From d184787e1e523db3ccbcb299e1be1fb056c354e0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 29 Jan 2026 17:02:15 +0100 Subject: [PATCH 1/9] HARM_BWE --- lib_com/ivas_prot_fx.h | 3 +- lib_com/options.h | 1 + lib_com/prot_fx.h | 5 + lib_dec/evs_dec_fx.c | 8 + lib_dec/ivas_core_dec_fx.c | 9 + lib_dec/swb_tbe_dec_fx.c | 236 ++++++++++++--- lib_enc/evs_enc_fx.c | 5 +- lib_enc/prot_fx_enc.h | 6 +- lib_enc/swb_tbe_enc_fx.c | 592 ++++++++++++++++++++++++++++--------- 9 files changed, 679 insertions(+), 186 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 4e380b17c..933aebfbb 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1865,6 +1865,7 @@ void stereoFdCngCoherence_fx( Word16 fft_exp ); +#ifndef HARM_BWE void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -1874,7 +1875,7 @@ void ivas_wb_tbe_dec_fx( Word16 *synth, /* o : WB synthesis/final synthesis */ Word16 *Q_synth ); - +#endif void GenShapedWBExcitation_ivas_fx( Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ diff --git a/lib_com/options.h b/lib_com/options.h index e11d5dffa..05f9cdff3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -102,6 +102,7 @@ #define FIX_2319_CLDFB_INIT_FLAGS /* FhG: basop issue 2319: init hs->flags during openCldfb(), to avoid reading of uninitialized memory */ #define FIX_BASOP_2357_OBJECT_EDIT_MSAN /* Nokia: basop issue 2357: initialize missing exponents in object edit */ #define FIX_BASOP_2354_MSAN_DIFF_Q_VALUE /* Nokia: Initialize Q value of diffuseness in rendering to Q30 */ +#define HARM_BWE /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3b93fda3b..699b23077 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5789,6 +5789,7 @@ void ivas_dequantizeSHBparams_fx_9_1( Word16 *MSFlag ); void fb_tbe_dec_fx( +#ifndef HARM_BWE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, @@ -5796,9 +5797,13 @@ void fb_tbe_dec_fx( Word16 hb_synth_exp ); void fb_tbe_dec_ivas_fx( +#endif Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, +#ifdef HARM_BWE + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ +#endif Word32 *hb_synth, /* o : high-band synthesis */ Word16 hb_synth_exp, Word16 *fb_synth_ref, diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index f320e323f..ecec2727f 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -408,7 +408,11 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { +#ifdef HARM_BWE + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); +#else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); +#endif } } ELSE IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) || @@ -843,7 +847,11 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { +#ifdef HARM_BWE + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); +#else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); +#endif } } Copy( hb_synth_fx, hBWE_TD->old_hb_synth_fx, output_frame ); /*Q15 - hb_synth_fx_exp*/ diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 9838195cc..623a6bca6 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1013,7 +1013,11 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ +#ifdef HARM_BWE + 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 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 ); +#endif } 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 ) { @@ -1077,7 +1081,12 @@ ivas_error ivas_core_dec_fx( /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { +#ifdef HARM_BWE + fb_tbe_dec_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, NULL, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); +#else + 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 ); +#endif } } ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || flag_bwe_bws ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index b9fb6f1b7..6767fe480 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -594,13 +594,18 @@ void ResetSHBbuffer_Dec_fx( /*--------------------------------------------------------------------------*/ /* CALLED FROM : */ /*==========================================================================*/ + +#ifdef HARM_BWE +void wb_tbe_dec_fx( +#else void ivas_wb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type Q0 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - const Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors Q15 */ - Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ +#endif + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 coder_type, /* i : coding type Q0 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc */ + const Word16 Q_exc, /* i : Q_exc factor */ + const Word16 voice_factors[], /* i : voicing factors Q15 */ + Word16 *synth, /* o : WB synthesis/final synthesis Q_synth */ Word16 *Q_synth ) { Word16 i; @@ -750,9 +755,18 @@ void ivas_wb_tbe_dec_fx( } ELSE { - /* de-quantization */ - Word16 ignore; - ivas_dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &ignore ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0 ); + } + ELSE + { +#endif + /* de-quantization */ + Word16 ignore; + ivas_dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &ignore ); + } } } ELSE @@ -835,9 +849,21 @@ void ivas_wb_tbe_dec_fx( /* From low band excitation, generate highband excitation */ Lmax = 0; move32(); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + } + } + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); + } } IF( Lmax == 0 ) { @@ -848,7 +874,16 @@ void ivas_wb_tbe_dec_fx( { Q_bwe_exc = norm_l( Lmax ); } - Q_bwe_exc = sub( Q_bwe_exc, 3 ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Q_bwe_exc = sub( Q_bwe_exc, 1 ); + } + ELSE +#endif + { + Q_bwe_exc = sub( Q_bwe_exc, 3 ); + } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); find_max_mem_wb( st_fx, &n_mem ); @@ -865,38 +900,82 @@ void ivas_wb_tbe_dec_fx( move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } - W_tmp = 0; - move64(); - IF( st_fx->element_mode > EVS_MONO ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { - tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - W_tmp = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + prev_pow = 0; + move32(); + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0_sat( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + } } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + ELSE +#endif { - W_tmp = W_mac_16_16( W_tmp, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16 + 1))*/ + W_tmp = 0; + move64(); + tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); + W_tmp = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + W_tmp = W_mac_16_16( W_tmp, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16 + 1))*/ + } + exp = W_norm( W_tmp ); + prev_pow = W_extract_h( W_shl( W_tmp, exp ) ); + exp = sub( add( add( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 1 ), exp ), 32 ); } - exp = W_norm( W_tmp ); - prev_pow = W_extract_h( W_shl( W_tmp, exp ) ); - exp = sub( add( add( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 1 ), exp ), 32 ); rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } +#endif + sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { - bwe_exc_extended_16[cnt] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); - move16(); + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } + + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + bwe_exc_extended_16[cnt] = round_fx( L_shl( bwe_exc_extended[cnt], sc ) ); + move16(); + } } Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, - hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, - bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); + } + ELSE +#endif + { + GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, + hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->state_lpc_syn_fx, coder_type, st_fx->element_mode, + bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, vf_modified, uv_flag, st_fx->igf ); + } curr_pow = 0; move32(); @@ -915,8 +994,16 @@ void ivas_wb_tbe_dec_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } - Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, - exp, &exp ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + } + ELSE +#endif + { + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, exp, &exp ); + } FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) { @@ -932,7 +1019,6 @@ void ivas_wb_tbe_dec_fx( /* Update SHB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - /* Adjust the subframe and frame gain of the synthesized shb signal */ /* Scale the shaped excitation */ ScaleShapedWB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, @@ -941,9 +1027,21 @@ void ivas_wb_tbe_dec_fx( max = 0; move16(); - FOR( i = 0; i < L_FRAME16k / 4; i++ ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + max = s_max( max, shaped_wb_excitation[i] ); /*Q0*/ + } + } + ELSE +#endif { - max = s_max( max, abs_s( shaped_wb_excitation[i] ) ); + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + max = s_max( max, abs_s( shaped_wb_excitation[i] ) ); + } } IF( max == 0 ) @@ -985,8 +1083,12 @@ void ivas_wb_tbe_dec_fx( } test(); - test(); - IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) +#ifdef HARM_BWE + IF( !st_fx->bfi && st_fx->prev_bfi ) +#else + test(); + IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) +#endif { IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) { @@ -1063,13 +1165,17 @@ void ivas_wb_tbe_dec_fx( FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_shb_fx[i] ); + } } FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) { if ( GT_16( abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ), max ) ) + { max = abs_s( hBWE_TD->state_lsyn_filt_dwn_shb_fx[i] ); + } } IF( EQ_32( st_fx->output_Fs, 32000 ) ) @@ -1178,10 +1284,21 @@ void ivas_wb_tbe_dec_fx( } ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { - Copy_Scale_sig_16_32_no_sat( synth, tmp_synL, L_FRAME48k, sub( Q11, Qx ) ); - interpolate_3_over_1_allpass_fx32( tmp_synL, L_FRAME16k, upsampled_synth_32fx, hBWE_TD->mem_resamp_HB_fx_32 ); - Copy_Scale_sig_32_16( hBWE_TD->mem_resamp_HB_fx_32, hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, Q11 ) ); - Copy_Scale_sig_32_16( upsampled_synth_32fx, synth, L_FRAME48k, sub( Qx, Q11 ) ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); + interpolate_3_over_1_allpass_fx( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB_fx ); + Copy( upsampled_synth, synth, L_FRAME48k ); + } + ELSE +#endif + { + Copy_Scale_sig_16_32_no_sat( synth, tmp_synL, L_FRAME48k, sub( Q11, Qx ) ); + interpolate_3_over_1_allpass_fx32( tmp_synL, L_FRAME16k, upsampled_synth_32fx, hBWE_TD->mem_resamp_HB_fx_32 ); + Copy_Scale_sig_32_16( hBWE_TD->mem_resamp_HB_fx_32, hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, Q11 ) ); + Copy_Scale_sig_32_16( upsampled_synth_32fx, synth, L_FRAME48k, sub( Qx, Q11 ) ); + } } } ELSE @@ -1238,7 +1355,7 @@ void ivas_wb_tbe_dec_fx( return; } - +#ifndef HARM_BWE void wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -1877,7 +1994,7 @@ void wb_tbe_dec_fx( return; } - +#endif /*======================================================================================*/ /* FUNCTION : void swb_tbe_dec_fx () */ @@ -1896,13 +2013,14 @@ void wb_tbe_dec_fx( /* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ /*--------------------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State *st_fx: : Decoder state structure */ +/* _ Decoder_State *st_fx: : Decoder state structure */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------------*/ /* CALLED FROM : RX */ /*======================================================================================*/ + void swb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -4635,7 +4753,9 @@ static void dequantizeSHBparams_fx_9_1( * * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module *-------------------------------------------------------------------*/ + void fb_tbe_dec_fx( +#ifndef HARM_BWE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, @@ -4690,9 +4810,13 @@ void fb_tbe_dec_fx( } void fb_tbe_dec_ivas_fx( +#endif Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, +#ifdef HARM_BWE + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ +#endif Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ Word16 hb_synth_exp, Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ @@ -4754,17 +4878,31 @@ void fb_tbe_dec_ivas_fx( { Copy_Scale_sig( fb_synth, fb_synth_ref, L_FRAME48k, sub( Q_fb_synth_ref, add( hb_synth_exp, 16 ) ) ); // scaling is required } - /* add the fb_synth component to the hb_synth component */ - /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ - FOR( i = 0; i < L_FRAME48k; i++ ) + +/* add the fb_synth component to the hb_synth component */ +#ifdef HARM_BWE + IF( st->element_mode == EVS_MONO ) { - // hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); - hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp - move16(); + FOR( i = 0; i < L_FRAME48k; i++ ) + { + hb_synth16[i] = add_sat( hb_synth16[i], fb_synth[i] ); + move16(); + } } + ELSE +#endif + { + FOR( i = 0; i < L_FRAME48k; i++ ) + { + hb_synth[i] = L_add( hb_synth[i], L_shl( fb_synth[i], Q11 ) ); // hb_synth_exp + move16(); + } + } + return; } + void tbe_read_bitstream_fx( Decoder_State *st_fx ) { diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 5f696e899..b6d47f23b 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -427,8 +427,11 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ +#ifdef HARM_BWEaa + wb_tbe_enc_ivas_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); +#else wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); - +#endif IF( EQ_16( st->codec_mode, MODE2 ) ) { tbe_write_bitstream_fx( st ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 30aa1498b..20a32694d 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -162,14 +162,14 @@ void fb_tbe_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc ); + const Word16 Q_fb_exc ); void fb_tbe_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ - Word16 Q_fb_exc, - Word16 Q_new_input ); + const Word16 Q_fb_exc, + const Word16 Q_new_input ); void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index c0af2d1e5..a6fcf90ef 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -8,7 +8,6 @@ #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#include "stl.h" #include "ivas_prot_fx.h" @@ -30,12 +29,17 @@ static void singlevectortest_gain_fx( const Word32 *inp, const Word16 dimen, con static void determine_gain_weights_fx( const Word32 *gain, Word16 *weights, const Word16 dims ); static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, Word16 *subgains, const Word16 extl ); - +#ifndef HARM_BWE static void QuantizeSHBsubgains_ivas_fx( Encoder_State *st_fx, Word16 subgains[], const Word16 extl ); +#endif +#ifdef HARM_BWE +static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); +#else static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind ); static void QuantizeSHBframegain_ivas_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); +#endif static Word16 closest_centroid_fx( const Word16 *data, const Word16 *weights, const Word16 *quantizer, const Word16 centroids, const Word16 length ); @@ -65,6 +69,15 @@ static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], W static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], const Word16 m ); +#ifdef HARM_BWE +static void Quant_BWE_LSF_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); + +static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, const Word16 Q_ener ); + +static void Quant_shb_res_gshape_fx( Encoder_State *st, Word16 shb_res_gshape_fx[] ); + +static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); +#else static void Quant_BWE_LSF_fx( Encoder_State *st_fx, const Word16 lsp_shb[], Word16 Q_lsfs[] ); static void Quant_BWE_LSF_ivas_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); @@ -80,6 +93,7 @@ static void Quant_shb_res_gshape_ivas_fx( Encoder_State *st, Word16 shb_res_gsha static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, const Word16 *lsp_shb_fx, Word16 *MA_lsp_shb_spacing, Word16 *frGainAttenuate, Word16 *frGainSmoothEn ); static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, Word16 *shb_frame_fx /* Q_in */, const Word16 *lpc_shb_fx /* Q12 */, const Word16 *lsp_shb_fx /* Q15 */, Word16 *MA_lsp_shb_spacing /* Q15 */, Word16 *frGainAttenuate /* Q0 */, Word16 *frGainSmoothEn /* Q0 */ ); +#endif /*-------------------------------------------------------------------* @@ -1196,7 +1210,11 @@ void wb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARM_BWE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind ); +#endif /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ @@ -1312,34 +1330,73 @@ void wb_tbe_enc_ivas_fx( k = 0; move16(); - FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { - L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); - hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); - move16(); - i--; - k++; + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r( L_tmp, hb_speech[j], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + } + } + ELSE +#endif + { + FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) + { + L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); + hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); + move16(); + i--; + k++; + } } } - autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); + } + ELSE +#endif + { + autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, ( ( NS2SA( INT_FS_12k8, 5000000L ) + L_SUBFR + L_FRAME ) * 5 / 16 ), win_lpc_hb_wb_ivas_fx, 0, 1 ); - /* Ensure R[0] isn't zero when entering Levinson-Durbin */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); + /* Ensure R[0] isn't zero when entering Levinson-Durbin */ + R_l[0] = s_max( R_l[0], 1 ); + move16(); + } E_LPC_lev_dur( R_h, R_l, lpc_wb_temp_fx, LepsP, LPC_SHB_ORDER_WB, NULL ); // Since 0th index will be 1 in floating point buffer, in fixed point one has to take norm of 0th index to identify the Q-factor Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); // Q12 - /* convert into lsps and calculate weights */ - FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { - lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 - move32(); - } + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_shr( L_deposit_h( lpc_wb_temp_fx[i] ), 1 ) ); + move32(); + } - lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + lpc2lsp_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } + ELSE +#endif + { + /* convert into lsps and calculate weights */ + FOR( i = 0; i <= LPC_SHB_ORDER_WB; i++ ) + { + lpc_wb_32_fx[i] = L_negate( L_deposit_h( shr( lpc_wb_temp_fx[i], 1 ) ) ); // Q27 + move32(); + } + lpc2lsp_ivas_fx( &lpc_wb_32_fx[1], lsp_wb_temp_fx, hBWE_TD->prev_lsp_wb_temp_fx, LPC_SHB_ORDER_WB ); + } FOR( i = 0; i < LPC_SHB_ORDER_WB; i++ ) { @@ -1464,8 +1521,17 @@ void wb_tbe_enc_ivas_fx( /* Quantization of LSFs */ i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ - - push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); +#ifdef HARM_BWE + IF( EQ_16( st_fx->codec_mode, MODE2 ) ) + { + hBWE_TD->lsf_WB = i; + move16(); + } + ELSE +#endif + { + push_indice( st_fx->hBstr, IND_SHB_LSF, i, NUM_BITS_WB_LSF ); + } Copy( wb_bwe_lsfvq_cbook_8bit_fx + i * LPC_SHB_ORDER_WB, lsp_wb, LPC_SHB_ORDER_WB ); lsp2lpc_fx( &lpc_wb[1], lsp_wb, hBWE_TD->prev_lpc_wb_fx, LPC_SHB_ORDER_WB ); @@ -1543,43 +1609,63 @@ void wb_tbe_enc_ivas_fx( prev_pow = 0; move32(); - Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); - /* Compare with the guard bits needed in the subsequent operations. - * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. - */ - IF( LT_16( Q_prev_pow, 3 ) ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); - move16(); + prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /* Q(2*st_fx->prev_Q_bwe_exc) */ } - Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); - move16(); + + Q_prev_pow = 0; + move32(); } ELSE +#endif { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + Q_prev_pow = norm_arr( hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_prev_pow, 3 ) ) { - shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( hBWE_TD->state_syn_shbexc_fx[i], 3 ); + move16(); + } + Q_prev_pow = shl_r( sub( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 3 ), 1 ); + move16(); + } + ELSE + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = hBWE_TD->state_syn_shbexc_fx[i]; + move16(); + } + Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); move16(); } - Q_prev_pow = shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ); - move16(); - } - IF( st_fx->element_mode > EVS_MONO ) - { tmp = sub( Q_prev_pow, 31 + 16 ); prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q_prev_pow*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ + + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + prev_pow = L_mac0( prev_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q_prev_pow */ + } } rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + } +#endif + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); FOR( i = 0; i < L_FRAME32k; i++ ) { @@ -1587,69 +1673,117 @@ void wb_tbe_enc_ivas_fx( move16(); } +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } +#endif Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); - GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, - hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, - vf_modified_fx, uv_flag, st_fx->igf ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); + } + ELSE +#endif + { + GenShapedWBExcitation_ivas_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, + hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, Q_bwe_exc_ext, hBWE_TD->bwe_seed, + vf_modified_fx, uv_flag, st_fx->igf ); + } curr_pow = 0; move32(); - Q_cur_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); - /* Compare with the guard bits needed in the subsequent operations. - * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. - */ - IF( LT_16( Q_cur_pow, 3 ) ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i + L_SHB_LAHEAD / 4], 3 ); + curr_pow = L_mac0( curr_pow, shaped_wb_excitation[i + L_SHB_LAHEAD / 4], shaped_wb_excitation[i + L_SHB_LAHEAD / 4] ); /* Q(2*Q_bwe_exc_ext) */ + } + + IF( GT_16( voice_factors[0], 24576 ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ + } + + Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( hBWE_TD->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + + FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + { + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } - Q_cur_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); + + Lscale = root_a_fx( Lscale, 31 - exp, &exp ); + L_tmp = Mult_32_16( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx( L_shl( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } ELSE +#endif { - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + Q_cur_pow = norm_arr( &shaped_wb_excitation[L_SHB_LAHEAD / 4], L_SHB_LAHEAD / 4 ); + /* Compare with the guard bits needed in the subsequent operations. + * Guard bits for L_SHB_LAHEAD / 4 (expression evaluates to 5) is 3. + */ + IF( LT_16( Q_cur_pow, 3 ) ) { - shaped_wb_exc_scale[i] = shaped_wb_excitation[i + L_SHB_LAHEAD / 4]; + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shr( shaped_wb_excitation[i + L_SHB_LAHEAD / 4], 3 ); + move16(); + } + Q_cur_pow = shl_r( sub( Q_bwe_exc_ext, 3 ), 1 ); move16(); } - Q_cur_pow = shl_r( Q_bwe_exc_ext, 1 ); - move16(); - } - IF( st_fx->element_mode > EVS_MONO ) - { + ELSE + { + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + shaped_wb_exc_scale[i] = shaped_wb_excitation[i + L_SHB_LAHEAD / 4]; + move16(); + } + Q_cur_pow = shl_r( Q_bwe_exc_ext, 1 ); + move16(); + } + tmp = sub( Q_cur_pow, 31 + 16 ); curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(Q_cur_pow)*/ - } - FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) - { - curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_cur_pow) */ - } - IF( GT_16( voice_factors[0], 24576 ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ - } + FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) + { + curr_pow = L_mac0( curr_pow, shaped_wb_exc_scale[i], shaped_wb_exc_scale[i] ); /* Q(Q_cur_pow) */ + } - Lscale = root_a_over_b_fx( curr_pow, Q_cur_pow, prev_pow, Q_prev_pow, &exp ); + IF( GT_16( voice_factors[0], 24576 ) ) + { + curr_pow = L_shr( curr_pow, 2 ); /* Q(Q_pow) */ + } - FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) - { - L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + Lscale = root_a_over_b_fx( curr_pow, Q_cur_pow, prev_pow, Q_prev_pow, &exp ); + + FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) + { + L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[i] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ + move16(); + } + + Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); + L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ + shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ move16(); } - Lscale = root_a_fx( Lscale, sub( 31, exp ), &exp ); - L_tmp = Mpy_32_16_1( Lscale, shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] ); /* Q(16-exp+Q_bwe_exc_ext) */ - shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc_ext */ - move16(); - /* Update WB excitation */ Copy( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD / 4 ); @@ -1753,7 +1887,11 @@ void wb_tbe_enc_ivas_fx( push_indice( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); /* Quantization of the subframe gain parameter */ +#ifdef HARM_BWE + QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl ); +#else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape, st_fx->extl ); +#endif } /* Compute the power of gains away from the peak gain after quantization */ @@ -1770,14 +1908,22 @@ void wb_tbe_enc_ivas_fx( EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); - /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) { L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); - GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = L_shl( Mpy_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ + } } pitBufAvg_fx = 0; @@ -1806,11 +1952,29 @@ void wb_tbe_enc_ivas_fx( } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ - GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, tmp ); /* Q18 */ + } IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) { - GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 21299 ); /* Q18 */ + } } /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ @@ -1826,33 +1990,70 @@ void wb_tbe_enc_ivas_fx( IF( st_fx->igf != 0 && EQ_16( st_fx->coder_type, VOICED ) ) { /*GainFrame *= 0.5f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 16384 ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 16384 ); + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 16384 ); + } } ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ { /*GainFrame *= 0.75f;*/ - GainFrame = Mpy_32_16_1( GainFrame, 24576 ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + GainFrame = Mult_32_16( GainFrame, 24576 ); + } + ELSE +#endif + { + GainFrame = Mpy_32_16_1( GainFrame, 24576 ); + } } /* Quantization of the frame gain parameter */ IF( st_fx->rf_mode ) { +#ifdef HARM_BWE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); +#endif } ELSE { +#ifdef HARM_BWE + QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); +#else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); +#endif } /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ - scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); - scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); - Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); +#ifdef HARM_BWE + IF( st_fx->element_mode > EVS_MONO ) +#endif + { + scale_sig( shaped_wb_excitation, ( L_FRAME16k + L_SHB_LAHEAD ) / 4, -1 ); + scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, -1 ); + Q_bwe_exc_ext = sub( Q_bwe_exc_ext, 1 ); + } + ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); - Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); +#ifdef HARM_BWE + IF( st_fx->element_mode > EVS_MONO ) +#endif + { + Scale_sig( hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, 1 ); + } hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; move16(); @@ -2098,7 +2299,11 @@ void swb_tbe_enc_fx( ELSE { /* LSF quantization (21 bits) */ +#ifdef HARM_BWE + Quant_BWE_LSF_fx( st_fx->hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); +#else Quant_BWE_LSF_fx( st_fx, lsf_shb_fx, lsf_shb_fx ); +#endif } /* space the lsfs to assert a minimum distance */ @@ -2744,7 +2949,11 @@ void swb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARM_BWE + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); +#else QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind ); +#endif /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation */ @@ -2933,7 +3142,9 @@ void swb_tbe_enc_ivas_fx( move16(); TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; +#ifndef HARM_BWE RF_ENC_HANDLE hRF = st_fx->hRF; +#endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; /* init and buffers set up */ @@ -3104,7 +3315,11 @@ void swb_tbe_enc_ivas_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ +#ifdef HARM_BWE + gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); +#else gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); +#endif test(); test(); @@ -3138,7 +3353,11 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ +#ifdef HARM_BWE + Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#else Quant_BWE_LSF_ivas_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#endif } /* space the lsfs to assert a minimum distance */ @@ -3312,7 +3531,11 @@ void swb_tbe_enc_ivas_fx( } shb_ener_sf_Q31 = Mult_32_16( shb_ener_sf_Q31, 102 /*0.003125f Q15*/ ); shb_ener_sf_Q31 = L_add( 1l /*1 Q0*/, shb_ener_sf_Q31 ); +#ifdef HARM_BWE + Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); +#else Quant_shb_ener_sf_ivas_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); +#endif /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ set16_fx( shb_res_fx, 0, L_FRAME16k ); @@ -3359,7 +3582,11 @@ void swb_tbe_enc_ivas_fx( move16(); } +#ifdef HARM_BWE + Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); +#else Quant_shb_res_gshape_ivas_fx( st_fx, shb_res_gshape_fx ); +#endif } ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) { @@ -4067,7 +4294,11 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the gain shape parameter */ +#ifdef HARM_BWE + QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); +#else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); +#endif /* Compute the power of gains away from the peak gain after quantization */ IF( st_fx->element_mode > EVS_MONO ) @@ -4359,6 +4590,9 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the frame gain parameter */ +#ifdef HARM_BWE + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); +#else IF( st_fx->rf_mode ) { QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); @@ -4367,6 +4601,7 @@ void swb_tbe_enc_ivas_fx( { QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); } +#endif IF( hStereoICBWE != NULL ) { @@ -5393,7 +5628,7 @@ static void QuantizeSHBsubgains_fx( return; } - +#ifndef HARM_BWE /*============================================================*/ /* FUNCTION : static void QuantizeSHBsubgains_ivas_fx() */ /*------------------------------------------------------------*/ @@ -5530,7 +5765,7 @@ static void QuantizeSHBsubgains_ivas_fx( return; } - +#endif /*-------------------------------------------------------------------* * Quant_shb_ener_sf_fx_fx() @@ -5539,6 +5774,7 @@ static void QuantizeSHBsubgains_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_fx( +#ifndef HARM_BWE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ Word16 Q_ener ) @@ -5595,9 +5831,10 @@ static void Quant_shb_ener_sf_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies Q_ener */ - Word16 Q_ener ) + const Word16 Q_ener ) { Word16 idxSubEner_fx; Word16 temp_shb_ener_sf_fx; @@ -5605,6 +5842,9 @@ static void Quant_shb_ener_sf_ivas_fx( Word32 L_tmp1, L_tmp; Word32 sum; Word16 tmp; +#ifdef HARM_BWE + Word16 Q_fac; +#endif TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; /* shb_ener_sf_fx[0] = log10(0.003125*shb_ener_sf[0:319]); */ @@ -5613,21 +5853,47 @@ static void Quant_shb_ener_sf_ivas_fx( exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); - exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ - L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ + exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ - tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ + tmp = round_fx( L_shl( L_tmp1, 30 - 14 ) ); /* tmp in Q12 */ - temp_shb_ener_sf_fx = 0; - move16(); - idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q11 */ + temp_shb_ener_sf_fx = 0; + move16(); + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 86, shl( 1, NUM_BITS_SHB_ENER_SF ) ); /* 86 = 0.042f in Q11 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q12 */ + + Q_fac = -Q10; + move16(); + } + ELSE +#endif + { + L_tmp1 = Mpy_32_16( exp, frac, 308 ); /* 308=LOG10(2) in Q10, so answer Ltmp in Q11 */ + + tmp = extract_l( L_tmp1 ); /* tmp in Q11 */ + + temp_shb_ener_sf_fx = 0; + move16(); + idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ + /* o: temp_shb_ener_sf_fx in Q11 */ + + Q_fac = -Q9; + move16(); + } /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ - L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q11+Q13+1 = Q25 */ - L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ + L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12/Q11+Q13+1 = Q26/Q25 */ +#ifdef HARM_BWE + L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ +#else + L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ +#endif + frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent */ L_tmp = Pow2( 14, frac ); *shb_ener_sf_Q31 = L_shl( L_tmp, add( sub( exp, 14 ), Q_ener ) ); /* In Q_ener */ move32(); @@ -5650,6 +5916,7 @@ static void Quant_shb_ener_sf_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_fx( +#ifndef HARM_BWE Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -5677,7 +5944,6 @@ static void Quant_shb_res_gshape_fx( return; } - /*-------------------------------------------------------------------* * Quant_shb_res_gshape_ivas_fx() * @@ -5685,6 +5951,7 @@ static void Quant_shb_res_gshape_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -5737,6 +6004,7 @@ static void Quant_shb_res_gshape_ivas_fx( /*==========================================================================*/ static void QuantizeSHBframegain_fx( +#ifndef HARM_BWE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -5904,6 +6172,7 @@ return; /*==========================================================================*/ static void QuantizeSHBframegain_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -5932,11 +6201,25 @@ static void QuantizeSHBframegain_ivas_fx( singlevectortest_gain_fx( GainFrame, 1, 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, &Q_GainFrame, SHBCB_FrameGain16_fx ); - test(); - IF( GT_64( W_deposit32_l( Q_GainFrame ), W_shl( W_mult_32_16( *GainFrame, 17367 ), 15 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) { - idxFrameGain--; - Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + { + idxFrameGain--; + Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + } + } + ELSE +#endif + { + test(); + IF( GT_64( W_deposit32_l( Q_GainFrame ), W_shl( W_mult_32_16( *GainFrame, 17367 ), 15 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ + { + idxFrameGain--; + Q_GainFrame = L_add( SHBCB_FrameGain16_fx[idxFrameGain], 0 ); /* Q18 */ + } } IF( EQ_16( st_fx->codec_mode, MODE2 ) ) @@ -6510,6 +6793,7 @@ static Word16 Find_LSF_grid_fx( * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ +#ifndef HARM_BWE static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, @@ -6632,13 +6916,20 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ -static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, - Word16 *shb_frame_fx /* Q_in */, - const Word16 *lpc_shb_fx /* Q12 */, - const Word16 *lsp_shb_fx /* Q15 */, - Word16 *MA_lsp_shb_spacing /* Q15 */, - Word16 *frGainAttenuate /* Q0 */, - Word16 *frGainSmoothEn /* Q0 */ ) +#endif + +#ifdef HARM_BWE +static void gainFrSmooth_En_fx( +#else +static void gainFrSmooth_En_ivas_fx( +#endif + Encoder_State *st_fx, + Word16 *shb_frame_fx /* Q_in */, + const Word16 *lpc_shb_fx /* Q12 */, + const Word16 *lsp_shb_fx /* Q15 */, + Word16 *MA_lsp_shb_spacing /* Q15 */, + Word16 *frGainAttenuate /* Q0 */, + Word16 *frGainSmoothEn /* Q0 */ ) { Word16 temp_shb_frame[L_FRAME16k + L_SHB_LAHEAD]; Word32 lsp_slow_evol_rate, lsp_fast_evol_rate; @@ -6686,8 +6977,18 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, /* estimate the mean square error in lsps from current frame to past frames */ tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); - lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); - lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO ) + { + lsp_slow_evol_rate = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); + lsp_fast_evol_rate = L_mac( lsp_fast_evol_rate, tempQ15_2, tempQ15_2 ); + } + ELSE +#endif + { + lsp_slow_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, L_mult( tempQ15_1, tempQ15_1 ), 0, &lsp_slow_evol_rate_e ); + lsp_fast_evol_rate = BASOP_Util_Add_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, L_mult( tempQ15_2, tempQ15_2 ), 0, &lsp_fast_evol_rate_e ); + } /* update the slow and fast interpolation lsps for next frame */ tempQ31 = L_mult( hBWE_TD->lsp_shb_slow_interpl_fx[i], 22937 /* 0.7f in Q15 */ ); @@ -6746,12 +7047,25 @@ static void gainFrSmooth_En_ivas_fx( Encoder_State *st_fx, } test(); - if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, INV_1000_Q31, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) +#ifdef HARM_BWE + IF( st_fx->element_mode == EVS_MONO && LT_32( lsp_slow_evol_rate, INV_1000_Q31 ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) { *frGainSmoothEn = 1; move16(); } + ELSE IF( st_fx->element_mode > EVS_MONO ) +#endif + { + test(); + if ( ( BASOP_Util_Cmp_Mant32Exp( lsp_slow_evol_rate, lsp_slow_evol_rate_e, INV_1000_Q31, 0 ) < 0 ) && ( BASOP_Util_Cmp_Mant32Exp( lsp_fast_evol_rate, lsp_fast_evol_rate_e, 2147484l /*0.001f in Q31*/, 0 ) < 0 ) ) + { + *frGainSmoothEn = 1; + move16(); + } + } } + + return; } #define MAXINT32 MAX_32 @@ -7123,7 +7437,7 @@ static void LVQQuant_BWE_LSF_fx( * * Quantize super highband spectral envolope *-------------------------------------------------------------------*/ - +#ifndef HARM_BWE static void Quant_BWE_LSF_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -7187,9 +7501,14 @@ static void Quant_BWE_LSF_fx( return; } +#endif +#ifdef HARM_BWE +static void Quant_BWE_LSF_fx( +#else static void Quant_BWE_LSF_ivas_fx( +#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 codec_mode, /* i : codec mode */ @@ -7276,7 +7595,7 @@ void fb_tbe_enc_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc ) + const Word16 Q_fb_exc ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -7305,10 +7624,7 @@ void fb_tbe_enc_fx( Copy_Scale_sig( new_input, input_fhb, L_FRAME48k, exp_temp ); - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS ) - L_FRAME48k / 2; IF( NE_16( st->last_extl, FB_TBE ) ) @@ -7400,8 +7716,8 @@ void fb_tbe_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate Q_new_input */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ - Word16 Q_fb_exc, - Word16 Q_new_input ) + const Word16 Q_fb_exc, + const Word16 Q_new_input ) { Word16 ratio; Word16 tmp_vec[L_FRAME48k]; @@ -7434,17 +7750,11 @@ void fb_tbe_enc_ivas_fx( exp_temp = add( exp_temp, Q_new_input ); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); } ELSE { - elliptic_bpf_48k_generic_fx( - st->element_mode, - 0, // IsUpsampled3 - input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); } test(); @@ -7541,6 +7851,7 @@ void fb_tbe_enc_ivas_fx( } /* ratio = (float)(1 << idxGain);*/ +#ifndef HARM_BWE IF( EQ_16( st->codec_mode, MODE2 ) ) { hBWE_TD->idxGain = idxGain; @@ -7548,10 +7859,22 @@ void fb_tbe_enc_ivas_fx( } ELSE { +#endif push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); +#ifndef HARM_BWE } +#endif + return; } + + +/*---------------------------------------------------------------------* + * tbe_write_bitstream() + * + * Write TBE bitstream. + *---------------------------------------------------------------------*/ + void tbe_write_bitstream_fx( Encoder_State *st_fx /* i/o: encoder state structure */ ) @@ -7578,7 +7901,6 @@ void tbe_write_bitstream_fx( ( ( EQ_16( st_fx->bwidth, SWB ) ) || ( EQ_16( st_fx->bwidth, FB ) ) ) ) { /* LSF coefficients */ - test(); IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) { @@ -7635,6 +7957,12 @@ void tbe_write_bitstream_fx( } +/*---------------------------------------------------------------------* + * TBEreset_enc() + * + * + *---------------------------------------------------------------------*/ + void TBEreset_enc_fx( TD_BWE_ENC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 last_core, /* i : last core */ -- GitLab From aeefdc0f11436f62815b20283992d9d5a284d26a Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 29 Jan 2026 17:15:23 +0100 Subject: [PATCH 2/9] clang-format --- lib_dec/evs_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index ecec2727f..6ecfa4093 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -409,7 +409,7 @@ ivas_error evs_dec_fx( IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { #ifdef HARM_BWE - fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); + fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); #else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); #endif -- GitLab From eac680a19a378feba5854a0606165c8cd1eba370 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 30 Jan 2026 11:08:49 +0100 Subject: [PATCH 3/9] updt --- lib_com/prot_fx.h | 3 +- lib_dec/swb_tbe_dec_fx.c | 86 ++++--- lib_enc/evs_enc_fx.c | 23 +- lib_enc/ivas_core_enc_fx.c | 4 + lib_enc/prot_fx_enc.h | 8 +- lib_enc/swb_tbe_enc_fx.c | 503 +++++++++++++++++++++++++++---------- 6 files changed, 456 insertions(+), 171 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 699b23077..ce33afa73 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5775,6 +5775,7 @@ void swb_tbe_dec_fx( Word16 *Q_synth, Word16 *pitch_buf ); +#ifndef HARM_BWE void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ @@ -5787,7 +5788,7 @@ void ivas_dequantizeSHBparams_fx_9_1( Word16 *Q_shb_res_gshape, /* o : Q14 */ Word16 *Q_mixFactors, /* o : Q15 */ Word16 *MSFlag ); - +#endif void fb_tbe_dec_fx( #ifndef HARM_BWE Decoder_State *st, /* i/o: encoder state structure */ diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 6767fe480..41d9e320a 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -2,22 +2,23 @@ EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ - #include #include "options.h" #include "rom_com.h" #include "prot_fx.h" #include "rom_dec.h" #include "stl.h" - #include "ivas_prot_fx.h" /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ +#ifdef HARM_BWE +static void dequantizeSHBparams_fx( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors, Word16 *MSFlag ); +#else static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors ); - +#endif static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2, Word16 *n_mem3 ); static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ); static void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ); @@ -27,15 +28,15 @@ static void Map_higher_LSF_fx( Word16 lsf_q[], const Word16 m, const Word16 grid static void Dequant_mirror_point_fx( const Word16 lsf_q[], const Word16 m_idx, Word16 *m ); static Word16 dotp_loc( const Word16 x[], const Word32 y[], const Word16 n ); static void find_max_mem_dec_m3( Decoder_State *st, Word16 *n_mem3 ); - -/* gain shape concealment code */ static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, Word32 *GainFrame ); + /*-------------------------------------------------------------------* * find_max_mem_dec() * * Find norm and max in TBE memories and past buffers *-------------------------------------------------------------------*/ + static void find_max_mem_dec( Decoder_State *st_fx, Word16 *n_mem, @@ -219,14 +220,17 @@ static void find_max_mem_dec( because of the Hilber transform and Q14 coeffs */ *n_mem3 = s_max( tempQ15, 0 ); move16(); - /* --------------------------------------------------------------*/ + + return; } + /*-------------------------------------------------------------------* * rescale_genSHB_mem_dec() * * Rescale genSHB memories *-------------------------------------------------------------------*/ + static void rescale_genSHB_mem_dec( Decoder_State *st_fx, Word16 sf ) @@ -276,9 +280,13 @@ static void rescale_genSHB_mem_dec( move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); + + return; } -void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) +static void find_max_mem_wb( + Decoder_State *st_fx, + Word16 *n_mem ) { Word16 i; Word16 max = 0; @@ -311,21 +319,18 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) FOR( i = 0; i < 7; i++ ) { - if ( GT_16( abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ), max ) ) max = abs_s( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx[i] ); } FOR( i = 0; i < 10; i++ ) { - if ( GT_16( abs_s( hBWE_TD->state_lpc_syn_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_lpc_syn_fx[i] ); } FOR( i = 0; i < 5; i++ ) { - if ( GT_16( abs_s( hBWE_TD->state_syn_shbexc_fx[i] ), max ) ) max = abs_s( hBWE_TD->state_syn_shbexc_fx[i] ); } @@ -341,10 +346,8 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) move16(); } - FOR( i = 0; i < 2; i++ ) { - if ( GT_32( L_abs( hBWE_TD->mem_csfilt_fx[i] ), Lmax ) ) Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } @@ -363,9 +366,14 @@ void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) move16(); *n_mem = s_max( *n_mem, 0 ); move16(); + + return; } -void rescale_genWB_mem( Decoder_State *st_fx, Word16 sf ) + +static void rescale_genWB_mem( + Decoder_State *st_fx, + Word16 sf ) { Word16 i; TD_BWE_DEC_HANDLE hBWE_TD; @@ -587,7 +595,7 @@ void ResetSHBbuffer_Dec_fx( /* _Word16 *synth o : WB synthesis/final synthesis Q_synth */ /*--------------------------------------------------------------------------*/ /* INPUT/OUTPUT ARGUMENTS : */ -/* Decoder_State *st_fx, i/o: decoder state structure */ +/* Decoder_State *st_fx, i/o: decoder state structure */ /*--------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ /* _ None */ @@ -640,8 +648,10 @@ void ivas_wb_tbe_dec_fx( Word16 f, inc; Word64 W_tmp; TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st_fx->hBWE_TD; set32_fx( &dummy2[0], 0, HILBERT_MEM_SIZE ); + IF( st_fx->bws_cnt == 0 ) { /* Initialization */ @@ -756,17 +766,13 @@ void ivas_wb_tbe_dec_fx( ELSE { #ifdef HARM_BWE - IF( st_fx->element_mode == EVS_MONO ) - { - dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0 ); - } - ELSE - { + /* de-quantization */ + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &j /*temp*/ ); +#else + /* de-quantization */ + Word16 ignore; + ivas_dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &ignore ); #endif - /* de-quantization */ - Word16 ignore; - ivas_dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &ignore ); - } } } ELSE @@ -1086,8 +1092,8 @@ void ivas_wb_tbe_dec_fx( #ifdef HARM_BWE IF( !st_fx->bfi && st_fx->prev_bfi ) #else - test(); - IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) + test(); + IF( !st_fx->bfi && ( st_fx->prev_bfi || st_fx->prev_use_partial_copy ) ) #endif { IF( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_wb_bwe_frame_pow_fx ) ) @@ -2328,10 +2334,14 @@ void swb_tbe_dec_fx( } ELSE { - /* de-quantization */ +#ifdef HARM_BWE + dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, + &shb_ener_sf_32, shb_res_gshape, &mixFactors, &j /*temp*/ ); +#else dequantizeSHBparams_fx_9_1( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, &shb_ener_sf_32, shb_res_gshape, &mixFactors ); +#endif Q_shb = 0; move16(); /* o: shb_ener_sf_32 in (2*Q_shb) */ @@ -3985,6 +3995,7 @@ static Word16 dotp_loc( Word16 i; Word32 suma; Word16 guarded_bits = find_guarded_bits_fx( n ); + suma = L_shr( Mpy_32_16_1( y[0], x[0] ), guarded_bits ); /*Qx + Qy - guarded_bits*/ FOR( i = 1; i < n; i++ ) @@ -3996,7 +4007,18 @@ static Word16 dotp_loc( return extract_h( suma ); /*Qx + Qy - 16*/ } + +/*-------------------------------------------------------------------* + * dequantizeSHBparams() + * + * Dequantize super highband spectral envolope, temporal gains and frame gain + *-------------------------------------------------------------------*/ + +#ifdef HARM_BWE +static void dequantizeSHBparams_fx( +#else void ivas_dequantizeSHBparams_fx_9_1( +#endif Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ Word32 extl_brate, /* i : extensiuon layer bitrate */ @@ -4428,7 +4450,7 @@ void ivas_dequantizeSHBparams_fx_9_1( return; } - +#ifndef HARM_BWE /*==========================================================================*/ /* FUNCTION : static void dequantizeSHBparams_fx_9_1 () */ /*--------------------------------------------------------------------------*/ @@ -4747,6 +4769,7 @@ static void dequantizeSHBparams_fx_9_1( return; } +#endif /*-------------------------------------------------------------------* * fb_tbe_dec() @@ -4879,7 +4902,7 @@ void fb_tbe_dec_ivas_fx( Copy_Scale_sig( fb_synth, fb_synth_ref, L_FRAME48k, sub( Q_fb_synth_ref, add( hb_synth_exp, 16 ) ) ); // scaling is required } -/* add the fb_synth component to the hb_synth component */ + /* add the fb_synth component to the hb_synth component */ #ifdef HARM_BWE IF( st->element_mode == EVS_MONO ) { @@ -5935,8 +5958,13 @@ void ivas_swb_tbe_dec_fx( ELSE { /* de-quantization */ +#ifdef HARM_BWE + dequantizeSHBparams_fx( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, + &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); +#else ivas_dequantizeSHBparams_fx_9_1( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); +#endif if ( hStereoICBWE != NULL ) { hStereoICBWE->MSFlag = MSFlag; diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index b6d47f23b..622f2225c 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -79,9 +79,6 @@ ivas_error evs_enc_fx( #endif ivas_error error; SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR; - // NOISE_EST_HANDLE hNoiseEst = st->hNoiseEst; - // VAD_HANDLE hVAD = st->hVAD; - // DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; LPD_state_HANDLE hLPDmem = st->hLPDmem; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; @@ -95,7 +92,6 @@ ivas_error evs_enc_fx( Q_shb_spch = 0; move16(); /* to avoid compiler warnings */ - /*------------------------------------------------------------------* * Initializiation *-----------------------------------------------------------------*/ @@ -176,19 +172,19 @@ ivas_error evs_enc_fx( /*---------------------------------------------------------------------* * Pre-processing *---------------------------------------------------------------------*/ + #ifdef FIX_I4_OL_PITCH - pre_proc( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &hq_core_type ); + pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, + &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #else pre_proc_fx( st, input_frame, old_inp_12k8, old_inp_16k, &inp, fr_bands, &Etot, &ener, pitch_orig, A, Aw, epsP_h, epsP_l, epsP, lsp_new, lsp_mid, &vad_hover_flag, &attack_flag, new_inp_resamp16k, &Voicing_flag, realBuffer, imagBuffer, &cldfbScale, hLPDmem->old_exc, &hq_core_type, &Q_new, &shift, Q_r ); #endif - // st->sharpFlag = sharpFlag; IF( EQ_16( st->mdct_sw, MODE2 ) ) { - Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ st->bits_frame_nominal = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ @@ -271,6 +267,7 @@ ivas_error evs_enc_fx( acelp_core_enc_fx( st, inp, ener, A, Aw, epsP_h, epsP_l, lsp_new, lsp_mid, vad_hover_flag, attack_flag, bwe_exc_extended, voice_factors, old_syn_12k8_16k, pitch_buf, &unbits, NULL, Q_new, shift ); } + /*---------------------------------------------------------------------* * HQ core encoding *---------------------------------------------------------------------*/ @@ -283,6 +280,7 @@ ivas_error evs_enc_fx( /*---------------------------------------------------------------------* * Postprocessing for ACELP/HQ core switching *---------------------------------------------------------------------*/ + core_switching_post_enc_fx( st, old_inp_12k8, old_inp_16k, A, shift, Q_new, st->Q_syn2, &Q_synth ); #ifndef FIX_I4_OL_PITCH IF( EQ_16( st->core, HQ_CORE ) ) @@ -447,6 +445,7 @@ ivas_error evs_enc_fx( * SWB(FB) TBE encoding * SWB BWE encoding *---------------------------------------------------------------------*/ + test(); IF( !st->Opt_SC_VBR && GE_32( st->input_Fs, 32000 ) ) { @@ -476,7 +475,11 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ +#ifdef HARM_BWE + fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc, 0 ); +#else fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc ); +#endif } IF( EQ_16( st->codec_mode, MODE2 ) ) @@ -649,9 +652,11 @@ static void initFrameHeader_loc( Encoder_State *st ) * * Write MODE2 frame header *-------------------------------------------------------------------*/ -static void writeFrameHeader_loc( Encoder_State *st ) -{ +static void writeFrameHeader_loc( + Encoder_State *st /* i/o: encoder state structure */ +) +{ BSTR_ENC_HANDLE hBstr = st->hBstr; IF( NE_32( st->core_brate, FRAME_NO_DATA ) ) diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 14230d021..ab3aadeb0 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -786,7 +786,11 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ +#ifdef HARM_BWE + fb_tbe_enc_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); +#else fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); +#endif } } } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 20a32694d..598301820 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -159,15 +159,17 @@ Word16 dtx_hangover_addition_fx( Word16 *rem_dtx_ho ); void fb_tbe_enc_fx( +#ifndef HARM_BWE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ const Word16 Q_fb_exc ); void fb_tbe_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ - const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ +#endif + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 new_input[], /* i : i speech at 48 kHz sample rate Q_new_input*/ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc*/ const Word16 Q_fb_exc, const Word16 Q_new_input ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index a6fcf90ef..6b0810af3 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -45,23 +45,27 @@ static Word16 closest_centroid_fx( const Word16 *data, const Word16 *weights, co static Word16 closest_centroid_lc_fx( const Word16 *data, const Word16 *quantizer, const Word16 centroids ); +#ifdef HARM_BWE +static void EstimateSHBFrameGain_fx( const Word16 element_mode, const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); +#else static void EstimateSHBFrameGain_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); static void EstimateSHBFrameGain_ivas_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); +#endif static void EstimateSHBGainShape_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, const Word16 *subwin, Word16 *n_subfr_saturation, const Flag limit_min_gain ); -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ); +static Word32 pow_off_pk_fx( const Word16 a[], const Word16 len, const Word16 step ); -static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ); +static Word32 pow_off_pk_corrected_fx( const Word16 a[], const Word16 len, const Word16 step ); static void find_max_mem_enc( Encoder_State *st_fx, Word16 *n_mem, Word16 *n_mem2 ); -static void rescale_genSHB_mem_enc( Encoder_State *st_fx, Word16 sf ); +static void rescale_genSHB_mem_enc( Encoder_State *st_fx, const Word16 sf ); static void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ); -static void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ); +static void rescale_genWB_mem_enc( Encoder_State *st_fx, const Word16 sf ); static void Quant_lower_LSF_fx( const Word16 lsf[], Word16 lsf_q[], Word16 lsf_idx[] ); @@ -218,9 +222,9 @@ void find_max_mem_enc( * Rescale genSHB memories *-------------------------------------------------------------------*/ -void rescale_genSHB_mem_enc( +static void rescale_genSHB_mem_enc( Encoder_State *st_fx, - Word16 sf ) + const Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -260,9 +264,14 @@ void rescale_genSHB_mem_enc( move16(); hBWE_TD->tbe_premph_fx = shl_r( hBWE_TD->tbe_premph_fx, sf ); move16(); + + return; } -void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ) + +static void find_max_mem_wb_enc( + Encoder_State *st_fx, + Word16 *n_mem ) { Word16 i; Word16 n_mem_32; @@ -337,9 +346,14 @@ void find_max_mem_wb_enc( Encoder_State *st_fx, Word16 *n_mem ) move16(); *n_mem = s_max( *n_mem, 0 ); move16(); + + return; } -void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) + +static void rescale_genWB_mem_enc( + Encoder_State *st_fx, + const Word16 sf ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -385,6 +399,8 @@ void rescale_genWB_mem_enc( Encoder_State *st_fx, Word16 sf ) hBWE_TD->mem_csfilt_fx[i] = L_shl( hBWE_TD->mem_csfilt_fx[i], sf ); move32(); } + + return; } @@ -1136,8 +1152,13 @@ void wb_tbe_enc_fx( p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); /* Estimate the gain parameter */ +#ifdef HARM_BWE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#else EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#endif /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -1282,10 +1303,7 @@ void wb_tbe_enc_ivas_fx( Word32 LepsP[LPC_SHB_ORDER_WB + 1]; Word32 prev_pow, curr_pow, Lscale; - /* Word16 scale; */ - /*Word16 ramp_flag;*/ Word32 p2m_in, p2m_out; - /*Word16 cnt, max =0;*/ Word16 n_mem, Q_bwe_exc, Q_bwe_exc_ext, exp_out, Q_cur_pow, Q_prev_pow; /* Q_hb_frame; */ Word32 L_tmp, Lmax; Word16 tmp, exp, Q_out, sc; @@ -1305,7 +1323,6 @@ void wb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; move16(); - /*Word16 att = 32767;*/ set16_fx( bwe_exc_extended_16, 0, L_FRAME32k + NL_BUFF_OFFSET ); hb_new_speech = hb_old_speech + WBTBE_LOOK_LSUFBR_5_OVER_16; hb_frame = hb_old_speech + WBTBE_LSUBFR_5_OVER_16 + WBTBE_ANA_ALIGNDELAY; @@ -1404,20 +1421,11 @@ void wb_tbe_enc_ivas_fx( move16(); } - /* lsp_spacing_fx = 16384; move16(); */ lsp_spacing_fx = lsp_wb_temp_fx[0]; move16(); FOR( i = 1; i < LPC_SHB_ORDER_WB; i++ ) { - /*if ( i == 0 ) - { - tmp = lsp_wb_temp_fx[0]; move16(); - } - else - {*/ tmp = sub( lsp_wb_temp_fx[i], lsp_wb_temp_fx[i - 1] ); - /*} */ - lsp_spacing_fx = s_min( lsp_spacing_fx, tmp ); } @@ -1521,6 +1529,7 @@ void wb_tbe_enc_ivas_fx( /* Quantization of LSFs */ i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ + #ifdef HARM_BWE IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { @@ -1809,6 +1818,7 @@ void wb_tbe_enc_ivas_fx( temp_wb_fac_fx = 0; move16(); } + L_feedback = L_mult0( temp_wb_fac_fx, temp_wb_fac_fx ); FOR( i = 1; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -1905,8 +1915,13 @@ void wb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ +#ifdef HARM_BWE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, + &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#else EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); +#endif /* If there's a big difference in the power of gains away from the peak gain */ /* due to poor quantization then suppress energy of the high band. */ @@ -2061,6 +2076,12 @@ void wb_tbe_enc_ivas_fx( } +/*-------------------------------------------------------------------* + * fb_tbe_reset_enc() + * + * Reset the extra parameters needed for FB TBE encoding + *-------------------------------------------------------------------*/ + void fb_tbe_reset_enc_fx( Word32 elliptic_bpf_2_48k_mem_fx[][4], Word32 *prev_fb_energy_fx, @@ -2839,8 +2860,13 @@ void swb_tbe_enc_fx( p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); /* Estimate the gain parameter */ +#ifdef HARM_BWE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, + GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#else EstimateSHBFrameGain_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -4344,8 +4370,13 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ +#ifdef HARM_BWE + EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, + GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#else EstimateSHBFrameGain_ivas_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); +#endif IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -4697,7 +4728,11 @@ void swb_tbe_enc_ivas_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ + static void EstimateSHBFrameGain_fx( +#ifdef HARM_BWE + const Word16 element_mode, /* i : element mode */ +#endif const Word16 length, /* i : SHB overlap length */ const Word16 *oriSHB, /* i : target original SHB frame Q(Q_oriSHB) */ const Word16 Q_oriSHB, /* i : Q of arget original SHB frame */ @@ -4709,6 +4744,7 @@ static void EstimateSHBFrameGain_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) +#ifndef HARM_BWE { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -4893,6 +4929,7 @@ static void EstimateSHBFrameGain_ivas_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) +#endif { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -4932,34 +4969,70 @@ static void EstimateSHBFrameGain_ivas_fx( move16(); j = skip[0]; move16(); - FOR( k = 0; k < length / 2; k++ ) - { - sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ - mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] ); - move32(); /* Q(16+Q_synSHB) */ - } - FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) +#ifdef HARM_BWE + IF( element_mode == EVS_MONO ) { - j = skip[i]; - move16(); - FOR( k = 0; k < length; k++ ) + FOR( k = 0; k < length / 2; k++ ) { - L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ - sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ - mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] ); + sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ + mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + mod_syn[j + k + length / 2] = L_mult( synSHB[j + k + length / 2], subgain[0] ); + move32(); /* Q(16+Q_synSHB) */ + } + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + j = skip[i]; + move16(); + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ + mod_syn[j + k] = L_shl( L_mult( sum_gain, synSHB[j + k] ), 1 ); + move32(); /* Q(16+Q_synSHB) */ + } + } + FOR( k = 0; k < length / 2; k++ ) + { + j = skip[i]; + move16(); + sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ + mod_syn[j + k] = L_mult( synSHB[j + k], sum_gain ); move32(); /* Q(16+Q_synSHB) */ } } - FOR( k = 0; k < length / 2; k++ ) + ELSE +#endif { - j = skip[i]; - move16(); - sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ - mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ + FOR( k = 0; k < length / 2; k++ ) + { + sum_gain = mult_r( subwin_shb_local[2 * k + 2], subgain[0] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + mod_syn[j + k + length / 2] = L_mult0( synSHB[j + k + length / 2], subgain[0] ); + move32(); /* Q(16+Q_synSHB) */ + } + FOR( i = 1; i < NUM_SHB_SUBFR / 2; i++ ) + { + j = skip[i]; + move16(); + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[k + 1], subgain[i] ); /* Q30 */ + sum_gain = round_fx( L_mac0( L_tmp, subwin_shb_local[length - k - 1], subgain[i - 1] ) ); /* Q14 */ + mod_syn[j + k] = L_mult( sum_gain, synSHB[j + k] ); + move32(); /* Q(16+Q_synSHB) */ + } + } + FOR( k = 0; k < length / 2; k++ ) + { + j = skip[i]; + move16(); + sum_gain = mult_r( subwin_shb_fx[length - 2 * k - 2], subgain[i - 1] ); /* Q15 */ + mod_syn[j + k] = L_mult0( synSHB[j + k], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + } } } ELSE @@ -4969,45 +5042,93 @@ static void EstimateSHBFrameGain_ivas_fx( join_length = i_mult2( num_join, length ); j = 0; move16(); - FOR( k = 0; k < length; k++ ) - { - sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ - mod_syn[j] = L_mult0( synSHB[j], sum_gain ); - move32(); /* Q(16+Q_synSHB) */ - j++; - } - FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + +#ifdef HARM_BWE + IF( element_mode == EVS_MONO ) { - FOR( k = 0; k < join_length - length; k++ ) + FOR( k = 0; k < length; k++ ) { - mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); + sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ + mod_syn[j] = L_mult( synSHB[j], sum_gain ); move32(); /* Q(16+Q_synSHB) */ j++; } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult( synSHB[j], subgain[i * num_join] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); + tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + mod_syn[j] = L_shl( L_mult( tmp, synSHB[j] ), 1 ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); + move32(); /* Q(16+Q_synSHB)*/ + j++; + } FOR( k = 0; k < length; k++ ) { - L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); - tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ mod_syn[j] = L_mult( tmp, synSHB[j] ); - move32(); /* Q(16+Q_synSHB) */ + move32(); /* Q(16+Q_synSHB ) */ j++; } } - FOR( k = 0; k < join_length - length; k++ ) - { - mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); - move32(); /* Q(16+Q_synSHB)*/ - j++; - } - FOR( k = 0; k < length; k++ ) + ELSE +#endif { - tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ - mod_syn[j] = L_mult0( tmp, synSHB[j] ); - move32(); /* Q(16+Q_synSHB ) */ - j++; + FOR( k = 0; k < length; k++ ) + { + sum_gain = mult_r( subwin_shb_local[k + 1], subgain[0] ); /* Q15 */ + mod_syn[j] = L_mult0( synSHB[j], sum_gain ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + FOR( i = 0; i < NUM_SHB_SUBGAINS - 1; i++ ) + { + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[i * num_join] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + + FOR( k = 0; k < length; k++ ) + { + L_tmp = L_mult0( subwin_shb_local[length - k - 1], subgain[i * num_join] ); + tmp = round_fx( L_mac0( L_tmp, subwin_shb_local[k + 1], subgain[( i + 1 ) * num_join] ) ); /* Q14 */ + mod_syn[j] = L_mult( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB) */ + j++; + } + } + FOR( k = 0; k < join_length - length; k++ ) + { + mod_syn[j] = L_mult0( synSHB[j], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); + move32(); /* Q(16+Q_synSHB)*/ + j++; + } + FOR( k = 0; k < length; k++ ) + { + tmp = mult_r( subwin_shb_local[length - k - 1], subgain[( NUM_SHB_SUBGAINS - 1 ) * num_join] ); /* Q15 */ + mod_syn[j] = L_mult0( tmp, synSHB[j] ); + move32(); /* Q(16+Q_synSHB ) */ + j++; + } } } + /* adjust frame energy */ oriNrg = L_deposit_l( 0 ); synNrg = L_deposit_l( 0 ); @@ -5017,14 +5138,14 @@ static void EstimateSHBFrameGain_ivas_fx( sig = mult_r_sat( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_orisHB*/ sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_synSHB - 2*/ } FOR( ; i < l_frame; i++ ) { oriNrg = L_mac0_sat( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ sig = round_fx_sat( mod_syn[i] ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_oriSHB - 2*/ } tmp = add( l_frame, l_shb_lahead ); @@ -5033,7 +5154,7 @@ static void EstimateSHBFrameGain_ivas_fx( sig = mult_r_sat( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB */ sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ - synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB / 2*Q_oriSHB - 2*/ } IF( EQ_32( oriNrg, MAX_32 ) ) { @@ -5056,7 +5177,17 @@ static void EstimateSHBFrameGain_ivas_fx( oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ } } - L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); + +#ifdef HARM_BWE + IF( element_mode == EVS_MONO ) + { + L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &exp_out ); + } + ELSE +#endif + { + L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); + } exp_out = sub( exp_out, scaling ); frame_gain = L_shl_sat( L_tmp, sub( exp_out, 13 ) ); /* Q18 */ *GainFrame = frame_gain; @@ -5066,7 +5197,10 @@ static void EstimateSHBFrameGain_ivas_fx( } -static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) +static Word32 pow_off_pk_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) { Word16 i, j; Word32 sum, L_tmp; @@ -5092,7 +5226,10 @@ static Word32 pow_off_pk_fx( Word16 a[], Word16 len, Word16 step ) } -static Word32 pow_off_pk_corrected_fx( Word16 a[], Word16 len, Word16 step ) +static Word32 pow_off_pk_corrected_fx( + const Word16 a[], + const Word16 len, + const Word16 step ) { Word16 i, j; Word32 sum, L_tmp; @@ -5404,6 +5541,7 @@ static void EstimateSHBGainShape_fx( /* RETURN ARGUMENTS : */ /* _ Word16 : index Q0 */ /*--------------------------------------------------------------------------*/ + static Word16 closest_centroid_fx( const Word16 *data, /* i : input data Qx*/ const Word16 *weights, /* i : weights */ @@ -5449,6 +5587,7 @@ static Word16 closest_centroid_fx( /* PURPOSE : Determine a set of closest VQ centroids for a given input */ /* Gain shape is 4 dimensional */ /*--------------------------------------------------------------------------*/ + static Word16 closest_centroid_lc_fx( const Word16 *data, /* i : input data Qx*/ const Word16 *quantizer, /* i : quantizer table Qx*/ @@ -6425,6 +6564,7 @@ return; /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------*/ + static void determine_gain_weights_fx( const Word32 *gain, /* i : Gain parameter Q18 */ Word16 *weights, /* o : gain weights Q12/Q6*/ @@ -6489,6 +6629,7 @@ static void determine_gain_weights_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------------------------*/ + static void singlevectortest_gain_fx( const Word32 *inp, /* i : input gain vector Q18*/ const Word16 dimen, /* i : dimension of the input vector */ @@ -6557,6 +6698,7 @@ static void singlevectortest_gain_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*------------------------------------------------------------------------------*/ + static void return_M_Least_fx_GainFrame( const Word32 *inp, /* i: input Q18*/ const Word32 *codebook, /* i: codebook Q18*/ @@ -7592,6 +7734,7 @@ static void Quant_BWE_LSF_ivas_fx( *-------------------------------------------------------------------*/ void fb_tbe_enc_fx( +#ifndef HARM_BWE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ @@ -7713,6 +7856,7 @@ void fb_tbe_enc_fx( } void fb_tbe_enc_ivas_fx( +#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate Q_new_input */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ @@ -7732,13 +7876,30 @@ void fb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; Word16 q_diff, q_input_fhb; Word64 temp1, temp2; +#ifdef HARM_BWE + Word16 offset; + + offset = 0; + move16(); + if ( st->element_mode > EVS_MONO ) + { + offset = NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); + } +#endif s_max_value = 0; move16(); +#ifdef HARM_BWE + FOR( i = 0; i < add( L_FRAME48k, offset ); i++ ) + { + s_max_value = s_max( s_max_value, abs_s( new_input[i - offset] ) ); + } +#else FOR( i = 0; i < L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ); i++ ) { s_max_value = s_max( s_max_value, abs_s( new_input[i - NS2SA( 48000, DELAY_FIR_RESAMPL_NS )] ) ); } +#endif exp_temp = norm_s( s_max_value ); if ( s_max_value == 0 ) { @@ -7746,21 +7907,36 @@ void fb_tbe_enc_ivas_fx( move16(); } +#ifdef HARM_BWE + if ( st->element_mode == EVS_MONO ) + { + exp_temp = sub( exp_temp, 1 ); + } +#endif + +#ifdef HARM_BWE + Copy_Scale_sig( new_input - offset, input_fhb_new, add( L_FRAME48k, offset ), exp_temp ); +#else Copy_Scale_sig( new_input - NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_fhb_new, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), exp_temp ); +#endif exp_temp = add( exp_temp, Q_new_input ); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); } ELSE { +#ifdef HARM_BWE + elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + offset, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#else elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); +#endif } test(); IF( GT_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_SCE ) ) { - IF( EQ_16( st->L_frame, L_FRAME ) ) { Sample_Delay_HP = NS2SA( 48000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ) - L_FRAME48k / 2; @@ -7783,75 +7959,147 @@ void fb_tbe_enc_ivas_fx( set16_fx( tmp_vec, 0, L_FRAME16k ); } - q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); - Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q - Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); // exp_temp - IF( q_diff > 0 ) - { - scale_sig( input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ), negate( q_diff ) ); // hBWE_TD->old_input_fhb_fx_Q - q_input_fhb = hBWE_TD->old_input_fhb_fx_Q; +#ifdef HARM_BWE + IF( st->element_mode == EVS_MONO ) + { + Word32 L_tmp, temp32, fb_exc_energy32; + Word16 tmp1; + + Copy_Scale_sig( hBWE_TD->old_input_fhb_fx, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP, sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ) ); + hBWE_TD->old_input_fhb_fx_Q = exp_temp; + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); + Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k - Sample_Delay_HP ); + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); + temp32 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ + temp32 = L_add_sat( temp32, L_shl_sat( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); /* Q11 */ + hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q11*/ + hBWE_TD->prev_fb_energy_fx_Q = sub( add( exp_temp, exp_temp ), 6 ); + fb_exc_energy32 = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc+1 -7) */ + + /*ratio = (float) sqrt( temp32 / fb_exc_energy );*/ + L_tmp = L_max( 1, temp32 ); /*Q6*/ + exp = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, exp ) ); + exp = sub( sub( 31, sub( add( exp_temp, exp_temp ), 8 ) ), exp ); /* in Q15 (L_tmp in Q6)*/ + + exp2 = norm_l( fb_exc_energy32 ); + tmp2 = extract_h( L_shl( fb_exc_energy32, exp2 ) ); + tmp1 = sub( add( Q_fb_exc, Q_fb_exc ), 8 ); /*1 - 9*/ + exp2 = sub( sub( 31, tmp1 ), exp2 ); /* in Q15 (L_tmp in Q6)*/ + + exp = sub( exp2, exp ); /* Denormalize and substract */ + IF( GT_16( tmp2, tmp ) ) + { + tmp2 = shr( tmp2, 1 ); + exp = add( exp, 1 ); + } + IF( 0 != tmp ) + { + tmp = div_s( tmp2, tmp ); + L_tmp = L_deposit_h( tmp ); + L_tmp = Isqrt_lc( L_tmp, &exp ); /*Q(31-exp)*/ + L_tmp = L_max( L_shr_sat( L_tmp, sub( 31, exp ) ), 0x1 ); /* Q0 */ + } + ELSE + { + L_tmp = 0; + } + + /* idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + idxGain = max( 0, min(15,idxGain) ); */ + ratio = 0; move16(); + IF( GE_32( L_tmp, 32768 ) ) + { + idxGain = 15; + move16(); + } + ELSE + { + ratio = extract_l( L_tmp ); + idxGain = sub( 14, norm_s( ratio ) ); + idxGain = s_max( 0, idxGain ); + } + + test(); + test(); + IF( GT_16( idxGain, 2 ) && LT_16( idxGain, 15 ) && GT_16( ratio, add( shl( 2, sub( idxGain, 1 ) ), shl( 2, sub( idxGain, 2 ) ) ) ) ) + { + idxGain = add( idxGain, 1 ); + } } ELSE +#endif { - scale_sig( input_fhb, Sample_Delay_HP, q_diff ); // exp_temp - q_input_fhb = exp_temp; + q_diff = sub( exp_temp, hBWE_TD->old_input_fhb_fx_Q ); + Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); // hBWE_TD->old_input_fhb_fx_Q + Copy( tmp_vec, input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ) ); // exp_temp + IF( q_diff > 0 ) + { + scale_sig( input_fhb + Sample_Delay_HP, sub( L_FRAME48k, Sample_Delay_HP ), negate( q_diff ) ); // hBWE_TD->old_input_fhb_fx_Q + q_input_fhb = hBWE_TD->old_input_fhb_fx_Q; + move16(); + } + ELSE + { + scale_sig( input_fhb, Sample_Delay_HP, q_diff ); // exp_temp + q_input_fhb = exp_temp; + move16(); + } + Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); + hBWE_TD->old_input_fhb_fx_Q = exp_temp; move16(); - } - Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); - hBWE_TD->old_input_fhb_fx_Q = exp_temp; - move16(); - temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ - temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb + temp2 = sum2_fx_no_sat( input_fhb, L_FRAME48k / 2 ); // 2*q_input_fhb /* Q(2*Q_input_fhb-8) */ + temp2 = W_add( temp2, W_shl( hBWE_TD->prev_fb_energy_fx, sub( shl( q_input_fhb, 1 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); // 2*q_input_fhb - temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb - exp = W_norm( temp1 ); - temp1 = W_shl( temp1, exp ); // 2*q_input_fhb+exp - hBWE_TD->prev_fb_energy_fx = W_extract_h( temp1 ); // 2*q_input_fhb+exp-32 - move32(); - hBWE_TD->prev_fb_energy_fx_Q = sub( add( shl( q_input_fhb, 1 ), exp ), 32 ); - move16(); + temp1 = sum2_fx_no_sat( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); // 2*q_input_fhb + exp = W_norm( temp1 ); + temp1 = W_shl( temp1, exp ); // 2*q_input_fhb+exp + hBWE_TD->prev_fb_energy_fx = W_extract_h( temp1 ); // 2*q_input_fhb+exp-32 + move32(); + hBWE_TD->prev_fb_energy_fx_Q = sub( add( shl( q_input_fhb, 1 ), exp ), 32 ); + move16(); - fb_exc_energy = sum2_fx_no_sat( fb_exc, L_FRAME16k ); // 2*Q_fb_exc + fb_exc_energy = sum2_fx_no_sat( fb_exc, L_FRAME16k ); // 2*Q_fb_exc - /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ - exp = sub( W_norm( temp2 ), 1 ); - tmp = extract_h( W_extract_h( W_shl( temp2, exp ) ) ); // 2*q_input_fhb+exp-48 - exp = sub( 63, add( shl( q_input_fhb, 1 ), exp ) ); // 15-(2*q_input_fhb+exp-48) + /*ratio = (float) sqrt( temp2 / fb_exc_energy );*/ + exp = sub( W_norm( temp2 ), 1 ); + tmp = extract_h( W_extract_h( W_shl( temp2, exp ) ) ); // 2*q_input_fhb+exp-48 + exp = sub( 63, add( shl( q_input_fhb, 1 ), exp ) ); // 15-(2*q_input_fhb+exp-48) - exp2 = W_norm( fb_exc_energy ); - tmp2 = extract_h( W_extract_h( W_shl( fb_exc_energy, exp2 ) ) ); // 2*Q_fb_exc+exp2-48 - exp2 = sub( 63, add( shl( Q_fb_exc, 1 ), exp2 ) ); // 15-(2*Q_fb_exc+exp2-48) + exp2 = W_norm( fb_exc_energy ); + tmp2 = extract_h( W_extract_h( W_shl( fb_exc_energy, exp2 ) ) ); // 2*Q_fb_exc+exp2-48 + exp2 = sub( 63, add( shl( Q_fb_exc, 1 ), exp2 ) ); // 15-(2*Q_fb_exc+exp2-48) - ratio = 0; - idxGain = 0; - move16(); - move16(); - test(); - IF( tmp != 0 && tmp2 != 0 ) - { - ratio = div_s( tmp, tmp2 ); // exp: exp-exp2 - exp = sub( exp, exp2 ); - /* ratio = (float) sqrt( temp2 / fb_exc_energy ); - idxGain = (short)( log2_f ((float)ratio) + 0.5f ); + ratio = 0; + idxGain = 0; + move16(); + move16(); + test(); + IF( tmp != 0 && tmp2 != 0 ) + { + ratio = div_s( tmp, tmp2 ); // exp: exp-exp2 + exp = sub( exp, exp2 ); + /* ratio = (float) sqrt( temp2 / fb_exc_energy ); + idxGain = (short)( log2_f ((float)ratio) + 0.5f ); - => idxGain = (short)( log2_f (sqrt( temp2 / fb_exc_energy )) + 0.5f ) - = (short)(log2f(sqrt(temp2 / fb_exc_energy)) + log2f(sqrt(2))) - = (short)log2f(sqrt(2 * (temp2 / fb_exc_energy))) - increase the exp of division result by one, two accommodate the multiplication with 2 in sqrt - */ - exp = add( exp, 1 ); - ratio = Sqrt16( ratio, &exp ); - /* Since ratio always lie betwwen 16384 and 32767, subtract the Q of sqrt result from 14 to get the integral part of log value */ - idxGain = sub( exp, 1 ); // 14 - (15-exp) + => idxGain = (short)( log2_f (sqrt( temp2 / fb_exc_energy )) + 0.5f ) + = (short)(log2f(sqrt(temp2 / fb_exc_energy)) + log2f(sqrt(2))) + = (short)log2f(sqrt(2 * (temp2 / fb_exc_energy))) + increase the exp of division result by one, two accommodate the multiplication with 2 in sqrt + */ + exp = add( exp, 1 ); + ratio = Sqrt16( ratio, &exp ); + /* Since ratio always lie betwwen 16384 and 32767, subtract the Q of sqrt result from 14 to get the integral part of log value */ + idxGain = sub( exp, 1 ); // 14 - (15-exp) - /* idxGain = max( 0, min( 15, idxGain ) ); */ - idxGain = s_max( 0, s_min( 15, idxGain ) ); + /* idxGain = max( 0, min( 15, idxGain ) ); */ + idxGain = s_max( 0, s_min( 15, idxGain ) ); + } } /* ratio = (float)(1 << idxGain);*/ -#ifndef HARM_BWE IF( EQ_16( st->codec_mode, MODE2 ) ) { hBWE_TD->idxGain = idxGain; @@ -7859,11 +8107,8 @@ void fb_tbe_enc_ivas_fx( } ELSE { -#endif push_indice( st->hBstr, IND_FB_SLOPE, idxGain, 4 ); -#ifndef HARM_BWE } -#endif return; } -- GitLab From 94edac5f11696beca1b7506bca908753f27bd8f5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 30 Jan 2026 11:13:18 +0100 Subject: [PATCH 4/9] rename HARM_BWE -> HARMONIZE_TBE --- lib_com/ivas_prot_fx.h | 2 +- lib_com/options.h | 2 +- lib_com/prot_fx.h | 6 +- lib_dec/evs_dec_fx.c | 4 +- lib_dec/ivas_core_dec_fx.c | 4 +- lib_dec/swb_tbe_dec_fx.c | 42 ++++++------- lib_enc/evs_enc_fx.c | 4 +- lib_enc/ivas_core_enc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 2 +- lib_enc/swb_tbe_enc_fx.c | 126 ++++++++++++++++++------------------- 10 files changed, 97 insertions(+), 97 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 933aebfbb..39db9ec08 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1865,7 +1865,7 @@ void stereoFdCngCoherence_fx( Word16 fft_exp ); -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE void ivas_wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ diff --git a/lib_com/options.h b/lib_com/options.h index ea62fd7e4..0e07484bb 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -103,7 +103,7 @@ #define FIX_BASOP_2357_OBJECT_EDIT_MSAN /* Nokia: basop issue 2357: initialize missing exponents in object edit */ #define FIX_BASOP_2354_MSAN_DIFF_Q_VALUE /* Nokia: Initialize Q value of diffuseness in rendering to Q30 */ #define FIX_2371_REMOVE_UNUSED_ISAR_FCNS /* Dolby: basop issue 2371: remove unused ISAR-related functions */ -#define HARM_BWE +#define HARMONIZE_TBE /* VA: harmonize core-coder TBE function duplications */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index ce33afa73..948bfea0b 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5775,7 +5775,7 @@ void swb_tbe_dec_fx( Word16 *Q_synth, Word16 *pitch_buf ); -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE void ivas_dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, /* i : extension layer */ @@ -5790,7 +5790,7 @@ void ivas_dequantizeSHBparams_fx_9_1( Word16 *MSFlag ); #endif void fb_tbe_dec_fx( -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, @@ -5802,7 +5802,7 @@ void fb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ Word16 Q_fb_exc, -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ #endif Word32 *hb_synth, /* o : high-band synthesis */ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 6ecfa4093..07b2deddc 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -408,7 +408,7 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( output_frame, L_FRAME48k ) && EQ_16( st_fx->extl, FB_TBE ) ) { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); #else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); @@ -847,7 +847,7 @@ ivas_error evs_dec_fx( test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, NULL, hb_synth_fx_exp, NULL, -1, output_frame ); #else fb_tbe_dec_fx( st_fx, fb_exc_fx, Q_fb_exc, hb_synth_fx, hb_synth_fx_exp ); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 623a6bca6..d7a837852 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1013,7 +1013,7 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE 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 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 ); @@ -1081,7 +1081,7 @@ ivas_error ivas_core_dec_fx( /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE fb_tbe_dec_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, NULL, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); #else diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 41d9e320a..6498a8262 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -14,7 +14,7 @@ * Local functions *-----------------------------------------------------------------*/ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE static void dequantizeSHBparams_fx( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors, Word16 *MSFlag ); #else static void dequantizeSHBparams_fx_9_1( Decoder_State *st_fx, const Word16 extl, Word32 extl_brate, Word16 *Q_lsf, Word16 *Q_subgain, Word32 *Q_framegrain, Word16 *uv_flag, Word32 *Q_shb_ener_sf_32, Word16 *Q_shb_res_gshape, Word16 *Q_mixFactors ); @@ -603,7 +603,7 @@ void ResetSHBbuffer_Dec_fx( /* CALLED FROM : */ /*==========================================================================*/ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE void wb_tbe_dec_fx( #else void ivas_wb_tbe_dec_fx( @@ -765,7 +765,7 @@ void ivas_wb_tbe_dec_fx( } ELSE { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE /* de-quantization */ dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &j /*temp*/ ); #else @@ -855,7 +855,7 @@ void ivas_wb_tbe_dec_fx( /* From low band excitation, generate highband excitation */ Lmax = 0; move32(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) @@ -880,7 +880,7 @@ void ivas_wb_tbe_dec_fx( { Q_bwe_exc = norm_l( Lmax ); } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Q_bwe_exc = sub( Q_bwe_exc, 1 ); @@ -906,7 +906,7 @@ void ivas_wb_tbe_dec_fx( move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { prev_pow = 0; @@ -934,7 +934,7 @@ void ivas_wb_tbe_dec_fx( rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); @@ -942,7 +942,7 @@ void ivas_wb_tbe_dec_fx( #endif sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) @@ -966,7 +966,7 @@ void ivas_wb_tbe_dec_fx( Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, @@ -1000,7 +1000,7 @@ void ivas_wb_tbe_dec_fx( curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc_ext) */ } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); @@ -1033,7 +1033,7 @@ void ivas_wb_tbe_dec_fx( max = 0; move16(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_FRAME16k / 4; i++ ) @@ -1089,7 +1089,7 @@ void ivas_wb_tbe_dec_fx( } test(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( !st_fx->bfi && st_fx->prev_bfi ) #else test(); @@ -1290,7 +1290,7 @@ void ivas_wb_tbe_dec_fx( } ELSE IF( EQ_32( st_fx->output_Fs, 48000 ) ) { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Scale_sig( hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( Qx, hBWE_TD->prev_Qx ) ); @@ -1361,7 +1361,7 @@ void ivas_wb_tbe_dec_fx( return; } -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE void wb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -2335,7 +2335,7 @@ void swb_tbe_dec_fx( ELSE { /* de-quantization */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, &shb_ener_sf_32, shb_res_gshape, &mixFactors, &j /*temp*/ ); #else @@ -4014,7 +4014,7 @@ static Word16 dotp_loc( * Dequantize super highband spectral envolope, temporal gains and frame gain *-------------------------------------------------------------------*/ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE static void dequantizeSHBparams_fx( #else void ivas_dequantizeSHBparams_fx_9_1( @@ -4450,7 +4450,7 @@ void ivas_dequantizeSHBparams_fx_9_1( return; } -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE /*==========================================================================*/ /* FUNCTION : static void dequantizeSHBparams_fx_9_1 () */ /*--------------------------------------------------------------------------*/ @@ -4778,7 +4778,7 @@ static void dequantizeSHBparams_fx_9_1( *-------------------------------------------------------------------*/ void fb_tbe_dec_fx( -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, @@ -4837,7 +4837,7 @@ void fb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: encoder state structure */ const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ Word16 Q_fb_exc, -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ #endif Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ @@ -4903,7 +4903,7 @@ void fb_tbe_dec_ivas_fx( } /* add the fb_synth component to the hb_synth component */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st->element_mode == EVS_MONO ) { FOR( i = 0; i < L_FRAME48k; i++ ) @@ -5958,7 +5958,7 @@ void ivas_swb_tbe_dec_fx( ELSE { /* de-quantization */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE dequantizeSHBparams_fx( st, st->extl, st->extl_brate, lsf_shb_fx, GainShape_fx, &GainFrame_fx, &stemp, &shb_ener_sf_32, shb_res_gshape_fx, &mixFactors_fx, &MSFlag ); #else diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 622f2225c..18cd6b96f 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -425,7 +425,7 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ -#ifdef HARM_BWEaa +#ifdef HARMONIZE_TBEaa wb_tbe_enc_ivas_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); #else wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); @@ -475,7 +475,7 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc, 0 ); #else fb_tbe_enc_fx( st, st->input_fx, fb_exc, Q_fb_exc ); diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index ab3aadeb0..b08dd6f67 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -786,7 +786,7 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, FB_TBE ) ) { /* FB TBE encoder */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE fb_tbe_enc_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); #else fb_tbe_enc_ivas_fx( st, st->input_fx, fb_exc_fx, Q_fb_exc, st->q_inp ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 598301820..bb85cd536 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -159,7 +159,7 @@ Word16 dtx_hangover_addition_fx( Word16 *rem_dtx_ho ); void fb_tbe_enc_fx( -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : i speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 6b0810af3..86540d0cb 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -29,11 +29,11 @@ static void singlevectortest_gain_fx( const Word32 *inp, const Word16 dimen, con static void determine_gain_weights_fx( const Word32 *gain, Word16 *weights, const Word16 dims ); static void QuantizeSHBsubgains_fx( Encoder_State *st_fx, Word16 *subgains, const Word16 extl ); -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE static void QuantizeSHBsubgains_ivas_fx( Encoder_State *st_fx, Word16 subgains[], const Word16 extl ); #endif -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind, const Word16 flag_conservative ); #else static void QuantizeSHBframegain_fx( Encoder_State *st_fx, Word32 *GainFrame, const Word16 extl, Word32 extl_brate, Word16 *rf_gainFrame_ind ); @@ -45,7 +45,7 @@ static Word16 closest_centroid_fx( const Word16 *data, const Word16 *weights, co static Word16 closest_centroid_lc_fx( const Word16 *data, const Word16 *quantizer, const Word16 centroids ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE static void EstimateSHBFrameGain_fx( const Word16 element_mode, const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); #else static void EstimateSHBFrameGain_fx( const Word16 length, const Word16 *oriSHB, const Word16 Q_oriSHB, const Word16 *synSHB, const Word16 Q_synSHB, Word16 *subgain, Word32 *GainFrame, const Word16 *win_shb, const Word16 *subwin_shb, const Word16 n_subfr_saturation ); @@ -73,7 +73,7 @@ static Word16 Quant_mirror_point_fx( const Word16 lsf[], const Word16 lsf_q[], W static Word16 Find_LSF_grid_fx( const Word16 lsf[], Word16 lsf_q[], const Word16 m ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE static void Quant_BWE_LSF_fx( BSTR_ENC_HANDLE hBstr, TD_BWE_ENC_HANDLE hBWE_TD, const Word16 codec_mode, const Word16 lsf_shb_fx[], Word16 Q_lsfs_fx[], const Word32 extl_brate ); static void Quant_shb_ener_sf_fx( Encoder_State *st_fx, Word32 *shb_ener_sf_Q31, const Word16 Q_ener ); @@ -1152,7 +1152,7 @@ void wb_tbe_enc_fx( p2m_out = pow_off_pk_fx( GainShape, NUM_SHB_SUBFR / 2, 2 ); /* Estimate the gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); #else @@ -1231,7 +1231,7 @@ void wb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind, 0 ); #else QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &hRF->RF_bwe_gainFr_ind ); @@ -1347,7 +1347,7 @@ void wb_tbe_enc_ivas_fx( k = 0; move16(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) @@ -1372,7 +1372,7 @@ void wb_tbe_enc_ivas_fx( } } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { autocorr_fx( hb_old_speech, LPC_SHB_ORDER_WB + 1, R_h, R_l, &Q_R, WBTBE_LPCWIN_LENGTH, win_lpc_hb_wb_fx, 0, 1 ); @@ -1391,7 +1391,7 @@ void wb_tbe_enc_ivas_fx( Copy_Scale_sig( lpc_wb_temp_fx, lpc_wb_temp_fx, LPC_SHB_ORDER_WB + 1, sub( norm_s( lpc_wb_temp_fx[0] ), 2 ) ); // Q12 -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { /* convert into lsps and calculate weights */ @@ -1530,7 +1530,7 @@ void wb_tbe_enc_ivas_fx( /* Quantization of LSFs */ i = closest_centroid_fx( lsp_wb, weights_lsp, wb_bwe_lsfvq_cbook_8bit_fx, 256, LPC_SHB_ORDER_WB ); /*move16(); */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( EQ_16( st_fx->codec_mode, MODE2 ) ) { hBWE_TD->lsf_WB = i; @@ -1618,7 +1618,7 @@ void wb_tbe_enc_ivas_fx( prev_pow = 0; move32(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) @@ -1668,7 +1668,7 @@ void wb_tbe_enc_ivas_fx( rescale_genWB_mem_enc( st_fx, sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ) ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); @@ -1682,7 +1682,7 @@ void wb_tbe_enc_ivas_fx( move16(); } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); @@ -1691,7 +1691,7 @@ void wb_tbe_enc_ivas_fx( Copy( hBWE_TD->state_syn_shbexc_fx, shaped_wb_excitation, L_SHB_LAHEAD / 4 ); Q_bwe_exc_ext = sub( Q_bwe_exc, 16 ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GenShapedWBExcitation_fx( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt_fx, @@ -1710,7 +1710,7 @@ void wb_tbe_enc_ivas_fx( curr_pow = 0; move32(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) @@ -1897,7 +1897,7 @@ void wb_tbe_enc_ivas_fx( push_indice( st_fx->hBstr, IND_UV_FLAG, uv_flag, 1 ); /* Quantization of the subframe gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE QuantizeSHBsubgains_fx( st_fx, GainShape, st_fx->extl ); #else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape, st_fx->extl ); @@ -1915,7 +1915,7 @@ void wb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN / 2, hb_frame, Q_ns, shaped_wb_excitation, Q_bwe_exc_ext, GainShape, &GainFrame, window_wb_fx, subwin_wb_fx, 0 ); #else @@ -1929,7 +1929,7 @@ void wb_tbe_enc_ivas_fx( IF( GT_32( p2m_out, L_shl( p2m_in, 1 ) ) ) { L_tmp = root_a_over_b_fx( L_shl( p2m_in, 1 ), 29, p2m_out, 29, &exp_out ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = L_shl( Mult_32_32( GainFrame, L_tmp ), exp_out ); /* Q18 */ @@ -1967,7 +1967,7 @@ void wb_tbe_enc_ivas_fx( } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, tmp ); /* Q18 */ @@ -1980,7 +1980,7 @@ void wb_tbe_enc_ivas_fx( IF( LT_16( lsp_spacing_fx, 328 ) && lsp_spacing_fx ) { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, 21299 ); /* Q18 */ @@ -2005,7 +2005,7 @@ void wb_tbe_enc_ivas_fx( IF( st_fx->igf != 0 && EQ_16( st_fx->coder_type, VOICED ) ) { /*GainFrame *= 0.5f;*/ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, 16384 ); @@ -2019,7 +2019,7 @@ void wb_tbe_enc_ivas_fx( ELSE IF( st_fx->igf != 0 && GT_16( avg_voice_fac, 11469 ) ) /*Q15 -> 0.35f*/ { /*GainFrame *= 0.75f;*/ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { GainFrame = Mult_32_16( GainFrame, 24576 ); @@ -2034,7 +2034,7 @@ void wb_tbe_enc_ivas_fx( /* Quantization of the frame gain parameter */ IF( st_fx->rf_mode ) { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); #else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); @@ -2042,7 +2042,7 @@ void wb_tbe_enc_ivas_fx( } ELSE { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); #else QuantizeSHBframegain_ivas_fx( st_fx, &GainFrame, st_fx->extl, st_fx->extl_brate, NULL, 0 ); @@ -2051,7 +2051,7 @@ void wb_tbe_enc_ivas_fx( /* Adjust the subframe and frame gain of the synthesized SHB signal */ /* Scale the shaped excitation*/ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode > EVS_MONO ) #endif { @@ -2063,7 +2063,7 @@ void wb_tbe_enc_ivas_fx( ScaleShapedSHB_fx( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap_fx, GainShape, GainFrame, window_wb_fx, subwin_wb_fx, &Q_bwe_exc_ext, &dummy, dummy, dummy ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode > EVS_MONO ) #endif { @@ -2320,7 +2320,7 @@ void swb_tbe_enc_fx( ELSE { /* LSF quantization (21 bits) */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Quant_BWE_LSF_fx( st_fx->hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); #else Quant_BWE_LSF_fx( st_fx, lsf_shb_fx, lsf_shb_fx ); @@ -2860,7 +2860,7 @@ void swb_tbe_enc_fx( p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); /* Estimate the gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); #else @@ -2975,7 +2975,7 @@ void swb_tbe_enc_fx( } /* Quantization of the frame gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); #else QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind ); @@ -3168,7 +3168,7 @@ void swb_tbe_enc_ivas_fx( move16(); TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE RF_ENC_HANDLE hRF = st_fx->hRF; #endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -3341,7 +3341,7 @@ void swb_tbe_enc_ivas_fx( /* Input signal filtering in case of tonal sounds in the high band gain Frame smoothing and attenuation control */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); #else gainFrSmooth_En_ivas_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); @@ -3379,7 +3379,7 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); #else Quant_BWE_LSF_ivas_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); @@ -3557,7 +3557,7 @@ void swb_tbe_enc_ivas_fx( } shb_ener_sf_Q31 = Mult_32_16( shb_ener_sf_Q31, 102 /*0.003125f Q15*/ ); shb_ener_sf_Q31 = L_add( 1l /*1 Q0*/, shb_ener_sf_Q31 ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); #else Quant_shb_ener_sf_ivas_fx( st_fx, &shb_ener_sf_Q31, shl( Q_shb, 1 ) ); @@ -3608,7 +3608,7 @@ void swb_tbe_enc_ivas_fx( move16(); } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); #else Quant_shb_res_gshape_ivas_fx( st_fx, shb_res_gshape_fx ); @@ -4320,7 +4320,7 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the gain shape parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); #else QuantizeSHBsubgains_ivas_fx( st_fx, GainShape_fx, st_fx->extl ); @@ -4370,7 +4370,7 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); #else @@ -4621,7 +4621,7 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the frame gain parameter */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); #else IF( st_fx->rf_mode ) @@ -4730,7 +4730,7 @@ void swb_tbe_enc_ivas_fx( /*--------------------------------------------------------------------------*/ static void EstimateSHBFrameGain_fx( -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE const Word16 element_mode, /* i : element mode */ #endif const Word16 length, /* i : SHB overlap length */ @@ -4744,7 +4744,7 @@ static void EstimateSHBFrameGain_fx( const Word16 *subwin_shb_local, /* i : SHB subframe window Q15 */ const Word16 n_subfr_saturation /* i : Number of subframes which saturated in GainShape oriNrg calculation */ ) -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE { const Word16 *skip; Word16 i, j, k, l_shb_lahead, l_frame; @@ -4970,7 +4970,7 @@ static void EstimateSHBFrameGain_ivas_fx( j = skip[0]; move16(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( element_mode == EVS_MONO ) { FOR( k = 0; k < length / 2; k++ ) @@ -5043,7 +5043,7 @@ static void EstimateSHBFrameGain_ivas_fx( j = 0; move16(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( element_mode == EVS_MONO ) { FOR( k = 0; k < length; k++ ) @@ -5178,7 +5178,7 @@ static void EstimateSHBFrameGain_ivas_fx( } } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( element_mode == EVS_MONO ) { L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, shl( Q_synSHB, 1 ), &exp_out ); @@ -5767,7 +5767,7 @@ static void QuantizeSHBsubgains_fx( return; } -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE /*============================================================*/ /* FUNCTION : static void QuantizeSHBsubgains_ivas_fx() */ /*------------------------------------------------------------*/ @@ -5913,7 +5913,7 @@ static void QuantizeSHBsubgains_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_ener_sf_fx( -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *shb_ener_sf_Q31, /* i/o: super highband subframe energies */ Word16 Q_ener ) @@ -5981,7 +5981,7 @@ static void Quant_shb_ener_sf_ivas_fx( Word32 L_tmp1, L_tmp; Word32 sum; Word16 tmp; -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Word16 Q_fac; #endif TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; @@ -5993,7 +5993,7 @@ static void Quant_shb_ener_sf_ivas_fx( exp = norm_l( sum ); frac = Log2_norm_lc( L_shl( sum, exp ) ); exp = sub( 30, add( exp, Q_ener ) ); /* 30-(exp+Q_ener ) */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { L_tmp1 = Mpy_32_16( exp, frac, 617 ); /* 2466=LOG10(2) in Q11, so answer Ltmp in Q12 */ @@ -6027,7 +6027,7 @@ static void Quant_shb_ener_sf_ivas_fx( /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ L_tmp = L_mult( temp_shb_ener_sf_fx, 27213 ); /* 3.321928 in Q13 -> L_tmp in Q12/Q11+Q13+1 = Q26/Q25 */ -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE L_tmp = L_shl( L_tmp, Q_fac ); /* bring L_tmp from Q26/Q25 to Q16 */ #else L_tmp = L_shl( L_tmp, -9 ); /* bring L_tmp from Q25 to Q16 */ @@ -6055,7 +6055,7 @@ static void Quant_shb_ener_sf_ivas_fx( *-------------------------------------------------------------------*/ static void Quant_shb_res_gshape_fx( -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 shb_res_gshape_fx[] /* i/o: super highband gain shapes Q14 */ ) @@ -6143,7 +6143,7 @@ static void Quant_shb_res_gshape_ivas_fx( /*==========================================================================*/ static void QuantizeSHBframegain_fx( -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ Word32 *GainFrame, /* i/o: Gain Q18 */ const Word16 extl, /* i : extension layer */ @@ -6341,7 +6341,7 @@ static void QuantizeSHBframegain_ivas_fx( 1 << NUM_BITS_SHB_FrameGain_LBR_WB, &idxFrameGain, &Q_GainFrame, SHBCB_FrameGain16_fx ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { IF( GT_32( Q_GainFrame, L_shl( Mult_32_16( *GainFrame, 17367 ), 1 ) ) && idxFrameGain > 0 ) /* 1.06 = +0.5 dB */ @@ -6935,7 +6935,7 @@ static Word16 Find_LSF_grid_fx( * * Gain frame smoothing and attenuation control *-------------------------------------------------------------------*/ -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE static void gainFrSmooth_En_fx( Encoder_State *st_fx, Word16 *shb_frame_fx, const Word16 *lpc_shb_fx, @@ -7060,7 +7060,7 @@ static void gainFrSmooth_En_fx( Encoder_State *st_fx, *-------------------------------------------------------------------*/ #endif -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE static void gainFrSmooth_En_fx( #else static void gainFrSmooth_En_ivas_fx( @@ -7119,7 +7119,7 @@ static void gainFrSmooth_En_ivas_fx( /* estimate the mean square error in lsps from current frame to past frames */ tempQ15_1 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_slow_interpl_fx[i] ); tempQ15_2 = sub( lsp_shb_fx[i], hBWE_TD->lsp_shb_fast_interpl_fx[i] ); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO ) { lsp_slow_evol_rate = L_mac( lsp_slow_evol_rate, tempQ15_1, tempQ15_1 ); @@ -7189,7 +7189,7 @@ static void gainFrSmooth_En_ivas_fx( } test(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st_fx->element_mode == EVS_MONO && LT_32( lsp_slow_evol_rate, INV_1000_Q31 ) && LT_32( lsp_fast_evol_rate, 2147484l /*0.001f Q31*/ ) ) { *frGainSmoothEn = 1; @@ -7579,7 +7579,7 @@ static void LVQQuant_BWE_LSF_fx( * * Quantize super highband spectral envolope *-------------------------------------------------------------------*/ -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE static void Quant_BWE_LSF_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ @@ -7646,7 +7646,7 @@ static void Quant_BWE_LSF_fx( #endif -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE static void Quant_BWE_LSF_fx( #else static void Quant_BWE_LSF_ivas_fx( @@ -7734,7 +7734,7 @@ static void Quant_BWE_LSF_ivas_fx( *-------------------------------------------------------------------*/ void fb_tbe_enc_fx( -#ifndef HARM_BWE +#ifndef HARMONIZE_TBE Encoder_State *st, /* i/o: encoder state structure */ const Word16 new_input[], /* i : input speech at 48 kHz sample rate */ const Word16 fb_exc[], /* i : FB excitation from the SWB part */ @@ -7876,7 +7876,7 @@ void fb_tbe_enc_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; Word16 q_diff, q_input_fhb; Word64 temp1, temp2; -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Word16 offset; offset = 0; @@ -7889,7 +7889,7 @@ void fb_tbe_enc_ivas_fx( s_max_value = 0; move16(); -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE FOR( i = 0; i < add( L_FRAME48k, offset ); i++ ) { s_max_value = s_max( s_max_value, abs_s( new_input[i - offset] ) ); @@ -7907,14 +7907,14 @@ void fb_tbe_enc_ivas_fx( move16(); } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE if ( st->element_mode == EVS_MONO ) { exp_temp = sub( exp_temp, 1 ); } #endif -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE Copy_Scale_sig( new_input - offset, input_fhb_new, add( L_FRAME48k, offset ), exp_temp ); #else Copy_Scale_sig( new_input - NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), input_fhb_new, L_FRAME48k + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), exp_temp ); @@ -7927,7 +7927,7 @@ void fb_tbe_enc_ivas_fx( } ELSE { -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + offset, &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); #else elliptic_bpf_48k_generic_fx( st->element_mode, 0, /* IsUpsampled3 */ input_fhb_new + NS2SA( 48000, DELAY_FIR_RESAMPL_NS ), &exp_temp, tmp_vec, hBWE_TD->elliptic_bpf_2_48k_mem_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, full_band_bpf_2_fx ); @@ -7959,7 +7959,7 @@ void fb_tbe_enc_ivas_fx( set16_fx( tmp_vec, 0, L_FRAME16k ); } -#ifdef HARM_BWE +#ifdef HARMONIZE_TBE IF( st->element_mode == EVS_MONO ) { Word32 L_tmp, temp32, fb_exc_energy32; -- GitLab From e21d3a202a352816406e9568deb16aa81ff411de Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 30 Jan 2026 11:19:33 +0100 Subject: [PATCH 5/9] updt --- lib_enc/init_enc_fx.c | 9 +++++++-- lib_enc/ivas_stereo_switching_enc_fx.c | 4 ++++ lib_enc/ivas_stereo_td_enc_fx.c | 4 ++++ lib_enc/prot_fx_enc.h | 3 ++- lib_enc/swb_tbe_enc_fx.c | 2 ++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 4a55101d5..6781802a4 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -842,8 +842,9 @@ ivas_error init_encoder_fx( { return error; } - +#ifndef HARMONIZE_TBE InitSWBencBuffer_fx( st->hBWE_TD ); +#endif } ELSE { @@ -851,9 +852,13 @@ ivas_error init_encoder_fx( { return error; } - +#ifndef HARMONIZE_TBE InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } ELSE diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index a87edb39f..58f1fc7a5 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -434,7 +434,11 @@ ivas_error stereo_memory_enc_fx( } } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->hBWE_TD ); +#else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index 92bd08afd..be0234c41 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -325,7 +325,11 @@ ivas_error stereo_set_tdm_fx( return error; } +#ifdef HARMONIZE_TBE + InitSWBencBuffer_fx( st->hBWE_TD ); +#else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); +#endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); IF( ( st->hBWE_FD = (FD_BWE_ENC_HANDLE) malloc( sizeof( FD_BWE_ENC_DATA ) ) ) == NULL ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index bb85cd536..7861d0d64 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3972,10 +3972,11 @@ void InitSWBencBuffer_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); +#ifndef HARMONIZE_TBE void InitSWBencBuffer_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); - +#endif void ResetSHBbuffer_Enc_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 86540d0cb..7bc5ae489 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -413,6 +413,7 @@ static void rescale_genWB_mem_enc( void InitSWBencBuffer_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) +#ifndef HARMONIZE_TBE { Word16 i; @@ -510,6 +511,7 @@ void InitSWBencBuffer_fx( void InitSWBencBuffer_ivas_fx( TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) +#endif { Word16 i; -- GitLab From 26c610621d2618b86d2c9e87e3429fca69e4db52 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 30 Jan 2026 11:32:21 +0100 Subject: [PATCH 6/9] updt --- lib_com/ivas_prot_fx.h | 2 ++ lib_dec/swb_tbe_dec_fx.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 39db9ec08..e2d5a52ee 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1601,6 +1601,7 @@ void ivas_hq_core_dec_fx( Word16 *Q_output ); +#ifndef HARMONIZE_TBE void ivas_HQ_FEC_Mem_update_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 *t_audio_q_fx, /*Q12*/ @@ -1616,6 +1617,7 @@ void ivas_HQ_FEC_Mem_update_fx( Word16 hq_core_type, /* i : normal or low-rate MDCT(HQ) core */ Word16 output_frame ); +#endif /* o : Consumed bits Q0 */ Word16 ivas_hq_classifier_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 6498a8262..910e2f756 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -259,13 +259,21 @@ static void rescale_genSHB_mem_dec( { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { +#ifdef HARMONIZE_TBE + hBWE_TD->state_lpc_syn_fx[i] = shl_sat( hBWE_TD->state_lpc_syn_fx[i], sf ); +#else hBWE_TD->state_lpc_syn_fx[i] = shl( hBWE_TD->state_lpc_syn_fx[i], sf ); +#endif move16(); } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { +#ifdef HARMONIZE_TBE + hBWE_TD->state_syn_shbexc_fx[i] = shl_sat( hBWE_TD->state_syn_shbexc_fx[i], sf ); +#else hBWE_TD->state_syn_shbexc_fx[i] = shl( hBWE_TD->state_syn_shbexc_fx[i], sf ); +#endif move16(); } } @@ -5542,6 +5550,7 @@ static void calc_tilt_bwe_fx_loc( return; } +#ifndef HARMONIZE_TBE /*-------------------------------------------------------------------* * swb_tbe_dec() * @@ -5588,6 +5597,7 @@ static void rescale_genSHB_mem_dec_ivas( return; } +#endif static void find_max_mem_dec_m3( Decoder_State *st, @@ -6358,7 +6368,11 @@ void ivas_swb_tbe_dec_fx( sc = sub( Q_bwe_exc, st->prev_Q_bwe_exc ); IF( sc != 0 ) { +#ifdef HARMONIZE_TBE + rescale_genSHB_mem_dec( st, sc ); +#else rescale_genSHB_mem_dec_ivas( st, sc ); +#endif } /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ -- GitLab From 1467784cd0a33552f721315fa4222e046619ec8a Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 30 Jan 2026 13:00:45 +0100 Subject: [PATCH 7/9] fix, updt --- lib_com/ivas_prot_fx.h | 4 +- lib_com/prot_fx.h | 114 +++++++++++++--------- lib_com/swb_tbe_com_fx.c | 129 ++++++++++++++----------- lib_dec/swb_tbe_dec_fx.c | 11 ++- lib_enc/evs_enc_fx.c | 4 +- lib_enc/init_enc_fx.c | 2 +- lib_enc/ivas_core_enc_fx.c | 4 + lib_enc/ivas_stereo_switching_enc_fx.c | 2 +- lib_enc/ivas_stereo_td_enc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 5 + lib_enc/swb_tbe_enc_fx.c | 27 +++++- 11 files changed, 187 insertions(+), 117 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index e2d5a52ee..b4d09d5ec 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1877,7 +1877,7 @@ void ivas_wb_tbe_dec_fx( Word16 *synth, /* o : WB synthesis/final synthesis */ Word16 *Q_synth ); -#endif + void GenShapedWBExcitation_ivas_fx( Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ @@ -1896,7 +1896,7 @@ void GenShapedWBExcitation_ivas_fx( const Word16 uv_flag, /* i : unvoiced flag */ const Word16 igf_flag ); - +#endif /* o : Q_syn_hb*/ Word16 ivas_wb_bwe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 948bfea0b..c45c2a749 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2856,11 +2856,12 @@ void Calc_rc0_h( Word16 *rc0 /* o : 1st parcor */ ); +#ifndef HARMONIZE_TBE void Calc_rc0_h_ivas_enc_fx( Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ); - +#endif void PostShortTerm_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -2895,11 +2896,11 @@ void PostShortTerm_ivas_dec_fx( ); void flip_spectrum_and_decimby4_fx( - const Word16 i[], /* i : i spectrum */ + const Word16 i[], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory */ - Word16 mem2[], /* i/o : memory */ + Word16 mem1[], /* i/o: memory */ + Word16 mem2[], /* i/o: memory */ const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core */ ); @@ -2913,69 +2914,90 @@ void GenShapedWBExcitation_fx( Word16 *mem_genSHBexc_filt_down3, /* i/o : memory */ Word16 *state_lpc_syn, /* i/o : memory */ const Word16 coder_type, /* i : coding type */ - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word16 *bwe_exc_extended, /* i : bandwidth extended exciatation */ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor */ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o : random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor */ const Word16 signal_type, const Word16 igf_flag ); +#ifdef HARMONIZE_TBE +void GenShapedWBExcitation_ivas_fx( + Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32 *mem_csfilt, /* i/o: memory Q_bwe_exc+16*/ + Word16 *mem_genSHBexc_filt_down1, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down2, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down3, /* i/o: memory Q_bwe_exc*/ + Word16 *state_lpc_syn, /* i/o: memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag /* i : IGF flag */ +); + +#endif void GenWBSynth_fx( - const Word16 *input_synspeech, /* i : i synthesized speech */ + const Word16 *input_synspeech, /* i : i synthesized speech */ Word16 *shb_syn_speech_16k, /* o : output highband compnent */ Word16 *state_lsyn_filt_shb1, /* i/o: memory */ Word16 *state_lsyn_filt_shb2 /* i/o: memory */ ); void GenShapedSHBExcitation_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc */ Word32 *mem_csfilt, /* i/o: memory */ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 element_mode, /* i : element mode */ - const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bandwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ Word16 *tbe_demph, /* i/o: de-emphasis memory */ Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: i shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: i res gain shape, Q14 */ + Word16 *lpc_shb_sf, /* i : LP coefficients */ + const Word32 shb_ener_sf_32, /* i : i shb ener, Q31 */ + Word16 *shb_res_gshape, /* i : i res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, - const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ + const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ Word16 fb_state_lpc_syn[], /* i/o: memory */ Word16 *fb_tbe_demph, /* i/o: fb de-emphasis memory */ Word16 *Q_bwe_exc, Word16 *Q_bwe_exc_fb, const Word16 Q_shb, - Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ - Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ + Word16 n_mem2, /* i : n_mem2 scale factor to adjust 24.4/32kbps memories */ + Word16 prev_Q_bwe_syn, /* i : st_fx->prev_Q_bwe_syn */ const Word32 bitrate, const Word16 prev_bfi ); void GenShapedSHBExcitation_ivas_enc_fx( - Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc_fb */ + Word16 *excSHB, /* o : synthesized shaped shb excitation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ + Word16 *White_exc16k_FB, /* o : white excitation for the Fullband extension Q_bwe_exc_fb */ Word32 *mem_csfilt, /* i/o: memory */ Word16 *mem_genSHBexc_filt_down_shb, /* i/o: memory */ Word16 *state_lpc_syn, /* i/o: memory */ - const Word16 coder_type, /* i : coding type */ - const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ + const Word16 coder_type, /* i : coding type */ + const Word16 *bwe_exc_extended, /* i : bwidth extended excitation */ Word16 bwe_seed[], /* i/o: random number generator seed */ - Word16 voice_factors[], /* i : voicing factor*/ - const Word16 extl, /* i : extension layer */ + Word16 voice_factors[], /* i : voicing factor*/ + const Word16 extl, /* i : extension layer */ Word16 *tbe_demph, /* i/o: de-emphasis memory */ Word16 *tbe_premph, /* i/o: pre-emphasis memory */ - Word16 *lpc_shb_sf, /* i: LP coefficients */ - const Word32 shb_ener_sf_32, /* i: input shb ener, Q31 */ - Word16 *shb_res_gshape, /* i: input res gain shape, Q14 */ + Word16 *lpc_shb_sf, /* i : LP coefficients */ + const Word32 shb_ener_sf_32, /* i : input shb ener, Q31 */ + Word16 *shb_res_gshape, /* i : input res gain shape, Q14 */ Word16 *shb_res, Word16 *vf_ind, const Word16 formant_fac, /* i : Formant sharpening factor [0..1] */ @@ -3087,19 +3109,19 @@ void ScaleShapedSHB_fx32( Word16 *Q_new ); void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o : synthesized shb signal */ - Word16 *overlap, /* i/o : buffer for overlap-add */ - const Word16 *subgain, /* i : subframe gain */ - const Word32 frame_gain, /* i : frame gain */ - const Word16 *win, /* i : window */ - const Word16 *subwin, /* i : subframes window */ - const Word16 Q_bwe_exc, - Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ - Word16 *Qx, /* o : newly computed Q factor for synSHB */ - Word16 prev_Qx, /* i : prev_Qx for memory scaling */ - Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o: synthesized shb signal */ + Word16 *overlap, /* i/o: buffer for overlap-add */ + const Word16 *subgain, /* i : subframe gain */ + const Word32 frame_gain, /* i : frame gain */ + const Word16 *win, /* i : window */ + const Word16 *subwin, /* i : subframes window */ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ + Word16 *Qx, /* o : newly computed Q factor for synSHB */ + Word16 prev_Qx, /* i : prev_Qx for memory scaling */ + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ); void non_linearity_fx( diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index e06c8c4f6..8f5f19d13 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -8,30 +8,29 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" #include "basop_util.h" -#include "ivas_prot_fx.h" /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ -#define POW_EXC16k_WHTND 1.14e11f /* power of random excitation, length 320 samples, uniform distribution */ -#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 // Q31 +#define POW_EXC16k_WHTND_FX_INV_SQRT 6360 // 1.14e11f in Q31 power of random excitation, length 320 samples, uniform distribution #define POW_EXC16k_WHTND_FX_INV_SQRT_IN_Q49 1667313793 // Q49 #define POW_EXC16k_WHTND_FX 178125000 // Q-6 -#define THR_ENV_ERROR_PLOSIVE 200.0f /* threshold for envelope error used in plosive detection */ #define THR_ENV_ERROR_PLOSIVE_FX 200 /* threshold for envelope error used in plosive detection Q0 */ + /*-----------------------------------------------------------------* * Local function prototypes *-----------------------------------------------------------------*/ static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[], Word16 element_mode ); static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); -static void Calc_st_filt_tbe( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); +static void Calc_st_filt_tbe_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); -void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); +static void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); + /*-------------------------------------------------------------------* * swb_tbe_reset() @@ -720,9 +719,15 @@ void Calc_rc0_h( *rc0 = negate( *rc0 ); move16(); } + + return; } +#ifdef HARMONIZE_TBE +static void Calc_rc0_h_ivas_enc_fx( +#else void Calc_rc0_h_ivas_enc_fx( +#endif Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ) @@ -781,7 +786,7 @@ void Calc_rc0_h_ivas_enc_fx( } } -static void Calc_st_filt_tbe( +static void Calc_st_filt_tbe_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ @@ -819,6 +824,8 @@ static void Calc_st_filt_tbe( move16(); } } + + return; } static void Calc_st_filt_tbe_ivas_enc_fx( @@ -859,8 +866,11 @@ static void Calc_st_filt_tbe_ivas_enc_fx( move16(); } } + + return; } +#ifndef HARMONIZE_TBE static void Calc_st_filt_tbe_ivas_dec_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ @@ -899,8 +909,10 @@ static void Calc_st_filt_tbe_ivas_dec_fx( move16(); } } -} + return; +} +#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ Word16 *sig_out, /* o : output signal */ @@ -1103,7 +1115,7 @@ void PostShortTerm_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); + Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ @@ -1223,7 +1235,11 @@ void PostShortTerm_ivas_dec_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ +#ifdef HARMONIZE_TBE + Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); +#else Calc_st_filt_tbe_ivas_dec_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); +#endif /* o: parcor0 in Q15 */ /* i/o: sig_ltp_fx in Q_bwe_exc */ @@ -1240,6 +1256,13 @@ void PostShortTerm_ivas_dec_fx( return; } + +/*-------------------------------------------------------------------* + * flip_spectrum_and_decimby4() + * + * + *-------------------------------------------------------------------*/ + void flip_spectrum_and_decimby4_fx( const Word16 input[], /* i : input spectrum Q_inp */ Word16 output[], /* o : output spectrum Q_inp */ @@ -1319,22 +1342,23 @@ void flip_spectrum_and_decimby4_fx( /*==========================================================================*/ void GenShapedWBExcitation_ivas_fx( - Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ - const Word16 *lpc_shb, /* i : lpc coefficients Q12*/ - Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ - Word32 *mem_csfilt, /* i/o : memory Q_bwe_exc+16*/ - Word16 *mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/ - Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/ - Word16 *state_lpc_syn, /* i/o : memory Q_bwe_exc*/ - const Word16 coder_type, /* i : coding type */ - const Word16 element_mode, /* i : element mode */ - const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ - const Word16 Q_bwe_exc, - Word16 bwe_seed[], /* i/o : random number generator seed */ - const Word16 voice_factors[], /* i : voicing factor Q15*/ - const Word16 uv_flag, /* i : unvoiced flag */ - const Word16 igf_flag ) + Word16 *excSHB, /* o : synthesized shaped shb exctiation Q_bwe_exc*/ + const Word16 *lpc_shb, /* i : lpc coefficients Q12 */ + Word16 *exc4kWhtnd, /* o : whitened synthesized shb excitation Q_bwe_exc*/ + Word32 *mem_csfilt, /* i/o: memory Q_bwe_exc+16*/ + Word16 *mem_genSHBexc_filt_down1, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down2, /* i/o: memory Q_bwe_exc*/ + Word16 *mem_genSHBexc_filt_down3, /* i/o: memory Q_bwe_exc*/ + Word16 *state_lpc_syn, /* i/o: memory Q_bwe_exc*/ + const Word16 coder_type, /* i : coding type */ + const Word16 element_mode, /* i : element mode */ + const Word16 *bwe_exc_extended, /* i : bwidth extended exciatation Q_bwe_exc*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 bwe_seed[], /* i/o: random number generator seed */ + const Word16 voice_factors[], /* i : voicing factor Q15*/ + const Word16 uv_flag, /* i : unvoiced flag */ + const Word16 igf_flag /* i : IGF flag */ +) { Word16 i, j, k; Word16 wht_fil_mem[LPC_WHTN_ORDER_WB]; @@ -4868,7 +4892,6 @@ void ScaleShapedSHB_fx( } } - Q_gFr_norm = norm_l( frame_gain ); if ( frame_gain == 0 ) { @@ -5106,19 +5129,19 @@ void ScaleShapedSHB_fx32( *-------------------------------------------------------------------*/ void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ - Word16 *synSHB, /* i/o : synthesized shb signal Q_bwe_exc/Qx */ - Word16 *overlap, /* i/o : buffer for overlap-add Q_bwe_exc/Qx */ - const Word16 *subgain, /* i : subframe gain Q15*/ - const Word32 frame_gain, /* i : frame gain Q18 */ - const Word16 *win, /* i : window Q15*/ - const Word16 *subwin, /* i : subframes window Q15*/ - const Word16 Q_bwe_exc, - Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ - Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ - Word16 *Qx, /* o : newly computed Q factor for synSHB */ - Word16 prev_Qx, /* i : prev_Qx for memory scaling */ - Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ + const Word16 length, /* i : SHB overlap length */ + Word16 *synSHB, /* i/o: synthesized shb signal Q_bwe_exc/Qx*/ + Word16 *overlap, /* i/o: buffer for overlap-add Q_bwe_exc/Qx*/ + const Word16 *subgain, /* i : subframe gain Q15*/ + const Word32 frame_gain, /* i : frame gain Q18*/ + const Word16 *win, /* i : window Q15*/ + const Word16 *subwin, /* i : subframes window Q15*/ + const Word16 Q_bwe_exc, /* i : Q for memories */ + Word16 L_frame, /* i : Frame length - determines whether 12.8 or 16kHz core in-use */ + Word16 dynQ, /* i : indicate whether output is dynamic Q, or Q0 */ + Word16 *Qx, /* o : newly computed Q factor for synSHB */ + Word16 prev_Qx, /* i : prev_Qx for memory scaling */ + Word32 *Hilbert_Mem /* i : Hilbert memory used for computing Qx */ ) { const Word16 *skip; @@ -5128,6 +5151,7 @@ void ScaleShapedWB_fx( Word16 sum_gain; Word32 L_tmp; Word16 max_val, abs_sig, sc1, sc2, shift, max_headroom, min_shift, max_shift, max_shift2; + /* Init */ set32_fx( mod_syn, 0, L_FRAME16k + L_SHB_LAHEAD ); @@ -5225,7 +5249,6 @@ void ScaleShapedWB_fx( } } - max_val = 0; move16(); FOR( i = 0; i < l_frame + l_shb_lahead; i++ ) @@ -5997,6 +6020,7 @@ void interp_code_5over2_fx( Ltemp = L_mult( inp_code_fx[kk], factor_j_fx[1] ); /*Q(16+x) */ interp_code_fx[i + 1] = round_fx( Ltemp ); /*Qx */ move16(); + return; } @@ -6224,7 +6248,6 @@ void elliptic_bpf_48k_generic_fx( } /*IsUpsampled3*/ - memory_fx2[0][0] = input_fx[L_FRAME48k - 4]; memory_fx2[0][1] = input_fx[L_FRAME48k - 3]; memory_fx2[0][2] = input_fx[L_FRAME48k - 2]; @@ -6272,7 +6295,6 @@ void elliptic_bpf_48k_generic_fx( } } - Q_temp = norm_l( L_tmpMax ); Q_temp = sub( Q_temp, 4 ); Scale_sig32( L_tmp2, 960, Q_temp ); @@ -6334,7 +6356,6 @@ void elliptic_bpf_48k_generic_fx( } } - memory_fx2[2][0] = L_tmp2[L_FRAME48k - 4]; memory_fx2[2][1] = L_tmp2[L_FRAME48k - 3]; memory_fx2[2][2] = L_tmp2[L_FRAME48k - 2]; @@ -6372,6 +6393,8 @@ void elliptic_bpf_48k_generic_fx( return; } + + /*-------------------------------------------------------------------* * synthesise_fb_high_band() * @@ -6428,20 +6451,12 @@ void synthesise_fb_high_band_fx( IF( EQ_16( L_frame, L_FRAME16k ) ) { /* for 16kHz ACELP core */ - elliptic_bpf_48k_generic_fx( - element_mode, - 1, // IsUpsampled3 - excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_3_fx - - ); + elliptic_bpf_48k_generic_fx( element_mode, 1, /* IsUpsampled3 */ excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_3_fx ); } ELSE { /* for 12.8kHz ACELP core */ - elliptic_bpf_48k_generic_fx( - element_mode, - 1, // IsUpsampled3 - excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_1_fx ); + elliptic_bpf_48k_generic_fx( element_mode, 1, /* IsUpsampled3 */ excitation_in_interp3, &exp_tmp, tmp, bpf_memory, bpf_memory_Q, full_band_bpf_1_fx ); } /* temp1 = sum2_f( tmp, L_FRAME48k ) + 0.001f */ temp1 = sum2_fx_mod( tmp, L_FRAME48k ); @@ -6524,15 +6539,18 @@ void synthesise_fb_high_band_fx( move16(); } } + return; } + /*-------------------------------------------------------------------* * Estimate_mix_factors_fx() * * * * Estimate mix factors for SHB excitation generation * *-------------------------------------------------------------------*/ -void Estimate_mix_factors_fx( + +static void Estimate_mix_factors_fx( const Word16 *shb_res, /* i : SHB LP residual in Q = Q_shb */ const Word16 Q_shb, const Word16 *exc16kWhtnd, /* i : SHB transformed low band excitation Q_bwe_exc */ @@ -6596,7 +6614,6 @@ void Estimate_mix_factors_fx( /* (Q_bwe_exc) */ } - length = L_FRAME16k; move16(); temp_p1_p2 = Dot_product( temp_numer1, temp_numer2, length ); /* 2*(Q_bwe_exc)+1 */ @@ -6672,6 +6689,7 @@ void Estimate_mix_factors_fx( return; } + /*======================================================================================*/ /* FUNCTION : prep_tbe_exc_fx() */ /*--------------------------------------------------------------------------------------*/ @@ -6721,7 +6739,6 @@ void prep_tbe_exc_fx( const Word16 idchan, /* i : channel ID */ const Word16 flag_TD_BWE, /* i : flag indicating whether hTD_BWE exists */ const Word16 tdm_LRTD_flag /* i : LRTD stereo mode flag */ - ) { Word16 i; diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 910e2f756..2d99d9a4a 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -7,7 +7,6 @@ #include "rom_com.h" #include "prot_fx.h" #include "rom_dec.h" -#include "stl.h" #include "ivas_prot_fx.h" /*-----------------------------------------------------------------* @@ -278,9 +277,6 @@ static void rescale_genSHB_mem_dec( } } - if ( EQ_16( st_fx->extl, FB_TBE ) ) - { - } hBWE_TD->mem_csfilt_fx[0] = L_shl( hBWE_TD->mem_csfilt_fx[0], sf ); move32(); @@ -292,6 +288,7 @@ static void rescale_genSHB_mem_dec( return; } + static void find_max_mem_wb( Decoder_State *st_fx, Word16 *n_mem ) @@ -482,6 +479,12 @@ static void InitSWBdecBuffer_fx( } +/*-------------------------------------------------------------------* + * ResetSHBbuffer_Dec() + * + * + *-------------------------------------------------------------------*/ + void ResetSHBbuffer_Dec_fx( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ const Word16 extl /* i : BWE extension layer */ diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 18cd6b96f..45e58c5e8 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -425,8 +425,8 @@ ivas_error evs_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ -#ifdef HARMONIZE_TBEaa - wb_tbe_enc_ivas_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); +#ifdef HARMONIZE_TBE + wb_tbe_enc_fx( st, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf ); #else wb_tbe_enc_fx( st, st->coder_type, hb_speech, bwe_exc_extended, Q_new, voice_factors, pitch_buf, st->voicing_fx ); #endif diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 6781802a4..b30b95806 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -857,7 +857,7 @@ ivas_error init_encoder_fx( #endif } #ifdef HARMONIZE_TBE - InitSWBencBuffer_fx( st->hBWE_TD ); + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); #endif ResetSHBbuffer_Enc_fx( st->hBWE_TD ); } diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index b08dd6f67..214daa265 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -666,7 +666,11 @@ ivas_error ivas_core_enc_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE encoder */ +#ifdef HARMONIZE_TBE + wb_tbe_enc_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); +#else wb_tbe_enc_ivas_fx( st, hb_speech_fx, bwe_exc_extended_fx[n], Q_new[n], voice_factors_fx[n], pitch_buf_fx[n] ); +#endif } ELSE IF( EQ_16( st->extl, WB_BWE ) && n == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { diff --git a/lib_enc/ivas_stereo_switching_enc_fx.c b/lib_enc/ivas_stereo_switching_enc_fx.c index 58f1fc7a5..a4a3080a7 100644 --- a/lib_enc/ivas_stereo_switching_enc_fx.c +++ b/lib_enc/ivas_stereo_switching_enc_fx.c @@ -435,7 +435,7 @@ ivas_error stereo_memory_enc_fx( } #ifdef HARMONIZE_TBE - InitSWBencBuffer_fx( st->hBWE_TD ); + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); #else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); #endif diff --git a/lib_enc/ivas_stereo_td_enc_fx.c b/lib_enc/ivas_stereo_td_enc_fx.c index be0234c41..4e3b5fdd1 100644 --- a/lib_enc/ivas_stereo_td_enc_fx.c +++ b/lib_enc/ivas_stereo_td_enc_fx.c @@ -326,7 +326,7 @@ ivas_error stereo_set_tdm_fx( } #ifdef HARMONIZE_TBE - InitSWBencBuffer_fx( st->hBWE_TD ); + InitSWBencBuffer_fx( st->element_mode, st->hBWE_TD ); #else InitSWBencBuffer_ivas_fx( st->hBWE_TD ); #endif diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 7861d0d64..49c438515 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -700,6 +700,7 @@ void wb_pre_proc_ivas_fx( ); void wb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz */ @@ -711,6 +712,7 @@ void wb_tbe_enc_fx( ); void wb_tbe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ @@ -3969,6 +3971,9 @@ void noise_est_init_ivas_fx( ); void InitSWBencBuffer_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 7bc5ae489..e11cd8d7b 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -18,6 +18,7 @@ #define ENVSHBRES_ACORR_MIN 40 /* minimum lag for calculating autocorrelation function on SHB residual TD envelope */ #define ENVSHBRES_ACORR_MAX 80 /* maximum lag for calculating autocorrelation function on SHB residual TD envelope */ + /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ @@ -411,6 +412,9 @@ static void rescale_genWB_mem_enc( *-------------------------------------------------------------------*/ void InitSWBencBuffer_fx( +#ifdef HARMONIZE_TBE + const Word16 element_mode, /* i : element mode */ +#endif TD_BWE_ENC_HANDLE hBWE_TD /* i/o: TD BWE data handle */ ) #ifndef HARMONIZE_TBE @@ -593,10 +597,23 @@ void InitSWBencBuffer_ivas_fx( hBWE_TD->prev_fb_energy_fx_Q = 0; move16(); - hBWE_TD->prev_Q_bwe_exc = 15; - move16(); - hBWE_TD->prev_Q_bwe_syn = 15; - move16(); +#ifdef HARMONIZE_TBE + IF( element_mode == EVS_MONO ) + { + hBWE_TD->prev_Q_bwe_exc = 31; + move16(); + hBWE_TD->prev_Q_bwe_syn = 31; + move16(); + } + ELSE +#endif + { + hBWE_TD->prev_Q_bwe_exc = 51; + move16(); + hBWE_TD->prev_Q_bwe_syn = 15; + move16(); + } + set16_fx( hBWE_TD->prev_lsp_wb_fx, 0, 6 ); set16_fx( hBWE_TD->prev_lsp_wb_temp_fx, 0, 6 ); set16_fx( hBWE_TD->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); @@ -676,6 +693,7 @@ void ResetSHBbuffer_Enc_fx( #define WBTBE_LPCWIN_LENGTH ( L_LOOK_12k8 + L_SUBFR + L_FRAME ) * 5 / 16 - 1 void wb_tbe_enc_fx( +#ifndef HARMONIZE_TBE Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz at Q-1 */ @@ -1276,6 +1294,7 @@ void wb_tbe_enc_fx( /*==========================================================================*/ void wb_tbe_enc_ivas_fx( +#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 *hb_speech, /* i : HB target signal (6-8kHz) at 16kHz Q(-1) */ const Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation Q(2*Q_new) */ -- GitLab From a1e21be182aa40399ece7079869025a76d2f644b Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 30 Jan 2026 14:16:23 +0100 Subject: [PATCH 8/9] fix --- lib_enc/swb_tbe_enc_fx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index e11cd8d7b..3b7f0956d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -6039,10 +6039,11 @@ static void Quant_shb_ener_sf_ivas_fx( temp_shb_ener_sf_fx = 0; move16(); idxSubEner_fx = usquant_fx( tmp, &temp_shb_ener_sf_fx, 0, 43, 1 << NUM_BITS_SHB_ENER_SF ); /* 43 = 0.042f in Q10 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q11 */ - + /* o: temp_shb_ener_sf_fx in Q11 */ +#ifdef HARMONIZE_TBE Q_fac = -Q9; move16(); +#endif } /* shb_ener_sf_fx[0] = pow(10.0, temp_shb_ener_sf_fx ); */ -- GitLab From a372743d752c038c688705d1cfd69b76231499c1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 30 Jan 2026 15:28:47 +0100 Subject: [PATCH 9/9] fix --- lib_dec/ivas_core_dec_fx.c | 1 - lib_enc/ivas_core_enc_fx.c | 2 +- lib_enc/swb_tbe_enc_fx.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 4f813e50c..a7eebafb5 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1086,7 +1086,6 @@ ivas_error ivas_core_dec_fx( #ifdef HARMONIZE_TBE fb_tbe_dec_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, NULL, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); #else - 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 ); #endif } diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 214daa265..2880c054a 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -759,7 +759,7 @@ ivas_error ivas_core_enc_fx( Copy_Scale_sig_16_32_no_sat( shb_speech_fx, shb_speech_fx32, L_FRAME16k, shift ); // Q_shb_spch Q_shb_spch = add( Q_shb_spch, shift ); #endif - IF( st->hBWE_FD ) // VE: to be moved to the end of swb_pre_proc_ivas_fx() + IF( st->hBWE_FD ) { shift = getScaleFactor16( st->hBWE_FD->L_old_wtda_swb_fx, L_FRAME48k ); st->Q_old_wtda = add( st->Q_old_wtda, shift ); diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 3b7f0956d..d6fe95325 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -608,7 +608,7 @@ void InitSWBencBuffer_ivas_fx( ELSE #endif { - hBWE_TD->prev_Q_bwe_exc = 51; + hBWE_TD->prev_Q_bwe_exc = 15; move16(); hBWE_TD->prev_Q_bwe_syn = 15; move16(); -- GitLab