From 3680f0bec90a979490f927dbb87b1dfe11a70d2f Mon Sep 17 00:00:00 2001 From: norvell Date: Wed, 5 Jun 2024 11:45:26 +0000 Subject: [PATCH 01/63] Expand LONG_TEST_SUITE to include STV tests for MASA and SBA that are not covered by self_test_ltv.prm. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a29792fa8..f8e5b2b22 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ variables: SCRIPTS_DIR: "/usr/local/scripts" EXIT_CODE_NON_BE: 123 EXIT_CODE_FAIL: 1 - LONG_TEST_SUITE: "tests/codec_be_on_mr_nonselection/test_param_file.py tests/renderer --param_file scripts/config/self_test_ltv.prm" + LONG_TEST_SUITE: "tests/codec_be_on_mr_nonselection tests/renderer --param_file scripts/config/self_test_ltv.prm" SHORT_TEST_SUITE: "tests/codec_be_on_mr_nonselection" TEST_SUITE: "" DUT_ENCODER_PATH: "./IVAS_cod" -- GitLab From d3643d9f257e3b6f8b39917ba090bcc7441ce228 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 6 Jun 2024 15:56:51 -0400 Subject: [PATCH 02/63] Fix proposal for 774, and removing some unecessary code at the same time (related to the part of code being fixed) --- lib_com/options.h | 1 + lib_com/prot.h | 3 ++- lib_dec/acelp_core_dec_fx.c | 5 +++++ lib_dec/acelp_core_dec_ivas_fx.c | 16 ++++++++++++---- lib_dec/hf_synth_fx.c | 18 ++++++++++++++---- lib_dec/stat_dec.h | 4 +++- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index cbd62853c..47515333d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -139,6 +139,7 @@ #define FIX_680_CNG_FRAME_BOUNDARIES_ISSUE /* Step was right shift by 2, which made the OVA wrong */ #define NONBE_FIX_1069_SVD_TUNING /* FhG: issue 1069: tune SVD constants */ #define FIX_778_STEREO_BRATE_SWITCHING +#define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 866d3aa79..698b29187 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -819,7 +819,7 @@ void hf_synth( float *synth, /* i/o: 12.8kHz synthesis signal */ float *synth16k /* i/o: 16kHz synthesis signal */ ); - +#ifndef FIX_774_ENERGY_BURST #ifdef IVAS_FLOAT_FIXED void hf_synth_ivas_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ @@ -838,6 +838,7 @@ void hf_synth_ivas_fx( const Word16 CNG_mode, /* i : CNG_mode */ Word16 element_mode ); #endif +#endif int16_t lsp_convert_poly( float w[], /* i/o: LSP or ISP parameters */ const int16_t L_frame, /* i : flag for up or down conversion */ diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index bb2dfffff..dd25918d2 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1787,8 +1787,13 @@ ivas_error acelp_core_dec_fx( IF( ( EQ_16( st_fx->L_frame, L_FRAME ) && NE_16( st_fx->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && ( EQ_16( st_fx->extl, -1 ) || EQ_16( st_fx->extl, SWB_CNG ) || ( EQ_16( st_fx->extl, WB_BWE ) && st_fx->extl_brate == 0 && NE_16( st_fx->coder_type, AUDIO ) ) ) ) ) { +#ifdef FIX_774_ENERGY_BURST + hf_synth_fx( st_fx->hBWE_zero, st_fx->core_brate, 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, &st_fx->hBWE_zero->memExp1, st_fx->hBWE_zero->mem_hp_interp_fx, st_fx->extl, st_fx->CNG_mode ); +#else hf_synth_fx( st_fx->hBWE_zero, st_fx->core_brate, 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, st_fx->CNG_mode ); +#endif } ELSE { diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index c59436411..989196472 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1882,22 +1882,29 @@ ivas_error acelp_core_dec_ivas_fx( IF( ( EQ_16( st->L_frame, L_FRAME ) && NE_16( st->bwidth, NB ) && GE_16( output_frame, L_FRAME16k ) && ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { +#ifndef FIX_774_ENERGY_BURST Word16 tmp_exp = 0; +#endif #ifdef MSAN_FIX Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else - Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif - +#ifdef FIX_774_ENERGY_BURST + hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, + psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &st->hBWE_zero->memExp1, + st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode ); +#else hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); +#endif #ifdef MSAN_FIX Copy_Scale_sig_16_32( synth_fx16, synth_fx, output_frame, 0 ); #else - Copy_Scale_sig_16_32( synth_fx16, synth_fx, L_FRAME48k, 0 ); + Copy_Scale_sig_16_32( synth_fx16, synth_fx, L_FRAME48k, 0 ); #endif - +#ifndef FIX_774_ENERGY_BURST IF( st->hBWE_FD != NULL ) { st->hBWE_FD->memExp1 = tmp_exp; @@ -1906,6 +1913,7 @@ ivas_error acelp_core_dec_ivas_fx( { Scale_sig( st->hBWE_zero->mem_hf_fx, L_FIR - 1, -tmp_exp ); } +#endif } ELSE { diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index f848edd5f..c63636e23 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -24,9 +24,11 @@ static void filt_6k_7k_scale_fx( Word16 signal[], Word16 lg, Word16 mem[], Word16 fact, Word16 exp ); 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 ); +#ifndef FIX_774_ENERGY_BURST #ifdef IVAS_FLOAT_FIXED static void hf_synthesis_ivas_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, Word16 element_mode ); #endif +#endif 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( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const Word32 core_brate, const Word16 Aq[], Word16 Ap[], Word16 *r, Word16 tilt0, Word16 tilt, Word16 voice_factor ); @@ -51,7 +53,10 @@ void hf_synth_init_fx( 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 ); - +#ifdef FIX_774_ENERGY_BURST + hBWE_zero->memExp1 = 0; + move16(); +#endif return; } void hf_synth_reset_fx( @@ -71,7 +76,10 @@ void hf_synth_reset_fx( 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 ); - +#ifdef FIX_774_ENERGY_BURST + hBWE_zero->memExp1 = 0; + move16(); +#endif return; } @@ -117,7 +125,7 @@ void hf_synth_fx( return; } - +#ifndef FIX_774_ENERGY_BURST #ifdef IVAS_FLOAT_FIXED void hf_synth_ivas_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, /* i/o: handle to 0 bit BWE parameters */ @@ -156,6 +164,7 @@ void hf_synth_ivas_fx( return; } #endif +#endif /*-----------------------------------------------------------------------------------* * hf_synthesis() * @@ -384,7 +393,7 @@ static void hf_synthesis_fx( return; } - +#ifndef FIX_774_ENERGY_BURST #ifdef IVAS_FLOAT_FIXED static void hf_synthesis_ivas_fx( ZERO_BWE_DEC_HANDLE hBWE_zero, @@ -611,6 +620,7 @@ static void hf_synthesis_ivas_fx( return; } #endif +#endif /*-------------------------------------------------------------------* * filt_6k_7k: diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 301014d92..1aec6e26d 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -1586,7 +1586,9 @@ typedef struct zero_bwe_dec_structure 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 */ - +#ifdef FIX_774_ENERGY_BURST + Word16 memExp1; /* Exponent for mem_hf_fx scaling*/ +#endif } ZERO_BWE_DEC_DATA, *ZERO_BWE_DEC_HANDLE; -- GitLab From 9db3f2eb1fdddab3a316a8311ac5dba6bcd7267f Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 6 Jun 2024 16:09:52 -0400 Subject: [PATCH 03/63] fix clang --- lib_dec/acelp_core_dec_ivas_fx.c | 10 +++++----- lib_dec/stat_dec.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 989196472..89559d6c2 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1888,21 +1888,21 @@ ivas_error acelp_core_dec_ivas_fx( #ifdef MSAN_FIX Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); #else - Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); + Copy_Scale_sig_32_16( synth_fx, synth_fx16, L_FRAME48k, 0 ); #endif #ifdef FIX_774_ENERGY_BURST hf_synth_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &st->hBWE_zero->memExp1, st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode ); #else - hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, - psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, - st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); + hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, + psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, + st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); #endif #ifdef MSAN_FIX Copy_Scale_sig_16_32( synth_fx16, synth_fx, output_frame, 0 ); #else - Copy_Scale_sig_16_32( synth_fx16, synth_fx, L_FRAME48k, 0 ); + Copy_Scale_sig_16_32( synth_fx16, synth_fx, L_FRAME48k, 0 ); #endif #ifndef FIX_774_ENERGY_BURST IF( st->hBWE_FD != NULL ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 1aec6e26d..29f1db0f1 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -1587,7 +1587,7 @@ typedef struct zero_bwe_dec_structure Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ #ifdef FIX_774_ENERGY_BURST - Word16 memExp1; /* Exponent for mem_hf_fx scaling*/ + Word16 memExp1; /* Exponent for mem_hf_fx scaling*/ #endif } ZERO_BWE_DEC_DATA, *ZERO_BWE_DEC_HANDLE; -- GitLab From 6ee3ca6c582753a350fec7bfca9e97da5e6f3cf2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 11:24:50 +0530 Subject: [PATCH 04/63] dirac_dec_stack_mem cleanup [x] Float stucture members DIRAC_DEC_STACK_MEM cleared [x] ivas_dirac_alloc_mem updates for float build --- lib_dec/ivas_dirac_dec.c | 88 ++++++++++++++-------- lib_rend/ivas_dirac_output_synthesis_dec.c | 26 +++---- lib_rend/ivas_dirac_rend.c | 74 +++++++++++------- lib_rend/ivas_stat_rend.h | 13 +++- lib_rend/lib_rend.c | 62 ++++++++++----- 5 files changed, 166 insertions(+), 97 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 5c8f35298..1dbb0e8ee 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3548,11 +3548,19 @@ void ivas_dirac_dec_render_sf_fx( if ( hDirAC->hConfig->dec_param_estim == TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + Word16 shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); + h_dirac_output_synthesis_state->q_cy_auto_dir_smooth += shift; - h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + // floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + + shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); + h_dirac_output_synthesis_state->q_cy_cross_dir_smooth += shift; + + /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands );*/ h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); @@ -3626,11 +3634,18 @@ void ivas_dirac_dec_render_sf_fx( floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, size ); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, size_ho ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth += shift; + // hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, size_ho ); + // floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); + + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ); hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); + + // hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; + // floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); @@ -3642,11 +3657,20 @@ void ivas_dirac_dec_render_sf_fx( { floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, size_ho ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, size_ho ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev += shift; + + /*hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, size_ho ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, size_ho );*/ + + shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev += shift; + - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, size_ho ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); + /*hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, size_ho ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho );*/ hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); @@ -5006,13 +5030,13 @@ void ivas_dirac_dec_render_sf_fx( { IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, hSpatParamRendCom->num_freq_bands ); - fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, hSpatParamRendCom->num_freq_bands ); + // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, hSpatParamRendCom->num_freq_bands ); + // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, hSpatParamRendCom->num_freq_bands ); } ELSE { - me2f_buf( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, 31 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hSpatParamRendCom->num_freq_bands ); - me2f_buf( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, 31 - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hSpatParamRendCom->num_freq_bands ); + // me2f_buf( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, 31 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hSpatParamRendCom->num_freq_bands ); + // me2f_buf( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, 31 - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hSpatParamRendCom->num_freq_bands ); } } IF( st_ivas->hMasa == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) @@ -5106,15 +5130,15 @@ void ivas_dirac_dec_render_sf_fx( { if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - fixedToFloat_arrL( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->direct_power_factor, h_dirac_output_synthesis_state->direct_power_factor_q, 2 * hSpatParamRendCom->num_freq_bands ); - fixedToFloat_arrL( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diffuse_power_factor, h_dirac_output_synthesis_state->diffuse_power_factor_q, 2 * hSpatParamRendCom->num_freq_bands ); + // fixedToFloat_arrL( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->direct_power_factor, h_dirac_output_synthesis_state->direct_power_factor_q, 2 * hSpatParamRendCom->num_freq_bands ); + // fixedToFloat_arrL( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diffuse_power_factor, h_dirac_output_synthesis_state->diffuse_power_factor_q, 2 * hSpatParamRendCom->num_freq_bands ); } else { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], 31 - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], 31 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], 31 - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], 31 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); } } } @@ -5124,17 +5148,17 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], 31 - h_dirac_output_synthesis_state->direct_power_factor_q ); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], 31 - h_dirac_output_synthesis_state->diffuse_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], 31 - h_dirac_output_synthesis_state->direct_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], 31 - h_dirac_output_synthesis_state->diffuse_power_factor_q ); } - fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, (num_channels_dir) *hSpatParamRendCom->num_freq_bands ); + // fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, (num_channels_dir) *hSpatParamRendCom->num_freq_bands ); } else { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); } } } @@ -5146,16 +5170,16 @@ void ivas_dirac_dec_render_sf_fx( if ( hDirAC->hConfig->dec_param_estim == TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + // fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + // fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); } IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); + // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); + // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; @@ -5165,11 +5189,11 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, size ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); + // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, size ); + // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, size ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, size ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); + // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, size ); + // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, size ); diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index de26b93ab..9fb7daee0 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -220,10 +220,10 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } /*TODO : remove float code*/ - if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) + /*if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } + }*/ IF( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx = (Word32 *) malloc( size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -232,7 +232,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /*TODO : remove float code*/ - dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; + //dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -246,12 +246,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } ELSE { - /*TODO : remove float code*/ - if ( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) @@ -822,10 +816,10 @@ void ivas_dirac_dec_output_synthesis_init_fx( *-----------------------------------------------------------------*/ /* initialize buffers */ - if ( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL ) + /*if ( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL ) { set_zero( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - } + }*/ if ( hodirac_flag ) { @@ -835,7 +829,7 @@ void ivas_dirac_dec_output_synthesis_init_fx( { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } - set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size ); + //set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size ); if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { @@ -1036,16 +1030,16 @@ void ivas_dirac_dec_output_synthesis_close_fx( *-----------------------------------------------------------------*/ /* free target power buffers */ - if ( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev != NULL ) + /*if ( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev != NULL ) { free( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev ); ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev = NULL; - } - if ( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev != NULL ) + }*/ + /*if ( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev != NULL ) { free( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev ); ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev = NULL; - } + }*/ if ( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev != NULL ) { free( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev ); diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 2e8ae2cb8..744035fa6 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1267,28 +1267,32 @@ ivas_error ivas_dirac_alloc_mem( } /* PSD related buffers */ - hDirAC_mem->cy_auto_dir_smooth = NULL; #ifdef IVAS_FLOAT_FIXED hDirAC_mem->cy_auto_dir_smooth_fx = NULL; hDirAC_mem->proto_power_smooth_fx = NULL; hDirAC_mem->proto_power_diff_smooth_fx = NULL; hDirAC_mem->direct_responses_square_fx = NULL; #else + hDirAC_mem->cy_auto_dir_smooth = NULL; hDirAC_mem->direct_responses_square = NULL; #endif #ifdef IVAS_FLOAT_FIXED hDirAC_mem->frame_dec_f_fx = NULL; #else + hDirAC_mem->proto_power_smooth = NULL; + hDirAC_mem->proto_power_diff_smooth = NULL; + hDirAC_mem->direct_responses_square = NULL; hDirAC_mem->frame_dec_f = NULL; #endif if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { +#ifndef IVAS_FLOAT_FIXED if ( ( hDirAC_mem->cy_auto_dir_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero( hDirAC_mem->cy_auto_dir_smooth, size ); -#ifdef IVAS_FLOAT_FIXED +#else if ( ( hDirAC_mem->cy_auto_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1297,7 +1301,19 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len = size; #endif -#ifdef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED + if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->proto_power_smooth, size ); + + if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); + } + set_zero( hDirAC_mem->proto_power_diff_smooth, size ); +#else if ( ( hDirAC_mem->proto_power_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1345,28 +1361,29 @@ ivas_error ivas_dirac_alloc_mem( #endif } } +#ifndef IVAS_FLOAT_FIXED + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth = hDirAC_mem->proto_power_smooth; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth = hDirAC_mem->proto_power_diff_smooth; hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth = hDirAC_mem->cy_auto_dir_smooth; -#ifdef IVAS_FLOAT_FIXED - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx = hDirAC_mem->proto_power_diff_smooth_fx; - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirAC_mem->proto_power_diff_smooth_q; - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len = hDirAC_mem->proto_power_diff_smooth_len; - hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx = hDirAC_mem->cy_auto_dir_smooth_fx; - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = 0; - move16(); -#else hDirACRend->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; -#endif -#ifdef IVAS_FLOAT_FIXED +#else hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx = hDirAC_mem->direct_responses_square_fx; hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx = hDirAC_mem->proto_power_smooth_fx; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = Q31; hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = Q31; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx = hDirAC_mem->proto_power_diff_smooth_fx; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = hDirAC_mem->proto_power_diff_smooth_q; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len = hDirAC_mem->proto_power_diff_smooth_len; hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = Q31; hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = Q31; + hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx = hDirAC_mem->cy_auto_dir_smooth_fx; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = 0; + move16(); #endif /* Target and smoothed nrg factors/gains */ +#ifndef IVAS_FLOAT_FIXED if ( ( hDirAC_mem->cy_cross_dir_smooth = (float *) malloc( sizeof( float ) * size_ho ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1376,6 +1393,7 @@ ivas_error ivas_dirac_alloc_mem( #else set_zero( hDirAC_mem->cy_cross_dir_smooth, size ); #endif +#endif #ifdef IVAS_FLOAT_FIXED if ( ( hDirAC_mem->cy_cross_dir_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size_ho ) ) == NULL ) { @@ -1422,7 +1440,6 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = num_outputs_diff * num_freq_bands_diff; #endif } - hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; #ifdef IVAS_FLOAT_FIXED hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx = hDirAC_mem->cy_cross_dir_smooth_fx; @@ -1431,6 +1448,8 @@ ivas_error ivas_dirac_alloc_mem( move16(); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = 0; move16(); +#else + hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; #endif /*Responses (gains/factors)*/ @@ -1528,16 +1547,18 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; #endif /* Gains/power factors*/ - hDirAC_mem->direct_power_factor = NULL; - hDirAC_mem->diffuse_power_factor = NULL; #ifdef IVAS_FLOAT_FIXED hDirAC_mem->direct_power_factor_fx = NULL; hDirAC_mem->diffuse_power_factor_fx = NULL; +#else + hDirAC_mem->direct_power_factor = NULL; + hDirAC_mem->diffuse_power_factor = NULL; #endif if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) { +#ifndef IVAS_FLOAT_FIXED if ( ( hDirAC_mem->direct_power_factor = (float *) malloc( sizeof( float ) * size_pf ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1546,7 +1567,7 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } -#ifdef IVAS_FLOAT_FIXED +#else IF( ( hDirAC_mem->direct_power_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * size_pf ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1558,10 +1579,6 @@ ivas_error ivas_dirac_alloc_mem( #endif } - hDirACRend->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; - set_zero( hDirACRend->h_output_synthesis_psd_state.direct_power_factor, size_pf ); - set_zero( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, size_pf ); #ifdef IVAS_FLOAT_FIXED hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx = hDirAC_mem->direct_power_factor_fx; hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx = hDirAC_mem->diffuse_power_factor_fx; @@ -1571,6 +1588,11 @@ ivas_error ivas_dirac_alloc_mem( move16(); hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31; move16(); +#else + hDirACRend->h_output_synthesis_psd_state.direct_power_factor = hDirAC_mem->direct_power_factor; + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor = hDirAC_mem->diffuse_power_factor; + set_zero( hDirACRend->h_output_synthesis_psd_state.direct_power_factor, size_pf ); + set_zero( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, size_pf ); #endif #ifndef IVAS_FLOAT_FIXED @@ -1679,10 +1701,6 @@ ivas_error ivas_dirac_alloc_mem( void ivas_dirac_free_mem_fx( DIRAC_DEC_STACK_MEM_HANDLE hDirAC_mem ) { - IF( hDirAC_mem->cy_auto_dir_smooth != NULL ) - { - free( hDirAC_mem->cy_auto_dir_smooth ); - } IF( hDirAC_mem->cy_auto_dir_smooth_fx != NULL ) { free( hDirAC_mem->cy_auto_dir_smooth_fx ); @@ -1713,10 +1731,6 @@ void ivas_dirac_free_mem_fx( free( hDirAC_mem->frame_dec_f ); } #endif - IF( hDirAC_mem->cy_cross_dir_smooth != NULL ) - { - free( hDirAC_mem->cy_cross_dir_smooth ); - } IF( hDirAC_mem->cy_cross_dir_smooth_fx != NULL ) { free( hDirAC_mem->cy_cross_dir_smooth_fx ); @@ -1755,6 +1769,7 @@ void ivas_dirac_free_mem_fx( { free( hDirAC_mem->proto_diffuse_buffer_f_fx ); } +#ifndef IVAS_FLOAT_FIXED IF( hDirAC_mem->direct_power_factor != NULL ) { free( hDirAC_mem->direct_power_factor ); @@ -1763,6 +1778,7 @@ void ivas_dirac_free_mem_fx( { free( hDirAC_mem->diffuse_power_factor ); } +#endif IF( hDirAC_mem->direct_power_factor_fx != NULL ) { free( hDirAC_mem->direct_power_factor_fx ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index c7964bdee..6cbd09ebb 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -275,8 +275,10 @@ typedef struct dirac_dec_stack_mem #endif /*Gain or power factors for directional and diffuse streams*/ +#ifndef IVAS_FLOAT_FIXED float *direct_power_factor; float *diffuse_power_factor; +#endif #ifdef IVAS_FLOAT_FIXED /*Prototypes*/ @@ -305,13 +307,14 @@ typedef struct dirac_dec_stack_mem Word32 *direct_responses_square_fx; #endif /* Target co-variance mtx */ - float *cy_auto_dir_smooth; - float *cy_cross_dir_smooth; float *cy_auto_diff_smooth; #ifdef IVAS_FLOAT_FIXED Word32 *cy_auto_dir_smooth_fx; Word32 *cy_cross_dir_smooth_fx; Word32 *cy_auto_diff_smooth_fx; +#else + float *cy_cross_dir_smooth; + float *cy_auto_dir_smooth; #endif #ifndef IVAS_FLOAT_FIXED @@ -375,8 +378,10 @@ typedef struct dirac_output_synthesis_state_structure #endif /* only pointer to local buffers */ +#ifndef IVAS_FLOAT_FIXED float *direct_power_factor; float *diffuse_power_factor; +#endif #ifndef IVAS_FLOAT_FIXED float *proto_power_smooth; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ @@ -399,13 +404,17 @@ typedef struct dirac_output_synthesis_state_structure float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ /* only pointer to local buffers */ +#ifndef IVAS_FLOAT_FIXED float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ +#endif float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ /* PSD memories */ +#ifndef IVAS_FLOAT_FIXED float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ +#endif float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ #ifndef IVAS_FLOAT_FIXED diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 925265558..135522e3b 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -14807,23 +14807,42 @@ static void intermidiate_ext_dirac_render( } } - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) + if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) + { + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth += shift; + } + if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) + { + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, shift ); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev += shift; + } + + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) { hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - } + }*/ - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) { hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); ; floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); + }*/ + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) + { + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth += shift; } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) { hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); - } + }*/ Word16 num_channels_dir = hDirACRend->num_outputs_dir; if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) @@ -14847,12 +14866,19 @@ static void intermidiate_ext_dirac_render( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) + + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); + Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev += shift; } + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) + { + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); + }*/ if ( hDirACRend->proto_signal_decorr_on == 1 ) { Word16 tmp_e; @@ -14915,8 +14941,8 @@ static void intermidiate_ext_dirac_render( { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); + // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); } /* @@ -14933,22 +14959,22 @@ static void intermidiate_ext_dirac_render( } } }*/ - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) { fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); - } - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) + }*/ + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) { fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - } - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) + }*/ + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) { fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); - } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) + }*/ + /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) { fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); - } + }*/ if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth ) { fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); -- GitLab From 81615393009f2b23b620d3cc5f4abc3d71e8a10c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 11:30:19 +0530 Subject: [PATCH 05/63] Clang formatting changes --- lib_rend/ivas_dirac_output_synthesis_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 9fb7daee0..73154c600 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -232,7 +232,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /*TODO : remove float code*/ - //dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; + // dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -829,7 +829,7 @@ void ivas_dirac_dec_output_synthesis_init_fx( { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } - //set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size ); + // set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size ); if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { -- GitLab From 5a8736249252c99ce86574bfdfd381d45711d45f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 12:23:48 +0530 Subject: [PATCH 06/63] Fix for issue#780:MASA 2 TC output difference --- lib_dec/cng_dec_fx.c | 1 + lib_dec/ivas_cpe_dec_fx.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 6377fa019..802e6772c 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1341,6 +1341,7 @@ static void shb_CNG_decod_ivas_fx( interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } + Scale_sig(shb_synth_fx, L_FRAME48k, -3); ResetSHBbuffer_Dec_fx( st ); return; } diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 4ff50cb31..2ab89940d 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -301,7 +301,7 @@ ivas_error ivas_cpe_dec_fx( } /* read DFT Stereo side info */ - nb_bits = extract_l( L_sub( ( hCPE->element_brate / FRAMES_PER_SEC ), Mpy_32_16_1( 26214, sts[0]->bits_frame_nominal ) ) ); // 0.8f in q15 = 26214 + nb_bits = extract_h( L_msu( Mpy_32_16_1( L_shl( hCPE->element_brate, 15 ) , 1311 /* 1/FRAMES_PER_SEC in Q16*/ ), 26214, sts[0]->bits_frame_nominal ) ); cpe_brate = st_ivas->hCPE[0]->element_brate; move32(); IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) -- GitLab From fe52a9ceb27f11ead3bc64dd4993072e4dbcf794 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 12:30:10 +0530 Subject: [PATCH 07/63] clang formatting changes --- lib_dec/cng_dec_fx.c | 2 +- lib_dec/ivas_cpe_dec_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 802e6772c..d75b598f2 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1341,7 +1341,7 @@ static void shb_CNG_decod_ivas_fx( interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } - Scale_sig(shb_synth_fx, L_FRAME48k, -3); + Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); ResetSHBbuffer_Dec_fx( st ); return; } diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 2ab89940d..a7d4daaae 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -301,7 +301,7 @@ ivas_error ivas_cpe_dec_fx( } /* read DFT Stereo side info */ - nb_bits = extract_h( L_msu( Mpy_32_16_1( L_shl( hCPE->element_brate, 15 ) , 1311 /* 1/FRAMES_PER_SEC in Q16*/ ), 26214, sts[0]->bits_frame_nominal ) ); + nb_bits = extract_h( L_msu( Mpy_32_16_1( L_shl( hCPE->element_brate, 15 ), 1311 /* 1/FRAMES_PER_SEC in Q16*/ ), 26214, sts[0]->bits_frame_nominal ) ); cpe_brate = st_ivas->hCPE[0]->element_brate; move32(); IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) -- GitLab From eb441f3a993735f395b92f4739d968e4a730eb4a Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 10 Jun 2024 09:34:08 +0200 Subject: [PATCH 08/63] Use only Ericsson Linux runner 5 --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8e5b2b22..f37aacd81 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -197,14 +197,14 @@ stages: # templates to define stages and platforms .test-job-linux: tags: - - ivas-basop-linux + - test-ericsson-linux-runner-5 .build-job-linux: stage: build timeout: "2 minutes" needs: [] tags: - - ivas-basop-linux + - test-ericsson-linux-runner-5 # template for test jobs on linux that need the TESTV_DIR .test-job-linux-needs-testv-dir: @@ -682,7 +682,7 @@ be-2-evs-26444: pages: stage: deploy tags: - - ivas-basop-linux + - test-ericsson-linux-runner-5 rules: - if: $UPDATE_PAGES script: -- GitLab From 02ac9c69646ff02846b29d354f74fab9231cf28c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 13:55:38 +0530 Subject: [PATCH 09/63] ivas_dirac_dec_binaural_determine_processing_matrices: converted to fixed point [x] ivas_dirac_dec_binaural_determine_processing_matrices is converted to fixed point and is integrated at all locations. [x] Floating point structure members from DIRAC_DEC_BIN_DATA and HRTFS_PARAMBIN_HANDLE cleaned up. --- lib_rend/ivas_dirac_dec_binaural_functions.c | 1118 +++++++++++------- lib_rend/ivas_rom_rend.c | 12 + lib_rend/ivas_rom_rend.h | 9 +- lib_rend/ivas_stat_rend.h | 13 +- lib_rend/lib_rend.c | 45 +- lib_util/hrtf_file_reader.c | 75 +- 6 files changed, 806 insertions(+), 466 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index c0f50d4b7..279cf432c 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -135,11 +135,13 @@ static void ivas_dirac_dec_decorrelate_slot_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBi static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 Rmat_fx[3][3], const Word16 subframe, const Word16 isHeadtracked, const MASA_ISM_DATA_HANDLE hMasaIsmData, Word16 q ); #else static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked, const MASA_ISM_DATA_HANDLE hMasaIsmData ); -#endif static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked, const int16_t nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData ); +#endif #ifdef IVAS_FLOAT_FIXED +static void ivas_dirac_dec_binaural_determine_processing_matrices_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, Word32 Rmat[3][3], const Word16 subframe, const Word16 isHeadtracked, const Word16 nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData ); + static void ivas_dirac_dec_binaural_process_output_fx( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, HANDLE_CLDFB_FILTER_BANK cldfbSynDec[MAX_OUTPUT_CHANNELS], Word32 *output_fx[], Word16 *q_out, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const Word16 q_inp, const Word16 max_band_decorr, const Word16 numInChannels, const Word16 processReverb, const Word16 subframe, const Word16 q_mat ); static void adaptTransportSignalsHeadtracked_fx( COMBINED_ORIENTATION_HANDLE hHeadTrackData, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 q_inp, const Word16 nBins, const Word16 nSlots, Word32 Rmat[3][3] ); @@ -171,10 +173,10 @@ static void getDirectPartGains_fx( const Word16 bin, Word16 aziDeg, Word16 eleDe #else static void getDirectPartGains( const int16_t bin, int16_t aziDeg, int16_t eleDeg, float *lRealp, float *lImagp, float *rRealp, float *rImagp, const uint8_t stereoMode, float Rmat[3][3], PARAMBIN_HRTF_GAIN_CACHE *gainCache, const int16_t isHeadtracked ); -#endif static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); +#endif static void ivas_masa_ext_rend_parambin_internal( MASA_EXT_REND_HANDLE hMasaExtRend, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, float *output_f[], const int16_t subframe ); @@ -372,6 +374,11 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( Word32 output_Fs; RENDERER_TYPE renderer_type; Word16 j, k, bin; + Word32 binCenterFreq_fx; + Word16 tmpFloat_fx; + Word16 tmp; + Word16 tmp_e; + Word16 tmp2; ivas_error error; hDiracDecBin = st_ivas->hDiracDecBin; @@ -398,12 +405,6 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( { FOR( k = 0; k < BINAURAL_CHANNELS + MAX_NUM_OBJECTS; k++ ) { -#if 1 /* todo: remove float */ - set_zero( hDiracDecBin->processMtxRe[j][k], nBins ); - set_zero( hDiracDecBin->processMtxIm[j][k], nBins ); - set_zero( hDiracDecBin->processMtxRePrev[j][k], nBins ); - set_zero( hDiracDecBin->processMtxImPrev[j][k], nBins ); -#endif set16_fx( hDiracDecBin->processMtxRe_fx[j][k], 0, nBins ); set16_fx( hDiracDecBin->processMtxIm_fx[j][k], 0, nBins ); set16_fx( hDiracDecBin->processMtxRePrev_fx[j][k], 0, nBins ); @@ -412,96 +413,110 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( FOR( k = 0; k < BINAURAL_CHANNELS; k++ ) { -#if 1 /* todo: remove float */ - set_zero( hDiracDecBin->processMtxDecRe[j][k], nBins ); - set_zero( hDiracDecBin->processMtxDecIm[j][k], nBins ); -#endif set16_fx( hDiracDecBin->processMtxDecRe_fx[j][k], 0, nBins ); set16_fx( hDiracDecBin->processMtxDecIm_fx[j][k], 0, nBins ); } -#if 1 /* to be converted */ - set_zero( hDiracDecBin->ChEnePrev[j], nBins ); - set_zero( hDiracDecBin->ChEneOutPrev[j], nBins ); -#endif - } -#if 1 /* to be converted */ - set_zero( hDiracDecBin->ChCrossRePrev, nBins ); - set_zero( hDiracDecBin->ChCrossImPrev, nBins ); - set_zero( hDiracDecBin->ChCrossReOutPrev, nBins ); - set_zero( hDiracDecBin->ChCrossImOutPrev, nBins ); -#endif + set32_fx( hDiracDecBin->ChEnePrev_fx[j], 0, nBins ); + set32_fx( hDiracDecBin->ChEneOutPrev_fx[j], 0, nBins ); + set16_fx( hDiracDecBin->ChEnePrev_e[j], 0, nBins ); + set16_fx( hDiracDecBin->ChEneOutPrev_e[j], 0, nBins ); + } + set32_fx( hDiracDecBin->ChCrossRePrev_fx, 0, nBins ); + set32_fx( hDiracDecBin->ChCrossImPrev_fx, 0, nBins ); + set16_fx( hDiracDecBin->ChCrossRePrev_e, 0, nBins ); + set16_fx( hDiracDecBin->ChCrossImPrev_e, 0, nBins ); + set32_fx( hDiracDecBin->ChCrossReOutPrev_fx, 0, nBins ); + set32_fx( hDiracDecBin->ChCrossImOutPrev_fx, 0, nBins ); + set16_fx( hDiracDecBin->ChCrossReOutPrev_e, 0, nBins ); + set16_fx( hDiracDecBin->ChCrossImOutPrev_e, 0, nBins ); hDiracDecBin->renderStereoOutputInsteadOfBinaural = 0; + hDiracDecBin->q_processMtx = Q15; + hDiracDecBin->q_processMtxSCCR = Q15; + hDiracDecBin->q_processMtxPrev = Q15; + hDiracDecBin->q_processMtxPrevSCCR = Q15; + hDiracDecBin->q_processMtxDec = Q15; + hDiracDecBin->q_processMtxDecPrev = Q15; + FOR( bin = 0; bin < nBins; bin++ ) { - float binCenterFreq, tmpFloat; - binCenterFreq = ( (float) bin + CLDFB_HALF_BIN_FREQUENCY_OFFSET ) / (float) nBins * ( (float) output_Fs / 2.0f ); + binCenterFreq_fx = L_mult0( extract_l( L_shr( output_Fs, 1 ) ), div_s( add( shl( bin, 1 ), 1 ), shl( nBins, 1 ) ) ) /*( (float) bin + 0.5f ) / (float) nBins * ( (float) output_Fs / 2.0f )*/; /*Q15*/ /* These formulas and values are from Christian Borss's publication for binaural diffuse field coherence */ - tmpFloat = max( 0.0f, 1.0f - binCenterFreq / 2700.0f ); - hDiracDecBin->diffuseFieldCoherence[bin] = tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f ); + tmp = BASOP_Util_Divide3232_Scale( binCenterFreq_fx, 2700 << Q15, &tmp_e ); + IF( tmp_e < 0 ) + { + tmp = shl( tmp, tmp_e ); /*q15*/ + tmp_e = 0; + } + tmpFloat_fx = s_max( 0, sub( shl_sat( 1, 15 - tmp_e ), tmp ) ) /*max( 0.0f, 1.0f - binCenterFreq / 2700.0f )*/; /*Q30*/ + tmp2 = extract_l( Mult_32_32( binCenterFreq_fx, 1952258 /*=2^31*180/(550)/360*/ ) % 32767 ); //*binCenterFreq_fx * EVS_PI / 550.0f*/ + hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( L_mult0( divide3232( tmpFloat_fx, Mult_32_16( binCenterFreq_fx, 187 /*2^15*pi/550*/ ) ), getSineWord16R2( tmp2 ) ), tmp_e ); /*tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f );*/ + hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); } - for ( bin = 0; bin < BINAURAL_COHERENCE_DIFFERENCE_BINS; bin++ ) + FOR( bin = 0; bin < BINAURAL_COHERENCE_DIFFERENCE_BINS; bin++ ) { - hDiracDecBin->diffuseFieldCoherenceX[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceX[bin]; - hDiracDecBin->diffuseFieldCoherenceY[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceY[bin]; - hDiracDecBin->diffuseFieldCoherenceZ[bin] = hDiracDecBin->diffuseFieldCoherence[bin] + diffuseFieldCoherenceDifferenceZ[bin]; + hDiracDecBin->diffuseFieldCoherenceX_fx[bin] = L_add( hDiracDecBin->diffuseFieldCoherence_fx[bin], diffuseFieldCoherenceDifferenceX_fx[bin] ); + hDiracDecBin->diffuseFieldCoherenceY_fx[bin] = L_add( hDiracDecBin->diffuseFieldCoherence_fx[bin], diffuseFieldCoherenceDifferenceY_fx[bin] ); + hDiracDecBin->diffuseFieldCoherenceZ_fx[bin] = L_add( hDiracDecBin->diffuseFieldCoherence_fx[bin], diffuseFieldCoherenceDifferenceZ_fx[bin] ); } - if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC ) /* Indication of binaural rendering without room effect */ + IF( EQ_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) /* Indication of binaural rendering without room effect */ { - set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); + set32_fx( hDiracDecBin->earlyPartEneCorrection_fx, ONE_IN_Q28, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->q_earlyPartEneCorrection = Q28; hDiracDecBin->hReverb = NULL; } - else if ( renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) /* Indication of binaural rendering with room effect */ + ELSE IF( EQ_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) /* Indication of binaural rendering with room effect */ { - mvr2r( hHrtfParambin->parametricEarlyPartEneCorrection, hDiracDecBin->earlyPartEneCorrection, nBins ); - + Copy32( hHrtfParambin->parametricEarlyPartEneCorrection_fx, hDiracDecBin->earlyPartEneCorrection_fx, nBins ); + hDiracDecBin->q_earlyPartEneCorrection = Q28; /* reconfiguration needed when Reverb. parameters are changed -> close and open the handle again */ - if ( hDiracDecBin->hReverb != NULL && ( ( hDiracDecBin->hReverb->numBins != nBins ) || - ( hDiracDecBin->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) ) + IF( hDiracDecBin->hReverb != NULL && ( ( hDiracDecBin->hReverb->numBins != nBins ) || + ( hDiracDecBin->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) ) { ivas_binaural_reverb_close_fx( &( hDiracDecBin->hReverb ) ); } - if ( hDiracDecBin->hReverb == NULL ) + IF( hDiracDecBin->hReverb == NULL ) { /* Todo Philips: Room acoustics should be passed here once the underlying part works. Probably enough to pick it from st_ivas but you know best. */ - if ( ( error = ivas_binaural_reverb_open_parambin( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, output_Fs, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_binaural_reverb_open_parambin( &hDiracDecBin->hReverb, nBins, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, NULL, output_Fs, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) { return error; } } } - else if ( renderer_type == RENDERER_STEREO_PARAMETRIC ) + ELSE IF( EQ_32( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - set_f( hDiracDecBin->earlyPartEneCorrection, 1.0f, CLDFB_NO_CHANNELS_MAX ); + set32_fx( hDiracDecBin->earlyPartEneCorrection_fx, ONE_IN_Q28, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->q_earlyPartEneCorrection = Q28; hDiracDecBin->hReverb = NULL; hDiracDecBin->renderStereoOutputInsteadOfBinaural = 1; } - else /* Not valid renderer type for this renderer */ + ELSE /* Not valid renderer type for this renderer */ { assert( false ); } hDiracDecBin->hDiffuseDist = NULL; /* Memory is allocated from stack during runtime when needed */ - if ( hDiracDecBin->hTdDecorr == NULL ) + IF( hDiracDecBin->hTdDecorr == NULL ) { hDiracDecBin->useTdDecorr = 0; } - if ( hDiracDecBin->h_freq_domain_decorr_ap_params != NULL ) + IF( hDiracDecBin->h_freq_domain_decorr_ap_params != NULL ) { ivas_dirac_dec_decorr_close_fx( &hDiracDecBin->h_freq_domain_decorr_ap_params, &hDiracDecBin->h_freq_domain_decorr_ap_state ); } - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hDiracDecBin->hTdDecorr ), &( hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( hDiracDecBin->hTdDecorr ), &( hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) { return error; } - if ( !hDiracDecBin->useTdDecorr && !( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) + IF( !hDiracDecBin->useTdDecorr && !( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) ) { Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, nBins ); @@ -525,19 +540,19 @@ ivas_error ivas_dirac_dec_init_binaural_data_fx( st_ivas->hDiracDecBin = hDiracDecBin; /* allocate transport channels */ - if ( st_ivas->hTcBuffer == NULL ) + IF( st_ivas->hTcBuffer == NULL ) { - int16_t nchan_to_allocate; - int16_t n_samples_granularity; + Word16 nchan_to_allocate; + Word16 n_samples_granularity; nchan_to_allocate = 2 * BINAURAL_CHANNELS; - if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nchan_to_allocate = 2 * BINAURAL_CHANNELS + 2; } n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); - if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ } @@ -686,7 +701,7 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( Copy32( parametricReverberationTimes_fx, hrtfParambin->parametricReverberationTimes_fx, CLDFB_NO_CHANNELS_MAX ); Copy32( parametricReverberationEneCorrections_fx, hrtfParambin->parametricReverberationEneCorrections_fx, CLDFB_NO_CHANNELS_MAX ); - mvr2r( parametricEarlyPartEneCorrection, hrtfParambin->parametricEarlyPartEneCorrection, CLDFB_NO_CHANNELS_MAX ); + Copy32( parametricEarlyPartEneCorrection_fx, hrtfParambin->parametricEarlyPartEneCorrection_fx, CLDFB_NO_CHANNELS_MAX ); *hHrtfParambin = hrtfParambin; } @@ -1179,6 +1194,7 @@ static void ivas_dirac_dec_binaural_internal( DIFFUSE_DISTRIBUTION_DATA diffuseDistData; Word16 nBins, offsetSamples; Word16 i, j; + Word16 q_mat; hDiracDecBin = st_ivas->hDiracDecBin; assert( hDiracDecBin ); hSpatParamRendCom = st_ivas->hSpatParamRendCom; @@ -1368,14 +1384,12 @@ static void ivas_dirac_dec_binaural_internal( FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - // floatToFixed_arrL( st_ivas->hSpar->hFbMixer->pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[idx], st_ivas->hSpar->hFbMixer->pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[idx], Q31, IVAS_MAX_NUM_FB_BANDS ); Scale_sig32( st_ivas->hSpar->hFbMixer->pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[idx], IVAS_MAX_NUM_FB_BANDS, sub( Q31, Q22 ) ); } #endif ivas_sba_prototype_renderer_fx( st_ivas, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_cldfb, subframe ); FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - // floatToFixed_arrL( st_ivas->hSpar->hFbMixer->pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band[idx], st_ivas->hSpar->hFbMixer->pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[idx], Q31, IVAS_MAX_NUM_FB_BANDS ); Scale_sig32( st_ivas->hSpar->hFbMixer->pFb->fb_bin_to_band.pp_cldfb_weights_per_spar_band_fx[idx], IVAS_MAX_NUM_FB_BANDS, sub( Q22, Q31 ) ); } } @@ -1413,32 +1427,6 @@ static void ivas_dirac_dec_binaural_internal( } } -#if 1 - Word16 q_earlyPartEneCorrection = Q_factor_arrL( hDiracDecBin->earlyPartEneCorrection, hSpatParamRendCom->num_freq_bands ); - hDiracDecBin->q_earlyPartEneCorrection = q_earlyPartEneCorrection; - floatToFixed_arr32( hDiracDecBin->earlyPartEneCorrection, hDiracDecBin->earlyPartEneCorrection_fx, q_earlyPartEneCorrection, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherence, hDiracDecBin->diffuseFieldCoherence_fx, Q31, hSpatParamRendCom->num_freq_bands ); - - FOR( j = 0; j < nBins; j++ ) - { - f2me( hDiracDecBin->ChCrossRePrev[j], &hDiracDecBin->ChCrossRePrev_fx[j], &hDiracDecBin->ChCrossRePrev_e[j] ); - f2me( hDiracDecBin->ChCrossImPrev[j], &hDiracDecBin->ChCrossImPrev_fx[j], &hDiracDecBin->ChCrossImPrev_e[j] ); - f2me( hDiracDecBin->ChCrossReOutPrev[j], &hDiracDecBin->ChCrossReOutPrev_fx[j], &hDiracDecBin->ChCrossReOutPrev_e[j] ); - f2me( hDiracDecBin->ChCrossImOutPrev[j], &hDiracDecBin->ChCrossImOutPrev_fx[j], &hDiracDecBin->ChCrossImOutPrev_e[j] ); - FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - f2me( hDiracDecBin->ChEnePrev[i][j], &hDiracDecBin->ChEnePrev_fx[i][j], &hDiracDecBin->ChEnePrev_e[i][j] ); - f2me( hDiracDecBin->ChEneOutPrev[i][j], &hDiracDecBin->ChEneOutPrev_fx[i][j], &hDiracDecBin->ChEneOutPrev_e[i][j] ); - } - } - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherence, hDiracDecBin->diffuseFieldCoherence_fx, 31, hSpatParamRendCom->num_freq_bands ); - IF( hDiracDecBin->hDiffuseDist ) - { - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceX, hDiracDecBin->diffuseFieldCoherenceX_fx, 31, 9 ); - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceY, hDiracDecBin->diffuseFieldCoherenceY_fx, 31, 9 ); - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceZ, hDiracDecBin->diffuseFieldCoherenceZ_fx, 31, 9 ); - } -#endif Word16 shift = 31; Word32 Cldfb_RealBuffer_inTmp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Cldfb_ImagBuffer_inTmp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; FOR( i = 0; i < 2; i++ ) @@ -1497,46 +1485,14 @@ static void ivas_dirac_dec_binaural_internal( move16(); } -#if 1 - FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - hDiracDecBin->ChEnePrev[i][j] = me2f( hDiracDecBin->ChEnePrev_fx[i][j], hDiracDecBin->ChEnePrev_e[i][j] ); - hDiracDecBin->ChEne[i][j] = me2f( hDiracDecBin->ChEne_fx[i][j], hDiracDecBin->ChEne_e[i][j] ); - hDiracDecBin->ChEneOut[i][j] = me2f( hDiracDecBin->ChEneOut_fx[i][j], hDiracDecBin->ChEneOut_e[i][j] ); - hDiracDecBin->ChEneOutPrev[i][j] = me2f( hDiracDecBin->ChEneOutPrev_fx[i][j], hDiracDecBin->ChEneOutPrev_e[i][j] ); - } - } - - FOR( j = 0; j < nBins; j++ ) - { - hDiracDecBin->ChCrossRePrev[j] = me2f( hDiracDecBin->ChCrossRePrev_fx[j], hDiracDecBin->ChCrossRePrev_e[j] ); - hDiracDecBin->ChCrossImPrev[j] = me2f( hDiracDecBin->ChCrossImPrev_fx[j], hDiracDecBin->ChCrossImPrev_e[j] ); - hDiracDecBin->ChCrossRe[j] = me2f( hDiracDecBin->ChCrossRe_fx[j], hDiracDecBin->ChCrossRe_e[j] ); - hDiracDecBin->ChCrossIm[j] = me2f( hDiracDecBin->ChCrossIm_fx[j], hDiracDecBin->ChCrossIm_e[j] ); - hDiracDecBin->ChCrossReOut[j] = me2f( hDiracDecBin->ChCrossReOut_fx[j], hDiracDecBin->ChCrossReOut_e[j] ); - hDiracDecBin->ChCrossImOut[j] = me2f( hDiracDecBin->ChCrossImOut_fx[j], hDiracDecBin->ChCrossImOut_e[j] ); - hDiracDecBin->ChCrossReOutPrev[j] = me2f( hDiracDecBin->ChCrossReOutPrev_fx[j], hDiracDecBin->ChCrossReOutPrev_e[j] ); - hDiracDecBin->ChCrossImOutPrev[j] = me2f( hDiracDecBin->ChCrossImOutPrev_fx[j], hDiracDecBin->ChCrossImOutPrev_e[j] ); - } - fixedToFloat_arrL( hDiracDecBin->frameMeanDiffuseness_fx, hDiracDecBin->frameMeanDiffuseness, 29, CLDFB_NO_CHANNELS_MAX ); -#endif - - // TODO: To be removed once below function is fixed - float Rmat[3][3]; - for ( i = 0; i < 3; i++ ) - { - fixedToFloat_arrL32( Rmat_fx[i], Rmat[i], Q30, 3 ); - } - ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, + ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); #if 1 Word32 *output_fx[MAX_OUTPUT_CHANNELS]; Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; Word16 q_out; - Word16 q_mat = 15; + q_inp = Q6; FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { @@ -1544,47 +1500,41 @@ static void ivas_dirac_dec_binaural_internal( } FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - FOR( slot = 0; slot < BINAURAL_CHANNELS; slot++ ) - { - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecRe[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecIm[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecRePrev[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecImPrev[ch][slot], nBins ) ); - } - } - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - FOR( slot = 0; slot < numInChannels; slot++ ) - { - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxRe[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxIm[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxRePrev[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxImPrev[ch][slot], nBins ) ); - } + st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } - q_mat = sub( q_mat, 1 ); // guardbits// +#endif + + q_mat = hDiracDecBin->q_processMtx; + q_mat = s_min( q_mat, hDiracDecBin->q_processMtxPrev ); + q_mat = s_min( q_mat, hDiracDecBin->q_processMtxDec ); + q_mat = s_min( q_mat, hDiracDecBin->q_processMtxDecPrev ); + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { FOR( slot = 0; slot < BINAURAL_CHANNELS; slot++ ) { - floatToFixed_arr16( hDiracDecBin->processMtxDecRe[ch][slot], hDiracDecBin->processMtxDecRe_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxDecIm[ch][slot], hDiracDecBin->processMtxDecIm_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxDecRePrev[ch][slot], hDiracDecBin->processMtxDecRePrev_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxDecImPrev[ch][slot], hDiracDecBin->processMtxDecImPrev_fx[ch][slot], q_mat, nBins ); + Scale_sig( hDiracDecBin->processMtxRe_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtx ) ); + Scale_sig( hDiracDecBin->processMtxIm_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtx ) ); + Scale_sig( hDiracDecBin->processMtxRePrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxPrev ) ); + Scale_sig( hDiracDecBin->processMtxImPrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxPrev ) ); + Scale_sig( hDiracDecBin->processMtxDecRe_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDec ) ); + Scale_sig( hDiracDecBin->processMtxDecIm_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDec ) ); + Scale_sig( hDiracDecBin->processMtxDecRePrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDecPrev ) ); + Scale_sig( hDiracDecBin->processMtxDecImPrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDecPrev ) ); } - } - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - FOR( slot = 0; slot < numInChannels; slot++ ) + FOR( slot = 0; slot < nchanSeparateChannels; slot++ ) { - floatToFixed_arr16( hDiracDecBin->processMtxRe[ch][slot], hDiracDecBin->processMtxRe_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxIm[ch][slot], hDiracDecBin->processMtxIm_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxRePrev[ch][slot], hDiracDecBin->processMtxRePrev_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxImPrev[ch][slot], hDiracDecBin->processMtxImPrev_fx[ch][slot], q_mat, nBins ); + Scale_sig( hDiracDecBin->processMtxRe_fx[ch][slot + BINAURAL_CHANNELS], nBins, sub( q_mat, hDiracDecBin->q_processMtx ) ); + Scale_sig( hDiracDecBin->processMtxIm_fx[ch][slot + BINAURAL_CHANNELS], nBins, sub( q_mat, hDiracDecBin->q_processMtx ) ); + Scale_sig( hDiracDecBin->processMtxRePrev_fx[ch][slot + BINAURAL_CHANNELS], nBins, sub( q_mat, hDiracDecBin->q_processMtxPrev ) ); + Scale_sig( hDiracDecBin->processMtxImPrev_fx[ch][slot + BINAURAL_CHANNELS], nBins, sub( q_mat, hDiracDecBin->q_processMtxPrev ) ); } - st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } -#endif + hDiracDecBin->q_processMtx = q_mat; + hDiracDecBin->q_processMtxPrev = q_mat; + hDiracDecBin->q_processMtxDec = q_mat; + hDiracDecBin->q_processMtxDecPrev = q_mat; + ivas_dirac_dec_binaural_process_output_fx( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_fx, &q_out, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_inp, max_band_decorr, numInChannels, config_data.processReverb, subframe, q_mat ); hDiracDecBin->hDiffuseDist = NULL; @@ -2221,7 +2171,6 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric Word16 nchan_transport; Word16 gainCacheBaseIndex; Word16 q_earlyPartEneCorrection; - q_earlyPartEneCorrection = hDiracDecBin->q_earlyPartEneCorrection; separateCenterChannelRendering = hConfig->separateCenterChannelRendering; move16(); @@ -2237,6 +2186,10 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric nBins = hSpatParamRendCom->num_freq_bands; /* Actually bins */ move16(); + q_earlyPartEneCorrection = s_min( Q31, add( getScaleFactor32( hDiracDecBin->earlyPartEneCorrection_fx, nBins ), hDiracDecBin->q_earlyPartEneCorrection ) ); + scale_sig32( hDiracDecBin->earlyPartEneCorrection_fx, nBins, sub( q_earlyPartEneCorrection, hDiracDecBin->q_earlyPartEneCorrection ) ); + hDiracDecBin->q_earlyPartEneCorrection = q_earlyPartEneCorrection; + set32_fx( hDiracDecBin->ChCrossRe_fx, 0, nBins ); set32_fx( hDiracDecBin->ChCrossIm_fx, 0, nBins ); set32_fx( hDiracDecBin->ChCrossReOut_fx, 0, nBins ); @@ -2810,6 +2763,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric } #endif +#ifndef IVAS_FLOAT_FIXED static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, @@ -2857,32 +2811,266 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( float CrEneL, CrEneR; /* Cr = residual decorrelated sound covariance matrix */ float CrCrossRe, CrCrossIm; float Mre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Mim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], MdecRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], MdecIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; /* M = mixing matrix; Mdec = residual decorrelated signal mixing matrix */ -#ifndef IVAS_FLOAT_FIXED - float prototypeMtx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] = { { 1.0f, 0.05f }, { 0.05f, 1.0f } }; /* Prototype matrix determines a reference signal in mixing matrix determination */ -#endif + float prototypeMtx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] = { { 1.0f, 0.05f }, { 0.05f, 1.0f } }; /* Prototype matrix determines a reference signal in mixing matrix determination */ + CrEneL = 0.0f; CrEneR = 0.0f; /* Formulate main processing matrix M */ -#ifndef IVAS_FLOAT_FIXED formulate2x2MixingMatrix( hDiracDecBin->ChEne[0][bin], hDiracDecBin->ChEne[1][bin], hDiracDecBin->ChCrossRe[bin], hDiracDecBin->ChCrossIm[bin], hDiracDecBin->ChEneOut[0][bin], hDiracDecBin->ChEneOut[1][bin], hDiracDecBin->ChCrossReOut[bin], hDiracDecBin->ChCrossImOut[bin], prototypeMtx, Mre, Mim, -#ifdef IVAS_FLOAT_FIXED - fix16_to_float( hDiracDecBin->reqularizationFactor_fx, Q14 ) ); -#else hDiracDecBin->reqularizationFactor ); -#endif + + /* Load estimated covariance matrix to the [2][2] matrix form */ + CxRe[0][0] = hDiracDecBin->ChEne[0][bin]; + CxRe[1][1] = hDiracDecBin->ChEne[1][bin]; + CxRe[1][0] = hDiracDecBin->ChCrossRe[bin]; + CxRe[0][1] = hDiracDecBin->ChCrossRe[bin]; + CxIm[0][0] = 0.0f; + CxIm[1][1] = 0.0f; + CxIm[1][0] = hDiracDecBin->ChCrossIm[bin]; + CxIm[0][1] = -hDiracDecBin->ChCrossIm[bin]; + + /* Make matrix multiplication M*Cx*M' to determine resulting covariance matrix of processing input with M */ + matrixMul( Mre, Mim, CxRe, CxIm, tmpMtxRe, tmpMtxIm ); + matrixTransp2Mul( tmpMtxRe, tmpMtxIm, Mre, Mim, resultMtxRe, resultMtxIm ); + + /* When below the frequency limit where decorrelation is applied, we inject the decorrelated + * residual (or missing) signal component. The procedure is active when there are not enough independent + * signal energy to synthesize a signal with the target covariance matrix from the non-decorrelated signals */ + if ( bin < max_band_decorr ) + { + float decorrelationReductionFactor; + + /* Subtract the resulting covariance matrix from the target covariance matrix to determine + * what signal component is missing. The result is the target covariance matrix for the residual signal, i.e., + * a residual covariance matrix. */ + CrEneL = max( 0.0f, hDiracDecBin->ChEneOut[0][bin] - resultMtxRe[0][0] ); + CrEneR = max( 0.0f, hDiracDecBin->ChEneOut[1][bin] - resultMtxRe[1][1] ); + CrCrossRe = hDiracDecBin->ChCrossReOut[bin] - resultMtxRe[1][0]; + CrCrossIm = hDiracDecBin->ChCrossImOut[bin] - resultMtxIm[1][0]; + + /* The amount of the decorrelated sound is further controlled based on the spatial metadata, + * by determining an energy-suppressed residual covariance matrix that is a control parameter + * that guides the processing of the decorrelated sound to a residual signal. + * The procedure improves quality in e.g. double-talk 2-direction rendering situations.*/ + if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + { + decorrelationReductionFactor = 1.0f; + } + else if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) || ( ivas_format == MASA_FORMAT && nchan_transport == 1 ) ) + { + decorrelationReductionFactor = sqrtf( fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] ) ); + } + else if ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && nchan_transport == 1 ) + { + decorrelationReductionFactor = 1.0f; + } + else + { + decorrelationReductionFactor = fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] ); + } + CrEneL *= decorrelationReductionFactor; + CrEneR *= decorrelationReductionFactor; + CrCrossRe *= decorrelationReductionFactor; + CrCrossIm *= decorrelationReductionFactor; + + /* Determine a residual mixing matrix Mdec for processing the decorrelated signal to obtain + * the residual signal (that has the residual covariance matrix) */ + formulate2x2MixingMatrix( hDiracDecBin->ChEne[0][bin], hDiracDecBin->ChEne[1][bin], + 0.0f, 0.0f, /* Decorrelated signal has ideally no cross-terms */ + CrEneL, CrEneR, + CrCrossRe, CrCrossIm, + prototypeMtx, MdecRe, MdecIm, 0.2f ); + } + else + { + for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + set_zero( MdecRe[chA], BINAURAL_CHANNELS ); + set_zero( MdecIm[chA], BINAURAL_CHANNELS ); + } + } + + /* The regularizations at determining mixing matrices cause signal energy to be lost to some degree, which is compensated for here */ + realizedOutputEne = CrEneL + CrEneR + resultMtxRe[0][0] + resultMtxRe[1][1]; + targetOutputEne = hDiracDecBin->ChEneOut[0][bin] + hDiracDecBin->ChEneOut[1][bin]; + missingOutputEne = fmaxf( 0.0f, targetOutputEne - realizedOutputEne ); + + gain = sqrtf( ( resultMtxRe[0][0] + resultMtxRe[1][1] + missingOutputEne ) / + fmaxf( 1e-12f, resultMtxRe[0][0] + resultMtxRe[1][1] ) ); + gain = fminf( 4.0f, gain ); + + for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + for ( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + { + Mre[chA][chB] *= gain; + Mim[chA][chB] *= gain; + } + } + + /* Store processing matrices */ + for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + for ( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + { + hDiracDecBin->processMtxRePrev[chA][chB][bin] = hDiracDecBin->processMtxRe[chA][chB][bin]; + hDiracDecBin->processMtxImPrev[chA][chB][bin] = hDiracDecBin->processMtxIm[chA][chB][bin]; + hDiracDecBin->processMtxDecRePrev[chA][chB][bin] = hDiracDecBin->processMtxDecRe[chA][chB][bin]; + hDiracDecBin->processMtxDecImPrev[chA][chB][bin] = hDiracDecBin->processMtxDecIm[chA][chB][bin]; + + hDiracDecBin->processMtxRe[chA][chB][bin] = Mre[chA][chB]; + hDiracDecBin->processMtxIm[chA][chB][bin] = Mim[chA][chB]; + hDiracDecBin->processMtxDecRe[chA][chB][bin] = MdecRe[chA][chB]; + hDiracDecBin->processMtxDecIm[chA][chB][bin] = MdecIm[chA][chB]; + } + } + + if ( separateCenterChannelRendering ) + { + /* The rendering of the separate center channel in masa + mono mode. + * The center channel is processed with a gain factor 0.8414f to match the loudness of different processing paths */ + float lRealp, lImagp, rRealp, rImagp; + float gainFactor; + int16_t aziDeg = 0; + int16_t eleDeg = 0; + uint8_t instantChange = 0; + + if ( ivas_format == MASA_ISM_FORMAT ) + { + gainFactor = 0.7943f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); + } + else + { + gainFactor = 0.8414f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); + } + + for ( chB = 0; chB < nchanSeparateChannels; chB++ ) + { + if ( ivas_format == MASA_ISM_FORMAT ) + { + if ( ism_mode == ISM_MASA_MODE_DISC ) + { + aziDeg = hMasaIsmData->azimuth_ism[chB][dirac_read_idx]; + eleDeg = hMasaIsmData->elevation_ism[chB][dirac_read_idx]; + } + else + { + aziDeg = hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; + eleDeg = hMasaIsmData->elevation_separated_ism[dirac_read_idx]; + instantChange = 1; + } + } + + for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + hDiracDecBin->processMtxRePrev[chA][chB + 2][bin] = hDiracDecBin->processMtxRe[chA][chB + 2][bin]; + hDiracDecBin->processMtxImPrev[chA][chB + 2][bin] = hDiracDecBin->processMtxIm[chA][chB + 2][bin]; + } + + getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); + + hDiracDecBin->processMtxRe[0][chB + 2][bin] = lRealp * gainFactor; + hDiracDecBin->processMtxIm[0][chB + 2][bin] = lImagp * gainFactor; + hDiracDecBin->processMtxRe[1][chB + 2][bin] = rRealp * gainFactor; + hDiracDecBin->processMtxIm[1][chB + 2][bin] = rImagp * gainFactor; + + if ( instantChange ) + { + for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + hDiracDecBin->processMtxRePrev[chA][chB + 2][bin] = hDiracDecBin->processMtxRe[chA][chB + 2][bin]; + hDiracDecBin->processMtxImPrev[chA][chB + 2][bin] = hDiracDecBin->processMtxIm[chA][chB + 2][bin]; + } + } + } + } + } + + return; +} #else - Word16 q_M, q_Mdec = 0, q_CrEne, q_CrCross; - Word32 prototypeMtx_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] = { { ONE_IN_Q31, 107374182 }, { 107374182, ONE_IN_Q31 } }; - Word32 Mre_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Mim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], MdecRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], MdecIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; /* M = mixing matrix; Mdec = residual decorrelated signal mixing matrix */ - Word32 CrEneL_fx, CrEneR_fx; /* Cr = residual decorrelated sound covariance matrix */ +static void ivas_dirac_dec_binaural_determine_processing_matrices_fx( + DIRAC_DEC_BIN_HANDLE hDiracDecBin, + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, + PARAMBIN_REND_CONFIG_HANDLE hConfig, + const Word16 max_band_decorr, + Word32 Rmat[3][3], + const Word16 subframe, + const Word16 isHeadtracked, + const Word16 nchanSeparateChannels, + const MASA_ISM_DATA_HANDLE hMasaIsmData ) +{ + Word16 chA, chB, bin; + Word16 separateCenterChannelRendering; + Word16 nBins; + Word16 dirac_read_idx; + PARAMBIN_HRTF_GAIN_CACHE gainCache[MAX_NUM_OBJECTS]; + Word16 idx; + ISM_MODE ism_mode; + IVAS_FORMAT ivas_format; + MC_MODE mc_mode; + Word32 ivas_total_brate; + Word16 nchan_transport; + Word16 exp; + Word16 q_processMtx[CLDFB_NO_CHANNELS_MAX], q_processMtxPrev[CLDFB_NO_CHANNELS_MAX]; + Word16 q_processMtx_SCCR[CLDFB_NO_CHANNELS_MAX], q_processMtxPrev_SCCR[CLDFB_NO_CHANNELS_MAX]; + Word16 q_processMtxDec[CLDFB_NO_CHANNELS_MAX], q_processMtxDecPrev[CLDFB_NO_CHANNELS_MAX]; + set_s( q_processMtx, hDiracDecBin->q_processMtx, CLDFB_NO_CHANNELS_MAX ); + set_s( q_processMtxPrev, hDiracDecBin->q_processMtxPrev, CLDFB_NO_CHANNELS_MAX ); + set_s( q_processMtx_SCCR, hDiracDecBin->q_processMtx, CLDFB_NO_CHANNELS_MAX ); + set_s( q_processMtxPrev_SCCR, hDiracDecBin->q_processMtxPrev, CLDFB_NO_CHANNELS_MAX ); + set_s( q_processMtxDec, hDiracDecBin->q_processMtxDec, CLDFB_NO_CHANNELS_MAX ); + set_s( q_processMtxDecPrev, hDiracDecBin->q_processMtxDecPrev, CLDFB_NO_CHANNELS_MAX ); + + ivas_format = hConfig->ivas_format; + separateCenterChannelRendering = extract_l( GT_16( nchanSeparateChannels, 0 ) ); + move16(); + mc_mode = hConfig->mc_mode; + ivas_total_brate = hConfig->ivas_total_brate; + move32(); + nchan_transport = hConfig->nchan_transport; + move16(); + nBins = hSpatParamRendCom->num_freq_bands; /* Actually bins */ + move16(); + + ism_mode = hConfig->ism_mode; + + dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; + move16(); + + FOR( idx = 0; idx < MAX_NUM_OBJECTS; idx++ ) + { + gainCache[idx].azi = -1000; /* Use -1000 as value for uninitialized cache. */ + move16(); + } + + FOR( bin = 0; bin < nBins; bin++ ) + { + Word32 tmpMtxRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], tmpMtxIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], resultMtxRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], resultMtxIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], gain_fx; + Word32 CxRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], CxIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; /* Input covariance matrix */ + Word32 realizedOutputEne_fx, targetOutputEne_fx, missingOutputEne_fx; + Word32 CrEneL_fx, CrEneR_fx; /* Cr = residual decorrelated sound covariance matrix */ Word32 CrCrossRe_fx, CrCrossIm_fx; + Word32 Mre_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Mim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], MdecRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], MdecIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; /* M = mixing matrix; Mdec = residual decorrelated signal mixing matrix */ + Word32 prototypeMtx_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS] = { { ONE_IN_Q31, 107374182 }, { 107374182, ONE_IN_Q31 } }; + Word16 q_M, q_Cx, q_tmp, q_res, q_CrEne, q_CrCross, q_Mdec = 0; + Word32 tmp1, tmp2, res1, res2; + Word16 q_tmp1, q_tmp2, q_realizedOutputEne, q_targetOutputEne, q_missingOutputEne, q_gain; + Word16 exp1, exp2, q_processMtx_bin, q_processMtxDec_bin; - IF( hDiracDecBin->ChEne_e[0][bin] > hDiracDecBin->ChEne_e[1][bin] ) + CrEneL_fx = 0; + move32(); + CrEneR_fx = 0; + move32(); + q_CrEne = Q31; + move16(); + + IF( GT_16( hDiracDecBin->ChEne_e[0][bin], hDiracDecBin->ChEne_e[1][bin] ) ) { hDiracDecBin->ChEne_fx[1][bin] = L_shr( hDiracDecBin->ChEne_fx[1][bin], sub( hDiracDecBin->ChEne_e[0][bin], hDiracDecBin->ChEne_e[1][bin] ) ); hDiracDecBin->q_ChEne = 31 - hDiracDecBin->ChEne_e[0][bin]; @@ -2894,7 +3082,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin->q_ChEne = 31 - hDiracDecBin->ChEne_e[1][bin]; hDiracDecBin->ChEne_e[0][bin] = hDiracDecBin->ChEne_e[1][bin]; } - IF( hDiracDecBin->ChEneOut_e[0][bin] > hDiracDecBin->ChEneOut_e[1][bin] ) + IF( GT_16( hDiracDecBin->ChEneOut_e[0][bin], hDiracDecBin->ChEneOut_e[1][bin] ) ) { hDiracDecBin->ChEneOut_fx[1][bin] = L_shr( hDiracDecBin->ChEneOut_fx[1][bin], sub( hDiracDecBin->ChEneOut_e[0][bin], hDiracDecBin->ChEneOut_e[1][bin] ) ); hDiracDecBin->q_ChEneOut = 31 - hDiracDecBin->ChEneOut_e[0][bin]; @@ -2907,7 +3095,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin->ChEneOut_e[0][bin] = hDiracDecBin->ChEneOut_e[1][bin]; } - IF( hDiracDecBin->ChCrossRe_e[bin] > hDiracDecBin->ChCrossIm_e[bin] ) + IF( GT_16( hDiracDecBin->ChCrossRe_e[bin], hDiracDecBin->ChCrossIm_e[bin] ) ) { hDiracDecBin->ChCrossIm_fx[bin] = L_shr( hDiracDecBin->ChCrossIm_fx[bin], sub( hDiracDecBin->ChCrossRe_e[bin], hDiracDecBin->ChCrossIm_e[bin] ) ); hDiracDecBin->q_ChCross = 31 - hDiracDecBin->ChCrossRe_e[bin]; @@ -2919,7 +3107,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin->q_ChCross = 31 - hDiracDecBin->ChCrossIm_e[bin]; hDiracDecBin->ChCrossRe_e[bin] = hDiracDecBin->ChCrossIm_e[bin]; } - IF( hDiracDecBin->ChCrossReOut_e[bin] > hDiracDecBin->ChCrossImOut_e[bin] ) + IF( GT_16( hDiracDecBin->ChCrossReOut_e[bin], hDiracDecBin->ChCrossImOut_e[bin] ) ) { hDiracDecBin->ChCrossImOut_fx[bin] = L_shr( hDiracDecBin->ChCrossImOut_fx[bin], sub( hDiracDecBin->ChCrossReOut_e[bin], hDiracDecBin->ChCrossImOut_e[bin] ) ); hDiracDecBin->q_ChCrossOut = 31 - hDiracDecBin->ChCrossReOut_e[bin]; @@ -2942,237 +3130,434 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin->q_ChCrossOut, prototypeMtx_fx, Mre_fx, Mim_fx, &q_M, hDiracDecBin->reqularizationFactor_fx ); - for ( int a = 0; a < BINAURAL_CHANNELS; a++ ) + IF( LT_16( hDiracDecBin->q_ChEne, hDiracDecBin->q_ChCross ) ) { - for ( int b = 0; b < BINAURAL_CHANNELS; b++ ) - { - Mre[a][b] = (float) Mre_fx[a][b] / (float) pow( 2, q_M ); - Mim[a][b] = (float) Mim_fx[a][b] / (float) pow( 2, q_M ); - } + CxRe_fx[0][0] = hDiracDecBin->ChEne_fx[0][bin]; + move32(); + CxRe_fx[1][1] = hDiracDecBin->ChEne_fx[1][bin]; + move32(); + CxRe_fx[1][0] = L_shr( hDiracDecBin->ChCrossRe_fx[bin], sub( hDiracDecBin->q_ChCross, hDiracDecBin->q_ChEne ) ); + move32(); + CxRe_fx[0][1] = L_shr( hDiracDecBin->ChCrossRe_fx[bin], sub( hDiracDecBin->q_ChCross, hDiracDecBin->q_ChEne ) ); + move32(); + CxIm_fx[0][0] = 0; + move32(); + CxIm_fx[1][1] = 0; + move32(); + CxIm_fx[1][0] = L_shr( hDiracDecBin->ChCrossIm_fx[bin], sub( hDiracDecBin->q_ChCross, hDiracDecBin->q_ChEne ) ); + move32(); + CxIm_fx[0][1] = L_shr( -hDiracDecBin->ChCrossIm_fx[bin], sub( hDiracDecBin->q_ChCross, hDiracDecBin->q_ChEne ) ); + move32(); + q_Cx = hDiracDecBin->q_ChEne; + move16(); + } + ELSE + { + CxRe_fx[0][0] = L_shr( hDiracDecBin->ChEne_fx[0][bin], sub( hDiracDecBin->q_ChEne, hDiracDecBin->q_ChCross ) ); + move32(); + CxRe_fx[1][1] = L_shr( hDiracDecBin->ChEne_fx[1][bin], sub( hDiracDecBin->q_ChEne, hDiracDecBin->q_ChCross ) ); + move32(); + CxRe_fx[1][0] = hDiracDecBin->ChCrossRe_fx[bin]; + move32(); + CxRe_fx[0][1] = hDiracDecBin->ChCrossRe_fx[bin]; + move32(); + CxIm_fx[0][0] = 0; + move32(); + CxIm_fx[1][1] = 0; + move32(); + CxIm_fx[1][0] = hDiracDecBin->ChCrossIm_fx[bin]; + move32(); + CxIm_fx[0][1] = -hDiracDecBin->ChCrossIm_fx[bin]; + move32(); + q_Cx = hDiracDecBin->q_ChCross; + move16(); } -#endif - - /* Load estimated covariance matrix to the [2][2] matrix form */ - CxRe[0][0] = hDiracDecBin->ChEne[0][bin]; - CxRe[1][1] = hDiracDecBin->ChEne[1][bin]; - CxRe[1][0] = hDiracDecBin->ChCrossRe[bin]; - CxRe[0][1] = hDiracDecBin->ChCrossRe[bin]; - CxIm[0][0] = 0.0f; - CxIm[1][1] = 0.0f; - CxIm[1][0] = hDiracDecBin->ChCrossIm[bin]; - CxIm[0][1] = -hDiracDecBin->ChCrossIm[bin]; /* Make matrix multiplication M*Cx*M' to determine resulting covariance matrix of processing input with M */ - matrixMul( Mre, Mim, CxRe, CxIm, tmpMtxRe, tmpMtxIm ); - matrixTransp2Mul( tmpMtxRe, tmpMtxIm, Mre, Mim, resultMtxRe, resultMtxIm ); + matrixMul_fx( Mre_fx, Mim_fx, &q_M, CxRe_fx, CxIm_fx, &q_Cx, tmpMtxRe_fx, tmpMtxIm_fx, &q_tmp ); + matrixTransp2Mul_fx( tmpMtxRe_fx, tmpMtxIm_fx, &q_tmp, Mre_fx, Mim_fx, &q_M, resultMtxRe_fx, resultMtxIm_fx, &q_res ); /* When below the frequency limit where decorrelation is applied, we inject the decorrelated * residual (or missing) signal component. The procedure is active when there are not enough independent * signal energy to synthesize a signal with the target covariance matrix from the non-decorrelated signals */ - if ( bin < max_band_decorr ) + IF( LT_16( bin, max_band_decorr ) ) { - float decorrelationReductionFactor; + Word32 decorrelationReductionFactor_fx; + Word16 q_decorrelationReductionFactor; /* Subtract the resulting covariance matrix from the target covariance matrix to determine * what signal component is missing. The result is the target covariance matrix for the residual signal, i.e., - * a residual covariance matrix. */ - CrEneL = max( 0.0f, hDiracDecBin->ChEneOut[0][bin] - resultMtxRe[0][0] ); - CrEneR = max( 0.0f, hDiracDecBin->ChEneOut[1][bin] - resultMtxRe[1][1] ); - CrCrossRe = hDiracDecBin->ChCrossReOut[bin] - resultMtxRe[1][0]; - CrCrossIm = hDiracDecBin->ChCrossImOut[bin] - resultMtxIm[1][0]; - - /* The amount of the decorrelated sound is further controlled based on the spatial metadata, - * by determining an energy-suppressed residual covariance matrix that is a control parameter - * that guides the processing of the decorrelated sound to a residual signal. - * The procedure improves quality in e.g. double-talk 2-direction rendering situations.*/ - if ( ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE ) + * a residual covariance matrix. */ + exp = sub( get_min_scalefactor( hDiracDecBin->ChEneOut_fx[0][bin], hDiracDecBin->ChEneOut_fx[1][bin] ), 3 ); + tmp1 = L_shl( hDiracDecBin->ChEneOut_fx[0][bin], exp ); + tmp2 = L_shl( hDiracDecBin->ChEneOut_fx[1][bin], exp ); + q_tmp1 = add( hDiracDecBin->q_ChEneOut, exp ); + + exp = sub( get_min_scalefactor( resultMtxRe_fx[0][0], resultMtxRe_fx[1][1] ), 3 ); + res1 = L_shl( resultMtxRe_fx[0][0], exp ); + res2 = L_shl( resultMtxRe_fx[1][1], exp ); + q_tmp2 = add( q_res, exp ); + + IF( LT_16( q_tmp1, q_tmp2 ) ) { - decorrelationReductionFactor = 1.0f; + CrEneL_fx = L_max( 0, L_sub( tmp1, L_shr( res1, sub( q_tmp2, q_tmp1 ) ) ) ); + CrEneR_fx = L_max( 0, L_sub( tmp2, L_shr( res2, sub( q_tmp2, q_tmp1 ) ) ) ); + q_CrEne = q_tmp1; + move16(); } - else if ( ( ivas_format == MC_FORMAT && mc_mode == MC_MODE_MCMASA ) || ( ivas_format == MASA_FORMAT && nchan_transport == 1 ) ) + ELSE { - decorrelationReductionFactor = sqrtf( fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] ) ); + CrEneL_fx = L_max( 0, L_sub( L_shr( tmp1, sub( q_tmp1, q_tmp2 ) ), res1 ) ); + CrEneR_fx = L_max( 0, L_sub( L_shr( tmp2, sub( q_tmp1, q_tmp2 ) ), res2 ) ); + q_CrEne = q_tmp2; + move16(); } - else if ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && nchan_transport == 1 ) + + exp = sub( get_min_scalefactor( hDiracDecBin->ChCrossReOut_fx[bin], hDiracDecBin->ChCrossImOut_fx[bin] ), 3 ); + tmp1 = L_shl( hDiracDecBin->ChCrossReOut_fx[bin], exp ); + tmp2 = L_shl( hDiracDecBin->ChCrossImOut_fx[bin], exp ); + q_tmp1 = add( hDiracDecBin->q_ChCrossOut, exp ); + + exp = sub( get_min_scalefactor( resultMtxRe_fx[1][0], resultMtxIm_fx[1][0] ), 3 ); + res1 = L_shl( resultMtxRe_fx[1][0], exp ); + res2 = L_shl( resultMtxIm_fx[1][0], exp ); + q_tmp2 = add( q_res, exp ); + + IF( LT_16( q_tmp1, q_tmp2 ) ) { - decorrelationReductionFactor = 1.0f; + CrCrossRe_fx = L_sub( tmp1, L_shr( res1, sub( q_tmp2, q_tmp1 ) ) ); + CrCrossIm_fx = L_sub( tmp2, L_shr( res2, sub( q_tmp2, q_tmp1 ) ) ); + q_CrCross = q_tmp1; + move16(); } - else + ELSE { - decorrelationReductionFactor = fmaxf( 0.0f, hDiracDecBin->frameMeanDiffuseness[bin] ); + CrCrossRe_fx = L_sub( L_shr( tmp1, sub( q_tmp1, q_tmp2 ) ), res1 ); + CrCrossIm_fx = L_sub( L_shr( tmp2, sub( q_tmp1, q_tmp2 ) ), res2 ); + q_CrCross = q_tmp2; + move16(); } - CrEneL *= decorrelationReductionFactor; - CrEneR *= decorrelationReductionFactor; - CrCrossRe *= decorrelationReductionFactor; - CrCrossIm *= decorrelationReductionFactor; - - /* Determine a residual mixing matrix Mdec for processing the decorrelated signal to obtain - * the residual signal (that has the residual covariance matrix) */ -#ifndef IVAS_FLOAT_FIXED - formulate2x2MixingMatrix( hDiracDecBin->ChEne[0][bin], hDiracDecBin->ChEne[1][bin], - 0.0f, 0.0f, /* Decorrelated signal has ideally no cross-terms */ - CrEneL, CrEneR, - CrCrossRe, CrCrossIm, - prototypeMtx, MdecRe, MdecIm, 0.2f ); -#else - int16_t exp, exp1; - f2me( CrEneL, &CrEneL_fx, &exp ); - f2me( CrEneR, &CrEneR_fx, &exp1 ); - if ( exp > exp1 ) + /* The amount of the decorrelated sound is further controlled based on the spatial metadata, + * by determining an energy-suppressed residual covariance matrix that is a control parameter + * that guides the processing of the decorrelated sound to a residual signal. + * The procedure improves quality in e.g. double-talk 2-direction rendering situations.*/ + IF( EQ_16( ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) { - CrEneR_fx = L_shr( CrEneR_fx, exp - exp1 ); - q_CrEne = 31 - exp; + decorrelationReductionFactor_fx = ONE_IN_Q30; + move32(); + q_decorrelationReductionFactor = Q30; + move16(); } - else + ELSE IF( L_or( L_and( EQ_16( ivas_format, MC_FORMAT ), EQ_16( mc_mode, MC_MODE_MCMASA ) ), L_and( EQ_16( ivas_format, MASA_FORMAT ), EQ_16( nchan_transport, 1 ) ) ) ) { - CrEneL_fx = L_shr( CrEneL_fx, exp1 - exp ); - q_CrEne = 31 - exp1; + exp = sub( 31, 29 ); + decorrelationReductionFactor_fx = Sqrt32( L_max( 0, hDiracDecBin->frameMeanDiffuseness_fx[bin] ), &exp ); + q_decorrelationReductionFactor = sub( 31, exp ); } - - f2me( CrCrossRe, &CrCrossRe_fx, &exp ); - f2me( CrCrossIm, &CrCrossIm_fx, &exp1 ); - if ( exp > exp1 ) + ELSE IF( L_and( L_or( EQ_16( ivas_format, SBA_FORMAT ), EQ_16( ivas_format, SBA_ISM_FORMAT ) ), EQ_16( nchan_transport, 1 ) ) ) { - CrCrossIm_fx = L_shr( CrCrossIm_fx, exp - exp1 ); - q_CrCross = 31 - exp; + decorrelationReductionFactor_fx = ONE_IN_Q30; + move32(); + q_decorrelationReductionFactor = Q30; + move16(); } - else + ELSE { - CrCrossRe_fx = L_shr( CrCrossRe_fx, exp1 - exp ); - q_CrCross = 31 - exp1; + decorrelationReductionFactor_fx = L_max( 0, hDiracDecBin->frameMeanDiffuseness_fx[bin] ); + q_decorrelationReductionFactor = 29; + move16(); } + CrEneL_fx = Mpy_32_32( CrEneL_fx, decorrelationReductionFactor_fx ); + CrEneR_fx = Mpy_32_32( CrEneR_fx, decorrelationReductionFactor_fx ); + q_CrEne = sub( add( q_CrEne, q_decorrelationReductionFactor ), 31 ); + CrCrossRe_fx = Mpy_32_32( CrCrossRe_fx, decorrelationReductionFactor_fx ); + CrCrossIm_fx = Mpy_32_32( CrCrossIm_fx, decorrelationReductionFactor_fx ); + q_CrCross = sub( add( q_CrCross, q_decorrelationReductionFactor ), 31 ); + formulate2x2MixingMatrix_fx( hDiracDecBin->ChEne_fx[0][bin], hDiracDecBin->ChEne_fx[1][bin], hDiracDecBin->q_ChEne, 0, 0, /* Decorrelated signal has ideally no cross-terms */ Q31, CrEneL_fx, CrEneR_fx, q_CrEne, CrCrossRe_fx, CrCrossIm_fx, q_CrCross, prototypeMtx_fx, MdecRe_fx, MdecIm_fx, &q_Mdec, 3277 ); // 3277 = 0.2 in Q14 - - for ( int a = 0; a < BINAURAL_CHANNELS; a++ ) - { - for ( int b = 0; b < BINAURAL_CHANNELS; b++ ) - { - MdecRe[a][b] = (float) MdecRe_fx[a][b] / (float) pow( 2, q_Mdec ); - MdecIm[a][b] = (float) MdecIm_fx[a][b] / (float) pow( 2, q_Mdec ); - } - } -#endif } - else + ELSE { - for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { - set_zero( MdecRe[chA], BINAURAL_CHANNELS ); - set_zero( MdecIm[chA], BINAURAL_CHANNELS ); + set_zero_fx( MdecRe_fx[chA], BINAURAL_CHANNELS ); + set_zero_fx( MdecIm_fx[chA], BINAURAL_CHANNELS ); } + q_Mdec = Q31; + move16(); } /* The regularizations at determining mixing matrices cause signal energy to be lost to some degree, which is compensated for here */ - realizedOutputEne = CrEneL + CrEneR + resultMtxRe[0][0] + resultMtxRe[1][1]; - targetOutputEne = hDiracDecBin->ChEneOut[0][bin] + hDiracDecBin->ChEneOut[1][bin]; - missingOutputEne = fmaxf( 0.0f, targetOutputEne - realizedOutputEne ); + tmp1 = L_add( CrEneL_fx, CrEneR_fx ); + exp = sub( get_min_scalefactor( resultMtxRe_fx[0][0], resultMtxRe_fx[1][1] ), 2 ); + tmp2 = L_add( L_shl( resultMtxRe_fx[0][0], exp ), L_shl( resultMtxRe_fx[1][1], exp ) ); + q_tmp2 = add( q_res, exp ); + IF( LT_16( q_CrEne, q_tmp2 ) ) + { + realizedOutputEne_fx = L_add( tmp1, L_shr( tmp2, sub( q_tmp2, q_CrEne ) ) ); + q_realizedOutputEne = q_CrEne; + move16(); + } + ELSE + { + realizedOutputEne_fx = L_add( L_shr( tmp1, sub( q_CrEne, q_tmp2 ) ), tmp2 ); + q_realizedOutputEne = q_tmp2; + move16(); + } - gain = sqrtf( ( resultMtxRe[0][0] + resultMtxRe[1][1] + missingOutputEne ) / - fmaxf( 1e-12f, resultMtxRe[0][0] + resultMtxRe[1][1] ) ); - gain = fminf( 4.0f, gain ); + exp = sub( get_min_scalefactor( hDiracDecBin->ChEneOut_fx[0][bin], hDiracDecBin->ChEneOut_fx[1][bin] ), 1 ); + targetOutputEne_fx = L_add( L_shl( hDiracDecBin->ChEneOut_fx[0][bin], exp ), L_shl( hDiracDecBin->ChEneOut_fx[1][bin], exp ) ); + q_targetOutputEne = add( hDiracDecBin->q_ChEneOut, exp ); - for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + exp = sub( norm_l( targetOutputEne_fx ), 2 ); + targetOutputEne_fx = L_shl( targetOutputEne_fx, exp ); + q_targetOutputEne = add( q_targetOutputEne, exp ); + exp = sub( norm_l( -realizedOutputEne_fx ), 2 ); + realizedOutputEne_fx = L_shl( -realizedOutputEne_fx, exp ); + q_realizedOutputEne = add( q_realizedOutputEne, exp ); + IF( LT_16( q_realizedOutputEne, q_targetOutputEne ) ) { - for ( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + missingOutputEne_fx = L_max( 0, L_add( L_shr( targetOutputEne_fx, sub( q_targetOutputEne, q_realizedOutputEne ) ), realizedOutputEne_fx ) ); + q_missingOutputEne = q_realizedOutputEne; + move16(); + } + ELSE + { + missingOutputEne_fx = L_max( 0, L_add( targetOutputEne_fx, L_shr( realizedOutputEne_fx, sub( q_realizedOutputEne, q_targetOutputEne ) ) ) ); + q_missingOutputEne = q_targetOutputEne; + move16(); + } + + tmp1 = BASOP_Util_Add_Mant32Exp( tmp2, sub( 31, q_tmp2 ), missingOutputEne_fx, sub( 31, q_missingOutputEne ), &exp1 ); + + { + Word16 exp_temp; + tmp2 = BASOP_Util_Add_Mant32Exp( tmp2, sub( 31, q_tmp2 ), EPSILON_MANT, EPSILON_EXP, &exp_temp ); + tmp2 = BASOP_Util_Divide3232_Scale_cadence( tmp1, tmp2, &exp ); + exp2 = add( exp, sub( exp1, exp_temp ) ); + } + gain_fx = Sqrt32( tmp2, &exp2 ); + q_gain = sub( 31, exp2 ); + + // 1073741824 = 4 in Q28 + IF( LT_16( q_gain, Q28 ) ) + { + gain_fx = L_min( gain_fx, L_shr( 1073741824, sub( Q28, q_gain ) ) ); + } + ELSE + { + gain_fx = L_min( L_shr( gain_fx, sub( q_gain, Q28 ) ), 1073741824 ); + q_gain = Q28; + move16(); + } + + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) { - Mre[chA][chB] *= gain; - Mim[chA][chB] *= gain; + Mre_fx[chA][chB] = Mpy_32_32( Mre_fx[chA][chB], gain_fx ); + move32(); + Mim_fx[chA][chB] = Mpy_32_32( Mim_fx[chA][chB], gain_fx ); + move32(); } } + q_M = sub( add( q_M, q_gain ), 31 ); + + exp = s_min( L_norm_arr( Mre_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ) ), L_norm_arr( Mim_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ) ) ); + scale_sig32( Mre_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ), exp ); + scale_sig32( Mim_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ), exp ); + q_M = add( q_M, exp ); + exp = s_min( L_norm_arr( MdecRe_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ) ), L_norm_arr( MdecIm_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ) ) ); + scale_sig32( MdecRe_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ), exp ); + scale_sig32( MdecIm_fx[0], i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ), exp ); + q_Mdec = add( q_Mdec, exp ); + + q_processMtx_bin = q_processMtx[bin]; + q_processMtxDec_bin = q_processMtxDec[bin]; /* Store processing matrices */ - for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { - for ( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) { - hDiracDecBin->processMtxRePrev[chA][chB][bin] = hDiracDecBin->processMtxRe[chA][chB][bin]; - hDiracDecBin->processMtxImPrev[chA][chB][bin] = hDiracDecBin->processMtxIm[chA][chB][bin]; - hDiracDecBin->processMtxDecRePrev[chA][chB][bin] = hDiracDecBin->processMtxDecRe[chA][chB][bin]; - hDiracDecBin->processMtxDecImPrev[chA][chB][bin] = hDiracDecBin->processMtxDecIm[chA][chB][bin]; + hDiracDecBin->processMtxRePrev_fx[chA][chB][bin] = hDiracDecBin->processMtxRe_fx[chA][chB][bin]; + move16(); + hDiracDecBin->processMtxImPrev_fx[chA][chB][bin] = hDiracDecBin->processMtxIm_fx[chA][chB][bin]; + move16(); - hDiracDecBin->processMtxRe[chA][chB][bin] = Mre[chA][chB]; - hDiracDecBin->processMtxIm[chA][chB][bin] = Mim[chA][chB]; - hDiracDecBin->processMtxDecRe[chA][chB][bin] = MdecRe[chA][chB]; - hDiracDecBin->processMtxDecIm[chA][chB][bin] = MdecIm[chA][chB]; + hDiracDecBin->processMtxDecRePrev_fx[chA][chB][bin] = hDiracDecBin->processMtxDecRe_fx[chA][chB][bin]; + move16(); + hDiracDecBin->processMtxDecImPrev_fx[chA][chB][bin] = hDiracDecBin->processMtxDecIm_fx[chA][chB][bin]; + move16(); + + hDiracDecBin->processMtxRe_fx[chA][chB][bin] = extract_h( Mre_fx[chA][chB] ); + move16(); + hDiracDecBin->processMtxIm_fx[chA][chB][bin] = extract_h( Mim_fx[chA][chB] ); + move16(); + + hDiracDecBin->processMtxDecRe_fx[chA][chB][bin] = extract_h( MdecRe_fx[chA][chB] ); + move16(); + hDiracDecBin->processMtxDecIm_fx[chA][chB][bin] = extract_h( MdecIm_fx[chA][chB] ); + move16(); } } + q_processMtxPrev[bin] = q_processMtx_bin; + move16(); + q_processMtxDecPrev[bin] = q_processMtxDec_bin; + move16(); + q_processMtx[bin] = sub( q_M, 16 ); + move16(); + q_processMtxDec[bin] = sub( q_Mdec, 16 ); + move16(); - if ( separateCenterChannelRendering ) + IF( separateCenterChannelRendering ) { /* The rendering of the separate center channel in masa + mono mode. * The center channel is processed with a gain factor 0.8414f to match the loudness of different processing paths */ - float lRealp, lImagp, rRealp, rImagp; - float gainFactor; - int16_t aziDeg = 0; - int16_t eleDeg = 0; - uint8_t instantChange = 0; + Word32 lRealp_fx, lImagp_fx, rRealp_fx, rImagp_fx; + Word32 gainFactor_fx; + Word16 q_tmp_sq; + Word16 aziDeg = 0; + move16(); + Word16 eleDeg = 0; + move16(); + UWord8 instantChange = 0; + move16(); - if ( ivas_format == MASA_ISM_FORMAT ) + exp = sub( 31, hDiracDecBin->q_earlyPartEneCorrection ); + tmp1 = Sqrt32( hDiracDecBin->earlyPartEneCorrection_fx[bin], &exp ); + q_tmp_sq = sub( 31, exp ); + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - gainFactor = 0.7943f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); + gainFactor_fx = Mpy_32_32( 1705746262, tmp1 ); // 1705746262 = 0.7943f in Q31 } - else + ELSE { - gainFactor = 0.8414f * sqrtf( hDiracDecBin->earlyPartEneCorrection[bin] ); + gainFactor_fx = Mpy_32_32( 1806892741, tmp1 ); // 1806892741 = 0.8414f in Q31 } + q_gain = sub( add( q_tmp_sq, 31 ), 31 ); - for ( chB = 0; chB < nchanSeparateChannels; chB++ ) + q_processMtx_bin = q_processMtx_SCCR[bin]; + + FOR( chB = 0; chB < nchanSeparateChannels; chB++ ) { - if ( ivas_format == MASA_ISM_FORMAT ) + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) { - if ( ism_mode == ISM_MASA_MODE_DISC ) + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) { aziDeg = hMasaIsmData->azimuth_ism[chB][dirac_read_idx]; + move16(); eleDeg = hMasaIsmData->elevation_ism[chB][dirac_read_idx]; + move16(); } - else + ELSE { aziDeg = hMasaIsmData->azimuth_separated_ism[dirac_read_idx]; + move16(); eleDeg = hMasaIsmData->elevation_separated_ism[dirac_read_idx]; + move16(); instantChange = 1; + move16(); } } - for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) - { - hDiracDecBin->processMtxRePrev[chA][chB + 2][bin] = hDiracDecBin->processMtxRe[chA][chB + 2][bin]; - hDiracDecBin->processMtxImPrev[chA][chB + 2][bin] = hDiracDecBin->processMtxIm[chA][chB + 2][bin]; - } -#ifdef IVAS_FLOAT_FIXED - Word32 Rmat_fx[3][3], lRealp_fx, lImagp_fx, rRealp_fx, rImagp_fx; - for ( int p = 0; p < 3; p++ ) + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { - floatToFixed_arrL( Rmat[p], Rmat_fx[p], Q30, 3 ); + hDiracDecBin->processMtxRePrev_fx[chA][add( chB, 2 )][bin] = hDiracDecBin->processMtxRe_fx[chA][add( chB, 2 )][bin]; + move16(); + hDiracDecBin->processMtxImPrev_fx[chA][add( chB, 2 )][bin] = hDiracDecBin->processMtxIm_fx[chA][add( chB, 2 )][bin]; + move16(); } + q_processMtxPrev_SCCR[bin] = q_processMtx_bin; + move16(); - getDirectPartGains_fx( bin, aziDeg, eleDeg, &lRealp_fx, &lImagp_fx, &rRealp_fx, &rImagp_fx, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat_fx, &gainCache[chB], isHeadtracked ); + getDirectPartGains_fx( bin, aziDeg, eleDeg, &lRealp_fx, &lImagp_fx, &rRealp_fx, &rImagp_fx, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); - lRealp = fixedToFloat_32( lRealp_fx, Q28 ); - lImagp = fixedToFloat_32( lImagp_fx, Q28 ); - rRealp = fixedToFloat_32( rRealp_fx, Q28 ); - rImagp = fixedToFloat_32( rImagp_fx, Q28 ); -#else - getDirectPartGains( bin, aziDeg, eleDeg, &lRealp, &lImagp, &rRealp, &rImagp, hDiracDecBin->renderStereoOutputInsteadOfBinaural, Rmat, &gainCache[chB], isHeadtracked ); -#endif - hDiracDecBin->processMtxRe[0][chB + 2][bin] = lRealp * gainFactor; - hDiracDecBin->processMtxIm[0][chB + 2][bin] = lImagp * gainFactor; - hDiracDecBin->processMtxRe[1][chB + 2][bin] = rRealp * gainFactor; - hDiracDecBin->processMtxIm[1][chB + 2][bin] = rImagp * gainFactor; + hDiracDecBin->processMtxRe_fx[0][add( chB, 2 )][bin] = extract_h( Mpy_32_32( lRealp_fx, gainFactor_fx ) ); + move16(); + hDiracDecBin->processMtxIm_fx[0][add( chB, 2 )][bin] = extract_h( Mpy_32_32( lImagp_fx, gainFactor_fx ) ); + move16(); + hDiracDecBin->processMtxRe_fx[1][add( chB, 2 )][bin] = extract_h( Mpy_32_32( rRealp_fx, gainFactor_fx ) ); + move16(); + hDiracDecBin->processMtxIm_fx[1][add( chB, 2 )][bin] = extract_h( Mpy_32_32( rImagp_fx, gainFactor_fx ) ); + move16(); + q_processMtx_SCCR[bin] = sub( sub( add( Q28, q_gain ), 31 ), 16 ); + move16(); - if ( instantChange ) + IF( instantChange ) { - for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { - hDiracDecBin->processMtxRePrev[chA][chB + 2][bin] = hDiracDecBin->processMtxRe[chA][chB + 2][bin]; - hDiracDecBin->processMtxImPrev[chA][chB + 2][bin] = hDiracDecBin->processMtxIm[chA][chB + 2][bin]; + hDiracDecBin->processMtxRePrev_fx[chA][add( chB, 2 )][bin] = hDiracDecBin->processMtxRe_fx[chA][add( chB, 2 )][bin]; + move16(); + hDiracDecBin->processMtxImPrev_fx[chA][add( chB, 2 )][bin] = hDiracDecBin->processMtxIm_fx[chA][add( chB, 2 )][bin]; + move16(); } + q_processMtxPrev_SCCR[bin] = q_processMtx_SCCR[bin]; + move16(); + } + } + } + } + /* Aligning Q-factors of all bins in the processing matrices to a common Q-factor */ + minimum_s( q_processMtx, nBins, &hDiracDecBin->q_processMtx ); + minimum_s( q_processMtxPrev, nBins, &hDiracDecBin->q_processMtxPrev ); + IF( separateCenterChannelRendering ) + { + minimum_s( q_processMtx_SCCR, nBins, &hDiracDecBin->q_processMtxSCCR ); + minimum_s( q_processMtxPrev_SCCR, nBins, &hDiracDecBin->q_processMtxPrevSCCR ); + } + hDiracDecBin->q_processMtx = s_min( hDiracDecBin->q_processMtx, hDiracDecBin->q_processMtxSCCR ); + hDiracDecBin->q_processMtxPrev = s_min( hDiracDecBin->q_processMtxPrev, hDiracDecBin->q_processMtxPrevSCCR ); + hDiracDecBin->q_processMtxSCCR = hDiracDecBin->q_processMtx; + move16(); + hDiracDecBin->q_processMtxPrevSCCR = hDiracDecBin->q_processMtxPrev; + move16(); + minimum_s( q_processMtxDec, nBins, &hDiracDecBin->q_processMtxDec ); + minimum_s( q_processMtxDecPrev, nBins, &hDiracDecBin->q_processMtxDecPrev ); + + FOR( bin = 0; bin < nBins; bin++ ) + { + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + { + hDiracDecBin->processMtxRe_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxRe_fx[chA][chB][bin], sub( q_processMtx[bin], hDiracDecBin->q_processMtx ) ); + move16(); + hDiracDecBin->processMtxIm_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxIm_fx[chA][chB][bin], sub( q_processMtx[bin], hDiracDecBin->q_processMtx ) ); + move16(); + hDiracDecBin->processMtxRePrev_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxRePrev_fx[chA][chB][bin], sub( q_processMtxPrev[bin], hDiracDecBin->q_processMtxPrev ) ); + move16(); + hDiracDecBin->processMtxImPrev_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxImPrev_fx[chA][chB][bin], sub( q_processMtxPrev[bin], hDiracDecBin->q_processMtxPrev ) ); + move16(); + hDiracDecBin->processMtxDecRe_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxDecRe_fx[chA][chB][bin], sub( q_processMtxDec[bin], hDiracDecBin->q_processMtxDec ) ); + move16(); + hDiracDecBin->processMtxDecIm_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxDecIm_fx[chA][chB][bin], sub( q_processMtxDec[bin], hDiracDecBin->q_processMtxDec ) ); + move16(); + hDiracDecBin->processMtxDecRePrev_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxDecRePrev_fx[chA][chB][bin], sub( q_processMtxDecPrev[bin], hDiracDecBin->q_processMtxDecPrev ) ); + move16(); + hDiracDecBin->processMtxDecImPrev_fx[chA][chB][bin] = shr( hDiracDecBin->processMtxDecImPrev_fx[chA][chB][bin], sub( q_processMtxDecPrev[bin], hDiracDecBin->q_processMtxDecPrev ) ); + move16(); + } + IF( separateCenterChannelRendering ) + { + FOR( chB = 0; chB < nchanSeparateChannels; chB++ ) + { + hDiracDecBin->processMtxRe_fx[chA][add( chB, 2 )][bin] = shr( hDiracDecBin->processMtxRe_fx[chA][add( chB, 2 )][bin], sub( q_processMtx_SCCR[bin], hDiracDecBin->q_processMtx ) ); + move16(); + hDiracDecBin->processMtxIm_fx[chA][add( chB, 2 )][bin] = shr( hDiracDecBin->processMtxIm_fx[chA][add( chB, 2 )][bin], sub( q_processMtx_SCCR[bin], hDiracDecBin->q_processMtx ) ); + move16(); + hDiracDecBin->processMtxRePrev_fx[chA][add( chB, 2 )][bin] = shr( hDiracDecBin->processMtxRePrev_fx[chA][add( chB, 2 )][bin], sub( q_processMtxPrev_SCCR[bin], hDiracDecBin->q_processMtxPrev ) ); + move16(); + hDiracDecBin->processMtxImPrev_fx[chA][add( chB, 2 )][bin] = shr( hDiracDecBin->processMtxImPrev_fx[chA][add( chB, 2 )][bin], sub( q_processMtxPrev_SCCR[bin], hDiracDecBin->q_processMtxPrev ) ); + move16(); } } } @@ -3180,7 +3565,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void ivas_dirac_dec_binaural_process_output_fx( @@ -4573,7 +4958,7 @@ static void matrixDiagMul_fx( } #endif // IVAS_FLOAT_FIXED - +#ifndef IVAS_FLOAT_FIXED static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], @@ -4597,7 +4982,7 @@ static void matrixMul( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void matrixMul_fx( Word32 Are_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word32 Aim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], @@ -4706,7 +5091,6 @@ static void matrixTransp1Mul_fx( Word16 size = i_mult( BINAURAL_CHANNELS, BINAURAL_CHANNELS ); Word32 tmp1, tmp2; - FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) { FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) @@ -4746,7 +5130,7 @@ static void matrixTransp1Mul_fx( } #endif // IVAS_FLOAT_FIXED - +#ifndef IVAS_FLOAT_FIXED static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], @@ -4770,7 +5154,7 @@ static void matrixTransp2Mul( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void matrixTransp2Mul_fx( Word32 Are_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word32 Aim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], @@ -6802,35 +7186,13 @@ static void ivas_masa_ext_rend_parambin_internal( Word16 nBins; Word16 i, j; Word16 nchan_transport; + Word16 q_mat; #if 1 hDiracDecBin = hMasaExtRend->hDiracDecBin; hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; Word32 *output_fx[MAX_OUTPUT_CHANNELS]; Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word16 q_earlyPartEneCorrection = Q_factor_arrL( hDiracDecBin->earlyPartEneCorrection, hSpatParamRendCom->num_freq_bands ); - hDiracDecBin->q_earlyPartEneCorrection = q_earlyPartEneCorrection; - floatToFixed_arr32( hDiracDecBin->earlyPartEneCorrection, hDiracDecBin->earlyPartEneCorrection_fx, q_earlyPartEneCorrection, hSpatParamRendCom->num_freq_bands ); - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherence, hDiracDecBin->diffuseFieldCoherence_fx, Q31, hSpatParamRendCom->num_freq_bands ); - FOR( j = 0; j < hSpatParamRendCom->num_freq_bands; j++ ) - { - f2me( hDiracDecBin->ChCrossRePrev[j], &hDiracDecBin->ChCrossRePrev_fx[j], &hDiracDecBin->ChCrossRePrev_e[j] ); - f2me( hDiracDecBin->ChCrossImPrev[j], &hDiracDecBin->ChCrossImPrev_fx[j], &hDiracDecBin->ChCrossImPrev_e[j] ); - f2me( hDiracDecBin->ChCrossReOutPrev[j], &hDiracDecBin->ChCrossReOutPrev_fx[j], &hDiracDecBin->ChCrossReOutPrev_e[j] ); - f2me( hDiracDecBin->ChCrossImOutPrev[j], &hDiracDecBin->ChCrossImOutPrev_fx[j], &hDiracDecBin->ChCrossImOutPrev_e[j] ); - FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - f2me( hDiracDecBin->ChEnePrev[i][j], &hDiracDecBin->ChEnePrev_fx[i][j], &hDiracDecBin->ChEnePrev_e[i][j] ); - f2me( hDiracDecBin->ChEneOutPrev[i][j], &hDiracDecBin->ChEneOutPrev_fx[i][j], &hDiracDecBin->ChEneOutPrev_e[i][j] ); - } - } - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherence, hDiracDecBin->diffuseFieldCoherence_fx, 31, hSpatParamRendCom->num_freq_bands ); - IF( hDiracDecBin->hDiffuseDist ) - { - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceX, hDiracDecBin->diffuseFieldCoherenceX_fx, 31, 9 ); - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceY, hDiracDecBin->diffuseFieldCoherenceY_fx, 31, 9 ); - floatToFixed_arr32( hDiracDecBin->diffuseFieldCoherenceZ, hDiracDecBin->diffuseFieldCoherenceZ_fx, 31, 9 ); - } FOR( ch = 0; ch < 2; ch++ ) { output_fx[ch] = output_fx_buff[ch]; @@ -6966,46 +7328,13 @@ static void ivas_masa_ext_rend_parambin_internal( /* Always using CLDFB decorrelation in MASA EXT renderer */ max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; -#if 1 - FOR( i = 0; i < BINAURAL_CHANNELS; i++ ) - { - FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) - { - hDiracDecBin->ChEnePrev[i][j] = me2f( hDiracDecBin->ChEnePrev_fx[i][j], hDiracDecBin->ChEnePrev_e[i][j] ); - hDiracDecBin->ChEne[i][j] = me2f( hDiracDecBin->ChEne_fx[i][j], hDiracDecBin->ChEne_e[i][j] ); - hDiracDecBin->ChEneOut[i][j] = me2f( hDiracDecBin->ChEneOut_fx[i][j], hDiracDecBin->ChEneOut_e[i][j] ); - hDiracDecBin->ChEneOutPrev[i][j] = me2f( hDiracDecBin->ChEneOutPrev_fx[i][j], hDiracDecBin->ChEneOutPrev_e[i][j] ); - } - } - - FOR( j = 0; j < nBins; j++ ) - { - hDiracDecBin->ChCrossRePrev[j] = me2f( hDiracDecBin->ChCrossRePrev_fx[j], hDiracDecBin->ChCrossRePrev_e[j] ); - hDiracDecBin->ChCrossImPrev[j] = me2f( hDiracDecBin->ChCrossImPrev_fx[j], hDiracDecBin->ChCrossImPrev_e[j] ); - hDiracDecBin->ChCrossRe[j] = me2f( hDiracDecBin->ChCrossRe_fx[j], hDiracDecBin->ChCrossRe_e[j] ); - hDiracDecBin->ChCrossIm[j] = me2f( hDiracDecBin->ChCrossIm_fx[j], hDiracDecBin->ChCrossIm_e[j] ); - hDiracDecBin->ChCrossReOut[j] = me2f( hDiracDecBin->ChCrossReOut_fx[j], hDiracDecBin->ChCrossReOut_e[j] ); - hDiracDecBin->ChCrossImOut[j] = me2f( hDiracDecBin->ChCrossImOut_fx[j], hDiracDecBin->ChCrossImOut_e[j] ); - hDiracDecBin->ChCrossReOutPrev[j] = me2f( hDiracDecBin->ChCrossReOutPrev_fx[j], hDiracDecBin->ChCrossReOutPrev_e[j] ); - hDiracDecBin->ChCrossImOutPrev[j] = me2f( hDiracDecBin->ChCrossImOutPrev_fx[j], hDiracDecBin->ChCrossImOutPrev_e[j] ); - } - fixedToFloat_arrL( hDiracDecBin->frameMeanDiffuseness_fx, hDiracDecBin->frameMeanDiffuseness, 29, CLDFB_NO_CHANNELS_MAX ); - -#endif - - float Rmat[3][3]; - for ( i = 0; i < 3; i++ ) // TODO: To be removed - { - fixedToFloat_arrL32( Rmat_fx[i], Rmat[i], Q30, 3 ); - } - ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, + ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, 0, NULL ); #if 1 Word16 q_out; - Word16 q_mat = 15; q_inp = Q6; FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { @@ -7013,46 +7342,39 @@ static void ivas_masa_ext_rend_parambin_internal( } FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - FOR( slot = 0; slot < BINAURAL_CHANNELS; slot++ ) - { - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecRe[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecIm[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecRePrev[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxDecImPrev[ch][slot], nBins ) ); - } - } - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - FOR( slot = 0; slot < numInChannels; slot++ ) - { - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxRe[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxIm[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxRePrev[ch][slot], nBins ) ); - q_mat = s_min( q_mat, Q_factor_arr( hDiracDecBin->processMtxImPrev[ch][slot], nBins ) ); - } + hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; } +#endif // Float to fix ends + + q_mat = hDiracDecBin->q_processMtx; + q_mat = s_min( q_mat, hDiracDecBin->q_processMtxPrev ); + q_mat = s_min( q_mat, hDiracDecBin->q_processMtxDec ); + q_mat = s_min( q_mat, hDiracDecBin->q_processMtxDecPrev ); + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { FOR( slot = 0; slot < BINAURAL_CHANNELS; slot++ ) { - floatToFixed_arr16( hDiracDecBin->processMtxDecRe[ch][slot], hDiracDecBin->processMtxDecRe_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxDecIm[ch][slot], hDiracDecBin->processMtxDecIm_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxDecRePrev[ch][slot], hDiracDecBin->processMtxDecRePrev_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxDecImPrev[ch][slot], hDiracDecBin->processMtxDecImPrev_fx[ch][slot], q_mat, nBins ); + Scale_sig( hDiracDecBin->processMtxDecRe_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDec ) ); + Scale_sig( hDiracDecBin->processMtxDecIm_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDec ) ); + Scale_sig( hDiracDecBin->processMtxDecRePrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDecPrev ) ); + Scale_sig( hDiracDecBin->processMtxDecImPrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxDecPrev ) ); } } FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { FOR( slot = 0; slot < numInChannels; slot++ ) { - floatToFixed_arr16( hDiracDecBin->processMtxRe[ch][slot], hDiracDecBin->processMtxRe_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxIm[ch][slot], hDiracDecBin->processMtxIm_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxRePrev[ch][slot], hDiracDecBin->processMtxRePrev_fx[ch][slot], q_mat, nBins ); - floatToFixed_arr16( hDiracDecBin->processMtxImPrev[ch][slot], hDiracDecBin->processMtxImPrev_fx[ch][slot], q_mat, nBins ); + Scale_sig( hDiracDecBin->processMtxRe_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtx ) ); + Scale_sig( hDiracDecBin->processMtxIm_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtx ) ); + Scale_sig( hDiracDecBin->processMtxRePrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxPrev ) ); + Scale_sig( hDiracDecBin->processMtxImPrev_fx[ch][slot], nBins, sub( q_mat, hDiracDecBin->q_processMtxPrev ) ); } - hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; } -#endif // Float to fix ends + hDiracDecBin->q_processMtx = q_mat; + hDiracDecBin->q_processMtxPrev = q_mat; + hDiracDecBin->q_processMtxDec = q_mat; + hDiracDecBin->q_processMtxDecPrev = q_mat; ivas_dirac_dec_binaural_process_output_fx( hDiracDecBin, hSpatParamRendCom, hMasaExtRend->cldfbSynRend, output_fx, &q_out, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_inp, max_band_decorr, numInChannels, config_data.processReverb, subframe, q_mat ); diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 97bed6db4..dab91ad0a 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -319,7 +319,19 @@ const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENCE_BINS] { 0.048207f, 0.10796f, 0.11845f, 0.047886f, 0.035917f, 0.045196f, 0.018863f, 0.015547f, 0.014157f }; +#ifdef IVAS_FLOAT_FIXED +const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS] = { /* Q31 */ + 101835824, 424621952, 484944768, 228427840, 18706944, 25829934, 68659344, 42236708, 17164408, +}; + +const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS] = { /* Q31 */ + -205359568, -656464256, -739314176, -331249344, -95837904, -122887608, -109167328, -75621488, -47566764, +}; +const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS] = { /* Q31 */ + 103523744, 231842336, 254369440, 102834400, 77131168, 97057672, 40507984, 33386928, 30401926, +}; +#endif /*----------------------------------------------------------------------------------* * TD ISM binaural renderer ROM tables diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 3ccdaa007..dd0f02d78 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -66,7 +66,7 @@ extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; #ifdef IVAS_FLOAT_FIXED extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; -extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; +extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS*DIRAC_MAX_DECORR_FILTER_LEN]; #endif extern const int16_t sba_map_tc[11]; @@ -99,6 +99,11 @@ extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; extern const float diffuseFieldCoherenceDifferenceX[BINAURAL_COHERENCE_DIFFERENCE_BINS]; extern const float diffuseFieldCoherenceDifferenceY[BINAURAL_COHERENCE_DIFFERENCE_BINS]; extern const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENCE_BINS]; +#ifdef IVAS_FLOAT_FIXED +extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; +extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; +extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; +#endif // IVAS_FLOAT_FIXED /*----------------------------------------------------------------------------------* @@ -136,7 +141,7 @@ extern const Word32 defaultHRIR_right_avg_power_32kHz_fx[LR_IAC_LENGTH_NR_FC]; / extern const Word32 defaultHRIR_coherence_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-27*/ extern const Word32 defaultHRIR_left_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ extern const Word32 defaultHRIR_right_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED /*----------------------------------------------------------------------------------* * t-design and SN3D normalization table *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 6cbd09ebb..8d83587e6 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -874,6 +874,7 @@ typedef struct ivas_diffuse_distribution_data_structure /* Parametric binaural data structure */ typedef struct ivas_dirac_dec_binaural_data_structure { +#ifndef IVAS_FLOAT_FIXED float ChEnePrev[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float ChCrossRePrev[CLDFB_NO_CHANNELS_MAX]; float ChCrossImPrev[CLDFB_NO_CHANNELS_MAX]; @@ -895,13 +896,16 @@ typedef struct ivas_dirac_dec_binaural_data_structure float diffuseFieldCoherenceY[BINAURAL_COHERENCE_DIFFERENCE_BINS]; float diffuseFieldCoherenceZ[BINAURAL_COHERENCE_DIFFERENCE_BINS]; float earlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX]; +#endif REVERB_STRUCT_HANDLE hReverb; uint8_t renderStereoOutputInsteadOfBinaural; +#ifndef IVAS_FLOAT_FIXED float frameMeanDiffuseness[CLDFB_NO_CHANNELS_MAX]; float processMtxRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; float processMtxImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecRePrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; float processMtxDecImPrev[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; +#endif #ifdef IVAS_FLOAT_FIXED Word32 earlyPartEneCorrection_fx[CLDFB_NO_CHANNELS_MAX]; Word16 q_earlyPartEneCorrection; @@ -914,6 +918,13 @@ typedef struct ivas_dirac_dec_binaural_data_structure Word16 processMtxDecRePrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; Word16 processMtxDecImPrev_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word16 q_processMtx; + Word16 q_processMtxSCCR; + Word16 q_processMtxPrev; + Word16 q_processMtxPrevSCCR; + Word16 q_processMtxDec; + Word16 q_processMtxDecPrev; + Word32 ChEnePrev_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; Word32 ChCrossRePrev_fx[CLDFB_NO_CHANNELS_MAX]; Word32 ChCrossImPrev_fx[CLDFB_NO_CHANNELS_MAX]; @@ -2191,8 +2202,8 @@ typedef struct ivas_hrtfs_parambin_struct #ifndef IVAS_FLOAT_FIXED float parametricReverberationTimes[CLDFB_NO_CHANNELS_MAX]; float parametricReverberationEneCorrections[CLDFB_NO_CHANNELS_MAX]; -#endif float parametricEarlyPartEneCorrection[CLDFB_NO_CHANNELS_MAX]; +#endif #ifdef IVAS_FLOAT_FIXED Word32 parametricReverberationTimes_fx[CLDFB_NO_CHANNELS_MAX]; /* Q31 */ Word32 parametricReverberationEneCorrections_fx[CLDFB_NO_CHANNELS_MAX]; /* Q31 */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 135522e3b..4a2db0827 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -5253,11 +5253,6 @@ static ivas_error setRendInputActiveMasa( } #if 1 /*TODO: To be removed later(fixed to float)*/ - IF( inputMasa->hMasaExtRend ) - { - IF( inputMasa->hMasaExtRend->hDiracDecBin ) - fixedToFloat_arrL( inputMasa->hMasaExtRend->hDiracDecBin->earlyPartEneCorrection_fx, inputMasa->hMasaExtRend->hDiracDecBin->earlyPartEneCorrection, (Word16) Q28 /*1.0f Q28*/, (Word16) CLDFB_NO_CHANNELS_MAX ); - } inputMasa->base.inputBuffer.data = inputMasa->bufferData; fixedToFloat_arrL( inputMasa->base.inputBuffer.data_fx, inputMasa->base.inputBuffer.data, 0, MAX_BUFFER_LENGTH ); /*fixed to float only for set zero(that's why q0)*/ #endif @@ -14119,40 +14114,34 @@ static ivas_error ivas_masa_ext_rend_parambin_init( { FOR( k = 0; k < BINAURAL_CHANNELS + MAX_NUM_OBJECTS; k++ ) { -#if 1 /*To be removed later(floating buffer init)*/ - set_zero( hDiracDecBin->processMtxRe[j][k], nBins ); - set_zero( hDiracDecBin->processMtxIm[j][k], nBins ); -#endif set16_fx( hDiracDecBin->processMtxRe_fx[j][k], 0, nBins ); set16_fx( hDiracDecBin->processMtxIm_fx[j][k], 0, nBins ); } FOR( k = 0; k < BINAURAL_CHANNELS; k++ ) { -#if 1 /*To be removed later(floating buffer init)*/ - set_zero( hDiracDecBin->processMtxDecRe[j][k], nBins ); - set_zero( hDiracDecBin->processMtxDecIm[j][k], nBins ); -#endif set16_fx( hDiracDecBin->processMtxDecRe_fx[j][k], 0, nBins ); set16_fx( hDiracDecBin->processMtxDecIm_fx[j][k], 0, nBins ); } -#if 1 /*TODO:To be removed later(floating buffer init)*/ - set_zero( hDiracDecBin->ChEnePrev[j], nBins ); - set_zero( hDiracDecBin->ChEneOutPrev[j], nBins ); -#endif + hDiracDecBin->q_processMtx = Q15; + hDiracDecBin->q_processMtxSCCR = Q15; + hDiracDecBin->q_processMtxPrev = Q15; + hDiracDecBin->q_processMtxPrevSCCR = Q15; + hDiracDecBin->q_processMtxDec = Q15; + hDiracDecBin->q_processMtxDecPrev = Q15; set_zero_fx( hDiracDecBin->ChEnePrev_fx[j], nBins ); set_zero_fx( hDiracDecBin->ChEneOutPrev_fx[j], nBins ); + set16_fx( hDiracDecBin->ChEnePrev_e[j], 0, nBins ); + set16_fx( hDiracDecBin->ChEneOutPrev_e[j], 0, nBins ); } -#if 1 /*TODO:To be removed later(floating buffer init)*/ - set_zero( hDiracDecBin->ChCrossRePrev, nBins ); - set_zero( hDiracDecBin->ChCrossImPrev, nBins ); - set_zero( hDiracDecBin->ChCrossReOutPrev, nBins ); - set_zero( hDiracDecBin->ChCrossImOutPrev, nBins ); -#endif set_zero_fx( hDiracDecBin->ChCrossRePrev_fx, nBins ); set_zero_fx( hDiracDecBin->ChCrossImPrev_fx, nBins ); set_zero_fx( hDiracDecBin->ChCrossReOutPrev_fx, nBins ); set_zero_fx( hDiracDecBin->ChCrossImOutPrev_fx, nBins ); + set16_fx( hDiracDecBin->ChCrossRePrev_e, 0, nBins ); + set16_fx( hDiracDecBin->ChCrossImPrev_e, 0, nBins ); + set16_fx( hDiracDecBin->ChCrossReOutPrev_e, 0, nBins ); + set16_fx( hDiracDecBin->ChCrossImOutPrev_e, 0, nBins ); hDiracDecBin->renderStereoOutputInsteadOfBinaural = 0; FOR( bin = 0; bin < nBins; bin++ ) @@ -14168,15 +14157,10 @@ static ivas_error ivas_masa_ext_rend_parambin_init( tmpFloat_fx = s_max( 0, sub( shl_sat( 1, 15 - tmp_e ), tmp ) ) /*max( 0.0f, 1.0f - binCenterFreq / 2700.0f )*/; /*Q30*/ tmp2 = extract_l( Mult_32_32( binCenterFreq_fx, 1952258 /*=2^31*180/(550)/360*/ ) % 32767 ); //*binCenterFreq_fx * EVS_PI / 550.0f*/ hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( L_mult0( divide3232( tmpFloat_fx, Mult_32_16( binCenterFreq_fx, 187 /*2^15*pi/550*/ ) ), getSineWord16R2( tmp2 ) ), tmp_e ); /*tmpFloat * sinf( binCenterFreq * EVS_PI / 550.0f ) / ( binCenterFreq * EVS_PI / 550.0f );*/ - hDiracDecBin->diffuseFieldCoherence[bin] = fixedToFloat( hDiracDecBin->diffuseFieldCoherence_fx[bin], Q30 ); + hDiracDecBin->diffuseFieldCoherence_fx[bin] = L_shl( hDiracDecBin->diffuseFieldCoherence_fx[bin], 1 ); // Q31 } /* No SPAR in external renderer so set directive diffuse field coherence tables to zero */ -#if 1 /*TODO: To be removed later(floating buffer init)*/ - set_zero( hDiracDecBin->diffuseFieldCoherenceX, BINAURAL_COHERENCE_DIFFERENCE_BINS ); - set_zero( hDiracDecBin->diffuseFieldCoherenceY, BINAURAL_COHERENCE_DIFFERENCE_BINS ); - set_zero( hDiracDecBin->diffuseFieldCoherenceZ, BINAURAL_COHERENCE_DIFFERENCE_BINS ); -#endif set_zero_fx( hDiracDecBin->diffuseFieldCoherenceX_fx, BINAURAL_COHERENCE_DIFFERENCE_BINS ); set_zero_fx( hDiracDecBin->diffuseFieldCoherenceY_fx, BINAURAL_COHERENCE_DIFFERENCE_BINS ); set_zero_fx( hDiracDecBin->diffuseFieldCoherenceZ_fx, BINAURAL_COHERENCE_DIFFERENCE_BINS ); @@ -14184,11 +14168,13 @@ static ivas_error ivas_masa_ext_rend_parambin_init( IF( EQ_16( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) /* Indication of binaural rendering without room effect */ { set32_fx( hDiracDecBin->earlyPartEneCorrection_fx, ONE_IN_Q28 /*1.0f Q28*/, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->q_earlyPartEneCorrection = Q28; hDiracDecBin->hReverb = NULL; } ELSE IF( EQ_16( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) /* Indication of binaural rendering with room effect */ { Copy32( hHrtfParambin->parametricEarlyPartEneCorrection_fx, hDiracDecBin->earlyPartEneCorrection_fx, nBins ); + hDiracDecBin->q_earlyPartEneCorrection = Q28; IF( hDiracDecBin->hReverb == NULL ) { @@ -14202,6 +14188,7 @@ static ivas_error ivas_masa_ext_rend_parambin_init( ELSE IF( EQ_16( renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { set32_fx( hDiracDecBin->earlyPartEneCorrection_fx, ONE_IN_Q28 /*1.0f Q28*/, CLDFB_NO_CHANNELS_MAX ); + hDiracDecBin->q_earlyPartEneCorrection = Q28; hDiracDecBin->hReverb = NULL; hDiracDecBin->renderStereoOutputInsteadOfBinaural = 1; } diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index e7f77bf2b..e7692ffb2 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -260,10 +260,10 @@ static void LoadBSplineBinaryITD( modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); - for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) + modelITD->elevKSeq_dyn_fx = (Word32 *)malloc(sizeof(Word32)*(modelITD->elevDim3 - 2)); + for (int i = 0; i < modelITD->elevDim3 - 2; i++) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix( modelITD->elevKSeq_dyn[i], 22 ); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix(modelITD->elevKSeq_dyn[i], 22); } #endif @@ -273,9 +273,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) + for (int i = 0; i < ((modelITD->azimDim3 + 1) / 2 - 2); i++) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix( modelITD->azimKSeq_dyn[i], Q22 ); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix(modelITD->azimKSeq_dyn[i], Q22); } #endif @@ -297,9 +297,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for ( int i = 0; i < tmp; i++ ) + for (int i = 0; i < tmp; i++) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix( modelITD->azimBsShape_dyn[i], Q30 ); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix(modelITD->azimBsShape_dyn[i], Q30); } #endif @@ -315,9 +315,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for ( int i = 0; i < tmp; i++ ) + for (int i = 0; i < tmp; i++) { - modelITD->elevBsShape_dyn_fx[i] = float_to_fix( modelITD->elevBsShape_dyn[i], Q30 ); + modelITD->elevBsShape_dyn_fx[i] = float_to_fix(modelITD->elevBsShape_dyn[i], Q30); } #endif @@ -427,7 +427,7 @@ static ivas_error LoadBSplineBinary( fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); - for ( i = 0; i < ( model->elevDim3 - 2 ); i++ ) + for ( i = 0; i < (model->elevDim3 - 2); i++ ) { model->elevKSeq_dyn_fx[i] = float_to_fix( model->elevKSeq_dyn[i], Q22 ); } @@ -448,9 +448,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) + for (int j = 0; j < (model->azimDim3_dyn[i] + 1); j++) { - model->azimKSeq_fx[i][j] = float_to_fix( model->azimKSeq[i][j], Q22 ); + model->azimKSeq_fx[i][j] = float_to_fix(model->azimKSeq[i][j], Q22); } #endif } @@ -486,9 +486,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for ( int j = 0; j < tmp; j++ ) + for (int j = 0; j < tmp; j++) { - model->azimBsShape_dyn_fx[i][j] = float_to_fix( model->azimBsShape_dyn[i][j], Q30 ); + model->azimBsShape_dyn_fx[i][j] = float_to_fix(model->azimBsShape_dyn[i][j], Q30); } #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); @@ -506,10 +506,10 @@ static ivas_error LoadBSplineBinary( model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + model->elevBsShape_dyn_fx = (Word32 *)malloc(tmp * sizeof(Word32)); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix( model->elevBsShape_dyn[i], Q30 ); + model->elevBsShape_dyn_fx[i] = float_to_fix(model->elevBsShape_dyn[i], Q30); } #endif @@ -785,9 +785,9 @@ static void HRTF_energy_sections_precalc( pAlphaR += AlphaN; #ifdef IVAS_FLOAT_FIXED tmp_fx = *pAlphaL_fx; - *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ + *pEL_fx = L_add(*pEL_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ tmp_fx = *pAlphaR_fx; - *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ + *pER_fx = L_add(*pER_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ pAlphaL_fx += AlphaN; pAlphaR_fx += AlphaN; #endif @@ -803,8 +803,8 @@ static void HRTF_energy_sections_precalc( model->EL = (const float *) model->EL_dyn; model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED - model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) - model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) + model->EL_dyn_e = add(shl(model->AlphaL_e, 1), 1); // 2 * AlphaL_e + 1 (one guard bit) + model->ER_dyn_e = add(shl(model->AlphaR_e, 1), 1); // 2 * AlphaR_e + 1 (one guard bit) model->EL_fx = model->EL_dyn_fx; model->EL_e = model->EL_dyn_e; @@ -895,7 +895,7 @@ ivas_error dealloc_HRTF_binary( free( hHrtf->ModelParams.azimKSeq ); #ifdef IVAS_FLOAT_FIXED free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + FOR ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq_fx[i] ); } @@ -1049,7 +1049,7 @@ static ivas_error create_HRTF_from_rawdata( for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { //( *hHRTF )->inv_diffuse_weight[i] = *( (float *) ( hrtf_data_rptr ) ); - ( *hHRTF )->inv_diffuse_weight_fx[i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 ); + ( *hHRTF )->inv_diffuse_weight_fx[i] = ( Word16 ) (* ( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15); hrtf_data_rptr += sizeof( float ); } @@ -1074,8 +1074,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1083,12 +1083,12 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); /* coeff_im (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1106,8 +1106,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1115,7 +1115,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } @@ -1143,8 +1143,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1152,7 +1152,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -1173,8 +1173,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1182,7 +1182,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -2186,8 +2186,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( /*adding conversion as file reading is done in float*/ floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricReverberationEneCorrections_fx, Q31, CLDFB_NO_CHANNELS_MAX ); - memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + //memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + memcpy( f_tmp_reverb, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( float ); + /*adding conversion as file reading is done in float*/ + floatToFixed_arrL( f_tmp_reverb, (*hHRTF)->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); return IVAS_ERR_OK; } -- GitLab From 30ac07dbbc60491bc778858ec450f16fee23b6c3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 13:59:42 +0530 Subject: [PATCH 10/63] clang formatting changes --- lib_rend/ivas_dirac_dec_binaural_functions.c | 6 +- lib_rend/ivas_rom_rend.h | 4 +- lib_util/hrtf_file_reader.c | 74 ++++++++++---------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 279cf432c..132225604 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1486,7 +1486,7 @@ static void ivas_dirac_dec_binaural_internal( } ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); #if 1 Word32 *output_fx[MAX_OUTPUT_CHANNELS]; @@ -7330,8 +7330,8 @@ static void ivas_masa_ext_rend_parambin_internal( max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, - 0, NULL ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, + 0, NULL ); #if 1 Word16 q_out; diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index dd0f02d78..720fc2c80 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -66,7 +66,7 @@ extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; #ifdef IVAS_FLOAT_FIXED extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; -extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS*DIRAC_MAX_DECORR_FILTER_LEN]; +extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; #endif extern const int16_t sba_map_tc[11]; @@ -141,7 +141,7 @@ extern const Word32 defaultHRIR_right_avg_power_32kHz_fx[LR_IAC_LENGTH_NR_FC]; / extern const Word32 defaultHRIR_coherence_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-27*/ extern const Word32 defaultHRIR_left_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ extern const Word32 defaultHRIR_right_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED /*----------------------------------------------------------------------------------* * t-design and SN3D normalization table *----------------------------------------------------------------------------------*/ diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index e7692ffb2..549d4cb4d 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -260,10 +260,10 @@ static void LoadBSplineBinaryITD( modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - modelITD->elevKSeq_dyn_fx = (Word32 *)malloc(sizeof(Word32)*(modelITD->elevDim3 - 2)); - for (int i = 0; i < modelITD->elevDim3 - 2; i++) + modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); + for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix(modelITD->elevKSeq_dyn[i], 22); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix( modelITD->elevKSeq_dyn[i], 22 ); } #endif @@ -273,9 +273,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - for (int i = 0; i < ((modelITD->azimDim3 + 1) / 2 - 2); i++) + for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix(modelITD->azimKSeq_dyn[i], Q22); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix( modelITD->azimKSeq_dyn[i], Q22 ); } #endif @@ -297,9 +297,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int i = 0; i < tmp; i++) + for ( int i = 0; i < tmp; i++ ) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix(modelITD->azimBsShape_dyn[i], Q30); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix( modelITD->azimBsShape_dyn[i], Q30 ); } #endif @@ -315,9 +315,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int i = 0; i < tmp; i++) + for ( int i = 0; i < tmp; i++ ) { - modelITD->elevBsShape_dyn_fx[i] = float_to_fix(modelITD->elevBsShape_dyn[i], Q30); + modelITD->elevBsShape_dyn_fx[i] = float_to_fix( modelITD->elevBsShape_dyn[i], Q30 ); } #endif @@ -427,7 +427,7 @@ static ivas_error LoadBSplineBinary( fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); - for ( i = 0; i < (model->elevDim3 - 2); i++ ) + for ( i = 0; i < ( model->elevDim3 - 2 ); i++ ) { model->elevKSeq_dyn_fx[i] = float_to_fix( model->elevKSeq_dyn[i], Q22 ); } @@ -448,9 +448,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - for (int j = 0; j < (model->azimDim3_dyn[i] + 1); j++) + for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) { - model->azimKSeq_fx[i][j] = float_to_fix(model->azimKSeq[i][j], Q22); + model->azimKSeq_fx[i][j] = float_to_fix( model->azimKSeq[i][j], Q22 ); } #endif } @@ -486,9 +486,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int j = 0; j < tmp; j++) + for ( int j = 0; j < tmp; j++ ) { - model->azimBsShape_dyn_fx[i][j] = float_to_fix(model->azimBsShape_dyn[i][j], Q30); + model->azimBsShape_dyn_fx[i][j] = float_to_fix( model->azimBsShape_dyn[i][j], Q30 ); } #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); @@ -506,10 +506,10 @@ static ivas_error LoadBSplineBinary( model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - model->elevBsShape_dyn_fx = (Word32 *)malloc(tmp * sizeof(Word32)); + model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix(model->elevBsShape_dyn[i], Q30); + model->elevBsShape_dyn_fx[i] = float_to_fix( model->elevBsShape_dyn[i], Q30 ); } #endif @@ -785,9 +785,9 @@ static void HRTF_energy_sections_precalc( pAlphaR += AlphaN; #ifdef IVAS_FLOAT_FIXED tmp_fx = *pAlphaL_fx; - *pEL_fx = L_add(*pEL_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ tmp_fx = *pAlphaR_fx; - *pER_fx = L_add(*pER_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ pAlphaL_fx += AlphaN; pAlphaR_fx += AlphaN; #endif @@ -803,8 +803,8 @@ static void HRTF_energy_sections_precalc( model->EL = (const float *) model->EL_dyn; model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED - model->EL_dyn_e = add(shl(model->AlphaL_e, 1), 1); // 2 * AlphaL_e + 1 (one guard bit) - model->ER_dyn_e = add(shl(model->AlphaR_e, 1), 1); // 2 * AlphaR_e + 1 (one guard bit) + model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) + model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) model->EL_fx = model->EL_dyn_fx; model->EL_e = model->EL_dyn_e; @@ -895,7 +895,7 @@ ivas_error dealloc_HRTF_binary( free( hHrtf->ModelParams.azimKSeq ); #ifdef IVAS_FLOAT_FIXED free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq_fx[i] ); } @@ -1049,7 +1049,7 @@ static ivas_error create_HRTF_from_rawdata( for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { //( *hHRTF )->inv_diffuse_weight[i] = *( (float *) ( hrtf_data_rptr ) ); - ( *hHRTF )->inv_diffuse_weight_fx[i] = ( Word16 ) (* ( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15); + ( *hHRTF )->inv_diffuse_weight_fx[i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 ); hrtf_data_rptr += sizeof( float ); } @@ -1074,8 +1074,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1083,12 +1083,12 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); /* coeff_im (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1106,8 +1106,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1115,7 +1115,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } @@ -1143,8 +1143,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1152,7 +1152,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -1173,8 +1173,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1182,7 +1182,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -2186,11 +2186,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( /*adding conversion as file reading is done in float*/ floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricReverberationEneCorrections_fx, Q31, CLDFB_NO_CHANNELS_MAX ); - //memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + // memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); memcpy( f_tmp_reverb, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( float ); /*adding conversion as file reading is done in float*/ - floatToFixed_arrL( f_tmp_reverb, (*hHRTF)->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); + floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); return IVAS_ERR_OK; } -- GitLab From 85416718141ed12cf78f6db33f84cfa44ee29adc Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 14:38:36 +0530 Subject: [PATCH 11/63] Fix for issue 685: High frequency difference between BASOP fixed point and PC main floating point for SBA HOA3 inputs --- lib_com/ivas_prot.h | 3 ++- lib_dec/ivas_jbm_dec.c | 19 +++++++++++++++---- lib_dec/ivas_sba_rendering_internal.c | 17 +++++++++-------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c388377c1..ca0bcf69e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5264,7 +5264,8 @@ void ivas_sba_mix_matrix_determiner_fx( const Word16 bfi, /* i : BFI flag */ const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix */ + const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix */ + const Word16 Q_p_Output /* i : number of subframes in mixing matrix */ ); #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index c38410672..56ad79dbb 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -576,7 +576,7 @@ ivas_error ivas_jbm_dec_tc_fx( num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ); SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; - Word16 Q_p_output = 14; + Word16 Q_p_output = MAX_16, temp_min; move16(); Word16 nchan_transport; @@ -586,13 +586,24 @@ ivas_error ivas_jbm_dec_tc_fx( move16(); FOR( ch = 0; ch < nchan_transport; ch++ ) { - Scale_sig32( p_output_fx[ch], output_frame, sub( Q_p_output, Q11 ) ); + temp_min = getScaleFactor32( p_output_fx[ch], output_frame ); + Q_p_output = s_min( Q_p_output, temp_min ); + } + Q_p_output = sub( Q_p_output, 2 ); + IF( GT_16( Q_p_output, 20 ) ) + { + Q_p_output = 20; + move16(); + } + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); } hSpar->hMdDec->Q_mixer_mat = 31; move16(); - ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames ); + ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output ); FOR( Word16 c = 0; c < nchan_transport; c++ ) { Scale_sig32( p_output_fx[c], output_frame, 11 ); @@ -978,7 +989,7 @@ ivas_error ivas_jbm_dec_tc_fx( } hSpar->hMdDec->Q_mixer_mat = 31; - ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames ); + ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, sub( Q_p_output, Q11 ) ); FOR( Word16 c = 0; c < nchan_transport; c++ ) { Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index a8be63373..6d87d5f81 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -836,17 +836,18 @@ ivas_error ivas_sba_linear_renderer( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED void ivas_sba_mix_matrix_determiner_fx( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - Word32 *output_fx[], /* i/o: transport/output audio channels */ - const Word16 bfi, /* i : BFI flag */ - const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ - const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix*/ + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ + Word32 *output_fx[], /* i/o: transport/output audio channels */ + const Word16 bfi, /* i : BFI flag */ + const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ + const Word16 output_frame, /* i : output frame length */ + const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ + const Word16 Q_output /* i : number of subframes in mixing matrix*/ ) { Word16 i, ch; Word16 num_bands_out, nchan_transport, nchan_out; - Word16 Q_p_output = 14; + Word16 Q_p_output = add( 11, Q_output ); move16(); Word32 temp_fx; /* Convert numeric range */ @@ -888,7 +889,7 @@ void ivas_sba_mix_matrix_determiner_fx( { FOR( i = 0; i < output_frame; i++ ) { - output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], 4 ), L_shl_sat( PCM16_TO_FLT_FAC_FX, 16 ) ); /*Q-0*/ + output_fx[ch][i] = Mult_32_32( L_shl_sat( output_fx[ch][i], sub( 18, Q_p_output ) ), L_shl_sat( PCM16_TO_FLT_FAC_FX, 16 ) ); /*Q-0*/ } } -- GitLab From 25fda054b935135e3e42b8dac9eb4a469177f08c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 15:09:25 +0530 Subject: [PATCH 12/63] cleanup of float struct members, replacing libcom functions in encoder with fxd [x] Cleanup of structure members from ivas_stat_rend [x] Cleanup of ivas_dirac_dec_binaural_render and ivas_omasa_dirac_td_binaural_jb [x] Cleanup of cy_auto_diff_smooth and cy_auto_diff_smooth_prev [x] Integration of lib_com fixed functions in encoder [x] dirac_output_synthesis_state_structure cleanup --- lib_com/ivas_fb_mixer.c | 126 +++++++- lib_com/ivas_masa_com.c | 137 +++----- lib_com/ivas_prot.h | 4 +- lib_com/ivas_prot_fx.h | 36 +++ lib_com/ivas_sba_config.c | 127 +++++++- lib_com/ivas_spar_com.c | 10 +- lib_dec/ivas_dirac_dec.c | 247 +-------------- lib_dec/ivas_dirac_output_synthesis_cov.c | 27 +- lib_dec/ivas_init_dec.c | 6 +- lib_dec/ivas_jbm_dec.c | 71 ++++- lib_dec/ivas_omasa_dec.c | 116 +++---- lib_dec/ivas_output_config.c | 5 +- lib_dec/ivas_sba_dec.c | 9 +- lib_dec/ivas_spar_decoder.c | 12 +- lib_dec/ivas_spar_md_dec.c | 8 +- lib_dec/lib_dec_fx.c | 31 +- lib_enc/ivas_init_enc.c | 16 + lib_enc/ivas_masa_enc.c | 143 +++++++++ lib_enc/ivas_osba_enc.c | 8 + lib_enc/ivas_sba_enc.c | 8 + lib_enc/ivas_spar_encoder.c | 6 +- lib_enc/ivas_spar_md_enc.c | 18 +- lib_enc/ivas_stat_enc.h | 4 + lib_enc/lib_enc.c | 12 + lib_rend/ivas_allrad_dec.c | 5 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 110 +++++-- lib_rend/ivas_dirac_decorr_dec.c | 309 ++++++++----------- lib_rend/ivas_dirac_output_synthesis_dec.c | 117 ------- lib_rend/ivas_dirac_rend.c | 21 +- lib_rend/ivas_mcmasa_ana.c | 11 +- lib_rend/ivas_output_init.c | 9 + lib_rend/ivas_output_init_fx.c | 4 +- lib_rend/ivas_prot_rend.h | 13 +- lib_rend/ivas_stat_rend.h | 48 +-- lib_rend/ivas_vbap.c | 11 +- lib_rend/lib_rend.c | 136 +------- lib_util/hrtf_file_reader.c | 83 ++--- lib_util/masa_file_reader.c | 7 + 38 files changed, 1037 insertions(+), 1034 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index d3dceac37..a03655eed 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -527,8 +527,8 @@ ivas_error ivas_FB_mixer_open_fx( { if ( fb_cfg->num_out_chans == 0 ) { - hFbMixer->ppFilterbank_inFR_re[i] = NULL; - hFbMixer->ppFilterbank_inFR_im[i] = NULL; + hFbMixer->ppFilterbank_inFR_re_fx[i] = NULL; + hFbMixer->ppFilterbank_inFR_im_fx[i] = NULL; } else { @@ -650,7 +650,7 @@ ivas_error ivas_FB_mixer_open_fx( for ( j = start_diff_band_non48k; j < num_bands; j++ ) { -#if 1 ////////////////////////////////// FLOAT //////////////////////// +#if 0 ////////////////////////////////// FLOAT //////////////////////// if ( ( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k[0][j] = (float *) malloc( sizeof( float ) * pActive_bins_per_band[j] ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); @@ -961,7 +961,7 @@ void ivas_FB_mixer_close( } #ifdef IVAS_FLOAT_FIXED - FOR( j = start_diff_band_non48k; j < num_bands; j++ ) + FOR ( j = start_diff_band_non48k; j < num_bands; j++ ) { free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] ); hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = NULL; @@ -995,6 +995,124 @@ void ivas_FB_mixer_close( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_FB_mixer_close_fx( + IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ + const int32_t sampling_rate, /* i : sampling rate in Hz */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +) +{ + IVAS_FB_MIXER_HANDLE hFbMixer; + IVAS_FB_CFG *fb_cfg; + int16_t i, j, num_bands; + int16_t num_chs_alloc; + + hFbMixer = *hFbMixer_in; + fb_cfg = hFbMixer->fb_cfg; + + IF ( fb_cfg->active_w_mixing == -1 ) + { + num_chs_alloc = 0; + } + ELSE IF ( fb_cfg->active_w_mixing ) + { + num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); + } + ELSE + { + num_chs_alloc = 1; /* only W channel processed for predicting YZX */ + } + + IF ( hFbMixer != NULL ) + { + FOR ( i = 0; i < num_chs_alloc; i++ ) + { + IF ( fb_cfg->num_out_chans > 0 ) + { + j = fb_cfg->remix_order[i]; + + free( hFbMixer->ppFilterbank_inFR_re_fx[j] ); + hFbMixer->ppFilterbank_inFR_re_fx[j] = NULL; + + free( hFbMixer->ppFilterbank_inFR_im_fx[j] ); + hFbMixer->ppFilterbank_inFR_im_fx[j] = NULL; + } + } + + IF ( fb_cfg->active_w_mixing == -1 ) + { + num_chs_alloc = 0; + } + ELSE + { + num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); + } + + FOR ( i = 0; i < num_chs_alloc; i++ ) + { + free( hFbMixer->ppFilterbank_prior_input_fx[i] ); + hFbMixer->ppFilterbank_prior_input_fx[i] = NULL; + } + + IF ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + { + free( hFbMixer->prior_mixer_fx[0][0] ); + hFbMixer->prior_mixer_fx[0][0] = NULL; + } + + IF ( !spar_reconfig_flag ) + { + IF ( fb_cfg->num_out_chans > 0 ) + { + num_bands = hFbMixer->pFb->filterbank_num_bands; + + IF ( fb_cfg->active_w_mixing != -1 ) + { + FOR ( i = 0; i < num_bands; i++ ) + { + free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band_fx[i] ); + hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band_fx[i] = NULL; + } + } + + IF ( sampling_rate != 48000 ) + { + int16_t start_diff_band_non48k; + start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands; + + FOR ( j = start_diff_band_non48k; j < num_bands; j++ ) + { + free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] ); + hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = NULL; + + free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j] ); + hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[1][j] = NULL; + } + } + } + IF ( hFbMixer->pFb != NULL ) + { + free( hFbMixer->pFb ); + hFbMixer->pFb = NULL; + } + } + + IF ( hFbMixer->fb_cfg != NULL ) + { + free( hFbMixer->fb_cfg ); + hFbMixer->fb_cfg = NULL; + } + + IF ( !spar_reconfig_flag ) + { + free( hFbMixer ); + hFbMixer = NULL; + } + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_fb_mixer_pcm_ingest() diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index c4cac721c..bce454a57 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -58,13 +58,13 @@ * Local prototypes *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static int16_t quantize_theta_masa( float x, const int16_t no_cb, float *xhat ); -#ifdef IVAS_FLOAT_FIXED -static Word16 quantize_theta_masa_fx( const Word32 x_fx, const Word16 no_cb, Word32 *xhat_fx ); -#endif static int16_t quantize_phi_masa( float phi, const int16_t flag_delta, float *phi_hat, const int16_t n ); -#ifdef IVAS_FLOAT_FIXED +#else +static Word16 quantize_theta_masa_fx( const Word32 x_fx, const Word16 no_cb, Word32 *xhat_fx ); + static int16_t quantize_phi_masa_fx( const Word32 phi, const Word16 flag_delta, Word32 *phi_hat, const Word16 n ); #endif @@ -75,6 +75,7 @@ static int16_t quantize_phi_masa_fx( const Word32 phi, const Word16 flag_delta, * Set-up MASA coding elements and bitrates *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_masa_set_elements( const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t mc_mode, /* i : MC format mode */ @@ -164,7 +165,7 @@ void ivas_masa_set_elements( return; } - +#else void ivas_masa_set_elements_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const Word16 mc_mode, /* i : MC format mode */ @@ -282,6 +283,8 @@ void ivas_masa_set_elements_fx( return; } +#endif + /*--------------------------------------------------------------- * generate_gridEq() @@ -289,6 +292,7 @@ void ivas_masa_set_elements_fx( * generate Spherical grid *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void generate_gridEq( SPHERICAL_GRID_DATA *data /* o : data structure for grid */ ) @@ -322,8 +326,7 @@ void generate_gridEq( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void generate_gridEq_fx( SPHERICAL_GRID_DATA *data /* o : data structure for grid */ ) @@ -355,6 +358,7 @@ void generate_gridEq_fx( * and other metadata properties. *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_masa_set_coding_config( MASA_CODEC_CONFIG *config, /* i/o: MASA coding config structure */ int16_t *band_mapping, /* o : Band mapping used */ @@ -484,15 +488,7 @@ void ivas_masa_set_coding_config( return; } - -#ifdef IVAS_FLOAT_FIXED -/*--------------------------------------------------------------- - * ivas_masa_set_coding_config_fx() - * - * Sets MASA codec parameters based on bitrate, number of directions, - * and other metadata properties. - *---------------------------------------------------------------*/ - +#else void ivas_masa_set_coding_config_fx( MASA_CODEC_CONFIG *config, /* i/o: MASA coding config structure */ Word16 *band_mapping, /* o : Band mapping used */ @@ -654,6 +650,7 @@ void ivas_masa_set_coding_config_fx( * *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void masa_sample_rate_band_correction( MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */ int16_t *band_mapping, /* i/o: Band mapping used and modified */ @@ -702,17 +699,9 @@ void masa_sample_rate_band_correction( for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { hQMetaData->q_direction[0].band_data[band].azimuth[sf] = 0.0f; -#ifdef IVAS_FLOAT_FIXED - hQMetaData->q_direction[0].band_data[band].azimuth_fx[sf] = 0; -#endif hQMetaData->q_direction[0].band_data[band].elevation[sf] = 0.0f; -#ifdef IVAS_FLOAT_FIXED - hQMetaData->q_direction[0].band_data[band].elevation_fx[sf] = 0; -#endif hQMetaData->q_direction[0].band_data[band].energy_ratio[sf] = 0.0f; -#ifdef IVAS_FLOAT_FIXED - hQMetaData->q_direction[0].band_data[band].energy_ratio_fx[sf] = 0; -#endif + if ( hQMetaData->coherence_flag && hQMetaData->q_direction[0].coherence_band_data != NULL ) { hQMetaData->q_direction[0].coherence_band_data[band].spread_coherence[sf] = 0u; @@ -721,17 +710,8 @@ void masa_sample_rate_band_correction( if ( hQMetaData->no_directions == 2 ) { hQMetaData->q_direction[1].band_data[band].azimuth[sf] = 0.0f; -#ifdef IVAS_FLOAT_FIXED - hQMetaData->q_direction[1].band_data[band].azimuth_fx[sf] = 0; -#endif hQMetaData->q_direction[1].band_data[band].elevation[sf] = 0.0f; -#ifdef IVAS_FLOAT_FIXED - hQMetaData->q_direction[1].band_data[band].elevation_fx[sf] = 0; -#endif hQMetaData->q_direction[1].band_data[band].energy_ratio[sf] = 0.0f; -#ifdef IVAS_FLOAT_FIXED - hQMetaData->q_direction[1].band_data[band].energy_ratio_fx[sf] = 0; -#endif if ( hQMetaData->coherence_flag && hQMetaData->q_direction[1].coherence_band_data != NULL ) { @@ -774,8 +754,7 @@ void masa_sample_rate_band_correction( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void masa_sample_rate_band_correction_fx( MASA_CODEC_CONFIG *config, /* i/o: MASA codec config */ Word16 *band_mapping, /* i/o: Band mapping used and modified */ @@ -899,6 +878,7 @@ void masa_sample_rate_band_correction_fx( *------------------------------------------------------------------------*/ /*! r: output index for direction */ +#ifndef IVAS_FLOAT_FIXED uint16_t index_theta_phi_16( float *p_theta, /* i/o: input elevation to be indexed */ float *p_phi, /* i/o: input azimuth to be indexed */ @@ -988,15 +968,7 @@ uint16_t index_theta_phi_16( return idx_sph; } - -#ifdef IVAS_FLOAT_FIXED -/*------------------------------------------------------------------------- - * index_theta_phi_16_fx() - * - * - *------------------------------------------------------------------------*/ - -/*! r: output index for direction */ +#else UWord16 index_theta_phi_16_fx( Word32 *p_theta, /* i/o: input elevation to be indexed */ Word32 *p_phi, /* i/o: input azimuth to be indexed */ @@ -1102,6 +1074,7 @@ UWord16 index_theta_phi_16_fx( } #endif + /*------------------------------------------------------------------------- * quantize_phi_masa() * @@ -1109,6 +1082,7 @@ UWord16 index_theta_phi_16_fx( *------------------------------------------------------------------------*/ /*! r: output index */ +#ifndef IVAS_FLOAT_FIXED static int16_t quantize_theta_masa( float x, /* i : theta value to be quantized */ const int16_t no_cb, /* i : number of codewords */ @@ -1142,15 +1116,7 @@ static int16_t quantize_theta_masa( return imin; } - -#ifdef IVAS_FLOAT_FIXED -/*------------------------------------------------------------------------- - * quantize_theta_masa_fx() - * - * - *------------------------------------------------------------------------*/ - -/*! r: output index */ +#else static Word16 quantize_theta_masa_fx( const Word32 x_fx, /* i : theta value to be quantized */ const Word16 no_cb, /* i : number of codewords */ @@ -1186,6 +1152,7 @@ static Word16 quantize_theta_masa_fx( } #endif + /*------------------------------------------------------------------------- * quantize_phi_masa() * @@ -1193,6 +1160,7 @@ static Word16 quantize_theta_masa_fx( *------------------------------------------------------------------------*/ /*! r: index azimuth */ +#ifndef IVAS_FLOAT_FIXED static int16_t quantize_phi_masa( float phi, /* i : azimuth value */ const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ @@ -1238,15 +1206,7 @@ static int16_t quantize_phi_masa( return id_phi; } - -#ifdef IVAS_FLOAT_FIXED -/*------------------------------------------------------------------------- - * quantize_phi_masa_fx() - * - * - *------------------------------------------------------------------------*/ - -/*! r: index azimuth */ +#else static Word16 quantize_phi_masa_fx( const Word32 phi_fx, /* i : azimuth value */ const Word16 flag_delta, /* i : flag indicating if the azimuth codebook is translated or not */ @@ -1301,9 +1261,9 @@ static Word16 quantize_phi_masa_fx( return id_phi; } - #endif + /*------------------------------------------------------------------------- * deindex_sph_idx() * @@ -1614,6 +1574,7 @@ void deindex_sph_idx_fx( *---------------------------------------------------------------*/ /*! r: valid or not 1/0 */ +#ifndef IVAS_FLOAT_FIXED int16_t valid_ratio_index( int16_t index, /* i : index to be checked */ const int16_t K, /* i : L1 norm to check against */ @@ -1650,8 +1611,7 @@ int16_t valid_ratio_index( return out; } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 valid_ratio_index_fx( Word16 index, /* i : index to be checked */ const Word16 K, /* i : L1 norm to check against */ @@ -1708,6 +1668,7 @@ Word16 valid_ratio_index_fx( * Obtains ISM ratio values from the quantized indexes *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void reconstruct_ism_ratios( int16_t *ratio_ism_idx, /* i : index vector */ const int16_t nchan_ism, /* i : number of components/objects */ @@ -1734,14 +1695,7 @@ void reconstruct_ism_ratios( return; } - - -/*--------------------------------------------------------------- - * reconstruct_ism_ratios_fx() - * - * Obtains ISM ratio values from the quantized indexes - *---------------------------------------------------------------*/ - +#else void reconstruct_ism_ratios_fx( Word16 *ratio_ism_idx, /* i : index vector Q0 */ const Word16 nchan_ism, /* i : number of components/objects Q0 */ @@ -1774,6 +1728,7 @@ void reconstruct_ism_ratios_fx( return; } +#endif /*--------------------------------------------------------------- @@ -1783,6 +1738,7 @@ void reconstruct_ism_ratios_fx( * to the total audio scene *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_modify_masa_energy_ratios( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] ) @@ -1811,15 +1767,7 @@ void ivas_omasa_modify_masa_energy_ratios( return; } - -#ifdef IVAS_FLOAT_FIXED -/*--------------------------------------------------------------- - * ivas_omasa_modify_masa_energy_ratios_fx() - * - * Updates energy ratios by taking into account the MASA content contribution - * to the total audio scene - *---------------------------------------------------------------*/ - +#else void ivas_omasa_modify_masa_energy_ratios_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_MAXIMUM_CODING_SUBBANDS] /* Q30 */ ) @@ -1863,6 +1811,7 @@ void ivas_omasa_modify_masa_energy_ratios_fx( * Obtain ISM ratio indexes for even content distribution bbetween objects *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void distribute_evenly_ism( int16_t *idx, /* o : index values */ const int16_t K, /* i : sum of indexes */ @@ -1895,14 +1844,7 @@ void distribute_evenly_ism( return; } - -#ifdef IVAS_FLOAT_FIXED -/*--------------------------------------------------------------- - * distribute_evenly_ism_fx() - * - * Obtain ISM ratio indexes for even content distribution bbetween objects - *---------------------------------------------------------------*/ - +#else void distribute_evenly_ism_fx( Word16 *idx, /* o : index values */ const Word16 K, /* i : sum of indexes */ @@ -1959,6 +1901,7 @@ void distribute_evenly_ism_fx( *---------------------------------------------------------------*/ /*! r: CPE bitrate value */ +#ifndef IVAS_FLOAT_FIXED int32_t calculate_cpe_brate_MASA_ISM( const ISM_MODE ism_mode, /* i : ism mode */ const int32_t ivas_total_brate, /* i : IVAS total bitrate */ @@ -1994,16 +1937,7 @@ int32_t calculate_cpe_brate_MASA_ISM( return cpe_brate; } - - -/*--------------------------------------------------------------- - * calculate_cpe_brate_MASA_ISM_fx() - * - * Calculates bitrate for MASA_ISM mode that is not used for separated objects, - * * but for the CPE part (metadata included) - *---------------------------------------------------------------*/ - -/*! r: CPE bitrate value */ +#else Word32 calculate_cpe_brate_MASA_ISM_fx( const ISM_MODE ism_mode, /* i : ism mode */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ @@ -2044,3 +1978,4 @@ Word32 calculate_cpe_brate_MASA_ISM_fx( return cpe_brate; } +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ca0bcf69e..058e962ac 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -7379,7 +7379,7 @@ ivas_error ivas_omasa_ism_metadata_dec( const int16_t dirac_bs_md_write_idx, /* i : DirAC bitstream write index */ int16_t nb_bits_metadata[] /* o : number of ISM metadata bits */ ); - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_omasa_dirac_td_binaural_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of samples requested */ @@ -7388,7 +7388,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( const int16_t nchan_transport, /* i : number of transport channels */ float *output_f[] /* o : rendered time signal */ ); - +#endif void ivas_omasa_rearrange_channels( float *output[], /* o : output synthesis signal */ const int16_t nchan_transport_ism, /* i : number of ISM TCs */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 61a49b5d1..10885e58b 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2223,6 +2223,12 @@ ivas_error ivas_FB_mixer_open_fx( const Word16 spar_reconfig_flag /* i : SPAR reconfiguration flag */ ); +void ivas_FB_mixer_close_fx( + IVAS_FB_MIXER_HANDLE *hFbMixer_in, /* i/o: FB mixer handle */ + const int32_t sampling_rate, /* i : sampling rate in Hz */ + const int16_t spar_reconfig_flag /* i : SPAR reconfiguration flag */ +); + void ivas_fb_mixer_cross_fading_fx( IVAS_FB_MIXER_HANDLE hFbMixer, Word32 **ppOut_pcm_fx, @@ -2232,4 +2238,34 @@ void ivas_fb_mixer_cross_fading_fx( const int16_t frame_len, const int16_t cf_offset ); +// ivas_omasa_dec.c +ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of samples requested */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailable, /* o : number of samples still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_fx[] /* o : rendered time signal */ +); + +Word16 ivas_sba_get_analysis_order_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order /* i : Ambisonic (SBA) order */ +); + +Word16 ivas_sba_get_nchan_metadata_fx( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate /* i : IVAS total bitrate */ +); + +void ivas_sba_get_spar_hoa_ch_ind_fx( + const Word16 num_md_chs, /* i : number of MD channels */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ); + +void ivas_sba_get_spar_hoa_md_flag_fx( + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word16 *spar_hoa_md_flag, + Word16 *spar_hoa_dirac2spar_md_flag ); #endif diff --git a/lib_com/ivas_sba_config.c b/lib_com/ivas_sba_config.c index 737127e59..23096223f 100644 --- a/lib_com/ivas_sba_config.c +++ b/lib_com/ivas_sba_config.c @@ -50,6 +50,7 @@ * Configure SBA coding *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_sba_config( const int32_t sba_total_brate, /* i : SBA total bitrate */ int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -113,8 +114,7 @@ void ivas_sba_config( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_sba_config_fx( const Word32 sba_total_brate, /* i : SBA total bitrate */ Word16 sba_order, /* i : Ambisonic (SBA) order */ @@ -126,6 +126,7 @@ void ivas_sba_config_fx( Word16 *element_mode /* o : element mode of the core coder */ ) { + test(); IF( ( LT_16( sba_order, 0 ) ) && ( LT_16( nb_channels, 0 ) ) ) { assert( 0 && "Either order or number of channels must be positive" ); @@ -136,7 +137,7 @@ void ivas_sba_config_fx( } ELSE IF( LT_16( nb_channels, 0 ) ) { - nb_channels = (Word16) ivas_sba_get_nchan_fx( sba_order, sba_planar ); + nb_channels = ivas_sba_get_nchan_fx( sba_order, sba_planar ); } ELSE { @@ -161,24 +162,31 @@ void ivas_sba_config_fx( IF( EQ_16( *nchan_transport, 1 ) ) { *nSCE = 1; + move16(); *nCPE = 0; + move16(); *element_mode = IVAS_SCE; + move16(); } ELSE { *nSCE = 0; + move16(); *nCPE = shr( *nchan_transport, 1 ); IF( NE_16( i_mult( 2, ( *nCPE ) ), *nchan_transport ) ) { *nCPE = add( *nCPE, 1 ); } *element_mode = IVAS_CPE_MDCT; + move16(); } } return; } #endif + + /*-------------------------------------------------------------------* * ivas_sba_get_order() * @@ -186,6 +194,7 @@ void ivas_sba_config_fx( *-------------------------------------------------------------------*/ /*! r: Ambisonic (SBA) order */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_sba_get_order( const int16_t nb_channels, /* i : Number of ambisonic channels */ const int16_t sba_planar /* i : SBA Planar flag */ @@ -208,15 +217,17 @@ int16_t ivas_sba_get_order( return ( sba_order ); } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 ivas_sba_get_order_fx( const Word16 nb_channels, /* i : Number of ambisonic channels */ const Word16 sba_planar /* i : SBA Planar flag */ ) { Word16 sba_order; - Word16 exp = 0; + + /* sba_order = (int16_t) sqrtf( (float) nb_channels ) - 1 */ + Word16 sba_order_non_sba_planar[MAX_INPUT_CHANNELS] = { 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3 }; + IF( sba_planar ) { sba_order = shr( sub( nb_channels, 1 ), 1 ); @@ -224,7 +235,8 @@ Word16 ivas_sba_get_order_fx( } ELSE { - sba_order = sub( Sqrt16( nb_channels, &exp ), MAX16B ); // 15 - exp + sba_order = sba_order_non_sba_planar[nb_channels - 1]; + move16(); assert( ( EQ_16( mult( add( sba_order, 1 ), add( sba_order, 1 ) ), nb_channels ) ) && "Number of channels not supported in SBA!" ); } @@ -234,6 +246,7 @@ Word16 ivas_sba_get_order_fx( } #endif + /*-------------------------------------------------------------------* * ivas_sba_get_analysis_order() * @@ -241,7 +254,26 @@ Word16 ivas_sba_get_order_fx( *-------------------------------------------------------------------*/ /*! r: Ambisonic (SBA) order used for analysis and coding */ -Word16 ivas_sba_get_analysis_order( +#ifndef IVAS_FLOAT_FIXED +int16_t ivas_sba_get_analysis_order( + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +) +{ + int16_t sba_analysis_order; + + sba_analysis_order = sba_order; + + if ( ivas_total_brate < SBA_MIN_BRATE_HOA ) + { + /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */ + sba_analysis_order = SBA_FOA_ORDER; + } + + return sba_analysis_order; +} +#else +Word16 ivas_sba_get_analysis_order_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const Word16 sba_order /* i : Ambisonic (SBA) order */ ) @@ -249,15 +281,18 @@ Word16 ivas_sba_get_analysis_order( Word16 sba_analysis_order; sba_analysis_order = sba_order; + move16(); IF( LT_32( ivas_total_brate, SBA_MIN_BRATE_HOA ) ) { /* Hard coding the sba_analysis_order as 1 as higher not supported below SBA_MIN_BRATE_HOA bitrate */ sba_analysis_order = SBA_FOA_ORDER; + move16(); } return sba_analysis_order; } +#endif /*-------------------------------------------------------------------* @@ -285,7 +320,7 @@ int16_t ivas_sba_get_nchan( return ( nb_channels ); } - +#ifdef IVAS_FLOAT_FIXED Word16 ivas_sba_get_nchan_fx( const Word16 sba_order, /* i : Ambisonic (SBA) order */ const Word16 sba_planar /* i : SBA planar flag */ @@ -295,15 +330,17 @@ Word16 ivas_sba_get_nchan_fx( IF( sba_planar ) { - nb_channels = add( mult( 2, sba_order ), 1 ); + nb_channels = add( shl( sba_order, 1 ), 1 ); } ELSE { - nb_channels = mult0( add( sba_order, 1 ), add( sba_order, 1 ) ); + nb_channels = i_mult( add( sba_order, 1 ), add( sba_order, 1 ) ); } return ( nb_channels ); } +#endif + /*-------------------------------------------------------------------* * ivas_sba_get_nchan_metadata() @@ -313,7 +350,7 @@ Word16 ivas_sba_get_nchan_fx( /*! r: number of ambisonics metadata channels */ #ifdef IVAS_FLOAT_FIXED -Word16 ivas_sba_get_nchan_metadata( +Word16 ivas_sba_get_nchan_metadata_fx( const Word16 sba_order, /* i : Ambisonic (SBA) order */ const Word32 ivas_total_brate /* i : IVAS total bitrate */ ) @@ -342,7 +379,7 @@ Word16 ivas_sba_get_nchan_metadata( return ( nb_channels ); } -#else +#endif int16_t ivas_sba_get_nchan_metadata( const int16_t sba_order, /* i : Ambisonic (SBA) order */ const int32_t ivas_total_brate /* i : IVAS total bitrate */ @@ -370,7 +407,6 @@ int16_t ivas_sba_get_nchan_metadata( return ( nb_channels ); } -#endif /*-------------------------------------------------------------------* @@ -380,7 +416,33 @@ int16_t ivas_sba_get_nchan_metadata( *-------------------------------------------------------------------*/ /*! r: flag indicating to code SPAR HOA MD for all bands */ +#ifndef IVAS_FLOAT_FIXED void ivas_sba_get_spar_hoa_ch_ind( + const int16_t num_md_chs, /* i : number of MD channels */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + int16_t HOA_md_ind[IVAS_SPAR_MAX_CH] ) +{ + int16_t ch; + const int16_t *hoa_ind; + + if ( ivas_total_brate >= IVAS_512k ) + { + hoa_ind = HOA_keep_ind_spar512; + } + else + { + hoa_ind = HOA_keep_ind_spar; + } + + for ( ch = 0; ch < num_md_chs; ch++ ) + { + HOA_md_ind[ch] = hoa_ind[ch]; + } + + return; +} +#else +void ivas_sba_get_spar_hoa_ch_ind_fx( const Word16 num_md_chs, /* i : number of MD channels */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word16 HOA_md_ind[IVAS_SPAR_MAX_CH] ) @@ -400,10 +462,12 @@ void ivas_sba_get_spar_hoa_ch_ind( FOR( ch = 0; ch < num_md_chs; ch++ ) { HOA_md_ind[ch] = hoa_ind[ch]; + move16(); } return; } +#endif /*-------------------------------------------------------------------* @@ -412,32 +476,67 @@ void ivas_sba_get_spar_hoa_ch_ind( * Get the flag to code SPAR HOA MD for all band *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_sba_get_spar_hoa_md_flag( + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + int16_t *spar_hoa_md_flag, + int16_t *spar_hoa_dirac2spar_md_flag ) +{ + if ( sba_order > 1 && ivas_total_brate >= IVAS_256k ) + { + *spar_hoa_md_flag = 1; + } + else + { + *spar_hoa_md_flag = 0; + } + + if ( sba_order > 1 && ivas_total_brate >= IVAS_512k ) + { + *spar_hoa_dirac2spar_md_flag = 0; + } + else + { + *spar_hoa_dirac2spar_md_flag = 1; + } + + return; +} +#else +void ivas_sba_get_spar_hoa_md_flag_fx( const Word16 sba_order, /* i : Ambisonic (SBA) order */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word16 *spar_hoa_md_flag, Word16 *spar_hoa_dirac2spar_md_flag ) { + test(); IF( GT_16( sba_order, 1 ) && GE_32( ivas_total_brate, IVAS_256k ) ) { *spar_hoa_md_flag = 1; + move16(); } ELSE { *spar_hoa_md_flag = 0; + move16(); } + test(); IF( GT_16( sba_order, 1 ) && GE_32( ivas_total_brate, IVAS_512k ) ) { *spar_hoa_dirac2spar_md_flag = 0; + move16(); } ELSE { *spar_hoa_dirac2spar_md_flag = 1; + move16(); } return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index a7299b89f..f37d9ce7d 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -3154,9 +3154,9 @@ void ivas_get_spar_md_from_dirac_fx( remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; - num_ch = ivas_sba_get_nchan_metadata( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); + num_ch = ivas_sba_get_nchan_metadata_fx( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); - hoa2_ch = ivas_sba_get_nchan_metadata( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); + hoa2_ch = ivas_sba_get_nchan_metadata_fx( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); // hoa2_ch max 6 foa_ch = FOA_CHANNELS; // foa_ch 4; @@ -3318,8 +3318,8 @@ void ivas_get_spar_md_from_dirac_fx( Word16 norm_q; int16_t num_ch_order, hoa2_ch_order; - num_ch_order = ivas_sba_get_nchan( order, 0 ); - hoa2_ch_order = ivas_sba_get_nchan( SBA_HOA2_ORDER, 0 ); + num_ch_order = ivas_sba_get_nchan_fx( order, 0 ); + hoa2_ch_order = ivas_sba_get_nchan_fx( SBA_HOA2_ORDER, 0 ); for ( ch = 0; ch < num_ch_order; ch++ ) { @@ -6765,7 +6765,7 @@ void ivas_spar_set_bitrate_config_fx( num_PR_bits_dirac_bands = s_max( 0, num_PR_bits_dirac_bands ); num_PR_bits_dirac_bands = i_mult( num_PR_bits_dirac_bands, DIRAC_TO_SPAR_HBR_PRED_CHS ); - n_input = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); + n_input = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; n_dec = sub( n_input, n_dmx ); bits_PR = ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][0]; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 1dbb0e8ee..cadcb29a9 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -182,11 +182,7 @@ static ivas_error ivas_dirac_rend_config_fx( Word16 num_outputs_dir_old; Word16 num_outputs_diff_old; Word16 num_protos_diff_old; - /*Todo: remove float code*/ - float *proto_frame_f_old; -#ifdef IVAS_FLOAT_FIXED Word32 *proto_frame_f_old_fx; -#endif Word16 proto_signal_decorr_on_old; uint16_t i, j, k; Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; @@ -244,7 +240,7 @@ static ivas_error ivas_dirac_rend_config_fx( nchan_transport_orig = st_ivas->nchan_transport; IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - st_ivas->nchan_transport = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); } nchan_transport = st_ivas->nchan_transport; @@ -729,13 +725,6 @@ IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirAC IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { -#if 1 /*TODO : remove float code*/ - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f ) - { - free( hDirACRend->proto_frame_f ); - } - hDirACRend->proto_frame_f = NULL; -#endif IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) { free( hDirACRend->proto_frame_f_fx ); @@ -761,25 +750,6 @@ ELSE } } hDirACRend->proto_frame_f_len = 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands; -#ifdef TRUE - /*Todo : to remove float code*/ - if ( flag_config == DIRAC_OPEN || ( flag_config == DIRAC_RECONFIGURE && hDirACRend->proto_frame_f == NULL ) ) - { - if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - } - else if ( flag_config == DIRAC_RECONFIGURE && ( hDirACRend->num_protos_diff != num_protos_diff_old ) ) - { - proto_frame_f_old = hDirACRend->proto_frame_f; - free( proto_frame_f_old ); - if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } - } -#endif } IF( EQ_16( flag_config, DIRAC_OPEN ) ) @@ -3542,8 +3512,9 @@ void ivas_dirac_dec_render_sf_fx( if ( h_dirac_output_synthesis_params->use_onset_filters && ( hDirAC->hConfig->dec_param_estim != TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) ) { - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, tmp1 - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1; } if ( hDirAC->hConfig->dec_param_estim == TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) @@ -3552,18 +3523,13 @@ void ivas_dirac_dec_render_sf_fx( scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); h_dirac_output_synthesis_state->q_cy_auto_dir_smooth += shift; - // h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - // floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); h_dirac_output_synthesis_state->q_cy_cross_dir_smooth += shift; - /*h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands );*/ - - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, tmp1 ); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth += tmp1; } if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) @@ -3629,51 +3595,40 @@ void ivas_dirac_dec_render_sf_fx( /////////////////////////////////////////////////////////////////////////////////////////////// size = hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands; size_ho = ( hodirac_flag ) ? size * DIRAC_HO_NUMSECTORS : size; + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, size ); + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth += shift; - // hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, size_ho ); - // floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ); hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; - // hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; - // floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); - + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); } ELSE { - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); + hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev += shift; - /*hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, size_ho ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, size_ho );*/ - shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev += shift; - - /*hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, size_ho ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho );*/ - - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); + tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE, tmp1 ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev += tmp1; tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands, tmp1 ); @@ -5026,178 +4981,10 @@ void ivas_dirac_dec_render_sf_fx( #ifdef IVAS_FLOAT_FIXED /////////////////////////////////////////////////////// FIXED TO FLOAT ////////////////////////////////////////////////////////////////////////////////////////// - IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) - { - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, hSpatParamRendCom->num_freq_bands ); - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, hSpatParamRendCom->num_freq_bands ); - } - ELSE - { - // me2f_buf( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, 31 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hSpatParamRendCom->num_freq_bands ); - // me2f_buf( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, 31 - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hSpatParamRendCom->num_freq_bands ); - } - } - IF( st_ivas->hMasa == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) - { - /*fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - - IF( hodirac_flag ) - { - fixedToFloat_arrL32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], &hDirACRend->h_output_synthesis_psd_state.direct_responses[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - }*/ - } - ELSE - { - /*fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_square, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - }*/ - } - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) - { - /*IF( nchan_transport >= 4 ) - { - fixedToFloat_arrL32( reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, 5 * hSpatParamRendCom->num_freq_bands ); - }*/ - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, 2 * nchan_transport * hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, 2 * hDirACRend->num_outputs_diff * hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - } - ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) - { - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], i_mult( 4, hSpatParamRendCom->num_freq_bands ) ) ); - fixedToFloat_arrL32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, i_mult( 6, hSpatParamRendCom->num_freq_bands ) ); - // fixedToFloat_arrL32( reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); - } - ELSE - { - SWITCH( nchan_transport ) - { - case 11: - case 8: - case 6: - case 4: - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( i_mult( 2, hSpatParamRendCom->subframe_nbslots[subframe_idx] ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ) ); - me2f_buf( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_q, hDirACRend->proto_frame_f, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ) ); - // fixedToFloat_arrL32( reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); - BREAK; - case 2: - IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) - { - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], i_mult( 6, hSpatParamRendCom->num_freq_bands ) ) ); - } - ELSE - { - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], i_mult( 4, hSpatParamRendCom->num_freq_bands ) ) ); - } - me2f_buf( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_q, hDirACRend->proto_frame_f, i_mult( 6, hSpatParamRendCom->num_freq_bands ) ); - // fixedToFloat_arrL32( reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); - BREAK; - case 1: - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], i_mult( 2, hSpatParamRendCom->num_freq_bands ) ) ); - me2f_buf( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_q, hDirACRend->proto_frame_f, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) ) ); - // fixedToFloat_arrL32( reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); - BREAK; - } - } - - IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) - { - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) - { - } - ELSE - { - /* me2f_buf( DirAC_mem.frame_dec_f_fx, 31 - DirAC_mem.frame_dec_f_q, DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_len ); - - hDirACRend->proto_frame_dec_f = DirAC_mem.frame_dec_f;*/ - } - } - ELSE - { - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) - { - } - ELSE - { - hDirACRend->proto_frame_dec_f = hDirACRend->proto_frame_f; - } - } - - if ( hDirAC->hConfig->dec_param_estim == FALSE && hodirac_flag ) + IF(EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD)) { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - // fixedToFloat_arrL( h_dirac_output_synthesis_state->direct_power_factor_fx, h_dirac_output_synthesis_state->direct_power_factor, h_dirac_output_synthesis_state->direct_power_factor_q, 2 * hSpatParamRendCom->num_freq_bands ); - // fixedToFloat_arrL( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_state->diffuse_power_factor, h_dirac_output_synthesis_state->diffuse_power_factor_q, 2 * hSpatParamRendCom->num_freq_bands ); - } - else - { - FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], 31 - hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); - // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], 31 - hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); - } - } - } - else if ( hDirAC->hConfig->dec_param_estim == TRUE ) - { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], 31 - h_dirac_output_synthesis_state->direct_power_factor_q ); - // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = me2f( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], 31 - h_dirac_output_synthesis_state->diffuse_power_factor_q ); - } - // fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, (num_channels_dir) *hSpatParamRendCom->num_freq_bands ); - } - else - { - FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); - // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); - } - } - } - - if ( h_dirac_output_synthesis_params->use_onset_filters && ( hDirAC->hConfig->dec_param_estim != TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) ) - { - fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, hDirACRend->num_outputs_diff * hSpatParamRendCom->num_freq_bands ); - } - - if ( hDirAC->hConfig->dec_param_estim == TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - // fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, h_dirac_output_synthesis_state->cy_auto_dir_smooth, h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - // fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, h_dirac_output_synthesis_state->cy_cross_dir_smooth, h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - fixedToFloat_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - } - - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) - { - // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); - // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, size ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr ); - } - ELSE - { - // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, size ); - // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, size_ho ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, size ); - // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, size ); - // fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, size_ho ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); - - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, size ); - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); } if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 1374393e3..6c09458ba 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -201,13 +201,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s( idx, interp_length ); } Copy32( proto_matrix, h_dirac_output_synthesis_params->proto_matrix_fx, nchan_in * nchan_out ); - -#if 1 /*TODO: To be removed later***************************************************************************************/ - if ( ( h_dirac_output_synthesis_params->proto_matrix = (float *) malloc( nchan_out * nchan_in * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); - } -#endif + h_dirac_output_synthesis_params->proto_matrix_e = 5; return IVAS_ERR_OK; } #else @@ -413,17 +407,6 @@ void ivas_dirac_dec_output_synthesis_cov_init_fx( set16_fx( h_dirac_output_synthesis_state->mixing_matrix_exp, 0, CLDFB_NO_CHANNELS_MAX ); set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp, 0, CLDFB_NO_CHANNELS_MAX ); set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_exp, 0, CLDFB_NO_CHANNELS_MAX ); -#if 1 /*TODO: To be removed :Floating point initializations*/ - // FOR ( idx = 0; idx < n_param_bands; idx++ ) - //{ - // set_zero( h_dirac_output_synthesis_state->mixing_matrix[idx], nchan_out * nchan_in ); - // } - - // FOR ( idx = 0; idx < n_param_bands_res; idx++ ) - //{ - // set_zero( h_dirac_output_synthesis_state->mixing_matrix_res[idx], nchan_out * nchan_out ); - // } -#endif return; } @@ -573,14 +556,6 @@ void ivas_dirac_dec_output_synthesis_cov_close_fx( free( h_dirac_output_synthesis_state->mixing_matrix_res_exp ); h_dirac_output_synthesis_state->mixing_matrix_res_exp = NULL; } -#if 1 /*TODO: To be removed later(floating point dealloc)*/ - /* free proto_matrix */ - IF( h_dirac_output_synthesis_params->proto_matrix != NULL ) - { - free( h_dirac_output_synthesis_params->proto_matrix ); - h_dirac_output_synthesis_params->proto_matrix = NULL; - } -#endif return; } #else diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 7a179371f..5b5fcfb55 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -158,7 +158,7 @@ ivas_error ivas_dec_setup( ELSE { /* set Ambisonic (SBA) order used for analysis and coding */ - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); } } @@ -256,9 +256,9 @@ ivas_error ivas_dec_setup( ELSE { /* set Ambisonic (SBA) order used for analysis and coding */ - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); - ivas_sba_config( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); + ivas_sba_config_fx( ivas_total_brate, st_ivas->sba_analysis_order, -1, &( st_ivas->nchan_transport ), st_ivas->sba_planar, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init ); /*correct number of CPEs for discrete ISM coding*/ IF( GT_16( st_ivas->ini_frame, 0 ) && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 56ad79dbb..7002b0453 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -2368,7 +2368,11 @@ void ivas_jbm_dec_feed_tc_to_renderer( { nchan_out_cov = nchan_out_transport; } - f2me_buf( st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, &st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_e, nchan_out_cov * nchan_transport ); + // f2me_buf( st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, &st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_e, nchan_out_cov * nchan_transport ); + + // Word16 shift_p = L_norm_arr(st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, nchan_out_cov * nchan_transport); + // scale_sig32(st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, nchan_out_cov * nchan_transport, shift_p); + // st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_e -= shift_p; scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); st_ivas->hParamMC->proto_matrix_int_e = 1; @@ -2696,7 +2700,15 @@ ivas_error ivas_jbm_dec_render( { if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { +#ifndef IVAS_FLOAT_FIXED ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output ); +#else + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx ); + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); + } +#endif } else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) { @@ -2930,7 +2942,15 @@ ivas_error ivas_jbm_dec_render( /* Loudspeakers, Ambisonics or Binaural rendering */ if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { +#ifndef IVAS_FLOAT_FIXED ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); +#else + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); + } +#endif } else if ( st_ivas->ivas_format == MASA_FORMAT ) { @@ -2973,10 +2993,6 @@ ivas_error ivas_jbm_dec_render( #if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; -#ifndef MSAN_FIX - uint16_t nchan_internal; - nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); -#endif hSpar->hMdDec->Q_mixer_mat = 30; #endif // @@ -3000,14 +3016,34 @@ ivas_error ivas_jbm_dec_render( { if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) { +#ifndef IVAS_FLOAT_FIXED if ( ( error = ivas_omasa_dirac_td_binaural_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ) ) != IVAS_ERR_OK ) { return error; } +#else + IF( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ) != IVAS_ERR_OK ) + { + return error; + } + + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); + } +#endif } else { +#ifndef IVAS_FLOAT_FIXED ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); +#else + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); + } +#endif } } else if ( st_ivas->renderer_type == RENDERER_DIRAC ) @@ -3168,7 +3204,15 @@ ivas_error ivas_jbm_dec_render( } else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { +#ifndef IVAS_FLOAT_FIXED ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); +#else + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); + } +#endif } else { @@ -3488,9 +3532,10 @@ ivas_error ivas_jbm_dec_render( } // ftf for ivas_dirac_dec_decorr_process_fx - Word16 tmp_e; - f2me_buf( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, &tmp_e, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = 31 - tmp_e; + Word16 tmp; + tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); + scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); + st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer += tmp; } if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) { @@ -3514,8 +3559,6 @@ ivas_error ivas_jbm_dec_render( Word16 tempp; FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ ) { - - tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], nchan_transport * nchan_out_cov ); scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], nchan_transport * nchan_out_cov, tempp ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp ); @@ -3582,7 +3625,15 @@ ivas_error ivas_jbm_dec_render( if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { +#ifndef IVAS_FLOAT_FIXED ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); +#else + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) + { + fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); + } +#endif } else if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) /* rendering to CICPxx and Ambisonics */ { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index fb302068d..be58073f4 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -1263,7 +1263,7 @@ void ivas_omasa_dirac_rend_jbm( return; } - +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * ivas_omasa_dirac_td_binaural_render() * @@ -1281,29 +1281,14 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( { int16_t n; float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED - Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; -#else float gain = OMASA_TDREND_MATCHING_GAIN; -#endif ivas_error error; float *p_sepobj[MAX_NUM_OBJECTS]; -#ifdef IVAS_FLOAT_FIXED - Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; -#else float *tc_local[MAX_TRANSPORT_CHANNELS]; -#endif -#ifdef MSAN_FIX - Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; - Word32 data_separated_objects_fx[MAX_NUM_OBJECTS][L_FRAME48k]; -#endif // MSAN_FIX for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) { p_sepobj[n] = &data_separated_objects[n][0]; -#ifdef MSAN_FIX - p_sepobj_fx[n] = &data_separated_objects_fx[n][0]; -#endif // MSAN_FIX } /* Delay the object signals to match the CLDFB delay. Delay the whole buffer with the first rendering call of the stretched buffer. */ @@ -1315,16 +1300,9 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( for ( n = 0; n < st_ivas->nchan_ism; n++ ) { -#ifdef IVAS_FLOAT_FIXED - tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; - v_multc_fixed_16( tc_local_fx[n], gain_fx, tc_local_fx[n], tcBufferSize ); - - delay_signal_fx( tc_local_fx[n], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size ); -#else tc_local[n] = st_ivas->hTcBuffer->tc[n + 2]; v_multc( tc_local[n], gain, tc_local[n], tcBufferSize ); delay_signal_float( tc_local[n], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size ); -#endif // IVAS_FLOAT_FIXED } } @@ -1333,60 +1311,82 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( /* reset combined orientation access index before calling the td renderer */ ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); -#ifdef IVAS_FLOAT_FIXED -#if 1 /* TODO: remove float to fix conversions */ - Word16 q_factor = Q11; -#ifndef MSAN_FIX - Word32 rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; - Word32 *p_rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - for ( int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) + if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) { - p_rend_output_fx[i] = rend_output_fx[i]; - for ( int j = 0; j < L_FRAME48k; j++ ) - { - p_rend_output_fx[i][j] = floatToFixed( p_sepobj[i][j], Q11 ); - } + return error; } -#endif -#endif -#ifdef MSAN_FIX - IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) + for ( n = 0; n < BINAURAL_CHANNELS; n++ ) { - return error; + v_add( output_f[n], p_sepobj[n], output_f[n], *nSamplesRendered ); } + + return IVAS_ERR_OK; +} #else - IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_rend_output_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) +/*--------------------------------------------------------------------------* + * ivas_omasa_dirac_td_binaural_render() + * + * Binaural rendering in OMASA format for JBM + *--------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of samples requested */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailable, /* o : number of samples still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_fx[] /* o : rendered time signal */ +) +{ + Word16 n; + Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; + move16(); + ivas_error error; + Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; + Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; + Word32 data_separated_objects_fx[MAX_NUM_OBJECTS][L_FRAME48k]; + Word16 q_factor = Q11; + move16(); + + FOR( n = 0; n < MAX_NUM_OBJECTS; n++ ) { - return error; + p_sepobj_fx[n] = &data_separated_objects_fx[n][0]; } -#endif -#if 1 /* TODO: remove fixed to float conversions */ - for ( int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) + + /* Delay the object signals to match the CLDFB delay. Delay the whole buffer with the first rendering call of the stretched buffer. */ + IF( EQ_16( st_ivas->hSpatParamRendCom->slots_rendered, 0 ) ) { - for ( int j = 0; j < L_FRAME48k; j++ ) + Word16 tcBufferSize; + + tcBufferSize = imult1616( st_ivas->hSpatParamRendCom->num_slots, st_ivas->hSpatParamRendCom->slot_size ); + + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { -#ifdef MSAN_FIX - p_sepobj[i][j] = fixedToFloat( p_sepobj_fx[i][j], Q11 ); -#else - p_sepobj[i][j] = fixedToFloat( p_rend_output_fx[i][j], Q11 ); -#endif + tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; + v_multc_fixed_16( tc_local_fx[n], gain_fx, tc_local_fx[n], tcBufferSize ); + + delay_signal_fx( tc_local_fx[n], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size ); } } -#endif -#else - if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) + + ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, nchan_transport, output_fx ); + + /* reset combined orientation access index before calling the td renderer */ + ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); + + IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } -#endif - for ( n = 0; n < BINAURAL_CHANNELS; n++ ) + + FOR( n = 0; n < BINAURAL_CHANNELS; n++ ) { - v_add( output_f[n], p_sepobj[n], output_f[n], *nSamplesRendered ); + v_add_fx( output_fx[n], p_sepobj_fx[n], output_fx[n], *nSamplesRendered ); } return IVAS_ERR_OK; } - +#endif /*--------------------------------------------------------------------------* * ivas_omasa_rearrange_channels() diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config.c index 18d7b0c50..2e34c3508 100644 --- a/lib_dec/ivas_output_config.c +++ b/lib_dec/ivas_output_config.c @@ -36,6 +36,9 @@ #include "ivas_prot.h" #include "ivas_stat_dec.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*-------------------------------------------------------------------------* @@ -166,7 +169,7 @@ void ivas_renderer_select( IF( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) { - nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); test(); test(); test(); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 214a5e430..9da244a34 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -802,7 +802,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( nchan_transport_old = st_ivas->nchan_transport; sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); *nSamplesFlushed = 0; granularity_new = st_ivas->hTcBuffer->n_samples_granularity; @@ -896,7 +896,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( #endif // IVAS_FLOAT_FIXED /* restore correct values for the current frame*/ - st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; } else if ( granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) @@ -1356,7 +1356,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { - tc_nchan_to_allocate = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + tc_nchan_to_allocate = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) { @@ -1820,6 +1820,7 @@ void ivas_sba_dec_digest_tc_fx( * * *-------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED ivas_error ivas_sba_dec_render_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -1843,7 +1844,7 @@ ivas_error ivas_sba_dec_render_fx( move16(); hSpar = st_ivas->hSpar; hSpatParamRendCom = st_ivas->hSpatParamRendCom; - nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); FOR( ch = 0; ch < nchan_out; ch++ ) diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 52a12a737..09757dbf8 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -296,7 +296,7 @@ ivas_error ivas_spar_dec_open_fx( sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - num_channels_internal = ivas_sba_get_nchan_metadata( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); + num_channels_internal = ivas_sba_get_nchan_metadata_fx( sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate ); hSpar = st_ivas->hSpar; @@ -531,7 +531,11 @@ void ivas_spar_dec_close( ivas_td_decorr_dec_close( &( *hSpar )->hTdDecorr ); /* FB mixer handle */ +#ifdef IVAS_FLOAT_FIXED + ivas_FB_mixer_close_fx( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag ); +#else ivas_FB_mixer_close( &( *hSpar )->hFbMixer, output_Fs, spar_reconfig_flag ); +#endif /* AGC */ #ifdef IVAS_FLOAT_FIXED @@ -1456,7 +1460,7 @@ static ivas_error ivas_spar_dec_MD_fx( move16(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); - num_channels = ivas_sba_get_nchan_metadata( sba_order, ivas_total_brate ); + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; @@ -2369,7 +2373,7 @@ void ivas_spar_dec_agc_pca_fx( IF( hSpar->hMdDec->td_decorr_flag ) { - num_in_ingest = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + num_in_ingest = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); move16(); } ELSE @@ -2632,7 +2636,7 @@ void ivas_spar_dec_digest_tc_fx( /* TD decorrelator */ default_frame = (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); nSamplesLeftForTD = nSamplesForRendering; - nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); FOR( ch = 0; ch < nchan_internal; ch++ ) { diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index dbfa58e17..125d7c7ae 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -970,9 +970,9 @@ ivas_error ivas_spar_md_dec_init( Word32 *pFC_fx = NULL, PR_minmax_fx[2]; ivas_error error; - ivas_sba_get_spar_hoa_md_flag( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag ); + ivas_sba_get_spar_hoa_md_flag_fx( sba_order, hDecoderConfig->ivas_total_brate, &hMdDec->spar_hoa_md_flag, &hMdDec->spar_hoa_dirac2spar_md_flag ); - ivas_sba_get_spar_hoa_ch_ind( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); + ivas_sba_get_spar_hoa_ch_ind_fx( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); @@ -1114,7 +1114,7 @@ static ivas_error ivas_spar_set_dec_config( hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; } - nchan = ivas_sba_get_nchan_metadata( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); + nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); switch ( nchan ) { @@ -1360,7 +1360,7 @@ void ivas_spar_md_dec_process_fx( active_w_vlbr = ( st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; - num_md_chs = ivas_sba_get_nchan_metadata( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); + num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 2764728f6..63830ac15 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -782,25 +782,12 @@ ivas_error IVAS_DEC_FeedFrame_Serial( { PARAM_MC_DEC_HANDLE hParamMC; hParamMC = hIvasDec->st_ivas->hParamMC; - Word16 nchan_out_transport, nchan_out_cov; MC_LS_SETUP mc_ls_setup; - Word16 nchan_transport, i; + Word16 i; mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( hIvasDec->st_ivas->transport_config ); hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); - nchan_transport = hIvasDec->st_ivas->nchan_transport; - nchan_out_transport = hIvasDec->st_ivas->hTransSetup.nchan_out_woLFE + hIvasDec->st_ivas->hTransSetup.num_lfe; - IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - nchan_out_cov = hIvasDec->st_ivas->hOutSetup.nchan_out_woLFE + hIvasDec->st_ivas->hOutSetup.num_lfe; - move16(); - } - ELSE - { - nchan_out_cov = nchan_out_transport; - } IF( hParamMC ) { - fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov ); FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) { fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); @@ -1219,25 +1206,11 @@ static ivas_error IVAS_DEC_Setup( { PARAM_MC_DEC_HANDLE hParamMC; hParamMC = st_ivas->hParamMC; - Word16 nchan_out_transport, nchan_out_cov; MC_LS_SETUP mc_ls_setup; - Word16 nchan_transport; mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); - nchan_transport = st_ivas->nchan_transport; - nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) - { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; - move16(); - } - ELSE - { - nchan_out_cov = nchan_out_transport; - } IF( hParamMC ) { - fixedToFloat_arrL( hParamMC->h_output_synthesis_params.proto_matrix_fx, hParamMC->h_output_synthesis_params.proto_matrix, 26, nchan_transport * nchan_out_cov ); IF( st_ivas->hParamMC->diff_proto_info ) { FOR( i = 0; i < hParamMC->diff_proto_info->num_protos_diff; i++ ) @@ -1301,7 +1274,7 @@ static ivas_error IVAS_DEC_Setup( { IF( st_ivas->hParamMC ) { - fixedToFloat_arrL( st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, 26, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_len ); + // fixedToFloat_arrL( st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_fx, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix, 26, st_ivas->hParamMC->h_output_synthesis_params.proto_matrix_len ); IF( st_ivas->hParamMC->diff_proto_info ) FOR( i = 0; i < st_ivas->hParamMC->diff_proto_info->num_protos_diff; i++ ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index 6137f0114..d48aa6997 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -588,7 +588,11 @@ ivas_error ivas_init_encoder( if ( ivas_format == SBA_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#else + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#endif if ( ( error = ivas_spar_enc_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) { @@ -727,7 +731,11 @@ ivas_error ivas_init_encoder( return error; } +#ifndef IVAS_FLOAT_FIXED st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#else + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#endif if ( ( error = ivas_spar_enc_open( st_ivas, 0 ) ) != IVAS_ERR_OK ) { @@ -1141,7 +1149,11 @@ ivas_error ivas_init_encoder_fx( IF( ivas_format == SBA_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#else + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#endif IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { @@ -1280,7 +1292,11 @@ ivas_error ivas_init_encoder_fx( return error; } +#ifndef IVAS_FLOAT_FIXED st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#else + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); +#endif if ( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 2ff2e226d..6f10ae187 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -40,6 +40,8 @@ #include "wmc_auto.h" #include "prot.h" #ifdef IVAS_FLOAT_FIXED +#include "prot_fx1.h" +#include "prot_fx2.h" #include "ivas_prot_fx.h" #endif @@ -112,7 +114,11 @@ ivas_error ivas_masa_enc_open( hEncoderConfig = st_ivas->hEncoderConfig; +#ifndef IVAS_FLOAT_FIXED generate_gridEq( &( hMasa->data.Sph_Grid16 ) ); +#else + generate_gridEq_fx( &( hMasa->data.Sph_Grid16 ) ); +#endif if ( hEncoderConfig->ivas_format == MASA_FORMAT || hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { @@ -140,7 +146,11 @@ ivas_error ivas_masa_enc_open( } } +#ifndef IVAS_FLOAT_FIXED ivas_masa_set_elements( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); +#else + ivas_masa_set_elements_fx( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); +#endif mvs2s( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); mvs2s( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); @@ -490,10 +500,18 @@ ivas_error ivas_masa_encode( /* Encode metadata */ masa_total_brate = ivas_total_brate; +#ifndef IVAS_FLOAT_FIXED if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_DISC ) { masa_total_brate = calculate_cpe_brate_MASA_ISM( ism_mode, ivas_total_brate, nchan_ism ); } +#else + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_DISC ) ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( ism_mode, ivas_total_brate, nchan_ism ); + } +#endif if ( masa_total_brate >= IVAS_384k ) { @@ -520,11 +538,49 @@ ivas_error ivas_masa_encode( } } +#ifndef IVAS_FLOAT_FIXED if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ ivas_omasa_modify_masa_energy_ratios( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio ); } +#else + Word16 b, d; + + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + for ( d = 0; d < hQMetaData->no_directions; d++ ) + { + floatToFixed_arr32( hQMetaData->q_direction[d].band_data[b].energy_ratio, hQMetaData->q_direction[d].band_data[b].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + + for ( b = 0; b < MAX_PARAM_SPATIAL_SUBFRAMES; ++b ) + { + floatToFixed_arr32( hMasa->data.hOmasaData->masa_to_total_energy_ratio[b], hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx[b], Q30, MASA_MAXIMUM_CODING_SUBBANDS ); + } + } + + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + /* Modify spatial metadata based on the MASA-to-total energy ratios */ + ivas_omasa_modify_masa_energy_ratios_fx( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio_fx ); + } + + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + for ( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) + { + for ( d = 0; d < hQMetaData->no_directions; d++ ) + { + fixedToFloat_arrL( hQMetaData->q_direction[d].band_data[b].energy_ratio_fx, hQMetaData->q_direction[d].band_data[b].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + } +#endif *nb_bits_metadata = hMetaData->nb_bits_tot; @@ -702,7 +758,11 @@ ivas_error ivas_masa_enc_config( } } +#ifndef IVAS_FLOAT_FIXED ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); +#else + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->hEncoderConfig->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, ivas_format, st_ivas->ism_mode, ism_total_brate ); +#endif hQMetaData->is_masa_ivas_format = 1; @@ -731,6 +791,7 @@ ivas_error ivas_masa_enc_config( hMasa->config.numberOfDirections = 1; } +#ifndef IVAS_FLOAT_FIXED if ( ivas_format == MASA_ISM_FORMAT ) { ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); @@ -739,6 +800,16 @@ ivas_error ivas_masa_enc_config( { ivas_masa_set_coding_config( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); } +#else + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) + { + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); + } + ELSE + { + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, ivas_total_brate, st_ivas->nchan_transport, ( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); + } +#endif /* Setup importance weights for two-direction band selection. */ if ( hMasa->config.numberOfDirections == 2 ) @@ -825,10 +896,18 @@ ivas_error ivas_masa_enc_config( st_ivas->hQMetaData->q_direction->cfg.inactiveBands = 0; masa_total_brate = ivas_total_brate; +#ifndef IVAS_FLOAT_FIXED if ( ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { masa_total_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); } +#else + test(); + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism ); + } +#endif if ( masa_total_brate >= IVAS_384k && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) { int16_t continueLoop; @@ -859,7 +938,39 @@ ivas_error ivas_masa_enc_config( } } +#ifndef IVAS_FLOAT_FIXED masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); +#else + Word16 numBands48k = hMasa->config.numCodingBands, band; + + for ( band = 0; band < numBands48k; band++ ) + { + floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].azimuth, hQMetaData->q_direction[0].band_data[band].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].elevation, hQMetaData->q_direction[0].band_data[band].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[0].band_data[band].energy_ratio, hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( hQMetaData->no_directions == 2 ) + { + floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].azimuth, hQMetaData->q_direction[1].band_data[band].azimuth_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].elevation, hQMetaData->q_direction[1].band_data[band].elevation_fx, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + floatToFixed_arrL( hQMetaData->q_direction[1].band_data[band].energy_ratio, hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } + + masa_sample_rate_band_correction_fx( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, masa_total_brate >= IVAS_384k, NULL ); + + for ( band = 0; band < numBands48k; band++ ) + { + fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].azimuth_fx, hQMetaData->q_direction[0].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].elevation_fx, hQMetaData->q_direction[0].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[0].band_data[band].energy_ratio_fx, hQMetaData->q_direction[0].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + if ( hQMetaData->no_directions == 2 ) + { + fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].azimuth_fx, hQMetaData->q_direction[1].band_data[band].azimuth, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].elevation_fx, hQMetaData->q_direction[1].band_data[band].elevation, Q22, MAX_PARAM_SPATIAL_SUBFRAMES ); + fixedToFloat_arrL( hQMetaData->q_direction[1].band_data[band].energy_ratio_fx, hQMetaData->q_direction[1].band_data[band].energy_ratio, Q30, MAX_PARAM_SPATIAL_SUBFRAMES ); + } + } +#endif if ( hMasa->config.numTwoDirBands >= hMasa->config.numCodingBands ) { @@ -1997,7 +2108,11 @@ void ivas_masa_enc_reconfigure( } } +#ifndef IVAS_FLOAT_FIXED ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); +#else + ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->hEncoderConfig->ivas_format, st_ivas->ism_mode, ism_total_brate ); +#endif } return; @@ -2063,8 +2178,19 @@ static void average_masa_metadata( hMeta->directional_meta[i].elevation[j][k] = atan2f( z_sum, sqrtf( x_sum * x_sum + y_sum * y_sum ) ) / EVS_PI * 180.0f; if ( useSphGrid == TRUE ) { +#ifndef IVAS_FLOAT_FIXED hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16( &( hMeta->directional_meta[i].elevation[j][k] ), &( hMeta->directional_meta[i].azimuth[j][k] ), Sph_Grid16 ); +#else + hMeta->directional_meta[i].elevation_fx[j][k] = floatToFixed( hMeta->directional_meta[i].elevation[j][k], Q22 ); + hMeta->directional_meta[i].azimuth_fx[j][k] = floatToFixed( hMeta->directional_meta[i].azimuth[j][k], Q22 ); + + hMeta->directional_meta[i].spherical_index[j][k] = index_theta_phi_16_fx( &( hMeta->directional_meta[i].elevation_fx[j][k] ), + &( hMeta->directional_meta[i].azimuth_fx[j][k] ), Sph_Grid16 ); + + hMeta->directional_meta[i].elevation[j][k] = fixedToFloat( hMeta->directional_meta[i].elevation_fx[j][k], Q22 ); + hMeta->directional_meta[i].azimuth[j][k] = fixedToFloat( hMeta->directional_meta[i].azimuth_fx[j][k], Q22 ); +#endif } vec_len = sqrtf( x_sum * x_sum + y_sum * y_sum + z_sum * z_sum ); hMeta->directional_meta[i].energy_ratio[j][k] = vec_len / ( energy_sum + EPSILON ); @@ -2737,7 +2863,11 @@ static void quantize_ratio_ism_vector( { if ( masa_to_total_energy_ratio >= MASA2TOTAL_THR ) { +#ifndef IVAS_FLOAT_FIXED distribute_evenly_ism( idx, max_sum_idx, nchan_ism ); +#else + distribute_evenly_ism_fx( idx, max_sum_idx, nchan_ism ); +#endif } else { @@ -2856,7 +2986,11 @@ static int16_t index_slice_enum( i = 0; while ( i <= x ) { +#ifndef IVAS_FLOAT_FIXED if ( valid_ratio_index( i, 7, nchan_ism - 1 ) ) +#else + IF( valid_ratio_index_fx( i, 7, nchan_ism - 1 ) ) +#endif { index++; } @@ -3533,7 +3667,16 @@ static void ivas_encode_masaism_metadata( } /* reconstructed values */ +#ifndef IVAS_FLOAT_FIXED reconstruct_ism_ratios( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band] ); +#else + Word16 step_fx = float_to_fix16( step, Q15 ); + floatToFixed_arr32( hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], Q30, MAX_NUM_OBJECTS ); + + reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, step_fx, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); + + fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, MAX_NUM_OBJECTS ); +#endif } if ( ( nchan_ism > 2 ) && ( idx_separated_object == nchan_ism - 1 ) ) diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 39df60bfd..296dbce5c 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -40,6 +40,9 @@ #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*------------------------------------------------------------------------- @@ -205,8 +208,13 @@ ivas_error ivas_osba_enc_reconfig( nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; +#ifndef IVAS_FLOAT_FIXED st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); +#else + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); + analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); +#endif nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; ndir_old = st_ivas->hQMetaData->no_directions; diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 6be86728f..cbd9c869d 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -41,6 +41,9 @@ #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*-------------------------------------------------------------------* @@ -111,8 +114,13 @@ ivas_error ivas_sba_enc_reconfigure( nchan_transport_old = st_ivas->nchan_transport; nCPE_old = st_ivas->nCPE; nSCE_old = st_ivas->nSCE; +#ifndef IVAS_FLOAT_FIXED st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, hEncoderConfig->sba_order ); analysis_order_old = ivas_sba_get_analysis_order( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); +#else + st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, hEncoderConfig->sba_order ); + analysis_order_old = ivas_sba_get_analysis_order_fx( hEncoderConfig->last_ivas_total_brate, hEncoderConfig->sba_order ); +#endif nbands_old = st_ivas->hQMetaData->q_direction->cfg.nbands; ndir_old = st_ivas->hQMetaData->no_directions; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index b304ea80f..0352d0fc9 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -297,7 +297,7 @@ ivas_error ivas_spar_enc_open_fx( hSpar->spar_reconfig_flag = 0; input_Fs = hEncoderConfig->input_Fs; sba_order_internal = extract_l( L_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ) ); - nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal, hEncoderConfig->ivas_total_brate ); + nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order_internal, hEncoderConfig->ivas_total_brate ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); ivas_total_brate = hEncoderConfig->ivas_total_brate; @@ -819,7 +819,11 @@ static ivas_error ivas_spar_enc_process( input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); +#ifndef IVAS_FLOAT_FIXED nchan_inp = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); +#else + nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); +#endif assert( nchan_inp <= hEncoderConfig->nchan_inp ); nchan_fb_in = hSpar->hFbMixer->fb_cfg->nchan_fb_in; diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 11c013dd1..b7a74310e 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -186,7 +186,7 @@ ivas_error ivas_spar_md_enc_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } - num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); IF( ( hMdEnc->mixer_mat_local_fx = (Word32 ***) malloc( num_channels * sizeof( Word32 ** ) ) ) == NULL ) { @@ -313,9 +313,15 @@ ivas_error ivas_spar_md_enc_init( float PR_minmax[2]; int16_t num_channels, i, j, k; +#ifndef IVAS_FLOAT_FIXED ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); ivas_sba_get_spar_hoa_ch_ind( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); +#else + ivas_sba_get_spar_hoa_md_flag_fx( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); + ivas_sba_get_spar_hoa_ch_ind_fx( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); +#endif table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); hMdEnc->spar_md.prior_dyn_active_w_flag = 0; @@ -379,9 +385,9 @@ ivas_error ivas_spar_md_enc_init_fx( Word16 table_idx; Word16 num_channels, i, j, k; - ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); - num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); - ivas_sba_get_spar_hoa_ch_ind( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); + ivas_sba_get_spar_hoa_md_flag_fx( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); + num_channels = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); + ivas_sba_get_spar_hoa_ch_ind_fx( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); table_idx = ivas_get_spar_table_idx_fx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); hMdEnc->spar_md.prior_dyn_active_w_flag = 0; @@ -669,7 +675,11 @@ ivas_error ivas_spar_md_enc_process( } num_quant_strats = hMdEnc->spar_md_cfg.num_quant_strats; +#ifndef IVAS_FLOAT_FIXED num_ch = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); +#else + num_ch = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); +#endif active_w = ( hMdEnc->spar_md_cfg.active_w == 1 ) || ( dyn_active_w_flag == 1 ); nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 3342895be..e804e272f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1010,6 +1010,10 @@ typedef struct ivas_omasa_encoder_one_data_struct float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; +#ifdef IVAS_FLOAT_FIXED + Word32 q_energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /* Q30 */ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ +#endif float lp_noise_CPE; /* LP filtered total noise estimation */ int16_t omasa_stereo_sw_cnt; diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 5f4329e03..33c01705d 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -520,7 +520,11 @@ ivas_error IVAS_ENC_ConfigureForAmbisonics( hEncoderConfig->sba_order = order; /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ +#ifndef IVAS_FLOAT_FIXED hEncoderConfig->nchan_inp = ivas_sba_get_nchan( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ +#else + hEncoderConfig->nchan_inp = ivas_sba_get_nchan_fx( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/ +#endif hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON; @@ -612,7 +616,11 @@ ivas_error IVAS_ENC_ConfigureForSBAObjects( /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */ /*Input file will always contain all channels for a given order irrespective of planar flag*/ +#ifndef IVAS_FLOAT_FIXED st_ivas->hEncoderConfig->nchan_inp = ivas_sba_get_nchan( st_ivas->hEncoderConfig->sba_order, 0 ) + numObjects; +#else + st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), (Word16) numObjects ); +#endif st_ivas->hEncoderConfig->Opt_PCA_ON = (int16_t) Opt_PCA_ON; @@ -918,7 +926,11 @@ static ivas_error configureEncoder( { st_ivas->ism_mode = ivas_omasa_ism_mode_select( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); +#ifndef IVAS_FLOAT_FIXED cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); +#else + cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); +#endif /*adapt element_mode according to the bit-rate*/ if ( hEncoderConfig->element_mode_init != IVAS_SCE ) diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index 62422fb03..98328dc56 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -39,6 +39,9 @@ #include "ivas_prot_rend.h" #include "ivas_rom_rend.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*-----------------------------------------------------------------------* @@ -218,7 +221,7 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( return error; } - num_harm = ivas_sba_get_nchan( ambisonics_order, 0 ); + num_harm = ivas_sba_get_nchan_fx( ambisonics_order, 0 ); /* Get t-design values */ num_td = SBA_T_DESIGN_11_SIZE; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 132225604..156108264 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -121,9 +121,11 @@ typedef struct parambin_rend_config_data * Local function prototypes *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void ivas_dirac_dec_binaural_internal_fx( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, Word32 *output_f[], const Word16 nchan_transport, const Word16 subframe ); +#else static void ivas_dirac_dec_binaural_internal( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, float *output_f[], const int16_t nchan_transport, const int16_t subframe ); -#ifndef IVAS_FLOAT_FIXED static void ivas_dirac_dec_decorrelate_slot( DIRAC_DEC_BIN_HANDLE hDiracDecBin, const int16_t num_freq_bands, const int16_t slot, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float decRe[][CLDFB_NO_CHANNELS_MAX], float decIm[][CLDFB_NO_CHANNELS_MAX] ); #endif @@ -749,12 +751,12 @@ ivas_error ivas_dirac_dec_binaural_copy_hrtfs( } #endif +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * void ivas_dirac_dec_binaural_render() * * *------------------------------------------------------------------------*/ - void ivas_dirac_dec_binaural_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -823,7 +825,81 @@ void ivas_dirac_dec_binaural_render( return; } +#else +/*------------------------------------------------------------------------- + * void ivas_dirac_dec_binaural_render_fx() + * + * + *------------------------------------------------------------------------*/ +void ivas_dirac_dec_binaural_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_f[] /* o : rendered time signal */ +) +{ + Word16 slots_to_render, first_sf, last_sf, subframe_idx; + UWord16 slot_size, ch; + UWord16 nchan_out; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + Word32 *output_fx_local[MAX_OUTPUT_CHANNELS]; + Word32 output_fx_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word16 output_length; + + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nchan_out = BINAURAL_CHANNELS; + FOR ( ch = 0; ch < nchan_out; ch++ ) + { + output_fx_local[ch] = output_fx_local_buff[ch]; + } + slot_size = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( (Word16) nSamplesAsked, (Word16) slot_size ) ); + *nSamplesRendered = imult1616( slots_to_render, slot_size ); + first_sf = hSpatParamRendCom->subframes_rendered; + last_sf = first_sf; + + WHILE( GT_16( slots_to_render, 0 ) ) + { + slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); + last_sf++; + } + output_length = 0; + FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + Word16 n_samples_sf = imult1616( slot_size, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + ivas_dirac_dec_binaural_internal_fx( st_ivas, st_ivas->hCombinedOrientationData, output_fx_local, nchan_transport, subframe_idx ); + + FOR ( ch = 0; ch < nchan_out; ch++ ) + { + output_fx_local[ch] += n_samples_sf; + } + + output_length = add( output_length, n_samples_sf ); + + /* update combined orientation access index */ + ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); + } + + FOR ( ch = 0; ch < nchan_out; ch++ ) + { + Copy32( output_fx_local_buff[ch], output_f[ch], output_length ); + } + + IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ) + { + hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; + } + + *nSamplesAvailable = imult1616( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), slot_size ); + + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_binaural_sba_gain() @@ -1134,10 +1210,10 @@ static void ivas_dirac_dec_binaural_internal( return; } #else -static void ivas_dirac_dec_binaural_internal( +static void ivas_dirac_dec_binaural_internal_fx( Decoder_Struct *st_ivas, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, - float *output_f[], + Word32 *output_fx[], const int16_t nchan_transport, const int16_t subframe ) { @@ -1194,7 +1270,7 @@ static void ivas_dirac_dec_binaural_internal( DIFFUSE_DISTRIBUTION_DATA diffuseDistData; Word16 nBins, offsetSamples; Word16 i, j; - Word16 q_mat; + Word16 q_mat, q_out; hDiracDecBin = st_ivas->hDiracDecBin; assert( hDiracDecBin ); hSpatParamRendCom = st_ivas->hSpatParamRendCom; @@ -1486,25 +1562,18 @@ static void ivas_dirac_dec_binaural_internal( } ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); #if 1 - Word32 *output_fx[MAX_OUTPUT_CHANNELS]; - Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - Word16 q_out; - q_inp = Q6; FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - output_fx[ch] = output_fx_buff[ch]; - } - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } #endif q_mat = hDiracDecBin->q_processMtx; + move16(); q_mat = s_min( q_mat, hDiracDecBin->q_processMtxPrev ); q_mat = s_min( q_mat, hDiracDecBin->q_processMtxDec ); q_mat = s_min( q_mat, hDiracDecBin->q_processMtxDecPrev ); @@ -1531,9 +1600,13 @@ static void ivas_dirac_dec_binaural_internal( } } hDiracDecBin->q_processMtx = q_mat; + move16(); hDiracDecBin->q_processMtxPrev = q_mat; + move16(); hDiracDecBin->q_processMtxDec = q_mat; + move16(); hDiracDecBin->q_processMtxDecPrev = q_mat; + move16(); ivas_dirac_dec_binaural_process_output_fx( hDiracDecBin, hSpatParamRendCom, st_ivas->cldfbSynDec, output_fx, &q_out, Cldfb_RealBuffer_in_fx, Cldfb_ImagBuffer_in_fx, q_inp, max_band_decorr, numInChannels, config_data.processReverb, subframe, q_mat ); @@ -1542,14 +1615,13 @@ static void ivas_dirac_dec_binaural_internal( hSpatParamRendCom->slots_rendered = add( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->subframe_nbslots[subframe] ); hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); -#if 1 FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - fixedToFloat_arrL32( output_fx[ch], output_f[ch], q_out, imult1616( nBins, hSpatParamRendCom->subframe_nbslots[subframe] ) ); + scale_sig32( output_fx[ch], imult1616( nBins, hSpatParamRendCom->subframe_nbslots[subframe] ), 11 - q_out ); // Scaling to Q11 scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + move16(); } -#endif return; } @@ -7330,8 +7402,8 @@ static void ivas_masa_ext_rend_parambin_internal( max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, - 0, NULL ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, + 0, NULL ); #if 1 Word16 q_out; diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index c1830eaed..d9cf168dc 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -489,15 +489,6 @@ ivas_error ivas_dirac_dec_decorr_open_fx( Copy( &split_frequencies_bands[0], freq_domain_decorr_ap_params->split_frequency_bands, add( freq_domain_decorr_ap_params->num_split_frequency_bands, 1 ) ); /* calc buffer size and allocate arrays */ -#if 1 - /*float code to be cleaned up*/ - freq_domain_decorr_ap_state->decorr_buffer = NULL; - freq_domain_decorr_ap_state->direct_energy_smooth = NULL; - freq_domain_decorr_ap_state->reverb_energy_smooth = NULL; - freq_domain_decorr_ap_params->pre_delay = NULL; - freq_domain_decorr_ap_params->filter_length = NULL; -#endif -#ifdef IVAS_FLOAT_FIXED freq_domain_decorr_ap_state->decorr_buffer_fx = NULL; freq_domain_decorr_ap_params->filter_coeff_num_real_fx = NULL; freq_domain_decorr_ap_params->filter_coeff_den_real_fx = NULL; @@ -507,39 +498,12 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_params->phase_coeff_imag_fx = NULL; freq_domain_decorr_ap_state->direct_energy_smooth_fx = NULL; freq_domain_decorr_ap_state->reverb_energy_smooth_fx = NULL; -#endif + freq_domain_decorr_ap_params->pre_delay = NULL; + freq_domain_decorr_ap_params->filter_length = NULL; - IF( num_outputs_diff > 0 ) + IF ( num_outputs_diff > 0 ) { buffer_size_decorr = ( ap_pre_delay[split_band_index_start] + ap_filter_length[split_band_index_start] ); -#if 1 - if ( ( freq_domain_decorr_ap_state->decorr_buffer = (float *) malloc( sizeof( float ) * 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); - } - set_f( freq_domain_decorr_ap_state->decorr_buffer, 0.0f, 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ); - - if ( ( freq_domain_decorr_ap_state->direct_energy_smooth = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); - } - - if ( ( freq_domain_decorr_ap_state->reverb_energy_smooth = (float *) malloc( sizeof( float ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); - } - - if ( ( freq_domain_decorr_ap_params->pre_delay = (Word16 *) malloc( sizeof( Word16 ) * freq_domain_decorr_ap_params->num_split_frequency_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); - } - if ( ( freq_domain_decorr_ap_params->filter_length = (Word16 *) malloc( sizeof( Word16 ) * freq_domain_decorr_ap_params->num_split_frequency_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); - } - set_f( freq_domain_decorr_ap_state->direct_energy_smooth, 0.0f, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); - set_f( freq_domain_decorr_ap_state->reverb_energy_smooth, 0.0f, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); -#endif IF( ( freq_domain_decorr_ap_state->decorr_buffer_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); @@ -577,12 +541,22 @@ ivas_error ivas_dirac_dec_decorr_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } + + IF((freq_domain_decorr_ap_params->pre_delay = (Word16 *)malloc(sizeof(Word16) * freq_domain_decorr_ap_params->num_split_frequency_bands)) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n")); + } + IF((freq_domain_decorr_ap_params->filter_length = (Word16 *)malloc(sizeof(Word16) * freq_domain_decorr_ap_params->num_split_frequency_bands)) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n")); + } + set32_fx( freq_domain_decorr_ap_state->direct_energy_smooth_fx, 0, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); set32_fx( freq_domain_decorr_ap_state->reverb_energy_smooth_fx, 0, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); freq_domain_decorr_ap_state->q_direct_energy_smooth = freq_domain_decorr_ap_state->q_reverb_energy_smooth = Q31; /* compute filter coefficients */ - FOR( k = 0; k < freq_domain_decorr_ap_params->num_split_frequency_bands; k++ ) + FOR ( k = 0; k < freq_domain_decorr_ap_params->num_split_frequency_bands; k++ ) { k_in = freq_domain_decorr_ap_params->split_frequency_bands[k]; k_out = freq_domain_decorr_ap_params->split_frequency_bands[k + 1]; @@ -591,11 +565,11 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_params->filter_length[k] = add( ap_filter_length[band_table_idx], 1 ); freq_domain_decorr_ap_params->pre_delay[k] = ap_pre_delay[band_table_idx]; - FOR( l = 0; l < num_outputs_diff; l++ ) + FOR ( l = 0; l < num_outputs_diff; l++ ) { - FOR( m = 0; m < num_bands; m++ ) + FOR ( m = 0; m < num_bands; m++ ) { - n = add( k_in, m ); + n = add(k_in , m); Word32 cur_lattice_delta_phi_32_fx = L_mult( ap_lattice_delta_phi_fx[l * DIRAC_MAX_DECORR_FILTER_LEN + ap_filter_length[k] - 1], (Word16) floatToFixed( n, 10 ) ); cur_lattice_delta_phi_fx = extract_h( cur_lattice_delta_phi_32_fx ); // Q10 @@ -1011,19 +985,19 @@ void ivas_dirac_dec_decorr_process_fx( } q_aux_buffer += q_shift; #else - (void) maximum_abs_32_fx( &input_frame_fx[0], 2 * num_protos_dir * num_freq_bands, &max_abs_val ); + (void)maximum_abs_32_fx(&input_frame_fx[0], 2 * num_protos_dir * num_freq_bands, &max_abs_val); q_shift = getScaleFactor32( &input_frame_fx[0], 2 * num_protos_dir * num_freq_bands ) - guarded_bits; - IF( LT_16( q_shift, sub( 0, guarded_bits ) ) && NE_32( max_abs_val, 0 ) ) + IF (LT_16(q_shift , sub(0, guarded_bits)) && NE_32(max_abs_val, 0)) { - q_shift = sub( 0, guarded_bits ); + q_shift = sub(0, guarded_bits); } - ELSE IF( EQ_32( max_abs_val, 0 ) ) + ELSE IF (EQ_32(max_abs_val, 0)) { q_shift = 0; } - FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) + FOR ( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++) { - v_shr( &input_frame_fx[2 * ch_idx * num_freq_bands], negate( q_shift ), &aux_buffer_fx[2 * ch_idx * num_freq_bands], 2 * num_freq_bands ); + v_shr(&input_frame_fx[2 * ch_idx * num_freq_bands], negate(q_shift), &aux_buffer_fx[2 * ch_idx * num_freq_bands], 2 * num_freq_bands); } FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { @@ -1299,17 +1273,17 @@ void ivas_dirac_dec_decorr_process_fx( h_freq_domain_decorr_ap_state->q_direct_energy_smooth = sub( 31, e_direct_energy_smooth ); // scaling energy buffers for better precision for higher values// - q_shift = L_norm_arr( h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616( num_protos_dir, max_band_decorr ) ); - Scale_sig32( h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616( num_protos_dir, max_band_decorr ), q_shift ); + q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr)); + Scale_sig32(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr), q_shift); h_freq_domain_decorr_ap_state->q_direct_energy_smooth = h_freq_domain_decorr_ap_state->q_direct_energy_smooth + q_shift; - q_shift = L_norm_arr( h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616( num_channels, max_band_decorr ) ); - Scale_sig32( h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616( num_channels, max_band_decorr ), q_shift ); + q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr)); + Scale_sig32(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr), q_shift); h_freq_domain_decorr_ap_state->q_reverb_energy_smooth = h_freq_domain_decorr_ap_state->q_reverb_energy_smooth + q_shift; - e_reverb_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_reverb_energy_smooth ); - e_direct_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_direct_energy_smooth ); + e_reverb_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_reverb_energy_smooth); + e_direct_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_direct_energy_smooth); // this step is b/c we are left shifting frame_dec_fx at the end of below for loop/ #ifdef MSAN_FIX @@ -1444,150 +1418,129 @@ void ivas_dirac_dec_decorr_process_fx( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_decorr_close_fx( - HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, - HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state ) + HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, + HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state) { - DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; + DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; - /*-----------------------------------------------------------------* - * check input handles - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * check input handles + *-----------------------------------------------------------------*/ - if ( ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL ) - { - return; - } + if (ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL) + { + return; + } - if ( *ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL ) - { - return; - } + if (*ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL) + { + return; + } - /*-----------------------------------------------------------------* - * free onset filter arrays - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * free onset filter arrays + *-----------------------------------------------------------------*/ - dirac_onset_detection_state = &( *ph_freq_domain_decorr_ap_state )->h_onset_detection_power_state; + dirac_onset_detection_state = &(*ph_freq_domain_decorr_ap_state)->h_onset_detection_power_state; #ifdef IVAS_FLOAT_FIXED - IF( dirac_onset_detection_state->onset_detector_1_fx != NULL ) - { - free( dirac_onset_detection_state->onset_detector_1_fx ); - dirac_onset_detection_state->onset_detector_1_fx = NULL; - } - - IF( dirac_onset_detection_state->onset_detector_2_fx != NULL ) - { - free( dirac_onset_detection_state->onset_detector_2_fx ); - dirac_onset_detection_state->onset_detector_2_fx = NULL; - } + IF(dirac_onset_detection_state->onset_detector_1_fx != NULL) + { + free(dirac_onset_detection_state->onset_detector_1_fx); + dirac_onset_detection_state->onset_detector_1_fx = NULL; + } + + IF(dirac_onset_detection_state->onset_detector_2_fx != NULL) + { + free(dirac_onset_detection_state->onset_detector_2_fx); + dirac_onset_detection_state->onset_detector_2_fx = NULL; + } #endif - /*-----------------------------------------------------------------* - * memory deallocation - *-----------------------------------------------------------------*/ - - /* free decorrelation buffer */ - if ( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer ); - ( *ph_freq_domain_decorr_ap_state )->decorr_buffer = NULL; - } - - /* free ducker smoothed direct energy buffer */ - if ( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth ); - ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth = NULL; - } - - /* free ducker smoothed reverb energy buffer */ - if ( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth ); - ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth = NULL; - } + /*-----------------------------------------------------------------* + * memory deallocation + *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - IF( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx ); - ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx = NULL; - } - - /* free ducker smoothed direct energy buffer */ - IF( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx ); - ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx = NULL; - } - - /* free ducker smoothed reverb energy buffer */ - IF( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx ); - ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx = NULL; - } + IF((*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx != NULL) + { + free((*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx); + (*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx = NULL; + } + + /* free ducker smoothed direct energy buffer */ + IF((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx != NULL) + { + free((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx); + (*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx = NULL; + } + + /* free ducker smoothed reverb energy buffer */ + IF((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx != NULL) + { + free((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx); + (*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx = NULL; + } #endif - /* free pre-delay param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->pre_delay != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_params )->pre_delay ); - ( *ph_freq_domain_decorr_ap_params )->pre_delay = NULL; - } - - /* free filter length param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->filter_length != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_params )->filter_length ); - ( *ph_freq_domain_decorr_ap_params )->filter_length = NULL; - } - - /* free pre-delay param buffer */ - if ( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands ); - ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands = NULL; - } + /* free pre-delay param buffer */ + if ((*ph_freq_domain_decorr_ap_params)->pre_delay != NULL) + { + free((*ph_freq_domain_decorr_ap_params)->pre_delay); + (*ph_freq_domain_decorr_ap_params)->pre_delay = NULL; + } + + /* free filter length param buffer */ + if ((*ph_freq_domain_decorr_ap_params)->filter_length != NULL) + { + free((*ph_freq_domain_decorr_ap_params)->filter_length); + (*ph_freq_domain_decorr_ap_params)->filter_length = NULL; + } + + /* free pre-delay param buffer */ + if ((*ph_freq_domain_decorr_ap_params)->split_frequency_bands != NULL) + { + free((*ph_freq_domain_decorr_ap_params)->split_frequency_bands); + (*ph_freq_domain_decorr_ap_params)->split_frequency_bands = NULL; + } #ifdef IVAS_FLOAT_FIXED /* free filter coeff param buffers */ - IF( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx ); - ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx = NULL; - } - - /* free pre-delay param buffer */ - IF( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx ); - ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx = NULL; - } - - /* free pre-delay param buffer */ - IF( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx ); - ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx = NULL; - } + IF((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx != NULL) + { + free((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx); + (*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx = NULL; + } /* free pre-delay param buffer */ - IF( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx != NULL ) - { - free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx ); - ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx = NULL; - } + IF((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx != NULL) + { + free((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx); + (*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx = NULL; + } + + /* free pre-delay param buffer */ + IF((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx != NULL) + { + free((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx); + (*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx = NULL; + } + + /* free pre-delay param buffer */ + IF((*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx != NULL) + { + free((*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx); + (*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx = NULL; + } #endif - /* free pointers to state and parameter structs */ - free( *ph_freq_domain_decorr_ap_params ); - *ph_freq_domain_decorr_ap_params = NULL; + /* free pointers to state and parameter structs */ + free(*ph_freq_domain_decorr_ap_params); + *ph_freq_domain_decorr_ap_params = NULL; - free( *ph_freq_domain_decorr_ap_state ); - *ph_freq_domain_decorr_ap_state = NULL; + free(*ph_freq_domain_decorr_ap_state); + *ph_freq_domain_decorr_ap_state = NULL; - return; + return; } #else void ivas_dirac_dec_decorr_close( @@ -1743,7 +1696,7 @@ static void get_lattice_coeffs_fx( { Word16 k; - FOR( k = 0; k < ap_filter_length[band_index]; k++ ) + FOR ( k = 0; k < ap_filter_length[band_index]; k++ ) { Word16 cur_lattice_coeff = ap_lattice_coeffs_fx[band_index][channel_index * ap_filter_length[band_index] + k]; lattice_coeffs[k] = cur_lattice_coeff; diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 73154c600..2390b1d5f 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -219,11 +219,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } - /*TODO : remove float code*/ - /*if ( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - }*/ IF( ( dirac_output_synthesis_state->cy_cross_dir_smooth_prev_fx = (Word32 *) malloc( size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -231,12 +226,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( dirac_output_synthesis_state->cy_cross_dir_smooth_prev_len = size; IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - /*TODO : remove float code*/ - // dirac_output_synthesis_state->cy_auto_dir_smooth_prev = NULL; - if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx = NULL; IF( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev_fx = (Word32 *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { @@ -246,20 +235,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } ELSE { - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) - { - if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } - } - else - { - if ( ( dirac_output_synthesis_state->cy_auto_diff_smooth_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } - } IF( ( dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -285,11 +260,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } /* direct and diffuse gain buffers */ - /*TODO : remove float code*/ - if ( ( dirac_output_synthesis_state->gains_dir_prev = (float *) malloc( size * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } IF( ( dirac_output_synthesis_state->gains_dir_prev_fx = (Word32 *) malloc( size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -297,11 +267,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( dirac_output_synthesis_state->gains_dir_prev_len = size; IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { - /*TODO : remove float code*/ - if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -310,11 +275,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } ELSE IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) { - /*TODO : remove float code*/ - if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -323,11 +283,6 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( } ELSE { - /*TODO : remove float code*/ - if ( ( dirac_output_synthesis_state->gains_diff_prev = (float *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); - } IF( ( dirac_output_synthesis_state->gains_diff_prev_fx = (Word32 *) malloc( hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); @@ -816,46 +771,6 @@ void ivas_dirac_dec_output_synthesis_init_fx( *-----------------------------------------------------------------*/ /* initialize buffers */ - /*if ( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev != NULL ) - { - set_zero( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - }*/ - - if ( hodirac_flag ) - { - size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir * DIRAC_HO_NUMSECTORS; - } - else - { - size = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; - } - // set_zero( h_dirac_output_synthesis_state->cy_cross_dir_smooth_prev, size ); - - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); - } - else if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD ) - { - set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff ); - } - else - { - set_zero( h_dirac_output_synthesis_state->cy_auto_diff_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - } - - set_zero( h_dirac_output_synthesis_state->gains_dir_prev, size ); - - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - set_zero( h_dirac_output_synthesis_state->gains_diff_prev, h_dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff ); - } - else - { - set_zero( h_dirac_output_synthesis_state->gains_diff_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - } - -#ifdef IVAS_FLOAT_FIXED IF( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx != NULL ) { set32_fx( h_dirac_output_synthesis_state->cy_auto_dir_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); @@ -910,7 +825,6 @@ void ivas_dirac_dec_output_synthesis_init_fx( set32_fx( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE ); } h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_q = Q31; -#endif return; } @@ -1029,36 +943,6 @@ void ivas_dirac_dec_output_synthesis_close_fx( * memory deallocation *-----------------------------------------------------------------*/ - /* free target power buffers */ - /*if ( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev != NULL ) - { - free( ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev ); - ( dirac_output_synthesis_state )->cy_auto_dir_smooth_prev = NULL; - }*/ - /*if ( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev != NULL ) - { - free( ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev ); - ( dirac_output_synthesis_state )->cy_cross_dir_smooth_prev = NULL; - }*/ - if ( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev != NULL ) - { - free( ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev ); - ( dirac_output_synthesis_state )->cy_auto_diff_smooth_prev = NULL; - } - - /* free gain buffers */ - if ( ( dirac_output_synthesis_state )->gains_dir_prev != NULL ) - { - free( ( dirac_output_synthesis_state )->gains_dir_prev ); - ( dirac_output_synthesis_state )->gains_dir_prev = NULL; - } - if ( ( dirac_output_synthesis_state )->gains_diff_prev != NULL ) - { - free( ( dirac_output_synthesis_state )->gains_diff_prev ); - ( dirac_output_synthesis_state )->gains_diff_prev = NULL; - } - -#ifdef IVAS_FLOAT_FIXED /* free interpolator */ IF( ( dirac_output_synthesis_params )->interpolator_fx != NULL ) { @@ -1137,7 +1021,6 @@ void ivas_dirac_dec_output_synthesis_close_fx( free( ( dirac_output_synthesis_state )->gains_diff_prev_fx ); ( dirac_output_synthesis_state )->gains_diff_prev_fx = NULL; } -#endif return; } #endif diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 744035fa6..320138fc8 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -745,13 +745,6 @@ void ivas_dirac_rend_close_fx( /* States */ /* free prototype signal buffers */ -#if 1 /* TODO: remove float code */ - IF( hDirACRend->proto_frame_f != NULL ) - { - free( hDirACRend->proto_frame_f ); - hDirACRend->proto_frame_f = NULL; - } -#endif IF( hDirACRend->proto_frame_f_fx != NULL ) { free( hDirACRend->proto_frame_f_fx ); @@ -1410,12 +1403,13 @@ ivas_error ivas_dirac_alloc_mem( if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { +#ifndef IVAS_FLOAT_FIXED if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero( hDirAC_mem->cy_auto_diff_smooth, size ); -#ifdef IVAS_FLOAT_FIXED +#else if ( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1426,12 +1420,13 @@ ivas_error ivas_dirac_alloc_mem( } else { +#ifndef IVAS_FLOAT_FIXED if ( ( hDirAC_mem->cy_auto_diff_smooth = (float *) malloc( sizeof( float ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero( hDirAC_mem->cy_auto_diff_smooth, num_outputs_diff * num_freq_bands_diff ); -#ifdef IVAS_FLOAT_FIXED +#else if ( ( hDirAC_mem->cy_auto_diff_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * num_outputs_diff * num_freq_bands_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1440,7 +1435,6 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = num_outputs_diff * num_freq_bands_diff; #endif } - hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; #ifdef IVAS_FLOAT_FIXED hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx = hDirAC_mem->cy_cross_dir_smooth_fx; hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx = hDirAC_mem->cy_auto_diff_smooth_fx; @@ -1450,6 +1444,7 @@ ivas_error ivas_dirac_alloc_mem( move16(); #else hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; + hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth = hDirAC_mem->cy_auto_diff_smooth; #endif /*Responses (gains/factors)*/ @@ -1735,10 +1730,6 @@ void ivas_dirac_free_mem_fx( { free( hDirAC_mem->cy_cross_dir_smooth_fx ); } - IF( hDirAC_mem->cy_auto_diff_smooth != NULL ) - { - free( hDirAC_mem->cy_auto_diff_smooth ); - } IF( hDirAC_mem->cy_auto_diff_smooth_fx != NULL ) { free( hDirAC_mem->cy_auto_diff_smooth_fx ); @@ -1880,7 +1871,7 @@ void compute_hoa_encoder_mtx_fx( { Word16 k, num_sh; - num_sh = (Word16) ivas_sba_get_nchan_fx( ambisonics_order, 0 ); + num_sh = ivas_sba_get_nchan_fx( ambisonics_order, 0 ); FOR( k = 0; k < num_responses; k++ ) { ivas_dirac_dec_get_response_fixed( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order ); // Q29 diff --git a/lib_rend/ivas_mcmasa_ana.c b/lib_rend/ivas_mcmasa_ana.c index 48d9c50f5..d210b3603 100644 --- a/lib_rend/ivas_mcmasa_ana.c +++ b/lib_rend/ivas_mcmasa_ana.c @@ -2331,12 +2331,14 @@ static void computeEvenLayout( } #endif + /*------------------------------------------------------------------------- * ivas_create_masa_out_meta() * * *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_create_masa_out_meta( MASA_DECODER_EXT_OUT_META_HANDLE extOutMeta, /* i/o: MASA metadata handle */ SPHERICAL_GRID_DATA *Sph_Grid16, /* i : Spherical grid */ @@ -2414,14 +2416,7 @@ void ivas_create_masa_out_meta( return; } - -#ifdef IVAS_FLOAT_FIXED -/*------------------------------------------------------------------------- - * ivas_create_masa_out_meta() - * - * - *------------------------------------------------------------------------*/ - +#else void ivas_create_masa_out_meta_fx( MASA_DECODER_EXT_OUT_META_HANDLE extOutMeta, /* i/o: MASA metadata handle */ SPHERICAL_GRID_DATA *Sph_Grid16, /* i : Spherical grid */ diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index 6ff205616..861a0db0e 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -40,6 +40,7 @@ #include "ivas_prot.h" #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" /*-------------------------------------------------------------------------* * audioCfg2channels() * @@ -530,7 +531,11 @@ Word16 ivas_get_nchan_buffers_dec( ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { Word16 nchan_internal; +#ifndef IVAS_FLOAT_FIXED nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); +#else + nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); +#endif nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; move16(); @@ -584,7 +589,11 @@ Word16 ivas_get_nchan_buffers_dec( ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { Word16 nchan_internal; +#ifndef IVAS_FLOAT_FIXED nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); +#else + nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); +#endif nchan_out_buff = add( st_ivas->nchan_ism, st_ivas->nchan_transport ); IF( st_ivas->hMCT != NULL ) diff --git a/lib_rend/ivas_output_init_fx.c b/lib_rend/ivas_output_init_fx.c index 708c93caf..2dc4f75d6 100644 --- a/lib_rend/ivas_output_init_fx.c +++ b/lib_rend/ivas_output_init_fx.c @@ -44,7 +44,7 @@ Word16 ivas_get_nchan_buffers_dec_ivas_fx( ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) { Word16 nchan_internal; - nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); + nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; move16(); @@ -99,7 +99,7 @@ Word16 ivas_get_nchan_buffers_dec_ivas_fx( ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { Word16 nchan_internal; - nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); + nchan_internal = ivas_sba_get_nchan_metadata_fx( sba_analysis_order, ivas_total_brate ); nchan_out_buff = add( st_ivas->nchan_ism, st_ivas->nchan_transport ); IF( st_ivas->hMCT != NULL ) diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 8e25239b7..66555279d 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -339,7 +339,7 @@ void ivas_dirac_dec_binaural_sba_gain( const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ const int16_t output_frame /* i : output frame length */ ); - +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_binaural_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -348,7 +348,16 @@ void ivas_dirac_dec_binaural_render( const int16_t nchan_transport, /* i : number of transport channels */ float *output_f[] /* o : rendered time signal */ ); - +#else +void ivas_dirac_dec_binaural_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_f[] /* o : rendered time signal */ +); +#endif void ivas_masa_ext_rend_parambin_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 8d83587e6..2c9d1ae7c 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -181,16 +181,17 @@ typedef struct dirac_decorr_params_structure typedef struct dirac_decorr_state_structure { +#ifndef IVAS_FLOAT_FIXED float *decorr_buffer; float *direct_energy_smooth; float *reverb_energy_smooth; -#ifdef IVAS_FLOAT_FIXED - Word32 *decorr_buffer_fx; +#else + Word32 *decorr_buffer_fx; /* Q(q_decorr_buffer) */ Word16 q_decorr_buffer; Word16 decorr_buffer_len; - Word32 *direct_energy_smooth_fx; + Word32 *direct_energy_smooth_fx; /* Q(q_direct_energy_smooth) */ Word16 q_direct_energy_smooth; - Word32 *reverb_energy_smooth_fx; + Word32 *reverb_energy_smooth_fx; /* Q(q_reverb_energy_smooth) */ Word16 q_reverb_energy_smooth; #endif @@ -306,8 +307,8 @@ typedef struct dirac_dec_stack_mem Word32 *direct_responses_fx; Word32 *direct_responses_square_fx; #endif + /* Target co-variance mtx */ - float *cy_auto_diff_smooth; #ifdef IVAS_FLOAT_FIXED Word32 *cy_auto_dir_smooth_fx; Word32 *cy_cross_dir_smooth_fx; @@ -315,6 +316,7 @@ typedef struct dirac_dec_stack_mem #else float *cy_cross_dir_smooth; float *cy_auto_dir_smooth; + float *cy_auto_diff_smooth; #endif #ifndef IVAS_FLOAT_FIXED @@ -325,7 +327,7 @@ typedef struct dirac_dec_stack_mem Word16 reference_power_q; Word16 reference_power_smooth_q; Word16 reference_power_len; - Word32 *onset_filter_fx; /* Q31 */ + Word32 *onset_filter_fx; /* Q31 */ #endif } DIRAC_DEC_STACK_MEM, *DIRAC_DEC_STACK_MEM_HANDLE; @@ -342,18 +344,19 @@ typedef struct dirac_output_synthesis_params_structure float *alpha_synthesis; float *alpha_synthesis_fast; #else - Word16 *interpolator_fx; /* Q15 */ - Word16 *alpha_synthesis_fx; /* Q15 */ - Word16 *alpha_synthesis_fast_fx; /* Q15 */ + Word16 *interpolator_fx; /* Q15 */ + Word16 *alpha_synthesis_fx; /* Q15 */ + Word16 *alpha_synthesis_fast_fx; /* Q15 */ #endif int16_t numAlphas; int16_t numAlphasFast; - float *proto_matrix; #ifdef IVAS_FLOAT_FIXED Word32 *proto_matrix_fx; Word16 proto_matrix_e; Word16 proto_matrix_len; +#else + float *proto_matrix; #endif #ifndef IVAS_FLOAT_FIXED @@ -400,22 +403,24 @@ typedef struct dirac_output_synthesis_state_structure #endif /* Output gain memories */ +#ifndef IVAS_FLOAT_FIXED float *gains_dir_prev; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ float *gains_diff_prev; /* Diffuse sound gains of previous synthesis block. Size: num_freq_bands*num_channel. */ +#endif /* only pointer to local buffers */ #ifndef IVAS_FLOAT_FIXED float *cy_auto_dir_smooth; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ float *cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ -#endif float *cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ +#endif /* PSD memories */ #ifndef IVAS_FLOAT_FIXED float *cy_auto_dir_smooth_prev; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ float *cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ -#endif float *cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound of previous synthesis block. Size: num_freq_bands*num_channels. */ +#endif #ifndef IVAS_FLOAT_FIXED const float *onset_filter; @@ -706,14 +711,14 @@ typedef struct ivas_dirac_rend_data_structure int16_t proto_signal_decorr_on; /*Decoder states=memories*/ +#ifndef IVAS_FLOAT_FIXED float *proto_frame_f; float *proto_frame_dec_f; -#ifdef IVAS_FLOAT_FIXED - Word32 *proto_frame_f_fx; +#else + Word32 *proto_frame_f_fx; /* Q(proto_frame_f_q) */ Word16 proto_frame_f_q; Word16 proto_frame_f_len; - - Word32 *proto_frame_dec_f_fx; + Word32 *proto_frame_dec_f_fx; /* Q(proto_frame_dec_f_q) */ Word16 proto_frame_dec_f_q; Word16 proto_frame_dec_f_len; #endif @@ -743,11 +748,11 @@ typedef struct ivas_dirac_rend_data_structure typedef struct vbap_vs_triplet_structure { uint8_t speaker_node[3]; +#ifndef IVAS_FLOAT_FIXED float inverse_matrix[3][3]; -#ifdef IVAS_FLOAT_FIXED - Word32 inverse_matrix_fx[3][3]; +#else + Word32 inverse_matrix_fx[3][3]; /* Q(q_inverse_matrix) */ Word16 q_inverse_matrix; - Word16 exp_inv_matrix; #endif } VBAP_VS_TRIPLET; @@ -1679,9 +1684,12 @@ typedef struct int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; const float *elevBsShape; int16_t elevSegSamples; +#ifndef IVAS_FLOAT_FIXED float resamp_factor; -#ifdef IVAS_FLOAT_FIXED +#else Word16 resamp_factor_fx; /*Q14*/ +#endif +#ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ const Word32 *azimKSeq_fx; /* Array, length azimDim3-2 */ const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 3d91b4128..7a51c4aa8 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -2182,7 +2182,7 @@ static Word16 check_and_store_triplet_fx( ) { Word16 ch_check; - Word16 k, i, j; + Word16 k; Word16 speaker_node_found_inside_triplet; UWord8 triplet_ok; @@ -2197,7 +2197,6 @@ static Word16 check_and_store_triplet_fx( speaker_node_triplet_unit_vec_matrix_fx[2] = speaker_node_data[chC].unit_vec_fx; Word16 exp_inv_mat = 31; matrix_inverse_3x3_32_fx( speaker_node_triplet_unit_vec_matrix_fx, inverse_matrix_fx, &exp_inv_mat ); - triplets[*triplet_index].exp_inv_matrix = exp_inv_mat; triplets[*triplet_index].q_inverse_matrix = 31 - exp_inv_mat; /* Check through all speaker nodes that none of them are within the triplet. @@ -2227,14 +2226,6 @@ static Word16 check_and_store_triplet_fx( { Copy32( inverse_matrix_fx[k], triplets[*triplet_index].inverse_matrix_fx[k], 3 ); } - /*TODO : Clean up float code*/ - FOR( i = 0; i < 3; i++ ) - { - FOR( j = 0; j < 3; j++ ) - { - triplets[*triplet_index].inverse_matrix[i][j] = me2f( triplets[*triplet_index].inverse_matrix_fx[i][j], exp_inv_mat ); - } - } /* Get center azimuth for fast search use */ Word32 tmp_a = L_add( L_shr( L_add( speaker_node_data[chA].unit_vec_fx[1], speaker_node_data[chB].unit_vec_fx[1] ), 2 ), L_shr( speaker_node_data[chC].unit_vec_fx[1], 2 ) ); // Q28 /*Condition to make tmp_a 0 to adress precision loss seen*/ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4a2db0827..63c64149e 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -13283,7 +13283,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( /* Directional and diffuses components in SHD */ /* Diffuseness components up to 1st order */ hDirACRend->num_outputs_diff = ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ) * ( min( hDirACRend->hOutSetup.ambisonics_order, 1 ) + 1 ); - hDirACRend->num_outputs_dir = ivas_sba_get_nchan( hDirACRend->hOutSetup.ambisonics_order, 0 ); + hDirACRend->num_outputs_dir = ivas_sba_get_nchan_fx( hDirACRend->hOutSetup.ambisonics_order, 0 ); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { @@ -13492,19 +13492,10 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { -#if 1 /*TODO :To be removed later(after dependecy on buffer_energyis completely removed)*/ - hDirACRend->proto_frame_f = NULL; -#endif hDirACRend->proto_frame_f_fx = NULL; } ELSE { -#if 1 /*TODO: To be removed later(after dependency on proto_frame_f is completely removed)*/ - IF( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } -#endif IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); @@ -14759,7 +14750,6 @@ static void intermidiate_ext_dirac_render( { Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - // floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } else { @@ -14769,27 +14759,23 @@ static void intermidiate_ext_dirac_render( { Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - // floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } else if ( ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( masa_band_mapping != NULL ) ) || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) { Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - // floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ { Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - // floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); } } else if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/ { Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - // floatToFixed_arrL32(hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult(hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir)); } } } @@ -14807,53 +14793,36 @@ static void intermidiate_ext_dirac_render( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev += shift; } - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) - { - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - }*/ - - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) - { - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); - ; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); - }*/ if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth += shift; } - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) - { - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); - }*/ Word16 num_channels_dir = hDirACRend->num_outputs_dir; if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; } - if ( h_dirac_output_synthesis_state->cy_auto_diff_smooth ) + if ( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) { - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); + tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth += tmp; } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev ) + if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) { - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); - ; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); + tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, tmp ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev += tmp; } + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); @@ -14861,16 +14830,11 @@ static void intermidiate_ext_dirac_render( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev += shift; } - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) - { - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); - floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); - }*/ if ( hDirACRend->proto_signal_decorr_on == 1 ) { - Word16 tmp_e; - f2me_buf( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, &tmp_e, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = 31 - tmp_e; + tmp = L_norm_arr( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); + scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); + hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer += tmp; } if ( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len > 0 ) @@ -14887,8 +14851,6 @@ static void intermidiate_ext_dirac_render( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = 31 - hr_exp; } - // f2me_buf(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); - // hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = 31 - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q; FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { /* CLDFB Analysis*/ @@ -14897,10 +14859,6 @@ static void intermidiate_ext_dirac_render( hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; } } - // if(DirAC_mem.frame_dec_f) - //{ - // //f2me_buf(DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_fx, &hDirACRend->proto_frame_dec_f_q, DirAC_mem.frame_dec_f_len); - // } hDirACRend->proto_frame_dec_f_q = 31 - hDirACRend->proto_frame_dec_f_q; if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) @@ -14926,72 +14884,6 @@ static void intermidiate_ext_dirac_render( } else { - FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) - { - // hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); - // hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); - } - - /* - IF(EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - } - ELSE - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_square, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); - } - } - }*/ - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); - }*/ - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); - }*/ - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); - }*/ - /*if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); - }*/ - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); - } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); - } - if ( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); - } - if ( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev ) - { - fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); - } - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len); - if ( hDirACRend->proto_signal_decorr_on == 1 ) - { - fixedToFloat_arrL32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - fixedToFloat_arrL( hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_direct_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr ); - fixedToFloat_arrL( hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_reverb_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr ); - } - } - // fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); - fixedToFloat_arrL32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, hDirACRend->proto_frame_f_len ); - // fixedToFloat_arrL32(DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_q, DirAC_mem.frame_dec_f_len); - FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) { /* CLDFB Analysis*/ diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 549d4cb4d..536668bac 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -260,10 +260,10 @@ static void LoadBSplineBinaryITD( modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); - for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) + modelITD->elevKSeq_dyn_fx = (Word32 *)malloc(sizeof(Word32)*(modelITD->elevDim3 - 2)); + for (int i = 0; i < modelITD->elevDim3 - 2; i++) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix( modelITD->elevKSeq_dyn[i], 22 ); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix(modelITD->elevKSeq_dyn[i], 22); } #endif @@ -273,9 +273,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) + for (int i = 0; i < ((modelITD->azimDim3 + 1) / 2 - 2); i++) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix( modelITD->azimKSeq_dyn[i], Q22 ); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix(modelITD->azimKSeq_dyn[i], Q22); } #endif @@ -297,9 +297,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for ( int i = 0; i < tmp; i++ ) + for (int i = 0; i < tmp; i++) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix( modelITD->azimBsShape_dyn[i], Q30 ); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix(modelITD->azimBsShape_dyn[i], Q30); } #endif @@ -315,9 +315,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for ( int i = 0; i < tmp; i++ ) + for (int i = 0; i < tmp; i++) { - modelITD->elevBsShape_dyn_fx[i] = float_to_fix( modelITD->elevBsShape_dyn[i], Q30 ); + modelITD->elevBsShape_dyn_fx[i] = float_to_fix(modelITD->elevBsShape_dyn[i], Q30); } #endif @@ -388,8 +388,9 @@ static ivas_error LoadBSplineBinary( HrFiltSet_p->SampleRate = 16000; if ( HrFiltSet_p->ModelParams.UseItdModel ) { +#ifndef IVAS_FLOAT_FIXED HrFiltSet_p->ModelParamsITD.resamp_factor = RESAMPLE_FACTOR_16_48; -#ifdef IVAS_FLOAT_FIXED +#else HrFiltSet_p->ModelParamsITD.resamp_factor_fx = RESAMPLE_FACTOR_16_48_FX; #endif } @@ -398,8 +399,9 @@ static ivas_error LoadBSplineBinary( HrFiltSet_p->SampleRate = 32000; if ( HrFiltSet_p->ModelParams.UseItdModel ) { +#ifndef IVAS_FLOAT_FIXED HrFiltSet_p->ModelParamsITD.resamp_factor = RESAMPLE_FACTOR_32_48; -#ifdef IVAS_FLOAT_FIXED +#else HrFiltSet_p->ModelParamsITD.resamp_factor_fx = RESAMPLE_FACTOR_32_48_FX; #endif } @@ -408,8 +410,9 @@ static ivas_error LoadBSplineBinary( HrFiltSet_p->SampleRate = 48000; if ( HrFiltSet_p->ModelParams.UseItdModel ) { +#ifndef IVAS_FLOAT_FIXED HrFiltSet_p->ModelParamsITD.resamp_factor = 1.0f; -#ifdef IVAS_FLOAT_FIXED +#else HrFiltSet_p->ModelParamsITD.resamp_factor_fx = ONE_IN_Q14; #endif } @@ -427,7 +430,7 @@ static ivas_error LoadBSplineBinary( fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); - for ( i = 0; i < ( model->elevDim3 - 2 ); i++ ) + for ( i = 0; i < (model->elevDim3 - 2); i++ ) { model->elevKSeq_dyn_fx[i] = float_to_fix( model->elevKSeq_dyn[i], Q22 ); } @@ -448,9 +451,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) + for (int j = 0; j < (model->azimDim3_dyn[i] + 1); j++) { - model->azimKSeq_fx[i][j] = float_to_fix( model->azimKSeq[i][j], Q22 ); + model->azimKSeq_fx[i][j] = float_to_fix(model->azimKSeq[i][j], Q22); } #endif } @@ -486,9 +489,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for ( int j = 0; j < tmp; j++ ) + for (int j = 0; j < tmp; j++) { - model->azimBsShape_dyn_fx[i][j] = float_to_fix( model->azimBsShape_dyn[i][j], Q30 ); + model->azimBsShape_dyn_fx[i][j] = float_to_fix(model->azimBsShape_dyn[i][j], Q30); } #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); @@ -506,10 +509,10 @@ static ivas_error LoadBSplineBinary( model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + model->elevBsShape_dyn_fx = (Word32 *)malloc(tmp * sizeof(Word32)); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix( model->elevBsShape_dyn[i], Q30 ); + model->elevBsShape_dyn_fx[i] = float_to_fix(model->elevBsShape_dyn[i], Q30); } #endif @@ -785,9 +788,9 @@ static void HRTF_energy_sections_precalc( pAlphaR += AlphaN; #ifdef IVAS_FLOAT_FIXED tmp_fx = *pAlphaL_fx; - *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ + *pEL_fx = L_add(*pEL_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ tmp_fx = *pAlphaR_fx; - *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ + *pER_fx = L_add(*pER_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ pAlphaL_fx += AlphaN; pAlphaR_fx += AlphaN; #endif @@ -803,8 +806,8 @@ static void HRTF_energy_sections_precalc( model->EL = (const float *) model->EL_dyn; model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED - model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) - model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) + model->EL_dyn_e = add(shl(model->AlphaL_e, 1), 1); // 2 * AlphaL_e + 1 (one guard bit) + model->ER_dyn_e = add(shl(model->AlphaR_e, 1), 1); // 2 * AlphaR_e + 1 (one guard bit) model->EL_fx = model->EL_dyn_fx; model->EL_e = model->EL_dyn_e; @@ -895,7 +898,7 @@ ivas_error dealloc_HRTF_binary( free( hHrtf->ModelParams.azimKSeq ); #ifdef IVAS_FLOAT_FIXED free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + FOR ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq_fx[i] ); } @@ -1049,7 +1052,7 @@ static ivas_error create_HRTF_from_rawdata( for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { //( *hHRTF )->inv_diffuse_weight[i] = *( (float *) ( hrtf_data_rptr ) ); - ( *hHRTF )->inv_diffuse_weight_fx[i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 ); + ( *hHRTF )->inv_diffuse_weight_fx[i] = ( Word16 ) (* ( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15); hrtf_data_rptr += sizeof( float ); } @@ -1074,8 +1077,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1083,12 +1086,12 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); /* coeff_im (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1106,8 +1109,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1115,7 +1118,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } @@ -1143,8 +1146,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1152,7 +1155,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -1173,8 +1176,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1182,7 +1185,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -2186,11 +2189,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( /*adding conversion as file reading is done in float*/ floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricReverberationEneCorrections_fx, Q31, CLDFB_NO_CHANNELS_MAX ); - // memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + //memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); memcpy( f_tmp_reverb, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( float ); /*adding conversion as file reading is done in float*/ - floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); + floatToFixed_arrL( f_tmp_reverb, (*hHRTF)->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); return IVAS_ERR_OK; } diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index 1a6943825..653149eb0 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -35,6 +35,9 @@ #include "ivas_stat_com.h" #include #include +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif struct MasaFileReader @@ -71,7 +74,11 @@ MasaFileReader *MasaFileReader_open( self = calloc( sizeof( MasaFileReader ), 1 ); self->file = file; +#ifndef IVAS_FLOAT_FIXED generate_gridEq( &self->sph_grid16 ); +#else + generate_gridEq_fx( &self->sph_grid16 ); +#endif return self; } -- GitLab From 55bd5603660f4013c47076a42a0e708fd0b40d4f Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 15:19:44 +0530 Subject: [PATCH 13/63] Clang formatting changes --- lib_com/ivas_fb_mixer.c | 36 +-- lib_dec/ivas_dirac_dec.c | 2 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 18 +- lib_rend/ivas_dirac_decorr_dec.c | 246 +++++++++---------- lib_rend/ivas_stat_rend.h | 2 +- lib_util/hrtf_file_reader.c | 74 +++--- 6 files changed, 189 insertions(+), 189 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index a03655eed..749952dfd 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -961,7 +961,7 @@ void ivas_FB_mixer_close( } #ifdef IVAS_FLOAT_FIXED - FOR ( j = start_diff_band_non48k; j < num_bands; j++ ) + FOR( j = start_diff_band_non48k; j < num_bands; j++ ) { free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] ); hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = NULL; @@ -1010,11 +1010,11 @@ void ivas_FB_mixer_close_fx( hFbMixer = *hFbMixer_in; fb_cfg = hFbMixer->fb_cfg; - IF ( fb_cfg->active_w_mixing == -1 ) + IF( fb_cfg->active_w_mixing == -1 ) { num_chs_alloc = 0; } - ELSE IF ( fb_cfg->active_w_mixing ) + ELSE IF( fb_cfg->active_w_mixing ) { num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); } @@ -1023,11 +1023,11 @@ void ivas_FB_mixer_close_fx( num_chs_alloc = 1; /* only W channel processed for predicting YZX */ } - IF ( hFbMixer != NULL ) + IF( hFbMixer != NULL ) { - FOR ( i = 0; i < num_chs_alloc; i++ ) + FOR( i = 0; i < num_chs_alloc; i++ ) { - IF ( fb_cfg->num_out_chans > 0 ) + IF( fb_cfg->num_out_chans > 0 ) { j = fb_cfg->remix_order[i]; @@ -1039,7 +1039,7 @@ void ivas_FB_mixer_close_fx( } } - IF ( fb_cfg->active_w_mixing == -1 ) + IF( fb_cfg->active_w_mixing == -1 ) { num_chs_alloc = 0; } @@ -1048,39 +1048,39 @@ void ivas_FB_mixer_close_fx( num_chs_alloc = max( fb_cfg->num_in_chans, fb_cfg->nchan_fb_in ); } - FOR ( i = 0; i < num_chs_alloc; i++ ) + FOR( i = 0; i < num_chs_alloc; i++ ) { free( hFbMixer->ppFilterbank_prior_input_fx[i] ); hFbMixer->ppFilterbank_prior_input_fx[i] = NULL; } - IF ( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) + IF( ( fb_cfg->active_w_mixing != -1 ) && ( fb_cfg->num_out_chans > 0 ) ) { free( hFbMixer->prior_mixer_fx[0][0] ); hFbMixer->prior_mixer_fx[0][0] = NULL; } - IF ( !spar_reconfig_flag ) + IF( !spar_reconfig_flag ) { - IF ( fb_cfg->num_out_chans > 0 ) + IF( fb_cfg->num_out_chans > 0 ) { num_bands = hFbMixer->pFb->filterbank_num_bands; - IF ( fb_cfg->active_w_mixing != -1 ) + IF( fb_cfg->active_w_mixing != -1 ) { - FOR ( i = 0; i < num_bands; i++ ) + FOR( i = 0; i < num_bands; i++ ) { free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band_fx[i] ); hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band_fx[i] = NULL; } } - IF ( sampling_rate != 48000 ) + IF( sampling_rate != 48000 ) { int16_t start_diff_band_non48k; start_diff_band_non48k = num_bands - hFbMixer->num_diff_bands; - FOR ( j = start_diff_band_non48k; j < num_bands; j++ ) + FOR( j = start_diff_band_non48k; j < num_bands; j++ ) { free( hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] ); hFbMixer->pFb->fb_consts.ppFilterbank_FRs_non48k_fx[0][j] = NULL; @@ -1090,20 +1090,20 @@ void ivas_FB_mixer_close_fx( } } } - IF ( hFbMixer->pFb != NULL ) + IF( hFbMixer->pFb != NULL ) { free( hFbMixer->pFb ); hFbMixer->pFb = NULL; } } - IF ( hFbMixer->fb_cfg != NULL ) + IF( hFbMixer->fb_cfg != NULL ) { free( hFbMixer->fb_cfg ); hFbMixer->fb_cfg = NULL; } - IF ( !spar_reconfig_flag ) + IF( !spar_reconfig_flag ) { free( hFbMixer ); hFbMixer = NULL; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index cadcb29a9..148c40a3c 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -4981,7 +4981,7 @@ void ivas_dirac_dec_render_sf_fx( #ifdef IVAS_FLOAT_FIXED /////////////////////////////////////////////////////// FIXED TO FLOAT ////////////////////////////////////////////////////////////////////////////////////////// - IF(EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD)) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 156108264..c429f551e 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -832,12 +832,12 @@ void ivas_dirac_dec_binaural_render( * *------------------------------------------------------------------------*/ void ivas_dirac_dec_binaural_render_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_f[] /* o : rendered time signal */ + Word32 *output_f[] /* o : rendered time signal */ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; @@ -850,7 +850,7 @@ void ivas_dirac_dec_binaural_render_fx( hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_out = BINAURAL_CHANNELS; - FOR ( ch = 0; ch < nchan_out; ch++ ) + FOR( ch = 0; ch < nchan_out; ch++ ) { output_fx_local[ch] = output_fx_local_buff[ch]; } @@ -869,12 +869,12 @@ void ivas_dirac_dec_binaural_render_fx( } output_length = 0; - FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { Word16 n_samples_sf = imult1616( slot_size, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); ivas_dirac_dec_binaural_internal_fx( st_ivas, st_ivas->hCombinedOrientationData, output_fx_local, nchan_transport, subframe_idx ); - FOR ( ch = 0; ch < nchan_out; ch++ ) + FOR( ch = 0; ch < nchan_out; ch++ ) { output_fx_local[ch] += n_samples_sf; } @@ -885,7 +885,7 @@ void ivas_dirac_dec_binaural_render_fx( ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); } - FOR ( ch = 0; ch < nchan_out; ch++ ) + FOR( ch = 0; ch < nchan_out; ch++ ) { Copy32( output_fx_local_buff[ch], output_f[ch], output_length ); } @@ -1562,7 +1562,7 @@ static void ivas_dirac_dec_binaural_internal_fx( } ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); #if 1 q_inp = Q6; @@ -7402,8 +7402,8 @@ static void ivas_masa_ext_rend_parambin_internal( max_band_decorr = hDiracDecBin->h_freq_domain_decorr_ap_params->max_band_decorr; ivas_dirac_dec_binaural_determine_processing_matrices_fx( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_fx, subframe, - hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, - 0, NULL ); + hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, + 0, NULL ); #if 1 Word16 q_out; diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index d9cf168dc..2e952223d 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -501,7 +501,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_params->pre_delay = NULL; freq_domain_decorr_ap_params->filter_length = NULL; - IF ( num_outputs_diff > 0 ) + IF( num_outputs_diff > 0 ) { buffer_size_decorr = ( ap_pre_delay[split_band_index_start] + ap_filter_length[split_band_index_start] ); IF( ( freq_domain_decorr_ap_state->decorr_buffer_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ) ) == NULL ) @@ -542,13 +542,13 @@ ivas_error ivas_dirac_dec_decorr_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } - IF((freq_domain_decorr_ap_params->pre_delay = (Word16 *)malloc(sizeof(Word16) * freq_domain_decorr_ap_params->num_split_frequency_bands)) == NULL) + IF( ( freq_domain_decorr_ap_params->pre_delay = (Word16 *) malloc( sizeof( Word16 ) * freq_domain_decorr_ap_params->num_split_frequency_bands ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } - IF((freq_domain_decorr_ap_params->filter_length = (Word16 *)malloc(sizeof(Word16) * freq_domain_decorr_ap_params->num_split_frequency_bands)) == NULL) + IF( ( freq_domain_decorr_ap_params->filter_length = (Word16 *) malloc( sizeof( Word16 ) * freq_domain_decorr_ap_params->num_split_frequency_bands ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } set32_fx( freq_domain_decorr_ap_state->direct_energy_smooth_fx, 0, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); @@ -556,7 +556,7 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_state->q_direct_energy_smooth = freq_domain_decorr_ap_state->q_reverb_energy_smooth = Q31; /* compute filter coefficients */ - FOR ( k = 0; k < freq_domain_decorr_ap_params->num_split_frequency_bands; k++ ) + FOR( k = 0; k < freq_domain_decorr_ap_params->num_split_frequency_bands; k++ ) { k_in = freq_domain_decorr_ap_params->split_frequency_bands[k]; k_out = freq_domain_decorr_ap_params->split_frequency_bands[k + 1]; @@ -565,11 +565,11 @@ ivas_error ivas_dirac_dec_decorr_open_fx( freq_domain_decorr_ap_params->filter_length[k] = add( ap_filter_length[band_table_idx], 1 ); freq_domain_decorr_ap_params->pre_delay[k] = ap_pre_delay[band_table_idx]; - FOR ( l = 0; l < num_outputs_diff; l++ ) + FOR( l = 0; l < num_outputs_diff; l++ ) { - FOR ( m = 0; m < num_bands; m++ ) + FOR( m = 0; m < num_bands; m++ ) { - n = add(k_in , m); + n = add( k_in, m ); Word32 cur_lattice_delta_phi_32_fx = L_mult( ap_lattice_delta_phi_fx[l * DIRAC_MAX_DECORR_FILTER_LEN + ap_filter_length[k] - 1], (Word16) floatToFixed( n, 10 ) ); cur_lattice_delta_phi_fx = extract_h( cur_lattice_delta_phi_32_fx ); // Q10 @@ -985,19 +985,19 @@ void ivas_dirac_dec_decorr_process_fx( } q_aux_buffer += q_shift; #else - (void)maximum_abs_32_fx(&input_frame_fx[0], 2 * num_protos_dir * num_freq_bands, &max_abs_val); + (void) maximum_abs_32_fx( &input_frame_fx[0], 2 * num_protos_dir * num_freq_bands, &max_abs_val ); q_shift = getScaleFactor32( &input_frame_fx[0], 2 * num_protos_dir * num_freq_bands ) - guarded_bits; - IF (LT_16(q_shift , sub(0, guarded_bits)) && NE_32(max_abs_val, 0)) + IF( LT_16( q_shift, sub( 0, guarded_bits ) ) && NE_32( max_abs_val, 0 ) ) { - q_shift = sub(0, guarded_bits); + q_shift = sub( 0, guarded_bits ); } - ELSE IF (EQ_32(max_abs_val, 0)) + ELSE IF( EQ_32( max_abs_val, 0 ) ) { q_shift = 0; } - FOR ( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++) + FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { - v_shr(&input_frame_fx[2 * ch_idx * num_freq_bands], negate(q_shift), &aux_buffer_fx[2 * ch_idx * num_freq_bands], 2 * num_freq_bands); + v_shr( &input_frame_fx[2 * ch_idx * num_freq_bands], negate( q_shift ), &aux_buffer_fx[2 * ch_idx * num_freq_bands], 2 * num_freq_bands ); } FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) { @@ -1273,17 +1273,17 @@ void ivas_dirac_dec_decorr_process_fx( h_freq_domain_decorr_ap_state->q_direct_energy_smooth = sub( 31, e_direct_energy_smooth ); // scaling energy buffers for better precision for higher values// - q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr)); - Scale_sig32(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr), q_shift); + q_shift = L_norm_arr( h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616( num_protos_dir, max_band_decorr ) ); + Scale_sig32( h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616( num_protos_dir, max_band_decorr ), q_shift ); h_freq_domain_decorr_ap_state->q_direct_energy_smooth = h_freq_domain_decorr_ap_state->q_direct_energy_smooth + q_shift; - q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr)); - Scale_sig32(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr), q_shift); + q_shift = L_norm_arr( h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616( num_channels, max_band_decorr ) ); + Scale_sig32( h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616( num_channels, max_band_decorr ), q_shift ); h_freq_domain_decorr_ap_state->q_reverb_energy_smooth = h_freq_domain_decorr_ap_state->q_reverb_energy_smooth + q_shift; - e_reverb_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_reverb_energy_smooth); - e_direct_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_direct_energy_smooth); + e_reverb_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_reverb_energy_smooth ); + e_direct_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_direct_energy_smooth ); // this step is b/c we are left shifting frame_dec_fx at the end of below for loop/ #ifdef MSAN_FIX @@ -1418,129 +1418,129 @@ void ivas_dirac_dec_decorr_process_fx( #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_decorr_close_fx( - HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, - HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state) + HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, + HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state ) { - DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; + DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; - /*-----------------------------------------------------------------* - * check input handles - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * check input handles + *-----------------------------------------------------------------*/ - if (ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL) - { - return; - } + if ( ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL ) + { + return; + } - if (*ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL) - { - return; - } + if ( *ph_freq_domain_decorr_ap_params == NULL || *ph_freq_domain_decorr_ap_state == NULL ) + { + return; + } - /*-----------------------------------------------------------------* - * free onset filter arrays - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * free onset filter arrays + *-----------------------------------------------------------------*/ - dirac_onset_detection_state = &(*ph_freq_domain_decorr_ap_state)->h_onset_detection_power_state; + dirac_onset_detection_state = &( *ph_freq_domain_decorr_ap_state )->h_onset_detection_power_state; #ifdef IVAS_FLOAT_FIXED - IF(dirac_onset_detection_state->onset_detector_1_fx != NULL) - { - free(dirac_onset_detection_state->onset_detector_1_fx); - dirac_onset_detection_state->onset_detector_1_fx = NULL; - } - - IF(dirac_onset_detection_state->onset_detector_2_fx != NULL) - { - free(dirac_onset_detection_state->onset_detector_2_fx); - dirac_onset_detection_state->onset_detector_2_fx = NULL; - } + IF( dirac_onset_detection_state->onset_detector_1_fx != NULL ) + { + free( dirac_onset_detection_state->onset_detector_1_fx ); + dirac_onset_detection_state->onset_detector_1_fx = NULL; + } + + IF( dirac_onset_detection_state->onset_detector_2_fx != NULL ) + { + free( dirac_onset_detection_state->onset_detector_2_fx ); + dirac_onset_detection_state->onset_detector_2_fx = NULL; + } #endif - /*-----------------------------------------------------------------* - * memory deallocation - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * memory deallocation + *-----------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - IF((*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx); - (*ph_freq_domain_decorr_ap_state)->decorr_buffer_fx = NULL; - } - - /* free ducker smoothed direct energy buffer */ - IF((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx); - (*ph_freq_domain_decorr_ap_state)->direct_energy_smooth_fx = NULL; - } - - /* free ducker smoothed reverb energy buffer */ - IF((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx); - (*ph_freq_domain_decorr_ap_state)->reverb_energy_smooth_fx = NULL; - } + IF( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx ); + ( *ph_freq_domain_decorr_ap_state )->decorr_buffer_fx = NULL; + } + + /* free ducker smoothed direct energy buffer */ + IF( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx ); + ( *ph_freq_domain_decorr_ap_state )->direct_energy_smooth_fx = NULL; + } + + /* free ducker smoothed reverb energy buffer */ + IF( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx ); + ( *ph_freq_domain_decorr_ap_state )->reverb_energy_smooth_fx = NULL; + } #endif - /* free pre-delay param buffer */ - if ((*ph_freq_domain_decorr_ap_params)->pre_delay != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->pre_delay); - (*ph_freq_domain_decorr_ap_params)->pre_delay = NULL; - } - - /* free filter length param buffer */ - if ((*ph_freq_domain_decorr_ap_params)->filter_length != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->filter_length); - (*ph_freq_domain_decorr_ap_params)->filter_length = NULL; - } - - /* free pre-delay param buffer */ - if ((*ph_freq_domain_decorr_ap_params)->split_frequency_bands != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->split_frequency_bands); - (*ph_freq_domain_decorr_ap_params)->split_frequency_bands = NULL; - } + /* free pre-delay param buffer */ + if ( ( *ph_freq_domain_decorr_ap_params )->pre_delay != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->pre_delay ); + ( *ph_freq_domain_decorr_ap_params )->pre_delay = NULL; + } + + /* free filter length param buffer */ + if ( ( *ph_freq_domain_decorr_ap_params )->filter_length != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->filter_length ); + ( *ph_freq_domain_decorr_ap_params )->filter_length = NULL; + } + + /* free pre-delay param buffer */ + if ( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands ); + ( *ph_freq_domain_decorr_ap_params )->split_frequency_bands = NULL; + } #ifdef IVAS_FLOAT_FIXED /* free filter coeff param buffers */ - IF((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx); - (*ph_freq_domain_decorr_ap_params)->filter_coeff_num_real_fx = NULL; - } + IF( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx ); + ( *ph_freq_domain_decorr_ap_params )->filter_coeff_num_real_fx = NULL; + } + + /* free pre-delay param buffer */ + IF( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx ); + ( *ph_freq_domain_decorr_ap_params )->filter_coeff_den_real_fx = NULL; + } /* free pre-delay param buffer */ - IF((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx); - (*ph_freq_domain_decorr_ap_params)->filter_coeff_den_real_fx = NULL; - } - - /* free pre-delay param buffer */ - IF((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx); - (*ph_freq_domain_decorr_ap_params)->phase_coeff_imag_fx = NULL; - } - - /* free pre-delay param buffer */ - IF((*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx != NULL) - { - free((*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx); - (*ph_freq_domain_decorr_ap_params)->phase_coeff_real_fx = NULL; - } + IF( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx ); + ( *ph_freq_domain_decorr_ap_params )->phase_coeff_imag_fx = NULL; + } + + /* free pre-delay param buffer */ + IF( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx != NULL ) + { + free( ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx ); + ( *ph_freq_domain_decorr_ap_params )->phase_coeff_real_fx = NULL; + } #endif - /* free pointers to state and parameter structs */ - free(*ph_freq_domain_decorr_ap_params); - *ph_freq_domain_decorr_ap_params = NULL; + /* free pointers to state and parameter structs */ + free( *ph_freq_domain_decorr_ap_params ); + *ph_freq_domain_decorr_ap_params = NULL; - free(*ph_freq_domain_decorr_ap_state); - *ph_freq_domain_decorr_ap_state = NULL; + free( *ph_freq_domain_decorr_ap_state ); + *ph_freq_domain_decorr_ap_state = NULL; - return; + return; } #else void ivas_dirac_dec_decorr_close( @@ -1696,7 +1696,7 @@ static void get_lattice_coeffs_fx( { Word16 k; - FOR ( k = 0; k < ap_filter_length[band_index]; k++ ) + FOR( k = 0; k < ap_filter_length[band_index]; k++ ) { Word16 cur_lattice_coeff = ap_lattice_coeffs_fx[band_index][channel_index * ap_filter_length[band_index] + k]; lattice_coeffs[k] = cur_lattice_coeff; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 2c9d1ae7c..0cf951fad 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1687,7 +1687,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float resamp_factor; #else - Word16 resamp_factor_fx; /*Q14*/ + Word16 resamp_factor_fx; /*Q14*/ #endif #ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 536668bac..048a86470 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -260,10 +260,10 @@ static void LoadBSplineBinaryITD( modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - modelITD->elevKSeq_dyn_fx = (Word32 *)malloc(sizeof(Word32)*(modelITD->elevDim3 - 2)); - for (int i = 0; i < modelITD->elevDim3 - 2; i++) + modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); + for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix(modelITD->elevKSeq_dyn[i], 22); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix( modelITD->elevKSeq_dyn[i], 22 ); } #endif @@ -273,9 +273,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - for (int i = 0; i < ((modelITD->azimDim3 + 1) / 2 - 2); i++) + for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix(modelITD->azimKSeq_dyn[i], Q22); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix( modelITD->azimKSeq_dyn[i], Q22 ); } #endif @@ -297,9 +297,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int i = 0; i < tmp; i++) + for ( int i = 0; i < tmp; i++ ) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix(modelITD->azimBsShape_dyn[i], Q30); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix( modelITD->azimBsShape_dyn[i], Q30 ); } #endif @@ -315,9 +315,9 @@ static void LoadBSplineBinaryITD( fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int i = 0; i < tmp; i++) + for ( int i = 0; i < tmp; i++ ) { - modelITD->elevBsShape_dyn_fx[i] = float_to_fix(modelITD->elevBsShape_dyn[i], Q30); + modelITD->elevBsShape_dyn_fx[i] = float_to_fix( modelITD->elevBsShape_dyn[i], Q30 ); } #endif @@ -430,7 +430,7 @@ static ivas_error LoadBSplineBinary( fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); - for ( i = 0; i < (model->elevDim3 - 2); i++ ) + for ( i = 0; i < ( model->elevDim3 - 2 ); i++ ) { model->elevKSeq_dyn_fx[i] = float_to_fix( model->elevKSeq_dyn[i], Q22 ); } @@ -451,9 +451,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - for (int j = 0; j < (model->azimDim3_dyn[i] + 1); j++) + for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) { - model->azimKSeq_fx[i][j] = float_to_fix(model->azimKSeq[i][j], Q22); + model->azimKSeq_fx[i][j] = float_to_fix( model->azimKSeq[i][j], Q22 ); } #endif } @@ -489,9 +489,9 @@ static ivas_error LoadBSplineBinary( fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int j = 0; j < tmp; j++) + for ( int j = 0; j < tmp; j++ ) { - model->azimBsShape_dyn_fx[i][j] = float_to_fix(model->azimBsShape_dyn[i][j], Q30); + model->azimBsShape_dyn_fx[i][j] = float_to_fix( model->azimBsShape_dyn[i][j], Q30 ); } #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); @@ -509,10 +509,10 @@ static ivas_error LoadBSplineBinary( model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - model->elevBsShape_dyn_fx = (Word32 *)malloc(tmp * sizeof(Word32)); + model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix(model->elevBsShape_dyn[i], Q30); + model->elevBsShape_dyn_fx[i] = float_to_fix( model->elevBsShape_dyn[i], Q30 ); } #endif @@ -788,9 +788,9 @@ static void HRTF_energy_sections_precalc( pAlphaR += AlphaN; #ifdef IVAS_FLOAT_FIXED tmp_fx = *pAlphaL_fx; - *pEL_fx = L_add(*pEL_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ tmp_fx = *pAlphaR_fx; - *pER_fx = L_add(*pER_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ pAlphaL_fx += AlphaN; pAlphaR_fx += AlphaN; #endif @@ -806,8 +806,8 @@ static void HRTF_energy_sections_precalc( model->EL = (const float *) model->EL_dyn; model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED - model->EL_dyn_e = add(shl(model->AlphaL_e, 1), 1); // 2 * AlphaL_e + 1 (one guard bit) - model->ER_dyn_e = add(shl(model->AlphaR_e, 1), 1); // 2 * AlphaR_e + 1 (one guard bit) + model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) + model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) model->EL_fx = model->EL_dyn_fx; model->EL_e = model->EL_dyn_e; @@ -898,7 +898,7 @@ ivas_error dealloc_HRTF_binary( free( hHrtf->ModelParams.azimKSeq ); #ifdef IVAS_FLOAT_FIXED free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq_fx[i] ); } @@ -1052,7 +1052,7 @@ static ivas_error create_HRTF_from_rawdata( for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { //( *hHRTF )->inv_diffuse_weight[i] = *( (float *) ( hrtf_data_rptr ) ); - ( *hHRTF )->inv_diffuse_weight_fx[i] = ( Word16 ) (* ( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15); + ( *hHRTF )->inv_diffuse_weight_fx[i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 ); hrtf_data_rptr += sizeof( float ); } @@ -1077,8 +1077,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1086,12 +1086,12 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); /* coeff_im (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1109,8 +1109,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1118,7 +1118,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } @@ -1146,8 +1146,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1155,7 +1155,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -1176,8 +1176,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1185,7 +1185,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -2189,11 +2189,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( /*adding conversion as file reading is done in float*/ floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricReverberationEneCorrections_fx, Q31, CLDFB_NO_CHANNELS_MAX ); - //memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + // memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); memcpy( f_tmp_reverb, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( float ); /*adding conversion as file reading is done in float*/ - floatToFixed_arrL( f_tmp_reverb, (*hHRTF)->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); + floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); return IVAS_ERR_OK; } -- GitLab From eb052b1fadb496ce46942cb26459ece2c7a40631 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 28 May 2024 17:52:24 +0530 Subject: [PATCH 14/63] Issue 738: Quaternion_slerp simplification --- lib_rend/ivas_orient_trk.c | 39 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 0a6cdbe4d..38c66b0c1 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -322,14 +322,14 @@ void QuaternionSlerp_fx( const Word32 t_fx, IVAS_QUATERNION *const r_fx ) { - IVAS_QUATERNION r1, r2; + IVAS_QUATERNION r1, r2, tmp_quat; Word32 sinPhi, cosPhi, temp_32; - Word16 q_min, sin_e, phi, s1, s2, temp_16, e_div; + Word16 q_min, sin_e, phi, s1, s2, temp_16; QuaternionNormalize_fx( q1_fx, &r1 ); QuaternionNormalize_fx( q2_fx, &r2 ); - Word16 w_qfact, x_qfact, y_qfact, z_qfact, q_result, q_dot = 0; + Word16 q_dot = 0; cosPhi = QuaternionDotProduct_fx( r1, r2, &q_dot ); q_min = s_min( r1.q_fact, r2.q_fact ); @@ -380,32 +380,13 @@ void QuaternionSlerp_fx( temp_16 = extract_h( temp_32 ); // Q13 s2 = getSineWord16R2( mult( temp_16, 20860 ) ); // Q15 - temp_32 = L_add( Mpy_32_16_1( r1.w_fx, s1 ), Mpy_32_16_1( r2.w_fx, s2 ) ); // q_min - r_fx->w_fx = BASOP_Util_Divide3232_Scale_cadence( temp_32, sinPhi, &e_div ); - e_div = e_div + ( 31 - q_min - sin_e ); - w_qfact = 31 - e_div; - - temp_32 = L_add( Mpy_32_16_1( r1.x_fx, s1 ), Mpy_32_16_1( r2.x_fx, s2 ) ); // q_min - r_fx->x_fx = BASOP_Util_Divide3232_Scale_cadence( temp_32, sinPhi, &e_div ); - e_div = e_div + ( 31 - q_min - sin_e ); - x_qfact = 31 - e_div; - - temp_32 = L_add( Mpy_32_16_1( r1.y_fx, s1 ), Mpy_32_16_1( r2.y_fx, s2 ) ); // q_min - r_fx->y_fx = BASOP_Util_Divide3232_Scale_cadence( temp_32, sinPhi, &e_div ); - e_div = e_div + ( 31 - q_min - sin_e ); - y_qfact = 31 - e_div; - - temp_32 = L_add( Mpy_32_16_1( r1.z_fx, s1 ), Mpy_32_16_1( r2.z_fx, s2 ) ); // q_min - r_fx->z_fx = BASOP_Util_Divide3232_Scale_cadence( temp_32, sinPhi, &e_div ); - e_div = e_div + ( 31 - q_min - sin_e ); - z_qfact = 31 - e_div; - - q_result = s_min( s_min( w_qfact, x_qfact ), s_min( y_qfact, z_qfact ) ); - r_fx->w_fx = L_shr( r_fx->w_fx, sub( w_qfact, q_result ) ); - r_fx->x_fx = L_shr( r_fx->x_fx, sub( x_qfact, q_result ) ); - r_fx->y_fx = L_shr( r_fx->y_fx, sub( y_qfact, q_result ) ); - r_fx->z_fx = L_shr( r_fx->z_fx, sub( z_qfact, q_result ) ); - r_fx->q_fact = q_result; + tmp_quat.w_fx = L_add( Mpy_32_16_1( r1.w_fx, s1 ), Mpy_32_16_1( r2.w_fx, s2 ) ); // q_min + tmp_quat.x_fx = L_add( Mpy_32_16_1( r1.x_fx, s1 ), Mpy_32_16_1( r2.x_fx, s2 ) ); // q_min + tmp_quat.y_fx = L_add( Mpy_32_16_1( r1.y_fx, s1 ), Mpy_32_16_1( r2.y_fx, s2 ) ); // q_min + tmp_quat.z_fx = L_add( Mpy_32_16_1( r1.z_fx, s1 ), Mpy_32_16_1( r2.z_fx, s2 ) ); // q_min + tmp_quat.q_fact = q_min; + + QuaternionDivision_fx(tmp_quat, sinPhi, r_fx, sin_e); } QuaternionNormalize_fx( *r_fx, r_fx ); -- GitLab From 329a6c52928655e9ea607e7557743ba1c8d99515 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 15:39:56 +0530 Subject: [PATCH 15/63] clang formatting changes --- lib_rend/ivas_orient_trk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 38c66b0c1..316a4a674 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -386,7 +386,7 @@ void QuaternionSlerp_fx( tmp_quat.z_fx = L_add( Mpy_32_16_1( r1.z_fx, s1 ), Mpy_32_16_1( r2.z_fx, s2 ) ); // q_min tmp_quat.q_fact = q_min; - QuaternionDivision_fx(tmp_quat, sinPhi, r_fx, sin_e); + QuaternionDivision_fx( tmp_quat, sinPhi, r_fx, sin_e ); } QuaternionNormalize_fx( *r_fx, r_fx ); -- GitLab From 948ed383c8d27b48091d62ba5a9bd32c0acae0a0 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 10 Jun 2024 14:45:11 +0200 Subject: [PATCH 16/63] Revert tag ivas-basop-linux --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f37aacd81..d4111c426 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -197,14 +197,14 @@ stages: # templates to define stages and platforms .test-job-linux: tags: - - test-ericsson-linux-runner-5 + - ivas-basop-linux .build-job-linux: stage: build timeout: "2 minutes" needs: [] tags: - - test-ericsson-linux-runner-5 + - ivas-basop-linux # template for test jobs on linux that need the TESTV_DIR .test-job-linux-needs-testv-dir: @@ -214,7 +214,7 @@ stages: - if [ ! -d "$TESTV_DIR" ]; then mkdir -p $TESTV_DIR; fi - cp -r scripts/testv/* $TESTV_DIR/ -.ivas-pytest-mld-anchor: &ivas-pytest-mld-anchor +.mv : &ivas-pytest-mld-anchor stage: test needs: ["build-codec-linux-make"] timeout: "240 minutes" @@ -682,7 +682,7 @@ be-2-evs-26444: pages: stage: deploy tags: - - test-ericsson-linux-runner-5 + - ivas-basop-linux rules: - if: $UPDATE_PAGES script: -- GitLab From b2662aadb1974885d34c58098d0844211c43b017 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 10 Jun 2024 14:47:22 +0200 Subject: [PATCH 17/63] Fix typo in .gitlab-ci.yml committed by accident --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d4111c426..f8e5b2b22 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -214,7 +214,7 @@ stages: - if [ ! -d "$TESTV_DIR" ]; then mkdir -p $TESTV_DIR; fi - cp -r scripts/testv/* $TESTV_DIR/ -.mv : &ivas-pytest-mld-anchor +.ivas-pytest-mld-anchor: &ivas-pytest-mld-anchor stage: test needs: ["build-codec-linux-make"] timeout: "240 minutes" -- GitLab From 88d43d2c9170cd392a3086916502e2578728ad1e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 21:37:19 +0530 Subject: [PATCH 18/63] jbm and dirac renderer clean-up, BASOP and instrumentation changes [x] jbm_dec_render and omasa_dirac_rend_jbm clean-up [x] Clean up: ModelParams_t and ModelParamsITD_t [x] BASOP and instrumentation changes --- lib_com/ivas_prot.h | 7 +- lib_com/ivas_prot_fx.h | 24 +- lib_com/prot_fx2.h | 2 +- lib_dec/acelp_core_switch_dec_fx.c | 100 +-- lib_dec/amr_wb_dec_fx.c | 143 ++-- lib_dec/ari_dec_fx.c | 58 +- lib_dec/ari_hm_dec.c | 105 +-- lib_dec/arith_coder_dec.c | 59 +- lib_dec/arith_coder_dec_fx.c | 34 +- lib_dec/avq_dec.c | 3 +- lib_dec/avq_dec_fx.c | 96 +-- lib_dec/bass_psfilter.c | 70 +- lib_dec/bass_psfilter_fx.c | 68 +- lib_dec/cng_dec_fx.c | 202 +++--- lib_dec/core_dec_init.c | 8 +- lib_dec/core_dec_init_fx.c | 576 ++++++++-------- lib_dec/core_dec_reconf_fx.c | 66 +- lib_dec/core_dec_switch_fx.c | 32 +- lib_dec/ivas_dirac_dec.c | 54 +- lib_dec/ivas_init_dec.c | 3 - lib_dec/ivas_jbm_dec.c | 921 +++++++------------------- lib_dec/ivas_omasa_dec.c | 98 ++- lib_dec/ivas_spar_decoder.c | 16 +- lib_dec/lib_dec_fx.c | 2 +- lib_dec/vlpc_2st_dec.c | 3 +- lib_rend/ivas_objectRenderer_hrFilt.c | 22 +- lib_rend/ivas_objectRenderer_mix.c | 3 - lib_rend/ivas_prot_rend.h | 4 +- lib_rend/ivas_reverb.c | 2 +- lib_rend/ivas_stat_rend.h | 36 +- lib_util/hrtf_file_reader.c | 363 +++++++--- 31 files changed, 1426 insertions(+), 1754 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 058e962ac..15826bdec 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -954,7 +954,7 @@ ivas_error ivas_jbm_dec_tc( float *data /* o : output synthesis signals */ ); #endif - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const uint16_t nSamplesAsked, /* i : number of samples wanted */ @@ -962,6 +962,7 @@ ivas_error ivas_jbm_dec_render( uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ int16_t *data /* o : output synthesis signal */ ); +#endif #ifdef IVAS_FLOAT_FIXED ivas_error ivas_jbm_dec_flush_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -7394,7 +7395,7 @@ void ivas_omasa_rearrange_channels( const int16_t nchan_transport_ism, /* i : number of ISM TCs */ const int16_t output_frame /* i : output frame length per channel */ ); - +#ifndef IVAS_FLOAT_FIXED void ivas_omasa_dirac_rend_jbm( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of samples requested */ @@ -7403,7 +7404,7 @@ void ivas_omasa_dirac_rend_jbm( const int16_t nchan_transport, /* i : number of transport channels */ float *output_f[] /* o : rendered time signal */ ); - +#endif #ifdef IVAS_FLOAT_FIXED void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( Decoder_Struct *st_ivas, diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 10885e58b..1c3e42ccd 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2096,11 +2096,8 @@ void td_bwe_dec_init_ivas_fx( ); void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#ifdef MSAN_FIX + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#endif // MSAN_FIX const int16_t nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ); @@ -2111,7 +2108,7 @@ void ivas_dirac_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - float *output_f[] /* o : rendered time signal */ + Word32 *output_f[] /* o : rendered time signal */ ); void ivas_dirac_dec_read_BS_fx( @@ -2268,4 +2265,21 @@ void ivas_sba_get_spar_hoa_md_flag_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word16 *spar_hoa_md_flag, Word16 *spar_hoa_dirac2spar_md_flag ); + +void ivas_omasa_dirac_rend_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of samples requested */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailable, /* o : number of samples still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_f[] /* o : rendered time signal */ +); + +ivas_error ivas_jbm_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of samples wanted */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ + Word16 *data /* o : output synthesis signal */ +); #endif diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 78e7ae597..12927bceb 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -8149,7 +8149,7 @@ void IGFSCFDecoderDecode( ); // ari_dec_fx.c -Word16 ari_decode_overflow_fx( Tastat *s ); +Word32 ari_decode_overflow_fx( Tastat *s ); void ari_start_decoding_14bits_fx( Decoder_State *st, diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index b86c8ae81..ccea920dd 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -34,7 +34,7 @@ ivas_error acelp_core_switch_dec_fx( Word16 i, delta, L_frame_for_cs, decode_bwe, tmp; Word16 d1m, ind1, fdelay, gapsize; Word32 cbrate; - Word16 synth_intFreq[2 * L_SUBFR]; + Word16 synth_intFreq[L_SUBFR * 2]; CLDFB_SCALE_FACTOR scaleFactor; Word32 workBuffer[128 * 3]; Word16 old_exc[L_EXC_DEC], *exc; @@ -42,7 +42,7 @@ ivas_error acelp_core_switch_dec_fx( Word16 hb_synth_tmp[NS2SA( 48000, 10000000 )]; const Word16 *hp_filter; Word16 Aq[2 * ( M + 1 )]; - Word16 bpf_error_signal[2 * L_SUBFR]; + Word16 bpf_error_signal[L_SUBFR * 2]; Word16 *pt1, *pt2; Word16 syn_fx_tmp[L_FRAME_16k]; Word32 *realBuffer[CLDFB_NO_COL_MAX_SWITCH], *imagBuffer[CLDFB_NO_COL_MAX_SWITCH]; @@ -72,12 +72,12 @@ ivas_error acelp_core_switch_dec_fx( Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); - set16_fx( mem_synth, 0, NS2SA( 16000, DELAY_CLDFB_NS ) + 2 ); + set16_fx( mem_synth, 0, add(NS2SA( 16000, DELAY_CLDFB_NS ), 2) ); set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */ /* set multiplication factor according to the sampling rate */ - delta = 1; - if ( GT_16( output_frame, L_FRAME16k ) ) + delta = 1; move16(); + IF ( GT_16( output_frame, L_FRAME16k ) ) { delta = shr( output_frame, 8 ); } @@ -97,7 +97,7 @@ ivas_error acelp_core_switch_dec_fx( IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { cbrate = L_add( st_fx->core_brate, 0 ); - if ( GT_32( cbrate, ACELP_24k40 ) ) + IF ( GT_32( cbrate, ACELP_24k40 ) ) { cbrate = L_add( ACELP_24k40, 0 ); } @@ -138,7 +138,7 @@ ivas_error acelp_core_switch_dec_fx( 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, 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 ); + syn_12k8_fx( shl(L_SUBFR, 1), Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); IF( st_fx->hPFstat->on && ( EQ_16( st_fx->last_bwidth, NB ) ) ) { @@ -149,20 +149,20 @@ ivas_error acelp_core_switch_dec_fx( pitch_buf_tmp[i] = L_SUBFR; move16(); } - nb_post_filt_fx( 2 * L_SUBFR, st_fx->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt_fx( shl(L_SUBFR, 1), 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 ) ) { - deemph_fx( synth_intFreq, PREEMPH_FAC, 2 * L_SUBFR, &( st_fx->mem_deemph_fx ) ); + deemph_fx( synth_intFreq, PREEMPH_FAC, shl(L_SUBFR, 1), &( st_fx->mem_deemph_fx ) ); } ELSE { - deemph_fx( synth_intFreq, PREEMPH_FAC_16k, 2 * L_SUBFR, &( st_fx->mem_deemph_fx ) ); + deemph_fx( synth_intFreq, PREEMPH_FAC_16k, shl(L_SUBFR, 1), &( st_fx->mem_deemph_fx ) ); } - unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp + M, st_fx->agc_mem_fx, 2 * L_SUBFR ); - Copy( syn_fx_tmp + M, synth_intFreq, 2 * L_SUBFR ); + unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp + M, st_fx->agc_mem_fx, shl(L_SUBFR, 1) ); + Copy( syn_fx_tmp + M, synth_intFreq, shl(L_SUBFR, 1) ); test(); IF( st_fx->hPFstat->on && ( NE_16( st_fx->last_bwidth, NB ) ) ) @@ -172,16 +172,16 @@ ivas_error acelp_core_switch_dec_fx( Residu3_fx( Aq, bpf_error_signal + M, exc, L_SUBFR, 1 ); E_UTIL_synthesis( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); scale_st_fx( synth_intFreq, bpf_error_signal, &st_fx->hPFstat->gain_prec, L_SUBFR ); - Copy( bpf_error_signal, synth_intFreq, L_SUBFR / 2 ); - blend_subfr2_fx( bpf_error_signal + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2 ); + Copy( bpf_error_signal, synth_intFreq, shr(L_SUBFR, 1) ); + blend_subfr2_fx( bpf_error_signal + shr(L_SUBFR, 1), synth_intFreq + shr(L_SUBFR, 1), synth_intFreq + shr(L_SUBFR, 1)); } st_fx->hPFstat->on = 0; move16(); - IF( st_fx->flag_cna != 0 ) + IF( NE_16(st_fx->flag_cna, 0 )) { - generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, 2 * L_SUBFR, 0 ); + generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, shl(L_SUBFR, 1), 0 ); } /*----------------------------------------------------------------* @@ -189,11 +189,11 @@ ivas_error acelp_core_switch_dec_fx( * Bass post-filter *----------------------------------------------------------------*/ - bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, 2 * L_SUBFR, NULL, + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, shl(L_SUBFR, 1), NULL, st_fx->bpf_off, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal ); - if ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -206,13 +206,13 @@ ivas_error acelp_core_switch_dec_fx( move16(); /* CLDFB analysis and add the BPF error signal */ - if ( ( error = cldfb_save_memory( st_fx->cldfbBPF ) ) != IVAS_ERR_OK ) + IF ( ( error = cldfb_save_memory( st_fx->cldfbBPF ) ) != IVAS_ERR_OK ) { return error; } i = 0; move16(); - if ( st_fx->bpf_off == 0 ) + IF ( EQ_16(st_fx->bpf_off, 0 )) { i = CLDFB_NO_COL_MAX_SWITCH; move16(); @@ -222,9 +222,9 @@ ivas_error acelp_core_switch_dec_fx( cldfb_restore_memory( st_fx->cldfbBPF ); /* CLDFB synthesis of the combined signal */ - scaleFactor.hb_scale = scaleFactor.lb_scale; + scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); - if ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -233,7 +233,7 @@ ivas_error acelp_core_switch_dec_fx( *Q_syn = 0; move16(); - Copy_Scale_sig( synth_intFreq + NS2SA( L_frame_for_cs * 50, SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) - 2, mem_synth, NS2SA( L_frame_for_cs * 50, DELAY_CLDFB_NS ) + 2, negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ + Copy_Scale_sig( synth_intFreq + sub(NS2SA( i_mult(L_frame_for_cs, 50), L_sub(SWITCH_GAP_LENGTH_NS, DELAY_CLDFB_NS) ), 2), mem_synth, add(NS2SA( i_mult(L_frame_for_cs, 50), DELAY_CLDFB_NS ), 2), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ /*----------------------------------------------------------------* * BWE decoding @@ -258,7 +258,7 @@ ivas_error acelp_core_switch_dec_fx( test(); IF( decode_bwe && !( ( EQ_16( output_frame, L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( output_frame, L_FRAME8k ) ) ) { - set16_fx( tmp_mem2, 0, 2 * L_FILT48k ); + set16_fx( tmp_mem2, 0, shl(L_FILT48k, 1)); hp_filter = hp16000_48000_fx; fdelay = 48; @@ -297,7 +297,7 @@ ivas_error acelp_core_switch_dec_fx( /* safety check in case of bit errors */ i = MAX_D1M_16k; move16(); - if ( EQ_16( st_fx->last_L_frame, L_FRAME ) ) + IF ( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { i = MAX_D1M_12k8; move16(); @@ -312,7 +312,7 @@ ivas_error acelp_core_switch_dec_fx( move16(); } - i = NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ); + i = NS2SA_fx2( st_fx->output_Fs, L_sub(FRAME_SIZE_NS, L_add(ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS)) ); move16(); Copy( st_fx->old_synth_sw_fx, hb_synth_tmp, i ); set16_fx( hb_synth_tmp + i, 0, NS2SA_fx2( st_fx->output_Fs, 10000000L ) - i ); @@ -421,12 +421,12 @@ ivas_error acelp_core_switch_dec_bfi_fx( set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - if ( st_fx->hBWE_TD != NULL ) + 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; + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, shl(PIT16k_MAX, 1) ); + bwe_exc = old_bwe_exc + shl(PIT16k_MAX, 1); } - else + ELSE { bwe_exc = NULL; } @@ -437,7 +437,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( move16(); /* SC-VBR */ - if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) + IF ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); @@ -464,13 +464,13 @@ ivas_error acelp_core_switch_dec_bfi_fx( { Word16 gain_buf[NB_SUBFR16k]; Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); - st_fx->Q_exc = 0; + st_fx->Q_exc = 0; move16(); /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); 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; + st_fx->Q_exc = Q_exc; move16(); } ELSE { @@ -515,7 +515,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy( st_fx->mem_syn2_fx, tmp_float, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); - tmp_float32 = st_fx->enr_old_fx; + tmp_float32 = st_fx->enr_old_fx; move32(); frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* @@ -557,12 +557,12 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy( tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST ); Copy( tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST ); Copy( tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST ); - hBPF->psf_att_fx = tmp_float7; + hBPF->psf_att_fx = tmp_float7; move16(); /*----------------------------------------------------------------* * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - if ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -570,10 +570,10 @@ ivas_error acelp_core_switch_dec_bfi_fx( negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); cldfb_restore_memory( st_fx->cldfbAna ); - scaleFactor.hb_scale = scaleFactor.lb_scale; + scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); /* CLDFB synthesis of the combined signal */ - if ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -662,12 +662,12 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - if ( st_fx->hBWE_TD != NULL ) + 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 + ELSE { bwe_exc = NULL; } @@ -678,7 +678,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( move16(); /* SC-VBR */ - if ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) + IF ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); @@ -705,13 +705,13 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( { Word16 gain_buf[NB_SUBFR16k]; Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); - st_fx->Q_exc = 0; + st_fx->Q_exc = 0; move16(); /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); 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; + st_fx->Q_exc = Q_exc; move16(); } ELSE { @@ -756,7 +756,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy( st_fx->mem_syn2_fx, tmp_float, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); - tmp_float32 = st_fx->enr_old_fx; + tmp_float32 = st_fx->enr_old_fx; move32(); frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* @@ -803,9 +803,9 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - Qtmp = 11 - st_fx->Q_syn; + Qtmp = sub(11, st_fx->Q_syn); Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); - if ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -817,7 +817,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( // scaleFactor.hb_scale = scaleFactor.lb_scale; /* CLDFB synthesis of the combined signal */ - if ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -825,7 +825,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/ Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); st_fx->cldfbSyn->Q_cldfb_state = add( st_fx->cldfbSyn->Q_cldfb_state, 1 ); - Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 11 - 5 - 1 ); + Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 5 ); /*11-5-1*/ // cldfbSynthesis_ivas_fx(realBuffer, imagBuffer, synth_out, (int16_t)(st_fx->output_Fs * 0.01f), st_fx->cldfbSyn); cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ), st_fx->cldfbSyn ); @@ -872,7 +872,7 @@ static void decod_gen_voic_core_switch_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; + Flag Overflow = 0; move16(); #endif @@ -905,7 +905,7 @@ static void decod_gen_voic_core_switch_fx( * Find the adaptive codebook vector. *--------------------------------------------------------------*/ - pred_lt4( &exc[0], &exc[0], T0, T0_frac, L_SUBFR + 1, pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[0], &exc[0], T0, T0_frac, add(L_SUBFR, 1), pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*--------------------------------------------------------------* * LP filtering of the adaptive excitation diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index ef751675e..5a7168372 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -39,7 +39,7 @@ ivas_error amr_wb_dec_fx( Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ Word16 xsp_tmp[M]; - Word16 Aq_fx[NB_SUBFR * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ + Word16 Aq_fx[NB_SUBFR * (M + 1)]; /* A(q) quantized for the 4 subframes */ Word16 exc2_fx[L_FRAME]; /* total excitation buffer */ Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ Word32 L_enr_q_fx; /* E information for FER protection */ @@ -51,7 +51,7 @@ ivas_error amr_wb_dec_fx( Word32 L_tmp, L_tmp1; Word16 pitch_buf_fx[NB_SUBFR], Qdct, tmp_coder_type; /* floating pitch for each subframe (Q6) */ Word16 tmp16; - Word16 sid_bw = 0; + Word16 sid_bw = 0; move16(); Word32 L_Ng_ener; Word16 exp2, ng_ener; @@ -138,7 +138,7 @@ ivas_error amr_wb_dec_fx( st_fx->bpf_off = 0; move16(); - if ( EQ_16( st_fx->last_core, HQ_CORE ) ) + IF ( EQ_16( st_fx->last_core, HQ_CORE ) ) { st_fx->bpf_off = 1; move16(); @@ -149,11 +149,11 @@ ivas_error amr_wb_dec_fx( move16(); st_fx->sr_core = i_mult( st_fx->L_frame, 50 ); - st_fx->fscale_old = st_fx->fscale; + st_fx->fscale_old = st_fx->fscale; move16(); st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Initialization in case that the first frame is the good received AMR-WB (IO) frame */ - IF( st_fx->ini_frame == 0 ) + IF( EQ_16(st_fx->ini_frame, 0 )) { st_fx->last_core = AMR_WB_CORE; move16(); @@ -168,7 +168,7 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ - if ( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) + IF ( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -186,12 +186,12 @@ ivas_error 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->hPFstat->on == 0 ) + IF ( EQ_16(st_fx->hPFstat->on, 0 )) { st_fx->hPFstat->reset = 1; move16(); } - IF( st_fx->bfi > 0 ) + IF( GT_16(st_fx->bfi, 0 )) { st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); } @@ -221,7 +221,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( st_fx->last_core != 0 ) ) + IF ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( NE_16(st_fx->last_core, 0 )) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -240,7 +240,7 @@ ivas_error amr_wb_dec_fx( st_fx->bpf_off = 1; move16(); - if ( st_fx->hPFstat->on != 0 ) + IF ( NE_16(st_fx->hPFstat->on, 0 )) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; @@ -280,28 +280,28 @@ ivas_error amr_wb_dec_fx( IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - tmp16 = 13107; + tmp16 = 13107; move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ - tmp16 = 16384; + tmp16 = 16384; move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - tmp16 = 26214; + tmp16 = 26214; move16(); } - FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) + FOR( i = sub(NB_SUBFR16k, NB_SUBFR); i < NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i - 1] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[sub(i, 1)] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } - FOR( i = 2 * NB_SUBFR16k - NB_SUBFR; i < 2 * NB_SUBFR16k; i++ ) + FOR( i = sub(shl(NB_SUBFR16k, 1), NB_SUBFR); i < shl(NB_SUBFR16k, 1); i++ ) { - st_fx->old_pitch_buf_fx[i - 2] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[sub(i, 2)] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } } @@ -312,17 +312,17 @@ ivas_error amr_wb_dec_fx( IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - tmp16 = 13107; + tmp16 = 13107; move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ - tmp16 = 16384; + tmp16 = 16384; move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - tmp16 = 26214; + tmp16 = 26214; move16(); } st_fx->bfi_pitch_fx = mult_r( tmp16, st_fx->bfi_pitch_fx ); st_fx->bfi_pitch_frame = L_FRAME; @@ -335,13 +335,13 @@ ivas_error amr_wb_dec_fx( { /* reset the unvoiced/audio signal improvement memories */ 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 ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + add(M, 1), add(M, 1) ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult(2, add(M, 1)), add(M, 1) ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult(3, add(M, 1)), add(M, 1) ); } /*End of _DIFF_FLOAT_FIX_*/ test(); - if ( EQ_16( st_fx->last_bwidth, NB ) && st_fx->ini_frame != 0 ) + IF ( EQ_16( st_fx->last_bwidth, NB ) && NE_16(st_fx->ini_frame, 0 )) { st_fx->rate_switching_reset = 1; move16(); @@ -382,14 +382,13 @@ ivas_error amr_wb_dec_fx( delta_mem_scale = 3; move16(); - test(); - if ( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ + IF ( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } - i = st_fx->Q_exc; + i = st_fx->Q_exc; move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, st_fx->L_frame * 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, @@ -397,8 +396,8 @@ ivas_error amr_wb_dec_fx( Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); /* update past excitation signals for LD music post-filter */ - 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 + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub(DCT_L_POST, add(L_FRAME, OFFSET2) )); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add(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 ); @@ -421,7 +420,7 @@ ivas_error amr_wb_dec_fx( st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440, st_fx->psf_lp_noise_fx ), 328, frame_e_fx ) ); /*Q8*/ } /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + sub(L_FRAME, 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 */ @@ -461,7 +460,7 @@ ivas_error amr_wb_dec_fx( st_fx->coder_type = GENERIC; move16(); - if ( vad_flag == 0 ) + IF ( EQ_16(vad_flag, 0 )) { st_fx->coder_type = INACTIVE; move16(); @@ -523,7 +522,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - if ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, 15 << 7 ) ) + IF ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl(15, 7) ) ) { tmp16 = 1; move16(); @@ -544,9 +543,9 @@ ivas_error amr_wb_dec_fx( 0, 0, 0, st_fx->last_core_brate, -1 ); /* update past excitation signals for LD music post-filter */ - 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 ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub(DCT_L_POST, add(L_FRAME, OFFSET2) )); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add(L_FRAME, OFFSET2) ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, sub(DCT_L_POST, OFFSET2) ); IF( NE_16( output_frame, L_FRAME8k ) ) { @@ -560,12 +559,12 @@ ivas_error amr_wb_dec_fx( test(); test(); - IF( NE_16( amr_io_class, UNVOICED_CLAS ) && NE_16( st_fx->coder_type, INACTIVE ) && LT_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) + IF( NE_16( amr_io_class, UNVOICED_CLAS ) && NE_16( st_fx->coder_type, INACTIVE ) && LT_16( st_fx->psf_lp_noise_fx, shl(15, 8) ) ) { tmp_coder_type = AUDIO; move16(); test(); - if ( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) + IF ( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) { tmp_coder_type = INACTIVE; move16(); @@ -631,7 +630,7 @@ ivas_error amr_wb_dec_fx( { /* long burst frame erasures */ test(); - if ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) + IF ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) { st_fx->last_good = VOICED_TRANSITION; move16(); @@ -664,7 +663,7 @@ ivas_error amr_wb_dec_fx( /* 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]; + hMusicPF->LDm_lt_diff_etot_fx[sub(i, 1)] = hMusicPF->LDm_lt_diff_etot_fx[i]; move16(); } /* Filter energies update */ @@ -681,7 +680,7 @@ ivas_error amr_wb_dec_fx( 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 ); /* update old synthesis for classification */ - Copy( syn_fx + L_FRAME - L_SYN_MEM_CLAS_ESTIM, st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + sub(L_FRAME, L_SYN_MEM_CLAS_ESTIM), st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); FOR( i = 0; i < NB_SUBFR; i++ ) @@ -734,7 +733,7 @@ ivas_error amr_wb_dec_fx( *-----------------------------------------------------------------*/ /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + L_FRAME - L_SYN_MEM, st_fx->mem_syn_r, L_SYN_MEM ); + Copy( syn_fx + sub(L_FRAME, L_SYN_MEM), st_fx->mem_syn_r, L_SYN_MEM ); deemph_fx( syn_fx, PREEMPH_FAC, L_FRAME, &( st_fx->mem_deemph_fx ) ); @@ -742,8 +741,8 @@ ivas_error 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, 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*/ + Copy_Scale_sig( syn_fx + shr(L_FRAME, 2), hTcxDec->old_syn_Overl, shr(L_FRAME, 2), sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ + Copy_Scale_sig( syn_fx + sub(L_FRAME, add(M, 1)), st_fx->syn, add(M, 1), sub( 0, st_fx->Q_syn ) ); /*Q0*/ /*------------------------------------------------------------------* * Formant post-filter @@ -755,7 +754,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->on = 1; move16(); test(); - formant_post_filt_fx( 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, sub( amr_io_class, AUDIO_CLAS ) == 0 ); + formant_post_filt_fx( 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, EQ_16(sub( amr_io_class, AUDIO_CLAS ), 0 )); } /*----------------------------------------------------------------* @@ -765,7 +764,7 @@ ivas_error amr_wb_dec_fx( flag_cna = 0; move16(); test(); - IF( ( GE_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) || ( st_fx->coder_type == INACTIVE ) ) + IF( ( GE_16( st_fx->psf_lp_noise_fx, shl(15, 8) ) ) || EQ_16( st_fx->coder_type, INACTIVE ) ) { /*VAD only for non inactive frame*/ test(); @@ -785,13 +784,13 @@ ivas_error amr_wb_dec_fx( #else ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, NULL, NULL, st_fx, 0, 0 ); #endif - st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; + st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; move16(); /*Noisy speech detector*/ noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - IF( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + IF( NE_16(st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 )) { st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); @@ -800,7 +799,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); - IF( st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, 15 << 8 ) ) + IF( st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl(15, 8) ) ) { flag_cna = 1; move16(); @@ -819,16 +818,16 @@ ivas_error amr_wb_dec_fx( } - IF( flag_cna == 0 ) + IF( EQ_16(flag_cna, 0 )) { test(); test(); test(); IF( EQ_16( st_fx->last_flag_cna, 1 ) && ( ( EQ_16( st_fx->last_core, ACELP_CORE ) && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - FOR( i = 0; i < L_FRAME / 2; i++ ) + FOR( i = 0; i < shr(L_FRAME, 1); i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * L_FRAME / 4], -st_fx->Q_syn ) ); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add(i, shr(i_mult(5, L_FRAME), 2))], -st_fx->Q_syn ) ); move16(); } } @@ -841,7 +840,7 @@ ivas_error amr_wb_dec_fx( *----------------------------------------------------------------*/ /* check if the CLDFB works on the right sample rate */ - IF( ( st_fx->cldfbAna->usb * st_fx->cldfbAna->no_col ) != L_FRAME ) + IF( NE_16(i_mult( st_fx->cldfbAna->usb, st_fx->cldfbAna->no_col ), L_FRAME )) { /* resample to ACELP internal sampling rate */ Word16 newCldfbBands = CLDFB_getNumChannels( INT_FS_FX ); @@ -849,7 +848,7 @@ ivas_error amr_wb_dec_fx( resampleCldfb( st_fx->cldfbAna, newCldfbBands, L_FRAME, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, L_FRAME, 0 ); - if ( st_fx->ini_frame > 0 ) + IF ( GT_16(st_fx->ini_frame, 0 )) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); } @@ -867,7 +866,7 @@ ivas_error amr_wb_dec_fx( /* CLDFB analysis and add the BPF error signal */ i = 0; move16(); - if ( st_fx->bpf_off == 0 ) + IF ( EQ_16(st_fx->bpf_off, 0 )) { i = CLDFB_NO_COL_MAX; move16(); @@ -877,7 +876,7 @@ ivas_error amr_wb_dec_fx( st_fx->Q_syn2 = st_fx->Q_syn; move16(); - if ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) + IF ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); @@ -909,7 +908,7 @@ ivas_error amr_wb_dec_fx( tmp16 = norm_l( L_Ng_ener ); exp2 = Log2_norm_lc( L_shl( L_Ng_ener, tmp16 ) ); tmp16 = sub( 30, tmp16 ); - ng_ener = mac_r( L_shl( L_mac( -1233858L, tmp16, 24660 ), 8 + 2 ), exp2, 771 ); + ng_ener = mac_r( L_shl( L_mac( -1233858L, tmp16, 24660 ), 10 ), exp2, 771 ); /* st_fx->ng_ener_ST = 0.7f * st_fx->ng_ener_ST + 0.3f * ng_ener; */ st_fx->Ng_ener_ST_fx = mac_r( L_mult( st_fx->Ng_ener_ST_fx, 22938 ), ng_ener, 9830 ); move16(); @@ -938,7 +937,7 @@ ivas_error amr_wb_dec_fx( 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->hAmrwb_IO->old_Aq_fx, NB_SUBFR * ( M + 1 ) ); + Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * add(M, 1) ); test(); test(); @@ -948,7 +947,7 @@ ivas_error amr_wb_dec_fx( test(); test(); test(); - if ( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && 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 ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF ( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && 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 ) ) && EQ_16(st_fx->plcInfo.concealment_method, TCX_NONTONAL) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { waveadj_rec = 1; move16(); @@ -973,7 +972,7 @@ ivas_error amr_wb_dec_fx( move32(); st_fx->prev_Q_exc = st_fx->Q_exc; move16(); - if ( !st_fx->bfi ) + IF ( !st_fx->bfi ) { st_fx->last_total_brate = st_fx->total_brate; move32(); @@ -991,10 +990,10 @@ ivas_error amr_wb_dec_fx( * Overlap of ACELP synthesis with old MDCT memory *----------------------------------------------------------------*/ - if ( st_fx->bfi ) + IF ( st_fx->bfi ) { /* calculate another loss frame to fill gap in case of switching frame loss */ - if ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) + IF ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) { return error; } @@ -1049,17 +1048,17 @@ ivas_error amr_wb_dec_fx( /* Delay ACELP synthesis by DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS delay */ IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ); + tmps = NS2SA_fx2( st_fx->output_Fs, L_sub(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 ) ); delay_signal( synth_out_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps ); } - if ( waveadj_rec ) + IF ( waveadj_rec ) { - tmps = 0; + tmps = 0; move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); move16(); } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth_out_fx + tmps, st_fx->plcInfo.data_noise, &st_fx->plcInfo.outx_new_n1_fx, @@ -1073,11 +1072,11 @@ ivas_error 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, ACELP_LOOK_NS + DELAY_BWE_TOTAL_NS ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ), sub( hHQ_core->Q_old_postdec, st_fx->Q_syn2 ) ); + Copy_Scale_sig( synth_out_fx + NS2SA_fx2( st_fx->output_Fs, L_add(ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS) ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, L_sub(FRAME_SIZE_NS, L_add(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, TCXLTP_DELAY_NS ); + Word16 delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); move16(); 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 ); @@ -1109,17 +1108,17 @@ void amr_wb_dec_init_fx( /* 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 ); + hAmrwb_IO->LT_UV_cnt_fx = shl( 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 ) ); + set16_fx( hAmrwb_IO->old_Aq_fx, 0, i_mult(NB_SUBFR, add(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; + hAmrwb_IO->old_Aq_fx[add(M, 1)] = 16384; + hAmrwb_IO->old_Aq_fx[i_mult(2, add( M, 1 ))] = 16384; + hAmrwb_IO->old_Aq_fx[i_mult(3, add( M, 1 ))] = 16384; move16(); move16(); move16(); diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 3fa319ad2..584cb5028 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -14,9 +14,9 @@ * Ari decode 14 bits routines -------------------------------------------------------------*/ -Word16 ari_decode_overflow_fx( Tastat *s ) +Word32 ari_decode_overflow_fx( Tastat *s ) { - return L_sub( L_sub( s->high, 1 ), s->low ) <= 0; + return LE_32(L_sub( L_sub( s->high, 1 ), s->low ), 0); } /** @@ -34,7 +34,7 @@ void ari_start_decoding_14bits_fx( val = L_and( L_deposit_l( get_next_indice( st, cbitsnew ) ), 0xffffL ); s->low = L_deposit_l( 0 ); - s->high = ari_q4new + 1; + s->high = L_add(ari_q4new, 1); move32(); s->value = val; move32(); @@ -56,13 +56,13 @@ Word16 ari_start_decoding_14bits_prm_fx( FOR( i = 0; i < cbitsnew; i++ ) { val = L_shl( val, 1 ); - if ( *( p + i ) ) + IF ( *( p + i ) ) { val = L_add( val, 1 ); } } s->low = L_deposit_l( 0 ); - s->high = ari_q4new + 1; + s->high = L_add(ari_q4new, 1); move32(); s->value = val; move32(); @@ -90,20 +90,20 @@ static Word16 ari_lookup_s17_fx( range_h = extract_l( L_shr( range, 15 ) ); tmp = L_multi31x16_X2( range_h, range_l, p[8] ); - if ( GT_32( tmp, cum ) ) + IF ( GT_32( tmp, cum ) ) { p = p + 8; } tmp = L_multi31x16_X2( range_h, range_l, p[4] ); - if ( GT_32( tmp, cum ) ) + IF ( GT_32( tmp, cum ) ) { p = p + 4; } tmp = L_multi31x16_X2( range_h, range_l, p[2] ); - if ( GT_32( tmp, cum ) ) + IF ( GT_32( tmp, cum ) ) { p = p + 2; } @@ -115,7 +115,7 @@ static Word16 ari_lookup_s17_fx( tmp = L_multi31x16_X2( range_h, range_l, p[1] ); test(); - if ( ( (Word32) ( &cum_freq[15] - p ) == 0 ) && ( GT_32( tmp, cum ) ) ) + IF ( EQ_32( (Word32) ( &cum_freq[15] - p ),0 ) && ( GT_32( tmp, cum ) ) ) { p = p + 1; } @@ -156,12 +156,12 @@ static Word16 ari_lookup_s27_fx( move16(); /* (il + ih) >> 1 */ tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF ( GT_32(tmp, 0 )) { il = im; move16(); } - if ( tmp <= 0 ) + IF ( LE_32(tmp, 0 )) { ih = im; move16(); @@ -170,12 +170,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF ( GT_32(tmp, 0 )) { il = im; move16(); } - if ( tmp <= 0 ) + IF ( LE_32(tmp, 0 )) { ih = im; move16(); @@ -184,12 +184,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF ( GT_32(tmp, 0 )) { il = im; move16(); } - if ( tmp <= 0 ) + IF ( LE_32(tmp, 0 )) { ih = im; move16(); @@ -198,12 +198,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF ( GT_32(tmp, 0 )) { il = im; move16(); } - if ( tmp <= 0 ) + IF ( LE_32(tmp, 0 )) { ih = im; move16(); @@ -215,7 +215,7 @@ static Word16 ari_lookup_s27_fx( im = add( il, 1 ); /* (il + ih) >> 1 */ tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - if ( tmp > 0 ) + IF ( GT_32(tmp, 0 )) { il = im; move16(); @@ -237,12 +237,12 @@ static Word16 ari_lookup_bit_fx( range = L_shl( range, 13 ); /* L_multi31x16_X2(range_h, range_l, 8192) */ cum = L_sub( range, cum ); - if ( cum > 0 ) + IF ( GT_32(cum, 0 )) { symbol = 1; move16(); } - if ( cum <= 0 ) + IF ( LE_32(cum, 0 )) { symbol = 0; move16(); @@ -275,15 +275,15 @@ static Word16 ari_decode_14bits_ext_fx( range = L_sub( high, low ); cum = L_add( L_shl( L_sub( value, low ), stat_bitsnew ), sub( shl( 1, stat_bitsnew ), 1 ) ); - if ( cum < 0 ) + IF ( LT_32(cum, 0 )) { - cum = 0x7fffffff; + cum = 0x7fffffff; move32(); } symbol = lookup_fn( cum, range, cum_freq ); high = L_add( low, mul_sbc_14bits( range, cum_freq[symbol] ) ); - low = L_add( low, mul_sbc_14bits( range, cum_freq[symbol + 1] ) ); + low = L_add( low, mul_sbc_14bits( range, cum_freq[add(symbol, 1)] ) ); FOR( i = 0; i < 0x7FFF; i++ ) { @@ -296,8 +296,8 @@ static Word16 ari_decode_14bits_ext_fx( { BREAK; } - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC ); - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB ); + assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC) ); + assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB) ); low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); low = L_shl( low, 1 ); high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); @@ -376,7 +376,7 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) { highlim = testval; move16(); - pows[k] = mult_r( pows[k - 1], pows[k - 1] ); + pows[k] = mult_r( pows[sub(k, 1)], pows[sub(k, 1)] ); move16(); testval = mult_r( pows[k], base ); @@ -389,7 +389,7 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) BREAK; } } - assert( k < 12 ); /* maximum 2^10-1*/ + assert( LT_16(k, 12) ); /* maximum 2^10-1*/ /* narrow the range down */ FOR( k = sub( k, 2 ); k >= 0; k-- ) @@ -479,8 +479,8 @@ static Word16 ari_decode_14bits_notbl_fx( { BREAK; } - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0CCC ); - assert( tab_ari_qnew[L_msb_high][L_msb_low] != 0x0BBB ); + assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC) ); + assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB) ); low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); low = L_shl( low, 1 ); high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index 0cf43fd5d..bcbbdd341 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -81,37 +81,37 @@ int16_t DecodeIndex( #ifdef IVAS_FLOAT_FIXED Word16 DecodeIndex_fx( - Decoder_State *st, - const Word16 Bandwidth, - Word16 *PeriodicityIndex ) + Decoder_State *st, + const Word16 Bandwidth, + Word16 *PeriodicityIndex) { - TCX_LTP_DEC_HANDLE hTcxLtpDec; - TCX_DEC_HANDLE hTcxDec; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; - hTcxLtpDec = st->hTcxLtpDec; - hTcxDec = st->hTcxDec; + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; - test(); - IF( ( hTcxDec->tcx_hm_LtpPitchLag > 0 ) && GT_16( hTcxLtpDec->tcxltp_gain, kLtpHmGainThr ) ) - { - Word16 LtpPitchIndex = sub( mult_r( hTcxDec->tcx_hm_LtpPitchLag, 1 << ( 15 - kLtpHmFractionalResolution ) ), 2 ); + test(); + IF(GT_16(hTcxDec->tcx_hm_LtpPitchLag, 0) && GT_16(hTcxLtpDec->tcxltp_gain, kLtpHmGainThr)) + { + Word16 LtpPitchIndex = sub(mult_r(hTcxDec->tcx_hm_LtpPitchLag, shl(1, sub(15, kLtpHmFractionalResolution))), 2); - *PeriodicityIndex = kLtpHmFlag; - move16(); - *PeriodicityIndex = s_or( *PeriodicityIndex, get_next_indice_fx( st, NumRatioBits[Bandwidth][LtpPitchIndex] ) ); - *PeriodicityIndex = add( *PeriodicityIndex, 1 ); - move16(); - *PeriodicityIndex = s_or( *PeriodicityIndex, shl( LtpPitchIndex, 9 ) ); - move16(); + *PeriodicityIndex = kLtpHmFlag; + move16(); + *PeriodicityIndex = s_or(*PeriodicityIndex, get_next_indice_fx(st, NumRatioBits[Bandwidth][LtpPitchIndex])); + *PeriodicityIndex = add(*PeriodicityIndex, 1); + move16(); + *PeriodicityIndex = s_or(*PeriodicityIndex, shl(LtpPitchIndex, 9)); + move16(); - return NumRatioBits[Bandwidth][LtpPitchIndex]; - } - ELSE - { - *PeriodicityIndex = get_next_indice_fx( st, 8 ); - move16(); - return 8; - } + return NumRatioBits[Bandwidth][LtpPitchIndex]; + } + ELSE + { + *PeriodicityIndex = get_next_indice_fx(st, 8); + move16(); + return 8; + } } #endif @@ -120,7 +120,7 @@ DecodeIndex_fx( * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED static int16_t tcx_hm_dequantize_gain( const int16_t coder_type, /* i : GC/VC coder type */ const int16_t gain_idx, /* i : quantization index */ @@ -132,28 +132,28 @@ static int16_t tcx_hm_dequantize_gain( /* safety check in case of bit errors */ if ( !( 0 <= gain_idx && gain_idx < ( 1 << kTcxHmNumGainBits ) ) ) { - *gain = 0; + *gain = 0; move16(); return 1; } - *gain = qGains[coder_type][gain_idx]; + *gain = qGains[coder_type][gain_idx]; move16(); return 0; } - +#else static Word16 tcx_hm_dequantize_gain_fx( - Word16 coder_type, /* i : coder type Q0 */ - Word16 gain_idx, /* i: quantization index Q0 */ - Word16 *gain /* o: dequantized gain Q11 */ + Word16 coder_type, /* i : coder type Q0 */ + Word16 gain_idx, /* i: quantization index Q0 */ + Word16 *gain /* o: dequantized gain Q11 */ ) { - assert( 0 <= coder_type && coder_type <= UNVOICED ); + assert(0 <= coder_type && coder_type <= UNVOICED); /* safety check in case of bit errors */ test(); - IF( !( 0 <= gain_idx && LT_16( gain_idx, ( 1 << kTcxHmNumGainBits ) ) ) ) + IF(!(LE_16(0, gain_idx) && LT_16(gain_idx, shl(1, kTcxHmNumGainBits)))) { *gain = 0; return 1; @@ -164,14 +164,14 @@ static Word16 tcx_hm_dequantize_gain_fx( return 0; } - +#endif /*-------------------------------------------------------------------* * tcx_hm_decode_ivas() * * *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void tcx_hm_decode_ivas( const int16_t L_frame, /* i : number of spectral lines */ Word32 env[], /* i/o: envelope shape (Q16) */ @@ -228,7 +228,7 @@ void tcx_hm_decode_ivas( return; } - +#else void tcx_hm_decode( const Word16 L_frame, /* i : number of spectral lines */ Word32 env[], /* i/o: envelope shape (Q16) */ @@ -250,10 +250,10 @@ void tcx_hm_decode( *hm_bits = 0; move16(); - L_frame_m_256 = sub( L_frame, 256 ); + L_frame_m_256 = sub(L_frame, 256); test(); - IF( !( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) ) + IF(!(EQ_16(coder_type, VOICED) || EQ_16(coder_type, GENERIC))) { /* A bit error was encountered */ *hm_bits = -1; @@ -261,27 +261,27 @@ void tcx_hm_decode( return; } - NumTargetBits = CountIndexBits_fx( ( L_frame_m_256 >= 0 ), prm_hm[1] ); + NumTargetBits = CountIndexBits_fx((L_frame_m_256 >= 0), prm_hm[1]); - NumTargetBits = add( NumTargetBits, targetBits ); + NumTargetBits = add(NumTargetBits, targetBits); - if ( EQ_16( coder_type, VOICED ) ) + IF (EQ_16(coder_type, VOICED)) { - NumTargetBits = add( NumTargetBits, kTcxHmNumGainBits ); + NumTargetBits = add(NumTargetBits, kTcxHmNumGainBits); } - *hm_bits = add( sub( NumTargetBits, targetBits ), 1 ); + *hm_bits = add(sub(NumTargetBits, targetBits), 1); move16(); /* Convert the index to lag */ - UnmapIndex_fx( prm_hm[1], ( L_frame_m_256 >= 0 ), LtpPitchLag, - ( ( LE_16( NumTargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( L_frame_m_256 < 0 ) ), - &fract_res, &lag ); + UnmapIndex_fx(prm_hm[1], (L_frame_m_256 >= 0), LtpPitchLag, + ((LE_16(NumTargetBits, kSmallerLagsTargetBitsThreshold)) || (L_frame_m_256 < 0)), + &fract_res, &lag); test(); test(); /* Render the harmonic model */ - IF( tcx_hm_render_fx( lag, fract_res, p ) ) + IF(tcx_hm_render_fx(lag, fract_res, p)) { /* A bit error was encountered */ *hm_bits = -1; @@ -290,15 +290,16 @@ void tcx_hm_decode( } /* Dequantize gain */ - IF( tcx_hm_dequantize_gain_fx( (Word16) EQ_16( coder_type, VOICED ), prm_hm[2], &gain ) ) + IF(tcx_hm_dequantize_gain_fx((Word16)EQ_16(coder_type, VOICED), prm_hm[2], &gain)) { /* A bit error was encountered */ - *hm_bits = -1; + *hm_bits = -1; move16(); return; } - tcx_hm_modify_envelope_fx( gain, lag, fract_res, p, env, L_frame ); + tcx_hm_modify_envelope_fx(gain, lag, fract_res, p, env, L_frame); return; } +#endif \ No newline at end of file diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index ee19c765d..5e475806b 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -134,19 +134,19 @@ static Word16 tcx_arith_decode_ivas_fx( Tastat as; UWord16 exp_k; Word16 tmp; - // Word32 L_tmp; + //Word32 L_tmp; bp = ari_start_decoding_14bits_prm_ivas_fx( prm, 0, &as ); - tmp = sub( envelope_e, 1 ); + tmp = sub(envelope_e, 1); - // L_tmp = L_deposit_l(0); + //L_tmp = L_deposit_l(0); - FOR( k = 0; k < L_frame; k++ ) + FOR (k = 0; k < L_frame; k++) { - IF( envelope[k] == 0 ) /* safety check in case of bit errors */ + IF( EQ_16(envelope[k], 0 )) /* safety check in case of bit errors */ { - set32_fx( q_spectrum, 0, L_frame ); + set32_fx(q_spectrum, 0, L_frame); return -1; } ELSE @@ -157,33 +157,33 @@ static Word16 tcx_arith_decode_ivas_fx( /* decode line magnitude */ bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k ); - IF( q != 0 ) + IF ( NE_16(q, 0 )) { /* line is non-zero, decode sign */ bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); - q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) ); - q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); + q_spectrum[k] = L_mult(q, sub(3, shl(s, 1))); + q_spectrum[k] = L_shl(q_spectrum[k], 30 - SPEC_EXP_DEC); } ELSE { /* line is zero, no sign needed */ - q_spectrum[k] = L_deposit_l( 0 ); + q_spectrum[k] = L_deposit_l(0); } - IF( LE_32( as.high, as.low ) ) + IF (LE_32(as.high, as.low)) { - IF( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ + IF ( LT_16(bp, target_bits) ) /* safety check in case of bit errors */ { bp = -1; move16(); } - BREAK; /* no bits left, so exit loop */ + BREAK; /* no bits left, so exit loop */ } } *q_spectrum_e = SPEC_EXP_DEC; move16(); - set32_fx( q_spectrum + k, 0, sub( L_frame, k ) ); + set32_fx(q_spectrum + k, 0, sub(L_frame, k)); return bp; } @@ -242,7 +242,7 @@ void tcx_arith_decode_envelope( gamma_uw = 1.0f / st->gamma_float; #define WMC_TOOL_SKIP - tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); + tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); #undef WMC_TOOL_SKIP if ( use_hm ) @@ -321,11 +321,12 @@ void tcx_arith_decode_envelope_ivas_fx( TCX_DEC_HANDLE hTcxDec; Word16 gamma_w, gamma_uw; Word16 hm_bits; - - 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 ) ) + + test();test();test();test();test();test(); + 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)))) || + (LE_16(target_bits, 0))) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -343,7 +344,7 @@ void tcx_arith_decode_envelope_ivas_fx( hTcxCfg = st->hTcxCfg; hTcxDec = st->hTcxDec; - *signaling_bits = 0; + *signaling_bits = 0; move16(); assert( hTcxDec->enableTcxLpc ); gamma_w = MAX16B; @@ -355,13 +356,13 @@ void tcx_arith_decode_envelope_ivas_fx( tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); #undef WMC_TOOL_SKIP - IF( use_hm != 0 ) + IF (NE_16(use_hm, 0)) { - IF( prm_hm[0] != 0 ) + IF (NE_16(prm_hm[0], 0)) { - tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); + tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF( hm_bits < 0 ) + IF (LT_16(hm_bits, 0)) { st->BER_detect = 1; move16(); @@ -379,13 +380,13 @@ void tcx_arith_decode_envelope_ivas_fx( hm_bits = 1; move16(); } - *signaling_bits = add( *signaling_bits, hm_bits ); + *signaling_bits = add(*signaling_bits, hm_bits); move16(); } L_spec_core = L_spec; move16(); - if ( st->igf ) + IF ( st->igf ) { L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); } @@ -397,14 +398,14 @@ void tcx_arith_decode_envelope_ivas_fx( move16(); /* safety check in case of bit errors */ - IF( *arith_bits < 0 ) + IF ( LT_16(*arith_bits, 0 )) { st->BER_detect = 1; move16(); set32_fx( q_spectrum, 0, L_frame ); } - set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); + set32_fx(q_spectrum + L_spec, 0, sub(L_frame, L_spec)); return; } diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index b338cc3e0..d47a01cd5 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -29,8 +29,8 @@ static Word16 tcx_arith_decode_fx( Word16 tmp; Word32 L_tmp, Q; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; - Flag Carry = 0; + Flag Overflow = 0; move32(); + Flag Carry = 0; move32(); #endif @@ -40,7 +40,7 @@ static Word16 tcx_arith_decode_fx( L_tmp = L_deposit_l( 0 ); FOR( k = 0; k < L_frame; k++ ) { - IF( envelope[k] == 0 ) /* safety check in case of bit errors */ + IF( EQ_16(envelope[k], 0 )) /* safety check in case of bit errors */ { set32_fx( q_spectrum, 0, L_frame ); return -1; @@ -52,11 +52,11 @@ static Word16 tcx_arith_decode_fx( /* decode line magnitude */ bp = ari_decode_14bits_pow_fx( prm, bp, target_bits, &q, &as, exp_k ); - if ( q == 0 ) + IF ( EQ_16(q, 0 )) { q_spectrum[k] = L_deposit_l( 0 ); } - IF( q != 0 ) /* line is non-zero, decode sign */ + IF( NE_16(q, 0 )) /* line is non-zero, decode sign */ { bp = ari_decode_14bits_sign_fx( prm, bp, target_bits, &s, &as ); @@ -66,16 +66,16 @@ static Word16 tcx_arith_decode_fx( L_tmp = L_macNs( L_tmp, q, k ); #endif - Q = L_mult( q, -( 1 << ( 30 - SPEC_EXP_DEC ) ) ); - if ( s == 0 ) - Q = L_mult( q, 1 << ( 30 - SPEC_EXP_DEC ) ); + Q = L_mult( q, negate(shl( 1, sub( 30, SPEC_EXP_DEC ) ) )); + IF ( EQ_16(s, 0 )) + Q = L_mult( q, shl(1, sub( 30, SPEC_EXP_DEC ) )); q_spectrum[k] = Q; move32(); } IF( ari_decode_overflow_fx( &as ) ) { - if ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ + IF ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ { bp = -1; move16(); @@ -125,13 +125,11 @@ void tcx_arith_decode_envelope_fx( Word16 hm_bits; tcx_cfg = st->hTcxCfg; - test(); - test(); - + test(); test(); test(); test(); test(); test(); test(); 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 ) ) + LE_16( target_bits, 0 ) ) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -159,13 +157,13 @@ void tcx_arith_decode_envelope_fx( tcx_arith_render_envelope( A_ind, L_frame, L_spec, tcx_cfg->preemph_fac, gamma_w, gamma_uw, env ); - IF( use_hm != 0 ) + IF( NE_16(use_hm, 0 )) { - IF( prm_hm[0] != 0 ) + IF( NE_16(prm_hm[0], 0 )) { tcx_hm_decode( L_spec, env, target_bits, tcx_cfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF( hm_bits < 0 ) + IF( LT_16(hm_bits, 0 )) { st->BER_detect = 1; move16(); @@ -193,7 +191,7 @@ void tcx_arith_decode_envelope_fx( L_spec_core = L_spec; move16(); - if ( st->igf ) + IF ( st->igf ) { L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); } @@ -205,7 +203,7 @@ void tcx_arith_decode_envelope_fx( move16(); /* safety check in case of bit errors */ - IF( *arith_bits < 0 ) + IF( LT_16(*arith_bits, 0 )) { st->BER_detect = 1; move16(); diff --git a/lib_dec/avq_dec.c b/lib_dec/avq_dec.c index c92a899d9..b0eef6b2f 100644 --- a/lib_dec/avq_dec.c +++ b/lib_dec/avq_dec.c @@ -285,7 +285,6 @@ void AVQ_demuxdec( return; } -#endif /*-----------------------------------------------------------------* * AVQ_dec_lpc_ivas() @@ -373,7 +372,7 @@ void AVQ_dec_lpc_ivas( * read codebook indices (rank I and event. Voronoi index kv) *-----------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void read_cv( Decoder_State *st, /* i/o: decoder state structure */ uint16_t *I, /* o : rank I code book index */ diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index e768e1ffd..c40ee51b2 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -79,30 +79,32 @@ void AVQ_demuxdec_fx( { move16(); svOrder[i] = j; - i++; - j++; + i = add(1, i); + j = add(1, j); } FOR( i = 0; i < NSV_MAX; i++ ) { - I[i] = (UWord16) -1; + I[i] = (UWord16) -1; move16(); } FOR( i = 0; i < Nsv; i++ ) { - k = svOrder[i]; + k = svOrder[i]; move16(); + test(); test(); test(); test(); test(); IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( ( bits % 5 ), 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, sub( Nsv, 1 ) ) ) { ordr_esti( Nsv - i, &trgtSvPos, &svOrder[i], Nsv ); - k = svOrder[i]; - avq_bit_sFlag = 1; + k = svOrder[i]; move16(); + avq_bit_sFlag = 1; move16(); } - + test(); IF( EQ_16( k, trgtSvPos ) && GT_16( avq_bit_sFlag, 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; + avq_bit_sFlag = 0; move16(); } ELSE { @@ -110,15 +112,15 @@ void AVQ_demuxdec_fx( } } - nq[k] = 0; /* initialization and also forced if the budget is exceeded */ + nq[k] = 0; move16(); /* initialization and also forced if the budget is exceeded */ IF( GT_16( bits, 8 ) ) { /* read the unary code including the stop bit for nq[i] */ - nq[k] = -1; + nq[k] = -1; move16(); DO { - ( nq[k] )++; + nq[k] = add(nq[k], 1); // IF ( 5 * nq[k] + 4 == bits ) IF( EQ_16( add( add( shl( nq[k], 2 ), nq[k] ), 4 ), bits ) ) @@ -163,50 +165,51 @@ void AVQ_demuxdec_fx( IF( GT_16( avq_bit_sFlag, 0 ) && GT_16( bits, 8 ) ) { i = svOrder[Nsv - 1]; - nq[i] = 0; + nq[i] = 0; move16(); bitsMod = bits % 5; IF( NE_16( i, sub( Nsv, 1 ) ) ) { - nullVec = 0; - FOR( j = i; j < Nsv - 1; j++ ) + nullVec = 0; move16(); + FOR( j = i; j < sub(Nsv, 1); j++ ) { IF( EQ_16( nq[svOrder[j]], 0 ) ) { nullVec = add( nullVec, 1 ); } } - nq_est = bits / 5; - IF( ( GT_16( 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 ) ) ) && EQ_16( nq[svOrder[Nsv - 2]], 0 ) ) /* dummy bits */ + nq_est = idiv1616(bits, 5); + test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); + IF( ( GT_16( 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 ) ) ) && EQ_16( nq[svOrder[sub(Nsv, 2)]], 0 ) ) /* dummy bits */ { dummy_bits = sub( 5, bitsMod ); bits = add( bits, dummy_bits ); /* add dummy bits */ - bitsMod = 0; + bitsMod = 0; move16(); } - ELSE IF( GT_16( nq_est, 4 ) && ( ( EQ_16( bitsMod, 0 ) && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && EQ_16( nq[svOrder[Nsv - 2]], 0 ) ) /* wasted bits 4, 5 for nq 6,7..*/ + ELSE IF( GT_16( nq_est, 4 ) && ( ( EQ_16( bitsMod, 0 ) && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && EQ_16( nq[svOrder[sub(Nsv, 2)]], 0 ) ) /* wasted bits 4, 5 for nq 6,7..*/ { - underflow = 0; + underflow = 0; move16(); IF( NE_16( ( add( bitsMod, nullVec ) % 5 ), 0 ) ) { - underflow = 1; + underflow = 1; move16(); } dummy_bits = add( nullVec, underflow ); bits = add( bits, dummy_bits ); /* add dummy bits */ - bitsMod = 0; + bitsMod = 0; move16(); } } - underflow = 1; + underflow = 1; move16(); IF( NE_16( bitsMod, 4 ) ) { - underflow = 0; + underflow = 0; move16(); bits = sub( bits, bitsMod ); } bits = add( bits, underflow ); /* read the unary code for unused bit*/ - unused_bits_idx = -1; + unused_bits_idx = -1; move16(); DO { - ( unused_bits_idx )++; + unused_bits_idx = add(unused_bits_idx, 1); IF( EQ_16( add( add( shl( unused_bits_idx, 2 ), unused_bits_idx ), 4 ), sub( bits, 1 ) ) ) { BREAK; @@ -214,28 +217,35 @@ void AVQ_demuxdec_fx( } WHILE( get_next_indice_1( st ) ); - unusedbitsFlag = 0; + unusedbitsFlag = 0; move16(); IF( EQ_16( dummy_bits, 0 ) ) { + test(); test(); test(); test(); IF( EQ_16( unused_bits_idx, 0 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) { - unusedbitsFlag = 1; + unusedbitsFlag = 1; move16(); } ELSE IF( EQ_16( unused_bits_idx, 1 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) { - unusedbitsFlag = -1; + unusedbitsFlag = -1; move16(); } } /*Compute AVQ code book number from unused Bits */ tmp = (Word16) ( sub( bits, add( add( shl( add( unusedbitsFlag, unused_bits_idx ), 2 ), unusedbitsFlag ), unused_bits_idx ) ) ); - nq_est = tmp / 5; - nq_est = EQ_16( ( tmp % 5 ), 0 ) ? nq_est : add( nq_est, 1 ); - + nq_est = idiv1616(tmp, 5); + IF(EQ_16( ( tmp % 5 ), 0 )) + { + nq_est = nq_est; move16(); + } + ELSE + { + nq_est = add( nq_est, 1 ); + } IF( EQ_16( nq_est, 1 ) ) { - nq_est = 0; + nq_est = 0; move16(); } bits = sub( bits, underflow ); @@ -246,9 +256,9 @@ void AVQ_demuxdec_fx( bits = sub( bits, 1 ); } - nq[i] = nq_est; + nq[i] = nq_est; move16(); /* read codebook indices (rank I and event. Voronoi index kv) */ - read_cv_fx( st, &I[i], &kv[i * 8], nq[i], &bits ); + read_cv_fx( st, &I[i], &kv[shl(i, 3)], nq[i], &bits ); bits = sub( bits, dummy_bits ); @@ -270,7 +280,7 @@ void AVQ_demuxdec_fx( xriq[add( shl( i, 3 ), j )] = code[j]; } } - + move16(); *nb_bits = bits; return; @@ -306,7 +316,7 @@ void AVQ_dec_lpc( /* decode all subvectors */ - FOR( l = Nsv - 1; l >= 0; l-- ) + FOR( l = sub(Nsv, 1); l >= 0; l-- ) { nq = indx[l]; /* quantizer number (0,2,3..n) */ move16(); @@ -361,7 +371,7 @@ void AVQ_dec_lpc( /* write decoded RE8 vector */ FOR( i = 0; i < 8; i++ ) { - nvecq[( l * 8 ) + i] = c[i]; + nvecq[add(shl( l, 3 ), i)] = c[i]; move16(); } } @@ -389,7 +399,7 @@ static void read_cv_fx( Word16 j, bits, order_v; bits = *nbits; - + move16(); /* read codebook indices (rank I and event. Voronoi index kv) */ IF( EQ_16( nq, 0 ) ) /* Q0 */ { @@ -397,13 +407,13 @@ static void read_cv_fx( } ELSE IF( LT_16( nq, 5 ) ) /* Q2, Q3, Q4 */ { - *I = get_next_indice( st, 4 * nq ); + *I = get_next_indice( st, shl(nq, 2) ); bits = sub( bits, shl( nq, 2 ) ); } ELSE IF( EQ_16( s_and( nq, 1 ), 0 ) ) /* Q4 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 4 * 4 ); - bits = sub( bits, 4 * 4 ); + *I = get_next_indice( st, 16); + bits = sub( bits, 16 ); order_v = (Word16) sub( shr( nq, 1 ), 2 ); FOR( j = 0; j < 8; j++ ) @@ -414,8 +424,8 @@ static void read_cv_fx( } ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 4 * 3 ); - bits = sub( bits, 4 * 3 ); + *I = get_next_indice( st, 12); + bits = sub( bits, 12); order_v = (Word16) sub( shr( nq, 1 ), 1 ); FOR( j = 0; j < 8; j++ ) diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index 48d136367..6b75fd1dd 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -537,12 +537,12 @@ void addBassPostFilter_ivas_fx( Word16 i, b; Word16 maxBand; const Word32 *weights_fx; - Word16 nCol = cldfb->no_col; - Word16 nColToProcess = nCol; - Word16 nChan = cldfb->no_channels; + Word16 nCol = cldfb->no_col; move16(); + Word16 nColToProcess = nCol; move16(); + Word16 nChan = cldfb->no_channels; move16(); IF( GT_16( samplesToProcess, -1 ) ) { - nColToProcess = ( ( samplesToProcess + cldfb->no_channels - 1 ) / cldfb->no_channels ); + nColToProcess = idiv1616( sub(add( samplesToProcess, cldfb->no_channels), 1 ), cldfb->no_channels ); move16(); } @@ -684,15 +684,15 @@ Word16 res_bpf_adapt_ivas_fx( IF( EQ_16( hStereoDft->res_cod_band_max, 6 ) ) { - i_start = 39; - i_end = 64; - bw_inv = 1311; /* 1/(64 - 39) in Q15 */ + i_start = 39; move16(); + i_end = 64; move16(); + bw_inv = 1311; move16(); /* 1/(64 - 39) in Q15 */ } ELSE { - i_start = 28; - i_end = 40; - bw_inv = 2720; /* 1/(40 - 28) in Q15*/ + i_start = 28; move16(); + i_end = 40; move16(); + bw_inv = 2720; move16(); /* 1/(40 - 28) in Q15*/ } /* Measure energy of high frequency band in MDCT domain */ @@ -713,21 +713,29 @@ Word16 res_bpf_adapt_ivas_fx( res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) ); - hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; + hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; move32(); /* Measure energy of discontinuities at subframe boundaries */ - error_nrg = 0; + error_nrg = 0; move32(); FOR( i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k ) { tmp = L_sub( bpf_error_signal_8k[i], hStereoDft->bpf_error_signal_last_fx ); error_nrg = Madd_32_32( error_nrg, tmp, tmp ); - hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[i + STEREO_DFT_L_SUBFR_8k - 1]; + hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[add(i, sub(STEREO_DFT_L_SUBFR_8k, 1))]; move32(); } error_nrg = L_shr( error_nrg, 1 ); // Q0 error_nrg = Mpy_32_16_1( error_nrg, 6553 /* 0.2f in Q15 */ ); /* Division by 5 for average value */ - bpf_error_ratio = LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg ) ? (Word16) ( L_shl( ( L_shl( error_nrg, Q5 ) / res_hb_nrg ), Q8 ) ) : shl( ONE_IN_Q12, 1 ); /* Form decision variable and apply limit */ + /* Form decision variable and apply limit */ + IF(LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg )) + { + bpf_error_ratio = (Word16)(L_shl((L_shl(error_nrg, Q5) / res_hb_nrg), Q8)); move16(); + } + ELSE + { + bpf_error_ratio = shl( ONE_IN_Q12, 1 ); + } bpf_error_ratio = add( mult( STEREO_DFT_BPF_ADAPT_BETA_FX, bpf_error_ratio ), mult( sub( MAX_16, STEREO_DFT_BPF_ADAPT_BETA_FX ), hStereoDft->bpf_error_ratio_mem_fx ) ); - hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio; + hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio; move16(); res_bpf_flag = (Word16) LT_16( bpf_error_ratio, ONE_IN_Q13 ); @@ -790,52 +798,52 @@ void bpf_pitch_coherence_ivas_fx( SWITCH( st->L_frame ) { case 80: - scaled_inv_L_frame = 26843545; + scaled_inv_L_frame = 26843545; move32(); BREAK; case 160: - scaled_inv_L_frame = 13421773; + scaled_inv_L_frame = 13421773; move32(); BREAK; case 256: - scaled_inv_L_frame = 8388608; + scaled_inv_L_frame = 8388608; move32(); BREAK; case 320: - scaled_inv_L_frame = 6710886; + scaled_inv_L_frame = 6710886; move32(); BREAK; case 512: - scaled_inv_L_frame = 4194304; + scaled_inv_L_frame = 4194304; move32(); BREAK; case 640: - scaled_inv_L_frame = 3355443; + scaled_inv_L_frame = 3355443; move32(); BREAK; case 960: - scaled_inv_L_frame = 2236962; + scaled_inv_L_frame = 2236962; move32(); BREAK; default: - scaled_inv_L_frame = 0; + scaled_inv_L_frame = 0; move32(); } nb_subfr = shr( st->L_frame, 6 ); - + test(); IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && NE_16( st->element_mode, EVS_MONO ) ) { - pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[nb_subfr + 1] ) ) ); + pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add(nb_subfr, 3)], st->old_pitch_buf_fx[add(nb_subfr, 2)] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[add(nb_subfr, 1)] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn1 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn1 = max( min( pcn1, 4096 ), 0 ); + pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); - pc = L_abs( L_sub( L_add( pitch_buf[nb_subfr - 1], pitch_buf[nb_subfr - 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); + pc = L_abs( L_sub( L_add( pitch_buf[sub(nb_subfr, 1)], pitch_buf[sub(nb_subfr, 2)] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn2 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn2 = max( min( pcn2, 4096 ), 0 ); + pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); - pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[nb_subfr + 3], st->old_pitch_buf_fx[nb_subfr + 2] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); + pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add(nb_subfr, 3)], st->old_pitch_buf_fx[add(nb_subfr, 2)] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn3 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); - pcn3 = max( min( pcn3, 4096 ), 0 ); + pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 ) ) { - st->hBPF->psf_att_fx = 13107; /*Q15*/ + st->hBPF->psf_att_fx = 13107; move16(); /*Q15*/ // st->hBPF->psf_att = 0.4f; set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 0c70d5b78..a6dae725f 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -45,7 +45,7 @@ void bass_psfilter_init_fx( set16_fx( hBPF->Track_on_hist, 0, L_TRACK_HIST ); set16_fx( hBPF->vibrato_hist, 0, L_TRACK_HIST ); set16_fx( hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST ); /* 80 in Q4*/ - hBPF->psf_att_fx = 32767; + hBPF->psf_att_fx = 32767; move16(); return; } @@ -157,7 +157,7 @@ void bass_psfilter_fx( { FOR( i = L_TRACK_HIST - 1; i > 0; i-- ) { - hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[i - 1]; + hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[sub(i, 1)]; move16(); /*Q6 */ } Ltmp = L_deposit_l( 0 ); @@ -168,7 +168,7 @@ void bass_psfilter_fx( tmp = round_fx( Ltmp ); /*Q4*/ /*tmp2 = div_s(1,nb_subfr); //Q15 */ tmp = mult_r( tmp, 8192 ); /*divide per 4 (when L_frame == L_FRAME) -> Q4*/ - if ( EQ_16( nb_subfr, 5 ) ) + IF ( EQ_16( nb_subfr, 5 ) ) { tmp = mult_r( tmp, 26214 ); /* multiply by 0.8 for case where L_frame == L_FRAME16k*/ } @@ -181,7 +181,7 @@ void bass_psfilter_fx( dist_pit_diff = abs_s( sub( idx_pit_max, idx_pit_min ) ); diff_pit = sub( loc_pit_max, loc_pit_min ); /*Q4 */ test(); - if ( EQ_16( L_frame, L_FRAME16k ) || EQ_16( L_frame, L_FRAME8k ) ) + IF ( EQ_16( L_frame, L_FRAME16k ) || EQ_16( L_frame, L_FRAME8k ) ) { diff_pit = mult_r( diff_pit, 26214 ); /*Q4 */ } @@ -189,7 +189,7 @@ void bass_psfilter_fx( test(); test(); test(); - if ( coder_type != INACTIVE && GE_16( diff_pit, 2 << 4 ) && LT_16( diff_pit, 10 << 4 ) && GE_16( dist_pit_diff, 3 ) ) + IF ( NE_16(coder_type, INACTIVE) && GE_16( diff_pit, shl(2, 4) ) && LT_16( diff_pit, shl(10, 4) ) && GE_16( dist_pit_diff, 3 ) ) { vibrato = 1; move16(); @@ -231,9 +231,9 @@ void bass_psfilter_fx( { /* do not use BPF for HQ core */ T_update = 80; - if ( EQ_16( L_frame, L_FRAME8k ) ) + IF ( EQ_16( L_frame, L_FRAME8k ) ) { - T_update = 40; + T_update = 40; move16(); } move16(); set16_fx( T_sf, 0, 5 ); @@ -293,14 +293,14 @@ void bass_psfilter_fx( syn_fx = &syn_buf_fx[add( nbpsf_pit_max, i_subfr )]; syn2_fx = &syn2_buf_fx[i_subfr]; - IF( T != 0 ) + IF( NE_16(T, 0 )) { test(); IF( GE_16( T, PIT_MIN ) && Opt_AMR_WB ) { T = Pit_track_fx( syn_fx, T ); - if ( NE_16( T, T_sf[subfr_pos] ) ) + IF ( NE_16( T, T_sf[subfr_pos] ) ) { Track_on = 1; move16(); @@ -364,14 +364,14 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF ( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ /* gain = corr / ener */ gain = div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ); - if ( Lcorr < 0 ) + IF ( LT_32(Lcorr, 0 )) { gain = sub( 0, gain ); } @@ -414,7 +414,7 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF ( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } @@ -425,7 +425,7 @@ void bass_psfilter_fx( #else alpha = shr( div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ), exp2 ); /*Q15 */ #endif - if ( Lcorr < 0 ) + IF ( LT_32(Lcorr, 0 )) { alpha = sub( 0, alpha ); } @@ -433,14 +433,14 @@ void bass_psfilter_fx( alpha = s_min( alpha, 16384 ); /*Q15 */ alpha = mult_r( alpha, hBPF->psf_att_fx ); - test(); - test(); + test(); test(); + test(); test(); IF( GT_16( alpha, 9830 ) && Track_on ) { alpha = 9830; move16(); } - ELSE if ( GT_16( alpha, 13107 ) && vibrato ) + ELSE IF ( GT_16( alpha, 13107 ) && vibrato ) { alpha = 13107; move16(); @@ -495,14 +495,14 @@ void bass_psfilter_fx( Lener = L_mac0( Lener, err[i], err[i] ); #endif } - exp2 = -1 - 2; + exp2 = sub(-1, 2); move16(); /* 'Lener' is divided by 2 */ IF( EQ_32( Lener, 2147483647L ) ) { Lener = L_deposit_h( -32768 ); - sigPtr = err + subfr_len / 2; - FOR( i = 0; i < subfr_len / 2; i++ ) + sigPtr = err + shr(subfr_len, 1); + FOR( i = 0; i < shr(subfr_len, 1); i++ ) { Lener0 = L_mult0( sigPtr[i], sigPtr[i] ); #ifdef BASOP_NOGLOB @@ -544,7 +544,7 @@ void bass_psfilter_fx( Track_on = 0; move16(); - if ( EQ_16( coder_type, AUDIO ) ) /* GSC mode without temporal component */ + IF ( EQ_16( coder_type, AUDIO ) ) /* GSC mode without temporal component */ { Track_on = 1; move16(); @@ -597,14 +597,14 @@ void bass_psfilter_fx( exp2 = norm_l( Lener ); tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF ( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ /* gain = corr / ener */ gain = div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ); - if ( Lcorr < 0 ) + IF ( LT_32(Lcorr, 0 )) { gain = sub( 0, gain ); } @@ -643,7 +643,7 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - if ( GT_16( tmp, tmp2 ) ) + IF ( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } @@ -680,14 +680,14 @@ void bass_psfilter_fx( Lener = L_mac0( Lener, err[i], err[i] ); #endif } - exp2 = -1 - 2; + exp2 = sub(-1, 2); move16(); /* 'Lener' is divided by 2 */ IF( EQ_32( Lener, 2147483647L ) ) { Lener = L_deposit_h( -32768 ); - sigPtr = err + subfr_len / 2; - FOR( i = 0; i < subfr_len / 2; i++ ) + sigPtr = err + shr(subfr_len, 1); + FOR( i = 0; i < shr(subfr_len, 1); i++ ) { Lener0 = L_mult0( sigPtr[i], sigPtr[i] ); #ifdef BASOP_NOGLOB @@ -725,11 +725,11 @@ void bass_psfilter_fx( * update memory for next frame *-------------------------------------------------------*/ - FOR( i = L_TRACK_HIST - 1; i > 0; i-- ) + FOR( i = sub(L_TRACK_HIST, 1); i > 0; i-- ) { - hBPF->Track_on_hist[i] = hBPF->Track_on_hist[i - 1]; + hBPF->Track_on_hist[i] = hBPF->Track_on_hist[sub(i, 1)]; move16(); - hBPF->vibrato_hist[i] = hBPF->vibrato_hist[i - 1]; + hBPF->vibrato_hist[i] = hBPF->vibrato_hist[sub(i, 1)]; move16(); } @@ -797,7 +797,7 @@ static Word16 Pit_track_fx( /* o : Pitch Lener0 = L_mult0( *v1, *v1 ); Ltmp0 = L_mult0( *v2, *v2 ); Lcorr0 = L_mult0( *v1++, *v2++ ); - FOR( i = 1; i < ( L_HALFR16k + NBPSF_L_EXTRA ) / 14; i++ ) + FOR( i = 1; i < idiv1616(add( L_HALFR16k, NBPSF_L_EXTRA ), 14); i++ ) { #ifdef BASOP_NOGLOB Lener0 = L_mac0_sat( Lener0, *v1, *v1 ); @@ -815,7 +815,7 @@ static Word16 Pit_track_fx( /* o : Pitch test(); IF( EQ_32( Lener0, 2147483647L ) || EQ_32( Ltmp0, 2147483647L ) || - EQ_32( Lcorr0, 2147483647L ) || EQ_32( Lcorr0, -2147483647 - 1L ) ) + EQ_32( Lcorr0, 2147483647L ) || EQ_32( Lcorr0, L_add(-2147483647, - 1L) ) ) { v1 -= i; move16(); @@ -860,7 +860,7 @@ static Word16 Pit_track_fx( /* o : Pitch /* Call the Integer Square Root (it will normalize again if req.) */ Ltmp = Isqrt( Ltmp ); /* We now do corr * 1 / sqrt(1/product) with high part of ratio only */ - exp1 = mac_r( ( 16 - 1 ) * 65536L - 0x8000L, exp1, 16384 ); + exp1 = mac_r(950272, exp1, 16384 ); /*( 16 - 1 ) * 65536L - 0x8000L*/ exp2 = norm_l( Ltmp ); Ltmp = L_shl( Ltmp, exp2 ); exp1 = sub( exp1, exp2 ); @@ -875,7 +875,7 @@ static Word16 Pit_track_fx( /* o : Pitch Ltmp = L_shl( Ltmp, exp1 ); #endif /* cn = normalized correlation of pitch/2 */ - if ( GT_32( Ltmp, 2040109466L ) ) /* 0.95f in Q31 */ + IF ( GT_32( Ltmp, 2040109466L ) ) /* 0.95f in Q31 */ { T = T2; move16(); @@ -943,7 +943,7 @@ void addBassPostFilter_fx( /* now do the subtraction */ - IF( nTimeSlots > 0 ) + IF( GT_16(nTimeSlots, 0 )) { /* Find common scale. */ b = s_max( cldfb_scale->lb_scale, scale.lb_scale ); diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index d75b598f2..e581bed9d 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -50,9 +50,9 @@ void CNG_dec_fx( Word16 num_bits; Word16 weights, ptr, j, k; Word16 m1; - Word16 m = 0; + Word16 m = 0; move16(); Word16 tmp[HO_HIST_SIZE * M]; - Word16 burst_ho_cnt = 0; + Word16 burst_ho_cnt = 0; move16(); Word16 ll, s_ptr; Word32 L_enr, L_tmp1; Word16 tmp1, exp; @@ -93,16 +93,16 @@ void CNG_dec_fx( IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* de-quantize the LSF vector */ - IF( st_fx->Opt_AMR_WB != 0 ) + IF( NE_16(st_fx->Opt_AMR_WB, 0 )) { /* Flt function */ isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); - /* 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 ); + enr_new = Enr_1_Az_fx( Aq_tmp, shl(L_SUBFR, 1) ); - IF( ( shr( enr_new, 14 ) > 0 ) ) + IF( GT_16( shr( enr_new, 14 ), 0 ) ) { /* Use old LSP vector */ Copy( st_fx->lsp_old_fx, lsp_new, M ); @@ -117,12 +117,12 @@ void CNG_dec_fx( NULL #endif ); - /* check if LSPs may trigger too much synthesis energy */ + /* 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 ); + enr_new = Enr_1_Az_fx( Aq_tmp, shl(L_SUBFR, 1)); - IF( shr( enr_new, 14 ) > 0 ) + IF( GT_16(shr( enr_new, 14 ), 0 )) { /* Use old LSP vector */ Copy( st_fx->lsp_old_fx, lsp_new, M ); @@ -138,7 +138,7 @@ void CNG_dec_fx( } /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( st_fx->first_CNG == 0 ) + IF( EQ_16(st_fx->first_CNG, 0 )) { Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); } @@ -154,7 +154,7 @@ void CNG_dec_fx( { istep = ISTEP_AMR_WB_SID_FX; move16(); - if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF ( EQ_32( st_fx->core_brate, SID_2k40 ) ) { istep = ISTEP_SID_FX; move16(); @@ -163,7 +163,7 @@ void CNG_dec_fx( /* initialize the energy quantization parameters */ num_bits = 6; move16(); - if ( st_fx->Opt_AMR_WB == 0 ) + IF ( EQ_16(st_fx->Opt_AMR_WB, 0 )) { num_bits = 7; move16(); @@ -180,12 +180,12 @@ void CNG_dec_fx( { tmp1 = add( hTdCngDec->old_enr_index, 40 ); } - IF( GT_16( L_enr_index, tmp1 ) && hTdCngDec->old_enr_index >= 0 ) /* Likely bit error and not startup */ + IF( GT_16( L_enr_index, tmp1 ) && GE_16(hTdCngDec->old_enr_index, 0 )) /* Likely bit error and not startup */ { L_enr_index = tmp1; move16(); L_enr_index = s_min( L_enr_index, 127 ); - if ( st_fx->Opt_AMR_WB != 0 ) + IF ( NE_16(st_fx->Opt_AMR_WB, 0 )) { L_enr_index = s_min( L_enr_index, 63 ); } @@ -195,8 +195,8 @@ void CNG_dec_fx( test(); test(); IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && - st_fx->first_CNG != 0 && - hTdCngDec->old_enr_index >= 0 && + NE_16(st_fx->first_CNG, 0) && + GE_16(hTdCngDec->old_enr_index, 0) && GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) { *allow_cn_step = 1; @@ -205,7 +205,7 @@ void CNG_dec_fx( hTdCngDec->old_enr_index = L_enr_index; move16(); - if ( L_enr_index == 0 ) + IF ( EQ_16(L_enr_index, 0 )) { L_enr_index = -5; move16(); @@ -226,7 +226,7 @@ void CNG_dec_fx( burst_ho_cnt = get_next_indice( st_fx, 3 ); /* 3bit */ *sid_bw = get_next_indice( st_fx, 1 ); - IF( *sid_bw == 0 ) + IF( EQ_16(*sid_bw, 0 )) { env_idx[0] = get_next_indice( st_fx, 6 ); move16(); @@ -238,10 +238,10 @@ void CNG_dec_fx( } } } - /* Reset CNG history if CNG frame length is changed */ + /* Reset CNG history IF CNG frame length is changed */ test(); test(); - IF( EQ_16( st_fx->bwidth, WB ) && st_fx->first_CNG != 0 && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) + IF( EQ_16( st_fx->bwidth, WB ) && NE_16(st_fx->first_CNG, 0) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) { hTdCngDec->ho_hist_size = 0; move16(); @@ -255,29 +255,29 @@ void CNG_dec_fx( test(); test(); test(); - IF( st_fx->last_core_brate <= SID_2k40 ) + IF( LE_32(st_fx->last_core_brate, SID_2k40 )) { - /* Reset hangover counter if not first SID period */ - if ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) + /* Reset hangover counter IF not first SID period */ + IF ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) { hTdCngDec->num_ho = 0; move16(); } - /* Update LSPs if last SID energy not outliers or insufficient number of hangover frames */ + /* Update LSPs IF last SID energy not outliers or insufficient number of hangover frames */ test(); IF( LT_16( hTdCngDec->num_ho, 3 ) || LT_32( Mult_32_16( hTdCngDec->Enew_fx, 21845 /*1/1.5f, Q15*/ ), st_fx->lp_ener_fx ) ) { FOR( i = 0; i < M; i++ ) { /* AR low-pass filter */ - st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 32768 - CNG_ISF_FACT_FX, lsp_new[i] ); + st_fx->lspCNG_fx[i] = mac_r( L_mult( CNG_ISF_FACT_FX, st_fx->lspCNG_fx[i] ), 3277, lsp_new[i] ); move16(); /* Q15 (15+15+1-16) */ } } } ELSE { - /* Update CNG_mode if allowed */ + /* Update CNG_mode IF allowed */ test(); test(); test(); @@ -301,7 +301,7 @@ void CNG_dec_fx( move16(); s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); move16(); - if ( s_ptr < 0 ) + IF ( LT_16(s_ptr, 0 )) { s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); } @@ -309,7 +309,7 @@ void CNG_dec_fx( FOR( ll = burst_ho_cnt; ll > 0; ll-- ) { hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + IF ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); @@ -322,31 +322,31 @@ void CNG_dec_fx( IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), st_fx->L_frame, 0 ); + lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[i_mult(s_ptr, M)] ), st_fx->L_frame, 0 ); } /* update the circular buffers */ - Copy( &( hTdCngDec->ho_lsp_circ_fx[s_ptr * M] ), &( hTdCngDec->ho_lsp_hist_fx[hTdCngDec->ho_hist_ptr * M] ), M ); + Copy( &( hTdCngDec->ho_lsp_circ_fx[i_mult(s_ptr, M)] ), &( hTdCngDec->ho_lsp_hist_fx[i_mult(hTdCngDec->ho_hist_ptr, M)] ), M ); Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - Copy32( &( hTdCngDec->ho_env_circ_fx[s_ptr * NUM_ENV_CNG] ), &( hTdCngDec->ho_env_hist_fx[hTdCngDec->ho_hist_ptr * NUM_ENV_CNG] ), NUM_ENV_CNG ); + Copy32( &( hTdCngDec->ho_env_circ_fx[i_mult(s_ptr, NUM_ENV_CNG)] ), &( hTdCngDec->ho_env_hist_fx[i_mult(hTdCngDec->ho_hist_ptr, NUM_ENV_CNG)] ), NUM_ENV_CNG ); hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + IF ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); } s_ptr = add( s_ptr, 1 ); - if ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) + IF ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) { s_ptr = 0; move16(); } } - IF( hTdCngDec->ho_hist_size > 0 ) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ + IF( GT_16(hTdCngDec->ho_hist_size, 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( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); @@ -354,7 +354,7 @@ void CNG_dec_fx( test(); test(); - if ( ( L_tmp1 > 0 && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) + IF ( ( GT_32(L_tmp1, 0) && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { *allow_cn_step = s_or( *allow_cn_step, 1 ); } @@ -365,17 +365,17 @@ void CNG_dec_fx( move16(); } test(); - IF( *allow_cn_step == 0 && hTdCngDec->ho_hist_size > 0 ) + IF( EQ_16(*allow_cn_step, 0) && GT_16(hTdCngDec->ho_hist_size, 0) ) { /* Use average of energies below last energy */ ptr = hTdCngDec->ho_hist_ptr; move16(); - Copy( &( hTdCngDec->ho_lsp_hist_fx[ptr * M] ), tmp, M ); + Copy( &( hTdCngDec->ho_lsp_hist_fx[i_mult(ptr, M)] ), tmp, M ); m1 = 0; move16(); - IF( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ) == 0 ) + IF( EQ_32(L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ), 0 )) { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[i_mult(ptr, NUM_ENV_CNG)], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } @@ -388,9 +388,9 @@ void CNG_dec_fx( FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) { ptr = sub( ptr, 1 ); - if ( ptr < 0 ) + IF (LT_16( ptr, 0 )) { - ptr = HO_HIST_SIZE - 1; + ptr = sub(HO_HIST_SIZE, 1); move16(); } @@ -405,10 +405,10 @@ void CNG_dec_fx( /*weights += W_DTX_HO[k];*/ weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - Copy( &hTdCngDec->ho_lsp_hist_fx[ptr * M], &tmp[m * M], M ); - IF( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ) == 0 ) + Copy( &hTdCngDec->ho_lsp_hist_fx[i_mult(ptr, M)], &tmp[i_mult(m, M)], M ); + IF( EQ_32(L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 )) { - Copy32( &hTdCngDec->ho_env_hist_fx[ptr * NUM_ENV_CNG], &tmp_env[m1 * NUM_ENV_CNG], NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[i_mult(ptr, NUM_ENV_CNG)], &tmp_env[i_mult(m1, NUM_ENV_CNG)], NUM_ENV_CNG ); m1 = add( m1, 1 ); } m = add( m, 1 ); @@ -419,7 +419,7 @@ void CNG_dec_fx( exp = norm_s( weights ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ L_tmp1 = Mult_32_16( L_enr, tmp1 ); /* Q(14-exp+6-15)->Q(5-exp) */ - L_enr = L_shl( L_tmp1, exp + 1 ); /* Q6 */ + L_enr = L_shl( L_tmp1, add(exp, 1) ); /* Q6 */ st_fx->lp_ener_fx = L_enr; /* Q6 */ @@ -430,26 +430,26 @@ void CNG_dec_fx( { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &tmp[i_mult(i, M)], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; move16(); /*X2.56 */ - tmpv = sub( 16384, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + tmpv = sub( 16384, add( lsf_tmp[sub(M, 1)], ftmp_fx ) ); /*QX2.56*/ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } ELSE { - lsp2lsf_fx( &tmp[i * M], lsf_tmp, M, INT_FS_16k_FX ); + lsp2lsf_fx( &tmp[i_mult(i, M)], lsf_tmp, M, INT_FS_16k_FX ); ftmp_fx = 1205; move16(); /*QX2.56*/ - tmpv = sub( 20480, add( lsf_tmp[M - 1], ftmp_fx ) ); /*QX2.56*/ + tmpv = sub( 20480, add( lsf_tmp[sub(M, 1)], ftmp_fx ) ); /*QX2.56*/ L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ - FOR( j = 0; j < M - 1; j++ ) + FOR( j = 0; j < sub(M, 1); j++ ) { - tmpv = sub( sub( lsf_tmp[j + 1], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ + tmpv = sub( sub( lsf_tmp[add(j, 1)], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ } @@ -487,10 +487,10 @@ void CNG_dec_fx( L_tmp1 = 0; FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add(i_mult(j, M), i)] ) ); } - L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[max_idx[0] * M + i] ) ); + L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[add(i_mult(max_idx[0], M), i)] ) ); tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ @@ -500,21 +500,21 @@ void CNG_dec_fx( { FOR( i = 0; i < M; i++ ) { - L_tmp1 = 0; + L_tmp1 = 0; move32(); FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[j * M + i] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add(i_mult(j, M), i)] ) ); } - L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[max_idx[0] * M + i] ), L_deposit_l( tmp[max_idx[1] * M + i] ) ) ); /*Q15*/ + L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[add(i_mult(max_idx[0], M), i)] ), L_deposit_l( tmp[add(i_mult(max_idx[1], M), i)] ) ) ); /*Q15*/ tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ } } - dist = 0; /*Q15*/ - max_dev = 0; /*Q15*/ + dist = 0; move16(); /*Q15*/ + max_dev = 0; move16(); /*Q15*/ FOR( i = 0; i < M; i++ ) { dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/ @@ -523,7 +523,7 @@ void CNG_dec_fx( #else dist = add( dist, dev ); /*Q15*/ #endif - if ( GT_16( dev, max_dev ) ) + IF ( GT_16( dev, max_dev ) ) { max_dev = dev; move16(); @@ -547,7 +547,7 @@ void CNG_dec_fx( st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); } } - IF( m1 > 0 ) + IF( GT_16(m1, 0 )) { FOR( i = 0; i < NUM_ENV_CNG; i++ ) { @@ -600,14 +600,14 @@ void CNG_dec_fx( /* Update hangover memory during CNG */ test(); #ifdef BASOP_NOGLOB - IF( *allow_cn_step == 0 && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) + IF( EQ_16(*allow_cn_step, 0) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) #else 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 ) ) ) ) #endif { /* update the pointer to circular buffer of old LSP vectors */ hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); - if ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + IF ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); @@ -620,7 +620,7 @@ void CNG_dec_fx( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; move32(); test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && *sid_bw == 0 ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16(*sid_bw, 0) ) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ exp = norm_l( hTdCngDec->Enew_fx ); @@ -653,16 +653,16 @@ void CNG_dec_fx( move32(); } hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - Copy32( env, &( hTdCngDec->ho_env_hist_fx[( hTdCngDec->ho_hist_ptr ) * NUM_ENV_CNG] ), NUM_ENV_CNG ); + Copy32( env, &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG)] ), NUM_ENV_CNG ); } - ELSE IF( *sid_bw != 0 ) + ELSE IF( NE_16(*sid_bw, 0 )) { hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); } hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - if ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + IF ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); @@ -672,7 +672,7 @@ void CNG_dec_fx( st_fx->last_CNG_L_frame = st_fx->L_frame; move16(); - if ( NE_32( st_fx->core_brate, SID_1k75 ) ) + IF ( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); @@ -680,9 +680,9 @@ void CNG_dec_fx( } /* Update the frame length memory */ - st_fx->last_CNG_L_frame = st_fx->L_frame; + st_fx->last_CNG_L_frame = st_fx->L_frame; move16(); - if ( NE_32( st_fx->core_brate, SID_1k75 ) ) + IF ( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); @@ -700,7 +700,7 @@ void CNG_dec_fx( tmp_loop = shr( st_fx->L_frame, 6 ); FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ { - Copy( Aq, &Aq[i * ( M + 1 )], M + 1 ); + Copy( Aq, &Aq[i_mult(i, add( M, 1 ))], add(M, 1) ); } return; @@ -723,11 +723,11 @@ void swb_CNG_dec_fx( ) { test(); - IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32(st_fx->core_brate, FRAME_NO_DATA) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF( st_fx->cng_type == LP_CNG && EQ_16( st_fx->extl, SWB_CNG ) ) + IF( EQ_16(st_fx->cng_type, LP_CNG) && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -741,7 +741,7 @@ void swb_CNG_dec_fx( st_fx->last_vad_fx = 1; move16(); st_fx->hTdCngDec->burst_cnt = add( st_fx->hTdCngDec->burst_cnt, 1 ); - if ( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) + IF ( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) { st_fx->hTdCngDec->burst_cnt = 0; move16(); @@ -763,11 +763,11 @@ void swb_CNG_dec_ivas_fx( ) { test(); - IF( st_fx->core_brate == FRAME_NO_DATA || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32(st_fx->core_brate, FRAME_NO_DATA) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF( st_fx->cng_type == LP_CNG && EQ_16( st_fx->extl, SWB_CNG ) ) + IF( EQ_16(st_fx->cng_type, LP_CNG) && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_ivas_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -833,14 +833,14 @@ static void shb_CNG_decod_fx( TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - IF( st_fx->bfi == 0 ) + IF( EQ_16(st_fx->bfi, 0 )) { test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { idx_ener_fx = get_next_indice( st_fx, 4 ); - if ( idx_ener_fx == 0 ) + IF ( EQ_16(idx_ener_fx, 0 )) { idx_ener_fx = -15; move16(); @@ -881,7 +881,7 @@ static void shb_CNG_decod_fx( IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - if ( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) + IF ( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) { st_fx->shb_dtx_count_fx = add( st_fx->shb_dtx_count_fx, 1 ); } @@ -889,7 +889,7 @@ static void shb_CNG_decod_fx( 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 */ + Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, add(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); @@ -905,12 +905,12 @@ static void shb_CNG_decod_fx( exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ - if ( st_fx->first_CNG == 0 ) + IF ( EQ_16(st_fx->first_CNG, 0 )) { st_fx->wb_cng_ener_fx = wb_ener16_fx; move16(); /*Q8 */ } - if ( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) + IF ( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) { allow_cn_step_fx = 1; move16(); @@ -929,12 +929,12 @@ static void shb_CNG_decod_fx( } test(); test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && st_fx->bfi == 0 ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16(st_fx->bfi, 0 )) { st_fx->last_wb_cng_ener_fx = st_fx->wb_cng_ener_fx; move16(); - if ( st_fx->first_CNG == 0 ) + IF ( EQ_16(st_fx->first_CNG, 0 )) { st_fx->shb_cng_ener_fx = st_fx->last_shb_cng_ener_fx; move16(); @@ -942,7 +942,7 @@ static void shb_CNG_decod_fx( } gain_fx = sub( st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx ); /*8 */ - if ( GT_16( gain_fx, 15 ) ) + IF ( GT_16( gain_fx, 15 ) ) { gain_fx = 15; move16(); @@ -969,21 +969,21 @@ static void shb_CNG_decod_fx( /* synthesis signal gain shaping */ - L_tmp = 0; + L_tmp = 0; move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/ } q = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q ); - q = q - 32; + q = sub(q, 32); ener_excSHB_fx = round_fx( L_tmp ); /*Qq */ IF( EQ_16( st_fx->last_vad_fx, 1 ) ) { st_fx->trans_cnt_fx = 0; move16(); test(); - if ( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) + IF ( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) { st_fx->trans_cnt_fx = 5; move16(); @@ -992,7 +992,7 @@ static void shb_CNG_decod_fx( ener_fx = st_fx->shb_cng_ener_fx; move16(); /*Q8 */ - IF( st_fx->trans_cnt_fx > 0 ) + IF( GT_16(st_fx->trans_cnt_fx, 0 )) { i = extract_l( L_mult0( st_fx->trans_cnt_fx, 17 ) ); /*Q0 */ #ifdef BASOP_NOGLOB @@ -1007,7 +1007,7 @@ static void shb_CNG_decod_fx( L_tmp = L_mult( 27213, tmp ); /*Q22, 27213=3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ L_tmp = L_add( L_tmp, 10 << 16 ); - if ( L_tmp < 0 ) + IF ( LT_32(L_tmp, 0 )) { L_tmp = 0; move32(); @@ -1019,7 +1019,7 @@ static void shb_CNG_decod_fx( L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ #endif L_tmp = L_shr( L_tmp, 10 ); - if ( L_tmp == 0 ) + IF ( EQ_32(L_tmp, 0 )) { L_tmp = 1; /*Q5 */ } @@ -1058,7 +1058,7 @@ static void shb_CNG_decod_fx( move32(); } - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) + FOR( i = 0; i < shl(ALLPASSSECTIONS_STEEP, 1); i++ ) { 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 ); } @@ -1202,12 +1202,12 @@ static void shb_CNG_decod_ivas_fx( } test(); test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && st->bfi == 0 ) + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16(st->bfi, 0 )) { st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32; move32(); - IF( st->first_CNG == 0 ) + IF( EQ_16(st->first_CNG, 0 )) { st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32; move32(); @@ -1242,7 +1242,7 @@ static void shb_CNG_decod_ivas_fx( /* synthesis signal gain shaping */ - L_tmp = 0; + L_tmp = 0; move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/ @@ -1277,12 +1277,12 @@ static void shb_CNG_decod_ivas_fx( } tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ - IF( tmp > 32767 ) + IF( GT_32(tmp, 32767 )) abort(); Word16 tmp_16 = (Word16) tmp; L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ - L_tmp = L_add( L_tmp, 10 << 16 ); + L_tmp = L_add( L_tmp, L_shl(10, 16) ); IF( LT_32( L_tmp, 0 ) ) { L_tmp = 0; @@ -1291,9 +1291,9 @@ static void shb_CNG_decod_ivas_fx( fra = L_Extract_lc( L_tmp, &exp ); L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ L_tmp = L_shr( L_tmp, 10 ); - IF( L_tmp == 0 ) + IF( EQ_32(L_tmp, 0 )) { - L_tmp = 1; /*Q5 */ + L_tmp = 1; move32();/*Q5 */ } exp = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp ); /*Q31*/ @@ -1341,7 +1341,7 @@ static void shb_CNG_decod_ivas_fx( interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } - Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); + Scale_sig(shb_synth_fx, L_FRAME48k, -3); ResetSHBbuffer_Dec_fx( st ); return; } @@ -1420,7 +1420,7 @@ void td_cng_dec_init_fx( // st->CNG_mode = -1; // for (i = 0; i < LPC_SHB_ORDER; i++) //{ - // if (st->element_mode != EVS_MONO) + // IF (st->element_mode != EVS_MONO) // { // hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1)); // } @@ -1520,7 +1520,7 @@ void td_cng_dec_init_ivas_fx( { IF( NE_16( st->element_mode, EVS_MONO ) ) { - hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( i + 1, 1 ), LPC_SHB_ORDER + 1 ); + hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( add(i, 1), 1 ), LPC_SHB_ORDER + 1 ); } ELSE { diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index b043eab46..48cb0af51 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -772,13 +772,13 @@ void reset_tcx_overl_buf_fx( ) { set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_old_syn_Overl = 0; + hTcxDec->Q_old_syn_Overl = 0; move16(); set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl_TDAC = 0; + hTcxDec->Q_syn_Overl_TDAC = 0; move16(); set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl = 0; + hTcxDec->Q_syn_Overl = 0; move16(); set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl_TDACFB = 0; + hTcxDec->Q_syn_Overl_TDACFB = 0; move16(); return; } #endif diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 835220694..96f758a06 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -71,7 +71,7 @@ void open_decoder_LPD_fx( #ifndef NEW_IVAS_OPEN_DEC hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); #endif - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { st->last_L_frame = st->L_frame_past = st->L_frame; move16(); @@ -85,7 +85,7 @@ void open_decoder_LPD_fx( IF( st->hTcxDec != NULL ) { hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { st->L_frameTCX_past = st->hTcxDec->L_frameTCX; } @@ -112,9 +112,9 @@ void open_decoder_LPD_fx( test(); test(); - if ( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || + IF ( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || - ( st->tcxonly != 0 && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) + ( NE_16(st->tcxonly, 0) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { st->nb_subfr = NB_SUBFR16k; move16(); @@ -130,7 +130,7 @@ void open_decoder_LPD_fx( st->TcxBandwidth = getTcxBandwidth( bwidth ); st->narrowBand = 0; move16(); - if ( EQ_16( bwidth, NB ) ) + IF ( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; move16(); @@ -162,7 +162,7 @@ void open_decoder_LPD_fx( hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); } } - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { st->pit_res_max_past = st->pit_res_max; } @@ -170,12 +170,12 @@ void open_decoder_LPD_fx( /*Preemphasis param*/ st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF( LT_16( st->fscale, ( 16000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) + IF( LT_16( st->fscale, 640)) /*( 16000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ { st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); } - ELSE if ( LT_16( st->fscale, ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) + ELSE IF ( LT_16( st->fscale, 960)) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) */ { st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); @@ -185,6 +185,7 @@ void open_decoder_LPD_fx( move16(); st->inv_gamma = GAMMA1_INV; move16(); + test(); test(); 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 ) ) ) { @@ -198,14 +199,14 @@ void open_decoder_LPD_fx( st->lpcQuantization = 0; move16(); test(); - if ( st->tcxonly == 0 && LE_32( st->sr_core, INT_FS_16k ) ) + IF ( EQ_16(st->tcxonly, 0) && LE_32( st->sr_core, INT_FS_16k ) ) { st->lpcQuantization = 1; } st->numlpc = 2; move16(); - if ( st->tcxonly == 0 ) + IF ( EQ_16(st->tcxonly, 0 )) { st->numlpc = 1; move16(); @@ -213,11 +214,11 @@ void open_decoder_LPD_fx( /* Initialize TBE */ st->prev_coder_type = GENERIC; - if ( st->hBWE_TD != NULL ) + IF ( st->hBWE_TD != NULL ) { - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, LPC_SHB_ORDER - 2 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub(LPC_SHB_ORDER, 2) ); hBWE_TD->prev_tilt_para_fx = 0; - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, M + 1 ); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add(M, 1) ); } /*TCX config*/ @@ -227,7 +228,7 @@ void open_decoder_LPD_fx( st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length; move16(); init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY should be rename to init_TCX_config - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -254,23 +255,23 @@ void open_decoder_LPD_fx( InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if ( st->tcxonly == 0 ) + IF ( EQ_16(st->tcxonly, 0 )) { assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } - if ( 1 ) // st->element_mode == EVS_MONO) + IF ( 1 ) // st->element_mode == EVS_MONO) { - if ( st->hTECDec == NULL ) + IF ( st->hTECDec == NULL ) { - if ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) + IF ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) { // return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); assert( 0 ); } } } - else + ELSE { st->hTECDec = NULL; } @@ -278,10 +279,10 @@ void open_decoder_LPD_fx( #else - if ( st->hIGFDec != NULL ) + IF ( st->hIGFDec != NULL ) { PMT( "To be done" ) - // if (!is_init || st->element_mode != IVAS_CPE_MDCT) + // 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); // } @@ -292,11 +293,11 @@ void open_decoder_LPD_fx( // } } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - if ( st->tcxonly == 0 ) + IF ( st->tcxonly == 0 ) { assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } - // if (st->tecDec_fx != NULL) + // IF (st->tecDec_fx != NULL) { resetTecDec_Fx( &( st->tecDec_fx ) ); } @@ -312,7 +313,7 @@ void open_decoder_LPD_fx( st->flag_cna = 0; move16(); } - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { st->flag_cna = 0; st->last_flag_cna = 0; @@ -320,7 +321,7 @@ void open_decoder_LPD_fx( } /* Static vectors to zero */ - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { st->last_is_cng = 0; @@ -330,26 +331,26 @@ void open_decoder_LPD_fx( move16(); IF( hTcxDec != NULL ) { - set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); + set16_fx( hTcxDec->old_syn_Overl, 0, shr(L_FRAME32k, 1) ); - 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( hTcxDec->syn_Overl_TDAC, 0, shr(L_FRAME32k, 1) ); + set16_fx( hTcxDec->syn_OverlFB, 0, shr(L_FRAME_MAX, 1) ); + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr(L_FRAME_MAX, 1) ); - set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); + set16_fx( hTcxDec->syn_Overl, 0, shr(L_FRAME32k, 1) ); set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); - set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); - hTcxDec->q_synth_history_fx = 0; + set16_fx( hTcxDec->synth_history_fx, 0, add(L_PROT48k, L_FRAME_MAX) ); + hTcxDec->q_synth_history_fx = 0; move16(); } - set16_fx( st->syn, 0, M + 1 ); + set16_fx( st->syn, 0, add(M, 1) ); set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); - mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ - mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ move16(); + mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ move16(); - st->con_tcx = 0; + st->con_tcx = 0; move16(); } ELSE { @@ -409,7 +410,7 @@ void open_decoder_LPD_fx( /*PLC*/ #ifndef NEW_IVAS_OPEN_DEC - IF( st->prev_bfi != 0 ) + IF( EQ_16(st->prev_bfi, 0 )) { PWord16 const *w; Word16 W1, W2, nz, delay_comp; @@ -417,36 +418,36 @@ void open_decoder_LPD_fx( W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ move16(); - nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); move16(); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ move16(); Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ - hHQ_core->Q_old_wtda = -1; + hHQ_core->Q_old_wtda = -1; move16(); 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++ ) { - 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] ) ); + hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add(i, nz)] ) ); } FOR( ; i < W1; i++ ) { - 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] ) ); + hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[sub(W2, add(1, sub( i, W2 )))].v.im, w[sub(W2, add(1, sub( i, W2 )))].v.im ), hHQ_core->old_out_fx[add(i, nz)] ) ); } - set16_fx( &hHQ_core->old_out_fx[W1 + nz], 0, nz ); + set16_fx( &hHQ_core->old_out_fx[add(W1, nz)], 0, nz ); lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX ); 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 ); + nz = NS2SA_fx2( st->sr_core, N_ZERO_MDCT_NS );move16(); Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); - hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; + hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda;move16(); } #else PMT( "acelp_plc_mdct_transition is missing" ) @@ -488,17 +489,17 @@ void open_decoder_LPD_fx( set16_fx( st->mem_syn2_fx, 0, M ); /*OLA -> zero */ - if ( st->hTcxDec != NULL ) + 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*/ + set16_fx( hTcxDec->old_syn_Overl, 0, shr(L_FRAME32k, 1 )); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr(L_FRAME32k, 1) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr(L_FRAME_MAX, 1) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl, 0, shr(L_FRAME32k, 1) ); /*HQ-CORE(bfi)->TCX don't need it*/ #if 0 PMT("to be moved to reset_tcx_overl_buf") #endif } - if ( st->hTcxCfg != NULL ) + IF ( st->hTcxCfg != NULL ) { Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); @@ -508,16 +509,16 @@ void open_decoder_LPD_fx( st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; } /*OLA for MDCT-LB always reset in codec switching cases*/ - if ( st->hHQ_core != NULL ) + IF ( st->hHQ_core != NULL ) { set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); } move16(); st->last_core_bfi = TCX_20_CORE; - if ( st->hPFstat != NULL ) + IF ( st->hPFstat != NULL ) { - st->hPFstat->on = 0; + st->hPFstat->on = 0; move16(); } move16(); /* reset CLDFB memories */ @@ -528,7 +529,7 @@ void open_decoder_LPD_fx( #if 0 PMT("cldfbSynHB is missing ") #endif - // if (st->cldfbSynHB != NULL) + // IF (st->cldfbSynHB != NULL) //{ // cldfb_reset_memory(st->cldfbSynHB); // } @@ -540,7 +541,7 @@ void open_decoder_LPD_fx( /* convert quantized LSP vector */ st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); - IF( st->tcxonly == 0 ) + IF( EQ_16(st->tcxonly, 0 )) { lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); } @@ -564,20 +565,20 @@ void open_decoder_LPD_fx( ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */ { /*Partial reset of ACELP memories*/ - st->rate_switching_reset = 1; + st->rate_switching_reset = 1; move16(); /*reset partly some memories*/ - st->tilt_code_fx = TILT_CODE; + st->tilt_code_fx = TILT_CODE; move16(); IF( !st->last_con_tcx ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); + set16_fx( st->old_Aq_12_8_fx, 0, add(M, 1) ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_old), st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + sub(L_SYN_MEM, M), st->mem_syn2_fx, M ); /*Untouched memories : st->syn */ } @@ -589,7 +590,7 @@ void open_decoder_LPD_fx( test(); test(); - if ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) + IF ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) { st->rate_switching_reset = 1; move16(); @@ -602,37 +603,37 @@ void open_decoder_LPD_fx( /* bass pf reset */ st->bpf_gain_param = 0; move16(); - if ( st->hBPF != NULL ) + IF ( st->hBPF != NULL ) { set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); } /* Formant postfilter */ - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { /*do nothing*/ } ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) ) { - IF( st->tcxonly == 0 ) + IF( EQ_16(st->tcxonly, 0 )) { - IF( st->hPFstat->on != 0 ) + IF( NE_16(st->hPFstat->on, 0 )) { - 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 ); + lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { 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->reset = 1; move16(); st->hPFstat->gain_prec = 16384; move16(); } } - ELSE IF( st->hPFstat->on != 0 ) + ELSE IF( NE_16(st->hPFstat->on, 0 )) { - 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 ); + lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE @@ -641,43 +642,43 @@ void open_decoder_LPD_fx( /*reset post-filter except for Narrowband*/ IF( NE_32( st->output_Fs, 8000 ) ) { - if ( st->hPFstat != NULL ) + IF ( st->hPFstat != NULL ) { - st->hPFstat->reset = 1; - if ( st->hPFstat->on != 0 ) + st->hPFstat->reset = 1; move16(); + IF ( NE_16(st->hPFstat->on, 0 )) { - st->hPFstat->reset = 0; + st->hPFstat->reset = 0; move16(); 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 ); + lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); } } } ELSE { - if ( st->hPFstat != NULL ) + 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*/ - if ( st->hTcxDec != NULL ) + IF ( st->hTcxDec != NULL ) { - hTcxDec->old_synth[hTcxDec->old_synth_len - 1] = st->syn[M]; + hTcxDec->old_synth[sub(hTcxDec->old_synth_len, 1)] = st->syn[M]; } move16(); - if ( st->hBPF != NULL ) + IF ( st->hBPF != NULL ) { - hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; + hBPF->pst_old_syn_fx[sub(NBPSF_PIT_MAX, 1)] = st->syn[M]; } move16(); } } /* lsf and lsp initialization */ - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); @@ -702,31 +703,31 @@ void open_decoder_LPD_fx( Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); set16_fx( st->mem_syn_unv_back, 0, M ); - st->last_gain_syn_deemph = 32768 / 2; + st->last_gain_syn_deemph = 16384; move16(); st->last_gain_syn_deemph_e = 1; move16(); test(); - IF( EQ_16( st->last_codec_mode, MODE1 ) || st->ini_frame == 0 ) + IF( EQ_16( st->last_codec_mode, MODE1 ) || EQ_16(st->ini_frame, 0) ) { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph = 32768 / 2; + st->last_concealed_gain_syn_deemph = 16384; move16(); st->last_concealed_gain_syn_deemph_e = 1; move16(); - if ( hTcxDec != NULL ) + IF ( hTcxDec != NULL ) { - hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/ + hTcxDec->conceal_eof_gain = 16384; /*Q14*/ move16(); } } /* Post processing */ - set16_fx( st->mem_Aq, 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( st->mem_Aq, 0, i_mult(NB_SUBFR16k, add(M, 1))); st->lp_ener_FER_fx = 15360; move16(); /*60 in Q8*/ - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { st->prev_bfi = 0; move16(); @@ -775,11 +776,11 @@ void open_decoder_LPD_fx( st->prev_widow_left_rect = 0; move16(); - if ( st->hTcxDec != NULL ) + 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 ) ) + 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; @@ -793,16 +794,15 @@ void open_decoder_LPD_fx( #else hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); - hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; - move16(); + hTcxDec->conNoiseLevelIndex = sub(PLC_MIN_STAT_BUFF_SIZE, 1); 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 = -6; + hTcxDec->conLastFrameLevel_e = 0; move16(); + hTcxDec->conCngLevelBackgroundTrace_e = -6; move16(); hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; #endif @@ -811,14 +811,14 @@ void open_decoder_LPD_fx( st->cummulative_damping = 32767 /*1.0f Q15*/; move16(); - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) { st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); } - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) { - st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ + st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ move16(); } @@ -842,14 +842,14 @@ void open_decoder_LPD_fx( move16(); /* TCX-LTP */ - if ( hTcxLtpDec != NULL ) + IF ( hTcxLtpDec != NULL ) { hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); } move16(); - test(); - IF( hTcxLtpDec != NULL && ( st->ini_frame == 0 || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) + test(); test(); + IF( hTcxLtpDec != NULL && ( EQ_16(st->ini_frame, 0) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) { #if 0 PMT("TO be verify, update seems to differ from float") @@ -858,12 +858,12 @@ void open_decoder_LPD_fx( move16(); hTcxLtpDec->tcxltp_pitch_fr = 0; move16(); - if ( hTcxDec != NULL ) + IF ( hTcxDec != NULL ) { hTcxDec->tcxltp_last_gain_unmodified = 0; } move16(); - IF( st->ini_frame == 0 ) + IF( EQ_16(st->ini_frame, 0) ) { set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); @@ -879,14 +879,14 @@ void open_decoder_LPD_fx( } /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */ - if ( st->hBPF != NULL ) + 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 + ELSE { - st->lp_error_ener = 0; + st->lp_error_ener = 0; move16(); } st->mem_error = L_deposit_l( 0 ); st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag ); @@ -898,7 +898,7 @@ void open_decoder_LPD_fx( 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 ) + IF ( hTcxDec != NULL ) { hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); @@ -907,7 +907,7 @@ void open_decoder_LPD_fx( move16(); st->p_bpf_noise_buf = NULL; - if ( st->tcxonly == 0 ) + IF ( EQ_16(st->tcxonly, 0 )) { st->p_bpf_noise_buf = st->bpf_noise_buf; } @@ -916,7 +916,7 @@ void open_decoder_LPD_fx( move16(); test(); test(); - if ( EQ_16( bwidth, SWB ) && + IF ( EQ_16( bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->tec_tfa = 1; @@ -950,7 +950,7 @@ void open_decoder_LPD_fx( test(); test(); test(); - IF( st->ini_frame == 0 || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) + IF( EQ_16(st->ini_frame, 0) || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { concealment_init_x( hTcxDec->L_frameTCX, &st->plcInfo ); } @@ -961,7 +961,7 @@ void open_decoder_LPD_fx( PMT("handle to tonalMDCTconceal is missing") #endif //#ifdef ADD_IVAS_HTONALMDCTCONC - if ( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) + IF ( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) { st->tonalMDCTconceal.nScaleFactors = 0; move16(); @@ -980,12 +980,12 @@ void open_decoder_LPD_fx( st->second_last_tns_active = 0; st->second_last_core = -1; #ifdef NEW_IVAS_OPEN_DEC - if ( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) + 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 ) + IF ( hTcxDec != NULL ) { hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move16(); @@ -997,31 +997,35 @@ void open_decoder_LPD_fx( test(); test(); test(); - if ( ( total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) - - if ( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || + IF ( ( EQ_32(total_brate, ACELP_9k60) || EQ_32(total_brate, ACELP_16k40) || EQ_32(total_brate, ACELP_24k40) ) && EQ_16(st->element_mode, EVS_MONO )) + { + test(); + test(); + test(); + IF ( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || ( EQ_32( st->total_brate, 24400 ) ) ) && - st->element_mode == EVS_MONO ) + EQ_16(st->element_mode, EVS_MONO) ) { move16(); st->dec_glr = 1; } + } move16(); st->dec_glr_idx = 0; - if ( hTcxDec != NULL ) + 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; + hTcxDec->enableTcxLpc = 1; move16(); + st->VAD = 0; move16(); + hTcxDec->old_gaintcx_bfi = 0; move16(); + hTcxDec->old_gaintcx_bfi_e = 0; move16(); + hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); } #ifndef NEW_IVAS_OPEN_DEC - st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; move16(); #endif - if ( hTcxLtpDec != NULL ) + IF ( hTcxLtpDec != NULL ) { - hTcxLtpDec->tcxltp_gain = 0; + hTcxLtpDec->tcxltp_gain = 0; move16(); } return; } @@ -1035,25 +1039,25 @@ void tcxltp_dec_init_fx( const Word16 pit_max, const Word32 sr_core ) { - hTcxLtpDec->tcxltp_gain = 0; + hTcxLtpDec->tcxltp_gain = 0; move16(); hTcxLtpDec->tcxltp = getTcxLtp( sr_core ); - - IF( ini_frame == 0 || ( EQ_16( last_codec_mode, MODE1 ) && EQ_16( element_mode, EVS_MONO ) ) ) + test(); test(); + IF( EQ_16(ini_frame, 0) || ( EQ_16( last_codec_mode, MODE1 ) && EQ_16( element_mode, EVS_MONO ) ) ) { - hTcxLtpDec->tcxltp_pitch_int = pit_max; - hTcxLtpDec->tcxltp_pitch_fr = 0; + hTcxLtpDec->tcxltp_pitch_int = pit_max; move16(); + hTcxLtpDec->tcxltp_pitch_fr = 0; move16(); - IF( ini_frame == 0 ) + IF( EQ_16(ini_frame, 0 )) { set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k ); - hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; - hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; - hTcxLtpDec->tcxltp_gain_post_prev = 0; - hTcxLtpDec->tcxltp_filt_idx_prev = -1; + hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; move16(); + hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; move16(); + hTcxLtpDec->tcxltp_gain_post_prev = 0; move16(); + hTcxLtpDec->tcxltp_filt_idx_prev = -1; move16(); } } @@ -1071,37 +1075,38 @@ void acelp_plc_mdct_transition_fx( Word16 i; /*PLC*/ - IF( st->prev_bfi != 0 && st->hTcxCfg != NULL ) + test(); + IF( NE_16(st->prev_bfi, 0) && st->hTcxCfg != NULL ) { W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); 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, N_ZERO_MDCT_NS ); - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); move16(); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); move16();/*CLDFB delay*/ Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); lerp( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( st->hTcxDec->L_frameTCX, 1 ) ); /*ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ - st->hHQ_core->Q_old_wtda = -1; + st->hHQ_core->Q_old_wtda = -1; move16(); set16_fx( st->hHQ_core->old_out_fx, 0, nz ); // Q_old_out is 0 Copy_Scale_sig( st->hHQ_core->fer_samples_fx + delay_comp, st->hHQ_core->old_out_fx + nz, W1, st->hHQ_core->Q_old_wtda ); /*Q-1*/ FOR( i = 0; i < W2; i++ ) { - st->hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[i + nz] ) ); + st->hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[add(i, nz)] ) ); } FOR( ; i < W1; i++ ) { - st->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 ), st->hHQ_core->old_out_fx[i + nz] ) ); + st->hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[sub(W2, add(1, sub( i, W2 )))].v.im, w[sub(W2, add(1, sub( i, W2 )))].v.im ), st->hHQ_core->old_out_fx[add(i, nz)] ) ); } - set16_fx( &st->hHQ_core->old_out_fx[W1 + nz], 0, nz ); + set16_fx( &st->hHQ_core->old_out_fx[add(W1, nz)], 0, nz ); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->hTcxDec->L_frameTCX ); Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); - nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS ); + nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS ); move16(); Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; } @@ -1146,7 +1151,7 @@ void open_decoder_LPD_ivas_fx( IF( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/ { - st->fscale_old = st->fscale; + st->fscale_old = st->fscale; move16(); } st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); @@ -1159,15 +1164,14 @@ void open_decoder_LPD_ivas_fx( { st->last_L_frame = st->L_frame_past = st->L_frame; move16(); - move16(); } IF( st->hTcxDec != NULL ) { st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - st->output_frame_fx = st->hTcxDec->L_frameTCX; + st->output_frame_fx = st->hTcxDec->L_frameTCX; move16(); IF( EQ_16( st->ini_frame, 0 ) ) { - st->L_frameTCX_past = st->hTcxDec->L_frameTCX; + st->L_frameTCX_past = st->hTcxDec->L_frameTCX; move16(); } } @@ -1175,25 +1179,26 @@ void open_decoder_LPD_ivas_fx( move16(); /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ + test(); test(); test(); test(); test(); test(); test(); test(); test(); IF( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || ( NE_16( st->tcxonly, 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { - st->nb_subfr = NB_SUBFR16k; + st->nb_subfr = NB_SUBFR16k; move16(); } ELSE { - st->nb_subfr = NB_SUBFR; + st->nb_subfr = NB_SUBFR; move16(); } st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ // assert(FSCALE_DENOM == 512); // assert(st->fscale == 2 * st->L_frame); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ // assert(st->bits_frame == (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f)); st->TcxBandwidth = getTcxBandwidth( bwidth ); - st->narrowBand = 0; + st->narrowBand = 0; move16(); IF( EQ_16( bwidth, NB ) ) { - st->narrowBand = 1; + st->narrowBand = 1; move16(); } IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -1219,28 +1224,29 @@ void open_decoder_LPD_ivas_fx( IF( EQ_16( st->ini_frame, 0 ) ) { - st->pit_res_max_past = st->pit_res_max; + st->pit_res_max_past = st->pit_res_max; move16(); } /*Preemphasis param*/ - IF( LT_16( st->fscale, ( 16000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) /*To be replaced with basops*/ + IF( LT_16( st->fscale, 640 )) /*16000 * FSCALE_DENOM ) / INT_FS_12k8*/ { st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); } - ELSE IF( LT_16( st->fscale, ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) ) + ELSE IF( LT_16( st->fscale, 960)) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ { st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); } ELSE { - st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ + st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); } // gamma_float to be removed later st->inv_gamma = GAMMA1_INV; move16(); + test(); IF( EQ_32( st->sr_core, INT_FS_16k ) ) { st->gamma = GAMMA16k; @@ -1262,43 +1268,45 @@ void open_decoder_LPD_ivas_fx( } /* LPC quantization */ + test(); IF( LE_32( st->sr_core, INT_FS_16k ) && EQ_16( st->tcxonly, 0 ) ) { - st->lpcQuantization = 1; + st->lpcQuantization = 1; move16(); } ELSE { - st->lpcQuantization = 0; + st->lpcQuantization = 0; move16(); } IF( EQ_16( st->tcxonly, 0 ) ) { - st->numlpc = 1; + st->numlpc = 1; move16(); } ELSE { - st->numlpc = 2; + st->numlpc = 2; move16(); } /* Initialize TBE */ - st->prev_coder_type = GENERIC; + st->prev_coder_type = GENERIC; move16(); 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 ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub(LPC_SHB_ORDER, 2 )); + hBWE_TD->prev_tilt_para_fx = 0; move16(); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add(M, 1) ); } IF( st->hIGFDec != NULL ) { + test(); IF( !is_init || NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { init_tcx_cfg_fx( st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, st->preemph_fac, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag, fscaleFB ); } ELSE { - st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - st->hTcxCfg->last_aldo = 1; + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); move16(); + st->hTcxCfg->last_aldo = 1; move16(); } } IF( st->hTECDec != NULL ) @@ -1320,7 +1328,7 @@ void open_decoder_LPD_ivas_fx( } IF( EQ_16( st->ini_frame, 0 ) ) { - st->flag_cna = 0; + st->flag_cna = 0; move16(); st->last_flag_cna = 0; move16(); } @@ -1337,18 +1345,18 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { reset_tcx_overl_buf_fx( st->hTcxDec ); - set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 ); + set16_fx( hTcxDec->syn_OverlFB, 0, shr(L_FRAME_MAX, 1)); set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); - set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); - hTcxDec->q_synth_history_fx = 0; + set16_fx( hTcxDec->synth_history_fx, 0, add(L_PROT48k, L_FRAME_MAX) ); + hTcxDec->q_synth_history_fx = 0; move16(); } - set16_fx( st->syn, 0, M + 1 ); + set16_fx( st->syn, 0, add(M, 1) ); set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); - mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ - mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ move16(); + mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ move16(); - st->con_tcx = 0; + st->con_tcx = 0; move16(); } ELSE { @@ -1381,6 +1389,7 @@ void open_decoder_LPD_ivas_fx( } /*Mode 1/2 switching*/ + test(); IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) { Copy( st->lsp_old_fx, st->lspold_uw, M ); @@ -1408,15 +1417,15 @@ void open_decoder_LPD_ivas_fx( IF( NE_16( st->prev_bfi, 0 ) && st->hTcxCfg != NULL ) { acelp_plc_mdct_transition_fx( st ); - *Q_syn_Overl_TDAC = *Q_fer_samples - 1; - *Q_syn_Overl = *Q_fer_samples; - *Q_syn_Overl_TDACFB = *Q_fer_samples - 1; - *Q_syn_OverlFB = *Q_fer_samples; - *Q_old_out = *Q_fer_samples - 1; - *Q_old_outLB = *Q_fer_samples - 1; + *Q_syn_Overl_TDAC = sub(*Q_fer_samples, 1); + *Q_syn_Overl = *Q_fer_samples; move16(); + *Q_syn_Overl_TDACFB = sub(*Q_fer_samples, 1); + *Q_syn_OverlFB = *Q_fer_samples; move16(); + *Q_old_out = sub(*Q_fer_samples, 1); + *Q_old_outLB = sub(*Q_fer_samples, 1); } } - + test(); test(); test(); test(); test(); IF( EQ_16( st->last_codec_mode, MODE2 ) && NE_16( st->L_frame, st->last_L_frame ) && ( ( EQ_16( st->m_frame_type, SID_FRAME ) && GT_16( st->last_core, ACELP_CORE ) ) || ( GT_16( st->last_core, ACELP_CORE ) && GT_16( st->core, ACELP_CORE ) ) || st->prev_bfi ) ) @@ -1425,16 +1434,17 @@ void open_decoder_LPD_ivas_fx( } /* Rate switching */ + test(); test(); test(); test(); test(); IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) ) { /* Switching from MDCT */ /*Reset of ACELP memories*/ - st->rate_switching_reset = 1; + st->rate_switching_reset = 1; move16(); // To be removed later - st->tilt_code_fx = TILT_CODE; + st->tilt_code_fx = TILT_CODE; move16(); set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); - set16_fx( st->syn, 0, 1 + M ); + set16_fx( st->syn, 0, add(1, M) ); set16_fx( st->mem_syn2_fx, 0, M ); /*OLA -> zero */ @@ -1445,11 +1455,11 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxCfg != NULL ) { - hHQ_core->Q_old_wtda = -1; /*To be removed later when hHQ_core->Q_old_wtda vaue is updated*/ + hHQ_core->Q_old_wtda = -1; /*To be removed later when hHQ_core->Q_old_wtda vaue is updated*/ move16(); Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); - *Q_syn_OverlFB = *Q_old_out; - st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ - st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + *Q_syn_OverlFB = *Q_old_out; move16(); + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ move16(); + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); } /*OLA for Mode 2 TCX always reset in Mode switching cases*/ @@ -1458,11 +1468,11 @@ void open_decoder_LPD_ivas_fx( set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); } - st->last_core_bfi = TCX_20_CORE; + st->last_core_bfi = TCX_20_CORE; move16(); IF( st->hPFstat != NULL ) { - st->hPFstat->on = 0; + st->hPFstat->on = 0; move16(); } /* reset CLDFB memories */ @@ -1491,7 +1501,7 @@ void open_decoder_LPD_ivas_fx( E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); - *Q_old_Aq_12_8 = 14; + *Q_old_Aq_12_8 = 14; move16(); IF( !st->last_con_tcx ) { ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC, st->Q_syn ); @@ -1502,20 +1512,20 @@ void open_decoder_LPD_ivas_fx( ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */ { /*Partial reset of ACELP memories*/ - st->rate_switching_reset = 1; + st->rate_switching_reset = 1; move16(); /*reset partly some memories*/ - st->tilt_code_fx = TILT_CODE; + st->tilt_code_fx = TILT_CODE; move16(); IF( !st->last_con_tcx ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, M + 1 ); + set16_fx( st->old_Aq_12_8_fx, 0, add(M, 1) ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_old), st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + sub(L_SYN_MEM, M), st->mem_syn2_fx, M ); } /* update of lsf_old only needed in BASOP */ /* ELSE IF( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ @@ -1523,7 +1533,7 @@ void open_decoder_LPD_ivas_fx( /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ /* } */ } - + test(); test(); IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && NE_16( st->ini_frame, 0 ) ) { st->rate_switching_reset = 1; @@ -1537,7 +1547,7 @@ void open_decoder_LPD_ivas_fx( } /* bass pf reset */ - st->bpf_gain_param = 0; + st->bpf_gain_param = 0; move16(); IF( st->hBPF != NULL ) { set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); @@ -1554,8 +1564,8 @@ void open_decoder_LPD_ivas_fx( { IF( st->hPFstat->on ) { - 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 ); + lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { @@ -1568,8 +1578,8 @@ void open_decoder_LPD_ivas_fx( } ELSE IF( st->hPFstat->on ) { - 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 ); + lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE @@ -1577,20 +1587,20 @@ void open_decoder_LPD_ivas_fx( /*codec mode switching*/ /*reset post-filter except for Narrowband*/ - IF( NE_32( st->output_Fs, L_FRAME8k * FRAMES_PER_SEC ) ) + IF( NE_32( st->output_Fs, i_mult(L_FRAME8k, FRAMES_PER_SEC) ) ) { IF( st->hPFstat != NULL ) { - st->hPFstat->reset = 1; - IF( st->hPFstat->on != 0 ) + st->hPFstat->reset = 1; move16(); + IF( NE_16(st->hPFstat->on, 0 )) { - st->hPFstat->reset = 0; + st->hPFstat->reset = 0; move16(); //-------------Present in EVS // 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 ); + lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); } } } @@ -1607,11 +1617,11 @@ void open_decoder_LPD_ivas_fx( /*feed last value old_synth as it is used for pre-emphasis mem*/ IF( st->hTcxDec != NULL ) { - st->hTcxDec->old_synth[st->hTcxDec->old_synth_len - 1] = st->syn[M]; + st->hTcxDec->old_synth[sub(st->hTcxDec->old_synth_len, 1)] = st->syn[M]; } IF( st->hBPF != NULL ) { - st->hBPF->pst_old_syn_fx[NBPSF_PIT_MAX - 1] = st->syn[M]; + st->hBPF->pst_old_syn_fx[sub(NBPSF_PIT_MAX, 1)] = st->syn[M]; } } } @@ -1633,46 +1643,44 @@ void open_decoder_LPD_ivas_fx( E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M ); E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M ); - st->plcBackgroundNoiseUpdated = 0; + st->plcBackgroundNoiseUpdated = 0; move16(); Copy( st->lsf_old_fx, st->lsf_q_cng, M ); Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); Copy( st->lsp_old_fx, st->lsp_q_cng, M ); Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); set16_fx( st->mem_syn_unv_back, 0, M ); - st->last_gain_syn_deemph = 32768 / 2; /* 1.f Q14*/ - + st->last_gain_syn_deemph = 16384; /* 1.f Q14*/ + test(); IF( EQ_16( st->last_codec_mode, MODE1 ) || EQ_16( st->ini_frame, 0 ) ) { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ - st->last_concealed_gain_syn_deemph = 32768 / 2; - move16(); - st->last_concealed_gain_syn_deemph_e = 1; - move16(); + st->last_concealed_gain_syn_deemph = 16384; + st->last_concealed_gain_syn_deemph_e = 1; move16(); IF( hTcxDec != NULL ) { - hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/ + hTcxDec->conceal_eof_gain = 16384; /*Q14*/ } } /* Post processing */ - set16_fx( st->mem_Aq, 0, NB_SUBFR16k * ( M + 1 ) ); + set16_fx( st->mem_Aq, 0, i_mult(NB_SUBFR16k, add(M, 1)) ); - st->lp_ener_FER_fx = 15360; /*60.0f Q8*/ + st->lp_ener_FER_fx = 15360; /*60.0f Q8*/ move16(); IF( EQ_16( st->ini_frame, 0 ) ) { - st->prev_bfi = 0; - st->last_core_bfi = -1; + st->prev_bfi = 0; move16(); + st->last_core_bfi = -1; move16(); IF( st->hTcxDec != NULL ) { - hTcxDec->tcxConceal_recalc_exc = 0; + hTcxDec->tcxConceal_recalc_exc = 0; move16(); } } - st->prev_old_bfi = 0; + st->prev_old_bfi = 0; move16(); IF( st->hTcxDec != NULL ) { - st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; - st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; + st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; move16(); move16(); + st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; move16(); move16(); set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); } @@ -1680,11 +1688,11 @@ void open_decoder_LPD_ivas_fx( Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); - st->clas_dec = UNVOICED_CLAS; + st->clas_dec = UNVOICED_CLAS; move16(); IF( !st->last_con_tcx ) { - st->old_enr_LP = 0; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ + st->old_enr_LP = 0; move16();/* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ } IF( st->prev_bfi ) @@ -1692,13 +1700,13 @@ void open_decoder_LPD_ivas_fx( /* calculate energy at the end of the previous frame */ IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, HQ_CORE ) ) { - st->output_frame_fx = st->hTcxDec->L_frameTCX; + st->output_frame_fx = st->hTcxDec->L_frameTCX; move16(); frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); } } ELSE { - st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ + st->last_good = UNVOICED_CLAS; move16(); /* last good received frame for concealment */ st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */ } st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -1708,11 +1716,11 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { - st->hTcxDec->prev_widow_left_rect = 0; - + st->hTcxDec->prev_widow_left_rect = 0; move16(); + test(); test(); test(); IF( is_init || MCT_flag || !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->element_mode, last_element_mode ) ) ) { - st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; + st->hTcxDec->NoiseLevelIndex_bfi = sub(PLC_MIN_STAT_BUFF_SIZE, 1); st->hTcxDec->CurrLevelIndex_bfi = 0; st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV; set16_fx( st->hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); @@ -1722,7 +1730,7 @@ void open_decoder_LPD_ivas_fx( hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); - hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; + hTcxDec->conNoiseLevelIndex = sub(PLC_MIN_STAT_BUFF_SIZE, 1); move16(); hTcxDec->conCurrLevelIndex = 0; move16(); @@ -1730,27 +1738,27 @@ void open_decoder_LPD_ivas_fx( 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 = -6; + hTcxDec->conLastFrameLevel_e = 0; move16(); + hTcxDec->conCngLevelBackgroundTrace_e = -6; move16(); - hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; + hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; move16(); } } - st->cummulative_damping = 32767 /*1.0f Q15*/; + st->cummulative_damping = 32767 /*1.0f Q15*/; move16(); - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) { st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); } - FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) { - st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ + st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; move16();/*Q14*/ } st->old_fpitch = L_deposit_h( st->pit_min ); - st->rate_switching_init = 1; + st->rate_switching_init = 1; move16(); - st->reset_mem_AR = 0; + st->reset_mem_AR = 0; move16(); /* For phase dispersion */ st->dm_fx.prev_gain_code = L_deposit_l( 0 ); @@ -1769,26 +1777,26 @@ void open_decoder_LPD_ivas_fx( IF( hTcxDec != NULL ) { st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX ); - + test(); test(); IF( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) { - hTcxDec->tcxltp_last_gain_unmodified = 0; + hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); } /* TCX */ hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); - hTcxDec->envWeighted = 0; + hTcxDec->envWeighted = 0; move16(); } 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 */ - hBPF->pst_mem_deemp_err_fx = 0; + hBPF->pst_mem_deemp_err_fx = 0; move16(); } ELSE { - st->lp_error_ener = 0; + st->lp_error_ener = 0; move32(); } st->mem_error = L_deposit_l( 0 ); IF( st->tcxonly ) @@ -1798,32 +1806,33 @@ void open_decoder_LPD_ivas_fx( } ELSE { - st->p_bpf_noise_buf = st->bpf_noise_buf; - st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; + st->p_bpf_noise_buf = st->bpf_noise_buf; move32(); + st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; move32(); } + test(); test(); test(); IF( EQ_16( bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { - st->tec_tfa = 1; + st->tec_tfa = 1; move16(); } ELSE { - st->tec_tfa = 0; + st->tec_tfa = 0; move16(); } - st->tec_flag = 0; - st->tfa_flag = 0; + st->tec_flag = 0; move16(); + st->tfa_flag = 0; move16(); /* needed in decoder to read the bitstream */ - st->enableGplc = 0; - - st->flagGuidedAcelp = 0; - st->tonal_mdct_plc_active = 0; - st->T0_4th = L_SUBFR; - st->guidedT0 = st->T0_4th; + st->enableGplc = 0; move16(); + st->flagGuidedAcelp = 0; move16(); + st->tonal_mdct_plc_active = 0; move16(); + st->T0_4th = L_SUBFR; move16(); + st->guidedT0 = st->T0_4th; move16(); + test(); test(); IF( st->hPlcInfo != NULL && GE_32( total_brate, HQ_48k ) && EQ_16( st->element_mode, EVS_MONO ) ) { - st->enablePlcWaveadjust = 1; + st->enablePlcWaveadjust = 1; move16(); IF( st->hTcxDec != NULL && ( EQ_16( st->ini_frame, 0 ) || LT_32( last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) ) { @@ -1832,23 +1841,24 @@ void open_decoder_LPD_ivas_fx( } ELSE { - st->enablePlcWaveadjust = 0; + st->enablePlcWaveadjust = 0; move16(); } /* PLC: [TCX: Tonal Concealment] */ + test(); test(); test(); IF( st->hTonalMDCTConc != NULL && !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) ) { - st->hTonalMDCTConc->nScaleFactors = 0; - st->hTonalMDCTConc->nSamples = 0; - st->hTonalMDCTConc->lastPcmOut = 0x0; - st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; - st->hTonalMDCTConc->lastBlockData.nSamples = 0; + st->hTonalMDCTConc->nScaleFactors = 0; move16(); + st->hTonalMDCTConc->nSamples = 0; move16(); + st->hTonalMDCTConc->lastPcmOut = 0x0; move16(); + st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; move16(); + st->hTonalMDCTConc->lastBlockData.nSamples = 0; move16(); TonalMDCTConceal_Init_ivas_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); } - st->last_tns_active = 0; - st->second_last_tns_active = 0; - st->second_last_core = -1; + st->last_tns_active = 0; move16(); + st->second_last_tns_active = 0; move16(); + st->second_last_core = -1; move16(); IF( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) { @@ -1861,31 +1871,31 @@ void open_decoder_LPD_ivas_fx( hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; move16(); } - + test(); test(); test(); test(); IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_32( st->element_mode, EVS_MONO ) ) { - st->dec_glr = 1; + st->dec_glr = 1; move16(); } ELSE { - st->dec_glr = 0; + st->dec_glr = 0; move16(); } - st->dec_glr_idx = 0; + st->dec_glr_idx = 0; move16(); - st->VAD = 0; + st->VAD = 0; move16(); IF( hTcxDec != NULL ) { - hTcxDec->enableTcxLpc = 1; - hTcxDec->old_gaintcx_bfi = 0; - hTcxDec->old_gaintcx_bfi_e = 0; + hTcxDec->enableTcxLpc = 1; move16(); + hTcxDec->old_gaintcx_bfi = 0; move16(); + hTcxDec->old_gaintcx_bfi_e = 0; move16(); - hTcxDec->tcx_hm_LtpPitchLag = -1; + hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); } IF( st->hTcxCfg != NULL ) { - st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; move16(); } return; diff --git a/lib_dec/core_dec_reconf_fx.c b/lib_dec/core_dec_reconf_fx.c index bb2f4c404..b90e755c4 100644 --- a/lib_dec/core_dec_reconf_fx.c +++ b/lib_dec/core_dec_reconf_fx.c @@ -26,7 +26,7 @@ void reconfig_decoder_LPD_ivas_fx( Word32 lowrate_tcxlpc_max_br; move16(); - st->bits_frame = bits_frame; + st->bits_frame = bits_frame; move16(); IF( EQ_16( bwidth, NB ) ) { @@ -42,15 +42,15 @@ void reconfig_decoder_LPD_ivas_fx( BITS_ALLOC_init_config_acelp( st->total_brate, 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; + st->acelp_cfg_rf.mode_index = 1; move16(); + st->acelp_cfg_rf.midLpc = 0; move16(); + st->acelp_cfg_rf.midLpc_enable = 0; move16(); + st->acelp_cfg_rf.pre_emphasis = 0; move16(); + st->acelp_cfg_rf.formant_enh = 1; move16(); + st->acelp_cfg_rf.formant_tilt = 1; move16(); + st->acelp_cfg_rf.voice_tilt = 1; move16(); + st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; move16(); + st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; move16(); IF( NE_16( st->element_mode, IVAS_SCE ) ) { @@ -82,7 +82,7 @@ void reconfig_decoder_LPD_ivas_fx( { IF( st->rf_flag ) { - i--; + i = sub(i, 1); } st->hTcxCfg->na_scale = scaleTcxTable[i].scale; move16(); @@ -141,11 +141,11 @@ void reconfig_decoder_LPD_ivas_fx( IF( GT_16( st->L_frame, st->last_L_frame ) ) { oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); - newLen = L_SYN_MEM_CLAS_ESTIM; + newLen = L_SYN_MEM_CLAS_ESTIM; move16(); } ELSE { - oldLen = L_SYN_MEM_CLAS_ESTIM; + oldLen = L_SYN_MEM_CLAS_ESTIM; move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } 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 ); @@ -170,7 +170,7 @@ void reconfig_decoder_LPD_ivas_fx( IF( EQ_16( st->ini_frame, 0 ) ) { - hTcxDec->envWeighted = 0; + hTcxDec->envWeighted = 0; move16(); move16(); } @@ -205,7 +205,7 @@ void reconfig_decoder_LPD_fx( move16(); st->narrowBand = 1; } - ELSE if ( GT_16( bwidth, NB ) ) + ELSE IF ( GT_16( bwidth, NB ) ) { move16(); st->narrowBand = 0; @@ -214,15 +214,15 @@ void reconfig_decoder_LPD_fx( BITS_ALLOC_init_config_acelp( st->total_brate, 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; + st->acelp_cfg_rf.mode_index = 1; move16(); + st->acelp_cfg_rf.midLpc = 0; move16(); + st->acelp_cfg_rf.midLpc_enable = 0; move16(); + st->acelp_cfg_rf.pre_emphasis = 0; move16(); + st->acelp_cfg_rf.formant_enh = 1; move16(); + st->acelp_cfg_rf.formant_tilt = 1; move16(); + st->acelp_cfg_rf.voice_tilt = 1; move16(); + st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; move16(); + st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; move16(); IF( NE_16( st->element_mode, IVAS_SCE ) ) @@ -238,7 +238,7 @@ void reconfig_decoder_LPD_fx( } move16(); - if ( st->hTcxCfg != NULL ) + IF ( st->hTcxCfg != NULL ) { Word16 i; @@ -247,7 +247,7 @@ void reconfig_decoder_LPD_fx( test(); IF( ( LT_16( bwidth, SWB ) ) && !( st->tcxonly ) ) { - Word16 scaleTableSize = sizeof( scaleTcxTable ) / sizeof( scaleTcxTable[0] ); /* is a constant */ + Word16 scaleTableSize = idiv1616(sizeof( scaleTcxTable ), sizeof( scaleTcxTable[0] )); /* is a constant */ FOR( i = 0; i < scaleTableSize; i++ ) { @@ -257,9 +257,9 @@ void reconfig_decoder_LPD_fx( ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) { - if ( st->rf_flag ) + IF ( st->rf_flag ) { - i--; + i = sub(i,1); } st->hTcxCfg->na_scale = scaleTcxTable[i].scale; move16(); @@ -270,7 +270,7 @@ void reconfig_decoder_LPD_fx( } /*if its not the first frame resample overlap buffer to new sampling rate */ - IF( st->ini_frame != 0 ) + IF( NE_16(st->ini_frame, 0 )) { test(); test(); @@ -318,12 +318,12 @@ void reconfig_decoder_LPD_fx( IF( GT_16( st->L_frame, st->last_L_frame ) ) { oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); - newLen = L_SYN_MEM_CLAS_ESTIM; + newLen = L_SYN_MEM_CLAS_ESTIM; move16(); move16(); } ELSE { - oldLen = L_SYN_MEM_CLAS_ESTIM; + oldLen = L_SYN_MEM_CLAS_ESTIM; move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } 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 ); @@ -344,10 +344,10 @@ void reconfig_decoder_LPD_fx( move16(); IF( GT_16( st->element_mode, IVAS_SCE ) ) { - lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE; + lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE; move16(); } 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 == 0 ) + IF ( EQ_16(st->ini_frame, 0 )) { hTcxDec->envWeighted = 0; move16(); diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 5241b42e0..32fbc67ac 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -47,7 +47,7 @@ void mode_switch_decoder_LPD_fx( bSwitchFromAmrwbIO = 0; move16(); - if ( EQ_16( st->last_core, AMR_WB_CORE ) ) + IF ( EQ_16( st->last_core, AMR_WB_CORE ) ) { bSwitchFromAmrwbIO = 1; move16(); @@ -62,12 +62,12 @@ void mode_switch_decoder_LPD_fx( st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( bwidth ); test(); test(); - IF( ( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, ( FSCALE_DENOM * 16000 ) / 12800 ) ) && ( EQ_16( fscale, st->fscale ) ) ) ) + IF( ( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, 640 ) ) && ( EQ_16( fscale, st->fscale ) ) ) ) { test(); test(); test(); - if ( ( ( GT_32( total_brate, 32000 ) ) && ( st->tcxonly == 0 ) ) || ( ( LE_32( total_brate, 32000 ) ) && ( st->tcxonly != 0 ) ) ) + IF ( ( ( GT_32( total_brate, 32000 ) ) && ( EQ_16( st->tcxonly, 0) ) ) || ( ( LE_32( total_brate, 32000 ) ) && ( NE_16(st->tcxonly, 0 )) ) ) { switchWB = 1; move16(); @@ -75,7 +75,7 @@ void mode_switch_decoder_LPD_fx( } test(); - if ( GT_16( st->last_L_frame, L_FRAME16k ) && LE_32( total_brate, ACELP_32k ) ) + IF ( GT_16( st->last_L_frame, L_FRAME16k ) && LE_32( total_brate, ACELP_32k ) ) { switchWB = 1; move16(); @@ -100,7 +100,7 @@ void mode_switch_decoder_LPD_fx( test(); test(); test(); - IF( NE_16( fscale, st->fscale ) || switchWB != 0 || bSwitchFromAmrwbIO != 0 || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) + IF( NE_16( fscale, st->fscale ) || NE_16(switchWB, 0) || NE_16(bSwitchFromAmrwbIO, 0) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT open_decoder_LPD_fx( st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0 ); @@ -136,7 +136,7 @@ void mode_switch_decoder_LPD_fx( st->narrowBand = 0; move16(); - if ( EQ_16( bwidth, NB ) ) + IF ( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; move16(); @@ -149,7 +149,7 @@ void mode_switch_decoder_LPD_fx( st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode ); move16(); - IF( st->hTcxCfg->fIsTNSAllowed != 0 && st->hIGFDec != NULL ) + IF( NE_16(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 @@ -165,7 +165,7 @@ void mode_switch_decoder_LPD_fx( reconfig_decoder_LPD_fx( st, frame_size, bwidth, total_brate, st->last_L_frame ); test(); - IF( hTcxDec->envWeighted != 0 && hTcxDec->enableTcxLpc == 0 ) + IF( NE_16(hTcxDec->envWeighted, 0) && EQ_16(hTcxDec->enableTcxLpc, 0 )) { Copy( st->lspold_uw, st->lsp_old_fx, M ); Copy( st->lsfold_uw, st->lsf_old_fx, M ); @@ -174,7 +174,7 @@ void mode_switch_decoder_LPD_fx( } /* update PLC LSF memories */ - IF( st->tcxonly == 0 ) + IF( EQ_16(st->tcxonly, 0 )) { lsp2lsf_fx( st->lsp_old_fx, st->lsfoldbfi1_fx, M, extract_l( st->sr_core ) ); } @@ -185,7 +185,7 @@ void mode_switch_decoder_LPD_fx( Copy( st->lsfoldbfi1_fx, st->lsfoldbfi0_fx, M ); Copy( st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx, M ); - IF( st->igf != 0 && hBWE_TD != NULL ) + IF( NE_16(st->igf, 0) && hBWE_TD != NULL ) { test(); test(); @@ -217,7 +217,7 @@ void mode_switch_decoder_LPD_fx( test(); 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 ) + IF( EQ_16(st->tec_tfa, 0 )) { set16_fx( st->hTECDec->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); } @@ -304,12 +304,12 @@ void mode_switch_decoder_LPD_ivas_fx( test(); test(); - IF( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, ( FSCALE_DENOM * 16000 ) / 12800 ) ) && ( EQ_16( fscale, st->fscale ) ) ) + IF( ( GE_16( bwidth, WB ) ) && ( EQ_16( fscale, 640 ) ) && ( EQ_16( fscale, st->fscale ) ) ) { test(); test(); test(); - IF( ( ( GT_32( total_brate, ACELP_32k ) ) && ( st->tcxonly == 0 ) ) || ( ( LE_32( total_brate, ACELP_32k ) ) && EQ_16( st->tcxonly, 1 ) ) ) + IF( ( ( GT_32( total_brate, ACELP_32k ) ) && ( EQ_16( st->tcxonly, 0) ) ) || ( ( LE_32( total_brate, ACELP_32k ) ) && EQ_16( st->tcxonly, 1 ) ) ) { switchWB = 1; move16(); @@ -327,13 +327,13 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hIGFDec != NULL ) { - st->hIGFDec->infoIGFStopFreq = -1; + st->hIGFDec->infoIGFStopFreq = -1; move16(); } move16(); test(); test(); - IF( st->igf && ( st->idchan == 0 || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) + IF( st->igf && ( EQ_16(st->idchan, 0) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { /* switch IGF configuration */ IGFDecSetMode_ivas_fx( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); @@ -359,7 +359,7 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - st->output_frame_fx = st->hTcxDec->L_frameTCX; + st->output_frame_fx = st->hTcxDec->L_frameTCX; move16(); } IF( st->hTcxCfg != NULL ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 148c40a3c..a8f882eb9 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3219,32 +3219,21 @@ void ivas_dirac_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - float *output_f[] /* o : rendered time signal */ + Word32 *output_fx[] /* o : rendered time signal */ ) { Word16 slots_to_render, first_sf, last_sf, subframe_idx; UWord16 slot_size, n_samples_sf, ch, nchan_intern; Word16 temp = 0; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; - float *output_f_local[MAX_OUTPUT_CHANNELS]; -#ifdef MSAN_FIX - float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV -#else - float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // VE2SB: TBV -#endif - Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; - Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // VE2SB: TBV - Word32 output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; + Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_intern = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); FOR( ch = 0; ch < nchan_intern; ch++ ) { - output_f_local[ch] = output_f_local_buff[ch]; - set_zero( output_f_local_buff[ch], nSamplesAsked ); - output_f_local_fx[ch] = output_f_local_buff_fx[ch]; set_zero_fx( output_f_local_fx[ch], nSamplesAsked ); } @@ -3271,7 +3260,7 @@ void ivas_dirac_dec_render_fx( FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { #ifdef MSAN_FIX - ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local, output_f_local_fx, nchan_transport, NULL, NULL ); + ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local_fx, nchan_transport, NULL, NULL ); #else ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local, nchan_transport, NULL, NULL ); #endif // MSAN_FIX @@ -3280,7 +3269,6 @@ void ivas_dirac_dec_render_fx( FOR( ch = 0; ch < nchan_intern; ch++ ) { - output_f_local[ch] += n_samples_sf; output_f_local_fx[ch] += n_samples_sf; } @@ -3292,7 +3280,6 @@ void ivas_dirac_dec_render_fx( { IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) { - mvr2r( output_f_local_buff[ch], output_f[ch], *nSamplesRendered ); Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); } } @@ -3406,10 +3393,7 @@ void ivas_dirac_dec_render( void ivas_dirac_dec_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#ifdef MSAN_FIX Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ -#endif // MSAN_FIX const Word16 nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], Word32 *pppQMfFrame_ts_im_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) @@ -4981,7 +4965,7 @@ void ivas_dirac_dec_render_sf_fx( #ifdef IVAS_FLOAT_FIXED /////////////////////////////////////////////////////// FIXED TO FLOAT ////////////////////////////////////////////////////////////////////////////////////////// - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF(EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD)) { hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; @@ -4993,7 +4977,6 @@ void ivas_dirac_dec_render_sf_fx( { scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; - fixedToFloat_arrL( output_buf_fx[i], output_f[i], Q11, index_slot * hSpatParamRendCom->num_freq_bands + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] ); } } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) @@ -5054,44 +5037,15 @@ void ivas_dirac_dec_render_sf_fx( Word16 tmp_lfe_idx = 0; for ( ch = 0; ch < outchannels; ch++ ) { - // fixedToFloat_arrL(output_buf_fx[i], output_f[i], Q11, index_slot * hSpatParamRendCom->num_freq_bands + hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx]); IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) ) { - IF( st_ivas->mc_mode == MC_MODE_MCMASA && !hDirACRend->hOutSetup.separateChannelEnabled ) - { - // Fixed to float - fixedToFloat_arrL( output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands + index_slot * hSpatParamRendCom->num_freq_bands ); - } - ELSE IF( st_ivas->mc_mode == MC_MODE_MCMASA && hDirACRend->hOutSetup.separateChannelEnabled ) - { - /* LFE has been synthesized in the time domain, do nothing. */ - } - ELSE - { - // Float to fixed. - fixedToFloat_arrL( output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands + index_slot * hSpatParamRendCom->num_freq_bands ); - } IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { tmp_lfe_idx = add( tmp_lfe_idx, 1 ); } } - ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) - { - /* The separated channel is already set to output_f[hOutSetup.separateChannelIndex]. Thus, the separated - * channel is combined with the synthesized channels here. */ - } - ELSE - { - // Fixed to float - fixedToFloat_arrL( output_buf_fx[ch], output_f[ch], Q11, hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] + index_slot * hSpatParamRendCom->num_freq_bands ); - } } } - else - { - /* NOTE: according to line coverage report this part is not being hit by any test case. Not adding fixed to float conversion here. */ - } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 5b5fcfb55..9d528f8df 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -4638,9 +4638,6 @@ void ivas_destroy_dec( } ELSE IF( st_ivas->hHrtfTD != NULL ) { -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); -#endif BSplineModelEvalDealloc_fx( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD ); } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 7002b0453..bb7d374a9 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -2566,26 +2566,22 @@ void ivas_jbm_dec_feed_tc_to_renderer( * Principal IVAS JBM rendering routine *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -ivas_error ivas_jbm_dec_render( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const uint16_t nSamplesAsked, /* i : number of samples wanted */ - uint16_t *nSamplesRendered, /* o : number of samples rendered */ - uint16_t *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ - int16_t *data /* o : output synthesis signal */ +ivas_error ivas_jbm_dec_render_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const UWord16 nSamplesAsked, /* i : number of samples wanted */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ + Word16 *data /* o : output synthesis signal */ ) { - int16_t n, nchan_out; - int16_t nchan_transport; - int16_t nchan_remapped; - int32_t output_Fs; + Word16 n, nchan_out; + Word16 nchan_transport; + Word16 nchan_remapped; + Word32 output_Fs; AUDIO_CONFIG output_config; - int16_t nSamplesAskedLocal; + Word16 nSamplesAskedLocal; ivas_error error; - float *p_output[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS] = { NULL }; - // float *p_tc[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS] = { NULL }; Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - Word32 tmp_buffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; - Word32 *p_temp_fx[MAX_OUTPUT_CHANNELS]; Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS]; Word16 subframe_len, gd_bits, exp, nchan_in, i, j; const Word16 output_q_factor = Q11; @@ -2598,35 +2594,35 @@ ivas_error ivas_jbm_dec_render( hSpatParamRendCom = st_ivas->hSpatParamRendCom; output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); nchan_out = st_ivas->hDecoderConfig->nchan_out; + move16(); nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm; + move16(); output_config = st_ivas->hDecoderConfig->output_config; + move32(); nSamplesAskedLocal = nSamplesAsked + st_ivas->hTcBuffer->n_samples_discard; + move16(); - for ( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { - p_output[n] = st_ivas->p_output_f[n]; p_output_fx[n] = st_ivas->p_output_fx[n]; } - for ( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - p_temp_fx[i] = tmp_buffer_fx[i]; - } - if ( !st_ivas->hDecoderConfig->Opt_tsm ) + IF( !st_ivas->hDecoderConfig->Opt_tsm ) { - for ( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) + FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) { p_tc_fx[n] = p_output_fx[n]; } - for ( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ ) + FOR( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; } } - else + ELSE { - for ( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) + FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ ) { p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered]; } @@ -2634,15 +2630,16 @@ ivas_error ivas_jbm_dec_render( #ifdef MSAN_FIX st_ivas->hTcBuffer->no_channels = st_ivas->hTcBuffer->nchan_buffer_full; + move16(); #endif // MSAN_FIX /*----------------------------------------------------------------* * Update combined orientation access index *----------------------------------------------------------------*/ - if ( st_ivas->hCombinedOrientationData != NULL ) + IF( st_ivas->hCombinedOrientationData != NULL ) { /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */ - st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start -= st_ivas->hTcBuffer->n_samples_discard; + st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start = sub( st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start, st_ivas->hTcBuffer->n_samples_discard ); ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData ); } @@ -2650,184 +2647,81 @@ ivas_error ivas_jbm_dec_render( /*----------------------------------------------------------------* * Rendering *----------------------------------------------------------------*/ - - if ( st_ivas->ivas_format == UNDEFINED_FORMAT ) + test(); + IF( EQ_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) ) { assert( 0 ); } - else if ( st_ivas->hTcBuffer->tc_buffer_mode == TC_BUFFER_MODE_BUFFER ) + ELSE IF( EQ_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) ) { Word16 slot_size, tmp, e; slot_size = st_ivas->hTcBuffer->n_samples_granularity; + move16(); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e ); tmp = shr( tmp, sub( 15, e ) ); - // slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); - FOR( Word16 ind = 0; ind < st_ivas->hTcBuffer->nchan_transport_jbm; ind++ ) - { - floatToFixed_arrL( p_output[ind], p_output_fx[ind], Q11, s_max( *nSamplesRendered, nSamplesAskedLocal ) ); - } ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); - - FOR( Word16 ind = 0; ind < st_ivas->hTcBuffer->nchan_transport_jbm; ind++ ) - { - fixedToFloat_arrL( p_output_fx[ind], p_output[ind], Q11, s_max( *nSamplesRendered, nSamplesAskedLocal ) ); - } } - else if ( st_ivas->ivas_format == STEREO_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) ) { /* Rendering */ - if ( st_ivas->renderer_type == RENDERER_MC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - Word16 q; - q = 11; + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } } - else if ( st_ivas->ivas_format == ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { /* Rendering */ - if ( st_ivas->ism_mode == ISM_MODE_PARAM ) + IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) ) { - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output_fx[0][lp] = (Word32) ( p_output[0][lp] * ( 1u << 11 ) ); - p_output_fx[1][lp] = (Word32) ( p_output[1][lp] * ( 1u << 11 ) ); - } + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); Word16 non_diegetic_pan_gain_fx = (Word16) ( 32767 * st_ivas->hDecoderConfig->non_diegetic_pan_gain ); ivas_apply_non_diegetic_panning_fx( p_output_fx, non_diegetic_pan_gain_fx, *nSamplesRendered ); - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output[0][lp] = (float) p_output_fx[0][lp] / ( 1u << 11 ); - p_output[1][lp] = (float) p_output_fx[1][lp] / ( 1u << 11 ); - } } - else if ( st_ivas->renderer_type == RENDERER_PARAM_ISM || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { - Word32 output_fx_tmp[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; - Word16 ch; - Word32 *p_output_fx_tmp[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; - FOR( Word16 lp = 0; lp < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; lp++ ) - { - p_output_fx_tmp[lp] = &output_fx_tmp[lp][0]; - } - - Word16 Q_p_output_buf = Q11; - FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx_tmp[i], Q_p_output_buf, L_FRAME48k ); - } - /*-------------------------------------------flt 2 fix----------------------------------------------------------*/ - /*-----following buffers and values are getting used in the function and hence are in the intermediate conv-----*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin-------------------------------------norm-Q-*/ - /*i/o : st_ivas->hParamIsmDec->hParamIsmRendering->mixing_matrix_lin_old---------------------------------norm-Q-*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->interpolator------------------------------------------Q14----*/ - /*i/o : st_ivas->hParamIsmDec->azimuth_values------------------------------------------------------------Q22----*/ - /*i/o : st_ivas->hParamIsmDec->elevation_values----------------------------------------------------------Q22----*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc-----------------------------------norm-Q-*/ - /*i : st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc-----------------------------------norm-Q-*/ - /*i/o : st_ivas->cldfbSynDec[ch]->cldfb_state------------------------------------------------------------Q11----*/ - /*--------------------------------------------------------------------------------------------------------------*/ - - Word16 n_out; - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) - { - n_out = st_ivas->nchan_ism; - } - else - { - n_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; - } - - /*-------------------------------------flt 2 fix----------------------------------------------------------*/ - - ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx_tmp ); - - /*-----------------------------------------fix 2 flt--------------------------------------------*/ - for ( ch = 0; ch < n_out; ch++ ) - { - fixedToFloat_arrL( p_output_fx_tmp[ch], p_output[ch], Q11, L_FRAME48k ); - } - /*-----------------------------------------fix 2 flt--------------------------------------------*/ + ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); - - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { /* Convert CICP19 -> Ambisonics */ -#if 1 - FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, *nSamplesRendered ); - } -#endif ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } } } - else /* ISM_MODE_DISC */ + ELSE /* ISM_MODE_DISC */ { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + test(); + test(); /* Loudspeaker or Ambisonics rendering */ - if ( st_ivas->renderer_type == RENDERER_TD_PANNING || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */ - Word16 q = 11; ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); - FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) - { - p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); - } - } } - else if ( st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output_fx[0][lp] = (Word32) ( p_output[0][lp] * ( 1u << 11 ) ); - p_output_fx[1][lp] = (Word32) ( p_output[1][lp] * ( 1u << 11 ) ); - } Word16 non_diegetic_pan_gain_fx = (Word16) ( 32767 * st_ivas->hDecoderConfig->non_diegetic_pan_gain ); ivas_apply_non_diegetic_panning_fx( p_output_fx, non_diegetic_pan_gain_fx, *nSamplesRendered ); - for ( int lp = 0; lp < L_FRAME48k; lp++ ) - { - p_output[0][lp] = (float) p_output_fx[0][lp] / ( 1u << 11 ); - p_output[1][lp] = (float) p_output_fx[1][lp] / ( 1u << 11 ); - } } - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { /* Convert to Ambisonics; used also for ISM->HOA3->binaural rendering */ #ifdef MSAN_FIX @@ -2835,8 +2729,10 @@ ivas_error ivas_jbm_dec_render( { FOR( j = 0; j < 16; j++ ) { - st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 + move32(); st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29 + move32(); } } #else @@ -2849,21 +2745,23 @@ ivas_error ivas_jbm_dec_render( } } #endif - Word16 Q_buffer_in = 11; ivas_ism2sba_sf_fx( st_ivas->hTcBuffer->tc_fx, p_output_fx, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order ); Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) ); FOR( j = 0; j < sba_num_chans; j++ ) { - fixedToFloat_arrL( p_output_fx[j], p_output[j], Q_buffer_in + 29 - 31, *nSamplesRendered ); + scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); } + #ifdef MSAN_FIX FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { FOR( j = 0; j < 16; j++ ) { - st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30 + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30 + move32(); st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30 + move32(); } } #else @@ -2879,566 +2777,315 @@ ivas_error ivas_jbm_dec_render( } /* Binaural rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output_fx[i][j] = floatToFixed( p_output[i][j], Q11 ); - } - } IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } - - // Fixed to float - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output[i][j] = fixedToFloat( p_output_fx[i][j], Q11 ); - } - } } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); gd_bits = find_guarded_bits_fx( subframe_len ); exp = 13; + move16(); nchan_in = 12; + move16(); nchan_out = 2; - exp -= gd_bits; + move16(); + exp = sub( exp, gd_bits ); *st_ivas->hCrendWrapper->p_io_qfactor = exp; - for ( i = 0; i < nchan_in; i++ ) + move16(); + FOR( i = 0; i < nchan_in; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - - p_temp_fx[i][j] = (Word32) float_to_fixed( p_output[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); } - if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_temp_fx, p_temp_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) { return error; } - for ( i = 0; i < nchan_out; i++ ) + FOR( i = 0; i < nchan_out; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - - p_output[i][j] = fixed_to_float( p_temp_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); } } } } - else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { nchan_remapped = nchan_transport; - + move16(); + test(); + test(); /* Loudspeakers, Ambisonics or Binaural rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else if ( st_ivas->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_DEC ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - for ( n = 0; n < nchan_remapped; n++ ) + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + FOR( n = 0; n < nchan_remapped; n++ ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); -#endif } -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) { return error; } -#if 1 // To Be removed - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif -#else - if ( ( error = ivas_sba_linear_renderer( p_output, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_DIRAC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { - ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ); + ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); } } - else + ELSE { -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - hSpar->hMdDec->Q_mixer_mat = 30; -#endif // - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif } } - else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nchan_remapped = st_ivas->nchan_transport; - - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + move16(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - if ( ( error = ivas_omasa_dirac_td_binaural_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ) ) != IVAS_ERR_OK ) - { - return error; - } -#else IF( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ) != IVAS_ERR_OK ) { return error; } - - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else + ELSE { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } } - else if ( st_ivas->renderer_type == RENDERER_DIRAC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { - ivas_omasa_dirac_rend_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); + ivas_omasa_dirac_rend_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); } } - else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { nchan_remapped = nchan_transport; - + move16(); /* Loudspeakers, Ambisonics or Binaural rendering */ - if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; hSpar->hMdDec->Q_mixer_mat = 30; -#endif // IF( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, output_q_factor, 960 ) ) != IVAS_ERR_OK ) { return error; } - -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif - -#if 1 /*TODO: remove fixed to float conversions */ - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output[i][j] = fixedToFloat( p_output_fx[i][j], Q11 ); - } - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_OSBA_STEREO ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + test(); /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/ - if ( st_ivas->nchan_ism == 1 && st_ivas->hDecoderConfig->Opt_tsm == 0 ) + IF( EQ_16( st_ivas->nchan_ism, 1 ) && EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) ) { -#ifdef IVAS_FLOAT_FIXED Copy32( p_tc_fx[2], p_output_fx[3], *nSamplesRendered ); Copy32( p_tc_fx[1], p_output_fx[2], *nSamplesRendered ); p_tc_fx[1] = p_output_fx[2]; p_tc_fx[2] = p_output_fx[3]; - - fixedToFloat_arrL( p_output_fx[2], p_output[2], 11, *nSamplesRendered ); - fixedToFloat_arrL( p_output_fx[3], p_output[3], 11, *nSamplesRendered ); -#else - mvr2r( p_tc[2], p_output[3], *nSamplesRendered ); - mvr2r( p_tc[1], p_output[2], *nSamplesRendered ); - p_tc[1] = p_output[2]; - p_tc[2] = p_output[3]; -#endif } /* render objects */ - Word16 q = 11; ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ); - FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < *nSamplesRendered; ind2++ ) - { - p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); - } - } /* add already rendered SBA part */ - for ( n = 0; n < nchan_out; n++ ) + FOR( n = 0; n < nchan_out; n++ ) { -#ifdef IVAS_FLOAT_FIXED v_add_fixed( p_output_fx[n], p_tc_fx[n + st_ivas->nchan_ism], p_output_fx[n], *nSamplesRendered, 0 ); - - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, *nSamplesRendered ); -#else - v_add( p_output[n], p_tc[n + st_ivas->nchan_ism], p_output[n], *nSamplesRendered ); -#endif } } - else if ( st_ivas->renderer_type == RENDERER_OSBA_AMBI || st_ivas->renderer_type == RENDERER_OSBA_LS || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - Word16 q = 11; IF( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ) != IVAS_ERR_OK ) { return error; } - q = Q11; - FOR( Word16 ind1 = 0; ind1 < s_max( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe, s_max( st_ivas->nchan_transport, st_ivas->nchan_ism ) ); ind1++ ) - { - FOR( Word16 ind2 = 0; ind2 < L_FRAME48k; ind2++ ) - { - p_output[ind1][ind2] = (float) ( p_output_fx[ind1][ind2] ) / (float) ( 1 << q ); - } - } } - else if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) /*EXT output = individual objects + HOA3*/ + ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/ { -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; hSpar->hMdDec->Q_mixer_mat = 30; -#endif // - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism], 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif - for ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered ); - - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output[n], *nSamplesRendered ); -#endif } } - else + ELSE { - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - floatToFixed_arr32( p_output[n], p_output_fx[n], Q11, 960 ); - } -#if 1 /*Float to fixed conversion*/ SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; hSpar->hMdDec->Q_mixer_mat = 30; -#endif // - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif } } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else + ELSE { - if ( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, 960 ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /*Fixed to float */ - for ( n = 0; n < st_ivas->p_out_len; n++ ) - { - fixedToFloat_arrL( p_output_fx[n], p_output[n], 11, 960 ); - } -#endif - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { - for ( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) + FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- ) { - mvr2r( p_output[n], p_output[n + st_ivas->nchan_ism], *nSamplesRendered ); + Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered ); } - for ( n = 0; n < st_ivas->nchan_ism; n++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - set_zero( p_output[n], *nSamplesRendered ); + set32_fx( p_output_fx[n], 0, *nSamplesRendered ); } } } } - else if ( st_ivas->ivas_format == MC_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) { - if ( st_ivas->mc_mode == MC_MODE_MCT ) + IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { - int16_t crendInPlaceRotation = FALSE; - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - if ( st_ivas->transport_config != st_ivas->intern_config && ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_FOA || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->intern_config == IVAS_AUDIO_CONFIG_HOA3 ) ) + Word16 crendInPlaceRotation = FALSE; + move16(); + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + + test(); + test(); + test(); + IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) ) { - if ( ( st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe ) < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) ) + IF( LT_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) ) { crendInPlaceRotation = TRUE; -#ifdef IVAS_FLOAT_FIXED + move16(); + ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX ); -#if 1 - FOR( i = 0; i < ( st_ivas->hIntSetup.ambisonics_order + 1 ) * ( st_ivas->hIntSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hTransSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE ); -#endif // IVAS_FLOAT_FIXED } } + test(); /* Rendering */ - if ( st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV || st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) { st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor; - subframe_len = st_ivas->hTcBuffer->subframe_nbslots[0] * st_ivas->hTcBuffer->n_samples_granularity; + subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity ); gd_bits = find_guarded_bits_fx( subframe_len ); exp = 13; - if ( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ) != IVAS_ERR_OK ) + move16(); + IF( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ) != IVAS_ERR_OK ) { return error; } - if ( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ) != IVAS_ERR_OK ) + IF( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ) != IVAS_ERR_OK ) { return error; } - exp -= gd_bits; + exp = sub( exp, gd_bits ); *st_ivas->hCrendWrapper->p_io_qfactor = exp; - for ( i = 0; i < nchan_in; i++ ) + move16(); + + FOR( i = 0; i < nchan_in; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output_fx[i][j] = (Word32) float_to_fixed( p_output[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); } - if ( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, - &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) - - + IF( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, + &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) { return error; } ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); - for ( i = 0; i < nchan_in; i++ ) + FOR( i = 0; i < nchan_in; i++ ) { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output[i][j] = fixed_to_float( p_output_fx[i][j], *st_ivas->hCrendWrapper->p_io_qfactor ); - } + scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); } } - else if ( st_ivas->renderer_type == RENDERER_MC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) { - *nSamplesRendered = min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - Word16 q = 11; + *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); + ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { -#ifdef IVAS_FLOAT_FIXED ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hIntSetup, p_tc, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f ); -#endif } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { -#if 1 /* TODO: remove float to fix conversions: */ - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output_fx[i][j] = floatToFixed( p_output[i][j], output_q_factor ); - } - } -#endif IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, output_q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } -#if 1 /* TODO: remove Fixed to float */ - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - for ( j = 0; j < L_FRAME48k; j++ ) - { - p_output[i][j] = fixedToFloat( p_output_fx[i][j], Q11 ); - } - } -#endif - - Word16 q = 11; - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx ); - - FOR( i = 0; i < st_ivas->nchan_transport; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) - { - if ( p_output[i] != NULL ) - { - // fixedToFloat_arrL(p_output_fx[i], p_output[i], 11, 960); - floatToFixed_arrL( p_output[i], p_output_fx[i], 11, 960 ); - } - } - ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx ); - FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) - { - if ( p_output[i] != NULL ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], 11, 960 ); - } - } - + test(); + test(); /* Rendering */ - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && !st_ivas->hDecoderConfig->Opt_Headrotation ) + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && !st_ivas->hDecoderConfig->Opt_Headrotation ) { - { - Word16 q = 11; - - ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); - - FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, MC_PARAMUPMIX_MAX_INPUT_CHANS ); ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } - } + ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); } - else if ( st_ivas->renderer_type == RENDERER_MC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) { - Word16 q = 11; - ivas_ls_setup_conversion_fx( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output_fx, p_output_fx ); - FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, MC_PARAMUPMIX_MAX_INPUT_CHANS ); ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } - else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { -#ifdef IVAS_FLOAT_FIXED ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f ); -#endif } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { -#ifdef IVAS_FLOAT_FIXED - // Word32 output_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - // Word32 *p_output_fx[MAX_OUTPUT_CHANNELS]; #ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, L_FRAME48k ); - p_output_fx[i] = p_output_fx[i]; - } - - Word16 num_subframes = (int16_t) ( ( *nSamplesRendered * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ); - for ( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) + Word16 num_subframes = (Word16) ( ( *nSamplesRendered * FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) / output_Fs ); + FOR( Word16 subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { Word16 idx = subframe_idx; Word16 pos_q = Q25; @@ -3452,40 +3099,18 @@ ivas_error ivas_jbm_dec_render( } } #endif - if ( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) - { - return error; - } -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, L_FRAME48k ); - } -#endif - -#else - if ( ( error = ivas_td_binaural_renderer( st_ivas, p_output, *nSamplesRendered ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } -#endif - - Word16 q = 11; ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx ); - - FOR( i = 0; i < max( st_ivas->hDecoderConfig->nchan_out, MC_PARAMUPMIX_MAX_INPUT_CHANS ); ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], q, *nSamplesRendered ); - } } } - else if ( st_ivas->mc_mode == MC_MODE_PARAMMC ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) { -#ifdef IVAS_FLOAT_FIXED #if 1 // ftf changes - int16_t channel_active_fx[MAX_OUTPUT_CHANNELS]; - // uint16_t nchan_out_init; + Word16 channel_active_fx[MAX_OUTPUT_CHANNELS]; Word16 nchan_out_cov; Word16 nchan_out_cldfb = 0; @@ -3493,34 +3118,39 @@ ivas_error ivas_jbm_dec_render( Word16 nchan_transport_tmp = st_ivas->nchan_transport; output_Fs = st_ivas->hDecoderConfig->output_Fs; Word16 nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; - // nchan_out_init = nchan_out_transport; - - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { nchan_out_cldfb = BINAURAL_CHANNELS; + move16(); set_s( channel_active_fx, 1, BINAURAL_CHANNELS ); - nchan_out_cov = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); } - else if ( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB ) + ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) { nchan_out_cov = nchan_out_transport; - nchan_out_cldfb = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + move16(); + nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); } - else if ( st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || st_ivas->hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); nchan_out_cldfb = nchan_out_cov; + move16(); set_s( channel_active_fx, 1, nchan_out_cov ); } - else + ELSE { nchan_out_cov = nchan_out_transport; + move16(); nchan_out_cldfb = nchan_out_transport; + move16(); set_s( channel_active_fx, 1, nchan_out_cov ); } // ftf for ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx // ftf changes - if ( st_ivas->hParamMC->max_band_decorr > 0 ) + IF( GT_16( st_ivas->hParamMC->max_band_decorr, 0 ) ) { // ftf for param_mc_protoSignalComputation_fx FOR( Word16 x = 0; x < st_ivas->hParamMC->diff_proto_info->num_protos_diff; x++ ) @@ -3537,22 +3167,25 @@ ivas_error ivas_jbm_dec_render( scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer += tmp; } - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { - if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + test(); + IF( st_ivas->hCombinedOrientationData && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { Word16 Q_hoa_encoder = 31; + move16(); floatToFixed_arrL( st_ivas->hParamMC->hoa_encoder, st_ivas->hParamMC->hoa_encoder_fx, Q_hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } - // ftf for ivas_binRenderer_fx /* CLDFB synthesis */ - for ( int ch = 0; ch < nchan_out_cldfb; ch++ ) + FOR( Word16 ch = 0; ch < nchan_out_cldfb; ch++ ) { - if ( st_ivas->cldfbSynDec[ch] ) + IF( st_ivas->cldfbSynDec[ch] ) { scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, Q11 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; + move16(); } } @@ -3572,139 +3205,90 @@ ivas_error ivas_jbm_dec_render( } #endif ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx ); -#if 1 // ftf changes - for ( int ch = 0; ch < nchan_out_cldfb; ch++ ) + FOR( int ch = 0; ch < nchan_out_cldfb; ch++ ) { - if ( st_ivas->cldfbSynDec[ch] ) + IF( st_ivas->cldfbSynDec[ch] ) { scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, Q5 ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; } - fixedToFloat_arrL( p_output_fx[ch], p_output[ch], Q11, *nSamplesRendered ); - } - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) - { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } } - if ( st_ivas->hParamMC->slots_rendered == st_ivas->hParamMC->num_slots ) + IF( EQ_16( st_ivas->hParamMC->slots_rendered, st_ivas->hParamMC->num_slots ) ) { FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ ) { - IF( st_ivas->hParamMC->band_grouping[param_band_idx] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { -#ifdef IVAS_FLOAT_FIXED mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx]; move16(); -#else - mvr2r( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old[param_band_idx], nchan_transport_tmp * nchan_out_cov ); -#endif } -#ifdef IVAS_FLOAT_FIXED mvl2l( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nchan_transport_tmp * nchan_out_cov ); st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]; move16(); -#else - mvr2r( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old[param_band_idx], nchan_transport_tmp * nchan_out_cov ); -#endif } } -#endif - -#else - ivas_param_mc_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ); -#endif } - else if ( st_ivas->mc_mode == MC_MODE_MCMASA ) + ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - int16_t offset = hSpatParamRendCom->slots_rendered * hSpatParamRendCom->slot_size; + Word16 offset = imult1616( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->slot_size ); nchan_remapped = st_ivas->nchan_transport; + move16(); - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { -#ifndef IVAS_FLOAT_FIXED - ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); -#else ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); - FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; ++i ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif } - else if ( st_ivas->renderer_type == RENDERER_DIRAC || st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) /* rendering to CICPxx and Ambisonics */ + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) /* rendering to CICPxx and Ambisonics */ { - ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ); + ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ); - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { /* we still need to copy the separate channel if available */ - if ( st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->hOutSetup.separateChannelEnabled ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - - fixedToFloat_arrL( p_output_fx[st_ivas->hOutSetup.separateChannelIndex], p_output[st_ivas->hOutSetup.separateChannelIndex], Q11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL - 1] + offset, p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); -#endif } -#ifdef IVAS_FLOAT_FIXED - FOR( i = 0; i < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, *nSamplesRendered ); - } ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 ); -#if 1 - FOR( i = 0; i < ( st_ivas->hOutSetup.ambisonics_order + 1 ) * ( st_ivas->hOutSetup.ambisonics_order + 1 ); i++ ) - { - fixedToFloat_arrL( p_output_fx[i], p_output[i], Q11, *nSamplesRendered ); - } -#endif -#else - ivas_mc2sba( st_ivas->hIntSetup, p_output, p_output, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0.f ); -#endif } - else if ( st_ivas->intern_config == IVAS_AUDIO_CONFIG_5_1 && ( output_config == IVAS_AUDIO_CONFIG_5_1_2 || output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1 ) ) + ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) ) { - for ( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; n++ ) + FOR( n = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); n < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); n++ ) { - set_zero( p_output[n], *nSamplesRendered ); + set32_fx( p_output_fx[n], 0, *nSamplesRendered ); } } } /* copy discrete C and TD LFE from internal TC to output */ - if ( st_ivas->hOutSetup.separateChannelEnabled ) + IF( st_ivas->hOutSetup.separateChannelEnabled ) { - if ( output_config == IVAS_AUDIO_CONFIG_5_1 || output_config == IVAS_AUDIO_CONFIG_7_1 || - output_config == IVAS_AUDIO_CONFIG_5_1_4 || output_config == IVAS_AUDIO_CONFIG_7_1_4 || - output_config == IVAS_AUDIO_CONFIG_5_1_2 || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe > 0 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || + EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) { -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL] + offset, p_output_fx[LFE_CHANNEL], *nSamplesRendered ); Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - - fixedToFloat_arrL( p_output_fx[LFE_CHANNEL], p_output[LFE_CHANNEL], Q11, *nSamplesRendered ); - fixedToFloat_arrL( p_output_fx[st_ivas->hOutSetup.separateChannelIndex], p_output[st_ivas->hOutSetup.separateChannelIndex], Q11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL] + offset, p_output[LFE_CHANNEL], *nSamplesRendered ); - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL - 1] + offset, p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); -#endif } - else if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && st_ivas->hOutSetup.num_lfe == 0 ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( st_ivas->hOutSetup.num_lfe, 0 ) ) { /* Delay the separated channel to sync with the DirAC rendering */ -#if 1 Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); - fixedToFloat_arrL( p_output_fx[st_ivas->hOutSetup.separateChannelIndex], p_output[st_ivas->hOutSetup.separateChannelIndex], Q11, *nSamplesRendered ); -#else - mvr2r( st_ivas->hTcBuffer->tc[LFE_CHANNEL - 1] + offset, p_output[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered ); -#endif } } } @@ -3716,69 +3300,36 @@ ivas_error ivas_jbm_dec_render( * - float to integer conversion *----------------------------------------------------------------*/ - st_ivas->hTcBuffer->n_samples_available -= *nSamplesRendered; - st_ivas->hTcBuffer->n_samples_rendered += *nSamplesRendered; + st_ivas->hTcBuffer->n_samples_available = sub( st_ivas->hTcBuffer->n_samples_available, *nSamplesRendered ); + st_ivas->hTcBuffer->n_samples_rendered = add( st_ivas->hTcBuffer->n_samples_rendered, *nSamplesRendered ); /* update global combined orientation start index */ ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered ); - if ( st_ivas->hTcBuffer->n_samples_discard > 0 ) + IF( GT_16( st_ivas->hTcBuffer->n_samples_discard, 0 ) ) { - for ( n = 0; n < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ ) + FOR( n = 0; n < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ ) { - p_output[n] += st_ivas->hTcBuffer->n_samples_discard; + p_output_fx[n] += st_ivas->hTcBuffer->n_samples_discard; } - *nSamplesRendered -= st_ivas->hTcBuffer->n_samples_discard; + *nSamplesRendered = sub( (Word16) *nSamplesRendered, st_ivas->hTcBuffer->n_samples_discard ); st_ivas->hTcBuffer->n_samples_discard = 0; + move16(); } { - if ( st_ivas->ivas_format != MONO_FORMAT ) + IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) ) { #ifndef DISABLE_LIMITER - Word16 ch_idx; - exp = 16; - for ( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ ) - { - - p_output_fx[ch_idx] = tmp_buffer_fx[ch_idx]; - } - for ( ch_idx = 0; ch_idx < nchan_out; ch_idx++ ) - { - exp = s_min( exp, Q_factor_arrL( p_output[ch_idx], *nSamplesRendered ) ); - } - exp -= 2; - exp = 11; - for ( ch_idx = 0; ch_idx < nchan_out; ch_idx++ ) - { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output_fx[ch_idx][j] = (Word32) ( p_output[ch_idx][j] * ( 1 << exp ) ); - } - } - ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp ); - for ( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ ) - { - for ( j = 0; j < *nSamplesRendered; j++ ) - { - p_output[ch_idx][j] = ( (float) p_output_fx[ch_idx][j] / ( 1 << exp ) ); - } - } + ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, output_q_factor ); #endif } } - Word16 q_p_output = Q11; - FOR( i = 0; i < nchan_out; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], q_p_output, *nSamplesRendered ); - } - - ivas_syn_output_fx( p_output_fx, q_p_output, *nSamplesRendered, nchan_out, data ); - FOR( i = 0; i < nchan_out; i++ ){} + ivas_syn_output_fx( p_output_fx, output_q_factor, *nSamplesRendered, nchan_out, data ); - - *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; + *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available; + move16(); pop_wmops(); return IVAS_ERR_OK; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index be58073f4..0e709625d 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -1145,6 +1145,7 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * ivas_omasa_dirac_rend_jbm() * @@ -1180,88 +1181,75 @@ void ivas_omasa_dirac_rend_jbm( subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; -#ifdef IVAS_FLOAT_FIXED - ivas_dirac_dec_render_fx( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f ); -#else ivas_dirac_dec_render( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f ); -#endif -#ifdef IVAS_FLOAT_FIXED - Word16 q_output = 31; - Word32 **output_fx, data_separated_objects_fx[4][960]; - q_output = Q11; -#ifdef MSAN_FIX /*Can be removed when dependency on data_separated_objects is removed*/ - Word16 no_channels; - IF( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) - { - no_channels = 1; - } - ELSE - { - no_channels = st_ivas->nchan_ism; - } - FOR( Word16 ind = 0; ind < no_channels; ind++ ) - { + ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); + + return; +} #else - FOR( Word16 ind = 0; ind < MAX_NUM_OBJECTS; ind++ ) +/*--------------------------------------------------------------------------* + * ivas_omasa_dirac_rend_jbm_fx() + * + * Rendering in OMASA format for JBM + *--------------------------------------------------------------------------*/ + +void ivas_omasa_dirac_rend_jbm_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of samples requested */ + UWord16 *nSamplesRendered, /* o : number of samples rendered */ + UWord16 *nSamplesAvailable, /* o : number of samples still to render */ + const Word16 nchan_transport, /* i : number of transport channels */ + Word32 *output_f[] /* o : rendered time signal */ +) +{ + Word16 subframes_rendered; + Word16 slots_rendered; + Word16 n; + Word32 data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { -#endif // MSAN_FIX - FOR( Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++ ) - { - // data_separated_objects_fx[ind][ind2] = (Word32)(data_separated_objects[ind][ind2] * (1<hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ) ); - FOR( Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++ ) + ELSE { - output_fx[ind] = (Word32 *) malloc( sizeof( Word32 ) * 960 ); - FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) + FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - // output_fx[ind][ind2] =(Word32)(output_f[ind][ind2] * (1<hSpatParamRendCom->subframes_rendered; + move16(); + slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + move16(); + + ivas_dirac_dec_render_fx( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f ); + #ifdef MSAN_FIX FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) #else FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) #endif // MSAN_FIX { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1 ); // Q30 -> Q29 - } + scale_sig32( st_ivas->hIsmRendererData->prev_gains_fx[ind1], MAX_OUTPUT_CHANNELS, -1 ); // Q30 -> Q29 } - ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects_fx, output_fx, subframes_rendered, slots_rendered ); + ivas_omasa_separate_object_render_jbm_fx( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); - FOR( Word16 ind = 0; ind < st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; ind++ ) - { - FOR( Word16 ind2 = 0; ind2 < 960; ind2++ ) - { - output_f[ind][ind2] = fixedToFloat( output_fx[ind][ind2], q_output ); - } - free( output_fx[ind] ); - } - free( output_fx ); #ifdef MSAN_FIX FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) #else FOR( Word16 ind1 = 0; ind1 < MAX_CICP_CHANNELS - 1; ind1++ ) #endif // MSAN_FIX { - FOR( Word16 ind2 = 0; ind2 < MAX_OUTPUT_CHANNELS; ind2++ ) - { - st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[ind1][ind2], 1 ); // Q29 -> Q30 - } + scale_sig32( st_ivas->hIsmRendererData->prev_gains_fx[ind1], MAX_OUTPUT_CHANNELS, 1 ); // Q29 -> Q30 } - // dbgwrite2_txt(output_f[1],960,"../omasa_soutput_f.txt"); -#else - ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, data_separated_objects, output_f, subframes_rendered, slots_rendered ); -#endif + return; } +#endif #ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 09757dbf8..acb58e751 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -2821,14 +2821,9 @@ void ivas_spar_dec_upmixer_sf_fx( const Word16 nchan_internal, /* i : number of internal channels */ Word16 out_len ) { - /*TODO: To be removed later--------------------------------------------------------*/ - float output[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - float *p_output[MAX_OUTPUT_CHANNELS]; - /*---------------------------------------------------------------------------*/ Word16 cldfb_band, num_cldfb_bands, numch_in, numch_out; Word32 *cldfb_in_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; Word32 *cldfb_in_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX]; - // Word32 output_fx[16][960]; Word16 i, b, ts, out_ch, in_ch; Word16 num_spar_bands, spar_band, nchan_transport; Word16 num_in_ingest, split_band; @@ -3069,16 +3064,7 @@ void ivas_spar_dec_upmixer_sf_fx( IF( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - FOR( Word16 ch = 0; ch < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); ch++ ) - { - fixedToFloat_arrL( output_fx[ch], output[ch], Q11, out_len ); - p_output[ch] = output[ch]; - } -#ifdef MSAN_FIX - ivas_dirac_dec_render_sf_fx( st_ivas, p_output, output_fx, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx ); -#else - ivas_dirac_dec_render_sf_fx( st_ivas, p_output, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx ); -#endif // MSAN_FIX + ivas_dirac_dec_render_sf_fx( st_ivas, output_fx, nchan_internal, cldfb_in_ts_re_fx, cldfb_in_ts_im_fx ); } /*------------------------------------------------------------------ends*/ IF( st_ivas->hDirAC != NULL ) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 63830ac15..8e036270b 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1613,7 +1613,7 @@ static ivas_error IVAS_DEC_GetRenderedSamples( st_ivas = hIvasDec->st_ivas; /* run the main IVAS decoding routine */ - error = ivas_jbm_dec_render( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf ); + error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf ); return error; } diff --git a/lib_dec/vlpc_2st_dec.c b/lib_dec/vlpc_2st_dec.c index ddeb78dc8..b032b7e56 100644 --- a/lib_dec/vlpc_2st_dec.c +++ b/lib_dec/vlpc_2st_dec.c @@ -44,7 +44,7 @@ * * *------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void vlpc_2st_dec_flt( float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ int16_t *indx, /* i : index[] (4 bits per words) */ @@ -75,3 +75,4 @@ void vlpc_2st_dec_flt( return; } +#endif \ No newline at end of file diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index b0ef34b24..27c391c89 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -441,7 +441,7 @@ static void GenerateFilter_fx( FOR( i = 0; i < num_az_idx[p]; i++ ) { modelEval->BM_fx[qp + i] = L_shl( Mpy_32_32( modelEval->elevBfVec_fx[p], modelEval->azimBfVec_fx[p][i] ), Q30 - ( Q30 * 2 - 31 ) ); // Q30 - BM_idx[qp + i] = add( model->azim_start_idx[EvIdx[p]], AzIdx[p][i] ); + BM_idx[qp + i] = add(model->azim_start_idx[EvIdx[p]] , AzIdx[p][i]); } qp = add( qp, num_az_idx[p] ); } @@ -930,7 +930,7 @@ static void getPeriodicBSplineSampVec_fx( FOR( i = 0; i < *num_az_idx; i++ ) { - d = sub( d0, imult1616( ( sub( add( i, nI ), 1 ) ), SegSamples ) ); /* offset of knot_interval */ + d = sub(d0 , imult1616(( sub(add(i , nI) , 1) ) , SegSamples)); /* offset of knot_interval */ d = sub( d0, imult1616( sub( add( i, nI ), 1 ), SegSamples ) ); BfVec_fx[i] = azimBsShape_fx[abs_s( d ) * subSampFactor]; AzIdx[i] = add( nI, i ) % NumBFs; @@ -1135,24 +1135,23 @@ void BSplineModelEvalDealloc_fx( /* Allocated in LoadBSplineBinary() */ Word16 i; - IF( model->modelROM ) + IF ( model->modelROM ) { free( (void *) model->azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR( i = 0; i < model->elevDim3; i++ ) + FOR ( i = 0; i < model->elevDim3; i++ ) { free( model->azimKSeq_fx[i] ); } - free( model->azimKSeq_fx ); - IF( modelEval != NULL ) + free( model->azimKSeq_fx); + IF ( modelEval != NULL ) { - free( modelEval->hrfModL_fx ); - free( modelEval->hrfModR_fx ); + free( modelEval->hrfModL_fx); + free( modelEval->hrfModR_fx); } } return; } -#endif // IVAS_FLOAT_FIXED - +#else void BSplineModelEvalDealloc( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i : Model evaluation structure */ @@ -1171,15 +1170,14 @@ void BSplineModelEvalDealloc( free( model->azimKSeq ); if ( modelEval != NULL ) { -#ifndef IVAS_FLOAT_FIXED free( modelEval->hrfModL ); free( modelEval->hrfModR ); -#endif } } return; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 4d652a0c3..e333a56b1 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -216,9 +216,6 @@ void TDREND_MIX_Dealloc_fx( { IF( EQ_16( hBinRendererTd->HrFiltSet_p->FilterMethod, TDREND_HRFILT_Method_BSplineModel ) ) { -#if 0 /*IVAS_FLOAT_FIXED_TO_BE_REMOVED*/ - BSplineModelEvalDealloc( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); -#endif BSplineModelEvalDealloc_fx( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); } ELSE diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 66555279d..0df7c7b7b 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1316,12 +1316,12 @@ void BSplineModelEvalDealloc_fx( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i : Model evaluation structure */ ); -#endif // IVAS_FLOAT_FIXED - +#else void BSplineModelEvalDealloc( ModelParams_t *model, /* i : Model parameters */ ModelEval_t *modelEval /* i : Model evaluation structure */ ); +#endif // IVAS_FLOAT_FIXED /* ----- Object renderer - hrfilt ----- */ diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 3ee653b70..6b7afe97f 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -2143,7 +2143,7 @@ static void set_reverb_acoustic_data_fx( tmp_exp = add( exp_argument_e, 1 ); L_tmp = BASOP_util_Pow2( L_deposit_h( tmp ), tmp_exp, &pow_exp ); L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] ); - tmp_exp = add( tmp_exp, pDsr_e[bin_idx] ); + tmp_exp = add( pow_exp, pDsr_e[bin_idx] ); pDsr_fx[bin_idx] = L_tmp; move32(); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 0cf951fad..808aef3db 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1602,7 +1602,6 @@ typedef struct const int16_t *azimShapeIdx; const int16_t *azimShapeSampFactor; - const float *elevKSeq; /* Array, N x elevDim2 x elevDim3 */ #ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ const Word32 *elevBsShape_fx; @@ -1616,24 +1615,29 @@ typedef struct Word16 EL_e; const Word32 *ER_fx; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ Word16 ER_e; -#endif // IVAS_FLOAT_FIXED +#else + const float *elevKSeq; /* Array, N x elevDim2 x elevDim3 */ const float *AlphaL; /* Array, size AlphaN x K */ const float *AlphaR; /* Array, size AlphaN x K */ const float *elevBsShape; float **azimKSeq; /* Array, length azimDim3+1 */ const float **azimBsShape; +#endif // IVAS_FLOAT_FIXED int16_t azimDim3Max; int16_t iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ int16_t iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ +#ifndef IVAS_FLOAT_FIXED const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ - +#endif /* Pointers for allocation of dynamic memory */ +#ifndef IVAS_FLOAT_FIXED float *AlphaL_dyn; float *AlphaR_dyn; float *EL_dyn; float *ER_dyn; +#endif #ifdef IVAS_FLOAT_FIXED Word32 *AlphaL_dyn_fx; Word32 *AlphaR_dyn_fx; @@ -1644,11 +1648,12 @@ typedef struct Word32 *ER_dyn_fx; Word16 ER_dyn_e; #endif - float *elevBsShape_dyn; - float *elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED Word32 *elevBsShape_dyn_fx; Word32 *elevKSeq_dyn_fx; +#else + float *elevKSeq_dyn; + float *elevBsShape_dyn; #endif int16_t *azimDim2_dyn; int16_t *azimDim3_dyn; @@ -1656,9 +1661,10 @@ typedef struct int16_t *azimSegSamples_dyn; int16_t *azimShapeIdx_dyn; int16_t *azimShapeSampFactor_dyn; - float **azimBsShape_dyn; #ifdef IVAS_FLOAT_FIXED Word32 **azimBsShape_dyn_fx; +#else + float **azimBsShape_dyn; #endif } ModelParams_t; @@ -1669,25 +1675,33 @@ typedef struct int16_t elevDim2; int16_t elevDim3; +#ifndef IVAS_FLOAT_FIXED const float *elevKSeq; /* Array, length elevDim3-2 */ +#endif int16_t azimDim2; int16_t azimDim3; +#ifndef IVAS_FLOAT_FIXED const float *azimKSeq; /* Array, length azimDim3-2 */ const float *W; /* Array, size (elevDim3*azimDim3) x K */ +#endif int16_t azimBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; int16_t azimBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; +#ifndef IVAS_FLOAT_FIXED const float *azimBsShape; +#endif int16_t azimSegSamples; int16_t elevBsLen[HRTF_MODEL_BSPLINE_NUM_COEFFS]; int16_t elevBsStart[HRTF_MODEL_BSPLINE_NUM_COEFFS]; +#ifndef IVAS_FLOAT_FIXED const float *elevBsShape; +#endif int16_t elevSegSamples; #ifndef IVAS_FLOAT_FIXED float resamp_factor; #else - Word16 resamp_factor_fx; /*Q14*/ + Word16 resamp_factor_fx; /*Q14*/ #endif #ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ @@ -1699,22 +1713,24 @@ typedef struct #endif // IVAS_FLOAT_FIXED /* Pointers for allocation of dynamic memory */ - float *elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED Word32 *elevKSeq_dyn_fx; Word32 *azimKSeq_dyn_fx; -#endif +#else + float *elevKSeq_dyn; float *azimKSeq_dyn; float *W_dyn; float *azimBsShape_dyn; +#endif #ifdef IVAS_FLOAT_FIXED Word32 *W_dyn_fx; Word16 W_dyn_e; Word32 *azimBsShape_dyn_fx; #endif - float *elevBsShape_dyn; #ifdef IVAS_FLOAT_FIXED Word32 *elevBsShape_dyn_fx; +#else + float *elevBsShape_dyn; #endif } ModelParamsITD_t; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 048a86470..963f313ce 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -247,7 +247,90 @@ static ivas_error read_hrtf_binary_header( * * Loads the B Spline HR filter model ITD data from file. --------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static void LoadBSplineBinaryITD( + ModelParamsITD_t *modelITD, /* i/o: ITD model parameter structure */ + FILE *f_hrtf /* i : HR filter data file handle */ +) +{ + Word16 tmp; + fread( &modelITD->N, sizeof( Word16 ), 1, f_hrtf ); + fread( &modelITD->elevDim2, sizeof( Word16 ), 1, f_hrtf ); + fread( &modelITD->elevDim3, sizeof( Word16 ), 1, f_hrtf ); + + float *elevKSeq_dyn_local = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); + fread( elevKSeq_dyn_local, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); + + modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); + FOR( int i = 0; i < modelITD->elevDim3 - 2; i++ ) + { + modelITD->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); + } + + fread( &modelITD->azimDim2, sizeof( Word16 ), 1, f_hrtf ); + fread( &modelITD->azimDim3, sizeof( Word16 ), 1, f_hrtf ); + + float *azimKSeq_dyn_local = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + fread( azimKSeq_dyn_local, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); + modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + FOR( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) + { + modelITD->azimKSeq_dyn_fx[i] = float_to_fix( azimKSeq_dyn_local[i], Q22 ); + } + + fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); + float *W_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( W_dyn_local, sizeof( float ), tmp, f_hrtf ); + + modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + f2me_buf( W_dyn_local, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); + + /* azimuth */ + fread( modelITD->azimBsLen, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + fread( modelITD->azimBsStart, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + + fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); + + float *azimBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( azimBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + + modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + FOR( int i = 0; i < tmp; i++ ) + { + modelITD->azimBsShape_dyn_fx[i] = float_to_fix( azimBsShape_dyn_local[i], Q30 ); + } + + fread( &modelITD->azimSegSamples, sizeof( Word16 ), 1, f_hrtf ); + /* elevation */ + fread( modelITD->elevBsLen, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + fread( modelITD->elevBsStart, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); + + fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); + + float *elevBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( elevBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + + modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + FOR( int i = 0; i < tmp; i++ ) + { + modelITD->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); + } + + fread( &modelITD->elevSegSamples, sizeof( Word16 ), 1, f_hrtf ); + + modelITD->elevKSeq_fx = (const Word32 *) modelITD->elevKSeq_dyn_fx; + + modelITD->azimKSeq_fx = (const Word32 *) modelITD->azimKSeq_dyn_fx; + modelITD->W_fx = modelITD->W_dyn_fx; + modelITD->W_e = modelITD->W_dyn_e; + move16(); + modelITD->azimBsShape_fx = (const Word32 *) modelITD->azimBsShape_dyn_fx; + modelITD->elevBsShape_fx = (const Word32 *) modelITD->elevBsShape_dyn_fx; + + return; +} +#else static void LoadBSplineBinaryITD( ModelParamsITD_t *modelITD, /* i/o: ITD model parameter structure */ FILE *f_hrtf /* i : HR filter data file handle */ @@ -257,34 +340,45 @@ static void LoadBSplineBinaryITD( fread( &modelITD->N, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->elevDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->elevDim3, sizeof( int16_t ), 1, f_hrtf ); - modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); - fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); - for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) + float *elevKSeq_dyn_local = (float *)malloc((modelITD->elevDim3 - 2) * sizeof(float)); + fread(elevKSeq_dyn_local, sizeof(float), modelITD->elevDim3 - 2, f_hrtf); + + modelITD->elevKSeq_dyn_fx = (Word32 *)malloc(sizeof(Word32)*(modelITD->elevDim3 - 2)); + for (int i = 0; i < modelITD->elevDim3 - 2; i++) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix( modelITD->elevKSeq_dyn[i], 22 ); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix(elevKSeq_dyn_local[i], Q22); } +#else + modelITD->elevKSeq_dyn = (float *)malloc((modelITD->elevDim3 - 2) * sizeof(float)); + fread(modelITD->elevKSeq_dyn, sizeof(float), modelITD->elevDim3 - 2, f_hrtf); #endif fread( &modelITD->azimDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->azimDim3, sizeof( int16_t ), 1, f_hrtf ); - modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *azimKSeq_dyn_local = (float *)malloc(((modelITD->azimDim3 + 1) / 2 - 2) * sizeof(float)); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + fread(azimKSeq_dyn_local, sizeof(float), (modelITD->azimDim3 + 1) / 2 - 2, f_hrtf); modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) + for (int i = 0; i < ((modelITD->azimDim3 + 1) / 2 - 2); i++) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix( modelITD->azimKSeq_dyn[i], Q22 ); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix(azimKSeq_dyn_local[i], Q22); } +#else + modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + fread( modelITD->azimKSeq_dyn, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); #endif fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - modelITD->W_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( modelITD->W_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *W_dyn_local = (float *)malloc(tmp * sizeof(float)); + fread(W_dyn_local, sizeof(float), tmp, f_hrtf); + modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - f2me_buf( modelITD->W_dyn, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); + f2me_buf( W_dyn_local, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); +#else + modelITD->W_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( modelITD->W_dyn, sizeof( float ), tmp, f_hrtf ); #endif /* azimuth */ @@ -293,14 +387,18 @@ static void LoadBSplineBinaryITD( fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - modelITD->azimBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *azimBsShape_dyn_local = (float *)malloc(tmp * sizeof(float)); + fread(azimBsShape_dyn_local, sizeof(float), tmp, f_hrtf); + modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for ( int i = 0; i < tmp; i++ ) + for (int i = 0; i < tmp; i++) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix( modelITD->azimBsShape_dyn[i], Q30 ); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix(azimBsShape_dyn_local[i], Q30); } +#else + modelITD->azimBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( modelITD->azimBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #endif fread( &modelITD->azimSegSamples, sizeof( int16_t ), 1, f_hrtf ); @@ -311,42 +409,50 @@ static void LoadBSplineBinaryITD( fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - modelITD->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *elevBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( elevBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( int i = 0; i < tmp; i++ ) { - modelITD->elevBsShape_dyn_fx[i] = float_to_fix( modelITD->elevBsShape_dyn[i], Q30 ); + modelITD->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); } +#else + modelITD->elevBsShape_dyn = (float *)malloc(tmp * sizeof(float)); + fread(modelITD->elevBsShape_dyn, sizeof(float), tmp, f_hrtf); #endif fread( &modelITD->elevSegSamples, sizeof( int16_t ), 1, f_hrtf ); - modelITD->elevKSeq = (const float *) modelITD->elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->elevKSeq_fx = (const Word32 *) modelITD->elevKSeq_dyn_fx; +#else + modelITD->elevKSeq = (const float *) modelITD->elevKSeq_dyn; #endif - modelITD->azimKSeq = (const float *) modelITD->azimKSeq_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->azimKSeq_fx = (const Word32 *) modelITD->azimKSeq_dyn_fx; +#else + modelITD->azimKSeq = (const float *) modelITD->azimKSeq_dyn; #endif - modelITD->W = (const float *) modelITD->W_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->W_fx = modelITD->W_dyn_fx; modelITD->W_e = modelITD->W_dyn_e; move16(); +#else + modelITD->W = (const float *) modelITD->W_dyn; #endif - modelITD->azimBsShape = (const float *) modelITD->azimBsShape_dyn; - modelITD->elevBsShape = (const float *) modelITD->elevBsShape_dyn; #ifdef IVAS_FLOAT_FIXED modelITD->azimBsShape_fx = (const Word32 *) modelITD->azimBsShape_dyn_fx; modelITD->elevBsShape_fx = (const Word32 *) modelITD->elevBsShape_dyn_fx; +#else + modelITD->elevBsShape = (const float *) modelITD->elevBsShape_dyn; + modelITD->azimBsShape = (const float *) modelITD->azimBsShape_dyn; #endif return; } - +#endif /*-------------------------------------------------------------------* * LoadBSplineBinary() @@ -426,73 +532,93 @@ static ivas_error LoadBSplineBinary( fread( &model->elevDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &model->elevDim3, sizeof( int16_t ), 1, f_hrtf ); - model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); - fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *elevKSeq_dyn_local = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); + fread( elevKSeq_dyn_local, sizeof( float ), model->elevDim3 - 2, f_hrtf ); model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); for ( i = 0; i < ( model->elevDim3 - 2 ); i++ ) { - model->elevKSeq_dyn_fx[i] = float_to_fix( model->elevKSeq_dyn[i], Q22 ); + model->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); } +#else + model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); + fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); #endif model->azimDim2_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); model->azimDim3_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); model->azim_start_idx_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); - model->azimKSeq = (float **) malloc( model->elevDim3 * sizeof( float * ) ); #ifdef IVAS_FLOAT_FIXED + float **azimKSeq_local = (float **)malloc(model->elevDim3 * sizeof(float *)); model->azimKSeq_fx = (Word32 **) malloc( model->elevDim3 * sizeof( Word32 * ) ); +#else + model->azimKSeq = (float **) malloc( model->elevDim3 * sizeof( float * ) ); #endif for ( i = 0; i < model->elevDim3; i++ ) { fread( &model->azimDim2_dyn[i], sizeof( int16_t ), 1, f_hrtf ); fread( &model->azimDim3_dyn[i], sizeof( int16_t ), 1, f_hrtf ); fread( &model->azim_start_idx_dyn[i], sizeof( int16_t ), 1, f_hrtf ); - model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); - fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #ifdef IVAS_FLOAT_FIXED + azimKSeq_local[i] = (float *)malloc((model->azimDim3_dyn[i] + 1) * sizeof(float)); + fread(azimKSeq_local[i], sizeof(float), (model->azimDim3_dyn[i] + 1), f_hrtf); model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) + for (int j = 0; j < (model->azimDim3_dyn[i] + 1); j++) { - model->azimKSeq_fx[i][j] = float_to_fix( model->azimKSeq[i][j], Q22 ); + model->azimKSeq_fx[i][j] = float_to_fix(azimKSeq_local[i][j], Q22); } +#else + model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); + fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #endif } fread( &model->AlphaN, sizeof( int16_t ), 1, f_hrtf ); +#ifdef IVAS_FLOAT_FIXED + float *AlphaL_dyn_local = (float *)malloc(model->AlphaN * model->K * sizeof(float)); + fread(AlphaL_dyn_local, sizeof(float), model->AlphaN * model->K, f_hrtf); + model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); + f2me_buf(AlphaL_dyn_local, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K ); +#else model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); fread( model->AlphaL_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); -#ifdef IVAS_FLOAT_FIXED - model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); - f2me_buf( model->AlphaL_dyn, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K ); #endif - model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); - fread( model->AlphaR_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + float *AlphaR_dyn_local = (float *)malloc(model->AlphaN * model->K * sizeof(float)); + fread(AlphaR_dyn_local, sizeof(float), model->AlphaN * model->K, f_hrtf); + model->AlphaR_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); - f2me_buf( model->AlphaR_dyn, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K ); + f2me_buf(AlphaR_dyn_local, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K ); +#else + model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); + fread( model->AlphaR_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); #endif /* azimuth */ fread( &model->num_unique_azim_splines, sizeof( int16_t ), 1, f_hrtf ); - model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); - model->azimBsShape_dyn = (float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); #ifdef IVAS_FLOAT_FIXED model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ); model->azimBsShape_dyn_fx = (Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ); + float **azimBsShape_dyn_local = (float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); +#else + model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); + model->azimBsShape_dyn = (float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); #endif model->azimSegSamples_dyn = (int16_t *) malloc( model->num_unique_azim_splines * sizeof( int16_t ) ); for ( i = 0; i < model->num_unique_azim_splines; i++ ) { fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - model->azimBsShape_dyn[i] = (float *) malloc( tmp * sizeof( float ) ); - fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED + azimBsShape_dyn_local[i] = (float *) malloc( tmp * sizeof( float ) ); + fread( azimBsShape_dyn_local[i], sizeof( float ), tmp, f_hrtf ); model->azimBsShape_dyn_fx[i] = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( int j = 0; j < tmp; j++ ) { - model->azimBsShape_dyn_fx[i][j] = float_to_fix( model->azimBsShape_dyn[i][j], Q30 ); + model->azimBsShape_dyn_fx[i][j] = float_to_fix( azimBsShape_dyn_local[i][j], Q30 ); } +#else + model->azimBsShape_dyn[i] = (float *) malloc( tmp * sizeof( float ) ); + fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); } @@ -506,23 +632,22 @@ static ivas_error LoadBSplineBinary( fread( model->elevBsLen, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( model->elevBsStart, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); - model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); - fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); + float *elevBsShape_dyn_local = (float *)malloc(tmp * sizeof(float)); + fread(elevBsShape_dyn_local, sizeof(float), tmp, f_hrtf); + model->elevBsShape_dyn_fx = (Word32 *)malloc(tmp * sizeof(Word32)); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix( model->elevBsShape_dyn[i], Q30 ); + model->elevBsShape_dyn_fx[i] = float_to_fix(elevBsShape_dyn_local[i], Q30); } +#else + model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #endif fread( &model->elevSegSamples, sizeof( int16_t ), 1, f_hrtf ); /* Set const pointers */ - model->AlphaL = (const float *) model->AlphaL_dyn; - model->AlphaR = (const float *) model->AlphaR_dyn; - model->EL = (const float *) model->EL_dyn; - model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED model->AlphaL_fx = model->AlphaL_dyn_fx; model->AlphaL_e = model->AlphaL_dyn_e; @@ -536,12 +661,18 @@ static ivas_error LoadBSplineBinary( model->ER_fx = model->ER_dyn_fx; model->ER_e = model->ER_dyn_e; move16(); +#else + model->AlphaL = (const float *) model->AlphaL_dyn; + model->AlphaR = (const float *) model->AlphaR_dyn; + model->EL = (const float *) model->EL_dyn; + model->ER = (const float *) model->ER_dyn; #endif - model->elevBsShape = (const float *) model->elevBsShape_dyn; - model->elevKSeq = (const float *) model->elevKSeq_dyn; #ifdef IVAS_FLOAT_FIXED model->elevBsShape_fx = (const Word32 *) model->elevBsShape_dyn_fx; model->elevKSeq_fx = (const Word32 *) model->elevKSeq_dyn_fx; +#else + model->elevBsShape = (const float *) model->elevBsShape_dyn; + model->elevKSeq = (const float *) model->elevKSeq_dyn; #endif model->azimDim2 = (const int16_t *) model->azimDim2_dyn; model->azimDim3 = (const int16_t *) model->azimDim3_dyn; @@ -552,9 +683,10 @@ static ivas_error LoadBSplineBinary( for ( i = 0; i < model->num_unique_azim_splines; i++ ) { - model->azimBsShape[i] = (const float *) model->azimBsShape_dyn[i]; #ifdef IVAS_FLOAT_FIXED model->azimBsShape_fx[i] = (const Word32 *) model->azimBsShape_dyn_fx[i]; +#else + model->azimBsShape[i] = (const float *) model->azimBsShape_dyn[i]; #endif } @@ -728,12 +860,13 @@ static void HRTF_energy_sections_precalc( ) { int16_t i, k, j; +#ifndef IVAS_FLOAT_FIXED float *pEL; float *pER; const float *pAlphaL; const float *pAlphaR; float tmp; -#ifdef IVAS_FLOAT_FIXED +#else Word32 *pEL_fx; Word32 *pER_fx; const Word32 *pAlphaL_fx; @@ -747,67 +880,70 @@ static void HRTF_energy_sections_precalc( AlphaN = model->AlphaN; /* Precalculated energies for each section and each row of the alpha matrices */ - model->EL_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); - model->ER_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); - pEL = model->EL_dyn; - pER = model->ER_dyn; #ifdef IVAS_FLOAT_FIXED model->EL_dyn_fx = (Word32 *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( Word32 ) ); model->ER_dyn_fx = (Word32 *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( Word32 ) ); pEL_fx = model->EL_dyn_fx; pER_fx = model->ER_dyn_fx; +#else + model->EL_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); + model->ER_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); + pEL = model->EL_dyn; + pER = model->ER_dyn; #endif for ( i = 0; i < HRTF_MODEL_N_SECTIONS; i++ ) { for ( j = 0; j < AlphaN; j++ ) /* rows of Alpha matrices */ { - *pEL = 0.0f; - *pER = 0.0f; #ifdef IVAS_FLOAT_FIXED *pEL_fx = 0; move32(); *pER_fx = 0; move32(); +#else + *pEL = 0.0f; + *pER = 0.0f; #endif - pAlphaL = &model->AlphaL[model->iSecFirst[i] * AlphaN + j]; - pAlphaR = &model->AlphaR[model->iSecFirst[i] * AlphaN + j]; #ifdef IVAS_FLOAT_FIXED pAlphaL_fx = &model->AlphaL_fx[model->iSecFirst[i] * AlphaN + j]; pAlphaR_fx = &model->AlphaR_fx[model->iSecFirst[i] * AlphaN + j]; +#else + pAlphaR = &model->AlphaR[model->iSecFirst[i] * AlphaN + j]; + pAlphaL = &model->AlphaL[model->iSecFirst[i] * AlphaN + j]; #endif for ( k = model->iSecFirst[i]; k < model->iSecLast[i]; k++ ) /* k within the sections */ { /* Energy calculation */ +#ifdef IVAS_FLOAT_FIXED + tmp_fx = *pAlphaL_fx; + *pEL_fx = L_add(*pEL_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + tmp_fx = *pAlphaR_fx; + *pER_fx = L_add(*pER_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + pAlphaL_fx += AlphaN; + pAlphaR_fx += AlphaN; +#else tmp = *pAlphaL; *pEL += tmp * tmp; tmp = *pAlphaR; *pER += tmp * tmp; pAlphaL += AlphaN; pAlphaR += AlphaN; -#ifdef IVAS_FLOAT_FIXED - tmp_fx = *pAlphaL_fx; - *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ - tmp_fx = *pAlphaR_fx; - *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ - pAlphaL_fx += AlphaN; - pAlphaR_fx += AlphaN; #endif } - pEL++; - pER++; #ifdef IVAS_FLOAT_FIXED pEL_fx++; pER_fx++; +#else + pEL++; + pER++; #endif } } - model->EL = (const float *) model->EL_dyn; - model->ER = (const float *) model->ER_dyn; #ifdef IVAS_FLOAT_FIXED - model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) - model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) + model->EL_dyn_e = add(shl(model->AlphaL_e, 1), 1); // 2 * AlphaL_e + 1 (one guard bit) + model->ER_dyn_e = add(shl(model->AlphaR_e, 1), 1); // 2 * AlphaR_e + 1 (one guard bit) model->EL_fx = model->EL_dyn_fx; model->EL_e = model->EL_dyn_e; @@ -815,6 +951,9 @@ static void HRTF_energy_sections_precalc( model->ER_fx = model->ER_dyn_fx; model->ER_e = model->ER_dyn_e; move16(); +#else + model->EL = (const float *) model->EL_dyn; + model->ER = (const float *) model->ER_dyn; #endif } @@ -845,76 +984,80 @@ ivas_error dealloc_HRTF_binary( { if ( hHrtf->ModelParams.UseItdModel ) { - free( hHrtf->ModelParamsITD.elevKSeq_dyn ); - free( hHrtf->ModelParamsITD.azimKSeq_dyn ); - free( hHrtf->ModelParamsITD.W_dyn ); - free( hHrtf->ModelParamsITD.azimBsShape_dyn ); - free( hHrtf->ModelParamsITD.elevBsShape_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParamsITD.elevKSeq_dyn_fx ); free( hHrtf->ModelParamsITD.azimKSeq_dyn_fx ); free( hHrtf->ModelParamsITD.W_dyn_fx ); free( hHrtf->ModelParamsITD.azimBsShape_dyn_fx ); free( hHrtf->ModelParamsITD.elevBsShape_dyn_fx ); +#else + free( hHrtf->ModelParamsITD.azimKSeq_dyn ); + free( hHrtf->ModelParamsITD.elevBsShape_dyn ); + free( hHrtf->ModelParamsITD.elevKSeq_dyn ); + free( hHrtf->ModelParamsITD.W_dyn ); + free( hHrtf->ModelParamsITD.azimBsShape_dyn ); #endif } - free( hHrtf->ModelParams.elevKSeq_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.elevKSeq_dyn_fx ); +#else + free( hHrtf->ModelParams.elevKSeq_dyn ); #endif free( hHrtf->ModelParams.azim_start_idx_dyn ); free( hHrtf->ModelParams.azimDim2_dyn ); free( hHrtf->ModelParams.azimDim3_dyn ); - free( hHrtf->ModelParams.AlphaL_dyn ); - free( hHrtf->ModelParams.AlphaR_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.AlphaL_dyn_fx ); free( hHrtf->ModelParams.AlphaR_dyn_fx ); +#else + free( hHrtf->ModelParams.AlphaL_dyn ); + free( hHrtf->ModelParams.AlphaR_dyn ); #endif free( hHrtf->ModelParams.azimSegSamples_dyn ); free( hHrtf->ModelParams.azimShapeIdx_dyn ); free( hHrtf->ModelParams.azimShapeSampFactor_dyn ); - free( hHrtf->ModelParams.elevBsShape_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.elevBsShape_dyn_fx ); +#else + free( hHrtf->ModelParams.elevBsShape_dyn ); #endif for ( i = 0; i < hHrtf->ModelParams.num_unique_azim_splines; i++ ) { - free( hHrtf->ModelParams.azimBsShape_dyn[i] ); - free( &hHrtf->ModelParams.azimBsShape_dyn[i] ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.azimBsShape_dyn_fx[i] ); free( &hHrtf->ModelParams.azimBsShape_dyn_fx[i] ); +#else + free( hHrtf->ModelParams.azimBsShape_dyn[i] ); + free( &hHrtf->ModelParams.azimBsShape_dyn[i] ); #endif } +#ifndef IVAS_FLOAT_FIXED free( (void *) hHrtf->ModelParams.azimBsShape ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ for ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq[i] ); } free( hHrtf->ModelParams.azimKSeq ); -#ifdef IVAS_FLOAT_FIXED +#else free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + FOR ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq_fx[i] ); } free( hHrtf->ModelParams.azimKSeq_fx ); #endif - free( hHrtf->ModelParams.EL_dyn ); - free( hHrtf->ModelParams.ER_dyn ); #ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelParams.EL_dyn_fx ); free( hHrtf->ModelParams.ER_dyn_fx ); -#endif -#ifdef IVAS_FLOAT_FIXED free( hHrtf->ModelEval.hrfModL_fx ); free( hHrtf->ModelEval.hrfModR_fx ); #else + free( hHrtf->ModelParams.EL_dyn ); + free( hHrtf->ModelParams.ER_dyn ); free( hHrtf->ModelEval.hrfModL ); free( hHrtf->ModelEval.hrfModR ); #endif @@ -1052,7 +1195,7 @@ static ivas_error create_HRTF_from_rawdata( for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { //( *hHRTF )->inv_diffuse_weight[i] = *( (float *) ( hrtf_data_rptr ) ); - ( *hHRTF )->inv_diffuse_weight_fx[i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 ); + ( *hHRTF )->inv_diffuse_weight_fx[i] = ( Word16 ) (* ( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15); hrtf_data_rptr += sizeof( float ); } @@ -1077,8 +1220,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1086,12 +1229,12 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); /* coeff_im (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1109,8 +1252,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1118,7 +1261,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } @@ -1146,8 +1289,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1155,7 +1298,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -1176,8 +1319,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) + //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1185,7 +1328,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - // hrtf_data_rptr += mem_size; + //hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -2189,11 +2332,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( /*adding conversion as file reading is done in float*/ floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricReverberationEneCorrections_fx, Q31, CLDFB_NO_CHANNELS_MAX ); - // memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + //memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); memcpy( f_tmp_reverb, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( float ); /*adding conversion as file reading is done in float*/ - floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); + floatToFixed_arrL( f_tmp_reverb, (*hHRTF)->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); return IVAS_ERR_OK; } -- GitLab From 4515e871a17498dc53d01c4e22d507b7847bf4c0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 10 Jun 2024 21:40:31 +0530 Subject: [PATCH 19/63] clang formatting changes --- lib_com/ivas_prot_fx.h | 2 +- lib_dec/acelp_core_switch_dec_fx.c | 101 ++-- lib_dec/amr_wb_dec_fx.c | 151 +++--- lib_dec/ari_dec_fx.c | 57 +- lib_dec/ari_hm_dec.c | 99 ++-- lib_dec/arith_coder_dec.c | 66 +-- lib_dec/arith_coder_dec_fx.c | 38 +- lib_dec/avq_dec_fx.c | 131 +++-- lib_dec/bass_psfilter.c | 85 +-- lib_dec/bass_psfilter_fx.c | 72 +-- lib_dec/cng_dec_fx.c | 209 ++++---- lib_dec/core_dec_init.c | 12 +- lib_dec/core_dec_init_fx.c | 714 ++++++++++++++++---------- lib_dec/core_dec_reconf_fx.c | 91 ++-- lib_dec/core_dec_switch_fx.c | 30 +- lib_dec/ivas_dirac_dec.c | 4 +- lib_dec/vlpc_2st_dec.c | 2 +- lib_rend/ivas_objectRenderer_hrFilt.c | 16 +- lib_rend/ivas_stat_rend.h | 12 +- lib_util/hrtf_file_reader.c | 110 ++-- 20 files changed, 1158 insertions(+), 844 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 1c3e42ccd..659ae5827 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2108,7 +2108,7 @@ void ivas_dirac_dec_render_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *output_f[] /* o : rendered time signal */ + Word32 *output_f[] /* o : rendered time signal */ ); void ivas_dirac_dec_read_BS_fx( diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index ccea920dd..31af985cb 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -72,12 +72,13 @@ ivas_error acelp_core_switch_dec_fx( Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 ); Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); - set16_fx( mem_synth, 0, add(NS2SA( 16000, DELAY_CLDFB_NS ), 2) ); + set16_fx( mem_synth, 0, add( NS2SA( 16000, DELAY_CLDFB_NS ), 2 ) ); set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */ /* set multiplication factor according to the sampling rate */ - delta = 1; move16(); - IF ( GT_16( output_frame, L_FRAME16k ) ) + delta = 1; + move16(); + IF( GT_16( output_frame, L_FRAME16k ) ) { delta = shr( output_frame, 8 ); } @@ -97,7 +98,7 @@ ivas_error acelp_core_switch_dec_fx( IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { cbrate = L_add( st_fx->core_brate, 0 ); - IF ( GT_32( cbrate, ACELP_24k40 ) ) + IF( GT_32( cbrate, ACELP_24k40 ) ) { cbrate = L_add( ACELP_24k40, 0 ); } @@ -138,7 +139,7 @@ ivas_error acelp_core_switch_dec_fx( 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, 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( shl(L_SUBFR, 1), Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); + syn_12k8_fx( shl( L_SUBFR, 1 ), Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn ); IF( st_fx->hPFstat->on && ( EQ_16( st_fx->last_bwidth, NB ) ) ) { @@ -149,20 +150,20 @@ ivas_error acelp_core_switch_dec_fx( pitch_buf_tmp[i] = L_SUBFR; move16(); } - nb_post_filt_fx( shl(L_SUBFR, 1), st_fx->hPFstat, &tmp_noise, 0, synth_intFreq, Aq, pitch_buf_tmp, AUDIO, st_fx->BER_detect, 0 ); + nb_post_filt_fx( shl( L_SUBFR, 1 ), 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 ) ) { - deemph_fx( synth_intFreq, PREEMPH_FAC, shl(L_SUBFR, 1), &( st_fx->mem_deemph_fx ) ); + deemph_fx( synth_intFreq, PREEMPH_FAC, shl( L_SUBFR, 1 ), &( st_fx->mem_deemph_fx ) ); } ELSE { - deemph_fx( synth_intFreq, PREEMPH_FAC_16k, shl(L_SUBFR, 1), &( st_fx->mem_deemph_fx ) ); + deemph_fx( synth_intFreq, PREEMPH_FAC_16k, shl( L_SUBFR, 1 ), &( st_fx->mem_deemph_fx ) ); } - unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp + M, st_fx->agc_mem_fx, shl(L_SUBFR, 1) ); - Copy( syn_fx_tmp + M, synth_intFreq, shl(L_SUBFR, 1) ); + unscale_AGC( synth_intFreq, st_fx->Q_syn, syn_fx_tmp + M, st_fx->agc_mem_fx, shl( L_SUBFR, 1 ) ); + Copy( syn_fx_tmp + M, synth_intFreq, shl( L_SUBFR, 1 ) ); test(); IF( st_fx->hPFstat->on && ( NE_16( st_fx->last_bwidth, NB ) ) ) @@ -172,16 +173,16 @@ ivas_error acelp_core_switch_dec_fx( Residu3_fx( Aq, bpf_error_signal + M, exc, L_SUBFR, 1 ); E_UTIL_synthesis( 1, Aq, exc, bpf_error_signal, L_SUBFR, st_fx->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); scale_st_fx( synth_intFreq, bpf_error_signal, &st_fx->hPFstat->gain_prec, L_SUBFR ); - Copy( bpf_error_signal, synth_intFreq, shr(L_SUBFR, 1) ); - blend_subfr2_fx( bpf_error_signal + shr(L_SUBFR, 1), synth_intFreq + shr(L_SUBFR, 1), synth_intFreq + shr(L_SUBFR, 1)); + Copy( bpf_error_signal, synth_intFreq, shr( L_SUBFR, 1 ) ); + blend_subfr2_fx( bpf_error_signal + shr( L_SUBFR, 1 ), synth_intFreq + shr( L_SUBFR, 1 ), synth_intFreq + shr( L_SUBFR, 1 ) ); } st_fx->hPFstat->on = 0; move16(); - IF( NE_16(st_fx->flag_cna, 0 )) + IF( NE_16( st_fx->flag_cna, 0 ) ) { - generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, shl(L_SUBFR, 1), 0 ); + generate_masking_noise_fx( synth_intFreq, st_fx->Q_syn, st_fx->hFdCngDec->hFdCngCom, shl( L_SUBFR, 1 ), 0 ); } /*----------------------------------------------------------------* @@ -189,11 +190,11 @@ ivas_error acelp_core_switch_dec_fx( * Bass post-filter *----------------------------------------------------------------*/ - bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, shl(L_SUBFR, 1), NULL, + bass_psfilter_fx( st_fx->hBPF, st_fx->Opt_AMR_WB, synth_intFreq, shl( L_SUBFR, 1 ), NULL, st_fx->bpf_off, st_fx->stab_fac_fx, &st_fx->stab_fac_smooth_fx, GENERIC, st_fx->Q_syn, bpf_error_signal ); - IF ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -206,13 +207,13 @@ ivas_error acelp_core_switch_dec_fx( move16(); /* CLDFB analysis and add the BPF error signal */ - IF ( ( error = cldfb_save_memory( st_fx->cldfbBPF ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbBPF ) ) != IVAS_ERR_OK ) { return error; } i = 0; move16(); - IF ( EQ_16(st_fx->bpf_off, 0 )) + IF( EQ_16( st_fx->bpf_off, 0 ) ) { i = CLDFB_NO_COL_MAX_SWITCH; move16(); @@ -222,9 +223,10 @@ ivas_error acelp_core_switch_dec_fx( cldfb_restore_memory( st_fx->cldfbBPF ); /* CLDFB synthesis of the combined signal */ - scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); + scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); - IF ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -233,7 +235,7 @@ ivas_error acelp_core_switch_dec_fx( *Q_syn = 0; move16(); - Copy_Scale_sig( synth_intFreq + sub(NS2SA( i_mult(L_frame_for_cs, 50), L_sub(SWITCH_GAP_LENGTH_NS, DELAY_CLDFB_NS) ), 2), mem_synth, add(NS2SA( i_mult(L_frame_for_cs, 50), DELAY_CLDFB_NS ), 2), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ + Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), L_sub( SWITCH_GAP_LENGTH_NS, DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */ /*----------------------------------------------------------------* * BWE decoding @@ -258,7 +260,7 @@ ivas_error acelp_core_switch_dec_fx( test(); IF( decode_bwe && !( ( EQ_16( output_frame, L_FRAME16k ) && EQ_16( st_fx->last_L_frame, L_FRAME16k ) ) || EQ_16( output_frame, L_FRAME8k ) ) ) { - set16_fx( tmp_mem2, 0, shl(L_FILT48k, 1)); + set16_fx( tmp_mem2, 0, shl( L_FILT48k, 1 ) ); hp_filter = hp16000_48000_fx; fdelay = 48; @@ -297,7 +299,7 @@ ivas_error acelp_core_switch_dec_fx( /* safety check in case of bit errors */ i = MAX_D1M_16k; move16(); - IF ( EQ_16( st_fx->last_L_frame, L_FRAME ) ) + IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { i = MAX_D1M_12k8; move16(); @@ -312,7 +314,7 @@ ivas_error acelp_core_switch_dec_fx( move16(); } - i = NS2SA_fx2( st_fx->output_Fs, L_sub(FRAME_SIZE_NS, L_add(ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS)) ); + i = NS2SA_fx2( st_fx->output_Fs, L_sub( FRAME_SIZE_NS, L_add( ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS ) ) ); move16(); Copy( st_fx->old_synth_sw_fx, hb_synth_tmp, i ); set16_fx( hb_synth_tmp + i, 0, NS2SA_fx2( st_fx->output_Fs, 10000000L ) - i ); @@ -421,10 +423,10 @@ ivas_error acelp_core_switch_dec_bfi_fx( set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - IF ( st_fx->hBWE_TD != NULL ) + IF( st_fx->hBWE_TD != NULL ) { - Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, shl(PIT16k_MAX, 1) ); - bwe_exc = old_bwe_exc + shl(PIT16k_MAX, 1); + Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, shl( PIT16k_MAX, 1 ) ); + bwe_exc = old_bwe_exc + shl( PIT16k_MAX, 1 ); } ELSE { @@ -437,7 +439,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( move16(); /* SC-VBR */ - IF ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) + IF( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); @@ -464,13 +466,15 @@ ivas_error acelp_core_switch_dec_bfi_fx( { Word16 gain_buf[NB_SUBFR16k]; Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); - st_fx->Q_exc = 0; move16(); + st_fx->Q_exc = 0; + move16(); /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); 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; move16(); + st_fx->Q_exc = Q_exc; + move16(); } ELSE { @@ -515,7 +519,8 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy( st_fx->mem_syn2_fx, tmp_float, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); - tmp_float32 = st_fx->enr_old_fx; move32(); + tmp_float32 = st_fx->enr_old_fx; + move32(); frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* @@ -557,12 +562,13 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy( tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST ); Copy( tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST ); Copy( tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST ); - hBPF->psf_att_fx = tmp_float7; move16(); + hBPF->psf_att_fx = tmp_float7; + move16(); /*----------------------------------------------------------------* * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - IF ( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -570,10 +576,11 @@ ivas_error acelp_core_switch_dec_bfi_fx( negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer ); cldfb_restore_memory( st_fx->cldfbAna ); - scaleFactor.hb_scale = scaleFactor.lb_scale; move16(); + scaleFactor.hb_scale = scaleFactor.lb_scale; + move16(); /* CLDFB synthesis of the combined signal */ - IF ( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -662,7 +669,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( set16_fx( old_exc2, 0, L_EXC_MEM ); } exc2 = old_exc2 + L_EXC_MEM; - IF ( st_fx->hBWE_TD != NULL ) + 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; @@ -678,7 +685,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( move16(); /* SC-VBR */ - IF ( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) + IF( EQ_16( st_fx->last_nelp_mode_dec, 1 ) ) { st_fx->nelp_mode_dec = 1; move16(); @@ -705,13 +712,15 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( { Word16 gain_buf[NB_SUBFR16k]; Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc ); - st_fx->Q_exc = 0; move16(); + st_fx->Q_exc = 0; + move16(); /* SC-VBR */ decod_nelp_fx( st_fx, &tmp_noise, pitch_buf, exc, exc2, voice_factors, bwe_exc, &Q_exc, st_fx->bfi, gain_buf ); FEC_pitch = pitch_buf[3]; move16(); 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; move16(); + st_fx->Q_exc = Q_exc; + move16(); } ELSE { @@ -756,7 +765,8 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy( st_fx->mem_syn2_fx, tmp_float, M ); syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp_float, 1, Q_exc, st_fx->Q_syn ); - tmp_float32 = st_fx->enr_old_fx; move32(); + tmp_float32 = st_fx->enr_old_fx; + move32(); frame_ener_fx( st_fx->L_frame, st_fx->last_good, syn, shr( add( FEC_pitch, 32 ), 6 ), &tmp_float32, st_fx->L_frame, st_fx->Q_syn, 3, 0 ); /*------------------------------------------------------------------* @@ -803,9 +813,9 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( * Resamping to the output sampling frequency *----------------------------------------------------------------*/ /* CLDFB analysis of the synthesis at internal sampling rate */ - Qtmp = sub(11, st_fx->Q_syn); + Qtmp = sub( 11, st_fx->Q_syn ); Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); - IF ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ) != IVAS_ERR_OK ) { return error; } @@ -817,7 +827,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( // scaleFactor.hb_scale = scaleFactor.lb_scale; /* CLDFB synthesis of the combined signal */ - IF ( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) + IF( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbSyn ) ) != IVAS_ERR_OK ) { return error; } @@ -872,7 +882,8 @@ static void decod_gen_voic_core_switch_fx( GSC_DEC_HANDLE hGSCDec; hGSCDec = st_fx->hGSCDec; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; move16(); + Flag Overflow = 0; + move16(); #endif @@ -905,7 +916,7 @@ static void decod_gen_voic_core_switch_fx( * Find the adaptive codebook vector. *--------------------------------------------------------------*/ - pred_lt4( &exc[0], &exc[0], T0, T0_frac, add(L_SUBFR, 1), pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); + pred_lt4( &exc[0], &exc[0], T0, T0_frac, add( L_SUBFR, 1 ), pitch_inter4_2, L_INTERPOL2, PIT_UP_SAMP ); /*--------------------------------------------------------------* * LP filtering of the adaptive excitation diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 5a7168372..d4cfde66c 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -39,7 +39,7 @@ ivas_error amr_wb_dec_fx( Word16 lsp_new_fx[M]; /* LSPs at the end of the frame */ Word16 lsf_new_fx[M]; /* LSFs at the end of the frame */ Word16 xsp_tmp[M]; - Word16 Aq_fx[NB_SUBFR * (M + 1)]; /* A(q) quantized for the 4 subframes */ + Word16 Aq_fx[NB_SUBFR * ( M + 1 )]; /* A(q) quantized for the 4 subframes */ Word16 exc2_fx[L_FRAME]; /* total excitation buffer */ Word16 mem_tmp_fx[M]; /* temporary synthesis filter memory */ Word32 L_enr_q_fx; /* E information for FER protection */ @@ -51,7 +51,8 @@ ivas_error amr_wb_dec_fx( Word32 L_tmp, L_tmp1; Word16 pitch_buf_fx[NB_SUBFR], Qdct, tmp_coder_type; /* floating pitch for each subframe (Q6) */ Word16 tmp16; - Word16 sid_bw = 0; move16(); + Word16 sid_bw = 0; + move16(); Word32 L_Ng_ener; Word16 exp2, ng_ener; @@ -138,7 +139,7 @@ ivas_error amr_wb_dec_fx( st_fx->bpf_off = 0; move16(); - IF ( EQ_16( st_fx->last_core, HQ_CORE ) ) + IF( EQ_16( st_fx->last_core, HQ_CORE ) ) { st_fx->bpf_off = 1; move16(); @@ -149,11 +150,12 @@ ivas_error amr_wb_dec_fx( move16(); st_fx->sr_core = i_mult( st_fx->L_frame, 50 ); - st_fx->fscale_old = st_fx->fscale; move16(); + st_fx->fscale_old = st_fx->fscale; + move16(); st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Initialization in case that the first frame is the good received AMR-WB (IO) frame */ - IF( EQ_16(st_fx->ini_frame, 0 )) + IF( EQ_16( st_fx->ini_frame, 0 ) ) { st_fx->last_core = AMR_WB_CORE; move16(); @@ -168,7 +170,7 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ - IF ( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -186,12 +188,12 @@ ivas_error 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 ( EQ_16(st_fx->hPFstat->on, 0 )) + IF( EQ_16( st_fx->hPFstat->on, 0 ) ) { st_fx->hPFstat->reset = 1; move16(); } - IF( GT_16(st_fx->bfi, 0 )) + IF( GT_16( st_fx->bfi, 0 ) ) { st_fx->nbLostCmpt = add( st_fx->nbLostCmpt, 1 ); } @@ -221,7 +223,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - IF ( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( NE_16(st_fx->last_core, 0 )) ) + IF( st_fx->last_con_tcx && ( NE_16( st_fx->L_frameTCX_past, st_fx->L_frame ) ) && ( NE_16( st_fx->last_core, 0 ) ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -240,7 +242,7 @@ ivas_error amr_wb_dec_fx( st_fx->bpf_off = 1; move16(); - IF ( NE_16(st_fx->hPFstat->on, 0 )) + IF( NE_16( st_fx->hPFstat->on, 0 ) ) { Word16 mem_syn_r_size_old, mem_syn_r_size_new; @@ -280,28 +282,31 @@ ivas_error amr_wb_dec_fx( IF( EQ_16( st_fx->last_L_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - tmp16 = 13107; move16(); + tmp16 = 13107; + move16(); } ELSE IF( EQ_16( st_fx->last_L_frame, 512 ) ) { /* (float)12800/(float)25600; */ - tmp16 = 16384; move16(); + tmp16 = 16384; + move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - tmp16 = 26214; move16(); + tmp16 = 26214; + move16(); } - FOR( i = sub(NB_SUBFR16k, NB_SUBFR); i < NB_SUBFR16k; i++ ) + FOR( i = sub( NB_SUBFR16k, NB_SUBFR ); i < NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[sub(i, 1)] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[sub( i, 1 )] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } - FOR( i = sub(shl(NB_SUBFR16k, 1), NB_SUBFR); i < shl(NB_SUBFR16k, 1); i++ ) + FOR( i = sub( shl( NB_SUBFR16k, 1 ), NB_SUBFR ); i < shl( NB_SUBFR16k, 1 ); i++ ) { - st_fx->old_pitch_buf_fx[sub(i, 2)] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); + st_fx->old_pitch_buf_fx[sub( i, 2 )] = Mpy_32_16_1( st_fx->old_pitch_buf_fx[i], tmp16 ); move32(); } } @@ -312,17 +317,20 @@ ivas_error amr_wb_dec_fx( IF( EQ_16( st_fx->bfi_pitch_frame, L_FRAME32k ) ) { /* (float)12800/(float)32000; */ - tmp16 = 13107; move16(); + tmp16 = 13107; + move16(); } ELSE IF( EQ_16( st_fx->bfi_pitch_frame, 512 ) ) { /* (float)12800/(float)25600; */ - tmp16 = 16384; move16(); + tmp16 = 16384; + move16(); } ELSE /* st->bfi_pitch_frame == L_FRAME16k */ { /* (float)12800/(float)16000; */ - tmp16 = 26214; move16(); + tmp16 = 26214; + move16(); } st_fx->bfi_pitch_fx = mult_r( tmp16, st_fx->bfi_pitch_fx ); st_fx->bfi_pitch_frame = L_FRAME; @@ -335,13 +343,13 @@ ivas_error amr_wb_dec_fx( { /* reset the unvoiced/audio signal improvement memories */ 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 + add(M, 1), add(M, 1) ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult(2, add(M, 1)), add(M, 1) ); - Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult(3, add(M, 1)), add(M, 1) ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + add( M, 1 ), add( M, 1 ) ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 2, add( M, 1 ) ), add( M, 1 ) ); + Copy( st_fx->hAmrwb_IO->old_Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx + i_mult( 3, add( M, 1 ) ), add( M, 1 ) ); } /*End of _DIFF_FLOAT_FIX_*/ test(); - IF ( EQ_16( st_fx->last_bwidth, NB ) && NE_16(st_fx->ini_frame, 0 )) + IF( EQ_16( st_fx->last_bwidth, NB ) && NE_16( st_fx->ini_frame, 0 ) ) { st_fx->rate_switching_reset = 1; move16(); @@ -382,13 +390,14 @@ ivas_error amr_wb_dec_fx( delta_mem_scale = 3; move16(); - IF ( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ + IF( LT_32( st_fx->lp_ener_fx, 40 ) ) /* very low energy frames, less than 0.3125 */ { delta_mem_scale = 0; move16(); } - i = st_fx->Q_exc; move16(); + i = st_fx->Q_exc; + move16(); Rescale_exc( hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st_fx->hGSCDec->last_exc_dct_in_fx, st_fx->L_frame, st_fx->L_frame * 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, @@ -396,8 +405,8 @@ ivas_error amr_wb_dec_fx( Copy_Scale_sig( exc2_fx, exc2_fx, st_fx->L_frame, sub( st_fx->Q_exc, i ) ); /* update past excitation signals for LD music post-filter */ - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub(DCT_L_POST, add(L_FRAME, OFFSET2) )); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add(L_FRAME, OFFSET2) ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub( DCT_L_POST, add( L_FRAME, OFFSET2 ) ) ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add( 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 ); @@ -420,7 +429,7 @@ ivas_error amr_wb_dec_fx( st_fx->psf_lp_noise_fx = round_fx( L_mac( L_mult( 32440, st_fx->psf_lp_noise_fx ), 328, frame_e_fx ) ); /*Q8*/ } /* update old synthesis for classification */ - Copy( syn_fx + sub(L_FRAME, L_SYN_MEM_CLAS_ESTIM), st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + sub( L_FRAME, 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 */ @@ -460,7 +469,7 @@ ivas_error amr_wb_dec_fx( st_fx->coder_type = GENERIC; move16(); - IF ( EQ_16(vad_flag, 0 )) + IF( EQ_16( vad_flag, 0 ) ) { st_fx->coder_type = INACTIVE; move16(); @@ -522,7 +531,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); test(); - IF ( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl(15, 7) ) ) + IF( EQ_16( st_fx->coder_type, INACTIVE ) && st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 7 ) ) ) { tmp16 = 1; move16(); @@ -543,9 +552,9 @@ ivas_error amr_wb_dec_fx( 0, 0, 0, st_fx->last_core_brate, -1 ); /* update past excitation signals for LD music post-filter */ - Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub(DCT_L_POST, add(L_FRAME, OFFSET2) )); - Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add(L_FRAME, OFFSET2) ), L_FRAME ); - Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, sub(DCT_L_POST, OFFSET2) ); + Copy( hMusicPF->dct_post_old_exc_fx + L_FRAME, hMusicPF->dct_post_old_exc_fx, sub( DCT_L_POST, add( L_FRAME, OFFSET2 ) ) ); + Copy( exc2_fx, hMusicPF->dct_post_old_exc_fx + sub( DCT_L_POST, add( L_FRAME, OFFSET2 ) ), L_FRAME ); + Copy( hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, sub( DCT_L_POST, OFFSET2 ) ); IF( NE_16( output_frame, L_FRAME8k ) ) { @@ -559,12 +568,12 @@ ivas_error amr_wb_dec_fx( test(); test(); - IF( NE_16( amr_io_class, UNVOICED_CLAS ) && NE_16( st_fx->coder_type, INACTIVE ) && LT_16( st_fx->psf_lp_noise_fx, shl(15, 8) ) ) + IF( NE_16( amr_io_class, UNVOICED_CLAS ) && NE_16( st_fx->coder_type, INACTIVE ) && LT_16( st_fx->psf_lp_noise_fx, shl( 15, 8 ) ) ) { tmp_coder_type = AUDIO; move16(); test(); - IF ( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) + IF( EQ_16( st_fx->last_coder_type, INACTIVE ) || EQ_16( st_fx->last_coder_type, UNVOICED ) ) { tmp_coder_type = INACTIVE; move16(); @@ -630,7 +639,7 @@ ivas_error amr_wb_dec_fx( { /* long burst frame erasures */ test(); - IF ( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) + IF( GT_16( st_fx->nbLostCmpt, 5 ) && GE_16( st_fx->clas_dec, VOICED_CLAS ) ) { st_fx->last_good = VOICED_TRANSITION; move16(); @@ -663,7 +672,7 @@ ivas_error amr_wb_dec_fx( /* Update circular buffer, keep last energy difference unchanged */ FOR( i = 1; i < MAX_LT; i++ ) { - hMusicPF->LDm_lt_diff_etot_fx[sub(i, 1)] = hMusicPF->LDm_lt_diff_etot_fx[i]; + hMusicPF->LDm_lt_diff_etot_fx[sub( i, 1 )] = hMusicPF->LDm_lt_diff_etot_fx[i]; move16(); } /* Filter energies update */ @@ -680,7 +689,7 @@ ivas_error amr_wb_dec_fx( 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 ); /* update old synthesis for classification */ - Copy( syn_fx + sub(L_FRAME, L_SYN_MEM_CLAS_ESTIM), st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); + Copy( syn_fx + sub( L_FRAME, L_SYN_MEM_CLAS_ESTIM ), st_fx->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); FOR( i = 0; i < NB_SUBFR; i++ ) @@ -733,7 +742,7 @@ ivas_error amr_wb_dec_fx( *-----------------------------------------------------------------*/ /* update old synthesis buffer - needed for ACELP internal sampling rate switching */ - Copy( syn_fx + sub(L_FRAME, L_SYN_MEM), st_fx->mem_syn_r, L_SYN_MEM ); + Copy( syn_fx + sub( L_FRAME, L_SYN_MEM ), st_fx->mem_syn_r, L_SYN_MEM ); deemph_fx( syn_fx, PREEMPH_FAC, L_FRAME, &( st_fx->mem_deemph_fx ) ); @@ -741,8 +750,8 @@ ivas_error amr_wb_dec_fx( Copy( syn_fx_tmp2, syn_fx, L_FRAME ); /* TCX=Q-1, ACELP2 Q0 */ - Copy_Scale_sig( syn_fx + shr(L_FRAME, 2), hTcxDec->old_syn_Overl, shr(L_FRAME, 2), sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ - Copy_Scale_sig( syn_fx + sub(L_FRAME, add(M, 1)), st_fx->syn, add(M, 1), sub( 0, st_fx->Q_syn ) ); /*Q0*/ + Copy_Scale_sig( syn_fx + shr( L_FRAME, 2 ), hTcxDec->old_syn_Overl, shr( L_FRAME, 2 ), sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ + Copy_Scale_sig( syn_fx + sub( L_FRAME, add( M, 1 ) ), st_fx->syn, add( M, 1 ), sub( 0, st_fx->Q_syn ) ); /*Q0*/ /*------------------------------------------------------------------* * Formant post-filter @@ -754,7 +763,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->on = 1; move16(); test(); - formant_post_filt_fx( 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, EQ_16(sub( amr_io_class, AUDIO_CLAS ), 0 )); + formant_post_filt_fx( 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, EQ_16( sub( amr_io_class, AUDIO_CLAS ), 0 ) ); } /*----------------------------------------------------------------* @@ -764,7 +773,7 @@ ivas_error amr_wb_dec_fx( flag_cna = 0; move16(); test(); - IF( ( GE_16( st_fx->psf_lp_noise_fx, shl(15, 8) ) ) || EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( ( GE_16( st_fx->psf_lp_noise_fx, shl( 15, 8 ) ) ) || EQ_16( st_fx->coder_type, INACTIVE ) ) { /*VAD only for non inactive frame*/ test(); @@ -784,13 +793,14 @@ ivas_error amr_wb_dec_fx( #else ApplyFdCng_fx( syn_fx, st_fx->Q_syn, NULL, NULL, NULL, st_fx, 0, 0 ); #endif - st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; move16(); + st_fx->hFdCngDec->hFdCngCom->frame_type_previous = st_fx->m_frame_type; + move16(); /*Noisy speech detector*/ noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD, syn_fx, st_fx->Q_syn ); st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - IF( NE_16(st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 )) + IF( NE_16( st_fx->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 ) ) { st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st_fx->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); @@ -799,7 +809,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); - IF( st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl(15, 8) ) ) + IF( st_fx->flag_cna && GE_16( st_fx->psf_lp_noise_fx, shl( 15, 8 ) ) ) { flag_cna = 1; move16(); @@ -818,16 +828,16 @@ ivas_error amr_wb_dec_fx( } - IF( EQ_16(flag_cna, 0 )) + IF( EQ_16( flag_cna, 0 ) ) { test(); test(); test(); IF( EQ_16( st_fx->last_flag_cna, 1 ) && ( ( EQ_16( st_fx->last_core, ACELP_CORE ) && NE_16( st_fx->last_coder_type, AUDIO ) ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) { - FOR( i = 0; i < shr(L_FRAME, 1); i++ ) + FOR( i = 0; i < shr( L_FRAME, 1 ); i++ ) { - syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add(i, shr(i_mult(5, L_FRAME), 2))], -st_fx->Q_syn ) ); + syn_fx[i] = add( syn_fx[i], shr_r( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add( i, shr( i_mult( 5, L_FRAME ), 2 ) )], -st_fx->Q_syn ) ); move16(); } } @@ -840,7 +850,7 @@ ivas_error amr_wb_dec_fx( *----------------------------------------------------------------*/ /* check if the CLDFB works on the right sample rate */ - IF( NE_16(i_mult( st_fx->cldfbAna->usb, st_fx->cldfbAna->no_col ), L_FRAME )) + IF( NE_16( i_mult( st_fx->cldfbAna->usb, st_fx->cldfbAna->no_col ), L_FRAME ) ) { /* resample to ACELP internal sampling rate */ Word16 newCldfbBands = CLDFB_getNumChannels( INT_FS_FX ); @@ -848,7 +858,7 @@ ivas_error amr_wb_dec_fx( resampleCldfb( st_fx->cldfbAna, newCldfbBands, L_FRAME, 0 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, L_FRAME, 0 ); - IF ( GT_16(st_fx->ini_frame, 0 )) + IF( GT_16( st_fx->ini_frame, 0 ) ) { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); } @@ -866,7 +876,7 @@ ivas_error amr_wb_dec_fx( /* CLDFB analysis and add the BPF error signal */ i = 0; move16(); - IF ( EQ_16(st_fx->bpf_off, 0 )) + IF( EQ_16( st_fx->bpf_off, 0 ) ) { i = CLDFB_NO_COL_MAX; move16(); @@ -876,7 +886,7 @@ ivas_error amr_wb_dec_fx( st_fx->Q_syn2 = st_fx->Q_syn; move16(); - IF ( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) + IF( NE_16( st_fx->cldfbSyn->bandsToZero, sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ) ) ) { /* in case of BW switching, re-init to default */ st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->cldfbAna->no_channels ); @@ -937,7 +947,7 @@ ivas_error amr_wb_dec_fx( 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->hAmrwb_IO->old_Aq_fx, NB_SUBFR * add(M, 1) ); + Copy( Aq_fx, st_fx->hAmrwb_IO->old_Aq_fx, NB_SUBFR * add( M, 1 ) ); test(); test(); @@ -947,7 +957,7 @@ ivas_error amr_wb_dec_fx( test(); test(); test(); - IF ( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && 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 ) ) && EQ_16(st_fx->plcInfo.concealment_method, TCX_NONTONAL) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && 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 ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { waveadj_rec = 1; move16(); @@ -972,7 +982,7 @@ ivas_error amr_wb_dec_fx( move32(); st_fx->prev_Q_exc = st_fx->Q_exc; move16(); - IF ( !st_fx->bfi ) + IF( !st_fx->bfi ) { st_fx->last_total_brate = st_fx->total_brate; move32(); @@ -990,10 +1000,10 @@ ivas_error amr_wb_dec_fx( * Overlap of ACELP synthesis with old MDCT memory *----------------------------------------------------------------*/ - IF ( st_fx->bfi ) + IF( st_fx->bfi ) { /* calculate another loss frame to fill gap in case of switching frame loss */ - IF ( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) + IF( ( error = acelp_core_switch_dec_bfi_fx( st_fx, hHQ_core->fer_samples_fx, st_fx->coder_type ) ) != IVAS_ERR_OK ) { return error; } @@ -1048,17 +1058,19 @@ ivas_error amr_wb_dec_fx( /* Delay ACELP synthesis by DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS delay */ IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, L_sub(DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS) ); + tmps = NS2SA_fx2( st_fx->output_Fs, L_sub( 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 ) ); delay_signal( synth_out_fx, output_frame, st_fx->prev_synth_buffer_fx, tmps ); } - IF ( waveadj_rec ) + IF( waveadj_rec ) { - tmps = 0; move16(); + tmps = 0; + move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { - tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); move16(); + tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); + move16(); } waveform_adj2_fix( st_fx->tonalMDCTconceal.secondLastPcmOut, synth_out_fx + tmps, st_fx->plcInfo.data_noise, &st_fx->plcInfo.outx_new_n1_fx, @@ -1072,11 +1084,12 @@ ivas_error 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, L_add(ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS) ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, L_sub(FRAME_SIZE_NS, L_add(ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS)) ), sub( hHQ_core->Q_old_postdec, st_fx->Q_syn2 ) ); + Copy_Scale_sig( synth_out_fx + NS2SA_fx2( st_fx->output_Fs, L_add( ACELP_LOOK_NS, DELAY_BWE_TOTAL_NS ) ), st_fx->old_synth_sw_fx, NS2SA_fx2( st_fx->output_Fs, L_sub( FRAME_SIZE_NS, L_add( 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, TCXLTP_DELAY_NS ); move16(); + Word16 delta = NS2SA_fx2( st_fx->output_Fs, TCXLTP_DELAY_NS ); + move16(); 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 ); @@ -1114,11 +1127,11 @@ void amr_wb_dec_init_fx( hAmrwb_IO->Last_ener_fx = 0; move16(); - set16_fx( hAmrwb_IO->old_Aq_fx, 0, i_mult(NB_SUBFR, add(M, 1)) ); + set16_fx( hAmrwb_IO->old_Aq_fx, 0, i_mult( NB_SUBFR, add( M, 1 ) ) ); hAmrwb_IO->old_Aq_fx[0] = 16384; - hAmrwb_IO->old_Aq_fx[add(M, 1)] = 16384; - hAmrwb_IO->old_Aq_fx[i_mult(2, add( M, 1 ))] = 16384; - hAmrwb_IO->old_Aq_fx[i_mult(3, add( M, 1 ))] = 16384; + hAmrwb_IO->old_Aq_fx[add( M, 1 )] = 16384; + hAmrwb_IO->old_Aq_fx[i_mult( 2, add( M, 1 ) )] = 16384; + hAmrwb_IO->old_Aq_fx[i_mult( 3, add( M, 1 ) )] = 16384; move16(); move16(); move16(); diff --git a/lib_dec/ari_dec_fx.c b/lib_dec/ari_dec_fx.c index 584cb5028..26390d6e0 100644 --- a/lib_dec/ari_dec_fx.c +++ b/lib_dec/ari_dec_fx.c @@ -16,7 +16,7 @@ Word32 ari_decode_overflow_fx( Tastat *s ) { - return LE_32(L_sub( L_sub( s->high, 1 ), s->low ), 0); + return LE_32( L_sub( L_sub( s->high, 1 ), s->low ), 0 ); } /** @@ -34,7 +34,7 @@ void ari_start_decoding_14bits_fx( val = L_and( L_deposit_l( get_next_indice( st, cbitsnew ) ), 0xffffL ); s->low = L_deposit_l( 0 ); - s->high = L_add(ari_q4new, 1); + s->high = L_add( ari_q4new, 1 ); move32(); s->value = val; move32(); @@ -56,13 +56,13 @@ Word16 ari_start_decoding_14bits_prm_fx( FOR( i = 0; i < cbitsnew; i++ ) { val = L_shl( val, 1 ); - IF ( *( p + i ) ) + IF( *( p + i ) ) { val = L_add( val, 1 ); } } s->low = L_deposit_l( 0 ); - s->high = L_add(ari_q4new, 1); + s->high = L_add( ari_q4new, 1 ); move32(); s->value = val; move32(); @@ -90,20 +90,20 @@ static Word16 ari_lookup_s17_fx( range_h = extract_l( L_shr( range, 15 ) ); tmp = L_multi31x16_X2( range_h, range_l, p[8] ); - IF ( GT_32( tmp, cum ) ) + IF( GT_32( tmp, cum ) ) { p = p + 8; } tmp = L_multi31x16_X2( range_h, range_l, p[4] ); - IF ( GT_32( tmp, cum ) ) + IF( GT_32( tmp, cum ) ) { p = p + 4; } tmp = L_multi31x16_X2( range_h, range_l, p[2] ); - IF ( GT_32( tmp, cum ) ) + IF( GT_32( tmp, cum ) ) { p = p + 2; } @@ -115,7 +115,7 @@ static Word16 ari_lookup_s17_fx( tmp = L_multi31x16_X2( range_h, range_l, p[1] ); test(); - IF ( EQ_32( (Word32) ( &cum_freq[15] - p ),0 ) && ( GT_32( tmp, cum ) ) ) + IF( EQ_32( (Word32) ( &cum_freq[15] - p ), 0 ) && ( GT_32( tmp, cum ) ) ) { p = p + 1; } @@ -156,12 +156,12 @@ static Word16 ari_lookup_s27_fx( move16(); /* (il + ih) >> 1 */ tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - IF ( GT_32(tmp, 0 )) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - IF ( LE_32(tmp, 0 )) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -170,12 +170,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - IF ( GT_32(tmp, 0 )) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - IF ( LE_32(tmp, 0 )) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -184,12 +184,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - IF ( GT_32(tmp, 0 )) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - IF ( LE_32(tmp, 0 )) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -198,12 +198,12 @@ static Word16 ari_lookup_s27_fx( im = shr( add( il, ih ), 1 ); tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - IF ( GT_32(tmp, 0 )) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); } - IF ( LE_32(tmp, 0 )) + IF( LE_32( tmp, 0 ) ) { ih = im; move16(); @@ -215,7 +215,7 @@ static Word16 ari_lookup_s27_fx( im = add( il, 1 ); /* (il + ih) >> 1 */ tmp = L_multi31x16_X2( range_h, range_l, cum_freq[im] ); tmp = L_sub( tmp, cum ); - IF ( GT_32(tmp, 0 )) + IF( GT_32( tmp, 0 ) ) { il = im; move16(); @@ -237,12 +237,12 @@ static Word16 ari_lookup_bit_fx( range = L_shl( range, 13 ); /* L_multi31x16_X2(range_h, range_l, 8192) */ cum = L_sub( range, cum ); - IF ( GT_32(cum, 0 )) + IF( GT_32( cum, 0 ) ) { symbol = 1; move16(); } - IF ( LE_32(cum, 0 )) + IF( LE_32( cum, 0 ) ) { symbol = 0; move16(); @@ -275,15 +275,16 @@ static Word16 ari_decode_14bits_ext_fx( range = L_sub( high, low ); cum = L_add( L_shl( L_sub( value, low ), stat_bitsnew ), sub( shl( 1, stat_bitsnew ), 1 ) ); - IF ( LT_32(cum, 0 )) + IF( LT_32( cum, 0 ) ) { - cum = 0x7fffffff; move32(); + cum = 0x7fffffff; + move32(); } symbol = lookup_fn( cum, range, cum_freq ); high = L_add( low, mul_sbc_14bits( range, cum_freq[symbol] ) ); - low = L_add( low, mul_sbc_14bits( range, cum_freq[add(symbol, 1)] ) ); + low = L_add( low, mul_sbc_14bits( range, cum_freq[add( symbol, 1 )] ) ); FOR( i = 0; i < 0x7FFF; i++ ) { @@ -296,8 +297,8 @@ static Word16 ari_decode_14bits_ext_fx( { BREAK; } - assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC) ); - assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB) ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC ) ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB ) ); low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); low = L_shl( low, 1 ); high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); @@ -376,7 +377,7 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) { highlim = testval; move16(); - pows[k] = mult_r( pows[sub(k, 1)], pows[sub(k, 1)] ); + pows[k] = mult_r( pows[sub( k, 1 )], pows[sub( k, 1 )] ); move16(); testval = mult_r( pows[k], base ); @@ -389,7 +390,7 @@ static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base ) BREAK; } } - assert( LT_16(k, 12) ); /* maximum 2^10-1*/ + assert( LT_16( k, 12 ) ); /* maximum 2^10-1*/ /* narrow the range down */ FOR( k = sub( k, 2 ); k >= 0; k-- ) @@ -479,8 +480,8 @@ static Word16 ari_decode_14bits_notbl_fx( { BREAK; } - assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC) ); - assert( NE_16(tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB) ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0CCC ) ); + assert( NE_16( tab_ari_qnew[L_msb_high][L_msb_low], 0x0BBB ) ); low = L_msu( low, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); low = L_shl( low, 1 ); high = L_msu( high, 1, tab_ari_qnew[L_msb_high][L_msb_low] ); diff --git a/lib_dec/ari_hm_dec.c b/lib_dec/ari_hm_dec.c index bcbbdd341..e2d5e8de7 100644 --- a/lib_dec/ari_hm_dec.c +++ b/lib_dec/ari_hm_dec.c @@ -81,37 +81,37 @@ int16_t DecodeIndex( #ifdef IVAS_FLOAT_FIXED Word16 DecodeIndex_fx( - Decoder_State *st, - const Word16 Bandwidth, - Word16 *PeriodicityIndex) + Decoder_State *st, + const Word16 Bandwidth, + Word16 *PeriodicityIndex ) { - TCX_LTP_DEC_HANDLE hTcxLtpDec; - TCX_DEC_HANDLE hTcxDec; + TCX_LTP_DEC_HANDLE hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec; - hTcxLtpDec = st->hTcxLtpDec; - hTcxDec = st->hTcxDec; + hTcxLtpDec = st->hTcxLtpDec; + hTcxDec = st->hTcxDec; - test(); - IF(GT_16(hTcxDec->tcx_hm_LtpPitchLag, 0) && GT_16(hTcxLtpDec->tcxltp_gain, kLtpHmGainThr)) - { - Word16 LtpPitchIndex = sub(mult_r(hTcxDec->tcx_hm_LtpPitchLag, shl(1, sub(15, kLtpHmFractionalResolution))), 2); + test(); + IF( GT_16( hTcxDec->tcx_hm_LtpPitchLag, 0 ) && GT_16( hTcxLtpDec->tcxltp_gain, kLtpHmGainThr ) ) + { + Word16 LtpPitchIndex = sub( mult_r( hTcxDec->tcx_hm_LtpPitchLag, shl( 1, sub( 15, kLtpHmFractionalResolution ) ) ), 2 ); - *PeriodicityIndex = kLtpHmFlag; - move16(); - *PeriodicityIndex = s_or(*PeriodicityIndex, get_next_indice_fx(st, NumRatioBits[Bandwidth][LtpPitchIndex])); - *PeriodicityIndex = add(*PeriodicityIndex, 1); - move16(); - *PeriodicityIndex = s_or(*PeriodicityIndex, shl(LtpPitchIndex, 9)); - move16(); + *PeriodicityIndex = kLtpHmFlag; + move16(); + *PeriodicityIndex = s_or( *PeriodicityIndex, get_next_indice_fx( st, NumRatioBits[Bandwidth][LtpPitchIndex] ) ); + *PeriodicityIndex = add( *PeriodicityIndex, 1 ); + move16(); + *PeriodicityIndex = s_or( *PeriodicityIndex, shl( LtpPitchIndex, 9 ) ); + move16(); - return NumRatioBits[Bandwidth][LtpPitchIndex]; - } - ELSE - { - *PeriodicityIndex = get_next_indice_fx(st, 8); - move16(); - return 8; - } + return NumRatioBits[Bandwidth][LtpPitchIndex]; + } + ELSE + { + *PeriodicityIndex = get_next_indice_fx( st, 8 ); + move16(); + return 8; + } } #endif @@ -132,28 +132,30 @@ static int16_t tcx_hm_dequantize_gain( /* safety check in case of bit errors */ if ( !( 0 <= gain_idx && gain_idx < ( 1 << kTcxHmNumGainBits ) ) ) { - *gain = 0; move16(); + *gain = 0; + move16(); return 1; } - *gain = qGains[coder_type][gain_idx]; move16(); + *gain = qGains[coder_type][gain_idx]; + move16(); return 0; } #else static Word16 tcx_hm_dequantize_gain_fx( - Word16 coder_type, /* i : coder type Q0 */ - Word16 gain_idx, /* i: quantization index Q0 */ - Word16 *gain /* o: dequantized gain Q11 */ + Word16 coder_type, /* i : coder type Q0 */ + Word16 gain_idx, /* i: quantization index Q0 */ + Word16 *gain /* o: dequantized gain Q11 */ ) { - assert(0 <= coder_type && coder_type <= UNVOICED); + assert( 0 <= coder_type && coder_type <= UNVOICED ); /* safety check in case of bit errors */ test(); - IF(!(LE_16(0, gain_idx) && LT_16(gain_idx, shl(1, kTcxHmNumGainBits)))) + IF( !( LE_16( 0, gain_idx ) && LT_16( gain_idx, shl( 1, kTcxHmNumGainBits ) ) ) ) { *gain = 0; return 1; @@ -250,10 +252,10 @@ void tcx_hm_decode( *hm_bits = 0; move16(); - L_frame_m_256 = sub(L_frame, 256); + L_frame_m_256 = sub( L_frame, 256 ); test(); - IF(!(EQ_16(coder_type, VOICED) || EQ_16(coder_type, GENERIC))) + IF( !( EQ_16( coder_type, VOICED ) || EQ_16( coder_type, GENERIC ) ) ) { /* A bit error was encountered */ *hm_bits = -1; @@ -261,27 +263,27 @@ void tcx_hm_decode( return; } - NumTargetBits = CountIndexBits_fx((L_frame_m_256 >= 0), prm_hm[1]); + NumTargetBits = CountIndexBits_fx( ( L_frame_m_256 >= 0 ), prm_hm[1] ); - NumTargetBits = add(NumTargetBits, targetBits); + NumTargetBits = add( NumTargetBits, targetBits ); - IF (EQ_16(coder_type, VOICED)) + IF( EQ_16( coder_type, VOICED ) ) { - NumTargetBits = add(NumTargetBits, kTcxHmNumGainBits); + NumTargetBits = add( NumTargetBits, kTcxHmNumGainBits ); } - *hm_bits = add(sub(NumTargetBits, targetBits), 1); + *hm_bits = add( sub( NumTargetBits, targetBits ), 1 ); move16(); /* Convert the index to lag */ - UnmapIndex_fx(prm_hm[1], (L_frame_m_256 >= 0), LtpPitchLag, - ((LE_16(NumTargetBits, kSmallerLagsTargetBitsThreshold)) || (L_frame_m_256 < 0)), - &fract_res, &lag); + UnmapIndex_fx( prm_hm[1], ( L_frame_m_256 >= 0 ), LtpPitchLag, + ( ( LE_16( NumTargetBits, kSmallerLagsTargetBitsThreshold ) ) || ( L_frame_m_256 < 0 ) ), + &fract_res, &lag ); test(); test(); /* Render the harmonic model */ - IF(tcx_hm_render_fx(lag, fract_res, p)) + IF( tcx_hm_render_fx( lag, fract_res, p ) ) { /* A bit error was encountered */ *hm_bits = -1; @@ -290,16 +292,17 @@ void tcx_hm_decode( } /* Dequantize gain */ - IF(tcx_hm_dequantize_gain_fx((Word16)EQ_16(coder_type, VOICED), prm_hm[2], &gain)) + IF( tcx_hm_dequantize_gain_fx( (Word16) EQ_16( coder_type, VOICED ), prm_hm[2], &gain ) ) { /* A bit error was encountered */ - *hm_bits = -1; move16(); + *hm_bits = -1; + move16(); return; } - tcx_hm_modify_envelope_fx(gain, lag, fract_res, p, env, L_frame); + tcx_hm_modify_envelope_fx( gain, lag, fract_res, p, env, L_frame ); return; } -#endif \ No newline at end of file +#endif diff --git a/lib_dec/arith_coder_dec.c b/lib_dec/arith_coder_dec.c index 5e475806b..367100965 100644 --- a/lib_dec/arith_coder_dec.c +++ b/lib_dec/arith_coder_dec.c @@ -134,19 +134,19 @@ static Word16 tcx_arith_decode_ivas_fx( Tastat as; UWord16 exp_k; Word16 tmp; - //Word32 L_tmp; + // Word32 L_tmp; bp = ari_start_decoding_14bits_prm_ivas_fx( prm, 0, &as ); - tmp = sub(envelope_e, 1); + tmp = sub( envelope_e, 1 ); - //L_tmp = L_deposit_l(0); + // L_tmp = L_deposit_l(0); - FOR (k = 0; k < L_frame; k++) + FOR( k = 0; k < L_frame; k++ ) { - IF( EQ_16(envelope[k], 0 )) /* safety check in case of bit errors */ + IF( EQ_16( envelope[k], 0 ) ) /* safety check in case of bit errors */ { - set32_fx(q_spectrum, 0, L_frame); + set32_fx( q_spectrum, 0, L_frame ); return -1; } ELSE @@ -157,33 +157,33 @@ static Word16 tcx_arith_decode_ivas_fx( /* decode line magnitude */ bp = ari_decode_14bits_pow_ivas( prm, bp, target_bits, &q, &as, exp_k ); - IF ( NE_16(q, 0 )) + IF( NE_16( q, 0 ) ) { /* line is non-zero, decode sign */ bp = ari_decode_14bits_sign_ivas( prm, bp, target_bits, &s, &as ); - q_spectrum[k] = L_mult(q, sub(3, shl(s, 1))); - q_spectrum[k] = L_shl(q_spectrum[k], 30 - SPEC_EXP_DEC); + q_spectrum[k] = L_mult( q, sub( 3, shl( s, 1 ) ) ); + q_spectrum[k] = L_shl( q_spectrum[k], 30 - SPEC_EXP_DEC ); } ELSE { /* line is zero, no sign needed */ - q_spectrum[k] = L_deposit_l(0); + q_spectrum[k] = L_deposit_l( 0 ); } - IF (LE_32(as.high, as.low)) + IF( LE_32( as.high, as.low ) ) { - IF ( LT_16(bp, target_bits) ) /* safety check in case of bit errors */ + IF( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ { bp = -1; move16(); } - BREAK; /* no bits left, so exit loop */ + BREAK; /* no bits left, so exit loop */ } } *q_spectrum_e = SPEC_EXP_DEC; move16(); - set32_fx(q_spectrum + k, 0, sub(L_frame, k)); + set32_fx( q_spectrum + k, 0, sub( L_frame, k ) ); return bp; } @@ -242,7 +242,7 @@ void tcx_arith_decode_envelope( gamma_uw = 1.0f / st->gamma_float; #define WMC_TOOL_SKIP - tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); + tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, FL2WORD16( hTcxCfg->preemph_fac_flt ), FL2WORD16( gamma_w ), FL2WORD16( 0.5f * gamma_uw ), env ); #undef WMC_TOOL_SKIP if ( use_hm ) @@ -321,12 +321,17 @@ void tcx_arith_decode_envelope_ivas_fx( TCX_DEC_HANDLE hTcxDec; Word16 gamma_w, gamma_uw; Word16 hm_bits; - - test();test();test();test();test();test(); - 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)))) || - (LE_16(target_bits, 0))) + + test(); + test(); + test(); + test(); + test(); + test(); + 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 ) ) ) ) || + ( LE_16( target_bits, 0 ) ) ) { /* this could happen in case of bit errors */ st->BER_detect = 1; @@ -344,7 +349,8 @@ void tcx_arith_decode_envelope_ivas_fx( hTcxCfg = st->hTcxCfg; hTcxDec = st->hTcxDec; - *signaling_bits = 0; move16(); + *signaling_bits = 0; + move16(); assert( hTcxDec->enableTcxLpc ); gamma_w = MAX16B; @@ -356,13 +362,13 @@ void tcx_arith_decode_envelope_ivas_fx( tcx_arith_render_envelope_flt( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env ); #undef WMC_TOOL_SKIP - IF (NE_16(use_hm, 0)) + IF( NE_16( use_hm, 0 ) ) { - IF (NE_16(prm_hm[0], 0)) + IF( NE_16( prm_hm[0], 0 ) ) { - tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); + tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF (LT_16(hm_bits, 0)) + IF( LT_16( hm_bits, 0 ) ) { st->BER_detect = 1; move16(); @@ -380,13 +386,13 @@ void tcx_arith_decode_envelope_ivas_fx( hm_bits = 1; move16(); } - *signaling_bits = add(*signaling_bits, hm_bits); + *signaling_bits = add( *signaling_bits, hm_bits ); move16(); } L_spec_core = L_spec; move16(); - IF ( st->igf ) + IF( st->igf ) { L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); } @@ -398,14 +404,14 @@ void tcx_arith_decode_envelope_ivas_fx( move16(); /* safety check in case of bit errors */ - IF ( LT_16(*arith_bits, 0 )) + IF( LT_16( *arith_bits, 0 ) ) { st->BER_detect = 1; move16(); set32_fx( q_spectrum, 0, L_frame ); } - set32_fx(q_spectrum + L_spec, 0, sub(L_frame, L_spec)); + set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) ); return; } diff --git a/lib_dec/arith_coder_dec_fx.c b/lib_dec/arith_coder_dec_fx.c index d47a01cd5..ee9208b4e 100644 --- a/lib_dec/arith_coder_dec_fx.c +++ b/lib_dec/arith_coder_dec_fx.c @@ -29,8 +29,10 @@ static Word16 tcx_arith_decode_fx( Word16 tmp; Word32 L_tmp, Q; #ifdef BASOP_NOGLOB_DECLARE_LOCAL - Flag Overflow = 0; move32(); - Flag Carry = 0; move32(); + Flag Overflow = 0; + move32(); + Flag Carry = 0; + move32(); #endif @@ -40,7 +42,7 @@ static Word16 tcx_arith_decode_fx( L_tmp = L_deposit_l( 0 ); FOR( k = 0; k < L_frame; k++ ) { - IF( EQ_16(envelope[k], 0 )) /* safety check in case of bit errors */ + IF( EQ_16( envelope[k], 0 ) ) /* safety check in case of bit errors */ { set32_fx( q_spectrum, 0, L_frame ); return -1; @@ -52,11 +54,11 @@ static Word16 tcx_arith_decode_fx( /* decode line magnitude */ bp = ari_decode_14bits_pow_fx( prm, bp, target_bits, &q, &as, exp_k ); - IF ( EQ_16(q, 0 )) + IF( EQ_16( q, 0 ) ) { q_spectrum[k] = L_deposit_l( 0 ); } - IF( NE_16(q, 0 )) /* line is non-zero, decode sign */ + IF( NE_16( q, 0 ) ) /* line is non-zero, decode sign */ { bp = ari_decode_14bits_sign_fx( prm, bp, target_bits, &s, &as ); @@ -66,16 +68,16 @@ static Word16 tcx_arith_decode_fx( L_tmp = L_macNs( L_tmp, q, k ); #endif - Q = L_mult( q, negate(shl( 1, sub( 30, SPEC_EXP_DEC ) ) )); - IF ( EQ_16(s, 0 )) - Q = L_mult( q, shl(1, sub( 30, SPEC_EXP_DEC ) )); + Q = L_mult( q, negate( shl( 1, sub( 30, SPEC_EXP_DEC ) ) ) ); + IF( EQ_16( s, 0 ) ) + Q = L_mult( q, shl( 1, sub( 30, SPEC_EXP_DEC ) ) ); q_spectrum[k] = Q; move32(); } IF( ari_decode_overflow_fx( &as ) ) { - IF ( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ + IF( LT_16( bp, target_bits ) ) /* safety check in case of bit errors */ { bp = -1; move16(); @@ -125,7 +127,13 @@ void tcx_arith_decode_envelope_fx( Word16 hm_bits; tcx_cfg = st->hTcxCfg; - test(); test(); test(); test(); test(); test(); test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); 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 ) ) ) ) || @@ -157,13 +165,13 @@ void tcx_arith_decode_envelope_fx( tcx_arith_render_envelope( A_ind, L_frame, L_spec, tcx_cfg->preemph_fac, gamma_w, gamma_uw, env ); - IF( NE_16(use_hm, 0 )) + IF( NE_16( use_hm, 0 ) ) { - IF( NE_16(prm_hm[0], 0 )) + IF( NE_16( prm_hm[0], 0 ) ) { tcx_hm_decode( L_spec, env, target_bits, tcx_cfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits ); - IF( LT_16(hm_bits, 0 )) + IF( LT_16( hm_bits, 0 ) ) { st->BER_detect = 1; move16(); @@ -191,7 +199,7 @@ void tcx_arith_decode_envelope_fx( L_spec_core = L_spec; move16(); - IF ( st->igf ) + IF( st->igf ) { L_spec_core = s_min( L_spec_core, st->hIGFDec->infoIGFStartLine ); } @@ -203,7 +211,7 @@ void tcx_arith_decode_envelope_fx( move16(); /* safety check in case of bit errors */ - IF( LT_16(*arith_bits, 0 )) + IF( LT_16( *arith_bits, 0 ) ) { st->BER_detect = 1; move16(); diff --git a/lib_dec/avq_dec_fx.c b/lib_dec/avq_dec_fx.c index c40ee51b2..68d3e9549 100644 --- a/lib_dec/avq_dec_fx.c +++ b/lib_dec/avq_dec_fx.c @@ -79,32 +79,42 @@ void AVQ_demuxdec_fx( { move16(); svOrder[i] = j; - i = add(1, i); - j = add(1, j); + i = add( 1, i ); + j = add( 1, j ); } FOR( i = 0; i < NSV_MAX; i++ ) { - I[i] = (UWord16) -1; move16(); + I[i] = (UWord16) -1; + move16(); } FOR( i = 0; i < Nsv; i++ ) { - k = svOrder[i]; move16(); - test(); test(); test(); test(); test(); + k = svOrder[i]; + move16(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( avq_bit_sFlag, 2 ) && EQ_16( ( bits % 5 ), 4 ) && GT_16( bits, 8 ) && LT_16( bits, 30 ) && GE_16( k, trgtSvPos ) && LT_16( i, sub( Nsv, 1 ) ) ) { ordr_esti( Nsv - i, &trgtSvPos, &svOrder[i], Nsv ); - k = svOrder[i]; move16(); - avq_bit_sFlag = 1; move16(); + k = svOrder[i]; + move16(); + avq_bit_sFlag = 1; + move16(); } test(); IF( EQ_16( k, trgtSvPos ) && GT_16( avq_bit_sFlag, 0 ) ) { - test(); test(); + 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(); + avq_bit_sFlag = 0; + move16(); } ELSE { @@ -112,15 +122,17 @@ void AVQ_demuxdec_fx( } } - nq[k] = 0; move16(); /* initialization and also forced if the budget is exceeded */ + nq[k] = 0; + move16(); /* initialization and also forced if the budget is exceeded */ IF( GT_16( bits, 8 ) ) { /* read the unary code including the stop bit for nq[i] */ - nq[k] = -1; move16(); + nq[k] = -1; + move16(); DO { - nq[k] = add(nq[k], 1); + nq[k] = add( nq[k], 1 ); // IF ( 5 * nq[k] + 4 == bits ) IF( EQ_16( add( add( shl( nq[k], 2 ), nq[k] ), 4 ), bits ) ) @@ -165,51 +177,71 @@ void AVQ_demuxdec_fx( IF( GT_16( avq_bit_sFlag, 0 ) && GT_16( bits, 8 ) ) { i = svOrder[Nsv - 1]; - nq[i] = 0; move16(); + nq[i] = 0; + move16(); bitsMod = bits % 5; IF( NE_16( i, sub( Nsv, 1 ) ) ) { - nullVec = 0; move16(); - FOR( j = i; j < sub(Nsv, 1); j++ ) + nullVec = 0; + move16(); + FOR( j = i; j < sub( Nsv, 1 ); j++ ) { IF( EQ_16( nq[svOrder[j]], 0 ) ) { nullVec = add( nullVec, 1 ); } } - nq_est = idiv1616(bits, 5); - test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); - IF( ( GT_16( 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 ) ) ) && EQ_16( nq[svOrder[sub(Nsv, 2)]], 0 ) ) /* dummy bits */ + nq_est = idiv1616( bits, 5 ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GT_16( 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 ) ) ) && EQ_16( nq[svOrder[sub( Nsv, 2 )]], 0 ) ) /* dummy bits */ { dummy_bits = sub( 5, bitsMod ); bits = add( bits, dummy_bits ); /* add dummy bits */ - bitsMod = 0; move16(); + bitsMod = 0; + move16(); } - ELSE IF( GT_16( nq_est, 4 ) && ( ( EQ_16( bitsMod, 0 ) && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && EQ_16( nq[svOrder[sub(Nsv, 2)]], 0 ) ) /* wasted bits 4, 5 for nq 6,7..*/ + ELSE IF( GT_16( nq_est, 4 ) && ( ( EQ_16( bitsMod, 0 ) && GT_16( nullVec, 3 ) && LT_16( nullVec, 6 ) ) || ( EQ_16( bitsMod, 4 ) && EQ_16( nullVec, 5 ) ) ) && EQ_16( nq[svOrder[sub( Nsv, 2 )]], 0 ) ) /* wasted bits 4, 5 for nq 6,7..*/ { - underflow = 0; move16(); + underflow = 0; + move16(); IF( NE_16( ( add( bitsMod, nullVec ) % 5 ), 0 ) ) { - underflow = 1; move16(); + underflow = 1; + move16(); } dummy_bits = add( nullVec, underflow ); bits = add( bits, dummy_bits ); /* add dummy bits */ - bitsMod = 0; move16(); + bitsMod = 0; + move16(); } } - underflow = 1; move16(); + underflow = 1; + move16(); IF( NE_16( bitsMod, 4 ) ) { - underflow = 0; move16(); + underflow = 0; + move16(); bits = sub( bits, bitsMod ); } bits = add( bits, underflow ); /* read the unary code for unused bit*/ - unused_bits_idx = -1; move16(); + unused_bits_idx = -1; + move16(); DO { - unused_bits_idx = add(unused_bits_idx, 1); + unused_bits_idx = add( unused_bits_idx, 1 ); IF( EQ_16( add( add( shl( unused_bits_idx, 2 ), unused_bits_idx ), 4 ), sub( bits, 1 ) ) ) { BREAK; @@ -217,35 +249,43 @@ void AVQ_demuxdec_fx( } WHILE( get_next_indice_1( st ) ); - unusedbitsFlag = 0; move16(); + unusedbitsFlag = 0; + move16(); IF( EQ_16( dummy_bits, 0 ) ) { - test(); test(); test(); test(); + test(); + test(); + test(); + test(); IF( EQ_16( unused_bits_idx, 0 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) { - unusedbitsFlag = 1; move16(); + unusedbitsFlag = 1; + move16(); } ELSE IF( EQ_16( unused_bits_idx, 1 ) && GT_16( bits, BIT_SAVING_LOW_THR ) ) { - unusedbitsFlag = -1; move16(); + unusedbitsFlag = -1; + move16(); } } /*Compute AVQ code book number from unused Bits */ tmp = (Word16) ( sub( bits, add( add( shl( add( unusedbitsFlag, unused_bits_idx ), 2 ), unusedbitsFlag ), unused_bits_idx ) ) ); - nq_est = idiv1616(tmp, 5); - IF(EQ_16( ( tmp % 5 ), 0 )) + nq_est = idiv1616( tmp, 5 ); + IF( EQ_16( ( tmp % 5 ), 0 ) ) { - nq_est = nq_est; move16(); + nq_est = nq_est; + move16(); } ELSE { - nq_est = add( nq_est, 1 ); + nq_est = add( nq_est, 1 ); } IF( EQ_16( nq_est, 1 ) ) { - nq_est = 0; move16(); + nq_est = 0; + move16(); } bits = sub( bits, underflow ); @@ -256,9 +296,10 @@ void AVQ_demuxdec_fx( bits = sub( bits, 1 ); } - nq[i] = nq_est; move16(); + nq[i] = nq_est; + move16(); /* read codebook indices (rank I and event. Voronoi index kv) */ - read_cv_fx( st, &I[i], &kv[shl(i, 3)], nq[i], &bits ); + read_cv_fx( st, &I[i], &kv[shl( i, 3 )], nq[i], &bits ); bits = sub( bits, dummy_bits ); @@ -280,7 +321,7 @@ void AVQ_demuxdec_fx( xriq[add( shl( i, 3 ), j )] = code[j]; } } - move16(); + move16(); *nb_bits = bits; return; @@ -316,7 +357,7 @@ void AVQ_dec_lpc( /* decode all subvectors */ - FOR( l = sub(Nsv, 1); l >= 0; l-- ) + FOR( l = sub( Nsv, 1 ); l >= 0; l-- ) { nq = indx[l]; /* quantizer number (0,2,3..n) */ move16(); @@ -371,7 +412,7 @@ void AVQ_dec_lpc( /* write decoded RE8 vector */ FOR( i = 0; i < 8; i++ ) { - nvecq[add(shl( l, 3 ), i)] = c[i]; + nvecq[add( shl( l, 3 ), i )] = c[i]; move16(); } } @@ -407,12 +448,12 @@ static void read_cv_fx( } ELSE IF( LT_16( nq, 5 ) ) /* Q2, Q3, Q4 */ { - *I = get_next_indice( st, shl(nq, 2) ); + *I = get_next_indice( st, shl( nq, 2 ) ); bits = sub( bits, shl( nq, 2 ) ); } ELSE IF( EQ_16( s_and( nq, 1 ), 0 ) ) /* Q4 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 16); + *I = get_next_indice( st, 16 ); bits = sub( bits, 16 ); order_v = (Word16) sub( shr( nq, 1 ), 2 ); @@ -424,8 +465,8 @@ static void read_cv_fx( } ELSE /* Q3 + Voronoi extensions r=1,2,3,... */ { - *I = get_next_indice( st, 12); - bits = sub( bits, 12); + *I = get_next_indice( st, 12 ); + bits = sub( bits, 12 ); order_v = (Word16) sub( shr( nq, 1 ), 1 ); FOR( j = 0; j < 8; j++ ) diff --git a/lib_dec/bass_psfilter.c b/lib_dec/bass_psfilter.c index 6b75fd1dd..b721487fb 100644 --- a/lib_dec/bass_psfilter.c +++ b/lib_dec/bass_psfilter.c @@ -537,12 +537,15 @@ void addBassPostFilter_ivas_fx( Word16 i, b; Word16 maxBand; const Word32 *weights_fx; - Word16 nCol = cldfb->no_col; move16(); - Word16 nColToProcess = nCol; move16(); - Word16 nChan = cldfb->no_channels; move16(); + Word16 nCol = cldfb->no_col; + move16(); + Word16 nColToProcess = nCol; + move16(); + Word16 nChan = cldfb->no_channels; + move16(); IF( GT_16( samplesToProcess, -1 ) ) { - nColToProcess = idiv1616( sub(add( samplesToProcess, cldfb->no_channels), 1 ), cldfb->no_channels ); + nColToProcess = idiv1616( sub( add( samplesToProcess, cldfb->no_channels ), 1 ), cldfb->no_channels ); move16(); } @@ -684,15 +687,21 @@ Word16 res_bpf_adapt_ivas_fx( IF( EQ_16( hStereoDft->res_cod_band_max, 6 ) ) { - i_start = 39; move16(); - i_end = 64; move16(); - bw_inv = 1311; move16(); /* 1/(64 - 39) in Q15 */ + i_start = 39; + move16(); + i_end = 64; + move16(); + bw_inv = 1311; + move16(); /* 1/(64 - 39) in Q15 */ } ELSE { - i_start = 28; move16(); - i_end = 40; move16(); - bw_inv = 2720; move16(); /* 1/(40 - 28) in Q15*/ + i_start = 28; + move16(); + i_end = 40; + move16(); + bw_inv = 2720; + move16(); /* 1/(40 - 28) in Q15*/ } /* Measure energy of high frequency band in MDCT domain */ @@ -713,29 +722,34 @@ Word16 res_bpf_adapt_ivas_fx( res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv ); res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) ); - hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; move32(); + hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg; + move32(); /* Measure energy of discontinuities at subframe boundaries */ - error_nrg = 0; move32(); + error_nrg = 0; + move32(); FOR( i = 0; i < L_FRAME8k; i += STEREO_DFT_L_SUBFR_8k ) { tmp = L_sub( bpf_error_signal_8k[i], hStereoDft->bpf_error_signal_last_fx ); error_nrg = Madd_32_32( error_nrg, tmp, tmp ); - hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[add(i, sub(STEREO_DFT_L_SUBFR_8k, 1))]; move32(); + hStereoDft->bpf_error_signal_last_fx = bpf_error_signal_8k[add( i, sub( STEREO_DFT_L_SUBFR_8k, 1 ) )]; + move32(); } - error_nrg = L_shr( error_nrg, 1 ); // Q0 - error_nrg = Mpy_32_16_1( error_nrg, 6553 /* 0.2f in Q15 */ ); /* Division by 5 for average value */ + error_nrg = L_shr( error_nrg, 1 ); // Q0 + error_nrg = Mpy_32_16_1( error_nrg, 6553 /* 0.2f in Q15 */ ); /* Division by 5 for average value */ /* Form decision variable and apply limit */ - IF(LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg )) + IF( LT_32( ( L_shr( error_nrg, 1 ) ), res_hb_nrg ) ) { - bpf_error_ratio = (Word16)(L_shl((L_shl(error_nrg, Q5) / res_hb_nrg), Q8)); move16(); + bpf_error_ratio = (Word16) ( L_shl( ( L_shl( error_nrg, Q5 ) / res_hb_nrg ), Q8 ) ); + move16(); } ELSE { - bpf_error_ratio = shl( ONE_IN_Q12, 1 ); + bpf_error_ratio = shl( ONE_IN_Q12, 1 ); } bpf_error_ratio = add( mult( STEREO_DFT_BPF_ADAPT_BETA_FX, bpf_error_ratio ), mult( sub( MAX_16, STEREO_DFT_BPF_ADAPT_BETA_FX ), hStereoDft->bpf_error_ratio_mem_fx ) ); - hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio; move16(); + hStereoDft->bpf_error_ratio_mem_fx = bpf_error_ratio; + move16(); res_bpf_flag = (Word16) LT_16( bpf_error_ratio, ONE_IN_Q13 ); @@ -798,52 +812,61 @@ void bpf_pitch_coherence_ivas_fx( SWITCH( st->L_frame ) { case 80: - scaled_inv_L_frame = 26843545; move32(); + scaled_inv_L_frame = 26843545; + move32(); BREAK; case 160: - scaled_inv_L_frame = 13421773; move32(); + scaled_inv_L_frame = 13421773; + move32(); BREAK; case 256: - scaled_inv_L_frame = 8388608; move32(); + scaled_inv_L_frame = 8388608; + move32(); BREAK; case 320: - scaled_inv_L_frame = 6710886; move32(); + scaled_inv_L_frame = 6710886; + move32(); BREAK; case 512: - scaled_inv_L_frame = 4194304; move32(); + scaled_inv_L_frame = 4194304; + move32(); BREAK; case 640: - scaled_inv_L_frame = 3355443; move32(); + scaled_inv_L_frame = 3355443; + move32(); BREAK; case 960: - scaled_inv_L_frame = 2236962; move32(); + scaled_inv_L_frame = 2236962; + move32(); BREAK; default: - scaled_inv_L_frame = 0; move32(); + scaled_inv_L_frame = 0; + move32(); } nb_subfr = shr( st->L_frame, 6 ); test(); IF( GT_16( st->clas_dec, UNVOICED_CLAS ) && NE_16( st->element_mode, EVS_MONO ) ) { - pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add(nb_subfr, 3)], st->old_pitch_buf_fx[add(nb_subfr, 2)] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[add(nb_subfr, 1)] ) ) ); + pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add( nb_subfr, 3 )], st->old_pitch_buf_fx[add( nb_subfr, 2 )] ), L_add( st->old_pitch_buf_fx[nb_subfr], st->old_pitch_buf_fx[add( nb_subfr, 1 )] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn1 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); pcn1 = L_max( L_min( pcn1, 4096 ), 0 ); - pc = L_abs( L_sub( L_add( pitch_buf[sub(nb_subfr, 1)], pitch_buf[sub(nb_subfr, 2)] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); + pc = L_abs( L_sub( L_add( pitch_buf[sub( nb_subfr, 1 )], pitch_buf[sub( nb_subfr, 2 )] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn2 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); pcn2 = L_max( L_min( pcn2, 4096 ), 0 ); - pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add(nb_subfr, 3)], st->old_pitch_buf_fx[add(nb_subfr, 2)] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); + pc = L_abs( L_sub( L_add( st->old_pitch_buf_fx[add( nb_subfr, 3 )], st->old_pitch_buf_fx[add( nb_subfr, 2 )] ), L_add( pitch_buf[1], pitch_buf[0] ) ) ); pc = Mpy_32_32( pc, scaled_inv_L_frame ); pcn3 = L_add( Mpy_32_32( pc, K_PC_DEC_FX32 ), C_PC_DEC_FX ); pcn3 = L_max( L_min( pcn3, 4096 ), 0 ); IF( LT_32( L_add( pcn1, L_add( pcn2, pcn3 ) ), 10240 ) ) { - st->hBPF->psf_att_fx = 13107; move16(); /*Q15*/ + st->hBPF->psf_att_fx = 13107; + move16(); /*Q15*/ // st->hBPF->psf_att = 0.4f; set16_fx( &st->hBPF->Track_on_hist[L_TRACK_HIST - nb_subfr], 1, nb_subfr ); } diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index a6dae725f..c8287c00c 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -45,7 +45,8 @@ void bass_psfilter_init_fx( set16_fx( hBPF->Track_on_hist, 0, L_TRACK_HIST ); set16_fx( hBPF->vibrato_hist, 0, L_TRACK_HIST ); set16_fx( hBPF->mem_mean_pit_fx, 1280, L_TRACK_HIST ); /* 80 in Q4*/ - hBPF->psf_att_fx = 32767; move16(); + hBPF->psf_att_fx = 32767; + move16(); return; } @@ -157,7 +158,7 @@ void bass_psfilter_fx( { FOR( i = L_TRACK_HIST - 1; i > 0; i-- ) { - hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[sub(i, 1)]; + hBPF->mem_mean_pit_fx[i] = hBPF->mem_mean_pit_fx[sub( i, 1 )]; move16(); /*Q6 */ } Ltmp = L_deposit_l( 0 ); @@ -168,7 +169,7 @@ void bass_psfilter_fx( tmp = round_fx( Ltmp ); /*Q4*/ /*tmp2 = div_s(1,nb_subfr); //Q15 */ tmp = mult_r( tmp, 8192 ); /*divide per 4 (when L_frame == L_FRAME) -> Q4*/ - IF ( EQ_16( nb_subfr, 5 ) ) + IF( EQ_16( nb_subfr, 5 ) ) { tmp = mult_r( tmp, 26214 ); /* multiply by 0.8 for case where L_frame == L_FRAME16k*/ } @@ -181,7 +182,7 @@ void bass_psfilter_fx( dist_pit_diff = abs_s( sub( idx_pit_max, idx_pit_min ) ); diff_pit = sub( loc_pit_max, loc_pit_min ); /*Q4 */ test(); - IF ( EQ_16( L_frame, L_FRAME16k ) || EQ_16( L_frame, L_FRAME8k ) ) + IF( EQ_16( L_frame, L_FRAME16k ) || EQ_16( L_frame, L_FRAME8k ) ) { diff_pit = mult_r( diff_pit, 26214 ); /*Q4 */ } @@ -189,7 +190,7 @@ void bass_psfilter_fx( test(); test(); test(); - IF ( NE_16(coder_type, INACTIVE) && GE_16( diff_pit, shl(2, 4) ) && LT_16( diff_pit, shl(10, 4) ) && GE_16( dist_pit_diff, 3 ) ) + IF( NE_16( coder_type, INACTIVE ) && GE_16( diff_pit, shl( 2, 4 ) ) && LT_16( diff_pit, shl( 10, 4 ) ) && GE_16( dist_pit_diff, 3 ) ) { vibrato = 1; move16(); @@ -231,9 +232,10 @@ void bass_psfilter_fx( { /* do not use BPF for HQ core */ T_update = 80; - IF ( EQ_16( L_frame, L_FRAME8k ) ) + IF( EQ_16( L_frame, L_FRAME8k ) ) { - T_update = 40; move16(); + T_update = 40; + move16(); } move16(); set16_fx( T_sf, 0, 5 ); @@ -293,14 +295,14 @@ void bass_psfilter_fx( syn_fx = &syn_buf_fx[add( nbpsf_pit_max, i_subfr )]; syn2_fx = &syn2_buf_fx[i_subfr]; - IF( NE_16(T, 0 )) + IF( NE_16( T, 0 ) ) { test(); IF( GE_16( T, PIT_MIN ) && Opt_AMR_WB ) { T = Pit_track_fx( syn_fx, T ); - IF ( NE_16( T, T_sf[subfr_pos] ) ) + IF( NE_16( T, T_sf[subfr_pos] ) ) { Track_on = 1; move16(); @@ -364,14 +366,14 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - IF ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ /* gain = corr / ener */ gain = div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ); - IF ( LT_32(Lcorr, 0 )) + IF( LT_32( Lcorr, 0 ) ) { gain = sub( 0, gain ); } @@ -414,7 +416,7 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - IF ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } @@ -425,7 +427,7 @@ void bass_psfilter_fx( #else alpha = shr( div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ), exp2 ); /*Q15 */ #endif - IF ( LT_32(Lcorr, 0 )) + IF( LT_32( Lcorr, 0 ) ) { alpha = sub( 0, alpha ); } @@ -433,14 +435,16 @@ void bass_psfilter_fx( alpha = s_min( alpha, 16384 ); /*Q15 */ alpha = mult_r( alpha, hBPF->psf_att_fx ); - test(); test(); - test(); test(); + test(); + test(); + test(); + test(); IF( GT_16( alpha, 9830 ) && Track_on ) { alpha = 9830; move16(); } - ELSE IF ( GT_16( alpha, 13107 ) && vibrato ) + ELSE IF( GT_16( alpha, 13107 ) && vibrato ) { alpha = 13107; move16(); @@ -495,14 +499,14 @@ void bass_psfilter_fx( Lener = L_mac0( Lener, err[i], err[i] ); #endif } - exp2 = sub(-1, 2); + exp2 = sub( -1, 2 ); move16(); /* 'Lener' is divided by 2 */ IF( EQ_32( Lener, 2147483647L ) ) { Lener = L_deposit_h( -32768 ); - sigPtr = err + shr(subfr_len, 1); - FOR( i = 0; i < shr(subfr_len, 1); i++ ) + sigPtr = err + shr( subfr_len, 1 ); + FOR( i = 0; i < shr( subfr_len, 1 ); i++ ) { Lener0 = L_mult0( sigPtr[i], sigPtr[i] ); #ifdef BASOP_NOGLOB @@ -544,7 +548,7 @@ void bass_psfilter_fx( Track_on = 0; move16(); - IF ( EQ_16( coder_type, AUDIO ) ) /* GSC mode without temporal component */ + IF( EQ_16( coder_type, AUDIO ) ) /* GSC mode without temporal component */ { Track_on = 1; move16(); @@ -597,14 +601,14 @@ void bass_psfilter_fx( exp2 = norm_l( Lener ); tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - IF ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } exp2 = sub( exp, exp2 ); /* exponent num - exponent denom */ /* gain = corr / ener */ gain = div_s( round_fx( L_shl( Ltmp, exp ) ), tmp2 ); - IF ( LT_32(Lcorr, 0 )) + IF( LT_32( Lcorr, 0 ) ) { gain = sub( 0, gain ); } @@ -643,7 +647,7 @@ void bass_psfilter_fx( #else tmp2 = round_fx( L_shl( Lener, exp2 ) ); #endif - IF ( GT_16( tmp, tmp2 ) ) + IF( GT_16( tmp, tmp2 ) ) { exp = sub( exp, 1 ); } @@ -680,14 +684,14 @@ void bass_psfilter_fx( Lener = L_mac0( Lener, err[i], err[i] ); #endif } - exp2 = sub(-1, 2); + exp2 = sub( -1, 2 ); move16(); /* 'Lener' is divided by 2 */ IF( EQ_32( Lener, 2147483647L ) ) { Lener = L_deposit_h( -32768 ); - sigPtr = err + shr(subfr_len, 1); - FOR( i = 0; i < shr(subfr_len, 1); i++ ) + sigPtr = err + shr( subfr_len, 1 ); + FOR( i = 0; i < shr( subfr_len, 1 ); i++ ) { Lener0 = L_mult0( sigPtr[i], sigPtr[i] ); #ifdef BASOP_NOGLOB @@ -725,11 +729,11 @@ void bass_psfilter_fx( * update memory for next frame *-------------------------------------------------------*/ - FOR( i = sub(L_TRACK_HIST, 1); i > 0; i-- ) + FOR( i = sub( L_TRACK_HIST, 1 ); i > 0; i-- ) { - hBPF->Track_on_hist[i] = hBPF->Track_on_hist[sub(i, 1)]; + hBPF->Track_on_hist[i] = hBPF->Track_on_hist[sub( i, 1 )]; move16(); - hBPF->vibrato_hist[i] = hBPF->vibrato_hist[sub(i, 1)]; + hBPF->vibrato_hist[i] = hBPF->vibrato_hist[sub( i, 1 )]; move16(); } @@ -797,7 +801,7 @@ static Word16 Pit_track_fx( /* o : Pitch Lener0 = L_mult0( *v1, *v1 ); Ltmp0 = L_mult0( *v2, *v2 ); Lcorr0 = L_mult0( *v1++, *v2++ ); - FOR( i = 1; i < idiv1616(add( L_HALFR16k, NBPSF_L_EXTRA ), 14); i++ ) + FOR( i = 1; i < idiv1616( add( L_HALFR16k, NBPSF_L_EXTRA ), 14 ); i++ ) { #ifdef BASOP_NOGLOB Lener0 = L_mac0_sat( Lener0, *v1, *v1 ); @@ -815,7 +819,7 @@ static Word16 Pit_track_fx( /* o : Pitch test(); IF( EQ_32( Lener0, 2147483647L ) || EQ_32( Ltmp0, 2147483647L ) || - EQ_32( Lcorr0, 2147483647L ) || EQ_32( Lcorr0, L_add(-2147483647, - 1L) ) ) + EQ_32( Lcorr0, 2147483647L ) || EQ_32( Lcorr0, L_add( -2147483647, -1L ) ) ) { v1 -= i; move16(); @@ -860,7 +864,7 @@ static Word16 Pit_track_fx( /* o : Pitch /* Call the Integer Square Root (it will normalize again if req.) */ Ltmp = Isqrt( Ltmp ); /* We now do corr * 1 / sqrt(1/product) with high part of ratio only */ - exp1 = mac_r(950272, exp1, 16384 ); /*( 16 - 1 ) * 65536L - 0x8000L*/ + exp1 = mac_r( 950272, exp1, 16384 ); /*( 16 - 1 ) * 65536L - 0x8000L*/ exp2 = norm_l( Ltmp ); Ltmp = L_shl( Ltmp, exp2 ); exp1 = sub( exp1, exp2 ); @@ -875,7 +879,7 @@ static Word16 Pit_track_fx( /* o : Pitch Ltmp = L_shl( Ltmp, exp1 ); #endif /* cn = normalized correlation of pitch/2 */ - IF ( GT_32( Ltmp, 2040109466L ) ) /* 0.95f in Q31 */ + IF( GT_32( Ltmp, 2040109466L ) ) /* 0.95f in Q31 */ { T = T2; move16(); @@ -943,7 +947,7 @@ void addBassPostFilter_fx( /* now do the subtraction */ - IF( GT_16(nTimeSlots, 0 )) + IF( GT_16( nTimeSlots, 0 ) ) { /* Find common scale. */ b = s_max( cldfb_scale->lb_scale, scale.lb_scale ); diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index e581bed9d..1c5628c8c 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -50,9 +50,11 @@ void CNG_dec_fx( Word16 num_bits; Word16 weights, ptr, j, k; Word16 m1; - Word16 m = 0; move16(); + Word16 m = 0; + move16(); Word16 tmp[HO_HIST_SIZE * M]; - Word16 burst_ho_cnt = 0; move16(); + Word16 burst_ho_cnt = 0; + move16(); Word16 ll, s_ptr; Word32 L_enr, L_tmp1; Word16 tmp1, exp; @@ -93,14 +95,14 @@ void CNG_dec_fx( IF( EQ_32( st_fx->core_brate, SID_1k75 ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* de-quantize the LSF vector */ - IF( NE_16(st_fx->Opt_AMR_WB, 0 )) + IF( NE_16( st_fx->Opt_AMR_WB, 0 ) ) { /* Flt function */ isf_dec_amr_wb_fx( st_fx, Aq, lsf_new, lsp_new ); /* 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, shl(L_SUBFR, 1) ); + enr_new = Enr_1_Az_fx( Aq_tmp, shl( L_SUBFR, 1 ) ); IF( GT_16( shr( enr_new, 14 ), 0 ) ) { @@ -120,9 +122,9 @@ void CNG_dec_fx( /* 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, shl(L_SUBFR, 1)); + enr_new = Enr_1_Az_fx( Aq_tmp, shl( L_SUBFR, 1 ) ); - IF( GT_16(shr( enr_new, 14 ), 0 )) + IF( GT_16( shr( enr_new, 14 ), 0 ) ) { /* Use old LSP vector */ Copy( st_fx->lsp_old_fx, lsp_new, M ); @@ -138,7 +140,7 @@ void CNG_dec_fx( } /* Initialize the CNG spectral envelope in case of the very first CNG frame */ - IF( EQ_16(st_fx->first_CNG, 0 )) + IF( EQ_16( st_fx->first_CNG, 0 ) ) { Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); } @@ -154,7 +156,7 @@ void CNG_dec_fx( { istep = ISTEP_AMR_WB_SID_FX; move16(); - IF ( EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) ) { istep = ISTEP_SID_FX; move16(); @@ -163,7 +165,7 @@ void CNG_dec_fx( /* initialize the energy quantization parameters */ num_bits = 6; move16(); - IF ( EQ_16(st_fx->Opt_AMR_WB, 0 )) + IF( EQ_16( st_fx->Opt_AMR_WB, 0 ) ) { num_bits = 7; move16(); @@ -180,12 +182,12 @@ void CNG_dec_fx( { tmp1 = add( hTdCngDec->old_enr_index, 40 ); } - IF( GT_16( L_enr_index, tmp1 ) && GE_16(hTdCngDec->old_enr_index, 0 )) /* Likely bit error and not startup */ + IF( GT_16( L_enr_index, tmp1 ) && GE_16( hTdCngDec->old_enr_index, 0 ) ) /* Likely bit error and not startup */ { L_enr_index = tmp1; move16(); L_enr_index = s_min( L_enr_index, 127 ); - IF ( NE_16(st_fx->Opt_AMR_WB, 0 )) + IF( NE_16( st_fx->Opt_AMR_WB, 0 ) ) { L_enr_index = s_min( L_enr_index, 63 ); } @@ -195,8 +197,8 @@ void CNG_dec_fx( test(); test(); IF( GT_32( st_fx->last_core_brate, SID_1k75 ) && - NE_16(st_fx->first_CNG, 0) && - GE_16(hTdCngDec->old_enr_index, 0) && + NE_16( st_fx->first_CNG, 0 ) && + GE_16( hTdCngDec->old_enr_index, 0 ) && GT_16( L_enr_index, add( hTdCngDec->old_enr_index, 1 ) ) ) { *allow_cn_step = 1; @@ -205,7 +207,7 @@ void CNG_dec_fx( hTdCngDec->old_enr_index = L_enr_index; move16(); - IF ( EQ_16(L_enr_index, 0 )) + IF( EQ_16( L_enr_index, 0 ) ) { L_enr_index = -5; move16(); @@ -226,7 +228,7 @@ void CNG_dec_fx( burst_ho_cnt = get_next_indice( st_fx, 3 ); /* 3bit */ *sid_bw = get_next_indice( st_fx, 1 ); - IF( EQ_16(*sid_bw, 0 )) + IF( EQ_16( *sid_bw, 0 ) ) { env_idx[0] = get_next_indice( st_fx, 6 ); move16(); @@ -241,7 +243,7 @@ void CNG_dec_fx( /* Reset CNG history IF CNG frame length is changed */ test(); test(); - IF( EQ_16( st_fx->bwidth, WB ) && NE_16(st_fx->first_CNG, 0) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) + IF( EQ_16( st_fx->bwidth, WB ) && NE_16( st_fx->first_CNG, 0 ) && NE_16( st_fx->L_frame, st_fx->last_CNG_L_frame ) ) { hTdCngDec->ho_hist_size = 0; move16(); @@ -255,10 +257,10 @@ void CNG_dec_fx( test(); test(); test(); - IF( LE_32(st_fx->last_core_brate, SID_2k40 )) + IF( LE_32( st_fx->last_core_brate, SID_2k40 ) ) { /* Reset hangover counter IF not first SID period */ - IF ( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) + IF( GT_32( st_fx->core_brate, FRAME_NO_DATA ) ) { hTdCngDec->num_ho = 0; move16(); @@ -301,7 +303,7 @@ void CNG_dec_fx( move16(); s_ptr = add( sub( hTdCngDec->ho_circ_ptr, burst_ho_cnt ), 1 ); move16(); - IF ( LT_16(s_ptr, 0 )) + IF( LT_16( s_ptr, 0 ) ) { s_ptr = add( s_ptr, hTdCngDec->ho_circ_size ); } @@ -309,7 +311,7 @@ void CNG_dec_fx( FOR( ll = burst_ho_cnt; ll > 0; ll-- ) { hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); - IF ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + IF( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); @@ -322,31 +324,31 @@ void CNG_dec_fx( IF( ( EQ_16( st_fx->L_frame, L_FRAME16k ) && hTdCngDec->ho_16k_lsp[s_ptr] == 0 ) || ( EQ_16( st_fx->L_frame, L_FRAME ) && EQ_16( hTdCngDec->ho_16k_lsp[s_ptr], 1 ) ) ) { /* Conversion from 16k LPSs to 12k8 */ - lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[i_mult(s_ptr, M)] ), st_fx->L_frame, 0 ); + lsp_convert_poly_fx( &( hTdCngDec->ho_lsp_circ_fx[i_mult( s_ptr, M )] ), st_fx->L_frame, 0 ); } /* update the circular buffers */ - Copy( &( hTdCngDec->ho_lsp_circ_fx[i_mult(s_ptr, M)] ), &( hTdCngDec->ho_lsp_hist_fx[i_mult(hTdCngDec->ho_hist_ptr, M)] ), M ); + Copy( &( hTdCngDec->ho_lsp_circ_fx[i_mult( s_ptr, M )] ), &( hTdCngDec->ho_lsp_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, M )] ), M ); Copy32( &( hTdCngDec->ho_ener_circ_fx[s_ptr] ), &( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] ), 1 ); hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - Copy32( &( hTdCngDec->ho_env_circ_fx[i_mult(s_ptr, NUM_ENV_CNG)] ), &( hTdCngDec->ho_env_hist_fx[i_mult(hTdCngDec->ho_hist_ptr, NUM_ENV_CNG)] ), NUM_ENV_CNG ); + Copy32( &( hTdCngDec->ho_env_circ_fx[i_mult( s_ptr, NUM_ENV_CNG )] ), &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG )] ), NUM_ENV_CNG ); hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - IF ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + IF( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); } s_ptr = add( s_ptr, 1 ); - IF ( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) + IF( EQ_16( s_ptr, hTdCngDec->ho_circ_size ) ) { s_ptr = 0; move16(); } } - IF( GT_16(hTdCngDec->ho_hist_size, 0 )) /* can be -1 at init MODE1_DTX_IN_CODEC_B_FIX */ + IF( GT_16( hTdCngDec->ho_hist_size, 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( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr], 2 ); @@ -354,7 +356,7 @@ void CNG_dec_fx( test(); test(); - IF ( ( GT_32(L_tmp1, 0) && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) + IF( ( GT_32( L_tmp1, 0 ) && ( st_fx->first_CNG || EQ_16( st_fx->element_mode, EVS_MONO ) ) ) ) { *allow_cn_step = s_or( *allow_cn_step, 1 ); } @@ -365,17 +367,17 @@ void CNG_dec_fx( move16(); } test(); - IF( EQ_16(*allow_cn_step, 0) && GT_16(hTdCngDec->ho_hist_size, 0) ) + IF( EQ_16( *allow_cn_step, 0 ) && GT_16( hTdCngDec->ho_hist_size, 0 ) ) { /* Use average of energies below last energy */ ptr = hTdCngDec->ho_hist_ptr; move16(); - Copy( &( hTdCngDec->ho_lsp_hist_fx[i_mult(ptr, M)] ), tmp, M ); + Copy( &( hTdCngDec->ho_lsp_hist_fx[i_mult( ptr, M )] ), tmp, M ); m1 = 0; move16(); - IF( EQ_32(L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ), 0 )) + IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x1 ), 0 ) ) { - Copy32( &hTdCngDec->ho_env_hist_fx[i_mult(ptr, NUM_ENV_CNG)], tmp_env, NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[i_mult( ptr, NUM_ENV_CNG )], tmp_env, NUM_ENV_CNG ); m1 = 1; move16(); } @@ -388,9 +390,9 @@ void CNG_dec_fx( FOR( k = 1; k < hTdCngDec->ho_hist_size; k++ ) { ptr = sub( ptr, 1 ); - IF (LT_16( ptr, 0 )) + IF( LT_16( ptr, 0 ) ) { - ptr = sub(HO_HIST_SIZE, 1); + ptr = sub( HO_HIST_SIZE, 1 ); move16(); } @@ -405,10 +407,10 @@ void CNG_dec_fx( /*weights += W_DTX_HO[k];*/ weights = add( weights, W_DTX_HO_FX[k] ); /* Q15 */ - Copy( &hTdCngDec->ho_lsp_hist_fx[i_mult(ptr, M)], &tmp[i_mult(m, M)], M ); - IF( EQ_32(L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 )) + Copy( &hTdCngDec->ho_lsp_hist_fx[i_mult( ptr, M )], &tmp[i_mult( m, M )], M ); + IF( EQ_32( L_and( hTdCngDec->ho_sid_bw, L_shl( (Word32) 0x1, k ) ), 0 ) ) { - Copy32( &hTdCngDec->ho_env_hist_fx[i_mult(ptr, NUM_ENV_CNG)], &tmp_env[i_mult(m1, NUM_ENV_CNG)], NUM_ENV_CNG ); + Copy32( &hTdCngDec->ho_env_hist_fx[i_mult( ptr, NUM_ENV_CNG )], &tmp_env[i_mult( m1, NUM_ENV_CNG )], NUM_ENV_CNG ); m1 = add( m1, 1 ); } m = add( m, 1 ); @@ -419,7 +421,7 @@ void CNG_dec_fx( exp = norm_s( weights ); tmp1 = div_s( shl( 1, sub( 14, exp ) ), weights ); /* Q(15+14-exp-15) */ 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 */ + L_enr = L_shl( L_tmp1, add( exp, 1 ) ); /* Q6 */ st_fx->lp_ener_fx = L_enr; /* Q6 */ @@ -430,27 +432,27 @@ void CNG_dec_fx( { IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - lsp2lsf_fx( &tmp[i_mult(i, M)], lsf_tmp, M, INT_FS_FX ); + lsp2lsf_fx( &tmp[i_mult( i, M )], lsf_tmp, M, INT_FS_FX ); ftmp_fx = 964; - move16(); /*X2.56 */ - tmpv = sub( 16384, add( lsf_tmp[sub(M, 1)], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + move16(); /*X2.56 */ + tmpv = sub( 16384, add( lsf_tmp[sub( M, 1 )], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } ELSE { - lsp2lsf_fx( &tmp[i_mult(i, M)], lsf_tmp, M, INT_FS_16k_FX ); + lsp2lsf_fx( &tmp[i_mult( i, M )], lsf_tmp, M, INT_FS_16k_FX ); ftmp_fx = 1205; - move16(); /*QX2.56*/ - tmpv = sub( 20480, add( lsf_tmp[sub(M, 1)], ftmp_fx ) ); /*QX2.56*/ - L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ + move16(); /*QX2.56*/ + tmpv = sub( 20480, add( lsf_tmp[sub( M, 1 )], ftmp_fx ) ); /*QX2.56*/ + L_tmp = L_mult0( tmpv, tmpv ); /*QX6.5536*/ } tmpv = sub( lsf_tmp[0], ftmp_fx ); /*QX2.56*/ L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ - FOR( j = 0; j < sub(M, 1); j++ ) + FOR( j = 0; j < sub( M, 1 ); j++ ) { - tmpv = sub( sub( lsf_tmp[add(j, 1)], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ - L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ + tmpv = sub( sub( lsf_tmp[add( j, 1 )], lsf_tmp[j] ), ftmp_fx ); /*QX2.56*/ + L_tmp = L_mac0( L_tmp, tmpv, tmpv ); /*QX6.5536*/ } C[i] = Mpy_32_16_1( L_tmp, 1928 ); /*QX6.5536*/ @@ -487,10 +489,10 @@ void CNG_dec_fx( L_tmp1 = 0; FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add(i_mult(j, M), i)] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add( i_mult( j, M ), i )] ) ); } - L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[add(i_mult(max_idx[0], M), i)] ) ); + L_tmp1 = L_sub( L_tmp1, L_deposit_l( tmp[add( i_mult( max_idx[0], M ), i )] ) ); tmpv = div_s( 1, sub( m, 1 ) ); /*Q15*/ L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ @@ -500,21 +502,24 @@ void CNG_dec_fx( { FOR( i = 0; i < M; i++ ) { - L_tmp1 = 0; move32(); + L_tmp1 = 0; + move32(); FOR( j = 0; j < m; j++ ) { - L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add(i_mult(j, M), i)] ) ); + L_tmp1 = L_add( L_tmp1, L_deposit_l( tmp[add( i_mult( j, M ), i )] ) ); } - L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[add(i_mult(max_idx[0], M), i)] ), L_deposit_l( tmp[add(i_mult(max_idx[1], M), i)] ) ) ); /*Q15*/ - tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ - L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ - lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ + L_tmp1 = L_sub( L_tmp1, L_add( L_deposit_l( tmp[add( i_mult( max_idx[0], M ), i )] ), L_deposit_l( tmp[add( i_mult( max_idx[1], M ), i )] ) ) ); /*Q15*/ + tmpv = div_s( 1, sub( m, 2 ) ); /*Q15*/ + L_tmp1 = Mpy_32_16_1( L_tmp1, tmpv ); /*Q15*/ + lsp_tmp[i] = extract_l( L_tmp1 ); /*Q15*/ } } - dist = 0; move16(); /*Q15*/ - max_dev = 0; move16(); /*Q15*/ + dist = 0; + move16(); /*Q15*/ + max_dev = 0; + move16(); /*Q15*/ FOR( i = 0; i < M; i++ ) { dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15*/ @@ -523,7 +528,7 @@ void CNG_dec_fx( #else dist = add( dist, dev ); /*Q15*/ #endif - IF ( GT_16( dev, max_dev ) ) + IF( GT_16( dev, max_dev ) ) { max_dev = dev; move16(); @@ -547,7 +552,7 @@ void CNG_dec_fx( st_fx->lspCNG_fx[i] = add( mult_r( 26214, lsp_tmp[i] ), mult_r( 6554, lsp_new[i] ) ); } } - IF( GT_16(m1, 0 )) + IF( GT_16( m1, 0 ) ) { FOR( i = 0; i < NUM_ENV_CNG; i++ ) { @@ -600,14 +605,14 @@ void CNG_dec_fx( /* Update hangover memory during CNG */ test(); #ifdef BASOP_NOGLOB - IF( EQ_16(*allow_cn_step, 0) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) + IF( EQ_16( *allow_cn_step, 0 ) && LT_32( hTdCngDec->Enew_fx, L_add_sat( st_fx->lp_ener_fx, L_shr( st_fx->lp_ener_fx, 1 ) ) ) ) #else 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 ) ) ) ) #endif { /* update the pointer to circular buffer of old LSP vectors */ hTdCngDec->ho_hist_ptr = add( hTdCngDec->ho_hist_ptr, 1 ); - IF ( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) + IF( EQ_16( hTdCngDec->ho_hist_ptr, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_ptr = 0; move16(); @@ -620,7 +625,7 @@ void CNG_dec_fx( hTdCngDec->ho_ener_hist_fx[hTdCngDec->ho_hist_ptr] = hTdCngDec->Enew_fx; move32(); test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16(*sid_bw, 0) ) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( *sid_bw, 0 ) ) { /* enr1 = (float)log10( st->Enew*L_frame + 0.1f ) / (float)log10( 2.0f );*/ exp = norm_l( hTdCngDec->Enew_fx ); @@ -653,16 +658,16 @@ void CNG_dec_fx( move32(); } hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); - Copy32( env, &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG)] ), NUM_ENV_CNG ); + Copy32( env, &( hTdCngDec->ho_env_hist_fx[i_mult( hTdCngDec->ho_hist_ptr, NUM_ENV_CNG )] ), NUM_ENV_CNG ); } - ELSE IF( NE_16(*sid_bw, 0 )) + ELSE IF( NE_16( *sid_bw, 0 ) ) { hTdCngDec->ho_sid_bw = L_shl( L_and( hTdCngDec->ho_sid_bw, (Word32) 0x3fffffffL ), 1 ); hTdCngDec->ho_sid_bw = L_or( hTdCngDec->ho_sid_bw, 0x1L ); } hTdCngDec->ho_hist_size = add( hTdCngDec->ho_hist_size, 1 ); - IF ( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) + IF( GT_16( hTdCngDec->ho_hist_size, HO_HIST_SIZE ) ) { hTdCngDec->ho_hist_size = HO_HIST_SIZE; move16(); @@ -672,7 +677,7 @@ void CNG_dec_fx( st_fx->last_CNG_L_frame = st_fx->L_frame; move16(); - IF ( NE_32( st_fx->core_brate, SID_1k75 ) ) + IF( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); @@ -680,9 +685,10 @@ void CNG_dec_fx( } /* Update the frame length memory */ - st_fx->last_CNG_L_frame = st_fx->L_frame; move16(); + st_fx->last_CNG_L_frame = st_fx->L_frame; + move16(); - IF ( NE_32( st_fx->core_brate, SID_1k75 ) ) + IF( NE_32( st_fx->core_brate, SID_1k75 ) ) { hTdCngDec->num_ho = m; move16(); @@ -700,7 +706,7 @@ void CNG_dec_fx( tmp_loop = shr( st_fx->L_frame, 6 ); FOR( i = 1; i < tmp_loop; i++ ) /* L_frame/L_SUBFR */ { - Copy( Aq, &Aq[i_mult(i, add( M, 1 ))], add(M, 1) ); + Copy( Aq, &Aq[i_mult( i, add( M, 1 ) )], add( M, 1 ) ); } return; @@ -723,11 +729,11 @@ void swb_CNG_dec_fx( ) { test(); - IF( EQ_32(st_fx->core_brate, FRAME_NO_DATA) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF( EQ_16(st_fx->cng_type, LP_CNG) && EQ_16( st_fx->extl, SWB_CNG ) ) + IF( EQ_16( st_fx->cng_type, LP_CNG ) && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -741,7 +747,7 @@ void swb_CNG_dec_fx( st_fx->last_vad_fx = 1; move16(); st_fx->hTdCngDec->burst_cnt = add( st_fx->hTdCngDec->burst_cnt, 1 ); - IF ( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) + IF( GT_16( st_fx->hTdCngDec->burst_cnt, 10 ) ) { st_fx->hTdCngDec->burst_cnt = 0; move16(); @@ -763,11 +769,11 @@ void swb_CNG_dec_ivas_fx( ) { test(); - IF( EQ_32(st_fx->core_brate, FRAME_NO_DATA) || EQ_32( st_fx->core_brate, SID_2k40 ) ) + IF( EQ_32( st_fx->core_brate, FRAME_NO_DATA ) || EQ_32( st_fx->core_brate, SID_2k40 ) ) { /* SHB SID decoding and CNG */ test(); - IF( EQ_16(st_fx->cng_type, LP_CNG) && EQ_16( st_fx->extl, SWB_CNG ) ) + IF( EQ_16( st_fx->cng_type, LP_CNG ) && EQ_16( st_fx->extl, SWB_CNG ) ) { shb_CNG_decod_ivas_fx( st_fx, synth_fx, shb_synth_fx, sid_bw, Qsyn ); } @@ -833,14 +839,14 @@ static void shb_CNG_decod_fx( TD_BWE_DEC_HANDLE hBWE_TD; hBWE_TD = st_fx->hBWE_TD; - IF( EQ_16(st_fx->bfi, 0 )) + IF( EQ_16( st_fx->bfi, 0 ) ) { test(); IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) ) { idx_ener_fx = get_next_indice( st_fx, 4 ); - IF ( EQ_16(idx_ener_fx, 0 )) + IF( EQ_16( idx_ener_fx, 0 ) ) { idx_ener_fx = -15; move16(); @@ -881,7 +887,7 @@ static void shb_CNG_decod_fx( IF( NE_16( st_fx->element_mode, IVAS_CPE_DFT ) ) { - IF ( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) + IF( LT_16( st_fx->shb_dtx_count_fx, 1000 ) ) { st_fx->shb_dtx_count_fx = add( st_fx->shb_dtx_count_fx, 1 ); } @@ -889,7 +895,7 @@ static void shb_CNG_decod_fx( 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, add(LPC_SHB_ORDER, 1), sub( norm_s( shb_lpcCNG_fx[0] ), 2 ) ); /* Q12 */ + Copy_Scale_sig( shb_lpcCNG_fx, shb_lpcCNG_fx, add( 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); @@ -905,12 +911,12 @@ static void shb_CNG_decod_fx( exp = sub( 30, add( exp, shl( Qsyn, 1 ) ) ); wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); wb_ener16_fx = round_fx( L_shl( wb_ener_fx, 10 ) ); /*wb_ener_fx in Q8 */ - IF ( EQ_16(st_fx->first_CNG, 0 )) + IF( EQ_16( st_fx->first_CNG, 0 ) ) { st_fx->wb_cng_ener_fx = wb_ener16_fx; move16(); /*Q8 */ } - IF ( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) + IF( GT_16( abs_s( sub( wb_ener16_fx, st_fx->wb_cng_ener_fx ) ), 3072 ) ) { allow_cn_step_fx = 1; move16(); @@ -929,12 +935,12 @@ static void shb_CNG_decod_fx( } test(); test(); - IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16(st_fx->bfi, 0 )) + IF( EQ_32( st_fx->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st_fx->bfi, 0 ) ) { st_fx->last_wb_cng_ener_fx = st_fx->wb_cng_ener_fx; move16(); - IF ( EQ_16(st_fx->first_CNG, 0 )) + IF( EQ_16( st_fx->first_CNG, 0 ) ) { st_fx->shb_cng_ener_fx = st_fx->last_shb_cng_ener_fx; move16(); @@ -942,7 +948,7 @@ static void shb_CNG_decod_fx( } gain_fx = sub( st_fx->wb_cng_ener_fx, st_fx->last_wb_cng_ener_fx ); /*8 */ - IF ( GT_16( gain_fx, 15 ) ) + IF( GT_16( gain_fx, 15 ) ) { gain_fx = 15; move16(); @@ -969,21 +975,22 @@ static void shb_CNG_decod_fx( /* synthesis signal gain shaping */ - L_tmp = 0; move32(); + L_tmp = 0; + move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/ } q = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, q ); - q = sub(q, 32); + q = sub( q, 32 ); ener_excSHB_fx = round_fx( L_tmp ); /*Qq */ IF( EQ_16( st_fx->last_vad_fx, 1 ) ) { st_fx->trans_cnt_fx = 0; move16(); test(); - IF ( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) + IF( GT_16( st_fx->hTdCngDec->burst_cnt, 3 ) && NE_16( st_fx->last_core, HQ_CORE ) ) { st_fx->trans_cnt_fx = 5; move16(); @@ -992,7 +999,7 @@ static void shb_CNG_decod_fx( ener_fx = st_fx->shb_cng_ener_fx; move16(); /*Q8 */ - IF( GT_16(st_fx->trans_cnt_fx, 0 )) + IF( GT_16( st_fx->trans_cnt_fx, 0 ) ) { i = extract_l( L_mult0( st_fx->trans_cnt_fx, 17 ) ); /*Q0 */ #ifdef BASOP_NOGLOB @@ -1007,7 +1014,7 @@ static void shb_CNG_decod_fx( L_tmp = L_mult( 27213, tmp ); /*Q22, 27213=3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ L_tmp = L_add( L_tmp, 10 << 16 ); - IF ( LT_32(L_tmp, 0 )) + IF( LT_32( L_tmp, 0 ) ) { L_tmp = 0; move32(); @@ -1019,7 +1026,7 @@ static void shb_CNG_decod_fx( L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ #endif L_tmp = L_shr( L_tmp, 10 ); - IF ( EQ_32(L_tmp, 0 )) + IF( EQ_32( L_tmp, 0 ) ) { L_tmp = 1; /*Q5 */ } @@ -1058,7 +1065,7 @@ static void shb_CNG_decod_fx( move32(); } - FOR( i = 0; i < shl(ALLPASSSECTIONS_STEEP, 1); i++ ) + FOR( i = 0; i < shl( ALLPASSSECTIONS_STEEP, 1 ); i++ ) { 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 ); } @@ -1202,12 +1209,12 @@ static void shb_CNG_decod_ivas_fx( } test(); test(); - IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16(st->bfi, 0 )) + IF( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( sid_bw, 1 ) && EQ_16( st->bfi, 0 ) ) { st->hTdCngDec->last_wb_cng_ener_fx_32 = st->hTdCngDec->wb_cng_ener_fx_32; move32(); - IF( EQ_16(st->first_CNG, 0 )) + IF( EQ_16( st->first_CNG, 0 ) ) { st->hTdCngDec->shb_cng_ener_fx_32 = st->hTdCngDec->last_shb_cng_ener_fx_32; move32(); @@ -1242,7 +1249,8 @@ static void shb_CNG_decod_ivas_fx( /* synthesis signal gain shaping */ - L_tmp = 0; move32(); + L_tmp = 0; + move32(); FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp = L_add( L_tmp, Mpy_32_16_1( L_mult0( excSHB_fx[i], excSHB_fx[i] ), 102 ) ); /*Q-16*/ @@ -1277,12 +1285,12 @@ static void shb_CNG_decod_ivas_fx( } tmp = L_shr( Mpy_32_16_1( ener_fx, 3277 ), 3 ); /*Q8 */ - IF( GT_32(tmp, 32767 )) + IF( GT_32( tmp, 32767 ) ) abort(); Word16 tmp_16 = (Word16) tmp; L_tmp = L_mult( 27213, tmp_16 ); /*Q22, 27213=3.321928 in Q13 */ L_tmp = L_shr( L_tmp, 6 ); /*Q16 */ - L_tmp = L_add( L_tmp, L_shl(10, 16) ); + L_tmp = L_add( L_tmp, L_shl( 10, 16 ) ); IF( LT_32( L_tmp, 0 ) ) { L_tmp = 0; @@ -1291,9 +1299,10 @@ static void shb_CNG_decod_ivas_fx( fra = L_Extract_lc( L_tmp, &exp ); L_tmp = L_shl( Pow2( exp, fra ), 5 ); /*Q5 */ L_tmp = L_shr( L_tmp, 10 ); - IF( EQ_32(L_tmp, 0 )) + IF( EQ_32( L_tmp, 0 ) ) { - L_tmp = 1; move32();/*Q5 */ + L_tmp = 1; + move32(); /*Q5 */ } exp = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp ); /*Q31*/ @@ -1341,7 +1350,7 @@ static void shb_CNG_decod_ivas_fx( interpolate_3_over_2_allpass_fx( shb_synth_fx, L_FRAME32k, shb_synth_fx, st->interpol_3_2_cng_dec_fx, allpass_poles_3_ov_2 ); } - Scale_sig(shb_synth_fx, L_FRAME48k, -3); + Scale_sig( shb_synth_fx, L_FRAME48k, -3 ); ResetSHBbuffer_Dec_fx( st ); return; } @@ -1520,7 +1529,7 @@ void td_cng_dec_init_ivas_fx( { IF( NE_16( st->element_mode, EVS_MONO ) ) { - hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( add(i, 1), 1 ), LPC_SHB_ORDER + 1 ); + hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( add( i, 1 ), 1 ), LPC_SHB_ORDER + 1 ); } ELSE { diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index 48cb0af51..d8c00803e 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -772,13 +772,17 @@ void reset_tcx_overl_buf_fx( ) { set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_old_syn_Overl = 0; move16(); + hTcxDec->Q_old_syn_Overl = 0; + move16(); set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl_TDAC = 0; move16(); + hTcxDec->Q_syn_Overl_TDAC = 0; + move16(); set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl = 0; move16(); + hTcxDec->Q_syn_Overl = 0; + move16(); set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ - hTcxDec->Q_syn_Overl_TDACFB = 0; move16(); + hTcxDec->Q_syn_Overl_TDACFB = 0; + move16(); return; } #endif diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index 96f758a06..c9f29bd2a 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -71,7 +71,7 @@ void open_decoder_LPD_fx( #ifndef NEW_IVAS_OPEN_DEC hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); #endif - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->last_L_frame = st->L_frame_past = st->L_frame; move16(); @@ -85,7 +85,7 @@ void open_decoder_LPD_fx( IF( st->hTcxDec != NULL ) { hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->L_frameTCX_past = st->hTcxDec->L_frameTCX; } @@ -112,9 +112,9 @@ void open_decoder_LPD_fx( test(); test(); - IF ( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || - ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || - ( NE_16(st->tcxonly, 0) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) + IF( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || + ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || + ( NE_16( st->tcxonly, 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { st->nb_subfr = NB_SUBFR16k; move16(); @@ -130,7 +130,7 @@ void open_decoder_LPD_fx( st->TcxBandwidth = getTcxBandwidth( bwidth ); st->narrowBand = 0; move16(); - IF ( EQ_16( bwidth, NB ) ) + IF( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; move16(); @@ -162,7 +162,7 @@ void open_decoder_LPD_fx( hTcxDec->pit_min_TCX = extract_l( L_shr( L_mult( st->pit_min, i ), 7 ) ); } } - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->pit_res_max_past = st->pit_res_max; } @@ -170,12 +170,12 @@ void open_decoder_LPD_fx( /*Preemphasis param*/ st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); - IF( LT_16( st->fscale, 640)) /*( 16000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ + IF( LT_16( st->fscale, 640 ) ) /*( 16000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ { st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); } - ELSE IF ( LT_16( st->fscale, 960)) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) */ + ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 ) */ { st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); @@ -185,7 +185,8 @@ void open_decoder_LPD_fx( move16(); st->inv_gamma = GAMMA1_INV; move16(); - test(); test(); + test(); + test(); 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 ) ) ) { @@ -199,14 +200,14 @@ void open_decoder_LPD_fx( st->lpcQuantization = 0; move16(); test(); - IF ( EQ_16(st->tcxonly, 0) && LE_32( st->sr_core, INT_FS_16k ) ) + IF( EQ_16( st->tcxonly, 0 ) && LE_32( st->sr_core, INT_FS_16k ) ) { st->lpcQuantization = 1; } st->numlpc = 2; move16(); - IF ( EQ_16(st->tcxonly, 0 )) + IF( EQ_16( st->tcxonly, 0 ) ) { st->numlpc = 1; move16(); @@ -214,11 +215,11 @@ void open_decoder_LPD_fx( /* Initialize TBE */ st->prev_coder_type = GENERIC; - IF ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub(LPC_SHB_ORDER, 2) ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub( LPC_SHB_ORDER, 2 ) ); hBWE_TD->prev_tilt_para_fx = 0; - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add(M, 1) ); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add( M, 1 ) ); } /*TCX config*/ @@ -228,7 +229,7 @@ void open_decoder_LPD_fx( st->hTcxCfg->tcx_mdct_window_length_old = st->hTcxCfg->tcx_mdct_window_length; move16(); init_TCX_config( st->hTcxCfg, st->L_frame, st->fscale, hTcxDec->L_frameTCX, fscaleFB ); // TEMPORARY should be rename to init_TCX_config - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->hTcxCfg->tcx_last_overlap_mode = st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); @@ -255,16 +256,16 @@ void open_decoder_LPD_fx( InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFDec->infoIGFStopFreq, st->total_brate, st->element_mode, 0 /*is_mct*/ ); } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - IF ( EQ_16(st->tcxonly, 0 )) + IF( EQ_16( st->tcxonly, 0 ) ) { assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } - IF ( 1 ) // st->element_mode == EVS_MONO) + IF( 1 ) // st->element_mode == EVS_MONO) { - IF ( st->hTECDec == NULL ) + IF( st->hTECDec == NULL ) { - IF ( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) + IF( ( st->hTECDec = (TEC_DEC_HANDLE) malloc( sizeof( TEC_DEC_DATA ) ) ) == NULL ) { // return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TEC\n")); assert( 0 ); @@ -279,8 +280,7 @@ void open_decoder_LPD_fx( #else - IF ( st->hIGFDec != NULL ) - { + IF( st->hIGFDec != NULL ){ PMT( "To be done" ) // IF (!is_init || st->element_mode != IVAS_CPE_MDCT) //{ @@ -293,7 +293,7 @@ void open_decoder_LPD_fx( // } } /*Constraint for adaptive BPF, otherwise parameter estimation and post-processing not time aligned*/ - IF ( st->tcxonly == 0 ) + IF( st->tcxonly == 0 ) { assert( 0 == ( st->hTcxCfg->lfacNext > 0 ? st->hTcxCfg->lfacNext : 0 ) ); } @@ -313,7 +313,7 @@ void open_decoder_LPD_fx( st->flag_cna = 0; move16(); } - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->flag_cna = 0; st->last_flag_cna = 0; @@ -321,7 +321,7 @@ void open_decoder_LPD_fx( } /* Static vectors to zero */ - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->last_is_cng = 0; @@ -331,26 +331,30 @@ void open_decoder_LPD_fx( move16(); IF( hTcxDec != NULL ) { - set16_fx( hTcxDec->old_syn_Overl, 0, shr(L_FRAME32k, 1) ); + set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); - set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr(L_FRAME32k, 1) ); - set16_fx( hTcxDec->syn_OverlFB, 0, shr(L_FRAME_MAX, 1) ); - set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr(L_FRAME_MAX, 1) ); + set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) ); + set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) ); + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); - set16_fx( hTcxDec->syn_Overl, 0, shr(L_FRAME32k, 1) ); + set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); - set16_fx( hTcxDec->synth_history_fx, 0, add(L_PROT48k, L_FRAME_MAX) ); - hTcxDec->q_synth_history_fx = 0; move16(); + set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); + hTcxDec->q_synth_history_fx = 0; + move16(); } - set16_fx( st->syn, 0, add(M, 1) ); + set16_fx( st->syn, 0, add( M, 1 ) ); set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); - mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ move16(); - mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ move16(); + mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ + move16(); + mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + move16(); - st->con_tcx = 0; move16(); + st->con_tcx = 0; + move16(); } ELSE { @@ -410,7 +414,7 @@ void open_decoder_LPD_fx( /*PLC*/ #ifndef NEW_IVAS_OPEN_DEC - IF( EQ_16(st->prev_bfi, 0 )) + IF( EQ_16( st->prev_bfi, 0 ) ) { PWord16 const *w; Word16 W1, W2, nz, delay_comp; @@ -418,36 +422,42 @@ void open_decoder_LPD_fx( W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 ); - w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ move16(); + w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ + move16(); - nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); move16(); - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ move16(); + nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); + move16(); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + move16(); Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ - hHQ_core->Q_old_wtda = -1; move16(); + hHQ_core->Q_old_wtda = -1; + move16(); 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++ ) { - hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add(i, nz)] ) ); + hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, nz )] ) ); } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[sub(W2, add(1, sub( i, W2 )))].v.im, w[sub(W2, add(1, sub( i, W2 )))].v.im ), hHQ_core->old_out_fx[add(i, nz)] ) ); + hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_fx[add( i, nz )] ) ); } - set16_fx( &hHQ_core->old_out_fx[add(W1, nz)], 0, nz ); + set16_fx( &hHQ_core->old_out_fx[add( W1, nz )], 0, nz ); lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX ); 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 );move16(); + nz = NS2SA_fx2( st->sr_core, N_ZERO_MDCT_NS ); + move16(); Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); - hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda;move16(); + hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda; + move16(); } #else PMT( "acelp_plc_mdct_transition is missing" ) @@ -489,17 +499,17 @@ void open_decoder_LPD_fx( set16_fx( st->mem_syn2_fx, 0, M ); /*OLA -> zero */ - IF ( st->hTcxDec != NULL ) + IF( st->hTcxDec != NULL ) { - set16_fx( hTcxDec->old_syn_Overl, 0, shr(L_FRAME32k, 1 )); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr(L_FRAME32k, 1) ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr(L_FRAME_MAX, 1) ); /*HQ-CORE(bfi)->TCX don't need it*/ - set16_fx( hTcxDec->syn_Overl, 0, shr(L_FRAME32k, 1) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ + set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) ); /*HQ-CORE(bfi)->TCX don't need it*/ #if 0 PMT("to be moved to reset_tcx_overl_buf") #endif } - IF ( st->hTcxCfg != NULL ) + IF( st->hTcxCfg != NULL ) { Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); @@ -509,16 +519,17 @@ void open_decoder_LPD_fx( st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; } /*OLA for MDCT-LB always reset in codec switching cases*/ - IF ( st->hHQ_core != NULL ) + IF( st->hHQ_core != NULL ) { set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); } move16(); st->last_core_bfi = TCX_20_CORE; - IF ( st->hPFstat != NULL ) + IF( st->hPFstat != NULL ) { - st->hPFstat->on = 0; move16(); + st->hPFstat->on = 0; + move16(); } move16(); /* reset CLDFB memories */ @@ -541,7 +552,7 @@ void open_decoder_LPD_fx( /* convert quantized LSP vector */ st->rate_switching_reset = lsp_convert_poly_fx( st->lsp_old_fx, st->L_frame, 0 ); - IF( EQ_16(st->tcxonly, 0 )) + IF( EQ_16( st->tcxonly, 0 ) ) { lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core ); } @@ -565,20 +576,22 @@ void open_decoder_LPD_fx( ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */ { /*Partial reset of ACELP memories*/ - st->rate_switching_reset = 1; move16(); + st->rate_switching_reset = 1; + move16(); /*reset partly some memories*/ - st->tilt_code_fx = TILT_CODE; move16(); + st->tilt_code_fx = TILT_CODE; + move16(); IF( !st->last_con_tcx ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, add(M, 1) ); + set16_fx( st->old_Aq_12_8_fx, 0, add( M, 1 ) ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_old), st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + sub(L_SYN_MEM, M), st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + sub( L_SYN_MEM, M ), st->mem_syn2_fx, M ); /*Untouched memories : st->syn */ } @@ -590,7 +603,7 @@ void open_decoder_LPD_fx( test(); test(); - IF ( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) + IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && st->ini_frame != 0 ) { st->rate_switching_reset = 1; move16(); @@ -603,37 +616,38 @@ void open_decoder_LPD_fx( /* bass pf reset */ st->bpf_gain_param = 0; move16(); - IF ( st->hBPF != NULL ) + IF( st->hBPF != NULL ) { set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); } /* Formant postfilter */ - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { /*do nothing*/ } ELSE IF( EQ_16( st->last_codec_mode, MODE2 ) ) { - IF( EQ_16(st->tcxonly, 0 )) + IF( EQ_16( st->tcxonly, 0 ) ) { - IF( NE_16(st->hPFstat->on, 0 )) + IF( NE_16( st->hPFstat->on, 0 ) ) { - lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { 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; move16(); + st->hPFstat->reset = 1; + move16(); st->hPFstat->gain_prec = 16384; move16(); } } - ELSE IF( NE_16(st->hPFstat->on, 0 )) + ELSE IF( NE_16( st->hPFstat->on, 0 ) ) { - lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE @@ -642,43 +656,45 @@ void open_decoder_LPD_fx( /*reset post-filter except for Narrowband*/ IF( NE_32( st->output_Fs, 8000 ) ) { - IF ( st->hPFstat != NULL ) + IF( st->hPFstat != NULL ) { - st->hPFstat->reset = 1; move16(); - IF ( NE_16(st->hPFstat->on, 0 )) + st->hPFstat->reset = 1; + move16(); + IF( NE_16( st->hPFstat->on, 0 ) ) { - st->hPFstat->reset = 0; move16(); + st->hPFstat->reset = 0; + move16(); 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 + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } } ELSE { - IF ( st->hPFstat != NULL ) + 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*/ - IF ( st->hTcxDec != NULL ) + IF( st->hTcxDec != NULL ) { - hTcxDec->old_synth[sub(hTcxDec->old_synth_len, 1)] = st->syn[M]; + hTcxDec->old_synth[sub( hTcxDec->old_synth_len, 1 )] = st->syn[M]; } move16(); - IF ( st->hBPF != NULL ) + IF( st->hBPF != NULL ) { - hBPF->pst_old_syn_fx[sub(NBPSF_PIT_MAX, 1)] = st->syn[M]; + hBPF->pst_old_syn_fx[sub( NBPSF_PIT_MAX, 1 )] = st->syn[M]; } move16(); } } /* lsf and lsp initialization */ - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); @@ -708,7 +724,7 @@ void open_decoder_LPD_fx( st->last_gain_syn_deemph_e = 1; move16(); test(); - IF( EQ_16( st->last_codec_mode, MODE1 ) || EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->last_codec_mode, MODE1 ) || EQ_16( st->ini_frame, 0 ) ) { /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ @@ -716,7 +732,7 @@ void open_decoder_LPD_fx( move16(); st->last_concealed_gain_syn_deemph_e = 1; move16(); - IF ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->conceal_eof_gain = 16384; /*Q14*/ move16(); @@ -724,10 +740,10 @@ void open_decoder_LPD_fx( } /* Post processing */ - set16_fx( st->mem_Aq, 0, i_mult(NB_SUBFR16k, add(M, 1))); + set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, add( M, 1 ) ) ); st->lp_ener_FER_fx = 15360; move16(); /*60 in Q8*/ - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { st->prev_bfi = 0; move16(); @@ -776,11 +792,11 @@ void open_decoder_LPD_fx( st->prev_widow_left_rect = 0; move16(); - IF ( st->hTcxDec != NULL ) + 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 ) ) + 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; @@ -794,15 +810,17 @@ void open_decoder_LPD_fx( #else hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); - hTcxDec->conNoiseLevelIndex = sub(PLC_MIN_STAT_BUFF_SIZE, 1); + hTcxDec->conNoiseLevelIndex = sub( PLC_MIN_STAT_BUFF_SIZE, 1 ); 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; move16(); - hTcxDec->conCngLevelBackgroundTrace_e = -6; move16(); + hTcxDec->conLastFrameLevel_e = 0; + move16(); + hTcxDec->conCngLevelBackgroundTrace_e = -6; + move16(); hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; #endif @@ -811,14 +829,15 @@ void open_decoder_LPD_fx( st->cummulative_damping = 32767 /*1.0f Q15*/; move16(); - FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); } - FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { - st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ move16(); + st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; /*Q14*/ + move16(); } @@ -842,14 +861,15 @@ void open_decoder_LPD_fx( move16(); /* TCX-LTP */ - IF ( hTcxLtpDec != NULL ) + IF( hTcxLtpDec != NULL ) { hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core ); } move16(); - test(); test(); - IF( hTcxLtpDec != NULL && ( EQ_16(st->ini_frame, 0) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) + test(); + test(); + IF( hTcxLtpDec != NULL && ( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) ) { #if 0 PMT("TO be verify, update seems to differ from float") @@ -858,12 +878,12 @@ void open_decoder_LPD_fx( move16(); hTcxLtpDec->tcxltp_pitch_fr = 0; move16(); - IF ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { hTcxDec->tcxltp_last_gain_unmodified = 0; } move16(); - IF( EQ_16(st->ini_frame, 0) ) + IF( EQ_16( st->ini_frame, 0 ) ) { set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); @@ -879,14 +899,15 @@ void open_decoder_LPD_fx( } /* in floating point implementation, different buffers are used: lp_error_ener <-> pst_lp_ener, mem_error <-> pst_mem_deemp_err */ - IF ( st->hBPF != NULL ) + 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; move16(); + st->lp_error_ener = 0; + move16(); } st->mem_error = L_deposit_l( 0 ); st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag ); @@ -898,7 +919,7 @@ void open_decoder_LPD_fx( 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 ) + IF( hTcxDec != NULL ) { hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); @@ -907,7 +928,7 @@ void open_decoder_LPD_fx( move16(); st->p_bpf_noise_buf = NULL; - IF ( EQ_16(st->tcxonly, 0 )) + IF( EQ_16( st->tcxonly, 0 ) ) { st->p_bpf_noise_buf = st->bpf_noise_buf; } @@ -916,8 +937,8 @@ void open_decoder_LPD_fx( move16(); test(); test(); - IF ( EQ_16( bwidth, SWB ) && - ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + IF( EQ_16( bwidth, SWB ) && + ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { st->tec_tfa = 1; move16(); @@ -950,7 +971,7 @@ void open_decoder_LPD_fx( test(); test(); test(); - IF( EQ_16(st->ini_frame, 0) || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) + IF( EQ_16( st->ini_frame, 0 ) || LT_32( st->last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { concealment_init_x( hTcxDec->L_frameTCX, &st->plcInfo ); } @@ -961,7 +982,7 @@ void open_decoder_LPD_fx( PMT("handle to tonalMDCTconceal is missing") #endif //#ifdef ADD_IVAS_HTONALMDCTCONC - IF ( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) + IF( /*st->ADD_IVAS_HTONALMDCTCONC != NULL &&*/ !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->tonalMDCTconceal.nSamples, st->hTcxDec->L_frameTCX ) ) ) { st->tonalMDCTconceal.nScaleFactors = 0; move16(); @@ -980,12 +1001,12 @@ void open_decoder_LPD_fx( st->second_last_tns_active = 0; st->second_last_core = -1; #ifdef NEW_IVAS_OPEN_DEC - IF ( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) + 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 ) + IF( hTcxDec != NULL ) { hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; move16(); @@ -997,14 +1018,14 @@ void open_decoder_LPD_fx( test(); test(); test(); - IF ( ( EQ_32(total_brate, ACELP_9k60) || EQ_32(total_brate, ACELP_16k40) || EQ_32(total_brate, ACELP_24k40) ) && EQ_16(st->element_mode, EVS_MONO )) + IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { test(); test(); test(); - IF ( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || - ( EQ_32( st->total_brate, 24400 ) ) ) && - EQ_16(st->element_mode, EVS_MONO) ) + IF( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) || + ( EQ_32( st->total_brate, 24400 ) ) ) && + EQ_16( st->element_mode, EVS_MONO ) ) { move16(); st->dec_glr = 1; @@ -1012,20 +1033,27 @@ void open_decoder_LPD_fx( } move16(); st->dec_glr_idx = 0; - IF ( hTcxDec != NULL ) + IF( hTcxDec != NULL ) { - hTcxDec->enableTcxLpc = 1; move16(); - st->VAD = 0; move16(); - hTcxDec->old_gaintcx_bfi = 0; move16(); - hTcxDec->old_gaintcx_bfi_e = 0; move16(); - hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); + hTcxDec->enableTcxLpc = 1; + move16(); + st->VAD = 0; + move16(); + hTcxDec->old_gaintcx_bfi = 0; + move16(); + hTcxDec->old_gaintcx_bfi_e = 0; + move16(); + hTcxDec->tcx_hm_LtpPitchLag = -1; + move16(); } #ifndef NEW_IVAS_OPEN_DEC - st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; move16(); + st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + move16(); #endif - IF ( hTcxLtpDec != NULL ) + IF( hTcxLtpDec != NULL ) { - hTcxLtpDec->tcxltp_gain = 0; move16(); + hTcxLtpDec->tcxltp_gain = 0; + move16(); } return; } @@ -1039,25 +1067,33 @@ void tcxltp_dec_init_fx( const Word16 pit_max, const Word32 sr_core ) { - hTcxLtpDec->tcxltp_gain = 0; move16(); + hTcxLtpDec->tcxltp_gain = 0; + move16(); hTcxLtpDec->tcxltp = getTcxLtp( sr_core ); - test(); test(); - IF( EQ_16(ini_frame, 0) || ( EQ_16( last_codec_mode, MODE1 ) && EQ_16( element_mode, EVS_MONO ) ) ) + test(); + test(); + IF( EQ_16( ini_frame, 0 ) || ( EQ_16( last_codec_mode, MODE1 ) && EQ_16( element_mode, EVS_MONO ) ) ) { - hTcxLtpDec->tcxltp_pitch_int = pit_max; move16(); - hTcxLtpDec->tcxltp_pitch_fr = 0; move16(); + hTcxLtpDec->tcxltp_pitch_int = pit_max; + move16(); + hTcxLtpDec->tcxltp_pitch_fr = 0; + move16(); - IF( EQ_16(ini_frame, 0 )) + IF( EQ_16( ini_frame, 0 ) ) { set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k ); set32_fx( hTcxLtpDec->tcxltp_mem_in_32, 0, TCXLTP_MAX_DELAY ); set32_fx( hTcxLtpDec->tcxltp_mem_out_32, 0, L_FRAME48k ); - hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; move16(); - hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; move16(); - hTcxLtpDec->tcxltp_gain_post_prev = 0; move16(); - hTcxLtpDec->tcxltp_filt_idx_prev = -1; move16(); + hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; + move16(); + hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; + move16(); + hTcxLtpDec->tcxltp_gain_post_prev = 0; + move16(); + hTcxLtpDec->tcxltp_filt_idx_prev = -1; + move16(); } } @@ -1076,37 +1112,41 @@ void acelp_plc_mdct_transition_fx( /*PLC*/ test(); - IF( NE_16(st->prev_bfi, 0) && st->hTcxCfg != NULL ) + IF( NE_16( st->prev_bfi, 0 ) && st->hTcxCfg != NULL ) { W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); 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, N_ZERO_MDCT_NS ); move16(); - delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); move16();/*CLDFB delay*/ + nz = NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ); + move16(); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); + move16(); /*CLDFB delay*/ Copy( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_OverlFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); lerp( st->hHQ_core->fer_samples_fx + delay_comp, st->hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( st->hTcxDec->L_frameTCX, 1 ) ); /*ACELP(bfi)->TCX(rect)*/ /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/ - st->hHQ_core->Q_old_wtda = -1; move16(); + st->hHQ_core->Q_old_wtda = -1; + move16(); set16_fx( st->hHQ_core->old_out_fx, 0, nz ); // Q_old_out is 0 Copy_Scale_sig( st->hHQ_core->fer_samples_fx + delay_comp, st->hHQ_core->old_out_fx + nz, W1, st->hHQ_core->Q_old_wtda ); /*Q-1*/ FOR( i = 0; i < W2; i++ ) { - st->hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[add(i, nz)] ) ); + st->hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), st->hHQ_core->old_out_fx[add( i, nz )] ) ); } FOR( ; i < W1; i++ ) { - st->hHQ_core->old_out_fx[add(i, nz)] = round_fx( Mpy_32_16_1( L_mult( w[sub(W2, add(1, sub( i, W2 )))].v.im, w[sub(W2, add(1, sub( i, W2 )))].v.im ), st->hHQ_core->old_out_fx[add(i, nz)] ) ); + st->hHQ_core->old_out_fx[add( i, nz )] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), st->hHQ_core->old_out_fx[add( i, nz )] ) ); } - set16_fx( &st->hHQ_core->old_out_fx[add(W1, nz)], 0, nz ); + set16_fx( &st->hHQ_core->old_out_fx[add( W1, nz )], 0, nz ); lerp( st->hHQ_core->old_out_fx, st->hHQ_core->old_out_LB_fx, st->L_frame, st->hTcxDec->L_frameTCX ); Copy( st->hHQ_core->old_out_fx + nz, st->hTcxDec->syn_Overl_TDACFB, shr( st->hTcxDec->L_frameTCX, 1 ) ); - nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS ); move16(); + nz = NS2SA( st->sr_core, N_ZERO_MDCT_NS ); + move16(); Copy( st->hHQ_core->old_out_LB_fx + nz, st->hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; } @@ -1151,7 +1191,8 @@ void open_decoder_LPD_ivas_fx( IF( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/ { - st->fscale_old = st->fscale; move16(); + st->fscale_old = st->fscale; + move16(); } st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); @@ -1168,10 +1209,12 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - st->output_frame_fx = st->hTcxDec->L_frameTCX; move16(); + st->output_frame_fx = st->hTcxDec->L_frameTCX; + move16(); IF( EQ_16( st->ini_frame, 0 ) ) { - st->L_frameTCX_past = st->hTcxDec->L_frameTCX; move16(); + st->L_frameTCX_past = st->hTcxDec->L_frameTCX; + move16(); } } @@ -1179,26 +1222,38 @@ void open_decoder_LPD_ivas_fx( move16(); /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ - test(); test(); test(); test(); test(); test(); test(); test(); test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( st->total_brate, 32000 ) ) || ( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->L_frame, L_FRAME16k ) && LE_32( total_brate, MAX_ACELP_BRATE ) ) || ( NE_16( st->tcxonly, 0 ) && ( EQ_32( st->sr_core, 32000 ) || EQ_32( st->sr_core, 16000 ) ) ) ) { - st->nb_subfr = NB_SUBFR16k; move16(); + st->nb_subfr = NB_SUBFR16k; + move16(); } ELSE { - st->nb_subfr = NB_SUBFR; move16(); + st->nb_subfr = NB_SUBFR; + move16(); } st->bits_frame = extract_l( L_shr( Mpy_32_16_1( L_shl( st->total_brate, 1 ), 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ // assert(FSCALE_DENOM == 512); // assert(st->fscale == 2 * st->L_frame); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */ // assert(st->bits_frame == (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f)); st->TcxBandwidth = getTcxBandwidth( bwidth ); - st->narrowBand = 0; move16(); + st->narrowBand = 0; + move16(); IF( EQ_16( bwidth, NB ) ) { - st->narrowBand = 1; move16(); + st->narrowBand = 1; + move16(); } IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -1224,23 +1279,25 @@ void open_decoder_LPD_ivas_fx( IF( EQ_16( st->ini_frame, 0 ) ) { - st->pit_res_max_past = st->pit_res_max; move16(); + st->pit_res_max_past = st->pit_res_max; + move16(); } /*Preemphasis param*/ - IF( LT_16( st->fscale, 640 )) /*16000 * FSCALE_DENOM ) / INT_FS_12k8*/ + IF( LT_16( st->fscale, 640 ) ) /*16000 * FSCALE_DENOM ) / INT_FS_12k8*/ { st->preemph_fac = PREEMPH_FAC; /*WB*/ move16(); } - ELSE IF( LT_16( st->fscale, 960)) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ + ELSE IF( LT_16( st->fscale, 960 ) ) /* ( 24000 * FSCALE_DENOM ) / INT_FS_12k8 )*/ { st->preemph_fac = PREEMPH_FAC_16k; /*WB*/ move16(); } ELSE { - st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ move16(); + st->preemph_fac = PREEMPH_FAC_SWB; /*SWB*/ + move16(); } // gamma_float to be removed later @@ -1271,29 +1328,35 @@ void open_decoder_LPD_ivas_fx( test(); IF( LE_32( st->sr_core, INT_FS_16k ) && EQ_16( st->tcxonly, 0 ) ) { - st->lpcQuantization = 1; move16(); + st->lpcQuantization = 1; + move16(); } ELSE { - st->lpcQuantization = 0; move16(); + st->lpcQuantization = 0; + move16(); } IF( EQ_16( st->tcxonly, 0 ) ) { - st->numlpc = 1; move16(); + st->numlpc = 1; + move16(); } ELSE { - st->numlpc = 2; move16(); + st->numlpc = 2; + move16(); } /* Initialize TBE */ - st->prev_coder_type = GENERIC; move16(); + st->prev_coder_type = GENERIC; + move16(); IF( st->hBWE_TD != NULL ) { - set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub(LPC_SHB_ORDER, 2 )); - hBWE_TD->prev_tilt_para_fx = 0; move16(); - set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add(M, 1) ); + set16_fx( hBWE_TD->prev_lsf_diff_fx, 16384, sub( LPC_SHB_ORDER, 2 ) ); + hBWE_TD->prev_tilt_para_fx = 0; + move16(); + set16_fx( hBWE_TD->cur_sub_Aq_fx, 0, add( M, 1 ) ); } IF( st->hIGFDec != NULL ) @@ -1305,8 +1368,11 @@ void open_decoder_LPD_ivas_fx( } ELSE { - st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; move16(); move16(); - st->hTcxCfg->last_aldo = 1; move16(); + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + move16(); + move16(); + st->hTcxCfg->last_aldo = 1; + move16(); } } IF( st->hTECDec != NULL ) @@ -1328,7 +1394,8 @@ void open_decoder_LPD_ivas_fx( } IF( EQ_16( st->ini_frame, 0 ) ) { - st->flag_cna = 0; move16(); + st->flag_cna = 0; + move16(); st->last_flag_cna = 0; move16(); } @@ -1345,18 +1412,22 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { reset_tcx_overl_buf_fx( st->hTcxDec ); - set16_fx( hTcxDec->syn_OverlFB, 0, shr(L_FRAME_MAX, 1)); + set16_fx( hTcxDec->syn_OverlFB, 0, shr( L_FRAME_MAX, 1 ) ); set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); - set16_fx( hTcxDec->synth_history_fx, 0, add(L_PROT48k, L_FRAME_MAX) ); - hTcxDec->q_synth_history_fx = 0; move16(); + set16_fx( hTcxDec->synth_history_fx, 0, add( L_PROT48k, L_FRAME_MAX ) ); + hTcxDec->q_synth_history_fx = 0; + move16(); } - set16_fx( st->syn, 0, add(M, 1) ); + set16_fx( st->syn, 0, add( M, 1 ) ); set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); - mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ move16(); - mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ move16(); + mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ + move16(); + mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + move16(); - st->con_tcx = 0; move16(); + st->con_tcx = 0; + move16(); } ELSE { @@ -1417,15 +1488,21 @@ void open_decoder_LPD_ivas_fx( IF( NE_16( st->prev_bfi, 0 ) && st->hTcxCfg != NULL ) { acelp_plc_mdct_transition_fx( st ); - *Q_syn_Overl_TDAC = sub(*Q_fer_samples, 1); - *Q_syn_Overl = *Q_fer_samples; move16(); - *Q_syn_Overl_TDACFB = sub(*Q_fer_samples, 1); - *Q_syn_OverlFB = *Q_fer_samples; move16(); - *Q_old_out = sub(*Q_fer_samples, 1); - *Q_old_outLB = sub(*Q_fer_samples, 1); + *Q_syn_Overl_TDAC = sub( *Q_fer_samples, 1 ); + *Q_syn_Overl = *Q_fer_samples; + move16(); + *Q_syn_Overl_TDACFB = sub( *Q_fer_samples, 1 ); + *Q_syn_OverlFB = *Q_fer_samples; + move16(); + *Q_old_out = sub( *Q_fer_samples, 1 ); + *Q_old_outLB = sub( *Q_fer_samples, 1 ); } } - test(); test(); test(); test(); test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->last_codec_mode, MODE2 ) && NE_16( st->L_frame, st->last_L_frame ) && ( ( EQ_16( st->m_frame_type, SID_FRAME ) && GT_16( st->last_core, ACELP_CORE ) ) || ( GT_16( st->last_core, ACELP_CORE ) && GT_16( st->core, ACELP_CORE ) ) || st->prev_bfi ) ) @@ -1434,17 +1511,23 @@ void open_decoder_LPD_ivas_fx( } /* Rate switching */ - test(); test(); test(); test(); test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->last_core, HQ_CORE ) ) { /* Switching from MDCT */ /*Reset of ACELP memories*/ - st->rate_switching_reset = 1; move16(); + st->rate_switching_reset = 1; + move16(); // To be removed later - st->tilt_code_fx = TILT_CODE; move16(); + st->tilt_code_fx = TILT_CODE; + move16(); set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); - set16_fx( st->syn, 0, add(1, M) ); + set16_fx( st->syn, 0, add( 1, M ) ); set16_fx( st->mem_syn2_fx, 0, M ); /*OLA -> zero */ @@ -1455,11 +1538,15 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxCfg != NULL ) { - hHQ_core->Q_old_wtda = -1; /*To be removed later when hHQ_core->Q_old_wtda vaue is updated*/ move16(); + hHQ_core->Q_old_wtda = -1; /*To be removed later when hHQ_core->Q_old_wtda vaue is updated*/ + move16(); Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); - *Q_syn_OverlFB = *Q_old_out; move16(); - st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ move16(); - st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; move16(); + *Q_syn_OverlFB = *Q_old_out; + move16(); + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ + move16(); + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + move16(); } /*OLA for Mode 2 TCX always reset in Mode switching cases*/ @@ -1468,11 +1555,13 @@ void open_decoder_LPD_ivas_fx( set16_fx( hHQ_core->old_out_LB_fx, 0, st->L_frame ); } - st->last_core_bfi = TCX_20_CORE; move16(); + st->last_core_bfi = TCX_20_CORE; + move16(); IF( st->hPFstat != NULL ) { - st->hPFstat->on = 0; move16(); + st->hPFstat->on = 0; + move16(); } /* reset CLDFB memories */ @@ -1501,7 +1590,8 @@ void open_decoder_LPD_ivas_fx( E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M ); Copy( st->lsp_old_fx, st->lspold_uw, M ); Copy( st->lsf_old_fx, st->lsfold_uw, M ); - *Q_old_Aq_12_8 = 14; move16(); + *Q_old_Aq_12_8 = 14; + move16(); IF( !st->last_con_tcx ) { ivas_synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC, st->Q_syn ); @@ -1512,20 +1602,22 @@ void open_decoder_LPD_ivas_fx( ELSE IF( NE_16( st->L_frame, st->last_L_frame ) ) /* Rate switching involving TCX only modes */ { /*Partial reset of ACELP memories*/ - st->rate_switching_reset = 1; move16(); + st->rate_switching_reset = 1; + move16(); /*reset partly some memories*/ - st->tilt_code_fx = TILT_CODE; move16(); + st->tilt_code_fx = TILT_CODE; + move16(); IF( !st->last_con_tcx ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); } - set16_fx( st->old_Aq_12_8_fx, 0, add(M, 1) ); + set16_fx( st->old_Aq_12_8_fx, 0, add( M, 1 ) ); /*Resamp others memories*/ /*Size of LPC syn memory*/ - lerp( st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_old), st->mem_syn_r + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - Copy( st->mem_syn_r + sub(L_SYN_MEM, M), st->mem_syn2_fx, M ); + lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( st->mem_syn_r + sub( L_SYN_MEM, M ), st->mem_syn2_fx, M ); } /* update of lsf_old only needed in BASOP */ /* ELSE IF( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ @@ -1533,7 +1625,8 @@ void open_decoder_LPD_ivas_fx( /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ /* } */ } - test(); test(); + test(); + test(); IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && NE_16( st->ini_frame, 0 ) ) { st->rate_switching_reset = 1; @@ -1547,7 +1640,8 @@ void open_decoder_LPD_ivas_fx( } /* bass pf reset */ - st->bpf_gain_param = 0; move16(); + st->bpf_gain_param = 0; + move16(); IF( st->hBPF != NULL ) { set16_fx( hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); @@ -1564,8 +1658,8 @@ void open_decoder_LPD_ivas_fx( { IF( st->hPFstat->on ) { - lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } ELSE { @@ -1578,8 +1672,8 @@ void open_decoder_LPD_ivas_fx( } ELSE IF( st->hPFstat->on ) { - lerp( st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } ELSE @@ -1587,20 +1681,22 @@ void open_decoder_LPD_ivas_fx( /*codec mode switching*/ /*reset post-filter except for Narrowband*/ - IF( NE_32( st->output_Fs, i_mult(L_FRAME8k, FRAMES_PER_SEC) ) ) + IF( NE_32( st->output_Fs, i_mult( L_FRAME8k, FRAMES_PER_SEC ) ) ) { IF( st->hPFstat != NULL ) { - st->hPFstat->reset = 1; move16(); - IF( NE_16(st->hPFstat->on, 0 )) + st->hPFstat->reset = 1; + move16(); + IF( NE_16( st->hPFstat->on, 0 ) ) { - st->hPFstat->reset = 0; move16(); + st->hPFstat->reset = 0; + move16(); //-------------Present in EVS // 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 + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_stp + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); - lerp( st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_old), st->hPFstat->mem_pf_in + sub(L_SYN_MEM, mem_syn_r_size_new), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); + lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); } } } @@ -1617,11 +1713,11 @@ void open_decoder_LPD_ivas_fx( /*feed last value old_synth as it is used for pre-emphasis mem*/ IF( st->hTcxDec != NULL ) { - st->hTcxDec->old_synth[sub(st->hTcxDec->old_synth_len, 1)] = st->syn[M]; + st->hTcxDec->old_synth[sub( st->hTcxDec->old_synth_len, 1 )] = st->syn[M]; } IF( st->hBPF != NULL ) { - st->hBPF->pst_old_syn_fx[sub(NBPSF_PIT_MAX, 1)] = st->syn[M]; + st->hBPF->pst_old_syn_fx[sub( NBPSF_PIT_MAX, 1 )] = st->syn[M]; } } } @@ -1643,7 +1739,8 @@ void open_decoder_LPD_ivas_fx( E_LPC_lsf_lsp_conversion( st->lsf_cng, st->lspold_cng, M ); E_LPC_f_lsp_a_conversion( st->lspold_cng, st->Aq_cng, M ); - st->plcBackgroundNoiseUpdated = 0; move16(); + st->plcBackgroundNoiseUpdated = 0; + move16(); Copy( st->lsf_old_fx, st->lsf_q_cng, M ); Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); Copy( st->lsp_old_fx, st->lsp_q_cng, M ); @@ -1656,31 +1753,41 @@ void open_decoder_LPD_ivas_fx( /* this assumes that MODE1 fades out in the frequency domain - otherwise some data from MODE1 would be needed here */ st->last_concealed_gain_syn_deemph = 16384; - st->last_concealed_gain_syn_deemph_e = 1; move16(); + st->last_concealed_gain_syn_deemph_e = 1; + move16(); IF( hTcxDec != NULL ) { hTcxDec->conceal_eof_gain = 16384; /*Q14*/ } } /* Post processing */ - set16_fx( st->mem_Aq, 0, i_mult(NB_SUBFR16k, add(M, 1)) ); + set16_fx( st->mem_Aq, 0, i_mult( NB_SUBFR16k, add( M, 1 ) ) ); - st->lp_ener_FER_fx = 15360; /*60.0f Q8*/ move16(); + st->lp_ener_FER_fx = 15360; /*60.0f Q8*/ + move16(); IF( EQ_16( st->ini_frame, 0 ) ) { - st->prev_bfi = 0; move16(); - st->last_core_bfi = -1; move16(); + st->prev_bfi = 0; + move16(); + st->last_core_bfi = -1; + move16(); IF( st->hTcxDec != NULL ) { - hTcxDec->tcxConceal_recalc_exc = 0; move16(); + hTcxDec->tcxConceal_recalc_exc = 0; + move16(); } } - st->prev_old_bfi = 0; move16(); + st->prev_old_bfi = 0; + move16(); IF( st->hTcxDec != NULL ) { - st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; move16(); move16(); - st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; move16(); move16(); + st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; + move16(); + move16(); + st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; + move16(); + move16(); set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); } @@ -1688,11 +1795,13 @@ void open_decoder_LPD_ivas_fx( Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M ); Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M ); - st->clas_dec = UNVOICED_CLAS; move16(); + st->clas_dec = UNVOICED_CLAS; + move16(); IF( !st->last_con_tcx ) { - st->old_enr_LP = 0; move16();/* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ + st->old_enr_LP = 0; + move16(); /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ } IF( st->prev_bfi ) @@ -1700,13 +1809,15 @@ void open_decoder_LPD_ivas_fx( /* calculate energy at the end of the previous frame */ IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, HQ_CORE ) ) { - st->output_frame_fx = st->hTcxDec->L_frameTCX; move16(); + st->output_frame_fx = st->hTcxDec->L_frameTCX; + move16(); frame_ener_fx( st->output_frame_fx, UNVOICED_CLAS, st->previoussynth_fx, -1, &st->enr_old_fx, 1, 0, 0, 0 ); } } ELSE { - st->last_good = UNVOICED_CLAS; move16(); /* last good received frame for concealment */ + st->last_good = UNVOICED_CLAS; + move16(); /* last good received frame for concealment */ st->enr_old_fx = L_deposit_l( 0 ); /* energy at the end of the previous frame */ } st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -1716,11 +1827,14 @@ void open_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { - st->hTcxDec->prev_widow_left_rect = 0; move16(); - test(); test(); test(); + st->hTcxDec->prev_widow_left_rect = 0; + move16(); + test(); + test(); + test(); IF( is_init || MCT_flag || !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->element_mode, last_element_mode ) ) ) { - st->hTcxDec->NoiseLevelIndex_bfi = sub(PLC_MIN_STAT_BUFF_SIZE, 1); + st->hTcxDec->NoiseLevelIndex_bfi = sub( PLC_MIN_STAT_BUFF_SIZE, 1 ); st->hTcxDec->CurrLevelIndex_bfi = 0; st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV; set16_fx( st->hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); @@ -1730,7 +1844,7 @@ void open_decoder_LPD_ivas_fx( hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/ move16(); - hTcxDec->conNoiseLevelIndex = sub(PLC_MIN_STAT_BUFF_SIZE, 1); + hTcxDec->conNoiseLevelIndex = sub( PLC_MIN_STAT_BUFF_SIZE, 1 ); move16(); hTcxDec->conCurrLevelIndex = 0; move16(); @@ -1738,27 +1852,34 @@ void open_decoder_LPD_ivas_fx( 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; move16(); - hTcxDec->conCngLevelBackgroundTrace_e = -6; move16(); + hTcxDec->conLastFrameLevel_e = 0; + move16(); + hTcxDec->conCngLevelBackgroundTrace_e = -6; + move16(); - hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; move16(); + hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; + move16(); } } - st->cummulative_damping = 32767 /*1.0f Q15*/; move16(); + st->cummulative_damping = 32767 /*1.0f Q15*/; + move16(); - FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { st->old_pitch_buf_fx[i] = L_deposit_h( st->pit_min ); } - FOR( i = 0; i < add(shl(NB_SUBFR16k, 1), 2); i++ ) + FOR( i = 0; i < add( shl( NB_SUBFR16k, 1 ), 2 ); i++ ) { - st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; move16();/*Q14*/ + st->mem_pitch_gain[i] = 16384 /*1.f Q14*/; + move16(); /*Q14*/ } st->old_fpitch = L_deposit_h( st->pit_min ); - st->rate_switching_init = 1; move16(); + st->rate_switching_init = 1; + move16(); - st->reset_mem_AR = 0; move16(); + st->reset_mem_AR = 0; + move16(); /* For phase dispersion */ st->dm_fx.prev_gain_code = L_deposit_l( 0 ); @@ -1777,26 +1898,31 @@ void open_decoder_LPD_ivas_fx( IF( hTcxDec != NULL ) { st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX ); - test(); test(); + test(); + test(); IF( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && EQ_16( st->element_mode, EVS_MONO ) ) ) { - hTcxDec->tcxltp_last_gain_unmodified = 0; move16(); + hTcxDec->tcxltp_last_gain_unmodified = 0; + move16(); } /* TCX */ hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode ); - hTcxDec->envWeighted = 0; move16(); + hTcxDec->envWeighted = 0; + move16(); } 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 */ - hBPF->pst_mem_deemp_err_fx = 0; move16(); + hBPF->pst_mem_deemp_err_fx = 0; + move16(); } ELSE { - st->lp_error_ener = 0; move32(); + st->lp_error_ener = 0; + move32(); } st->mem_error = L_deposit_l( 0 ); IF( st->tcxonly ) @@ -1806,33 +1932,48 @@ void open_decoder_LPD_ivas_fx( } ELSE { - st->p_bpf_noise_buf = st->bpf_noise_buf; move32(); - st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; move32(); + st->p_bpf_noise_buf = st->bpf_noise_buf; + move32(); + st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; + move32(); } - test(); test(); test(); + test(); + test(); + test(); IF( EQ_16( bwidth, SWB ) && ( EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) { - st->tec_tfa = 1; move16(); + st->tec_tfa = 1; + move16(); } ELSE { - st->tec_tfa = 0; move16(); + st->tec_tfa = 0; + move16(); } - st->tec_flag = 0; move16(); - st->tfa_flag = 0; move16(); + st->tec_flag = 0; + move16(); + st->tfa_flag = 0; + move16(); /* needed in decoder to read the bitstream */ - st->enableGplc = 0; move16(); + st->enableGplc = 0; + move16(); - st->flagGuidedAcelp = 0; move16(); - st->tonal_mdct_plc_active = 0; move16(); - st->T0_4th = L_SUBFR; move16(); - st->guidedT0 = st->T0_4th; move16(); - test(); test(); + st->flagGuidedAcelp = 0; + move16(); + st->tonal_mdct_plc_active = 0; + move16(); + st->T0_4th = L_SUBFR; + move16(); + st->guidedT0 = st->T0_4th; + move16(); + test(); + test(); IF( st->hPlcInfo != NULL && GE_32( total_brate, HQ_48k ) && EQ_16( st->element_mode, EVS_MONO ) ) { - st->enablePlcWaveadjust = 1; move16(); + st->enablePlcWaveadjust = 1; + move16(); IF( st->hTcxDec != NULL && ( EQ_16( st->ini_frame, 0 ) || LT_32( last_total_brate, HQ_48k ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) ) { @@ -1841,24 +1982,35 @@ void open_decoder_LPD_ivas_fx( } ELSE { - st->enablePlcWaveadjust = 0; move16(); + st->enablePlcWaveadjust = 0; + move16(); } /* PLC: [TCX: Tonal Concealment] */ - test(); test(); test(); + test(); + test(); + test(); IF( st->hTonalMDCTConc != NULL && !( GT_16( st->element_mode, EVS_MONO ) && NE_16( st->ini_frame, 0 ) && EQ_16( st->hTonalMDCTConc->nSamples, st->hTcxDec->L_frameTCX ) ) ) { - st->hTonalMDCTConc->nScaleFactors = 0; move16(); - st->hTonalMDCTConc->nSamples = 0; move16(); - st->hTonalMDCTConc->lastPcmOut = 0x0; move16(); - st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; move16(); - st->hTonalMDCTConc->lastBlockData.nSamples = 0; move16(); + st->hTonalMDCTConc->nScaleFactors = 0; + move16(); + st->hTonalMDCTConc->nSamples = 0; + move16(); + st->hTonalMDCTConc->lastPcmOut = 0x0; + move16(); + st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; + move16(); + st->hTonalMDCTConc->lastBlockData.nSamples = 0; + move16(); TonalMDCTConceal_Init_ivas_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg ); } - st->last_tns_active = 0; move16(); - st->second_last_tns_active = 0; move16(); - st->second_last_core = -1; move16(); + st->last_tns_active = 0; + move16(); + st->second_last_tns_active = 0; + move16(); + st->second_last_core = -1; + move16(); IF( st->hTcxCfg != NULL && NE_16( st->element_mode, EVS_MONO ) ) { @@ -1871,31 +2023,43 @@ void open_decoder_LPD_ivas_fx( hTcxDec->tcxltp_third_last_pitch = st->old_fpitch; move16(); } - test(); test(); test(); test(); + test(); + test(); + test(); + test(); IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && EQ_32( st->element_mode, EVS_MONO ) ) { - st->dec_glr = 1; move16(); + st->dec_glr = 1; + move16(); } ELSE { - st->dec_glr = 0; move16(); + st->dec_glr = 0; + move16(); } - st->dec_glr_idx = 0; move16(); + st->dec_glr_idx = 0; + move16(); - st->VAD = 0; move16(); + st->VAD = 0; + move16(); IF( hTcxDec != NULL ) { - hTcxDec->enableTcxLpc = 1; move16(); - hTcxDec->old_gaintcx_bfi = 0; move16(); - hTcxDec->old_gaintcx_bfi_e = 0; move16(); + hTcxDec->enableTcxLpc = 1; + move16(); + hTcxDec->old_gaintcx_bfi = 0; + move16(); + hTcxDec->old_gaintcx_bfi_e = 0; + move16(); - hTcxDec->tcx_hm_LtpPitchLag = -1; move16(); + hTcxDec->tcx_hm_LtpPitchLag = -1; + move16(); } IF( st->hTcxCfg != NULL ) { - st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; move16(); + st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + move16(); } return; diff --git a/lib_dec/core_dec_reconf_fx.c b/lib_dec/core_dec_reconf_fx.c index b90e755c4..568280948 100644 --- a/lib_dec/core_dec_reconf_fx.c +++ b/lib_dec/core_dec_reconf_fx.c @@ -26,7 +26,8 @@ void reconfig_decoder_LPD_ivas_fx( Word32 lowrate_tcxlpc_max_br; move16(); - st->bits_frame = bits_frame; move16(); + st->bits_frame = bits_frame; + move16(); IF( EQ_16( bwidth, NB ) ) { @@ -42,15 +43,24 @@ void reconfig_decoder_LPD_ivas_fx( BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); /*Configuration of partial copy*/ - st->acelp_cfg_rf.mode_index = 1; move16(); - st->acelp_cfg_rf.midLpc = 0; move16(); - st->acelp_cfg_rf.midLpc_enable = 0; move16(); - st->acelp_cfg_rf.pre_emphasis = 0; move16(); - st->acelp_cfg_rf.formant_enh = 1; move16(); - st->acelp_cfg_rf.formant_tilt = 1; move16(); - st->acelp_cfg_rf.voice_tilt = 1; move16(); - st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; move16(); - st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; move16(); + st->acelp_cfg_rf.mode_index = 1; + move16(); + st->acelp_cfg_rf.midLpc = 0; + move16(); + st->acelp_cfg_rf.midLpc_enable = 0; + move16(); + st->acelp_cfg_rf.pre_emphasis = 0; + move16(); + st->acelp_cfg_rf.formant_enh = 1; + move16(); + st->acelp_cfg_rf.formant_tilt = 1; + move16(); + st->acelp_cfg_rf.voice_tilt = 1; + move16(); + st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; + move16(); + st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; + move16(); IF( NE_16( st->element_mode, IVAS_SCE ) ) { @@ -82,7 +92,7 @@ void reconfig_decoder_LPD_ivas_fx( { IF( st->rf_flag ) { - i = sub(i, 1); + i = sub( i, 1 ); } st->hTcxCfg->na_scale = scaleTcxTable[i].scale; move16(); @@ -141,11 +151,13 @@ void reconfig_decoder_LPD_ivas_fx( IF( GT_16( st->L_frame, st->last_L_frame ) ) { oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); - newLen = L_SYN_MEM_CLAS_ESTIM; move16(); + newLen = L_SYN_MEM_CLAS_ESTIM; + move16(); } ELSE { - oldLen = L_SYN_MEM_CLAS_ESTIM; move16(); + oldLen = L_SYN_MEM_CLAS_ESTIM; + move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } 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 ); @@ -170,7 +182,8 @@ void reconfig_decoder_LPD_ivas_fx( IF( EQ_16( st->ini_frame, 0 ) ) { - hTcxDec->envWeighted = 0; move16(); + hTcxDec->envWeighted = 0; + move16(); move16(); } @@ -205,7 +218,7 @@ void reconfig_decoder_LPD_fx( move16(); st->narrowBand = 1; } - ELSE IF ( GT_16( bwidth, NB ) ) + ELSE IF( GT_16( bwidth, NB ) ) { move16(); st->narrowBand = 0; @@ -214,15 +227,24 @@ void reconfig_decoder_LPD_fx( BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); /*Configuration of partial copy*/ - st->acelp_cfg_rf.mode_index = 1; move16(); - st->acelp_cfg_rf.midLpc = 0; move16(); - st->acelp_cfg_rf.midLpc_enable = 0; move16(); - st->acelp_cfg_rf.pre_emphasis = 0; move16(); - st->acelp_cfg_rf.formant_enh = 1; move16(); - st->acelp_cfg_rf.formant_tilt = 1; move16(); - st->acelp_cfg_rf.voice_tilt = 1; move16(); - st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; move16(); - st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; move16(); + st->acelp_cfg_rf.mode_index = 1; + move16(); + st->acelp_cfg_rf.midLpc = 0; + move16(); + st->acelp_cfg_rf.midLpc_enable = 0; + move16(); + st->acelp_cfg_rf.pre_emphasis = 0; + move16(); + st->acelp_cfg_rf.formant_enh = 1; + move16(); + st->acelp_cfg_rf.formant_tilt = 1; + move16(); + st->acelp_cfg_rf.voice_tilt = 1; + move16(); + st->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; + move16(); + st->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; + move16(); IF( NE_16( st->element_mode, IVAS_SCE ) ) @@ -238,7 +260,7 @@ void reconfig_decoder_LPD_fx( } move16(); - IF ( st->hTcxCfg != NULL ) + IF( st->hTcxCfg != NULL ) { Word16 i; @@ -247,7 +269,7 @@ void reconfig_decoder_LPD_fx( test(); IF( ( LT_16( bwidth, SWB ) ) && !( st->tcxonly ) ) { - Word16 scaleTableSize = idiv1616(sizeof( scaleTcxTable ), sizeof( scaleTcxTable[0] )); /* is a constant */ + Word16 scaleTableSize = idiv1616( sizeof( scaleTcxTable ), sizeof( scaleTcxTable[0] ) ); /* is a constant */ FOR( i = 0; i < scaleTableSize; i++ ) { @@ -257,9 +279,9 @@ void reconfig_decoder_LPD_fx( ( GE_32( total_brate, scaleTcxTable[i].bitrateFrom ) ) && ( LT_32( total_brate, scaleTcxTable[i].bitrateTo ) ) ) { - IF ( st->rf_flag ) + IF( st->rf_flag ) { - i = sub(i,1); + i = sub( i, 1 ); } st->hTcxCfg->na_scale = scaleTcxTable[i].scale; move16(); @@ -270,7 +292,7 @@ void reconfig_decoder_LPD_fx( } /*if its not the first frame resample overlap buffer to new sampling rate */ - IF( NE_16(st->ini_frame, 0 )) + IF( NE_16( st->ini_frame, 0 ) ) { test(); test(); @@ -318,12 +340,14 @@ void reconfig_decoder_LPD_fx( IF( GT_16( st->L_frame, st->last_L_frame ) ) { oldLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->last_L_frame, getInvFrameLen( st->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); - newLen = L_SYN_MEM_CLAS_ESTIM; move16(); + newLen = L_SYN_MEM_CLAS_ESTIM; + move16(); move16(); } ELSE { - oldLen = L_SYN_MEM_CLAS_ESTIM; move16(); + oldLen = L_SYN_MEM_CLAS_ESTIM; + move16(); newLen = extract_l( L_shr( Mpy_32_16_1( L_mult0( st->L_frame, getInvFrameLen( st->last_L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); } 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 ); @@ -344,10 +368,11 @@ void reconfig_decoder_LPD_fx( move16(); IF( GT_16( st->element_mode, IVAS_SCE ) ) { - lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE; move16(); + lowrate_tcxlpc_max_br = LOWRATE_TCXLPC_MAX_BR_CPE; + move16(); } 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 ( EQ_16(st->ini_frame, 0 )) + IF( EQ_16( st->ini_frame, 0 ) ) { hTcxDec->envWeighted = 0; move16(); diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 32fbc67ac..2316e9c09 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -47,7 +47,7 @@ void mode_switch_decoder_LPD_fx( bSwitchFromAmrwbIO = 0; move16(); - IF ( EQ_16( st->last_core, AMR_WB_CORE ) ) + IF( EQ_16( st->last_core, AMR_WB_CORE ) ) { bSwitchFromAmrwbIO = 1; move16(); @@ -67,7 +67,7 @@ void mode_switch_decoder_LPD_fx( test(); test(); test(); - IF ( ( ( GT_32( total_brate, 32000 ) ) && ( EQ_16( st->tcxonly, 0) ) ) || ( ( LE_32( total_brate, 32000 ) ) && ( NE_16(st->tcxonly, 0 )) ) ) + IF( ( ( GT_32( total_brate, 32000 ) ) && ( EQ_16( st->tcxonly, 0 ) ) ) || ( ( LE_32( total_brate, 32000 ) ) && ( NE_16( st->tcxonly, 0 ) ) ) ) { switchWB = 1; move16(); @@ -75,7 +75,7 @@ void mode_switch_decoder_LPD_fx( } test(); - IF ( GT_16( st->last_L_frame, L_FRAME16k ) && LE_32( total_brate, ACELP_32k ) ) + IF( GT_16( st->last_L_frame, L_FRAME16k ) && LE_32( total_brate, ACELP_32k ) ) { switchWB = 1; move16(); @@ -100,7 +100,7 @@ void mode_switch_decoder_LPD_fx( test(); test(); test(); - IF( NE_16( fscale, st->fscale ) || NE_16(switchWB, 0) || NE_16(bSwitchFromAmrwbIO, 0) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) + IF( NE_16( fscale, st->fscale ) || NE_16( switchWB, 0 ) || NE_16( bSwitchFromAmrwbIO, 0 ) || EQ_16( st->last_codec_mode, MODE1 ) || st->force_lpd_reset ) { #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT open_decoder_LPD_fx( st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0 ); @@ -136,7 +136,7 @@ void mode_switch_decoder_LPD_fx( st->narrowBand = 0; move16(); - IF ( EQ_16( bwidth, NB ) ) + IF( EQ_16( bwidth, NB ) ) { st->narrowBand = 1; move16(); @@ -149,7 +149,7 @@ void mode_switch_decoder_LPD_fx( st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( total_brate, st->igf, st->element_mode ); move16(); - IF( NE_16(st->hTcxCfg->fIsTNSAllowed, 0 )&& st->hIGFDec != NULL ) + IF( NE_16( 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 @@ -165,7 +165,7 @@ void mode_switch_decoder_LPD_fx( reconfig_decoder_LPD_fx( st, frame_size, bwidth, total_brate, st->last_L_frame ); test(); - IF( NE_16(hTcxDec->envWeighted, 0) && EQ_16(hTcxDec->enableTcxLpc, 0 )) + IF( NE_16( hTcxDec->envWeighted, 0 ) && EQ_16( hTcxDec->enableTcxLpc, 0 ) ) { Copy( st->lspold_uw, st->lsp_old_fx, M ); Copy( st->lsfold_uw, st->lsf_old_fx, M ); @@ -174,7 +174,7 @@ void mode_switch_decoder_LPD_fx( } /* update PLC LSF memories */ - IF( EQ_16(st->tcxonly, 0 )) + IF( EQ_16( st->tcxonly, 0 ) ) { lsp2lsf_fx( st->lsp_old_fx, st->lsfoldbfi1_fx, M, extract_l( st->sr_core ) ); } @@ -185,7 +185,7 @@ void mode_switch_decoder_LPD_fx( Copy( st->lsfoldbfi1_fx, st->lsfoldbfi0_fx, M ); Copy( st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx, M ); - IF( NE_16(st->igf, 0) && hBWE_TD != NULL ) + IF( NE_16( st->igf, 0 ) && hBWE_TD != NULL ) { test(); test(); @@ -217,7 +217,7 @@ void mode_switch_decoder_LPD_fx( test(); 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( EQ_16(st->tec_tfa, 0 )) + IF( EQ_16( st->tec_tfa, 0 ) ) { set16_fx( st->hTECDec->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); } @@ -309,7 +309,7 @@ void mode_switch_decoder_LPD_ivas_fx( test(); test(); test(); - IF( ( ( GT_32( total_brate, ACELP_32k ) ) && ( EQ_16( st->tcxonly, 0) ) ) || ( ( LE_32( total_brate, ACELP_32k ) ) && EQ_16( st->tcxonly, 1 ) ) ) + IF( ( ( GT_32( total_brate, ACELP_32k ) ) && ( EQ_16( st->tcxonly, 0 ) ) ) || ( ( LE_32( total_brate, ACELP_32k ) ) && EQ_16( st->tcxonly, 1 ) ) ) { switchWB = 1; move16(); @@ -327,13 +327,14 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hIGFDec != NULL ) { - st->hIGFDec->infoIGFStopFreq = -1; move16(); + st->hIGFDec->infoIGFStopFreq = -1; + move16(); } move16(); test(); test(); - IF( st->igf && ( EQ_16(st->idchan, 0) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) + IF( st->igf && ( EQ_16( st->idchan, 0 ) || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ) { /* switch IGF configuration */ IGFDecSetMode_ivas_fx( st->hIGFDec, total_brate, bwidth, st->element_mode, -1, -1, st->rf_flag ); @@ -359,7 +360,8 @@ void mode_switch_decoder_LPD_ivas_fx( IF( st->hTcxDec != NULL ) { st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); - st->output_frame_fx = st->hTcxDec->L_frameTCX; move16(); + st->output_frame_fx = st->hTcxDec->L_frameTCX; + move16(); } IF( st->hTcxCfg != NULL ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index a8f882eb9..afaa9d78a 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3392,7 +3392,7 @@ void ivas_dirac_dec_render( *------------------------------------------------------------------------*/ void ivas_dirac_dec_render_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ const Word16 nchan_transport, /* i : number of transport channels */ Word32 *pppQMfFrame_ts_re_fx[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], @@ -4965,7 +4965,7 @@ void ivas_dirac_dec_render_sf_fx( #ifdef IVAS_FLOAT_FIXED /////////////////////////////////////////////////////// FIXED TO FLOAT ////////////////////////////////////////////////////////////////////////////////////////// - IF(EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD)) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; diff --git a/lib_dec/vlpc_2st_dec.c b/lib_dec/vlpc_2st_dec.c index b032b7e56..ac22f990a 100644 --- a/lib_dec/vlpc_2st_dec.c +++ b/lib_dec/vlpc_2st_dec.c @@ -75,4 +75,4 @@ void vlpc_2st_dec_flt( return; } -#endif \ No newline at end of file +#endif diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index 27c391c89..5f888df99 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -441,7 +441,7 @@ static void GenerateFilter_fx( FOR( i = 0; i < num_az_idx[p]; i++ ) { modelEval->BM_fx[qp + i] = L_shl( Mpy_32_32( modelEval->elevBfVec_fx[p], modelEval->azimBfVec_fx[p][i] ), Q30 - ( Q30 * 2 - 31 ) ); // Q30 - BM_idx[qp + i] = add(model->azim_start_idx[EvIdx[p]] , AzIdx[p][i]); + BM_idx[qp + i] = add( model->azim_start_idx[EvIdx[p]], AzIdx[p][i] ); } qp = add( qp, num_az_idx[p] ); } @@ -930,7 +930,7 @@ static void getPeriodicBSplineSampVec_fx( FOR( i = 0; i < *num_az_idx; i++ ) { - d = sub(d0 , imult1616(( sub(add(i , nI) , 1) ) , SegSamples)); /* offset of knot_interval */ + d = sub( d0, imult1616( ( sub( add( i, nI ), 1 ) ), SegSamples ) ); /* offset of knot_interval */ d = sub( d0, imult1616( sub( add( i, nI ), 1 ), SegSamples ) ); BfVec_fx[i] = azimBsShape_fx[abs_s( d ) * subSampFactor]; AzIdx[i] = add( nI, i ) % NumBFs; @@ -1135,18 +1135,18 @@ void BSplineModelEvalDealloc_fx( /* Allocated in LoadBSplineBinary() */ Word16 i; - IF ( model->modelROM ) + IF( model->modelROM ) { free( (void *) model->azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR ( i = 0; i < model->elevDim3; i++ ) + FOR( i = 0; i < model->elevDim3; i++ ) { free( model->azimKSeq_fx[i] ); } - free( model->azimKSeq_fx); - IF ( modelEval != NULL ) + free( model->azimKSeq_fx ); + IF( modelEval != NULL ) { - free( modelEval->hrfModL_fx); - free( modelEval->hrfModR_fx); + free( modelEval->hrfModL_fx ); + free( modelEval->hrfModR_fx ); } } return; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 808aef3db..3158cc8de 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1617,19 +1617,19 @@ typedef struct Word16 ER_e; #else const float *elevKSeq; /* Array, N x elevDim2 x elevDim3 */ - const float *AlphaL; /* Array, size AlphaN x K */ - const float *AlphaR; /* Array, size AlphaN x K */ + const float *AlphaL; /* Array, size AlphaN x K */ + const float *AlphaR; /* Array, size AlphaN x K */ const float *elevBsShape; float **azimKSeq; /* Array, length azimDim3+1 */ const float **azimBsShape; -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED int16_t azimDim3Max; int16_t iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ int16_t iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ #ifndef IVAS_FLOAT_FIXED - const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ - const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ + const float *EL; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ + const float *ER; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ #endif /* Pointers for allocation of dynamic memory */ #ifndef IVAS_FLOAT_FIXED @@ -1701,7 +1701,7 @@ typedef struct #ifndef IVAS_FLOAT_FIXED float resamp_factor; #else - Word16 resamp_factor_fx; /*Q14*/ + Word16 resamp_factor_fx; /*Q14*/ #endif #ifdef IVAS_FLOAT_FIXED const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 963f313ce..b00de3950 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -341,28 +341,28 @@ static void LoadBSplineBinaryITD( fread( &modelITD->elevDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->elevDim3, sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - float *elevKSeq_dyn_local = (float *)malloc((modelITD->elevDim3 - 2) * sizeof(float)); - fread(elevKSeq_dyn_local, sizeof(float), modelITD->elevDim3 - 2, f_hrtf); + float *elevKSeq_dyn_local = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); + fread( elevKSeq_dyn_local, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); - modelITD->elevKSeq_dyn_fx = (Word32 *)malloc(sizeof(Word32)*(modelITD->elevDim3 - 2)); - for (int i = 0; i < modelITD->elevDim3 - 2; i++) + modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( Word32 ) * ( modelITD->elevDim3 - 2 ) ); + for ( int i = 0; i < modelITD->elevDim3 - 2; i++ ) { - modelITD->elevKSeq_dyn_fx[i] = float_to_fix(elevKSeq_dyn_local[i], Q22); + modelITD->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); } #else - modelITD->elevKSeq_dyn = (float *)malloc((modelITD->elevDim3 - 2) * sizeof(float)); - fread(modelITD->elevKSeq_dyn, sizeof(float), modelITD->elevDim3 - 2, f_hrtf); + modelITD->elevKSeq_dyn = (float *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( float ) ); + fread( modelITD->elevKSeq_dyn, sizeof( float ), modelITD->elevDim3 - 2, f_hrtf ); #endif fread( &modelITD->azimDim2, sizeof( int16_t ), 1, f_hrtf ); fread( &modelITD->azimDim3, sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - float *azimKSeq_dyn_local = (float *)malloc(((modelITD->azimDim3 + 1) / 2 - 2) * sizeof(float)); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - fread(azimKSeq_dyn_local, sizeof(float), (modelITD->azimDim3 + 1) / 2 - 2, f_hrtf); + float *azimKSeq_dyn_local = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + fread( azimKSeq_dyn_local, sizeof( float ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ - for (int i = 0; i < ((modelITD->azimDim3 + 1) / 2 - 2); i++) + for ( int i = 0; i < ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ); i++ ) { - modelITD->azimKSeq_dyn_fx[i] = float_to_fix(azimKSeq_dyn_local[i], Q22); + modelITD->azimKSeq_dyn_fx[i] = float_to_fix( azimKSeq_dyn_local[i], Q22 ); } #else modelITD->azimKSeq_dyn = (float *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( float ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ @@ -371,8 +371,8 @@ static void LoadBSplineBinaryITD( fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - float *W_dyn_local = (float *)malloc(tmp * sizeof(float)); - fread(W_dyn_local, sizeof(float), tmp, f_hrtf); + float *W_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( W_dyn_local, sizeof( float ), tmp, f_hrtf ); modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); f2me_buf( W_dyn_local, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); @@ -388,13 +388,13 @@ static void LoadBSplineBinaryITD( fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - float *azimBsShape_dyn_local = (float *)malloc(tmp * sizeof(float)); - fread(azimBsShape_dyn_local, sizeof(float), tmp, f_hrtf); + float *azimBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( azimBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); - for (int i = 0; i < tmp; i++) + for ( int i = 0; i < tmp; i++ ) { - modelITD->azimBsShape_dyn_fx[i] = float_to_fix(azimBsShape_dyn_local[i], Q30); + modelITD->azimBsShape_dyn_fx[i] = float_to_fix( azimBsShape_dyn_local[i], Q30 ); } #else modelITD->azimBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); @@ -419,8 +419,8 @@ static void LoadBSplineBinaryITD( modelITD->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); } #else - modelITD->elevBsShape_dyn = (float *)malloc(tmp * sizeof(float)); - fread(modelITD->elevBsShape_dyn, sizeof(float), tmp, f_hrtf); + modelITD->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); + fread( modelITD->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); #endif fread( &modelITD->elevSegSamples, sizeof( int16_t ), 1, f_hrtf ); @@ -548,7 +548,7 @@ static ivas_error LoadBSplineBinary( model->azimDim3_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); model->azim_start_idx_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); #ifdef IVAS_FLOAT_FIXED - float **azimKSeq_local = (float **)malloc(model->elevDim3 * sizeof(float *)); + float **azimKSeq_local = (float **) malloc( model->elevDim3 * sizeof( float * ) ); model->azimKSeq_fx = (Word32 **) malloc( model->elevDim3 * sizeof( Word32 * ) ); #else model->azimKSeq = (float **) malloc( model->elevDim3 * sizeof( float * ) ); @@ -559,12 +559,12 @@ static ivas_error LoadBSplineBinary( fread( &model->azimDim3_dyn[i], sizeof( int16_t ), 1, f_hrtf ); fread( &model->azim_start_idx_dyn[i], sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - azimKSeq_local[i] = (float *)malloc((model->azimDim3_dyn[i] + 1) * sizeof(float)); - fread(azimKSeq_local[i], sizeof(float), (model->azimDim3_dyn[i] + 1), f_hrtf); + azimKSeq_local[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); + fread( azimKSeq_local[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - for (int j = 0; j < (model->azimDim3_dyn[i] + 1); j++) + for ( int j = 0; j < ( model->azimDim3_dyn[i] + 1 ); j++ ) { - model->azimKSeq_fx[i][j] = float_to_fix(azimKSeq_local[i][j], Q22); + model->azimKSeq_fx[i][j] = float_to_fix( azimKSeq_local[i][j], Q22 ); } #else model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); @@ -573,22 +573,22 @@ static ivas_error LoadBSplineBinary( } fread( &model->AlphaN, sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - float *AlphaL_dyn_local = (float *)malloc(model->AlphaN * model->K * sizeof(float)); - fread(AlphaL_dyn_local, sizeof(float), model->AlphaN * model->K, f_hrtf); + float *AlphaL_dyn_local = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); + fread( AlphaL_dyn_local, sizeof( float ), model->AlphaN * model->K, f_hrtf ); model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); - f2me_buf(AlphaL_dyn_local, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K ); + f2me_buf( AlphaL_dyn_local, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K ); #else model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); fread( model->AlphaL_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); #endif #ifdef IVAS_FLOAT_FIXED - float *AlphaR_dyn_local = (float *)malloc(model->AlphaN * model->K * sizeof(float)); - fread(AlphaR_dyn_local, sizeof(float), model->AlphaN * model->K, f_hrtf); + float *AlphaR_dyn_local = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); + fread( AlphaR_dyn_local, sizeof( float ), model->AlphaN * model->K, f_hrtf ); model->AlphaR_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); - f2me_buf(AlphaR_dyn_local, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K ); + f2me_buf( AlphaR_dyn_local, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K ); #else model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); fread( model->AlphaR_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); @@ -633,12 +633,12 @@ static ivas_error LoadBSplineBinary( fread( model->elevBsStart, sizeof( int16_t ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED - float *elevBsShape_dyn_local = (float *)malloc(tmp * sizeof(float)); - fread(elevBsShape_dyn_local, sizeof(float), tmp, f_hrtf); - model->elevBsShape_dyn_fx = (Word32 *)malloc(tmp * sizeof(Word32)); + float *elevBsShape_dyn_local = (float *) malloc( tmp * sizeof( float ) ); + fread( elevBsShape_dyn_local, sizeof( float ), tmp, f_hrtf ); + model->elevBsShape_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); for ( i = 0; i < tmp; i++ ) { - model->elevBsShape_dyn_fx[i] = float_to_fix(elevBsShape_dyn_local[i], Q30); + model->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); } #else model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); @@ -918,9 +918,9 @@ static void HRTF_energy_sections_precalc( /* Energy calculation */ #ifdef IVAS_FLOAT_FIXED tmp_fx = *pAlphaL_fx; - *pEL_fx = L_add(*pEL_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pEL_fx = L_add( *pEL_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ tmp_fx = *pAlphaR_fx; - *pER_fx = L_add(*pER_fx, L_shr(Mpy_32_32(tmp_fx, tmp_fx), 1)); /* one guard bit */ + *pER_fx = L_add( *pER_fx, L_shr( Mpy_32_32( tmp_fx, tmp_fx ), 1 ) ); /* one guard bit */ pAlphaL_fx += AlphaN; pAlphaR_fx += AlphaN; #else @@ -942,8 +942,8 @@ static void HRTF_energy_sections_precalc( } } #ifdef IVAS_FLOAT_FIXED - model->EL_dyn_e = add(shl(model->AlphaL_e, 1), 1); // 2 * AlphaL_e + 1 (one guard bit) - model->ER_dyn_e = add(shl(model->AlphaR_e, 1), 1); // 2 * AlphaR_e + 1 (one guard bit) + model->EL_dyn_e = add( shl( model->AlphaL_e, 1 ), 1 ); // 2 * AlphaL_e + 1 (one guard bit) + model->ER_dyn_e = add( shl( model->AlphaR_e, 1 ), 1 ); // 2 * AlphaR_e + 1 (one guard bit) model->EL_fx = model->EL_dyn_fx; model->EL_e = model->EL_dyn_e; @@ -1043,7 +1043,7 @@ ivas_error dealloc_HRTF_binary( free( hHrtf->ModelParams.azimKSeq ); #else free( (void *) hHrtf->ModelParams.azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ - FOR ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + FOR( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) { free( hHrtf->ModelParams.azimKSeq_fx[i] ); } @@ -1195,7 +1195,7 @@ static ivas_error create_HRTF_from_rawdata( for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) { //( *hHRTF )->inv_diffuse_weight[i] = *( (float *) ( hrtf_data_rptr ) ); - ( *hHRTF )->inv_diffuse_weight_fx[i] = ( Word16 ) (* ( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15); + ( *hHRTF )->inv_diffuse_weight_fx[i] = (Word16) ( *( (float *) ( hrtf_data_rptr ) ) * ONE_IN_Q15 ); hrtf_data_rptr += sizeof( float ); } @@ -1220,8 +1220,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1229,12 +1229,12 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } } - mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); + mem_size = max_total_num_fsamp_per_iteration * sizeof( float ); /* coeff_im (the size depends on pIndex_frequency_max) */ for ( i = 0; i < ( *hHRTF )->max_num_ir; i++ ) @@ -1252,8 +1252,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations[i][j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max[i][j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max[i][j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max[i][j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1261,7 +1261,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max[i][j][k]; } } @@ -1289,8 +1289,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for (Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1298,7 +1298,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -1319,8 +1319,8 @@ static ivas_error create_HRTF_from_rawdata( for ( k = 0; k < ( *hHRTF )->num_iterations_diffuse[j]; k++ ) { mem_size = ( *hHRTF )->pIndex_frequency_max_diffuse[j][k] * sizeof( float ); - //memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); - for ( Word16 l = 0; l < (*hHRTF)->pIndex_frequency_max_diffuse[j][k]; l++ ) + // memcpy( pOut_to_bin_wptr, hrtf_data_rptr, mem_size ); + for ( Word16 l = 0; l < ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; l++ ) { float *tmp, temp_buf[1]; tmp = temp_buf; @@ -1328,7 +1328,7 @@ static ivas_error create_HRTF_from_rawdata( pOut_to_bin_wptr_fx[l] = (Word32) ( *tmp * ONE_IN_Q29 ); hrtf_data_rptr += sizeof( float ); } - //hrtf_data_rptr += mem_size; + // hrtf_data_rptr += mem_size; pOut_to_bin_wptr_fx += ( *hHRTF )->pIndex_frequency_max_diffuse[j][k]; } } @@ -2332,11 +2332,11 @@ static ivas_error create_parambin_HRTF_from_rawdata( /*adding conversion as file reading is done in float*/ floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricReverberationEneCorrections_fx, Q31, CLDFB_NO_CHANNELS_MAX ); - //memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); + // memcpy( ( *hHRTF )->parametricEarlyPartEneCorrection, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); memcpy( f_tmp_reverb, hrtf_data_rptr, CLDFB_NO_CHANNELS_MAX * sizeof( float ) ); hrtf_data_rptr += CLDFB_NO_CHANNELS_MAX * sizeof( float ); /*adding conversion as file reading is done in float*/ - floatToFixed_arrL( f_tmp_reverb, (*hHRTF)->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); + floatToFixed_arrL( f_tmp_reverb, ( *hHRTF )->parametricEarlyPartEneCorrection_fx, Q28, CLDFB_NO_CHANNELS_MAX ); return IVAS_ERR_OK; } -- GitLab From b63cb1a1a75a80db6b0d18ed0d412ae51178d0a2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 11 Jun 2024 08:43:28 +0530 Subject: [PATCH 20/63] EVS BE fix --- lib_dec/amr_wb_dec_fx.c | 2 +- lib_dec/core_dec_init_fx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index d4cfde66c..53d5fc20f 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -750,7 +750,7 @@ ivas_error amr_wb_dec_fx( Copy( syn_fx_tmp2, syn_fx, L_FRAME ); /* TCX=Q-1, ACELP2 Q0 */ - Copy_Scale_sig( syn_fx + shr( L_FRAME, 2 ), hTcxDec->old_syn_Overl, shr( L_FRAME, 2 ), sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ + Copy_Scale_sig( syn_fx + shr( L_FRAME, 1 ), hTcxDec->old_syn_Overl, shr( L_FRAME, 1 ), sub( -1, st_fx->Q_syn ) ); /*Q_syn*/ Copy_Scale_sig( syn_fx + sub( L_FRAME, add( M, 1 ) ), st_fx->syn, add( M, 1 ), sub( 0, st_fx->Q_syn ) ); /*Q0*/ /*------------------------------------------------------------------* diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index c9f29bd2a..7acc450f9 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -414,7 +414,7 @@ void open_decoder_LPD_fx( /*PLC*/ #ifndef NEW_IVAS_OPEN_DEC - IF( EQ_16( st->prev_bfi, 0 ) ) + IF( NE_16( st->prev_bfi, 0 ) ) { PWord16 const *w; Word16 W1, W2, nz, delay_comp; -- GitLab From 90f7f3e5d8c29c864f2bcac71f212ac565fb61e3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 11 Jun 2024 12:22:42 +0530 Subject: [PATCH 21/63] ASAN and USAN fixes --- lib_com/options.h | 5 +++++ lib_dec/amr_wb_dec_fx.c | 2 +- lib_dec/gs_dec.c | 4 ++++ lib_dec/ivas_mct_dec.c | 14 ++++++++++++++ lib_dec/ivas_omasa_dec.c | 30 ++++++++++++++++++++++++++++- lib_dec/ivas_sba_dirac_stereo_dec.c | 13 +++++++++++++ lib_dec/pvq_core_dec.c | 17 ++++++++++++++++ lib_dec/updt_dec.c | 4 ++++ lib_dec/updt_dec_fx.c | 8 +++++++- lib_enc/core_enc_updt.c | 4 ++++ lib_enc/gs_enc.c | 4 ++++ lib_enc/pvq_core_enc.c | 5 +++++ 12 files changed, 107 insertions(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 47515333d..ab6123579 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -72,6 +72,11 @@ #define NON_BE_FIX_1048_THRESHOLD_COH_BASOP /* Nokia: Fix 1048 replace comparison with 0 with comparison to threshold, to align with BASOP*/ #define NONBE_FIX_1054_NEGATIVE_LVQ_INDEX /* Nokia: issue 1054: Input to decode_comb in deindex_lvq_SHB should be positive */ +#define FIX_1033_MEMORY_LEAK_OMASA /* Nokia / Orange: issue #1033: Memory leak in OMASA to BINAURAL with HRTF with bitrate switching */ +#define FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* Ericsson: premature cast to unsigned detected by USAN corrected */ +#define FIX_1027_GSC_INT_OVERFLOW /* VA: issue 2207: overflow in GSC */ +#define NONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO /* FhG: avoid sidegain DFT-Stereo param to be larger than 1 when converting from Dirac parameters */ +#define NON_BE_1055_RESET_LP_MEMORIES /* VA: issue 1055: Correctly reset LP filter MA and AR memories in bitrate switching */ /* #################### End FIXES switches ############################ */ diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 53d5fc20f..2320cc2f3 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -763,7 +763,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->on = 1; move16(); test(); - formant_post_filt_fx( 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, EQ_16( sub( amr_io_class, AUDIO_CLAS ), 0 ) ); + formant_post_filt_fx( 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, (Word16)EQ_16( sub( amr_io_class, AUDIO_CLAS ), 0 ) ); } /*----------------------------------------------------------------* diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index 010aad694..dccecfe0c 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -639,7 +639,11 @@ void gsc_dec( } if ( concat_out[j] < 0 ) { +#ifdef FIX_1027_GSC_INT_OVERFLOW + seed_init = (int16_t) ( (int32_t) seed_init + 3 ); +#else seed_init += 3; +#endif } } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 31976aae0..d6da0f015 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1920,8 +1920,15 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( st_ivas->hBinRendererTd != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) ) { +#ifdef FIX_1033_MEMORY_LEAK_OMASA + if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + { +#endif ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; +#ifdef FIX_1033_MEMORY_LEAK_OMASA + } +#endif } IF( st_ivas->hDiracDecBin != NULL ) @@ -2548,8 +2555,15 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->hBinRendererTd != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_OBJECTS_TD ) ) { +#ifdef FIX_1033_MEMORY_LEAK_OMASA + if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + { +#endif ivas_td_binaural_close( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; +#ifdef FIX_1033_MEMORY_LEAK_OMASA + } +#endif } if ( st_ivas->hDiracDecBin != NULL ) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 0e709625d..cfc09029e 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -457,10 +457,17 @@ ivas_error ivas_omasa_dec_config_fx( IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { /* Allocate TD renderer for the objects in DISC mode */ - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ) != IVAS_ERR_OK ) +#ifdef FIX_1033_MEMORY_LEAK_OMASA + IF ( st_ivas->hBinRendererTd == NULL ) + { +#endif + IF ( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ) != IVAS_ERR_OK ) { return error; } +#ifdef FIX_1033_MEMORY_LEAK_OMASA + } +#endif /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ IF( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) @@ -471,9 +478,16 @@ ivas_error ivas_omasa_dec_config_fx( ELSE { /* TD renderer handle */ +#ifdef FIX_1033_MEMORY_LEAK_OMASA + IF ( st_ivas->hBinRendererTd != NULL && st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + { +#endif ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; +#ifdef FIX_1033_MEMORY_LEAK_OMASA + } +#endif /* ISM renderer handle + ISM data handle */ ivas_omasa_separate_object_renderer_close( st_ivas ); @@ -707,11 +721,18 @@ ivas_error ivas_omasa_dec_config( { if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { +#ifdef FIX_1033_MEMORY_LEAK_OMASA + if ( st_ivas->hBinRendererTd == NULL ) + { +#endif /* Allocate TD renderer for the objects in DISC mode */ if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } +#ifdef FIX_1033_MEMORY_LEAK_OMASA + } +#endif /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ if ( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) @@ -722,8 +743,15 @@ ivas_error ivas_omasa_dec_config( else { /* TD renderer handle */ +#ifdef FIX_1033_MEMORY_LEAK_OMASA + if ( st_ivas->hBinRendererTd != NULL && st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + { +#endif ivas_td_binaural_close( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; +#ifdef FIX_1033_MEMORY_LEAK_OMASA + } +#endif /* ISM renderer handle + ISM data handle */ ivas_omasa_separate_object_renderer_close( st_ivas ); diff --git a/lib_dec/ivas_sba_dirac_stereo_dec.c b/lib_dec/ivas_sba_dirac_stereo_dec.c index c869afb08..13e9bb16b 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec.c @@ -386,10 +386,23 @@ static void map_params_dirac_to_stereo( } } +#ifdef NONBE_FIX_1096_NAN_VALUES_IN_DIRAC_TO_STEREO + /* Clamp values here. [-1, 1] is the allowed range, but due to precision issues they can be slightly off which can cause problems later. */ + side_gain[b] *= sqrtf( 1.f - diffuseness[b] ); + side_gain[b] = max( min( side_gain[b], 1 ), -1 ); + side_gain[b +STEREO_DFT_BAND_MAX] *= sqrtf( 1.f - diffuseness[b] ); + side_gain[b + STEREO_DFT_BAND_MAX] = max( min( side_gain[b + STEREO_DFT_BAND_MAX], 1 ), -1 ); + /* for residual prediction gain, allowed range is [0, 1]*/ + res_pred_gain[b] = diffuseness[b] * ( 1.0f - surrCoh[b] ); + res_pred_gain[b] = max( min( res_pred_gain[b], 1 ), 0 ); + res_pred_gain[b + STEREO_DFT_BAND_MAX] = diffuseness[b] * ( 1.0f - surrCoh[b] ); + res_pred_gain[b + STEREO_DFT_BAND_MAX] = max( min( res_pred_gain[b + STEREO_DFT_BAND_MAX], 1 ), 0 ); +#else side_gain[b] *= sqrtf( 1.f - diffuseness[b] ); side_gain[b + STEREO_DFT_BAND_MAX] *= sqrtf( 1.f - diffuseness[b] ); res_pred_gain[b] = diffuseness[b] * ( 1.0f - surrCoh[b] ); res_pred_gain[b + STEREO_DFT_BAND_MAX] = diffuseness[b] * ( 1.0f - surrCoh[b] ); +#endif } } diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 9d09d7572..3ef717d3e 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -109,8 +109,17 @@ static void pvq_decode_band( for ( j = 0; j < Np; j++ ) { +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR g_part[j] = -( (float) g_part_s[j] ) / 32768; + /* note: here g_part needs to be become exactly 1.0(float) thus in BASOP Word16 g_part_s is in the negative Q15 domain */ +#endif + +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR +/* aligned to BASOP to avoid USAN undefined negation warning for -(-32768) */ + g_part_s[j] = negate( g_part_s[j] ); +#else g_part_s[j] = -g_part_s[j]; +#endif } srt_vec_ind( g_part_s, sg_part, idx_sort, Np ); @@ -416,7 +425,11 @@ static void densitySymbolIndexDecode( { tot = res * ( res + 1 ) + 1; dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( ( res + 1 ) * ( res + 1 ) - dec_freq ) ) + res + 1; +#else alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( res + 1 ) * ( res + 1 ) - dec_freq ) + res + 1; +#endif sym_freq = 2 * ( res - alpha ) + 1; cum_freq = alpha * ( 2 * ( res + 1 ) - alpha ); } @@ -434,7 +447,11 @@ static void densitySymbolIndexDecode( dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); if ( dec_freq < tot - ( res + 1 ) - ( res - ( c + 1 ) ) * ( res - c ) * c + c + 1 ) { +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) ( res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) ) / ( 2 * res_c ); +#else alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) / ( 2 * res_c ); +#endif sym_freq = 2 * alpha * res_c + 1; cum_freq = alpha * ( ( alpha - 1 ) * res_c + 1 ); } diff --git a/lib_dec/updt_dec.c b/lib_dec/updt_dec.c index fafad2f85..70c049e0f 100644 --- a/lib_dec/updt_dec.c +++ b/lib_dec/updt_dec.c @@ -518,7 +518,11 @@ void updt_dec_common( st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + ( 1.0f - ENV_SMOOTH_FAC ) * st->stab_fac_smooth_lt; } +#ifdef NON_BE_1055_RESET_LP_MEMORIES + if ( ( st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) || ( st->tcxonly && ( st->codec_mode == MODE2 || st->element_mode > EVS_MONO ) ) ) +#else if ( ( st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) || ( st->tcxonly && st->codec_mode == MODE2 ) ) +#endif { /* reset LP memories */ set_zero( st->mem_MA, M ); diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 1f018a243..8b817242f 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -983,7 +983,13 @@ void ivas_updt_dec_common_fx( L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); } #endif - IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) +#ifdef NON_BE_1055_RESET_LP_MEMORIES + IF( (LE_32(st_fx->core_brate , SID_2k40) && EQ_16(st_fx->cng_type , FD_CNG) ) || (st_fx->tcxonly && (EQ_16(st_fx->codec_mode , MODE2) || GT_16(st_fx->element_mode , EVS_MONO)) ) ) +#else + IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) + || (st_fx->tcxonly && EQ_16(st_fx->codec_mode,MODE2)) + ) +#endif { /* reset LP memories */ diff --git a/lib_enc/core_enc_updt.c b/lib_enc/core_enc_updt.c index 26342fc32..bfd845b49 100644 --- a/lib_enc/core_enc_updt.c +++ b/lib_enc/core_enc_updt.c @@ -89,7 +89,11 @@ void core_encode_update( } } +#ifdef NON_BE_1055_RESET_LP_MEMORIES + if ( ( st->Opt_DTX_ON && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) || ( st->tcxonly && ( st->codec_mode == MODE2 || st->element_mode > EVS_MONO ) ) ) +#else if ( ( st->Opt_DTX_ON && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) || ( st->tcxonly && st->codec_mode == MODE2 ) ) +#endif { /* reset LP memories */ set_zero( st->mem_MA, M ); diff --git a/lib_enc/gs_enc.c b/lib_enc/gs_enc.c index 6071f294b..309c56a36 100644 --- a/lib_enc/gs_enc.c +++ b/lib_enc/gs_enc.c @@ -542,7 +542,11 @@ void gsc_enc( } if ( concat_out[j] < 0 ) { +#ifdef FIX_1027_GSC_INT_OVERFLOW + seed_init = (int16_t) ( (int32_t) seed_init + 3 ); +#else seed_init += 3; +#endif } } diff --git a/lib_enc/pvq_core_enc.c b/lib_enc/pvq_core_enc.c index 6f7375149..a22a68cce 100644 --- a/lib_enc/pvq_core_enc.c +++ b/lib_enc/pvq_core_enc.c @@ -121,7 +121,12 @@ static void pvq_encode_band( for ( j = 0; j < Np; j++ ) { g_part[j] = -( (float) g_part_s[j] ) / 32768; +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + /* aligned to BASOP to avoid USAN undefined negation warning with -(-32768) */ + g_part_s[j] = negate( g_part_s[j] ); +#else g_part_s[j] = -g_part_s[j]; +#endif } srt_vec_ind( g_part_s, sg_part, idx_sort, Np ); -- GitLab From 8da4fd6235449e2705dbff04bc969f2abb727c61 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 11 Jun 2024 12:28:16 +0530 Subject: [PATCH 22/63] Clang formatting changes --- lib_dec/amr_wb_dec_fx.c | 2 +- lib_dec/ivas_mct_dec.c | 8 ++++---- lib_dec/ivas_omasa_dec.c | 30 ++++++++++++++--------------- lib_dec/ivas_sba_dirac_stereo_dec.c | 2 +- lib_dec/pvq_core_dec.c | 2 +- lib_dec/updt_dec_fx.c | 6 ++---- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 2320cc2f3..616b76093 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -763,7 +763,7 @@ ivas_error amr_wb_dec_fx( st_fx->hPFstat->on = 1; move16(); test(); - formant_post_filt_fx( 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, (Word16)EQ_16( sub( amr_io_class, AUDIO_CLAS ), 0 ) ); + formant_post_filt_fx( 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, (Word16) EQ_16( sub( amr_io_class, AUDIO_CLAS ), 0 ) ); } /*----------------------------------------------------------------* diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index d6da0f015..8e4d8f4b1 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1924,8 +1924,8 @@ static ivas_error ivas_mc_dec_reconfig_fx( if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) { #endif - ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); - st_ivas->hHrtfTD = NULL; + ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); + st_ivas->hHrtfTD = NULL; #ifdef FIX_1033_MEMORY_LEAK_OMASA } #endif @@ -2559,8 +2559,8 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) { #endif - ivas_td_binaural_close( &st_ivas->hBinRendererTd ); - st_ivas->hHrtfTD = NULL; + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + st_ivas->hHrtfTD = NULL; #ifdef FIX_1033_MEMORY_LEAK_OMASA } #endif diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index cfc09029e..d3b2595a0 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -458,13 +458,13 @@ ivas_error ivas_omasa_dec_config_fx( { /* Allocate TD renderer for the objects in DISC mode */ #ifdef FIX_1033_MEMORY_LEAK_OMASA - IF ( st_ivas->hBinRendererTd == NULL ) + IF( st_ivas->hBinRendererTd == NULL ) { #endif - IF ( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ) != IVAS_ERR_OK ) - { - return error; - } + IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef FIX_1033_MEMORY_LEAK_OMASA } #endif @@ -479,12 +479,12 @@ ivas_error ivas_omasa_dec_config_fx( { /* TD renderer handle */ #ifdef FIX_1033_MEMORY_LEAK_OMASA - IF ( st_ivas->hBinRendererTd != NULL && st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + IF( st_ivas->hBinRendererTd != NULL && st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) { #endif - ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); + ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); - st_ivas->hHrtfTD = NULL; + st_ivas->hHrtfTD = NULL; #ifdef FIX_1033_MEMORY_LEAK_OMASA } #endif @@ -725,11 +725,11 @@ ivas_error ivas_omasa_dec_config( if ( st_ivas->hBinRendererTd == NULL ) { #endif - /* Allocate TD renderer for the objects in DISC mode */ - if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + /* Allocate TD renderer for the objects in DISC mode */ + if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } #ifdef FIX_1033_MEMORY_LEAK_OMASA } #endif @@ -747,8 +747,8 @@ ivas_error ivas_omasa_dec_config( if ( st_ivas->hBinRendererTd != NULL && st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) { #endif - ivas_td_binaural_close( &st_ivas->hBinRendererTd ); - st_ivas->hHrtfTD = NULL; + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); + st_ivas->hHrtfTD = NULL; #ifdef FIX_1033_MEMORY_LEAK_OMASA } #endif diff --git a/lib_dec/ivas_sba_dirac_stereo_dec.c b/lib_dec/ivas_sba_dirac_stereo_dec.c index 13e9bb16b..4e669a803 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec.c @@ -390,7 +390,7 @@ static void map_params_dirac_to_stereo( /* Clamp values here. [-1, 1] is the allowed range, but due to precision issues they can be slightly off which can cause problems later. */ side_gain[b] *= sqrtf( 1.f - diffuseness[b] ); side_gain[b] = max( min( side_gain[b], 1 ), -1 ); - side_gain[b +STEREO_DFT_BAND_MAX] *= sqrtf( 1.f - diffuseness[b] ); + side_gain[b + STEREO_DFT_BAND_MAX] *= sqrtf( 1.f - diffuseness[b] ); side_gain[b + STEREO_DFT_BAND_MAX] = max( min( side_gain[b + STEREO_DFT_BAND_MAX], 1 ), -1 ); /* for residual prediction gain, allowed range is [0, 1]*/ res_pred_gain[b] = diffuseness[b] * ( 1.0f - surrCoh[b] ); diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 3ef717d3e..6333fd52d 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -115,7 +115,7 @@ static void pvq_decode_band( #endif #ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR -/* aligned to BASOP to avoid USAN undefined negation warning for -(-32768) */ + /* aligned to BASOP to avoid USAN undefined negation warning for -(-32768) */ g_part_s[j] = negate( g_part_s[j] ); #else g_part_s[j] = -g_part_s[j]; diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 8b817242f..fb846b91a 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -984,11 +984,9 @@ void ivas_updt_dec_common_fx( } #endif #ifdef NON_BE_1055_RESET_LP_MEMORIES - IF( (LE_32(st_fx->core_brate , SID_2k40) && EQ_16(st_fx->cng_type , FD_CNG) ) || (st_fx->tcxonly && (EQ_16(st_fx->codec_mode , MODE2) || GT_16(st_fx->element_mode , EVS_MONO)) ) ) + IF( ( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && ( EQ_16( st_fx->codec_mode, MODE2 ) || GT_16( st_fx->element_mode, EVS_MONO ) ) ) ) #else - IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) - || (st_fx->tcxonly && EQ_16(st_fx->codec_mode,MODE2)) - ) + IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) #endif { -- GitLab From 2007c02fd071d000a90cb9a7b84197a30f0e564a Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 11 Jun 2024 15:13:36 -0400 Subject: [PATCH 23/63] Fix saturation, add debugging and missing rescaling --- lib_com/options.h | 1 + lib_com/swb_tbe_com_fx.c | 15 +++++++++++++++ lib_dec/swb_tbe_dec.c | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index ab6123579..5a6238041 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -145,6 +145,7 @@ #define NONBE_FIX_1069_SVD_TUNING /* FhG: issue 1069: tune SVD constants */ #define FIX_778_STEREO_BRATE_SWITCHING #define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ +#define FIX_729_MISSING_RESCALING /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index e93fdc57c..ffb96c5df 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -727,6 +727,9 @@ static void filt_mu_fx( Word16 mu, ga, temp; const Word16 *ptrs; Word16 tmp, exp; +#ifdef FIX_729_MISSING_RESCALING + Flag Overflow = 0; +#endif IF( EQ_16( SubFrameLength, L_SUBFR ) ) @@ -767,7 +770,19 @@ static void filt_mu_fx( { temp = mult_r( mu, ( *ptrs++ ) ); temp = add( temp, *ptrs ); /*Q12 */ +#ifdef FIX_729_MISSING_RESCALING + sig_out[n] = shl_o( mult_r( ga, temp ), 1, &Overflow ); +#ifdef DEBUGGING + if ( Overflow ) + { + fprintf( stderr, "Saturation in filt_mu_fx for ga = %d, temp = %d, result = %.2f at frame %d\n\n", ga, temp, (float) ga * temp * 4.0 / 65536.0, frame ); + Overflow = 0; + } +#endif + +#else sig_out[n] = shl( mult_r( ga, temp ), 1 ); +#endif move16(); /*Q12 */ } diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 37e2b6b08..70c57bff2 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -1733,6 +1733,15 @@ void ivas_swb_tbe_dec_fx( st->prev_Q_bwe_exc_fb = 51; move16(); } + +#ifdef FIX_729_MISSING_RESCALING + /* rescale the TBE post proc memory */ + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) + { + hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], Q_bwe_exc - st->prev_Q_bwe_syn ); + move16(); + } +#endif /* fill-in missing SHB excitation */ IF( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 ) { -- GitLab From 46a792389fe488965146282e9d1288bac1be9a48 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 12 Jun 2024 11:46:07 +0530 Subject: [PATCH 24/63] BASOP and instrumentation changes [x] Added missed BASOPs and instrumentation code [x] Few BASOPs are to be updated as per discussion with PC group. Changes will be made through subsequent MRs. --- lib_dec/core_switching_dec.c | 114 +++++++- lib_dec/core_switching_dec_fx.c | 35 ++- lib_dec/dec2t32_fx.c | 4 +- lib_dec/dec4t64_fx.c | 50 ++-- lib_dec/dec_ace_fx.c | 92 ++++-- lib_dec/dec_acelp_fx.c | 22 +- lib_dec/dec_acelp_tcx_main_fx.c | 58 ++-- lib_dec/dec_amr_wb_fx.c | 11 +- lib_dec/dec_gen_voic_fx.c | 79 ++++-- lib_dec/decision_matrix_dec_fx.c | 29 +- lib_dec/er_dec_acelp_fx.c | 206 ++++++++------ lib_dec/er_dec_tcx_fx.c | 324 ++++++++++++---------- lib_dec/er_scale_syn_fx.c | 20 +- lib_dec/er_sync_exc.c | 2 +- lib_dec/er_sync_exc_fx.c | 84 +++--- lib_dec/er_util_fx.c | 121 ++++---- lib_dec/hq_core_dec_fx.c | 2 +- lib_dec/hq_env_dec_fx.c | 7 +- lib_dec/hq_lr_dec_fx.c | 16 +- lib_dec/igf_dec_fx.c | 160 ++++++----- lib_dec/igf_scf_dec_fx.c | 27 +- lib_dec/init_dec_fx.c | 120 +++++--- lib_dec/inov_dec_fx.c | 53 ++-- lib_dec/ivas_dirac_output_synthesis_cov.c | 105 ++----- lib_dec/updt_dec_fx.c | 6 +- 25 files changed, 1031 insertions(+), 716 deletions(-) diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 653ef2523..d2d4f6669 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -81,8 +81,12 @@ ivas_error core_switching_pre_dec_ivas_fx( Word16 exp = 25; error = IVAS_ERR_OK; + move32(); /* Codec mode switching */ + test(); + test(); + test(); IF( EQ_16( st->last_codec_mode, MODE2 ) || ( ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) { #ifndef FIX_770_DISCONTINUITIES_SW_TCX2ACELP @@ -119,6 +123,7 @@ ivas_error core_switching_pre_dec_ivas_fx( { st->hBPF->pst_lp_ener_fx = round_fx( L_shl( Mpy_32_16_1( st->lp_error_ener, 0x6054 ), 2 + 8 ) ); /* convert from 15Q16, log2 -> 7Q8 10*log10 */ st->hBPF->pst_mem_deemp_err_fx = 0; + move16(); } #endif st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); @@ -136,6 +141,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); set16_fx( st->hb_prev_synth_buffer_fx, 0, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); + test(); IF( st->hBWE_TD != NULL && NE_16( st->last_core, ACELP_CORE ) ) { #ifdef MSAN_FIX @@ -155,6 +161,7 @@ ivas_error core_switching_pre_dec_ivas_fx( st->igf = 0; move16(); + test(); IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) { hf_synth_reset_fx( st->hBWE_zero ); @@ -196,6 +203,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move32(); } + test(); IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) { IF( EQ_16( st->element_mode, EVS_MONO ) ) @@ -238,6 +246,8 @@ ivas_error core_switching_pre_dec_ivas_fx( delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); /*TODO To be tested:control not entering the block*/ + test(); + test(); IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) { /*TODO None of the test dtreams are entering this block,hence enabled assert(0)*/ @@ -281,6 +291,8 @@ ivas_error core_switching_pre_dec_ivas_fx( Copy_Scale_sig_32_16( fer_samples_fx, st->hHQ_core->fer_samples_fx, 960, 9 ); } + test(); + test(); IF( !st->last_con_tcx && EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->core, HQ_CORE ) ) { lerp( st->hTcxDec->syn_Overl, st->hHQ_core->fer_samples_fx + delay_comp, output_frame / 2, st->last_L_frame / 2 ); @@ -298,6 +310,7 @@ ivas_error core_switching_pre_dec_ivas_fx( /*FEC*/ IF( LE_16( st->L_frame, L_FRAME16k ) ) { + test(); IF( LE_16( st->last_L_frame, L_FRAME16k ) && NE_16( st->core, HQ_CORE ) ) { IF( NE_16( st->L_frame, st->last_L_frame ) ) @@ -325,6 +338,8 @@ ivas_error core_switching_pre_dec_ivas_fx( /* Here we only handle cases where last_ppp and last_nelp not updated when coming from CodecB or other cores within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ + test(); + test(); IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || NE_16( st->last_codec_mode, MODE2 ) ) ) { st->last_ppp_mode_dec = 0; @@ -334,6 +349,9 @@ ivas_error core_switching_pre_dec_ivas_fx( } /* Handle state reset of stat_noise_uv_mod memory */ + test(); + test(); + test(); IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) || LE_32( st->last_total_brate, PPP_NELP_2k80 ) ) ) { st->act_count = 3; @@ -342,9 +360,21 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); } + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && EQ_16( st->last_core, HQ_CORE ) ) || ( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( nchan_out, 2 ) && NE_32( st->core_brate, SID_2k40 ) && NE_32( st->core_brate, FRAME_NO_DATA ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) ) ) { + test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { st->hPFstat->reset = 1; @@ -368,6 +398,12 @@ ivas_error core_switching_pre_dec_ivas_fx( lsf2lsp_fx( st->lsf_old_fx, st->lsp_old_fx, M, INT_FS_12k8 ); } + test(); + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && EQ_16( nchan_out, 2 ) && GT_32( st->core_brate, SID_2k40 ) && ( EQ_32( last_core_brate_st0, FRAME_NO_DATA ) || EQ_32( last_core_brate_st0, SID_2k40 ) ) && st->hTcxDec != NULL ) { /* Last frame was Stereo CNG and the synthesis memory is outdated -- reset */ @@ -430,6 +466,8 @@ ivas_error core_switching_pre_dec_ivas_fx( cldfb_reset_memory_fx( st->cldfbSyn ); /* reset TBE memories */ + test(); + test(); IF( !st->last_con_tcx && !( ( EQ_16( st->last_core, HQ_CORE ) ) && GT_16( st->element_mode, EVS_MONO ) ) ) { set16_fx( st->old_exc_fx, 0, L_EXC_MEM_DEC ); @@ -445,6 +483,7 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } + test(); IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) { hf_synth_reset_fx( st->hBWE_zero ); @@ -459,6 +498,9 @@ ivas_error core_switching_pre_dec_ivas_fx( } } + test(); + test(); + test(); IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) { IF( st->hBWE_TD != NULL ) @@ -491,6 +533,7 @@ ivas_error core_switching_pre_dec_ivas_fx( move16(); move16(); + test(); IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) { hf_synth_reset_fx( st->hBWE_zero ); @@ -504,6 +547,9 @@ ivas_error core_switching_pre_dec_ivas_fx( set16_fx( st->hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); } + test(); + test(); + test(); IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( 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 */ @@ -514,14 +560,19 @@ ivas_error core_switching_pre_dec_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for old_synth_lenFB (32 bit) \n" ) ); } - Copy_Scale_sig_16_32( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, Q10 - Q_old_synthFB ); + Copy_Scale_sig_16_32( st->hTcxDec->old_synthFB_fx, old_synthFB_fx, st->hTcxDec->old_synth_lenFB, sub( Q10, Q_old_synthFB ) ); Copy32( old_synthFB_fx + st->hTcxDec->old_synth_lenFB - offset, st->cldfbAna->cldfb_state_fx, offset ); st->cldfbAna->Q_cldfb_state = Q10; + move16(); IF( old_synthFB_fx ) free( old_synthFB_fx ); } } + test(); + test(); + test(); + test(); IF( EQ_16( st->core, HQ_CORE ) && ( EQ_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) || ( ( NE_16( st->element_mode, EVS_MONO ) ) && ( NE_16( st->last_core, HQ_CORE ) ) ) ) ) { set32_fx( st->hHQ_core->prev_env_fx, 0, SFM_N_WB ); @@ -545,7 +596,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( NE_16( st->element_mode, EVS_MONO ) ) { /* Estimate mem_env_delta to reinit env_stab */ - tmp_fx = L_max( 0, ENV_STAB_EST1_FX + Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ) + Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ); /*Q12*/ + tmp_fx = L_max( 0, L_add( ENV_STAB_EST1_FX, L_add( Mult_32_16( st->stab_fac_smooth_lt_fx, ENV_STAB_EST2_FX ), Mult_32_16( st->log_energy_diff_lt_fx, ENV_STAB_EST3_FX ) ) ) ); /*Q12*/ st->hHQ_core->mem_env_delta = extract_l( L_min( MAX16B, tmp_fx ) ); /* Convert to Q12 and handle saturation */ @@ -609,6 +660,12 @@ ivas_error core_switching_pre_dec_ivas_fx( /*switch on CNA on active frames*/ IF( EQ_16( st->element_mode, EVS_MONO ) ) /* for IVAS modes, st->flag_cna is set earlier */ { + test(); + test(); + test(); + test(); + test(); + test(); IF( st->VAD && ( ( NE_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, CNA_MAX_BRATE ) ) || ( EQ_16( st->core, AMR_WB_CORE ) && LE_32( st->total_brate, ACELP_8k85 ) ) ) ) { st->flag_cna = 1; @@ -628,6 +685,10 @@ ivas_error core_switching_pre_dec_ivas_fx( } /* Reconfigure CNG */ + test(); + test(); + test(); + test(); IF( st->hFdCngDec && ( NE_16( st->last_L_frame, st->L_frame ) || NE_16( st->hFdCngDec->hFdCngCom->frameSize, st->L_frame ) || EQ_16( st->ini_frame, 0 ) || NE_16( st->bwidth, st->last_bwidth ) ) ) { /* || st->last_core == AMR_WB_CORE || st->last_codec_mode == MODE2)){*/ @@ -645,24 +706,29 @@ ivas_error core_switching_pre_dec_ivas_fx( move32(); } } + test(); + test(); IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->L_frame, L_FRAME16k ) && LE_16( st->last_L_frame, L_FRAME16k ) ) { + test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { lerp( st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->last_L_frame, st->hFdCngDec->hFdCngCom->olapBufferAna_fx + st->L_frame, st->L_frame, st->last_L_frame ); } - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->L_frame * 2, st->last_L_frame * 2, Q_olapBufferSynth2 ); + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth2 ); + test(); IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->L_frame * 2, st->last_L_frame * 2, Q_olapBufferSynth ); + L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth ); IF( EQ_16( st->L_frame, L_FRAME ) ) { FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); + move32(); } } ELSE @@ -670,6 +736,7 @@ ivas_error core_switching_pre_dec_ivas_fx( FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); + move32(); } } } @@ -1682,6 +1749,8 @@ void bandwidth_switching_detect_ivas_fx( Decoder_State *st_fx /* i/o: encoder state structure */ ) { + test(); + test(); 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 */ @@ -1698,6 +1767,7 @@ void bandwidth_switching_detect_ivas_fx( test(); test(); test(); + test(); IF( GE_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) { st_fx->bws_cnt1 = 0; @@ -1932,6 +2002,9 @@ void ivas_bw_switching_pre_proc_fx( return; } + test(); + test(); + test(); IF( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) { /*----------------------------------------------------------------------* @@ -1958,9 +2031,10 @@ void ivas_bw_switching_pre_proc_fx( tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; - st->enerLL_fx_Q = ( Q + shift - 32 ) / 2; + st->enerLL_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); W_tmp = 0; + move64(); FOR( ; i < L_FRAME; i++ ) { W_tmp = W_add( W_tmp, W_shr( W_mult0_32_32( syn_dct_fx[i], syn_dct_fx[i] ), Q ) ); @@ -1971,7 +2045,8 @@ void ivas_bw_switching_pre_proc_fx( tmp = L_shr( tmp, 7 ); // divide by 128 tmp = getSqrtWord32( tmp ); st->enerLH_fx = tmp; - st->enerLH_fx_Q = ( Q + shift - 32 ) / 2; + move32(); + st->enerLH_fx_Q = shr( sub( add( Q, shift ), 32 ), 1 ); } ELSE { @@ -1985,9 +2060,12 @@ void ivas_bw_switching_pre_proc_fx( tmp = L_shr( L_tmp, 5 ); // divide by 32 tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; + move32(); st->enerLL_fx_Q = Q_audio; + move16(); L_tmp = 0; + move32(); FOR( ; i < 64; i++ ) { L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow ); @@ -1996,12 +2074,15 @@ void ivas_bw_switching_pre_proc_fx( tmp = L_shr( L_tmp, 5 ); // divide by 32 tmp = getSqrtWord32( tmp ); st->enerLH_fx = tmp; + move32(); st->enerLH_fx_Q = Q_audio; + move16(); } ELSE { Word32 tmp, L_tmp = 0; L_tmp = 0; + move32(); FOR( i = 0; i < L_FRAME / 2; i++ ) { L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow ); @@ -2009,9 +2090,12 @@ void ivas_bw_switching_pre_proc_fx( tmp = L_shr( L_tmp, 5 ); // divide by 32 tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; + move32(); st->enerLL_fx_Q = Q_audio; + move16(); L_tmp = 0; + move32(); FOR( ; i < L_FRAME; i++ ) { L_tmp = L_mac0_o( L_tmp, st->t_audio_q_fx[i], st->t_audio_q_fx[i], &Overflow ); @@ -2019,15 +2103,25 @@ void ivas_bw_switching_pre_proc_fx( tmp = L_shr( L_tmp, 5 ); // divide by 32 tmp = getSqrtWord32( tmp ); st->enerLL_fx = tmp; + move32(); st->enerLL_fx_Q = Q_audio; + move16(); } } + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) ) { // st->prev_ener_shb = 0.0f; st->prev_ener_shb_fx = 0; + move16(); IF( st->hBWE_FD != NULL ) { // set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV ); @@ -2037,12 +2131,18 @@ void ivas_bw_switching_pre_proc_fx( ELSE IF( ( ( EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) || ( EQ_16( st->core, st->last_core ) && NE_16( st->extl, st->last_extl ) ) ) && GE_16( st->last_bwidth, SWB ) ) { st->attenu_fx = 3277; + move16(); } + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_extl, WB_TBE ) || EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) && GT_32( st->core_brate, ACELP_8k00 ) ) ) { st->prev_fractive = 0; - st->prev_fractive = 0; + move16(); } return; diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 5cd563a2f..4f8854d7c 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -513,6 +513,9 @@ ivas_error core_switching_pre_dec_fx( hTcxDec = st_fx->hTcxDec; error = IVAS_ERR_OK; + test(); + test(); + test(); /* Codec switching */ IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && GT_16( st_fx->element_mode, EVS_MONO ) ) ) { @@ -555,6 +558,7 @@ ivas_error core_switching_pre_dec_fx( move16(); + test(); IF( hBWE_TD != NULL && NE_16( st_fx->last_core, ACELP_CORE ) ) { hBWE_TD->prev_hb_synth_fx_exp = 31; @@ -564,6 +568,7 @@ ivas_error core_switching_pre_dec_fx( hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); } + test(); IF( GE_32( st_fx->output_Fs, 16000 ) && st_fx->hBWE_zero != NULL ) { hf_synth_reset_fx( st_fx->hBWE_zero ); @@ -678,6 +683,9 @@ ivas_error core_switching_pre_dec_fx( cldfb_restore_memory( st_fx->cldfbSyn ); } + test(); + test(); + test(); IF( !st_fx->last_con_tcx && st_fx->last_core_bfi == ACELP_CORE && EQ_16( st_fx->core, HQ_CORE ) ) { lerp( hTcxDec->syn_Overl, hHQ_core->fer_samples_fx + delay_comp, shr( st_fx->output_frame_fx, 1 ), shr( st_fx->last_L_frame, 1 ) ); @@ -857,6 +865,7 @@ ivas_error core_switching_pre_dec_fx( /* reset TBE memories */ test(); + test(); IF( !st_fx->last_con_tcx && !( ( EQ_16( st_fx->last_core, HQ_CORE ) ) && GT_16( st_fx->element_mode, EVS_MONO ) ) ) { @@ -984,7 +993,7 @@ ivas_error core_switching_pre_dec_fx( /* handle switching cases where preecho_sb was not called in the last frame (memory not up to date) */ IF( hHQ_core != NULL ) { - hHQ_core->pastpre--; + hHQ_core->pastpre = sub( hHQ_core->pastpre, 1 ); IF( hHQ_core->pastpre <= 0 ) { reset_preecho_dec_fx( hHQ_core ); @@ -1420,7 +1429,7 @@ ivas_error core_switching_post_dec_fx( set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); test(); - if ( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) + IF( NE_16( st_fx->last_extl, SWB_BWE ) && NE_16( st_fx->last_extl, FB_BWE ) ) { hBWE_FD->prev_mode = NORMAL; move16(); @@ -1578,7 +1587,7 @@ ivas_error core_switching_post_dec_ivas_fx( delta = 1; move16(); - if ( GE_16( output_frame, L_FRAME16k ) ) + IF( GE_16( output_frame, L_FRAME16k ) ) { delta = shr( Fs_kHz, 3 ); } @@ -2015,7 +2024,7 @@ ivas_error core_switching_post_dec_ivas_fx( } /* reset TBE buffers */ - if ( hBWE_TD != NULL ) + IF( hBWE_TD != NULL ) { /* reset SWB TBE buffers */ test(); @@ -2143,13 +2152,13 @@ void core_switching_hq_prepare_dec_fx( IF( EQ_16( st_fx->last_L_frame, L_FRAME ) ) { cbrate = L_add( st_fx->core_brate, 0 ); - if ( GT_32( st_fx->core_brate, ACELP_24k40 ) ) + IF( GT_32( st_fx->core_brate, ACELP_24k40 ) ) { cbrate = L_add( ACELP_24k40, 0 ); } /* subtract ACELP switching frame bits */ - if ( GE_32( st_fx->core_brate, ACELP_11k60 ) ) + IF( GE_32( st_fx->core_brate, ACELP_11k60 ) ) { ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */ } @@ -2173,7 +2182,7 @@ void core_switching_hq_prepare_dec_fx( } /* subtract ACELP switching frame bits */ - if ( GE_32( st_fx->core_brate, ACELP_11k60 ) ) + IF( GE_32( st_fx->core_brate, ACELP_11k60 ) ) { ( *num_bits ) = sub( ( *num_bits ), 1 ); /* LP_FLAG bit */ } @@ -2298,31 +2307,36 @@ static void smoothTransitionDtxToTcx_fx( #endif filter_len = TRANSITION_SMOOTHING_LEN_16k; + move16(); IF( EQ_16( output_frame, L_FRAME32k ) ) { filter_len = TRANSITION_SMOOTHING_LEN_32k; + move16(); } ELSE IF( EQ_16( output_frame, L_FRAME48k ) ) { filter_len = TRANSITION_SMOOTHING_LEN_48k; + move16(); } /* prepare buffer */ FOR( i = 0; i < filter_len / 2; i++ ) { smoothing_input_buffer[i] = synth[0]; + move16(); } - Copy( synth, smoothing_input_buffer + filter_len / 2, add( shl( delay_comp, 1 ), shr( filter_len, 1 ) ) ); + Copy( synth, smoothing_input_buffer + shr( filter_len, 1 ), add( shl( delay_comp, 1 ), shr( filter_len, 1 ) ) ); /* apply Mean filter */ w = div_s( 1, filter_len ); mem = 0; + move32(); FOR( i = 0; i < filter_len; i++ ) { mem = L_add( mem, L_deposit_l( smoothing_input_buffer[i] ) ); } // mem = sum32_fx( smoothing_input_buffer, filter_len ); - FOR( i = 0; i < 2 * delay_comp; i++ ) + FOR( i = 0; i < shl( delay_comp, 1 ); i++ ) { smoothing_out_buffer[i] = extract_l( Mpy_32_16_1( mem, w ) ); move16(); @@ -2343,7 +2357,8 @@ static void smoothTransitionDtxToTcx_fx( } fade_in = 0; - FOR( ; i < 2 * delay_comp; i++ ) + move16(); + FOR( ; i < shl( delay_comp, 1 ); i++ ) { synth[i] = add( mult_r( synth[i], fade_in ), mult_r( smoothing_out_buffer[i], sub( ONE_IN_Q15 - 1, fade_in ) ) ); move16(); diff --git a/lib_dec/dec2t32_fx.c b/lib_dec/dec2t32_fx.c index 519d8ed87..e62814cc6 100644 --- a/lib_dec/dec2t32_fx.c +++ b/lib_dec/dec2t32_fx.c @@ -58,7 +58,7 @@ void dec_acelp_2t32_fx( code[i0] = -512; move16(); - if ( s_and( index, 0x800 ) == 0 ) + IF( s_and( index, 0x800 ) == 0 ) { code[i0] = 512; move16(); @@ -66,7 +66,7 @@ void dec_acelp_2t32_fx( code[i1] = -512; move16(); - if ( s_and( index, 0x20 ) == 0 ) + IF( s_and( index, 0x20 ) == 0 ) { code[i1] = 512; move16(); diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 6186891de..882dd67f9 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -180,6 +180,7 @@ void dec_acelp_4t64_fx( FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { ind1[k] = get_next_indice( st_fx, 2 ); + move32(); } FOR( k = 0; k < NB_TRACK_FCB_4T; k++ ) { @@ -194,10 +195,12 @@ void dec_acelp_4t64_fx( FOR( k = 0; k < NB_TRACK_FCB_4T - 2; k++ ) { ind1[k] = get_next_indice( st_fx, 10 ); + move32(); } FOR( k = 2; k < NB_TRACK_FCB_4T; k++ ) { ind1[k] = get_next_indice( st_fx, 2 ); + move32(); } FOR( k = 0; k < NB_TRACK_FCB_4T - 2; k++ ) { @@ -255,7 +258,7 @@ static void add_pulses_fx( { /* i = ((pos[k] & (NB_POS-1))*NB_TRACK) + track */ logic16(); - i = shl( (Word16) ( pos[k] & ( NB_POS_FCB_4T - 1 ) ), 2 ); + i = shl( s_and( pos[k], ( NB_POS_FCB_4T - 1 ) ), 2 ); logic16(); IF( ( pos[k] & NB_POS_FCB_4T ) == 0 ) @@ -296,7 +299,7 @@ void dec_1p_N1_fx( /* i = ((index >> N) & 1); */ i = L_shr( index, N ) & 1L; - if ( i != 0 ) + IF ( i != 0 ) { pos1 = add( pos1, NB_POS_FCB_4T ); } @@ -557,7 +560,7 @@ static void dec_6p_6N2_fx( offsetA = offsetB = j; move16(); logic16(); - IF( ( L_shr( index, sub( n_6, 5 ) ) & 1L ) == 0 ) + IF( L_and( L_shr( index, sub( n_6, 5 ) ), 1L ) == 0 ) { /* IF (((index >> ((6*N)-5)) & 1) == 0) */ offsetA = offset; @@ -649,7 +652,7 @@ IF( ( LT_16( pulse_pos_num, pulse_num ) ) && ( GT_16( pulse_pos_num, 1 ) ) ) sector_6p_num[i] = 1; move16(); } - sector_6p_num[k]++; + sector_6p_num[k] = add( sector_6p_num[k], 1 ); move16(); } ELSE{ @@ -690,20 +693,23 @@ static void fcb_decode_position_fx( FOR( i = 0; i < pos_num - 1; i++ ) { /* k = PI_select_table[16-l][temp] - k ;*/ - k = L_sub( PI_select_table[16 - l][temp], k ); + k = L_sub( PI_select_table[L_sub( 16, l )][temp], k ); - FOR( ; PI_select_table[16 - l][temp] >= k; l += 2 ); + FOR( ; PI_select_table[L_sub( 16, l )][temp] >= k; l += 2 ); - if ( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) + IF ( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) { l = L_sub( l, 1 ); } /* k = PI_select_table[17-l][temp--] - k ;*/ - k = L_sub( PI_select_table[L_sub( 17, l )][temp--], k ); + k = L_sub( PI_select_table[L_sub( 17, l )][temp], k ); + temp = sub( temp, 1 ); pos_vector[i] = extract_l( L_sub( l, 1 ) ); + move16(); } pos_vector[i] = extract_l( L_add( l, k ) ); + move16(); return; } @@ -768,10 +774,12 @@ void D_ACELP_decode_43bit_fx( UWord16 idxs[], Word16 code[], Word16 *pulsestrack set16_fx( code, 0, L_SUBFR ); ps[3] = L_deposit_l( s_and( idxs[0], 0x1ff ) ); + move32(); ps[2] = L_add( L_shl( s_and( idxs[1], 3 ), 7 ), L_shr( idxs[0], 9 ) ); + move32(); joint_index = L_shr( L_add( L_shl( (Word32) idxs[2], 16 ), (Word32) idxs[1] ), 2 ); - if ( GE_32( joint_index, joint_offset ) ) + IF ( GE_32( joint_index, joint_offset ) ) { joint_index = L_sub( joint_index, joint_offset ); } @@ -1052,6 +1060,7 @@ static void dec_1p_N1_L_subfr_fx( } pos[0] = pos1; + move16(); return; } @@ -1070,15 +1079,16 @@ static void add_pulses_L_subfr_fx( FOR( k = 0; k < nb_pulse; k++ ) { - i = shl( ( pos[k] & ( nb_pos - 1 ) ), 2 ); - IF( EQ_16( ( pos[k] & nb_pos ), 0 ) ) + i = shl( s_and( pos[k], sub( nb_pos, 1 ) ), 2 ); + IF( EQ_16( sub( pos[k], nb_pos ), 0 ) ) { - ptr[i] = add( ptr[i], 512 ); + move16(); } ELSE { ptr[i] = sub( ptr[i], 512 ); + move16(); } } @@ -1097,6 +1107,7 @@ void dec_acelp_fast_fx( PulseConfig config; skip_track = -1; + move16(); set16_fx( code, 0, L_subfr ); st->total_num_bits = extract_l( st->total_brate / FRAMES_PER_SEC ); @@ -1151,10 +1162,12 @@ void dec_acelp_fast_fx( IF( EQ_16( config.bits, 20 ) ) { skip_track = -1; + move16(); } ELSE IF( EQ_16( (Word16) config.codetrackpos, (Word16) TRACKPOS_FIXED_FIRST ) ) { skip_track = 0; + move16(); } ELSE IF( EQ_16( (Word16) config.codetrackpos, (Word16) TRACKPOS_FREE_ONE ) ) { @@ -1181,6 +1194,7 @@ void dec_acelp_fast_fx( ELSE /* L_subfr == 2*L_SUBFR */ { config.bits = cdk_index; + move16(); IF( EQ_16( cdk_index, 14 ) ) { @@ -1190,19 +1204,23 @@ void dec_acelp_fast_fx( index = get_next_indice_fx( st, 14 ); - i0 = shl( shr( index, 7 ) & ( NB_POS_FCB_2T_128 - 1 ), 1 ); - i1 = add( shl( index & ( NB_POS_FCB_2T_128 - 1 ), 1 ), 1 ); + i0 = shl( s_and( shr( index, 7 ), ( NB_POS_FCB_2T_128 - 1 ) ), 1 ); + i1 = add( shl( s_and( index, ( NB_POS_FCB_2T_128 - 1 ) ), 1 ), 1 ); code[i0] = -512; - IF( EQ_16( ( index & 0x2000 ), 0 ) ) + move16(); + IF( EQ_16( s_and( index, 0x2000 ), 0 ) ) { code[i0] = 512; + move16(); } code[i1] = -512; - IF( EQ_16( ( index & 0x40 ), 0 ) ) + move16(); + IF( EQ_16( s_and( index, 0x40 ), 0 ) ) { code[i1] = 512; + move16(); } } ELSE IF( EQ_16( cdk_index, 12 ) ) diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 0f623af53..8764b1d2a 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -140,7 +140,7 @@ void decoder_acelp_fx( move16(); test(); test(); - if ( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) + IF( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -153,7 +153,7 @@ void decoder_acelp_fx( /* Reset phase dispersion */ - IF( st->last_core_bfi > ACELP_CORE ) + IF( GT_16( st->last_core_bfi, ACELP_CORE ) ) { st->dm_fx.prev_gain_code = L_deposit_l( 0 ); set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); @@ -169,6 +169,7 @@ void decoder_acelp_fx( synth_mem_updt2( st->L_frame, L_FRAME16k, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC ); } + test(); IF( st->last_con_tcx && st->old_enr_LP ) { Word16 enr_LP, ratio; @@ -184,6 +185,7 @@ void decoder_acelp_fx( FOR( i = 0; i < L_EXC_MEM_DEC; i++ ) { st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); + move16(); } } } @@ -211,7 +213,7 @@ void decoder_acelp_fx( * Fast recovery flag *------------------------------------------------------------------------*/ test(); - if ( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) + IF( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) { /*Force BPF to be applied fully*/ st->bpf_gain_param = 3; @@ -252,6 +254,12 @@ void decoder_acelp_fx( FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { + Word16 idx = 0; + IF( i_subfr != 0 ) + { + idx = idiv1616( i_subfr, L_SUBFR ); + } + test(); IF( EQ_16( st->use_partial_copy, 1 ) && EQ_16( st->rf_frame_type, RF_NELP ) ) { @@ -270,16 +278,18 @@ void decoder_acelp_fx( *-------------------------------------------------------*/ test(); - IF( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] == 0 ) + IF( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 ) { gain_pit = prev_gain_pit; + move16(); } IF( acelp_cfg.ltp_bits != 0 ) { /* 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[idx] = 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 ); + move32(); /* find pitch excitation */ test(); IF( EQ_16( st->pit_res_max, 6 ) && !( st->use_partial_copy ) ) @@ -324,9 +334,13 @@ void decoder_acelp_fx( set16_fx( &exc[i_subfr], 0, L_SUBFR ); T0 = L_SUBFR; + move16(); T0_frac = 0; + move16(); T0_res = 1; - pitch_buf[i_subfr / L_SUBFR] = L_deposit_h( L_SUBFR ); + move16(); + pitch_buf[idx] = L_deposit_h( L_SUBFR ); + move32(); } IF( st->igf != 0 ) @@ -334,7 +348,8 @@ void decoder_acelp_fx( tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); } - pitch_buffer[i_subfr / L_SUBFR] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); + pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); + move16(); /*-------------------------------------------------------* * - Decode innovative codebook. * @@ -352,7 +367,7 @@ void decoder_acelp_fx( } ELSE { - config = PulseConfTable[acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; + config = PulseConfTable[acelp_cfg.fixed_cdk_index[idx]]; D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, prm, &st->BER_detect ); ( prm ) += 8; /*-------------------------------------------------------* @@ -366,7 +381,7 @@ void decoder_acelp_fx( * - Generate Gaussian excitation * *-------------------------------------------------------*/ test(); - IF( EQ_16( acelp_cfg.gains_mode[i_subfr / L_SUBFR], 7 ) && !st->use_partial_copy ) + IF( EQ_16( acelp_cfg.gains_mode[idx], 7 ) && !st->use_partial_copy ) { gaus_L2_dec( code2, st->tilt_code_fx, p_A, acelp_cfg.formant_enh_num, &( st->seed_acelp ) ); } @@ -379,18 +394,20 @@ void decoder_acelp_fx( /*-------------------------------------------------* * - Decode codebooks gains. * *-------------------------------------------------*/ - IF( st->acelp_cfg.gains_mode[i_subfr / L_SUBFR] != 0 ) + IF( st->acelp_cfg.gains_mode[idx] != 0 ) { - decode_acelp_gains_fx( code, acelp_cfg.gains_mode[i_subfr / L_SUBFR], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ), + decode_acelp_gains_fx( code, acelp_cfg.gains_mode[idx], 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; + move32(); } IF( st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) { st->past_gpit = 67; + move32(); } IF( st->igf != 0 ) { @@ -400,12 +417,14 @@ void decoder_acelp_fx( /* 5/2 times resampled past memories*/ reScaleLen_fx = add( shl( i_subfr, 1 ), shr( i_subfr, 1 ) ); reSampLen = ( L_SUBFR * HIBND_ACB_L_FAC ); + move16(); } ELSE { /* 2 times resampled past memories*/ reScaleLen_fx = shl( i_subfr, 1 ); reSampLen = ( L_SUBFR * 2 ); + move16(); } Rescale_exc( NULL, &exc[i_subfr], &bwe_exc[reScaleLen_fx], @@ -424,7 +443,7 @@ void decoder_acelp_fx( *----------------------------------------------------------*/ 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; + pgainT[idx] = gain_pit; move16(); /*-------------------------------------------------------* @@ -449,7 +468,9 @@ void decoder_acelp_fx( } } gain_code_pre = gain_code; - st->tilt_code_dec_fx[i_subfr / L_SUBFR] = st->tilt_code_fx; + move32(); + st->tilt_code_dec_fx[idx] = st->tilt_code_fx; + move16(); tmp2 = shr( L_SUBFR, 1 ); @@ -462,7 +483,7 @@ void decoder_acelp_fx( Ltmp = L_shl( Ltmp, add( 5, st->Q_exc ) ); Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); #ifdef BASOP_NOGLOB - exc2[i + i_subfr] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); + exc2[add( i, i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); #else exc2[i + i_subfr] = round_fx( L_shl( Ltmp, 1 ) ); #endif @@ -477,7 +498,7 @@ void decoder_acelp_fx( #endif BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - exc[i + i_subfr] = round_fx_sat( Ltmp ); + exc[add( i, i_subfr )] = round_fx_sat( Ltmp ); #else exc[i + i_subfr] = round_fx( Ltmp ); #endif @@ -490,14 +511,16 @@ void decoder_acelp_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ gain_code = gain_code_tmp; + move32(); gain_pit = gain_pit_tmp; + move16(); IF( st->igf != 0 ) { prep_tbe_exc_fx( st->L_frame, #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, + i_subfr, gain_pit, gain_code, code, st->voice_fac, &voice_factors[idx], bwe_exc, gain_preQ, code_preQ, st->Q_exc, T0, T0_frac, st->coder_type, st->core_brate #ifdef ADD_IVAS_TBE_CODE , @@ -511,7 +534,7 @@ void decoder_acelp_fx( *---------------------------------------------------------*/ 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, - acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], L_SUBFR, st->L_frame, st->Q_exc ); + acelp_cfg.fixed_cdk_index[idx], L_SUBFR, st->L_frame, st->Q_exc ); } /* !RF_NELP frame partial copy */ /*----------------------------------------------------------* @@ -525,16 +548,16 @@ void decoder_acelp_fx( * update lp_filtered gains for the case of frame erasure *-----------------------------------------------------------------*/ - st->Mode2_lp_gainp = L_add( st->Mode2_lp_gainp, L_mult0( st->past_gpit, weights[i_subfr / L_SUBFR] ) ); /* 2Q29=1Q14*Q15 */ + st->Mode2_lp_gainp = L_add( st->Mode2_lp_gainp, L_mult0( st->past_gpit, weights[idx] ) ); /* 2Q29=1Q14*Q15 */ move32(); - st->Mode2_lp_gainc = L_add( st->Mode2_lp_gainc, Mpy_32_16_1( st->past_gcode, weights[i_subfr / L_SUBFR] ) ); /* 15Q16=15Q16*Q15 */ + st->Mode2_lp_gainc = L_add( st->Mode2_lp_gainc, Mpy_32_16_1( st->past_gcode, weights[idx] ) ); /* 15Q16=15Q16*Q15 */ move32(); /*----------------------------------------------------------* * - update pitch lag for guided ACELP * *----------------------------------------------------------*/ test(); - if ( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) + IF( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) { st->T0_4th = T0; move16(); @@ -547,6 +570,7 @@ void decoder_acelp_fx( /* copy current gain for next subframe use, in case there is no explicit encoding */ prev_gain_pit = gain_pit; + move16(); } /* end of subframe loop */ IF( st->BER_detect ) @@ -560,7 +584,7 @@ void decoder_acelp_fx( int_lsp_fx( st->L_frame, st->old_lsp_q_cng, st->lsp_q_cng, st->Aq_cng, M, interpol_frac_fx, 0 ); p_A = st->Aq_cng; - IF( st->last_good < UNVOICED_TRANSITION ) + IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { Copy( st->mem_syn2_fx, mem_syn, M ); } @@ -601,6 +625,7 @@ void decoder_acelp_fx( FOR( k = 0; k < st->nb_subfr; k++ ) { pit16[k] = shl( extract_h( pitch_buf[k] ), 6 ); /*Q6*/ + move16(); } FEC_clas_estim_fx( st, /*Opt_AMR_WB*/ 0, st->L_frame, &( st->clas_dec ), st->core_ext_mode, pit16, syn, @@ -617,10 +642,16 @@ void decoder_acelp_fx( { Word16 pBuf_scaleSyn[NB_SUBFR16k]; + Word16 L_frame_fr = 0; + IF( st->L_frame != 0 ) + { + L_frame_fr = idiv1616( st->L_frame, L_SUBFR ); + } - FOR( i = 0; i < ( st->L_frame / L_SUBFR ); i++ ) + FOR( i = 0; i < L_frame_fr; i++ ) { pBuf_scaleSyn[i] = round_fx( pitch_buf[i] ); + move16(); } Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); @@ -649,9 +680,9 @@ void decoder_acelp_fx( move16(); E_UTIL_deemph2( st->Q_syn, syn, st->preemph_fac, st->L_frame, &tmp_deemph ); /* tmp_deemph and syn in Q0 starting from here*/ - bufferCopyFx( syn + st->L_frame - st->L_frame / 2, hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); + bufferCopyFx( syn + shr( st->L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); - Copy( syn + st->L_frame - M - 1, st->syn, 1 + M ); /*Q0*/ + Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); /*Q0*/ Copy( syn, synth, st->L_frame ); IF( st->hBWE_TD != NULL ) @@ -666,19 +697,26 @@ void decoder_acelp_fx( /* Output pitch parameters for bass post-filter */ FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - *pT++ = round_fx( pitch_buf[i_subfr / L_SUBFR] ); + Word16 idx = 0; + IF( i_subfr != 0 ) + { + idx = idiv1616( i_subfr, L_SUBFR ); + } + *pT++ = round_fx( pitch_buf[idx] ); } hTcxDec->tcxltp_last_gain_unmodified = 0; + move16(); /*Update MODE1*/ Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); st->old_Es_pred_fx = Es_pred; + move16(); 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, 6 ) - 1]; + st->old_fpitch = pitch_buf[sub( shr( st->L_frame, 6 ), 1 )]; move32(); diff --git a/lib_dec/dec_acelp_fx.c b/lib_dec/dec_acelp_fx.c index d2bcffb6c..b560f7bea 100644 --- a/lib_dec/dec_acelp_fx.c +++ b/lib_dec/dec_acelp_fx.c @@ -38,7 +38,7 @@ void D_ACELP_indexing_fx( UWord32 idxs32[4], index_n[NB_TRACK_FCB_4T]; Word16 restpulses, wordcnt, wordcnt32; - assert( num_tracks == NB_TRACK_FCB_4T ); + assert( EQ_16( num_tracks, NB_TRACK_FCB_4T ) ); wordcnt = shr( add( config.bits, 15 ), 4 ); /* ceil(bits/16) */ @@ -210,21 +210,21 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 FOR( ; p; p-- ) /* one pulse placed, so one less left */ { - IF( LT_32( s, pulsestostates[k][p - 1] ) ) + IF( LT_32( s, pulsestostates[k][sub( p, 1 )] ) ) { BREAK; } - s = L_sub( s, pulsestostates[k][p - 1] ); + s = L_sub( s, pulsestostates[k][sub( p, 1 )] ); IF( v[idx] != 0 ) /* there is a pulse here already = sign is known */ { - if ( v[idx] > 0 ) + IF( v[idx] > 0 ) { v[idx] = add( v[idx], _1_CODE ); /* place one more pulse here */ move16(); } - if ( v[idx] <= 0 ) + IF( v[idx] <= 0 ) { v[idx] = sub( v[idx], _1_CODE ); /* place one more pulse here */ move16(); @@ -234,7 +234,7 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 { v[idx] = +_1_CODE; /* place a negative pulse here */ move16(); - if ( L_and( s, 0x1 ) != 0 ) + IF( L_and( s, 0x1 ) != 0 ) { v[idx] = -_1_CODE; /* place a negative pulse here */ move16(); @@ -272,7 +272,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[4] = 1; move16(); - if ( GE_16( indx_flag, track_num ) ) + IF( GE_16( indx_flag, track_num ) ) { hi_to_low[4] = 9; move16(); @@ -280,7 +280,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[7] = 1; move16(); - if ( GE_16( indx_flag_2, 1 ) ) + IF( GE_16( indx_flag_2, 1 ) ) { hi_to_low[7] = 9; move16(); @@ -308,7 +308,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in } ELSE { - FOR( track = ( wordcnt - 1 ); track >= track_num; track-- ) + FOR( track = sub( wordcnt, 1 ); track >= track_num; track-- ) { index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } @@ -322,7 +322,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in ELSE { index = L_deposit_l( 0 ); - FOR( track = ( wordcnt - 1 ); track >= 2; track-- ) + FOR( track = sub( wordcnt, 1 ); track >= 2; track-- ) { index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } @@ -362,7 +362,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in ELSE { index = L_deposit_l( 0 ); - FOR( track = ( wordcnt - 1 ); track >= 0; track-- ) + FOR( track = sub( wordcnt, 1 ); track >= 0; track-- ) { index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index 7976b2763..93eb4605f 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -30,7 +30,7 @@ static void decode_frame_type_fx( Decoder_State *st frame_size_index = 0; move16(); total_brate = st->total_brate; - move16(); + move32(); Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ @@ -69,9 +69,10 @@ static void decode_frame_type_fx( Decoder_State *st ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) { st->cng_type = get_next_indice( st, 1 ); - if ( NE_16( st->cng_type, FD_CNG ) ) + IF( NE_16( st->cng_type, FD_CNG ) ) { st->BER_detect = 1; + move16(); } st->m_frame_type = SID_FRAME; move16(); @@ -83,7 +84,7 @@ static void decode_frame_type_fx( Decoder_State *st frame_len_indicator = get_next_indice( st, 1 ); IF( EQ_16( st->bwidth, NB ) ) { - if ( frame_len_indicator ) + IF( frame_len_indicator ) { st->BER_detect = 1; move16(); @@ -94,18 +95,24 @@ static void decode_frame_type_fx( Decoder_State *st IF( frame_len_indicator == 0 ) { st->L_frame = L_FRAME; + move16(); st->total_brate = ACELP_9k60; + move32(); } ELSE { st->L_frame = L_FRAME16k; + move16(); + test(); IF( st->last_total_brate == ACELP_16k40 || st->last_total_brate == ACELP_24k40 ) { st->total_brate = st->last_total_brate; + move32(); } ELSE { st->total_brate = ACELP_16k40; + move32(); } } @@ -151,7 +158,7 @@ static void decode_frame_type_fx( Decoder_State *st } ELSE { - st->bwidth += FrameSizeConfig[frame_size_index].bandwidth_min; + st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); } IF( GT_16( st->bwidth, FB ) ) @@ -172,12 +179,13 @@ static void decode_frame_type_fx( Decoder_State *st } /* Get reserved bits */ + test(); IF( FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0 ) { Word16 dummyBit; dummyBit = (Word8) get_next_indice( st, 1 ); move16(); - if ( dummyBit != 0 ) + IF( dummyBit != 0 ) { st->BER_detect = 1; move16(); @@ -190,7 +198,8 @@ static void decode_frame_type_fx( Decoder_State *st st->rate_switching_init = 0; move16(); - if ( st->last_codec_mode != MODE2 || !st->BER_detect ) + test(); + IF( NE_16( st->last_codec_mode, MODE2 ) || !st->BER_detect ) { /* Mode or Rate Change */ test(); @@ -225,13 +234,14 @@ static void decode_frame_type_fx( Decoder_State *st ELSE { st->cldfbSyn->bandsToZero = 0; + move16(); } /* Reconf FD-CNG */ L_tmp = st->total_brate; move32(); test(); - if ( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) + IF( EQ_16( st->rf_flag, 1 ) && EQ_32( st->total_brate, ACELP_13k20 ) ) { L_tmp = ACELP_9k60; move32(); @@ -251,16 +261,18 @@ static void decode_frame_type_fx( Decoder_State *st #endif IF( EQ_16( st->L_frame, L_FRAME ) ) { - FOR( n = 0; n < st->L_frame * 2; n++ ) + FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 ); + move16(); } } ELSE { - FOR( n = 0; n < st->L_frame * 2; n++ ) + FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 ); + move16(); } } } @@ -268,7 +280,9 @@ static void decode_frame_type_fx( Decoder_State *st IF( NE_16( st->bwidth, st->last_bwidth ) ) { st->hFdCngDec->hFdCngCom->msFrCnt_init_counter = 0; + move16(); st->hFdCngDec->hFdCngCom->init_old = 32767; + move16(); } /* Reconf BPF */ @@ -281,6 +295,7 @@ static void decode_frame_type_fx( Decoder_State *st } st->total_brate = total_brate; + move32(); } @@ -323,7 +338,7 @@ Word16 dec_acelp_tcx_frame_fx( start_bit_pos = st->next_bit_pos; move16(); - if ( EQ_16( st->rf_flag, 1 ) ) + IF( EQ_16( st->rf_flag, 1 ) ) { start_bit_pos = sub( start_bit_pos, 2 ); } @@ -351,6 +366,7 @@ Word16 dec_acelp_tcx_frame_fx( ); st->force_lpd_reset = 0; + move16(); test(); test(); @@ -368,7 +384,7 @@ Word16 dec_acelp_tcx_frame_fx( move16(); st->L_frame = L_frame; move16(); - if ( st->ini_frame != 0 ) + IF( st->ini_frame != 0 ) { st->total_brate = total_brate; move32(); @@ -393,6 +409,7 @@ Word16 dec_acelp_tcx_frame_fx( move32(); st->bfi = 1; move16(); + test(); IF( st->ini_frame == 0 && st->hTcxCfg != NULL ) { st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( SWB ); @@ -413,10 +430,10 @@ Word16 dec_acelp_tcx_frame_fx( FOR( i = 0; i < 8 * 2; i++ ) { st->bit_stream[i] = 0; + move16(); } } - IF( s_and( (Word16) NE_16( st->m_frame_type, SID_FRAME ), (Word16) NE_16( st->m_frame_type, ZERO_FRAME ) ) ) /* test */ { @@ -457,15 +474,16 @@ Word16 dec_acelp_tcx_frame_fx( decoder_LPD_fx( pcmBuf, pcmbufFB, NULL, st, bpf_noise_buf, 1, &bitsRead, NULL, pitch_buf, voice_factors, ptr_bwe_exc ); } - test(); - test(); - test(); - test(); - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { + test(); + test(); + test(); + test(); IF( ( st->bfi == 0 && ( EQ_16( st->prev_bfi, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) || ( ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) ) { hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } @@ -495,20 +513,20 @@ Word16 dec_acelp_tcx_frame_fx( -1 as flag-bit not considered in rf_target_bits */ IF( EQ_16( st->rf_flag, 1 ) ) { - get_next_indice_tmp_fx( st, start_bit_pos + num_bits - st->rf_target_bits - 3 - get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) - st->next_bit_pos ); + get_next_indice_tmp_fx( st, sub( sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), 3 ), get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ), st->next_bit_pos ) ); } ELSE { - get_next_indice_tmp_fx( st, start_bit_pos + num_bits - st->rf_target_bits - get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) - st->next_bit_pos ); + get_next_indice_tmp_fx( st, sub( sub( sub( add( start_bit_pos, num_bits ), st->rf_target_bits ), get_tbe_bits_fx( st->total_brate, st->bwidth, st->rf_flag ) ), st->next_bit_pos ) ); } tbe_read_bitstream_fx( st ); } /* updates */ st->last_voice_factor_fx = voice_factors[st->nb_subfr - 1]; - ; move16(); st->last_coder_type = st->coder_type; + move16(); } ELSE { diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index 6c0a668d2..9682b152b 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -140,14 +140,21 @@ void decod_amr_wb_fx( L_tmp = L_mac( L_tmp, VF_1st_PARAM_FX, voice_fac_fx ); voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); + Word16 idx = 0; + IF( i_subfr != 0 ) + { + idx = idiv1616( i_subfr, L_SUBFR ); + } + /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/ - voice_factors_fx[i_subfr / L_SUBFR] = s_min( s_max( 0, voice_fac_fx ), 32767 ); + voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 ); move16(); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); - gain_buf[i_subfr / L_SUBFR] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; + move16(); } hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 8f75dea7f..1fd514e1c 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -282,8 +282,14 @@ ivas_error decod_gen_voic_fx( * Prepare TBE excitation *-----------------------------------------------------------------*/ + Word16 idx = 0; + IF( i_subfr_fx != 0 ) + { + idx = idiv1616( i_subfr_fx, L_SUBFR ); + } + 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, + &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate ); @@ -305,7 +311,7 @@ ivas_error decod_gen_voic_fx( p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - gain_buf[i_subfr_fx / L_SUBFR] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; move16(); } @@ -379,7 +385,7 @@ ivas_error decod_gen_voic_fx( #else fracb = round_fx( L_shl( curr_res_nrg, expb ) ); #endif - expb = sub( 30, expb + ( 2 * st_fx->Q_exc ) ); + expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); fracb = shl( fracb, scale ); @@ -387,12 +393,14 @@ ivas_error decod_gen_voic_fx( enratio = div_s( fracb, fraca ); exp1 = sub( expb, expa ); - Qenratio = 15 - exp1; + Qenratio = sub( 15, exp1 ); } ELSE { enratio = 0; + move16(); Qenratio = 0; + move16(); } /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ @@ -400,7 +408,7 @@ ivas_error decod_gen_voic_fx( { expa = norm_l( prev_spch_nrg ); fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); - expa = sub( 30, expa + ( 2 * st_fx->prev_Q_syn_fr ) ); + expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); #ifdef BASOP_NOGLOB @@ -408,7 +416,7 @@ ivas_error decod_gen_voic_fx( #else fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); #endif - expb = sub( 30, expb + ( 2 * st_fx->Q_syn ) ); + expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); fracb = shl( fracb, scale ); @@ -416,12 +424,14 @@ ivas_error decod_gen_voic_fx( sp_enratio = div_s( fracb, fraca ); exp1 = sub( expb, expa ); - Qsp_enratio = 15 - exp1; + Qsp_enratio = sub( 15, exp1 ); } ELSE { sp_enratio = 0; + move16(); Qsp_enratio = 0; + move16(); } test(); @@ -429,11 +439,11 @@ ivas_error decod_gen_voic_fx( test(); test(); #ifdef BASOP_NOGLOB - IF( GT_16( shl_ro( enratio, 15 - Qenratio, &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ - LT_16( shl_ro( enratio, 10 - Qenratio, &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ - GT_16( shl_ro( sp_enratio, 15 - Qsp_enratio, &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ - st_fx->bfi_pitch_fx < 9600 && /*Q6*/ - pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ + IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ + LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ + GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ + LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ + LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -474,7 +484,7 @@ ivas_error decod_gen_voic_fx( /* update bwe_exc for SWB-TBE */ FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) { - interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + ( i_subfr_fx * 2 ), L_SUBFR ); + interp_code_4over2_fx( exc_fx + i_subfr_fx, bwe_exc_fx + shl( i_subfr_fx, 1 ), L_SUBFR ); } count_free( PREVP ); @@ -725,11 +735,11 @@ ivas_error decod_gen_voic_ivas_fx( IF( gain_preQ_fx != 0 ) { - if ( st_fx->element_mode == EVS_MONO ) + IF( st_fx->element_mode == EVS_MONO ) { tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); } - else + ELSE { tmp1_fx = add( 15 - Q_AVQ_OUT - 2, st_fx->Q_exc ); } @@ -782,8 +792,15 @@ ivas_error decod_gen_voic_ivas_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, st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate);*/ + + Word16 idx = 0; + IF( i_subfr_fx != 0 ) + { + idx = idiv1616( i_subfr_fx, L_SUBFR ); + } + prep_tbe_exc_ivas_fx( L_frame, L_SUBFR, 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, + &voice_factors_fx[idx], bwe_exc_fx, gain_preQ_fx, code_preQ_fx, st_fx->Q_exc, T0_fx, T0_frac_fx, st_fx->coder_type, st_fx->core_brate, st_fx->element_mode, st_fx->idchan, st_fx->hBWE_TD != NULL, st_fx->tdm_LRTD_flag ); @@ -806,7 +823,7 @@ ivas_error decod_gen_voic_ivas_fx( p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - gain_buf[i_subfr_fx / L_SUBFR] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; move16(); } @@ -867,11 +884,11 @@ ivas_error decod_gen_voic_ivas_fx( { expa = norm_l( prev_res_nrg ); fraca = extract_h( L_shl( prev_res_nrg, expa ) ); - expa = sub( 30, expa + ( 2 * st_fx->prev_Q_exc_fr ) ); + expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) ); expb = norm_l( curr_res_nrg ); fracb = round_fx( L_shl( curr_res_nrg, expb ) ); - expb = sub( 30, expb + ( 2 * st_fx->Q_exc ) ); + expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); fracb = shl( fracb, scale ); @@ -879,12 +896,14 @@ ivas_error decod_gen_voic_ivas_fx( enratio = div_s( fracb, fraca ); exp1 = sub( expb, expa ); - Qenratio = 15 - exp1; + Qenratio = sub( 15, exp1 ); } ELSE { enratio = 0; + move16(); Qenratio = 0; + move16(); } /* sp_enratio = curr_spch_nrg/prev_spch_nrg */ @@ -892,11 +911,11 @@ ivas_error decod_gen_voic_ivas_fx( { expa = norm_l( prev_spch_nrg ); fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); - expa = sub( 30, expa + ( 2 * st_fx->prev_Q_syn_fr ) ); + expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); - expb = sub( 30, expb + ( 2 * st_fx->Q_syn ) ); + expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); fracb = shl( fracb, scale ); @@ -904,12 +923,14 @@ ivas_error decod_gen_voic_ivas_fx( sp_enratio = div_s( fracb, fraca ); exp1 = sub( expb, expa ); - Qsp_enratio = 15 - exp1; + Qsp_enratio = sub( 15, exp1 ); } ELSE { sp_enratio = 0; + move16(); Qsp_enratio = 0; + move16(); } test(); @@ -917,11 +938,11 @@ ivas_error decod_gen_voic_ivas_fx( test(); test(); #ifdef BASOP_NOGLOB - IF( GT_16( shl_ro( enratio, 15 - Qenratio, &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ - LT_16( shl_ro( enratio, 10 - Qenratio, &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ - GT_16( shl_ro( sp_enratio, 15 - Qsp_enratio, &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ - st_fx->bfi_pitch_fx < 9600 && /*Q6*/ - pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ + IF( GT_16( shl_ro( enratio, sub( 15, Qenratio ), &Overflow ), 8192 ) && /*compare with 0.25 in Q15*/ + LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ + GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ + LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ + LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -950,7 +971,7 @@ ivas_error decod_gen_voic_ivas_fx( ph_offset_fx = 0; move16(); - if ( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) + IF( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/decision_matrix_dec_fx.c b/lib_dec/decision_matrix_dec_fx.c index a2b1108a8..8c9a12b69 100644 --- a/lib_dec/decision_matrix_dec_fx.c +++ b/lib_dec/decision_matrix_dec_fx.c @@ -47,7 +47,7 @@ void decision_matrix_dec_fx( st->igf = 0; move16(); - if ( GT_32( st->total_brate, ACELP_8k00 ) ) + IF( GT_32( st->total_brate, ACELP_8k00 ) ) { st->vbr_hw_BWE_disable_dec = 0; move16(); @@ -78,7 +78,7 @@ void decision_matrix_dec_fx( move16(); tmp16 = get_next_indice( st, 1 ); - if ( EQ_16( tmp16, 1 ) ) + IF( EQ_16( tmp16, 1 ) ) { st->L_frame = L_FRAME16k; move16(); @@ -93,7 +93,7 @@ void decision_matrix_dec_fx( st->L_frame = L_FRAME16k; move16(); - if ( tmp16 == 0 ) + IF( tmp16 == 0 ) { st->L_frame = L_FRAME; move16(); @@ -102,7 +102,7 @@ void decision_matrix_dec_fx( } test(); - if ( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) + IF( GE_32( st->output_Fs, 32000 ) && GE_16( st->bwidth, SWB ) ) { st->extl = SWB_CNG; move16(); @@ -111,7 +111,7 @@ void decision_matrix_dec_fx( test(); test(); test(); - if ( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) + IF( EQ_32( st->total_brate, FRAME_NO_DATA ) && st->prev_bfi && !st->bfi && GT_16( st->L_frame, L_FRAME16k ) ) { st->L_frame = st->last_CNG_L_frame; move16(); @@ -206,7 +206,7 @@ void decision_matrix_dec_fx( st->core = HQ_CORE; move16(); - if ( temp_core == 0 ) + IF( temp_core == 0 ) { st->core = ACELP_CORE; move16(); @@ -244,10 +244,10 @@ void decision_matrix_dec_fx( start_idx = add( start_idx, 1 ); start_idx = add( start_idx, get_next_indice( st, nBits ) ); - IF( start_idx >= MAX_ACELP_SIG ) + IF( GE_16( start_idx, MAX_ACELP_SIG ) ) { ind = 0; - move16(); + move32(); st->BER_detect = 1; move16(); } @@ -255,6 +255,7 @@ void decision_matrix_dec_fx( { /* retrieve the signaling indice */ ind = acelp_sig_tbl[start_idx]; + move32(); /* convert signaling indice into signaling information */ st->coder_type = extract_l( L_and( ind, 0x7L ) ); @@ -262,7 +263,7 @@ void decision_matrix_dec_fx( { st->core = HQ_CORE; move16(); - st->bwidth = extract_l( L_shr( ind, 3 ) & 0x7L ); + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7L ) ); } ELSE { @@ -412,7 +413,7 @@ void decision_matrix_dec_fx( test(); IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->bwidth, WB ) && LT_32( st->total_brate, ACELP_9k60 ) ) { - if ( st->vbr_hw_BWE_disable_dec == 0 ) + IF( st->vbr_hw_BWE_disable_dec == 0 ) { st->extl = WB_BWE; move16(); @@ -443,7 +444,7 @@ void decision_matrix_dec_fx( { st->extl = SWB_BWE_HIGHRATE; move16(); - if ( EQ_16( st->bwidth, FB ) ) + IF( EQ_16( st->bwidth, FB ) ) { st->extl = FB_BWE_HIGHRATE; move16(); @@ -470,7 +471,7 @@ void decision_matrix_dec_fx( move16(); st->extl_brate = SWB_TBE_1k6; move32(); - if ( GE_32( st->total_brate, ACELP_24k40 ) ) + IF( GE_32( st->total_brate, ACELP_24k40 ) ) { st->extl_brate = SWB_TBE_2k8; move32(); @@ -530,7 +531,7 @@ void decision_matrix_dec_fx( st->last_L_frame = L_FRAME16k; move16(); tmp16 = get_next_indice( st, 1 ); - if ( tmp16 == 0 ) + IF( tmp16 == 0 ) { st->last_L_frame = L_FRAME; move16(); @@ -669,7 +670,7 @@ void decision_matrix_dec_fx( st->nb_subfr = NB_SUBFR; move16(); - if ( EQ_16( st->L_frame, L_FRAME16k ) ) + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { st->nb_subfr = NB_SUBFR16k; move16(); diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index e3fceb149..100a6b207 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -92,23 +92,22 @@ void con_acelp_fx( const Word16 scale_h1 = 5; HQ_DEC_HANDLE hHQ_core; TCX_DEC_HANDLE hTcxDec; + move16(); hHQ_core = st->hHQ_core; hTcxDec = st->hTcxDec; /*Inits*/ - move16(); l_fir_fer = L_FIR_FER; + move16(); fUseExtrapolatedPitch = 0; move16(); extrapolationFailed = 1; move16(); - move16(); - move16(); - move16(); alpha = 0; + move16(); /*st->Mode2_lp_gainc = L_shl(st->Mode2_lp_gainc,7);*/ /*rudiment, could be changed in the whole file but should work also*/ pc = L_deposit_l( 0 ); @@ -130,7 +129,7 @@ void con_acelp_fx( * PLC: [ACELP:Extrapolate Pitch Lag] *------------------------------------------------------------------------*/ - if ( EQ_16( st->flagGuidedAcelp, 1 ) ) + IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { T0 = st->guidedT0; move16(); @@ -143,13 +142,13 @@ void con_acelp_fx( st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); T0 = round_fx( predPitchLag ); - IF( extrapolationFailed != 0 ) + IF( NE_16( extrapolationFailed, 0 ) ) { /*------------------------------------------------------------------------* * - Construct adaptive codebook from side information * *------------------------------------------------------------------------*/ - IF( st->flagGuidedAcelp == 0 ) + IF( EQ_16( st->flagGuidedAcelp, 0 ) ) { nSubframes = 0; move16(); @@ -174,8 +173,8 @@ void con_acelp_fx( } tmp_tc = st->old_fpitch; - move16(); /* take the previous frame last pitch*/ - if ( nSubframes > 0 ) + move32(); /* take the previous frame last pitch*/ + IF( GT_16( nSubframes, 0 ) ) { tmp_tc = L_deposit_h( st->guidedT0 ); /* take the transmit pitch*/ } @@ -184,9 +183,10 @@ void con_acelp_fx( * PLC: calculate damping factor */ alpha = Damping_fact_fx( coder_type, st->nbLostCmpt, st->last_good, stab_fac, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ st->cummulative_damping = shl( mult( st->cummulative_damping, alpha ), 1 ); /*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ - if ( EQ_16( st->nbLostCmpt, 1 ) ) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { st->cummulative_damping = 32767 /*1.f Q15*/; /*Q15*/ + move16(); } /*-----------------------------------------------------------------* @@ -212,20 +212,20 @@ void con_acelp_fx( test(); test(); test(); - if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( tmp < 0 ) && extrapolationFailed == 0 ) + IF( GT_16( T0, 0 ) && ( NE_16( T0, Tc ) ) && LT_16( tmp, 0 ) && EQ_16( extrapolationFailed, 0 ) ) { fUseExtrapolatedPitch = 1; move16(); } pt_exc = exc; - if ( st->enableGplc != 0 ) + IF( NE_16( st->enableGplc, 0 ) ) { - pt_exc = &exc[nSubframes * L_SUBFR]; + pt_exc = &exc[imult1616( nSubframes, L_SUBFR )]; } pt1_exc = pt_exc - Tc; - IF( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { /* Required because later pt1_exc[1] used in filtering points to exc[0]. To make it safe also for GPL pt_exc is used instead of exc */ pt_exc[0] = 0; @@ -252,8 +252,8 @@ void con_acelp_fx( tmp_32 = L_mult( lpFiltAdapt[0], pt1_exc[-1] ); tmp_32 = L_mac( tmp_32, lpFiltAdapt[1], pt1_exc[0] ); tmp_16 = mac_r( tmp_32, lpFiltAdapt[2], pt1_exc[1] ); - move16(); *pt_exc = tmp_16; + move16(); pt_exc++; pt1_exc++; } @@ -263,12 +263,12 @@ void con_acelp_fx( /* copy the first pitch cycle without low-pass filtering */ FOR( i = 0; i < Tc; i++ ) { - move16(); *pt_exc++ = *pt1_exc++; + move16(); } } - if ( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { pt1_exc = harmonic_exc_buf; } @@ -276,8 +276,8 @@ void con_acelp_fx( l = add( st->L_frame, sub( imult1616( L_SUBFR, sub( 1, nSubframes ) ), Tc ) ); FOR( i = 0; i < l; i++ ) { - move16(); *pt_exc++ = *pt1_exc++; + move16(); } /*-------------------------------------------------------* @@ -285,29 +285,29 @@ void con_acelp_fx( * PLC: Resync pulse positions. *-------------------------------------------------------*/ - IF( nSubframes > 0 ) + IF( GT_16( nSubframes, 0 ) ) { - move16(); - move16(); pitch_buf[0] = L_deposit_h( st->guidedT0 ); + move32(); pitch_buf[1] = L_deposit_h( st->guidedT0 ); + move32(); } - IF( nSubframes > 0 ) + IF( GT_16( nSubframes, 0 ) ) { - move16(); - move16(); pitch_buf[3] = pitch_buf[2] = pitch_buf[1]; /* do not resync on second half of frame */ - if ( EQ_16( st->nb_subfr, 5 ) ) + move32(); + move32(); + IF( EQ_16( st->nb_subfr, 5 ) ) { /* for guided acelp cases and nSubframes=2, set pitch_buf[4] to avoid memory_access issues in post_decoder() */ pitch_buf[4] = pitch_buf[3]; - move16(); + move32(); } } ELSE { - IF( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { get_subframe_pitch( st->nb_subfr, st->old_fpitch, predPitchLag, pitch_buf ); @@ -325,7 +325,7 @@ void con_acelp_fx( *------------------------------------------------------------*/ pt_exc = exc + st->L_frame; pt1_exc = pt_exc - T0; - if ( T0 == 0 ) + IF( EQ_16( T0, 0 ) ) { pt1_exc = pt_exc - Tc; } @@ -341,11 +341,11 @@ void con_acelp_fx( * PLC: update the floating point pitch for consecutive loss *-------------------------------------------------------*/ - IF( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { - move32(); st->old_fpitch = predPitchLag; - if ( EQ_16( st->flagGuidedAcelp, 1 ) ) + move32(); + IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { st->old_fpitch = L_deposit_h( T0 ); } @@ -384,12 +384,14 @@ void con_acelp_fx( } ELSE { - gain = 0x4000 /*1 (1Q14)*/; /* start-of-the-frame gain */ + gain = 0x4000 /*1 (1Q14)*/; /* start-of-the-frame gain */ + move16(); st->Mode2_lp_gainp = L_shl( L_deposit_l( alpha ), 15 ); /*1Q14->2Q29*/ } tmp_16 = extract_l( L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 ) ); tmp_16 = T_DIV_L_Frame[tmp_16]; + move16(); tmp_32 = L_mult0( tmp_16, sub( gain, alpha ) ); /* 0Q15 * 2^-7 * 1Q14 -> 2Q29 * 2^-7*/ tmp_32 = L_shr( tmp_32, 6 ); /*-> 1Q30*/ step = round_fx( tmp_32 ); /*->1Q14*/ @@ -415,7 +417,6 @@ void con_acelp_fx( l = add( l, L_SUBFR ); FOR( ; i < l; i++ ) { - move16(); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ @@ -423,6 +424,7 @@ void con_acelp_fx( exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may be 1 after shift*/ #endif BASOP_SATURATE_WARNING_ON_EVS + move16(); gain = sub( gain, step ); } } @@ -430,7 +432,6 @@ void con_acelp_fx( l = add( st->L_frame, shr( st->L_frame, 1 ) ); FOR( ; i < l; i++ ) { - move16(); BASOP_SATURATE_WARNING_OFF_EVS #ifdef BASOP_NOGLOB exc[i] = mult_r( exc[i], shl_sat( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ @@ -438,13 +439,16 @@ void con_acelp_fx( exc[i] = mult_r( exc[i], shl( gain, 1 ) ); /*overflow is first iteration because gain may become 1 due to shift*/ #endif BASOP_SATURATE_WARNING_ON_EVS + move16(); gain = sub( gain, step ); } FOR( i = 0; i < st->nb_subfr; i++ ) { pT[i] = round_fx( pitch_buf[i] ); /*Q0*/ + move16(); pitch_buffer[i] = round_fx( pitch_buf[i] ); + move16(); } /* update old exc without random part*/ @@ -459,6 +463,7 @@ void con_acelp_fx( FOR( i = 0; i < st->nb_subfr; i++ ) { pitch_buf[i] = L_deposit_h( st->pit_max ); /*15Q16*/ + move32(); pgainT[i] = 0; move16(); pT[i] = L_SUBFR; @@ -480,7 +485,6 @@ void con_acelp_fx( * search for "Scale from randomized buffer to excitation buffer" *-----------------------------------------------------------------*/ noise_buf = buf; - move16(); tmpSeed = st->seed_acelp; move16(); l = add( st->L_frame, sub( l_fir_fer, 1 ) ); @@ -514,6 +518,7 @@ void con_acelp_fx( tmp = 32767 /*1.0f Q15*/; + move16(); gainSynthDeemph = getLevelSynDeemph_fx( &( tmp ), A, M, @@ -526,14 +531,14 @@ void con_acelp_fx( /*gainCNG=st->cngTDLevel/gainSynthDeemph;*/ BASOP_Util_Divide_MantExp( st->cngTDLevel, st->cngTDLevel_e, gainSynthDeemph, gainSynthDeemph_e, &gainCNG, &gainCNG_e ); gainCNG_e = sub( gainCNG_e, 15 - 5 ); /*Q15->Q5*/ - if ( gainCNG == 0 ) + IF( EQ_16( gainCNG, 0 ) ) { gainCNG_e = 0; move16(); } gain_32 = st->Mode2_lp_gainc; /*15Q16 */ /* start-of-the-frame gain */ - move16(); + move32(); #ifdef BASOP_NOGLOB ftmp = round_fx_sat( L_shl_sat( gain_32, 1 ) ); /*Q0*/ @@ -549,20 +554,22 @@ void con_acelp_fx( /*in case of overflow:*/ test(); #ifdef BASOP_NOGLOB - if ( ( EQ_16( shl_sat( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && ( gainCNG == MAXVAL_WORD16 ) ) + IF( ( EQ_16( shl_sat( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && EQ_16( gainCNG, MAXVAL_WORD16 ) ) #else - if ( ( EQ_16( shl( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && ( gainCNG == MAXVAL_WORD16 ) ) + IF( ( EQ_16( shl( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && EQ_16( gainCNG, MAXVAL_WORD16 ) ) #endif { - move16(); tmp_16 = 1; + move16(); } BASOP_SATURATE_WARNING_ON_EVS - IF( tmp_16 > 0 ) + IF( GT_16( tmp_16, 0 ) ) { gainCNG = ftmp /*Q0*/; + move16(); gainCNG_e = 5; /*-> Q5*/ + move16(); s_16 = norm_s( gainCNG ); gainCNG = shl( gainCNG, s_16 ); gainCNG_e = sub( gainCNG_e, s_16 ); @@ -595,7 +602,7 @@ void con_acelp_fx( highPassFiltering_fx( st->last_good, add( st->L_frame, shr( l_fir_fer, 1 ) ), noise_buf, hp_filt, l_fir_fer ); - pt_exc = noise_buf + l_fir_fer / 2; + pt_exc = noise_buf + shr( l_fir_fer, 1 ); /*** Find energy normalization factor ***/ /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, st->L_frame ) / st->L_frame );*/ /* normalize energy */ /*<--- FLC*/ @@ -607,20 +614,24 @@ void con_acelp_fx( /*scalingfactor is twice the headroom (at noise insertion onto the buffer), -1 (because of mult) +31 (Result is Q31) +s_32 (output scalingfactor of dot_product)*/ tmp_16 = T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )]; + move16(); tmp_32 = Mpy_32_16_1( tmp_32, tmp_16 ); /* Q31 * 2^s_32 * 0Q15 * 2^-7 */ s_32 = sub( s_32, 7 ); /*tmp_32 is Q31 * 2^s_32 */ /*assure doing Isqrt not for 0*/ - IF( tmp_32 != 0 ) + IF( NE_32( tmp_32, 0 ) ) { s_gain_inov = s_32; + move16(); tmp_32 = ISqrt32( tmp_32, &s_gain_inov ); } ELSE { s_gain_inov = 0; + move16(); tmp_32 = 0; + move16(); } @@ -635,7 +646,7 @@ void con_acelp_fx( step_32 = L_shr( step_32, 7 ); /* 15Q16 */ test(); - if ( ( EQ_16( st->last_good, UNVOICED_CLAS ) ) && ( NE_16( coder_type, UNVOICED ) ) ) /* Attenuate somewhat on unstable unvoiced */ + IF( ( EQ_16( st->last_good, UNVOICED_CLAS ) ) && ( NE_16( coder_type, UNVOICED ) ) ) /* Attenuate somewhat on unstable unvoiced */ { gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q15 * 2^s_gain_inov*/ } @@ -698,7 +709,7 @@ void con_acelp_fx( gain_16 = round_fx( gain_32 ); } - l = add( shr( st->L_frame, 1 ), l_fir_fer / 2 ); + l = add( shr( st->L_frame, 1 ), shr( l_fir_fer, 1 ) ); FOR( i = 0; i < l; i++ ) { /* *pt_exc++ *= (gain_inov * gain); <=> *pt_exc++ *= gain_16; */ /*<-- FLC*/ @@ -710,23 +721,23 @@ void con_acelp_fx( /*store st->past_gcode*/ /* at this point gain is equal to st->Mode2_lp_gainc, so we don't need to calculate gain at all */ st->past_gcode = st->Mode2_lp_gainc; /*15Q16 */ - move16(); + move32(); /*-----------------------------------------------------------------* * PLC: [ACELP: general] * PLC: Construct the total excitation *-----------------------------------------------------------------*/ - IF( st->last_good < UNVOICED_TRANSITION ) + IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { - bufferCopyFx( noise_buf + l_fir_fer / 2, exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ + bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ Copy( harmonic_exc_buf + st->L_frame, st->old_exc_fx, L_EXC_MEM_DEC ); Copy( exc, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ) ); /* Update exc_unv */ } ELSE { /* Update exc_unv */ - bufferCopyFx( noise_buf + l_fir_fer / 2, exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ + bufferCopyFx( noise_buf + shr( l_fir_fer, 1 ), exc_unv, add( st->L_frame, shr( st->L_frame, 1 ) ), 0, *Qf_exc, negate( g_e ), 0 ); /*copy between different formats*/ } /* Compute total excitation in noisebuffer to save memories */ @@ -761,7 +772,7 @@ void con_acelp_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { - IF( st->last_good < UNVOICED_TRANSITION ) + IF( LT_16( st->last_good, UNVOICED_TRANSITION ) ) { Copy( st->mem_syn2_fx, mem_syn_unv, M ); } @@ -776,7 +787,7 @@ void con_acelp_fx( } /* voiced synth */ - IF( st->last_good >= UNVOICED_TRANSITION ) + IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { p_A = A; FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) @@ -791,12 +802,15 @@ void con_acelp_fx( deemph_fx( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ + /* i_subfr / L_SUBFR */ + tmp_16 = shr( i_subfr, Q6 ); /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[i_subfr / L_SUBFR] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); tmp_32 = L_max( tmp_32, 1 ); - gain_lpc_e[i_subfr / L_SUBFR] = add( gain_lpc_e[i_subfr / L_SUBFR], 2 * scale_h1 ); + gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); + move16(); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); move16(); - gain_lpc[i_subfr / L_SUBFR] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[i_subfr / L_SUBFR] ) ); p_A += ( M + 1 ); /* Pointer move */ } @@ -805,20 +819,21 @@ void con_acelp_fx( move16(); FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - - g = mult_r( st->last_gain_syn_deemph, gain_lpc[i_subfr / L_SUBFR] ); + /* i_subfr / L_SUBFR */ + tmp_16 = shr( i_subfr, Q6 ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); #ifdef BASOP_NOGLOB - g_e = add_sat( st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr / L_SUBFR] ); + g_e = add_sat( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); g = shl_sat( g, g_e ); #else - g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr / L_SUBFR] ); + g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); g = shl( g, g_e ); #endif FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc[i_subfr + i] = mult_r( exc[i_subfr + i], g ); + exc[i_subfr + i] = mult_r( exc[add( i_subfr, i )], g ); move16(); } } @@ -843,18 +858,16 @@ void con_acelp_fx( memsynPrecission_fx( st->nbLostCmpt, mem_syn, exc, st->L_frame, &s_16 ); FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - - E_UTIL_synthesis( synthScaling, p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); - p_A += ( M + 1 ); + p_A = p_A + add( M, 1 ); } Copy( mem_syn, mem_syn2, M ); /* synthesize ola*/ - E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc[i_subfr], &syn[i_subfr], ( st->L_frame / 2 ), mem_syn2, 0, M ); + E_UTIL_synthesis( synthScaling, p_A - add( M, 1 ), &exc[i_subfr], &syn[i_subfr], shr( st->L_frame, 1 ), mem_syn2, 0, M ); } test(); - IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) + IF( GT_16( st->nbLostCmpt, 5 ) && GT_16( s_16, 0 ) ) { /*scale back mem_syn, exc and synthesis*/ Scale_sig( mem_syn, M, negate( s_16 ) ); @@ -879,12 +892,15 @@ void con_acelp_fx( deemph_fx( h1, st->preemph_fac, L_SUBFR, &tmp ); /* impulse response of deemph */ /* impulse response level = gain introduced by synthesis+deemphasis */ + /* i_subfr / L_SUBFR */ + tmp_16 = shr( i_subfr, Q6 ); /* gain_lpc[i_subfr/L_SUBFR] = 1.f/(float)sqrt(dotp( h1, h1, L_SUBFR)); */ - tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[i_subfr / L_SUBFR] ); + tmp_32 = Dot_productSq16HQ( 0, h1, L_SUBFR, &gain_lpc_e[tmp_16] ); tmp_32 = L_max( tmp_32, 1 ); - gain_lpc_e[i_subfr / L_SUBFR] = add( gain_lpc_e[i_subfr / L_SUBFR], 2 * scale_h1 ); + gain_lpc_e[tmp_16] = add( gain_lpc_e[tmp_16], shl( scale_h1, 1 ) ); + move16(); + gain_lpc[tmp_16] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[tmp_16] ) ); move16(); - gain_lpc[i_subfr / L_SUBFR] = round_fx( ISqrt32( tmp_32, &gain_lpc_e[i_subfr / L_SUBFR] ) ); p_A += ( M + 1 ); /* Pointer move */ } @@ -893,8 +909,10 @@ void con_acelp_fx( move16(); FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { - g = mult_r( st->last_gain_syn_deemph, gain_lpc[i_subfr / L_SUBFR] ); - g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[i_subfr / L_SUBFR] ); + /* i_subfr / L_SUBFR */ + tmp_16 = shr( i_subfr, Q6 ); + g = mult_r( st->last_gain_syn_deemph, gain_lpc[tmp_16] ); + g_e = add( st->last_gain_syn_deemph_e, gain_lpc_e[tmp_16] ); #ifdef BASOP_NOGLOB g = shl_sat( g, g_e ); #else @@ -903,7 +921,7 @@ void con_acelp_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* exc[i_subfr + i] *= st->last_gain_syn_deemph*gain_lpc[j]; */ - exc_unv[i_subfr + i] = mult_r( exc_unv[i_subfr + i], g ); + exc_unv[add( i_subfr, i )] = mult_r( exc_unv[add( i_subfr, i )], g ); move16(); } } @@ -922,6 +940,7 @@ void con_acelp_fx( rescale_mem( Qf_exc, &Qf_syn_new, &Qf_syn, mem_syn_unv, NULL, M, st->L_frame ); synthScaling = sub( *Qf_exc, Qf_syn ); *Qf_mem_syn = Qf_syn; + move16(); p_A = st->Aq_cng; @@ -931,7 +950,7 @@ void con_acelp_fx( FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { E_UTIL_synthesis( synthScaling, p_A, &exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1, M ); - p_A += ( M + 1 ); + p_A = p_A + add( M, 1 ); } Copy( mem_syn_unv, st->mem_syn_unv_back, M ); @@ -939,11 +958,11 @@ void con_acelp_fx( { Copy( mem_syn_unv, mem_syn, M ); /* unvoiced for ola */ - E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc_unv[i_subfr], &syn_unv[i_subfr], shr( st->L_frame, 1 ), mem_syn_unv, 0, M ); + E_UTIL_synthesis( synthScaling, p_A - add( M, 1 ), &exc_unv[i_subfr], &syn_unv[i_subfr], shr( st->L_frame, 1 ), mem_syn_unv, 0, M ); } test(); - IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) + IF( GT_16( st->nbLostCmpt, 5 ) && GT_16( s_16, 0 ) ) { /*scale back mem_syn_unv, exc_unv and synthesis*/ Scale_sig( mem_syn_unv, M, negate( s_16 ) ); @@ -988,6 +1007,7 @@ void con_acelp_fx( FOR( k = 0; k < st->nb_subfr; k++ ) { pit16[k] = shl( extract_h( pitch_buf[k] ), 6 ); /*Q6*/ + move16(); } FEC_clas_estim_fx( @@ -1037,19 +1057,20 @@ void con_acelp_fx( /*Q_mem_syn_new = Q_mem_syn;*/ /*NOT "+synthScaling", cause mem_syn format is not changed*/ /* Deemphasis and output synth */ tmp_deemph = st->syn[M]; + move16(); E_UTIL_deemph2( *Qf_mem_syn, syn, st->preemph_fac, add( st->L_frame, shr( st->L_frame, 1 ) ), &tmp_deemph ); Copy( syn, synth, st->L_frame ); - bufferCopyFx( syn + st->L_frame - st->L_frame / 2, hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); + bufferCopyFx( syn + sub( st->L_frame, shr( st->L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 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, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); - Copy( syn + st->L_frame - M - 1, st->syn, add( 1, M ) ); + Copy( syn + sub( st->L_frame, sub( 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( p_A - add( M, 1 ), st->old_Aq_12_8_fx, add( M, 1 ) ); Copy( syn + st->L_frame, hTcxDec->syn_Overl, shr( st->L_frame, 1 ) ); @@ -1064,59 +1085,62 @@ void con_acelp_fx( n = extract_h( L_mult( st->L_frame, 9216 /*(float)N_ZERO_MDCT_NS/(float)FRAME_SIZE_NS Q15*/ ) ); - hHQ_core->Q_old_wtda_LB = getScaleFactor16( syn + st->L_frame - n, + hHQ_core->Q_old_wtda_LB = getScaleFactor16( syn + sub( st->L_frame, n ), sub( st->L_frame, n ) ); move16(); - bufferCopyFx( syn + st->L_frame - n, hHQ_core->old_out_LB_fx, sub( st->L_frame, n ), 0, 0, hHQ_core->Q_old_wtda_LB, 0 ); + bufferCopyFx( syn + sub( st->L_frame, n ), hHQ_core->old_out_LB_fx, sub( st->L_frame, n ), 0, 0, hHQ_core->Q_old_wtda_LB, 0 ); FOR( i = 0; i < W2; i++ ) { - 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] ) ); + hHQ_core->old_out_LB_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + move16(); } FOR( ; i < W1; i++ ) { - 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] ) ); + hHQ_core->old_out_LB_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, sub( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, sub( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + move16(); } - set16_fx( &hHQ_core->old_out_LB_fx[W1 + n], 0, n ); + set16_fx( &hHQ_core->old_out_LB_fx[add( W1, n )], 0, n ); hHQ_core->Q_old_wtda = hHQ_core->Q_old_wtda_LB; + move16(); FOR( i = 0; i < W2; i++ ) { - move16(); buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); + move16(); } FOR( ; i < W1; i++ ) { + buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); move16(); - buf[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[W1 - 1 - i].v.im ); } FOR( i = 0; i < W2; i++ ) { + hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); /* A-D */ move16(); - hTcxDec->syn_Overl_TDAC[i] = add( buf[i], buf[W1 - 1 - i] ); /* A-D */ } /*-2*/ FOR( i = 0; i < W2; i++ ) { + hTcxDec->syn_Overl_TDAC[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); /* B-C */ move16(); - hTcxDec->syn_Overl_TDAC[W2 + i] = add( buf[W2 + i], buf[W1 - 1 - W2 - i] ); /* B-C */ } FOR( i = 0; i < W2; i++ ) { - move16(); hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[i].v.re ); + move16(); } FOR( ; i < W1; i++ ) { + hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[sub( sub( W1, 1 ), i )].v.im ); move16(); - hTcxDec->syn_Overl_TDAC[i] = mult_r( hTcxDec->syn_Overl_TDAC[i], w[W1 - 1 - i].v.im ); } /* update memory for full band */ @@ -1130,8 +1154,7 @@ void con_acelp_fx( lerp( exc, st->hWIDec->old_exc2_fx, L_EXC_MEM, st->L_frame ); lerp( syn, st->hWIDec->old_syn2_fx, L_EXC_MEM, st->L_frame ); } - st->bfi_pitch_fx = shl( round_fx( pitch_buf[st->nb_subfr - 1] ), 6 ); - move16(); + st->bfi_pitch_fx = shl( round_fx( pitch_buf[sub( st->nb_subfr, 1 )] ), 6 ); st->bfi_pitch_frame = st->L_frame; move16(); @@ -1163,7 +1186,7 @@ static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc BASOP_SATURATE_WARNING_ON_EVS } /*if there is energy in scale_syn, then increase precision*/ - IF( abs_s( tmp ) > 0 ) + IF( GT_16( abs_s( tmp ), 0 ) ) { sf_mem_syn = getScaleFactor16( mem_syn, M ); /*sf_exc = getScaleFactor16(exc, add(shr(len,1),len));*/ /*this returns 0 if signal is 0*/ @@ -1173,12 +1196,11 @@ static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc max = s_max( max, abs_s( exc[k] ) ); } sf_exc = norm_s( max ); - if ( max == 0 ) + IF( EQ_16( max, 0 ) ) { sf_exc = 16; move16(); } - move16(); *s_16 = s_max( sub( s_min( sf_exc, sf_mem_syn ), 5 ), 0 ) /*5 bits of headroom, scaling not smaller than 0*/; Scale_sig( mem_syn, M, *s_16 ); Scale_sig( exc, add( shr( len, 1 ), len ), *s_16 ); diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 312049e70..e51721c82 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -29,7 +29,9 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L L_acc = L_deposit_l( 0 ); L_c = L_deposit_l( 0 ); Overflow = 0; + move16(); Carry = 0; + move16(); tmp16 = round_fx( old_fpitch ); /*Q0*/ tmp_loop = shl( L_subfr, 1 ); @@ -46,29 +48,31 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L /*st->lp_gainc += ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] ) * ( exc[i-2*L_subfr] - st->Mode2_lp_gainp * exc[i-2*L_subfr-(int)(st->old_fpitch+0.5f)] );*/ #ifdef BASOP_NOGLOB - tmp16_3 = sub_o( exc[i - 2 * L_subfr] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[i - 2 * L_subfr - tmp16] /*Q1*/ ) /*Q1*/, &Overflow ); + tmp16_3 = sub_o( exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/, &Overflow ); #else - tmp16_3 = sub( exc[i - 2 * L_subfr] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[i - 2 * L_subfr - tmp16] /*Q1*/ ) /*Q1*/ ); + tmp16_3 = sub( exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, mult_r( tmp16_2 /*Q15*/, exc[sub( sub( i, shl( L_subfr, 1 ) ), tmp16 )] /*Q1*/ ) /*Q1*/ ); #endif #ifdef BASOP_NOGLOB L_acc = L_macNs_co( L_acc, tmp16_3, tmp16_3, &Carry, &Overflow ); /*Q3*/ #else - L_acc = L_macNs( L_acc, tmp16_3, tmp16_3 ); /*Q3*/ + L_acc = L_macNs( L_acc, tmp16_3, tmp16_3 ); /*Q3*/ #endif Overflow = 0; + move16(); #ifdef BASOP_NOGLOB L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /*Accumulate Carrys*/ #else - L_c = L_macNs( L_c, 0, 0 ); /*Accumulate Carrys*/ + L_c = L_macNs( L_c, 0, 0 ); /*Accumulate Carrys*/ #endif Carry = 0; + move16(); } L_tmp = norm_llQ31( L_c, L_acc, &tmp_e ); /*Q3,norm,tmp_e*/ tmp_e = add( tmp_e, 31 - ( add( shl( Q_exc, 1 ), 1 ) ) ); /*L_tmp is Q31, now*/ tmp16 = BASOP_Util_Divide3216_Scale( L_tmp /*Q31,norm,tmp_e*/, shl( L_subfr, 1 ) /*Q15,15*/, &tmp2_e ) /*Q15,tmp2_e+tmp_e-15*/; tmp_e = sub( add( tmp2_e, tmp_e ), 15 ); - IF( tmp16 != 0 ) + IF( NE_16( tmp16, 0 ) ) { tmp16 = Sqrt16( tmp16, &tmp_e ); /*Q15,norm,tmp_e*/ } @@ -83,10 +87,14 @@ static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp Flag Overflow = 0; Flag Carry = 0; #endif + move16(); + move16(); Carry = 0; + move16(); Overflow = 0; + move16(); L_c = L_deposit_l( 0 ); L_acc = L_deposit_l( 0 ); @@ -96,22 +104,24 @@ static void calcGainc2_fx( Word16 *exc, Word16 Q_exc, Word16 L_subfr, Word32 *lp FOR( i = 0; i < cnt; i++ ) { /* *gainc += ( exc[i-2*L_subfr] ) * ( exc[i-2*L_subfr]); */ -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ - L_acc = L_macNs_co( L_acc, exc[i - 2 * L_subfr] /*Q1*/, exc[i - 2 * L_subfr] /*Q1*/, &Carry, &Overflow ); /*Q3*/ +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ + L_acc = L_macNs_co( L_acc, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, &Carry, &Overflow ); /*Q3*/ #else - L_acc = L_macNs( L_acc, exc[i - 2 * L_subfr] /*Q1*/, exc[i - 2 * L_subfr] /*Q1*/ ); /*Q3*/ + L_acc = L_macNs( L_acc, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/, exc[sub( i, shl( L_subfr, 1 ) )] /*Q1*/ ); /*Q3*/ #endif Overflow = 0; + move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); /* Accumulate Carrys */ #else - L_c = L_macNs( L_c, 0, 0 ); /* Accumulate Carrys */ + L_c = L_macNs( L_c, 0, 0 ); /* Accumulate Carrys */ #endif Carry = 0; + move16(); } - L_tmp = norm_llQ31( L_c, L_acc, &tmp_e ); /*Q3,norm,tmp_e*/ - tmp_e = add( tmp_e, 31 - ( add( shl( Q_exc, 1 ), 1 ) ) ); /*L_tmp is Q31, now*/ + L_tmp = norm_llQ31( L_c, L_acc, &tmp_e ); /*Q3,norm,tmp_e*/ + tmp_e = add( tmp_e, sub( 31, ( add( shl( Q_exc, 1 ), 1 ) ) ) ); /*L_tmp is Q31, now*/ tmp16 = BASOP_Util_Divide3216_Scale( L_tmp /*Q31,norm,tmp_e*/, shl( L_subfr, 1 ) /*Q15,15*/, &tmp2_e ) /*Q15,tmp2_e+tmp_e-15*/; tmp_e = sub( add( tmp2_e, tmp_e ), 15 ); @@ -223,7 +233,7 @@ void con_tcx_fx( st->L_frame, &s ); - FOR( i = 0; i < ( 2 * NB_SUBFR16k + 2 ); i++ ) + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); move32(); @@ -240,12 +250,12 @@ void con_tcx_fx( IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - 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 ); + mem = synth[sub( -( add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ) ), 1 )]; + move16(); + Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( 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 ) ); - move32(); + st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); @@ -255,7 +265,7 @@ void con_tcx_fx( ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[-L_frame - 1] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); + autocorr_fx( &( synth[sub( -L_frame, 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); @@ -272,8 +282,8 @@ void con_tcx_fx( BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ Residu3_fx( A_local, - &( synth[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx = Q0*/ - &( exc[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx+1 = Q1*/ + &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx = Q0*/ + &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx+1 = Q1*/ add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), 1 ); BASOP_SATURATE_WARNING_ON_EVS @@ -281,19 +291,20 @@ void con_tcx_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[-L_frame - 1]; + mem = synth[sub( -L_frame, 1 )]; + move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); + Copy( st->old_Aq_12_8_fx, A_local, add( M, 1 ) ); offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), offset + tmp16, Q_exc - st->Q_exc ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-2 * L_subfr] ), 2 * L_subfr + offset, Q_exc - st->Q_exc ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); } } @@ -305,7 +316,7 @@ void con_tcx_fx( test(); IF( GT_16( st->last_good, UNVOICED_CLAS ) && !( EQ_16( st->last_good, UNVOICED_TRANSITION ) && EQ_16( st->core_ext_mode, GENERIC ) ) ) { - + test(); IF( EQ_16( st->nbLostCmpt, 1 ) || hTcxDec->tcxConceal_recalc_exc ) { calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &( st->Mode2_lp_gainc ) ); @@ -313,7 +324,7 @@ void con_tcx_fx( tmp16 = 0; move16(); - if ( GT_32( st->output_Fs, 25600 ) ) + IF( GT_32( st->output_Fs, 25600 ) ) { tmp16 = 1; move16(); @@ -334,8 +345,7 @@ void con_tcx_fx( test(); test(); - test(); - if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) ) + IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -343,7 +353,6 @@ void con_tcx_fx( } ELSE { - pitch_pred_linear_fit( st->nbLostCmpt, st->last_good, @@ -362,7 +371,7 @@ void con_tcx_fx( test(); test(); test(); - if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) ) + IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) && EQ_16( extrapolationFailed, 0 ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -375,7 +384,7 @@ void con_tcx_fx( pt_exc = exc + offset; pt1_exc = pt_exc - Tc; - if ( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { pt_exc = buf; } @@ -388,7 +397,6 @@ void con_tcx_fx( { FOR( i = 0; i < Tc; i++ ) { - move16(); #ifdef BASOP_NOGLOB *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), @@ -416,6 +424,7 @@ void con_tcx_fx( 0 /* 0.0000f Q15*/, pt1_exc[4] ), 174 /* 0.0053f Q15*/, pt1_exc[5] ); #endif + move16(); pt1_exc++; } } @@ -423,7 +432,6 @@ void con_tcx_fx( { FOR( i = 0; i < Tc; i++ ) { - move16(); #ifdef BASOP_NOGLOB *pt_exc++ = mac_r_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mac_sat( L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), @@ -451,6 +459,7 @@ void con_tcx_fx( -121 /*-0.0037f Q15*/, pt1_exc[4] ), -174 /*-0.0053f Q15*/, pt1_exc[5] ); #endif + move16(); pt1_exc++; } } @@ -470,7 +479,7 @@ void con_tcx_fx( move16(); } - if ( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { pt1_exc = buf; } @@ -481,7 +490,7 @@ void con_tcx_fx( move16(); } - IF( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { get_subframe_pitch( st->nb_subfr, st->old_fpitch, @@ -504,7 +513,7 @@ void con_tcx_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { pt_exc = exc + L_frame; - IF( T0 == 0 ) + IF( EQ_16( T0, 0 ) ) { pt1_exc = pt_exc - Tc; } @@ -521,10 +530,10 @@ void con_tcx_fx( } } - if ( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { st->old_fpitchFB = predPitchLag; - move16(); + move32(); } st->bpf_gain_param = 0; move16(); @@ -560,10 +569,13 @@ void con_tcx_fx( gain32 = L_add( 2147483647l /*1.f Q31*/, 0 ); /*Q31*/ gain = 32767 /*1.f Q15*/; /*Q15*/ move16(); - if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) + test(); + IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { gain32 = 1073741824l /*0.5f Q31*/; + move32(); gain = 16384 /*0.5f Q15*/; + move16(); } /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/ @@ -590,8 +602,8 @@ void con_tcx_fx( } /* update old exc without random part */ - offset = s_max( round_fx( st->old_fpitchFB ) - shr( L_frame, 1 ), 0 ); - Copy( exc + L_frame - offset, hTcxDec->old_excFB_fx, shr( L_frame, 1 ) + offset ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -603,6 +615,7 @@ void con_tcx_fx( lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; + move16(); } ELSE { @@ -699,7 +712,7 @@ void con_tcx_fx( { tmp16 = 19661 /*0.6f Q15*/; move16(); - if ( LE_32( st->output_Fs, 16000 ) ) + IF( LE_32( st->output_Fs, 16000 ) ) { tmp16 = 6554 /*0.2f Q15*/; move16(); @@ -707,7 +720,7 @@ void con_tcx_fx( mem = noise[0]; move16(); - preemph_copy_fx( &noise[1], &noise[1], tmp16, L_frame + ( L_frame / 2 ) + L_FIR_FER2, &mem ); + preemph_copy_fx( &noise[1], &noise[1], tmp16, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), &mem ); } /* high rate filter tuning */ IF( LE_32( st->output_Fs, 16000 ) ) @@ -741,12 +754,13 @@ void con_tcx_fx( Word16 j; L_tmp2 = 0; move32(); - for ( j = 11; j > 0; j-- ) + FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[i + L_FIR_FER2 - j], hp_filt[L_FIR_FER2 - j] ); + L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); } L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ + move16(); } } } @@ -766,7 +780,7 @@ void con_tcx_fx( move16(); gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); #endif - IF( 0 != st->tcxonly ) + IF( NE_16( st->tcxonly, 0 ) ) { /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, @@ -797,7 +811,8 @@ void con_tcx_fx( } gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/ - if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) + test(); + IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); } @@ -818,9 +833,7 @@ void con_tcx_fx( L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ - move32(); st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); - move32(); /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */ /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/ @@ -828,7 +841,7 @@ void con_tcx_fx( tmp_e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, tmp_e ); /*Q16,-tmp_e*/ step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/ - step32 = L_shl( step32, sub( ( 25 - 22 ), tmp_e ) ); /*Q25*/ + step32 = L_shl( step32, sub( 25 - 22, tmp_e ) ); /*Q25*/ pt_exc = noise + L_FIR_FER2 / 2; @@ -855,7 +868,7 @@ void con_tcx_fx( #ifdef BASOP_NOGLOB /* Critical Overflow */ gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ #else - gain_inov = round_fx( L_tmp ); /*Q15,gain_inov_e*/ + gain_inov = round_fx( L_tmp ); /*Q15,gain_inov_e*/ #endif } @@ -876,8 +889,8 @@ void con_tcx_fx( pt_exc++; } tmp16 = add( L_frame, L_FIR_FER2 / 2 ); - step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, ( 25 - 16 ) ) ); /*Q16,-tmp_e*/ - FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ + step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/ + FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { *pt_exc = mult_r( *pt_exc, gain_tmp ); move16(); @@ -905,10 +918,10 @@ void con_tcx_fx( FOR( i = 0; i < tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + exc[i] = add_sat( exc[i], shl_sat( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #else - exc[i] = add( exc[i], shl( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + exc[i] = add( exc[i], shl( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #endif } @@ -916,7 +929,7 @@ void con_tcx_fx( 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, hTcxDec->old_excFB_fx, 2 * L_subfr + shr( L_frame, 1 ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -928,6 +941,7 @@ void con_tcx_fx( lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; + move16(); } /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ @@ -950,7 +964,7 @@ void con_tcx_fx( st->prev_Q_syn = new_Q; move16(); - exp_scale = sub( tmp16, Q_exc - 1 ); + exp_scale = sub( tmp16, sub( Q_exc, 1 ) ); Q_syn = tmp16; move16(); @@ -962,6 +976,7 @@ void con_tcx_fx( tmp_deemph = shl( tmp_deemph, Q_syn ); #endif st->Q_syn = Q_syn; + move16(); /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ /*buf[0;M] Q0: mem_syn*/ @@ -1014,28 +1029,30 @@ void con_tcx_fx( /* copy mem_syn as 16kHz */ mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + L_frame - M - 1, st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); - lerp( syn + L_frame - shr( L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + L_frame - n, hHQ_core->old_out_fx, sub( L_frame, n ) ); + lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); FOR( i = 0; i < W12; i++ ) { - 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] ) ); + hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, n )] ) ); + move16(); } FOR( ; i < W1; i++ ) { - 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] ) ); + hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( i, n )] ) ); + move16(); } - set16_fx( &hHQ_core->old_out_fx[W1 + n], 0, n ); + set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -1056,11 +1073,10 @@ void con_tcx_fx( } #ifdef BASOP_NOGLOB - st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); + st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #else - st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); + st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #endif - move16(); st->bfi_pitch_frame = st->L_frame; move16(); @@ -1074,7 +1090,7 @@ void con_tcx_fx( } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); move16(); } @@ -1082,9 +1098,9 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[W1 - 1 - i] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); #else - hTcxDec->syn_Overl_TDACFB[i] = add( buf[i], buf[W1 - 1 - i] ); + hTcxDec->syn_Overl_TDACFB[i] = add( buf[i], buf[sub( sub( W1, 1 ), i )] ); #endif move16(); } @@ -1092,9 +1108,9 @@ void con_tcx_fx( FOR( i = 0; i < W2; i++ ) { #ifdef BASOP_NOGLOB - hTcxDec->syn_Overl_TDACFB[W2 + i] = add_sat( buf[W2 + i], buf[W1 - 1 - W2 - i] ); + hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); #else - hTcxDec->syn_Overl_TDACFB[W2 + i] = add( buf[W2 + i], buf[W1 - 1 - W2 - i] ); + hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); #endif move16(); } @@ -1106,11 +1122,12 @@ void con_tcx_fx( } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; + move16(); synth[-1] = pre_emph_buf; move16(); @@ -1194,7 +1211,6 @@ void con_tcx_ivas_fx( /* 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->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/ W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; move16(); @@ -1213,7 +1229,7 @@ void con_tcx_ivas_fx( st->L_frame, &s ); - FOR( i = 0; i < ( 2 * NB_SUBFR16k + 2 ); i++ ) + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { old_pitch_buf[i] = L_shl( Mpy_32_16_1( st->old_pitch_buf_fx[i], c ), s ); move32(); @@ -1230,12 +1246,12 @@ void con_tcx_ivas_fx( IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ - 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 ); + mem = synth[sub( -add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), M + M ), 1 )]; + move16(); + Q_exc = E_UTIL_f_preemph3( &( synth[-add( add( 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 ) ); - move32(); + st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); st->Mode2_lp_gainp = L_max( st->Mode2_lp_gainp, 0 ); st->Mode2_lp_gainp = L_min( st->Mode2_lp_gainp, 65536l /*1.0f Q16*/ ); @@ -1245,7 +1261,7 @@ void con_tcx_ivas_fx( ham_cos_window( ana_window, mult( L_frame, 24576 /*0.75f Q15*/ ), shr( L_frame, 2 ) ); /* Autocorrelation */ - autocorr_fx( &( synth[-L_frame - 1] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); + autocorr_fx( &( synth[sub( -L_frame, 1 )] ), M, r_h, r_l, &Q_r, L_frame, ana_window, 0, 0 ); /* Lag windowing */ lag_wind( r_h, r_l, M, st->output_Fs, LAGW_STRONG ); @@ -1262,8 +1278,8 @@ void con_tcx_ivas_fx( BASOP_SATURATE_WARNING_OFF_EVS /*saturation possible in case of spiky synthesis*/ Residu3_fx( A_local, - &( synth[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx = Q0*/ - &( exc[-( 2 * L_subfr + Tc + 1 + M )] ), /*Qx+1 = Q1*/ + &( synth[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx = Q0*/ + &( exc[-add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M )] ), /*Qx+1 = Q1*/ add( add( add( shl( L_subfr, 1 ), Tc ), 1 ), M ), 1 ); BASOP_SATURATE_WARNING_ON_EVS @@ -1271,19 +1287,20 @@ void con_tcx_ivas_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[-L_frame - 1]; + mem = synth[sub( -L_frame, 1 )]; + move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); + Copy( st->old_Aq_12_8_fx, A_local, add( M, 1 ) ); offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) { tmp16 = s_max( Tc - shr( L_frame, 1 ), 0 ); - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), offset + tmp16, Q_exc - st->Q_exc ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-tmp16] ), add( offset, tmp16 ), sub( Q_exc, st->Q_exc ) ); } ELSE { - Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-2 * L_subfr] ), 2 * L_subfr + offset, Q_exc - st->Q_exc ); + Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-shl( L_subfr, 1 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); } } @@ -1295,7 +1312,7 @@ void con_tcx_ivas_fx( test(); IF( GT_16( st->last_good, UNVOICED_CLAS ) && !( EQ_16( st->last_good, UNVOICED_TRANSITION ) && EQ_16( st->core_ext_mode, GENERIC ) ) ) { - + test(); IF( EQ_16( st->nbLostCmpt, 1 ) || hTcxDec->tcxConceal_recalc_exc ) { calcGainc_fx( exc, Q_exc, st->old_fpitchFB, L_subfr, st->Mode2_lp_gainp, &( st->Mode2_lp_gainc ) ); @@ -1303,7 +1320,7 @@ void con_tcx_ivas_fx( tmp16 = 0; move16(); - if ( GT_32( st->output_Fs, 25600 ) ) + IF( GT_32( st->output_Fs, 25600 ) ) { tmp16 = 1; move16(); @@ -1324,8 +1341,7 @@ void con_tcx_ivas_fx( test(); test(); - test(); - if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) ) + IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -1352,7 +1368,7 @@ void con_tcx_ivas_fx( test(); test(); test(); - if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) ) + IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) && EQ_16( extrapolationFailed, 0 ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -1365,7 +1381,7 @@ void con_tcx_ivas_fx( pt_exc = exc + offset; pt1_exc = pt_exc - Tc; - if ( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { pt_exc = buf; } @@ -1378,7 +1394,6 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < Tc; i++ ) { - move16(); *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mult( 174 /* 0.0053f Q15*/, pt1_exc[-5] ), 0 /* 0.0000f Q15*/, pt1_exc[-4] ), @@ -1391,6 +1406,7 @@ void con_tcx_ivas_fx( -1442 /*-0.0440f Q15*/, pt1_exc[3] ), 0 /* 0.0000f Q15*/, pt1_exc[4] ), 174 /* 0.0053f Q15*/, pt1_exc[5] ); + move16(); pt1_exc++; } } @@ -1398,7 +1414,6 @@ void con_tcx_ivas_fx( { FOR( i = 0; i < Tc; i++ ) { - move16(); *pt_exc++ = mac_r( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mac( L_mult( -174 /*-0.0053f Q15*/, pt1_exc[-5] ), -121 /*-0.0037f Q15*/, pt1_exc[-4] ), @@ -1411,6 +1426,7 @@ void con_tcx_ivas_fx( -459 /*-0.0140f Q15*/, pt1_exc[3] ), -121 /*-0.0037f Q15*/, pt1_exc[4] ), -174 /*-0.0053f Q15*/, pt1_exc[5] ); + move16(); pt1_exc++; } } @@ -1430,7 +1446,7 @@ void con_tcx_ivas_fx( move16(); } - if ( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { pt1_exc = buf; } @@ -1441,7 +1457,7 @@ void con_tcx_ivas_fx( move16(); } - IF( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { get_subframe_pitch( st->nb_subfr, st->old_fpitch, @@ -1464,7 +1480,7 @@ void con_tcx_ivas_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { pt_exc = exc + L_frame; - IF( T0 == 0 ) + IF( EQ_16( T0, 0 ) ) { pt1_exc = pt_exc - Tc; } @@ -1481,10 +1497,10 @@ void con_tcx_ivas_fx( } } - if ( fUseExtrapolatedPitch != 0 ) + IF( NE_16( fUseExtrapolatedPitch, 0 ) ) { st->old_fpitchFB = predPitchLag; - move16(); + move32(); } st->bpf_gain_param = 0; move16(); @@ -1520,10 +1536,13 @@ void con_tcx_ivas_fx( gain32 = L_add( 2147483647l /*1.f Q31*/, 0 ); /*Q31*/ gain = 32767 /*1.f Q15*/; /*Q15*/ move16(); - if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) + test(); + IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { gain32 = 1073741824l /*0.5f Q31*/; + move32(); gain = 16384 /*0.5f Q15*/; + move16(); } /*step = (1.0f/(L_frame+(L_frame/2))) * (gain - alpha);*/ @@ -1550,8 +1569,8 @@ void con_tcx_ivas_fx( } /* update old exc without random part */ - offset = s_max( round_fx( st->old_fpitchFB ) - shr( L_frame, 1 ), 0 ); - Copy( exc + L_frame - offset, hTcxDec->old_excFB_fx, shr( L_frame, 1 ) + offset ); + offset = s_max( sub( round_fx( st->old_fpitchFB ), shr( L_frame, 1 ) ), 0 ); + Copy( exc + sub( L_frame, offset ), hTcxDec->old_excFB_fx, add( shr( L_frame, 1 ), offset ) ); /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1563,6 +1582,7 @@ void con_tcx_ivas_fx( lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; + move16(); } ELSE { @@ -1593,44 +1613,52 @@ void con_tcx_ivas_fx( * Construct the random part of excitation *-----------------------------------------------------------------*/ #ifndef IVAS_CODE_CON_TCX - IF( coh != -16384 ) + IF( NE_16( coh, -16384 ) ) { Word16 tmpSeed1; Word16 alpha_coh; Word16 random1, random2; + Word16 e; tmpSeed1 = *noise_seed; noise = buf; noise_e = 1; - Word16 e = 0; + move16(); + e = 0; + move16(); alpha_coh = 0; + move16(); IF( NE_16( coh, 16384 ) ) { - alpha_coh = Sqrt16( div_s( ( 16384 - coh ), ( 16384 + coh ) ), &e ); + alpha_coh = Sqrt16( div_s( sub( 16384, coh ), add( 16384, coh ) ), &e ); } - IF( st->idchan == 1 ) + IF( EQ_16( st->idchan, 1 ) ) { alpha_coh = negate( alpha_coh ); } - FOR( i = 0; i < L_frame + L_FIR_FER2 - 1; i++ ) + FOR( i = 0; i < add( L_frame, L_FIR_FER2 - 1 ); i++ ) { random1 = own_random2_fx( tmpSeed1 ); random2 = own_random2_fx( tmpSeed1 ); noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), noise_e ) ); + move16(); } - IF( st->idchan == 1 || only_left ) + test(); + IF( EQ_16( st->idchan, 1 ) || only_left ) { *noise_seed = tmpSeed1; + move16(); } - FOR( ; i < L_frame + ( L_frame / 2 ) + 2 * L_FIR_FER2; i++ ) + FOR( ; i < add( add( L_frame, shr( L_frame, 1 ) ), 2 * L_FIR_FER2 ); i++ ) { random1 = own_random2_fx( tmpSeed1 ); random2 = own_random2_fx( tmpSeed1 ); noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), noise_e ) ); + move16(); } } ELSE @@ -1665,7 +1693,7 @@ void con_tcx_ivas_fx( { tmp16 = 19661 /*0.6f Q15*/; move16(); - if ( LE_32( st->output_Fs, 16000 ) ) + IF( LE_32( st->output_Fs, 16000 ) ) { tmp16 = 6554 /*0.2f Q15*/; move16(); @@ -1673,7 +1701,7 @@ void con_tcx_ivas_fx( mem = noise[0]; move16(); - preemph_copy_fx( &noise[1], &noise[1], tmp16, L_frame + ( L_frame / 2 ) + L_FIR_FER2, &mem ); + preemph_copy_fx( &noise[1], &noise[1], tmp16, add( add( L_frame, shr( L_frame, 1 ) ), L_FIR_FER2 ), &mem ); } /* high rate filter tuning */ IF( LE_32( st->output_Fs, 16000 ) ) @@ -1707,9 +1735,9 @@ void con_tcx_ivas_fx( Word16 j; L_tmp2 = 0; move32(); - for ( j = 11; j > 0; j-- ) + FOR( j = 11; j > 0; j-- ) { - L_tmp2 = L_mac( L_tmp2, noise[i + L_FIR_FER2 - j], hp_filt[L_FIR_FER2 - j] ); + L_tmp2 = L_mac( L_tmp2, noise[add( i, sub( L_FIR_FER2, j ) )], hp_filt[sub( L_FIR_FER2, j )] ); } L_tmp2 = Mpy_32_16_1( L_tmp2, st->cummulative_damping /*Q15*/ ); /*Q0, noise_e*/ noise[i] = mac_r( L_tmp2, gain_tmp, noise[i] ); /*Q15, noise_e*/ @@ -1720,6 +1748,7 @@ void con_tcx_ivas_fx( /* PLC: [TCX: Fade-out] retrieve background level */ #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT tmp16 = 32767; + move16(); IF( A_cng != NULL ) { gainSynthDeemph = shr( getLevelSynDeemph_fx( &( tmp16 ), A_cng, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ), 2 ); @@ -1733,7 +1762,7 @@ void con_tcx_ivas_fx( move16(); gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); #endif - IF( 0 != st->tcxonly ) + IF( NE_16( st->tcxonly, 0 ) ) { /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, @@ -1741,11 +1770,13 @@ void con_tcx_ivas_fx( gainSynthDeemph, gainSynthDeemph_e, &gainCNG, &gainCNG_e ); #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - IF( st->element_mode == IVAS_CPE_MDCT && A_cng != NULL ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && A_cng != NULL ) { IF( GT_16( st->nbLostCmpt, add( MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME, MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN ) ) ) { gainCNG = 0; + move16(); } ELSE IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) { @@ -1786,9 +1817,7 @@ void con_tcx_ivas_fx( L_tmp = Mpy_32_16_1( st->Mode2_lp_gainc, alpha ) /*Q15*/; L_tmp2 = L_mult( sub( 16384 /*1.f Q14*/, alpha ) /*Q14*/, gainCNG /*Q15,gainCNG_e*/ ); /*Q30,gainCNG_e*/ st->Mode2_lp_gainc = BASOP_Util_Add_Mant32Exp( L_tmp, 31 - 15, L_tmp2, add( gainCNG_e, 31 - 30 ), &tmp_e ); /*Q31*/ - move32(); st->Mode2_lp_gainc = L_shl( st->Mode2_lp_gainc, sub( tmp_e, 31 - 16 ) ); - move32(); /* PLC: [TCX: Fade-out] Linearly attenuate the gain through the frame */ /*step = (1.0f/L_frame) * (gain - (st->Mode2_lp_gainc));*/ @@ -1796,17 +1825,17 @@ void con_tcx_ivas_fx( tmp_e = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, tmp_e ); /*Q16,-tmp_e*/ step32 = Mpy_32_16_1( L_tmp /*Q16,-tmp_e*/, getInvFrameLen( L_frame ) /*W16Q21*/ ); /*Q22,-tmp_e*/ - step32 = L_shl( step32, sub( ( 25 - 22 ), tmp_e ) ); /*Q25*/ + step32 = L_shl( step32, sub( 25 - 22, tmp_e ) ); /*Q25*/ - pt_exc = noise + L_FIR_FER2 / 2; + pt_exc = noise + shr( L_FIR_FER2, 1 ); /*gain_inov = 1.0f / (float)sqrt( dot_product( pt_exc, pt_exc, L_frame ) / L_frame + 0.01f );*/ /* normalize energy */ L_tmp = Dot_productSq16HQ( 0, pt_exc /*Q0,15+1*/, L_frame, &tmp_e ) /*Q31,tmp_e+16+16*/; L_tmp = Mpy_32_16_1( L_tmp, getInvFrameLen( L_frame ) /*W16Q21*/ ) /*W32Q37,tmp_e+16+16*/ /*Q5,tmp_e*/; tmp_e = add( tmp_e, 31 - 5 ); /*-->Q31*/ gain_inov = 0; - gain_inov_e = 0; move16(); + gain_inov_e = 0; move16(); IF( NE_32( L_tmp, 0 ) ) { @@ -1847,8 +1876,8 @@ void con_tcx_ivas_fx( pt_exc++; } tmp16 = add( L_frame, L_FIR_FER2 / 2 ); - step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, ( 25 - 16 ) ) ); /*Q16,-tmp_e*/ - FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ + step32_tmp = L_shl( step32 /*Q25*/, sub( tmp_e, 25 - 16 ) ); /*Q16,-tmp_e*/ + FOR( i = 0; i < tmp16; i++ ) /* Actual filtered random part of excitation */ { *pt_exc = mult_r( *pt_exc, gain_tmp ); move16(); @@ -1876,10 +1905,10 @@ void con_tcx_ivas_fx( FOR( i = 0; i < tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + exc[i] = add_sat( exc[i], shl_sat( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #else - exc[i] = add( exc[i], shl( noise[i + ( L_FIR_FER2 / 2 )], Q_exc + noise_e ) ); /*Q1*/ + exc[i] = add( exc[i], shl( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #endif } @@ -1887,7 +1916,7 @@ void con_tcx_ivas_fx( 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, hTcxDec->old_excFB_fx, 2 * L_subfr + shr( L_frame, 1 ) ); + Copy( exc + sub( L_frame, shl( L_subfr, 1 ) ), hTcxDec->old_excFB_fx, add( shl( L_subfr, 1 ), shr( L_frame, 1 ) ) ); /* copy old_exc as 16kHz for acelp decoding */ IF( EQ_16( st->nbLostCmpt, 1 ) ) { @@ -1899,6 +1928,7 @@ void con_tcx_ivas_fx( lerp( exc, st->old_exc_fx + L_FRAME16k / 2, L_FRAME16k, L_frame ); } st->Q_exc = Q_exc; + move16(); } /*buf[0;L_FIR_FER2 + L_Frame + L_Frame/2] Q0, noise_e*/ /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1*/ @@ -1921,7 +1951,7 @@ void con_tcx_ivas_fx( st->prev_Q_syn = new_Q; move16(); - exp_scale = sub( tmp16, Q_exc - 1 ); + exp_scale = sub( tmp16, sub( Q_exc, 1 ) ); Q_syn = tmp16; move16(); @@ -1933,21 +1963,24 @@ void con_tcx_ivas_fx( tmp_deemph = shl( tmp_deemph, Q_syn ); #endif st->Q_syn = Q_syn; + move16(); /*buf[OLD_EXC_SIZE_DEC;3/2 L_frame] Q1: exc*/ /*buf[0;M] Q0: mem_syn*/ #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT - if ( A_cng != NULL ) + IF( A_cng != NULL ) { Word16 alpha_delayed; alpha_delayed = 16384; - IF( st->nbLostCmpt > MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE ) + move16(); + IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE ) ) { alpha_delayed = Damping_fact_fx( st->core_ext_mode, st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_DELAY_4_LSP_FADE, st->last_good, st->stab_fac_fx, &( st->Mode2_lp_gainp ), ACELP_CORE ); } - IF( st->plcBackgroundNoiseUpdated && alpha_delayed != 16384 ) + test(); + IF( st->plcBackgroundNoiseUpdated && NE_16( alpha_delayed, 16384 ) ) { Word16 lsp_local[M], lsp_fade[M], alpha_inv; @@ -1958,6 +1991,7 @@ void con_tcx_ivas_fx( FOR( i = 0; i < M; i++ ) { lsp_fade[i] = add( mult_r( alpha_delayed, lsp_local[i] ), mult_r( alpha_inv, st->lspold_cng[i] ) ); + move16(); } E_LPC_f_lsp_a_conversion( lsp_fade, A_local, M ); @@ -1985,28 +2019,30 @@ void con_tcx_ivas_fx( /* copy mem_syn as 16kHz */ mem_syn_r_size_new = shr( L_FRAME16k, 4 ); /* replace 1.25/20.0 by shr(4) */ - Copy( syn + L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); - lerp( st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old ); + Copy( syn + sub( L_frame, L_SYN_MEM ), st->mem_syn_r, L_SYN_MEM ); + lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old ); Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Deemphasis and output synth and ZIR */ deemph_fx( syn, st->preemph_fac, add( L_frame, shr( L_frame, 1 ) ), &tmp_deemph ); - bufferCopyFx( syn + L_frame - M - 1, st->syn, 1 + M, Q_syn, 0, 0, 0 ); + bufferCopyFx( syn + sub( L_frame, M + 1 ), st->syn, 1 + M, Q_syn, 0, 0, 0 ); - lerp( syn + L_frame - shr( L_frame, 1 ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); - Copy( syn + L_frame - n, hHQ_core->old_out_fx, sub( L_frame, n ) ); + lerp( syn + sub( L_frame, shr( L_frame, 1 ) ), hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), shr( L_frame, 1 ) ); + Copy( syn + sub( L_frame, n ), hHQ_core->old_out_fx, sub( L_frame, n ) ); FOR( i = 0; i < W12; i++ ) { - 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] ) ); + hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[add( i, n )] ) ); + move16(); } FOR( ; i < W1; i++ ) { - 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] ) ); + hHQ_core->old_out_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im, w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ), hHQ_core->old_out_fx[add( i, n )] ) ); + move16(); } - set16_fx( &hHQ_core->old_out_fx[W1 + n], 0, n ); + set16_fx( &hHQ_core->old_out_fx[add( W1, n )], 0, n ); hHQ_core->Q_old_wtda = Q_syn; move16(); @@ -2027,11 +2063,10 @@ void con_tcx_ivas_fx( } #ifdef BASOP_NOGLOB - st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); + st->bfi_pitch_fx /*Q6*/ = round_fx_sat( L_shl_sat( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #else - st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[st->nb_subfr - 1] /*15Q16*/, 6 /*Q6*/ ) ); + st->bfi_pitch_fx /*Q6*/ = round_fx( L_shl( pitch_buf[sub( st->nb_subfr, 1 )] /*15Q16*/, 6 /*Q6*/ ) ); #endif - move16(); st->bfi_pitch_frame = st->L_frame; move16(); @@ -2045,20 +2080,20 @@ void con_tcx_ivas_fx( } FOR( ; i < W1; i++ ) { - buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); + buf[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[W1 - 1 - i] ); + hTcxDec->syn_Overl_TDACFB[i] = add_sat( buf[i], buf[sub( sub( W1, 1 ), i )] ); move16(); } FOR( i = 0; i < W2; i++ ) { - hTcxDec->syn_Overl_TDACFB[W2 + i] = add_sat( buf[W2 + i], buf[W1 - 1 - W2 - i] ); + hTcxDec->syn_Overl_TDACFB[add( W2, i )] = add_sat( buf[add( W2, i )], buf[sub( sub( sub( W1, 1 ), W2 ), i )] ); move16(); } @@ -2069,11 +2104,12 @@ void con_tcx_ivas_fx( } FOR( ; i < W1; i++ ) { - hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[W12 - 1 - ( i - W12 )].v.im ); + hTcxDec->syn_Overl_TDACFB[i] = mult_r( hTcxDec->syn_Overl_TDACFB[i], w[sub( sub( W12, 1 ), sub( i, W12 ) )].v.im ); move16(); } st->hTcxCfg->tcx_curr_overlap_mode = FULL_OVERLAP; + move16(); synth[-1] = pre_emph_buf; move16(); diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index d9d80c6ed..a8c76aa85 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -37,17 +37,18 @@ Word16 Damping_fact_fx( /* o : damping factor Word32 gain32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif - IF( core == ACELP_CORE ) + IF( EQ_16( core, ACELP_CORE ) ) { alpha = mult_r( _ALPHA_VT_FX, 16384 ); /* rapid convergence to 0 */ /*Q14*/ test(); test(); - test(); /*ELSEIF*/ test(); - test(); /*ELSEIF*/ + test(); + test(); IF( ( EQ_16( coder_type, UNVOICED ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) /* Clear unvoiced last good frame */ { alpha = mult_r( _ALPHA_UU_FX, 16384 ); /*Q14*/ @@ -78,15 +79,15 @@ Word16 Damping_fact_fx( /* o : damping factor { alpha = 13107 /*0.8f Q14*/; /*Q14*/ } - ELSE if ( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) + ELSE IF( ( ( EQ_16( last_good, VOICED_CLAS ) ) || ( EQ_16( last_good, ONSET ) ) ) && ( LE_16( nbLostCmpt, 3 ) ) ) { alpha = mult_r( _ALPHA_V_FX, 16384 ); /* constant for the first 3 erased frames */ } IF( GE_16( last_good, VOICED_CLAS ) ) { - move16(); lp_tmp = *lp_gainp; + move32(); IF( EQ_16( nbLostCmpt, 1 ) ) /* if first erased frame in a block, reset harmonic gain */ { @@ -95,7 +96,6 @@ Word16 Damping_fact_fx( /* o : damping factor /*gain = (float)sqrt( *lp_gainp );*/ /* move pitch gain towards 1 for voiced to remove energy fluctuations */ /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ s_gainp = 31 - 29; - move16(); gain32 = Sqrt32( lp_tmp, &s_gainp ); #ifdef BASOP_NOGLOB @@ -114,22 +114,22 @@ Word16 Damping_fact_fx( /* o : damping factor } ELSE { - /*0.7 + 0.2*stab_fac*/ move16(); + /*0.7 + 0.2*stab_fac*/ lp_tmp = Mpy_32_16_1( lp_tmp, mac_r( 1503238528l /*0.7f Q31*/, 6554 /*0.2f Q15*/, stab_fac ) ); /*2Q29*/ alpha = round_fx( L_shl( lp_tmp, 1 ) ); /*1Q14*/ } - move16(); *lp_gainp = lp_tmp; /*store*/ + move32(); } } ELSE { alpha = mac_r( 375809632l /*0.35f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/ - if ( LT_16( nbLostCmpt, 2 ) ) + IF( LT_16( nbLostCmpt, 2 ) ) { alpha = mac_r( 751619264l /*0.70f Q30*/, 4915 /*0.3f Q14*/, stab_fac ); /*Q14*/ } - if ( EQ_16( nbLostCmpt, 2 ) ) + IF( EQ_16( nbLostCmpt, 2 ) ) { alpha = mac_r( 483183808l /*0.45f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/ } diff --git a/lib_dec/er_sync_exc.c b/lib_dec/er_sync_exc.c index ea14a7f4b..68cc16665 100644 --- a/lib_dec/er_sync_exc.c +++ b/lib_dec/er_sync_exc.c @@ -42,6 +42,7 @@ #include "cnst.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------*/ @@ -56,7 +57,6 @@ *--------------------------------------------------------------------*/ /*! r: Index of the position of the minimum energy, that is the position i where filter(x[i-filterLength/2],...,x[i+(filterLength-filterLength/2)-1]) is at maximum. */ -#ifndef IVAS_FLOAT_FIXED static int16_t GetMinimumPosition( const float *x, /* i : input signal */ const int16_t length, /* i : length of the filter length used for the energy calculation */ diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index 44c6230d2..f01c98655 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -34,6 +34,7 @@ static Word16 GetMinimumPosition_fx( Word32 energy, energy_old, tmptest; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif filterLength = s_min( filterLength, length ); @@ -41,7 +42,7 @@ static Word16 GetMinimumPosition_fx( iMinEnergyPos = center; move16(); - IF( filterLength > 0 ) + IF( GT_16( filterLength, 0 ) ) { center = add( center, 1 ); energy = L_deposit_l( 0 ); @@ -59,7 +60,7 @@ static Word16 GetMinimumPosition_fx( #else energy = L_msu( energy_old, tmp16, tmp16 ); #endif - tmp16 = shr( x[i + filterLength], tmp_e ); + tmp16 = shr( x[add( i, filterLength )], tmp_e ); BASOP_SATURATE_WARNING_OFF_EVS /*Saturation will be handled*/ #ifdef BASOP_NOGLOB energy = L_mac_sat( energy, tmp16, tmp16 ); @@ -76,17 +77,17 @@ static Word16 GetMinimumPosition_fx( tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif BASOP_SATURATE_WARNING_ON_EVS - IF( tmptest == 0 ) + IF( EQ_32( tmptest, 0 ) ) { tmp_e = add( tmp_e, 1 ); energy = L_shr( energy_old, 2 ); tmp16 = shr( x[i], tmp_e ); energy = L_msu( energy, tmp16, tmp16 ); - tmp16 = shr( x[i + filterLength], tmp_e ); + tmp16 = shr( x[add( i, filterLength )], tmp_e ); energy = L_mac( energy, tmp16, tmp16 ); } - IF( energy < 0 ) + IF( LT_32( energy, 0 ) ) { iMinEnergyPos = add( i, center ); tmp_e = 0; @@ -118,10 +119,10 @@ static Word16 FindMaxPeak_fx( move16(); FOR( i = 1; i < length; i++ ) { - if ( GT_16( abs_s( x[i] ), abs_s( x[iMax] ) ) ) + IF( GT_16( abs_s( x[i] ), abs_s( x[iMax] ) ) ) { - move16(); iMax = i; + move16(); } } @@ -144,16 +145,14 @@ static void AddSamples_fx( Word16 ftmp; pt_dest = new_exc; - move16(); pt_src = old_exc; - move16(); last_min_pos = 0; move16(); FOR( i = 0; i < nb_min; i++ ) { /* Copy section */ - FOR( j = min_pos[i] - last_min_pos; j > 0; j-- ) + FOR( j = sub( min_pos[i], last_min_pos ); j > 0; j-- ) { *pt_dest++ = *pt_src++; move16(); @@ -253,7 +252,7 @@ void PulseResynchronization_fx( test(); test(); test(); - IF( ( LT_32( L_deposit_h( nFrameLength ), pitchStart ) ) || ( pitchStart <= 0 ) || ( pitchEnd <= 0 ) || ( LT_16( nSubframes, 1 ) ) || ( GT_16( nSubframes, 5 ) ) || ( LE_32( Mpy_32_16_1( pitchEnd, add( nSubframes, 1 ) ), Mpy_32_16_1( pitchStart, sub( nSubframes, 1 ) ) ) ) || ( src_exc - dst_exc >= 0 ) ) + IF( ( LT_32( L_deposit_h( nFrameLength ), pitchStart ) ) || LE_32( pitchStart, 0 ) || LE_32( pitchEnd, 0 ) || ( LT_16( nSubframes, 1 ) ) || ( GT_16( nSubframes, 5 ) ) || ( LE_32( Mpy_32_16_1( pitchEnd, add( nSubframes, 1 ) ), Mpy_32_16_1( pitchStart, sub( nSubframes, 1 ) ) ) ) || ( src_exc - dst_exc >= 0 ) ) { /* This is error handling and recovery that should never occur. */ test(); @@ -275,7 +274,7 @@ void PulseResynchronization_fx( /*samplesDelta = 0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart;*/ /* pitchDelta*freqStart = ((pitchEnd - pitchStart)/roundedPitchStart)/nSubframes */ tmp16 = shl( roundedPitchStart, 2 ); /*Q0*/ - if ( EQ_16( nSubframes, 5 ) ) + IF( EQ_16( nSubframes, 5 ) ) { tmp16 = add( tmp16, roundedPitchStart ); /*Q0*/ /*tmp16=roundedPitchStart*nSubframes*/ } @@ -307,6 +306,7 @@ void PulseResynchronization_fx( tmp2_e = add( tmp2_e, 31 - 16 ); /* tmp32_a is now regarded as Q31 with scaling tmp2_e */ tmp3_e = tmp2_e; + move16(); tmp32_a = L_negate( tmp32_a ); #ifdef BASOP_NOGLOB tmp32_a = L_add( L_shl_o( 1, sub( 31, tmp3_e ), &Overflow ), tmp32_a ); /*Q31,tmp3_e*/ /*tmp32_a= 1.0f-pitchStart*freqStart*/ @@ -332,7 +332,7 @@ void PulseResynchronization_fx( tmp32 = L_add( tmp32, 65536l /*1.f Q16*/ ); k = extract_h( tmp32 ); test(); - IF( ( k >= 0 ) && LE_16( add( k, 1 ), NB_PULSES_MAX ) ) + IF( GE_16( k, 0 ) && LE_16( add( k, 1 ), NB_PULSES_MAX ) ) { absPitchDiff = L_abs( L_sub( L_deposit_h( roundedPitchStart ), pitchEnd ) ); /*Q16*/ @@ -361,7 +361,7 @@ void PulseResynchronization_fx( /* Calculate the integer number of samples to be added/removed in each pitch cycle */ /*cycleDelta = max(0, (absPitchDiff-(k+1)*perCycleDeltaDelta)*T0*freqStart); */ - tmp_e = norm_s( k + 1 ); + tmp_e = norm_s( add( k, 1 ) ); tmp32 = L_mult( perCycleDeltaDelta /*Q15,perCycleDeltaDelta_e*/, shl( add( k, 1 ), tmp_e ) /*Q0, tmp_e*/ ) /*Q0+16, perCycleDeltaDelta_e-tmp_e*/; tmp32 = BASOP_Util_Add_Mant32Exp( absPitchDiff /*Q16*/, 31 - 16, L_negate( tmp32 ), add( sub( perCycleDeltaDelta_e, tmp_e ), 31 - 16 ), &tmp_e ); /*Q31,tmp_e*/ tmp32 = Mpy_32_16_1( tmp32, T0 /*Q0*/ ); /*Q16,tmp_e*/ @@ -370,7 +370,7 @@ void PulseResynchronization_fx( cycleDelta_e = add( tmp_e, freqStart_e ); tmp32_a = L_shl( tmp32, cycleDelta_e ); roundedCycleDelta = extract_h( L_abs( tmp32_a ) ); - if ( tmp32 < 0 ) + IF( LT_32( tmp32, 0 ) ) { roundedCycleDelta = negate( roundedCycleDelta ); } @@ -383,19 +383,19 @@ void PulseResynchronization_fx( #else cycleDelta = round_fx( tmp32 ); /*Q15, cycleDelta_e*/ #endif - if ( cycleDelta == 0 ) + IF( EQ_16( cycleDelta, 0 ) ) { - move16(); cycleDelta_e = 0; + move16(); } /*roundedCycleDelta = (int)(cycleDelta); */ /*done above*/ + iDeltaSamples[0] = roundedCycleDelta; /*Q0*/ move16(); - iDeltaSamples[0] = roundedCycleDelta; /*Q0*/ /*fractionalLeft = cycleDelta-roundedCycleDelta;*/ /*done above*/ nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); /*Q0*/ - tmp_e = ( s_max( 2, k ) ); + tmp_e = s_max( 2, k ); tmp_e = norm_s( tmp_e ); /*maximum norming factor for following loop*/ @@ -415,7 +415,7 @@ void PulseResynchronization_fx( iDeltaSamples[i] = roundedCycleDelta; move16(); roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[i - 1] = roundedCycleDelta; + iDeltaSamples[sub( i, 1 )] = roundedCycleDelta; move16(); } ELSE @@ -428,9 +428,9 @@ void PulseResynchronization_fx( fractionalLeft = lshr( extract_l( cycleDelta32 ), 1 ); /*Q15*/ /* cycleDelta32 should never be < 0 here */ nSamplesDeltaRemain = sub( nSamplesDeltaRemain, roundedCycleDelta ); } - iDeltaSamples[k + 1] = s_max( 0, nSamplesDeltaRemain ); + iDeltaSamples[add( k, 1 )] = s_max( 0, nSamplesDeltaRemain ); move16(); - maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[k + 1] ); /*Q0*/ + maxDeltaSamples = s_max( iDeltaSamples[k], iDeltaSamples[add( k, 1 )] ); /*Q0*/ /* Find the location of the minimum energy between the first two pulses */ @@ -449,7 +449,7 @@ void PulseResynchronization_fx( iMinPos1 = add( iMinPos1, T0 ); - IF( nSamplesDelta < 0 ) + IF( LT_16( nSamplesDelta, 0 ) ) { /* Find the location of the minimum energy before the first pulse */ @@ -460,43 +460,45 @@ void PulseResynchronization_fx( } ELSE { - move16(); iMinPos[0] = sub( GetMinimumPosition_fx( src_exc, T0, iDeltaSamples[0] ), shr( iDeltaSamples[0], 1 ) ); + move16(); } /* Find the location of the minimum energy between the pulses */ FOR( i = 1; i <= k; i++ ) { - move16(); iMinPos[i] = add( iMinPos1, sub( imult1616( sub( i, 1 ), roundedPitchStart ), shr( iDeltaSamples[i], 1 ) ) ); + move16(); } /* Find the location of the minimum energy after the last pulse */ - IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[k + 1], shr( iDeltaSamples[k + 1], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( LT_16( add( iMinPos1, add( imult1616( k, roundedPitchStart ), sub( iDeltaSamples[add( k, 1 )], shr( iDeltaSamples[add( k, 1 )], 1 ) ) ) ), sub( nFrameLength, nSamplesDelta ) ) ) { + iMinPos[add( k, 1 )] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[add( k, 1 )], 1 ) ) ); move16(); - iMinPos[k + 1] = add( iMinPos1, sub( imult1616( k, roundedPitchStart ), shr( iDeltaSamples[k + 1], 1 ) ) ); } ELSE { /*iMinPos[k+1] = T0+k*roundedPitchStart + GetMinimumPosition_fx(src_exc+T0+k*roundedPitchStart, nFrameLength-nSamplesDelta-(T0+k*roundedPitchStart), iDeltaSamples[k+1]) - iDeltaSamples[k+1]/2; */ - tmp16 = GetMinimumPosition_fx( src_exc + T0 + k * roundedPitchStart, sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[k + 1] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); tmp16 = add( add( T0, imult1616( k, roundedPitchStart ) ), tmp16 ); - tmp16 = sub( tmp16, shr( iDeltaSamples[k + 1], 1 ) ); - iMinPos[k + 1] = tmp16; + tmp16 = sub( tmp16, shr( iDeltaSamples[add( k, 1 )], 1 ) ); + iMinPos[add( k, 1 )] = tmp16; move16(); } - IF( GT_16( add( iMinPos[k + 1], iDeltaSamples[k + 1] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { - iDeltaSamples[k] += add( iMinPos[k + 1], sub( iDeltaSamples[k + 1], sub( nFrameLength, nSamplesDelta ) ) ); - iDeltaSamples[k + 1] = sub( nFrameLength, add( nSamplesDelta, iMinPos[k + 1] ) ); + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); + move16(); + iDeltaSamples[add( k, 1 )] = sub( nFrameLength, add( nSamplesDelta, iMinPos[add( k, 1 )] ) ); + move16(); } /* Remove samples at the given positions */ - RemoveSamples_fx( src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k + 2 ); + RemoveSamples_fx( src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, add( k, 2 ) ); } ELSE { @@ -523,27 +525,27 @@ void PulseResynchronization_fx( /* Find the location of the minimum energy after the last pulse */ IF( LT_16( iMinPos1, sub( nFrameLength, nSamplesDelta ) ) ) { - iMinPos[k + 1] = iMinPos1; + iMinPos[add( k, 1 )] = iMinPos1; move16(); } ELSE { - tmp16 = GetMinimumPosition_fx( src_exc + T0 + k * roundedPitchStart, sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[k + 1] ); + tmp16 = GetMinimumPosition_fx( src_exc + add( T0, imult1616( k, roundedPitchStart ) ), sub( nFrameLength, add( nSamplesDelta, add( T0, imult1616( k, roundedPitchStart ) ) ) ), iDeltaSamples[add( k, 1 )] ); tmp16 = add( add( tmp16, T0 ), imult1616( k, roundedPitchStart ) ); - iMinPos[k + 1] = tmp16; + iMinPos[add( k, 1 )] = tmp16; move16(); } - IF( GT_16( add( iMinPos[k + 1], iDeltaSamples[k + 1] ), sub( nFrameLength, nSamplesDelta ) ) ) + IF( GT_16( add( iMinPos[add( k, 1 )], iDeltaSamples[add( k, 1 )] ), sub( nFrameLength, nSamplesDelta ) ) ) { + iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[add( k, 1 )], sub( iDeltaSamples[add( k, 1 )], sub( nFrameLength, nSamplesDelta ) ) ) ); move16(); + iDeltaSamples[add( k, 1 )] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[add( k, 1 )] ); move16(); - iDeltaSamples[k] = add( iDeltaSamples[k], add( iMinPos[k + 1], sub( iDeltaSamples[k + 1], sub( nFrameLength, nSamplesDelta ) ) ) ); - iDeltaSamples[k + 1] = sub( sub( nFrameLength, nSamplesDelta ), iMinPos[k + 1] ); } /* Add samples at the given positions */ - AddSamples_fx( src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, k + 2 ); + AddSamples_fx( src_exc, dst_exc, nFrameLength, nSamplesDelta, iMinPos, iDeltaSamples, add( k, 2 ) ); } } } diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index f526a6103..09a7842d1 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -48,9 +48,10 @@ void minimumStatistics_fx( Word32 tmp32; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#endif move16(); +#endif aOpt_e = 0; + move16(); BASOP_SATURATE_WARNING_OFF_EVS @@ -63,14 +64,14 @@ void minimumStatistics_fx( BASOP_SATURATE_WARNING_ON_EVS currentFrameLevel = PLC_MIN_CNG_LEV; move16(); - move16(); currentFrameLevel_e = 0; + move16(); } BASOP_SATURATE_WARNING_ON_EVS /* compute optimal factor aOpt for recursive smoothing of frame minima */ tmp2 = BASOP_Util_Add_MantExp( *lastFrameLevel, *lastFrameLevel_e, negate( *noiseEstimate ), noiseEstimate_e, &tmp ); - IF( tmp >= 0 ) + IF( GE_16( tmp, 0 ) ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); @@ -84,22 +85,22 @@ void minimumStatistics_fx( } aOpt = mult_r( aOpt, aOpt ); /* Q15 */ aOpt_e = shl( aOpt_e, 1 ); - if ( aOpt == 0 ) + IF( EQ_16( aOpt, 0 ) ) { - move16(); aOpt_e = 0; + move16(); } *lastFrameLevel = currentFrameLevel; move16(); - move16(); *lastFrameLevel_e = currentFrameLevel_e; + move16(); /* recursively compute smoothed frame minima using optimal factor aOpt */ tmp = *currLevelIndex; move16(); move16(); - if ( tmp == 0 ) + IF( EQ_16( tmp, 0 ) ) { tmp = PLC_MIN_STAT_BUFF_SIZE; move16(); @@ -108,9 +109,9 @@ void minimumStatistics_fx( /*f = (aOpt * noiseLevelMemory[tmp-1]) - (currentFrameLevel * (aOpt-1))*/ /*tmp32*/ /*tmp*/ - tmp32 = L_mult( aOpt, noiseLevelMemory[tmp - 1] ); /*Q_tmp32 = aOpt_e + noiseLevelMemory_e[tmp - 1]*/ - move16(); + tmp32 = L_mult( aOpt, noiseLevelMemory[sub( tmp, 1 )] ); /*Q_tmp32 = aOpt_e + noiseLevelMemory_e[tmp - 1]*/ tmp_e = tmp; + move16(); tmp2 = BASOP_Util_Add_MantExp( aOpt, aOpt_e, negate( 32768 / 2 ), 1, &tmp ); @@ -123,7 +124,7 @@ void minimumStatistics_fx( move16(); } - *new_noiseEstimate_e = BASOP_Util_Add_MantExp( round_fx( tmp32 ), add( aOpt_e, noiseLevelMemory_e[tmp_e - 1] ), negate( s_max( tmp, -32767 ) /*to avoid negate(-32768)*/ ), tmp2, &f ); + *new_noiseEstimate_e = BASOP_Util_Add_MantExp( round_fx( tmp32 ), add( aOpt_e, noiseLevelMemory_e[sub( tmp_e, 1 )] ), negate( s_max( tmp, -32767 ) /*to avoid negate(-32768)*/ ), tmp2, &f ); assert( f >= 0 ); @@ -131,7 +132,7 @@ void minimumStatistics_fx( p = *noiseLevelIndex; move16(); tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); - IF( tmp >= 0 ) + IF( GE_16( tmp, 0 ) ) { /*rescale noiseLevelMemory*/ @@ -142,8 +143,6 @@ void minimumStatistics_fx( } ELSE { - move16(); - setnoiseLevelMemory_fx( f, new_noiseEstimate_e, noiseLevelMemory_e, noiseLevelMemory, currLevelIndex ); /* current min is not a new min, so check if min must be re-searched */ @@ -152,6 +151,7 @@ void minimumStatistics_fx( f = noiseLevelMemory[p]; /* min is still in memory, so return it */ move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; + move16(); } ELSE { @@ -159,7 +159,7 @@ void minimumStatistics_fx( FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) { tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( noiseLevelMemory[i] ), noiseLevelMemory_e[i], &tmp ); - if ( tmp > 0 ) + IF( GT_16( tmp, 0 ) ) { p = i; move16(); @@ -168,6 +168,7 @@ void minimumStatistics_fx( f = noiseLevelMemory[p]; move16(); *new_noiseEstimate_e = noiseLevelMemory_e[p]; + move16(); } } @@ -177,7 +178,7 @@ void minimumStatistics_fx( p = add( *currLevelIndex, 1 ); *currLevelIndex = add( *currLevelIndex, 1 ); move16(); - if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) + IF( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { *currLevelIndex = 0; move16(); @@ -221,6 +222,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ levelSynDeemphSub = L_deposit_l( 0 ); levelSynDeemph = L_deposit_l( 0 ); tmp = 0; + move16(); Q_h1 = 9; /*synthesis scaling for */ move16(); @@ -259,7 +261,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ tmp16 = 32767 /*1.0f Q15*/; move16(); - if ( GT_16( numLoops, 1 ) ) + IF( GT_16( numLoops, 1 ) ) { tmp16 = div_s( 1, numLoops ); } @@ -268,8 +270,8 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ } s16 = norm_l( levelSynDeemph ); levelSynDeemph = L_shl( levelSynDeemph, s16 ); - move16(); *Exp = sub( 10, s16 ); /*Set exponent in order to transform returnvalue to Q15*/ + move16(); #ifdef BASOP_NOGLOB return round_fx_sat( levelSynDeemph ); /*Q15*/ @@ -293,14 +295,14 @@ void genPlcFiltBWAdap_fx( IF( EQ_32( sr_core, INT_FS_16k ) ) { - IF( type == 0 ) + IF( EQ_16( type, 0 ) ) { - move16(); - move16(); - move16(); *lpFiltAdapt++ = 7282 /* 0.4000f/(2.f*0.4000f+1.f) Q15*/; + move16(); *lpFiltAdapt++ = 18204 /* 1.f/(2.f*0.4000f+1.f) Q15*/; + move16(); *lpFiltAdapt = 7282 /* 0.4000f/(2.f*0.4000f+1.f) Q15*/; + move16(); } ELSE { @@ -310,24 +312,24 @@ void genPlcFiltBWAdap_fx( b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); b = shr( b, sub( 1, exp ) ); a = negate( mult_r( a, b ) ); - move16(); - move16(); - move16(); *lpFiltAdapt++ = a; + move16(); *lpFiltAdapt++ = b; + move16(); *lpFiltAdapt = a; + move16(); } } ELSE /*sr_core = INT_FS_12k8 */ { - IF( type == 0 ) + IF( EQ_16( type, 0 ) ) { - move16(); - move16(); - move16(); *lpFiltAdapt++ = 5899 /* 0.2813f/(2.f*0.2813f+1.f) Q15*/; + move16(); *lpFiltAdapt++ = 20970 /* 1.f/(2.f*0.2813f+1.f) Q15*/; + move16(); *lpFiltAdapt = 5899 /* 0.2813f/(2.f*0.2813f+1.f) Q15*/; + move16(); } ELSE { @@ -337,12 +339,12 @@ void genPlcFiltBWAdap_fx( b = Inv16( add( a, 16384 /*0.5f Q15*/ ), &exp ); b = shr( b, sub( 1, exp ) ); a = negate( mult_r( a, b ) ); - move16(); - move16(); - move16(); *lpFiltAdapt++ = a; + move16(); *lpFiltAdapt++ = b; + move16(); *lpFiltAdapt = a; + move16(); } } } @@ -365,10 +367,10 @@ void highPassFiltering_fx( IF( GT_16( last_good, UNVOICED_TRANSITION ) ) { - FOR( i = 0; i < L_buffer; i++ ) { exc2[i] = round_fx( L_sub( Dot_product( &exc2[i], hp_filt, l_fir_fer ), 1 ) ); + move16(); } } } @@ -388,18 +390,21 @@ Word16 GetPLCModeDecision_ivas_fx( hTcxDec = st->hTcxDec; - IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[2 * st->nb_subfr] = L_deposit_h( st->guidedT0 ); - st->old_pitch_buf_fx[2 * st->nb_subfr + 1] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + move32(); + st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ + move16(); + move16(); } st->plc_use_future_lag = 0; move16(); test(); test(); - if ( ( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified != 0 ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) + IF( ( GT_16( st->last_core, ACELP_CORE ) && NE_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) { /* no updates needed here, because already updated in last good frame */ st->plc_use_future_lag = 1; @@ -412,7 +417,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); st->last_core = ACELP_CORE; move16(); - if ( st->Opt_AMR_WB ) + IF( st->Opt_AMR_WB ) { core = ACELP_CORE; move16(); @@ -424,7 +429,7 @@ Word16 GetPLCModeDecision_ivas_fx( { core = ACELP_CORE; move16(); - if ( GT_16( st->nbLostCmpt, 1 ) ) + IF( GT_16( st->nbLostCmpt, 1 ) ) { core = st->last_core_bfi; move16(); @@ -444,6 +449,7 @@ Word16 GetPLCModeDecision_ivas_fx( test(); test(); test(); + test(); // PMT("handle to tonalMDCTconceal is missing") //#ifdef ADD_IVAS_HTONALMDCTCONC IF( ( st->hTonalMDCTConc != NULL && EQ_16( st->last_core, TCX_20_CORE ) ) && ( EQ_16( st->second_last_core, TCX_20_CORE ) ) && ( ( LE_32( st->old_fpitch, L_deposit_h( shr( st->L_frame, 1 ) ) ) ) || ( LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) ) @@ -454,9 +460,8 @@ Word16 GetPLCModeDecision_ivas_fx( { Word32 pitch; - pitch = L_deposit_h( 0 ); - if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) + IF( GT_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) { pitch = L_add( st->old_fpitch, 0 ); } @@ -464,7 +469,7 @@ Word16 GetPLCModeDecision_ivas_fx( // , (st->element_mode == IVAS_CPE_MDCT ? &(st->hTcxCfg->psychParamsTCX20) : st->hTcxCfg->psychParamsCurrent) //); - TonalMDCTConceal_Detect_ivas_fx( st->hTonalMDCTConc, pitch, &numIndices, ( st->element_mode == IVAS_CPE_MDCT ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ), + TonalMDCTConceal_Detect_ivas_fx( st->hTonalMDCTConc, pitch, &numIndices, ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ? &( st->hTcxCfg->psychParamsTCX20 ) : st->hTcxCfg->psychParamsCurrent ), st->element_mode ); test(); @@ -473,7 +478,8 @@ Word16 GetPLCModeDecision_ivas_fx( test(); test(); test(); - IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( 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, 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*/ ) ) ) ) + test(); + IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( GT_16( numIndices, 0 ) && ( ( LE_16( st->last_good, 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(); @@ -486,10 +492,10 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); } } - ELSE IF( st->last_core != ACELP_CORE ) + ELSE IF( NE_16( st->last_core, ACELP_CORE ) ) { test(); - if ( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) + IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = st->last_core; move16(); @@ -515,15 +521,19 @@ Word16 GetPLCModeDecision_fx( IF( EQ_16( st->flagGuidedAcelp, 1 ) ) { - st->old_pitch_buf_fx[2 * st->nb_subfr] = L_deposit_h( st->guidedT0 ); - st->old_pitch_buf_fx[2 * st->nb_subfr + 1] = L_deposit_h( st->guidedT0 ); + st->old_pitch_buf_fx[shl( st->nb_subfr, 1 )] = L_deposit_h( st->guidedT0 ); + move32(); + st->old_pitch_buf_fx[add( shl( st->nb_subfr, 1 ), 1 )] = L_deposit_h( st->guidedT0 ); + move32(); st->mem_pitch_gain[0] = st->mem_pitch_gain[1] = 16384 /*1.f Q14*/; /*Q14*/ + move16(); + move16(); } st->plc_use_future_lag = 0; move16(); test(); test(); - if ( ( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified != 0 ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) + IF( ( GT_16( st->last_core, ACELP_CORE ) && NE_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) { /* no updates needed here, because already updated in last good frame */ st->plc_use_future_lag = 1; @@ -536,7 +546,7 @@ Word16 GetPLCModeDecision_fx( move16(); st->last_core = ACELP_CORE; move16(); - if ( st->Opt_AMR_WB ) + IF( st->Opt_AMR_WB ) { core = ACELP_CORE; move16(); @@ -548,7 +558,7 @@ Word16 GetPLCModeDecision_fx( { core = ACELP_CORE; move16(); - if ( GT_16( st->nbLostCmpt, 1 ) ) + IF( GT_16( st->nbLostCmpt, 1 ) ) { core = st->last_core_bfi; move16(); @@ -580,11 +590,11 @@ Word16 GetPLCModeDecision_fx( pitch = L_deposit_h( 0 ); - if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) + IF( GT_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) { pitch = L_add( st->old_fpitch, 0 ); } - if ( st->element_mode == EVS_MONO ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { TonalMDCTConceal_Detect( &st->tonalMDCTconceal, pitch, &numIndices, st->element_mode #ifdef ADD_IVAS_HTONALMDCTCONC @@ -593,7 +603,7 @@ Word16 GetPLCModeDecision_fx( #endif ); } - else + ELSE { TonalMDCTConceal_Detect( st->hTonalMDCTConc, pitch, &numIndices, st->element_mode #ifdef ADD_IVAS_HTONALMDCTCONC @@ -609,7 +619,8 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); - IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( 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, 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*/ ) ) ) ) + test(); + IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( GT_16( numIndices, 0 ) && ( ( LE_16( st->last_good, 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(); @@ -622,10 +633,10 @@ Word16 GetPLCModeDecision_fx( move16(); } } - ELSE IF( st->last_core != ACELP_CORE ) + ELSE IF( NE_16( st->last_core, ACELP_CORE ) ) { test(); - if ( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) + IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = st->last_core; move16(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index ee61b4b43..81cfae830 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -131,7 +131,7 @@ void hq_core_dec_fx( { hHQ_core->HqVoicing = 0; move16(); - if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) + IF ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { hHQ_core->HqVoicing = 1; move16(); diff --git a/lib_dec/hq_env_dec_fx.c b/lib_dec/hq_env_dec_fx.c index d89c24fc1..14037b5f6 100644 --- a/lib_dec/hq_env_dec_fx.c +++ b/lib_dec/hq_env_dec_fx.c @@ -66,11 +66,12 @@ Word16 decode_envelope_indices_fx( /* o : Number of b ELSE { hcode_l = 0; - IF( LCmode == 0 ) + move16(); + IF( EQ_16( LCmode, 0 ) ) { hdecnrm_context_fx( st_fx, num_sfm, &difidx[start_norm], &hcode_l ); } - ELSE IF( LCmode == 1 ) + ELSE IF( EQ_16( LCmode, 1 ) ) { startNormPlus1 = add( start_norm, 1 ); hdecnrm_resize_fx( st_fx, num_sfm, &difidx[startNormPlus1] ); @@ -106,7 +107,7 @@ Word16 decode_envelope_indices_fx( /* o : Number of b } } } - ELSE IF( LCmode == 2 ) + ELSE IF( EQ_16( LCmode, 2 ) ) { startNormPlus1 = add( start_norm, 1 ); hdecnrm_fx( st_fx, num_sfm, &difidx[start_norm + 1] ); diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 0a615b317..3ed9d6f0a 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -240,7 +240,7 @@ void hq_lr_dec_fx( { num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); } - if ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) + IF ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { flag_spt_fx = 1; move16(); @@ -435,7 +435,7 @@ void hq_lr_dec_fx( #else Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + IF ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } @@ -564,7 +564,7 @@ void hq_lr_dec_fx( ELSE { Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ - if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + IF ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q13 */ } @@ -798,7 +798,7 @@ void hq_lr_dec_fx( #else Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - if ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + IF ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } @@ -1043,7 +1043,7 @@ static Word16 decode_huff_8s_fx( { Word16 bit; - WHILE( *hufftab > 0 ) + WHILE( GT_16( *hufftab, 0 ) ) { *rbits = add( *rbits, s_and( *hufftab, 0xf ) ); bit = get_next_indice( st_fx, s_and( *hufftab, 0xf ) ); @@ -1069,13 +1069,13 @@ static Word16 large_symbol_dec_fx( /* o : bits move16(); ns2mode = get_next_indice( st_fx, BITS_DE_8SMODE ); - IF( ns2mode == 0 ) + IF( EQ_16( ns2mode, 0 ) ) { ns2mode0 = get_next_indice( st_fx, BITS_DE_8SMODE_N0 ); ns2mode1 = get_next_indice( st_fx, BITS_DE_8SMODE_N1 ); cntbits = add( cntbits, BITS_DE_8SMODE_N0 + BITS_DE_8SMODE_N1 ); - IF( ns2mode0 == 0 ) + IF( EQ_16( ns2mode0, 0 ) ) { IF( EQ_16( ns2mode1, 1 ) ) { @@ -1210,7 +1210,7 @@ static Word16 band_energy_dequant_fx( /* parsing energy difference coding mode */ deng_cmode = get_next_indice( st_fx, BITS_DE_CMODE ); - IF( deng_cmode == 0 ) + IF( EQ_16( deng_cmode, 0 ) ) { deng_bits = large_symbol_dec_fx( st_fx, bq2_fx, bands_fx ); diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index cddeec0de..4ae2c9ebd 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -48,17 +48,17 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou { tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ - if ( cond[i] == 0 ) + IF( EQ_16( cond[i], 0 ) ) { tmp32 = L_deposit_h( 0 ); } - if ( tmp32 >= 0 ) + IF( GE_32( tmp32, 0 ) ) { x_max = L_max( x_max, tmp32 ); } - if ( tmp32 < 0 ) + IF( LT_32( tmp32, 0 ) ) { x_min = L_min( x_min, tmp32 ); } @@ -69,11 +69,11 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou i_min = 0x20; move16(); - if ( x_max != 0 ) + IF( NE_32( x_max, 0 ) ) { i_max = norm_l( x_max ); } - if ( x_min != 0 ) + IF( NE_32( x_min, 0 ) ) { i_min = norm_l( x_min ); } @@ -111,15 +111,15 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou FOR( sb = start; sb < stop; sb++ ) { - if ( TCXNoise[sb] ) + IF ( TCXNoise[sb] ) { tmp16 = extract_h( L_shl( in[sb], s_l ) ); } - if ( TCXNoise[sb] ) + IF ( TCXNoise[sb] ) { nE = L_mac( nE, tmp16, tmp16 ); } - if ( TCXNoise[sb] ) + IF ( TCXNoise[sb] ) { noise = add( noise, 1 ); } @@ -157,19 +157,19 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in FOR( sb = start; sb < stop; sb++ ) { - if ( TCXNoise[sb] ) + IF ( TCXNoise[sb] ) { val = Random( nfSeed ); } - if ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { in[sb] = L_deposit_l( val ); } - if ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { val = shr( val, 5 ); } - if ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { rE = L_mac( rE, val, val ); } @@ -179,20 +179,20 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in /* make sure that rE is never 0 */ - if ( rE == 0 ) + IF( EQ_32( rE, 0 ) ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - if ( totalNoiseNrg == 0 ) + IF( EQ_32( totalNoiseNrg, 0 ) ) { rE = L_max( rE, 0x00010000 ); } /* make sure that rE is never smaller than totalNoiseNrg */ L_tmp = L_sub( rE, totalNoiseNrg ); - if ( L_tmp < 0 ) + IF( LT_32( L_tmp, 0 ) ) { rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ move32(); @@ -204,7 +204,7 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in FOR( sb = start; sb < stop; sb++ ) { - if ( TCXNoise[sb] ) + IF ( TCXNoise[sb] ) { in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); move32(); @@ -256,18 +256,18 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in } - IF( n_noise_bands_tile != 0 ) + IF( NE_16( n_noise_bands_tile, 0 ) ) { noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 /* make sure that rE is never 0 */ - if ( rE == 0 ) + IF ( EQ_32(rE, 0) ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - if ( totalNoiseNrg == 0 ) + IF ( EQ_32(totalNoiseNrg, 0) ) { rE = L_max( rE, 0x00010000 ); } @@ -338,18 +338,18 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, } - IF( n_noise_bands_tile != 0 ) + IF( NE_16( n_noise_bands_tile, 0 ) ) { noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 /* make sure that rE is never 0 */ - IF( rE == 0 ) + IF( EQ_32(rE, 0) ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - IF( totalNoiseNrg == 0 ) + IF( EQ_32(totalNoiseNrg, 0) ) { rE = L_max( rE, 0x00010000 ); } @@ -391,7 +391,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, tmp = get_next_indice( st, 1 ); - IF( tmp == 0 ) + IF( EQ_16(tmp, 0) ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; move16(); @@ -403,7 +403,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; move16(); - if ( tmp == 0 ) + IF ( EQ_16(tmp, 0) ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); @@ -436,7 +436,7 @@ static void IGF_setLinesToZero( const Word16 startLine, /**< in if there is content in the original MDCT spectrum */ FOR( i = startLine; i < stopLine; i++ ) { - if ( pSpectralData[i] != 0 ) + IF ( NE_32(pSpectralData[i], 0) ) { pPowerSpecIGF[i] = L_deposit_l( 0 ); } @@ -547,7 +547,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; move16(); - IF( abs_sum != 0 ) + IF( NE_32(abs_sum, 0) ) { FOR( i = strt_cpy; i < startLine; i++ ) { @@ -572,7 +572,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* medium whitening detected */ IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) { - IF( n_noise_bands != 0 ) + IF( NE_16(n_noise_bands, 0) ) { IGF_replaceTCXNoise_2( igf_spec, TCXNoise, @@ -595,7 +595,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* off whitening detectded */ ELSE { - IF( n_noise_bands_off != 0 ) + IF( NE_16(n_noise_bands_off, 0) ) { IGF_replaceTCXNoise_2( hPrivateData->pSpecFlat, TCXNoise, @@ -692,7 +692,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in IF( GT_16( element_mode, EVS_MONO ) ) { - tile_width = hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]] - hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; + tile_width = sub(hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]); stop = add( strt_cpy, tile_width ); } ELSE @@ -717,7 +717,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; move16(); - IF( abs_sum != 0 ) + IF( NE_32(abs_sum, 0) ) { FOR( i = strt_cpy; i < stop; i++ ) { @@ -744,7 +744,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { IF( GT_16( element_mode, EVS_MONO ) ) { - IF( n_noise_bands != 0 ) + IF( NE_16(n_noise_bands, 0) ) { IGF_replaceTCXNoise_2_new_ivas( igf_spec, specMed_e, @@ -759,7 +759,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } ELSE { - IF( n_noise_bands != 0 ) + IF( NE_16(n_noise_bands, 0) ) { IGF_replaceTCXNoise_2( igf_spec, TCXNoise, @@ -785,7 +785,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in IF( GT_16( element_mode, EVS_MONO ) ) { - IF( n_noise_bands_off != 0 ) + IF( NE_16(n_noise_bands_off, 0) ) { IGF_replaceTCXNoise_2_new_ivas( src_spec, src_spec_e, @@ -800,7 +800,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } ELSE { - IF( n_noise_bands_off != 0 ) + IF( NE_16(n_noise_bands_off, 0) ) { IGF_replaceTCXNoise_2( src_spec, TCXNoise, @@ -1533,19 +1533,19 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* select correct hopsize for envelope refinement */ hopsize = 2; move16(); - if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) + IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) { hopsize = 4; move16(); } - if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) + IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) { hopsize = 1; move16(); } hopsize = s_min( hopsize, hPrivateData->igfInfo.maxHopsize ); - IF( hopsize > 1 ) + IF( GT_16(hopsize, 1) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { @@ -1571,7 +1571,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } /* IGF_rescale_SCF */ - IF( hGrid->infoIsRefined != 0 ) + IF( NE_16(hGrid->infoIsRefined, 0) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) { @@ -1628,7 +1628,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( L_tmp2 < 0 ) + IF( LT_32(L_tmp2, 0) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -1706,7 +1706,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( L_tmp2 < 0 ) + IF( LT_32(L_tmp2, 0) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -1731,7 +1731,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in negate( dN[start_sfb] ), dN_e[start_sfb], &tmp ); /* float: tmp = dE - dN[start_sfb] */ - IF( tmp < 0 ) + IF( LT_16(tmp, 0) ) { /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ L_tmp = L_mult( fFactor, tmp ); @@ -1752,7 +1752,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in sfb_p1 = add( start_sfb, 1 ); sfb_m1 = sub( stop_sfb, 1 ); test(); - IF( hGrid->infoIsRefined != 0 && EQ_16( hopsize, 1 ) ) + IF( NE_16(hGrid->infoIsRefined, 0) && EQ_16( hopsize, 1 ) ) { /* apply filter to absolute energy values: */ FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) @@ -1882,7 +1882,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* gain calculation */ gain[sfb] = 0; move16(); - IF( pN[sfb] != 0 ) + IF( NE_32(pN[sfb], 0) ) { tmp = BASOP_Util_Divide3232_Scale( dNlocal, pN[sfb], &s ); s = sub( add( s, dNlocal_e ), pN_e[sfb] ); @@ -1907,7 +1907,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*--- check gains /spectrum exponents for possible overflows --- */ /* get tile index */ - if ( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF ( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -1917,7 +1917,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*check whether overflow would occur and calculate Headroom, needed*/ shift = sub( L_tmp_e, *spectrum_e ); tmp = sub( shift, sub( norm_l( L_tmp ), TCX_IMDCT_HEADROOM ) ); - if ( tmp > 0 ) + IF ( GT_16(tmp, 0) ) { Hr = s_max( Hr, tmp ); } @@ -1925,7 +1925,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* disable rescaling if gain is smaler than 1 */ /* gain < 1, if norm_s(gain[sfb]) >= gain_e[sfb] */ tmp = sub( norm_s( gain[sfb] ), gain_e[sfb] ); - if ( tmp >= 0 ) + IF ( GE_16(tmp, 0) ) { Hr = 0; move16(); @@ -1935,7 +1935,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* Rescale spectrum if overflow may occur */ tileIdx = -1; move16(); - IF( Hr > 0 ) + IF( GT_16(Hr, 0) ) { /* rescale virtual Spec, cheap and easy: reset scalingfactor */ *virtualSpec_e = add( *virtualSpec_e, Hr ); @@ -1957,7 +1957,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2035,7 +2035,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *spectrum_e ); tmp = norm_l( L_tmp ) - shift - 32; - if ( tmp < 0 ) + IF ( LT_16(tmp, 0) ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2048,7 +2048,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *virtualSpec_e ); tmp = norm_l( L_tmp ) - shift - 32; - if ( tmp < 0 ) + IF ( LT_16(tmp, 0) ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2236,12 +2236,12 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* select correct hopsize for envelope refinement */ hopsize = 2; move16(); - if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) + IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) { hopsize = 4; move16(); } - if ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) + IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) { hopsize = 1; move16(); @@ -2252,7 +2252,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in hopsize = s_min( hopsize, 2 ); } - IF( hopsize > 1 ) + IF( GT_16(hopsize, 1) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { @@ -2278,7 +2278,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } /* IGF_rescale_SCF */ - IF( hGrid->infoIsRefined != 0 ) + IF( NE_16(hGrid->infoIsRefined, 0) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) { @@ -2335,7 +2335,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( L_tmp2 < 0 ) + IF( LT_32(L_tmp2, 0) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -2402,7 +2402,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); - IF( L_tmp2 < 0 ) + IF( LT_32(L_tmp2, 0) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -2427,7 +2427,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in negate( dN[start_sfb] ), dN_e[start_sfb], &tmp ); /* float: tmp = dE - dN[start_sfb] */ - IF( tmp < 0 ) + IF( LT_16(tmp, 0) ) { /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ L_tmp = L_mult( fFactor, tmp ); @@ -2448,7 +2448,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in sfb_p1 = add( start_sfb, 1 ); sfb_m1 = sub( stop_sfb, 1 ); test(); - IF( hGrid->infoIsRefined != 0 && EQ_16( hopsize, 1 ) ) + IF( NE_16(hGrid->infoIsRefined, 0) && EQ_16( hopsize, 1 ) ) { /* apply filter to absolute energy values: */ FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) @@ -2606,7 +2606,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2770,7 +2770,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in ak_norm = Mpy_32_16_r( ak, 2185 ); tmp_16 = sub( 31, norm_l( ak_norm ) ); - if ( ak == 0 ) + IF ( EQ_32(ak, 0) ) { tmp_16 = 0; move16(); @@ -2793,7 +2793,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); tmp_16 = sub( 31, norm_l( ak_norm ) ); - if ( ak == 0 ) + IF ( EQ_32(ak, 0) ) { tmp_16 = 0; move16(); @@ -2802,7 +2802,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); div = shl( 1, tmp_16 ); - if ( LT_32( ak, 16 ) ) + IF ( LT_32( ak, 16 ) ) { div = 1; move16(); @@ -3050,12 +3050,12 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in move16(); } - IF( isIndepFrame == 0 ) + IF( EQ_16(isIndepFrame, 0) ) { tmp = get_next_indice( st, 1 ); } - IF( tmp == 1 ) + IF( EQ_16(tmp, 1) ) { FOR( p = 0; p < nT; p++ ) { @@ -3066,16 +3066,18 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in ELSE { IGF_decode_whitening_level( st, hPrivateData, 0 ); + test(); IF( hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_SWB_48000_CPE || hPrivateData->igfInfo.bitRateIndex == IGF_BITRATE_FB_48000_CPE ) { tmp = 0; + move16(); } ELSE { tmp = get_next_indice( st, 1 ); } - IF( tmp == 1 ) + IF( EQ_16(tmp, 1) ) { FOR( p = 1; p < nT; p++ ) { @@ -3133,12 +3135,12 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins move16(); } - IF( isIndepFrame == 0 ) + IF( EQ_16(isIndepFrame, 0) ) { tmp = get_next_indice( st, 1 ); } - IF( tmp == 1 ) + IF( EQ_16(tmp, 1) ) { FOR( p = 0; p < nT; p++ ) { @@ -3150,7 +3152,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins { IGF_decode_whitening_level( st, hPrivateData, 0 ); tmp = get_next_indice( st, 1 ); - IF( tmp == 1 ) + IF( EQ_16(tmp, 1) ) { FOR( p = 1; p < nT; p++ ) { @@ -3205,7 +3207,7 @@ void IGFDecReadLevel( /**< ou move16(); IGFAllZero = get_next_indice( st, 1 ); - IF( IGFAllZero == 0 ) + IF( EQ_16(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] */ igfGridIdx, isIndepFrame ); @@ -3266,17 +3268,18 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); /* concealment counter */ - IF( bfi != 0 ) + IF( NE_16(bfi, 0) ) { hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); } ELSE { hPrivateData->frameLossCounter = 0; + move16(); } /* skip IGF processing if all IGF levels are zero */ - IF( hInstance->infoIGFAllZero == 0 ) + IF( EQ_16(hInstance->infoIGFAllZero, 0) ) { @@ -3433,7 +3436,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); /* concealment counter */ - IF( bfi != 0 ) + IF( NE_16(bfi, 0) ) { hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); } @@ -3444,7 +3447,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } /* skip IGF processing if all IGF levels are zero */ - IF( hInstance->infoIGFAllZero == 0 ) + IF( EQ_16(hInstance->infoIGFAllZero, 0) ) { FOR( i = 0; i < hGrid->nTiles; i++ ) { @@ -4048,16 +4051,21 @@ void IGFDecUpdateInfo_ivas_fx( { hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; hIGFDec->infoIGFStartFreq = hGrid->startFrequency; + move16(); hIGFDec->infoIGFStopFreq = hGrid->stopFrequency; + move16(); hIGFDec->infoIGFStartLine = hGrid->startLine; + move16(); hIGFDec->infoIGFStopLine = hGrid->stopLine; + move16(); } /* TODO: this was added to keep the EVS 16-bit noise info in sync. */ - FOR( int l = 0; l < IGF_START_MX; l++ ) + FOR( Word16 l = 0; l < IGF_START_MX; l++ ) { // u8bit to 16bit hIGFDec->infoTCXNoise_evs[l] = (Word16) hIGFDec->infoTCXNoise[l]; + move16(); } return; @@ -4265,9 +4273,9 @@ Word16 get_igf_startline( { Word16 igf_startline; - IF( st->igf == 0 ) + IF( EQ_16(st->igf, 0) ) { - IF( st->narrowBand == 0 ) + IF( EQ_16(st->narrowBand, 0) ) { /* minimum needed for output with sampling rates lower then the nominal sampling rate */ diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index ec6d6276a..a622058d7 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -27,9 +27,9 @@ void IGFSCFDecoderOpen( { - 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; + hPublicData->scfCountLongBlock[0] = sub(hIgfInfo->grid[0].swb_offset_len, 1); + hPublicData->scfCountLongBlock[1] = sub(hIgfInfo->grid[1].swb_offset_len, 1); + hPublicData->scfCountLongBlock[2] = sub(hIgfInfo->grid[2].swb_offset_len, 1); move16(); move16(); move16(); @@ -54,7 +54,7 @@ static Word16 quant_ctx_fx( result = s_min( abs_s( ctx ), IGF_CTX_OFFSET ); /* limit the absolute value to IGF_CTX_OFFSET */ - if ( ctx < 0 ) /* add the sign back, if needed */ + IF( LT_16( ctx, 0 ) ) /* add the sign back, if needed */ { result = negate( result ); } @@ -80,7 +80,7 @@ static Word16 arith_decode_bits_fx( x = lshl( x, 1 ); /* decode one bit using the new raw AC function */ bit = ari_decode_14bits_bit_ext_fx( st, &hPrivateData->acState ); - if ( bit != 0 ) + IF( NE_16( bit, 0 ) ) { x = s_or( x, 1 ); } @@ -107,7 +107,7 @@ static Word16 arith_decode_residual_fx( /* meaning of the values of val: */ /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */ test(); - IF( ( val != 0 ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) + IF( ( NE_16( val, 0 ) ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) { x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ @@ -133,12 +133,12 @@ static Word16 arith_decode_residual_fx( extra = add( 15, extra ); } - if ( val == 0 ) + IF( EQ_16( val, 0 ) ) { /* escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); } - if ( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) + IF( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) { /* escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); @@ -186,9 +186,9 @@ static void decode_sfe_vector_fx( FOR( f = 0; f < length; ++f ) { - IF( t == 0 ) + IF( EQ_16( t, 0 ) ) { - IF( f == 0 ) + IF( EQ_16( f, 0 ) ) { /* (t == 0) && (f == 0) */ /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ @@ -228,7 +228,7 @@ static void decode_sfe_vector_fx( ELSE { /* t == 1 */ - IF( f == 0 ) + IF( EQ_16( f, 0 ) ) { /* (t == 1) && (f == 0) */ res = arith_decode_residual_fx( hPrivateData, @@ -264,7 +264,7 @@ static void decode_sfe_vector_fx( } } - IF( x[f] < 0 ) + IF( LT_16(x[f], 0) ) { x[f] = 0; move16(); @@ -293,6 +293,7 @@ void IGFSCFDecoderReset( /* reset of coder */ hPublicData->t = 0; /* indicate that an independent block follows */ + move16(); /* we do not need to fill hPublicData->prev with zeros, because when t = 0 no previous information is used */ } @@ -314,7 +315,7 @@ void IGFSCFDecoderDecode( ari_start_decoding_14bits_fx( st, &hPublicData->acState ); /* start AC decoding */ /* check if coder needs a reset and do it if necessary */ - IF( indepFlag != 0 ) + IF( NE_16( indepFlag, 0 ) ) { /* reset of coder */ IGFSCFDecoderReset( hPublicData ); diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 3f94cea06..b327a6c0b 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -129,7 +129,8 @@ ivas_error init_decoder_fx( * SWB BWE parameters *-----------------------------------------------------------------*/ - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( EQ_16(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 ) { @@ -147,7 +148,8 @@ ivas_error init_decoder_fx( * IGF *-----------------------------------------------------------------*/ - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + test(); + IF( ( EQ_16(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 ) { @@ -205,7 +207,9 @@ ivas_error init_decoder_fx( 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 ) ) + test(); + test(); + IF( ( EQ_16(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 ) { @@ -223,7 +227,6 @@ ivas_error init_decoder_fx( * parameters for fast recovery (WI) *-----------------------------------------------------------------*/ test(); - test(); IF( EQ_32( st_fx->output_Fs, 16000 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) { IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) count_malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) @@ -234,7 +237,7 @@ ivas_error init_decoder_fx( 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 + ELSE { st_fx->hWIDec = NULL; } @@ -243,6 +246,8 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * NB/formant post-filter *-----------------------------------------------------------------*/ + 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->hPFstat = (PFSTAT_HANDLE) count_malloc( sizeof( PFSTAT ) ) ) == NULL ) @@ -324,10 +329,13 @@ ivas_error init_decoder_fx( move16(); #ifdef MSAN_FIX st_fx->Q_stat_noise = 31; + move16(); #endif // MSAN_FIX /*-----------------------------------------------------------------* * LD music post-filter *-----------------------------------------------------------------*/ + 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->hMusicPF = (MUSIC_POSTFILT_HANDLE) count_malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) @@ -346,9 +354,9 @@ ivas_error init_decoder_fx( 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( EQ_16(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 ) + 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" ) ); } @@ -420,7 +428,7 @@ ivas_error init_decoder_fx( 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( ( EQ_16(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 ) { @@ -453,8 +461,11 @@ ivas_error init_decoder_fx( move16(); } st_fx->Qprev_synth_buffer_fx = 15; + move16(); st_fx->old_bfi_cnt = 0; + move16(); st_fx->prev_old_bfi = 0; + 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 ); IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) @@ -466,7 +477,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ /* TCX-LTP */ - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( EQ_16(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 ) { @@ -480,7 +491,7 @@ ivas_error init_decoder_fx( /* 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( EQ_16(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 ) { @@ -497,7 +508,7 @@ ivas_error init_decoder_fx( st_fx->hTcxDec = NULL; } /* TCX config. data structure */ - IF( ( idchan == 0 || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( EQ_16(idchan, 0) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { @@ -524,10 +535,10 @@ ivas_error init_decoder_fx( * TBE parameters *-----------------------------------------------------------------*/ - - IF( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + test(); + IF( EQ_16(idchan, 0) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - if ( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) count_malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + 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" ) ); } @@ -540,6 +551,7 @@ ivas_error init_decoder_fx( #ifdef MSAN_FIX st_fx->hBWE_TD->prev_hb_synth_fx_exp = 31; + move16(); #endif } ELSE @@ -548,7 +560,9 @@ ivas_error init_decoder_fx( } st_fx->tilt_swb_fx = 0; + move16(); st_fx->tilt_wb_fx = 0; + move16(); st_fx->prev_ener_shb_fx = 0; move16(); @@ -608,6 +622,7 @@ ivas_error init_decoder_fx( /*----------------------------------------------------------------------------------* * AMR-WB IO mode parameters *----------------------------------------------------------------------------------*/ + test(); IF( st_fx->Opt_AMR_WB || 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 ) @@ -628,8 +643,9 @@ ivas_error init_decoder_fx( /*-----------------------------------------------------------------* * HF (6-7kHz) (zero) BWE parameters *-----------------------------------------------------------------*/ - - IF( ( idchan == 0 && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + test(); + test(); + IF( ( EQ_16(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 ) { @@ -650,13 +666,13 @@ ivas_error init_decoder_fx( st_fx->bpf_off = 0; + 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( ( EQ_16(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 ) { @@ -673,18 +689,18 @@ ivas_error init_decoder_fx( * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ /* open analysis for max. SR 48kHz */ - if ( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ) != IVAS_ERR_OK ) + IF ( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ) != IVAS_ERR_OK ) { return error; } /* open analysis BPF for max. SR 16kHz */ - if ( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ) != IVAS_ERR_OK ) + IF ( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ) != IVAS_ERR_OK ) { return error; } /* open synthesis for output SR */ - if ( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ) != IVAS_ERR_OK ) + IF ( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ) != IVAS_ERR_OK ) { return error; } @@ -767,15 +783,17 @@ ivas_error init_decoder_fx( resampleCldfb( st_fx->cldfbAna, newCldfbBands, st_fx->L_frame, 1 ); resampleCldfb( st_fx->cldfbBPF, newCldfbBands, st_fx->L_frame, 1 ); + + test(); #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*/ ) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16(idchan, 0) ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) #endif { /* Create FD_CNG instance */ - if ( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ) != IVAS_ERR_OK ) + IF ( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ) != IVAS_ERR_OK ) { return error; } @@ -789,6 +807,7 @@ ivas_error init_decoder_fx( } st_fx->lp_noise = -167772160l /*-20.f Q23*/; + move32(); st_fx->force_lpd_reset = 0; move16(); @@ -822,13 +841,21 @@ ivas_error init_decoder_fx( *----------------------------------------------------------------------------------*/ #if 1 // IVAS_CODE -> To be verified st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ + move16(); st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + move16(); st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + move16(); st_fx->element_mode = EVS_MONO; /* element mode */ + move16(); st_fx->last_element_mode = st_fx->element_mode; /* element mode */ + move16(); st_fx->element_brate = -1; /* element bitrate */ + move16(); st_fx->low_rate_mode = 0; /* low-rate mode flag */ + move16(); st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ + move16(); // st_fx->cng_ism_flag = 0; // st_fx->coder_type = GENERIC; /* low-rate mode flag */ @@ -837,7 +864,9 @@ ivas_error init_decoder_fx( st_fx->id_element = -1; /* element ID */ #endif st_fx->extl_orig = -1; /* extension layer */ + move16(); st_fx->extl_brate_orig = 0; /* extension layer bitrate */ + move16(); return error; } @@ -1078,6 +1107,8 @@ ivas_error init_decoder_ivas_fx( st_fx->Last_GSC_noisy_speech_flag = 0; move16(); + test(); + test(); IF( ( EQ_16( 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 ) @@ -1095,7 +1126,8 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * parameters for fast recovery (WI) *-----------------------------------------------------------------*/ - + + test(); IF( EQ_32( st_fx->output_Fs, 16000 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) { IF( ( st_fx->hWIDec = (WI_DEC_HANDLE) count_malloc( sizeof( WI_DEC_DATA ) ) ) == NULL ) @@ -1114,6 +1146,8 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * NB/formant post-filter *-----------------------------------------------------------------*/ + test(); + test(); IF( ( EQ_16( 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 ) @@ -1133,7 +1167,9 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * HF (6-7kHz) (zero) BWE parameters *-----------------------------------------------------------------*/ - + + test(); + test(); IF( ( EQ_16( 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) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) @@ -1154,7 +1190,8 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * LD music post-filter *-----------------------------------------------------------------*/ - + test(); + test(); IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { IF( ( st_fx->hMusicPF = (MUSIC_POSTFILT_HANDLE) count_malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) @@ -1186,9 +1223,12 @@ ivas_error init_decoder_ivas_fx( st_fx->active_cnt = 20; move16(); + test(); + test(); + test(); IF( EQ_16( 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 ) + 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" ) ); } @@ -1223,6 +1263,9 @@ ivas_error init_decoder_ivas_fx( set16_fx( st_fx->old_synth_sw_fx, 0, NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS ) ); } + test(); + test(); + test(); IF( ( EQ_16( 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) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) @@ -1258,9 +1301,10 @@ ivas_error init_decoder_ivas_fx( * TBE parameters *-----------------------------------------------------------------*/ + test(); IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - if ( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + IF ( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } @@ -1283,7 +1327,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * SWB BWE parameters *-----------------------------------------------------------------*/ - + test(); IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) @@ -1346,7 +1390,7 @@ ivas_error init_decoder_ivas_fx( /*----------------------------------------------------------------------------------* * AMR-WB IO mode parameters *----------------------------------------------------------------------------------*/ - + test(); IF( st_fx->Opt_AMR_WB || 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 ) @@ -1402,6 +1446,8 @@ ivas_error init_decoder_ivas_fx( st_fx->bpf_off = 0; move16(); + test(); + test(); IF( ( EQ_16( 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) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) @@ -1419,7 +1465,8 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ - + test(); + test(); IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { /* open analysis for max. SR 48kHz */ @@ -1518,6 +1565,7 @@ ivas_error init_decoder_ivas_fx( *-----------------------------------------------------------------*/ /* TCX-LTP */ + test(); IF( ( EQ_16( 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 ) @@ -1531,6 +1579,7 @@ ivas_error init_decoder_ivas_fx( } /* TCX core */ + test(); IF( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { IF( ( st_fx->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) @@ -1549,6 +1598,7 @@ ivas_error init_decoder_ivas_fx( } /* TCX config. data structure */ + test(); IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) @@ -1562,6 +1612,7 @@ ivas_error init_decoder_ivas_fx( } /* Tonal MDCT concealment data structure */ + test(); IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) @@ -1577,7 +1628,8 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * IGF *-----------------------------------------------------------------*/ - + + test(); IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) @@ -1644,6 +1696,7 @@ ivas_error init_decoder_ivas_fx( st_fx->m_old_frame_type = ACTIVE_FRAME; move16(); + test(); IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { resampleCldfb_ivas_fx( st_fx->cldfbAna, L_mult0( st_fx->L_frame, FRAMES_PER_SEC ) ); @@ -1654,6 +1707,9 @@ ivas_error init_decoder_ivas_fx( * FD-CNG decoder *-----------------------------------------------------------------*/ + test(); + test(); + test(); IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( idchan, 0 ) ) && NE_16( mc_mode, MC_MODE_MCT ) && NE_16( mc_mode, MC_MODE_PARAMUPMIX ) ) { /* Create FD_CNG instance */ diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index cedf36a6e..0024e7464 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -60,61 +60,71 @@ void inov_decode_fx( IF( EQ_16( L_frame, L_FRAME ) ) { g1 = FORMANT_SHARPENING_G1; + move16(); g2 = FORMANT_SHARPENING_G2; + move16(); } ELSE { g1 = FORMANT_SHARPENING_G1_16k; + move16(); g2 = FORMANT_SHARPENING_G2_16k; + move16(); } IF( !Opt_AMR_WB ) { - if ( st_fx->acelp_cfg.fcb_mode ) + IF ( st_fx->acelp_cfg.fcb_mode ) { - int16_t i; - int16_t indexing_indices[8], wordcnt, bitcnt; + Word16 i; + Word16 indexing_indices[8], wordcnt, bitcnt; PulseConfig config; - if ( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr] >= 0 ) + test(); + test(); + test(); + IF( GE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr], 0 ) ) { - if ( L_subfr == 2 * L_SUBFR ) + IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + move16(); - if ( nBits == 8 ) + IF( EQ_16( nBits, 8 ) ) { // dec_acelp_1t64(st_fx, code, L_subfr); dec_acelp_1t64_fx( st_fx, code, L_subfr ); } - else + ELSE { // dec_acelp_fast(st_fx, nBits, code, L_subfr); dec_acelp_fast_fx( 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 ) ) + ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( EQ_16( st_fx->idchan, 0 ) && LE_16( 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 ) + IF( EQ_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 0 ) ) { // dec_acelp_1t64(st_fx, code, L_SUBFR); dec_acelp_1t64_fx( st_fx, code, L_SUBFR ); } - else + ELSE { // dec_acelp_fast(st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR); dec_acelp_fast_fx( st_fx, st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], code, L_SUBFR ); } } - else + ELSE { wordcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) >> 4; + move16(); bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; + move16(); // PMT("CONDITION above is missing -> idchan") - for ( i = 0; i < wordcnt; i++ ) + FOR ( i = 0; i < wordcnt; i++ ) { indexing_indices[i] = get_next_indice( st_fx, 16 ); } - if ( bitcnt ) + IF( bitcnt ) { indexing_indices[i] = get_next_indice( st_fx, bitcnt ); } @@ -122,14 +132,15 @@ void inov_decode_fx( D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); } } - else + ELSE { set16_fx( code, 0, L_SUBFR ); } } - else + ELSE { nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + move16(); IF( EQ_16( nBits, 7 ) ) { @@ -237,12 +248,16 @@ void inov_decode_ivas_fx( IF( EQ_16( L_frame, L_FRAME ) ) { g1 = FORMANT_SHARPENING_G1; + move16(); g2 = FORMANT_SHARPENING_G2; + move16(); } ELSE { g1 = FORMANT_SHARPENING_G1_16k; + move16(); g2 = FORMANT_SHARPENING_G2_16k; + move16(); } IF( !Opt_AMR_WB ) @@ -253,6 +268,9 @@ void inov_decode_ivas_fx( Word16 i; Word16 indexing_indices[8], wordcnt, bitcnt; PulseConfig config; + test(); + test(); + test(); IF( GE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr], 0 ) ) { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) @@ -270,7 +288,7 @@ void inov_decode_ivas_fx( dec_acelp_fast_fx( st_fx, nBits, code, L_subfr ); } } - ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( 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 ) ) + ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( EQ_16( st_fx->idchan, 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) { IF( EQ_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 0 ) ) { @@ -286,7 +304,9 @@ void inov_decode_ivas_fx( ELSE { wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); + move16(); bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; + move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { @@ -309,6 +329,7 @@ void inov_decode_ivas_fx( #endif { nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + move16(); IF( EQ_16( nBits, 7 ) ) { diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 6c09458ba..70a8a0e2e 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -1091,13 +1091,11 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply residual mixing */ - matrix_product_fx( mixing_matrix_res_smooth_fx, nY, nY, 0, diff_f_real_fx, nY, 1, 0, output_f_real_fx ); - output_f_real_e = add( mixing_matrix_res_smooth_e, 25 ); + matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_real_fx, 25, nY, 1, 0, output_f_real_fx, &output_f_real_e ); scale_sig32( output_f_real_fx, nY, 6 - ( 31 - output_f_real_e ) ); - matrix_product_fx( mixing_matrix_res_smooth_fx, nY, nY, 0, diff_f_imag_fx, nY, 1, 0, output_f_imag_fx ); - output_f_imag_e = mixing_matrix_res_smooth_e + 25; + matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_imag_fx, 25, nY, 1, 0, output_f_imag_fx, &output_f_imag_e ); scale_sig32( output_f_imag_fx, nY, 6 - ( 31 - output_f_imag_e ) ); FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) @@ -1131,13 +1129,11 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply mixing matrix */ - matrix_product_fx( mixing_matrix_smooth_fx, nY, nX, 0, input_f_real_fx, nX, 1, 0, output_f_real_fx ); - output_f_real_e = add( mixing_matrix_smooth_e, 25 ); + matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_real_fx, 25, nX, 1, 0, output_f_real_fx, &output_f_real_e ); scale_sig32( output_f_real_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_real_e ) ) ); - matrix_product_fx( mixing_matrix_smooth_fx, nY, nX, 0, input_f_imag_fx, nX, 1, 0, output_f_imag_fx ); - output_f_imag_e = add( mixing_matrix_smooth_e, 25 ); + matrix_product_mant_exp_fx( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, nY, nX, 0, input_f_imag_fx, 25, nX, 1, 0, output_f_imag_fx, &output_f_imag_e ); scale_sig32( output_f_imag_fx, MAX_CICP_CHANNELS, sub( 6, sub( 31, output_f_imag_e ) ) ); /* collect output */ @@ -1701,9 +1697,7 @@ Word16 computeMixingMatrices_fx( /* Computing Q*Cx*Q' */ - matrix_product_fx( Q_fx, lengthCy, lengthCx, 0, Cx_fx, lengthCx, lengthCx, 0, Q_Cx_fx ); - Q_Cx_e = Q_e + Cx_fx_e; - + matrix_product_mant_exp_fx( Q_fx, Q_e, lengthCy, lengthCx, 0, Cx_fx, Cx_fx_e, lengthCx, lengthCx, 0, Q_Cx_fx, &Q_Cx_e ); Word16 guard_bits = find_guarded_bits_fx( lengthCx + 1 ); @@ -1790,15 +1784,11 @@ Word16 computeMixingMatrices_fx( /* Computing the input matrix Kx'*Q'*G_hat'*Ky */ - matrix_product_fx( Kx_fx, lengthCx, lengthCx, 1, Q_fx, lengthCy, lengthCx, 1, mat_mult_buffer1_fx ); - mat_mult_buffer1_e = Kx_fx_e[0] + Q_e; - + matrix_product_mant_exp_fx( Kx_fx, Kx_fx_e[0], lengthCx, lengthCx, 1, Q_fx, Q_e, lengthCy, lengthCx, 1, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); matrix_diag_product_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCx, lengthCy, 0, G_hat_fx, G_hat_e, lengthCy, mat_mult_buffer2_fx, &mat_mult_buffer2_e ); - matrix_product_fx( mat_mult_buffer2_fx, lengthCx, lengthCy, 0, Ky_fx, lengthCy, lengthCy, 0, mat_mult_buffer1_fx ); - mat_mult_buffer1_e = mat_mult_buffer2_e + Ky_fx_e[0]; - + matrix_product_mant_exp_fx( mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCy, 0, Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); IF( lengthCx < lengthCy ) { @@ -1843,42 +1833,15 @@ Word16 computeMixingMatrices_fx( mat_mult_buffer1_e = 0; mat_mult_buffer2_e = 0; - guard_bits = find_guarded_bits_fx( lengthCx + 1 ); - FOR( i = 0; i < lengthCx * lengthCy; ++i ) - { - IF( mat_mult_buffer1_e > mat_mult_buffer1_e ) - { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); - } - ELSE - { - mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], guard_bits ); - } - } - - IF( mat_mult_buffer1_e > mat_mult_buffer2_e ) - { - mat_mult_buffer2_e += guard_bits; - } - ELSE - { - mat_mult_buffer1_e += guard_bits; - } - - matrix_product_fx( mat_mult_buffer1_fx, lengthCy, lengthCx, 0, - mat_mult_buffer2_fx, lengthCx, lengthCx, 1, - mat_mult_buffer3_fx ); - mat_mult_buffer3_e = mat_mult_buffer1_e + mat_mult_buffer2_e; + matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, + mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, + mat_mult_buffer3_fx, &mat_mult_buffer3_e ); /************************ Formulate M **********************/ - matrix_product_fx( Ky_fx, lengthCy, lengthCy, 0, mat_mult_buffer3_fx, lengthCy, lengthCx, 0, mat_mult_buffer1_fx ); - mat_mult_buffer1_e = Ky_fx_e[0] + mat_mult_buffer3_e; - - - matrix_product_fx( mat_mult_buffer1_fx, lengthCy, lengthCx, 0, Kx_reg_inv_fx, lengthCx, lengthCx, 0, mixing_matrix_fx ); - mixing_matrix_e = Kx_reg_inv_e[0] + mat_mult_buffer1_e; + matrix_product_mant_exp_fx( Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); + matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, Kx_reg_inv_fx, Kx_reg_inv_e[0], lengthCx, lengthCx, 0, mixing_matrix_fx, &mixing_matrix_e ); /*-----------------------------------------------------------------* * Formulate Cr @@ -1887,11 +1850,9 @@ Word16 computeMixingMatrices_fx( /* Compute Cy_tilde = M*Cx*M' */ - matrix_product_fx( mixing_matrix_fx, lengthCy, lengthCx, 0, Cx_fx, lengthCx, lengthCx, 0, mat_mult_buffer1_fx ); - mat_mult_buffer1_e = mixing_matrix_e + Cx_fx_e; + matrix_product_mant_exp_fx( mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, Cx_fx, Cx_fx_e, lengthCx, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e); - matrix_product_fx( mat_mult_buffer1_fx, lengthCy, lengthCx, 0, mixing_matrix_fx, lengthCy, lengthCx, 1, mat_mult_buffer2_fx ); - mat_mult_buffer2_e = mat_mult_buffer1_e + mixing_matrix_e; + matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 1, mat_mult_buffer2_fx, &mat_mult_buffer2_e); Cr_p_fx = Cr_fx; Cy_p_fx = Cy_fx; @@ -2490,44 +2451,20 @@ Word16 computeMixingMatricesResidual_fx( svdMat2mat_fx( svd_v_buffer_fx, mat_mult_buffer1_fx, lengthCy, lengthCx ); svdMat2mat_fx( svd_u_buffer_fx, mat_mult_buffer2_fx, lengthCx, lengthCx ); - mat_mult_buffer2_e = 0; - move16(); mat_mult_buffer1_e = 0; move16(); + mat_mult_buffer2_e = 0; + move16(); - Word16 guard_bits = find_guarded_bits_fx( lengthCx + 1 ); - - FOR( i = 0; i < lengthCy * lengthCx; ++i ) - { - IF( mat_mult_buffer1_e > mat_mult_buffer2_e ) - { - mat_mult_buffer2_fx[i] = L_shr( mat_mult_buffer2_fx[i], guard_bits ); - } - ELSE - { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); - } - } - - IF( mat_mult_buffer1_e > mat_mult_buffer2_e ) - { - mat_mult_buffer2_e += guard_bits; - } - ELSE - { - mat_mult_buffer1_e += guard_bits; - } - matrix_product_fx( mat_mult_buffer1_fx, lengthCy, lengthCx, 0, - mat_mult_buffer2_fx, lengthCx, lengthCx, 1, - mat_mult_buffer3_fx ); - mat_mult_buffer3_e = 0; + matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, + mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, + mat_mult_buffer3_fx, &mat_mult_buffer3_e); /*-----------------------------------------------------------------* * Formulate M *-----------------------------------------------------------------*/ - matrix_product_fx( Ky_fx, lengthCy, lengthCy, 0, mat_mult_buffer3_fx, lengthCy, lengthCx, 0, mat_mult_buffer1_fx ); - mat_mult_buffer1_e = Ky_fx_e[0] + mat_mult_buffer3_e; + matrix_product_mant_exp_fx( Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e); FOR( i = 0; i < num_outputs; i++ ) { @@ -2549,7 +2486,7 @@ Word16 computeMixingMatricesResidual_fx( matrix_diag_product_fx( mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, Cx_fx, Cx_e, lengthCx, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); - guard_bits = find_guarded_bits_fx( lengthCx + 1 ); + Word16 guard_bits = find_guarded_bits_fx( lengthCx + 1 ); FOR( i = 0; i < lengthCy * lengthCx; ++i ) { diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index fb846b91a..8b817242f 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -984,9 +984,11 @@ void ivas_updt_dec_common_fx( } #endif #ifdef NON_BE_1055_RESET_LP_MEMORIES - IF( ( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && ( EQ_16( st_fx->codec_mode, MODE2 ) || GT_16( st_fx->element_mode, EVS_MONO ) ) ) ) + IF( (LE_32(st_fx->core_brate , SID_2k40) && EQ_16(st_fx->cng_type , FD_CNG) ) || (st_fx->tcxonly && (EQ_16(st_fx->codec_mode , MODE2) || GT_16(st_fx->element_mode , EVS_MONO)) ) ) #else - IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) + IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) + || (st_fx->tcxonly && EQ_16(st_fx->codec_mode,MODE2)) + ) #endif { -- GitLab From 37f9b19490d5d86828f38a0911ce1a90ac5be286 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 12 Jun 2024 11:51:11 +0530 Subject: [PATCH 25/63] clang formatting changes --- lib_dec/dec4t64_fx.c | 6 +- lib_dec/hq_core_dec_fx.c | 2 +- lib_dec/hq_lr_dec_fx.c | 8 +- lib_dec/igf_dec_fx.c | 150 +++++++++++----------- lib_dec/igf_scf_dec_fx.c | 8 +- lib_dec/init_dec_fx.c | 66 +++++----- lib_dec/inov_dec_fx.c | 4 +- lib_dec/ivas_dirac_output_synthesis_cov.c | 14 +- lib_dec/updt_dec_fx.c | 6 +- 9 files changed, 130 insertions(+), 134 deletions(-) diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 882dd67f9..10e9b5b13 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -299,7 +299,7 @@ void dec_1p_N1_fx( /* i = ((index >> N) & 1); */ i = L_shr( index, N ) & 1L; - IF ( i != 0 ) + IF( i != 0 ) { pos1 = add( pos1, NB_POS_FCB_4T ); } @@ -697,7 +697,7 @@ static void fcb_decode_position_fx( FOR( ; PI_select_table[L_sub( 16, l )][temp] >= k; l += 2 ); - IF ( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) + IF( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) { l = L_sub( l, 1 ); } @@ -779,7 +779,7 @@ void D_ACELP_decode_43bit_fx( UWord16 idxs[], Word16 code[], Word16 *pulsestrack move32(); joint_index = L_shr( L_add( L_shl( (Word32) idxs[2], 16 ), (Word32) idxs[1] ), 2 ); - IF ( GE_32( joint_index, joint_offset ) ) + IF( GE_32( joint_index, joint_offset ) ) { joint_index = L_sub( joint_index, joint_offset ); } diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 81cfae830..e13071294 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -131,7 +131,7 @@ void hq_core_dec_fx( { hHQ_core->HqVoicing = 0; move16(); - IF ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) + IF( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { hHQ_core->HqVoicing = 1; move16(); diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 3ed9d6f0a..8a014d817 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -240,7 +240,7 @@ void hq_lr_dec_fx( { num_bits = sub( num_bits, get_usebit_npswb_fx( hqswb_clas_fx ) ); } - IF ( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) + IF( EQ_16( hqswb_clas_fx, HQ_NORMAL ) ) { flag_spt_fx = 1; move16(); @@ -435,7 +435,7 @@ void hq_lr_dec_fx( #else Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - IF ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } @@ -564,7 +564,7 @@ void hq_lr_dec_fx( ELSE { Ep_avrgL_fx = L_add( Ep_avrgL_fx, L_shr( Ep_tmp_fx[i], 1 ) ); /*Q12 */ - IF ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q13 */ } @@ -798,7 +798,7 @@ void hq_lr_dec_fx( #else Ep_avrgL_fx = L_add( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ #endif - IF ( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) + IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ } diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 4ae2c9ebd..deace01a0 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -109,26 +109,24 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou nE = 0; move32(); - FOR( sb = start; sb < stop; sb++ ) - { - IF ( TCXNoise[sb] ) - { + FOR( sb = start; sb < stop; sb++ ){ + IF( TCXNoise[sb] ){ tmp16 = extract_h( L_shl( in[sb], s_l ) ); - } - IF ( TCXNoise[sb] ) - { - nE = L_mac( nE, tmp16, tmp16 ); - } - IF ( TCXNoise[sb] ) - { - noise = add( noise, 1 ); - } - } +} +IF( TCXNoise[sb] ) +{ + nE = L_mac( nE, tmp16, tmp16 ); +} +IF( TCXNoise[sb] ) +{ + noise = add( noise, 1 ); +} +} - *totalNoiseNrg = nE; - move32(); +*totalNoiseNrg = nE; +move32(); - return noise; +return noise; } /**********************************************************************/ /* @@ -157,7 +155,7 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in FOR( sb = start; sb < stop; sb++ ) { - IF ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { val = Random( nfSeed ); } @@ -204,7 +202,7 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in FOR( sb = start; sb < stop; sb++ ) { - IF ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); move32(); @@ -261,13 +259,13 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 /* make sure that rE is never 0 */ - IF ( EQ_32(rE, 0) ) + IF( EQ_32( rE, 0 ) ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - IF ( EQ_32(totalNoiseNrg, 0) ) + IF( EQ_32( totalNoiseNrg, 0 ) ) { rE = L_max( rE, 0x00010000 ); } @@ -343,13 +341,13 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, noise_band_ratio = div_s( n_noise_bands_tile, n_noise_bands ); // Q15 /* make sure that rE is never 0 */ - IF( EQ_32(rE, 0) ) + IF( EQ_32( rE, 0 ) ) { rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ - IF( EQ_32(totalNoiseNrg, 0) ) + IF( EQ_32( totalNoiseNrg, 0 ) ) { rE = L_max( rE, 0x00010000 ); } @@ -391,7 +389,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, tmp = get_next_indice( st, 1 ); - IF( EQ_16(tmp, 0) ) + IF( EQ_16( tmp, 0 ) ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; move16(); @@ -403,7 +401,7 @@ static void IGF_decode_whitening_level( Decoder_State *st, hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; move16(); - IF ( EQ_16(tmp, 0) ) + IF( EQ_16( tmp, 0 ) ) { hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; move16(); @@ -436,7 +434,7 @@ static void IGF_setLinesToZero( const Word16 startLine, /**< in if there is content in the original MDCT spectrum */ FOR( i = startLine; i < stopLine; i++ ) { - IF ( NE_32(pSpectralData[i], 0) ) + IF( NE_32( pSpectralData[i], 0 ) ) { pPowerSpecIGF[i] = L_deposit_l( 0 ); } @@ -547,7 +545,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; move16(); - IF( NE_32(abs_sum, 0) ) + IF( NE_32( abs_sum, 0 ) ) { FOR( i = strt_cpy; i < startLine; i++ ) { @@ -572,7 +570,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* medium whitening detected */ IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) { - IF( NE_16(n_noise_bands, 0) ) + IF( NE_16( n_noise_bands, 0 ) ) { IGF_replaceTCXNoise_2( igf_spec, TCXNoise, @@ -595,7 +593,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* off whitening detectded */ ELSE { - IF( NE_16(n_noise_bands_off, 0) ) + IF( NE_16( n_noise_bands_off, 0 ) ) { IGF_replaceTCXNoise_2( hPrivateData->pSpecFlat, TCXNoise, @@ -692,7 +690,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in IF( GT_16( element_mode, EVS_MONO ) ) { - tile_width = sub(hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]); + tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); stop = add( strt_cpy, tile_width ); } ELSE @@ -717,7 +715,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; move16(); - IF( NE_32(abs_sum, 0) ) + IF( NE_32( abs_sum, 0 ) ) { FOR( i = strt_cpy; i < stop; i++ ) { @@ -744,7 +742,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { IF( GT_16( element_mode, EVS_MONO ) ) { - IF( NE_16(n_noise_bands, 0) ) + IF( NE_16( n_noise_bands, 0 ) ) { IGF_replaceTCXNoise_2_new_ivas( igf_spec, specMed_e, @@ -759,7 +757,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } ELSE { - IF( NE_16(n_noise_bands, 0) ) + IF( NE_16( n_noise_bands, 0 ) ) { IGF_replaceTCXNoise_2( igf_spec, TCXNoise, @@ -785,7 +783,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in IF( GT_16( element_mode, EVS_MONO ) ) { - IF( NE_16(n_noise_bands_off, 0) ) + IF( NE_16( n_noise_bands_off, 0 ) ) { IGF_replaceTCXNoise_2_new_ivas( src_spec, src_spec_e, @@ -800,7 +798,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } ELSE { - IF( NE_16(n_noise_bands_off, 0) ) + IF( NE_16( n_noise_bands_off, 0 ) ) { IGF_replaceTCXNoise_2( src_spec, TCXNoise, @@ -1533,19 +1531,19 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* select correct hopsize for envelope refinement */ hopsize = 2; move16(); - IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) + IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) { hopsize = 4; move16(); } - IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) + IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) { hopsize = 1; move16(); } hopsize = s_min( hopsize, hPrivateData->igfInfo.maxHopsize ); - IF( GT_16(hopsize, 1) ) + IF( GT_16( hopsize, 1 ) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { @@ -1571,7 +1569,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } /* IGF_rescale_SCF */ - IF( NE_16(hGrid->infoIsRefined, 0) ) + IF( NE_16( hGrid->infoIsRefined, 0 ) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) { @@ -1628,7 +1626,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( LT_32(L_tmp2, 0) ) + IF( LT_32( L_tmp2, 0 ) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -1706,7 +1704,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( LT_32(L_tmp2, 0) ) + IF( LT_32( L_tmp2, 0 ) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -1731,7 +1729,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in negate( dN[start_sfb] ), dN_e[start_sfb], &tmp ); /* float: tmp = dE - dN[start_sfb] */ - IF( LT_16(tmp, 0) ) + IF( LT_16( tmp, 0 ) ) { /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ L_tmp = L_mult( fFactor, tmp ); @@ -1752,7 +1750,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in sfb_p1 = add( start_sfb, 1 ); sfb_m1 = sub( stop_sfb, 1 ); test(); - IF( NE_16(hGrid->infoIsRefined, 0) && EQ_16( hopsize, 1 ) ) + IF( NE_16( hGrid->infoIsRefined, 0 ) && EQ_16( hopsize, 1 ) ) { /* apply filter to absolute energy values: */ FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) @@ -1882,7 +1880,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* gain calculation */ gain[sfb] = 0; move16(); - IF( NE_32(pN[sfb], 0) ) + IF( NE_32( pN[sfb], 0 ) ) { tmp = BASOP_Util_Divide3232_Scale( dNlocal, pN[sfb], &s ); s = sub( add( s, dNlocal_e ), pN_e[sfb] ); @@ -1907,7 +1905,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*--- check gains /spectrum exponents for possible overflows --- */ /* get tile index */ - IF ( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -1917,7 +1915,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*check whether overflow would occur and calculate Headroom, needed*/ shift = sub( L_tmp_e, *spectrum_e ); tmp = sub( shift, sub( norm_l( L_tmp ), TCX_IMDCT_HEADROOM ) ); - IF ( GT_16(tmp, 0) ) + IF( GT_16( tmp, 0 ) ) { Hr = s_max( Hr, tmp ); } @@ -1925,7 +1923,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* disable rescaling if gain is smaler than 1 */ /* gain < 1, if norm_s(gain[sfb]) >= gain_e[sfb] */ tmp = sub( norm_s( gain[sfb] ), gain_e[sfb] ); - IF ( GE_16(tmp, 0) ) + IF( GE_16( tmp, 0 ) ) { Hr = 0; move16(); @@ -1935,7 +1933,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* Rescale spectrum if overflow may occur */ tileIdx = -1; move16(); - IF( GT_16(Hr, 0) ) + IF( GT_16( Hr, 0 ) ) { /* rescale virtual Spec, cheap and easy: reset scalingfactor */ *virtualSpec_e = add( *virtualSpec_e, Hr ); @@ -1957,7 +1955,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - IF ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2035,7 +2033,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *spectrum_e ); tmp = norm_l( L_tmp ) - shift - 32; - IF ( LT_16(tmp, 0) ) + IF( LT_16( tmp, 0 ) ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2048,7 +2046,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *virtualSpec_e ); tmp = norm_l( L_tmp ) - shift - 32; - IF ( LT_16(tmp, 0) ) + IF( LT_16( tmp, 0 ) ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2236,12 +2234,12 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* select correct hopsize for envelope refinement */ hopsize = 2; move16(); - IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) + IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_OFF ) ) { hopsize = 4; move16(); } - IF ( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) + IF( EQ_16( hPrivateData->currWhiteningLevel[0], IGF_WHITENING_STRONG ) ) { hopsize = 1; move16(); @@ -2252,7 +2250,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in hopsize = s_min( hopsize, 2 ); } - IF( GT_16(hopsize, 1) ) + IF( GT_16( hopsize, 1 ) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { @@ -2278,7 +2276,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in } /* IGF_rescale_SCF */ - IF( NE_16(hGrid->infoIsRefined, 0) ) + IF( NE_16( hGrid->infoIsRefined, 0 ) ) { FOR( sfb = start_sfb; sfb < stop_sfb; sfb += 2 ) { @@ -2335,7 +2333,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in #endif BASOP_SATURATE_WARNING_ON_EVS - IF( LT_32(L_tmp2, 0) ) + IF( LT_32( L_tmp2, 0 ) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -2402,7 +2400,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_tmp2 = L_shl_sat( L_negate( Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ) ), sub( sNlocal_e, L_tmp_e ) ); L_tmp2 = L_sub_sat( L_tmp2, L_negate( L_tmp ) ); - IF( LT_32(L_tmp2, 0) ) + IF( LT_32( L_tmp2, 0 ) ) { L_tmp = Mpy_32_16_1( sNlocal, 33 /*0.001f Q15*/ ); L_tmp_e = sNlocal_e; @@ -2427,7 +2425,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in negate( dN[start_sfb] ), dN_e[start_sfb], &tmp ); /* float: tmp = dE - dN[start_sfb] */ - IF( LT_16(tmp, 0) ) + IF( LT_16( tmp, 0 ) ) { /* float: dS[start_sfb] = dN[start_sfb] + fFactor * (dE-dN[start_sfb]); basop: */ L_tmp = L_mult( fFactor, tmp ); @@ -2448,7 +2446,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in sfb_p1 = add( start_sfb, 1 ); sfb_m1 = sub( stop_sfb, 1 ); test(); - IF( NE_16(hGrid->infoIsRefined, 0) && EQ_16( hopsize, 1 ) ) + IF( NE_16( hGrid->infoIsRefined, 0 ) && EQ_16( hopsize, 1 ) ) { /* apply filter to absolute energy values: */ FOR( sfb = sfb_p1; sfb < sfb_m1; sfb++ ) @@ -2606,7 +2604,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - IF ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2770,7 +2768,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in ak_norm = Mpy_32_16_r( ak, 2185 ); tmp_16 = sub( 31, norm_l( ak_norm ) ); - IF ( EQ_32(ak, 0) ) + IF( EQ_32( ak, 0 ) ) { tmp_16 = 0; move16(); @@ -2793,7 +2791,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); tmp_16 = sub( 31, norm_l( ak_norm ) ); - IF ( EQ_32(ak, 0) ) + IF( EQ_32( ak, 0 ) ) { tmp_16 = 0; move16(); @@ -2802,7 +2800,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); div = shl( 1, tmp_16 ); - IF ( LT_32( ak, 16 ) ) + IF( LT_32( ak, 16 ) ) { div = 1; move16(); @@ -3050,12 +3048,12 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in move16(); } - IF( EQ_16(isIndepFrame, 0) ) + IF( EQ_16( isIndepFrame, 0 ) ) { tmp = get_next_indice( st, 1 ); } - IF( EQ_16(tmp, 1) ) + IF( EQ_16( tmp, 1 ) ) { FOR( p = 0; p < nT; p++ ) { @@ -3077,7 +3075,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in tmp = get_next_indice( st, 1 ); } - IF( EQ_16(tmp, 1) ) + IF( EQ_16( tmp, 1 ) ) { FOR( p = 1; p < nT; p++ ) { @@ -3135,12 +3133,12 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins move16(); } - IF( EQ_16(isIndepFrame, 0) ) + IF( EQ_16( isIndepFrame, 0 ) ) { tmp = get_next_indice( st, 1 ); } - IF( EQ_16(tmp, 1) ) + IF( EQ_16( tmp, 1 ) ) { FOR( p = 0; p < nT; p++ ) { @@ -3152,7 +3150,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins { IGF_decode_whitening_level( st, hPrivateData, 0 ); tmp = get_next_indice( st, 1 ); - IF( EQ_16(tmp, 1) ) + IF( EQ_16( tmp, 1 ) ) { FOR( p = 1; p < nT; p++ ) { @@ -3207,7 +3205,7 @@ void IGFDecReadLevel( /**< ou move16(); IGFAllZero = get_next_indice( st, 1 ); - IF( EQ_16(IGFAllZero, 0) ) + IF( EQ_16( 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] */ igfGridIdx, isIndepFrame ); @@ -3268,7 +3266,7 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); /* concealment counter */ - IF( NE_16(bfi, 0) ) + IF( NE_16( bfi, 0 ) ) { hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); } @@ -3279,7 +3277,7 @@ void IGFDecApplyMono( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } /* skip IGF processing if all IGF levels are zero */ - IF( EQ_16(hInstance->infoIGFAllZero, 0) ) + IF( EQ_16( hInstance->infoIGFAllZero, 0 ) ) { @@ -3436,7 +3434,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in set16_fx( igf_spec_e, 0, IGF_MAX_TILES ); /* concealment counter */ - IF( NE_16(bfi, 0) ) + IF( NE_16( bfi, 0 ) ) { hPrivateData->frameLossCounter = add( hPrivateData->frameLossCounter, 1 ); } @@ -3447,7 +3445,7 @@ void IGFDecApplyMono_ivas( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } /* skip IGF processing if all IGF levels are zero */ - IF( EQ_16(hInstance->infoIGFAllZero, 0) ) + IF( EQ_16( hInstance->infoIGFAllZero, 0 ) ) { FOR( i = 0; i < hGrid->nTiles; i++ ) { @@ -4273,9 +4271,9 @@ Word16 get_igf_startline( { Word16 igf_startline; - IF( EQ_16(st->igf, 0) ) + IF( EQ_16( st->igf, 0 ) ) { - IF( EQ_16(st->narrowBand, 0) ) + IF( EQ_16( st->narrowBand, 0 ) ) { /* minimum needed for output with sampling rates lower then the nominal sampling rate */ diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index a622058d7..cda1bb3b8 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -27,9 +27,9 @@ void IGFSCFDecoderOpen( { - hPublicData->scfCountLongBlock[0] = sub(hIgfInfo->grid[0].swb_offset_len, 1); - hPublicData->scfCountLongBlock[1] = sub(hIgfInfo->grid[1].swb_offset_len, 1); - hPublicData->scfCountLongBlock[2] = sub(hIgfInfo->grid[2].swb_offset_len, 1); + hPublicData->scfCountLongBlock[0] = sub( hIgfInfo->grid[0].swb_offset_len, 1 ); + hPublicData->scfCountLongBlock[1] = sub( hIgfInfo->grid[1].swb_offset_len, 1 ); + hPublicData->scfCountLongBlock[2] = sub( hIgfInfo->grid[2].swb_offset_len, 1 ); move16(); move16(); move16(); @@ -264,7 +264,7 @@ static void decode_sfe_vector_fx( } } - IF( LT_16(x[f], 0) ) + IF( LT_16( x[f], 0 ) ) { x[f] = 0; move16(); diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index b327a6c0b..ad5c524c1 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -130,7 +130,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); - IF( EQ_16(idchan, 0) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_16( 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 ) { @@ -149,7 +149,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); - IF( ( EQ_16(idchan, 0) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( EQ_16( 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 ) { @@ -209,7 +209,7 @@ ivas_error init_decoder_fx( test(); test(); - IF( ( EQ_16(idchan, 0) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( EQ_16( 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 ) { @@ -354,9 +354,9 @@ ivas_error init_decoder_fx( test(); test(); test(); - IF( EQ_16(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( EQ_16( 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 ) + 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" ) ); } @@ -428,7 +428,7 @@ ivas_error init_decoder_fx( test(); test(); test(); - IF( ( EQ_16(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( ( EQ_16( 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 ) { @@ -477,7 +477,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ /* TCX-LTP */ - IF( ( EQ_16(idchan,0) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( EQ_16( 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 ) { @@ -491,7 +491,7 @@ ivas_error init_decoder_fx( /* TCX core */ // VE: reduction possible for MCT_CHAN_MODE_LFE channel - see I1-172 - IF( EQ_16(idchan, 0) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_16( 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 ) { @@ -508,7 +508,7 @@ ivas_error init_decoder_fx( st_fx->hTcxDec = NULL; } /* TCX config. data structure */ - IF( ( EQ_16(idchan, 0) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) + IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { IF( ( st_fx->hTcxCfg = (TCX_CONFIG_HANDLE) count_malloc( sizeof( TCX_config ) ) ) == NULL ) { @@ -536,9 +536,9 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); - IF( EQ_16(idchan, 0) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) + IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) count_malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + 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" ) ); } @@ -645,7 +645,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16(idchan, 0) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( EQ_16( 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 ) { @@ -672,7 +672,7 @@ ivas_error init_decoder_fx( *-----------------------------------------------------------------*/ test(); test(); - IF( ( EQ_16(idchan, 0) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) + IF( ( EQ_16( 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 ) { @@ -689,18 +689,18 @@ ivas_error init_decoder_fx( * FD BPF & resampling tools parameters *-----------------------------------------------------------------*/ /* open analysis for max. SR 48kHz */ - IF ( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb( &st_fx->cldfbAna, CLDFB_ANALYSIS, CLDFB_getNumChannels( 48000 ), 320 ) ) != IVAS_ERR_OK ) { return error; } /* open analysis BPF for max. SR 16kHz */ - IF ( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb( &st_fx->cldfbBPF, CLDFB_ANALYSIS, CLDFB_getNumChannels( 16000 ), 320 ) ) != IVAS_ERR_OK ) { return error; } /* open synthesis for output SR */ - IF ( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ) != IVAS_ERR_OK ) + IF( ( error = openCldfb( &st_fx->cldfbSyn, CLDFB_SYNTHESIS, CLDFB_getNumChannels( st_fx->output_Fs ), st_fx->output_frame_fx ) ) != IVAS_ERR_OK ) { return error; } @@ -788,12 +788,12 @@ ivas_error init_decoder_fx( #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 ) || EQ_16(idchan, 0) ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) + IF( ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) || EQ_16( idchan, 0 ) ) /*&& mc_mode != MC_MODE_MCT && mc_mode != MC_MODE_PARAMUPMIX*/ ) #endif { /* Create FD_CNG instance */ - IF ( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ) != IVAS_ERR_OK ) + IF( ( error = createFdCngDec_fx( &st_fx->hFdCngDec ) ) != IVAS_ERR_OK ) { return error; } @@ -839,22 +839,22 @@ ivas_error init_decoder_fx( /*----------------------------------------------------------------------------------* * Stereo/IVAS parameters *----------------------------------------------------------------------------------*/ -#if 1 // IVAS_CODE -> To be verified - st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ +#if 1 // IVAS_CODE -> To be verified + st_fx->tdm_LRTD_flag = 0; /* LRTD stereo mode flag */ move16(); - st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ + st_fx->cna_dirac_flag = 0; /* CNA in DirAC flag */ move16(); - st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ + st_fx->cng_sba_flag = 0; /* CNG in SBA flag */ move16(); - st_fx->element_mode = EVS_MONO; /* element mode */ + st_fx->element_mode = EVS_MONO; /* element mode */ move16(); st_fx->last_element_mode = st_fx->element_mode; /* element mode */ move16(); - st_fx->element_brate = -1; /* element bitrate */ + st_fx->element_brate = -1; /* element bitrate */ move16(); - st_fx->low_rate_mode = 0; /* low-rate mode flag */ + st_fx->low_rate_mode = 0; /* low-rate mode flag */ move16(); - st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ + st_fx->last_low_rate_mode = 0; /* low-rate mode flag */ move16(); // st_fx->cng_ism_flag = 0; // st_fx->coder_type = GENERIC; /* low-rate mode flag */ @@ -863,7 +863,7 @@ ivas_error init_decoder_fx( #ifdef DEBUGGING st_fx->id_element = -1; /* element ID */ #endif - st_fx->extl_orig = -1; /* extension layer */ + st_fx->extl_orig = -1; /* extension layer */ move16(); st_fx->extl_brate_orig = 0; /* extension layer bitrate */ move16(); @@ -1126,7 +1126,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * parameters for fast recovery (WI) *-----------------------------------------------------------------*/ - + test(); IF( EQ_32( st_fx->output_Fs, 16000 ) && EQ_16( st_fx->element_mode, EVS_MONO ) ) { @@ -1167,7 +1167,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * HF (6-7kHz) (zero) BWE parameters *-----------------------------------------------------------------*/ - + test(); test(); IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) @@ -1228,7 +1228,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( EQ_16( 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 ) + 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" ) ); } @@ -1304,7 +1304,7 @@ ivas_error init_decoder_ivas_fx( test(); IF( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) { - IF ( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + IF( ( st_fx->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); } @@ -1446,7 +1446,7 @@ ivas_error init_decoder_ivas_fx( st_fx->bpf_off = 0; move16(); - test(); + test(); test(); IF( ( EQ_16( idchan, 0 ) && NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { @@ -1628,7 +1628,7 @@ ivas_error init_decoder_ivas_fx( /*-----------------------------------------------------------------* * IGF *-----------------------------------------------------------------*/ - + test(); IF( ( EQ_16( idchan, 0 ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) { diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 0024e7464..9531a05be 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -74,7 +74,7 @@ void inov_decode_fx( IF( !Opt_AMR_WB ) { - IF ( st_fx->acelp_cfg.fcb_mode ) + IF( st_fx->acelp_cfg.fcb_mode ) { Word16 i; Word16 indexing_indices[8], wordcnt, bitcnt; @@ -120,7 +120,7 @@ void inov_decode_fx( bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; move16(); // PMT("CONDITION above is missing -> idchan") - FOR ( i = 0; i < wordcnt; i++ ) + FOR( i = 0; i < wordcnt; i++ ) { indexing_indices[i] = get_next_indice( st_fx, 16 ); } diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 70a8a0e2e..11535dded 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -1834,8 +1834,8 @@ Word16 computeMixingMatrices_fx( mat_mult_buffer2_e = 0; matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, - mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, - mat_mult_buffer3_fx, &mat_mult_buffer3_e ); + mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, + mat_mult_buffer3_fx, &mat_mult_buffer3_e ); /************************ Formulate M **********************/ @@ -1850,9 +1850,9 @@ Word16 computeMixingMatrices_fx( /* Compute Cy_tilde = M*Cx*M' */ - matrix_product_mant_exp_fx( mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, Cx_fx, Cx_fx_e, lengthCx, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e); + matrix_product_mant_exp_fx( mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, Cx_fx, Cx_fx_e, lengthCx, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); - matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 1, mat_mult_buffer2_fx, &mat_mult_buffer2_e); + matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 1, mat_mult_buffer2_fx, &mat_mult_buffer2_e ); Cr_p_fx = Cr_fx; Cy_p_fx = Cy_fx; @@ -2457,14 +2457,14 @@ Word16 computeMixingMatricesResidual_fx( move16(); matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, - mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, - mat_mult_buffer3_fx, &mat_mult_buffer3_e); + mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, + mat_mult_buffer3_fx, &mat_mult_buffer3_e ); /*-----------------------------------------------------------------* * Formulate M *-----------------------------------------------------------------*/ - matrix_product_mant_exp_fx( Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e); + matrix_product_mant_exp_fx( Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer3_fx, mat_mult_buffer3_e, lengthCy, lengthCx, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); FOR( i = 0; i < num_outputs; i++ ) { diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 8b817242f..fb846b91a 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -984,11 +984,9 @@ void ivas_updt_dec_common_fx( } #endif #ifdef NON_BE_1055_RESET_LP_MEMORIES - IF( (LE_32(st_fx->core_brate , SID_2k40) && EQ_16(st_fx->cng_type , FD_CNG) ) || (st_fx->tcxonly && (EQ_16(st_fx->codec_mode , MODE2) || GT_16(st_fx->element_mode , EVS_MONO)) ) ) + IF( ( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && ( EQ_16( st_fx->codec_mode, MODE2 ) || GT_16( st_fx->element_mode, EVS_MONO ) ) ) ) #else - IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) - || (st_fx->tcxonly && EQ_16(st_fx->codec_mode,MODE2)) - ) + IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) #endif { -- GitLab From 4f3fdb501323add4b99d1aa03776329323cdecb0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 12 Jun 2024 13:37:02 +0530 Subject: [PATCH 26/63] EVS BE issue fixed --- lib_dec/er_dec_acelp_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index 100a6b207..11ada1141 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1067,7 +1067,7 @@ void con_acelp_fx( /* save last half frame if next frame is TCX */ bufferCopyFx( syn + st->L_frame, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); - Copy( syn + sub( st->L_frame, sub( M, 1 ) ), st->syn, add( 1, M ) ); + Copy( syn + sub( st->L_frame, add( M, 1 ) ), st->syn, add( 1, M ) ); /* update old_Aq */ Copy( p_A - add( M, 1 ), st->old_Aq_12_8_fx, add( M, 1 ) ); @@ -1097,7 +1097,7 @@ void con_acelp_fx( } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_LB_fx[add( i, n )] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, sub( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, sub( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); move16(); } set16_fx( &hHQ_core->old_out_LB_fx[add( W1, n )], 0, n ); -- GitLab From 844527b3e3f44ae7c4c9e5fd36b72af5c6ba5a33 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 12 Jun 2024 13:57:16 +0530 Subject: [PATCH 27/63] Fix for issue 754: Concealment artifacts at 48kbps stereo --- lib_com/tcx_utils_fx.c | 4 ++-- lib_dec/FEC_HQ_phase_ecu_fx.c | 8 ++++---- lib_dec/er_dec_acelp_fx.c | 4 ++-- lib_dec/er_dec_tcx_fx.c | 18 +++++++++--------- lib_dec/gaus_dec_fx.c | 6 +++--- lib_dec/ivas_spar_decoder.c | 4 +--- lib_enc/cod_uv_fx.c | 6 +++--- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index 1932730ac..74149f2be 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -1787,7 +1787,7 @@ void tcx_noise_filling( win = add( win, 1 ); } - seed = own_random2_fx( seed ); + Random( &seed ); Q[i] = L_mult0( mult( seed, fac_ns ), win ); move32(); @@ -1952,7 +1952,7 @@ void tcx_noise_filling_with_shift( Word16 nrm = 31; - seed = own_random2_fx( seed ); + Random( &seed ); Q[i] = L_mult0( mult( seed, fac_ns ), win ); IF( Q[i] ) { diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index bd6d018a6..8e7c7b99d 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -2383,7 +2383,7 @@ static void ivas_subst_spec_fx( IF( NE_16( ph_dith, 0 ) ) { Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ - *seed = own_random2_fx( *seed ); /* in Q0 */ + Random( seed ); /* in Q0 */ acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ acc = L_shr( acc, PHASE_DITH_SCALE_SHIFT ); Xph = L_add( Xph, acc ); /* in Q16. */ @@ -2782,9 +2782,9 @@ static void subst_spec_fx( move16(); IF( ph_dith != 0 ) { - Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ - *seed = own_random2_fx( *seed ); /* in Q0 */ - acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ + Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ + Random( seed ); /* in Q0 */ + acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ acc = L_shr( acc, PHASE_DITH_SCALE_SHIFT ); Xph = L_add( Xph, acc ); /* in Q16. */ diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index 11ada1141..eec1d3be8 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -490,7 +490,7 @@ void con_acelp_fx( l = add( st->L_frame, sub( l_fir_fer, 1 ) ); FOR( i = 0; i < l; i++ ) { - tmpSeed = own_random2_fx( tmpSeed ); + Random( &tmpSeed ); noise_buf[i] = tmpSeed; /*Q0*/ move16(); } @@ -500,7 +500,7 @@ void con_acelp_fx( l = add( add( st->L_frame, shr( st->L_frame, 1 ) ), sub( l_fir_fer, 1 ) ); FOR( ; i < l; i++ ) { - tmpSeed = own_random2_fx( tmpSeed ); + Random( &tmpSeed ); noise_buf[i] = tmpSeed; /*Q0*/ move16(); } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index e51721c82..fa30326ca 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -692,7 +692,7 @@ void con_tcx_fx( tmp_loop = add( L_frame, L_FIR_FER2 - 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - tmpSeed = own_random2_fx( tmpSeed ); + Random( &tmpSeed ); noise[i] = shr( tmpSeed, noise_e ); move16(); } @@ -702,7 +702,7 @@ void con_tcx_fx( 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 ); + Random( &tmpSeed ); noise[i] = shr( tmpSeed, noise_e ); move16(); } @@ -1622,7 +1622,7 @@ void con_tcx_ivas_fx( tmpSeed1 = *noise_seed; noise = buf; - noise_e = 1; + noise_e = 2; move16(); e = 0; move16(); @@ -1640,8 +1640,8 @@ void con_tcx_ivas_fx( FOR( i = 0; i < add( L_frame, L_FIR_FER2 - 1 ); i++ ) { - random1 = own_random2_fx( tmpSeed1 ); - random2 = own_random2_fx( tmpSeed1 ); + random1 = Random( &tmpSeed1 ); + random2 = Random( &tmpSeed1 ); noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), noise_e ) ); move16(); } @@ -1655,8 +1655,8 @@ void con_tcx_ivas_fx( FOR( ; i < add( add( L_frame, shr( L_frame, 1 ) ), 2 * L_FIR_FER2 ); i++ ) { - random1 = own_random2_fx( tmpSeed1 ); - random2 = own_random2_fx( tmpSeed1 ); + random1 = Random( &tmpSeed1 ); + random2 = Random( &tmpSeed1 ); noise[i] = add( shr( random1, noise_e ), shr( mult( alpha_coh, random2 ), noise_e ) ); move16(); } @@ -1673,7 +1673,7 @@ void con_tcx_ivas_fx( tmp_loop = add( L_frame, L_FIR_FER2 - 1 ); FOR( i = 0; i < tmp_loop; i++ ) { - tmpSeed = own_random2_fx( tmpSeed ); + Random( &tmpSeed ); noise[i] = shr( tmpSeed, noise_e ); move16(); } @@ -1683,7 +1683,7 @@ void con_tcx_ivas_fx( 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 ); + Random( &tmpSeed ); noise[i] = shr( tmpSeed, noise_e ); move16(); } diff --git a/lib_dec/gaus_dec_fx.c b/lib_dec/gaus_dec_fx.c index ae394105d..0dec8dbf6 100644 --- a/lib_dec/gaus_dec_fx.c +++ b/lib_dec/gaus_dec_fx.c @@ -268,13 +268,13 @@ void gaus_L2_dec( move16(); FOR( i = 0; i < L_SUBFR; i++ ) { - seed = own_random2_fx( seed ); + Random( &seed ); tmp32 = L_mac( 0, seed, 1 << 9 ); - seed = own_random2_fx( seed ); + Random( &seed ); tmp32 = L_mac( tmp32, seed, 1 << 9 ); - seed = own_random2_fx( seed ); + Random( &seed ); code[i] = mac_r( tmp32, seed, 1 << 9 ); move16(); } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index acb58e751..f18e474e4 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -883,9 +883,7 @@ static int16_t ivas_parse_spar_header( static Word16 get_random_number_fx( Word16 *seed ) { - Word16 x = own_random2_fx( *seed ); - *seed = x; - return x; + return Random( seed ); } #else static float get_random_number( diff --git a/lib_enc/cod_uv_fx.c b/lib_enc/cod_uv_fx.c index 5ebfe4840..bf20ecfd0 100644 --- a/lib_enc/cod_uv_fx.c +++ b/lib_enc/cod_uv_fx.c @@ -47,13 +47,13 @@ void gauss_L2_fx( /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/ FOR( i = 0; i < L_SUBFR; i++ ) { - *seed_acelp = own_random2_fx( *seed_acelp ); + Random( seed_acelp ); tmp32 = L_mac( 0, *seed_acelp, 1 << 9 ); - *seed_acelp = own_random2_fx( *seed_acelp ); + Random( seed_acelp ); tmp32 = L_mac( tmp32, *seed_acelp, 1 << 9 ); - *seed_acelp = own_random2_fx( *seed_acelp ); + Random( seed_acelp ); code[i] = mac_r( tmp32, *seed_acelp, 1 << 9 ); move16(); } -- GitLab From a9f77f0f062a8131a7f882752fddcc279e881e70 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 12 Jun 2024 14:00:02 +0530 Subject: [PATCH 28/63] clang formatting changes --- lib_dec/FEC_HQ_phase_ecu_fx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 8e7c7b99d..e43cf7f25 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -2382,9 +2382,9 @@ static void ivas_subst_spec_fx( move16(); IF( NE_16( ph_dith, 0 ) ) { - Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ - Random( seed ); /* in Q0 */ - acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ + Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ + Random( seed ); /* in Q0 */ + acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ acc = L_shr( acc, PHASE_DITH_SCALE_SHIFT ); Xph = L_add( Xph, acc ); /* in Q16. */ -- GitLab From 41ec68e58784b04e10deea398b6e2eea30ad45f6 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 13 Jun 2024 12:20:10 +0530 Subject: [PATCH 29/63] Fix for issue 769: Instability in stereo synthesis at 48 kbps --- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index f1b88a8df..5ad8ef7e4 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -467,6 +467,14 @@ void stereo_mdct_core_dec_fx( { sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech = extract_h( sts[ch]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ); } + test(); + test(); + IF( NE_16( sts[ch]->igf, 0 ) && sts[ch]->hIGFDec && sts[ch]->hIGFDec->virtualSpec_fx ) + { + Scale_sig32( sts[ch]->hIGFDec->virtualSpec_fx + sub( sts[ch]->hIGFDec->infoIGFStartLine, IGF_START_MN ), s_min( sub( sts[ch]->hIGFDec->infoIGFStopLine, sts[ch]->hIGFDec->infoIGFStartLine ), 856 ), sub( sts[ch]->hIGFDec->virtualSpec_e, x_e[ch][0] ) ); + sts[ch]->hIGFDec->virtualSpec_e = x_e[ch][0]; + move16(); + } } Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); -- GitLab From 5c695118a686e40ee550aa24759b340ca1ef1f96 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 13 Jun 2024 14:30:00 +0530 Subject: [PATCH 30/63] Conversion of deindex_sph_idx_fx --- lib_com/ivas_cnst.h | 5 +- lib_com/ivas_masa_com.c | 205 ++++++++++++++++++++++++++-------------- 2 files changed, 136 insertions(+), 74 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index da5d5fcef..ccf395ce5 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1273,9 +1273,13 @@ enum #define MASA_NO_POINTS_EQUATOR 430 #define MASA_NO_CIRCLES 121 #define MASA_ASIN_OFFSET 0.0064471690266724975f +#define MASA_ASIN_OFFSET_Q15 ( 211 ) #define MASA_NTOT2_FAC 32768.00566947353f +#define MASA_NTOT2_FAC_Q15 ( 1073741952 ) #define MASA_ANGLE_AT_EQUATOR 0.012894427382667f +#define MASA_ANGLE_AT_EQUATOR_Q31 ( 27690572 ) #define MASA_ANGLE_AT_EQUATOR_DEG 0.738796268264740f +#define MASA_ANGLE_AT_EQUATOR_DEG_Q31 ( 1586552905l ) #define MASA_INV_ANGLE_AT_EQUATOR_DEG 1.353553128183453f #define MASA_STEREO_MIN_BITRATE IVAS_24k4 #define MAXIMUM_OMASA_FREQ_BANDS 8 /* Corresponds to maximum number of coding bands at 32 kbps */ @@ -1285,7 +1289,6 @@ enum #define NBITS_HR_COH 4 #define MASA_INV_ANGLE_AT_EQUATOR_DEG_Q30 (1453366656l) -#define MASA_ANGLE_AT_EQUATOR_DEG_Q31 (1586552905l) #define MASA_JBM_RINGBUFFER_FRAMES 3 diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index bce454a57..bbfc3d69c 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -1416,153 +1416,212 @@ void deindex_sph_idx( } void deindex_sph_idx_fx( - const uint16_t sphIndex, /* i : Spherical index */ + const UWord16 sphIndex, /* i : Spherical index */ const SPHERICAL_GRID_DATA *gridData, /* i : Prepared spherical grid */ Word32 *theta_fx, /* o : Elevation */ Word32 *phi_fx /* o : Azimuth */ ) { - // temp conversion as function using sin and cos - float theta = (float) *theta_fx / ( 1 << 22 ); - float phi = (float) *phi_fx / ( 1 << 22 ); - - - float ba_crt, del_crt, div_crt, a4_crt; - float estim; - int32_t base_low, base_up; - int16_t n_crt; - int16_t id_th; - int16_t sign_theta; - int16_t id_phi; - int16_t no_th = gridData->no_theta; - const int16_t *n = gridData->no_phi; - const float ba[3] = { 2.137991118026424e+02f, 1.244854404591542e+02f, 1.228408647140870e+02f }; - const float del[3] = { 7.998262115303199e+05f, 1.300883976959332e+06f, 1.424072242426373e+06f }; - const float div[3] = { -0.237662341081474f, -0.100938185496887f, -0.092050209205032f }; - const float a4[3] = { -8.415300425381099f, -19.814106922515204f, -21.727272727270197f }; - const uint16_t limit_index1 = 64964, limit_index2 = 47870; + Word32 ba_crt_fx, del_crt_fx, div_crt_fx, a4_crt_fx; + Word32 estim_fx; + Word32 base_low, base_up; + Word16 n_crt; + Word16 id_th; + Word16 sign_theta; + Word16 id_phi; + Word16 no_th = gridData->no_theta; + const Word16 *n = gridData->no_phi; + const Word32 ba_fx[3] = { 1793476992, 1044259584, 1030463872 }; /* Q23 */ + const Word32 del_fx[3] = { 819022016, 1332105216, 1458249984 }; /* Q10 */ + const Word32 div_fx[3] = { -510376000, -216763104, -197676320 }; /* Q31 */ + const Word32 a4_fx[3] = { -564741248, -1329702144, -1458092544 }; /* Q26 */ + const UWord16 limit_index1 = 64964, limit_index2 = 47870; + Word32 tmp32; + Word16 tmp16, tmp_e; + move16(); + move16(); - if ( sphIndex >= limit_index1 ) + IF( GE_32( sphIndex, limit_index1 ) ) { - ba_crt = ba[2]; - div_crt = div[2]; - a4_crt = a4[2]; - del_crt = del[2]; + ba_crt_fx = ba_fx[2]; + move32(); + div_crt_fx = div_fx[2]; + move32(); + a4_crt_fx = a4_fx[2]; + move32(); + del_crt_fx = del_fx[2]; + move32(); } - else if ( sphIndex >= limit_index2 ) + ELSE IF( GE_32( sphIndex, limit_index2 ) ) { - ba_crt = ba[1]; - div_crt = div[1]; - a4_crt = a4[1]; - del_crt = del[1]; + ba_crt_fx = ba_fx[1]; + move32(); + div_crt_fx = div_fx[1]; + move32(); + a4_crt_fx = a4_fx[1]; + move32(); + del_crt_fx = del_fx[1]; + move32(); } - else + ELSE { - ba_crt = ba[0]; - div_crt = div[0]; - a4_crt = a4[0]; - del_crt = del[0]; + ba_crt_fx = ba_fx[0]; + move32(); + div_crt_fx = div_fx[0]; + move32(); + a4_crt_fx = a4_fx[0]; + move32(); + del_crt_fx = del_fx[0]; + move32(); } - estim = ba_crt + div_crt * sqrtf( del_crt + a4_crt * sphIndex ); + tmp32 = Mpy_32_32( a4_crt_fx, L_shl_sat( sphIndex, Q15 ) ); /* Q10 */ + tmp32 = L_add( del_crt_fx, tmp32 ); /* Q10 */ + tmp16 = Q31 - Q10; + tmp32 = Sqrt32( tmp32, &tmp16 ); + tmp32 = Mpy_32_32( div_crt_fx, tmp32 ); + tmp32 = L_shr( tmp32, sub( Q8, tmp16 ) ); /* Q23 */ + estim_fx = L_add( ba_crt_fx, tmp32 ); /* Q23 */ - if ( estim > MASA_NO_CIRCLES ) + if ( GT_32( estim_fx, MASA_NO_CIRCLES << Q23 ) ) { - estim = MASA_NO_CIRCLES; + estim_fx = MASA_NO_CIRCLES << Q23; + move32(); } - assert( estim > 0 ); - id_th = (int16_t) roundf( estim ) - 1; + assert( estim_fx > 0 ); + id_th = sub( extract_l( L_shr_r( estim_fx, Q23 ) ), 1 ); /* Q0 */ if ( id_th < 0 ) { id_th = 0; + move16(); } - if ( id_th == 0 ) + IF( id_th == 0 ) { base_low = 0; + move32(); base_up = n[0]; + move32(); } - else + ELSE { - estim = MASA_ANGLE_AT_EQUATOR * (float) ( id_th - 0.5f ); + estim_fx = Mpy_32_32( MASA_ANGLE_AT_EQUATOR_Q31, L_sub( L_shl( id_th, Q22 ), 2097152 ) /* 0.5f in Q22 */ ); /* Q22 */ base_low = n[0]; - if ( id_th >= 2 ) + move32(); + IF( GE_16( id_th, 2 ) ) { - if ( id_th == 2 ) + tmp32 = estim_fx % 26353590; /* 2 * PI in Q22 */ + tmp32 = Mpy_32_32( tmp32, 341782638 /* 2147483647 / 2 * PI */ ); /* Q7 */ + tmp16 = extract_l( L_shr( tmp32, Q7 ) ); + + tmp16 = getSineWord16R2( tmp16 ); + tmp16 = sub( tmp16, MASA_ASIN_OFFSET_Q15 ); + tmp32 = Mpy_32_16_1( MASA_NTOT2_FAC_Q15, tmp16 ); /* Q15 */ + + IF( EQ_16( id_th, 2 ) ) { - base_low += 2 * (int16_t) ceilf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) ); + base_low = L_add( base_low, L_shl( extract_l( L_shr( ceil_fixed( tmp32, Q15 ), Q15 ) ), 1 ) ); /* Q0 */ } - else + ELSE { - base_low += 2 * (int16_t) roundf( MASA_NTOT2_FAC * ( sinf( estim ) - MASA_ASIN_OFFSET ) ); + base_low = L_add( base_low, L_shl( extract_l( L_shr_r( tmp32, Q15 ) ), 1 ) ); /* Q0 */ } } - base_up = base_low + 2 * n[id_th]; + base_up = L_add( base_low, L_shl( n[id_th], 1 ) ); } sign_theta = 1; + move16(); n_crt = n[id_th]; - if ( sphIndex < base_low ) + move16(); + IF( LT_32( sphIndex, base_low ) ) { id_th--; n_crt = n[id_th]; - if ( id_th == 0 ) + move16(); + IF( id_th == 0 ) { base_low = 0; + move32(); base_up = n_crt; + move32(); } - else + ELSE { base_up = base_low; - base_low -= 2 * n[id_th]; + move32(); + base_low = L_sub( base_low, shl( n[id_th], 1 ) ); } assert( sphIndex >= base_low ); } - else if ( sphIndex >= base_up ) + ELSE IF( GE_32( sphIndex, base_up ) ) { id_th++; n_crt = n[id_th]; + move16(); base_low = base_up; - base_up += 2 * n_crt; + move32(); + base_up = L_add( base_up, shl( n_crt, 1 ) ); assert( sphIndex < base_up ); } - id_phi = (int16_t) ( sphIndex - base_low ); - if ( sphIndex - base_low >= n_crt ) + id_phi = extract_l( L_sub( sphIndex, base_low ) ); + IF( GE_32( L_sub( sphIndex, base_low ), n_crt ) ) { - id_phi -= n_crt; + id_phi = sub( id_phi, n_crt ); sign_theta = -1; + move16(); } - if ( id_th == 0 ) + IF( id_th == 0 ) { - theta = 0.f; - phi = (float) sphIndex * 360 / (float) n_crt - 180; + *theta_fx = 0; + move32(); + tmp32 = imult3216( sphIndex, 360 ); + tmp16 = BASOP_Util_Divide3232_Scale( tmp32, n_crt, &tmp_e ); + tmp32 = L_shl( tmp16, add( Q7, tmp_e ) ); /* Q22 */ + *phi_fx = L_sub( tmp32, 180 << Q22 ); /* Q22 */ + move32(); } - else + ELSE { - if ( id_th == no_th - 1 ) + IF( EQ_16( id_th, sub( no_th, 1 ) ) ) { id_phi = 0; - phi = -180; - theta = 90 * (float) sign_theta; + move16(); + *phi_fx = -754974720; /* -180 in Q22 */ + move32(); + *theta_fx = L_shl( L_mult0( 90, sign_theta ), Q22 ); /* Q22 */ + move32(); } - else + ELSE { - theta = id_th * MASA_ANGLE_AT_EQUATOR_DEG * (float) sign_theta; - if ( id_th % 2 == 0 ) + *theta_fx = Mpy_32_32( L_shl( id_th, Q22 ), MASA_ANGLE_AT_EQUATOR_DEG_Q31 ); /* Q22 */ + move32(); + if ( EQ_16( sign_theta, -1 ) ) { - phi = (float) id_phi * 360 / (float) n_crt - 180; + *theta_fx = L_negate( *theta_fx ); /* Q22 */ + move32(); } - else + IF( id_th % 2 == 0 ) + { + tmp32 = L_mult0( id_phi, 360 ); + tmp16 = BASOP_Util_Divide3232_Scale( tmp32, n_crt, &tmp_e ); + tmp32 = L_shl( tmp16, add( Q7, tmp_e ) ); /* Q22 */ + *phi_fx = L_sub( tmp32, 180 << Q22 ); /* Q22 */ + move32(); + } + ELSE { - phi = ( (float) id_phi + 0.5f ) * 360 / (float) n_crt - 180; + tmp32 = L_add( L_mult0( id_phi, 360 ), 180 ); + tmp16 = BASOP_Util_Divide3232_Scale( tmp32, n_crt, &tmp_e ); + tmp32 = L_shl( tmp16, add( Q7, tmp_e ) ); /* Q22 */ + *phi_fx = L_sub( tmp32, 180 << Q22 ); /* Q22 */ + move32(); } } } - *theta_fx = (Word32) ( theta * ( 1 << 22 ) ); - *phi_fx = (Word32) ( phi * ( 1 << 22 ) ); return; } -- GitLab From 155e557e10d64ea4aa6cb556c508a19d82c0c592 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 13 Jun 2024 15:24:52 +0530 Subject: [PATCH 31/63] ASAN fixes --- lib_dec/ivas_jbm_dec.c | 4 ++-- lib_util/hrtf_file_reader.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index bb7d374a9..4556baaf5 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -2109,7 +2109,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */ Word32 *p_data_f_fx[MAX_CLDFB_DIGEST_CHANNELS]; Word32 *data_fx; - data_fx = (Word32 *) malloc( 8640 * sizeof( Word32 ) ); + data_fx = (Word32 *) malloc( ( add( imult1616( nSamplesForRendering, st_ivas->hTcBuffer->nchan_transport_jbm ), s_min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ) ) ) * sizeof( Word32 ) ); IF( st_ivas->hTcBuffer ) { @@ -2135,7 +2135,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( { #ifdef IVAS_FLOAT_FIXED #if 1 - floatToFixed_arrL( data, data_fx, 11, s_min( 3, st_ivas->hTcBuffer->nchan_transport_jbm ) * 2880 ); + floatToFixed_arrL( data, data_fx, 11, add( imult1616( nSamplesForRendering, st_ivas->hTcBuffer->nchan_transport_jbm ), s_min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ) ) ); #endif ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11 ); diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index b00de3950..a4994e544 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -266,6 +266,7 @@ static void LoadBSplineBinaryITD( { modelITD->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); } + free( elevKSeq_dyn_local ); fread( &modelITD->azimDim2, sizeof( Word16 ), 1, f_hrtf ); fread( &modelITD->azimDim3, sizeof( Word16 ), 1, f_hrtf ); @@ -277,6 +278,7 @@ static void LoadBSplineBinaryITD( { modelITD->azimKSeq_dyn_fx[i] = float_to_fix( azimKSeq_dyn_local[i], Q22 ); } + free( azimKSeq_dyn_local ); fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); float *W_dyn_local = (float *) malloc( tmp * sizeof( float ) ); @@ -284,6 +286,7 @@ static void LoadBSplineBinaryITD( modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); f2me_buf( W_dyn_local, modelITD->W_dyn_fx, &modelITD->W_dyn_e, tmp ); + free( W_dyn_local ); /* azimuth */ fread( modelITD->azimBsLen, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); @@ -299,6 +302,7 @@ static void LoadBSplineBinaryITD( { modelITD->azimBsShape_dyn_fx[i] = float_to_fix( azimBsShape_dyn_local[i], Q30 ); } + free( azimBsShape_dyn_local ); fread( &modelITD->azimSegSamples, sizeof( Word16 ), 1, f_hrtf ); @@ -316,6 +320,7 @@ static void LoadBSplineBinaryITD( { modelITD->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); } + free( elevBsShape_dyn_local ); fread( &modelITD->elevSegSamples, sizeof( Word16 ), 1, f_hrtf ); @@ -540,6 +545,7 @@ static ivas_error LoadBSplineBinary( { model->elevKSeq_dyn_fx[i] = float_to_fix( elevKSeq_dyn_local[i], Q22 ); } + free( elevKSeq_dyn_local ); #else model->elevKSeq_dyn = (float *) malloc( ( model->elevDim3 - 2 ) * sizeof( float ) ); fread( model->elevKSeq_dyn, sizeof( float ), model->elevDim3 - 2, f_hrtf ); @@ -566,11 +572,16 @@ static ivas_error LoadBSplineBinary( { model->azimKSeq_fx[i][j] = float_to_fix( azimKSeq_local[i][j], Q22 ); } + free( azimKSeq_local[i] ); #else model->azimKSeq[i] = (float *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( float ) ); fread( model->azimKSeq[i], sizeof( float ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); #endif } +#ifdef IVAS_FLOAT_FIXED + free( azimKSeq_local ); +#endif + fread( &model->AlphaN, sizeof( int16_t ), 1, f_hrtf ); #ifdef IVAS_FLOAT_FIXED float *AlphaL_dyn_local = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); @@ -578,6 +589,7 @@ static ivas_error LoadBSplineBinary( model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); f2me_buf( AlphaL_dyn_local, model->AlphaL_dyn_fx, &model->AlphaL_dyn_e, model->AlphaN * model->K ); + free( AlphaL_dyn_local ); #else model->AlphaL_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); fread( model->AlphaL_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); @@ -589,6 +601,7 @@ static ivas_error LoadBSplineBinary( model->AlphaR_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); f2me_buf( AlphaR_dyn_local, model->AlphaR_dyn_fx, &model->AlphaR_dyn_e, model->AlphaN * model->K ); + free( AlphaR_dyn_local ); #else model->AlphaR_dyn = (float *) malloc( model->AlphaN * model->K * sizeof( float ) ); fread( model->AlphaR_dyn, sizeof( float ), model->AlphaN * model->K, f_hrtf ); @@ -616,12 +629,16 @@ static ivas_error LoadBSplineBinary( { model->azimBsShape_dyn_fx[i][j] = float_to_fix( azimBsShape_dyn_local[i][j], Q30 ); } + free( azimBsShape_dyn_local[i] ); #else model->azimBsShape_dyn[i] = (float *) malloc( tmp * sizeof( float ) ); fread( model->azimBsShape_dyn[i], sizeof( float ), tmp, f_hrtf ); #endif fread( &model->azimSegSamples_dyn[i], sizeof( int16_t ), 1, f_hrtf ); } +#ifdef IVAS_FLOAT_FIXED + free( azimBsShape_dyn_local ); +#endif // IVAS_FLOAT_FIXED model->azimShapeIdx_dyn = (int16_t *) malloc( model->elevDim3 * sizeof( int16_t ) ); fread( model->azimShapeIdx_dyn, sizeof( int16_t ), model->elevDim3, f_hrtf ); @@ -640,6 +657,7 @@ static ivas_error LoadBSplineBinary( { model->elevBsShape_dyn_fx[i] = float_to_fix( elevBsShape_dyn_local[i], Q30 ); } + free( elevBsShape_dyn_local ); #else model->elevBsShape_dyn = (float *) malloc( tmp * sizeof( float ) ); fread( model->elevBsShape_dyn, sizeof( float ), tmp, f_hrtf ); -- GitLab From 58d955af7d5724c6b4db2a7771a7a1cce258ff43 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 14 Jun 2024 12:03:10 +0530 Subject: [PATCH 32/63] Fix for issue 793: Energy difference in Stereo PLC case --- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 5ad8ef7e4..66e01228b 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -388,7 +388,7 @@ void stereo_mdct_core_dec_fx( st = sts[ch]; FOR( k = 0; k < nSubframes[ch]; k++ ) { - sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx_32[ch], DEC ); + sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx_32[ch][k * M], DEC ); IF( st->hTonalMDCTConc != NULL && EQ_16( add( k, 1 ), nSubframes[ch] ) ) { -- GitLab From 65e3e9caab69d23277c74cd80eddcd2c6675c666 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 14 Jun 2024 13:46:32 +0530 Subject: [PATCH 33/63] Integrating lib_com functions in lib_enc - 1 [x] Integrated all the functions present in ivas_mc_com.c and ivas_mcmasa_com.c --- lib_com/ivas_cnst.h | 5 + lib_com/ivas_mc_com.c | 188 +++++++++++++++++++++++--- lib_com/ivas_mc_param_com.c | 2 +- lib_com/ivas_mcmasa_com.c | 116 +++++++--------- lib_com/ivas_prot.h | 10 +- lib_com/ivas_prot_fx.h | 21 +++ lib_dec/ivas_corecoder_dec_reconfig.c | 2 +- lib_dec/ivas_init_dec.c | 2 +- lib_dec/ivas_masa_dec.c | 4 +- lib_dec/ivas_mc_param_dec.c | 4 +- lib_dec/ivas_mcmasa_dec.c | 9 -- lib_dec/ivas_mct_dec.c | 10 +- lib_dec/lib_dec_fx.c | 4 +- lib_enc/ivas_init_enc.c | 32 +++++ lib_enc/ivas_mcmasa_enc.c | 11 ++ lib_enc/ivas_mct_enc.c | 16 +++ lib_enc/lib_enc.c | 4 + 17 files changed, 322 insertions(+), 118 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index ccf395ce5..33a48c136 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1341,8 +1341,13 @@ typedef enum #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 */ +#ifdef IVAS_FLOAT_FIXED +#define MCMASA_MONOBITRATIO_64k_Q31 ( 536870912 ) +#define MCMASA_MONOBITRATIO_Q31 ( 644245095 ) +#else #define MCMASA_MONOBITRATIO 0.3f #define MCMASA_MONOBITRATIO_64k 0.25f +#endif #define MC_MASA_THR_ELEVATION 40 #define MCMASA_LFE_QLOW -6.5f diff --git a/lib_com/ivas_mc_com.c b/lib_com/ivas_mc_com.c index ec3b5333e..abaed7ae4 100644 --- a/lib_com/ivas_mc_com.c +++ b/lib_com/ivas_mc_com.c @@ -37,6 +37,9 @@ #include "prot.h" #include "ivas_prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*--------------------------------------------------------------- @@ -46,13 +49,84 @@ * ---------------------------------------------------------------*/ /*! r : MC format mode */ +#ifndef IVAS_FLOAT_FIXED MC_MODE ivas_mc_mode_select( + const MC_LS_SETUP mc_ls_setup, /* i : MC loudspeaker setup */ + const int32_t total_brate /* i : IVAS total bitrate */ +) +{ + MC_MODE mc_mode = MC_MODE_MCT; + + switch ( mc_ls_setup ) + { + case MC_LS_SETUP_5_1: + if ( total_brate < IVAS_48k ) + { + mc_mode = MC_MODE_MCMASA; + } + else if ( total_brate < IVAS_96k ) + { + mc_mode = MC_MODE_PARAMMC; + } + break; + case MC_LS_SETUP_7_1: + if ( total_brate < IVAS_48k ) + { + mc_mode = MC_MODE_MCMASA; + } + else if ( total_brate < IVAS_128k ) + { + mc_mode = MC_MODE_PARAMMC; + } + break; + case MC_LS_SETUP_5_1_2: + if ( total_brate < IVAS_48k ) + { + mc_mode = MC_MODE_MCMASA; + } + else if ( total_brate < IVAS_128k ) + { + mc_mode = MC_MODE_PARAMMC; + } + break; + case MC_LS_SETUP_5_1_4: + if ( total_brate < IVAS_96k ) + { + mc_mode = MC_MODE_MCMASA; + } + else if ( total_brate < IVAS_160k ) + { + mc_mode = MC_MODE_PARAMMC; + } + break; + case MC_LS_SETUP_7_1_4: + if ( total_brate < IVAS_128k ) + { + mc_mode = MC_MODE_MCMASA; + } + else if ( total_brate < IVAS_160k ) + { + mc_mode = MC_MODE_PARAMMC; + } + else if ( total_brate < IVAS_192k ) + { + mc_mode = MC_MODE_PARAMUPMIX; + } + break; + default: + assert( 0 && "LS Setup not supported or defined for MC mode!\n" ); + } + + return mc_mode; +} +#else +MC_MODE ivas_mc_mode_select_fx( const MC_LS_SETUP mc_ls_setup, /* i : MC loudspeaker setup */ const Word32 total_brate /* i : IVAS total bitrate */ ) { MC_MODE mc_mode = MC_MODE_MCT; - move16(); + move32(); SWITCH( mc_ls_setup ) { @@ -60,65 +134,65 @@ MC_MODE ivas_mc_mode_select( IF( LT_32( total_brate, IVAS_48k ) ) { mc_mode = MC_MODE_MCMASA; - move16(); + move32(); } ELSE IF( LT_32( total_brate, IVAS_96k ) ) { mc_mode = MC_MODE_PARAMMC; - move16(); + move32(); } BREAK; case MC_LS_SETUP_7_1: IF( LT_32( total_brate, IVAS_48k ) ) { mc_mode = MC_MODE_MCMASA; - move16(); + move32(); } ELSE IF( LT_32( total_brate, IVAS_128k ) ) { mc_mode = MC_MODE_PARAMMC; - move16(); + move32(); } BREAK; case MC_LS_SETUP_5_1_2: IF( LT_32( total_brate, IVAS_48k ) ) { mc_mode = MC_MODE_MCMASA; - move16(); + move32(); } ELSE IF( LT_32( total_brate, IVAS_128k ) ) { mc_mode = MC_MODE_PARAMMC; - move16(); + move32(); } BREAK; case MC_LS_SETUP_5_1_4: IF( LT_32( total_brate, IVAS_96k ) ) { mc_mode = MC_MODE_MCMASA; - move16(); + move32(); } ELSE IF( LT_32( total_brate, IVAS_160k ) ) { mc_mode = MC_MODE_PARAMMC; - move16(); + move32(); } BREAK; case MC_LS_SETUP_7_1_4: IF( LT_32( total_brate, IVAS_128k ) ) { mc_mode = MC_MODE_MCMASA; - move16(); + move32(); } ELSE IF( LT_32( total_brate, IVAS_160k ) ) { mc_mode = MC_MODE_PARAMMC; - move16(); + move32(); } ELSE IF( LT_32( total_brate, IVAS_192k ) ) { mc_mode = MC_MODE_PARAMUPMIX; - move16(); + move32(); } BREAK; default: @@ -127,6 +201,7 @@ MC_MODE ivas_mc_mode_select( return mc_mode; } +#endif /*--------------------------------------------------------------- @@ -137,7 +212,7 @@ MC_MODE ivas_mc_mode_select( /*! r : number of loudspeaker channels */ #ifdef IVAS_FLOAT_FIXED -Word16 ivas_mc_ls_setup_get_num_channels( +Word16 ivas_mc_ls_setup_get_num_channels_fx( const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup */ ) { @@ -216,6 +291,7 @@ int16_t ivas_mc_ls_setup_get_num_channels( * ---------------------------------------------------------------*/ /*! r : multi channel loudspeaker setup */ +#ifndef IVAS_FLOAT_FIXED MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( const AUDIO_CONFIG output_config /* i : output audio configuration */ ) @@ -223,29 +299,61 @@ MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( MC_LS_SETUP mc_ls_setup; mc_ls_setup = MC_LS_SETUP_INVALID; - move16(); + + switch ( output_config ) + { + case IVAS_AUDIO_CONFIG_5_1: + mc_ls_setup = MC_LS_SETUP_5_1; + break; + case IVAS_AUDIO_CONFIG_7_1: + mc_ls_setup = MC_LS_SETUP_7_1; + break; + case IVAS_AUDIO_CONFIG_5_1_2: + mc_ls_setup = MC_LS_SETUP_5_1_2; + break; + case IVAS_AUDIO_CONFIG_5_1_4: + mc_ls_setup = MC_LS_SETUP_5_1_4; + break; + case IVAS_AUDIO_CONFIG_7_1_4: + mc_ls_setup = MC_LS_SETUP_7_1_4; + break; + default: + assert( 0 && "Output config is not a valid MC loudspeaker setup!\n" ); + } + + return mc_ls_setup; +} +#else +MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup_fx( + const AUDIO_CONFIG output_config /* i : output audio configuration */ +) +{ + MC_LS_SETUP mc_ls_setup; + + mc_ls_setup = MC_LS_SETUP_INVALID; + move32(); SWITCH( output_config ) { case IVAS_AUDIO_CONFIG_5_1: mc_ls_setup = MC_LS_SETUP_5_1; - move16(); + move32(); BREAK; case IVAS_AUDIO_CONFIG_7_1: mc_ls_setup = MC_LS_SETUP_7_1; - move16(); + move32(); BREAK; case IVAS_AUDIO_CONFIG_5_1_2: mc_ls_setup = MC_LS_SETUP_5_1_2; - move16(); + move32(); BREAK; case IVAS_AUDIO_CONFIG_5_1_4: mc_ls_setup = MC_LS_SETUP_5_1_4; - move16(); + move32(); BREAK; case IVAS_AUDIO_CONFIG_7_1_4: mc_ls_setup = MC_LS_SETUP_7_1_4; - move16(); + move32(); BREAK; default: assert( 0 && "Output config is not a valid MC loudspeaker setup!\n" ); @@ -253,6 +361,7 @@ MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( return mc_ls_setup; } +#endif /*--------------------------------------------------------------- @@ -262,35 +371,72 @@ MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup( * ---------------------------------------------------------------*/ /*! r: audio configuration*/ +#ifndef IVAS_FLOAT_FIXED AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config( const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup*/ ) { AUDIO_CONFIG audio_config; audio_config = IVAS_AUDIO_CONFIG_INVALID; - move16(); + + switch ( mc_ls_setup ) + { + case MC_LS_SETUP_5_1: + audio_config = IVAS_AUDIO_CONFIG_5_1; + break; + case MC_LS_SETUP_7_1: + audio_config = IVAS_AUDIO_CONFIG_7_1; + break; + case MC_LS_SETUP_5_1_2: + audio_config = IVAS_AUDIO_CONFIG_5_1_2; + break; + case MC_LS_SETUP_5_1_4: + audio_config = IVAS_AUDIO_CONFIG_5_1_4; + break; + case MC_LS_SETUP_7_1_4: + audio_config = IVAS_AUDIO_CONFIG_7_1_4; + break; + default: + assert( 0 && "MC loudspeaker setup is not valid!\n" ); + } + + return audio_config; +} +#else +AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config_fx( + const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup*/ +) +{ + AUDIO_CONFIG audio_config; + audio_config = IVAS_AUDIO_CONFIG_INVALID; + move32(); SWITCH( mc_ls_setup ) { case MC_LS_SETUP_5_1: audio_config = IVAS_AUDIO_CONFIG_5_1; + move32(); BREAK; case MC_LS_SETUP_7_1: audio_config = IVAS_AUDIO_CONFIG_7_1; + move32(); BREAK; case MC_LS_SETUP_5_1_2: audio_config = IVAS_AUDIO_CONFIG_5_1_2; + move32(); BREAK; case MC_LS_SETUP_5_1_4: audio_config = IVAS_AUDIO_CONFIG_5_1_4; + move32(); BREAK; case MC_LS_SETUP_7_1_4: audio_config = IVAS_AUDIO_CONFIG_7_1_4; + move32(); BREAK; default: assert( 0 && "MC loudspeaker setup is not valid!\n" ); } - move16(); return audio_config; } +#endif diff --git a/lib_com/ivas_mc_param_com.c b/lib_com/ivas_mc_param_com.c index 07c646cb7..07ab1f9b8 100644 --- a/lib_com/ivas_mc_param_com.c +++ b/lib_com/ivas_mc_param_com.c @@ -117,7 +117,7 @@ void ivas_param_mc_metadata_open( #ifndef FIX_901_PARAMMC_DEAD_CODE Word16 nchan_setup; - nchan_setup = ivas_mc_ls_setup_get_num_channels( mc_ls_setup ); + nchan_setup = ivas_mc_ls_setup_get_num_channels_fx( mc_ls_setup ); #endif /* get coding band mappings */ diff --git a/lib_com/ivas_mcmasa_com.c b/lib_com/ivas_mcmasa_com.c index 53693bf0b..f8550d48e 100644 --- a/lib_com/ivas_mcmasa_com.c +++ b/lib_com/ivas_mcmasa_com.c @@ -39,15 +39,13 @@ #endif -#ifdef IVAS_FLOAT_FIXED -#define MCMASA_MONOBITRATIO_64k_Q31 ( 536870912 ) -#define MCMASA_MONOBITRATIO_Q31 ( 644245095 ) /*--------------------------------------------------------------------------* * ivas_mcmasa_setNumTransportChannels() * * Set number of transport channels in McMASA *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_setNumTransportChannels_fx( Word16 *nchan_transport, /* o : Pointer to number of transport channels to be set */ Word16 *element_mode, /* o : Pointer to element mode to be set */ @@ -71,6 +69,27 @@ void ivas_mcmasa_setNumTransportChannels_fx( return; } +#else +void ivas_mcmasa_setNumTransportChannels( + int16_t *nchan_transport, /* o : Pointer to number of transport channels to be set */ + int16_t *element_mode, /* o : Pointer to element mode to be set */ + const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ +) +{ + if ( ivas_total_brate >= IVAS_48k ) + { + *nchan_transport = 2; + *element_mode = IVAS_CPE_MDCT; + } + else + { + *nchan_transport = 1; + *element_mode = IVAS_SCE; + } + + return; +} +#endif /*--------------------------------------------------------------------------* @@ -79,6 +98,7 @@ void ivas_mcmasa_setNumTransportChannels_fx( * Set separate channel parameters in McMASA based on bitrate *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_set_separate_channel_mode_fx( UWord8 *separateChannelEnabled, /* o : Pointer to separate channel toggle */ Word16 *separateChannelIndex, /* o : Pointer to separate channel index */ @@ -100,6 +120,27 @@ void ivas_mcmasa_set_separate_channel_mode_fx( return; } +#else +void ivas_mcmasa_set_separate_channel_mode( + uint8_t *separateChannelEnabled, /* o : Pointer to separate channel toggle */ + int16_t *separateChannelIndex, /* o : Pointer to separate channel index */ + const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ +) +{ + if ( ivas_total_brate >= MCMASA_SEPARATE_BRATE ) + { + *separateChannelEnabled = 1; + *separateChannelIndex = 2; /* Center channel */ + } + else + { + *separateChannelEnabled = 0; + *separateChannelIndex = 0; + } + + return; +} +#endif /*--------------------------------------------------------------------------* @@ -108,6 +149,7 @@ void ivas_mcmasa_set_separate_channel_mode_fx( * Split the total bitrate to elements in McMASA *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_split_brate_fx( const UWord8 separateChannelEnabled, /* i : Transport running in "separate channel" mode */ const Word32 ivas_total_brate, /* i : IVAS total bitrate available to be split */ @@ -122,11 +164,11 @@ void ivas_mcmasa_split_brate_fx( /* 25% of total bitrate is used for SCE below 96 kb/s (separated mono channel), otherwise 30% */ IF( LT_32( ivas_total_brate, IVAS_96k ) ) { - *brate_sce = (Word32) ( Mpy_32_32( MCMASA_MONOBITRATIO_64k_Q31, ivas_total_brate ) ); // Q0 + *brate_sce = Mpy_32_32( MCMASA_MONOBITRATIO_64k_Q31, ivas_total_brate ); /* Q0 */ } ELSE { - *brate_sce = (Word32) ( Mpy_32_32( MCMASA_MONOBITRATIO_Q31, ivas_total_brate ) ); // Q0 + *brate_sce = Mpy_32_32( MCMASA_MONOBITRATIO_Q31, ivas_total_brate ); /* Q0 */ } *brate_cpe = L_sub( ivas_total_brate, *brate_sce ); @@ -134,6 +176,7 @@ void ivas_mcmasa_split_brate_fx( ELSE { Word16 tmp_e = 0; + move16(); Word16 tmp = BASOP_Util_Divide3216_Scale( ivas_total_brate, ( add( nCPE, nSCE ) ), &tmp_e ); *brate_sce = GT_16( nSCE, 0 ) ? ( L_shr( (Word32) tmp, negate( add( 1, tmp_e ) ) ) ) : 0; move32(); @@ -143,67 +186,7 @@ void ivas_mcmasa_split_brate_fx( return; } -#endif -/*--------------------------------------------------------------------------* - * ivas_mcmasa_setNumTransportChannels() - * - * Set number of transport channels in McMASA - *--------------------------------------------------------------------------*/ - -void ivas_mcmasa_setNumTransportChannels( - int16_t *nchan_transport, /* o : Pointer to number of transport channels to be set */ - int16_t *element_mode, /* o : Pointer to element mode to be set */ - const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ -) -{ - if ( ivas_total_brate >= IVAS_48k ) - { - *nchan_transport = 2; - *element_mode = IVAS_CPE_MDCT; - } - else - { - *nchan_transport = 1; - *element_mode = IVAS_SCE; - } - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_mcmasa_set_separate_channel_mode() - * - * Set separate channel parameters in McMASA based on bitrate - *--------------------------------------------------------------------------*/ - -void ivas_mcmasa_set_separate_channel_mode( - uint8_t *separateChannelEnabled, /* o : Pointer to separate channel toggle */ - int16_t *separateChannelIndex, /* o : Pointer to separate channel index */ - const int32_t ivas_total_brate /* i : Total bitrate of IVAS */ -) -{ - if ( ivas_total_brate >= MCMASA_SEPARATE_BRATE ) - { - *separateChannelEnabled = 1; - *separateChannelIndex = 2; /* Center channel */ - } - else - { - *separateChannelEnabled = 0; - *separateChannelIndex = 0; - } - - return; -} - - -/*--------------------------------------------------------------------------* - * ivas_mcmasa_split_brate() - * - * Split the total bitrate to elements in McMASA - *--------------------------------------------------------------------------*/ - +#else void ivas_mcmasa_split_brate( const uint8_t separateChannelEnabled, /* i : Transport running in "separate channel" mode */ const int32_t ivas_total_brate, /* i : IVAS total bitrate available to be split */ @@ -235,3 +218,4 @@ void ivas_mcmasa_split_brate( return; } +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 15826bdec..1aab20d0e 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -788,20 +788,14 @@ ivas_error ivas_mc_dec_config( /*! r: MC format mode (MCT, McMASA, ParamMC) */ MC_MODE ivas_mc_mode_select( - const MC_LS_SETUP mc_ls_setup, /* i : loudspeaker setup (CICP) */ - const Word32 total_brate /* i : IVAS total bitrate */ + const MC_LS_SETUP mc_ls_setup, /* i : MC loudspeaker setup */ + const int32_t total_brate /* i : IVAS total bitrate */ ); /*! r: number of loudspeaker channels */ -#ifdef IVAS_FLOAT_FIXED -Word16 ivas_mc_ls_setup_get_num_channels( - const MC_LS_SETUP mc_ls_setup /* i : loudspeaker setup (CICP) */ -); -#else int16_t ivas_mc_ls_setup_get_num_channels( const MC_LS_SETUP mc_ls_setup /* i : loudspeaker setup (CICP) */ ); -#endif /*! r: output configuration*/ AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 659ae5827..e91e31d23 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2282,4 +2282,25 @@ ivas_error ivas_jbm_dec_render_fx( UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */ Word16 *data /* o : output synthesis signal */ ); + +/*! r: MC format mode (MCT, McMASA, ParamMC) */ +MC_MODE ivas_mc_mode_select_fx( + const MC_LS_SETUP mc_ls_setup, /* i : MC loudspeaker setup */ + const Word32 total_brate /* i : IVAS total bitrate */ +); + +/*! r: number of loudspeaker channels */ +Word16 ivas_mc_ls_setup_get_num_channels_fx( + const MC_LS_SETUP mc_ls_setup /* i : loudspeaker setup (CICP) */ +); + +/*! r: multi channel loudspeaker setup */ +MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup_fx( + const AUDIO_CONFIG output_config /* i : output audio configuration */ +); + +/*! r: output configuration */ +AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config_fx( + const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup*/ +); #endif diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 87c1c17b0..862ecaa11 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -82,7 +82,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) ) { - last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ + last_mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ } ELSE { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 9d528f8df..5e18e1750 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2253,7 +2253,7 @@ ivas_error ivas_init_decoder_fx( } } - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) ); st_ivas->nSCE = 0; st_ivas->nCPE = st_ivas->nchan_transport / CPE_CHANNELS; diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a638ee537..6dce33f67 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1002,7 +1002,7 @@ ivas_error ivas_masa_decode_fx( test(); IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - hQMetaData->q_direction->cfg.mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + hQMetaData->q_direction->cfg.mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); } ELSE { @@ -1728,7 +1728,7 @@ static ivas_error ivas_masa_dec_config_fx( test(); IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - st_ivas->hQMetaData->q_direction[i].cfg.mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + st_ivas->hQMetaData->q_direction[i].cfg.mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); } ELSE { diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 23d454fbd..2badc75fe 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -211,7 +211,7 @@ ivas_error ivas_param_mc_dec_open_fx( #ifndef FIX_901_PARAMMC_DEAD_CODE hTransportSetup = st_ivas->hTransSetup; #endif - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hParamMC->hoa_encoder_fx = NULL; #if 1 /*TODO: To be removed later(floating pointer initialization)*/ @@ -1109,7 +1109,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( #ifndef FIX_901_PARAMMC_DEAD_CODE hTransportSetup = st_ivas->hTransSetup; #endif - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index c010fb175..1ccf304df 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -114,24 +114,15 @@ ivas_error ivas_mcmasa_dec_reconfig( #endif /* get new McMASA settings */ -#ifdef IVAS_FLOAT_FIXED - ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); - ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); -#else ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->element_mode_init ), ivas_total_brate ); ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hOutSetup.separateChannelEnabled ), &( st_ivas->hOutSetup.separateChannelIndex ), ivas_total_brate ); -#endif /* transport channel settings may affect renderer */ ivas_renderer_select( st_ivas ); /* renderer change may affect internal config */ ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); -#ifdef IVAS_FLOAT_FIXED - ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); -#else ivas_mcmasa_set_separate_channel_mode( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); -#endif #ifdef IVAS_FLOAT_FIXED if ( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 8e4d8f4b1..88605f837 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -339,7 +339,7 @@ ivas_error ivas_mct_dec_fx( IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->bfi, 0 ) ) { /* get the number of channels from the signalled MC LS setup */ - n = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); + n = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) ); IF( NE_16( n, st_ivas->nchan_transport ) ) { @@ -1346,7 +1346,7 @@ ivas_error ivas_mc_dec_config_fx( IF( EQ_16( st_ivas->bfi, 0 ) ) { /* set transported MC LS setup */ - signaled_config = ivas_mc_map_ls_setup_to_output_config( idx ); + signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx ); IF( EQ_16( st_ivas->ini_frame, 0 ) ) { @@ -1354,7 +1354,7 @@ ivas_error ivas_mc_dec_config_fx( } /* select MC format mode */ - st_ivas->mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); + st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); /* MC format switching */ IF( st_ivas->ini_frame != 0 ) @@ -1468,7 +1468,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; nchan_transport_old = st_ivas->nchan_transport; nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); - last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ + last_mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ /* temporally set the current mc_mode back to the previous one to make sure the following call to ivas_init_dec_get_num_cldfb_instances() returns the correct counts */ @@ -1543,7 +1543,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( } IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { - st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) ); st_ivas->nSCE = 0; st_ivas->nCPE = st_ivas->nchan_transport / 2; diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 8e036270b..5edade576 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -784,7 +784,7 @@ ivas_error IVAS_DEC_FeedFrame_Serial( hParamMC = hIvasDec->st_ivas->hParamMC; MC_LS_SETUP mc_ls_setup; Word16 i; - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( hIvasDec->st_ivas->transport_config ); + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( hIvasDec->st_ivas->transport_config ); hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); IF( hParamMC ) { @@ -1207,7 +1207,7 @@ static ivas_error IVAS_DEC_Setup( PARAM_MC_DEC_HANDLE hParamMC; hParamMC = st_ivas->hParamMC; MC_LS_SETUP mc_ls_setup; - mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ); + mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); IF( hParamMC ) { diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index d48aa6997..cc7ee8f2c 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -800,7 +800,11 @@ ivas_error ivas_init_encoder( } else if ( ivas_format == MC_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); +#else + st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); +#endif if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) { @@ -830,7 +834,11 @@ ivas_error ivas_init_encoder( return error; } +#ifndef IVAS_FLOAT_FIXED st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); +#else + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); +#endif } else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { @@ -888,7 +896,11 @@ ivas_error ivas_init_encoder( { int32_t brate_sce, brate_cpe; +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); +#else + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); +#endif if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { @@ -905,7 +917,11 @@ ivas_error ivas_init_encoder( return error; } +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#else + ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#endif for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { @@ -1361,7 +1377,11 @@ ivas_error ivas_init_encoder_fx( } else if ( ivas_format == MC_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate ); +#else + st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); +#endif if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK ) { @@ -1391,7 +1411,11 @@ ivas_error ivas_init_encoder_fx( return error; } +#ifndef IVAS_FLOAT_FIXED st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); +#else + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); +#endif } else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) { @@ -1449,7 +1473,11 @@ ivas_error ivas_init_encoder_fx( { int32_t brate_sce, brate_cpe; +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); +#else + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate ); +#endif if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { @@ -1466,7 +1494,11 @@ ivas_error ivas_init_encoder_fx( return error; } +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#else + ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe ); +#endif for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 02c99e1ff..56800005b 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -41,6 +41,9 @@ #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*------------------------------------------------------------------------- @@ -116,7 +119,11 @@ ivas_error ivas_mcmasa_enc_open( input_Fs = st_ivas->hEncoderConfig->input_Fs; /* Determine if to separate some channels from the analysis */ +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_set_separate_channel_mode( &( hMcMasa->separateChannelEnabled ), &( hMcMasa->separateChannelIndex ), st_ivas->hEncoderConfig->ivas_total_brate ); +#else + ivas_mcmasa_set_separate_channel_mode_fx( &( hMcMasa->separateChannelEnabled ), &( hMcMasa->separateChannelIndex ), st_ivas->hEncoderConfig->ivas_total_brate ); +#endif numAnalysisChannels = nchan_inp - 1; if ( hMcMasa->separateChannelEnabled ) @@ -451,7 +458,11 @@ ivas_error ivas_mcmasa_enc_reconfig( ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs ); /* Determine if to separate some channels from the analysis */ +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), ivas_total_brate ); +#else + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), ivas_total_brate ); +#endif if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 50b7d7ab8..49364ad7f 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -620,7 +620,11 @@ ivas_error ivas_mc_enc_config( last_mc_mode = st_ivas->mc_mode; /* select MC format mode */ +#ifndef IVAS_FLOAT_FIXED st_ivas->mc_mode = ivas_mc_mode_select( st_ivas->hEncoderConfig->mc_input_setup, st_ivas->hEncoderConfig->ivas_total_brate ); +#else + st_ivas->mc_mode = ivas_mc_mode_select_fx( st_ivas->hEncoderConfig->mc_input_setup, st_ivas->hEncoderConfig->ivas_total_brate ); +#endif /* write MC LS setup */ st0 = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; @@ -669,7 +673,11 @@ static ivas_error ivas_mc_enc_reconfig( st_ivas->nSCE = 0; st_ivas->nCPE = st_ivas->hEncoderConfig->nchan_inp / 2; +#ifndef IVAS_FLOAT_FIXED st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup ); +#else + st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); +#endif if ( last_mc_mode != MC_MODE_MCT ) { @@ -789,7 +797,11 @@ static ivas_error ivas_mc_enc_reconfig( { if ( last_mc_mode != MC_MODE_MCMASA ) { +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); +#else + ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( st_ivas->hEncoderConfig->element_mode_init ), st_ivas->hEncoderConfig->ivas_total_brate ); +#endif if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) { @@ -893,7 +905,11 @@ static ivas_error ivas_mc_enc_reconfig( if ( st_ivas->mc_mode == MC_MODE_MCMASA ) { +#ifndef IVAS_FLOAT_FIXED ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); +#else + ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); +#endif } else if ( st_ivas->mc_mode == MC_MODE_MCT ) { diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 33c01705d..b2eaa4800 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -762,7 +762,11 @@ ivas_error IVAS_ENC_ConfigureForMultichannel( break; } +#ifndef IVAS_FLOAT_FIXED hEncoderConfig->nchan_inp = ivas_mc_ls_setup_get_num_channels( hEncoderConfig->mc_input_setup ); +#else + hEncoderConfig->nchan_inp = ivas_mc_ls_setup_get_num_channels_fx( hEncoderConfig->mc_input_setup ); +#endif hIvasEnc->maxBandwidthUser = max_bwidth_user; -- GitLab From 1db587e54234df9cb0cacdc948eb8c084e32c740 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 14 Jun 2024 14:23:24 +0530 Subject: [PATCH 34/63] Fix for issue 787: Extra 2ms delay in OSBA STEREO output --- lib_dec/ivas_mct_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 88605f837..42d82f995 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -628,7 +628,7 @@ ivas_error ivas_mct_dec_fx( } /* synthesis synchronization between stereo modes */ - IF( EQ_16( st_ivas->sba_dirac_stereo_flag, 0 ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && LE_16( cpe_id, sub( nCPE, 2 ) ) ) ) + IF( EQ_16( st_ivas->sba_dirac_stereo_flag, 0 ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && LT_16( cpe_id, sub( nCPE, 2 ) ) ) ) { synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); } -- GitLab From 48a8e62359f414c82dd640ee8b6fbaed1f5f494d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 14 Jun 2024 15:16:32 +0530 Subject: [PATCH 35/63] Fix for issue 789: Fluttering noise in SBA binaural room reverb output [x] Fix for issue 789 [x] tcxnoisebuf cleanup. --- lib_com/prot.h | 2 +- lib_com/tcx_utils.c | 2 +- lib_dec/dec_tcx.c | 2 +- lib_dec/igf_dec.c | 46 ++++++++++++------------ lib_dec/igf_dec_fx.c | 19 +++------- lib_dec/ivas_core_dec.c | 6 ---- lib_dec/ivas_mct_dec.c | 2 +- lib_dec/ivas_mct_dec_mct_fx.c | 23 ------------ lib_dec/ivas_stereo_mdct_core_dec_fx.c | 48 +------------------------ lib_dec/lib_dec_fx.c | 49 ++------------------------ lib_dec/stat_dec.h | 5 +-- 11 files changed, 38 insertions(+), 166 deletions(-) diff --git a/lib_com/prot.h b/lib_com/prot.h index 698b29187..817465058 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -7718,7 +7718,7 @@ void tcx_noise_filling_flt( const int16_t L_frame, const float tiltCompFactor, float fac_ns, - uint8_t *infoTCXNoise, + Word16 *infoTCXNoise, const int16_t element_mode /* i : IVAS element mode */ ); diff --git a/lib_com/tcx_utils.c b/lib_com/tcx_utils.c index 4cd7d8c8c..06d12bb36 100644 --- a/lib_com/tcx_utils.c +++ b/lib_com/tcx_utils.c @@ -840,7 +840,7 @@ void tcx_noise_filling_flt( const int16_t L_frame, const float tiltCompFactor, float fac_ns, - uint8_t *infoTCXNoise, + Word16 *infoTCXNoise, const int16_t element_mode /* i : IVAS element mode */ ) { diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 4692a482e..586470bac 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -1178,7 +1178,7 @@ void decoder_tcx_noisefilling( nf_seed += (int16_t) ( abs( prm_sqQ[i] ) * i * 2 ); } } - tcx_noise_filling_flt( x, nf_seed, firstLine, noiseFillingSize, noiseTransWidth, L_frame, noiseTiltFactor, fac_ns, st->igf ? st->hIGFDec->infoTCXNoise : NULL, st->element_mode ); + tcx_noise_filling_flt( x, nf_seed, firstLine, noiseFillingSize, noiseTransWidth, L_frame, noiseTiltFactor, fac_ns, st->igf ? st->hIGFDec->infoTCXNoise_ptr : NULL, st->element_mode ); st->seed_tcx_plc = nf_seed; } diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index 6ef921b52..2afd2cb8a 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -58,7 +58,7 @@ #ifndef IVAS_FLOAT_FIXED static int16_t IGF_replaceTCXNoise_1_flr( const float *in, /* i : MDCT spectrum */ - const uint8_t *TCXNoise, /* i : tcx noise indicator vector */ + const int16_t *TCXNoise, /* i : tcx noise indicator vector */ const int16_t start, /* i : start MDCT subband index */ const int16_t stop, /* i : stop MDCT subband index */ float *totalNoiseNrg /* o : measured noise energy */ @@ -95,7 +95,7 @@ static int16_t IGF_replaceTCXNoise_1_flr( #ifndef IVAS_FLOAT_FIXED static void IGF_replaceTCXNoise_2_flt( float *in, /* i/o: MDCT spectrum */ - const uint8_t *TCXNoise, /* i : tcx noise indicator vector */ + const int16_t *TCXNoise, /* i : tcx noise indicator vector */ const int16_t start, /* i : start MDCT subband index */ const int16_t stop, /* i : stop MDCT subband index */ float totalNoiseNrg, /* i : measured noise energy */ @@ -141,7 +141,7 @@ static void IGF_replaceTCXNoise_2_flt( #ifndef IVAS_FLOAT_FIXED static void IGF_replaceTCXNoise_2_new_flt( float *in, /* i/o: MDCT spectrum */ - const uint8_t *TCXNoise, /* i : tcx noise indicator vector */ + const int16_t *TCXNoise, /* i : tcx noise indicator vector */ const int16_t start, /* i : start MDCT subband index */ const int16_t stop, /* i : stop MDCT subband index */ float totalNoiseNrg, /* i : measured noise energy */ @@ -326,7 +326,7 @@ static void IGF_setLinesToZero_flt( static void IGF_prep_flt( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /* i : IGF private data handle */ const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ - const uint8_t *TCXNoise, /* i : TCX noise vector */ + const int16_t *TCXNoise, /* i : TCX noise vector */ float *igf_spec, /* o : prepared IGF spectrum */ float *src_spec, /* i : source spectrum */ const int16_t element_mode /* i : IVAS element mode */ @@ -450,8 +450,8 @@ static void IGF_prepStereo_flt( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, /* i : IGF private data handle */ IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataR, /* i : IGF private data handle */ const int16_t igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ - const uint8_t *TCXNoiseL, /* i : TCX noise vector */ - const uint8_t *TCXNoiseR, /* i : TCX noise vector */ + const int16_t *TCXNoiseL, /* i : TCX noise vector */ + const int16_t *TCXNoiseR, /* i : TCX noise vector */ float *igf_specL, /* o : prepared IGF spectrum */ float *igf_specR, /* o : prepared IGF spectrum */ float *src_specL, /* i : source spectrum */ @@ -1214,7 +1214,7 @@ void IGFDecApplyMono_flt( mvr2r( hPrivateData->pSpecFlat_float, igf_spec, hGrid->startLine ); } - hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1_flr( igf_spec, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_float ); + hPrivateData->n_noise_bands = IGF_replaceTCXNoise_1_flr( igf_spec, hIGFDec->infoTCXNoise_ptr, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_float ); break; } } @@ -1223,13 +1223,13 @@ void IGFDecApplyMono_flt( { if ( hPrivateData->currWhiteningLevel[i] == IGF_WHITENING_OFF ) { - hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1_flr( hPrivateData->pSpecFlat_float, hIGFDec->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_off_float ); + hPrivateData->n_noise_bands_off = IGF_replaceTCXNoise_1_flr( hPrivateData->pSpecFlat_float, hIGFDec->infoTCXNoise_ptr, hGrid->minSrcSubband, hGrid->startLine, &hPrivateData->totalNoiseNrg_off_float ); break; } } /* apply IGF in three steps: */ - IGF_prep_flt( hPrivateData, igfGridIdx, hIGFDec->infoTCXNoise, igf_spec, hPrivateData->pSpecFlat_float, element_mode ); + IGF_prep_flt( hPrivateData, igfGridIdx, hIGFDec->infoTCXNoise_ptr, igf_spec, hPrivateData->pSpecFlat_float, element_mode ); IGF_calc_flt( hPrivateData, igfGridIdx, spectrum, igf_spec ); IGF_appl_flt( hPrivateData, igfGridIdx, spectrum, igf_spec, hIGFDec->virtualSpec_float, hIGFDec->flag_sparse, 1 ); } @@ -1237,7 +1237,7 @@ void IGFDecApplyMono_flt( /* reset TCX noise indicator vector */ nLinesToReset = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1; nLinesToReset = IGF_START_MX / nLinesToReset; - set_c( (int8_t *) ( hIGFDec->infoTCXNoise ), 0, nLinesToReset ); + set_s( (int16_t *) ( hIGFDec->infoTCXNoise_ptr ), 0, nLinesToReset ); return; } @@ -1327,7 +1327,7 @@ void IGFDecApplyStereo_flt( mvr2r( hPrivateDataL->pSpecFlat_float, igf_specL, hGrid->startLine ); } - hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1_flr( igf_specL, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg_float ); + hPrivateDataL->n_noise_bands = IGF_replaceTCXNoise_1_flr( igf_specL, hIGFDecL->infoTCXNoise_ptr, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg_float ); if ( !bfi ) { @@ -1338,7 +1338,7 @@ void IGFDecApplyStereo_flt( mvr2r( hPrivateDataR->pSpecFlat_float, igf_specR, hGrid->startLine ); } - hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1_flr( igf_specR, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg_float ); + hPrivateDataR->n_noise_bands = IGF_replaceTCXNoise_1_flr( igf_specR, hIGFDecR->infoTCXNoise_ptr, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg_float ); break; } @@ -1348,15 +1348,15 @@ void IGFDecApplyStereo_flt( { if ( hPrivateDataL->currWhiteningLevel[i] == IGF_WHITENING_OFF || hPrivateDataR->currWhiteningLevel[i] == IGF_WHITENING_OFF ) { - hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1_flr( hPrivateDataL->pSpecFlat_float, hIGFDecL->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg_off_float ); + hPrivateDataL->n_noise_bands_off = IGF_replaceTCXNoise_1_flr( hPrivateDataL->pSpecFlat_float, hIGFDecL->infoTCXNoise_ptr, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataL->totalNoiseNrg_off_float ); - hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1_flr( hPrivateDataR->pSpecFlat_float, hIGFDecR->infoTCXNoise, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg_off_float ); + hPrivateDataR->n_noise_bands_off = IGF_replaceTCXNoise_1_flr( hPrivateDataR->pSpecFlat_float, hIGFDecR->infoTCXNoise_ptr, hGrid->minSrcSubband, hGrid->startLine, &hPrivateDataR->totalNoiseNrg_off_float ); break; } } /* apply IGF in three steps: */ - IGF_prepStereo_flt( hPrivateDataL, hPrivateDataR, igfGridIdx, hIGFDecL->infoTCXNoise, hIGFDecR->infoTCXNoise, igf_specL, igf_specR, hPrivateDataL->pSpecFlat_float, hPrivateDataR->pSpecFlat_float, coreMsMask ); + IGF_prepStereo_flt( hPrivateDataL, hPrivateDataR, igfGridIdx, hIGFDecL->infoTCXNoise_ptr, hIGFDecR->infoTCXNoise_ptr, igf_specL, igf_specR, hPrivateDataL->pSpecFlat_float, hPrivateDataR->pSpecFlat_float, coreMsMask ); IGF_calc_flt( hPrivateDataL, igfGridIdx, spectrumL, igf_specL ); IGF_calc_flt( hPrivateDataR, igfGridIdx, spectrumR, igf_specR ); @@ -1367,8 +1367,8 @@ void IGFDecApplyStereo_flt( /* reset TCX noise indicator vector */ nLinesToReset = ( igfGridIdx == IGF_GRID_LB_SHORT ) ? 2 : 1; nLinesToReset = IGF_START_MX / nLinesToReset; - set_c( (int8_t *) ( hIGFDecL->infoTCXNoise ), 0, nLinesToReset ); - set_c( (int8_t *) ( hIGFDecR->infoTCXNoise ), 0, nLinesToReset ); + set_s( (int16_t *) ( hIGFDecL->infoTCXNoise_ptr ), 0, nLinesToReset ); + set_s( (int16_t *) ( hIGFDecR->infoTCXNoise_ptr ), 0, nLinesToReset ); return; } @@ -1426,7 +1426,7 @@ void IGFDecSetMode_flt( } hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; #ifdef IVAS_FLOAT_FIXED hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; @@ -1457,7 +1457,7 @@ void IGFDecUpdateInfo_flt( H_IGF_GRID hGrid; hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; @@ -1493,7 +1493,7 @@ void IGFDecReplicateTCX10State_flt( ) { mvs2s( &hIGFDec->flag_sparseBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->flag_sparseBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); - mvc2c( &hIGFDec->infoTCXNoiseBuf[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoiseBuf[0], ( IGF_START_MX ) / 2 ); + mvs2s( &hIGFDec->infoTCXNoise_evs[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoise_evs[0], ( IGF_START_MX ) / 2 ); mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 ); #ifdef IVAS_FLOAT_FIXED @@ -1594,7 +1594,7 @@ void IGFDecRestoreTCX10SubFrameData_flt( /* restore flattening trigger for current subframe */ hIGFDec->flatteningTrigger = hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx]; hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[subFrameIdx * ( IGF_START_MX ) / 2]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[subFrameIdx * ( IGF_START_MX ) / 2]; hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2]; hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[subFrameIdx * IGF_START_MX / 2]; hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[subFrameIdx]; @@ -1612,14 +1612,14 @@ void init_igf_dec_flt( IGF_DEC_INSTANCE_HANDLE hIGFDec /* i/o: IGF decoder handle */ ) { - set_c( (int8_t *) ( hIGFDec->infoTCXNoiseBuf ), 0, IGF_START_MX ); + set_s( (int16_t *) ( hIGFDec->infoTCXNoise_evs ), 0, IGF_START_MX ); set_f( hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); hIGFDec->igfData.igfInfo.nfSeedBuf[0] = 9733; hIGFDec->igfData.igfInfo.nfSeedBuf[1] = 9733; hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; return; diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index deace01a0..d2c4670b3 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -3987,7 +3987,7 @@ void IGFDecSetMode_ivas_fx( } hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; return; } /**********************************************************************/ /* @@ -4032,7 +4032,7 @@ void IGFDecUpdateInfo_ivas_fx( H_IGF_GRID hGrid; hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; @@ -4057,15 +4057,6 @@ void IGFDecUpdateInfo_ivas_fx( hIGFDec->infoIGFStopLine = hGrid->stopLine; move16(); } - - /* TODO: this was added to keep the EVS 16-bit noise info in sync. */ - FOR( Word16 l = 0; l < IGF_START_MX; l++ ) - { - // u8bit to 16bit - hIGFDec->infoTCXNoise_evs[l] = (Word16) hIGFDec->infoTCXNoise[l]; - move16(); - } - return; } @@ -4074,7 +4065,7 @@ void IGFDecReplicateTCX10State_fx( ) { Copy( &hIGFDec->flag_sparseBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->flag_sparseBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); - mvc2c( &hIGFDec->infoTCXNoiseBuf[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoiseBuf[0], ( IGF_START_MX ) / 2 ); + mvs2s( &hIGFDec->infoTCXNoise_evs[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoise_evs[0], ( IGF_START_MX ) / 2 ); /* TODO: remove float dependency */ // mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); @@ -4209,7 +4200,7 @@ void IGFDecRestoreTCX10SubFrameData_fx( /* restore flattening trigger for current subframe */ hIGFDec->flatteningTrigger = hPrivateData->igf_flatteningTrigger_subframe[subFrameIdx]; hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[subFrameIdx * ( IGF_START_MX ) / 2]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[subFrameIdx * ( IGF_START_MX ) / 2]; hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[subFrameIdx * ( N_MAX_TCX - IGF_START_MN ) / 2]; hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[subFrameIdx * IGF_START_MX / 2]; @@ -4257,7 +4248,7 @@ void init_igf_dec( set32_fx( hIGFDec->igfData.pSpecFlatBuf_fx, 0, IGF_START_MX ); hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; - hIGFDec->infoTCXNoise = &hIGFDec->infoTCXNoiseBuf[0]; + hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; return; diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 48a3e04c9..0bccf0c82 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -491,12 +491,6 @@ ivas_error ivas_core_dec( st->mem_error = st->hBPF->pst_mem_deemp_err_fx; - // u8bit to 16bit - FOR( int l = 0; l < IGF_START_MX; l++ ) - { - st->hIGFDec->infoTCXNoise_evs[l] = (Word16) st->hIGFDec->infoTCXNoise[l]; - } - /* TCX decoder */ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 42d82f995..3d115b9f4 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1759,7 +1759,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( set_f( st->hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); #endif FOR( Word16 l = 0; l < IGF_START_MX; l++ ) - st->hIGFDec->infoTCXNoiseBuf[l] = (uint8_t) st->hIGFDec->infoTCXNoise_evs[l]; + st->hIGFDec->infoTCXNoise_evs[l] = (uint8_t) st->hIGFDec->infoTCXNoise_evs[l]; #endif } diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx.c index 25774ec40..a91acad66 100644 --- a/lib_dec/ivas_mct_dec_mct_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx.c @@ -371,20 +371,8 @@ void mctStereoIGF_dec_fx( x[p_ch[ch]][k][i] = L_shr( x[p_ch[ch]][k][i], sub( 31 - Q12, x_e ) ); move32(); } - - // IF( st->igf ) - //{ - // // TODO: remove this float to fixed conversion later. - // me2f_buf( st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); - // } } } - // TODO: Converting 16bit noise info to u8bit. can remove this later. - FOR( Word16 i = 0; i < IGF_START_MX; i++ ) - { - sts[0]->hIGFDec->infoTCXNoise[i] = (uint8_t) sts[0]->hIGFDec->infoTCXNoise_evs[i]; - sts[1]->hIGFDec->infoTCXNoise[i] = (uint8_t) sts[1]->hIGFDec->infoTCXNoise_evs[i]; - } } } @@ -433,17 +421,6 @@ void mctStereoIGF_dec_fx( // Converting from variable exponent to Fixed q-factor (Q12) x[ch][k][i] = L_shr( x[ch][k][i], sub( 31 - Q12, x_e ) ); } - - IF( st->igf ) - { - // TODO: Fixed to float. Remove this later. - // me2f_buf( st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); - // TODO: 16bit to u8bit. Remove this later. - FOR( Word16 l = 0; l < IGF_START_MX; l++ ) - { - st->hIGFDec->infoTCXNoise[l] = (uint8_t) st->hIGFDec->infoTCXNoise_evs[l]; - } - } } } } diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 66e01228b..edf392ec4 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -102,7 +102,7 @@ void stereo_mdct_core_dec_fx( ) { Word16 k, ch, nChannels; - Word16 i, l, j; + Word16 i, j; Decoder_State *st, **sts; /* bitstream */ @@ -237,32 +237,8 @@ void stereo_mdct_core_dec_fx( } } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[ch]->hIGFDec->infoTCXNoise[l]; - move16(); - } - } - } - ivas_mdct_core_invQ_fx( hCPE, nTnsBitsTCX10, p_param, param_lpc, param, fUseTns, tnsData, x_0_fx, x_0_e, x_fx, x_e, x_len, Aq_fx, ms_mask, 0 ); - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise[l] = (UWord8) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - } - } - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { Word16 subFrames = ( hCPE->hCoreCoder[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; @@ -307,14 +283,6 @@ void stereo_mdct_core_dec_fx( Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); x_e[ch][k] = 20; move16(); - IF( st->igf ) - { - // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - st->hIGFDec->infoTCXNoise[l] = (UWord8) st->hIGFDec->infoTCXNoise_evs[l]; - } - } } } } @@ -337,12 +305,6 @@ void stereo_mdct_core_dec_fx( x_e[1][k] = 20; move16(); move16(); - - FOR( i = 0; i < IGF_START_MX; i++ ) - { - sts[0]->hIGFDec->infoTCXNoise[i] = (UWord8) sts[0]->hIGFDec->infoTCXNoise_evs[i]; - sts[1]->hIGFDec->infoTCXNoise[i] = (UWord8) sts[1]->hIGFDec->infoTCXNoise_evs[i]; - } } ELSE { @@ -354,14 +316,6 @@ void stereo_mdct_core_dec_fx( Scale_sig32( x_fx[ch][k], x_len[ch][k], sub( x_e[ch][k], 20 ) ); x_e[ch][k] = 20; move16(); - IF( st->igf ) - { - // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - st->hIGFDec->infoTCXNoise[l] = (UWord8) st->hIGFDec->infoTCXNoise_evs[l]; - } - } } } } diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 5edade576..2b979de69 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1333,14 +1333,12 @@ static ivas_error IVAS_DEC_GetTcSamples( { /* run the main IVAS decoding routine */ /*------------------------flt 2 fix----------------------*/ - Word16 l, n; + Word16 n; Decoder_State *st, **sts; /* used for bitstream handling */ - MCT_DEC_HANDLE hMCT; - Word16 ch, nCPE, cpe_id; + Word16 nCPE, cpe_id; nCPE = st_ivas->nCPE; DECODER_TC_BUFFER_HANDLE hTcBuffer = st_ivas->hTcBuffer; Word16 n_ch_cldfb_tmp = hTcBuffer->nchan_transport_jbm - hTcBuffer->nchan_buffer_full; - hMCT = st_ivas->hMCT; Word16 num_freq_bands = 0; /* Float to Fixed */ IF( pcmBuf != NULL ) @@ -1366,7 +1364,6 @@ static ivas_error IVAS_DEC_GetTcSamples( nCPE = st_ivas->nCPE; move16(); - hMCT = st_ivas->hMCT; FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { hCPE = st_ivas->hCPE[cpe_id]; @@ -1376,14 +1373,6 @@ static ivas_error IVAS_DEC_GetTcSamples( FOR( n = 0; n < CPE_CHANNELS; n++ ) { st = hCPE->hCoreCoder[n]; - IF( sts[n]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - // u8bit to 16bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[n]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[n]->hIGFDec->infoTCXNoise[l]; - } - } IF( st->hTcxDec ) st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; IF( st->hTcxDec ) @@ -1481,19 +1470,6 @@ static ivas_error IVAS_DEC_GetTcSamples( { hCPE = st_ivas->hCPE[cpe_id]; sts = hCPE->hCoreCoder; - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = hCPE->hCoreCoder[ch]; - IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) - { - // 16bit to u8bit - FOR( l = 0; l < IGF_START_MX; l++ ) - { - sts[ch]->hIGFDec->infoTCXNoise[l] = (UWord8) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - } - } - FOR( n = 0; n < 2; n++ ) { st = hCPE->hCoreCoder[n]; @@ -1527,27 +1503,6 @@ static ivas_error IVAS_DEC_GetTcSamples( } } } - - - IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) - { - IF( !hMCT->currBlockDataCnt ) - { - FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) - { - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf ) - { - FOR( l = 0; l < IGF_START_MX; l++ ) - { - st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (UWord8) st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; - } - } - } - } - } - } } #endif // fixed to float } diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 29f1db0f1..876e56a1e 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -557,8 +557,9 @@ typedef struct igfdec_instance_struct int16_t infoIGFStartLine; int16_t infoIGFStopFreq; int16_t infoIGFStartFreq; - uint8_t *infoTCXNoise; - uint8_t infoTCXNoiseBuf[IGF_START_MX]; + // uint8_t *infoTCXNoise; + // uint8_t infoTCXNoiseBuf[IGF_START_MX]; + Word16 *infoTCXNoise_ptr; Word16 infoTCXNoise_evs[IGF_START_MX]; int16_t *flag_sparse; int16_t flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; -- GitLab From 8e367bab2734ab4b783aa6f99806e558a92086fa Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 17 Jun 2024 15:03:42 -0400 Subject: [PATCH 36/63] 798 Fix proposal, modifications under FIX_798_LSF_SECONDARY_CH_MISSING_CODE and FIX_798_WRONG_CPY_OF_PITCH --- lib_com/bits_alloc_fx.c | 4 +-- lib_com/ivas_stereo_td_bit_alloc.c | 19 ++++++++++- lib_com/options.h | 2 ++ lib_com/prot_fx2.h | 6 ++-- lib_dec/acelp_core_dec_fx.c | 2 +- lib_dec/acelp_core_dec_ivas_fx.c | 4 +++ lib_dec/cng_dec_fx.c | 2 +- lib_dec/dlpc_stoch_fx.c | 6 ++-- lib_dec/lsf_dec_fx.c | 54 ++++++++++++++++-------------- 9 files changed, 62 insertions(+), 37 deletions(-) diff --git a/lib_com/bits_alloc_fx.c b/lib_com/bits_alloc_fx.c index 514a9f894..5d3fc0dcf 100644 --- a/lib_com/bits_alloc_fx.c +++ b/lib_com/bits_alloc_fx.c @@ -823,7 +823,7 @@ ivas_error config_acelp1( bits -= acelp_cfg->mid_lsf_bits; } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE else if ( tdm_lp_reuse_flag == 1 && idchan == 1 && active_cnt != 1 ) { bits -= TDM_IC_LSF_PRED_BITS; @@ -1384,7 +1384,7 @@ ivas_error config_acelp1( { if ( idchan > 0 && element_mode == IVAS_CPE_TD ) { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE if ( !tdm_lp_reuse_flag ) { acelp_cfg->lsf_bits += bits; /* increase LSF Q bits */ diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 1458bc8e6..326eae880 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -893,7 +893,24 @@ void td_stereo_param_updt_fx( Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); Copy( lsf_old_PCh_fx, tdm_lsfQ_PCh_fx, M ); } +#ifdef FIX_798_WRONG_CPY_OF_PITCH + IF( EQ_16( flag_ACELP16k , 1 ) ) + { + Word16 tmp16; + Word16 mult_factor = 26214 /*0.8f in Q15*/; + FOR( i = 0; i < NB_SUBFR; i++ ) + { + tmp16 = mult_r( pitch_buf_PCh_fx[i], mult_factor ); /* Convert 16kHz to 12.8 kHz pitch values */ + tdm_Pri_pitch_buf_fx[i] = s_max( tmp16, PIT_MIN << 6 ); /* pitch is represented in Q6*/ + move16(); + } + } + ELSE + { + Copy( pitch_buf_PCh_fx, tdm_Pri_pitch_buf_fx, NB_SUBFR ); + } +#else /* This is only to keep the buffer up-to-date */ Word16 mult_factor = 26214 /*0.8f in Q15*/; Word16 min_tdm_Pri_pitch_buf_fx = 0; @@ -919,7 +936,7 @@ void td_stereo_param_updt_fx( { Copy( pitch_buf_PCh_fx, tdm_Pri_pitch_buf_fx, NB_SUBFR ); } - +#endif return; } #endif diff --git a/lib_com/options.h b/lib_com/options.h index 5a6238041..54efb5ce1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -146,6 +146,8 @@ #define FIX_778_STEREO_BRATE_SWITCHING #define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ #define FIX_729_MISSING_RESCALING +#define FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Adding the missing code to properly render the secondary channel of TD stereo*/ +#define FIX_798_WRONG_CPY_OF_PITCH /* The copy of the pitch from primary to secondary channel was wrong AND safety check was really wrong */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 12927bceb..131a12285 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -5501,7 +5501,7 @@ void lsf_dec_fx( 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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif @@ -5615,9 +5615,9 @@ void lsf_end_dec_fx( Word16 *lpc_param, Word16 *LSF_Q_prediction, /* o : LSF prediction mode */ Word16 *nb_indices -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , - const float tdm_lsfQ_PCh[M] + const Word16 tdm_lsfQ_PCh[M] #endif ); diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index dd25918d2..c3cf9be3b 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -801,7 +801,7 @@ ivas_error acelp_core_dec_fx( #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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , tdm_lsfQ_PCh #endif diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 89559d6c2..7722df190 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -755,7 +755,11 @@ ivas_error acelp_core_dec_ivas_fx( if ( !tdm_lp_reuse_flag ) { +#ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE + lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode , tdm_lsfQ_PCh_fx ); +#else lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); +#endif } else { diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 1c5628c8c..d68b63446 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -114,7 +114,7 @@ void CNG_dec_fx( ELSE { lsf_dec_fx( st_fx, 0, Aq, &LSF_Q_prediction, lsf_new, lsp_new, 0, 0 -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif diff --git a/lib_dec/dlpc_stoch_fx.c b/lib_dec/dlpc_stoch_fx.c index c024f1622..83436ea99 100644 --- a/lib_dec/dlpc_stoch_fx.c +++ b/lib_dec/dlpc_stoch_fx.c @@ -51,7 +51,7 @@ void lpc_unquantize_fx( IF( ( EQ_32( st->sr_core, INT_FS_16k ) ) && ( EQ_16( coder_type, UNVOICED ) ) ) { 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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif @@ -62,7 +62,7 @@ void lpc_unquantize_fx( IF( EQ_16( st->core, TCX_20_CORE ) ) { 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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif @@ -71,7 +71,7 @@ void lpc_unquantize_fx( ELSE { 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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , NULL #endif diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 407ea463f..1324c2071 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -8,9 +8,9 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx1.h" /* Function prototypes */ #include "prot_fx2.h" /* Function prototypes */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE #include "ivas_prot.h" -#include "ivas_rom_com.h" +//#include "ivas_rom_com.h" #endif /*-------------------------------------------------------------------* * Local functions @@ -110,7 +110,7 @@ void lsf_dec_fx( 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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif @@ -124,9 +124,7 @@ void lsf_dec_fx( Word16 tmp_old[M + 1], tmp_new[M + 1]; Word16 enr_old = 0, enr_new = 0; Word16 lsf_diff, coder_type; -#ifdef REMOVE_IVAS_UNUSED_PARAMETERS_WARNING - (void) ( tdm_low_rate_mode ); -#endif + /* initialize */ coder_type = st_fx->coder_type; if ( EQ_32( st_fx->core_brate, SID_2k40 ) ) @@ -180,7 +178,12 @@ void lsf_dec_fx( } /* LSF de-quantization */ - lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc ); + lsf_end_dec_fx( st_fx, 0, coder_type, st_fx->bwidth, nBits, lsf_new, param_lpc, LSF_Q_prediction, &no_param_lpc +#ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE + , + tdm_lsfQ_PCh +#endif + ); /* convert quantized LSFs to LSPs */ @@ -367,7 +370,7 @@ void lsf_end_dec_fx( 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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE , const Word16 tdm_lsfQ_PCh[M] /* i : Q LSFs for primary channel */ #endif @@ -395,7 +398,7 @@ void lsf_end_dec_fx( Word16 coder_type; Word16 ber_flag; Word16 flag_1bit_gran; -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE Word16 pred3[M]; #endif flag_1bit_gran = (Word16) GT_16( st->element_mode, EVS_MONO ); @@ -456,7 +459,7 @@ void lsf_end_dec_fx( /*--------------------------------------------------------------------------* * Select safety_net or predictive mode *--------------------------------------------------------------------------*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE IF( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* if secondary channel predmode is set to be > 2 */ @@ -500,16 +503,15 @@ void lsf_end_dec_fx( /*--------------------------------------------------------------------------* * Read indices from array *--------------------------------------------------------------------------*/ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Make sure there are the correct bit allocations */ - IF( st->idchan == 1 && predmode > 2 ) + IF( EQ_16(st->idchan, 1) && GT_16(predmode, 2) ) { - 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 ); + lsf_allocate_fx( nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); stages0 = stages1; - mvs2s( levels1, levels0, stages0 ); - mvs2s( bits1, bits0, stages0 ); + Copy( levels1, levels0, stages0 ); + Copy( bits1, bits0, stages0 ); } #endif @@ -680,26 +682,26 @@ void lsf_end_dec_fx( { pred1[i] = add( pred0[i], mult_r( MU_MA_FX, st->mem_MA_fx[i] ) ); } -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* 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 ( st->tdm_LRTD_flag == 0 && EQ_16(st->idchan, 1) && tdm_lsfQ_PCh != NULL ) { - tdm_SCh_LSF_intra_pred( st->element_brate, tdm_lsfQ_PCh, pred3 ); + tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 ); } #endif IF( safety_net ) { /* LVQ */ -#ifdef LSF_RE_USE_SECONDARY_CHANNEL - if ( st->tdm_LRTD_flag == 0 && st->idchan == 1 && tdm_lsfQ_PCh != NULL ) +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE + if ( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { /* intra mode*/ st->BER_detect = st->BER_detect | - vq_dec_lvq( 0, qlsf, &lindice[1], stages0, M, 9, /*mode_lvq_p,*/ levels0[stages0 - 1] ); + vq_dec_lvq_ivas_fx( 0, qlsf, &lindice[1], stages0, M, 9, levels0[stages0 - 1] ); - v_add( qlsf, pred3, qlsf, M ); - v_sub( qlsf, pred1, st->mem_MA, M ); + Vr_add( qlsf, pred3, qlsf, M ); + Vr_subt( qlsf, pred1, st->mem_MA_fx, M ); } else #endif @@ -721,7 +723,7 @@ void lsf_end_dec_fx( } ELSE { -#ifdef LSF_RE_USE_SECONDARY_CHANNEL +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE IF( EQ_16( predmode, 4 ) ) { mode_lvq_p = 9; @@ -741,7 +743,7 @@ void lsf_end_dec_fx( &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 +#if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE test(); IF( EQ_16( predmode, 1 ) || EQ_16( predmode, 4 ) ) /* MA only */ #else -- GitLab From a2d668cd05f83f4db53c99cb5d6c3c2ef28001ba Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 17 Jun 2024 18:49:59 -0400 Subject: [PATCH 37/63] fix clang_format --- lib_com/ivas_stereo_td_bit_alloc.c | 3 ++- lib_dec/acelp_core_dec_ivas_fx.c | 2 +- lib_dec/lsf_dec_fx.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 326eae880..d86e0a3d7 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -894,7 +894,8 @@ void td_stereo_param_updt_fx( Copy( lsf_old_PCh_fx, tdm_lsfQ_PCh_fx, M ); } #ifdef FIX_798_WRONG_CPY_OF_PITCH - IF( EQ_16( flag_ACELP16k , 1 ) ) + Q_var = 0; + IF( EQ_16( flag_ACELP16k, 1 ) ) { Word16 tmp16; Word16 mult_factor = 26214 /*0.8f in Q15*/; diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 7722df190..57ac9397a 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -756,7 +756,7 @@ ivas_error acelp_core_dec_ivas_fx( if ( !tdm_lp_reuse_flag ) { #ifdef FIX_798_LSF_SECONDARY_CH_MISSING_CODE - lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode , tdm_lsfQ_PCh_fx ); + lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode, tdm_lsfQ_PCh_fx ); #else lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); #endif diff --git a/lib_dec/lsf_dec_fx.c b/lib_dec/lsf_dec_fx.c index 1324c2071..9ba2e84d7 100644 --- a/lib_dec/lsf_dec_fx.c +++ b/lib_dec/lsf_dec_fx.c @@ -505,7 +505,7 @@ void lsf_end_dec_fx( *--------------------------------------------------------------------------*/ #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* Make sure there are the correct bit allocations */ - IF( EQ_16(st->idchan, 1) && GT_16(predmode, 2) ) + IF( EQ_16( st->idchan, 1 ) && GT_16( predmode, 2 ) ) { /* use same AR prediction bit allocation for intra and inter modes*/ lsf_allocate_fx( nBits - 1, mode_lvq, 9, &stages0, &stages1, levels0, levels1, bits0, bits1 ); @@ -684,7 +684,7 @@ void lsf_end_dec_fx( } #if defined LSF_RE_USE_SECONDARY_CHANNEL || defined FIX_798_LSF_SECONDARY_CH_MISSING_CODE /* TD stereo SCh: perform intra-frame prediction with pulling-to-mean */ - if ( st->tdm_LRTD_flag == 0 && EQ_16(st->idchan, 1) && tdm_lsfQ_PCh != NULL ) + if ( st->tdm_LRTD_flag == 0 && EQ_16( st->idchan, 1 ) && tdm_lsfQ_PCh != NULL ) { tdm_SCh_LSF_intra_pred_fx( st->element_brate, tdm_lsfQ_PCh, pred3 ); } -- GitLab From f4fa28668df6405bac23f97509a650aafe8d1e8c Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 17 Jun 2024 18:55:21 -0400 Subject: [PATCH 38/63] fix gcc warning --- lib_com/ivas_stereo_td_bit_alloc.c | 9 ++++++--- lib_dec/ivas_core_dec.c | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index d86e0a3d7..78fb93730 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -871,8 +871,12 @@ void td_stereo_param_updt_fx( Word16 tdm_lsfQ_PCh_fx[], /* o : Q LSFs for primary channel Qx2.56*/ Word16 tdm_Pri_pitch_buf_fx[], /* o : pitch values for primary channel Q_var */ const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 tdm_use_IAWB_Ave_lpc, /* i : flag to indicate the usage of mean inactive LP coefficients */ - Word16 Q_var ) + const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Word16 Q_var +#endif +) { Word16 i; /* Copy some primary channel information into the secondary channel structure for later usage */ @@ -894,7 +898,6 @@ void td_stereo_param_updt_fx( Copy( lsf_old_PCh_fx, tdm_lsfQ_PCh_fx, M ); } #ifdef FIX_798_WRONG_CPY_OF_PITCH - Q_var = 0; IF( EQ_16( flag_ACELP16k, 1 ) ) { Word16 tmp16; diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 0bccf0c82..667dd2902 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -538,7 +538,12 @@ ivas_error ivas_core_dec( Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10 ); td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, - tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q6 ); + tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Q6 +#endif + ); Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10 ); } -- GitLab From 05eab919b5820b7c41527928ab6328da3d7d7654 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 17 Jun 2024 19:05:19 -0400 Subject: [PATCH 39/63] fix gcc error --- lib_com/ivas_prot_fx.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index e91e31d23..d093336b6 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -835,8 +835,12 @@ void td_stereo_param_updt_fx( Word16 tdm_lsfQ_PCh[], /* o : Q LSFs for primary channel */ Word16 tdm_Pri_pitch_buf[], /* o : pitch values for primary channel */ const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 tdm_use_IAWB_Ave_lpc, /* i : flag to indicate the usage of mean inactive LP coefficients */ - Word16 Q_var ); + const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Word16 Q_var +#endif +); void updateBuffersForDmxMdctStereo_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */ -- GitLab From 4ab99a122f49adb21ce4ac2fbe8ee7b57b14c2da Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 17 Jun 2024 19:43:54 -0400 Subject: [PATCH 40/63] fix again clang formatting --- lib_com/ivas_prot_fx.h | 18 +++++++++--------- lib_com/ivas_stereo_td_bit_alloc.c | 20 ++++++++++---------- lib_dec/ivas_core_dec.c | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index d093336b6..91be1b984 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -828,17 +828,17 @@ void ivas_lfe_dec_close_fx( void td_stereo_param_updt_fx( - const Word16 lsp_old_PCh[], /* i : primary channel old LSPs */ - const Word16 lsf_old_PCh[], /* i : primary channel old LSFs */ - const Word16 pitch_buf_PCh[], /* i : primary channel pitch buffer */ - Word16 tdm_lspQ_PCh[], /* o : Q LSPs for primary channel */ - Word16 tdm_lsfQ_PCh[], /* o : Q LSFs for primary channel */ - Word16 tdm_Pri_pitch_buf[], /* o : pitch values for primary channel */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ + const Word16 lsp_old_PCh[], /* i : primary channel old LSPs */ + const Word16 lsf_old_PCh[], /* i : primary channel old LSFs */ + const Word16 pitch_buf_PCh[], /* i : primary channel pitch buffer */ + Word16 tdm_lspQ_PCh[], /* o : Q LSPs for primary channel */ + Word16 tdm_lsfQ_PCh[], /* o : Q LSFs for primary channel */ + Word16 tdm_Pri_pitch_buf[], /* o : pitch values for primary channel */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ #ifndef FIX_798_WRONG_CPY_OF_PITCH , - Word16 Q_var + Word16 Q_var #endif ); diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index 78fb93730..2ca004b6e 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -864,17 +864,17 @@ void td_stereo_param_updt( #ifdef IVAS_FLOAT_FIXED void td_stereo_param_updt_fx( - const Word16 lsp_old_PCh_fx[], /* i : primary channel old LSPs Q15*/ - const Word16 lsf_old_PCh_fx[], /* i : primary channel old LSFs Qx2.56*/ - const Word16 pitch_buf_PCh_fx[], /* i : primary channel pitch buffer Q_var*/ - Word16 tdm_lspQ_PCh_fx[], /* o : Q LSPs for primary channel Q15*/ - Word16 tdm_lsfQ_PCh_fx[], /* o : Q LSFs for primary channel Qx2.56*/ - Word16 tdm_Pri_pitch_buf_fx[], /* o : pitch values for primary channel Q_var */ - const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ - const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ + const Word16 lsp_old_PCh_fx[], /* i : primary channel old LSPs Q15*/ + const Word16 lsf_old_PCh_fx[], /* i : primary channel old LSFs Qx2.56*/ + const Word16 pitch_buf_PCh_fx[], /* i : primary channel pitch buffer Q_var*/ + Word16 tdm_lspQ_PCh_fx[], /* o : Q LSPs for primary channel Q15*/ + Word16 tdm_lsfQ_PCh_fx[], /* o : Q LSFs for primary channel Qx2.56*/ + Word16 tdm_Pri_pitch_buf_fx[], /* o : pitch values for primary channel Q_var */ + const Word16 flag_ACELP16k, /* i : ACELP@16kHz flag */ + const Word16 tdm_use_IAWB_Ave_lpc /* i : flag to indicate the usage of mean inactive LP coefficients */ #ifndef FIX_798_WRONG_CPY_OF_PITCH - , - Word16 Q_var + , + Word16 Q_var #endif ) { diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 667dd2902..70b47f009 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -541,7 +541,7 @@ ivas_error ivas_core_dec( tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc #ifndef FIX_798_WRONG_CPY_OF_PITCH , - Q6 + Q6 #endif ); -- GitLab From 093fd8d203753dc15f5ceda0c925f7230fc453e4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 09:24:42 +0530 Subject: [PATCH 41/63] Removal of scale of CLDFB_FILTER_BANK from decoder [x] Removed dependency of "scale" in CLDFB_FILTER_BANK in decoder [x] Removed dependency of q_scale from CLDFB_FILTER_BANK [x] Aligned scale of CLDFB_FILTER_BANK to be in Q8 --- lib_com/cldfb.c | 42 +++++++------------- lib_com/cnst.h | 14 +++++++ lib_com/stat_com.h | 5 +-- lib_dec/fd_cng_dec.c | 6 +-- lib_dec/ivas_cpe_dec_fx.c | 6 --- lib_rend/ivas_dirac_dec_binaural_functions.c | 5 --- 6 files changed, 33 insertions(+), 45 deletions(-) diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index f7c03a8f9..b2022f725 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -2043,8 +2043,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17036; hs->p_filter = CLDFB80_10_fx; - hs->q_scale = norm_s( (Word16) CLDFB80_10_SCALE ); - hs->scale = (Word16) ( CLDFB80_10_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = CLDFB80_10_SCALE_FX_Q8; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2064,8 +2063,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_10_fx; - hs->q_scale = norm_s( (Word16) LDQMF_10_SCALE ); - hs->scale = (Word16) ( LDQMF_10_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = LDQMF_10_SCALE_FX_Q8; #endif } break; @@ -2098,8 +2096,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_16_fx; - hs->q_scale = norm_s( (Word16) CLDFB80_16_SCALE ); - hs->scale = (Word16) ( CLDFB80_16_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = CLDFB80_16_SCALE_FX_Q8; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2119,8 +2116,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_16_fx; - hs->q_scale = norm_s( (Word16) LDQMF_16_SCALE ); - hs->scale = (Word16) ( LDQMF_16_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = LDQMF_16_SCALE_FX_Q8; #endif } break; @@ -2153,8 +2149,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_20_fx; - hs->q_scale = norm_s( (Word16) CLDFB80_20_SCALE ); - hs->scale = (Word16) ( CLDFB80_20_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = CLDFB80_20_SCALE_FX_Q8; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2174,8 +2169,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15390; hs->p_filter = LDQMF_20_fx; - hs->q_scale = norm_s( (Word16) LDQMF_20_SCALE ); - hs->scale = (Word16) ( LDQMF_20_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = LDQMF_20_SCALE_FX_Q8; #endif } break; @@ -2208,8 +2202,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_30_fx; - hs->q_scale = norm_s( (Word16) CLDFB80_30_SCALE ); - hs->scale = (Word16) ( CLDFB80_30_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = CLDFB80_30_SCALE_FX_Q8; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2229,8 +2222,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15388; hs->p_filter = LDQMF_30_fx; - hs->q_scale = norm_s( (Word16) LDQMF_30_SCALE ); - hs->scale = (Word16) ( LDQMF_30_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = LDQMF_30_SCALE_FX_Q8; #endif } break; @@ -2263,8 +2255,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17050; hs->p_filter = CLDFB80_32_fx; - hs->q_scale = norm_s( (Word16) CLDFB80_32_SCALE ); - hs->scale = (Word16) ( CLDFB80_32_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = CLDFB80_32_SCALE_FX_Q8; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2284,8 +2275,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15392; hs->p_filter = LDQMF_32_fx; - hs->q_scale = norm_s( (Word16) LDQMF_32_SCALE ); - hs->scale = (Word16) ( LDQMF_32_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = LDQMF_32_SCALE_FX_Q8; #endif } break; @@ -2318,8 +2308,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_re_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_40_fx; - hs->q_scale = norm_s( (Word16) CLDFB80_40_SCALE ); - hs->scale = (Word16) ( CLDFB80_40_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = CLDFB80_40_SCALE_FX_Q8; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2339,8 +2328,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_40_fx; - hs->q_scale = norm_s( (Word16) LDQMF_40_SCALE ); - hs->scale = (Word16) ( LDQMF_40_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = LDQMF_40_SCALE_FX_Q8; #endif } break; @@ -2373,8 +2361,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = NULL; hs->p_filter_sf = (Word16) 17051; hs->p_filter = CLDFB80_60_fx; - hs->q_scale = norm_s( (Word16) CLDFB80_60_SCALE ); - hs->scale = (Word16) ( CLDFB80_60_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = CLDFB80_60_SCALE_FX_Q8; #endif } else if ( hs->prototype == CLDFB_PROTOTYPE_5_00MS ) @@ -2394,8 +2381,7 @@ static void cldfb_init_proto_and_twiddles( hs->rot_vec_syn_delay_im_fx = rot_vec_delay_im_LDQMF_fx; hs->p_filter_sf = (Word16) 15391; hs->p_filter = LDQMF_60_fx; - hs->q_scale = norm_s( (Word16) LDQMF_60_SCALE ); - hs->scale = (Word16) ( LDQMF_60_SCALE * ( 1 << hs->q_scale ) ); + hs->scale = LDQMF_60_SCALE_FX_Q8; #endif } break; diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 8b0f44383..890f1b017 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -794,6 +794,13 @@ typedef enum #define CLDFB80_32_SCALE 88.303848f #define CLDFB80_40_SCALE 88.304726f #define CLDFB80_60_SCALE 88.028412f +#define CLDFB80_10_SCALE_FX_Q8 ( 22603 ) +#define CLDFB80_16_SCALE_FX_Q8 ( 22605 ) +#define CLDFB80_20_SCALE_FX_Q8 ( 22605 ) +#define CLDFB80_30_SCALE_FX_Q8 ( 22588 ) +#define CLDFB80_32_SCALE_FX_Q8 ( 22606 ) +#define CLDFB80_40_SCALE_FX_Q8 ( 22606 ) +#define CLDFB80_60_SCALE_FX_Q8 ( 22535 ) #define LDQMF_10_SCALE 84.567841f #define LDQMF_16_SCALE 84.567932f @@ -802,6 +809,13 @@ typedef enum #define LDQMF_32_SCALE 84.568001f #define LDQMF_40_SCALE 84.567986f #define LDQMF_60_SCALE 84.303284f +#define LDQMF_10_SCALE_FX_Q8 ( 21649 ) +#define LDQMF_16_SCALE_FX_Q8 ( 21649 ) +#define LDQMF_20_SCALE_FX_Q8 ( 21649 ) +#define LDQMF_30_SCALE_FX_Q8 ( 21632 ) +#define LDQMF_32_SCALE_FX_Q8 ( 21649 ) +#define LDQMF_40_SCALE_FX_Q8 ( 21649 ) +#define LDQMF_60_SCALE_FX_Q8 ( 21582 ) #define L_FFT 256 /* Spectral analysis - length of the FFT */ #define LOG2_L_FFT 8 /* Spectral analysis - log2 of L_FFT */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index 4b07886f7..05fd4b643 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -780,9 +780,8 @@ typedef struct cldfb_filter_bank_struct int16_t nab; /* number of active bands */ Word16 filtermode; - float scale_flt; /* scaling of frequency domain */ - Word16 scale; - Word16 q_scale; + float scale_flt; /* scaling of frequency domain */ + Word16 scale; /* scaling of frequency domain */ /* Q8 */ } CLDFB_FILTER_BANK, *HANDLE_CLDFB_FILTER_BANK; diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 7ad0bd0a0..5ee55a3a7 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -3029,8 +3029,8 @@ void generate_masking_noise_dirac_ivas_fx( q_shift = norm_l( scale_fx ); scale_fx = L_shl( scale_fx, q_shift ); q_scale = add( q_scale, q_shift ); - scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2q -34 - q_scale = sub( add( q_scale, i_mult( 2, h_cldfb->q_scale ) ), 34 ); + scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2 * Q8 -34 + q_scale = sub( add( q_scale, 2 * Q8 ), 31 ); ptr_level_fx = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; q_ptr_level = 31 - hFdCngCom->cngNoiseLevelExp; move16(); @@ -3043,7 +3043,7 @@ void generate_masking_noise_dirac_ivas_fx( scale_fx = L_shl( scale_fx, q_shift ); q_scale = add( q_scale, q_shift ); num = Mpy_32_32( scale_fx, *ptr_level_fx ); - q_num = sub( add( q_scale, q_ptr_level ), 30 ); + q_num = sub( add( q_scale, q_ptr_level ), 31 ); exp = sub( 31, q_num ); num = Sqrt32( num, &exp ); /* Real part in CLDFB band */ diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index a7d4daaae..713bf6841 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -141,12 +141,6 @@ ivas_error ivas_cpe_dec_fx( hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = q_old_out_LB; } } - // q_tcxltp_mem_in_float = 11; - FOR( Word16 ind2 = 0; ind2 < 2; ind2++ ) - { - IF( hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->cldfbSyn ) - hCPE->hCoreCoder[ind2]->cldfbSyn->scale = (Word16) ( hCPE->hCoreCoder[ind2]->cldfbSyn->scale_flt * ( 1u << norm_s( (Word16) hCPE->hCoreCoder[0]->cldfbSyn->scale_flt ) ) ); - } #endif // Float to fix conversions IF( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index c429f551e..1e7c7dedf 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -1234,11 +1234,6 @@ static void ivas_dirac_dec_binaural_internal_fx( } nchan_tc = add( nchan_tc, ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); #endif - - st_ivas->cldfbAnaDec[1]->q_scale = 15; - IF( abs_s( (Word16) st_ivas->cldfbAnaDec[1]->scale_flt ) != 0 ) - st_ivas->cldfbAnaDec[1]->q_scale = norm_s( (Word16) st_ivas->cldfbAnaDec[1]->scale_flt ); - st_ivas->cldfbAnaDec[1]->scale = (Word16) ( st_ivas->cldfbAnaDec[1]->scale_flt * ( 1 << st_ivas->cldfbAnaDec[1]->q_scale ) ); IF( st_ivas->hSCE[0] ) { Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ); -- GitLab From 6c64bda3c2617efdf9a4146d50602e3a56c85ac0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 09:30:50 +0530 Subject: [PATCH 42/63] Fix for issue 788: Distortion between 10k to 20k in fixed point OSBA Mono output --- lib_dec/ivas_stereo_mdct_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index edf392ec4..37f8c7983 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -274,7 +274,7 @@ void stereo_mdct_core_dec_fx( FOR( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; - IF( !EQ_16( bfi, 0 ) || ( NE_16( bfi, 0 ) && NE_16( st->core, ACELP_CORE ) ) ) + IF( !bfi || ( bfi && NE_16( st->core, ACELP_CORE ) ) ) { FOR( k = 0; k < nSubframes[ch]; k++ ) { -- GitLab From b816371c26439acfb539b4ecd541d392e4751b6c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 10:57:06 +0530 Subject: [PATCH 43/63] Float code cleanup, BASOP addition and instrumentation [x] hoa_encoder float cleanup and hoa_encoder_fx made as Q31 [x] BASOP and instrumentation code added --- lib_com/ivas_prot.h | 20 +- lib_com/ivas_spar_com.c | 277 +------ lib_dec/ACcontextMapping_dec_fx.c | 79 +- lib_dec/TonalComponentDetection.c | 6 +- lib_dec/TonalComponentDetection_fx.c | 35 +- lib_dec/acelp_core_dec_ivas_fx.c | 789 ++++++++++++------- lib_dec/dec_tcx.c | 25 - lib_dec/igf_dec.c | 18 - lib_dec/ivas_binRenderer_internal.c | 2 +- lib_dec/ivas_init_dec.c | 4 +- lib_dec/ivas_ism_param_dec.c | 2 +- lib_dec/ivas_ism_renderer.c | 2 +- lib_dec/ivas_jbm_dec.c | 11 - lib_dec/ivas_mc_param_dec.c | 16 - lib_dec/ivas_mc_paramupmix_dec.c | 1 - lib_dec/ivas_mct_dec.c | 12 +- lib_dec/ivas_sba_rendering_internal.c | 5 +- lib_dec/ivas_stat_dec.h | 8 +- lib_dec/lib_dec_fx.c | 6 - lib_dec/tns_base_dec.c | 3 +- lib_dec/tonalMDCTconcealment.c | 40 +- lib_dec/tonalMDCTconcealment_fx.c | 220 ++++-- lib_dec/transition_dec.c | 3 +- lib_dec/transition_dec_fx.c | 32 +- lib_dec/updt_dec_fx.c | 145 ++-- lib_dec/vlpc_1st_dec.c | 3 +- lib_dec/vlpc_2st_dec.c | 3 +- lib_dec/vlpc_2st_dec_fx.c | 4 + lib_dec/voiced_dec_fx.c | 40 +- lib_dec/waveadjust_fec_dec.c | 18 +- lib_dec/waveadjust_fec_dec_fx.c | 59 +- lib_rend/ivas_allrad_dec.c | 4 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 9 +- lib_rend/ivas_dirac_output_synthesis_dec.c | 14 +- lib_rend/ivas_dirac_rend.c | 6 +- lib_rend/ivas_stat_rend.h | 2 +- lib_rend/lib_rend.c | 24 +- 37 files changed, 1040 insertions(+), 907 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 1aab20d0e..65770f002 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -384,12 +384,12 @@ ivas_error create_cpe_dec( ivas_error create_mct_dec_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); -#endif // IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED ivas_error create_mct_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ); - +#endif ivas_error mct_dec_reconfigure( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const uint16_t b_nchan_change /* i : flag indicating different channel count */ @@ -4553,24 +4553,12 @@ void ivas_dirac_dec_get_response( const int16_t ambisonics_order ); #ifdef IVAS_FLOAT_FIXED -void ivas_dirac_dec_get_response_fixed( - const Word16 azimuth, - const Word16 elevation, - Word32 *response, - const Word16 ambisonics_order ); - -void ivas_dirac_dec_get_response_fixed_Q( - const Word16 azimuth, - const Word16 elevation, - Word32 *response, - const Word16 ambisonics_order, - Word16 Q); - void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, Word32 * response, - const Word16 ambisonics_order); + const Word16 ambisonics_order, + Word16 Q_out); #endif void calculate_hodirac_sector_parameters( diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index f37d9ce7d..aa762741c 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -3284,7 +3284,7 @@ void ivas_get_spar_md_from_dirac_fx( if ( n_ts > 1 ) { // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][i_ts], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][i_ts], Q22 ), response_avg_fx, order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][i_ts], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][i_ts], Q22 ), response_avg_fx, order, Q30 ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); @@ -3293,7 +3293,7 @@ void ivas_get_spar_md_from_dirac_fx( else if ( useLowerRes ) { // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][0], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][0], Q22 ), response_avg_fx, order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][0], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][0], Q22 ), response_avg_fx, order, Q30 ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); @@ -3304,7 +3304,7 @@ void ivas_get_spar_md_from_dirac_fx( for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][block], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][block], Q22 ), &( response_fx[block][0] ), order ); + ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][block], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][block], Q22 ), &( response_fx[block][0] ), order, Q30 ); /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { response[block][l] = (float) response_fx[block][l] / ( 1 << 30 ); @@ -4060,128 +4060,13 @@ void ivas_dirac_dec_get_response( #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- - * ivas_dirac_dec_get_response_fixed() + * ivas_dirac_dec_get_response_fx() * * Block Q of 29 is maintained * calculate reponse, 1 degree resolution * Input azimuth and elevation are expected in Q0 *------------------------------------------------------------------------*/ -void ivas_dirac_dec_get_response_fixed( - const Word16 azimuth, - const Word16 elevation, - Word32 *response, - const Word16 ambisonics_order ) -{ - Word16 index_azimuth, index_elevation; - Word16 el, e, az; - Word32 cos_1, cos_2, sin_1, cos_az[3]; - Word32 sin_az[3]; - Word32 f, c; - Word16 l, m; - Word16 b, b1, b_2, b1_2, a; - - index_azimuth = ( azimuth + 180 ) % 360; - index_elevation = elevation + 90; - e = index_elevation > 90 ? -1 : 1; - el = index_elevation > 90 ? 180 - index_elevation : index_elevation; - - az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth; - f = index_azimuth > 180 ? -( 1 << Q29 ) : ( 1 << Q29 ); - - cos_1 = dirac_gains_trg_term_int[az][0] >> 1; // Q29 - cos_2 = Mpy_32_32( cos_1, cos_1 ); // Q27 - sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] >> 1 ); // Q27 - cos_az[0] = cos_1; // Q29 - cos_az[1] = L_sub( Mpy_32_32( ( 1 << Q30 ), cos_2 ), ( 1 << Q25 ) ) << 4; // Q29 - cos_az[2] = L_sub( Mpy_32_32( Mpy_32_32( ( 1 << Q30 ), cos_1 ), cos_az[1] ) << 4, cos_az[0] ); // Q29 - sin_az[0] = sin_1 << 2; // Q29 - sin_az[1] = Mpy_32_32( Mpy_32_32( sin_1, ( 1 << Q30 ) ), cos_1 ) << 6; // Q29 - sin_az[2] = Mpy_32_32( sin_1, L_sub( L_shl_sat( Mpy_32_32( ( 1 << Q30 ), cos_2 ), 5 ), ( 1 << 29 ) ) ) << 4; - - response[0] = ( 1 << 29 ); - /* Un-optimized code - for reference */ - /* for( l = 1; l<= ambisonics_order; l++ ) */ - /* { */ - /* int16_t b, b1, a; */ - /* float c; */ - /* for( m = 0; m < l; m++ ) */ - /* { */ - /* b = l*l+m; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - - /* if( m%2 == 1 ) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c * sin_az[l-m-1]; */ - - /* b1 = l*l+2*l-m; */ - /* response[b1] = c * cos_az[l-m-1]; */ - - /* } */ - - /* b = l*l+l; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - /* if( l%2 == 1) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c; */ - /* } */ - - FOR( l = 1; l <= ambisonics_order; l++ ) - { - b_2 = l * l; - b1_2 = l * l + 2 * l; - FOR( m = 0; m < l; m += 2 ) - { - b = b_2 + m; - a = dirac_gains_P_idx[b]; - c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 - - response[b] = Mpy_32_32( c, sin_az[l - m - 1] ) << 6; // Q29 - - b1 = b1_2 - m; - response[b1] = Mpy_32_32( c, cos_az[l - m - 1] ) << 6; // Q29 - } - - FOR( m = 1; m < l; m += 2 ) - { - b = b_2 + m; - a = dirac_gains_P_idx[b]; - c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 - IF( e == -1 ) - { - c = -c; - } - - response[b] = Mpy_32_32( c, sin_az[l - m - 1] ) << 6; // Q29 - - b1 = b1_2 - m; - response[b1] = Mpy_32_32( c, cos_az[l - m - 1] ) << 6; // Q29 - } - - b = b_2 + l; - a = dirac_gains_P_idx[b]; - c = Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ); // Q26 - IF( l % 2 == 1 ) - { - IF( e == -1 ) - { - c = -c; - } - } - - response[b] = c << 3; // Q29 - } - - return; -} Word32 local_result_table[91][9] = { { -1518500224, @@ -6193,7 +6078,8 @@ void ivas_dirac_dec_get_response_fx( const Word16 azimuth, const Word16 elevation, Word32 *response_fx, - const Word16 ambisonics_order ) + const Word16 ambisonics_order, + Word16 Q_out ) { // float response[MAX_OUTPUT_CHANNELS]; int16_t index_azimuth, index_elevation; @@ -6203,7 +6089,7 @@ void ivas_dirac_dec_get_response_fx( // float sin_az[3]; Word32 sin_az_fx[3]; // float f, c; - Word32 f_fx, c_fx; + Word32 f_fx; Word32 c_fx_better; int16_t l, m; int16_t b, b1, b_2, b1_2, a; @@ -6239,7 +6125,7 @@ void ivas_dirac_dec_get_response_fx( sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, ( cos_2_fx - ONE_IN_Q29 ) ), 2 ); // response[0] = 1.0f; - response_fx[0] = ONE_IN_Q30; + response_fx[0] = L_shl_sat( 1, Q_out ); /* Un-optimized code - for reference */ /* for( l = 1; l<= ambisonics_order; l++ ) */ /* { */ @@ -6283,16 +6169,16 @@ void ivas_dirac_dec_get_response_fx( b = b_2 + m; a = dirac_gains_P_idx[b]; // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); + // c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); c_fx_better = local_result_table[el][a]; // response[b] = c * sin_az[l - m - 1]; - response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); - response_fx[b] = Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ); + // response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out b1 = b1_2 - m; // response[b1] = c * cos_az[l - m - 1]; - response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); - response_fx[b1] = Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ); + // response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out } for ( m = 1; m < l; m += 2 ) @@ -6300,159 +6186,42 @@ void ivas_dirac_dec_get_response_fx( b = b_2 + m; a = dirac_gains_P_idx[b]; // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); + // c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); c_fx_better = local_result_table[el][a]; if ( e == -1 ) { - c_fx = L_negate( c_fx ); + // c_fx = L_negate( c_fx ); c_fx_better = L_negate( c_fx_better ); } // c = c * e; // response[b] = c * sin_az[l - m - 1]; - response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); - response_fx[b] = Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ); + // response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out b1 = b1_2 - m; // response[b1] = c * cos_az[l - m - 1]; - response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); - response_fx[b1] = Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ); + // response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out } b = b_2 + l; a = dirac_gains_P_idx[b]; // c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - c_fx = Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ); + // c_fx = Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ); c_fx_better = local_result_table_2[el][a]; if ( l % 2 == 1 ) { // c = c * e; if ( e == -1 ) { - c_fx = L_negate( c_fx ); + // c_fx = L_negate( c_fx ); c_fx_better = L_negate( c_fx_better ); } } // response[b] = c; - response_fx[b] = L_shl( c_fx, 2 ); - response_fx[b] = c_fx_better; - } - - return; -} - -void ivas_dirac_dec_get_response_fixed_Q( - const Word16 azimuth, - const Word16 elevation, - Word32 *response, - const Word16 ambisonics_order, - Word16 Q_out ) -{ - Word16 index_azimuth, index_elevation; - Word16 el, e, az; - Word32 cos_1, cos_2, sin_1, cos_az[3]; - Word32 sin_az[3]; - Word32 f, c; - Word16 l, m; - Word16 b, b1, b_2, b1_2, a; - - index_azimuth = ( azimuth + 180 ) % 360; - index_elevation = elevation + 90; - e = index_elevation > 90 ? -1 : 1; - el = index_elevation > 90 ? 180 - index_elevation : index_elevation; - - az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth; - f = index_azimuth > 180 ? -( 1 << Q29 ) : ( 1 << Q29 ); - - cos_1 = dirac_gains_trg_term_int[az][0] >> 1; // Q29 - cos_2 = Mpy_32_32( cos_1, cos_1 ); // Q27 - sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] >> 1 ); // Q27 - cos_az[0] = cos_1; // Q29 - cos_az[1] = L_sub( Mpy_32_32( ( 1 << Q30 ), cos_2 ), ( 1 << Q25 ) ) << 4; // Q29 - cos_az[2] = L_sub( Mpy_32_32( Mpy_32_32( ( 1 << Q30 ), cos_1 ), cos_az[1] ) << 4, cos_az[0] ); // Q29 - sin_az[0] = sin_1 << 2; // Q29 - sin_az[1] = Mpy_32_32( Mpy_32_32( sin_1, ( 1 << Q30 ) ), cos_1 ) << 6; // Q29 - sin_az[2] = Mpy_32_32( sin_1, L_sub( L_shl_sat( Mpy_32_32( ( 1 << Q30 ), cos_2 ), 5 ), ( 1 << 29 ) ) ) << 4; - - response[0] = L_shl( 1, Q_out ); - /* Un-optimized code - for reference */ - /* for( l = 1; l<= ambisonics_order; l++ ) */ - /* { */ - /* int16_t b, b1, a; */ - /* float c; */ - /* for( m = 0; m < l; m++ ) */ - /* { */ - /* b = l*l+m; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - - /* if( m%2 == 1 ) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c * sin_az[l-m-1]; */ - - /* b1 = l*l+2*l-m; */ - /* response[b1] = c * cos_az[l-m-1]; */ - - /* } */ - - /* b = l*l+l; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - /* if( l%2 == 1) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c; */ - /* } */ - - FOR( l = 1; l <= ambisonics_order; l++ ) - { - b_2 = l * l; - b1_2 = l * l + 2 * l; - FOR( m = 0; m < l; m += 2 ) - { - b = b_2 + m; - a = dirac_gains_P_idx[b]; - c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 - - response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), Q_out - Q23 ); // Q_out - - b1 = b1_2 - m; - response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), Q_out - Q23 ); // Q_out - } - - FOR( m = 1; m < l; m += 2 ) - { - b = b_2 + m; - a = dirac_gains_P_idx[b]; - c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 - IF( e == -1 ) - { - c = -c; - } - - response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), Q_out - Q23 ); // Q29 - - b1 = b1_2 - m; - response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), Q_out - Q23 ); // Q29 - } - - b = b_2 + l; - a = dirac_gains_P_idx[b]; - c = Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ); // Q26 - IF( l % 2 == 1 ) - { - IF( e == -1 ) - { - c = -c; - } - } - - response[b] = L_shl( c, Q_out - Q26 ); // Q29 + // response_fx[b] = L_shl( c_fx, 2 ); + response_fx[b] = L_shl_sat( c_fx_better, sub( Q_out, 30 ) ); // Q_out } return; diff --git a/lib_dec/ACcontextMapping_dec_fx.c b/lib_dec/ACcontextMapping_dec_fx.c index f2ec7d573..01298f6dd 100644 --- a/lib_dec/ACcontextMapping_dec_fx.c +++ b/lib_dec/ACcontextMapping_dec_fx.c @@ -371,9 +371,11 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( start_bit_pos = st->next_bit_pos; lsbs_bit_pos = add( start_bit_pos, sub( nbbits, 1 ) ); n = 0; + move16(); k = 1; + move16(); nt_half = shr( nt, 1 ); - + move16(); WHILE( LT_16( k, nt_half ) ) { n = add( n, 1 ); @@ -381,16 +383,17 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( } bits_tups = n; - - n = get_next_indice_fx( st, n ) + 1; + move16(); + n = add( get_next_indice_fx( st, n ), 1 ); t = 0; - + move16(); lastnz = shl( n, 1 ); - IF( GT_16( lastnz, nt ) ) + if ( GT_16( lastnz, nt ) ) { st->BER_detect = 1; + move16(); return 0; } @@ -411,13 +414,16 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( ELSE { rateFlag = 0; + move16(); } /* Init */ c[0] = c[1] = 0; - + move16(); + move16(); /* mapped domain */ numPeakIndicesOrig = hm_cfg->numPeakIndices; + move16(); hm_cfg->numPeakIndices = s_min( hm_cfg->numPeakIndices, lastnz ); numHoleIndices = sub( lastnz, hm_cfg->numPeakIndices ); @@ -425,18 +431,22 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( FOR( k = numHoleIndices; k < hm_cfg->numHoleIndices; ++k ) { hm_cfg->holeIndices[k] = add( hm_cfg->holeIndices[k], nt ); + move16(); } ii[0] = numPeakIndicesOrig; + move16(); ii[1] = 0; - + move16(); p1 = p2 = 0; /* to avoid compilation warnings */ - + move16(); + move16(); /* Start Decoding */ /* Initialize range decoder */ rc_uni_dec_init_fx( &rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits ); /* (nbbits + 30) entries are read by the decoder */ nbbits_m2 = nbbits; + move16(); rest_bits = negate( nbbits_m2 ); /* Main Loop through the 2-tuples */ @@ -448,25 +458,27 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Get context */ ctx = &c[s_or( p1, p2 )]; - t = add( *ctx, rateFlag ); IF( LT_16( nt_half, idx ) ) { - t = add( t, 1 << NBITS_CONTEXT ); + t = add( t, shl( 1, NBITS_CONTEXT ) ); } esc_nb = 0; + move16(); r = 0; - + move16(); + test(); /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/ - IF( ( GE_16( t, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ) ) || lsbs_bit_pos <= 0 ) + IF( ( GE_16( t, ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ) ) ) || ( lsbs_bit_pos <= 0 ) ) { st->BER_detect = 1; return 0; } a = b = 0; - + move16(); + move16(); /* MSBs decoding */ FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev ) { @@ -484,12 +496,16 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( a = add( a, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) ); b = add( b, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) ); } - + test(); + test(); IF( ( LT_16( lsbs_bit_pos, -1 ) && GE_16( r, VAL_ESC ) ) || GT_16( lev, 14 ) ) { x[a1_i] = 0; + move16(); x[b1_i] = 0; + move16(); st->BER_detect = 1; + move16(); return 0; } @@ -515,15 +531,16 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Store decoded data */ x[a1_i] = a; + move16(); x[b1_i] = b; - + move16(); /* Update context for next 2-tuple */ IF( EQ_32( p1, p2 ) ) { /* peak-peak or hole-hole context */ lev = sub( esc_nb, 1 ); - IF( LE_16( lev, 0 ) ) + IF( lev <= 0 ) { t = add( 1, imult1616( add( a1, b1 ), add( lev, 2 ) ) ); } @@ -542,12 +559,14 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( { /* update first context */ c[p1] = update_mixed_context( c[p1], a ); + move16(); } IF( idx2 & 1 ) { /* update second context */ c[p2] = update_mixed_context( c[p2], b ); + move16(); } } } @@ -565,6 +584,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Decode signs */ n = nt; + move16(); } ELSE /* if(!hm_cfg) */ { @@ -575,10 +595,12 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( IF( GT_16( nbbits, 400 ) ) { rateFlag = 2; + move16(); } ELSE { rateFlag = 0; + move16(); } /* Start Decoding */ @@ -586,27 +608,32 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( rc_uni_dec_init_fx( &rc_st_dec, &st->bit_stream[st->next_bit_pos], nbbits ); /* (nbbits + 30) entries are read by the decoder */ nbbits_m2 = nbbits; + move16(); rest_bits = negate( nbbits_m2 ); t = 0; + move16(); s = 0; - + move16(); /* Main Loop through the 2-tuples */ FOR( k = 0; k < lastnz; k += 2 ) { rateQ = add( rateFlag, (Word16) GT_16( k, ( nt_half ) ) ); - + test(); /* BER detection: Check max value of context t leading to out-of-bound access to ari_lookup_s17_LC[]*/ - IF( ( GE_16( t, ( 1 << ( NBITS_CONTEXT ) ) ) ) || lsbs_bit_pos <= 0 ) + IF( ( GE_16( t, ( 1 << ( NBITS_CONTEXT ) ) ) ) || ( lsbs_bit_pos <= 0 ) ) { st->BER_detect = 1; + move16(); return 0; } a = b = 0; + move16(); esc_nb = 0; + move16(); r = 0; - + move16(); /* MSBs decoding */ FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev ) { @@ -624,12 +651,16 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( a = add( a, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) ); b = add( b, shl( get_indice_1_fx( st, lsbs_bit_pos-- ), lev ) ); } - + test(); + test(); IF( ( LT_16( lsbs_bit_pos, -1 ) && GE_16( r, VAL_ESC ) ) || GT_16( lev, 14 ) ) { x[k + 0] = 0; + move16(); x[k + 1] = 0; + move16(); st->BER_detect = 1; + move16(); return 0; } @@ -655,8 +686,9 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Store decoded data */ x[k + 0] = a; + move16(); x[k + 1] = b; - + move16(); /* Update context for next 2-tuple */ IF( LT_16( esc_nb, 2 ) ) { @@ -674,6 +706,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( /* Decode signs */ n = lastnz; + move16(); } /* end of if(hm_cfg) */ FOR( k = 0; k < n; k++ ) @@ -681,6 +714,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( IF( x[k] > 0 ) { x[k] = imult1616( x[k], sub( 1, shl( get_next_indice_1_fx( st ), 1 ) ) ); + move16(); } } @@ -690,6 +724,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx( FOR( k = 0; k < resQBits; ++k ) { x[nt + k] = get_indice_1_fx( st, sub( lsbs_bit_pos, k ) ); + move16(); } /* Set bitstream pointer to end of buffer */ diff --git a/lib_dec/TonalComponentDetection.c b/lib_dec/TonalComponentDetection.c index 76ee5e179..66333630f 100644 --- a/lib_dec/TonalComponentDetection.c +++ b/lib_dec/TonalComponentDetection.c @@ -45,11 +45,8 @@ #include "stat_com.h" #include "wmc_auto.h" #include "ivas_prot.h" -#ifdef IVAS_FLOAT_FIXED -#include "ivas_prot_fx.h" -#endif // IVAS_FLOAT_FIXED - +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ @@ -889,3 +886,4 @@ static void findTonalComponents( return; } +#endif \ No newline at end of file diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 55a262318..4a576bfe0 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -64,24 +64,29 @@ void ivas_DetectTonalComponents_fx( { Word16 F0; Word16 thresholdModification[L_FRAME_MAX], lastMDCTSpect_exp; - Word32 pScaledMdctSpectrum[L_FRAME_MAX] = { 0 }; + Word32 pScaledMdctSpectrum[L_FRAME_MAX]; Word16 nBands; Word32 sns_int_scf_fx[FDNS_NPTS]; Word16 q_pScaledMdctSpectrum; + set32_fx( pScaledMdctSpectrum, 0, L_FRAME_MAX ); + FOR( Word16 i = 0; i < nSamples; i++ ) { pScaledMdctSpectrum[i] = L_shl( lastMDCTSpectrum[i], 16 ); // Q31 - lastMDCTSpectrum_exp + move32(); } #ifdef MSAN_FIX FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { - sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], 1 + scaleFactors_exp[i] ); // Q16 + sns_int_scf_fx[i] = L_shl_sat( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 + move32(); } #endif IF( psychParamsCurrent == NULL ) { nBands = FDNS_NPTS; + move16(); // PMT("add nBands argument to mdct_shaping_16") mdct_shaping_16( lastMDCTSpectrum, nSamplesCore, nSamples, scaleFactors, scaleFactors_exp, scaleFactors_max_e, pScaledMdctSpectrum ); @@ -92,23 +97,25 @@ void ivas_DetectTonalComponents_fx( #ifndef MSAN_FIX FOR( Word16 i = 0; i < FDNS_NPTS; i++ ) { - sns_int_scf_fx[i] = L_shl( scaleFactors[i], 1 + scaleFactors_exp[i] ); // Q16 + sns_int_scf_fx[i] = L_shl( scaleFactors[i], add( 1, scaleFactors_exp[i] ) ); // Q16 } #endif - q_pScaledMdctSpectrum = 31 - lastMDCTSpectrum_exp; + q_pScaledMdctSpectrum = sub( 31, lastMDCTSpectrum_exp ); sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore ); - q_pScaledMdctSpectrum = q_pScaledMdctSpectrum + 1; - Word16 tmp_e = 31 - q_pScaledMdctSpectrum; + q_pScaledMdctSpectrum = add( q_pScaledMdctSpectrum, 1 ); + Word16 tmp_e = sub( 31, q_pScaledMdctSpectrum ); nBands = psychParamsCurrent->nBands; + move16(); // till nSamplesCore different Q and nSamples - nSamplesCore in different Q - Scale_sig32( pScaledMdctSpectrum + nSamplesCore, nSamples - nSamplesCore, lastMDCTSpectrum_exp - tmp_e ); - lastMDCTSpect_exp = 31 - q_pScaledMdctSpectrum; + Scale_sig32( pScaledMdctSpectrum + nSamplesCore, sub( nSamples, nSamplesCore ), sub( lastMDCTSpectrum_exp, tmp_e ) ); + lastMDCTSpect_exp = sub( 31, q_pScaledMdctSpectrum ); } - for ( int i = nSamplesCore; i < nSamples; ++i ) + FOR( Word16 i = nSamplesCore; i < nSamples; ++i ) { Word64 tmp = W_mult_32_32( pScaledMdctSpectrum[i], sns_int_scf_fx[nBands - 1] ); // q_pScaledMdctSpectrum + 16 + 1 pScaledMdctSpectrum[i] = W_extract_h( W_shl( tmp, Q15 ) ); // q_pScaledMdctSpectrum + move32(); } /* Find peak candidates in the last frame. */ @@ -390,6 +397,7 @@ static void getEnvelope( sum = L_deposit_l( 0 ); level = 31089 /*LEVEL_ABOVE_ENVELOPE Q12*/; /*Q12*/ + move16(); FOR( i = 0; i < n2; i++ ) { @@ -424,13 +432,14 @@ static void getEnvelope( { sum = L_sub( sum, powerSpec[i - n1] ); tmp = Mpy_32_16_1( sum, level ); - envelope[i] = Mpy_32_16_1( tmp, InvIntTable[nSamples - ( i - nHalfFilterLength )] ); + envelope[i] = Mpy_32_16_1( tmp, InvIntTable[sub( nSamples, sub( i, nHalfFilterLength ) )] ); move32(); } FOR( i = 1; i < nSamples - 1; i++ ) { smoothedSpectrum[i] = L_add( L_add( Mpy_32_16_1( powerSpec[i - 1], 3072 /*0.75f Q12*/ ), L_shr( powerSpec[i], LEVEL_EXP ) ), Mpy_32_16_1( powerSpec[i + 1], 3072 /*0.75f Q12*/ ) ); + move32(); } move32(); @@ -663,7 +672,7 @@ static void CorrectF0( ELSE { test(); - IF( EQ_16( nSameDiff, nMostCommonDiff ) && ( abs_s( sub( iMostCommonDiff, pHarmonicIndexes[0] ) ) > abs_s( sub( sortedDiff[i - 1], pHarmonicIndexes[0] ) ) ) ) + IF( EQ_16( nSameDiff, nMostCommonDiff ) && GT_16( abs_s( sub( iMostCommonDiff, pHarmonicIndexes[0] ) ), abs_s( sub( sortedDiff[i - 1], pHarmonicIndexes[0] ) ) ) ) { nMostCommonDiff = nSameDiff; move16(); @@ -718,6 +727,7 @@ static void CorrectF0( ELSE { F0 = 0; + move16(); } } /* Otherwise if there are at least 3 distances between peaks with length 1 and if the 1st harmonic is in pHarmonicIndexes then keep the original F0 */ @@ -1040,6 +1050,9 @@ static void findTonalComponents( } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ + test(); + test(); + test(); IF( ( EQ_16( element_mode, EVS_MONO ) && GT_32( Mpy_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), Mpy_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) || ( NE_16( element_mode, EVS_MONO ) && ( GT_64( W_mult_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), W_mult_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) ) ) { diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 89559d6c2..3679bde98 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -103,18 +103,18 @@ ivas_error acelp_core_dec_ivas_fx( Word16 old_bwe_exc_fx[( ( PIT16k_MAX + ( L_FRAME16k + 1 ) + L_SUBFR16k ) * 2 )]; /* excitation buffer */ #endif Word16 *bwe_exc_fx; /* Excitation for SWB TBE */ - int16_t i, j, int_fs; - int16_t tc_subfr; - int16_t allow_cn_step; + Word16 i, j, int_fs; + Word16 tc_subfr; + Word16 allow_cn_step; Word16 temp_buf_fx[L_FRAME16k + L_SYN_MEM]; - int16_t last_pulse_pos; - int16_t T0_tmp; - int16_t do_WI; + Word16 last_pulse_pos; + Word16 T0_tmp; + Word16 do_WI; Word16 dct_buffer_fx[DCT_L_POST]; Word16 exc_buffer_fx[DCT_L_POST]; Word16 dct_exc_tmp_fx[L_FRAME16k]; - int16_t nb_bits; /* number of bits */ - int16_t indice; /* parameter indices to write */ + Word16 nb_bits; /* number of bits */ + Word16 indice; /* parameter indices to write */ Word16 gain_buf_fx[NB_SUBFR16k]; Word16 syn_fx_tmp2[L_FRAME_16k]; Word16 pitch_buf_tmp[NB_SUBFR16k]; @@ -125,14 +125,16 @@ ivas_error acelp_core_dec_ivas_fx( Word32 *realBuffer_fx[CLDFB_NO_COL_MAX], *imagBuffer_fx[CLDFB_NO_COL_MAX]; Word32 realBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 imagBufferTmp_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; - int16_t LSF_Q_prediction; /* LSF prediction mode */ + Word16 LSF_Q_prediction; /* LSF prediction mode */ Word16 avoid_lpc_burst_on_recovery; Word16 tmpF_fx; - int16_t uc_two_stage_flag; - int16_t tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; + Word16 uc_two_stage_flag; + Word16 tdm_lp_reuse_flag, tdm_low_rate_mode, tdm_Pitch_reuse_flag; Word16 *old_exc_s_fx; /* Start of last excitation frame */ Word16 *p_tdm_Pri_pitch_buf_fx; - int16_t local_element_mode; + Word16 local_element_mode; + Word16 tmp_e = 0; + move16(); ivas_error error; Word32 bpf_error_signal_fx[L_FRAME16k]; @@ -146,46 +148,53 @@ ivas_error acelp_core_dec_ivas_fx( Word16 tmp; error = IVAS_ERR_OK; - - if ( st->element_mode == IVAS_CPE_MDCT && nchan_out == 1 && st->idchan == 1 && last_element_brate <= IVAS_SID_5k2 ) + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( nchan_out, 1 ) && EQ_16( st->idchan, 1 ) && LE_32( last_element_brate, IVAS_SID_5k2 ) ) { /* 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; } push_wmops( "acelp_core_dec" ); - - output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); + tmp = BASOP_Util_Divide3232_Scale( st->output_Fs, FRAMES_PER_SEC, &tmp_e ); + output_frame = shr( tmp, sub( 15, tmp_e ) ); + // 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 ) + test(); + test(); + IF( LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( nchan_out, 2 ) ) { - if ( st->cng_type == FD_CNG ) + IF( EQ_16( st->cng_type, FD_CNG ) ) { configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; /* Only run parameter decoding in SID frames */ - if ( st->core_brate == SID_2k40 ) + IF( EQ_32( st->core_brate, SID_2k40 ) ) { FdCng_decodeSID_ivas_fx( st ); - rescale_fdCngDec( st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ); + rescale_fdCngDec( st->hFdCngDec, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); } - for ( i = 0; i < NPART; i++ ) + FOR( i = 0; i < NPART; i++ ) { st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = L_add( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) ); + move32(); } ApplyFdCng_ivas_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); - if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + IF( LT_16( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 0 ) ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + move16(); } } - else + ELSE { configureFdCngDec_fx( st->hFdCngDec, st->bwidth, ACELP_14k25, st->L_frame, st->last_L_frame, st->element_mode ); @@ -216,150 +225,191 @@ ivas_error acelp_core_dec_ivas_fx( *----------------------------------------------------------------*/ /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { set32_fx( realBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( imagBufferTmp_fx[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer_fx[i] = realBufferTmp_fx[i]; + move32(); imagBuffer_fx[i] = imagBufferTmp_fx[i]; + move32(); } /*----------------------------------------------------------------* * Initialization *----------------------------------------------------------------*/ LSF_Q_prediction = -1; - + move16(); set_s( syn_tmp_fx, 0, L_SUBFR ); psyn_fx = syn_tmp_fx + L_SUBFR; syn1_tmp_fx[0] = 0; + move16(); syn1_tmp_fx[1] = 0; + move16(); syn1_fx = syn1_tmp_fx + 2; st->bpf_off = 0; - - if ( st->last_core == HQ_CORE || st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE || ( st->element_mode == IVAS_CPE_DFT && st->last_core_brate <= SID_2k40 ) || ( st->element_mode == IVAS_CPE_MDCT && st->last_core_brate <= SID_2k40 ) ) + move16(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->last_core, HQ_CORE ) || EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->last_core_brate, SID_2k40 ) ) ) { /* in case of HQ->ACELP switching, do not apply BPF */ st->bpf_off = 1; - + move16(); if ( st->hPFstat != NULL ) { /* in case of core switching, reset post-filter memories */ st->hPFstat->on = 0; + move16(); } if ( st->hGSCDec != NULL ) { /* reset the GSC pre echo energy threshold in case of switching */ st->hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); } } - if ( st->hGSCDec != NULL && st->prev_bfi > 0 ) + IF( st->hGSCDec != NULL && ( st->prev_bfi > 0 ) ) { /* reset the GSC pre echo energy threshold in case of FEC */ st->hGSCDec->Last_frame_ener_fx = MAX_32; + move32(); } - - 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 ) ) + test(); + test(); + test(); + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( EQ_32( st->last_core_brate, SID_2k40 ) || EQ_32( st->last_core_brate, FRAME_NO_DATA ) ) ) { set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, FFTLEN ); set_s( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); } st->clas_dec = st->last_good; - + move16(); enr_q_fx = 0; + move32(); Es_pred_fx = 0; + move16(); tmp_noise_fx = 0; - + move16(); Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); exc_fx = old_exc_fx + L_EXC_MEM_DEC; - if ( st->hWIDec != NULL ) + IF( st->hWIDec != NULL ) { Copy( st->hWIDec->old_exc2_fx, old_exc2_fx, L_EXC_MEM ); } - else + ELSE { set_s( old_exc2_fx, 0, L_EXC_MEM ); } exc2_fx = old_exc2_fx + L_EXC_MEM; - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { Copy( st->hBWE_TD->old_bwe_exc_fx, old_bwe_exc_fx, PIT16k_MAX * 2 ); bwe_exc_fx = old_bwe_exc_fx + PIT16k_MAX * 2; } - else + ELSE { bwe_exc_fx = NULL; } last_pulse_pos = 0; + move16(); do_WI = 0; + move16(); st->GSC_noisy_speech = 0; + move16(); st->relax_prev_lsf_interp = 0; + move16(); set_s( gain_buf_fx, 0, NB_SUBFR16k ); - if ( st->L_frame == L_FRAME ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { st->gamma = GAMMA1; + move16(); st->inv_gamma = GAMMA1_INV; + move16(); st->preemph_fac = PREEMPH_FAC; + move16(); int_fs = INT_FS_12k8; + move16(); } - else + ELSE { st->gamma = GAMMA16k; + move16(); st->inv_gamma = GAMMA16k_INV; + move16(); st->preemph_fac = PREEMPH_FAC_16k; + move16(); int_fs = INT_FS_16k; + move16(); } - + test(); /* reset post-filter in case of switching */ - if ( st->hPFstat != NULL && st->hPFstat->on == 0 ) + IF( st->hPFstat != NULL && ( st->hPFstat->on == 0 ) ) { st->hPFstat->reset = 1; + move16(); } avoid_lpc_burst_on_recovery = 0; - if ( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && st->last_core != 0 ) + move16(); + test(); + test(); + IF( st->last_con_tcx && NE_16( st->L_frameTCX_past, st->L_frame ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; + move16(); } - + test(); /* TD stereo parameters */ - if ( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) { tdm_lp_reuse_flag = hStereoTD->tdm_lp_reuse_flag; + move16(); tdm_low_rate_mode = hStereoTD->tdm_low_rate_mode; + move16(); tdm_Pitch_reuse_flag = hStereoTD->tdm_Pitch_reuse_flag; + move16(); p_tdm_Pri_pitch_buf_fx = hStereoTD->tdm_Pri_pitch_buf_fx; } - else + ELSE { tdm_lp_reuse_flag = 0; + move16(); tdm_low_rate_mode = 0; - if ( st->element_mode == IVAS_SCE && st->low_rate_mode ) + move16(); + test(); + IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) { tdm_low_rate_mode = 1; + move16(); } tdm_Pitch_reuse_flag = 0; + move16(); p_tdm_Pri_pitch_buf_fx = NULL; } /*----------------------------------------------------------------* * Updates in case of internal sampling rate switching *----------------------------------------------------------------*/ - - if ( st->last_L_frame != st->L_frame && ( st->last_core == ACELP_CORE || st->last_core == AMR_WB_CORE ) ) + test(); + test(); + IF( NE_16( st->last_L_frame, st->L_frame ) && ( EQ_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - int16_t dec; + Word16 dec; - if ( st->hPFstat->on != 0 ) + IF( ( st->hPFstat->on != 0 ) ) { - int16_t mem_syn_r_size_old, mem_syn_r_size_new; + Word16 mem_syn_r_size_old, mem_syn_r_size_new; mem_syn_r_size_old = mult_r( 2048, st->last_L_frame ); mem_syn_r_size_new = mult_r( 2048, st->L_frame ); 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 ); @@ -378,11 +428,11 @@ ivas_error acelp_core_dec_ivas_fx( Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Reset LPC mem */ - if ( st->sr_core == INT_FS_16k ) + IF( EQ_32( st->sr_core, INT_FS_16k ) ) { Copy( GEWB2_Ave_fx, st->mem_AR_fx, M ); } - else + ELSE { Copy( GEWB_Ave_fx, st->mem_AR_fx, M ); } @@ -390,9 +440,11 @@ ivas_error acelp_core_dec_ivas_fx( /* update synthesis filter memories */ dec = DEC; - if ( st->element_mode != EVS_MONO ) + move16(); + IF( NE_16( st->element_mode, EVS_MONO ) ) { dec = DEC_IVAS; + move16(); } synth_mem_updt2( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, dec ); Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); @@ -408,14 +460,17 @@ ivas_error acelp_core_dec_ivas_fx( IF( EQ_16( st->last_L_frame, L_FRAME32k ) ) { tmpF_fx = 13107; + move16(); } ELSE IF( EQ_16( st->last_L_frame, 512 ) ) { tmpF_fx = 16384; + move16(); } ELSE /* st->last_L_frame == L_FRAME16k */ { tmpF_fx = 26214; + move16(); } FOR( i = NB_SUBFR16k - NB_SUBFR; i < NB_SUBFR16k; i++ ) @@ -446,8 +501,9 @@ ivas_error acelp_core_dec_ivas_fx( { tmpF_fx = 20480; // Q14 exp = 1; + move16(); } - + move16(); FOR( i = 2 * NB_SUBFR - 1; i >= NB_SUBFR; i-- ) { st->old_pitch_buf_fx[i + 2] = Mpy_32_16_1( L_shl( st->old_pitch_buf_fx[i], exp ), tmpF_fx ); @@ -503,23 +559,27 @@ ivas_error acelp_core_dec_ivas_fx( { tmpF_fx = 20480; // Q14 exp = 1; + move16(); } + move16(); st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); st->bfi_pitch_frame = L_FRAME16k; move16(); } } - - if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) + test(); + test(); + IF( EQ_16( st->last_bwidth, NB ) && NE_16( st->bwidth, NB ) && ( st->ini_frame != 0 ) ) { st->rate_switching_reset = 1; + move16(); } /*----------------------------------------------------------------------* * GOOD frame *----------------------------------------------------------------------*/ - if ( !st->bfi ) + IF( !st->bfi ) { /*----------------------------------------------------------------* @@ -527,18 +587,24 @@ ivas_error acelp_core_dec_ivas_fx( *----------------------------------------------------------------*/ tc_subfr = -1; - if ( st->coder_type == TRANSITION ) + move16(); + IF( EQ_16( st->coder_type, TRANSITION ) ) { - tc_subfr = tc_classif( st ); + tc_subfr = tc_classif_fx( st, st->L_frame ); } /*----------------------------------------------------------------* * Decoding of GSC IVAS mode *----------------------------------------------------------------*/ - - if ( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && !tdm_low_rate_mode ) + test(); + test(); + test(); + test(); + IF( GT_16( st->element_mode, EVS_MONO ) && EQ_16( st->idchan, 0 ) && !( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && !tdm_low_rate_mode ) { - if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) + test(); + test(); + IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) ) { st->GSC_IVAS_mode = get_next_indice( st, 2 ); } @@ -547,48 +613,55 @@ ivas_error acelp_core_dec_ivas_fx( /*----------------------------------------------------------------* * Decoding of inactive CNG frames *----------------------------------------------------------------*/ - - if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) + test(); + IF( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) { /* decode CNG parameters */ - if ( st->cng_type == LP_CNG ) + IF( EQ_16( st->cng_type, LP_CNG ) ) { CNG_dec_fx( st, last_element_mode, Aq_fx, lsp_new_fx, lsf_new_fx, &allow_cn_step, sid_bw, q_env_fx ); - for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) + FOR( Word32 nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { - Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, norm_s( Aq_fx[nsf * ( M + 1 )] ) - Q2 ); - Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); + Aq_fx[imult3216( nsf, M + 1 )] = ONE_IN_Q12; + move16(); } - Copy( Aq_fx, st->Aq_cng, M + 1 ); + Copy( Aq_fx, st->Aq_cng, add( M, 1 ) ); /* comfort noise generation */ local_element_mode = st->element_mode; - if ( ( nchan_out == 1 && st->element_mode == IVAS_CPE_DFT ) || ( st->masa_sid_format == 1 ) ) + move16(); + test(); + test(); + IF( ( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) ) || EQ_16( st->masa_sid_format, 1 ) ) { local_element_mode = IVAS_SCE; /* For DFT Stereo mono decoding, run CNG_exc as in SCE */ + move16(); } CNG_exc_fx( st->core_brate, st->L_frame, &st->hTdCngDec->Enew_fx, &st->hTdCngDec->cng_seed, exc_fx, exc2_fx, &st->lp_ener_fx, st->last_core_brate, &st->first_CNG, &( st->hTdCngDec->cng_ener_seed ), bwe_exc_fx, allow_cn_step, &st->hTdCngDec->last_allow_cn_step, st->prev_Q_exc, st->Q_exc, st->hTdCngDec->num_ho, q_env_fx, st->hTdCngDec->lp_env_fx, st->hTdCngDec->old_env_fx, st->hTdCngDec->exc_mem_fx, st->hTdCngDec->exc_mem1_fx, sid_bw, &st->hTdCngDec->cng_ener_seed1, exc3_fx, st->Opt_AMR_WB, local_element_mode ); } - else + ELSE { - if ( st->core_brate == SID_2k40 && st->element_mode != IVAS_CPE_MDCT ) + IF( EQ_32( st->core_brate, SID_2k40 ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { Word16 old_NoiseEstExp = st->hFdCngDec->hFdCngCom->sidNoiseEstExp; FdCng_decodeSID_ivas_fx( st ); - rescale_fdCngDec( st->hFdCngDec, old_NoiseEstExp - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ); - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ) - Q2 ); + rescale_fdCngDec( st->hFdCngDec, sub( old_NoiseEstExp, st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ), Q2 ) ); *sid_bw = 0; + move16(); } - if ( st->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { assert( nchan_out == 1 ); - for ( i = 0; i < NPART; i++ ) + FOR( i = 0; i < NPART; i++ ) { st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] = L_add( Mpy_32_32( STEREO_DFT_FD_FILT_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEstLp[i] ), Mpy_32_32( STEREO_DFT_FD_FILT_COMP_Q31, st->hFdCngDec->hFdCngCom->sidNoiseEst[i] ) ); + move32(); } Word16 new_sidNoiseEstExp = 31 - Q4; Scale_sig32( st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - new_sidNoiseEstExp ); @@ -600,21 +673,23 @@ ivas_error acelp_core_dec_ivas_fx( ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + IF( LT_16( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 0 ) ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + move16(); } } - if ( !read_sid_info ) + IF( !read_sid_info ) { Word32 noise_lvl_highest_fx; noise_lvl_highest_fx = 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++ ) + FOR( Word16 b = st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; b < st->hFdCngDec->hFdCngCom->stopBand; b++ ) { st->hFdCngDec->hFdCngCom->cngNoiseLevel[b] = noise_lvl_highest_fx; + move32(); } } @@ -634,6 +709,8 @@ ivas_error acelp_core_dec_ivas_fx( move16(); } i = st->Q_exc; + move16(); + test(); IF( st->hMusicPF && st->hGSCDec ) { Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, @@ -652,26 +729,30 @@ ivas_error acelp_core_dec_ivas_fx( Copy_Scale_sig( exc2_fx, exc2_fx, st->L_frame, sub( st->Q_exc, i ) ); /* update past excitation signals for LD music post-filter */ - if ( st->hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); Copy( exc2_fx, st->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++ ) + FOR( i = 0; i < DCT_L_POST; i++ ) { st->hMusicPF->filt_lfE_fx[i] = add( 9830, mult_r( 22937, st->hMusicPF->filt_lfE_fx[i] ) ); + move16(); } } /* synthesis at 12.8kHz sampling rate */ Aq_fx[0] = ONE_IN_Q12; + move16(); syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); syn_12k8_fx( st->L_frame, Aq_fx, exc3_fx, syn1_fx, st->mem_syn3_fx, 1, st->Q_exc, st->Q_syn ); st->Q_syn_cng = st->Q_syn; + move16(); st->Q_exc_cng = st->Q_exc; + move16(); /* reset the decoder */ CNG_reset_dec_fx( st, pitch_buf_fx, voice_factors_fx ); @@ -683,7 +764,7 @@ ivas_error acelp_core_dec_ivas_fx( /* save and delay synthesis to be used by SWB BWE */ Copy_Scale_sig( syn1_fx, temp_buf_fx, st->L_frame, sub( -1, st->Q_syn ) ); - if ( st->hBWE_FD != NULL ) + IF( st->hBWE_FD != NULL ) { save_old_syn_fx( st->L_frame, syn1_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } @@ -693,7 +774,7 @@ ivas_error acelp_core_dec_ivas_fx( * Decoding of all other frames *----------------------------------------------------------------*/ - else + ELSE { /*-----------------------------------------------------------------* @@ -701,27 +782,34 @@ ivas_error acelp_core_dec_ivas_fx( *-----------------------------------------------------------------*/ nb_bits = 0; + move16(); st->acelp_cfg.FEC_mode = 0; + move16(); uc_two_stage_flag = 0; - - if ( !st->nelp_mode_dec && !st->ppp_mode_dec ) + move16(); + test(); + IF( !st->nelp_mode_dec && !st->ppp_mode_dec ) { - int16_t tc_subfr_tmp; + Word16 tc_subfr_tmp; tc_subfr_tmp = tc_subfr; - if ( tc_subfr_tmp < L_SUBFR ) + move16(); + if ( LT_16( tc_subfr_tmp, L_SUBFR ) ) { tc_subfr_tmp = 0; + move16(); } - if ( tc_subfr == TC_0_192 ) + if ( EQ_16( tc_subfr, TC_0_192 ) ) { nb_bits = -1; + move16(); } config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); - - if ( st->coder_type == TRANSITION && tc_subfr < L_SUBFR && st->L_frame == L_FRAME ) + test(); + test(); + IF( EQ_16( st->coder_type, TRANSITION ) && LT_16( tc_subfr, L_SUBFR ) && EQ_16( st->L_frame, L_FRAME ) ) { config_acelp1_IVAS( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); } @@ -730,8 +818,10 @@ ivas_error acelp_core_dec_ivas_fx( /*-----------------------------------------------------------------* * After CNG period, use the most up-to-date LSPs *-----------------------------------------------------------------*/ - - if ( st->hTdCngDec != NULL && ( st->last_core_brate == FRAME_NO_DATA || st->last_core_brate == SID_2k40 ) ) + test(); + test(); + test(); + IF( st->hTdCngDec != NULL && ( EQ_32( st->last_core_brate, FRAME_NO_DATA ) || EQ_32( st->last_core_brate, SID_2k40 ) ) ) { Copy( st->lspCNG_fx, st->lsp_old_fx, M ); lsp2lsf_fx( st->lspCNG_fx, st->lsf_old_fx, M, int_fs ); @@ -741,40 +831,43 @@ ivas_error acelp_core_dec_ivas_fx( * Reset higher ACELP pre-quantizer in case of switching *-----------------------------------------------------------------*/ - if ( !st->use_acelp_preq ) + IF( !st->use_acelp_preq ) { st->mem_preemp_preQ_fx = 0; st->last_nq_preQ = 0; st->last_code_preq = 0; + move16(); + move16(); + move16(); } st->use_acelp_preq = 0; - + move16(); /*-----------------------------------------------------------------* * LSF de-quantization and interpolation *-----------------------------------------------------------------*/ - if ( !tdm_lp_reuse_flag ) + IF( !tdm_lp_reuse_flag ) { lsf_dec_fx( st, tc_subfr, Aq_fx, &LSF_Q_prediction, lsf_new_fx, lsp_new_fx, lsp_mid_fx, tdm_low_rate_mode /*, tdm_lsfQ_PCh*/ ); } - else + ELSE { const Word16 *pt_interp_2_fx; - if ( st->active_cnt != 1 ) + IF( NE_16( st->active_cnt, 1 ) ) { - int16_t beta_index; + Word16 beta_index; beta_index = get_next_indice( st, TDM_IC_LSF_PRED_BITS ); tdm_SCh_lsf_reuse_fx( DEC, st->element_brate, lsf_new_fx, lsp_new_fx, tdm_lsfQ_PCh_fx, NULL, &beta_index ); } - else + ELSE { Copy( tdm_lspQ_PCh_fx, lsp_new_fx, M ); Copy( tdm_lsfQ_PCh_fx, lsf_new_fx, M ); } - if ( st->rate_switching_reset ) + IF( st->rate_switching_reset ) { /* extrapolation in case of unstable LSF convert */ Copy( lsp_new_fx, st->lsp_old_fx, M ); @@ -782,12 +875,15 @@ ivas_error acelp_core_dec_ivas_fx( } pt_interp_2_fx = interpol_frac_fx; - if ( tdm_low_rate_mode == 1 && st->coder_type > UNVOICED ) + move16(); + test(); + IF( EQ_16( tdm_low_rate_mode, 1 ) && GT_16( st->coder_type, UNVOICED ) ) { pt_interp_2_fx = interpol_frac2_fx; + move16(); } - if ( st->active_cnt == 1 ) + IF( EQ_16( st->active_cnt, 1 ) ) { Copy( lsp_new_fx, st->lsp_old_fx, M ); lsp2lsf_fx( lsp_new_fx, st->lsf_old_fx, M, st->sr_core ); @@ -802,13 +898,15 @@ ivas_error acelp_core_dec_ivas_fx( for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { #else - FOR( int nsf = 0; nsf < st->nb_subfr; nsf++ ) + FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) #endif { - Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, norm_s( Aq_fx[nsf * ( M + 1 )] ) - Q2 ); - Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); + Aq_fx[imult3216( nsf, add( M, 1 ) )] = ONE_IN_Q12; + move16(); } - if ( st->last_core == HQ_CORE && st->element_mode > EVS_MONO ) + test(); + IF( EQ_16( st->last_core, HQ_CORE ) && GT_16( st->element_mode, EVS_MONO ) ) { /* Prepare ACB memory from last HQ frame */ old_exc_s_fx = st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame; @@ -821,17 +919,17 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig( old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, st->Q_exc ); #endif } - - if ( st->last_core != ACELP_CORE && st->element_mode > EVS_MONO ) + test(); + IF( NE_16( st->last_core, ACELP_CORE ) && GT_16( st->element_mode, EVS_MONO ) ) { /* Prepare ACB memory of old_bwe_exc */ - if ( st->L_frame == L_FRAME ) + IF( EQ_16( st->L_frame, L_FRAME ) ) { lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * HIBND_ACB_L_FAC, L_EXC_MEM_DEC ); } - else + ELSE { - lerp( old_exc_fx, old_bwe_exc_fx, L_EXC_MEM_DEC * 2, L_EXC_MEM_DEC ); + lerp( old_exc_fx, old_bwe_exc_fx, shl( L_EXC_MEM_DEC, 1 ), L_EXC_MEM_DEC ); } } @@ -839,20 +937,27 @@ ivas_error acelp_core_dec_ivas_fx( * FEC - first good frame after lost frame(s) (possibility to correct the ACB) *-----------------------------------------------------------------*/ - if ( st->acelp_cfg.FEC_mode > 0 ) + IF( st->acelp_cfg.FEC_mode > 0 ) { last_pulse_pos = 0; - + move16(); /* decode the last glottal pulse position */ T0_tmp = FEC_pos_dec_fx( st, &last_pulse_pos, &enr_q_fx, nb_bits ); - - if ( st->last_core != HQ_CORE || ( st->last_core == HQ_CORE && st->last_con_tcx ) ) + test(); + test(); + IF( NE_16( st->last_core, HQ_CORE ) || ( EQ_16( st->last_core, HQ_CORE ) && st->last_con_tcx ) ) { - if ( st->clas_dec == SIN_ONSET && last_pulse_pos != 0 && st->prev_bfi == 1 ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->clas_dec, SIN_ONSET ) && NE_16( last_pulse_pos, 0 ) && EQ_16( st->prev_bfi, 1 ) ) { FEC_SinOnset_fx( old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, last_pulse_pos, T0_tmp, enr_q_fx, Aq_fx, st->L_frame, st->Q_exc ); } - else if ( ( st->coder_type == GENERIC || st->coder_type == VOICED ) && last_pulse_pos != 0 && st->old_bfi_cnt == 1 && st->hWIDec != NULL ) + ELSE IF( ( EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, VOICED ) ) && NE_16( last_pulse_pos, 0 ) && EQ_16( st->old_bfi_cnt, 1 ) && st->hWIDec != NULL ) { do_WI = FEC_enhACB_fx( st->L_frame, st->last_L_frame, old_exc_fx + L_EXC_MEM_DEC - L_EXC_MEM, T0_tmp, last_pulse_pos, st->bfi_pitch_fx ); } @@ -863,8 +968,13 @@ ivas_error acelp_core_dec_ivas_fx( * In case of first frame after an erasure and transition from voiced to unvoiced or inactive * redo the LPC interpolation *------------------------------------------------------------*/ - - if ( st->stab_fac_fx == 0 && st->old_bfi_cnt > 0 && st->clas_dec != VOICED_CLAS && st->clas_dec != ONSET && st->relax_prev_lsf_interp == 0 && !( st->element_mode == IVAS_CPE_TD && st->idchan == 1 ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( st->stab_fac_fx == 0 ) && ( st->old_bfi_cnt > 0 ) && NE_16( st->clas_dec, VOICED_CLAS ) && NE_16( st->clas_dec, ONSET ) && ( st->relax_prev_lsf_interp == 0 ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) ) { int_lsp4_fx( st->L_frame, st->lsp_old_fx, lsp_mid_fx, lsp_new_fx, Aq_fx, M, 2 ); } @@ -873,7 +983,7 @@ ivas_error acelp_core_dec_ivas_fx( * Decoding of the scaled predicted innovation energy *---------------------------------------------------------------*/ - if ( nb_bits > 0 ) + IF( GT_16( nb_bits, 0 ) ) { indice = get_next_indice( st, nb_bits ); Es_pred_dec_fx( &Es_pred_fx, indice, nb_bits, uc_two_stage_flag ); @@ -882,25 +992,26 @@ ivas_error acelp_core_dec_ivas_fx( /*------------------------------------------------------------* * Decode excitation according to coding type *------------------------------------------------------------*/ - - if ( tdm_low_rate_mode ) /* tdm stereo low rate mode */ + test(); + test(); + IF( tdm_low_rate_mode ) /* tdm stereo low rate mode */ { - if ( st->coder_type <= UNVOICED ) + IF( LE_16( st->coder_type, UNVOICED ) ) { tdm_low_rate_dec_fx( st, dct_exc_tmp_fx /*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - else /* GENERIC */ + ELSE /* GENERIC */ { decod_gen_2sbfr_ivas_fx( st, sharpFlag, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ); - if ( st->element_mode == IVAS_CPE_TD ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } } } - else if ( st->nelp_mode_dec ) + ELSE IF( st->nelp_mode_dec ) { /* SC-VBR - NELP frames */ Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); @@ -910,29 +1021,30 @@ ivas_error acelp_core_dec_ivas_fx( decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } - else if ( st->coder_type == UNVOICED ) + ELSE IF( EQ_16( st->coder_type, UNVOICED ) ) { /* UNVOICED frames */ decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - else if ( st->ppp_mode_dec ) + ELSE IF( st->ppp_mode_dec ) { Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); st->Q_exc = 0; + move16(); /* SC-VBR - PPP frames */ - if ( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) + IF( ( error = decod_ppp_fx( st, Aq_fx, pitch_buf_fx, exc_fx, exc2_fx, st->bfi, gain_buf_fx, voice_factors_fx, bwe_exc_fx ) ) != IVAS_ERR_OK ) { return error; } Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } - else if ( st->coder_type == TRANSITION ) + ELSE IF( EQ_16( st->coder_type, TRANSITION ) ) { decod_tran_fx( st, st->L_frame, tc_subfr, Aq_fx, Es_pred_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, sharpFlag, gain_buf_fx ); } - else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) + ELSE IF( EQ_16( st->coder_type, AUDIO ) || ( EQ_16( st->coder_type, INACTIVE ) && st->inactive_coder_type_flag ) ) { /* AUDIO and INACTIVE frames (coded by GSC technology) */ decod_audio_ivas_fx( st, dct_exc_tmp_fx, Aq_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, gain_buf_fx @@ -943,15 +1055,15 @@ ivas_error acelp_core_dec_ivas_fx( ); tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } - else + ELSE { /* GENERIC, VOICED and INACTIVE frames (coded by AVQ technology) */ - if ( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) + IF( ( error = decod_gen_voic_ivas_fx( st, st->L_frame, sharpFlag, Aq_fx, Es_pred_fx, do_WI, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, unbits, gain_buf_fx, tdm_Pitch_reuse_flag, p_tdm_Pri_pitch_buf_fx ) ) != IVAS_ERR_OK ) { return error; } - if ( st->element_mode == IVAS_CPE_TD ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { tmp_noise_fx = shr_r( st->lp_gainc_fx, 3 ); /*Q0*/ } @@ -961,7 +1073,7 @@ ivas_error acelp_core_dec_ivas_fx( syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); /* save and delay synthesis to be used by SWB BWE */ - if ( st->hBWE_FD != NULL ) + IF( st->hBWE_FD != NULL ) { save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } @@ -975,8 +1087,11 @@ ivas_error acelp_core_dec_ivas_fx( /*------------------------------------------------------------* * Decode information and modify the excitation signal of stationary unvoiced frames *------------------------------------------------------------*/ - - if ( !( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) && st->nelp_mode_dec != 1 && !( st->element_mode == IVAS_SCE && tdm_low_rate_mode ) ) + test(); + test(); + test(); + test(); + IF( !( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) && NE_16( st->nelp_mode_dec, 1 ) && !( EQ_16( st->element_mode, IVAS_SCE ) && tdm_low_rate_mode ) ) { stat_noise_uv_dec_fx( st, lsp_new_fx, lsp_mid_fx, Aq_fx, exc2_fx, uc_two_stage_flag ); } @@ -987,23 +1102,31 @@ ivas_error acelp_core_dec_ivas_fx( *------------------------------------------------------------*/ /* update past excitation signals for LD music post-filter */ - if ( st->hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { - Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); + Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, sub( sub( DCT_L_POST, L_FRAME ), OFFSET2 ) ); Copy( exc2_fx, st->hMusicPF->dct_post_old_exc_fx + ( DCT_L_POST - L_FRAME - OFFSET2 ), L_FRAME ); - Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, DCT_L_POST - OFFSET2 ); + Copy( st->hMusicPF->dct_post_old_exc_fx, exc_buffer_fx, sub( DCT_L_POST, OFFSET2 ) ); } + test(); + test(); + test(); - if ( ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) || ( st->GSC_IVAS_mode >= 1 && st->L_frame == L_FRAME ) ) + IF( ( EQ_16( st->coder_type, AUDIO ) && !st->GSC_noisy_speech ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && EQ_16( st->L_frame, L_FRAME ) ) ) { - int16_t last_coder_type = st->last_coder_type; - - if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD ) || ( st->GSC_IVAS_mode >= 1 && st->GSC_noisy_speech == 0 ) ) + Word16 last_coder_type = st->last_coder_type; + move16(); + test(); + test(); + test(); + IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) || ( GE_16( st->GSC_IVAS_mode, 1 ) && ( st->GSC_noisy_speech == 0 ) ) ) { last_coder_type = AUDIO; + move16(); } Word16 qdct = 0; + move16(); /* Extrapolation of the last future part, windowing and high resolution DCT transform */ Prep_music_postP_fx( exc_buffer_fx, dct_buffer_fx, st->hMusicPF->filt_lfE_fx, st->last_core, st->element_mode, pitch_buf_fx, st->hMusicPF->LDm_enh_lp_gbin_fx, st->Q_exc, &qdct ); @@ -1016,7 +1139,7 @@ ivas_error acelp_core_dec_ivas_fx( &st->Q_syn, st->mem_syn_clas_estim_fx, 0, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, temp_buf_fx, mem_tmp_fx ); } - else + ELSE { /* Core synthesis at 12.8kHz or 16kHz */ i = 1; @@ -1031,7 +1154,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); test(); - if ( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + IF( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); @@ -1043,9 +1166,9 @@ ivas_error acelp_core_dec_ivas_fx( Copy( st->mem_syn2_fx, mem_tmp_fx, M ); syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); - if ( st->hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { - for ( i = 0; i < DCT_L_POST; i++ ) + FOR( i = 0; i < DCT_L_POST; i++ ) { st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); } @@ -1078,9 +1201,11 @@ ivas_error acelp_core_dec_ivas_fx( FEC_scale_syn_fx( st->L_frame, &update_flg, st->clas_dec, st->last_good, psyn_fx, pitch_buf_tmp, st->enr_old_fx, enr_q_fx, st->coder_type, LSF_Q_prediction, &st->scaling_flag, &st->lp_ener_FEC_av, &st->lp_ener_FEC_max, st->bfi, st->total_brate, st->prev_bfi, st->last_core_brate, exc_fx, exc2_fx, Aq_fx, &st->old_enr_LP, mem_tmp_fx, st->mem_syn2_fx, st->Q_exc, st->Q_syn, avoid_lpc_burst_on_recovery, 0 ); - + test(); + test(); + test(); /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ - if ( ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->total_brate <= ACELP_7k20 ) || ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + IF( ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && LE_32( st->total_brate, ACELP_7k20 ) ) || EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { frame_ener_fx( st->L_frame, st->clas_dec, psyn_fx, pitch_buf_tmp[sub( shr( st->L_frame, 6 ), 1 )], &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); } @@ -1092,15 +1217,17 @@ ivas_error acelp_core_dec_ivas_fx( * BAD frame *----------------------------------------------------------------*/ - else + ELSE { /* SC-VBR */ - IF( EQ_16( st->last_nelp_mode_dec, 1 ) ) + if ( EQ_16( st->last_nelp_mode_dec, 1 ) ) { st->nelp_mode_dec = 1; move16(); } - + test(); + test(); + test(); /* long burst frame erasures */ IF( GT_16( st->nbLostCmpt, 5 ) && GE_16( st->clas_dec, VOICED_CLAS ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) { @@ -1116,13 +1243,14 @@ ivas_error acelp_core_dec_ivas_fx( for ( int nsf = 0; nsf < NB_SUBFR16k; nsf++ ) { #else - FOR( int nsf = 0; nsf < st->nb_subfr; nsf++ ) + FOR( Word32 nsf = 0; nsf < st->nb_subfr; nsf++ ) { #endif - Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, norm_s( Aq_fx[nsf * ( M + 1 )] ) - Q2 ); - Aq_fx[nsf * ( M + 1 )] = ONE_IN_Q12; + Scale_sig( Aq_fx + ( nsf * ( M + 1 ) ), M + 1, sub( norm_s( Aq_fx[imult3216( nsf, add( M, 1 ) )] ), Q2 ) ); + Aq_fx[imult3216( nsf, add( M, 1 ) )] = ONE_IN_Q12; + move16(); } - if ( st->nelp_mode_dec == 1 ) + IF( EQ_16( st->nelp_mode_dec, 1 ) ) { /* SC-VBR */ Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, -st->Q_exc ); @@ -1131,10 +1259,10 @@ ivas_error acelp_core_dec_ivas_fx( decod_nelp_fx( st, &tmp_noise_fx, pitch_buf_fx, exc_fx, exc2_fx, voice_factors_fx, bwe_exc_fx, &st->Q_exc, st->bfi, gain_buf_fx ); FEC_pitch_fx = pitch_buf_fx[3]; - + move16(); Rescale_exc( st->hMusicPF->dct_post_old_exc_fx, exc_fx, NULL, st->hGSCDec->last_exc_dct_in_fx, L_FRAME, 0, (Word32) 0, &( st->Q_exc ), st->Q_subfr, exc2_fx, L_FRAME, st->coder_type ); } - else + ELSE { /* calculation of excitation signal */ FEC_exc_estim_fx( st, st->L_frame, exc_fx, exc2_fx, dct_exc_tmp_fx, pitch_buf_fx, voice_factors_fx, &FEC_pitch_fx, bwe_exc_fx, lsf_new_fx, &st->Q_exc, &tmp_noise_fx ); @@ -1146,13 +1274,14 @@ ivas_error acelp_core_dec_ivas_fx( /* SC-VBR */ st->prev_gain_pit_dec_fx = st->lp_gainp_fx; + move16(); } /* synthesis for ACELP core switching and SWB BWE */ syn_12k8_fx( st->L_frame, Aq_fx, exc_fx, temp_buf_fx, st->mem_syn1_fx, 1, st->Q_exc, -1 ); /* save and delay synthesis to be used by SWB BWE */ - if ( st->hBWE_FD != NULL ) + IF( st->hBWE_FD != NULL ) { save_old_syn_fx( st->L_frame, temp_buf_fx, old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k_fx, st->preemph_fac, &st->hBWE_FD->mem_deemph_old_syn_fx ); } @@ -1161,21 +1290,23 @@ ivas_error acelp_core_dec_ivas_fx( Inac_switch_ematch_ivas_fx( exc2_fx, dct_exc_tmp_fx, st->hGSCDec->lt_ener_per_band_fx, st->coder_type, st->L_frame, st->total_brate, st->Q_exc, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); /* update past excitation signals for LD music post-filter */ - if ( st->hMusicPF != NULL ) + IF( st->hMusicPF != NULL ) { Copy( st->hMusicPF->dct_post_old_exc_fx + L_FRAME, st->hMusicPF->dct_post_old_exc_fx, DCT_L_POST - L_FRAME - OFFSET2 ); Copy( exc2_fx, st->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++ ) + FOR( i = 0; i < DCT_L_POST; i++ ) { - st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( ( 1228 << ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); + st->hMusicPF->filt_lfE_fx[i] = round_fx( L_mac( L_shl( 1228, ( 16 ) ), 22938, st->hMusicPF->filt_lfE_fx[i] ) ); + move16(); } /* Update circular buffer, keep last energy difference unchanged */ - for ( i = 1; i < MAX_LT; i++ ) + FOR( i = 1; i < MAX_LT; i++ ) { st->hMusicPF->LDm_lt_diff_etot_fx[i - 1] = st->hMusicPF->LDm_lt_diff_etot_fx[i]; + move16(); } } @@ -1185,7 +1316,7 @@ ivas_error acelp_core_dec_ivas_fx( move16(); test(); test(); - if ( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) + IF( EQ_16( st->coder_type, INACTIVE ) && st->flag_cna && GE_16( round_fx( L_shl( st->lp_noise, 1 ) ), 15 << 7 ) ) { k = 1; move16(); @@ -1193,30 +1324,31 @@ ivas_error acelp_core_dec_ivas_fx( Rescale_mem( st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, 4, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 1, k, temp_buf_fx ); - - if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + test(); + IF( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) { Copy( st->mem_syn2_fx, mem_tmp_fx, M ); } syn_12k8_fx( st->L_frame, Aq_fx, exc2_fx, psyn_fx, st->mem_syn2_fx, 1, st->Q_exc, st->Q_syn ); /* update buffer for classifier */ - if ( st->hWIDec != NULL ) + IF( st->hWIDec != NULL ) { Copy( exc2_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_exc2_fx, L_EXC_MEM ); Copy( psyn_fx + st->L_frame - L_EXC_MEM, st->hWIDec->old_syn2_fx, L_EXC_MEM ); } st->prev_Q_exc_fr = st->Q_exc; st->prev_Q_syn_fr = st->Q_syn; - + move16(); + move16(); Copy( psyn_fx + st->L_frame - L_SYN_MEM_CLAS_ESTIM, st->mem_syn_clas_estim_fx, L_SYN_MEM_CLAS_ESTIM ); /*------------------------------------------------------------* * FEC - Smooth the speech energy evolution when recovering after a BAD frame * (smoothing is performed in the excitation domain and signal is resynthesized after) *------------------------------------------------------------*/ - - if ( ( st->total_brate == ACELP_7k20 ) || ( st->total_brate == ACELP_8k00 ) ) + test(); + IF( EQ_32( st->total_brate, ACELP_7k20 ) || EQ_32( st->total_brate, ACELP_8k00 ) ) { Copy_Scale_sig( pitch_buf_fx, pitch_buf_tmp, NB_SUBFR16k, -Q6 ); @@ -1228,7 +1360,7 @@ ivas_error acelp_core_dec_ivas_fx( /* estimate the pitch-synchronous speech energy per sample to be used when normal operation recovers */ frame_ener_fx( st->L_frame, st->last_good, psyn_fx, shr( add( FEC_pitch_fx, 32 ), 6 ), &st->enr_old_fx, st->L_frame, st->Q_syn, 3, 0 ); - if ( st->nelp_mode_dec != 1 ) + IF( NE_16( st->nelp_mode_dec, 1 ) ) { /* modify the excitation signal of stationary unvoiced frames */ stat_noise_uv_mod_fx( st->coder_type, 0, st->lsp_old_fx, lsp_new_fx, lsp_new_fx, Aq_fx, exc2_fx, st->Q_exc, 1, &st->ge_sm_fx, @@ -1265,10 +1397,11 @@ ivas_error acelp_core_dec_ivas_fx( ELSE { st->hPFstat->on = 0; + move16(); nb_post_filt_fx( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, psyn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); } } - else + ELSE { st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); } @@ -1284,7 +1417,7 @@ ivas_error acelp_core_dec_ivas_fx( Copy( syn_fx_tmp2, psyn_fx, st->L_frame ); IF( st->hTcxDec != NULL ) { - Copy_Scale_sig( psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, st->L_frame / 2, sub( -1, st->Q_syn ) ); /*Q-1*/ + Copy_Scale_sig( psyn_fx + st->L_frame / 2, st->hTcxDec->old_syn_Overl, shr( st->L_frame, 1 ), sub( -1, st->Q_syn ) ); /*Q-1*/ } Copy_Scale_sig( psyn_fx + st->L_frame - M - 1, st->syn, M + 1, sub( 0, st->Q_syn ) ); /*Q0*/ @@ -1295,10 +1428,11 @@ ivas_error acelp_core_dec_ivas_fx( test(); test(); test(); - + test(); IF( st->hPFstat != NULL && GE_16( st->last_bwidth, WB ) && ( GT_32( st->core_brate, ACELP_24k40 ) || GT_16( st->element_mode, EVS_MONO ) ) && LE_32( st->core_brate, ACELP_32k ) ) { st->hPFstat->on = 1; + move16(); /*----ftf conversions---*/ Copy( psyn_fx, temp_buf_fx + L_SYN_MEM, L_FRAME16k ); @@ -1317,30 +1451,39 @@ ivas_error acelp_core_dec_ivas_fx( Residu3_fx( Aq_fx, temp_buf_fx + M, temp_buf_fx + M + L_SUBFR, L_SUBFR, 1 ); E_UTIL_synthesis( 1, Aq_fx, temp_buf_fx + M + L_SUBFR, temp_buf_fx, L_SUBFR, st->hPFstat->mem_stp + L_SYN_MEM - M, 0, M ); scale_st_fx( psyn_fx, temp_buf_fx, &st->hPFstat->gain_prec, L_SUBFR ); - Copy( temp_buf_fx, psyn_fx, L_SUBFR / 2 ); + Copy( temp_buf_fx, psyn_fx, ( L_SUBFR >> 1 ) ); blend_subfr2_fx( temp_buf_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2, psyn_fx + L_SUBFR / 2 ); } st->hPFstat->on = 0; + move16(); } /*----------------------------------------------------------------* * Comfort noise addition *----------------------------------------------------------------*/ - - if ( ( st->hFdCngDec != NULL || st->idchan == 1 ) && st->element_mode != IVAS_CPE_MDCT ) + test(); + test(); + IF( ( st->hFdCngDec != NULL || EQ_16( st->idchan, 1 ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - if ( st->element_mode == IVAS_CPE_TD || st->flag_cna || ( st->cng_type == FD_CNG && st->total_brate <= ACELP_32k ) || ( st->cng_type == LP_CNG && st->core_brate <= SID_2k40 ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( EQ_16( st->cng_type, LP_CNG ) && LE_32( st->core_brate, SID_2k40 ) ) ) { /*VAD only for non inactive frame*/ - st->VAD = st->VAD && ( st->coder_type != INACTIVE ); - - if ( st->idchan == 0 && ( st->flag_cna || ( st->cng_type == FD_CNG && st->total_brate <= ACELP_32k ) || ( st->cng_type == LP_CNG && st->core_brate <= SID_2k40 ) ) ) + st->VAD = st->VAD && NE_16( st->coder_type, INACTIVE ); + test(); + test(); + test(); + test(); + IF( EQ_16( st->idchan, 0 ) && ( st->flag_cna || ( EQ_16( st->cng_type, FD_CNG ) && LE_32( st->total_brate, ACELP_32k ) ) || ( EQ_16( st->cng_type, LP_CNG ) && LE_32( st->core_brate, SID_2k40 ) ) ) ) { /*Noisy speech detector*/ noisy_speech_detection_fx( st->hFdCngDec, st->VAD, psyn_fx, st->Q_syn ); st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = mult_r( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 32440 /*0.99 Q15*/ ); - IF( st->hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) + IF( NE_16( st->hFdCngDec->hFdCngCom->flag_noisy_speech, 0 ) ) { st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); move16(); @@ -1353,8 +1496,8 @@ ivas_error acelp_core_dec_ivas_fx( st->lp_noise = st->hFdCngDec->lp_noise; move32(); } - - if ( st->element_mode != IVAS_CPE_TD && !st->cng_ism_flag ) + test(); + IF( NE_16( st->element_mode, IVAS_CPE_TD ) && !st->cng_ism_flag ) { /*Noise estimate*/ @@ -1367,46 +1510,49 @@ ivas_error acelp_core_dec_ivas_fx( /*==========================================================*/ ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); /*==========================================================*/ - if ( st->hFdCngDec->partNoiseShape_exp < 0 ) + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) { Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); st->hFdCngDec->partNoiseShape_exp = 0; } - if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } } - if ( !st->cna_dirac_flag ) + IF( !st->cna_dirac_flag ) { + test(); + test(); /* 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->flag_cna && !( EQ_16( st->coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->GSC_noisy_speech ) ) ) { - if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { - if ( hStereoCng->flag_cna_fade ) + IF( hStereoCng->flag_cna_fade ) { generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); hStereoCng->flag_cna_fade = 0; } - else + ELSE { - if ( st->element_mode != last_element_mode && st->idchan == 0 ) + IF( NE_16( st->element_mode, last_element_mode ) && ( st->idchan == 0 ) ) { /* Clear memory for secondary channel CNA */ - set_s( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2 ); + set_s( hStereoCng->olapBufferSynth22_fx, 0, shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ) ); } generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); } } - else if ( st->element_mode != IVAS_CPE_DFT ) + ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - if ( st->idchan == 0 ) + IF( st->idchan == 0 ) { - if ( st->element_mode != last_element_mode ) + IF( NE_16( st->element_mode, last_element_mode ) ) { set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } @@ -1414,75 +1560,79 @@ ivas_error acelp_core_dec_ivas_fx( } } } - 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 ) ) + ELSE IF( st->flag_cna && EQ_16( st->coder_type, AUDIO ) && ( ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, TCX_20_CORE ) ) ) { - if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) { generate_stereo_masking_noise_fx( psyn_fx, st->Q_syn, st, hStereoTD, flag_sec_CNA, 1, hStereoCng, nchan_out ); hStereoCng->flag_cna_fade = 1; + move16(); } - else + ELSE { - FOR( i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) + FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); move16(); } } } - else + ELSE { if ( hStereoCng != NULL ) { hStereoCng->flag_cna_fade = 1; hStereoCng->enableSecCNA = 0; + move16(); + move16(); } } - if ( st->element_mode == IVAS_CPE_TD ) + IF( EQ_16( 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 ) ) ) + IF( ( st->idchan == 0 ) && ( EQ_16( nchan_out, 2 ) || ( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) ) ) { ApplyFdCng_ivas_fx( psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - if ( st->hFdCngDec->partNoiseShape_exp < 0 ) + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) { Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp ); st->hFdCngDec->partNoiseShape_exp = 0; } - if ( st->hFdCngDec->partNoiseShape_exp < 0 ) + IF( st->hFdCngDec->partNoiseShape_exp < 0 ) { Scale_sig32( st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp ); st->hFdCngDec->partNoiseShape_exp = 0; } - if ( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) + IF( st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0 ) { Scale_sig32( st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; } + move16(); } } } } - if ( !st->cna_dirac_flag ) + IF( !st->cna_dirac_flag ) { - 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 ) ) + IF( ( st->flag_cna == 0 ) && EQ_16( st->L_frame, L_FRAME16k ) && EQ_16( st->last_flag_cna, 1 ) && ( ( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->last_coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->Last_GSC_noisy_speech_flag ) ) ) || EQ_16( st->last_core, AMR_WB_CORE ) ) ) { - FOR( i = 0; i < st->hFdCngDec->hFdCngCom->frameSize / 2; i++ ) + FOR( i = 0; i < shr( st->hFdCngDec->hFdCngCom->frameSize, 1 ); i++ ) { - psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st->hFdCngDec->hFdCngCom->frameSize / 4], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); + psyn_fx[i] = add( psyn_fx[i], shr_r( mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth2[i + imult1616( 5, shr( st->hFdCngDec->hFdCngCom->frameSize, 2 ) )], st->hFdCngDec->hFdCngCom->fftlenFac ), -st->Q_syn ) ); move16(); } } - if ( st->flag_cna == 0 || ( st->coder_type == AUDIO && !( st->element_mode > EVS_MONO && st->GSC_noisy_speech ) ) ) + IF( ( st->flag_cna == 0 ) || ( EQ_16( st->coder_type, AUDIO ) && !( GT_16( st->element_mode, EVS_MONO ) && st->GSC_noisy_speech ) ) ) { - if ( st->idchan == 0 ) + IF( st->idchan == 0 ) { set_s( st->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st->hFdCngDec->hFdCngCom->fftlen ); } - if ( hStereoCng != NULL && st->idchan == 0 ) + IF( hStereoCng != NULL && ( st->idchan == 0 ) ) { set_s( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->fftlen ); } @@ -1496,14 +1646,14 @@ ivas_error acelp_core_dec_ivas_fx( *----------------------------------------------------------------*/ /* check if the CLDFB works on the right sample rate */ - if ( ( st->cldfbAna->no_channels * st->cldfbAna->no_col ) != st->L_frame ) + IF( NE_16( imult1616( st->cldfbAna->no_channels, st->cldfbAna->no_col ), st->L_frame ) ) { - resampleCldfb_ivas_fx( st->cldfbAna, st->L_frame * FRAMES_PER_SEC ); - resampleCldfb_ivas_fx( st->cldfbBPF, st->L_frame * FRAMES_PER_SEC ); + resampleCldfb_ivas_fx( st->cldfbAna, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); + resampleCldfb_ivas_fx( st->cldfbBPF, L_mult0( st->L_frame, FRAMES_PER_SEC ) ); - if ( st->ini_frame > 0 ) + IF( st->ini_frame > 0 ) { - st->cldfbSyn->bandsToZero = st->cldfbSyn->no_channels - st->cldfbAna->no_channels; + st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); } } @@ -1512,10 +1662,11 @@ ivas_error acelp_core_dec_ivas_fx( Word32 pitch_buf_fx_q20[12]; Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, Q4 ); - Word16 lim = st->L_frame / 64; - for ( Word16 lp = 0; lp < lim; lp++ ) + Word16 lim = shr( st->L_frame, 6 ); + FOR( Word16 lp = 0; lp < lim; lp++ ) { pitch_buf_fx_q20[lp] = L_shl( pitch_buf_fx[lp], Q14 ); + move32(); } bpf_pitch_coherence_ivas_fx( st, pitch_buf_fx_q20 ); Scale_sig32( st->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, -Q4 ); @@ -1543,8 +1694,8 @@ ivas_error acelp_core_dec_ivas_fx( Word32 syn_tmp_32_fx[L_FRAME16k + L_SUBFR], *syn_32_fx; set32_fx( syn_tmp_32_fx, 0, L_FRAME16k + L_SUBFR ); syn_32_fx = syn_tmp_32_fx + L_SUBFR; - - if ( st->element_mode != IVAS_CPE_DFT || use_cldfb_for_dft ) + test(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) || use_cldfb_for_dft ) { /* analysis of the synthesis at internal sampling rate */ Word32 realBufferSave_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; @@ -1573,37 +1724,38 @@ ivas_error acelp_core_dec_ivas_fx( for ( i = 0; i < L_FRAME16k; i++ ) #endif { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), 4 + st->Q_syn ); // Q12 + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); // Q12 + move32(); } Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 st->cldfbAna->Q_cldfb_state = Q12; - + move16(); cldfbAnalysis_ivas_fx( syn_32_fx, realBuffer_fx, imagBuffer_fx, -1, st->cldfbAna ); Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; - + move16(); /* analysis and add the BPF error signal */ Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; Word16 q_bpf_error_signal; Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); q_bpf_error_signal = Q6; - + move16(); #ifdef MSAN_FIX Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, st->L_frame, q_bpf_error_signal - st->Q_syn ); // Q6 #else Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn ); // Q6 #endif - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 } Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - + move16(); tmp = -1; move16(); IF( st->bpf_off ) @@ -1613,9 +1765,9 @@ ivas_error acelp_core_dec_ivas_fx( } addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( q_bpf_error_signal - Q10 ) ); // Q10 + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( sub( q_bpf_error_signal, Q10 ) ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; - + move16(); /* set output mask for upsampling */ IF( EQ_16( st->bwidth, NB ) ) { @@ -1627,58 +1779,67 @@ ivas_error acelp_core_dec_ivas_fx( /* in case of BW switching, re-init to default */ st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->cldfbAna->no_channels ); } - + test(); IF( !st->cng_sba_flag || EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { + test(); + test(); + test(); /*WB/SWB-FD_CNG*/ IF( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && ( EQ_16( st->cng_type, FD_CNG ) ) && ( LE_16( st->hFdCngDec->hFdCngCom->numCoreBands, st->cldfbSyn->no_channels ) ) ) { Word16 tmpBufferScale = 0; + move16(); generate_comfort_noise_dec_hf_ivas_fx( realBuffer_fx, imagBuffer_fx, /*realBuffer, imagBuffer,*/ &tmpBufferScale, st->hFdCngDec->hFdCngCom, st->cng_ism_flag ); /* Fixed to float */ FOR( i = 0; i < st->hFdCngDec->hFdCngCom->numSlots; i++ ) { - Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, st->hFdCngDec->hFdCngCom->regularStopBand - st->hFdCngDec->hFdCngCom->numCoreBands, ( tmpBufferScale + 15 ) - Q31 ); // Q0 - Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, st->hFdCngDec->hFdCngCom->regularStopBand - st->hFdCngDec->hFdCngCom->numCoreBands, ( tmpBufferScale + 15 ) - Q31 ); // Q0 + Scale_sig32( realBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 + Scale_sig32( imagBuffer_fx[i] + st->hFdCngDec->hFdCngCom->numCoreBands, sub( st->hFdCngDec->hFdCngCom->regularStopBand, st->hFdCngDec->hFdCngCom->numCoreBands ), sub( add( tmpBufferScale, 15 ), Q31 ) ); // Q0 } - IF( st->hFdCngDec->hFdCngCom->regularStopBand < st->cldfbSyn->no_channels ) + IF( LT_16( st->hFdCngDec->hFdCngCom->regularStopBand, st->cldfbSyn->no_channels ) ) { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, st->hFdCngDec->hFdCngCom->regularStopBand ); } ELSE { st->cldfbSyn->bandsToZero = 0; + move16(); } } } - if ( save_hb_synth_fx16 != NULL ) + IF( save_hb_synth_fx16 != NULL ) { /* save and then zero-out lowband */ Word16 Q_real = 0, Q_imag = 0; Word32 max_real = 0, max_imag = 0; - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + move16(); + move16(); + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); } } Word32 max_val = max( max_real, max_imag ); - Q_imag = norm_l( max_val ) - 3 /* Guard bits */; + Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; Q_real = Q_imag; - - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_imag ); } - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, ( Q_real - 1 ) - Q10 ); // (Q_real-1) + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // (Q_real-1) st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, Q_real - 1 ); + Scale_sig32( save_hb_synth_fx, L_FRAME48k, sub( Q_real, 1 ) ); FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { @@ -1686,20 +1847,24 @@ ivas_error acelp_core_dec_ivas_fx( { realBufferSave_fx[i][j] = realBuffer_fx[i][j]; imagBufferSave_fx[i][j] = imagBuffer_fx[i][j]; + move32(); + move32(); IF( j < st->hFdCngDec->hFdCngCom->numCoreBands && i < st->hFdCngDec->hFdCngCom->numSlots ) { realBuffer_fx[i][j] = 0; imagBuffer_fx[i][j] = 0; + move32(); + move32(); } } } cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, save_hb_synth_fx, -1, st->cldfbSynHB ); - Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( Q_real - 1 ) ); // Q0 - Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, Q10 - ( Q_real - 1 ) ); // Q10 + Scale_sig32( save_hb_synth_fx, L_FRAME48k, -( sub( Q_real, 1 ) ) ); // Q0 + Scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSynHB->Q_cldfb_state = Q10; - + move16(); /* restore lowband */ FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { @@ -1707,59 +1872,67 @@ ivas_error acelp_core_dec_ivas_fx( { realBuffer_fx[i][j] = realBufferSave_fx[i][j]; imagBuffer_fx[i][j] = imagBufferSave_fx[i][j]; + move32(); + move32(); } } - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q_real - 1 ) - Q10 ); // Q_real-1 + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); // Q_real-1 st->cldfbSynHB->Q_cldfb_state = sub( Q_real, 1 ); cldfbSynthesis_ivas_fx( pRealSave_fx, pImagSave_fx, synth_fx, -1, st->cldfbSyn ); - Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - ( Q_real - 1 ) ); // Q10 + Scale_sig32( synth_fx, L_FRAME48k, -sub( Q_real, 1 ) ); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); } - else + ELSE { /* synthesis of the combined signal */ Word16 Q_real = 0, Q_imag = 0; Word32 max_real = 0, max_imag = 0; - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + move16(); + move16(); + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); } } Word32 max_val = max( max_real, max_imag ); - Q_imag = norm_l( max_val ) - 3 /* Guard bits */; + Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; Q_real = Q_imag; - - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); } - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q_real - 1 ) - Q10 ); //(Q_real - 1) - st->cldfbSyn->Q_cldfb_state = Q_real - 1; + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) + st->cldfbSyn->Q_cldfb_state = sub( Q_real, 1 ); #ifndef MSAN_FIX Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); #endif cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx, -1, st->cldfbSyn ); #ifdef MSAN_FIX - scale_sig32( synth_fx, output_frame, -( Q_real - 1 ) ); + scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); #else Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - ( Q_real - 1 ) ); // Q10 + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); // Q10 st->cldfbSyn->Q_cldfb_state = Q10; + move16(); } /* save synthesis - needed in case of core switching */ Copy32( synth_fx, st->previoussynth_fx_32, output_frame ); // Q0 } - else + 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) */ + Word16 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) */ /* analysis of the synthesis at internal sampling rate - needed for DFT stereo -> TD stereo switching */ #ifndef MSAN_FIX @@ -1768,37 +1941,38 @@ ivas_error acelp_core_dec_ivas_fx( FOR( i = 0; i < st->L_frame; i++ ) #endif { - syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), 4 + st->Q_syn ); + syn_32_fx[i] = L_shr( L_deposit_h( psyn_fx[i] ), add( 4, st->Q_syn ) ); + move32(); } Word16 offset = sub( st->cldfbAna->p_filter_length, st->cldfbAna->no_channels ); Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, 1 ); // Q12 st->cldfbAna->Q_cldfb_state = Q12; + move16(); cldfbAnalysis_ivas_fx( syn_32_fx + st->L_frame - nSamples, realBuffer_fx, imagBuffer_fx, nSamples, st->cldfbAna ); Scale_sig32( st->cldfbAna->cldfb_state_fx, offset, -1 ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; - - /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ + move16(); /* analysis and add the BPF error signal - needed for DFT stereo -> TD stereo switching */ Word32 tmp_bpf_error_signal_fx[L_FRAME16k]; Word16 q_bpf_error_signal; Word16 cldfb_state_offset = sub( st->cldfbBPF->p_filter_length, st->cldfbBPF->no_channels ); // Get Q-factor q_bpf_error_signal = Q6; - - Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, q_bpf_error_signal - st->Q_syn ); // Q6 - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + move16(); + Copy_Scale_sig_16_32( bpf_error_signal_16fx, tmp_bpf_error_signal_fx, L_FRAME16k, sub( q_bpf_error_signal, st->Q_syn ) ); // Q6 + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { Scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 Scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, -Q7 ); // Q0 } - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, q_bpf_error_signal - Q10 ); // q_bpf_error_signal (Q6) + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, sub( q_bpf_error_signal, Q10 ) ); // q_bpf_error_signal (Q6) st->cldfbBPF->Q_cldfb_state = q_bpf_error_signal; - + move16(); tmp = 0; move16(); - IF( !st->bpf_off ) + if ( !st->bpf_off ) { tmp = nSamples; move16(); @@ -1806,29 +1980,33 @@ ivas_error acelp_core_dec_ivas_fx( addBassPostFilter_ivas_fx( tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF ); - Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -( q_bpf_error_signal - Q10 ) ); // Q10 + Scale_sig32( st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -sub( q_bpf_error_signal, Q10 ) ); // Q10 st->cldfbBPF->Q_cldfb_state = Q10; /* synthesis of the combined signal - needed for DFT stereo -> TD stereo switching */ Word16 Q_real = 0, Q_imag = 0; Word32 max_real = 0, max_imag = 0; - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + move16(); + move16(); + move32(); + move32(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { - for ( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) + FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { max_real = max( max_real, L_abs( realBuffer_fx[i][j] ) ); max_imag = max( max_imag, L_abs( imagBuffer_fx[i][j] ) ); } } Word32 max_val = max( max_real, max_imag ); - Q_imag = norm_l( max_val ) - 3 /* Guard bits */; + Q_imag = sub( norm_l( max_val ), 3 ) /* Guard bits */; Q_real = Q_imag; - - for ( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + move16(); + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) { scale_sig32( realBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); scale_sig32( imagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, Q_real ); } - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, ( Q_real - 1 ) - Q10 ); //(Q_real - 1) + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( sub( Q_real, 1 ), Q10 ) ); //(Q_real - 1) #ifndef MSAN_FIX Scale_sig32( synth_fx, L_FRAME48k, Q_real - 1 ); #endif @@ -1836,14 +2014,14 @@ ivas_error acelp_core_dec_ivas_fx( cldfbSynthesis_ivas_fx( realBuffer_fx, imagBuffer_fx, synth_fx /*dummy*/, NS2SA( st->output_Fs, FRAME_SIZE_NS /*DELAY_CLDFB_NS*/ ), st->cldfbSyn ); #ifdef MSAN_FIX - Scale_sig32( synth_fx, output_frame, -( Q_real - 1 ) ); + Scale_sig32( synth_fx, output_frame, -sub( Q_real, 1 ) ); #else Scale_sig32( synth_fx, L_FRAME48k, -( Q_real - 1 ) ); #endif - Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, Q10 - ( Q_real - 1 ) ); + Scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q10, sub( Q_real, 1 ) ) ); st->cldfbSyn->Q_cldfb_state = Q10; - - if ( st->p_bpf_noise_buf_32 ) + move16(); + IF( st->p_bpf_noise_buf_32 ) { Copy_Scale_sig_16_32( bpf_error_signal_16fx, bpf_error_signal_fx, st->L_frame, -1 ); // Q_syn-1 Copy32( bpf_error_signal_fx, st->p_bpf_noise_buf_32, st->L_frame ); @@ -1858,15 +2036,15 @@ ivas_error acelp_core_dec_ivas_fx( #ifndef MSAN_FIX Scale_sig( syn_tmp_fx, L_FRAME16k + L_SUBFR, -st->Q_syn ); #else - Scale_sig( syn_tmp_fx, st->L_frame + L_SUBFR, -st->Q_syn ); + Scale_sig( syn_tmp_fx, add( st->L_frame, L_SUBFR ), -st->Q_syn ); #endif - if ( st->element_mode > EVS_MONO ) + IF( GT_16( st->element_mode, EVS_MONO ) ) { Copy( psyn_fx, output_fx, st->L_frame ); } st->Q_syn2 = 0; - + move16(); /*-----------------------------------------------------------------* * Bandwidth extension 6kHz-7kHz *-----------------------------------------------------------------*/ @@ -1884,6 +2062,7 @@ ivas_error acelp_core_dec_ivas_fx( { #ifndef FIX_774_ENERGY_BURST Word16 tmp_exp = 0; + move16(); #endif #ifdef MSAN_FIX Copy_Scale_sig_32_16( synth_fx, synth_fx16, output_frame, 0 ); @@ -1908,10 +2087,11 @@ ivas_error acelp_core_dec_ivas_fx( IF( st->hBWE_FD != NULL ) { st->hBWE_FD->memExp1 = tmp_exp; + move16(); } ELSE { - Scale_sig( st->hBWE_zero->mem_hf_fx, L_FIR - 1, -tmp_exp ); + Scale_sig( st->hBWE_zero->mem_hf_fx, sub( L_FIR, 1 ), -tmp_exp ); } #endif } @@ -1928,24 +2108,40 @@ ivas_error acelp_core_dec_ivas_fx( * Populate parameters for SWB TBE *-----------------------------------------------------------------*/ - if ( st->hBWE_TD != NULL ) + IF( st->hBWE_TD != NULL ) { - if ( ( !st->bfi && st->prev_bfi ) || ( st->last_vbr_hw_BWE_disable_dec == 1 && st->vbr_hw_BWE_disable_dec == 0 ) || ( ( st->extl == SWB_TBE || st->extl == WB_TBE || st->extl == FB_TBE ) && st->last_extl != SWB_TBE && st->last_extl != WB_TBE && st->last_extl != FB_TBE ) || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && !st->tdm_LRTD_flag ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( !st->bfi && st->prev_bfi ) || ( EQ_16( st->last_vbr_hw_BWE_disable_dec, 1 ) && ( st->vbr_hw_BWE_disable_dec == 0 ) ) || ( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, WB_TBE ) && NE_16( st->last_extl, FB_TBE ) ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && !st->tdm_LRTD_flag ) ) { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); set_s( st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET ); } - - if ( !st->ppp_mode_dec && ( st->idchan == 0 || st->element_mode != IVAS_CPE_TD || ( st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) ) ) + test(); + test(); + test(); + test(); + test(); + IF( !st->ppp_mode_dec && ( EQ_16( st->idchan, 0 ) || NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) ) { Copy_Scale_sig_16_32( st->hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_fx, NL_BUFF_OFFSET, ( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); non_linearity_ivas_fx( bwe_exc_fx, bwe_exc_extended_fx + NL_BUFF_OFFSET, L_FRAME32k, &st->hBWE_TD->bwe_non_lin_prev_scale_fx, st->Q_exc, st->coder_type, voice_factors_fx, st->L_frame ); Copy_Scale_sig_32_16( bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -( 2 * st->Q_exc - ( st->prev_Q_bwe_exc - 16 ) ) ); } - - if ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) + test(); + IF( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); } } /*----------------------------------------------------------------------* @@ -1953,7 +2149,7 @@ ivas_error acelp_core_dec_ivas_fx( *----------------------------------------------------------------------*/ updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); - + test(); IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { /* update CNG parameters in active frames */ @@ -1965,7 +2161,7 @@ ivas_error acelp_core_dec_ivas_fx( /* Set 16k LSP flag for CNG buffer */ st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; move16(); - IF( NE_16( st->L_frame, L_FRAME ) ) + if ( NE_16( st->L_frame, L_FRAME ) ) { st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 1; move16(); @@ -1973,7 +2169,7 @@ ivas_error acelp_core_dec_ivas_fx( } { - if ( save_hb_synth_fx16 ) + IF( save_hb_synth_fx16 ) { Copy_Scale_sig_32_16( save_hb_synth_fx, save_hb_synth_fx16, L_FRAME48k, 0 ); } @@ -1985,6 +2181,7 @@ ivas_error acelp_core_dec_ivas_fx( if ( st->hFdCngDec ) { st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; + move16(); } } diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 586470bac..921e84976 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -495,32 +495,7 @@ void IMDCT( edxt( x, xn_buf + overlap / 2 + nz, L_frame, kernel_type, TRUE ); } v_multc( xn_buf + overlap / 2 + nz, (float) sqrt( (float) L_frame / NORM_MDCT_FACTOR ), tmp, L_frame ); -#ifndef IVAS_FLOAT_FIXED_UNIT_TESTING window_ola_ext( tmp, xn_buf, old_out, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, kernel_type ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( xn_buf, L_frame + ( L_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ), "xn_buf_float.txt", NULL ); - dbgwrite_txt( old_out, L_frame, "old_out_float.txt", NULL ); -#endif -#else - Word32 xn_buf_fx[1200] = { 0 }, tmp_fx[1200], old_out_fx[1200]; - for ( int i = 0; i < L_frame; i++ ) - { - old_out_fx[i] = old_out[i] * ( 1 << Q15 ); - tmp_fx[i] = tmp[i] * ( 1 << Q15 ); - } - - window_ola_ext_fx( tmp_fx, xn_buf_fx, old_out_fx, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, kernel_type ); - - for ( int i = 0; i < L_frame; i++ ) - { - old_out[i] = (float) old_out_fx[i] / ( 1 << Q15 ); - xn_buf[i] = (float) xn_buf_fx[i] / ( 1 << Q15 ); - } -#ifdef DUMPS_ENABLED - dbgwrite_txt( xn_buf, L_frame + ( L_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ), "xn_buf_fixed.txt", NULL ); - dbgwrite_txt( old_out, L_frame, "old_out_fixed.txt", NULL ); -#endif -#endif // IVAS_FLOAT_FIXED_UNIT_TESTING } else { diff --git a/lib_dec/igf_dec.c b/lib_dec/igf_dec.c index 2afd2cb8a..c6d72f5d8 100644 --- a/lib_dec/igf_dec.c +++ b/lib_dec/igf_dec.c @@ -1174,11 +1174,7 @@ void IGFDecApplyMono_flt( nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1; set_s( hIGFDec->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); -#ifndef IVAS_FLOAT_FIXED set_f( hIGFDec->virtualSpec_float, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift ); -#else - set_val_Word32( hIGFDec->virtualSpec, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); -#endif hPrivateData = &hIGFDec->igfData; hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; @@ -1276,13 +1272,8 @@ void IGFDecApplyStereo_flt( nShift = igfGridIdx == IGF_GRID_LB_SHORT ? 2 : 1; set_s( hIGFDecL->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); set_s( hIGFDecR->flag_sparse, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); -#ifndef IVAS_FLOAT_FIXED set_f( hIGFDecL->virtualSpec_float, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift ); set_f( hIGFDecR->virtualSpec_float, 0.f, ( N_MAX_TCX - IGF_START_MN ) / nShift ); -#else - set_val_Word32( hIGFDecL->virtualSpec, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); - set_val_Word32( hIGFDecR->virtualSpec, 0, ( N_MAX_TCX - IGF_START_MN ) / nShift ); -#endif hPrivateDataL = &hIGFDecL->igfData; hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx]; @@ -1428,13 +1419,7 @@ void IGFDecSetMode_flt( hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; hIGFDec->virtualSpec_float = &hIGFDec->virtualSpecBuf[0]; -#ifdef IVAS_FLOAT_FIXED - hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; -#endif hIGFDec->igfData.pSpecFlat_float = &hIGFDec->igfData.pSpecFlatBuf[0]; -#ifdef IVAS_FLOAT_FIXED - hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; -#endif hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; return; @@ -1496,9 +1481,6 @@ void IGFDecReplicateTCX10State_flt( mvs2s( &hIGFDec->infoTCXNoise_evs[( IGF_START_MX ) / 2], &hIGFDec->infoTCXNoise_evs[0], ( IGF_START_MX ) / 2 ); mvr2r( &hIGFDec->virtualSpecBuf[( N_MAX_TCX - IGF_START_MN ) / 2], &hIGFDec->virtualSpecBuf[0], ( N_MAX_TCX - IGF_START_MN ) / 2 ); mvr2r( &hIGFDec->igfData.pSpecFlatBuf[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf[0], IGF_START_MX / 2 ); -#ifdef IVAS_FLOAT_FIXED - Copy32( &hIGFDec->igfData.pSpecFlatBuf_fx[IGF_START_MX / 2], &hIGFDec->igfData.pSpecFlatBuf_fx[0], IGF_START_MX / 2 ); -#endif hIGFDec->igfData.igfInfo.nfSeedBuf[0] = hIGFDec->igfData.igfInfo.nfSeedBuf[1]; diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index 910469008..a00fa71ee 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -1927,7 +1927,7 @@ ivas_error ivas_binRenderer_open_fx( { FOR( k = 0; k < 11; k++ ) { - ivas_dirac_dec_get_response_fixed( (Word16) L_shr_r( ls_azimuth_CICP19_fx[k], 22 ), (Word16) L_shr_r( ls_elevation_CICP19_fx[k], 22 ), hBinRenderer->hReverb->foa_enc_fx[k], 1 ); + ivas_dirac_dec_get_response_fx( (Word16) L_shr_r( ls_azimuth_CICP19_fx[k], 22 ), (Word16) L_shr_r( ls_elevation_CICP19_fx[k], 22 ), hBinRenderer->hReverb->foa_enc_fx[k], 1, Q29 ); // Q29: hBinRenderer->hReverb->foa_enc_fx[k] } } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 5e18e1750..234fe1e11 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1965,7 +1965,7 @@ ivas_error ivas_init_decoder_fx( IF( st_ivas->nCPE > 1 ) { - IF( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } @@ -2127,7 +2127,7 @@ ivas_error ivas_init_decoder_fx( IF( st_ivas->nCPE > 1 ) { - IF( ( error = create_mct_dec( st_ivas ) ) != IVAS_ERR_OK ) + IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 982467cbe..1d3614c37 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1922,7 +1922,7 @@ void ivas_ism_dec_digest_tc_fx( /*get HOA gets for direction (ACN/SN3D)*/ Word16 azi = shr( extract_h( st_ivas->hIsmMetaData[i]->azimuth_fx ), 22 - 16 ); Word16 ele = shr( extract_h( st_ivas->hIsmMetaData[i]->elevation_fx ), 22 - 16 ); - ivas_dirac_dec_get_response_fx( azi, ele, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIntSetup.ambisonics_order ); + ivas_dirac_dec_get_response_fx( azi, ele, st_ivas->hIsmRendererData->gains_fx[i], st_ivas->hIntSetup.ambisonics_order, Q30 ); } } } diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 663af323d..f766a5b95 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -1104,7 +1104,7 @@ void ivas_omasa_separate_object_render_jbm_fx( } ELSE { - ivas_dirac_dec_get_response_fixed( azimuth, elevation, gains_fx, hDirACRend->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response_fx( azimuth, elevation, gains_fx, hDirACRend->hOutSetup.ambisonics_order, Q29 ); } FOR( j = 0; j < nchan_out_woLFE; j++ ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 4556baaf5..fa512cf9c 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -3167,17 +3167,6 @@ ivas_error ivas_jbm_dec_render_fx( scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer += tmp; } - test(); - IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) - { - test(); - IF( st_ivas->hCombinedOrientationData && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) - { - Word16 Q_hoa_encoder = 31; - move16(); - floatToFixed_arrL( st_ivas->hParamMC->hoa_encoder, st_ivas->hParamMC->hoa_encoder_fx, Q_hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); - } - } /* CLDFB synthesis */ FOR( Word16 ch = 0; ch < nchan_out_cldfb; ch++ ) { diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 2badc75fe..516080471 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -214,9 +214,6 @@ ivas_error ivas_param_mc_dec_open_fx( mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; hParamMC->hoa_encoder_fx = NULL; -#if 1 /*TODO: To be removed later(floating pointer initialization)*/ - hParamMC->hoa_encoder = NULL; -#endif /* determine the synthesis config */ if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD || st_ivas->transport_config == output_config ) @@ -491,12 +488,6 @@ ivas_error ivas_param_mc_dec_open_fx( /* Head or external rotation */ if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { -#if 1 /*TODO : To be removed later*/ - IF( ( hParamMC->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } -#endif IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -2246,13 +2237,6 @@ void ivas_param_mc_dec_close_fx( free( hParamMC->Cldfb_ImagBuffer_tc_fx ); hParamMC->Cldfb_ImagBuffer_tc_fx = NULL; } -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED /*TODO: To be removed later(Floating point memory dealloc)------------------------------- */ - IF( hParamMC->hoa_encoder != NULL ) - { - free( hParamMC->hoa_encoder ); - hParamMC->hoa_encoder = NULL; - } -#endif /***********************************ends here************************************************/ free( *hParamMC_out ); *hParamMC_out = NULL; diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index dec62f973..43dfffa4e 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -343,7 +343,6 @@ ivas_error ivas_mc_paramupmix_dec_open( } compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hMCParamUpmix->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); // compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hMCParamUpmix->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER ); - Scale_sig32( hMCParamUpmix->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS, Q2 ); // Q29=>Q31 } /* allocate transport channels*/ diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 3d115b9f4..3e11870eb 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -781,7 +781,7 @@ ivas_error create_mct_dec_fx( return IVAS_ERR_OK; } -#endif // IVAS_FLOAT_FIXED +#else // IVAS_FLOAT_FIXED ivas_error create_mct_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -873,18 +873,10 @@ ivas_error create_mct_dec( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } -#ifndef IVAS_FLOAT_FIXED initMdctStereoDecData( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); -#else - initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); -#endif hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; -#ifndef IVAS_FLOAT_FIXED hMCT->hBlockData[n]->hStereoMdct->smooth_ratio = 1.f; -#else - hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; -#endif } for ( ; n < MCT_MAX_BLOCKS; n++ ) { @@ -907,7 +899,7 @@ ivas_error create_mct_dec( return IVAS_ERR_OK; } - +#endif /*------------------------------------------------------------------------- * mct_dec_reconfigure() diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 6d87d5f81..86da344d9 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -249,11 +249,12 @@ void ivas_mc2sba_fx( azimuth = (Word16) L_shr( hIntSetup.ls_azimuth_fx[idx_in], 22 ); elevation = (Word16) L_shr( hIntSetup.ls_elevation_fx[idx_in], 22 ); idx_in++; - ivas_dirac_dec_get_response_fixed( + ivas_dirac_dec_get_response_fx( azimuth, elevation, gains_fx, /*Q-29*/ - sba_order ); + sba_order, + Q29 ); /* get HOA response for direction (ACN/SN3D)*/ FOR( j = 0; j < sba_num_chans; j++ ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index e8beec6d0..272cc4582 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -894,10 +894,10 @@ typedef struct ivas_param_mc_dec_data_structure HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params; HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state; #ifdef IVAS_FLOAT_FIXED - Word32 *hoa_encoder_fx; -#endif // IVAS_FLOAT_FIXED - + Word32 *hoa_encoder_fx; // Q31 +#else float *hoa_encoder; +#endif // IVAS_FLOAT_FIXED } PARAM_MC_DEC_DATA, *PARAM_MC_DEC_HANDLE; @@ -925,7 +925,7 @@ typedef struct ivas_mc_paramupmix_dec_data_structure Word16 *param_interpolator_fx; // Q15 Word32 alpha_sf_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 Word32 beta_sf_fx[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; // Q28 - Word32 *hoa_encoder_fx; + Word32 *hoa_encoder_fx; // Q31 #else float alphas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; float betas[MC_PARAMUPMIX_COMBINATIONS][IVAS_MAX_NUM_BANDS]; diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 2b979de69..11a38a393 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -792,8 +792,6 @@ ivas_error IVAS_DEC_FeedFrame_Serial( { fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); } - IF( hParamMC->hoa_encoder_fx ) - fixedToFloat_arrL( hParamMC->hoa_encoder_fx, hParamMC->hoa_encoder, Q29, hIvasDec->st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } #endif @@ -1218,8 +1216,6 @@ static ivas_error IVAS_DEC_Setup( fixedToFloat_arrL( hParamMC->diff_proto_info->proto_fac_fx[i], hParamMC->diff_proto_info->proto_fac[i], 26, hParamMC->diff_proto_info->num_source_chan_diff[i] ); } } - IF( hParamMC->hoa_encoder_fx ) - fixedToFloat_arrL( hParamMC->hoa_encoder_fx, hParamMC->hoa_encoder, Q29, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } @@ -1280,8 +1276,6 @@ static ivas_error IVAS_DEC_Setup( { fixedToFloat_arrL( st_ivas->hParamMC->diff_proto_info->proto_fac_fx[i], st_ivas->hParamMC->diff_proto_info->proto_fac[i], 26, st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[i] ); } - IF( st_ivas->hParamMC->hoa_encoder_fx ) - fixedToFloat_arrL( st_ivas->hParamMC->hoa_encoder_fx, st_ivas->hParamMC->hoa_encoder, Q29, st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS ); } } } diff --git a/lib_dec/tns_base_dec.c b/lib_dec/tns_base_dec.c index f23f4f6aa..0f88f4aca 100644 --- a/lib_dec/tns_base_dec.c +++ b/lib_dec/tns_base_dec.c @@ -42,7 +42,7 @@ #include "stat_com.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * ReadTnsData_ivas() * @@ -141,3 +141,4 @@ int16_t DecodeTnsData_ivas( return ( pTnsData->nFilters > 0 ) ? TRUE : FALSE; } +#endif diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index 922d0a252..a9b293e4e 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -53,7 +53,7 @@ /*******************************************************/ /*-------------- public functions -------------------- */ /*******************************************************/ - +#ifndef IVAS_FLOAT_FIXED ivas_error TonalMDCTConceal_Init_ivas( TonalMDCTConcealPtr hTonalMDCTConc, const uint16_t nSamples, @@ -126,7 +126,6 @@ ivas_error TonalMDCTConceal_Init_ivas( return IVAS_ERR_OK; } -#ifndef IVAS_FLOAT_FIXED void TonalMDCTConceal_SaveFreqSignal_ivas( TonalMDCTConcealPtr hTonalMDCTConc, const float *mdctSpectrum, @@ -1079,11 +1078,11 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( Word32 noise_shape_buffer[L_FRAME48k]; Word16 noise_shape_buffer_e[L_FRAME48k]; Word16 start_idx, stop_idx, noise_shape_buffer_common_exp = MIN16B_FLT_FX, last_scf_e, temp_e; + move16(); Word32 *cngNoiseLevelPtr; Word32 last_scf; Word16 c_e, c_inv_e; - move16(); push_wmops( "create_conc_noise" ); @@ -1119,7 +1118,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( move16(); IF( st->tonal_mdct_plc_active ) { - max_noise_line = s_max( max_noise_line, hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1 ); + max_noise_line = s_max( max_noise_line, extract_l( L_add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ) ) ); } /* first lost frame is handled separately */ @@ -1640,16 +1639,43 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( psychParams = st->hTonalMDCTConc->psychParams; hFdCngCom = st->hFdCngDec->hFdCngCom; - inc = ( ( EQ_32( whitening_mode, ON_FIRST_LOST_FRAME ) ? st->core : st->last_core ) > TCX_20_CORE ) ? 2 : 1; + IF( EQ_32( whitening_mode, ON_FIRST_LOST_FRAME ) ) + { + IF( GT_16( st->core, TCX_20_CORE ) ) + { + inc = 2; + move16(); + } + ELSE + { + inc = 1; + move16(); + } + } + ELSE + { + IF( GT_16( st->last_core, TCX_20_CORE ) ) + { + inc = 2; + move16(); + } + ELSE + { + inc = 1; + move16(); + } + } start_idx = shr( hFdCngCom->startBand, sub( inc, 1 ) ); stop_idx = shr( L_frame, sub( inc, 1 ) ); noiseLevelPtr = hFdCngCom->cngNoiseLevel; noiseLevelPtr_exp = hFdCngCom->cngNoiseLevelExp; + move16(); set32_fx( whitenend_noise_shape, 0, start_idx ); FOR( Word16 j = start_idx; j < stop_idx; j++ ) { whitenend_noise_shape[j] = *noiseLevelPtr; + move32(); noiseLevelPtr += inc; } @@ -1657,7 +1683,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( { Word32 scf[SNS_NPTS]; - sns_compute_scf_fx( whitenend_noise_shape, psychParams, L_frame, scf, ( 31 - noiseLevelPtr_exp ) ); + sns_compute_scf_fx( whitenend_noise_shape, psychParams, L_frame, scf, sub( 31, noiseLevelPtr_exp ) ); sns_interpolate_scalefactors_fx( scfs_int, scf, ENC ); sns_interpolate_scalefactors_fx( scfs_bg, scf, DEC ); @@ -1674,7 +1700,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( q_wns = sub( 31, noiseLevelPtr_exp ); sns_shape_spectrum_fx( whitenend_noise_shape, &q_wns, psychParams, scfs_for_shaping, Q16, L_frame ); - Copy32( whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel, stop_idx - start_idx ); + Copy32( whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel, sub( stop_idx, start_idx ) ); hFdCngCom->cngNoiseLevelExp = sub( 30, q_wns ); } ELSE diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index f64ef3a7b..a41fd48f5 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -84,10 +84,7 @@ ivas_error TonalMDCTConceal_Init( hTonalMDCTConc->secondLastBlockData.blockIsConcealed = 0; move16(); - // hTonalMDCTConc->pTCI_fix = (TonalComponentsInfo_fix *)hTonalMDCTConc->timeDataBuffer; move16(); - - hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); IF( NE_16( hTonalMDCTConc->nSamples, nSamples ) ) @@ -122,14 +119,12 @@ ivas_error TonalMDCTConceal_Init( move16(); move16(); /* just the second half of the second last pcm output is needed */ - hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, 3 * ( s_min( L_FRAME_MAX, nSamples ) ) / 2 )]; + hTonalMDCTConc->secondLastPcmOut = &hTonalMDCTConc->timeDataBuffer[sub( ( 3 * L_FRAME_MAX ) / 2, shr( imult1616( 3, ( s_min( L_FRAME_MAX, nSamples ) ) ), 1 ) )]; 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 */ -#if 1 - // TO do enable when only fix code is present currently disabled due to float array in structure - // assert(sizeof(*hTonalMDCTConc->pTCI) <= (hTonalMDCTConc->lastPcmOut-hTonalMDCTConc->timeDataBuffer)*sizeof(hTonalMDCTConc->timeDataBuffer[0])); -#endif + assert( sizeof( *hTonalMDCTConc->pTCI ) <= ( hTonalMDCTConc->lastPcmOut - hTonalMDCTConc->timeDataBuffer ) * sizeof( hTonalMDCTConc->timeDataBuffer[0] ) ); + return IVAS_ERR_OK; } ivas_error TonalMDCTConceal_Init_ivas_fx( @@ -193,8 +188,6 @@ ivas_error TonalMDCTConceal_Init_ivas_fx( move16(); hTonalMDCTConc->pTCI = (TonalComponentsInfo *) hTonalMDCTConc->timeDataBuffer; - // hTonalMDCTConc->pTCI = &hTonalMDCTConc->pTCI1; - move16(); hTonalMDCTConc->lastPitchLag = L_deposit_l( 0 ); @@ -498,6 +491,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( { /* Store new data */ hTonalMDCTConc->last_block_nrg = 0; + move32(); FOR( i = 0; i < infoIGFStartLine; i++ ) { @@ -505,12 +499,13 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( hTonalMDCTConc->last_block_nrg = L_add( hTonalMDCTConc->last_block_nrg, L_shr( L_mult0( tmp, tmp ), 16 ) ); } - hTonalMDCTConc->last_block_nrg_exp = 31 - ( ( 15 - mdctSpectrum_exp ) * 2 - 16 ); + hTonalMDCTConc->last_block_nrg_exp = sub( 31, sub( shl( sub( 15, mdctSpectrum_exp ), 1 ), 16 ) ); /* Store new data */ s = getScaleFactor32( mdctSpectrum, nNewSamples ); max_exp = 0; + move16(); FOR( i = 0; i < hTonalMDCTConc->nScaleFactors; i++ ) { hTonalMDCTConc->lastBlockData.scaleFactors_exp[i] = scaleFactors_exp[i]; @@ -520,6 +515,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( /*s = sub(s, max_exp);*/ hTonalMDCTConc->lastBlockData.scaleFactors_max_e = max_exp; + move16(); FOR( i = 0; i < nNewSamples; i++ ) { @@ -529,6 +525,7 @@ void TonalMDCTConceal_SaveFreqSignal_ivas_fx( hTonalMDCTConc->lastBlockData.spectralData_exp = sub( mdctSpectrum_exp, s ); move16(); + move16(); hTonalMDCTConc->lastBlockData.gain_tcx_exp = gain_tcx_exp; Copy( scaleFactors, hTonalMDCTConc->lastBlockData.scaleFactors, hTonalMDCTConc->nScaleFactors ); } @@ -651,6 +648,7 @@ static void FindPhaseDifferences( /* o if ( s_and( k, 1 ) != 0 ) { phaseDiff[i] = -12868 /*-EVS_PI 3Q12*/; + move16(); } } ELSE @@ -662,6 +660,7 @@ static void FindPhaseDifferences( /* o if ( s_and( k, 1 ) != 0 ) { phaseDiff[i] = 0 /*0 Q13*/; /*2Q13*/ + move16(); } } ELSE @@ -683,6 +682,7 @@ static void FindPhaseDifferences( /* o { L_tmp = L_shl( L_tmp, sfn ); sfn = 0; + move16(); } a = L_sub( m, L_tmp ); /*sf*/ @@ -697,13 +697,13 @@ static void FindPhaseDifferences( /* o ELSE { sfd = 0; + move16(); L_tmp = L_shl( L_tmp, sf ); } L_tmp = L_add( n, L_tmp ); fractional = BASOP_util_atan2( a, L_tmp, sub( sfn, sfd ) ); /*2Q13*/ L_tmp = L_mult( fractional, 28672 /*BANDWIDTH/2.0f Q13*/ ); /*2Q13*2Q13=4Q27*/ - move16(); /* fractional is in the range 0..+pi */ /* we need to stay in the range -2pi..+2pi */ @@ -739,22 +739,21 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( Word16 nSamples; Word16 i; Word16 floorPowerSpectrum; /* Minimum significant value of a spectral line in the power spectrum */ -#ifdef MSAN_FIX - Word32 powerSpectrum[L_FRAME_MAX] = { 0 }; -#else Word32 powerSpectrum[L_FRAME_MAX]; -#endif Word16 invScaleFactors[FDNS_NPTS]; Word16 invScaleFactors_exp[FDNS_NPTS]; Word16 powerSpectrum_exp, tmp_exp, old_exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif // Word16 nBands; Word32 invScaleFactors_fx[FDNS_NPTS]; Word16 old_power_spectrum_q, power_spectrum_q; + set32_fx( powerSpectrum, 0, L_FRAME_MAX ); + nSamples = hTonalMDCTConc->nNonZeroSamples; move16(); @@ -783,22 +782,6 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( set32_fx( powerSpectrum + hTonalMDCTConc->nSamples, 0, sub( hTonalMDCTConc->nSamplesCore, hTonalMDCTConc->nSamples ) ); } - // DetectTonalComponents(hTonalMDCTConc->pTCI->indexOfTonalPeak, - // hTonalMDCTConc->pTCI->lowerIndex, - // hTonalMDCTConc->pTCI->upperIndex, - // &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, - // floorPowerSpectrum); - ivas_DetectTonalComponents_fx( (Word16 *) hTonalMDCTConc->pTCI->indexOfTonalPeak, (Word16 *) hTonalMDCTConc->pTCI->lowerIndex, (Word16 *) hTonalMDCTConc->pTCI->upperIndex, @@ -820,15 +803,16 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( IF( hTonalMDCTConc->pTCI->numIndexes > 0 ) { - hTonalMDCTConc->secondLastPowerSpectrum = hTonalMDCTConc->secondLastBlockData.spectralData; /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; + move16(); powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ FOR( i = 0; i < nSamples; i++ ) { tmp_exp = old_exp; + move16(); powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); move32(); @@ -842,9 +826,9 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( invScaleFactors[i] = Inv16( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &invScaleFactors_exp[i] ); } - - power_spectrum_q = 31 - powerSpectrum_exp; + power_spectrum_q = sub( 31, powerSpectrum_exp ); old_power_spectrum_q = power_spectrum_q; + move16(); /* here mdct_shaping() is intentionally used rather then mdct_shaping_16() */ IF( psychParamsCurrent == NULL ) { @@ -854,22 +838,25 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( { FOR( i = 0; i < FDNS_NPTS; i++ ) { - invScaleFactors_fx[i] = L_shl( invScaleFactors[i], 1 + invScaleFactors_exp[i] ); // Q16 + invScaleFactors_fx[i] = L_shl( invScaleFactors[i], add( 1, invScaleFactors_exp[i] ) ); // Q16 + move32(); } sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore ); - power_spectrum_q++; + power_spectrum_q = add( power_spectrum_q, 1 ); // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); // nBands = psychParamsCurrent->nBands; } - IF( old_power_spectrum_q < power_spectrum_q ) - Scale_sig32( powerSpectrum, hTonalMDCTConc->nSamplesCore, old_power_spectrum_q - power_spectrum_q ); + IF( LT_16( old_power_spectrum_q, power_spectrum_q ) ) + { + Scale_sig32( powerSpectrum, hTonalMDCTConc->nSamplesCore, sub( old_power_spectrum_q, power_spectrum_q ) ); + } ELSE { - Scale_sig32( powerSpectrum + hTonalMDCTConc->nSamplesCore, nSamples - hTonalMDCTConc->nSamplesCore, power_spectrum_q - old_power_spectrum_q ); - powerSpectrum_exp = 31 - power_spectrum_q; + Scale_sig32( powerSpectrum + hTonalMDCTConc->nSamplesCore, sub( nSamples, hTonalMDCTConc->nSamplesCore ), sub( power_spectrum_q, old_power_spectrum_q ) ); + powerSpectrum_exp = sub( 31, power_spectrum_q ); } Scale_sig32( powerSpectrum, nSamples, -3 ); /*Adding guard bits*/ - powerSpectrum_exp += 3; + powerSpectrum_exp = add( powerSpectrum_exp, 3 ); 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] ); @@ -884,6 +871,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif + move32(); } powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); @@ -916,6 +904,7 @@ static void CalcPowerSpecAndDetectTonalComponents( Word16 powerSpectrum_exp, tmp_exp, old_exp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif @@ -973,10 +962,12 @@ static void CalcPowerSpecAndDetectTonalComponents( /*sqrtFLOAT(powerSpectrum, powerSpectrum, nSamples);*/ old_exp = powerSpectrum_exp; + move16(); powerSpectrum_exp = mult_r( sub( powerSpectrum_exp, 2 ), 1 << 14 ); /*remove 2 bits of headroom from CalcPowerSpec*/ FOR( i = 0; i < nSamples; i++ ) { tmp_exp = old_exp; + move16(); powerSpectrum[i] = Sqrt32( powerSpectrum[i], &tmp_exp ); powerSpectrum[i] = L_shr( powerSpectrum[i], sub( powerSpectrum_exp, tmp_exp ) ); move32(); @@ -1024,6 +1015,7 @@ static void CalcPowerSpecAndDetectTonalComponents( #else hTonalMDCTConc->secondLastPowerSpectrum[i] = round_fx( powerSpectrum[i] ); #endif + move32(); } powerSpectrum_exp = sub( powerSpectrum_exp, hTonalMDCTConc->secondLastBlockData.gain_tcx_exp ); @@ -1083,7 +1075,9 @@ void TonalMDCTConceal_Detect( nSamples = hTonalMDCTConc->nSamples; move16(); secondLastMDST_exp = 16; /*time signal Q-1*/ + move16(); secondLastMDCT_exp = 16; /*time signal Q-1*/ + move16(); test(); test(); test(); @@ -1100,6 +1094,7 @@ void TonalMDCTConceal_Detect( CalcMDXT( hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp ); CalcMDXT( hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp ); hTonalMDCTConc->nNonZeroSamples = 0; + move16(); FOR( i = 0; i < hTonalMDCTConc->nSamples; i++ ) { if ( hTonalMDCTConc->secondLastBlockData.spectralData[i] != 0 ) @@ -1220,7 +1215,9 @@ void TonalMDCTConceal_Detect_ivas_fx( nSamples = hTonalMDCTConc->nSamples; move16(); secondLastMDST_exp = 16; /*time signal Q-1*/ + move16(); secondLastMDCT_exp = 16; /*time signal Q-1*/ + move16(); test(); test(); test(); @@ -1237,6 +1234,7 @@ void TonalMDCTConceal_Detect_ivas_fx( CalcMDXT( hTonalMDCTConc, 0, hTonalMDCTConc->secondLastPcmOut, secondLastMDST, &secondLastMDST_exp ); CalcMDXT( hTonalMDCTConc, 1, hTonalMDCTConc->secondLastPcmOut, secondLastMDCT, &secondLastMDCT_exp ); hTonalMDCTConc->nNonZeroSamples = 0; + move16(); FOR( i = 0; i < hTonalMDCTConc->nSamples; i++ ) { if ( hTonalMDCTConc->secondLastBlockData.spectralData[i] != 0 ) @@ -1270,7 +1268,6 @@ void TonalMDCTConceal_Detect_ivas_fx( } secondLastMDCT_exp = sub( secondLastMDCT_exp, s ); move16(); - // CalcPowerSpecAndDetectTonalComponents(hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag); ivas_CalcPowerSpecAndDetectTonalComponents_fx( hTonalMDCTConc, secondLastMDST, secondLastMDST_exp, secondLastMDCT, secondLastMDCT_exp, pitchLag, psychParamsCurrent, element_mode ); } ELSE @@ -1287,14 +1284,13 @@ void TonalMDCTConceal_Detect_ivas_fx( } ELSE { - // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, hTonalMDCTConc->secondLastBlockData.scaleFactors, hTonalMDCTConc->nSamplesCore); Word16 power_spectrum_q; FOR( i = 0; i < FDNS_NPTS; i++ ) { - sns_int_scf_fx[i] = L_shl( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], 1 + hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ); // Q16 + sns_int_scf_fx[i] = L_shl( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], add( 1, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); // Q16 + move32(); } sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, sns_int_scf_fx, 16, hTonalMDCTConc->nSamplesCore ); - // nBands = psychParamsCurrent->nBands; } powerSpectrum_exp = getScaleFactor32( powerSpectrum, nSamples ); powerSpectrum_exp = sub( powerSpectrum_exp, 3 ); /*extra 3 bits of headroom for MA filter in getEnvelope*/ @@ -1365,7 +1361,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word16 last_block_nrg_correct_e; crossfadeGain = crossfadeGain_const; - + move16(); push_wmops( "InsertNoise" ); g = sub( MAX16B, crossfadeGain ); @@ -1373,10 +1369,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { rnd = 1977; + move16(); } ELSE { rnd = *pSeed; + move16(); } /* based on what is done in tcx_noise_filling() */ @@ -1384,6 +1382,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( hTonalMDCTConc->faded_signal_nrg = L_deposit_h( 0 ); L_tmp = 805306368l /*0.375f Q31*/; + move32(); inv_exp = 15; move16(); inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); @@ -1401,8 +1400,10 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( nrgWhiteNoise = L_deposit_h( 0 ); last_block_nrg_correct = L_deposit_h( 0 ); last_block_nrg_correct_e = 0; - + move16(); exp_last = exp_noise = 0; + move16(); + move16(); IF( !hTonalMDCTConc->lastBlockData.blockIsValid ) { @@ -1421,19 +1422,23 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( GT_32( concealment_noise[i], 0 ) ) { mdctSpectrum[i] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ); + move32(); } ELSE { mdctSpectrum[i] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[i] ), 16 ) ); + move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + move32(); } *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); } /* actual fadeout is done in this case */ ELSE @@ -1442,7 +1447,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word16 exp_num, exp_den; exp_num = cngLevelBackgroundTrace_bfi_e; + move16(); exp_den = hTonalMDCTConc->curr_noise_nrg_exp; + move16(); ld = norm_l( cngLevelBackgroundTrace_bfi ); num = L_shl( cngLevelBackgroundTrace_bfi, ld ); @@ -1481,16 +1488,20 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { exp = 0; + move16(); } FOR( i = 0; i < crossOverFreq; i++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + move16(); Word32 y = concealment_noise[i]; + move32(); IF( GT_16( g, 0 ) ) { @@ -1537,14 +1548,16 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( LT_16( l, crossOverFreq ) ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y = concealment_noise[l]; + move32(); last_block_nrg_correct = L_add( last_block_nrg_correct, Mpy_32_16_1( L_msu( 0, x, fac ), x ) ); // exp = 2 * x_exp + ld y = L_negate( Mpy_32_32( y, y ) ); hTonalMDCTConc->curr_noise_nrg = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->curr_noise_nrg, hTonalMDCTConc->curr_noise_nrg_exp, y, 2 * concealment_noise_e, &hTonalMDCTConc->curr_noise_nrg_exp ); } } } - last_block_nrg_correct_e = hTonalMDCTConc->lastBlockData.spectralData_exp * 2 + ld; + last_block_nrg_correct_e = add( shl( hTonalMDCTConc->lastBlockData.spectralData_exp, 1 ), ld ); /* if fadeout has not started yet, only apply sign scrambling */ IF( GE_16( crossfadeGain, CROSSFADE_THRESHOLD ) ) @@ -1554,10 +1567,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( GT_32( concealment_noise[l], 0 ) ) { mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + move32(); } ELSE { mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + move32(); } } FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) @@ -1567,10 +1582,12 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( GT_32( concealment_noise[l], 0 ) ) { mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + move32(); } ELSE { mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + move32(); } } } @@ -1580,19 +1597,23 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( GT_32( concealment_noise[l], 0 ) ) { mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + move32(); } ELSE { mdctSpectrum[l] = L_negate( L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ) ); + move32(); } } FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { mdctSpectrum[l] = L_shl( L_deposit_l( hTonalMDCTConc->lastBlockData.spectralData[l] ), 16 ); + move32(); } *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); } /* actual fadeout is done in this case */ ELSE @@ -1601,7 +1622,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Word16 exp_num, exp_den; exp_num = cngLevelBackgroundTrace_bfi_e; + move16(); exp_den = hTonalMDCTConc->curr_noise_nrg_exp; + move16(); ld = norm_l( cngLevelBackgroundTrace_bfi ); num = L_shl( cngLevelBackgroundTrace_bfi, ld ); @@ -1628,6 +1651,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { g = shr( g, exp ); *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); } ELSE { @@ -1640,16 +1664,20 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { exp = 0; + move16(); } FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y = concealment_noise[l]; + move32(); IF( GT_16( g, 0 ) ) { @@ -1672,7 +1700,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y = concealment_noise[l]; + move32(); L_tmp = Mpy_32_16_1( y, g ); L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); @@ -1681,6 +1711,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } mdctSpectrum[l] = L_shl( L_tmp2, exp ); + move32(); hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); } @@ -1689,7 +1720,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1] + 1; l < crossOverFreq; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y = concealment_noise[l]; + move32(); L_tmp = Mpy_32_16_1( y, g ); L_tmp2 = L_msu( L_tmp, crossfadeGain, x ); @@ -1698,6 +1731,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( L_tmp2 = L_mac( L_tmp, crossfadeGain, x ); } mdctSpectrum[l] = L_shl( L_tmp2, exp ); + move32(); hTonalMDCTConc->faded_signal_nrg = L_add( hTonalMDCTConc->faded_signal_nrg, Mpy_32_32( mdctSpectrum[l], mdctSpectrum[l] ) ); } @@ -1705,6 +1739,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( l = crossOverFreq; l < hTonalMDCTConc->lastBlockData.nSamples; l++ ) { mdctSpectrum[l] = L_deposit_h( 0 ); + move32(); } hTonalMDCTConc->faded_signal_nrg_exp = shl( *mdctSpectrum_exp, 1 ); @@ -1715,7 +1750,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( Flag flag; flag = EQ_16( hTonalMDCTConc->curr_noise_nrg_exp, 0 ) && GT_32( hTonalMDCTConc->curr_noise_nrg, MDCT_ST_PLC_FADEOUT_MIN_NOISE_NRG_Q31 ); flag = flag || GT_16( hTonalMDCTConc->curr_noise_nrg_exp, 0 ); - + test(); IF( GT_32( hTonalMDCTConc->faded_signal_nrg, 0 ) && flag ) { Word16 num_exp, den_exp; @@ -1724,7 +1759,9 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( num = BASOP_Util_Add_Mant32Exp( hTonalMDCTConc->last_block_nrg, hTonalMDCTConc->last_block_nrg_exp, L_negate( last_block_nrg_correct ), last_block_nrg_correct_e, &num_exp ); den = hTonalMDCTConc->faded_signal_nrg; + move32(); den_exp = hTonalMDCTConc->faded_signal_nrg_exp; + move16(); ld = norm_l( num ); num = L_shl( num, ld ); @@ -1747,6 +1784,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( FOR( i = 0; i < crossOverFreq; i++ ) { mdctSpectrum[i] = Mpy_32_16_1( mdctSpectrum[i], tmp ); + move32(); } *mdctSpectrum_exp = add( *mdctSpectrum_exp, exp ); } @@ -1777,6 +1815,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { set32_fx( mdctSpectrum, 0, crossOverFreq ); *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { @@ -1794,7 +1833,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( exp = sub( exp_last, exp_noise ); - IF( nrgNoiseInLastFrame > nrgWhiteNoise ) + IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); exp = add( exp, 1 ); @@ -1811,6 +1850,7 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( { g = shr( g, exp ); *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); } ELSE { @@ -1823,18 +1863,22 @@ void TonalMDCTConceal_InsertNoise_ivas_fx( IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { exp = 0; + move16(); } } FOR( i = 0; i < crossOverFreq; i++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; + move16(); Word32 const y = mdctSpectrum[i]; + move32(); - IF( GT_16( g, 0 ) ) + IF( g > 0 ) { L_tmp = Mpy_32_16_1( y, g ); } @@ -1868,6 +1912,7 @@ ELSE FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y; rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); @@ -1885,17 +1930,19 @@ ELSE FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { - 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 = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[i - 1], hTonalMDCTConc->pTCI->lowerIndex[i - 1] ), 1 ) ), 15, &exp ) ); tmp = shl( tmp, exp ); tilt = mult_r( tilt, tmp ); // Q15 FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); + move32(); } FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y; rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); @@ -1913,7 +1960,7 @@ ELSE } 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 ) ); + L_deposit_h( extract_l( L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ), 1 ) ) ), 15, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB tmp = shl_sat( tmp, exp ); @@ -1926,6 +1973,7 @@ ELSE FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y; rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); y = L_mult( tilt, rnd ); @@ -1944,6 +1992,7 @@ ELSE { set32_fx( mdctSpectrum, 0, crossOverFreq ); *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { @@ -1959,7 +2008,7 @@ ELSE exp = sub( exp_last, exp_noise ); - IF( nrgNoiseInLastFrame > nrgWhiteNoise ) + IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); exp = add( exp, 1 ); @@ -1975,6 +2024,7 @@ ELSE { g = shr( g, exp ); *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); } ELSE { @@ -1987,16 +2037,20 @@ ELSE IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { exp = 0; + move16(); } FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 const y = mdctSpectrum[l]; + move32(); IF( GT_16( g, 0 ) ) { @@ -2017,7 +2071,9 @@ ELSE FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 const y = mdctSpectrum[l]; + move32(); IF( GT_16( g, 0 ) ) { @@ -2043,13 +2099,16 @@ ELSE FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); + move32(); } } FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 const y = mdctSpectrum[l]; + move32(); IF( GT_16( g, 0 ) ) { @@ -2075,6 +2134,7 @@ ELSE } *pSeed = rnd; +move16(); pop_wmops(); @@ -2128,6 +2188,7 @@ void TonalMDCTConceal_InsertNoise( /* may just become active if the very first frame is lost */ set32_fx( mdctSpectrum, 0, hTonalMDCTConc->nSamples ); *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT else if ( concealment_noise != NULL ) @@ -2323,6 +2384,7 @@ void TonalMDCTConceal_InsertNoise( { #ifndef IVAS_CODE_CNG_FIX185_PLC_FADEOUT L_tmp = 805306368l /*0.375f Q31*/; + move32(); inv_exp = 15; move16(); inv_samples = Inv16( hTonalMDCTConc->lastBlockData.nSamples, &inv_exp ); @@ -2352,6 +2414,7 @@ void TonalMDCTConceal_InsertNoise( FOR( i = 0; i < crossOverFreq; i++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[i]; + move16(); Word32 y; rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); y = L_mult( tilt, rnd ); @@ -2370,6 +2433,7 @@ void TonalMDCTConceal_InsertNoise( { set32_fx( mdctSpectrum, 0, crossOverFreq ); *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { @@ -2387,7 +2451,7 @@ void TonalMDCTConceal_InsertNoise( exp = sub( exp_last, exp_noise ); - IF( nrgNoiseInLastFrame > nrgWhiteNoise ) + IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); exp = add( exp, 1 ); @@ -2404,6 +2468,7 @@ void TonalMDCTConceal_InsertNoise( { g = shr( g, exp ); *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); } ELSE { @@ -2416,17 +2481,21 @@ void TonalMDCTConceal_InsertNoise( IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { exp = 0; + move16(); } } FOR( i = 0; i < crossOverFreq; i++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[i]; + move16(); Word32 const y = mdctSpectrum[i]; + move32(); if ( g > 0 ) { @@ -2457,6 +2526,7 @@ void TonalMDCTConceal_InsertNoise( FOR( l = hTonalMDCTConc->pTCI->lowerIndex[0]; l <= hTonalMDCTConc->pTCI->upperIndex[0]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); + move32(); } ld = sub( 14, norm_s( hTonalMDCTConc->lastBlockData.nSamples ) ); @@ -2464,6 +2534,7 @@ void TonalMDCTConceal_InsertNoise( FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y; rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); y = L_mult( tilt, rnd ); @@ -2481,18 +2552,20 @@ void TonalMDCTConceal_InsertNoise( FOR( i = 1; i < hTonalMDCTConc->pTCI->numIndexes; i++ ) { /*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 = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[i - 1], hTonalMDCTConc->pTCI->lowerIndex[i - 1] ), 1 ) ), 15, &exp ) ); tmp = shl( tmp, exp ); tilt = mult_r( tilt, tmp ); FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); + move32(); } FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y; rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); y = L_mult( tilt, rnd ); @@ -2508,7 +2581,7 @@ void TonalMDCTConceal_InsertNoise( } } - 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 ) ); + tmp = round_fx( BASOP_Util_fPow( L_deposit_h( tiltFactor ), 0, L_deposit_h( (UWord16) L_add( L_sub( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], hTonalMDCTConc->pTCI->lowerIndex[hTonalMDCTConc->pTCI->numIndexes - 1] ), 1 ) ), 15, &exp ) ); BASOP_SATURATE_WARNING_OFF_EVS /*next op may result in 32768*/ #ifdef BASOP_NOGLOB tmp = shl_sat( tmp, exp ); @@ -2521,6 +2594,7 @@ void TonalMDCTConceal_InsertNoise( FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 y; rnd = extract_l( L_mac0( 13849, rnd, 31821 ) ); y = L_mult( tilt, rnd ); @@ -2539,6 +2613,7 @@ void TonalMDCTConceal_InsertNoise( { set32_fx( mdctSpectrum, 0, crossOverFreq ); *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { @@ -2554,7 +2629,7 @@ void TonalMDCTConceal_InsertNoise( exp = sub( exp_last, exp_noise ); - IF( nrgNoiseInLastFrame > nrgWhiteNoise ) + IF( GT_32( nrgNoiseInLastFrame, nrgWhiteNoise ) ) { nrgNoiseInLastFrame = L_shr( nrgNoiseInLastFrame, 1 ); exp = add( exp, 1 ); @@ -2570,6 +2645,7 @@ void TonalMDCTConceal_InsertNoise( { g = shr( g, exp ); *mdctSpectrum_exp = hTonalMDCTConc->lastBlockData.spectralData_exp; + move16(); } ELSE { @@ -2583,16 +2659,20 @@ void TonalMDCTConceal_InsertNoise( IF( exp < 0 ) { *mdctSpectrum_exp = SPEC_EXP_DEC; + move16(); } ELSE { exp = 0; + move16(); } FOR( l = 0; l < hTonalMDCTConc->pTCI->lowerIndex[0]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 const y = mdctSpectrum[l]; + move32(); if ( g > 0 ) { @@ -2613,7 +2693,9 @@ void TonalMDCTConceal_InsertNoise( FOR( l = hTonalMDCTConc->pTCI->upperIndex[i - 1] + 1; l < hTonalMDCTConc->pTCI->lowerIndex[i]; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 const y = mdctSpectrum[l]; + move32(); if ( g > 0 ) { @@ -2639,13 +2721,16 @@ void TonalMDCTConceal_InsertNoise( FOR( l = hTonalMDCTConc->pTCI->lowerIndex[i]; l <= hTonalMDCTConc->pTCI->upperIndex[i]; l++ ) { mdctSpectrum[l] = L_deposit_l( 0 ); + move32(); } } FOR( l = add( hTonalMDCTConc->pTCI->upperIndex[hTonalMDCTConc->pTCI->numIndexes - 1], 1 ); l < crossOverFreq; l++ ) { Word16 const x = hTonalMDCTConc->lastBlockData.spectralData[l]; + move16(); Word32 const y = mdctSpectrum[l]; + move32(); if ( g > 0 ) { @@ -2692,7 +2777,7 @@ void TonalMDCTConceal_Apply( Word16 nSamples; - IF( hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid ) + IF( s_and( hTonalMDCTConc->lastBlockData.blockIsValid, hTonalMDCTConc->secondLastBlockData.blockIsValid ) ) { assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); @@ -2767,6 +2852,7 @@ void TonalMDCTConceal_Apply( mdctSpectrum[l] = Mpy_32_16_1( powerSpectrum[l], getCosWord16( extract_l( currentPhase ) ) ); move32(); mdctSpectrum[l] = L_shr( mdctSpectrum[l], exp ); + move32(); } } } @@ -2796,6 +2882,7 @@ void TonalMDCTConceal_Apply_ivas_fx( Word16 *tmp_secondLastPowerSpectrum = hTonalMDCTConc->secondLastPowerSpectrum; Word16 tmp_secondLastPowerSpectrum_exp = hTonalMDCTConc->secondLastPowerSpectrum_exp; + move16(); Word16 max_nSamples = s_max( hTonalMDCTConc->nNonZeroSamples, hTonalMDCTConc->nSamplesCore ); @@ -2806,9 +2893,10 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( i = 0; i < FDNS_NPTS; i++ ) { scaleFactors[i] = L_shr( L_deposit_h( hTonalMDCTConc->secondLastBlockData.scaleFactors[i] ), sub( hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); + move32(); } - IF( hTonalMDCTConc->lastBlockData.blockIsValid & hTonalMDCTConc->secondLastBlockData.blockIsValid ) + IF( s_and( hTonalMDCTConc->lastBlockData.blockIsValid, hTonalMDCTConc->secondLastBlockData.blockIsValid ) ) { assert( hTonalMDCTConc->pTCI->numIndexes > 0 ); @@ -2825,6 +2913,7 @@ void TonalMDCTConceal_Apply_ivas_fx( move16(); Word16 exp1 = powerSpectrum_exp; + move16(); IF( psychParamsCurrent == NULL ) { @@ -2844,6 +2933,7 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( Word16 c = 0; c < hTonalMDCTConc->nSamplesCore; c++ ) { powerSpectrum[c] = L_shr( powerSpectrum[c], 1 ); + move32(); } /* adding guard bit */ @@ -2851,6 +2941,7 @@ void TonalMDCTConceal_Apply_ivas_fx( FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) { scaleFactors[c] = L_shr( scaleFactors[c], 1 ); + move32(); } sns_shape_spectrum_fx( powerSpectrum, &q_ps, psychParamsCurrent, scaleFactors, q_sf, hTonalMDCTConc->nSamplesCore ); @@ -2862,11 +2953,14 @@ void TonalMDCTConceal_Apply_ivas_fx( } Word16 exp_left = powerSpectrum_exp; + move16(); Word16 exp_right = exp1; + move16(); FOR( Word16 c = hTonalMDCTConc->nSamplesCore; c < nSamples; c++ ) { powerSpectrum[c] = Mpy_32_16_1( powerSpectrum[c], hTonalMDCTConc->secondLastBlockData.scaleFactors[nBands - 1] ); + move32(); } exp_right = add( exp_right, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[nBands - 1] ); @@ -2896,12 +2990,12 @@ void TonalMDCTConceal_Apply_ivas_fx( IF( !hTonalMDCTConc->lastBlockData.blockIsConcealed ) { - IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0 ) + if ( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive != 0 ) { hTonalMDCTConc->nFramesLost = add( hTonalMDCTConc->nFramesLost, 2 ); /*Q1*/ move16(); } - IF( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) + if ( hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive == 0 ) { hTonalMDCTConc->nFramesLost = 3; /*Q1*/ move16(); diff --git a/lib_dec/transition_dec.c b/lib_dec/transition_dec.c index c417947d7..a219d8882 100644 --- a/lib_dec/transition_dec.c +++ b/lib_dec/transition_dec.c @@ -41,7 +41,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*----------------------------------------------------------------------* * Local function prototypes *----------------------------------------------------------------------*/ @@ -764,3 +764,4 @@ int16_t tc_classif( return ( tc_subfr ); } +#endif diff --git a/lib_dec/transition_dec_fx.c b/lib_dec/transition_dec_fx.c index 7cd782036..46bb39bf9 100644 --- a/lib_dec/transition_dec_fx.c +++ b/lib_dec/transition_dec_fx.c @@ -61,14 +61,15 @@ void transition_dec_fx( (void) ( Opt_AMR_WB ); #endif - i_subfridx = shr( i_subfr, 6 ); /*i_subfr / L_SUBFR*/ + i_subfridx = i_subfr / L_SUBFR; /*i_subfr / L_SUBFR*/ /* Set limit_flag to 0 for restrained limits, and 1 for extended limits */ limit_flag = 0; - + move16(); /*---------------------------------------------------------------------* * zero adaptive contribution (glottal shape codebook search not * in first subframe(s) ) *---------------------------------------------------------------------*/ + test(); IF( GT_16( tc_subfr, add( i_subfr, TC_0_192 ) ) ) { set16_fx( &exc[i_subfr], 0, L_SUBFR ); @@ -219,7 +220,7 @@ void transition_dec_fx( 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]; + bwe_exc[add( i, i_subfr * HIBND_ACB_L_FAC )] = bwe_exc[sub( add( i, i_subfr * HIBND_ACB_L_FAC ), offset )]; move16(); } } @@ -248,7 +249,7 @@ void transition_dec_fx( 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]; + bwe_exc[add( i, i_subfr * HIBND_ACB_L_FAC )] = bwe_exc[sub( add( i, i_subfr * HIBND_ACB_L_FAC ), offset )]; move16(); } } @@ -299,7 +300,7 @@ void transition_dec_fx( } /* biterror detection mechanism */ - IF( GT_16( add( ( *T0 << 2 ), *T0_frac ), add( ( PIT_MAX << 2 ), 2 ) ) ) + IF( GT_16( add( shl( *T0, 2 ), *T0_frac ), add( ( PIT_MAX << 2 ), 2 ) ) ) { *T0 = L_SUBFR; move16(); @@ -316,7 +317,8 @@ void transition_dec_fx( move16(); /* penality for 2 ptrs initialization */ 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]; + bwe_exc[add( i, i_subfr * HIBND_ACB_L_FAC )] = bwe_exc[sub( add( i, i_subfr * HIBND_ACB_L_FAC ), offset )]; + move16(); } } ELSE IF( ( EQ_16( i_subfr, 3 * L_SUBFR ) ) && ( EQ_16( tc_subfr, TC_0_128 ) ) ) @@ -337,7 +339,7 @@ void transition_dec_fx( move16(); /* penality for 2 ptrs initialization */ 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]; + bwe_exc[add( i, i_subfr * HIBND_ACB_L_FAC )] = bwe_exc[sub( add( i, i_subfr * HIBND_ACB_L_FAC ), offset )]; move16(); } } @@ -358,7 +360,7 @@ void transition_dec_fx( move16(); /* penality for 2 ptrs initialization */ 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]; + bwe_exc[add( i, i_subfr * HIBND_ACB_L_FAC )] = bwe_exc[sub( add( i, i_subfr * HIBND_ACB_L_FAC ), offset )]; move16(); } } @@ -455,7 +457,6 @@ void transition_dec_fx( } ELSE /* L_frame == L_FRAME16k */ { - test(); if ( GE_16( i_subfr, 2 * L_SUBFR ) ) { limit_flag = 1; @@ -512,7 +513,7 @@ void transition_dec_fx( } /* biterror detection mechanism */ - IF( GT_16( add( ( *T0 << 2 ), *T0_frac ), ( ( 2 * L_SUBFR ) << 2 ) ) ) + IF( GT_16( add( shl( *T0, 2 ), *T0_frac ), ( ( 2 * L_SUBFR ) << 2 ) ) ) { *T0 = L_SUBFR; move16(); @@ -554,7 +555,7 @@ void transition_dec_fx( { /* bwe_exc[i + i_subfr * 2] = bwe_exc[i + i_subfr * 2 - *T0 * 2 */ /* - (int) ((float) *T0_frac * 0.5f + 4 + 0.5f) + 4];*/ - bwe_exc[i + i_subfr * 2] = bwe_exc[i + i_subfr * 2 - offset]; + bwe_exc[add( i, i_subfr * 2 )] = bwe_exc[sub( add( i, i_subfr * 2 ), offset )]; } lp_filt_exc_dec_fx( st_fx, MODE1, i_subfr, L_SUBFR, L_frame, st_fx->acelp_cfg.ltf_mode, exc ); @@ -638,6 +639,7 @@ static void tc_dec_fx( Word16 index; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif /*----------------------------------------------------------------* * find the number of bits @@ -661,7 +663,7 @@ static void tc_dec_fx( *T0_frac = 0; move16(); } - ELSE IF( ( tc_subfr == 3 * L_SUBFR ) ) + ELSE IF( EQ_16( tc_subfr, 3 * L_SUBFR ) ) { i = (Word16) get_next_indice( st_fx, nBits ); @@ -756,6 +758,7 @@ static void tc_dec_fx( if ( imp_sign == 0 ) { gain_trans = negate( gain_trans ); + move16(); } /* local max for scaling need */ @@ -781,7 +784,7 @@ static void tc_dec_fx( move16(); /* penalty for exc + i_subfr initialisation */ FOR( i = 0; i < j; i++ ) { - exc[i + i_subfr] = 0; + exc[add( i, i_subfr )] = 0; move16(); } j = s_min( L_SUBFR, add( imp_pos, L_IMPULSE2 ) ); @@ -792,6 +795,7 @@ static void tc_dec_fx( #else exc[i + i_subfr] = round_fx( L_shl( L_mult( pt_shape[i], gain_trans ), sc ) ); /* (Qx * Q14 ) */ #endif + move16(); } FOR( ; i < L_SUBFR; i++ ) { @@ -836,7 +840,7 @@ Word16 tc_classif_fx( #endif IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - if ( get_next_indice( st_fx, 1 ) ) + IF( get_next_indice( st_fx, 1 ) ) { tc_subfr = TC_0_0; move16(); diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index fb846b91a..a92130a62 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -36,6 +36,7 @@ void updt_dec_fx( /* update old excitation buffer */ Copy( &old_exc_fx[st_fx->L_frame], st_fx->old_exc_fx, L_EXC_MEM_DEC ); + test(); IF( !st_fx->Opt_AMR_WB && hBWE_TD != NULL ) { Copy( &old_bwe_exc_fx[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 ); @@ -47,6 +48,7 @@ void updt_dec_fx( /* update last coding type */ st_fx->last_coder_type = st_fx->coder_type; + move16(); test(); test(); test(); @@ -55,11 +57,11 @@ void updt_dec_fx( st_fx->last_coder_type = UNVOICED; move16(); } - test(); - test(); IF( st_fx->hGSCDec != NULL ) { - IF( ( NE_16( st_fx->coder_type, AUDIO ) || st_fx->Last_GSC_noisy_speech_flag != 0 ) && st_fx->hGSCDec->Last_GSC_pit_band_idx > 0 ) + test(); + test(); + if ( ( NE_16( st_fx->coder_type, AUDIO ) || st_fx->Last_GSC_noisy_speech_flag != 0 ) && st_fx->hGSCDec->Last_GSC_pit_band_idx > 0 ) { st_fx->hGSCDec->Last_GSC_pit_band_idx = 0; move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ @@ -100,7 +102,8 @@ void updt_dec_fx( } } test(); - IF( st_fx->hGSCDec != NULL && st_fx->coder_type != AUDIO && st_fx->coder_type != INACTIVE ) + test(); + IF( st_fx->hGSCDec != NULL && NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) ) { st_fx->hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); @@ -131,7 +134,7 @@ void updt_dec_fx( 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[st_fx->L_frame / L_SUBFR + 2], st_fx->L_frame / L_SUBFR ); + Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[add( st_fx->L_frame / L_SUBFR, 2 )], st_fx->L_frame / L_SUBFR ); IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { st_fx->mem_pitch_gain[2] = gain_buf[3]; @@ -189,7 +192,7 @@ void updt_dec_fx( move16(); /*core switching updates*/ - Copy( &Aq[( st_fx->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st_fx->old_Aq_12_8_fx, M + 1 ); + Copy( &Aq[imult1616( sub( st_fx->L_frame / L_SUBFR, 1 ), ( M + 1 ) )], st_fx->old_Aq_12_8_fx, M + 1 ); st_fx->old_Es_pred_fx = Es_pred; move16(); @@ -233,13 +236,13 @@ void updt_IO_switch_dec_fx( } /* reset TD BWE buffers */ 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( 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 ); @@ -249,7 +252,9 @@ void updt_IO_switch_dec_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 ); hBWE_TD->prev_pow_exc16kWhtnd_fx32 = 1; /*Q0 1.f*/ - hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + move32(); + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + move16(); swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); } @@ -259,12 +264,13 @@ void updt_IO_switch_dec_fx( move16(); 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( 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(); } - move16(); IF( hBWE_FD != NULL ) { @@ -286,11 +292,11 @@ void updt_IO_switch_dec_fx( set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP ); /* reset the unvoiced/audio signal improvement memories */ - IF( st_fx->hGSCDec != NULL ) + if ( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->seed_tcx = 15687; + move16(); } - move16(); st_fx->hAmrwb_IO->UV_cnt_fx = 30; st_fx->hAmrwb_IO->LT_UV_cnt_fx = ( 60 << 6 ); @@ -340,9 +346,10 @@ void updt_IO_switch_dec_fx( move16(); /* reset the unvoiced/audio signal improvement memories */ - IF( st_fx->hGSCDec != NULL ) + if ( st_fx->hGSCDec != NULL ) { st_fx->hGSCDec->seed_tcx = 15687; + move16(); } Copy( st_fx->hAmrwb_IO->lt_diff_etot_fx, tmp_buf, MAX_LT ); @@ -393,7 +400,7 @@ void updt_bw_switching_fx( const Word16 Qpost ) { test(); - IF( st_fx->output_Fs == 32000 && st_fx->bwidth == SWB ) + IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) ) { #ifdef BASOP_NOGLOB st_fx->tilt_swb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ), 3 ) ); @@ -465,6 +472,7 @@ void updt_dec_common_fx( move16(); st_fx->prev_old_bfi = st_fx->prev_bfi; + move16(); st_fx->prev_bfi = st_fx->bfi; move16(); if ( NE_16( st_fx->core, AMR_WB_CORE ) ) @@ -506,21 +514,24 @@ void updt_dec_common_fx( IF( st_fx->use_partial_copy ) { st_fx->prev_rf_frame_type = st_fx->rf_frame_type; + move16(); } ELSE { st_fx->prev_rf_frame_type = INACTIVE; + move16(); } - if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 1 || st_fx->use_partial_copy != 0 ) ) + if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( NE_16( st_fx->bfi, 1 ) || st_fx->use_partial_copy != 0 ) ) { st_fx->rf_flag_last = st_fx->rf_flag; + move16(); } IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { test(); - if ( !st_fx->bfi && ( st_fx->core_brate > SID_2k40 || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) ) + if ( !st_fx->bfi && ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) ) { move16(); st_fx->last_active_brate = st_fx->total_brate; @@ -607,10 +618,12 @@ void updt_dec_common_fx( IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { st_fx->last_nelp_mode_dec = 1; + move16(); } ELSE { st_fx->last_nelp_mode_dec = 0; + move16(); } } @@ -633,10 +646,12 @@ void updt_dec_common_fx( IF( EQ_16( st_fx->core, HQ_CORE ) ) { st_fx->prev_coder_type = GENERIC; + move16(); } ELSE IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->prev_coder_type = st_fx->coder_type; + move16(); } test(); @@ -673,8 +688,6 @@ void updt_dec_common_fx( } /* update bandwidth switching parameters */ - test(); - test(); st_fx->last_flag_cna = st_fx->flag_cna; move16(); if ( st_fx->hFdCngDec != NULL ) @@ -686,8 +699,10 @@ void updt_dec_common_fx( if ( GT_16( st_fx->element_mode, EVS_MONO ) ) { st_fx->m_old_frame_type = st_fx->m_frame_type; + move16(); } - + test(); + test(); /* update bandwidth switching parameters */ IF( EQ_16( st_fx->core, AMR_WB_CORE ) ) { @@ -716,6 +731,8 @@ void updt_dec_common_fx( /* synchronisation of CNG seeds*/ test(); test(); + test(); + test(); IF( st_fx->hTdCngDec != NULL && ( st_fx->bfi || ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, SID_2k40 ) ) ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { Random( &( st_fx->hTdCngDec->cng_seed ) ); @@ -733,11 +750,12 @@ void updt_dec_common_fx( st_fx->last_total_brate_ber = st_fx->total_brate; move32(); - if ( st_fx->bfi == 0 ) + IF( st_fx->bfi == 0 ) { st_fx->last_total_brate = st_fx->total_brate; st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal; move32(); + move32(); } st_fx->last_low_rate_mode = st_fx->low_rate_mode; move16(); @@ -757,7 +775,7 @@ static void ivas_updt_bw_switching_fx( const Word16 Qpost ) { test(); - IF( st_fx->output_Fs == 32000 && st_fx->bwidth == SWB ) + IF( EQ_32( st_fx->output_Fs, 32000 ) && EQ_16( st_fx->bwidth, SWB ) ) { #ifdef BASOP_NOGLOB st_fx->tilt_swb_fx = ivas_calc_tilt_bwe_fx( synth, Qpost, L_FRAME32k ); @@ -778,7 +796,7 @@ static void ivas_updt_bw_switching_fx( st_fx->last_inner_frame = L_FRAME32k; move16(); test(); - IF( EQ_16( st_fx->bwidth, WB ) && EQ_16( st_fx->bws_cnt, 0 ) ) + if ( EQ_16( st_fx->bwidth, WB ) && ( st_fx->bws_cnt == 0 ) ) { st_fx->last_inner_frame = L_FRAME16k; move16(); @@ -834,6 +852,7 @@ void ivas_updt_dec_common_fx( move16(); st_fx->prev_old_bfi = st_fx->prev_bfi; + move16(); st_fx->prev_bfi = st_fx->bfi; move16(); IF( NE_16( st_fx->core, AMR_WB_CORE ) ) @@ -850,6 +869,7 @@ void ivas_updt_dec_common_fx( IF( st_fx->hHQ_nbfec != NULL ) { st_fx->hHQ_nbfec->prev_last_core = st_fx->last_core; + move16(); } IF( st_fx->hTcxDec != NULL ) @@ -859,6 +879,8 @@ void ivas_updt_dec_common_fx( } test(); test(); + 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 ) || !st_fx->bfi ) { test(); @@ -866,7 +888,7 @@ void ivas_updt_dec_common_fx( test(); test(); - IF( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL ) + if ( st_fx->bfi && ( LE_16( st_fx->last_good, UNVOICED_TRANSITION ) ) && ( GT_16( st_fx->clas_dec, UNVOICED_TRANSITION ) ) && st_fx->last_con_tcx && st_fx->hTcxDec != NULL ) { hTcxDec->tcxConceal_recalc_exc = 1; move16(); @@ -877,21 +899,27 @@ void ivas_updt_dec_common_fx( IF( st_fx->use_partial_copy ) { st_fx->prev_rf_frame_type = st_fx->rf_frame_type; + move16(); } ELSE { st_fx->prev_rf_frame_type = INACTIVE; + move16(); } - - IF( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 0 || st_fx->use_partial_copy != 0 ) ) + test(); + test(); + if ( EQ_16( st_fx->m_frame_type, ACTIVE_FRAME ) && ( st_fx->bfi != 0 || st_fx->use_partial_copy != 0 ) ) { st_fx->rf_flag_last = st_fx->rf_flag; + move16(); } IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { test(); - IF( !st_fx->bfi && ( st_fx->core_brate > SID_2k40 || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) ) + test(); + test(); + if ( !st_fx->bfi && ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) ) { move16(); st_fx->last_active_brate = st_fx->total_brate; @@ -907,25 +935,26 @@ void ivas_updt_dec_common_fx( if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->last_hq_core_type = hq_core_type_fx; + move16(); } } ELSE IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { test(); - IF( ( !st_fx->bfi ) && ( st_fx->last_is_cng == 0 ) ) + if ( ( !st_fx->bfi ) && ( st_fx->last_is_cng == 0 ) ) { move16(); st_fx->last_active_brate = st_fx->total_brate; } /* INFO: moved from update_decoder_LPD_cng() */ - IF( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) + if ( NE_16( st_fx->m_frame_type, ACTIVE_FRAME ) ) { move16(); st_fx->last_is_cng = 1; } - IF( !st_fx->bfi ) + if ( !st_fx->bfi ) { st_fx->last_core = st_fx->core; } @@ -962,19 +991,21 @@ void ivas_updt_dec_common_fx( st->stab_fac_smooth_lt = ENV_SMOOTH_FAC * st->stab_fac + ( 1.0f - ENV_SMOOTH_FAC ) * st->stab_fac_smooth_lt; } #else - if ( st_fx->element_mode != EVS_MONO ) + IF( st_fx->element_mode != EVS_MONO ) { Word16 q_div = sub( Q31, shl( Qpostd, 1 ) ); - Word16 output_frame = NS2SA( st_fx->output_Fs, FRAME_SIZE_NS ); + Word16 output_frame = NS2SA_fx2( st_fx->output_Fs, FRAME_SIZE_NS ); + move16(); Word32 sum_val = sum_32_32_fx( synth, output_frame ); Word32 div_val = BASOP_Util_Divide3232_Scale( sum_val, output_frame, &q_div ); Word32 log_energy = L_add( L_shl( L_deposit_l( add( q_div, sub( Q31, shl( Qpostd, 1 ) ) ) ), Q15 ), L_shr( BASOP_Util_Log2( L_shl( L_add( div_val, EPSILON_FX ), Q16 ) ), Q10 ) ); Word32 log_energy_diff = L_abs( L_sub( st_fx->log_energy_old_fx, log_energy ) ); st_fx->log_energy_old_fx = log_energy; + move32(); st_fx->log_energy_diff_lt_fx = Madd_32_16( Mpy_32_16_1( log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub( MAX_16, ENV_SMOOTH_FAC_FX ) ); - if ( st_fx->core == HQ_CORE ) + IF( EQ_16( st_fx->core, HQ_CORE ) ) { st_fx->stab_fac_fx = extract_l( L_min( MAX_16, L_add( L_shr( STAB_FAC_EST1_FX, Q15 ), Madd_32_32( L_shr( Mpy_32_16_1( STAB_FAC_EST2_FX, st_fx->hHQ_core->mem_env_delta ), Q15 ), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx ) ) ) ); st_fx->stab_fac_fx = s_max( 0, st_fx->stab_fac_fx ); @@ -983,12 +1014,16 @@ void ivas_updt_dec_common_fx( L_mult( sub( MAX_16, ENV_SMOOTH_FAC_FX ), st_fx->stab_fac_smooth_lt_fx ) ) ); } #endif + + test(); + test(); + test(); #ifdef NON_BE_1055_RESET_LP_MEMORIES - IF( ( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && ( EQ_16( st_fx->codec_mode, MODE2 ) || GT_16( st_fx->element_mode, EVS_MONO ) ) ) ) + test(); + IF( ( LE_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && ( EQ_16( st_fx->codec_mode, MODE2 ) || ( st_fx->element_mode > EVS_MONO ) ) ) ) #else IF( ( ( LE_32( st_fx->core_brate, SID_2k40 ) ) && EQ_16( st_fx->cng_type, FD_CNG ) ) || ( st_fx->tcxonly && EQ_16( st_fx->codec_mode, MODE2 ) ) ) #endif - { /* reset LP memories */ set16_fx( st_fx->mem_MA_fx, 0, M ); @@ -1007,10 +1042,12 @@ void ivas_updt_dec_common_fx( IF( EQ_16( st_fx->use_partial_copy, 1 ) && EQ_16( st_fx->rf_frame_type, RF_NELP ) ) { st_fx->last_nelp_mode_dec = 1; + move16(); } ELSE { st_fx->last_nelp_mode_dec = 0; + move16(); } } @@ -1033,17 +1070,22 @@ void ivas_updt_dec_common_fx( IF( EQ_16( st_fx->core, HQ_CORE ) ) { st_fx->prev_coder_type = GENERIC; + move16(); } ELSE IF( NE_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->prev_coder_type = st_fx->coder_type; + move16(); } + test(); + test(); + test(); test(); IF( ( GT_32( st_fx->core_brate, SID_2k40 ) || ( GT_32( st_fx->core_brate, SID_1k75 ) && EQ_16( st_fx->core, AMR_WB_CORE ) ) ) && EQ_16( st_fx->first_CNG, 1 ) && st_fx->hTdCngDec != NULL ) { - IF( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) + if ( GE_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) { st_fx->hTdCngDec->act_cnt = 0; move16(); @@ -1053,20 +1095,19 @@ void ivas_updt_dec_common_fx( test(); - IF( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) ) + if ( ( EQ_16( st_fx->hTdCngDec->act_cnt, BUF_DEC_RATE ) ) && ( st_fx->hTdCngDec->ho_hist_size > 0 ) ) { st_fx->hTdCngDec->ho_hist_size = sub( st_fx->hTdCngDec->ho_hist_size, 1 ); } - // st_fx->hTdCngDec->act_cnt2 = add(st_fx->hTdCngDec->act_cnt2, 1); - - IF( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) + if ( GE_16( st_fx->hTdCngDec->act_cnt2, MIN_ACT_CNG_UPD ) ) { st_fx->hTdCngDec->act_cnt2 = MIN_ACT_CNG_UPD; move16(); } } + test(); test(); test(); if ( LE_32( st_fx->core_brate, SID_2k40 ) && st_fx->first_CNG == 0 && ( EQ_16( st_fx->cng_type, LP_CNG ) || EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) ) ) @@ -1086,12 +1127,15 @@ void ivas_updt_dec_common_fx( move16(); } - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode > EVS_MONO ) { st_fx->m_old_frame_type = st_fx->m_frame_type; + move16(); } /* update bandwidth switching parameters */ + test(); + test(); IF( EQ_16( st_fx->core, AMR_WB_CORE ) ) { st_fx->last_bwidth = WB; @@ -1119,6 +1163,8 @@ void ivas_updt_dec_common_fx( /* synchronisation of CNG seeds*/ test(); test(); + test(); + test(); IF( st_fx->hTdCngDec != NULL && ( st_fx->bfi || ( NE_32( st_fx->core_brate, FRAME_NO_DATA ) && NE_32( st_fx->core_brate, SID_2k40 ) ) ) && NE_16( st_fx->core, AMR_WB_CORE ) ) { Random( &( st_fx->hTdCngDec->cng_seed ) ); @@ -1136,11 +1182,12 @@ void ivas_updt_dec_common_fx( st_fx->last_total_brate_ber = st_fx->total_brate; move32(); - if ( st_fx->bfi == 0 ) + IF( st_fx->bfi == 0 ) { st_fx->last_total_brate = st_fx->total_brate; st_fx->last_bits_frame_nominal = st_fx->bits_frame_nominal; move32(); + move32(); } st_fx->last_low_rate_mode = st_fx->low_rate_mode; move16(); @@ -1206,12 +1253,14 @@ void update_decoder_LPD_cng( Copy( st->syn, synth_buf, 1 + M ); Copy( timeDomainBuffer, synth, st->L_frame ); Copy( synth + st->L_frame - ( 1 + M ), st->syn, 1 + M ); - Copy( hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len - st->L_frame ); - Copy( synth, hTcxDec->old_synth + hTcxDec->old_synth_len - st->L_frame, st->L_frame ); - bufferCopyFx( synth + st->L_frame - ( st->L_frame / 2 ), hTcxDec->old_syn_Overl, st->L_frame / 2, 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); + Copy( hTcxDec->old_synth + st->L_frame, hTcxDec->old_synth, sub( hTcxDec->old_synth_len, st->L_frame ) ); + Copy( synth, hTcxDec->old_synth + sub( hTcxDec->old_synth_len, st->L_frame ), st->L_frame ); + bufferCopyFx( synth + sub( st->L_frame, ( st->L_frame / 2 ) ), hTcxDec->old_syn_Overl, st->L_frame / 2, 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); hTcxDec->tcxltp_last_gain_unmodified = 0; + move16(); hTcxDec->envWeighted = 0; + move16(); } /* Update pe-synth memory */ @@ -1219,7 +1268,9 @@ void update_decoder_LPD_cng( tmp = synth[-( 1 + M )]; st->Q_syn = E_UTIL_f_preemph3( synth - M, st->preemph_fac, M + st->L_frame, &tmp, 1 ); - st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; + st->prev_Q_syn = st->Q_syn = sub( st->Q_syn, 1 ); + move16(); + move16(); Copy( synth + st->L_frame - M, st->mem_syn2_fx, M ); Copy( synth + st->L_frame - L_SYN_MEM, st->mem_syn_r, L_SYN_MEM ); @@ -1229,9 +1280,9 @@ void update_decoder_LPD_cng( { Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, sub( add( st->Q_syn, 1 ), st->Q_exc ) ); } - st->Q_exc = st->Q_syn + 1; + st->Q_exc = add( st->Q_syn, 1 ); Copy( st->old_exc_fx + st->L_frame, st->old_exc_fx, sub( L_EXC_MEM_DEC, st->L_frame ) ); - Residu3_fx( A, synth, st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, 1 ); + Residu3_fx( A, synth, st->old_exc_fx + sub( L_EXC_MEM_DEC, st->L_frame ), st->L_frame, 1 ); /* Update LPC-related memories */ @@ -1267,7 +1318,7 @@ void update_decoder_LPD_cng( /* Reset TCX overlap */ move16(); move16(); - if ( st->hTcxCfg != NULL ) + IF( st->hTcxCfg != NULL ) { st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; } diff --git a/lib_dec/vlpc_1st_dec.c b/lib_dec/vlpc_1st_dec.c index 6472bd385..be759eb61 100644 --- a/lib_dec/vlpc_1st_dec.c +++ b/lib_dec/vlpc_1st_dec.c @@ -40,7 +40,7 @@ #include "prot.h" #include "rom_com.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------* * vlpc_1st_dec_flt() * @@ -66,3 +66,4 @@ void vlpc_1st_dec_flt( return; } +#endif diff --git a/lib_dec/vlpc_2st_dec.c b/lib_dec/vlpc_2st_dec.c index ac22f990a..fdb29ebe6 100644 --- a/lib_dec/vlpc_2st_dec.c +++ b/lib_dec/vlpc_2st_dec.c @@ -38,13 +38,12 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------* * vlpc_2st_dec_flt() * * *------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void vlpc_2st_dec_flt( float *lsfq, /* i/o: i:1st stage o:1st+2nd stage */ int16_t *indx, /* i : index[] (4 bits per words) */ diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index 7629ab2c2..df4d8e53e 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -51,18 +51,22 @@ void vlpc_2st_dec( IF( EQ_32( sr_core, 16000 ) ) { gap = 102; + move16(); } ELSE IF( EQ_32( sr_core, 25600 ) ) { gap = 64; + move16(); } ELSE IF( EQ_32( sr_core, 32000 ) ) { gap = 51; + move16(); } ELSE { gap = 34; + move16(); } reorder_lsf_fx( lsfq, gap, M, INT_FS_FX ); diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index 2095a7694..e31032d4c 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -52,6 +52,9 @@ ivas_error ppp_voiced_decoder_fx( { Word16 k, delta_lag_D = 0, temp, Ql, Qh, diff; Word16 upper_cut_off_freq_of_interest = 0, upper_cut_off_freq = 0; + move16(); + move16(); + move16(); Word16 pl, l, n, rem_fx; Word16 temp_l_fx, temp_pl_fx, interp_delay_fx[3]; Word32 logLag, Ltemp_q, Ltemp, rem32, temp32_fx, tempnH_fx; @@ -73,16 +76,17 @@ ivas_error ppp_voiced_decoder_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); - IF( ( error = DTFS_new_fx( &TMPDTFS_FX ) ) != IVAS_ERR_OK ) + IF( NE_32( ( 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 ) + IF( NE_32( ( 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 ) + IF( NE_32( ( error = DTFS_new_fx( &dtfs_temp_fx ) ), IVAS_ERR_OK ) ) { IVAS_ERROR( error, "Error creating DTFS structure" ); } @@ -104,6 +108,7 @@ ivas_error ppp_voiced_decoder_fx( } temp_Fs = 8000; + move16(); if ( EQ_16( st_fx->bwidth, WB ) ) { @@ -168,7 +173,6 @@ ivas_error ppp_voiced_decoder_fx( set16_fx( pitch, s_min( MAX_LAG_PIT << 6, s_max( 19 << 6, shl( temp_l_fx, 6 ) ) ), NB_SUBFR ); /*Q6 */ } - if ( EQ_16( st_fx->last_coder_type, UNVOICED ) ) { pl = l; @@ -229,7 +233,7 @@ ivas_error ppp_voiced_decoder_fx( L_tmp = L_deposit_h( TMPDTFS_FX->lag_fx ); /*Q16 */ exp = norm_l( L_tmp ); tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = ( 30 - exp - 16 ); + exp = sub( sub( 30, exp ), 16 ); L_tmp = Mpy_32_16( exp, tmp, 12330 ); /* Q13 */ /* 10*log10(2) in Q12*/ logLag = L_shl( L_tmp, 10 ); /*Q23 */ @@ -320,10 +324,10 @@ ivas_error ppp_voiced_decoder_fx( exp = norm_s( CURRP_Q_D_FX->lag_fx ); tmp = div_s( shl( 1, sub( 14, exp ) ), CURRP_Q_D_FX->lag_fx ); /*29-exp */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult0( tmp, 12800 ), exp - 7 ); + L_tmp = L_shl_sat( L_mult0( tmp, 12800 ), sub( exp, 7 ) ); temp32_fx = round_fx_sat( L_tmp ); #else - L_tmp = L_shl( L_mult0( tmp, 12800 ), exp - 7 ); + L_tmp = L_shl( L_mult0( tmp, 12800 ), sub( exp, 7 ) ); temp32_fx = round_fx( L_tmp ); #endif diff = round_fx( L_shl( temp32_fx, 16 - 6 ) ); /*Q0 */ @@ -332,7 +336,7 @@ ivas_error ppp_voiced_decoder_fx( exp = norm_s( diff ); tmp = div_s( shl( 1, sub( 14, exp ) ), diff ); /*29-exp */ - L_tmp = L_shl( L_mult0( 4000, tmp ), exp - 7 ); + L_tmp = L_shl( L_mult0( 4000, tmp ), sub( exp, 7 ) ); tempnH_fx = extract_h( L_tmp ); CURRP_Q_D_FX->nH_4kHz_fx = round_fx( L_shl( tempnH_fx, 16 - 6 ) ); /*Q0 */ @@ -357,15 +361,17 @@ ivas_error ppp_voiced_decoder_fx( IF( bfi == 0 ) { - 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 ) + IF( NE_32( ( 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; } } - 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 ) + IF( NE_32( ( 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; } @@ -406,19 +412,29 @@ void sc_vbr_dec_init( ) { hSC_VBR->nelp_dec_seed = 0; + move16(); hSC_VBR->firstTime_voiceddec = 1; + move16(); /* 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 = 0; + move16(); hSC_VBR->dtfs_dec_nH = 0; + move16(); hSC_VBR->dtfs_dec_nH_4kHz = 0; + move16(); hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx = 0; + move16(); hSC_VBR->dtfs_dec_upper_cut_off_freq_fx = 0; + move16(); hSC_VBR->ph_offset_D_fx = 0; + move16(); hSC_VBR->lastLgainD_fx = 0; + move16(); hSC_VBR->lastHgainD_fx = 0; + move16(); set16_fx( hSC_VBR->lasterbD_fx, 0, NUM_ERB_WB ); /* NELP decoder variables */ diff --git a/lib_dec/waveadjust_fec_dec.c b/lib_dec/waveadjust_fec_dec.c index 245d8bbf6..0931fe0d6 100644 --- a/lib_dec/waveadjust_fec_dec.c +++ b/lib_dec/waveadjust_fec_dec.c @@ -654,7 +654,7 @@ void waveform_adj2( return; } -#endif + /*-------------------------------------------------------------------* * set_state_ivas() @@ -694,22 +694,17 @@ void concealment_init( hPlcInfo->L_frameTCX = L_frameTCX; hPlcInfo->Pitch = 0; hPlcInfo->T_bfi = 0; -#ifndef IVAS_FLOAT_FIXED hPlcInfo->outx_new_n1 = 0.0f; hPlcInfo->nsapp_gain = 0.0f; -#endif -#ifndef IVAS_FLOAT_FIXED + hPlcInfo->nsapp_gain_n = 0.0f; hPlcInfo->ener_mean = 59.4260f; -#endif -#ifndef IVAS_FLOAT_FIXED hPlcInfo->ener = 0.0f; -#endif + hPlcInfo->zp = L_frameTCX; -#ifndef IVAS_FLOAT_FIXED + hPlcInfo->recovery_gain_float = 0.0f; hPlcInfo->step_concealgain = 0.0f; -#endif hPlcInfo->concealment_method = TCX_NONTONAL; hPlcInfo->subframe = 0; hPlcInfo->nbLostCmpt = 0; @@ -727,15 +722,14 @@ void concealment_init( { hPlcInfo->Transient[i] = 1; } -#ifndef IVAS_FLOAT_FIXED for ( i = 0; i < L_FRAME_MAX; i++ ) { hPlcInfo->data_reci2[i] = 0; } -#endif + return; } - +#endif /*-------------------------------------------------------------------* * concealment_decode() diff --git a/lib_dec/waveadjust_fec_dec_fx.c b/lib_dec/waveadjust_fec_dec_fx.c index ddbcb90df..e7aadde27 100644 --- a/lib_dec/waveadjust_fec_dec_fx.c +++ b/lib_dec/waveadjust_fec_dec_fx.c @@ -67,7 +67,7 @@ void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 ELSE { - IF( EQ_16( subframe, 0 ) ) + IF( subframe == 0 ) { set_state( plcInfo->Transient, curr_mode, MAX_POST_LEN ); @@ -80,7 +80,7 @@ void concealment_update_x( Word16 bfi, Word16 curr_mode, Word16 tonality, Word32 pitch_search_fx(), low_freq_rate is derived on the last good TCX-10 spectrum */ test(); - IF( !bfi || EQ_16( subframe, 0 ) ) + IF( !bfi || subframe == 0 ) { Word32 *ptr = data_reci2 + subframe; @@ -336,6 +336,8 @@ void get_maxConv_and_pitch_x( Word16 *s_LP, Word16 s, Word16 e, Word16 N, Word32 Word16 size_tmp = N; move16(); move16(); + move16(); + move16(); nbits = sub( 15, norm_s( sub( N, s ) ) ); FOR( t = s; t < e; t++ ) @@ -800,7 +802,8 @@ void concealment_init_x( Word16 N, void *_plcInfo ) move16(); plcInfo->subframe_fx = 0; move16(); - plcInfo->nbLostCmpt = (int16_t) L_deposit_l( 0 ); + plcInfo->nbLostCmpt = (Word16) L_deposit_l( 0 ); + move16(); plcInfo->seed = 21845; move16(); @@ -834,12 +837,15 @@ void concealment_init_ivas_fx( { Word16 i; hPlcInfo->L_frameTCX = L_frameTCX; + move16(); hPlcInfo->FrameSize = L_frameTCX; move16(); hPlcInfo->Pitch = 0; + move16(); hPlcInfo->Pitch_fx = 0; move16(); hPlcInfo->T_bfi = 0; + move16(); hPlcInfo->T_bfi_fx = 0; move16(); hPlcInfo->outx_new_n1_fx = 0; @@ -851,6 +857,7 @@ void concealment_init_ivas_fx( hPlcInfo->ener_mean_fx = L_deposit_l( 15213 ); hPlcInfo->ener_fx = L_deposit_l( 0 ); hPlcInfo->zp = L_frameTCX; + move16(); hPlcInfo->zp_fx = L_frameTCX; move16(); hPlcInfo->recovery_gain = 0; @@ -860,9 +867,11 @@ void concealment_init_ivas_fx( hPlcInfo->concealment_method = TCX_NONTONAL; move16(); hPlcInfo->subframe = 0; + move16(); hPlcInfo->subframe_fx = 0; move16(); hPlcInfo->nbLostCmpt = (Word16) L_deposit_l( 0 ); + move16(); hPlcInfo->seed = RANDOM_INITSEED; move16(); @@ -885,6 +894,7 @@ void concealment_init_ivas_fx( FOR( i = 0; i < L_FRAME_MAX; i++ ) { hPlcInfo->data_reci2_fx[i] = L_deposit_l( 0 ); + move32(); } return; } @@ -1149,9 +1159,13 @@ Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], FOR( i = 0; i < len_x; i++ ) { if ( x[i] >= 0 ) + { x_max = s_max( x_max, x[i] ); + } if ( x[i] < 0 ) + { x_min = s_min( x_min, x[i] ); + } } i_max = 0x10; @@ -1160,10 +1174,14 @@ Word16 ffr_getSfWord16( /* o: measured headroom in range [0..15], move16(); if ( x_max != 0 ) + { i_max = norm_s( x_max ); + } if ( x_min != 0 ) + { i_min = norm_s( x_min ); + } i = s_and( s_min( i_max, i_min ), 0xF ); @@ -1201,15 +1219,15 @@ static Word16 OverlapAdd_fx( Word16 *pitch125_data, Word16 *sbuf, Word16 n, Word { Word16 tmp; Word16 dat; - dat = shl( sbuf[n + i], s16MaxCoefNorm ); + dat = shl( sbuf[add( n, i )], s16MaxCoefNorm ); tmp = extract_l( L_shl( L_mult0( i, tmp16 ), s ) ); /* q15 */ - sbuf[n + i] = round_fx( L_add( L_shr( L_mult( dat, sub( 32767, tmp ) ), s16MaxCoefNorm ), - L_shr( L_mult( shl( pitch125_data[i], s16MaxCoefNorm2 ), tmp ), s16MaxCoefNorm2 ) ) ); + sbuf[add( n, i )] = round_fx( L_add( L_shr( L_mult( dat, sub( 32767, tmp ) ), s16MaxCoefNorm ), + L_shr( L_mult( shl( pitch125_data[i], s16MaxCoefNorm2 ), tmp ), s16MaxCoefNorm2 ) ) ); } FOR( i = n1; i < n2; i++ ) { - sbuf[n + i] = pitch125_data[i]; + sbuf[add( n, i )] = pitch125_data[i]; move16(); } @@ -1260,6 +1278,7 @@ static void add_noise( Word16 *const sbuf, } *outx_new_n1 = noise_seg[i - 1]; /*q0*/ + move16(); return; } @@ -1318,7 +1337,7 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, test(); test(); - IF( ( LT_16( pos1, pos2 ) ) && ( GT_16( pos3, pitch ) ) && ( LT_16( pos1, Framesizediv2 ) ) ) + if ( ( LT_16( pos1, pos2 ) ) && ( GT_16( pos3, pitch ) ) && ( LT_16( pos1, Framesizediv2 ) ) ) { pitch = add( i2, sub( pitch, i1 ) ); } @@ -1329,16 +1348,17 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, Word16 pitch125_data[L_FRAME_MAX]; move16(); move16(); + move16(); pitch125 = extract_l( ( L_shr( L_add( L_add( L_deposit_h( pitch ), L_mult( pitch, 8192 ) ), 32768 ), 16 ) ) ); Loverlap = sub( pitch125, pitch ); FOR( i = 0; i < pitch; i++ ) { - pitch125_data[i] = outdata2[Framesize - pitch + i]; + pitch125_data[i] = outdata2[add( sub( Framesize, pitch ), i )]; move16(); } FOR( i = 0; i < Loverlap; i++ ) { - pitch125_data[pitch + i] = outx_new[i]; + pitch125_data[add( pitch, i )] = outx_new[i]; move16(); } FOR( i = 0; i < Framesize; i++ ) @@ -1357,7 +1377,7 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, move16(); } - p_tmp[-1] = outdata2[Framesize - pitch - 1]; + p_tmp[-1] = outdata2[sub( sub( Framesize, pitch ), 1 )]; move16(); p_tmp[pitch125] = outx_new[Loverlap]; move16(); @@ -1375,6 +1395,7 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, #else pitch125_data[i] = round_fx( L_shr( L_add( ( L_mult( p_tmp[i], 20972 ) ), L_mac( L_mult( p_tmp[i - 1], 5898 ), p_tmp[i + 1], 5898 ) ), s16MaxCoefNorm ) ); #endif + move16(); } } @@ -1386,7 +1407,7 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, /* maximum pitch lag is 3/4 Framesize; pitch125_data is reused for temporary storage, since outdata2 (holding the pcm data of the last good frame) is still needed and overlapbuf overlaps outdata2 */ - Copy( &sbuf[Framesize / 4], pitch125_data, ( 3 * Framesize ) / 4 ); + Copy( &sbuf[Framesize / 4], pitch125_data, shr( imult1616( 3, Framesize ), 2 ) ); *nsapp_gain = 0; move16(); @@ -1398,7 +1419,7 @@ static Word16 waveform_adj_fix( Word16 *overlapbuf, /* save current (noisy) output from IMDCT */ mvr2r_Word16( outx_new, data_noise, tmp ); /* overlapbuf can now be filled with sbuf, needed for subsequently lost frames */ - Copy( pitch125_data, &overlapbuf[Framesize / 4], ( 3 * Framesize ) / 4 ); + Copy( pitch125_data, &overlapbuf[Framesize / 4], shr( imult1616( 3, Framesize ), 2 ) ); } FOR( i = 0; i < Framesize; i++ ) { @@ -1438,7 +1459,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, Word16 tmp = vadmin( pitch, Framesizesubn ); FOR( i = 0; i < tmp; i++ ) { - sbuf[n + i] = overlapbuf[Framesizesubp + i]; + sbuf[add( n, i )] = overlapbuf[add( Framesizesubp, i )]; move16(); } n = add( n, pitch ); @@ -1454,7 +1475,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, { Word16 size = Framesize; Word16 *noise_ptr = data_noise; - + move16(); /* use last (noisy) output from IMDCT for noise generation */ add_noise( sbuf, outx_new_n1, noise_ptr, size, nsapp_gain, nsapp_gain_n, 0 ); @@ -1522,7 +1543,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, gain_zero_start = add( gain_zero_start, 1 ); } - IF( delay > 0 ) + if ( delay > 0 ) { Framesize = sub( Framesize, delay ); } @@ -1536,9 +1557,9 @@ void waveform_adj2_fix( Word16 *overlapbuf, dat = shl( sbuf[i], s16MaxCoefNorm ); temp_OUT = mult( *recovery_gain, sub( 32767, ratio ) ); #ifdef BASOP_NOGLOB - outx_new[i] = round_fx_sat( L_add_sat( L_shr_sat( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); + outx_new[i] = round_fx_sat( L_add_sat( L_shr_sat( L_mult( temp_OUT, dat ), sub( s16MaxCoefNorm, 1 ) ), L_shr_sat( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); #else - outx_new[i] = round_fx( L_add( L_shr( L_mult( temp_OUT, dat ), s16MaxCoefNorm - 1 ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); + outx_new[i] = round_fx( L_add( L_shr( L_mult( temp_OUT, dat ), sub( s16MaxCoefNorm, 1 ) ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ) ); #endif move16(); #ifdef BASOP_NOGLOB @@ -1555,6 +1576,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, #else outx_new[i] = round_fx( L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), ratio ), s16MaxCoefNorm2 ) ); #endif + move16(); } if ( *recovery_gain < 0 ) @@ -1574,6 +1596,7 @@ void waveform_adj2_fix( Word16 *overlapbuf, dat = shl( sbuf[i], s16MaxCoefNorm ); tmp = extract_l( L_shr( L_mult( i, ptable ), tablescale ) ); outx_new[i] = round_fx( L_add( L_shr( L_mult( dat, sub( 32767, tmp ) ), s16MaxCoefNorm ), L_shr( L_mult( shl( outx_new[i], s16MaxCoefNorm2 ), tmp ), s16MaxCoefNorm2 ) ) ); + move16(); } } } diff --git a/lib_rend/ivas_allrad_dec.c b/lib_rend/ivas_allrad_dec.c index 98328dc56..d99b2a1e7 100644 --- a/lib_rend/ivas_allrad_dec.c +++ b/lib_rend/ivas_allrad_dec.c @@ -232,10 +232,10 @@ ivas_error ivas_sba_get_hoa_dec_matrix_fx( FOR( i = 0; i < num_td; i++ ) { /* spherical harmonics response for t-design, corresponding to ambisonic order */ - ivas_dirac_dec_get_response_fixed( + ivas_dirac_dec_get_response_fx( ( (Word16) L_shr( t_design_azi[i], 22 ) ) > 0 ? ( (Word16) L_shr( t_design_azi[i], 22 ) ) : ( (Word16) L_shr( t_design_azi[i], 22 ) ) + 1, ( (Word16) L_shr( t_design_ele[i], 22 ) ) > 0 ? ( (Word16) L_shr( t_design_ele[i], 22 ) ) : ( (Word16) L_shr( t_design_ele[i], 22 ) ) + 1, - Y_td_int, ambisonics_order ); + Y_td_int, ambisonics_order, Q29 ); FOR( j = 0; j < num_harm; j++ ) { Y_td_int[j] = L_shl( Mpy_32_32( Y_td_int[j], norm_sn3d_hoa3_int[j] ), Q1 ); // Q28 diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 1e7c7dedf..59b022eff 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -6337,10 +6337,11 @@ static void hrtfShGetHrtf_fx( { Word32 shVec[HRTF_SH_CHANNELS]; - ivas_dirac_dec_get_response_fixed( aziDeg, - eleDeg, - shVec, - HRTF_SH_ORDER ); + ivas_dirac_dec_get_response_fx( aziDeg, + eleDeg, + shVec, + HRTF_SH_ORDER, + Q29 ); FOR( k = 0; k < HRTF_SH_CHANNELS; k++ ) { diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 2390b1d5f..8ae785ac5 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -4391,11 +4391,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( } ELSE { - ivas_dirac_dec_get_response_fixed_Q( azimuth[k], elevation[k], direct_response_hoa_fx, hDirACRend->hOutSetup.ambisonics_order, Q_direct_response_hoa ); + ivas_dirac_dec_get_response_fx( azimuth[k], elevation[k], direct_response_hoa_fx, hDirACRend->hOutSetup.ambisonics_order, Q_direct_response_hoa ); IF( hodirac_flag ) { - ivas_dirac_dec_get_response_fixed_Q( azimuth2[k], elevation2[k], direct_response_dir2_fx, hDirACRend->hOutSetup.ambisonics_order, Q_direct_response_dir2 ); + ivas_dirac_dec_get_response_fx( azimuth2[k], elevation2[k], direct_response_dir2_fx, hDirACRend->hOutSetup.ambisonics_order, Q_direct_response_dir2 ); } } @@ -4509,11 +4509,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( { IF( hMasaIsm->ism_is_edited[dir] ) { - ivas_dirac_dec_get_response_fixed( hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], direct_response_temp_fx, hDirACRend->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response_fx( hMasaIsm->azimuth_ism_edited[dir], hMasaIsm->elevation_ism_edited[dir], direct_response_temp_fx, hDirACRend->hOutSetup.ambisonics_order, Q29 ); } ELSE { - ivas_dirac_dec_get_response_fixed( hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], direct_response_temp_fx, hDirACRend->hOutSetup.ambisonics_order ); + ivas_dirac_dec_get_response_fx( hMasaIsm->azimuth_ism[dir][md_idx], hMasaIsm->elevation_ism[dir][md_idx], direct_response_temp_fx, hDirACRend->hOutSetup.ambisonics_order, Q29 ); } exp_direct_response_temp = 2; move16(); @@ -6246,13 +6246,13 @@ static void spreadCoherencePanningHoa_fx( Word32 gainCenter_fx; Word32 gainSide_fx; - ivas_dirac_dec_get_response_fixed_Q( azimuth, elevation, direct_response_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( azimuth, elevation, direct_response_fx, ambisonics_order, *Q_direct_response ); Word16 exp_Gain_side = 0, exp_Gain_center = 0; IF( GT_32( spreadCoh_fx, 0 ) ) { - ivas_dirac_dec_get_response_fixed_Q( azimuth + 30, elevation, direct_response_left_fx, ambisonics_order, *Q_direct_response ); - ivas_dirac_dec_get_response_fixed_Q( azimuth + 330, elevation, direct_response_right_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( azimuth + 30, elevation, direct_response_left_fx, ambisonics_order, *Q_direct_response ); + ivas_dirac_dec_get_response_fx( azimuth + 330, elevation, direct_response_right_fx, ambisonics_order, *Q_direct_response ); Word16 var_a, var_b, exp_a = 0; diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 320138fc8..6cb2491d7 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1874,7 +1874,7 @@ void compute_hoa_encoder_mtx_fx( num_sh = ivas_sba_get_nchan_fx( ambisonics_order, 0 ); FOR( k = 0; k < num_responses; k++ ) { - ivas_dirac_dec_get_response_fixed( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order ); // Q29 + ivas_dirac_dec_get_response_fx( shr( extract_h( azimuth[k] ), Q22 - Q16 ), shr( extract_h( elevation[k] ), Q22 - Q16 ), &response_fx[k * num_sh], ambisonics_order, Q31 ); // Q29 } return; @@ -4135,7 +4135,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( { /*DIRAC_SYNTHESIS_PSD_SHD: Virtual LS->HOA encoding*/ Word16 gb = find_guarded_bits_fx( hDirACRend->num_outputs_diff ); - diff_square_e = add( shl( add( 2, add( proto_e, gb ) ), 1 ), 1 ); + diff_square_e = add( shl( add( proto_e, gb ), 1 ), 1 ); max_e = add( s_max( diff_square_e, smooth_e ), 1 ); Scale_sig32( p_power_smooth_fx, h_dirac_output_synthesis_state->proto_power_diff_smooth_len, sub( smooth_e, max_e ) ); FOR( k = 0; k < hDirACRend->hOutSetup.nchan_out_woLFE; k++ ) @@ -4169,7 +4169,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( p_diff_buffer_1_fx += 2; } } - diff_e = add( add( 2, proto_e ), gb ); + diff_e = add( proto_e, gb ); } h_dirac_output_synthesis_state->proto_power_diff_smooth_q = sub( 31, max_e ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 3158cc8de..87b4f6d36 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -691,7 +691,7 @@ typedef struct ivas_dirac_rend_data_structure #else Word16 *frequency_axis_fx; /* Q0 */ Word16 *diffuse_response_function_fx; /* Q15 */ - Word32 *hoa_encoder_fx; /* Q29 */ + Word32 *hoa_encoder_fx; /* Q31 */ const Word32 *hoa_decoder; /* Q29 */ #endif /*Decoder parameters */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 63c64149e..221c47a33 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3475,7 +3475,7 @@ static ivas_error updateLfePanGainsForAmbiOut( FOR( i = 0; i < numLfeIn; i++ ) { /* panning gains */ - ivas_dirac_dec_get_response_fixed( inputMc->lfeRouting.lfeOutputAzimuth_fx, inputMc->lfeRouting.lfeOutputElevation_fx, inputMc->lfeRouting.lfePanMtx_fx[i], outAmbiOrder ); + ivas_dirac_dec_get_response_fx( inputMc->lfeRouting.lfeOutputAzimuth_fx, inputMc->lfeRouting.lfeOutputElevation_fx, inputMc->lfeRouting.lfePanMtx_fx[i], outAmbiOrder, Q29 ); /* linear input gain */ v_multc_fixed( inputMc->lfeRouting.lfePanMtx_fx[i], inputMc->lfeRouting.lfeInputGain_fx, inputMc->lfeRouting.lfePanMtx_fx[i], IVAS_MAX_OUTPUT_CHANNELS ); @@ -3687,7 +3687,7 @@ static ivas_error updateMcPanGainsForAmbiOut( { ++ch_out; } - ivas_dirac_dec_get_response_fixed( (Word16) L_shr( spkAzi_fx[ch_in], 22 ), (Word16) L_shr( spkEle_fx[ch_in], 22 ), inputMc->panGains_fx[ch_out], outAmbiOrder ); + ivas_dirac_dec_get_response_fx( (Word16) L_shr( spkAzi_fx[ch_in], 22 ), (Word16) L_shr( spkEle_fx[ch_in], 22 ), inputMc->panGains_fx[ch_out], outAmbiOrder, Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { Word32 temp = inputMc->panGains_fx[ch_out][i]; @@ -3720,7 +3720,7 @@ static ivas_error updateMcPanGainsForAmbiOut( } } - ivas_dirac_dec_get_response_fixed( (Word16) L_shr( spkAzi_fx[ch_in], 22 ), (Word16) L_shr( spkEle_fx[ch_in], 22 ), inputMc->panGains_fx[ch_out], outAmbiOrder ); + ivas_dirac_dec_get_response_fx( (Word16) L_shr( spkAzi_fx[ch_in], 22 ), (Word16) L_shr( spkEle_fx[ch_in], 22 ), inputMc->panGains_fx[ch_out], outAmbiOrder, Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { Word32 temp = inputMc->panGains_fx[ch_out][i]; @@ -9684,10 +9684,11 @@ static ivas_error renderIsmToSba( // TODO tmu review when #215 is resolved azimuth_tmp = extract_l( L_shr( ismInput->previousPos.azimuth_fx, Q22 ) ); elevation_tmp = extract_l( L_shr( ismInput->previousPos.elevation_fx, Q22 ) ); - ivas_dirac_dec_get_response_fixed( azimuth_tmp, - elevation_tmp, - ismInput->prev_pan_gains_fx, - ambiOrderOut ); + ivas_dirac_dec_get_response_fx( azimuth_tmp, + elevation_tmp, + ismInput->prev_pan_gains_fx, + ambiOrderOut, + Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { ismInput->prev_pan_gains_fx[i] = L_shl_sat( ismInput->prev_pan_gains_fx[i], Q2 ); @@ -9700,10 +9701,11 @@ static ivas_error renderIsmToSba( // TODO tmu review when #215 is resolved azimuth_tmp = extract_l( L_shr( ismInput->currentPos.azimuth_fx, Q22 ) ); elevation_tmp = extract_l( L_shr( ismInput->currentPos.elevation_fx, Q22 ) ); - ivas_dirac_dec_get_response_fixed( azimuth_tmp, - elevation_tmp, - currentPanGains_fx, - ambiOrderOut ); + ivas_dirac_dec_get_response_fx( azimuth_tmp, + elevation_tmp, + currentPanGains_fx, + ambiOrderOut, + Q29 ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { currentPanGains_fx[i] = L_shl_sat( currentPanGains_fx[i], Q2 ); -- GitLab From 778342cb7d06881a9cda200ea9624d5c9a8ea37d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 11:09:24 +0530 Subject: [PATCH 44/63] Clang formatting changes --- lib_dec/TonalComponentDetection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/TonalComponentDetection.c b/lib_dec/TonalComponentDetection.c index 66333630f..12908a001 100644 --- a/lib_dec/TonalComponentDetection.c +++ b/lib_dec/TonalComponentDetection.c @@ -886,4 +886,4 @@ static void findTonalComponents( return; } -#endif \ No newline at end of file +#endif -- GitLab From a1240ac95874dcec4297a3fd64a9d33d940a4d90 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 11:26:27 +0530 Subject: [PATCH 45/63] Fix for issue 784: BASOP decoder without JBM not BE to BASOP decoder with zero-delay profile --- lib_dec/ivas_jbm_dec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index fa512cf9c..7891c7baa 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -3029,6 +3029,10 @@ ivas_error ivas_jbm_dec_render_fx( FOR( i = 0; i < nchan_in; i++ ) { scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + IF( st_ivas->hDecoderConfig->Opt_tsm ) + { + scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); + } } IF( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData, &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ) != IVAS_ERR_OK ) @@ -3040,6 +3044,10 @@ ivas_error ivas_jbm_dec_render_fx( FOR( i = 0; i < nchan_in; i++ ) { scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + IF( st_ivas->hDecoderConfig->Opt_tsm ) + { + scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); + } } } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) ) -- GitLab From bb647bbfca76861e1c73e754a9cedfdd26bf0c3e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 11:47:48 +0530 Subject: [PATCH 46/63] Integrate lib_com functions in lib_enc modules [x] Integrated all the functions present in ivas_stereo_dft_com.c, ivas_stereo_mdct_bands_com.c, delay_comp.c and ivas_stereo_mdct_stereo_com.c [x] Integrated functions invdct4_transform, ivas_get_df_ratio_bits, ivas_qmetadata_azimuth_elevation_to_direction_vector, masa_sq, only_reduce_bits_direction in encoder [x] ivas_qmetadata_direction_vector_to_azimuth_elevation is integrated but disabled due to the high deviations observed after integrating the function. --- lib_com/delay_comp.c | 20 +- lib_com/ivas_qmetadata_com.c | 23 +- lib_com/ivas_stereo_dft_com.c | 140 +- lib_com/ivas_stereo_mdct_bands_com.c | 80 +- lib_com/ivas_stereo_mdct_stereo_com.c | 27 +- lib_dec/TonalComponentDetection.c | 2 +- lib_dec/ivas_stereo_dft_dec_fx.c | 4 +- lib_dec/lib_dec_fx.c | 5 +- lib_enc/ivas_corecoder_enc_reconfig.c | 4 + lib_enc/ivas_cpe_enc.c | 58 + lib_enc/ivas_dirac_enc.c | 464 +++ lib_enc/ivas_masa_enc.c | 379 ++- lib_enc/ivas_mcmasa_enc.c | 538 ++++ lib_enc/ivas_mct_core_enc.c | 15 + lib_enc/ivas_mct_enc.c | 12 + lib_enc/ivas_omasa_enc.c | 214 ++ lib_enc/ivas_qmetadata_enc.c | 4208 ++++++++++++++++++------- lib_enc/ivas_stereo_cng_enc.c | 7 + lib_enc/ivas_stereo_dft_enc.c | 18 + lib_enc/ivas_stereo_mdct_core_enc.c | 15 + lib_enc/ivas_stereo_mdct_stereo_enc.c | 12 +- lib_enc/ivas_stereo_switching_enc.c | 4 + lib_enc/lib_enc.c | 30 + lib_enc/lib_enc.h | 7 + 24 files changed, 5069 insertions(+), 1217 deletions(-) diff --git a/lib_com/delay_comp.c b/lib_com/delay_comp.c index 9174efd31..0c0beef9e 100644 --- a/lib_com/delay_comp.c +++ b/lib_com/delay_comp.c @@ -49,6 +49,7 @@ *--------------------------------------------------------------------------*/ /*! r: delay value in ns */ +#ifndef IVAS_FLOAT_FIXED int32_t get_delay( const int16_t enc_dec, /* i : encoder/decoder flag */ const int32_t io_fs, /* i : input/output sampling frequency */ @@ -111,13 +112,7 @@ int32_t get_delay( return delay; } - -/*-------------------------------------------------------------------------- - * get_delay_fx() - * - * Function returns various types of delays in the codec in ns. - *--------------------------------------------------------------------------*/ - +#else 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 */ @@ -130,6 +125,7 @@ Word32 get_delay_fx( /* o : delay value in ms ) { Word32 delay = 0; + move32(); IF( EQ_16( what_delay, ENC ) ) { @@ -141,17 +137,19 @@ Word32 get_delay_fx( /* o : delay value in ms ELSE { delay = IVAS_ENC_DELAY_NS; + move32(); 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 */ + move32(); } } 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; + delay = L_add( delay, IVAS_FB_ENC_DELAY_NS ); } } ELSE @@ -172,6 +170,7 @@ Word32 get_delay_fx( /* o : delay value in ms ELSE /* IVAS */ { delay = IVAS_DEC_DELAY_NS; + move32(); #ifdef SPLIT_REND_WITH_HEAD_ROT @@ -181,7 +180,7 @@ Word32 get_delay_fx( /* o : delay value in ms IF( hCldfb != NULL ) { /* compensate for filterbank delay */ - delay += IVAS_FB_DEC_DELAY_NS; + delay = L_add( delay, IVAS_FB_DEC_DELAY_NS ); } #ifdef SPLIT_REND_WITH_HEAD_ROT } @@ -189,10 +188,11 @@ Word32 get_delay_fx( /* o : delay value in ms 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 */ + delay = L_add( delay, IVAS_ENC_DELAY_NS ); /* Compensate also the encoder delay in the decoder with MASA */ } } } return delay; } +#endif diff --git a/lib_com/ivas_qmetadata_com.c b/lib_com/ivas_qmetadata_com.c index f816a740a..bc998fed5 100644 --- a/lib_com/ivas_qmetadata_com.c +++ b/lib_com/ivas_qmetadata_com.c @@ -466,6 +466,7 @@ void ivas_qmetadata_close( *------------------------------------------------------------------------*/ /*! r: codeword index */ +#ifndef IVAS_FLOAT_FIXED int16_t masa_sq( const float in, /* i : input value */ const float *threshold, /* i : partition */ @@ -484,8 +485,7 @@ int16_t masa_sq( return -1; } - -#ifdef IVAS_FLOAT_FIXED +#else Word16 masa_sq_fx( const Word32 in, /* i : input value */ const Word32 *threshold, /* i : partition */ @@ -728,7 +728,7 @@ ivas_error only_reduce_bits_direction_fx( return IVAS_ERR_OK; } -#endif +#else ivas_error only_reduce_bits_direction( int16_t *reduce_bits_out, IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ @@ -834,6 +834,7 @@ ivas_error only_reduce_bits_direction( return IVAS_ERR_OK; } +#endif /*--------------------------------------------------------------- @@ -940,6 +941,7 @@ void update_bits_next_block( * Inverse DCT transform for 4D vector *---------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void invdct4_transform( float *v, /* i : input vector */ uint8_t *invdct_v /* o : inverse transformed vector */ @@ -976,8 +978,7 @@ void invdct4_transform( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void invdct4_transform_fx( Word32 *v_fx, /* i : input vector */ UWord8 *invdct_v, /* o : inverse transformed vector */ @@ -1052,7 +1053,7 @@ void masa_compensate_two_dir_energy_ratio_index_fx( return; } -#endif +#else void masa_compensate_two_dir_energy_ratio_index( const int16_t ratio_index_1, /* i : Input ratio for direction 1 */ const int16_t ratio_index_2, /* i : Input ratio for direction 2 */ @@ -1091,7 +1092,7 @@ void masa_compensate_two_dir_energy_ratio_index( return; } - +#endif /*--------------------------------------------------------------- * set_qmetadata_maxbit_req() @@ -1144,6 +1145,7 @@ void ivas_set_qmetadata_maxbit_req( * *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_qmetadata_azimuth_elevation_to_direction_vector( const float az, /* i : azimuth */ const float el, /* i : elevation */ @@ -1160,8 +1162,7 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( const Word32 az, /* i : azimuth */ const Word32 el, /* i : elevation */ @@ -1171,8 +1172,8 @@ void ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( Word16 radius_length; Word16 elevation_fx, azimuth_fx; - elevation_fx = extract_l( L_shr( Mpy_32_16_1( el, 91 ), 7 ) ); - azimuth_fx = extract_l( L_shr( Mpy_32_16_1( az, 91 ), 7 ) ); + elevation_fx = extract_l( L_shr( Mpy_32_32( el, 5965232 ), 7 ) ); + azimuth_fx = extract_l( L_shr( Mpy_32_32( az, 5965232 ), 7 ) ); dv[2] = L_shl( getSineWord16R2( elevation_fx ), Q15 ); /* Q30 */ move32(); diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c index 02eb6dfb0..595d8f1db 100644 --- a/lib_com/ivas_stereo_dft_com.c +++ b/lib_com/ivas_stereo_dft_com.c @@ -43,13 +43,13 @@ #include "ivas_prot_fx.h" #endif -#ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * stereo_dft_config() * * DFT Stereo Configuration function *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void stereo_dft_config_fx( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ const Word32 brate, /* i : IVAS/CPE/nominal total bitrate */ @@ -195,80 +195,7 @@ void stereo_dft_config_fx( return; } - -/*------------------------------------------------------------------------- - * stereo_dft_band_config() - * - * Stereo DFT bands condfiguration - *------------------------------------------------------------------------*/ - -Word16 stereo_dft_band_config_fx( - Word16 *band_limits, /* o : DFT band limits */ - const Word16 band_res, /* i : DFT band resolution */ - const Word16 NFFT, /* i : analysis/synthesis window length */ - const Word16 enc_dec /* i : flag to indicate enc vs dec */ -) -{ - Word16 nbands; - - /*sanity check*/ - assert( ( EQ_16( band_res, 1 ) || EQ_16( band_res, 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" ); - - band_limits[0] = 1; - move16(); - nbands = 0; - move16(); - WHILE( LT_16( band_limits[nbands++], shr( NFFT, 1 ) ) ) - { - IF( EQ_16( band_res, 0 ) ) - { - assert( 0 && "stereo DFT: band config failed!\n" ); - } - ELSE IF( EQ_16( band_res, 1 ) ) - { - IF( EQ_16( enc_dec, ENC ) ) - { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); - move16(); - } - ELSE - { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); - move16(); - } - - assert( ( LT_16( nbands, STEREO_DFT_ERB4_BANDS ) ) && "stereo DFT: band config failed!\n" ); - } - ELSE - { - IF( EQ_16( enc_dec, ENC ) ) - { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); - move16(); - } - ELSE - { - band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); - move16(); - } - - assert( ( LT_16( nbands, STEREO_DFT_ERB8_BANDS ) ) && "stereo DFT: band config failed!\n" ); - } - } - nbands = sub( nbands, 1 ); - band_limits[nbands] = shr( NFFT, 1 ); /*Nyquist Freq*/ - move16(); - - return ( nbands ); -} -#endif - -/*------------------------------------------------------------------------- - * stereo_dft_config() - * - * DFT Stereo Configuration function - *------------------------------------------------------------------------*/ - +#else void stereo_dft_config( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ const int32_t brate, /* i : IVAS/CPE/nominal total bitrate */ @@ -378,6 +305,7 @@ void stereo_dft_config( return; } +#endif /*------------------------------------------------------------------------- * stereo_dft_band_config() @@ -385,6 +313,67 @@ void stereo_dft_config( * Stereo DFT bands condfiguration *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +Word16 stereo_dft_band_config_fx( + Word16 *band_limits, /* o : DFT band limits */ + const Word16 band_res, /* i : DFT band resolution */ + const Word16 NFFT, /* i : analysis/synthesis window length */ + const Word16 enc_dec /* i : flag to indicate enc vs dec */ +) +{ + Word16 nbands; + + /*sanity check*/ + assert( ( EQ_16( band_res, 1 ) || EQ_16( band_res, 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" ); + + band_limits[0] = 1; + move16(); + nbands = 0; + move16(); + WHILE( LT_16( band_limits[nbands++], shr( NFFT, 1 ) ) ) + { + IF( EQ_16( band_res, 0 ) ) + { + assert( 0 && "stereo DFT: band config failed!\n" ); + } + ELSE IF( EQ_16( band_res, 1 ) ) + { + IF( enc_dec == ENC ) + { + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + move16(); + } + ELSE + { + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb4[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + move16(); + } + + assert( ( LT_16( nbands, STEREO_DFT_ERB4_BANDS ) ) && "stereo DFT: band config failed!\n" ); + } + ELSE + { + IF( enc_dec == ENC ) + { + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 2 ), 26214 /* 1.60000002 in Q14 */ ) ); + move16(); + } + ELSE + { + band_limits[nbands] = round_fx( L_mult0( shl( dft_band_limits_erb8[nbands], 1 ), 26214 /* 0.800000012 in Q14 */ ) ); + move16(); + } + + assert( ( LT_16( nbands, STEREO_DFT_ERB8_BANDS ) ) && "stereo DFT: band config failed!\n" ); + } + } + nbands = sub( nbands, 1 ); + band_limits[nbands] = shr( NFFT, 1 ); /*Nyquist Freq*/ + move16(); + + return ( nbands ); +} +#else int16_t stereo_dft_band_config( int16_t *band_limits, /* o : DFT band limits */ const int16_t band_res, /* i : DFT band resolution */ @@ -437,3 +426,4 @@ int16_t stereo_dft_band_config( return ( nbands ); } +#endif diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com.c index af8110c06..3c06612c4 100644 --- a/lib_com/ivas_stereo_mdct_bands_com.c +++ b/lib_com/ivas_stereo_mdct_bands_com.c @@ -84,47 +84,54 @@ void stereo_mdct_init_bands_fx( IF( tmp_tcx_mode > 0 ) { tcx_mode = tmp_tcx_mode; - L_frameTCX = ( tcx_mode == TCX_20_CORE ) ? L_frame : ( L_frame / 2 ); + move16(); + L_frameTCX = EQ_16( tcx_mode, TCX_20_CORE ) ? L_frame : ( L_frame / 2 ); + move16(); } ELSE { /*transition frame*/ - L_frameTCX = L_frame + L_frame / 4; + L_frameTCX = add( L_frame, L_frame / 4 ); tcx_mode = TCX_20_CORE; + move16(); } /* select table */ - IF( L_frame == L_FRAME48k ) + IF( EQ_16( L_frame, L_FRAME48k ) ) { sfbParam.steBands = mdctStereoBands_32000_640; - cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[0] : sfbParam.steBands->bndCnt_TCX10[0] ); + cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[0] : sfbParam.steBands->bndCnt_TCX10[0]; + move16(); - sfbWidths = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10 ); + sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10; } ELSE { - IF( element_brate < IVAS_96k ) + IF( LT_32( element_brate, IVAS_96k ) ) { sfbParam.steBands = mdctStereoBands_32000_640; SWITCH( L_frame ) { case L_FRAME32k: - cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[1] : sfbParam.steBands->bndCnt_TCX10[1] ); + cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[1] : sfbParam.steBands->bndCnt_TCX10[1]; + move16(); BREAK; case L_FRAME25_6k: - cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[2] : sfbParam.steBands->bndCnt_TCX10[2] ); + cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[2] : sfbParam.steBands->bndCnt_TCX10[2]; + move16(); BREAK; case L_FRAME16k: - cnt = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bdnCnt_TCX20[3] : sfbParam.steBands->bndCnt_TCX10[3] ); + cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[3] : sfbParam.steBands->bndCnt_TCX10[3]; + move16(); BREAK; default: assert( !"Subband division not defined for this frame size" ); return; } - sfbWidths = ( tcx_mode == TCX_20_CORE ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10 ); + sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10; } ELSE { @@ -145,33 +152,40 @@ void stereo_mdct_init_bands_fx( return; } - sfbWidths = ( tcx_mode == TCX_20_CORE ? sfbParam.lpcBndsParam->bandLengthsTCX20 : sfbParam.lpcBndsParam->bandLengthsTCX10 ); + sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.lpcBndsParam->bandLengthsTCX20 : sfbParam.lpcBndsParam->bandLengthsTCX10; cnt = 64; + move16(); } } /* calc sfb offsets */ specStartOffset = 0; + move16(); FOR( i = 0; i < cnt; i++ ) { - sfbOffset[i] = min( specStartOffset, L_frameTCX ); - specStartOffset += sfbWidths[i]; + sfbOffset[i] = s_min( specStartOffset, L_frameTCX ); + move16(); + specStartOffset = add( specStartOffset, sfbWidths[i] ); - IF( sfbOffset[i] >= L_frameTCX ) + IF( GE_16( sfbOffset[i], L_frameTCX ) ) { BREAK; } } *sfbCnt = i; - sfbOffset[*sfbCnt] = min( specStartOffset, L_frameTCX ); + move16(); + sfbOffset[*sfbCnt] = s_min( specStartOffset, L_frameTCX ); + move16(); IF( igf ) { Word16 sfbOldCnt = *sfbCnt; Word16 igfSfbStep = hIgfGrid->infoIsRefined ? 2 : 1; Word16 k; + move16(); + move16(); /* modify sfb bands according to igf grid */ assert( hIgfGrid != NULL ); @@ -179,44 +193,49 @@ void stereo_mdct_init_bands_fx( /* find sfb where IGF starts */ FOR( i = 0; i <= *sfbCnt; i++ ) { - IF( sfbOffset[i] >= hIgfGrid->startLine ) + IF( GE_16( sfbOffset[i], hIgfGrid->startLine ) ) { /* set band border to igf start line */ sfbOffset[i] = hIgfGrid->startLine; + move16(); *sfbCnt = i; + move16(); BREAK; } } /* change bands above the igf start line to match igf bands */ - for ( i = 1, k = igfSfbStep; i < hIgfGrid->swb_offset_len; i++, k += igfSfbStep ) + FOR( ( i = 1, k = igfSfbStep ); i < hIgfGrid->swb_offset_len; ( i++, k += igfSfbStep ) ) { - sfbOffset[*sfbCnt + i] = hIgfGrid->swb_offset[k]; + sfbOffset[add( *sfbCnt, i )] = hIgfGrid->swb_offset[k]; + move16(); } - *sfbCnt += ( hIgfGrid->swb_offset_len - 1 ); + *sfbCnt = add( *sfbCnt, sub( hIgfGrid->swb_offset_len, 1 ) ); + move16(); /* better save than sorry, overwrite anything that is left above */ FOR( i = *sfbCnt + 1; i < sfbOldCnt + 1; i++ ) { sfbOffset[i] = 0; + move16(); } } ELSE { - IF( sfbOffset[*sfbCnt] < L_frameTCX ) + IF( LT_16( sfbOffset[*sfbCnt], L_frameTCX ) ) { - Word16 nMissingBins = L_frameTCX - sfbOffset[*sfbCnt]; - IF( sfbWidths[i] / 2 < nMissingBins ) + Word16 nMissingBins = sub( L_frameTCX, sfbOffset[*sfbCnt] ); + if ( LT_16( sfbWidths[i] / 2, nMissingBins ) ) { ( *sfbCnt )++; } sfbOffset[*sfbCnt] = L_frameTCX; + move16(); } } return; } -#endif - +#else void stereo_mdct_init_bands( const int16_t L_frame, /* i : frame length */ const int16_t tmp_tcx_mode, /* i : tcx mode (TCX10, TCX 20), -1 if transition frame */ @@ -365,6 +384,7 @@ void stereo_mdct_init_bands( } return; } +#endif /*-------------------------------------------------------------------* * stereo_mdct_init_igf_start_band() @@ -389,20 +409,21 @@ void stereo_mdct_init_igf_start_band_fx( FOR( i = 0; i < stbParams->sfbCnt; i++ ) { - IF( igfStartLine == stbParams->sfbOffset[i] ) + IF( EQ_16( igfStartLine, stbParams->sfbOffset[i] ) ) { stbParams->sfbIgfStart = i; + move16(); BREAK; } } stbParams->nBandsStereoCore = stbParams->sfbIgfStart; + move16(); return; } -#endif - +#else void stereo_mdct_init_igf_start_band( STEREO_MDCT_BAND_PARAMETERS *stbParams, /* i/o: stereo frequency band parameters */ const float transFac, /* i : transform factor */ @@ -413,11 +434,7 @@ void stereo_mdct_init_igf_start_band( int16_t i, bitRateIndex, igfStartLine; const int16_t *swb_offset; -#ifdef IVAS_FLOAT_FIXED - bitRateIndex = IGF_MapBitRateToIndex( element_brate, bwidth, IVAS_CPE_MDCT, 0 ); -#else bitRateIndex = IGF_MapBitRateToIndex_flt( element_brate, bwidth, IVAS_CPE_MDCT, 0 ); -#endif swb_offset = &swb_offset_LB_new[bitRateIndex][1]; igfStartLine = IGF_ApplyTransFac_flt( swb_offset[0], transFac ); @@ -435,3 +452,4 @@ void stereo_mdct_init_igf_start_band( return; } +#endif diff --git a/lib_com/ivas_stereo_mdct_stereo_com.c b/lib_com/ivas_stereo_mdct_stereo_com.c index 275dcbdae..28e22b28c 100644 --- a/lib_com/ivas_stereo_mdct_stereo_com.c +++ b/lib_com/ivas_stereo_mdct_stereo_com.c @@ -42,14 +42,13 @@ #include "ivas_prot_fx.h" #endif -#ifdef IVAS_FLOAT_FIXED -#define POINT_2_Q15 6554 /*-------------------------------------------------------------------* * splitAvailableBits() * * split available bits between channels based on the split ratio *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void splitAvailableBits_fx( const Word16 total_bits, /* i : total available bits for TCX coding */ const Word16 split_ratio, /* i : split ratio */ @@ -60,25 +59,22 @@ void splitAvailableBits_fx( { assert( split_ratio >= 1 && split_ratio < SMDCT_BITRATE_RATIO_RANGE ); - *bits_ch0 = split_ratio * total_bits / SMDCT_BITRATE_RATIO_RANGE; + /* *bits_ch0 = split_ratio * total_bits / SMDCT_BITRATE_RATIO_RANGE; */ + *bits_ch0 = extract_l( L_mult0( split_ratio, total_bits ) / SMDCT_BITRATE_RATIO_RANGE ); + move16(); /* for SBA mode bias the distribution towards the W channel */ - if ( split_ratio < 7 && isSBAStereoMode ) + test(); + IF( LT_16( split_ratio, 7 ) && isSBAStereoMode ) { - //*bits_ch0 += (int16_t) ( 0.2 * *bits_ch0 ); - *bits_ch0 += (Word16) ( Mpy_32_16_1( 6554, *bits_ch0 ) ); // 0.2 in Q15 + *bits_ch0 = add( *bits_ch0, extract_l( Mpy_32_16_1( 6554 /* 0.2 in Q15 */, *bits_ch0 ) ) ); + move16(); } - *bits_ch1 = total_bits - *bits_ch0; + *bits_ch1 = sub( total_bits, *bits_ch0 ); + move16(); return; } -#endif - -/*-------------------------------------------------------------------* - * splitAvailableBits() - * - * split available bits between channels based on the split ratio - *-------------------------------------------------------------------*/ - +#else void splitAvailableBits( const int16_t total_bits, /* i : total available bits for TCX coding */ const int16_t split_ratio, /* i : split ratio */ @@ -99,3 +95,4 @@ void splitAvailableBits( return; } +#endif diff --git a/lib_dec/TonalComponentDetection.c b/lib_dec/TonalComponentDetection.c index 12908a001..66333630f 100644 --- a/lib_dec/TonalComponentDetection.c +++ b/lib_dec/TonalComponentDetection.c @@ -886,4 +886,4 @@ static void findTonalComponents( return; } -#endif +#endif \ No newline at end of file diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 09867f30c..8a7f883ec 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -333,8 +333,10 @@ static void stereo_dft_dec_open_fx( /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ set_s( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_DEC_DFT_NB ); - hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[0], hStereoDft->NFFT, DEC ); + move16(); hStereoDft->hb_stefi_delay = NS2SA( output_Fs, STEREO_DFT_TD_STEFI_DELAY_NS ); + move16(); IF( GT_16( nchan_transport, 2 ) ) { diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 11a38a393..7ca71ffb2 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -2422,9 +2422,12 @@ ivas_error IVAS_DEC_GetDelay( out_fs_fx = ( hDecoderConfig->output_Fs != 48000 ) ? ( ( hDecoderConfig->output_Fs != 32000 ) ? FS_16K_IN_NS_Q31 : FS_32K_IN_NS_Q31 ) : FS_48K_IN_NS_Q31; - nSamples[1] = NS2SA_fx2( hDecoderConfig->output_Fs, get_delay( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); + nSamples[1] = NS2SA_fx2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) ); + move16(); nSamples[2] = (Word16) W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ); + move16(); nSamples[0] = add( nSamples[1], nSamples[2] ); + move16(); IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) ) { diff --git a/lib_enc/ivas_corecoder_enc_reconfig.c b/lib_enc/ivas_corecoder_enc_reconfig.c index 21eedf230..da56ae4dc 100644 --- a/lib_enc/ivas_corecoder_enc_reconfig.c +++ b/lib_enc/ivas_corecoder_enc_reconfig.c @@ -481,7 +481,11 @@ ivas_error ivas_corecoder_enc_reconfig( st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); +#else + initMdctStereoEncData_fx( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 ); +#endif st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT || hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 5e9f49ba7..55f76e430 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -271,6 +271,7 @@ ivas_error ivas_cpe_enc( } +#ifndef IVAS_FLOAT_FIXED if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || ( ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) || sts[0]->last_core_brate <= SID_2k40 ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ { @@ -291,6 +292,36 @@ ivas_error ivas_cpe_enc( stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } +#else + test(); + test(); + test(); + test(); + test(); + /* No Basop - sts[0]->ini_frame == 0 as comparison with 0 */ + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 || + ( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) || LE_32( sts[0]->last_core_brate, SID_2k40 ) ) ) /* If the last frame was SID or NO_DATA, we need to run stereo_dft_config here since VAD decision is not known yet */ + { + IF( st_ivas->hQMetaData != NULL ) + { + test(); + /* No Basop - st_ivas->ism_mode != ISM_MODE_NONE as comparison with 0 */ + IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && st_ivas->ism_mode != ISM_MODE_NONE ) + { + stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.70f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + ELSE + { + stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + } + ELSE + { + /* note; "bits_frame_nominal" needed in TD stereo as well */ + stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + } +#endif if ( hCPE->element_mode == IVAS_CPE_TD ) { @@ -301,7 +332,11 @@ ivas_error ivas_cpe_enc( } else { +#ifndef IVAS_FLOAT_FIXED stereo_dft_config( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#else + stereo_dft_config_fx( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#endif } } @@ -344,7 +379,11 @@ ivas_error ivas_cpe_enc( /* reconfiguration in case of bitrate switching */ if ( hCPE->element_brate != hCPE->last_element_brate && st_ivas->hMCT == NULL ) { +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 0 ); +#else + initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 0 ); +#endif hCPE->hStereoMdct->isSBAStereoMode = ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); } } @@ -515,7 +554,11 @@ ivas_error ivas_cpe_enc( /* reconfiguration of MDCT stereo */ if ( sts[0]->bwidth != sts[0]->last_bwidth || ( ( hCPE->last_element_brate != hCPE->element_brate || hCPE->last_element_mode != hCPE->element_mode ) && sts[0]->bwidth != sts[0]->max_bwidth ) ) { +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, sts[0]->bwidth, 0, NULL, 0 ); +#else + initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, sts[0]->bwidth, 0, NULL, 0 ); +#endif hCPE->hStereoMdct->isSBAStereoMode = ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) @@ -586,6 +629,7 @@ ivas_error ivas_cpe_enc( if ( sts[0]->core_brate == SID_2k40 || sts[0]->core_brate == FRAME_NO_DATA ) { /* Reconfigure DFT Stereo for inactive frames */ +#ifndef IVAS_FLOAT_FIXED if ( sts[0]->core_brate == SID_2k40 ) { stereo_dft_config( hCPE->hStereoDft->hConfig, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); @@ -594,6 +638,16 @@ ivas_error ivas_cpe_enc( { stereo_dft_config( hCPE->hStereoDft->hConfig, FRAME_NO_DATA, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } +#else + IF( EQ_32( sts[0]->core_brate, SID_2k40 ) ) + { + stereo_dft_config_fx( hCPE->hStereoDft->hConfig, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } + ELSE + { + stereo_dft_config_fx( hCPE->hStereoDft->hConfig, FRAME_NO_DATA, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + } +#endif stereo_dft_cng_side_gain( hCPE->hStereoDft, hCPE->hStereoCng, sts[0]->core_brate, sts[0]->last_core_brate, sts[0]->bwidth ); } @@ -955,7 +1009,11 @@ ivas_error create_cpe_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); +#else + initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, max_bwidth, 0, NULL, 1 ); +#endif hCPE->hStereoMdct->isSBAStereoMode = ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) ); if ( hCPE->element_mode == IVAS_CPE_MDCT && element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 23ddd3ddd..6f58a2501 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -36,7 +36,10 @@ #include #include "cnst.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" @@ -278,6 +281,7 @@ void ivas_dirac_enc_close( * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_dirac_enc( DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -293,6 +297,9 @@ ivas_error ivas_dirac_enc( { int16_t orig_dirac_bands; float dir[3], avg_dir[3]; +#ifdef IVAS_FLOAT_FIXED + Word32 dir_fx[3] /*, avg_dir_fx[3]*/; +#endif float energySum, vecLen; int16_t i, j, b, i_ts; ivas_error error; @@ -342,7 +349,21 @@ ivas_error ivas_dirac_enc( /* combine all DirAC bands except the last one, handle last band separately, last band covers BW above WB */ for ( j = 0; j < orig_dirac_bands - 1; j++ ) { +#ifdef IVAS_FLOAT_FIXED + /*==========================================flt-2-fix======================================================*/ + hQMetaData->q_direction[0].band_data[j].azimuth_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].azimuth[i], Q22 ); + hQMetaData->q_direction[0].band_data[j].elevation_fx[i] = floatToFixed( hQMetaData->q_direction[0].band_data[j].elevation[i], Q22 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( hQMetaData->q_direction[0].band_data[j].azimuth_fx[i], hQMetaData->q_direction[0].band_data[j].elevation_fx[i], &dir_fx[0] ); + + /*==========================================fix-2-flt======================================================*/ + fixedToFloat_arrL( dir_fx, dir, Q30, 3 ); + /*==========================================fix-2-flt======================================================*/ + +#else ivas_qmetadata_azimuth_elevation_to_direction_vector( hQMetaData->q_direction[0].band_data[j].azimuth[i], hQMetaData->q_direction[0].band_data[j].elevation[i], &dir[0] ); +#endif vecLen = hQMetaData->q_direction[0].band_data[j].energy_ratio[i] * hDirAC->buffer_energy[i * orig_dirac_bands + j]; avg_dir[0] += dir[0] * vecLen; @@ -352,7 +373,22 @@ ivas_error ivas_dirac_enc( energySum += hDirAC->buffer_energy[i * orig_dirac_bands + j]; } +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + Word16 q_dir_e = 0; + f2me_buf( avg_dir, avg_dir_fx, &q_dir_e, 3 ); + Scale_sig32( avg_dir_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( &avg_dir_fx[0], Q30, &hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], &hQMetaData->q_direction[0].band_data[0].elevation_fx[i] ); + + /*==========================================fix-2-flt======================================================*/ + hQMetaData->q_direction[0].band_data[0].azimuth[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].azimuth_fx[i], Q22 ); + hQMetaData->q_direction[0].band_data[0].elevation[i] = fixedToFloat( hQMetaData->q_direction[0].band_data[0].elevation_fx[i], Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); +#endif hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; @@ -403,6 +439,133 @@ ivas_error ivas_dirac_enc( return IVAS_ERR_OK; } +#else +ivas_error ivas_dirac_enc( + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + float *data_f[], /* i/o: SBA channels */ + float **ppIn_FR_real, /* o : real freq domain values */ + float **ppIn_FR_imag, /* o : imag freq domain values */ + const int16_t input_frame, /* i : input frame length */ + const int16_t dtx_vad, /* i : DTX vad flag */ + const IVAS_FORMAT ivas_format, /* i : ivas format */ + const int16_t hodirac_flag /* i : hodirac flag */ +) +{ + int16_t orig_dirac_bands; + float dir[3], avg_dir[3]; + float energySum, vecLen; + int16_t i, j, b, i_ts; + ivas_error error; + push_wmops( "ivas_dirac_enc" ); + + ivas_dirac_param_est_enc( hDirAC, hQMetaData->q_direction, hQMetaData->useLowerRes, data_f, ppIn_FR_real, ppIn_FR_imag, input_frame, ivas_format, hodirac_flag, hodirac_flag ? HOA2_CHANNELS : FOA_CHANNELS, &( hDirAC->mono_frame_count ), &( hQMetaData->dirac_mono_flag ) ); + + if ( hQMetaData->q_direction->cfg.nbands > 0 ) + { + orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; + + if ( dtx_vad == 1 ) + { + /* WB 4TC mode bit : disable for now*/ + push_next_indice( hMetaData, 0, 1 ); + + /* Set Energy Ratio to 0.0 if the mono flag is set, before the metadata is encoded */ + if ( hQMetaData->dirac_mono_flag ) + { + for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + { + hQMetaData->q_direction[0].band_data[b].energy_ratio[i_ts] = 0.0f; + hQMetaData->q_direction[0].band_data[b].azimuth[i_ts] = 0.0f; + hQMetaData->q_direction[0].band_data[b].elevation[i_ts] = 0.0f; + } + } + } + + if ( ( error = ivas_qmetadata_enc_encode( hMetaData, hQMetaData, hodirac_flag ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + hQMetaData->q_direction[0].cfg.nbands = DIRAC_DTX_BANDS; + + /* compute directions */ + for ( i = 0; i < hQMetaData->q_direction[0].cfg.nblocks; i++ ) + { + set_zero( dir, 3 ); + set_zero( avg_dir, 3 ); + energySum = 0.0f; + + /* combine all DirAC bands except the last one, handle last band separately, last band covers BW above WB */ + for ( j = 0; j < orig_dirac_bands - 1; j++ ) + { + ivas_qmetadata_azimuth_elevation_to_direction_vector( hQMetaData->q_direction[0].band_data[j].azimuth[i], hQMetaData->q_direction[0].band_data[j].elevation[i], &dir[0] ); + vecLen = hQMetaData->q_direction[0].band_data[j].energy_ratio[i] * hDirAC->buffer_energy[i * orig_dirac_bands + j]; + + avg_dir[0] += dir[0] * vecLen; + avg_dir[1] += dir[1] * vecLen; + avg_dir[2] += dir[2] * vecLen; + + energySum += hDirAC->buffer_energy[i * orig_dirac_bands + j]; + } + + ivas_qmetadata_direction_vector_to_azimuth_elevation( &avg_dir[0], &hQMetaData->q_direction[0].band_data[0].azimuth[i], &hQMetaData->q_direction[0].band_data[0].elevation[i] ); + hQMetaData->q_direction[0].band_data[0].energy_ratio[i] = sqrtf( dotp( avg_dir, avg_dir, 3 ) ) / ( energySum + EPSILON ); + + hQMetaData->q_direction[0].band_data[1].azimuth[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i]; + hQMetaData->q_direction[0].band_data[1].elevation[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i]; + hQMetaData->q_direction[0].band_data[1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i]; + } + + /* 1 bit to indicate mode MD coding : temp solution*/ + push_next_indice( hMetaData, 1, 1 ); + + /* encode SID parameters */ + ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT ); + } + + for ( b = hQMetaData->q_direction->cfg.start_band; b < hQMetaData->q_direction->cfg.nbands; b++ ) + { + for ( i_ts = 0; i_ts < ( ( dtx_vad == 1 ) ? hQMetaData->q_direction[0].cfg.nblocks : 1 ); i_ts++ ) + { + hQMetaData->q_direction->band_data[b].azimuth[i_ts] = hQMetaData->q_direction->band_data[b].q_azimuth[i_ts]; + hQMetaData->q_direction->band_data[b].elevation[i_ts] = hQMetaData->q_direction->band_data[b].q_elevation[i_ts]; + hQMetaData->q_direction[0].band_data[b].energy_ratio[0] = 1.0f - diffuseness_reconstructions[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; + } + } + + if ( dtx_vad == 0 ) + { + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; + } + + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = orig_dirac_bands - 2; j >= 0; j-- ) + { + hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; + hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; + hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; + } + } + + hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + } + } + pop_wmops(); + + return IVAS_ERR_OK; +} +#endif /*------------------------------------------------------------------------- @@ -593,6 +756,306 @@ void computeReferencePower_enc( * *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_param_est_enc( + DIRAC_ENC_HANDLE hDirAC, + IVAS_QDIRECTION *q_direction, + const uint8_t useLowerRes, + float *data_f[], + float **pp_fr_real, + float **pp_fr_imag, + const int16_t input_frame, + const IVAS_FORMAT ivas_format, + const int16_t hodirac_flag, + const int16_t nchan_fb_in, + int16_t *mono_frame_count, + int16_t *dirac_mono_flag ) +{ + int16_t i, d, ts, index, l_ts, num_freq_bands; + int16_t band_m_idx, block_m_idx; + float dir_v[DIRAC_NUM_DIMS]; +#ifdef IVAS_FLOAT_FIXED_ + Word32 dir_v_fx[DIRAC_NUM_DIMS]; +#endif + float *pcm_in[DIRAC_MAX_ANA_CHANS]; + float Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + float Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + float *p_Cldfb_RealBuffer[DIRAC_MAX_ANA_CHANS]; + float *p_Cldfb_ImagBuffer[DIRAC_MAX_ANA_CHANS]; + float intensity_real[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + float direction_vector[DIRAC_NUM_DIMS][DIRAC_MAX_NBANDS]; + float diffuseness_vector[DIRAC_MAX_NBANDS]; + float renormalization_factor[DIRAC_MAX_NBANDS]; + float renormalization_factor_diff[DIRAC_MAX_NBANDS]; + float norm_tmp; + int16_t mrange[2]; + int16_t num_blocks; + float reference_power[CLDFB_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; + float azi_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + float ele_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + float diff_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + float ene_secs[2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS]; + + push_wmops( "dirac_enc_param_est" ); + num_freq_bands = hDirAC->hConfig->nbands; + + /* Initialization */ + l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; + if ( useLowerRes ) + { + q_direction->cfg.nblocks = 1; + num_blocks = 1; + } + else + { + q_direction->cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; + num_blocks = MAX_PARAM_SPATIAL_SUBFRAMES; + } + + /* Need to initialize renormalization_factors, direction_m and diffuseness_m */ + for ( i = 0; i < hDirAC->hConfig->nbands; i++ ) + { + renormalization_factor_diff[i] = 0; + hDirAC->diffuseness_m[i] = 0; + } + + set_zero( azi_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + set_zero( ele_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + set_zero( diff_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + set_zero( ene_secs, 2 * DIRAC_MAX_ANA_CHANS * DIRAC_MAX_NBANDS ); + + /* Copy current frame to memory for delay compensation */ + for ( i = 0; i < nchan_fb_in; i++ ) + { + pcm_in[i] = data_f[i]; + p_Cldfb_RealBuffer[i] = &Cldfb_RealBuffer[i][0]; + p_Cldfb_ImagBuffer[i] = &Cldfb_ImagBuffer[i][0]; + } + + /* do processing over all CLDFB time slots */ + for ( block_m_idx = 0; block_m_idx < num_blocks; block_m_idx++ ) + { + mrange[0] = hDirAC->block_grouping[block_m_idx]; + mrange[1] = hDirAC->block_grouping[block_m_idx + 1]; + + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + renormalization_factor[band_m_idx] = EPSILON; + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + } + + for ( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + if ( hDirAC->hFbMixer ) + { + ivas_fb_mixer_get_windowed_fr( hDirAC->hFbMixer, pcm_in, p_Cldfb_RealBuffer, p_Cldfb_ImagBuffer, l_ts, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); + + ivas_fb_mixer_update_prior_input( hDirAC->hFbMixer, pcm_in, l_ts, hDirAC->hFbMixer->fb_cfg->num_in_chans ); + + for ( i = 0; i < nchan_fb_in; i++ ) + { + pcm_in[i] += l_ts; + } + } + else + { + for ( i = 0; i < nchan_fb_in; i++ ) + { + mvr2r( &pp_fr_real[i][ts * l_ts], Cldfb_RealBuffer[i], l_ts ); + mvr2r( &pp_fr_imag[i][ts * l_ts], Cldfb_ImagBuffer[i], l_ts ); + } + } + + computeReferencePower_enc( + hDirAC->band_grouping, + Cldfb_RealBuffer, + Cldfb_ImagBuffer, + reference_power[ts], + hDirAC->hConfig->enc_param_start_band, + num_freq_bands, + ivas_format, + hodirac_flag ? 0 : 1, + FOA_CHANNELS, + mono_frame_count, + dirac_mono_flag ); + + computeIntensityVector_enc( + hDirAC, + Cldfb_RealBuffer, + Cldfb_ImagBuffer, + hDirAC->hConfig->enc_param_start_band, + num_freq_bands, + intensity_real ); + + if ( !hodirac_flag ) + { + computeDirectionVectors( + intensity_real[0], + intensity_real[1], + intensity_real[2], + hDirAC->hConfig->enc_param_start_band, + num_freq_bands, + direction_vector[0], + direction_vector[1], + direction_vector[2] ); + } + + /* fill buffers of length "averaging_length" time slots for intensity and energy */ + hDirAC->index_buffer_intensity = ( hDirAC->index_buffer_intensity % hDirAC->no_col_avg_diff ) + 1; /* averaging_length = 32 */ + index = hDirAC->index_buffer_intensity; + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + /* only real part needed */ + mvr2r( intensity_real[i], &( hDirAC->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + } + mvr2r( reference_power[ts], &( hDirAC->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + + computeDiffuseness_mdft( hDirAC->buffer_intensity_real, hDirAC->buffer_energy, num_freq_bands, hDirAC->no_col_avg_diff, diffuseness_vector ); + + if ( hodirac_flag ) + { + calculate_hodirac_sector_parameters( + hDirAC, + Cldfb_RealBuffer, + Cldfb_ImagBuffer, + 0.20f, + hDirAC->band_grouping, + hDirAC->hConfig->nbands, + hDirAC->hConfig->enc_param_start_band, + azi_secs, + ele_secs, + diff_secs, + ene_secs ); + } + + if ( hodirac_flag ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; + renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + } + } + else + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); + + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; + renormalization_factor[band_m_idx] += norm_tmp; + + hDirAC->diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; + renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + } + } + } + + if ( !hodirac_flag ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + renormalization_factor[band_m_idx] = EPSILON; + for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + { + renormalization_factor[band_m_idx] += ( hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] * hDirAC->direction_vector_m[d][block_m_idx][band_m_idx] ); + } + renormalization_factor[band_m_idx] = sqrtf( renormalization_factor[band_m_idx] ); + + if ( renormalization_factor[band_m_idx] > EPSILON ) + { + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] /= renormalization_factor[band_m_idx]; + } + else + { + hDirAC->direction_vector_m[0][block_m_idx][band_m_idx] = 1; + hDirAC->direction_vector_m[1][block_m_idx][band_m_idx] = 0; + hDirAC->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + } + + /* save the elevation and azimuth values to be used later by the ivas_dirac_QuantizeParameters function */ + for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + { + dir_v[d] = hDirAC->direction_vector_m[d][block_m_idx][band_m_idx]; + } + +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + Word16 q_dir_e = 0; + f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); + Scale_sig32( dir_v_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( + dir_v_fx, + Q31 - q_dir_e, + &q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], + &q_direction->band_data[band_m_idx].elevation_fx[block_m_idx] ); + + /*==========================================fix-2-flt======================================================*/ + q_direction->band_data[band_m_idx].azimuth[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].azimuth_fx[block_m_idx], Q22 ); + q_direction->band_data[band_m_idx].elevation[block_m_idx] = fixedToFloat( q_direction->band_data[band_m_idx].elevation_fx[block_m_idx], Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_direction_vector_to_azimuth_elevation( + dir_v, + &q_direction->band_data[band_m_idx].azimuth[block_m_idx], + &q_direction->band_data[band_m_idx].elevation[block_m_idx] ); +#endif + } + } + + /* Sectors */ + if ( hodirac_flag ) + { + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + q_direction->band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[band_m_idx]; + q_direction->band_data[band_m_idx].elevation[block_m_idx] = ele_secs[band_m_idx]; + // q_direction->band_data[band_m_idx].energy_ratio[block_m_idx] = 1.f - diffuseness_vector[band_m_idx]; // set later + + q_direction[1].band_data[band_m_idx].azimuth[block_m_idx] = azi_secs[num_freq_bands + band_m_idx]; + q_direction[1].band_data[band_m_idx].elevation[block_m_idx] = ele_secs[num_freq_bands + band_m_idx]; + q_direction[1].band_data[band_m_idx].energy_ratio[block_m_idx] = ( 1.f - diff_secs[band_m_idx] ) / ( ( 1.f - diff_secs[band_m_idx] ) + ( 1.f - diff_secs[num_freq_bands + band_m_idx] ) + EPSILON ); + } + } + } + + /* Diffuseness */ + for ( band_m_idx = 0; band_m_idx < hDirAC->hConfig->nbands; band_m_idx++ ) + { + if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + { + hDirAC->diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + } + else + { + hDirAC->diffuseness_m[band_m_idx] = 0.f; + } + + /* set coherence to zero and convert diffuseness to energy ratio*/ + + set_f( q_direction->band_data[band_m_idx].energy_ratio, 1.f - hDirAC->diffuseness_m[band_m_idx], q_direction->cfg.nblocks ); + + for ( block_m_idx = 0; block_m_idx < q_direction->cfg.nblocks; block_m_idx++ ) + { + if ( q_direction->coherence_band_data != NULL ) + { + q_direction->coherence_band_data[band_m_idx].spread_coherence[block_m_idx] = 0; + } + } + } + + pop_wmops(); + return; +} +#else void ivas_dirac_param_est_enc( DIRAC_ENC_HANDLE hDirAC, IVAS_QDIRECTION *q_direction, @@ -869,6 +1332,7 @@ void ivas_dirac_param_est_enc( pop_wmops(); return; } +#endif /*------------------------------------------------------------------------- diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 6f10ae187..2445f2e0d 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -39,6 +39,8 @@ #include "ivas_stat_enc.h" #include "wmc_auto.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #ifdef IVAS_FLOAT_FIXED #include "prot_fx1.h" #include "prot_fx2.h" @@ -241,6 +243,7 @@ void ivas_masa_enc_close( * main MASA encoder function *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_masa_encode( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -584,6 +587,378 @@ ivas_error ivas_masa_encode( *nb_bits_metadata = hMetaData->nb_bits_tot; + if ( ivas_format == MASA_FORMAT && Opt_DTX_ON ) + { + /* save old values */ + uint8_t numCodingBands = hMasa->config.numCodingBands; + uint8_t numTwoDirBands = hMasa->config.numTwoDirBands; + int16_t nbands = hQMetaData->q_direction[0].cfg.nbands; + uint8_t numberOfDirections = hMasa->config.numberOfDirections; + uint8_t numberOfDirectionsMeta = hMasa->masaMetadata.descriptive_meta.numberOfDirections; + uint16_t numberOfDirectionsQMetaData = hQMetaData->no_directions; + + if ( !( hMasa->config.numberOfDirections == 1 && hQMetaData->q_direction->cfg.nbands == 5 ) ) + { + for ( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) + { + for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + mvr2r( h_orig_metadata[i].azimuth[j], hMasa->masaMetadata.directional_meta[i].azimuth[j], MASA_FREQUENCY_BANDS ); + mvr2r( h_orig_metadata[i].elevation[j], hMasa->masaMetadata.directional_meta[i].elevation[j], MASA_FREQUENCY_BANDS ); + mvr2r( h_orig_metadata[i].energy_ratio[j], hMasa->masaMetadata.directional_meta[i].energy_ratio[j], MASA_FREQUENCY_BANDS ); + } + } + + /* Force to have 5 bands and 1 direction */ + hMasa->config.numCodingBands = 5; + hMasa->config.numTwoDirBands = 0; + combine_freqbands_and_subframes( hMasa ); + hQMetaData->q_direction[0].cfg.nbands = 5; + + if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands ) + { + /* Combine directions */ + ivas_masa_combine_directions( hMasa ); + + /* If we joined all bands, then metadata is now one directional. */ + if ( hMasa->config.numTwoDirBands == 0 ) + { + hMasa->config.numberOfDirections = 1; + hMasa->masaMetadata.descriptive_meta.numberOfDirections = 0; + hQMetaData->no_directions = 1; + } + } + + move_metadata_to_qmetadata( hMasa, hQMetaData ); + + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] = floatToFixed( hQMetaData->q_direction[0].band_data[j].energy_ratio[0], Q30 ); + /*=====================================flt-2-fix============================================*/ + + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +#else + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[0] = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); +#endif + } + } + + free( h_orig_metadata ); + + ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, masa_sid_descriptor, ivas_format ); + + /* restore old values */ + hMasa->config.numCodingBands = numCodingBands; + hMasa->config.numTwoDirBands = numTwoDirBands; + hQMetaData->q_direction[0].cfg.nbands = nbands; + hMasa->config.numberOfDirections = numberOfDirections; + hMasa->masaMetadata.descriptive_meta.numberOfDirections = numberOfDirectionsMeta; + hQMetaData->no_directions = numberOfDirectionsQMetaData; + } + + return IVAS_ERR_OK; +} +#else +ivas_error ivas_masa_encode( + MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder structure */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + int16_t *nb_bits_metadata, /* o : number of metadata bits written */ + const int16_t nchan_transport, /* i : number of MASA input/transport channels */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + const int16_t Opt_DTX_ON, /* i : DTX on flag */ + const int16_t element_mode, /* i : element mode */ + const ISM_MODE ism_mode, /* i : ISM format mode */ + const int16_t nchan_ism, /* i : number of ISM channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata handle */ + const int16_t idx_separated_object, /* i : index of the separated object */ + OMASA_ENC_HANDLE hOMasa, /* i : OMASA encoder handle */ + const int16_t ism_imp, /* i : importance of separated object */ + const int16_t flag_omasa_ener_brate /* i : less bitrate for objects in OMASA flag */ +) +{ + MASA_DIRECTIONAL_SPATIAL_META *h_orig_metadata; + int16_t i, j; + int16_t masa_sid_descriptor; + int16_t low_bitrate_mode; + int32_t masa_total_brate; + ivas_error error; + + masa_sid_descriptor = -1; + h_orig_metadata = NULL; + low_bitrate_mode = 0; + + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + { + /* Create the MASA SID descriptor for the metadata and CPE mode, in order to have the SID frame self-contained. */ + if ( Opt_DTX_ON && hQMetaData != NULL ) + { + if ( nchan_transport == 2 ) /* this is MASA format in CPE only */ + { + masa_sid_descriptor = 0; /* for IVAS_CPE_DFT */ + if ( element_mode == IVAS_CPE_MDCT ) + { + masa_sid_descriptor = 1; + } + } + } + + /* Validate and compensate ratios as necessary */ + compensate_energy_ratios( hMasa ); + + if ( Opt_DTX_ON ) + { + if ( ( h_orig_metadata = (MASA_DIRECTIONAL_SPATIAL_META *) malloc( MASA_MAXIMUM_DIRECTIONS * sizeof( MASA_DIRECTIONAL_SPATIAL_META ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA encoder\n" ) ); + } + + for ( i = 0; i < MASA_MAXIMUM_DIRECTIONS; i++ ) + { + for ( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) + { + mvr2r( hMasa->masaMetadata.directional_meta[i].azimuth[j], h_orig_metadata[i].azimuth[j], MASA_FREQUENCY_BANDS ); + mvr2r( hMasa->masaMetadata.directional_meta[i].elevation[j], h_orig_metadata[i].elevation[j], MASA_FREQUENCY_BANDS ); + mvr2r( hMasa->masaMetadata.directional_meta[i].energy_ratio[j], h_orig_metadata[i].energy_ratio[j], MASA_FREQUENCY_BANDS ); + mvs2s( (int16_t *) ( hMasa->masaMetadata.directional_meta[i].spherical_index[j] ), (int16_t *) ( h_orig_metadata[i].spherical_index[j] ), MASA_FREQUENCY_BANDS ); + } + } + } + + if ( ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) && ivas_total_brate >= IVAS_384k ) + { + hMasa->config.mergeRatiosOverSubframes = 0; + } + + /* Combine frequency bands and sub-frames */ + combine_freqbands_and_subframes( hMasa ); + } + + if ( hMasa->config.numberOfDirections == 2 && hMasa->config.numTwoDirBands < hMasa->config.numCodingBands && ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) ) + { + if ( ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) || ( ivas_format != MASA_ISM_FORMAT ) ) + { + /* Combine directions */ + ivas_masa_combine_directions( hMasa ); + } + + /* If we joined all bands, then metadata is now one directional. */ + if ( hMasa->config.numTwoDirBands == 0 ) + { + hMasa->config.numberOfDirections = 1; + hMasa->masaMetadata.descriptive_meta.numberOfDirections = 0; + hQMetaData->no_directions = 1; + } + } + + /* Reset qmetadata bit budget */ + hQMetaData->metadata_max_bits = hMasa->config.max_metadata_bits; + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + { + if ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE ) + { + /* write the number of objects in ISM_MASA format*/ + push_next_indice( hMetaData, nchan_ism - 1, NO_BITS_MASA_ISM_NO_OBJ ); + hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + + /* write index of separated object if needed */ + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && nchan_ism > 1 ) + { + push_next_indice( hMetaData, idx_separated_object, NO_BITS_MASA_ISM_NO_OBJ ); + hQMetaData->metadata_max_bits -= NO_BITS_MASA_ISM_NO_OBJ; + } + + /* write ISM importance flag (one per object) */ + if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + } + else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( hIsmMetaData[0]->ism_md_null_flag ) + { + /* signal NULL metadata frame */ + push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + + /* write the ISM class to ISM_NO_META and again the true ISM class */ + push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + } + else + { + push_next_indice( hMetaData, hIsmMetaData[0]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + + if ( hIsmMetaData[0]->ism_imp == ISM_NO_META ) + { + /* signal low-rate ISM_NO_META frame */ + push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + + /* signal presence of MD in low-rate ISM_NO_META frame */ + push_next_indice( hMetaData, hIsmMetaData[0]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; + } + } + } + else if ( ism_mode == ISM_MASA_MODE_DISC ) + { + for ( i = 0; i < nchan_ism; i++ ) + { + if ( hIsmMetaData[i]->ism_md_null_flag ) + { + /* signal NULL metadata frame */ + push_next_indice( hMetaData, 1, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + + /* write the ISM class to ISM_NO_META and again the true ISM class */ + push_next_indice( hMetaData, ISM_NO_META, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + } + else + { + push_next_indice( hMetaData, hIsmMetaData[i]->ism_imp, ISM_METADATA_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_FLAG_BITS; + + if ( hIsmMetaData[i]->ism_imp == ISM_NO_META ) + { + /* signal low-rate ISM_NO_META frame */ + push_next_indice( hMetaData, 0, ISM_METADATA_MD_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_MD_FLAG_BITS; + + /* signal presence of MD in low-rate ISM_NO_META frame */ + push_next_indice( hMetaData, hIsmMetaData[i]->ism_md_lowrate_flag, ISM_METADATA_INACTIVE_FLAG_BITS ); + hQMetaData->metadata_max_bits -= ISM_METADATA_INACTIVE_FLAG_BITS; + } + } + } + + if ( ivas_total_brate == IVAS_128k && nchan_ism >= 3 ) + { + push_next_indice( hMetaData, flag_omasa_ener_brate, 1 ); + hQMetaData->metadata_max_bits -= 1; + } + } + } + else + { + /* write the number of MASA transport channels */ + push_next_indice( hMetaData, nchan_transport - 1, MASA_TRANSP_BITS ); + hQMetaData->metadata_max_bits -= MASA_TRANSP_BITS; + } + + if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MODE_NONE ) + { + /* signal MASA_ISM_FORMAT to decoder */ + push_next_indice( hMetaData, 1, 1 ); + /* write reserved bit */ + push_next_indice( hMetaData, 0, MASA_HEADER_BITS - 1 ); + hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + } + else + { + /* the MASA_ISM_FORMAT is not signalled here */ + /* write reserved bits */ + push_next_indice( hMetaData, 0, MASA_HEADER_BITS ); + hQMetaData->metadata_max_bits -= MASA_HEADER_BITS; + } + /* write number of directions */ + push_next_indice( hMetaData, hQMetaData->no_directions - 1, 1 ); + hQMetaData->metadata_max_bits -= 1; + + /* write subframe mode */ + push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_SUBFRAME_BITS ); + hQMetaData->metadata_max_bits -= MASA_SUBFRAME_BITS; + } + + if ( ivas_format == MC_FORMAT ) + { + int16_t lfeBitsWritten; + lfeBitsWritten = encode_lfe_to_total_energy_ratio( hMasa, hMetaData, ivas_total_brate ); + hQMetaData->metadata_max_bits -= lfeBitsWritten; + } + + /* Move data from encoder to qmetadata */ + if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT ) + { + move_metadata_to_qmetadata( hMasa, hQMetaData ); + } + + if ( hMasa->config.max_metadata_bits < MINIMUM_BIT_BUDGET_NORMAL_META && !hMasa->config.joinedSubframes ) + { + reduce_metadata_further( hMasa, hQMetaData, ivas_format ); + + low_bitrate_mode = ( ivas_total_brate <= 32000 ); + + /* Write low bitrate mode. 1 signals that we have merged through time, 0 signals merge through frequency. */ + push_next_indice( hMetaData, hQMetaData->q_direction[0].cfg.nblocks == 1 ? 1 : 0, MASA_LOWBITRATE_MODE_BITS ); + hQMetaData->metadata_max_bits -= MASA_LOWBITRATE_MODE_BITS; + } + + /* Encode MASA+ISM metadata */ + if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + /* encode MASA/ISM energy ratios */ + ivas_encode_masaism_metadata( hMasa, hQMetaData, hMetaData, hIsmMetaData, nchan_ism, low_bitrate_mode, hOMasa->nCodingBands, hOMasa->nSubframes, idx_separated_object, ism_imp ); + } + else + { + if ( ivas_format == MASA_ISM_FORMAT ) + { + hMasa->data.hOmasaData->masa_to_total_energy_ratio[0][0] = -1; /* signals NOT to adjust the energy ratios */ + } + } + + /* Encode metadata */ + masa_total_brate = ivas_total_brate; + + if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_DISC ) + { + masa_total_brate = calculate_cpe_brate_MASA_ISM( ism_mode, ivas_total_brate, nchan_ism ); + } + + if ( masa_total_brate >= IVAS_384k ) + { + if ( masa_total_brate >= IVAS_512k ) + { + if ( ( error = ivas_qmetadata_enc_encode_hr_384_512( hMetaData, hQMetaData, 16, 4 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + if ( ( error = ivas_qmetadata_enc_encode_hr_384_512( hMetaData, hQMetaData, 11, 3 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else + { + if ( ( error = ivas_qmetadata_enc_encode( hMetaData, hQMetaData, 0 ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ivas_format == MASA_ISM_FORMAT && ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + /* Modify spatial metadata based on the MASA-to-total energy ratios */ + ivas_omasa_modify_masa_energy_ratios( hQMetaData, hMasa->data.hOmasaData->masa_to_total_energy_ratio ); + } + + *nb_bits_metadata = hMetaData->nb_bits_tot; + if ( ivas_format == MASA_FORMAT && Opt_DTX_ON ) { /* save old values */ @@ -649,6 +1024,7 @@ ivas_error ivas_masa_encode( return IVAS_ERR_OK; } +#endif /*-----------------------------------------------------------------------* @@ -3671,11 +4047,10 @@ static void ivas_encode_masaism_metadata( reconstruct_ism_ratios( ratio_ism_idx[band], nchan_ism, step, hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band] ); #else Word16 step_fx = float_to_fix16( step, Q15 ); - floatToFixed_arr32( hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], Q30, MAX_NUM_OBJECTS ); reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, step_fx, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); - fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, MAX_NUM_OBJECTS ); + fixedToFloat_arrL( hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band], hMasa->data.hOmasaData->q_energy_ratio_ism[sf][band], Q30, nchan_ism ); #endif } diff --git a/lib_enc/ivas_mcmasa_enc.c b/lib_enc/ivas_mcmasa_enc.c index 56800005b..34f1c2249 100644 --- a/lib_enc/ivas_mcmasa_enc.c +++ b/lib_enc/ivas_mcmasa_enc.c @@ -36,8 +36,11 @@ #include #include "ivas_cnst.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "options.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" @@ -731,6 +734,7 @@ void ivas_mcmasa_enc( * Estimate metadata parameters for McMASA *--------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED void ivas_mcmasa_param_est_enc( MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ @@ -748,6 +752,11 @@ void ivas_mcmasa_param_est_enc( int16_t ts, i, j, d; int16_t num_freq_bins, num_freq_bands, index; float dir_v[DIRAC_NUM_DIMS]; +#ifdef IVAS_FLOAT_FIXED_ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 dir_v_fx[DIRAC_NUM_DIMS]; +#endif int16_t l_ts; float *pcm_in[MCMASA_MAX_ANA_CHANS]; float Chnl_RealBuffer[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; @@ -1038,7 +1047,22 @@ void ivas_mcmasa_param_est_enc( { dir_v[d] = hMcMasa->direction_vector_m[d][block_m_idx][band_m_idx]; } +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + Word16 q_dir_e = 0; + f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); + Scale_sig32( dir_v_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, Q30, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); + + /*==========================================fix-2-flt======================================================*/ + azimuth_m_values[block_m_idx][band_m_idx] = fixedToFloat( azimuth_m_values_fx[block_m_idx][band_m_idx], Q22 ); + elevation_m_values[block_m_idx][band_m_idx] = fixedToFloat( elevation_m_values_fx[block_m_idx][band_m_idx], Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else ivas_qmetadata_direction_vector_to_azimuth_elevation( dir_v, &azimuth_m_values[block_m_idx][band_m_idx], &elevation_m_values[block_m_idx][band_m_idx] ); +#endif } /* Coherence processing */ @@ -1243,6 +1267,520 @@ void ivas_mcmasa_param_est_enc( return; } +#else +void ivas_mcmasa_param_est_enc( + MCMASA_ENC_HANDLE hMcMasa, /* i : McMASA encoder structure */ + MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder structure */ + float *data_f[], /* i : Audio frame in MC-format */ + float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated elevation */ + float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated azimuth */ + float energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated direct-to-total ratio */ + float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated spread coherence */ + float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* o : Estimated surround coherence */ + const int16_t input_frame, /* i : Input frame size */ + const int16_t nchan_inp /* i : Number of input channels */ +) +{ + float reference_power[MDFT_NO_COL_MAX][DIRAC_NO_FB_BANDS_MAX]; + int16_t ts, i, j, d; + int16_t num_freq_bins, num_freq_bands, index; + float dir_v[DIRAC_NUM_DIMS]; + int16_t l_ts; + float *pcm_in[MCMASA_MAX_ANA_CHANS]; + float Chnl_RealBuffer[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + float Chnl_ImagBuffer[MCMASA_MAX_ANA_CHANS][DIRAC_NO_FB_BANDS_MAX]; + float *p_Chnl_RealBuffer[MCMASA_MAX_ANA_CHANS]; + float *p_Chnl_ImagBuffer[MCMASA_MAX_ANA_CHANS]; + float Foa_RealBuffer[FOA_CHANNELS][DIRAC_NO_FB_BANDS_MAX]; + float Foa_ImagBuffer[FOA_CHANNELS][DIRAC_NO_FB_BANDS_MAX]; + float FoaEven_RealBuffer[FOA_CHANNELS][DIRAC_NO_FB_BANDS_MAX]; + float FoaEven_ImagBuffer[FOA_CHANNELS][DIRAC_NO_FB_BANDS_MAX]; + float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + float intensity_even_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + float direction_vector[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + float diffuseness_vector[MASA_FREQUENCY_BANDS]; + float vertical_diffuseness_vector[MASA_FREQUENCY_BANDS]; + float diffuseness_m[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + float coherentEnergyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + int16_t band_m_idx, block_m_idx; + float renormalization_factor_diff[MASA_FREQUENCY_BANDS]; + float norm_tmp; + int16_t mrange[2], brange[2]; + int16_t numSubFramesForRatio; + CovarianceMatrix COVls[MASA_FREQUENCY_BANDS]; + float absCOVls[MCMASA_MAX_ANA_CHANS][MCMASA_MAX_ANA_CHANS]; + float lsEnergy[MCMASA_MAX_ANA_CHANS]; + float lsEnergySum, maxEne; + int16_t loudestCh; + float surrCoh, tempCoh, tempCoh2; + int16_t i1, i2, i3; + float angleDist, minAngleDist; + float currentAzi; + float lsEnergyRelation; + float tempLsEnergyRelation; + float stereoness, cohwideness, spreadCoh; + float stereoRatio, cohPanRatio; + float stereoCoh, cohPanCoh, cohRatio; + float renormalization_factor_coh[MASA_FREQUENCY_BANDS]; + int16_t numAnalysisChannels; + + num_freq_bins = input_frame / MDFT_NO_COL_MAX; + num_freq_bands = hMcMasa->nbands; + l_ts = input_frame / MDFT_NO_COL_MAX; + + numAnalysisChannels = nchan_inp - 1; + if ( hMcMasa->separateChannelEnabled ) + { + numAnalysisChannels = nchan_inp - 2; + } + + if ( hMcMasa->combineRatios ) + { + /* Need to initialize renormalization_factors, and variables to be normalized */ + set_zero( renormalization_factor_diff, hMcMasa->nbands ); + set_zero( diffuseness_m[0], hMcMasa->nbands ); + set_zero( renormalization_factor_coh, hMcMasa->nbands ); + set_zero( surroundingCoherence[0], hMcMasa->nbands ); + set_zero( coherentEnergyRatio[0], hMcMasa->nbands ); + } + + /* Copy current frame to memory for delay compensation */ + for ( i = 0; i < numAnalysisChannels; i++ ) + { + pcm_in[i] = data_f[i]; + p_Chnl_RealBuffer[i] = &Chnl_RealBuffer[i][0]; + p_Chnl_ImagBuffer[i] = &Chnl_ImagBuffer[i][0]; + } + + /* do processing over all CLDFB time slots */ + for ( block_m_idx = 0; block_m_idx < MAX_PARAM_SPATIAL_SUBFRAMES; block_m_idx++ ) + { + mrange[0] = hMcMasa->block_grouping[block_m_idx]; + mrange[1] = hMcMasa->block_grouping[block_m_idx + 1]; + + for ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + { + hMcMasa->direction_vector_m[0][block_m_idx][band_m_idx] = 0; + hMcMasa->direction_vector_m[1][block_m_idx][band_m_idx] = 0; + hMcMasa->direction_vector_m[2][block_m_idx][band_m_idx] = 0; + } + + /* Reset variable */ + for ( i = 0; i < hMcMasa->nbands; i++ ) + { + for ( j = 0; j < numAnalysisChannels; j++ ) + { + set_zero( COVls[i].xr[j], numAnalysisChannels ); + set_zero( COVls[i].xi[j], numAnalysisChannels ); + } + } + + for ( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + ivas_fb_mixer_get_windowed_fr( hMcMasa->hFbMixer, pcm_in, p_Chnl_RealBuffer, p_Chnl_ImagBuffer, l_ts, l_ts, hMcMasa->hFbMixer->fb_cfg->num_in_chans ); + + ivas_fb_mixer_update_prior_input( hMcMasa->hFbMixer, pcm_in, l_ts, hMcMasa->hFbMixer->fb_cfg->num_in_chans ); + + for ( i = 0; i < numAnalysisChannels; i++ ) + { + pcm_in[i] += l_ts; + } + + /* Compute covariance matrix */ + for ( i = 0; i < num_freq_bands; i++ ) + { + brange[0] = hMcMasa->band_grouping[i]; + brange[1] = hMcMasa->band_grouping[i + 1]; + for ( j = brange[0]; j < brange[1]; j++ ) + { + compute_cov_mtx( Chnl_RealBuffer, Chnl_ImagBuffer, j, numAnalysisChannels, &( COVls[i] ) ); + } + + /* Store energies for guiding metadata encoding */ + hMasa->data.energy[block_m_idx][i] = 0.0f; + for ( j = 0; j < numAnalysisChannels; j++ ) + { + hMasa->data.energy[block_m_idx][i] += COVls[i].xr[j][j]; + } + } + + if ( !hMcMasa->separateChannelEnabled ) + { + /* Compute low frequency energy */ + for ( i = 0; i < numAnalysisChannels; i++ ) + { + for ( j = 0; j < CLDFB_TO_MDFT_FAC; j++ ) + { + hMcMasa->totalLfEne[block_m_idx] += Chnl_RealBuffer[i][j] * Chnl_RealBuffer[i][j] + Chnl_ImagBuffer[i][j] * Chnl_ImagBuffer[i][j]; + } + } + } + + /* Compute standard FOA */ + /* W */ + v_add( Chnl_RealBuffer[0], Chnl_RealBuffer[1], Foa_RealBuffer[0], num_freq_bins ); + v_add( Chnl_ImagBuffer[0], Chnl_ImagBuffer[1], Foa_ImagBuffer[0], num_freq_bins ); + for ( i = 2; i < numAnalysisChannels; i++ ) + { + v_add( Chnl_RealBuffer[i], Foa_RealBuffer[0], Foa_RealBuffer[0], num_freq_bins ); + v_add( Chnl_ImagBuffer[i], Foa_ImagBuffer[0], Foa_ImagBuffer[0], num_freq_bins ); + } + + /* Y */ + v_multc( Chnl_RealBuffer[0], hMcMasa->chnlToFoaMtx[1][0], Foa_RealBuffer[1], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hMcMasa->chnlToFoaMtx[1][0], Foa_ImagBuffer[1], num_freq_bins ); + for ( i = 1; i < numAnalysisChannels; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hMcMasa->chnlToFoaMtx[1][i], Foa_RealBuffer[1], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hMcMasa->chnlToFoaMtx[1][i], Foa_ImagBuffer[1], num_freq_bins ); + } + + /* Z */ + if ( hMcMasa->isHorizontalSetup ) + { + /* Set zero for horizontal setups */ + set_zero( Foa_RealBuffer[2], num_freq_bins ); + set_zero( Foa_ImagBuffer[2], num_freq_bins ); + } + else + { + v_multc( Chnl_RealBuffer[0], hMcMasa->chnlToFoaMtx[2][0], Foa_RealBuffer[2], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hMcMasa->chnlToFoaMtx[2][0], Foa_ImagBuffer[2], num_freq_bins ); + for ( i = 1; i < numAnalysisChannels; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hMcMasa->chnlToFoaMtx[2][i], Foa_RealBuffer[2], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hMcMasa->chnlToFoaMtx[2][i], Foa_ImagBuffer[2], num_freq_bins ); + } + } + + /* X */ + v_multc( Chnl_RealBuffer[0], hMcMasa->chnlToFoaMtx[3][0], Foa_RealBuffer[3], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hMcMasa->chnlToFoaMtx[3][0], Foa_ImagBuffer[3], num_freq_bins ); + for ( i = 1; i < numAnalysisChannels; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hMcMasa->chnlToFoaMtx[3][i], Foa_RealBuffer[3], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hMcMasa->chnlToFoaMtx[3][i], Foa_ImagBuffer[3], num_freq_bins ); + } + + /* Compute even FOA */ + /* W */ + mvr2r( Foa_RealBuffer[0], FoaEven_RealBuffer[0], num_freq_bins ); + mvr2r( Foa_ImagBuffer[0], FoaEven_ImagBuffer[0], num_freq_bins ); + + /* Y */ + v_multc( Chnl_RealBuffer[0], hMcMasa->chnlToFoaEvenMtx[1][0], FoaEven_RealBuffer[1], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hMcMasa->chnlToFoaEvenMtx[1][0], FoaEven_ImagBuffer[1], num_freq_bins ); + for ( i = 1; i < numAnalysisChannels; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hMcMasa->chnlToFoaEvenMtx[1][i], FoaEven_RealBuffer[1], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hMcMasa->chnlToFoaEvenMtx[1][i], FoaEven_ImagBuffer[1], num_freq_bins ); + } + + /* Z (even setups are handled as horizontal) */ + set_zero( FoaEven_RealBuffer[2], num_freq_bins ); + set_zero( FoaEven_ImagBuffer[2], num_freq_bins ); + + /* X */ + v_multc( Chnl_RealBuffer[0], hMcMasa->chnlToFoaEvenMtx[3][0], FoaEven_RealBuffer[3], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hMcMasa->chnlToFoaEvenMtx[3][0], FoaEven_ImagBuffer[3], num_freq_bins ); + for ( i = 1; i < numAnalysisChannels; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hMcMasa->chnlToFoaEvenMtx[3][i], FoaEven_RealBuffer[3], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hMcMasa->chnlToFoaEvenMtx[3][i], FoaEven_ImagBuffer[3], num_freq_bins ); + } + + /* Direction estimation */ + computeIntensityVector_enc( + hMcMasa->band_grouping, + Foa_RealBuffer, + Foa_ImagBuffer, + 0, + num_freq_bands, + intensity_real ); + + computeDirectionVectors( + intensity_real[0], + intensity_real[1], + intensity_real[2], + 0, + num_freq_bands, + direction_vector[0], + direction_vector[1], + direction_vector[2] ); + + /* Power and intensity estimation for diffuseness */ + computeIntensityVector_enc( + hMcMasa->band_grouping, + FoaEven_RealBuffer, + FoaEven_ImagBuffer, + 0, + num_freq_bands, + intensity_even_real ); + + computeReferencePower_enc( hMcMasa->band_grouping, + FoaEven_RealBuffer, + FoaEven_ImagBuffer, + reference_power[ts], + 0, + num_freq_bands, + MC_FORMAT, + 0, + FOA_CHANNELS, + NULL, + NULL ); + + /* Fill buffers of length "averaging_length" time slots for intensity and energy */ + hMcMasa->index_buffer_intensity = ( hMcMasa->index_buffer_intensity % hMcMasa->no_col_avg_diff ) + 1; /* averaging_length = 32 */ + index = hMcMasa->index_buffer_intensity; + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + /* only real part needed */ + mvr2r( intensity_even_real[i], &( hMcMasa->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + } + mvr2r( reference_power[ts], &( hMcMasa->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + + computeDiffuseness_mdft( hMcMasa->buffer_intensity_real, hMcMasa->buffer_energy, num_freq_bands, hMcMasa->no_col_avg_diff, diffuseness_vector ); + + /* Compute vertical diffuseness, and tune original diffuseness if needed */ + if ( !hMcMasa->isHorizontalSetup ) + { + mvr2r( intensity_real[2], &( hMcMasa->buffer_intensity_real_vert[index - 1][0] ), num_freq_bands ); + computeVerticalDiffuseness( hMcMasa->buffer_intensity_real_vert, hMcMasa->buffer_energy, hMcMasa->no_col_avg_diff, num_freq_bands, vertical_diffuseness_vector ); + v_min( diffuseness_vector, vertical_diffuseness_vector, diffuseness_vector, num_freq_bands ); + } + + for ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + { + norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); + + hMcMasa->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; + hMcMasa->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; + hMcMasa->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; + + if ( hMcMasa->combineRatios ) + { + diffuseness_m[0][band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; + renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + } + else + { + diffuseness_m[block_m_idx][band_m_idx] = diffuseness_vector[band_m_idx]; + } + } + } + + for ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + { + for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + { + dir_v[d] = hMcMasa->direction_vector_m[d][block_m_idx][band_m_idx]; + } + ivas_qmetadata_direction_vector_to_azimuth_elevation( dir_v, &azimuth_m_values[block_m_idx][band_m_idx], &elevation_m_values[block_m_idx][band_m_idx] ); + } + + /* Coherence processing */ + for ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + { + /* Compute absolute values */ + for ( i = 0; i < numAnalysisChannels; i++ ) + { + for ( j = i; j < numAnalysisChannels; j++ ) + { + absCOVls[i][j] = sqrtf( ( COVls[band_m_idx].xr[i][j] * COVls[band_m_idx].xr[i][j] + COVls[band_m_idx].xi[i][j] * COVls[band_m_idx].xi[i][j] ) ); + } + lsEnergy[i] = absCOVls[i][i]; + } + + /* Find loudest channel */ + maxEne = lsEnergy[0]; + loudestCh = 0; + for ( i = 1; i < numAnalysisChannels; i++ ) + { + if ( lsEnergy[i] > maxEne ) + { + maxEne = lsEnergy[i]; + loudestCh = i; + } + } + + /* Compute surrounding coherence */ + surrCoh = 1.0f; + for ( i = 0; i < numAnalysisChannels; i++ ) + { + if ( i != loudestCh ) + { + if ( i < loudestCh ) + { + i1 = i; + i2 = loudestCh; + } + else + { + i1 = loudestCh; + i2 = i; + } + tempCoh = absCOVls[i1][i2] / ( sqrtf( ( lsEnergy[i1] * lsEnergy[i2] + EPSILON ) ) ); + surrCoh = ( surrCoh < tempCoh ) ? surrCoh : tempCoh; + } + } + surrCoh = surrCoh * surrCoh; + surrCoh = ( surrCoh < 1.0f ) ? surrCoh : 1.0f; + surrCoh = ( surrCoh > 0.0f ) ? surrCoh : 0.0f; + + /* Compute spread coherence */ + if ( elevation_m_values[block_m_idx][band_m_idx] < NEAR_HORIZONTAL_PLANE_ELEVATION ) /* Computed only near horizontal plane */ + { + minAngleDist = 180.0f; + i1 = 0; + currentAzi = azimuth_m_values[block_m_idx][band_m_idx]; + for ( i = 0; i < hMcMasa->numHorizontalChannels; i++ ) + { + angleDist = fabsf( currentAzi - hMcMasa->ls_azimuth[i] ); + if ( angleDist > 180.0f ) + { + angleDist = fabsf( angleDist - 360.0f ); + } + if ( angleDist < minAngleDist ) + { + minAngleDist = angleDist; + i1 = i; + } + } + i2 = hMcMasa->leftNearest[i1]; + i3 = hMcMasa->rightNearest[i1]; + + if ( i2 < i3 ) + { + stereoCoh = absCOVls[i2][i3] / ( sqrtf( lsEnergy[i2] * lsEnergy[i3] + EPSILON ) ); + } + else + { + stereoCoh = absCOVls[i3][i2] / ( sqrtf( lsEnergy[i2] * lsEnergy[i3] + EPSILON ) ); + } + lsEnergyRelation = ( lsEnergy[i2] + lsEnergy[i3] ) / ( lsEnergy[i1] + lsEnergy[i2] + lsEnergy[i3] + EPSILON ); + stereoness = stereoCoh * lsEnergyRelation; + + if ( i1 < i2 ) + { + tempCoh = absCOVls[i1][i2] / ( sqrtf( lsEnergy[i1] * lsEnergy[i2] + EPSILON ) ); + } + else + { + tempCoh = absCOVls[i2][i1] / ( sqrtf( lsEnergy[i1] * lsEnergy[i2] + EPSILON ) ); + } + if ( i1 < i3 ) + { + tempCoh2 = absCOVls[i1][i3] / ( sqrtf( lsEnergy[i1] * lsEnergy[i3] + EPSILON ) ); + } + else + { + tempCoh2 = absCOVls[i3][i1] / ( sqrtf( lsEnergy[i1] * lsEnergy[i3] + EPSILON ) ); + } + cohPanCoh = ( tempCoh < tempCoh2 ) ? tempCoh : tempCoh2; + lsEnergyRelation = lsEnergy[i2] / ( lsEnergy[i1] + EPSILON ); + tempLsEnergyRelation = lsEnergy[i1] / ( lsEnergy[i2] + EPSILON ); + lsEnergyRelation = ( lsEnergyRelation < tempLsEnergyRelation ) ? lsEnergyRelation : tempLsEnergyRelation; + tempLsEnergyRelation = lsEnergy[i3] / ( lsEnergy[i1] + EPSILON ); + lsEnergyRelation = ( lsEnergyRelation < tempLsEnergyRelation ) ? lsEnergyRelation : tempLsEnergyRelation; + tempLsEnergyRelation = lsEnergy[i1] / ( lsEnergy[i3] + EPSILON ); + lsEnergyRelation = ( lsEnergyRelation < tempLsEnergyRelation ) ? lsEnergyRelation : tempLsEnergyRelation; + cohwideness = cohPanCoh * lsEnergyRelation; + + spreadCoh = ( cohwideness > stereoness ) ? cohwideness : stereoness; + if ( spreadCoh > 0.5f ) + { + if ( cohwideness > stereoness ) + { + tempCoh = stereoness - ( cohwideness - 0.5f ); + spreadCoh = ( tempCoh > 0.5f ) ? tempCoh : 0.5f; + } + } + spreadCoh = ( spreadCoh < 1.0f ) ? spreadCoh : 1.0f; + spreadCoh = ( spreadCoh > 0.0f ) ? spreadCoh : 0.0f; + + /* Compute energy ratio tuning parameter */ + lsEnergySum = sum_f( lsEnergy, numAnalysisChannels ) + EPSILON; + lsEnergyRelation = ( lsEnergy[i2] + lsEnergy[i3] ) / lsEnergySum; + stereoRatio = stereoCoh * lsEnergyRelation - surrCoh; + + lsEnergyRelation = ( lsEnergy[i1] + lsEnergy[i2] + lsEnergy[i3] ) / lsEnergySum; + cohPanRatio = cohPanCoh * lsEnergyRelation - surrCoh; + + cohRatio = ( stereoRatio > cohPanRatio ) ? stereoRatio : cohPanRatio; + cohRatio = ( cohRatio < 1.0f ) ? cohRatio : 1.0f; + cohRatio = ( cohRatio > 0.0f ) ? cohRatio : 0.0f; + } + else /* Otherwise, set spread coherence to zero */ + { + spreadCoh = 0.0f; + cohRatio = 0.0f; + lsEnergySum = sum_f( lsEnergy, numAnalysisChannels ); + } + + /* Store values */ + spreadCoherence[block_m_idx][band_m_idx] = spreadCoh; + + if ( hMcMasa->combineRatios ) + { + surroundingCoherence[0][band_m_idx] += lsEnergySum * surrCoh; + coherentEnergyRatio[0][band_m_idx] += lsEnergySum * cohRatio; + renormalization_factor_coh[band_m_idx] += lsEnergySum; + } + else + { + surroundingCoherence[block_m_idx][band_m_idx] = surrCoh; + coherentEnergyRatio[block_m_idx][band_m_idx] = cohRatio; + } + } + } + + if ( hMcMasa->combineRatios ) + { + for ( band_m_idx = 0; band_m_idx < hMcMasa->nbands; band_m_idx++ ) + { + if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + { + diffuseness_m[0][band_m_idx] /= renormalization_factor_diff[band_m_idx]; + } + else + { + diffuseness_m[0][band_m_idx] = 0.f; + } + if ( renormalization_factor_coh[band_m_idx] > EPSILON ) + { + surroundingCoherence[0][band_m_idx] /= renormalization_factor_coh[band_m_idx]; + coherentEnergyRatio[0][band_m_idx] /= renormalization_factor_coh[band_m_idx]; + } + else + { + surroundingCoherence[0][band_m_idx] = 0.f; + coherentEnergyRatio[0][band_m_idx] = 0.f; + } + } + } + + /* Determine energy ratios */ + if ( hMcMasa->combineRatios ) + { + numSubFramesForRatio = 1; + } + else + { + numSubFramesForRatio = MAX_PARAM_SPATIAL_SUBFRAMES; + } + + for ( i = 0; i < numSubFramesForRatio; i++ ) + { + for ( j = 0; j < hMcMasa->nbands; j++ ) + { + energyRatio[i][j] = 1.0f - diffuseness_m[i][j]; + energyRatio[i][j] = ( energyRatio[i][j] > coherentEnergyRatio[i][j] ) ? energyRatio[i][j] : coherentEnergyRatio[i][j]; + } + } + + return; +} +#endif /*--------------------------------------------------------------------------* diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index e09f42e78..cc18b15cf 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -38,6 +38,9 @@ #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*----------------------------------------------------------* @@ -260,16 +263,28 @@ void ivas_mct_core_enc( if ( switch_bw ) { +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[ch]->hStereoMdct, ivas_format, sts[ch_core]->element_mode, sts[ch_core]->element_brate, sts[ch_core]->bwidth, sts[ch_core]->igf, sts[ch_core]->hIGFEnc->igfData.igfInfo.grid, 0 ); +#else + initMdctStereoEncData_fx( hMCT->hBlockData[ch]->hStereoMdct, ivas_format, sts[ch_core]->element_mode, sts[ch_core]->element_brate, sts[ch_core]->bwidth, + sts[ch_core]->igf, sts[ch_core]->hIGFEnc->igfData.igfInfo.grid, 0 ); +#endif } if ( sts[ch_core]->igf ) { +#ifndef IVAS_FLOAT_FIXED /* calculate the igf start band from the igf start line */ stereo_mdct_init_igf_start_band( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20, 1.0f, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); stereo_mdct_init_igf_start_band( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10, 0.5f, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); +#else + /* calculate the igf start band from the igf start line */ + stereo_mdct_init_igf_start_band_fx( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX20, 16384 /* 1.0f in Q14 */, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); + + stereo_mdct_init_igf_start_band_fx( &hMCT->hBlockData[ch]->hStereoMdct->stbParamsTCX10, 8192 /* 0.5f in Q14 */, sts[ch_core]->bwidth, sts[ch_core]->total_brate ); +#endif } else { diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 49364ad7f..e0e9d5cbc 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -224,7 +224,11 @@ ivas_error ivas_mct_enc( for ( n = 0; n < (int16_t) ( hMCT->nchan_out_woLFE * 0.5 ); n++ ) { +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 0 ); +#else + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 0 ); +#endif } } @@ -375,7 +379,11 @@ ivas_error create_mct_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 1 ); +#else + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, 1 ); +#endif } for ( ; n < MCT_MAX_BLOCKS; n++ ) @@ -529,7 +537,11 @@ ivas_error mct_enc_reconfigure( } } +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, mem_init ); +#else + initMdctStereoEncData_fx( hMCT->hBlockData[n]->hStereoMdct, ivas_format, IVAS_CPE_MDCT, cp_bitrate, st_ivas->hEncoderConfig->max_bwidth, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->igf ? st_ivas->hCPE[0]->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid : NULL, mem_init ); +#endif } for ( ; n < MCT_MAX_BLOCKS; n++ ) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 102a8307b..1f5499f07 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -36,7 +36,10 @@ #include #include "ivas_cnst.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #include "ivas_rom_com.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" @@ -737,6 +740,216 @@ int16_t ivas_omasa_ener_brate( *--------------------------------------------------------------------------*/ /* Estimate MASA parameters from the objects */ +#ifdef IVAS_FLOAT_FIXED +static void ivas_omasa_param_est_enc( + OMASA_ENC_HANDLE hOMasa, + OMASA_ENCODER_DATA_HANDLE hOmasaData, + ISM_METADATA_HANDLE hIsmMeta[], + float *data_f[], + float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + float energyRatio[MASA_FREQUENCY_BANDS], + float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], + float surroundingCoherence[MASA_FREQUENCY_BANDS], + float diffuseness_m[MASA_FREQUENCY_BANDS], + const int16_t input_frame, + const int16_t nchan_ism ) +{ + float reference_power[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + int16_t ts, i, j, d, k; + int16_t num_freq_bins, num_freq_bands, index; + float dir_v[DIRAC_NUM_DIMS]; +#ifdef IVAS_FLOAT_FIXED_ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 dir_v_fx[DIRAC_NUM_DIMS]; +#endif + int16_t l_ts; + float Chnl_RealBuffer[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; + float Chnl_ImagBuffer[MCMASA_MAX_ANA_CHANS][CLDFB_NO_CHANNELS_MAX]; + float Foa_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float Foa_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + float intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + float direction_vector[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS]; + float diffuseness_vector[MASA_FREQUENCY_BANDS]; + int16_t band_m_idx, block_m_idx; + float renormalization_factor_diff[MASA_FREQUENCY_BANDS]; + float norm_tmp; + int16_t mrange[2], brange[2]; + + num_freq_bins = hOMasa->cldfbAnaEnc[0]->no_channels; + num_freq_bands = hOMasa->nbands; + l_ts = input_frame / CLDFB_NO_COL_MAX; + + /* Need to initialize renormalization_factors, and variables to be normalized */ + set_zero( renormalization_factor_diff, hOMasa->nbands ); + set_zero( diffuseness_m, hOMasa->nbands ); + + /* Compute ISM to FOA matrices */ + for ( i = 0; i < nchan_ism; i++ ) + { + hOMasa->chnlToFoaMtx[0][i] = 1.0f; + hOMasa->chnlToFoaMtx[1][i] = sinf( ( hIsmMeta[i]->azimuth / 180.0f * EVS_PI ) ) * cosf( ( hIsmMeta[i]->elevation / 180.0f * EVS_PI ) ); + hOMasa->chnlToFoaMtx[2][i] = sinf( ( hIsmMeta[i]->elevation / 180.0f * EVS_PI ) ); + hOMasa->chnlToFoaMtx[3][i] = cosf( ( hIsmMeta[i]->azimuth / 180.0f * EVS_PI ) ) * cosf( ( hIsmMeta[i]->elevation / 180.0f * EVS_PI ) ); + } + + /* do processing over all CLDFB time slots */ + for ( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) + { + mrange[0] = hOMasa->block_grouping[block_m_idx]; + mrange[1] = hOMasa->block_grouping[block_m_idx + 1]; + + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] = 0.0f; + hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] = 0.0f; + hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] = 0.0f; + } + + set_zero( hOmasaData->energy_ism[block_m_idx], num_freq_bands ); + + for ( ts = mrange[0]; ts < mrange[1]; ts++ ) + { + for ( i = 0; i < nchan_ism; i++ ) + { + cldfbAnalysis_ts_ivas( &( data_f[i][l_ts * ts] ), Chnl_RealBuffer[i], Chnl_ImagBuffer[i], l_ts, hOMasa->cldfbAnaEnc[i] ); + } + + /* Compute energy */ + for ( i = 0; i < num_freq_bands; i++ ) + { + brange[0] = hOMasa->band_grouping[i]; + brange[1] = hOMasa->band_grouping[i + 1]; + for ( j = brange[0]; j < brange[1]; j++ ) + { + for ( k = 0; k < nchan_ism; k++ ) + { + hOmasaData->energy_ism[block_m_idx][i] += Chnl_RealBuffer[k][j] * Chnl_RealBuffer[k][j] + Chnl_ImagBuffer[k][j] * Chnl_ImagBuffer[k][j]; + } + } + } + + /* Compute FOA */ + /* W */ + mvr2r( Chnl_RealBuffer[0], Foa_RealBuffer[0], num_freq_bins ); + mvr2r( Chnl_ImagBuffer[0], Foa_ImagBuffer[0], num_freq_bins ); + for ( i = 1; i < nchan_ism; i++ ) + { + v_add( Chnl_RealBuffer[i], Foa_RealBuffer[0], Foa_RealBuffer[0], num_freq_bins ); + v_add( Chnl_ImagBuffer[i], Foa_ImagBuffer[0], Foa_ImagBuffer[0], num_freq_bins ); + } + + /* Y */ + v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[1][0], Foa_RealBuffer[1], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[1][0], Foa_ImagBuffer[1], num_freq_bins ); + for ( i = 1; i < nchan_ism; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[1][i], Foa_RealBuffer[1], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[1][i], Foa_ImagBuffer[1], num_freq_bins ); + } + + /* Z */ + v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[2][0], Foa_RealBuffer[2], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[2][0], Foa_ImagBuffer[2], num_freq_bins ); + for ( i = 1; i < nchan_ism; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[2][i], Foa_RealBuffer[2], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[2][i], Foa_ImagBuffer[2], num_freq_bins ); + } + + /* X */ + v_multc( Chnl_RealBuffer[0], hOMasa->chnlToFoaMtx[3][0], Foa_RealBuffer[3], num_freq_bins ); + v_multc( Chnl_ImagBuffer[0], hOMasa->chnlToFoaMtx[3][0], Foa_ImagBuffer[3], num_freq_bins ); + for ( i = 1; i < nchan_ism; i++ ) + { + v_multc_acc( Chnl_RealBuffer[i], hOMasa->chnlToFoaMtx[3][i], Foa_RealBuffer[3], num_freq_bins ); + v_multc_acc( Chnl_ImagBuffer[i], hOMasa->chnlToFoaMtx[3][i], Foa_ImagBuffer[3], num_freq_bins ); + } + + /* Direction estimation */ + computeIntensityVector_enc( hOMasa->band_grouping, Foa_RealBuffer, Foa_ImagBuffer, num_freq_bands, intensity_real ); + computeDirectionVectors( intensity_real[0], intensity_real[1], intensity_real[2], 0, num_freq_bands, direction_vector[0], direction_vector[1], direction_vector[2] ); + + /* Power estimation for diffuseness */ + computeReferencePower_omasa( hOMasa->band_grouping, Foa_RealBuffer, Foa_ImagBuffer, reference_power[ts], 0, num_freq_bands ); + + /* Fill buffers of length "averaging_length" time slots for intensity and energy */ + hOMasa->index_buffer_intensity = ( hOMasa->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1; /* averaging_length = 32 */ + index = hOMasa->index_buffer_intensity; + for ( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + /* only real part needed */ + mvr2r( intensity_real[i], &( hOMasa->buffer_intensity_real[i][index - 1][0] ), num_freq_bands ); + } + mvr2r( reference_power[ts], &( hOMasa->buffer_energy[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + + computeDiffuseness( hOMasa->buffer_intensity_real, hOMasa->buffer_energy, num_freq_bands, diffuseness_vector ); + + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + norm_tmp = reference_power[ts][band_m_idx] * ( 1 - diffuseness_vector[band_m_idx] ); + + hOMasa->direction_vector_m[0][block_m_idx][band_m_idx] += norm_tmp * direction_vector[0][band_m_idx]; + hOMasa->direction_vector_m[1][block_m_idx][band_m_idx] += norm_tmp * direction_vector[1][band_m_idx]; + hOMasa->direction_vector_m[2][block_m_idx][band_m_idx] += norm_tmp * direction_vector[2][band_m_idx]; + + diffuseness_m[band_m_idx] += reference_power[ts][band_m_idx] * diffuseness_vector[band_m_idx]; + renormalization_factor_diff[band_m_idx] += reference_power[ts][band_m_idx]; + } + } + + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + for ( d = 0; d < DIRAC_NUM_DIMS; d++ ) + { + dir_v[d] = hOMasa->direction_vector_m[d][block_m_idx][band_m_idx]; + } + +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + Word16 q_dir_e = 0; + f2me_buf( dir_v, dir_v_fx, &q_dir_e, 3 ); + Scale_sig32( dir_v_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( dir_v_fx, Q30, &azimuth_m_values_fx[block_m_idx][band_m_idx], &elevation_m_values_fx[block_m_idx][band_m_idx] ); + + /*==========================================fix-2-flt======================================================*/ + azimuth_m_values[block_m_idx][band_m_idx] = fixedToFloat( azimuth_m_values_fx[block_m_idx][band_m_idx], Q22 ); + elevation_m_values[block_m_idx][band_m_idx] = fixedToFloat( elevation_m_values_fx[block_m_idx][band_m_idx], Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_direction_vector_to_azimuth_elevation( dir_v, &azimuth_m_values[block_m_idx][band_m_idx], &elevation_m_values[block_m_idx][band_m_idx] ); +#endif + } + + /* Set coherences to zero, as this mode is used at lowest bit rates where the coherences are not transmitted */ + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + spreadCoherence[block_m_idx][band_m_idx] = 0.0f; + surroundingCoherence[band_m_idx] = 0.0f; + } + } + + /* Determine energy ratios */ + for ( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) + { + if ( renormalization_factor_diff[band_m_idx] > EPSILON ) + { + diffuseness_m[band_m_idx] /= renormalization_factor_diff[band_m_idx]; + } + else + { + diffuseness_m[band_m_idx] = 0.0f; + } + + energyRatio[band_m_idx] = 1.0f - diffuseness_m[band_m_idx]; + } + + return; +} +#else static void ivas_omasa_param_est_enc( OMASA_ENC_HANDLE hOMasa, OMASA_ENCODER_DATA_HANDLE hOmasaData, @@ -925,6 +1138,7 @@ static void ivas_omasa_param_est_enc( return; } +#endif /* Estimate energies and ratios */ diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 84ff09dd8..bc6e1f9de 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -133,6 +133,7 @@ static int16_t find_optimal_GR_orders( const int16_t *q_idx, const int16_t len, * Main function for quantizing and coding Spatial Metadata *-----------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_qmetadata_enc_encode( BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ @@ -248,9 +249,18 @@ ivas_error ivas_qmetadata_enc_encode( { if ( hQMetaData->twoDirBands[j] == 1 ) { +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] = floatToFixed( hQMetaData->q_direction[0].band_data[j].energy_ratio[0], Q30 ); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0] = floatToFixed( hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0], Q30 ); + /*=====================================flt-2-fix============================================*/ + + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +#else index_dirRatio1Inv = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); index_dirRatio2Inv = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); - +#endif for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; @@ -482,7 +492,11 @@ ivas_error ivas_qmetadata_enc_encode( } } +#ifdef IVAS_FLOAT_FIXED + only_reduce_bits_direction_fx( &extra_bits, q_direction, reduce_bits, nbands, nblocks, ind_order ); +#else only_reduce_bits_direction( &extra_bits, q_direction, reduce_bits, nbands, nblocks, ind_order ); +#endif bits_dir[d] = hMetaData->nb_bits_tot; requantize_direction_EC_3( &extra_bits, q_direction, nbands, hMetaData, elevation_orig, azimuth_orig, ind_order ); bits_dir[d] = hMetaData->nb_bits_tot - bits_dir[d]; @@ -519,58 +533,68 @@ ivas_error ivas_qmetadata_enc_encode( return error; } - - -/*-----------------------------------------------------------------------* - * ivas_qmetadata_enc_encode_hr_384_512() - * - * Main function for quantizing and coding Spatial Metadata at HRs - *-----------------------------------------------------------------------*/ - -ivas_error ivas_qmetadata_enc_encode_hr_384_512( - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ - const int16_t bits_sph_idx, - const int16_t bits_sp_coh ) +#else +ivas_error ivas_qmetadata_enc_encode( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ + const int16_t hodirac_flag /* i : flag to indicate HO-DirAC mode */ +) { - int16_t i, j; - int16_t bits_diff[QMETADATA_MAX_NO_DIRECTIONS]; + int16_t i, bit_pos_start, bit_pos_start_coh; + int16_t next_ind_start; + uint16_t diffuseness_index_max_ec_frame; + uint16_t diffuseness_index_max_ec_frame_pre[QMETADATA_MAX_NO_DIRECTIONS]; + int16_t bits_dir_raw_pre[QMETADATA_MAX_NO_DIRECTIONS]; + int16_t bits_diff_sum; + int16_t bits_diff[QMETADATA_MAX_NO_DIRECTIONS], bits_coherence[QMETADATA_MAX_NO_DIRECTIONS]; + int16_t bits_dir[QMETADATA_MAX_NO_DIRECTIONS], bits_dir_raw; + int16_t extra_bits; IVAS_QDIRECTION *q_direction; int16_t nbands, nblocks, start_band; int16_t ndirections, d; - int16_t all_coherence_zero; - int16_t bits_ec; float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t all_coherence_zero; + int16_t bit_pos_0, total_bits_1dir, bits_no_dirs_coh; + int16_t bits_signaling[QMETADATA_MAX_NO_DIRECTIONS]; + int16_t indice_coherence; + int16_t bits_dir_bands[MASA_MAXIMUM_CODING_SUBBANDS], raw_flag[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t diff_bits, bits_ec, next_ind_raw_flag; + int16_t dfRatio_bits[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t bits_surround_coh, no_TF; + int16_t dir2_bands[MASA_MAXIMUM_TWO_DIR_BANDS]; + int16_t ind_order[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t reduce_bits; ivas_error error; error = IVAS_ERR_OK; + /* Save initial position in bitstream */ + bit_pos_0 = hMetaData->nb_bits_tot; + bit_pos_start = bit_pos_0; + ndirections = hQMetaData->no_directions; + extra_bits = 0; /* Check if coherence should be encoded */ all_coherence_zero = 1; - if ( hQMetaData->q_direction->cfg.inactiveBands > 0 ) - { - push_next_indice( hMetaData, 1, 1 ); - /* write the number of inactive higher bands */ - ivas_qmetadata_encode_extended_gr( hMetaData, hQMetaData->q_direction->cfg.inactiveBands - 1, MASA_MAXIMUM_CODING_SUBBANDS, 1 ); - } - else - { - /* no change */ - push_next_indice( hMetaData, 0, 1 ); - } + bits_no_dirs_coh = 0; + if ( hQMetaData->coherence_flag ) { all_coherence_zero = hQMetaData->all_coherence_zero; + push_next_indice( hMetaData, all_coherence_zero, 1 ); /* signal coherence */ + bits_no_dirs_coh += 1; } - /* encode 2 direction subbands position */ - if ( ndirections == 2 && bits_sph_idx == 11 ) + if ( ndirections > 1 ) { - write_2dir_info( hMetaData, hQMetaData->twoDirBands, hQMetaData->q_direction[0].cfg.nbands, hQMetaData->numTwoDirBands ); + /* Reorder 2dir bands for more efficient encoding. */ + if ( !hodirac_flag ) + { + ivas_qmetadata_reorder_2dir_bands( hQMetaData ); + } d = 0; for ( i = hQMetaData->q_direction[1].cfg.start_band; i < hQMetaData->q_direction[1].cfg.nbands; i++ ) { @@ -580,6 +604,8 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( mvr2r( hQMetaData->q_direction[1].band_data[i].elevation, hQMetaData->q_direction[1].band_data[d].elevation, hQMetaData->q_direction[1].cfg.nblocks ); mvr2r( hQMetaData->q_direction[1].band_data[i].energy_ratio, hQMetaData->q_direction[1].band_data[d].energy_ratio, hQMetaData->q_direction[1].cfg.nblocks ); + dir2_bands[d] = i; + if ( hQMetaData->coherence_flag ) { mvc2c( hQMetaData->q_direction[1].coherence_band_data[i].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].cfg.nblocks ); @@ -587,7 +613,10 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( d++; } } - for ( i = hQMetaData->numTwoDirBands; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) + + bits_no_dirs_coh += write_2dir_info( hMetaData, hQMetaData->twoDirBands, hQMetaData->q_direction[0].cfg.nbands, hQMetaData->numTwoDirBands ); + + for ( i = d; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) { set_f( hQMetaData->q_direction[1].band_data[i].energy_ratio, 0.0f, hQMetaData->q_direction[1].cfg.nblocks ); } @@ -595,23 +624,90 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; } - /*Quantization and encoding of the Diffuseness */ - ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( hQMetaData, bits_diff, bits_sph_idx, hMetaData ); + /*Quantization of the Diffuseness */ + ivas_qmetadata_quantize_diffuseness_nrg_ratios( hQMetaData, bits_dir_raw_pre, bits_diff, dfRatio_bits, hodirac_flag ); + + bits_diff_sum = 0; + bits_diff[0] = ivas_qmetadata_entropy_encode_diffuseness( hMetaData, &( hQMetaData->q_direction[0] ), &diffuseness_index_max_ec_frame_pre[0] ); + bits_diff_sum += bits_diff[0]; + + if ( ndirections == 2 ) + { + bits_diff[1] = ivas_qmetadata_entropy_encode_df_ratio( hMetaData, &( hQMetaData->q_direction[1] ), dfRatio_bits ); + bits_diff_sum += bits_diff[1]; + } + + /* 2dir energy ratio encoding reuses index memory. Now that diffRatio and dFRatio have been encoded, + * we retrieve index_dirRatio1Inv and index_dirRatio1Inv for further parameter encoding. This is + * necessary only for bands that have two concurrent directions. */ + if ( hQMetaData->no_directions == 2 ) + { + int16_t j, k, dir2band, index_dirRatio1Inv, index_dirRatio2Inv; + + dir2band = 0; + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { + if ( hQMetaData->twoDirBands[j] == 1 ) + { + index_dirRatio1Inv = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + index_dirRatio2Inv = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; + } + + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = index_dirRatio2Inv; + } + + dir2band++; + } + } + } /* Encode surround coherence */ - if ( all_coherence_zero == 0 ) + if ( ndirections == 2 ) { - encode_surround_coherence_hr( hQMetaData, hMetaData ); + no_TF = hQMetaData->q_direction[0].cfg.nbands * hQMetaData->q_direction[0].cfg.nblocks + hQMetaData->q_direction[1].cfg.nbands * hQMetaData->q_direction[1].cfg.nblocks; + if ( ( all_coherence_zero == 0 ) && ( hQMetaData->metadata_max_bits - bits_no_dirs_coh - 4.3f * no_TF - sum_s( bits_diff, ndirections ) >= MASA_MIN_BITS_SURR_COH ) ) + { + bits_surround_coh = encode_surround_coherence( hQMetaData, hMetaData ); + } + else + { + bits_surround_coh = 0; + for ( i = 0; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) + { + if ( hQMetaData->surcoh_band_data != NULL ) + { + set_c( (int8_t *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); + } + } + } + bits_no_dirs_coh += bits_surround_coh; + total_bits_1dir = ( ( hQMetaData->metadata_max_bits - bits_no_dirs_coh ) * hQMetaData->q_direction[0].cfg.nbands * hQMetaData->q_direction[0].cfg.nblocks ) / no_TF; } else { - for ( i = 0; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) + no_TF = hQMetaData->q_direction[0].cfg.nbands * hQMetaData->q_direction[0].cfg.nblocks; + if ( ( all_coherence_zero == 0 ) && ( hQMetaData->metadata_max_bits - bits_no_dirs_coh - 4.3f * no_TF - bits_diff[0] >= MASA_MIN_BITS_SURR_COH ) ) { - if ( hQMetaData->surcoh_band_data != NULL ) + bits_surround_coh = encode_surround_coherence( hQMetaData, hMetaData ); + } + else + { + bits_surround_coh = 0; + for ( i = 0; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) { - set_c( (int8_t *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); + if ( hQMetaData->surcoh_band_data != NULL ) + { + set_c( (int8_t *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); + } } } + total_bits_1dir = hQMetaData->metadata_max_bits - bits_no_dirs_coh - bits_surround_coh; } /* Loop over number of directions*/ @@ -619,1316 +715,2779 @@ ivas_error ivas_qmetadata_enc_encode_hr_384_512( { q_direction = &( hQMetaData->q_direction[d] ); + if ( d == 1 ) + { + transform_azimuth_dir2( hQMetaData, dir2_bands ); + } + nbands = q_direction->cfg.nbands; nblocks = q_direction->cfg.nblocks; start_band = q_direction->cfg.start_band; + diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; + bits_dir_raw = bits_dir_raw_pre[d]; - - q_direction->not_in_2D = 0; - - /*Coherence */ - if ( all_coherence_zero == 0 ) + /* This sets bit budget correctly for the second direction */ + if ( d == 0 ) { - ivas_qmetadata_quantize_coherence_hr_512( hQMetaData, d, all_coherence_zero, hMetaData, bits_sp_coh ); + bits_diff[d] = bits_diff_sum; } - - /* write the spherical indexes */ - bits_ec = hMetaData->nb_bits_tot; - if ( bits_sph_idx == 11 ) + else { - /* do the quantization */ - quantize_direction_frame( q_direction, azimuth_orig, elevation_orig, 1 ); + bits_diff[d] = 0; } - for ( i = start_band; i < nbands; i++ ) + + bits_signaling[d] = 0; + + /*Coherence */ + bits_coherence[d] = 0; + bit_pos_start_coh = hMetaData->nb_bits_tot; + + if ( all_coherence_zero == 0 ) { - for ( j = 0; j < nblocks; j++ ) - { - push_next_indice( hMetaData, q_direction->band_data[i].spherical_index[j], bits_sph_idx ); - } + bits_coherence[d] = ivas_qmetadata_quantize_coherence( hQMetaData, d, all_coherence_zero, hMetaData, 0, &indice_coherence, 0 ); } - bits_ec = hMetaData->nb_bits_tot - bits_ec; - - /* Save quantized DOAs */ - if ( bits_sph_idx == 11 ) + if ( q_direction->cfg.mc_ls_setup == MC_LS_SETUP_5_1 || q_direction->cfg.mc_ls_setup == MC_LS_SETUP_7_1 ) { - for ( i = start_band; i < nbands; i++ ) - { - mvr2r( azimuth_orig[i], q_direction->band_data[i].azimuth, nblocks ); - mvr2r( elevation_orig[i], q_direction->band_data[i].elevation, nblocks ); - } + q_direction->not_in_2D = 0; + /* Quantize directions*/ + quantize_direction_frame2D( q_direction, azimuth_orig, elevation_orig ); } else { - for ( i = start_band; i < nbands; i++ ) - { - mvr2r( q_direction->band_data[i].azimuth, q_direction->band_data[i].q_azimuth, nblocks ); - mvr2r( q_direction->band_data[i].elevation, q_direction->band_data[i].q_elevation, nblocks ); - } + /* Quantize directions*/ + quantize_direction_frame( q_direction, azimuth_orig, elevation_orig, 0 ); } - } - if ( hQMetaData->q_direction->cfg.inactiveBands > 0 ) - { - hQMetaData->q_direction[0].cfg.nbands += hQMetaData->q_direction->cfg.inactiveBands; - if ( ndirections > 1 ) + /* Signalling 2D*/ + push_next_indice( hMetaData, ( q_direction->not_in_2D > 0 ), 1 ); /*2D flag*/ + bits_signaling[d] = 1; + + /* Save state of metadata bitstream buffer after writing energy ratios, number of dirs and save space for coherence*/ + bit_pos_start = hMetaData->nb_bits_tot; + next_ind_start = hMetaData->nb_ind_tot; + + /* Encode quantized directions with EC frame-wise*/ + if ( total_bits_1dir + bits_surround_coh <= hQMetaData->qmetadata_max_bit_req ) { - hQMetaData->q_direction[1].cfg.nbands += hQMetaData->q_direction->cfg.inactiveBands; + push_next_indice( hMetaData, 0, 1 ); /*Write 1 bit to signal EC frame-wise (EC1)*/ + bits_signaling[d]++; } - } - return error; -} + next_ind_raw_flag = hMetaData->nb_ind_tot; + push_next_indice( hMetaData, 0, 1 ); /* Raw coding flag*/ + bits_dir_bands[0] = ivas_qmetadata_raw_encode_dir( NULL, q_direction, q_direction->cfg.nbands, q_direction->cfg.start_band ); -/*-----------------------------------------------------------------------* - * ivas_qmetadata_enc_sid_encode() - * - * Main function for coding SID for Spatial Metadata - *-----------------------------------------------------------------------*/ - -/*! r: number of bits written */ -void ivas_qmetadata_enc_sid_encode( - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ - const int16_t masa_sid_descriptor, /* i : description of MASA SID coding structure */ - const int16_t ivas_format /* i : IVAS format */ -) -{ - int16_t b, m; - int16_t bit_pos_start; - IVAS_QDIRECTION *q_direction; - int16_t nbands, nblocks, start_band; - float avg_direction_vector[3]; - float direction_vector[3]; - float avg_azimuth[MASA_MAXIMUM_CODING_SUBBANDS]; - float avg_elevation[MASA_MAXIMUM_CODING_SUBBANDS]; - int16_t bits_dir, bits_diff, bits_delta; - int16_t metadata_sid_bits; /* bits allocated to SID for metadata */ - - if ( ivas_format == SBA_FORMAT ) - { - metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 2 - SID_FORMAT_NBITS; /* -1 for inactive mode header bit*/ - } - else - { - metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; - } - - - /* Save initial position in bitstream */ - bit_pos_start = hMetaData->nb_bits_tot; - - /* write for MASA the number of transport channels used at coding and the CPE mode DFT/MDCT */ - if ( masa_sid_descriptor > -1 ) - { - push_next_indice( hMetaData, masa_sid_descriptor, 1 ); - } - - /* Code for one direction: diffuseness and average DOA(s)*/ - q_direction = &( q_metadata->q_direction[0] ); - nbands = q_direction->cfg.nbands; - nblocks = q_direction->cfg.nblocks; - start_band = 0; /*Start always with band 0 for SID*/ - - /* sanity checks*/ - assert( q_metadata->no_directions == 1 && "Qmetadata SID: only one direction supported!" ); - if ( ivas_format == SBA_FORMAT ) - { - assert( ( q_direction->cfg.nbands == DIRAC_DTX_BANDS ) && "Qmetadata SID: only 2 bands supported!" ); - } - else - { - assert( ( q_direction->cfg.nbands == 5 ) && "Qmetadata SID: only 5 bands supported!" ); - } + reduce_bits = hQMetaData->is_masa_ivas_format ? ( total_bits_1dir - ( bits_diff[d] + bits_coherence[d] + bits_signaling[d] ) - 1 ) : MASA_MAX_BITS; + bits_ec = ivas_qmetadata_entropy_encode_dir( hMetaData, q_direction, diffuseness_index_max_ec_frame, q_direction->cfg.nbands, q_direction->cfg.start_band, bits_dir_bands[0], reduce_bits, 0 ); - if ( ivas_format != SBA_FORMAT ) - { - /* Signalling 2D*/ - push_next_indice( hMetaData, ( q_direction->not_in_2D > 0 ), 1 ); /*2D flag*/ - } - else - { - q_direction->not_in_2D = 1; /* force for merged modes */ - } + if ( bits_ec < 0 ) + { + hMetaData->ind_list[next_ind_raw_flag].value = 1; /*rewrite flag*/ + bits_ec = ivas_qmetadata_raw_encode_dir( hMetaData, q_direction, q_direction->cfg.nbands, q_direction->cfg.start_band ); + } + bits_dir[d] = bits_ec + 1; + extra_bits = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); - /*Encode the quantized diffuseness in raw coding*/ - bits_dir = 0; - bits_diff = 0; - if ( ivas_format != SBA_FORMAT ) - { - for ( b = start_band; b < nbands; b++ ) + /* Encode quantized directions with EC band-wise */ + if ( ( total_bits_1dir + bits_surround_coh <= hQMetaData->qmetadata_max_bit_req ) && ( bits_dir[d] + bits_diff[d] + bits_coherence[d] + bits_signaling[d] > total_bits_1dir ) && q_direction->cfg.nblocks > 1 ) { - q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); - bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); - q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; + restore_metadata_buffer( hMetaData, next_ind_start, bit_pos_start ); - if ( q_direction->not_in_2D == 0 ) - { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); - bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); - } - else + /* Write signaling */ + push_next_indice( hMetaData, 1, 1 ); /*Write 1 bit to signal no EC frame-wise (EC1)*/ + push_next_indice( hMetaData, 0, 1 ); /*Write 1 bit to signal EC band-wise (EC2)*/ + bits_signaling[d] = 3; + + /* Write raw flags */ + next_ind_raw_flag = hMetaData->nb_ind_tot; + for ( i = start_band; i < nbands; i++ ) { - bits_dir += q_direction->band_data[b].bits_sph_idx[0]; + push_next_indice( hMetaData, 0, 1 ); /* Raw coding flag*/ } - } - /* Reduce bit demand by increasing diffuseness*/ - bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; - if ( bits_delta > 0 ) - { - while ( bits_delta > 0 ) + bits_dir[d] = 0; + diff_bits = bits_diff[d] + bits_coherence[d] + bits_signaling[d] - total_bits_1dir; + for ( i = start_band; i < nbands; i++ ) { - for ( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) + bits_dir_bands[i] = ivas_qmetadata_raw_encode_dir( NULL, q_direction, i + 1, i ); + + /* Write ec bits */ + bits_ec = ivas_qmetadata_entropy_encode_dir( hMetaData, q_direction, diffuseness_index_max_ec_frame, i + 1, i, bits_dir_bands[i], MASA_MAX_BITS, 0 ); + + if ( bits_ec >= 0 ) { - if ( q_direction->band_data[b].bits_sph_idx[0] < 11 ) - { - bits_delta -= 1; - q_direction->band_data[b].bits_sph_idx[0]++; - } + bits_dir_bands[i] = bits_ec; + raw_flag[i] = 0; } - } - - if ( q_direction->not_in_2D == 0 ) - { - for ( b = start_band; b < nbands; b++ ) + else { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + raw_flag[i] = 1; } + diff_bits += bits_dir_bands[i] + 1; } - } - else - { - while ( bits_delta < 0 ) + + small_requantize_direction_frame( q_direction, azimuth_orig, elevation_orig, raw_flag, bits_dir_bands, &diff_bits ); + + for ( i = start_band; i < nbands; i++ ) { - for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) + if ( raw_flag[i] ) { - if ( q_direction->band_data[b].bits_sph_idx[0] >= 4 ) - { - bits_delta += 1; - q_direction->band_data[b].bits_sph_idx[0]--; - if ( q_direction->not_in_2D == 0 ) - { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); - } - } + /* Rewrite raw flag value */ + hMetaData->ind_list[next_ind_raw_flag + i - start_band].value = 1; + + /* Write ec bits */ + bits_ec = ivas_qmetadata_raw_encode_dir( hMetaData, q_direction, i + 1, i ); } + bits_dir[d] += bits_dir_bands[i] + 1; } + + extra_bits = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); } - } - else - { - for ( b = start_band; b < nbands; b++ ) + + /* Requantized directions */ + if ( ( total_bits_1dir + bits_surround_coh <= hQMetaData->qmetadata_max_bit_req ) && ( bits_dir[d] + bits_diff[d] + bits_coherence[d] + bits_signaling[d] > total_bits_1dir ) ) { - q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); - bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); - q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; - if ( q_direction->not_in_2D == 0 ) + /*Bit budget exceeded, bit reduction strategy?*/ + extra_bits = 0; + + restore_metadata_buffer( hMetaData, next_ind_start, bit_pos_start ); + + push_next_indice( hMetaData, 1, 1 ); /*Write 1 bit to signal no EC frame-wise (EC1)*/ + if ( nblocks > 1 ) { - q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); - bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); + push_next_indice( hMetaData, 1, 1 ); /*Write 1 bit to signal requantization stage (EC3)*/ + bits_signaling[d] = 3; } else { - bits_dir += q_direction->band_data[b].bits_sph_idx[0]; + bits_signaling[d] = 2; } - } - - /* Reduce bit demand by increasing diffuseness*/ - bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; - while ( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) - { - for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) + if ( hQMetaData->is_masa_ivas_format == 0 ) { - if ( q_direction->band_data[b].energy_ratio_index[0] < ( DIRAC_DIFFUSE_LEVELS - 1 ) ) + reduce_bits = bits_dir_raw - ( total_bits_1dir - bits_diff[d] - bits_coherence[d] - bits_signaling[d] ); + ind_order[0] = -1; + } + else + { + ind_order[0] = 0; + reduce_bits = min( nbands * nblocks + MASA_BIT_REDUCT_PARAM, bits_dir_raw - ( total_bits_1dir - bits_diff[d] - bits_coherence[d] - bits_signaling[d] ) ); + + if ( reduce_bits > bits_dir_raw - nbands * nblocks ) { - bits_delta += q_direction->band_data[b].bits_sph_idx[0]; - q_direction->band_data[b].energy_ratio_index[0]++; - q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; - bits_delta -= q_direction->band_data[b].bits_sph_idx[0]; + reduce_bits = bits_dir_raw - nbands * nblocks; } } - } - } - assert( ( bits_delta >= 0 ) && "Bit budget in Qmetadata SID is violated!!!" ); - - /*Code diffuseness*/ - for ( b = start_band; b < nbands; b++ ) - { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); - } - /* Compute and Quantize an average direction per band*/ - for ( b = start_band; b < nbands; b++ ) - { - set_zero( avg_direction_vector, 3 ); - for ( m = 0; m < nblocks; m++ ) - { - /*compute the average direction */ - ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[b].azimuth[m], q_direction->band_data[b].elevation[m], direction_vector ); - v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); + only_reduce_bits_direction( &extra_bits, q_direction, reduce_bits, nbands, nblocks, ind_order ); + bits_dir[d] = hMetaData->nb_bits_tot; + requantize_direction_EC_3( &extra_bits, q_direction, nbands, hMetaData, elevation_orig, azimuth_orig, ind_order ); + bits_dir[d] = hMetaData->nb_bits_tot - bits_dir[d]; } - ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth[b], &avg_elevation[b] ); - - /* Quantize the average direction */ - if ( q_direction->not_in_2D == 0 ) + /* finalize writing coherence */ + if ( ( bits_coherence[d] > 0 ) && ( all_coherence_zero == 0 ) && ( nblocks > 1 ) ) { - avg_elevation[b] = 0; - q_direction->band_data[b].spherical_index[0] = quantize_direction2D( avg_azimuth[b], q_direction->band_data[b].azimuth_m_alphabet[0], &avg_azimuth[b], - &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + bit_pos_start = hMetaData->nb_bits_tot; + hMetaData->nb_bits_tot = bit_pos_start_coh; + ivas_qmetadata_quantize_coherence( hQMetaData, d, all_coherence_zero, hMetaData, 1, &indice_coherence, 0 ); + hMetaData->nb_bits_tot = bit_pos_start; } - else + + if ( d == 0 ) { - q_direction->band_data[b].spherical_index[0] = quantize_direction( avg_elevation[b], avg_azimuth[b], q_direction->band_data[b].bits_sph_idx[0], &avg_elevation[b], &avg_azimuth[b], - &q_direction->band_data[b].elevation_index[0], &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + total_bits_1dir = hQMetaData->metadata_max_bits - ( hMetaData->nb_bits_tot - bit_pos_0 ); } /* Save quantized DOAs */ - q_direction->band_data[b].q_azimuth[0] = avg_azimuth[b]; - q_direction->band_data[b].q_elevation[0] = avg_elevation[b]; - - if ( q_direction->band_data[b].azimuth_index[0] == MASA_NO_INDEX ) + for ( i = start_band; i < nbands; i++ ) { - q_direction->band_data[b].azimuth_index[0] = 0; + mvr2r( q_direction->band_data[i].azimuth, q_direction->band_data[i].q_azimuth, nblocks ); + mvr2r( q_direction->band_data[i].elevation, q_direction->band_data[i].q_elevation, nblocks ); } - } - /* quantize average elevation and azimuth angles */ - if ( q_direction->not_in_2D > 0 ) - { - for ( b = start_band; b < nbands; b++ ) - { - push_next_indice( hMetaData, q_direction->band_data[b].spherical_index[0], q_direction->band_data[b].bits_sph_idx[0] ); - } - } - else - { - for ( b = start_band; b < nbands; b++ ) + /* Copy original DOAs back to q_direction*/ + for ( i = start_band; i < nbands; i++ ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].azimuth_index[0], q_direction->band_data[b].azimuth_m_alphabet[0] ); + mvr2r( azimuth_orig[i], q_direction->band_data[i].azimuth, nblocks ); + mvr2r( elevation_orig[i], q_direction->band_data[i].elevation, nblocks ); } } - - /* fill bits*/ - assert( ( hMetaData->nb_bits_tot - bit_pos_start ) <= metadata_sid_bits && "Too many written bits!" ); - while ( ( hMetaData->nb_bits_tot - bit_pos_start ) < metadata_sid_bits ) - { - push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ - } - - return; + return error; } +#endif -/*------------------------------------------------------------------------- - * reset_metadata_spatial() +/*-----------------------------------------------------------------------* + * ivas_qmetadata_enc_encode_hr_384_512() * - * Reset metadata in spatial formats - *------------------------------------------------------------------------*/ + * Main function for quantizing and coding Spatial Metadata at HRs + *-----------------------------------------------------------------------*/ -void reset_metadata_spatial( - const IVAS_FORMAT ivas_format, /* i : IVAS format */ - BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ - const int32_t element_brate, /* i : element bitrate */ - int32_t *total_brate, /* o : total bitrate */ - const int32_t core_brate, /* i : core bitrate */ - const int16_t nb_bits_metadata /* i : number of meatdata bits */ -) +ivas_error ivas_qmetadata_enc_encode_hr_384_512( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *hQMetaData, /* i/o: metadata handle */ + const int16_t bits_sph_idx, + const int16_t bits_sp_coh ) { - int16_t i, next_ind_sid, last_ind_sid; - int16_t j; - int16_t metadata_sid_bits; + int16_t i, j; + int16_t bits_diff[QMETADATA_MAX_NO_DIRECTIONS]; + IVAS_QDIRECTION *q_direction; + int16_t nbands, nblocks, start_band; + int16_t ndirections, d; + int16_t all_coherence_zero; + int16_t bits_ec; + float azimuth_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES], elevation_orig[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + ivas_error error; - if ( core_brate == SID_2k40 || core_brate == FRAME_NO_DATA ) - { - if ( ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) && core_brate != FRAME_NO_DATA ) - { - if ( ivas_format == SBA_FORMAT ) - { - hMetaData->ind_list[0].value = 1; - metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + error = IVAS_ERR_OK; - while ( hMetaData->nb_bits_tot < metadata_sid_bits ) - { - push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ - } - } - else - { - /* Reset metadata and keep only SID metadata*/ - last_ind_sid = hMetaData->nb_ind_tot; - next_ind_sid = hMetaData->nb_ind_tot; - while ( hMetaData->nb_bits_tot > nb_bits_metadata ) - { - next_ind_sid--; - hMetaData->nb_bits_tot -= hMetaData->ind_list[next_ind_sid].nb_bits; - } - hMetaData->nb_bits_tot = 0; + ndirections = hQMetaData->no_directions; - for ( i = 0; i < next_ind_sid; i++ ) - { - hMetaData->ind_list[i].nb_bits = -1; - } + /* Check if coherence should be encoded */ + all_coherence_zero = 1; + if ( hQMetaData->q_direction->cfg.inactiveBands > 0 ) + { + push_next_indice( hMetaData, 1, 1 ); + /* write the number of inactive higher bands */ + ivas_qmetadata_encode_extended_gr( hMetaData, hQMetaData->q_direction->cfg.inactiveBands - 1, MASA_MAXIMUM_CODING_SUBBANDS, 1 ); + } + else + { + /* no change */ + push_next_indice( hMetaData, 0, 1 ); + } + if ( hQMetaData->coherence_flag ) + { + all_coherence_zero = hQMetaData->all_coherence_zero; + push_next_indice( hMetaData, all_coherence_zero, 1 ); /* signal coherence */ + } - for ( j = 0, i = next_ind_sid; i < last_ind_sid; i++, j++ ) + /* encode 2 direction subbands position */ + if ( ndirections == 2 && bits_sph_idx == 11 ) + { + write_2dir_info( hMetaData, hQMetaData->twoDirBands, hQMetaData->q_direction[0].cfg.nbands, hQMetaData->numTwoDirBands ); + d = 0; + for ( i = hQMetaData->q_direction[1].cfg.start_band; i < hQMetaData->q_direction[1].cfg.nbands; i++ ) + { + if ( hQMetaData->twoDirBands[i] == 1 ) + { + mvr2r( hQMetaData->q_direction[1].band_data[i].azimuth, hQMetaData->q_direction[1].band_data[d].azimuth, hQMetaData->q_direction[1].cfg.nblocks ); + mvr2r( hQMetaData->q_direction[1].band_data[i].elevation, hQMetaData->q_direction[1].band_data[d].elevation, hQMetaData->q_direction[1].cfg.nblocks ); + mvr2r( hQMetaData->q_direction[1].band_data[i].energy_ratio, hQMetaData->q_direction[1].band_data[d].energy_ratio, hQMetaData->q_direction[1].cfg.nblocks ); + + if ( hQMetaData->coherence_flag ) { - hMetaData->ind_list[j].value = hMetaData->ind_list[i].value; - hMetaData->ind_list[j].nb_bits = hMetaData->ind_list[i].nb_bits; - hMetaData->nb_bits_tot += hMetaData->ind_list[j].nb_bits; - hMetaData->ind_list[i].nb_bits = -1; + mvc2c( hQMetaData->q_direction[1].coherence_band_data[i].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].cfg.nblocks ); } - - hMetaData->nb_ind_tot = j; + d++; } } - else + for ( i = hQMetaData->numTwoDirBands; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) { - /*Reset metadata*/ - reset_indices_enc( hMetaData, hMetaData->nb_ind_tot ); + set_f( hQMetaData->q_direction[1].band_data[i].energy_ratio, 0.0f, hQMetaData->q_direction[1].cfg.nblocks ); } - *total_brate = element_brate; - } - else if ( ivas_format != SBA_FORMAT ) - { - /* Reset SID metadata bits*/ - while ( hMetaData->nb_bits_tot > nb_bits_metadata ) - { - hMetaData->nb_ind_tot--; - hMetaData->nb_bits_tot -= hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits; - hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits = -1; - } + hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; } - return; -} - - -/*------------------------------------------------------------------------- - * quantize_direction2D() - * - * - *------------------------------------------------------------------------*/ - -/*! r: quantized spherical index */ -int16_t quantize_direction2D( - float phi, /* i : input azimuth value */ - const int16_t no_cw, /* i : number of bits */ - float *phi_q, /* o : quantized azimuth value */ - uint16_t *index_phi, /* o : quantized azimuth index */ - const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ -) -{ - int16_t idx_sph; - uint16_t id_phi; - if ( no_cw < 2 ) - { - *phi_q = 0; - - return 0; - } + /*Quantization and encoding of the Diffuseness */ + ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( hQMetaData, bits_diff, bits_sph_idx, hMetaData ); - if ( mc_format != MC_LS_SETUP_INVALID ) + /* Encode surround coherence */ + if ( all_coherence_zero == 0 ) { - id_phi = quantize_phi_chan_compand( phi + 180, phi_q, no_cw, 0, mc_format ); + encode_surround_coherence_hr( hQMetaData, hMetaData ); } else { - id_phi = quantize_phi( phi + 180, 0, phi_q, no_cw ); + for ( i = 0; i < hQMetaData->q_direction[0].cfg.nbands; i++ ) + { + if ( hQMetaData->surcoh_band_data != NULL ) + { + set_c( (int8_t *) hQMetaData->surcoh_band_data[i].surround_coherence, 0, hQMetaData->q_direction[0].cfg.nblocks ); + } + } } - *phi_q -= 180; - *index_phi = ivas_qmetadata_reorder_generic( id_phi - ( no_cw >> 1 ) ); - idx_sph = id_phi; + /* Loop over number of directions*/ + for ( d = 0; d < ndirections; d++ ) + { + q_direction = &( hQMetaData->q_direction[d] ); - return idx_sph; -} + nbands = q_direction->cfg.nbands; + nblocks = q_direction->cfg.nblocks; + start_band = q_direction->cfg.start_band; -static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( - IVAS_QMETADATA_HANDLE hQMetaData, - int16_t *needed_bits, - const int16_t bits_dir_hr, - BSTR_ENC_HANDLE hMetaData ) -{ - int16_t j, k; - int16_t index; + q_direction->not_in_2D = 0; - needed_bits[0] = 0; - needed_bits[1] = 0; + /*Coherence */ + if ( all_coherence_zero == 0 ) + { + ivas_qmetadata_quantize_coherence_hr_512( hQMetaData, d, all_coherence_zero, hMetaData, bits_sp_coh ); + } - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) - { - for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + /* write the spherical indexes */ + bits_ec = hMetaData->nb_bits_tot; + if ( bits_sph_idx == 11 ) { - index = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); - push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index; - hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index; - hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; - needed_bits[0] += MASA_BITS_ER_HR; - hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_dir_hr; + /* do the quantization */ + quantize_direction_frame( q_direction, azimuth_orig, elevation_orig, 1 ); } - } - if ( hQMetaData->no_directions == 2 ) - { - float ratioSum; - if ( bits_dir_hr == 16 ) + for ( i = start_band; i < nbands; i++ ) { - for ( j = hQMetaData->q_direction[1].cfg.start_band; j < hQMetaData->q_direction[1].cfg.nbands; j++ ) + for ( j = 0; j < nblocks; j++ ) { - for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) - { - index = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); - push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); - hQMetaData->q_direction[1].band_data[j].energy_ratio_index[k] = index; - hQMetaData->q_direction[1].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; + push_next_indice( hMetaData, q_direction->band_data[i].spherical_index[j], bits_sph_idx ); + } + } + bits_ec = hMetaData->nb_bits_tot - bits_ec; - ratioSum = hQMetaData->q_direction[0].band_data[j].energy_ratio[k] + hQMetaData->q_direction[1].band_data[j].energy_ratio[k]; - if ( ratioSum > 1.0f ) - { - hQMetaData->q_direction[0].band_data[j].energy_ratio[k] /= ratioSum; - hQMetaData->q_direction[1].band_data[j].energy_ratio[k] /= ratioSum; - } - needed_bits[1] += MASA_BITS_ER_HR; - hQMetaData->q_direction[1].band_data[j].bits_sph_idx[k] = bits_dir_hr; - } + /* Save quantized DOAs */ + if ( bits_sph_idx == 11 ) + { + for ( i = start_band; i < nbands; i++ ) + { + mvr2r( azimuth_orig[i], q_direction->band_data[i].azimuth, nblocks ); + mvr2r( elevation_orig[i], q_direction->band_data[i].elevation, nblocks ); } } else { - int16_t pos_2dir_band[MASA_MAXIMUM_CODING_SUBBANDS]; - k = 0; - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; j++ ) + for ( i = start_band; i < nbands; i++ ) { - if ( hQMetaData->twoDirBands[j] == 1 ) - { - pos_2dir_band[k] = j; - k++; - } - else - { - pos_2dir_band[k] = 0; - } + mvr2r( q_direction->band_data[i].azimuth, q_direction->band_data[i].q_azimuth, nblocks ); + mvr2r( q_direction->band_data[i].elevation, q_direction->band_data[i].q_elevation, nblocks ); } - for ( j = hQMetaData->q_direction[1].cfg.start_band; j < hQMetaData->q_direction[1].cfg.nbands; j++ ) - { - for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) - { - index = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); - push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); - hQMetaData->q_direction[1].band_data[j].energy_ratio_index[k] = index; - hQMetaData->q_direction[1].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; - - ratioSum = hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio[k] + hQMetaData->q_direction[1].band_data[j].energy_ratio[k]; - - if ( ratioSum > 1.0f ) - { - hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio[k] /= ratioSum; - hQMetaData->q_direction[1].band_data[j].energy_ratio[k] /= ratioSum; - } + } + } - needed_bits[1] += MASA_BITS_ER_HR; - hQMetaData->q_direction[1].band_data[j].bits_sph_idx[k] = bits_dir_hr; - } - } + if ( hQMetaData->q_direction->cfg.inactiveBands > 0 ) + { + hQMetaData->q_direction[0].cfg.nbands += hQMetaData->q_direction->cfg.inactiveBands; + if ( ndirections > 1 ) + { + hQMetaData->q_direction[1].cfg.nbands += hQMetaData->q_direction->cfg.inactiveBands; } } - return; + return error; } -/*------------------------------------------------------------------------- - * ivas_qmetadata_quantize_diffuseness_nrg_ratios() +/*-----------------------------------------------------------------------* + * ivas_qmetadata_enc_sid_encode() * - * Quantize diffuseness - *------------------------------------------------------------------------*/ + * Main function for coding SID for Spatial Metadata + *-----------------------------------------------------------------------*/ -static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( - IVAS_QMETADATA_HANDLE hQMetaData, - int16_t *needed_bits, - int16_t *nbits_diff, - int16_t *dfRatioBits, - const int16_t hodirac_flag ) +/*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +void ivas_qmetadata_enc_sid_encode( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ + const int16_t masa_sid_descriptor, /* i : description of MASA SID coding structure */ + const int16_t ivas_format /* i : IVAS format */ +) { - int16_t j, k, dir2band; - int16_t index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; - int16_t index_diff; + int16_t b, m; + int16_t bit_pos_start; + IVAS_QDIRECTION *q_direction; + int16_t nbands, nblocks, start_band; + float avg_direction_vector[3]; + float direction_vector[3]; + float avg_azimuth[MASA_MAXIMUM_CODING_SUBBANDS]; + float avg_elevation[MASA_MAXIMUM_CODING_SUBBANDS]; +#ifdef IVAS_FLOAT_FIXED + // Word32 avg_direction_vector_fx[3]; + Word32 direction_vector_fx[3]; + // Word32 avg_azimuth_fx[MASA_MAXIMUM_CODING_SUBBANDS]; + // Word32 avg_elevation_fx[MASA_MAXIMUM_CODING_SUBBANDS]; +#endif + int16_t bits_dir, bits_diff, bits_delta; + int16_t metadata_sid_bits; /* bits allocated to SID for metadata */ - nbits_diff[0] = 0; - nbits_diff[1] = 0; - needed_bits[0] = 0; - needed_bits[1] = 0; - dir2band = 0; + if ( ivas_format == SBA_FORMAT ) + { + metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 2 - SID_FORMAT_NBITS; /* -1 for inactive mode header bit*/ + } + else + { + metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + } - for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + + /* Save initial position in bitstream */ + bit_pos_start = hMetaData->nb_bits_tot; + + /* write for MASA the number of transport channels used at coding and the CPE mode DFT/MDCT */ + if ( masa_sid_descriptor > -1 ) { - if ( hQMetaData->no_directions == 2 && hQMetaData->twoDirBands[j] == 1 ) + push_next_indice( hMetaData, masa_sid_descriptor, 1 ); + } + + /* Code for one direction: diffuseness and average DOA(s)*/ + q_direction = &( q_metadata->q_direction[0] ); + nbands = q_direction->cfg.nbands; + nblocks = q_direction->cfg.nblocks; + start_band = 0; /*Start always with band 0 for SID*/ + + /* sanity checks*/ + assert( q_metadata->no_directions == 1 && "Qmetadata SID: only one direction supported!" ); + if ( ivas_format == SBA_FORMAT ) + { + assert( ( q_direction->cfg.nbands == DIRAC_DTX_BANDS ) && "Qmetadata SID: only 2 bands supported!" ); + } + else + { + assert( ( q_direction->cfg.nbands == 5 ) && "Qmetadata SID: only 5 bands supported!" ); + } + + if ( ivas_format != SBA_FORMAT ) + { + /* Signalling 2D*/ + push_next_indice( hMetaData, ( q_direction->not_in_2D > 0 ), 1 ); /*2D flag*/ + } + else + { + q_direction->not_in_2D = 1; /* force for merged modes */ + } + + /*Encode the quantized diffuseness in raw coding*/ + bits_dir = 0; + bits_diff = 0; + if ( ivas_format != SBA_FORMAT ) + { + for ( b = start_band; b < nbands; b++ ) { - float diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; - float dirRatio1, dirRatio2, sumRatio; - int16_t dfRatio_index, dfRatio_qsteps, dfRatio_bits; + q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); + bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; - /* With 2dir metadata, we quantize and transmit diffuse-to-total ratio (diffRatio) and - * distribution factor of direct-to-total ratios (dFRatio). This is more efficient and - * accurate than simple separate quantization of each direct-to-total ratio or their - * separate inverses. */ - if ( hodirac_flag ) + if ( q_direction->not_in_2D == 0 ) { - /* already encoded as total and ratios in HO-DirAC */ - diffRatio = 1.f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0]; - dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0]; + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); } else { - dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio[0]; - dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0]; - sumRatio = dirRatio1 + dirRatio2; - diffRatio = 1.0f - sumRatio; - dfRatio = sumRatio < EPSILON ? 0.5f : dirRatio1 / sumRatio; + bits_dir += q_direction->band_data[b].bits_sph_idx[0]; } + } + /* Reduce bit demand by increasing diffuseness*/ + bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; + if ( bits_delta > 0 ) + { + while ( bits_delta > 0 ) + { + for ( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) + { + if ( q_direction->band_data[b].bits_sph_idx[0] < 11 ) + { + bits_delta -= 1; + q_direction->band_data[b].bits_sph_idx[0]++; + } + } + } - index_diff = masa_sq( diffRatio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); - diffRatioQ = diffuseness_reconstructions[index_diff]; - - if ( hodirac_flag ) + if ( q_direction->not_in_2D == 0 ) { - dfRatio_bits = ivas_get_df_ratio_bits_hodirac( index_diff ); + for ( b = start_band; b < nbands; b++ ) + { + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + } } - else + } + else + { + while ( bits_delta < 0 ) { - dfRatio_bits = ivas_get_df_ratio_bits( index_diff ); + for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) + { + if ( q_direction->band_data[b].bits_sph_idx[0] >= 4 ) + { + bits_delta += 1; + q_direction->band_data[b].bits_sph_idx[0]--; + if ( q_direction->not_in_2D == 0 ) + { + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + } + } + } } + } + } + else + { + for ( b = start_band; b < nbands; b++ ) + { + q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); + bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; - dfRatioBits[dir2band] = dfRatio_bits; - - dfRatio_qsteps = ( 1 << dfRatio_bits ); - if ( hodirac_flag ) + if ( q_direction->not_in_2D == 0 ) { - dfRatio_index = usquant( dfRatio, &dfRatioQ, 0.0f, 1.f / ( dfRatio_qsteps - 1 ), dfRatio_qsteps ); - dirRatio1Q = 1.f - diffRatioQ; - dirRatio2Q = dfRatioQ; + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); + bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); } else { - dfRatio_index = usquant( dfRatio, &dfRatioQ, 0.5f, 0.5f / ( dfRatio_qsteps - 1 ), dfRatio_qsteps ); - - /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ - dirRatio1Q = dfRatioQ * ( 1.0f - diffRatioQ ); - dirRatio2Q = ( 1.0f - diffRatioQ ) - dirRatio1Q; + bits_dir += q_direction->band_data[b].bits_sph_idx[0]; } + } - index_dirRatio1Inv = masa_sq( 1.0f - dirRatio1Q, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + /* Reduce bit demand by increasing diffuseness*/ + bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; - /* Note: To save memory, we store temporarily index_diff and dfRatio_index into first and second direction - * energy ratio index variables until they have been encoded. index_dirRatio1Inv and index_dirRatio2Inv are - * then later retrieved for further use in encoding. */ - for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + while ( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) + { + for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; - hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = dirRatio1Q; - } - nbits_diff[0] += MASA_BITS_ER; - - if ( hodirac_flag ) - { - float tmp; - index_dirRatio2Inv = usquant( dirRatio2Q, &tmp, 0.0f, 1.f / ( DIRAC_DIFFUSE_LEVELS - 1 ), DIRAC_DIFFUSE_LEVELS ); - } - else - { - index_dirRatio2Inv = masa_sq( 1.0f - dirRatio2Q, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + if ( q_direction->band_data[b].energy_ratio_index[0] < ( DIRAC_DIFFUSE_LEVELS - 1 ) ) + { + bits_delta += q_direction->band_data[b].bits_sph_idx[0]; + q_direction->band_data[b].energy_ratio_index[0]++; + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; + bits_delta -= q_direction->band_data[b].bits_sph_idx[0]; + } } + } + } + assert( ( bits_delta >= 0 ) && "Bit budget in Qmetadata SID is violated!!!" ); - for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) - { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[k] = dirRatio2Q; - } - nbits_diff[1] += dfRatio_bits; + /*Code diffuseness*/ + for ( b = start_band; b < nbands; b++ ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + } - /* Obtain compensated direct-to-total ratios for direction quantization. This compensates for the - * fact that with 2dir data, it is harder to achieve separate high direct-to-total ratio values - * which are assumed by the direction quantization system. In practice, this improves direction - * accuracy when it is perceptual meaningful. */ + /* Compute and Quantize an average direction per band*/ + for ( b = start_band; b < nbands; b++ ) + { + set_zero( avg_direction_vector, 3 ); + for ( m = 0; m < nblocks; m++ ) + { + /*compute the average direction */ #ifdef IVAS_FLOAT_FIXED - masa_compensate_two_dir_energy_ratio_index_fx( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); + /*==========================================flt-2-fix======================================================*/ + q_direction->band_data[b].azimuth_fx[m] = floatToFixed( q_direction->band_data[b].azimuth[m], Q22 ); + q_direction->band_data[b].elevation_fx[m] = floatToFixed( q_direction->band_data[b].elevation[m], Q22 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); + + /*==========================================fix-2-flt======================================================*/ + fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); + /*==========================================fix-2-flt======================================================*/ #else - masa_compensate_two_dir_energy_ratio_index( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); + ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[b].azimuth[m], q_direction->band_data[b].elevation[m], direction_vector ); #endif + v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); + } - for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) - { - hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; - hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; - } - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv_mod]; +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + Word16 q_dir_e = 0; + f2me_buf( avg_direction_vector, avg_direction_vector_fx, &q_dir_e, 3 ); + Scale_sig32( avg_direction_vector_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ - for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) - { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; - hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; - } - needed_bits[1] += hQMetaData->q_direction[1].cfg.nblocks * bits_direction_masa[index_dirRatio2Inv_mod]; + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx[b], &avg_elevation_fx[b] ); - dir2band++; + /*==========================================fix-2-flt======================================================*/ + avg_azimuth[b] = fixedToFloat( avg_azimuth_fx[b], Q22 ); + avg_elevation[b] = fixedToFloat( avg_elevation_fx[b], Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth[b], &avg_elevation[b] ); +#endif + + /* Quantize the average direction */ + if ( q_direction->not_in_2D == 0 ) + { + avg_elevation[b] = 0; + q_direction->band_data[b].spherical_index[0] = quantize_direction2D( avg_azimuth[b], q_direction->band_data[b].azimuth_m_alphabet[0], &avg_azimuth[b], + &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); } else { - index_dirRatio1Inv = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); - - for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) - { - hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; - hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions[index_dirRatio1Inv]; - hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; - } + q_direction->band_data[b].spherical_index[0] = quantize_direction( avg_elevation[b], avg_azimuth[b], q_direction->band_data[b].bits_sph_idx[0], &avg_elevation[b], &avg_azimuth[b], + &q_direction->band_data[b].elevation_index[0], &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + } - nbits_diff[0] += MASA_BITS_ER; + /* Save quantized DOAs */ + q_direction->band_data[b].q_azimuth[0] = avg_azimuth[b]; + q_direction->band_data[b].q_elevation[0] = avg_elevation[b]; - needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv]; + if ( q_direction->band_data[b].azimuth_index[0] == MASA_NO_INDEX ) + { + q_direction->band_data[b].azimuth_index[0] = 0; } } - return; -} - - -/*------------------------------------------------------------------------- - * ivas_diffuseness_huff_ec_encode() - * - * - *------------------------------------------------------------------------*/ - -static int16_t ivas_diffuseness_huff_ec_encode( - BSTR_ENC_HANDLE hMetaData, - const uint16_t idx ) -{ - int16_t nbits; - nbits = 0; - if ( idx <= DIFF_EC_HUFF_GR0_LIMIT ) + /* quantize average elevation and azimuth angles */ + if ( q_direction->not_in_2D > 0 ) { - if ( idx > 0 ) + for ( b = start_band; b < nbands; b++ ) { - push_next_indice( hMetaData, ( 1 << idx ) - 1, idx ); - nbits += idx; + push_next_indice( hMetaData, q_direction->band_data[b].spherical_index[0], q_direction->band_data[b].bits_sph_idx[0] ); } - push_next_indice( hMetaData, 0, 1 ); - nbits += 1; } else { - push_next_indice( hMetaData, 511, DIFF_EC_HUFF_GR0_LIMIT + 1 ); - push_next_indice( hMetaData, idx - DIFF_EC_HUFF_GR0_LIMIT - 1, 2 ); - nbits += DIFF_EC_HUFF_GR0_LIMIT + 3; + for ( b = start_band; b < nbands; b++ ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].azimuth_index[0], q_direction->band_data[b].azimuth_m_alphabet[0] ); + } } - return nbits; -} -/*------------------------------------------------------------------------- - * ivas_diffuseness_huff_ec_prepare() - * - * - *------------------------------------------------------------------------*/ + /* fill bits*/ + assert( ( hMetaData->nb_bits_tot - bit_pos_start ) <= metadata_sid_bits && "Too many written bits!" ); + while ( ( hMetaData->nb_bits_tot - bit_pos_start ) < metadata_sid_bits ) + { + push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ + } -static void ivas_diffuseness_huff_ec_prepare( - IVAS_QDIRECTION *q_direction, - int16_t *best_av, - uint16_t *avr_idx, - int16_t *diffuseness_bits_huff ) + return; +} +#else +void ivas_qmetadata_enc_sid_encode( + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + IVAS_QMETADATA *q_metadata, /* i/o: metadata handle */ + const int16_t masa_sid_descriptor, /* i : description of MASA SID coding structure */ + const int16_t ivas_format /* i : IVAS format */ +) { - int16_t bits; - int16_t av_crt; - int16_t av; - int16_t sh_idx; - uint16_t ui_sh_idx[MASA_MAXIMUM_CODING_SUBBANDS]; - int16_t b, start_band, nbands; - - start_band = q_direction->cfg.start_band; - nbands = q_direction->cfg.nbands; + int16_t b, m; + int16_t bit_pos_start; + IVAS_QDIRECTION *q_direction; + int16_t nbands, nblocks, start_band; + float avg_direction_vector[3]; + float direction_vector[3]; + float avg_azimuth[MASA_MAXIMUM_CODING_SUBBANDS]; + float avg_elevation[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t bits_dir, bits_diff, bits_delta; + int16_t metadata_sid_bits; /* bits allocated to SID for metadata */ - *diffuseness_bits_huff = 0; - av = 0; - for ( b = start_band; b < nbands; b++ ) + if ( ivas_format == SBA_FORMAT ) { - av += q_direction->band_data[b].energy_ratio_index[0]; + metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 2 - SID_FORMAT_NBITS; /* -1 for inactive mode header bit*/ } - av = (int16_t) ( 0.5f + av / (float) nbands ); - *best_av = av; - - *diffuseness_bits_huff = MAX16B; - for ( av_crt = av - 1; av_crt <= av + 1; av_crt++ ) + else { - bits = 0; - for ( b = start_band; b < nbands; b++ ) - { - sh_idx = q_direction->band_data[b].energy_ratio_index[0] - av_crt; - ui_sh_idx[b] = ( sh_idx <= 0 ) ? ( -2 * sh_idx ) : sh_idx * 2 - 1; - if ( ui_sh_idx[b] >= 2 * DIRAC_DIFFUSE_LEVELS - 3 ) - { - bits = 100; /* to avoid difference larger than 6 in absolute value */ - } - - bits += ( ui_sh_idx[b] <= DIFF_EC_HUFF_GR0_LIMIT ) ? ( ui_sh_idx[b] + 1 ) : 11; - } - - if ( bits < *diffuseness_bits_huff ) - { - *diffuseness_bits_huff = bits; - mvs2s( (int16_t *) ui_sh_idx, (int16_t *) avr_idx, nbands ); - *best_av = av_crt; - } + metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; } - *diffuseness_bits_huff += MASA_BITS_ER; /* for the average */ - - return; -} -/*------------------------------------------------------------------------- - * ivas_qmetadata_entropy_encode_diffuseness() - * - * encode diffuseness - *------------------------------------------------------------------------*/ + /* Save initial position in bitstream */ + bit_pos_start = hMetaData->nb_bits_tot; -static int16_t ivas_qmetadata_entropy_encode_diffuseness( - BSTR_ENC_HANDLE hMetaData, - IVAS_QDIRECTION *q_direction, - uint16_t *diffuseness_index_max_ec_frame ) -{ - int16_t start_bit_pos; - int16_t diffuseness_bits_raw; - int16_t b; - int16_t min_diffuseness_m_index, max_diffuseness_m_index; - int16_t nbands; - int16_t start_band; + /* write for MASA the number of transport channels used at coding and the CPE mode DFT/MDCT */ + if ( masa_sid_descriptor > -1 ) + { + push_next_indice( hMetaData, masa_sid_descriptor, 1 ); + } + /* Code for one direction: diffuseness and average DOA(s)*/ + q_direction = &( q_metadata->q_direction[0] ); nbands = q_direction->cfg.nbands; - start_band = q_direction->cfg.start_band; - - start_bit_pos = hMetaData->nb_bits_tot; + nblocks = q_direction->cfg.nblocks; + start_band = 0; /*Start always with band 0 for SID*/ - if ( nbands == 1 ) + /* sanity checks*/ + assert( q_metadata->no_directions == 1 && "Qmetadata SID: only one direction supported!" ); + if ( ivas_format == SBA_FORMAT ) { - /* If there is only one band, diffuseness should be coded directly as raw with no signaling. */ - push_next_indice( hMetaData, q_direction->band_data[0].energy_ratio_index[0], MASA_BITS_ER ); - *diffuseness_index_max_ec_frame = 5; - return ( hMetaData->nb_bits_tot - start_bit_pos ); + assert( ( q_direction->cfg.nbands == DIRAC_DTX_BANDS ) && "Qmetadata SID: only 2 bands supported!" ); } - - /* compute the number of raw coding bits */ - diffuseness_bits_raw = 0; - for ( b = start_band; b < nbands; b++ ) + else { - diffuseness_bits_raw += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); + assert( ( q_direction->cfg.nbands == 5 ) && "Qmetadata SID: only 5 bands supported!" ); } - min_diffuseness_m_index = q_direction->band_data[start_band].energy_ratio_index[0]; - max_diffuseness_m_index = q_direction->band_data[start_band].energy_ratio_index[0]; - - for ( b = start_band; b < nbands; b++ ) + if ( ivas_format != SBA_FORMAT ) { - if ( q_direction->band_data[b].energy_ratio_index[0] < min_diffuseness_m_index ) - { - min_diffuseness_m_index = q_direction->band_data[b].energy_ratio_index[0]; - } - - if ( q_direction->band_data[b].energy_ratio_index[0] > max_diffuseness_m_index ) - { - max_diffuseness_m_index = q_direction->band_data[b].energy_ratio_index[0]; - } + /* Signalling 2D*/ + push_next_indice( hMetaData, ( q_direction->not_in_2D > 0 ), 1 ); /*2D flag*/ + } + else + { + q_direction->not_in_2D = 1; /* force for merged modes */ } - if ( nbands < DIFF_EC_HUFF_BAND_LIMIT ) + /*Encode the quantized diffuseness in raw coding*/ + bits_dir = 0; + bits_diff = 0; + if ( ivas_format != SBA_FORMAT ) { - /* Use similarity coding approach or raw coding when there is a low number of bands. */ - /* one bit is used to indicate whether diffuseness values are entropy coded or coded raw */ - if ( min_diffuseness_m_index == max_diffuseness_m_index ) /* all values are equal */ - { - push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ - push_next_indice( hMetaData, 1, 1 ); /* dif_have_unique_value */ - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ - } - else if ( min_diffuseness_m_index + 1 == max_diffuseness_m_index ) /* only two consecutive values are present */ + for ( b = start_band; b < nbands; b++ ) { - push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ - push_next_indice( hMetaData, 0, 1 ); /* dif_have_unique_value */ - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value */ + q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); + bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; - for ( b = start_band; b < nbands; b++ ) + if ( q_direction->not_in_2D == 0 ) { - push_next_indice( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - min_diffuseness_m_index, 1 ); /* dif_bit_offset_values */ + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); } - } - else /* raw coding */ - { - push_next_indice( hMetaData, 1, 1 ); /* dif_use_raw_coding */ - - for ( b = start_band; b < nbands; b++ ) + else { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ + bits_dir += q_direction->band_data[b].bits_sph_idx[0]; } } - } - else - { - /* Use Huffman-coding approach or raw coding when there is a high number of bands. */ - int16_t diffuseness_bits_huff; - int16_t best_av; - uint16_t avr_idx[MASA_MAXIMUM_CODING_SUBBANDS]; - /* First, obtain average indices and bit usage for Huffman-coding. */ - ivas_diffuseness_huff_ec_prepare( q_direction, &best_av, avr_idx, &diffuseness_bits_huff ); - - /* If there is benefit, use Huffman-coding. Otherwise, use raw coding. */ - if ( diffuseness_bits_huff < diffuseness_bits_raw ) + /* Reduce bit demand by increasing diffuseness*/ + bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; + if ( bits_delta > 0 ) { - /* Signal Huffman EC */ - push_next_indice( hMetaData, 0, 1 ); - push_next_indice( hMetaData, best_av, MASA_BITS_ER ); - for ( b = start_band; b < nbands; b++ ) + while ( bits_delta > 0 ) { - ivas_diffuseness_huff_ec_encode( hMetaData, avr_idx[b] ); + for ( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) + { + if ( q_direction->band_data[b].bits_sph_idx[0] < 11 ) + { + bits_delta -= 1; + q_direction->band_data[b].bits_sph_idx[0]++; + } + } + } + + if ( q_direction->not_in_2D == 0 ) + { + for ( b = start_band; b < nbands; b++ ) + { + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + } } } else { - /* Signal raw */ - push_next_indice( hMetaData, 1, 1 ); - for ( b = start_band; b < nbands; b++ ) + while ( bits_delta < 0 ) { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ + for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) + { + if ( q_direction->band_data[b].bits_sph_idx[0] >= 4 ) + { + bits_delta += 1; + q_direction->band_data[b].bits_sph_idx[0]--; + if ( q_direction->not_in_2D == 0 ) + { + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 8, q_direction->band_data[b].bits_sph_idx[0] ) ); + } + } + } } } } - - *diffuseness_index_max_ec_frame = 5; - /* adaptively select the diffuseness_index_max_ec threshold */ - if ( min_diffuseness_m_index > 5 ) + else { - *diffuseness_index_max_ec_frame = DIRAC_DIFFUSE_LEVELS - 1; - } - - - return ( hMetaData->nb_bits_tot - start_bit_pos ); -} - - -/*------------------------------------------------------------------------- - * ivas_qmetadata_entropy_encode_df_ratio() - * - * encode dfRatio - *------------------------------------------------------------------------*/ - -static int16_t ivas_qmetadata_entropy_encode_df_ratio( - BSTR_ENC_HANDLE hMetaData, - IVAS_QDIRECTION *q_direction, - int16_t *df_ratio_bits ) -{ - int16_t start_bit_pos; - int16_t bits_raw; - int16_t b; - int16_t min_index, max_index; - int16_t nbands, start_band; - int16_t max_df_ratio_bits; - int16_t ec_mode = 0; - int16_t max_alphabet_size; - - nbands = q_direction->cfg.nbands; - start_band = q_direction->cfg.start_band; + for ( b = start_band; b < nbands; b++ ) + { + q_direction->band_data[b].energy_ratio_index[0] = max( q_direction->band_data[b].energy_ratio_index[0], 4 ); + bits_diff += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; - start_bit_pos = hMetaData->nb_bits_tot; + if ( q_direction->not_in_2D == 0 ) + { + q_direction->band_data[b].azimuth_m_alphabet[0] = 1 << ( min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ); + bits_dir += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].azimuth_m_alphabet[0] - 1, q_direction->band_data[b].azimuth_m_alphabet[0] ); + } + else + { + bits_dir += q_direction->band_data[b].bits_sph_idx[0]; + } + } - if ( nbands == 1 ) - { - /* If there is only one band, ratio should be coded directly as raw with no signaling. */ - push_next_indice( hMetaData, q_direction->band_data[0].energy_ratio_index[0], df_ratio_bits[0] ); + /* Reduce bit demand by increasing diffuseness*/ + bits_delta = metadata_sid_bits - ( hMetaData->nb_bits_tot - bit_pos_start ) - bits_diff - bits_dir; - return ( hMetaData->nb_bits_tot - start_bit_pos ); + while ( bits_delta < 0 && ( q_direction->not_in_2D > 0 ) ) + { + for ( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) + { + if ( q_direction->band_data[b].energy_ratio_index[0] < ( DIRAC_DIFFUSE_LEVELS - 1 ) ) + { + bits_delta += q_direction->band_data[b].bits_sph_idx[0]; + q_direction->band_data[b].energy_ratio_index[0]++; + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[q_direction->band_data[b].energy_ratio_index[0]]; + bits_delta -= q_direction->band_data[b].bits_sph_idx[0]; + } + } + } } + assert( ( bits_delta >= 0 ) && "Bit budget in Qmetadata SID is violated!!!" ); - /* compute the number of raw coding bits */ - bits_raw = 0; - max_df_ratio_bits = 0; + /*Code diffuseness*/ for ( b = start_band; b < nbands; b++ ) { - bits_raw += df_ratio_bits[b]; - max_df_ratio_bits = max( df_ratio_bits[b], max_df_ratio_bits ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - 4, DIRAC_DIFFUSE_LEVELS - 4 ); } - min_index = q_direction->band_data[start_band].energy_ratio_index[0]; - max_index = q_direction->band_data[start_band].energy_ratio_index[0]; + /* Compute and Quantize an average direction per band*/ for ( b = start_band; b < nbands; b++ ) { - if ( q_direction->band_data[b].energy_ratio_index[0] < min_index ) + set_zero( avg_direction_vector, 3 ); + for ( m = 0; m < nblocks; m++ ) { - min_index = q_direction->band_data[b].energy_ratio_index[0]; + /*compute the average direction */ + ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[b].azimuth[m], q_direction->band_data[b].elevation[m], direction_vector ); + v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); } - if ( q_direction->band_data[b].energy_ratio_index[0] > max_index ) + ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth[b], &avg_elevation[b] ); + + /* Quantize the average direction */ + if ( q_direction->not_in_2D == 0 ) { - max_index = q_direction->band_data[b].energy_ratio_index[0]; + avg_elevation[b] = 0; + q_direction->band_data[b].spherical_index[0] = quantize_direction2D( avg_azimuth[b], q_direction->band_data[b].azimuth_m_alphabet[0], &avg_azimuth[b], + &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); + } + else + { + q_direction->band_data[b].spherical_index[0] = quantize_direction( avg_elevation[b], avg_azimuth[b], q_direction->band_data[b].bits_sph_idx[0], &avg_elevation[b], &avg_azimuth[b], + &q_direction->band_data[b].elevation_index[0], &q_direction->band_data[b].azimuth_index[0], q_direction->cfg.mc_ls_setup ); } - } - /* Decide what modes are possible */ - if ( bits_raw >= max_df_ratio_bits + 2 + nbands ) - { - ec_mode = 2; - } - else if ( bits_raw >= max_df_ratio_bits + 1 ) - { - ec_mode = 1; - } - else - { - ec_mode = 0; - } - max_alphabet_size = 1 << max_df_ratio_bits; + /* Save quantized DOAs */ + q_direction->band_data[b].q_azimuth[0] = avg_azimuth[b]; + q_direction->band_data[b].q_elevation[0] = avg_elevation[b]; - if ( min_index == max_index && ec_mode > 0 ) /* all values are equal */ - { - push_next_indice( hMetaData, 0, 1 ); /* Signal between EC and raw */ - if ( ec_mode > 1 ) + if ( q_direction->band_data[b].azimuth_index[0] == MASA_NO_INDEX ) { - /* Only use bit for signaling if necessary */ - push_next_indice( hMetaData, 0, 1 ); /* Signal between one value or bandwise diff mode */ + q_direction->band_data[b].azimuth_index[0] = 0; } - - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size ); } - else if ( min_index + 1 == max_index && ec_mode > 1 ) /* only two consecutive values are present */ - { - push_next_indice( hMetaData, 0, 1 ); - push_next_indice( hMetaData, 1, 1 ); - ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size - 1 ); + /* quantize average elevation and azimuth angles */ + if ( q_direction->not_in_2D > 0 ) + { for ( b = start_band; b < nbands; b++ ) { - push_next_indice( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - min_index, 1 ); /* Band-wise offset values */ + push_next_indice( hMetaData, q_direction->band_data[b].spherical_index[0], q_direction->band_data[b].bits_sph_idx[0] ); } } - else /* raw coding */ + else { - if ( ec_mode > 0 ) + for ( b = start_band; b < nbands; b++ ) { - push_next_indice( hMetaData, 1, 1 ); /* Only signal raw mode if not implicitly using it */ + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].azimuth_index[0], q_direction->band_data[b].azimuth_m_alphabet[0] ); } + } - for ( b = start_band; b < nbands; b++ ) - { - ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], 1 << df_ratio_bits[b] ); /* dif_values */ - } + + /* fill bits*/ + assert( ( hMetaData->nb_bits_tot - bit_pos_start ) <= metadata_sid_bits && "Too many written bits!" ); + while ( ( hMetaData->nb_bits_tot - bit_pos_start ) < metadata_sid_bits ) + { + push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ } - return ( hMetaData->nb_bits_tot - start_bit_pos ); + return; } +#endif /*------------------------------------------------------------------------- - * restore_metadata_buffer() + * reset_metadata_spatial() * - * Restore metadata buffer + * Reset metadata in spatial formats *------------------------------------------------------------------------*/ -void restore_metadata_buffer( - BSTR_ENC_HANDLE hMetaData, - const int16_t next_ind_start, - const int16_t bit_pos_start ) +void reset_metadata_spatial( + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + BSTR_ENC_HANDLE hMetaData, /* i/o: metadata bitstream handle */ + const int32_t element_brate, /* i : element bitrate */ + int32_t *total_brate, /* o : total bitrate */ + const int32_t core_brate, /* i : core bitrate */ + const int16_t nb_bits_metadata /* i : number of meatdata bits */ +) { - int16_t i; + int16_t i, next_ind_sid, last_ind_sid; + int16_t j; + int16_t metadata_sid_bits; - for ( i = next_ind_start; i < hMetaData->nb_ind_tot; i++ ) + if ( core_brate == SID_2k40 || core_brate == FRAME_NO_DATA ) { - hMetaData->ind_list[i].nb_bits = -1; - } - hMetaData->nb_bits_tot = bit_pos_start; - hMetaData->nb_ind_tot = next_ind_start; + if ( ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT ) && core_brate != FRAME_NO_DATA ) + { + if ( ivas_format == SBA_FORMAT ) + { + hMetaData->ind_list[0].value = 1; + metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; - return; -} + while ( hMetaData->nb_bits_tot < metadata_sid_bits ) + { + push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ + } + } + else + { + /* Reset metadata and keep only SID metadata*/ + last_ind_sid = hMetaData->nb_ind_tot; + next_ind_sid = hMetaData->nb_ind_tot; + while ( hMetaData->nb_bits_tot > nb_bits_metadata ) + { + next_ind_sid--; + hMetaData->nb_bits_tot -= hMetaData->ind_list[next_ind_sid].nb_bits; + } + hMetaData->nb_bits_tot = 0; -/*------------------------------------------------------------------------- - * ivas_qmetadata_encode_quasi_uniform() - * - * encode value using a quasi-uniform code of b or b + 1 bits, where b = floor(log2(alphabet_size)) - *------------------------------------------------------------------------*/ + for ( i = 0; i < next_ind_sid; i++ ) + { + hMetaData->ind_list[i].nb_bits = -1; + } -static void ivas_qmetadata_encode_quasi_uniform( - BSTR_ENC_HANDLE hMetaData, - const uint16_t value, - const uint16_t alphabet_size ) -{ - int16_t bits; - uint16_t tresh; + for ( j = 0, i = next_ind_sid; i < last_ind_sid; i++, j++ ) + { + hMetaData->ind_list[j].value = hMetaData->ind_list[i].value; + hMetaData->ind_list[j].nb_bits = hMetaData->ind_list[i].nb_bits; + hMetaData->nb_bits_tot += hMetaData->ind_list[j].nb_bits; + hMetaData->ind_list[i].nb_bits = -1; + } - bits = 30 - norm_l( alphabet_size ); /* bits = floor(log2(alphabet_size)) */ - tresh = ( 1U << ( bits + 1 ) ) - alphabet_size; + hMetaData->nb_ind_tot = j; + } + } + else + { + /*Reset metadata*/ + reset_indices_enc( hMetaData, hMetaData->nb_ind_tot ); + } - if ( value < tresh ) - { - push_next_indice( hMetaData, value, bits ); + *total_brate = element_brate; } - else /* value >= tresh */ + else if ( ivas_format != SBA_FORMAT ) { - push_next_indice( hMetaData, value + tresh, bits + 1 ); + /* Reset SID metadata bits*/ + while ( hMetaData->nb_bits_tot > nb_bits_metadata ) + { + hMetaData->nb_ind_tot--; + hMetaData->nb_bits_tot -= hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits; + hMetaData->ind_list[hMetaData->nb_ind_tot].nb_bits = -1; + } } return; } -/*-----------------------------------------------------------------------* - * GR encoder function definitions - *-----------------------------------------------------------------------*/ /*------------------------------------------------------------------------- - * GR_bits_new() + * quantize_direction2D() * * *------------------------------------------------------------------------*/ -/*! r: number of bits using Golomb Rice code */ -static int16_t GR_bits_new( - uint16_t *data, /* i : data to encode with GR */ - int16_t *no_symb, /* i : number of symbols for each component*/ - const int16_t no_data, /* i : number of input data */ - const int16_t GR_order, /* i : GR order to be used */ - const int16_t check_two_orders, /* i : check also coding with GR_order-1 */ - int16_t *real_GR_ord /* o : the GR order that has been used */ +/*! r: quantized spherical index */ +int16_t quantize_direction2D( + float phi, /* i : input azimuth value */ + const int16_t no_cw, /* i : number of bits */ + float *phi_q, /* o : quantized azimuth value */ + uint16_t *index_phi, /* o : quantized azimuth index */ + const MC_LS_SETUP mc_format /* i : channel format if in MC-mode */ ) { - int16_t nbits = 0, i; - int16_t nbits1 = 0; - int16_t nb; - - for ( i = 0; i < no_data; i++ ) + int16_t idx_sph; + uint16_t id_phi; + if ( no_cw < 2 ) { - nb = ivas_qmetadata_encode_extended_gr_length( data[i], no_symb[i], GR_order ); - nbits += nb; + *phi_q = 0; + + return 0; } - if ( check_two_orders == 1 ) + if ( mc_format != MC_LS_SETUP_INVALID ) { - for ( i = 0; i < no_data; i++ ) - { - nb = ivas_qmetadata_encode_extended_gr_length( data[i], no_symb[i], GR_order - 1 ); - nbits1 += nb; - } - - if ( nbits1 < nbits ) - { - nbits = nbits1 + 1; - *real_GR_ord = GR_order - 1; - } - else - { - nbits += 1; - *real_GR_ord = GR_order; - } + id_phi = quantize_phi_chan_compand( phi + 180, phi_q, no_cw, 0, mc_format ); } else { - *real_GR_ord = GR_order; + id_phi = quantize_phi( phi + 180, 0, phi_q, no_cw ); } + *phi_q -= 180; + *index_phi = ivas_qmetadata_reorder_generic( id_phi - ( no_cw >> 1 ) ); - return nbits; -} - + idx_sph = id_phi; -/*------------------------------------------------------------------------- - * GR_bits_azimuth_context() - * - * Encoding azimuth indexes with GR code using context - *------------------------------------------------------------------------*/ + return idx_sph; +} -/*! r: numer of bits used for coding */ -static int16_t GR_bits_azimuth_context( - uint16_t *data_in, /* i : data to be encoded */ - int16_t *no_symb, /* i : number of symbols for each component */ - const int16_t no_data_in, /* i : number of input data */ - const int16_t GR_order, /* i : GR order (GR_order or GR_order-1 are used ) */ - const uint16_t *bits_dir, /* i : bits for encoding the direction for each TF tile */ - int16_t *real_GR_ord, /* o : which GR order has been used */ - int16_t *p_use_context /* o : flag telling if context has been used or not */ -) +#ifdef IVAS_FLOAT_FIXED +static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( + IVAS_QMETADATA_HANDLE hQMetaData, + int16_t *needed_bits, + const int16_t bits_dir_hr, + BSTR_ENC_HANDLE hMetaData ) { - int16_t i, nbits, nbits1, use_context; - uint16_t cdata[MAX_PARAM_SPATIAL_SUBFRAMES]; - uint16_t data[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t min_val, max_val; - int16_t real_GR_ord1; - int16_t no_symb_local[MAX_PARAM_SPATIAL_SUBFRAMES]; - int16_t no_data = 0; - - for ( i = 0; i < no_data_in; i++ ) - { - if ( data_in[i] < MASA_NO_INDEX ) - { - no_symb_local[no_data] = no_symb[i]; - data[no_data++] = data_in[i]; - } - } - - if ( no_data == 0 ) - { - *p_use_context = -3; /* corresponding to nothing to be written */ - return 0; - } + int16_t j, k; + int16_t index; - nbits = 0; - use_context = 0; + needed_bits[0] = 0; + needed_bits[1] = 0; - for ( i = 0; i < no_data; i++ ) + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) { - if ( ( bits_dir[i] <= 1 ) ) - { - nbits += bits_dir[i]; - use_context = 1; - } - else + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { - *real_GR_ord = GR_order - ( bits_dir[i] == 2 ); - nbits += ivas_qmetadata_encode_extended_gr_length( data[i], no_symb_local[i], *real_GR_ord ); +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] = floatToFixed( hQMetaData->q_direction[0].band_data[j].energy_ratio[k], Q30 ); + /*=====================================flt-2-fix============================================*/ + + index = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[k] ), diffuseness_thresholds_hr_fx, HR_MASA_ER_LEVELS ); +#else + index = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); +#endif + push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index; + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index; + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; + needed_bits[0] += MASA_BITS_ER_HR; + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_dir_hr; } } - real_GR_ord1 = 0; - if ( use_context == 0 ) + if ( hQMetaData->no_directions == 2 ) { - nbits = GR_bits_new( data, no_symb_local, no_data, GR_order, 1, real_GR_ord ); - nbits1 = nbits; - - min_val = data[0]; - for ( i = 1; i < no_data; i++ ) + float ratioSum; + if ( bits_dir_hr == 16 ) { - if ( data[i] < min_val ) + for ( j = hQMetaData->q_direction[1].cfg.start_band; j < hQMetaData->q_direction[1].cfg.nbands; j++ ) { - min_val = data[i]; - } + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] = floatToFixed( hQMetaData->q_direction[1].band_data[j].energy_ratio[k], Q30 ); + /*=====================================flt-2-fix============================================*/ + + index = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] ), diffuseness_thresholds_hr_fx, HR_MASA_ER_LEVELS ); +#else + index = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); +#endif + push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); + hQMetaData->q_direction[1].band_data[j].energy_ratio_index[k] = index; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; + + ratioSum = hQMetaData->q_direction[0].band_data[j].energy_ratio[k] + hQMetaData->q_direction[1].band_data[j].energy_ratio[k]; + if ( ratioSum > 1.0f ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] /= ratioSum; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] /= ratioSum; + } + + needed_bits[1] += MASA_BITS_ER_HR; + hQMetaData->q_direction[1].band_data[j].bits_sph_idx[k] = bits_dir_hr; + } + } } - for ( i = 0; i < no_data; i++ ) + else { - cdata[i] = data[i] - min_val; + int16_t pos_2dir_band[MASA_MAXIMUM_CODING_SUBBANDS]; + k = 0; + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; j++ ) + { + if ( hQMetaData->twoDirBands[j] == 1 ) + { + pos_2dir_band[k] = j; + k++; + } + else + { + pos_2dir_band[k] = 0; + } + } + for ( j = hQMetaData->q_direction[1].cfg.start_band; j < hQMetaData->q_direction[1].cfg.nbands; j++ ) + { + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] = floatToFixed( hQMetaData->q_direction[1].band_data[j].energy_ratio[k], Q30 ); + /*=====================================flt-2-fix============================================*/ + + index = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[1].band_data[j].energy_ratio_fx[k] ), diffuseness_thresholds_hr_fx, HR_MASA_ER_LEVELS ); +#else + index = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); +#endif + push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); + hQMetaData->q_direction[1].band_data[j].energy_ratio_index[k] = index; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; + + ratioSum = hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio[k] + hQMetaData->q_direction[1].band_data[j].energy_ratio[k]; + + if ( ratioSum > 1.0f ) + { + hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio[k] /= ratioSum; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] /= ratioSum; + } + + needed_bits[1] += MASA_BITS_ER_HR; + hQMetaData->q_direction[1].band_data[j].bits_sph_idx[k] = bits_dir_hr; + } + } } + } - maximum_s( no_symb_local, no_data, &max_val ); - nbits1 = GR_bits_new( cdata, no_symb_local, no_data, GR_order - 1, 1, &real_GR_ord1 ) + ivas_qmetadata_encode_extended_gr_length( min_val, max_val, MASA_GR_ORD_AZ ); + return; +} +#else +static void ivas_qmetadata_quantize_diffuseness_nrg_ratios_hr_512( + IVAS_QMETADATA_HANDLE hQMetaData, + int16_t *needed_bits, + const int16_t bits_dir_hr, + BSTR_ENC_HANDLE hMetaData ) +{ + int16_t j, k; + int16_t index; - if ( nbits1 < nbits ) + needed_bits[0] = 0; + needed_bits[1] = 0; + + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) { - nbits = nbits1 + 1; - use_context = -2; - *real_GR_ord = real_GR_ord1; + index = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); + push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index; + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index; + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; + needed_bits[0] += MASA_BITS_ER_HR; + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_dir_hr; + } + } + + if ( hQMetaData->no_directions == 2 ) + { + float ratioSum; + if ( bits_dir_hr == 16 ) + { + for ( j = hQMetaData->q_direction[1].cfg.start_band; j < hQMetaData->q_direction[1].cfg.nbands; j++ ) + { + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { + index = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); + push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); + hQMetaData->q_direction[1].band_data[j].energy_ratio_index[k] = index; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; + + ratioSum = hQMetaData->q_direction[0].band_data[j].energy_ratio[k] + hQMetaData->q_direction[1].band_data[j].energy_ratio[k]; + if ( ratioSum > 1.0f ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] /= ratioSum; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] /= ratioSum; + } + + needed_bits[1] += MASA_BITS_ER_HR; + hQMetaData->q_direction[1].band_data[j].bits_sph_idx[k] = bits_dir_hr; + } + } } else { - nbits = nbits + 1; - use_context = -1; + int16_t pos_2dir_band[MASA_MAXIMUM_CODING_SUBBANDS]; + k = 0; + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; j++ ) + { + if ( hQMetaData->twoDirBands[j] == 1 ) + { + pos_2dir_band[k] = j; + k++; + } + else + { + pos_2dir_band[k] = 0; + } + } + for ( j = hQMetaData->q_direction[1].cfg.start_band; j < hQMetaData->q_direction[1].cfg.nbands; j++ ) + { + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { + index = masa_sq( 1.0f - hQMetaData->q_direction[1].band_data[j].energy_ratio[k], diffuseness_thresholds_hr, HR_MASA_ER_LEVELS ); + push_next_indice( hMetaData, index, MASA_BITS_ER_HR ); + hQMetaData->q_direction[1].band_data[j].energy_ratio_index[k] = index; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions_hr[index]; + + ratioSum = hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio[k] + hQMetaData->q_direction[1].band_data[j].energy_ratio[k]; + + if ( ratioSum > 1.0f ) + { + hQMetaData->q_direction[0].band_data[pos_2dir_band[j]].energy_ratio[k] /= ratioSum; + hQMetaData->q_direction[1].band_data[j].energy_ratio[k] /= ratioSum; + } + + needed_bits[1] += MASA_BITS_ER_HR; + hQMetaData->q_direction[1].band_data[j].bits_sph_idx[k] = bits_dir_hr; + } + } } } - *p_use_context = use_context; - - return nbits; + return; } +#endif /*------------------------------------------------------------------------- - * mean_removed_GR_new() + * ivas_qmetadata_quantize_diffuseness_nrg_ratios() * - * Golomb Rice encoding with mean removing + * Quantize diffuseness *------------------------------------------------------------------------*/ -/*! r: number of bits used */ -static int16_t mean_removed_GR_new( - const uint16_t *idx, /* i : data to encode */ - const int16_t max_no_symb, - const int16_t len, /* i : number of data */ - const int16_t adapt_GR, /* i : flag for telling to use or nor two GR order values */ - int16_t *GR_ord, /* i/o: GR order */ - uint16_t *p_av, /* o : average index */ - uint16_t *mr_idx /* o : mean removed indexes */ -) +#ifdef IVAS_FLOAT_FIXED +static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( + IVAS_QMETADATA_HANDLE hQMetaData, + int16_t *needed_bits, + int16_t *nbits_diff, + int16_t *dfRatioBits, + const int16_t hodirac_flag ) { - int16_t av, i, nbits; - int16_t sh_idx[MASA_MAXIMUM_CODING_SUBBANDS]; - int16_t max_ns[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t j, k, dir2band; + int16_t index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; + int16_t index_diff; + + nbits_diff[0] = 0; + nbits_diff[1] = 0; + needed_bits[0] = 0; + needed_bits[1] = 0; + dir2band = 0; + + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { + if ( hQMetaData->no_directions == 2 && hQMetaData->twoDirBands[j] == 1 ) + { + float diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; +#ifdef IVAS_FLOAT_FIXED + Word32 diffRatio_fx, dirRatio1Q_fx, dirRatio2Q_fx; +#endif + float dirRatio1, dirRatio2, sumRatio; + int16_t dfRatio_index, dfRatio_qsteps, dfRatio_bits; + + /* With 2dir metadata, we quantize and transmit diffuse-to-total ratio (diffRatio) and + * distribution factor of direct-to-total ratios (dFRatio). This is more efficient and + * accurate than simple separate quantization of each direct-to-total ratio or their + * separate inverses. */ + if ( hodirac_flag ) + { + /* already encoded as total and ratios in HO-DirAC */ + diffRatio = 1.f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0]; + dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0]; + } + else + { + dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio[0]; + dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0]; + sumRatio = dirRatio1 + dirRatio2; + diffRatio = 1.0f - sumRatio; + dfRatio = sumRatio < EPSILON ? 0.5f : dirRatio1 / sumRatio; + } + + +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + diffRatio_fx = floatToFixed( diffRatio, Q30 ); + /*=====================================flt-2-fix============================================*/ + + index_diff = masa_sq_fx( diffRatio_fx, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +#else + index_diff = masa_sq( diffRatio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); +#endif + diffRatioQ = diffuseness_reconstructions[index_diff]; + + if ( hodirac_flag ) + { + dfRatio_bits = ivas_get_df_ratio_bits_hodirac( index_diff ); + } + else + { + dfRatio_bits = ivas_get_df_ratio_bits( index_diff ); + } + + dfRatioBits[dir2band] = dfRatio_bits; + + dfRatio_qsteps = ( 1 << dfRatio_bits ); + if ( hodirac_flag ) + { + dfRatio_index = usquant( dfRatio, &dfRatioQ, 0.0f, 1.f / ( dfRatio_qsteps - 1 ), dfRatio_qsteps ); + dirRatio1Q = 1.f - diffRatioQ; + dirRatio2Q = dfRatioQ; + } + else + { + dfRatio_index = usquant( dfRatio, &dfRatioQ, 0.5f, 0.5f / ( dfRatio_qsteps - 1 ), dfRatio_qsteps ); + + /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ + dirRatio1Q = dfRatioQ * ( 1.0f - diffRatioQ ); + dirRatio2Q = ( 1.0f - diffRatioQ ) - dirRatio1Q; + } + +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + dirRatio1Q_fx = floatToFixed( dirRatio1Q, Q30 ); + /*=====================================flt-2-fix============================================*/ + + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio1Q_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +#else + index_dirRatio1Inv = masa_sq( 1.0f - dirRatio1Q, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); +#endif + + /* Note: To save memory, we store temporarily index_diff and dfRatio_index into first and second direction + * energy ratio index variables until they have been encoded. index_dirRatio1Inv and index_dirRatio2Inv are + * then later retrieved for further use in encoding. */ + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = dirRatio1Q; + } + nbits_diff[0] += MASA_BITS_ER; + + if ( hodirac_flag ) + { + float tmp; + index_dirRatio2Inv = usquant( dirRatio2Q, &tmp, 0.0f, 1.f / ( DIRAC_DIFFUSE_LEVELS - 1 ), DIRAC_DIFFUSE_LEVELS ); + } + else + { +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + dirRatio2Q_fx = floatToFixed( dirRatio2Q, Q30 ); + /*=====================================flt-2-fix============================================*/ + + index_dirRatio2Inv = masa_sq_fx( L_sub( ONE_IN_Q30, dirRatio2Q_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +#else + index_dirRatio2Inv = masa_sq( 1.0f - dirRatio2Q, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); +#endif + } + + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[k] = dirRatio2Q; + } + nbits_diff[1] += dfRatio_bits; + + /* Obtain compensated direct-to-total ratios for direction quantization. This compensates for the + * fact that with 2dir data, it is harder to achieve separate high direct-to-total ratio values + * which are assumed by the direction quantization system. In practice, this improves direction + * accuracy when it is perceptual meaningful. */ +#ifdef IVAS_FLOAT_FIXED + masa_compensate_two_dir_energy_ratio_index_fx( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); +#else + masa_compensate_two_dir_energy_ratio_index( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); +#endif + + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; + } + needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv_mod]; + + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; + hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; + } + needed_bits[1] += hQMetaData->q_direction[1].cfg.nblocks * bits_direction_masa[index_dirRatio2Inv_mod]; + + dir2band++; + } + else + { +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] = floatToFixed( hQMetaData->q_direction[0].band_data[j].energy_ratio[0], Q30 ); + /*=====================================flt-2-fix============================================*/ + + index_dirRatio1Inv = masa_sq_fx( L_sub( ONE_IN_Q30, hQMetaData->q_direction[0].band_data[j].energy_ratio_fx[0] ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +#else + index_dirRatio1Inv = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); +#endif + + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions[index_dirRatio1Inv]; + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; + } + + nbits_diff[0] += MASA_BITS_ER; + + needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv]; + } + } + + return; +} +#else +static void ivas_qmetadata_quantize_diffuseness_nrg_ratios( + IVAS_QMETADATA_HANDLE hQMetaData, + int16_t *needed_bits, + int16_t *nbits_diff, + int16_t *dfRatioBits, + const int16_t hodirac_flag ) +{ + int16_t j, k, dir2band; + int16_t index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; + int16_t index_diff; + + nbits_diff[0] = 0; + nbits_diff[1] = 0; + needed_bits[0] = 0; + needed_bits[1] = 0; + dir2band = 0; + + for ( j = hQMetaData->q_direction[0].cfg.start_band; j < hQMetaData->q_direction[0].cfg.nbands; ++j ) + { + if ( hQMetaData->no_directions == 2 && hQMetaData->twoDirBands[j] == 1 ) + { + float diffRatio, dfRatio, dfRatioQ, diffRatioQ, dirRatio1Q, dirRatio2Q; + float dirRatio1, dirRatio2, sumRatio; + int16_t dfRatio_index, dfRatio_qsteps, dfRatio_bits; + + /* With 2dir metadata, we quantize and transmit diffuse-to-total ratio (diffRatio) and + * distribution factor of direct-to-total ratios (dFRatio). This is more efficient and + * accurate than simple separate quantization of each direct-to-total ratio or their + * separate inverses. */ + if ( hodirac_flag ) + { + /* already encoded as total and ratios in HO-DirAC */ + diffRatio = 1.f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0]; + dfRatio = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0]; + } + else + { + dirRatio1 = hQMetaData->q_direction[0].band_data[j].energy_ratio[0]; + dirRatio2 = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[0]; + sumRatio = dirRatio1 + dirRatio2; + diffRatio = 1.0f - sumRatio; + dfRatio = sumRatio < EPSILON ? 0.5f : dirRatio1 / sumRatio; + } + + + index_diff = masa_sq( diffRatio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + diffRatioQ = diffuseness_reconstructions[index_diff]; + + if ( hodirac_flag ) + { + dfRatio_bits = ivas_get_df_ratio_bits_hodirac( index_diff ); + } + else + { + dfRatio_bits = ivas_get_df_ratio_bits( index_diff ); + } + + dfRatioBits[dir2band] = dfRatio_bits; + + dfRatio_qsteps = ( 1 << dfRatio_bits ); + if ( hodirac_flag ) + { + dfRatio_index = usquant( dfRatio, &dfRatioQ, 0.0f, 1.f / ( dfRatio_qsteps - 1 ), dfRatio_qsteps ); + dirRatio1Q = 1.f - diffRatioQ; + dirRatio2Q = dfRatioQ; + } + else + { + dfRatio_index = usquant( dfRatio, &dfRatioQ, 0.5f, 0.5f / ( dfRatio_qsteps - 1 ), dfRatio_qsteps ); + + /* Direction quantization requires also separately quantized direct-to-total ratios. Thus, we calculate them. */ + dirRatio1Q = dfRatioQ * ( 1.0f - diffRatioQ ); + dirRatio2Q = ( 1.0f - diffRatioQ ) - dirRatio1Q; + } + + index_dirRatio1Inv = masa_sq( 1.0f - dirRatio1Q, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + + /* Note: To save memory, we store temporarily index_diff and dfRatio_index into first and second direction + * energy ratio index variables until they have been encoded. index_dirRatio1Inv and index_dirRatio2Inv are + * then later retrieved for further use in encoding. */ + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_diff; + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = dirRatio1Q; + } + nbits_diff[0] += MASA_BITS_ER; + + if ( hodirac_flag ) + { + float tmp; + index_dirRatio2Inv = usquant( dirRatio2Q, &tmp, 0.0f, 1.f / ( DIRAC_DIFFUSE_LEVELS - 1 ), DIRAC_DIFFUSE_LEVELS ); + } + else + { + index_dirRatio2Inv = masa_sq( 1.0f - dirRatio2Q, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + } + + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[k] = dfRatio_index; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio[k] = dirRatio2Q; + } + nbits_diff[1] += dfRatio_bits; + + /* Obtain compensated direct-to-total ratios for direction quantization. This compensates for the + * fact that with 2dir data, it is harder to achieve separate high direct-to-total ratio values + * which are assumed by the direction quantization system. In practice, this improves direction + * accuracy when it is perceptual meaningful. */ + + masa_compensate_two_dir_energy_ratio_index( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); + + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv_mod; + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv_mod]; + } + needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv_mod]; + + for ( k = 0; k < hQMetaData->q_direction[1].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[k] = index_dirRatio2Inv_mod; + hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[k] = bits_direction_masa[index_dirRatio2Inv_mod]; + } + needed_bits[1] += hQMetaData->q_direction[1].cfg.nblocks * bits_direction_masa[index_dirRatio2Inv_mod]; + + dir2band++; + } + else + { + index_dirRatio1Inv = masa_sq( 1.0f - hQMetaData->q_direction[0].band_data[j].energy_ratio[0], diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + + for ( k = 0; k < hQMetaData->q_direction[0].cfg.nblocks; k++ ) + { + hQMetaData->q_direction[0].band_data[j].energy_ratio_index[k] = index_dirRatio1Inv; + hQMetaData->q_direction[0].band_data[j].energy_ratio_index_mod[k] = index_dirRatio1Inv; + hQMetaData->q_direction[0].band_data[j].energy_ratio[k] = 1.0f - diffuseness_reconstructions[index_dirRatio1Inv]; + hQMetaData->q_direction[0].band_data[j].bits_sph_idx[k] = bits_direction_masa[index_dirRatio1Inv]; + } + + nbits_diff[0] += MASA_BITS_ER; + + needed_bits[0] += hQMetaData->q_direction[0].cfg.nblocks * bits_direction_masa[index_dirRatio1Inv]; + } + } + + return; +} +#endif + + +/*------------------------------------------------------------------------- + * ivas_diffuseness_huff_ec_encode() + * + * + *------------------------------------------------------------------------*/ + +static int16_t ivas_diffuseness_huff_ec_encode( + BSTR_ENC_HANDLE hMetaData, + const uint16_t idx ) +{ + int16_t nbits; + nbits = 0; + if ( idx <= DIFF_EC_HUFF_GR0_LIMIT ) + { + if ( idx > 0 ) + { + push_next_indice( hMetaData, ( 1 << idx ) - 1, idx ); + nbits += idx; + } + push_next_indice( hMetaData, 0, 1 ); + nbits += 1; + } + else + { + push_next_indice( hMetaData, 511, DIFF_EC_HUFF_GR0_LIMIT + 1 ); + push_next_indice( hMetaData, idx - DIFF_EC_HUFF_GR0_LIMIT - 1, 2 ); + nbits += DIFF_EC_HUFF_GR0_LIMIT + 3; + } + return nbits; +} + + +/*------------------------------------------------------------------------- + * ivas_diffuseness_huff_ec_prepare() + * + * + *------------------------------------------------------------------------*/ + +static void ivas_diffuseness_huff_ec_prepare( + IVAS_QDIRECTION *q_direction, + int16_t *best_av, + uint16_t *avr_idx, + int16_t *diffuseness_bits_huff ) +{ + int16_t bits; + int16_t av_crt; + int16_t av; + int16_t sh_idx; + uint16_t ui_sh_idx[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t b, start_band, nbands; + + start_band = q_direction->cfg.start_band; + nbands = q_direction->cfg.nbands; + + *diffuseness_bits_huff = 0; + av = 0; + for ( b = start_band; b < nbands; b++ ) + { + av += q_direction->band_data[b].energy_ratio_index[0]; + } + av = (int16_t) ( 0.5f + av / (float) nbands ); + *best_av = av; + + *diffuseness_bits_huff = MAX16B; + for ( av_crt = av - 1; av_crt <= av + 1; av_crt++ ) + { + bits = 0; + for ( b = start_band; b < nbands; b++ ) + { + sh_idx = q_direction->band_data[b].energy_ratio_index[0] - av_crt; + ui_sh_idx[b] = ( sh_idx <= 0 ) ? ( -2 * sh_idx ) : sh_idx * 2 - 1; + if ( ui_sh_idx[b] >= 2 * DIRAC_DIFFUSE_LEVELS - 3 ) + { + bits = 100; /* to avoid difference larger than 6 in absolute value */ + } + + bits += ( ui_sh_idx[b] <= DIFF_EC_HUFF_GR0_LIMIT ) ? ( ui_sh_idx[b] + 1 ) : 11; + } + + if ( bits < *diffuseness_bits_huff ) + { + *diffuseness_bits_huff = bits; + mvs2s( (int16_t *) ui_sh_idx, (int16_t *) avr_idx, nbands ); + *best_av = av_crt; + } + } + + *diffuseness_bits_huff += MASA_BITS_ER; /* for the average */ + + return; +} + +/*------------------------------------------------------------------------- + * ivas_qmetadata_entropy_encode_diffuseness() + * + * encode diffuseness + *------------------------------------------------------------------------*/ + +static int16_t ivas_qmetadata_entropy_encode_diffuseness( + BSTR_ENC_HANDLE hMetaData, + IVAS_QDIRECTION *q_direction, + uint16_t *diffuseness_index_max_ec_frame ) +{ + int16_t start_bit_pos; + int16_t diffuseness_bits_raw; + int16_t b; + int16_t min_diffuseness_m_index, max_diffuseness_m_index; + int16_t nbands; + int16_t start_band; + + nbands = q_direction->cfg.nbands; + start_band = q_direction->cfg.start_band; + + start_bit_pos = hMetaData->nb_bits_tot; + + if ( nbands == 1 ) + { + /* If there is only one band, diffuseness should be coded directly as raw with no signaling. */ + push_next_indice( hMetaData, q_direction->band_data[0].energy_ratio_index[0], MASA_BITS_ER ); + *diffuseness_index_max_ec_frame = 5; + return ( hMetaData->nb_bits_tot - start_bit_pos ); + } + + /* compute the number of raw coding bits */ + diffuseness_bits_raw = 0; + for ( b = start_band; b < nbands; b++ ) + { + diffuseness_bits_raw += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); + } + + min_diffuseness_m_index = q_direction->band_data[start_band].energy_ratio_index[0]; + max_diffuseness_m_index = q_direction->band_data[start_band].energy_ratio_index[0]; + + for ( b = start_band; b < nbands; b++ ) + { + if ( q_direction->band_data[b].energy_ratio_index[0] < min_diffuseness_m_index ) + { + min_diffuseness_m_index = q_direction->band_data[b].energy_ratio_index[0]; + } + + if ( q_direction->band_data[b].energy_ratio_index[0] > max_diffuseness_m_index ) + { + max_diffuseness_m_index = q_direction->band_data[b].energy_ratio_index[0]; + } + } + + if ( nbands < DIFF_EC_HUFF_BAND_LIMIT ) + { + /* Use similarity coding approach or raw coding when there is a low number of bands. */ + /* one bit is used to indicate whether diffuseness values are entropy coded or coded raw */ + if ( min_diffuseness_m_index == max_diffuseness_m_index ) /* all values are equal */ + { + push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ + push_next_indice( hMetaData, 1, 1 ); /* dif_have_unique_value */ + ivas_qmetadata_encode_quasi_uniform( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ + } + else if ( min_diffuseness_m_index + 1 == max_diffuseness_m_index ) /* only two consecutive values are present */ + { + push_next_indice( hMetaData, 0, 1 ); /* dif_use_raw_coding */ + push_next_indice( hMetaData, 0, 1 ); /* dif_have_unique_value */ + ivas_qmetadata_encode_quasi_uniform( hMetaData, min_diffuseness_m_index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value */ + + for ( b = start_band; b < nbands; b++ ) + { + push_next_indice( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - min_diffuseness_m_index, 1 ); /* dif_bit_offset_values */ + } + } + else /* raw coding */ + { + push_next_indice( hMetaData, 1, 1 ); /* dif_use_raw_coding */ + + for ( b = start_band; b < nbands; b++ ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ + } + } + } + else + { + /* Use Huffman-coding approach or raw coding when there is a high number of bands. */ + int16_t diffuseness_bits_huff; + int16_t best_av; + uint16_t avr_idx[MASA_MAXIMUM_CODING_SUBBANDS]; + + /* First, obtain average indices and bit usage for Huffman-coding. */ + ivas_diffuseness_huff_ec_prepare( q_direction, &best_av, avr_idx, &diffuseness_bits_huff ); + + /* If there is benefit, use Huffman-coding. Otherwise, use raw coding. */ + if ( diffuseness_bits_huff < diffuseness_bits_raw ) + { + /* Signal Huffman EC */ + push_next_indice( hMetaData, 0, 1 ); + push_next_indice( hMetaData, best_av, MASA_BITS_ER ); + for ( b = start_band; b < nbands; b++ ) + { + ivas_diffuseness_huff_ec_encode( hMetaData, avr_idx[b] ); + } + } + else + { + /* Signal raw */ + push_next_indice( hMetaData, 1, 1 ); + for ( b = start_band; b < nbands; b++ ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], DIRAC_DIFFUSE_LEVELS ); /* dif_values */ + } + } + } + + *diffuseness_index_max_ec_frame = 5; + /* adaptively select the diffuseness_index_max_ec threshold */ + if ( min_diffuseness_m_index > 5 ) + { + *diffuseness_index_max_ec_frame = DIRAC_DIFFUSE_LEVELS - 1; + } + + + return ( hMetaData->nb_bits_tot - start_bit_pos ); +} + + +/*------------------------------------------------------------------------- + * ivas_qmetadata_entropy_encode_df_ratio() + * + * encode dfRatio + *------------------------------------------------------------------------*/ + +static int16_t ivas_qmetadata_entropy_encode_df_ratio( + BSTR_ENC_HANDLE hMetaData, + IVAS_QDIRECTION *q_direction, + int16_t *df_ratio_bits ) +{ + int16_t start_bit_pos; + int16_t bits_raw; + int16_t b; + int16_t min_index, max_index; + int16_t nbands, start_band; + int16_t max_df_ratio_bits; + int16_t ec_mode = 0; + int16_t max_alphabet_size; + + nbands = q_direction->cfg.nbands; + start_band = q_direction->cfg.start_band; + + start_bit_pos = hMetaData->nb_bits_tot; + + if ( nbands == 1 ) + { + /* If there is only one band, ratio should be coded directly as raw with no signaling. */ + push_next_indice( hMetaData, q_direction->band_data[0].energy_ratio_index[0], df_ratio_bits[0] ); + + return ( hMetaData->nb_bits_tot - start_bit_pos ); + } + + /* compute the number of raw coding bits */ + bits_raw = 0; + max_df_ratio_bits = 0; + for ( b = start_band; b < nbands; b++ ) + { + bits_raw += df_ratio_bits[b]; + max_df_ratio_bits = max( df_ratio_bits[b], max_df_ratio_bits ); + } + + min_index = q_direction->band_data[start_band].energy_ratio_index[0]; + max_index = q_direction->band_data[start_band].energy_ratio_index[0]; + for ( b = start_band; b < nbands; b++ ) + { + if ( q_direction->band_data[b].energy_ratio_index[0] < min_index ) + { + min_index = q_direction->band_data[b].energy_ratio_index[0]; + } + + if ( q_direction->band_data[b].energy_ratio_index[0] > max_index ) + { + max_index = q_direction->band_data[b].energy_ratio_index[0]; + } + } + + /* Decide what modes are possible */ + if ( bits_raw >= max_df_ratio_bits + 2 + nbands ) + { + ec_mode = 2; + } + else if ( bits_raw >= max_df_ratio_bits + 1 ) + { + ec_mode = 1; + } + else + { + ec_mode = 0; + } + max_alphabet_size = 1 << max_df_ratio_bits; + + if ( min_index == max_index && ec_mode > 0 ) /* all values are equal */ + { + push_next_indice( hMetaData, 0, 1 ); /* Signal between EC and raw */ + if ( ec_mode > 1 ) + { + /* Only use bit for signaling if necessary */ + push_next_indice( hMetaData, 0, 1 ); /* Signal between one value or bandwise diff mode */ + } + + ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size ); + } + else if ( min_index + 1 == max_index && ec_mode > 1 ) /* only two consecutive values are present */ + { + push_next_indice( hMetaData, 0, 1 ); + push_next_indice( hMetaData, 1, 1 ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, min_index, max_alphabet_size - 1 ); + + for ( b = start_band; b < nbands; b++ ) + { + push_next_indice( hMetaData, q_direction->band_data[b].energy_ratio_index[0] - min_index, 1 ); /* Band-wise offset values */ + } + } + else /* raw coding */ + { + if ( ec_mode > 0 ) + { + push_next_indice( hMetaData, 1, 1 ); /* Only signal raw mode if not implicitly using it */ + } + + for ( b = start_band; b < nbands; b++ ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[b].energy_ratio_index[0], 1 << df_ratio_bits[b] ); /* dif_values */ + } + } + + return ( hMetaData->nb_bits_tot - start_bit_pos ); +} + + +/*------------------------------------------------------------------------- + * restore_metadata_buffer() + * + * Restore metadata buffer + *------------------------------------------------------------------------*/ + +void restore_metadata_buffer( + BSTR_ENC_HANDLE hMetaData, + const int16_t next_ind_start, + const int16_t bit_pos_start ) +{ + int16_t i; + + for ( i = next_ind_start; i < hMetaData->nb_ind_tot; i++ ) + { + hMetaData->ind_list[i].nb_bits = -1; + } + hMetaData->nb_bits_tot = bit_pos_start; + hMetaData->nb_ind_tot = next_ind_start; + + return; +} + + +/*------------------------------------------------------------------------- + * ivas_qmetadata_encode_quasi_uniform() + * + * encode value using a quasi-uniform code of b or b + 1 bits, where b = floor(log2(alphabet_size)) + *------------------------------------------------------------------------*/ + +static void ivas_qmetadata_encode_quasi_uniform( + BSTR_ENC_HANDLE hMetaData, + const uint16_t value, + const uint16_t alphabet_size ) +{ + int16_t bits; + uint16_t tresh; + + bits = 30 - norm_l( alphabet_size ); /* bits = floor(log2(alphabet_size)) */ + tresh = ( 1U << ( bits + 1 ) ) - alphabet_size; + + if ( value < tresh ) + { + push_next_indice( hMetaData, value, bits ); + } + else /* value >= tresh */ + { + push_next_indice( hMetaData, value + tresh, bits + 1 ); + } + + return; +} + + +/*-----------------------------------------------------------------------* + * GR encoder function definitions + *-----------------------------------------------------------------------*/ +/*------------------------------------------------------------------------- + * GR_bits_new() + * + * + *------------------------------------------------------------------------*/ + +/*! r: number of bits using Golomb Rice code */ +static int16_t GR_bits_new( + uint16_t *data, /* i : data to encode with GR */ + int16_t *no_symb, /* i : number of symbols for each component*/ + const int16_t no_data, /* i : number of input data */ + const int16_t GR_order, /* i : GR order to be used */ + const int16_t check_two_orders, /* i : check also coding with GR_order-1 */ + int16_t *real_GR_ord /* o : the GR order that has been used */ +) +{ + int16_t nbits = 0, i; + int16_t nbits1 = 0; + int16_t nb; + + for ( i = 0; i < no_data; i++ ) + { + nb = ivas_qmetadata_encode_extended_gr_length( data[i], no_symb[i], GR_order ); + nbits += nb; + } + + if ( check_two_orders == 1 ) + { + for ( i = 0; i < no_data; i++ ) + { + nb = ivas_qmetadata_encode_extended_gr_length( data[i], no_symb[i], GR_order - 1 ); + nbits1 += nb; + } + + if ( nbits1 < nbits ) + { + nbits = nbits1 + 1; + *real_GR_ord = GR_order - 1; + } + else + { + nbits += 1; + *real_GR_ord = GR_order; + } + } + else + { + *real_GR_ord = GR_order; + } + + return nbits; +} + + +/*------------------------------------------------------------------------- + * GR_bits_azimuth_context() + * + * Encoding azimuth indexes with GR code using context + *------------------------------------------------------------------------*/ + +/*! r: numer of bits used for coding */ +static int16_t GR_bits_azimuth_context( + uint16_t *data_in, /* i : data to be encoded */ + int16_t *no_symb, /* i : number of symbols for each component */ + const int16_t no_data_in, /* i : number of input data */ + const int16_t GR_order, /* i : GR order (GR_order or GR_order-1 are used ) */ + const uint16_t *bits_dir, /* i : bits for encoding the direction for each TF tile */ + int16_t *real_GR_ord, /* o : which GR order has been used */ + int16_t *p_use_context /* o : flag telling if context has been used or not */ +) +{ + int16_t i, nbits, nbits1, use_context; + uint16_t cdata[MAX_PARAM_SPATIAL_SUBFRAMES]; + uint16_t data[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t min_val, max_val; + int16_t real_GR_ord1; + int16_t no_symb_local[MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t no_data = 0; + + for ( i = 0; i < no_data_in; i++ ) + { + if ( data_in[i] < MASA_NO_INDEX ) + { + no_symb_local[no_data] = no_symb[i]; + data[no_data++] = data_in[i]; + } + } + + if ( no_data == 0 ) + { + *p_use_context = -3; /* corresponding to nothing to be written */ + return 0; + } + + nbits = 0; + use_context = 0; + + for ( i = 0; i < no_data; i++ ) + { + if ( ( bits_dir[i] <= 1 ) ) + { + nbits += bits_dir[i]; + use_context = 1; + } + else + { + *real_GR_ord = GR_order - ( bits_dir[i] == 2 ); + nbits += ivas_qmetadata_encode_extended_gr_length( data[i], no_symb_local[i], *real_GR_ord ); + } + } + + real_GR_ord1 = 0; + if ( use_context == 0 ) + { + nbits = GR_bits_new( data, no_symb_local, no_data, GR_order, 1, real_GR_ord ); + nbits1 = nbits; + + min_val = data[0]; + for ( i = 1; i < no_data; i++ ) + { + if ( data[i] < min_val ) + { + min_val = data[i]; + } + } + for ( i = 0; i < no_data; i++ ) + { + cdata[i] = data[i] - min_val; + } + + maximum_s( no_symb_local, no_data, &max_val ); + nbits1 = GR_bits_new( cdata, no_symb_local, no_data, GR_order - 1, 1, &real_GR_ord1 ) + ivas_qmetadata_encode_extended_gr_length( min_val, max_val, MASA_GR_ORD_AZ ); + + if ( nbits1 < nbits ) + { + nbits = nbits1 + 1; + use_context = -2; + *real_GR_ord = real_GR_ord1; + } + else + { + nbits = nbits + 1; + use_context = -1; + } + } + + *p_use_context = use_context; + + return nbits; +} + + +/*------------------------------------------------------------------------- + * mean_removed_GR_new() + * + * Golomb Rice encoding with mean removing + *------------------------------------------------------------------------*/ + +/*! r: number of bits used */ +static int16_t mean_removed_GR_new( + const uint16_t *idx, /* i : data to encode */ + const int16_t max_no_symb, + const int16_t len, /* i : number of data */ + const int16_t adapt_GR, /* i : flag for telling to use or nor two GR order values */ + int16_t *GR_ord, /* i/o: GR order */ + uint16_t *p_av, /* o : average index */ + uint16_t *mr_idx /* o : mean removed indexes */ +) +{ + int16_t av, i, nbits; + int16_t sh_idx[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t max_ns[MASA_MAXIMUM_CODING_SUBBANDS]; + + av = (int16_t) ( 0.5f + sum_s( (const int16_t *) idx, len ) / (float) len ); + *p_av = av; + for ( i = 0; i < len; i++ ) + { + max_ns[i] = 2 * ( max_no_symb ); + sh_idx[i] = idx[i] - av; + } + + for ( i = 0; i < len; i++ ) + { + if ( sh_idx[i] < 0 ) + { + sh_idx[i] = -2 * sh_idx[i]; + } + else if ( sh_idx[i] > 0 ) + { + sh_idx[i] = sh_idx[i] * 2 - 1; + } + else + { + sh_idx[i] = 0; + } + mr_idx[i] = (uint16_t) sh_idx[i]; + } + + nbits = GR_bits_new( mr_idx, max_ns, len, *GR_ord, adapt_GR, GR_ord ); + + return nbits; +} + + +/*------------------------------------------------------------------------- + * ivas_qmetadata_encode_quasi_uniform_length() + * + *------------------------------------------------------------------------*/ + +static int16_t ivas_qmetadata_encode_quasi_uniform_length( + const uint16_t value, + const uint16_t alphabet_size ) +{ + int16_t bits; + uint16_t tresh; + + bits = 30 - norm_l( alphabet_size ); /* bits = floor(log2(alphabet_size)) */ + tresh = ( 1U << ( bits + 1 ) ) - alphabet_size; + + if ( value >= tresh ) + { + bits++; + } + + return bits; +} + + +/*------------------------------------------------------------------------- + * ivas_qmetadata_entropy_encode_dir() + * + * Main function for entropy coding of the directions + *------------------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED +static int16_t ivas_qmetadata_entropy_encode_dir( + BSTR_ENC_HANDLE hMetaData, + IVAS_QDIRECTION *q_direction, + const uint16_t diffuseness_index_max_ec_frame, + const int16_t nbands, + const int16_t start_band, + const int16_t direction_bits_raw, + int16_t max_bits, + const int16_t hrmasa_flag ) +{ + uint16_t diff_idx_min; + int16_t i, j; + int16_t nblocks; + + float avg_direction_vector[3], direction_vector[3], avg_azimuth, avg_elevation; +#ifdef IVAS_FLOAT_FIXED + Word32 /*avg_direction_vector_fx[3],*/ direction_vector_fx[3] /*, avg_azimuth_fx, avg_elevation_fx*/; +#endif + int16_t avg_azimuth_alphabet, avg_elevation_alphabet; + uint16_t avg_azimuth_index, avg_elevation_index; + int16_t avg_elevation_index_projected; + int16_t avg_azimuth_index_projected; + uint16_t avg_elevation_index_initial, avg_elevation_offset; + uint16_t avg_azimuth_index_initial, avg_azimuth_offset; + int16_t elevation_bits_ec_best, azimuth_bits_ec_best; + + int16_t gr_param_elevation_best = 0, avg_elevation_index_best = 0; + uint16_t dist_elevation_indexes_best[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t gr_param_azimuth_best, avg_azimuth_index_best; + uint16_t dist_azimuth_indexes_best[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + + uint16_t idx, dist_count; + int16_t direction_bits_ec; + + uint16_t dist_elevation_indexes[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + uint16_t dist_elevation_alphabets[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + uint16_t dist_azimuth_indexes[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + uint16_t dist_azimuth_alphabets[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t all_zero_dist_elevation_indexes = 1, all_zero_dist_azimuth_indexes = 1; + int16_t gr_param_elevation, gr_size_elevation, egr_size_elevation, gr_param_azimuth, gr_size_azimuth; + int16_t egr_size_azimuth, elevation_bits_ec, azimuth_bits_ec; + + float abs_theta; + float theta_cb[MAX_NO_THETA]; + int16_t sign_th, no_th; + int16_t avg_azimuth_index_upd = 0, use_adapt_avg; + int16_t make_gain = 0; + int16_t bits_gained = 0; + nblocks = q_direction->cfg.nblocks; + + /* estimate the number of bits for entropy coding of the direction values */ + direction_bits_ec = 0; + diff_idx_min = DIRAC_DIFFUSE_LEVELS; + idx = 0; + dist_count = 0; + set_zero( avg_direction_vector, 3 ); + + for ( i = start_band; i < nbands; i++ ) + { + if ( hrmasa_flag ) + { + diff_idx_min = 0; // min( q_direction->band_data[i].energy_ratio_index_mod[0]>>1, diff_idx_min ); + } + else + { + diff_idx_min = min( q_direction->band_data[i].energy_ratio_index_mod[0], diff_idx_min ); + } + + if ( q_direction->band_data[i].energy_ratio_index_mod[0] > diffuseness_index_max_ec_frame ) + { + /* estimate the raw part */ + if ( q_direction->not_in_2D > 0 ) + { + for ( j = 0; j < nblocks; j++ ) + { + direction_bits_ec += q_direction->band_data[i].bits_sph_idx[j]; + } + } + else + { + for ( j = 0; j < nblocks; j++ ) + { + direction_bits_ec += ivas_qmetadata_encode_quasi_uniform_length( q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); + } + } + } + else + { + dist_count += nblocks; + + for ( j = 0; j < nblocks; j++ ) + { + /*compute the average direction */ +#ifdef IVAS_FLOAT_FIXED + /*==========================================flt-2-fix======================================================*/ + q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); + q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector_fx ); + + /*==========================================fix-2-flt======================================================*/ + fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[i].azimuth[j], q_direction->band_data[i].elevation[j], direction_vector ); +#endif + v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); + } + } + } + + /* quantize average elevation and azimuth angles using the best angle spacing and equatorial precision */ +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + Word16 q_dir_e = 0; + f2me_buf( avg_direction_vector, avg_direction_vector_fx, &q_dir_e, 3 ); + Scale_sig32( avg_direction_vector_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx, &avg_elevation_fx ); + + /*==========================================fix-2-flt======================================================*/ + avg_azimuth = fixedToFloat( avg_azimuth_fx, Q22 ); + avg_elevation = fixedToFloat( avg_elevation_fx, Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth, &avg_elevation ); +#endif + + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + avg_elevation_alphabet = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane */ + } + else + { + avg_elevation_alphabet = no_theta_masa[bits_direction_masa[diff_idx_min] - 3] * 2 - 1; + avg_azimuth_alphabet = no_phi_masa[bits_direction_masa[diff_idx_min] - 1][0]; /* average azimuth is quantized on the equatorial plane */ + } + + no_th = no_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + + for ( i = 0; i < no_th; i++ ) + { + theta_cb[i] = i * delta_theta_masa[bits_direction_masa[diff_idx_min] - 3]; + } + + if ( theta_cb[i - 1] > 90 ) + { + theta_cb[i - 1] = 90; + } + + if ( avg_elevation < 0 ) + { + abs_theta = -avg_elevation; + sign_th = -1; + } + else + { + abs_theta = avg_elevation; + sign_th = 1; + } + + avg_elevation_index = squant( abs_theta, &avg_elevation, theta_cb, no_th ); + + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + assert( avg_elevation >= 0 ); + } + else + { + if ( sign_th < 0 ) + { + avg_elevation_index = ( avg_elevation_alphabet >> 1 ) - avg_elevation_index; + } + else + { + avg_elevation_index += ( avg_elevation_alphabet >> 1 ); + } + avg_elevation *= sign_th; + } + + avg_azimuth_index = (uint16_t) ( quantize_phi( avg_azimuth + 180, 0, &avg_azimuth, avg_azimuth_alphabet ) ); + + /* Elevation only if not 2D */ + if ( q_direction->not_in_2D > 0 ) + { + avg_elevation_index_initial = avg_elevation_index; + elevation_bits_ec_best = MAX16B; + avg_elevation_index_best = -1; /* out of range value */ + gr_param_elevation_best = -1; /* out of range value */ + + for ( avg_elevation_offset = 0; avg_elevation_offset < q_direction->cfg.search_effort; avg_elevation_offset++ ) + { + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + avg_elevation_index = avg_elevation_index_initial + avg_elevation_offset; + } + else + { + avg_elevation_index = (uint16_t) ( avg_elevation_index_initial + ivas_qmetadata_dereorder_generic( avg_elevation_offset ) ); + } + avg_elevation_index = (uint16_t) ( ( avg_elevation_index + avg_elevation_alphabet ) % avg_elevation_alphabet ); + + all_zero_dist_elevation_indexes = 1; + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( avg_elevation_index, avg_elevation_alphabet ); + } + else + { + elevation_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic( avg_elevation_index - ( avg_elevation_alphabet >> 1 ) ), avg_elevation_alphabet ); + } + idx = 0; + for ( i = start_band; i < nbands; i++ ) + { + if ( q_direction->band_data[i].energy_ratio_index_mod[0] <= diffuseness_index_max_ec_frame ) + { + for ( j = 0; j < nblocks; j++ ) + { + /* project the quantized average elevation to the same grid as the current sample */ + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); + } + else + { + avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_index, avg_elevation_alphabet, q_direction->band_data[i].elevation_m_alphabet[j] ); + } + + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + if ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected > 0 ) + { + dist_elevation_indexes[idx] = 2 * ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected ) - 1; + } + else + { + dist_elevation_indexes[idx] = -2 * ( q_direction->band_data[i].elevation_index[j] - avg_elevation_index_projected ); + } + } + else + { + dist_elevation_indexes[idx] = ivas_qmetadata_reorder_elevation_index( q_direction->band_data[i].elevation_index[j], avg_elevation_index_projected, q_direction->band_data[i].elevation_m_alphabet[j] ); + } + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + dist_elevation_alphabets[idx] = 2 * q_direction->band_data[i].elevation_m_alphabet[j] - 1; + } + else + { + dist_elevation_alphabets[idx] = q_direction->band_data[i].elevation_m_alphabet[j]; + } + + if ( dist_elevation_indexes[idx] != 0 ) + { + all_zero_dist_elevation_indexes = 0; + } + idx++; + } + } + } + + if ( all_zero_dist_elevation_indexes ) + { + egr_size_elevation = 0; + gr_param_elevation = 4; + } + else + { + gr_param_elevation = ivas_qmetadata_get_optimal_gr_param( dist_elevation_indexes, idx, 4, &gr_size_elevation ); + egr_size_elevation = 0; + for ( i = 0; i < idx; i++ ) + { + egr_size_elevation += ivas_qmetadata_encode_extended_gr_length( dist_elevation_indexes[i], dist_elevation_alphabets[i], gr_param_elevation ); + } + } + elevation_bits_ec += ivas_qmetadata_encode_quasi_uniform_length( gr_param_elevation, 4 + 1 ) + egr_size_elevation; + + if ( elevation_bits_ec < elevation_bits_ec_best ) + { + elevation_bits_ec_best = elevation_bits_ec; + avg_elevation_index_best = avg_elevation_index; + gr_param_elevation_best = gr_param_elevation; + for ( idx = 0; idx < dist_count; idx++ ) + { + dist_elevation_indexes_best[idx] = dist_elevation_indexes[idx]; + } + } + } + + direction_bits_ec += elevation_bits_ec_best; + } + + /*Azimuth*/ + use_adapt_avg = 0; + if ( ( nbands - start_band >= 5 ) && ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( nblocks > 1 ) ) + { + use_adapt_avg = calc_var_azi( q_direction, diffuseness_index_max_ec_frame, avg_azimuth - 180, &avg_azimuth ); + avg_azimuth_index = (uint16_t) ( quantize_phi( avg_azimuth + 180, 0, &avg_azimuth, avg_azimuth_alphabet ) ); + } + avg_azimuth_index_initial = avg_azimuth_index; /* avg_azimuth_index;*/ + azimuth_bits_ec_best = MAX16B; + avg_azimuth_index_best = -1; /* out of range value */ + gr_param_azimuth_best = -1; /* out of range value */ + + for ( avg_azimuth_offset = 0; avg_azimuth_offset < q_direction->cfg.search_effort; avg_azimuth_offset++ ) + { + set_zero( avg_direction_vector, 3 ); + avg_azimuth_index = (uint16_t) ( avg_azimuth_index_initial + ivas_qmetadata_dereorder_generic( avg_azimuth_offset ) ); + avg_azimuth_index = (uint16_t) ( ( avg_azimuth_index + avg_azimuth_alphabet ) % avg_azimuth_alphabet ); + all_zero_dist_azimuth_indexes = 1; + azimuth_bits_ec = ivas_qmetadata_encode_quasi_uniform_length( ivas_qmetadata_reorder_generic( avg_azimuth_index - ( avg_azimuth_alphabet >> 1 ) ), avg_azimuth_alphabet ); + + idx = 0; + for ( i = start_band; i < nbands; i++ ) + { + if ( q_direction->band_data[i].energy_ratio_index_mod[0] <= diffuseness_index_max_ec_frame ) + { + for ( j = 0; j < nblocks; j++ ) + { + + if ( ( idx > MASA_LIMIT_IDX_AVG_AZI ) && ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( use_adapt_avg == 1 ) ) + { + avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index_upd, avg_azimuth_alphabet, q_direction->band_data[i].azimuth_m_alphabet[j] ); + } + else + { + if ( ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( use_adapt_avg == 1 ) ) + { +#ifdef IVAS_FLOAT_FIXED + /*==========================================flt-2-fix======================================================*/ + q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); + q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector_fx ); + + /*==========================================fix-2-flt======================================================*/ + fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[i].azimuth[j], q_direction->band_data[i].elevation[j], direction_vector ); +#endif + if ( idx < 4 ) + { + v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); + } + } + /* project the quantized average azimuth angle to the same grid as the current sample */ + avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, q_direction->band_data[i].azimuth_m_alphabet[j] ); + } + dist_azimuth_indexes[idx] = ivas_qmetadata_reorder_azimuth_index( ivas_qmetadata_dereorder_generic( q_direction->band_data[i].azimuth_index[j] ) + ( q_direction->band_data[i].azimuth_m_alphabet[j] >> 1 ), avg_azimuth_index_projected, q_direction->band_data[i].azimuth_m_alphabet[j] ); + dist_azimuth_alphabets[idx] = q_direction->band_data[i].azimuth_m_alphabet[j]; + + if ( dist_azimuth_indexes[idx] != 0 ) + { + all_zero_dist_azimuth_indexes = 0; + } + + if ( ( idx >= MASA_LIMIT_IDX_AVG_AZI ) && ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( use_adapt_avg == 1 ) ) + { + if ( idx % nblocks == 0 ) + { + v_multc( avg_direction_vector, 0.5f, avg_direction_vector, 3 ); + } + + /*compute the average direction per already coded subband */ +#ifdef IVAS_FLOAT_FIXED + /*==========================================flt-2-fix======================================================*/ + q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); + q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector_fx ); + + /*==========================================fix-2-flt======================================================*/ + fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[i].azimuth[j], q_direction->band_data[i].elevation[j], direction_vector ); +#endif + v_add( avg_direction_vector, direction_vector, avg_direction_vector, 3 ); +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + q_dir_e = 0; + f2me_buf( avg_direction_vector, avg_direction_vector_fx, &q_dir_e, 3 ); + Scale_sig32( avg_direction_vector_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, Q30, &avg_azimuth_fx, &avg_elevation_fx ); + + /*==========================================fix-2-flt======================================================*/ + avg_azimuth = fixedToFloat( avg_azimuth_fx, Q22 ); + avg_elevation = fixedToFloat( avg_elevation_fx, Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector, &avg_azimuth, &avg_elevation ); +#endif + avg_azimuth_index_upd = quantize_phi( avg_azimuth + 180, 0, &avg_azimuth, avg_azimuth_alphabet ); + } + idx++; + } + } + } + + if ( all_zero_dist_azimuth_indexes ) + { + egr_size_azimuth = 0; + gr_param_azimuth = 5; + } + else + { + /* estimate the ExtendedGR part for azimuth */ + gr_param_azimuth = ivas_qmetadata_get_optimal_gr_param( dist_azimuth_indexes, idx, 5, &gr_size_azimuth ); + egr_size_azimuth = 0; + for ( i = 0; i < idx; i++ ) + { + egr_size_azimuth += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes[i], dist_azimuth_alphabets[i], gr_param_azimuth ); + } + } + + azimuth_bits_ec += ivas_qmetadata_encode_quasi_uniform_length( gr_param_azimuth, 5 + 1 ) + egr_size_azimuth; + + if ( azimuth_bits_ec < azimuth_bits_ec_best ) + { + azimuth_bits_ec_best = azimuth_bits_ec; + avg_azimuth_index_best = avg_azimuth_index; + gr_param_azimuth_best = gr_param_azimuth; + + for ( idx = 0; idx < dist_count; idx++ ) + { + dist_azimuth_indexes_best[idx] = dist_azimuth_indexes[idx]; + } + } + } - av = (int16_t) ( 0.5f + sum_s( (const int16_t *) idx, len ) / (float) len ); - *p_av = av; - for ( i = 0; i < len; i++ ) + if ( ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( dist_count > 4 ) && ( gr_param_azimuth_best != 5 ) && ( nblocks > 1 ) ) { - max_ns[i] = 2 * ( max_no_symb ); - sh_idx[i] = idx[i] - av; + azimuth_bits_ec_best += 1; } - for ( i = 0; i < len; i++ ) + direction_bits_ec += azimuth_bits_ec_best; + + /*Decision raw or EC*/ + /* one bit is used to indicate whether the direction values are entropy coded or coded raw */ + if ( direction_bits_ec < direction_bits_raw ) /* entropy coding is better */ { - if ( sh_idx[i] < 0 ) + + /* encode the raw part first */ + for ( i = start_band; i < nbands; i++ ) { - sh_idx[i] = -2 * sh_idx[i]; + if ( q_direction->band_data[i].energy_ratio_index_mod[0] > diffuseness_index_max_ec_frame ) + { + if ( q_direction->not_in_2D > 0 ) + { + for ( j = 0; j < nblocks; j++ ) + { + push_next_indice( hMetaData, q_direction->band_data[i].spherical_index[j], q_direction->band_data[i].bits_sph_idx[j] ); + } + } + else + { + for ( j = 0; j < nblocks; j++ ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, q_direction->band_data[i].azimuth_index[j], q_direction->band_data[i].azimuth_m_alphabet[j] ); + } + } + } } - else if ( sh_idx[i] > 0 ) + + if ( nbands > 1 && direction_bits_ec - max_bits > 0 && direction_bits_ec - max_bits < nblocks * nbands ) { - sh_idx[i] = sh_idx[i] * 2 - 1; + make_gain = 1; } - else + + if ( q_direction->not_in_2D > 0 ) { - sh_idx[i] = 0; - } - mr_idx[i] = (uint16_t) sh_idx[i]; - } + /* encode the ExtendedGR part for elevation */ + if ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, avg_elevation_index_best, avg_elevation_alphabet ); + } + else + { + ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic( avg_elevation_index_best - ( avg_elevation_alphabet >> 1 ) ), avg_elevation_alphabet ); + } - nbits = GR_bits_new( mr_idx, max_ns, len, *GR_ord, adapt_GR, GR_ord ); + ivas_qmetadata_encode_quasi_uniform( hMetaData, gr_param_elevation_best, 4 + 1 ); - return nbits; -} + if ( gr_param_elevation_best != 4 ) /* not all zero */ + { + for ( idx = 0; idx < dist_count; idx++ ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_elevation_indexes_best[idx], dist_elevation_alphabets[idx], gr_param_elevation_best ); + } + } + } + /* encode the ExtendedGR part for azimuth */ + ivas_qmetadata_encode_quasi_uniform( hMetaData, ivas_qmetadata_reorder_generic( avg_azimuth_index_best - ( avg_azimuth_alphabet >> 1 ) ), avg_azimuth_alphabet ); -/*------------------------------------------------------------------------- - * ivas_qmetadata_encode_quasi_uniform_length() - * - *------------------------------------------------------------------------*/ + ivas_qmetadata_encode_quasi_uniform( hMetaData, gr_param_azimuth_best, 5 + 1 ); -static int16_t ivas_qmetadata_encode_quasi_uniform_length( - const uint16_t value, - const uint16_t alphabet_size ) -{ - int16_t bits; - uint16_t tresh; + if ( gr_param_azimuth_best != 5 ) /* not all zero */ + { + for ( idx = 0; idx < min( nblocks, dist_count ); idx++ ) + { + if ( make_gain == 1 && bits_gained < direction_bits_ec - max_bits && dist_azimuth_alphabets[idx] > 40 ) + { + if ( dist_azimuth_indexes_best[idx] > 1 ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - + ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + else if ( dist_azimuth_indexes_best[idx] == 1 ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - + ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + else + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + } + else + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + } - bits = 30 - norm_l( alphabet_size ); /* bits = floor(log2(alphabet_size)) */ - tresh = ( 1U << ( bits + 1 ) ) - alphabet_size; + if ( dist_count > nblocks ) + { + if ( ( q_direction->cfg.mc_ls_setup != MC_LS_SETUP_INVALID ) && ( nblocks > 1 ) ) + { + push_next_indice( hMetaData, use_adapt_avg, 1 ); + } + for ( idx = nblocks; idx < dist_count; idx++ ) + { + if ( make_gain == 1 && bits_gained < direction_bits_ec - max_bits && dist_azimuth_alphabets[idx] > 40 ) + { + if ( dist_azimuth_indexes_best[idx] > 1 ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - + ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 2, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + else if ( dist_azimuth_indexes_best[idx] == 1 ) + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + bits_gained += ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ) - + ivas_qmetadata_encode_extended_gr_length( dist_azimuth_indexes_best[idx] - 1, dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + else + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + } + else + { + ivas_qmetadata_encode_extended_gr( hMetaData, dist_azimuth_indexes_best[idx], dist_azimuth_alphabets[idx], gr_param_azimuth_best ); + } + } + } + } - if ( value >= tresh ) + direction_bits_ec -= bits_gained; + } + else { - bits++; + direction_bits_ec = -1; } - return bits; + return direction_bits_ec; } - - -/*------------------------------------------------------------------------- - * ivas_qmetadata_entropy_encode_dir() - * - * Main function for entropy coding of the directions - *------------------------------------------------------------------------*/ - +#else static int16_t ivas_qmetadata_entropy_encode_dir( BSTR_ENC_HANDLE hMetaData, IVAS_QDIRECTION *q_direction, @@ -2435,6 +3994,7 @@ static int16_t ivas_qmetadata_entropy_encode_dir( return direction_bits_ec; } +#endif /*------------------------------------------------------------------------- @@ -3296,31 +4856,128 @@ static int16_t encode_directions_subband( &q_direction->band_data[j].elevation_index[k], &q_direction->band_data[j].azimuth_index[k], q_direction->cfg.mc_ls_setup ); } - if ( allowed_bits > 0 ) - { - nbits = write_fixed_rate_direction( hMetaData, q_direction, j, no_subframes ); - } - } - } + if ( allowed_bits > 0 ) + { + nbits = write_fixed_rate_direction( hMetaData, q_direction, j, no_subframes ); + } + } + } + } + else + { + set_f( q_direction->band_data[j].elevation, 0.0f, no_subframes ); + set_f( q_direction->band_data[j].azimuth, 0.0f, no_subframes ); + } + + *p_diff = diff; + + return nbits; +} + + +/*-------------------------------------------------------------------* + * calc_var_azi() + * + * + *-------------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED +static int16_t calc_var_azi( + const IVAS_QDIRECTION *q_direction, + const int16_t diffuseness_index_max_ec_frame, + const float avg_azimuth, + float *avg_azimuth_out ) +{ + float var_band, dif; + float avg_direction_vector_band[3], avg_azimuth_band[24], direction_vector[3]; + float avg_elevation; +#ifdef IVAS_FLOAT_FIXED + Word32 /* avg_direction_vector_band_fx[3], avg_azimuth_band_fx[24],*/ direction_vector_fx[3]; + // Word32 avg_elevation_fx; +#endif + int16_t i, j, idx; + + idx = 0; + set_zero( avg_azimuth_band, 24 ); + + for ( i = 0; i < q_direction->cfg.nbands; i++ ) + { + set_zero( avg_direction_vector_band, 3 ); + if ( q_direction->band_data[i].energy_ratio_index_mod[0] <= diffuseness_index_max_ec_frame ) + { + for ( j = 0; j < q_direction->cfg.nblocks; j++ ) + { + /*compute the average direction */ +#ifdef IVAS_FLOAT_FIXED + /*==========================================flt-2-fix======================================================*/ + q_direction->band_data[i].azimuth_fx[j] = floatToFixed( q_direction->band_data[i].azimuth[j], Q22 ); + q_direction->band_data[i].elevation_fx[j] = floatToFixed( q_direction->band_data[i].elevation[j], Q22 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[i].azimuth_fx[j], q_direction->band_data[i].elevation_fx[j], direction_vector_fx ); + + /*==========================================fix-2-flt======================================================*/ + fixedToFloat_arrL( direction_vector_fx, direction_vector, Q30, 3 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_azimuth_elevation_to_direction_vector( q_direction->band_data[i].azimuth[j], q_direction->band_data[i].elevation[j], direction_vector ); +#endif + v_add( avg_direction_vector_band, direction_vector, avg_direction_vector_band, 3 ); + } +#ifdef IVAS_FLOAT_FIXED_ + /*==========================================flt-2-fix======================================================*/ + Word16 q_dir_e = 0; + f2me_buf( avg_direction_vector_band, avg_direction_vector_band_fx, &q_dir_e, 3 ); + Scale_sig32( avg_direction_vector_band_fx, 3, -1 ); + /*==========================================flt-2-fix======================================================*/ + + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_band_fx, Q30, &avg_azimuth_band_fx[idx], &avg_elevation_fx ); + + /*==========================================fix-2-flt======================================================*/ + avg_azimuth_band[idx] = fixedToFloat( avg_azimuth_band_fx[idx], Q22 ); + // avg_elevation = fixedToFloat( avg_elevation_fx, Q22 ); + /*==========================================fix-2-flt======================================================*/ +#else + ivas_qmetadata_direction_vector_to_azimuth_elevation( avg_direction_vector_band, &avg_azimuth_band[idx], &avg_elevation ); +#endif + idx++; + } + } + + var_band = 0.0f; + + for ( i = 0; i < idx; i++ ) + { + dif = ( avg_azimuth_band[idx] - avg_azimuth ); + if ( dif < 0 ) + { + dif = -dif; + } + if ( dif > 180 ) + { + dif = 360 - dif; + } + + var_band += dif * dif; + } + + if ( idx > 0 ) + { + var_band = var_band / idx; + } + + if ( var_band <= VAR_AZI_THRESH ) + { + *avg_azimuth_out = avg_azimuth; + return 0; } else { - set_f( q_direction->band_data[j].elevation, 0.0f, no_subframes ); - set_f( q_direction->band_data[j].azimuth, 0.0f, no_subframes ); + *avg_azimuth_out = avg_azimuth_band[0]; + return 1; } - - *p_diff = diff; - - return nbits; } - - -/*-------------------------------------------------------------------* - * calc_var_azi() - * - * - *-------------------------------------------------------------------*/ - +#else static int16_t calc_var_azi( const IVAS_QDIRECTION *q_direction, const int16_t diffuseness_index_max_ec_frame, @@ -3384,6 +5041,7 @@ static int16_t calc_var_azi( return 1; } } +#endif /*-------------------------------------------------------------------* @@ -4246,54 +5904,260 @@ static int16_t encode_spread_coherence_1sf( no_idx16 = (int16_t) round_f( ( nbits_fr1 / 16.0f + 0.5f ) ); } - assert( no_idx16 <= 4 ); + assert( no_idx16 <= 4 ); + + k = nbits_fr1; + for ( i = 0; i < no_idx16 - 1; i++ ) + { + k -= 16; + push_next_indice( hMasaMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */ + } + push_next_indice( hMasaMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k ); + } + } + else + { + /* write flag */ + nbits = 1; + + /* write flag*/ + push_next_indice( hMasaMetaData, 1, 1 ); + + /* write GR_ord */ + push_next_indice( hMasaMetaData, GR_ord, 1 ); + nbits += 1; + + /* write the min */ + bits_GR = hMasaMetaData->nb_bits_tot; + ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv, 0 ); + nbits += hMasaMetaData->nb_bits_tot - bits_GR; + + /* write GR data */ + for ( j = 0; j < idx_shift; j++ ) + { + bits_GR = hMasaMetaData->nb_bits_tot; + ivas_qmetadata_encode_extended_gr( hMasaMetaData, mr_idx_sp_coh[j], no_cv_shift[j], GR_ord ); + nbits += hMasaMetaData->nb_bits_tot - bits_GR; + } + } + + return nbits; +} + + +/*-------------------------------------------------------------------* + * encode_surround_coherence() + * + * encoding surround coherence + *-------------------------------------------------------------------*/ + +/*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +static int16_t encode_surround_coherence( + IVAS_QMETADATA *hQMetaData, /* i : quantized metadata */ + BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ +) +{ + int16_t i, j, k; + int16_t idx_ER, idx16; + int16_t nbits, nbits_fr; + uint16_t idx_sur_coh[MASA_MAXIMUM_CODING_SUBBANDS]; + uint16_t mr_idx_sur_coh[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t GR_ord, bits_GR; + uint64_t idx, idx1; + int16_t no_idx16; + int16_t no_cv[MASA_MAXIMUM_CODING_SUBBANDS]; + float error_ratio_surr; +#ifdef IVAS_FLOAT_FIXED + Word32 error_ratio_surr_fx; +#endif + IVAS_QDIRECTION *q_direction; + int16_t half_coding_subbands, nbits_fr1, coding_subbands; + int16_t all_coherence_zero; + uint16_t idx_sur_coh_shift[MASA_MAXIMUM_CODING_SUBBANDS]; + uint8_t idx_shift; + int16_t max_val = 0, nbits_max; + int16_t no_cv_shift[MASA_MAXIMUM_CODING_SUBBANDS], min_idx; + + coding_subbands = hQMetaData->q_direction[0].cfg.nbands; + all_coherence_zero = hQMetaData->all_coherence_zero; + q_direction = &( hQMetaData->q_direction[0] ); + nbits = 0; + + if ( all_coherence_zero == 1 ) + { + nbits = 0; + } + else + { + GR_ord = 1; + k = 0; + idx_shift = 0; + for ( j = 0; j < coding_subbands; j++ ) + { + if ( hQMetaData->no_directions == 2 ) + { + k += hQMetaData->twoDirBands[j]; + idx16 = max( k - 1, 0 ); + error_ratio_surr = 1.0f - q_direction[0].band_data[j].energy_ratio[0] - q_direction[1].band_data[idx16].energy_ratio[0] * hQMetaData->twoDirBands[j]; + } + else + { + error_ratio_surr = 1.0f - q_direction[0].band_data[j].energy_ratio[0]; + } + + if ( error_ratio_surr <= 0 ) + { + error_ratio_surr = 0; + idx_sur_coh[j] = 0; + no_cv[j] = 1; + hQMetaData->surcoh_band_data[j].surround_coherence[0] = 0; /* sur_coherence_cb_masa[idx_cb_sur_coh_masa[DIRAC_DIFFUSE_LEVELS - 1] * MASA_MAX_NO_CV_SUR_COH]; */ + } + else + { +#ifdef IVAS_FLOAT_FIXED + /*=====================================flt-2-fix============================================*/ + error_ratio_surr_fx = floatToFixed( error_ratio_surr, Q30 ); + /*=====================================flt-2-fix============================================*/ + + idx_ER = masa_sq_fx( error_ratio_surr_fx, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); +#else + idx_ER = masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); +#endif + + idx_sur_coh[j] = squant_int( hQMetaData->surcoh_band_data[j].surround_coherence[0], &hQMetaData->surcoh_band_data[j].surround_coherence[0], + &sur_coherence_cb_masa[idx_cb_sur_coh_masa[idx_ER] * MASA_MAX_NO_CV_SUR_COH], idx_cb_sur_coh_masa[idx_ER] + 2 ); + + no_cv[j] = idx_cb_sur_coh_masa[idx_ER] + 2; + no_cv_shift[idx_shift] = no_cv[j]; + idx_sur_coh_shift[idx_shift++] = idx_sur_coh[j]; + } + } + + if ( sum_s( no_cv, coding_subbands ) == coding_subbands ) + { + return 0; + } + + nbits_max = 0; + if ( coding_subbands > MASA_LIMIT_NO_BANDS_SUR_COH ) + { + j = maximum_s( (int16_t *) idx_sur_coh, coding_subbands, &max_val ); + for ( j = 0; j < coding_subbands; j++ ) + { + if ( no_cv[j] > max_val + 1 ) + { + no_cv[j] = max_val + 1; + } + } + nbits_max = MASA_MAX_NO_CV_SUR_COH - max_val; /* encoded with GR0 as max_no_vals - no_vals*/ + } + + nbits = coherence_coding_length( idx_sur_coh_shift, idx_shift, coding_subbands, no_cv, + mr_idx_sur_coh, no_cv_shift, &min_idx, &GR_ord, &nbits_fr, &nbits_fr1 ); + half_coding_subbands = coding_subbands / 2; + idx1 = 0; + + /* should check how to encode the average - check distribution */ + if ( nbits_fr + nbits_fr1 + nbits_max < nbits ) + { + /* write flag*/ + push_next_indice( hMetaData, 0, 1 ); + + /* create combined index */ + nbits = nbits_fr + nbits_fr1 + 1; + if ( coding_subbands > MASA_LIMIT_NO_BANDS_SUR_COH ) + { + /* write max value*/ + bits_GR = hMetaData->nb_bits_tot; + ivas_qmetadata_encode_extended_gr( hMetaData, MASA_MAX_NO_CV_SUR_COH - max_val - 1, MASA_MAX_NO_CV_SUR_COH, 0 ); + nbits += hMetaData->nb_bits_tot - bits_GR; + } + + if ( nbits_fr1 > 0 ) + { + idx = create_combined_index( idx_sur_coh, half_coding_subbands, no_cv ); + idx1 = create_combined_index( &idx_sur_coh[half_coding_subbands], half_coding_subbands, &no_cv[half_coding_subbands] ); + } + else + { + idx = create_combined_index( idx_sur_coh, coding_subbands, no_cv ); + } + + if ( nbits_fr % 16 == 0 ) + { + no_idx16 = nbits_fr / 16; + } + else + { + no_idx16 = (int16_t) round_f( ( nbits_fr / 16.0f + 0.5f ) ); + } + + /* write combined index */ + k = nbits_fr; + for ( i = 0; i < no_idx16 - 1; i++ ) + { + k -= 16; + push_next_indice( hMetaData, ( ( idx >> k ) & 65535 ), 16 ); /* 16 bits */ + } + + push_next_indice( hMetaData, ( idx & ( ( 1 << k ) - 1 ) ), k ); + + if ( nbits_fr1 > 0 ) + { + if ( nbits_fr1 % 16 == 0 ) + { + no_idx16 = nbits_fr1 / 16; + } + else + { + no_idx16 = (int16_t) round_f( ( nbits_fr1 / 16.0f + 0.5f ) ); + } + + assert( no_idx16 <= 4 ); + + k = nbits_fr1; + for ( i = 0; i < no_idx16 - 1; i++ ) + { + k -= 16; + push_next_indice( hMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */ + } + + push_next_indice( hMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k ); + } + } + else + { + /* write flag */ + nbits = 1; + + /* write flag*/ + push_next_indice( hMetaData, 1, 1 ); + + /* write GR_ord */ + push_next_indice( hMetaData, GR_ord, 1 ); + nbits += 1; + + /* write the min */ + bits_GR = hMetaData->nb_bits_tot; + ivas_qmetadata_encode_extended_gr( hMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH, 0 ); + nbits += hMetaData->nb_bits_tot - bits_GR; - k = nbits_fr1; - for ( i = 0; i < no_idx16 - 1; i++ ) + /* write GR data */ + for ( j = 0; j < idx_shift; j++ ) { - k -= 16; - push_next_indice( hMasaMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */ - } - push_next_indice( hMasaMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k ); - } - } - else - { - /* write flag */ - nbits = 1; - - /* write flag*/ - push_next_indice( hMasaMetaData, 1, 1 ); - - /* write GR_ord */ - push_next_indice( hMasaMetaData, GR_ord, 1 ); - nbits += 1; + bits_GR = hMetaData->nb_bits_tot; - /* write the min */ - bits_GR = hMasaMetaData->nb_bits_tot; - ivas_qmetadata_encode_extended_gr( hMasaMetaData, min_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv, 0 ); - nbits += hMasaMetaData->nb_bits_tot - bits_GR; + ivas_qmetadata_encode_extended_gr( hMetaData, mr_idx_sur_coh[j], no_cv_shift[j], GR_ord ); - /* write GR data */ - for ( j = 0; j < idx_shift; j++ ) - { - bits_GR = hMasaMetaData->nb_bits_tot; - ivas_qmetadata_encode_extended_gr( hMasaMetaData, mr_idx_sp_coh[j], no_cv_shift[j], GR_ord ); - nbits += hMasaMetaData->nb_bits_tot - bits_GR; + nbits += hMetaData->nb_bits_tot - bits_GR; + } } } return nbits; } - - -/*-------------------------------------------------------------------* - * encode_surround_coherence() - * - * encoding surround coherence - *-------------------------------------------------------------------*/ - -/*! r: number of bits written */ +#else static int16_t encode_surround_coherence( IVAS_QMETADATA *hQMetaData, /* i : quantized metadata */ BSTR_ENC_HANDLE hMetaData /* i/o: metadata bitstream handle */ @@ -4487,6 +6351,7 @@ static int16_t encode_surround_coherence( return nbits; } +#endif static int16_t encode_surround_coherence_hr( @@ -4931,6 +6796,214 @@ static int16_t ivas_qmetadata_quantize_coherence_hr_512( *-------------------------------------------------------------------*/ /*! r: number of bits written */ +#ifdef IVAS_FLOAT_FIXED +static int16_t ivas_qmetadata_quantize_coherence( + IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata */ + const int16_t idx_d, /* i : current direction index */ + const int16_t all_coherence_zero, /* i : all coherence is zero - flag */ + BSTR_ENC_HANDLE hMetaData, /* i : metadata handle */ + const int16_t write_flag, /* i : flag to actually write the data or not */ + int16_t *indice_coherence, + const int16_t hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ +) +{ + int16_t j, k; + float dct_coh[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; +#ifdef IVAS_FLOAT_FIXED + Word32 dct_coh_fx[MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; +#endif + uint16_t idx_dct[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t coding_subbands; + int16_t nbits; + uint64_t no_cb; + int16_t MASA_grouping[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t nbits1; + int16_t coding_subbands_0, d; + int16_t two_dir_band[MASA_MAXIMUM_CODING_SUBBANDS]; + int16_t no_cb_vec[MASA_MAXIMUM_CODING_SUBBANDS]; + IVAS_QDIRECTION *q_direction; + int16_t min_index; + min_index = 0; + q_direction = &( hQMetaData->q_direction[idx_d] ); + coding_subbands = q_direction->cfg.nbands; + nbits = 0; + + if ( all_coherence_zero == 1 ) + { + return nbits; + } + + if ( hQMetaData->q_direction[idx_d].cfg.nblocks == 1 ) + { + nbits = encode_spread_coherence_1sf( hQMetaData, idx_d, hMetaData, hrmasa_flag ); + + return nbits; + } + else + { + k = 0; + no_cb = 1; + coding_subbands_0 = hQMetaData->q_direction[0].cfg.nbands; + if ( coding_subbands_0 <= 5 ) + { + for ( j = 0; j < 5; j++ ) + { + MASA_grouping[j] = j; + } + } + else + { + if ( coding_subbands_0 <= 8 ) + { + mvs2s( MASA_grouping_8_to_5, MASA_grouping, 8 ); + } + else if ( coding_subbands_0 <= 12 ) + { + mvs2s( MASA_grouping_12_to_5, MASA_grouping, 12 ); + } + else if ( coding_subbands_0 <= 18 ) + { + mvs2s( MASA_grouping_18_to_5, MASA_grouping, 18 ); + } + else + { + if ( coding_subbands_0 <= 24 ) + { + mvs2s( MASA_grouping_24_to_5, MASA_grouping, 24 ); + } + } + } + + if ( coding_subbands < coding_subbands_0 ) + { + d = 0; + for ( j = 0; j < coding_subbands_0; j++ ) + { + if ( hQMetaData->twoDirBands[j] == 1 ) + { + two_dir_band[d++] = j; + } + } + } + + for ( j = 0; j < coding_subbands; j++ ) + { + /* DCT transform */ + dct4_transform( hQMetaData->q_direction[idx_d].coherence_band_data[j].spread_coherence, dct_coh[j] ); + + if ( hrmasa_flag ) + { + minimum_s( (int16_t *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); + no_cb_vec[j] = len_cb_dct0_masa[min_index >> 1]; + } + else + { + no_cb_vec[j] = len_cb_dct0_masa[q_direction->band_data[j].energy_ratio_index[0]]; + } + + if ( write_flag ) + { + /* quantize first DCT parameter */ + dct_coh[j][0] = quantize_DCT_0_coh( dct_coh[j][0], j, coherence_cb0_masa, MASA_DELTA_AZI_DCT0, MASA_NO_CV_COH, q_direction, &idx_dct[k], &no_cb_vec[j], hrmasa_flag ); + } + + if ( coding_subbands < coding_subbands_0 ) + { + idx_dct[k + coding_subbands] = squant( dct_coh[j][1], &dct_coh[j][1], &coherence_cb1_masa[MASA_grouping[two_dir_band[j]] * MASA_NO_CV_COH1], MASA_NO_CV_COH1 ); + } + else + { + idx_dct[k + coding_subbands] = squant( dct_coh[j][1], &dct_coh[j][1], &coherence_cb1_masa[MASA_grouping[j] * MASA_NO_CV_COH1], MASA_NO_CV_COH1 ); + } + k++; + + dct_coh[j][2] = 0.0f; + dct_coh[j][3] = 0.0f; + } + + nbits1 = 0; + if ( sum_s( no_cb_vec, coding_subbands ) > MASA_COH_LIMIT_2IDX ) + { + /* make two indxes */ + no_cb = 1; + + for ( j = 0; j < coding_subbands / 2; j++ ) + { + no_cb *= no_cb_vec[j]; + } + + nbits = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + no_cb = 1; + + for ( j = coding_subbands / 2; j < coding_subbands; j++ ) + { + no_cb *= no_cb_vec[j]; + } + nbits1 = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + } + else + { + no_cb = 1; + + for ( j = 0; j < coding_subbands; j++ ) + { + no_cb *= no_cb_vec[j]; + } + + nbits = (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + } + + if ( write_flag ) + { + for ( j = 0; j < coding_subbands; j++ ) + { + /* inverse DCT transform */ + +#ifdef IVAS_FLOAT_FIXED + + /*================================flt-2-fix========================================*/ + floatToFixed_arrL( dct_coh[j], dct_coh_fx[j], Q21, MAX_PARAM_SPATIAL_SUBFRAMES ); // Q21 is used in decoder hence chosed otherwise function can work with variable Q + /*================================fix-2-flt========================================*/ + + invdct4_transform_fx( dct_coh_fx[j], q_direction->coherence_band_data[j].spread_coherence, Q21 ); +#else + invdct4_transform( dct_coh[j], q_direction->coherence_band_data[j].spread_coherence ); +#endif + } + + nbits = encode_coherence_indexesDCT0( idx_dct, coding_subbands, no_cb_vec, hMetaData, *indice_coherence, nbits, nbits1 ); + } + else + { + /* write dummy data now and save the position */ + *indice_coherence = hMetaData->nb_ind_tot; + k = nbits; + while ( k > 0 ) + { + push_next_indice( hMetaData, 0, min( 16, k ) ); + k -= 16; + } + + if ( nbits1 > 0 ) + { + k = nbits1; + while ( k > 0 ) + { + push_next_indice( hMetaData, 0, min( 16, k ) ); + k -= 16; + } + } + nbits += nbits1; + set_s( no_cb_vec, MASA_NO_CV_COH1, coding_subbands ); + nbits += encode_coherence_indexesDCT1( &idx_dct[coding_subbands], coding_subbands, hMetaData ); + + return nbits; + } + } + + return nbits; +} +#else static int16_t ivas_qmetadata_quantize_coherence( IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata */ const int16_t idx_d, /* i : current direction index */ @@ -5124,6 +7197,7 @@ static int16_t ivas_qmetadata_quantize_coherence( return nbits; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 3763c8761..f8fa5aea4 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -42,6 +42,9 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #include "prot_fx1.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*------------------------------------------------------------------- @@ -406,7 +409,11 @@ void stereo_dft_cng_side_gain( /* Use coarse band partitioning in inactive frames */ /* Rescale bands to the coarser partitioning taking the band size into account */ mvs2s( hStereoDft->band_limits, band_limits_full, STEREO_DFT_BAND_MAX + 1 ); +#ifndef IVAS_FLOAT_FIXED hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->hConfig->band_res, min( STEREO_DFT_N_32k_ENC, NFFT_inner ), ENC ); +#else + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, s_min( STEREO_DFT_N_32k_ENC, NFFT_inner ), ENC ); +#endif if ( nbands_full > hStereoDft->nbands + 1 ) { for ( b = 0; b < hStereoDft->nbands; b++ ) diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index e25bc7d5e..2d48fa86d 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -281,7 +281,11 @@ ivas_error stereo_dft_enc_create( hStereoDft_loc->hConfig->force_mono_transmission = 0; +#ifndef IVAS_FLOAT_FIXED stereo_dft_config( hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS ); +#else + stereo_dft_config_fx( hStereoDft_loc->hConfig, IVAS_24k4, &tmpS, &tmpS ); +#endif stereo_dft_enc_open( hStereoDft_loc, input_Fs, max_bwidth ); @@ -416,8 +420,13 @@ static void stereo_dft_enc_open( /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ NFFT_inner = STEREO_DFT_N_MAX_ENC * inner_frame_tbl[max_bwidth] / L_FRAME48k; +#ifndef IVAS_FLOAT_FIXED hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); hStereoDft->nbands_dmx = stereo_dft_band_config( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); +#else + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); + hStereoDft->nbands_dmx = stereo_dft_band_config_fx( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); +#endif /*Set configuration*/ set_s( hStereoDft->band_res, hStereoDft->hConfig->band_res, STEREO_DFT_ENC_DFT_NB ); @@ -911,8 +920,13 @@ void stereo_dft_enc_update( /* update band limits in case of rate switching assuming max_bwidth as BWD output not yet know here */ NFFT_inner = STEREO_DFT_N_MAX_ENC * inner_frame_tbl[max_bwidth] / L_FRAME48k; +#ifndef IVAS_FLOAT_FIXED hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); hStereoDft->nbands_dmx = stereo_dft_band_config( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); +#else + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); + hStereoDft->nbands_dmx = stereo_dft_band_config_fx( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); +#endif /*Compute main parameters*/ hStereoDft->gipd_band_max = dft_band_ipd[1][3]; @@ -2155,7 +2169,11 @@ void stereo_dft_enc_write_BS( } /* set number of bands according to bandwidth after BWD */ +#ifndef IVAS_FLOAT_FIXED hStereoDft->nbands = stereo_dft_band_config( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, ENC ); +#else + hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->band_res[k_offset], NFFT_inner, ENC ); +#endif if ( core_brate == FRAME_NO_DATA ) { diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 3c4b324c4..73081c98a 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -39,6 +39,9 @@ #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*-------------------------------------------------------------------* * sync_tcx_mode() @@ -186,11 +189,19 @@ void stereo_mdct_core_enc( if ( hCPE->hCoreCoder[0]->igf ) { +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, STEREO_FORMAT, IVAS_CPE_MDCT, hCPE->element_brate, hCPE->hCoreCoder[0]->bwidth, hCPE->hCoreCoder[0]->igf, hCPE->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid, 0 ); stereo_mdct_init_igf_start_band( &( hCPE->hStereoMdct->stbParamsTCX20 ), 1.0f, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); stereo_mdct_init_igf_start_band( &( hCPE->hStereoMdct->stbParamsTCX10 ), 0.5f, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); stereo_mdct_init_igf_start_band( &( hCPE->hStereoMdct->stbParamsTCX20afterACELP ), 1.25f, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); +#else + initMdctStereoEncData_fx( hCPE->hStereoMdct, STEREO_FORMAT, IVAS_CPE_MDCT, hCPE->element_brate, hCPE->hCoreCoder[0]->bwidth, hCPE->hCoreCoder[0]->igf, hCPE->hCoreCoder[0]->hIGFEnc->igfData.igfInfo.grid, 0 ); + + stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20 ), 16384 /* 1.0f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); + stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX10 ), 8192 /* 0.5f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); + stereo_mdct_init_igf_start_band_fx( &( hCPE->hStereoMdct->stbParamsTCX20afterACELP ), 20480 /* 1.25f in Q14 */, hCPE->hCoreCoder[0]->bwidth, hCPE->element_brate ); +#endif } else { @@ -415,7 +426,11 @@ void stereo_mdct_core_enc( nAvailBits -= meta_bits; nAvailBits -= SMDCT_NBBITS_SPLIT_RATIO; +#ifndef IVAS_FLOAT_FIXED splitAvailableBits( nAvailBits, hStereoMdct->split_ratio, hStereoMdct->isSBAStereoMode, &sts[0]->bits_frame_channel, &sts[1]->bits_frame_channel ); +#else + splitAvailableBits_fx( nAvailBits, hStereoMdct->split_ratio, hStereoMdct->isSBAStereoMode, &sts[0]->bits_frame_channel, &sts[1]->bits_frame_channel ); +#endif sts[0]->bits_frame_channel += sts[0]->core * SMDCT_MINIMUM_ARITH_BITS; sts[1]->bits_frame_channel += sts[1]->core * SMDCT_MINIMUM_ARITH_BITS; diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 9ea4b937a..62206ccc3 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -1032,6 +1032,7 @@ static void MsStereoDecision( * initialize encoder mdct stereo structure *-----------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void initMdctStereoEncData( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ @@ -1090,7 +1091,7 @@ void initMdctStereoEncData( return; } -#ifdef IVAS_FLOAT_FIXED +#else void initMdctStereoEncData_fx( STEREO_MDCT_ENC_DATA *hStereoMdct, /* i/o: mdct stereo parameters structure */ const IVAS_FORMAT ivas_format, /* i : IVAS format */ @@ -1124,7 +1125,8 @@ void initMdctStereoEncData_fx( hStereoMdct->split_ratio = SMDCT_EQUAL_RATIO_RANGE; - set16_fx( hStereoMdct->global_ild, shr( SMDCT_ILD_RANGE, 1 ), 2 ); + move16(); + set16_fx( hStereoMdct->global_ild, SMDCT_ILD_RANGE >> 1, 2 ); IF( mem_init ) { @@ -1132,7 +1134,9 @@ void initMdctStereoEncData_fx( hStereoMdct->hDft_ana = NULL; } - IF( !( element_mode == IVAS_CPE_MDCT && element_brate <= MAX_MDCT_ITD_BRATE && ivas_format == STEREO_FORMAT ) ) + test(); + test(); + IF( !( EQ_16( element_mode, IVAS_CPE_MDCT ) && LE_32( element_brate, MAX_MDCT_ITD_BRATE ) && EQ_32( ivas_format, STEREO_FORMAT ) ) ) { IF( hStereoMdct->hDft_ana != NULL ) { @@ -1150,6 +1154,8 @@ void initMdctStereoEncData_fx( return; } #endif + + /*-----------------------------------------------------------------------* * initMdctItdHandling() * diff --git a/lib_enc/ivas_stereo_switching_enc.c b/lib_enc/ivas_stereo_switching_enc.c index 87e692f3b..03cf7bfe2 100644 --- a/lib_enc/ivas_stereo_switching_enc.c +++ b/lib_enc/ivas_stereo_switching_enc.c @@ -531,7 +531,11 @@ ivas_error stereo_memory_enc( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } +#ifndef IVAS_FLOAT_FIXED initMdctStereoEncData( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, hCPE->hCoreCoder[0]->max_bwidth, 0, NULL, 1 ); +#else + initMdctStereoEncData_fx( hCPE->hStereoMdct, ivas_format, hCPE->element_mode, hCPE->element_brate, hCPE->hCoreCoder[0]->max_bwidth, 0, NULL, 1 ); +#endif hCPE->hStereoMdct->isSBAStereoMode = ( ivas_format == SBA_FORMAT && nchan_transport == 2 ); diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index b2eaa4800..6de215c49 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1365,6 +1365,7 @@ static ivas_error configureEncoder_fx( * *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error IVAS_ENC_GetDelay( const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ int16_t *delay /* o : encoder delay */ @@ -1390,6 +1391,35 @@ ivas_error IVAS_ENC_GetDelay( return IVAS_ERR_OK; } +#else +ivas_error IVAS_ENC_GetDelay( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + Word16 *delay /* o : encoder delay */ +) +{ + ENCODER_CONFIG_HANDLE hEncoderConfig; + + hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig; + + IF( !hIvasEnc->isConfigured ) + { + return IVAS_ERR_NOT_CONFIGURED; + } + + IF( delay == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + *delay = NS2SA( hEncoderConfig->input_Fs, get_delay_fx( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL ) ); + move16(); + + *delay = imult1616( *delay, hEncoderConfig->nchan_inp ); + move16(); + + return IVAS_ERR_OK; +} +#endif /*---------------------------------------------------------------------* diff --git a/lib_enc/lib_enc.h b/lib_enc/lib_enc.h index 82aaf5a3c..1f7907ae8 100644 --- a/lib_enc/lib_enc.h +++ b/lib_enc/lib_enc.h @@ -299,10 +299,17 @@ ivas_error IVAS_ENC_SetChannelAwareConfig( /* Getter functions - retrieve information from an encoder through a handle */ /*! r: encoder error code */ +#ifndef IVAS_FLOAT_FIXED ivas_error IVAS_ENC_GetDelay( const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ int16_t *delay /* o : encoder delay */ ); +#else +ivas_error IVAS_ENC_GetDelay( + const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */ + Word16 *delay /* o : encoder delay */ +); +#endif /*! r: encoder error code */ ivas_error IVAS_ENC_GetNumInChannels( -- GitLab From b033717ac0657366ca62297ce1e78f740a57c3d0 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 11:53:22 +0530 Subject: [PATCH 47/63] Clang formatting changes --- lib_dec/TonalComponentDetection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/TonalComponentDetection.c b/lib_dec/TonalComponentDetection.c index 66333630f..12908a001 100644 --- a/lib_dec/TonalComponentDetection.c +++ b/lib_dec/TonalComponentDetection.c @@ -886,4 +886,4 @@ static void findTonalComponents( return; } -#endif \ No newline at end of file +#endif -- GitLab From 43020a644a28fad85a78e0e8a9a068c58b344038 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 12:11:55 +0530 Subject: [PATCH 48/63] BASOP addition and instrumentation changes --- lib_com/ivas_cnst.h | 4 + lib_com/ivas_prot.h | 2 +- lib_dec/ivas_binRenderer_internal.c | 324 ++++--- lib_dec/ivas_core_dec.c | 585 ++++++++---- lib_dec/ivas_corecoder_dec_reconfig.c | 95 +- lib_dec/ivas_cpe_dec_fx.c | 467 ++++++---- lib_dec/ivas_dec.c | 4 +- lib_dec/ivas_decision_matrix_dec.c | 33 +- lib_dec/ivas_dirac_dec.c | 1035 +++++++++++++++------ lib_dec/ivas_dirac_output_synthesis_cov.c | 494 ++++++---- 10 files changed, 2087 insertions(+), 956 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 33a48c136..06e5e34b8 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1603,6 +1603,10 @@ typedef enum *----------------------------------------------------------------------------------*/ #define BINAURAL_MAXBANDS 60 /* Max number of bands */ +#ifdef IVAS_FLOAT_FIXED +#define BINAURAL_MAXBANDS_Q25 2013265920 /* Max number of bands in Q25 */ +#define ONE_BY_48000_Q31 44740 +#endif #define BINAURAL_CONVBANDS 50 /* Bands upto which convolution is performed */ #define BINAURAL_NTAPS 3 #define BINAURAL_NTAPS_SBA BINAURAL_NTAPS diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 65770f002..fda8732d9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -6656,7 +6656,7 @@ void ivas_binRenderer( void ivas_binRenderer_fx( BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ - const int16_t numTimeSlots, /* i : number of time slots to render */ + const Word16 numTimeSlots, /* i : number of time slots to render */ Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index a00fa71ee..0f92acf2d 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -154,11 +154,21 @@ static void ivas_binRenderer_filterModule_fx( { Word64 outRealLeft_fx = 0, outRealRight_fx = 0, outImagLeft_fx = 0, outImagRight_fx = 0; Word64 W_sub1 = 0, W_add1 = 0, W_sub2 = 0, W_add2 = 0; + move64(); + move64(); + move64(); + move64(); + move64(); + move64(); + move64(); + move64(); FOR( tapIdx = hBinRenderer->hBinRenConvModule->numTapsArray[bandIdx] - 1; tapIdx > 0; tapIdx-- ) { filterStatesLeftRealPtr_fx[tapIdx] = filterStatesLeftRealPtr_fx[tapIdx - 1]; + move32(); filterStatesLeftImagPtr_fx[tapIdx] = filterStatesLeftImagPtr_fx[tapIdx - 1]; + move32(); W_sub1 = W_sub( W_mult0_32_32( filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[tapIdx], filterTapsLeftImagPtr_fx[tapIdx] ) ); // Q29 + Q_filterStates[tapIdx - 1] @@ -169,12 +179,13 @@ static void ivas_binRenderer_filterModule_fx( W_add2 = W_add( W_mult0_32_32( filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightImagPtr_fx[tapIdx] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] ) ); // Q29 + Q_filterStates[tapIdx - 1] - outRealLeft_fx = W_shr( outRealLeft_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); - outImagLeft_fx = W_shr( outImagLeft_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); - outRealRight_fx = W_shr( outRealRight_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); - outImagRight_fx = W_shr( outImagRight_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); + outRealLeft_fx = W_shr( outRealLeft_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); + outImagLeft_fx = W_shr( outImagLeft_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); + outRealRight_fx = W_shr( outRealRight_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); + outImagRight_fx = W_shr( outImagRight_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); Q_filterStates[tapIdx] = Q_filterStates[tapIdx - 1]; + move16(); /* Left Real and Imag */ outRealLeft_fx = W_add( outRealLeft_fx, W_sub1 ); // Q29 + Q_filterStates[1] @@ -186,31 +197,38 @@ static void ivas_binRenderer_filterModule_fx( } filterStatesLeftRealPtr_fx[0] = CLDFB_real[chIdx][k][bandIdx]; + move32(); filterStatesLeftImagPtr_fx[0] = CLDFB_imag[chIdx][k][bandIdx]; + move32(); Q_filterStates[0] = Q_curr; + move16(); /* Left Real and Imag */ // Q29 + Q_curr out_Conv_CLDFB_real[0][k][bandIdx] = W_add( out_Conv_CLDFB_real[0][k][bandIdx], - W_add( W_shr( outRealLeft_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outRealLeft_fx, sub( Q_filterStates[1], Q_curr ) ), W_sub( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsLeftRealPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsLeftImagPtr_fx[0] ) ) ) ); // Q29 + move64(); out_Conv_CLDFB_imag[0][k][bandIdx] = W_add( out_Conv_CLDFB_imag[0][k][bandIdx], - W_add( W_shr( outImagLeft_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outImagLeft_fx, sub( Q_filterStates[1], Q_curr ) ), W_add( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsLeftImagPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsLeftRealPtr_fx[0] ) ) ) ); // Q29 + move64(); /* Right Real and Imag */ out_Conv_CLDFB_real[1][k][bandIdx] = W_add( out_Conv_CLDFB_real[1][k][bandIdx], - W_add( W_shr( outRealRight_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outRealRight_fx, sub( Q_filterStates[1], Q_curr ) ), W_sub( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsRightRealPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsRightImagPtr_fx[0] ) ) ) ); // Q29 + move64(); out_Conv_CLDFB_imag[1][k][bandIdx] = W_add( out_Conv_CLDFB_imag[1][k][bandIdx], - W_add( W_shr( outImagRight_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outImagRight_fx, sub( Q_filterStates[1], Q_curr ) ), W_add( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsRightImagPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsRightRealPtr_fx[0] ) ) ) ); // Q29 + move64(); } } } @@ -788,38 +806,46 @@ void ivas_init_binaural_hrtf_fx( HrtfFastConv->leftHRIRImag_HOA3_fx = NULL; HrtfFastConv->rightHRIRReal_HOA3_fx = NULL; HrtfFastConv->rightHRIRImag_HOA3_fx = NULL; - HrtfFastConv->FASTCONV_HOA3_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_HOA3_latency_s_fx = 0; + move32(); HrtfFastConv->leftHRIRReal_fx = NULL; HrtfFastConv->leftHRIRImag_fx = NULL; HrtfFastConv->rightHRIRReal_fx = NULL; HrtfFastConv->rightHRIRImag_fx = NULL; - HrtfFastConv->FASTCONV_HRIR_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_HRIR_latency_s_fx = 0; + move32(); HrtfFastConv->leftBRIRReal_fx = NULL; HrtfFastConv->leftBRIRImag_fx = NULL; HrtfFastConv->rightBRIRReal_fx = NULL; HrtfFastConv->rightBRIRImag_fx = NULL; - HrtfFastConv->FASTCONV_BRIR_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_BRIR_latency_s_fx = 0; + move32(); HrtfFastConv->leftHRIRReal_HOA2_fx = NULL; HrtfFastConv->leftHRIRImag_HOA2_fx = NULL; HrtfFastConv->rightHRIRReal_HOA2_fx = NULL; HrtfFastConv->rightHRIRImag_HOA2_fx = NULL; - HrtfFastConv->FASTCONV_HOA2_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_HOA2_latency_s_fx = 0; + move32(); HrtfFastConv->leftHRIRReal_FOA_fx = NULL; HrtfFastConv->leftHRIRImag_FOA_fx = NULL; HrtfFastConv->rightHRIRReal_FOA_fx = NULL; HrtfFastConv->rightHRIRImag_FOA_fx = NULL; - HrtfFastConv->FASTCONV_FOA_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_FOA_latency_s_fx = 0; + move32(); - HrtfFastConv->allocate_init_flag = 0x00; + HrtfFastConv->allocate_init_flag = 0; + move16(); FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { - HrtfFastConv->fastconvReverberationTimes_fx[i] = 0x00; - HrtfFastConv->fastconvReverberationEneCorrections_fx[i] = 0x00; + HrtfFastConv->fastconvReverberationTimes_fx[i] = 0; + move32(); + HrtfFastConv->fastconvReverberationEneCorrections_fx[i] = 0; + move32(); } return; @@ -968,135 +994,155 @@ ivas_error ivas_allocate_binaural_hrtf_fx( const Word16 allocate_init_flag /* i : Memory allocation flag */ ) { - IF( input_config == IVAS_AUDIO_CONFIG_HOA3 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_HOA3_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA3_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA3_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA3_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA3" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA3" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA3" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA3" ); } } } - IF( input_config == IVAS_AUDIO_CONFIG_HOA2 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_HOA2_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA2_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA2_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA2_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA2" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA2" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA2" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA2" ); } } } - IF( input_config == IVAS_AUDIO_CONFIG_FOA || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_FOA ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_FOA ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_FOA_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_FOA_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_FOA_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_FOA_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_FOA" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_FOA" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_FOA" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_FOA" ); } } } - IF( renderer_type == RENDERER_BINAURAL_FASTCONV || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + test(); + IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag" ); } } } - IF( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + test(); + IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftBRIRReal_fx != NULL ) && ( HrtfFastConv->leftBRIRImag_fx != NULL ) && ( HrtfFastConv->rightBRIRReal_fx != NULL ) && ( HrtfFastConv->rightBRIRImag_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRImag" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRImag" ); } @@ -1269,6 +1315,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( Word16 i, j; ivas_error error; + test(); IF( hHrtfFastConv != NULL && *hHrtfFastConv != NULL ) { /* Tables already loaded from file */ @@ -1286,36 +1333,44 @@ static ivas_error ivas_binaural_hrtf_open_fx( ivas_init_binaural_hrtf_fx( HrtfFastConv ); - IF( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { HrtfFastConv->FASTCONV_HRIR_latency_s_fx = FASTCONV_HRIR_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) ) { HrtfFastConv->FASTCONV_HOA2_latency_s_fx = FASTCONV_HOA2_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { HrtfFastConv->FASTCONV_HOA3_latency_s_fx = FASTCONV_HOA3_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_FOA ) + if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) ) { HrtfFastConv->FASTCONV_FOA_latency_s_fx = FASTCONV_FOA_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { HrtfFastConv->FASTCONV_BRIR_latency_s_fx = FASTCONV_BRIR_latency_s_fx; + move32(); } HrtfFastConv->allocate_init_flag = 1; + move16(); - IF( ( error = ivas_allocate_binaural_hrtf_fx( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_allocate_binaural_hrtf_fx( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ), IVAS_ERR_OK ) ) { return error; } FOR( i = 0; i < BINAURAL_CONVBANDS; i++ ) { - IF( renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { FOR( j = 0; j < HRTF_LS_CHANNELS; j++ ) { @@ -1325,7 +1380,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightHRIRImag_fx[i][j] = rightHRIRImag_fx[i][j]; } } - ELSE IF( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + ELSE IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { FOR( j = 0; j < HRTF_LS_CHANNELS; j++ ) { @@ -1335,7 +1390,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightBRIRImag_fx[i][j] = rightBRIRImag_fx[i][j]; } } - IF( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { FOR( j = 0; j < HOA3_CHANNELS; j++ ) { @@ -1345,7 +1400,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightHRIRImag_HOA3_fx[i][j] = rightHRIRImag_HOA3_fx[i][j]; } } - IF( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) ) { FOR( j = 0; j < HOA2_CHANNELS; j++ ) { @@ -1355,7 +1410,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightHRIRImag_HOA2_fx[i][j] = rightHRIRImag_HOA2_fx[i][j]; } } - IF( input_config == IVAS_AUDIO_CONFIG_FOA ) + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) ) { FOR( j = 0; j < FOA_CHANNELS; j++ ) { @@ -1616,24 +1671,22 @@ static void ivas_binaural_obtain_DMX( *-------------------------------------------------------------------------*/ static void ivas_binaural_obtain_DMX_fx( - const int16_t numTimeSlots, + const Word16 numTimeSlots, BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle */ Word32 RealBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals */ Word32 ImagBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals */ Word32 realDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 imagDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] ) { - int16_t chIdx, bandIdx, k; + Word16 chIdx, bandIdx, k; - IF( hBinRenderer->ivas_format == MC_FORMAT ) + test(); + IF( EQ_32( hBinRenderer->ivas_format, MC_FORMAT ) ) { /* Obtain the downmix */ - // float P_in[CLDFB_NO_CHANNELS_MAX]; Word32 P_in_fx[CLDFB_NO_CHANNELS_MAX]; - // float P_out, factEQ; Word32 P_out_fx, factEQ_fx; - int16_t chOutIdx; - // float temp1, temp2; + Word16 chOutIdx; Word32 temp1_fx, temp2_fx; FOR( k = 0; k < numTimeSlots; k++ ) @@ -1652,22 +1705,21 @@ static void ivas_binaural_obtain_DMX_fx( FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { Word32 dmxConst = hBinRenderer->hReverb->dmxmtx_fx[chOutIdx][chIdx]; + move32(); FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { FOR( k = 0; k < numTimeSlots; k++ ) { - // temp1 = RealBuffer[chIdx][k][bandIdx] * dmxConst; - // temp2 = ImagBuffer[chIdx][k][bandIdx] * dmxConst; - // realDMX[chOutIdx][k][bandIdx] += temp1; - // imagDMX[chOutIdx][k][bandIdx] += temp2; temp1_fx = Mpy_32_32( RealBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in temp2_fx = Mpy_32_32( ImagBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in realDMX[chOutIdx][k][bandIdx] = L_add( realDMX[chOutIdx][k][bandIdx], temp1_fx ); // Q_in + move32(); imagDMX[chOutIdx][k][bandIdx] = L_add( imagDMX[chOutIdx][k][bandIdx], temp2_fx ); // Q_in + move32(); - // P_in[bandIdx] += temp1 * temp1 + temp2 * temp2; P_in_fx[bandIdx] = L_add( P_in_fx[bandIdx], L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in + move32(); } } } @@ -1678,45 +1730,43 @@ static void ivas_binaural_obtain_DMX_fx( FOR( k = 0; k < numTimeSlots; k++ ) { temp1_fx = realDMX[chOutIdx][k][bandIdx]; + move32(); temp2_fx = imagDMX[chOutIdx][k][bandIdx]; - // P_out += temp1 * temp1 + temp2 * temp2; + move32(); P_out_fx = L_add( P_out_fx, L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in } - // if ( ( factEQ <= 1e-20f ) || ( P_in[bandIdx] <= 1e-20f ) || ( P_out <= 1e-20f ) ) - IF( LE_32( P_in_fx[bandIdx], 0 ) || LE_32( P_out_fx, 0 ) ) + test(); + IF( ( P_in_fx[bandIdx] <= 0 ) || ( P_out_fx <= 0 ) ) { - // factEQ = 1.0f; factEQ_fx = 0x40000000; + move32(); } ELSE { - // factEQ = sqrtf( P_in[bandIdx] / ( P_out + 1e-20f ) ); Word16 div = divide3232( P_in_fx[bandIdx], P_out_fx ); Word16 exp = norm_l( div ); factEQ_fx = Sqrt32( L_shl( div, Q16 ), &exp ); factEQ_fx = L_shl( factEQ_fx, exp - 1 ); // Q30 } - IF( LE_32( factEQ_fx, 0 ) ) + if ( factEQ_fx <= 0 ) { factEQ_fx = 0x40000000; + move32(); } - // factEQ = max( min( factEQ, 2.0f ), 0.5f ); factEQ_fx = L_max( L_min( factEQ_fx, 0x7fffffff ), 0x20000000 ); // Q30 FOR( k = 0; k < numTimeSlots; k++ ) { - // realDMX[chOutIdx][k][bandIdx] *= factEQ; - // imagDMX[chOutIdx][k][bandIdx] *= factEQ; realDMX[chOutIdx][k][bandIdx] = Mpy_32_32( realDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1 + move32(); imagDMX[chOutIdx][k][bandIdx] = Mpy_32_32( imagDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1 + move32(); } } } } - ELSE IF( hBinRenderer->ivas_format == SBA_FORMAT || hBinRenderer->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( hBinRenderer->ivas_format, SBA_FORMAT ) || EQ_32( hBinRenderer->ivas_format, MASA_FORMAT ) ) { - // float *outRealLeftPtr, *outImagLeftPtr, *outRealRightPtr, *outImagRightPtr; - // float *inRealPtr, *inImagPtr; Word32 *outRealLeftPtr_fx, *outImagLeftPtr_fx, *outRealRightPtr_fx, *outImagRightPtr_fx; Word32 *inRealPtr_fx, *inImagPtr_fx; @@ -1734,7 +1784,6 @@ static void ivas_binaural_obtain_DMX_fx( FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - // float foa_const = hBinRenderer->hReverb->foa_enc[chIdx][1]; Word32 foa_const_fx = L_shl( hBinRenderer->hReverb->foa_enc_fx[chIdx][1], 1 ); // Q30 inRealPtr_fx = (Word32 *) &( RealBuffer[chIdx][k][0] ); @@ -1742,15 +1791,15 @@ static void ivas_binaural_obtain_DMX_fx( FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - // outRealLeftPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f + foa_const ); - // outImagLeftPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f + foa_const ); outRealLeftPtr_fx[bandIdx] = L_add( outRealLeftPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); outImagLeftPtr_fx[bandIdx] = L_add( outImagLeftPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); - // outRealRightPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f - foa_const ); - // outImagRightPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f - foa_const ); outRealRightPtr_fx[bandIdx] = L_add( outRealRightPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); outImagRightPtr_fx[bandIdx] = L_add( outImagRightPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); } } } @@ -1775,6 +1824,7 @@ ivas_error ivas_binRenderer_open_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * prepare library opening @@ -1789,9 +1839,12 @@ ivas_error ivas_binRenderer_open_fx( /* Define of head rotation has to be done in binRendeder in CLDFB*/ hBinRenderer->rotInCldfb = 0; - IF( st_ivas->ivas_format == MC_FORMAT || st_ivas->ivas_format == SBA_FORMAT ) + move16(); + test(); + if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { hBinRenderer->rotInCldfb = 1; + move16(); } @@ -1800,45 +1853,55 @@ ivas_error ivas_binRenderer_open_fx( IF( st_ivas->hIntSetup.is_loudspeaker_setup ) { hBinRenderer->ivas_format = MC_FORMAT; + move32(); } ELSE { hBinRenderer->ivas_format = SBA_FORMAT; + move32(); } - hBinRenderer->max_band = (int16_t) ( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + hBinRenderer->max_band = extract_l( Mpy_32_32( Mpy_32_32( BINAURAL_MAXBANDS_Q25, L_shl( st_ivas->hDecoderConfig->output_Fs, Q6 ) ), ONE_BY_48000_Q31 ) ); convBand = hBinRenderer->max_band; + move16(); hBinRenderer->timeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; /* Corresponds to 5 msec sound to motion latency */ + move16(); - IF( convBand > BINAURAL_CONVBANDS ) + IF( GT_16( convBand, BINAURAL_CONVBANDS ) ) { hBinRenderer->conv_band = BINAURAL_CONVBANDS; + move16(); } ELSE { hBinRenderer->conv_band = convBand; + move16(); } /*LFE rendering switched off by default*/ hBinRenderer->render_lfe = 0; + move16(); - IF( st_ivas->ivas_format != ISM_FORMAT && st_ivas->hIntSetup.is_loudspeaker_setup ) + test(); + if ( NE_32( st_ivas->ivas_format, ISM_FORMAT ) && st_ivas->hIntSetup.is_loudspeaker_setup ) { hBinRenderer->render_lfe = 1; + move16(); } /* Load HRTF tables */ - IF( ( error = ivas_binaural_hrtf_open_fx( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binaural_hrtf_open_fx( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) ) { IVAS_OUTPUT_SETUP out_setup; /* Allocate memories and buffers needed for convolutional module in CICP19 */ - IF( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, IVAS_AUDIO_CONFIG_7_1_4, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, IVAS_AUDIO_CONFIG_7_1_4, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) ) { return error; } @@ -1847,42 +1910,47 @@ ivas_error ivas_binRenderer_open_fx( IF( st_ivas->hoa_dec_mtx == NULL ) { - IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ), IVAS_ERR_OK ) ) { return error; } } hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; + move32(); } ELSE { /* Allocate memories and buffers needed for convolutional module */ - IF( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { - IF( hBinRenderer->ivas_format == MC_FORMAT ) + IF( EQ_32( hBinRenderer->ivas_format, MC_FORMAT ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s_fx; + move32(); } ELSE { - IF( hBinRenderer->nInChannels == 16 ) + IF( EQ_16( hBinRenderer->nInChannels, 16 ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s_fx; //(int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s * 1000000000.f ); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s_fx; + move32(); } - ELSE IF( hBinRenderer->nInChannels == 9 ) + ELSE IF( EQ_16( hBinRenderer->nInChannels, 9 ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s_fx; + move32(); } - ELSE IF( hBinRenderer->nInChannels == 4 ) + ELSE IF( EQ_16( hBinRenderer->nInChannels, 4 ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s_fx; + move32(); } ELSE { @@ -1893,14 +1961,16 @@ ivas_error ivas_binRenderer_open_fx( ELSE { /* same value for MC or HOA both use MC BRIR*/ - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; + move32(); } } /* Allocate memories needed for reverb module */ - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_binaural_reverb_open_fastconv_fx( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binaural_reverb_open_fastconv_fx( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) ) { return error; } @@ -1911,6 +1981,7 @@ ivas_error ivas_binRenderer_open_fx( FOR( k = 0; k < hBinRenderer->nInChannels; k++ ) { hBinRenderer->hReverb->dmxmtx_fx[chIdx][k] = dmxmtx_table_fx[chIdx][k]; + move32(); } } } @@ -1923,17 +1994,19 @@ ivas_error ivas_binRenderer_open_fx( IF( hBinRenderer->hReverb != NULL ) { + test(); + test(); IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) { FOR( k = 0; k < 11; k++ ) { - ivas_dirac_dec_get_response_fx( (Word16) L_shr_r( ls_azimuth_CICP19_fx[k], 22 ), (Word16) L_shr_r( ls_elevation_CICP19_fx[k], 22 ), hBinRenderer->hReverb->foa_enc_fx[k], 1, Q29 ); + ivas_dirac_dec_get_response_fx( extract_l( L_shr_r( ls_azimuth_CICP19_fx[k], 22 ) ), extract_l( L_shr_r( ls_elevation_CICP19_fx[k], 22 ) ), hBinRenderer->hReverb->foa_enc_fx[k], 1, Q29 ); // Q29: hBinRenderer->hReverb->foa_enc_fx[k] } } - ELSE IF( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } @@ -2302,6 +2375,7 @@ void ivas_binRenderer_close_fx( BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */ ) { + test(); IF( hBinRenderer == NULL || *hBinRenderer == NULL ) { return; @@ -2426,12 +2500,14 @@ void ivas_binaural_hrtf_close( { Word16 allocate_init_flag; + test(); IF( hHrtfFastConv == NULL || *hHrtfFastConv == NULL ) { return; } allocate_init_flag = ( *hHrtfFastConv )->allocate_init_flag; + move16(); ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag ); ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag ); @@ -2566,22 +2642,35 @@ void ivas_binaural_add_LFE_fx( IF( st_ivas->hBinRenderer != NULL ) { render_lfe = st_ivas->hBinRenderer->render_lfe; + move16(); } ELSE { render_lfe = TRUE; + move16(); } IF( render_lfe ) { - IF( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { gain_fx = GAIN_LFE_FX; + move16(); } ELSE { - gain_fx = ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe_fx : GAIN_LFE_FX; + test(); + IF( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) + { + gain_fx = st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe_fx; + move16(); + } + ELSE + { + gain_fx = GAIN_LFE_FX; + move16(); + } } FOR( idx_lfe = 0; idx_lfe < st_ivas->hIntSetup.num_lfe; idx_lfe++ ) { @@ -2590,8 +2679,11 @@ void ivas_binaural_add_LFE_fx( FOR( int idx = 0; idx < output_frame; idx++ ) { input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] = L_shl_sat( input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx], 1 ); // saturating to keep same q + move32(); output_fx[0][idx] = L_add_sat( output_fx[0][idx], input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] ); + move32(); output_fx[1][idx] = L_add_sat( output_fx[1][idx], input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] ); + move32(); } } } @@ -2610,7 +2702,7 @@ void ivas_binaural_add_LFE_fx( void ivas_binRenderer_fx( BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ - const int16_t numTimeSlots, /* i : number of time slots to render */ + const Word16 numTimeSlots, /* i : number of time slots to render */ Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ @@ -2638,20 +2730,24 @@ void ivas_binRenderer_fx( } /* Head rotation in HOA3 or CICPx */ + test(); + test(); IF( hCombinedOrientationData != NULL && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] && hBinRenderer->rotInCldfb ) { IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) { /* Rotation in SHD (HOA3) */ - IF( hCombinedOrientationData->shd_rot_max_order == -1 ) + IF( EQ_16( hCombinedOrientationData->shd_rot_max_order, -1 ) ) { rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, 3 ); *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 ) + move16(); } ELSE IF( hCombinedOrientationData->shd_rot_max_order > 0 ) { rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, hCombinedOrientationData->shd_rot_max_order ); *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 ) + move16(); } } ELSE @@ -2663,7 +2759,8 @@ void ivas_binRenderer_fx( } /* HOA decoding to CICP19 if needed*/ - IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nInChannels != 16 ) + test(); + IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && NE_16( hBinRenderer->nInChannels, 16 ) ) { ivas_sba2mc_cldfb_fixed( *( hBinRenderer->hInputSetup ), RealBuffer_fx, ImagBuffer_fx, hBinRenderer->nInChannels, hBinRenderer->conv_band, numTimeSlots, hBinRenderer->hoa_dec_mtx ); @@ -2677,7 +2774,9 @@ void ivas_binRenderer_fx( FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { Cldfb_RealBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_RealBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29 + move32(); Cldfb_ImagBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_ImagBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29 + move32(); } } } @@ -2708,11 +2807,12 @@ void ivas_binRenderer_fx( { FOR( j = 0; j < numTimeSlots; j++ ) { - FOR( k = 0; k < hBinRenderer->hReverb->numBins; k++ ) { reverbRe_fx[i][j][k] = L_shl( reverbRe_fx[i][j][k], 1 ); //*Q_in + move32(); reverbIm_fx[i][j][k] = L_shl( reverbIm_fx[i][j][k], 1 ); //*Q_in + move32(); } } } diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 0bccf0c82..2f9af21ab 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -58,45 +58,48 @@ ivas_error ivas_core_dec( SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ - const int16_t n_channels, /* i : number of channels to be decoded */ + const Word16 n_channels, /* i : number of channels to be decoded */ Word32 *output_32_fx[], /* o : output synthesis signal */ Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ) { - int16_t i, n, output_frame; + Word16 i, n, output_frame; Decoder_State **sts, *st; STEREO_ICBWE_DEC_HANDLE hStereoICBWE; STEREO_TD_DEC_DATA_HANDLE hStereoTD; - int16_t sharpFlag[CPE_CHANNELS]; + Word16 sharpFlag[CPE_CHANNELS]; Word16 tmp_buffer_fx[L_FRAME48k]; set_s( tmp_buffer_fx, 0, L_FRAME48k ); - Word16 tmp16 = 0, tmp16_2, j; + Word16 tmp16, tmp16_2, j; + tmp16 = 0; + move16(); Word16 Q_white_exc; Q_white_exc = 0; + move16(); - int16_t tmps, incr; + Word16 tmps, incr; Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; - int16_t core_switching_flag[CPE_CHANNELS]; + Word16 core_switching_flag[CPE_CHANNELS]; Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; - int16_t unbits[CPE_CHANNELS]; - int16_t sid_bw[CPE_CHANNELS]; + Word16 unbits[CPE_CHANNELS]; + Word16 sid_bw[CPE_CHANNELS]; FRAME_MODE frameMode[CPE_CHANNELS]; - int16_t tdm_LRTD_flag; - int32_t element_brate, output_Fs; - int32_t last_element_brate; - int16_t use_cldfb_for_dft; + Word16 tdm_LRTD_flag; + Word32 element_brate, output_Fs; + Word32 last_element_brate; + Word16 use_cldfb_for_dft; Word32 *p_output_mem_fx; - int16_t flag_sec_CNA; - int16_t read_sid_info; - int16_t last_element_mode; - int16_t nchan_out; + Word16 flag_sec_CNA; + Word16 read_sid_info; + Word16 last_element_mode; + Word16 nchan_out; Word32 *save_hb_synth_32_fx; ivas_error error; Word32 L_tmp; @@ -121,6 +124,7 @@ ivas_error ivas_core_dec( #endif error = IVAS_ERR_OK; + move32(); push_wmops( "ivas_core_dec" ); /*------------------------------------------------------------------* @@ -128,24 +132,33 @@ ivas_error ivas_core_dec( *-----------------------------------------------------------------*/ use_cldfb_for_dft = 0; + move16(); tdm_LRTD_flag = -1; + move16(); read_sid_info = 1; /* read SID by default */ + move16(); IF( hSCE != NULL ) { sts = hSCE->hCoreCoder; hStereoICBWE = NULL; element_brate = hSCE->element_brate; + move32(); last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ + move32(); last_element_mode = IVAS_SCE; + move16(); hStereoTD = NULL; p_output_mem_fx = NULL; nchan_out = 1; - IF( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) + move16(); + test(); + IF( st_ivas != NULL && EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { - IF( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) + if ( NE_16( st_ivas->hISMDTX.sce_id_dtx, hSCE->sce_id ) ) { read_sid_info = 0; + move16(); } } } @@ -153,22 +166,37 @@ ivas_error ivas_core_dec( { sts = hCPE->hCoreCoder; element_brate = hCPE->element_brate; + move32(); last_element_brate = hCPE->last_element_brate; + move32(); last_element_mode = hCPE->last_element_mode; + move16(); hStereoICBWE = hCPE->hStereoICBWE; hStereoTD = hCPE->hStereoTD; p_output_mem_fx = hCPE->output_mem_fx[1]; nchan_out = hCPE->nchan_out; + move16(); - IF( hCPE->hStereoTD != NULL ) + if ( hCPE->hStereoTD != NULL ) { tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; + move16(); } - IF( sts[0]->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) { - use_cldfb_for_dft = ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ? 1 : 0; + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) + { + use_cldfb_for_dft = 1; + move16(); + } + ELSE + { + use_cldfb_for_dft = 0; + move16(); + } } } @@ -179,15 +207,18 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); st->cldfbAna->Q_cldfb_state = Q10; + move16(); } IF( st->cldfbSynHB ) { scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); } } output_Fs = sts[0]->output_Fs; + move32(); output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); FOR( n = 0; n < n_channels; n++ ) @@ -199,37 +230,56 @@ ivas_error ivas_core_dec( *-----------------------------------------------------------------*/ frameMode[n] = FRAMEMODE_NORMAL; + move32(); st->rate_switching_reset = 0; - + move16(); st->mdct_sw = MODE1; - + move16(); sid_bw[n] = -1; + move16(); core_switching_flag[n] = 0; + move16(); sharpFlag[n] = 0; + move16(); unbits[n] = 0; + move16(); st->GSC_IVAS_mode = 0; + move16(); st->element_brate = element_brate; - + move32(); st->use_partial_copy = 0; + move16(); st->rf_flag = 0; + move16(); st->rf_frame_type = RF_NO_DATA; + move16(); - IF( st->bfi == 1 ) + IF( EQ_16( st->bfi, 1 ) ) { frameMode[n] = FRAMEMODE_MISSING; + move32(); st->coder_type = st->last_coder_type; + move16(); } ELSE { - IF( !( st->element_mode == IVAS_CPE_TD && n == 1 ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ { st->coder_type = INACTIVE; + move16(); } st->extl = -1; + move16(); st->flagGuidedAcelp = 0; + move16(); } - IF( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) + test(); + test(); + test(); + test(); + IF( !st->bfi && st->prev_bfi && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) { conceal_eof_gain32 = L_shl( L_deposit_l( st->hTcxDec->conceal_eof_gain ), 1 ); @@ -257,40 +307,47 @@ ivas_error ivas_core_dec( * Decision matrix (selection of technologies) *-----------------------------------------------------------------*/ - IF( st->bfi != 1 ) + test(); + test(); + IF( NE_16( st->bfi, 1 ) ) { ivas_decision_matrix_dec_fx( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); synchonize_channels_mdct_sid_fx( sts, n ); - IF( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ + IF( NE_16( st->bfi, 1 ) ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ { - st->sr_core = st->L_frame * FRAMES_PER_SEC; + st->sr_core = L_mult0( st->L_frame, FRAMES_PER_SEC ); st->fscale_old = st->fscale; + move16(); st->fscale = sr2fscale( st->sr_core ); } ELSE { frameMode[n] = FRAMEMODE_MISSING; + move32(); } } - ELSE IF( st->element_mode >= IVAS_SCE && st->prev_bfi == 1 && st->last_con_tcx == 1 ) + ELSE IF( GE_16( st->element_mode, IVAS_SCE ) && EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_con_tcx, 1 ) ) { st->core = TCX_20_CORE; + move16(); } } /* n_channels loop */ /* MDCT stereo -> DFT stereo switching */ - IF( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { Word16 ovl, fade_len; - IF( sts[0]->L_frame != sts[0]->last_L_frame ) + IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) { - Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - sts[0]->hHQ_core->Q_old_wtda_LB ); + Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); - Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sts[0]->hHQ_core->Q_old_wtda_LB - Q11 ); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); } - IF( sts[0]->L_frame != L_FRAME16k ) + IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) { ovl = mult( sts[0]->L_frame, 5120 ); /*STEREO_DFT32MS_OVL_16k/L_FRAME16k = 5/32 = 5120 (Q15)*/ L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); @@ -300,12 +357,17 @@ ivas_error ivas_core_dec( } } + test(); IF( hCPE != NULL && hCPE->hStereoCng != NULL ) { hCPE->hStereoCng->flag_cna_fade = 0; + move16(); } - IF( sba_dirac_stereo_flag && hSCE && sts[0]->total_brate <= SID_2k40 && sts[0]->cng_type == FD_CNG ) + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) ) { save_hb_synth_32_fx = hSCE->save_hb_synth_fx; } @@ -318,7 +380,8 @@ ivas_error ivas_core_dec( * Decode SID for MDCT-Stereo DTX mode *-----------------------------------------------------------------*/ - IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) + test(); + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) && EQ_32( sts[0]->total_brate, SID_2k40 ) ) { IF( sts[0]->cng_sba_flag ) { @@ -334,7 +397,9 @@ ivas_error ivas_core_dec( * Sanity check in combined format coding *-----------------------------------------------------------------*/ - IF( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) { ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); } @@ -351,28 +416,32 @@ ivas_error ivas_core_dec( * Initialization *-----------------------------------------------------------------*/ - IF( st->bfi == 1 ) + IF( EQ_16( st->bfi, 1 ) ) { - st->nbLostCmpt++; + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); } ELSE { - IF( st->prev_bfi == 1 ) + IF( EQ_16( st->prev_bfi, 1 ) ) { st->prev_nbLostCmpt = st->nbLostCmpt; + move16(); } ELSE { st->prev_nbLostCmpt = 0; + move16(); } st->nbLostCmpt = 0; + move16(); } st->enablePlcWaveadjust = 0; + move16(); - IF( n == 1 ) + IF( EQ_16( n, 1 ) ) { - sts[1]->BER_detect |= sts[0]->BER_detect; + sts[1]->BER_detect = s_or( sts[1]->BER_detect, sts[0]->BER_detect ); } /*---------------------------------------------------------------------* @@ -384,19 +453,26 @@ ivas_error ivas_core_dec( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - Word16 Q_olapBufferSynth = 15, Q_olapBufferSynth2 = 15; /*Initializing with max values to avoid warnings*/ + Word16 Q_olapBufferSynth, Q_olapBufferSynth2; + + Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ + Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ + move16(); + move16(); Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); - IF( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) { return error; } flag_sec_CNA = -1; + move16(); IF( hCPE != NULL ) { flag_sec_CNA = sts[1]->flag_cna; + move16(); } /*---------------------------------------------------------------------* @@ -405,7 +481,7 @@ ivas_error ivas_core_dec( * HQ core decoding *---------------------------------------------------------------------*/ - IF( st->core == ACELP_CORE ) + IF( EQ_16( st->core, ACELP_CORE ) ) { /* ACELP core decoder */ Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; @@ -420,127 +496,184 @@ ivas_error ivas_core_dec( save_hb_synth_16_fx = NULL; } - /* float2fix, to be removed */ IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbBPF ) { scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); st->cldfbBPF->Q_cldfb_state = Q10; + move16(); } IF( st->cldfbSyn ) { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); st->cldfbSyn->Q_cldfb_state = Q10; + move16(); } IF( st->hFdCngDec != NULL ) { Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); st->hFdCngDec->msNoiseEst_exp = 27; + move16(); - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] - 1 ) - 3 ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); } - IF( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) + IF( hCPE == NULL ) { - return error; + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, NULL, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE->hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } } - /* fix2float, to be removed */ - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - st->Q_syn2 ); - Scale_sig( output_16_fx[n], L_FRAME48k, -st->Q_syn2 ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); + Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ st->cldfbAna->Q_cldfb_state = Q10; + move16(); } IF( st->cldfbBPF ) { scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); st->cldfbBPF->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbSyn ) { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSyn->Q_cldfb_state = Q11; + move16(); } st->prev_Q_syn = st->Q_syn; + move16(); if ( save_hb_synth_32_fx ) { Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); hSCE->q_save_hb_synth_fx = Q11; + move16(); } - Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -1 ) ); + Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q11, negate( Q1 ) ) ); } Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); + test(); + test(); + test(); IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - Word16 Qsyn_temp = st->Q_syn; + Word16 Qsyn_temp; + STEREO_CNG_DEC_HANDLE hStereoCng; + IVAS_FORMAT ivas_format; + + Qsyn_temp = st->Q_syn; + move16(); st->Q_syn = 0; + move16(); st->prev_Q_syn = st->Q_syn; + move16(); st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - + move16(); st->mem_error = st->hBPF->pst_mem_deemp_err_fx; + move32(); /* TCX decoder */ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); st->hFdCngDec->msNoiseEst_exp = 27; + move16(); Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); - stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hCPE == NULL ? NULL : hCPE->hStereoCng, nchan_out, st_ivas == NULL ? 0 : st_ivas->ivas_format ); + IF( hCPE == NULL ) + { + hStereoCng = NULL; + } + ELSE + { + hStereoCng = hCPE->hStereoCng; + } + IF( st_ivas == NULL ) + { + ivas_format = 0; + move32(); + } + ELSE + { + ivas_format = st_ivas->ivas_format; + move32(); + } + stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; + move16(); Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); IF( st->hTcxDec ) { st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; + move16(); } - st->hBPF->pst_mem_deemp_err_fx = (Word16) st->mem_error; + st->hBPF->pst_mem_deemp_err_fx = extract_l( st->mem_error ); } IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ + Word16 Q_output; + + Q_output = 0; + move16(); Q_synth = 0; - Word16 Q_output = 0; + move16(); ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - Q_output ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); #ifdef MSAN_FIX - Scale_sig( synth_16_fx[n], output_frame, -Q_synth ); + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); #else - Scale_sig( synth_16_fx[n], L_FRAME48k, -Q_synth ); + Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); #endif - Scale_sig( output_16_fx[n], L_FRAME48k, -Q_output ); + Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); } /*---------------------------------------------------------------------* * TD stereo updates *---------------------------------------------------------------------*/ - IF( st->element_mode == IVAS_CPE_TD && n == 0 ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10 ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q6 ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); } } /* n_channels loop */ @@ -564,11 +697,13 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbSynHB ) { scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); } } @@ -577,31 +712,43 @@ ivas_error ivas_core_dec( } ELSE { - Word16 e_sig = 17; + Word16 e_sig; Word16 ch; + + e_sig = 17; + move16(); sts = hCPE->hCoreCoder; FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; st->last_gain_syn_deemph = 0; + move16(); IF( st->hHQ_core ) { st->hHQ_core->Q_fer_samples = 0; + move16(); } #ifdef FIX_778_STEREO_BRATE_SWITCHING st->Q_syn = 0; move16(); #endif st->prev_Q_syn = st->Q_syn; + move16(); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, st->Q_syn - st->hHQ_core->Q_old_wtda_LB ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, st->Q_syn - st->hHQ_core->Q_old_wtda ); + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda_LB ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda ) ); IF( st->hTcxDec ) - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + { + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + } IF( st->hTcxDec ) - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + { + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + } } stereo_mdct_core_dec_fx( st_ivas, hCPE, output_32_fx, synth_16_fx ); @@ -610,39 +757,41 @@ ivas_error ivas_core_dec( { st = hCPE->hCoreCoder[ch]; st->hHQ_core->Q_old_wtda_LB = st->Q_syn; + move16(); st->hHQ_core->Q_old_wtda = st->Q_syn; + move16(); } #ifdef MSAN_FIX - Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, e_sig - 15 ); - Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, e_sig - 15 ); + Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); #else - Scale_sig( synth_16_fx[0], L_FRAME48k, e_sig - 15 ); - Scale_sig( synth_16_fx[1], L_FRAME48k, e_sig - 15 ); + Scale_sig( synth_16_fx[0], L_FRAME48k, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], L_FRAME48k, sub( e_sig, 15 ) ); #endif } } /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ - ELSE IF( hCPE->nchan_out == 1 ) + ELSE IF( EQ_16( hCPE->nchan_out, 1 ) ) { sts[0] = hCPE->hCoreCoder[0]; sts[1] = hCPE->hCoreCoder[1]; - IF( hCPE->last_element_brate <= IVAS_SID_5k2 ) + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { - sts[0]->hHQ_core->exp_old_out = 15 - sts[0]->hHQ_core->Q_old_wtda; - sts[1]->hHQ_core->exp_old_out = 15 - sts[1]->hHQ_core->Q_old_wtda; + sts[0]->hHQ_core->exp_old_out = sub( 15, sts[0]->hHQ_core->Q_old_wtda ); + sts[1]->hHQ_core->exp_old_out = sub( 15, sts[1]->hHQ_core->Q_old_wtda ); } updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); - IF( hCPE->last_element_brate <= IVAS_SID_5k2 ) + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { - sts[0]->hHQ_core->Q_old_wtda = 15 - sts[0]->hHQ_core->exp_old_out; - sts[1]->hHQ_core->Q_old_wtda = 15 - sts[1]->hHQ_core->exp_old_out; + sts[0]->hHQ_core->Q_old_wtda = sub( 15, sts[0]->hHQ_core->exp_old_out ); + sts[1]->hHQ_core->Q_old_wtda = sub( 15, sts[1]->hHQ_core->exp_old_out ); } } test(); - IF( EQ_16( sts[0]->bfi, 0 ) && EQ_16( sts[0]->prev_bfi, 1 ) ) + IF( sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) { /* On first good frame after frameloss undo the whitening of the bg noise shape */ FOR( n = 0; n < n_channels; ++n ) @@ -651,6 +800,7 @@ ivas_error ivas_core_dec( { Scale_sig32( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27 ) ); sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 27; + move16(); TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); } @@ -662,13 +812,20 @@ ivas_error ivas_core_dec( * Stereo CNG updates *---------------------------------------------------------------------*/ + test(); IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) { /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ - Word16 Q_c_PS_LT = 31, Q_output = 11; + Word16 Q_c_PS_LT, Q_output; + Word32 c_PS_LT_fx; - Word32 c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); + Q_c_PS_LT = 31; + move16(); + Q_output = 11; + move16(); + c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); Q_c_PS_LT = Q31; + move16(); stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); @@ -689,10 +846,11 @@ ivas_error ivas_core_dec( /*core_switching_post_dec*/ Q_synth = 0; + move16(); if ( st->hHQ_core != NULL ) { st->hHQ_core->Q_old_postdec = 0; - // st->hHQ_core->Q_old_wtda = 0; + move16(); } /*------------------fix-to-fix-end-----------------------*/ @@ -711,12 +869,13 @@ ivas_error ivas_core_dec( set16_fx( output_mem_16_fx, 0, NS2SA( st->output_Fs, 3125000 ) ); } - Scale_sig32( output_32_fx[n], L_FRAME48k, Q4 - Q11 ); + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q4, Q11 ) ); IF( st->hHQ_core != NULL ) { - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); st->hHQ_core->Q_old_wtda = 0; + move16(); } /*size of synth is choosen as delay comp to start with*/ @@ -726,11 +885,14 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); st->cldfbSyn->Q_cldfb_state = Q4; + move16(); } Word16 q_audio, old_syn_fx; old_syn_fx = Q11; + move16(); q_audio = Q12; + move16(); test(); test(); test(); @@ -748,27 +910,25 @@ ivas_error ivas_core_dec( ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) { GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); - - move16(); } /* Memories Scaling */ - Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, st->prev_Q_bwe_syn2 - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), st->prev_Qx - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), st->prev_Qx - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, st->prev_Qx - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); } /* Memories Re-Scaling */ IF( st->hBWE_TD != NULL ) { - Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, Q11 - st->prev_Q_bwe_syn2 ); - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, Q11 - st->prev_Qx ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), Q11 - st->prev_Qx ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), Q11 - st->prev_Qx ); - Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, Q11 - st->prev_Qx ); - Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP ); + Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); + Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ) ); } /*---------------------------------------------------------------------* * Postprocessing for ACELP/MDCT core switching @@ -780,10 +940,31 @@ ivas_error ivas_core_dec( test(); IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth ); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); } - IF( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE, &Q_synth ) ) != IVAS_ERR_OK ) + IVAS_FORMAT ivas_format; + IF( st_ivas != NULL ) + { + ivas_format = st_ivas->ivas_format; + move32(); + } + ELSE + { + ivas_format = UNDEFINED_FORMAT; + move32(); + } + IF( hCPE != NULL ) + { + last_element_mode = hCPE->last_element_mode; + move16(); + } + ELSE + { + last_element_mode = IVAS_SCE; + move16(); + } + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ivas_format, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) { return error; } @@ -794,7 +975,7 @@ ivas_error ivas_core_dec( test(); IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth ); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); } /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ @@ -803,7 +984,7 @@ ivas_error ivas_core_dec( test(); test(); test(); - IF( EQ_16( n, 0 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) + IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) { Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); } @@ -813,8 +994,8 @@ ivas_error ivas_core_dec( ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); - Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); - Scale_sig32( output_32_fx[n], L_FRAME48k, Q11 - Q4 ); + Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), Q11 ); + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q11, Q4 ) ); /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -823,6 +1004,7 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q11, Q4 ) ); st->cldfbSyn->Q_cldfb_state = Q11; + move16(); } #ifdef MSAN_FIX @@ -833,15 +1015,20 @@ ivas_error ivas_core_dec( /*------------------reset-code-start---------------------*/ + test(); + test(); IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) { - + test(); IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) { st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; + move16(); } st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; + move16(); st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; + move16(); } /*---------------------------------------------------------------------* @@ -853,7 +1040,9 @@ ivas_error ivas_core_dec( Word16 Q_syn_hb; Q_input = 0; + move16(); Q_hb_synth_fx = 0; + move16(); Q_synth_fx = 0; move16(); @@ -874,28 +1063,28 @@ ivas_error ivas_core_dec( ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && EQ_16( st->bws_cnt, 0 ) && EQ_32( st->extl_brate, 0 ) ) + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) { /* do nothing */ } - ELSE IF( EQ_16( st->extl, WB_BWE ) && EQ_16( st->bws_cnt, 0 ) ) + ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) { /* WB BWE decoder */ Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); } /* Memories Re-Scaling */ - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, Q11 - Q_hb_synth_fx ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - Q_input ); - Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, Q11 - Q_synth_fx ); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); + Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); IF( hBWE_FD != NULL ) { - Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, Q11 - hBWE_FD->old_wtda_swb_fx_exp ); + Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); } IF( st->hBWE_TD != NULL ) { - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, Q11 - st->prev_Qx ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); } /*---------------------------------------------------------------------* @@ -913,7 +1102,7 @@ ivas_error ivas_core_dec( test(); test(); test(); - IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && GT_16( st->bws_cnt, 0 ) ) ) + IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) { /* SWB TBE decoder */ Q_white_exc = 0; @@ -921,11 +1110,11 @@ ivas_error ivas_core_dec( ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); IF( GT_16( Q_white_exc, 31 ) ) { - Scale_sig( tmp_buffer_fx, L_FRAME48k, 31 - Q_white_exc ); + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); Q_white_exc = 31; move16(); } @@ -936,14 +1125,14 @@ ivas_error ivas_core_dec( fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); } } - ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && EQ_16( st->core, ACELP_CORE ) && GT_16( st->bwidth, NB ) && GT_16( st->bws_cnt, 0 ) && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) + ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && EQ_16( st->core, ACELP_CORE ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) { /* SWB BWE decoder */ Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); - Scale_sig32( hb_synth_32_fx[n], output_frame, Q11 - Q_syn_hb ); + Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); - Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, hBWE_FD->old_wtda_swb_fx_exp - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); } /*---------------------------------------------------------------------* @@ -981,46 +1170,62 @@ ivas_error ivas_core_dec( * SWB CNG *---------------------------------------------------------------------*/ - IF( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) + test(); + test(); + test(); + test(); + IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) { /* SHB CNG decoder */ Word16 synth_fxl[960]; /* Q-2 */ - Word16 q = 2; - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 + q ) ); + Word16 q; + + q = 2; + move16(); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( add( Q11, q ) ) ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, -( Q11 + q ) ); + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); #else - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, -( Q11 + q ) ); + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); #endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, ( Q8 - st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, ( st->prev_Q_bwe_syn2 - Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, ( st->prev_Q_bwe_syn2 - Q11 ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); - swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], -q ); + swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); - Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, add( Q11, q ) ); + Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, add( Q11, q ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, st->prev_Q_bwe_syn ) ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, imult1616( 2, ALLPASSSECTIONS_STEEP ), negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); } /*-------------------------------------------------------------------* * Inter-channel BWE decoding *-------------------------------------------------------------------*/ test(); - IF( EQ_16( n, 0 ) && GE_16( st->element_mode, IVAS_CPE_DFT ) ) + IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) { - Word16 q = 11; + Word16 q; + q = 11; + move16(); - if ( hCPE->hStereoDft != NULL ) + IF( hCPE->hStereoDft != NULL ) { hCPE->hStereoDft->td_gain_fx[0] = 1; + move32(); } - Scale_sig( tmp_buffer_fx, L_FRAME48k, Q11 - Q_white_exc ); + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( Q11, Q_white_exc ) ); stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); #ifdef MSAN_FIX - IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( hCPE->hCoreCoder[0]->tdm_LRTD_flag, 0 ) ) ) ) ) ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag != 0 ) ) ) ) ) ) ) { Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); @@ -1037,15 +1242,24 @@ ivas_error ivas_core_dec( * BFI waveform adjustment *----------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) { tmps = NS2SA_fx2( output_Fs, DELAY_CLDFB_NS ); waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, - st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, st->hPlcInfo->nbLostCmpt + 1, st->bfi ); + st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); st->hPlcInfo->Pitch = 0; + move16(); } } @@ -1057,7 +1271,7 @@ ivas_error ivas_core_dec( test(); test(); test(); - IF( ( NE_16( st->extl, -1 ) && ( NE_16( st->extl, IGF_BWE ) || EQ_16( st->last_core, ACELP_CORE ) ) ) || ( GT_16( st->bws_cnt, 0 ) && EQ_16( st->core, ACELP_CORE ) ) ) + IF( ( NE_16( st->extl, -1 ) && ( NE_16( st->extl, IGF_BWE ) || EQ_16( st->last_core, ACELP_CORE ) ) ) || ( st->bws_cnt > 0 && EQ_16( st->core, ACELP_CORE ) ) ) { /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ IF( EQ_16( st->L_frame, L_FRAME ) ) @@ -1067,6 +1281,7 @@ ivas_error ivas_core_dec( } ELSE { + test(); IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) { /* HR SWB BWE on top of ACELP@16kHz */ @@ -1089,12 +1304,13 @@ ivas_error ivas_core_dec( test(); test(); test(); - + test(); + test(); IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && EQ_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) { /* switching between BWE and TBE technologies */ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) @@ -1110,13 +1326,15 @@ ivas_error ivas_core_dec( { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { - tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16] ), 1 ) ) ); + tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ), 1 ) ) ); + move16(); tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); + move16(); tmp16 = add( tmp16, incr ); } Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); @@ -1124,7 +1342,7 @@ ivas_error ivas_core_dec( ELSE IF( GT_16( tmps, st->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = idiv1616( L_FRAME * 2, add( shl( st->old_bwe_delay, 1 ), 1 ) ); + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( st->old_bwe_delay, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < st->old_bwe_delay; i++ ) @@ -1139,9 +1357,11 @@ ivas_error ivas_core_dec( move16(); } tmp16 = 0; + move16(); FOR( i = 0; i < st->old_bwe_delay; i++ ) { - tmp_buffer_fx[tmps - 1 - i] = round_fx( L_mac( L_mult( tmp_buffer_fx[tmps - 1 - i], 32767 ), st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16 /*i * incr*/] ) ); + tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); + move16(); tmp16 = add( tmp16, incr ); } @@ -1158,11 +1378,11 @@ ivas_error ivas_core_dec( Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); - Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, -11 ); + Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, negate( 11 ) ); } ELSE { - Copy_Scale_sig_32_16( hb_synth_32_fx[n] + output_frame - tmps, st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); + Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); } st->old_bwe_delay = tmps; @@ -1174,25 +1394,30 @@ ivas_error ivas_core_dec( IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && EQ_16( st->core, ACELP_CORE ) && st->hTdCngDec != NULL ) { Word16 exp, fra; + Word16 gb; SWITCH( output_frame ) { case L_FRAME8k: tmp16 = 205; + move16(); BREAK; /*Q15*/ case L_FRAME16k: tmp16 = 102; + move16(); BREAK; /*Q15*/ case L_FRAME32k: tmp16 = 51; + move16(); BREAK; /*Q15*/ case L_FRAME48k: tmp16 = 34; + move16(); BREAK; /*Q15*/ } L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ - Word16 gb = find_guarded_bits_fx( output_frame ); + gb = find_guarded_bits_fx( output_frame ); L_tmp = L_add( L_tmp, sum2_f_32_fx( hb_synth_32_fx[n], output_frame, sub( 11, gb ) ) ); L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); exp = norm_l( L_tmp ); @@ -1224,8 +1449,8 @@ ivas_error ivas_core_dec( { if ( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); } } } @@ -1236,18 +1461,20 @@ ivas_error ivas_core_dec( { if ( hSCE->hCoreCoder[0]->hHQ_core != NULL ) { - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); } } } - Word16 exp_max = 0; + Word16 exp_max; Word32 output_fx_loc[L_FRAME48k]; + exp_max = 0; + move16(); IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - + test(); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || sba_dirac_stereo_flag ) { ivas_post_proc_fx( hSCE, hCPE, n, synth_32_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); @@ -1264,7 +1491,9 @@ ivas_error ivas_core_dec( } ELSE /* IVAS_CPE_DFT */ { - Word16 q = 11; + Word16 q; + q = 11; + move16(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); @@ -1281,6 +1510,7 @@ ivas_error ivas_core_dec( Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); } + test(); IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ @@ -1303,53 +1533,50 @@ ivas_error ivas_core_dec( test(); IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { - Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0 /*, temp = 0*/; - move16(); + Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; move16(); move16(); move16(); move16(); move16(); - Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); + Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( Q11 ) ); st->q_prev_synth_buffer_fx = 0; + move16(); exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame ); - exp_ouput += 11; + exp_ouput = add( exp_ouput, Q11 ); exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - exp_prev_synth_buffer += st->q_prev_synth_buffer_fx; - exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) - NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + exp_prev_synth_buffer = add( exp_prev_synth_buffer, st->q_prev_synth_buffer_fx ); + exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ) ); exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ) + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) - output_frame ); + exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ) ); #ifndef FIX_740_HQ_CORE_OVA exp_synth_history += st->hTcxDec->q_synth_history_fx; #endif exp_max = s_min( exp_synth_history, exp_ouput ); exp_max = s_min( exp_max, exp_prev_synth_buffer ); - move16(); exp_max = s_min( exp_max, exp_old_out ); - move16(); exp_max = s_min( exp_max, exp_delay_buf_out ); - move16(); Copy32( output_32_fx[n], output_fx_loc, output_frame ); - Scale_sig32( output_fx_loc, output_frame, exp_max - 11 ); - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max - 0 ); - Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) - NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), exp_max - 0 ); - Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), exp_max - st->q_prev_synth_buffer_fx ); - Scale_sig( st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ) + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) - output_frame, exp_max - st->Q_syn ); + Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); + Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); + Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); + Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, st->Q_syn ) ); - st->q_prev_synth_buffer_fx = exp_max - st->q_prev_synth_buffer_fx; + st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); } /* Save synthesis for HQ FEC */ save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); /* Updates */ - ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], 11 ); + ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), -exp_max ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); } /* n_channels loop */ @@ -1360,11 +1587,13 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbSynHB ) { scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); } } diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 862ecaa11..ccb39cadf 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -35,6 +35,7 @@ #include "ivas_prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx1.h" #include "prot_fx2.h" #endif // IVAS_FLOAT_FIXED #include "prot.h" @@ -150,14 +151,22 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* prepare bitstream buffers */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - move32(); + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + ELSE + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } } } IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = mct_dec_reconfigure_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = mct_dec_reconfigure_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -165,7 +174,14 @@ ivas_error ivas_corecoder_dec_reconfig_fx( } ELSE { - st0 = GT_16( nSCE_old, 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + IF( nSCE_old > 0 ) + { + st0 = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st0 = st_ivas->hCPE[0]->hCoreCoder[0]; + } prev_bfi = st0->prev_bfi; move16(); nSCE_existing = s_min( nSCE_old, st_ivas->nSCE ); @@ -180,9 +196,9 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); test(); - IF( sba_dirac_stereo_flag_old && EQ_16( nCPE_old, 0 ) && st_ivas->hCPE[0] ) + IF( sba_dirac_stereo_flag_old && ( nCPE_old == 0 ) && st_ivas->hCPE[0] ) { - st_ivas->hCPE[0]->hCoreCoder[0] = 0; /* this has been deallocated as part of the SCE it actually belongs to */ + st_ivas->hCPE[0]->hCoreCoder[0] = NULL; /* this has been deallocated as part of the SCE it actually belongs to */ destroy_cpe_dec( st_ivas->hCPE[0] ); st_ivas->hCPE[0] = NULL; } @@ -192,7 +208,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* don't deallocate first CPE in case of mono/stereo output of 1 TC SBA, only deallocate core coder */ test(); test(); - IF( EQ_16( cpe_id, 0 ) && st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old ) + IF( ( cpe_id == 0 ) && st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { @@ -248,7 +264,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( } FOR( ; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ), IVAS_ERR_OK ) ) { return error; } @@ -258,7 +274,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); test(); test(); - IF( st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old && EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nSCE_old, 0 ) ) + IF( st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old && EQ_16( st_ivas->nchan_transport, 1 ) && ( nSCE_old == 0 ) ) { st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ st_ivas->hCPE[0]->hCoreCoder[1] = NULL; @@ -272,8 +288,16 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* prepare bitstream buffers */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - move32(); + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + ELSE + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } } } FOR( ; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -285,7 +309,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( move16(); } - IF( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ), IVAS_ERR_OK ) ) { return error; } @@ -307,19 +331,20 @@ ivas_error ivas_corecoder_dec_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hCPE[0]->element_brate, INV_FRAME_PER_SEC_Q15 ) ); + move16(); st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; move16(); } } - IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( st_ivas->hMCT != NULL && GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = mct_dec_reconfigure_fx( st_ivas, (UWord16) NE_16( st_ivas->nchan_transport, nchan_transport_old ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = mct_dec_reconfigure_fx( st_ivas, (UWord16) NE_16( st_ivas->nchan_transport, nchan_transport_old ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -329,7 +354,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); IF( EQ_16( st_ivas->nCPE, 1 ) && GT_16( nCPE_old, 1 ) ) { - IF( ( st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + IF( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } @@ -372,9 +397,9 @@ ivas_error ivas_corecoder_dec_reconfig_fx( ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ) { /* if at least one CPE is already available, only allocate DFT Stereo struct */ - IF( GT_16( st_ivas->nCPE, 0 ) ) + IF( ( st_ivas->nCPE > 0 ) ) { - IF( ( error = stereo_dft_dec_create_fx( &( st_ivas->hCPE[0]->hStereoDft ), st_ivas->hCPE[0]->element_brate, st_ivas->hDecoderConfig->output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = stereo_dft_dec_create_fx( &( st_ivas->hCPE[0]->hStereoDft ), st_ivas->hCPE[0]->element_brate, st_ivas->hDecoderConfig->output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) ) { return error; } @@ -382,7 +407,9 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* otherwise create extra dummy CPE */ ELSE { - IF( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 quo, rem; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &quo, &rem, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, quo ) ), IVAS_ERR_OK ) ) { return error; } @@ -401,7 +428,6 @@ ivas_error ivas_corecoder_dec_reconfig_fx( } set32_fx( st_ivas->hSCE[0]->save_synth_fx, 0, output_frame ); st_ivas->hSCE[0]->q_save_synth_fx = 0; - // st_ivas->hSCE[0]->q_save_synth_fx = Q11; move16(); } @@ -429,7 +455,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); IF( LE_32( hDecoderConfig->last_ivas_total_brate, IVAS_SID_5k2 ) && GE_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = initMdctStereoDtxData_fx( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = initMdctStereoDtxData_fx( st_ivas->hCPE[0] ) ), IVAS_ERR_OK ) ) { return error; } @@ -778,6 +804,7 @@ ivas_error ivas_hp20_dec_reconfig_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * HP20 memories @@ -946,10 +973,13 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* special case, if there was one transport channel in the previous frame and more than one in the current frame, remove the second CLDFB here, it was for CNA/CNG */ + test(); + test(); + test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( nchan_transport_old, 1 ) && EQ_16( numCldfbAnalyses_old, 2 ) && GT_16( st_ivas->nchan_transport, 1 ) ) { deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[1] ) ); - numCldfbAnalyses_old--; + numCldfbAnalyses_old = sub( numCldfbAnalyses_old, 1 ); } /* resample CLDFB analysis instances */ FOR( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) @@ -974,7 +1004,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* create additional CLDFB synthesis instances */ FOR( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - IF( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -994,22 +1024,35 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* create additional CLDFB synthesis instances */ FOR( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - IF( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } } } /* CLDFB Interpolation weights */ - IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( NE_16( numCldfbAnalyses_old, numCldfbAnalyses ) || NE_16( numCldfbSyntheses_old, numCldfbSyntheses ) || NE_16( nchan_transport_old, st_ivas->nchan_transport ) ) && NE_16( numCldfbAnalyses, 0 ) && NE_16( numCldfbSyntheses, 0 ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( NE_16( numCldfbAnalyses_old, numCldfbAnalyses ) || NE_16( numCldfbSyntheses_old, numCldfbSyntheses ) || NE_16( nchan_transport_old, st_ivas->nchan_transport ) ) && ( numCldfbAnalyses != 0 ) && ( numCldfbSyntheses != 0 ) ) { ivas_spar_get_cldfb_gains_fx( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 + { + st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], sub( Q27, Q11 ) ); // Scaling down from 27 to 11 + move32(); + } st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11; + move16(); FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21 - 11 ); // Scaling down from 21 to 11 + { + st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], sub( Q21, Q11 ) ); // Scaling down from 21 to 11 + move32(); + } st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11; + move16(); } return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 713bf6841..e0ac57446 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -78,7 +78,7 @@ ivas_error ivas_cpe_dec_fx( Word16 last_bwidth; Word16 tdm_ratio_idx; Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */ - Word16 q_res_buf = Q8; + Word16 q_res_buf; Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */ CPE_DEC_HANDLE hCPE; Decoder_State **sts; @@ -86,8 +86,12 @@ ivas_error ivas_cpe_dec_fx( ivas_error error; Word32 cpe_brate; Word32 element_brate_ref; + Word32 quo, rem; error = IVAS_ERR_OK; + move32(); + q_res_buf = Q8; + move16(); push_wmops( "ivas_cpe_dec" ); @@ -121,29 +125,34 @@ ivas_error ivas_cpe_dec_fx( *----------------------------------------------------------------*/ #if 1 // Float to fix conversions - Word16 q_old_out_LB = 31; + Word16 q_old_out_LB; + q_old_out_LB = 31; + move16(); // q_output_mem = 11; // q_buff_LBTCX_mem = 11; // q_input_mem_LB = q_buff_LBTCX_mem; FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { + test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); } } q_old_out_LB = Q11; + move16(); FOR( Word16 ind1 = 0; ind1 < 1; ind1++ ) { IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = q_old_out_LB; + move16(); } } #endif // Float to fix conversions - IF( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) ) { return error; } @@ -152,14 +161,15 @@ ivas_error ivas_cpe_dec_fx( { IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda - Q11 ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); } } FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { + test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB - Q11 ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); } } #endif @@ -170,7 +180,7 @@ ivas_error ivas_cpe_dec_fx( n_channels = CPE_CHANNELS; move16(); - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) + if ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { n_channels = 1; /* in DFT stereo, only M channel is coded */ move16(); @@ -186,7 +196,7 @@ ivas_error ivas_cpe_dec_fx( sts[n]->element_mode = hCPE->element_mode; move16(); - IF( !st_ivas->bfi ) + if ( !st_ivas->bfi ) { sts[n]->tdm_LRTD_flag = 0; move16(); @@ -225,18 +235,27 @@ ivas_error ivas_cpe_dec_fx( test(); test(); test(); - IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || EQ_16( sts[0]->ini_frame, 0 ) || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) ) + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) ) { + STEREO_DFT_CONFIG_DATA_HANDLE hConfig; + IF( hCPE->hStereoDft == NULL ) + { + hConfig = NULL; + } + ELSE + { + hConfig = hCPE->hStereoDft->hConfig; + } test(); IF( st_ivas->hQMetaData != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (Word32) ( st_ivas->hQMetaData->bits_frame_nominal * 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } ELSE { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } ELSE @@ -244,11 +263,11 @@ ivas_error ivas_cpe_dec_fx( /* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */ IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } ELSE { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } } @@ -257,8 +276,9 @@ ivas_error ivas_cpe_dec_fx( { IF( hCPE->hStereoTD->tdm_LRTD_flag ) { - sts[0]->bits_frame_nominal = extract_l( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); - sts[1]->bits_frame_nominal = extract_l( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); + iDiv_and_mod_32( L_shr( hCPE->element_brate, 1 ), FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[0]->bits_frame_nominal = extract_l( quo ); + sts[1]->bits_frame_nominal = extract_l( quo ); } ELSE { @@ -278,7 +298,8 @@ ivas_error ivas_cpe_dec_fx( /* Update DFT Stereo memories */ stereo_dft_dec_update_fx( hCPE->hStereoDft, output_frame, 0 ); - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { IF( EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { @@ -300,12 +321,23 @@ ivas_error ivas_cpe_dec_fx( move32(); IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( (Word16) ( cpe_brate / FRAMES_PER_SEC ), 1 ), nb_bits_metadata ); - sts[1]->bit_stream = sts[1]->bit_stream + (Word16) ( hCPE->brate_surplus / FRAMES_PER_SEC ); + iDiv_and_mod_32( cpe_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata ); + IF( hCPE->brate_surplus < 0 ) + { + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + } + sts[1]->bit_stream = sts[1]->bit_stream + extract_l( quo ); } ELSE { - sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( (Word16) ( ivas_total_brate / FRAMES_PER_SEC ), 1 ), nb_bits_metadata ); + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata ); } IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) @@ -331,9 +363,11 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nb_bits = sub( nb_bits, nb_bits_metadata ); - IF( LT_32( hCPE->brate_surplus, 0 ) ) + IF( hCPE->brate_surplus < 0 ) { - nb_bits = add( nb_bits, extract_l( hCPE->brate_surplus / FRAMES_PER_SEC ) ); + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + nb_bits = add( nb_bits, extract_l( quo ) ); } } @@ -341,7 +375,7 @@ ivas_error ivas_cpe_dec_fx( } /* subtract metadata bitbudget */ - sts[0]->total_brate = L_sub( sts[0]->total_brate, nb_bits_metadata * FRAMES_PER_SEC ); + sts[0]->total_brate = L_sub( sts[0]->total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /* subtract bit-rate for combined format coding */ test(); @@ -363,8 +397,18 @@ ivas_error ivas_cpe_dec_fx( /* signal bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; move16(); - sts[1]->bits_frame_channel = extract_l( hCPE->element_brate / FRAMES_PER_SEC ); - sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( hCPE->brate_surplus / FRAMES_PER_SEC ) ); + iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bits_frame_channel = extract_l( quo ); + IF( hCPE->brate_surplus < 0 ) + { + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + } + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( quo ) ); IF( st_ivas->hQMetaData != NULL ) { sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits ); @@ -378,7 +422,16 @@ ivas_error ivas_cpe_dec_fx( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - brate_surplus[0] = L_shr( L_mult( (Word16) L_shr( ( hCPE->brate_surplus / FRAMES_PER_SEC ), 1 ), FRAMES_PER_SEC ), 1 ); + IF( hCPE->brate_surplus < 0 ) + { + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + } + brate_surplus[0] = L_shr( L_mult( extract_l( L_shr( quo, 1 ) ), FRAMES_PER_SEC ), 1 ); move32(); brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] ); move32(); @@ -386,9 +439,9 @@ ivas_error ivas_cpe_dec_fx( test(); test(); - IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( EQ_16( sts[0]->first_CNG, 0 ) || EQ_16( sts[1]->first_CNG, 0 ) ) ) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( sts[0]->first_CNG == 0 || sts[1]->first_CNG == 0 ) ) { - IF( ( error = initMdctStereoDtxData_fx( hCPE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = initMdctStereoDtxData_fx( hCPE ) ), IVAS_ERR_OK ) ) { return error; } @@ -409,15 +462,26 @@ ivas_error ivas_cpe_dec_fx( sts[n]->total_brate = hCPE->element_brate; move32(); } - sts[n]->bits_frame_nominal = extract_l( sts[n]->total_brate / FRAMES_PER_SEC ); - sts[n]->bits_frame_channel = extract_l( L_shr( ( hCPE->element_brate / FRAMES_PER_SEC ), sub( n_channels, 1 ) ) ); + iDiv_and_mod_32( sts[n]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[n]->bits_frame_nominal = extract_l( quo ); + iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[n]->bits_frame_channel = extract_l( L_shr( quo, sub( n_channels, 1 ) ) ); /* subtract bit-rate for combined format coding */ test(); test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( brate_surplus[n] / FRAMES_PER_SEC ) ); + IF( brate_surplus[n] < 0 ) + { + iDiv_and_mod_32( L_abs( brate_surplus[n] ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( brate_surplus[n], FRAMES_PER_SEC, &quo, &rem, 0 ); + } + sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( quo ) ); sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] ); } } @@ -447,7 +511,14 @@ ivas_error ivas_cpe_dec_fx( FOR( n = 0; n < n_channels; n++ ) { /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ - sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, ( hCPE->hStereoTD != NULL ? hCPE->hStereoTD->tdm_LRTD_flag : 0 ), sts[n]->bwidth, sts[n]->cng_type ); + IF( hCPE->hStereoTD != NULL ) + { + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, hCPE->hStereoTD->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); + } + ELSE + { + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, 0, sts[n]->bwidth, sts[n]->cng_type ); + } } FOR( n = 0; n < n_channels; n++ ) @@ -469,7 +540,7 @@ ivas_error ivas_cpe_dec_fx( { sts[n]->VAD = 1; move16(); - sts[n]->active_cnt++; + sts[n]->active_cnt = add( sts[n]->active_cnt, 1 ); sts[n]->active_cnt = s_min( sts[n]->active_cnt, 100 ); } @@ -495,7 +566,8 @@ ivas_error ivas_cpe_dec_fx( { tdm_configure_dec( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata ); - sts[1]->bit_stream = sts[0]->bit_stream + extract_l( sts[0]->total_brate / FRAMES_PER_SEC ); + iDiv_and_mod_32( sts[0]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bit_stream = sts[0]->bit_stream + extract_l( quo ); } ELSE { @@ -514,7 +586,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { - IF( ( error = ivas_core_dec( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_core_dec( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -539,7 +611,7 @@ ivas_error ivas_cpe_dec_fx( set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); /* core decoder */ - IF( ( error = ivas_core_dec( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_core_dec( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -547,47 +619,73 @@ ivas_error ivas_cpe_dec_fx( // Scaling of DFT's Word16 shift; Word32 tmp1, tmp2; + Word16 shift1, shift2; maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 ); maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 ); - shift = s_min( ( tmp1 == 0 ) ? 31 : norm_l( tmp1 ), ( tmp2 == 0 ) ? 31 : norm_l( tmp2 ) ); + IF( tmp1 == 0 ) + { + shift1 = Q31; + move16(); + } + ELSE + { + shift1 = norm_l( tmp1 ); + } + IF( tmp2 == 0 ) + { + shift2 = Q31; + move16(); + } + ELSE + { + shift2 = norm_l( tmp2 ); + } + shift = s_min( shift1, shift2 ); - IF( shift != 31 ) + IF( NE_16( shift, 31 ) ) { - shift = hCPE->hStereoDft->q_dft + shift - Q13; /* Q13 for guard bits */ + shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q13 ); /* Q13 for guard bits */ - IF( shift > hCPE->hStereoDft->q_dft ) + IF( GT_16( shift, hCPE->hStereoDft->q_dft ) ) { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft ); + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); hCPE->hStereoDft->q_dft = shift; + move16(); } } ELSE { hCPE->hStereoDft->q_dft = Q8; + move16(); } /* DFT Stereo residual decoding */ test(); - IF( GT_16( hCPE->hStereoDft->res_cod_band_max, 0 ) && !st_ivas->bfi ) + IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st_ivas->bfi ) { - Word16 q = Q11; + Word16 q; Word16 q_out_DFT[2]; - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10 ); + q = Q11; + move16(); + + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), 10 ); - Scale_sig32( output[1], L_FRAME8k, Q11 - Q15 ); // Q15 -> Q11 + Scale_sig32( output[1], L_FRAME8k, sub( Q11, Q15 ) ); // Q15 -> Q11 q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft; + move16(); + move16(); stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, hCPE->hStereoDft->q_dft - q_out_DFT[1] ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); } /* DFT stereo CNG */ @@ -595,6 +693,7 @@ ivas_error ivas_cpe_dec_fx( Word16 q_dft; q_dft = hCPE->hStereoDft->q_dft; + move16(); // TODO : To check this @@ -608,20 +707,25 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; + move16(); FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + move16(); } hCPE->hStereoDft->first_frame = 0; + move16(); } scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; + move16(); #endif stereo_dft_unify_dmx_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata ); #if 1 scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = Q16; + move16(); #endif } ELSE @@ -631,21 +735,26 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; + move16(); FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + move16(); } hCPE->hStereoDft->first_frame = 0; + move16(); } scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; + move16(); } #endif stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #if 1 scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = Q16; + move16(); #endif } @@ -733,7 +842,7 @@ ivas_error ivas_cpe_dec_fx( test(); test(); test(); - IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && EQ_16( is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ), 0 ) ) ) ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( is_DTXrate( ivas_total_brate ) == 0 || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ) == 0 ) ) ) { applyDmxMdctStereo_fx( hCPE, output, output_frame ); } @@ -809,6 +918,7 @@ ivas_error create_cpe_dec( Word32 cpe_brate; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * Allocate CPE handle @@ -824,13 +934,17 @@ ivas_error create_cpe_dec( *-----------------------------------------------------------------*/ output_Fs = st_ivas->hDecoderConfig->output_Fs; - + move32(); hCPE->cpe_id = cpe_id; - + move16(); hCPE->element_brate = element_brate; + move32(); hCPE->last_element_brate = hCPE->element_brate; + move32(); hCPE->element_mode = st_ivas->element_mode_init; + move16(); hCPE->last_element_mode = st_ivas->element_mode_init; + move16(); hCPE->hStereoDft = NULL; hCPE->hStereoDftDmx = NULL; @@ -841,43 +955,62 @@ ivas_error create_cpe_dec( hCPE->hStereoCng = NULL; hCPE->stereo_switching_counter = 10; + move16(); hCPE->NbFrameMod = 7; + move16(); // hCPE->lt_es_em = 0.0f; hCPE->lt_es_em_fx = 0; + move32(); /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */ + test(); + test(); + test(); IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) ) { hCPE->nchan_out = CPE_CHANNELS; + move16(); } ELSE { hCPE->nchan_out = s_min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out ); } + test(); + test(); + test(); IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { cpe_brate = element_brate; + move32(); } ELSE { cpe_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); } + test(); + test(); + test(); + test(); IF( ( ( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) || ( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { hCPE->nchan_out = 1; + move16(); } FOR( n = 0; n < CPE_CHANNELS; n++ ) { - set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); - set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ) ); + set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_fx2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); + set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_fx2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, STEREO_DFT32MS_OVL_NS ) ) ); } hCPE->q_prev_synth_fx = 0; + move16(); hCPE->brate_surplus = 0; + move32(); /*-----------------------------------------------------------------* * DFT stereo I/O Buffers: allocate and initialize @@ -885,6 +1018,11 @@ ivas_error create_cpe_dec( FOR( i = 0; i < CPE_CHANNELS; i++ ) { + test(); + test(); + test(); + test(); + test(); IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) || ( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) && EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) ) || st_ivas->sba_dirac_stereo_flag ) { @@ -900,7 +1038,7 @@ ivas_error create_cpe_dec( } set32_fx( hCPE->input_mem_LB_fx[i], 0, STEREO_DFT32MS_OVL_16k ); - IF( EQ_16( i, 0 ) ) + IF( i == 0 ) { IF( ( hCPE->input_mem_BPF_fx[0] = (Word32 *) malloc( sizeof( Word32 ) * STEREO_DFT32MS_OVL_16k ) ) == NULL ) { @@ -915,6 +1053,7 @@ ivas_error create_cpe_dec( } set32_fx( hCPE->output_mem_fx[i], 0, NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ) ); hCPE->q_output_mem_fx[i] = Q11; + move16(); IF( LT_16( i, hCPE->nchan_out ) ) { IF( ( hCPE->prev_synth_chs_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_fx2( output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) @@ -932,12 +1071,13 @@ ivas_error create_cpe_dec( { hCPE->input_mem_fx[i] = NULL; hCPE->input_mem_LB_fx[i] = NULL; - IF( EQ_16( i, 0 ) ) + IF( i == 0 ) { hCPE->input_mem_BPF_fx[0] = NULL; } hCPE->output_mem_fx[i] = NULL; hCPE->q_output_mem_fx[i] = 0; + move16(); hCPE->prev_synth_chs_fx[i] = NULL; } } @@ -964,10 +1104,13 @@ ivas_error create_cpe_dec( // st->total_brate = hCPE->element_brate / ( CPE_CHANNELS ); st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); st->is_ism_format = 0; + move16(); st->ivas_format = st_ivas->ivas_format; + move32(); - IF( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) { return error; } @@ -979,141 +1122,137 @@ ivas_error create_cpe_dec( * DFT stereo initialization *-----------------------------------------------------------------*/ - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( hCPE->cpe_id, 0 ) ) ){ -#ifdef IVAS_FLOAT_FIXED - IF( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ){ - return error; -} -#else - IF( ( error = stereo_dft_dec_create( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ){ + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && hCPE->cpe_id == 0 ) ) + { + IF( NE_32( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) ) + { return error; -} -#endif -} + } + } -/*-----------------------------------------------------------------* - * DFT stereo mono DMX initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * DFT stereo mono DMX initialization + *-----------------------------------------------------------------*/ -IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) ) -{ - IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + test(); + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); - } + IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); + } -#ifdef IVAS_FLOAT_FIXED - stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx ); -#else - stereo_dft_dmx_out_reset( hCPE->hStereoDftDmx ); -#endif -} + stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx ); + } -/*-----------------------------------------------------------------* - * Temporal inter-channel alignment initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Temporal inter-channel alignment initialization + *-----------------------------------------------------------------*/ -IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) ) -{ - IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + test(); + test(); + test(); + IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); - } + IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); + } -#ifdef IVAS_FLOAT_FIXED - stereo_tca_init_dec_fx( hCPE->hStereoTCA ); -#else - stereo_tca_init_dec( hCPE->hStereoTCA ); -#endif -} + stereo_tca_init_dec_fx( hCPE->hStereoTCA ); + } -/*-----------------------------------------------------------------* - * Stereo IC BWE initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Stereo IC BWE initialization + *-----------------------------------------------------------------*/ -IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) ) -{ - IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + test(); + test(); + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) ); - } + IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) ); + } -#ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); -#else - stereo_icBWE_init_dec( hCPE->hStereoICBWE ); -#endif -} + stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); + } -/*-----------------------------------------------------------------* - * TD stereo initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * TD stereo initialization + *-----------------------------------------------------------------*/ -IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) -{ - IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); - } + IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); + } - stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); -} + stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); + } -/*-----------------------------------------------------------------* - * MDCT stereo initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ -IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) -{ - IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) ); - } + IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) ); + } - IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) - { - hCPE->hStereoMdct->use_itd = 1; - } - ELSE - { - hCPE->hStereoMdct->use_itd = 0; - } + test(); + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) + { + hCPE->hStereoMdct->use_itd = 1; + move16(); + } + ELSE + { + hCPE->hStereoMdct->use_itd = 0; + move16(); + } - hCPE->hStereoMdct->reverse_dmx = 0; -#ifndef IVAS_FLOAT_FIXED - hCPE->hStereoMdct->smooth_ratio = 1.f; -#else - hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; -#endif - set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); - set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); -#ifndef IVAS_FLOAT_FIXED - hCPE->hStereoMdct->lastCoh = 1.f; -#else - hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; -#endif - hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; - hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; - hCPE->hStereoMdct->IGFStereoMode[0] = -1; - hCPE->hStereoMdct->IGFStereoMode[1] = -1; -} + hCPE->hStereoMdct->reverse_dmx = 0; + move16(); + hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + move32(); + set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); + set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); + hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; + move16(); + hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; + move16(); + hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + move16(); + hCPE->hStereoMdct->IGFStereoMode[0] = -1; + move16(); + hCPE->hStereoMdct->IGFStereoMode[1] = -1; + move16(); + } -/*-----------------------------------------------------------------* - * Stereo CNG initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Stereo CNG initialization + *-----------------------------------------------------------------*/ -IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) -{ - IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); + IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); + } + stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize ); } - stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize ); -} -st_ivas->hCPE[cpe_id] = hCPE; + st_ivas->hCPE[cpe_id] = hCPE; -return error; + return error; } @@ -1302,7 +1441,7 @@ static void read_stereo_mode_and_bwidth_fx( { sts = hCPE->hCoreCoder; test(); - IF( st_ivas->hMCT && NE_16( hCPE->cpe_id, 0 ) ) + IF( st_ivas->hMCT && hCPE->cpe_id != 0 ) { sts[0]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth; move16(); diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 1ce8d7f10..f81110cb5 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -55,7 +55,9 @@ ivas_error ivas_dec( { // TODO: move here function ivas_jbm_dec_tc() and rename it to ivas_dec() st_ivas->ivas_format = UNDEFINED_FORMAT; // temp. to avoid compilation warnings - data[0] = 0; // temp. to avoid compilation warnings + move32(); + data[0] = 0; // temp. to avoid compilation warnings + move16(); return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 4e19ae179..c6623f9e5 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -511,7 +511,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - IF( ( EQ_16( st->idchan, 0 ) && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) + IF( ( st->idchan == 0 && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) { st->core = ACELP_CORE; move16(); @@ -545,12 +545,13 @@ void ivas_decision_matrix_dec_fx( move16(); } } - ELSE IF( EQ_32( st->total_brate, SID_2k40 ) && EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->cng_sba_flag, 0 ) ) + ELSE IF( EQ_32( st->total_brate, SID_2k40 ) && EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->cng_sba_flag == 0 ) { /* read channel coherence */ Word16 index; index = get_next_indice( st, 4 ); st->hFdCngDec->hFdCngCom->coherence_fx = get_next_index_4_by_15[index]; + move16(); ///* TODO: remove floating point dependency */ // st->hFdCngDec->hFdCngCom->coherence_flt = ( (float) get_next_index_4_by_15[index] ) / ( ( 1 << 15 ) - 1 ); @@ -662,7 +663,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); - IF( EQ_16( st->idchan, 1 ) && ( EQ_16( st->tdm_LRTD_flag, 0 ) || LT_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) ) + IF( EQ_16( st->idchan, 1 ) && ( st->tdm_LRTD_flag == 0 || LT_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) ) { st->bwidth = WB; /* only WB in the secondary channel */ move16(); @@ -713,7 +714,7 @@ void ivas_decision_matrix_dec_fx( { st->extl = WB_BWE; move16(); - IF( GE_32( st->total_brate, MIN_BRATE_WB_BWE ) ) + if ( GE_32( st->total_brate, MIN_BRATE_WB_BWE ) ) { st->extl_brate = WB_BWE_0k35; move32(); @@ -721,7 +722,7 @@ void ivas_decision_matrix_dec_fx( } ELSE IF( EQ_16( st->bwidth, WB ) && ( LT_32( st->total_brate, MIN_BRATE_WB_BWE ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) ) ) { - IF( EQ_16( st->vbr_hw_BWE_disable_dec, 0 ) ) + if ( st->vbr_hw_BWE_disable_dec == 0 ) { st->extl = WB_BWE; move16(); @@ -757,6 +758,14 @@ void ivas_decision_matrix_dec_fx( } ELSE IF( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( GE_32( st->total_brate, MIN_BRATE_SWB_BWE ) || ( GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) || ( LT_32( element_brate, IVAS_16k4 ) && GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) ) ) { /* read the SWB TBE/BWE selection bit */ @@ -775,6 +784,9 @@ void ivas_decision_matrix_dec_fx( move32(); st->extl_brate = SWB_TBE_1k6; move32(); + test(); + test(); + test(); IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) { st->extl_brate = SWB_TBE_2k8; @@ -824,6 +836,8 @@ void ivas_decision_matrix_dec_fx( move16(); st->extl_brate = FB_TBE_1k8; move32(); + test(); + test(); IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) { st->extl_brate = FB_TBE_3k0; @@ -838,7 +852,7 @@ void ivas_decision_matrix_dec_fx( { icbwe_brate = STEREO_BITS_ICBWE * FRAMES_PER_SEC; move32(); - IF( EQ_16( st->flag_ACELP16k, 0 ) ) + if ( st->flag_ACELP16k == 0 ) { icbwe_brate = ( STEREO_BITS_ICBWE - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); @@ -848,7 +862,7 @@ void ivas_decision_matrix_dec_fx( { icbwe_brate = STEREO_BITS_ICBWE_DFT * FRAMES_PER_SEC; move32(); - IF( EQ_16( st->flag_ACELP16k, 0 ) ) + if ( st->flag_ACELP16k == 0 ) { icbwe_brate = ( STEREO_BITS_ICBWE_DFT - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); @@ -860,7 +874,6 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - test(); IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) { icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); @@ -994,7 +1007,7 @@ void ivas_decision_matrix_dec_fx( st->inactive_coder_type_flag = 0; /* AVQ by default */ move16(); - IF( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) + if ( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) { st->inactive_coder_type_flag = 1; /* GSC */ move16(); @@ -1020,7 +1033,7 @@ void ivas_decision_matrix_dec_fx( move32(); } - IF( EQ_16( st->ini_frame, 0 ) ) + IF( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index afaa9d78a..a740ef159 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -65,16 +65,26 @@ static ivas_error ivas_dirac_dec_config_internal_fx( ivas_error error; DIRAC_CONFIG_FLAG flag_config; - flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + flag_config = DIRAC_RECONFIGURE; + move32(); + } + ELSE + { + flag_config = flag_config_inp; + move32(); + } error = IVAS_ERR_OK; + move32(); hDirAC = NULL; - IF( flag_config == DIRAC_RECONFIGURE ) + IF( EQ_32( flag_config, DIRAC_RECONFIGURE ) ) { hDirAC = st_ivas->hDirAC; } - ELSE IF( flag_config == DIRAC_OPEN ) + ELSE IF( EQ_32( flag_config, DIRAC_OPEN ) ) { /*-----------------------------------------------------------------* * prepare library opening @@ -97,15 +107,26 @@ static ivas_error ivas_dirac_dec_config_internal_fx( * DirAC main configuration *-----------------------------------------------------------------*/ - IF( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ), IVAS_ERR_OK ) ) { return error; } - IF( flag_config == DIRAC_OPEN ) + IF( EQ_32( flag_config, DIRAC_OPEN ) ) { - hDirAC->spar_to_dirac_write_idx = ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) ? DELAY_DIRAC_PARAM_DEC_SFR : 0; + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; + move16(); + } + ELSE + { + hDirAC->spar_to_dirac_write_idx = 0; + move16(); + } hDirAC->dithering_seed = DIRAC_DITH_SEED; + move16(); st_ivas->hDirAC = hDirAC; } @@ -184,10 +205,10 @@ static ivas_error ivas_dirac_rend_config_fx( Word16 num_protos_diff_old; Word32 *proto_frame_f_old_fx; Word16 proto_signal_decorr_on_old; - uint16_t i, j, k; + UWord16 i, j, k; Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; - int32_t output_Fs, ivas_total_brate; + Word32 output_Fs, ivas_total_brate; ivas_error error; Word16 nchan_transport_orig; Word16 hodirac_flag; @@ -195,20 +216,32 @@ static ivas_error ivas_dirac_rend_config_fx( DIRAC_REND_HANDLE hDirACRend; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { ls_azimuth_fx[i] = 0; + move32(); ls_elevation_fx[i] = 0; + move32(); } -#endif - flag_config = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + flag_config = DIRAC_RECONFIGURE; + move32(); + } + ELSE + { + flag_config = flag_config_inp; + move32(); + } error = IVAS_ERR_OK; + move32(); hDirACRend = NULL; output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ); hDirAC = st_ivas->hDirAC; @@ -230,24 +263,37 @@ static ivas_error ivas_dirac_rend_config_fx( } nchan_transport_old = 0; + move16(); } nchan_transport_old = 0; + move16(); num_outputs_dir_old = 0; + move16(); num_outputs_diff_old = 0; + move16(); num_protos_diff_old = 0; + move16(); nchan_transport_orig = st_ivas->nchan_transport; + move16(); + test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); } nchan_transport = st_ivas->nchan_transport; - IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) + move16(); + test(); + test(); + if ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { nchan_transport = 1; + move16(); } + test(); + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { Word16 tmp1, tmp2, tmp3; @@ -260,7 +306,9 @@ static ivas_error ivas_dirac_rend_config_fx( hDirACRend->hOutSetup = st_ivas->hIntSetup; nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; + move16(); + test(); IF( hDirACRend->hOutSetup.ls_azimuth_fx != NULL && hDirACRend->hOutSetup.ls_elevation_fx != NULL ) { Copy32( hDirACRend->hOutSetup.ls_azimuth_fx, ls_azimuth_fx, nchan_out_woLFE ); @@ -270,25 +318,35 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, negate( (Word16) 1 ) ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ - IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + move16(); + test(); + if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; + move16(); } } - ELSE IF( GE_16( hDirACRend->hOutSetup.ambisonics_order, SBA_FOA_ORDER ) ) { Copy32( ls_azimuth_4d4_fx, ls_azimuth_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); Copy32( ls_elevation_4d4_fx, ls_elevation_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); } + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 ); nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; - Copy32( &ls_azimuth_fx[add( hDirACRend->hOutSetup.separateChannelIndex, 1 )], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); - Copy32( &ls_elevation_fx[add( hDirACRend->hOutSetup.separateChannelIndex, 1 )], &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); + move16(); + Copy32( &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); + Copy32( &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); } /*-----------------------------------------------------------------* @@ -296,32 +354,55 @@ static ivas_error ivas_dirac_rend_config_fx( *-----------------------------------------------------------------*/ st_ivas->nchan_transport = nchan_transport_orig; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( GT_16( nchan_transport_orig, 2 ) && hDirACRend->hOutSetup.is_loudspeaker_setup && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && !hodirac_flag ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + move32(); hDirACRend->panningConf = DIRAC_PANNING_VBAP; + move32(); } ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; + move32(); hDirACRend->panningConf = DIRAC_PANNING_HOA3; + move32(); nchan_out_woLFE = 1; + move16(); } ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && hDirACRend->hOutSetup.is_loudspeaker_setup ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + move32(); hDirACRend->panningConf = DIRAC_PANNING_VBAP; + move32(); } ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_32( st_ivas->nchan_transport, 1 ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; + move32(); hDirACRend->panningConf = DIRAC_PANNING_HOA3; + move32(); } ELSE { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; + move32(); hDirACRend->panningConf = DIRAC_PANNING_HOA3; + move32(); } IF( EQ_16( flag_config, DIRAC_OPEN ) ) @@ -334,8 +415,13 @@ static ivas_error ivas_dirac_rend_config_fx( ivas_dirac_dec_get_frequency_axis_fx( hDirACRend->frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands ); } + test(); + test(); + test(); IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) && EQ_16( nchan_transport, 2 ) ) { + test(); + test(); IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect == NULL ) || EQ_16( flag_config, DIRAC_OPEN ) ) { IF( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) @@ -347,6 +433,7 @@ static ivas_error ivas_dirac_rend_config_fx( } ELSE { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect != NULL ) { free( hDirACRend->masa_stereo_type_detect ); @@ -355,6 +442,7 @@ static ivas_error ivas_dirac_rend_config_fx( } hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */ + move16(); /*-----------------------------------------------------------------* * (re)configure sub-modules @@ -364,8 +452,11 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) { num_outputs_dir_old = hDirACRend->num_outputs_dir; + move16(); num_outputs_diff_old = hDirACRend->num_outputs_diff; + move16(); num_protos_diff_old = hDirACRend->num_protos_diff; + move16(); } /* allocate output setup related arrays */ @@ -373,7 +464,9 @@ static ivas_error ivas_dirac_rend_config_fx( { /* Directional and diffuses components in output LS format */ hDirACRend->num_outputs_diff = nchan_out_woLFE; + move16(); hDirACRend->num_outputs_dir = nchan_out_woLFE; + move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { @@ -385,12 +478,16 @@ static ivas_error ivas_dirac_rend_config_fx( ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; + move16(); hDirACRend->num_outputs_dir = nchan_out_woLFE; + move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ - hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ + move16(); + hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ + move16(); } ELSE { @@ -400,17 +497,20 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( flag_config, DIRAC_OPEN ) ) { num_outputs_dir_old = hDirACRend->num_outputs_dir; + move16(); IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } num_outputs_diff_old = hDirACRend->num_outputs_diff; + move16(); IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } + test(); IF( NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) ) { free( hDirACRend->proto_index_dir ); @@ -421,6 +521,7 @@ static ivas_error ivas_dirac_rend_config_fx( } set16_fx( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir ); + test(); IF( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) ) { free( hDirACRend->proto_index_diff ); @@ -433,9 +534,11 @@ static ivas_error ivas_dirac_rend_config_fx( hDirACRend->sba_map_tc = sba_map_tc; + test(); IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { - IF( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) ) + test(); + if ( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) ) { hDirACRend->sba_map_tc = sba_map_tc_512; } @@ -444,92 +547,121 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( nchan_transport, 1 ) ) { hDirACRend->num_protos_ambi = 1; + move16(); hDirACRend->num_protos_dir = 1; + move16(); hDirACRend->num_protos_diff = 1; + move16(); } ELSE IF( EQ_16( nchan_transport, 2 ) ) { IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->num_protos_ambi = 2; + move16(); hDirACRend->num_protos_diff = 1; + move16(); hDirACRend->num_protos_dir = 2; + move16(); hDirACRend->proto_index_dir[1] = 1; + move16(); } ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { /* Following the foa rendering for code compatibility */ hDirACRend->num_protos_ambi = 2; + move16(); hDirACRend->num_protos_dir = 2; + move16(); hDirACRend->num_protos_diff = 3; + move16(); hDirACRend->proto_index_dir[0] = 0; + move16(); hDirACRend->proto_index_diff[0] = 0; + move16(); } ELSE { hDirACRend->num_protos_ambi = 2; + move16(); hDirACRend->num_protos_diff = 3; + move16(); FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { - IF( GT_32( ls_azimuth_fx[k], 0 ) ) + IF( ls_azimuth_fx[k] > 0 ) { hDirACRend->proto_index_diff[k] = 1; + move16(); } - ELSE IF( LT_32( ls_azimuth_fx[k], 0 ) ) + ELSE IF( ls_azimuth_fx[k] < 0 ) { hDirACRend->proto_index_diff[k] = 2; + move16(); } ELSE { hDirACRend->proto_index_diff[k] = 0; + move16(); } } IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) { hDirACRend->num_protos_dir = 3; + move16(); Copy( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE ); } ELSE { hDirACRend->num_protos_dir = 2; + move16(); hDirACRend->proto_index_dir[1] = 1; + move16(); } } } ELSE /* nchan_transport > 2 */ { hDirACRend->num_protos_ambi = 4; + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff; + move16(); FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { hDirACRend->proto_index_diff[k] = k; + move16(); } hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir; + move16(); FOR( k = 0; k < hDirACRend->num_outputs_dir; k++ ) { hDirACRend->proto_index_dir[k] = k; + move16(); } } ELSE { hDirACRend->num_protos_diff = 1; + move16(); hDirACRend->num_protos_dir = nchan_transport; + move16(); FOR( k = 0; k < s_min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ ) { - IF( hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir ) + if ( LT_16( hDirACRend->sba_map_tc[k], hDirACRend->num_outputs_dir ) ) { hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k; + move16(); } } } } + test(); /* direct/diffuse responses */ IF( EQ_16( flag_config, DIRAC_OPEN ) ) { @@ -548,6 +680,9 @@ static ivas_error ivas_dirac_rend_config_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } + + test(); + test(); IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) ) { initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, @@ -561,6 +696,8 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { + test(); + test(); IF( EQ_16( flag_config, DIRAC_OPEN ) ) { IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) @@ -582,6 +719,7 @@ static ivas_error ivas_dirac_rend_config_fx( } ELSE { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx ) { free( hDirACRend->hoa_encoder_fx ); @@ -590,24 +728,27 @@ static ivas_error ivas_dirac_rend_config_fx( } /* VBAP */ - IF( EQ_16( flag_config, DIRAC_OPEN ) ) + if ( EQ_16( flag_config, DIRAC_OPEN ) ) { st_ivas->hVBAPdata = NULL; } - IF( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) + test(); + IF( EQ_32( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL ) { vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); } - IF( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL ) { vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); @@ -623,6 +764,8 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( flag_config, DIRAC_OPEN ) ) { hDirACRend->hoa_decoder = NULL; + test(); + test(); IF( ( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || ( GT_16( nchan_transport, 2 ) ) ) { IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -632,7 +775,7 @@ static ivas_error ivas_dirac_rend_config_fx( free( st_ivas->hoa_dec_mtx ); st_ivas->hoa_dec_mtx = NULL; } - IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ), IVAS_ERR_OK ) ) { return error; } @@ -643,184 +786,237 @@ static ivas_error ivas_dirac_rend_config_fx( } /* decorrelation */ - proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirACRend->proto_signal_decorr_on : 0; + IF( flag_config == DIRAC_RECONFIGURE ) + { + proto_signal_decorr_on_old = hDirACRend->proto_signal_decorr_on; + move16(); + } + ELSE + { + proto_signal_decorr_on_old = 0; + move16(); + } hDirACRend->proto_signal_decorr_on = 1; - IF( ( GT_16( nchan_transport, 2 ) ) && ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) ) ) + move16(); + test(); + if ( ( GT_16( nchan_transport, 2 ) ) && ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) ) ) { /*switch off decorrelation for 4 transport channels*/ hDirACRend->proto_signal_decorr_on = 0; + move16(); } - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->proto_signal_decorr_on = 0; + move16(); } - IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ){ -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ){ - return error; -} -#else - IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ){ - return error; -} -#endif -} -ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) -{ - ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); -} -ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) -{ - IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { - /* close and reopen the decorrelator */ - ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + Word16 nchan_transport_tmp; + IF( GT_16( nchan_transport, 2 ) ) { - return error; + nchan_transport_tmp = 4; + move16(); } -#else - IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + ELSE + { + nchan_transport_tmp = nchan_transport; + move16(); + } + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ), + IVAS_ERR_OK ) ) { return error; } -#endif } -} - -/* output synthesis */ -IF( EQ_16( flag_config, DIRAC_OPEN ) ) -{ - IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) { - return error; + ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); } - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; -} -ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) ) -{ - ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); - - IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) { - return error; + test(); + test(); + IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + Word16 nchan_transport_tmp; + IF( GT_16( nchan_transport, 2 ) ) + { + nchan_transport_tmp = 4; + move16(); + } + ELSE + { + nchan_transport_tmp = nchan_transport; + move16(); + } + /* close and reopen the decorrelator */ + ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ), + IVAS_ERR_OK ) ) + { + return error; + } + } } - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; -} -IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) -{ - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; -} + /* output synthesis */ + test(); + test(); + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) ) + { + return error; + } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; + move16(); + } + ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) ) + { + ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); -/*-----------------------------------------------------------------* - * memory allocation - *-----------------------------------------------------------------*/ + IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) ) + { + return error; + } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; + move16(); + } -IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) -{ - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) + test(); + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - free( hDirACRend->proto_frame_f_fx ); + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; + move16(); } - hDirACRend->proto_frame_f_fx = NULL; -} -ELSE -{ - IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) ) + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + test(); + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + free( hDirACRend->proto_frame_f_fx ); } + hDirACRend->proto_frame_f_fx = NULL; } - ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) ) + ELSE { - proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx; - free( proto_frame_f_old_fx ); - IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + test(); + test(); + test(); + IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) ) + { + proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx; + free( proto_frame_f_old_fx ); + IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + } + hDirACRend->proto_frame_f_len = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) ); } - hDirACRend->proto_frame_f_len = 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands; -} -IF( EQ_16( flag_config, DIRAC_OPEN ) ) -{ - hDirACRend->buffer_energy_fx = NULL; -} + if ( EQ_16( flag_config, DIRAC_OPEN ) ) + { + hDirACRend->buffer_energy_fx = NULL; + } -IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == TRUE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) -{ - hDirACRend->index_buffer_intensity = 0; - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == TRUE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) { - FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + hDirACRend->index_buffer_intensity = 0; + move16(); + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + } + set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF ); + IF( hDirACRend->buffer_energy_fx == NULL ) + { + IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); + set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); + } + ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) + { + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) + { + free( hDirACRend->buffer_intensity_real_fx[i][j] ); + } + hDirACRend->buffer_intensity_real_fx[i][j] = NULL; + } + } + IF( hDirACRend->buffer_energy_fx != NULL ) + { + free( hDirACRend->buffer_energy_fx ); + hDirACRend->buffer_energy_fx = NULL; } } - set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF ); - IF( hDirACRend->buffer_energy_fx == NULL ) + /* output synthesis */ + ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); + + /* Allocate stack memory */ + IF( NE_16( flag_config, DIRAC_OPEN ) ) { - IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); } - set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); - set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); -} -ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) -{ - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + IF( NE_32( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ), IVAS_ERR_OK ) ) { - FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) - { - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) - { - free( hDirACRend->buffer_intensity_real_fx[i][j] ); - } - hDirACRend->buffer_intensity_real_fx[i][j] = NULL; - } + return error; } - IF( hDirACRend->buffer_energy_fx != NULL ) + + if ( EQ_16( flag_config, DIRAC_OPEN ) ) { - free( hDirACRend->buffer_energy_fx ); - hDirACRend->buffer_energy_fx = NULL; + st_ivas->hDirACRend = hDirACRend; } -} -/* output synthesis */ -ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); -/* Allocate stack memory */ -IF( NE_16( flag_config, DIRAC_OPEN ) ) -{ - ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); -} -IF( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) -{ return error; } - -IF( EQ_16( flag_config, DIRAC_OPEN ) ) -{ - st_ivas->hDirACRend = hDirACRend; -} - -return error; -} #else static ivas_error ivas_dirac_rend_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1477,24 +1673,45 @@ ivas_error ivas_dirac_dec_config_fx( Word16 dec_param_estim_new; error = IVAS_ERR_OK; + move32(); /* Solve and setup flags for inits */ - dec_config_flag = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + dec_config_flag = DIRAC_RECONFIGURE; + move32(); + } + ELSE + { + dec_config_flag = flag_config_inp; + move32(); + } output_Fs = st_ivas->hDecoderConfig->output_Fs; move32(); hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; + IF( EQ_32( dec_config_flag, DIRAC_RECONFIGURE ) ) + { + dec_param_estim_old = st_ivas->hDirAC->hConfig->dec_param_estim; + move16(); + } + ELSE + { + dec_param_estim_old = FALSE; + move16(); + } sparfoa_flag = 0; move16(); + test(); + test(); IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) { sparfoa_flag = 1; move16(); } - IF( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -1502,7 +1719,7 @@ ivas_error ivas_dirac_dec_config_fx( /* This is required for parambin */ test(); test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + if ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; move16(); @@ -1559,16 +1776,35 @@ ivas_error ivas_dirac_dec_config_fx( IF( !sparfoa_flag ) { - common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp; - IF( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, - st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ) != IVAS_ERR_OK ) + IF( st_ivas->hSpatParamRendCom == NULL ) + { + common_rend_config_flag = DIRAC_OPEN; + move32(); + } + ELSE + { + common_rend_config_flag = flag_config_inp; + move32(); + } + IF( NE_32( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, + st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ), + IVAS_ERR_OK ) ) { return error; } IF( need_dirac_rend ) { - rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp; - IF( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) + IF( st_ivas->hDirACRend == NULL ) + { + rend_config_flag = DIRAC_OPEN; + move32(); + } + ELSE + { + rend_config_flag = flag_config_inp; + move32(); + } + IF( NE_32( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -1579,7 +1815,7 @@ ivas_error ivas_dirac_dec_config_fx( IF( NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { /*WIP*/ - IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } @@ -1587,7 +1823,7 @@ ivas_error ivas_dirac_dec_config_fx( IF( st_ivas->hDiracDecBin == NULL ) { - IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } @@ -1595,12 +1831,14 @@ ivas_error ivas_dirac_dec_config_fx( ELSE { /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ + test(); + test(); IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) { ivas_dirac_dec_decorr_close_fx( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); // done } - IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -1613,8 +1851,9 @@ ivas_error ivas_dirac_dec_config_fx( Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, - DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ), + IVAS_ERR_OK ) ) { return error; } @@ -1825,6 +2064,7 @@ void ivas_dirac_dec_close_fx( { DIRAC_DEC_HANDLE hDirAC; + test(); IF( hDirAC_out == NULL || *hDirAC_out == NULL ) { return; @@ -1865,6 +2105,7 @@ void ivas_dirac_dec_read_BS_fx( { Word16 i, j, b, dir, orig_dirac_bands; Word16 next_bit_pos_orig; + Word32 quo, rem; test(); test(); @@ -1872,8 +2113,9 @@ void ivas_dirac_dec_read_BS_fx( { next_bit_pos_orig = st->next_bit_pos; move16(); - st->next_bit_pos = extract_l( L_sub( ivas_total_brate / FRAMES_PER_SEC, 1 ) ); - IF( GT_16( last_bit_pos, 0 ) ) + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + st->next_bit_pos = extract_l( L_sub( quo, 1 ) ); + if ( last_bit_pos > 0 ) { st->next_bit_pos = last_bit_pos; move16(); @@ -1892,7 +2134,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); /* if we start with a SID frame, we need to init the azi/ele arrays.*/ - IF( EQ_16( st->ini_frame, 0 ) ) + IF( st->ini_frame == 0 ) { FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { @@ -1901,6 +2143,7 @@ void ivas_dirac_dec_read_BS_fx( } } *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ) ); + move16(); FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { @@ -1936,6 +2179,7 @@ void ivas_dirac_dec_read_BS_fx( hQMetaData->sba_inactive_mode = 0; move16(); hQMetaData->is_masa_ivas_format = 0; + move16(); IF( hQMetaData->useLowerRes ) { hQMetaData->q_direction[0].cfg.nblocks = 1; @@ -1947,6 +2191,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); } *nb_bits = add( *nb_bits, ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ) ); + move16(); } st->next_bit_pos = next_bit_pos_orig; @@ -1958,7 +2203,8 @@ void ivas_dirac_dec_read_BS_fx( move16(); /* subtract mode signaling bits, since bitstream was moved after mode reading */ - st->next_bit_pos = extract_l( L_sub( L_sub( ivas_total_brate / FRAMES_PER_SEC, 1 ), SID_FORMAT_NBITS ) ); + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS ) ); move16(); /* 1 bit flag for signaling metadata to read */ b = st->bit_stream[( st->next_bit_pos )--]; @@ -1970,7 +2216,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); /* if we start with a SID frame, we need to init the azi/ele arrays.*/ - IF( EQ_16( st->ini_frame, 0 ) ) + IF( st->ini_frame == 0 ) { FOR( dir = 0; dir < hQMetaData->no_directions; dir++ ) { @@ -1982,6 +2228,7 @@ void ivas_dirac_dec_read_BS_fx( } } *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ) ); + move16(); FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; @@ -2015,6 +2262,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); } + test(); IF( hDirAC != NULL && hSpatParamRendCom != NULL ) { ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands ); @@ -2197,6 +2445,7 @@ void ivas_qmetadata_to_dirac_fx( q_direction = &( hQMetaData->q_direction[0] ); hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; + move16(); hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections ); test(); @@ -2272,7 +2521,7 @@ void ivas_qmetadata_to_dirac_fx( move32(); /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */ - IF( LT_32( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], 0 ) ) + if ( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] < 0 ) { hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = 0; move32(); @@ -2353,7 +2602,7 @@ void ivas_qmetadata_to_dirac_fx( nbands = hDirAC->hConfig->nbands; move16(); - IF( EQ_16( hQMetaData->q_direction[0].cfg.nblocks, 0 ) ) + if ( hQMetaData->q_direction[0].cfg.nblocks == 0 ) { /* No transmission -> no copy from qmetadata buffers*/ nbands = start_band; @@ -2402,7 +2651,7 @@ void ivas_qmetadata_to_dirac_fx( } /* Bands with spatial data transmitted */ - IF( hodirac_flag ) + if ( hodirac_flag ) { no_secs = DIRAC_HO_NUMSECTORS; move16(); @@ -2433,7 +2682,6 @@ void ivas_qmetadata_to_dirac_fx( move16(); diffuseness_fx = L_sub( ONE_IN_Q30, q_direction->band_data[qBand_idx].energy_ratio_fx[0] ); - move32(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -2443,7 +2691,7 @@ void ivas_qmetadata_to_dirac_fx( block_qmetadata = s_max( block_qmetadata, 0 ); - IF( LT_32( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], 0 ) ) + if ( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] < 0 ) { q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] = L_add( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], 1509949440 /*360.0F in Q22*/ ); move32(); @@ -2478,11 +2726,11 @@ void ivas_qmetadata_to_dirac_fx( azi = extract_h( L_shr( ( L_add( azimuth_fx, ONE_IN_Q21 ) ), 6 ) ); ele = extract_h( L_shr( ( L_add( elevation_fx, ONE_IN_Q21 ) ), 6 ) ); /*addition of one to compensate precision loss*/ - IF( LT_16( azi, 0 ) ) + if ( azi < 0 ) { azi = add( azi, 1 ); } - IF( LT_16( ele, 0 ) ) + if ( ele < 0 ) { ele = add( ele, 1 ); } @@ -2517,11 +2765,11 @@ void ivas_qmetadata_to_dirac_fx( ele = extract_h( L_shr( final_2_32, 31 - final_2_exp - 16 ) ); /*addition of one to compensate precision loss*/ - IF( LT_16( azi, 0 ) ) + if ( azi < 0 ) { azi = add( azi, 1 ); } - IF( LT_16( ele, 0 ) ) + if ( ele < 0 ) { ele = add( ele, 1 ); } @@ -2562,7 +2810,7 @@ void ivas_qmetadata_to_dirac_fx( IF( hodirac_flag ) { - IF( EQ_16( idx_sec, 0 ) ) + IF( idx_sec == 0 ) { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; move16(); @@ -2594,8 +2842,8 @@ void ivas_qmetadata_to_dirac_fx( move16(); } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) @@ -2936,8 +3184,8 @@ void ivas_qmetadata_to_dirac( tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) @@ -2989,17 +3237,25 @@ void ivas_dirac_dec_set_md_map( /* adapt subframes */ hSpatParamRendCom->num_slots = nCldfbTs; + move16(); hSpatParamRendCom->slots_rendered = 0; + move16(); num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); hSpatParamRendCom->subframes_rendered = 0; + move16(); ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); /* copy also to tc buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ + test(); + test(); + test(); IF( ( st_ivas->ivas_format != MASA_ISM_FORMAT || st_ivas->ism_mode != ISM_MASA_MODE_DISC ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) { st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes; + move16(); mvs2s( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); } @@ -3007,7 +3263,9 @@ void ivas_dirac_dec_set_md_map( set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - IF( st_ivas->ivas_format == MASA_FORMAT ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } @@ -3020,24 +3278,30 @@ void ivas_dirac_dec_set_md_map( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } + test(); + test(); IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { Word64 tmp_fx; Word16 sf_idx, slot_idx, slot_idx_abs; + Word32 quo, rem; slot_idx_abs = 0; + move16(); FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) { tmp_fx = 0; + move64(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) { - tmp_fx += hSpatParamRendCom->render_to_md_map[slot_idx_abs]; - slot_idx_abs++; + tmp_fx = W_add_nosat( tmp_fx, W_deposit32_l( L_deposit_l( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ) ); + slot_idx_abs = add( slot_idx_abs, 1 ); } - hSpatParamRendCom->render_to_md_map[sf_idx] = ( round_fx( (Word32) ( tmp_fx << 16 ) / hSpatParamRendCom->subframe_nbslots[sf_idx] ) + hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; + iDiv_and_mod_32( W_extract_l( W_shl_nosat( tmp_fx, 16 ) ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 ); + hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; } - set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes ); + set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); } return; @@ -3127,17 +3391,25 @@ void ivas_dirac_dec_set_md_map_fx( /* adapt subframes */ hSpatParamRendCom->num_slots = nCldfbTs; + move16(); hSpatParamRendCom->slots_rendered = 0; + move16(); num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); hSpatParamRendCom->subframes_rendered = 0; + move16(); ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); /* copy also to tc buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ + test(); + test(); + test(); IF( ( st_ivas->ivas_format != MASA_ISM_FORMAT || st_ivas->ism_mode != ISM_MASA_MODE_DISC ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) { st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes; + move16(); Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); } @@ -3145,7 +3417,9 @@ void ivas_dirac_dec_set_md_map_fx( set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - IF( st_ivas->ivas_format == MASA_FORMAT ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } @@ -3158,6 +3432,8 @@ void ivas_dirac_dec_set_md_map_fx( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } + test(); + test(); IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { Word16 sf_idx, slot_idx, slot_idx_abs; @@ -3168,9 +3444,11 @@ void ivas_dirac_dec_set_md_map_fx( Word16 ans_fix_16, exp_final; slot_idx_abs = 0; + move16(); FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) { tmp_fx = 0; + move32(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) { tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ); @@ -3178,17 +3456,22 @@ void ivas_dirac_dec_set_md_map_fx( } exp_denom = 15, exp_num = 31; + move16(); + move16(); norm_num = norm_l( tmp_fx ); num = L_shl( tmp_fx, norm_num ); - exp_num = exp_num - norm_num; + exp_num = sub( exp_num, norm_num ); + move16(); norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] ); denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom ); - exp_denom = exp_denom - norm_denom; + exp_denom = sub( exp_denom, norm_denom ); + move16(); exp = sub( exp_num, exp_denom ); + move16(); - IF( num > denom ) + IF( GT_32( num, L_deposit_l( denom ) ) ) { num = L_shr( num, 1 ); exp = add( exp, 1 ); @@ -3196,11 +3479,12 @@ void ivas_dirac_dec_set_md_map_fx( ans = div_l( num, denom ); ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final ); - ans_fix_16 = round_fx( L_shr( ans_fix_32, 31 - exp_final - 16 ) ); + ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) ); hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } - set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes ); + set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); } return; @@ -3225,6 +3509,7 @@ void ivas_dirac_dec_render_fx( Word16 slots_to_render, first_sf, last_sf, subframe_idx; UWord16 slot_size, n_samples_sf, ch, nchan_intern; Word16 temp = 0; + move16(); SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV @@ -3251,10 +3536,11 @@ void ivas_dirac_dec_render_fx( last_sf = first_sf; move16(); - WHILE( GT_16( slots_to_render, 0 ) ) + WHILE( slots_to_render > 0 ) { slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); - last_sf++; + last_sf = add( last_sf, 1 ); + move16(); } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -3278,6 +3564,8 @@ void ivas_dirac_dec_render_fx( FOR( ch = 0; ch < nchan_intern; ch++ ) { + test(); + test(); IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) { Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); @@ -3412,6 +3700,8 @@ void ivas_dirac_dec_render_sf_fx( Word32 Cldfb_RealBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; Word16 index = 0, num_freq_bands = 0; + move16(); + move16(); /* local copies of azi, ele, diffuseness */ Word16 azimuth[CLDFB_NO_CHANNELS_MAX]; @@ -3423,12 +3713,16 @@ void ivas_dirac_dec_render_sf_fx( Word32 surCohEner_fx; Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX]; Word16 surCohRatio_q_fx = 0, temp_q = 0; + move16(); + move16(); Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word16 cldfb_buf_q; Word16 offset, buff_len; Word16 q_cldfb, q_temp_cldfb = 0; + move16(); Word16 proto_length = 0; + move16(); Word16 q_proto_direct_buffer[CLDFB_SLOTS_PER_SUBFRAME]; Word16 q_proto_diffuse_buffer[CLDFB_SLOTS_PER_SUBFRAME]; Word16 size, size_ho; @@ -3438,11 +3732,15 @@ void ivas_dirac_dec_render_sf_fx( uint16_t coherence_flag; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word16 scale = 0; + move16(); DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; Word16 num_channels_dir, exp; Word16 q_diffuseness_vector = Q31, q_reference_power_smooth = Q31; + move16(); + move16(); Word16 proto_power_smooth_len = 0; + move16(); Word16 tmp1; push_wmops( "ivas_dirac_dec_render" ); @@ -3455,80 +3753,117 @@ void ivas_dirac_dec_render_sf_fx( DirAC_mem = hDirACRend->stack_mem; reference_power_fx = DirAC_mem.reference_power_fx; - reference_power_smooth_fx = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; + IF( DirAC_mem.reference_power_fx == NULL ) + { + reference_power_smooth_fx = NULL; + } + ELSE + { + reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; + } onset_filter_fx = DirAC_mem.onset_filter_fx; - onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + IF( DirAC_mem.onset_filter_fx == NULL ) + { + onset_filter_subframe_fx = NULL; + } + ELSE + { + onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + } q_cldfb = Q11; move16(); set_s( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); set_s( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX ); - //////////////////////////////////////////////////////////////////////////// to be removed /////////////////////////////////////////////////////////////////// + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { IF( hDirACRend->masa_stereo_type_detect ) { hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0; + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31; + move16(); } } + test(); IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { - if ( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 ) + IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state ); tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len ); scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); - state->proto_power_diff_smooth_q += tmp1; + state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 ); } } h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); num_channels_dir = hDirACRend->num_outputs_dir; + move16(); hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + if ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; + move16(); } - if ( h_dirac_output_synthesis_params->use_onset_filters && ( hDirAC->hConfig->dec_param_estim != TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) ) + test(); + test(); + IF( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { - tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, tmp1 - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); + tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1; + move16(); } - if ( hDirAC->hConfig->dec_param_estim == TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + test(); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - Word16 shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); - h_dirac_output_synthesis_state->q_cy_auto_dir_smooth += shift; + Word16 shift; + shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift ); - shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); - h_dirac_output_synthesis_state->q_cy_cross_dir_smooth += shift; + shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift ); - tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, tmp1 ); - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth += tmp1; + tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 ); } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + move16(); } } - else if ( !L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( !L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { + Word16 outchannels; idx_lfe = 0; + move16(); idx_in = 0; - Word16 outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + move16(); + outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || @@ -3539,11 +3874,13 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( outchannels, 1 ); } + test(); IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) ) { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -3556,12 +3893,16 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { - Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); + Word16 cldfbSynIdx; + cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; + move16(); } } ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) @@ -3570,66 +3911,82 @@ void ivas_dirac_dec_render_sf_fx( ELSE { st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; + move16(); idx_in = add( idx_in, 1 ); } } } } - /////////////////////////////////////////////////////////////////////////////////////////////// - size = hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands; - size_ho = ( hodirac_flag ) ? size * DIRAC_HO_NUMSECTORS : size; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); + size = imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ); + IF( hodirac_flag ) + { + size_ho = imult1616( size, DIRAC_HO_NUMSECTORS ); + } + ELSE + { + size_ho = size; + move16(); + } + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); + Word16 shift; + shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ) ); hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; + move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ) ); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; + move16(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ) ); hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; + move16(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); + Word16 shift; + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; + move16(); - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); + shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); - tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE, tmp1 ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev += tmp1; + tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp1 ); - tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands, tmp1 ); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q += tmp1; + tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, tmp1 ); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { - tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_params.max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_params.max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE, tmp1 ); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q += tmp1; + tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, tmp1 ); } } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - IF( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) + test(); + test(); + IF( st_ivas->hQMetaData != NULL && NE_32( st_ivas->ivas_format, SBA_FORMAT ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { coherence_flag = st_ivas->hQMetaData->coherence_flag; move16(); @@ -3683,11 +4040,12 @@ void ivas_dirac_dec_render_sf_fx( set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); } + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) { p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; - IF( EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + IF( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); @@ -3704,6 +4062,7 @@ void ivas_dirac_dec_render_sf_fx( IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) { + Word16 *masa_band_mapping; /* compute response */ IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { @@ -3746,7 +4105,11 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - Word16 max_exp_direct = 0, max_exp_diffusion = 0; + Word16 max_exp_direct, max_exp_diffusion; + max_exp_direct = 0; + move16(); + max_exp_diffusion = 0; + move16(); ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->diffuseness_vector_fx[md_idx], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, @@ -3760,8 +4123,7 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - surCohRatio_fx[i] = (Word32) hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]; - move32(); + surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); } } ELSE @@ -3772,12 +4134,22 @@ void ivas_dirac_dec_render_sf_fx( move16(); } + IF( st_ivas->hMasa == NULL ) + { + masa_band_mapping = NULL; + } + ELSE + { + masa_band_mapping = st_ivas->hMasa->data.band_mapping; + } + test(); + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 1 ) ) { ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, hDirACRend, st_ivas->hVBAPdata, - st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + masa_band_mapping, st_ivas->hMasaIsmData, azimuth, elevation, @@ -3793,7 +4165,7 @@ void ivas_dirac_dec_render_sf_fx( ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, hDirACRend, st_ivas->hVBAPdata, - st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + masa_band_mapping, st_ivas->hMasaIsmData, azimuth, elevation, @@ -3806,6 +4178,7 @@ void ivas_dirac_dec_render_sf_fx( } } + test(); IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -3827,6 +4200,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } + test(); IF( L_and( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ), NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); @@ -3846,6 +4220,8 @@ void ivas_dirac_dec_render_sf_fx( md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); } + test(); + test(); IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) @@ -3883,12 +4259,17 @@ void ivas_dirac_dec_render_sf_fx( } /* CNG in DirAC, extra CLDFB ana for CNA*/ + test(); + test(); + test(); + test(); IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; Word16 Q_input = Q11; move16(); q_temp_cldfb = Q11; + move16(); generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom, st_ivas->cldfbAnaDec[1], st_ivas->hTcBuffer->tc_fx[1], @@ -3902,7 +4283,10 @@ void ivas_dirac_dec_render_sf_fx( } /* LFE synthesis */ - IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + test(); + test(); + test(); + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && hDirACRend->hOutSetup.num_lfe == 0 ) ) { ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, @@ -3917,7 +4301,9 @@ void ivas_dirac_dec_render_sf_fx( *-----------------------------------------------------------------*/ IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + test(); + test(); + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) { protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, @@ -4048,7 +4434,10 @@ void ivas_dirac_dec_render_sf_fx( { Copy( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) ); Copy( &hSpatParamRendCom->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) ); - IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + + test(); + test(); + IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); @@ -4056,9 +4445,10 @@ void ivas_dirac_dec_render_sf_fx( } /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */ - IF( EQ_16( hDirACRend->index_buffer_intensity, 0 ) ) + IF( hDirACRend->index_buffer_intensity == 0 ) { hDirACRend->index_buffer_intensity = 1; + move16(); } ELSE { @@ -4072,19 +4462,19 @@ void ivas_dirac_dec_render_sf_fx( computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, q_cldfb, num_freq_bands, - hDirACRend->buffer_intensity_real_fx[0][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[1][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[2][sub( index, 1 )], - &hDirACRend->q_buffer_intensity_real[sub( index, 1 )] ); - - computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[1][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[2][sub( index, 1 )], - hDirACRend->q_buffer_intensity_real[sub( index, 1 )], + hDirACRend->buffer_intensity_real_fx[0][index - 1], + hDirACRend->buffer_intensity_real_fx[1][index - 1], + hDirACRend->buffer_intensity_real_fx[2][index - 1], + &hDirACRend->q_buffer_intensity_real[index - 1] ); + + computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][index - 1], + hDirACRend->buffer_intensity_real_fx[1][index - 1], + hDirACRend->buffer_intensity_real_fx[2][index - 1], + hDirACRend->q_buffer_intensity_real[index - 1], num_freq_bands, azimuth, elevation ); Copy32( reference_power_fx, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); - hDirACRend->q_buffer_energy[sub( index, 1 )] = DirAC_mem.reference_power_q; + hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q; move16(); computeDiffuseness_fixed( hDirACRend->buffer_intensity_real_fx, hDirACRend->buffer_energy_fx, num_freq_bands, hSpatParamRendCom->diffuseness_vector_fx[md_idx], hDirACRend->q_buffer_intensity_real, hDirACRend->q_buffer_energy, &hSpatParamRendCom->q_diffuseness_vector ); @@ -4103,11 +4493,11 @@ void ivas_dirac_dec_render_sf_fx( hDirACRend->num_protos_diff, hDirACRend->synthesisConf, nchan_transport, - &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff], + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff )], hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->num_protos_diff, hDirACRend->proto_index_diff, - &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport )], + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx[add( imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff ), imult1616( imult1616( 2, hSpatParamRendCom->num_freq_bands ), s_min( 4, nchan_transport ) ) )], &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, onset_filter_fx, hDirACRend->h_freq_domain_decorr_ap_params, @@ -4168,10 +4558,13 @@ void ivas_dirac_dec_render_sf_fx( /*-----------------------------------------------------------------* * output synthesis *-----------------------------------------------------------------*/ + test(); IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { - DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state ); - Word16 diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); + DIRAC_OUTPUT_SYNTHESIS_STATE *state; + Word16 diffuse_start; + state = &( hDirACRend->h_output_synthesis_psd_state ); + diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len ); scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); @@ -4191,12 +4584,14 @@ void ivas_dirac_dec_render_sf_fx( num_channels_dir = hDirACRend->num_outputs_dir; move16(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; move16(); } + test(); + test(); IF( L_and( h_dirac_output_synthesis_params->use_onset_filters, L_and( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) { Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_params->max_band_decorr, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); @@ -4208,6 +4603,7 @@ void ivas_dirac_dec_render_sf_fx( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); } + test(); IF( L_and( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); @@ -4239,6 +4635,8 @@ void ivas_dirac_dec_render_sf_fx( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); } + test(); + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order > 0 ) { ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx, @@ -4282,9 +4680,10 @@ void ivas_dirac_dec_render_sf_fx( IF( hDirAC->hConfig->dec_param_estim ) { - Word16 fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp ); + Word16 fac; Flag flag = 0; move32(); + fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp ); fac = shl_o( fac, exp, &flag ); IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ) @@ -4449,6 +4848,7 @@ void ivas_dirac_dec_render_sf_fx( &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ); + test(); IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) @@ -4618,9 +5018,13 @@ void ivas_dirac_dec_render_sf_fx( index_slot = slot_idx_start_cldfb_synth; move16(); + test(); + test(); IF( L_or( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */ + test(); + test(); IF( L_and( L_and( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ), EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { Word16 in_ch; @@ -4645,6 +5049,7 @@ void ivas_dirac_dec_render_sf_fx( interp_offset = st_ivas->hTcBuffer->n_samples_rendered; move16(); + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] ) { ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx ); @@ -4654,6 +5059,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( i = 0; i < num_objects; i++ ) { /* Combined rotation: rotate the object positions depending the head and external orientations */ + test(); IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) ) { Word16 az_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ) ); @@ -4675,23 +5081,25 @@ void ivas_dirac_dec_render_sf_fx( move16(); for ( j = 0, j2 = 0; j < nchan_out_woLFE; j++, j2++ ) { - IF( L_and( GT_16( st_ivas->hIntSetup.num_lfe, 0 ), ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) + test(); + IF( L_and( st_ivas->hIntSetup.num_lfe > 0, ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) { IF( LT_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) ) { - lfe_index++; - j2++; + lfe_index = add( lfe_index, 1 ); + j2 = add( j2, 1 ); } ELSE { - j2++; + j2 = add( j2, 1 ); } } gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j]; move32(); prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j]; move32(); - IF( L_or( GT_32( L_abs( gain_fx ), 0 ), GT_32( L_abs( prev_gain_fx ), 0 ) ) ) + test(); + IF( L_or( L_abs( gain_fx ) > 0, L_abs( prev_gain_fx ) > 0 ) ) { Word32 *tc_re_fx, *tc_im_fx; Word16 *w1_fx, w2_fx; @@ -4719,7 +5127,8 @@ void ivas_dirac_dec_render_sf_fx( } } /* update here only in case of head rotation */ - IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] == 1 ) + test(); + IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) ) { st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; move32(); @@ -4730,7 +5139,8 @@ void ivas_dirac_dec_render_sf_fx( } /* Perform binaural rendering */ - Word16 input_q = Q6; + Word16 input_q; + input_q = Q6; move16(); ivas_binRenderer_fx( st_ivas->hBinRenderer, @@ -4802,6 +5212,13 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || @@ -4812,6 +5229,7 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( outchannels, 1 ); } + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { Word32 tmp_separated_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -4824,7 +5242,9 @@ void ivas_dirac_dec_render_sf_fx( Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe ); FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { /* Move the LFE channel to the correct place */ Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe ); @@ -4867,8 +5287,12 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { + test(); + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) @@ -4963,31 +5387,44 @@ void ivas_dirac_dec_render_sf_fx( hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); -#ifdef IVAS_FLOAT_FIXED - /////////////////////////////////////////////////////// FIXED TO FLOAT ////////////////////////////////////////////////////////////////////////////////////////// IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; + move16(); hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; + move16(); } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; + move16(); } } - else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { } - else + ELSE { + Word16 outchannels; idx_lfe = 0; + move16(); idx_in = 0; - Word16 outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + move16(); + outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || @@ -4998,11 +5435,13 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( outchannels, 1 ); } + test(); IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) ) { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5015,28 +5454,36 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; + move16(); } } ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) { scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; + move16(); idx_in = add( idx_in, 1 ); } } } - if ( !hDirACRend->hOutSetup.separateChannelEnabled || hDirACRend->hOutSetup.output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM ) + test(); + IF( !hDirACRend->hOutSetup.separateChannelEnabled || NE_32( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { Word16 tmp_lfe_idx = 0; - for ( ch = 0; ch < outchannels; ch++ ) + move16(); + FOR( ch = 0; ch < outchannels; ch++ ) { + test(); IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) ) { IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) @@ -5047,8 +5494,6 @@ void ivas_dirac_dec_render_sf_fx( } } } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#endif pop_wmops(); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 11535dded..c11dda7cc 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -87,42 +87,40 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( /* buffer length and interpolator */ h_dirac_output_synthesis_params->alpha_synthesis_fx = NULL; - if ( ( h_dirac_output_synthesis_params->proto_matrix_fx = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_params->proto_matrix_fx = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - h_dirac_output_synthesis_params->proto_matrix_len = nchan_out * nchan_in; - move16(); + h_dirac_output_synthesis_params->proto_matrix_len = imult1616( nchan_out, nchan_in ); + /* cov buffers */ - for ( idx = 0; idx < num_param_bands; idx++ ) + FOR( idx = 0; idx < num_param_bands; idx++ ) { - - if ( ( h_dirac_output_synthesis_state->cx_old_fx[idx] = (Word32 *) malloc( nchan_in * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->cx_old_fx[idx] = (Word32 *) malloc( nchan_in * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - h_dirac_output_synthesis_state->cx_old_len = nchan_in * nchan_in; - move16(); - if ( ( h_dirac_output_synthesis_state->cy_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) + h_dirac_output_synthesis_state->cx_old_len = imult1616( nchan_in, nchan_in ); + IF( ( h_dirac_output_synthesis_state->cy_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], nchan_in * nchan_in ); - set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], nchan_out * nchan_out ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], nchan_out * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], imult1616( nchan_in, nchan_in ) ); + set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], imult1616( nchan_out, nchan_out ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], imult1616( nchan_out, nchan_in ) ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], nchan_out * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], imult1616( nchan_out, nchan_in ) ); h_dirac_output_synthesis_state->mixing_matrix_len = i_mult( nchan_out, nchan_in ); } - for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { h_dirac_output_synthesis_state->cx_old_fx[idx] = NULL; h_dirac_output_synthesis_state->cy_old_fx[idx] = NULL; @@ -130,32 +128,32 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = NULL; } - for ( idx = 0; idx < num_param_bands_residual; idx++ ) + FOR( idx = 0; idx < num_param_bands_residual; idx++ ) { - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], nchan_out * nchan_out ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], nchan_out * nchan_out ); h_dirac_output_synthesis_state->mixing_matrix_res_len = i_mult( nchan_out, nchan_out ); } - for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = NULL; h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = NULL; } - if ( ( h_dirac_output_synthesis_state->cx_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->cx_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - if ( ( h_dirac_output_synthesis_state->cy_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->cy_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } @@ -163,25 +161,25 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( set16_fx( h_dirac_output_synthesis_state->cx_old_e, 0, CLDFB_NO_CHANNELS_MAX ); set16_fx( h_dirac_output_synthesis_state->cy_old_e, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set16_fx( h_dirac_output_synthesis_state->mixing_matrix_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } @@ -202,6 +200,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } Copy32( proto_matrix, h_dirac_output_synthesis_params->proto_matrix_fx, nchan_in * nchan_out ); h_dirac_output_synthesis_params->proto_matrix_e = 5; + move16(); return IVAS_ERR_OK; } #else @@ -339,8 +338,8 @@ void ivas_dirac_dec_output_synthesis_get_interpolator_fx( FOR( idx = 1; idx <= interp_length; ++idx ) { - tmp = BASOP_Util_Divide3232_Scale( (Word32) idx, (Word32) interp_length, &exp_diff ); // (Q15 - exp_diff) - h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = shl_sat( tmp, exp_diff ); // Q15 + tmp = BASOP_Util_Divide3232_Scale( L_deposit_l( idx ), L_deposit_l( interp_length ), &exp_diff ); // (Q15 - exp_diff) + h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = shl_sat( tmp, exp_diff ); // Q15 move16(); } @@ -390,16 +389,16 @@ void ivas_dirac_dec_output_synthesis_cov_init_fx( /* initialize buffers */ FOR( idx = 0; idx < n_param_bands; idx++ ) { - set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], nchan_in * nchan_in ); - set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], nchan_out * nchan_out ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], nchan_out * nchan_in ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], nchan_out * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], imult1616( nchan_in, nchan_in ) ); + set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], imult1616( nchan_out, nchan_out ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], imult1616( nchan_out, nchan_in ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], imult1616( nchan_out, nchan_in ) ); } FOR( idx = 0; idx < n_param_bands_res; idx++ ) { - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], nchan_out * nchan_out ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], nchan_out * nchan_out ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], imult1616( nchan_out, nchan_out ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], imult1616( nchan_out, nchan_out ) ); } @@ -778,18 +777,16 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( move16(); brange[1] = hParamMC->band_grouping[param_band + 1]; move16(); - num_bands = brange[1] - brange[0]; - move16(); + num_bands = sub( brange[1], brange[0] ); FOR( band_idx = 0; band_idx < num_bands; band_idx++ ) { - band = brange[0] + band_idx; - move16(); + band = add( brange[0], band_idx ); FOR( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) { - real_in_buffer_fx[band_idx + num_bands * ch_idx] = RealBuffer_fx[ch_idx * hParamMC->num_freq_bands + band]; + real_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = RealBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; move32(); - imag_in_buffer_fx[band_idx + num_bands * ch_idx] = ImagBuffer_fx[ch_idx * hParamMC->num_freq_bands + band]; + imag_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = ImagBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; move32(); } } @@ -809,17 +806,17 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( i = 0; i < num_bands * nchan_in; ++i ) { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], output_e - RealBuffer_e ); + real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); move32(); - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], output_e - ImagBuffer_e ); + imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); move32(); } cmplx_matrix_square_fx( real_in_buffer_fx, imag_in_buffer_fx, num_bands, nchan_in, real_buffer_fx, imag_buffer_fx, output_e, &output_e ); - v_add_fixed_me( cx_fx[param_band], *cx_e, real_buffer_fx, output_e, cx_fx[param_band], &tmp1_e, nchan_in * nchan_in, 1 ); + v_add_fixed_me( cx_fx[param_band], *cx_e, real_buffer_fx, output_e, cx_fx[param_band], &tmp1_e, imult1616( nchan_in, nchan_in ), 1 ); - v_add_fixed_me( cx_imag_fx[param_band], *cx_imag_e, imag_buffer_fx, output_e, cx_imag_fx[param_band], &tmp2_e, nchan_in * nchan_in, 1 ); + v_add_fixed_me( cx_imag_fx[param_band], *cx_imag_e, imag_buffer_fx, output_e, cx_imag_fx[param_band], &tmp2_e, imult1616( nchan_in, nchan_in ), 1 ); cx_init_e[param_band] = tmp1_e; move16(); @@ -848,10 +845,10 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) { L_tmp = BASOP_Util_Add_Mant32Exp( cx_fx[i][j], cx_init_e[i], 0, 0, &tmp1_e ); - cx_fx[i][j] = L_shr( L_tmp, tmp1 - tmp1_e ); + cx_fx[i][j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); move32(); L_tmp = BASOP_Util_Add_Mant32Exp( cx_imag_fx[i][j], cx_init_imag_e[i], 0, 0, &tmp2_e ); - cx_imag_fx[i][j] = L_shr( L_tmp, tmp2 - tmp2_e ); + cx_imag_fx[i][j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); move32(); } } @@ -1008,8 +1005,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word16 param_band_idx, band, ch_idx; Word16 have_residual; Word16 brange[2]; - DIRAC_OUTPUT_SYNTHESIS_COV_STATE h_synthesis_state = hParamMC->h_output_synthesis_cov_state; - + DIRAC_OUTPUT_SYNTHESIS_COV_STATE h_synthesis_state; Word32 mixing_matrix_smooth_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; Word16 mixing_matrix_smooth_e; Word32 mixing_matrix_res_smooth_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; @@ -1025,6 +1021,8 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word32 diff_f_real_fx[MAX_CICP_CHANNELS]; Word32 diff_f_imag_fx[MAX_CICP_CHANNELS]; + h_synthesis_state = hParamMC->h_output_synthesis_cov_state; + set_zero_fx( input_f_real_fx, PARAM_MC_MAX_TRANSPORT_CHANS ); set_zero_fx( input_f_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS ); set_zero_fx( output_f_real_fx, MAX_CICP_CHANNELS ); @@ -1039,37 +1037,39 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( move16(); brange[0] = hParamMC->band_grouping[param_band_idx]; move16(); - brange[1] = hParamMC->band_grouping[param_band_idx + 1]; + brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; move16(); - IF( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) + if ( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) { have_residual = 1; move16(); } - v_multc_fixed( mixing_matrix_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_smooth_fx, nY * nX ); + v_multc_fixed( mixing_matrix_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_smooth_fx, imult1616( nY, nX ) ); mixing_matrix_smooth_e = mixing_matrix_e[param_band_idx]; // interpolator is W16 move16(); - v_multc_fixed( h_synthesis_state.mixing_matrix_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nX ); + v_multc_fixed( h_synthesis_state.mixing_matrix_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, imult1616( nY, nX ) ); mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_old_exp[param_band_idx]; // interpolator is W16 + move16(); - v_add_fixed_me( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_smooth_fx, &mixing_matrix_smooth_e, nY * nX, 0 ); + v_add_fixed_me( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_smooth_fx, &mixing_matrix_smooth_e, imult1616( nY, nX ), 0 ); IF( have_residual ) { /* residual mixing matrix interpolation*/ - v_multc_fixed( mixing_matrix_res_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_res_smooth_fx, nY * nY ); + v_multc_fixed( mixing_matrix_res_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_res_smooth_fx, imult1616( nY, nY ) ); mixing_matrix_res_smooth_e = mixing_matrix_res_e[param_band_idx]; // interpolator is W16 + move16(); - set_zero_fx( mixing_matrix_buffer_fx, nY * nY ); - v_multc_fixed( h_synthesis_state.mixing_matrix_res_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nY ); + set_zero_fx( mixing_matrix_buffer_fx, imult1616( nY, nY ) ); + v_multc_fixed( h_synthesis_state.mixing_matrix_res_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, imult1616( nY, nY ) ); mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_res_old_exp[param_band_idx]; // interpolator is W16 + move16(); - - v_add_fixed_me( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_res_smooth_fx, &mixing_matrix_res_smooth_e, nY * nY, 0 ); + v_add_fixed_me( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_res_smooth_fx, &mixing_matrix_res_smooth_e, imult1616( nY, nY ), 0 ); } @@ -1080,7 +1080,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( IF( have_residual ) { /* collect diffuse prototypes */ - assert( band < hParamMC->h_output_synthesis_params.max_band_decorr ); + assert( LT_16( band, hParamMC->h_output_synthesis_params.max_band_decorr ) ); FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; // Q6 @@ -1092,11 +1092,11 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply residual mixing */ matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_real_fx, 25, nY, 1, 0, output_f_real_fx, &output_f_real_e ); - scale_sig32( output_f_real_fx, nY, 6 - ( 31 - output_f_real_e ) ); + scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_imag_fx, 25, nY, 1, 0, output_f_imag_fx, &output_f_imag_e ); - scale_sig32( output_f_imag_fx, nY, 6 - ( 31 - output_f_imag_e ) ); + scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { @@ -1121,9 +1121,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( FOR( ch_idx = 0; ch_idx < nX; ch_idx++ ) { - input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 + input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; // Q6 move32(); - input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; + input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; move32(); } @@ -1140,7 +1140,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add( Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_real_fx[ch_idx] ); + move32(); Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add( Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_imag_fx[ch_idx] ); + move32(); } } } @@ -1436,7 +1438,7 @@ Word16 computeMixingMatrices_fx( Word16 *Cr_e ) { Word16 i, j; - Word16 out = EXIT_SUCCESS; + Word16 out; Word16 nL, nC; Word16 lengthCx = num_inputs; Word16 lengthCy = num_outputs; @@ -1505,6 +1507,8 @@ Word16 computeMixingMatrices_fx( Word32 *Cr_p_fx, *Cy_tilde_p_fx, *Cy_p_fx; push_wmops( "dirac_cov_mix_mat" ); + out = EXIT_SUCCESS; + move16(); set32_fx( svd_s_buffer_fx, 0, MAX_OUTPUT_CHANNELS ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) @@ -1515,9 +1519,9 @@ Word16 computeMixingMatrices_fx( } - Copy32( Q, Q_fx, lengthCy * lengthCx ); - Copy32( Cx, Cx_fx, lengthCx * lengthCx ); - Copy32( Cy, Cy_fx, lengthCy * lengthCy ); + Copy32( Q, Q_fx, imult1616( lengthCy, lengthCx ) ); + Copy32( Cx, Cx_fx, imult1616( lengthCx, lengthCx ) ); + Copy32( Cy, Cy_fx, imult1616( lengthCy, lengthCy ) ); Q_e = Q_fx_e; move16(); @@ -1546,23 +1550,32 @@ Word16 computeMixingMatrices_fx( FOR( j = 0; j < lengthCy; ++j ) { tmp_e = svd_s_buffer_fx_e; + move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); - Ky_fx_e[i + j * lengthCy] = +tmp_e; + Ky_fx[add( i, imult1616( j, lengthCy ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + move32(); + Ky_fx_e[add( i, imult1616( j, lengthCy ) )] = tmp_e; + move16(); } } exp = Ky_fx_e[0]; + move16(); FOR( i = 1; i < lengthCy * lengthCy; i++ ) { - IF( exp < Ky_fx_e[i] ) - exp = Ky_fx_e[i]; + if ( LT_16( exp, Ky_fx_e[i] ) ) + { + exp = Ky_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Ky_fx[i] = L_shr( Ky_fx[i], exp - Ky_fx_e[i] ); + Ky_fx[i] = L_shr( Ky_fx[i], sub( exp, Ky_fx_e[i] ) ); + move32(); Ky_fx_e[i] = exp; + move16(); } @@ -1581,22 +1594,30 @@ Word16 computeMixingMatrices_fx( FOR( j = 0; j < lengthCx; ++j ) { tmp_e = svd_s_buffer_fx_e; + move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Kx_fx[i + j * lengthCx] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); - Kx_fx_e[i + j * lengthCx] = tmp_e; + Kx_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + move32(); + Kx_fx_e[add( i, imult1616( j, lengthCx ) )] = tmp_e; + move16(); } } exp = Kx_fx_e[0]; + move16(); FOR( i = 1; i < lengthCx * lengthCx; i++ ) { - IF( exp < Kx_fx_e[i] ) - exp = Kx_fx_e[i]; + if ( LT_16( exp, Kx_fx_e[i] ) ) + { + exp = Kx_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - Kx_fx[i] = L_shr( Kx_fx[i], exp - Kx_fx_e[i] ); + Kx_fx[i] = L_shr( Kx_fx[i], sub( exp, Kx_fx_e[i] ) ); + move32(); Kx_fx_e[i] = exp; move16(); } @@ -1607,26 +1628,30 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_fx_e; move16(); svd_s_buffer_fx[i] = Sqrt32( svd_s_buffer_fx[i], &tmp_e ); + move32(); svd_s_buffer_e[i] = tmp_e; move16(); } // making the Q common - Word16 max = svd_s_buffer_e[0]; + Word16 max_e; + max_e = svd_s_buffer_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { - IF( max < svd_s_buffer_e[i] ) + if ( LT_16( max_e, svd_s_buffer_e[i] ) ) { - max = svd_s_buffer_e[i]; + max_e = svd_s_buffer_e[i]; move16(); } } FOR( i = 0; i < lengthCx; i++ ) { - svd_s_buffer_fx[i] = L_shr( svd_s_buffer_fx[i], ( max - svd_s_buffer_e[i] ) ); + svd_s_buffer_fx[i] = L_shr( svd_s_buffer_fx[i], ( max_e - svd_s_buffer_e[i] ) ); + move32(); } - svd_s_buffer_fx_e = max; + svd_s_buffer_fx_e = max_e; move16(); @@ -1639,16 +1664,19 @@ Word16 computeMixingMatrices_fx( move16(); L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); - limit_e = limit_e + reg_Sx_e; + limit_e = add( limit_e, reg_Sx_e ); limit_fx = L_add( L_tmp, EPSILON_FX ); FOR( i = 0; i < lengthCx; ++i ) { svd_s_buffer_e[i] = svd_s_buffer_fx_e; + move16(); IF( BASOP_Util_Cmp_Mant32Exp( svd_s_buffer_fx[i], svd_s_buffer_fx_e, limit_fx, limit_e ) < 0 ) { svd_s_buffer_fx[i] = limit_fx; + move32(); svd_s_buffer_e[i] = limit_e; + move16(); } } @@ -1667,11 +1695,13 @@ Word16 computeMixingMatrices_fx( { Word16 scale, reg_fac_fx; reg_fac_fx = BASOP_Util_Divide3232_Scale( 1, svd_s_buffer_fx[i], &scale ); - scale = scale + ( 31 - svd_s_buffer_e[i] ); + scale = add( scale, sub( Q31, svd_s_buffer_e[i] ) ); FOR( j = 0; j < lengthCx; ++j ) { - Kx_reg_inv_fx[i + j * lengthCx] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); - Kx_reg_inv_e[i + j * lengthCx] = scale; + Kx_reg_inv_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); + move32(); + Kx_reg_inv_e[add( i, imult1616( j, lengthCx ) )] = scale; + move16(); } } @@ -1679,14 +1709,17 @@ Word16 computeMixingMatrices_fx( move16(); FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - IF( exp < Kx_reg_inv_e[i] ) - exp = Kx_reg_inv_e[i]; - move16(); + if ( LT_16( exp, Kx_reg_inv_e[i] ) ) + { + exp = Kx_reg_inv_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i] ); + Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], sub( exp, Kx_reg_inv_e[i] ) ); + move32(); Kx_reg_inv_e[i] = exp; move16(); } @@ -1699,27 +1732,30 @@ Word16 computeMixingMatrices_fx( matrix_product_mant_exp_fx( Q_fx, Q_e, lengthCy, lengthCx, 0, Cx_fx, Cx_fx_e, lengthCx, lengthCx, 0, Q_Cx_fx, &Q_Cx_e ); - Word16 guard_bits = find_guarded_bits_fx( lengthCx + 1 ); + Word16 guard_bits; + guard_bits = find_guarded_bits_fx( lengthCx + 1 ); FOR( i = 0; i < lengthCy * lengthCx; ++i ) { - IF( Q_Cx_e > Q_e ) + IF( GT_16( Q_Cx_e, Q_e ) ) { Q_fx[i] = L_shr( Q_fx[i], guard_bits ); + move32(); } ELSE { Q_Cx_fx[i] = L_shr( Q_Cx_fx[i], guard_bits ); + move32(); } } - IF( Q_Cx_e > Q_e ) + IF( GT_16( Q_Cx_e, Q_e ) ) { - Q_e += guard_bits; + Q_e = add( Q_e, guard_bits ); } ELSE { - Q_Cx_e += guard_bits; + Q_Cx_e = add( Q_Cx_e, guard_bits ); } matrix_product_diag_fx( Q_Cx_fx, Q_Cx_e, lengthCy, lengthCx, 0, Q_fx, Q_e, lengthCy, lengthCx, 1, Cy_hat_diag_fx, &Cy_hat_diag_e ); @@ -1737,7 +1773,8 @@ Word16 computeMixingMatrices_fx( L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); limit_fx = L_add( L_tmp, EPSILON_FX ); - limit_e = limit_e + reg_ghat_e; + limit_e = add( limit_e, reg_ghat_e ); + move16(); } @@ -1753,8 +1790,8 @@ Word16 computeMixingMatrices_fx( move16(); } - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &exp ); - exp = exp + ( Cy_fx_e - Cy_hat_diag_buff_e[i] ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], Cy_hat_diag_fx[i], &exp ); + exp = add( exp, sub( Cy_fx_e, Cy_hat_diag_buff_e[i] ) ); L_tmp = Sqrt32( L_deposit_h( tmp ), &exp ); G_hat_fx[i] = L_tmp; move32(); @@ -1766,13 +1803,17 @@ Word16 computeMixingMatrices_fx( move16(); FOR( i = 1; i < lengthCy; i++ ) { - IF( exp < G_hat_buff_e[i] ) - exp = G_hat_buff_e[i]; + if ( LT_16( exp, G_hat_buff_e[i] ) ) + { + exp = G_hat_buff_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy; i++ ) { - G_hat_fx[i] = L_shr( G_hat_fx[i], exp - G_hat_buff_e[i] ); + G_hat_fx[i] = L_shr( G_hat_fx[i], sub( exp, G_hat_buff_e[i] ) ); + move32(); } G_hat_e = exp; @@ -1790,7 +1831,7 @@ Word16 computeMixingMatrices_fx( matrix_product_mant_exp_fx( mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCy, 0, Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); - IF( lengthCx < lengthCy ) + IF( LT_16( lengthCx, lengthCy ) ) { mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 1 ); @@ -1831,7 +1872,9 @@ Word16 computeMixingMatrices_fx( svdMat2mat_fx( svd_u_buffer_fx, mat_mult_buffer2_fx, lengthCx, lengthCx ); mat_mult_buffer1_e = 0; + move16(); mat_mult_buffer2_e = 0; + move16(); matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, @@ -1861,7 +1904,9 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { Cy_fx[i] = L_shr( Cy_p_fx[i], exp - Cy_fx_e ); + move32(); Cy_tilde_p_fx[i] = L_shr( Cy_tilde_p_fx[i], exp - mat_mult_buffer2_e ); + move32(); } Cy_fx_e = exp; move16(); @@ -1872,14 +1917,18 @@ Word16 computeMixingMatrices_fx( FOR( j = 0; j < lengthCy; ++j ) { - *( Cr_p_fx++ ) = *( Cy_p_fx++ ) - *( Cy_tilde_p_fx++ ); + *( Cr_p_fx ) = L_sub( *( Cy_p_fx ), *( Cy_tilde_p_fx ) ); + move32(); + Cr_p_fx++; + Cy_p_fx++; + Cy_tilde_p_fx++; } /* Avoid Meaningless negative main diagonal elements */ - IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[i + i * lengthCy], exp, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[add( i, imult1616( i, lengthCy ) )], exp, 0, 0 ) < 0 ) { - Cr_fx[i + i * lengthCy] = 0; - move16(); + Cr_fx[add( i, imult1616( i, lengthCy ) )] = 0; + move32(); } } @@ -1890,7 +1939,7 @@ Word16 computeMixingMatrices_fx( * Energy Compensation *-----------------------------------------------------------------*/ - IF( energy_compensation_flag == 1 ) + IF( EQ_16( energy_compensation_flag, 1 ) ) { adj_fx_p = svd_s_buffer_fx; Cy_tilde_p_fx = mat_mult_buffer2_fx; @@ -1899,7 +1948,7 @@ Word16 computeMixingMatrices_fx( { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[i + i * lengthCy], mat_mult_buffer2_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], mat_mult_buffer2_e, 0, 0 ) < 0 ) { adj_fx_p[i] = 1073741824; move32(); @@ -1908,8 +1957,8 @@ Word16 computeMixingMatrices_fx( } ELSE { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + lengthCy * i], L_add( Cy_tilde_p_fx[i + i * lengthCy], EPSILON_FX ), &exp ); - exp = exp + ( Cy_fx_e - mat_mult_buffer2_e ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], L_add( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], EPSILON_FX ), &exp ); + exp = add( exp, sub( Cy_fx_e, mat_mult_buffer2_e ) ); L_tmp = L_deposit_h( tmp ); L_tmp = Sqrt32( L_tmp, &exp ); adj_fx_p[i] = L_tmp; @@ -1928,22 +1977,27 @@ Word16 computeMixingMatrices_fx( } exp = adj_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { - IF( exp < adj_e[i] ) - exp = adj_e[i]; + if ( LT_16( exp, adj_e[i] ) ) + { + exp = adj_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], exp - adj_e[i] ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); + move32(); } adj_fx_e = exp; move16(); diag_matrix_product_fx( adj_fx, adj_fx_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCx * lengthCy ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCx, lengthCy ) ); mixing_matrix_e = mat_mult_buffer3_e; move16(); } @@ -2172,9 +2226,11 @@ Word16 computeMixingMatricesResidual_fx( Word16 *mixing_matrix_ret_e ) { Word16 i, j; - Word16 out = EXIT_SUCCESS; - Word16 lengthCx = extract_l( num_outputs ); - Word16 lengthCy = extract_l( num_outputs ); + Word16 out, lengthCx, lengthCy; + out = EXIT_SUCCESS; + move16(); + lengthCx = extract_l( num_outputs ); + lengthCy = extract_l( num_outputs ); Word32 svd_in_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; Word32 mat_mult_buffer2_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; @@ -2189,6 +2245,7 @@ Word16 computeMixingMatricesResidual_fx( Word32 adj_fx[MAX_OUTPUT_CHANNELS]; Word32 mat_mult_buffer3_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; Word16 mixing_matrix_e = 0, mat_mult_buffer1_e, adj_e, mat_mult_buffer3_e, mat_mult_buffer2_e; + move16(); #ifdef MSAN_FIX Word32 svd_s_buffer_fx[MAX_OUTPUT_CHANNELS] = { 0 }; @@ -2243,22 +2300,29 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < lengthCy; ++j ) { tmp_e = svd_s_buffer_fx_e; + move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + move32(); Ky_fx_e[i + j * lengthCy] = tmp_e; + move16(); } } exp = Ky_fx_e[0]; + move16(); FOR( i = 1; i < lengthCy * lengthCy; i++ ) { - IF( exp < Ky_fx_e[i] ) - exp = Ky_fx_e[i]; + if ( LT_16( exp, Ky_fx_e[i] ) ) + { + exp = Ky_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Ky_fx[i] = L_shr( Ky_fx[i], exp - Ky_fx_e[i] ); + Ky_fx[i] = L_shr( Ky_fx[i], sub( exp, Ky_fx_e[i] ) ); Ky_fx_e[i] = exp; move16(); } @@ -2284,15 +2348,20 @@ Word16 computeMixingMatricesResidual_fx( } exp = Kx_fx_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { - IF( exp < Kx_fx_e[i] ) - exp = Kx_fx_e[i]; + if ( LT_16( exp, Kx_fx_e[i] ) ) + { + exp = Kx_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx; i++ ) { Kx_fx[i] = L_shr( Kx_fx[i], exp - Kx_fx_e[i] ); + move32(); Kx_fx_e[i] = exp; move16(); } @@ -2310,24 +2379,26 @@ Word16 computeMixingMatricesResidual_fx( L_tmp = L_add( L_tmp, EPSILLON_FX ); limit_fx = L_tmp; move16(); - limit_e = limit_e + reg_Sx_e; + limit_e = add( limit_e, reg_Sx_e ); FOR( i = 0; i < lengthCx; ++i ) { IF( BASOP_Util_Cmp_Mant32Exp( Kx_fx[i], Kx_fx_e[0], limit_fx, limit_e ) > 0 ) { div_tmp = Kx_fx[i]; + move32(); exp = Kx_fx_e[0]; move16(); } ELSE { div_tmp = limit_fx; + move32(); exp = limit_e; move16(); } tmp = BASOP_Util_Divide3232_Scale( 1073741824, div_tmp, &scale ); - scale = scale + ( 1 - exp ); + scale = add( scale, sub( Q1, exp ) ); Kx_reg_inv_fx[i] = L_deposit_h( tmp ); Kx_reg_inv_e[i] = scale; @@ -2335,15 +2406,20 @@ Word16 computeMixingMatricesResidual_fx( } exp = Kx_reg_inv_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { - IF( exp < Kx_reg_inv_e[i] ) - exp = Kx_reg_inv_e[i]; + if ( LT_16( exp, Kx_reg_inv_e[i] ) ) + { + exp = Kx_reg_inv_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i] ); + Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], sub( exp, Kx_reg_inv_e[i] ) ); + move32(); } Kx_reg_inv_fx_e = exp; move16(); @@ -2365,6 +2441,7 @@ Word16 computeMixingMatricesResidual_fx( /* Computing Cy_hat_diag */ Copy32( Cx_fx, Cy_hat_diag_fx, extract_l( num_outputs ) ); Cy_hat_diag_e = Cx_e; + move16(); FOR( i = 0; i < lengthCy; ++i ) { @@ -2379,12 +2456,13 @@ Word16 computeMixingMatricesResidual_fx( L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); limit_fx = L_add( L_tmp, EPSILON_FX ); - limit_e = limit_e + reg_ghat_e; + limit_e = add( limit_e, reg_ghat_e ); /* Computing G_hat */ FOR( i = 0; i < lengthCy; ++i ) { Cy_hat_diag_fx_e[i] = Cy_hat_diag_e; + move16(); IF( BASOP_Util_Cmp_Mant32Exp( limit_fx, limit_e, Cy_hat_diag_fx[i], Cy_hat_diag_e ) > 0 ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ { Cy_hat_diag_fx[i] = limit_fx; @@ -2393,7 +2471,7 @@ Word16 computeMixingMatricesResidual_fx( move16(); } tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &scale ); - scale = scale + ( Cy_fx_e - Cy_hat_diag_fx_e[i] ); + scale = add( scale, sub( Cy_fx_e, Cy_hat_diag_fx_e[i] ) ); L_tmp = Sqrt32( L_deposit_h( tmp ), &scale ); G_hat_fx[i] = L_tmp; @@ -2410,18 +2488,23 @@ Word16 computeMixingMatricesResidual_fx( { L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); Kx_fx[i] = L_tmp; - Kx_fx_e[i] = Kx_fx_e[i] + G_hat_e[i]; + move32(); + Kx_fx_e[i] = add( Kx_fx_e[i], G_hat_e[i] ); + move16(); } FOR( i = 0; i < num_outputs; i++ ) { - Word32 fac_fx = Kx_fx[i]; + Word32 fac_fx; + fac_fx = Kx_fx[i]; + move32(); FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32( Ky_fx[i + j * num_outputs], fac_fx ); - mat_mult_buffer1_fx[i + j * num_outputs] = L_tmp; - mat_mult_buffer1_buff_e[i + j * num_outputs] = extract_l( L_add( Ky_fx_e[i + j * num_outputs], Kx_fx_e[i] ) ); + L_tmp = Mpy_32_32( Ky_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); + mat_mult_buffer1_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + move32(); + mat_mult_buffer1_buff_e[add( i, imult1616( j, extract_l( num_outputs ) ) )] = extract_l( L_add( Ky_fx_e[add( i, imult1616( j, extract_l( num_outputs ) ) )], Kx_fx_e[i] ) ); } } @@ -2429,22 +2512,21 @@ Word16 computeMixingMatricesResidual_fx( move16(); FOR( i = 1; i < num_outputs * num_outputs; i++ ) { - IF( mat_mult_buffer1_e < mat_mult_buffer1_buff_e[i] ) - mat_mult_buffer1_e = mat_mult_buffer1_buff_e[i]; + if ( LT_16( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ) + { + mat_mult_buffer1_e = mat_mult_buffer1_buff_e[i]; + move16(); + } } FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], mat_mult_buffer1_e - mat_mult_buffer1_buff_e[i] ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); + move32(); } mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 0 ); - /*FOR ( Word32 g = 0; g < lengthCx; g++ ) - { - me2f_buf( ( svd_in_buffer_fx[g] ), mat_mult_buffer1_e, ( svd_in_buffer[g] ), lengthCy ); - }*/ - svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, lengthCx, lengthCy ); /* Actually Processing P */ @@ -2468,13 +2550,17 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs; i++ ) { - Word32 fac_fx = Kx_reg_inv_fx[i]; + Word32 fac_fx; + fac_fx = Kx_reg_inv_fx[i]; + move32(); FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + i * num_outputs], fac_fx ); - mixing_matrix_fx[j + i * num_outputs] = L_tmp; - mixing_matrix_e = mat_mult_buffer1_e + Kx_reg_inv_fx_e; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); + mixing_matrix_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + move32(); + mixing_matrix_e = add( mat_mult_buffer1_e, Kx_reg_inv_fx_e ); + move16(); } } @@ -2490,23 +2576,25 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy * lengthCx; ++i ) { - IF( mat_mult_buffer1_e > mixing_matrix_e ) + IF( GT_16( mat_mult_buffer1_e, mixing_matrix_e ) ) { mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], guard_bits ); + move32(); } ELSE { mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); + move32(); } } - IF( mat_mult_buffer1_e > mixing_matrix_e ) + IF( GT_16( mat_mult_buffer1_e, mixing_matrix_e ) ) { - mixing_matrix_e += guard_bits; + mixing_matrix_e = add( mixing_matrix_e, guard_bits ); } ELSE { - mat_mult_buffer1_e += guard_bits; + mat_mult_buffer1_e = add( mat_mult_buffer1_e, guard_bits ); } matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 1, Cy_tilde_fx, &Cy_tilde_e ); @@ -2519,10 +2607,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; ++i ) { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + lengthCy * i], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); - scale = scale + ( Cy_fx_e - Cy_tilde_e ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( lengthCy, i ) )], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); + scale = add( scale, sub( Cy_fx_e, Cy_tilde_e ) ); adj_fx_p[i] = Sqrt32( L_deposit_h( tmp ), &scale ); adj_buff_e[i] = scale; + move16(); IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) { adj_fx_p[i] = 1073741824; @@ -2533,21 +2622,26 @@ Word16 computeMixingMatricesResidual_fx( } adj_e = adj_buff_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { - IF( adj_e < adj_buff_e[i] ) - adj_e = adj_buff_e[i]; + if ( LT_16( adj_e, adj_buff_e[i] ) ) + { + adj_e = adj_buff_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], adj_e - adj_buff_e[i] ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); + move32(); } diag_matrix_product_fx( adj_fx, adj_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCy * lengthCx ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCy, lengthCx ) ); *mixing_matrix_ret_e = mat_mult_buffer3_e; move16(); @@ -2612,21 +2706,27 @@ Word16 computeMixingMatricesISM_fx( push_wmops( "dirac_cov_mix_mat" ); out = EXIT_SUCCESS; + move32(); lengthCx = num_inputs; + move16(); lengthCy = num_outputs; + move16(); FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - IF( Q_16fx[i] == MAX_16 ) + IF( EQ_16( Q_16fx[i], MAX_16 ) ) { Q_fx[i] = MAX_32; + move32(); } ELSE { Q_fx[i] = L_deposit_h( Q_16fx[i] ); + move32(); } } Q_e = 0; + move16(); set32_fx( svd_s_buffer_fx, 0, MAX_OUTPUT_CHANNELS ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { @@ -2643,6 +2743,7 @@ Word16 computeMixingMatricesISM_fx( set16_fx( temp_e, Cx_diag_e, lengthCx ); v_sqrt_fx( Cx_diag_fx, temp_e, Kx_fx, lengthCx ); Kx_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { Kx_e = s_max( Kx_e, temp_e[i] ); @@ -2650,6 +2751,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCx; i++ ) { Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); + move32(); } /* Regularization of Sx */ @@ -2658,11 +2760,22 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCx; ++i ) { - svd_s_buffer_fx[i] = ( ( Kx_fx[i] > limit_fx ) ? Kx_fx[i] : limit_fx ); + IF( GT_32( Kx_fx[i], limit_fx ) ) + { + svd_s_buffer_fx[i] = Kx_fx[i]; + move32(); + } + ELSE + { + svd_s_buffer_fx[i] = limit_fx; + move32(); + } } svd_s_buffer_fx_e = Kx_e; + move16(); limit_fx = 0; + move32(); /* regularized Kx-1 */ @@ -2670,18 +2783,25 @@ Word16 computeMixingMatricesISM_fx( { IF( svd_s_buffer_fx[i] ) { - Word32 reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, svd_s_buffer_fx[i], &temp_e[i] ); + Word32 reg_fac; + reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, svd_s_buffer_fx[i], &temp_e[i] ); Kx_reg_inv_fx[i] = reg_fac; + move32(); temp_e[i] = sub( temp_e[i], svd_s_buffer_fx_e ); + move16(); } ELSE { - Word32 reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, EPSILON_FX_M, &temp_e[i] ); + Word32 reg_fac; + reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, EPSILON_FX_M, &temp_e[i] ); Kx_reg_inv_fx[i] = reg_fac; + move32(); temp_e[i] = sub( temp_e[i], EPSILON_FX_E ); + move16(); } } Kx_reg_inv_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { Kx_reg_inv_e = s_max( Kx_reg_inv_e, temp_e[i] ); @@ -2689,6 +2809,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCx; i++ ) { Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); + move32(); } /************************ normalization matrix G hat **********************/ @@ -2706,29 +2827,32 @@ Word16 computeMixingMatricesISM_fx( IF( GT_16( Q_Cx_e, Q_e ) ) { Q_fx[i] = L_shr( Q_fx[i], guard_bits ); + move32(); } ELSE { Q_Cx_fx[i] = L_shr( Q_Cx_fx[i], guard_bits ); + move32(); } } IF( GT_16( Q_Cx_e, Q_e ) ) { - Q_e += guard_bits; + Q_e = add( Q_e, guard_bits ); } ELSE { - Q_Cx_e += guard_bits; + Q_Cx_e = add( Q_Cx_e, guard_bits ); } matrix_product_diag_fx( Q_Cx_fx, Q_Cx_e, lengthCy, lengthCx, 0, Q_fx, Q_e, lengthCy, lengthCx, 1, Cy_hat_diag_fx, &Cy_hat_diag_e ); /* Computing Cy_hat_diag */ FOR( i = 0; i < lengthCy; ++i ) { - IF( GT_32( Cy_hat_diag_fx[i], limit_fx ) ) + if ( GT_32( Cy_hat_diag_fx[i], limit_fx ) ) { limit_fx = Cy_hat_diag_fx[i]; + move32(); } } @@ -2737,33 +2861,43 @@ Word16 computeMixingMatricesISM_fx( /* Computing G_hat */ FOR( i = 0; i < lengthCy; ++i ) { - IF( GT_32( limit_fx, Cy_hat_diag_fx[i] ) ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ + if ( GT_32( limit_fx, Cy_hat_diag_fx[i] ) ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ { Cy_hat_diag_fx[i] = limit_fx; + move32(); } IF( Cy_diag_fx[i] ) { IF( Cy_hat_diag_fx[i] ) { G_hat_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_hat_diag_fx[i], &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, Cy_hat_diag_e ) ); + move16(); G_hat_fx[i] = Sqrt32( G_hat_fx[i], &temp_e[i] ); + move32(); } ELSE { G_hat_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], EPSILON_FX_M, &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, EPSILON_FX_E ) ); + move16(); G_hat_fx[i] = Sqrt32( G_hat_fx[i], &temp_e[i] ); + move32(); } } ELSE { G_hat_fx[i] = 0; + move32(); temp_e[i] = 0; + move16(); } // G_hat[i] = sqrtf( Cy_diag[i] / Cy_hat_diag[i] ); } G_hat_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { G_hat_e = s_max( G_hat_e, temp_e[i] ); @@ -2771,6 +2905,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; i++ ) { G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); + move32(); } /************************ Formulate optimal P **********************/ @@ -2787,7 +2922,9 @@ Word16 computeMixingMatricesISM_fx( mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, num_responses, 1 ); nL = num_responses; + move16(); nC = lengthCx; + move16(); svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); } ELSE @@ -2795,7 +2932,9 @@ Word16 computeMixingMatricesISM_fx( mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, num_responses, 0 ); nL = lengthCx; + move16(); nC = num_responses; + move16(); svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); } @@ -2804,8 +2943,10 @@ Word16 computeMixingMatricesISM_fx( /* can be skipped: lambda is always column-truncated identity matrix, so this operation just truncates V to num_input_channel columns */ svdMat2mat_fx( svd_v_buffer_fx, mat_mult_buffer1_fx, num_responses, lengthCx ); mat_mult_buffer1_e = 0; + move16(); svdMat2mat_fx( svd_u_buffer_fx, mat_mult_buffer2_fx, lengthCx, lengthCx ); mat_mult_buffer2_e = 0; + move16(); matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, num_responses, lengthCx, 0, mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); @@ -2829,43 +2970,56 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; ++i ) { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( LT_32( Cy_tilde_p_fx[i + i * lengthCy], 0 ) ) + IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] < 0 ) { adj_fx[i] = MAX_32; + move32(); temp_e[i] = 0; + move16(); } ELSE { IF( Cy_diag_fx[i] ) { - IF( Cy_tilde_p_fx[i + i * lengthCy] ) + IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] ) { - adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[i + i * lengthCy], &temp_e[i] ); + adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, mat_mult_buffer2_e ) ); + move16(); adj_fx[i] = Sqrt32( adj_fx[i], &temp_e[i] ); + move32(); } ELSE { adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], EPSILON_FX_M, &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, EPSILON_FX_E ) ); + move16(); adj_fx[i] = Sqrt32( adj_fx[i], &temp_e[i] ); + move32(); } } ELSE { adj_fx[i] = 0; + move32(); temp_e[i] = 0; + move16(); } } // if ( adj[i] > 4.0f ) - IF( GT_16( BASOP_Util_Cmp_Mant32Exp( adj_fx[i], temp_e[i], MAX_32, 2 ), 0 ) ) + IF( BASOP_Util_Cmp_Mant32Exp( adj_fx[i], temp_e[i], MAX_32, 2 ) > 0 ) { adj_fx[i] = MAX_32; + move32(); temp_e[i] = 2; + move16(); } } adj_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { adj_e = s_max( adj_e, temp_e[i] ); @@ -2873,12 +3027,14 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; i++ ) { adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); + move32(); } diag_matrix_product_fx( adj_fx, adj_e, lengthCy, mixing_matrix_fx, *mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCy * lengthCx ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCy, lengthCx ) ); *mixing_matrix_e = mat_mult_buffer3_e; + move16(); } pop_wmops(); -- GitLab From e6dbe88832c1cb30ea8ea2165f45a9c3ecd1bb65 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 12:15:07 +0530 Subject: [PATCH 49/63] Clang formatting changes --- lib_dec/ivas_dirac_dec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index a740ef159..c5c65c8d1 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -2842,8 +2842,8 @@ void ivas_qmetadata_to_dirac_fx( move16(); } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) @@ -3184,8 +3184,8 @@ void ivas_qmetadata_to_dirac( tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) -- GitLab From 588e13202013b76785ce4f5e7ab9e821bc8a6567 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 12:39:27 +0530 Subject: [PATCH 50/63] Fix for issue 771: Frequency peak for DTX Stereo at lower bitrates and issue 772: Noise Burst for DTX Stereo at lower bitrates with Fs 16kHz --- lib_com/prot.h | 5 + lib_com/tools.c | 24 ++ lib_dec/cng_dec_fx.c | 10 - lib_dec/core_switching_dec.c | 2 +- lib_dec/ivas_core_dec.c | 41 ++- lib_dec/ivas_stereo_cng_dec.c | 470 +++++++++++++--------------------- lib_dec/ivas_stereo_dft_dec.c | 10 +- 7 files changed, 235 insertions(+), 327 deletions(-) diff --git a/lib_com/prot.h b/lib_com/prot.h index 817465058..ed69b9f6e 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -171,6 +171,11 @@ Word32 sum2_f_32_fx( const Word32 *vec, /* i : input vector */ const int16_t lvec, /* i : length of input vector */ Word16 gb ); + +Word32 sum2_32_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *e ); #endif void set_c( diff --git a/lib_com/tools.c b/lib_com/tools.c index 4bb03acc0..6a6ea3d42 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -233,6 +233,30 @@ Word32 sum2_f_32_fx( return tmp; } + +Word32 sum2_32_fx( + const Word32 *vec, /* i : input vector */ + const Word16 lvec, /* i : length of input vector */ + Word16 *e ) +{ + int16_t i; + Word32 tmp; + + tmp = 0; + Word32 var_a = 0; + Word16 exp = 0, exp_tmp; + FOR( i = 0; i < lvec; i++ ) + { + exp_tmp = norm_l( vec[i] ); + var_a = L_shl( vec[i], exp_tmp ); + var_a = Mpy_32_32( var_a, var_a ); + exp_tmp = shl( sub( *e, exp_tmp ), 1 ); + tmp = BASOP_Util_Add_Mant32Exp( tmp, exp, var_a, exp_tmp, &exp ); + } + *e = exp; + + return tmp; +} #endif /*-------------------------------------------------------------------* diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 1c5628c8c..15be52f70 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -684,16 +684,6 @@ void CNG_dec_fx( } } - /* Update the frame length memory */ - st_fx->last_CNG_L_frame = st_fx->L_frame; - move16(); - - IF( NE_32( st_fx->core_brate, SID_1k75 ) ) - { - hTdCngDec->num_ho = m; - move16(); - } - IF( st_fx->Opt_AMR_WB ) { E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index d2d4f6669..7e7bfbd6c 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -340,7 +340,7 @@ ivas_error core_switching_pre_dec_ivas_fx( within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || NE_16( st->last_codec_mode, MODE2 ) ) ) + IF( EQ_16( st->core, ACELP_CORE ) && ( NE_16( st->last_core, ACELP_CORE ) || EQ_16( st->last_codec_mode, MODE2 ) ) ) { st->last_ppp_mode_dec = 0; st->last_nelp_mode_dec = 0; diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 2f9af21ab..6ccf133f1 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -1194,11 +1194,14 @@ ivas_error ivas_core_dec( swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, add( Q11, q ) ); - Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, add( Q11, q ) ); - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, st->prev_Q_bwe_syn ) ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, imult1616( 2, ALLPASSSECTIONS_STEEP ), negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); + IF( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) + { + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); + } + Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); } /*-------------------------------------------------------------------* @@ -1393,8 +1396,8 @@ ivas_error ivas_core_dec( test(); IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && EQ_16( st->core, ACELP_CORE ) && st->hTdCngDec != NULL ) { - Word16 exp, fra; - Word16 gb; + Word16 exp; + Word32 fra; SWITCH( output_frame ) { case L_FRAME8k: @@ -1417,14 +1420,24 @@ ivas_error ivas_core_dec( L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ - gb = find_guarded_bits_fx( output_frame ); - L_tmp = L_add( L_tmp, sum2_f_32_fx( hb_synth_32_fx[n], output_frame, sub( 11, gb ) ) ); + Word16 exp2; + exp = 20; + move16(); + Word32 L_tmp2 = sum2_32_fx( hb_synth_32_fx[n], output_frame, &exp ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, 20, L_tmp2, exp, &exp ); L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); - exp = norm_l( L_tmp ); - fra = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, shl( sub( Q11, 0 ), 1 ) ), exp ); - L_tmp = Mpy_32_16( exp, fra, LG10 ); - st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, 10 ) ); /*Q8*/ + exp2 = norm_l( L_tmp ); + exp = sub( exp, exp2 ); + fra = BASOP_Util_Log2( L_shl_sat( L_tmp, exp2 ) ); + exp2 = norm_l( exp ); + L_tmp = L_shl( exp, exp2 ); + exp = sub( Q31, exp2 ); + L_tmp = BASOP_Util_Add_Mant32Exp( fra, 6, L_tmp, exp, &exp ); + // exp = sub( sub( 30, shl( sub( Q11, 0 ), 1 ) ), exp ); + L_tmp = Mpy_32_16_1( L_tmp, 24660 ); + exp = add( exp, 2 ); + st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, exp - 7 ) ); /*Q8*/ + st->hTdCngDec->last_shb_ener_fx = L_shl_sat( L_tmp, exp - 20 ); /*Q11*/ } } diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 418d04fbf..ddb29199d 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -684,12 +684,11 @@ static void stereo_dft_generate_comfort_noise_fx( Word32 tmp, enr; Word16 q_enr; Word32 shb_shape[L_FRAME16k]; - Word16 q_shb_shape[L_FRAME16k]; + Word16 q_shb_shape; Word32 *ptr0, *ptr1, *ptr2; - Word16 *ptr_q_shb; Word16 dmpf[M + 2], Atmp[M + 2]; Word32 cngNoiseLevel_upd[L_FRAME16k], cngNoiseLevel_hist[L_FRAME16k - 2]; - Word16 q_cng_temp[L_FRAME16k]; + Word16 e_cng_temp[L_FRAME16k]; Word32 *ptr_tmp, *ptr_cng; Word32 E0, E1; Word16 b, q_cngNoiseLevel_upd, q_cngNoiseLevel; @@ -699,32 +698,31 @@ static void stereo_dft_generate_comfort_noise_fx( Word16 scaleMS; Word16 scaleAvg; Word16 LR_ratio; - Word16 factor; + Word32 factor; Word16 alpha; Word32 ftmp; Word16 trigo_dec[STEREO_DFT32MS_N_16k / 2 + 1]; const Word16 *pTrigo; Word16 trigo_step; - Word16 addl_guard_bits; - Word16 max_diff; - /* - * The additional guard bits data is added to tackle very small shb_cng_gain_fx_32. - * One additional guard bit is added for every 6dB post -12dB. - * -12dB in Q11 is (Word32)0xFFFFA000. - * The guard bits are calculated by converting the power of 10 exponent to power of 2 exponent. - */ - addl_guard_bits = s_max( 1, shr( extract_l( L_shr( Mpy_32_16_1( L_sub( (Word32) 0xFFFFA000, st->hTdCngDec->shb_cng_gain_fx_32 ), (Word16) 0x2A85 ), Q11 ) ), 1 ) ); - - move16(); + // Word16 addl_guard_bits; + // Word16 max_diff; + Word32 tmp32_1, tmp32_2; + Word16 q_div, q_sqrt1, q_sqrt2, q_sqrt, sqrt_res; + Word16 q_shift; hFdCngCom = st->hFdCngDec->hFdCngCom; push_wmops( "DFT_CNG" ); - set_val_Word16( dmpf, 0, M + 2 ); - set_val_Word16( Atmp, 0, M + 2 ); + set16_fx( dmpf, 0, M + 2 ); + set16_fx( Atmp, 0, M + 2 ); - set_val_Word32( DFT[chan], 0, STEREO_DFT_BUF_MAX ); + set_zero_fx( DFT[chan], STEREO_DFT_BUF_MAX ); + set32_fx( cngNoiseLevel_upd, 0, L_FRAME16k ); + + q_shift = s_min( getScaleFactor32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN ), sub( hFdCngCom->cngNoiseLevelExp, 27 ) ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, q_shift ); + hFdCngCom->cngNoiseLevelExp = sub( hFdCngCom->cngNoiseLevelExp, q_shift ); enr = 0; /* Eliminates compiler warning. They are always set before they are used */ move32(); @@ -736,25 +734,21 @@ static void stereo_dft_generate_comfort_noise_fx( move32(); lp_noise = 0; move32(); - q_cngNoiseLevel_upd = 0; - move16(); - q_cngNoiseLevel = 0; + q_shb_shape = 0; move16(); IF( EQ_16( chan, 0 ) ) { - pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; + pSideGain = hStereoDft->side_gain_fx + i_mult( STEREO_DFT_NBDIV, STEREO_DFT_BAND_MAX ); FOR( b = 0; b < hStereoDft->nbands; b++ ) { IF( EQ_16( hStereoCng->xfade_frame_counter, 0 ) ) { hStereoDft->g_state_fx[b] = extract_h( *pSideGain++ ); - move16(); } ELSE { hStereoDft->g_state_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, extract_h( *pSideGain++ ) ), mult( A_GFILT_FX, hStereoDft->g_state_fx[b] ) ); - move16(); } IF( hStereoCng->first_SID ) @@ -762,7 +756,6 @@ static void stereo_dft_generate_comfort_noise_fx( IF( hStereoCng->first_SID_after_TD ) { hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); - move16(); } ELSE { @@ -775,41 +768,35 @@ static void stereo_dft_generate_comfort_noise_fx( IF( GT_16( hStereoCng->nr_corr_frames, CORR_INIT ) ) { hStereoCng->cm_fx[b] = extract_h( Mpy_32_32( hStereoCng->c_LR_LT_fx, hStereoCng->c_LR_LT_fx ) ); - move16(); } ELSE { hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); - move16(); } } ELSE { hStereoCng->cm_fx[b] = add( mult( ONE_MINUS_A_GFILT_FX, hStereoCng->coh_fx[b] ), mult( A_GFILT_FX, hStereoCng->cm_fx[b] ) ); - move16(); } } IF( hStereoCng->first_SID_after_TD ) { - Word16 q_div, q_sqrt, q_sqrt2; scaleAvg = 0; move16(); FOR( b = 0; b < hStereoDft->nbands; b++ ) { - Word32 tmp_n, tmp_d, tmp_32, tmp_32_2; - Word16 sqrt_res; - IF( LT_16( hStereoCng->cm_fx[b], (Word32) ( 0x7333 ) ) ) + IF( LT_16( hStereoCng->cm_fx[b], 0x7333 ) ) { - gamma = hStereoCng->cm_fx[b]; + gamma = hStereoCng->cm_fx[b]; /* Q15 */ move16(); - gamma = BASOP_Util_Divide1616_Scale( gamma, sub( MAX_16, gamma ), &q_div ); + gamma = BASOP_Util_Divide1616_Scale( gamma, 32767 - gamma, &q_div ); /* e(q_div) */ q_sqrt2 = q_div + 16; - tmp_32_2 = Sqrt32( gamma, &q_sqrt2 ); - tmp_32 = BASOP_Util_Add_Mant32Exp( gamma, 16 + q_div, sub( MAX_16, mult( hStereoDft->g_state_fx[b], hStereoDft->g_state_fx[b] ) ), 16, &q_sqrt ); - tmp_32 = Sqrt32( tmp_32, &q_sqrt ); - tmp_32 = BASOP_Util_Add_Mant32Exp( tmp_32, q_sqrt, L_negate( tmp_32_2 ), q_sqrt2, &q_sqrt ); - gamma = extract_h( L_shl( tmp_32, q_sqrt ) ); + tmp32_1 = BASOP_Util_Add_Mant32Exp( gamma, add( q_div, 16 ), sub( 32767, mult_r( hStereoDft->g_state_fx[b], hStereoDft->g_state_fx[b] ) ), 16, &q_sqrt1 ); /* e(q_sqrt1) */ + tmp32_1 = Sqrt32( tmp32_1, &q_sqrt1 ); /* e(q_sqrt1) */ + tmp32_2 = Sqrt32( gamma, &q_sqrt2 ); /* e(q_sqrt2) */ + tmp32_1 = BASOP_Util_Add_Mant32Exp( tmp32_1, q_sqrt1, L_negate( tmp32_2 ), q_sqrt2, &q_sqrt1 ); /* e(q_sqrt1) */ + gamma = extract_h( L_shl( tmp32_1, q_sqrt1 ) ); /* Q15 */ } ELSE { @@ -821,25 +808,25 @@ static void stereo_dft_generate_comfort_noise_fx( c = BASOP_Util_Divide3232_Scale( L_add( L_mult( add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ), add( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ), - L_shr( L_mult( gamma, gamma ), 2 ) ), + L_shr( L_mult( gamma, gamma ), 4 ) ), L_add( Mpy_32_32( sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ), sub( ONE_IN_Q13, shr( hStereoDft->g_state_fx[b], 2 ) ) ), - L_shr( L_mult( gamma, gamma ), 2 ) ), + L_shr( L_mult( gamma, gamma ), 4 ) ), &q_div ); q_sqrt = q_div; move16(); sqrt_res = Sqrt16( mult( c, hStereoCng->cm_fx[b] ), &q_sqrt ); // Add 1 to q_sqrt to account for multiplication with 2.0 in float computation. q_sqrt = add( q_sqrt, 1 ); - tmp_n = L_add( L_add( L_shl( 1, sub( Q15, q_div ) ), c ), L_shr( L_deposit_l( sqrt_res ), sub( q_div, q_sqrt ) ) ); + tmp32_1 = L_add( L_add( L_shl( 1, sub( Q15, q_div ) ), c ), L_shr( L_deposit_l( sqrt_res ), sub( q_div, q_sqrt ) ) ); q_sqrt = q_div; move16(); sqrt_res = Sqrt16( mult( c, hStereoCng->cm_fx[b] ), &q_sqrt ); - tmp_d = L_shl( L_add( L_shl( L_deposit_l( mult( c, mult( LR_ratio, LR_ratio ) ) ), q_div ), - L_add( mult( mult( sub( MAX_16, LR_ratio ), sub( MAX_16, LR_ratio ) ), mult( targetGain, targetGain ) ), - L_shl( L_deposit_l( mult( mult( LR_ratio, sub( MAX_16, LR_ratio ) ), mult( targetGain, sqrt_res ) ) ), add( 1, q_sqrt ) ) ) ), // add(1, q_sqrt) to account for multiplication with 2 and also to maintain uniform q. - 2 ); - scaleMS = BASOP_Util_Divide3232_Scale( tmp_n, tmp_d, &q_div ); + tmp32_2 = L_shl( L_add( L_shl( L_deposit_l( mult( c, mult( LR_ratio, LR_ratio ) ) ), q_div ), + L_add( mult( mult( sub( MAX_16, LR_ratio ), sub( MAX_16, LR_ratio ) ), mult( targetGain, targetGain ) ), + L_shl( L_deposit_l( mult( mult( LR_ratio, sub( MAX_16, LR_ratio ) ), mult( targetGain, sqrt_res ) ) ), add( 1, q_sqrt ) ) ) ), // add(1, q_sqrt) to account for multiplication with 2 and also to maintain uniform q. + 2 ); + scaleMS = BASOP_Util_Divide3232_Scale( tmp32_1, tmp32_2, &q_div ); q_sqrt = q_div; move16(); scaleMS = Sqrt16( scaleMS, &q_sqrt ); @@ -852,241 +839,159 @@ static void stereo_dft_generate_comfort_noise_fx( IF( EQ_16( st->cng_type, LP_CNG ) ) { - Word16 q_sqrt, q_div, rshift_shb = 0, rshift_cng; - Word32 min_val; - move16(); - set_val_Word32( cngNoiseLevel_upd, 0, st->L_frame ); + set32_fx( cngNoiseLevel_upd, 0, st->L_frame ); /* Deemphasis */ dmpf[0] = MAX_16; move16(); dmpf[1] = negate( st->preemph_fac ); move16(); - Copy( st->Aq_cng, Atmp, M + 1 ); + mvs2s( st->Aq_cng, Atmp, M + 1 ); conv_fx_32( Atmp, dmpf, cngNoiseLevel_upd, M + 2 ); IF( EQ_16( st->L_frame, L_FRAME ) ) { pTrigo = hStereoDft->dft_trigo_12k8_fx; trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; - move16(); } ELSE { pTrigo = hStereoDft->dft_trigo_16k_fx; trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; - move16(); } - FOR( i = 0; i < shr( st->L_frame, 2 ); i++ ) + FOR( i = 0; i < st->L_frame / 4; i++ ) { - trigo_dec[i] = pTrigo[i * trigo_step]; - move16(); - trigo_dec[sub( shr( st->L_frame, 1 ), i )] = pTrigo[i * trigo_step]; - move16(); + trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[sub( shr( st->L_frame, 1 ), i )] = pTrigo[i_mult( i, trigo_step )]; } - trigo_dec[shr( st->L_frame, 2 )] = pTrigo[shr( st->L_frame, 2 ) * trigo_step]; - move16(); + trigo_dec[shr( st->L_frame, 2 )] = pTrigo[i_mult( shr( st->L_frame, 2 ), trigo_step )]; - rshift_cng = getScaleFactor32( cngNoiseLevel_upd, st->L_frame ); - rshift_cng = sub( find_guarded_bits_fx( st->L_frame ), rshift_cng ); - /* - * The guardbits calculated here are not sufficient for all cases. - * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, - * additional guard bits have to be added. The choice based on existing test vector set is Q2 - */ - rshift_cng = add( rshift_cng, addl_guard_bits ); + Word16 rshift_cng = sub( find_guarded_bits_fx( st->L_frame ), getScaleFactor32( cngNoiseLevel_upd, st->L_frame ) ); v_shr_32( cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, rshift_cng ); - // Input Q to fft will be Q30 - rshift. + q_cngNoiseLevel_upd = sub( Q30, rshift_cng ); + rfft_fx( cngNoiseLevel_upd, trigo_dec, st->L_frame, -1 ); - // v_shr_32(cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, negate(rshift)); + + Word16 shift = sub( getScaleFactor32( cngNoiseLevel_upd, st->L_frame ), 1 ); + scale_sig32( cngNoiseLevel_upd, st->L_frame, shift ); + q_cngNoiseLevel_upd = add( q_cngNoiseLevel_upd, shift ); + set16_fx( e_cng_temp, q_cngNoiseLevel_upd, st->L_frame ); /* Compute 1/|A| */ ptr0 = cngNoiseLevel_upd; ptr1 = ptr0 + 2; ptr2 = ptr1 + 1; - assert( st->lp_ener_fx > 0 ); + assert( GT_32( st->lp_ener_fx, 0 ) ); + // lp_ener_fx will be in Q6 at this point. // So applying appropriate left shift on the denominator. - factor = shr( BASOP_Util_Divide3232_Scale( st->lp_ener_fx, L_shl( st->L_frame, Q6 ), &q_div ), 1 ); /* fixed factor in the loop below */ - factor = Sqrt16( factor, &q_div ); - // there is multiplication with 2.0 that has to be applied on the factor and - // a left shift of q_div as shown in the below two steps. - // factor = shl(factor, add(q_div, 1)); - // q_div = 0; move16(); - // The left shift of q_div and 1 (because of multiplication factor 2.0) is handled below. - // by adjusting q_inv_sqrt. - minimum_abs32_fx( ptr0, st->L_frame, &min_val ); - // q_inv_sqrt = sub( sub( Q31, norm_l( L_abs( min_val ) ) ), add( q_div, 1 ) ); - - /* cngNoiseLevel_upd buffer has Q of ( Q30 - rshift_cng )*/ - FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) - { - // if ((*ptr1 == 0) && (*ptr2 == 0)) - // assert(0); - // assert( (*ptr1 != 0) || (*ptr2 != 0)); - IF( norm_l( *ptr1 ) > rshift_cng && norm_l( *ptr2 ) > rshift_cng ) - { - ftmp = Madd_32_32( Mpy_32_32( L_shl( *ptr1, rshift_cng ), L_shl( *ptr1, rshift_cng ) ), L_shl( *ptr2, rshift_cng ), L_shl( *ptr2, rshift_cng ) ); - q_sqrt = Q2; - } - ELSE - { - ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); - q_sqrt = sub( Q31, sub( shl( sub( Q30, rshift_cng ), 1 ), Q31 ) ); - } + factor = L_shr( BASOP_Util_Divide3232_Scale_cadence( st->lp_ener_fx, L_shl( st->L_frame, Q6 ), &q_div ), 1 ); /* fixed factor in the loop below */ + factor = Sqrt32( factor, &q_div ); + q_div = add( q_div, 1 ); + + Word16 q_tmp; + FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) + { + ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); + assert( GT_32( ftmp, 0 ) ); + q_sqrt = sub( 62, shl( q_cngNoiseLevel_upd, 1 ) ); IF( EQ_32( ftmp, 0 ) ) { - ftmp = EPSILON_FX; - move32(); + ftmp = EPSILLON_FX; q_sqrt = s_max( 0, q_sqrt ); } tmp = ISqrt32( ftmp, &q_sqrt ); - tmp = Mpy_32_16_1( tmp, factor ); - q_cng_temp[i] = sub( add( sub( Q31, q_sqrt ), sub( Q15, add( q_div, 1 ) ) ), Q15 ); - *ptr0++ = tmp; - move32(); + e_cng_temp[i] = sub( 31, add( q_sqrt, q_div ) ); + *ptr0++ = Mpy_32_32( factor, tmp ); ptr1 += 2; ptr2 += 2; } - /* The initial values in the cngNoiseLevel_upd buffer, from index 0 to st->L_frame / 2 - 1, are updated in the for loop above, - with their Q factors stored in q_cng_temp. The values stored after index st->L_frame / 2 - 1 have a Q factor of (Q30 - rshift_cng). - - Calculate the maximum difference between (Q30 - rshift_cng) and the headroom available for the values stored in cngNoiseLevel_upd - for the initial st->L_frame / 2 - 1 value that were updated in the above for loop. - - If the maximum difference is negative, the cngNoiseLevel_upd buffer has enough headroom to accommodate all the values - with a Q factor of (Q30 - rshift_cng). - - - If the maximum difference is positive, some values in the cngNoiseLevel_upd buffer may overflow with a Q factor of - (Q30 - rshift_cng). In this case, scale the cngNoiseLevel_upd buffer to a Q factor of (Q30 - rshift_cng - max_diff) - to prevent overflows. */ - - max_diff = sub( sub( sub( Q30, rshift_cng ), q_cng_temp[0] ), norm_l( cngNoiseLevel_upd[0] ) ); - FOR( i = 1; i < shr( st->L_frame, 1 ) - 1; i++ ) + FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) { - max_diff = s_max( max_diff, sub( sub( sub( Q30, rshift_cng ), q_cng_temp[i] ), norm_l( cngNoiseLevel_upd[i] ) ) ); + q_cngNoiseLevel_upd = s_min( q_cngNoiseLevel_upd, e_cng_temp[i] + norm_l( cngNoiseLevel_upd[i] ) ); } - IF( LT_16( max_diff, 0 ) ) + FOR( i = 0; i < st->L_frame; i++ ) { - FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) - { - cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( sub( Q30, rshift_cng ), q_cng_temp[i] ) ); - } - q_cngNoiseLevel_upd = sub( Q30, rshift_cng ); - } - ELSE - { - FOR( i = 0; i < shr( st->L_frame, 1 ) - 1; i++ ) - { - cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( sub( sub( Q30, rshift_cng ), q_cng_temp[i] ), max_diff ) ); - } - scale_sig32( cngNoiseLevel_upd + shr( st->L_frame, 1 ) - 1, shr( st->L_frame, 1 ) + 1, -max_diff ); - q_cngNoiseLevel_upd = sub( sub( Q30, rshift_cng ), max_diff ); + cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( q_cngNoiseLevel_upd, e_cng_temp[i] ) ); } IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) { /* Transform shb LP spectrum */ - set_val_Word32( shb_shape, 0, L_FRAME16k ); - set_val_Word16( q_shb_shape, 0, L_FRAME16k ); - Copy_Scale_sig_16_32( st->hTdCngDec->shb_lpcCNG_fx, shb_shape, LPC_SHB_ORDER + 1, Q15 ); + set32_fx( shb_shape, 0, L_FRAME16k ); + Copy_Scale_sig_16_32( st->hTdCngDec->shb_lpcCNG_fx, shb_shape, LPC_SHB_ORDER + 1, Q15 ); // Q30 IF( NE_16( st->L_frame, L_FRAME16k ) ) { pTrigo = hStereoDft->dft_trigo_16k_fx; - trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; - move16(); + trigo_step = i_mult( STEREO_DFT_TRIGO_SRATE_16k_STEP, STEREO_DFT_TRIGO_DEC_STEP ); + FOR( i = 0; i < L_FRAME16k / 4; i++ ) { - trigo_dec[i] = pTrigo[i * trigo_step]; - move16(); - trigo_dec[L_FRAME16k / 2 - i] = pTrigo[i * trigo_step]; - move16(); + trigo_dec[i] = pTrigo[i_mult( i, trigo_step )]; + trigo_dec[sub( shr( L_FRAME16k, 1 ), i )] = pTrigo[i_mult( i, trigo_step )]; } - trigo_dec[L_FRAME16k / 4] = pTrigo[L_FRAME16k / 4 * trigo_step]; - move16(); + trigo_dec[shr( L_FRAME16k, 2 )] = pTrigo[i_mult( shr( L_FRAME16k, 2 ), trigo_step )]; } - rshift_shb = getScaleFactor32( shb_shape, L_FRAME16k ); - rshift_shb = sub( find_guarded_bits_fx( L_FRAME16k ), rshift_shb ); - /* - * The guardbits calculated here are not sufficient for all cases. - * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, - * additional guard bits have to be added. The choice based on existing test vector set is Q2 - */ - rshift_shb = add( rshift_shb, addl_guard_bits ); + Word16 rshift_shb = sub( find_guarded_bits_fx( L_FRAME16k ), getScaleFactor32( shb_shape, L_FRAME16k ) ); v_shr_32( shb_shape, shb_shape, L_FRAME16k, rshift_shb ); + q_shb_shape = sub( Q30, rshift_shb ); + rfft_fx( shb_shape, trigo_dec, L_FRAME16k, -1 ); - // v_shr_32(shb_shape, shb_shape, L_FRAME16k, negate(rshift)); + + shift = sub( getScaleFactor32( shb_shape, L_FRAME16k ), 1 ); + scale_sig32( shb_shape, L_FRAME16k, shift ); + q_shb_shape = add( q_shb_shape, shift ); /* Compute 1/|A| */ - enr = Madd_32_32( Mpy_32_32( L_shl( shb_shape[0], addl_guard_bits ), L_shl( shb_shape[0], addl_guard_bits ) ), - L_shl( shb_shape[1], addl_guard_bits ), L_shl( shb_shape[1], addl_guard_bits ) ); - q_enr = add( sub( shl( sub( Q30, rshift_shb ), 1 ), Q31 ), shl( addl_guard_bits, 1 ) ); - IF( EQ_32( enr, 0 ) ) - { - enr = EPSILON_FX; - move32(); - q_enr = s_max( 0, q_enr ); - } + enr = Madd_32_32( Mpy_32_32( shb_shape[0], shb_shape[0] ), shb_shape[1], shb_shape[1] ); + q_enr = sub( 62, shl( q_shb_shape, 1 ) ); ptr0 = shb_shape; ptr1 = ptr0 + 2; ptr2 = ptr1 + 1; FOR( i = 0; i < L_FRAME16k / 2 - 1; i++ ) { - Word16 q_shift = sub( shl( sub( Q30, rshift_shb ), 1 ), Q31 ); - // assert((*ptr1 != 0) || (*ptr2 != 0)); - ftmp = Madd_32_32( Mpy_32_32( L_shl( *ptr1, addl_guard_bits ), L_shl( *ptr1, addl_guard_bits ) ), - L_shl( *ptr2, addl_guard_bits ), L_shl( *ptr2, addl_guard_bits ) ); - q_shift = add( q_shift, shl( addl_guard_bits, 1 ) ); - IF( EQ_32( ftmp, 0 ) ) - { - ftmp = EPSILON_FX; - move32(); - q_shift = s_max( 0, q_shift ); - } - ftmp = L_deposit_l( BASOP_Util_Divide3232_Scale( L_sub( L_shl( Q1, q_shift ), 1 ), ftmp, &q_div ) ); - ftmp = L_shl( ftmp, sub( q_div, sub( Q15, q_shift ) ) ); + ftmp = Madd_32_32( Mpy_32_32( *ptr1, *ptr1 ), *ptr2, *ptr2 ); + q_tmp = sub( shl( q_shb_shape, 1 ), 31 ); + assert( GT_32( ftmp, 0 ) ); + q_div = 0; + ftmp = BASOP_Util_Divide3232_Scale_cadence( L_shl( 1, q_tmp ), ftmp, &q_div ); /* in float: - both a = "div"=(1/(x^2+y^2) and sqrt(a) is used and summed up in the same loop. - - in BASOP: - sum up using inv_sqrt( *ptr1 * *ptr1 + *ptr2 * *ptr2 ), in this loop - and then sum up enr = sum( *ptr0 * *ptr0 ), in a subsequent MAC loop */ - enr = L_add( enr, ftmp ); - q_div = sub( Q31, q_shift ); - ftmp = Sqrt32( ftmp, &q_div ); - // Reduce the Q of shb_shape back to its original Q i.e., Q30 - rshift - ftmp = L_shr( ftmp, sub( sub( Q31, q_div ), sub( Q30, rshift_shb ) ) ); - *ptr0++ = ftmp; - move32(); + both a = "div"=(1/(x^2+y^2) and sqrt(a) is used and summed up in the same loop. + + in BASOP: + sum up using inv_sqrt( *ptr1 * *ptr1 + *ptr2 * *ptr2 ), in this loop + and then sum up enr = sum( *ptr0 * *ptr0 ), in a subsequent MAC loop */ + enr = BASOP_Util_Add_Mant32Exp( enr, q_enr, ftmp, q_div, &q_enr ); + tmp32_1 = Sqrt32( ftmp, &q_div ); + *ptr0++ = L_shl( tmp32_1, sub( q_div, sub( 31, q_shb_shape ) ) ); ptr1 += 2; ptr2 += 2; } } /* Update CNG noise level from MS noise estimation */ - Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); + mvl2l( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); ptr_cng = cngNoiseLevel_hist; - FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < sub( st->last_L_frame, hFdCngCom->startBand ) / 2; i++ ) { - tmp = *( cngNoiseLevel_hist + i * 2 ); - move32(); - tmp = L_add( tmp, *( cngNoiseLevel_hist + i * 2 + 1 ) ); + tmp = *( cngNoiseLevel_hist + shl( i, 1 ) ); + tmp = L_add( tmp, *( cngNoiseLevel_hist + add( shl( i, 1 ), 1 ) ) ); *ptr_cng++ = L_shr( tmp, 1 ); - move32(); } - IF( last_element_mode == IVAS_CPE_TD && chan == 0 && hStereoCng->xfade_frame_counter == 0 && !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + IF( EQ_16( last_element_mode, IVAS_CPE_TD ) && EQ_16( chan, 0 ) && EQ_16( hStereoCng->xfade_frame_counter, 0 ) && GE_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) { ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; FOR( i = 0; i < shr( sub( st->last_L_frame, hFdCngCom->startBand ), 1 ); i++ ) { E0 = L_add( E0, *ptr_cng++ ); - E1 = Madd_32_32( E1, ( *ptr_tmp ), ( *ptr_tmp ) ); + E1 = L_add( E1, Mpy_32_32( ( *ptr_tmp ), ( *ptr_tmp ) ) ); ptr_tmp++; } @@ -1124,55 +1029,41 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) { - Word16 shift_val = sub( Q31, q_cngNoiseLevel_upd ); /* low band */ - ptr_level = cngNoiseLevel_upd; - ptr_r = DFT[chan] + hFdCngCom->startBand + k * STEREO_DFT32MS_N_MAX; + ptr_level = cngNoiseLevel_upd; // Q(q_cngNoiseLevel_upd) + ptr_r = DFT[chan] + add( hFdCngCom->startBand, i_mult( k, STEREO_DFT32MS_N_MAX ) ); // Q(q_dft) ptr_i = ptr_r + 1; scale = shr( output_frame, 1 ); - FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) + FOR( i = 0; i < ( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2; i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); - // the Q factor of ptr_level is q_cngNoiseLevel_upd - // To ensure the result of the multiplication is with optimal precision - // apply left shift on the input data and use it for multiplication - // result of multiplication will be in same Q as ptr_r buffer - tmp = imult3216( ( *ptr_r ), scale ); - IF( GE_16( norm_l( tmp ), shift_val ) ) - { - ( *ptr_r ) = Mpy_32_32( L_shl( tmp, shift_val ), *ptr_level ); - move32(); - } - ELSE + tmp32_1 = Mpy_32_16_1( *ptr_level, scale ); // Q(q_cngNoiseLevel_upd - 15) + q_shift = norm_l( tmp32_1 ); + IF( GT_16( q_shift, sub( 46, q_cngNoiseLevel_upd ) ) ) { - ( *ptr_r ) = L_shl( Mpy_32_32( tmp, *ptr_level ), shift_val ); - move32(); + q_shift = sub( 46, q_cngNoiseLevel_upd ); } + tmp32_1 = L_shl( tmp32_1, q_shift ); + q_shift = sub( sub( 46, q_cngNoiseLevel_upd ), q_shift ); + + ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); ptr_r += 2; + /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - tmp = imult3216( ( *ptr_i ), scale ); - move32(); - IF( GE_16( norm_l( tmp ), shift_val ) ) - { - ( *ptr_i ) = Mpy_32_32( L_shl( tmp, shift_val ), *ptr_level ); - } - ELSE - { - ( *ptr_i ) = L_shl( Mpy_32_32( tmp, *ptr_level ), shift_val ); - } + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); ptr_i += 2; ptr_level++; } IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) { - Word16 q_res = 0; Word32 scale_32; + Word16 q_res; /* high band generation, flipped spectrum */ - assert( enr != 0 ); + assert( NE_32( enr, 0 ) ); // 10 ^ (0.1 * st->hTdCngDec->shb_cng_gain) // Above expression equivalent to 2 ^ (3.321928094 * 0.1 * st->hTdCngDec->shb_cng_gain) // 3.321928094 * 0.1 = 0.3321928094 @@ -1184,63 +1075,71 @@ static void stereo_dft_generate_comfort_noise_fx( move16(); scale = BASOP_Util_Divide3232_Scale( scale_32, enr, &q_div ); // q_res = add(q_div, sub( q_enr, sub(Q31, q_res))); move16(); - q_res = sub( Q15, add( sub( Q15, q_div ), sub( sub( Q31, q_res ), q_enr ) ) ); - move16(); + q_res = q_res - q_enr + q_div; // q_div = sub(Q15, q_res); move16(); q_div = q_res; inv_scale = ISqrt16( scale, &q_res ); scale = Sqrt16( scale, &q_div ); - ptr_shb = shb_shape + L_FRAME16k / 2 - 1; - ptr_q_shb = q_shb_shape + L_FRAME16k / 2 - 1; + ptr_shb = shb_shape + sub( shr( L_FRAME16k, 1 ), 1 ); /* Averaging for Nyquist frequency */ - tmp = Mpy_32_16_1( cngNoiseLevel_upd[sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 )], inv_scale ); - // q of cngNoiseLevel_upd is Q16. - // ptr_shb will be in Q30 - rshift. tmp is in Q16(Q15 + 1 (for the 0.5 in multiplication)) - q_res, Applying appropriate shift on tmp - q_res = sub( sub( Q30, rshift_cng ), sub( Q16, q_res ) ); - IF( LT_16( q_res, norm_l( tmp ) ) ) + Word16 q1, q2; + tmp32_1 = Mpy_32_16_1( cngNoiseLevel_upd[sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 )], inv_scale ); + tmp32_2 = *( ptr_shb - 1 ); + q1 = sub( add( q_cngNoiseLevel_upd, 1 ), q_res ); + q2 = q_shb_shape; + *ptr_shb = BASOP_Util_Add_Mant32Exp( tmp32_1, sub( Q31, q1 ), tmp32_2, sub( Q31, q2 ), &q_tmp ); + q_tmp = sub( q_tmp, 1 ); + IF( LT_16( sub( Q31, q_tmp ), q_shb_shape ) ) { - tmp = L_shl( tmp, q_res ); - q_res = 0; - move16(); + scale_sig32( shb_shape, L_FRAME16k, sub( sub( Q31, q_tmp ), q_shb_shape ) ); + q_shb_shape = sub( Q31, q_tmp ); } - *ptr_q_shb = q_res; - move16(); - // Bring both ptr_shb and ptr_shb - 1 to the same Q. - *ptr_shb = L_shr( L_add( tmp, L_shr( *( ptr_shb - 1 ), sub( q_res, *( ptr_q_shb - 1 ) ) ) ), 1 ); - move32(); - ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + *ptr_shb = L_shl( *ptr_shb, sub( q_shb_shape, sub( Q31, q_tmp ) ) ); + + // *ptr_shb = 0.5f * ( cngNoiseLevel_upd[( hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 - 1] / scale + *( ptr_shb - 1 ) ); + + ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + i_mult( k, STEREO_DFT32MS_N_MAX ); ptr_i = ptr_r + 1; - FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) + FOR( i = 0; i < shr( sub( s_min( output_frame, i_mult( hFdCngCom->regularStopBand, 16 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); - // ptr_shb will be in Q30 - rshift at this point. So apply left shift by 1 to compensate Mpy_32_32 right shift.. - ( *ptr_r ) = W_extract_l( W_shl( W_mult0_32_32( *ptr_r, *ptr_shb ), sub( add( rshift_shb, add( 1, *ptr_q_shb ) ), 31 ) ) ); - move32(); + tmp32_1 = *ptr_shb; + q_shift = norm_l( tmp32_1 ); + IF( GT_16( q_shift, sub( 31, q_shb_shape ) ) ) + { + q_shift = sub( 31, q_shb_shape ); + } + tmp32_1 = L_shl( tmp32_1, q_shift ); + q_shift = sub( sub( 31, q_shb_shape ), q_shift ); + + ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = W_extract_l( W_shl( W_mult0_32_32( *ptr_i, *ptr_shb ), sub( add( rshift_shb, add( 1, *ptr_q_shb ) ), 31 ) ) ); - move32(); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); ptr_i += 2; ptr_shb--; } /* rescale */ - // scale = L_shr(imult3216(scale, output_frame) , 1); - // multiplication with shr(output_frame, 1) is carried out below. - ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + tmp32_1 = L_mult0( scale, shr( output_frame, 1 ) ); + q_shift = norm_l( tmp32_1 ); + IF( GT_16( q_shift, add( Q16, q_div ) ) ) + { + q_shift = add( Q16, q_div ); + } + tmp32_1 = L_shl( tmp32_1, q_shift ); + q_shift = sub( add( Q16, q_div ), q_shift ); + + ptr_r = DFT[chan] + add( hFdCngCom->stopFFTbin, i_mult( k, STEREO_DFT32MS_N_MAX ) ); ptr_i = ptr_r + 1; - FOR( i = 0; i < shr( sub( s_min( output_frame, shl( hFdCngCom->regularStopBand, 4 ) ), hFdCngCom->stopFFTbin ), 1 ); i++ ) + FOR( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) { - ( *ptr_r ) = W_extract_l( W_shl( W_mult0_32_32( Mpy_32_16_1( *ptr_r, scale ), shr( output_frame, 1 ) ), q_div ) ); - move32(); - move32(); - ( *ptr_i ) = W_extract_l( W_shl( W_mult0_32_32( Mpy_32_16_1( *ptr_i, scale ), shr( output_frame, 1 ) ), q_div ) ); - move32(); - move32(); + ( *ptr_r ) = L_shl( Mpy_32_32( ( *ptr_r ), tmp32_1 ), q_shift ); + ( *ptr_i ) = L_shl( Mpy_32_32( ( *ptr_i ), tmp32_1 ), q_shift ); ptr_r += 2; ptr_i += 2; } @@ -1250,29 +1149,21 @@ static void stereo_dft_generate_comfort_noise_fx( /* Expand cngNoiseLevel_flt from 0-159 to 0-318, compute noise level */ lp_noise = 0; move32(); - ptr_level = hFdCngCom->cngNoiseLevel + sub( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); + ptr_level = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, add( hFdCngCom->startBand, 1 ) ); ptr_tmp = cngNoiseLevel_upd + sub( shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ), 1 ); - rshift_cng = sub( sub( 31, hFdCngCom->cngNoiseLevelExp ), sub( shl( q_cngNoiseLevel_upd, 1 ), Q31 ) ); + + q_tmp = s_max( hFdCngCom->cngNoiseLevelExp, shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ) ); + scale_sig32( hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( hFdCngCom->cngNoiseLevelExp, q_tmp ) ); + hFdCngCom->cngNoiseLevelExp = q_tmp; + FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) { - IF( norm_l( *ptr_tmp ) >= rshift_cng ) - { - *ptr_level-- = Mpy_32_32( L_shl( *ptr_tmp, rshift_cng ), *ptr_tmp ); - move32(); - } - ELSE - { - *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), rshift_cng ); - move32(); - } - + *ptr_level-- = L_shl( Mpy_32_32( *ptr_tmp, *ptr_tmp ), sub( shl( sub( Q31, q_cngNoiseLevel_upd ), 1 ), hFdCngCom->cngNoiseLevelExp ) ); ptr_tmp--; *ptr_level = *( ptr_level + 1 ); move32(); - lp_noise = L_add( lp_noise, L_shl( *ptr_level--, 1 ) ); + lp_noise = L_add( lp_noise, L_shl( *ptr_level--, add( 1, sub( Q6, sub( Q31, hFdCngCom->cngNoiseLevelExp ) ) ) ) ); } - // q_cngNoiseLevel = sub(shl(q_cngNoiseLevel_upd, 1), Q31); - // hFdCngCom->q_cngNoiseLevel = q_cngNoiseLevel; move16(); } ELSE { @@ -1286,19 +1177,18 @@ static void stereo_dft_generate_comfort_noise_fx( move16(); FOR( k = 0; k < ( hFdCngCom->nFFTpart - 2 ); k++ ) { - Word16 q_div; - factor = BASOP_Util_Divide3232_Scale( ( hFdCngCom->sidNoiseEstLp[k] + DELTA_FX ), ( st->hFdCngDec->partNoiseShape[k] + DELTA_FX ), &q_div ); - factor = s_min( add( hStereoDft->scale_fx, extract_l( Mpy_32_16_1( L_mult( sub( factor, hStereoDft->scale_fx ), hStereoCng->xfade_frame_counter ), ONE_BY_MAX_K ) ) ), factor ); + factor = BASOP_Util_Divide3232_Scale_cadence( ( hFdCngCom->sidNoiseEstLp[k] + DELTA_FX ), ( st->hFdCngDec->partNoiseShape[k] + DELTA_FX ), &q_div ); + factor = s_min( add( hStereoDft->scale_fx, extract_l( Mpy_32_16_1( L_mult( sub( extract_h( factor ), hStereoDft->scale_fx ), hStereoCng->xfade_frame_counter ), ONE_BY_MAX_K ) ) ), extract_h( factor ) ); FOR( ; j <= hFdCngCom->part[k]; j++ ) { - hFdCngCom->cngNoiseLevel[j] = Mpy_32_16_1( st->hFdCngDec->bandNoiseShape[j], factor ); + hFdCngCom->cngNoiseLevel[j] = Mpy_32_32( st->hFdCngDec->bandNoiseShape[j], factor ); move32(); } } } } scale = shr( output_frame, 1 ); - numSlots = shr( hFdCngCom->numSlots, 2 ); + numSlots = shr( hFdCngCom->numSlots, 1 ); FOR( k = 0; k < STEREO_DFT_NBDIV; k++ ) { ptr_level = hFdCngCom->cngNoiseLevel; @@ -1307,7 +1197,6 @@ static void stereo_dft_generate_comfort_noise_fx( q_cngNoiseLevel = sub( Q31, hFdCngCom->cngNoiseLevelExp ); FOR( i = 0; i < shr( sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ), 1 ); i++ ) { - Word16 q_sqrt; /* Real part in FFT bins */ tmp = *ptr_level++; move32(); @@ -1316,14 +1205,13 @@ static void stereo_dft_generate_comfort_noise_fx( rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); q_sqrt = sub( Q31, q_cngNoiseLevel ); tmp = Sqrt32( tmp, &q_sqrt ); - tmp = Mpy_32_32( *( ptr_r ), tmp ); - tmp = imult3216( tmp, scale ); - ( *ptr_r ) = L_shl( tmp, q_sqrt ); + *( ptr_r ) = imult3216( Mpy_32_32( *( ptr_r ), tmp ), scale ); + ( *ptr_r ) = L_shl( ( *ptr_r ), q_sqrt ); move32(); ptr_r += 2; /* Imaginary part in FFT bins */ rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); - ( *ptr_i ) = Mpy_32_32( ( *ptr_i ), tmp ); + ( *ptr_i ) = L_shl( imult3216( Mpy_32_32( ( *ptr_i ), tmp ), scale ), q_sqrt ); move32(); ptr_i += 2; } @@ -1334,16 +1222,8 @@ static void stereo_dft_generate_comfort_noise_fx( { FOR( i = 0; i < numSlots; i++ ) { -#ifndef MSAN_FIX - Word16 q_sqrt; -#else - Word16 q_sqrt = hFdCngCom->cngNoiseLevelExp; -#endif /* Real part in FFT bins */ rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); -#ifdef MSAN_FIX - q_sqrt = sub( Q31, q_cngNoiseLevel ); -#endif tmp = Mpy_32_16_1( Sqrt32( *ptr_level, &q_sqrt ), scale ); ( *ptr_r ) = Mpy_32_32( *ptr_r, tmp ); move32(); @@ -1421,7 +1301,7 @@ static void stereo_dft_generate_comfort_noise_fx( { alpha = (Word16) ( 0x799A ); move16(); - IF( GT_32( st->hFdCngDec->smoothed_psd_fx[i], 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], l_shift_val ) ) ) + IF( GT_32( st->hFdCngDec->smoothed_psd_fx[i], 0 ) && GT_32( Mpy_32_16_1( ftmp, (Word16) 0x3333 ), L_shr_sat( st->hFdCngDec->smoothed_psd_fx[i], l_shift_val ) ) ) { /* prevent abrupt upward update steps */ ftmp = L_add( L_shl( st->hFdCngDec->smoothed_psd_fx[i], 2 ), L_shr( st->hFdCngDec->smoothed_psd_fx[i], 1 ) ); diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index 0ed260376..daa92a594 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -789,13 +789,9 @@ void stereo_dft_dec_analyze_fx( zp = NS2SA( inputFs, STEREO_DFT32MS_ZP_NS ); ovl = NS2SA( inputFs, STEREO_DFT32MS_OVL_NS ); NFFT = NS2SA( inputFs, STEREO_DFT32MS_N_NS ); - Word16 w1, w2, qw1, qw2, qfac_fx; - qw1 = norm_s( hStereoDft->NFFT ); - qw2 = norm_s( NFFT ); - w1 = shl( hStereoDft->NFFT, qw1 - 1 ); - w2 = shl( NFFT, qw2 ); - fac_fx = L_shl( div_s( w1, w2 ), 16 ); - qfac_fx = 31 - ( qw2 - ( qw1 - 1 ) ); + Word16 qfac_fx; + fac_fx = BASOP_Util_Divide3232_Scale_cadence( hStereoDft->NFFT, NFFT, &qfac_fx ); + qfac_fx = sub( 31, qfac_fx ); ovl2 = NS2SA( inputFs, STEREO_DFT32MS_OVL2_NS ); /* Offset FOR the time buffers */ -- GitLab From 9bd31f5a3dda1edd6c867eb2d05c0906e7526f92 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 14:01:37 +0530 Subject: [PATCH 51/63] EVS BE issue fix --- lib_dec/cng_dec_fx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index 15be52f70..2b938920f 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -684,6 +684,17 @@ void CNG_dec_fx( } } + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + { + st_fx->last_CNG_L_frame = st_fx->L_frame; + move16(); + + IF( NE_32( st_fx->core_brate, SID_1k75 ) ) + { + hTdCngDec->num_ho = m; + move16(); + } + } IF( st_fx->Opt_AMR_WB ) { E_LPC_f_isp_a_conversion( st_fx->lspCNG_fx, Aq, M ); -- GitLab From 2e7c99a987c654e161ea331b159233c5fb02e2be Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 19 Jun 2024 16:28:50 -0400 Subject: [PATCH 52/63] proposal for #800 --- lib_com/mslvq_com_fx.c | 4 ++++ lib_com/options.h | 1 + 2 files changed, 5 insertions(+) diff --git a/lib_com/mslvq_com_fx.c b/lib_com/mslvq_com_fx.c index cad23d0fb..9a5014b4f 100644 --- a/lib_com/mslvq_com_fx.c +++ b/lib_com/mslvq_com_fx.c @@ -1277,7 +1277,11 @@ void deindex_lvq_SHB_fx( { Word32 temp = Mpy_32_16_1( sigma_BWE_fx[mode * LATTICE_DIM + i], scale ); temp = Mpy_32_16_1( temp, out[i] ); +#ifndef FIX_800_PROPOSAL_HB_LPC_COEFFICIENT out[i] = extract_h( temp ); +#else + out[i] = extract_l( temp ); /* Q15 output*/ +#endif // out[i] *= scale * sigma_BWE_fx[mode * LATTICE_DIM + i]; } } diff --git a/lib_com/options.h b/lib_com/options.h index 5a6238041..7929f9a6d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -146,6 +146,7 @@ #define FIX_778_STEREO_BRATE_SWITCHING #define FIX_774_ENERGY_BURST /* Fix 0 bit BWE */ #define FIX_729_MISSING_RESCALING +#define FIX_800_PROPOSAL_HB_LPC_COEFFICIENT /* Proposal to fix wrong shape of TDBWE, #800 */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ -- GitLab From 5a7b3eb1e19cf1995f11d3b446bc5e160e715493 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 21 Jun 2024 12:28:56 +0530 Subject: [PATCH 53/63] Integration of ivas_entropy_coder_common.c and ivas_omasa_com.c funcs [x] Integration of all the functions present in ivas_entropy_coder_common.c and ivas_omasa_com.c except ivas_get_stereo_panning_gains in lib_enc --- lib_com/cnst.h | 2 +- lib_com/ivas_entropy_coder_common.c | 428 +++++++++++++++++++++++----- lib_com/ivas_omasa_com.c | 80 ++++-- lib_com/ivas_prot_fx.h | 77 +++++ lib_com/ivas_stat_com.h | 2 +- lib_com/ivas_tools.c | 14 + lib_dec/ivas_core_dec.c | 2 +- lib_dec/ivas_entropy_decoder.c | 7 + lib_dec/ivas_init_dec.c | 3 +- lib_dec/ivas_masa_dec.c | 2 +- lib_dec/ivas_omasa_dec.c | 15 +- lib_dec/ivas_spar_md_dec.c | 4 +- lib_dec/ivas_stereo_dft_dec_fx.c | 2 +- lib_enc/ivas_core_enc.c | 14 + lib_enc/ivas_entropy_coder.c | 7 + lib_enc/ivas_init_enc.c | 10 + lib_enc/ivas_ism_metadata_enc.c | 16 ++ lib_enc/ivas_masa_enc.c | 17 ++ lib_enc/ivas_omasa_enc.c | 14 + lib_enc/ivas_sce_enc.c | 5 + lib_enc/ivas_spar_md_enc.c | 9 +- lib_enc/lib_enc.c | 7 +- 22 files changed, 625 insertions(+), 112 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 890f1b017..7dde79cee 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -575,7 +575,7 @@ enum #define FRAMES_PER_SEC 50 #ifdef IVAS_FLOAT_FIXED #define MAX_PARAM_SPATIAL_SUB_FRAMES_PER_SEC 200 //(FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) -#define ONE_BY_FRAMES_PER_SEC ((Word32)(0x028F5C29)) +#define ONE_BY_FRAMES_PER_SEC_Q31 ((Word32)(0x028F5C29)) #define FRAMES_PER_SEC_BY_2 (FRAMES_PER_SEC >> 1) #endif #define INV_FRAME_PER_SEC_Q15 656 diff --git a/lib_com/ivas_entropy_coder_common.c b/lib_com/ivas_entropy_coder_common.c index 9dcf13060..69ceb4fff 100644 --- a/lib_com/ivas_entropy_coder_common.c +++ b/lib_com/ivas_entropy_coder_common.c @@ -48,7 +48,31 @@ * wrap around *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_wrap_arround( + int16_t *pArr, + const int16_t min_val, + const int16_t max_val, + const int16_t length ) +{ + int16_t i; + + for ( i = 0; i < length; i++ ) + { + if ( pArr[i] < min_val ) + { + pArr[i] = max_val - min_val + pArr[i] + 1; + } + if ( pArr[i] > max_val ) + { + pArr[i] = min_val + pArr[i] - max_val - 1; + } + } + + return; +} +#else +void ivas_wrap_arround_fx( Word16 *pArr, const Word16 min_val, const Word16 max_val, @@ -61,15 +85,18 @@ void ivas_wrap_arround( IF( LT_16( pArr[i], min_val ) ) { pArr[i] = add( sub( max_val, min_val ), add( pArr[i], 1 ) ); + move16(); } IF( GT_16( pArr[i], max_val ) ) { pArr[i] = sub( add( min_val, pArr[i] ), add( max_val, 1 ) ); + move16(); } } return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -78,7 +105,25 @@ void ivas_wrap_arround( * get cumulative frequency model *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_get_cum_freq_model( + const int16_t *pFreq_model, + const int16_t length, + int16_t *pCum_freq_model ) +{ + int16_t i; + + pCum_freq_model[length] = 0; + + for ( i = length; i > 0; i-- ) + { + pCum_freq_model[i - 1] = pCum_freq_model[i] + pFreq_model[i]; + } + + return; +} +#else +void ivas_get_cum_freq_model_fx( const Word16 *pFreq_model, const Word16 length, Word16 *pCum_freq_model ) @@ -86,14 +131,17 @@ void ivas_get_cum_freq_model( Word16 i; pCum_freq_model[length] = 0; + move16(); FOR( i = length; i > 0; i-- ) { pCum_freq_model[i - 1] = add( pCum_freq_model[i], pFreq_model[i] ); + move16(); } return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -102,29 +150,87 @@ void ivas_get_cum_freq_model( * Map the ivas_arith_pred_r_consts and ivas_huff_pred_r_consts tables *-----------------------------------------------------------------------------------------*/ -Word16 ivas_map_num_pred_r_to_idx( +#ifndef IVAS_FLOAT_FIXED +int16_t ivas_map_num_pred_r_to_idx( + const int16_t num_quant_points_pred_r, + const int16_t active_w_flag ) +{ + int16_t pred_r_to_idx = -1; + if ( active_w_flag == 0 ) + { + switch ( num_quant_points_pred_r ) + { + case 1: + pred_r_to_idx = PRED_Q_1; + break; + case 7: + pred_r_to_idx = PRED_Q_7; + break; + case 15: + pred_r_to_idx = PRED_Q_15; + break; + case 21: + pred_r_to_idx = PRED_Q_21; + break; + case 31: + pred_r_to_idx = PRED_Q_31; + break; + default: + assert( !"Forbidden value for prediction quantization strategy index" ); + break; + } + } + else + { + switch ( num_quant_points_pred_r ) + { + case 7: + pred_r_to_idx = PRED_Q_7_ACTIVE_W; + break; + case 15: + pred_r_to_idx = PRED_Q_15_ACTIVE_W; + break; + case 21: + pred_r_to_idx = PRED_Q_21_ACTIVE_W; + break; + default: + assert( !"Forbidden value for prediction quantization strategy index" ); + break; + } + } + + return pred_r_to_idx; +} +#else +Word16 ivas_map_num_pred_r_to_idx_fx( const Word16 num_quant_points_pred_r, const Word16 active_w_flag ) { Word16 pred_r_to_idx = -1; - IF( EQ_16( active_w_flag, 0 ) ) + move16(); + IF( active_w_flag == 0 ) { SWITCH( num_quant_points_pred_r ) { case 1: pred_r_to_idx = PRED_Q_1; + move16(); BREAK; case 7: pred_r_to_idx = PRED_Q_7; + move16(); BREAK; case 15: pred_r_to_idx = PRED_Q_15; + move16(); BREAK; case 21: pred_r_to_idx = PRED_Q_21; + move16(); BREAK; case 31: pred_r_to_idx = PRED_Q_31; + move16(); BREAK; default: assert( !"Forbidden value for prediction quantization strategy index" ); @@ -137,12 +243,15 @@ Word16 ivas_map_num_pred_r_to_idx( { case 7: pred_r_to_idx = PRED_Q_7_ACTIVE_W; + move16(); BREAK; case 15: pred_r_to_idx = PRED_Q_15_ACTIVE_W; + move16(); BREAK; case 21: pred_r_to_idx = PRED_Q_21_ACTIVE_W; + move16(); BREAK; default: assert( !"Forbidden value for prediction quantization strategy index" ); @@ -152,6 +261,7 @@ Word16 ivas_map_num_pred_r_to_idx( return pred_r_to_idx; } +#endif /*-----------------------------------------------------------------------------------------* @@ -160,23 +270,54 @@ Word16 ivas_map_num_pred_r_to_idx( * Map the ivas_arith_drct_r_consts and ivas_huff_drct_r_consts tables *-----------------------------------------------------------------------------------------*/ -Word16 ivas_map_num_drct_r_to_idx( +#ifndef IVAS_FLOAT_FIXED +int16_t ivas_map_num_drct_r_to_idx( + const int16_t num_quant_points_drct_r ) +{ + int16_t drct_r_to_idx = -1; + switch ( num_quant_points_drct_r ) + { + case 1: + drct_r_to_idx = DRCT_Q_1; + break; + case 7: + drct_r_to_idx = DRCT_Q_7; + break; + case 9: + drct_r_to_idx = DRCT_Q_9; + break; + case 11: + drct_r_to_idx = DRCT_Q_11; + break; + default: + assert( !"Forbidden value for DRCT quantization strategy index" ); + break; + } + return drct_r_to_idx; +} +#else +Word16 ivas_map_num_drct_r_to_idx_fx( const Word16 num_quant_points_drct_r ) { Word16 drct_r_to_idx = -1; + move16(); SWITCH( num_quant_points_drct_r ) { case 1: drct_r_to_idx = DRCT_Q_1; + move16(); BREAK; case 7: drct_r_to_idx = DRCT_Q_7; + move16(); BREAK; case 9: drct_r_to_idx = DRCT_Q_9; + move16(); BREAK; case 11: drct_r_to_idx = DRCT_Q_11; + move16(); BREAK; default: assert( !"Forbidden value for DRCT quantization strategy index" ); @@ -184,6 +325,7 @@ Word16 ivas_map_num_drct_r_to_idx( } return drct_r_to_idx; } +#endif /*-----------------------------------------------------------------------------------------* @@ -192,29 +334,69 @@ Word16 ivas_map_num_drct_r_to_idx( * Map the ivas_arith_decd_r_consts and ivas_huff_decd_r_consts tables *-----------------------------------------------------------------------------------------*/ -Word16 ivas_map_num_decd_r_to_idx( +#ifndef IVAS_FLOAT_FIXED +int16_t ivas_map_num_decd_r_to_idx( + const int16_t num_quant_points_decd_r ) +{ + int16_t decd_r_to_idx = -1; + switch ( num_quant_points_decd_r ) + { + case 1: + decd_r_to_idx = DECD_Q_1; + break; + case 3: + decd_r_to_idx = DECD_Q_3; + break; + case 5: + decd_r_to_idx = DECD_Q_5; + break; + case 7: + decd_r_to_idx = DECD_Q_7; + break; + case 9: + decd_r_to_idx = DECD_Q_9; + break; + case 11: + decd_r_to_idx = DECD_Q_11; + break; + default: + assert( !"Forbidden value for DECD quantization strategy index" ); + break; + } + + return decd_r_to_idx; +} +#else +Word16 ivas_map_num_decd_r_to_idx_fx( const Word16 num_quant_points_decd_r ) { Word16 decd_r_to_idx = -1; + move16(); SWITCH( num_quant_points_decd_r ) { case 1: decd_r_to_idx = DECD_Q_1; + move16(); BREAK; case 3: decd_r_to_idx = DECD_Q_3; + move16(); BREAK; case 5: decd_r_to_idx = DECD_Q_5; + move16(); BREAK; case 7: decd_r_to_idx = DECD_Q_7; + move16(); BREAK; case 9: decd_r_to_idx = DECD_Q_9; + move16(); BREAK; case 11: decd_r_to_idx = DECD_Q_11; + move16(); BREAK; default: assert( !"Forbidden value for DECD quantization strategy index" ); @@ -223,15 +405,16 @@ Word16 ivas_map_num_decd_r_to_idx( return decd_r_to_idx; } +#endif -#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------------------------- - * * Function ivas_spar_arith_com_init() * * arith coder init *---------------------------------------------------------------------------------------- - */ +#ifndef IVAS_FLOAT_FIXED static void ivas_spar_arith_com_init( ivas_arith_t *pArith, const ivas_freq_models_t *pFreq_models, @@ -333,12 +516,6 @@ static void ivas_spar_arith_com_init( return; } #else -/*---------------------------------------------------------------------------------------- - * - * Function ivas_spar_arith_com_init_fx() - * - * arith coder init - *---------------------------------------------------------------------------------------- - */ - static void ivas_spar_arith_com_init_fx( ivas_arith_t *pArith, const ivas_freq_models_t *pFreq_models, @@ -348,25 +525,29 @@ static void ivas_spar_arith_com_init_fx( { Word16 i, j; Word16 sum, log2_int, log2_frac; - Word32 tmp32, log2_int32, L_tmp2; + Word32 tmp32, log2_int32, L_tmp1, L_tmp2; pArith->vals = pFreq_models->vals; pArith->range = q_levels; + move16(); pArith->num_models = pFreq_models->num_models; + move16(); pArith->dyn_model_bits = ivas_get_bits_to_encode( pArith->num_models - 1 ); + move16(); pArith->pFreq_model = pFreq_models->freq_model[0]; - ivas_get_cum_freq_model( pArith->pFreq_model, pArith->range, pArith->cum_freq[0] ); + ivas_get_cum_freq_model_fx( pArith->pFreq_model, pArith->range, pArith->cum_freq[0] ); FOR( i = 0; i < pArith->num_models - 1; i++ ) { pArith->pAlt_freq_models[i] = pFreq_models->freq_model[i + 1]; - ivas_get_cum_freq_model( pArith->pAlt_freq_models[i], pArith->range, pArith->cum_freq[i + 1] ); + ivas_get_cum_freq_model_fx( pArith->pAlt_freq_models[i], pArith->range, pArith->cum_freq[i + 1] ); } - IF( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { sum = 0; + move16(); FOR( i = 1; i < pArith->range + 1; i++ ) { sum = add( sum, pArith->pFreq_model[i] ); @@ -374,22 +555,23 @@ static void ivas_spar_arith_com_init_fx( log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */ FOR( i = 1; i < pArith->range + 1; i++ ) { - Word32 L_tmp1; log2_int = norm_s( pArith->pFreq_model[i] ); tmp32 = L_deposit_h( shl( pArith->pFreq_model[i], log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */ pArith->saved_dist_arr[0][i - 1] = L_sub( L_tmp1, L_tmp2 ); + move32(); } FOR( j = 0; j < pArith->num_models - 1; j++ ) { sum = 0; + move16(); FOR( i = 1; i < pArith->range + 1; i++ ) { sum = add( sum, pArith->pAlt_freq_models[j][i] ); @@ -397,38 +579,42 @@ static void ivas_spar_arith_com_init_fx( log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */ FOR( i = 1; i < pArith->range + 1; i++ ) { - Word32 L_tmp1; log2_int = norm_s( pArith->pAlt_freq_models[j][i] ); tmp32 = L_deposit_h( shl( pArith->pAlt_freq_models[j][i], log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */ pArith->saved_dist_arr[j + 1][i - 1] = L_sub( L_tmp1, L_tmp2 ); + move32(); } } } pArith_diff->vals = pFreq_models->diff_vals; pArith_diff->range = q_levels; + move16(); pArith_diff->num_models = pFreq_models->diff_num_models; + move16(); pArith_diff->dyn_model_bits = ivas_get_bits_to_encode( pArith_diff->num_models - 1 ); + move16(); pArith_diff->pFreq_model = pFreq_models->diff_freq_model[0]; - ivas_get_cum_freq_model( pArith_diff->pFreq_model, pArith_diff->range, pArith_diff->cum_freq[0] ); + ivas_get_cum_freq_model_fx( pArith_diff->pFreq_model, pArith_diff->range, pArith_diff->cum_freq[0] ); FOR( i = 0; i < pArith_diff->num_models - 1; i++ ) { pArith_diff->pAlt_freq_models[i] = pFreq_models->diff_freq_model[i + 1]; - ivas_get_cum_freq_model( pArith_diff->pAlt_freq_models[i], pArith_diff->range, pArith_diff->cum_freq[i + 1] ); + ivas_get_cum_freq_model_fx( pArith_diff->pAlt_freq_models[i], pArith_diff->range, pArith_diff->cum_freq[i + 1] ); } - IF( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { sum = 0; + move16(); FOR( i = 1; i < pArith_diff->range + 1; i++ ) { sum = add( sum, pArith_diff->pFreq_model[i] ); @@ -436,22 +622,23 @@ static void ivas_spar_arith_com_init_fx( log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */ FOR( i = 1; i < pArith_diff->range + 1; i++ ) { - Word32 L_tmp1; log2_int = norm_s( pArith_diff->pFreq_model[i] ); tmp32 = L_deposit_h( shl( pArith_diff->pFreq_model[i], log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */ pArith_diff->saved_dist_arr[0][i - 1] = L_sub( L_tmp1, L_tmp2 ); + move32(); } FOR( j = 0; j < pArith_diff->num_models - 1; j++ ) { sum = 0; + move16(); FOR( i = 1; i < pArith_diff->range + 1; i++ ) { sum = add( sum, pArith_diff->pAlt_freq_models[j][i] ); @@ -459,17 +646,17 @@ static void ivas_spar_arith_com_init_fx( log2_int = norm_s( sum ); tmp32 = L_deposit_h( shl( sum, log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp2 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */ FOR( i = 1; i < pArith_diff->range + 1; i++ ) { - Word32 L_tmp1; log2_int = norm_s( pArith_diff->pAlt_freq_models[j][i] ); tmp32 = L_deposit_h( shl( pArith_diff->pAlt_freq_models[j][i], log2_int ) ); log2_frac = Log2_norm_lc( tmp32 ); - log2_int32 = L_shl( (Word32) sub( sub( 30, log2_int ), 16 ), 15 ); - L_tmp1 = L_add( log2_int32, (Word32) log2_frac ); /* Q15 */ + log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 ); + L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */ pArith_diff->saved_dist_arr[j + 1][i - 1] = L_sub( L_tmp1, L_tmp2 ); + move32(); } } } @@ -477,13 +664,46 @@ static void ivas_spar_arith_com_init_fx( return; } #endif + + /*-----------------------------------------------------------------------------------------* * Function ivas_spar_arith_coeffs_com_init() * * Init for Arithm. coding *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_arith_coeffs_com_init( + ivas_arith_coeffs_t *pArith_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const int16_t table_idx, + const int16_t enc_dec ) +{ + int16_t i, pred_r_index, drct_r_index, decd_r_index; + int16_t num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; + + for ( i = 0; i < MAX_QUANT_STRATS; i++ ) + { + num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ + pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, ivas_spar_br_table_consts[table_idx].active_w ); + ivas_spar_arith_com_init( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index], + &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); + + num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */ + drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); + ivas_spar_arith_com_init( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index], + &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); + + num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */ + decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); + ivas_spar_arith_com_init( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index], + &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); + } + + return; +} +#else +void ivas_spar_arith_coeffs_com_init_fx( ivas_arith_coeffs_t *pArith_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, const Word16 table_idx, @@ -495,36 +715,27 @@ void ivas_spar_arith_coeffs_com_init( FOR( i = 0; i < MAX_QUANT_STRATS; i++ ) { num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ - pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, ivas_spar_br_table_consts[table_idx].active_w ); -#ifdef IVAS_FLOAT_FIXED + move16(); + pred_r_index = ivas_map_num_pred_r_to_idx_fx( num_quant_points_pred_r, ivas_spar_br_table_consts[table_idx].active_w ); ivas_spar_arith_com_init_fx( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index], &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); -#else - ivas_spar_arith_com_init( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index], - &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); -#endif + num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */ - drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); -#ifdef IVAS_FLOAT_FIXED + move16(); + drct_r_index = ivas_map_num_drct_r_to_idx_fx( num_quant_points_drct_r ); ivas_spar_arith_com_init_fx( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index], &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); -#else - ivas_spar_arith_com_init( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index], - &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); -#endif + num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */ - decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); -#ifdef IVAS_FLOAT_FIXED + move16(); + decd_r_index = ivas_map_num_decd_r_to_idx_fx( num_quant_points_decd_r ); ivas_spar_arith_com_init_fx( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index], &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); -#else - ivas_spar_arith_com_init( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index], - &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); -#endif } return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -533,8 +744,37 @@ void ivas_spar_arith_coeffs_com_init( * Find min and max length in codebook and finalize initialization of ivas_huffman_cfg_t. *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_huffman_dec_init_min_max_len( ivas_huffman_cfg_t *p_huff_cfg ) +{ + int16_t i, code_len; + const int16_t *codebook; + + codebook = p_huff_cfg->codebook; + + p_huff_cfg->min_len = p_huff_cfg->sym_len; + p_huff_cfg->max_len = 0; + + for ( i = 0; i < p_huff_cfg->sym_len; i++ ) + { + code_len = codebook[1]; + if ( p_huff_cfg->min_len > code_len ) + { + p_huff_cfg->min_len = code_len; + } + if ( p_huff_cfg->max_len < code_len ) + { + p_huff_cfg->max_len = code_len; + } + codebook = codebook + 3; + } + + return; +} +#else +static void ivas_huffman_dec_init_min_max_len_fx( + ivas_huffman_cfg_t *p_huff_cfg ) { Word16 i, code_len; const Word16 *codebook; @@ -542,24 +782,30 @@ static void ivas_huffman_dec_init_min_max_len( codebook = p_huff_cfg->codebook; p_huff_cfg->min_len = p_huff_cfg->sym_len; + move16(); p_huff_cfg->max_len = 0; + move16(); FOR( i = 0; i < p_huff_cfg->sym_len; i++ ) { code_len = codebook[1]; - IF( GT_16( p_huff_cfg->min_len, code_len ) ) + move16(); + if ( GT_16( p_huff_cfg->min_len, code_len ) ) { p_huff_cfg->min_len = code_len; + move16(); } - IF( LT_16( p_huff_cfg->max_len, code_len ) ) + if ( LT_16( p_huff_cfg->max_len, code_len ) ) { p_huff_cfg->max_len = code_len; + move16(); } codebook = codebook + 3; } return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -568,7 +814,54 @@ static void ivas_huffman_dec_init_min_max_len( * Init for Huffman decoding *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_huff_coeffs_com_init( + ivas_huff_coeffs_t *pHuff_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const int16_t table_idx, + const int16_t enc_dec ) +{ + int16_t i, pred_r_index, drct_r_index, decd_r_index; + int16_t num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; + ivas_huffman_cfg_t *p_huff_cfg; + + for ( i = 0; i < MAX_QUANT_STRATS; i++ ) + { + p_huff_cfg = &pHuff_coeffs->pred_huff_re[i]; + num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ + pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, 0 ); + p_huff_cfg->codebook = &ivas_huff_pred_r_consts[pred_r_index].code_book[0][0]; + if ( enc_dec == DEC ) + { + p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].PR.q_levels[0]; + ivas_huffman_dec_init_min_max_len( p_huff_cfg ); + } + + p_huff_cfg = &pHuff_coeffs->drct_huff_re[i]; + num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */ + drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); + p_huff_cfg->codebook = &ivas_huff_drct_r_consts[drct_r_index].code_book[0][0]; + if ( enc_dec == DEC ) + { + p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].C.q_levels[0]; + ivas_huffman_dec_init_min_max_len( p_huff_cfg ); + } + + p_huff_cfg = &pHuff_coeffs->decd_huff_re[i]; + num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */ + decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); + p_huff_cfg->codebook = &ivas_huff_decd_r_consts[decd_r_index].code_book[0][0]; + if ( enc_dec == DEC ) + { + p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].P_r.q_levels[0]; + ivas_huffman_dec_init_min_max_len( p_huff_cfg ); + } + } + + return; +} +#else +void ivas_spar_huff_coeffs_com_init_fx( ivas_huff_coeffs_t *pHuff_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, const Word16 table_idx, @@ -582,34 +875,41 @@ void ivas_spar_huff_coeffs_com_init( { p_huff_cfg = &pHuff_coeffs->pred_huff_re[i]; num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ - pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, 0 ); + move16(); + pred_r_index = ivas_map_num_pred_r_to_idx_fx( num_quant_points_pred_r, 0 ); p_huff_cfg->codebook = &ivas_huff_pred_r_consts[pred_r_index].code_book[0][0]; IF( EQ_16( enc_dec, DEC ) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].PR.q_levels[0]; - ivas_huffman_dec_init_min_max_len( p_huff_cfg ); + move16(); + ivas_huffman_dec_init_min_max_len_fx( p_huff_cfg ); } p_huff_cfg = &pHuff_coeffs->drct_huff_re[i]; num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */ - drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); + move16(); + drct_r_index = ivas_map_num_drct_r_to_idx_fx( num_quant_points_drct_r ); p_huff_cfg->codebook = &ivas_huff_drct_r_consts[drct_r_index].code_book[0][0]; IF( EQ_16( enc_dec, DEC ) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].C.q_levels[0]; - ivas_huffman_dec_init_min_max_len( p_huff_cfg ); + move16(); + ivas_huffman_dec_init_min_max_len_fx( p_huff_cfg ); } p_huff_cfg = &pHuff_coeffs->decd_huff_re[i]; num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */ - decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); + move16(); + decd_r_index = ivas_map_num_decd_r_to_idx_fx( num_quant_points_decd_r ); p_huff_cfg->codebook = &ivas_huff_decd_r_consts[decd_r_index].code_book[0][0]; IF( EQ_16( enc_dec, DEC ) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].P_r.q_levels[0]; - ivas_huffman_dec_init_min_max_len( p_huff_cfg ); + move16(); + ivas_huffman_dec_init_min_max_len_fx( p_huff_cfg ); } } return; } +#endif diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index c76621969..afdac0d9b 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -89,7 +89,7 @@ /*! r : ISM format mode */ #ifdef IVAS_FLOAT_FIXED -ISM_MODE ivas_omasa_ism_mode_select( +ISM_MODE ivas_omasa_ism_mode_select_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ const Word16 nchan_ism /* i : number of input ISM's */ ) @@ -169,6 +169,7 @@ ISM_MODE ivas_omasa_ism_mode_select( ELSE { ism_mode = ISM_MODE_NONE; + move16(); } BREAK; } @@ -258,7 +259,7 @@ ISM_MODE ivas_omasa_ism_mode_select( * ---------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_set_omasa_TC( +void ivas_set_omasa_TC_fx( const ISM_MODE ism_mode, /* i : ISM mode */ const Word16 nchan_ism, /* i : number of input ISMs */ Word16 *nSCE, /* o : number of SCEs */ @@ -331,7 +332,7 @@ void ivas_set_omasa_TC( /*! r: adjusted bitrate */ #ifdef IVAS_FLOAT_FIXED -Word32 ivas_interformat_brate( +Word32 ivas_interformat_brate_fx( const ISM_MODE ism_mode, /* i : ISM mode */ const Word16 nchan_ism, /* i : number of ISM channels */ const Word32 element_brate, /* i : element bitrate */ @@ -342,17 +343,32 @@ Word32 ivas_interformat_brate( Word32 element_brate_out; Word16 nBits, limit_low, limit_high; - nBits = extract_l( div_l( element_brate, shr( FRAMES_PER_SEC, 1 ) ) ); + nBits = extract_l( Mpy_32_32( element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* Q0 */ - IF( EQ_16( ism_imp, ISM_INACTIVE_IMP ) ) + IF( ism_imp == ISM_INACTIVE_IMP ) { nBits = BITS_ISM_INACTIVE; move16(); } ELSE { - IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_DISC ) && ( ( EQ_16( nchan_ism, 4 ) && EQ_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 3 ) && LE_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 2 ) && LE_32( element_brate, 11000 ) ) ) ) /* for border case in DISC mode */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) && ( ( EQ_16( nchan_ism, 4 ) && EQ_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 3 ) && LE_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 2 ) && LE_32( element_brate, 11000 ) ) ) ) /* for border case in DISC mode */ { + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( limit_flag, 1 ) && ( ( EQ_16( nchan_ism, 4 ) && EQ_32( element_brate, 24000 ) ) || ( EQ_16( nchan_ism, 3 ) && EQ_32( element_brate, 20000 ) ) || ( EQ_16( nchan_ism, 2 ) && LE_32( element_brate, 11000 ) ) ) ) { return element_brate; @@ -379,11 +395,12 @@ Word32 ivas_interformat_brate( } } } - ELSE IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_PARAM_ONE_OBJ ) || - ( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_DISC ) && EQ_32( element_brate, 9600 ) ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */ + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || + ( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( element_brate, 9600 ) ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */ ) { - IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_PARAM_ONE_OBJ ) && EQ_32( element_brate, IVAS_13k2 ) ) + test(); + IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && EQ_32( element_brate, IVAS_13k2 ) ) { IF( EQ_16( ism_imp, ISM_LOW_IMP ) ) { @@ -414,7 +431,7 @@ Word32 ivas_interformat_brate( } } } - ELSE IF( EQ_16( (Word16) ism_mode, (Word16) ISM_MASA_MODE_MASA_ONE_OBJ ) && EQ_32( element_brate, 16000 ) ) + ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) && EQ_32( element_brate, 16000 ) ) { IF( EQ_16( ism_imp, ISM_LOW_IMP ) ) { @@ -447,7 +464,8 @@ Word32 ivas_interformat_brate( } limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC; - IF( EQ_16( ism_imp, ISM_INACTIVE_IMP ) ) + move16(); + IF( ism_imp == ISM_INACTIVE_IMP ) { limit_low = BITS_ISM_INACTIVE; move16(); @@ -466,7 +484,7 @@ Word32 ivas_interformat_brate( move16(); } - nBits = check_bounds_s( nBits, limit_low, limit_high ); + nBits = check_bounds_s_fx( nBits, limit_low, limit_high ); element_brate_out = L_mult0( nBits, FRAMES_PER_SEC ); @@ -618,7 +636,7 @@ int32_t ivas_interformat_brate( * ---------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_combined_format_brate_sanity( +void ivas_combined_format_brate_sanity_fx( const Word32 element_brate, /* i : element bitrate */ const Word16 core, /* i : core */ const Word32 total_brate, /* i : total bitrate */ @@ -640,10 +658,10 @@ void ivas_combined_format_brate_sanity( { limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC; move16(); - nBits = extract_l( div_l( *core_brate, shr( FRAMES_PER_SEC, 1 ) ) ); + nBits = extract_l( Mpy_32_32( *core_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); *diff_nBits = sub( nBits, limit_high ); - IF( GT_16( *diff_nBits, 0 ) ) + IF( *diff_nBits > 0 ) { IF( EQ_16( core, TCX_20_CORE ) || EQ_16( core, TCX_10_CORE ) ) { @@ -661,11 +679,11 @@ void ivas_combined_format_brate_sanity( * set inactive coder_type flag in ACELP core *-----------------------------------------------------------------*/ - IF( EQ_16( core, ACELP_CORE ) ) + IF( core == ACELP_CORE ) { *inactive_coder_type_flag = 0; /* AVQ by default */ move16(); - IF( LE_32( L_add( *core_brate, brate_diff ), MAX_GSC_INACTIVE_BRATE ) ) + if ( LE_32( L_add( *core_brate, brate_diff ), MAX_GSC_INACTIVE_BRATE ) ) { *inactive_coder_type_flag = 1; /* GSC */ move16(); @@ -729,6 +747,7 @@ void ivas_combined_format_brate_sanity( } #endif + /*--------------------------------------------------------------- * bits_index_ism_ratio() * @@ -737,7 +756,7 @@ void ivas_combined_format_brate_sanity( /*!r : number of bits for ISM ratio index */ #ifdef IVAS_FLOAT_FIXED -Word16 bits_index_ism_ratio( +Word16 bits_index_ism_ratio_fx( const Word16 nchan_ism /* i : number of objects */ ) { @@ -802,7 +821,7 @@ int16_t bits_index_ism_ratio( * * ---------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void calculate_nbits_meta( const int16_t nchan_ism, float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], @@ -860,7 +879,7 @@ void calculate_nbits_meta( return; } -#ifdef IVAS_FLOAT_FIXED +#else static Word16 get_bits_ism( Word32 val ) { Word16 res; @@ -914,7 +933,7 @@ void calculate_nbits_meta_fx( const Word16 ism_imp ) { Word16 sf, band, obj; - Word32 priority[MAX_NUM_OBJECTS], max_p; + Word32 priority[MAX_NUM_OBJECTS], max_p; /* Q29 */ IF( GT_16( nchan_ism, 1 ) ) { @@ -925,7 +944,7 @@ void calculate_nbits_meta_fx( { FOR( obj = 0; obj < nchan_ism; obj++ ) { - priority[obj] = max( priority[obj], ( Mpy_32_32( q_energy_ratio_ism[sf][band][obj], L_sub( 1073741824, masa_to_total_energy_ratio[sf][band] ) ) ) ); // Qx - 1 + priority[obj] = L_max( priority[obj], ( Mpy_32_32( q_energy_ratio_ism[sf][band][obj], L_sub( 1073741824 /* 1.0f in Q30 */, masa_to_total_energy_ratio[sf][band] ) ) ) ); // Qx - 1 move32(); } } @@ -933,7 +952,7 @@ void calculate_nbits_meta_fx( } ELSE { - priority[0] = 536870912; + priority[0] = 536870912; /* 1.0f in Q29 */ move32(); } @@ -945,7 +964,7 @@ void calculate_nbits_meta_fx( { IF( EQ_16( ism_imp, 3 ) ) { - priority[obj] = 536870912; + priority[obj] = 536870912; /* 1.0f in Q29 */ move32(); } ELSE IF( EQ_16( ism_imp, 2 ) ) @@ -955,7 +974,7 @@ void calculate_nbits_meta_fx( } ELSE { - priority[obj] = max_p; + priority[obj] = max_p; /* Q29 */ move32(); } } @@ -966,6 +985,7 @@ void calculate_nbits_meta_fx( } #endif + /*--------------------------------------------------------------- * ivas_get_stereo_panning_gains() * @@ -1161,7 +1181,7 @@ void ivas_get_stereo_panning_gains_fx( /*! r: limitation flag */ #ifdef IVAS_FLOAT_FIXED -Word16 calculate_brate_limit_flag( +Word16 calculate_brate_limit_flag_fx( const Word16 ism_imp[], /* i : ISM importance flags */ const Word16 nchan_ism /* i : number of objects */ ) @@ -1178,17 +1198,19 @@ Word16 calculate_brate_limit_flag( FOR( n = 0; n < nchan_ism; n++ ) { brate_limit_flag = add( brate_limit_flag, ism_imp[n] ); - IF( EQ_16( ism_imp[n], 0 ) ) + if ( ism_imp[n] == 0 ) { nzeros = add( nzeros, 1 ); } } nchan_ism_sat = nchan_ism; - IF( EQ_16( nchan_ism & 1, 1 ) ) + if ( EQ_16( nchan_ism & 1, 1 ) ) { nchan_ism_sat = sub( nchan_ism, 1 ); } + + /* brate_limit_flag >= (int16_t) ( nchan_ism * 2.5f ) */ IF( GE_16( i_mult( 2, brate_limit_flag ), add( i_mult( 4, nchan_ism ), nchan_ism_sat ) ) ) { brate_limit_flag = 1; @@ -1196,7 +1218,7 @@ Word16 calculate_brate_limit_flag( } ELSE { - IF( GE_16( i_mult( 2, nzeros ), nchan_ism ) ) + if ( GE_16( i_mult( 2, nzeros ), nchan_ism ) ) { brate_limit_flag = -1; /* there is no limitation, on the contrary */ move16(); diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 91be1b984..f7c387d2d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2307,4 +2307,81 @@ MC_LS_SETUP ivas_mc_map_output_config_to_mc_ls_setup_fx( AUDIO_CONFIG ivas_mc_map_ls_setup_to_output_config_fx( const MC_LS_SETUP mc_ls_setup /* i : multi channel loudspeaker setup*/ ); + +void ivas_wrap_arround_fx( + Word16 *pArr, + const Word16 min_val, + const Word16 max_val, + const Word16 length ); + +void ivas_get_cum_freq_model_fx( + const Word16 *pFreq_model, + const Word16 length, + Word16 *pCum_freq_model ); + +Word16 ivas_map_num_pred_r_to_idx_fx( + const Word16 num_quant_points_pred_r, + const Word16 active_w_flag ); + +Word16 ivas_map_num_drct_r_to_idx_fx( + const Word16 num_quant_points_drct_r ); + +Word16 ivas_map_num_decd_r_to_idx_fx( + const Word16 num_quant_points_decd_r ); + +void ivas_spar_arith_coeffs_com_init_fx( + ivas_arith_coeffs_t *pArith_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec ); + +void ivas_spar_huff_coeffs_com_init_fx( + ivas_huff_coeffs_t *pHuff_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const Word16 table_idx, + const Word16 enc_dec ); + +ISM_MODE ivas_omasa_ism_mode_select_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism /* i : number of input ISM's */ +); + +void ivas_set_omasa_TC_fx( + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word16 nchan_ism, /* i : number of input ISMs */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE /* o : number of CPEs */ +); + +Word32 ivas_interformat_brate_fx( + const ISM_MODE ism_mode, /* i : ISM mode */ + const Word16 nchan_ism, /* i : number of ISM channels */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 ism_imp, /* i : ISM importance flag */ + const Word16 limit_flag /* i : flag to limit the bitrate increase */ +); + +Word16 check_bounds_s_fx( + const Word16 value, /* i : Input value */ + const Word16 low, /* i : Low limit */ + const Word16 high /* i : High limit */ +); + +void ivas_combined_format_brate_sanity_fx( + const Word32 element_brate, /* i : element bitrate */ + const Word16 core, /* i : core */ + const Word32 total_brate, /* i : total bitrate */ + Word32 *core_brate, /* i/o: core bitrate */ + Word16 *inactive_coder_type_flag, /* o : inactive coder_type flag */ + Word16 *diff_nBits /* o : number of differential bits */ +); + +Word16 bits_index_ism_ratio_fx( + const Word16 nchan_ism /* i : number of objects */ +); + +Word16 calculate_brate_limit_flag_fx( + const Word16 ism_imp[], /* i : ISM importance flags */ + const Word16 nchan_ism /* i : number of objects */ +); #endif diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index 586d88f1a..34b7942d6 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -317,7 +317,7 @@ typedef struct ivas_arith_t int16_t range; int16_t num_models; #ifdef IVAS_FLOAT_FIXED - Word32 saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; + Word32 saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; /* Q15 */ #else float saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; #endif diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 91824fff9..dfc98c90d 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1161,6 +1161,20 @@ int16_t check_bounds_s( return value_adj; } +#ifdef IVAS_FLOAT_FIXED +Word16 check_bounds_s_fx( + const Word16 value, /* i : Input value */ + const Word16 low, /* i : Low limit */ + const Word16 high /* i : High limit */ +) +{ + Word16 value_adj; + + value_adj = s_min( s_max( value, low ), high ); + + return value_adj; +} +#endif /*-------------------------------------------------------------------* * check_bounds_l() diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 8bbbd12e8..4ee545e49 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -401,7 +401,7 @@ ivas_error ivas_core_dec( test(); IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) { - ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); + ivas_combined_format_brate_sanity_fx( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); } /*------------------------------------------------------------------* diff --git a/lib_dec/ivas_entropy_decoder.c b/lib_dec/ivas_entropy_decoder.c index 01922f9c3..af8e4082a 100644 --- a/lib_dec/ivas_entropy_decoder.c +++ b/lib_dec/ivas_entropy_decoder.c @@ -38,6 +38,9 @@ #include "ivas_rom_com.h" #include #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*------------------------------------------------------------------------------------------* @@ -134,7 +137,11 @@ static void ivas_arithCoder_decode_array_diff( pOutput_arr[n] = add( sub( pSymbol_old[n], offset ), pOutput_arr[n] ); } +#ifndef IVAS_FLOAT_FIXED ivas_wrap_arround( pOutput_arr, 0, sub( pArith_diff->range, 1 ), length ); +#else + ivas_wrap_arround_fx( pOutput_arr, 0, sub( pArith_diff->range, 1 ), length ); +#endif FOR( n = 0; n < length; n++ ) { diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 234fe1e11..eb526f1f5 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -210,7 +210,8 @@ ivas_error ivas_dec_setup( /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata */ st_ivas->nchan_ism = 2 * st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 1] + st_ivas->bit_stream[ivas_total_brate / FRAMES_PER_SEC - 2] + 1; - st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism ); + move32(); IF( GT_16( st_ivas->ini_frame, 0 ) ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 6dce33f67..2673ec268 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -4767,7 +4767,7 @@ static void read_ism_ratio_index_fx( IF( EQ_16( sf, 0 ) ) { - bits_index = bits_index_ism_ratio( nchan_ism ); + bits_index = bits_index_ism_ratio_fx( nchan_ism ); /* read coding type */ IF( EQ_32( bit_stream[( *next_bit_pos )--], 1 ) ) diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index d3b2595a0..d239baccc 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -272,7 +272,7 @@ ivas_error ivas_omasa_dec_config_fx( move32(); /* save previous frame parameters */ - ism_mode_old = ivas_omasa_ism_mode_select( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->nchan_ism ); + ism_mode_old = ivas_omasa_ism_mode_select_fx( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->nchan_ism ); move16(); st_ivas->ism_mode = ism_mode_old; move16(); @@ -294,7 +294,7 @@ ivas_error ivas_omasa_dec_config_fx( move16(); /* set ism_mode of current frame */ - st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism ); move16(); /*-----------------------------------------------------------------* @@ -343,7 +343,7 @@ ivas_error ivas_omasa_dec_config_fx( } } - ivas_set_omasa_TC( st_ivas->ism_mode, st_ivas->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); + ivas_set_omasa_TC_fx( st_ivas->ism_mode, st_ivas->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); /* re-configure hp20 memories */ IF( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) @@ -915,7 +915,8 @@ void ivas_set_surplus_brate_dec( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { - *ism_total_brate = ivas_interformat_brate( st_ivas->ism_mode, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); + *ism_total_brate = ivas_interformat_brate_fx( st_ivas->ism_mode, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); + move32(); st_ivas->hCPE[0]->brate_surplus = L_sub( st_ivas->hSCE[0]->element_brate, *ism_total_brate ); @@ -941,8 +942,7 @@ void ivas_set_surplus_brate_dec( move16(); } - brate_limit_flag = calculate_brate_limit_flag( ism_imp, st_ivas->nchan_ism ); - move16(); + brate_limit_flag = calculate_brate_limit_flag_fx( ism_imp, st_ivas->nchan_ism ); ism_total_brate_ref = 0; move32(); @@ -972,7 +972,8 @@ void ivas_set_surplus_brate_dec( st_ivas->hSCE[n]->element_brate = element_brate[n]; move32(); - *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag ) ); + *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate_fx( ISM_MASA_MODE_DISC, st_ivas->nchan_ism, st_ivas->hSCE[n]->element_brate, st_ivas->hIsmMetaData[n]->ism_imp, brate_limit_flag ) ); + move32(); test(); test(); diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 125d7c7ae..44a771249 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -1033,8 +1033,8 @@ ivas_error ivas_spar_md_dec_init( PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; ivas_spar_quant_dtx_init_fx( &hMdDec->spar_md, PR_minmax_fx ); - ivas_spar_arith_coeffs_com_init( &hMdDec->arith_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); - ivas_spar_huff_coeffs_com_init( &hMdDec->huff_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); + ivas_spar_arith_coeffs_com_init_fx( &hMdDec->arith_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); + ivas_spar_huff_coeffs_com_init_fx( &hMdDec->huff_coeffs, &hMdDec->spar_md_cfg, hMdDec->table_idx, DEC ); hMdDec->spar_md_cfg.prev_quant_idx = -1; diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 8a7f883ec..d11dd6ba2 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -1396,7 +1396,7 @@ void stereo_dft_dec_fx( Word32 DFT_W, DFT_Y; Word16 q_samp_ratio = Q15; - output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC ); + output_frame = (Word16) Mpy_32_32( L_add( st0->output_Fs, FRAMES_PER_SEC_BY_2 ), ONE_BY_FRAMES_PER_SEC_Q31 ); /*------------------------------------------------------------------* * Initialization diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index db7f5d9d1..ebc6bd649 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -39,6 +39,9 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*-------------------------------------------------------------------* @@ -183,11 +186,22 @@ ivas_error ivas_core_enc( * Sanity check in combined format coding *-----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED diff_nBits = 0; if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) { ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits ); } +#else + diff_nBits = 0; + move16(); + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity_fx( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &diff_nBits ); + } +#endif /*---------------------------------------------------------------------* * Core Encoding diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 757378034..14ed149e1 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -39,6 +39,9 @@ #include "math.h" #include #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif #ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -286,7 +289,11 @@ static Word16 ivas_arithCoder_encode_array_diff( pIn_old_scratch[n] = sub( pIn_new[n], pIn_old_scratch[n] ); } +#ifndef IVAS_FLOAT_FIXED ivas_wrap_arround( pIn_old_scratch, pArith_diff->vals[0], pArith_diff->vals[pArith_diff->range - 1], length ); +#else + ivas_wrap_arround_fx( pIn_old_scratch, pArith_diff->vals[0], pArith_diff->vals[pArith_diff->range - 1], length ); +#endif arith_result = ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length, wc_strat_arith ); IF( LT_16( arith_result, 0 ) ) diff --git a/lib_enc/ivas_init_enc.c b/lib_enc/ivas_init_enc.c index cc7ee8f2c..1daf86b23 100644 --- a/lib_enc/ivas_init_enc.c +++ b/lib_enc/ivas_init_enc.c @@ -656,7 +656,12 @@ ivas_error ivas_init_encoder( int32_t ism_total_brate; int16_t k; +#ifndef IVAS_FLOAT_FIXED st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); +#else + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); + move32(); +#endif st_ivas->nchan_transport = 2; if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) @@ -1233,7 +1238,12 @@ ivas_error ivas_init_encoder_fx( int32_t ism_total_brate; int16_t k; +#ifndef IVAS_FLOAT_FIXED st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); +#else + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); + move32(); +#endif st_ivas->nchan_transport = 2; if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 2154f3042..0b4a5e2e9 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -40,6 +40,9 @@ #include "prot.h" #include #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif /*-----------------------------------------------------------------------* @@ -631,7 +634,11 @@ ivas_error ivas_ism_metadata_enc( int16_t brate_limit_flag; int32_t ism_total_brate_ref; ism_total_brate_ref = *ism_total_brate; +#ifndef IVAS_FLOAT_FIXED brate_limit_flag = calculate_brate_limit_flag( ism_imp, nchan_ism ); +#else + brate_limit_flag = calculate_brate_limit_flag_fx( ism_imp, nchan_ism ); +#endif bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SEC ); set_s( bits_element, bits_ism / nchan_ism, nchan_ism ); @@ -641,7 +648,12 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < nchan_ism; ch++ ) { +#ifndef IVAS_FLOAT_FIXED *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); +#else + *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate_fx( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ) ); + move32(); +#endif if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) { @@ -760,7 +772,11 @@ ivas_error ivas_ism_metadata_enc_create( if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { nchan_transport = MAX_PARAM_ISM_WAVE; +#ifndef IVAS_FLOAT_FIXED ivas_set_omasa_TC( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); +#else + ivas_set_omasa_TC_fx( st_ivas->ism_mode, n_ISms, &st_ivas->nSCE, &st_ivas->nCPE ); +#endif } else if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) { diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 2445f2e0d..4cc597b98 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -3635,7 +3635,11 @@ static int16_t encode_ratio_ism_subframe( bits_index = 0; if ( sf == 0 ) { +#ifndef IVAS_FLOAT_FIXED bits_index = bits_index_ism_ratio( nchan_ism ); +#else + bits_index = bits_index_ism_ratio_fx( nchan_ism ); +#endif nbits = 0; for ( b = 0; b < numCodingBands; b++ ) @@ -4126,7 +4130,20 @@ static void ivas_encode_masaism_metadata( } } +#ifndef IVAS_FLOAT_FIXED calculate_nbits_meta( nchan_ism, hOmasaData->q_energy_ratio_ism, hOmasaData->masa_to_total_energy_ratio, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#else + FOR( sf = 0; sf < numSf; ++sf ) + { + FOR( band = 0; band < numCodingBands; ++band ) + { + floatToFixed_arr32( hOmasaData->q_energy_ratio_ism[sf][band], hOmasaData->q_energy_ratio_ism_fx[sf][band], Q30, nchan_ism ); + hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = floatToFixed_32( hOmasaData->masa_to_total_energy_ratio[sf][band], Q30 ); + } + } + + calculate_nbits_meta_fx( nchan_ism, hOmasaData->q_energy_ratio_ism_fx, hOmasaData->masa_to_total_energy_ratio_fx, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#endif /* quantize directions */ for ( obj = 0; obj < nchan_ism; obj++ ) diff --git a/lib_enc/ivas_omasa_enc.c b/lib_enc/ivas_omasa_enc.c index 1f5499f07..075135e41 100644 --- a/lib_enc/ivas_omasa_enc.c +++ b/lib_enc/ivas_omasa_enc.c @@ -216,13 +216,22 @@ ivas_error ivas_omasa_enc_config( ivas_total_brate = hEncoderConfig->ivas_total_brate; nSCE_old = st_ivas->nSCE; +#ifndef IVAS_FLOAT_FIXED st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism ); +#else + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); + move32(); +#endif st_ivas->nchan_transport = 2; /* reconfiguration in case of bitrate switching */ if ( hEncoderConfig->last_ivas_total_brate != ivas_total_brate ) { +#ifndef IVAS_FLOAT_FIXED ivas_set_omasa_TC( st_ivas->ism_mode, hEncoderConfig->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); +#else + ivas_set_omasa_TC_fx( st_ivas->ism_mode, hEncoderConfig->nchan_ism, &st_ivas->nSCE, &st_ivas->nCPE ); +#endif k = 0; while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] ) @@ -673,7 +682,12 @@ void ivas_set_surplus_brate_enc( { if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) { +#ifndef IVAS_FLOAT_FIXED st_ivas->hCPE[0]->brate_surplus = st_ivas->hSCE[0]->element_brate - ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ); +#else + st_ivas->hCPE[0]->brate_surplus = L_sub( st_ivas->hSCE[0]->element_brate, ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, st_ivas->hSCE[0]->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) ); + move32(); +#endif /* note: ISM st->total_brate is iset in ivas_sce_enc() */ } else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC || st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index ba36a7a2b..3e40937fb 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -210,7 +210,12 @@ ivas_error ivas_sce_enc( { ivas_set_ism_importance_interformat( hSCE->element_brate, 1, st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->hMasa->data.hOmasaData->lp_noise_CPE, &st_ivas->hIsmMetaData[0]->ism_imp ); +#ifndef IVAS_FLOAT_FIXED st->total_brate = ivas_interformat_brate( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ) - nb_bits_metadata * FRAMES_PER_SEC; +#else + st->total_brate = L_sub( ivas_interformat_brate_fx( ISM_MASA_MODE_PARAM_ONE_OBJ, 1, hSCE->element_brate, st_ivas->hIsmMetaData[0]->ism_imp, 0 ), L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); + move32(); +#endif } /*----------------------------------------------------------------* diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index b7a74310e..88dc5ffc8 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -342,8 +342,13 @@ ivas_error ivas_spar_md_enc_init( return IVAS_ERR_INTERNAL; } +#ifndef IVAS_FLOAT_FIXED ivas_spar_arith_coeffs_com_init( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); ivas_spar_huff_coeffs_com_init( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); +#else + ivas_spar_arith_coeffs_com_init_fx( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); + ivas_spar_huff_coeffs_com_init_fx( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); +#endif if ( hEncoderConfig->Opt_DTX_ON == 1 ) { @@ -408,8 +413,8 @@ ivas_error ivas_spar_md_enc_init_fx( return IVAS_ERR_INTERNAL; } - ivas_spar_arith_coeffs_com_init( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); - ivas_spar_huff_coeffs_com_init( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); + ivas_spar_arith_coeffs_com_init_fx( &hMdEnc->arith_coeffs, &hMdEnc->spar_md_cfg, table_idx, ENC ); + ivas_spar_huff_coeffs_com_init_fx( &hMdEnc->huff_coeffs, NULL, table_idx, ENC ); #if 0 // Some issues IF (EQ_16(hEncoderConfig->Opt_DTX_ON, 1)) { diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 6de215c49..292956a0a 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -928,11 +928,14 @@ static ivas_error configureEncoder( } else if ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT ) { +#ifndef IVAS_FLOAT_FIXED st_ivas->ism_mode = ivas_omasa_ism_mode_select( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); -#ifndef IVAS_FLOAT_FIXED cpe_brate = calculate_cpe_brate_MASA_ISM( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); #else + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); + move32(); + cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); #endif @@ -1217,7 +1220,7 @@ static ivas_error configureEncoder_fx( } ELSE IF( EQ_32( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) ) { - st_ivas->ism_mode = ivas_omasa_ism_mode_select( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); + st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism ); -- GitLab From ab9aad237f338dbd0f050c6087f3cd5ba7aeb25e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 21 Jun 2024 13:30:17 +0530 Subject: [PATCH 54/63] MSAN error fix and LTV stereo crash issue fix [x] Fix for LTV crash: test_param_file_tests[ltv-stereo at 16.4 kbps, 32kHz in, 16kHz out, DTX on] [x] MSAN error fix --- lib_dec/ivas_mc_param_dec.c | 3 +++ lib_dec/ivas_stereo_cng_dec.c | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 516080471..8e38d958b 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -5037,6 +5037,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS ); +#ifdef MSAN_FIX + set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); +#endif Word16 proto_matrix_noLFE_e = 0; Word16 guard_bit_cx = find_guarded_bits_fx( nY_intern + 1 ); diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index ddb29199d..54d67d007 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -688,7 +688,7 @@ static void stereo_dft_generate_comfort_noise_fx( Word32 *ptr0, *ptr1, *ptr2; Word16 dmpf[M + 2], Atmp[M + 2]; Word32 cngNoiseLevel_upd[L_FRAME16k], cngNoiseLevel_hist[L_FRAME16k - 2]; - Word16 e_cng_temp[L_FRAME16k]; + Word16 e_norm_temp[L_FRAME16k]; Word32 *ptr_tmp, *ptr_cng; Word32 E0, E1; Word16 b, q_cngNoiseLevel_upd, q_cngNoiseLevel; @@ -876,7 +876,7 @@ static void stereo_dft_generate_comfort_noise_fx( Word16 shift = sub( getScaleFactor32( cngNoiseLevel_upd, st->L_frame ), 1 ); scale_sig32( cngNoiseLevel_upd, st->L_frame, shift ); q_cngNoiseLevel_upd = add( q_cngNoiseLevel_upd, shift ); - set16_fx( e_cng_temp, q_cngNoiseLevel_upd, st->L_frame ); + set16_fx( e_norm_temp, q_cngNoiseLevel_upd, st->L_frame ); /* Compute 1/|A| */ ptr0 = cngNoiseLevel_upd; @@ -902,7 +902,7 @@ static void stereo_dft_generate_comfort_noise_fx( q_sqrt = s_max( 0, q_sqrt ); } tmp = ISqrt32( ftmp, &q_sqrt ); - e_cng_temp[i] = sub( 31, add( q_sqrt, q_div ) ); + e_norm_temp[i] = sub( 31, add( q_sqrt, q_div ) ); *ptr0++ = Mpy_32_32( factor, tmp ); ptr1 += 2; ptr2 += 2; @@ -910,11 +910,11 @@ static void stereo_dft_generate_comfort_noise_fx( FOR( i = 0; i < sub( shr( st->L_frame, 1 ), 1 ); i++ ) { - q_cngNoiseLevel_upd = s_min( q_cngNoiseLevel_upd, e_cng_temp[i] + norm_l( cngNoiseLevel_upd[i] ) ); + q_cngNoiseLevel_upd = s_min( q_cngNoiseLevel_upd, e_norm_temp[i] + norm_l( cngNoiseLevel_upd[i] ) ); } FOR( i = 0; i < st->L_frame; i++ ) { - cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( q_cngNoiseLevel_upd, e_cng_temp[i] ) ); + cngNoiseLevel_upd[i] = L_shl( cngNoiseLevel_upd[i], sub( q_cngNoiseLevel_upd, e_norm_temp[i] ) ); } IF( GT_16( sub( s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin ), 0 ) ) @@ -952,6 +952,7 @@ static void stereo_dft_generate_comfort_noise_fx( ptr0 = shb_shape; ptr1 = ptr0 + 2; ptr2 = ptr1 + 1; + set16_fx( e_norm_temp, q_shb_shape, st->L_frame ); FOR( i = 0; i < L_FRAME16k / 2 - 1; i++ ) { @@ -968,10 +969,21 @@ static void stereo_dft_generate_comfort_noise_fx( and then sum up enr = sum( *ptr0 * *ptr0 ), in a subsequent MAC loop */ enr = BASOP_Util_Add_Mant32Exp( enr, q_enr, ftmp, q_div, &q_enr ); tmp32_1 = Sqrt32( ftmp, &q_div ); - *ptr0++ = L_shl( tmp32_1, sub( q_div, sub( 31, q_shb_shape ) ) ); + *ptr0++ = tmp32_1; + e_norm_temp[i] = sub( 31, q_div ); ptr1 += 2; ptr2 += 2; } + q_shb_shape = MAX_16; + + FOR( i = 0; i < L_FRAME16k; i++ ) + { + q_shb_shape = s_min( q_shb_shape, add( e_norm_temp[i], norm_l( shb_shape[i] ) ) ); + } + FOR( i = 0; i < L_FRAME16k; i++ ) + { + shb_shape[i] = L_shl( shb_shape[i], sub( q_shb_shape, e_norm_temp[i] ) ); + } } /* Update CNG noise level from MS noise estimation */ -- GitLab From e09be01426a6194851007a13a4d610e6a7968f6c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 21 Jun 2024 13:52:53 +0530 Subject: [PATCH 55/63] BASOP additions and instrumention code additions --- lib_com/cnst.h | 2 + lib_dec/FEC_adapt_codebook_fx.c | 31 +-- lib_dec/FEC_clas_estim_fx.c | 33 ++-- lib_dec/FEC_fx.c | 39 ++-- lib_dec/er_dec_acelp_fx.c | 64 +++--- lib_dec/er_dec_tcx_fx.c | 62 +++--- lib_dec/er_scale_syn_fx.c | 7 +- lib_dec/er_sync_exc_fx.c | 24 +-- lib_dec/er_util_fx.c | 50 ++--- lib_dec/evs_dec_fx.c | 128 +++++++----- lib_dec/fd_cng_dec.c | 336 +++++++++++++++----------------- lib_dec/fd_cng_dec_fx.c | 290 +++++++++++++++++++-------- lib_dec/ivas_lfe_dec_fx.c | 41 ++-- lib_dec/ivas_lfe_plc_fx.c | 17 +- lib_dec/ivas_ls_custom_dec.c | 14 +- lib_dec/ivas_masa_dec.c | 258 ++++++++++++++---------- lib_dec/ivas_mcmasa_dec.c | 8 +- lib_dec/ivas_mct_core_dec.c | 109 ++++++++--- 18 files changed, 907 insertions(+), 606 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 7dde79cee..a77a8d8e0 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1818,7 +1818,9 @@ typedef enum _DCTTYPE #define CNA_INIT_NBANDS 6 #define GAIN_Q_OFFSET_EVS 60.f +#define GAIN_Q_OFFSET_EVS_FX_Q0 60 #define GAIN_Q_OFFSET_IVAS 45.f +#define GAIN_Q_OFFSET_IVAS_FX_Q0 45 /*----------------------------------------------------------------------------------* * Bass post-filter constants diff --git a/lib_dec/FEC_adapt_codebook_fx.c b/lib_dec/FEC_adapt_codebook_fx.c index 6a8a23518..63c5559c0 100644 --- a/lib_dec/FEC_adapt_codebook_fx.c +++ b/lib_dec/FEC_adapt_codebook_fx.c @@ -64,7 +64,7 @@ Word16 FEC_SinOnset_fx( P0 = PIT_MAX; move16(); /* Should never be the case, however... */ } - ELSE if ( GT_16( P0, PIT16k_MAX ) && EQ_16( L_frame, L_FRAME16k ) ) + ELSE IF( GT_16( P0, PIT16k_MAX ) && EQ_16( L_frame, L_FRAME16k ) ) { P0 = PIT16k_MAX; move16(); /* Should never be the case, however... */ @@ -134,13 +134,11 @@ Word16 FEC_SinOnset_fx( { L_tmp = L_mult( gain, H_low[i] ); /* Q_exc*Q15 -> Q_exc */ H_low_s[i] = round_fx( L_shl( L_tmp, exp2 ) ); + move16(); } /*------------------------------------------------------------------------------------------* * Construct the harmonic part as a train of low-pass filtered pulses *------------------------------------------------------------------------------------------*/ - move16(); - move16(); - move16(); pt_exc = exc_tmp + sub( L_frame, add( add( 1, MODE1_L_FIR_FER / 2 ), P0 ) ); /* beginning of the 1st pulse */ pt_end = exc_tmp + onset_len; len = (Word16) ( pt_exc - pt_end ); @@ -165,7 +163,7 @@ Word16 FEC_SinOnset_fx( move16(); } } - Copy( &exc_tmp[L_frame - L_EXC_MEM], exc, L_EXC_MEM ); + Copy( &exc_tmp[sub( L_frame, L_EXC_MEM )], exc, L_EXC_MEM ); return Q_exc; } @@ -191,7 +189,7 @@ Word16 FEC_enhACB_fx( Copy( exc_io, exc + L_FRAME16k - L_EXC_MEM, L_EXC_MEM ); Tc = shr( bfi_pitch, 6 ); - Copy( exc + L_FRAME16k - Tc, exc + L_FRAME16k, L_SUBFR ); + Copy( exc + sub( L_FRAME16k, Tc ), exc + L_FRAME16k, L_SUBFR ); /*------------------------------------------------------------ * Decode phase information transmitted in the bitstream @@ -229,6 +227,7 @@ Word16 FEC_enhACB_fx( move16(); Tlist[0] = findpulse_fx( L_frame, exc + sub( L_frame, pit_search ), pit_search, DEC, &sign ); + move16(); /*Terr = (short) abs(pit_search-Tlist[0]-P0);*/ Terr = abs_s( sub( pit_search, add( Tlist[0], P0 ) ) ); @@ -236,6 +235,7 @@ Word16 FEC_enhACB_fx( dist_Plast = sub( Tc, Tlist[0] ); Tlist[1] = findpulse_fx( L_frame, exc + sub( L_frame, pit_search ), add( pit_search, L_SUBFR ), DEC, &sign ); + move16(); /*if(Terr > abs(Tlist[1]-Tc + P0))*/ @@ -256,7 +256,6 @@ Word16 FEC_enhACB_fx( { /* performe excitation resynchronization here */ Do_WI = FEC_synchro_exc_fx( L_frame, exc, P0, dist_Plast, Tc ); - move16(); Copy( exc + L_FRAME16k - L_EXC_MEM, exc_io, L_EXC_MEM ); } ELSE @@ -350,15 +349,16 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag * --------------------------------------------------------------------*/ L_min_energy = L_add( MAX_32, 0 ); L_tmp = L_mult( pt_exc[start_search], pt_exc[start_search] ); - L_tmp = L_mac( L_tmp, pt_exc[start_search + 1], pt_exc[start_search + 1] ); - L_tmp = L_mac( L_tmp, pt_exc[start_search + 2], pt_exc[start_search + 2] ); - L_tmp = L_mac( L_tmp, pt_exc[start_search + 3], pt_exc[start_search + 3] ); - L_tmp = L_mac( L_tmp, pt_exc[start_search + 4], pt_exc[start_search + 4] ); + L_tmp = L_mac( L_tmp, pt_exc[add( start_search, 1 )], pt_exc[add( start_search, 1 )] ); + L_tmp = L_mac( L_tmp, pt_exc[add( start_search, 2 )], pt_exc[add( start_search, 2 )] ); + L_tmp = L_mac( L_tmp, pt_exc[add( start_search, 3 )], pt_exc[add( start_search, 3 )] ); + L_tmp = L_mac( L_tmp, pt_exc[add( start_search, 4 )], pt_exc[add( start_search, 4 )] ); IF( LT_32( L_tmp, L_min_energy ) ) { L_min_energy = L_add( L_tmp, 0 ); min_pos[0] = add( add( pos, start_search ), 2 ); + move16(); } FOR( i = start_search; i < -5; i++ ) @@ -371,6 +371,7 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag L_min_energy = L_tmp; /* sets to 'L_tmp' in 1 clock */ move32(); min_pos[0] = add( add( pos, i ), 2 ); + move16(); } } @@ -407,13 +408,15 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag nb_min = 1; move16(); points_by_pos[0] = abs_s( point_to_remove ); + move16(); } ELSE { /* First position */ /* fact = (float)fabs(point_to_remove) / sqi[nb_min-2]; (nb_min*nb_min) */ - fact = mult_r( shl( abs_s( point_to_remove ), 7 ), inv_sqi[nb_min - 2] ); /*Q7 */ - points_by_pos[0] = mult_r( fact, 256 ); /*Q7 */ + fact = mult_r( shl( abs_s( point_to_remove ), 7 ), inv_sqi[sub( nb_min, 2 )] ); /*Q7 */ + points_by_pos[0] = mult_r( fact, 256 ); /*Q7 */ + move16(); total_point = points_by_pos[0]; move16(); @@ -475,9 +478,7 @@ Word16 FEC_synchro_exc_fx( /* o : do_WI flag Copy( pt_exc1, pt_exc, tmp_len ); remaining_len = sub( remaining_len, tmp_len ); pt_exc1 += tmp_len; - move16(); pt_exc += tmp_len; - move16(); /* Find point to add and Add points */ tmp16 = mult_r( *pt_exc1, -1638 ); diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index aef047af1..9591807b7 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -110,9 +110,13 @@ void FEC_clas_estim_fx( move16(); codec_mode = st_fx->codec_mode; - tcxonly = st_fx->tcxonly; /* i : tcxonly flag */ /*B*/ - narrowBand = st_fx->narrowBand; /* i : narrowband flag */ /*B*/ + move16(); + tcxonly = st_fx->tcxonly; /* i : tcxonly flag */ /*B*/ + move16(); + narrowBand = st_fx->narrowBand; /* i : narrowband flag */ /*B*/ + move16(); preemph_fac = st_fx->preemph_fac; /* i : preemphasis factor */ /*B*/ + move16(); /*------------------------------------------------------------------------* * Copy synthesized into local buffer *------------------------------------------------------------------------*/ @@ -129,13 +133,14 @@ void FEC_clas_estim_fx( 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 ) || EQ_32( last_core_brate, ACELP_23k85 ) ) && !Opt_AMR_WB && EQ_16( codec_mode, MODE2 ) && GT_16( L_frame, L_FRAME ) ) { Word16 oldLenClasBuff, newLenClasBuff; oldLenClasBuff = extract_l( L_shr( Mpy_32_16_1( L_mult0( st_fx->last_L_frame, getInvFrameLen( st_fx->L_frame ) /*Q21*/ ) /*Q21*/, L_SYN_MEM_CLAS_ESTIM /*Q0*/ ) /*Q6*/, 6 ) /*Q0*/ ); newLenClasBuff = L_SYN_MEM_CLAS_ESTIM; move16(); - lerp( &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - oldLenClasBuff], &mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM - newLenClasBuff], newLenClasBuff, oldLenClasBuff ); + lerp( &mem_syn_clas_estim[sub( L_SYN_MEM_CLAS_ESTIM, oldLenClasBuff )], &mem_syn_clas_estim[sub( L_SYN_MEM_CLAS_ESTIM, newLenClasBuff )], newLenClasBuff, oldLenClasBuff ); } synth = old_synth + L_SYN_MEM_CLAS_ESTIM; @@ -280,7 +285,7 @@ void FEC_clas_estim_fx( pos = sub( L_frame, T0 ); /* T0 [34 231] */ - Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[0] ); + Corre( &pt1[pos], &pt1[sub( pos, T0 )], T0, &cor_max[0] ); #ifdef BASOP_NOGLOB T0 = mult_r_sat( add_sat( pitch[2], pitch[3] ), 256 ); #else @@ -294,14 +299,14 @@ void FEC_clas_estim_fx( j = 16384; move16(); pos = sub( pos, T0 ); /* T0 [34 231] */ - Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[1] ); + Corre( &pt1[pos], &pt1[sub( pos, T0 )], T0, &cor_max[1] ); Ltmp = L_add( Ltmp, cor_max[1] ); IF( GT_16( pos, pos_limit ) ) { j = 10923; move16(); pos = sub( pos, T0 ); /* T0 [34 231] */ - Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[2] ); + Corre( &pt1[pos], &pt1[sub( pos, T0 )], T0, &cor_max[2] ); Ltmp = L_add( Ltmp, cor_max[2] ); } IF( GT_16( pos, pos_limit ) ) @@ -309,7 +314,7 @@ void FEC_clas_estim_fx( j = 8192; move16(); pos = sub( pos, T0 ); /* T0 [34 231] */ - Corre( &pt1[pos], &pt1[pos - T0], T0, &cor_max[3] ); + Corre( &pt1[pos], &pt1[sub( pos, T0 )], T0, &cor_max[3] ); Ltmp = L_add( Ltmp, cor_max[3] ); } } @@ -473,6 +478,8 @@ void FEC_clas_estim_fx( case ONSET: case SIN_ONSET: case VOICED_TRANSITION: + test(); + test(); IF( LT_16( fmerit1, 12780 /*0.39f Q15*/ ) ) { result = UNVOICED_CLAS; @@ -543,7 +550,7 @@ void FEC_clas_estim_fx( *decision_hyst = 200; move16(); } - ELSE if ( *decision_hyst < 0 ) + ELSE IF( *decision_hyst < 0 ) { *decision_hyst = 0; move16(); @@ -783,7 +790,7 @@ static Word16 FEC_dec_class_fx( IF( NE_16( st_fx->coder_type, VOICED ) ) { /* decode the class */ - tmpS = (Word16) get_next_indice( st_fx, FEC_BITS_CLS ); + tmpS = (Word16) get_next_indice_fx( st_fx, FEC_BITS_CLS ); IF( tmpS == 0 ) { @@ -820,7 +827,7 @@ static Word16 FEC_dec_class_fx( test(); IF( GT_16( st_fx->acelp_cfg.FEC_mode, 1 ) ) { - tmpS = (Word16) get_next_indice( st_fx, FEC_BITS_ENR ); + 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) */ tmpS = mult_r( shl( tmpS, 10 ), 24576 ); /* Q10*Q13->Q8 */ L_tmp = L_mult( tmpS, 10885 ); /* 0.332192 in Q15 */ @@ -867,7 +874,9 @@ Word16 FEC_pos_dec_fx( IF( EQ_16( st_fx->coder_type, GENERIC ) && GT_16( st_fx->acelp_cfg.FEC_mode, 2 ) ) { 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 + FEC_BITS_POS + nBits_es_Pred; + bit_pos_pitch_index = add( add( st_fx->next_bit_pos, FEC_BITS_POS ), nBits_es_Pred ); + test(); + test(); IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && EQ_16( st_fx->coder_type, GENERIC ) ) { /* Harmonic flag is present */ @@ -884,7 +893,7 @@ Word16 FEC_pos_dec_fx( pit16k_Q_dec_fx( pitch_index, 10, 1, &T0, &T0_frac, &T0_min, &T0_max, &st_fx->BER_detect ); /* decode last pulse position */ - *last_pulse_pos = (Word16) get_next_indice( st_fx, FEC_BITS_POS ); + *last_pulse_pos = (Word16) get_next_indice_fx( st_fx, FEC_BITS_POS ); /* respect the sign */ IF( GE_16( *last_pulse_pos, 128 ) ) diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 225e2c638..a029f1dfd 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -99,6 +99,7 @@ void FEC_exc_estim_fx( GSC_DEC_HANDLE hGSCDec; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif hGSCDec = st_fx->hGSCDec; @@ -107,6 +108,7 @@ void FEC_exc_estim_fx( /* nb_subfr = L_frame/L_SUBFR */ nb_subfr = shr( L_frame, 6 ); Diff_len = 0; /* to avoid compilation flags */ + move16(); set16_fx( exc_dct_in, 0, L_FRAME16k ); extrapolationFailed = 1; @@ -148,7 +150,9 @@ void FEC_exc_estim_fx( tmp_old_pitch = &st_fx->old_pitch_buf_fx[2 * NB_SUBFR16k - 1]; tmp_pitmin = PIT16k_MIN_EXTEND; + move16(); tmp_pitmax = PIT16k_MAX; + move16(); IF( EQ_16( L_frame, L_FRAME ) ) { tmp_old_pitch = &st_fx->old_pitch_buf_fx[2 * NB_SUBFR - 1]; @@ -278,7 +282,7 @@ void FEC_exc_estim_fx( test(); test(); test(); - IF( st_fx->last_coder_type == UNVOICED && LE_16( st_fx->nbLostCmpt, 3 ) ) + IF( EQ_16( st_fx->last_coder_type, UNVOICED ) && LE_16( st_fx->nbLostCmpt, 3 ) ) { /* last good frame was clearly unvoiced */ alpha = _ALPHA_UU_FX; @@ -412,7 +416,7 @@ void FEC_exc_estim_fx( /* last pitch cycle of the previous frame is repeatedly copied up to an extra subframe */ - tmp = (Word16) ( ( exc + L_frame + L_SUBFR ) - pt_exc ); + tmp = extract_l( ( exc + add( L_frame, L_SUBFR ) ) - pt_exc ); FOR( i = 0; i < tmp; i++ ) { *pt_exc++ = *pt1_exc++; @@ -430,8 +434,8 @@ void FEC_exc_estim_fx( test(); IF( ( cond1 < 0 ) && ( new_pit > 0 ) && ( cond2 != 0 ) && ( cond3 > 0 ) && extrapolationFailed == 0 ) { - Copy( exc, exc - L_frame - L_SUBFR, L_frame + L_SUBFR ); - PulseResynchronization_fx( exc - L_frame - L_SUBFR, exc, L_frame, nb_subfr, L_deposit_h( Tc /*Q0*/ ) /*15Q16*/, L_deposit_h( new_pit /*Q0*/ ) /*15Q16*/ ); + Copy( exc, exc - add( L_frame, L_SUBFR ), add( L_frame, L_SUBFR ) ); + PulseResynchronization_fx( exc - add( L_frame, L_SUBFR ), exc, L_frame, nb_subfr, L_deposit_h( Tc /*Q0*/ ) /*15Q16*/, L_deposit_h( new_pit /*Q0*/ ) /*15Q16*/ ); } } test(); @@ -457,7 +461,8 @@ void FEC_exc_estim_fx( /* end of the frame gain */ test(); - + test(); + test(); IF( !( GE_16( st_fx->last_good, VOICED_CLAS ) && LT_16( st_fx->last_good, INACTIVE_CLAS ) && NE_16( st_fx->last_coder_type, AUDIO ) && GT_16( st_fx->nbLostCmpt, 1 ) ) ) { st_fx->lp_gainp_fx = shr( alpha, 1 ); /* alpha in Q15 */ @@ -504,13 +509,13 @@ void FEC_exc_estim_fx( move16(); /*ptr init*/ FOR( i = 0; i < Len; i++ ) { - exc_dct_in[i + Diff_len] = mult_r( exc_dct_in[i + Diff_len], sm_table_fx[i] ); + exc_dct_in[add( i, Diff_len )] = mult_r( exc_dct_in[add( i, Diff_len )], sm_table_fx[i] ); move16(); } FOR( ; i < max_len; i++ ) { - exc_dct_in[i + Diff_len] = 0; + exc_dct_in[add( i, Diff_len )] = 0; move16(); } Diff_len = add( Diff_len, 1 ); @@ -527,14 +532,16 @@ void FEC_exc_estim_fx( { st_fx->GSC_noisy_speech = st_fx->Last_GSC_noisy_speech_flag; move16(); + /* st_fx->L_frame / L_SUBFR */ + tmp = shr( st_fx->L_frame, 6 ); /* Replication of the last spectrum, with a slight downscaling of its dynamic */ - if ( st_fx->element_mode == EVS_MONO ) + IF( st_fx->element_mode == EVS_MONO ) { - gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); + gsc_dec_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); } - else + ELSE { - gsc_dec_ivas_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc ); + gsc_dec_ivas_fx( st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, tmp, st_fx->last_coder_type, &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 */ @@ -653,6 +660,7 @@ void FEC_exc_estim_fx( #else *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); #endif + move16(); } FOR( i = 0; i < L_frame; i++ ) @@ -665,6 +673,7 @@ void FEC_exc_estim_fx( #else *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); #endif + move16(); /* gain -= step; */ L_tmp2 = L_sub( L_tmp2, L_step ); tmp = round_fx( L_tmp2 ); @@ -679,6 +688,7 @@ void FEC_exc_estim_fx( #else *pt_exc++ = round_fx( L_shl( L_tmp, exp ) ); #endif + move16(); } } @@ -699,7 +709,6 @@ void FEC_exc_estim_fx( /* For voiced and generic signals - prepare a HP filter for the random part of excitation */ /* tmp = -(1-tilt_code) to correctly represent 1.0000 */ tmp = add( st_fx->tilt_code_fx, -32768 ); - move16(); FOR( i = 0; i < MODE1_L_FIR_FER; i++ ) { hp_filt[i] = msu_r( 0, tmp, h_high_fx[i] ); @@ -708,7 +717,6 @@ void FEC_exc_estim_fx( /* HP filter the random part of the excitation and add the adaptive part */ pt_exc = exc2_buf; - move16(); FOR( i = 0; i < L_frame; i++ ) { /* exc2[i] = exc[i] + dotp( &exc2_buf[i], hp_filt, MODE1_L_FIR_FER );*/ @@ -740,7 +748,6 @@ void FEC_exc_estim_fx( { IF( EQ_16( L_frame, L_FRAME ) ) { - interp_code_5over2_fx( exc, bwe_exc, L_frame ); } ELSE @@ -775,7 +782,9 @@ void FEC_exc_estim_fx( { gain_dec_bfi_fx( hAmrwb_IO->past_qua_en_fx ); } - st_fx->bfi_pitch_fx = pitch_buf[( L_frame / L_SUBFR ) - 1]; + /* L_frame / L_SUBFR */ + tmp = shr( L_frame, 6 ); + st_fx->bfi_pitch_fx = pitch_buf[sub( tmp, 1 )]; move16(); st_fx->bfi_pitch_frame = st_fx->L_frame; move16(); diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index eec1d3be8..debb8aad3 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -129,7 +129,7 @@ void con_acelp_fx( * PLC: [ACELP:Extrapolate Pitch Lag] *------------------------------------------------------------------------*/ - IF( EQ_16( st->flagGuidedAcelp, 1 ) ) + if ( EQ_16( st->flagGuidedAcelp, 1 ) ) { T0 = st->guidedT0; move16(); @@ -142,13 +142,13 @@ void con_acelp_fx( st->plc_use_future_lag, &extrapolationFailed, st->nb_subfr ); T0 = round_fx( predPitchLag ); - IF( NE_16( extrapolationFailed, 0 ) ) + IF( extrapolationFailed != 0 ) { /*------------------------------------------------------------------------* * - Construct adaptive codebook from side information * *------------------------------------------------------------------------*/ - IF( EQ_16( st->flagGuidedAcelp, 0 ) ) + IF( st->flagGuidedAcelp == 0 ) { nSubframes = 0; move16(); @@ -174,7 +174,7 @@ void con_acelp_fx( tmp_tc = st->old_fpitch; move32(); /* take the previous frame last pitch*/ - IF( GT_16( nSubframes, 0 ) ) + if ( nSubframes > 0 ) { tmp_tc = L_deposit_h( st->guidedT0 ); /* take the transmit pitch*/ } @@ -183,7 +183,7 @@ void con_acelp_fx( * PLC: calculate damping factor */ alpha = Damping_fact_fx( coder_type, st->nbLostCmpt, st->last_good, stab_fac, &( st->Mode2_lp_gainp ), 0 ); /*Q14*/ st->cummulative_damping = shl( mult( st->cummulative_damping, alpha ), 1 ); /*shl(Q15*Q14,1)=shl(Q14,1) = Q15*/ - IF( EQ_16( st->nbLostCmpt, 1 ) ) + if ( EQ_16( st->nbLostCmpt, 1 ) ) { st->cummulative_damping = 32767 /*1.f Q15*/; /*Q15*/ move16(); @@ -212,20 +212,20 @@ void con_acelp_fx( test(); test(); test(); - IF( GT_16( T0, 0 ) && ( NE_16( T0, Tc ) ) && LT_16( tmp, 0 ) && EQ_16( extrapolationFailed, 0 ) ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( tmp < 0 ) && extrapolationFailed == 0 ) { fUseExtrapolatedPitch = 1; move16(); } pt_exc = exc; - IF( NE_16( st->enableGplc, 0 ) ) + if ( st->enableGplc != 0 ) { pt_exc = &exc[imult1616( nSubframes, L_SUBFR )]; } pt1_exc = pt_exc - Tc; - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + IF( fUseExtrapolatedPitch != 0 ) { /* Required because later pt1_exc[1] used in filtering points to exc[0]. To make it safe also for GPL pt_exc is used instead of exc */ pt_exc[0] = 0; @@ -268,7 +268,7 @@ void con_acelp_fx( } } - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { pt1_exc = harmonic_exc_buf; } @@ -285,7 +285,7 @@ void con_acelp_fx( * PLC: Resync pulse positions. *-------------------------------------------------------*/ - IF( GT_16( nSubframes, 0 ) ) + IF( nSubframes > 0 ) { pitch_buf[0] = L_deposit_h( st->guidedT0 ); move32(); @@ -293,7 +293,7 @@ void con_acelp_fx( move32(); } - IF( GT_16( nSubframes, 0 ) ) + IF( nSubframes > 0 ) { pitch_buf[3] = pitch_buf[2] = pitch_buf[1]; /* do not resync on second half of frame */ move32(); @@ -307,7 +307,7 @@ void con_acelp_fx( } ELSE { - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + IF( fUseExtrapolatedPitch != 0 ) { get_subframe_pitch( st->nb_subfr, st->old_fpitch, predPitchLag, pitch_buf ); @@ -325,7 +325,7 @@ void con_acelp_fx( *------------------------------------------------------------*/ pt_exc = exc + st->L_frame; pt1_exc = pt_exc - T0; - IF( EQ_16( T0, 0 ) ) + if ( T0 == 0 ) { pt1_exc = pt_exc - Tc; } @@ -341,11 +341,11 @@ void con_acelp_fx( * PLC: update the floating point pitch for consecutive loss *-------------------------------------------------------*/ - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + IF( fUseExtrapolatedPitch != 0 ) { st->old_fpitch = predPitchLag; move32(); - IF( EQ_16( st->flagGuidedAcelp, 1 ) ) + if ( EQ_16( st->flagGuidedAcelp, 1 ) ) { st->old_fpitch = L_deposit_h( T0 ); } @@ -531,7 +531,7 @@ void con_acelp_fx( /*gainCNG=st->cngTDLevel/gainSynthDeemph;*/ BASOP_Util_Divide_MantExp( st->cngTDLevel, st->cngTDLevel_e, gainSynthDeemph, gainSynthDeemph_e, &gainCNG, &gainCNG_e ); gainCNG_e = sub( gainCNG_e, 15 - 5 ); /*Q15->Q5*/ - IF( EQ_16( gainCNG, 0 ) ) + if ( gainCNG == 0 ) { gainCNG_e = 0; move16(); @@ -554,9 +554,9 @@ void con_acelp_fx( /*in case of overflow:*/ test(); #ifdef BASOP_NOGLOB - IF( ( EQ_16( shl_sat( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && EQ_16( gainCNG, MAXVAL_WORD16 ) ) + if ( ( EQ_16( shl_sat( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && EQ_16( gainCNG, MAXVAL_WORD16 ) ) #else - IF( ( EQ_16( shl( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && EQ_16( gainCNG, MAXVAL_WORD16 ) ) + if ( ( EQ_16( shl( ftmp, sub( gainCNG_e, 1 ) ), MAXVAL_WORD16 ) ) && EQ_16( gainCNG, MAXVAL_WORD16 ) ) #endif { tmp_16 = 1; @@ -564,7 +564,7 @@ void con_acelp_fx( } BASOP_SATURATE_WARNING_ON_EVS - IF( GT_16( tmp_16, 0 ) ) + IF( tmp_16 > 0 ) { gainCNG = ftmp /*Q0*/; move16(); @@ -620,7 +620,7 @@ void con_acelp_fx( s_32 = sub( s_32, 7 ); /*tmp_32 is Q31 * 2^s_32 */ /*assure doing Isqrt not for 0*/ - IF( NE_32( tmp_32, 0 ) ) + IF( tmp_32 != 0 ) { s_gain_inov = s_32; move16(); @@ -646,7 +646,7 @@ void con_acelp_fx( step_32 = L_shr( step_32, 7 ); /* 15Q16 */ test(); - IF( ( EQ_16( st->last_good, UNVOICED_CLAS ) ) && ( NE_16( coder_type, UNVOICED ) ) ) /* Attenuate somewhat on unstable unvoiced */ + if ( ( EQ_16( st->last_good, UNVOICED_CLAS ) ) && ( NE_16( coder_type, UNVOICED ) ) ) /* Attenuate somewhat on unstable unvoiced */ { gain_inov = mult_r( gain_inov, 26214 /*0.8f Q15*/ ); /*Q15 * 2^s_gain_inov*/ } @@ -859,15 +859,15 @@ void con_acelp_fx( FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { E_UTIL_synthesis( synthScaling, p_A, &exc[i_subfr], &syn[i_subfr], L_SUBFR, mem_syn, 1, M ); - p_A = p_A + add( M, 1 ); + p_A += ( M + 1 ); } Copy( mem_syn, mem_syn2, M ); /* synthesize ola*/ - E_UTIL_synthesis( synthScaling, p_A - add( M, 1 ), &exc[i_subfr], &syn[i_subfr], shr( st->L_frame, 1 ), mem_syn2, 0, M ); + E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc[i_subfr], &syn[i_subfr], shr( st->L_frame, 1 ), mem_syn2, 0, M ); } test(); - IF( GT_16( st->nbLostCmpt, 5 ) && GT_16( s_16, 0 ) ) + IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn, exc and synthesis*/ Scale_sig( mem_syn, M, negate( s_16 ) ); @@ -950,7 +950,7 @@ void con_acelp_fx( FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { E_UTIL_synthesis( synthScaling, p_A, &exc_unv[i_subfr], &syn_unv[i_subfr], L_SUBFR, mem_syn_unv, 1, M ); - p_A = p_A + add( M, 1 ); + p_A += ( M + 1 ); } Copy( mem_syn_unv, st->mem_syn_unv_back, M ); @@ -958,11 +958,11 @@ void con_acelp_fx( { Copy( mem_syn_unv, mem_syn, M ); /* unvoiced for ola */ - E_UTIL_synthesis( synthScaling, p_A - add( M, 1 ), &exc_unv[i_subfr], &syn_unv[i_subfr], shr( st->L_frame, 1 ), mem_syn_unv, 0, M ); + E_UTIL_synthesis( synthScaling, p_A - ( M + 1 ), &exc_unv[i_subfr], &syn_unv[i_subfr], shr( st->L_frame, 1 ), mem_syn_unv, 0, M ); } test(); - IF( GT_16( st->nbLostCmpt, 5 ) && GT_16( s_16, 0 ) ) + IF( GT_16( st->nbLostCmpt, 5 ) && ( s_16 > 0 ) ) { /*scale back mem_syn_unv, exc_unv and synthesis*/ Scale_sig( mem_syn_unv, M, negate( s_16 ) ); @@ -1067,10 +1067,10 @@ void con_acelp_fx( /* save last half frame if next frame is TCX */ bufferCopyFx( syn + st->L_frame, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); - Copy( syn + sub( st->L_frame, add( M, 1 ) ), st->syn, add( 1, M ) ); + Copy( syn + sub(st->L_frame, M + 1), st->syn, 1 + M ); /* update old_Aq */ - Copy( p_A - add( M, 1 ), st->old_Aq_12_8_fx, add( M, 1 ) ); + Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); Copy( syn + st->L_frame, hTcxDec->syn_Overl, shr( st->L_frame, 1 ) ); @@ -1097,7 +1097,7 @@ void con_acelp_fx( } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); + hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub(W2, add(1, sub(i, W2 )))].v.im, w[sub(W2, add(1, sub( i, W2 )))].v.im ), hHQ_core->old_out_LB_fx[add(i, n)] ) ); move16(); } set16_fx( &hHQ_core->old_out_LB_fx[add( W1, n )], 0, n ); @@ -1186,7 +1186,7 @@ static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc BASOP_SATURATE_WARNING_ON_EVS } /*if there is energy in scale_syn, then increase precision*/ - IF( GT_16( abs_s( tmp ), 0 ) ) + IF( abs_s( tmp ) > 0 ) { sf_mem_syn = getScaleFactor16( mem_syn, M ); /*sf_exc = getScaleFactor16(exc, add(shr(len,1),len));*/ /*this returns 0 if signal is 0*/ @@ -1196,7 +1196,7 @@ static void memsynPrecission_fx( Word16 nbLostCmpt, Word16 *mem_syn, Word16 *exc max = s_max( max, abs_s( exc[k] ) ); } sf_exc = norm_s( max ); - IF( EQ_16( max, 0 ) ) + if ( max == 0 ) { sf_exc = 16; move16(); diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index fa30326ca..8849f7b63 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -72,7 +72,7 @@ static void calcGainc_fx( Word16 *exc, Word16 Q_exc, Word32 old_fpitch, Word16 L tmp16 = BASOP_Util_Divide3216_Scale( L_tmp /*Q31,norm,tmp_e*/, shl( L_subfr, 1 ) /*Q15,15*/, &tmp2_e ) /*Q15,tmp2_e+tmp_e-15*/; tmp_e = sub( add( tmp2_e, tmp_e ), 15 ); - IF( NE_16( tmp16, 0 ) ) + IF( tmp16 != 0 ) { tmp16 = Sqrt16( tmp16, &tmp_e ); /*Q15,norm,tmp_e*/ } @@ -294,7 +294,7 @@ void con_tcx_fx( mem = synth[sub( -L_frame, 1 )]; move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, add( M, 1 ) ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) @@ -324,7 +324,7 @@ void con_tcx_fx( tmp16 = 0; move16(); - IF( GT_32( st->output_Fs, 25600 ) ) + if ( GT_32( st->output_Fs, 25600 ) ) { tmp16 = 1; move16(); @@ -345,7 +345,7 @@ void con_tcx_fx( test(); test(); - IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -371,7 +371,7 @@ void con_tcx_fx( test(); test(); test(); - IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) && EQ_16( extrapolationFailed, 0 ) ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -384,7 +384,7 @@ void con_tcx_fx( pt_exc = exc + offset; pt1_exc = pt_exc - Tc; - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { pt_exc = buf; } @@ -479,7 +479,7 @@ void con_tcx_fx( move16(); } - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { pt1_exc = buf; } @@ -490,7 +490,7 @@ void con_tcx_fx( move16(); } - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { get_subframe_pitch( st->nb_subfr, st->old_fpitch, @@ -513,7 +513,7 @@ void con_tcx_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { pt_exc = exc + L_frame; - IF( EQ_16( T0, 0 ) ) + IF( T0 == 0 ) { pt1_exc = pt_exc - Tc; } @@ -530,7 +530,7 @@ void con_tcx_fx( } } - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { st->old_fpitchFB = predPitchLag; move32(); @@ -712,7 +712,7 @@ void con_tcx_fx( { tmp16 = 19661 /*0.6f Q15*/; move16(); - IF( LE_32( st->output_Fs, 16000 ) ) + if ( LE_32( st->output_Fs, 16000 ) ) { tmp16 = 6554 /*0.2f Q15*/; move16(); @@ -780,7 +780,7 @@ void con_tcx_fx( move16(); gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); #endif - IF( NE_16( st->tcxonly, 0 ) ) + IF( st->tcxonly != 0 ) { /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, @@ -812,7 +812,7 @@ void con_tcx_fx( gain32 = L_add( st->Mode2_lp_gainc, 0 ); /* start-of-the-frame gain - Q16*/ test(); - IF( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) + if ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) && EQ_16( st->use_partial_copy, 1 ) ) { gain32 = Mpy_32_16_1( gain32, 22938 /*0.7f Q15*/ ); } @@ -868,7 +868,7 @@ void con_tcx_fx( #ifdef BASOP_NOGLOB /* Critical Overflow */ gain_inov = round_fx_sat( L_tmp ); /*Q15,gain_inov_e*/ #else - gain_inov = round_fx( L_tmp ); /*Q15,gain_inov_e*/ + gain_inov = round_fx( L_tmp ); /*Q15,gain_inov_e*/ #endif } @@ -918,10 +918,10 @@ void con_tcx_fx( FOR( i = 0; i < tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat( exc[i], shl_sat( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ + exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #else - exc[i] = add( exc[i], shl( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ + exc[i] = add( exc[i], shl( noise[i + ( L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #endif } @@ -1290,7 +1290,7 @@ void con_tcx_ivas_fx( mem = synth[sub( -L_frame, 1 )]; move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); - Copy( st->old_Aq_12_8_fx, A_local, add( M, 1 ) ); + Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); offset = shr( L_frame, 1 ); IF( GE_16( st->last_good, UNVOICED_TRANSITION ) ) @@ -1320,7 +1320,7 @@ void con_tcx_ivas_fx( tmp16 = 0; move16(); - IF( GT_32( st->output_Fs, 25600 ) ) + if ( GT_32( st->output_Fs, 25600 ) ) { tmp16 = 1; move16(); @@ -1341,7 +1341,7 @@ void con_tcx_ivas_fx( test(); test(); - IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -1368,7 +1368,7 @@ void con_tcx_ivas_fx( test(); test(); test(); - IF( GT_16( T0, 0 ) && NE_16( T0, Tc ) && LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) && EQ_16( extrapolationFailed, 0 ) ) + if ( ( T0 > 0 ) && ( NE_16( T0, Tc ) ) && ( LT_32( L_deposit_h( abs_s( sub( T0, Tc ) ) ) /*Q16*/, L_mult( 4915 /*.15f Q15*/ /*Q15*/, Tc /*Q0*/ ) /*Q16*/ ) ) && ( extrapolationFailed == 0 ) ) { fUseExtrapolatedPitch = 1; move16(); @@ -1381,7 +1381,7 @@ void con_tcx_ivas_fx( pt_exc = exc + offset; pt1_exc = pt_exc - Tc; - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { pt_exc = buf; } @@ -1446,7 +1446,7 @@ void con_tcx_ivas_fx( move16(); } - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { pt1_exc = buf; } @@ -1457,7 +1457,7 @@ void con_tcx_ivas_fx( move16(); } - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + IF( fUseExtrapolatedPitch != 0 ) { get_subframe_pitch( st->nb_subfr, st->old_fpitch, @@ -1480,7 +1480,7 @@ void con_tcx_ivas_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { pt_exc = exc + L_frame; - IF( EQ_16( T0, 0 ) ) + IF( T0 == 0 ) { pt1_exc = pt_exc - Tc; } @@ -1497,7 +1497,7 @@ void con_tcx_ivas_fx( } } - IF( NE_16( fUseExtrapolatedPitch, 0 ) ) + if ( fUseExtrapolatedPitch != 0 ) { st->old_fpitchFB = predPitchLag; move32(); @@ -1638,7 +1638,7 @@ void con_tcx_ivas_fx( alpha_coh = negate( alpha_coh ); } - FOR( i = 0; i < add( L_frame, L_FIR_FER2 - 1 ); i++ ) + FOR( i = 0; i < L_frame + L_FIR_FER2 - 1; i++ ) { random1 = Random( &tmpSeed1 ); random2 = Random( &tmpSeed1 ); @@ -1653,7 +1653,7 @@ void con_tcx_ivas_fx( move16(); } - FOR( ; i < add( add( L_frame, shr( L_frame, 1 ) ), 2 * L_FIR_FER2 ); i++ ) + FOR( ; i < L_frame + ( L_frame / 2 ) + 2 * L_FIR_FER2; i++ ) { random1 = Random( &tmpSeed1 ); random2 = Random( &tmpSeed1 ); @@ -1693,7 +1693,7 @@ void con_tcx_ivas_fx( { tmp16 = 19661 /*0.6f Q15*/; move16(); - IF( LE_32( st->output_Fs, 16000 ) ) + if ( LE_32( st->output_Fs, 16000 ) ) { tmp16 = 6554 /*0.2f Q15*/; move16(); @@ -1762,7 +1762,7 @@ void con_tcx_ivas_fx( move16(); gainSynthDeemph = getLevelSynDeemph_fx( &( tmp16 ), A_local, M, shr( L_frame, 2 ), st->preemph_fac, 1, &gainSynthDeemph_e ); #endif - IF( NE_16( st->tcxonly, 0 ) ) + IF( st->tcxonly != 0 ) { /* gainCNG = st->conCngLevelBackgroundTrace/gainSynthDeemph; */ BASOP_Util_Divide_MantExp( hTcxDec->conCngLevelBackgroundTrace, @@ -1905,10 +1905,10 @@ void con_tcx_ivas_fx( FOR( i = 0; i < tmp16; i++ ) { #ifdef BASOP_NOGLOB - exc[i] = add_sat( exc[i], shl_sat( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ + exc[i] = add_sat( exc[i], shl_sat( noise[i + ( L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #else - exc[i] = add( exc[i], shl( noise[add( i, L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ + exc[i] = add( exc[i], shl( noise[i + ( L_FIR_FER2 / 2 )], add( Q_exc, noise_e ) ) ); /*Q1*/ move16(); #endif } diff --git a/lib_dec/er_scale_syn_fx.c b/lib_dec/er_scale_syn_fx.c index a8c76aa85..ed78d8842 100644 --- a/lib_dec/er_scale_syn_fx.c +++ b/lib_dec/er_scale_syn_fx.c @@ -41,7 +41,7 @@ Word16 Damping_fact_fx( /* o : damping factor #endif - IF( EQ_16( core, ACELP_CORE ) ) + IF( core == ACELP_CORE ) { alpha = mult_r( _ALPHA_VT_FX, 16384 ); /* rapid convergence to 0 */ /*Q14*/ test(); @@ -96,6 +96,7 @@ Word16 Damping_fact_fx( /* o : damping factor /*gain = (float)sqrt( *lp_gainp );*/ /* move pitch gain towards 1 for voiced to remove energy fluctuations */ /*BASOP_Util_Sqrt_MantExp(lp_gainp,&lp_gainp_E);*/ s_gainp = 31 - 29; + move16(); gain32 = Sqrt32( lp_tmp, &s_gainp ); #ifdef BASOP_NOGLOB @@ -125,11 +126,11 @@ Word16 Damping_fact_fx( /* o : damping factor ELSE { alpha = mac_r( 375809632l /*0.35f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/ - IF( LT_16( nbLostCmpt, 2 ) ) + if ( LT_16( nbLostCmpt, 2 ) ) { alpha = mac_r( 751619264l /*0.70f Q30*/, 4915 /*0.3f Q14*/, stab_fac ); /*Q14*/ } - IF( EQ_16( nbLostCmpt, 2 ) ) + if ( EQ_16( nbLostCmpt, 2 ) ) { alpha = mac_r( 483183808l /*0.45f Q30*/, 6554 /*0.4f Q14*/, stab_fac ); /*Q14*/ } diff --git a/lib_dec/er_sync_exc_fx.c b/lib_dec/er_sync_exc_fx.c index f01c98655..f4535152f 100644 --- a/lib_dec/er_sync_exc_fx.c +++ b/lib_dec/er_sync_exc_fx.c @@ -42,7 +42,7 @@ static Word16 GetMinimumPosition_fx( iMinEnergyPos = center; move16(); - IF( GT_16( filterLength, 0 ) ) + IF( filterLength > 0 ) { center = add( center, 1 ); energy = L_deposit_l( 0 ); @@ -77,7 +77,7 @@ static Word16 GetMinimumPosition_fx( tmptest = L_sub( energy, MAXVAL_WORD32 ); #endif BASOP_SATURATE_WARNING_ON_EVS - IF( EQ_32( tmptest, 0 ) ) + IF( tmptest == 0 ) { tmp_e = add( tmp_e, 1 ); energy = L_shr( energy_old, 2 ); @@ -87,7 +87,7 @@ static Word16 GetMinimumPosition_fx( energy = L_mac( energy, tmp16, tmp16 ); } - IF( LT_32( energy, 0 ) ) + IF( energy < 0 ) { iMinEnergyPos = add( i, center ); tmp_e = 0; @@ -119,7 +119,7 @@ static Word16 FindMaxPeak_fx( move16(); FOR( i = 1; i < length; i++ ) { - IF( GT_16( abs_s( x[i] ), abs_s( x[iMax] ) ) ) + if ( GT_16( abs_s( x[i] ), abs_s( x[iMax] ) ) ) { iMax = i; move16(); @@ -152,7 +152,7 @@ static void AddSamples_fx( FOR( i = 0; i < nb_min; i++ ) { /* Copy section */ - FOR( j = sub( min_pos[i], last_min_pos ); j > 0; j-- ) + FOR( j = min_pos[i] - last_min_pos; j > 0; j-- ) { *pt_dest++ = *pt_src++; move16(); @@ -252,7 +252,7 @@ void PulseResynchronization_fx( test(); test(); test(); - IF( ( LT_32( L_deposit_h( nFrameLength ), pitchStart ) ) || LE_32( pitchStart, 0 ) || LE_32( pitchEnd, 0 ) || ( LT_16( nSubframes, 1 ) ) || ( GT_16( nSubframes, 5 ) ) || ( LE_32( Mpy_32_16_1( pitchEnd, add( nSubframes, 1 ) ), Mpy_32_16_1( pitchStart, sub( nSubframes, 1 ) ) ) ) || ( src_exc - dst_exc >= 0 ) ) + IF( ( LT_32( L_deposit_h( nFrameLength ), pitchStart ) ) || ( pitchStart <= 0 ) || ( pitchEnd <= 0 ) || ( LT_16( nSubframes, 1 ) ) || ( GT_16( nSubframes, 5 ) ) || ( LE_32( Mpy_32_16_1( pitchEnd, add( nSubframes, 1 ) ), Mpy_32_16_1( pitchStart, sub( nSubframes, 1 ) ) ) ) || ( src_exc - dst_exc >= 0 ) ) { /* This is error handling and recovery that should never occur. */ test(); @@ -274,7 +274,7 @@ void PulseResynchronization_fx( /*samplesDelta = 0.5f*pitchDelta*nFrameLength*(nSubframes+1)*freqStart;*/ /* pitchDelta*freqStart = ((pitchEnd - pitchStart)/roundedPitchStart)/nSubframes */ tmp16 = shl( roundedPitchStart, 2 ); /*Q0*/ - IF( EQ_16( nSubframes, 5 ) ) + if ( EQ_16( nSubframes, 5 ) ) { tmp16 = add( tmp16, roundedPitchStart ); /*Q0*/ /*tmp16=roundedPitchStart*nSubframes*/ } @@ -332,7 +332,7 @@ void PulseResynchronization_fx( tmp32 = L_add( tmp32, 65536l /*1.f Q16*/ ); k = extract_h( tmp32 ); test(); - IF( GE_16( k, 0 ) && LE_16( add( k, 1 ), NB_PULSES_MAX ) ) + IF( ( k >= 0 ) && LE_16( add( k, 1 ), NB_PULSES_MAX ) ) { absPitchDiff = L_abs( L_sub( L_deposit_h( roundedPitchStart ), pitchEnd ) ); /*Q16*/ @@ -370,7 +370,7 @@ void PulseResynchronization_fx( cycleDelta_e = add( tmp_e, freqStart_e ); tmp32_a = L_shl( tmp32, cycleDelta_e ); roundedCycleDelta = extract_h( L_abs( tmp32_a ) ); - IF( LT_32( tmp32, 0 ) ) + if ( tmp32 < 0 ) { roundedCycleDelta = negate( roundedCycleDelta ); } @@ -383,7 +383,7 @@ void PulseResynchronization_fx( #else cycleDelta = round_fx( tmp32 ); /*Q15, cycleDelta_e*/ #endif - IF( EQ_16( cycleDelta, 0 ) ) + if ( cycleDelta == 0 ) { cycleDelta_e = 0; move16(); @@ -415,7 +415,7 @@ void PulseResynchronization_fx( iDeltaSamples[i] = roundedCycleDelta; move16(); roundedCycleDelta = extract_h( cycleDelta32 ); /* cycleDelta32 should never be < 0 here */ - iDeltaSamples[sub( i, 1 )] = roundedCycleDelta; + iDeltaSamples[i - 1] = roundedCycleDelta; move16(); } ELSE @@ -449,7 +449,7 @@ void PulseResynchronization_fx( iMinPos1 = add( iMinPos1, T0 ); - IF( LT_16( nSamplesDelta, 0 ) ) + IF( nSamplesDelta < 0 ) { /* Find the location of the minimum energy before the first pulse */ diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 09a7842d1..ee0c52b8e 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -71,7 +71,7 @@ void minimumStatistics_fx( /* compute optimal factor aOpt for recursive smoothing of frame minima */ tmp2 = BASOP_Util_Add_MantExp( *lastFrameLevel, *lastFrameLevel_e, negate( *noiseEstimate ), noiseEstimate_e, &tmp ); - IF( GE_16( tmp, 0 ) ) + IF( tmp >= 0 ) { /* aOpt = *noiseEstimate / *lastFrameLevel; */ aOpt = BASOP_Util_Divide1616_Scale( *noiseEstimate, *lastFrameLevel, &aOpt_e ); @@ -85,7 +85,7 @@ void minimumStatistics_fx( } aOpt = mult_r( aOpt, aOpt ); /* Q15 */ aOpt_e = shl( aOpt_e, 1 ); - IF( EQ_16( aOpt, 0 ) ) + if ( aOpt == 0 ) { aOpt_e = 0; move16(); @@ -100,7 +100,7 @@ void minimumStatistics_fx( tmp = *currLevelIndex; move16(); move16(); - IF( EQ_16( tmp, 0 ) ) + if ( tmp == 0 ) { tmp = PLC_MIN_STAT_BUFF_SIZE; move16(); @@ -118,7 +118,7 @@ void minimumStatistics_fx( tmp = mult_r( tmp, currentFrameLevel ); /*Q_tmp = tmp2 + currentFrameLevel_e*/ tmp2 = add( tmp2, currentFrameLevel_e ); - IF( EQ_16( tmp, 0 ) ) + if ( tmp == 0 ) { tmp2 = 0; move16(); @@ -132,7 +132,7 @@ void minimumStatistics_fx( p = *noiseLevelIndex; move16(); tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( f ), *new_noiseEstimate_e, &tmp ); - IF( GE_16( tmp, 0 ) ) + IF( tmp >= 0 ) { /*rescale noiseLevelMemory*/ @@ -159,7 +159,7 @@ void minimumStatistics_fx( FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) { tmp2 = BASOP_Util_Add_MantExp( noiseLevelMemory[p], noiseLevelMemory_e[p], negate( noiseLevelMemory[i] ), noiseLevelMemory_e[i], &tmp ); - IF( GT_16( tmp, 0 ) ) + if ( tmp > 0 ) { p = i; move16(); @@ -178,7 +178,7 @@ void minimumStatistics_fx( p = add( *currLevelIndex, 1 ); *currLevelIndex = add( *currLevelIndex, 1 ); move16(); - IF( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) + if ( EQ_16( *currLevelIndex, PLC_MIN_STAT_BUFF_SIZE ) ) { *currLevelIndex = 0; move16(); @@ -261,7 +261,7 @@ Word16 getLevelSynDeemph_fx( /*10Q5*/ tmp16 = 32767 /*1.0f Q15*/; move16(); - IF( GT_16( numLoops, 1 ) ) + if ( GT_16( numLoops, 1 ) ) { tmp16 = div_s( 1, numLoops ); } @@ -295,7 +295,7 @@ void genPlcFiltBWAdap_fx( IF( EQ_32( sr_core, INT_FS_16k ) ) { - IF( EQ_16( type, 0 ) ) + IF( type == 0 ) { *lpFiltAdapt++ = 7282 /* 0.4000f/(2.f*0.4000f+1.f) Q15*/; move16(); @@ -322,7 +322,7 @@ void genPlcFiltBWAdap_fx( } ELSE /*sr_core = INT_FS_12k8 */ { - IF( EQ_16( type, 0 ) ) + IF( type == 0 ) { *lpFiltAdapt++ = 5899 /* 0.2813f/(2.f*0.2813f+1.f) Q15*/; move16(); @@ -404,7 +404,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); test(); test(); - IF( ( GT_16( st->last_core, ACELP_CORE ) && NE_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) + if ( ( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified != 0 ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) { /* no updates needed here, because already updated in last good frame */ st->plc_use_future_lag = 1; @@ -417,7 +417,7 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); st->last_core = ACELP_CORE; move16(); - IF( st->Opt_AMR_WB ) + if ( st->Opt_AMR_WB ) { core = ACELP_CORE; move16(); @@ -429,7 +429,7 @@ Word16 GetPLCModeDecision_ivas_fx( { core = ACELP_CORE; move16(); - IF( GT_16( st->nbLostCmpt, 1 ) ) + if ( GT_16( st->nbLostCmpt, 1 ) ) { core = st->last_core_bfi; move16(); @@ -461,7 +461,7 @@ Word16 GetPLCModeDecision_ivas_fx( Word32 pitch; pitch = L_deposit_h( 0 ); - IF( GT_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) + if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { pitch = L_add( st->old_fpitch, 0 ); } @@ -479,7 +479,7 @@ Word16 GetPLCModeDecision_ivas_fx( test(); test(); test(); - IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( GT_16( numIndices, 0 ) && ( ( LE_16( st->last_good, 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*/ ) ) ) ) + IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( 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, 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(); @@ -492,10 +492,10 @@ Word16 GetPLCModeDecision_ivas_fx( move16(); } } - ELSE IF( NE_16( st->last_core, ACELP_CORE ) ) + ELSE IF( st->last_core != ACELP_CORE ) { test(); - IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) + if ( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = st->last_core; move16(); @@ -533,7 +533,7 @@ Word16 GetPLCModeDecision_fx( move16(); test(); test(); - IF( ( GT_16( st->last_core, ACELP_CORE ) && NE_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) + if ( ( st->last_core > ACELP_CORE && hTcxDec->tcxltp_last_gain_unmodified != 0 ) || ( EQ_16( st->flagGuidedAcelp, 1 ) ) ) { /* no updates needed here, because already updated in last good frame */ st->plc_use_future_lag = 1; @@ -546,7 +546,7 @@ Word16 GetPLCModeDecision_fx( move16(); st->last_core = ACELP_CORE; move16(); - IF( st->Opt_AMR_WB ) + if ( st->Opt_AMR_WB ) { core = ACELP_CORE; move16(); @@ -558,7 +558,7 @@ Word16 GetPLCModeDecision_fx( { core = ACELP_CORE; move16(); - IF( GT_16( st->nbLostCmpt, 1 ) ) + if ( GT_16( st->nbLostCmpt, 1 ) ) { core = st->last_core_bfi; move16(); @@ -590,11 +590,11 @@ Word16 GetPLCModeDecision_fx( pitch = L_deposit_h( 0 ); - IF( GT_16( hTcxDec->tcxltp_last_gain_unmodified, 0 ) ) + if ( hTcxDec->tcxltp_last_gain_unmodified > 0 ) { pitch = L_add( st->old_fpitch, 0 ); } - IF( EQ_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode == EVS_MONO ) { TonalMDCTConceal_Detect( &st->tonalMDCTconceal, pitch, &numIndices, st->element_mode #ifdef ADD_IVAS_HTONALMDCTCONC @@ -620,7 +620,7 @@ Word16 GetPLCModeDecision_fx( test(); test(); test(); - IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( LT_32( L_abs( L_sub( hTcxDec->tcxltp_third_last_pitch, hTcxDec->tcxltp_second_last_pitch ) ), 32768l /*0.5f Q16*/ ) ) ) || ( GT_16( numIndices, 0 ) && ( ( LE_16( st->last_good, 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*/ ) ) ) ) + IF( ( GT_16( numIndices, 10 ) ) || ( ( GT_16( numIndices, 5 ) ) && ( 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, 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(); @@ -633,10 +633,10 @@ Word16 GetPLCModeDecision_fx( move16(); } } - ELSE IF( NE_16( st->last_core, ACELP_CORE ) ) + ELSE IF( st->last_core != ACELP_CORE ) { test(); - IF( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) + if ( LE_16( st->last_good, UNVOICED_TRANSITION ) || LE_16( hTcxDec->tcxltp_last_gain_unmodified, 13107 /*0.4f Q15*/ ) ) { core = st->last_core; move16(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 33515f491..e258c68e9 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -70,17 +70,22 @@ ivas_error evs_dec_fx( ivas_error error; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move16(); #endif hBWE_TD = st_fx->hBWE_TD; hHQ_core = st_fx->hHQ_core; hTcxLtpDec = st_fx->hTcxLtpDec; hTcxDec = st_fx->hTcxDec; error = IVAS_ERR_OK; + move16(); + move16(); + move16(); timeIn_e = 0; move16(); delay_tdbwe = 0; /* for compiler warning*/ + move16(); Qpostd = 0; move16(); /* default and used for MODE2 */ concealWholeFrame = -1; @@ -91,7 +96,9 @@ ivas_error evs_dec_fx( *-----------------------------------------------------------------*/ st_fx->idchan = 0; + move16(); st_fx->element_brate = st_fx->total_brate; + move32(); st_fx->flag_ACELP16k = set_ACELP_flag( EVS_MONO, -1, st_fx->total_brate, 0, 0, -1, -1 ); FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) @@ -99,7 +106,9 @@ ivas_error evs_dec_fx( set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX ); realBuffer[i] = realBufferTmp[i]; + move32(); imagBuffer[i] = imagBufferTmp[i]; + move32(); } if ( st_fx->bfi == 0 ) { @@ -158,6 +167,7 @@ ivas_error evs_dec_fx( #else hHQ_core->old_out_fx[i] = shl( mult_r( hHQ_core->old_out_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif + move16(); } FOR( i = 0; i < st_fx->L_frame; i++ ) { @@ -166,10 +176,11 @@ ivas_error evs_dec_fx( #else hHQ_core->old_out_LB_fx[i] = shl( mult_r( hHQ_core->old_out_LB_fx[i], st_fx->plcInfo.recovery_gain ), 1 ); #endif + move16(); } /* attenuate PLC buffers, if no aldo window is used and if no sid or zero frame is received */ - IF( 0 == st_fx->hTcxCfg->last_aldo ) + IF( st_fx->hTcxCfg->last_aldo == 0 ) { Word32 f; Word16 s; @@ -180,7 +191,6 @@ ivas_error evs_dec_fx( tmp1 = extract_l( L_shr_r( f, s ) ); FOR( i = 0; i < st_fx->hTcxCfg->tcx_mdct_window_lengthFB; i++ ) { - #ifdef BASOP_NOGLOB hTcxDec->syn_OverlFB[i] = shl_sat( mult_sat( tmp1, hTcxDec->syn_OverlFB[i] ), add( s, 1 ) ); #else @@ -214,6 +224,7 @@ ivas_error evs_dec_fx( if ( !st_fx->bfi ) { st_fx->flagGuidedAcelp = 0; + move16(); } /*----------------------------------------------------------------* @@ -229,6 +240,7 @@ ivas_error evs_dec_fx( { getPartialCopyInfo( st_fx, &st_fx->coder_type, &sharpFlag ); frameMode = st_fx->bfi; + move16(); } test(); @@ -265,6 +277,10 @@ ivas_error evs_dec_fx( } /* if previous frame was HQ Core or TCX10, drop partial copy info and continue HQ Core/TCX10 concealment */ + test(); + test(); + test(); + test(); IF( st_fx->use_partial_copy && ( ( sub( st_fx->last_core, HQ_CORE ) == 0 ) || ( sub( st_fx->last_core, TCX_10_CORE ) == 0 ) || ( ( sub( st_fx->last_core, TCX_20_CORE ) == 0 ) && getTcxonly( /*EVS_MONO, */ st_fx->last_total_brate /*, 0, 0*/ ) ) ) ) { st_fx->bfi = 1; @@ -295,6 +311,7 @@ ivas_error evs_dec_fx( { st_fx->sr_core = i_mult( st_fx->L_frame, FRAMES_PER_SEC ); st_fx->fscale_old = st_fx->fscale; + move16(); st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); } ELSE @@ -332,7 +349,7 @@ ivas_error evs_dec_fx( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ // PMT("core_switching_pre_dec_fx missign args") - if ( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame ) ) != IVAS_ERR_OK ) { return error; } @@ -345,7 +362,7 @@ ivas_error evs_dec_fx( { /* ACELP core decoder */ - 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 ) + 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; } @@ -423,6 +440,15 @@ ivas_error evs_dec_fx( test(); test(); test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || ( NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) && GT_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->core, ACELP_CORE ) && GE_32( st_fx->output_Fs, 32000 ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) ) { swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, @@ -539,10 +565,10 @@ ivas_error evs_dec_fx( test(); test(); test(); - test(); - IF( EQ_16( st_fx->core, ACELP_CORE ) && !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && 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 ) ) && st_fx->plcInfo.concealment_method == TCX_NONTONAL && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) + IF( EQ_16( st_fx->core, ACELP_CORE ) && !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && 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 ) ) && EQ_16( st_fx->plcInfo.concealment_method, TCX_NONTONAL ) && LT_32( st_fx->plcInfo.nbLostCmpt, 4 ) ) { tmps = 0; + move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { tmps = NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ); @@ -562,6 +588,7 @@ ivas_error evs_dec_fx( add( extract_l( st_fx->plcInfo.nbLostCmpt ), 1 ), st_fx->bfi ); st_fx->plcInfo.Pitch_fx = 0; + move16(); } /*----------------------------------------------------------------* @@ -621,8 +648,9 @@ ivas_error evs_dec_fx( move16(); FOR( i = 0; i < tmps; i++ ) { - tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), - st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay - 1 - i], sin_table256_fx[tmp16] ) ); + tmp_buffer_fx[i] = round_fx( L_mac( L_mult( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[sub( 255, tmp16 )] ), + st_fx->hb_prev_synth_buffer_fx[sub( sub( st_fx->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ) ); + move16(); tmp16 = add( tmp16, incr ); } Copy( tmp_buffer_fx, st_fx->hb_prev_synth_buffer_fx, tmps ); @@ -636,7 +664,7 @@ ivas_error evs_dec_fx( move16(); FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { - tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); + tmp_buffer_fx[i] = mult_r( st_fx->hb_prev_synth_buffer_fx[i], sin_table256_fx[sub( 255, tmp16 )] ); move16(); tmp16 = add( tmp16, incr ); } @@ -649,7 +677,8 @@ ivas_error evs_dec_fx( FOR( i = 0; i < st_fx->old_bwe_delay; i++ ) { /*tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr];*/ - tmp_buffer_fx[tmps - 1 - i] = round_fx( L_mac( L_mult( tmp_buffer_fx[tmps - 1 - i], 32767 ), st_fx->hb_prev_synth_buffer_fx[st_fx->old_bwe_delay - 1 - i], sin_table256_fx[tmp16 /*i * incr*/] ) ); + tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st_fx->hb_prev_synth_buffer_fx[sub( sub( st_fx->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); + move16(); tmp16 = add( tmp16, incr ); } @@ -663,8 +692,8 @@ ivas_error evs_dec_fx( } Copy( hb_synth_fx, tmp_buffer_fx, output_frame ); Copy( st_fx->hb_prev_synth_buffer_fx, hb_synth_fx, tmps ); - Copy( tmp_buffer_fx, hb_synth_fx + tmps, output_frame - tmps ); - Copy( tmp_buffer_fx + output_frame - tmps, st_fx->hb_prev_synth_buffer_fx, tmps ); + Copy( tmp_buffer_fx, hb_synth_fx + tmps, sub( output_frame, tmps ) ); + Copy( tmp_buffer_fx + sub( output_frame, tmps ), st_fx->hb_prev_synth_buffer_fx, tmps ); st_fx->old_bwe_delay = tmps; move16(); @@ -674,9 +703,7 @@ ivas_error evs_dec_fx( test(); test(); test(); - test(); - IF( ( st_fx->ppp_mode_dec || ( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) && EQ_16( st_fx->L_frame, st_fx->last_L_frame ) && ( st_fx->bws_cnt > 1 || st_fx->last_extl != -1 ) ) - + IF( ( st_fx->ppp_mode_dec || ( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) && EQ_16( st_fx->L_frame, st_fx->last_L_frame ) && ( GT_16( st_fx->bws_cnt, 1 ) || NE_16( st_fx->last_extl, -1 ) ) ) { Copy( hBWE_TD->old_hb_synth_fx, hb_synth_fx, output_frame ); IF( LT_16( hBWE_TD->prev_hb_synth_fx_exp, 14 ) ) @@ -686,6 +713,7 @@ ivas_error evs_dec_fx( ELSE { hb_synth_fx_exp = 14; + move16(); } } ELSE @@ -703,15 +731,19 @@ ivas_error evs_dec_fx( { case L_FRAME8k: tmp16 = 205; + move16(); BREAK; /*Q15*/ case L_FRAME16k: tmp16 = 102; + move16(); BREAK; /*Q15*/ case L_FRAME32k: tmp16 = 51; + move16(); BREAK; /*Q15*/ case L_FRAME48k: tmp16 = 34; + move16(); BREAK; /*Q15*/ } @@ -754,25 +786,25 @@ ivas_error evs_dec_fx( concealWholeFrame = 0; move16(); - if ( EQ_16( frameMode, FRAMEMODE_NORMAL ) ) + if ( EQ_32( frameMode, FRAMEMODE_NORMAL ) ) { st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); + move32(); } - IF( EQ_16( frameMode, FRAMEMODE_MISSING ) ) + IF( EQ_32( frameMode, FRAMEMODE_MISSING ) ) { test(); test(); IF( st_fx->use_partial_copy && GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) ) { st_fx->m_decodeMode = DEC_NO_FRAM_LOSS; - move16(); + move32(); } ELSE { st_fx->m_decodeMode = DEC_CONCEALMENT_EXT; - move16(); + move32(); } } @@ -799,7 +831,7 @@ ivas_error evs_dec_fx( if ( st_fx->bfi ) { frameMode = FRAMEMODE_MISSING; - move16(); + move32(); } IF( st_fx->igf ) { @@ -918,7 +950,7 @@ ivas_error evs_dec_fx( hb_synth_fx_exp = st_fx->prev_Q_bwe_syn2; move16(); } - ELSE IF( st_fx->bwidth == WB && st_fx->last_extl == WB_TBE ) + ELSE IF( EQ_16( st_fx->bwidth, WB ) && EQ_16( st_fx->last_extl, WB_TBE ) ) { GenTransition_WB_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->old_tbe_synth_fx, st_fx->prev_Qx, 2 * NS2SA( st_fx->output_Fs, 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, hBWE_TD->mem_resamp_HB_fx ); @@ -937,6 +969,7 @@ ivas_error evs_dec_fx( { 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( hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, &hBWE_TD->prev_fbbwe_ratio_fx ); } swb_tbe_reset_synth_fx( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); @@ -959,7 +992,6 @@ ivas_error evs_dec_fx( { nab = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); st_fx->cldfbSyn->lsb = s_min( st_fx->cldfbAna->no_channels, st_fx->cldfbSyn->no_channels ); - move16(); st_fx->cldfbSyn->usb = st_fx->cldfbSyn->no_channels; move16(); st_fx->cldfbAna->lsb = st_fx->cldfbAna->no_channels; @@ -979,14 +1011,12 @@ ivas_error evs_dec_fx( - do CNG during inactive frames ****************************************/ HANDLE_FD_CNG_DEC hFdCngDec = st_fx->hFdCngDec; - move16(); - noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && st_fx->m_frame_type == ACTIVE_FRAME, output_sp, 0 ); + noisy_speech_detection_fx( st_fx->hFdCngDec, st_fx->VAD && EQ_16( 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 ) + if ( hFdCngDec->hFdCngCom->flag_noisy_speech != 0 ) { hFdCngDec->hFdCngCom->likelihood_noisy_speech = add( hFdCngDec->hFdCngCom->likelihood_noisy_speech, 328 /*0.01 Q15*/ ); - move16(); } st_fx->lp_noise = hFdCngDec->lp_noise; move32(); @@ -1045,6 +1075,11 @@ ivas_error evs_dec_fx( update_decoder_LPD_cng( st_fx, st_fx->coder_type, timeDomainBuffer, A, st_fx->p_bpf_noise_buf ); /* Generate additional comfort noise to mask potential coding artefacts */ + test(); + test(); + test(); + test(); + test(); IF( st_fx->flag_cna ) { generate_masking_noise_fx( timeDomainBuffer, 0, st_fx->hFdCngDec->hFdCngCom, st_fx->hFdCngDec->hFdCngCom->frameSize, 0 ); @@ -1053,12 +1088,12 @@ ivas_error evs_dec_fx( { FOR( i = 0; i < st_fx->L_frame / 2; i++ ) { - timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[i + 5 * st_fx->L_frame / 4] ); + timeDomainBuffer[i] = add( timeDomainBuffer[i], st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( st_fx->L_frame, 2 ) ) )] ); move16(); } } /* check if the CLDFB works on the right sample rate */ - IF( NE_16( ( st_fx->cldfbAna->no_channels * st_fx->cldfbAna->no_col ), st_fx->L_frame ) ) + IF( NE_16( i_mult( st_fx->cldfbAna->no_channels, st_fx->cldfbAna->no_col ), st_fx->L_frame ) ) { Word16 newCldfbBands = CLDFB_getNumChannels( L_mult0( st_fx->L_frame, 50 ) ); @@ -1073,9 +1108,9 @@ ivas_error evs_dec_fx( { st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, 10 ); } - ELSE IF( st_fx->hFdCngDec->hFdCngCom->regularStopBand < st_fx->cldfbSyn->no_channels ) + ELSE IF( LT_16( st_fx->hFdCngDec->hFdCngCom->regularStopBand, st_fx->cldfbSyn->no_channels ) ) { - st_fx->cldfbSyn->bandsToZero = st_fx->cldfbSyn->no_channels - st_fx->hFdCngDec->hFdCngCom->regularStopBand; + st_fx->cldfbSyn->bandsToZero = sub( st_fx->cldfbSyn->no_channels, st_fx->hFdCngDec->hFdCngCom->regularStopBand ); } timeIn_e = 2; @@ -1090,7 +1125,7 @@ ivas_error evs_dec_fx( cldfbAnalysisFiltering( st_fx->cldfbAna, realBuffer, imagBuffer, &st_fx->scaleFactor, timeDomainBuffer, timeIn_e, CLDFB_NO_COL_MAX, workBuffer ); } - if ( st_fx->flag_cna == 0 ) + IF( st_fx->flag_cna == 0 ) { set16_fx( st_fx->hFdCngDec->hFdCngCom->olapBufferSynth2, 0, st_fx->hFdCngDec->hFdCngCom->fftlen ); } @@ -1214,7 +1249,7 @@ ivas_error evs_dec_fx( } ELSE { - Copy( hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB - delay_comp, st_fx->delay_buf_out_fx, delay_comp ); + Copy( hTcxDec->old_synthFB_fx + sub( hTcxDec->old_synth_lenFB, delay_comp ), st_fx->delay_buf_out_fx, delay_comp ); IF( EQ_32( st_fx->output_Fs, 8000 ) ) { Copy( hTcxDec->FBTCXdelayBuf, st_fx->previoussynth_fx, delay_comp ); @@ -1232,8 +1267,8 @@ ivas_error evs_dec_fx( { Copy( output_sp, tmp_buffer_fx, output_frame ); Copy_Scale_sig( st_fx->prev_synth_buffer_fx, output_sp, delay_tdbwe, negate( timeIn_e ) ); - Copy( tmp_buffer_fx, output_sp + delay_tdbwe, output_frame - delay_tdbwe ); - Copy_Scale_sig( tmp_buffer_fx + output_frame - delay_tdbwe, st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e ); + Copy( tmp_buffer_fx, output_sp + delay_tdbwe, sub( output_frame, delay_tdbwe ) ); + Copy_Scale_sig( tmp_buffer_fx + sub( output_frame, delay_tdbwe ), st_fx->prev_synth_buffer_fx, delay_tdbwe, timeIn_e ); } test(); @@ -1320,7 +1355,7 @@ ivas_error evs_dec_fx( Copy_Scale_sig( pcmbufFB + tmps, output_sp + shl( tmps, 1 ), sub( hTcxDec->L_frameTCX, shl( tmps, 1 ) ), negate( timeIn_e ) ); } - Copy( pcmbufFB + hTcxDec->L_frameTCX - tmps, hTcxDec->FBTCXdelayBuf, tmps ); + Copy( pcmbufFB + sub( hTcxDec->L_frameTCX, tmps ), hTcxDec->FBTCXdelayBuf, tmps ); test(); IF( st_fx->bfi && GT_16( st_fx->last_core, ACELP_CORE ) ) @@ -1367,7 +1402,6 @@ ivas_error evs_dec_fx( 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 ); @@ -1386,30 +1420,28 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->codec_mode, MODE1 ) ) { - Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, output_frame - post_hq_delay + NS2SA_fx2( st_fx->output_Fs, 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 */ + Copy( hTcxDec->synth_history_fx + output_frame, hTcxDec->synth_history_fx, add( sub( output_frame, post_hq_delay ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_MEM_NS ) ) ); + Copy_Scale_sig( synth_fx, hTcxDec->old_synthFB_fx + sub( 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( hTcxDec->old_synthFB_fx + 2 * output_frame - post_hq_delay, 0, post_hq_delay ); + set16_fx( hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), post_hq_delay ), 0, post_hq_delay ); IF( GE_16( output_frame, L_FRAME16k ) ) { - - Copy_Scale_sig( st_fx->prev_synth_buffer_fx, hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA_fx2( st_fx->output_Fs, 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 + sub( shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( st_fx->Qprev_synth_buffer_fx ) ); } IF( NE_16( st_fx->core, ACELP_CORE ) ) { IF( GE_16( output_frame, L_FRAME16k ) ) { - - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + 2 * output_frame, NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ) ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); } ELSE { - Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); - Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + 2 * output_frame - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); + Copy_Scale_sig( synth_fx + output_frame, hTcxDec->old_synthFB_fx + sub( shl( output_frame, 1 ), NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS ) ), NS2SA_fx2( st_fx->output_Fs, DELAY_CLDFB_NS ), negate( Qpostd ) ); + Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_fx2( st_fx->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + shl( output_frame, 1 ) - NS2SA_fx2( st_fx->output_Fs, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), NS2SA_fx2( st_fx->output_Fs, PH_ECU_LOOKAHEAD_NS ), negate( hHQ_core->Q_old_wtda ) ); } } } @@ -1445,6 +1477,8 @@ ivas_error evs_dec_fx( { st_fx->bfi = 0; move16(); + test(); + test(); IF( st_fx->use_partial_copy && GE_16( st_fx->rf_frame_type, RF_TCXFD ) && LE_16( st_fx->rf_frame_type, RF_TCXTD2 ) ) { if ( EQ_16( frameMode, FRAMEMODE_MISSING ) ) diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 5ee55a3a7..063a91269 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -131,76 +131,37 @@ void initFdCngDec( /* Set some counters and flags */ hFdCngDec->flag_dtx_mode = 0; -#ifndef IVAS_FLOAT_FIXED - hFdCngDec->lp_noise_float = -20.f; - hFdCngDec->lp_speech_float = 25.f; + move16(); - /* Initialize noise estimation algorithm */ - set_f( hFdCngDec->bandNoiseShape_float, 0.0f, FFTLEN2 ); - set_f( hFdCngDec->partNoiseShape_float, 0.0f, NPART ); - set_f( hFdCngDec->msPeriodog_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msBminSubWin_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msPsd_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msNoiseFloor_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msNoiseEst_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msMinBuf_float, FLT_MAX, MSNUMSUBFR * NPART_SHAPING ); - set_f( hFdCngDec->msCurrentMin_float, FLT_MAX, NPART_SHAPING ); - set_f( hFdCngDec->msCurrentMinOut_float, FLT_MAX, NPART_SHAPING ); - set_f( hFdCngDec->msCurrentMinSubWindow_float, FLT_MAX, NPART_SHAPING ); -#endif - set_s( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); - set_s( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); -#ifndef IVAS_FLOAT_FIXED - set_f( hFdCngDec->msPsdFirstMoment_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msPsdSecondMoment_float, 0.0f, NPART_SHAPING ); -#endif + set16_fx( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING ); + set16_fx( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING ); hFdCngDec->msPeriodogBufPtr = 0; -#ifndef IVAS_FLOAT_FIXED - set_f( hFdCngDec->msPeriodogBuf_float, 0.0f, MSBUFLEN * NPART_SHAPING ); - set_f( hFdCngDec->msLogPeriodog_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->msLogNoiseEst_float, 0.0f, NPART_SHAPING ); - set_f( hFdCngDec->psize_shaping_float, 0.0f, NPART_SHAPING ); -#endif + move16(); hFdCngDec->nFFTpart_shaping = 0; - -#ifndef IVAS_FLOAT_FIXED - set_f( hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, 0.0f, NPART ); - set_f( hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k ); - set_f( hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING ); -#endif + move16(); hFdCngDec->ms_last_inactive_bwidth = NB; + move16(); hFdCngDec->ms_cnt_bw_up = 0; -#ifndef IVAS_FLOAT_FIXED - hFdCngDec->cna_LR_LT = 0.5f; - hFdCngDec->cna_ILD_LT = 0.0f; -#endif + move16(); hFdCngDec->first_cna_noise_updated = 0; + move16(); hFdCngDec->first_cna_noise_update_cnt = 0; + move16(); hFdCngDec->cna_nbands = CNA_INIT_NBANDS; - mvs2s( cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1 ); - + move16(); + Copy( cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1 ); -#ifndef IVAS_FLOAT_FIXED - hFdCngDec->cna_act_fact = 1.0f; - hFdCngDec->cna_rescale_fact = 0.0f; -#else hFdCngDec->cna_act_fact_fx = MAX_WORD16; + move16(); hFdCngDec->cna_rescale_fact_fx = 0; -#endif + move16(); hFdCngDec->cna_seed = 5687; -#ifndef IVAS_FLOAT_FIXED - set_zero( hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX ); - set_zero( hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX ); -#endif + move16(); st->CNG_mode = -1; -#ifndef IVAS_FLOAT_FIXED - mvr2r( st->lsp_old, st->lspCNG, M ); -#endif // #ifndef IVAS_FLOAT_FIXED + move16(); return; } @@ -590,7 +551,7 @@ void configureFdCngDec_ivas_fx( hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( hsCom->FdCngSetup.numPartitions, 1 )], 1 ); #ifndef IVAS_FLOAT_FIXED /* remove floating point dependency */ initPartitions_flt( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize_flt, hsCom->psize_inv_flt, 0 ); @@ -616,11 +577,12 @@ void configureFdCngDec_ivas_fx( hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], sub( hsCom->stopFFTbin, hsCom->startBand ) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); #ifndef IVAS_FLOAT_FIXED hsCom->CLDFBpsize_inv_flt[j] = hsCom->psize_inv_flt[j + hsCom->nFFTpart]; // TODO remove floating point dependency #endif - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; + move16(); + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; move16(); } @@ -651,12 +613,6 @@ void configureFdCngDec_ivas_fx( hsCom->olapWinAna_fx = olapWinAna512_fx; hsCom->fftSineTab_fx = NULL; hsCom->olapWinSyn_fx = olapWinSyn256_fx; -#ifndef IVAS_FLOAT_FIXED - /* TODO: remove floating point dependency */ - hsCom->fftSineTab_flt = NULL; - hsCom->olapWinAna_flt = olapWinAna512; - hsCom->olapWinSyn_flt = olapWinSyn256; -#endif hsCom->fftlenShift = 8; move16(); hsCom->fftlenFac = 32767 /*1.0 Q15*/; @@ -666,12 +622,6 @@ void configureFdCngDec_ivas_fx( hsCom->olapWinAna_fx = olapWinAna640_fx; hsCom->fftSineTab_fx = fftSineTab640_fx; hsCom->olapWinSyn_fx = olapWinSyn320_fx; -#ifndef IVAS_FLOAT_FIXED - /* remove floating point dependency */ - hsCom->fftSineTab_flt = fftSineTab640; - hsCom->olapWinAna_flt = olapWinAna640; - hsCom->olapWinSyn_flt = olapWinSyn320; -#endif hsCom->fftlenShift = 9; move16(); hsCom->fftlenFac = 20480 /*0.625 Q15*/; @@ -1397,8 +1347,21 @@ void FdCng_decodeSID_ivas_fx( HANDLE_FD_CNG_COM hFdCngCom; Word32 *invTrfMatrix_fx; Word32 tmpRAM_fx[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC]; + Word16 tmp16; + + IF( st->element_mode == EVS_MONO ) + { + tmp16 = GAIN_Q_OFFSET_EVS_FX_Q0; + move16(); + } + ELSE + { + tmp16 = GAIN_Q_OFFSET_IVAS_FX_Q0; + move16(); + } - const Word16 gain_q_offset = (Word16) ( ( st->element_mode == EVS_MONO ) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS ); // Q0 + const Word16 gain_q_offset = tmp16; /* Q0 */ + move16(); invTrfMatrix_fx = (Word32 *) tmpRAM_fx; @@ -1408,24 +1371,26 @@ void FdCng_decodeSID_ivas_fx( N = hFdCngCom->npart; gain = 0; - hFdCngCom->sid_frame_counter++; + move32(); + hFdCngCom->sid_frame_counter = add( hFdCngCom->sid_frame_counter, 1 ); /* Read bitstream */ - for ( i = 0; i < FD_CNG_stages_37bits; i++ ) + FOR( i = 0; i < FD_CNG_stages_37bits; i++ ) { - indices[i] = get_next_indice( st, bits_37bits[i] ); + indices[i] = get_next_indice_fx( st, bits_37bits[i] ); + move16(); } - index = get_next_indice( st, 7 ); + index = get_next_indice_fx( st, 7 ); /* MSVQ decoder */ - if ( st->element_mode != EVS_MONO ) + IF( st->element_mode != EVS_MONO ) { - create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); + create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 ); } - else + ELSE { /* Legacy EVS_MONO MSVQ tables */ msvq_dec_fx( cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL, 7 ); } @@ -1433,42 +1398,51 @@ void FdCng_decodeSID_ivas_fx( /* Decode gain */ // gain = ((float)index - gain_q_offset) / 1.5f; - gain = L_mult0( ( index - gain_q_offset ), 21845 ); // Q15 + gain = L_mult0( sub( index, gain_q_offset ), 21845 ); // Q15 /* Apply gain and undo log */ Word16 res_exp[NPART]; Word16 max_res_exp = 0; - for ( i = 0; i < N; i++ ) + move16(); + FOR( i = 0; i < N; i++ ) { // sidNoiseEst_flt[i] = (float)pow(10.f, (v[i] + gain) / 10.f); sidNoiseEst[i] = BASOP_util_Pow2( Mpy_32_32( L_add( v[i], gain ), LOG_10_BASE_2_BY_10_Q31 ), Q16, &res_exp[i] ); - if ( max_res_exp < res_exp[i] ) + move32(); + IF( LT_16( max_res_exp, res_exp[i] ) ) { max_res_exp = res_exp[i]; + move16(); } } - for ( i = 0; i < N; i++ ) + FOR( i = 0; i < N; i++ ) { - sidNoiseEst[i] = L_shr( sidNoiseEst[i], max_res_exp - res_exp[i] ); + sidNoiseEst[i] = L_shr( sidNoiseEst[i], sub( max_res_exp, res_exp[i] ) ); + move32(); } hFdCngCom->sidNoiseEstExp = max_res_exp; + move16(); /* NB last band energy compensation */ - if ( hFdCngCom->CngBandwidth == NB ) + IF( hFdCngCom->CngBandwidth == NB ) { - sidNoiseEst[N - 1] = Mpy_32_16_1( sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); + sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( sidNoiseEst[sub( N, 1 )], NB_LAST_BAND_SCALE ); + move32(); } - if ( hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20 ) + test(); + IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - sidNoiseEst[N - 1] = Mpy_32_16_1( sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); + sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( sidNoiseEst[sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE ); + move32(); } - scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 ); + scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 ); hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp; + move16(); lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac ); @@ -2064,7 +2038,7 @@ void generate_masking_noise_ivas_fx( } } - IF( i < SIZE_SCALE_TABLE_CN_AMRWB ) + IF( LT_16( i, SIZE_SCALE_TABLE_CN_AMRWB ) ) { scale_fx = L_deposit_h( scaleTable_cn_only_amrwbio[i][1] ); /* Q30 */ } @@ -2084,7 +2058,7 @@ void generate_masking_noise_ivas_fx( { rand_gauss_fx( &fftBuffer_fx[0], seed, *exp_out ); // Q15 ptr_r_fx = fftBuffer_fx + 2; - Word16 exp1 = 32 - hFdCngCom->cngNoiseLevelExp; + Word16 exp1 = sub( 32, hFdCngCom->cngNoiseLevelExp ); Word32 mpy1 = Sqrt32( Mpy_32_32( scale_fx, *ptr_level_fx ), &exp1 ); // Q = noise_exp-1 mpy1 = L_shl( mpy1, exp1 ); // Q31 fftBuffer_fx[0] = Mpy_32_32( fftBuffer_fx[0], mpy1 ); /* DC component in FFT */ // Q = Q15 @@ -2094,15 +2068,15 @@ void generate_masking_noise_ivas_fx( { fftBuffer_fx[0] = 0; move32(); - set_l( fftBuffer_fx + 2, 0, 2 * ( startBand - 1 ) ); - ptr_r_fx = fftBuffer_fx + 2 * startBand; + set32_fx( fftBuffer_fx + 2, 0, shl( sub( startBand, 1 ), 1 ) ); + ptr_r_fx = fftBuffer_fx + shl( startBand, 1 ); } ptr_i_fx = ptr_r_fx + 1; FOR( ; ptr_level_fx < cngNoiseLevel_fx + hFdCngCom->stopFFTbin - startBand; ptr_level_fx++ ) { /* Real part in FFT bins */ rand_gauss_fx( ptr_r_fx, seed, *exp_out ); // Q15 - Word16 exp2 = 32 - hFdCngCom->cngNoiseLevelExp; + Word16 exp2 = sub( 32, hFdCngCom->cngNoiseLevelExp ); Word32 mpy2 = Sqrt32( L_shr( Mpy_32_32( scale_fx, *ptr_level_fx ), 1 ), &exp2 ); // Q = noise_exp-1 ( *ptr_r_fx ) = L_shl( Mpy_32_32( *ptr_r_fx, mpy2 ), exp2 ); // Q = Q15 ptr_r_fx += 2; @@ -2114,7 +2088,7 @@ void generate_masking_noise_ivas_fx( } /* Remaining FFT bins are set to zero */ - set_l( fftBuffer_fx + 2 * hFdCngCom->stopFFTbin, 0, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin ); + set32_fx( fftBuffer_fx + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) ); /* Nyquist frequency is discarded */ fftBuffer_fx[1] = 0; move32(); @@ -2124,7 +2098,7 @@ void generate_masking_noise_ivas_fx( /* very low level case - update random seeds and reset FFT buffer; don't fully skip SynthesisSTFT_flt(), because of the buffer updates done there... */ generate_masking_noise_update_seed_fx( hFdCngCom ); - set_l( fftBuffer_fx, 0, hFdCngCom->fftlen ); + set32_fx( fftBuffer_fx, 0, hFdCngCom->fftlen ); } /* Perform STFT synthesis */ @@ -2141,11 +2115,11 @@ void generate_masking_noise_ivas_fx( /* Add some comfort noise on top of decoded signal */ IF( return_noise ) { - mvl2l( maskingNoise_fx, timeDomainBuffer, min( hFdCngCom->frameSize, length ) ); + Copy32( maskingNoise_fx, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ) ); } ELSE { - v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, min( hFdCngCom->frameSize, length ), 0 ); + v_add_fixed( maskingNoise_fx, timeDomainBuffer, timeDomainBuffer, s_min( hFdCngCom->frameSize, length ), 0 ); } return; @@ -2434,156 +2408,152 @@ void generate_stereo_masking_noise_fx( IF( st->idchan == 0 ) { hFdCngCom = st->hFdCngDec->hFdCngCom; - Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, hFdCngCom->frameSize / 2, Q6 - st->Q_syn ); - Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, hFdCngCom->frameSize / 2 ); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, Ns_fx, shr( hFdCngCom->frameSize, 1 ), sub( Q6, st->Q_syn ) ); + Copy32( hFdCngCom->olapBufferSynth2_fx, Np_fx, shr( hFdCngCom->frameSize, 1 ) ); - set_l( &Np_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2 ); - set_l( &Ns_fx[hFdCngCom->frameSize / 2], 0, hFdCngCom->frameSize / 2 ); + set32_fx( &Np_fx[shr( hFdCngCom->frameSize, 1 )], 0, shr( hFdCngCom->frameSize, 1 ) ); + set32_fx( &Ns_fx[shr( hFdCngCom->frameSize, 1 )], 0, shr( hFdCngCom->frameSize, 1 ) ); IF( !fadeOut ) { - // generate_masking_noise(N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out); - Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, -( st->Q_syn - 15 ) ); + Copy_Scale_sig_16_32( hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22_32fx, hFdCngCom->fftlen, sub( Q15, st->Q_syn ) ); generate_masking_noise_ivas_fx( N1_fx, &N1_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out ); // N1_fx Q6 /* 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); generate_masking_noise_ivas_fx( N2_fx, &N2_fx_exp, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out ); // N2_fx Q6 - // gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT; gamma_fx = L_shr( Mpy_32_32( hStereoCng->c_PS_LT_fx, hStereoCng->c_PS_LT_fx ), 1 ); - // scale = 1.0f; scale_fx = ONE_IN_Q30; - // if (gamma < 0.9f) - IF( gamma_fx < 966367642 ) + move32(); + IF( LT_32( gamma_fx, 966367642 /* 0.9 in Q30 */ ) ) { - // gamma = gamma / (1 - gamma); - // gamma = (float)sqrt(gamma + 1) - (float)sqrt(gamma); - // scale = 1.0f / (float)sqrt(1 + gamma * gamma); Word16 exp_gamma = 0; + move16(); Word16 divisor1 = Inv16( (Word16) L_shr( L_sub( ONE_IN_Q30, gamma_fx ), Q15 ), &exp_gamma ); // Q15-exp_gamma gamma_fx = L_shl( Mpy_32_16_1( gamma_fx, divisor1 ), exp_gamma ); // Q30 Word16 exp_gamma1 = Q1, exp_gamma2 = Q1, exp_gamma3 = Q1; + move16(); + move16(); + move16(); gamma_fx = Sqrt32( L_add( gamma_fx, ONE_IN_Q30 ), &exp_gamma1 ); - // gamma_fx = L_shl( gamma_fx, exp_gamma1 ); Word32 temp = Sqrt32( gamma_fx, &exp_gamma2 ); // Q31-exp_gamma1 - gamma_fx = L_sub( gamma_fx, L_shl( temp, exp_gamma2 - exp_gamma1 ) ); // Q31-exp_gamma1 - gamma_fx = L_shl( gamma_fx, exp_gamma1 - Q1 ); // Q30 + gamma_fx = L_sub( gamma_fx, L_shl( temp, sub( exp_gamma2, exp_gamma1 ) ) ); // Q31-exp_gamma1 + gamma_fx = L_shl( gamma_fx, sub( exp_gamma1, Q1 ) ); // Q30 Word32 divisor2 = Sqrt32( L_add( ONE_IN_Q30, L_shl( Mpy_32_32( gamma_fx, gamma_fx ), Q1 ) ), &exp_gamma3 ); // Q31 - exp_gamma3 - scale_fx = L_shl( divide3232( ONE_IN_Q30, divisor2 ), Q15 + exp_gamma3 ); // Q30 + scale_fx = L_shl( divide3232( ONE_IN_Q30, divisor2 ), add( Q15, exp_gamma3 ) ); // Q30 } ELSE { gamma_fx = 0; + move16(); } 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]); Np_fx[i] = L_add( Np_fx[i], Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ) ); // Q6 - Word32 add2 = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 + move32(); + Word32 add2 = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 if ( hStereoCng->c_PS_LT_fx < 0 ) { add2 = L_negate( add2 ); } Ns_fx[i] = L_add( Ns_fx[i], add2 ); + move32(); } 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]); Np_fx[i] = Mpy_32_32( scale_fx, L_shl( L_add( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 + move32(); Ns_fx[i] = Mpy_32_32( scale_fx, L_shl( L_sub( N1_fx[i], Mpy_32_32( gamma_fx, L_shl( N2_fx[i], Q1 ) ) ), Q1 ) ); // Q6 + move32(); IF( hStereoCng->c_PS_LT_fx < 0 ) { Ns_fx[i] = L_negate( Ns_fx[i] ); + move32(); } } /* Below code to be converted */ - Word32 scale_fx_tmp = Mpy_32_32( scale_fx, L_shl( hFdCngCom->fftlen / 2, Q22 ) ); // Q21 - // scale_fx = L_shr(scale_fx, Q1) * hFdCngCom->fftlen; - for ( i = 0; i < hFdCngCom->frameSize / 2; i++ ) + Word32 scale_fx_tmp = Mpy_32_32( scale_fx, L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ) ); // Q21 + FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - // hFdCngCom->olapBufferSynth2_flt[i] = scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); - // hStereoCng->olapBufferSynth22[i] = sign(hStereoCng->c_PS_LT) * scale * (hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4]); hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, - L_add( L_shr( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15 ), - Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4] ) ) ), + L_add( L_shr( hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ) ) ), Q14 ); // Q_olap + move16(); hStereoCng->olapBufferSynth22_fx[i] = (Word16) L_shr( Mpy_32_32( scale_fx_tmp, - L_sub( L_shr( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4], Q15 ), - Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[i + 5 * hFdCngCom->frameSize / 4] ) ) ), + L_sub( L_shr( hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )], Q15 ), + Mpy_32_16_1( gamma_fx, hStereoCng->olapBufferSynth22_fx[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ) ) ), Q14 ); // Q_olap + move16(); } } - else + ELSE { FOR( i = 0; i < hFdCngCom->frameSize / 2; i++ ) { - // Np[i] += N1[i]; Np_fx[i] = L_add( Np_fx[i], N1_fx[i] ); // Q6 + move32(); } - // mvr2r(&N1[hFdCngCom->frameSize / 2], &Np[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2); - mvl2l( &N1_fx[hFdCngCom->frameSize / 2], &Np_fx[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2 ); - // float scale = (float)(hFdCngCom->fftlen / 2); - scale_fx = L_shl( hFdCngCom->fftlen / 2, Q22 ); // Q21 - for ( i = 0; i < hFdCngCom->frameSize; i++ ) + Copy32( &N1_fx[shr( hFdCngCom->frameSize, 1 )], &Np_fx[shr( hFdCngCom->frameSize, 1 )], shr( hFdCngCom->frameSize, 1 ) ); + scale_fx = L_shl( shr( hFdCngCom->fftlen, 1 ), Q22 ); // Q21 + FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { - // hFdCngCom->olapBufferSynth2_flt[i] = scale * hFdCngCom->olapBufferSynth2_flt[i + 5 * hFdCngCom->frameSize / 4]; - hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] ), Q6 ); // Q_olap + hFdCngCom->olapBufferSynth2[i] = (Word16) L_shr( Mpy_32_16_1( scale_fx, hFdCngCom->olapBufferSynth2[add( i, i_mult( 5, shr( hFdCngCom->frameSize, 2 ) ) )] ), Q6 ); // Q_olap + move16(); } } - Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, ( st->Q_syn - 15 ) ); + Copy_Scale_sig_32_16( hStereoCng->olapBufferSynth22_32fx, hStereoCng->olapBufferSynth22_fx, hFdCngCom->fftlen, sub( st->Q_syn, 15 ) ); } - else + ELSE { - set_s( hFdCngCom->olapBufferSynth2, 0, hFdCngCom->frameSize / 2 ); - set_s( hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize / 2 ); + set16_fx( hFdCngCom->olapBufferSynth2, 0, shr( hFdCngCom->frameSize, 1 ) ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, shr( hFdCngCom->frameSize, 1 ) ); } - if ( flag_sec_CNA ) + IF( flag_sec_CNA ) { Copy_Scale_sig_32_16( Ns_fx, hStereoCng->maskingNoiseS_fx, hFdCngCom->frameSize, 0 ); // Q6 hStereoCng->enableSecCNA = 1; + move16(); } - else + ELSE { - set_s( hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize ); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, hFdCngCom->frameSize ); } /* add masking noise */ - // v_add(Np, syn, syn, hFdCngCom->frameSize); - for ( i = 0; i < hFdCngCom->frameSize; i++ ) + FOR( i = 0; i < hFdCngCom->frameSize; i++ ) { - syn[i] = syn[i] + (Word16) L_shr( Np_fx[i], Q16 + Q6 - Q_syn ); // Q_syn + syn[i] = add( syn[i], (Word16) L_shr( Np_fx[i], sub( Q16 + Q6, Q_syn ) ) ); // Q_syn + move16(); } } - else if ( hStereoCng->enableSecCNA ) + ELSE IF( hStereoCng->enableSecCNA ) { Word16 SP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); /* Use long-term SP ratio based on L/R synthesis */ Word16 prevSP_ratio_fx = hStereoTD->prevSP_ratio_fx; /* Use long-term SP ratio based on L/R synthesis */ + move16(); /* scale and add masking noise */ - for ( i = 0; i < *hStereoCng->frameSize / 4; i++ ) + FOR( i = 0; i < *hStereoCng->frameSize / 4; i++ ) { - // Word16 scale_fx_tmp = idiv1616( add( imult1616( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), imult1616( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ) ); // Q15 Word16 s; Word16 scale_fx_tmp = BASOP_Util_Divide3216_Scale( L_add( L_mult0( prevSP_ratio_fx, sub( shr( *hStereoCng->frameSize, 2 ), i ) ), L_mult0( SP_ratio_fx, i ) ), shr( *hStereoCng->frameSize, 2 ), &s ); // Q15 scale_fx_tmp = shl( scale_fx_tmp, s ); - // syn[i] += scale * hStereoCng->maskingNoiseS[i]; - syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); + syn[i] = add( syn[i], mult( scale_fx_tmp, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + move16(); } - for ( ; i < *hStereoCng->frameSize / 2; i++ ) + FOR( ; i < *hStereoCng->frameSize / 2; i++ ) { - // syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + move16(); } - for ( ; i < *hStereoCng->frameSize; i++ ) + FOR( ; i < *hStereoCng->frameSize; i++ ) { - // syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i]; - syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], Q6 - Q_syn ) ) ); + syn[i] = add( syn[i], mult( SP_ratio_fx, shr( hStereoCng->maskingNoiseS_fx[i], sub( Q6, Q_syn ) ) ) ); + move16(); } hStereoTD->prevSP_ratio_fx = extract_h( hStereoTD->SP_ratio_LT_fx ); } @@ -2753,7 +2723,7 @@ void generate_masking_noise_lb_dirac_fx( GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) && LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) ) { - break; + BREAK; } } @@ -2761,8 +2731,8 @@ void generate_masking_noise_lb_dirac_fx( Word16 div1 = BASOP_Util_Divide1616_Scale( negate( scaleTable_cn_dirac[i].scale_ivas ), shl( 10, Q11 ), &exp ); exp = add( exp, sub( sub( 15, 13 ), sub( 15, 11 ) ) ); Word32 scale_temp = BASOP_util_Pow2( Mpy_32_16_1( LOG_10_BASE_2, div1 ), add( exp, 2 ), &exp ); - scale_temp = L_sub( scale_temp, L_shl( 1, Q31 - exp ) ); - scale = L_shl( scale_temp, exp - Q1 ); // Q30 + scale_temp = L_sub( scale_temp, L_shl( 1, sub( Q31, exp ) ) ); + scale = L_shl( scale_temp, sub( exp, Q1 ) ); // Q30 scale = Mpy_32_32( scale, hFdCngCom->likelihood_noisy_speech_32fx ); // Q30 } @@ -2770,7 +2740,6 @@ void generate_masking_noise_lb_dirac_fx( /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/ test(); - test(); IF( cna_flag && tdBuffer != NULL ) { WHILE( GT_16( n_samples_out, 0 ) ) @@ -2788,21 +2757,23 @@ void generate_masking_noise_lb_dirac_fx( rand_gauss_fx( &fftBuffer[0], seed, exp_out ); ptr_r = fftBuffer + 2; - Word16 exp2 = 31 - hFdCngCom->cngNoiseLevelExp; + Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); Word32 sqr = Sqrt32( L_shr( Mpy_32_32( scale, *ptr_level ), 1 ), &exp2 ); /* DC component in FFT */ sqr = L_shl( sqr, exp2 ); fftBuffer[0] = Mpy_32_32( fftBuffer[0], sqr ); /* DC component in FFT */ + move32(); ptr_level++; } ELSE { fftBuffer[0] = 0; + move32(); set32_fx( fftBuffer + 2, 0, shl( sub( hFdCngCom->startBand, 1 ), 1 ) ); ptr_r = fftBuffer + shl( hFdCngCom->startBand, 1 ); } ptr_i = ptr_r + 1; - FOR( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ ) + FOR( ; ptr_level < cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); ptr_level++ ) { rand_gauss_fx( ptr_r, seed, exp_out ); Word16 exp2 = sub( 31, hFdCngCom->cngNoiseLevelExp ); @@ -2819,6 +2790,7 @@ void generate_masking_noise_lb_dirac_fx( set32_fx( fftBuffer + shl( hFdCngCom->stopFFTbin, 1 ), 0, sub( hFdCngCom->fftlen, shl( hFdCngCom->stopFFTbin, 1 ) ) ); /* Nyquist frequency is discarded */ fftBuffer[1] = 0; + move32(); /* Perform STFT synthesis */ SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); @@ -3004,22 +2976,23 @@ void generate_masking_noise_dirac_ivas_fx( IF( cna_flag && tdBuffer_fx != NULL ) { *q_cldfb = q_input; + move16(); IF( scale_fx != 0 ) { /* LF CLDFB*/ - cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[L_mult0( hFdCngCom->numCoreBands, slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); } ELSE { /* LB ana CLDFB*/ - cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); + cldfbAnalysis_ts_fx_fixed_q( &( tdBuffer_fx[L_mult0( hFdCngCom->numCoreBands, slot_index )] ), Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hFdCngCom->numCoreBands, h_cldfb, q_cldfb ); } } /*HF CLDFB - CNA and/or FD-CNG*/ IF( fd_cng_flag ) { - scale_fx += 2048; // 1 in Q11 + scale_fx = L_add( scale_fx, 2048 ); // 1 in Q11 move16(); } IF( scale_fx != 0 ) @@ -3029,10 +3002,10 @@ void generate_masking_noise_dirac_ivas_fx( q_shift = norm_l( scale_fx ); scale_fx = L_shl( scale_fx, q_shift ); q_scale = add( q_scale, q_shift ); - scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2 * Q8 -34 + scale_fx = Mpy_32_32( scale_fx, Mpy_32_16_1( L_mult( h_cldfb->scale, h_cldfb->scale ), CLDFB_SCALING ) ); // Q = q_scale + 2 * Q8 - 34 q_scale = sub( add( q_scale, 2 * Q8 ), 31 ); - ptr_level_fx = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; - q_ptr_level = 31 - hFdCngCom->cngNoiseLevelExp; + ptr_level_fx = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); + q_ptr_level = sub( 31, hFdCngCom->cngNoiseLevelExp ); move16(); FOR( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ ) @@ -3049,9 +3022,11 @@ void generate_masking_noise_dirac_ivas_fx( /* Real part in CLDFB band */ rand_gauss_fx( &Cldfb_RealBuffer_fx[i], seed, *q_cldfb ); Cldfb_RealBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_RealBuffer_fx[i], num ), exp ); + move32(); /* Imaginary part in CLDFB band */ rand_gauss_fx( &Cldfb_ImagBuffer_fx[i], seed, *q_cldfb ); Cldfb_ImagBuffer_fx[i] = L_shl( Mpy_32_32( Cldfb_ImagBuffer_fx[i], num ), exp ); + move32(); ptr_level_fx++; } @@ -3092,7 +3067,7 @@ void FdCngDecodeMDCTStereoSID_fx( Word32 tmp32, tmp32_arr[NPART]; invTrfMatrix_fx = (Word32 *) tmpRAM_fx; - create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); // Q31 + create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); // Q31 is_out_ms = 0; move16(); @@ -3182,14 +3157,14 @@ void FdCngDecodeMDCTStereoSID_fx( // Bringing in same exponent FOR( p = 0; p < N; p++ ) { - lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], ( exp_arr[p] - exp_arr[max_exp_idx] ) ); + lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); move32(); } hFdCngCom->sidNoiseEstExp = exp_arr[max_exp_idx]; move16(); - scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 ); + scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 ); hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp; move16(); @@ -3353,8 +3328,8 @@ void FdCngDecodeDiracMDCTStereoSID_fx( Word16 exp_arr[NPART]; Word32 tmp32, tmp32_arr[NPART]; - invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /* dynamically filled */ - create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); // Q31 + invTrfMatrix_fx = (Word32 *) tmpRAM_fx; /* dynamically filled */ + create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); // Q31 FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { @@ -3410,7 +3385,7 @@ void FdCngDecodeDiracMDCTStereoSID_fx( // Bringing in same exponent FOR( p = 0; p < N; p++ ) { - lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], ( exp_arr[p] - exp_arr[max_exp_idx] ) ); + lr_ptr_fx[ch][p] = L_shl( tmp32_arr[p], sub( exp_arr[p], exp_arr[max_exp_idx] ) ); move32(); } @@ -3419,18 +3394,18 @@ void FdCngDecodeDiracMDCTStereoSID_fx( /* NB last band energy compensation */ test(); - IF( EQ_16( hFdCngCom->CngBandwidth, NB ) ) + IF( hFdCngCom->CngBandwidth == NB ) { - lr_ptr_fx[ch][N - 1] = Mpy_32_32( lr_ptr_fx[ch][N - 1], NB_LAST_BAND_SCALE_Q31 ); + lr_ptr_fx[ch][sub( N, 1 )] = Mpy_32_32( lr_ptr_fx[ch][sub( N, 1 )], NB_LAST_BAND_SCALE_Q31 ); move32(); } ELSE IF( EQ_16( hFdCngCom->CngBandwidth, SWB ) && LE_32( hFdCngCom->CngBitrate, ACELP_13k20 ) ) { - lr_ptr_fx[ch][N - 1] = Mpy_32_32( lr_ptr_fx[ch][N - 1], SWB_13k2_LAST_BAND_SCALE_Q31 ); + lr_ptr_fx[ch][sub( N, 1 )] = Mpy_32_32( lr_ptr_fx[ch][sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE_Q31 ); move32(); } - scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 ); + scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, sub( hFdCngCom->stopBand, hFdCngCom->startBand ), hFdCngCom->cngNoiseLevel, 1 ); hFdCngCom->cngNoiseLevelExp = hFdCngCom->sidNoiseEstExp; move16(); @@ -3462,7 +3437,6 @@ void FdCngDecodeDiracMDCTStereoSID_fx( IF( LT_16( exp_diff, 0 ) ) { sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp = add( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, negate( exp_diff ) ); - move16(); } } diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 91022457e..cdbf98f55 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -54,11 +54,11 @@ ivas_error createFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) /* Allocate memory */ hs = (HANDLE_FD_CNG_DEC) count_malloc( sizeof( FD_CNG_DEC ) ); - if ( hs == NULL ) + 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 ) + IF( ( error = createFdCngCom( &( hs->hFdCngCom ) ) ) != IVAS_ERR_OK ) { return error; } @@ -81,10 +81,8 @@ void initFdCngDec_ivas_fx( ivas_initFdCngCom_fx( hFdCngDec->hFdCngCom, scale ); set16_fx( hFdCngDec->olapBufferAna, 0, FFTLEN ); hFdCngDec->hFdCngCom->olapBufferAna = hFdCngDec->olapBufferAna; - move16(); set16_fx( hFdCngDec->olapBufferSynth2, 0, FFTLEN ); hFdCngDec->hFdCngCom->olapBufferSynth2 = hFdCngDec->olapBufferSynth2; - move16(); /* Set some counters and flags */ @@ -208,7 +206,9 @@ void initFdCngDec_fx( hFdCngDec->flag_dtx_mode = 0; move16(); hFdCngDec->lp_noise = -167772160l /*-20.f Q23*/; /* format: Q8.24 */ + move32(); hFdCngDec->lp_speech = 209715200l /* 25.f Q23*/; /* format: Q8.24 */ + move32(); /* Initialization of the noise estimation algorithm */ @@ -257,15 +257,19 @@ void initFdCngDec_fx( set16_fx( hFdCngDec->msLogNoiseEst, 0, NPART_SHAPING ); set16_fx( hFdCngDec->psize_shaping, 0, NPART_SHAPING ); - move16(); hFdCngDec->nFFTpart_shaping = 0; + move16(); set32_fx( hFdCngDec->msPeriodog_ST_fx, 0, NPART_SHAPING ); hFdCngDec->msPeriodog_ST_exp = 0; + move16(); hFdCngDec->hFdCngCom->fftBuffer_exp = 0; + move16(); hFdCngDec->hFdCngCom->periodog_exp = 0; + move16(); set32_fx( hFdCngDec->smoothed_psd_fx, 0, L_FRAME16k ); #ifdef IVAS_FLOAT_FIXED hFdCngDec->q_smoothed_psd = Q4; + move16(); #endif #ifdef IVAS_CODE_CNG @@ -325,12 +329,14 @@ void configureFdCngDec_fx( hsCom->CngBandwidth = bwidth; + move16(); IF( EQ_16( hsCom->CngBandwidth, FB ) ) { hsCom->CngBandwidth = SWB; + move16(); } test(); - if ( total_brate != FRAME_NO_DATA && NE_32( total_brate, SID_2k40 ) ) + IF( total_brate != FRAME_NO_DATA && NE_32( total_brate, SID_2k40 ) ) { hsCom->CngBitrate = total_brate; move32(); @@ -339,17 +345,17 @@ void configureFdCngDec_fx( { /* set minimum active CBR bitrate if CngBitrate is uninitialized */ hsCom->CngBitrate = ACELP_7k20; - IF( GT_16( element_mode, EVS_MONO ) ) + move32(); + if ( 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 ) ) + if ( EQ_16( element_mode, IVAS_CPE_MDCT ) ) { hsCom->CngBitrate = IVAS_48k; move32(); @@ -453,7 +459,7 @@ void configureFdCngDec_fx( hsCom->startBand = 2; move16(); - hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1], 1 ); + hsCom->stopBand = add( hsCom->FdCngSetup.sidPartitions[sub( 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 ); @@ -473,9 +479,9 @@ void configureFdCngDec_fx( hsCom->nCLDFBpart = sub( hsCom->npart, hsCom->nFFTpart ); FOR( j = 0; j < hsCom->nCLDFBpart; j++ ) { - hsCom->CLDFBpart[j] = sub( hsCom->part[j + hsCom->nFFTpart], ( hsCom->stopFFTbin - hsCom->startBand ) ); + hsCom->CLDFBpart[j] = sub( hsCom->part[add( j, hsCom->nFFTpart )], sub( hsCom->stopFFTbin, hsCom->startBand ) ); move16(); - hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart]; + hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[add( j, hsCom->nFFTpart )]; move16(); } @@ -593,6 +599,8 @@ Word16 ApplyFdCng_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; Flag Carry = 0; + move16(); + move16(); #endif #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT int16_t L_frame, last_L_frame; @@ -623,7 +631,6 @@ Word16 ApplyFdCng_fx( cngNoiseLevel = hFdCngCom->cngNoiseLevel; cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; move16(); - move16(); nBins = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); SWITCH( st->m_frame_type ) @@ -663,9 +670,20 @@ Word16 ApplyFdCng_fx( ( st->element_mode == IVAS_CPE_TD ) ) && ( !st->BER_detect ) ) #else + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( ( concealWholeFrame == 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 == LP_CNG ) && ( hFdCngDec->flag_dtx_mode != 0 ) ) == 0 ) && ( is_music == 0 ) && ( st->BER_detect == 0 ) ) + ( LT_16( *timeDomainInput, MAXVAL_WORD16 ) ) && GT_16( *timeDomainInput, MINVAL_WORD16 ) && ( LT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MAXVAL_WORD16 ) ) && GT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MINVAL_WORD16 ) && ( ( ( hFdCngDec->flag_dtx_mode == 0 ) && ( st->VAD != 0 ) ) == 0 ) && ( ( ( st->cng_type == LP_CNG ) && ( hFdCngDec->flag_dtx_mode != 0 ) ) == 0 ) && ( is_music == 0 ) && ( st->BER_detect == 0 ) ) #endif { /* Perform noise estimation at the decoder */ @@ -687,7 +705,7 @@ Word16 ApplyFdCng_fx( /* Update CNG levels */ test(); - IF( hFdCngDec->flag_dtx_mode != 0 && st->cng_type == FD_CNG ) + IF( hFdCngDec->flag_dtx_mode != 0 && EQ_16( st->cng_type, FD_CNG ) ) { /* This needs to be done only once per inactive phase */ bandcombinepow( @@ -803,12 +821,14 @@ Word16 ApplyFdCng_fx( { Carry = 0; + move16(); #ifdef BASOP_NOGLOB L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif Overflow = 0; + move16(); if ( *( cngNoiseLevel + j ) < 0 ) { @@ -860,8 +880,10 @@ Word16 ApplyFdCng_fx( L_tmp = L_add( L_tmp, L_shr( cngNoiseLevel[j], 16 ) ); } L_tmp_exp = add( *cngNoiseLevel_exp, 16 ); + test(); + test(); #ifdef BASOP_NOGLOB - IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( L_shl_o( L_tmp, L_tmp_exp, &Overflow ) > 21474836 /*0.01f Q31*/ ) ) + IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( GT_32( L_shl_o( L_tmp, L_tmp_exp, &Overflow ), 21474836 ) /*0.01f Q31*/ ) ) #else IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( L_shl( L_tmp, L_tmp_exp ) > 21474836 /*0.01f Q31*/ ) ) #endif @@ -943,14 +965,15 @@ Word16 ApplyFdCng_fx( #endif /* Update the shaping parameters */ + 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, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape, 1 ); + scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( 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( hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -964,9 +987,11 @@ Word16 ApplyFdCng_fx( { Carry = 0; + move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); Overflow = 0; + move16(); if ( *( cngNoiseLevel + j ) < 0 ) { @@ -1029,7 +1054,7 @@ Word16 ApplyFdCng_fx( hFdCngCom->psize_inv, hFdCngDec->partNoiseShape, &hFdCngDec->partNoiseShape_exp ); - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) + if ( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { #ifdef IVAS_CODE_CNG Copy( hFdCngDec->hFdCngCom->sidNoiseEst, hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART ); @@ -1196,6 +1221,8 @@ Word16 ApplyFdCng_ivas_fx( #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; Flag Carry = 0; + move16(); + move16(); #endif Word16 L_frame, last_L_frame; // Word32 *sidNoiseEst; @@ -1216,13 +1243,11 @@ Word16 ApplyFdCng_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG; - test(); move16(); } cngNoiseLevel = hFdCngCom->cngNoiseLevel; cngNoiseLevel_exp = &hFdCngCom->cngNoiseLevelExp; move16(); - move16(); nBins = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); SWITCH( st->m_frame_type ) @@ -1251,13 +1276,20 @@ Word16 ApplyFdCng_ivas_fx( test(); test(); test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( concealWholeFrame, 0 ) && ( timeDomainInput == NULL || - ( *timeDomainInput( MINVAL_WORD16 ) && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) < MAXVAL_WORD16 && - *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( MINVAL_WORD16 ) ) ) && + ( LT_16( *timeDomainInput, MAXVAL_WORD16 ) && GT_16( *timeDomainInput, MINVAL_WORD16 ) && + LT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MAXVAL_WORD16 ) && + GT_16( *( timeDomainInput + sub( hFdCngCom->frameSize, 1 ) ), MINVAL_WORD16 ) ) ) && ( ( ( ( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && hFdCngDec->flag_dtx_mode ) || !st->VAD || ( LT_16( st->ini_frame, 100 ) && st->is_ism_format ) ) && - !( EQ_16( st->cng_type, LP_CNG ) && hFdCngDec->flag_dtx_mode ) && ( EQ_16( is_music, 0 ) ) ) || + !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && ( !st->BER_detect ) ) { @@ -1276,7 +1308,7 @@ Word16 ApplyFdCng_ivas_fx( /* Update CNG levels */ test(); - IF( hFdCngDec->flag_dtx_mode != 0 && st->cng_type == FD_CNG ) + IF( hFdCngDec->flag_dtx_mode != 0 && EQ_16( st->cng_type, FD_CNG ) ) { /* This needs to be done only once per inactive phase */ bandcombinepow( @@ -1387,18 +1419,20 @@ Word16 ApplyFdCng_ivas_fx( { Carry = 0; + move16(); #ifdef BASOP_NOGLOB L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif Overflow = 0; + move16(); - IF( *( cngNoiseLevel + j ) < 0 ) + if ( *( cngNoiseLevel + j ) < 0 ) { L_c = L_msuNs( L_c, 0, 0 ); } - IF( *( cngNoiseLevel + j ) >= 0 ) + if ( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); @@ -1439,18 +1473,20 @@ Word16 ApplyFdCng_ivas_fx( { Carry = 0; + move16(); #ifdef BASOP_NOGLOB L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif Overflow = 0; + move16(); - IF( *( cngNoiseLevel + j ) < 0 ) + if ( *( cngNoiseLevel + j ) < 0 ) { L_c = L_msuNs( L_c, 0, 0 ); } - IF( *( cngNoiseLevel + j ) >= 0 ) + if ( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); @@ -1488,18 +1524,20 @@ Word16 ApplyFdCng_ivas_fx( { Carry = 0; + move16(); #ifdef BASOP_NOGLOB L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); #else L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); #endif Overflow = 0; + move16(); - IF( *( cngNoiseLevel + j ) < 0 ) + if ( *( cngNoiseLevel + j ) < 0 ) { L_c = L_msuNs( L_c, 0, 0 ); } - IF( *( cngNoiseLevel + j ) >= 0 ) + if ( *( cngNoiseLevel + j ) >= 0 ) { #ifdef BASOP_NOGLOB L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); @@ -1533,12 +1571,12 @@ Word16 ApplyFdCng_ivas_fx( perform_noise_estimation_dec_ivas_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } } - test(); - test(); + test(); IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) ) { /* always set psychParameters for MDCT-Stereo ... */ + test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->hTonalMDCTConc != NULL ) { st->hTonalMDCTConc->psychParams = EQ_16( st->core, TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10; @@ -1549,16 +1587,18 @@ Word16 ApplyFdCng_ivas_fx( move32(); FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) { - L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], 31 - *cngNoiseLevel_exp ) ); + L_tmp = L_add_sat( L_tmp, L_shl_sat( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); } L_tmp_exp = 0; move16(); #ifdef BASOP_NOGLOB - IF( L_shl_o( L_tmp, L_tmp_exp, &Overflow ) > 21474836 /*0.01f Q31*/ ) + IF( GT_32( L_shl_o( L_tmp, L_tmp_exp, &Overflow ), 21474836 ) /*0.01f Q31*/ ) #else IF( L_shl( L_tmp, L_tmp_exp ) > 21474836 /*0.01f Q31*/ ) #endif { + test(); + test(); IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( st->core, ACELP_CORE ) ) { TonalMdctConceal_whiten_noise_shape_ivas_fx( st, L_frame, ON_FIRST_LOST_FRAME ); @@ -1594,14 +1634,15 @@ Word16 ApplyFdCng_ivas_fx( /* Update the shaping parameters */ + test(); IF( NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - scalebands_fx( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape, 1 ); + scalebands_fx( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, sub( 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( hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */ + Copy32( hFdCngDec->bandNoiseShape, cngNoiseLevel, sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ) ); /* This sets the new CNG levels until a SID update overwrites it */ *cngNoiseLevel_exp = hFdCngDec->bandNoiseShape_exp; move16(); @@ -1613,15 +1654,17 @@ Word16 ApplyFdCng_ivas_fx( { Carry = 0; + move16(); #ifdef BASOP_NOGLOB /* Critical Carry/Overflow */ L_tmp = L_add_co( L_tmp, *( cngNoiseLevel + j ), &Carry, &Overflow ); Overflow = 0; + move16(); - IF( *( cngNoiseLevel + j ) < 0 ) + if ( *( cngNoiseLevel + j ) < 0 ) { L_c = L_msuNs_co( L_c, 0, 0, &Carry, &Overflow ); } - IF( *( cngNoiseLevel + j ) >= 0 ) + if ( *( cngNoiseLevel + j ) >= 0 ) { L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); } @@ -1629,11 +1672,11 @@ Word16 ApplyFdCng_ivas_fx( L_tmp = L_add_c( L_tmp, *( cngNoiseLevel + j ) ); Overflow = 0; - IF( *( cngNoiseLevel + j ) < 0 ) + if ( *( cngNoiseLevel + j ) < 0 ) { L_c = L_msuNs( L_c, 0, 0 ); } - IF( *( cngNoiseLevel + j ) >= 0 ) + if ( *( cngNoiseLevel + j ) >= 0 ) { L_c = L_macNs( L_c, 0, 0 ); } @@ -1658,7 +1701,6 @@ Word16 ApplyFdCng_ivas_fx( BREAK; } hFdCngCom->inactive_frame_counter = add( hFdCngCom->inactive_frame_counter, 1 ); - move16(); /************************************* * SID_FRAME or ZERO_FRAME at DECODER * @@ -1783,12 +1825,11 @@ Word16 ApplyFdCng_ivas_fx( } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - IF( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + IF( !( LT_16( hFdCngCom->msFrCnt_init_counter, hFdCngCom->msFrCnt_init_thresh ) ) ) { // sidNoiseEst = hFdCngCom->sidNoiseEstLp; s2 = negate( sub( WORD32_BITS, 1 ) ); - move16(); /* Shape the SID noise levels in each FFT bin */ j = 0; move16(); @@ -2221,7 +2262,7 @@ void perform_noise_estimation_dec_fx( len = sub( stopFFTbin, startBand ); - s = getScaleFactor32( &fftBuffer[2 * startBand], 2 * len ); + s = getScaleFactor32( &fftBuffer[shl( startBand, 1 )], shl( len, 1 ) ); s = sub( s, 1 ); ptr_per = periodog; @@ -2232,6 +2273,7 @@ void perform_noise_estimation_dec_fx( tmp = L_mult( tmp_r, tmp_r ); *ptr_per = tmp; + move32(); ptr_per++; ptr_r = fftBuffer + 2; @@ -2250,6 +2292,7 @@ void perform_noise_estimation_dec_fx( tmp = L_mac( L_mult( tmp_r, tmp_r ), tmp_i, tmp_i ); *ptr_per = tmp; + move32(); ptr_r += 2; ptr_i += 2; @@ -2289,6 +2332,7 @@ void perform_noise_estimation_dec_fx( FOR( i = 0; i < len; i++ ) { hFdCngDec->hFdCngCom->periodog[i] = Mpy_32_16_1( hFdCngDec->hFdCngCom->periodog[i], fac ); + move32(); } hFdCngDec->hFdCngCom->periodog_exp = add( hFdCngDec->hFdCngCom->periodog_exp, sub( 2, s ) ); #endif @@ -2400,24 +2444,29 @@ void perform_noise_estimation_dec_ivas_fx( move16(); /* Perform STFT analysis */ + test(); IF( !( EQ_16( element_mode, IVAS_CPE_MDCT ) && power_spectrum != NULL ) ) { /* Perform STFT analysis */ AnalysisSTFT_fx( timeDomainInput, Q, fftBuffer, &fftBuffer_exp, hFdCngDec->hFdCngCom ); } + test(); IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_DFT ) ) { SWITCH( hFdCngDec->hFdCngCom->fftlen ) { case 640: rescale_fac = 20972; // 4/(640 * 640) in Q31 + move32(); BREAK; case 512: rescale_fac = 32768; // 4/(512 * 512) in Q31 + move32(); BREAK; case 320: rescale_fac = 83886; // 4/(320 * 320) in Q31 + move32(); BREAK; default: assert( 0 ); @@ -2427,6 +2476,7 @@ void perform_noise_estimation_dec_ivas_fx( { W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); min_q = 2; + move16(); ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( i_mult( sub( 31, fftBuffer_exp ), 2 ), min_q ) ) ); ptr_per++; ptr_r = fftBuffer + 2; @@ -2467,7 +2517,7 @@ void perform_noise_estimation_dec_ivas_fx( min_q = 0; } } - ( *ptr_per ) = W_extract_l( W_shr( W_tmp, ( 31 - fftBuffer_exp ) * 2 - min_q ) ); // Qmin_q + ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( shl( sub( 31, fftBuffer_exp ), 1 ), min_q ) ) ); // Qmin_q /* 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*/ ( *ptr_per ) = Mpy_32_32_r( ( *ptr_per ), rescale_fac ); // Q = min_q @@ -2482,8 +2532,9 @@ void perform_noise_estimation_dec_ivas_fx( hFdCngDec->hFdCngCom->periodog_exp = sub( 31, min_q ); hFdCngDec->hFdCngCom->fftBuffer_exp = fftBuffer_exp; + move16(); - tmp_s = getScaleFactor32( periodog, stopFFTbin - startBand ); + tmp_s = getScaleFactor32( periodog, sub( stopFFTbin, startBand ) ); IF( GT_16( tmp_s, 7 ) ) { tmp_s = sub( tmp_s, 7 ); @@ -2491,6 +2542,7 @@ void perform_noise_estimation_dec_ivas_fx( FOR( p = 0; p < stopFFTbin - startBand; p++ ) { periodog[p] = L_shl( periodog[p], tmp_s ); + move32(); } } @@ -2506,19 +2558,24 @@ void perform_noise_estimation_dec_ivas_fx( temp = L_add( temp, periodog[i] ); } msPeriodog[p] = Mpy_32_16_1( temp, psize_inv[p] ); // Qtemp = Qperiodog + move32(); } hFdCngDec->msPeriodog_exp = hFdCngDec->hFdCngCom->periodog_exp; + move16(); /* 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; + move16(); FOR( p = 0; p < npart; p++ ) { /* calculate variance over all bins in power partition */ temp = 0; + move32(); W_tmp = 0; + move64(); FOR( ; i <= part[p]; i++ ) { delta = L_sub( periodog[i], msPeriodog[p] ); @@ -2544,10 +2601,12 @@ void perform_noise_estimation_dec_ivas_fx( L_tmp = L_shr( L_tmp, sub( sub( hFdCngDec->hFdCngCom->periodog_exp, e_temp ), 2 ) ); msPeriodog[p] = L_add( msPeriodog[p], L_tmp ); + move32(); IF( LT_32( msPeriodog[p], 0 ) ) { msPeriodog[p] = 0; + move32(); } } } @@ -2559,11 +2618,14 @@ void perform_noise_estimation_dec_ivas_fx( FOR( p = 0; p < npart; p++ ) { msPeriodog[p] = L_shr( msPeriodog[p], sub( 5, tmp_s ) ); + move32(); } hFdCngDec->msPeriodog_exp = add( hFdCngDec->msPeriodog_exp, sub( 5, tmp_s ) ); } enr_tot = 1; + move32(); enr_tot0 = 1; + move32(); IF( GE_16( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ) { enr_tot = L_add_sat( L_shr( sum32_fx( msPeriodog, npart ), sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ), 1 ); @@ -2575,33 +2637,41 @@ void perform_noise_estimation_dec_ivas_fx( enr_tot0 = L_add_sat( L_shr( sum32_fx( msNoiseEst, npart ), sub( hFdCngDec->msPeriodog_exp, hFdCngDec->msNoiseEst_exp ) ), 1 ); } + test(); IF( !( NE_16( L_frame, last_L_frame ) || LE_32( last_core_brate, SID_2k40 ) ) ) { IF( GT_16( hFdCngDec->hFdCngCom->periodog_exp, hFdCngDec->msPeriodog_ST_exp ) ) { exp_flag = 1; + move16(); } ELSE { exp_flag = 0; + move16(); } } /* update short-term periodogram on larger partitions */ FOR( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ ) { + test(); IF( NE_16( L_frame, last_L_frame ) || LE_32( last_core_brate, SID_2k40 ) ) { /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */ hFdCngDec->msPeriodog_ST_fx[p] = msPeriodog[p]; + move32(); hFdCngDec->msPeriodog_ST_exp = hFdCngDec->hFdCngCom->periodog_exp; + move16(); } ELSE { temp = msPeriodog[p]; + move32(); IF( exp_flag ) { hFdCngDec->msPeriodog_ST_fx[p] = L_shr( hFdCngDec->msPeriodog_ST_fx[p], sub( hFdCngDec->hFdCngCom->periodog_exp, hFdCngDec->msPeriodog_ST_exp ) ); + move32(); } ELSE { @@ -2609,13 +2679,16 @@ void perform_noise_estimation_dec_ivas_fx( } hFdCngDec->msPeriodog_ST_fx[p] = L_add( Mpy_32_16_1( hFdCngDec->msPeriodog_ST_fx[p], ST_PERIODOG_FACT_Q15 ), Mpy_32_16_1( temp, sub( MAX_16, ST_PERIODOG_FACT_Q15 ) ) ); + move32(); } } + test(); IF( !( NE_16( L_frame, last_L_frame ) || LE_32( last_core_brate, SID_2k40 ) ) ) { IF( exp_flag ) { hFdCngDec->msPeriodog_ST_exp = hFdCngDec->hFdCngCom->periodog_exp; + move16(); } } @@ -2630,25 +2703,40 @@ void perform_noise_estimation_dec_ivas_fx( /* [60] 317 230 */ /* [61] 253 */ + test(); + test(); IF( EQ_16( last_L_frame, L_FRAME16k ) && EQ_16( L_frame, L_FRAME ) ) { msNoiseEst[61] = msNoiseEst[58]; + move32(); msNoiseEst[60] = L_min( msNoiseEst[58], msNoiseEst[57] ); + move32(); msNoiseEst[59] = msNoiseEst[57]; + move32(); msNoiseEst[58] = msNoiseEst[56]; + move32(); msNoiseEst[57] = msNoiseEst[56]; + move32(); msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[55] ); + move32(); } ELSE IF( EQ_16( last_L_frame, L_FRAME ) && EQ_16( L_frame, L_FRAME16k ) ) { msNoiseEst[56] = L_min( msNoiseEst[56], msNoiseEst[57] ); + move32(); msNoiseEst[57] = L_min( msNoiseEst[58], msNoiseEst[59] ); + move32(); msNoiseEst[58] = L_min( msNoiseEst[60], msNoiseEst[61] ); + move32(); msNoiseEst[59] = 0; + move32(); msNoiseEst[60] = 0; + move32(); msNoiseEst[61] = 0; + move32(); hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; + move16(); } /* Smooth with IIR filter */ @@ -2657,10 +2745,11 @@ void perform_noise_estimation_dec_ivas_fx( IF( !VAD ) { Word16 e = 15; + move16(); /* background noise update with moving average */ IF( NE_16( hFdCngDec->first_cna_noise_update_cnt, 0 ) ) { - alpha = Inv16( hFdCngDec->first_cna_noise_update_cnt + 1, &e ); + alpha = Inv16( add( hFdCngDec->first_cna_noise_update_cnt, 1 ), &e ); IF( LT_16( e, 0 ) ) { alpha = shr( alpha, negate( e ) ); // Q15 @@ -2668,8 +2757,10 @@ void perform_noise_estimation_dec_ivas_fx( FOR( p = 0; p < npart; p++ ) { temp = msPeriodog[p]; + move32(); temp = L_shr( temp, sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ); msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], sub( shl_sat( 1, sub( 15, e ) ), alpha ) ), Mpy_32_16_1( temp, alpha ) ); + move32(); } } ELSE @@ -2677,31 +2768,36 @@ void perform_noise_estimation_dec_ivas_fx( FOR( p = 0; p < npart; p++ ) { msNoiseEst[p] = L_shr( msPeriodog[p], sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ); + move32(); } } /* 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 ) + IF( LT_16( 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; + move16(); IF( EQ_16( hFdCngDec->hFdCngCom->msFrCnt_init_counter, 0 ) ) { hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1; + move16(); } } } ELSE { hFdCngDec->first_cna_noise_update_cnt = 0; + move16(); } } ELSE { hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1; + move16(); IF( VAD ) { Word16 scale; @@ -2723,6 +2819,7 @@ void perform_noise_estimation_dec_ivas_fx( wght = lin_interp_fx( enr_ratio, 0, shr( 26214, sub( 15, scale ) ) /*0.8f in Q15*/, shr( 16384, sub( 15, scale ) ) /*0.5f in Q15*/, shr( 31130, sub( 15, scale ) ) /*0.95f in Q15*/, shr( 32767, sub( 15, scale ) ) /*1 in Q15*/ ); Word16 temp_q_msNoiseEst[NPART_SHAPING]; Word16 min_q_msNoiseEst = MAX_16; + move16(); FOR( p = 0; p < NPART_SHAPING; p++ ) { temp_q_msNoiseEst[p] = hFdCngDec->msNoiseEst_exp; @@ -2734,13 +2831,16 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_32( L_tmp, msNoiseEst[p] ) ) { msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], wght ), Mpy_32_16_1( L_tmp, (Word16) L_sub( shr( MAX_16, sub( 15, scale ) ), wght ) ) ); + move32(); temp_q_msNoiseEst[p] = sub( add( hFdCngDec->msNoiseEst_exp, scale ), 15 ); + move16(); } min_q_msNoiseEst = s_min( temp_q_msNoiseEst[p], min_q_msNoiseEst ); } FOR( p = 0; p < NPART_SHAPING; p++ ) { msNoiseEst[p] = L_shl( msNoiseEst[p], sub( min_q_msNoiseEst, temp_q_msNoiseEst[p] ) ); + move32(); } hFdCngDec->msNoiseEst_exp = min_q_msNoiseEst; move16(); @@ -2754,28 +2854,35 @@ void perform_noise_estimation_dec_ivas_fx( IF( LT_32( hFdCngDec->msPeriodog_ST_fx[p], msNoiseEst[p] ) ) { msNoiseEst[p] = L_add( Mpy_32_16_1( msNoiseEst[p], CNA_ACT_DN_FACT_Q15 ), Mpy_32_16_1( L_tmp, (Word16) L_sub( ONE_IN_Q15, CNA_ACT_DN_FACT_Q15 ) ) ); + move32(); } } } } ELSE { - + test(); IF( GE_16( bwidth, WB ) && EQ_16( hFdCngDec->ms_last_inactive_bwidth, NB ) ) { /* bandwidth increased -> set counter for fast initilization */ hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES; + move16(); } hFdCngDec->ms_last_inactive_bwidth = bwidth; + move16(); /* update background noise during inactive frames */ ptr_per = msNoiseEst; FOR( p = 0; p < npart; p++ ) { Word16 i_e = 15; + move16(); enr = msPeriodog[p]; + move32(); temp = L_shr( enr, sub( hFdCngDec->msNoiseEst_exp, hFdCngDec->msPeriodog_exp ) ); alpha = 31130; // 0.95f in Q15 + move16(); /* bandwidth increased -> do fast re-initilization */ + test(); IF( GT_16( hFdCngDec->ms_cnt_bw_up, 0 ) && GT_16( p, 55 ) ) { alpha = Inv16( add( hFdCngDec->ms_cnt_bw_up, 1 ), &i_e ); @@ -2788,6 +2895,7 @@ void perform_noise_estimation_dec_ivas_fx( { /* faster downward update for single-bin partitions */ alpha = 26214; // 0.8f in Q15 + move16(); } ELSE IF( GT_32( temp, L_shl( ( *ptr_per ), 1 ) ) ) { @@ -2810,21 +2918,24 @@ void perform_noise_estimation_dec_ivas_fx( Copy32( msNoiseEst, hFdCngDec->msPsd_fx, npart ); hFdCngDec->msPsd_exp_fft = hFdCngDec->msNoiseEst_exp; + move16(); /* Expand partitions into bins of power spectrum */ scalebands_fx( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, sub( stopFFTbin, startBand ), hFdCngDec->bandNoiseShape, 1 ); hFdCngDec->bandNoiseShape_exp = hFdCngDec->msNoiseEst_exp; + move16(); Copy32( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd_fx[startBand], sub( stopFFTbin, startBand ) ); hFdCngDec->q_smoothed_psd = sub( Q31, hFdCngDec->bandNoiseShape_exp ); set32_fx( &hFdCngDec->smoothed_psd_fx[stopFFTbin], 0, sub( L_FRAME16k, stopFFTbin ) ); } ELSE { + test(); IF( EQ_16( 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; - periodog_exp = 31 - Q_power_spectrum; + periodog_exp = sub( 31, Q_power_spectrum ); } ELSE { @@ -2833,6 +2944,7 @@ void perform_noise_estimation_dec_ivas_fx( { W_tmp = W_mult0_32_32( fftBuffer[0], fftBuffer[0] ); /* DC component */ min_q = 2; + move16(); ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( i_mult( sub( 31, fftBuffer_exp ), 2 ), min_q ) ) ); ptr_per++; ptr_r = fftBuffer + 2; @@ -2848,12 +2960,15 @@ void perform_noise_estimation_dec_ivas_fx( { case 640: rescale_fac = 20972; // 4/(640 * 640) in Q31 + move32(); BREAK; case 512: rescale_fac = 32768; // 4/(512 * 512) in Q31 + move32(); BREAK; case 320: rescale_fac = 83886; // 4/(320 * 320) in Q31 + move32(); BREAK; default: assert( 0 ); @@ -2877,23 +2992,29 @@ void perform_noise_estimation_dec_ivas_fx( { reIter--; *reIter = L_shr( *reIter, diff ); + move32(); } IF( GE_16( tmp_q, 0 ) ) { min_q = tmp_q; + move16(); } ELSE IF( LT_16( tmp_q, 0 ) ) { min_q = 0; + move16(); } } ( *ptr_per ) = W_extract_l( W_shr( W_tmp, sub( i_mult( sub( 31, fftBuffer_exp ), 2 ), min_q ) ) ); // Q = min_q + move32(); /* 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*/ ( *ptr_per ) = Mpy_32_32_r( ( *ptr_per ), rescale_fac ); // Q = min_q + move32(); IF( LT_16( tmp_q, 0 ) ) { ( *ptr_per ) = L_shl( ( *ptr_per ), negate( tmp_q ) ); + move32(); } ptr_r += 2; @@ -2902,6 +3023,7 @@ void perform_noise_estimation_dec_ivas_fx( hFdCngDec->hFdCngCom->periodog_exp = sub( 31, min_q ); hFdCngDec->hFdCngCom->fftBuffer_exp = fftBuffer_exp; + move16(); tmp_s = getScaleFactor32( periodog, L_frame ); IF( GT_16( tmp_s, 3 ) ) @@ -2911,9 +3033,11 @@ void perform_noise_estimation_dec_ivas_fx( FOR( p = 0; p < stopFFTbin - startBand; p++ ) { periodog[p] = L_shl( periodog[p], tmp_s ); + move32(); } } periodog_exp = hFdCngDec->hFdCngCom->periodog_exp; + move16(); } /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */ @@ -2957,6 +3081,7 @@ void perform_noise_estimation_dec_ivas_fx( FOR( i = 0; i < hFdCngDec->npart_shaping; i++ ) { hFdCngDec->msPsd_fx[i] = (Word32) hFdCngDec->msPsd[i]; + move32(); } hFdCngDec->msPsd_exp_fft = 6 + WORD16_BITS; @@ -3024,12 +3149,12 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* MSVQ decoder */ #ifdef IVAS_FLOAT_FIXED - if ( corest->element_mode != EVS_MONO ) + IF( corest->element_mode != EVS_MONO ) { - create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM_fx ) / ( sizeof( Word32 ) ) ); + create_IDCT_N_Matrix_fx( invTrfMatrix_fx, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, FDCNG_VQ_MAX_LEN * FDCNG_VQ_DCT_MAXTRUNC ); msvq_dec_fx( ivas_cdk_37bits_fx, NULL, NULL, stages_37bits, N, maxN_37bits, indices, 1, invTrfMatrix_fx, v, NULL, 7 ); } - else + ELSE #endif { msvq_decoder( @@ -3043,6 +3168,7 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) FOR( i = 0; i < N; i++ ) { v[i] = L_deposit_h( v16[i] ); + move32(); } } @@ -3089,18 +3215,19 @@ void FdCng_decodeSID_fx( HANDLE_FD_CNG_COM st, Decoder_State *corest ) /* NB last band energy compensation */ IF( st->CngBandwidth == NB ) { - st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], NB_LAST_BAND_SCALE ); + st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], NB_LAST_BAND_SCALE ); move32(); } test(); - if ( st->CngBandwidth == SWB && st->CngBitrate <= ACELP_13k20 ) + IF( EQ_16( st->CngBandwidth, SWB ) && LE_32( st->CngBitrate, ACELP_13k20 ) ) { - st->sidNoiseEst[N - 1] = Mpy_32_16_1( st->sidNoiseEst[N - 1], SWB_13k2_LAST_BAND_SCALE ); + st->sidNoiseEst[sub( N, 1 )] = Mpy_32_16_1( st->sidNoiseEst[sub( N, 1 )], SWB_13k2_LAST_BAND_SCALE ); + move32(); } - scalebands( sidNoiseEst, st->part, st->npart, st->midband, st->nFFTpart, st->stopBand - st->startBand, st->cngNoiseLevel, 1 ); + scalebands( sidNoiseEst, st->part, st->npart, st->midband, st->nFFTpart, sub( st->stopBand, st->startBand ), st->cngNoiseLevel, 1 ); st->cngNoiseLevelExp = st->sidNoiseEstExp; move16(); @@ -3170,16 +3297,17 @@ void noisy_speech_detection_fx( } 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; + move32(); Etot_exp = 31; + move16(); FOR( i = 0; i < hFdCngDec->hFdCngCom->frameSize; i++ ) { tmp = L_shr_r( L_mult0( syn[i], syn[i] ), sub( Etot_exp, 31 ) ); - IF( L_sub( maxWord32, tmp ) < Etot ) + IF( LT_32( L_sub( maxWord32, tmp ), Etot ) ) { Etot_exp = add( Etot_exp, 1 ); Etot = L_shr_r( Etot, 1 ); @@ -3215,12 +3343,11 @@ void noisy_speech_detection_fx( } 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( hFdCngDec->lp_speech, 377487360l /*45.0 Q23*/ ); - if ( LT_32( hFdCngDec->lp_noise, tmp ) ) + IF( LT_32( hFdCngDec->lp_noise, tmp ) ) { hFdCngDec->lp_noise = tmp; move32(); @@ -3228,7 +3355,7 @@ void noisy_speech_detection_fx( hFdCngDec->hFdCngCom->flag_noisy_speech = 0; move16(); - if ( LT_32( L_sub( hFdCngDec->lp_speech, hFdCngDec->lp_noise ), 234881024l /*28.0 Q23*/ ) ) + IF( LT_32( L_sub( hFdCngDec->lp_speech, hFdCngDec->lp_noise ), 234881024l /*28.0 Q23*/ ) ) { hFdCngDec->hFdCngCom->flag_noisy_speech = 1; move16(); @@ -3270,11 +3397,13 @@ void generate_comfort_noise_dec_fx( HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec; HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom; TCX_DEC_HANDLE hTcxDec; + move16(); hTcxDec = st->hTcxDec; /* Warning fix */ s = 0; + move16(); // PMTE(); /*IVAS CODE need to be added */ /* pointer initialization */ @@ -3358,12 +3487,12 @@ void generate_comfort_noise_dec_fx( fftBufferExp = add( shr( cngNoiseLevelExp, 1 ), randGaussExp ); /* If previous frame is active, reset the overlap-add buffer */ - IF( hFdCngCom->frame_type_previous == ACTIVE_FRAME ) + IF( EQ_16( hFdCngCom->frame_type_previous, ACTIVE_FRAME ) ) { set16_fx( hFdCngCom->olapBufferSynth, 0, hFdCngCom->fftlen ); test(); test(); - if ( ( st->last_core_bfi > ACELP_CORE && st->codec_mode == MODE2 ) || st->codec_mode == MODE1 ) + if ( ( st->last_core_bfi > ACELP_CORE && EQ_16( st->codec_mode, MODE2 ) ) || EQ_16( st->codec_mode, MODE1 ) ) { tcx_transition = 1; move16(); @@ -3388,12 +3517,12 @@ void generate_comfort_noise_dec_fx( /*(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 ( st->L_frame == L_FRAME16k ) + if ( EQ_16( st->L_frame, 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( st->bwidth, NB ) ) + IF( st->bwidth != NB ) { IF( EQ_16( st->bwidth, WB ) ) { @@ -3463,7 +3592,7 @@ void generate_comfort_noise_dec_fx( /* Overlap-add when previous frame is active */ test(); - IF( hFdCngCom->frame_type_previous == ACTIVE_FRAME && st->codec_mode == MODE2 ) + IF( EQ_16( hFdCngCom->frame_type_previous, ACTIVE_FRAME ) && EQ_16( st->codec_mode, MODE2 ) ) { Word32 old_exc_ener, gain, noise32; Word16 seed_loc, lpcorder, old_syn, tmp, gain16, N, N2, N4, N8; @@ -3494,13 +3623,14 @@ void generate_comfort_noise_dec_fx( 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 ); + st->hTcxCfg->tcx_mdct_window_min_length, 0, left_overlap_mode, NULL, NULL, NULL, NULL, NULL, shr( N, 1 ), shr( sub( abs_s( st->hTcxCfg->tcx_offset ), st->hTcxCfg->tcx_offset ), 1 ), 1, 0, 0 ); IF( st->hTcxCfg->last_aldo != 0 ) { FOR( i = 0; i < sub( hFdCngCom->frameSize, NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ ) { 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 ) ); + move16(); } } ELSE @@ -3510,7 +3640,8 @@ void generate_comfort_noise_dec_fx( FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ ) { - timeDomainOutput[i] += shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ); + timeDomainOutput[i] = add( timeDomainOutput[i], shl( hTcxDec->syn_Overl[i], TCX_IMDCT_HEADROOM ) ); + move16(); } } } @@ -3580,6 +3711,7 @@ void generate_comfort_noise_dec_fx( { noise32 = rand_gauss( &seed_loc ); noise[i] = extract_h( noise32 ); + move16(); gain = L_add( gain, L_shr( L_mult( noise[i], noise[i] ), normShiftP2 ) ); } gain = L_shl( Mpy_32_16_1( gain, shl( normFacG, normShiftGM1 ) ), 1 ); @@ -3645,8 +3777,8 @@ void generate_comfort_noise_dec_fx( tmp = mult( noise[i], hFdCngCom->olapWinSyn[i].v.re ); timeDomainOutput[i] = add( timeDomainOutput[i], tmp ); move16(); - tmp = mult( noise[i + N4], hFdCngCom->olapWinSyn[N4 - 1 - i].v.im ); - timeDomainOutput[i + N4] = add( timeDomainOutput[i + N4], tmp ); + tmp = mult( noise[add( i, N4 )], hFdCngCom->olapWinSyn[sub( sub( N4, 1 ), i )].v.im ); + timeDomainOutput[add( i, N4 )] = add( timeDomainOutput[add( i, N4 )], tmp ); move16(); } } @@ -3670,8 +3802,9 @@ void generate_comfort_noise_dec_hf_fx( Word32 *ptr_level; HANDLE_FD_CNG_COM hFdCngCom = st->hFdCngDec->hFdCngCom; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; + move16(); ptr_level = cngNoiseLevel; seed = &( hFdCngCom->seed ); @@ -3684,7 +3817,6 @@ void generate_comfort_noise_dec_hf_fx( { sn = add( sn, 1 ); cngNoiseLevelExp = add( cngNoiseLevelExp, sn ); - move16(); } randGaussExp = CNG_RAND_GAUSS_SHIFT; @@ -3743,7 +3875,7 @@ void generate_comfort_noise_dec_hf_ivas_fx( Word32 *cngNoiseLevel; Word32 tmp1, tmp2; - cngNoiseLevel = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; + cngNoiseLevel = hFdCngCom->cngNoiseLevel + sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); ptr_level = cngNoiseLevel; @@ -3812,9 +3944,7 @@ void generate_comfort_noise_dec_hf_ivas_fx( IF( cng_coh_flag ) { tmp1 = rand_gauss( seed ); - move16(); tmp2 = rand_gauss( seed2 ); - move16(); bufferReal[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); move32(); @@ -3822,9 +3952,7 @@ void generate_comfort_noise_dec_hf_ivas_fx( move32(); tmp1 = rand_gauss( seed ); - move16(); tmp2 = rand_gauss( seed2 ); - move16(); bufferImag[i][j] = L_add( Mpy_32_16_1( tmp1, c1 ), Mpy_32_16_1( tmp2, c2 ) ); move32(); @@ -3897,7 +4025,7 @@ void generate_masking_noise_fx( cngNoiseLevelExp = hFdCngCom->cngNoiseLevelExp; move16(); - IF( core != AMR_WB_CORE ) + IF( NE_16( core, AMR_WB_CORE ) ) { scaleTableSize = 18; move16(); diff --git a/lib_dec/ivas_lfe_dec_fx.c b/lib_dec/ivas_lfe_dec_fx.c index 18bb18224..4d5dd9591 100644 --- a/lib_dec/ivas_lfe_dec_fx.c +++ b/lib_dec/ivas_lfe_dec_fx.c @@ -70,7 +70,14 @@ static void ivas_lfe_dec_delay_adjust_fx( Word32 tmp_buffer[L_FRAME48k]; diff = sub( hLFE->lfe_prior_buf_len, hLFE->pWindow_state->fade_len ); - loop_counter = LT_16( diff, 0 ) ? 0 : diff; + IF( diff < 0 ) + { + loop_counter = 0; + } + ELSE + { + loop_counter = diff; + } move16(); fade_len = hLFE->pWindow_state->fade_len; move16(); @@ -233,7 +240,7 @@ static Word16 ivas_lfe_dec_dequant_fx( move16(); FOR( i = 0; i < 4; i++ ) { - abs_values[iii * 4 + i] = get_next_indice_fx( st0, base2_bit_size ); + abs_values[add( iii * 4 , i )] = get_next_indice_fx( st0, base2_bit_size ); move16(); } } @@ -248,7 +255,7 @@ static Word16 ivas_lfe_dec_dequant_fx( FOR( i = 0; i < 4; i++ ) { - abs_values[iii * 4 + i] = ivas_ari_decode_14bits_bit_ext_1_lfe( st0, &as, hLFE->cum_freq_models[quant_strategy][iii], &extra_bits_read ); + abs_values[add( iii * 4, i )] = ivas_ari_decode_14bits_bit_ext_1_lfe( st0, &as, hLFE->cum_freq_models[quant_strategy][iii], &extra_bits_read ); move16(); } ivas_ari_done_decoding_14bits_ext_1_lfe( st0, extra_bits_read ); @@ -259,7 +266,7 @@ static Word16 ivas_lfe_dec_dequant_fx( { values[i] = shl( abs_values[i], 9 ); // Q9 move16(); - IF( GT_16( sign_bits[i], 0 ) ) + IF( sign_bits[i] > 0 ) { values[i] = shl( sub( negate( abs_values[i] ), 1 ), 9 ); // Q9 move16(); @@ -273,12 +280,12 @@ static Word16 ivas_lfe_dec_dequant_fx( { pOut_buf[2 * i] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i] ); // Q30 + Q9 >> 15 = Q24 move32(); - pOut_buf[2 * i + 1] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 1] ); // Q30 + Q9 >> 15 = Q24 + pOut_buf[add( 2 * i, 1 )] = Mpy_32_16_1( two_pow_shift_by_4, values[add( 2 * i, 1 )] ); // Q30 + Q9 >> 15 = Q24 move32(); - pOut_buf[2 * i + *num_dct_pass_bins] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 2] ); // Q30 + Q9 >> 15 = Q24 + pOut_buf[add( 2 * i, *num_dct_pass_bins )] = Mpy_32_16_1( two_pow_shift_by_4, values[add( 4 * i, 2 )] ); // Q30 + Q9 >> 15 = Q24 move32(); - pOut_buf[2 * i + *num_dct_pass_bins + 1] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i + 3] ); // Q30 + Q9 >> 15 = Q24 + pOut_buf[add( add( 2 * i, *num_dct_pass_bins ), 1 )] = Mpy_32_16_1( two_pow_shift_by_4, values[add( 4 * i, 3 )] ); // Q30 + Q9 >> 15 = Q24 move32(); } } @@ -305,6 +312,7 @@ void ivas_lfe_dec_fx( { Word16 num_dct_pass_bins; Word16 i, j, dct_len, q_out = 0; + move16(); Word32 out[L_FRAME48k]; Word32 t_audio[L_FRAME48k]; Word32 lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS]; @@ -314,7 +322,7 @@ void ivas_lfe_dec_fx( num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS; move16(); - IF( EQ_16( bfi, 0 ) ) + IF( bfi == 0 ) { ivas_lfe_dec_dequant_fx( hLFE, st0, lfe_dct, &num_dct_pass_bins ); // Q24 @@ -340,7 +348,7 @@ void ivas_lfe_dec_fx( move16(); FOR( i = 0; i < L_FRAME_1k6; i++ ) { - hLFE->prevsynth_buf_fx[i + LFE_PLC_BUFLEN - L_FRAME_1k6] = output_lfe_ch[j]; + hLFE->prevsynth_buf_fx[sub( add( i, LFE_PLC_BUFLEN ), L_FRAME_1k6 )] = output_lfe_ch[j]; move32(); j = add( j, shr( output_frame, 5 ) ); } @@ -351,8 +359,8 @@ void ivas_lfe_dec_fx( ELSE { /* note: in BFI branch, buffer 't_audio' is in time-domain ('wtda' signal) */ - hLFE->bfi_count++; - + hLFE->bfi_count = add( hLFE->bfi_count, 1 ); + move16(); ivas_lfe_tdplc_fx( hLFE, hLFE->prevsynth_buf_fx, t_audio, output_frame ); ivas_itda_fx( t_audio, out, dct_len ); @@ -375,7 +383,7 @@ void ivas_lfe_dec_fx( } } - IF( GT_16( hLFE->filter_state.order, 0 ) ) + IF( hLFE->filter_state.order > 0 ) { /* NOTE: this block is not getting hit by any stream present in pytest test suite */ /* Low Pass Filter */ @@ -383,7 +391,7 @@ void ivas_lfe_dec_fx( } /* add delay to make overall max(block_offset, 11.5) */ - IF( GT_16( hLFE->lfe_addl_delay, 0 ) ) + IF( hLFE->lfe_addl_delay > 0 ) { delay_signal_fx( output_lfe_ch, output_frame, hLFE->lfe_delay_buf_fx, hLFE->lfe_addl_delay ); } @@ -451,6 +459,7 @@ ivas_error ivas_create_lfe_dec_fx( /* delay calculation */ hLFE->lfe_block_delay_s_fx = add( IVAS_LFE_FADE_S_Q15, ivas_lfe_lpf_delay_Q15[IVAS_FILTER_ORDER_4 - 3] ); + move16(); block_offset_s = BLOCK_OFFSET_S_Q15; move16(); @@ -461,6 +470,7 @@ ivas_error ivas_create_lfe_dec_fx( hLFE->filter_state.order = filt_order; move16(); hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, low_pass_delay_dec_out ); + move16(); hLFE->lfe_prior_buf_len = NS2SA_fx2( output_Fs, IVAS_LFE_FADE_NS ); move16(); @@ -473,10 +483,13 @@ ivas_error ivas_create_lfe_dec_fx( lfe_addl_delay_s = sub( block_offset_s, hLFE->lfe_block_delay_s_fx ); lfe_addl_delay_s = s_max( 0, lfe_addl_delay_s ); add_delay_sa = (Word16) W_round64_L( W_mult0_32_32( L_shl( binauralization_delay_ns, 1 ), output_fs_fx ) ); + move16(); hLFE->lfe_addl_delay = add( (Word16) L_shr( ( (Word32) lfe_addl_delay_s * (Word32) output_Fs ), 15 ), add_delay_sa ); + move16(); hLFE->lfe_block_delay_s_fx = add( hLFE->lfe_block_delay_s_fx, add( lfe_addl_delay_s, (Word16) ( add_delay_sa / output_Fs ) ) ); + move16(); - IF( GT_16( hLFE->lfe_addl_delay, 0 ) ) + IF( hLFE->lfe_addl_delay > 0 ) { IF( ( hLFE->lfe_delay_buf_fx = (Word32 *) malloc( hLFE->lfe_addl_delay * sizeof( Word32 ) ) ) == NULL ) { diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index 325fc962e..7c1d59d5d 100644 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -208,6 +208,7 @@ static Word16 d_lev_dur_fx( { Word16 i, j, l; Word16 flag = 0; + move16(); Word32 buf_fx[TCXLTP_LTP_ORDER]; Word16 rc_q_fx[TCXLTP_LTP_ORDER]; Word32 *rc_fx; /* reflection coefficients 0,...,m-1 */ @@ -305,7 +306,7 @@ static Word16 d_lev_dur_fx( IF( LT_16( rc_q_fx[i - 1], 31 ) ) { - IF( GT_32( abs( rc_fx[i - 1] ), L_shr( 2146302532, sub( 31, rc_q_fx[i - 1] ) ) ) ) // 2146302532 = 0.99945f in Q31 + if ( GT_32( abs( rc_fx[i - 1] ), L_shr( 2146302532, sub( 31, rc_q_fx[i - 1] ) ) ) ) // 2146302532 = 0.99945f in Q31 { flag = 1; /* Test for unstable filter. If unstable keep old A(z) */ move16(); @@ -313,7 +314,7 @@ static Word16 d_lev_dur_fx( } ELSE { - IF( GT_32( abs( L_shr( rc_fx[i - 1], sub( rc_q_fx[i - 1], 31 ) ) ), 2146302532 ) ) // 2146302532 = 0.00045f in Q31 + if ( GT_32( abs( L_shr( rc_fx[i - 1], sub( rc_q_fx[i - 1], 31 ) ) ), 2146302532 ) ) // 2146302532 = 0.00045f in Q31 { flag = 1; /* Test for unstable filter. If unstable keep old A(z) */ move16(); @@ -397,7 +398,7 @@ static Word16 d_lev_dur_fx( err_fx = L_add( err_fx, L_shr( temp1, sub( temp_q1, err_q_fx ) ) ); } - IF( LE_32( err_fx, 0 ) ) + IF( err_fx <= 0 ) { err_fx = 21474836; // 0.01 in Q31 move32(); @@ -437,7 +438,7 @@ static Word16 d_a2rc_fx( FOR( m = 0; m < lpcorder; m++ ) { - ff_fx[m] = -a_fx[m]; + ff_fx[m] = L_negate( a_fx[m] ); move32(); ff_q_fx[m] = a_q_fx[m]; move32(); @@ -460,7 +461,7 @@ static Word16 d_a2rc_fx( return 0; } - refl_fx[m] = -km_fx; + refl_fx[m] = L_negate( km_fx ); move32(); exp1 = norm_l( km_fx ); @@ -470,7 +471,7 @@ static Word16 d_a2rc_fx( denom_fx = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q30, temp1, &temp_q1 ) ); denom_q_fx = sub( 15, temp_q1 ); - FOR( j = 0; j < m / 2; j++ ) + FOR( j = 0; j < shr( m, 1 ); j++ ) { n = sub( sub( m, 1 ), j ); @@ -524,7 +525,7 @@ static Word16 d_a2rc_fx( } } - IF( m & 1 ) + IF( s_and( m, 1 ) ) { exp1 = norm_l( denom_fx ); exp2 = sub( norm_l( ff_fx[j] ), 1 ); @@ -793,7 +794,7 @@ static Word32 find_max_delta_fx( } ELSE { - eps_fx = -abs( eps_fx ); + eps_fx = L_negate( abs( eps_fx ) ); } } ELSE diff --git a/lib_dec/ivas_ls_custom_dec.c b/lib_dec/ivas_ls_custom_dec.c index cfdce74bd..86414d84a 100644 --- a/lib_dec/ivas_ls_custom_dec.c +++ b/lib_dec/ivas_ls_custom_dec.c @@ -82,15 +82,19 @@ ivas_error ivas_ls_custom_open_fx( } ( *hLsSetupCustom )->num_spk = -1; + move16(); ( *hLsSetupCustom )->is_planar_setup = -1; + move16(); set32_fx( ( *hLsSetupCustom )->ls_azimuth_fx, 0, MAX_OUTPUT_CHANNELS ); set32_fx( ( *hLsSetupCustom )->ls_elevation_fx, 0, MAX_OUTPUT_CHANNELS ); ( *hLsSetupCustom )->num_lfe = -1; + move16(); set_s( ( *hLsSetupCustom )->lfe_idx, -1, MAX_OUTPUT_CHANNELS ); ( *hLsSetupCustom )->separate_ch_found = -1; + move16(); set16_fx( ( *hLsSetupCustom )->separate_ch_gains_fx, 0, MAX_OUTPUT_CHANNELS ); return IVAS_ERR_OK; @@ -135,17 +139,25 @@ void ivas_ls_custom_setup_fx( ) { hOutSetup->output_config = IVAS_AUDIO_CONFIG_LS_CUSTOM; + move32(); hOutSetup->nchan_out_woLFE = hLsSetupCustom->num_spk; + move16(); hOutSetup->ls_azimuth_fx = hLsSetupCustom->ls_azimuth_fx; + move32(); hOutSetup->ls_elevation_fx = hLsSetupCustom->ls_elevation_fx; + move32(); hOutSetup->num_lfe = hLsSetupCustom->num_lfe; + move16(); hOutSetup->index_lfe[0] = hLsSetupCustom->lfe_idx[0]; /* IVAS_OUTPUT_SETUP only supports 1 LFE */ + move16(); hOutSetup->is_loudspeaker_setup = TRUE; - hOutSetup->is_planar_setup = (int8_t) hLsSetupCustom->is_planar_setup; + move16(); + hOutSetup->is_planar_setup = (Word8) hLsSetupCustom->is_planar_setup; + move16(); return; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 2673ec268..8b187d57a 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -645,6 +645,7 @@ ivas_error ivas_masa_decode_fx( move16(); hQMetaData->is_masa_ivas_format = 1; + move16(); *nb_bits_read = 0; move16(); @@ -654,7 +655,7 @@ ivas_error ivas_masa_decode_fx( Word16 tmp, tmp_e; tmp = BASOP_Util_Divide3232_Scale( masa_brate, FRAMES_PER_SEC, &tmp_e ); - tmp = shr( tmp, 15 - tmp_e ); + tmp = shr( tmp, sub( 15, tmp_e ) ); assert( masa_brate / FRAMES_PER_SEC == tmp ); IF( EQ_32( masa_brate, IVAS_SID_5k2 ) ) @@ -674,9 +675,9 @@ ivas_error ivas_masa_decode_fx( IF( EQ_16( st->bfi, 0 ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { test(); - IF( NE_16( ivas_format, MC_FORMAT ) || NE_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + IF( NE_32( ivas_format, MC_FORMAT ) || NE_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - IF( NE_16( ivas_format, MASA_ISM_FORMAT ) ) + IF( NE_32( ivas_format, MASA_ISM_FORMAT ) ) { /* number of transport channels is always 2 for MASA_ISM format */ /* the number of MASA transport channels was read in ivas_dec_setup() */ @@ -685,7 +686,7 @@ ivas_error ivas_masa_decode_fx( } test(); - IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && NE_16( st_ivas->ism_mode, ISM_MODE_NONE ) ) + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && NE_32( st_ivas->ism_mode, ISM_MODE_NONE ) ) { /* the number of objects was read */ st->next_bit_pos = sub( st->next_bit_pos, NO_BITS_MASA_ISM_NO_OBJ ); @@ -828,7 +829,7 @@ ivas_error ivas_masa_decode_fx( } test(); - IF( NE_16( ivas_format, MC_FORMAT ) || NE_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + IF( NE_32( ivas_format, MC_FORMAT ) || NE_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { /* read subframe mode */ byteBuffer = st->bit_stream[( st->next_bit_pos )--]; @@ -847,7 +848,7 @@ ivas_error ivas_masa_decode_fx( } /* Once we know incoming configuration, we can config decoder further based on bitrate etc. */ - IF( ( error = ivas_masa_dec_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_masa_dec_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -857,9 +858,12 @@ ivas_error ivas_masa_decode_fx( IF( LT_32( hMasa->config.max_metadata_bits, MINIMUM_BIT_BUDGET_NORMAL_META ) && EQ_16( hMasa->config.joinedSubframes, FALSE ) ) { /* read low bitrate mode */ - byteBuffer = st->bit_stream[( st->next_bit_pos )--]; + byteBuffer = st->bit_stream[st->next_bit_pos]; + move16(); + st->next_bit_pos = sub( st->next_bit_pos, 1 ); move16(); *nb_bits_read = add( *nb_bits_read, 1 ); + move16(); low_bitrate_mode = byteBuffer; move16(); @@ -877,15 +881,17 @@ ivas_error ivas_masa_decode_fx( /* Remove already read bits from the bit budget */ hQMetaData->metadata_max_bits = sub( hQMetaData->metadata_max_bits, *nb_bits_read ); + move16(); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { IF( st_ivas->hDirAC != NULL ) { *nb_bits_read = add( *nb_bits_read, ivas_decode_masaism_metadata_fx( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx, st_ivas->hSpatParamRendCom->dirac_md_buffer_length ) ); + move16(); FOR( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) { IF( EQ_16( st_ivas->hMasaIsmData->idx_separated_ism, obj ) ) @@ -908,6 +914,7 @@ ivas_error ivas_masa_decode_fx( { *nb_bits_read = add( *nb_bits_read, ivas_decode_masaism_metadata_fx( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, 0, MAX_PARAM_SPATIAL_SUBFRAMES ) ); + move16(); } } } @@ -915,10 +922,9 @@ ivas_error ivas_masa_decode_fx( masa_total_brate = ivas_total_brate; move32(); test(); - IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { masa_total_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); - move32(); } IF( GE_32( masa_total_brate, IVAS_384k ) ) @@ -927,11 +933,13 @@ ivas_error ivas_masa_decode_fx( { *nb_bits_read = add( *nb_bits_read, ivas_qmetadata_dec_decode_hr_384_512( hQMetaData, st->bit_stream, &st->next_bit_pos, hMasa->data.sph_grid16, 16, 4, hMasa->config.numCodingBands ) ); + move16(); } ELSE { *nb_bits_read = add( *nb_bits_read, ivas_qmetadata_dec_decode_hr_384_512( hQMetaData, st->bit_stream, &st->next_bit_pos, hMasa->data.sph_grid16, 11, 3, hMasa->config.numCodingBands ) ); + move16(); } } ELSE @@ -942,21 +950,23 @@ ivas_error ivas_masa_decode_fx( test(); test(); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { /* Modify spatial metadata based on the MASA-to-total energy ratios */ ivas_omasa_modify_masa_energy_ratios_fx( hQMetaData, st_ivas->hMasaIsmData->masa_to_total_energy_ratio_fx ); } /* Get direction decoding quality. EC 1 and 2 are handled by the default value. */ - IF( EQ_16( hQMetaData->ec_flag, 2 ) ) + if ( EQ_16( hQMetaData->ec_flag, 2 ) ) { hMasa->data.dir_decode_quality_fx = hQMetaData->dir_comp_ratio_fx; /* Q15 */ + move16(); } hMasa->config.coherencePresent = !hQMetaData->all_coherence_zero; + move16(); - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { index_16bits_fx( hQMetaData, hMasa->data.sph_grid16 ); } @@ -966,17 +976,17 @@ ivas_error ivas_masa_decode_fx( { restore_lowbitrate_masa_fx( hQMetaData, low_bitrate_mode, hMasa->config.numCodingBands ); } - ELSE IF( hMasa->config.joinedSubframes == TRUE ) + ELSE IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) { replicate_subframes_fx( hQMetaData ); } } - ELSE IF( EQ_16( st->bfi, 0 ) && EQ_16( ivas_format, MASA_FORMAT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + ELSE IF( EQ_16( st->bfi, 0 ) && EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { IF( hQMetaData->q_direction == NULL ) { /* replicate ivas_masa_dec_config() in case that first good received frame is SID frame */ - IF( ( error = ivas_masa_dec_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_masa_dec_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -986,13 +996,15 @@ ivas_error ivas_masa_decode_fx( hQMetaData->metadata_max_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; move16(); - IF( ( error = ivas_qmetadata_allocate_memory( hQMetaData, 5, 1, 0 ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_qmetadata_allocate_memory( hQMetaData, 5, 1, 0 ) ), IVAS_ERR_OK ) ) { return error; } hQMetaData->numTwoDirBands = hMasa->config.numTwoDirBands; + move16(); hQMetaData->useLowerRes = 0; + move16(); hQMetaData->q_direction->cfg.nbands = 5; move16(); @@ -1000,7 +1012,7 @@ ivas_error ivas_masa_decode_fx( move16(); test(); - IF( EQ_16( ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + IF( EQ_32( ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { hQMetaData->q_direction->cfg.mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); } @@ -1019,13 +1031,13 @@ ivas_error ivas_masa_decode_fx( IF( EQ_16( st_ivas->nchan_transport, 2 ) ) { - assert( GT_16( st_ivas->nCPE, 0 ) ); + assert( st_ivas->nCPE > 0 ); st_ivas->hCPE[0]->element_mode = tmp_elem_mode; move16(); } *nb_bits_read = add( *nb_bits_read, SID_FORMAT_NBITS ); } - ELSE IF( EQ_16( st->bfi, 0 ) && EQ_16( ivas_format, MASA_FORMAT ) && EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) + ELSE IF( st->bfi == 0 && EQ_32( ivas_format, MASA_FORMAT ) && EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { IF( hQMetaData->q_direction == NULL ) { @@ -1044,11 +1056,11 @@ ivas_error ivas_masa_decode_fx( ivas_qmetadata_to_dirac_fx( hQMetaData, st_ivas->hDirAC, hMasa, st_ivas->hSpatParamRendCom, ivas_total_brate, ivas_format, 0, 0 ); } - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { IF( hQMetaData->q_direction == NULL ) { - IF( ( error = ivas_masa_dec_config_fx( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_masa_dec_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1091,7 +1103,7 @@ ivas_error ivas_masa_decode_fx( st->next_bit_pos = next_bit_pos_orig; move16(); - IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( ivas_format, MASA_ISM_FORMAT ) ) { Word32 cpe_brate; cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, ivas_total_brate, st_ivas->nchan_ism ); @@ -1111,7 +1123,7 @@ ivas_error ivas_masa_decode_fx( move16(); } - IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) + if ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; move32(); @@ -1123,7 +1135,7 @@ ivas_error ivas_masa_decode_fx( test(); test(); test(); - IF( EQ_16( ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->nCPE, 1 ) && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) + IF( EQ_32( ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->nCPE, 1 ) && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) { IF( LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) { @@ -1136,7 +1148,7 @@ ivas_error ivas_masa_decode_fx( move16(); } - IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) + if ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; move16(); @@ -1145,7 +1157,7 @@ ivas_error ivas_masa_decode_fx( } test(); - IF( EQ_16( ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->nCPE, 1 ) ) + IF( EQ_32( ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->nCPE, 1 ) ) { st_ivas->hCPE[0]->hCoreCoder[0]->masa_sid_format = 0; move16(); @@ -1155,7 +1167,7 @@ ivas_error ivas_masa_decode_fx( st_ivas->hCPE[0]->hCoreCoder[0]->masa_sid_format = 1; move16(); - IF( GE_32( ivas_total_brate, IVAS_SID_5k2 ) ) + if ( GE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { st_ivas->hCPE[0]->element_brate = ivas_total_brate; move32(); @@ -1165,7 +1177,7 @@ ivas_error ivas_masa_decode_fx( test(); test(); - IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + IF( ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { create_masa_ext_out_meta_fx( hMasa, hQMetaData, st_ivas->nchan_transport ); } @@ -1307,7 +1319,7 @@ ivas_error ivas_masa_dec_open_fx( test(); test(); test(); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->nSCE, 0 ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->nSCE, 0 ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { FOR( i = 0; i < st_ivas->nSCE; i++ ) { @@ -1320,7 +1332,9 @@ ivas_error ivas_masa_dec_open_fx( Copy( DirAC_block_grouping, hMasa->config.block_grouping, MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); Copy( MASA_band_grouping_24, hMasa->config.band_grouping, MASA_FREQUENCY_BANDS + 1 ); hMasa->config.numberOfDirections = 1; + move16(); hMasa->config.joinedSubframes = FALSE; + move16(); /* Create spherical grid only for external output */ IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) @@ -1386,14 +1400,14 @@ ivas_error ivas_masa_dec_open_fx( test(); test(); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { nchan_transport = 1; move16(); nchan_to_allocate = 1; move16(); } - ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) ) + ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) ) { /* addtl channel for CNG */ nchan_to_allocate = add( nchan_to_allocate, 1 ); @@ -1655,6 +1669,7 @@ static ivas_error ivas_masa_dec_config_fx( Word32 ivas_total_brate; Word32 ism_total_brate; error = IVAS_ERR_OK; + move32(); hMasa = st_ivas->hMasa; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; @@ -1666,7 +1681,7 @@ static ivas_error ivas_masa_dec_config_fx( test(); test(); test(); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->nSCE, 0 ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && st_ivas->nSCE > 0 && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { FOR( i = 0; i < st_ivas->nSCE; i++ ) { @@ -1676,20 +1691,21 @@ static ivas_error ivas_masa_dec_config_fx( ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE, st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate ); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hCPE[0]->element_brate, st_ivas->nchan_transport, MC_MODE_NONE ); } ELSE { - ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( st_ivas->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ); + ivas_masa_set_coding_config_fx( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) ); } test(); test(); - IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_512k ) ) + IF( ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_512k ) ) { hMasa->config.mergeRatiosOverSubframes = 0; + move16(); /* initialize spherical grid */ IF( hMasa->data.sph_grid16 == NULL ) @@ -1709,12 +1725,13 @@ static ivas_error ivas_masa_dec_config_fx( move16(); /* TODO: use fixed version of this function call */ - IF( ( error = ivas_qmetadata_allocate_memory( st_ivas->hQMetaData, hMasa->config.numCodingBands, hMasa->config.numberOfDirections, hMasa->config.useCoherence ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_allocate_memory( st_ivas->hQMetaData, hMasa->config.numCodingBands, hMasa->config.numberOfDirections, hMasa->config.useCoherence ) ), IVAS_ERR_OK ) ) { return error; } st_ivas->hQMetaData->numTwoDirBands = st_ivas->hMasa->config.numTwoDirBands; + move16(); st_ivas->hQMetaData->useLowerRes = 0; move16(); @@ -1722,11 +1739,18 @@ static ivas_error ivas_masa_dec_config_fx( { st_ivas->hQMetaData->q_direction[i].cfg.nbands = hMasa->config.numCodingBands; move16(); - st_ivas->hQMetaData->q_direction[i].cfg.nblocks = EQ_16( hMasa->config.joinedSubframes, TRUE ) ? 1 : 4; + IF( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) + { + st_ivas->hQMetaData->q_direction[i].cfg.nblocks = 1; + } + ELSE + { + st_ivas->hQMetaData->q_direction[i].cfg.nblocks = 4; + } move16(); test(); - IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) + IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { st_ivas->hQMetaData->q_direction[i].cfg.mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); } @@ -1815,16 +1839,16 @@ void ivas_masa_prerender_fx( test(); test(); - IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->nchan_transport, 2 ) && EQ_16( nchan_remapped, 1 ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->nchan_transport, 2 ) && EQ_16( nchan_remapped, 1 ) ) { - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { Copy32( output_fx[0], output_fx[1], output_frame ); /* Copy mono signal to stereo output channels */ } ELSE { test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_DISABLE ) ) { v_multc_fixed( output_fx[0], SQRT2_FIXED, output_fx[0], output_frame ); /* q + 30 - 31 = q - 1*/ /* Gain transport signal when transmitting mono with cpe in order to match loudness */ *q_shift = -1; /* Q has decreased by 1. */ @@ -1955,12 +1979,14 @@ static void replicate_subframes_fx( IF( hQMetaData->q_direction[dir].coherence_band_data != NULL ) { hQMetaData->q_direction[dir].coherence_band_data[band].spread_coherence[sf] = hQMetaData->q_direction[dir].coherence_band_data[band].spread_coherence[0]; + move16(); } } IF( hQMetaData->surcoh_band_data != NULL ) { hQMetaData->surcoh_band_data[band].surround_coherence[sf] = hQMetaData->surcoh_band_data[band].surround_coherence[0]; + move16(); } } } @@ -2058,10 +2084,12 @@ static void restore_lowbitrate_masa_fx( IF( hQMetaData->q_direction[0].coherence_band_data != NULL ) { hQMetaData->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hQMetaData->q_direction[0].coherence_band_data[band].spread_coherence[0]; + move16(); } IF( hQMetaData->surcoh_band_data != NULL ) { hQMetaData->surcoh_band_data[band].surround_coherence[sf] = hQMetaData->surcoh_band_data[band].surround_coherence[0]; + move16(); } } } @@ -2088,10 +2116,12 @@ static void restore_lowbitrate_masa_fx( IF( hQMetaData->q_direction[0].coherence_band_data != NULL ) { hQMetaData->q_direction[0].coherence_band_data[band].spread_coherence[sf] = hQMetaData->q_direction[0].coherence_band_data[0].spread_coherence[sf]; + move16(); } IF( hQMetaData->surcoh_band_data != NULL ) { hQMetaData->surcoh_band_data[band].surround_coherence[sf] = hQMetaData->surcoh_band_data[0].surround_coherence[sf]; + move16(); } } } @@ -2277,7 +2307,7 @@ static ivas_error init_lfe_synth_data_fx( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_HOA3 ) || - ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) ) + ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && ( st_ivas->hOutSetup.num_lfe > 0 ) ) ) ) { Word16 bufferSize; Word16 i; @@ -2955,16 +2985,16 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); test(); test(); - IF( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend == NULL ) || - ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin == NULL ) ) + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend == NULL ) || + ( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin == NULL ) ) { /* init a new DirAC dec */ - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } } - ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) || EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DISABLE ) || EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { IF( st_ivas->hDirAC != NULL ) { @@ -3019,9 +3049,9 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); test(); test(); - IF( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } @@ -3040,7 +3070,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( { tmp = CPE_CHANNELS; move16(); - IF( GT_16( st_ivas->nCPE, 1 ) ) + if ( GT_16( st_ivas->nCPE, 1 ) ) { st_ivas->nCPE = 1; move16(); @@ -3075,9 +3105,9 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); test(); test(); - IF( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) ) + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } @@ -3093,9 +3123,9 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); test(); test(); - IF( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) ) + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && st_ivas->hDirACRend != NULL ) || ( ( EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) && st_ivas->hDiracDecBin != NULL ) ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } @@ -3110,14 +3140,14 @@ ivas_error ivas_masa_dec_reconfigure_fx( } test(); - IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->last_ivas_format, MASA_FORMAT ) ) /* note: switching within OMASA is handled in ivas_omasa_dec_config() */ + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && EQ_32( st_ivas->last_ivas_format, MASA_FORMAT ) ) /* note: switching within OMASA is handled in ivas_omasa_dec_config() */ { /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ IF( st_ivas->hDiracDecBin != NULL ) { - IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -3140,7 +3170,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( floatToFixed_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q, 16 ); } #endif - if ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, st_ivas->nchan_transport, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -3158,7 +3188,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); test(); test(); - IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->nSCE, 0 ) && ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_32( st_ivas->nSCE, 0 ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { FOR( n = 0; n < st_ivas->nSCE; n++ ) { @@ -3168,7 +3198,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( ivas_masa_set_elements_fx( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, st_ivas->hQMetaData, &tmp, &tmp, &tmp, st_ivas->ivas_format, st_ivas->ism_mode, ism_total_brate ); - IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { st_ivas->nchan_ism = 0; move16(); @@ -3183,6 +3213,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( Word16 n_samples_granularity; n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + move16(); buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); tc_nchan_transport = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); @@ -3195,7 +3226,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { tc_nchan_to_allocate = add( shl( BINAURAL_CHANNELS, 1 ), 2 ); } @@ -3206,29 +3237,29 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); test(); test(); - IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ IF( GT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { IF( LT_16( n_samples_granularity, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } } } } - ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) + ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_32( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { /* addtl channel for CNG */ tc_nchan_to_allocate = add( tc_nchan_to_allocate, 1 ); @@ -3238,7 +3269,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); IF( NE_16( tc_nchan_transport, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( buffer_mode_new, st_ivas->hTcBuffer->tc_buffer_mode ) ) { - IF( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) + if ( NE_32( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ), IVAS_ERR_OK ) ) { return error; } @@ -3256,7 +3287,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); test(); - IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); FOR( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ ) @@ -3325,7 +3356,11 @@ void ivas_spar_param_to_masa_param_mapping_fx( { FOR( Word16 ind2 = 0; ind2 < 4; ind2++ ) { - common_q = common_q < q_cldfb[ind][ind2] ? common_q : q_cldfb[ind][ind2]; + if ( GT_16( common_q, q_cldfb[ind][ind2] ) ) + { + common_q = q_cldfb[ind][ind2]; + move16(); + } } } /* Set values */ @@ -3354,7 +3389,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( slot_idx_start = hSpar->slots_rendered; move16(); slot_fac_fx = BASOP_Util_Divide3232_Scale( 1, hSpar->subframe_nbslots[subframe], &q_slot_fac ); - IF( LT_16( q_slot_fac, 0 ) ) + IF( q_slot_fac < 0 ) { slot_fac_fx = shr( slot_fac_fx, -1 * q_slot_fac ); } @@ -3450,7 +3485,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( max_common_val = GT_64( transportSignalEnergies_max, transportSignalCrossCorrelation_max ) ? transportSignalEnergies_max : transportSignalCrossCorrelation_max; - IF( NE_64( max_common_val, 0 ) ) + IF( max_common_val != 0 ) { headroom_left_max_common = W_norm( max_common_val ); IF( GT_16( headroom_left_max_common, 32 ) ) @@ -3577,7 +3612,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( q_I_res = sub( 31, shl( q_inCovarianceMtx, 1 ) ); } I_fx = Sqrt32( (Word32) I_res, &q_I_res ); - IF( LT_16( q_I_res, 0 ) ) + IF( q_I_res < 0 ) { I_fx = L_shr( I_fx, -1 * q_I_res ); q_I_res = 0; @@ -3601,7 +3636,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( ele_q = sub( 31, shl( q_inCovarianceMtx, 1 ) ); } I_ele = Sqrt32( (Word32) I_ele, &ele_q ); - IF( LT_16( ele_q, 0 ) ) + IF( ele_q < 0 ) { I_ele = W_shr( I_ele, -1 * ele_q ); ele_q = 0; @@ -3622,7 +3657,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( ratio_fx = L_max( 0, L_min( ratio_fx, ONE_IN_Q30 ) ); azi_val = (Word64) azi_fx * ONE_BY_PI_OVER_180_Q25; - IF( LT_64( azi_val, 0 ) ) + IF( azi_val < 0 ) { azi_val = W_shr( -1 * azi_val, 13 + 25 ); azi_val = -1 * azi_val; @@ -3632,7 +3667,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( azi_val = W_shr( azi_val, 13 + 25 ); } ele_val = (Word64) ele_fx * ONE_BY_PI_OVER_180_Q25; - IF( LT_64( ele_val, 0 ) ) + IF( ele_val < 0 ) { ele_val = W_shr( -1 * ele_val, 13 + 25 ); ele_val = -1 * ele_val; @@ -3682,7 +3717,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( } diffuseGainSum_fx = L_add_sat( L_add_sat( diffuseGainY_fx, diffuseGainX_fx ), diffuseGainZ_fx ); - IF( EQ_32( diffuseGainSum_fx, 0 ) ) + IF( diffuseGainSum_fx == 0 ) { hDiffuseDist->diffuseRatioX_fx[bin] = 715827904; move32(); @@ -3694,12 +3729,13 @@ void ivas_spar_param_to_masa_param_mapping_fx( ELSE { Word16 temp_q = 0; + move16(); Word16 intermediate_results; intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainX_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); // saturating value to less than 1 - IF( LE_16( temp_q, 0 ) ) + IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, -1 * temp_q ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); } ELSE { @@ -3710,9 +3746,9 @@ void ivas_spar_param_to_masa_param_mapping_fx( intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainY_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); // saturating value to less than 1 - IF( LE_16( temp_q, 0 ) ) + IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, -1 * temp_q ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); } ELSE { @@ -3723,9 +3759,9 @@ void ivas_spar_param_to_masa_param_mapping_fx( intermediate_results = BASOP_Util_Divide3232_Scale( diffuseGainZ_fx, diffuseGainSum_fx + EPSILON_FX_SMALL, &temp_q ); // saturating value to less than 1 - IF( LE_16( temp_q, 0 ) ) + IF( temp_q <= 0 ) { - intermediate_results = shr( intermediate_results, -1 * temp_q ); + intermediate_results = shr( intermediate_results, negate( temp_q ) ); } ELSE { @@ -4193,8 +4229,11 @@ static void create_masa_ext_out_meta_fx( MASA_DECODER_EXT_OUT_META *extOutMeta; numDirections = hMasa->config.numberOfDirections; + move16(); numCodingBands = hMasa->config.numCodingBands; + move16(); bandMap = hMasa->data.band_mapping; + move16(); extOutMeta = hMasa->data.extOutMeta; descMeta = &hMasa->data.extOutMeta->descriptiveMeta; @@ -4202,6 +4241,7 @@ static void create_masa_ext_out_meta_fx( FOR( i = 0; i < 8; i++ ) { descMeta->formatDescriptor[i] = ivasmasaFormatDescriptor[i]; + move16(); } descMeta->numberOfDirections = numDirections - 1; descMeta->numberOfChannels = (UWord8) ( sub( nchan_transport, 1 ) ); @@ -4212,6 +4252,14 @@ static void create_masa_ext_out_meta_fx( descMeta->channelDistance = 0x0u; descMeta->channelLayout = 0x0u; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + /* Construct spatial metadata from qmetadata */ FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { @@ -4233,7 +4281,9 @@ static void create_masa_ext_out_meta_fx( FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) { UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); + move16(); extOutMeta->directToTotalRatio[dir][sf][b_new] = tmp; + move16(); } } @@ -4245,6 +4295,7 @@ static void create_masa_ext_out_meta_fx( FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) { extOutMeta->spreadCoherence[dir][sf][b_new] = hQMetaData->q_direction[dir].coherence_band_data[b_old].spread_coherence[sf]; + move16(); } } } @@ -4253,6 +4304,7 @@ static void create_masa_ext_out_meta_fx( FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { extOutMeta->spreadCoherence[dir][sf][i] = 0; + move16(); } } } @@ -4269,11 +4321,13 @@ static void create_masa_ext_out_meta_fx( FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { extOutMeta->directToTotalRatio[1][sf][i] = 0; + move16(); } FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { extOutMeta->spreadCoherence[1][sf][i] = 0; + move16(); } } @@ -4284,10 +4338,13 @@ static void create_masa_ext_out_meta_fx( FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) { extOutMeta->diffuseToTotalRatio[sf][b_new] = UINT8_MAX; + move16(); FOR( dir = 0; dir < numDirections; dir++ ) { UWord8 tmp = (UWord8) L_shr( hQMetaData->q_direction[dir].band_data[b_old].energy_ratio_fx[sf], Q30 - 8 ); + move16(); extOutMeta->diffuseToTotalRatio[sf][b_new] -= tmp; + move16(); } } } @@ -4300,6 +4357,7 @@ static void create_masa_ext_out_meta_fx( FOR( b_new = bandMap[b_old]; b_new < bandMap[b_old + 1]; b_new++ ) { extOutMeta->surroundCoherence[sf][b_new] = hQMetaData->surcoh_band_data[b_old].surround_coherence[sf]; + move16(); } } } @@ -4308,6 +4366,7 @@ static void create_masa_ext_out_meta_fx( FOR( i = 0; i < MASA_FREQUENCY_BANDS; i++ ) { extOutMeta->surroundCoherence[sf][i] = 0; + move16(); } } } @@ -4393,7 +4452,7 @@ static void decode_index_slice_fx( { j = 0; move16(); - WHILE( GE_16( index, 0 ) ) + WHILE( index >= 0 ) { IF( valid_ratio_index_fx( j, K, nchan_ism - 1 ) ) { @@ -4404,14 +4463,14 @@ static void decode_index_slice_fx( j = sub( j, 1 ); base[0] = 1; move16(); - FOR( i = 1; i < sub( nchan_ism, 1 ); i++ ) + FOR( i = 1; i < nchan_ism - 1; i++ ) { base[i] = i_mult( base[i - 1], 10 ); move16(); } sum = 0; move16(); - FOR( i = sub( nchan_ism, 2 ); i >= 0; i-- ) + FOR( i = nchan_ism - 2; i >= 0; i-- ) { IF( EQ_16( j, 0 ) ) { @@ -4765,7 +4824,7 @@ static void read_ism_ratio_index_fx( ELSE { - IF( EQ_16( sf, 0 ) ) + IF( sf == 0 ) { bits_index = bits_index_ism_ratio_fx( nchan_ism ); @@ -4787,7 +4846,8 @@ static void read_ism_ratio_index_fx( test(); IF( GT_16( idx_sep_obj, -1 ) && EQ_16( ratio_ism_idx[b][idx_sep_obj_local], 0 ) ) { - ( *num_zeros )++; + *num_zeros = add( *num_zeros, 1 ); + move16(); } } ELSE @@ -4808,9 +4868,10 @@ static void read_ism_ratio_index_fx( } decode_index_slice_fx( index, ratio_ism_idx[b_signif], nchan_ism, no_levels_ratio_ism ); test(); - IF( GT_16( idx_sep_obj, -1 ) && EQ_16( ratio_ism_idx[b_signif][idx_sep_obj_local], 0 ) ) + IF( GT_16( idx_sep_obj, -1 ) && ratio_ism_idx[b_signif][idx_sep_obj_local] == 0 ) { - ( *num_zeros )++; + *num_zeros = add( *num_zeros, 1 ); + move16(); } Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); FOR( b = b_signif + 1; b < numCodingBands; b++ ) @@ -4834,14 +4895,15 @@ static void read_ism_ratio_index_fx( } ratio_ism_idx[b][i] = add( ratio_ism_idx[b][i], ratio_ism_idx_ref[i] ); move16(); - ratio_ism_idx[b][nchan_ism - 1] = sub( ratio_ism_idx[b][nchan_ism - 1], ratio_ism_idx[b][i] ); + ratio_ism_idx[b][sub( nchan_ism, 1 )] = sub( ratio_ism_idx[b][sub( nchan_ism, 1 )], ratio_ism_idx[b][i] ); move16(); } Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); test(); IF( GT_16( idx_sep_obj, -1 ) && EQ_16( ratio_ism_idx[b][idx_sep_obj_local], 0 ) ) { - ( *num_zeros )++; + *num_zeros = add( *num_zeros, 1 ); + move16(); } } ELSE @@ -4885,7 +4947,7 @@ static void read_ism_ratio_index_fx( { IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) { - IF( EQ_16( idx_sep_obj_local, 0 ) ) + IF( idx_sep_obj_local == 0 ) { ratio_ism_idx[b][0] = 0; move16(); @@ -4915,7 +4977,7 @@ static void read_ism_ratio_index_fx( FOR( i = 0; i < nchan_ism - 1 - shift_one; i++ ) { buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, GR_order ); - IF( EQ_16( buf % 2, 0 ) ) + IF( ( buf % 2 ) == 0 ) { ratio_ism_idx[b][i] = negate( shr( buf, 1 ) ); move16(); @@ -4947,7 +5009,7 @@ static void read_ism_ratio_index_fx( { IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) { - ratio_ism_idx[b][nchan_ism - 1] = no_levels_ratio_ism; + ratio_ism_idx[b][sub( nchan_ism, 1 )] = no_levels_ratio_ism; move16(); FOR( i = 0; i < nchan_ism - 1; i++ ) { @@ -4955,7 +5017,7 @@ static void read_ism_ratio_index_fx( move16(); test(); - IF( NE_16( shift_one, 0 ) && EQ_16( i, idx_sep_obj_local ) ) + IF( ( shift_one != 0 ) && EQ_16( i, idx_sep_obj_local ) ) { ratio_ism_idx[b][i] = 0; move16(); @@ -4983,7 +5045,7 @@ static void read_ism_ratio_index_fx( move16(); test(); - IF( NE_16( shift_one, 0 ) && EQ_16( i, idx_sep_obj_local ) ) + IF( ( shift_one != 0 ) && EQ_16( i, idx_sep_obj_local ) ) { ratio_ism_idx[b_signif][i] = 0; move16(); @@ -5421,7 +5483,7 @@ static Word16 ivas_decode_masaism_metadata_fx( test(); test(); // if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) - IF( ( GT_32( azimuth, 0 ) && GT_32( hMasaIsmData->q_azimuth_old_fx[obj], 0 ) ) || ( LT_32( azimuth, 0 ) && LT_32( hMasaIsmData->q_azimuth_old_fx[obj], 0 ) ) ) + IF( ( ( azimuth > 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] > 0 ) ) || ( ( azimuth < 0 ) && ( hMasaIsmData->q_azimuth_old_fx[obj] < 0 ) ) ) { Word16 tmp_e; delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); @@ -5540,7 +5602,7 @@ static Word16 rint_fx( /* returns in Q0 */ { res = add( res, 1 ); } - IF( LT_32( num, 0 ) ) + if ( num < 0 ) { res = negate( res ); } diff --git a/lib_dec/ivas_mcmasa_dec.c b/lib_dec/ivas_mcmasa_dec.c index 1ccf304df..b0d4f5c71 100644 --- a/lib_dec/ivas_mcmasa_dec.c +++ b/lib_dec/ivas_mcmasa_dec.c @@ -54,6 +54,7 @@ ivas_error ivas_mcmasa_dec_reconfig( Word32 ivas_total_brate; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); /* close the old MASA instance */ ivas_masa_dec_close_fx( &( st_ivas->hMasa ) ); @@ -69,25 +70,26 @@ ivas_error ivas_mcmasa_dec_reconfig( ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); ivas_mcmasa_set_separate_channel_mode_fx( &( st_ivas->hIntSetup.separateChannelEnabled ), &( st_ivas->hIntSetup.separateChannelIndex ), ivas_total_brate ); - IF( ( error = ivas_masa_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_masa_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); + test(); IF( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) && NE_16( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) { IF( st_ivas->hDirAC == NULL ) { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } } ELSE { - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec.c index b703aaaef..7bd948ad6 100644 --- a/lib_dec/ivas_mct_core_dec.c +++ b/lib_dec/ivas_mct_core_dec.c @@ -167,11 +167,13 @@ void ivas_mct_side_bits_fx( { Word16 ch, cpe_id, nChannels, i, k, nSubframes; Word16 nf_side_bits, availableBits, next_bit_pos, nf_bits; - Word16 chBitRatios[MCT_MAX_CHANNELS]; + Word16 chBitRatios[MCT_MAX_CHANNELS], tmp, scale; Decoder_State *st, *sts[MCT_MAX_CHANNELS]; nf_side_bits = 0; nChannels = hMCT->nchan_out_woLFE; + move16(); + move16(); /*initializations */ FOR( ( cpe_id = 0, i = 0 ); cpe_id < nCPE; cpe_id++ ) @@ -185,12 +187,13 @@ void ivas_mct_side_bits_fx( } /*first read IFG bits */ + test(); IF( !bfi && st0->igf ) { FOR( ch = 0; ch < nChannels; ch++ ) { st = sts[ch]; - IF( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + if ( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { continue; } @@ -200,7 +203,7 @@ void ivas_mct_side_bits_fx( } /*read MCT data and calculate frame bits per channel */ - FOR( ch = 0; ch < (Word16) ( hMCT->nchan_out_woLFE * 0.5 ); ch++ ) + FOR( ch = 0; ch < shr( hMCT->nchan_out_woLFE, 1 ); ch++ ) { initMdctStereoDecData_fx( hMCT->hBlockData[ch]->hStereoMdct, st0->igf, st0->hIGFDec->igfData.igfInfo.grid, hCPE[0]->element_brate, st0->bwidth ); } @@ -208,6 +211,7 @@ void ivas_mct_side_bits_fx( IF( !bfi ) { availableBits = 0; + move16(); ivas_mct_dec_mct_fx( hMCT, sts, nChannels ); @@ -216,37 +220,59 @@ void ivas_mct_side_bits_fx( { st = sts[ch]; - IF( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( EQ_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { chBitRatios[ch] = 0; st->bits_frame_channel = 0; + move16(); + move16(); continue; } chBitRatios[ch] = get_next_indice_fx( sts[0], NBBITS_MCT_RATIO ); - - nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1; + IF( EQ_16( st->core, TCX_10_CORE ) ) + { + nSubframes = NB_DIV; + move16(); + } + ELSE + { + nSubframes = 1; + move16(); + } FOR( k = 0; k < nSubframes; k++ ) { - nf_side_bits += ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + nf_side_bits = add( nf_side_bits, ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ) ); } } - availableBits = (Word16) ( ( ivas_total_brate / FRAMES_PER_SEC ) - sts[0]->next_bit_pos - nf_side_bits ); - availableBits -= nb_bits_metadata; + tmp = BASOP_Util_Divide3232_Scale( ivas_total_brate, FRAMES_PER_SEC, &scale ); + tmp = shr( tmp, sub( 15, scale ) ); + + availableBits = (Word16) ( sub( sub( tmp, sts[0]->next_bit_pos ), nf_side_bits ) ); + availableBits = sub( availableBits, nb_bits_metadata ); splitAvailableBitsMCT( (void **) sts, availableBits, chBitRatios, DEC, nChannels ); next_bit_pos = sts[0]->next_bit_pos; + move16(); FOR( ch = 1; ch < nChannels; ch++ ) { - nf_bits = ( sts[ch - 1]->core == TCX_20_CORE ? 1 : NB_DIV ) * ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + nf_bits = NB_DIV; + move16(); + if ( EQ_16( sts[ch - 1]->core, TCX_20_CORE ) ) + { + nf_bits = 1; + move16(); + } + nf_bits = imult1616( nf_bits, ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ) ); - IF( chBitRatios[ch - 1] == 0 ) /* indicates LFE with no content */ + if ( chBitRatios[ch - 1] == 0 ) /* indicates LFE with no content */ { nf_bits = 0; + move16(); } - next_bit_pos += sts[ch - 1]->bits_frame_channel + nf_bits; + next_bit_pos = add( next_bit_pos, add( sts[ch - 1]->bits_frame_channel, nf_bits ) ); sts[ch]->bit_stream = bitstream + next_bit_pos; } } @@ -278,7 +304,7 @@ void ivas_mct_core_dec( Word16 tcx_offset; Word16 tcx_offsetFB; Word16 left_rect; - Word16 L_spec; + Word16 L_spec, scale, tmp1, tmp2; #ifdef DEBUG_MCT float nrg[MCT_MAX_CHANNELS]; #endif @@ -291,37 +317,43 @@ void ivas_mct_core_dec( *--------------------------------------------------------------------------------*/ nChannels = hMCT->nchan_out_woLFE; + move16(); /*initializations */ i = 0; + move16(); FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { sts[i] = hCPE[cpe_id]->hCoreCoder[ch]; - i++; + i = add( i, 1 ); } } i = 0; + move16(); FOR( ch = 0; ch < nChannels; ch++ ) { - IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + IF( EQ_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { continue; } - i++; + i = add( i, 1 ); } bfi = sts[0]->bfi; + move16(); FOR( ch = 0; ch < nChannels; ch++ ) { /* Initialization or re-configuration of Stereo TCX */ sts[ch]->enablePlcWaveadjust = 0; + move16(); x_fx[ch][0] = signal_out_fx[ch]; x_fx[ch][1] = signal_out_fx[ch] + ( L_FRAME48k / 2 ); q_x[ch] = Q12; + move16(); } IF( sts[0]->igf ) @@ -332,33 +364,51 @@ void ivas_mct_core_dec( { st = sts[ch]; - IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) /*indicates LFE */ + if ( EQ_32( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) /*indicates LFE */ { continue; } - IF( bfi && st->core == ACELP_CORE ) /*no igf processing needed*/ + test(); + if ( bfi && EQ_16( st->core, ACELP_CORE ) ) /*no igf processing needed*/ { continue; } - nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1; + + IF( EQ_16( st->core, TCX_10_CORE ) ) + { + nSubframes = NB_DIV; + } + ELSE + { + nSubframes = 1; + } + move16(); FOR( k = 0; k < nSubframes; k++ ) { - L_spec = st->hTcxCfg->tcx_coded_lines / nSubframes; + L_spec = BASOP_Util_Divide1616_Scale( st->hTcxCfg->tcx_coded_lines, nSubframes, &scale ); + L_spec = shr( L_spec, sub( 15, scale ) ); - init_tcx_info_fx( st, st->L_frame / nSubframes, st->hTcxDec->L_frameTCX / nSubframes, k, bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); + tmp1 = BASOP_Util_Divide1616_Scale( st->L_frame, nSubframes, &scale ); + tmp1 = shr( tmp1, sub( 15, scale ) ); + tmp2 = BASOP_Util_Divide1616_Scale( st->hTcxDec->L_frameTCX, nSubframes, &scale ); + tmp2 = shr( tmp1, sub( 15, scale ) ); + init_tcx_info_fx( st, tmp1, tmp2, k, bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); Word16 x_e, x_len; /* mono or dual mono IGF decoding */ - x_e = 31 - q_x[ch]; + x_e = sub( 31, q_x[ch] ); decoder_tcx_IGF_mono_fx( st, x_fx[ch][k], &x_e, &x_len, L_frame, left_rect, bfi, k ); - q_x[ch] = 31 - x_e; - for ( i = 0; i < x_len; i++ ) + q_x[ch] = sub( 31, x_e ); + move16(); + FOR( i = 0; i < x_len; i++ ) { - x_fx[ch][k][i] = L_shr( x_fx[ch][k][i], q_x[ch] - Q12 ); + x_fx[ch][k][i] = L_shr( x_fx[ch][k][i], sub( q_x[ch], Q12 ) ); + move32(); } q_x[ch] = Q12; + move16(); } } } @@ -377,12 +427,15 @@ void ivas_mct_core_dec( apply_MCT_dec_fx( hMCT, sts, x_fx, q_x ); FOR( ch = 0; ch < nChannels; ch++ ) { - for ( i = 0; i < L_FRAME48k / 2; i++ ) + FOR( i = 0; i < L_FRAME48k / 2; i++ ) { - x_fx[ch][0][i] = L_shr( x_fx[ch][0][i], q_x[ch] - Q12 ); - x_fx[ch][1][i] = L_shr( x_fx[ch][1][i], q_x[ch] - Q12 ); + x_fx[ch][0][i] = L_shr( x_fx[ch][0][i], sub( q_x[ch], Q12 ) ); + x_fx[ch][1][i] = L_shr( x_fx[ch][1][i], sub( q_x[ch], Q12 ) ); + move32(); + move32(); } q_x[ch] = Q12; + move16(); } } -- GitLab From 63f9bc6dc1d547b5fc9798a7276d17450deca8f2 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 21 Jun 2024 14:06:16 +0530 Subject: [PATCH 56/63] Clang formatting changes --- lib_dec/er_dec_acelp_fx.c | 4 ++-- lib_dec/ivas_lfe_dec_fx.c | 2 +- lib_dec/ivas_masa_dec.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/er_dec_acelp_fx.c b/lib_dec/er_dec_acelp_fx.c index debb8aad3..ca23584a1 100644 --- a/lib_dec/er_dec_acelp_fx.c +++ b/lib_dec/er_dec_acelp_fx.c @@ -1067,7 +1067,7 @@ void con_acelp_fx( /* save last half frame if next frame is TCX */ bufferCopyFx( syn + st->L_frame, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ), 0 /*Qf_syn*/, -1 /*Qf_old_xnq*/, 0, 0 /*Q_old_xnq*/ ); - Copy( syn + sub(st->L_frame, M + 1), st->syn, 1 + M ); + Copy( syn + sub( st->L_frame, M + 1 ), st->syn, 1 + M ); /* update old_Aq */ Copy( p_A - ( M + 1 ), st->old_Aq_12_8_fx, M + 1 ); @@ -1097,7 +1097,7 @@ void con_acelp_fx( } FOR( ; i < W1; i++ ) { - hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub(W2, add(1, sub(i, W2 )))].v.im, w[sub(W2, add(1, sub( i, W2 )))].v.im ), hHQ_core->old_out_LB_fx[add(i, n)] ) ); + hHQ_core->old_out_LB_fx[i + n] = round_fx( Mpy_32_16_1( L_mult( w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im, w[sub( W2, add( 1, sub( i, W2 ) ) )].v.im ), hHQ_core->old_out_LB_fx[add( i, n )] ) ); move16(); } set16_fx( &hHQ_core->old_out_LB_fx[add( W1, n )], 0, n ); diff --git a/lib_dec/ivas_lfe_dec_fx.c b/lib_dec/ivas_lfe_dec_fx.c index 4d5dd9591..32519adc2 100644 --- a/lib_dec/ivas_lfe_dec_fx.c +++ b/lib_dec/ivas_lfe_dec_fx.c @@ -240,7 +240,7 @@ static Word16 ivas_lfe_dec_dequant_fx( move16(); FOR( i = 0; i < 4; i++ ) { - abs_values[add( iii * 4 , i )] = get_next_indice_fx( st0, base2_bit_size ); + abs_values[add( iii * 4, i )] = get_next_indice_fx( st0, base2_bit_size ); move16(); } } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 8b187d57a..a6f797e0a 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -914,7 +914,7 @@ ivas_error ivas_masa_decode_fx( { *nb_bits_read = add( *nb_bits_read, ivas_decode_masaism_metadata_fx( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, 0, MAX_PARAM_SPATIAL_SUBFRAMES ) ); - move16(); + move16(); } } } -- GitLab From e0eaee409f97c7cf26fb6039ce252ae3c0d19ce4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 21 Jun 2024 15:35:19 +0530 Subject: [PATCH 57/63] Corrected the index in ivas_lfe_dec_dequant_fx --- lib_dec/ivas_lfe_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_lfe_dec_fx.c b/lib_dec/ivas_lfe_dec_fx.c index 32519adc2..f615bbd1e 100644 --- a/lib_dec/ivas_lfe_dec_fx.c +++ b/lib_dec/ivas_lfe_dec_fx.c @@ -280,7 +280,7 @@ static Word16 ivas_lfe_dec_dequant_fx( { pOut_buf[2 * i] = Mpy_32_16_1( two_pow_shift_by_4, values[4 * i] ); // Q30 + Q9 >> 15 = Q24 move32(); - pOut_buf[add( 2 * i, 1 )] = Mpy_32_16_1( two_pow_shift_by_4, values[add( 2 * i, 1 )] ); // Q30 + Q9 >> 15 = Q24 + pOut_buf[add( 2 * i, 1 )] = Mpy_32_16_1( two_pow_shift_by_4, values[add( 4 * i, 1 )] ); // Q30 + Q9 >> 15 = Q24 move32(); pOut_buf[add( 2 * i, *num_dct_pass_bins )] = Mpy_32_16_1( two_pow_shift_by_4, values[add( 4 * i, 2 )] ); // Q30 + Q9 >> 15 = Q24 -- GitLab From 6e9aefb66de9afdf56dba160a3058f75b7c8e188 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 21 Jun 2024 16:03:05 +0530 Subject: [PATCH 58/63] Integration and conversion of ism_quant_meta function --- lib_com/ivas_cnst.h | 8 + lib_com/ivas_ism_com.c | 56 +++ lib_com/ivas_prot_fx.h | 9 + lib_com/ivas_rom_com.c | 13 + lib_com/ivas_rom_com.h | 5 + lib_com/ivas_rom_com_fx.c | 18 +- lib_enc/ivas_ism_metadata_enc.c | 839 ++++++++++++++++++++++++++++++-- lib_enc/ivas_ism_param_enc.c | 54 ++ 8 files changed, 962 insertions(+), 40 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 06e5e34b8..1b6940be5 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -343,14 +343,22 @@ typedef enum #define ISM_AZIMUTH_MAX_FX 754974720 #define ISM_AZIMUTH_LOW_BORDER -140.0f #define ISM_AZIMUTH_HIGH_BORDER 135.0f +#define ISM_AZIMUTH_LOW_BORDER_FX -587202560 +#define ISM_AZIMUTH_HIGH_BORDER_FX 566231040 #define ISM_ELEVATION_NBITS 6 #define ISM_ELEVATION_MIN -90.0f #define ISM_ELEVATION_MAX 90.0f +#define ISM_ELEVATION_MIN_FX -377487360 +#define ISM_ELEVATION_MAX_FX 377487360 #define ISM_ELEVATION_LOW_BORDER -70.0f #define ISM_ELEVATION_HIGH_BORDER 65.0f +#define ISM_ELEVATION_LOW_BORDER_FX -293601280 +#define ISM_ELEVATION_HIGH_BORDER_FX 272629760 #define ISM_Q_STEP 2.5f +#define ISM_Q_STEP_FX 10485760 #define ISM_Q_STEP_BORDER 5.0f +#define ISM_Q_STEP_BORDER_FX 20971520 #define ISM_RADIUS_NBITS 6 #define ISM_RADIUS_MIN 0.0f diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index a27621adb..6f0b03286 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -838,6 +838,62 @@ void ivas_ism_reset_metadata_API( *-------------------------------------------------------------------*/ /*! r: index of the winning codeword */ +#ifdef IVAS_FLOAT_FIXED +Word16 ism_quant_meta_fx( + const Word32 val, /* i : scalar value to quantize Q22 */ + Word32 *valQ, /* o : quantized value Q22 */ + const Word32 borders_fx[], /* i : level borders Q22 */ + const Word32 q_step_fx, /* i : quantization step Q22 */ + const Word32 q_step_border_fx, /* i : quantization step at the border Q22 */ + const Word16 cbsize /* i : codebook size */ +) +{ + Word16 idx, idx_start; + Word32 qlow_fx, step_fx; + Word16 tmp, tmp_e; + + IF( val <= borders_fx[1] ) + { + qlow_fx = borders_fx[0]; + move32(); + idx_start = 0; + move32(); + step_fx = q_step_border_fx; + move32(); + } + ELSE IF( val <= borders_fx[2] ) + { + qlow_fx = borders_fx[1]; + move32(); + tmp = BASOP_Util_Divide3232_Scale( L_sub( borders_fx[1], borders_fx[0] ), q_step_border_fx, &tmp_e ); + idx_start = shr( tmp, sub( 15, tmp_e ) ); + step_fx = q_step_fx; + move32(); + } + ELSE + { + qlow_fx = borders_fx[2]; + move32(); + tmp = BASOP_Util_Divide3232_Scale( L_add( L_sub( borders_fx[3], borders_fx[2] ), L_sub( q_step_border_fx, ONE_IN_Q22 ) ), q_step_border_fx, &tmp_e ); + idx_start = sub( cbsize, add( 1, shr( tmp, sub( 15, tmp_e ) ) ) ); + step_fx = q_step_border_fx; + move32(); + } + + + tmp = BASOP_Util_Divide3232_Scale( L_sub( val, qlow_fx ), step_fx, &tmp_e ); + tmp = shl( tmp, sub( Q1, sub( 15, tmp_e ) ) ); + tmp = add( tmp, 1 ); + tmp = shr( tmp, 1 ); + idx = add( idx_start, s_max( 0, s_min( sub( cbsize, 1 ), tmp ) ) ); + + // idx = idx_start + (int16_t) max( 0.f, min( cbsize - 1, ( ( val - qlow_fx ) / step_fx + 0.5f ) ) ); + *valQ = L_add( imult3216( step_fx, sub( idx, idx_start ) ), qlow_fx ); + + return idx; +} +#endif + int16_t ism_quant_meta( const float val, /* i : scalar value to quantize */ float *valQ, /* o : quantized value */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f7c387d2d..8ae9ce456 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2384,4 +2384,13 @@ Word16 calculate_brate_limit_flag_fx( const Word16 ism_imp[], /* i : ISM importance flags */ const Word16 nchan_ism /* i : number of objects */ ); +Word16 ism_quant_meta_fx( + const Word32 val, /* i : scalar value to quantize */ + Word32 *valQ, /* o : quantized value */ + const Word32 borders_fx[], /* i : level borders */ + const Word32 q_step_fx, /* i : quantization step */ + const Word32 q_step_border_fx, /* i : quantization step at the border */ + const Word16 cbsize /* i : codebook size */ +); + #endif diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 70869d12c..c3b7456f3 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -3576,6 +3576,19 @@ const float ism_elevation_borders[4] = ISM_ELEVATION_MIN, ISM_ELEVATION_LOW_BORDER, ISM_ELEVATION_HIGH_BORDER, ISM_ELEVATION_MAX }; +#ifdef IVAS_FLOAT_FIXED +const Word32 ism_azimuth_borders_fx[4] = +{ + ISM_AZIMUTH_MIN_FX, ISM_AZIMUTH_LOW_BORDER_FX, ISM_AZIMUTH_HIGH_BORDER_FX, ISM_AZIMUTH_MAX_FX +}; + +const Word32 ism_elevation_borders_fx[4] = +{ + ISM_ELEVATION_MIN_FX, ISM_ELEVATION_LOW_BORDER_FX, ISM_ELEVATION_HIGH_BORDER_FX, ISM_ELEVATION_MAX_FX +}; + +#endif + /*----------------------------------------------------------------------------------* * Param ISM ROM tables diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index c96f4e884..e90ae83ac 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -406,6 +406,11 @@ extern const Word32 dct12_fx[]; extern const float ism_azimuth_borders[4]; extern const float ism_elevation_borders[4]; +#ifdef IVAS_FLOAT_FIXED +extern const Word32 ism_azimuth_borders_fx[4]; +extern const Word32 ism_elevation_borders_fx[4]; +#endif + /*----------------------------------------------------------------------------------* * Param ISM ROM tables *----------------------------------------------------------------------------------*/ diff --git a/lib_com/ivas_rom_com_fx.c b/lib_com/ivas_rom_com_fx.c index 726c23cb3..0570d4f3c 100644 --- a/lib_com/ivas_rom_com_fx.c +++ b/lib_com/ivas_rom_com_fx.c @@ -288,15 +288,15 @@ const Word16 ivas_divde_255[256] = { 31996, 32125, 32253, 32382, 32510, 32639, 32767 }; -const Word32 ism_azimuth_borders_fx[4] = -{ - -754974720, -587202560, 566231040, 754974720 -}; - -const Word32 ism_elevation_borders_fx[4] = -{ - -377487360, -293601280, 272639760, 377487360 -}; +//const Word32 ism_azimuth_borders_fx[4] = +//{ +// -754974720, -587202560, 566231040, 754974720 +//}; +// +//const Word32 ism_elevation_borders_fx[4] = +//{ +// -377487360, -293601280, 272639760, 377487360 +//}; const Word16 gridEq_Table[NO_THETA16_MAX] = { 430, 423, 422, 422, 422, 422, 421, 421, 420, 420, 419, 418, 417, 417, 416, diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 0b4a5e2e9..8f58798b3 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -36,8 +36,11 @@ #include "options.h" #include "ivas_cnst.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "ivas_rom_com.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #include #include "wmc_auto.h" #ifdef IVAS_FLOAT_FIXED @@ -123,50 +126,673 @@ static void rate_ism_importance( { int16_t ch, ctype; - for ( ch = 0; ch < nchan_transport; ch++ ) - { - ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + for ( ch = 0; ch < nchan_transport; ch++ ) + { + ctype = hSCE[ch]->hCoreCoder[0]->coder_type_raw; + + if ( hSCE[ch]->hCoreCoder[0]->tcxonly ) + { + if ( hSCE[ch]->hCoreCoder[0]->localVAD == 0 ) + { + ctype = INACTIVE; + } + else if ( ctype == UNVOICED ) + { + ctype = GENERIC; + } + } + + if ( ( hIsmMeta[ch]->ism_metadata_flag == 0 || lowrate_metadata_flag[ch] == 1 ) && hSCE[ch]->hCoreCoder[0]->localVAD == 0 ) + { + ism_imp[ch] = ISM_NO_META; + } + else if ( ctype == INACTIVE || ctype == UNVOICED ) + { + ism_imp[ch] = ISM_LOW_IMP; + } + else if ( ctype == VOICED ) + { + ism_imp[ch] = ISM_MEDIUM_IMP; + } + else /* GENERIC */ + { + ism_imp[ch] = ISM_HIGH_IMP; + } + } + + return; +} + + +/*-------------------------------------------------------------------------* + * ivas_ism_metadata_enc() + * + * quantize and encode ISM metadata + *-------------------------------------------------------------------------*/ + +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_ism_metadata_enc( + int32_t *ism_total_brate, /* i/o: ISM total bitrate */ + const int16_t nchan_ism, /* i : number of ISM channels */ + const int16_t nchan_transport, /* i : number of transport channels */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + SCE_ENC_HANDLE hSCE[], /* i/o: SCE encoder handles */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + int16_t nb_bits_metadata[], /* o : number of metadata bits */ + const int16_t vad_flag[], /* i : VAD flag */ + const int16_t ism_mode, /* i : ISM mode */ + const PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i : Param ISM Enc Handle */ + const int16_t ism_extended_metadata_flag, /* i : Extended metadata flag */ + const float lp_noise_CPE, + const int16_t flag_omasa_ener_brate, /* i : less bitrate for objects in OMASA flag */ + int16_t *omasa_stereo_sw_cnt, + const int16_t ini_frame ) +{ + int16_t i, ch, nb_bits_start = 0; + int16_t flag_abs_azimuth[MAX_NUM_OBJECTS]; + int16_t flag_abs_elevation[MAX_NUM_OBJECTS]; + int16_t idx_angle1_abs = 0; + int16_t idx_angle2_abs = 0; + int16_t flag_abs_yaw[MAX_NUM_OBJECTS]; + int16_t flag_abs_pitch[MAX_NUM_OBJECTS]; + int16_t idx_radius_abs = 0, flag_abs_radius[MAX_NUM_OBJECTS]; + float valQ; +#ifdef IVAS_FLOAT_FIXED + Word32 valQ_fx; +#endif + ISM_METADATA_HANDLE hIsmMetaData; + int32_t element_brate[MAX_NUM_OBJECTS], total_brate[MAX_NUM_OBJECTS]; + int16_t ism_metadata_flag_global; + int16_t non_diegetic_flag_global; + int16_t ism_imp[MAX_NUM_OBJECTS]; + int16_t null_metadata_flag[MAX_NUM_OBJECTS]; + int16_t lowrate_metadata_flag[MAX_NUM_OBJECTS]; + int16_t nbands, nblocks; + ivas_error error; + + error = IVAS_ERR_OK; + push_wmops( "ism_meta_enc" ); + + /* initialization */ + ism_metadata_flag_global = 0; + non_diegetic_flag_global = 0; + set_s( nb_bits_metadata, 0, nchan_transport ); + set_s( flag_abs_azimuth, 0, nchan_ism ); + set_s( flag_abs_elevation, 0, nchan_ism ); + set_s( flag_abs_yaw, 0, nchan_ism ); + set_s( flag_abs_pitch, 0, nchan_ism ); + set_s( flag_abs_radius, 0, nchan_ism ); + set_s( null_metadata_flag, 0, nchan_ism ); + set_s( lowrate_metadata_flag, 0, nchan_ism ); + + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + /*----------------------------------------------------------------* + * Rate importance of particular ISM streams in combined format coding + *----------------------------------------------------------------*/ + + ivas_set_ism_importance_interformat( *ism_total_brate, nchan_transport, hIsmMeta, hSCE, lp_noise_CPE, ism_imp ); + } + else + { + /*----------------------------------------------------------------* + * Set Metadata presence / importance flag + *----------------------------------------------------------------*/ + + for ( ch = 0; ch < nchan_ism; ch++ ) + { + if ( ism_mode == ISM_MODE_PARAM ) + { + hIsmMeta[ch]->ism_metadata_flag = 1; + } + else if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) + { + null_metadata_flag[ch] = !hIsmMeta[ch]->ism_metadata_flag; + + if ( hIsmMeta[ch]->ism_metadata_flag == 1 ) + { + if ( ism_mode != ISM_SBA_MODE_DISC ) + { + /* In case of low level noise for low bitrate inactive frames, do not sent metadata */ + hIsmMeta[ch]->ism_metadata_flag = vad_flag[ch] || hSCE[ch]->hCoreCoder[0]->lp_noise > 10 || hSCE[ch]->hCoreCoder[0]->tcxonly; + } + + /* in inactive frames, send MD 1) in ISM_MD_INC_DIFF_CNT_MAX consecutive frames when MD significantly change, 2) at least every ISM_MD_FEC_DIFF frames */ + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + { + if ( ( fabsf( hIsmMeta[ch]->azimuth - hIsmMeta[ch]->last_true_azimuth ) > ISM_MD_FEC_DIFF ) || + ( fabsf( hIsmMeta[ch]->elevation - hIsmMeta[ch]->last_true_elevation ) > ISM_MD_FEC_DIFF ) || ( fabsf( hIsmMeta[ch]->radius - hIsmMeta[ch]->last_true_radius ) > ISM_MD_RAD_FEC_DIFF ) ) + { + + lowrate_metadata_flag[ch] = 1; + + hIsmMeta[ch]->ism_md_inc_diff_cnt = 0; + } + else if ( hIsmMeta[ch]->ism_md_inc_diff_cnt < ISM_MD_INC_DIFF_CNT_MAX ) + { + + lowrate_metadata_flag[ch] = 1; + + if ( hIsmMeta[ch]->ism_md_inc_diff_cnt % 2 == 0 ) + { + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + } + else + { + hIsmMeta[ch]->position_angle.angle2_diff_cnt = ISM_FEC_MAX; + } + } + else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) + { + + lowrate_metadata_flag[ch] = 1; + + hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; + } + } + } + } + } + + /*----------------------------------------------------------------* + * Rate importance of particular ISM streams + *----------------------------------------------------------------*/ + + if ( ism_mode != ISM_SBA_MODE_DISC ) + { + rate_ism_importance( nchan_transport, hIsmMeta, hSCE, lowrate_metadata_flag, ism_imp ); + } + } + + /*----------------------------------------------------------------* + * Write ISM common signaling + *----------------------------------------------------------------*/ + + if ( ism_mode != ISM_MASA_MODE_DISC && ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ && ism_mode != ISM_SBA_MODE_DISC ) + { + /* write number of objects - unary coding */ + for ( ch = 1; ch < nchan_ism; ch++ ) + { + push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); + } + push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); + } + + for ( ch = 0; ch < nchan_ism; ch++ ) + { + ism_metadata_flag_global |= hIsmMeta[ch]->ism_metadata_flag; + ism_metadata_flag_global |= lowrate_metadata_flag[ch]; + non_diegetic_flag_global |= hIsmMeta[ch]->non_diegetic_flag; + } + + /* write extended metadata presence flag */ + if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) && *ism_total_brate >= ISM_EXTENDED_METADATA_BRATE ) + { + push_indice( hBstr, IND_ISM_EXTENDED_FLAG, ism_extended_metadata_flag, ISM_EXTENDED_METADATA_BITS ); + + /* Write global non-diegetic object flag */ + if ( ism_extended_metadata_flag ) + { + push_indice( hBstr, IND_ISM_EXTENDED_NDP_FLAG, non_diegetic_flag_global, ISM_EXTENDED_METADATA_BITS ); + } + } + + /* write ISM metadata flag (one per object) */ + for ( ch = 0; ch < nchan_transport; ch++ ) + { + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + /* flags will be written in ivas_masa_encode() */ + hIsmMeta[ch]->ism_imp = ism_imp[ch]; + hIsmMeta[ch]->ism_md_null_flag = null_metadata_flag[ch]; + hIsmMeta[ch]->ism_md_lowrate_flag = lowrate_metadata_flag[ch]; + } + else + { + if ( null_metadata_flag[ch] ) + { + /* signal NULL metadata frame */ + push_indice( hBstr, IND_ISM_MD_NULL_FLAG, 1, ISM_METADATA_MD_FLAG_BITS ); + + /* write the ISM class to ISM_NO_META and again the true ISM class */ + if ( ism_mode != ISM_SBA_MODE_DISC ) + { + push_indice( hBstr, IND_ISM_METADATA_FLAG, ISM_NO_META, ISM_METADATA_FLAG_BITS ); + push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); + } + else + { + push_indice( hBstr, IND_ISM_METADATA_FLAG, ISM_NO_META, 1 ); + } + } + else if ( ism_mode != ISM_SBA_MODE_DISC ) + { + push_indice( hBstr, IND_ISM_METADATA_FLAG, ism_imp[ch], ISM_METADATA_FLAG_BITS ); + + if ( ism_imp[ch] == ISM_NO_META ) + { + /* signal low-rate ISM_NO_META frame */ + push_indice( hBstr, IND_ISM_MD_NULL_FLAG, 0, ISM_METADATA_MD_FLAG_BITS ); + + /* signal presence of MD in low-rate ISM_NO_META frame */ + push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, lowrate_metadata_flag[ch], ISM_METADATA_INACTIVE_FLAG_BITS ); + } + } + else /*ism_mode == ISM_SBA_MODE_DISC*/ + { + /* all objects are considered active*/ + push_indice( hBstr, IND_ISM_METADATA_FLAG, 1, 1 ); + } + } + } + + + if ( ism_metadata_flag_global ) + { + /*----------------------------------------------------------------* + * Metadata quantization and coding, loop over all objects + *----------------------------------------------------------------*/ + + int16_t total_bits_metadata = 0; + int16_t bits_metadata_ism = 0; + int16_t nb_bits_objcod_written; + + if ( ism_mode == ISM_MODE_PARAM ) + { + nb_bits_start = hBstr->nb_bits_tot; + } + + for ( ch = 0; ch < nchan_ism; ch++ ) + { + hIsmMetaData = hIsmMeta[ch]; + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + { + nb_bits_start = hBstr->nb_bits_tot; + } + + if ( hIsmMeta[ch]->ism_metadata_flag || lowrate_metadata_flag[ch] ) + { + /*----------------------------------------------------------------* + * Quantize and encode azimuth and elevation + *----------------------------------------------------------------*/ + + if ( ism_extended_metadata_flag && non_diegetic_flag_global ) + { + /* Write non-diegetic flag for each object */ + push_indice( hBstr, IND_ISM_NDP_FLAG, hIsmMeta[ch]->non_diegetic_flag, ISM_METADATA_IS_NDP_BITS ); + } + + if ( hIsmMeta[ch]->non_diegetic_flag && ism_extended_metadata_flag ) + { + /* Map azimuth to panning range [-90:90] */ + if ( hIsmMetaData->azimuth > 90.0f ) + { + hIsmMetaData->azimuth = 180.0f - hIsmMetaData->azimuth; + } + + if ( hIsmMetaData->azimuth < -90.0f ) + { + hIsmMetaData->azimuth = -180.0f - hIsmMetaData->azimuth; + } + +#ifdef IVAS_FLOAT_FIXED + /*===============================flt-2-fix======================================*/ + hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); + /*===============================flt-2-fix======================================*/ + idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); + /*===============================fix-2-flt======================================*/ + valQ = fixedToFloat( valQ_fx, Q22 ); + /*===============================fix-2-flt======================================*/ +#else + idx_angle1_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); +#endif + encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, hSCE[0]->hCoreCoder[0]->ini_frame, idx_angle1_abs, 0, &flag_abs_azimuth[ch], NULL ); + } + else + { + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + { +#ifdef IVAS_FLOAT_FIXED + /*===============================flt-2-fix======================================*/ + hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); + hIsmMetaData->elevation_fx = floatToFixed( hIsmMetaData->elevation, Q22 ); + /*===============================flt-2-fix======================================*/ + idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); + idx_angle2_abs = ism_quant_meta_fx( hIsmMetaData->elevation_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); + /*===============================fix-2-flt======================================*/ + valQ = fixedToFloat( valQ_fx, Q22 ); + /*===============================fix-2-flt======================================*/ +#else + idx_angle1_abs = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); + idx_angle2_abs = ism_quant_meta( hIsmMetaData->elevation, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); +#endif + } + else /* ISM_MODE_PARAM */ + { + idx_angle1_abs = hParamIsm->azi_index[ch]; + idx_angle2_abs = hParamIsm->ele_index[ch]; + } + encode_angle_indices( hBstr, &( hIsmMetaData->position_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_azimuth[ch], &flag_abs_elevation[ch] ); + + /*----------------------------------------------------------------* + * Quantize and encode radius, yaw, and pitch + *----------------------------------------------------------------*/ + if ( ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_SBA_MODE_DISC ) && ism_extended_metadata_flag ) + { +#ifdef IVAS_FLOAT_FIXED + /*===============================flt-2-fix======================================*/ + hIsmMetaData->yaw_fx = floatToFixed( hIsmMetaData->yaw, Q22 ); + hIsmMetaData->pitch_fx = floatToFixed( hIsmMetaData->pitch, Q22 ); + /*===============================flt-2-fix======================================*/ + idx_angle1_abs = ism_quant_meta_fx( hIsmMetaData->yaw_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); + idx_angle2_abs = ism_quant_meta_fx( hIsmMetaData->pitch_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); + /*===============================fix-2-flt======================================*/ + valQ = fixedToFloat( valQ_fx, Q22 ); + /*===============================fix-2-flt======================================*/ +#else + idx_angle1_abs = ism_quant_meta( hIsmMetaData->yaw, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); + idx_angle2_abs = ism_quant_meta( hIsmMetaData->pitch, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); +#endif + idx_radius_abs = usquant( hIsmMetaData->radius, &valQ, ISM_RADIUS_MIN, ISM_RADIUS_DELTA, 1 << ISM_RADIUS_NBITS ); + + encode_angle_indices( hBstr, &( hIsmMetaData->orientation_angle ), hIsmMetaData->last_ism_metadata_flag, ini_frame, idx_angle1_abs, idx_angle2_abs, &flag_abs_yaw[ch], &flag_abs_pitch[ch] ); + encode_radius( hBstr, &hIsmMetaData->last_radius_idx, &hIsmMetaData->radius_diff_cnt, hIsmMetaData->last_ism_metadata_flag, idx_radius_abs, &flag_abs_radius[ch] ); + } + } + + /* save number of metadata bits written */ + if ( ism_mode == ISM_MODE_DISC || ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || ism_mode == ISM_SBA_MODE_DISC ) + { + nb_bits_metadata[ch] = hBstr->nb_bits_tot - nb_bits_start; + } + + /* Updates */ + hIsmMeta[ch]->last_true_azimuth = hIsmMeta[ch]->azimuth; + hIsmMeta[ch]->last_true_elevation = hIsmMeta[ch]->elevation; + hIsmMeta[ch]->last_true_radius = hIsmMeta[ch]->radius; + } + } + + /*----------------------------------------------------------------* + * inter-object logic minimizing the use of several absolutely coded + * indexes in the same frame + *----------------------------------------------------------------*/ + + i = 0; + while ( i == 0 || i < nchan_ism / INTER_OBJECT_PARAM_CHECK ) + { + int16_t num, abs_num, abs_first, abs_next, pos_zero; + int16_t abs_matrice[INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM]; + + num = min( INTER_OBJECT_PARAM_CHECK, nchan_ism - i * INTER_OBJECT_PARAM_CHECK ); + i++; + + set_s( abs_matrice, 0, INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM ); + + for ( ch = 0; ch < num; ch++ ) + { + if ( flag_abs_azimuth[ch] == 1 ) + { + abs_matrice[ch * ISM_NUM_PARAM] = 1; + } + + if ( flag_abs_elevation[ch] == 1 ) + { + abs_matrice[ch * ISM_NUM_PARAM + 1] = 1; + } + } + abs_num = sum_s( abs_matrice, INTER_OBJECT_PARAM_CHECK * ISM_NUM_PARAM ); + + abs_first = 0; + while ( abs_num > 1 ) + { + /* find first "1" entry */ + while ( abs_matrice[abs_first] == 0 ) + { + abs_first++; + } + + /* find next "1" entry */ + abs_next = abs_first + 1; + while ( abs_matrice[abs_next] == 0 ) + { + abs_next++; + } + + /* find "0" position */ + pos_zero = 0; + while ( abs_matrice[pos_zero] == 1 ) + { + pos_zero++; + } + + ch = abs_next / ISM_NUM_PARAM; + + if ( abs_next % ISM_NUM_PARAM == 0 ) + { + hIsmMeta[ch]->position_angle.angle1_diff_cnt = abs_num - 1; + } + + if ( abs_next % ISM_NUM_PARAM == 1 ) + { + hIsmMeta[ch]->position_angle.angle2_diff_cnt = abs_num - 1; + /*hIsmMeta[ch]->elevation_diff_cnt = min( hIsmMeta[ch]->elevation_diff_cnt, ISM_FEC_MAX );*/ + } + + abs_first++; + abs_num--; + } + } + + if ( ism_mode == ISM_SBA_MODE_DISC ) + { + int16_t md_diff_flag[MAX_NUM_OBJECTS]; + + set_s( md_diff_flag, 1, nchan_ism ); + for ( ch = 0; ch < nchan_ism; ch++ ) + { + hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; + + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) + { + hIsmMeta[ch]->ism_md_fec_cnt_enc++; + } + else + { + hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; + } + hIsmMeta[ch]->ism_md_inc_diff_cnt++; + hIsmMeta[ch]->ism_md_inc_diff_cnt = min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); + } + + update_last_metadata( nchan_ism, hIsmMeta, md_diff_flag ); + + pop_wmops(); + return error; + } + if ( ism_mode == ISM_MODE_PARAM ) + { + /* Keep the metdata transmission as is during active parts */ + /* But send the flag with 1 bit */ + push_next_indice( hBstr, hParamIsm->flag_noisy_speech, 1 ); + + /* Loop over multiwave to write the object indices into bitstream */ + for ( ch = 0; ch < MAX_PARAM_ISM_WAVE; ch++ ) + { + for ( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) + { + for ( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) + { + push_next_indice( hBstr, hParamIsm->obj_indices[nbands][nblocks][ch], PARAM_ISM_OBJ_IND_NBITS ); + } + } + } + + /* Loop over bands to write the power ratio's indices into bitstream */ + for ( nbands = 0; nbands < hParamIsm->nbands; nbands++ ) + { + for ( nblocks = 0; nblocks < hParamIsm->nblocks[nbands]; nblocks++ ) + { + push_next_indice( hBstr, hParamIsm->power_ratios_idx[nbands][nblocks], PARAM_ISM_POW_RATIO_NBITS ); + } + } + + /* total metadata bits */ + total_bits_metadata = hBstr->nb_bits_tot - nb_bits_start; + + /* bits per ISM*/ + bits_metadata_ism = (int16_t) ( total_bits_metadata / nchan_transport ); + + /* Divide the metadata bits into n_Isms*/ + nb_bits_objcod_written = 0; + for ( ch = 0; ch < nchan_transport; ch++ ) + { + if ( ch == nchan_transport - 1 ) + { + nb_bits_metadata[ch] = total_bits_metadata - nb_bits_objcod_written; + } + else + { + nb_bits_metadata[ch] = bits_metadata_ism; + nb_bits_objcod_written += bits_metadata_ism; + } + } + } + } + else if ( ism_mode == ISM_SBA_MODE_DISC ) + { + pop_wmops(); + return error; + } + + /*----------------------------------------------------------------* + * Take into account the combined format bit-budget distribution + *----------------------------------------------------------------*/ + + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + int16_t bits_ism, bits_element[MAX_NUM_OBJECTS]; + int16_t brate_limit_flag; + int32_t ism_total_brate_ref; + ism_total_brate_ref = *ism_total_brate; +#ifndef IVAS_FLOAT_FIXED + brate_limit_flag = calculate_brate_limit_flag( ism_imp, nchan_ism ); +#else + brate_limit_flag = calculate_brate_limit_flag_fx( ism_imp, nchan_ism ); +#endif + + bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SEC ); + set_s( bits_element, bits_ism / nchan_ism, nchan_ism ); + bits_element[nchan_ism - 1] += bits_ism % nchan_ism; + bitbudget_to_brate( bits_element, element_brate, nchan_ism ); + + *ism_total_brate = 0; + for ( ch = 0; ch < nchan_ism; ch++ ) + { +#ifndef IVAS_FLOAT_FIXED + *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); +#else + *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate_fx( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ) ); + move32(); +#endif + + if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) + { + *ism_total_brate -= ADJUST_ISM_BRATE_NEG; + } - if ( hSCE[ch]->hCoreCoder[0]->tcxonly ) + if ( brate_limit_flag == -1 && ism_imp[ch] >= 1 && nchan_ism >= 3 && ( ism_total_brate_ref - *ism_total_brate > IVAS_48k ) ) + { + *ism_total_brate += ADJUST_ISM_BRATE_POS; + } + } + ism_metadata_flag_global = 1; + + if ( ism_mode == ISM_MASA_MODE_DISC ) { - if ( hSCE[ch]->hCoreCoder[0]->localVAD == 0 ) + brate_limit_flag = 0; + for ( int16_t n = 0; n < nchan_ism; n++ ) { - ctype = INACTIVE; + brate_limit_flag += ism_imp[n]; } - else if ( ctype == UNVOICED ) + + if ( brate_limit_flag >= nchan_ism * ISM_HIGH_IMP - 2 ) { - ctype = GENERIC; + *omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; } } + } - if ( ( hIsmMeta[ch]->ism_metadata_flag == 0 || lowrate_metadata_flag[ch] == 1 ) && hSCE[ch]->hCoreCoder[0]->localVAD == 0 ) + /*----------------------------------------------------------------* + * Configuration and decision about bitrates per channel + *----------------------------------------------------------------*/ + + if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 1 ) ) != IVAS_ERR_OK ) { - ism_imp[ch] = ISM_NO_META; + return error; } - else if ( ctype == INACTIVE || ctype == UNVOICED ) + } + else + { + if ( ( error = ivas_ism_config( *ism_total_brate, nchan_transport, nchan_ism, hIsmMeta, ism_extended_metadata_flag, null_metadata_flag, ism_imp, element_brate, total_brate, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK ) { - ism_imp[ch] = ISM_LOW_IMP; + return error; } - else if ( ctype == VOICED ) + } + + for ( ch = 0; ch < nchan_ism; ch++ ) + { + hIsmMeta[ch]->last_ism_metadata_flag = hIsmMeta[ch]->ism_metadata_flag; + + if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { - ism_imp[ch] = ISM_MEDIUM_IMP; + hIsmMeta[ch]->ism_md_fec_cnt_enc++; } - else /* GENERIC */ + else { - ism_imp[ch] = ISM_HIGH_IMP; + hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; } + hIsmMeta[ch]->ism_md_inc_diff_cnt++; + hIsmMeta[ch]->ism_md_inc_diff_cnt = min( hIsmMeta[ch]->ism_md_inc_diff_cnt, ISM_MD_INC_DIFF_CNT_MAX ); } - return; -} + for ( ch = 0; ch < nchan_transport; ch++ ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 0; + if ( ism_mode == ISM_MODE_DISC ) + { + if ( ism_imp[ch] == ISM_NO_META && ( ( total_brate[ch] < ACELP_8k00 && element_brate[ch] < SCE_CORE_16k_LOW_LIMIT ) || + ( total_brate[ch] <= ACELP_16k_LOW_LIMIT && element_brate[ch] >= SCE_CORE_16k_LOW_LIMIT ) ) ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + } + + hSCE[ch]->element_brate = element_brate[ch]; + } + else if ( ism_mode == ISM_MASA_MODE_DISC || ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ ) + { + if ( ism_imp[ch] == ISM_INACTIVE_IMP ) + { + hSCE[ch]->hCoreCoder[0]->low_rate_mode = 1; + } + } + hSCE[ch]->hCoreCoder[0]->total_brate = total_brate[ch]; -/*-------------------------------------------------------------------------* - * ivas_ism_metadata_enc() - * - * quantize and encode ISM metadata - *-------------------------------------------------------------------------*/ + /* write metadata only in active frames */ + if ( hSCE[0]->hCoreCoder[0]->core_brate > SID_2k40 ) + { + reset_indices_enc( hSCE[ch]->hMetaData, hSCE[ch]->hMetaData->nb_ind_tot ); + } + } + + pop_wmops(); + return error; +} +#else ivas_error ivas_ism_metadata_enc( int32_t *ism_total_brate, /* i/o: ISM total bitrate */ const int16_t nchan_ism, /* i : number of ISM channels */ @@ -634,11 +1260,7 @@ ivas_error ivas_ism_metadata_enc( int16_t brate_limit_flag; int32_t ism_total_brate_ref; ism_total_brate_ref = *ism_total_brate; -#ifndef IVAS_FLOAT_FIXED brate_limit_flag = calculate_brate_limit_flag( ism_imp, nchan_ism ); -#else - brate_limit_flag = calculate_brate_limit_flag_fx( ism_imp, nchan_ism ); -#endif bits_ism = (int16_t) ( *ism_total_brate / FRAMES_PER_SEC ); set_s( bits_element, bits_ism / nchan_ism, nchan_ism ); @@ -648,12 +1270,8 @@ ivas_error ivas_ism_metadata_enc( *ism_total_brate = 0; for ( ch = 0; ch < nchan_ism; ch++ ) { -#ifndef IVAS_FLOAT_FIXED - *ism_total_brate += ivas_interformat_brate( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ); -#else *ism_total_brate = L_add( *ism_total_brate, ivas_interformat_brate_fx( ism_mode, nchan_ism, hSCE[ch]->element_brate, ism_imp[ch], brate_limit_flag ) ); move32(); -#endif if ( ism_imp[ch] > 1 && flag_omasa_ener_brate == 1 && brate_limit_flag >= 0 ) { @@ -751,6 +1369,7 @@ ivas_error ivas_ism_metadata_enc( return error; } +#endif /*------------------------------------------------------------------------- @@ -1238,6 +1857,163 @@ static void encode_angle_indices( * Quantize and encode ISM metadata in SID frame *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_ism_metadata_sid_enc( + ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ + const int16_t flag_noisy_speech, /* i : noisy speech flag */ + const int16_t nchan_ism, /* i : number of objects */ + const int16_t nchan_transport, /* i : number of transport channels */ + const ISM_MODE ism_mode, /* i : ISM mode */ + ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles */ + const int16_t sid_flag, /* i : indication of SID frame */ + const int16_t md_diff_flag[], /* i : metadata differental flag */ + BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */ + int16_t nb_bits_metadata[] /* o : number of metadata bits */ +) +{ + int16_t i, ch, nBits, nBits_start, nBits_unused; + float q_step, q_step_border; +#ifdef IVAS_FLOAT_FIXED + Word32 q_step_fx, q_step_border_fx; +#endif + int16_t idx, idx_azimuth, idx_elevation; + int16_t nBits_azimuth, nBits_elevation, nBits_coh, nBits_sce_id; +#ifdef IVAS_FLOAT_FIXED + Word32 valQ_fx; +#endif + ISM_METADATA_HANDLE hIsmMetaData; + + if ( sid_flag ) + { + nBits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; + nBits -= SID_FORMAT_NBITS; + nBits_start = hBstr->nb_bits_tot; + + /*----------------------------------------------------------------* + * Write ISm common signaling + *----------------------------------------------------------------*/ + + /* write number of objects - unary coding */ + for ( ch = 1; ch < nchan_ism; ch++ ) + { + push_indice( hBstr, IND_ISM_NUM_OBJECTS, 1, 1 ); + } + push_indice( hBstr, IND_ISM_NUM_OBJECTS, 0, 1 ); + + /* write SID metadata flag (one per object) */ + for ( ch = 0; ch < nchan_ism; ch++ ) + { + push_indice( hBstr, IND_ISM_METADATA_FLAG, md_diff_flag[ch], 1 ); + } + + /*----------------------------------------------------------------* + * Set quantization bits based on the number of coded objects + *----------------------------------------------------------------*/ + + ivas_get_ism_sid_quan_bitbudget( nchan_ism, &nBits_azimuth, &nBits_elevation, &q_step, &q_step_border, &nBits_coh, &nBits_sce_id ); + + /*----------------------------------------------------------------* + * Spatial parameters, loop over TCs - 1 + *----------------------------------------------------------------*/ + + /* write ISM mode flag to explicitly signal number of spatial parameters */ + if ( nchan_ism > 2 ) + { + if ( ism_mode == ISM_MODE_DISC ) + { + push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, 0, 1 ); + } + else + { + push_indice( hBstr, IND_ISM_MD_INACTIVE_FLAG, 1, 1 ); + } + + if ( ism_mode == ISM_MODE_PARAM ) + { + /* write noisy speech flag */ + push_indice( hBstr, IND_ISM_NOISY_SPEECH_FLAG, flag_noisy_speech, 1 ); + nBits_sce_id = 1; + } + } + + if ( nchan_transport > 1 ) + { + /* write sce id */ + push_indice( hBstr, IND_ISM_SCE_ID_DTX, hISMDTX->sce_id_dtx, nBits_sce_id ); + + /* quantize and write coherence */ + for ( ch = 0; ch < nchan_transport; ch++ ) + { + if ( ch == hISMDTX->sce_id_dtx ) + { + continue; + } + + idx = (int16_t) ( hISMDTX->coh[ch] * ( ( 1 << nBits_coh ) - 1 ) + 0.5f ); + assert( ( idx >= 0 ) && ( idx <= ( ( 1 << nBits_coh ) - 1 ) ) ); + push_indice( hBstr, IND_ISM_DTX_COH_SCA, idx, nBits_coh ); + } + } + + /*----------------------------------------------------------------* + * Metadata quantization and coding, loop over all objects + *----------------------------------------------------------------*/ + + for ( ch = 0; ch < nchan_ism; ch++ ) + { + if ( md_diff_flag[ch] == 1 ) + { + hIsmMetaData = hIsmMeta[ch]; + +#ifdef IVAS_FLOAT_FIXED + /*===============================flt-2-fix======================================*/ + hIsmMetaData->azimuth_fx = floatToFixed( hIsmMetaData->azimuth, Q22 ); + hIsmMetaData->elevation_fx = floatToFixed( hIsmMetaData->elevation, Q22 ); + q_step_fx = floatToFixed( q_step, Q22 ); + q_step_border_fx = floatToFixed( q_step_border, Q22 ); + /*===============================flt-2-fix======================================*/ + idx_azimuth = ism_quant_meta_fx( hIsmMetaData->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_azimuth ); + idx_elevation = ism_quant_meta_fx( hIsmMetaData->elevation_fx, &valQ_fx, ism_elevation_borders_fx, q_step_fx, q_step_border_fx, 1 << nBits_elevation ); +#else + idx_azimuth = ism_quant_meta( hIsmMetaData->azimuth, &valQ, ism_azimuth_borders, q_step, q_step_border, 1 << nBits_azimuth ); + idx_elevation = ism_quant_meta( hIsmMetaData->elevation, &valQ, ism_elevation_borders, q_step, q_step_border, 1 << nBits_elevation ); +#endif + + push_indice( hBstr, IND_ISM_AZIMUTH, idx_azimuth, nBits_azimuth ); + push_indice( hBstr, IND_ISM_ELEVATION, idx_elevation, nBits_elevation ); + + /* update last indexes to correspond to active frames coding */ + if ( nBits_azimuth > ISM_AZIMUTH_NBITS ) + { + hIsmMetaData->position_angle.last_angle1_idx = idx_azimuth >> ( nBits_azimuth - ISM_AZIMUTH_NBITS ); + hIsmMetaData->position_angle.last_angle2_idx = idx_elevation >> ( nBits_elevation - ISM_ELEVATION_NBITS ); + } + else + { + hIsmMetaData->position_angle.last_angle1_idx = idx_azimuth << ( ISM_AZIMUTH_NBITS - nBits_azimuth ); + hIsmMetaData->position_angle.last_angle2_idx = idx_elevation << ( ISM_ELEVATION_NBITS - nBits_elevation ); + } + + hIsmMetaData->ism_md_fec_cnt_enc = 0; + hIsmMeta[ch]->ism_md_inc_diff_cnt = ISM_MD_INC_DIFF_CNT_MAX; + } + } + + /* Write unused (padding) bits */ + nBits_unused = nBits - hBstr->nb_bits_tot; + while ( nBits_unused > 0 ) + { + i = min( nBits_unused, 16 ); + push_indice( hBstr, IND_UNUSED, 0, i ); + nBits_unused -= i; + } + + nb_bits_metadata[0] = hBstr->nb_bits_tot - nBits_start; + } + + return; +} +#else void ivas_ism_metadata_sid_enc( ISM_DTX_HANDLE hISMDTX, /* i/o: ISM DTX handle */ const int16_t flag_noisy_speech, /* i : noisy speech flag */ @@ -1377,3 +2153,4 @@ void ivas_ism_metadata_sid_enc( return; } +#endif diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 52b7bc030..c3a0881f6 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -35,7 +35,10 @@ #include #include "options.h" #include "ivas_prot.h" +#include "ivas_prot_fx.h" #include "prot.h" +#include "prot_fx1.h" +#include "prot_fx2.h" #include "cnst.h" #include "ivas_cnst.h" #include "ivas_rom_com.h" @@ -169,6 +172,56 @@ static void ivas_param_ism_compute_obj_parameters( } +#ifdef IVAS_FLOAT_FIXED +static void ivas_param_ism_enc_quantize_DOA( + const int16_t nchan_ism, /* i : number of ISM channels */ + ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata */ + PARAM_ISM_CONFIG_HANDLE hParamIsm /* i/o: Param ISM encoder handle */ +) +{ + int16_t i, azi_idx, ele_idx; + float valQ; +#ifdef IVAS_FLOAT_FIXED + Word32 valQ_fx; +#endif + + + /* Loop over objects */ + for ( i = 0; i < nchan_ism; i++ ) + { +#ifdef IVAS_FLOAT_FIXED + /*===============================flt-2-fix======================================*/ + hIsmMetaData[i]->azimuth_fx = floatToFixed( hIsmMetaData[i]->azimuth, Q22 ); + hIsmMetaData[i]->elevation_fx = floatToFixed( hIsmMetaData[i]->elevation, Q22 ); + /*===============================flt-2-fix======================================*/ + + /* Quantize the elevation and obtain quantized elevation value and index */ + ele_idx = ism_quant_meta_fx( hIsmMetaData[i]->elevation_fx, &valQ_fx, ism_elevation_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_ELEVATION_NBITS ); + + /* Obtain the index of quantized azimuth values */ + azi_idx = ism_quant_meta_fx( hIsmMetaData[i]->azimuth_fx, &valQ_fx, ism_azimuth_borders_fx, ISM_Q_STEP_FX, ISM_Q_STEP_BORDER_FX, 1 << ISM_AZIMUTH_NBITS ); + /*===============================fix-2-flt======================================*/ + valQ = fixedToFloat( valQ_fx, Q22 ); + /*===============================fix-2-flt======================================*/ +#else + /* Quantize the elevation and obtain quantized elevation value and index */ + ele_idx = ism_quant_meta( hIsmMetaData[i]->elevation, &valQ, ism_elevation_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_ELEVATION_NBITS ); + + /* Obtain the index of quantized azimuth values */ + azi_idx = ism_quant_meta( hIsmMetaData[i]->azimuth, &valQ, ism_azimuth_borders, ISM_Q_STEP, ISM_Q_STEP_BORDER, 1 << ISM_AZIMUTH_NBITS ); +#endif + + /*Replace azimuth with quantized values */ + hIsmMetaData[i]->azimuth = valQ; + + /* Copy the quantized indices */ + hParamIsm->azi_index[i] = azi_idx; + hParamIsm->ele_index[i] = ele_idx; + } + + return; +} +#else static void ivas_param_ism_enc_quantize_DOA( const int16_t nchan_ism, /* i : number of ISM channels */ ISM_METADATA_HANDLE hIsmMetaData[MAX_NUM_OBJECTS], /* i : ISM metadata */ @@ -198,6 +251,7 @@ static void ivas_param_ism_enc_quantize_DOA( return; } +#endif /*-------------------------------------------------------------------------* -- GitLab From f697fe96b8f0e1191f3594d89faeb0d370786ab3 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 24 Jun 2024 12:26:59 +0530 Subject: [PATCH 59/63] Fix for issue 696: Audible "plop" at 16.4 kbps stereo likely due to ipd difference between float and fixed point --- lib_com/cnst.h | 2 + lib_dec/ivas_stat_dec.h | 8 ++-- lib_dec/ivas_stereo_dft_dec_fx.c | 78 ++++++++++++++++---------------- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index a77a8d8e0..a1ec42fb9 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -3008,6 +3008,8 @@ enum #define EVS_PI 3.14159265358979323846264338327950288f #define EVS_PI_FX 25736 /* pi in Q13 */ #define EVS_2PI_FX 51472 /* 2 * pi in Q13 */ +#define EVS_PI_FX_Q27 421657428 /* pi in Q28 */ +#define EVS_2PI_FX_Q27 843314856 /* 2 * pi in Q28 */ #define EVS_PI_BY_2_FX (Word16)(0x3244) //#define EVS_PI_FX (Word16)(0x6488) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 272cc4582..ba197492c 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -159,7 +159,7 @@ typedef struct stereo_dft_dec_data_struct #ifndef IVAS_FLOAT_FIXED float gipd[STEREO_DFT_DEC_DFT_NB]; #else - Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q13 */ + Word32 gipd_fx[STEREO_DFT_DEC_DFT_NB]; /* Q27 */ #endif int16_t no_ipd_flag; /* flag to indicate when no IPD gets used */ @@ -197,9 +197,9 @@ typedef struct stereo_dft_dec_data_struct Word32 itd_xfade_target_fx; /* Q15 */ Word32 itd_xfade_prev_fx; /* Q15 */ - Word32 ipd_xfade_target_fx; /* Q13 */ - Word32 ipd_xfade_step_fx; /* Q13 */ - Word32 ipd_xfade_prev_fx; /* Q13 */ + Word32 ipd_xfade_target_fx; /* Q27 */ + Word32 ipd_xfade_step_fx; /* Q27 */ + Word32 ipd_xfade_prev_fx; /* Q27 */ Word32 res_pred_gain_fx[STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX]; /* prediction gain for the residual HFs */ /* Q31 */ #endif int16_t res_pred_band_min; /* Band min for prediction of residual */ diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index d11dd6ba2..2238d768f 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -838,14 +838,14 @@ void stereo_dft_dec_smooth_parameters_fx( #endif { Word16 q_val; - IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX ) ) + IF( GT_32( L_sub( hStereoDft->gipd_fx[add( k, k_offset )], hStereoDft->ipd_xfade_prev_fx ), EVS_PI_FX_Q27 ) ) { - hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX ); + hStereoDft->ipd_xfade_target_fx = L_sub( hStereoDft->gipd_fx[add( k, k_offset )], EVS_PI_FX_Q27 ); move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); - q_val = sub( q_val, Q2 ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); - IF( GT_16( q_val, 16 ) ) + IF( GT_16( q_val, 32 ) ) { assert( 0 ); } @@ -854,14 +854,14 @@ void stereo_dft_dec_smooth_parameters_fx( hStereoDft->ipd_xfade_step_fx = L_shl( hStereoDft->ipd_xfade_step_fx, q_val ); } } - ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX ) ) + ELSE IF( GT_32( L_sub( hStereoDft->ipd_xfade_prev_fx, hStereoDft->gipd_fx[add( k, k_offset )] ), EVS_PI_FX_Q27 ) ) { - hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX, 1 ) ); + hStereoDft->ipd_xfade_target_fx = L_add( hStereoDft->gipd_fx[add( k, k_offset )], L_shl( EVS_PI_FX_Q27, 1 ) ); move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); - q_val = sub( q_val, Q2 ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); - IF( GT_16( q_val, 16 ) ) + IF( GT_16( q_val, 32 ) ) { assert( 0 ); } @@ -874,10 +874,10 @@ void stereo_dft_dec_smooth_parameters_fx( { hStereoDft->ipd_xfade_target_fx = hStereoDft->gipd_fx[add( k, k_offset )]; move32(); - hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q13 ), &q_val ); - q_val = sub( q_val, Q2 ); + hStereoDft->ipd_xfade_step_fx = BASOP_Util_Divide3232_Scale( L_sub( hStereoDft->ipd_xfade_target_fx, hStereoDft->ipd_xfade_prev_fx ), L_shl( L_sub( STEREO_DFT_ITD_CNG_XFADE, hStereoDft->ipd_xfade_counter ), Q24 ), &q_val ); + q_val = add( q_val, Q9 ); /* Q27 - (Q15 - q_val + (-3))*/ move32(); - IF( GT_16( q_val, 16 ) ) + IF( GT_16( q_val, 32 ) ) { assert( 0 ); } @@ -1135,13 +1135,13 @@ void stereo_dft_dec_smooth_parameters_fx( /* Smoothing of IPDs*/ pgIpd = hStereoDft->gipd_fx + ( add( k, k_offset ) ); diff_ipd = L_sub( pgIpd[0], pgIpd[-hStereoDft->prm_res[add( k, k_offset )]] ); - IF( LT_32( diff_ipd, -EVS_PI_FX ) ) + IF( LT_32( diff_ipd, -EVS_PI_FX_Q27 ) ) { - pgIpd[0] = L_add( L_add( pgIpd[0], EVS_PI_FX ), EVS_PI_FX ); + pgIpd[0] = L_add( pgIpd[0], EVS_2PI_FX_Q27 ); } - ELSE IF( GT_32( diff_ipd, EVS_PI_FX ) ) + ELSE IF( GT_32( diff_ipd, EVS_PI_FX_Q27 ) ) { - pgIpd[0] = L_sub( L_sub( pgIpd[0], EVS_PI_FX ), EVS_PI_FX ); + pgIpd[0] = L_sub( pgIpd[0], EVS_2PI_FX_Q27 ); } IF( !hStereoDft->attackPresent ) @@ -1637,23 +1637,23 @@ void stereo_dft_dec_fx( IF( NE_32( pgIpd[0], 0 ) ) { Word32 theta = pgIpd[0]; - WHILE( GT_32( theta, EVS_2PI_FX ) ) + WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - WHILE( LT_32( theta, -EVS_2PI_FX ) ) + WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - IF( GT_32( theta, EVS_PI_FX ) ) + IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - ELSE IF( LT_32( theta, -EVS_PI_FX ) ) + ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - c0 = getCosWord16( extract_l( theta ) ); + c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) { c0 = MAX_16; @@ -1662,7 +1662,7 @@ void stereo_dft_dec_fx( { c0 = shl( c0, 1 ); } - s0 = getSinWord16( extract_l( theta ) ); + s0 = getSinWord16( (Word16) L_shr( theta, 14 ) ); FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ @@ -1902,23 +1902,23 @@ void stereo_dft_dec_fx( IF( NE_32( pgIpd[0], 0 ) ) { Word32 theta = pgIpd[0]; - WHILE( GT_32( theta, EVS_2PI_FX ) ) + WHILE( GT_32( theta, EVS_2PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - WHILE( LT_32( theta, -EVS_2PI_FX ) ) + WHILE( LT_32( theta, -EVS_2PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - IF( GT_32( theta, EVS_PI_FX ) ) + IF( GT_32( theta, EVS_PI_FX_Q27 ) ) { - theta = L_sub( theta, EVS_2PI_FX ); + theta = L_sub( theta, EVS_2PI_FX_Q27 ); } - ELSE IF( LT_32( theta, -EVS_PI_FX ) ) + ELSE IF( LT_32( theta, -EVS_PI_FX_Q27 ) ) { - theta = L_add( theta, EVS_2PI_FX ); + theta = L_add( theta, EVS_2PI_FX_Q27 ); } - c0 = getCosWord16( extract_l( theta ) ); + c0 = getCosWord16( (Word16) L_shr( theta, 14 ) ); IF( EQ_16( c0, ONE_IN_Q14 ) ) { c0 = MAX_16; @@ -1927,7 +1927,7 @@ void stereo_dft_dec_fx( { c0 = shl( c0, 1 ); } - s0 = getSinWord16( extract_l( theta ) ); + s0 = getSinWord16( (Word16) L_shr( theta, 14 ) ); FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { /*rotate L*/ @@ -2335,6 +2335,7 @@ static void stereo_dft_dequantize_ipd_fx( { Word16 i; Word16 delta_fx; + Word32 temp_out; IF( EQ_16( bits, 2 ) ) /* 2-bit phase quantization for the highest frequency band only */ { delta_fx = ( EVS_PI_FX ) >> 1; @@ -2355,7 +2356,8 @@ static void stereo_dft_dequantize_ipd_fx( FOR( i = 0; i < N; i++ ) { - *out_fx = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); + temp_out = L_sub( L_mult0( ind[i], delta_fx ), ( EVS_PI_FX ) ); + *out_fx = L_shl( temp_out, 14 ); } return; } -- GitLab From 47efd16528edf62479158ac4da28ace2dcd0484e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 24 Jun 2024 13:39:19 +0530 Subject: [PATCH 60/63] BASOP and instrumentation changes in lib_dec and lib_rend --- lib_com/ivas_prot.h | 12 +- lib_dec/ivas_init_dec.c | 8 +- lib_dec/ivas_mc_param_dec.c | 998 ++++++++++++++++-------- lib_dec/ivas_mc_paramupmix_dec.c | 344 ++++---- lib_dec/ivas_mct_dec.c | 386 ++++++--- lib_dec/ivas_mct_dec_mct_fx.c | 53 +- lib_dec/ivas_out_setup_conversion.c | 265 ++++--- lib_dec/ivas_pca_dec_fx.c | 38 +- lib_dec/ivas_post_proc.c | 292 ++++--- lib_dec/ivas_qmetadata_dec.c | 414 ++++++---- lib_dec/ivas_qspherical_dec.c | 17 +- lib_dec/ivas_sba_dec.c | 527 ++++++------- lib_dec/ivas_sba_dirac_stereo_dec_fx.c | 229 +++--- lib_dec/ivas_sba_rendering_internal.c | 162 +--- lib_dec/ivas_sce_dec_fx.c | 103 ++- lib_dec/ivas_sns_dec_fx.c | 130 ++- lib_dec/lib_dec_fx.c | 2 +- lib_rend/ivas_objectRenderer_sfx.c | 9 +- lib_rend/ivas_prot_rend.h | 22 +- lib_rend/ivas_rom_binaural_crend_head.c | 95 ++- lib_rend/ivas_rom_binaural_crend_head.h | 167 ++-- lib_rend/ivas_rom_rend.c | 58 +- lib_rend/ivas_rom_rend.h | 52 +- lib_rend/ivas_rotation.c | 741 ++++++++++++------ lib_rend/ivas_sba_rendering.c | 93 ++- lib_rend/lib_rend.c | 4 +- 26 files changed, 3266 insertions(+), 1955 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index fda8732d9..363237d9c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -491,9 +491,15 @@ void destroy_core_dec( DEC_CORE_HANDLE hCoreCoder /* i/o: core decoder structure */ ); +#ifndef IVAS_FLOAT_FIXED void ivas_destroy_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#else +void ivas_destroy_dec_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); +#endif void ivas_initialize_handles_dec( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ @@ -4614,9 +4620,9 @@ void ivas_mc_paramupmix_dec_digest_tc( #ifdef IVAS_FLOAT_FIXED void ivas_mc_paramupmix_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ - uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ - uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ Word32 *input_fx[], /* i : core-coder transport channels */ Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ ); diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index eb526f1f5..214c004fa 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -4479,7 +4479,7 @@ void ivas_initialize_handles_dec( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_destroy_dec( +void ivas_destroy_dec_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder handle */ ) { @@ -4624,13 +4624,13 @@ void ivas_destroy_dec( /* OMASA structure */ ivas_omasa_data_close_fx( &st_ivas->hMasaIsmData ); /* Head track data handle */ - ivas_headTrack_close( &st_ivas->hHeadTrackData ); + ivas_headTrack_close_fx( &st_ivas->hHeadTrackData ); /* External orientation data handle */ - ivas_external_orientation_close( &st_ivas->hExtOrientationData ); + ivas_external_orientation_close_fx( &st_ivas->hExtOrientationData ); /* Combined orientation data handle */ - ivas_combined_orientation_close( &st_ivas->hCombinedOrientationData ); + ivas_combined_orientation_close_fx( &st_ivas->hCombinedOrientationData ); /* Time Domain binaural renderer handle */ IF( st_ivas->hBinRendererTd != NULL ) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 8e38d958b..d25fff5f8 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -93,7 +93,11 @@ static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, #else static void ivas_param_mc_dec_copy_diffuse_proto( PARAM_MC_DEC_HANDLE hParamMC, float Cldfb_buffer_real[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Cldfb_buffer_imag[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], const int16_t nY, const int16_t slot_idx ); #endif -static Word16 ivas_param_mc_range_decoder_LC( UWord16 *bit_buffer, Word16 *x, Word16 *BER_detect, const Word16 sz_seq, const Word16 sz_alphabet, const UWord16 *cft, const UWord16 *sft, const Word16 tot_shift, const Word16 nbbits ); +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_param_mc_range_decoder_LC_fx( UWord16 *bit_buffer, Word16 *x, Word16 *BER_detect, const Word16 sz_seq, const Word16 sz_alphabet, const UWord16 *cft, const UWord16 *sft, const Word16 tot_shift, const Word16 nbbits ); +#else +static int16_t ivas_param_mc_range_decoder_LC( uint16_t *bit_buffer, int16_t *x, int16_t *BER_detect, const int16_t sz_seq, const int16_t sz_alphabet, const uint16_t *cft, const uint16_t *sft, const int16_t tot_shift, const int16_t nbbits ); +#endif #ifndef IVAS_FLOAT_FIXED static int16_t ivas_param_mc_uniform_decoder( float *seq, const int16_t sz_seq, const float *alphabet, const int16_t N, uint16_t bit_buffer[PARAM_MC_MAX_BITS] ); @@ -190,51 +194,67 @@ ivas_error ivas_param_mc_dec_open_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ - if ( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL ) + IF( ( hParamMC = (PARAM_MC_DEC_HANDLE) malloc( sizeof( PARAM_MC_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - if ( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL ) + IF( ( hParamMC->hMetadataPMC = (HANDLE_IVAS_PARAM_MC_METADATA) malloc( sizeof( IVAS_PARAM_MC_METADATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC metadata \n" ) ); } output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); output_config = st_ivas->hDecoderConfig->output_config; + move32(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); #ifndef FIX_901_PARAMMC_DEAD_CODE hTransportSetup = st_ivas->hTransSetup; #endif mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); - nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); hParamMC->hoa_encoder_fx = NULL; /* determine the synthesis config */ - if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD || st_ivas->transport_config == output_config ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( st_ivas->transport_config, output_config ) ) { hParamMC->synthesis_conf = PARAM_MC_SYNTH_DIRECT; + move32(); } - else if ( output_config == IVAS_AUDIO_CONFIG_MONO || output_config == IVAS_AUDIO_CONFIG_STEREO ) + ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { hParamMC->synthesis_conf = PARAM_MC_SYNTH_MONO_STEREO; + move32(); } - else if ( st_ivas->transport_config != output_config ) + ELSE IF( NE_32( st_ivas->transport_config, output_config ) ) { - if ( ( output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM && nchan_out_transport > audioCfg2channels( output_config ) ) || ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM && nchan_out_transport > st_ivas->hOutSetup.nchan_out_woLFE ) ) + test(); + test(); + IF( ( NE_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, audioCfg2channels( output_config ) ) ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( nchan_out_transport, st_ivas->hOutSetup.nchan_out_woLFE ) ) ) { hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_COV; + move32(); /* need to reset the intern config */ st_ivas->intern_config = output_config; + move32(); ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); - if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { st_ivas->hIntSetup.nchan_out_woLFE = st_ivas->hLsSetupCustom->num_spk; + move32(); #if 0 /*TODO: To be removed later*/ st_ivas->hIntSetup.ls_azimuth = st_ivas->hLsSetupCustom->ls_azimuth; st_ivas->hIntSetup.ls_elevation = st_ivas->hLsSetupCustom->ls_elevation; @@ -243,9 +263,10 @@ ivas_error ivas_param_mc_dec_open_fx( st_ivas->hIntSetup.ls_elevation_fx = st_ivas->hLsSetupCustom->ls_elevation_fx; } } - else + ELSE { hParamMC->synthesis_conf = PARAM_MC_SYNTH_LS_CONV_CLDFB; + move32(); } } @@ -254,46 +275,67 @@ ivas_error ivas_param_mc_dec_open_fx( #endif hParamMC->ls_conv_dmx_matrix_fx = NULL; - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + test(); + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); } - else + ELSE { nchan_out_cov = nchan_out_transport; + move16(); } st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + move16(); config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); nchan_transport = st_ivas->nchan_transport; + move16(); - switch ( nchan_transport ) + SWITCH( nchan_transport ) { case 4: case 3: st_ivas->nCPE = 2; + move16(); st_ivas->nSCE = 0; + move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; - break; + move16(); + BREAK; case 2: st_ivas->nCPE = 1; + move16(); st_ivas->nSCE = 0; + move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); - break; + BREAK; } /*-----------------------------------------------------------------* * set input parameters *-----------------------------------------------------------------*/ - hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; - set_s( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); - set_s( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); + // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; + Word16 temp_e; + Word16 temp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + temp = BASOP_Util_Divide1616_Scale( temp, CLDFB_NO_COL_MAX, &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + hParamMC->slot_size = temp; + move16(); + set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); + set16_fx( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hParamMC->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; + move16(); - hParamMC->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + // hParamMC->num_freq_bands = (int16_t)(output_Fs * INV_CLDFB_BANDWIDTH + 0.5f); + hParamMC->num_freq_bands = extract_l( Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ); + move16(); hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; + move16(); #ifndef FIX_901_PARAMMC_DEAD_CODE ivas_param_mc_metadata_open( mc_ls_setup, hTransportSetup.index_lfe[0], ivas_total_brate, hParamMC->hMetadataPMC ); #else @@ -302,42 +344,45 @@ ivas_error ivas_param_mc_dec_open_fx( /* init arrays for quantized parameters */ - if ( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) + IF( ( hParamMC->icc_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - if ( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) + IF( ( hParamMC->icld_q_fx = (Word16 *) malloc( hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); - set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); + set16_fx( hParamMC->icld_q_fx, PARAM_MC_DEFAULT_MIN_ILD_FX, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ) ); + set16_fx( hParamMC->icc_q_fx, 0, imult1616( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ) ); param_mc_set_num_synth_bands( output_Fs, hParamMC ); /* Band Grouping */ - if ( hParamMC->hMetadataPMC->num_parameter_bands == 20 ) + IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 20 ) ) { - mvs2s( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); + Copy( param_mc_band_grouping_20, hParamMC->band_grouping, 20 + 1 ); } - else if ( hParamMC->hMetadataPMC->num_parameter_bands == 14 ) + ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 14 ) ) { - mvs2s( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); + Copy( param_mc_band_grouping_14, hParamMC->band_grouping, 14 + 1 ); } - else if ( hParamMC->hMetadataPMC->num_parameter_bands == 10 ) + ELSE IF( EQ_16( hParamMC->hMetadataPMC->num_parameter_bands, 10 ) ) { - mvs2s( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); + Copy( param_mc_band_grouping_10, hParamMC->band_grouping, 10 + 1 ); } - else + ELSE { assert( 0 && "nbands must be 20, 14, or 10!" ); } /* set max parameter band for abs cov */ k = 0; - while ( hParamMC->band_grouping[k] <= PARAM_MC_MAX_BAND_ABS_COV_DEC ) + move16(); + WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) ) { - hParamMC->max_param_band_abs_cov = ( k++ ); + hParamMC->max_param_band_abs_cov = k; + move16(); + k = add( k, 1 ); } /*-----------------------------------------------------------------* @@ -346,15 +391,18 @@ ivas_error ivas_param_mc_dec_open_fx( /* prototype signal computation */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB || hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + test(); + test(); + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - if ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + test(); + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { #if 0 /*TODO: To be removed later (floating point malloc)*/ if ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) @@ -367,84 +415,93 @@ ivas_error ivas_param_mc_dec_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - for ( k = 0; k < nchan_out_transport; k++ ) + FOR( k = 0; k < nchan_out_transport; k++ ) { - Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[k * nchan_out_cov], nchan_out_cov ); /*Q30*/ + Copy32( st_ivas->hLsSetUpConversion->dmxMtx_fx[k], &hParamMC->ls_conv_dmx_matrix_fx[L_mult0( k, nchan_out_cov )], nchan_out_cov ); /*Q30*/ } /* convert ParamMC parameter bands to SFB */ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; - for ( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) + move16(); + FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) { - st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; + st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] ); + move16(); } } - else + ELSE { /* close the ls conversion handle immediately, it was only needed to get the DMX matrix in case of DMX in the covariance domain */ ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); } } } - if ( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL ) + IF( ( hParamMC->proto_matrix_int_fx = (Word32 *) malloc( nchan_out_transport * nchan_transport * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport ); /*Q31*/ + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, imult1616( nchan_transport, nchan_out_transport ) ); /*Q31*/ - hParamMC->proto_matrix_int_len = nchan_out_transport * nchan_transport; + hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport ); move16(); - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + test(); + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); /*Q.26*/ + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); /*Q.26*/ matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx ); /*Q.26*/ - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); /*Q.26*/ - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); /*Q.26*/ + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { proto_mtx_norm_fx = ONE_IN_Q26; /*Q26*/ - for ( k = 0; k < nchan_transport * nchan_out_cov; k++ ) + move32(); + FOR( k = 0; k < imult1616( nchan_transport, nchan_out_cov ); k++ ) { proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); /*Q.26*/ } proto_mtx_norm_fx = divide3232( ONE_IN_Q26, proto_mtx_norm_fx ); /*Q15*/ /* transfer flattened proto_matrix to 2D in hLsSetupConversion->dmxMtx */ - for ( k = 0; k < nchan_transport; k++ ) + FOR( k = 0; k < nchan_transport; k++ ) { - for ( int16_t i = 0; i < nchan_out_cov; i++ ) + FOR( Word16 i = 0; i < nchan_out_cov; i++ ) { - st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[k * nchan_out_cov + i], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/ + st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mult_32_16( proto_matrix_fx[add( imult1616( k, nchan_out_cov ), i )], extract_l( proto_mtx_norm_fx ) ), 4 ); /*Q.30*/ + move32(); } } } } - else + ELSE { - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport ); /*Q.31*/ - Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5 ); /*Scaling down to 26*/ + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); /*Q.31*/ + Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); /*Scaling down to 26*/ } - if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { hParamMC->num_outputs_diff = 0; + move16(); hParamMC->diff_proto_info = NULL; hParamMC->h_output_synthesis_params.use_onset_filters = 0; + move16(); hParamMC->max_band_decorr = 0; + move16(); hParamMC->h_freq_domain_decorr_ap_params = NULL; hParamMC->h_freq_domain_decorr_ap_state = NULL; } - else + ELSE { hParamMC->num_outputs_diff = nchan_out_cov; - if ( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) + move16(); + IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - if ( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = param_mc_get_diff_proto_info_fx( proto_matrix_fx, nchan_transport, nchan_out_cov, hParamMC->diff_proto_info, Q26 ) ), IVAS_ERR_OK ) ) { return error; } @@ -455,30 +512,36 @@ ivas_error ivas_param_mc_dec_open_fx( ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, hParamMC->diff_proto_info->num_protos_diff, - DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, + hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ), + IVAS_ERR_OK ) ) { return error; } hParamMC->h_output_synthesis_params.use_onset_filters = 0; + move16(); hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; + move16(); } hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; + move16(); max_param_band_residual = 0; + move16(); - for ( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) + FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) { - if ( hParamMC->band_grouping[k] <= hParamMC->max_band_decorr ) + IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) ) { max_param_band_residual = k; + move16(); assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr ); break; } } /* output synthesis */ - if ( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -486,7 +549,10 @@ ivas_error ivas_param_mc_dec_open_fx( ivas_param_mc_dec_compute_interpolator_fx( 0, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hParamMC->h_output_synthesis_params.interpolator_fx ); /* Head or external rotation */ - if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + test(); + test(); + test(); + IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { IF( ( hParamMC->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL ) { @@ -499,7 +565,7 @@ ivas_error ivas_param_mc_dec_open_fx( * memory allocation *-----------------------------------------------------------------*/ - IF( GT_16( hParamMC->max_band_decorr, 0 ) ) + IF( hParamMC->max_band_decorr > 0 ) { IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { @@ -518,32 +584,36 @@ ivas_error ivas_param_mc_dec_open_fx( ivas_param_mc_dec_init_fx( hParamMC, nchan_transport, nchan_out_cov ); - IF( hParamMC->synthesis_conf != PARAM_MC_SYNTH_MONO_STEREO ) + IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { Word16 n_cldfb_slots; n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; + move16(); IF( st_ivas->hDecoderConfig->Opt_tsm ) { n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; + move16(); } - IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + Word16 cldfb_buf_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands ); + IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } - set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); - IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + set32_fx( hParamMC->Cldfb_RealBuffer_tc_fx, 0, cldfb_buf_size ); + IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_buf_size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } - set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + set32_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, 0, cldfb_buf_size ); - hParamMC->sz = n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands; + hParamMC->sz = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands ); + move16(); IF( st_ivas->hTcBuffer == NULL ) { - IF( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -556,7 +626,9 @@ ivas_error ivas_param_mc_dec_open_fx( } hParamMC->subframes_rendered = 0; + move16(); hParamMC->slots_rendered = 0; + move16(); st_ivas->hParamMC = hParamMC; return error; @@ -974,6 +1046,7 @@ static void ivas_param_mc_get_param_band_mapping( FOR( source_band_idx = 0; source_band_idx < n_source_bands; source_band_idx++ ) { /* find lowest corresponding source band*/ + test(); IF( LE_16( source_band_grouping[source_band_idx], lower ) && GE_16( source_band_grouping[source_band_idx + 1], lower ) ) { DO @@ -997,6 +1070,7 @@ static void ivas_param_mc_get_param_band_mapping( for ( source_band_idx = 0; source_band_idx < source_band_in_target_band_cnt; source_band_idx++ ) { parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx] = shl_sat( mult( parameter_band_mapping->source_band_factor_fx[target_band_idx][source_band_idx], norm_fac_fx ) /*Q10*/, 5 ); /*Q15*/ + move16(); } parameter_band_mapping->n_source_bands[target_band_idx] = source_band_in_target_band_cnt; move16(); @@ -1087,22 +1161,28 @@ ivas_error ivas_param_mc_dec_reconfig_fx( hParamMC = st_ivas->hParamMC; error = IVAS_ERR_OK; + move32(); /* save important config information from the previous state */ nchan_transport_old = st_ivas->nchan_transport; + move32(); num_param_bands_old = hParamMC->hMetadataPMC->num_parameter_bands; + move32(); /*-----------------------------------------------------------------* * prepare library opening *-----------------------------------------------------------------*/ output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); #ifndef FIX_901_PARAMMC_DEAD_CODE hTransportSetup = st_ivas->hTransSetup; #endif mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); + test(); IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); @@ -1110,24 +1190,33 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ELSE { nchan_out_cov = nchan_out_transport; + move16(); } st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); + move16(); config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate ); nchan_transport = st_ivas->nchan_transport; + move16(); SWITCH( nchan_transport ) { case 4: case 3: st_ivas->nCPE = 2; + move16(); st_ivas->nSCE = 0; + move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); BREAK; case 2: st_ivas->nCPE = 1; + move16(); st_ivas->nSCE = 0; + move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); BREAK; } @@ -1136,7 +1225,9 @@ ivas_error ivas_param_mc_dec_reconfig_fx( * set input parameters *-----------------------------------------------------------------*/ hParamMC->num_freq_bands = shr( add( (Word16) Mpy_32_32( output_Fs, INV_CLDFB_BANDWIDTH_Q31 << 1 ), 1 ), 1 ); + move16(); hParamMC->max_band_energy_compensation = hParamMC->num_freq_bands; + move16(); #ifndef FIX_901_PARAMMC_DEAD_CODE /* deallocate the full icc map, gets newly allocated in the metadata open function */ @@ -1176,6 +1267,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_param_mc_get_param_band_mapping( hParamMC->hMetadataPMC->num_parameter_bands, hParamMC->band_grouping, num_param_bands_old, band_grouping_old, ¶meter_band_mapping ); + test(); IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) ) { Word16 *ild_q_old_fx = hParamMC->icld_q_fx; @@ -1193,6 +1285,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( set16_fx( hParamMC->icc_q_fx, 0, hParamMC->hMetadataPMC->num_parameter_bands * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ); /*Q15*/ /* map old to new parameter banding, only for same number of TCs, needs some more thought for a changing number of TCs */ + test(); IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) ) { Word16 new_param_band_idx, param_idx, source_param_idx; @@ -1200,18 +1293,22 @@ ivas_error ivas_param_mc_dec_reconfig_fx( Word16 *p_icc_new_fx = hParamMC->icc_q_fx; Word16 *p_ild_new_fx = hParamMC->icld_q_fx; Word16 p_ild_new_e = 23; + move16(); Word16 p_ild_new_tmp; /* ICC */ num_param_lfe = hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe; + move16(); FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) { FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) { *p_icc_new_fx = 0; + move16(); FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { *p_icc_new_fx = add( *p_icc_new_fx, mult( icc_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx], parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); /*Q15*/ + move16(); } p_icc_new_fx++; } @@ -1219,17 +1316,21 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /* ILD */ num_param_lfe = hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe; + move16(); FOR( new_param_band_idx = 0; new_param_band_idx < hParamMC->hMetadataPMC->num_parameter_bands; new_param_band_idx++ ) { FOR( param_idx = 0; param_idx < num_param_lfe; param_idx++ ) { *p_ild_new_fx = 0; + move16(); FOR( source_param_idx = 0; source_param_idx < parameter_band_mapping.n_source_bands[new_param_band_idx]; source_param_idx++ ) { p_ild_new_tmp = extract_h( BASOP_util_Pow2( L_mult0( 10885 /*log2(10)/10*2^15*/, ild_q_old_fx[parameter_band_mapping.source_band_idx[new_param_band_idx][source_param_idx] * num_param_lfe + param_idx] ), 8, &p_ild_new_e ) ); *p_ild_new_fx = add( *p_ild_new_fx, mult( p_ild_new_tmp, parameter_band_mapping.source_band_factor_fx[new_param_band_idx][source_param_idx] ) ); + move16(); } *p_ild_new_fx = extract_l( L_shr( Mpy_32_16_1( L_add( BASOP_Util_Log2( *p_ild_new_fx ), L_add( 16 << Q25, p_ild_new_e << 25 ) ), 24660 ), 15 ) ); + move16(); p_ild_new_fx++; } } @@ -1242,9 +1343,12 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /* set max parameter band for abs cov */ k = 0; + move16(); WHILE( LE_16( hParamMC->band_grouping[k], PARAM_MC_MAX_BAND_ABS_COV_DEC ) ) { - hParamMC->max_param_band_abs_cov = ( k++ ); + hParamMC->max_param_band_abs_cov = k; + move16(); + k = add( k, 1 ); } /*-----------------------------------------------------------------* @@ -1262,22 +1366,14 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); } - IF( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } /* convert the ls conv dmx matrix into column order matrix format (nchan_out_cldfb x nchan_out) */ -#if 0 /*To be removed later*/ - free( hParamMC->ls_conv_dmx_matrix ); -#endif free( hParamMC->ls_conv_dmx_matrix_fx ); -#if 0 - IF ( ( hParamMC->ls_conv_dmx_matrix = (float *) malloc( nchan_out_transport * nchan_out_cov * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); - } -#endif + IF( ( hParamMC->ls_conv_dmx_matrix_fx = (Word32 *) malloc( nchan_out_transport * nchan_out_cov * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -1290,13 +1386,16 @@ ivas_error ivas_param_mc_dec_reconfig_fx( /* convert ParamMC parameter bands to SFB */ st_ivas->hLsSetUpConversion->sfbCnt = hParamMC->num_param_bands_synth; + move16(); FOR( k = 0; k <= hParamMC->num_param_bands_synth; k++ ) { - st_ivas->hLsSetUpConversion->sfbOffset[k] = PARAM_MC_BAND_TO_MDCT_BAND_RATIO * hParamMC->band_grouping[k]; + st_ivas->hLsSetUpConversion->sfbOffset[k] = imult1616( PARAM_MC_BAND_TO_MDCT_BAND_RATIO, hParamMC->band_grouping[k] ); + move16(); } FOR( ; k < MAX_SFB + 2; k++ ) { st_ivas->hLsSetUpConversion->sfbOffset[k] = 0; + move16(); } } @@ -1307,23 +1406,25 @@ ivas_error ivas_param_mc_dec_reconfig_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - hParamMC->proto_matrix_int_len = nchan_out_transport * nchan_transport; + hParamMC->proto_matrix_int_len = imult1616( nchan_out_transport, nchan_transport ); move16(); - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, nchan_transport * nchan_out_transport ); /*Q31*/ + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, hParamMC->proto_matrix_int_fx, hParamMC->proto_matrix_int_len ); /*Q31*/ } + test(); IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, -4 ); + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), -4 ); matrix_product_fx( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_cov, nchan_out_transport, 0, ivas_param_mc_conf[config_index].dmx_fac_fx, nchan_out_transport, nchan_transport, 0, proto_matrix_fx /*Q26*/ ); - Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, nchan_out_transport * nchan_out_cov, 4 ); + Scale_sig32( hParamMC->ls_conv_dmx_matrix_fx, imult1616( nchan_out_transport, nchan_out_cov ), 4 ); IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { proto_mtx_norm_fx = ONE_IN_Q26; - FOR( k = 0; k < nchan_transport * nchan_out_cov; k++ ) + move32(); + FOR( k = 0; k < imult1616( nchan_transport, nchan_out_cov ); k++ ) { proto_mtx_norm_fx = L_max( L_abs( proto_mtx_norm_fx ), L_abs( proto_matrix_fx[k] ) ); } @@ -1335,16 +1436,18 @@ ivas_error ivas_param_mc_dec_reconfig_fx( FOR( Word16 i = 0; i < nchan_out_cov; i++ ) { st_ivas->hLsSetUpConversion->dmxMtx_fx[k][i] = L_shl( Mpy_32_16_1( proto_matrix_fx[k * nchan_out_cov + i], (Word16) proto_mtx_norm_fx ), 4 ); + move32(); } } } } ELSE { - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, nchan_out_transport * nchan_transport ); - Scale_sig32( proto_matrix_fx, nchan_out_transport * nchan_transport, -5 ); + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); + Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); } + test(); IF( NE_16( nchan_transport_old, nchan_transport ) && NE_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { Word16 i; @@ -1392,6 +1495,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( } hParamMC->num_outputs_diff = nchan_out_cov; + move16(); IF( ( hParamMC->diff_proto_info = (PARAM_MC_DIFF_PROTO_INFO *) malloc( sizeof( PARAM_MC_DIFF_PROTO_INFO ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -1408,38 +1512,46 @@ ivas_error ivas_param_mc_dec_reconfig_fx( Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, hParamMC->num_freq_bands ); - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, - hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hParamMC->h_freq_domain_decorr_ap_params ), &( hParamMC->h_freq_domain_decorr_ap_state ), hParamMC->num_freq_bands, hParamMC->num_outputs_diff, + hParamMC->diff_proto_info->num_protos_diff, DIRAC_SYNTHESIS_COV_MC_LS, frequency_axis_fx, nchan_transport, output_Fs ) ), + IVAS_ERR_OK ) ) { return error; } hParamMC->h_output_synthesis_params.use_onset_filters = 0; + move16(); hParamMC->max_band_decorr = hParamMC->h_freq_domain_decorr_ap_params->max_band_decorr; + move16(); /* init decorrelation */ - IF( GT_16( hParamMC->max_band_decorr, 0 ) ) + IF( hParamMC->max_band_decorr > 0 ) { - len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; + len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr ); /* init onsetDetectionPower */ set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len ); set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len ); hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31; + move16(); } } hParamMC->max_band_energy_compensation = hParamMC->band_grouping[hParamMC->hMetadataPMC->nbands_coded]; + move16(); max_param_band_residual = 0; + move16(); FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) { IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) ) { max_param_band_residual = k; + move16(); assert( hParamMC->band_grouping[k] == hParamMC->max_band_decorr ); - break; + BREAK; } } + test(); IF( NE_16( nchan_transport_old, nchan_transport ) || NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) ) { DIRAC_OUTPUT_SYNTHESIS_COV_STATE cov_state_old = hParamMC->h_output_synthesis_cov_state; @@ -1450,8 +1562,9 @@ ivas_error ivas_param_mc_dec_reconfig_fx( set_zero_fx( tmp_buf_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); /* output synthesis */ - IF( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, - hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_cov_open_fx( &( hParamMC->h_output_synthesis_params ), &( hParamMC->h_output_synthesis_cov_state ), hParamMC->max_band_decorr, PARAM_MC_MAX_NSLOTS, + hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual, nchan_transport, nchan_out_cov, proto_matrix_fx ) ), + IVAS_ERR_OK ) ) { return error; } @@ -1461,6 +1574,7 @@ ivas_error ivas_param_mc_dec_reconfig_fx( ivas_dirac_dec_output_synthesis_cov_init_fx( &( hParamMC->h_output_synthesis_cov_state ), nchan_transport, nchan_out_cov, hParamMC->hMetadataPMC->num_parameter_bands, max_param_band_residual ); /* map old to new parameter banding, only for same number of TCs, needs some more thought for changing number of TCs */ + test(); IF( NE_16( num_param_bands_old, hParamMC->hMetadataPMC->num_parameter_bands ) && EQ_16( nchan_transport_old, nchan_transport ) ) { Word16 new_param_band_idx, source_param_idx; @@ -1497,14 +1611,15 @@ ivas_error ivas_param_mc_dec_reconfig_fx( * memory allocation *-----------------------------------------------------------------*/ - IF( GT_16( hParamMC->max_band_decorr, 0 ) && NE_16( nchan_transport_old, nchan_transport ) ) + test(); + IF( ( hParamMC->max_band_decorr > 0 ) && NE_16( nchan_transport_old, nchan_transport ) ) { free( hParamMC->proto_frame_f_fx ); IF( ( hParamMC->proto_frame_f_fx = (Word32 *) malloc( 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - set_zero_fx( hParamMC->proto_frame_f_fx, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); + set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) ); } @@ -1525,21 +1640,24 @@ ivas_error ivas_param_mc_dec_reconfig_fx( } n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; + move16(); IF( st_ivas->hDecoderConfig->Opt_tsm ) { n_cldfb_slots = MAX_JBM_CLDFB_TIMESLOTS; + move16(); } - IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + Word16 cldfb_size = imult1616( imult1616( n_cldfb_slots, nchan_transport ), hParamMC->num_freq_bands ); + IF( ( hParamMC->Cldfb_RealBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } - set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + set_zero_fx( hParamMC->Cldfb_RealBuffer_tc_fx, cldfb_size ); - IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands * sizeof( Word32 ) ) ) == NULL ) + IF( ( hParamMC->Cldfb_ImagBuffer_tc_fx = (Word32 *) malloc( cldfb_size * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC JBM\n" ) ); } - set_zero_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, n_cldfb_slots * nchan_transport * hParamMC->num_freq_bands ); + set_zero_fx( hParamMC->Cldfb_ImagBuffer_tc_fx, cldfb_size ); } ELSE { @@ -2416,13 +2534,18 @@ void ivas_param_mc_dec_read_BS_fx( IF( !st->bfi ) { - metadata_bit_pos = extract_l( ivas_total_brate / FRAMES_PER_SEC - 1 ); - bits_to_copy = s_min( extract_l( ivas_total_brate / FRAMES_PER_SEC ), PARAM_MC_MAX_BITS ); + /*metadata_bit_pos = extract_l(ivas_total_brate / FRAMES_PER_SEC - 1); + bits_to_copy = s_min(extract_l(ivas_total_brate / FRAMES_PER_SEC), PARAM_MC_MAX_BITS);*/ + Word16 temp = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + metadata_bit_pos = sub( temp, 1 ); + bits_to_copy = s_min( temp, PARAM_MC_MAX_BITS ); /* copy and reverse metadata */ FOR( bit_pos = 0; bit_pos < bits_to_copy; bit_pos++ ) { - bit_buffer[bit_pos] = st->bit_stream[metadata_bit_pos--]; + bit_buffer[bit_pos] = st->bit_stream[metadata_bit_pos]; + move16(); + metadata_bit_pos = sub( metadata_bit_pos, 1 ); move16(); } @@ -2480,8 +2603,37 @@ void ivas_param_mc_dec_read_BS_fx( band_step = PARAM_MC_TRANSIENT_BAND_STEP; move16(); - num_lfe_bands = add( PARAM_MC_MAX_BAND_LFE / band_step, ( PARAM_MC_MAX_BAND_LFE % band_step ) ? 1 : 0 ); - num_param_bands = add( hMetadataPMC->nbands_coded / band_step, ( ( hMetadataPMC->nbands_coded % band_step ) ? 1 : 0 ) ); + + /*num_lfe_bands = add(PARAM_MC_MAX_BAND_LFE / band_step, (PARAM_MC_MAX_BAND_LFE % band_step) ? 1 : 0); + num_param_bands = add(hMetadataPMC->nbands_coded / band_step, ((hMetadataPMC->nbands_coded % band_step) ? 1 : 0));*/ + Word16 temp_e; + temp = BASOP_Util_Divide3232_Scale( PARAM_MC_MAX_BAND_LFE, band_step, &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + Word16 temp1; + IF( PARAM_MC_MAX_BAND_LFE % band_step ) + { + temp1 = 1; + } + ELSE + { + temp1 = 0; + } + move16(); + num_lfe_bands = add( temp, temp1 ); + + temp = BASOP_Util_Divide3232_Scale( hMetadataPMC->nbands_coded, band_step, &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + Word16 temp2; + IF( hMetadataPMC->nbands_coded % band_step ) + { + temp2 = 1; + } + ELSE + { + temp2 = 0; + } + move16(); + num_param_bands = add( temp, temp2 ); } ELSE { @@ -2490,7 +2642,8 @@ void ivas_param_mc_dec_read_BS_fx( IF( EQ_16( param_frame_idx, hMetadataPMC->coding_band_mapping[j] ) ) { /* LFE ICC is always the last ICC in coding band 0 */ - num_lfe_bands++; + num_lfe_bands = add( num_lfe_bands, 1 ); + move16(); } } } @@ -2573,11 +2726,11 @@ void ivas_param_mc_dec_read_BS_fx( /* set LFE ILD and ICC to zero above PARAM_MC_MAX_BAND_LFE for attack frames */ IF( hMetadataPMC->bAttackPresent ) { - FOR( k = PARAM_MC_MAX_BAND_LFE; k < band_step * num_lfe_bands; k++ ) + FOR( k = PARAM_MC_MAX_BAND_LFE; k < imult1616( band_step, num_lfe_bands ); k++ ) { - hParamMC->icc_q_fx[( k + 1 ) * icc_map_size - 1] = 32767; /* 1.0f in Q15 */ + hParamMC->icc_q_fx[L_sub( L_mult0( add( k, 1 ), icc_map_size ), 1 )] = 32767; /* 1.0f in Q15 */ move16(); - hParamMC->icld_q_fx[( k + 1 ) * ild_map_size - 1] = PARAM_MC_DEFAULT_MIN_ILD_FX; /* -92.0f in Q8 */ + hParamMC->icld_q_fx[L_sub( L_mult0( add( k, 1 ), ild_map_size ), 1 )] = PARAM_MC_DEFAULT_MIN_ILD_FX; /* -92.0f in Q8 */ move16(); } } @@ -2844,31 +2997,34 @@ void ivas_param_mc_dec_digest_tc_fx( push_wmops( "param_mc_dec_digest_tc" ); - set_s( channel_active, 0, MAX_CICP_CHANNELS ); + set16_fx( channel_active, 0, MAX_CICP_CHANNELS ); nchan_transport = st_ivas->nchan_transport; - nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + move16(); + nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { nchan_out_cldfb = BINAURAL_CHANNELS; move16(); - set_s( channel_active, 1, nchan_out_cldfb ); - nchan_out_cov = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + set16_fx( channel_active, 1, nchan_out_cldfb ); + nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); hSynthesisOutputSetup = &st_ivas->hTransSetup; } - ELSE IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB ) + ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) { nchan_out_cov = nchan_out_transport; move16(); - nchan_out_cldfb = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); hSynthesisOutputSetup = &st_ivas->hTransSetup; } - ELSE IF( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { - nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); nchan_out_cldfb = nchan_out_cov; move16(); - set_s( channel_active, 1, nchan_out_cov ); + set16_fx( channel_active, 1, nchan_out_cov ); hSynthesisOutputSetup = &st_ivas->hOutSetup; } ELSE @@ -2877,14 +3033,15 @@ void ivas_param_mc_dec_digest_tc_fx( move16(); nchan_out_cldfb = nchan_out_transport; move16(); - set_s( channel_active, 1, nchan_out_cov ); + set16_fx( channel_active, 1, nchan_out_cov ); hSynthesisOutputSetup = &st_ivas->hTransSetup; } /* adapt transient position */ IF( hParamMC->hMetadataPMC->bAttackPresent ) { - hParamMC->hMetadataPMC->attackIndex = (int16_t) max( 0, hParamMC->hMetadataPMC->attackIndex + ( ( nCldfbSlots - DEFAULT_JBM_CLDFB_TIMESLOTS ) / 2 ) ); + hParamMC->hMetadataPMC->attackIndex = s_max( 0, add( hParamMC->hMetadataPMC->attackIndex, shr( sub( nCldfbSlots, DEFAULT_JBM_CLDFB_TIMESLOTS ), 1 ) ) ); + move16(); } /* adapt subframes */ hParamMC->num_slots = nCldfbSlots; @@ -2895,7 +3052,8 @@ void ivas_param_mc_dec_digest_tc_fx( move16(); ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes ); st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes; - mvs2s( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes ); + move16(); + Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes ); ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx ); @@ -2932,18 +3090,18 @@ void ivas_param_mc_dec_digest_tc_fx( move16(); cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout ); - Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); - Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); + Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); + Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); } hParamMC->Cldfb_ImagBuffer_tc_e = qout; move16(); } - IF( slot_idx >= 2 * hParamMC->hMetadataPMC->attackIndex ) + IF( GE_16( slot_idx, shl( hParamMC->hMetadataPMC->attackIndex, 1 ) ) ) { - ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6, - &hParamMC->Cldfb_ImagBuffer_tc_fx[slot_idx * hParamMC->num_freq_bands * nchan_transport], + &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6, cx_fx, &cx_e, @@ -2959,11 +3117,13 @@ void ivas_param_mc_dec_digest_tc_fx( FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { /* Cx for transport channels */ - FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) + FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) { real_part_fx = cx_fx[param_band_idx][i]; + move16(); imag_part_fx = cx_imag_fx[param_band_idx][i]; + move16(); cx_buff_e[param_band_idx][i] = cx_e; move16(); @@ -2972,8 +3132,9 @@ void ivas_param_mc_dec_digest_tc_fx( { L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx ); L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx ); - L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, cx_e + cx_e, L_tmp2, cx_imag_e + cx_imag_e, &tmp_e ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, add( cx_e, cx_e ), L_tmp2, add( cx_imag_e, cx_imag_e ), &tmp_e ); cx_fx[param_band_idx][i] = Sqrt32( L_tmp1, &tmp_e ); + move32(); cx_buff_e[param_band_idx][i] = tmp_e; move16(); } @@ -2993,21 +3154,24 @@ void ivas_param_mc_dec_digest_tc_fx( FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { /* Cx for transport channels */ - FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) + FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) { - IF( max_e < cx_buff_e[param_band_idx][i] ) - max_e = cx_buff_e[param_band_idx][i]; + IF( LT_16( max_e, cx_buff_e[param_band_idx][i] ) ) + { + max_e = cx_buff_e[param_band_idx][i]; + } } } FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { /* Cx for transport channels */ - FOR( i = 0; i < nchan_transport * nchan_transport; i++ ) + FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) { - cx_fx[param_band_idx][i] = L_shr( cx_fx[param_band_idx][i], max_e - cx_buff_e[param_band_idx][i] ); + cx_fx[param_band_idx][i] = L_shr( cx_fx[param_band_idx][i], sub( max_e, cx_buff_e[param_band_idx][i] ) ); + move32(); } } @@ -3017,12 +3181,14 @@ void ivas_param_mc_dec_digest_tc_fx( /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/ + test(); + test(); IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) ) { FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 ) { - v_add_fx( cx_fx[param_band_idx], cx_fx[param_band_idx + 1], cx_fx[param_band_idx], nchan_transport * nchan_transport ); - Copy32( cx_fx[param_band_idx], cx_fx[param_band_idx + 1], nchan_transport * nchan_transport ); + v_add_fx( cx_fx[param_band_idx], cx_fx[add( param_band_idx, 1 )], cx_fx[param_band_idx], imult1616( nchan_transport, nchan_transport ) ); + Copy32( cx_fx[param_band_idx], cx_fx[add( param_band_idx, 1 )], imult1616( nchan_transport, nchan_transport ) ); } } @@ -3321,23 +3487,30 @@ void ivas_param_mc_dec_render_fx( #endif UWord32 output_Fs; Word16 tmp_q = 0; + move16(); hParamMC = st_ivas->hParamMC; assert( hParamMC ); push_wmops( "param_mc_dec_render" ); - set_s( channel_active, 0, MAX_CICP_CHANNELS ); + set16_fx( channel_active, 0, MAX_CICP_CHANNELS ); nchan_transport = st_ivas->nchan_transport; - nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + move16(); + nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); #ifndef MSAN_FIX nchan_out_init = nchan_out_transport; + move16(); #endif output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); + + test(); + test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { nchan_out_cldfb = BINAURAL_CHANNELS; - set_s( channel_active, 1, nchan_out_cldfb ); + set16_fx( channel_active, 1, nchan_out_cldfb ); #ifndef MSAN_FIX IF( st_ivas->hCombinedOrientationData ) { @@ -3349,23 +3522,28 @@ void ivas_param_mc_dec_render_fx( ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) { nchan_out_cov = nchan_out_transport; + move16(); nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); } ELSE IF( EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) { nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); nchan_out_cldfb = nchan_out_cov; - set_s( channel_active, 1, nchan_out_cov ); + move16(); + set16_fx( channel_active, 1, nchan_out_cov ); } ELSE { nchan_out_cov = nchan_out_transport; + move16(); nchan_out_cldfb = nchan_out_transport; - set_s( channel_active, 1, nchan_out_cov ); + move16(); + set16_fx( channel_active, 1, nchan_out_cov ); } /* set everything to zero that will not be decoded */ nband_synth = hParamMC->band_grouping[hParamMC->num_param_bands_synth]; + move16(); #ifndef IVAS_FLOAT_FIXED nbands_to_zero = sub( hParamMC->num_freq_bands, nband_synth ); #endif @@ -3388,12 +3566,20 @@ void ivas_param_mc_dec_render_fx( } /* loop FOR synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min( sub( hParamMC->num_slots, hParamMC->slots_rendered ), nSamplesAsked / NS2SA( output_Fs, CLDFB_SLOT_NS ) ); - *nSamplesRendered = slots_to_render * NS2SA( output_Fs, CLDFB_SLOT_NS ); + /*slots_to_render = min(sub(hParamMC->num_slots, hParamMC->slots_rendered), nSamplesAsked / NS2SA(output_Fs, CLDFB_SLOT_NS)); + *nSamplesRendered = slots_to_render * NS2SA(output_Fs, CLDFB_SLOT_NS);*/ + Word16 temp_e; + Word16 temp = BASOP_Util_Divide1616_Scale( nSamplesAsked, NS2SA( output_Fs, CLDFB_SLOT_NS ), &temp_e ); + temp = shr( temp, sub( 15, temp_e ) ); + slots_to_render = s_min( sub( hParamMC->num_slots, hParamMC->slots_rendered ), temp ); + *nSamplesRendered = imult1616( slots_to_render, NS2SA( output_Fs, CLDFB_SLOT_NS ) ); + move16(); Word16 j, k; first_sf = hParamMC->subframes_rendered; + move16(); last_sf = first_sf; - WHILE( GT_16( slots_to_render, 0 ) ) + move16(); + WHILE( slots_to_render > 0 ) { slots_to_render = sub( slots_to_render, hParamMC->subframe_nbslots[last_sf] ); last_sf = add( last_sf, 1 ); @@ -3406,17 +3592,19 @@ void ivas_param_mc_dec_render_fx( } } slot_idx_start = hParamMC->slots_rendered; + move16(); slot_idx_start_cldfb_synth = 0; + move16(); Flag is_zero = 1; - move16(); + move32(); FOR( j = 0; j < st_ivas->hParamMC->hMetadataPMC->nbands_coded; j++ ) { is_zero = 1; move16(); FOR( i = 0; i < hParamMC->h_output_synthesis_cov_state.mixing_matrix_len; i++ ) { - IF( NE_32( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j][i], 0 ) ) + IF( hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[j][i] != 0 ) { is_zero = 0; move16(); @@ -3429,7 +3617,7 @@ void ivas_param_mc_dec_render_fx( } is_zero = 1; move16(); - IF( st_ivas->hParamMC->band_grouping[j] < st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( LT_16( st_ivas->hParamMC->band_grouping[j], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) ) { FOR( i = 0; i < hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len; i++ ) { @@ -3451,7 +3639,7 @@ void ivas_param_mc_dec_render_fx( { FOR( slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; ( slot_idx++, hParamMC->slots_rendered++ ) ) { - IF( GT_16( hParamMC->max_band_decorr, 0 ) ) + IF( hParamMC->max_band_decorr > 0 ) { /*-----------------------------------------------------------------* * protoype signal computation @@ -3460,7 +3648,7 @@ void ivas_param_mc_dec_render_fx( &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], hParamMC->proto_frame_f_fx, hParamMC->diff_proto_info, hParamMC->num_freq_bands ); - Scale_sig32( hParamMC->proto_frame_f_fx, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands, Q11 - Q5 ); + Scale_sig32( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ), Q11 - Q5 ); /*-----------------------------------------------------------------* * frequency domain decorrelation *-----------------------------------------------------------------*/ @@ -3487,10 +3675,12 @@ void ivas_param_mc_dec_render_fx( FOR( k = 0; k < nchan_out_cov; k++ ) { - FOR( int l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ ) + FOR( Word16 l = 0; l < hParamMC->h_output_synthesis_params.max_band_decorr; l++ ) { - Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], 6 - tmp_q ); - Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], 6 - tmp_q ); + Cldfb_RealBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_RealBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); + move32(); + Cldfb_ImagBuffer_fx[k][slot_idx][l] = L_shl( Cldfb_ImagBuffer_fx[k][slot_idx][l], sub( 6, tmp_q ) ); + move32(); } } } @@ -3499,17 +3689,21 @@ void ivas_param_mc_dec_render_fx( * output synthesis *-----------------------------------------------------------------*/ ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( - &hParamMC->Cldfb_RealBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], - &hParamMC->Cldfb_ImagBuffer_tc_fx[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, slot_idx + slot_idx_start, + &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( hParamMC->slots_rendered, nchan_transport ), hParamMC->num_freq_bands )], + &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( hParamMC->slots_rendered, nchan_transport ), hParamMC->num_freq_bands )], Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, slot_idx, add( slot_idx, slot_idx_start ), nchan_transport, nchan_out_cov, hParamMC ); + test(); IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { + test(); IF( st_ivas->hCombinedOrientationData && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { Word16 Q_Cldfb_ImagBuffer, Q_Cldfb_RealBuffer; - Q_Cldfb_ImagBuffer = sub( Q6, 5 ); /*max value =MAX_INTERN_CHANNELS(=16)*Cldfb_ImagBuffer_fx*/ - Q_Cldfb_RealBuffer = sub( Q6, 5 ); + Q_Cldfb_ImagBuffer = Q6 - 5; /*max value =MAX_INTERN_CHANNELS(=16)*Cldfb_ImagBuffer_fx*/ + move16(); + Q_Cldfb_RealBuffer = Q6 - 5; + move16(); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { FOR( j = 0; j < MAX_PARAM_SPATIAL_SUBFRAMES; j++ ) @@ -3540,8 +3734,9 @@ void ivas_param_mc_dec_render_fx( IF( st_ivas->hBinRenderer->render_lfe ) { Word16 tmp_exp = 0; + move16(); Word16 tmp = BASOP_Util_Divide1616_Scale( GAIN_LFE_FX, hLsSetup.nchan_out_woLFE, &tmp_exp ); - tmp_exp = tmp_exp + ( 1 - 15 ); + tmp_exp = add( tmp_exp, ( 1 - 15 ) ); FOR( idx_lfe = 0; idx_lfe < hLsSetup.num_lfe; idx_lfe++ ) { /* Copy just the first band of LFE*/ @@ -3562,11 +3757,14 @@ void ivas_param_mc_dec_render_fx( } idx_out = 0; + move16(); idx_lfe = 0; + move16(); FOR( ch = 0; ch < ( hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe ); ch++ ) { - IF( ( GT_16( hLsSetup.num_lfe, 0 ) ) && ( EQ_16( hLsSetup.index_lfe[idx_lfe], ch ) ) ) + test(); + IF( ( hLsSetup.num_lfe > 0 ) && EQ_16( hLsSetup.index_lfe[idx_lfe], ch ) ) { IF( LT_16( idx_lfe, ( sub( hLsSetup.num_lfe, 1 ) ) ) ) { @@ -3588,9 +3786,11 @@ void ivas_param_mc_dec_render_fx( } } + test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { Word16 input_q = 6; + move16(); /* Implement binaural rendering */ ivas_binRenderer_fx( st_ivas->hBinRenderer, st_ivas->hCombinedOrientationData, @@ -3611,9 +3811,9 @@ void ivas_param_mc_dec_render_fx( } } - FOR( int idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ ) + FOR( Word16 idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ ) { - FOR( int idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ ) + FOR( Word16 idx2 = 0; idx2 < hParamMC->subframe_nbslots[subframe_idx]; idx2++ ) { Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( Q6, input_q ) ); @@ -3652,16 +3852,16 @@ void ivas_param_mc_dec_render_fx( } } - Word16 len = slot_idx_start_cldfb_synth * hParamMC->num_freq_bands + hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx]; + Word16 len = add( imult1616( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands ), imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); scale_sig32( output_f_fx[ch], len, 5 - 11 ); - cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), - hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch] ); + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][L_mult0( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands )] ), + imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ), st_ivas->cldfbSynDec[ch] ); scale_sig32( output_f_fx[ch], len, 11 - 5 ); } ELSE { - set32_fx( &( output_f_fx[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands] ), 0, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx] ); + set32_fx( &( output_f_fx[ch][L_mult0( slot_idx_start_cldfb_synth, hParamMC->num_freq_bands )] ), 0, imult1616( hParamMC->num_freq_bands, hParamMC->subframe_nbslots[subframe_idx] ) ); } } slot_idx_start = add( slot_idx_start, hParamMC->subframe_nbslots[subframe_idx] ); @@ -3677,16 +3877,20 @@ void ivas_param_mc_dec_render_fx( IF( EQ_16( hParamMC->slots_rendered, hParamMC->num_slots ) ) { hParamMC->hMetadataPMC->last_coded_bwidth = hParamMC->hMetadataPMC->coded_bwidth; + move16(); param_mc_update_mixing_matrices_fx( hParamMC, hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_transport, nchan_out_cov ); } hParamMC->subframes_rendered = last_sf; - *nSamplesAvailableNext = ( hParamMC->num_slots - hParamMC->slots_rendered ) * NS2SA( output_Fs, CLDFB_SLOT_NS ); + move16(); + *nSamplesAvailableNext = imult1616( sub( hParamMC->num_slots, hParamMC->slots_rendered ), NS2SA( output_Fs, CLDFB_SLOT_NS ) ); + move16(); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { channel_active_fx[i] = channel_active[i]; + move16(); } pop_wmops(); @@ -4036,17 +4240,19 @@ static void ivas_param_mc_dec_init_fx( *-----------------------------------------------------------------*/ /* decorrelation */ - IF( GT_16( hParamMC->max_band_decorr, 0 ) ) + IF( hParamMC->max_band_decorr > 0 ) { - len = hParamMC->diff_proto_info->num_protos_diff * hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; + len = imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr ); /* init onsetDetectionPower */ set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx, len ); set_zero_fx( hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx, len ); hParamMC->h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = Q31; + move16(); } max_param_band_residual = 0; + move16(); /* output synthesis */ FOR( k = hParamMC->hMetadataPMC->num_parameter_bands; k >= 0; k-- ) @@ -4054,7 +4260,8 @@ static void ivas_param_mc_dec_init_fx( IF( LE_16( hParamMC->band_grouping[k], hParamMC->max_band_decorr ) ) { max_param_band_residual = k; - break; + move16(); + BREAK; } } @@ -4064,10 +4271,10 @@ static void ivas_param_mc_dec_init_fx( * init proto frames *-----------------------------------------------------------------*/ - IF( GT_16( hParamMC->max_band_decorr, 0 ) ) + IF( hParamMC->max_band_decorr > 0 ) { - set_zero_fx( hParamMC->proto_frame_f_fx, 2 * hParamMC->diff_proto_info->num_protos_diff * hParamMC->num_freq_bands ); - set32_fx( hParamMC->proto_frame_dec_f_fx, 0, 2 * nchan_cov * hParamMC->num_freq_bands ); + set_zero_fx( hParamMC->proto_frame_f_fx, shl( imult1616( hParamMC->diff_proto_info->num_protos_diff, hParamMC->num_freq_bands ), 1 ) ); + set32_fx( hParamMC->proto_frame_dec_f_fx, 0, shl( imult1616( nchan_cov, hParamMC->num_freq_bands ), 1 ) ); } return; @@ -4195,7 +4402,7 @@ static void param_mc_protoSignalComputation_fx( Word32 *p_real_buffer_fx; // Q12 Word32 *p_imag_buffer_fx; // Q12 - set32_fx( proto_frame_f_fx, 0, 2 * num_freq_bands * diff_proto_info->num_protos_diff ); + set32_fx( proto_frame_f_fx, 0, shl( imult1616( num_freq_bands, diff_proto_info->num_protos_diff ), 1 ) ); FOR( proto_ch_idx = 0; proto_ch_idx < diff_proto_info->num_protos_diff; proto_ch_idx++ ) @@ -4212,9 +4419,9 @@ static void param_mc_protoSignalComputation_fx( Word16 source_ch_idx = diff_proto_info->source_chan_idx[proto_ch_idx][source_ch_cnt]; move16(); - p_proto_frame_fx = &proto_frame_f_fx[proto_ch_idx * num_freq_bands * 2]; - p_real_buffer_fx = &RealBuffer_fx[source_ch_idx * num_freq_bands]; - p_imag_buffer_fx = &ImagBuffer_fx[source_ch_idx * num_freq_bands]; + p_proto_frame_fx = &proto_frame_f_fx[shl( imult1616( proto_ch_idx, num_freq_bands ), 1 )]; + p_real_buffer_fx = &RealBuffer_fx[imult1616( source_ch_idx, num_freq_bands )]; + p_imag_buffer_fx = &ImagBuffer_fx[imult1616( source_ch_idx, num_freq_bands )]; FOR( band = 0; band < num_freq_bands; band++ ) { @@ -4258,7 +4465,9 @@ static void ivas_param_mc_dec_copy_diffuse_proto( Word16 num_freq_bands, num_freq_bands_diff; Word32 *p_proto_diff_fx; num_freq_bands = hParamMC->num_freq_bands; + move16(); num_freq_bands_diff = hParamMC->h_output_synthesis_params.max_band_decorr; + move16(); FOR( k = 0; k < nY; k++ ) { @@ -4267,7 +4476,9 @@ static void ivas_param_mc_dec_copy_diffuse_proto( FOR( l = 0; l < num_freq_bands_diff; l++ ) { Cldfb_buffer_real_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + move32(); Cldfb_buffer_imag_fx[k][slot_idx][l] = *( p_proto_diff_fx++ ); + move32(); } } @@ -4309,6 +4520,26 @@ static void ivas_param_mc_dec_copy_diffuse_proto( * decode a number of bits to an integer *------------------------------------------------------------------------*/ /* r : decoded integer */ +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_param_mc_bin2dec_fx( + UWord16 bits[PARAM_MC_MAX_BITS], /* i : bit buffer */ + const Word16 N /* i : number of bits to decode */ +) +{ + Word16 i; + Word16 out; + + assert( N <= 16 ); + out = 0; + move16(); + FOR( i = 0; i < N; i++ ) + { + out = add( out, shl( bits[i], sub( sub( N, 1 ), i ) ) ); + } + + return out; +} +#else static int16_t ivas_param_mc_bin2dec( uint16_t bits[PARAM_MC_MAX_BITS], /* i : bit buffer */ const int16_t N /* i : number of bits to decode */ @@ -4326,7 +4557,7 @@ static int16_t ivas_param_mc_bin2dec( return out; } - +#endif /*------------------------------------------------------------------------- * ivas_param_mc_uniform_decoder() @@ -4347,12 +4578,14 @@ static Word16 ivas_param_mc_uniform_decoder_fx( Word16 n_bits; n_bits = 0; + move16(); assert( N * sz_seq < PARAM_MC_MAX_BITS ); FOR( i = 0; i < sz_seq; ++i ) { - idx = ivas_param_mc_bin2dec( &bit_buffer[i * N], N ); + idx = ivas_param_mc_bin2dec_fx( &bit_buffer[i * N], N ); seq[i] = alphabet[idx]; + move16(); } n_bits = imult1616( N, sz_seq ); @@ -4393,8 +4626,8 @@ static int16_t ivas_param_mc_uniform_decoder( * * decode a sequency of inidices coded with a range coder *------------------------------------------------------------------------*/ - -static Word16 ivas_param_mc_range_decoder_LC( +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_param_mc_range_decoder_LC_fx( UWord16 *bit_buffer, /* i : bit buffer to read from */ Word16 *x, /* o : decoded indices */ Word16 *BER_detect, /* o : flag for indicating a bit error */ @@ -4414,28 +4647,75 @@ static Word16 ivas_param_mc_range_decoder_LC( /* Start Decoding */ /* Initialize range decoder */ cur_bit_pos = 0; -#ifdef IVAS_FLOAT_FIXED - rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ -#else - rc_uni_dec_init( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ -#endif // IVAS_FLOAT_FIXED + move16(); + rc_uni_dec_init_fx( &rc_st_dec, bit_buffer, sub( nbbits, 32 ) ); /* (nbbits + 30) entries are read by the decoder */ /* Main Loop through the indices */ FOR( k = 0; k < sz_seq; k++ ) { -#ifdef IVAS_FLOAT_FIXED r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*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} */ + + /* Update bitstream pointer */ + cur_bit_pos = rc_uni_dec_virtual_finish( &rc_st_dec ); + + /* Confirm that there is no overflow */ + IF( GT_16( cur_bit_pos, nbbits ) ) + { + *BER_detect = s_or( *BER_detect, 1 ); + move16(); + } + + x[k] = r; + move16(); + } + + /* 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 */ + IF( rc_st_dec.bit_error_detected != 0 ) + { + *BER_detect = s_or( *BER_detect, 1 ); + move16(); + } + + return cur_bit_pos; +} #else +static int16_t ivas_param_mc_range_decoder_LC( + uint16_t *bit_buffer, /* i : bit buffer to read from */ + int16_t *x, /* o : decoded indices */ + int16_t *BER_detect, /* o : flag for indicating a bit error */ + const int16_t sz_seq, /* i : size of the sequence to be decoded */ + const int16_t sz_alphabet, /* i : size of the alphabet */ + const uint16_t *cft, /* i : cumulative frequency table */ + const uint16_t *sft, /* i : symbol frequency table */ + const int16_t tot_shift, /* i : total frequency as a power of 2 */ + const int16_t nbbits /* i : maximum bit budget */ +) +{ + RangeUniDecState rc_st_dec; /* State of the range decoder */ + int16_t cur_bit_pos; + int16_t k; + int16_t r; + + /* Start Decoding */ + /* Initialize range decoder */ + cur_bit_pos = 0; + rc_uni_dec_init( &rc_st_dec, bit_buffer, nbbits - 32 ); /* (nbbits + 30) entries are read by the decoder */ + + /* Main Loop through the indices */ + for ( k = 0; k < sz_seq; k++ ) + { r = rc_uni_dec_read_symbol_fastS( &rc_st_dec, cft, sft, sz_alphabet, tot_shift ); /*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} */ -#endif // IVAS_FLOAT_FIXED /* Update bitstream pointer */ cur_bit_pos = rc_uni_dec_virtual_finish( &rc_st_dec ); /* Confirm that there is no overflow */ - IF( cur_bit_pos > nbbits ) + if ( cur_bit_pos > nbbits ) { *BER_detect |= 1; } @@ -4447,14 +4727,14 @@ static Word16 ivas_param_mc_range_decoder_LC( /*st->next_bit_pos = rc_uni_dec_finish(&rc_st_dec);*/ /* Check for bitstream errors */ - IF( rc_st_dec.bit_error_detected != 0 ) + if ( rc_st_dec.bit_error_detected != 0 ) { *BER_detect |= 1; } return cur_bit_pos; } - +#endif /*------------------------------------------------------------------------- * param_mc_compute_interpolator() @@ -4474,7 +4754,7 @@ static void ivas_param_mc_dec_compute_interpolator_fx( IF( bAttackPresent ) { - FOR( idx = 0; idx < 2 * attackPos; idx++ ) + FOR( idx = 0; idx < shl( attackPos, 1 ); idx++ ) { interpolator[idx] = 0; move16(); @@ -4581,11 +4861,11 @@ static void remove_lfe_from_cy_fx( ptrCy = cy; ptrCy_out = cy_woLFE; - FOR( lfe_idx1 = 0; lfe_idx1 < num_lfe + 1; lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < add( num_lfe, 1 ); lfe_idx1++ ) { FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR( lfe_idx2 = 0; lfe_idx2 < num_lfe + 1; lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < add( num_lfe, 1 ); lfe_idx2++ ) { FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { @@ -4991,10 +5271,6 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word16 remove_lfe; Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP]; - nY_band = nY_cov; - num_lfe_bands = 0; - remove_lfe = 0; - Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; @@ -5021,6 +5297,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( Word16 tmp_e, tmp; Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e; + move16(); Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; @@ -5041,6 +5318,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); #endif Word16 proto_matrix_noLFE_e = 0; + move16(); Word16 guard_bit_cx = find_guarded_bits_fx( nY_intern + 1 ); Word16 guard_bit_cy = find_guarded_bits_fx( nY_cov * nY_cov ); @@ -5051,18 +5329,23 @@ static void ivas_param_mc_get_mixing_matrices_fx( Copy32( Cx_in_fixed[i], Cx_in_fx[i], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); nY_band = nY_cov; + move16(); num_lfe_bands = 0; + move16(); remove_lfe = 0; + move16(); - set_s( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP ); + set16_fx( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP ); IF( hSynthesisOutputSetup->num_lfe ) { Word32 *proto_matrix_ptr_in_fx; FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ ) { lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1]; + move16(); } - lfe_indices[hSynthesisOutputSetup->num_lfe + 1] = nY_cov; + lfe_indices[add( hSynthesisOutputSetup->num_lfe, 1 )] = nY_cov; + move16(); proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0]; proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0]; proto_matrix_noLFE_e = proto_matrix_e; @@ -5072,11 +5355,12 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) { - FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ ); + move32(); } proto_matrix_ptr_in_fx++; } @@ -5087,9 +5371,10 @@ static void ivas_param_mc_get_mixing_matrices_fx( move16(); } - IF( hParamMC->hMetadataPMC->lfe_on ) + if ( hParamMC->hMetadataPMC->lfe_on ) { num_lfe_bands = PARAM_MC_MAX_BAND_LFE; + move16(); } FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) @@ -5098,7 +5383,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( { remove_lfe = 1; move16(); - nY_band = nY_cov - hSynthesisOutputSetup->num_lfe; + nY_band = sub( nY_cov, hSynthesisOutputSetup->num_lfe ); proto_matrix_ptr_fx = proto_matrix_noLFE_fx; proto_matrix_ptr_e = proto_matrix_noLFE_e; move16(); @@ -5126,18 +5411,16 @@ static void ivas_param_mc_get_mixing_matrices_fx( Cx_state_e = Cx_in_e; move16(); matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx ); - mat_mult_buffer1_e = hParamMC->proto_matrix_int_e + Cx_in_e; + mat_mult_buffer1_e = add( hParamMC->proto_matrix_int_e, Cx_in_e ); matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx ); - Cproto_e = mat_mult_buffer1_e + hParamMC->proto_matrix_int_e; - move16(); - + Cproto_e = add( mat_mult_buffer1_e, hParamMC->proto_matrix_int_e ); FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ ) { - IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[ch_idx1 + ch_idx1 * nY_intern], Cproto_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )], Cproto_e, 0, 0 ) < 0 ) { - Cproto_fx[ch_idx1 + ch_idx1 * nY_intern] = 0; + Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )] = 0; move32(); } } @@ -5147,8 +5430,8 @@ static void ivas_param_mc_get_mixing_matrices_fx( move16(); ivas_param_mc_dequantize_cov_fx( hParamMC, - hParamMC->icld_q_fx + param_band_idx * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe, - hParamMC->icc_q_fx + param_band_idx * hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe, + hParamMC->icld_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ), + hParamMC->icc_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ), param_band_idx, nY_cov, synth_config, nY_intern, @@ -5160,8 +5443,8 @@ static void ivas_param_mc_get_mixing_matrices_fx( IF( hParamMC->hMetadataPMC->bAttackPresent ) { /* no smoothing on attacks */ - Copy32( Cx_state_fx, Cx_fx, nX * nX ); - Copy32( Cy_state_fx, Cy_full_fx, nY_cov * nY_cov ); + Copy32( Cx_state_fx, Cx_fx, imult1616( nX, nX ) ); + Copy32( Cy_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) ); Cy_full_e = Cy_state_e; move16(); Cx_e = Cx_state_e; @@ -5172,29 +5455,34 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* smoothing gains are now identical to one, simply add up */ // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov ); - tmp_e = max( hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_state_e ) + guard_bit_cx; + tmp_e = add( s_max( hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_state_e ), guard_bit_cx ); FOR( i = 0; i < nX * nX; i++ ) { - Cx_old_state_fx[i] = L_shr( Cx_old_state_fx[i], tmp_e - hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] ); - Cx_state_fx[i] = L_shr( Cx_state_fx[i], tmp_e - Cx_state_e ); + Cx_old_state_fx[i] = L_shr( Cx_old_state_fx[i], sub( tmp_e, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] ) ); + move32(); + Cx_state_fx[i] = L_shr( Cx_state_fx[i], sub( tmp_e, Cx_state_e ) ); + move32(); } hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = tmp_e; + move16(); Cx_state_e = tmp_e; move16(); - tmp_e = max( hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_state_e ) + guard_bit_cy; - FOR( i = 0; i < nY_cov * nY_cov; i++ ) + tmp_e = add( s_max( hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_state_e ), guard_bit_cy ); + FOR( i = 0; i < imult1616( nY_cov, nY_cov ); i++ ) { - Cy_old_state_fx[i] = L_shr( Cy_old_state_fx[i], tmp_e - hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] ); - Cy_state_fx[i] = L_shr( Cy_state_fx[i], tmp_e - Cy_state_e ); + Cy_old_state_fx[i] = L_shr( Cy_old_state_fx[i], sub( tmp_e, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] ) ); + move32(); + Cy_state_fx[i] = L_shr( Cy_state_fx[i], sub( tmp_e, Cy_state_e ) ); + move32(); } hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = tmp_e; Cy_state_e = tmp_e; move16(); - v_add_32( Cx_state_fx, Cx_old_state_fx, Cx_fx, nX * nX ); - v_add_32( Cy_state_fx, Cy_old_state_fx, Cy_full_fx, nY_cov * nY_cov ); + v_add_32( Cx_state_fx, Cx_old_state_fx, Cx_fx, imult1616( nX, nX ) ); + v_add_32( Cy_state_fx, Cy_old_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) ); Cy_full_e = Cy_state_e; move16(); @@ -5202,21 +5490,21 @@ static void ivas_param_mc_get_mixing_matrices_fx( move16(); } - Copy32( Cx_state_fx, Cx_old_state_fx, nX * nX ); + Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) ); - Copy32( Cy_state_fx, Cy_old_state_fx, nY_cov * nY_cov ); + Copy32( Cy_state_fx, Cy_old_state_fx, imult1616( nY_cov, nY_cov ) ); Word16 new_e = 0; - + move16(); hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = Cx_state_e; move16(); hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e; move16(); - FOR( i = 0; i < nX * nX; i++ ) + FOR( i = 0; i < imult1616( nX, nX ); i++ ) { - IF( NE_32( Cx_old_state_fx[i], 0 ) ) + if ( Cx_old_state_fx[i] != 0 ) { new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx]; move16(); @@ -5229,9 +5517,9 @@ static void ivas_param_mc_get_mixing_matrices_fx( new_e = 0; move16(); - FOR( i = 0; i < nY_cov * nY_cov; i++ ) + FOR( i = 0; i < imult1616( nY_cov, nY_cov ); i++ ) { - IF( NE_32( Cy_old_state_fx[i], 0 ) ) + if ( Cy_old_state_fx[i] != 0 ) { new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx]; move16(); @@ -5250,41 +5538,45 @@ static void ivas_param_mc_get_mixing_matrices_fx( } ELSE { - Copy32( Cy_full_fx, Cy_fx, nY_band * nY_band ); + Copy32( Cy_full_fx, Cy_fx, imult1616( nY_band, nY_band ) ); Cy_e = Cy_full_e; move16(); } matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx ); - mat_mult_buffer1_e = proto_matrix_ptr_e + Cx_e; + mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e ); - Word16 guard_bits = find_guarded_bits_fx( nY_band + 1 ); + Word16 guard_bits = find_guarded_bits_fx( add( nY_band, 1 ) ); - FOR( i = 0; i < nY_band * nX; ++i ) + FOR( i = 0; i < imult1616( nY_band, nX ); ++i ) { proto_matrix_ptr_fx[i] = L_shr( proto_matrix_ptr_fx[i], guard_bits ); + move32(); mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); + move32(); } - proto_matrix_ptr_e += guard_bits; - mat_mult_buffer1_e += guard_bits; + proto_matrix_ptr_e = add( proto_matrix_ptr_e, guard_bits ); + mat_mult_buffer1_e = add( mat_mult_buffer1_e, guard_bits ); matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e ); - FOR( i = 0; i < nY_band * nX; ++i ) + FOR( i = 0; i < imult1616( nY_band, nX ); ++i ) { proto_matrix_ptr_fx[i] = L_shl( proto_matrix_ptr_fx[i], guard_bits ); + move32(); mat_mult_buffer1_fx[i] = L_shl( mat_mult_buffer1_fx[i], guard_bits ); + move32(); } - proto_matrix_ptr_e -= guard_bits; - mat_mult_buffer1_e -= guard_bits; + proto_matrix_ptr_e = sub( proto_matrix_ptr_e, guard_bits ); + mat_mult_buffer1_e = sub( mat_mult_buffer1_e, guard_bits ); /* make sure we have no negative entries in Cproto_diag due to rounding errors */ FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ ) { - IF( BASOP_Util_Cmp_Mant32Exp( Cproto_diag_fx[ch_idx1], Cproto_diag_e, 0, 0 ) < 0 ) + if ( BASOP_Util_Cmp_Mant32Exp( Cproto_diag_fx[ch_idx1], Cproto_diag_e, 0, 0 ) < 0 ) { Cproto_diag_fx[ch_idx1] = 0; move16(); @@ -5295,7 +5587,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( /* Computing the mixing matrices */ /* bands with decorr */ - IF( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) { computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 0, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e ); /* Compute mixing matrix FOR residual */ @@ -5303,19 +5595,20 @@ static void ivas_param_mc_get_mixing_matrices_fx( IF( remove_lfe ) { - set_zero_fx( mixing_matrix_res_fx[param_band_idx], nY_cov * nY_cov ); + set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) ); ptrMM_fx = mixing_matrix_res_local_fx; ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx]; - FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) { - FOR( ch_idx1 = lfe_indices[lfe_idx1] + 1; ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) + FOR( ch_idx1 = add( lfe_indices[lfe_idx1], 1 ); ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) { - FOR( lfe_idx2 = 0; lfe_idx2 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx2++ ) + FOR( lfe_idx2 = 0; lfe_idx2 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx2++ ) { - FOR( ch_idx2 = lfe_indices[lfe_idx2] + 1; ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) + FOR( ch_idx2 = add( lfe_indices[lfe_idx2], 1 ); ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) { *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); + move32(); } ptrMM_out_fx++; } @@ -5328,7 +5621,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( } ELSE { - Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], nY_cov * nY_cov ); + Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) ); mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e; move16(); } @@ -5344,7 +5637,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( i = 0; i < nY_band; i++ ) { tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e ); - tmp_e = Cy_diag_e + Cproto_diag_e; + tmp_e = add( Cy_diag_e, Cproto_diag_e ); L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e ); Cy_diag_fx[i] = L_tmp; move32(); @@ -5358,13 +5651,17 @@ static void ivas_param_mc_get_mixing_matrices_fx( FOR( i = 1; i < nY_band; i++ ) { - IF( Cy_diag_e < Cy_diag_buff_e[i] ) - Cy_diag_e = Cy_diag_buff_e[i]; + if ( LT_16( Cy_diag_e, Cy_diag_buff_e[i] ) ) + { + Cy_diag_e = Cy_diag_buff_e[i]; + move16(); + } } FOR( i = 0; i < nY_band; i++ ) { - Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], Cy_diag_e - Cy_diag_buff_e[i] ); + Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], sub( Cy_diag_e, Cy_diag_buff_e[i] ) ); + move32(); } diag_matrix_product_fx( Cy_diag_fx, Cy_diag_e, nY_band, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e ); @@ -5372,16 +5669,17 @@ static void ivas_param_mc_get_mixing_matrices_fx( IF( remove_lfe ) { - set_zero_fx( mixing_matrix_fx[param_band_idx], nX * nY_cov ); + set_zero_fx( mixing_matrix_fx[param_band_idx], imult1616( nX, nY_cov ) ); ptrMM_fx = mixing_matrix_local_fx; ptrMM_out_fx = mixing_matrix_fx[param_band_idx]; FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) { - FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe + 1; lfe_idx1++ ) + FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) { - FOR( ch_idx2 = lfe_indices[lfe_idx1] + 1; ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) { *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); + move32(); } ptrMM_out_fx++; } @@ -5393,7 +5691,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( } ELSE { - Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], nY_cov * nX ); + Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], imult1616( nY_cov, nX ) ); mixing_matrix_e[param_band_idx] = mixing_matrix_local_e; move16(); } @@ -5626,15 +5924,19 @@ static void param_mc_update_mixing_matrices_fx( Word16 brange[2]; brange[0] = hParamMC->band_grouping[param_band_idx]; - brange[1] = hParamMC->band_grouping[param_band_idx + 1]; + move16(); + brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; + move16(); - Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], nX * nY ); + Copy32( mixing_matrix[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nX, nY ) ); hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = mixing_matrix_exp[param_band_idx]; + move16(); - IF( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) + IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) { - Copy32( mixing_matrix_res[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], nY * nY ); + Copy32( mixing_matrix_res[param_band_idx], hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nY, nY ) ); hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = mixing_matrix_res_exp[param_band_idx]; + move16(); } } @@ -5869,18 +6171,23 @@ static void ivas_param_mc_dequantize_cov_fx( /*get back Nrg*/ tmp = 0; + move16(); FOR( k = 0; k < nY_int; k++ ) { Word32 ref_ener_fx = 0; + move32(); Word16 ref_ener_e = 0; + move16(); Word16 ref_channel_cnt; Word16 ref_channel_idx; FOR( ref_channel_cnt = 0; ref_channel_cnt < h_ild_mapping->num_ref_channels[k]; ref_channel_cnt++ ) { ref_channel_idx = h_ild_mapping->ref_channel_idx[k][ref_channel_cnt]; - ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[ref_channel_idx + ref_channel_idx * nX], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e ); + move16(); + ref_ener_fx = BASOP_Util_Add_Mant32Exp( Cx_state_fx[add( ref_channel_idx, imult1616( ref_channel_idx, nX ) )], Cx_state_e, ref_ener_fx, ref_ener_e, &ref_ener_e ); + move32(); } L_tmp = Mpy_32_16_1( 713378626, ild_q_fx[k] ); /*Q24 : L_tmp Q31 for log2(10)/10 -> 713378626 */ @@ -5898,12 +6205,12 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( k = 0; k < nY_int; k++ ) { // a_fx[k] = 1.f / ( sqrtf( Cproto_fx[k + nY_int * k] ) + EPSILON ); - tmp_e = Cp_buf_e[k + nY_int * k]; + tmp_e = Cp_buf_e[add( k, imult1616( nY_int, k ) )]; move16(); - IF( NE_32( Cproto_fx[k + nY_int * k], 0 ) ) + IF( NE_32( Cproto_fx[add( k, imult1616( nY_int, k ) )], 0 ) ) { - L_tmp = ISqrt32( Cproto_fx[k + nY_int * k], &tmp_e ); + L_tmp = ISqrt32( Cproto_fx[add( k, imult1616( nY_int, k ) )], &tmp_e ); } ELSE { @@ -5919,9 +6226,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_int; l++ ) { - Cy_state_int_fx[k * nY_int + l] = Mpy_32_32( Cproto_fx[k * nY_int + l], a_fx[k] ); + Cy_state_int_fx[add( imult1616( k, nY_int ), l )] = Mpy_32_32( Cproto_fx[add( imult1616( k, nY_int ), l )], a_fx[k] ); move32(); - Cy_state_int_e[k * nY_int + l] = add( Cp_buf_e[k * nY_int + l], a_e[k] ); + Cy_state_int_e[add( imult1616( k, nY_int ), l )] = add( Cp_buf_e[add( imult1616( k, nY_int ), l )], a_e[k] ); move16(); } } @@ -5938,7 +6245,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_int; l++ ) { ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx ); + move32(); *Cyp_e = add( *Cyp_e, ap_e ); + move16(); Cyp_fx += nY_int; Cyp_e += nY_int; @@ -5972,18 +6281,17 @@ static void ivas_param_mc_dequantize_cov_fx( } test(); - test(); - IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || EQ_16( hParamMC->hMetadataPMC->lfe_on, 0 ) ) + IF( GE_16( param_band_index, PARAM_MC_MAX_BAND_LFE ) || ( hParamMC->hMetadataPMC->lfe_on == 0 ) ) { FOR( k = 0; k < nY_int; k++ ) { - Cy_state_int_fx[k + 3 * nY_int] = ONE_IN_Q31; + Cy_state_int_fx[add( k, imult1616( 3, nY_int ) )] = ONE_IN_Q31; move32(); - Cy_state_int_e[k + 3 * nY_int] = 0; + Cy_state_int_e[add( k, imult1616( 3, nY_int ) )] = 0; move16(); - Cy_state_int_fx[3 + k * nY_int] = ONE_IN_Q31; + Cy_state_int_fx[add( 3, imult1616( k, nY_int ) )] = ONE_IN_Q31; move32(); - Cy_state_int_e[3 + k * nY_int] = 0; + Cy_state_int_e[add( 3, imult1616( k, nY_int ) )] = 0; move16(); } Nrqq_fx[3] = 0; @@ -6003,9 +6311,9 @@ static void ivas_param_mc_dequantize_cov_fx( /* v_multc( Cy_state_int_fx + k * nY_int, a_fx[k], Cy_state_int_fx + k * nY_int, nY_int ) */ FOR( l = 0; l < nY_int; l++ ) { - Cy_state_int_fx[k * nY_int + l] = Mpy_32_32( Cy_state_int_fx[k * nY_int + l], a_fx[k] ); + Cy_state_int_fx[add( imult1616( k, nY_int ), l )] = Mpy_32_32( Cy_state_int_fx[add( imult1616( k, nY_int ), l )], a_fx[k] ); move32(); - Cy_state_int_e[k * nY_int + l] = add( Cy_state_int_e[k * nY_int + l], a_e[k] ); + Cy_state_int_e[add( imult1616( k, nY_int ), l )] = add( Cy_state_int_e[add( imult1616( k, nY_int ), l )], a_e[k] ); move16(); } } @@ -6022,7 +6330,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_int; l++ ) { ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx ); + move32(); ( *Cyp_e ) = add( *Cyp_e, ap_e ); + move16(); Cyp_fx += nY_int; Cyp_e += nY_int; @@ -6057,8 +6367,8 @@ static void ivas_param_mc_dequantize_cov_fx( { FOR( l = 0; l < nY_int; l++ ) { - L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[k + l * nY_cov], Nrqq_fx[l] ); - tmp_e = add( ls_conv_dmx_matrix_e[k + l * nY_cov], Nrqq_e[l] ); + L_tmp = Mpy_32_32( hParamMC->ls_conv_dmx_matrix_fx[add( k, imult1616( l, nY_cov ) )], Nrqq_fx[l] ); + tmp_e = add( ls_conv_dmx_matrix_e[add( k, imult1616( l, nY_cov ) )], Nrqq_e[l] ); L_tmp = BASOP_Util_Add_Mant32Exp( target_ch_ener_fx[k], target_ch_ener_e[k], L_tmp, tmp_e, &tmp_e ); target_ch_ener_fx[k] = L_tmp; move32(); @@ -6066,12 +6376,12 @@ static void ivas_param_mc_dequantize_cov_fx( move16(); } - dmx_ch_ener_fx[k] = Cy_state_fx[k + nY_cov * k]; + dmx_ch_ener_fx[k] = Cy_state_fx[add( k, imult1616( nY_cov, k ) )]; move32(); - IF( dmx_ch_ener_fx[k] < 0.0f ) + IF( dmx_ch_ener_fx[k] < 0 ) { - Cy_state_fx[k + nY_cov * k] = L_negate( Cy_state_fx[k + nY_cov * k] ); + Cy_state_fx[add( k, imult1616( nY_cov, k ) )] = L_negate( Cy_state_fx[add( k, imult1616( nY_cov, k ) )] ); move32(); dmx_ch_ener_fx[k] = L_negate( dmx_ch_ener_fx[k] ); move32(); @@ -6086,7 +6396,7 @@ static void ivas_param_mc_dequantize_cov_fx( } ELSE { - BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[k + nY_cov * k], &tmp, &tmp_e ); + BASOP_Util_Divide_MantExp( extract_h( target_ch_ener_fx[k] ), target_ch_ener_e[k], extract_h( dmx_ch_ener_fx[k] ), Cy_buf_e[add( k, imult1616( nY_cov, k ) )], &tmp, &tmp_e ); tmp = Sqrt16( tmp, &tmp_e ); target_ch_ener_fx[k] = L_deposit_h( tmp ); move32(); @@ -6096,9 +6406,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_cov; l++ ) { - Cy_state_fx[k * nY_cov + l] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[k * nY_cov + l] ); + Cy_state_fx[add( imult1616( k, nY_cov ), l )] = Mpy_32_32( target_ch_ener_fx[k], Cy_state_fx[add( imult1616( k, nY_cov ), l )] ); move32(); - Cy_buf_e[k * nY_cov + l] = add( target_ch_ener_e[k], Cy_buf_e[k * nY_cov + l] ); + Cy_buf_e[add( imult1616( k, nY_cov ), l )] = add( target_ch_ener_e[k], Cy_buf_e[add( imult1616( k, nY_cov ), l )] ); move16(); } @@ -6111,7 +6421,9 @@ static void ivas_param_mc_dequantize_cov_fx( FOR( l = 0; l < nY_cov; l++ ) { ( *Cyp_fx ) = Mpy_32_32( *Cyp_fx, ap_fx ); + move32(); *Cyp_e = add( *Cyp_e, ap_e ); + move16(); Cyp_fx += nY_cov; Cyp_e += nY_cov; @@ -6120,21 +6432,21 @@ static void ivas_param_mc_dequantize_cov_fx( } ELSE { - Copy32( Cy_state_int_fx, Cy_state_fx, nY_int * nY_int ); - Copy( Cy_state_int_e, Cy_buf_e, nY_int * nY_int ); + Copy32( Cy_state_int_fx, Cy_state_fx, imult1616( nY_int, nY_int ) ); + Copy( Cy_state_int_e, Cy_buf_e, imult1616( nY_int, nY_int ) ); } /*normalize output matrix to a common exponent*/ tmp = 0; - FOR( k = 0; k < nY_int * nY_int; k++ ) + FOR( k = 0; k < imult1616( nY_int, nY_int ); k++ ) { Cy_state_fx[k] = BASOP_Util_Add_Mant32Exp( Cy_state_fx[k], Cy_buf_e[k], 0, 0, &Cy_buf_e[k] ); move32(); tmp = s_max( tmp, Cy_buf_e[k] ); } - FOR( k = 0; k < nY_int * nY_int; k++ ) + FOR( k = 0; k < imult1616( nY_int, nY_int ); k++ ) { - L_tmp = L_shr( Cy_state_fx[k], tmp - Cy_buf_e[k] ); + L_tmp = L_shr( Cy_state_fx[k], sub( tmp, Cy_buf_e[k] ) ); Cy_state_fx[k] = L_tmp; move32(); } @@ -6192,6 +6504,7 @@ static void param_mc_set_num_synth_bands( } move16(); hParamMC->num_param_bands_synth = s_min( hParamMC->hMetadataPMC->nbands_coded, max_param_band_synth ); + move16(); return; } @@ -6261,24 +6574,25 @@ static ivas_error param_mc_get_diff_proto_info_fx( float proto_fac[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; #endif Word32 proto_fac_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; - uint16_t cur_out_ch; - uint16_t cur_diff_proto; - uint16_t cur_transport_ch; - uint16_t max_num_src_chan; + UWord16 cur_out_ch; + UWord16 cur_diff_proto; + UWord16 cur_transport_ch; + UWord16 max_num_src_chan; /* Initializations */ max_num_src_chan = 0; + move16(); #if FLT_ENABLE set_zero( proto_fac, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); #endif set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); - if ( ( p_diff_proto_info->proto_index_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ) ) == NULL ) + IF( ( p_diff_proto_info->proto_index_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } set16_fx( p_diff_proto_info->proto_index_diff, 0, nchan_out_cov ); - if ( ( p_diff_proto_info->num_source_chan_diff = (int16_t *) malloc( nchan_out_cov * sizeof( int16_t ) ) ) == NULL ) + IF( ( p_diff_proto_info->num_source_chan_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } @@ -6286,18 +6600,21 @@ static ivas_error param_mc_get_diff_proto_info_fx( /* we have at least one prototype, copy the first one */ p_diff_proto_info->num_protos_diff = 1; + move16(); #if FLT_ENABLE mvr2r_inc( proto_mtx, nchan_out_cov, proto_fac, nchan_out_cov, nchan_transport ); #endif mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport ); p_diff_proto_info->proto_index_diff[0] = 0; + move16(); /* search for distinct prototypes */ - for ( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ ) + FOR( cur_out_ch = 1; cur_out_ch < nchan_out_cov; cur_out_ch++ ) { - uint16_t found = 0; + UWord16 found = 0; + move16(); - for ( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) + FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) { #if FLT_ENABLE float diff = 0; @@ -6305,16 +6622,17 @@ static ivas_error param_mc_get_diff_proto_info_fx( // const float *proto_mtx_ptr = proto_mtx + cur_out_ch; #endif Word32 diff_fx = 0; + move32(); Word32 *proto_fac_ptr_fx = proto_fac_fx + cur_diff_proto; const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch; - for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) + FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) { #if FLT_ENABLE diff += fabsf( *proto_fac_ptr - *proto_mtx_ptr ); proto_fac_ptr += nchan_out_cov; proto_mtx_ptr += nchan_out_cov; #endif - diff_fx += L_abs( *proto_fac_ptr_fx - *proto_mtx_ptr ); + diff_fx = L_add( diff_fx, L_abs( L_sub( *proto_fac_ptr_fx, *proto_mtx_ptr ) ) ); proto_fac_ptr_fx += nchan_out_cov; proto_mtx_ptr += nchan_out_cov; } @@ -6323,31 +6641,34 @@ static ivas_error param_mc_get_diff_proto_info_fx( #if FLT_ENABLE if ( diff < 0.1f ) #else - if ( LT_64( diff_fx * 10, L_shl_sat( 1, Q_proto_mtx ) ) ) + IF( LT_64( W_mult0_32_32( diff_fx, 10 ), L_shl_sat( 1, Q_proto_mtx ) ) ) #endif { found = 1; + move16(); p_diff_proto_info->proto_index_diff[cur_out_ch] = cur_diff_proto; - break; + move16(); + BREAK; } } /* new distinct prototype, add it */ - if ( found == 0 ) + IF( found == 0 ) { #if FLT_ENABLE const float *proto_mtx_ptr = proto_mtx + cur_out_ch; #else const Word32 *proto_mtx_ptr = proto_mtx + cur_out_ch; #endif - int16_t cur_num_src_chan; + Word16 cur_num_src_chan; cur_num_src_chan = 0; - for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) + move16(); + FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) { - if ( *proto_mtx_ptr > EPSILON ) + IF( GT_32( *proto_mtx_ptr, 0 /*EPSILON*/ ) ) { - cur_num_src_chan++; + cur_num_src_chan = add( cur_num_src_chan, 1 ); } proto_mtx_ptr += nchan_out_cov; } @@ -6358,13 +6679,13 @@ static ivas_error param_mc_get_diff_proto_info_fx( mvr2r_inc_fixed( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac_fx + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport ); #endif p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff; - p_diff_proto_info->num_protos_diff++; + p_diff_proto_info->num_protos_diff = add( p_diff_proto_info->num_protos_diff, 1 ); max_num_src_chan = s_max( max_num_src_chan, cur_num_src_chan ); } } /* set up the prototype info struct */ - if ( ( p_diff_proto_info->source_chan_idx = (int16_t **) malloc( p_diff_proto_info->num_protos_diff * sizeof( int16_t * ) ) ) == NULL ) + IF( ( p_diff_proto_info->source_chan_idx = (Word16 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word16 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } @@ -6374,40 +6695,42 @@ static ivas_error param_mc_get_diff_proto_info_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #endif - if ( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL ) + IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } - for ( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) + FOR( cur_diff_proto = 0; cur_diff_proto < p_diff_proto_info->num_protos_diff; cur_diff_proto++ ) { #if FLT_ENABLE float *proto_fac_ptr; #endif Word32 *proto_fac_ptr; - if ( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (int16_t *) malloc( max_num_src_chan * sizeof( int16_t ) ) ) == NULL ) + IF( ( p_diff_proto_info->source_chan_idx[cur_diff_proto] = (Word16 *) malloc( max_num_src_chan * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #if 1 /*To be removed later*/ - if ( ( p_diff_proto_info->proto_fac[cur_diff_proto] = (float *) malloc( max_num_src_chan * sizeof( float ) ) ) == NULL ) + IF( ( p_diff_proto_info->proto_fac[cur_diff_proto] = (float *) malloc( max_num_src_chan * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } #endif - if ( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL ) + IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } proto_fac_ptr = proto_fac_fx + cur_diff_proto; - for ( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) + FOR( cur_transport_ch = 0; cur_transport_ch < nchan_transport; cur_transport_ch++ ) { - if ( *proto_fac_ptr > EPSILON_FX_SMALL ) + IF( GT_32( *proto_fac_ptr, EPSILON_FX_SMALL ) ) { p_diff_proto_info->source_chan_idx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = cur_transport_ch; + move16(); p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = *proto_fac_ptr; - p_diff_proto_info->num_source_chan_diff[cur_diff_proto]++; + move16(); + p_diff_proto_info->num_source_chan_diff[cur_diff_proto] = add( p_diff_proto_info->num_source_chan_diff[cur_diff_proto], 1 ); } proto_fac_ptr += nchan_out_cov; } @@ -6602,18 +6925,24 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( Word16 dequant_ordered_fx[PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE]; Word16 n_lfe_idx; - range_coding = bit_buffer[( *bit_pos )++]; + range_coding = bit_buffer[*bit_pos]; + move16(); + *bit_pos = add( *bit_pos, 1 ); + move16(); /* Decoding the sequence */ n_lfe_idx = sub( map_size, map_size_wo_lfe ); sz_seq = add( imult1616( num_param_bands, map_size_wo_lfe ), imult1616( num_lfe_bands, n_lfe_idx ) ); - set_s( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE ); + set16_fx( idx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE ); set16_fx( dequant_ordered_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE ); set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE ); IF( range_coding ) { - delta_coding = bit_buffer[( *bit_pos )++]; + delta_coding = bit_buffer[*bit_pos]; + move16(); + *bit_pos = add( *bit_pos, 1 ); + move16(); IF( delta_coding ) { @@ -6622,28 +6951,33 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( idx_offset = sub( hParamCodingInfo->quantizer_size, 1 ); /* read range coded delta ICC indices */ - *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC( &bit_buffer[*bit_pos], delta_idx, BER_detect, sz_seq, sz_alphabet, - hParamCodingInfo->cum_freq_delta, hParamCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, max_bits - *bit_pos ) ); + *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], delta_idx, BER_detect, sz_seq, sz_alphabet, + hParamCodingInfo->cum_freq_delta, hParamCodingInfo->sym_freq_delta, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) ); + move16(); /* delta index to absolute index */ FOR( j = 0; j < sz_seq; j++ ) { idx[j] = add( idx_prev, sub( delta_idx[j], idx_offset ) ); idx_prev = idx[j]; + move16(); } } ELSE { /* read range coded absolute ICC indices */ sz_alphabet = hParamCodingInfo->quantizer_size; - *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC( &bit_buffer[*bit_pos], idx, BER_detect, sz_seq, sz_alphabet, - hParamCodingInfo->cum_freq, hParamCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, max_bits - *bit_pos ) ); + move16(); + *bit_pos = add( *bit_pos, ivas_param_mc_range_decoder_LC_fx( &bit_buffer[*bit_pos], idx, BER_detect, sz_seq, sz_alphabet, + hParamCodingInfo->cum_freq, hParamCodingInfo->sym_freq, PARAM_MC_RANGE_CODER_TOT_SHIFT, sub( max_bits, *bit_pos ) ) ); + move16(); } /* dequantize */ FOR( j = 0; j < sz_seq; j++ ) { dequant_seq_fx[j] = hParamCodingInfo->quantizer_fx[idx[j]]; + move16(); } } ELSE @@ -6651,6 +6985,7 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( set16_fx( dequant_seq_fx, 0, PARAM_MC_MAX_PARAMETER_BANDS * PARAM_MC_MAX_VAL_MAP_SIZE ); /* read uniformly coded ICCs */ *bit_pos = add( *bit_pos, ivas_param_mc_uniform_decoder_fx( dequant_seq_fx, sz_seq, hParamCodingInfo->quantizer_fx, hParamCodingInfo->uni_bits, &bit_buffer[*bit_pos] ) ); + move16(); } /* reorder from sequential to parameter-band-wise */ @@ -6659,7 +6994,9 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( { FOR( i = 0; i < num_param_bands; ++i ) { - dequant_ordered_fx[j + i * map_size] = dequant_seq_fx[k++]; + dequant_ordered_fx[add( j, imult1616( i, map_size ) )] = dequant_seq_fx[k]; + move16(); + k = add( k, 1 ); } } @@ -6667,7 +7004,9 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( { FOR( j = 0; j < n_lfe_idx; j++ ) { - dequant_ordered_fx[map_size - n_lfe_idx + j + i * map_size] = dequant_seq_fx[k++]; + dequant_ordered_fx[add( add( sub( map_size, n_lfe_idx ), j ), imult1616( i, map_size ) )] = dequant_seq_fx[k]; + move16(); + k = add( k, 1 ); } } @@ -6676,14 +7015,15 @@ static void ivas_param_mc_bs_decode_parameter_values_fx( j = 0; FOR( k = 0; k < hMetadataPMC->nbands_coded; k += band_step ) { + test(); IF( hMetadataPMC->bAttackPresent || EQ_16( hMetadataPMC->param_frame_idx, hMetadataPMC->coding_band_mapping[k] ) ) { - Copy( dequant_ordered_fx + j * map_size, value_buffer + k * map_size, map_size ); + Copy( dequant_ordered_fx + imult1616( j, map_size ), value_buffer + imult1616( k, map_size ), map_size ); j++; } IF( hMetadataPMC->bAttackPresent && k + 1 < hMetadataPMC->nbands_coded ) { - Copy( value_buffer + k * map_size, value_buffer + ( k + 1 ) * map_size, map_size ); + Copy( value_buffer + imult1616( k, map_size ), value_buffer + imult1616( add( k, 1 ), map_size ), map_size ); } } } diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 43dfffa4e..b8d3fac66 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -56,21 +56,21 @@ *-----------------------------------------------------------------------*/ /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */ -const int16_t MC_PARAMUPMIX_CHIDX1[MC_PARAMUPMIX_COMBINATIONS] = { 0, 1, 4, 5 }; -const int16_t MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 }; +const Word16 MC_PARAMUPMIX_CHIDX1[MC_PARAMUPMIX_COMBINATIONS] = { 0, 1, 4, 5 }; +const Word16 MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 }; /*-----------------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------------*/ -static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 *param_interpol_fx, const int16_t ch, const int16_t slots_rendered ); +static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 *param_interpol_fx, const Word16 ch, const Word16 slots_rendered ); static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, Word32 *output_fx[MAX_OUTPUT_CHANNELS] ); -static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering ); +static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const Word16 nSamplesForRendering ); -static int16_t huff_read( Decoder_State *st, const int16_t ( *ht )[2] ); +static Word16 huff_read( Decoder_State *st, const Word16 ( *ht )[2] ); static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, Word32 *vq ); @@ -102,6 +102,7 @@ void ivas_mc_paramupmix_dec_read_BS( push_wmops( "mc_paramupmix_read_bs" ); *nb_bits = 0; + move16(); IF( st0->bfi ) { @@ -111,16 +112,22 @@ void ivas_mc_paramupmix_dec_read_BS( { hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; + move32(); + move32(); } } hMCParamUpmix->first_frame = 1; + move16(); } ELSE /* IF (!st->bfi) */ { bit_stream_orig = st0->bit_stream; next_bit_pos_orig = st0->next_bit_pos; - last_bit_pos = (Word16) L_sub( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ), 1 ); + move16(); + Word32 L_temp = Mpy_32_32( st_ivas->hDecoderConfig->ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ); + last_bit_pos = extract_l( L_sub( L_temp, 1 ) ); nb_bits_read_orig = 0; + move16(); last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /* reverse the bitstream for easier reading of indices */ FOR( i = 0; i < s_min( MAX_BITS_METADATA, last_bit_pos ); i++ ) { @@ -128,8 +135,11 @@ void ivas_mc_paramupmix_dec_read_BS( } st0->bit_stream = bstr_meta; st0->next_bit_pos = 0; + move16(); st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) ); + move16(); st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ + move32(); FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { @@ -138,8 +148,10 @@ void ivas_mc_paramupmix_dec_read_BS( get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas_fx[i] ); } *nb_bits = add( *nb_bits, st0->next_bit_pos ); + move16(); st0->bit_stream = bit_stream_orig; st0->next_bit_pos = next_bit_pos_orig; + move16(); IF( hMCParamUpmix->first_frame ) { @@ -149,6 +161,7 @@ void ivas_mc_paramupmix_dec_read_BS( Copy32( hMCParamUpmix->betas_fx[i], hMCParamUpmix->beta_prev_fx[i], IVAS_MAX_NUM_BANDS ); } hMCParamUpmix->first_frame = 0; + move16(); } } @@ -193,16 +206,16 @@ void ivas_mc_paramupmix_dec_digest_tc( *------------------------------------------------------------------------*/ void ivas_mc_paramupmix_dec_render( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ - uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ - uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *input_fx[], /* i : core-coder transport channels */ - Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ + UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ + UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ + Word32 *input_fx[], /* i : core-coder transport channels */ + Word32 *output_fx[] /* i/o: synthesized core-coder transport channels */ ) { - int16_t slots_to_render, first_sf, last_sf, subframe_idx; - uint16_t slot_size, ch; + Word16 slots_to_render, first_sf, last_sf, subframe_idx; + UWord16 slot_size, ch; Word32 *output_local_fx[MAX_OUTPUT_CHANNELS]; MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; @@ -211,44 +224,48 @@ void ivas_mc_paramupmix_dec_render( push_wmops( "ivas_mc_paramupmix_dec_render" ); - for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) + FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { output_local_fx[ch] = output_fx[ch]; } slot_size = st_ivas->hTcBuffer->n_samples_granularity; + move16(); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = min( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size ); - *nSamplesRendered = slots_to_render * slot_size; + slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); + *nSamplesRendered = imult1616( slots_to_render, (Word16) slot_size ); + move16(); first_sf = st_ivas->hTcBuffer->subframes_rendered; + move16(); last_sf = first_sf; + move16(); - for ( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ ) + FOR( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ ) { Copy32( input_fx[ch], output_local_fx[ch], *nSamplesRendered ); } - while ( slots_to_render > 0 ) + WHILE( slots_to_render > 0 ) { - slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf]; - last_sf++; + slots_to_render = sub( slots_to_render, st_ivas->hTcBuffer->subframe_nbslots[last_sf] ); + last_sf = add( last_sf, 1 ); } { - for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Copy32( hMCParamUpmix->alpha_prev_fx[ch], hMCParamUpmix->alpha_sf_fx[ch], IVAS_MAX_NUM_BANDS ); Copy32( hMCParamUpmix->beta_prev_fx[ch], hMCParamUpmix->beta_sf_fx[ch], IVAS_MAX_NUM_BANDS ); } - for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { - int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx]; + Word16 n_samples_sf = imult1616( (Word16) slot_size, st_ivas->hTcBuffer->subframe_nbslots[subframe_idx] ); ivas_mc_paramupmix_dec_sf( st_ivas, output_local_fx ); - for ( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ ) + FOR( ch = 0; ch < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ ) { output_local_fx[ch] += n_samples_sf; } @@ -256,14 +273,15 @@ void ivas_mc_paramupmix_dec_render( /* update combined orientation access index */ ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); } - for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Copy32( hMCParamUpmix->alphas_fx[ch], hMCParamUpmix->alpha_prev_fx[ch], IVAS_MAX_NUM_BANDS ); Copy32( hMCParamUpmix->betas_fx[ch], hMCParamUpmix->beta_prev_fx[ch], IVAS_MAX_NUM_BANDS ); } } - *nSamplesAvailable = ( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered ) * slot_size; + *nSamplesAvailable = imult1616( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), (Word16) slot_size ); + move16(); pop_wmops(); return; @@ -287,7 +305,7 @@ ivas_error ivas_mc_paramupmix_dec_open( ivas_error error; error = IVAS_ERR_OK; - + move32(); /*-----------------------------------------------------------------* * prepare library opening @@ -298,16 +316,23 @@ ivas_error ivas_mc_paramupmix_dec_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param-Upmix MC\n" ) ); } output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); hMCParamUpmix->first_frame = 1; + move16(); st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); nchan_transport = st_ivas->nchan_transport; + move16(); SWITCH( nchan_transport ) { case 8: st_ivas->nCPE = 4; + move16(); st_ivas->nSCE = 0; + move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); BREAK; } @@ -317,9 +342,9 @@ ivas_error ivas_mc_paramupmix_dec_open( * set input parameters *-----------------------------------------------------------------*/ - hMCParamUpmix->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + hMCParamUpmix->num_freq_bands = (Word16) Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 ); - for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { ivas_td_decorr_dec_open_fx( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 ); } @@ -347,16 +372,18 @@ ivas_error ivas_mc_paramupmix_dec_open( /* allocate transport channels*/ hMCParamUpmix->free_param_interpolator = 0; + move16(); IF( ( hMCParamUpmix->param_interpolator_fx = (Word16 *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) ); } hMCParamUpmix->free_param_interpolator = 1; + move16(); ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator_fx ); - if ( st_ivas->hTcBuffer == NULL ) + IF( st_ivas->hTcBuffer == NULL ) { int16_t nchan_to_allocate; int16_t nchan_tc; @@ -365,19 +392,27 @@ ivas_error ivas_mc_paramupmix_dec_open( buffer_mode = TC_BUFFER_MODE_RENDERER; nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas ); nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; + move16(); - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) + test(); + test(); + test(); + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { buffer_mode = TC_BUFFER_MODE_BUFFER; + move32(); nchan_tc = st_ivas->hDecoderConfig->nchan_out; + move16(); nchan_to_allocate = nchan_tc; + move16(); } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; + move16(); } - if ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -398,31 +433,31 @@ void ivas_mc_paramupmix_dec_close( MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle */ ) { - int16_t i; + Word16 i; - if ( hMCParamUpmix == NULL || *hMCParamUpmix == NULL ) + IF( hMCParamUpmix == NULL || *hMCParamUpmix == NULL ) { return; } - for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) ); } - for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ ) + FOR( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ ) { IF( ( *hMCParamUpmix )->pcm_delay_fx[i] != NULL ) { free( ( *hMCParamUpmix )->pcm_delay_fx[i] ); } } - if ( ( *hMCParamUpmix )->param_interpolator_fx != NULL ) + IF( ( *hMCParamUpmix )->param_interpolator_fx != NULL ) { - if ( ( *hMCParamUpmix )->free_param_interpolator == 1 ) + IF( EQ_16( ( *hMCParamUpmix )->free_param_interpolator, 1 ) ) { free( ( *hMCParamUpmix )->param_interpolator_fx ); } } - if ( ( *hMCParamUpmix )->hoa_encoder_fx != NULL ) + IF( ( *hMCParamUpmix )->hoa_encoder_fx != NULL ) { free( ( *hMCParamUpmix )->hoa_encoder_fx ); ( *hMCParamUpmix )->hoa_encoder_fx = NULL; @@ -446,18 +481,18 @@ static void paramupmix_td_decorr_process_jbm_fx( Word32 *pcm_in[], /* i : input audio channels */ Word32 **pp_out_pcm, /* o : output audio channels */ const Word16 output_frame, /* i : output frame length */ - Word32 *q_format ) + Word16 *q_format ) { Word16 j, k; Word16 offset; Word32 in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; - offset = (Word16) ( output_frame / 10 ); + offset = idiv1616( output_frame, 10 ); /* Look-ahead delay */ FOR( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ ) { - mvl2l( pcm_in[k], pp_out_pcm[k], output_frame ); + Copy32( pcm_in[k], pp_out_pcm[k], output_frame ); delay_signal_fx( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset ); /* In ducking gains */ @@ -468,8 +503,10 @@ static void paramupmix_td_decorr_process_jbm_fx( FOR( j = 0; j < output_frame; j++ ) { pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], in_duck_gain[j] ); + move16(); } - q_format[k] -= Q1; + q_format[k] = sub( q_format[k], Q1 ); + move16(); } /* All pass delay section */ @@ -481,8 +518,10 @@ static void paramupmix_td_decorr_process_jbm_fx( FOR( j = 0; j < output_frame; j++ ) { pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], out_duck_gain[j] ); + move32(); } - q_format[k] -= Q1; + q_format[k] = sub( q_format[k], Q1 ); + move16(); } } @@ -498,13 +537,13 @@ static void paramupmix_td_decorr_process_jbm_fx( static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - const int16_t nSamplesForRendering ) + const Word16 nSamplesForRendering ) { MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; Word32 *pPcm_tmp_fx[MC_PARAMUPMIX_COMBINATIONS]; Word32 *p_tc_fx[MC_PARAMUPMIX_COMBINATIONS]; - int16_t nchan_internal, ch; - int16_t nSamplesLeftForTD, default_frame; + Word16 nchan_internal, ch; + Word16 nSamplesLeftForTD, default_frame; hMCParamUpmix = st_ivas->hMCParamUpmix; assert( hMCParamUpmix ); @@ -512,41 +551,44 @@ static void ivas_param_upmix_dec_decorr_subframes( push_wmops( "ivas_param_upmix_dec_decorr_subframes" ); /* TD decorrelator */ - default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); nSamplesLeftForTD = nSamplesForRendering; + move16(); nchan_internal = MC_PARAMUPMIX_COMBINATIONS; + move16(); - for ( ch = 0; ch < nchan_internal; ch++ ) + FOR( ch = 0; ch < nchan_internal; ch++ ) { - pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 8]; - p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 4]; + pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, 8 )]; + p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[add( ch, 4 )]; } - while ( nSamplesLeftForTD ) + WHILE( nSamplesLeftForTD ) { - int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame ); + Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); { - Word32 i, q_format[MC_PARAMUPMIX_COMBINATIONS]; + Word16 i, q_format[MC_PARAMUPMIX_COMBINATIONS]; FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { q_format[i] = Q11; + move16(); } paramupmix_td_decorr_process_jbm_fx( hMCParamUpmix->hTdDecorr, p_tc_fx, pPcm_tmp_fx, nSamplesToDecorr, q_format ); FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { - Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, Q11 - extract_l( q_format[i] ) ); + Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); } } - for ( ch = 0; ch < nchan_internal; ch++ ) + FOR( ch = 0; ch < nchan_internal; ch++ ) { p_tc_fx[ch] += nSamplesToDecorr; } - nSamplesLeftForTD -= nSamplesToDecorr; + nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); } pop_wmops(); @@ -566,11 +608,11 @@ static void ps_pred_process_sf( Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */ Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 *param_interpol_fx, - const int16_t ch, - const int16_t slots_rendered ) + const Word16 ch, + const Word16 slots_rendered ) { Word32 vmre_fx, vmim_fx, vsre_fx, vsim_fx; - int16_t iqmf, ipar, ismp, iismp; + Word16 iqmf, ipar, ismp, iismp; Word32 alpha_smp_fx, beta_smp_fx; Word32 *alpha1_fx, *alpha2_fx; Word32 *beta1_fx, *beta2_fx; @@ -582,7 +624,7 @@ static void ps_pred_process_sf( Word16 ifac_fx; Word32 alpha_start_fx[IVAS_MAX_NUM_BANDS], beta_start_fx[IVAS_MAX_NUM_BANDS]; Word32 res_a, res_b; - const int16_t qmf_to_par_band[] = { + const Word16 qmf_to_par_band[] = { 0, 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, @@ -593,27 +635,33 @@ static void ps_pred_process_sf( Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS ); - for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ ) + FOR( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ ) { ipar = qmf_to_par_band[iqmf]; + move16(); alpha1_fx = alpha_prev_fx; + move16(); beta1_fx = beta_prev_fx; + move16(); ismp = 0; alpha2_fx = hMCParamUpmix->alphas_fx[ch]; beta2_fx = hMCParamUpmix->betas_fx[ch]; alpha_smp_fx = alpha_start_fx[ipar]; + move32(); beta_smp_fx = beta_start_fx[ipar]; + move32(); - for ( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ ) + FOR( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ ) { - if ( ( slots_rendered == 0 ) && ( iismp == 0 ) ) + IF( ( slots_rendered == 0 ) && ( iismp == 0 ) ) { ifac_fx = param_interpol_fx[iismp]; + move16(); } - else + ELSE { - ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[iismp - 1] ); + ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[sub( iismp, 1 )] ); } dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); dbeta_fx = Mpy_32_16_1( L_sub( beta2_fx[ipar], beta1_fx[ipar] ), ifac_fx ); @@ -622,9 +670,13 @@ static void ps_pred_process_sf( beta_smp_fx = L_add( dbeta_fx, beta_smp_fx ); vmre_fx = qmf_mod_re_fx[ismp][iqmf]; + move32(); vmim_fx = qmf_mod_im_fx[ismp][iqmf]; + move32(); vsre_fx = qmf_side_re_fx[ismp][iqmf]; + move32(); vsim_fx = qmf_side_im_fx[ismp][iqmf]; + move32(); res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); @@ -634,10 +686,12 @@ static void ps_pred_process_sf( res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); - ismp++; + ismp = add( ismp, 1 ); } alpha_sf_fx[ipar] = alpha_smp_fx; + move32(); beta_sf_fx[ipar] = beta_smp_fx; + move32(); } return; @@ -649,15 +703,15 @@ static void ivas_mc_paramupmix_dec_sf( Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */ ) { - int16_t i, ch, slot_idx, k; + Word16 i, ch, slot_idx, k; Word32 *pPcm_temp_fx[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/ /*CLDFB*/ Word32 Cldfb_RealBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; Word32 Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; - int16_t noparamupmix_delay, n_samples_rendered; + Word16 noparamupmix_delay, n_samples_rendered; MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix; - int16_t subframeIdx, idx_in, maxBand; + Word16 subframeIdx, idx_in, maxBand; #ifdef MSAN_FIX Word32 Cldfb_RealBuffer_subfr_fx[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] = { 0 }; Word32 Cldfb_ImagBuffer_subfr_fx[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] = { 0 }; @@ -672,96 +726,110 @@ static void ivas_mc_paramupmix_dec_sf( assert( hMCParamUpmix ); push_wmops( "ivas_mc_paramupmix_dec_sf" ); - for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) + FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ ) { pPcm_temp_fx[2 * i] = output_fx[i + 4]; /* un-decorrelated */ pPcm_temp_fx[2 * i + 1] = output_fx[i + 8]; /* decorrelated */ } /* CLDFB Analysis*/ - for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) + FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) { /* slot loop for gathering the input data */ - for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { Word16 q_cldfb = 11; - cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb ); + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb ); } } - for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { ps_pred_process_sf( hMCParamUpmix, st_ivas->hTcBuffer, - Cldfb_RealBuffer_fx[2 * ch], /* in/out */ - Cldfb_ImagBuffer_fx[2 * ch], - Cldfb_RealBuffer_fx[2 * ch + 1], /* in/out decorr */ - Cldfb_ImagBuffer_fx[2 * ch + 1], + Cldfb_RealBuffer_fx[shl( ch, 1 )], /* in/out */ + Cldfb_ImagBuffer_fx[shl( ch, 1 )], + Cldfb_RealBuffer_fx[add( shl( ch, 1 ), 1 )], /* in/out decorr */ + Cldfb_ImagBuffer_fx[add( shl( ch, 1 ), 1 )], &hMCParamUpmix->param_interpolator_fx[st_ivas->hTcBuffer->slots_rendered], ch, st_ivas->hTcBuffer->slots_rendered ); /*-- m, s -> l, r ----------------------------*/ - for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { - for ( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) + FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { Word32 qlre_fx = Cldfb_RealBuffer_fx[2 * ch][slot_idx][k]; Word32 qlim_fx = Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k]; Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; - - Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); - Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); + move32(); + move32(); + move32(); + move32(); + + Cldfb_RealBuffer_fx[shl( ch, 1 )][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[shl( ch, 1 )][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[add( shl( ch, 1 ), 1 )][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[add( shl( ch, 1 ), 1 )][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); + move32(); + move32(); + move32(); + move32(); } } } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + Word16 temp_e; + maxBand = BASOP_Util_Divide3232_Scale( (Word32) W_mult0_32_32( CLDFB_NO_CHANNELS_MAX, st_ivas->hDecoderConfig->output_Fs ), 48000, &temp_e ); + maxBand = shr( maxBand, sub( 15, temp_e ) ); subframeIdx = st_ivas->hTcBuffer->subframes_rendered; + move16(); /* fastconv binaural rendering and CLDFB synthesis */ /* cldfb analysis of non-coupled, non-LFE channels */ idx_in = 0; - for ( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ ) + move16(); + FOR( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ ) { - if ( st_ivas->hIntSetup.index_lfe[0] != ch ) + IF( st_ivas->hIntSetup.index_lfe[0] != ch ) { pPcm_temp_fx[ch] = output_fx[ch]; /* slot loop for gathering the input data */ - for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { Word16 q_cldfb = 11; + move16(); - cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), + cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], - maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in], &q_cldfb ); + maxBand, st_ivas->cldfbAnaDec[add( MC_PARAMUPMIX_COMBINATIONS * 2, idx_in )], &q_cldfb ); } - idx_in++; + idx_in = add( idx_in, 1 ); } } /* copy and reorder cldfb analysis of coupled channels */ - for ( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ ) + FOR( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ ) { - for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ ) { Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); } - idx_in += 2; + idx_in = add( idx_in, 2 ); } - if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF( st_ivas->hCombinedOrientationData && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { - for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_subfr_fx, Cldfb_ImagBuffer_subfr_fx, maxBand, GAIN_LFE_FX ); } @@ -770,6 +838,7 @@ static void ivas_mc_paramupmix_dec_sf( /* Implement binaural rendering */ Word16 input_q = 6; + move16(); /* Implement binaural rendering */ ivas_binRenderer_fx( st_ivas->hBinRenderer, st_ivas->hCombinedOrientationData, @@ -778,37 +847,39 @@ static void ivas_mc_paramupmix_dec_sf( Cldfb_RealBuffer_subfr_fx, Cldfb_ImagBuffer_subfr_fx, &input_q ); - for ( int idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ ) + FOR( Word16 idx1 = 0; idx1 < BINAURAL_CHANNELS; idx1++ ) { - for ( int idx2 = 0; idx2 < MAX_PARAM_SPATIAL_SUBFRAMES; idx2++ ) + FOR( Word16 idx2 = 0; idx2 < MAX_PARAM_SPATIAL_SUBFRAMES; idx2++ ) { - Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, 6 - input_q ); - Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, 6 - input_q ); + Scale_sig32( Cldfb_RealBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); + Scale_sig32( Cldfb_ImagBuffer_Binaural_fx[idx1][idx2], CLDFB_NO_CHANNELS_MAX, sub( 6, input_q ) ); } } /* Implement CLDFB synthesis */ - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; - for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ ) + FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ ) { RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[ch][slot_idx]; ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[ch][slot_idx]; } - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, Q11 ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q5 - Q11 ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; + move16(); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] ); - scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, Q5 ) ); + scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + move16(); } - for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - Scale_sig32( output_fx[ch], maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], 6 ); + Scale_sig32( output_fx[ch], imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6 ); } } - else + ELSE { /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */ pPcm_temp_fx[0] = output_fx[4]; @@ -821,57 +892,59 @@ static void ivas_mc_paramupmix_dec_sf( pPcm_temp_fx[7] = output_fx[11]; /* CLDFB synthesis */ - for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) + FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ ) { scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5; - for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) + move16(); + FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ ) { Word32 *ptr_im_fx[1], *ptr_re_fx[1]; ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; - cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), + cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ), hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] ); } scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + move16(); } // Done to keep entire buffer in q11 - for ( ch = 4; ch < 12; ch++ ) + FOR( ch = 4; ch < 12; ch++ ) { - Scale_sig32( output_fx[ch], hMCParamUpmix->num_freq_bands * st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered], 6 ); + Scale_sig32( output_fx[ch], imult1616( hMCParamUpmix->num_freq_bands, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ), 6 ); } /* adjust delay of other channels */ noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS ); - n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands; - if ( n_samples_rendered > noparamupmix_delay ) + n_samples_rendered = imult1616( st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered], hMCParamUpmix->num_freq_bands ); + IF( n_samples_rendered > noparamupmix_delay ) { - for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Word32 tmp_buf_fx[L_SUBFRAME5MS_48k]; - Copy32( &output_fx[ch][n_samples_rendered - noparamupmix_delay], tmp_buf_fx, noparamupmix_delay ); - Copy32( output_fx[ch], &output_fx[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay ); + Copy32( &output_fx[ch][sub( n_samples_rendered, noparamupmix_delay )], tmp_buf_fx, noparamupmix_delay ); + Copy32( output_fx[ch], &output_fx[ch][noparamupmix_delay], sub( n_samples_rendered, noparamupmix_delay ) ); Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], noparamupmix_delay ); Copy32( tmp_buf_fx, hMCParamUpmix->pcm_delay_fx[ch], noparamupmix_delay ); } } - else + ELSE { - for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) + FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ ) { Word32 tmp_buf_fx[L_SUBFRAME5MS_48k]; Copy32( &output_fx[ch][0], tmp_buf_fx, n_samples_rendered ); Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], n_samples_rendered ); - Copy32( &hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], noparamupmix_delay - n_samples_rendered ); - Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered ); + Copy32( &hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], sub( noparamupmix_delay, n_samples_rendered ) ); + Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][sub( noparamupmix_delay, n_samples_rendered )], n_samples_rendered ); } } } - st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; - st_ivas->hTcBuffer->subframes_rendered++; + st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ); + st_ivas->hTcBuffer->subframes_rendered = add( st_ivas->hTcBuffer->subframes_rendered, 1 ); pop_wmops(); return; @@ -888,10 +961,13 @@ static Word16 huff_read( DO { next_bit = st->bit_stream[st->next_bit_pos]; - st->next_bit_pos++; + move16(); + st->next_bit_pos = add( st->next_bit_pos, 1 ); + move16(); node = ht[node][next_bit]; + move16(); } - WHILE( GT_16( node, 0 ) ); + WHILE( node > 0 ); return negate( add( node, 1 ) ); } @@ -906,13 +982,16 @@ static void huffman_decode( Word16 iv, nquant, offset; nquant = 0; + move16(); SWITCH( parType ) { case ALPHA: nquant = ivas_mc_paramupmix_alpha_quant_table_fx.nquant; + move16(); BREAK; case BETA: nquant = ivas_mc_paramupmix_beta_quant_table_fx[0].nquant; + move16(); BREAK; default: assert( 0 ); @@ -950,6 +1029,7 @@ static void huffman_decode( FOR( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ ) { vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[sub( iv, 1 )] ), offset ); + move32(); } return; @@ -966,6 +1046,7 @@ static void dequant_alpha( FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ ) { v[iv] = quant_table->data[vq[iv]]; + move32(); } return; @@ -984,6 +1065,7 @@ static void dequant_beta( { quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; beta[iv] = quant_table->data[bq[iv]]; + move32(); } return; @@ -1002,7 +1084,7 @@ static void get_ec_data( IF( EQ_32( parType, ALPHA ) ) { dequant_alpha( parQ, ab ); - mvl2l( parQ, alphaQEnv, (Word16) IVAS_MAX_NUM_BANDS ); + Copy32( parQ, alphaQEnv, (Word16) IVAS_MAX_NUM_BANDS ); } ELSE { diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 3e11870eb..66fe480ef 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -330,13 +330,17 @@ ivas_error ivas_mct_dec_fx( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; move32(); + test(); + test(); + test(); + test(); IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { /* save LFE channel */ - mvl2l( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); + Copy32( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); } - IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->bfi, 0 ) ) + IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) && ( st_ivas->bfi == 0 ) ) { /* get the number of channels from the signalled MC LS setup */ n = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) ); @@ -353,24 +357,24 @@ ivas_error ivas_mct_dec_fx( /*initialize param_lpc buffer*/ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - set_s( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); + set16_fx( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); } set32_fx( &output_fx[0][0], 0, L_FRAME48k ); set32_fx( &output_fx[1][0], 0, L_FRAME48k ); - IF( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0, &q_output ) ), IVAS_ERR_OK ) ) { return error; } - IF( EQ_16( cpe_id, 0 ) ) + if ( cpe_id == 0 ) { st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ move32(); } - IF( EQ_16( st_ivas->bfi, 0 ) ) + IF( st_ivas->bfi == 0 ) { ivas_mdct_dec_side_bits_frame_channel_fx( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, (Word16) GT_16( i_mult( add( cpe_id, 1 ), CPE_CHANNELS ), hMCT->nchan_out_woLFE ) ); @@ -394,15 +398,15 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; x_e[n][0] = 20; - x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + shr( L_FRAME48k, 1 ); - x_e[n][1] = 20; move16(); + x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + x_e[n][1] = 20; move16(); - set32_fx( x_fx[n][0], 0, shr( L_FRAME48k, 1 ) ); - set32_fx( x_fx[n][1], 0, shr( L_FRAME48k, 1 ) ); + set32_fx( x_fx[n][0], 0, L_FRAME48k / 2 ); + set32_fx( x_fx[n][1], 0, L_FRAME48k / 2 ); } ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], @@ -410,16 +414,27 @@ ivas_error ivas_mct_dec_fx( FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { - Word16 subFrames = ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_10_CORE ) ? NB_DIV : 1; + Word16 subFrames; + IF( EQ_16( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core, TCX_10_CORE ) ) + { + subFrames = NB_DIV; + } + ELSE + { + subFrames = 1; + } + move16(); FOR( k = 0; k < subFrames; ++k ) { - Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, subFrames - 1 ), sub( x_e[ch][k], 20 ) ); + Scale_sig32( x_fx[ch][k], shr( L_FRAME48k, sub( subFrames, 1 ) ), sub( x_e[ch][k], 20 ) ); } } st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect ); + move16(); test(); st_ivas->BER_detect = s_or( st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect ); + move16(); test(); } @@ -441,7 +456,8 @@ ivas_error ivas_mct_dec_fx( /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ - IF( NE_16( st_ivas->sba_dirac_stereo_flag, 0 ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + test(); + IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { FOR( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) { @@ -460,9 +476,9 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Copy_Scale_sig_16_32( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, sub( Q16, Q12 ) ); - x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + Copy_Scale_sig_16_32( Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, Q16 - Q12 ); + x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; + x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); x_e[n][0] = 20; move16(); x_e[n][1] = 20; @@ -473,9 +489,18 @@ ivas_error ivas_mct_dec_fx( FOR( Word16 ind = 0; ind < 2; ind++ ) { - Word16 nSubFrames = EQ_16( hCPE->hCoreCoder[ind]->core, TCX_20_CORE ) ? 1 : NB_DIV; + Word16 nSubFrames; + IF( EQ_16( hCPE->hCoreCoder[ind]->core, TCX_20_CORE ) ) + { + nSubFrames = 1; + } + ELSE + { + nSubFrames = NB_DIV; + } + move16(); Scale_sig32( x_fx[ind][0], shr( L_FRAME48k, sub( nSubFrames, 1 ) ), sub( x_e[ind][0], 20 ) ); - IF( nSubFrames == 2 ) + IF( EQ_16( nSubFrames, 2 ) ) { Scale_sig32( x_fx[ind][1], shr( L_FRAME48k, 1 ), sub( x_e[ind][1], 20 ) ); } @@ -483,6 +508,8 @@ ivas_error ivas_mct_dec_fx( } + test(); + test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_MC ) ) { /* Equalization in MDCT Domain */ @@ -496,11 +523,11 @@ ivas_error ivas_mct_dec_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_all_fx[n + cpe_id * CPE_CHANNELS][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); - x_all_e[n + cpe_id * CPE_CHANNELS][1] = 20; + x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; + x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); + x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1] = 20; move16(); - x_all_e[n + cpe_id * CPE_CHANNELS][0] = 20; + x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0] = 20; move16(); } } @@ -511,8 +538,8 @@ ivas_error ivas_mct_dec_fx( { FOR( n = 0; n < CPE_CHANNELS; n++ ) { - Scale_sig32( x_all_fx[n + cpe_id * CPE_CHANNELS][0], shr( L_FRAME48k, 1 ), sub( x_all_e[n + cpe_id * CPE_CHANNELS][0], 20 ) ); - Scale_sig32( x_all_fx[n + cpe_id * CPE_CHANNELS][1], shr( L_FRAME48k, 1 ), sub( x_all_e[n + cpe_id * CPE_CHANNELS][1], 20 ) ); + Scale_sig32( x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0], ( L_FRAME48k / 2 ), sub( x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][0], 20 ) ); + Scale_sig32( x_all_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1], ( L_FRAME48k / 2 ), sub( x_all_e[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )][1], 20 ) ); } } } @@ -524,35 +551,36 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; - x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + x_fx[n][0] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )]; + x_fx[n][1] = output_fx[add( n, shl( cpe_id, 1 /* * CPE_CHANNELS*/ ) )] + ( L_FRAME48k / 2 ); } FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF( NE_16( hCPE->hCoreCoder[n]->Q_syn, 0 ) ) + IF( hCPE->hCoreCoder[n]->Q_syn != 0 ) { Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[n]->Q_syn ); } if ( sts[n]->hTcxDec && sts[n]->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) { sts[n]->hTcxDec->conCngLevelBackgroundTrace_e = 0; + move16(); } } - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0] - 1 ) ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, M + 1, ( 28 - norm_s( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0] - 1 ) ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_Aq_12_8_fx, hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, norm_s( sub( hCPE->hCoreCoder[0]->old_Aq_12_8_fx[0], 1 ) ) ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[1]->old_Aq_12_8_fx, hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32, add( M, 1 ), sub( 28, norm_s( sub( hCPE->hCoreCoder[1]->old_Aq_12_8_fx[0], 1 ) ) ) ); ivas_mdct_core_reconstruct_fx( hCPE, x_fx, synth_fx, fUseTns[cpe_id], 1, q_output, 15 ); FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF( NE_16( hCPE->hCoreCoder[n]->Q_syn, 0 ) ) + IF( hCPE->hCoreCoder[n]->Q_syn != 0 ) { Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); } IF( hCPE->hCoreCoder[n]->hBPF ) { - hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub( Q16, hCPE->hCoreCoder[n]->Q_syn2 - 1 ) ) ); - Scale_sig( hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, hCPE->hCoreCoder[n]->Q_syn2 - 1 ); + hCPE->hCoreCoder[n]->hBPF->pst_mem_deemp_err_fx = extract_l( L_shr( hCPE->hCoreCoder[n]->mem_error, sub( Q16, sub( hCPE->hCoreCoder[n]->Q_syn2, 1 ) ) ) ); + Scale_sig( hCPE->hCoreCoder[n]->hBPF->pst_old_syn_fx, NBPSF_PIT_MAX, sub( hCPE->hCoreCoder[n]->Q_syn2, 1 ) ); } IF( hCPE->hCoreCoder[n]->hTcxDec ) { @@ -572,16 +600,18 @@ ivas_error ivas_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { - IF( NE_16( st_ivas->sba_dirac_stereo_flag, 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) + test(); + test(); + IF( ( st_ivas->sba_dirac_stereo_flag != 0 ) && ( NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, sub( Q11, 0 ) ); + Copy_Scale_sig_16_32( synth_fx[n], synth_fx_32[n], L_FRAME48k, Q11 - 0 ); Copy_Scale_sig_16_32( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, Q11 ); ivas_post_proc_fx( NULL, hCPE, n, synth_fx_32[n], NULL, output_frame, 1 ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, sub( 0, Q11 ) ); + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], output_frame, 0 - Q11 ); #else - Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, sub( 0, Q11 ) ); + Copy_Scale_sig_32_16( synth_fx_32[n], synth_fx[n], L_FRAME48k, 0 - Q11 ); #endif } @@ -589,7 +619,7 @@ ivas_error ivas_mct_dec_fx( Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem_fx[1] != NULL ) { - Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), sub( 0, Q11 ) ); + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), 0 - Q11 ); } ELSE { @@ -597,25 +627,37 @@ ivas_error ivas_mct_dec_fx( } Word16 Q_synth = 0; + move16(); - IF( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) + Word16 dirac_stereo_flag; + test(); + IF( NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) || GE_16( cpe_id, sub( nCPE, 2 ) ) ) + { + dirac_stereo_flag = st_ivas->sba_dirac_stereo_flag; + } + ELSE + { + dirac_stereo_flag = 0; + } + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx[n], output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, dirac_stereo_flag, -1, hCPE->last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig_16_32( synth_fx[n], output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub( Q11, Q_synth ) ); + Copy_Scale_sig_16_32( synth_fx[n], output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_frame, sub( Q11, Q_synth ) ); /* Save synthesis for HQ FEC */ Word32 output_fx_[L_FRAME48k]; - mvl2l( output_fx[cpe_id * CPE_CHANNELS + n], output_fx_, L_FRAME48k ); - Scale_sig32( output_fx_, L_FRAME48k, sub( Q16, Q11 ) ); + mvl2l( output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], output_fx_, L_FRAME48k ); + Scale_sig32( output_fx_, L_FRAME48k, Q16 - Q11 ); Copy_Scale_sig32_16( sts[n]->prev_synth_buffer32_fx, sts[n]->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); sts[n]->q_prev_synth_buffer_fx = 0; + move16(); save_synthesis_hq_fec_fx( sts[n], output_fx_, output_frame, hCPE ); /* CoreCoder common updates */ - ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[cpe_id * CPE_CHANNELS + n], 11 ); + ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[add( shl( cpe_id, 1 /* * CPE_CHANNELS*/ ), n )], 11 ); } /* n_channels loop */ @@ -628,28 +670,32 @@ ivas_error ivas_mct_dec_fx( } /* synthesis synchronization between stereo modes */ - IF( EQ_16( st_ivas->sba_dirac_stereo_flag, 0 ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && LT_16( cpe_id, sub( nCPE, 2 ) ) ) ) + test(); + test(); + IF( ( st_ivas->sba_dirac_stereo_flag == 0 ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && LT_16( cpe_id, sub( nCPE, 2 ) ) ) ) { - synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); + synchro_synthesis_fx( ivas_total_brate, hCPE, output_fx + imult1616( cpe_id, CPE_CHANNELS ), output_frame, 0 ); } } /* move channels after LFE to correct output for multi-channel MCT */ + test(); + test(); IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { Word32 tmp[L_FRAME48k]; /*save center channel output*/ - mvl2l( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); + Copy32( output_fx[sub( hMCT->nchan_out_woLFE, 1 )], tmp, output_frame ); - FOR( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) + FOR( n = sub( hMCT->nchan_out_woLFE, 1 ); n >= LFE_CHANNEL; n-- ) { - mvl2l( output_fx[n - 1], output_fx[n + 1], output_frame ); + Copy32( output_fx[sub( n, 1 )], output_fx[add( n, 1 )], output_frame ); } - mvl2l( tmp, output_fx[LFE_CHANNEL - 1], output_frame ); + Copy32( tmp, output_fx[sub( LFE_CHANNEL, 1 )], output_frame ); /* save LFE channel */ - mvl2l( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); + Copy32( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); } pop_wmops(); @@ -688,21 +734,29 @@ ivas_error create_mct_dec_fx( *-----------------------------------------------------------------*/ /* Determine active channels */ + test(); + test(); + test(); + test(); IF( ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { hMCT->nchan_out_woLFE = st_ivas->nchan_transport; + move16(); IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism ); + move16(); } } ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); + move16(); } ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); + move16(); } ELSE { @@ -722,13 +776,15 @@ ivas_error create_mct_dec_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); } } /* in case we have an uneven number of transport channels, indicate last channel ID as inactive */ IF( hMCT->nchan_out_woLFE % 2 ) { - st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + move32(); } /*Initialize MCT block data */ @@ -744,7 +800,8 @@ ivas_error create_mct_dec_fx( /*Initialize all parameters to zero*/ hMCT->hBlockData[n]->ch1 = 0; hMCT->hBlockData[n]->ch2 = 0; - + move16(); + move16(); /*-----------------------------------------------------------------* * MDCT stereo initialization *-----------------------------------------------------------------*/ @@ -757,7 +814,10 @@ ivas_error create_mct_dec_fx( initMdctStereoDecData_fx( hMCT->hBlockData[n]->hStereoMdct, st_ivas->hCPE[0]->hCoreCoder[0]->igf, st_ivas->hCPE[0]->hCoreCoder[0]->hIGFDec->igfData.igfInfo.grid, cp_bitrate, SWB ); hMCT->hBlockData[n]->hStereoMdct->use_itd = 0; hMCT->hBlockData[n]->hStereoMdct->reverse_dmx = 0; + move16(); + move16(); hMCT->hBlockData[n]->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + move32(); } FOR( ; n < MCT_MAX_BLOCKS; n++ ) { @@ -769,10 +829,11 @@ ivas_error create_mct_dec_fx( *-----------------------------------------------------------------*/ hMCT->currBlockDataCnt = 0; + move16(); /*Initialize bits required to signal channel-pair index*/ // hMCT->bitsChannelPairIndex = max( 1, (Word16) ( floorf( ( logf( (float) hMCT->nchan_out_woLFE * ( hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) * INV_LOG_2 ) ) + 1 ) ); - hMCT->bitsChannelPairIndex = s_max( 1, floor_log_2( (Word32) hMCT->nchan_out_woLFE * ( (Word32) hMCT->nchan_out_woLFE - 1 ) / 2 - 1 ) + 1 ); + hMCT->bitsChannelPairIndex = s_max( 1, add( floor_log_2( sub( shr( imult1616( hMCT->nchan_out_woLFE, sub( hMCT->nchan_out_woLFE, 1 ) ), 1 ), 1 ) ), 1 ) ); set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); @@ -938,15 +999,18 @@ ivas_error mct_dec_reconfigure_fx( IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { hMCT->nchan_out_woLFE = add( hMCT->nchan_out_woLFE, st_ivas->nchan_ism ); + move16(); } } ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) ) { hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); + move16(); } ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { hMCT->nchan_out_woLFE = sub( st_ivas->nchan_transport, st_ivas->hTransSetup.num_lfe ); + move16(); } ELSE { @@ -960,6 +1024,7 @@ ivas_error mct_dec_reconfigure_fx( FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); } } @@ -967,15 +1032,16 @@ ivas_error mct_dec_reconfigure_fx( IF( hMCT->nchan_out_woLFE % 2 ) { st_ivas->hCPE[st_ivas->nCPE - 1]->hCoreCoder[1]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + move32(); } tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, hMCT->nchan_out_woLFE, &tmp_exp ); - cp_bitrate = L_shl( tmp, tmp_exp + 2 ); + cp_bitrate = L_shl( tmp, add( tmp_exp, 2 ) ); IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, &tmp_exp ); - cp_bitrate = L_shl( tmp, tmp_exp + 2 ); + cp_bitrate = L_shl( tmp, add( tmp_exp, 2 ) ); } /* set correct nominal bitrates and igf config already here, otherwise we @@ -994,8 +1060,10 @@ ivas_error mct_dec_reconfigure_fx( IF( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { tmp = BASOP_Util_Divide3232_Scale( st_ivas->hCPE[cpe_id]->element_brate, FRAMES_PER_SEC, &tmp_exp ); - st->bits_frame_nominal = shr( tmp, 15 - tmp_exp ); + st->bits_frame_nominal = shr( tmp, sub( 15, tmp_exp ) ); + move16(); st->igf = getIgfPresent_fx( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag ); // no floating point so directly pluggable + move16(); IF( st->igf ) { @@ -1007,7 +1075,7 @@ ivas_error mct_dec_reconfigure_fx( /*Initialize MCT block data */ tmp = BASOP_Util_Divide1616_Scale( hMCT->nchan_out_woLFE, CPE_CHANNELS, &tmp_exp ); - max_blocks = shr( tmp, 15 - tmp_exp ); + max_blocks = shr( tmp, sub( 15, tmp_exp ) ); FOR( n = 0; n < max_blocks; n++ ) { @@ -1071,16 +1139,16 @@ ivas_error mct_dec_reconfigure_fx( L_tmp = L_sub( L_shr( L_mult0( hMCT->nchan_out_woLFE, sub( hMCT->nchan_out_woLFE, 1 ) ), 1 ), 1 ); tmp_exp = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, tmp_exp ); - log_tmp = BASOP_Util_Log2( L_tmp ); // ( 31 - tmp_exp ) - log_tmp = L_add( log_tmp, L_shl( ( Q31 - tmp_exp ), Q25 ) ); // Q25 + log_tmp = BASOP_Util_Log2( L_tmp ); // ( 31 - tmp_exp ) + log_tmp = L_add( log_tmp, L_shl( sub( Q31, tmp_exp ), Q25 ) ); // Q25 // scale down from Q25 to Q0 tmp = extract_l( L_shr( log_tmp, Q25 ) ); tmp = add( tmp, 1 ); hMCT->bitsChannelPairIndex = s_max( 1, tmp ); - set_s( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); - set_s( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); + set16_fx( hMCT->chBitRatios, 0, MCT_MAX_CHANNELS ); + set16_fx( hMCT->lowE_ch, 0, MCT_MAX_CHANNELS ); } return IVAS_ERR_OK; @@ -1250,6 +1318,7 @@ void ivas_mct_dec_close( { Word16 n, maxBlocks; + test(); IF( hMCT == NULL || *hMCT == NULL ) { return; @@ -1335,32 +1404,36 @@ ivas_error ivas_mc_dec_config_fx( /* store last frame MC mode */ last_mc_mode = st_ivas->mc_mode; - IF( EQ_16( st_ivas->bfi, 0 ) ) + IF( st_ivas->bfi == 0 ) { /* set transported MC LS setup */ signaled_config = ivas_mc_map_ls_setup_to_output_config_fx( idx ); - IF( EQ_16( st_ivas->ini_frame, 0 ) ) + if ( st_ivas->ini_frame == 0 ) { st_ivas->transport_config = signaled_config; + move32(); } /* select MC format mode */ st_ivas->mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( signaled_config ), st_ivas->hDecoderConfig->ivas_total_brate ); + move32(); /* MC format switching */ IF( st_ivas->ini_frame != 0 ) { + test(); IF( NE_32( st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->hDecoderConfig->ivas_total_brate ) || st_ivas->transport_config != signaled_config || last_mc_mode != st_ivas->mc_mode ) { IF( st_ivas->hRenderConfig ) { FOR( Word16 i = 0; i < 4; i++ ) { - st_ivas->hRenderConfig->directivity_fx[i * 3 + 2] = shl_sat( st_ivas->hRenderConfig->directivity_fx[i * 3 + 2], 9 ); + st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )] = shl_sat( st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )], 9 ); + move16(); } } - IF( ( error = ivas_mc_dec_reconfig_fx( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_dec_reconfig_fx( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -1368,13 +1441,15 @@ ivas_error ivas_mc_dec_config_fx( { FOR( Word16 i = 0; i < 4; i++ ) { - st_ivas->hRenderConfig->directivity_fx[i * 3 + 2] = shr( st_ivas->hRenderConfig->directivity_fx[i * 3 + 2], 9 ); + st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )] = shr( st_ivas->hRenderConfig->directivity_fx[add( imult1616( i, 3 ), 2 )], 9 ); + move16(); } } } } st_ivas->transport_config = signaled_config; + move32(); } return IVAS_ERR_OK; @@ -1457,22 +1532,31 @@ static ivas_error ivas_mc_dec_reconfig_fx( Word16 nchan_out_buff_old, nchan_out_buff; error = IVAS_ERR_OK; + move32(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); nchan_transport_old = st_ivas->nchan_transport; + move16(); nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); last_mc_mode = ivas_mc_mode_select_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ /* temporally set the current mc_mode back to the previous one to make sure the following call to ivas_init_dec_get_num_cldfb_instances() returns the correct counts */ mc_mode = st_ivas->mc_mode; + move32(); st_ivas->mc_mode = last_mc_mode; + move32(); ivas_init_dec_get_num_cldfb_instances_ivas_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); st_ivas->mc_mode = mc_mode; + move32(); nSCE_old = st_ivas->nSCE; + move16(); nCPE_old = st_ivas->nCPE; + move16(); sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + move16(); /* special handling needed for the hp20 buffers for McMASA */ IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) ) @@ -1482,45 +1566,60 @@ static ivas_error ivas_mc_dec_reconfig_fx( ELSE { nchan_hp20_old = nchan_transport_old; + move16(); } st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); + move16(); /* save old IntSetup, might be needed for JBM flushing...*/ intern_config_old = st_ivas->intern_config; + move32(); hIntSetupOld = st_ivas->hIntSetup; tc_granularity_new = 1; + move16(); /* renderer might have changed, reselect */ renderer_type_old = st_ivas->renderer_type; + move32(); ivas_renderer_select( st_ivas ); /* side effect of the renderer selection can be a changed internal config */ ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); /* transfer subframe info from DirAC or ParamMC to central tc buffer */ + test(); IF( EQ_16( last_mc_mode, MC_MODE_PARAMMC ) ) { st_ivas->hTcBuffer->nb_subframes = st_ivas->hParamMC->nb_subframes; + move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hParamMC->subframes_rendered; + move16(); st_ivas->hTcBuffer->num_slots = st_ivas->hParamMC->num_slots; + move16(); st_ivas->hTcBuffer->slots_rendered = st_ivas->hParamMC->slots_rendered; + move16(); Copy( st_ivas->hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } ELSE IF( EQ_16( last_mc_mode, MC_MODE_MCMASA ) && st_ivas->hSpatParamRendCom != NULL ) { st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + move16(); st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + move16(); st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + move16(); Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); + move16(); IF( LT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &hIntSetupOld, last_mc_mode, ISM_MODE_NONE, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } @@ -1528,7 +1627,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( /* JBM: when granularity goes up set samples to discard at the beginning of the frame */ ELSE IF( GT_16( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - IF( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1536,8 +1635,11 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ) ); + move16(); st_ivas->nSCE = 0; - st_ivas->nCPE = st_ivas->nchan_transport / 2; + move16(); + st_ivas->nCPE = shr( st_ivas->nchan_transport, 1 ); + move16(); IF( NE_16( last_mc_mode, MC_MODE_MCT ) ) { @@ -1569,9 +1671,10 @@ static ivas_error ivas_mc_dec_reconfig_fx( } /* init LS conversion if the renderer type asks for it */ + test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_MC ) && st_ivas->hLsSetUpConversion == NULL ) { - if ( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1581,8 +1684,11 @@ static ivas_error ivas_mc_dec_reconfig_fx( ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { st_ivas->nSCE = 0; + move16(); st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2; + move16(); st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; + move16(); IF( NE_16( last_mc_mode, MC_MODE_PARAMUPMIX ) ) { @@ -1599,15 +1705,16 @@ static ivas_error ivas_mc_dec_reconfig_fx( ivas_qmetadata_close( &st_ivas->hQMetaData ); /* init LS conversion if the renderer type asks for it */ + test(); IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) ) && st_ivas->hLsSetUpConversion == NULL ) { - IF( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ls_setup_conversion_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mc_paramupmix_dec_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1618,19 +1725,20 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( NE_16( last_mc_mode, MC_MODE_PARAMMC ) ) { /* remove old ls conversion for MCT if open, gets reopened correctly within ivas_param_mc_dec_open when needed */ + test(); IF( EQ_16( renderer_type_old, RENDERER_MC ) && st_ivas->hLsSetUpConversion != NULL ) { ivas_ls_setup_conversion_close_fx( &st_ivas->hLsSetUpConversion ); } - IF( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_mc_dec_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } ELSE { - IF( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_param_mc_dec_reconfig_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1650,6 +1758,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( EQ_16( last_mc_mode, MC_MODE_MCT ) ) { + test(); IF( st_ivas->hMCT != NULL && LE_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { ivas_mct_dec_close( &st_ivas->hMCT ); @@ -1669,13 +1778,13 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( NE_16( last_mc_mode, MC_MODE_MCMASA ) ) { - IF( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ), IVAS_ERR_OK ) ) { return error; } } - IF( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mcmasa_dec_reconfig( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -1713,6 +1822,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( { st_ivas->element_mode_init = IVAS_CPE_MDCT; } + move16(); } /*-----------------------------------------------------------------* @@ -1722,11 +1832,13 @@ static ivas_error ivas_mc_dec_reconfig_fx( /* special case: MCT->ParamMC with more than 2 TC, CPE 1 stays, but has the wrong mct_chan_mode in channel 1 and might have IGF static memory not allocated and the bit stream index list not set, set correct mct_chan_mode and init missing static mem (IGF, HQ) and some config (TNS) do it here since it is _very_ MC specific */ + test(); + test(); IF( EQ_16( last_mc_mode, MC_MODE_MCT ) && EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && GT_16( st_ivas->nchan_transport, CPE_CHANNELS ) ) { st = st_ivas->hCPE[1]->hCoreCoder[1]; - IF( st_ivas->nchan_transport == 3 ) + IF( EQ_16( st_ivas->nchan_transport, 3 ) ) { st->mct_chan_mode = MCT_CHAN_MODE_IGNORE; } @@ -1734,6 +1846,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( { st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; } + move32(); IF( st->hIGFDec == NULL ) { @@ -1743,6 +1856,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( } st->igf = 0; + move16(); init_igf_dec( st->hIGFDec ); #if 1 /*TODO: To be removed later(floating point initialization)*/ #if ( defined EVS_FLOAT ) || !( defined IVAS_FLOAT_FIXED ) @@ -1751,7 +1865,10 @@ static ivas_error ivas_mc_dec_reconfig_fx( set_f( st->hIGFDec->igfData.pSpecFlatBuf, 0, IGF_START_MX ); #endif FOR( Word16 l = 0; l < IGF_START_MX; l++ ) - st->hIGFDec->infoTCXNoise_evs[l] = (uint8_t) st->hIGFDec->infoTCXNoise_evs[l]; + { + st->hIGFDec->infoTCXNoise_evs[l] = (UWord8) st->hIGFDec->infoTCXNoise_evs[l]; + move16(); + } #endif } @@ -1776,31 +1893,46 @@ static ivas_error ivas_mc_dec_reconfig_fx( } st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( ivas_total_brate, st->igf, st->element_mode ); + move16(); } IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { - uint8_t separateChannelEnabled; - int16_t separateChannelIndex; + UWord8 separateChannelEnabled; + Word16 separateChannelIndex; ivas_mcmasa_set_separate_channel_mode_fx( &separateChannelEnabled, &separateChannelIndex, ivas_total_brate ); ivas_mcmasa_split_brate_fx( separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &new_brate_SCE, &new_brate_CPE ); } ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) ) { new_brate_SCE = 0; - new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + move32(); + Word16 temp_e; + Word32 L_temp = BASOP_Util_Divide3232_Scale_cadence( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &temp_e ); + L_temp = L_shr( L_temp, sub( 31, temp_e ) ); + new_brate_CPE = L_shl( L_temp, 1 ) /*CPE_CHANNELS*/; } ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { new_brate_SCE = 0; - new_brate_CPE = ( ivas_total_brate / ( st_ivas->nchan_transport - 1 ) ) * CPE_CHANNELS; + move32(); + Word16 temp_e; + Word32 L_temp = BASOP_Util_Divide3232_Scale_cadence( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &temp_e ); + L_temp = L_shr( L_temp, sub( 31, temp_e ) ); + new_brate_CPE = L_shl( L_temp, 1 ) /*CPE_CHANNELS*/; } ELSE { new_brate_SCE = 0; /* ivas_total_brate / st_ivas->nchan_transport;*/ - new_brate_CPE = ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS; + move32(); + Word16 temp_e; + Word32 L_temp = BASOP_Util_Divide3232_Scale_cadence( ivas_total_brate, st_ivas->nchan_transport, &temp_e ); + L_temp = L_shr( L_temp, sub( 31, temp_e ) ); + new_brate_CPE = L_shl( L_temp, 1 ) /*CPE_CHANNELS*/; } - IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ) != IVAS_ERR_OK ) + test(); + test(); + IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, new_brate_SCE, new_brate_CPE ) ), IVAS_ERR_OK ) ) { return error; } @@ -1822,7 +1954,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( /*-----------------------------------------------------------------* * re-configure HP20 memories *-----------------------------------------------------------------*/ - IF( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -1830,23 +1962,27 @@ static ivas_error ivas_mc_dec_reconfig_fx( * Allocate the LFE handle that is coded separately after the allocation of the core coders *-----------------------------------------------------------------*/ + test(); + test(); IF( ( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) && st_ivas->hLFE == NULL ) { Word32 binauralization_delay_ns = st_ivas->binaural_latency_ns; + move32(); IF( st_ivas->hBinRenderer != NULL ) { IF( st_ivas->hBinRenderer->render_lfe ) { /* Account for filterbank delay */ - binauralization_delay_ns += IVAS_FB_DEC_DELAY_NS; + binauralization_delay_ns = L_add( binauralization_delay_ns, IVAS_FB_DEC_DELAY_NS ); } - else + ELSE { binauralization_delay_ns = 0; + move32(); } } - IF( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, binauralization_delay_ns ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_create_lfe_dec_fx( &st_ivas->hLFE, st_ivas->hDecoderConfig->output_Fs, binauralization_delay_ns ) ), IVAS_ERR_OK ) ) { return error; } @@ -1861,12 +1997,14 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) { + test(); + test(); IF( ( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) && ( NE_16( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) ) ) { IF( st_ivas->hDirAC != NULL ) { /* reconfigure existing DirAC dec */ - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_RECONFIGURE ) ), IVAS_ERR_OK ) ) { return error; } @@ -1874,7 +2012,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( ELSE { /* init a new DirAC dec */ - IF( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, DIRAC_OPEN ) ), IVAS_ERR_OK ) ) { return error; } @@ -1894,26 +2032,43 @@ static ivas_error ivas_mc_dec_reconfig_fx( AUDIO_CONFIG output_config; output_config = st_ivas->hDecoderConfig->output_config; + move32(); /* binaural renderers*/ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* remove unneeded binaural renderers */ + test(); + test(); IF( st_ivas->hBinRenderer != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { ivas_binRenderer_close_fx( &st_ivas->hBinRenderer ); } + test(); + test(); + test(); + test(); + test(); IF( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hCrend != NULL ) && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) || NE_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) ) { ivas_rend_closeCrend( &( st_ivas->hCrendWrapper ) ); } + test(); IF( st_ivas->hBinRendererTd != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) ) { #ifdef FIX_1033_MEMORY_LEAK_OMASA - if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + IF( EQ_16( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM, TRUE ) ) { #endif ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); @@ -1925,6 +2080,8 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( st_ivas->hDiracDecBin != NULL ) { + test(); + test(); IF( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); @@ -1932,6 +2089,11 @@ static ivas_error ivas_mc_dec_reconfig_fx( } /* init necessary new renderers */ + test(); + test(); + test(); + test(); + test(); IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { IF( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) @@ -1941,13 +2103,13 @@ static ivas_error ivas_mc_dec_reconfig_fx( } ELSE IF( st_ivas->hBinRendererTd == NULL && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { - IF( ( error = ivas_td_binaural_open_fx( st_ivas, &st_ivas->SrcInd[0], &st_ivas->num_src ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, &st_ivas->SrcInd[0], &st_ivas->num_src ) ), IVAS_ERR_OK ) ) { return error; } IF( EQ_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ), IVAS_ERR_OK ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } @@ -1962,11 +2124,12 @@ static ivas_error ivas_mc_dec_reconfig_fx( } ELSE IF( st_ivas->hCrendWrapper == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) ) { - IF( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) { return error; } st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; + move32(); } } /* mono/stereo */ @@ -1983,7 +2146,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( * CLDFB instances *-----------------------------------------------------------------*/ - IF( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -2000,37 +2163,56 @@ static ivas_error ivas_mc_dec_reconfig_fx( tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); tc_nchan_allocate_new = tc_nchan_tc_new; + move16(); tc_nchan_full_new = tc_nchan_tc_new; + move16(); + test(); + test(); IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; + tc_nchan_allocate_new = BINAURAL_CHANNELS * 2; + move16(); tc_nchan_full_new = tc_nchan_allocate_new; + move16(); } + test(); + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { tc_nchan_full_new = 0; + move16(); } ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; + move16(); tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; + move32(); IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; + move32(); tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; + move16(); tc_nchan_allocate_new = tc_nchan_tc_new; + move16(); } tc_nchan_full_new = tc_nchan_allocate_new; + move16(); } /* reconfigure buffer */ + test(); + test(); + test(); + test(); IF( NE_16( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) || NE_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) ) { - IF( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) { return error; } @@ -2039,17 +2221,25 @@ static ivas_error ivas_mc_dec_reconfig_fx( IF( st_ivas->hSpatParamRendCom != NULL ) { st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + move16(); st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + move16(); Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } ELSE IF( st_ivas->hParamMC != NULL ) { st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; + move16(); st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + move16(); Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } } @@ -2061,7 +2251,7 @@ static ivas_error ivas_mc_dec_reconfig_fx( nchan_out_buff = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); - IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx.c index a91acad66..9c3dced33 100644 --- a/lib_dec/ivas_mct_dec_mct_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx.c @@ -56,6 +56,7 @@ static void indexToChannelPair_fx( { Word16 ch1, ch2; Word16 tmpIdx = 0; + move16(); FOR( ch2 = 1; ch2 < nChannels; ch2++ ) { @@ -97,6 +98,7 @@ void ivas_mct_dec_mct_fx( MCT_DEC_BLOCK_DATA_HANDLE hBlock; Decoder_State *p_st[CPE_CHANNELS]; Word16 nchan_active = 0; + move16(); hMCT->currBlockDataCnt = get_next_indice_fx( sts[0], MCT_NUM_BLOCK_DATA_BITS ); move16(); @@ -121,8 +123,7 @@ void ivas_mct_dec_mct_fx( { FOR( ch = 0; ch < nchan; ch++ ) { - IF( - NE_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + IF( NE_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { hMCT->lowE_ch[ch] = get_next_indice_fx( sts[0], 1 ); move16(); @@ -132,9 +133,9 @@ void ivas_mct_dec_mct_fx( FOR( ch = 0; ch < nchan; ch++ ) { - IF( NE_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) + if ( NE_16( sts[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { - nchan_active++; + nchan_active = add( nchan_active, 1 ); } } @@ -177,11 +178,18 @@ static void applyGlobalILD_fx( Word16 q_qratio; Word16 tmp, tmp_e; - FOR( ch = 0; ch < ( hMCT->nchan_out_woLFE ); - ch++ ) + FOR( ch = 0; ch < ( hMCT->nchan_out_woLFE ); ch++ ) { - nSubframes = ( EQ_16( sts[ch]->core, TCX_20_CORE ) ) ? 1 : NB_DIV; - move16(); + IF( EQ_16( sts[ch]->core, TCX_20_CORE ) ) + { + nSubframes = 1; + move16(); + } + ELSE + { + nSubframes = NB_DIV; + move16(); + } tmp = BASOP_Util_Divide1616_Scale( sts[ch]->hTcxDec->L_frameTCX, nSubframes, &tmp_e ); L_subframeTCX = shr( tmp, add( 15, negate( tmp_e ) ) ); @@ -189,7 +197,7 @@ static void applyGlobalILD_fx( { IF( hMCT->lowE_ch[ch] ) { - tmp = BASOP_Util_Divide3216_Scale( (Word32) hMCT->mc_global_ild[ch] << Q26, SMDCT_ILD_RANGE, &tmp_e ); // Q26 + tmp = BASOP_Util_Divide3216_Scale( L_shl( hMCT->mc_global_ild[ch], Q26 ), SMDCT_ILD_RANGE, &tmp_e ); // Q26 qratio = L_shr( (Word32) tmp, negate( add( 1, tmp_e ) ) ); } ELSE @@ -204,7 +212,7 @@ static void applyGlobalILD_fx( { v_multc_fixed( x[ch][k], qratio, x[ch][k], L_subframeTCX ); // Qx - 5 + q_qratio } - q_x[ch] = q_x[ch] - 5 + q_qratio; + q_x[ch] = add( sub( q_x[ch], 5 ), q_qratio ); move16(); } ELSE @@ -311,6 +319,7 @@ void mctStereoIGF_dec_fx( { tmp = BASOP_Util_Divide1616_Scale( sts[0]->hTcxCfg->tcx_coded_lines, nSubframes, &tmp_e ); L_spec[0] = shr( tmp, add( 15, negate( tmp_e ) ) ); + move16(); tmp = BASOP_Util_Divide1616_Scale( sts[0]->L_frame, nSubframes, &tmp_e ); L_frame_nSubframe = shr( tmp, add( 15, negate( tmp_e ) ) ); @@ -321,18 +330,20 @@ void mctStereoIGF_dec_fx( init_tcx_info_fx( sts[0], L_frame_nSubframe, L_frameTCX_nSubframe, k, bfi, &tcx_offset[0], &tcx_offsetFB[0], &L_frame[0], &L_frameTCX[0], &left_rect[0], &L_spec[0] ); /* stereo IGF decoding */ - assert( ( EQ_16( sts[0]->core, sts[1]->core ) ) || ( EQ_16( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[0], SMDCT_DUAL_MONO ) ) ); + assert( ( EQ_16( sts[0]->core, sts[1]->core ) ) || ( ( hMCT->hBlockData[b]->hStereoMdct->mdct_stereo_mode[0] == SMDCT_DUAL_MONO ) ) ); decoder_tcx_IGF_stereo_fx( sts, hMCT->hBlockData[b]->hStereoMdct, hMCT->hBlockData[b]->mask, p_x, p_x_e, p_x_len, L_frame[0], left_rect[0], k, bfi, 1 /* MCT_flag */ ); // Shifting output with variable exponent back to Q12 FOR( Word16 i = 0; i < p_x_len[0][k]; i++ ) { - p_x[0][k][i] = L_shr( p_x[0][k][i], 31 - Q12 - p_x_e[0][k] ); + p_x[0][k][i] = L_shr( p_x[0][k][i], sub( 31 - Q12, p_x_e[0][k] ) ); + move32(); } FOR( Word16 i = 0; i < p_x_len[1][k]; i++ ) { - p_x[1][k][i] = L_shr( p_x[1][k][i], 31 - Q12 - p_x_e[1][k] ); + p_x[1][k][i] = L_shr( p_x[1][k][i], sub( 31 - Q12, p_x_e[1][k] ) ); + move32(); } } ELSE @@ -343,7 +354,7 @@ void mctStereoIGF_dec_fx( st = sts[ch]; test(); - IF( bfi && EQ_16( st->core, ACELP_CORE ) ) /*no igf processing needed*/ + IF( bfi && ( st->core == ACELP_CORE ) ) /*no igf processing needed*/ { CONTINUE; } @@ -376,7 +387,7 @@ void mctStereoIGF_dec_fx( } } - IF( NE_16( sum16_fx( singleChEle, ( hMCT->nchan_out_woLFE ) ), 0 ) ) + IF( sum16_fx( singleChEle, ( hMCT->nchan_out_woLFE ) ) != 0 ) { FOR( ch = 0; ch < ( hMCT->nchan_out_woLFE ); ch++ ) { @@ -384,7 +395,7 @@ void mctStereoIGF_dec_fx( { st = stm[ch]; test(); - IF( bfi && EQ_16( st->core, ACELP_CORE ) ) /*no igf processing needed*/ + IF( bfi && ( st->core == ACELP_CORE ) ) /*no igf processing needed*/ { CONTINUE; } @@ -392,7 +403,15 @@ void mctStereoIGF_dec_fx( { CONTINUE; } - nSubframes = ( EQ_16( st->core, TCX_10_CORE ) ) ? NB_DIV : 1; + + IF( EQ_16( st->core, TCX_10_CORE ) ) + { + nSubframes = NB_DIV; + } + ELSE + { + nSubframes = 1; + } move16(); FOR( k = 0; k < nSubframes; k++ ) diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index ad6f0f9c1..60f3f8158 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -76,25 +76,29 @@ static void ivas_lssetupconversion_computeEQFactor_fx( Word32 *EQ ) { - IF( L_shr( *outputEnergy, 3 ) > Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MAX_SQ_Q28, *inputEnergy ) ) + IF( GT_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MAX_SQ_Q28, *inputEnergy ) ) ) { *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MAX_Q29, 1 ); + move32(); return; } - IF( L_shr( *outputEnergy, 3 ) < Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MIN_SQ_Q28, *inputEnergy ) ) + IF( LT_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MIN_SQ_Q28, *inputEnergy ) ) ) { *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MIN_Q29, 1 ); + move32(); return; } - IF( *outputEnergy == 0 && *inputEnergy == 0 ) + test(); + IF( ( *outputEnergy == 0 ) && ( *inputEnergy == 0 ) ) { *EQ = ONE_IN_Q30; + move32(); return; } /* Compute the Equalization Gain */ Word16 tmp_e; - Word16 tmp = BASOP_Util_Divide3232_Scale( *outputEnergy, ( EPSILON_FX + *inputEnergy ), &tmp_e ); + Word16 tmp = BASOP_Util_Divide3232_Scale( *outputEnergy, L_add( EPSILON_FX, *inputEnergy ), &tmp_e ); Word32 tmp_32 = L_shl( (Word32) tmp, 16 ); tmp_32 = Sqrt32( tmp_32, &tmp_e ); *EQ = L_shr( tmp_32, 1 - tmp_e ); @@ -133,7 +137,16 @@ static void ivas_lssetupconversion_mdct_init_bands_fx( Word16 i, cnt, specStartOffset, L_frameTCX; const UWord8 *sfbWidths; - L_frameTCX = ( EQ_16( tcx_mode, TCX_20_CORE ) ) ? output_frame : ( shr( output_frame, 1 ) ); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + L_frameTCX = output_frame; + move16(); + } + ELSE + { + L_frameTCX = shr( output_frame, 1 ); + } + SWITCH( output_frame ) { @@ -152,9 +165,18 @@ static void ivas_lssetupconversion_mdct_init_bands_fx( return; } - sfbWidths = ( EQ_16( tcx_mode, TCX_20_CORE ) ? lpcBndsParam->bandLengthsTCX20 : lpcBndsParam->bandLengthsTCX10 ); - cnt = ( EQ_16( tcx_mode, TCX_20_CORE ) ? 64 : 32 ); - move16(); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + sfbWidths = lpcBndsParam->bandLengthsTCX20; + cnt = 64; + move16(); + } + ELSE + { + sfbWidths = lpcBndsParam->bandLengthsTCX10; + cnt = 32; + move16(); + } /* calc sfb offsets */ specStartOffset = 0; @@ -162,10 +184,9 @@ static void ivas_lssetupconversion_mdct_init_bands_fx( FOR( i = 0; i < cnt; i++ ) { - sfbOffset[i] = min( specStartOffset, L_frameTCX ); + sfbOffset[i] = s_min( specStartOffset, L_frameTCX ); move16(); specStartOffset = add( specStartOffset, sfbWidths[i] ); - move16(); IF( GE_16( sfbOffset[i], L_frameTCX ) ) { @@ -175,7 +196,7 @@ static void ivas_lssetupconversion_mdct_init_bands_fx( *sfbCnt = i; move16(); - sfbOffset[*sfbCnt] = min( specStartOffset, L_frameTCX ); + sfbOffset[*sfbCnt] = s_min( specStartOffset, L_frameTCX ); move16(); IF( LT_16( sfbOffset[*sfbCnt], L_frameTCX ) ) @@ -184,7 +205,8 @@ static void ivas_lssetupconversion_mdct_init_bands_fx( IF( LT_16( shr( (Word16) sfbWidths[i], 1 ), nMissingBins ) ) { - ( *sfbCnt )++; + ( *sfbCnt ) = add( ( *sfbCnt ), 1 ); + move16(); } sfbOffset[*sfbCnt] = L_frameTCX; move16(); @@ -274,7 +296,6 @@ static void get_custom_ls_conversion_matrix_fx( Word16 lfe_in_idx, lfe_out_idx; Word32 dmxCoeff_LFE; - /* TODO: remove the floating point dependency */ Word32 tmp_gains[MAX_OUTPUT_CHANNELS]; lfe_in_idx = -1; @@ -286,12 +307,12 @@ static void get_custom_ls_conversion_matrix_fx( nchan_out = add( hLsSetupCustom->num_spk, hLsSetupCustom->num_lfe ); /* The below code will need to be restructured in case additional LFEs must be supported */ - IF( GT_16( hTransSetup.num_lfe, 0 ) ) + if ( hTransSetup.num_lfe > 0 ) { lfe_in_idx = hTransSetup.index_lfe[0]; move16(); } - IF( GT_16( hLsSetupCustom->num_lfe, 0 ) ) + if ( hLsSetupCustom->num_lfe > 0 ) { lfe_out_idx = hLsSetupCustom->lfe_idx[0]; move16(); @@ -323,7 +344,7 @@ static void get_custom_ls_conversion_matrix_fx( set32_fx( hLsSetUpConversion->dmxMtx_fx[ch_in], dmxCoeff_LFE, nchan_out ); } - ch_in_woLFE--; + ch_in_woLFE = sub( ch_in_woLFE, 1 ); } ELSE IF( NE_16( lfe_out_idx, ch_in ) ) { @@ -335,7 +356,7 @@ static void get_custom_ls_conversion_matrix_fx( { IF( EQ_16( lfe_out_idx, ch_out ) ) { - ch_out_woLFE--; + ch_out_woLFE = sub( ch_out_woLFE, 1 ); } ELSE { @@ -502,7 +523,15 @@ static ivas_error get_ls_conversion_matrix_fx( value = conversion_matrix_fx[k].value; move16(); - ch_in = index / nchan_out; + IF( index != 0 ) + { + ch_in = idiv1616( index, nchan_out ); + } + ELSE + { + ch_in = 0; + move16(); + } ch_out = index % nchan_out; hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = value; @@ -652,40 +681,28 @@ ivas_error ivas_ls_setup_conversion_open_fx( IF( EQ_32( st_ivas->renderer_type, RENDERER_MC_PARAMMC ) ) { inChannels = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); - hLsSetUpConversion->sfbCnt = (Word16) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + hLsSetUpConversion->sfbCnt = (Word16) ( L_add( output_Fs, 400 ) / CLDFB_BANDWIDTH ); FOR( chIdx = 0; chIdx < outChannels; chIdx++ ) { - IF( ( hLsSetUpConversion->targetEnergyPrev_fx[chIdx] = (Word32 *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( Word32 ) ) ) == NULL ) + IF( ( hLsSetUpConversion->targetEnergyPrev_fx[chIdx] = (Word32 *) malloc( hLsSetUpConversion->sfbCnt * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); } - IF( ( hLsSetUpConversion->dmxEnergyPrev_fx[chIdx] = (Word32 *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( Word32 ) ) ) == NULL ) + IF( ( hLsSetUpConversion->dmxEnergyPrev_fx[chIdx] = (Word32 *) malloc( hLsSetUpConversion->sfbCnt * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); } set32_fx( hLsSetUpConversion->targetEnergyPrev_fx[chIdx], 0, hLsSetUpConversion->sfbCnt ); hLsSetUpConversion->te_prev_exp = 0; + move16(); set32_fx( hLsSetUpConversion->dmxEnergyPrev_fx[chIdx], 0, hLsSetUpConversion->sfbCnt ); hLsSetUpConversion->dmx_prev_exp = 0; - /* TODO: remove the floating point dependency */ - // IF( ( hLsSetUpConversion->targetEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) - //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - // } - // IF( ( hLsSetUpConversion->dmxEnergyPrev[chIdx] = (float *) malloc( ( hLsSetUpConversion->sfbCnt ) * sizeof( float ) ) ) == NULL ) - //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - // } - // set_f( hLsSetUpConversion->targetEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); - // set_f( hLsSetUpConversion->dmxEnergyPrev[chIdx], 0.0f, hLsSetUpConversion->sfbCnt ); + move16(); } FOR( ; chIdx < MAX_CICP_CHANNELS; chIdx++ ) { hLsSetUpConversion->targetEnergyPrev_fx[chIdx] = NULL; hLsSetUpConversion->dmxEnergyPrev_fx[chIdx] = NULL; - /* TODO: remove the floating point dependency */ - // hLsSetUpConversion->targetEnergyPrev[chIdx] = NULL; - // hLsSetUpConversion->dmxEnergyPrev[chIdx] = NULL; } } ELSE @@ -718,29 +735,14 @@ ivas_error ivas_ls_setup_conversion_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); } - /* TODO: remove the floating point dependency */ - // IF( ( hLsSetUpConversion->targetEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) - //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - // } - // IF( ( hLsSetUpConversion->dmxEnergyPrev[0] = (float *) malloc( ( MAX_SFB + 2 ) * sizeof( float ) ) ) == NULL ) - //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LS configuration Conversion Handle \n" ) ); - // } FOR( chIdx = 1; chIdx < MAX_CICP_CHANNELS; chIdx++ ) { hLsSetUpConversion->targetEnergyPrev_fx[chIdx] = NULL; hLsSetUpConversion->dmxEnergyPrev_fx[chIdx] = NULL; - /* TODO: remove the floating point dependency */ - // hLsSetUpConversion->targetEnergyPrev[chIdx] = NULL; - // hLsSetUpConversion->dmxEnergyPrev[chIdx] = NULL; } set32_fx( hLsSetUpConversion->targetEnergyPrev_fx[0], 0, MAX_SFB + 2 ); set32_fx( hLsSetUpConversion->dmxEnergyPrev_fx[0], 0, MAX_SFB + 2 ); - /* TODO: remove the floating point dependency */ - // set_f( hLsSetUpConversion->targetEnergyPrev[0], 0.0f, MAX_SFB + 2 ); - // set_f( hLsSetUpConversion->dmxEnergyPrev[0], 0.0f, MAX_SFB + 2 ); } /* Initialize the DMX conversion matrix */ @@ -752,21 +754,11 @@ ivas_error ivas_ls_setup_conversion_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for temp dmx matrix \n" ) ); } set32_fx( hLsSetUpConversion->dmxMtx_fx[chIdx], 0, outChannels ); - - /* TODO: remove the floating point dependency */ - /* Allocate memory depending on the number of output channels */ - // IF( ( hLsSetUpConversion->dmxMtx[chIdx] = (float *) malloc( outChannels * sizeof( float ) ) ) == NULL ) - //{ - // return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR temp dmx matrix \n" ) ); - // } - // set_zero( hLsSetUpConversion->dmxMtx[chIdx], outChannels ); } FOR( ; chIdx < MAX_CICP_CHANNELS; chIdx++ ) { hLsSetUpConversion->dmxMtx_fx[chIdx] = NULL; - /* TODO: remove the floating point dependency */ - // hLsSetUpConversion->dmxMtx[chIdx] = NULL; } IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) @@ -792,15 +784,6 @@ ivas_error ivas_ls_setup_conversion_open_fx( } } - /* TODO: remove the floating point dependency */ - FOR( Word16 i = 0; i < inChannels; ++i ) - { - FOR( Word16 j = 0; j < outChannels; ++j ) - { - // hLsSetUpConversion->dmxMtx[i][j] = fix_to_float( hLsSetUpConversion->dmxMtx_fx[i][j], Q30 ); - } - } - st_ivas->hLsSetUpConversion = hLsSetUpConversion; return IVAS_ERR_OK; @@ -958,7 +941,7 @@ void ivas_ls_setup_conversion_close_fx( ) { Word16 idx; - + test(); IF( hLsSetUpConversion == NULL || *hLsSetUpConversion == NULL ) { return; @@ -983,25 +966,6 @@ void ivas_ls_setup_conversion_close_fx( free( ( *hLsSetUpConversion )->dmxEnergyPrev_fx[idx] ); ( *hLsSetUpConversion )->dmxEnergyPrev_fx[idx] = NULL; } - - /* TODO: remove the floating point dependency */ - // IF( ( *hLsSetUpConversion )->dmxMtx[idx] != NULL ) - //{ - // free( ( *hLsSetUpConversion )->dmxMtx[idx] ); - // ( *hLsSetUpConversion )->dmxMtx[idx] = NULL; - // } - - // IF( ( *hLsSetUpConversion )->targetEnergyPrev[idx] != NULL ) - //{ - // free( ( *hLsSetUpConversion )->targetEnergyPrev[idx] ); - // ( *hLsSetUpConversion )->targetEnergyPrev[idx] = NULL; - // } - - // IF( ( *hLsSetUpConversion )->dmxEnergyPrev[idx] != NULL ) - //{ - // free( ( *hLsSetUpConversion )->dmxEnergyPrev[idx] ); - // ( *hLsSetUpConversion )->dmxEnergyPrev[idx] = NULL; - // } } free( *hLsSetUpConversion ); @@ -1083,7 +1047,7 @@ void ivas_ls_setup_conversion_fx( dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; move32(); - IF( EQ_32( dmxCoeff, 0 ) ) + IF( dmxCoeff == 0 ) { CONTINUE; } @@ -1222,6 +1186,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( // Scale the array Word16 q_output = 31; + move16(); FOR( i = 0; i < inChannels; ++i ) { q_output = s_min( q_output, L_norm_arr( output[i], L_FRAME48k ) ); @@ -1243,7 +1208,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { x[chInIdx][0] = output[chInIdx]; - x[chInIdx][1] = output[chInIdx] + ( L_FRAME48k / 2 ); + x[chInIdx][1] = output[chInIdx] + L_FRAME48k / 2; } /* Assign all the declared handles*/ @@ -1300,8 +1265,10 @@ void ivas_ls_setup_conversion_process_mdct_fx( /* Convert the signal resolution to TCX20 */ /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - sig[0] = pTmp[0] = x[chInIdx][0]; - sig[1] = pTmp[1] = x[chInIdx][1]; + pTmp[0] = x[chInIdx][0]; + sig[0] = pTmp[0]; + pTmp[1] = x[chInIdx][1]; + sig[1] = pTmp[1]; /* convert (sub)frames to higher frequency resolution */ IF( NE_16( transform_type[chInIdx][0], TCX_20 ) ) @@ -1311,8 +1278,9 @@ void ivas_ls_setup_conversion_process_mdct_fx( IF( EQ_16( transform_type[chInIdx][subFrameIdx], TCX_5 ) ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp[subFrameIdx] = sig[subFrameIdx] = convertRes + subFrameIdx * frameSize / 2; - convert_coeffs_to_higher_res_fx( x[chInIdx][subFrameIdx], x[chInIdx][subFrameIdx] + frameSize / 4, pTmp[subFrameIdx], frameSize / 4 ); + sig[subFrameIdx] = convertRes + L_shr( L_mult0( subFrameIdx, frameSize ), 1 ); + pTmp[subFrameIdx] = sig[subFrameIdx]; + convert_coeffs_to_higher_res_fx( x[chInIdx][subFrameIdx], x[chInIdx][subFrameIdx] + shr( frameSize, 2 ), pTmp[subFrameIdx], shr( frameSize, 2 ) ); } } @@ -1389,16 +1357,18 @@ void ivas_ls_setup_conversion_process_mdct_fx( /* Step 3: Peform energy smoothing */ FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - targetEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, targetEnergy[bandIdx] ), Mpy_32_32( L_sub( ONE_IN_Q31, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] ) ); + targetEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, targetEnergy[bandIdx] ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] ) ); move32(); - dmxEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[bandIdx] ), Mpy_32_32( L_sub( ONE_IN_Q31, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] ) ); + dmxEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[bandIdx] ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] ) ); move32(); hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy[bandIdx]; move32(); hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; move32(); hLsSetUpConversion->te_prev_exp = 31; + move16(); hLsSetUpConversion->dmx_prev_exp = 31; + move16(); } FOR( i = 0; i < inChannels; ++i ) @@ -1406,6 +1376,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( j = 0; j < L_FRAME48k; ++j ) { output[i][j] = L_shr( output[i][j], q_output ); + move32(); } } @@ -1797,16 +1768,20 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( idx = 0; idx < CPE_CHANNELS; idx++ ) { /* get the channel index */ - chInIdx = add( imult1616( cpe_idx, CPE_CHANNELS ), idx ); + chInIdx = add( cpe_idx * CPE_CHANNELS, idx ); assert( chInIdx <= nchan_transport ); transform_type[chInIdx][0] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[0]; + move16(); transform_type[chInIdx][1] = hCPE[cpe_idx]->hCoreCoder[idx]->transform_type[1]; + move16(); mct_chan_mode[chInIdx] = hCPE[cpe_idx]->hCoreCoder[idx]->mct_chan_mode; + move16(); } } /* set overall frequency resolution of (sub)frame to maximum of (sub)frame, requires conversion if both channels are not the same */ frameSize = hLsSetUpConversion->sfbOffset[hLsSetUpConversion->sfbCnt]; + move16(); set_zero_fx( targetEnergy_fx, MAX_SFB + 2 ); set_zero_fx( dmxEnergy_fx, MAX_SFB + 2 ); @@ -1825,7 +1800,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( IF( EQ_16( transform_type[chInIdx][subFrameIdx], TCX_5 ) ) { /* subframe is TCX5, but TCX10 or TCX20 in other channel -> convert channel with TCX5 to TCX10 resolution */ - pTmp_fx[subFrameIdx] = sig_fx[chInIdx][subFrameIdx] = convertRes_fx[chInIdx] + subFrameIdx * frameSize / 2; + pTmp_fx[subFrameIdx] = sig_fx[chInIdx][subFrameIdx] = convertRes_fx[chInIdx] + L_mult0( subFrameIdx, frameSize ) / 2; convert_coeffs_to_higher_res_fx( x_fx[chInIdx][subFrameIdx], x_fx[chInIdx][subFrameIdx] + frameSize / 4, pTmp_fx[subFrameIdx], frameSize / 4 ); /*Q=31-x_e[chInIdx][subFrameIdx]*/ } } @@ -1839,6 +1814,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( } } Word16 input_exp, output_exp = 0; + move16(); /* precalculate MDST estimate */ FOR( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) @@ -1846,9 +1822,11 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( IF( NE_16( mct_chan_mode[chInIdx], MCT_CHAN_MODE_IGNORE ) ) { mdst_fx[chInIdx][0] = mdst_fx[chInIdx][frameSize - 1] = 0; + move32(); FOR( i = 1; i < frameSize - 1; i++ ) { mdst_fx[chInIdx][i] = L_sub( sig_fx[chInIdx][0][i + 1], sig_fx[chInIdx][0][i - 1] ); /*Q=31-x_e[chInIdx][0]*/ + move32(); } } } @@ -1862,6 +1840,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( set_zero_fx( Nrqq_fx, MAX_OUTPUT_CHANNELS ); set_zero_fx( target_ch_ener_fx, MAX_OUTPUT_CHANNELS ); Word16 max_e = 0; + move16(); FOR( idx = 0; idx < nchan_transport; idx++ ) { IF( NE_16( mct_chan_mode[idx], MCT_CHAN_MODE_IGNORE ) ) @@ -1877,34 +1856,43 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( set_zero_fx( imag_buffer_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); start = hLsSetUpConversion->sfbOffset[bandIdx]; + move16(); stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; + move16(); num_bands = sub( stop, start ); FOR( i = 0; i < num_bands; i++ ) { - band = start + i; + band = add( start, i ); FOR( idx = 0; idx < nchan_transport; idx++ ) { - IF( mct_chan_mode[idx] != MCT_CHAN_MODE_IGNORE ) + IF( NE_16( mct_chan_mode[idx], MCT_CHAN_MODE_IGNORE ) ) { - real_in_buffer_fx[i + num_bands * idx] = L_shr( sig_fx[idx][0][band], max_e - x_e[idx][0] ); /*Setting the exponent to max_e*/ - imag_in_buffer_fx[i + num_bands * idx] = L_shr( mdst_fx[idx][band], max_e - x_e[idx][0] ); /*Setting the exponent to max_e*/ + real_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( sig_fx[idx][0][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + imag_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( mdst_fx[idx][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + move32(); + move32(); } } } Word16 shift = 1; - FOR( i = 0; i < num_bands * nchan_transport; ++i ) + FOR( i = 0; i < i_mult( num_bands, nchan_transport ); ++i ) { real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], shift ); + move32(); imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], shift ); + move32(); } input_exp = max_e; + move16(); input_exp = add( input_exp, shift ); cmplx_matrix_square_fx( real_in_buffer_fx, imag_in_buffer_fx, num_bands, nchan_transport, real_buffer_fx, imag_buffer_fx, input_exp, &output_exp ); - v_add_32( cx_fx[bandIdx], real_buffer_fx, cx_fx[bandIdx], nchan_transport * nchan_transport ); /*Q=Q_real_buffer=Q_imag_buffer=output_exp*/ - v_add_32( cx_imag_fx[bandIdx], imag_buffer_fx, cx_imag_fx[bandIdx], nchan_transport * nchan_transport ); /*Q=Q_real_buffer=Q_imag_buffer=output_exp*/ + v_add_32( cx_fx[bandIdx], real_buffer_fx, cx_fx[bandIdx], i_mult( nchan_transport, nchan_transport ) ); /*Q=Q_real_buffer=Q_imag_buffer=output_exp*/ + v_add_32( cx_imag_fx[bandIdx], imag_buffer_fx, cx_imag_fx[bandIdx], i_mult( nchan_transport, nchan_transport ) ); /*Q=Q_real_buffer=Q_imag_buffer=output_exp*/ } Word16 exp_in = 10, exp_out = 0; + move16(); + move16(); FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { DMXEne_fx = 0; @@ -1916,17 +1904,20 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) { Word32 ref_ener_fx = 0; + move32(); Word16 ref_channel_cnt; Word16 ref_channel_idx; FOR( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[chInIdx]; ref_channel_cnt++ ) { ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[chInIdx][ref_channel_cnt]; - ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][ref_channel_idx + ref_channel_idx * nchan_transport] ); /*Exponent=output_exp*/ + move16(); + ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][add( ref_channel_idx, i_mult( ref_channel_idx, nchan_transport ) )] ); /*Exponent=output_exp*/ } Word32 temp; temp = BASOP_util_Pow2( L_mult0( ild_q_fx[chInIdx], 2721 /*log2(10)*(2^13)/10*/ ), exp_in, &exp_out ); - Nrqq_fx[hParamMC->hMetadataPMC->ild_mapping_conf->ild_index[chInIdx]] = L_shr( Mpy_32_16_1( ref_ener_fx, (Word16) Mpy_32_32( temp, hParamMC->hMetadataPMC->ild_factors_fx[chInIdx] ) ), 2 - exp_out ); /*exp=output_exp*/ + Nrqq_fx[hParamMC->hMetadataPMC->ild_mapping_conf->ild_index[chInIdx]] = L_shr( Mpy_32_16_1( ref_ener_fx, extract_l( Mpy_32_32( temp, hParamMC->hMetadataPMC->ild_factors_fx[chInIdx] ) ) ), sub( 2, exp_out ) ); /*exp=output_exp*/ + move32(); } /* Step 1.3 get target Cy like in ivas_param_mc_get_mono_stereo_mixing_matrices() (with dmx matrix from CICPX to MONO/STEREO saved in hParamMC) */ @@ -1934,22 +1925,25 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { FOR( i = 0; i < nchan_transport_format; i++ ) { - IF( EQ_32( hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out], 32768 ) ) - hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out] = 32767; - target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], Mpy_32_16_1( Nrqq_fx[i], (Word16) hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + i * nchan_out] ) ); /*output_exp + 2*/ + target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], L_shl( Mpy_32_32( Nrqq_fx[i], hParamMC->ls_conv_dmx_matrix_fx[add( chOutIdx, i_mult( i, nchan_out ) )] ), 1 ) ); /*output_exp + 2*/ + move32(); } - cy_fx[chOutIdx + nchan_out * chOutIdx] = target_ch_ener_fx[chOutIdx]; + cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] = target_ch_ener_fx[chOutIdx]; + move32(); } /* Step 1.4 final target energy for the band would then be the sum over the diagonal of Cy*/ FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { - targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[chOutIdx + nchan_out * chOutIdx] ); /*exp=output_exp+2*/ + targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] ); /*exp=output_exp+2*/ + move32(); } /* Step 2: Calculate DMX ener */ start = hLsSetUpConversion->sfbOffset[bandIdx]; + move16(); stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; + move16(); FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { @@ -1965,17 +1959,20 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( /* Loop over all the bins in the band */ FOR( binIdx = start; binIdx < stop; binIdx++ ) { - tmpDMXSig_fx = Mult_32_32( dmxCoeff_fx, L_shr( sig_fx[chInIdx][0][binIdx], max_e - x_e[chInIdx][0] ) ); /*max_e+1*/ + tmpDMXSig_fx = Mult_32_32( dmxCoeff_fx, L_shr( sig_fx[chInIdx][0][binIdx], sub( max_e, x_e[chInIdx][0] ) ) ); /*max_e+1*/ dmxSignalReal_fx[binIdx] = L_add( dmxSignalReal_fx[binIdx], tmpDMXSig_fx ); + move32(); - tmpDMXSig_fx = Mult_32_32( dmxCoeff_fx, L_shr( mdst_fx[chInIdx][binIdx], max_e - x_e[chInIdx][0] ) ); /*max_e+1*/ + tmpDMXSig_fx = Mult_32_32( dmxCoeff_fx, L_shr( mdst_fx[chInIdx][binIdx], sub( max_e, x_e[chInIdx][0] ) ) ); /*max_e+1*/ dmxSignalImag_fx[binIdx] = L_add( dmxSignalImag_fx[binIdx], tmpDMXSig_fx ); + move32(); } } } } /* Loop over all the bins in the band */ DMXEne_fx = 0; + move32(); FOR( binIdx = start; binIdx < stop; binIdx++ ) { tmpReal_fx = L_shr( dmxSignalReal_fx[binIdx], 1 ); @@ -1986,18 +1983,25 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( } dmxEnergy_fx[bandIdx] = DMXEne_fx; /*2*(max_e+2)*/ + move32(); } /* Step 3: Peform energy smoothing */ FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - targetEnergy_fx[bandIdx] = L_add( Mult_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, targetEnergy_fx[bandIdx] ), Mult_32_32( L_sub( MAX_32, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx], output_exp + 2 - hLsSetUpConversion->te_prev_exp ) ) ); /*output_exp + 2*/ - dmxEnergy_fx[bandIdx] = L_add( Mult_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy_fx[bandIdx] ), Mult_32_32( L_sub( MAX_32, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx], 2 * ( max_e + 2 ) - hLsSetUpConversion->dmx_prev_exp ) ) ); /*2 * (max_e + 2)*/ + targetEnergy_fx[bandIdx] = L_add( Mult_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, targetEnergy_fx[bandIdx] ), Mult_32_32( L_sub( MAX_32, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx], add( output_exp, sub( 2, hLsSetUpConversion->te_prev_exp ) ) ) ) ); /*output_exp + 2*/ + move32(); + dmxEnergy_fx[bandIdx] = L_add( Mult_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy_fx[bandIdx] ), Mult_32_32( L_sub( MAX_32, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), L_shr( hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx], sub( shl( add( max_e, 2 ), 1 ), hLsSetUpConversion->dmx_prev_exp ) ) ) ); /*2 * (max_e + 2)*/ + move32(); hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy_fx[bandIdx]; + move32(); hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy_fx[bandIdx]; + move32(); } - hLsSetUpConversion->te_prev_exp = output_exp + 2; - hLsSetUpConversion->dmx_prev_exp = 2 * ( max_e + 2 ); + hLsSetUpConversion->te_prev_exp = add( output_exp, 2 ); + move16(); + hLsSetUpConversion->dmx_prev_exp = shl( add( max_e, 2 ), 1 ); + move16(); /* Step 4: Perform equalization */ FOR( chInIdx = 0; chInIdx < nchan_transport; chInIdx++ ) { @@ -2009,7 +2013,9 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { start = hLsSetUpConversion->sfbOffset[bandIdx]; + move16(); stop = hLsSetUpConversion->sfbOffset[bandIdx + 1]; + move16(); /*Compute Eq gains */ ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy_fx[bandIdx], &dmxEnergy_fx[bandIdx], &eqGain_fx ); @@ -2023,10 +2029,11 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( ELSE { stop_tcx5 = 0; + move16(); FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - start = hLsSetUpConversion->sfbOffset[bandIdx] / 2; - stop = hLsSetUpConversion->sfbOffset[bandIdx + 1] / 2; + start = shr( hLsSetUpConversion->sfbOffset[bandIdx], 1 ); + stop = shr( hLsSetUpConversion->sfbOffset[bandIdx + 1], 1 ); /*Compute Eq gains */ ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy_fx[bandIdx], &dmxEnergy_fx[bandIdx], &eqGain_fx ); @@ -2040,21 +2047,25 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( binIdx = start; binIdx < stop; binIdx++ ) { x_fx[chInIdx][subFrameIdx][binIdx] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx], eqGain_fx ), 1 ); + move32(); } } ELSE { /* TCX5*/ start_tcx5 = stop_tcx5; - stop_tcx5 = ( stop + 1 ) / 2; + move16(); + stop_tcx5 = shr( add( stop, 1 ), 1 ); FOR( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { x_fx[chInIdx][subFrameIdx][binIdx] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx], eqGain_fx ), 1 ); + move32(); } FOR( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )], eqGain_fx ), 1 ); + x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )], eqGain_fx ), 1 ); + move32(); } } } @@ -2463,9 +2474,9 @@ void ivas_lssetupconversion_process_param_mc_fx( push_wmops( "LS_Renderer_Process_Param_MC" ); /* inits */ - inChannels = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; + inChannels = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); move16(); - outChannels = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + outChannels = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); move16(); hLsSetUpConversion = st_ivas->hLsSetUpConversion; @@ -2519,7 +2530,7 @@ void ivas_lssetupconversion_process_param_mc_fx( { dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; move32(); - IF( EQ_32( dmxCoeff, 0 ) ) + IF( dmxCoeff == 0 ) { CONTINUE; } @@ -2578,7 +2589,9 @@ void ivas_lssetupconversion_process_param_mc_fx( hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; move32(); hLsSetUpConversion->te_prev_exp = 31; + move16(); hLsSetUpConversion->dmx_prev_exp = 31; + move16(); } } } diff --git a/lib_dec/ivas_pca_dec_fx.c b/lib_dec/ivas_pca_dec_fx.c index 58aa5d04d..40052469b 100644 --- a/lib_dec/ivas_pca_dec_fx.c +++ b/lib_dec/ivas_pca_dec_fx.c @@ -52,10 +52,10 @@ static Word32 ivas_bitstream_read_int32_fx( Word32 val; /* MSB */ - val = get_next_indice_fx( st0, bits - 16 ) << 16; + val = L_shl( get_next_indice_fx( st0, sub( bits, 16 ) ), 16 ); /* + LSB */ - val += get_next_indice_fx( st0, 16 ); + val = L_add( val, get_next_indice_fx( st0, 16 ) ); return val; } @@ -65,10 +65,10 @@ static void pca_dec_reset_dquat_fx( Word16 *qr_fx ) { set16_fx( ql_fx, 0, IVAS_PCA_INTERP ); - ql_fx[0] = 32767; + ql_fx[0] = MAX_16; move16(); set16_fx( qr_fx, 0, IVAS_PCA_INTERP ); - qr_fx[0] = 32767; + qr_fx[0] = MAX_16; move16(); return; } @@ -81,7 +81,7 @@ static void pca_dec_reset_mem_eigvec_fx( FOR( i = 0; i < shr( IVAS_PCA_LEN_INTERP_EIG_DEC, 4 ); i++ ) { - eye_matrix_fx( &hPCA->mem_eigVec_interp_fx[16 * i], FOA_CHANNELS, 32767 ); + eye_matrix_fx( &hPCA->mem_eigVec_interp_fx[i_mult( 16, i )], FOA_CHANNELS, MAX_16 ); } return; @@ -103,19 +103,20 @@ static void pca_inv_transform_sub_fx( { FOR( k = 0; k < n_channels; k++ ) { - buffer_data[k] = transformed_data[k][j + start]; + buffer_data[k] = transformed_data[k][add( j, start )]; move32(); } FOR( k = 0; k < n_channels; k++ ) { temp = 0; + move32(); FOR( i = 0; i < n_channels; i++ ) { - temp2 = Mpy_32_16_1( buffer_data[i], eigVec[k * IVAS_PCA_INTERP + i] ); + temp2 = Mpy_32_16_1( buffer_data[i], eigVec[add( k * IVAS_PCA_INTERP, i )] ); temp = L_add( temp, temp2 ); } - transformed_data[k][j + start] = temp; + transformed_data[k][add( j, start )] = temp; move32(); } } @@ -140,12 +141,12 @@ static void pca_dec_inv_transform_fx( pca_interp_preproc_fx( hPCA->prev_ql_fx, hPCA->prev_qr_fx, ql_fx, qr_fx, IVAS_PCA_N_SLOTS, ql_interp_fx, qr_interp_fx ); - slot_len = (Word16) ( n_samples / IVAS_PCA_N_SLOTS ); - move16(); - for ( j = 0; j < IVAS_PCA_N_SLOTS; j++ ) + slot_len = idiv1616( n_samples, IVAS_PCA_N_SLOTS ); + + FOR( j = 0; j < IVAS_PCA_N_SLOTS; j++ ) { /* convert from double quaternion to 4D matrix */ - dquat2mat_fx( &ql_interp_fx[4 * j], &qr_interp_fx[4 * j], &hPCA->mem_eigVec_interp_fx[16 * j + IVAS_PCA_DELAY_CMP * 16] ); + dquat2mat_fx( &ql_interp_fx[4 * j], &qr_interp_fx[4 * j], &hPCA->mem_eigVec_interp_fx[add( 16 * j, IVAS_PCA_DELAY_CMP * 16 )] ); pca_inv_transform_sub_fx( &hPCA->mem_eigVec_interp_fx[16 * j], decoded_data, slot_len * j, slot_len, n_channels ); } @@ -235,11 +236,15 @@ void ivas_pca_dec_fx( /* @@@TODO: check how ivas_total_brate is set if bfi == 1 */ // ToDo: and what happens in DTX where "ivas_total_brate" can be close to zero? /* handle bit rate switching */ + test(); + test(); IF( NE_32( ivas_total_brate, PCA_BRATE ) || ( EQ_32( ivas_total_brate, PCA_BRATE ) && GT_16( n_channels, FOA_CHANNELS ) ) ) { /* set PCA by-pass mode in current frame and interpolate transform as previous frame used PCA */ pca_dec_reset_dquat_fx( ql_fx, qr_fx ); + test(); + test(); IF( ( NE_32( last_ivas_total_brate, PCA_BRATE ) ) || ( EQ_32( last_ivas_total_brate, PCA_BRATE ) && GT_16( hPCA->prev_pca_bypass, 1 ) ) ) { pca_dec_reset_mem_eigvec_fx( hPCA ); @@ -253,7 +258,7 @@ void ivas_pca_dec_fx( hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); move16(); - IF( GT_16( hPCA->prev_pca_bypass, 2 ) ) + if ( GT_16( hPCA->prev_pca_bypass, 2 ) ) { hPCA->prev_pca_bypass = 2; move16(); @@ -262,7 +267,7 @@ void ivas_pca_dec_fx( return; } - IF( !bfi ) + IF( bfi == 0 ) { /* set PCA by-pass mode indicator */ pca_bypass = hPCA->pca_bypass; @@ -291,12 +296,13 @@ void ivas_pca_dec_fx( pca_dec_update_dquat_fx( hPCA, ql_fx, qr_fx ); hPCA->prev_pca_bypass = add( hPCA->prev_pca_bypass, 1 ); - hPCA->prev_pca_bypass = min( hPCA->prev_pca_bypass, 2 ); + move16(); + hPCA->prev_pca_bypass = s_min( hPCA->prev_pca_bypass, 2 ); move16(); return; // exit happens here } - IF( !bfi ) + IF( bfi == 0 ) { pca_dec_s3_fx( hPCA->index[0], ql_fx ); pca_dec_s3_fx( hPCA->index[1], qr_fx ); diff --git a/lib_dec/ivas_post_proc.c b/lib_dec/ivas_post_proc.c index 297708375..694bc5320 100644 --- a/lib_dec/ivas_post_proc.c +++ b/lib_dec/ivas_post_proc.c @@ -177,13 +177,20 @@ void ivas_post_proc_fx( } output_Fs = sts[0]->output_Fs; + move32(); + test(); + test(); + test(); + test(); + test(); IF( ( NE_16( sts[n]->element_mode, IVAS_CPE_DFT ) && !( sba_dirac_stereo_flag && NE_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) ) || ( EQ_16( sts[n]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { IF( sts[n]->hTcxLtpDec != NULL ) { hTcxLtpDec = sts[n]->hTcxLtpDec; + test(); IF( NE_16( sts[n]->core, TCX_20_CORE ) && NE_16( sts[n]->core, TCX_10_CORE ) ) { /* TCX-LTP Postfilter: used in Mode 1 to update memories and to avoid discontinuities when the past frame was TCX */ @@ -193,19 +200,25 @@ void ivas_post_proc_fx( { /* set delay */ delay_comp = NS2SA_fx2( output_Fs, DELAY_CLDFB_NS ); + move16(); - IF( !( EQ_16( sts[n]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) && NE_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( EQ_16( sts[n]->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ), 0 ) && NE_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) { // mvr2r( sts[n]->prev_synth_buffer32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32, 0 ); - Copy32( sts[n]->delay_buf_out32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32 + 0, delay_comp ); + Copy32( sts[n]->delay_buf_out32_fx, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); } ELSE IF( sba_dirac_stereo_flag && EQ_16( sts[n]->element_mode, IVAS_CPE_MDCT ) ) { Word16 numZeros = (Word16) ( NS2SA_fx2( output_Fs, N_ZERO_MDCT_NS ) ); + move16(); Copy32( sts[n]->hHQ_core->oldOut_fx + numZeros, sts[n]->hTcxDec->FBTCXdelayBuf_32, delay_comp ); } - tcx_ltp_post32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, NS2SA_fx2( output_Fs, ACELP_LOOK_NS ) + delay_comp, synth, sts[n]->hTcxDec->FBTCXdelayBuf_32 ); + tcx_ltp_post32( sts[n], hTcxLtpDec, sts[n]->core, output_frame, add( NS2SA_fx2( output_Fs, ACELP_LOOK_NS ), delay_comp ), synth, sts[n]->hTcxDec->FBTCXdelayBuf_32 ); } } } @@ -214,9 +227,10 @@ void ivas_post_proc_fx( Word16 pit_res_max_past_tmp; pit_res_max_past_tmp = sts[0]->pit_res_max_past; + move16(); FOR( k = 0; k < hCPE->nchan_out; k++ ) { - IF( EQ_16( k, 0 ) ) + IF( k == 0 ) { hTcxLtpDec = sts[0]->hTcxLtpDec; } @@ -225,11 +239,16 @@ void ivas_post_proc_fx( hTcxLtpDec = hCPE->hStereoDft->hTcxLtpDec; /* copy LTP side-info of downmix channel also to right channel struct */ hTcxLtpDec->tcxltp = sts[0]->hTcxLtpDec->tcxltp; + move16(); hTcxLtpDec->tcxltp_gain = sts[0]->hTcxLtpDec->tcxltp_gain; + move16(); hTcxLtpDec->tcxltp_pitch_int = sts[0]->hTcxLtpDec->tcxltp_pitch_int; + move16(); hTcxLtpDec->tcxltp_pitch_fr = sts[0]->hTcxLtpDec->tcxltp_pitch_fr; + move16(); /* revert update of pit_res_max_past to have correct value also in right channel */ sts[0]->pit_res_max_past = pit_res_max_past_tmp; + move16(); } /*TCX-LTP*/ @@ -286,19 +305,25 @@ void stereo_dft_dec_core_switching_fx( st = hCPE->hCoreCoder[0]; /* in DFT stereo, only M channel is decoded by the CoreCoder */ output_Fs = st->output_Fs; + move32(); L_frameTCX = st->hTcxDec->L_frameTCX; + move16(); /*TBE*/ delay_tdbwe = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); + move16(); delay_dft_dec = NS2SA( output_Fs, STEREO_DFT_DELAY_DEC_BWE_NS ); - delay_dft_dec_lb = NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT_DELAY_DEC_BWE_NS ); + move16(); + delay_dft_dec_lb = NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT_DELAY_DEC_BWE_NS ); + move16(); /* TCX/ACELP/HQ-CORE->TCX */ - tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ FB*/ - delay_comp = NS2SA( st->L_frame * FRAMES_PER_SEC, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/ + tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); /*cross-fading size @ FB*/ + move16(); + delay_comp = NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), DELAY_BWE_TOTAL_NS ); /*cross-fading size @ LB*/ + move16(); - calc_inv = 1; - calc_inv = calc_inv << 31; + calc_inv = W_shl( 1, 31 ); // Memory Tables ////////////////////////////////////////////////////////////////////////////// @@ -306,17 +331,22 @@ void stereo_dft_dec_core_switching_fx( Word32 delay_comp_inv_tbl[] = { 2147483647, 306783378, 153391689, 97612893, 74051160, 58040098, 48806446, 42107522, 36398027, 32537631, 29020049 }; /////////////////////////////////////////////////////////////////////////////////////////////// - IF( st->last_L_frame != st->L_frame && st->last_L_frame <= L_FRAME16k && st->L_frame <= L_FRAME16k ) + test(); + test(); + IF( NE_16( st->last_L_frame, st->L_frame ) && LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) { - L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); - L_lerp_fx_q11( hCPE->input_mem_BPF_fx[0], hCPE->input_mem_BPF_fx[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA( L_mult0( st->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + L_lerp_fx_q11( hCPE->input_mem_BPF_fx[0], hCPE->input_mem_BPF_fx[0], NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA( L_mult0( st->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); } - IF( st->prev_bfi && !( st->last_core_bfi == ACELP_CORE && st->last_con_tcx == 1 ) ) + test(); + test(); + if ( ( st->prev_bfi != 0 ) && EQ_16( EQ_16( st->last_core_bfi, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) ) { /* last_core needed FOR correctly decoding ACELP->TCX/HQ switching frames in ivas_core_dec(). In the following steps the decoder needs to consider IF the core was changed due to a lost frame to apply the correct transition */ st->last_core = st->last_core_bfi; + move16(); } #ifndef MSAN_FIX @@ -326,15 +356,28 @@ void stereo_dft_dec_core_switching_fx( } #endif - IF( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE || ( st->bfi == 1 && st->core == ACELP_CORE && st->con_tcx == 1 ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) ) { - IF( ( ( st->last_core != ACELP_CORE || ( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) && st->last_core != AMR_WB_CORE ) || ( sba_dirac_stereo_dtx_flag && st->cng_type == FD_CNG ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( NE_16( st->last_core, ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( sba_dirac_stereo_dtx_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */ { /* In case of a TCX to ACELP switch next frame */ - Copy32( &output_fx[st->L_frame - NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + Copy32( &output_fx[st->L_frame - NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /* BPF */ - IF( st->p_bpf_noise_buf_32 && st->core != HQ_CORE ) + test(); + test(); + IF( st->p_bpf_noise_buf_32 && NE_16( st->core, HQ_CORE ) ) { #ifdef MSAN_FIX Scale_sig32( st->p_bpf_noise_buf_32, st->L_frame, sub( *q, Q11 ) ); @@ -342,7 +385,7 @@ void stereo_dft_dec_core_switching_fx( stereo_dft_dec_analyze_fx( hCPE, st->p_bpf_noise_buf_32, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_BPF, 2, 0, q, q_DFT ); } /* st->p_bpf_noise_buf not updated FOR HQ core -> skip analysis and set input memory to zero */ - ELSE IF( st->p_bpf_noise_buf_32 && st->core == HQ_CORE ) + ELSE IF( st->p_bpf_noise_buf_32 && EQ_16( st->core, HQ_CORE ) ) { set32_fx( hCPE->input_mem_BPF_fx[0], 0, STEREO_DFT32MS_OVL_16k ); } @@ -350,25 +393,31 @@ void stereo_dft_dec_core_switching_fx( /* TCX */ stereo_dft_dec_analyze_fx( hCPE, synth_fx, DFT_fx, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, q, q_DFT ); } - ELSE IF( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) /* ACELP -> TCX/HQ */ + ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */ { - IF( st->last_core_brate <= SID_2k40 && st->element_mode == IVAS_SCE ) + test(); + IF( LE_32( st->last_core_brate, SID_2k40 ) && LE_16( st->element_mode, IVAS_SCE ) ) { - Word32 mem_len = NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); - Word32 mem_len_inv = mem_len_inv_tbl[mem_len / 25]; + Word16 mem_len = NS2SA( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + move16(); + Word32 mem_len_inv = mem_len_inv_tbl[idiv1616( mem_len, 25 )]; + move32(); Word16 qmem_len = norm_l( mem_len ); Word32 mem_len_fx = L_shl( mem_len, qmem_len ); FOR( i = 0; i < mem_len; i++ ) { - hCPE->input_mem_fx[0][i] = Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_fx - i * ( 1 << qmem_len ) ); - hCPE->input_mem_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_inv ), 31 - qmem_len ); + hCPE->input_mem_fx[0][i] = Mpy_32_32( hCPE->input_mem_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); + move32(); + hCPE->input_mem_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); + move32(); } /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */ FOR( i = 0; i < delay_tdbwe; i++ ) { - hCPE->input_mem_fx[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] = - L_add( hCPE->input_mem_fx[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i], hb_synth_fx[i] ); + hCPE->input_mem_fx[0][add( sub( NS2SA( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )] = + L_add( hCPE->input_mem_fx[0][NS2SA( L_add( L_sub( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )], hb_synth_fx[i] ); + move32(); } } ELSE @@ -376,7 +425,8 @@ void stereo_dft_dec_core_switching_fx( /* Update FB input buff with hb synth FOR last delay_tdbwe sampled */ FOR( i = 0; i < delay_tdbwe; i++ ) { - hCPE->input_mem_fx[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_tdbwe + i] = hb_synth_fx[i]; + hCPE->input_mem_fx[0][add( sub( NS2SA( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_tdbwe ), i )] = hb_synth_fx[i]; + move32(); } } @@ -387,40 +437,46 @@ void stereo_dft_dec_core_switching_fx( Word32 tmps_inv = (Word32) ( calc_inv / tmps ); FOR( i = 0; i < tmps; i++ ) { - synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[i + delay_tdbwe], tmps_fx - i * ( 1 << qtmps ) ), Mpy_32_32( synth_fx[i], i * ( 1 << qtmps ) ) ); - synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], tmps_inv ), 31 - qtmps ); + synth_tmp_fx[i] = L_add( Mpy_32_32( hb_synth_fx[add( i, delay_tdbwe )], L_sub( tmps_fx, L_shl( i, qtmps ) ) ), Mpy_32_32( synth_fx[i], L_shl( i, qtmps ) ) ); + move32(); + synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], tmps_inv ), sub( 31, qtmps ) ); + move32(); } /* FB-TCX */ stereo_dft_dec_analyze_fx( hCPE, synth_tmp_fx, DFT_fx, 0, L_frameTCX, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, q, q_DFT ); - IF( !st->tcxonly ) + IF( st->tcxonly == 0 ) { - IF( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) + IF( EQ_16( hCPE->hStereoDft->hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) ) { Copy32( output_fx, tcx_core_buf_fx, L_FRAME16k ); } /* fading-out LB-TCX/ACELP */ Word16 qdelay_comp = norm_l( delay_comp ); - Word32 delay_comp_inv = delay_comp_inv_tbl[delay_comp / 7]; + Word32 delay_comp_inv = delay_comp_inv_tbl[idiv1616( delay_comp, 7 )]; + move32(); Word32 delay_comp_fx = L_shl( delay_comp, qdelay_comp ); FOR( i = 0; i < delay_comp; i++ ) { - output_fx[i] = Mpy_32_32( output_fx[i], delay_comp_fx - i * ( 1 << qdelay_comp ) ); - output_fx[i] = L_shl( Mpy_32_32( output_fx[i], delay_comp_inv ), 31 - qdelay_comp ); + output_fx[i] = Mpy_32_32( output_fx[i], L_sub( delay_comp_fx, L_shl( i, qdelay_comp ) ) ); + move32(); + output_fx[i] = L_shl( Mpy_32_32( output_fx[i], delay_comp_inv ), sub( Q31, qdelay_comp ) ); + move32(); } /* In case of TCX frames, output LB TCX is zeroed out until the end but in case of an TCX->ACELP switch, this memory is needed, hence it is backed up */ /* Unlike the case when DFT32MS is disabled, there is only 1 DFT analysis window, hence in the TCX frame we don't want to do a DFT analysis FOR LB TCX but in a potential ACELP frame, we want the memories of the LB TCX FOR the last OLA samples so that HB analysis can be skipped */ - Copy32( &output_fx[st->L_frame - NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + Copy32( &output_fx[st->L_frame - NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS )], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /*zero the rest FOR avoiding adding contribution except the last samples which are not considered in DFT analysis (potentially used in next ACELP frame)*/ - IF( st->last_core_brate > SID_2k40 ) + IF( GT_32( st->last_core_brate, SID_2k40 ) ) { FOR( ; i < st->L_frame; i++ ) { output_fx[i] = 0; + move32(); } stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB_ADD, 1, 0, q, q_DFT ); @@ -428,7 +484,7 @@ void stereo_dft_dec_core_switching_fx( /* BPF */ IF( st->p_bpf_noise_buf_32 ) { - set32_fx( hCPE->input_mem_BPF_fx[0], 0, NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + set32_fx( hCPE->input_mem_BPF_fx[0], 0, NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); } } } @@ -436,40 +492,49 @@ void stereo_dft_dec_core_switching_fx( } ELSE /* ACELP core */ { - IF( st->core_brate <= SID_2k40 && !( sba_dirac_stereo_dtx_flag ) ) + test(); + test(); + test(); + IF( LE_32( st->core_brate, SID_2k40 ) && !sba_dirac_stereo_dtx_flag ) { - set32_fx( hCPE->input_mem_fx[0], 0, NS2SA( st->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); - set32_fx( hCPE->input_mem_LB_fx[0], 0, NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + set32_fx( hCPE->input_mem_fx[0], 0, NS2SA( L_mult0( st->hTcxDec->L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); + set32_fx( hCPE->input_mem_LB_fx[0], 0, NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); /* CNG generated in ivas_cpe_dec() */ } - ELSE IF( st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE || st->last_core == HQ_CORE ) /* TCX/HQ -> ACELP */ + ELSE IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */ { - IF( ( st->last_L_frame <= L_FRAME16k && st->L_frame <= L_FRAME16k ) || ( sba_dirac_stereo_dtx_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) ) + IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( sba_dirac_stereo_dtx_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { /* In case of a TCX to ACELP switch, retrieve the LB-TCX memories FOR the first STEREO_DFT32MS_OVL_NS NS of OLA */ - L_lerp_fx_q11( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( st->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + L_lerp_fx_q11( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA( L_mult0( st->last_L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); } - IF( sba_dirac_stereo_dtx_flag && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) + IF( sba_dirac_stereo_dtx_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { Word16 nZeros; nZeros = (Word16) ( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + move16(); delay_comp = NS2SA( st->output_Fs, DELAY_CLDFB_NS ); + move16(); - Copy32( &st->hHQ_core->oldOut_fx[nZeros - delay_comp - NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )], hCPE->input_mem_fx[0], NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + Copy32( &st->hHQ_core->oldOut_fx[sub( nZeros, add( delay_comp, NS2SA( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ) )], hCPE->input_mem_fx[0], NS2SA( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); Copy32( synth_fx, synth_tmp_fx, output_frame ); Word16 mem_len; - mem_len = NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + mem_len = NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ); + move16(); Word16 qmem_len = norm_l( mem_len ); Word32 mem_len_fx = L_shl( mem_len, qmem_len ); Word32 mem_len_inv = (Word32) ( calc_inv / tmps ); + move32(); FOR( i = 0; i < mem_len; i++ ) { - hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_fx - ( i * ( 1 << qmem_len ) ) ); - hCPE->input_mem_LB_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_inv ), 31 - qmem_len ); + hCPE->input_mem_LB_fx[0][i] = Mpy_32_32( hCPE->input_mem_LB_fx[0][i], L_sub( mem_len_fx, L_shl( i, qmem_len ) ) ); + move32(); + hCPE->input_mem_LB_fx[0][i] = L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][i], mem_len_inv ), sub( Q31, qmem_len ) ); + move32(); } set32_fx( output_fx, 0, st->L_frame ); @@ -487,19 +552,22 @@ void stereo_dft_dec_core_switching_fx( ELSE { /* ACELP */ - FOR( i = 0; i < ( NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ); i++ ) + FOR( i = 0; i < ( NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb ); i++ ) { hCPE->input_mem_LB_fx[0][i] = 0; + move32(); } /* ACELP fading-in*/ Word16 qdelay_dft_dec_lb = norm_l( delay_dft_dec_lb ); Word32 delay_dft_dec_lb_inv = (Word32) ( calc_inv / delay_dft_dec_lb ); FOR( i = 0; i < delay_dft_dec_lb; i++ ) { - hCPE->input_mem_LB_fx[0][NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb + i] = - Mpy_32_32( hCPE->input_mem_LB_fx[0][NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb + i], i * ( 1 << qdelay_dft_dec_lb ) ); - hCPE->input_mem_LB_fx[0][NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb + i] = - L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec_lb + i], delay_dft_dec_lb_inv ), 31 - qdelay_dft_dec_lb ); + hCPE->input_mem_LB_fx[0][add( sub( NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )] = + Mpy_32_32( hCPE->input_mem_LB_fx[0][add( sub( NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )], L_shl( i, qdelay_dft_dec_lb ) ); + move32(); + hCPE->input_mem_LB_fx[0][add( sub( NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )] = + L_shl( Mpy_32_32( hCPE->input_mem_LB_fx[0][add( sub( NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec_lb ), i )], delay_dft_dec_lb_inv ), sub( Q31, qdelay_dft_dec_lb ) ); + move32(); } stereo_dft_dec_analyze_fx( hCPE, output_fx, DFT_fx, 0, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, q, q_DFT ); @@ -514,29 +582,34 @@ void stereo_dft_dec_core_switching_fx( /* Fading-in TD-BWE, Fading-out FB-TCX*/ Copy32( synth_fx, synth_tmp_fx, output_frame ); - IF( hCPE->last_element_mode != IVAS_CPE_MDCT ) + IF( NE_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { Word16 qdelay_dft_dec = norm_l( delay_dft_dec ); Word32 delay_dft_dec_inv = (Word32) ( calc_inv / delay_dft_dec ); Word32 delay_dft_dec_fx = L_shl( delay_dft_dec, qdelay_dft_dec ); FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade-in and TCX fade-out */ { - hCPE->input_mem_fx[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec + i] = L_add( - Mpy_32_32( hb_synth_fx[delay_tdbwe - delay_dft_dec + i], i * ( 1 << qdelay_dft_dec ) ), - Mpy_32_32( hCPE->input_mem_fx[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec + i], delay_dft_dec_fx - i * ( 1 << qdelay_dft_dec ) ) ); - hCPE->input_mem_fx[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec + i] = L_shl( - Mpy_32_32( hCPE->input_mem_fx[0][NS2SA( L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) - delay_dft_dec + i], delay_dft_dec_inv ), - 31 - qdelay_dft_dec ); + hCPE->input_mem_fx[0][add( sub( NS2SA( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )] = L_add( + Mpy_32_32( hb_synth_fx[add( sub( delay_tdbwe, delay_dft_dec ), i )], L_shl( i, qdelay_dft_dec ) ), + Mpy_32_32( hCPE->input_mem_fx[0][add( sub( NS2SA( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ) ); + move32(); + hCPE->input_mem_fx[0][add( sub( NS2SA( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )] = L_shl( + Mpy_32_32( hCPE->input_mem_fx[0][add( sub( NS2SA( L_mult0( L_frameTCX, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), delay_dft_dec ), i )], delay_dft_dec_inv ), + sub( Q31, qdelay_dft_dec ) ); + move32(); } FOR( i = 0; i < delay_dft_dec; i++ ) /* 1.25 ms of hb_synth fade out. ICBWE fade in performed in time domain here */ { - synth_tmp_fx[i] = Mpy_32_32( hb_synth_fx[delay_tdbwe - delay_dft_dec + i], delay_dft_dec_fx - i * ( 1 << qdelay_dft_dec ) ); - synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], delay_dft_dec_inv ), 31 - qdelay_dft_dec ); + synth_tmp_fx[i] = Mpy_32_32( hb_synth_fx[add( sub( delay_tdbwe, delay_dft_dec ), i )], L_sub( delay_dft_dec_fx, L_shl( i, qdelay_dft_dec ) ) ); + move32(); + synth_tmp_fx[i] = L_shl( Mpy_32_32( synth_tmp_fx[i], delay_dft_dec_inv ), sub( Q31, qdelay_dft_dec ) ); + move32(); } FOR( ; i < output_frame; i++ ) { synth_tmp_fx[i] = 0; + move32(); } } } @@ -546,7 +619,7 @@ void stereo_dft_dec_core_switching_fx( { stereo_dft_dec_analyze_fx( hCPE, synth_tmp_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0, q, q_DFT ); } - ELSE IF( hCPE->last_element_mode == IVAS_CPE_MDCT ) + ELSE IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { stereo_dft_dec_analyze_fx( hCPE, synth_tmp_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_HB_ADD, 1, 0, q, q_DFT ); } @@ -557,14 +630,18 @@ void stereo_dft_dec_core_switching_fx( } ELSE /* ACELP -> ACELP */ { - IF( sba_dirac_stereo_dtx_flag && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) + test(); + test(); + test(); + test(); + IF( sba_dirac_stereo_dtx_flag && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { set32_fx( output_fx, 0, st->L_frame ); } /* this needs an indication FOR sba2stereo in general */ - ELSE IF( hCPE->element_mode == IVAS_SCE && st->last_core_brate <= SID_2k40 && st->cng_type == FD_CNG ) + ELSE IF( EQ_16( hCPE->element_mode, IVAS_SCE ) && LE_32( st->last_core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { - L_lerp_fx_q11( hCPE->input_mem_fx[0], hCPE->input_mem_LB_fx[0], NS2SA( st->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), NS2SA( output_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); + L_lerp_fx_q11( hCPE->input_mem_fx[0], hCPE->input_mem_LB_fx[0], NS2SA( L_mult0( st->L_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), NS2SA( L_mult0( output_frame, FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ) ); } /* ACELP synthesis @ internal sampling rate */ @@ -581,13 +658,17 @@ void stereo_dft_dec_core_switching_fx( } /* BWE */ - IF( sba_dirac_stereo_dtx_flag && st->core_brate <= SID_2k40 && st->cng_type == FD_CNG ) + test(); + test(); + test(); + test(); + IF( sba_dirac_stereo_dtx_flag && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { stereo_dft_dec_analyze_fx( hCPE, synth_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 0, 0, q, q_DFT ); } - ELSE IF( st->extl != -1 || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) ) + ELSE IF( NE_16( st->extl, -1 ) || ( ( st->bws_cnt > 0 ) && EQ_16( st->core, ACELP_CORE ) ) ) { - stereo_dft_dec_analyze_fx( hCPE, hb_synth_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 2, -delay_tdbwe, q, q_DFT ); + stereo_dft_dec_analyze_fx( hCPE, hb_synth_fx, DFT_fx, 0, output_frame, output_frame, DFT_STEREO_DEC_ANA_FB_ADD, 2, negate( delay_tdbwe ), q, q_DFT ); } } } @@ -596,30 +677,46 @@ void stereo_dft_dec_core_switching_fx( * enhanced stereo filling: allpass filter *----------------------------------------------------------------*/ - IF( hCPE->hStereoDft->hConfig->res_pred_mode == STEREO_DFT_RESPRED_ESF ) + IF( EQ_16( hCPE->hStereoDft->hConfig->res_pred_mode, STEREO_DFT_RESPRED_ESF ) ) { - IF( st->sr_core == INT_FS_12k8 ) + IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) { ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_12k8; + move16(); + ap_fade_len_inv = 67108864; + move32(); } ELSE { ap_fade_len = STEREO_DFT_ALLPASS_FADELEN_16k; + move16(); + ap_fade_len_inv = 53687091; + move32(); } qap_fade_len = norm_l( ap_fade_len ); ap_fade_len_fx = L_shl( ap_fade_len, qap_fade_len ); - ap_fade_len_inv = ap_fade_len == 32 ? 67108864 : 53687091; - IF( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE || ( st->bfi == 1 && st->core == ACELP_CORE && st->con_tcx == 1 ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) ) { Word16 numZeros = (Word16) ( NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); Word32 tmp_fade_fx[max( STEREO_DFT_ALLPASS_FADELEN_12k8, STEREO_DFT_ALLPASS_FADELEN_16k )]; Copy32( st->hHQ_core->old_outLB_fx + numZeros, hCPE->hStereoDft->ap_fade_mem_fx, ap_fade_len ); hCPE->hStereoDft->q_ap_fade_mem_fx = st->hHQ_core->q_old_outLB_fx; - - IF( st->last_core == ACELP_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) && !st->tcxonly ) + move16(); + + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->last_core, ACELP_CORE ) && !( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) && !st->tcxonly ) { Copy32( tcx_core_buf_fx, pAp_input_fx, st->L_frame ); } @@ -628,34 +725,39 @@ void stereo_dft_dec_core_switching_fx( Copy32( output_fx, pAp_input_fx, st->L_frame ); } - IF( st->last_core == ACELP_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) && !st->tcxonly ) /* ACELP -> TCX/HQ-Core */ + IF( EQ_16( st->last_core, ACELP_CORE ) && EQ_16( EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ), 0 ) && !st->tcxonly ) /* ACELP -> TCX/HQ-Core */ { Copy32( tcx_core_buf_fx, tmp_fade_fx, ap_fade_len ); FOR( i = 0; i < ap_fade_len; i++ ) { pAp_input_fx[i] = L_add( - Mpy_32_32( pAp_input_fx[i], i * ( 1 << qap_fade_len ) ), - Mpy_32_32( tmp_fade_fx[i], ap_fade_len_fx - i * ( 1 << qap_fade_len ) ) ); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), 31 - qap_fade_len ); + Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ), + Mpy_32_32( tmp_fade_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); + move32(); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + move32(); } } } ELSE { Copy32( output_fx, pAp_input_fx, st->L_frame ); - IF( st->last_core != ACELP_CORE ) /* TCX/HQ-Core -> ACELP */ + IF( NE_16( st->last_core, ACELP_CORE ) ) /* TCX/HQ-Core -> ACELP */ { Word16 shift = sub( hCPE->hStereoDft->q_ap_fade_mem_fx, q_DFT[0] ); FOR( i = 0; i < ap_fade_len; i++ ) { pAp_input_fx[i] = L_add( - Mpy_32_32( pAp_input_fx[i], i * ( 1 << qap_fade_len ) ), - Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), ap_fade_len_fx - i * ( 1 << qap_fade_len ) ) ); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), 31 - qap_fade_len ); + Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ), + Mpy_32_32( L_shr( hCPE->hStereoDft->ap_fade_mem_fx[i], shift ), L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ) ); + move32(); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + move32(); } } } predelay = NS2SA( st->sr_core, DELAY_BWE_TOTAL_NS ); + move16(); /* apply predelay to have same overall filter delay FOR all cases */ @@ -672,21 +774,27 @@ void stereo_dft_dec_core_switching_fx( { FOR( i = 0; i < ap_fade_len; i++ ) { - pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], ap_fade_len_fx - i * ( 1 << qap_fade_len ) ); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), 31 - qap_fade_len ); + pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_sub( ap_fade_len_fx, L_shl( i, qap_fade_len ) ) ); + move32(); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + move32(); } } set32_fx( pAp_input_fx + ap_fade_len, 0, st->L_frame - ap_fade_len ); hCPE->hStereoDft->ap_wasTransient = 1; + move16(); } ELSE IF( hCPE->hStereoDft->ap_wasTransient ) { FOR( i = 0; i < ap_fade_len; i++ ) { - pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], i * ( 1 << qap_fade_len ) ); - pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), 31 - qap_fade_len ); + pAp_input_fx[i] = Mpy_32_32( pAp_input_fx[i], L_shl( i, qap_fade_len ) ); + move32(); + pAp_input_fx[i] = L_shl( Mpy_32_32( pAp_input_fx[i], ap_fade_len_inv ), sub( Q31, qap_fade_len ) ); + move32(); } hCPE->hStereoDft->ap_wasTransient = 0; + move16(); } /* apply 5-stage allpass, each stage consisting of a nested allpass pair */ @@ -697,15 +805,21 @@ void stereo_dft_dec_core_switching_fx( /* apply DFT to allpass-filtered signal */ stereo_dft_dec_analyze_fx( hCPE, pAp_input_fx, DFT_fx, 1, st->L_frame, output_frame, DFT_STEREO_DEC_ANA_FB, 0, 0, q, q_DFT ); hCPE->hStereoDft->q_ap_delay_mem_fx = *q; + move16(); } - IF( st->core == ACELP_CORE ) + IF( EQ_16( st->core, ACELP_CORE ) ) { IF( !use_cldfb_for_dft ) /* Skip this FOR DFT Stereo mono output at non-residual bitrates */ { L_lerp_fx_q11( output_fx, synth_fx, output_frame, hCPE->hCoreCoder[0]->L_frame ); /* Dirty resampling, but should be good enough FOR ECU analysis */ } - IF( !use_cldfb_for_dft || ( ( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && st->cng_type == LP_CNG && st->extl == SWB_CNG && hCPE->nchan_out == 1 ) ) + test(); + test(); + test(); + test(); + test(); + IF( !use_cldfb_for_dft || ( ( EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core_brate, SID_2k40 ) ) && EQ_16( st->cng_type, LP_CNG ) && EQ_16( st->extl, SWB_CNG ) && EQ_16( hCPE->nchan_out, 1 ) ) ) { v_add_fx( synth_fx, hb_synth_fx, synth_fx, output_frame ); /* Use one channel TD-BWE FOR ECU analysis buffer */ } diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index c830e1b78..cb1460ea2 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -165,6 +165,7 @@ Word16 ivas_qmetadata_dec_decode( move16(); all_coherence_zero = 1; move16(); + IF( hQMetaData->coherence_flag ) { /* read if coherence is zero */ @@ -188,12 +189,15 @@ Word16 ivas_qmetadata_dec_decode( p[0] = dif_p[0]; move16(); hQMetaData->twoDirBands[p[0]] = 1; + move16(); FOR( b = 1; b < hQMetaData->numTwoDirBands; b++ ) { dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); move16(); p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); + move16(); hQMetaData->twoDirBands[p[b]] = 1; + move16(); } bits_no_dirs_coh = add( bits_no_dirs_coh, sub( d, *index ) ); } @@ -215,7 +219,7 @@ Word16 ivas_qmetadata_dec_decode( { dfRatio_bits[dir2band] = ivas_get_df_ratio_bits_hodirac( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); move16(); - dir2band++; + dir2band = add( dir2band, 1 ); } } @@ -235,7 +239,7 @@ Word16 ivas_qmetadata_dec_decode( { dfRatio_bits[dir2band] = ivas_get_df_ratio_bits( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); move16(); - dir2band++; + dir2band = add( dir2band, 1 ); } } @@ -308,7 +312,7 @@ Word16 ivas_qmetadata_dec_decode( move16(); } - dir2band++; + dir2band = add( dir2band, 1 ); } ELSE { @@ -349,6 +353,7 @@ Word16 ivas_qmetadata_dec_decode( bits_dir_raw_pre[1] = 0; move16(); dir2band = 0; + move16(); FOR( b = hQMetaData->q_direction[0].cfg.start_band; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { test(); @@ -383,7 +388,7 @@ Word16 ivas_qmetadata_dec_decode( move16(); } - dir2band++; + dir2band = add( dir2band, 1 ); } ELSE { @@ -404,7 +409,7 @@ Word16 ivas_qmetadata_dec_decode( no_TF = add( i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), i_mult2( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); test(); - IF( EQ_32( all_coherence_zero, 0 ) && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) + IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); } @@ -429,7 +434,7 @@ Word16 ivas_qmetadata_dec_decode( no_TF = i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); test(); - IF( EQ_32( all_coherence_zero, 0 ) && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) + IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); } @@ -468,7 +473,7 @@ Word16 ivas_qmetadata_dec_decode( diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; move16(); - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { bits_diff = bits_diff_sum; move16(); @@ -485,7 +490,7 @@ Word16 ivas_qmetadata_dec_decode( bits_coherence = 0; move16(); - IF( EQ_32( all_coherence_zero, 0 ) ) + IF( all_coherence_zero == 0 ) { bits_coherence = read_coherence_data_fx( bitstream, index, hQMetaData, d, 0 ); } @@ -517,30 +522,32 @@ Word16 ivas_qmetadata_dec_decode( move16(); IF( LE_16( add( total_bits_1dir, bits_sur_coherence ), hQMetaData->qmetadata_max_bit_req ) ) { - ec_flag = bitstream[( *index )--]; + ec_flag = bitstream[( *index )]; move16(); - signal_bits++; + ( *index ) = sub( ( *index ), 1 ); + move16(); + signal_bits = add( signal_bits, 1 ); IF( GT_16( nblocks, 1 ) ) { IF( ec_flag ) { ec_flag = add( ec_flag, (Word16) bitstream[( *index )--] ); - signal_bits++; + signal_bits = add( signal_bits, 1 ); } } } /* Decode quantized directions frame-wise */ test(); - IF( EQ_16( ec_flag, 0 ) ) /* EC 1*/ + IF( !ec_flag ) /* EC 1*/ { bits_dir = 0; move16(); raw_flag[0] = bitstream[( *index )--]; move16(); - bits_dir++; + bits_dir = add( bits_dir, 1 ); - IF( EQ_16( raw_flag[0], 0 ) ) + IF( !raw_flag[0] ) { bits_dir = add( bits_dir, ivas_qmetadata_entropy_decode_dir_fx( q_direction, bitstream, index, diffuseness_index_max_ec_frame, nbands, start_band, 0 ) ); } @@ -558,7 +565,7 @@ Word16 ivas_qmetadata_dec_decode( { raw_flag[b] = bitstream[( *index )--]; move16(); - bits_dir++; + bits_dir = add( bits_dir, 1 ); } /* Read EC bits*/ @@ -566,7 +573,7 @@ Word16 ivas_qmetadata_dec_decode( FOR( b = start_band; b < nbands; b++ ) { - IF( EQ_16( raw_flag[b], 0 ) ) + IF( !raw_flag[b] ) { bits_dir = add( bits_dir, ivas_qmetadata_entropy_decode_dir_fx( q_direction, bitstream, index, diffuseness_index_max_ec_frame, b + 1, b, 0 ) ); } @@ -578,7 +585,7 @@ Word16 ivas_qmetadata_dec_decode( diff_bits = add( diff_bits, bits_dir ); /* Small requantization?*/ - IF( GT_16( q_direction->not_in_2D, 0 ) ) + IF( q_direction->not_in_2D > 0 ) { /* This is not an ideal solution but mirrors better encoder */ Word16 i, j; @@ -621,7 +628,7 @@ Word16 ivas_qmetadata_dec_decode( ec_flag = 2; move16(); - IF( EQ_16( hQMetaData->is_masa_ivas_format, 0 ) ) + IF( hQMetaData->is_masa_ivas_format == 0 ) { reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ); ind_order[0] = -1; @@ -643,7 +650,7 @@ Word16 ivas_qmetadata_dec_decode( bits_dir = read_directions_fx( q_direction, (UWord8) nbands, (UWord8) nblocks, bitstream, index, ind_order ); } - IF( GT_16( bits_coherence, 0 ) ) + IF( bits_coherence > 0 ) { IF( GT_16( nblocks, 1 ) ) { @@ -660,7 +667,7 @@ Word16 ivas_qmetadata_dec_decode( } } } - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( start_index_0, *index ) ); } @@ -673,6 +680,7 @@ Word16 ivas_qmetadata_dec_decode( { d = sub( hQMetaData->q_direction[1].cfg.nbands, 1 ); nblocks = hQMetaData->q_direction[0].cfg.nblocks; + move16(); FOR( b = hQMetaData->q_direction[0].cfg.nbands - 1; b >= 0; b-- ) { @@ -712,7 +720,7 @@ Word16 ivas_qmetadata_dec_decode( { mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); } - d--; + d = sub( d, 1 ); } ELSE { @@ -728,7 +736,7 @@ Word16 ivas_qmetadata_dec_decode( } /* Scale energy ratios that sum to over one */ - IF( !hodirac_flag ) + IF( hodirac_flag == 0 ) { FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { @@ -1339,6 +1347,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( Word16 p[MASA_MAXIMUM_CODING_SUBBANDS], dif_p[MASA_MAXIMUM_CODING_SUBBANDS]; Word16 codedBands, sf_nbands0, sf_nbands1; sf_nbands1 = 1; + move16(); Word64 W_nrg_ratio[2][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; start_index_0 = *index; @@ -1371,6 +1380,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( hQMetaData->coherence_flag && hQMetaData->q_direction[0].coherence_band_data != NULL ) { hQMetaData->q_direction[0].coherence_band_data[b].spread_coherence[m] = 0u; + move16(); } IF( EQ_32( hQMetaData->no_directions, 2 ) ) @@ -1389,6 +1399,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( hQMetaData->coherence_flag && hQMetaData->q_direction[1].coherence_band_data != NULL ) { hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence[m] = 0u; + move16(); } } @@ -1396,12 +1407,14 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( hQMetaData->coherence_flag && hQMetaData->surcoh_band_data != NULL ) { hQMetaData->surcoh_band_data[b].surround_coherence[m] = 0u; + move16(); } } IF( EQ_32( hQMetaData->no_directions, 2 ) ) { hQMetaData->twoDirBands[b] = 0; + move16(); } } sf_nbands0 = hQMetaData->q_direction[0].cfg.nbands; @@ -1435,7 +1448,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; move16(); - IF( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) + if ( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) { hQMetaData->q_direction[1].cfg.nbands = codedBands; move16(); @@ -1448,6 +1461,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( p[0] = dif_p[0]; move16(); hQMetaData->twoDirBands[p[0]] = 1; + move16(); FOR( b = 1; b < hQMetaData->q_direction[1].cfg.nbands; b++ ) { dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); @@ -1455,6 +1469,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); move16(); hQMetaData->twoDirBands[p[b]] = 1; + move16(); } } @@ -1521,7 +1536,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { pos_2dir_band[d] = b; move16(); - d++; + d = add( d, 1 ); } ELSE { @@ -1576,7 +1591,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( } } - IF( EQ_32( all_coherence_zero, 0 ) ) + IF( !all_coherence_zero ) { read_surround_coherence_hr_fx( bitstream, index, hQMetaData, W_nrg_ratio ); } @@ -1601,7 +1616,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); /* Read coherence, IF any */ - IF( EQ_32( all_coherence_zero, 0 ) ) + IF( !all_coherence_zero ) { read_coherence_data_hr_512_fx( bitstream, index, hQMetaData, d, bits_sp_coh ); } @@ -1651,7 +1666,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); } - d--; + d = sub( d, 1 ); } ELSE { @@ -2102,10 +2117,12 @@ Word16 ivas_qmetadata_dec_sid_decode( IF( EQ_16( ivas_format, SBA_FORMAT ) ) { metadata_sid_bits = (Word16) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 2 - SID_FORMAT_NBITS; /* -1 for inactive mode header bit*/ + move16(); } ELSE { metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + move16(); } start_index = *index; @@ -2166,7 +2183,7 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Decode diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 4 ), 4 ); + diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( DIRAC_DIFFUSE_LEVELS, 4 ) ), 4 ); move16(); q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; move16(); @@ -2179,21 +2196,22 @@ Word16 ivas_qmetadata_dec_sid_decode( bits_delta = sub( sub( metadata_sid_bits, sub( start_index, *index ) ), bits_dir ); /* bit_diff is already read */ - IF( GT_16( bits_delta, 0 ) ) + IF( bits_delta > 0 ) { - WHILE( GT_16( bits_delta, 0 ) ) + WHILE( bits_delta > 0 ) { FOR( b = start_band; b < nbands && ( bits_delta > 0 ); b++ ) { IF( LT_32( q_direction->band_data[b].bits_sph_idx[0], 11 ) ) { bits_delta = sub( bits_delta, 1 ); - q_direction->band_data[b].bits_sph_idx[0]++; + q_direction->band_data[b].bits_sph_idx[0] = add( q_direction->band_data[b].bits_sph_idx[0], 1 ); + move16(); } } } - IF( EQ_16( q_direction->not_in_2D, 0 ) ) + IF( q_direction->not_in_2D == 0 ) { FOR( b = start_band; b < nbands; b++ ) { @@ -2204,18 +2222,19 @@ Word16 ivas_qmetadata_dec_sid_decode( } ELSE { - WHILE( LT_16( bits_delta, 0 ) ) + WHILE( bits_delta < 0 ) { FOR( b = nbands - 1; b >= start_band && ( bits_delta < 0 ); b-- ) { IF( GE_32( q_direction->band_data[b].bits_sph_idx[0], 4 ) ) { bits_delta = add( bits_delta, 1 ); - q_direction->band_data[b].bits_sph_idx[0]--; + q_direction->band_data[b].bits_sph_idx[0] = sub( q_direction->band_data[b].bits_sph_idx[0], 1 ); + move16(); } } - IF( EQ_16( q_direction->not_in_2D, 0 ) ) + IF( q_direction->not_in_2D == 0 ) { FOR( b = start_band; b < nbands; b++ ) { @@ -2254,7 +2273,7 @@ Word16 ivas_qmetadata_dec_sid_decode( } /* Decoder DOAs*/ - IF( GT_16( q_direction->not_in_2D, 0 ) ) + IF( q_direction->not_in_2D > 0 ) { FOR( b = start_band; b < nbands; b++ ) { @@ -2300,7 +2319,7 @@ Word16 ivas_qmetadata_dec_sid_decode( q_direction->band_data[b].azimuth_index[0] = add( ivas_qmetadata_dereorder_generic( q_direction->band_data[b].azimuth_index[0] ), shr( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ) ); move16(); - temp_result = div_s( ( q_direction->band_data[b].azimuth_index[0] << 6 ), ( q_direction->band_data[b].azimuth_m_alphabet[0] << 6 ) ); + temp_result = div_s( ( shl( q_direction->band_data[b].azimuth_index[0], 6 ) ), ( shl( q_direction->band_data[b].azimuth_m_alphabet[0], 6 ) ) ); temp_result = Mpy_32_16_1( DEGREE_360_Q_22, (Word16) temp_result ); avg_azimuth_fx = L_sub( temp_result, DEGREE_180_Q_22 ); @@ -2315,9 +2334,9 @@ Word16 ivas_qmetadata_dec_sid_decode( FOR( m = 0; m < nblocks - 1; m++ ) { v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); } - ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); + ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); FOR( i = 0; i < nblocks; i++ ) { @@ -2576,11 +2595,12 @@ static Word16 ivas_diffuseness_huff_ec_decode_fx( Word16 val; val = 0; - WHILE( val <= DIFF_EC_HUFF_GR0_LIMIT ) + move16(); + WHILE( LE_16( val, DIFF_EC_HUFF_GR0_LIMIT ) ) { - IF( bitstream[( *index )--] == 1 ) + IF( EQ_16( bitstream[( *index )--], 1 ) ) { - val++; + val = add( val, 1 ); } ELSE { @@ -2588,21 +2608,19 @@ static Word16 ivas_diffuseness_huff_ec_decode_fx( } } - IF( val == DIFF_EC_HUFF_GR0_LIMIT + 1 ) + IF( EQ_16( val, DIFF_EC_HUFF_GR0_LIMIT + 1 ) ) { - val += 2 * bitstream[( *index )]; - ( *index )--; - val += bitstream[( *index )]; - ( *index )--; + val = add( val, shl( bitstream[( *index )--], 1 ) ); + val = add( val, bitstream[( *index )--] ); } IF( val % 2 == 0 ) { - return -( val / 2 ) + av; + return add( negate( shr( val, 1 ) ), av ); } ELSE { - return ( val + 1 ) / 2 + av; + return add( shr( add( val, 1 ), 1 ), av ); } } #else @@ -2679,6 +2697,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( FOR( b = 0; b < MASA_BITS_ER; b++ ) { q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + move16(); } *diffuseness_index_max_ec_frame = 5; move16(); @@ -2686,12 +2705,12 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( return MASA_BITS_ER; } - IF( EQ_32( bitstream[( *index )--], 0 ) ) /* dif_use_raw_coding */ + IF( bitstream[( *index )--] == 0 ) /* dif_use_raw_coding */ { /* Decode with similarity strategy with low band count. On higher band counts, decode with Huffman-coding strategy. */ IF( LT_16( nbands, DIFF_EC_HUFF_BAND_LIMIT ) ) { - IF( NE_32( bitstream[( *index )--], 0 ) ) /* dif_have_unique_value */ + IF( bitstream[( *index )--] ) /* dif_have_unique_value */ { dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ @@ -2732,6 +2751,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( q_direction->band_data[b].energy_ratio_index[0] = ivas_diffuseness_huff_ec_decode_fx( bitstream, index, av ); move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); + move16(); } } } @@ -2745,15 +2765,17 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); + move16(); } } *diffuseness_index_max_ec_frame = 5; move16(); /* adaptively select the diffuseness_index_max_ec threshold */ - IF( GT_32( dif_min, 5 ) ) + if ( GT_32( dif_min, 5 ) ) { - *diffuseness_index_max_ec_frame = (UWord16) sub( DIRAC_DIFFUSE_LEVELS, 1 ); + *diffuseness_index_max_ec_frame = (UWord16) DIRAC_DIFFUSE_LEVELS - 1; + move16(); } return sub( index_start, *index ); @@ -2990,6 +3012,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( { // q_direction->band_data[0].energy_ratio_index[0] = ( q_direction->band_data[0].energy_ratio_index[0] << 1 ) + bitstream[( *index )--]; q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + move16(); } return dfRatio_bits[0]; } @@ -3028,7 +3051,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( move16(); IF( EQ_16( ec_mode, 1 ) ) { - IF( EQ_32( bitstream[( *index )--], 0 ) ) + if ( bitstream[( *index )--] == 0 ) { dec_mode = 1; /* Switch to one value EC coding */ move16(); @@ -3036,9 +3059,9 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( } ELSE IF( EQ_16( ec_mode, 2 ) ) { - IF( EQ_32( bitstream[( *index )--], 0 ) ) + IF( bitstream[( *index )--] == 0 ) { - IF( EQ_32( bitstream[( *index )--], 0 ) ) + IF( bitstream[( *index )--] == 0 ) { dec_mode = 1; /* Switch to one value EC coding */ move16(); @@ -3269,7 +3292,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( bands_entropic[b] = 0; move16(); - IF( GT_16( q_direction->not_in_2D, 0 ) ) + IF( q_direction->not_in_2D > 0 ) { decode_fixed_rate_fx( q_direction, bitstream, index, b, nblocks ); } @@ -3302,7 +3325,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( /*EC for the low diffuseness*/ /*Elevation only if not 2D */ - IF( GT_16( q_direction->not_in_2D, 0 ) ) + IF( q_direction->not_in_2D > 0 ) { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { @@ -3334,6 +3357,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( ELSE { diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + move16(); } IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) @@ -3346,13 +3370,13 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( /*reorder elevation indexing*/ tmp_index = sub( avg_elevation_index_projected, shr( elev_alph[b], 1 ) ); - IF( LT_16( tmp_index, 0 ) ) + IF( tmp_index < 0 ) { - tmp_index = negate( shl( tmp_index, 1 ) ); + tmp_index = negate( tmp_index * 2 ); } - ELSE IF( GT_16( tmp_index, 0 ) ) + ELSE IF( tmp_index > 0 ) { - tmp_index = sub( shl( tmp_index, 1 ), 1 ); + tmp_index = sub( ( tmp_index * 2 ), 1 ); } avg_elevation_index_projected = tmp_index; move16(); @@ -3429,12 +3453,12 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( tmp_index = ivas_qmetadata_ReorderElevationDecoded( tmp_index, avg_elevation_index_projected, elev_alph[b] ); /*reorder elevation indexing*/ - tmp_index = sub( tmp_index, shr( elev_alph[b], 1 ) ); - IF( LT_16( tmp_index, 0 ) ) + tmp_index = sub( tmp_index, elev_alph[b] / 2 ); + IF( tmp_index < 0 ) { tmp_index = negate( shl( tmp_index, 1 ) ); } - ELSE IF( GT_16( tmp_index, 0 ) ) + ELSE IF( tmp_index > 0 ) { tmp_index = sub( shl( tmp_index, 1 ), 1 ); } @@ -3484,7 +3508,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; + azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][add( q_direction->band_data[b].elevation_index[m], 1 ) / 2]; move16(); } @@ -3547,7 +3571,8 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { use_adapt_avg = bitstream[*index]; move16(); - ( *index )--; + ( *index ) = sub( *index, 1 ); + move16(); } avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, azith_alph[b][m], gr_param_azith ); @@ -3565,6 +3590,8 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); move32(); } + + test(); IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && GT_16( nblocks, 1 ) ) { IF( LT_16( idx, MASA_LIMIT_IDX_AVG_AZI ) ) @@ -3577,7 +3604,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { IF( EQ_16( use_adapt_avg, 1 ) ) { - IF( EQ_16( m, 0 ) ) + IF( m == 0 ) { FOR( Word16 l = 0; l < 3; l++ ) { @@ -3593,7 +3620,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( avg_azimuth_index = quantize_phi_fx( L_add( avg_azimuth_fx, DEGREE_180_Q_22 ), 0, &avg_azimuth_fx, avg_azimuth_alphabet ); } } - idx++; + idx = add( idx, 1 ); } } } @@ -4070,7 +4097,7 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( FOR( b = start_band; b < nbands; b++ ) { - IF( GT_16( q_direction->not_in_2D, 0 ) ) + IF( q_direction->not_in_2D > 0 ) { decode_fixed_rate_fx( q_direction, bitstream, index, b, nblocks ); } @@ -4093,7 +4120,7 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( move32(); q_direction->band_data[b].elevation_index[m] = 0; move16(); - azith_alph = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][0]; + azith_alph = no_phi_masa[bits_direction_masa[diff_idx] - 1][0]; move16(); q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph ); move16(); @@ -4255,10 +4282,13 @@ Word16 ivas_qmetadata_DecodeExtendedGR( { msb = 0; move16(); - WHILE( LT_16( msb, sub( msb_size, 1 ) ) && NE_32( bitstream[*index], 0 ) ) + test(); + WHILE( LT_16( msb, sub( msb_size, 1 ) ) && bitstream[*index] ) { - msb++; - ( *index )--; + test(); + msb = add( msb, 1 ); + ( *index ) = sub( ( *index ), 1 ); + move16(); } IF( EQ_16( msb, sub( msb_size, 1 ) ) ) @@ -4267,7 +4297,8 @@ Word16 ivas_qmetadata_DecodeExtendedGR( } ELSE { - ( *index )--; + ( *index ) = sub( ( *index ), 1 ); + move16(); lsb = 0; move16(); FOR( i = 0; i < gr_param; i++ ) @@ -4348,7 +4379,7 @@ static Word16 ivas_qmetadata_ReorderElevationDecoded( dist_reorder = ivas_qmetadata_dereorder_generic( elev_dist ); elev_index_reorder = add( elev_avg, dist_reorder ); - IF( LT_16( elev_index_reorder, 0 ) ) + IF( elev_index_reorder < 0 ) { elev_index_reorder = add( elev_index_reorder, elev_alph ); } @@ -4428,7 +4459,7 @@ static Word16 read_directions_fx( allowed_bits = extract_l( L_add( allowed_bits, q_direction->band_data[j].bits_sph_idx[k] ) ); } - last_j = sub( j, (Word16) EQ_16( allowed_bits, 0 ) ); + last_j = sub( j, (Word16) ( allowed_bits == 0 ) ); FOR( j = 0; j < last_j; j++ ) { @@ -4464,7 +4495,7 @@ static Word16 read_directions_fx( { byteBuffer = 0; move16(); - IF( LE_16( use_vq, 1 ) ) + if ( LE_16( use_vq, 1 ) ) { byteBuffer = 1; move16(); @@ -4489,12 +4520,12 @@ static Word16 read_directions_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[sub( bits_dir0[k], 3 )]; + q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[bits_dir0[k] - 3]; move16(); } ELSE { - q_direction->band_data[i].elevation_m_alphabet[k] = sub( shl( no_theta_masa[sub( bits_dir0[k], 3 )], 1 ), 1 ); + q_direction->band_data[i].elevation_m_alphabet[k] = shl( no_theta_masa[bits_dir0[k] - 3], 1 ) - 1; move16(); } } @@ -4505,7 +4536,7 @@ static Word16 read_directions_fx( } } - IF( GT_16( allowed_bits, 0 ) ) + IF( allowed_bits > 0 ) { IF( EQ_32( byteBuffer, 1 ) ) { @@ -4574,13 +4605,13 @@ static Word16 read_directions_fx( move16(); allowed_bits = sum16_fx( bits_dir0, q_direction->cfg.nblocks ); test(); - IF( GT_16( allowed_bits, 0 ) && EQ_16( masa_subframes, 1 ) ) + IF( allowed_bits > 0 && EQ_16( masa_subframes, 1 ) ) { nbits = add( nbits, decode_fixed_rate_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); } ELSE { - IF( GT_16( allowed_bits, 0 ) ) + IF( allowed_bits > 0 ) { use_vq = 0; move16(); @@ -4612,7 +4643,7 @@ static Word16 read_directions_fx( move16(); } - IF( GT_16( allowed_bits, 0 ) ) + IF( allowed_bits > 0 ) { test(); IF( EQ_32( byteBuffer, 1 ) || LE_16( use_vq, 1 ) ) @@ -4920,7 +4951,7 @@ static Word16 decode_azimuth_fx( { IF( LT_32( q_direction->band_data[idx_subband].azimuth_index[k], MASA_NO_INDEX ) ) { - j_az++; + j_az = add( j_az, 1 ); } ELSE { @@ -4929,19 +4960,19 @@ static Word16 decode_azimuth_fx( } } - IF( EQ_16( j_az, 0 ) ) + IF( !j_az ) { return nbits; } - IF( EQ_32( byteBuffer, 0 ) ) + IF( !byteBuffer ) { /* use context */ use_context = 0; move16(); FOR( k = 0; k < masa_subframes; k++ ) { - IF( LE_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 1 ) ) + if ( LE_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 1 ) ) { use_context = 1; move16(); @@ -4952,7 +4983,7 @@ static Word16 decode_azimuth_fx( { FOR( k = 0; k < masa_subframes; k++ ) { - IF( EQ_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 0 ) ) + IF( q_direction->band_data[idx_subband].bits_sph_idx[k] == 0 ) { q_direction->band_data[idx_subband].azimuth_index[k] = 0; move16(); @@ -4968,7 +4999,7 @@ static Word16 decode_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k] = byteBuffer; move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( q_direction->band_data[idx_subband].azimuth_index[k] * ( -180 ), Q22 ); + q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( L_mult0( q_direction->band_data[idx_subband].azimuth_index[k], -180 ), Q22 ); move32(); } ELSE @@ -4985,18 +5016,20 @@ static Word16 decode_azimuth_fx( ELSE { /* read bit to check if min removed encoding */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); - IF( EQ_32( byteBuffer, 0 ) ) /* regular GR coding5 */ + bit_pos = sub( bit_pos, 1 ); + IF( byteBuffer == 0 ) /* regular GR coding5 */ { /* read GR_order */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); + bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); FOR( k = 0; k < masa_subframes; k++ ) { - IF( GT_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 0 ) ) + IF( q_direction->band_data[idx_subband].bits_sph_idx[k] > 0 ) { IF( GT_16( no_phi_masa[L_sub( q_direction->band_data[idx_subband].bits_sph_idx[k], 1 )][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { @@ -5026,19 +5059,20 @@ static Word16 decode_azimuth_fx( { /* min removed GR coding */ /* read GR_order */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); + bit_pos = sub( bit_pos, 1 ); /* read min index value */ maximum_s( q_direction->band_data[idx_subband].azimuth_m_alphabet, masa_subframes, &max_val ); min_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, max_val, MASA_GR_ORD_AZ ); FOR( k = 0; k < masa_subframes; k++ ) { - IF( GT_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 0 ) ) + IF( q_direction->band_data[idx_subband].bits_sph_idx[k] > 0 ) { - IF( GT_16( no_phi_masa[sub( q_direction->band_data[idx_subband].bits_sph_idx[k], 1 )][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) + IF( GT_16( no_phi_masa[q_direction->band_data[idx_subband].bits_sph_idx[k] - 1][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( L_sub( MASA_GR_ORD_AZ, 1 ), byteBuffer ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ - 1, byteBuffer ) ) ); move16(); q_direction->band_data[idx_subband].azimuth_index[k] = (UWord16) L_add( q_direction->band_data[idx_subband].azimuth_index[k], min_idx ); move16(); @@ -5260,7 +5294,7 @@ static Word16 decode_elevation_fx( q_direction->band_data[j].elevation_fx[k] = 0; move32(); - IF( GT_32( q_direction->band_data[j].bits_sph_idx[k], 0 ) ) + IF( q_direction->band_data[j].bits_sph_idx[k] > 0 ) { IF( LE_32( q_direction->band_data[j].bits_sph_idx[k], 2 ) ) { @@ -5276,19 +5310,19 @@ static Word16 decode_elevation_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 3 )]; + q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3]; move16(); } ELSE { - q_direction->band_data[j].elevation_m_alphabet[k] = sub( shl( no_theta_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 3 )], 1 ), 1 ); + q_direction->band_data[j].elevation_m_alphabet[k] = shl( no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3], 1 ) - 1; move16(); } } } ELSE { - nr_NO_INDEX++; + nr_NO_INDEX = add( nr_NO_INDEX, 1 ); } } @@ -5296,14 +5330,18 @@ static Word16 decode_elevation_fx( { { /* read if same or not */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); + bit_pos = sub( bit_pos, 1 ); IF( EQ_32( byteBuffer, 1 ) ) /* same value */ { /* read value */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; + move16(); + bit_pos = sub( bit_pos, 1 ); + byteBuffer = (UWord16) L_add( L_shl( byteBuffer, 1 ), bitstream[bit_pos] ); move16(); - byteBuffer = (UWord16) L_add( L_shl( byteBuffer, 1 ), bitstream[bit_pos--] ); + bit_pos = sub( bit_pos, 1 ); same_idx = byteBuffer; move16(); @@ -5321,7 +5359,8 @@ static Word16 decode_elevation_fx( ELSE { /* not same; decode mean removed GR */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; + bit_pos = sub( bit_pos, 1 ); move16(); GR_ord_elevation = extract_l( L_sub( MASA_GR_ORD_EL, byteBuffer ) ); @@ -5518,6 +5557,7 @@ static Word16 decode_fixed_rate_fx( FOR( i = 0; i < q_direction->band_data[b].bits_sph_idx[m]; i++ ) { value = (UWord16) L_add( L_shl( value, 1 ), bitstream[( *pbit_pos )--] ); + move16(); } q_direction->band_data[b].spherical_index[m] = value; @@ -5599,7 +5639,7 @@ static Word16 decode_azimuth2D_fx( bits_dir0 = (Word16 *) q_direction->band_data[j].bits_sph_idx; allowed_bits = sum16_fx( bits_dir0, no_frames ); - IF( GT_16( allowed_bits, 0 ) ) + IF( allowed_bits > 0 ) { use_vq = 0; move16(); @@ -5625,7 +5665,9 @@ static Word16 decode_azimuth2D_fx( set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_frames ); FOR( k = 0; k < s_min( allowed_bits, no_frames ); k++ ) { - q_direction->band_data[j].azimuth_fx[k] = L_shl( -180 * bitstream[bit_pos--], Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_shl( L_mult0( -180, bitstream[bit_pos] ), Q22 ); + move32(); + bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); } } @@ -5642,22 +5684,23 @@ static Word16 decode_azimuth2D_fx( move16(); FOR( i = 0; i < bits_dir0[k]; i++ ) { - Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos--] ); + Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos] ); + bit_pos = sub( bit_pos, 1 ); } nbits = add( nbits, bits_dir0[k] ); IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].azimuth_fx[k] = L_shl( 360, Q22 - bits_dir0[k] ) * Buffer - L_shl( 180, Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_sub( L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer, L_shl( 180, Q22 ) ); move32(); q_direction->band_data[j].azimuth_fx[k] = companding_azimuth_fx( q_direction->band_data[j].azimuth_fx[k], q_direction->cfg.mc_ls_setup, - ( q_direction->band_data[j].elevation_fx[k] > MC_MASA_THR_ELEVATION * ( 1 << 22 ) ), -1 ); + (Word16) GT_32( q_direction->band_data[j].elevation_fx[k], L_shl( MC_MASA_THR_ELEVATION, 22 ) ), -1 ); move32(); } ELSE { - q_direction->band_data[j].azimuth_fx[k] = L_shl( 360, Q22 - bits_dir0[k] ) * Buffer - L_shl( 180, Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer - L_shl( 180, Q22 ); move32(); } } @@ -5840,17 +5883,17 @@ static Word16 read_truncGR_azimuth_fx( { FOR( i = 0; i < min( allowed_bits, no_subframes ); i++ ) { - IF( EQ_32( bitstream[( *pbit_pos )--], 0 ) ) + IF( bitstream[( *pbit_pos )--] == 0 ) { q_direction->band_data[j].azimuth_fx[i] = 0; move32(); } ELSE { - q_direction->band_data[j].azimuth_fx[i] = L_shl( -180, 22 ); + q_direction->band_data[j].azimuth_fx[i] = ( -180 * ONE_IN_Q22 ); move32(); } - nbits++; + nbits = add( nbits, 1 ); } return nbits; @@ -5881,7 +5924,7 @@ static Word16 read_truncGR_azimuth_fx( { q_direction->band_data[j].azimuth_fx[i] = cb_azi_chan_fx[(UWord16) L_shr( (UWord16) L_add( idx, 1 ), 1 )]; move32(); - IF( GT_32( L_and( idx, 1 ), 0 ) ) + IF( L_and( idx, 1 ) > 0 ) { q_direction->band_data[j].azimuth_fx[i] = L_negate( q_direction->band_data[j].azimuth_fx[i] ); move32(); @@ -5997,7 +6040,7 @@ static Word16 read_common_direction_fx( move16(); set_zero_direction_fx( q_direction, j, no_subframes ); - IF( EQ_16( bits_total, 0 ) ) + IF( !bits_total ) { return nbits; } @@ -6021,8 +6064,9 @@ static Word16 read_common_direction_fx( } - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); + bit_pos = sub( bit_pos, 1 ); bits_el = 1; move16(); nbits = add( nbits, 1 ); @@ -6033,7 +6077,7 @@ static Word16 read_common_direction_fx( move16(); bits_el = add( bits_el, 1 ); nbits = add( nbits, 1 ); - IF( EQ_32( byteBuffer, 0 ) ) + IF( byteBuffer == 0 ) { FOR( i = 0; i < no_subframes; i++ ) { @@ -6047,7 +6091,7 @@ static Word16 read_common_direction_fx( move16(); bits_el = add( bits_el, 1 ); nbits = add( nbits, 1 ); - IF( EQ_32( byteBuffer, 0 ) ) + IF( byteBuffer == 0 ) { FOR( i = 0; i < no_subframes; i++ ) { @@ -6061,14 +6105,14 @@ static Word16 read_common_direction_fx( byteBuffer = bitstream[bit_pos--]; move16(); nbits = add( nbits, 1 ); - IF( EQ_32( byteBuffer, 0 ) ) + IF( byteBuffer == 0 ) { - set32_fx( q_direction->band_data[j].elevation_fx, L_shl( 90, Q22 ), no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( 90 * ONE_IN_Q22 ), no_subframes ); set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); } ELSE { - set32_fx( q_direction->band_data[j].elevation_fx, L_shl( -90, Q22 ), no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( -90 * ONE_IN_Q22 ), no_subframes ); set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); } *pbit_pos = bit_pos; @@ -6086,8 +6130,9 @@ static Word16 read_common_direction_fx( nbits = add( nbits, s_min( no_subframes, bits_el ) ); FOR( i = 0; i < s_min( no_subframes, bits_el ); i++ ) { - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); + bit_pos = sub( bit_pos, 1 ); /*qdirection->azimuth_index[j][i] = (uint16_t) byteBuffer; */ q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; move32(); @@ -6281,8 +6326,9 @@ static void decode_spread_coherence_fx( { IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { - two_dir_band[d++] = j; + two_dir_band[d] = j; move16(); + d = add( d, 1 ); } } } @@ -6321,13 +6367,13 @@ static void decode_spread_coherence_fx( IF( LT_16( coding_subbands, coding_subbands_0 ) ) { - assert( idx_d == 1 ); - dct_coh_fx[i][1] = coherence_cb1_masa_fx[MASA_grouping[two_dir_band[i]] * MASA_NO_CV_COH1 + q_direction->coherence_band_data[i].spread_coherence_dct1_index]; + assert( EQ_16( idx_d, 1 ) ); + dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[two_dir_band[i]], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; move32(); } ELSE { - dct_coh_fx[i][1] = coherence_cb1_masa_fx[MASA_grouping[i] * MASA_NO_CV_COH1 + q_direction->coherence_band_data[i].spread_coherence_dct1_index]; + dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[i], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; move32(); } @@ -6474,6 +6520,7 @@ static ivas_error read_huf( ) { Word16 done = 0, end_pos; + move16(); UWord16 ByteBuffer; Word16 nbits, val; UWord16 i; @@ -6484,11 +6531,11 @@ static ivas_error read_huf( move16(); val = 0; move16(); - WHILE( EQ_16( done, 0 ) && LT_16( nbits, max_len ) ) + WHILE( !done && LT_16( nbits, max_len ) ) { ByteBuffer = bitstream[end_pos--]; move16(); - val = add( shl( val, 1 ), (Word16) L_and( ByteBuffer, 1 ) ); + val = add( shl( val, 1 ), ByteBuffer & 1 ); nbits = add( nbits, 1 ); FOR( i = 0; i < len; i++ ) { @@ -6574,8 +6621,9 @@ static Word16 read_GR_min_removed_data( move16(); /* read GR order */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); + bit_pos = sub( bit_pos, 1 ); nbits = 1; move16(); @@ -6731,6 +6779,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < half_no_bands; j++ ) { no_cb *= no_cv_vec[j]; + move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); no_cb = 1; @@ -6738,6 +6787,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = half_no_bands; j < no_bands; j++ ) { no_cb *= no_cv_vec[j]; + move16(); } no_bits_vec1 = (Word16) ceil_log_2( no_cb ); } @@ -6748,12 +6798,13 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < no_bands; j++ ) { no_cb *= no_cv_vec[j]; + move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); no_bits_vec1 = 0; move16(); } - IF( GT_16( no_bits_vec1, 0 ) ) + IF( no_bits_vec1 > 0 ) { idx_fr = 0; move64(); @@ -6951,10 +7002,14 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )--] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); + move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )--]; + GR_param = bitstream[( *p_bit_pos )]; + move16(); + ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { @@ -6969,6 +7024,7 @@ static Word16 read_coherence_data_hr_512_fx( } decoded_idx_fx = L_shl( decoded_idx, 9 ); hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + move16(); } } ELSE @@ -6978,17 +7034,22 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )--] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); + move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )--]; + GR_param = bitstream[( *p_bit_pos )]; + move16(); + ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { decoded_idx = add( ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, cb_size - min_index, GR_param ), min_index ); decoded_idx_fx = L_shl( decoded_idx, 9 ); hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + move16(); } } } @@ -7109,7 +7170,7 @@ static Word16 read_coherence_data_fx( coding_subbands = hQMetaData->q_direction[idx_dir].cfg.nbands; move16(); - extra_cv = (Word16) ( coding_subbands / MASA_FACTOR_CV_COH ); + extra_cv = idiv1616( coding_subbands, MASA_FACTOR_CV_COH ); move16(); q_direction = &( hQMetaData->q_direction[idx_dir] ); bit_pos = *p_bit_pos; @@ -7142,8 +7203,9 @@ static Word16 read_coherence_data_fx( return 0; } - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; move16(); + bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); IF( L_and( byteBuffer, 1 ) ) @@ -7163,10 +7225,12 @@ static Word16 read_coherence_data_fx( q_res = add( sub( 15, q_den ), q_num ); res = L_shl( res, sub( 16, q_res ) ); q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + move16(); } ELSE { q_direction->coherence_band_data[j].spread_coherence[0] = 0; + move16(); } } } @@ -7188,10 +7252,12 @@ static Word16 read_coherence_data_fx( q_res = add( sub( 15, q_den ), q_num ); res = L_shl( res, sub( 16, q_res ) ); q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + move16(); } ELSE { q_direction->coherence_band_data[j].spread_coherence[0] = 0; + move16(); } } } @@ -7219,7 +7285,7 @@ static Word16 read_coherence_data_fx( no_cb = 1; move64(); - FOR( j = 0; j < coding_subbands / 2; j++ ) + FOR( j = 0; j < shr( coding_subbands, 1 ); j++ ) { no_cb *= no_cv_vec[j]; move64(); @@ -7793,7 +7859,7 @@ static Word16 read_surround_coherence( error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); } - IF( LE_32( error_ratio_surr, 0 ) ) + IF( error_ratio_surr <= 0 ) { error_ratio_surr = 0; move32(); @@ -7818,9 +7884,10 @@ static Word16 read_surround_coherence( { FOR( k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) { - IF( hQMetaData->surcoh_band_data != NULL ) + if ( hQMetaData->surcoh_band_data != NULL ) { hQMetaData->surcoh_band_data[j].surround_coherence[k] = 0; + move16(); } } } @@ -7829,7 +7896,8 @@ static Word16 read_surround_coherence( } /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; + bit_pos = sub( bit_pos, 1 ); move16(); bits_sur_coherence = add( bits_sur_coherence, 1 ); @@ -7837,8 +7905,8 @@ static Word16 read_surround_coherence( { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos--]; - move16(); + byteBuffer = bitstream[bit_pos]; + bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ @@ -7855,7 +7923,7 @@ static Word16 read_surround_coherence( /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_cv_vec[j] - min_index, ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } @@ -7880,6 +7948,7 @@ static Word16 read_surround_coherence( } hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + move16(); } } ELSE @@ -7902,10 +7971,12 @@ static Word16 read_surround_coherence( IF( GT_16( no_cv_vec[j], 1 ) ) { hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + move16(); } ELSE { hQMetaData->surcoh_band_data[j].surround_coherence[0] = 0; + move16(); } } } @@ -7915,6 +7986,7 @@ static Word16 read_surround_coherence( FOR( k = 1; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) { hQMetaData->surcoh_band_data[j].surround_coherence[k] = hQMetaData->surcoh_band_data[j].surround_coherence[0]; + move16(); } } @@ -8120,11 +8192,14 @@ static Word16 read_surround_coherence_hr_fx( // q_direction = hQMetaData->q_direction; bits_sur_coherence = 0; + move16(); bit_pos = *p_bit_pos; + move16(); FOR( sf = 0; sf < hQMetaData->q_direction[0].cfg.nblocks; sf++ ) { d = 0; + move16(); FOR( j = 0; j < coding_subbands; j++ ) { @@ -8145,8 +8220,11 @@ static Word16 read_surround_coherence_hr_fx( IF( LE_64( error_ratio_surr_fx, ( 461168601842 ) ) ) // 1e-7 in Q62 { error_ratio_surr_fx = 0; + move64(); no_cv_vec[j] = 1; + move16(); idx_ER[j] = 0; + move16(); } ELSE { @@ -8165,6 +8243,7 @@ static Word16 read_surround_coherence_hr_fx( IF( hQMetaData->surcoh_band_data != NULL ) { hQMetaData->surcoh_band_data[j].surround_coherence[k] = 0; + move16(); } } } @@ -8172,14 +8251,18 @@ static Word16 read_surround_coherence_hr_fx( ELSE { /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; + move16(); + bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); IF( byteBuffer & 1 ) { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos]; + move16(); + bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ @@ -8191,15 +8274,18 @@ static Word16 read_surround_coherence_hr_fx( FOR( j = 0; j < coding_subbands; j++ ) { bits_GR = bit_pos; + move16(); /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_cv_vec[j] - min_index, ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); + move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } ELSE { idx_sur_coh[j] = 0; + move16(); } } @@ -8208,12 +8294,16 @@ static Word16 read_surround_coherence_hr_fx( IF( GT_16( no_cv_vec[j], 1 ) ) { hQMetaData->surcoh_band_data[j].sur_coherence_index = (UWord16) L_add( (Word32) idx_sur_coh[j], L_deposit_l( min_index ) ); - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH + hQMetaData->surcoh_band_data[j].sur_coherence_index]; + move16(); + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + move16(); } ELSE { hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; + move16(); hQMetaData->surcoh_band_data[j].surround_coherence[sf] = 0; + move16(); } } } @@ -8228,6 +8318,7 @@ static Word16 read_surround_coherence_hr_fx( FOR( j = 0; j < coding_subbands; j++ ) { hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; + move16(); } /* deindex surround coherence */ @@ -8235,11 +8326,13 @@ static Word16 read_surround_coherence_hr_fx( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH + hQMetaData->surcoh_band_data[j].sur_coherence_index]; + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + move16(); } ELSE { hQMetaData->surcoh_band_data[j].surround_coherence[sf] = 0; + move16(); } } } @@ -8249,6 +8342,7 @@ static Word16 read_surround_coherence_hr_fx( /* Replace return value with the actual read bits. bits_sur_coherence might show wrong count at this point. */ bits_sur_coherence = sub( *p_bit_pos, bit_pos ); *p_bit_pos = bit_pos; + move16(); return bits_sur_coherence; } @@ -8273,6 +8367,7 @@ static void decode_combined_index_fx( UWord64 base[MASA_MAXIMUM_CODING_SUBBANDS + 1]; base[0] = 1; + move64(); FOR( i = 1; i < len; i++ ) { base[i] = base[i - 1] * no_cv_vec[i - 1]; @@ -8285,6 +8380,7 @@ static void decode_combined_index_fx( } index[0] = (UWord16) comb_index; + move16(); return; } @@ -8339,17 +8435,17 @@ static void read_stream_dct_coeffs_omasa_fx( move16(); sign = 1; move16(); - IF( EQ_16( first_line, 0 ) ) + IF( !first_line ) { /* read sign */ sign = bit_stream[( *index )--]; move16(); - IF( EQ_16( sign, 0 ) ) + IF( !sign ) { sign = -1; move16(); } - nbits++; + nbits = add( nbits, 1 ); } set16_fx( q_idx, 0, len_stream ); @@ -8362,7 +8458,7 @@ static void read_stream_dct_coeffs_omasa_fx( q_idx[0] = i_mult( q_idx[0], sign ); move16(); - IF( NE_16( q_idx[0], 0 ) ) + IF( q_idx[0] != 0 ) { IF( GE_16( len_stream, 8 ) ) { @@ -8404,7 +8500,9 @@ static void read_stream_dct_coeffs_omasa_fx( ELSE { /* read GR order (only one) */ - GR1 = bit_stream[( *index )--]; + GR1 = bit_stream[( *index )]; + move16(); + ( *index ) = sub( ( *index ), 1 ); move16(); FOR( i = 1; i < len_stream; i++ ) { @@ -8419,7 +8517,7 @@ static void read_stream_dct_coeffs_omasa_fx( move32(); FOR( i = 1; i < len_stream; i++ ) { - IF( EQ_16( s_and( q_idx[i], 1 ), 0 ) ) + IF( s_and( q_idx[i], 1 ) == 0 ) { q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); move32(); @@ -8567,7 +8665,7 @@ void ivas_omasa_decode_masa_to_total_fx( set16_fx( q_idx, 0, i_mult( nbands, nblocks ) ); FOR( i = 0; i < n_streams; i++ ) { - read_stream_dct_coeffs_omasa_fx( &q_idx[i * len_stream], &q_dct_data_fx[i * len_stream], len_stream, bit_stream, index, i == 0 ); + read_stream_dct_coeffs_omasa_fx( &q_idx[L_mult0( i, len_stream )], &q_dct_data_fx[L_mult0( i, len_stream )], len_stream, bit_stream, index, i == 0 ); } /* inverse DCT2 transform */ @@ -8611,7 +8709,7 @@ void ivas_omasa_decode_masa_to_total_fx( move32(); masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); move32(); - k++; + k = add( k, 1 ); } } diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec.c index 332f4952f..40fdbdc5e 100644 --- a/lib_dec/ivas_qspherical_dec.c +++ b/lib_dec/ivas_qspherical_dec.c @@ -119,30 +119,35 @@ Word32 deindex_elevation_fx( theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ); IF( GT_32( theta_hat_fx, L_shl( 90, Q22 ) ) ) { - theta_hat_fx = L_shl( 90, Q22 ); + theta_hat_fx = 90 * ONE_IN_Q22; + move32(); } } ELSE { - IF( EQ_32( L_and( *id_th, 1 ), 0 ) ) + IF( L_and( *id_th, 1 ) == 0 ) { /* theta is negative */ *id_th = (UWord16) L_shr( *id_th, 1 ); + move16(); id_th_fx = L_shr( id_th_fx, 1 ); theta_hat_fx = L_negate( L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ) ); - IF( LT_32( theta_hat_fx, L_shl( -90, Q22 ) ) ) + IF( LT_32( theta_hat_fx, -90 * ONE_IN_Q22 ) ) { - theta_hat_fx = L_shl( -90, Q22 ); + theta_hat_fx = -90 * ONE_IN_Q22; + move32(); } } ELSE { *id_th = (UWord16) L_shr( L_add( *id_th, 1 ), 1 ); + move16(); id_th_fx = L_shr( L_add( id_th_fx, L_shl( 1, q_id_th ) ), 1 ); theta_hat_fx = L_shl( Mpy_32_32( id_th_fx, delta_theta_masa_fx[sub( no_bits, 3 )] ), sub( 31, q_id_th ) ); - IF( GT_32( theta_hat_fx, L_shl( 90, Q22 ) ) ) + IF( GT_32( theta_hat_fx, 90 * ONE_IN_Q22 ) ) { - theta_hat_fx = L_shl( 90, Q22 ); + theta_hat_fx = 90 * ONE_IN_Q22; + move32(); } } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 9da244a34..5dda982b8 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -55,24 +55,33 @@ void ivas_sba_set_cna_cng_flag( ) { Word16 n, cpe_id; - - IF( st_ivas->ivas_format == SBA_FORMAT && st_ivas->nchan_transport == 1 ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( st_ivas->nchan_transport, 1 ) ) { /* skip as done in init function */ /* st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; */ /* st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; */ } - ELSE IF( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) ) ) + ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) || ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) ) ) { st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + move16(); st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + move16(); } - ELSE IF( st_ivas->nchan_transport == 2 ) + ELSE IF( EQ_16( st_ivas->nchan_transport, 2 ) ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; + move16(); st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + move16(); } } ELSE @@ -82,7 +91,9 @@ void ivas_sba_set_cna_cng_flag( FOR( n = 0; n < CPE_CHANNELS; n++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; + move16(); st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; + move16(); } } } @@ -746,30 +757,33 @@ ivas_error ivas_sba_dec_reconfigure( *-------------------------------------------------------------------*/ ivas_error ivas_sba_dec_reconfigure_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - uint16_t *nSamplesFlushed, /* o : number of samples flushed */ - int16_t *data /* o : output synthesis signal */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + UWord16 *nSamplesFlushed, /* o : number of samples flushed */ + Word16 *data /* o : output synthesis signal */ ) { - int16_t nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; + Word16 nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old; AUDIO_CONFIG intern_config_old; - int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; - int16_t sba_dirac_stereo_flag_old; - int32_t ivas_total_brate; - int32_t last_ivas_total_brate; - int16_t num_channels, num_md_sub_frames; - int16_t nchan_out_buff, nchan_out_buff_old; - int16_t sba_analysis_order_old_flush; + Word16 numCldfbAnalyses_old, numCldfbSyntheses_old; + Word16 sba_dirac_stereo_flag_old; + Word32 ivas_total_brate; + Word32 last_ivas_total_brate; + Word16 num_channels, num_md_sub_frames; + Word16 nchan_out_buff, nchan_out_buff_old; + Word16 sba_analysis_order_old_flush; DECODER_CONFIG_HANDLE hDecoderConfig; ivas_error error; ISM_MODE ism_mode_old; - int16_t granularity_new; + Word16 granularity_new; ism_mode_old = st_ivas->ism_mode; hDecoderConfig = st_ivas->hDecoderConfig; ivas_total_brate = hDecoderConfig->ivas_total_brate; + move32(); last_ivas_total_brate = st_ivas->last_active_ivas_total_brate; + move32(); sba_analysis_order_old_flush = st_ivas->sba_analysis_order; + move16(); /*-----------------------------------------------------------------* * Set SBA high-level parameters @@ -781,157 +795,157 @@ ivas_error ivas_sba_dec_reconfigure_fx( ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); nchan_hp20_old = getNumChanSynthesis( st_ivas ); - if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - if ( ivas_total_brate >= IVAS_256k ) + IF( GE_32( ivas_total_brate, IVAS_256k ) ) { st_ivas->ism_mode = ISM_SBA_MODE_DISC; + move16(); } - else + ELSE { st_ivas->ism_mode = ISM_MODE_NONE; + move16(); } } - else + ELSE { st_ivas->ism_mode = ISM_MODE_NONE; + move16(); } nSCE_old = st_ivas->nSCE; + move16(); nCPE_old = st_ivas->nCPE; + move16(); nchan_transport_old = st_ivas->nchan_transport; + move16(); sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag; + move16(); st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); *nSamplesFlushed = 0; + move16(); granularity_new = st_ivas->hTcBuffer->n_samples_granularity; + move16(); /* we may need to flush only for binaural and OSBA and TSM */ - if ( st_ivas->ivas_format == SBA_ISM_FORMAT && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ) { RENDERER_TYPE renderer_type_new; - int16_t sba_order_internal; + Word16 sba_order_internal; - sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /* get new renderer type */ /* copy the logic from ivas_renderer_select(), because calling this function has too many side effects that would affect the flushing */ - if ( ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) <= 2 ) + IF( LE_16( ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ), 2 ) ) { - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL ) + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) { renderer_type_new = RENDERER_BINAURAL_PARAMETRIC; + move16(); } - else + ELSE { renderer_type_new = RENDERER_BINAURAL_PARAMETRIC_ROOM; + move16(); } } - else + ELSE { - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + test(); + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { renderer_type_new = RENDERER_BINAURAL_FASTCONV; + move16(); } - else + ELSE { renderer_type_new = RENDERER_BINAURAL_FASTCONV_ROOM; + move16(); } } /* determine new granularity */ granularity_new = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + move16(); /* this will change anyway only with binaural */ - if ( renderer_type_new == RENDERER_BINAURAL_FASTCONV && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + test(); + IF( EQ_16( renderer_type_new, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - granularity_new *= JBM_CLDFB_SLOTS_IN_SUBFRAME; + granularity_new = i_mult( granularity_new, JBM_CLDFB_SLOTS_IN_SUBFRAME ); } /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ - if ( granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + IF( LT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { /* write back info for correct rendering of the flushable samples */ st_ivas->sba_analysis_order = sba_analysis_order_old_flush; + move16(); st_ivas->hDecoderConfig->ivas_total_brate = last_ivas_total_brate; + move32(); -#ifdef IVAS_FLOAT_FIXED -#if 1 /*Float to fixed conversion*/ - if ( st_ivas->hIsmRendererData ) - { - FOR( Word16 ind1 = 0; ind1 < st_ivas->hIsmRendererData->interpolator_len; ind1++ ) - { - st_ivas->hIsmRendererData->interpolator_fx[ind1] = (Word16) L_min( 32767, floatToFixed( st_ivas->hIsmRendererData->interpolator_fx[ind1], 15 ) ); - } - } - FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) - { - if ( st_ivas->hIsmMetaData[ind1] ) - { - st_ivas->hIsmMetaData[ind1]->azimuth_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->azimuth * ( 1 << 22 ) ); - st_ivas->hIsmMetaData[ind1]->elevation_fx = (Word32) ( st_ivas->hIsmMetaData[ind1]->elevation * ( 1 << 22 ) ); - } - } -#endif - if ( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ), IVAS_ERR_OK ) ) { return error; } -#if 1 /*Fixed to float */ - FOR( Word16 ind1 = 0; ind1 < MAX_NUM_OBJECTS; ind1++ ) - { - if ( st_ivas->hIsmMetaData[ind1] ) - { - st_ivas->hIsmMetaData[ind1]->azimuth = (float) ( st_ivas->hIsmMetaData[ind1]->azimuth_fx ) / (float) ( 1 << 22 ); - st_ivas->hIsmMetaData[ind1]->elevation = (float) ( st_ivas->hIsmMetaData[ind1]->elevation_fx ) / (float) ( 1 << 22 ); - } - } -#endif -#else - if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, granularity_new, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, st_ivas->mc_mode, ism_mode_old, nSamplesFlushed, data ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif // IVAS_FLOAT_FIXED /* restore correct values for the current frame*/ st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order ); + move16(); st_ivas->hDecoderConfig->ivas_total_brate = ivas_total_brate; + move32(); } - else if ( granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + ELSE IF( GT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } /* make sure the changed number of slots in the last subframe is not lost in the following steps */ - if ( st_ivas->hSpatParamRendCom != NULL ) + IF( st_ivas->hSpatParamRendCom != NULL ) { st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + move32(); } st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + move32(); } } /* save old */ - if ( ism_mode_old != ISM_SBA_MODE_DISC ) + IF( NE_16( ism_mode_old, ISM_SBA_MODE_DISC ) ) { - if ( st_ivas->hDirAC == NULL && st_ivas->hSpar != NULL ) + test(); + IF( st_ivas->hDirAC == NULL && st_ivas->hSpar != NULL ) { st_ivas->hTcBuffer->num_slots = st_ivas->hSpar->num_slots; + move16(); st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpar->nb_subframes; + move16(); st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpar->slots_rendered; + move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered; + move16(); mvs2s( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - else if ( st_ivas->hSpatParamRendCom != NULL ) + ELSE IF( st_ivas->hSpatParamRendCom != NULL ) { st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots; + move16(); st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + move16(); st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + move16(); st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + move16(); mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } } @@ -940,59 +954,67 @@ ivas_error ivas_sba_dec_reconfigure_fx( * Allocate, initialize, and configure SBA handles *-----------------------------------------------------------------*/ - int16_t sba_order_internal; + Word16 sba_order_internal; SPAR_DEC_HANDLE hSpar; hSpar = st_ivas->hSpar; - sba_order_internal = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); + sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - if ( hSpar != NULL ) + IF( hSpar != NULL ) { - if ( ( hSpar->hPCA != NULL ) && ( ( hDecoderConfig->ivas_total_brate != PCA_BRATE ) || ( st_ivas->sba_order != 1 ) ) ) + test(); + test(); + IF( ( hSpar->hPCA != NULL ) && ( NE_32( hDecoderConfig->ivas_total_brate, PCA_BRATE ) || NE_16( st_ivas->sba_order, 1 ) ) ) { free( st_ivas->hSpar->hPCA ); hSpar->hPCA = NULL; } - if ( nchan_transport_old != ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) || ( last_ivas_total_brate >= IVAS_512k && ivas_total_brate < IVAS_512k ) || ( last_ivas_total_brate < IVAS_512k && ivas_total_brate >= IVAS_512k ) ) + test(); + test(); + test(); + test(); + test(); + IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) ) { ivas_spar_dec_close( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 ); - if ( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( last_ivas_total_brate < IVAS_24k4 && ivas_total_brate >= IVAS_24k4 ) + ELSE IF( LT_32( last_ivas_total_brate, IVAS_24k4 ) && GE_32( ivas_total_brate, IVAS_24k4 ) ) { num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; + move16(); ivas_spar_md_dec_matrix_close_fx( st_ivas->hSpar->hMdDec, num_channels ); num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, ivas_total_brate, st_ivas->last_active_ivas_total_brate ); - if ( ( error = ivas_spar_md_dec_matrix_open_fx( st_ivas->hSpar->hMdDec, num_channels, num_md_sub_frames ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_spar_md_dec_matrix_open_fx( st_ivas->hSpar->hMdDec, num_channels, num_md_sub_frames ) ), IVAS_ERR_OK ) ) { return error; } } - if ( hSpar->hPCA == NULL && st_ivas->hDecoderConfig->ivas_total_brate == PCA_BRATE && st_ivas->sba_order == 1 && st_ivas->ivas_format == SBA_FORMAT ) + test(); + test(); + test(); + IF( hSpar->hPCA == NULL && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( st_ivas->sba_order, 1 ) && EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { - if ( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + IF( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); } - // ivas_pca_dec_init( hSpar->hPCA ); -#ifdef IVAS_FLOAT_FIXED ivas_pca_dec_init_fx( hSpar->hPCA ); -#endif } ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); } - else + ELSE { - if ( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1000,14 +1022,17 @@ ivas_error ivas_sba_dec_reconfigure_fx( hSpar = st_ivas->hSpar; st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); + move16(); - if ( st_ivas->nchan_transport == 1 ) + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { st_ivas->element_mode_init = IVAS_SCE; + move16(); } - else + ELSE { st_ivas->element_mode_init = IVAS_CPE_MDCT; + move16(); } /*-----------------------------------------------------------------* @@ -1016,10 +1041,11 @@ ivas_error ivas_sba_dec_reconfigure_fx( /* renderer might have changed */ intern_config_old = st_ivas->intern_config; + move16(); ivas_renderer_select( st_ivas ); /* side effect of the renderer selection can be a changed internal config */ - if ( st_ivas->intern_config != intern_config_old ) + IF( NE_16( st_ivas->intern_config, intern_config_old ) ) { ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); } @@ -1028,47 +1054,44 @@ ivas_error ivas_sba_dec_reconfigure_fx( * Reallocate and initialize binaural rendering handles *--------------------------------------------------------------------*/ - if ( st_ivas->hBinRenderer == NULL && ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) ) + test(); + test(); + test(); + test(); + IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { - /*float2fix block: to be removed*/ - /* if (st_ivas->hIntSetup.ls_azimuth && st_ivas->hIntSetup.ls_azimuth_fx) { - floatToFixed_arrL((float *)st_ivas->hIntSetup.ls_azimuth, (Word32 *)st_ivas->hIntSetup.ls_azimuth_fx, Q22, st_ivas->hIntSetup.nchan_out_woLFE); - } - if (st_ivas->hIntSetup.ls_elevation && st_ivas->hIntSetup.ls_elevation_fx) { - floatToFixed_arrL((float *)st_ivas->hIntSetup.ls_elevation, (Word32 *)st_ivas->hIntSetup.ls_elevation_fx, Q22, st_ivas->hIntSetup.nchan_out_woLFE); - }*/ - /*float2fix block end*/ /* open fastconv binaural renderer */ - if ( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - else if ( st_ivas->hBinRenderer != NULL && ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM ) ) + ELSE IF( st_ivas->hBinRenderer != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { ivas_binRenderer_close_fx( &st_ivas->hBinRenderer ); } - if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX && st_ivas->hMonoDmxRenderer == NULL ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && st_ivas->hMonoDmxRenderer == NULL ) { - if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } - if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX ) + IF( NE_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); } - if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), - st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), + st_ivas->ivas_format ) ), + IVAS_ERR_OK ) ) { return error; } - if ( ( ( st_ivas->renderer_type != RENDERER_DISABLE ) && ( st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC ) ) || ( ( hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_FOA ) && ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_STEREO ) && ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_MONO ) ) ) + IF( ( ( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) && ( NE_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) ) ) || ( ( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) && ( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) && ( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) ) ) { DIRAC_CONFIG_FLAG flag_config; @@ -1078,162 +1101,134 @@ ivas_error ivas_sba_dec_reconfigure_fx( flag_config = DIRAC_RECONFIGURE_MODE; } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_dirac_dec_config_fx( st_ivas, flag_config ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_dirac_dec_config( st_ivas, flag_config ) ) != IVAS_ERR_OK ) -#endif + IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, flag_config ) ), IVAS_ERR_OK ) ) { return error; } } - else + ELSE { - int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; + Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1]; - st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - if ( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) + st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + move16(); + IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; + move16(); - set_c( (int8_t *) st_ivas->hQMetaData->twoDirBands, (int8_t) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); - st_ivas->hQMetaData->numTwoDirBands = (uint8_t) st_ivas->hQMetaData->q_direction[0].cfg.nbands; + set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); + st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands; + move16(); } - ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( L_add( st_ivas->hDecoderConfig->output_Fs, 400 ) / CLDFB_BANDWIDTH ), st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); if ( st_ivas->hDirAC ) { st_ivas->hDirAC->hConfig->enc_param_start_band = st_ivas->hSpar->enc_param_start_band; + move16(); } } - if ( st_ivas->renderer_type == RENDERER_DISABLE ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) { -#ifdef IVAS_FLOAT_FIXED ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) ); ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) ); ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) ); vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); -#else - ivas_dirac_rend_close( &( st_ivas->hDirACRend ) ); - ivas_spat_hSpatParamRendCom_close( &( st_ivas->hSpatParamRendCom ) ); - ivas_dirac_dec_close( &( st_ivas->hDirAC ) ); - vbap_free_data( &( st_ivas->hVBAPdata ) ); -#endif } if ( st_ivas->hDirAC != NULL ) { st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; + move16(); } /*-----------------------------------------------------------------* * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ - if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - if ( ism_mode_old == ISM_MODE_NONE && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + IF( EQ_16( ism_mode_old, ISM_MODE_NONE ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - int32_t temp_brate[MAX_SCE]; + Word32 temp_brate[MAX_SCE]; st_ivas->ism_mode = ISM_SBA_MODE_DISC; -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) -#else - if ( ( error = ivas_ism_metadata_dec_create( st_ivas, st_ivas->nchan_ism, temp_brate ) ) != IVAS_ERR_OK ) -#endif + move16(); + + IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( st_ivas->renderer_type == RENDERER_TD_PANNING || - st_ivas->renderer_type == RENDERER_NON_DIEGETIC_DOWNMIX || - st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || - st_ivas->renderer_type == RENDERER_OSBA_STEREO || - st_ivas->renderer_type == RENDERER_OSBA_AMBI || - st_ivas->renderer_type == RENDERER_OSBA_LS || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || - st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || - st_ivas->renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_ivas->renderer_type, RENDERER_TD_PANNING ) || + EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) || + EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || + EQ_16( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) || + EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || + EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) || + EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || + EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || + EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) ) { -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_ism_renderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - if ( ( error = ivas_ism_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } -#endif } - if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) ) { - if ( st_ivas->hMonoDmxRenderer == NULL ) + IF( st_ivas->hMonoDmxRenderer == NULL ) { - if ( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } } - else + ELSE { ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer ); } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { /* Allocate TD renderer for the objects in DISC mode */ - if ( st_ivas->hBinRendererTd == NULL ) + IF( st_ivas->hBinRendererTd == NULL ) { -#ifdef IVAS_FLOAT_FIXED Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; - IF( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ) != IVAS_ERR_OK ) - { - return error; - } -#if 1 // Cleanup changes for ivas_td_binaural_open: fixed to float - Word16 nchan_rend = num_src; - IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) - { - nchan_rend--; /* Skip LFE channel -- added to the others */ - } - FOR( Word16 nS = 0; nS < nchan_rend; nS++ ) - { - TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]]; - IF( Src_p->SrcSpatial_p != NULL ) - { - Src_p->SrcSpatial_p->q_Pos_p = Q31; - } - TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p; - SrcSpatial_p->q_Pos_p = Q31; - } -#endif -#else - if ( ( error = ivas_td_binaural_open( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) { return error; } -#endif } } /* Allocate memory for OSBA delay buffer */ - if ( ( error = ivas_osba_data_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_osba_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } - st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); + move16(); } - else if ( ism_mode_old == ISM_SBA_MODE_DISC && st_ivas->ism_mode == ISM_MODE_NONE ) + ELSE IF( EQ_16( ism_mode_old, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->ism_mode, ISM_MODE_NONE ) ) { /* ISM renderer handle */ ivas_ism_renderer_close( &st_ivas->hIsmRendererData ); @@ -1241,59 +1236,50 @@ ivas_error ivas_sba_dec_reconfigure_fx( ivas_osba_data_close_fx( &st_ivas->hSbaIsmData ); /* Time Domain binaural renderer handle */ - if ( st_ivas->hBinRendererTd != NULL ) + IF( st_ivas->hBinRendererTd != NULL ) { - if ( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) + IF( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM == TRUE ) { ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); st_ivas->hHrtfTD = NULL; } } - nchan_transport_old += st_ivas->nchan_ism; + nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); st_ivas->ism_mode = ISM_MODE_NONE; + move16(); } - else if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - st_ivas->nCPE += ( st_ivas->nchan_ism + 1 ) >> 1; + st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->nchan_ism, 1 ), 1 ) ); + move16(); nCPE_old = st_ivas->nCPE; + move16(); nchan_transport_old = st_ivas->nchan_transport; - nchan_transport_old += st_ivas->nchan_ism; + move16(); + nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); } } -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - if ( ( error = ivas_corecoder_dec_reconfig( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ), IVAS_ERR_OK ) ) { return error; } -#endif /*-----------------------------------------------------------------* * HP20 memories *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) ) { return error; } -#else - if ( ( error = ivas_hp20_dec_reconfig( st_ivas, nchan_hp20_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif + /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ - if ( st_ivas->hDiracDecBin != NULL ) + IF( st_ivas->hDiracDecBin != NULL ) { - if ( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -1302,78 +1288,80 @@ ivas_error ivas_sba_dec_reconfigure_fx( /*-----------------------------------------------------------------* * CLDFB instances *-----------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -#if 1 - // Float to fix conversions for ivas_cldfb_dec_reconfig_fx -#ifndef MSAN_FIX - IF( st_ivas->hSpar ) - { - st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_factor_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, 16 ); - floatToFixed_arr( st_ivas->hSpar->hFbMixer->cldfb_cross_fade, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q, 16 ); - } -#endif // MSAN_FIX -#endif - if ( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - if ( ( error = ivas_cldfb_dec_reconfig( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) { return error; } -#endif /*-----------------------------------------------------------------* * JBM TC buffers *-----------------------------------------------------------------*/ { - int16_t tc_nchan_to_allocate; - int16_t tc_nchan_tc; + Word16 tc_nchan_to_allocate; + Word16 tc_nchan_tc; TC_BUFFER_MODE tc_buffer_mode; tc_buffer_mode = TC_BUFFER_MODE_RENDERER; + move16(); tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas ); tc_nchan_to_allocate = tc_nchan_tc; - if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) - { - if ( ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) + move16(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) + { + test(); + test(); + IF( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) ) { - tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out + st_ivas->nchan_ism; + tc_nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); tc_nchan_to_allocate = tc_nchan_tc; + move16(); } - else + ELSE { tc_buffer_mode = TC_BUFFER_MODE_BUFFER; + move16(); tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out; + move16(); tc_nchan_to_allocate = tc_nchan_tc; + move16(); } } - else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { - tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; + tc_nchan_to_allocate = shl( BINAURAL_CHANNELS, 1 ); } - else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { tc_nchan_to_allocate = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - tc_nchan_to_allocate += st_ivas->nchan_ism; + tc_nchan_to_allocate = add( tc_nchan_to_allocate, st_ivas->nchan_ism ); } } - else + ELSE { - if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) || ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) ) { tc_nchan_to_allocate++; /* we need a channel for the CNG in this case*/ } } - if ( tc_nchan_tc != st_ivas->hTcBuffer->nchan_transport_jbm || tc_nchan_to_allocate != st_ivas->hTcBuffer->nchan_transport_internal || tc_buffer_mode != st_ivas->hTcBuffer->tc_buffer_mode || granularity_new != st_ivas->hTcBuffer->n_samples_granularity ) + test(); + test(); + test(); + IF( NE_16( tc_nchan_tc, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( tc_buffer_mode, st_ivas->hTcBuffer->tc_buffer_mode ) || NE_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) ) { - if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode, tc_nchan_tc, tc_nchan_to_allocate, tc_nchan_to_allocate, granularity_new ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode, tc_nchan_tc, tc_nchan_to_allocate, tc_nchan_to_allocate, granularity_new ) ), IVAS_ERR_OK ) ) { return error; } @@ -1381,24 +1369,33 @@ ivas_error ivas_sba_dec_reconfigure_fx( } /* resync SPAR and DirAC JBM info from TC Buffer */ - if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity ) + test(); + IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) ) { mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); } mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); st_ivas->hSpar->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); st_ivas->hSpar->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); - if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - int16_t granularityMultiplier = st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size; - int16_t n; - for ( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ ) + Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); + Word16 n; + FOR( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ ) { - st_ivas->hSpatParamRendCom->subframe_nbslots[n] = st_ivas->hTcBuffer->subframe_nbslots[n] * granularityMultiplier; + st_ivas->hSpatParamRendCom->subframe_nbslots[n] = i_mult( st_ivas->hTcBuffer->subframe_nbslots[n], granularityMultiplier ); + move16(); st_ivas->hSpar->subframe_nbslots[n] = st_ivas->hSpatParamRendCom->subframe_nbslots[n]; + move16(); } } @@ -1408,12 +1405,12 @@ ivas_error ivas_sba_dec_reconfigure_fx( nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } #ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } @@ -1746,13 +1743,16 @@ void ivas_sba_dec_digest_tc_fx( Word32 *decorr_signal[BINAURAL_CHANNELS]; Word32 *p_tc[2 * BINAURAL_CHANNELS]; Word16 q_format = 14; - default_frame = (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + Word16 exp = 0; + move16(); + default_frame = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &exp ); + default_frame = shr( default_frame, sub( Q15, exp ) ); nSamplesLeftForTD = nSamplesForRendering; move16(); FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) { - decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx + BINAURAL_CHANNELS]; + decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[add( ch_idx, BINAURAL_CHANNELS )]; move32(); p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; move32(); @@ -1785,7 +1785,7 @@ void ivas_sba_dec_digest_tc_fx( test(); test(); test(); - IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) + if ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) && st_ivas->nCPE > 0 && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) ) { nchan_transport = 1; move16(); /* Only one channel transported */ @@ -1806,7 +1806,7 @@ void ivas_sba_dec_digest_tc_fx( ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) && ( EQ_16( nchan_transport, 1 ) && NE_16( st_ivas->nchan_transport, 2 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] - 1 ) - 2 ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 2 ) ); generate_masking_noise_lb_dirac_fx( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc_fx[1], nCldfbSlots, st->cna_dirac_flag && st->flag_cna ); } @@ -1853,18 +1853,20 @@ ivas_error ivas_sba_dec_render_fx( } slot_size = NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + move16(); /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ - slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), nSamplesAsked / slot_size ); + slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); *nSamplesRendered = imult1616( slots_to_render, slot_size ); + move16(); first_sf = hSpar->subframes_rendered; last_sf = first_sf; move16(); move16(); - WHILE( GT_16( slots_to_render, 0 ) ) + WHILE( slots_to_render > 0 ) { slots_to_render = sub( slots_to_render, hSpar->subframe_nbslots[last_sf] ); - last_sf++; + last_sf = add( last_sf, 1 ); } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -1884,7 +1886,7 @@ ivas_error ivas_sba_dec_render_fx( IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) ) { - IF( ( error = ivas_sba_linear_renderer_fx( output_fx, *nSamplesRendered, st_ivas->hIntSetup.nchan_out_woLFE, 0, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup ) ) != IVAS_ERR_OK ) + if ( NE_32( ( error = ivas_sba_linear_renderer_fx( output_fx, *nSamplesRendered, st_ivas->hIntSetup.nchan_out_woLFE, 0, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup ) ), IVAS_ERR_OK ) ) { return error; } @@ -1895,15 +1897,18 @@ ivas_error ivas_sba_dec_render_fx( IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ) { hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } ELSE { hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } move16(); } *nSamplesAvailableNext = imult1616( sub( hSpar->num_slots, hSpar->slots_rendered ), slot_size ); + move16(); return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index aaa838a2c..2ad1c081b 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -69,7 +69,7 @@ Word16 ivas_get_sba_dirac_stereo_flag( { IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) { - IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) + if ( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) { sba_dirac_stereo_flag = 1; move16(); @@ -77,7 +77,7 @@ Word16 ivas_get_sba_dirac_stereo_flag( } ELSE { - IF( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + if ( EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { sba_dirac_stereo_flag = 1; move16(); @@ -86,7 +86,7 @@ Word16 ivas_get_sba_dirac_stereo_flag( } ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + if ( EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { sba_dirac_stereo_flag = 1; move16(); @@ -219,7 +219,7 @@ static Word16 ivas_sba_dirac_stereo_band_config( static Word16 get_panning_tangent_gain( const Word16 sinAngleMapped ) { - Word16 tbl_len = sizeof( ivas_sine_panning_tbl_fx ) / sizeof( ivas_sine_panning_tbl_fx[0] ); + Word16 tbl_len = sizeof( ivas_sine_panning_tbl_fx ) / sizeof( ivas_sine_panning_tbl_fx[0] ); // Not using BASOP because size can be calculted at compile-time. move16(); Word16 idx = shr( tbl_len, 1 ); move16(); @@ -236,7 +236,7 @@ static Word16 get_panning_tangent_gain( { return ptr_tan[tbl_len - 1]; } - ELSE IF( LE_16( idx, 0 ) ) + ELSE IF( idx <= 0 ) { return ptr_tan[0]; } @@ -267,12 +267,10 @@ static Word16 get_panning_tangent_gain( ELSE IF( GT_16( sinAngleMapped, ptr_sin[idx] ) ) { lim_l = add( idx, 1 ); - move16(); } ELSE IF( LT_16( sinAngleMapped, ptr_sin[idx] ) ) { lim_r = sub( idx, 1 ); - move16(); } } } @@ -288,25 +286,21 @@ static Word16 get_panning( Word16 azSubEl = aziDeg - eleDeg; move16(); const Word16 *ptr_sin_az = &ivas_sin_az_fx[180]; - while ( azAddEl > 180 ) + WHILE( GT_16( azAddEl, 180 ) ) { - azAddEl = azAddEl - 360; - move16(); + azAddEl = sub( azAddEl, 360 ); } - while ( azAddEl < -180 ) + WHILE( LT_16( azAddEl, negate( 180 ) ) ) { - azAddEl = azAddEl + 360; - move16(); + azAddEl = add( azAddEl, 360 ); } - while ( azSubEl > 180 ) + WHILE( GT_16( azSubEl, 180 ) ) { - azSubEl = azSubEl - 360; - move16(); + azSubEl = sub( azSubEl, 360 ); } - while ( azSubEl < -180 ) + WHILE( LT_16( azSubEl, negate( 180 ) ) ) { - azSubEl = azSubEl + 360; - move16(); + azSubEl = add( azSubEl, 360 ); } /*sin(az)cos(el) = 0.5 * (sin(az + el) + sin(az - el)) */ Word16 sin_az_cos_el = add( shr( ptr_sin_az[azAddEl], 1 ), shr( ptr_sin_az[azSubEl], 1 ) ); @@ -393,16 +387,18 @@ static void map_params_dirac_to_stereo( FOR( i = hStereoDft->band_limits[b]; i < hStereoDft->band_limits[b + 1]; i++ ) { tmp64 = W_add( tmp64, W_add( W_mult0_32_32( pDFT[2 * i], pDFT[2 * i] ), - W_mult0_32_32( pDFT[2 * i + 1], pDFT[2 * i + 1] ) ) ); - move32(); + W_mult0_32_32( pDFT[add( 2 * i, 1 )], pDFT[add( 2 * i, 1 )] ) ) ); + move64(); } subframe_band_nrg[k][b] = W_extract_h( W_shl( tmp64, 1 ) ); + move32(); q_nrg = sub( Q31, sub( shl( hStereoDft->q_dft, 1 ), Q31 ) ); subframe_band_nrg[k][b] = Sqrt32( subframe_band_nrg[k][b], &q_nrg ); move32(); IF( NE_16( sub( Q31, q_nrg ), hStereoDft->q_smooth_buf_fx ) ) { subframe_band_nrg[k][b] = L_shl( subframe_band_nrg[k][b], sub( hStereoDft->q_smooth_buf_fx, sub( Q31, q_nrg ) ) ); + move32(); } hStereoDft->smooth_buf_fx[b][NB_DIV - 1 - k] = subframe_band_nrg[k][b]; move32(); @@ -413,7 +409,7 @@ static void map_params_dirac_to_stereo( smooth_long_avg[k][b] = 0; move32(); /* Multiplying and adding avoids overflow */ - FOR( i = sub( NB_DIV - 1, k ); i < add( SBA_DIRAC_NRG_SMOOTH_SHORT + NB_DIV - 1, k ); i++ ) + FOR( i = sub( sub( NB_DIV, 1 ), k ); i < add( sub( add( SBA_DIRAC_NRG_SMOOTH_SHORT, NB_DIV ), 1 ), k ); i++ ) { smooth_short_avg[k][b] = Madd_32_16( smooth_short_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x2AAB ); /* 1/ 3 in Q15*/ move32(); @@ -421,7 +417,7 @@ static void map_params_dirac_to_stereo( move32(); } - FOR( i = sub( NB_DIV - 1 + SBA_DIRAC_NRG_SMOOTH_SHORT, k ); i < sub( SBA_DIRAC_NRG_SMOOTH_LONG + NB_DIV - 1, k ); i++ ) + FOR( i = sub( add( sub( NB_DIV, 1 ), SBA_DIRAC_NRG_SMOOTH_SHORT ), k ); i < sub( sub( add( SBA_DIRAC_NRG_SMOOTH_LONG, NB_DIV ), 1 ), k ); i++ ) { smooth_long_avg[k][b] = Madd_32_16( smooth_long_avg[k][b], hStereoDft->smooth_buf_fx[b][i], (Word16) 0x0CCD ); move32(); @@ -429,7 +425,7 @@ static void map_params_dirac_to_stereo( /* calculate smoothing factor based on energy averages */ /* reduce factor for higher short-term energy */ - IF( NE_32( smooth_long_avg[k][b], 0 ) ) + IF( smooth_long_avg[k][b] ) { hStereoDft->smooth_fac_fx[k][b] = extract_l( s_min( MAX_16, BASOP_Util_Divide3232_Scale( smooth_long_avg[k][b], smooth_short_avg[k][b], &q_div ) ) ); move32(); @@ -506,36 +502,9 @@ static void map_params_dirac_to_stereo( } pSynth += block_len; } -#if 0 - /* - * block_nrg array's q-format will be q_synth at this point in the control flow. - * So unity used for division numerator should also be in the same Q - q_synth. - */ - nrg_norm1 = L_deposit_l(BASOP_Util_Divide3232_Scale(L_shl(1, q_synth), L_add(block_nrg[0] , L_add(block_nrg[1] , EPSILON_FIX) ), &q_div1)); - IF (NE_16(q_div1, 0) && NE_32(block_nrg[0], 0) && NE_32(block_nrg[1], 0)) - { - /* - nrg_norm1 obtained in the previous step will be in Q15 - q_div1 format. - Below step converts and stores nrg_norm1 in Q31 format. - */ - nrg_norm1 = L_shl(nrg_norm1, add(Q16, q_div1)); - q_div1 = 0; - } - nrg_norm2 = L_deposit_l(BASOP_Util_Divide3232_Scale(L_shl(1, q_synth), L_add(block_nrg[2] , L_add(block_nrg[3] , EPSILON_FIX) ), &q_div2)); - IF (NE_16(q_div2, 0) && NE_32(block_nrg[2], 0) && NE_32(block_nrg[3], 0)) - { - /* - nrg_norm2 obtained in the previous step will be in Q15 - q_div2 format. - Below step converts and stores nrg_norm2 in Q31 format. - */ - nrg_norm2 = L_shl(nrg_norm2, add(Q16, q_div2)); - q_div2 = 0; - } -#else nrg_norm1 = L_add( block_nrg[0], L_add( block_nrg[1], EPSILON_FIX ) ); nrg_norm2 = L_add( block_nrg[2], L_add( block_nrg[3], EPSILON_FIX ) ); -#endif /* extract DirAC parameters from metadata */ FOR( b = 0; b < nbands; b++ ) @@ -567,7 +536,7 @@ static void map_params_dirac_to_stereo( block_metadata = block; move16(); } - IF( LT_32( q_direction->band_data[b].azimuth_fx[block_metadata], 0 ) ) + IF( q_direction->band_data[b].azimuth_fx[block_metadata] < 0 ) { q_direction->band_data[b].azimuth_fx[block_metadata] = L_add( (Word32) 0x5A000000, q_direction->band_data[b].azimuth_fx[block_metadata] ); move16(); @@ -592,19 +561,6 @@ static void map_params_dirac_to_stereo( move32(); FOR( block = 0; block < shr( nBlocks, 1 ); block++ ) { -#if 0 - IF ( EQ_16(b_wide_panning, 1) ) - { - /* panning between left and ride, saturate at the stereo ls positions (+/- 30deg azi) */ - side_gain[b] = Madd_32_32(side_gain[b], nrg_norm1, Mpy_32_16_1(block_nrg[block] , get_panning( azimuth[block][b], elevation[block][b]) )); - move32(); - } - ELSE - { - side_gain[b] = Madd_32_32(side_gain[b], nrg_norm1, Mpy_32_16_1(block_nrg[block] , mult(ptr_sin_az[azimuth[block][b]] , ptr_cos_el[elevation[block][b]]))); - move32(); - } -#else /* * The floating point version of the code computes * nrg_norm1 = 1 / (block_nrg[0] + block_nrg[1]); and then computes @@ -613,7 +569,7 @@ static void map_params_dirac_to_stereo( IF( EQ_16( b_wide_panning, 1 ) ) { Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); - IF( NE_16( q_div1, 0 ) ) + IF( q_div1 ) { temp = L_shl_sat( temp, q_div1 ); } @@ -624,14 +580,13 @@ static void map_params_dirac_to_stereo( ELSE { Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm1, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); - IF( NE_16( q_div1, 0 ) ) + IF( q_div1 ) { temp = L_shl_sat( temp, q_div1 ); } side_gain[b] = L_add_sat( side_gain[b], temp ); move32(); } -#endif } /* combine angles of last 2 blocks to side gain of second subframe */ @@ -639,23 +594,10 @@ static void map_params_dirac_to_stereo( move32(); FOR( block = shr( nBlocks, 1 ); block < nBlocks; block++ ) { -#if 0 - IF ( EQ_16(b_wide_panning, 1) ) - { - /* panning between left and ride, saturate at the stereo ls positions (+/- 30deg azi) */ - side_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_32(side_gain[b + STEREO_DFT_BAND_MAX], nrg_norm2 , Mpy_32_16_1(block_nrg[block] , get_panning( azimuth[block][b], elevation[block][b]))); - move32(); - } - ELSE - { - side_gain[b + STEREO_DFT_BAND_MAX] = Madd_32_32(side_gain[b + STEREO_DFT_BAND_MAX], nrg_norm2 , Mpy_32_16_1(block_nrg[block] , mult( ptr_sin_az[azimuth[block][b]] , ptr_cos_el[elevation[block][b]]))); - move32(); - } -#else IF( EQ_16( b_wide_panning, 1 ) ) { Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), get_panning( azimuth[block][b], elevation[block][b] ) ); - IF( NE_16( q_div1, 0 ) ) + IF( q_div1 ) { temp = L_shl_sat( temp, q_div1 ); } @@ -666,29 +608,31 @@ static void map_params_dirac_to_stereo( ELSE { Word32 temp = L_mult( BASOP_Util_Divide3232_Scale( block_nrg[block], nrg_norm2, &q_div1 ), mult( ptr_sin_az[azimuth[block][b]], ptr_cos_el[elevation[block][b]] ) ); - IF( NE_16( q_div1, 0 ) ) + IF( q_div1 ) { temp = L_shl_sat( temp, q_div1 ); } side_gain[b + STEREO_DFT_BAND_MAX] = L_add_sat( side_gain[b + STEREO_DFT_BAND_MAX], temp ); move32(); } -#endif } q_sqrt = 0; + move16(); side_gain[b] = Mpy_32_32( side_gain[b], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); move32(); - IF( NE_16( q_sqrt, 0 ) ) + IF( q_sqrt ) { side_gain[b] = L_shl( side_gain[b], q_sqrt ); q_sqrt = 0; + move16(); } side_gain[b + STEREO_DFT_BAND_MAX] = Mpy_32_32( side_gain[b + STEREO_DFT_BAND_MAX], Sqrt32( L_sub( MAX_32, diffuseness[b] ), &q_sqrt ) ); move32(); - IF( NE_16( q_sqrt, 0 ) ) + IF( q_sqrt ) { side_gain[b + STEREO_DFT_BAND_MAX] = L_shl( side_gain[b], q_sqrt ); q_sqrt = 0; + move16(); } res_pred_gain[b] = Mpy_32_16_1( diffuseness[b], sub( MAX_16, surrCoh[b] ) ); move32(); @@ -728,7 +672,9 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( Word32 hb_nrg2 = EPSILON_FIX; move32(); - IF( ( EQ_16( core, ACELP_CORE ) && EQ_16( fd_cng_flag, 0 ) ) || EQ_16( hStereoDft->core_hist[1], ACELP_CORE ) ) + test(); + test(); + IF( ( EQ_16( core, ACELP_CORE ) && !fd_cng_flag ) || EQ_16( hStereoDft->core_hist[1], ACELP_CORE ) ) { FOR( i = 0; i < shr( output_frame, 2 ); i++ ) { @@ -736,9 +682,11 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( } hStereoDft->hb_nrg_subr_fx[0] = hb_nrg2; + move32(); hStereoDft->q_hb_nrg_subr = sub( shl( q_hb_synth, 1 ), 31 ); move32(); hb_nrg = L_add( hb_nrg, hb_nrg2 ); + move32(); hb_nrg2 = EPSILON_FIX; move32(); @@ -759,8 +707,9 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( { IF( GT_16( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ) ) { - v_shr( hStereoDft->hb_stefi_sig_fx, sub( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ), hStereoDft->hb_stefi_sig_fx, sizeof( hStereoDft->hb_stefi_sig_fx ) / sizeof( hStereoDft->hb_stefi_sig_fx[0] ) ); + v_shr( hStereoDft->hb_stefi_sig_fx, sub( hStereoDft->q_hb_stefi_sig_fx, q_hb_synth ), hStereoDft->hb_stefi_sig_fx, idiv1616( sizeof( hStereoDft->hb_stefi_sig_fx ), sizeof( hStereoDft->hb_stefi_sig_fx[0] ) ) ); hStereoDft->q_hb_stefi_sig_fx = q_hb_synth; + move16(); Copy32( hb_synth, hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, output_frame ); } ELSE @@ -774,7 +723,9 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( set_val_Word32( hStereoDft->hb_stefi_sig_fx + hStereoDft->hb_stefi_delay, 0, output_frame ); #ifdef MSAN_FIX hStereoDft->hb_nrg_subr_fx[0] = 0; + move32(); hStereoDft->hb_nrg_subr_fx[1] = 0; + move32(); #endif // MSAN_FIX } hStereoDft->hb_nrg_subr_fx[0] = hStereoDft->hb_nrg_subr_fx[0]; // imult3216(hStereoDft->hb_nrg_subr_fx[0] , shr(hStereoDft->NFFT, 1)); @@ -785,8 +736,14 @@ static void ivas_sba_dirac_stereo_compute_td_stefi_nrgs( move32(); hStereoDft->td_gain_fx[0] = 0; move32(); - hStereoDft->core_hist[0] = ( fd_cng_flag ) ? TCX_20_CORE : core; /* full signal available for DTX with FD-CNG, thus apply stereo filling on full spectrum like in TCX */ + hStereoDft->core_hist[0] = core; /* full signal available for DTX with FD-CNG, thus apply stereo filling on full spectrum like in TCX */ move16(); + + if ( fd_cng_flag ) + { + hStereoDft->core_hist[0] = TCX_20_CORE; + move16(); + } return; } @@ -808,9 +765,9 @@ static void ivas_sba_dirac_stereo_compute_hb_gain( move16(); /* last band covers whole HB range, no averaging needed */ - hb_gain[0] = hStereoDft->side_gain_fx[k_offset * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1]; + hb_gain[0] = hStereoDft->side_gain_fx[sub( add( i_mult( k_offset, STEREO_DFT_BAND_MAX ), hStereoDft->nbands ), 1 )]; move32(); - hb_gain[1] = hStereoDft->side_gain_fx[( k_offset + 1 ) * STEREO_DFT_BAND_MAX + hStereoDft->nbands - 1]; + hb_gain[1] = hStereoDft->side_gain_fx[sub( add( i_mult( add( k_offset, 1 ), STEREO_DFT_BAND_MAX ), hStereoDft->nbands ), 1 )]; move32(); return; @@ -838,10 +795,16 @@ static void ivas_sba_dirac_stereo_upmix_hb( Word32 gp, gm; Word16 gain_fac; - IF( EQ_16( mcmasa, 0 ) ) + IF( !mcmasa ) { - gain_fac = ( bwidth == FB ) ? (Word32) 0x2000 : (Word32) 0x2A3D; /* last matrix element not used for SWB, divide by 3 instead of 4*/ + gain_fac = (Word32) 0x2A3D; /* last matrix element not used for SWB, divide by 3 instead of 4*/ move16(); + if ( EQ_16( bwidth, FB ) ) + { + gain_fac = (Word32) 0x2000; + move16(); + } + IF( sba_mono_flag ) { gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8], gain_fac ), @@ -851,11 +814,13 @@ static void ivas_sba_dirac_stereo_upmix_hb( { gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11], gain_fac ); } + FOR( i = 0; i < shr( output_frame, 1 ); i++ ) { hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); move32(); } + gp = L_add( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][8 + IVAS_MAX_NUM_BANDS], gain_fac ), Madd_32_16( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[0][0][9 + IVAS_MAX_NUM_BANDS], gain_fac ), hStereoDft->mixer_mat_smooth_fx[0][0][10 + IVAS_MAX_NUM_BANDS], gain_fac ) ); @@ -863,6 +828,7 @@ static void ivas_sba_dirac_stereo_upmix_hb( { gp = Madd_32_16( gp, hStereoDft->mixer_mat_smooth_fx[0][0][11 + IVAS_MAX_NUM_BANDS], gain_fac ); } + FOR( i = shr( output_frame, 1 ); i < output_frame; i++ ) { hb_stereo_synth[0][i] = Mpy_32_32( hb_synth[i], gp ); @@ -1164,9 +1130,16 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( move16(); FOR( k = 0; k < 2; k++ ) { - FOR( i_sf = k * 2; i_sf < ( k + 1 ) * 2; i_sf++ ) + FOR( i_sf = shl( k, 1 ); i_sf < shl( add( k, 1 ), 1 ); i_sf++ ) { - md_sf = (Word16) ( EQ_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ? i_sf : 0 ); + md_sf = 0; + move16(); + + IF( EQ_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + md_sf = i_sf; + move16(); + } IF( hStereoDft->first_frame ) { FOR( i = 0; i < 2; i++ ) @@ -1176,12 +1149,12 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( FOR( b = 0; b < hStereoDft->nbands; b++ ) { // The Q format of mixer_mat_fx is Q30 so applying the left shift. - hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = L_shl_sat( hMdDec->mixer_mat_fx[i][j][b], 1 ); + hStereoDft->mixer_mat_smooth_fx[i][j][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->mixer_mat_fx[i][j][b], 1 ); move32(); } FOR( ; b < IVAS_MAX_NUM_BANDS; b++ ) { - hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = 0; + hStereoDft->mixer_mat_smooth_fx[i][j][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )] = 0; move32(); } } @@ -1199,7 +1172,7 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( move16(); // The Q format of mixer_mat_prev_fx is Q30 so applying the left shift. hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS] = - L_add_sat( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[i][j][b + k * IVAS_MAX_NUM_BANDS], beta ), + L_add_sat( Mpy_32_16_1( hStereoDft->mixer_mat_smooth_fx[i][j][add( b, i_mult( k, IVAS_MAX_NUM_BANDS ) )], beta ), L_shl_sat( Mpy_32_16_1( hMdDec->mixer_mat_prev_fx[i_hist][i][j][b], sub( (Word16) 0x7FFF, beta ) ), Q1 ) ); move32(); } @@ -1218,7 +1191,7 @@ void ivas_sba_dirac_stereo_smooth_parameters_fx( { FOR( b = 0; b < hStereoDft->nbands; b++ ) { - hMdDec->mixer_mat_prev_fx[4][i][j][b] = hMdDec->mixer_mat_fx[i][j][b + md_sf * IVAS_MAX_NUM_BANDS]; + hMdDec->mixer_mat_prev_fx[4][i][j][b] = hMdDec->mixer_mat_fx[i][j][add( b, i_mult( md_sf, IVAS_MAX_NUM_BANDS ) )]; move32(); } } @@ -1265,25 +1238,30 @@ void ivas_sba_dirac_stereo_dec_fx( hCPE = st_ivas->hCPE[0]; hStereoDft = hCPE->hStereoDft; q = hCPE->hStereoDft->q_dft; + move16(); q_dft[0] = hCPE->hStereoDft->q_dft; + move16(); q_dft[1] = hCPE->hStereoDft->q_dft; + move16(); #ifdef MSAN_FIX - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); #else Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #endif IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), negate( sub( Q11, hCPE->hStereoDft->q_dft ) ) ); #else Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), -( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX hSCE->q_prev_hb_synth_fx = hCPE->hStereoDft->q_dft; + move16(); } - IF( GT_16( st_ivas->nchan_transport, 1 ) && EQ_16( mcmasa, 0 ) ) + test(); + IF( GT_16( st_ivas->nchan_transport, 1 ) && !mcmasa ) { dtx_flag = 0; move16(); @@ -1293,14 +1271,21 @@ void ivas_sba_dirac_stereo_dec_fx( ELSE { dtx_flag = (Word16) LE_32( hSCE->hCoreCoder[0]->core_brate, SID_2k40 ); + move16(); + test(); fd_cng_flag = ( dtx_flag && EQ_16( hSCE->hCoreCoder[0]->cng_type, FD_CNG ) ); + move16(); } sba_mono_flag = (Word16) EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ); + move16(); - memOffset = NS2SA( L_mult0( output_frame, FRAMES_PER_SEC ), L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ); + memOffset = NS2SA( L_mult0( output_frame, FRAMES_PER_SEC ), IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); + move16(); ivas_sba_dirac_stereo_config( hStereoDft->hConfig ); - hStereoDft->nbands = ivas_sba_dirac_stereo_band_config( hStereoDft->band_limits, st_ivas->hDecoderConfig->output_Fs, hStereoDft->NFFT, ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !mcmasa ) ); + test(); + test(); + hStereoDft->nbands = ivas_sba_dirac_stereo_band_config( hStereoDft->band_limits, st_ivas->hDecoderConfig->output_Fs, hStereoDft->NFFT, ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) ); stereo_dft_dec_update_fx( hStereoDft, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); IF( GT_16( st_ivas->nchan_transport, 1 ) ) { @@ -1323,9 +1308,13 @@ void ivas_sba_dirac_stereo_dec_fx( } /* mapping of DirAC parameters (azimuth, elevation, diffuseness) to DFT Stereo parameters (side gain, prediction gain) */ + test(); + test(); + test(); + test(); map_params_dirac_to_stereo( hStereoDft, st_ivas->hQMetaData, tmp_synth, DFT[0], st_ivas->ivas_format == MC_FORMAT, - ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ) ? hSCE->hCoreCoder[0]->L_frame : output_frame, - ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ), hSCE != NULL ? hSCE->q_save_synth_fx : 0 ); + ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || mcmasa ) ? hSCE->hCoreCoder[0]->L_frame : output_frame, + ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || mcmasa ), hSCE != NULL ? hSCE->q_save_synth_fx : 0 ); IF( ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) { @@ -1333,12 +1322,12 @@ void ivas_sba_dirac_stereo_dec_fx( } /* DFT Stereo upmix */ - stereo_dft_dec_fx( hStereoDft, hCPE->hCoreCoder[0], DFT, NULL, NULL, 1 /*st_ivas->sba_dirac_stereo_flag*/, sba_mono_flag, ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hMdDec : NULL, ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hFbMixer->cross_fade_start_offset : 0, + stereo_dft_dec_fx( hStereoDft, hCPE->hCoreCoder[0], DFT, NULL, NULL, 1 /*st_ivas->sba_dirac_stereo_flag*/, sba_mono_flag, ( st_ivas->hSpar != NULL && !mcmasa ) ? st_ivas->hSpar->hMdDec : NULL, ( st_ivas->hSpar != NULL && ( !mcmasa ) ) ? st_ivas->hSpar->hFbMixer->cross_fade_start_offset : 0, st_ivas->hDecoderConfig->output_Fs, st_ivas->nchan_transport, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); /* DFT synthesis */ stereo_dft_dec_synthesize_fx( hCPE, DFT, 0, output[0], output_frame ); - IF( EQ_16( sba_mono_flag, 0 ) ) + IF( !sba_mono_flag ) { stereo_dft_dec_synthesize_fx( hCPE, DFT, 1, output[1], output_frame ); } @@ -1346,7 +1335,7 @@ void ivas_sba_dirac_stereo_dec_fx( synchro_synthesis_fx( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); /* output scaling */ - IF( EQ_16( sba_mono_flag, 0 ) ) + IF( !sba_mono_flag ) { v_shr( output[0], 1, output[0], output_frame ); v_shr( output[1], 1, output[1], output_frame ); @@ -1356,26 +1345,33 @@ void ivas_sba_dirac_stereo_dec_fx( IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { Copy32( hSCE->save_hb_synth_fx + output_frame - memOffset, tmp_buf, memOffset ); - Copy32( hSCE->save_hb_synth_fx, hSCE->save_hb_synth_fx + memOffset, output_frame - memOffset ); + Copy32( hSCE->save_hb_synth_fx, hSCE->save_hb_synth_fx + memOffset, sub( output_frame, memOffset ) ); Copy32( hSCE->prev_hb_synth_fx, hSCE->save_hb_synth_fx, memOffset ); v_shr( tmp_buf, sub( hSCE->q_prev_hb_synth_fx, hSCE->q_save_hb_synth_fx ), hSCE->prev_hb_synth_fx, memOffset ); } - IF( ( EQ_16( hCPE->hCoreCoder[0]->core, ACELP_CORE ) || EQ_16( hCPE->hCoreCoder[0]->last_core, ACELP_CORE ) ) && EQ_16( fd_cng_flag, 0 ) && EQ_16( st_ivas->nchan_transport, 1 ) ) + test(); + test(); + test(); + IF( ( EQ_16( hCPE->hCoreCoder[0]->core, ACELP_CORE ) || EQ_16( hCPE->hCoreCoder[0]->last_core, ACELP_CORE ) ) && !fd_cng_flag && EQ_16( st_ivas->nchan_transport, 1 ) ) { /* upmix ACELP BWE */ ivas_sba_dirac_stereo_compute_hb_gain( hStereoDft, hb_gain ); - ivas_sba_dirac_stereo_upmix_hb( hb_synth_stereo, hSCE->save_hb_synth_fx, hb_gain, output_frame, ( ( st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) || mcmasa ), sba_mono_flag, hSCE->hCoreCoder[0]->bwidth, hStereoDft ); + test(); + test(); + ivas_sba_dirac_stereo_upmix_hb( hb_synth_stereo, hSCE->save_hb_synth_fx, hb_gain, output_frame, ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) || mcmasa ), sba_mono_flag, hSCE->hCoreCoder[0]->bwidth, hStereoDft ); /* add HB to ACELP core */ v_add_fx( output[0], hb_synth_stereo[0], output[0], output_frame ); - IF( EQ_16( sba_mono_flag, 0 ) ) + IF( !sba_mono_flag ) { v_add_fx( output[1], hb_synth_stereo[1], output[1], output_frame ); /* apply TD Stereo Filling as is done in ICBWE */ - ivas_sba_dirac_stereo_apply_td_stefi( hStereoDft, output, output_frame, ( ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) && !mcmasa ) ); + test(); + test(); + ivas_sba_dirac_stereo_apply_td_stefi( hStereoDft, output, output_frame, ( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && !mcmasa ) ); } } @@ -1386,18 +1382,19 @@ void ivas_sba_dirac_stereo_dec_fx( } #ifdef MSAN_FIX - Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); #else Scale_sig32( hCPE->prev_hb_synth_fx[0], NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #endif IF( hSCE != NULL ) { #ifdef MSAN_FIX - Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); + Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); #else Scale_sig32( hSCE->prev_hb_synth_fx, NS2SA_fx2( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ), ( Q11 - hCPE->hStereoDft->q_dft ) ); #endif // MSAN_FIX hSCE->q_prev_hb_synth_fx = Q11; + move16(); } return; diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 86da344d9..03b5eb85c 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -132,24 +132,25 @@ void ivas_sba2mc_cldfb_fixed( const Word32 *hoa_dec_mtx /* i : HOA decoding mtx */ ) { - int16_t iBlock, iBand, n, m; + Word16 iBlock, iBand, n, m; Word32 realOut_fx[16][MAX_PARAM_SPATIAL_SUBFRAMES * CLDFB_NO_CHANNELS_MAX], imagOut_fx[16][MAX_PARAM_SPATIAL_SUBFRAMES * CLDFB_NO_CHANNELS_MAX]; Word32 g_fx; Word32 *p_real_fx, *p_imag_fx, *p_realOut_fx, *p_imagOut_fx; - int16_t nb_channels_in; + Word16 nb_channels_in; push_wmops( "ivas_sba2mc_cldfb_fixed" ); nb_channels_in = hInSetup.nchan_out_woLFE; - assert( ( nb_channels_in == 16 ) && ( nb_channels_out == 11 ) && "ivas_sba2mc_cldfb_fixed; only HOA3 to CICP19 is for now supported!" ); + move16(); + assert( EQ_16( nb_channels_in, 16 ) && EQ_16( nb_channels_out, 11 ) && "ivas_sba2mc_cldfb_fixed; only HOA3 to CICP19 is for now supported!" ); FOR( n = 0; n < nb_channels_out; n++ ) { - set_l( realOut_fx[n], 0, MAX_PARAM_SPATIAL_SUBFRAMES * nb_bands ); - set_l( imagOut_fx[n], 0, MAX_PARAM_SPATIAL_SUBFRAMES * nb_bands ); + set_l( realOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); + set_l( imagOut_fx[n], 0, i_mult( MAX_PARAM_SPATIAL_SUBFRAMES, nb_bands ) ); FOR( m = 0; m < nb_channels_in; m++ ) { - g_fx = hoa_dec_mtx[SBA_NHARM_HOA3 * n + m]; // Q29 + g_fx = hoa_dec_mtx[add( SBA_NHARM_HOA3 * n, m )]; // Q29 p_realOut_fx = realOut_fx[n]; p_imagOut_fx = imagOut_fx[n]; @@ -159,8 +160,10 @@ void ivas_sba2mc_cldfb_fixed( p_imag_fx = ImagBuffer[m][iBlock]; FOR( iBand = 0; iBand < nb_bands; iBand++ ) { - *p_realOut_fx = *p_realOut_fx + Mpy_32_32( L_shl_sat( g_fx, Q2 ), *( p_real_fx++ ) ); // Q_real - *p_imagOut_fx = *p_imagOut_fx + Mpy_32_32( L_shl_sat( g_fx, Q2 ), *( p_imag_fx++ ) ); // Q_imag + *p_realOut_fx = L_add( *p_realOut_fx, Mpy_32_32( L_shl_sat( g_fx, Q2 ), *( p_real_fx++ ) ) ); // Q_real + move32(); + *p_imagOut_fx = L_add( *p_imagOut_fx, Mpy_32_32( L_shl_sat( g_fx, Q2 ), *( p_imag_fx++ ) ) ); // Q_imag + move32(); p_realOut_fx++; p_imagOut_fx++; } @@ -180,7 +183,9 @@ void ivas_sba2mc_cldfb_fixed( FOR( iBand = 0; iBand < nb_bands; iBand++ ) { *( p_real_fx++ ) = *p_realOut_fx++; + move32(); *( p_imag_fx++ ) = *p_imagOut_fx++; + move32(); } } } @@ -228,27 +233,30 @@ void ivas_mc2sba_fx( move16(); FOR( i = 0; i < add( hIntSetup.nchan_out_woLFE, hIntSetup.num_lfe ); i++ ) { - IF( GT_16( hIntSetup.num_lfe, 0 ) && EQ_16( i, hIntSetup.index_lfe[idx_lfe] ) ) + IF( ( hIntSetup.num_lfe > 0 ) && EQ_16( i, hIntSetup.index_lfe[idx_lfe] ) ) { - IF( GT_16( gain_lfe_fx, 0 ) ) + IF( gain_lfe_fx > 0 ) { /* Add LFE to omni W with gain*/ FOR( k = 0; k < output_frame; k++ ) { buffer_tmp_fx[0][k] = L_add( buffer_tmp_fx[0][k], L_shl( Mult_32_16( in_buffer_td_fx[i][k], gain_lfe_fx ), 1 ) ); /*Q+14-15+1==Q*/ + move32(); } } IF( LT_16( idx_lfe, sub( hIntSetup.num_lfe, 1 ) ) ) { - idx_lfe++; + idx_lfe = add( idx_lfe, 1 ); } } ELSE { azimuth = (Word16) L_shr( hIntSetup.ls_azimuth_fx[idx_in], 22 ); + move16(); elevation = (Word16) L_shr( hIntSetup.ls_elevation_fx[idx_in], 22 ); - idx_in++; + move16(); + idx_in = add( idx_in, 1 ); ivas_dirac_dec_get_response_fx( azimuth, elevation, @@ -262,6 +270,7 @@ void ivas_mc2sba_fx( FOR( k = 0; k < output_frame; k++ ) { buffer_tmp_fx[j][k] = L_add( buffer_tmp_fx[j][k], L_shl( Mult_32_32( in_buffer_td_fx[i][k], gains_fx[j] ), 2 ) ); /*Q+29-31+2==Q*/ + move32(); } } } @@ -393,18 +402,20 @@ void ivas_param_mc_mc2sba_cldfb_fx( FOR( idx_ch = 0; idx_ch < add( hTransSetup.nchan_out_woLFE, hTransSetup.num_lfe ); idx_ch++ ) { - IF( GT_16( hTransSetup.num_lfe, 0 ) && EQ_16( idx_ch, hTransSetup.index_lfe[idx_lfe] ) ) + IF( ( hTransSetup.num_lfe > 0 ) && EQ_16( idx_ch, hTransSetup.index_lfe[idx_lfe] ) ) { - IF( GT_32( gain_lfe_fx, 0 ) ) + IF( gain_lfe_fx > 0 ) { /* Add LFE to Omni Channel i.e. W (Just first Band) */ Cldfb_RealBuffer_tmp_fx[0][0] = L_add_sat( Cldfb_RealBuffer_tmp_fx[0][0], Mult_32_16( L_shl( Cldfb_RealBuffer_fx[idx_ch][slot_idx][0], 1 ), gain_lfe_fx ) ); + move32(); Cldfb_ImagBuffer_tmp_fx[0][0] = L_add_sat( Cldfb_ImagBuffer_tmp_fx[0][0], Mult_32_16( L_shl( Cldfb_ImagBuffer_fx[idx_ch][slot_idx][0], 1 ), gain_lfe_fx ) ); + move32(); } IF( LT_16( idx_lfe, sub( hTransSetup.num_lfe, 1 ) ) ) { - idx_lfe++; + idx_lfe = add( idx_lfe, 1 ); } } ELSE @@ -415,11 +426,13 @@ void ivas_param_mc_mc2sba_cldfb_fx( FOR( idx_band = 0; idx_band < nBands; idx_band++ ) { Cldfb_RealBuffer_tmp_fx[idx_out][idx_band] = L_add( Cldfb_RealBuffer_tmp_fx[idx_out][idx_band], Mult_32_32( ( *gains_fx ), Cldfb_RealBuffer_fx[idx_ch][slot_idx][idx_band] ) ); + move32(); Cldfb_ImagBuffer_tmp_fx[idx_out][idx_band] = L_add( Cldfb_ImagBuffer_tmp_fx[idx_out][idx_band], Mult_32_32( ( *gains_fx ), Cldfb_ImagBuffer_fx[idx_ch][slot_idx][idx_band] ) ); + move32(); } gains_fx++; } - idx_in++; + idx_in = add( idx_in, 1 ); } } FOR( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ ) @@ -521,7 +534,7 @@ Word16 ivas_sba_remapTCs_fx( move16(); IF( EQ_16( nchan_remapped, 3 ) ) { - nchan_remapped++; + nchan_remapped = add( nchan_remapped, 1 ); IF( EQ_16( nchan_remapped, 4 ) ) { Copy32( sba_data_fx[2], sba_data_fx[3], output_frame ); @@ -542,7 +555,8 @@ Word16 ivas_sba_remapTCs_fx( move32(); sba_data_fx[3][i] = temp_fx; move32(); - IF( EQ_16( st_ivas->nchan_transport, 3 ) ) + + if ( EQ_16( st_ivas->nchan_transport, 3 ) ) { sba_data_fx[2][i] = 0; move32(); @@ -619,7 +633,7 @@ void ivas_ism2sba_sf_fx( Word32 *tc_fx, *out_fx, gain_fx, prev_gain_fx; Word16 sba_num_chans; - assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" ); + assert( LE_16( sba_order, 3 ) && "Only order up to 3 is supported!" ); assert( hIsmRendererData != NULL && "hIsmRendererData not allocated!" ); /* Init*/ sba_num_chans = imult1616( add( sba_order, 1 ), add( sba_order, 1 ) ); @@ -641,7 +655,8 @@ void ivas_ism2sba_sf_fx( FOR( k = 0; k < n_samples_to_render; k++ ) { g1_fx = sub( 32767, *g2_fx ); - *( out_fx ) += Mult_32_32( ( Mult_32_16( gain_fx, ( *( g2_fx ) ) ) + Mult_32_16( prev_gain_fx, g1_fx ) ), ( *( tc_fx ) ) ); /*Q_buffer_in + 29 - 31*/ + *( out_fx ) = L_add( *( out_fx ), Mult_32_32( ( Mult_32_16( gain_fx, ( *( g2_fx ) ) ) + Mult_32_16( prev_gain_fx, g1_fx ) ), ( *( tc_fx ) ) ) ); /*Q_buffer_in + 29 - 31*/ + move32(); g2_fx++; tc_fx++; out_fx++; @@ -865,9 +880,9 @@ void ivas_sba_mix_matrix_determiner_fx( temp_fx = MAX16B; move32(); } - ELSE IF( LT_32( temp_fx, ( -1 * PCM16_TO_FLT_FAC_FX ) ) ) + ELSE IF( LT_32( temp_fx, L_negate( PCM16_TO_FLT_FAC_FX ) ) ) { - temp_fx = ( -1 * PCM16_TO_FLT_FAC_FX ); + temp_fx = L_negate( PCM16_TO_FLT_FAC_FX ); move32(); } temp_fx = Mult_32_32( MAX_32 / PCM16_TO_FLT_FAC_FX, L_shl( temp_fx, Q_p_output ) ); @@ -900,109 +915,6 @@ void ivas_sba_mix_matrix_determiner_fx( ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); return; } -#endif // IVAS_FLOAT_FIXED - -#ifdef IVAS_FLOAT_FIXED - -void ivas_sba_mix_matrix_determiner( - SPAR_DEC_HANDLE hSpar, /* i/o: SPAR decoder handle */ - float *output[], /* i/o: transport/output audio channels */ - const int16_t bfi, /* i : BFI flag */ - const int16_t nchan_remapped, /* i : num channels after remapping of TCs */ - const int16_t output_frame, /* i : output frame length */ - const int16_t num_md_sub_frames /* i : number of subframes in mixing matrix*/ -) -{ - int16_t i, ch; - float temp; - int16_t num_bands_out, nchan_transport, nchan_out; - - /* Convert numeric range */ - for ( ch = 0; ch < nchan_remapped; ch++ ) - { - for ( i = 0; i < output_frame; i++ ) - { - temp = output[ch][i]; - temp = floorf( temp + 0.5f ); - - if ( temp > MAX16B_FLT ) - { - temp = MAX16B_FLT; - } - else if ( temp < ( -1.0f * PCM16_TO_FLT_FAC ) ) - { - temp = ( -1.0f * PCM16_TO_FLT_FAC ); - } - temp *= ( 1.0f / PCM16_TO_FLT_FAC ); - output[ch][i] = temp; - } - } - - /* AGC */ - nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; - nchan_out = nchan_transport; -#ifndef IVAS_FLOAT_FIXED - ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &output[0][0], output_frame, "flt_ivas_agc_dec_process_output.txt", NULL ); -#endif // DUMPS_ENABLED -#else - Word32 *output_fx[20]; - FOR( Word16 c = 0; c < nchan_transport; c++ ) - { - output_fx[c] = malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); - FOR( Word16 j = 0; j < output_frame; j++ ) - { - output_fx[c][j] = (Word32) ( output[c][j] * ONE_IN_Q14 ); - } - } - - ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); - - FOR( Word16 c = 0; c < nchan_transport; c++ ) - { - FOR( Word16 j = 0; j < output_frame; j++ ) - { - output[c][j] = (float) output_fx[c][j] / ONE_IN_Q11; - } - } - -#ifdef DUMPS_ENABLED - dbgwrite_txt( &output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); -#endif // DUMPS_ENABLED - - FOR( Word16 c = 0; c < nchan_transport; c++ ) - { - free( output_fx[c] ); - } -#endif // !IVAS_FLOAT_FIXED - - /* Convert numeric range back */ - for ( ch = 0; ch < nchan_out; ch++ ) - { - for ( i = 0; i < output_frame; i++ ) - { - output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC; - } - } - - /* Mixing matrix determiner */ - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; -#ifdef IVAS_FLOAT_FIXED -#if 1 /*Float to fixed changes */ - // Word16 num_out_ch; - // num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; - hSpar->hMdDec->Q_mixer_mat = 31; - // Word16 num_in_ch; - // num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; -#endif - ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); -#else - ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ); -#endif // IVAS_FLOAT_FIXED - - return; -} #else diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 6c183fc07..78ce1a71a 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -73,13 +73,17 @@ ivas_error ivas_sce_dec_fx( st = hSCE->hCoreCoder[0]; st->BER_detect = s_or( st->BER_detect, st_ivas->BER_detect ); + move16(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; + move32(); IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) ) { st->cng_type = FD_CNG; + move16(); } /*------------------------------------------------------------------* @@ -87,52 +91,70 @@ ivas_error ivas_sce_dec_fx( *-----------------------------------------------------------------*/ /* set total_brate - needed in DTX */ + test(); + test(); + test(); + test(); IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { st->total_brate = L_sub( ivas_total_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + move16(); + test(); assert( EQ_32( st->total_brate, SID_2k40 ) && "SCE SID must be 2.4kbps!" ); + test(); IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( st_ivas->hISMDTX.sce_id_dtx, sce_id ) ) { st->total_brate = FRAME_NO_DATA; + move32(); } } ELSE IF( !st_ivas->bfi && EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { st->total_brate = FRAME_NO_DATA; + move32(); } ELSE IF( !st_ivas->bfi && NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && LE_32( last_ivas_total_brate, IVAS_SID_5k2 ) ) { st->total_brate = L_sub( hSCE->element_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + move32(); } /* read the bandwidth */ + test(); IF( st_ivas->bfi || LE_32( st->total_brate, SID_2k40 ) ) { /* BFI or SID/NO_DATA frame -> do nothing */ } ELSE { + test(); + test(); + test(); IF( st->low_rate_mode ) { /* ISM Low-rate mode -> always WB */ st->bwidth = WB; + move16(); } ELSE IF( LT_32( hSCE->element_brate, MIN_BRATE_SWB_SCE ) ) { /* only WB is supported */ st->bwidth = WB; + move16(); } ELSE IF( ( LT_32( hSCE->element_brate, MIN_BRATE_FB_STEREO ) && !st->is_ism_format ) || ( LT_32( hSCE->element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) ) { /* WB and SWB are supported */ st->bwidth = add( get_next_indice( st, 1 ), WB ); + move16(); } ELSE { /* WB, SWB and FB are supported */ st->bwidth = get_next_indice( st, NBITS_BWIDTH ); + move16(); } } @@ -141,59 +163,80 @@ ivas_error ivas_sce_dec_fx( *-----------------------------------------------------------------*/ st->idchan = 0; + move16(); st->element_mode = IVAS_SCE; + move16(); /* Force to MODE1 in IVAS */ st->codec_mode = MODE1; + move16(); /* set "bits_frame_nominal" */ + test(); IF( ( st_ivas->hQMetaData != NULL ) && NE_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) ) { + test(); + test(); + test(); + test(); IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); + move16(); } ELSE IF( ( EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) && GE_32( ivas_total_brate, MCMASA_SEPARATE_BRATE ) ) || ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) ) { st->bits_frame_nominal = extract_l( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ) ); + move16(); } ELSE IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MODE_NONE ) && EQ_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); + move16(); } ELSE { st->bits_frame_nominal = st_ivas->hQMetaData->bits_frame_nominal; + move16(); } } ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) ) { st->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hSpar->core_nominal_brate, INV_FRAME_PER_SEC_Q15 ) ); + move16(); } ELSE { st->bits_frame_nominal = extract_l( L_sub( Mpy_32_16_1( hSCE->element_brate, INV_FRAME_PER_SEC_Q15 ), ISM_NB_BITS_METADATA_NOMINAL ) ); + move16(); } /* set "total_brate" */ + test(); + test(); + test(); + test(); IF( !st_ivas->bfi && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) { st->total_brate = L_sub( ivas_total_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); - IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( st_ivas->hISMDTX.sce_id_dtx, sce_id ) ) + if ( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( st_ivas->hISMDTX.sce_id_dtx, sce_id ) ) { st->total_brate = FRAME_NO_DATA; + move32(); } } ELSE IF( !st_ivas->bfi && EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { st->total_brate = ivas_total_brate; + move32(); } ELSE IF( !st_ivas->bfi && NE_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) && NE_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) /* note: in ISMs, total_brate[] is set in ivas_ism_config() */ { st->total_brate = L_sub( hSCE->element_brate, L_shr( L_mult( nb_bits_metadata, FRAMES_PER_SEC ), 1 ) ); + move32(); } /*----------------------------------------------------------------* @@ -201,36 +244,52 @@ ivas_error ivas_sce_dec_fx( *----------------------------------------------------------------*/ /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ + test(); + test(); + test(); + test(); + test(); IF( ( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) && st->low_rate_mode && !( EQ_32( st->total_brate, SID_2k40 ) || EQ_32( st->total_brate, FRAME_NO_DATA ) ) ) { st->flag_ACELP16k = 0; + move16(); } ELSE { st->flag_ACELP16k = set_ACELP_flag_IVAS( IVAS_SCE, hSCE->element_brate, st->total_brate, 0, 0, -1, -1 ); + move16(); } IF( is_DTXrate( ivas_total_brate ) ) { st->VAD = 0; + move16(); } ELSE { st->VAD = 1; + move16(); } + + test(); + test(); + test(); IF( st->VAD && LE_32( hSCE->element_brate, CNA_MAX_BRATE ) ) { st->flag_cna = 1; + move16(); } ELSE IF( ( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) ) && LE_32( hSCE->element_brate, ACELP_32k ) ) { st->flag_cna = 1; + move16(); } ELSE { st->flag_cna = 0; + move16(); } /*----------------------------------------------------------------* @@ -239,7 +298,7 @@ ivas_error ivas_sce_dec_fx( set32_fx( output[0], 0, L_FRAME48k ); - IF( ( error = ivas_core_dec( st_ivas, hSCE, NULL, NULL, 1, output, outputHB, NULL, st_ivas->sba_dirac_stereo_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_core_dec( st_ivas, hSCE, NULL, NULL, 1, output, outputHB, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -249,12 +308,14 @@ ivas_error ivas_sce_dec_fx( /* skip addition of ACELP BWE for now, will be done after upmix */ Copy32( outputHB[0], hSCE->save_hb_synth_fx, output_frame ); hSCE->q_save_hb_synth_fx = Q11; + move16(); } ELSE IF( !st_ivas->sba_dirac_stereo_flag ) { Word32 output_Fs; output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); /*----------------------------------------------------------------* * LB synthesis synchronization between IVAS formats @@ -280,8 +341,10 @@ ivas_error ivas_sce_dec_fx( *----------------------------------------------------------------*/ hSCE->last_element_brate = hSCE->element_brate; + move32(); st_ivas->BER_detect = s_or( st_ivas->BER_detect, st->BER_detect ); + move16(); pop_wmops(); @@ -307,6 +370,7 @@ ivas_error create_sce_dec( Word16 output_frame; error = IVAS_ERR_OK; + move16(); output_frame = extract_l( Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); /*-----------------------------------------------------------------* @@ -323,9 +387,11 @@ ivas_error create_sce_dec( *-----------------------------------------------------------------*/ hSCE->sce_id = sce_id; + move16(); hSCE->element_brate = element_brate; + move32(); - set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); + set32_fx( hSCE->prev_hb_synth_fx, 0, NS2SA_fx2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); /*-----------------------------------------------------------------* * Core Coder, 1 instance: allocate and initialize @@ -340,39 +406,42 @@ ivas_error create_sce_dec( copy_decoder_config( st_ivas, st ); st->total_brate = hSCE->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move16(); st->is_ism_format = 0; + move16(); st->ivas_format = st_ivas->ivas_format; - IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) + move16(); + + test(); + if ( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { st->is_ism_format = 1; + move16(); } // if (st_ivas->mode == IVAS_DEC_MODE_EVS) - if ( st->element_mode == EVS_MONO ) + IF( EQ_16( st->element_mode, EVS_MONO ) ) { error = init_decoder_fx( st, EVS_MONO ); - if ( error ) + IF( error ) { - { - return error; - } + return error; } } - else + ELSE { error = init_decoder_ivas_fx( st, 0, st_ivas->mc_mode ); - if ( error ) + IF( error ) { - { - return error; - } + return error; } } IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || ( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && EQ_16( st_ivas->nchan_transport, 1 ) ) ) ) { - IF( ( error = openCldfb_ivas_fx( &st->cldfbSynHB, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &st->cldfbSynHB, CLDFB_SYNTHESIS, st->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -383,7 +452,7 @@ ivas_error create_sce_dec( } /* allocate and initialize "hTdCngDec" - needed in DTX */ - IF( EQ_16( sce_id, 0 ) && st->hTdCngDec == NULL ) + IF( ( sce_id == 0 ) && st->hTdCngDec == NULL ) { IF( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) { @@ -405,6 +474,7 @@ ivas_error create_sce_dec( } set_zero_fx( hSCE->save_synth_fx, output_frame ); hSCE->q_save_synth_fx = 0; + move16(); IF( ( hSCE->save_hb_synth_fx = (Word32 *) malloc( sizeof( *( hSCE->save_hb_synth_fx ) ) * output_frame ) ) == NULL ) { @@ -412,6 +482,7 @@ ivas_error create_sce_dec( } set_zero_fx( hSCE->save_hb_synth_fx, output_frame ); hSCE->q_save_hb_synth_fx = 0; + move16(); } ELSE { diff --git a/lib_dec/ivas_sns_dec_fx.c b/lib_dec/ivas_sns_dec_fx.c index 342808ee2..8d5e1f007 100644 --- a/lib_dec/ivas_sns_dec_fx.c +++ b/lib_dec/ivas_sns_dec_fx.c @@ -50,17 +50,19 @@ *-------------------------------------------------------------------*/ static void sns_1st_dec_fx( - const int16_t index, /* i : codebook index */ - const int16_t core, - const int16_t L_frame, + const Word16 index, /* i : codebook index */ + const Word16 core, + const Word16 L_frame, Word32 *snsq_fx /* i/o: i:prediction o:quantized sns */ ) { Word16 i; const Word16 *p_dico, *means; - const Word16 cdbk_fix = 8; // 1.f / powf( 2, SNS_CDBKS_BITS_4_FRAC ) in Q15 + const Word16 cdbk_fix = 8; // 1.f / powf( 2, SNS_CDBKS_BITS_4_FRAC ) in Q15 + move16(); const Word16 means_fix = 2; // 1.f / powf( 2, SNS_MEANS_BITS_4_FRAC ) in Q15 + move16(); means = NULL; SWITCH( L_frame ) @@ -79,18 +81,20 @@ static void sns_1st_dec_fx( } - p_dico = &sns_1st_cdbk[0][core - 1][0] + ( index % 32 ) * ( M / 2 ); + p_dico = &sns_1st_cdbk[0][core - 1][0] + i_mult( index % 32, ( M / 2 ) ); FOR( i = 0; i < M / 2; i++ ) { snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); // Q16 + move32(); } - p_dico = &sns_1st_cdbk[1][core - 1][0] + ( index >> 5 ) * ( M / 2 ); + p_dico = &sns_1st_cdbk[1][sub( core, 1 )][0] + i_mult( shr( index, 5 ), ( M / 2 ) ); FOR( i = M / 2; i < M; i++ ) { snsq_fx[i] = L_add( L_mult( ( *p_dico++ ), cdbk_fix ), L_mult( means[i], means_fix ) ); + move32(); } return; @@ -109,28 +113,34 @@ static void sns_2st_dec_fx( { Word16 i; Word16 xq_fx[M]; - Word16 scale_fx = float_to_fix16( 0.400000006f, 15 ); + Word16 scale_fx = 13107; + move16(); /* quantize */ AVQ_dec_lpc( indx, xq_fx, 2 ); Word32 tmp = 0; + move32(); Word16 snsq_dIFf = 0; + move16(); Word32 tmp1; FOR( i = 0; i < M; i++ ) { tmp = L_mult( scale_fx, xq_fx[i] ); // q16 - IF( *q_snsq >= 16 ) + IF( GE_16( *q_snsq, 16 ) ) { - snsq_dIFf = *q_snsq - 16; + snsq_dIFf = sub( *q_snsq, 16 ); tmp1 = L_shr( snsq_fx[i], snsq_dIFf ); snsq_fx[i] = L_add( tmp1, tmp ); + move32(); *q_snsq = 16; + move16(); } ELSE { - snsq_dIFf = 16 - *q_snsq; + snsq_dIFf = sub( 16, *q_snsq ); tmp1 = L_shr( tmp, snsq_dIFf ); snsq_fx[i] = L_add( snsq_fx[i], tmp1 ); + move32(); } } return; @@ -142,45 +152,49 @@ static void sns_2st_dec_fx( *-------------------------------------------------------------------*/ void sns_avq_dec_fx( - int16_t *index, /* i : Quantization indices */ + Word16 *index, /* i : Quantization indices */ Word32 SNS_Q[NB_DIV][M], /* o : Quantized SNS vectors */ Word16 *q_snsq, - const int16_t L_frame, /* i : frame length */ - const int16_t numlpc /* i : Number of sets of lpc */ + const Word16 L_frame, /* i : frame length */ + const Word16 numlpc /* i : Number of sets of lpc */ ) { Word16 i, nbi, last; Word16 q_type; /* go from one-based indexing to zero-based indexing */ - last = numlpc - 1; + last = sub( numlpc, 1 ); index++; /* Decode last LPC */ sns_1st_dec_fx( *index++, numlpc, L_frame, SNS_Q[last] ); // Q16 *q_snsq = 16; + move16(); sns_2st_dec_fx( SNS_Q[last], q_snsq, index ); - nbi = 2 + index[0] + index[1]; + nbi = add( add( 2, index[0] ), index[1] ); index += nbi; /* Decode intermediate LPC (512 framing) */ - IF( numlpc == 2 ) + IF( EQ_16( numlpc, 2 ) ) { q_type = *index++; + move16(); IF( q_type == 0 ) { sns_1st_dec_fx( *index++, numlpc, L_frame, SNS_Q[0] ); *q_snsq = 16; + move16(); sns_2st_dec_fx( SNS_Q[0], q_snsq, index ); } - ELSE IF( q_type == 1 ) + ELSE IF( EQ_16( q_type, 1 ) ) { FOR( i = 0; i < M; i++ ) { SNS_Q[0][i] = SNS_Q[1][i]; + move32(); } sns_2st_dec_fx( SNS_Q[0], q_snsq, index ); } @@ -208,48 +222,69 @@ void sns_avq_dec_stereo_fx( Word32 mid_q_fx[M], side_q_fx[M]; stereo_mode = *indexl++; + move16(); + indexr++; Word16 tmp1 = 0, tmp2 = 0, q_mid = 0, q_side = 0; Word16 tmp_dIFf_q = 0; - IF( stereo_mode == 2 ) + move16(); + move16(); + move16(); + move16(); + move16(); + + IF( EQ_16( stereo_mode, 2 ) ) { /* MS coding */ tmp1 = *indexl++; + move16(); sns_1st_dec_fx( tmp1, TCX_20_CORE, L_frame, mid_q_fx ); q_mid = 16; + move16(); sns_2st_dec_fx( mid_q_fx, &q_mid, indexl ); FOR( i = 0; i < M; i++ ) { side_q_fx[i] = 0; + move32(); q_side = 31; + move16(); } - IF( *indexr++ == -1 ) + IF( EQ_16( *indexr++, -1 ) ) { sns_2st_dec_fx( side_q_fx, &q_side, indexr ); } Word32 tmp_c = 0; + move32(); FOR( i = 0; i < M; i++ ) { tmp_c = L_shr( side_q_fx[i], 1 ); // q_side - IF( q_mid >= q_side ) + IF( GE_16( q_mid, q_side ) ) { - tmp_dIFf_q = q_mid - q_side; + tmp_dIFf_q = sub( q_mid, q_side ); SNS_Ql[i] = L_add( L_shr( mid_q_fx[i], tmp_dIFf_q ), tmp_c ); // q_side + move32(); SNS_Qr[i] = L_sub( L_shr( mid_q_fx[i], tmp_dIFf_q ), tmp_c ); // q_side + move32(); *q_r = q_side; + move16(); *q_l = *q_r; + move16(); } ELSE { - tmp_dIFf_q = q_side - q_mid; + tmp_dIFf_q = sub( q_side, q_mid ); SNS_Ql[i] = L_add( mid_q_fx[i], L_shr( tmp_c, tmp_dIFf_q ) ); // q_mid + move32(); SNS_Qr[i] = L_sub( mid_q_fx[i], L_shr( tmp_c, tmp_dIFf_q ) ); // q_mid + move32(); *q_r = q_mid; + move16(); *q_l = *q_r; + move16(); } } } @@ -257,13 +292,17 @@ void sns_avq_dec_stereo_fx( { /* LR decoding */ tmp1 = *indexl++; + move16(); tmp2 = *indexr++; + move16(); sns_1st_dec_fx( tmp1, TCX_20_CORE, L_frame, SNS_Ql ); *q_l = 16; + move16(); sns_2st_dec_fx( SNS_Ql, q_l, indexl ); sns_1st_dec_fx( tmp2, TCX_20_CORE, L_frame, SNS_Qr ); *q_r = 16; + move16(); sns_2st_dec_fx( SNS_Qr, q_r, indexr ); } @@ -287,30 +326,50 @@ void dequantize_sns_fx( Decoder_State *st; sns_stereo_mode[0] = indices[0][0]; + move16(); sns_stereo_mode[1] = indices[0][1]; + move16(); zero_side_flag[0] = indices[0][2]; + move16(); zero_side_flag[1] = indices[0][3]; + move16(); FOR( ch = 0; ch < CPE_CHANNELS; ++ch ) { Word16 idxIndices; st = sts[ch]; - nSubframes = ( st->core == TCX_20_CORE ) ? 1 : NB_DIV; + nSubframes = NB_DIV; + move16(); + if ( EQ_16( st->core, TCX_20_CORE ) ) + { + nSubframes = 1; + move16(); + } + idxIndices = 0; + move16(); FOR( k = 0; k < nSubframes; ++k ) { - const Word16 is_side = ch == 1 && sns_stereo_mode[k] == SNS_STEREO_MODE_MS; + const Word16 is_side = EQ_16( ch, 1 ) && EQ_16( sns_stereo_mode[k], SNS_STEREO_MODE_MS ); + + const Word16 *const *cdbks_fx = EQ_16( nSubframes, 1 ) ? ivas_sns_cdbks_tcx20_fx : ivas_sns_cdbks_tcx10_fx; - const Word16 *const *cdbks_fx = ( nSubframes == 1 ) ? ivas_sns_cdbks_tcx20_fx : ivas_sns_cdbks_tcx10_fx; + Word16 nStages = SNS_MSVQ_NSTAGES_TCX10; + move16(); + + if ( EQ_16( nSubframes, 1 ) ) + { + nStages = SNS_MSVQ_NSTAGES_TCX20; + move16(); + } - Word16 nStages = ( ( nSubframes == 1 ) ? SNS_MSVQ_NSTAGES_TCX20 : SNS_MSVQ_NSTAGES_TCX10 ); Word32 *snsQ_fx = snsQ_out_fx[ch][k]; IF( is_side ) { - const Word16 *const *side_cdbks_fx = ( st->core == TCX_20_CORE ) ? ivas_sns_cdbks_side_tcx20_fx : ivas_sns_cdbks_side_tcx10_fx; + const Word16 *const *side_cdbks_fx = EQ_16( st->core, TCX_20_CORE ) ? ivas_sns_cdbks_side_tcx20_fx : ivas_sns_cdbks_side_tcx10_fx; IF( zero_side_flag[k] ) { @@ -319,19 +378,26 @@ void dequantize_sns_fx( } nStages = SNS_MSVQ_NSTAGES_SIDE; - msvq_dec_fx( side_cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][idxIndices + SNS_STEREO_MODE_OFFSET_INDICES], 0, NULL, snsQ_fx, NULL, 15 ); // always 15 + move16(); + msvq_dec_fx( side_cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][add( idxIndices, SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 15 ); // always 15 } ELSE { - msvq_dec_fx( cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][idxIndices + SNS_STEREO_MODE_OFFSET_INDICES], 0, NULL, snsQ_fx, NULL, 12 ); + msvq_dec_fx( cdbks_fx, NULL, NULL, nStages, M, M, &indices[ch][add( idxIndices, SNS_STEREO_MODE_OFFSET_INDICES )], 0, NULL, snsQ_fx, NULL, 12 ); } - idxIndices += nStages; + idxIndices = add( idxIndices, nStages ); } } - IF( sns_stereo_mode[0] == SNS_STEREO_MODE_MS || sns_stereo_mode[1] == SNS_STEREO_MODE_MS ) + IF( EQ_16( sns_stereo_mode[0], SNS_STEREO_MODE_MS ) || EQ_16( sns_stereo_mode[1], SNS_STEREO_MODE_MS ) ) { - nSubframes = ( sts[0]->core == TCX_20_CORE ) ? 1 : NB_DIV; + nSubframes = NB_DIV; + move16(); + if ( EQ_16( sts[0]->core, TCX_20_CORE ) ) + { + nSubframes = 1; + move16(); + } FOR( k = 0; k < nSubframes; ++k ) { IF( sns_stereo_mode[k] == SNS_STEREO_MODE_MS ) diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 7ca71ffb2..62b92ebb7 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -294,7 +294,7 @@ void IVAS_DEC_Close( IF( ( *phIvasDec )->st_ivas ) { - ivas_destroy_dec( ( *phIvasDec )->st_ivas ); + ivas_destroy_dec_fx( ( *phIvasDec )->st_ivas ); ( *phIvasDec )->st_ivas = NULL; } diff --git a/lib_rend/ivas_objectRenderer_sfx.c b/lib_rend/ivas_objectRenderer_sfx.c index 8289708df..a09455953 100644 --- a/lib_rend/ivas_objectRenderer_sfx.c +++ b/lib_rend/ivas_objectRenderer_sfx.c @@ -51,8 +51,9 @@ * Local function prototypes *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void sincResample( const float *input, float *output, const int16_t length_in, const int16_t length_out ); -#ifdef IVAS_FLOAT_FIXED +#else static void sincResample_fx( const Word32 *input_fx, Word32 *output_fx, const Word16 length_in, const Word16 length_out ); #endif @@ -61,6 +62,7 @@ static void sincResample_fx( const Word32 *input_fx, Word32 *output_fx, const Wo * * Apply ITD by delaying late channel *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void TDREND_Apply_ITD( float *input, /* i : Input subframe to be time adjusted */ float *out_left, /* o : Output left channel with ITD applied */ @@ -161,7 +163,7 @@ void TDREND_Apply_ITD( return; } -#ifdef IVAS_FLOAT_FIXED +#else void TDREND_Apply_ITD_fx( Word32 *input_fx, /* i : Input subframe to be time adjusted Qx */ Word32 *out_left_fx, /* o : Output left channel with ITD applied Qx */ @@ -283,6 +285,7 @@ void TDREND_Apply_ITD_fx( * The sinc resampling reads SFX_SPAT_BIN_SINC_M (5) samples outside of * the target frame. *---------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void sincResample( const float *input, /*i : Input signal */ float *output, /*o : Output signal */ @@ -347,7 +350,7 @@ static void sincResample( return; } -#ifdef IVAS_FLOAT_FIXED +#else static void sincResample_fx( const Word32 *input_fx, /*i : Input signal Qx */ Word32 *output_fx, /*o : Output signal Qx */ diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 0df7c7b7b..0334bdc33 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -2274,9 +2274,15 @@ ivas_error ivas_headTrack_open( ); #endif +#ifndef IVAS_FLOAT_FIXED void ivas_headTrack_close( HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ ); +#else +void ivas_headTrack_close_fx( + HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ +); +#endif void Euler2Quat( const float yaw, /* i : yaw (x) */ @@ -2471,21 +2477,29 @@ ivas_error ivas_external_orientation_open( EXTERNAL_ORIENTATION_HANDLE *hExtOrientationData, /* o : external orientation handle */ const int16_t num_subframes /* i : number of subframes */ ); - +#ifndef IVAS_FLOAT_FIXED void ivas_external_orientation_close( EXTERNAL_ORIENTATION_HANDLE *hExtOrientationData /* i/o: external orientation handle */ ); - +#else +void ivas_external_orientation_close_fx( + EXTERNAL_ORIENTATION_HANDLE *hExtOrientationData /* i/o: external orientation handle */ +); +#endif ivas_error ivas_combined_orientation_open( COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData, /* o : combined orientation handle */ const int32_t fs, /* i : sampling rate */ const int16_t num_subframes /* i : number of subframes */ ); - +#ifndef IVAS_FLOAT_FIXED void ivas_combined_orientation_close( COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData /* i/o: combined orientation handle */ ); - +#else +void ivas_combined_orientation_close_fx( + COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData /* i/o: combined orientation handle */ +); +#endif ivas_error combine_external_and_head_orientations_dec( HEAD_TRACK_DATA_HANDLE hHeadTrackData, /* i : head track handle */ EXTERNAL_ORIENTATION_HANDLE hExtOrientationData, /* i : external orientation handle */ diff --git a/lib_rend/ivas_rom_binaural_crend_head.c b/lib_rend/ivas_rom_binaural_crend_head.c index efb3c568c..a34162e49 100644 --- a/lib_rend/ivas_rom_binaural_crend_head.c +++ b/lib_rend/ivas_rom_binaural_crend_head.c @@ -53,9 +53,9 @@ /********************** CRendBin_Combined_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_HRIR_latency_s = 0.000020834f; - -#ifdef IVAS_FLOAT_FIXED +#else const Word32 CRendBin_Combined_HRIR_latency_s_fx = 44741;/*Q-31*/ #endif // IVAS_FLOAT_FIXED /* Sample Rate = 48000 */ @@ -65,11 +65,13 @@ const uint16_t CRendBin_Combined_HRIR_num_iterations_48kHz[15][BINAURAL_CHANNELS const uint16_t CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[15][BINAURAL_CHANNELS][1]={{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}}}; const uint16_t CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz[15]={0, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[15]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}; #endif const uint16_t *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_HRIR_coeff_re_48kHz[15][BINAURAL_CHANNELS][240]={ { {1.101488f, 1.121686f, 1.165024f, 1.224338f, 1.257855f, 1.220486f, 1.149240f, 1.140890f, 1.185728f, 1.128055f, 0.902355f, 0.707875f, 0.788108f, 1.099541f, 1.375119f, 1.484928f, 1.549978f, 1.695559f, 1.876431f, 1.995635f, 2.041427f, 2.028898f, 1.921455f, 1.700966f, 1.448293f, 1.277519f, 1.224020f, 1.244684f, 1.297952f, 1.382592f, 1.515360f, 1.701068f, 1.918656f, 2.122718f, 2.265994f, 2.329628f, 2.329558f, 2.294332f, 2.241762f, 2.173492f, 2.084598f, 1.978110f, 1.871591f, 1.786593f, 1.731800f, 1.700143f, 1.679095f, 1.656899f, 1.622424f, 1.569381f, 1.502234f, 1.432448f, 1.368773f, 1.314020f, 1.268340f, 1.231321f, 1.202278f, 1.180534f, 1.163747f, 1.146145f, 1.121645f, 1.087903f, 1.043613f, 0.983612f, 0.901864f, 0.798972f, 0.683390f, 0.566766f, 0.461005f, 0.376682f, 0.319308f, 0.287365f, 0.275856f, 0.280196f, 0.295624f, 0.315889f, 0.334947f, 0.349113f, 0.357350f, 0.360958f, 0.362742f, 0.364984f, 0.368682f, 0.375343f, 0.387569f, 0.406700f, 0.431922f, 0.462716f, 0.499762f, 0.542220f, 0.586337f, 0.627805f, 0.663761f, 0.692071f, 0.710593f, 0.717887f, @@ -316,7 +318,7 @@ const float CRendBin_Combined_HRIR_coeff_im_48kHz[15][BINAURAL_CHANNELS][240]={ }; const float *CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -327,11 +329,13 @@ const uint16_t CRendBin_Combined_HRIR_num_iterations_32kHz[15][BINAURAL_CHANNELS const uint16_t CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[15][BINAURAL_CHANNELS][1]={{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}}}; const uint16_t CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz[15]={0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[15]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}; #endif const uint16_t *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_HRIR_coeff_re_32kHz[15][BINAURAL_CHANNELS][160]={ { {1.274160f, 1.294020f, 1.337410f, 1.397007f, 1.430345f, 1.392644f, 1.321540f, 1.313359f, 1.357865f, 1.299918f, 1.074412f, 0.879944f, 0.959736f, 1.270988f, 1.546758f, 1.656396f, 1.720956f, 1.866458f, 2.047459f, 2.166309f, 2.211621f, 2.199100f, 2.091661f, 1.870665f, 1.617573f, 1.446851f, 1.393188f, 1.413236f, 1.466179f, 1.550859f, 1.683267f, 1.868310f, 2.085674f, 2.289697f, 2.432421f, 2.495403f, 2.495189f, 2.459782f, 2.406497f, 2.337636f, 2.248632f, 2.141773f, 2.034425f, 1.948929f, 1.893998f, 1.861756f, 1.839825f, 1.817228f, 1.782513f, 1.728672f, 1.660650f, 1.590534f, 1.526449f, 1.470717f, 1.424223f, 1.386891f, 1.357216f, 1.334362f, 1.316849f, 1.298879f, 1.273497f, 1.238579f, 1.193651f, 1.133144f, 1.050266f, 0.946198f, 0.830030f, 0.712686f, 0.605579f, 0.520129f, 0.462158f, 0.429220f, 0.416204f, 0.419491f, 0.434223f, 0.453184f, 0.470641f, 0.483821f, 0.491166f, 0.493159f, 0.493315f, 0.494589f, 0.497104f, 0.501870f, 0.512491f, 0.530588f, 0.554259f, 0.582935f, 0.618415f, 0.659661f, 0.701812f, 0.741007f, 0.775413f, 0.802205f, 0.818331f, 0.823262f, @@ -518,7 +522,7 @@ const float CRendBin_Combined_HRIR_coeff_im_32kHz[15][BINAURAL_CHANNELS][160]={ }; const float *CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -529,11 +533,13 @@ const uint16_t CRendBin_Combined_HRIR_num_iterations_16kHz[15][BINAURAL_CHANNELS const uint16_t CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[15][BINAURAL_CHANNELS][1]={{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}}}; const uint16_t CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz[15]={0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[15]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}; #endif const uint16_t *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_HRIR_coeff_re_16kHz[15][BINAURAL_CHANNELS][80]={ { { 1.239183f, 1.256884f, 1.300573f, 1.362041f, 1.394364f, 1.354510f, 1.284249f, 1.277360f, 1.319933f, 1.260104f, 1.035831f, 0.841818f, 0.918943f, 1.228789f, 1.505938f, 1.615001f, 1.676409f, 1.821102f, 2.003314f, 2.120456f, 2.162423f, 2.149697f, 2.042953f, 1.819108f, 1.562774f, 1.392343f, 1.338502f, 1.354661f, 1.404734f, 1.489962f, 1.620994f, 1.801308f, 2.016368f, 2.220843f, 2.360726f, 2.418417f, 2.416549f, 2.381039f, 2.323273f, 2.248889f, 2.158818f, 2.050759f, 1.937222f, 1.846306f, 1.790643f, 1.755504f, 1.725726f, 1.698099f, 1.662521f, 1.603450f, 1.526080f, 1.451493f, 1.385684f, 1.321724f, 1.264611f, 1.223329f, 1.190008f, 1.155210f, 1.126054f, 1.104272f, 1.071790f, 1.020334f, 0.962879f, 0.897728f, 0.801926f, 0.675382f, 0.545582f, 0.420598f, 0.290433f, 0.173783f, 0.099765f, 0.050651f, -0.006501f, -0.051832f, -0.062025f, -0.095855f, -0.220501f, -0.379318f, -0.456547f, -0.451019f}, @@ -660,7 +666,7 @@ const float CRendBin_Combined_HRIR_coeff_im_16kHz[15][BINAURAL_CHANNELS][80]={ }; const float *CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -669,8 +675,9 @@ const Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS /********************** CRendBin_FOA_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_latency_s = 0.000020834f; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 CRendBin_FOA_HRIR_latency_s_fx = 44741; #endif // IVAS_FLOAT_FIXED @@ -681,11 +688,13 @@ const uint16_t CRendBin_FOA_HRIR_num_iterations_48kHz[4][BINAURAL_CHANNELS]={{1, const uint16_t CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[4][BINAURAL_CHANNELS][1]={{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}}}; const uint16_t CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz[4]={0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[4]={0, 0, 0, 0}; #endif const uint16_t *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_coeff_re_48kHz[4][BINAURAL_CHANNELS][240]={ { {0.966218f, 0.733332f, 0.371154f, 0.013886f, -0.255271f, -0.429740f, -0.543550f, -0.621345f, -0.659916f, -0.644001f, -0.568080f, -0.442479f, -0.285885f, -0.117060f, 0.048289f, 0.198155f, 0.325513f, 0.429363f, 0.513050f, 0.580002f, 0.630568f, 0.663334f, 0.679201f, 0.682684f, 0.678369f, 0.667227f, 0.647704f, 0.619700f, 0.585896f, 0.549425f, 0.511893f, 0.474018f, 0.436790f, 0.401079f, 0.366792f, 0.333238f, 0.300207f, 0.268253f, 0.237980f, 0.209327f, 0.181631f, 0.154220f, 0.126862f, 0.099653f, 0.072728f, 0.046213f, 0.020311f, -0.004833f, -0.029303f, -0.053269f, -0.076722f, -0.099506f, -0.121536f, -0.142793f, -0.163190f, -0.182595f, -0.200971f, -0.218400f, -0.234976f, -0.250747f, -0.265719f, -0.279920f, -0.293435f, -0.306316f, -0.318471f, -0.329791f, -0.340363f, -0.350414f, -0.360064f, -0.369343f, -0.378409f, -0.387487f, -0.396622f, -0.405768f, -0.415062f, -0.424742f, -0.434871f, -0.445428f, -0.456546f, -0.468369f, -0.480767f, -0.493503f, -0.506517f, -0.519763f, -0.532917f, -0.545542f, -0.557444f, -0.568682f, -0.579373f, -0.589605f, -0.599351f, -0.608366f, -0.616332f, -0.623173f, -0.629056f, -0.634137f, @@ -756,7 +765,7 @@ const float CRendBin_FOA_HRIR_coeff_im_48kHz[4][BINAURAL_CHANNELS][240]={ }; const float *CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -767,11 +776,13 @@ const uint16_t CRendBin_FOA_HRIR_num_iterations_32kHz[4][BINAURAL_CHANNELS]={{1, const uint16_t CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[4][BINAURAL_CHANNELS][1]={{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}}}; const uint16_t CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz[4]={0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[4]={0, 0, 0, 0}; #endif const uint16_t *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_coeff_re_32kHz[4][BINAURAL_CHANNELS][160]={ { {1.009979f, 0.777112f, 0.414923f, 0.057622f, -0.211538f, -0.386004f, -0.499848f, -0.577684f, -0.616265f, -0.600367f, -0.524501f, -0.398947f, -0.242372f, -0.073587f, 0.091690f, 0.241505f, 0.368831f, 0.472616f, 0.556219f, 0.623114f, 0.673631f, 0.706309f, 0.722082f, 0.725502f, 0.721116f, 0.709865f, 0.690241f, 0.662164f, 0.628264f, 0.591665f, 0.554026f, 0.516064f, 0.478714f, 0.442859f, 0.408459f, 0.374798f, 0.341619f, 0.309511f, 0.279115f, 0.250331f, 0.222462f, 0.194888f, 0.167394f, 0.140026f, 0.112906f, 0.086220f, 0.060166f, 0.034831f, 0.010148f, -0.013999f, -0.037628f, -0.060633f, -0.082892f, -0.104342f, -0.124944f, -0.144600f, -0.163218f, -0.180856f, -0.197673f, -0.213722f, -0.228947f, -0.243382f, -0.257175f, -0.270358f, -0.282781f, -0.294366f, -0.305254f, -0.315630f, -0.325566f, -0.335147f, -0.344568f, -0.353990f, -0.363436f, -0.372929f, -0.382614f, -0.392659f, -0.403132f, -0.414084f, -0.425629f, -0.437840f, -0.450624f, -0.463808f, -0.477282f, -0.490945f, -0.504537f, -0.517665f, -0.530059f, -0.541752f, -0.552944f, -0.563732f, -0.574004f, -0.583524f, -0.592061f, -0.599512f, -0.605962f, -0.611610f, @@ -826,7 +837,7 @@ const float CRendBin_FOA_HRIR_coeff_im_32kHz[4][BINAURAL_CHANNELS][160]={ }; const float *CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -837,11 +848,13 @@ const uint16_t CRendBin_FOA_HRIR_num_iterations_16kHz[4][BINAURAL_CHANNELS]={{1, const uint16_t CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[4][BINAURAL_CHANNELS][1]={{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}}}; const uint16_t CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz[4]={0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[4]={0, 0, 0, 0}; #endif const uint16_t *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_FOA_HRIR_coeff_re_16kHz[4][BINAURAL_CHANNELS][80]={ { { 1.066299f, 0.831753f, 0.469820f, 0.113997f, -0.155945f, -0.332046f, -0.445167f, -0.521969f, -0.562027f, -0.547501f, -0.470580f, -0.344643f, -0.190080f, -0.022238f, 0.144217f, 0.293618f, 0.418613f, 0.521970f, 0.606614f, 0.672232f, 0.720345f, 0.753099f, 0.769493f, 0.770796f, 0.764174f, 0.753391f, 0.733696f, 0.702773f, 0.667010f, 0.631061f, 0.592423f, 0.551074f, 0.512366f, 0.477047f, 0.440550f, 0.403206f, 0.369206f, 0.337153f, 0.303479f, 0.270983f, 0.242735f, 0.214328f, 0.182386f, 0.151528f, 0.124233f, 0.095401f, 0.063829f, 0.035419f, 0.010359f, -0.017668f, -0.047701f, -0.073299f, -0.096723f, -0.124198f, -0.151868f, -0.173748f, -0.195138f, -0.221363f, -0.245696f, -0.264016f, -0.284769f, -0.310840f, -0.332497f, -0.348925f, -0.371386f, -0.398406f, -0.417735f, -0.434354f, -0.462032f, -0.492418f, -0.512100f, -0.536134f, -0.579084f, -0.619428f, -0.648156f, -0.709398f, -0.814740f, -0.869114f, -0.792023f, -0.672661f}, @@ -880,7 +893,7 @@ const float CRendBin_FOA_HRIR_coeff_im_16kHz[4][BINAURAL_CHANNELS][80]={ }; const float *CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -888,8 +901,9 @@ const Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NU /********************** CRendBin_HOA2_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_latency_s = 0.000020834f; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 CRendBin_HOA2_HRIR_latency_s_fx = 44741; #endif // IVAS_FLOAT_FIXED @@ -900,11 +914,13 @@ const uint16_t CRendBin_HOA2_HRIR_num_iterations_48kHz[9][BINAURAL_CHANNELS]={{1 const uint16_t CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[9][BINAURAL_CHANNELS][1]={{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}}}; const uint16_t CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz[9]={0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[9]={0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif const uint16_t *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_coeff_re_48kHz[9][BINAURAL_CHANNELS][240]={ { {0.955467f, 0.635681f, 0.166653f, -0.248686f, -0.508651f, -0.626077f, -0.650285f, -0.604530f, -0.488417f, -0.308510f, -0.090053f, 0.133390f, 0.331939f, 0.484574f, 0.581273f, 0.623235f, 0.619217f, 0.579562f, 0.512138f, 0.422298f, 0.315745f, 0.200824f, 0.086720f, -0.021278f, -0.123379f, -0.220908f, -0.311538f, -0.390400f, -0.454756f, -0.505495f, -0.544554f, -0.573087f, -0.592353f, -0.604514f, -0.611652f, -0.614839f, -0.614702f, -0.612258f, -0.608712f, -0.604725f, -0.600146f, -0.594359f, -0.586798f, -0.577264f, -0.565860f, -0.552745f, -0.538040f, -0.521885f, -0.504388f, -0.485535f, -0.465319f, -0.443966f, -0.421881f, -0.399382f, -0.376688f, -0.354132f, -0.332145f, -0.310934f, -0.290358f, -0.270218f, -0.250519f, -0.231307f, -0.212442f, -0.193768f, -0.175388f, -0.157519f, -0.140147f, -0.123115f, -0.106462f, -0.090326f, -0.074575f, -0.058912f, -0.043292f, -0.027843f, -0.012429f, 0.003258f, 0.019199f, 0.035158f, 0.051271f, 0.067966f, 0.085226f, 0.102477f, 0.119366f, 0.136149f, 0.153084f, 0.169846f, 0.185867f, 0.201051f, 0.215857f, 0.230656f, 0.245156f, 0.258620f, 0.270655f, 0.281594f, 0.291923f, 0.301545f, @@ -1055,7 +1071,7 @@ const float CRendBin_HOA2_HRIR_coeff_im_48kHz[9][BINAURAL_CHANNELS][240]={ }; const float *CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -1066,11 +1082,13 @@ const uint16_t CRendBin_HOA2_HRIR_num_iterations_32kHz[9][BINAURAL_CHANNELS]={{1 const uint16_t CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[9][BINAURAL_CHANNELS][1]={{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}}}; const uint16_t CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz[9]={0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[9]={0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif const uint16_t *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_coeff_re_32kHz[9][BINAURAL_CHANNELS][160]={ { {0.897602f, 0.577826f, 0.108806f, -0.306523f, -0.566468f, -0.683867f, -0.708050f, -0.662267f, -0.546112f, -0.366162f, -0.147663f, 0.075830f, 0.274439f, 0.427135f, 0.523893f, 0.565927f, 0.561989f, 0.522411f, 0.455067f, 0.365320f, 0.258865f, 0.144039f, 0.030037f, -0.077847f, -0.179832f, -0.277247f, -0.367752f, -0.446478f, -0.510700f, -0.561304f, -0.600215f, -0.628591f, -0.647703f, -0.659706f, -0.666671f, -0.669681f, -0.669369f, -0.666740f, -0.662997f, -0.658812f, -0.654035f, -0.648036f, -0.640253f, -0.630498f, -0.618870f, -0.605516f, -0.590564f, -0.574163f, -0.556413f, -0.537291f, -0.516802f, -0.495178f, -0.472808f, -0.450009f, -0.427015f, -0.404157f, -0.381849f, -0.360307f, -0.339403f, -0.318926f, -0.298870f, -0.279294f, -0.260068f, -0.241018f, -0.222243f, -0.203976f, -0.186205f, -0.168754f, -0.151665f, -0.135094f, -0.118902f, -0.102773f, -0.086674f, -0.070750f, -0.054844f, -0.038640f, -0.022176f, -0.005693f, 0.010967f, 0.028233f, 0.046067f, 0.063897f, 0.081395f, 0.098808f, 0.116372f, 0.133779f, 0.150477f, 0.166354f, 0.181854f, 0.197372f, 0.212626f, 0.226853f, 0.239657f, 0.251401f, 0.262567f, 0.273031f, @@ -1185,7 +1203,7 @@ const float CRendBin_HOA2_HRIR_coeff_im_32kHz[9][BINAURAL_CHANNELS][160]={ }; const float *CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -1196,11 +1214,13 @@ const uint16_t CRendBin_HOA2_HRIR_num_iterations_16kHz[9][BINAURAL_CHANNELS]={{1 const uint16_t CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[9][BINAURAL_CHANNELS][1]={{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}},{{80},{80}}}; const uint16_t CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz[9]={0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[9]={0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif const uint16_t *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA2_HRIR_coeff_re_16kHz[9][BINAURAL_CHANNELS][80]={ { { 0.854113f, 0.536451f, 0.067092f, -0.350133f, -0.609131f, -0.724504f, -0.749647f, -0.705240f, -0.587299f, -0.405686f, -0.188603f, 0.034290f, 0.235326f, 0.389114f, 0.484257f, 0.526650f, 0.525509f, 0.486339f, 0.417501f, 0.329156f, 0.225561f, 0.110464f, -0.004565f, -0.110029f, -0.209397f, -0.307633f, -0.398358f, -0.473786f, -0.535896f, -0.587622f, -0.625653f, -0.650087f, -0.667773f, -0.680841f, -0.685616f, -0.684346f, -0.683354f, -0.681293f, -0.673940f, -0.665480f, -0.660678f, -0.654254f, -0.641454f, -0.627762f, -0.616498f, -0.601208f, -0.579959f, -0.560224f, -0.542768f, -0.519685f, -0.491848f, -0.467631f, -0.444806f, -0.415518f, -0.384419f, -0.359637f, -0.335182f, -0.304116f, -0.274642f, -0.252517f, -0.227297f, -0.194558f, -0.166484f, -0.145123f, -0.116152f, -0.080136f, -0.053083f, -0.030604f, 0.005387f, 0.046361f, 0.073460f, 0.102702f, 0.155814f, 0.209408f, 0.244378f, 0.309617f, 0.442675f, 0.565949f, 0.579052f, 0.523768f}, @@ -1279,7 +1299,7 @@ const float CRendBin_HOA2_HRIR_coeff_im_16kHz[9][BINAURAL_CHANNELS][80]={ }; const float *CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -1287,9 +1307,9 @@ const Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={N /********************** CRendBin_HOA3_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA3_HRIR_latency_s = 0.000020834f; - -#ifdef IVAS_FLOAT_FIXED +#else const Word32 CRendBin_HOA3_HRIR_latency_s_fx = 44741;/*Q-31*/ #endif /* Sample Rate = 48000 */ @@ -1299,11 +1319,13 @@ const uint16_t CRendBin_HOA3_HRIR_num_iterations_48kHz[16][BINAURAL_CHANNELS]={{ const uint16_t CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[16][BINAURAL_CHANNELS][1]={{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}},{{240},{240}}}; const uint16_t CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz[16]={0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[16]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif const uint16_t *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA3_HRIR_coeff_re_48kHz[16][BINAURAL_CHANNELS][240]={ { {0.975460f, 0.823508f, 0.578722f, 0.311394f, 0.071393f, -0.117298f, -0.265803f, -0.406443f, -0.536876f, -0.603591f, -0.568995f, -0.446021f, -0.232011f, 0.098533f, 0.446049f, 0.539124f, 0.219489f, -0.255318f, -0.399037f, -0.041354f, 0.472264f, 0.693368f, 0.533266f, 0.219305f, -0.059008f, -0.291241f, -0.505715f, -0.670083f, -0.755827f, -0.790827f, -0.808813f, -0.807132f, -0.777516f, -0.733727f, -0.690346f, -0.645074f, -0.594162f, -0.543258f, -0.496359f, -0.450603f, -0.404959f, -0.361817f, -0.320310f, -0.277796f, -0.235759f, -0.196817f, -0.159540f, -0.122007f, -0.085990f, -0.053099f, -0.021484f, 0.010278f, 0.040672f, 0.068775f, 0.095789f, 0.121856f, 0.145524f, 0.166807f, 0.187076f, 0.206251f, 0.223418f, 0.239269f, 0.254992f, 0.270072f, 0.283633f, 0.296367f, 0.309129f, 0.321380f, 0.332609f, 0.343518f, 0.354653f, 0.365577f, 0.376080f, 0.386687f, 0.397603f, 0.408487f, 0.419268f, 0.430118f, 0.440990f, 0.451887f, 0.462914f, 0.473622f, 0.483318f, 0.492236f, 0.501131f, 0.509707f, 0.516930f, 0.522835f, 0.528471f, 0.534052f, 0.538627f, 0.541575f, 0.543261f, 0.544286f, 0.544970f, 0.545324f, @@ -1566,7 +1588,7 @@ const float CRendBin_HOA3_HRIR_coeff_im_48kHz[16][BINAURAL_CHANNELS][240]={ }; const float *CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -1577,11 +1599,13 @@ const uint16_t CRendBin_HOA3_HRIR_num_iterations_32kHz[16][BINAURAL_CHANNELS]={{ const uint16_t CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS] = {0, 0}; const uint16_t CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[16][BINAURAL_CHANNELS][1]={{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}},{{160},{160}}}; const uint16_t CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz = 0; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz[16]={0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f}; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[16]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif const uint16_t *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA3_HRIR_coeff_re_32kHz[16][BINAURAL_CHANNELS][160]={ { {0.931532f, 0.779586f, 0.534806f, 0.267486f, 0.027500f, -0.161171f, -0.309658f, -0.450275f, -0.580679f, -0.647362f, -0.612734f, -0.489723f, -0.275668f, 0.054919f, 0.402480f, 0.495609f, 0.176032f, -0.298719f, -0.442377f, -0.084625f, 0.429064f, 0.650237f, 0.490213f, 0.176336f, -0.101893f, -0.334041f, -0.548421f, -0.712689f, -0.798336f, -0.833235f, -0.851109f, -0.849315f, -0.819587f, -0.775679f, -0.732168f, -0.686769f, -0.635729f, -0.584686f, -0.537641f, -0.491741f, -0.445951f, -0.402650f, -0.360980f, -0.318308f, -0.276103f, -0.236981f, -0.199525f, -0.161814f, -0.125607f, -0.092516f, -0.060704f, -0.028744f, 0.001865f, 0.030189f, 0.057418f, 0.083709f, 0.107616f, 0.129141f, 0.149647f, 0.169072f, 0.186505f, 0.202619f, 0.218604f, 0.233964f, 0.247817f, 0.260837f, 0.273890f, 0.286455f, 0.298003f, 0.309223f, 0.320684f, 0.331955f, 0.342805f, 0.353754f, 0.365034f, 0.376301f, 0.387457f, 0.398686f, 0.409965f, 0.421281f, 0.432717f, 0.443847f, 0.453997f, 0.463372f, 0.472714f, 0.481764f, 0.489489f, 0.495891f, 0.502022f, 0.508134f, 0.513263f, 0.516755f, 0.518993f, 0.520614f, 0.521907f, 0.522857f, @@ -1780,7 +1804,7 @@ const float CRendBin_HOA3_HRIR_coeff_im_32kHz[16][BINAURAL_CHANNELS][160]={ }; const float *CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -1796,6 +1820,7 @@ const float CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz[16]={0.000000f, 0.000000 const Word16 CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[16]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif const uint16_t *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_HOA3_HRIR_coeff_re_16kHz[16][BINAURAL_CHANNELS][80]={ { { 0.883857f, 0.733415f, 0.488407f, 0.219765f, -0.019522f, -0.206727f, -0.355857f, -0.497398f, -0.626479f, -0.691928f, -0.658239f, -0.535571f, -0.319712f, 0.011730f, 0.358242f, 0.451741f, 0.134258f, -0.340096f, -0.484683f, -0.125786f, 0.390069f, 0.611189f, 0.450608f, 0.138633f, -0.137573f, -0.370128f, -0.584446f, -0.746152f, -0.830104f, -0.865577f, -0.882556f, -0.877705f, -0.846732f, -0.803300f, -0.757904f, -0.709171f, -0.657369f, -0.606374f, -0.556373f, -0.507104f, -0.460955f, -0.416905f, -0.371212f, -0.325363f, -0.282989f, -0.241932f, -0.199475f, -0.158957f, -0.122405f, -0.085805f, -0.048176f, -0.013848f, 0.017815f, 0.051603f, 0.085261f, 0.113579f, 0.139998f, 0.169326f, 0.196673f, 0.218159f, 0.240616f, 0.267320f, 0.290455f, 0.308757f, 0.331756f, 0.358830f, 0.379533f, 0.397779f, 0.425526f, 0.455662f, 0.476389f, 0.501029f, 0.542486f, 0.581357f, 0.609875f, 0.668286f, 0.765750f, 0.813077f, 0.736556f, 0.621909f}, @@ -1930,7 +1955,7 @@ const float CRendBin_HOA3_HRIR_coeff_im_16kHz[16][BINAURAL_CHANNELS][80]={ }; const float *CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; const float *CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]={NULL,NULL}; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; const Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={NULL,NULL}; #endif @@ -1938,9 +1963,9 @@ const Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]={N /********************** CRendBin_Combined_BRIR **********************/ +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_BRIR_latency_s = 0.000145834f; - -#ifdef IVAS_FLOAT_FIXED +#else const Word32 CRendBin_Combined_BRIR_latency_s_fx = 313176;/*Q-31*/ #endif /* Sample Rate = 48000 */ @@ -1955,6 +1980,7 @@ const float CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz[15]={0.224183f, 0.22 const Word16 CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[15]={7346, 7453, 7924, 6788, 7146, 7305, 7607, 8133, 8167, 8571, 8069, 9147, 9361, 8602, 8907,}; #endif const uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS][40]={{47, 47, 47, 47, 47, 47, 51, 51, 58, 58, 58, 65, 65, 65, 65, 65, 72, 72, 72, 74, 74, 77, 77, 79, 81, 81, 81, 81, 87, 87, 87, 87, 87, 87, 91, 91, 93, 93, 93, 98},{47, 47, 47, 47, 47, 47, 51, 51, 58, 58, 58, 65, 65, 65, 65, 65, 72, 72, 72, 74, 74, 77, 77, 79, 81, 81, 81, 81, 87, 87, 87, 87, 87, 87, 91, 91, 93, 93, 93, 98}}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_BRIR_coeff_re_48kHz[15][BINAURAL_CHANNELS][2955]={ { {-0.009093f, 0.009357f, -0.003453f, 0.000012f, 0.008747f, -0.004985f, 0.003413f, -0.000634f, 0.001224f, -0.005937f, -0.012436f, -0.002558f, 0.004885f, -0.003188f, 0.002971f, 0.004317f, 0.003658f, -0.002726f, 0.002070f, -0.007687f, -0.001416f, 0.001935f, 0.003177f, -0.000251f, -0.000183f, 0.000966f, 0.001890f, -0.006432f, -0.005361f, 0.002269f, 0.004446f, -0.002213f, 0.004654f, 0.008920f, -0.011982f, 0.001718f, -0.005741f, -0.003864f, 0.002657f, -0.001469f, 0.007339f, -0.002261f, 0.006608f, 0.003502f, 0.001066f, -0.000452f, 0.003522f, 0.000236f, -0.000743f, -0.003707f, 0.010716f, -0.007427f, -0.002282f, 0.003802f, 0.004147f, -0.000158f, -0.003653f, 0.002094f, -0.004039f, 0.004196f, 0.000776f, 0.001549f, -0.000111f, -0.001391f, -0.001353f, 0.005598f, -0.014358f, 0.003399f, -0.001873f, -0.008279f, -0.001439f, 0.007045f, 0.003361f, 0.004391f, -0.006305f, 0.005087f, -0.002217f, 0.003215f, 0.001901f, 0.002512f, -0.002684f, 0.001092f, 0.003738f, -0.002456f, -0.005636f, 0.002331f, -0.005235f, 0.001052f, 0.003778f, 0.000046f, -0.001918f, -0.002121f, 0.000983f, 0.002093f, -0.000885f, 0.002506f, @@ -3981,7 +4007,7 @@ const float CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS][288 -0.000127f, 0.000656f, 0.000958f, -0.021049f, -0.074011f, -0.030558f, -0.060400f, -0.013558f, -0.021114f, -0.008540f, 0.005511f, -0.019813f, -0.023982f, -0.038366f, -0.030493f, 0.027259f, -0.004844f, -0.024409f, -0.025928f, 0.005871f, -0.034505f, -0.048697f, 0.008047f, -0.011337f, -0.010427f, -0.010467f, 0.009378f, -0.029024f, 0.030558f, -0.017759f, 0.020760f, -0.014447f, -0.013858f, 0.000338f, 0.016772f, -0.023665f, -0.022591f, 0.012137f, -0.004260f, 0.033434f, -0.014631f, 0.019165f, 0.028836f, 0.013706f, -0.010477f, -0.004783f, -0.002989f, 0.023649f, -0.008272f, 0.015882f, 0.031926f, -0.026792f, -0.046736f, -0.018402f, 0.015888f, 0.019470f, -0.022037f, 0.036317f, -0.011659f, -0.013109f, -0.004357f, -0.003960f, -0.011213f, -0.029378f, -0.012396f, -0.030354f, -0.029055f, -0.018001f, 0.021498f, 0.005089f, -0.005130f, 0.001988f, 0.033225f, 0.031204f, 0.002242f, -0.014392f, 0.005985f, -0.003233f, 0.013707f, 0.004324f, -0.005912f, -0.013698f, -0.001190f, -0.002712f, -0.021764f, -0.005600f, 0.008350f, 0.022686f, -0.010079f, 0.000076f, 0.008688f, -0.012663f, -0.000348f, -0.000824f, 0.000437f, -0.006566f, 0.008540f, 0.000569f, 0.002267f, -0.000988f, 0.001342f} }; - +#endif /* Sample Rate = 32000 */ const int16_t CRendBin_Combined_BRIR_max_num_iterations_32kHz = 22; @@ -3994,6 +4020,7 @@ const float CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz[15]={0.224190f, 0.22 const Word16 CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[15]={7346, 7452, 7924, 6787, 7147, 7305, 7606, 8132, 8167, 8571, 8071, 9147, 9364, 8602, 8907,}; #endif const uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS][40]={{47, 47, 47, 47, 47, 47, 50, 50, 56, 56, 56, 63, 63, 63, 63, 63, 72, 72, 72, 74, 74, 77, 77, 79, 81, 81, 81, 81, 87, 87, 87, 87, 87, 87, 93, 93, 93, 93, 93, 97},{47, 47, 47, 47, 47, 47, 50, 50, 56, 56, 56, 63, 63, 63, 63, 63, 72, 72, 72, 74, 74, 77, 77, 79, 81, 81, 81, 81, 87, 87, 87, 87, 87, 87, 93, 93, 93, 93, 93, 97}}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_BRIR_coeff_re_32kHz[15][BINAURAL_CHANNELS][2819]={ { {-0.009097f, 0.009352f, -0.003456f, 0.000006f, 0.008745f, -0.004992f, 0.003412f, -0.000642f, 0.001223f, -0.005946f, -0.012435f, -0.002568f, 0.004887f, -0.003199f, 0.002973f, 0.004305f, 0.003661f, -0.002738f, 0.002074f, -0.007701f, -0.001411f, 0.001920f, 0.003183f, -0.000267f, -0.000175f, 0.000950f, 0.001899f, -0.006450f, -0.005352f, 0.002251f, 0.004456f, -0.002233f, 0.004665f, 0.008899f, -0.011970f, 0.001696f, -0.005728f, -0.003886f, 0.002671f, -0.001493f, 0.007354f, -0.002285f, 0.006623f, 0.003476f, 0.001083f, -0.000478f, 0.003540f, 0.000208f, -0.000724f, -0.003736f, 0.010735f, -0.007457f, -0.002261f, 0.003771f, 0.004169f, -0.000190f, -0.003631f, 0.002061f, -0.004016f, 0.004162f, 0.000801f, 0.001514f, -0.000085f, -0.001427f, -0.001326f, 0.005561f, -0.014330f, 0.003361f, -0.001844f, -0.008319f, -0.001409f, 0.007005f, 0.003391f, 0.004349f, -0.006273f, 0.005044f, -0.002184f, 0.003171f, 0.001934f, 0.002467f, -0.002649f, 0.001045f, 0.003774f, -0.002504f, -0.005599f, 0.002282f, -0.005197f, 0.001002f, 0.003817f, -0.000006f, -0.001878f, -0.002174f, 0.001025f, 0.002039f, -0.000843f, 0.002450f, @@ -5944,7 +5971,7 @@ const float CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS][287 0.031458f, -0.028595f, 0.018366f, 0.005588f, 0.025444f, 0.023474f, 0.015827f, 0.002536f, -0.016093f, -0.013878f, 0.033029f, -0.014058f, -0.001464f, 0.008051f, 0.028131f, 0.040762f, -0.001287f, 0.027841f, -0.022859f, -0.023842f, 0.002646f, -0.008821f, 0.013114f, 0.008322f, -0.020389f, 0.002753f, 0.012887f, 0.033517f, 0.011396f, 0.013723f, 0.012570f, 0.014979f, 0.003823f, -0.001202f, 0.021244f, 0.003721f, 0.016982f, 0.027236f, 0.005652f, -0.011237f, -0.009558f, 0.024547f, 0.006403f, 0.050382f, 0.011733f, 0.019842f, -0.020594f, -0.032353f, -0.003144f, -0.037770f, -0.024221f, -0.008633f, -0.012941f, 0.001391f, -0.001955f, 0.000276f, 0.000488f, -0.028253f, -0.023404f, -0.012371f, -0.024166f, 0.008796f, 0.009562f, -0.007331f, -0.001898f, -0.022425f, -0.003544f, 0.006580f, -0.006407f, -0.001948f, 0.002266f, -0.014163f, 0.005888f, -0.004370f, 0.001670f, 0.002484f, 0.000065f, 0.000944f, 0.003053f, -0.003401f, 0.000513f, 0.003267f, -0.000142f, 0.000763f, 0.000945f, -0.021037f, -0.074026f, -0.030548f, -0.060417f, -0.013550f, -0.021133f, -0.008534f, 0.005490f, -0.019809f, -0.024006f, -0.038365f, -0.030519f, 0.027258f, -0.004872f, -0.024412f, -0.025958f, 0.005865f, -0.034537f, -0.048705f, 0.008013f, -0.011347f, -0.010463f, -0.010480f, 0.009340f, -0.029039f, 0.030517f, -0.017776f, 0.020717f, -0.014466f, -0.013902f, 0.000316f, 0.016725f, -0.023690f, -0.022640f, 0.012110f, -0.004311f, 0.033404f, -0.014684f, 0.019133f, 0.028780f, 0.013672f, -0.010535f, -0.004820f, -0.003049f, 0.023610f, -0.008334f, 0.015840f, 0.031862f, -0.026837f, -0.046802f, -0.018449f, 0.015820f, 0.019420f, -0.022107f, 0.036264f, -0.011732f, -0.013165f, -0.004432f, -0.004019f, -0.011290f, -0.029439f, -0.012475f, -0.030418f, -0.029136f, -0.018067f, 0.021415f, 0.005020f, -0.005215f, 0.001915f, 0.033137f, 0.031128f, 0.002152f, -0.014470f, 0.005893f, -0.003315f, 0.013612f, 0.004239f, -0.006009f, -0.013786f, -0.001289f, -0.002803f, -0.021865f, -0.005694f, 0.008246f, 0.022588f, -0.010185f, -0.000025f, 0.008581f, -0.012767f, -0.000458f, -0.000932f, 0.000324f, -0.006676f, 0.008426f, 0.000455f, 0.002150f, -0.001106f} }; - +#endif /* Sample Rate = 16000 */ const int16_t CRendBin_Combined_BRIR_max_num_iterations_16kHz = 23; @@ -5957,6 +5984,7 @@ const float CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz[15]={0.223532f, 0.22 const Word16 CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[15]={7346, 7452, 7924, 6787, 7147, 7305, 7606, 8132, 8167, 8571, 8071, 9147, 9364, 8602, 8907}; #endif const uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS][40]={{46, 46, 46, 46, 46, 46, 46, 49, 49, 53, 53, 53, 55, 55, 61, 61, 61, 65, 67, 67, 67, 67, 67, 67, 69, 72, 72, 72, 73, 73, 75, 75, 75, 75, 75, 75, 75, 75, 75, 77},{46, 46, 46, 46, 46, 46, 46, 49, 49, 53, 53, 53, 55, 55, 61, 61, 61, 65, 67, 67, 67, 67, 67, 67, 69, 72, 72, 72, 73, 73, 75, 75, 75, 75, 75, 75, 75, 75, 75, 77}}; +#ifndef IVAS_FLOAT_FIXED const float CRendBin_Combined_BRIR_coeff_re_16kHz[15][BINAURAL_CHANNELS][1774]={ { {0.010832f, 0.002712f, -0.004173f, 0.000188f, -0.002118f, 0.002726f, 0.010885f, -0.000914f, -0.007116f, -0.010756f, 0.001174f, -0.008083f, -0.002332f, -0.002440f, 0.001864f, 0.005777f, -0.008313f, -0.004040f, -0.002553f, 0.000455f, -0.004910f, -0.008631f, -0.003371f, -0.007258f, -0.003869f, 0.001568f, -0.000354f, -0.003350f, -0.000643f, -0.000920f, 0.000933f, -0.007724f, -0.001925f, 0.003126f, 0.006652f, 0.003422f, -0.000986f, -0.000941f, 0.000320f, -0.007324f, -0.004978f, 0.001622f, 0.000486f, 0.001950f, -0.001956f, 0.001611f, -0.001588f, 0.002919f, -0.001525f, 0.005462f, 0.005550f, -0.000510f, -0.000125f, 0.004259f, 0.001657f, -0.000296f, 0.000411f, -0.008943f, -0.005621f, -0.001358f, 0.003347f, -0.003679f, -0.007892f, -0.004968f, -0.003761f, -0.005550f, 0.003359f, -0.010204f, 0.003130f, 0.010428f, -0.005504f, -0.002617f, -0.005058f, 0.005816f, -0.002310f, -0.006421f, 0.001701f, -0.009205f, 0.009235f, -0.003556f, -0.000119f, 0.008653f, -0.005126f, 0.003328f, -0.000784f, 0.001148f, -0.006096f, -0.012503f, -0.002727f, 0.004827f, -0.003367f, 0.002923f, 0.004129f, 0.003619f, -0.002924f, 0.002040f, @@ -7271,6 +7299,7 @@ const float CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS][252 0.018358f, -0.020195f, 0.012285f, -0.036205f, -0.000230f, -0.019486f, 0.021761f, -0.002862f, 0.002417f, -0.003265f, -0.021068f, -0.000886f, 0.017137f, 0.047554f, 0.002807f, 0.003558f, 0.009315f, 0.016659f, -0.003390f, -0.003905f, 0.000798f, -0.000180f, 0.040620f, -0.003109f, 0.005685f, 0.017226f, -0.016770f, -0.026851f, -0.000591f, -0.028399f, -0.004244f, -0.014234f, -0.011375f, -0.005117f, -0.012932f, 0.007654f, 0.009595f, -0.016141f, 0.020769f, 0.018611f, -0.003081f, -0.003444f, -0.017888f, 0.013329f, 0.004146f, 0.044256f, 0.048210f, 0.000359f, -0.014792f, -0.011865f, 0.040392f, -0.026530f, -0.030252f, 0.031509f, -0.028569f, 0.018427f, 0.005621f, 0.025515f, 0.023514f, 0.015908f, 0.002584f, -0.016001f, -0.013823f, 0.033133f, -0.013996f, -0.001348f, 0.008121f, 0.028260f, 0.040839f, -0.001144f, 0.027926f, -0.022702f, -0.023750f, 0.002818f, -0.008721f, 0.013302f, 0.008430f, -0.020183f, 0.002868f, 0.013112f, 0.033640f, 0.011641f, 0.013855f, 0.012837f, 0.015118f, 0.004113f, -0.001054f, 0.021560f, 0.003879f, 0.017326f, 0.027403f, 0.006026f, -0.011061f, -0.009150f, 0.024733f, 0.006850f, 0.050578f, 0.012222f, 0.020049f, -0.020057f, -0.032135f, -0.002553f, -0.037541f, -0.023567f, -0.008392f, -0.012215f, 0.001644f, -0.001142f, 0.000540f, 0.001404f, -0.027979f, -0.022362f, -0.012091f, -0.022963f, 0.009075f, 0.010977f, -0.007069f, -0.000183f, -0.022228f, -0.001348f, 0.006548f, -0.003034f} }; +#endif #ifdef IVAS_FLOAT_FIXED //BRIR and HRIR coeff tables in Q29 const Word32 CRendBin_Combined_BRIR_coeff_re_48kHz_fx[15][BINAURAL_CHANNELS][2955] ={ diff --git a/lib_rend/ivas_rom_binaural_crend_head.h b/lib_rend/ivas_rom_binaural_crend_head.h index ef5f09c83..cc0f73571 100644 --- a/lib_rend/ivas_rom_binaural_crend_head.h +++ b/lib_rend/ivas_rom_binaural_crend_head.h @@ -54,8 +54,9 @@ extern Word32 cosine_table_Q31 [181]; #endif /********************** CRendBin_Combined_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_HRIR_latency_s; -#ifdef IVAS_FLOAT_FIXED +#else extern Word32 CRendBin_Combined_HRIR_latency_s_fx; #endif // IVAS_FLOAT_FIXED @@ -66,21 +67,23 @@ extern uint16_t CRendBin_Combined_HRIR_num_iterations_48kHz[15][BINAURAL_CHANNEL extern uint16_t CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[15][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz[15]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[15]; #endif extern uint16_t *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_HRIR_coeff_re_48kHz[15][BINAURAL_CHANNELS][240]; extern float CRendBin_Combined_HRIR_coeff_im_48kHz[15][BINAURAL_CHANNELS][240]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_Combined_HRIR_coeff_re_48kHz_fx[15][BINAURAL_CHANNELS][240]; extern Word32 CRendBin_Combined_HRIR_coeff_im_48kHz_fx[15][BINAURAL_CHANNELS][240]; extern Word32 *CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -89,21 +92,23 @@ extern uint16_t CRendBin_Combined_HRIR_num_iterations_32kHz[15][BINAURAL_CHANNEL extern uint16_t CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[15][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz[15]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[15]; #endif extern uint16_t *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_HRIR_coeff_re_32kHz[15][BINAURAL_CHANNELS][160]; extern float CRendBin_Combined_HRIR_coeff_im_32kHz[15][BINAURAL_CHANNELS][160]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_Combined_HRIR_coeff_re_32kHz_fx[15][BINAURAL_CHANNELS][160]; extern Word32 CRendBin_Combined_HRIR_coeff_im_32kHz_fx[15][BINAURAL_CHANNELS][160]; extern Word32 *CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; /* Sample Rate = 16000 */ @@ -112,29 +117,32 @@ extern uint16_t CRendBin_Combined_HRIR_num_iterations_16kHz[15][BINAURAL_CHANNEL extern uint16_t CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[15][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz[15]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[15]; #endif extern uint16_t *CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_HRIR_coeff_re_16kHz[15][BINAURAL_CHANNELS][80]; extern float CRendBin_Combined_HRIR_coeff_im_16kHz[15][BINAURAL_CHANNELS][80]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_Combined_HRIR_coeff_re_16kHz_fx[15][BINAURAL_CHANNELS][80]; extern Word32 CRendBin_Combined_HRIR_coeff_im_16kHz_fx[15][BINAURAL_CHANNELS][80]; extern Word32 *CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]; /********************** CRendBin_FOA_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_FOA_HRIR_latency_s; -#ifdef IVAS_FLOAT_FIXED +#else extern Word32 CRendBin_FOA_HRIR_latency_s_fx; #endif // IVAS_FLOAT_FIXED @@ -145,21 +153,23 @@ extern uint16_t CRendBin_FOA_HRIR_num_iterations_48kHz[4][BINAURAL_CHANNELS]; extern uint16_t CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[4][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz[4]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[4]; #endif extern uint16_t *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_FOA_HRIR_coeff_re_48kHz[4][BINAURAL_CHANNELS][240]; extern float CRendBin_FOA_HRIR_coeff_im_48kHz[4][BINAURAL_CHANNELS][240]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_FOA_HRIR_coeff_re_48kHz_fx[4][BINAURAL_CHANNELS][240]; extern Word32 CRendBin_FOA_HRIR_coeff_im_48kHz_fx[4][BINAURAL_CHANNELS][240]; extern Word32 *CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -168,21 +178,23 @@ extern uint16_t CRendBin_FOA_HRIR_num_iterations_32kHz[4][BINAURAL_CHANNELS]; extern uint16_t CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[4][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz[4]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[4]; #endif extern uint16_t *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_FOA_HRIR_coeff_re_32kHz[4][BINAURAL_CHANNELS][160]; extern float CRendBin_FOA_HRIR_coeff_im_32kHz[4][BINAURAL_CHANNELS][160]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_FOA_HRIR_coeff_re_32kHz_fx[4][BINAURAL_CHANNELS][160]; extern Word32 CRendBin_FOA_HRIR_coeff_im_32kHz_fx[4][BINAURAL_CHANNELS][160]; extern Word32 *CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; /* Sample Rate = 16000 */ @@ -191,28 +203,31 @@ extern uint16_t CRendBin_FOA_HRIR_num_iterations_16kHz[4][BINAURAL_CHANNELS]; extern uint16_t CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[4][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz[4]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[4]; #endif extern uint16_t *CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_FOA_HRIR_coeff_re_16kHz[4][BINAURAL_CHANNELS][80]; extern float CRendBin_FOA_HRIR_coeff_im_16kHz[4][BINAURAL_CHANNELS][80]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_FOA_HRIR_coeff_re_16kHz_fx[4][BINAURAL_CHANNELS][80]; extern Word32 CRendBin_FOA_HRIR_coeff_im_16kHz_fx[4][BINAURAL_CHANNELS][80]; extern Word32 *CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]; /********************** CRendBin_HOA2_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA2_HRIR_latency_s; -#ifdef IVAS_FLOAT_FIXED +#else extern Word32 CRendBin_HOA2_HRIR_latency_s_fx; #endif // IVAS_FLOAT_FIXED @@ -223,21 +238,23 @@ extern uint16_t CRendBin_HOA2_HRIR_num_iterations_48kHz[9][BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[9][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz[9]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[9]; #endif extern uint16_t *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA2_HRIR_coeff_re_48kHz[9][BINAURAL_CHANNELS][240]; extern float CRendBin_HOA2_HRIR_coeff_im_48kHz[9][BINAURAL_CHANNELS][240]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[9][BINAURAL_CHANNELS][240]; extern Word32 CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[9][BINAURAL_CHANNELS][240]; extern Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -246,21 +263,23 @@ extern uint16_t CRendBin_HOA2_HRIR_num_iterations_32kHz[9][BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[9][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz[9]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[9]; #endif extern uint16_t *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA2_HRIR_coeff_re_32kHz[9][BINAURAL_CHANNELS][160]; extern float CRendBin_HOA2_HRIR_coeff_im_32kHz[9][BINAURAL_CHANNELS][160]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_HOA2_HRIR_coeff_re_32kHz_fx[9][BINAURAL_CHANNELS][160]; extern Word32 CRendBin_HOA2_HRIR_coeff_im_32kHz_fx[9][BINAURAL_CHANNELS][160]; extern Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; /* Sample Rate = 16000 */ @@ -269,28 +288,29 @@ extern uint16_t CRendBin_HOA2_HRIR_num_iterations_16kHz[9][BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[9][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz[9]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[9]; #endif extern uint16_t *CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA2_HRIR_coeff_re_16kHz[9][BINAURAL_CHANNELS][80]; extern float CRendBin_HOA2_HRIR_coeff_im_16kHz[9][BINAURAL_CHANNELS][80]; -#ifdef IVAS_FLOAT_FIXED -extern Word32 CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[9][BINAURAL_CHANNELS][80]; -extern Word32 CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[9][BINAURAL_CHANNELS][80]; -#endif extern float *CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]; extern float *CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED +#else +extern Word32 CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[9][BINAURAL_CHANNELS][80]; +extern Word32 CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[9][BINAURAL_CHANNELS][80]; extern Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; #endif /********************** CRendBin_HOA3_HRIR **********************/ +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA3_HRIR_latency_s; -#ifdef IVAS_FLOAT_FIXED +#else extern Word32 CRendBin_HOA3_HRIR_latency_s_fx; #endif // IVAS_FLOAT_FIXED @@ -302,21 +322,23 @@ extern uint16_t CRendBin_HOA3_HRIR_num_iterations_48kHz[16][BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[16][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz[16]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[16]; #endif extern uint16_t *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA3_HRIR_coeff_re_48kHz[16][BINAURAL_CHANNELS][240]; extern float CRendBin_HOA3_HRIR_coeff_im_48kHz[16][BINAURAL_CHANNELS][240]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[16][BINAURAL_CHANNELS][240]; extern Word32 CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[16][BINAURAL_CHANNELS][240]; extern Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS]; /* Sample Rate = 32000 */ @@ -325,21 +347,23 @@ extern uint16_t CRendBin_HOA3_HRIR_num_iterations_32kHz[16][BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[16][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz[16]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[16]; #endif extern uint16_t *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA3_HRIR_coeff_re_32kHz[16][BINAURAL_CHANNELS][160]; extern float CRendBin_HOA3_HRIR_coeff_im_32kHz[16][BINAURAL_CHANNELS][160]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[16][BINAURAL_CHANNELS][160]; extern Word32 CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[16][BINAURAL_CHANNELS][160]; extern Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS]; /* Sample Rate = 16000 */ @@ -348,28 +372,31 @@ extern uint16_t CRendBin_HOA3_HRIR_num_iterations_16kHz[16][BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[16][BINAURAL_CHANNELS][1]; extern uint16_t CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz[16]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[16]; #endif extern uint16_t *CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_HOA3_HRIR_coeff_re_16kHz[16][BINAURAL_CHANNELS][80]; extern float CRendBin_HOA3_HRIR_coeff_im_16kHz[16][BINAURAL_CHANNELS][80]; -#ifdef IVAS_FLOAT_FIXED +extern float *CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]; +extern float *CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]; +#else extern Word32 CRendBin_HOA3_HRIR_coeff_re_16kHz_fx[16][BINAURAL_CHANNELS][80]; extern Word32 CRendBin_HOA3_HRIR_coeff_im_16kHz_fx[16][BINAURAL_CHANNELS][80]; extern Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS]; extern Word32 *CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS]; #endif -extern float *CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS]; -extern float *CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS]; /********************** CRendBin_Combined_BRIR **********************/ +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_BRIR_latency_s; -#ifdef IVAS_FLOAT_FIXED +#else extern Word32 CRendBin_Combined_BRIR_latency_s_fx; #endif // IVAS_FLOAT_FIXED @@ -380,21 +407,23 @@ extern uint16_t CRendBin_Combined_BRIR_num_iterations_48kHz[15][BINAURAL_CHANNEL extern uint16_t CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[15][BINAURAL_CHANNELS][22]; extern uint16_t CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz[15]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[15]; #endif extern uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[BINAURAL_CHANNELS][40]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_BRIR_coeff_re_48kHz[15][BINAURAL_CHANNELS][2955]; extern float CRendBin_Combined_BRIR_coeff_im_48kHz[15][BINAURAL_CHANNELS][2955]; -#ifdef IVAS_FLOAT_FIXED +extern float CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS][2885]; +extern float CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS][2885]; +#else extern Word32 CRendBin_Combined_BRIR_coeff_re_48kHz_fx[15][BINAURAL_CHANNELS][2955]; extern Word32 CRendBin_Combined_BRIR_coeff_im_48kHz_fx[15][BINAURAL_CHANNELS][2955]; extern Word32 CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[BINAURAL_CHANNELS][2885]; extern Word32 CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[BINAURAL_CHANNELS][2885]; #endif -extern float CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz[BINAURAL_CHANNELS][2885]; -extern float CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz[BINAURAL_CHANNELS][2885]; /* Sample Rate = 32000 */ @@ -403,21 +432,23 @@ extern uint16_t CRendBin_Combined_BRIR_num_iterations_32kHz[15][BINAURAL_CHANNEL extern uint16_t CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[15][BINAURAL_CHANNELS][22]; extern uint16_t CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz[15]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[15]; #endif extern uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[BINAURAL_CHANNELS][40]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_BRIR_coeff_re_32kHz[15][BINAURAL_CHANNELS][2819]; extern float CRendBin_Combined_BRIR_coeff_im_32kHz[15][BINAURAL_CHANNELS][2819]; -#ifdef IVAS_FLOAT_FIXED +extern float CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS][2870]; +extern float CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS][2870]; +#else extern Word32 CRendBin_Combined_BRIR_coeff_re_32kHz_fx[15][BINAURAL_CHANNELS][2819]; extern Word32 CRendBin_Combined_BRIR_coeff_im_32kHz_fx[15][BINAURAL_CHANNELS][2819]; extern Word32 CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[BINAURAL_CHANNELS][2870]; extern Word32 CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[BINAURAL_CHANNELS][2870]; #endif -extern float CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz[BINAURAL_CHANNELS][2870]; -extern float CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz[BINAURAL_CHANNELS][2870]; /* Sample Rate = 16000 */ @@ -426,19 +457,21 @@ extern uint16_t CRendBin_Combined_BRIR_num_iterations_16kHz[15][BINAURAL_CHANNEL extern uint16_t CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[BINAURAL_CHANNELS]; extern uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[15][BINAURAL_CHANNELS][23]; extern uint16_t CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz[15]; -#ifdef IVAS_FLOAT_FIXED +#else extern Word16 CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[15]; #endif extern uint16_t CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[BINAURAL_CHANNELS][40]; +#ifndef IVAS_FLOAT_FIXED extern float CRendBin_Combined_BRIR_coeff_re_16kHz[15][BINAURAL_CHANNELS][1774]; extern float CRendBin_Combined_BRIR_coeff_im_16kHz[15][BINAURAL_CHANNELS][1774]; -#ifdef IVAS_FLOAT_FIXED +extern float CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS][2522]; +extern float CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS][2522]; +#else extern Word32 CRendBin_Combined_BRIR_coeff_re_16kHz_fx[15][BINAURAL_CHANNELS][1774]; extern Word32 CRendBin_Combined_BRIR_coeff_im_16kHz_fx[15][BINAURAL_CHANNELS][1774]; extern Word32 CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[BINAURAL_CHANNELS][2522]; extern Word32 CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[BINAURAL_CHANNELS][2522]; #endif -extern float CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz[BINAURAL_CHANNELS][2522]; -extern float CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz[BINAURAL_CHANNELS][2522]; #endif /* _IVAS_ROM_BINAURAL_CREND_HEAD_ */ diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index dab91ad0a..b78c6fba1 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -50,7 +50,7 @@ const Word16 diffuse_response_CICP6_fx[5] = { 13824, 13824, 12137, 16495, 16495 const Word16 diffuse_response_CICP14_fx[7] = { 12507, 12507, 9237, 17691, 17691, 4977, 4977 };//Q15 const Word16 diffuse_response_CICP16_fx[9] = { 11324, 11324, 9945, 13513, 13513, 8853, 8853, 9905, 9905 };//Q15 -#endif +#else const float ls_azimuth_4d4[8] = { 45.0f, -45.0f, 135.0f, -135.0f, 45.0f, -45.0f, 135.0f, -135.0f }; @@ -61,11 +61,12 @@ const float diffuse_response_CICP6[5] = { 0.4219f, 0.4219f, 0.3704f, 0.5034f, 0. const float diffuse_response_CICP14[7] = { 0.3817f, 0.3817f, 0.2819f, 0.5399f, 0.5399f, 0.1519f, 0.1519f }; const float diffuse_response_CICP16[9] = { 0.3456f, 0.3456f, 0.3035f, 0.4124f, 0.4124f, 0.2702f, 0.2702f, 0.3023f, 0.3023f }; - +#endif const int16_t ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS] = { 7, 2, 1 }; const int16_t ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS] = { 15, 6, 3 }; +#ifndef IVAS_FLOAT_FIXED const float ap_lattice_delta_phi[DIRAC_MAX_NUM_DECORR_FILTERS*DIRAC_MAX_DECORR_FILTER_LEN] = { 1.802519f, 0.922986f, 1.813685f, 1.272828f, 0.856928f, 0.366571f, 1.531249f, 1.318158f, 0.123812f, 0.897173f, 0.958696f, 1.256384f, 0.179677f, 0.668918f, 1.440292f, 1.573058f, 1.396481f, 1.191463f, 0.444143f, 1.666942f, @@ -91,8 +92,7 @@ const float ap_lattice_delta_phi[DIRAC_MAX_NUM_DECORR_FILTERS*DIRAC_MAX_DECORR_F 0.669967f, 1.535929f, 1.841878f, 0.979127f, 0.614002f, 1.879218f, 0.512531f, 1.167061f, 0.081697f, 1.773427f, 1.535668f, 0.757729f, 0.220395f, 1.538243f, 1.281162f, 0.302159f, 0.889871f, 0.798522f, 1.476288f, 1.665941f, 0.915365f, 1.394094f, 0.757041f, 0.350064f, 1.199679f, 1.319499f, 1.128405f, 0.632337f, 0.790673f, 0.461582f, 1.693343f, 1.537442f, 0.346527f, 0.433782f, 1.754552f, 0.550903f, 0.686724f, 0.764433f, 1.792750f, 1.489998f }; - -#ifdef IVAS_FLOAT_FIXED +#else const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS*DIRAC_MAX_DECORR_FILTER_LEN] /*Q14*/ = { 29532 , 15122 , 29715 , 20854 , 14040 , 6006 , 25088 , 21597 , 2029 , 14699 , 15707 , 20585 , 2944 , 10960 , 23598 , 25773 , 22880 , 19521 , 7277 , 27311 , 20872 , 28626 , 23074 , @@ -117,7 +117,7 @@ const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS*DIRAC_MAX_DECO 27295 , 14997 , 22841 , 12403 , 5735 , 19656 , 21619 , 18488 , 10360 , 12954 , 7563 , 27744 , 25189 , 5677 , 7107 , 28747 , 9026 , 11251 , 12524 , 29372 , 24412 }; #endif - +#ifndef IVAS_FLOAT_FIXED const float ap_lattice_coeffs_1[DIRAC_DECORR_FILTER_LEN_1*DIRAC_MAX_NUM_DECORR_FILTERS] = { 0.795329f, 0.502700f, 0.204456f, 0.416566f, 0.459648f, 0.270454f, -0.201944f, 0.027997f, 0.067811f, -0.052627f, -0.038779f, -0.057387f, 0.020480f, 0.367697f, -0.593705f, @@ -203,7 +203,7 @@ const float * const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS] = &ap_lattice_coeffs_3[0], }; -#ifdef IVAS_FLOAT_FIXED +#else const Word16 ap_lattice_coeffs_1_fx[330] = { 26061, 16472, 6699, 13650, 15061, 8862, -6617, 917, 2222, -1724, -1270, -1880, 671, 12048, -19454, 17487, 6635, -63, 6392, -6044, -7663, 7474, -10790, -11098, -2611, 1716, -310, 5859, 6253, -15691, 1442, 25837, 4375, -5690, 17871, 22329, 10907, 9656, 10658, 1560, 5157, 3810, 7175, -6201, -10400, -24696, 25309, -16625, 9076, -22700, 7612, -11624, -511, -7309, 10174, -1147, 2810, -16383, 7053, 6599, -16238, -9884, 6439, 10687, -19476, 10319, 21911, 2511, 1497, -4089, -6660, -9738, 4122, -5881, -6611, 5279, 12977, 8745, 11684, 15995, -1843, 4563, -9712, -3697, 1225, -12039, -7087, -9088, 12760, 3772, -7879, -8880, 13982, -362, 4974, 8306, 7397, 16341, -4468, 14516, -9994, -1025, -352, 5581, 16268, -4583, -7929, -3435, 9645, -2219, -16128, -15978, 1192, 3584, 12981, -11562, -6747, -2719, -15172, -10135, 848, -3029, -4100, -5115, -160, 5847, 2935, 1468, 7805, -10227, -12802, -5850, 14890, 12681, -12742, -6481, 1164, 14922, -1782, 12452, 9534, 1599, 2576, 7265, -7128, 3974, -12998, -7159, -4170, -8831, -11279, -15238, -13808, -852, 7259, 11861, -11411, 9666, 11998, 2315, -2819, 8261, 5113, -2057, 13401, 7944, -9888, -2167, 12735, -15146, -5206, 7562, -3053, 1542, 2405, -10977, 751, 11619, 2372, 638, 11039, -15746, 5579, 8508, -12896, -11422, -3570, 9137, 12631, 11870, -10444, 11872, 9467, 9542, -9110, -14722, -9453, -13565, -13280, -9671, -8031, 82, 9433, 11410, -5844, -6767, 11504, -15800, 699, -16128, 1593, 14853, 3576, 7621, -15524, 4603, 11551, -3231, 4822, -1828, 3530, -7570, 11708, 11404, 7615, -10642, 5324, 1888, -1990, -319, -7346, -9252, -2144, 2119, 9187, -9335, -15417, 638, -14493, 12360, 14659, -9519, 11322, 12130, -10260, 3918, 9830, 13336, -9106, 14648, 6383, 5167, -7320, -4822, 12421, -7089, 4520, -13014, 2421, -8949, -14517, -5515, 11346, 1230, 2142, 5370, -4014, 11975, -10365, 3842, -9872, 5558, -11025, 8844, -13767, -10855, 16335, -12878, -15144, -10587, 15432, -11778, 8661, 7104, 16167, 4963, -10539, 15217, -11654, 13775, 6039, -9900, 4474, -8285, 6353, 9790, 7825, -12658, -5963, -2533, 4090, -8630, 12766, 147, 11134, 13605, 12378, 13114, 11548, -124, -6046, 14199, -7784, 4839, 13343, 2215, -8169, -11600, 10516, 13959, 10144, -6215, -6863, 5209, -2684, 12675, 5851, -13341, 7280, -4885, }; const Word16 ap_lattice_coeffs_2_fx[132] = { 20764, 22321, -1619, 9395, 4784, 4436, -13439, -6775, -21527, -3334, 14296, 11135, -4305, -25354, -9883, 10733, 10886, 6745, 23514, -18100, -4919, 1787, 7848, -21249, -23653, 6205, 2234, 203, 2523, 1267, 13874, -3560, 14157, -13586, 9104, 13712, 2549, -9275, -11698, 151, -14504, -12200, 13216, 7963, 10301, 14565, 11387, 16254, 3552, 15380, -5579, 10692, 5641, 14428, 1914, 11130, -6388, 16096, -9217, -1412, -15810, -10977, -11015, 6437, -5394, 14499, -4429, -11612, 14815, -10198, -11391, 16329, -9469, 12334, -5830, 6407, 10940, -5003, 1744, 15000, 14499, 7708, -11310, -9374, 5093, 13283, 7113, -3537, 350, 12090, -16330, -16246, -7060, -3075, 10494, -453, 16036, 15427, -2157, 11366, 893, 4918, 15860, -16298, 5531, -16182, -5686, 10966, 8658, -13914, -10319, 8293, 13021, -16107, -14867, -15183, -626, 11, 10336, 15477, 3117, 9285, -7375, -3924, -15626, 1229, 11041, 16204, -2051, 5821, 15200, 16032, }; const Word16 ap_lattice_coeffs_3_fx[66] = { 621, -6953, 13851, -13128, -3502, -805, 4587, 9161, 1060, 20726, 18957, -24071, 563, 433, -908, -11578, -15799, -16097, 14975, 5410, 15391, -6412, 14421, -15642, 11802, -16074, 15880, -5694, 247, 9115, 14234, 1977, -6347, -1104, 16260, 96, -15756, -3589, -760, 10639, -9570, -11670, -12012, 12481, -9887, 3614, 12575, 9960, -16373, -11455, 10969, -662, -14092, -5069, -12161, 10947, 11367, -5465, -7506, 3865, 11183, 16071, 16176, -12049, 13976, -1499, }; @@ -216,12 +216,12 @@ const Word16 * const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS] = }; #endif +#ifndef IVAS_FLOAT_FIXED const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1] = { 0.0f, 0.125f, 0.375f, 1.0f }; - -#ifdef IVAS_FLOAT_FIXED +#else const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]/*Q14*/ = { 0 , 2048, 6144, 16384 }; @@ -263,48 +263,52 @@ const int16_t channelIndex_CICP14[7] = { 0, 1, 2, 5, 6, 9, 10 }; const int16_t channelIndex_CICP16[9] = { 0, 1, 2, 5, 6, 9, 10, 11, 12 }; const int16_t channelIndex_CICP19[11] = { 0, 1, 2, 3, 4, 7, 8, 9, 10, 13, 14 }; - +#ifndef IVAS_FLOAT_FIXED const float surCohEne[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = { 3.0903f, 2.0053f, 1.0860f, 0.8072f, 0.7079f }; - +#else const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = { 25315, 16427, 8896, 6612, 5799 }; - +#endif +#ifndef IVAS_FLOAT_FIXED const float spreadCohEne05[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = { 2.3988f, 1.7783f, 1.1220f, 1.1220f, 1.1220f }; - +#else const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = /* Q13 */ { 19650, 14567, 9191, 9191, 9191 }; - +#endif +#ifndef IVAS_FLOAT_FIXED const float spreadCohEne1[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = { 1.5975f, 1.1220f, 1.1220f, 1.1220f, 1.1220f }; - +#else const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS] = /* Q14 */ { 26173, 18382, 18382, 18382, 18382 }; - +#endif +#ifndef IVAS_FLOAT_FIXED const float lowBitRateBinauralEQ[LOW_BIT_RATE_BINAURAL_EQ_BINS] = { 0.979f, 0.893f, 0.762f, 0.615f, 0.52f, 0.48f, 0.477f, 0.477f, 0.48f, 0.501f, 0.546f, 0.602f, 0.652f, 0.664f, 0.652f, 0.639f, 0.635f }; - +#else const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS] = { 2102386432, 1917702912, 1636382592, 1320702464, 1116691456, 1030792128, 1024349696, 1024349696, 1030792128, 1075889280, 1172526080, 1292785152, 1400159360, 1425929088, 1400159360, 1372242048, 1363652096 }; - +#endif +#ifndef IVAS_FLOAT_FIXED const float diffuseFieldCoherenceDifferenceX[BINAURAL_COHERENCE_DIFFERENCE_BINS] = { 0.047421f, 0.19773f, 0.22582f, 0.10637f, 0.0087111f, 0.012028f, 0.031972f, 0.019668f, 0.0079928f @@ -319,7 +323,7 @@ const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENCE_BINS] { 0.048207f, 0.10796f, 0.11845f, 0.047886f, 0.035917f, 0.045196f, 0.018863f, 0.015547f, 0.014157f }; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS] = { /* Q31 */ 101835824, 424621952, 484944768, 228427840, 18706944, 25829934, 68659344, 42236708, 17164408, }; @@ -342,6 +346,7 @@ const int16_t HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS] = 13, 12, 11 }; +#ifndef IVAS_FLOAT_FIXED const float SincTable[321] = { 1.00000000f, 0.99957629f, 0.99830587f, 0.99619078f, 0.99323448f, 0.98944177f, 0.98481881f, 0.97937311f, @@ -387,7 +392,7 @@ const float SincTable[321] = 0.00000000f }; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 SincTable_fx[321] /*Q31*/ = { 2147483647, 2146573696, 2143845504, 2139303424, 2132954752, 2124809984, 2114882304, 2103187712, 2089745280, 2074576896, 2057706880, 2039162624, 2018973952, 1997173632, 1973796608, 1948880384, @@ -431,7 +436,7 @@ const Word32 SincTable_fx[321] /*Q31*/ = { 4368840, 3818118, 3267783, 2718370, 2170290, 1624034, 1079948, 538481, }; #endif - +#ifndef IVAS_FLOAT_FIXED const float defaultHRIR_coherence_48kHz[LR_IAC_LENGTH_NR_FC] = { 0.983003f, 0.933450f, 0.789276f, 0.574420f, 0.340710f, 0.144220f, 0.018803f, 0.000000f, 0.000000f, 0.000000f, 0.011939f, 0.035489f, 0.043188f, 0.042460f, 0.041788f, 0.038562f, 0.028911f, 0.017162f, @@ -719,7 +724,7 @@ const float defaultHRIR_right_avg_power_16kHz[LR_IAC_LENGTH_NR_FC] = { 0.485566f, 0.481405f, 0.471746f, 0.440098f, 0.408450f, 0.376802f, 0.330743f, 0.284685f, 0.238626f, 0.203638f, 0.171419f, 0.139199f, 0.126311f, 0.126311f }; -#ifdef IVAS_FLOAT_FIXED +#else const Word32 defaultHRIR_coherence_48kHz_fx[LR_IAC_LENGTH_NR_FC] /*Q-27*/ = { 131936432,125285536,105934832,77097344,45729324,19356880,2523696,0,0, 0,1602425,4763253,5796595,5698884,5608690,5175704,3880368,2303444, @@ -1154,16 +1159,18 @@ const float ivas_reverb_default_DSR[IVAS_REVERB_DEFAULT_N_BANDS] = * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED /* CICP1 - Mono */ const float ls_azimuth_CICP1[1] = { 0.0f }; const float ls_elevation_CICP1[1] = { 0.0f }; - +#endif /*----------------------------------------------------------------------------------* * LS Renderer ROM tables *----------------------------------------------------------------------------------*/ - + /* All matrices are stored with dimensions nchan_in x nchan_out */ + /* Downmix matrices */ #ifdef IVAS_FLOAT_FIXED /* All matrices are stored with dimensions nchan_in x nchan_out */ /* Downmix matrices */ @@ -1512,9 +1519,7 @@ const LS_CONVERSION_MAPPING_FX ls_conversion_mapping_fx[LS_SETUP_CONVERSION_NUM_ {IVAS_AUDIO_CONFIG_5_1_4, IVAS_AUDIO_CONFIG_7_1_4, ls_conversion_cicp16_cicp19_fx}, }; -#endif - /* All matrices are stored with dimensions nchan_in x nchan_out */ - /* Downmix matrices */ +#else const float ls_conversion_cicpX_mono[12][1] = { {1.00000000f}, @@ -1546,7 +1551,6 @@ const float ls_conversion_cicpX_stereo[12][2] = {0.849999964f, 0.000000000f}, {0.000000000f, 0.849999964f} }; -#ifndef IVAS_FLOAT_FIXED const LS_CONVERSION_MATRIX ls_conversion_cicp12_cicp6[] = { /* First row indicates the number of non-zero elements and the number of matrix columns */ diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 720fc2c80..c70edf8c6 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -42,12 +42,13 @@ * DirAC renderer ROM tables *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED extern const float ls_azimuth_4d4[8]; extern const float ls_elevation_4d4[8]; extern const float diffuse_response_CICP6[5]; extern const float diffuse_response_CICP14[7]; extern const float diffuse_response_CICP16[9]; -#ifdef IVAS_FLOAT_FIXED +#else extern const Word32 ls_azimuth_4d4_fx[8]; extern const Word32 ls_elevation_4d4_fx[8]; extern const Word16 diffuse_response_CICP6_fx[5]; @@ -57,16 +58,20 @@ extern const Word16 diffuse_response_CICP16_fx[9]; extern const int16_t ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const int16_t ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; +#ifndef IVAS_FLOAT_FIXED extern const float ap_lattice_delta_phi[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; extern const float ap_lattice_coeffs_1[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; extern const float ap_lattice_coeffs_2[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; extern const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; extern const float *const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS]; -extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; -#ifdef IVAS_FLOAT_FIXED -extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; +#else extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; +extern const Word16 ap_lattice_coeffs_1_fx[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; +extern const Word16 ap_lattice_coeffs_2_fx[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; +extern const Word16 ap_lattice_coeffs_3_fx[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; +extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; #endif extern const int16_t sba_map_tc[11]; @@ -82,24 +87,31 @@ extern const int16_t channelIndex_CICP14[7]; extern const int16_t channelIndex_CICP16[9]; extern const int16_t channelIndex_CICP19[11]; +#ifndef IVAS_FLOAT_FIXED /* These are equalization values for spread and surround coherent sounds, approximating the spectrum * for such sounds at anechoic multichannel listening. */ extern const float surCohEne[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; extern const float spreadCohEne05[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; extern const float spreadCohEne1[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /* Values for low-bit-rate equalization */ extern const float lowBitRateBinauralEQ[LOW_BIT_RATE_BINAURAL_EQ_BINS]; -extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; /* Diffuse field binaural coherence directional adjustment values */ extern const float diffuseFieldCoherenceDifferenceX[BINAURAL_COHERENCE_DIFFERENCE_BINS]; extern const float diffuseFieldCoherenceDifferenceY[BINAURAL_COHERENCE_DIFFERENCE_BINS]; extern const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENCE_BINS]; -#ifdef IVAS_FLOAT_FIXED +#else +/* These are equalization values for spread and surround coherent sounds, approximating the spectrum + * for such sounds at anechoic multichannel listening. */ +extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; +extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; +extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; + +/* Values for low-bit-rate equalization */ +extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; + +/* Diffuse field binaural coherence directional adjustment values */ extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; @@ -112,10 +124,8 @@ extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFE extern const int16_t HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; +#ifndef IVAS_FLOAT_FIXED extern const float SincTable[321]; -#ifdef IVAS_FLOAT_FIXED -extern const Word32 SincTable_fx[321]; -#endif extern const float defaultHRIR_coherence_48kHz[LR_IAC_LENGTH_NR_FC]; extern const float defaultHRIR_left_avg_power_48kHz[LR_IAC_LENGTH_NR_FC]; @@ -129,7 +139,9 @@ extern const float defaultHRIR_coherence_16kHz[LR_IAC_LENGTH_NR_FC]; extern const float defaultHRIR_left_avg_power_16kHz[LR_IAC_LENGTH_NR_FC]; extern const float defaultHRIR_right_avg_power_16kHz[LR_IAC_LENGTH_NR_FC]; -#ifdef IVAS_FLOAT_FIXED +#else +extern const Word32 SincTable_fx[321]; + extern const Word32 defaultHRIR_coherence_48kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-27*/ extern const Word32 defaultHRIR_left_avg_power_48kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ extern const Word32 defaultHRIR_right_avg_power_48kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ @@ -177,27 +189,27 @@ extern const float ivas_reverb_default_DSR[]; /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices *----------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED extern const float ls_azimuth_CICP1[1]; extern const float ls_elevation_CICP1[1]; - +#endif /*----------------------------------------------------------------------------------* * LS Configuration Converter ROM tables *----------------------------------------------------------------------------------*/ /* Downmix matrices */ +#ifndef IVAS_FLOAT_FIXED extern const float ls_conversion_cicpX_mono[12][1]; extern const float ls_conversion_cicpX_stereo[12][2]; -#ifdef IVAS_FLOAT_FIXED -extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; -extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; -#endif /* Mapping table of input config : output config with corresponding matrix */ -#ifndef IVAS_FLOAT_FIXED extern const LS_CONVERSION_MAPPING ls_conversion_mapping[]; #else +extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; +extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; + +/* Mapping table of input config : output config with corresponding matrix */ extern const LS_CONVERSION_MAPPING_FX ls_conversion_mapping_fx[]; #endif diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index be96d186f..9bb102e1d 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -47,11 +47,10 @@ #include "ivas_prot_fx.h" #include "debug.h" #include "ivas_rom_binaural_crend_head.h" -#define float_to_fixed( n, factor ) ( round( n * ( 1 << factor ) ) ) Word16 square_root16_table[] = { 0, 0x4000, 0x5A82 }; // Q14 Word16 square_root30_q12[31] = { - // Q10 + // Q12 0, 4096, 5793, @@ -94,12 +93,17 @@ static ivas_error combine_external_and_head_orientations( IVAS_VECTOR3 *listenerPos, EXTERNAL_ORIENTATION_HANDLE hExtOrientationData, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData ); - +#ifndef IVAS_FLOAT_FIXED static void external_target_interpolation( EXTERNAL_ORIENTATION_HANDLE hExtOrientationData, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, const int16_t i ); - +#else +static void external_target_interpolation_fx( + EXTERNAL_ORIENTATION_HANDLE hExtOrientationData, + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, + const Word16 i ); +#endif #ifndef IVAS_FLOAT_FIXED static bool are_orientations_same( const IVAS_QUATERNION *orientation1, const IVAS_QUATERNION *orientation2 ); #endif @@ -129,7 +133,7 @@ ivas_error ivas_headTrack_open_fx( } /* Initialization */ - ( *hHeadTrackData )->lrSwitchInterpVal_fx = 0; + ( *hHeadTrackData )->lrSwitchInterpVal_fx = 0; // Q30 move32(); ( *hHeadTrackData )->lrSwitchedCurrent = 0; move32(); @@ -140,7 +144,7 @@ ivas_error ivas_headTrack_open_fx( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Orientation tracking" ); } - IF( ( error = ivas_orient_trk_Init_fx( ( *hHeadTrackData )->OrientationTracker ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_orient_trk_Init_fx( ( *hHeadTrackData )->OrientationTracker ) ), IVAS_ERR_OK ) ) { return error; } @@ -149,7 +153,7 @@ ivas_error ivas_headTrack_open_fx( FOR( i = 0; i < 3; i++ ) { set32_fx( ( *hHeadTrackData )->Rmat_prev_fx[i], 0, 3 ); - ( *hHeadTrackData )->Rmat_prev_fx[i][i] = ONE_IN_Q31; + ( *hHeadTrackData )->Rmat_prev_fx[i][i] = ONE_IN_Q31; // Q31 move32(); } @@ -212,11 +216,12 @@ ivas_error ivas_headTrack_open( * * Deallocate Head-Tracking handle *-----------------------------------------------------------------------*/ - -void ivas_headTrack_close( +#ifdef IVAS_FLOAT_FIXED +void ivas_headTrack_close_fx( HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ ) { + test(); IF( hHeadTrackData == NULL || *hHeadTrackData == NULL ) { return; @@ -233,7 +238,28 @@ void ivas_headTrack_close( return; } +#else +void ivas_headTrack_close( + HEAD_TRACK_DATA_HANDLE *hHeadTrackData /* i/o: head track handle */ +) +{ + if ( hHeadTrackData == NULL || *hHeadTrackData == NULL ) + { + return; + } + + if ( ( *hHeadTrackData )->OrientationTracker != NULL ) + { + free( ( *hHeadTrackData )->OrientationTracker ); + ( *hHeadTrackData )->OrientationTracker = NULL; + } + free( ( *hHeadTrackData ) ); + *hHeadTrackData = NULL; + + return; +} +#endif /*---------------------------------------------------------------------------------- * QuatToRotMat() @@ -259,25 +285,18 @@ void QuatToRotMat_fx( // Adding a guard bit to squared terms since 2*x is not being done in those // statements (R[0][0], R[1][1], R[2][2]). This is done to avoid L_shl. Word32 ww = L_shr( Mpy_32_32( w, w ), 1 ); // 2 * Qx - 31 - 1 = 2*Qx-32 - move32(); Word32 xx = L_shr( Mpy_32_32( x, x ), 1 ); - move32(); Word32 yy = L_shr( Mpy_32_32( y, y ), 1 ); - move32(); Word32 zz = L_shr( Mpy_32_32( z, z ), 1 ); - move32(); + Word32 wx = Mpy_32_32( w, x ); - move32(); Word32 wz = Mpy_32_32( w, z ); - move32(); Word32 wy = Mpy_32_32( w, y ); - move32(); + Word32 xy = Mpy_32_32( x, y ); - move32(); Word32 xz = Mpy_32_32( x, z ); - move32(); + Word32 yz = Mpy_32_32( y, z ); - move32(); Rmat[0][0] = L_sub( L_sub( L_add( ww, xx ), yy ), zz ); move32(); @@ -302,8 +321,7 @@ void QuatToRotMat_fx( return; } -#endif - +#else void QuatToRotMat( const IVAS_QUATERNION quat, /* i : quaternion describing the rotation */ float Rmat[3][3] /* o : real-space rotation matrix for this rotation */ @@ -323,6 +341,7 @@ void QuatToRotMat( return; } +#endif #ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -366,10 +385,14 @@ void Euler2Quat_fx( Word16 sp = getSinWord16( extract_l( L_shr_r( pitch, 10 ) ) ); Word16 cy = getCosWord16( extract_l( L_shr_r( yaw, 10 ) ) ); Word16 sy = getSinWord16( extract_l( L_shr_r( yaw, 10 ) ) ); - quat->w_fx = L_shr_r( L_add( Mpy_32_16_1( L_mult0( cr, cp ), cy ), Mpy_32_16_1( L_mult0( sr, sp ), sy ) ), 5 ); - quat->x_fx = L_shr_r( L_sub( Mpy_32_16_1( L_mult0( sr, cp ), cy ), Mpy_32_16_1( L_mult0( cr, sp ), sy ) ), 5 ); - quat->y_fx = L_shr_r( L_add( Mpy_32_16_1( L_mult0( sr, cp ), sy ), Mpy_32_16_1( L_mult0( cr, sp ), cy ) ), 5 ); - quat->z_fx = L_shr_r( L_sub( Mpy_32_16_1( L_mult0( cr, cp ), sy ), Mpy_32_16_1( L_mult0( sr, sp ), cy ) ), 5 ); + quat->w_fx = L_shr_r( L_add( Mpy_32_16_1( L_mult0( cr, cp ), cy ), Mpy_32_16_1( L_mult0( sr, sp ), sy ) ), 5 ); // Q19 + move32(); + quat->x_fx = L_shr_r( L_sub( Mpy_32_16_1( L_mult0( sr, cp ), cy ), Mpy_32_16_1( L_mult0( cr, sp ), sy ) ), 5 ); // Q19 + move32(); + quat->y_fx = L_shr_r( L_add( Mpy_32_16_1( L_mult0( sr, cp ), sy ), Mpy_32_16_1( L_mult0( cr, sp ), cy ) ), 5 ); // Q19 + move32(); + quat->z_fx = L_shr_r( L_sub( Mpy_32_16_1( L_mult0( cr, cp ), sy ), Mpy_32_16_1( L_mult0( sr, sp ), cy ) ), 5 ); // Q19 + move32(); return; } @@ -381,7 +404,7 @@ void Euler2Quat_fx( * * Converts degrees to normalized radians *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED float deg2rad( float degrees ) { @@ -396,9 +419,10 @@ float deg2rad( return PI_OVER_180 * degrees; } -#ifdef IVAS_FLOAT_FIXED +#else Word32 deg2rad_fx( - Word32 degrees ) + Word32 degrees // Q23 +) { WHILE( GE_32( degrees, DEGREE_180 ) ) { @@ -409,7 +433,7 @@ Word32 deg2rad_fx( degrees = L_add( degrees, DEGREE_360 ); } - return Mpy_32_32( PI_OVER_180_FX, degrees ); + return Mpy_32_32( PI_OVER_180_FX, degrees ); // Q23 } #endif @@ -418,7 +442,7 @@ Word32 deg2rad_fx( * * Converts normalized radians to degrees *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED float rad2deg( float radians ) { @@ -433,9 +457,10 @@ float rad2deg( return _180_OVER_PI * radians; } -#ifdef IVAS_FLOAT_FIXED +#else Word32 rad2deg_fx( - Word32 radians ) + Word32 radians // Q13 +) { WHILE( GE_32( radians, EVS_PI_FX ) ) @@ -447,7 +472,7 @@ Word32 rad2deg_fx( radians = L_add( radians, EVS_PI_FX ); } - return ( radians * _180_OVER_PI_FX ); + return W_extract_l( W_mult0_32_32( radians, _180_OVER_PI_FX ) ); // Q23 } #endif #ifdef IVAS_FLOAT_FIXED @@ -458,11 +483,11 @@ Word32 rad2deg_fx( *------------------------------------------------------------------------*/ void rotateAziEle_fx( - Word16 azi_in, /* i : output elevation */ - Word16 ele_in, /* i : input elevation */ - Word16 *azi, /* o : rotated azimuth */ - Word16 *ele, /* o : rotated elevation */ - Word32 Rmat_fx[3][3], /* i : real-space rotation matrix */ + Word16 azi_in, /* i : output elevation Q0 */ + Word16 ele_in, /* i : input elevation Q0 */ + Word16 *azi, /* o : rotated azimuth Q0 */ + Word16 *ele, /* o : rotated elevation Q0 */ + Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30*/ const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ ) { @@ -476,7 +501,14 @@ void rotateAziEle_fx( /*Conversion spherical to cartesian coordinates*/ IF( GT_16( abs_s( azi_in ), 180 ) ) { - azi_in = GT_16( azi_in, 0 ) ? sub( azi_in, 360 ) : add( azi_in, 360 ); + IF( azi_in > 0 ) + { + azi_in = sub( azi_in, 360 ); + } + ELSE + { + azi_in = add( azi_in, 360 ); + } } temp_16 = ele_in; move16(); @@ -497,8 +529,9 @@ void rotateAziEle_fx( /*Rotation mtx multiplication*/ FOR( n = 0; n < 3; n++ ) { - temp = L_add( Mpy_32_32( dv_fx[0], Rmat_fx[n][0] ), Mpy_32_32( dv_fx[1], Rmat_fx[n][1] ) ); - dv_r_fx[n] = L_add( Mpy_32_32( dv_fx[2], Rmat_fx[n][2] ), temp ); // Q30 + temp = L_add( Mpy_32_32( dv_fx[0], Rmat_fx[n][0] ), Mpy_32_32( dv_fx[1], Rmat_fx[n][1] ) ); // Q30 + dv_r_fx[n] = L_add( Mpy_32_32( dv_fx[2], Rmat_fx[n][2] ), temp ); // Q30 + move32(); } /*Conversion cartesian to spherical coordinates*/ @@ -507,21 +540,28 @@ void rotateAziEle_fx( x = dv_r_fx[0]; move32(); radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); - radian = y > 0 ? radian : -radian; - IF( LT_32( x, 0 ) ) + if ( y <= 0 ) { - IF( LT_32( radian, 0 ) ) + radian = negate( radian ); + } + + IF( x < 0 ) + { + IF( radian < 0 ) { - angle = -add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); } ELSE { angle = sub( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); } - IF( EQ_16( radian, 0 ) ) + IF( radian == 0 ) { - angle = GE_32( y, 0 ) ? angle : -angle; + if ( y < 0 ) + { + angle = negate( angle ); + } } } ELSE @@ -529,29 +569,38 @@ void rotateAziEle_fx( angle = extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 24 ) ); } - *azi = (Word16) ( s_max( -180, min( 180, angle ) ) ); + *azi = s_max( -180, min( 180, angle ) ); + move16(); - IF( EQ_16( isPlanar, 0 ) ) + IF( isPlanar == 0 ) { sqrt_fx = L_Frac_sqrtQ31( L_add( Mpy_32_32( dv_r_fx[0], dv_r_fx[0] ), Mpy_32_32( dv_r_fx[1], dv_r_fx[1] ) ) ); y = dv_r_fx[2]; + move32(); x = sqrt_fx; + move32(); radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); - radian = y > 0 ? radian : -radian; + if ( y <= 0 ) + { + radian = negate( radian ); + } - IF( LT_32( x, 0 ) ) + IF( x < 0 ) { - IF( LT_16( radian, 0 ) ) + IF( radian < 0 ) { - angle = -add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); } ELSE { angle = sub( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); } - IF( EQ_16( radian, 0 ) ) + IF( radian == 0 ) { - angle = y >= 0 ? angle : -angle; + if ( y < 0 ) + { + angle = negate( angle ); + } } } ELSE @@ -559,7 +608,8 @@ void rotateAziEle_fx( angle = extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ); } - *ele = (Word16) ( s_max( -90, s_min( 90, angle ) ) ); + *ele = s_max( -90, s_min( 90, angle ) ); + move16(); } ELSE { @@ -576,11 +626,11 @@ void rotateAziEle_fx( * Apply rotation to direction parameters azimuth and elevation *------------------------------------------------------------------------*/ void rotateAziEle_fx_frac_az_el( - Word32 azi_in, /* i : output elevation */ - Word32 ele_in, /* i : input elevation */ - Word32 *azi, /* o : rotated azimuth */ - Word32 *ele, /* o : rotated elevation */ - Word32 Rmat_fx[3][3], /* i : real-space rotation matrix */ + Word32 azi_in, /* i : output elevation Q22 */ + Word32 ele_in, /* i : input elevation Q22 */ + Word32 *azi, /* o : rotated azimuth Q22 */ + Word32 *ele, /* o : rotated elevation Q22 */ + Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ ) { @@ -594,13 +644,20 @@ void rotateAziEle_fx_frac_az_el( /*Conversion spherical to cartesian coordinates*/ IF( GT_32( abs( azi_in ), _180_IN_Q22 ) ) { - azi_in = GT_32( azi_in, 0 ) ? ( azi_in - _360_IN_Q22 ) : ( azi_in + _360_IN_Q22 ); - move32(); + IF( azi_in > 0 ) + { + azi_in = L_sub( azi_in, _360_IN_Q22 ); + } + ELSE + { + azi_in = L_add( azi_in, _360_IN_Q22 ); + } } - azi_in_q13 = (Word16) L_shr( Mpy_32_32( azi_in, PI_OVER_180_FX ), Q9 ); - ele_in_q13 = (Word16) L_shr( Mpy_32_32( ele_in, PI_OVER_180_FX ), Q9 ); + azi_in_q13 = extract_l( L_shr( Mpy_32_32( azi_in, PI_OVER_180_FX ), Q9 ) ); + ele_in_q13 = extract_l( L_shr( Mpy_32_32( ele_in, PI_OVER_180_FX ), Q9 ) ); w_fx = getCosWord16( ele_in_q13 ); // Q14 dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); + move32(); IF( EQ_32( dv_fx[0], ONE_IN_Q29 ) ) { move32(); @@ -609,8 +666,10 @@ void rotateAziEle_fx_frac_az_el( ELSE { dv_fx[0] = L_shl( dv_fx[0], 2 ); + move32(); } dv_fx[1] = L_mult( w_fx, getSinWord16( azi_in_q13 ) ); + move32(); IF( EQ_32( dv_fx[1], ONE_IN_Q30 ) ) { move32(); @@ -619,8 +678,10 @@ void rotateAziEle_fx_frac_az_el( ELSE { dv_fx[1] = L_shl( dv_fx[1], 1 ); + move32(); } - dv_fx[2] = (Word32) getSinWord16( ele_in_q13 ); + dv_fx[2] = L_deposit_l( getSinWord16( ele_in_q13 ) ); + move32(); IF( EQ_32( dv_fx[2], ONE_IN_Q15 ) ) { move32(); @@ -629,6 +690,7 @@ void rotateAziEle_fx_frac_az_el( ELSE { dv_fx[2] = L_shl( dv_fx[2], 16 ); + move32(); } /*Rotation mtx multiplication*/ @@ -636,6 +698,7 @@ void rotateAziEle_fx_frac_az_el( { temp = L_add( Mpy_32_32( dv_fx[0], Rmat_fx[n][0] ), Mpy_32_32( dv_fx[1], Rmat_fx[n][1] ) ); dv_r_fx[n] = L_add( Mpy_32_32( dv_fx[2], Rmat_fx[n][2] ), temp ); // Q30 + move32(); } /*Conversion cartesian to spherical coordinates*/ @@ -645,17 +708,19 @@ void rotateAziEle_fx_frac_az_el( x = dv_r_fx[0]; radian = BASOP_util_atan2( y, x, 0 ); // Q13 - angle = ( Mpy_32_16_1( _180_OVER_PI_Q25, radian ) >> 1 ); // Q22 + angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 - *azi = (Word32) ( max( L_shl( -180, 22 ), min( L_shl( 180, 22 ), angle ) ) ); // Q22 - *azi = ( L_add( *azi, ONE_IN_Q21 ) >> Q22 ) << Q22; - IF( LT_32( abs( *azi ), ONE_IN_Q22 ) ) + *azi = L_max( L_shl( -180, 22 ), L_min( L_shl( 180, 22 ), angle ) ); // Q22 + move32(); + *azi = L_shl( L_shr( L_add( *azi, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); + if ( LT_32( abs( *azi ), ONE_IN_Q22 ) ) { move32(); *azi = 0; } - IF( EQ_16( isPlanar, 0 ) ) + IF( isPlanar == 0 ) { sqrt_fx = L_Frac_sqrtQ31( L_add( Mpy_32_32( dv_r_fx[0], dv_r_fx[0] ), Mpy_32_32( dv_r_fx[1], dv_r_fx[1] ) ) ); y = dv_r_fx[2]; @@ -664,12 +729,14 @@ void rotateAziEle_fx_frac_az_el( move32(); radian = BASOP_util_atan2( y, x, 0 ); - angle = ( Mpy_32_16_1( _180_OVER_PI_Q25, radian ) >> 1 ); // Q22 + angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 - *ele = (Word32) ( max( L_shl( -90, 22 ), min( L_shl( 90, 22 ), angle ) ) ); // Q22 - *ele = ( L_add( *ele, ONE_IN_Q21 ) >> Q22 ) << Q22; - IF( LT_32( abs( *ele ), ONE_IN_Q22 ) ) + *ele = L_max( L_shl( -90, 22 ), L_min( L_shl( 90, 22 ), angle ) ); // Q22 + move32(); + *ele = L_shl( L_shr( L_add( *ele, ONE_IN_Q21 ), Q22 ), Q22 ); + move32(); + if ( LT_32( abs( *ele ), ONE_IN_Q22 ) ) { *ele = 0; move32(); @@ -691,11 +758,11 @@ void rotateAziEle_fx_frac_az_el( *------------------------------------------------------------------------*/ void rotateAziEle_fixed( - Word16 azi_in, /* i : output elevation */ - Word16 ele_in, /* i : input elevation */ - Word32 *azi, /* o : rotated azimuth */ - Word32 *ele, /* o : rotated elevation */ - Word32 Rmat_fx[3][3], /* i : real-space rotation matrix */ + Word16 azi_in, /* i : output elevation Q0 */ + Word16 ele_in, /* i : input elevation Q0 */ + Word32 *azi, /* o : rotated azimuth Q22 */ + Word32 *ele, /* o : rotated elevation Q22 */ + Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ ) { @@ -708,7 +775,14 @@ void rotateAziEle_fixed( /*Conversion spherical to cartesian coordinates*/ IF( GT_16( abs_s( azi_in ), 180 ) ) { - azi_in = ( azi_in > 0 ) ? sub( azi_in, 360 ) : add( azi_in, 360 ); + IF( azi_in > 0 ) + { + azi_in = sub( azi_in, 360 ); + } + ELSE + { + azi_in = add( azi_in, 360 ); + } } temp_16 = ele_in; move16(); @@ -731,6 +805,7 @@ void rotateAziEle_fixed( { temp = L_add( Mpy_32_32( dv_fx[0], Rmat_fx[n][0] ), Mpy_32_32( dv_fx[1], Rmat_fx[n][1] ) ); dv_r_fx[n] = L_add( Mpy_32_32( dv_fx[2], Rmat_fx[n][2] ), temp ); // Q30 + move32(); } /*Conversion cartesian to spherical coordinates*/ @@ -742,25 +817,27 @@ void rotateAziEle_fixed( angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 - - *azi = (Word32) ( L_max( L_shl( -180, 22 ), L_min( L_shl( 180, 22 ), angle ) ) ); // Q22 - IF( LE_32( L_abs( *azi ), ONE_IN_Q22 ) ) + *azi = L_max( L_shl( -180, 22 ), L_min( L_shl( 180, 22 ), angle ) ); // Q22 + move32(); + if ( LE_32( L_abs( *azi ), ONE_IN_Q22 ) ) { *azi = 0; move32(); } - IF( EQ_16( isPlanar, 0 ) ) + IF( isPlanar == 0 ) { sqrt_fx = L_Frac_sqrtQ31( L_add( Mpy_32_32( dv_r_fx[0], dv_r_fx[0] ), Mpy_32_32( dv_r_fx[1], dv_r_fx[1] ) ) ); y = dv_r_fx[2]; + move32(); x = sqrt_fx; + move32(); radian = BASOP_util_atan2( y, x, 0 ); angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 - - *ele = (Word32) ( L_max( L_shl( -90, 22 ), L_min( L_shl( 90, 22 ), angle ) ) ); // Q22 - IF( LT_32( L_abs( *ele ), ONE_IN_Q22 ) ) + *ele = L_max( L_shl( -90, 22 ), L_min( L_shl( 90, 22 ), angle ) ); // Q22 + move32(); + if ( LT_32( L_abs( *ele ), ONE_IN_Q22 ) ) { *ele = 0; move32(); @@ -775,6 +852,7 @@ void rotateAziEle_fixed( return; } #endif +#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * rotateAziEle() * @@ -822,6 +900,7 @@ void rotateAziEle( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -832,45 +911,52 @@ void rotateAziEle( void rotateFrame_shd( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : head and external orientation combined handle */ - Word32 *output[], /* i/o: unrotated HOA3 signal buffer in TD */ + Word32 *output[], /* i/o: unrotated HOA3 signal buffer in TD Q11 */ const Word16 subframe_len, /* i : subframe length per channel */ const IVAS_OUTPUT_SETUP hTransSetup, /* i : format for rotation */ const Word16 subframe_idx /* i : subframe index */ ) { // Not yet tested, no test cases entering the function. - Word16 i, l, n, m; + Word16 i, l, n, m, offset; Word16 m1, m2; Word16 shd_rot_max_order; Word32 tmp = Q31_BY_SUB_FRAME_240; + move32(); Word32 tmpRot[2 * HEADROT_ORDER + 1]; Word16 SHrotmat_prev[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; Word32 cross_fade[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; shd_rot_max_order = hTransSetup.ambisonics_order; + move16(); + offset = imult1616( subframe_idx, subframe_len ); SWITCH( subframe_len ) { case L_SUBFRAME_48k: tmp = Q31_BY_SUB_FRAME_240; + move32(); BREAK; case L_SUBFRAME_32k: tmp = Q31_BY_SUB_FRAME_180; + move32(); BREAK; case L_SUBFRAME_16k: tmp = Q31_BY_SUB_FRAME_80; + move32(); BREAK; case L_SUBFRAME_8k: tmp = Q31_BY_SUB_FRAME_40; + move32(); BREAK; default: BREAK; } - move32(); FOR( i = 0; i < subframe_len; i++ ) { - cross_fade[i] = UL_Mpy_32_32( i, tmp ); + cross_fade[i] = UL_Mpy_32_32( i, tmp ); // Q31 + move32(); } /* initialize rotation matrices with zeros */ FOR( i = 0; i < HEADROT_SHMAT_DIM; i++ ) @@ -882,7 +968,7 @@ void rotateFrame_shd( /* calculate ambisonics rotation matrices for the previous and current frames */ SHrotmatgen_fx( SHrotmat_prev, hCombinedOrientationData->Rmat_prev_fx, shd_rot_max_order ); - SHrotmatgen_fx( SHrotmat, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], shd_rot_max_order ); + SHrotmatgen_fx( SHrotmat /*Q14*/, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], shd_rot_max_order ); FOR( i = 0; i < subframe_len; i++ ) { @@ -904,15 +990,16 @@ void rotateFrame_shd( FOR( m = m1; m < m2; m++ ) { /* crossfade with previous rotation gains */ - tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ), output[m][subframe_idx * subframe_len + i] ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ), output[m][subframe_idx * subframe_len + i] ) ); - tmpRot[n - m1] = L_add( L_shl( tmp, 1 ), tmpRot[n - m1] ); + tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ) ); + tmpRot[n - m1] = L_add( L_shl( tmp, 1 ), tmpRot[n - m1] ); // Q11 } } /* write back the result */ FOR( n = m1; n < m2; n++ ) { - output[n][subframe_idx * subframe_len + i] = (Word32) tmpRot[n - m1]; + output[n][add( offset, i )] = tmpRot[n - m1]; // Q11 + move32(); } m1 = m2; move16(); @@ -1062,19 +1149,19 @@ void rotateFrame_shd( *------------------------------------------------------------------------*/ void rotateFrame_sd( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : head and external orientation combined handle */ - Word32 *output[], /* i/o: unrotated SD signal buffer in TD */ + Word32 *output[], /* i/o: unrotated SD signal buffer in TD Q11 */ const Word16 subframe_len, /* i : subframe length per channel */ const IVAS_OUTPUT_SETUP hTransSetup, /* i : format for rotation */ const EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ const Word16 subframe_idx /* i : subframe index */ ) { - Word16 i, j; + Word16 i, j, offset; Word16 nchan, index_lfe; Word16 ch_in, ch_in_woLFE, ch_out, ch_out_woLFE; Word16 azimuth, elevation; Word32 azimuth_fx, elevation_fx; - Word32 tmp = Q31_BY_SUB_FRAME_240; + Word32 tmp = Q31_BY_SUB_FRAME_240; // Q31 move32(); Word32 out_temp; Word32 tmp_gains_fx[MAX_CICP_CHANNELS - 1]; @@ -1086,33 +1173,39 @@ void rotateFrame_sd( nchan = add( hTransSetup.nchan_out_woLFE, hTransSetup.num_lfe ); index_lfe = hTransSetup.index_lfe[0]; move16(); + offset = imult1616( subframe_idx, subframe_len ); SWITCH( subframe_len ) { case L_SUBFRAME_48k: tmp = Q31_BY_SUB_FRAME_240; + move32(); BREAK; case L_SUBFRAME_32k: tmp = Q31_BY_SUB_FRAME_180; + move32(); BREAK; case L_SUBFRAME_16k: tmp = Q31_BY_SUB_FRAME_80; + move32(); BREAK; case L_SUBFRAME_8k: tmp = Q31_BY_SUB_FRAME_40; + move32(); BREAK; default: BREAK; } - move32(); + FOR( i = 0; i < subframe_len; i++ ) { - cross_fade_fx[i] = UL_Mpy_32_32( i, tmp ); + cross_fade_fx[i] = UL_Mpy_32_32( i, tmp ); // Q31 + move32(); } FOR( ch_in = 0; ch_in < nchan; ch_in++ ) { /* zero output and gain buffers */ - set_val_Word32( &output_tmp_fx[ch_in][subframe_idx * subframe_len], 0, subframe_len ); + set_val_Word32( &output_tmp_fx[ch_in][offset], 0, subframe_len ); set_val_Word32( gains_prev_fx[ch_in], 0, nchan ); set_val_Word32( gains_fx[ch_in], 0, nchan ); /* set gains to passthrough by default */ @@ -1127,17 +1220,25 @@ void rotateFrame_sd( } /* input channel index without LFE */ - ch_in_woLFE = ( ch_in >= index_lfe ) ? sub( ch_in, 1 ) : ch_in; + IF( GE_16( ch_in, index_lfe ) ) + { + ch_in_woLFE = sub( ch_in, 1 ); + } + ELSE + { + ch_in_woLFE = ch_in; + move16(); + } /* gains for previous subframe rotation */ - rotateAziEle_fx( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ), (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ), &azimuth, &elevation, hCombinedOrientationData->Rmat_prev_fx, hTransSetup.is_planar_setup ); + rotateAziEle_fx( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), &azimuth, &elevation, hCombinedOrientationData->Rmat_prev_fx, hTransSetup.is_planar_setup ); test(); test(); - IF( hEFAPdata != NULL && ( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) != azimuth || (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) != elevation ) ) + IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( (Word32) azimuth, Q22 ); - elevation_fx = L_shl( (Word32) elevation, Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); @@ -1150,19 +1251,29 @@ void rotateFrame_sd( } /* output channel index without LFE */ - ch_out_woLFE = ( ch_out >= index_lfe ) ? sub( ch_out, 1 ) : ch_out; + IF( GE_16( ch_out, index_lfe ) ) + { + ch_out_woLFE = sub( ch_out, 1 ); + } + ELSE + { + ch_out_woLFE = ch_out; + move16(); + } gains_prev_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 + move32(); } } /* gains for current subframe rotation */ - rotateAziEle_fx( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ), (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ), &azimuth, &elevation, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hTransSetup.is_planar_setup ); - - IF( hEFAPdata != NULL && ( (Word16) L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) != azimuth || (Word16) L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) != elevation ) ) + rotateAziEle_fx( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), &azimuth, &elevation, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hTransSetup.is_planar_setup ); + test(); + test(); + IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( (Word32) azimuth, Q22 ); - elevation_fx = L_shl( (Word32) elevation, Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); FOR( ch_out = 0; ch_out < nchan; ch_out++ ) @@ -1174,9 +1285,18 @@ void rotateFrame_sd( } /* output channel index without LFE */ - ch_out_woLFE = ( ch_out >= index_lfe ) ? sub( ch_out, 1 ) : ch_out; + IF( GE_16( ch_out, index_lfe ) ) + { + ch_out_woLFE = sub( ch_out, 1 ); + } + ELSE + { + ch_out_woLFE = ch_out; + move16(); + } gains_fx[ch_in][ch_out] = tmp_gains_fx[ch_out_woLFE]; // Q30 + move32(); } } } @@ -1192,10 +1312,11 @@ void rotateFrame_sd( { out_temp = output[ch_in][i]; move32(); - Word32 temp = Mpy_32_32( Mpy_32_32( ( cross_fade_fx[j] ), gains_fx[ch_in][ch_out] ), out_temp ); - Word32 temp1 = Mpy_32_32( Mpy_32_32( L_sub( ONE_IN_Q31, cross_fade_fx[j] ), gains_prev_fx[ch_in][ch_out] ), out_temp ); - output_tmp_fx[ch_out][i] = L_add( L_shl( L_add( temp, temp1 ), 1 ), output_tmp_fx[ch_out][i] ); - j++; + Word32 temp = Mpy_32_32( Mpy_32_32( ( cross_fade_fx[j] ), gains_fx[ch_in][ch_out] ), out_temp ); // Q10 + Word32 temp1 = Mpy_32_32( Mpy_32_32( L_sub( ONE_IN_Q31, cross_fade_fx[j] ), gains_prev_fx[ch_in][ch_out] ), out_temp ); // Q10 + output_tmp_fx[ch_out][i] = L_add( L_shl( L_add( temp, temp1 ), 1 ), output_tmp_fx[ch_out][i] ); // Q11 + move32(); + j = add( j, 1 ); } } } @@ -1211,7 +1332,7 @@ void rotateFrame_sd( /* copy to output */ FOR( ch_out = 0; ch_out < nchan; ch_out++ ) { - mvr2r_Word32( &output_tmp_fx[ch_out][subframe_idx * subframe_len], &output[ch_out][subframe_idx * subframe_len], subframe_len ); + mvr2r_Word32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); } pop_wmops(); @@ -1358,12 +1479,12 @@ void rotateFrame_sd( * Apply rotation to signals in Spherical Harmonic Domain and in CLDFB *------------------------------------------------------------------------*/ void rotateFrame_shd_cldfb( - Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part */ - Word32 Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part */ - Word32 Rmat[3][3], /* i : real-space rotation matrix */ - const Word16 nInChannels, /* i : number of channels */ - const Word16 numTimeSlots, /* i : number of time slots to process */ - const Word16 shd_rot_max_order /* i : split-order rotation method */ + Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part Qx -> Qx-1 */ + Word32 Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part Qx -> Qx-1 */ + Word32 Rmat[3][3], /* i : real-space rotation matrix Q30 */ + const Word16 nInChannels, /* i : number of channels */ + const Word16 numTimeSlots, /* i : number of time slots to process */ + const Word16 shd_rot_max_order /* i : split-order rotation method */ ) { Word16 n = 0; @@ -1374,6 +1495,15 @@ void rotateFrame_shd_cldfb( Word32 realRot[2 * HEADROT_ORDER + 1], imagRot[2 * HEADROT_ORDER + 1]; Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; Word32 temp1, temp2; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); assert( nInChannels == HEADROT_SHMAT_DIM && "Number of channels must be 16!" ); /* initialize rotation matrices with zeros */ @@ -1414,16 +1544,18 @@ void rotateFrame_shd_cldfb( { temp1 = Mpy_32_16_r( Cldfb_RealBuffer[m][i][iBand], SHrotmat[n][m] ); temp2 = Mpy_32_16_r( Cldfb_ImagBuffer[m][i][iBand], SHrotmat[n][m] ); - realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(exp_real + 14 - 15) - imagRot[n - m1] = L_add( temp2, imagRot[n - m1] ); // Q(exp_im + 14 - 15) + realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(x + 14 - 15) + move32(); + imagRot[n - m1] = L_add( temp2, imagRot[n - m1] ); // Q(x + 14 - 15) + move32(); } } /* write back the result */ FOR( n = m1; n < m2; n++ ) { - Cldfb_RealBuffer[n][i][iBand] = realRot[n - m1]; + Cldfb_RealBuffer[n][i][iBand] = realRot[n - m1]; // Qx - 1 move32(); - Cldfb_ImagBuffer[n][i][iBand] = imagRot[n - m1]; + Cldfb_ImagBuffer[n][i][iBand] = imagRot[n - m1]; // Qx - 1 move32(); } m1 = m2; @@ -1456,8 +1588,10 @@ void rotateFrame_shd_cldfb( { FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { - Cldfb_RealBuffer[0][j][k] = L_shr( Cldfb_RealBuffer[0][j][k], 1 ); - Cldfb_ImagBuffer[0][j][k] = L_shr( Cldfb_ImagBuffer[0][j][k], 1 ); + Cldfb_RealBuffer[0][j][k] = L_shr( Cldfb_RealBuffer[0][j][k], 1 ); // Qx - 1 + move32(); + Cldfb_ImagBuffer[0][j][k] = L_shr( Cldfb_ImagBuffer[0][j][k], 1 ); // Qx - 1 + move32(); } } return; @@ -1671,13 +1805,13 @@ void rotateFrame_sd_cldfb( *------------------------------------------------------------------------*/ void rotateFrame_sd_cldfb_fixed( - Word32 Rmat_fx[3][3], /* i : real-space rotation matrix (Q30) */ - Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part */ - Word32 Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part */ - const IVAS_OUTPUT_SETUP_HANDLE hOutputSetup, /* i : output format setup number of channels */ - const EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ - const Word16 numTimeSlots, /* i : number of time slots to process */ - const Word16 nb_band /* i : number of CLDFB bands to process */ + Word32 Rmat_fx[3][3], /* i : real-space rotation matrix (Q30) */ + Word32 Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain real part Qx */ + Word32 Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: unrotated HOA3 signal buffer in cldfb domain imag part Qx */ + const IVAS_OUTPUT_SETUP_HANDLE hOutputSetup, /* i : output format setup number of channels */ + const EFAP_HANDLE hEFAPdata, /* i : EFAP structure */ + const Word16 numTimeSlots, /* i : number of time slots to process */ + const Word16 nb_band /* i : number of CLDFB bands to process */ ) { Word16 iBlock, iBand, m, n; @@ -1693,12 +1827,15 @@ void rotateFrame_sd_cldfb_fixed( push_wmops( "rotateFrame_sd_cldfb" ); nInChannels = hOutputSetup->nchan_out_woLFE; + move16(); isPlanar = 1; + move16(); FOR( n = 0; n < nInChannels; n++ ) { IF( hOutputSetup->ls_elevation_fx[n] != 0 ) { isPlanar = 0; + move16(); BREAK; } } @@ -1706,16 +1843,17 @@ void rotateFrame_sd_cldfb_fixed( /* rotation of Euler angles */ FOR( n = 0; n < nInChannels; n++ ) { - rotateAziEle_fx( (Word16) L_shr( hOutputSetup->ls_azimuth_fx[n], Q22 ), (Word16) L_shr( hOutputSetup->ls_elevation_fx[n], Q22 ), &azimuth, &elevation, Rmat_fx, isPlanar ); - IF( hEFAPdata != NULL && ( (Word16) L_shr( hOutputSetup->ls_azimuth_fx[n], Q22 ) != azimuth || (Word16) L_shr( hOutputSetup->ls_elevation_fx[n], Q22 ) != elevation ) ) + rotateAziEle_fx( extract_l( L_shr( hOutputSetup->ls_azimuth_fx[n], Q22 ) ), extract_l( L_shr( hOutputSetup->ls_elevation_fx[n], Q22 ) ), &azimuth, &elevation, Rmat_fx, isPlanar ); + test(); + test(); + IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hOutputSetup->ls_azimuth_fx[n], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hOutputSetup->ls_elevation_fx[n], Q22 ) ), elevation ) ) ) { - // efap_determine_gains( hEFAPdata, gains[n], azimuth, elevation, EFAP_MODE_EFAP ); efap_determine_gains_fx( hEFAPdata, gains_fx[n], L_shl( azimuth, Q22 ), L_shl( elevation, Q22 ), EFAP_MODE_EFAP ); } ELSE { set_l( gains_fx[n], 0, nInChannels ); - gains_fx[n][n] = 0x7fffffff; + gains_fx[n][n] = 0x7fffffff; // Q31 move32(); } } @@ -1730,22 +1868,20 @@ void rotateFrame_sd_cldfb_fixed( g1_fx = gains_fx[m][n]; move32(); p_realRot_fx = realRot_fx[n]; - move32(); p_imagRot_fx = imagRot_fx[n]; - move32(); - IF( GT_32( g1_fx, 0 ) ) + + IF( g1_fx > 0 ) { FOR( iBlock = 0; iBlock < numTimeSlots; iBlock++ ) { p_real_fx = Cldfb_RealBuffer[m][iBlock]; - move32(); p_imag_fx = Cldfb_ImagBuffer[m][iBlock]; - move32(); + FOR( iBand = 0; iBand < nb_band; iBand++ ) { - *( p_realRot_fx ) = L_add( *p_realRot_fx, Mpy_32_32( g1_fx, *( p_real_fx++ ) ) ); + *( p_realRot_fx ) = L_add( *p_realRot_fx, Mpy_32_32( g1_fx, *( p_real_fx++ ) ) ); // Qx move32(); - *( p_imagRot_fx ) = L_add( *p_imagRot_fx, Mpy_32_32( g1_fx, *( p_imag_fx++ ) ) ); + *( p_imagRot_fx ) = L_add( *p_imagRot_fx, Mpy_32_32( g1_fx, *( p_imag_fx++ ) ) ); // Qx move32(); p_realRot_fx++; p_imagRot_fx++; @@ -1758,15 +1894,13 @@ void rotateFrame_sd_cldfb_fixed( FOR( n = 0; n < nInChannels; n++ ) { p_realRot_fx = realRot_fx[n]; - move32(); p_imagRot_fx = imagRot_fx[n]; - move32(); + FOR( iBlock = 0; iBlock < numTimeSlots; iBlock++ ) { p_real_fx = Cldfb_RealBuffer[n][iBlock]; - move32(); p_imag_fx = Cldfb_ImagBuffer[n][iBlock]; - move32(); + FOR( iBand = 0; iBand < nb_band; iBand++ ) { *( p_real_fx++ ) = *( p_realRot_fx++ ); @@ -1819,14 +1953,19 @@ ivas_error ivas_external_orientation_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for external orientation memory\n" ) ); } ( *hExtOrientationData )->num_subframes = num_subframes; + move16(); /* Enable head rotation and disable external orientation as default */ FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { ( *hExtOrientationData )->enableHeadRotation[i] = 1; + move16(); ( *hExtOrientationData )->enableExternalOrientation[i] = 0; + move16(); ( *hExtOrientationData )->enableRotationInterpolation[i] = 0; + move16(); ( *hExtOrientationData )->numFramesToTargetOrientation[i] = 0; move16(); + ( *hExtOrientationData )->Quaternions[i] = identity; } return IVAS_ERR_OK; @@ -1870,7 +2009,7 @@ ivas_error ivas_external_orientation_open( * Deallocate external orientation handle *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_external_orientation_close( +void ivas_external_orientation_close_fx( EXTERNAL_ORIENTATION_HANDLE *hExtOrientationData /* i/o: external orientation handle */ ) { @@ -1918,6 +2057,7 @@ ivas_error ivas_combined_orientation_open( Word16 i; Word16 j; Word16 tmp_e = 0, tmp; + move16(); IVAS_QUATERNION identity; IVAS_VECTOR3 origo; identity.w_fx = ONE_IN_Q31; @@ -1947,9 +2087,9 @@ ivas_error ivas_combined_orientation_open( /* Initialization */ ( *hCombinedOrientationData )->num_subframes = num_subframes; move16(); - ( *hCombinedOrientationData )->interpolationCoefficient_fx = ONE_IN_Q30; + ( *hCombinedOrientationData )->interpolationCoefficient_fx = ONE_IN_Q30; // Q30 move32(); - ( *hCombinedOrientationData )->interpolationIncrement_fx = ONE_IN_Q30; + ( *hCombinedOrientationData )->interpolationIncrement_fx = ONE_IN_Q30; // Q30 move32(); IF( EQ_16( num_subframes, 1 ) ) { @@ -1962,10 +2102,14 @@ ivas_error ivas_combined_orientation_open( move16(); } ( *hCombinedOrientationData )->lrSwitchedNext = 0; + move16(); ( *hCombinedOrientationData )->lrSwitchedCurrent = 0; + move16(); ( *hCombinedOrientationData )->lrSwitchInterpVal_fx = 0; + move32(); ( *hCombinedOrientationData )->isInterpolationOngoing = FALSE; + move16(); ( *hCombinedOrientationData )->Quaternions_ext_interpolation_start = identity; ( *hCombinedOrientationData )->Quaternions_ext_interpolation_target = identity; @@ -1980,7 +2124,7 @@ ivas_error ivas_combined_orientation_open( FOR( j = 0; j < 3; j++ ) { set32_fx( ( *hCombinedOrientationData )->Rmat_fx[i][j], 0, 3 ); - ( *hCombinedOrientationData )->Rmat_fx[i][j][j] = ONE_IN_Q30; + ( *hCombinedOrientationData )->Rmat_fx[i][j][j] = ONE_IN_Q30; // Q30 move32(); } } @@ -2003,14 +2147,18 @@ ivas_error ivas_combined_orientation_open( ( *hCombinedOrientationData )->q_procChEneIIR = Q31; move16(); ( *hCombinedOrientationData )->isExtOrientationFrozen = 0; + move16(); ( *hCombinedOrientationData )->isHeadRotationFrozen = 0; + move16(); ( *hCombinedOrientationData )->subframe_idx = 0; move16(); tmp = BASOP_Util_Divide3232_Scale( fs, MAX_PARAM_SPATIAL_SUB_FRAMES_PER_SEC, &tmp_e ); ( *hCombinedOrientationData )->subframe_size = shr( tmp, sub( 15, tmp_e ) ); + move16(); // ( *hCombinedOrientationData )->subframe_size = (int16_t) ( fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); ( *hCombinedOrientationData )->cur_subframe_samples_rendered = 0; + move16(); return IVAS_ERR_OK; } @@ -2102,7 +2250,7 @@ ivas_error ivas_combined_orientation_open( *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_combined_orientation_close( +void ivas_combined_orientation_close_fx( COMBINED_ORIENTATION_HANDLE *hCombinedOrientationData /* i/o: combined orientation handle */ ) { @@ -2189,9 +2337,10 @@ ivas_error combine_external_and_head_orientations_rend( /* Head rotation data not available, use the freezed value or disable */ FOR( i = 0; i < hExtOrientationData->num_subframes; i++ ) { - IF( hExtOrientationData->enableHeadRotation[i] != 2 ) + IF( NE_16( hExtOrientationData->enableHeadRotation[i], 2 ) ) { hExtOrientationData->enableHeadRotation[i] = 0; + move16(); } } } @@ -2239,6 +2388,8 @@ ivas_error combine_external_and_head_orientations( move16(); /* Form combined orientations or return if no data available */ + test(); + test(); IF( hCombinedOrientationData == NULL ) { test(); @@ -2255,6 +2406,7 @@ ivas_error combine_external_and_head_orientations( { /* Reset the combined orientations and rotations */ hCombinedOrientationData->isInterpolationOngoing = FALSE; + move16(); hCombinedOrientationData->interpolationCoefficient_fx = ONE_IN_Q30; move32(); hCombinedOrientationData->interpolationIncrement_fx = ONE_IN_Q30; @@ -2264,6 +2416,7 @@ ivas_error combine_external_and_head_orientations( FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { hCombinedOrientationData->enableCombinedOrientation[i] = 0; + move16(); hCombinedOrientationData->Quaternions[i] = identity; hCombinedOrientationData->listenerPos[i] = origo; @@ -2290,35 +2443,46 @@ ivas_error combine_external_and_head_orientations( FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { /* Check for frozen external orientation */ - IF( hExtOrientationData->enableExternalOrientation[i] == 2 ) + IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 2 ) ) { - IF( hCombinedOrientationData->isExtOrientationFrozen != 1 ) + IF( NE_16( hCombinedOrientationData->isExtOrientationFrozen, 1 ) ) { hCombinedOrientationData->Quaternion_frozen_ext = hExtOrientationData->Quaternions[i]; hCombinedOrientationData->isExtOrientationFrozen = 1; + move16(); } } ELSE { hCombinedOrientationData->Quaternion_frozen_ext = identity; hCombinedOrientationData->isExtOrientationFrozen = 0; + move16(); } test(); - IF( hExtOrientationData->enableRotationInterpolation[i] == 1 && hExtOrientationData->enableExternalOrientation[i] > 0 ) + IF( EQ_16( hExtOrientationData->enableRotationInterpolation[i], 1 ) && hExtOrientationData->enableExternalOrientation[i] > 0 ) { test(); - IF( hCombinedOrientationData->isInterpolationOngoing == true && hCombinedOrientationData->interpolationCoefficient_fx <= ONE_IN_Q30 && are_orientations_same_fx( &hCombinedOrientationData->Quaternions_ext_interpolation_target, &hExtOrientationData->Quaternions[i] ) == true ) + test(); + IF( EQ_16( hCombinedOrientationData->isInterpolationOngoing, true ) && LE_32( hCombinedOrientationData->interpolationCoefficient_fx, ONE_IN_Q30 ) && EQ_16( are_orientations_same_fx( &hCombinedOrientationData->Quaternions_ext_interpolation_target, &hExtOrientationData->Quaternions[i] ), true ) ) { /* Continue interpolation */ - hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); + hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); - hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); + hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact = Q29; move16(); @@ -2326,24 +2490,31 @@ ivas_error combine_external_and_head_orientations( move16(); QuaternionSlerp_fx( hCombinedOrientationData->Quaternions_ext_interpolation_start, hCombinedOrientationData->Quaternions_ext_interpolation_target, hCombinedOrientationData->interpolationCoefficient_fx, &hCombinedOrientationData->Quaternions[i] ); hCombinedOrientationData->interpolationCoefficient_fx = L_add( hCombinedOrientationData->interpolationIncrement_fx, hCombinedOrientationData->interpolationCoefficient_fx ); + move32(); } ELSE { /* Stop interpolation or check for new interpolation */ hCombinedOrientationData->isInterpolationOngoing = FALSE; + move16(); hCombinedOrientationData->interpolationCoefficient_fx = ONE_IN_Q30; move32(); hCombinedOrientationData->interpolationIncrement_fx = ONE_IN_Q30; move32(); - external_target_interpolation( hExtOrientationData, hCombinedOrientationData, i ); + external_target_interpolation_fx( hExtOrientationData, hCombinedOrientationData, i ); Word16 l_shift = 0; move16(); l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); + move16(); } } ELSE @@ -2351,40 +2522,42 @@ ivas_error combine_external_and_head_orientations( /* Interpolation disabled, use the current orientation values */ /* Use the most recent external orientation */ - IF( hExtOrientationData->enableExternalOrientation[i] == 1 ) + IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 1 ) ) { hCombinedOrientationData->Quaternions[i] = hExtOrientationData->Quaternions[i]; } /* Use the freezed external orientation */ - ELSE IF( hExtOrientationData->enableExternalOrientation[i] == 2 ) + ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 2 ) ) { hCombinedOrientationData->Quaternions[i] = hCombinedOrientationData->Quaternion_frozen_ext; } } } } - + test(); IF( hExtOrientationData != NULL && headRotQuaternions != NULL ) { /* Combine head and external orientations */ FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { /* Check for frozen head rotation */ - IF( hExtOrientationData->enableHeadRotation[i] == 2 ) + IF( EQ_16( hExtOrientationData->enableHeadRotation[i], 2 ) ) { - IF( hCombinedOrientationData->isHeadRotationFrozen != 1 ) + IF( NE_16( hCombinedOrientationData->isHeadRotationFrozen, 1 ) ) { hCombinedOrientationData->Quaternion_frozen_head = headRotQuaternions[i]; hCombinedOrientationData->isHeadRotationFrozen = 1; + move16(); } } ELSE { hCombinedOrientationData->Quaternion_frozen_head = identity; hCombinedOrientationData->isHeadRotationFrozen = 0; + move16(); } /* Use the most recent head rotation */ - IF( hExtOrientationData->enableHeadRotation[i] == 1 ) + IF( EQ_16( hExtOrientationData->enableHeadRotation[i], 1 ) ) { IF( hExtOrientationData->enableExternalOrientation[i] > 0 ) { @@ -2396,7 +2569,7 @@ ivas_error combine_external_and_head_orientations( } } /* Use the freezed head rotation */ - ELSE IF( hExtOrientationData->enableHeadRotation[i] == 2 ) + ELSE IF( EQ_16( hExtOrientationData->enableHeadRotation[i], 2 ) ) { IF( hExtOrientationData->enableExternalOrientation[i] > 0 ) { @@ -2407,15 +2580,15 @@ ivas_error combine_external_and_head_orientations( hCombinedOrientationData->Quaternions[i] = hCombinedOrientationData->Quaternion_frozen_head; } } - /* Reset the combined orientations to identity */ - IF( hExtOrientationData->enableHeadRotation[i] == 0 && hExtOrientationData->enableExternalOrientation[i] == 0 ) + test(); + if ( hExtOrientationData->enableHeadRotation[i] == 0 && hExtOrientationData->enableExternalOrientation[i] == 0 ) { hCombinedOrientationData->Quaternions[i] = identity; } } } - + test(); IF( headRotQuaternions != NULL || hExtOrientationData != NULL ) { /* Calculate the combined rotation matrix */ @@ -2428,9 +2601,9 @@ ivas_error combine_external_and_head_orientations( /* Save the current orientations */ IF( hExtOrientationData != NULL ) { - IF( hExtOrientationData->enableExternalOrientation[hExtOrientationData->num_subframes - 1] > 0 ) + IF( hExtOrientationData->enableExternalOrientation[sub( hExtOrientationData->num_subframes, 1 )] > 0 ) { - hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[hExtOrientationData->num_subframes - 1]; + hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[sub( hExtOrientationData->num_subframes, 1 )]; } ELSE { @@ -2444,13 +2617,16 @@ ivas_error combine_external_and_head_orientations( hCombinedOrientationData->listenerPos[i] = listenerPos[i]; } } - /* Check if combined orientation is enabled */ + test(); + test(); + test(); IF( headRotQuaternions != NULL && hExtOrientationData == NULL ) { FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { hCombinedOrientationData->enableCombinedOrientation[i] = 1; + move16(); } } ELSE IF( headRotQuaternions == NULL && hExtOrientationData != NULL ) @@ -2460,10 +2636,12 @@ ivas_error combine_external_and_head_orientations( IF( hExtOrientationData->enableExternalOrientation[i] > 0 ) { hCombinedOrientationData->enableCombinedOrientation[i] = 1; + move16(); } ELSE { hCombinedOrientationData->enableCombinedOrientation[i] = 0; + move16(); } } } @@ -2471,13 +2649,16 @@ ivas_error combine_external_and_head_orientations( { FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { + test(); IF( hExtOrientationData->enableExternalOrientation[i] > 0 || ( hExtOrientationData->enableHeadRotation[i] > 0 ) ) { hCombinedOrientationData->enableCombinedOrientation[i] = 1; + move16(); } ELSE { hCombinedOrientationData->enableCombinedOrientation[i] = 0; + move16(); } } } @@ -2486,6 +2667,7 @@ ivas_error combine_external_and_head_orientations( FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { hCombinedOrientationData->enableCombinedOrientation[i] = 0; + move16(); } } @@ -2504,6 +2686,7 @@ ivas_error combine_external_and_head_orientations( FOR( Word16 k = 0; k < 3; k++ ) { hCombinedOrientationData->Rmat_fx[i][j][k] = L_shl( hCombinedOrientationData->Rmat_fx[i][j][k], sub( 62, shl( hCombinedOrientationData->Quaternions[i].q_fact, 1 ) ) ); // Q30 + move32(); } } } @@ -2514,10 +2697,15 @@ ivas_error combine_external_and_head_orientations( { l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); + move16(); } return IVAS_ERR_OK; } @@ -2774,7 +2962,7 @@ ivas_error combine_external_and_head_orientations( * *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void external_target_interpolation( +static void external_target_interpolation_fx( EXTERNAL_ORIENTATION_HANDLE hExtOrientationData, /* i : external orientation handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i/o: combined orientation handle */ const Word16 i /* i : subframe index */ @@ -2782,12 +2970,14 @@ static void external_target_interpolation( { /* Sanity check for number of frames */ hExtOrientationData->numFramesToTargetOrientation[i] = s_min( hExtOrientationData->numFramesToTargetOrientation[i], hCombinedOrientationData->maximumFramesToTargetOrientation ); + move16(); hExtOrientationData->numFramesToTargetOrientation[i] = s_max( hExtOrientationData->numFramesToTargetOrientation[i], 0 ); + move16(); /* Interpolate from the current orientation to the target orientation */ IF( hExtOrientationData->numFramesToTargetOrientation[i] > 0 ) { - IF( are_orientations_same_fx( &hCombinedOrientationData->Quaternions_ext_interpolation_target, &hExtOrientationData->Quaternions[i] ) == false ) + IF( EQ_16( are_orientations_same_fx( &hCombinedOrientationData->Quaternions_ext_interpolation_target, &hExtOrientationData->Quaternions[i] ), false ) ) { /* Target orientation is different from the previous target, update the values */ @@ -2795,11 +2985,11 @@ static void external_target_interpolation( hCombinedOrientationData->Quaternions_ext_interpolation_target = hExtOrientationData->Quaternions[i]; /* Use the most recent external orientation as the starting orientation */ - IF( hExtOrientationData->enableExternalOrientation[i] == 1 ) + IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 1 ) ) { - IF( GT_16( i, 0 ) ) + IF( i > 0 ) { - IF( hExtOrientationData->enableExternalOrientation[i - 1] == 0 ) + IF( hExtOrientationData->enableExternalOrientation[sub( i, 1 )] == 0 ) { IVAS_QUATERNION identity; identity.w_fx = ONE_IN_Q31; @@ -2812,13 +3002,13 @@ static void external_target_interpolation( move16(); hCombinedOrientationData->Quaternions_ext_interpolation_start = identity; } - ELSE IF( hExtOrientationData->enableExternalOrientation[i - 1] == 2 ) + ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[sub( i, 1 )], 2 ) ) { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_frozen_ext; } ELSE { - hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[i - 1]; + hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[sub( i, 1 )]; } } ELSE @@ -2826,7 +3016,7 @@ static void external_target_interpolation( hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_prev_extOrientation; } } - ELSE IF( hExtOrientationData->enableExternalOrientation[i] == 2 ) + ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i], 2 ) ) { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_frozen_ext; } @@ -2836,21 +3026,31 @@ static void external_target_interpolation( /* Calculate the interpolation increment and coefficient */ tmp = BASOP_Util_Divide3232_Scale_cadence( ONE_IN_Q30, L_shl( L_deposit_l( hExtOrientationData->numFramesToTargetOrientation[i] ), 2 ), &tmp_e ); hCombinedOrientationData->interpolationIncrement_fx = L_shl( tmp, sub( tmp_e, 31 ) ); /* Q30 */ + move32(); hCombinedOrientationData->interpolationCoefficient_fx = hCombinedOrientationData->interpolationIncrement_fx; move32(); } /* Interpolate */ hCombinedOrientationData->isInterpolationOngoing = TRUE; - hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx, hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact - Q29 ); + move16(); + hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.w_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.x_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.y_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_start.z_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact, Q29 ) ); // Q29 + move32(); - hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); - hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx, hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact - Q29 ); + hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.w_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.x_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.y_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); + hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx = L_shr( hCombinedOrientationData->Quaternions_ext_interpolation_target.z_fx, sub( hCombinedOrientationData->Quaternions_ext_interpolation_target.q_fact, Q29 ) ); // Q29 + move32(); hCombinedOrientationData->Quaternions_ext_interpolation_start.q_fact = Q29; move16(); @@ -2858,11 +3058,13 @@ static void external_target_interpolation( move16(); QuaternionSlerp_fx( hCombinedOrientationData->Quaternions_ext_interpolation_start, hCombinedOrientationData->Quaternions_ext_interpolation_target, hCombinedOrientationData->interpolationCoefficient_fx, &hCombinedOrientationData->Quaternions[i] ); hCombinedOrientationData->interpolationCoefficient_fx = L_add_sat( hCombinedOrientationData->interpolationCoefficient_fx, hCombinedOrientationData->interpolationIncrement_fx ); + move32(); } ELSE { /* Use the target orientation immediately */ hCombinedOrientationData->isInterpolationOngoing = FALSE; + move16(); hCombinedOrientationData->interpolationCoefficient_fx = ONE_IN_Q30; move32(); hCombinedOrientationData->interpolationIncrement_fx = ONE_IN_Q30; @@ -2958,6 +3160,7 @@ static bool are_orientations_same_fx( const IVAS_QUATERNION *orientation2 ) { bool orientationsAreSame = true; + move16(); Word32 error_margin_fx = 107374182; // 0.05f in Q31 move32(); Word16 error_margin_e = 0; @@ -2966,7 +3169,12 @@ static bool are_orientations_same_fx( move16(); move16(); move16(); + move16(); Word32 w_result = 0, x_result = 0, y_result = 0, z_result = 0; + move32(); + move32(); + move32(); + move32(); w_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->w_fx, sub( 31, orientation1->q_fact ), L_negate( orientation2->w_fx ), sub( 31, orientation2->q_fact ), &w_e ) ); x_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->x_fx, sub( 31, orientation1->q_fact ), L_negate( orientation2->x_fx ), sub( 31, orientation2->q_fact ), &x_e ) ); y_result = L_abs( BASOP_Util_Add_Mant32Exp( orientation1->y_fx, sub( 31, orientation1->q_fact ), L_negate( orientation2->y_fx ), sub( 31, orientation2->q_fact ), &y_e ) ); @@ -2975,12 +3183,17 @@ static bool are_orientations_same_fx( Word16 Flag_2 = BASOP_Util_Cmp_Mant32Exp( x_result, x_e, error_margin_fx, error_margin_e ); Word16 Flag_3 = BASOP_Util_Cmp_Mant32Exp( y_result, y_e, error_margin_fx, error_margin_e ); Word16 Flag_4 = BASOP_Util_Cmp_Mant32Exp( z_result, z_e, error_margin_fx, error_margin_e ); + + test(); + test(); + test(); IF( EQ_16( Flag_1, 1 ) || EQ_16( Flag_2, 1 ) || EQ_16( Flag_3, 1 ) || EQ_16( Flag_4, 1 ) ) { orientationsAreSame = false; + move16(); } return orientationsAreSame; @@ -3035,18 +3248,18 @@ static Word32 SHrot_p_fx( Word32 p = 0; move32(); - ri1 = SHrotmat[i + 1 + 1][1 + 1 + 1]; + ri1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( 1, 1 ), 1 )]; move16(); - rim1 = SHrotmat[i + 1 + 1][-1 + 1 + 1]; + rim1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( -1, 1 ), 1 )]; move16(); - ri0 = SHrotmat[i + 1 + 1][0 + 1 + 1]; + ri0 = SHrotmat[add( add( i, 1 ), 1 )][add( 1, 1 )]; move16(); IF( EQ_16( b, -l ) ) { - R_lm1_1 = R_lm1[a + l - 1][0]; + R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][0]; move16(); - R_lm1_2 = R_lm1[a + l - 1][2 * l - 2]; + R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; move16(); p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); } @@ -3054,13 +3267,13 @@ static Word32 SHrot_p_fx( { IF( EQ_16( b, l ) ) { - R_lm1_1 = R_lm1[a + l - 1][sub( shl( l, 1 ), 2 )]; - R_lm1_2 = R_lm1[a + l - 1][0]; + R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; + R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][0]; p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); } ELSE { - R_lm1_1 = R_lm1[a + l - 1][b + l - 1]; + R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( add( b, l ), 1 )]; move16(); p = L_mult0( ri0, R_lm1_1 ); } @@ -3200,8 +3413,9 @@ static Word32 SHrot_u_fx( const Word16 l, const Word16 m, const Word16 n, - Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], - Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM] ) + Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], // Q14 + Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM] // Q14 +) { return SHrot_p_fx( 0, l, m, n, SHrotmat, R_lm1 ); } @@ -3210,15 +3424,16 @@ static Word32 SHrot_v_fx( const Word16 l, const Word16 m, const Word16 n, - Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], - Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM] ) + Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], // Q14 + Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM] // Q14 +) { Word32 result; Word32 p0, p1; Word16 d; - IF( EQ_16( m, 0 ) ) + IF( m == 0 ) { p0 = SHrot_p_fx( 1, l, 1, n, SHrotmat, R_lm1 ); // Q28 p1 = SHrot_p_fx( -1, l, -1, n, SHrotmat, R_lm1 ); // Q28 @@ -3226,19 +3441,31 @@ static Word32 SHrot_v_fx( } ELSE { - IF( GT_16( m, 0 ) ) + IF( m > 0 ) { - d = ( m == 1 ) ? 1 : 0; - p0 = (Word32) SHrot_p_fx( 1, l, m - 1, n, SHrotmat, R_lm1 ); - p1 = (Word32) SHrot_p_fx( -1, l, -m + 1, n, SHrotmat, R_lm1 ); - result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[1 + d] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 + d = 0; + move16(); + if ( EQ_16( m, 1 ) ) + { + d = 1; + move16(); + } + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); + p1 = SHrot_p_fx( -1, l, add( negate( m ), 1 ), n, SHrotmat, R_lm1 ); + result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[add( 1, d )] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 } ELSE { - d = ( m == -1 ) ? 1 : 0; - p0 = (Word32) SHrot_p_fx( 1, l, m + 1, n, SHrotmat, R_lm1 ); - p1 = (Word32) SHrot_p_fx( -1, l, -m - 1, n, SHrotmat, R_lm1 ); - result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[1 + d] ); // Q27 + d = 0; + move16(); + if ( EQ_16( m, -1 ) ) + { + d = 1; + move16(); + } + p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); + p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); + result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[add( 1, d )] ); // Q27 } } return result; // Q27 @@ -3248,28 +3475,29 @@ static Word32 SHrot_w_fx( const Word16 l, const Word16 m, const Word16 n, - Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], - Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM] ) + Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], // Q14 + Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM] // Q14 +) { Word32 result, p0, p1; - IF( EQ_16( m, 0 ) ) + IF( m == 0 ) { printf( "ERROR should not be called\n" ); return 0; } ELSE { - IF( GT_16( m, 0 ) ) + IF( m > 0 ) { - p0 = SHrot_p_fx( 1, l, m + 1, n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, -m - 1, n, SHrotmat, R_lm1 ); + p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); + p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); result = L_add( p0, p1 ); } ELSE { - p0 = SHrot_p_fx( 1, l, m - 1, n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, -m + 1, n, SHrotmat, R_lm1 ); + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); + p1 = SHrot_p_fx( -1, l, sub( 1, m ), n, SHrotmat, R_lm1 ); result = L_sub( p0, p1 ); } } @@ -3287,9 +3515,9 @@ static Word32 SHrot_w_fx( *------------------------------------------------------------------------*/ void SHrotmatgen_fx( - Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], /* o : rotation matrix in SHD */ - Word32 Rmat[3][3], /* i : real-space rotation matrix */ - const Word16 order /* i : ambisonics order */ + Word16 SHrotmat[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM], /* o : rotation matrix in SHD Q14 */ + Word32 Rmat[3][3], /* i : real-space rotation matrix Q30 */ + const Word16 order /* i : ambisonics order */ ) { Word16 d = 0; @@ -3307,6 +3535,7 @@ void SHrotmatgen_fx( move16(); move16(); move16(); + move16(); Word32 u32_fx = 0, v32_fx = 0, w32_fx = 0; move32(); @@ -3327,16 +3556,25 @@ void SHrotmatgen_fx( move16(); SHrotmat[1][1] = extract_h( Rmat[1][1] ); + move16(); SHrotmat[1][2] = extract_h( Rmat[1][2] ); + move16(); SHrotmat[1][3] = extract_h( Rmat[1][0] ); + move16(); SHrotmat[2][1] = extract_h( Rmat[2][1] ); + move16(); SHrotmat[2][2] = extract_h( Rmat[2][2] ); + move16(); SHrotmat[2][3] = extract_h( Rmat[2][0] ); + move16(); SHrotmat[3][1] = extract_h( Rmat[0][1] ); + move16(); SHrotmat[3][2] = extract_h( Rmat[0][2] ); + move16(); SHrotmat[3][3] = extract_h( Rmat[0][0] ); + move16(); FOR( i = 0; i < 2 * 1 + 1; i++ ) { @@ -3353,22 +3591,33 @@ void SHrotmatgen_fx( set_val_Word16( &R_l[0][0], 0, HEADROT_SHMAT_DIM2 ); FOR( m = -l; m <= l; m++ ) { - d = ( m == 0 ) ? 1 : 0; - absm = (Word16) abs( m ); + d = 0; + move16(); + if ( m == 0 ) + { + d = 1; + move16(); + } + absm = extract_l( abs( m ) ); sql2mm2 = square_root30_q12[sub( imult1616( l, l ), imult1616( m, m ) )]; + move16(); sqdabsm = square_root30_q12[imult1616( add( 1, d ), imult1616( sub( add( l, absm ), 1 ), add( l, absm ) ) )]; + move16(); sqlabsm = square_root30_q12[imult1616( sub( l, add( absm, 1 ) ), sub( l, absm ) )]; + move16(); FOR( n = -l; n <= l; n++ ) { IF( EQ_16( abs_s( n ), l ) ) { sqdenom = square_root30_q12[imult1616( shl( l, 1 ), sub( shl( l, 1 ), 1 ) )]; + move16(); } ELSE { sqdenom = square_root30_q12[sub( imult1616( l, l ), imult1616( n, n ) )]; + move16(); } @@ -3376,23 +3625,24 @@ void SHrotmatgen_fx( v = imult1616( div_l( L_shl( (Word32) sqdabsm, 14 ), sqdenom ), sub( 1, shl( d, 1 ) ) ); // Q14 w = imult1616( div_l( L_shl( (Word32) sqlabsm, 14 ), sqdenom ), negate( sub( 1, d ) ) ); // Q14 - IF( NE_16( u, 0 ) ) + IF( u != 0 ) { result = SHrot_u_fx( l, m, n, SHrotmat, R_lm1 ); // Q28 u32_fx = Mpy_32_16_r( result, u ); // Q27 } - IF( NE_16( v, 0 ) ) + IF( v != 0 ) { result = SHrot_v_fx( l, m, n, SHrotmat, R_lm1 ); v32_fx = Mpy_32_16_r( result, v ); // Q26 } - IF( NE_16( w, 0 ) ) + IF( w != 0 ) { result = SHrot_w_fx( l, m, n, SHrotmat, R_lm1 ); w32_fx = Mpy_32_16_r( result, w ); // Q27 } // Addind and converting to 16 bit integer of Q14 - R_l[m + l][n + l] = extract_h( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ) * L_shl( 1, 4 ) ); // Q14 + R_l[add( m, l )][add( n, l )] = extract_h( L_shl( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ), 4 ) ); // Q14 + move16(); } } @@ -3400,7 +3650,7 @@ void SHrotmatgen_fx( { FOR( j = 0; j < 2 * l + 1; j++ ) { - SHrotmat[band_idx + i][band_idx + j] = R_l[i][j]; + SHrotmat[add( band_idx, i )][add( band_idx, j )] = R_l[i][j]; move16(); } } @@ -3580,11 +3830,14 @@ void ivas_combined_orientation_update_index( ELSE { hCombinedOrientationData->cur_subframe_samples_rendered = add( hCombinedOrientationData->cur_subframe_samples_rendered, samples_rendered ); + move16(); div_result = BASOP_Util_Divide3216_Scale( hCombinedOrientationData->cur_subframe_samples_rendered, hCombinedOrientationData->subframe_size, &exp ); hCombinedOrientationData->subframe_idx = add( hCombinedOrientationData->subframe_idx, shl( div_result, exp + 1 ) ); + move16(); hCombinedOrientationData->cur_subframe_samples_rendered = hCombinedOrientationData->cur_subframe_samples_rendered % hCombinedOrientationData->subframe_size; move16(); - hCombinedOrientationData->subframe_idx = s_min( hCombinedOrientationData->subframe_idx, hCombinedOrientationData->num_subframes - 1 ); + hCombinedOrientationData->subframe_idx = s_min( hCombinedOrientationData->subframe_idx, sub( hCombinedOrientationData->num_subframes, 1 ) ); + move16(); } } @@ -3658,9 +3911,13 @@ void ivas_combined_orientation_update_start_index( ELSE { hCombinedOrientationData->cur_subframe_samples_rendered_start = add( hCombinedOrientationData->cur_subframe_samples_rendered_start, samples_rendered ); + move16(); hCombinedOrientationData->subframe_idx_start = add( hCombinedOrientationData->subframe_idx_start, mult( hCombinedOrientationData->cur_subframe_samples_rendered, div_s( 1, hCombinedOrientationData->subframe_size ) ) ); + move16(); hCombinedOrientationData->cur_subframe_samples_rendered_start = hCombinedOrientationData->cur_subframe_samples_rendered % hCombinedOrientationData->subframe_size; /* No operator to calculate modulo*/ + move16(); hCombinedOrientationData->subframe_idx_start = s_min( hCombinedOrientationData->subframe_idx, sub( hCombinedOrientationData->num_subframes, 1 ) ); + move16(); } } diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 6a71233a3..c2aeaef5d 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -50,8 +50,8 @@ #ifdef IVAS_FLOAT_FIXED void ivas_sba_prototype_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder struct */ - Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real */ - Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag */ + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, real Q(q_cldfb[][])*/ + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Input audio in CLDFB domain, imag Q(q_cldfb[][])*/ Word16 q_cldfb[6][CLDFB_SLOTS_PER_SUBFRAME], const Word16 subframe /* i : Subframe to render */ ) @@ -75,14 +75,20 @@ void ivas_sba_prototype_renderer_fx( hSpar = st_ivas->hSpar; hDecoderConfig = st_ivas->hDecoderConfig; num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; + move16(); num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + move16(); numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + move16(); numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; + move16(); slot_idx_start = hSpar->slots_rendered; + move16(); - ///////scaling////////////// + /* Scaling up the real and imaginary buffers */ Word16 norm_q = 31; // to handle overflow + move16(); FOR( Word16 i = 0; i < 6; i++ ) { @@ -91,13 +97,14 @@ void ivas_sba_prototype_renderer_fx( norm_q = s_min( q_cldfb[i][j], norm_q ); } } - norm_q = 31 - norm_q - 2; // to handle overflow + norm_q = sub( sub( 31, norm_q ), 2 ); // to handle overflow Word16 q_inp[6][CLDFB_SLOTS_PER_SUBFRAME]; FOR( Word16 i = 0; i < 6; i++ ) { FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) { q_inp[i][j] = s_min( L_norm_arr( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX ), L_norm_arr( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX ) ); + move16(); norm_q = s_min( q_inp[i][j], norm_q ); } } @@ -105,19 +112,23 @@ void ivas_sba_prototype_renderer_fx( { FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) { - // q_inp[i][j] = s_min(L_norm_arr(inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX), L_norm_arr(inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX)); - scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, norm_q - 2 ); - scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, norm_q - 2 ); - q_cldfb[i][j] = q_cldfb[i][j] + norm_q - 2; + scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); + scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); + q_cldfb[i][j] = sub( add( q_cldfb[i][j], norm_q ), 2 ); + move16(); } } - /////////////////// - IF( st_ivas->nchan_transport == 1 ) + + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { firstInCh = 0; inChEnd = 1; firstOutCh = 0; outChEnd = 1; + move16(); + move16(); + move16(); + move16(); } ELSE /* 2 TC */ { @@ -125,6 +136,10 @@ void ivas_sba_prototype_renderer_fx( inChEnd = 2; firstOutCh = 1; outChEnd = 2; + move16(); + move16(); + move16(); + move16(); } /* Apply mixing matrix */ @@ -132,8 +147,7 @@ void ivas_sba_prototype_renderer_fx( { /* determine SPAR parameters FOR this time slot */ md_idx = hSpar->render_to_md_map[ts + slot_idx_start]; - // delete below - // floatToFixed_arr( hSpar->hFbMixer->cldfb_cross_fade, hSpar->hFbMixer->cldfb_cross_fade_fx, Q15, CLDFB_NO_COL_MAX ); + move16(); ivas_spar_get_parameters_fx( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat_fx ); @@ -144,26 +158,26 @@ void ivas_sba_prototype_renderer_fx( Word32 cldfb_par_fx; ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; - // delete below - // FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) - //{ - // floatToFixed_arrL( bin2band->pp_cldfb_weights_per_spar_band[idx], bin2band->pp_cldfb_weights_per_spar_band_fx[idx], Q31, IVAS_MAX_NUM_FB_BANDS ); - //} FOR( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { out_re_fx[out_ch] = 0; + move32(); out_im_fx[out_ch] = 0; + move32(); FOR( in_ch = firstInCh; in_ch < inChEnd; in_ch++ ) { - IF( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap FOR the CLDFB bands */ + IF( LT_16( cldfb_band, CLDFB_PAR_WEIGHT_START_BAND ) ) /* tuning parameter, depends on how much SPAR Filters overlap FOR the CLDFB bands */ { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; + move16(); cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // q30 + move32(); } ELSE { cldfb_par_fx = 0; + move32(); FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ @@ -173,6 +187,8 @@ void ivas_sba_prototype_renderer_fx( out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j]; out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // q30+q_cldfb[i][j + move32(); + move32(); } } @@ -181,17 +197,26 @@ void ivas_sba_prototype_renderer_fx( { inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // q30+q_cldfb[i][j]; + q1 //to keep constat q to entire buffer inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); + move32(); + move32(); } } /* Update mixing matrices */ - IF( ( ( slot_idx_start + ts + 1 ) == hSpar->num_slots ) || ( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) != ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) ) + test(); + IF( EQ_16( add( add( slot_idx_start, ts ), 1 ), hSpar->num_slots ) || NE_16( shr( md_idx, 2 ), shr( hSpar->render_to_md_map[add( add( ts, slot_idx_start ), 1 )], 2 ) ) ) // shr is used in place of division by JBM_CLDFB_SLOTS_IN_SUBFRAME, ( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) != ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) { /* we have crossed an unadapted parameter sf border, update previous mixing matrices */ - Word16 md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME; - md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0; - hSpar->i_subframe++; - hSpar->i_subframe = min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + Word16 md_sf = shr( md_idx, 2 ); // md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME + if ( NE_16( num_md_sub_frames, MAX_PARAM_SPATIAL_SUBFRAMES ) ) + { + md_sf = 0; + move16(); + } + hSpar->i_subframe = add( hSpar->i_subframe, 1 ); + move16(); + hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + move16(); Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); @@ -203,7 +228,8 @@ void ivas_sba_prototype_renderer_fx( { FOR( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS]; + hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( b, imult1616( md_sf, IVAS_MAX_NUM_BANDS ) )]; + move32(); } } } @@ -212,37 +238,46 @@ void ivas_sba_prototype_renderer_fx( /* Create prototypes */ - IF( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { FOR( ts = 0; ts < hSpar->subframe_nbslots[subframe]; ts++ ) { - IF( st_ivas->nchan_transport == 1 ) /* Dual mono */ + IF( EQ_16( st_ivas->nchan_transport, 1 ) ) /* Dual mono */ { Copy32( inRe_fx[0][ts], inRe_fx[1][ts], CLDFB_NO_CHANNELS_MAX ); Copy32( inIm_fx[0][ts], inIm_fx[1][ts], CLDFB_NO_CHANNELS_MAX ); } - ELSE IF( st_ivas->nchan_transport == 2 ) /* Opposing cardioids */ + ELSE IF( EQ_16( st_ivas->nchan_transport, 2 ) ) /* Opposing cardioids */ { Word32 temp_signal_fx[CLDFB_NO_CHANNELS_MAX]; FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + move32(); inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + move32(); inRe_fx[0][ts][idx] = temp_signal_fx[idx]; + move32(); } FOR( int idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + move32(); inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + move32(); inIm_fx[0][ts][idx] = temp_signal_fx[idx]; + move32(); } } } } - hSpar->subframes_rendered++; - hSpar->slots_rendered += hSpar->subframe_nbslots[subframe]; + hSpar->subframes_rendered = add( hSpar->subframes_rendered, 1 ); + move16(); + hSpar->slots_rendered = add( hSpar->slots_rendered, hSpar->subframe_nbslots[subframe] ); + move16(); pop_wmops(); return; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 221c47a33..ed8709301 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -13124,8 +13124,8 @@ void IVAS_REND_Close( closeHeadRotation( hIvasRend ); - ivas_external_orientation_close( &hIvasRend->hExternalOrientationData ); - ivas_combined_orientation_close( &hIvasRend->hCombinedOrientationData ); + ivas_external_orientation_close_fx( &hIvasRend->hExternalOrientationData ); + ivas_combined_orientation_close_fx( &hIvasRend->hCombinedOrientationData ); free( hIvasRend ); *phIvasRend = NULL; -- GitLab From ba6773858fea696388d20a61cc36e8e5fa548169 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 24 Jun 2024 13:59:27 +0530 Subject: [PATCH 61/63] clang formatting changes --- lib_dec/ivas_mct_dec.c | 318 +++++++++++++++++++-------------------- lib_rend/ivas_rom_rend.h | 2 +- 2 files changed, 159 insertions(+), 161 deletions(-) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 66fe480ef..235543277 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -2065,204 +2065,202 @@ static ivas_error ivas_mc_dec_reconfig_fx( } test(); - IF( st_ivas->hBinRendererTd != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) ) - { + IF( st_ivas->hBinRendererTd != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) ){ #ifdef FIX_1033_MEMORY_LEAK_OMASA - IF( EQ_16( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM, TRUE ) ) - { + IF( EQ_16( st_ivas->hBinRendererTd->HrFiltSet_p->ModelParams.modelROM, TRUE ) ){ #endif ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); - st_ivas->hHrtfTD = NULL; + st_ivas->hHrtfTD = NULL; #ifdef FIX_1033_MEMORY_LEAK_OMASA - } + } #endif - } + } - IF( st_ivas->hDiracDecBin != NULL ) - { - test(); - test(); - IF( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) - { - ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); - } - } + IF( st_ivas->hDiracDecBin != NULL ) + { + test(); + test(); + IF( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) && NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); + } + } - /* init necessary new renderers */ - test(); - test(); - test(); - test(); - test(); - IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + /* init necessary new renderers */ + test(); + test(); + test(); + test(); + test(); + IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) + { + IF( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + ELSE IF( st_ivas->hBinRendererTd == NULL && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) + { + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, &st_ivas->SrcInd[0], &st_ivas->num_src ) ), IVAS_ERR_OK ) ) + { + return error; + } + IF( EQ_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + { + IF( NE_32( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ), IVAS_ERR_OK ) ) { - IF( ( error = ivas_binRenderer_open_fx( st_ivas ) ) != IVAS_ERR_OK ) - { - return error; - } + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); } - ELSE IF( st_ivas->hBinRendererTd == NULL && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) - { - IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, &st_ivas->SrcInd[0], &st_ivas->num_src ) ), IVAS_ERR_OK ) ) - { - return error; - } - IF( EQ_16( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) - { - IF( NE_32( ( error = ivas_rend_initCrendWrapper( &st_ivas->hCrendWrapper ) ), IVAS_ERR_OK ) ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" ); - } - st_ivas->hCrendWrapper->hCrend = NULL; - st_ivas->hCrendWrapper->hHrtfCrend = NULL; - IF( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) - { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); - } - } - } - ELSE IF( st_ivas->hCrendWrapper == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) ) + st_ivas->hCrendWrapper->hCrend = NULL; + st_ivas->hCrendWrapper->hHrtfCrend = NULL; + IF( ( st_ivas->hCrendWrapper->hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL ) { - IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) - { - return error; - } - st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; - move32(); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend\n" ); } } - /* mono/stereo */ - ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) - { - /* nothing should happen here... */ - } - /* LS */ - ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) + } + ELSE IF( st_ivas->hCrendWrapper == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) ) + { + IF( NE_32( ( error = ivas_rend_openCrend( &( st_ivas->hCrendWrapper ), st_ivas->intern_config, st_ivas->hDecoderConfig->output_config, st_ivas->hRenderConfig, st_ivas->hSetOfHRTF, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) { + return error; } + st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; + move32(); } - /*-----------------------------------------------------------------* - * CLDFB instances - *-----------------------------------------------------------------*/ +} +/* mono/stereo */ +ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) +{ + /* nothing should happen here... */ +} +/* LS */ +ELSE IF( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) +{ +} +} +/*-----------------------------------------------------------------* + * CLDFB instances + *-----------------------------------------------------------------*/ - IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) - { - return error; - } +IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) ) +{ + return error; +} - /*-----------------------------------------------------------------* - * JBM TC buffers - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * JBM TC buffers + *-----------------------------------------------------------------*/ - { - Word16 tc_nchan_full_new; - DECODER_TC_BUFFER_HANDLE hTcBuffer; +{ + Word16 tc_nchan_full_new; + DECODER_TC_BUFFER_HANDLE hTcBuffer; - hTcBuffer = st_ivas->hTcBuffer; - tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); - tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - tc_nchan_allocate_new = tc_nchan_tc_new; + hTcBuffer = st_ivas->hTcBuffer; + tc_buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); + tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); + tc_nchan_allocate_new = tc_nchan_tc_new; + move16(); + tc_nchan_full_new = tc_nchan_tc_new; + move16(); + + test(); + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + { + tc_nchan_allocate_new = BINAURAL_CHANNELS * 2; move16(); - tc_nchan_full_new = tc_nchan_tc_new; + tc_nchan_full_new = tc_nchan_allocate_new; move16(); + } - test(); - test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) - { - tc_nchan_allocate_new = BINAURAL_CHANNELS * 2; - move16(); - tc_nchan_full_new = tc_nchan_allocate_new; - move16(); - } - - test(); - test(); - IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) - { - tc_nchan_full_new = 0; - move16(); - } - ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + test(); + test(); + IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) && NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + { + tc_nchan_full_new = 0; + move16(); + } + ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) + { + tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; + move16(); + tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; + move32(); + IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - tc_nchan_allocate_new = MC_PARAMUPMIX_MAX_INPUT_CHANS; - move16(); - tc_buffer_mode_new = TC_BUFFER_MODE_RENDERER; + tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; move32(); - IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) - { - tc_buffer_mode_new = TC_BUFFER_MODE_BUFFER; - move32(); - tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; - move16(); - tc_nchan_allocate_new = tc_nchan_tc_new; - move16(); - } - tc_nchan_full_new = tc_nchan_allocate_new; - move16(); - } - - /* reconfigure buffer */ - test(); - test(); - test(); - test(); - IF( NE_16( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || - NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) || - NE_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) ) - { - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ - IF( st_ivas->hSpatParamRendCom != NULL ) - { - st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + tc_nchan_tc_new = st_ivas->hDecoderConfig->nchan_out; move16(); - st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + tc_nchan_allocate_new = tc_nchan_tc_new; move16(); - st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; - move16(); - st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - move16(); - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } - ELSE IF( st_ivas->hParamMC != NULL ) + tc_nchan_full_new = tc_nchan_allocate_new; + move16(); + } + + /* reconfigure buffer */ + test(); + test(); + test(); + test(); + IF( NE_16( hTcBuffer->tc_buffer_mode, tc_buffer_mode_new ) || NE_16( hTcBuffer->nchan_transport_jbm, tc_nchan_tc_new ) || + NE_16( hTcBuffer->nchan_buffer_full, tc_nchan_full_new ) || NE_16( hTcBuffer->nchan_transport_internal, tc_nchan_allocate_new ) || + NE_16( tc_granularity_new, hTcBuffer->n_samples_granularity ) ) + { + IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode_new, tc_nchan_tc_new, tc_nchan_allocate_new, tc_nchan_full_new, tc_granularity_new ) ), IVAS_ERR_OK ) ) { - st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; - move16(); - st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; - move16(); - st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; - move16(); - st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; - move16(); - Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + return error; } } + /* transfer subframe info from central tc buffer to ParamMC or McMASA (DirAC) */ + IF( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); + st_ivas->hSpatParamRendCom->num_slots = st_ivas->hTcBuffer->num_slots; + move16(); + st_ivas->hSpatParamRendCom->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + move16(); + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } + ELSE IF( st_ivas->hParamMC != NULL ) + { + st_ivas->hParamMC->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + move16(); + st_ivas->hParamMC->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + move16(); + st_ivas->hParamMC->num_slots = st_ivas->hTcBuffer->num_slots; + move16(); + st_ivas->hParamMC->slots_rendered = st_ivas->hTcBuffer->slots_rendered; + move16(); + Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hParamMC->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + } +} - /*-----------------------------------------------------------------* - * floating-point output audio buffers - *-----------------------------------------------------------------*/ +/*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ - nchan_out_buff = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); +nchan_out_buff = ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, -1, -1 ); - IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) - { - return error; - } +IF( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) +{ + return error; +} #if 1 /*TODO: To be removed later*/ - if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif +if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) +{ return error; } +#endif +return error; +} #else static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index c70edf8c6..06590cee1 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -153,7 +153,7 @@ extern const Word32 defaultHRIR_right_avg_power_32kHz_fx[LR_IAC_LENGTH_NR_FC]; / extern const Word32 defaultHRIR_coherence_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-27*/ extern const Word32 defaultHRIR_left_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ extern const Word32 defaultHRIR_right_avg_power_16kHz_fx[LR_IAC_LENGTH_NR_FC]; /*Q-23*/ -#endif // IVAS_FLOAT_FIXED +#endif // IVAS_FLOAT_FIXED /*----------------------------------------------------------------------------------* * t-design and SN3D normalization table *----------------------------------------------------------------------------------*/ -- GitLab From 4770ac4d68d06a79fb1263db8738e84f37a10404 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 24 Jun 2024 15:16:08 +0530 Subject: [PATCH 62/63] Fix for issue 678: Amplitude issue in BWE during bitrate switching [x] With these changes, the high frequency burst observed at 22.8s is resolved. --- lib_com/ivas_prot_fx.h | 4 ++-- lib_com/ivas_sns_com_fx.c | 12 ++++++++++-- lib_dec/TonalComponentDetection_fx.c | 2 +- lib_dec/ivas_mdct_core_dec.c | 8 ++++---- lib_dec/ivas_stereo_switching_dec.c | 1 + lib_dec/tonalMDCTconcealment.c | 2 +- lib_dec/tonalMDCTconcealment_fx.c | 6 +++--- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 8ae9ce456..a96ef417a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -315,8 +315,8 @@ void sns_shape_spectrum_fx( const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ - const Word16 L_frame /* i : frame length */ -); + const Word16 L_frame, /* i : frame length */ + Word16 *length ); // ivas_stereo_eclvq_com_fx.c Word32 ECSQ_dequantize_gain_fx( diff --git a/lib_com/ivas_sns_com_fx.c b/lib_com/ivas_sns_com_fx.c index b08155749..12f546ef3 100644 --- a/lib_com/ivas_sns_com_fx.c +++ b/lib_com/ivas_sns_com_fx.c @@ -284,8 +284,8 @@ void sns_shape_spectrum_fx( const PsychoacousticParameters *pPsychParams, /* i : psychoacoustic parameters used to get the frequency bands */ const Word32 *scf_int, /* i : already interpolated SNS scalefactors */ const Word16 q_scf_int, /* i : Q of interpolated SNS scalefactors */ - const Word16 L_frame /* i : frame length */ -) + const Word16 L_frame, /* i : frame length */ + Word16 *length ) { Word16 i, n, k, tmp_k, bw, q_tmp = 0, shift, min_shift = 63; Word64 L64_tmp[L_FRAME48k]; @@ -311,6 +311,10 @@ void sns_shape_spectrum_fx( } } tmp_k = k; + if ( length != NULL ) + { + *length = k; + } q_tmp = sub( add( add( *q_spectrum, q_scf_int ), min_shift ), 32 ); IF( GT_16( q_tmp, 30 ) ) { @@ -340,6 +344,10 @@ void sns_shape_spectrum_fx( } } tmp_k = k; + if ( length != NULL ) + { + *length = k; + } q_tmp = sub( add( add( *q_spectrum, q_scf_int ), min_shift ), 32 ); IF( GT_16( q_tmp, 30 ) ) { diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 4a576bfe0..c3224a099 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -101,7 +101,7 @@ void ivas_DetectTonalComponents_fx( } #endif q_pScaledMdctSpectrum = sub( 31, lastMDCTSpectrum_exp ); - sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore ); + sns_shape_spectrum_fx( pScaledMdctSpectrum, &q_pScaledMdctSpectrum, psychParamsCurrent, sns_int_scf_fx, 16, nSamplesCore, NULL ); q_pScaledMdctSpectrum = add( q_pScaledMdctSpectrum, 1 ); Word16 tmp_e = sub( 31, q_pScaledMdctSpectrum ); nBands = psychParamsCurrent->nBands; diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 0b3973293..f3f268f35 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2430,7 +2430,7 @@ void ivas_mdct_core_tns_ns_fx( x_e[ch][k] = sub( 31, q_x ); Word16 q_sns_int_scf; - Word16 q_2; + Word16 q_2, length; q_sns_int_scf = add( 16 - 1, getScaleFactor32( sns_int_scf_fx, FDNS_NPTS ) ); // q_sns_int_scf -= 1; FOR( Word16 c = 0; c < FDNS_NPTS; c++ ) @@ -2438,15 +2438,15 @@ void ivas_mdct_core_tns_ns_fx( sns_int_scf_fx[c] = L_shl( sns_int_scf_fx[c], q_sns_int_scf - 16 ); } q_2 = q_x; - sns_shape_spectrum_fx( x_fx[ch][k], &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, q_sns_int_scf, st->hTcxCfg->psychParamsCurrent->nBins ); + sns_shape_spectrum_fx( x_fx[ch][k], &q_x, st->hTcxCfg->psychParamsCurrent, sns_int_scf_fx, q_sns_int_scf, st->hTcxCfg->psychParamsCurrent->nBins, &length ); IF( LT_16( q_2, add( q_x, 1 ) ) ) /*scaling to q_2*/ { - Scale_sig32( &x_fx[ch][k][0], st->hTcxCfg->psychParamsCurrent->nBins, q_2 - q_x - 1 ); + Scale_sig32( &x_fx[ch][k][0], length, q_2 - q_x - 1 ); q_x = q_2; } ELSE /*scaling to q_x+1*/ { - Scale_sig32( &x_fx[ch][k][0] + st->hTcxCfg->psychParamsCurrent->nBins, L_spec[ch] - st->hTcxCfg->psychParamsCurrent->nBins, q_x + 1 - q_2 ); + Scale_sig32( &x_fx[ch][k][0] + length, L_spec[ch] - length, q_x + 1 - q_2 ); q_x = add( q_x, 1 ); } x_e[ch][k] = sub( 31, q_x ); diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index b4df02cab..f3253d728 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -1700,6 +1700,7 @@ ivas_error stereo_memory_dec_fx( IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_TD ) ) { mvl2l( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); + Copy_Scale_sig32_16( st->hTcxDec->old_syn_Overl_32, st->hTcxDec->old_syn_Overl, L_FRAME16k / 2, add( st->Q_syn, 5 ) ); //(st->Qsyn - (11 - 16)) } set16_fx( st->hTcxDec->FBTCXdelayBuf, 0, 111 ); diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index a9b293e4e..8e2097d74 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -1698,7 +1698,7 @@ void TonalMdctConceal_whiten_noise_shape_ivas_fx( IF( GT_32( sum32_sat( scfs_for_shaping, FDNS_NPTS ), 0 ) ) { q_wns = sub( 31, noiseLevelPtr_exp ); - sns_shape_spectrum_fx( whitenend_noise_shape, &q_wns, psychParams, scfs_for_shaping, Q16, L_frame ); + sns_shape_spectrum_fx( whitenend_noise_shape, &q_wns, psychParams, scfs_for_shaping, Q16, L_frame, NULL ); Copy32( whitenend_noise_shape + start_idx, hFdCngCom->cngNoiseLevel, sub( stop_idx, start_idx ) ); hFdCngCom->cngNoiseLevelExp = sub( 30, q_wns ); diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index a41fd48f5..9ebbc635e 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -841,7 +841,7 @@ static void ivas_CalcPowerSpecAndDetectTonalComponents_fx( invScaleFactors_fx[i] = L_shl( invScaleFactors[i], add( 1, invScaleFactors_exp[i] ) ); // Q16 move32(); } - sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore ); + sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, invScaleFactors_fx, 16, hTonalMDCTConc->nSamplesCore, NULL ); power_spectrum_q = add( power_spectrum_q, 1 ); // sns_shape_spectrum(powerSpectrum, psychParamsCurrent, invScaleFactors, hTonalMDCTConc->nSamplesCore); // nBands = psychParamsCurrent->nBands; @@ -1290,7 +1290,7 @@ void TonalMDCTConceal_Detect_ivas_fx( sns_int_scf_fx[i] = L_shl( hTonalMDCTConc->secondLastBlockData.scaleFactors[i], add( 1, hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i] ) ); // Q16 move32(); } - sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, sns_int_scf_fx, 16, hTonalMDCTConc->nSamplesCore ); + sns_shape_spectrum_fx( powerSpectrum, &power_spectrum_q, psychParamsCurrent, sns_int_scf_fx, 16, hTonalMDCTConc->nSamplesCore, NULL ); } powerSpectrum_exp = getScaleFactor32( powerSpectrum, nSamples ); powerSpectrum_exp = sub( powerSpectrum_exp, 3 ); /*extra 3 bits of headroom for MA filter in getEnvelope*/ @@ -2944,7 +2944,7 @@ void TonalMDCTConceal_Apply_ivas_fx( move32(); } - sns_shape_spectrum_fx( powerSpectrum, &q_ps, psychParamsCurrent, scaleFactors, q_sf, hTonalMDCTConc->nSamplesCore ); + sns_shape_spectrum_fx( powerSpectrum, &q_ps, psychParamsCurrent, scaleFactors, q_sf, hTonalMDCTConc->nSamplesCore, NULL ); powerSpectrum_exp = sub( 31, add( q_ps, 1 ) ); -- GitLab From f7e12576a88ae14df92699f5ca02b6b0b449a35d Mon Sep 17 00:00:00 2001 From: Jan Kiene Date: Tue, 25 Jun 2024 08:09:41 +0200 Subject: [PATCH 63/63] activate ssnr measurement and rename anchor --- .gitlab-ci.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8e5b2b22..fb5645e8c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -214,7 +214,7 @@ stages: - if [ ! -d "$TESTV_DIR" ]; then mkdir -p $TESTV_DIR; fi - cp -r scripts/testv/* $TESTV_DIR/ -.ivas-pytest-mld-anchor: &ivas-pytest-mld-anchor +.ivas-pytest-anchor: &ivas-pytest-anchor stage: test needs: ["build-codec-linux-make"] timeout: "240 minutes" @@ -240,7 +240,7 @@ stages: ### run pytest - exit_code=0 - - python3 -m pytest $TEST_SUITE -v --create_cut --html=report.html --self-contained-html --junit-xml=report-junit.xml --mld --dut_encoder_path $DUT_ENCODER_PATH --dut_decoder_path $DUT_DECODER_PATH -n auto --testcase_timeout $testcase_timeout || exit_code=$? + - python3 -m pytest $TEST_SUITE -v --create_cut --html=report.html --self-contained-html --junit-xml=report-junit.xml --mld --ssnr --dut_encoder_path $DUT_ENCODER_PATH --dut_decoder_path $DUT_DECODER_PATH -n auto --testcase_timeout $testcase_timeout || exit_code=$? - zero_errors=$(cat report-junit.xml | grep -c 'errors="0"') || true - python3 scripts/parse_mld_xml.py report-junit.xml $MLD_ARTIFACT_NAME @@ -418,7 +418,7 @@ build-codec-linux-instrumented-make: # - USE_LTV=0 # - TEST_SUITE="$SHORT_TEST_SUITE" # - LEVEL_SCALING=1.0 -# <<: *ivas-pytest-mld-anchor +# <<: *ivas-pytest-anchor ivas-pytest-mld-dec: extends: @@ -429,7 +429,7 @@ ivas-pytest-mld-dec: - DUT_ENCODER_PATH=./IVAS_cod_ref - TEST_SUITE="$SHORT_TEST_SUITE" - LEVEL_SCALING=1.0 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor #ivas-pytest-mld-enc-dec-lev-10: # extends: @@ -439,7 +439,7 @@ ivas-pytest-mld-dec: # - USE_LTV=0 # - TEST_SUITE="$SHORT_TEST_SUITE" # - LEVEL_SCALING=0.3162 -# <<: *ivas-pytest-mld-anchor +# <<: *ivas-pytest-anchor ivas-pytest-mld-dec-lev-10: extends: @@ -450,7 +450,7 @@ ivas-pytest-mld-dec-lev-10: - DUT_ENCODER_PATH=./IVAS_cod_ref - TEST_SUITE="$SHORT_TEST_SUITE" - LEVEL_SCALING=0.3162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor #ivas-pytest-mld-enc-dec-lev+10: # extends: @@ -460,7 +460,7 @@ ivas-pytest-mld-dec-lev-10: # - USE_LTV=0 # - TEST_SUITE="$SHORT_TEST_SUITE" # - LEVEL_SCALING=3.162 -# <<: *ivas-pytest-mld-anchor +# <<: *ivas-pytest-anchor ivas-pytest-mld-dec-lev+10: extends: @@ -471,7 +471,7 @@ ivas-pytest-mld-dec-lev+10: - DUT_ENCODER_PATH=./IVAS_cod_ref - TEST_SUITE="$SHORT_TEST_SUITE" - LEVEL_SCALING=3.162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-enc-fx-dec-flt-interop: extends: @@ -482,7 +482,7 @@ ivas-pytest-mld-long-enc-fx-dec-flt-interop: - DUT_DECODER_PATH=./IVAS_dec_ref - TEST_SUITE="$SHORT_TEST_SUITE" - LEVEL_SCALING=1.0 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-enc-fx-dec-flt-lev-10-interop: extends: @@ -493,7 +493,7 @@ ivas-pytest-mld-long-enc-fx-dec-flt-lev-10-interop: - DUT_DECODER_PATH=./IVAS_dec_ref - TEST_SUITE="$SHORT_TEST_SUITE" - LEVEL_SCALING=0.3162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-enc-fx-dec-flt-lev+10-interop: extends: @@ -504,7 +504,7 @@ ivas-pytest-mld-long-enc-fx-dec-flt-lev+10-interop: - DUT_DECODER_PATH=./IVAS_dec_ref - TEST_SUITE="$SHORT_TEST_SUITE" - LEVEL_SCALING=3.162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-dec-msan: extends: @@ -539,7 +539,7 @@ ivas-pytest-mld-long-enc-dec: - USE_LTV=1 - TEST_SUITE="$LONG_TEST_SUITE" - LEVEL_SCALING=1.0 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-dec: extends: @@ -550,7 +550,7 @@ ivas-pytest-mld-long-dec: - DUT_ENCODER_PATH=./IVAS_cod_ref - TEST_SUITE="$LONG_TEST_SUITE" - LEVEL_SCALING=1.0 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-enc-dec-lev-10: extends: @@ -560,7 +560,7 @@ ivas-pytest-mld-long-enc-dec-lev-10: - USE_LTV=1 - TEST_SUITE="$LONG_TEST_SUITE" - LEVEL_SCALING=0.3162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-dec-lev-10: extends: @@ -571,7 +571,7 @@ ivas-pytest-mld-long-dec-lev-10: - DUT_ENCODER_PATH=./IVAS_cod_ref - TEST_SUITE="$LONG_TEST_SUITE" - LEVEL_SCALING=0.3162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-enc-dec-lev+10: extends: @@ -581,7 +581,7 @@ ivas-pytest-mld-long-enc-dec-lev+10: - USE_LTV=1 - TEST_SUITE="$LONG_TEST_SUITE" - LEVEL_SCALING=3.162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-pytest-mld-long-dec-lev+10: extends: @@ -592,7 +592,7 @@ ivas-pytest-mld-long-dec-lev+10: - DUT_ENCODER_PATH=./IVAS_cod_ref - TEST_SUITE="$LONG_TEST_SUITE" - LEVEL_SCALING=3.162 - <<: *ivas-pytest-mld-anchor + <<: *ivas-pytest-anchor ivas-smoke-test-saturation: extends: -- GitLab