From 5427429c49b86b6064bf45412b36f9e6c35abb89 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 26 Feb 2026 14:23:56 +0100 Subject: [PATCH 01/12] HARMONIZE_TBE3 --- lib_com/options.h | 1 + lib_com/prot_fx.h | 27 ++- lib_dec/evs_dec_fx.c | 13 +- lib_dec/ivas_core_dec_fx.c | 4 + lib_dec/swb_tbe_dec_fx.c | 481 +++++++++++++++++++++++++++++++------ 5 files changed, 440 insertions(+), 86 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 10396a5c3..baceb3e2c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -96,6 +96,7 @@ #define HARM_2336_DOTP /* VA: basop 2336; Harmonisation of some dot_product function + some BE optimisation */ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ +#define HARMONIZE_TBE3 /* VA: basop issue 2399: Remove duplicated code: TBE, step 3 */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a4a32366e..be82ef2c5 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9829,17 +9829,34 @@ void v_sub32_fx( const Word16 N /* i : Vector length */ ); +#ifdef HARMONIZE_TBE3 void swb_tbe_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word16 *Q_white_exc, /* o : Q-factor of White_exc16k_fx */ + Word16 *synth_fx16, /* o : SHB synthesis/final synthesis 16-bit : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ + Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ + Word16 *pitch_buf_fx /* i : Q6 */ +); +#else +void swb_tbe_dec_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ Word16 Q_exc, const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ Word16 *pitch_buf_fx, /* i : Q6 */ - Word16 *Q_white_exc ); + Word16 *Q_white_exc /* o : Q-factor of White_exc16k_fx */ +); +#endif Word16 swb_bwe_dec_fx32( Decoder_State *st_fx, /* i/o: decoder state structure */ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 20f6e7f70..3bba7013b 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -416,8 +416,13 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || ( NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) && GT_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->core, ACELP_CORE ) && GE_32( st_fx->output_Fs, 32000 ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) ) { /* SWB TBE decoder */ +#ifdef HARMONIZE_TBE3 + swb_tbe_dec_ivas_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, + old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, pitch_buf_fx, &hb_synth_fx_exp ); +#else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); +#endif /* FB TBE decoder */ test(); @@ -853,8 +858,14 @@ ivas_error evs_dec_fx( ELSE IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) { /* SWB TBE decoder */ +#ifdef HARMONIZE_TBE3 + swb_tbe_dec_ivas_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, + hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, pitch_buf_fx, &hb_synth_fx_exp ); +#else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); +#endif + test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) { @@ -1352,7 +1363,7 @@ ivas_error evs_dec_fx( Scale_sig32( mem_hp20_in_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ hp20( synth_fx, 1 /*stride*/, output_frame, mem_hp20_in_fx, st_fx->output_Fs ); #else - Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ + Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ hp20( synth_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); #endif diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index c44b34c17..d42445dfc 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1000,7 +1000,11 @@ ivas_error ivas_core_dec_fx( IF( flag_swb_tbe ) { /* SWB TBE decoder */ +#ifdef HARMONIZE_TBE3 + swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, &Q_white_exc, NULL, hb_synth_32_fx[n], pitch_buf_fx[n], &tmp16 ); +#else swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); +#endif Copy_Scale_sig_16_32_no_sat( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, hBWE_TD->prev_Q_bwe_syn2 ) ); // Q11 Copy_Scale_sig_32_16( hBWE_TD->old_tbe_synth_fx_32, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 60f22396e..407555b1b 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -4531,6 +4531,21 @@ static void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ +#ifdef HARMONIZE_TBE3 +void swb_tbe_dec_ivas_fx( + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word16 *Q_white_exc, /* o : Q-factor of White_exc16k_fx */ + Word16 *synth_fx16, /* o : SHB synthesis/final synthesis 16-bit : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ + Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ + Word16 *pitch_buf_fx /* i : Q6 */ +) +#else void swb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ @@ -4539,9 +4554,11 @@ void swb_tbe_dec_ivas_fx( const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ Word16 *pitch_buf_fx, /* i : Q6 */ - Word16 *Q_white_exc ) + Word16 *Q_white_exc /* o : Q-factor of White_exc16k_fx */ +) +#endif { Word16 i, j, cnt, n; Word16 stemp; @@ -4551,6 +4568,9 @@ void swb_tbe_dec_ivas_fx( Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; Word16 lsf_shb_fx[LPC_SHB_ORDER], lpc_shb_fx[LPC_SHB_ORDER + 1], GainShape_fx[NUM_SHB_SUBFR]; // Q12,Q12,Q15 Word32 GainFrame_fx; // Q18 +#ifdef HARMONIZE_TBE3 + Word16 error_fx16[L_FRAME32k]; +#endif Word32 error_fx[L_FRAME32k]; Word16 ener_fx; Word32 L_ener; @@ -4605,6 +4625,10 @@ void swb_tbe_dec_ivas_fx( Word16 expa, expb; Word16 fraca, fracb; Word16 exp_ener, inv_ener; +#ifdef HARMONIZE_TBE3 + Word16 Q_exc = st->Q_exc; + move16(); +#endif hBWE_TD = st->hBWE_TD; @@ -4642,9 +4666,19 @@ void swb_tbe_dec_ivas_fx( move16(); } - /* find tilt */ - calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); - tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) ); +/* find tilt */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k_fx16, st->Q_syn2, st->L_frame ); + tilt_swb_fec_fx = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); + } + ELSE +#endif + { + calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); + tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) ); + } test(); if ( st->bfi && st->clas_dec != UNVOICED_CLAS ) { @@ -4865,12 +4899,13 @@ void swb_tbe_dec_ivas_fx( } } } - ELSE + ELSE /* FER concealment of TBE parameters */ { Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb_fx, LPC_SHB_ORDER ); test(); IF( EQ_16( st->codec_mode, MODE1 ) && ( st->element_mode == EVS_MONO ) ) { + /* Gradient based GS estimation */ gradientGainShape( st, GainShape_fx, &GainFrame_fx ); } ELSE @@ -4906,6 +4941,7 @@ void swb_tbe_dec_ivas_fx( } } + /* FER concealment for SWB_TBE_2k8 */ IF( GE_32( st->extl_brate, SWB_TBE_2k8 ) ) { test(); @@ -4977,10 +5013,25 @@ void swb_tbe_dec_ivas_fx( /* get the gainshape delay */ Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) +#ifdef HARMONIZE_TBE3 + test(); + test(); + IF( st->element_mode == EVS_MONO && ( ( st->rf_flag != 0 ) || EQ_32( st->total_brate, ACELP_9k60 ) ) ) { - hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape_fx[i * 4]; /*Q15*/ - move16(); + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape_fx[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); + move16(); + } + } + ELSE +#endif + { + FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) + { + hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape_fx[i * 4]; /*Q15*/ + move16(); + } } L_tmp = L_mult( voice_factors_fx[0], 8192 ); @@ -5008,12 +5059,13 @@ void swb_tbe_dec_ivas_fx( } } +#ifndef HARMONIZE_TBE3 // VE: TBV!!! test(); IF( st->use_partial_copy && st->nelp_mode_dec ) { set16_fx( vf_modified_fx, 0, NB_SUBFR16k ); } - +#endif /* SHB LSF from current frame; and convert to LSP for interpolation */ E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); @@ -5162,8 +5214,17 @@ void swb_tbe_dec_ivas_fx( ptr_lsp_interp_coef_fx += 2; tmp = i_mult( j, ( LPC_SHB_ORDER + 1 ) ); + /* convert LSPs to LP coefficients */ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); + +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + /* Bring the LPCs to Q12 */ + Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); + } +#endif } } @@ -5189,25 +5250,30 @@ void swb_tbe_dec_ivas_fx( Copy( lsf_shb_fx, st->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); } - /* convert LSPs back into LP coeffs */ - E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ - lpc_shb_fx[0] = ONE_IN_Q12; - move16(); - - test(); - IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) - { - Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 - vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ - } - ELSE +#ifdef HARMONIZE_TBE3 + IF( st->element_mode > EVS_MONO ) +#endif { - vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ + /* convert LSPs back into LP coeffs */ + E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ + lpc_shb_fx[0] = ONE_IN_Q12; + move16(); + + test(); + IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) + { + Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 + vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ + /* i: mixFactors_fx in Q15 */ + /* o: vind in Q0 */ + } + ELSE + { + vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/ + /* i: mixFactors_fx in Q15 */ + /* o: vind in Q0 */ + } } /* Determine formant PF strength */ @@ -5238,6 +5304,7 @@ void swb_tbe_dec_ivas_fx( move16(); } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); + /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ find_max_mem_dec( st, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ tmp = add( st->prev_Q_bwe_exc, n_mem ); @@ -5279,7 +5346,22 @@ void swb_tbe_dec_ivas_fx( Q_shb = 0; move16(); - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + IF( GT_32( st->total_brate, ACELP_32k ) ) + { + FOR( j = 0; j < 4; j++ ) + { + Copy( lpc_shb_fx, &lpc_shb_sf_fx[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); + } + } + } + ELSE +#endif + { + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + } #ifdef HARMONIZE_TBE2 GenShapedSHBExcitation_ivas_fx( DEC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, @@ -5303,6 +5385,7 @@ void swb_tbe_dec_ivas_fx( *Q_white_exc = Q_bwe_exc_fb; move16(); + IF( EQ_16( st->extl, FB_TBE ) ) { hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; @@ -5322,6 +5405,7 @@ void swb_tbe_dec_ivas_fx( hBWE_TD->mem_stp_swb_fx[i] = shl_sat( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); move16(); } + /* fill-in missing SHB excitation */ test(); test(); @@ -5336,13 +5420,27 @@ void swb_tbe_dec_ivas_fx( } test(); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO || ( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) +#endif { FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { /* TD BWE post-processing */ - PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); + } + ELSE +#endif + { + PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); + } } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ @@ -5375,10 +5473,7 @@ void swb_tbe_dec_ivas_fx( exp = 0; move16(); } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ + IF( EQ_16( st->element_mode, EVS_MONO ) ) { FOR( ; i < L_SHB_LAHEAD + 10; i++ ) @@ -5452,10 +5547,32 @@ void swb_tbe_dec_ivas_fx( L_ener = L_add_sat( L_ener, L_shr( ener_tmp_fx[i], 2 ) ); /* 2*Q_bwe_exc */ } } - ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ + } + ELSE +#endif + { + ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ + } + /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + ener_fx = mult( ener_fx, 11587 ); + if ( GT_16( st->tilt_swb_fx, 16384 ) ) + { + st->prev_fractive = 1; + move16(); + } + } + +#endif IF( is_fractive == 0 ) { IF( GT_16( st->tilt_wb_fx, 2048 ) ) /*assuming st->tilt_wb_fx in Q11*/ @@ -5499,10 +5616,22 @@ void swb_tbe_dec_ivas_fx( IF( ener_fx != 0 ) { - L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/ - exp_ener = norm_s( ener_fx ); - tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ - inv_ener = shr( div_s( 16384, tmp ), 1 ); /*Q(15+14-2-exp-1) = 26 - exp*/ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 14 ) ); /* 3+11 +st->Q_syn2 -14 = st->Q_syn2*/ + exp_ener = norm_s( ener_fx ); + tmp = shl( ener_fx, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ + } + ELSE +#endif + { + L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/ + exp_ener = norm_s( ener_fx ); + tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ + inv_ener = shr( div_s( 16384, tmp ), 1 ); /*Q(15+14-2-exp-1) = 26 - exp*/ + } test(); IF( GT_32( L_tmp, st->enerLH_fx ) ) /*st->Q_syn2*/ @@ -5517,8 +5646,17 @@ void swb_tbe_dec_ivas_fx( move16(); /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } - L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + } + ELSE +#endif + { + GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ + } } ELSE { @@ -5578,13 +5716,34 @@ void swb_tbe_dec_ivas_fx( { ener_fx = s_max( 1, ener_fx ); exp_ener = norm_s( ener_fx ); - tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/ - prev_ener_ratio_fx = L_shr_sat( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + tmp = shl( ener_fx, exp_ener ); /*Q(3+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp)*/ + prev_ener_ratio_fx = L_shr_sat( L_mult0( st->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ + } + ELSE +#endif + { + tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ + inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/ + prev_ener_ratio_fx = L_shr_sat( L_mult0( st->prev_ener_shb_fx, inv_ener ), add( sub( 9, exp_ener ), 1 ) ); /*Q: 1+27-exp-9+exp-1 = 18 */ + } } IF( EQ_16( st->nbLostCmpt, 1 ) ) { +#ifdef HARMONIZE_TBE3 + Word16 thr_tilt_swb = 4096; + move16(); + if ( st->element_mode == EVS_MONO ) + { + thr_tilt_swb = 16384; + move16(); + } +#endif + test(); test(); test(); @@ -5621,8 +5780,13 @@ void swb_tbe_dec_ivas_fx( GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } } +#ifdef HARMONIZE_TBE3 + ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, thr_tilt_swb ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && + ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) ) +#else ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 4096 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) ) +#endif { GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); } @@ -5756,7 +5920,16 @@ void swb_tbe_dec_ivas_fx( move16(); IF( i != 0 ) { - idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); +#ifdef HARMONIZE_TBE3 // VE: TBV + IF( st->element_mode == EVS_MONO ) + { + idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + } + ELSE +#endif + { + idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); + } } GainShape_fx[i] = GainShape_tmp_fx[idx]; move16(); @@ -5770,10 +5943,14 @@ void swb_tbe_dec_ivas_fx( hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; move16(); - /* Gain shape smoothing after quantization */ test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st->element_mode != EVS_MONO && ( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) +#endif { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -5824,7 +6001,17 @@ void swb_tbe_dec_ivas_fx( Word16 n_mem3_new = 0; move16(); - find_max_mem_dec_m3( st, &n_mem3_new ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + n_mem3_new = n_mem3; + move16(); + } + ELSE +#endif + { + find_max_mem_dec_m3( st, &n_mem3_new ); + } ScaleShapedSHB_fx( SHB_OVERLAP_LEN, shaped_shb_excitation_fx, /* i/o: Q_bwe_exc */ @@ -5847,10 +6034,23 @@ void swb_tbe_dec_ivas_fx( max_val = 0; move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + FOR( i = 0; i < L_FRAME16k; i++ ) + { + max_val = s_max( max_val, shaped_shb_excitation_fx[i] ); /* Q0 */ + } + } + ELSE +#endif { - max_val = s_max( max_val, abs_s( shaped_shb_excitation_fx[i] ) ); /* Q0 */ + FOR( i = 0; i < L_FRAME16k; i++ ) + { + max_val = s_max( max_val, abs_s( shaped_shb_excitation_fx[i] ) ); /* Q0 */ + } } + IF( max_val == 0 ) { curr_frame_pow_fx = 0; @@ -6114,16 +6314,57 @@ void swb_tbe_dec_ivas_fx( set16_fx( st->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ } - FOR( i = 0; i < L_FRAME16k; i++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], sub( Q11, Q_bwe_exc ) ); - move32(); + /* rescale the memories if Q_bwe_exc is different from previous frame */ + sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn2 ); + IF( sc != 0 ) + { + FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) + { + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); + move16(); + } + + IF( EQ_16( st->L_frame, L_FRAME ) ) + { + FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) + { + hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); + move32(); + } + } + IF( EQ_32( st->output_Fs, 48000 ) ) + { + Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); + } + IF( EQ_32( st->output_Fs, 16000 ) ) + { + Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); + } + } + + GenSHBSynth_fx( shaped_shb_excitation_fx, error_fx16, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, + hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); + + Copy( error_fx16 + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); } + ELSE +#endif + { + FOR( i = 0; i < L_FRAME16k; i++ ) + { + shaped_shb_excitation_fx_32[i] = L_shl( shaped_shb_excitation_fx[i], sub( Q11, Q_bwe_exc ) ); + move32(); + } + + /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ + GenSHBSynth_fx32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); - /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ - GenSHBSynth_fx32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) ); - Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH ); + Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) ); + Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH ); + } /* resample SHB synthesis (if needed) and scale down */ synth_scale_fx = 32767; @@ -6149,16 +6390,37 @@ void swb_tbe_dec_ivas_fx( tmp1 = 0; move16(); - Word32 idx32 = L_shr_r( 0x00333333, 10 ); /*NUM_SHB_SUBFR/L_FRAME16k*/ // Q16 - - FOR( i = 0; i < L_FRAME16k; i++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - Word16 idx; - idx = extract_h( imult3216( idx32, i ) ); /*Q0*/ - L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ - move16(); - tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + FOR( i = 0; i < L_FRAME16k; i++ ) + { + Word16 idx = 0; + IF( i != 0 ) + { + idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); + } + L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); + tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + } + } + ELSE +#endif + { + Word32 idx32 = L_shr_r( 0x00333333, 10 ); + /*NUM_SHB_SUBFR/L_FRAME16k*/ // Q16 + + FOR( i = 0; i < L_FRAME16k; i++ ) + { + Word16 idx; + idx = extract_h( imult3216( idx32, i ) ); /*Q0*/ + L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[idx] ); /* Q : 18 + tmp +15 -15*/ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + move16(); + tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); + } } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ @@ -6179,43 +6441,98 @@ void swb_tbe_dec_ivas_fx( move16(); } - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - FOR( i = 0; i < L_FRAME32k; i++ ) + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { - error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); - move32(); + + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx16[i] = mult_r( error_fx16[i], synth_scale_fx ); + move16(); + } + } + + interpolate_3_over_2_allpass_fx( error_fx16, L_FRAME32k, synth_fx16, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); + } + ELSE +#endif + { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); + move32(); + } } + + interpolate_3_over_2_allpass_fx32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } - interpolate_3_over_2_allpass_fx32( error_fx, L_FRAME32k, synth_fx, hBWE_TD->int_3_over_2_tbemem_dec_fx_32 ); } ELSE IF( EQ_32( st->output_Fs, 32000 ) ) { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - FOR( i = 0; i < L_FRAME32k; i++ ) + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { - synth_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); - move32(); /*Qx*/ + FOR( i = 0; i < L_FRAME32k; i++ ) + { + synth_fx16[i] = mult_r( synth_scale_fx, error_fx16[i] ); + move16(); /*Qx*/ + } } + + Copy( error_fx16, synth_fx16, L_FRAME32k ); } ELSE +#endif { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + synth_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); + move32(); /*Qx*/ + } + } + Copy32( error_fx, synth_fx, L_FRAME32k ); } } ELSE IF( EQ_32( st->output_Fs, 16000 ) ) { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - FOR( i = 0; i < L_FRAME32k; i++ ) + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { - error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); - move32(); + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx16[i] = mult_r( error_fx16[i], synth_scale_fx ); + move16(); + } } + + Decimate_allpass_steep_fx( error_fx16, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth_fx16 ); } + ELSE +#endif + { + IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ + { + FOR( i = 0; i < L_FRAME32k; i++ ) + { + error_fx[i] = Mpy_32_16_1( error_fx[i], synth_scale_fx ); + move32(); + } + } - Decimate_allpass_steep_fx32( error_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, synth_fx ); + Decimate_allpass_steep_fx32( error_fx, hBWE_TD->mem_resamp_HB_32k_fx_32, L_FRAME32k, synth_fx ); + } } /* Update previous frame parameters for FEC */ @@ -6254,6 +6571,10 @@ void swb_tbe_dec_ivas_fx( move16(); hBWE_TD->prev_Qx = Q_bwe_exc; move16(); +#ifdef HARMONIZE_TBE3 + *Q_synth = Q_bwe_exc; + move16(); +#endif return; } -- GitLab From 65720d90d2e38341d41f7a59839a0e0fa71a5965 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Feb 2026 08:27:02 +0100 Subject: [PATCH 02/12] HARMONIZE_TBE3 --- lib_dec/evs_dec_fx.c | 4 +- lib_dec/ivas_core_dec_fx.c | 2 +- lib_dec/swb_tbe_dec_fx.c | 155 ++++++++++++++++++++++--------------- 3 files changed, 96 insertions(+), 65 deletions(-) diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 3bba7013b..d7e05c938 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -418,7 +418,7 @@ ivas_error evs_dec_fx( /* SWB TBE decoder */ #ifdef HARMONIZE_TBE3 swb_tbe_dec_ivas_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, - old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, pitch_buf_fx, &hb_synth_fx_exp ); + old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); #else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); @@ -860,7 +860,7 @@ ivas_error evs_dec_fx( /* SWB TBE decoder */ #ifdef HARMONIZE_TBE3 swb_tbe_dec_ivas_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, - hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, pitch_buf_fx, &hb_synth_fx_exp ); + hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); #else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index d42445dfc..c379c0ee6 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1001,7 +1001,7 @@ ivas_error ivas_core_dec_fx( { /* SWB TBE decoder */ #ifdef HARMONIZE_TBE3 - swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, &Q_white_exc, NULL, hb_synth_32_fx[n], pitch_buf_fx[n], &tmp16 ); + swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, &Q_white_exc, NULL, hb_synth_32_fx[n], &tmp16, pitch_buf_fx[n] ); #else swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); #endif diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 407555b1b..31f5978da 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -5059,13 +5059,6 @@ void swb_tbe_dec_ivas_fx( } } -#ifndef HARMONIZE_TBE3 // VE: TBV!!! - test(); - IF( st->use_partial_copy && st->nelp_mode_dec ) - { - set16_fx( vf_modified_fx, 0, NB_SUBFR16k ); - } -#endif /* SHB LSF from current frame; and convert to LSP for interpolation */ E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); @@ -5186,8 +5179,13 @@ void swb_tbe_dec_ivas_fx( Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); } - /* convert from lsp to lsf */ - lsp2lsf_fx( lsp_temp_fx, lsf_shb_fx, LPC_SHB_ORDER, 1 ); +#ifdef HARMONIZE_TBE3 + IF( st->element_mode != EVS_MONO ) +#endif + { + /* convert from lsp to lsf */ + lsp2lsf_fx( lsp_temp_fx, lsf_shb_fx, LPC_SHB_ORDER, 1 ); + } } Copy( lsf_diff_fx + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); @@ -5250,35 +5248,35 @@ void swb_tbe_dec_ivas_fx( Copy( lsf_shb_fx, st->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); } + /* convert LSPs back into LP coeffs */ + E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ + lpc_shb_fx[0] = ONE_IN_Q12; + move16(); + + test(); #ifdef HARMONIZE_TBE3 - IF( st->element_mode > EVS_MONO ) + IF( st->element_mode > EVS_MONO && ( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) ) +#else + IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) #endif { - /* convert LSPs back into LP coeffs */ - E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ - lpc_shb_fx[0] = ONE_IN_Q12; - move16(); - - test(); - IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) - { - Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 - vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ - } - ELSE - { - vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ - } + Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 + vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ + /* i: mixFactors_fx in Q15 */ + /* o: vind in Q0 */ + } + ELSE + { + vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/ + /* i: mixFactors_fx in Q15 */ + /* o: vind in Q0 */ } /* Determine formant PF strength */ formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ + IF( GT_32( st->total_brate, ACELP_32k ) ) { FOR( j = 0; j < 4; j++ ) @@ -5291,9 +5289,23 @@ void swb_tbe_dec_ivas_fx( /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ +#ifdef HARMONIZE_TBE3 + Word16 sig_len = L_FRAME32k + NL_BUFF_OFFSET; + move16(); + IF( st->element_mode == EVS_MONO ) + { + sig_len = L_FRAME32k; + move16(); + } + + Lmax = 0; + move32(); + FOR( cnt = 0; cnt < sig_len; cnt++ ) +#else Lmax = 0; move32(); FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#endif { Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) ); } @@ -5324,13 +5336,29 @@ void swb_tbe_dec_ivas_fx( /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) { - bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) ); - move16(); - } + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) ); + } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + + /* state_syn_shbexc_fx is kept at (st->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ + Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); + } + ELSE +#endif + { + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended_fx[cnt], sc ) ); + move16(); + } + } /* save the previous Q factor (32-bit) of the buffer */ st->prev_Q_bwe_exc = Q_bwe_exc; @@ -5356,32 +5384,40 @@ void swb_tbe_dec_ivas_fx( Copy( lpc_shb_fx, &lpc_shb_sf_fx[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); } } + + /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the low band ACELP core excitation */ + GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + st->coder_type, st->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, + shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi ); } ELSE #endif { Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - } #ifdef HARMONIZE_TBE2 - GenShapedSHBExcitation_ivas_fx( DEC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, - hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, - shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, - st->element_mode, st->flag_ACELP16k, nlExc16k_fx, NULL, mixExc16k_fx, NULL, st->extl_brate, MSFlag, - NULL, 0, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); -#else - GenShapedSHBExcitation_ivas_dec_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, + GenShapedSHBExcitation_ivas_fx( DEC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, - st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, - NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); + st->element_mode, st->flag_ACELP16k, nlExc16k_fx, NULL, mixExc16k_fx, NULL, st->extl_brate, MSFlag, + NULL, 0, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); +#else + GenShapedSHBExcitation_ivas_dec_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + st->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_32, + shb_res_gshape_fx, shb_res_dummy_fx, &vind, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi, + st->element_mode, st->flag_ACELP16k, nlExc16k_fx, mixExc16k_fx, st->extl_brate, MSFlag, + NULL, &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), NULL, NULL ); #endif + } *Q_white_exc = Q_bwe_exc_fb; move16(); @@ -5920,16 +5956,7 @@ void swb_tbe_dec_ivas_fx( move16(); IF( i != 0 ) { -#ifdef HARMONIZE_TBE3 // VE: TBV - IF( st->element_mode == EVS_MONO ) - { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); - } - ELSE -#endif - { - idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); - } + idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); } GainShape_fx[i] = GainShape_tmp_fx[idx]; move16(); @@ -6485,8 +6512,10 @@ void swb_tbe_dec_ivas_fx( move16(); /*Qx*/ } } - - Copy( error_fx16, synth_fx16, L_FRAME32k ); + ELSE + { + Copy( error_fx16, synth_fx16, L_FRAME32k ); + } } ELSE #endif @@ -6499,8 +6528,10 @@ void swb_tbe_dec_ivas_fx( move32(); /*Qx*/ } } - - Copy32( error_fx, synth_fx, L_FRAME32k ); + ELSE + { + Copy32( error_fx, synth_fx, L_FRAME32k ); + } } } ELSE IF( EQ_32( st->output_Fs, 16000 ) ) -- GitLab From fb6c906ba372ed409eca85f72fcbd05a0196e33c Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Feb 2026 10:51:05 +0100 Subject: [PATCH 03/12] fix decoder --- lib_com/prot_fx.h | 33 +++++++++++++++++---------------- lib_dec/evs_dec_fx.c | 6 ++---- lib_dec/ivas_core_dec_fx.c | 2 +- lib_dec/swb_tbe_dec_fx.c | 38 ++++++++++++++++++++++++++++++++------ 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 356aa5838..8c7ea4e45 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -5516,6 +5516,21 @@ void wb_tbe_dec_fx( Word16 *synth, /* i/o: ACELP core synthesis/final synthesis */ Word16 *Q_synth ); +#ifdef HARMONIZE_TBE3 +void swb_tbe_dec_fx( + Decoder_State *st, /* i/o: decoder state structure */ + STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ + const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ + const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ + Word16 *Q_white_exc, /* o : Q-factor of White_exc16k_fx */ + Word16 *synth_fx16, /* o : SHB synthesis/final synthesis 16-bit : Qx */ + Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ + Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ + Word16 *pitch_buf_fx /* i : Q6 */ +); +#else void swb_tbe_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 coder_type, /* i : coding type */ @@ -5528,6 +5543,7 @@ void swb_tbe_dec_fx( Word16 *synth, /* o : SHB synthesis/final synthesis */ Word16 *Q_synth, Word16 *pitch_buf ); +#endif void fb_tbe_dec_fx( Decoder_State *st, /* i/o: encoder state structure */ @@ -9818,21 +9834,7 @@ void v_sub32_fx( const Word16 N /* i : Vector length */ ); -#ifdef HARMONIZE_TBE3 -void swb_tbe_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ - const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ - const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word16 *Q_white_exc, /* o : Q-factor of White_exc16k_fx */ - Word16 *synth_fx16, /* o : SHB synthesis/final synthesis 16-bit : Qx */ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ - Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ - Word16 *pitch_buf_fx /* i : Q6 */ -); -#else +#ifndef HARMONIZE_TBE3 void swb_tbe_dec_ivas_fx( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ @@ -9846,7 +9848,6 @@ void swb_tbe_dec_ivas_fx( Word16 *Q_white_exc /* o : Q-factor of White_exc16k_fx */ ); #endif - Word16 swb_bwe_dec_fx32( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index d7e05c938..0c134ce5b 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -417,8 +417,7 @@ ivas_error evs_dec_fx( { /* SWB TBE decoder */ #ifdef HARMONIZE_TBE3 - swb_tbe_dec_ivas_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, - old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); + swb_tbe_dec_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); #else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); @@ -859,8 +858,7 @@ ivas_error evs_dec_fx( { /* SWB TBE decoder */ #ifdef HARMONIZE_TBE3 - swb_tbe_dec_ivas_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, - hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); + swb_tbe_dec_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); #else swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index c379c0ee6..8198d4373 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1001,7 +1001,7 @@ ivas_error ivas_core_dec_fx( { /* SWB TBE decoder */ #ifdef HARMONIZE_TBE3 - swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, &Q_white_exc, NULL, hb_synth_32_fx[n], &tmp16, pitch_buf_fx[n] ); + swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, &Q_white_exc, NULL, hb_synth_32_fx[n], NULL, pitch_buf_fx[n] ); #else swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); #endif diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 31f5978da..4c661baf0 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -1334,7 +1334,7 @@ void wb_tbe_dec_fx( return; } - +#ifndef HARMONIZE_TBE3 /*======================================================================================*/ /* FUNCTION : void swb_tbe_dec_fx () */ /*--------------------------------------------------------------------------------------*/ @@ -3022,6 +3022,14 @@ void swb_tbe_dec_fx( return; } +#endif + +/*-------------------------------------------------------------------* + * gradientGainShape() + * + * + *-------------------------------------------------------------------*/ + static void gradientGainShape( Decoder_State *st_fx, Word16 *GainShape, @@ -4532,7 +4540,7 @@ static void find_max_mem_dec_m3( *-------------------------------------------------------------------*/ #ifdef HARMONIZE_TBE3 -void swb_tbe_dec_ivas_fx( +void swb_tbe_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ @@ -5552,6 +5560,13 @@ void swb_tbe_dec_ivas_fx( move16(); L_ener = EPSILON_FX_SMALL; move32(); +#ifdef HARMONIZE_TBE3 + if ( st->element_mode == EVS_MONO ) + { + L_ener = 0; + move32(); + } +#endif FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -6132,10 +6147,19 @@ void swb_tbe_dec_ivas_fx( curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; move16(); } + test(); test(); IF( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) ) { +#ifdef HARMONIZE_TBE3 + IF( st->element_mode == EVS_MONO ) + { + L_tmp = L_shr( curr_frame_pow_fx, 4 ); + L_tmp = Mult_32_16( L_tmp, 17476 ); + } +#endif + test(); test(); IF( ( GT_32( L_shr( curr_frame_pow_fx, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && @@ -6437,8 +6461,6 @@ void swb_tbe_dec_ivas_fx( #endif { Word32 idx32 = L_shr_r( 0x00333333, 10 ); - /*NUM_SHB_SUBFR/L_FRAME16k*/ // Q16 - FOR( i = 0; i < L_FRAME16k; i++ ) { Word16 idx; @@ -6602,9 +6624,13 @@ void swb_tbe_dec_ivas_fx( move16(); hBWE_TD->prev_Qx = Q_bwe_exc; move16(); + #ifdef HARMONIZE_TBE3 - *Q_synth = Q_bwe_exc; - move16(); + if ( Q_synth != NULL ) + { + *Q_synth = Q_bwe_exc; + move16(); + } #endif return; -- GitLab From 9a143de22ccd3985cf68e183feef42bb9100a0c6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Feb 2026 15:55:43 +0100 Subject: [PATCH 04/12] HARMONIZE_TBE3 encoder + fix decoder EVS CAM --- lib_com/prot_fx.h | 36 ++- lib_com/swb_tbe_com_fx.c | 137 ++++++-- lib_dec/dec_post_fx.c | 4 + lib_dec/swb_tbe_dec_fx.c | 73 ++--- lib_enc/evs_enc_fx.c | 4 + lib_enc/ivas_core_enc_fx.c | 4 + lib_enc/prot_fx_enc.h | 24 +- lib_enc/swb_tbe_enc_fx.c | 628 ++++++++++++++++++++++++++----------- 8 files changed, 633 insertions(+), 277 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 8c7ea4e45..72441f667 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2669,11 +2669,19 @@ void flip_and_downmix_generic_fx( ); void Calc_rc0_h( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ + Word16 *rc0 /* o : 1st parcor */ ); void PostShortTerm_fx( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -2684,6 +2692,7 @@ void PostShortTerm_fx( const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); +#ifndef HARMONIZE_TBE3 void PostShortTerm_ivas_enc_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -2705,7 +2714,7 @@ void PostShortTerm_ivas_dec_fx( Word16 *mem_zero, /* i/o: null memory to compute h_st*/ const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); - +#endif void flip_spectrum_and_decimby4_fx( const Word16 i[], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ @@ -5546,15 +5555,16 @@ void swb_tbe_dec_fx( #endif void fb_tbe_dec_fx( - Decoder_State *st, /* i/o: encoder state structure */ - const Word16 fb_exc[], /* i : FB excitation from the SWB part */ - Word16 Q_fb_exc, - Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word32 *hb_synth, /* o : high-band synthesis */ - Word16 hb_synth_exp, - Word16 *fb_synth_ref, - Word16 Q_fb_synth_ref, - Word16 output_frame ); + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ + const Word16 Q_fb_exc, /* i : Q-factor of fb_exc[] */ + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + const Word16 hb_synth_exp, /* i : Q-factor of hb_synth[] */ + Word16 *fb_synth_ref, /* o : Q_fb_synth_ref */ + Word16 Q_fb_synth_ref, /* i : Q-factor of fb_synth_ref[] */ + const Word16 output_frame /* i : output frame length */ +); void tbe_read_bitstream_fx( Decoder_State *st_fx /* i/o: encoder state structure */ @@ -5564,8 +5574,8 @@ void GenTransition_fx( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ Word16 *output_HB, /* o : synthesized HB transitions signal st_fx->prev_Q_bwe_syn2 */ const Word32 output_Fs, /* i : output sampling rate */ - Word16 rf_flag, /* i : RF flag */ - Word32 total_bitrate /* i : total bitrate */ + const Word16 rf_flag, /* i : RF flag */ + const Word32 total_bitrate /* i : total bitrate */ ); void GenTransition_fx32( diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 96db4fb33..a99ff54fe 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -26,7 +26,11 @@ 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 ); +#ifdef HARMONIZE_TBE3 +static void Calc_st_filt_tbe_fx( const Word16 element_mode, const Word16 enc_dec, Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); +#else static void Calc_st_filt_tbe_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); +#endif 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 ); 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 ); @@ -630,37 +634,74 @@ void flip_spectrum_fx( * * computes 1st parcor from composed filter impulse response *---------------------------------------------------------------------------*/ + void Calc_rc0_h( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ + Word16 *rc0 /* o : 1st parcor */ ) { Word32 L_acc; Word16 *ptrs; Word16 acf0, acf1; +#ifdef HARMONIZE_TBE3 + Word16 tmp2; +#endif Word16 temp, sh_acf; Word16 i; /* computation of the autocorrelation function acf */ - L_acc = L_mult( h[0], h[0] ); - FOR( i = 1; i < LONG_H_ST; i++ ) +#ifdef HARMONIZE_TBE3 + IF( element_mode != EVS_MONO && enc_dec == ENC ) { - L_acc = L_mac( L_acc, h[i], h[i] ); - } - sh_acf = norm_l( L_acc ); - L_acc = L_shl( L_acc, sh_acf ); - acf0 = extract_h( L_acc ); + L_acc = L_mult( h[0], h[0] ); // TBV: shouldn't it be "shr( h[0], 2 )" ? + FOR( i = 1; i < LONG_H_ST; i++ ) + { + tmp2 = shr( h[i], 2 ); + L_acc = L_mac( L_acc, tmp2, tmp2 ); + } + sh_acf = norm_l( L_acc ); + L_acc = L_shl( L_acc, sh_acf ); + acf0 = extract_h( L_acc ); - ptrs = h; + ptrs = h; - temp = *ptrs++; - move16(); - L_acc = L_mult( temp, *ptrs ); - FOR( i = 1; i < LONG_H_ST - 1; i++ ) + temp = *ptrs++; + move16(); + L_acc = L_mult( temp, *ptrs ); + FOR( i = 1; i < LONG_H_ST - 1; i++ ) + { + temp = shr( *ptrs++, 2 ); + move16(); + L_acc = L_mac( L_acc, temp, shr( *ptrs, 2 ) ); + } + } + ELSE +#endif { + L_acc = L_mult( h[0], h[0] ); + FOR( i = 1; i < LONG_H_ST; i++ ) + { + L_acc = L_mac( L_acc, h[i], h[i] ); + } + sh_acf = norm_l( L_acc ); + L_acc = L_shl( L_acc, sh_acf ); + acf0 = extract_h( L_acc ); + + ptrs = h; + temp = *ptrs++; move16(); - L_acc = L_mac( L_acc, temp, *ptrs ); + L_acc = L_mult( temp, *ptrs ); + FOR( i = 1; i < LONG_H_ST - 1; i++ ) + { + temp = *ptrs++; + move16(); + L_acc = L_mac( L_acc, temp, *ptrs ); + } } L_acc = L_shl( L_acc, sh_acf ); acf1 = extract_h( L_acc ); @@ -750,6 +791,10 @@ static void Calc_rc0_h_ivas_enc_fx( } static void Calc_st_filt_tbe_fx( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ @@ -764,10 +809,27 @@ static void Calc_st_filt_tbe_fx( Word16 g0, temp; Word16 i; temp = sub( 2, norm_s( apond2[0] ) ); - /* compute i.r. of composed filter apond2 / apond1 */ - Syn_filt_s( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + +#ifdef HARMONIZE_TBE3 + IF( element_mode != EVS_MONO && enc_dec == ENC ) + { + /* compute i.r. of composed filter apond2 / apond1 */ + syn_filt_fx( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + } + ELSE +#endif + { + /* compute i.r. of composed filter apond2 / apond1 */ + Syn_filt_s( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); + } + /* compute 1st parcor */ +#ifdef HARMONIZE_TBE3 + Calc_rc0_h( element_mode, enc_dec, h, parcor0 ); +#else Calc_rc0_h( h, parcor0 ); +#endif + /* compute g0 */ L_g0 = L_mult0( 1, abs_s( h[0] ) ); @@ -791,6 +853,7 @@ static void Calc_st_filt_tbe_fx( return; } +#ifndef HARMONIZE_TBE3 static void Calc_st_filt_tbe_ivas_enc_fx( Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ @@ -832,6 +895,7 @@ static void Calc_st_filt_tbe_ivas_enc_fx( return; } +#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ @@ -992,7 +1056,18 @@ static void scale_st_swb( return; } + +/*-------------------------------------------------------------------* + * PostShortTerm() + * + * Short term processing + *-------------------------------------------------------------------*/ + void PostShortTerm_fx( +#ifdef HARMONIZE_TBE3 + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ +#endif Word16 *sig_in, /* i : input signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -1006,8 +1081,7 @@ void PostShortTerm_fx( Word16 apond1_fx[LPC_SHB_ORDER + 1]; /* denominator coeff.*/ Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ Word16 sig_ltp_fx[L_SUBFR16k + 1]; /* residual signal */ - /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */ - Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ + Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ Word16 tmp; parcor0_fx = 0; @@ -1023,24 +1097,34 @@ void PostShortTerm_fx( /* Compute weighted LPC coefficients */ weight_a_fx( lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER ); - weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); - /* o: apond1_fx, apond2_fx in Q12 */ + weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); /* apond1_fx, apond2_fx in Q12 */ /* Compute A(gamma2) residual */ - Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); - /* o: sig_ltp_fx in Q_bwe_exc */ + Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); /* sig_ltp_fx in Q_bwe_exc */ /* Save last output of 1/A(gamma1) */ sig_ltp_fx[0] = *ptr_mem_stp; move16(); /* Control short term pst filter gain and compute parcor0 */ +#ifdef HARMONIZE_TBE3 + Calc_st_filt_tbe_fx( element_mode, enc_dec, apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); +#else 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 */ +#endif + /* parcor0 in Q15, sig_ltp_fx in Q_bwe_exc */ /* 1/A(gamma1) filtering, mem_stp is updated */ - Syn_filt_s( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); +#ifdef HARMONIZE_TBE3 + IF( element_mode != EVS_MONO && enc_dec == ENC ) + { + syn_filt_fx( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); + } + ELSE +#endif + { + Syn_filt_s( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); + } /* (1 + mu z-1) tilt filtering */ filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); @@ -1052,6 +1136,7 @@ void PostShortTerm_fx( return; } +#ifndef HARMONIZE_TBE3 void PostShortTerm_ivas_enc_fx( Word16 *sig_in, /* i : input signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ @@ -1171,7 +1256,7 @@ void PostShortTerm_ivas_dec_fx( return; } - +#endif /*-------------------------------------------------------------------* * flip_spectrum_and_decimby4() diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index 442e0caf0..b76218055 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -1309,7 +1309,11 @@ static void calc_st_filt_local_fx( E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M ); /* compute 1st parcor */ +#ifdef HARMONIZE_TBE3 + Calc_rc0_h( EVS_MONO, DEC, h, parcor0 ); +#else Calc_rc0_h( h, parcor0 ); +#endif /* compute g0 */ L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 4c661baf0..04ce9402c 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3386,7 +3386,6 @@ static void dequantizeSHBparams_fx( hBWE_TD = st_fx->hBWE_TD; /* LSFs */ - IF( EQ_16( extl, WB_TBE ) ) { IF( EQ_32( extl_brate, WB_TBE_0k35 ) ) @@ -3491,7 +3490,7 @@ static void dequantizeSHBparams_fx( idx_shb_fr_gain = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_ENER_SF ); } temp_shb_ener_sf_fx = usdequant_fx( idx_shb_fr_gain, 0, 86 ); /* 86 = 0.042f in Q11 = Qin-1 */ - /* o: temp_shb_ener_sf_fx in Q12 */ + /* temp_shb_ener_sf_fx in Q12 */ /* *Q_shb_ener_sf = Pow(10.0, temp_shb_ener_sf_fx ); */ /* = pow(2, 3.321928*temp_shb_ener_sf_fx) */ @@ -3514,12 +3513,9 @@ static void dequantizeSHBparams_fx( idx_res_gs[i] = (Word16) get_next_indice_fx( st_fx, NUM_BITS_SHB_RES_GS ); move16(); } - Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], - 2048 /*0.125f Q14*/, /*2048 = 0.125 in Q14 */ - 1024 /*0.125f Q13*/ /*1024 = 0.125 in Q13 */ - ); + Q_shb_res_gshape[i] = usdequant_fx( idx_res_gs[i], 2048 /*0.125f Q14*/, 1024 /*0.125f Q13*/ ); move16(); - /* o: Q_shb_res_gshape in Q14 */ + /* Q_shb_res_gshape in Q14 */ } IF( EQ_16( st_fx->codec_mode, MODE2 ) ) @@ -3533,7 +3529,7 @@ static void dequantizeSHBparams_fx( } *Q_mixFactors = usdequant_fx( idx_mixFac, 4096 /* 0.125 in Q15 */, 2048 /* 0.125 in Q14 */ ); move16(); - /* o: Q_mixFactors in Q15 */ + /* Q_mixFactors in Q15 */ } ELSE { @@ -3790,16 +3786,16 @@ static void dequantizeSHBparams_fx( *-------------------------------------------------------------------*/ void fb_tbe_dec_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, - Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ - Word16 hb_synth_exp, - Word16 *fb_synth_ref, /*Q_fb_synth_ref*/ - Word16 Q_fb_synth_ref, - Word16 output_frame ) - + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part Q_fb_exc */ + const Word16 Q_fb_exc, /* i : Q-factor of fb_exc[] */ + Word16 *hb_synth16, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + Word32 *hb_synth, /* o : high-band synthesis Q(15 - hb_synth_exp) */ + const Word16 hb_synth_exp, /* i : Q-factor of hb_synth[] */ + Word16 *fb_synth_ref, /* o : Q_fb_synth_ref */ + Word16 Q_fb_synth_ref, /* i : Q-factor of fb_synth_ref[] */ + const Word16 output_frame /* i : output frame length */ +) { Word16 i; Word16 ratio = 0; @@ -3847,8 +3843,7 @@ void fb_tbe_dec_fx( fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* FB TBE synthesis */ - synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp, - st->element_mode ); + synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp, st->element_mode ); test(); IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->idchan == 0 ) ) @@ -3982,6 +3977,8 @@ void tbe_read_bitstream_fx( hBWE_TD->idxGain = (Word16) get_next_indice_fx( st_fx, 4 ); move16(); } + + return; } @@ -3997,8 +3994,8 @@ void GenTransition_fx( TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */ Word16 *output_HB, /* o : synthesized HB transitions signal st_fx->prev_Q_bwe_syn2 */ const Word32 output_Fs, /* i : output sampling rate */ - Word16 rf_flag, /* i : RF flag */ - Word32 total_bitrate /* i : total bitrate */ + const Word16 rf_flag, /* i : RF flag */ + const Word32 total_bitrate /* i : total bitrate */ ) { Word16 i, length; @@ -5271,19 +5268,16 @@ void swb_tbe_dec_ivas_fx( { Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ + /* mixFactors_fx in Q15, vind in Q0 */ } ELSE { vind = shl( mixFactors_fx, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*8*/ - /* i: mixFactors_fx in Q15 */ - /* o: vind in Q0 */ + /* mixFactors_fx in Q15, vind in Q0 */ } /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ + formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); /* lpc_shb_fx Q12, formant_fac_fx Q15 */ IF( GT_32( st->total_brate, ACELP_32k ) ) { @@ -5308,7 +5302,7 @@ void swb_tbe_dec_ivas_fx( Lmax = 0; move32(); - FOR( cnt = 0; cnt < sig_len; cnt++ ) + FOR( cnt = 0; cnt < sig_len; cnt++ ) // note: this differs from the encoder where the length is always L_FRAME32k #else Lmax = 0; move32(); @@ -5324,6 +5318,7 @@ void swb_tbe_dec_ivas_fx( move16(); } Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); + /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ find_max_mem_dec( st, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ @@ -5465,6 +5460,7 @@ void swb_tbe_dec_ivas_fx( test(); #ifdef HARMONIZE_TBE3 + test(); IF( st->element_mode == EVS_MONO || ( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) ) #else IF( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) @@ -5474,17 +5470,12 @@ void swb_tbe_dec_ivas_fx( { /* TD BWE post-processing */ #ifdef HARMONIZE_TBE3 - IF( st->element_mode == EVS_MONO ) - { - PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - } - ELSE + PostShortTerm_fx( st->element_mode, DEC, &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); +#else + PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); #endif - { - PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - } } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ @@ -6149,8 +6140,12 @@ void swb_tbe_dec_ivas_fx( } test(); +#ifdef HARMONIZE_TBE3 + IF( !st->bfi && st->prev_bfi ) // note: this is likely a bug in EVS +#else test(); IF( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) ) +#endif { #ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 8133da6e5..e6e934ec8 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -476,7 +476,11 @@ ivas_error evs_enc_fx( test(); IF( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) { +#ifdef HARMONIZE_TBE3 + swb_tbe_enc_fx( st, NULL, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); +#else swb_tbe_enc_fx( st, st->coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); +#endif IF( EQ_16( st->extl, FB_TBE ) ) { diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 55956600d..60dd1d1a3 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -737,7 +737,11 @@ ivas_error ivas_core_enc_fx( Word16 Q_fb_exc; Word16 fb_exc_fx[L_FRAME16k]; +#ifdef HARMONIZE_TBE3 + swb_tbe_enc_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], 0, st->voicing_fx, pitch_buf_fx[n] ); +#else swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], 0, st->voicing_fx, pitch_buf_fx[n] ); +#endif IF( EQ_16( st->extl, FB_TBE ) ) { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 153c24b36..39748c73c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -581,6 +581,7 @@ void InitSWBencBufferStates_fx( ); void swb_tbe_enc_fx( +#ifndef HARMONIZE_TBE3 Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ Word16 *new_speech_fx, /* i : original i signal */ @@ -595,17 +596,18 @@ void swb_tbe_enc_fx( ); void swb_tbe_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ - const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ - Word16 *Q_white_exc, - Word16 Q_new, - Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6 */ +#endif + Encoder_State *st_fx, /* i/o: encoder state structure */ + STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ + const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ + Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ + Word16 Q_new, /* i : Q_new */ + Word16 Q_shb, /* i : SHB target Q factor */ + Word16 *voicing, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : subframe pitch Q6 */ ); void tbe_write_bitstream_fx( diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 7e52cca53..0e0ae926c 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1369,6 +1369,7 @@ void fb_tbe_reset_enc_fx( /*======================================================================================*/ void swb_tbe_enc_fx( +#ifndef HARMONIZE_TBE3 Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 coder_type, /* i : coding type */ Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ @@ -2286,24 +2287,24 @@ void swb_tbe_enc_fx( /*======================================================================================*/ void swb_tbe_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ - const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ - Word16 *Q_white_exc, - Word16 Q_new, - Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6 */ +#endif + Encoder_State *st_fx, /* i/o: encoder state structure */ + STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ + Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ + Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2 * Q_new */ + const Word16 voice_factors_fx[], /* i : voicing factors Q15 */ + Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc */ + Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ + Word16 Q_new, /* i : Q_new */ + Word16 Q_shb, /* i : SHB target Q factor */ + Word16 *voicing, /* i : OL maximum normalized correlation */ + const Word16 pitch_buf[] /* i : subframe pitch Q6 */ + ) { Word16 i, j, k, delay; - Word16 shb_old_speech_fx[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; Word32 GainFrame_fx; /* Q18 */ Word16 GainShape_fx[NUM_SHB_SUBFR]; /* Q15 */ @@ -2344,7 +2345,6 @@ void swb_tbe_enc_ivas_fx( Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER]; Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )]; - /*Word32 shb_ener_sf_fx_32[4];*/ Word32 shb_ener_sf_Q31; Word16 shb_res_fx[L_FRAME16k]; Word16 shb_res_gshape_fx[NB_SUBFR16k]; @@ -2352,12 +2352,10 @@ void swb_tbe_enc_ivas_fx( Word16 vf_ind_fx; Word16 formant_fac_fx; - // int16_t stab_check = 1; Word16 MSFlag; Word16 *nlExc16k_fx, *nlExc16k_e, *mixExc16k_fx, *mixExc16k_e; Word16 shaped_shb_excitationTemp_fx[L_FRAME16k]; - Word16 acorr_v2a_fx; /* Q15 */ Word16 acorr_EnvSHBres[ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN], *p_acorr, shb_env_tilt_fx; @@ -2469,15 +2467,31 @@ void swb_tbe_enc_ivas_fx( 0, 1 ); - /* Spectral smoothing of autocorrelation coefficients */ +#ifdef HARMONIZE_TBE3 + const Word16 *p_wac_swb_h, *p_wac_swb_l; + IF( st_fx->element_mode == EVS_MONO ) + { + p_wac_swb_h = wac_swb_h; + p_wac_swb_l = wac_swb_l; + } + ELSE + { + p_wac_swb_h = wac_swb_ivas_h; + p_wac_swb_l = wac_swb_ivas_l; + } +#endif test(); test(); IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { +#ifdef HARMONIZE_TBE3 + L_tmp = Mpy_32( R_h[i], R_l[i], p_wac_swb_h[i - 1], p_wac_swb_l[i - 1] ); +#else L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_ivas_h[i - 1], wac_swb_ivas_l[i - 1] ); +#endif L_Extract( L_tmp, &R_h[i], &R_l[i] ); } } @@ -2499,19 +2513,23 @@ void swb_tbe_enc_ivas_fx( /* if the LP gain is greater than a threshold, avoid saturation */ Word16 flag_sat = 0; - Word16 lpc_shb_fx0_req_shift = sub( norm_s( lpc_shb_fx[0] ), 2 ); - IF( GT_16( lpc_shb_fx0_req_shift, 0 ) ) +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode != EVS_MONO ) +#endif { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) + Word16 lpc_shb_fx0_req_shift = sub( norm_s( lpc_shb_fx[0] ), 2 ); + IF( GT_16( lpc_shb_fx0_req_shift, 0 ) ) { - IF( LT_16( norm_s( lpc_shb_fx[i] ), lpc_shb_fx0_req_shift ) ) + FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { - flag_sat = 1; - break; + IF( LT_16( norm_s( lpc_shb_fx[i] ), lpc_shb_fx0_req_shift ) ) + { + flag_sat = 1; + break; + } } } } - IF( GT_16( enerG, 256 /* 32.0 in Q3 */ ) || flag_sat ) { set16_fx( lpc_shb_fx, 0, LPC_SHB_ORDER + 1 ); @@ -2520,7 +2538,16 @@ void swb_tbe_enc_ivas_fx( } /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ - scale_sig( lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); + } + ELSE +#endif + { + scale_sig( lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); + } /* Expand bandwidth of the LP coeffs */ test(); @@ -2534,8 +2561,6 @@ void swb_tbe_enc_ivas_fx( } } - /* stab_check = a2lsp( lsf_shb, lpc_shb, LPC_SHB_ORDER ); */ - /* LPC to LSP conversion */ /* LPC: Q12, LSP: Q15 */ E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); @@ -2546,7 +2571,12 @@ void swb_tbe_enc_ivas_fx( test(); test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) ) +#else IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) +#endif { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { @@ -2556,11 +2586,6 @@ void swb_tbe_enc_ivas_fx( } } - // if ( stab_check == 0 ) - //{ - // mvr2r( hBWE_TD->prev_lsp_shb, lsf_shb, LPC_SHB_ORDER ); - // } - Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); @@ -2572,7 +2597,16 @@ void swb_tbe_enc_ivas_fx( test(); IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { - lsp_weights_ivas_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); + } + ELSE +#endif + { + lsp_weights_ivas_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); + } /* to compensate for the 1.1* weighting done inside the function lsp_weights */ /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ @@ -2600,7 +2634,16 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ - Quant_BWE_LSF_fx( hBstr, st_fx->hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + Quant_BWE_LSF_fx( hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); // this is likely a bug in EVS + } + ELSE +#endif + { + Quant_BWE_LSF_fx( hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); + } } /* space the lsfs to assert a minimum distance */ @@ -2658,11 +2701,11 @@ void swb_tbe_enc_ivas_fx( Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); } - lsf_diff_fx[0] = lsf_diff_fx[sub( LPC_SHB_ORDER, 1 )] = 16384; /*Q15*/ + lsf_diff_fx[0] = lsf_diff_fx[LPC_SHB_ORDER - 1] = 16384; /*Q15*/ move16(); FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) { - lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[sub( i, 1 )] ); + lsf_diff_fx[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] ); move16(); } a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl_fx, M ); @@ -2741,6 +2784,9 @@ void swb_tbe_enc_ivas_fx( shb_ener_sf_Q31 = 0; move16(); test(); +#ifdef HARMONIZE_TBE3 + test(); +#endif IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) { /* ---------- SHB LSP interpolation ---------- */ @@ -2782,16 +2828,14 @@ void swb_tbe_enc_ivas_fx( Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); - /* i: shb_frame_fx in Q_shb */ - /* o: shb_res_fx in Q_shb */ + /* shb_frame_fx in Q_shb, shb_res_fx in Q_shb */ set32_fx( shb_res_gshape_fx_32, 0, NB_SUBFR16k ); FOR( i = 0; i < NB_SUBFR16k; i++ ) { - shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i_mult( i, 64 ), 64 ); + shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i_mult( i, 64 ), 64 ); /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ move32(); } - /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ maximum_32_fx( shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp ); @@ -2809,7 +2853,6 @@ void swb_tbe_enc_ivas_fx( exp = norm_l( L_tmp ); tmp = extract_h( L_shl( L_tmp, exp ) ); recip = div_s( 16384, tmp ); - // Q_recip = sub( 31, sub( exp, 14 ) ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ } @@ -2823,7 +2866,11 @@ void swb_tbe_enc_ivas_fx( Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); } +#ifdef HARMONIZE_TBE3 + ELSE IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { FOR( j = 0; j < 4; j++ ) { @@ -2842,24 +2889,29 @@ void swb_tbe_enc_ivas_fx( Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); } + /* Save the SWB LSP values from current frame for interpolation */ Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ - /* for 13.2 and 16.4kbps */ + + /* convert from lsp to to lpc for SHB synthesis */ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ + formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ /* calculate SHB auto-correlation function and convert to SHB voicing factor */ - // acorr_v2a = 0.0f; L_tmp = 0; move32(); acorr_v2a_fx = 0; move16(); test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { /* calculate the TD envelope of the SHB residual signal */ Scale_sig( hBWE_TD->mem_shb_res_fx, MAX_LEN_MA_FILTER, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ @@ -2926,7 +2978,6 @@ void swb_tbe_enc_ivas_fx( } /* last half of the last segment */ - // set_f( p_env, den_seg_mean[3], seg_len_2 ); set16_fx( p_env, den_seg_mean[3], seg_len_2 ); hBWE_TD->old_mean_EnvSHBres_fx = den_seg_mean[3]; move16(); @@ -3004,7 +3055,6 @@ void swb_tbe_enc_ivas_fx( Word64 W_tmp = 0; move64(); - // tmp = *p_buf; FOR( i = 0; i < L_FRAME4k; ++i ) { L_tmp = L_mult( buf_EnvSHBres_fx[L_FRAME4k + i], p_buf[i] ); // 2 * Q_shb + 1 @@ -3045,8 +3095,6 @@ void swb_tbe_enc_ivas_fx( tmp_e = sub( 31, sub( sub( add( sub( 31, tmp_e ), Q_shb ), 15 ), 5 ) ); - // L_tmp = BASOP_Util_fPow(exp_tmp, exp_e, 2, 31, &res_e); - L_tmp = BASOP_Util_fPow( exp_tmp, exp_e, L_tmp, tmp_e, &res_e ); L_tmp = BASOP_Util_Add_Mant32Exp( ONE_IN_Q31, 0, L_tmp, res_e, &tmp_e ); acorr_v2a_fx = BASOP_Util_Divide3232_Scale( 2, L_tmp, &res_e ); @@ -3071,12 +3119,9 @@ void swb_tbe_enc_ivas_fx( move16(); } - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ vf_ind_fx = 20; move16(); - /* Save the SWB LSP values from current frame for interpolation */ - /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ Lmax = L_deposit_l( 0 ); @@ -3109,12 +3154,30 @@ void swb_tbe_enc_ivas_fx( rescale_genSHB_mem_enc( st_fx, sc ); } - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); - move16(); + Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); + + FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) + { + bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + move16(); + } + Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); + } + ELSE +#endif + { + sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); + + /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ + FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) + { + bwe_exc_extended_16[cnt] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); + move16(); + } } /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ @@ -3130,17 +3193,32 @@ void swb_tbe_enc_ivas_fx( Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; move16(); + /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, + hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, + st_fx->coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, + &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, + shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, + &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 ); + } + ELSE +#endif + { #ifdef HARMONIZE_TBE2 - GenShapedSHBExcitation_ivas_fx( ENC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, + GenShapedSHBExcitation_ivas_fx( ENC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, #else - GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, + GenShapedSHBExcitation_ivas_enc_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, #endif - hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, - vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, - shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, - &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, - nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, - &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); + hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, + vf_modified_fx, st_fx->extl, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, + shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, + &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0, st_fx->element_mode, st_fx->flag_ACELP16k, nlExc16k_fx, + nlExc16k_e, mixExc16k_fx, mixExc16k_e, st_fx->extl_brate, MSFlag, EnvSHBres_4k_norm_fx, Q_EnvSHBres_4k_norm, + &( hBWE_TD->prev_pow_exc16kWhtnd_fx32 ), &( hBWE_TD->prev_mix_factor_fx ), &Env_error_fx, Env_error_part_fx ); + } *Q_white_exc = Q_bwe_exc_fb; move16(); @@ -3195,61 +3273,89 @@ void swb_tbe_enc_ivas_fx( } test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode == EVS_MONO || ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { +#ifdef HARMONIZE_TBE3 + PostShortTerm_fx( st_fx->element_mode, ENC, &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); +#else PostShortTerm_ivas_enc_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - /* i: shaped_shb_excitation_fx in Q_bwe_exc */ - /* i: lpc_shb_fx in Q12 */ + hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); /* shaped_shb_excitation_fx in Q_bwe_exc, lpc_shb_fx in Q12 */ +#endif } + Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - Word16 max_val; - maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); - IF( max_val == 0 ) - { - Lscale = ONE_IN_Q31; /* 1.0f in Q31 */ - move32(); - IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) - { - Lscale = ONE_IN_Q30; /* sqrtf(0.25) = 0.5 in Q31 */ - move32(); - } - exp = 0; - move16(); - } - ELSE +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - Word64 prev_pow_64fx, curr_pow_64fx; - Word16 w_shift; tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); - prev_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { - prev_pow_64fx = W_mac0_16_16( prev_pow_64fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ - curr_pow_64fx = W_mac0_16_16( curr_pow_64fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ } - IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) { /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_64fx = W_shr( curr_pow_64fx, 2 ); /* scale by 0.25 */ + curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ } - w_shift = s_min( W_norm( prev_pow_64fx ), W_norm( curr_pow_64fx ) ); - prev_pow_fx = W_extract_h( W_shl( prev_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 - curr_pow_fx = W_extract_h( W_shl( curr_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 - w_shift = sub( add( shl( Q_bwe_exc, 1 ), w_shift ), 32 ); + Lscale = root_a_over_b_fx( curr_pow_fx, shl( Q_bwe_exc, 1 ), prev_pow_fx, shl( Q_bwe_exc, 1 ), &exp ); + } + ELSE +#endif + { + Word16 max_val; + maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); + IF( max_val == 0 ) + { + Lscale = ONE_IN_Q31; /* 1.0f in Q31 */ + move32(); + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + Lscale = ONE_IN_Q30; /* sqrtf(0.25) = 0.5 in Q31 */ + move32(); + } + exp = 0; + move16(); + } + ELSE + { + Word64 prev_pow_64fx, curr_pow_64fx; + Word16 w_shift; + tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); + prev_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + curr_pow_64fx = W_shl( 21475ll /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ + FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) + { + prev_pow_64fx = W_mac0_16_16( prev_pow_64fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_64fx = W_mac0_16_16( curr_pow_64fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ + } - Lscale = root_a_over_b_fx( curr_pow_fx, - w_shift, - prev_pow_fx, - w_shift, - &exp ); + IF( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) + { + /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ + curr_pow_64fx = W_shr( curr_pow_64fx, 2 ); /* scale by 0.25 */ + } + + w_shift = s_min( W_norm( prev_pow_64fx ), W_norm( curr_pow_64fx ) ); + prev_pow_fx = W_extract_h( W_shl( prev_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 + curr_pow_fx = W_extract_h( W_shl( curr_pow_64fx, w_shift ) ); // 2*(Q_bwe_exc)+w_shift-32 + w_shift = sub( add( shl( Q_bwe_exc, 1 ), w_shift ), 32 ); + + Lscale = root_a_over_b_fx( curr_pow_fx, w_shift, prev_pow_fx, w_shift, &exp ); + } } FOR( i = 0; i < L_SHB_LAHEAD; i++ ) @@ -3264,10 +3370,7 @@ void swb_tbe_enc_ivas_fx( exp = 0; move16(); } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ + IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) { FOR( ; i < L_SHB_LAHEAD + 10; i++ ) @@ -3275,8 +3378,13 @@ void swb_tbe_enc_ivas_fx( tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ tmp = sub( 32767 /*1.0f Q15*/, tmp ); +#ifdef HARMONIZE_TBE3 + Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#else L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#endif shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } @@ -3288,6 +3396,11 @@ void swb_tbe_enc_ivas_fx( tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ tmp = sub( 32767 /*1.0f Q15*/, tmp ); +#ifdef HARMONIZE_TBE3 + // TODO: to be verified, at the decoder there is + // Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 ); + // L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#endif L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ @@ -3310,11 +3423,27 @@ void swb_tbe_enc_ivas_fx( /* Estimate the gain-shape parameter */ n_subfr_saturation = 0; move16(); - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); +#ifdef HARMONIZE_TBE3 + Word16 limit_min_gain = 0; + move16(); + IF( st_fx->element_mode == EVS_MONO ) + { + limit_min_gain = 1; + move16(); + } + + EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, limit_min_gain ); +#else + EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); +#endif test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { /* Gain shape attenuation in case of big error in envelope modelling */ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) @@ -3322,7 +3451,6 @@ void swb_tbe_enc_ivas_fx( IF( GT_16( Env_error_part_fx[i], 100 ) ) { /* set gain shape to the average of the remaining gains */ - // GainShape[i] = ( sum_f( GainShape, NUM_SHB_SUBGAINS ) - GainShape[i] ) / ( NUM_SHB_SUBGAINS - 1 ); L_tmp = L_sub( sum16_32_fx( GainShape_fx, NUM_SHB_SUBGAINS ), GainShape_fx[i] ); tmp = BASOP_Util_Divide3232_Scale( L_tmp, NUM_SHB_SUBGAINS - 1, &exp ); GainShape_fx[i] = shl( tmp, sub( exp, 15 ) ); /* Q15 */ @@ -3332,7 +3460,12 @@ void swb_tbe_enc_ivas_fx( } test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode == EVS_MONO || NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { /* Gain shape BWS/high band low energy fix */ IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ @@ -3340,8 +3473,6 @@ void swb_tbe_enc_ivas_fx( /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ - /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); move16(); } @@ -3350,7 +3481,12 @@ void swb_tbe_enc_ivas_fx( /* high-band gain control in case of BWS */ test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { IF( st_fx->bwidth_sw_cnt > 0 ) { @@ -3365,43 +3501,69 @@ void swb_tbe_enc_ivas_fx( } /* Gain frame adjustment factor */ - /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ - IF( hBWE_TD->prev_swb_GainShape_fx == 0 ) - { - exp = 13 /* norm_s(3) */; - tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; - } - ELSE +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); - } - - L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ + test(); + IF( GainShape_fx[0] && hBWE_TD->prev_swb_GainShape_fx ) + { + exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); + L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ - exp1 = sub( exp, exp1 ); /*move16(); */ - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + } + ELSE + { + temp_swb_fac = 0; + move16(); + } - L_feedback = L_mult( temp_swb_fac, temp_swb_fac ); + L_feedback = L_mult0( temp_swb_fac, temp_swb_fac ); + FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) + { + test(); + IF( GainShape_fx[i] && GainShape_fx[i - 1] ) + { + exp = norm_s( GainShape_fx[i - 1] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ + + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + } + ELSE + { + temp_swb_fac = 0; + move16(); + } - FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) + L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); + } + } + ELSE +#endif { - test(); - IF( GainShape_fx[i - 1] == 0 ) + IF( hBWE_TD->prev_swb_GainShape_fx == 0 ) { exp = 13 /* norm_s(3) */; tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; } ELSE { - exp = norm_s( GainShape_fx[i - 1] ); - tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); } - L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ + + L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ exp1 = norm_l( L_tmp ); frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); @@ -3409,7 +3571,31 @@ void swb_tbe_enc_ivas_fx( L_tmp = Mpy_32_16( exp1, frac, 22713 ); temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); + L_feedback = L_mult( temp_swb_fac, temp_swb_fac ); + + FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) + { + test(); + IF( GainShape_fx[i - 1] == 0 ) + { + exp = 13 /* norm_s(3) */; + tmp = 21845 /* div_s( shl(1, sub(14, exp)), 3 /\* 0.0001 in Q15 *\/ ) */; + } + ELSE + { + exp = norm_s( GainShape_fx[i - 1] ); + tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); + } + L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ + + exp1 = norm_l( L_tmp ); + frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); + exp1 = sub( exp, exp1 ); + L_tmp = Mpy_32_16( exp1, frac, 22713 ); + temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); + + L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); + } } /* feedback = 0.4f / (1 + 0.5f * feedback) */ @@ -3429,14 +3615,28 @@ void swb_tbe_enc_ivas_fx( move16(); /*Q15 */ } - /* calculate tilt in all sub-frame gains */ - Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); - lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + GainShape_tilt_fx = 0; // just to avoid compilation warnings + move16(); + } + ELSE +#endif + { + /* calculate tilt in all sub-frame gains */ + Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); + lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); + } test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { - // if (acorr_v2a < 0.4f && vf_ind >= 5 && fabs(GainShape_tilt) < 0.2f && shb_env_tilt < 500.0f && hBWE_TD->prev_shb_env_tilt < 500.0f) test(); test(); test(); @@ -3444,14 +3644,11 @@ void swb_tbe_enc_ivas_fx( IF( LT_16( acorr_v2a_fx, 13107 ) /* 0.4f in Q15 */ && GE_16( vf_ind_fx, 5 ) && LT_16( abs_s( GainShape_tilt_fx ), 6554 /* 0.2f in Q15 */ ) && LT_32( L_deposit_l( shb_env_tilt_fx ), L_shl( 500, Q_shb ) ) && LT_32( L_deposit_l( hBWE_TD->prev_shb_env_tilt_fx ), L_shl( 500, hBWE_TD->prev_Q_shb ) ) ) { /* stronger smoothing in case of unvoiced SHB residual signal with gaussian excitation */ - // feedback = lin_interp(acorr_v2a, 0.4f, 0.0f, 0.0f, 0.95f, 0); feedback = lin_interp_ivas_fx( acorr_v2a_fx, 13107 /* 0.4f in Q15 */, 0, 0, 31130 /* 0.95f in Q15 */, 0 ); - // feedback = min( max( feedback, 0.0f ), 1.0f ); feedback = s_min( s_max( feedback, 0 ), MAX16B ); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - // GainShape[i] = ( 1 - feedback ) * GainShape[i] + feedback * GainShape_Interp[i]; GainShape_fx[i] = extract_h( L_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i] ), feedback, GainShape_Interp_fx[i] ) ); move16(); } @@ -3473,7 +3670,6 @@ void swb_tbe_enc_ivas_fx( L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ - test(); test(); IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 /* 2.4f in Q13 */ ) && GT_16( tmp1, 6554 /* 0.8f in Q13 */ ) ) ) @@ -3493,10 +3689,14 @@ void swb_tbe_enc_ivas_fx( } test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { /* Re-normalize gain shape before quantization */ - // sum_gain = sum2_f(GainShape, NUM_SHB_SUBGAINS); tmp = 0; move16(); sum_gain_fx = sum2_16_exp_fx( GainShape_fx, NUM_SHB_SUBGAINS, &tmp, 2 ); @@ -3507,11 +3707,9 @@ void swb_tbe_enc_ivas_fx( } ELSE { - // normFact = (float) sqrt( 1.0f / sum_gain ); normFact_fx = ISqrt32( sum_gain_fx, &tmp ); } - // v_multc( GainShape, normFact, GainShape, NUM_SHB_SUBGAINS ); FOR( i = 0; i < NUM_SHB_SUBGAINS; ++i ) { GainShape_fx[i] = extract_h( L_shl( Mpy_32_16_1( normFact_fx, GainShape_fx[i] ), tmp ) ); /* Q15 */ @@ -3546,7 +3744,12 @@ void swb_tbe_enc_ivas_fx( } /* Gain shape smoothing after quantization */ +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -3556,16 +3759,13 @@ void swb_tbe_enc_ivas_fx( lls_interp_n_fx( GainShape_Interp_fx, NUM_SHB_SUBGAINS, &GainShape_tilt_fx, &temp, 1 ); - // if ( vf_ind >= 6 && fabs( GainShape_tilt ) < 0.12f ) test(); IF( GE_16( vf_ind_fx, 6 ) && LT_16( abs_s( GainShape_tilt_fx ), 3932 /* 0.12f in Q15 */ ) ) { - // feedback = 0.3f; feedback = 9830; /* 0.3f in Q15 */ move16(); FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { - // GainShape[i] = ( 1 - feedback ) * GainShape[i * NUM_SHB_SUBGAINS] + feedback * GainShape_Interp[i]; GainShape_fx[i] = extract_h( L_mac( L_mult( sub( MAX16B, feedback ), GainShape_fx[i * NUM_SHB_SUBGAINS] ), feedback, GainShape_Interp_fx[i] ) ); // Q15 move16(); } @@ -3579,8 +3779,7 @@ void swb_tbe_enc_ivas_fx( } /* Estimate the gain parameter */ - 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 ); + 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 ); IF( EQ_16( st_fx->tec_tfa, 1 ) ) { @@ -3595,7 +3794,6 @@ void swb_tbe_enc_ivas_fx( GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ } - // if ( st_fx->element_mode > EVS_MONO && st_fx->L_frame != st_fx->last_L_frame && hBWE_TD->prev_gainFr_SHB != 0 && ( st_fx->last_extl == SWB_TBE || st_fx->last_extl == FB_TBE ) && st_fx->coder_type == TRANSITION && st_fx->coder_type_raw != VOICED && st_fx->clas == VOICED_CLAS && st_fx->last_clas == VOICED_CLAS && ( 3.0f * voice_factors[0] < voice_factors[( st_fx->L_frame >> 6 ) - 1] ) ) test(); test(); test(); @@ -3607,48 +3805,42 @@ void swb_tbe_enc_ivas_fx( test(); IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->L_frame, st_fx->last_L_frame ) && hBWE_TD->prev_gainFr_SHB_fx != 0 && ( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) && EQ_16( st_fx->coder_type, TRANSITION ) && NE_16( st_fx->coder_type_raw, VOICED ) && EQ_16( st_fx->clas, VOICED_CLAS ) && EQ_16( st_fx->last_clas, VOICED_CLAS ) && LT_16( mult( 24576 /* 3.0f in Q13 */, voice_factors_fx[0] ), shr( voice_factors_fx[( st_fx->L_frame >> 6 ) - 1], 2 ) ) ) { - // float fac = GainFrame / hBWE_TD->prev_gainFr_SHB; Word16 fac = BASOP_Util_Divide3232_Scale( GainFrame_fx, hBWE_TD->prev_gainFr_SHB_fx, &tmp_e ); - // if ( fac > 4.0f ) IF( BASOP_Util_Cmp_Mant32Exp( L_deposit_h( fac ), tmp_e, 1073741824, 3 ) > 0 ) { - // GainFrame = 4.0f * GainFrame / fac; GainFrame_fx = BASOP_Util_Divide3216_Scale( GainFrame_fx, fac, &tmp1_e ); GainFrame_fx = L_shl( GainFrame_fx, add( tmp1_e, 2 ) ); /* Q18 */ } } test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { - // if ( acorr_v2a > 0.1f && Env_error > 5.0f ) test(); test(); IF( GT_16( acorr_v2a_fx, 3277 /* 0.1f in Q15 */ ) && GT_16( Env_error_fx, 5 ) ) { /* attenuate frame gain in case of voiced SHB residual signal with gaussian excitation */ - // fact_atten = lin_interp( Env_error, 5.0f, 1.0f, 25.0f, 0.2f, 1 ); fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 5, MAX16B, 25, 6554 /* 0.2f in Q15 */, 1 ); - // GainFrame *= fact_atten; GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); } /* Frame gain attenuation in case of big error in envelope modelling */ - // else if ( Env_error > 100.0f || hBWE_TD->prev_Env_error > 100.0f ) ELSE IF( GT_16( Env_error_fx, 100 ) || GT_16( hBWE_TD->prev_Env_error_fx, 100 ) ) { - // if ( Env_error > 100.0f ) IF( GT_16( Env_error_fx, 100 ) ) { - // fact_atten = lin_interp( Env_error, 100.0f, 1.0f, 300.0f, 0.1f, 1 ); fact_atten_fx = lin_interp_ivas_fx( Env_error_fx, 100, MAX16B, 300, 3277 /* 0.1f in Q15 */, 1 ); } ELSE { - // fact_atten = lin_interp( hBWE_TD->prev_Env_error, 100.0f, 1.0f, 300.0f, 0.5f, 1 ); fact_atten_fx = lin_interp_ivas_fx( hBWE_TD->prev_Env_error_fx, 100, MAX16B, 300, ONE_IN_Q14 /* 0.5f in Q15 */, 1 ); } - // GainFrame *= fact_atten; GainFrame_fx = Mpy_32_16_1( GainFrame_fx, fact_atten_fx ); } } @@ -3677,17 +3869,25 @@ void swb_tbe_enc_ivas_fx( ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) { /*GainFrame *= (0.8f + 0.5f*feedback); */ - tmp = add( 13107 /* 0.8 in Q14 */, shr( feedback, 2 ) ); - GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, tmp ), 1 ); /* Q18 */ +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + tmp = add( 26214, mult_r( feedback, 16384 ) ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ + } + ELSE +#endif + { + tmp = add( 13107 /* 0.8 in Q14 */, shr( feedback, 2 ) ); + GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, tmp ), 1 ); /* Q18 */ + } } hBWE_TD->prev_frGainAtten = frGainAttenuate; move16(); - hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; move16(); /* Q18 */ - // if ( GainFrame > 153.0f && st_fx->element_mode >= IVAS_CPE_DFT && hStereoICBWE != NULL ) test(); test(); if ( GT_32( GainFrame_fx, 40108032 /* 153.0f in Q18 */ ) && GE_16( st_fx->element_mode, IVAS_CPE_DFT ) && hStereoICBWE != NULL ) @@ -3700,9 +3900,13 @@ void swb_tbe_enc_ivas_fx( tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { - // sd_uq_q = 1 - 0.7f * ( sd_uq_q * sd_uq_q ); tmp1 = mult_r( 22938 /*0.7f Q15*/, tmp ); /* Q15, Q6 => Q6 */ L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ } @@ -3725,7 +3929,12 @@ void swb_tbe_enc_ivas_fx( /* keep the L_tmp; dont overwrite */ test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode == EVS_MONO || ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ /* pitch_buf: Q6 */ @@ -3744,32 +3953,57 @@ void swb_tbe_enc_ivas_fx( } voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ - // if ( voicingBufAvg <= 0.0f && sd_uq_q * pitBufAvg != 0 ) - test(); - IF( voicingBufAvg_fx <= 0 && Mpy_32_16_1( L_tmp, pitBufAvg_fx ) != 0 ) +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) { - // voicingBufAvg = sd_uq_q * pitBufAvg / 1.001f; - tmp = BASOP_Util_Divide1616_Scale( pitBufAvg_fx, 16400, &tmp_e ); - tmp_e = sub( add( tmp_e, 5 ), 1 ); - L_tmp1 = Mpy_32_16_1( L_tmp, tmp ); - voicingBufAvg_fx = extract_h( L_tmp1 ); + /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ + /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ + + /* 1/voicingBufAvg_fx */ + tmp = 32767; + move16(); + IF( voicingBufAvg_fx > 0 ) + { + exp = norm_s( voicingBufAvg_fx ); + tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ + + /* sd_uq_q*pitBufAvg */ + L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ + tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ + } } - // else if ( voicingBufAvg <= 0.0f ) - ELSE IF( voicingBufAvg_fx <= 0 ) + ELSE +#endif { - // voicingBufAvg = 1.0f; - voicingBufAvg_fx = MAX16B; - move16(); + test(); + IF( voicingBufAvg_fx <= 0 && Mpy_32_16_1( L_tmp, pitBufAvg_fx ) != 0 ) + { + // voicingBufAvg = sd_uq_q * pitBufAvg / 1.001f; + tmp = BASOP_Util_Divide1616_Scale( pitBufAvg_fx, 16400, &tmp_e ); + tmp_e = sub( add( tmp_e, 5 ), 1 ); + L_tmp1 = Mpy_32_16_1( L_tmp, tmp ); + voicingBufAvg_fx = extract_h( L_tmp1 ); + } + ELSE IF( voicingBufAvg_fx <= 0 ) + { + voicingBufAvg_fx = MAX16B; + move16(); + } } } /* high-band gain control in case of BWS */ test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode != EVS_MONO && ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) +#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { IF( st_fx->bwidth_sw_cnt > 0 ) { - // GainFrame *= ( (float) ( st_fx->bwidth_sw_cnt ) / (float) BWS_TRAN_PERIOD ); tmp = i_mult( st_fx->bwidth_sw_cnt, ONE_BY_BWS_TRAN_PERIOD_Q15 ); GainFrame_fx = Mpy_32_16_1( GainFrame_fx, tmp ); } @@ -3777,9 +4011,19 @@ void swb_tbe_enc_ivas_fx( /* Controlled gain evolution in SWB for stronger voiced segments */ test(); +#ifdef HARMONIZE_TBE3 + test(); + IF( st_fx->element_mode == EVS_MONO ) + { + tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); + tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); + GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ + } + ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) +#endif { - // GainFrame *= sd_uq_q; GainFrame_fx = Mpy_32_16_1( GainFrame_fx, extract_l( L_shl( L_tmp, 2 ) ) ); } ELSE @@ -3810,8 +4054,7 @@ void swb_tbe_enc_ivas_fx( if ( EQ_16( st_fx->rf_mode, 1 ) ) { /* Compensate for energy increase mismatch due to memory-less synthesis */ - // GainFrame *= 0.85f; - GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 ); + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 /*0.85f Q15*/ ); } } ELSE @@ -3820,12 +4063,21 @@ void swb_tbe_enc_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) { /* Compensate for energy increase mismatch due to memory-less synthesis*/ - GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ + GainFrame_fx = Mpy_32_16_1( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ } } /* Quantization of the frame gain parameter */ - 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 ); +#ifdef HARMONIZE_TBE3 + IF( st_fx->element_mode == EVS_MONO ) + { + QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); + } + ELSE +#endif + { + 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 ); + } IF( hStereoICBWE != NULL ) { -- GitLab From 714cb791c391f7ba7008a10dd2ecbe08aab55c83 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Feb 2026 16:23:34 +0100 Subject: [PATCH 05/12] formatting --- lib_com/swb_tbe_com_fx.c | 571 +++++++++++++++++++-------------------- lib_dec/swb_tbe_dec_fx.c | 12 +- lib_enc/swb_tbe_enc_fx.c | 112 ++++---- 3 files changed, 335 insertions(+), 360 deletions(-) diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index a99ff54fe..d55bb7676 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -435,7 +435,6 @@ void flip_and_downmix_generic_fx32( /* Hilber transform stage - 0 - single precision */ Hilbert_transform_fx( tmp, tmp, tmpi_R, tmpi_I, length, 0 ); - Copy32( mem2_ext, tmpi2_R, HILBERT_ORDER2 ); Copy32( mem3_ext, tmpi2_I, HILBERT_ORDER2 ); @@ -609,10 +608,11 @@ static void Hilbert_transform_sp_fx( /*---------------------------------------------- * flip_spectrum_fx *----------------------------------------------*/ + void flip_spectrum_fx( - const Word16 input[], /* i : input spectrum */ - Word16 output[], /* o : output spectrum */ - const Word16 length /* i : vector length */ + const Word16 input[], /* i : input spectrum */ + Word16 output[], /* o : output spectrum */ + const Word16 length /* i : vector length */ ) { Word16 i; @@ -731,6 +731,7 @@ void Calc_rc0_h( return; } +#ifndef HARMONIZE_TBE3 static void Calc_rc0_h_ivas_enc_fx( Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ @@ -789,6 +790,7 @@ static void Calc_rc0_h_ivas_enc_fx( move16(); } } +#endif static void Calc_st_filt_tbe_fx( #ifdef HARMONIZE_TBE3 @@ -938,9 +940,7 @@ static void filt_mu_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /*(14 - exp) */ ga = shl_sat( tmp, exp ); /*Q14 */ - /* ga = (float) 1. / ((float) 1. - (float) fabs (mu)); */ - ptrs = sig_in; /* points on sig_in(-1) */ FOR( n = 0; n < SubFrameLength; n++ ) @@ -1108,11 +1108,11 @@ void PostShortTerm_fx( /* Control short term pst filter gain and compute parcor0 */ #ifdef HARMONIZE_TBE3 - Calc_st_filt_tbe_fx( element_mode, enc_dec, apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); + Calc_st_filt_tbe_fx( element_mode, enc_dec, apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); /* parcor0 in Q15, sig_ltp_fx in Q_bwe_exc */ #else Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); + /* i: parcor0 in Q15, o: sig_ltp_fx in Q_bwe_exc */ #endif - /* parcor0 in Q15, sig_ltp_fx in Q_bwe_exc */ /* 1/A(gamma1) filtering, mem_stp is updated */ #ifdef HARMONIZE_TBE3 @@ -1127,8 +1127,7 @@ void PostShortTerm_fx( } /* (1 + mu z-1) tilt filtering */ - filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); - /* o: sig_out in Q_bwe_exc */ + filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); /* sig_out in Q_bwe_exc */ /* gain control */ scale_st_swb( sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); @@ -1265,12 +1264,12 @@ void PostShortTerm_ivas_dec_fx( *-------------------------------------------------------------------*/ void flip_spectrum_and_decimby4_fx( - const Word16 input[], /* i : input spectrum Q_inp */ - Word16 output[], /* o : output spectrum Q_inp */ - const Word16 length, /* i : vector length */ - Word16 mem1[], /* i/o : memory Q_inp */ - Word16 mem2[], /* i/o : memory Q_inp */ - const Word16 ramp_flag /*i: flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ + const Word16 input[], /* i : input spectrum Q_inp */ + Word16 output[], /* o : output spectrum Q_inp */ + const Word16 length, /* i : vector length */ + Word16 mem1[], /* i/o: memory Q_inp */ + Word16 mem2[], /* i/o: memory Q_inp */ + const Word16 ramp_flag /* i : flag to trigger slow ramp-up of output following change of core (HQ to ACELP or 12k8 to 16k ACELP) */ ) { Word16 i; @@ -2265,333 +2264,328 @@ void GenShapedSHBExcitation_fx( *mem_csfilt = Mult_32_16( L_tmp, varEnvShape ); move32(); } + + /* Track the low band envelope */ + L_tmp = *mem_csfilt; + move32(); + FOR( i = 0; i < L_FRAME16k; i++ ) { - /* Track the low band envelope */ - L_tmp = *mem_csfilt; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) + excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], excTmp2[i] ); + move16(); + /* excNoisyEnv : Q_bwe_exc, + *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ + L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_bwe_exc+16 */ + } + *mem_csfilt = L_tmp; + move32(); + + /* create a random excitation - Reuse exc16k memory */ + White_exc16k = exc16k; + create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); + create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); + + L_tmp = L_deposit_l( 0 ); + tmp = add( *Q_bwe_exc, 1 ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + L_tmp4 = L_shl_sat( L_deposit_l( White_exc16k[k] ), tmp ); + if ( excNoisyEnv[k] != 0 ) { - excNoisyEnv[i] = mac_r( L_tmp, csfilt_num2[0], excTmp2[i] ); - move16(); - /* excNoisyEnv : Q_bwe_exc, - *mem_csfilt: Q_bwe_exc+16, excTmp2: Q_bwe_exc, csfilt_num2[0] Q15 */ - L_tmp = L_mult( excNoisyEnv[i], neg_csfilt_den2[1] ); /* Q_bwe_exc+16 */ + L_tmp4 = L_mult( excNoisyEnv[k], White_exc16k[k] ); /* (Q_bwe_exc) +5 +1*/ } - *mem_csfilt = L_tmp; + White_exc16k_32[k] = L_tmp4; move32(); + L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); } + Q_temp = norm_l( L_tmp ); + if ( L_tmp == 0 ) { - /* create a random excitation - Reuse exc16k memory */ - White_exc16k = exc16k; - create_random_vector_fx( White_exc16k, L_FRAME, bwe_seed, element_mode ); - create_random_vector_fx( White_exc16k + L_FRAME, L_FRAME16k - L_FRAME, bwe_seed, element_mode ); - - L_tmp = L_deposit_l( 0 ); - tmp = add( *Q_bwe_exc, 1 ); - FOR( k = 0; k < L_FRAME16k; k++ ) - { - L_tmp4 = L_shl_sat( L_deposit_l( White_exc16k[k] ), tmp ); - if ( excNoisyEnv[k] != 0 ) - { - L_tmp4 = L_mult( excNoisyEnv[k], White_exc16k[k] ); /* (Q_bwe_exc) +5 +1*/ - } - White_exc16k_32[k] = L_tmp4; - move32(); - L_tmp = L_max( L_tmp, L_abs( White_exc16k_32[k] ) ); - } - Q_temp = norm_l( L_tmp ); - if ( L_tmp == 0 ) - { - Q_temp = 31; - move16(); - } - /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ - /* White_exc16k in Q6 */ + Q_temp = 31; + move16(); + } + /*Copy_Scale_sig( White_exc16k, White_exc16k, L_FRAME16k, sub(NOISE_QFAC, 5) );)*/ + /* White_exc16k in Q6 */ - /* calculate pow22 */ - /* pow22=0.00001f */ - tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); - pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ - tmp = sub( NOISE_QFAC, 5 ); - FOR( k = 0; k < L_FRAME16k; k++ ) - { - /* White_exc16k[k] *= excNoisyEnv[k]; */ - White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); - move16(); - /* i: excNoisyEnv in (Q_bwe_exc) */ - /* i: White_exc16k in Q6 */ - /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ - /* pow22 += White_exc16k[k] * White_exc16k[k]; */ - pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ - } - /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ - Q_pow22 = shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ); + /* calculate pow22 */ + /* pow22=0.00001f */ + tmp = sub( shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ), 31 ); + pow22 = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 0.00001f in 2*(Q_bwe_exc-NOISE_QADJ) */ + tmp = sub( NOISE_QFAC, 5 ); + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /* White_exc16k[k] *= excNoisyEnv[k]; */ + White_exc16k[k] = mult_r( excNoisyEnv[k], shl( White_exc16k[k], tmp ) ); + move16(); + /* i: excNoisyEnv in (Q_bwe_exc) */ + /* i: White_exc16k in Q6 */ + /* o: White_exc16k in (Q_bwe_exc-NOISE_QADJ) */ + /* pow22 += White_exc16k[k] * White_exc16k[k]; */ + pow22 = L_mac0_sat( pow22, White_exc16k[k], White_exc16k[k] ); /* 2*(Q_bwe_exc-NOISE_QADJ)*/ } + /*Q_pow22 = sub( shl(*Q_bwe_exc,1), 18 );*/ + Q_pow22 = shl( sub( *Q_bwe_exc, NOISE_QADJ ), 1 ); IF( GE_32( bitrate, ACELP_24k40 ) ) { IF( EQ_16( *vf_ind, 20 ) ) /* encoder side */ { + Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, + ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); + tmp = voiceFacEst[0]; + move16(); + tmp2 = MAX_16; + move16(); + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - Estimate_mix_factors_fx( shb_res, Q_shb, exc16kWhtnd, *Q_bwe_exc, White_exc16k, - ( *Q_bwe_exc - NOISE_QADJ ), pow1, Q_pow1, pow22, Q_pow22, voiceFacEst, vf_ind ); - tmp = voiceFacEst[0]; + tmp2 = 26214 /*0.8f Q15*/; move16(); - tmp2 = MAX_16; - move16(); - if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) - { - tmp2 = 26214 /*0.8f Q15*/; - move16(); - } } } ELSE /* decoder side */ + { + /* *vf_ind is an integer scale by 0.125f*/ + tmp = shl( *vf_ind, ( 15 - 3 ) ); + tmp2 = MAX_16; + move16(); + if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) { - { /* *vf_ind is an integer scale by 0.125f*/ - tmp = shl( *vf_ind, ( 15 - 3 ) ); - tmp2 = MAX_16; - move16(); - if ( LE_16( tmp, 22938 /*0.7f Q15*/ ) ) + tmp2 = 26214 /*0.8f Q15*/; + move16(); + } + } { - tmp2 = 26214 /*0.8f Q15*/; + voice_factors[0] = mult_r( voice_factors[0], tmp2 ); + move16(); + voice_factors[1] = mult_r( voice_factors[1], tmp2 ); + move16(); + voice_factors[2] = mult_r( voice_factors[2], tmp2 ); + move16(); + voice_factors[3] = mult_r( voice_factors[3], tmp2 ); + move16(); + voice_factors[4] = mult_r( voice_factors[4], tmp2 ); move16(); } } -} -{ - voice_factors[0] = mult_r( voice_factors[0], tmp2 ); - move16(); - voice_factors[1] = mult_r( voice_factors[1], tmp2 ); - move16(); - voice_factors[2] = mult_r( voice_factors[2], tmp2 ); - move16(); - voice_factors[3] = mult_r( voice_factors[3], tmp2 ); - move16(); - voice_factors[4] = mult_r( voice_factors[4], tmp2 ); - move16(); -} -} -tmp = sub( Q_temp, 3 ); -FOR( k = 0; k < L_FRAME16k; k++ ) -{ - White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ -} -prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; -move16(); -*Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); -move16(); -deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); // Q_bwe_exc-NOISE_QADJ -{ - IF( EQ_16( coder_type, UNVOICED ) ) + tmp = sub( Q_temp, 3 ); + FOR( k = 0; k < L_FRAME16k; k++ ) { - L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); - scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ - FOR( k = 0; k < L_FRAME16k; k++ ) - { - /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ - L_tmp = L_mult( White_exc16k[k], scale ); - /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ - exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); - move16(); - /* exc16kWhtnd: Q_bwe_exc */ - } - preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc + White_exc16k_FB[k] = round_fx( L_shl( White_exc16k_32[k], tmp ) ); /* Q_bwe_exc +5 +1 +Q_temp -16 -3 */ } - ELSE + prev_Q_bwe_exc_fb = *Q_bwe_exc_fb; + move16(); + *Q_bwe_exc_fb = sub( add( *Q_bwe_exc, Q_temp ), 13 ); + move16(); + deemph_fx( White_exc16k, PREEMPH_FAC, L_FRAME16k, tbe_demph ); // Q_bwe_exc-NOISE_QADJ { - Word16 nbSubFr, lSubFr; - Word16 tempQ15; - Word32 tempQ31; - /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ - nbSubFr = NB_SUBFR16k; - lSubFr = ( L_FRAME16k / NB_SUBFR16k ); - IF( LT_32( bitrate, ACELP_24k40 ) ) + IF( EQ_16( coder_type, UNVOICED ) ) { - nbSubFr = NB_SUBFR; - move16(); - lSubFr = ( L_FRAME16k / NB_SUBFR ); - move16(); + L_tmp = root_a_over_b_fx( pow1, Q_pow1, pow22, Q_pow22, &exp ); + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ + FOR( k = 0; k < L_FRAME16k; k++ ) + { + /* White_exc16k: (Q_bwe_exc-NOISE_QADJ), scale: Q15 */ + L_tmp = L_mult( White_exc16k[k], scale ); + /* L_tmp: (Q_bwe_exc-NOISE_QADJ) + 15 + 1 */ + exc16kWhtnd[k] = round_fx( L_shl( L_tmp, NOISE_QADJ ) ); + move16(); + /* exc16kWhtnd: Q_bwe_exc */ + } + preemph_fx( exc16kWhtnd, PREEMPH_FAC, L_FRAME16k, tbe_premph ); // Q_bwe_exc } - k = 0; - FOR( i = 0; i < nbSubFr; i++ ) + ELSE { - test(); - IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) + Word16 nbSubFr, lSubFr; + Word16 tempQ15; + Word32 tempQ31; + /*nbSubFr = ( bitrate < ACELP_24k40 )? NB_SUBFR : NB_SUBFR16k;*/ + nbSubFr = NB_SUBFR16k; + lSubFr = ( L_FRAME16k / NB_SUBFR16k ); + IF( LT_32( bitrate, ACELP_24k40 ) ) { - exp = 0; + nbSubFr = NB_SUBFR; move16(); - tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ - temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - exp = 0; + lSubFr = ( L_FRAME16k / NB_SUBFR ); move16(); - tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ - temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ - temp = sub( MAX_16, temp ); - tempQ31 = Mult_32_16( pow1, temp ); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ } - ELSE + k = 0; + FOR( i = 0; i < nbSubFr; i++ ) { - /* Adjust noise mixing for formant sharpening filter */ - tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); - /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ - vf_tmp = sub( MAX_16, tempQ15 ); - vf_tmp = mult_r( voice_factors[i], vf_tmp ); + test(); + IF( EQ_16( coder_type, VOICED ) && ( LT_32( bitrate, ACELP_24k40 ) ) ) + { + exp = 0; + move16(); + tempQ15 = Sqrt16( voice_factors[i], &exp ); /* Q15 */ + temp = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ + exp = 0; + move16(); + tempQ15 = Sqrt16( temp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - exp = 0; - move16(); - tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ - temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - - /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ - temp = sub( MAX_16, vf_tmp ); - tempQ31 = Mult_32_16( pow1, temp ); - L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); - temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ - } + /*temp2 = root_a_over_b_fx( pow1 * (1.0f - temp), pow22 ); */ + temp = sub( MAX_16, temp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ + } + ELSE + { + /* Adjust noise mixing for formant sharpening filter */ + tempQ15 = mult_r( SWB_NOISE_MIX_FAC_FX, formant_fac ); + /* vf_tmp = voice_factors[i] * (1.0f - vf_tmp); */ + vf_tmp = sub( MAX_16, tempQ15 ); + vf_tmp = mult_r( voice_factors[i], vf_tmp ); - FOR( j = 0; j < lSubFr; j++ ) - { - /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ - L_tmp = L_mult( temp2, White_exc16k[k + j] ); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ - L_tmp = L_shl_sat( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ - exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); - move16(); - /* Q_bwe_exc */ - } - k = add( k, lSubFr ); + exp = 0; + move16(); + tempQ15 = Sqrt16( vf_tmp, &exp ); /* Q15 */ + temp1 = shl( tempQ15, exp ); /* Q15 exc16kWhtnd scale factor */ - /* estimate the pre-emph factor */ - tempQ15 = sub( MAX_16, voice_factors[i] ); - exp = 0; - move16(); - temp = Sqrt16( tempQ15, &exp ); - temp = shl( temp, exp - 1 ); + /*temp2 = root_a_over_b(pow1 * (1.0f - vf_tmp), pow22); */ + temp = sub( MAX_16, vf_tmp ); + tempQ31 = Mult_32_16( pow1, temp ); + L_tmp = root_a_over_b_fx( tempQ31, Q_pow1, pow22, Q_pow22, &exp ); + temp2 = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q15 whiteEnvShapedExc scale factor */ + } + + FOR( j = 0; j < lSubFr; j++ ) + { + /*exc16kWhtnd[k+j] = temp1 * exc16kWhtnd[k+j] + temp2 * White_exc16k[k+j]; */ + L_tmp = L_mult( temp2, White_exc16k[k + j] ); /* 16+(Q_bwe_exc-NOISE_QADJ)*/ + L_tmp = L_shl_sat( L_tmp, NOISE_QADJ ); /* 16+(Q_bwe_exc) */ + exc16kWhtnd[k + j] = mac_r_sat( L_tmp, temp1, exc16kWhtnd[k + j] ); + move16(); + /* Q_bwe_exc */ + } + k = add( k, lSubFr ); - temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ - temp = div_s( temp, temp2 ); /* Q15 */ - temp = mult_r( PREEMPH_FAC, temp ); + /* estimate the pre-emph factor */ + tempQ15 = sub( MAX_16, voice_factors[i] ); + exp = 0; + move16(); + temp = Sqrt16( tempQ15, &exp ); + temp = shl( temp, exp - 1 ); + + temp2 = add( temp, shl( temp1, -1 ) ); /* shift right by 1 to avoid overflow */ + temp = div_s( temp, temp2 ); /* Q15 */ + temp = mult_r( PREEMPH_FAC, temp ); - preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_bwe_exc + preemph_fx( &exc16kWhtnd[i * lSubFr], temp, lSubFr, tbe_premph ); // Q_bwe_exc + } } } -} -IF( LT_32( bitrate, ACELP_24k40 ) ) -{ - Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: excSHB in Q_bwe_exc */ -} -ELSE -{ - set16_fx( zero_mem, 0, LPC_SHB_ORDER ); + IF( LT_32( bitrate, ACELP_24k40 ) ) + { + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, exc16kWhtnd, excSHB, L_FRAME16k, state_lpc_syn, 1 ); + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: excSHB in Q_bwe_exc */ + } + ELSE + { + set16_fx( zero_mem, 0, LPC_SHB_ORDER ); - Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[0] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[1] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[2] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); - syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); - move32(); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, tempSHB, 80, zero_mem, 1 ); + syn_shb_ener_sf[3] = L_shr( sum2_fx( tempSHB, 80 ), 3 ); + move32(); - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: tempSHB in Q_bwe_exc */ - /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ - IF( LE_32( bitrate, ACELP_32k ) ) - { - L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: tempSHB in Q_bwe_exc */ + /* o: syn_shb_ener_sf in (2*Q_bwe_exc+1) */ + IF( LE_32( bitrate, ACELP_32k ) ) + { + L_tmp = sum32_fx( syn_shb_ener_sf, 4 ); - /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ - tmp = shl( Q_shb, 1 ); - tmp2 = add( shl( *Q_bwe_exc, 1 ), 1 ); - L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ + /* find root_a(tempSHB[0]) = root_a_over_b(shb_ener_sf[0]), L_tmp) */ + tmp = shl( Q_shb, 1 ); + tmp2 = add( shl( *Q_bwe_exc, 1 ), 1 ); + L_tmp2 = root_a_over_b_fx( shb_ener_sf_32, tmp, L_tmp, tmp2, &exp ); /* L_tmp2 in (Q31-exp) */ - *Q_bwe_exc = sub( *Q_bwe_exc, exp ); - move16(); /* compensate for the exp shift */ - tmp2 = add( prev_Q_bwe_syn, n_mem2 ); - IF( GT_16( *Q_bwe_exc, tmp2 ) ) + *Q_bwe_exc = sub( *Q_bwe_exc, exp ); + move16(); /* compensate for the exp shift */ + tmp2 = add( prev_Q_bwe_syn, n_mem2 ); + IF( GT_16( *Q_bwe_exc, tmp2 ) ) + { + L_tmp2 = L_shl( L_tmp2, sub( tmp2, *Q_bwe_exc ) ); + *Q_bwe_exc = tmp2; + move16(); + } + FOR( i = 0; i < L_FRAME16k; i++ ) + { + L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ + exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + move16(); + } + } + /* i: L_tmp2 in (Q31-exp) */ + /* i: exc16kWhtnd in Q_bwe_exc */ + /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ + + /* Rescale the past memories: LP synth and SHB look ahead buffers */ + tmp = sub( *Q_bwe_exc, prev_Q_bwe_syn ); + FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - L_tmp2 = L_shl( L_tmp2, sub( tmp2, *Q_bwe_exc ) ); - *Q_bwe_exc = tmp2; + state_lpc_syn[i] = shl( state_lpc_syn[i], tmp ); move16(); } - FOR( i = 0; i < L_FRAME16k; i++ ) + FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) { - L_tmp3 = Mult_32_16( L_tmp2, exc16kWhtnd[i] ); /* *Q_bwe_exc + (31-exp) - 15 */ - exc16kWhtnd[i] = round_fx( L_tmp3 ); /* *Q_bwe_exc - exp */ + excSHB[i] = shl( excSHB[i], tmp ); move16(); } - } - /* i: L_tmp2 in (Q31-exp) */ - /* i: exc16kWhtnd in Q_bwe_exc */ - /* o: exc16kWhtnd in Q_bwe_exc: (Q_bwe_exc-exp) */ + /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - /* Rescale the past memories: LP synth and SHB look ahead buffers */ - tmp = sub( *Q_bwe_exc, prev_Q_bwe_syn ); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - state_lpc_syn[i] = shl( state_lpc_syn[i], tmp ); - move16(); - } - FOR( i = -L_SHB_LAHEAD; i < 0; i++ ) - { - excSHB[i] = shl( excSHB[i], tmp ); - move16(); + Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); + Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); + /* i: exc16kWhtnd in (Q_bwe_exc) */ + /* o: excSHB in (Q_bwe_exc) */ } - /* Do mem_stp_swb_fx scaling before PostShortTerm_fx */ - - Syn_filt_s( 0, lpc_shb_sf, LPC_SHB_ORDER, exc16kWhtnd, excSHB, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 80, excSHB + 80, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + 2 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 160, excSHB + 160, 80, state_lpc_syn, 1 ); - Syn_filt_s( 0, lpc_shb_sf + 3 * ( LPC_SHB_ORDER + 1 ), LPC_SHB_ORDER, exc16kWhtnd + 240, excSHB + 240, 80, state_lpc_syn, 1 ); - /* i: exc16kWhtnd in (Q_bwe_exc) */ - /* o: excSHB in (Q_bwe_exc) */ -} - -IF( EQ_16( extl, FB_TBE ) ) -{ - tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); - Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); - Scale_sig( fb_tbe_demph, 1, tmp ); - Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); - /* i: White_exc16k_FB in (14-n2) */ - /* o: White_exc16k_FB_temp in (14-n2) */ - FOR( i = 0; i < 10; i++ ) + IF( EQ_16( extl, FB_TBE ) ) { - FOR( j = 0; j < 32; ++j ) + tmp = sub( add( *Q_bwe_exc_fb, 20 ), prev_Q_bwe_exc_fb ); + Scale_sig( fb_state_lpc_syn, LPC_SHB_ORDER, tmp ); + Scale_sig( fb_tbe_demph, 1, tmp ); + Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER, White_exc16k_FB, White_exc16k_FB_temp, L_FRAME16k, fb_state_lpc_syn, 1 ); + /* i: White_exc16k_FB in (14-n2) */ + /* o: White_exc16k_FB_temp in (14-n2) */ + + FOR( i = 0; i < 10; i++ ) { - White_exc16k_FB_temp[i * 32 + j] = mult_r( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); - move16(); + FOR( j = 0; j < 32; ++j ) + { + White_exc16k_FB_temp[i * 32 + j] = mult_r( White_exc16k_FB_temp[i * 32 + j], cos_fb_exc_fx[j] ); + move16(); + } } - } - *Q_bwe_exc_fb = add( *Q_bwe_exc_fb, 20 ); - move16(); /**Q_bwe_exc_fb +35 +1 -16*/ - flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); + *Q_bwe_exc_fb = add( *Q_bwe_exc_fb, 20 ); + move16(); /**Q_bwe_exc_fb +35 +1 -16*/ + flip_spectrum_fx( White_exc16k_FB_temp, White_exc16k_FB, L_FRAME16k ); - deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); -} -ELSE -{ - set16_fx( White_exc16k_FB, 0, L_FRAME16k ); -} + deemph_fx( White_exc16k_FB, fb_deemph_fac, L_FRAME16k, fb_tbe_demph ); + } + ELSE + { + set16_fx( White_exc16k_FB, 0, L_FRAME16k ); + } -return; + return; } #ifdef HARMONIZE_TBE2 @@ -5510,7 +5504,7 @@ void ScaleShapedSHB_fx32( *-------------------------------------------------------------------*/ void ScaleShapedWB_fx( - const Word16 length, /* i : SHB overlap length */ + 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*/ @@ -6303,7 +6297,6 @@ void create_random_vector_fx( /* INPUT/OUTPUT ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------------*/ - /* _ None */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ @@ -6311,21 +6304,21 @@ void create_random_vector_fx( /*======================================================================================*/ void interp_code_5over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx */ + Word16 interp_code_fx[], /* o : output vector Qx */ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, kk, kkp1, i_len2; Word32 Ltemp; - Word16 factor_i_fx[5] = { 6554, 19661, 32767, 19661, 6554 }; + const Word16 factor_i_fx[5] = { 6554, 19661, 32767, 19661, 6554 }; move16(); move16(); move16(); move16(); move16(); move16(); - Word16 factor_j_fx[5] = { 26214, 13107, 0, 13107, 26214 }; + const Word16 factor_j_fx[5] = { 26214, 13107, 0, 13107, 26214 }; move16(); move16(); move16(); @@ -6408,7 +6401,6 @@ void interp_code_5over2_fx( /* INPUT/OUTPUT ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------------------*/ - /* _ None */ /*--------------------------------------------------------------------------------------*/ /* RETURN ARGUMENTS : */ @@ -6416,9 +6408,9 @@ void interp_code_5over2_fx( /*======================================================================================*/ void interp_code_4over2_fx( - const Word16 inp_code_fx[], /* i : input vector Qx*/ - Word16 interp_code_fx[], /* o : output vector Qx*/ - const Word16 inp_length /* i : length of input vector */ + const Word16 inp_code_fx[], /* i : input vector Qx */ + Word16 interp_code_fx[], /* o : output vector Qx */ + const Word16 inp_length /* i : length of input vector */ ) { Word16 i, j; @@ -6958,7 +6950,6 @@ static void Estimate_mix_factors_fx( /* temp_p1_p3 = (float)sqrt(pow1/pow3); */ temp_p1_p3 = root_a_over_b_fx( pow1, Q_pow1, pow3, ( 2 * Q_shb + 1 ), &exp2 ); /* temp_p1_p3 in (Q31+exp2) */ - sc1 = sub( Q_bwe_exc, sub( Q_frac, exp1 ) ); sc2 = sub( Q_bwe_exc, sub( Q_shb, exp2 ) ); FOR( i = 0; i < L_FRAME16k; i++ ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 04ce9402c..e531c40c2 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -4637,9 +4637,10 @@ void swb_tbe_dec_ivas_fx( hBWE_TD = st->hBWE_TD; +#ifndef HARMONIZE_TBE3 Word32 old_syn_12k8_16k_fx[L_FRAME16k]; Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) - +#endif /* initializations */ GainFrame_fx = 0; move32(); @@ -4671,7 +4672,7 @@ void swb_tbe_dec_ivas_fx( move16(); } -/* find tilt */ + /* find tilt */ #ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { @@ -4681,6 +4682,10 @@ void swb_tbe_dec_ivas_fx( ELSE #endif { +#ifdef HARMONIZE_TBE3 + Word32 old_syn_12k8_16k_fx[L_FRAME16k]; + Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) +#endif calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) ); } @@ -5368,7 +5373,6 @@ void swb_tbe_dec_ivas_fx( move16(); Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - /* -------- end of rescaling memories -------- */ Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; @@ -6408,7 +6412,7 @@ void swb_tbe_dec_ivas_fx( /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ GenSHBSynth_fx32( shaped_shb_excitation_fx_32, error_fx, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->L_frame, &( hBWE_TD->syn_dm_phase ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) ); + Copy_Scale_sig_32_16( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -( Q11 - Q_bwe_exc ) ); Copy32( error_fx + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH ); } diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 0e0ae926c..b8bf8546b 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -299,7 +299,6 @@ static void find_max_mem_wb_enc( Lmax = L_abs( hBWE_TD->mem_csfilt_fx[i] ); } - IF( Lmax == 0 ) { n_mem_32 = 31; @@ -2659,9 +2658,9 @@ void swb_tbe_enc_ivas_fx( L_tmp = L_mac( L_tmp, tmp, tmp ); } sd_uq_q_fx = round_fx( L_tmp ); /* sd_uq_q_fx in Q15 */ + /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ /* mean(voice_factors_fx[i], 4); */ - L_tmp = L_mult( voice_factors_fx[0], 8192 ); L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); @@ -2811,12 +2810,9 @@ void swb_tbe_enc_ivas_fx( } /* -------- Calculate the SHB Energy -------- */ - /*shb_ener_sf[0] = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, 320 );*/ FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++ ) { - /* shbEner = shbEner + in[i] * in[i] */ - shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); - /* o: shb_ener_sf_Q31 in (2*Q_shb) */ + shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); /* shb_ener_sf_Q31 in (2*Q_shb) */ } 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 ); @@ -2935,10 +2931,8 @@ void swb_tbe_enc_ivas_fx( move16(); FOR( k = 0; k < 4; k++ ) { - // seg_mean[k] = max(1.0f, mean(&EnvSHBres_4k[k * seg_len], seg_len)); seg_mean[k] = s_max( 1, mean_no_sat_fx( &EnvSHBres_4k_fx[k * seg_len], seg_len ) ); /* Q_shb */ move16(); - // den_seg_mean[k] = 1.0f / seg_mean[k]; tmp = BASOP_Util_Divide1616_Scale( MAX16B, seg_mean[k], &tmp_e ); tmp_e = sub( tmp_e, sub( 15, Q_shb ) ); den_seg_mean[k] = shl_sat( tmp, tmp_e ); /* Q15 */ @@ -2954,7 +2948,6 @@ void swb_tbe_enc_ivas_fx( { env_mean_normf_fx[0] = hBWE_TD->old_mean_EnvSHBres_fx; /* Q15 */ move16(); - // step = (den_seg_mean[0] - hBWE_TD->old_mean_EnvSHBres) * den_seg_len_2; step = mult( sub( den_seg_mean[0], hBWE_TD->old_mean_EnvSHBres_fx ), den_seg_len_2 ); /* Q15 */ FOR( i = 1; i < seg_len_2; i++ ) { @@ -2967,7 +2960,6 @@ void swb_tbe_enc_ivas_fx( p_env = &env_mean_normf_fx[seg_len_2]; FOR( k = 1; k < 4; k++ ) { - // step = ( den_seg_mean[k] - den_seg_mean[k - 1] ) * den_seg_len; step = mult( sub( den_seg_mean[k], den_seg_mean[k - 1] ), den_seg_len ); FOR( i = 0; i < seg_len; i++ ) { @@ -3015,10 +3007,8 @@ void swb_tbe_enc_ivas_fx( Copy( &buf_EnvSHBres_fx[L_FRAME4k], hBWE_TD->old_EnvSHBres_fx, L_FRAME4k ); // Q_shb /* calculate energy normalization factor for the auto-correlation function */ - // pow0 = sum2_f( &buf_EnvSHBres[L_FRAME4k], L_FRAME4k ) + 1.0f; pow_e = sub( 15, Q_shb ); pow0_fx = sum2_16_exp_fx( &buf_EnvSHBres_fx[L_FRAME4k], L_FRAME4k, &pow_e, 0 /* Give guard bits */ ) + 1; - // if (hBWE_TD->prev_enr_EnvSHBres == 1.0f) IF( BASOP_Util_Cmp_Mant32Exp( hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e, 1, 31 ) == 0 ) { // scale = 1.0f / pow0; @@ -3027,7 +3017,6 @@ void swb_tbe_enc_ivas_fx( } ELSE { - // scale = 1.0f / max( pow0, hBWE_TD->prev_enr_EnvSHBres ); L_tmp1 = pow0_fx; move32(); IF( BASOP_Util_Cmp_Mant32Exp( L_tmp1, pow_e, hBWE_TD->prev_enr_EnvSHBres_fx, hBWE_TD->prev_enr_EnvSHBres_e ) < 0 ) @@ -3064,7 +3053,6 @@ void swb_tbe_enc_ivas_fx( tmp_e = W_norm( W_tmp ); L_tmp1 = W_extract_h( W_shl( W_tmp, tmp_e ) ); // 2 * Q_shb + tmp_e - 31 L_tmp = Mpy_32_16_1( L_tmp1, scale_fx ); /* 2 * Q_shb + tmp_e - 31 - scale_e */ - //*p_acorr++ = extract_h( L_shl( L_tmp, add( 16, Q_shb ) - ( 2 * Q_shb + tmp_e - 31 - scale_e ) ) ); *p_acorr++ = extract_h( L_shl( L_tmp, sub( add( 16, Q_shb ), sub( sub( add( shl( Q_shb, 1 ), tmp_e ), 31 ), scale_e ) ) ) ); move16(); } @@ -3076,11 +3064,9 @@ void swb_tbe_enc_ivas_fx( /* multiply with the maximum of the SHB autocorrelation function */ maximum_fx( acorr_EnvSHBres, ENVSHBRES_ACORR_MAX - ENVSHBRES_ACORR_MIN, &temp ); - // acorr_v2a *= temp; L_tmp = Mpy_32_16_1( L_tmp, temp ); /* 31 - tmp_e + Q_shb - 15 */ - // alpha = 25.0f; - alpha_fx = -1677721600; // Q26 + alpha_fx = -1677721600; // -25.0 in Q26 move32(); // acorr_v2a = 2.0f / ( 1.0f + (float) expf( -alpha * acorr_v2a ) ) - 1.0f; @@ -3104,7 +3090,6 @@ void swb_tbe_enc_ivas_fx( res_e = BASOP_Util_Add_MantExp( acorr_v2a_fx, res_e, -1, 15, &acorr_v2a_fx ); /* limit in the range 0.0 - 1.0 */ - // acorr_v2a = min( 1.0f, max( 0.0f, acorr_v2a ) ); acorr_v2a_fx = shl_sat( acorr_v2a_fx, res_e ); if ( acorr_v2a_fx < 0 ) @@ -4111,14 +4096,9 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < L_FRAME16k; i++ ) { L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ - /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ + White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ move16(); - /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); - /*White_exc16k_fx[i] =32767;*/ - /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ move16(); @@ -4530,15 +4510,15 @@ static Word32 pow_off_pk_corrected_fx( /*--------------------------------------------------------------------------*/ static void EstimateSHBGainShape_fx( - 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 target original SHB frame */ - const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ - const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ - Word16 *subgain, /* o : estimate of gain shape Q15 */ - const Word16 *subwin, /* i : SHB subframe window Q15 */ - Word16 *n_subfr_saturation, /* o : Number of subframes which saturated while calculating oriNrg */ - const Flag limit_min_gain /* i : gain shape limiting flag */ + 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 target original SHB frame */ + const Word16 *synSHB, /* i : shaped SHB excitation Q(Q_synSHB) */ + const Word16 Q_synSHB, /* i : Q of shaped SHB excitation */ + Word16 *subgain, /* o : estimate of gain shape Q15 */ + const Word16 *subwin, /* i : SHB subframe window Q15 */ + Word16 *n_subfr_saturation, /* o : Number of subframes which saturated while calculating oriNrg */ + const Flag limit_min_gain /* i : gain shape limiting flag */ ) { const Word16 *skip; @@ -4794,11 +4774,11 @@ static void EstimateSHBGainShape_fx( /*--------------------------------------------------------------------------*/ static Word16 closest_centroid_fx( - const Word16 *data, /* i : input data Qx*/ - const Word16 *weights, /* i : weights */ - const Word16 *quantizer, /* i : quantizer table Qx*/ - const Word16 centroids, /* i : number of centroids */ - const Word16 length ) /* i : dimension of quantiser */ + const Word16 *data, /* i : input data Qx */ + const Word16 *weights, /* i : weights */ + const Word16 *quantizer, /* i : quantizer table Qx */ + const Word16 centroids, /* i : number of centroids */ + const Word16 length ) /* i : dimension of quantiser */ { Word16 i, j, index; Word16 tmp, tmpL; @@ -4903,9 +4883,9 @@ static Word16 closest_centroid_lc_fx( /*------------------------------------------------------------*/ static void QuantizeSHBsubgains_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 subgains[], /* i/o: super highband temporal gains Q15*/ - const Word16 extl /* i : extension layer */ + Encoder_State *st_fx, /* i/o: encoder state structure */ + Word16 subgains[], /* i/o: super highband temporal gains Q15 */ + const Word16 extl /* i : extension layer */ ) { Word16 i, idxSubGain; @@ -5405,9 +5385,10 @@ return; /*------------------------------------------------------------*/ static void determine_gain_weights_fx( - const Word32 *gain, /* i : Gain parameter Q18 */ - Word16 *weights, /* o : gain weights Q12/Q6*/ - const Word16 dims /* i : number of gains */ ) + const Word32 *gain, /* i : Gain parameter Q18 */ + Word16 *weights, /* o : gain weights Q12/Q6*/ + const Word16 dims /* i : number of gains */ +) { Word16 j; Word16 exp, exp1, frac, tmp, exp2; @@ -5470,13 +5451,13 @@ static void determine_gain_weights_fx( /*------------------------------------------------------------------------------*/ static void singlevectortest_gain_fx( - const Word32 *inp, /* i : input gain vector Q18*/ - const Word16 dimen, /* i : dimension of the input vector */ - const Word16 cb_size, /* i : codebook size */ - Word16 *index, /* o : quanitzation index */ - Word32 *recon, /* o : Reconstruction Q18 */ - const Word32 *codebook - /* i : Codebook Q18*/ ) + const Word32 *inp, /* i : input gain vector Q18*/ + const Word16 dimen, /* i : dimension of the input vector */ + const Word16 cb_size, /* i : codebook size */ + Word16 *index, /* o : quanitzation index */ + Word32 *recon, /* o : Reconstruction Q18 */ + const Word32 *codebook /* i : Codebook Q18*/ +) { Word16 k, interNum, flag; Word32 meanU, meanQ; @@ -5618,9 +5599,9 @@ static void return_M_Least_fx_GainFrame( *-------------------------------------------------------------------*/ static void Quant_lower_LSF_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ - Word16 lsf_q[], /* o : Quantized LSFs Q15 */ - Word16 lsf_idx[] /* o : Quantized LSFs indices */ + const Word16 lsf[], /* i : Input LSFs Q15 */ + Word16 lsf_q[], /* o : Quantized LSFs Q15 */ + Word16 lsf_idx[] /* o : Quantized LSFs indices */ ) { Word16 i; @@ -5644,9 +5625,9 @@ static void Quant_lower_LSF_fx( *-------------------------------------------------------------------*/ static Word16 Quant_mirror_point_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ - const Word16 lsf_q[], /* i : Quantized LSFs Q15 */ - Word16 *m /* o : Mirror point Q15 */ + const Word16 lsf[], /* i : Input LSFs Q15 */ + const Word16 lsf_q[], /* i : Quantized LSFs Q15 */ + Word16 *m /* o : Mirror point Q15 */ ) { Word16 m_diff; @@ -5670,9 +5651,9 @@ static Word16 Quant_mirror_point_fx( *-------------------------------------------------------------------*/ static Word16 Find_LSF_grid_fx( - const Word16 lsf[], /* i : Input LSFs Q15 */ - Word16 lsf_q[], /* o : Quantized LSFs Q15 */ - const Word16 m /* i : Mirror point Q15 */ + const Word16 lsf[], /* i : Input LSFs Q15 */ + Word16 lsf_q[], /* o : Quantized LSFs Q15 */ + const Word16 m /* i : Mirror point Q15 */ ) { Word16 lsf_map[NUM_MAP_LSF]; @@ -5690,7 +5671,6 @@ static Word16 Find_LSF_grid_fx( Word16 tmp, exp, tmp1; Word32 L_tmp; - tmp = shl( m, 1 ); lsf_map[0] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 0] ); move16(); @@ -5703,7 +5683,6 @@ static Word16 Find_LSF_grid_fx( lsf_map[4] = sub( tmp, lsf_q[NUM_MAP_LSF - 1 - 4] ); move16(); - IF( GT_16( m, MAX_LSF_FX_2 ) ) { offset = lsf_map[0]; @@ -5918,6 +5897,7 @@ static void gainFrSmooth_En_fx( return; } + #define MAXINT32 MAX_32 static void first_VQstages_fx( const Word16 *const *cb, @@ -6293,8 +6273,8 @@ static void Quant_BWE_LSF_fx( 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 */ - const Word16 lsf_shb_fx[], /* i : unquanitzed LSFs Q15 */ - Word16 Q_lsfs_fx[], /* o : quanitzed LSFs Q15 */ + const Word16 lsf_shb_fx[], /* i : unquanitzed LSFs Q15 */ + Word16 Q_lsfs_fx[], /* o : quanitzed LSFs Q15 */ const Word32 extl_brate /* i : extension layer bit rate */ ) { @@ -6366,6 +6346,7 @@ static void Quant_BWE_LSF_fx( return; } + /*-------------------------------------------------------------------* * fb_tbe_enc() * @@ -6616,14 +6597,13 @@ void fb_tbe_enc_fx( *---------------------------------------------------------------------*/ void tbe_write_bitstream_fx( - Encoder_State *st_fx /* i/o: encoder state structure */ + Encoder_State *st_fx /* i/o: encoder state structure */ ) { Word16 i; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - test(); test(); test(); -- GitLab From c4cb8a23ddbc712a9ca2152da5a326a9c658006a Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 27 Feb 2026 16:27:24 +0100 Subject: [PATCH 06/12] formatting --- lib_enc/swb_tbe_enc_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index b8bf8546b..afe00ac80 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -3447,7 +3447,7 @@ void swb_tbe_enc_ivas_fx( test(); #ifdef HARMONIZE_TBE3 test(); - IF( st_fx->element_mode == EVS_MONO || NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) + IF( st_fx->element_mode == EVS_MONO || ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) #else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) #endif -- GitLab From 6b6895a1d8a2c4db3a17af496c92f341b7cef44b Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 08:20:02 +0100 Subject: [PATCH 07/12] simplifications within HARMONIZE_TBE3 --- lib_dec/swb_tbe_dec_fx.c | 14 --------- lib_enc/swb_tbe_enc_fx.c | 67 ---------------------------------------- 2 files changed, 81 deletions(-) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index be16b23a4..382072e35 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -5265,11 +5265,7 @@ void swb_tbe_dec_ivas_fx( move16(); test(); -#ifdef HARMONIZE_TBE3 - IF( st->element_mode > EVS_MONO && ( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) -#endif { Word32 vind_temp = Mpy_32_32( L_shl( L_add( L_deposit_l( mixFactors_fx ), 1 ), 15 ), ( ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) << 16 ) ); // check addition of 1 vind = extract_l( L_shr( vind_temp, 15 ) ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ /*mixFactors*7*/ @@ -5463,12 +5459,7 @@ void swb_tbe_dec_ivas_fx( } test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st->element_mode == EVS_MONO || ( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( NE_32( st->extl_brate, SWB_TBE_1k10 ) && NE_32( st->extl_brate, SWB_TBE_1k75 ) ) -#endif { FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { @@ -5982,12 +5973,7 @@ void swb_tbe_dec_ivas_fx( /* Gain shape smoothing after quantization */ test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st->element_mode != EVS_MONO && ( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st->extl_brate, SWB_TBE_1k10 ) || EQ_32( st->extl_brate, SWB_TBE_1k75 ) ) -#endif { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index afe00ac80..2a1a5fad9 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -2783,9 +2783,6 @@ void swb_tbe_enc_ivas_fx( shb_ener_sf_Q31 = 0; move16(); test(); -#ifdef HARMONIZE_TBE3 - test(); -#endif IF( GE_32( st_fx->extl_brate, SWB_TBE_2k8 ) ) { /* ---------- SHB LSP interpolation ---------- */ @@ -2862,11 +2859,7 @@ void swb_tbe_enc_ivas_fx( Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); } -#ifdef HARMONIZE_TBE3 - ELSE IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { FOR( j = 0; j < 4; j++ ) { @@ -2902,12 +2895,7 @@ void swb_tbe_enc_ivas_fx( move16(); test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { /* calculate the TD envelope of the SHB residual signal */ Scale_sig( hBWE_TD->mem_shb_res_fx, MAX_LEN_MA_FILTER, sub( hBWE_TD->prev_Q_shb, Q_shb ) ); /* Q(hBWE_TD->prev_Q_shb) -> Q(Q_shb) */ @@ -3258,12 +3246,7 @@ void swb_tbe_enc_ivas_fx( } test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode == EVS_MONO || ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { @@ -3423,12 +3406,7 @@ void swb_tbe_enc_ivas_fx( #endif test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { /* Gain shape attenuation in case of big error in envelope modelling */ FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) @@ -3445,12 +3423,7 @@ void swb_tbe_enc_ivas_fx( } test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode == EVS_MONO || ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { /* Gain shape BWS/high band low energy fix */ IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ @@ -3466,12 +3439,7 @@ void swb_tbe_enc_ivas_fx( /* high-band gain control in case of BWS */ test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { IF( st_fx->bwidth_sw_cnt > 0 ) { @@ -3615,12 +3583,7 @@ void swb_tbe_enc_ivas_fx( } test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { test(); test(); @@ -3674,12 +3637,7 @@ void swb_tbe_enc_ivas_fx( } test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { /* Re-normalize gain shape before quantization */ tmp = 0; @@ -3729,12 +3687,7 @@ void swb_tbe_enc_ivas_fx( } /* Gain shape smoothing after quantization */ -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -3800,12 +3753,7 @@ void swb_tbe_enc_ivas_fx( } test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { test(); test(); @@ -3885,12 +3833,7 @@ void swb_tbe_enc_ivas_fx( tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { tmp1 = mult_r( 22938 /*0.7f Q15*/, tmp ); /* Q15, Q6 => Q6 */ L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ @@ -3914,12 +3857,7 @@ void swb_tbe_enc_ivas_fx( /* keep the L_tmp; dont overwrite */ test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode == EVS_MONO || ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ /* pitch_buf: Q6 */ @@ -3980,12 +3918,7 @@ void swb_tbe_enc_ivas_fx( /* high-band gain control in case of BWS */ test(); -#ifdef HARMONIZE_TBE3 - test(); - IF( st_fx->element_mode != EVS_MONO && ( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ) -#else IF( NE_32( st_fx->extl_brate, SWB_TBE_1k10 ) && NE_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { IF( st_fx->bwidth_sw_cnt > 0 ) { -- GitLab From e531e5b94c9889b675896c587a7b14e38099ce2a Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 10:09:28 +0100 Subject: [PATCH 08/12] clang-format --- apps/encoder.c | 4 ++-- apps/encoder_fmtsw.c | 4 ++-- lib_com/basop_settings.h | 4 ++-- lib_com/lsf_tools_fx.c | 12 ++++++------ lib_com/pvq_com_fx.c | 2 +- lib_com/rom_com_fx.c | 6 +++--- lib_com/swb_tbe_com_fx.c | 2 +- lib_com/tcq_position_arith_fx.c | 2 +- lib_dec/FEC_clas_estim_fx.c | 2 +- lib_dec/amr_wb_dec_fx.c | 4 ++-- lib_dec/dec_tcx_fx.c | 2 +- lib_dec/ivas_dirac_dec_fx.c | 4 ++-- lib_dec/swb_tbe_dec_fx.c | 2 +- lib_enc/ACcontextMapping_enc_fx.c | 4 ++-- lib_enc/enc_prm_fx.c | 2 +- lib_enc/ivas_masa_enc_fx.c | 2 +- lib_enc/lsf_msvq_ma_enc_fx.c | 12 ++++++------ lib_enc/pitch_ol_fx.c | 6 +++--- lib_enc/swb_bwe_enc_lr_fx.c | 2 +- lib_enc/vad_fx.c | 4 ++-- lib_isar/isar_lc3plus_dec.h | 2 +- lib_isar/isar_lc3plus_enc.h | 2 +- lib_isar/isar_lcld_encoder.c | 6 +++--- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 4 ++-- 24 files changed, 48 insertions(+), 48 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 31d9b448c..9e10a9c5c 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -55,10 +55,10 @@ rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ #include #if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) -#define S_ISREG( m ) ( ( ( m ) & S_IFMT ) == S_IFREG ) +#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) #endif #if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) -#define S_ISDIR( m ) ( ( ( m ) & S_IFMT ) == S_IFDIR ) +#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) #endif #endif diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c index 036144175..12cc57349 100644 --- a/apps/encoder_fmtsw.c +++ b/apps/encoder_fmtsw.c @@ -55,10 +55,10 @@ rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ #include #if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) -#define S_ISREG( m ) ( ( ( m ) & S_IFMT ) == S_IFREG ) +#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) #endif #if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) -#define S_ISDIR( m ) ( ( ( m ) & S_IFMT ) == S_IFDIR ) +#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) #endif #endif diff --git a/lib_com/basop_settings.h b/lib_com/basop_settings.h index 6d1d513a2..79544c078 100644 --- a/lib_com/basop_settings.h +++ b/lib_com/basop_settings.h @@ -59,13 +59,13 @@ \def Macro converts a float < 1 to Word32 fixed point with saturation and rounding */ #define FL2WORD32( val ) \ - ( Word32 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD32 ) ) ? (int32_t) ( MAXVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) - 0.5 ) <= (double) ( MINVAL_WORD32 ) ) ? (int32_t) ( MINVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) - 0.5 ) ) ) + ( Word32 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD32 ) ) ? (int32_t) ( MAXVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD32_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD32 ) ) ? (int32_t) ( MINVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) (WORD32_FIX_SCALE) -0.5 ) ) ) /*! \def Macro converts a float < 1 to Word16 fixed point with saturation and rounding */ #define FL2WORD16( val ) \ - ( Word16 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD16 ) ) ? (int32_t) ( MAXVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) - 0.5 ) <= (double) ( MINVAL_WORD16 ) ) ? (int32_t) ( MINVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) - 0.5 ) ) ) + ( Word16 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD16 ) ) ? (int32_t) ( MAXVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD16_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD16 ) ) ? (int32_t) ( MINVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) (WORD16_FIX_SCALE) -0.5 ) ) ) /*! \def Macro converts a Word32 fixed point to Word16 fixed point <1 with saturation diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index 71f30f83f..ba6dc36fe 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -584,8 +584,8 @@ Word16 lpc2lsp_fx( tfreq[rc] = rt; rc = add( rc, 2 ); } /* end else, find Q root */ - } /* end for */ - } /* end else */ + } /* end for */ + } /* end else */ FOR( i = 0; i < order; i++ ) { @@ -729,8 +729,8 @@ Word16 lpc2lsp_ivas_fx( tfreq[rc] = rt; rc = add( rc, 2 ); } /* end else, find Q root */ - } /* end for */ - } /* end else */ + } /* end for */ + } /* end else */ FOR( i = 0; i < order; i++ ) { @@ -3567,7 +3567,7 @@ Word32 poscos_fx( Lacc = L_sub( Lacc, L_shl( Ltemp, 1 ) ); /* Lacc=cos( w) in Q30 */ return L_negate( Lacc ); /* return -cos( w), Q30 */ - } /* end else */ + } /* end else */ } @@ -3683,7 +3683,7 @@ Word16 root_search_fx( move16(); return ( add( round_fx( Ltemp ), shl( low, 6 ) ) ); } /* end else ( root in interval) */ - } /* end else ( exact root at high) */ + } /* end else ( exact root at high) */ /* find the exact root */ *v_low = v_high; diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index f86e66f60..49a83bc7b 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -440,7 +440,7 @@ void NearOppSplitAdjustment_fx( QuantaPerDsDirac_fx( Nhead, Midx, hBitsN, &qmin ); qskew = sub( qavg, qmin ); /* Q0 */ qskew = s_max( 0, qskew ); /* Q0 */ - } /* end of skew calc code*/ + } /* end of skew calc code*/ QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out Q0*/ L_qnum = L_sub( L_deposit_l( sub( sub( add( qband, qzero ), qac ), qskew ) ), L_mult0( Nopp, oppRQ3 ) ); /* Q0 */ diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index ef6d2d354..eff398b33 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25785,9 +25785,9 @@ const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3, 4 /*sfm==80*/, 4 /*sfm /*% sfms=[8,16,24,32,48,64,80,96], round(sqrt(sfms)*2^11) */ const Word16 fine_gain_pred_sqrt_bw[8] = { 5793, 8192, 10033, 11585, 14189, 16384, 18318, 20066 }; /* (Q11) */ const Word16 ivas_band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { - /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ - -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ -}; // Q0 + /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ + -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ +}; // Q0 const Word16 ivas_band_len_ener_shift[9] = { 1, 2, 2, 2, 3, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; // Q0 /* 96 requires 1 bit more than 48 */ const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ /*% sfms=[8,16,24,32,40,48,64,80,96], round(sqrt(sfms)*2^11) */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 7f39768d9..d55bb7676 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -1544,7 +1544,7 @@ void GenShapedWBExcitation_ivas_fx( #ifdef HARMONIZE_TBE2 pow22 = L_add( pow22, L_shr( L_tmp, Q_pow ) ); /* Q22 */ #else - pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ + pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ #endif } } diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index 431a509b1..f74aea076 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1237,7 +1237,7 @@ Word32 GetISCScale_fx( *nzpout = nzposcurr; move16(); } /*magnitude coding */ - } /*TCQ */ + } /*TCQ */ IF( actualt_fx == 0 ) { diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index 946f770e8..f968ccb90 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -731,7 +731,7 @@ void FEC_clas_estim_fx( } } } /*if (Opt_AMR_WB)*/ - } /*if (codec_mode==MODE1)*/ + } /*if (codec_mode==MODE1)*/ } /* Do the classification only diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 00347cac7..0eb145603 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -21,8 +21,8 @@ ivas_error amr_wb_dec_fx( Word16 output_sp[], /* o : synthesis output */ Word32 *mem_hp20_in_fx /* i/o: hp20 filter memory Qx*/ #else - Word16 output_sp[], /* o : synthesis output Q_syn2*/ - Decoder_State *st_fx /* o : Decoder static variables structure */ + Word16 output_sp[], /* o : synthesis output Q_syn2*/ + Decoder_State *st_fx /* o : Decoder static variables structure */ #endif ) { diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 0f5f1ec57..339826d53 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2267,7 +2267,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp8, fullbandScale ); } /* TRANSITION_OVERLAP */ - } /* TCX-20 and TCX-only */ + } /* TCX-20 and TCX-only */ /* Window and overlap-add past frame if past frame is TCX */ test(); diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index a92537347..7d25477b4 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -1895,8 +1895,8 @@ void ivas_qmetadata_to_dirac_fx( } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 382072e35..71032ae83 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3767,7 +3767,7 @@ static void dequantizeSHBparams_fx( { *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); move32(); - } /*Q18*/ + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index eca622dd0..f9e2d919c 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1419,7 +1419,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( } } - } /*end of the 2-tuples loop*/ + } /*end of the 2-tuples loop*/ total_output_bits = round_fx( W_shl_sat_l( bit_estimate_fx, -Q7 ) ); /* Q23 -> Q16 -> Q0 */ IF( *stop ) { @@ -1794,7 +1794,7 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t ); /* Q0 */ move16(); - } /*end of the 2-tuples loop*/ + } /*end of the 2-tuples loop*/ total_output_bits = round_fx( W_shl_sat_l( hContextMem->bit_estimate_fx, -Q7 ) ); /* Q0 */ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f ); diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index c138f0e21..f72a955a8 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -686,7 +686,7 @@ void enc_prm_fx( n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; push_next_indice( hBstr, prm[j++], n ); } /*end of for(sfr)*/ - } /*end of mode[0]==0*/ + } /*end of mode[0]==0*/ /*--------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 8a957b267..5779ea017 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -3792,7 +3792,7 @@ static void masa_metadata_direction_alignment_fx( move16(); } } /* sf */ - } /* band */ + } /* band */ return; } diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 3557f0a37..3f6b39dcb 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -835,8 +835,8 @@ void msvq_enc_fx( p_max = ( *func_ptr )( dist[1] ); } /*IF (L_sub(tmp,dist[1][p_max]) < 0) */ - } /* FOR (c=0; c= 0) */ - } /* FOR (j = subsect0; ... */ + } /* FOR (j = subsect0; ... */ } ELSE /* 3rd half-frame (look-ahead) */ { @@ -1118,7 +1118,7 @@ void pitch_ol_fx( offset1 = add( offset1, sec_length1[j] ); } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + } /* FOR i < NHFR */ pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, EVS_MONO, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); @@ -1832,7 +1832,7 @@ void pitch_ol_ivas_fx( offset1 = add( offset1, sec_length1[j] ); } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + } /* FOR i < NHFR */ pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, IVAS_SCE, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); /* any element mode other than EVS_MONO is OK here */ return; diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index c691af8ba..4a549ffef 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -875,7 +875,7 @@ static void EncodeSWBSubbands_fx( Word16 ss_min_fx; /* Qss */ Word32 L_th_g[NB_SWB_SUBBANDS]; Word16 QbeL; - GainItem_fx pk_sf_fx[( NB_SWB_SUBBANDS ) * 8]; + GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) *8]; Word16 pul_res_fx[NB_SWB_SUBBANDS]; GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS * N_NBIGGEST_PULSEARCH]; diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index eec0b656d..b6ffbc738 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -1534,7 +1534,7 @@ Word16 wb_vad_fx( } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ + } /* end of NB */ /* *flag_noisy_speech_snr is a Word8 parameter */ @@ -2809,7 +2809,7 @@ Word16 wb_vad_ivas_fx( } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ + } /* end of NB */ /* *flag_noisy_speech_snr is a Word8 parameter */ diff --git a/lib_isar/isar_lc3plus_dec.h b/lib_isar/isar_lc3plus_dec.h index 6f469f48b..461e15dc8 100644 --- a/lib_isar/isar_lc3plus_dec.h +++ b/lib_isar/isar_lc3plus_dec.h @@ -76,7 +76,7 @@ typedef struct ISAR_LC3PLUS_DEC_HANDLE int16_t *pcm_conversion_buffer; uint8_t *scratch; LC3PLUS_CONFIG config; -} *ISAR_LC3PLUS_DEC_HANDLE; +} * ISAR_LC3PLUS_DEC_HANDLE; ivas_error ISAR_LC3PLUS_DEC_Open( const LC3PLUS_CONFIG config, /* i : decoder configuration */ diff --git a/lib_isar/isar_lc3plus_enc.h b/lib_isar/isar_lc3plus_enc.h index 5ce87a91f..793da7b9f 100644 --- a/lib_isar/isar_lc3plus_enc.h +++ b/lib_isar/isar_lc3plus_enc.h @@ -51,7 +51,7 @@ typedef struct ISAR_LC3PLUS_ENC_HANDLE int32_t num_ftds; LC3PLUS_RTP_FDL fdl_request; uint8_t *scratch; -} *ISAR_LC3PLUS_ENC_HANDLE; +} * ISAR_LC3PLUS_ENC_HANDLE; ivas_error ISAR_LC3PLUS_ENC_Open( const LC3PLUS_CONFIG config, /* i : encoder configuration */ diff --git a/lib_isar/isar_lcld_encoder.c b/lib_isar/isar_lcld_encoder.c index 5b34a4ff3..9b33cc653 100644 --- a/lib_isar/isar_lcld_encoder.c +++ b/lib_isar/isar_lcld_encoder.c @@ -1431,7 +1431,7 @@ static void QuantizeSpectrumDPCM_Opt( fImag_fx ); iBlockOffset++; } /* group length */ - } /* groups */ + } /* groups */ pfPredStateReal_fx[iFBOffset] = fPrevReal_fx; move32(); pfPredStateImag_fx[iFBOffset] = fPrevImag_fx; @@ -1466,8 +1466,8 @@ static void QuantizeSpectrumDPCM_Opt( iBlockOffset++; } /* group length */ - } /* groups */ - } /* predEnable */ + } /* groups */ + } /* predEnable */ iFBOffset++; } /* bandwidth */ } diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 2a81e28a8..7426c3688 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -663,7 +663,7 @@ static void getPeriodicBSplineSampVec_fx( #ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *azimBsShape_fx, /* i : Basis shape Q15 */ #else - const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ + const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ #endif const Word16 subSampFactor /* i : Subsampling factor */ ) @@ -755,7 +755,7 @@ static void getStandardBSplineSampVec_fx( const Word16 *KSeq_fx, /* i : knot sequence including multiplicities Q KSeq_Q_fx */ const Word16 KSeq_Q_fx, /* i : Q-value of knot sequence */ #else - const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ + const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ #endif const Word16 SegSamples, /* i : samples per segment */ const Word16 *BsLen, /* i : lengths of basis shapes */ -- GitLab From 75dc415d2fd6bbe43b010966647b79ff225e5077 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 10:15:03 +0100 Subject: [PATCH 09/12] Revert "clang-format" --- apps/encoder.c | 4 ++-- apps/encoder_fmtsw.c | 4 ++-- lib_com/basop_settings.h | 4 ++-- lib_com/lsf_tools_fx.c | 12 ++++++------ lib_com/pvq_com_fx.c | 2 +- lib_com/rom_com_fx.c | 6 +++--- lib_com/swb_tbe_com_fx.c | 2 +- lib_com/tcq_position_arith_fx.c | 2 +- lib_dec/FEC_clas_estim_fx.c | 2 +- lib_dec/amr_wb_dec_fx.c | 4 ++-- lib_dec/dec_tcx_fx.c | 2 +- lib_dec/ivas_dirac_dec_fx.c | 4 ++-- lib_dec/swb_tbe_dec_fx.c | 2 +- lib_enc/ACcontextMapping_enc_fx.c | 4 ++-- lib_enc/enc_prm_fx.c | 2 +- lib_enc/ivas_masa_enc_fx.c | 2 +- lib_enc/lsf_msvq_ma_enc_fx.c | 12 ++++++------ lib_enc/pitch_ol_fx.c | 6 +++--- lib_enc/swb_bwe_enc_lr_fx.c | 2 +- lib_enc/vad_fx.c | 4 ++-- lib_isar/isar_lc3plus_dec.h | 2 +- lib_isar/isar_lc3plus_enc.h | 2 +- lib_isar/isar_lcld_encoder.c | 6 +++--- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 4 ++-- 24 files changed, 48 insertions(+), 48 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 9e10a9c5c..31d9b448c 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -55,10 +55,10 @@ rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ #include #if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) -#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) +#define S_ISREG( m ) ( ( ( m ) & S_IFMT ) == S_IFREG ) #endif #if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) -#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) +#define S_ISDIR( m ) ( ( ( m ) & S_IFMT ) == S_IFDIR ) #endif #endif diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c index 12cc57349..036144175 100644 --- a/apps/encoder_fmtsw.c +++ b/apps/encoder_fmtsw.c @@ -55,10 +55,10 @@ rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ #include #if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) -#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) +#define S_ISREG( m ) ( ( ( m ) & S_IFMT ) == S_IFREG ) #endif #if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) -#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) +#define S_ISDIR( m ) ( ( ( m ) & S_IFMT ) == S_IFDIR ) #endif #endif diff --git a/lib_com/basop_settings.h b/lib_com/basop_settings.h index 79544c078..6d1d513a2 100644 --- a/lib_com/basop_settings.h +++ b/lib_com/basop_settings.h @@ -59,13 +59,13 @@ \def Macro converts a float < 1 to Word32 fixed point with saturation and rounding */ #define FL2WORD32( val ) \ - ( Word32 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD32 ) ) ? (int32_t) ( MAXVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD32_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD32 ) ) ? (int32_t) ( MINVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) (WORD32_FIX_SCALE) -0.5 ) ) ) + ( Word32 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD32 ) ) ? (int32_t) ( MAXVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) - 0.5 ) <= (double) ( MINVAL_WORD32 ) ) ? (int32_t) ( MINVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) - 0.5 ) ) ) /*! \def Macro converts a float < 1 to Word16 fixed point with saturation and rounding */ #define FL2WORD16( val ) \ - ( Word16 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD16 ) ) ? (int32_t) ( MAXVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD16_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD16 ) ) ? (int32_t) ( MINVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) (WORD16_FIX_SCALE) -0.5 ) ) ) + ( Word16 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD16 ) ) ? (int32_t) ( MAXVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) - 0.5 ) <= (double) ( MINVAL_WORD16 ) ) ? (int32_t) ( MINVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) - 0.5 ) ) ) /*! \def Macro converts a Word32 fixed point to Word16 fixed point <1 with saturation diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index ba6dc36fe..71f30f83f 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -584,8 +584,8 @@ Word16 lpc2lsp_fx( tfreq[rc] = rt; rc = add( rc, 2 ); } /* end else, find Q root */ - } /* end for */ - } /* end else */ + } /* end for */ + } /* end else */ FOR( i = 0; i < order; i++ ) { @@ -729,8 +729,8 @@ Word16 lpc2lsp_ivas_fx( tfreq[rc] = rt; rc = add( rc, 2 ); } /* end else, find Q root */ - } /* end for */ - } /* end else */ + } /* end for */ + } /* end else */ FOR( i = 0; i < order; i++ ) { @@ -3567,7 +3567,7 @@ Word32 poscos_fx( Lacc = L_sub( Lacc, L_shl( Ltemp, 1 ) ); /* Lacc=cos( w) in Q30 */ return L_negate( Lacc ); /* return -cos( w), Q30 */ - } /* end else */ + } /* end else */ } @@ -3683,7 +3683,7 @@ Word16 root_search_fx( move16(); return ( add( round_fx( Ltemp ), shl( low, 6 ) ) ); } /* end else ( root in interval) */ - } /* end else ( exact root at high) */ + } /* end else ( exact root at high) */ /* find the exact root */ *v_low = v_high; diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 49a83bc7b..f86e66f60 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -440,7 +440,7 @@ void NearOppSplitAdjustment_fx( QuantaPerDsDirac_fx( Nhead, Midx, hBitsN, &qmin ); qskew = sub( qavg, qmin ); /* Q0 */ qskew = s_max( 0, qskew ); /* Q0 */ - } /* end of skew calc code*/ + } /* end of skew calc code*/ QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out Q0*/ L_qnum = L_sub( L_deposit_l( sub( sub( add( qband, qzero ), qac ), qskew ) ), L_mult0( Nopp, oppRQ3 ) ); /* Q0 */ diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index eff398b33..ef6d2d354 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25785,9 +25785,9 @@ const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3, 4 /*sfm==80*/, 4 /*sfm /*% sfms=[8,16,24,32,48,64,80,96], round(sqrt(sfms)*2^11) */ const Word16 fine_gain_pred_sqrt_bw[8] = { 5793, 8192, 10033, 11585, 14189, 16384, 18318, 20066 }; /* (Q11) */ const Word16 ivas_band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { - /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ - -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ -}; // Q0 + /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ + -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ +}; // Q0 const Word16 ivas_band_len_ener_shift[9] = { 1, 2, 2, 2, 3, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; // Q0 /* 96 requires 1 bit more than 48 */ const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ /*% sfms=[8,16,24,32,40,48,64,80,96], round(sqrt(sfms)*2^11) */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index d55bb7676..7f39768d9 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -1544,7 +1544,7 @@ void GenShapedWBExcitation_ivas_fx( #ifdef HARMONIZE_TBE2 pow22 = L_add( pow22, L_shr( L_tmp, Q_pow ) ); /* Q22 */ #else - pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ + pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ #endif } } diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index f74aea076..431a509b1 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1237,7 +1237,7 @@ Word32 GetISCScale_fx( *nzpout = nzposcurr; move16(); } /*magnitude coding */ - } /*TCQ */ + } /*TCQ */ IF( actualt_fx == 0 ) { diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index f968ccb90..946f770e8 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -731,7 +731,7 @@ void FEC_clas_estim_fx( } } } /*if (Opt_AMR_WB)*/ - } /*if (codec_mode==MODE1)*/ + } /*if (codec_mode==MODE1)*/ } /* Do the classification only diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 0eb145603..00347cac7 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -21,8 +21,8 @@ ivas_error amr_wb_dec_fx( Word16 output_sp[], /* o : synthesis output */ Word32 *mem_hp20_in_fx /* i/o: hp20 filter memory Qx*/ #else - Word16 output_sp[], /* o : synthesis output Q_syn2*/ - Decoder_State *st_fx /* o : Decoder static variables structure */ + Word16 output_sp[], /* o : synthesis output Q_syn2*/ + Decoder_State *st_fx /* o : Decoder static variables structure */ #endif ) { diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 339826d53..0f5f1ec57 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2267,7 +2267,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp8, fullbandScale ); } /* TRANSITION_OVERLAP */ - } /* TCX-20 and TCX-only */ + } /* TCX-20 and TCX-only */ /* Window and overlap-add past frame if past frame is TCX */ test(); diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index 7d25477b4..a92537347 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -1895,8 +1895,8 @@ void ivas_qmetadata_to_dirac_fx( } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 71032ae83..382072e35 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3767,7 +3767,7 @@ static void dequantizeSHBparams_fx( { *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); move32(); - } /*Q18*/ + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index f9e2d919c..eca622dd0 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1419,7 +1419,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( } } - } /*end of the 2-tuples loop*/ + } /*end of the 2-tuples loop*/ total_output_bits = round_fx( W_shl_sat_l( bit_estimate_fx, -Q7 ) ); /* Q23 -> Q16 -> Q0 */ IF( *stop ) { @@ -1794,7 +1794,7 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t ); /* Q0 */ move16(); - } /*end of the 2-tuples loop*/ + } /*end of the 2-tuples loop*/ total_output_bits = round_fx( W_shl_sat_l( hContextMem->bit_estimate_fx, -Q7 ) ); /* Q0 */ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f ); diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index f72a955a8..c138f0e21 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -686,7 +686,7 @@ void enc_prm_fx( n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; push_next_indice( hBstr, prm[j++], n ); } /*end of for(sfr)*/ - } /*end of mode[0]==0*/ + } /*end of mode[0]==0*/ /*--------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 5779ea017..8a957b267 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -3792,7 +3792,7 @@ static void masa_metadata_direction_alignment_fx( move16(); } } /* sf */ - } /* band */ + } /* band */ return; } diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 3f6b39dcb..3557f0a37 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -835,8 +835,8 @@ void msvq_enc_fx( p_max = ( *func_ptr )( dist[1] ); } /*IF (L_sub(tmp,dist[1][p_max]) < 0) */ - } /* FOR (c=0; c= 0) */ - } /* FOR (j = subsect0; ... */ + } /* FOR (j = subsect0; ... */ } ELSE /* 3rd half-frame (look-ahead) */ { @@ -1118,7 +1118,7 @@ void pitch_ol_fx( offset1 = add( offset1, sec_length1[j] ); } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + } /* FOR i < NHFR */ pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, EVS_MONO, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); @@ -1832,7 +1832,7 @@ void pitch_ol_ivas_fx( offset1 = add( offset1, sec_length1[j] ); } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + } /* FOR i < NHFR */ pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, IVAS_SCE, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); /* any element mode other than EVS_MONO is OK here */ return; diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 4a549ffef..c691af8ba 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -875,7 +875,7 @@ static void EncodeSWBSubbands_fx( Word16 ss_min_fx; /* Qss */ Word32 L_th_g[NB_SWB_SUBBANDS]; Word16 QbeL; - GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) *8]; + GainItem_fx pk_sf_fx[( NB_SWB_SUBBANDS ) * 8]; Word16 pul_res_fx[NB_SWB_SUBBANDS]; GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS * N_NBIGGEST_PULSEARCH]; diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index b6ffbc738..eec0b656d 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -1534,7 +1534,7 @@ Word16 wb_vad_fx( } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ + } /* end of NB */ /* *flag_noisy_speech_snr is a Word8 parameter */ @@ -2809,7 +2809,7 @@ Word16 wb_vad_ivas_fx( } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ + } /* end of NB */ /* *flag_noisy_speech_snr is a Word8 parameter */ diff --git a/lib_isar/isar_lc3plus_dec.h b/lib_isar/isar_lc3plus_dec.h index 461e15dc8..6f469f48b 100644 --- a/lib_isar/isar_lc3plus_dec.h +++ b/lib_isar/isar_lc3plus_dec.h @@ -76,7 +76,7 @@ typedef struct ISAR_LC3PLUS_DEC_HANDLE int16_t *pcm_conversion_buffer; uint8_t *scratch; LC3PLUS_CONFIG config; -} * ISAR_LC3PLUS_DEC_HANDLE; +} *ISAR_LC3PLUS_DEC_HANDLE; ivas_error ISAR_LC3PLUS_DEC_Open( const LC3PLUS_CONFIG config, /* i : decoder configuration */ diff --git a/lib_isar/isar_lc3plus_enc.h b/lib_isar/isar_lc3plus_enc.h index 793da7b9f..5ce87a91f 100644 --- a/lib_isar/isar_lc3plus_enc.h +++ b/lib_isar/isar_lc3plus_enc.h @@ -51,7 +51,7 @@ typedef struct ISAR_LC3PLUS_ENC_HANDLE int32_t num_ftds; LC3PLUS_RTP_FDL fdl_request; uint8_t *scratch; -} * ISAR_LC3PLUS_ENC_HANDLE; +} *ISAR_LC3PLUS_ENC_HANDLE; ivas_error ISAR_LC3PLUS_ENC_Open( const LC3PLUS_CONFIG config, /* i : encoder configuration */ diff --git a/lib_isar/isar_lcld_encoder.c b/lib_isar/isar_lcld_encoder.c index 9b33cc653..5b34a4ff3 100644 --- a/lib_isar/isar_lcld_encoder.c +++ b/lib_isar/isar_lcld_encoder.c @@ -1431,7 +1431,7 @@ static void QuantizeSpectrumDPCM_Opt( fImag_fx ); iBlockOffset++; } /* group length */ - } /* groups */ + } /* groups */ pfPredStateReal_fx[iFBOffset] = fPrevReal_fx; move32(); pfPredStateImag_fx[iFBOffset] = fPrevImag_fx; @@ -1466,8 +1466,8 @@ static void QuantizeSpectrumDPCM_Opt( iBlockOffset++; } /* group length */ - } /* groups */ - } /* predEnable */ + } /* groups */ + } /* predEnable */ iFBOffset++; } /* bandwidth */ } diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 7426c3688..2a81e28a8 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -663,7 +663,7 @@ static void getPeriodicBSplineSampVec_fx( #ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *azimBsShape_fx, /* i : Basis shape Q15 */ #else - const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ + const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ #endif const Word16 subSampFactor /* i : Subsampling factor */ ) @@ -755,7 +755,7 @@ static void getStandardBSplineSampVec_fx( const Word16 *KSeq_fx, /* i : knot sequence including multiplicities Q KSeq_Q_fx */ const Word16 KSeq_Q_fx, /* i : Q-value of knot sequence */ #else - const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ + const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ #endif const Word16 SegSamples, /* i : samples per segment */ const Word16 *BsLen, /* i : lengths of basis shapes */ -- GitLab From 81acf01238e5c8d1c0c81761c5105a0485203a8e Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 12:06:07 +0100 Subject: [PATCH 10/12] comments --- lib_basop/basop32.c | 2 +- lib_basop/typedefs.h | 2 +- lib_dec/ivas_core_dec_fx.c | 9 ++++++++- lib_dec/swb_tbe_dec_fx.c | 21 ++++++++++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib_basop/basop32.c b/lib_basop/basop32.c index 27b499276..4f601911b 100644 --- a/lib_basop/basop32.c +++ b/lib_basop/basop32.c @@ -345,7 +345,7 @@ Flag Carry = 0; do \ { \ (void) 0; \ - } while ( 0 ) /* no-op */ + } while ( 0 ) /* no-op */ #define B_HELPER_GET_GLOBAL( global_flag ) 0 /* Default to 0 */ #endif diff --git a/lib_basop/typedefs.h b/lib_basop/typedefs.h index ed3860391..001f3f164 100644 --- a/lib_basop/typedefs.h +++ b/lib_basop/typedefs.h @@ -183,7 +183,7 @@ typedef struct */ typedef int Bool; #define false 0 -#define true 1 +#define true 1 /* ********* Check current platform diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 8198d4373..791c8172c 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1009,16 +1009,20 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_no_sat( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, hBWE_TD->prev_Q_bwe_syn2 ) ); // Q11 Copy_Scale_sig_32_16( hBWE_TD->old_tbe_synth_fx_32, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx +#ifndef HARMONIZE_TBE3 IF( GT_16( Q_white_exc, 31 ) ) { Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); // Q31 Q_white_exc = 31; move16(); } - +#endif /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { +#ifdef HARMONIZE_TBE3 + // TODO: check why 'Q_synth' is not used instead of 'Q_white_exc' as the second but last paremeter in the following function call +#endif 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 ); } } @@ -1113,6 +1117,9 @@ ivas_error ivas_core_dec_fx( q = Q11; move16(); +#ifdef HARMONIZE_TBE3 + // TODO: check whether 'Q_synth' is not used instead of 'Q_white_exc' as the last paremeter in the following function call +#endif stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q, Q_white_exc ); test(); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 382072e35..e36cedced 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3767,7 +3767,7 @@ static void dequantizeSHBparams_fx( { *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); move32(); - } /*Q18*/ + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); @@ -4689,6 +4689,7 @@ void swb_tbe_dec_ivas_fx( calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) ); } + test(); if ( st->bfi && st->clas_dec != UNVOICED_CLAS ) { @@ -5069,6 +5070,14 @@ void swb_tbe_dec_ivas_fx( } } +#if 0 // TBV: this looks like a bug in EVS: the code is present in float but not in BASOP + test(); + IF( st->use_partial_copy && st->nelp_mode_dec ) + { + set16_fx( vf_modified_fx, 0, NB_SUBFR16k ); + } + +#endif /* SHB LSF from current frame; and convert to LSP for interpolation */ E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); @@ -6473,6 +6482,16 @@ void swb_tbe_dec_ivas_fx( } *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); move16(); + +#ifdef HARMONIZE_TBE3 + test(); + IF( st->element_mode != EVS_MONO && GT_16( *Q_white_exc, Q31 ) ) + { + Scale_sig( White_exc16k_fx, L_FRAME16k, sub( Q31, *Q_white_exc ) ); // Q31 + Q_white_exc = Q31; + move16(); + } +#endif } #ifdef HARMONIZE_TBE3 -- GitLab From ebc87df352ea1e317a921e08e18ec0e786656c15 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 13:34:33 +0100 Subject: [PATCH 11/12] clang-format --- lib_dec/swb_tbe_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index e36cedced..8928dc71d 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3767,7 +3767,7 @@ static void dequantizeSHBparams_fx( { *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); move32(); - } /*Q18*/ + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); -- GitLab From c973ef047944228456560e0d883272e75d489ac6 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 2 Mar 2026 13:45:59 +0100 Subject: [PATCH 12/12] fix build --- lib_dec/swb_tbe_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 8928dc71d..cb0a565d0 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -6488,7 +6488,7 @@ void swb_tbe_dec_ivas_fx( IF( st->element_mode != EVS_MONO && GT_16( *Q_white_exc, Q31 ) ) { Scale_sig( White_exc16k_fx, L_FRAME16k, sub( Q31, *Q_white_exc ) ); // Q31 - Q_white_exc = Q31; + *Q_white_exc = Q31; move16(); } #endif -- GitLab