From de111a2cb5d77610c70b7838bec5091e1da0caab Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 29 Jan 2026 11:48:04 -0500 Subject: [PATCH 1/6] proposed fix to 2380, issue with Q_exc being possibly too high when coming from CNG --- lib_com/gs_gains_fx.c | 29 +++++++++++++++++++++++++++-- lib_com/gs_noisefill_fx.c | 36 +++++++++++++++++++++++++++++++++--- lib_com/options.h | 1 + lib_com/prot_fx.h | 14 +++++++++++--- 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 769af2692..b25dace82 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -70,12 +70,19 @@ static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const /* _ None */ /*========================================================================*/ +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX +Word16 Comp_and_apply_gain_fx( +#else void Comp_and_apply_gain_fx( +#endif Word16 exc_diffQ[], /* i/o: Quantized excitation */ Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ Word16 Mbands_gn, /* i : number of bands */ const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + const Word16 max_lt_ener, /* i : max_lt_ener of lt_ener_per_band_fx */ +#endif Word16 Qexc_diff, Word16 Q_exc ) { @@ -83,6 +90,9 @@ void Comp_and_apply_gain_fx( Word16 StartBin, NB_Qbins; Word16 y_gain; Word16 L16, frac, exp1, tmp_exp; +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + Word16 Q_adapt; +#endif Word32 L32; /* Recreate excitation for local synthesis and decoder */ @@ -92,6 +102,16 @@ void Comp_and_apply_gain_fx( move16(); tmp_exp = add( 14, sub( Q_exc, Qexc_diff ) ); /* In case of reuse, it can be computed outside the loop*/ +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + Q_adapt = 0; + move16(); + test(); + test(); + IF( GT_16( Q_exc, 3 ) && EQ_16( ReUseGain, 0 ) && GT_16( max_lt_ener, 8192 /* 13 bits */ ) ) /* When lt_energy is high, Q_exc shouldn't be high too, addresses cases when switching from CNG */ + { + Q_adapt = sub( 3 - 1, Q_exc ); /* add extra 1 bit headroom */ + } +#endif FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { StartBin = add( StartBin, NB_Qbins ); @@ -126,7 +146,9 @@ void Comp_and_apply_gain_fx( Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) ); - +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + tmp_exp = add( tmp_exp, Q_adapt ); +#endif FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ @@ -135,8 +157,11 @@ void Comp_and_apply_gain_fx( } } } - +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + return add( Q_exc, Q_adapt ); +#else return; +#endif } #ifndef FIX_2338_HARM_GSC_GAIN_COMP diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 383e2812d..4d902da52 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1081,6 +1081,9 @@ void highband_exc_dct_in_ivas_fx( Word16 frac, exp, tmp1; Word16 tmp2; Word16 *end, Q_hb_exc; +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + Word16 max_lt_ener, old_Q_exc; +#endif FOR( j = 10; j < MBANDS_GN; j++ ) { @@ -1364,10 +1367,9 @@ void highband_exc_dct_in_ivas_fx( move16(); } } -#ifndef FIX_2338_HARM_GSC_GAIN_COMP +#if !defined FIX_2338_HARM_GSC_GAIN_COMP && !defined FIX_2380_HARM_GSC_GAIN_COMP_FX IF( EQ_16( element_mode, EVS_MONO ) ) { -#endif Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); IF( exc_wo_nf != NULL ) @@ -1375,7 +1377,6 @@ void highband_exc_dct_in_ivas_fx( Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc ); Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } -#ifndef FIX_2338_HARM_GSC_GAIN_COMP } ELSE { @@ -1406,7 +1407,36 @@ void highband_exc_dct_in_ivas_fx( Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) ); } } +#elif defined FIX_2380_HARM_GSC_GAIN_COMP_FX + max_lt_ener = 0; + move16(); + IF( NE_16( element_mode, EVS_MONO ) ) /* to keep EVS BE */ + { + FOR( i = 0; i < MBANDS_GN; i++ ) + { + max_lt_ener = s_max( max_lt_ener, lt_ener_per_band_fx[i] ); + } + } + old_Q_exc = *Q_exc; + move16(); + *Q_exc = Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, max_lt_ener, Qexc_diffQ, *Q_exc ); + Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, old_Q_exc ) ); + + IF( exc_wo_nf != NULL ) + { + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, max_lt_ener, Qexc_diffQ, *Q_exc ); + Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); + } +#else /* #if defined FIX_2338_HARM_GSC_GAIN_COMP */ + Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); + + IF( exc_wo_nf != NULL ) + { + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc ); + Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); + } #endif + /*--------------------------------------------------------------------------------------* * add the correction layer to the LF bins, * and add the quantized pulses or the noise for the higher part of the spectrum diff --git a/lib_com/options.h b/lib_com/options.h index 0e313e5e9..e0548ca60 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -111,6 +111,7 @@ #define FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT /* Dolby: Issue 2250: random vector generation in GenShapedSHBExcitation() */ #define FIX_2338_HARM_GSC_GAIN_COMP /* VA: basop issue 2338: harmonization of band gain computation for both EVS and IVAS */ +#define FIX_2380_HARM_GSC_GAIN_COMP_FX /* VA: basop issue 2380 & 2381: Fix issue when switching from CNG low energy to active content with high energy */ #define FIX_BASOP_2317_UNINIT_VALUE_IN_STEREO_CNG /* Eri: Basop issue 2317: Uninitialized value read in case of DTX and BW switching */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 3b93fda3b..f71079f6c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1703,14 +1703,22 @@ void Ener_per_band_comp_ivas_fx( const Word16 L_frame /* i : frame length */ ); +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX +Word16 Comp_and_apply_gain_fx( +#else void Comp_and_apply_gain_fx( +#endif Word16 exc_diffQ[], /* i/o: Quantized excitation */ Word16 Ener_per_bd_iQ[], /* i : Target ener per band Q13 */ - Word16 Ener_per_bd_yQ[], /* i/o : Ener per band for norm vector i->Q13/o->Q13 */ - Word16 Mbands_gn, /* i : number of bands */ - const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ + Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector i->Q13/o->Q13 */ + Word16 Mbands_gn, /* i : number of bands */ + const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ +#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX + const Word16 max_lt_ener, /* i : max_lt_ener of lt_ener_per_band_fx */ +#endif Word16 Qexc_diff, Word16 Q_exc ); + #ifndef FIX_2338_HARM_GSC_GAIN_COMP void Comp_and_apply_gain_ivas_fx( Word16 exc_diffQ[], /* i/o: Quantized excitation */ -- GitLab From 3e51b45ce930709b2a4cfa975be9de121479691e Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Thu, 29 Jan 2026 12:01:02 -0500 Subject: [PATCH 2/6] fix encoder --- lib_com/gs_noisefill_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 4d902da52..ec45be809 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1410,7 +1410,7 @@ void highband_exc_dct_in_ivas_fx( #elif defined FIX_2380_HARM_GSC_GAIN_COMP_FX max_lt_ener = 0; move16(); - IF( NE_16( element_mode, EVS_MONO ) ) /* to keep EVS BE */ + IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep EVS BE */ { FOR( i = 0; i < MBANDS_GN; i++ ) { -- GitLab From c01b2c44575699f750dd94f90a202923c5ae2d7c Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 30 Jan 2026 11:05:37 -0500 Subject: [PATCH 3/6] Use target energy instead of lt_ener, adapt variable name accordingly --- lib_com/gs_gains_fx.c | 4 ++-- lib_com/gs_noisefill_fx.c | 13 +++++++------ lib_com/prot_fx.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index b25dace82..43c3e85e0 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -81,7 +81,7 @@ void Comp_and_apply_gain_fx( Word16 Mbands_gn, /* i : number of bands */ const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - const Word16 max_lt_ener, /* i : max_lt_ener of lt_ener_per_band_fx */ + const Word16 max_target_ener, /* i : max_target_ener of Ener_per_bd_iQ */ #endif Word16 Qexc_diff, Word16 Q_exc ) @@ -107,7 +107,7 @@ void Comp_and_apply_gain_fx( move16(); test(); test(); - IF( GT_16( Q_exc, 3 ) && EQ_16( ReUseGain, 0 ) && GT_16( max_lt_ener, 8192 /* 13 bits */ ) ) /* When lt_energy is high, Q_exc shouldn't be high too, addresses cases when switching from CNG */ + IF( GT_16( Q_exc, 3 ) && EQ_16( ReUseGain, 0 ) && GT_16( max_target_ener, 12 ) ) /* When target energy is high, Q_exc shouldn't be high too, addresses cases when switching from CNG or from almos*/ { Q_adapt = sub( 3 - 1, Q_exc ); /* add extra 1 bit headroom */ } diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index ec45be809..296df4cbc 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1082,7 +1082,7 @@ void highband_exc_dct_in_ivas_fx( Word16 tmp2; Word16 *end, Q_hb_exc; #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - Word16 max_lt_ener, old_Q_exc; + Word16 max_target_ener, old_Q_exc; #endif FOR( j = 10; j < MBANDS_GN; j++ ) @@ -1408,23 +1408,24 @@ void highband_exc_dct_in_ivas_fx( } } #elif defined FIX_2380_HARM_GSC_GAIN_COMP_FX - max_lt_ener = 0; + max_target_ener = 0; move16(); IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep EVS BE */ { - FOR( i = 0; i < MBANDS_GN; i++ ) + FOR( i = 0; i < MBANDS_GN/2; i++ ) { - max_lt_ener = s_max( max_lt_ener, lt_ener_per_band_fx[i] ); + max_target_ener = s_max( max_target_ener, Ener_per_bd_iQ[i] ); } + max_target_ener = sub( 15, norm_s( max_target_ener ) ); } old_Q_exc = *Q_exc; move16(); - *Q_exc = Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, max_lt_ener, Qexc_diffQ, *Q_exc ); + *Q_exc = Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, max_target_ener, Qexc_diffQ, *Q_exc ); Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, old_Q_exc ) ); IF( exc_wo_nf != NULL ) { - Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, max_lt_ener, Qexc_diffQ, *Q_exc ); + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, max_target_ener, Qexc_diffQ, *Q_exc ); Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } #else /* #if defined FIX_2338_HARM_GSC_GAIN_COMP */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index f71079f6c..0435db6a2 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1714,7 +1714,7 @@ void Comp_and_apply_gain_fx( Word16 Mbands_gn, /* i : number of bands */ const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - const Word16 max_lt_ener, /* i : max_lt_ener of lt_ener_per_band_fx */ + const Word16 max_target_ener, /* i : Ener_per_bd_iQ of lt_ener_per_band_fx */ #endif Word16 Qexc_diff, Word16 Q_exc ); -- GitLab From b82f9751cea168fc9633ce639a54a6dc0e654b2b Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 30 Jan 2026 11:35:16 -0500 Subject: [PATCH 4/6] Fix clang --- lib_com/gs_noisefill_fx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 296df4cbc..cc487f876 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1412,7 +1412,7 @@ void highband_exc_dct_in_ivas_fx( move16(); IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep EVS BE */ { - FOR( i = 0; i < MBANDS_GN/2; i++ ) + FOR( i = 0; i < MBANDS_GN / 2; i++ ) { max_target_ener = s_max( max_target_ener, Ener_per_bd_iQ[i] ); } @@ -1429,13 +1429,13 @@ void highband_exc_dct_in_ivas_fx( Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } #else /* #if defined FIX_2338_HARM_GSC_GAIN_COMP */ - Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); + Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc ); - IF( exc_wo_nf != NULL ) - { - Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc ); - Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); - } + IF( exc_wo_nf != NULL ) + { + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc ); + Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); + } #endif /*--------------------------------------------------------------------------------------* -- GitLab From 044c43e067f08dd98786a4998697488ae0963aeb Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 30 Jan 2026 14:34:29 -0500 Subject: [PATCH 5/6] Change of strategy and and reuse Ittiam approache for the first computation of gains and Q_exc adjutement (for the second run, it not necessary as both excitation vectors have the same dynamic --- lib_com/gs_gains_fx.c | 61 ++++++++++++++++++++++++++++----------- lib_com/gs_noisefill_fx.c | 17 +++++------ lib_com/prot_fx.h | 2 +- 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index 43c3e85e0..cb7cc852e 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -81,7 +81,7 @@ void Comp_and_apply_gain_fx( Word16 Mbands_gn, /* i : number of bands */ const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - const Word16 max_target_ener, /* i : max_target_ener of Ener_per_bd_iQ */ + const Word16 Flag_adj_q_exc, /* i : Flag allowing Q_exc adjustment */ #endif Word16 Qexc_diff, Word16 Q_exc ) @@ -92,6 +92,8 @@ void Comp_and_apply_gain_fx( Word16 L16, frac, exp1, tmp_exp; #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX Word16 Q_adapt; + Word16 Q_exc_diffQ[L_FRAME16k]; + Word32 exc_diffQ32[L_FRAME16k]; #endif Word32 L32; @@ -102,16 +104,7 @@ void Comp_and_apply_gain_fx( move16(); tmp_exp = add( 14, sub( Q_exc, Qexc_diff ) ); /* In case of reuse, it can be computed outside the loop*/ -#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - Q_adapt = 0; - move16(); - test(); - test(); - IF( GT_16( Q_exc, 3 ) && EQ_16( ReUseGain, 0 ) && GT_16( max_target_ener, 12 ) ) /* When target energy is high, Q_exc shouldn't be high too, addresses cases when switching from CNG or from almos*/ - { - Q_adapt = sub( 3 - 1, Q_exc ); /* add extra 1 bit headroom */ - } -#endif + FOR( i_band = 0; i_band < Mbands_gn; i_band++ ) { StartBin = add( StartBin, NB_Qbins ); @@ -147,18 +140,52 @@ void Comp_and_apply_gain_fx( move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) ); #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - tmp_exp = add( tmp_exp, Q_adapt ); + IF( Flag_adj_q_exc != 0) + { + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) + { + exc_diffQ32[i] = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ + move32(); + Q_exc_diffQ[i] = Q_exc; + if ( exc_diffQ[i] ) + { + Q_exc_diffQ[i] = sub( Q_exc_diffQ[i], tmp_exp ); + move16(); + } + } + } + ELSE #endif - FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ - exc_diffQ[i] = round_fx_sat( L_shl_sat( L32, tmp_exp ) ); /*Q_exc */ - move16(); + FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) + { + L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ + exc_diffQ[i] = round_fx_sat( L_shl_sat( L32, tmp_exp ) ); /*Q_exc */ + move16(); + } } + } } #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - return add( Q_exc, Q_adapt ); + Q_adapt = Q_exc; + move16(); + test(); + IF( EQ_16( ReUseGain, 0 ) && Flag_adj_q_exc != 0 ) + { + Word16 total_bins = add( StartBin, NB_Qbins ); + move16(); + FOR(i = 0; i < total_bins; i++) + { + Q_adapt = s_min( Q_adapt, add( Q_exc_diffQ[i], norm_l( exc_diffQ32[i] ) ) ); + move16(); + } + FOR(i = 0; i < total_bins; i++) + { + exc_diffQ[i] = round_fx( L_shl( exc_diffQ32[i], sub( Q_adapt, Q_exc_diffQ[i] ) ) ); /*Q_exc*/ + } + } + return Q_adapt; #else return; #endif diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index cc487f876..123e4a7f3 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -1082,7 +1082,7 @@ void highband_exc_dct_in_ivas_fx( Word16 tmp2; Word16 *end, Q_hb_exc; #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - Word16 max_target_ener, old_Q_exc; + Word16 Flag_adj_q_exc, old_Q_exc; #endif FOR( j = 10; j < MBANDS_GN; j++ ) @@ -1408,24 +1408,21 @@ void highband_exc_dct_in_ivas_fx( } } #elif defined FIX_2380_HARM_GSC_GAIN_COMP_FX - max_target_ener = 0; + Flag_adj_q_exc = 0; move16(); - IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep EVS BE */ + IF( NE_16( element_mode, EVS_MONO ) && lt_ener_per_band_fx != NULL ) /* to keep all EVS BE */ { - FOR( i = 0; i < MBANDS_GN / 2; i++ ) - { - max_target_ener = s_max( max_target_ener, Ener_per_bd_iQ[i] ); - } - max_target_ener = sub( 15, norm_s( max_target_ener ) ); + Flag_adj_q_exc = 1; + move16(); } old_Q_exc = *Q_exc; move16(); - *Q_exc = Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, max_target_ener, Qexc_diffQ, *Q_exc ); + *Q_exc = Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Flag_adj_q_exc, Qexc_diffQ, *Q_exc ); Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, old_Q_exc ) ); IF( exc_wo_nf != NULL ) { - Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, max_target_ener, Qexc_diffQ, *Q_exc ); + Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Flag_adj_q_exc, Qexc_diffQ, *Q_exc ); Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame ); } #else /* #if defined FIX_2338_HARM_GSC_GAIN_COMP */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 0435db6a2..c06a57180 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1714,7 +1714,7 @@ void Comp_and_apply_gain_fx( Word16 Mbands_gn, /* i : number of bands */ const Word16 ReUseGain, /* i : Reuse the gain in Ener_per_bd_yQ */ #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - const Word16 max_target_ener, /* i : Ener_per_bd_iQ of lt_ener_per_band_fx */ + const Word16 Flag_adj_q_exc, /* i : Ener_per_bd_iQ of lt_ener_per_band_fx */ #endif Word16 Qexc_diff, Word16 Q_exc ); -- GitLab From ad4e9f58dd109dd5d38e30e3a30009411efe3c77 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 30 Jan 2026 14:40:48 -0500 Subject: [PATCH 6/6] Fix clang --- lib_com/gs_gains_fx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index cb7cc852e..e84336385 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -140,7 +140,7 @@ void Comp_and_apply_gain_fx( move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) ); #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX - IF( Flag_adj_q_exc != 0) + IF( Flag_adj_q_exc != 0 ) { FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { @@ -164,7 +164,6 @@ void Comp_and_apply_gain_fx( move16(); } } - } } #ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX @@ -175,12 +174,12 @@ void Comp_and_apply_gain_fx( { Word16 total_bins = add( StartBin, NB_Qbins ); move16(); - FOR(i = 0; i < total_bins; i++) + FOR( i = 0; i < total_bins; i++ ) { Q_adapt = s_min( Q_adapt, add( Q_exc_diffQ[i], norm_l( exc_diffQ32[i] ) ) ); move16(); } - FOR(i = 0; i < total_bins; i++) + FOR( i = 0; i < total_bins; i++ ) { exc_diffQ[i] = round_fx( L_shl( exc_diffQ32[i], sub( Q_adapt, Q_exc_diffQ[i] ) ) ); /*Q_exc*/ } -- GitLab