From ef86491f0d9ca9ccc1c17bb71699a2b2769addff Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 4 Nov 2025 14:38:24 +0100 Subject: [PATCH 1/3] Make Q-factor of synth_16_fx and output_16_fx dynamic to prevent overflow in HQ_CORE mode --- lib_com/options.h | 1 + lib_dec/ivas_core_dec_fx.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7cf668641..299ff7e9b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,6 +91,7 @@ #define FIX_2174_JBM_BASOP_ALIGNMENT /* VoiceAge, Nokia: Fixes to JBM BASOP implementation and alignment to float */ #define FIX_2176_ASSERT_DEC_MAP_PARAMS_DIRAC2STEREO /* FhG: Reduce hStereoDft->q_smooth_buf_fx by one to prevent overflow in the subframe_band_nrg[][] calculation */ +#define FIX_1947_DEC_HIGH_MLD_FOR_STEREO2MONO /* FhG: Make Q-factor of synth_16_fx and output_16_fx dynamic to prevent overflow in HQ_CORE mode */ /* ################### End FIXES switches ########################### */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 1fd7cb0f3..ae955c5ed 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -643,8 +643,14 @@ ivas_error ivas_core_dec_fx( ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); // Q11 - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); // Q0 - Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); // Q0 +#ifdef FIX_1947_DEC_HIGH_MLD_FOR_STEREO2MONO + st->Q_syn_factor = s_min( 0, s_min( Q_synth, Q_output ) ); + Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor + Scale_sig( output_16_fx[n], L_FRAME48k, sub( st->Q_syn_factor, Q_output ) ); // st->Q_syn_factor +#else + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); // Q0 + Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); // Q0 +#endif } /*---------------------------------------------------------------------* -- GitLab From 0a9a564cb0ed08796d573f70e78751673a5bfe96 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 4 Nov 2025 15:57:44 +0100 Subject: [PATCH 2/3] Modify st->Q_syn_factor to allow positive values in HQ_CORE mode. --- lib_dec/ivas_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index ae955c5ed..f9287ab5f 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -644,7 +644,7 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); // Q11 #ifdef FIX_1947_DEC_HIGH_MLD_FOR_STEREO2MONO - st->Q_syn_factor = s_min( 0, s_min( Q_synth, Q_output ) ); + st->Q_syn_factor = s_min( Q_synth, Q_output ); Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor Scale_sig( output_16_fx[n], L_FRAME48k, sub( st->Q_syn_factor, Q_output ) ); // st->Q_syn_factor #else -- GitLab From c021fbe355c2a25f162b2ff965fca19c08488c14 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 4 Nov 2025 16:51:09 +0100 Subject: [PATCH 3/3] Limit st->Q_syn_factor to nonpositive values in HQ_CORE mode. --- lib_dec/ivas_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index f9287ab5f..ae955c5ed 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -644,7 +644,7 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); // Q11 #ifdef FIX_1947_DEC_HIGH_MLD_FOR_STEREO2MONO - st->Q_syn_factor = s_min( Q_synth, Q_output ); + st->Q_syn_factor = s_min( 0, s_min( Q_synth, Q_output ) ); Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor Scale_sig( output_16_fx[n], L_FRAME48k, sub( st->Q_syn_factor, Q_output ) ); // st->Q_syn_factor #else -- GitLab