From bfd0340d8f003cbbd00b4c0be575d310e4381224 Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 17 Oct 2025 14:22:17 +0200 Subject: [PATCH 1/2] Use dynamic Q factor for synth_fx and synthFB_fx to prevent overflow --- lib_com/options.h | 2 +- lib_dec/dec_tcx_fx.c | 11 +++++++++++ lib_dec/ivas_core_dec_fx.c | 9 ++++++++- lib_dec/ivas_tcx_core_dec_fx.c | 14 ++++++++++++-- lib_dec/stat_dec.h | 4 ++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 38bbbc7a5..be84219f2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -79,7 +79,7 @@ #define FIX_1785_ASSERT_IN_IVAS_JBM_DEC_RENDER_FX /* Orange: 10ms Rendering: Assert in ivas_jbm_dec_render_fx() -> scale_sig32 */ #define FIX_2081_REVISE_H1_SCALING /* VA: accommodate for H1 overshoot that was causing assert in set_impule. Not BE with MASA on LTV with bitrate switching for only 2 instances */ #define TEMP_FIX_2088_MSAN_INIT_ERROR /* Eri: Temporary fix for Issue 2088 - MSAN error. Will come with later port of JBM+Split rendering update */ - +#define FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE /* FhG: Use dynamic Q factor for synth_fx and synthFB_fx to prevent overflow */ /* ################### End FIXES switches ########################### */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index ee8273a7b..6466fc4b0 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4073,8 +4073,19 @@ void decoder_tcx_ivas_fx( fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); /* Scaling up again */ +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Word16 scf_min = s_min( getScaleFactor16( synth_fx, L_frame_glob ), getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ); + Word16 q_min = add( s_min( q_win, q_winFB ), scf_min ); + q_min = s_min( q_min, st->Q_syn ); + scale_sig( synth_fx, L_frame_glob, sub( q_min, q_win ) ); + scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_min, q_winFB ) ); + st->Q_syn_factor = sub( q_min, st->Q_syn ); + st->Q_syn = q_min; +#else Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) ); Scale_sig( synthFB_fx, L_frameTCX_glob, sub( st->Q_syn, q_winFB ) ); +#endif + // Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, 1 ); Scale_sig( st->hTcxDec->old_syn_Overl, 320, ( -2 - st->hTcxDec->Q_old_syn_Overl ) ); // Scaling to Q-2 diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index f3020662b..cbf346b7d 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -597,8 +597,11 @@ ivas_error ivas_core_dec_fx( } stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, sub( Q11, st->Q_syn_factor ) ); // Q11 +#else Copy_Scale_sig_16_32_DEPREC( output_16_fx[n], output_32_fx[n], output_frame, Q11 ); // Q11 +#endif IF( st->hTcxDec ) { @@ -805,7 +808,11 @@ ivas_error ivas_core_dec_fx( *---------------------------------------------------------------------*/ /*core_switching_post_dec*/ +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Q_synth = add( sub( 15, e_sig[0] ), st->Q_syn_factor ); +#else Q_synth = sub( 15, e_sig[0] ); +#endif /*------------------fix-to-fix-end-----------------------*/ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index b36aad0c1..722ce3217 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -309,7 +309,10 @@ void stereo_tcx_core_dec_fx( set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); #endif set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + st->Q_syn_factor = 0; + move16(); +#endif /*--------------------------------------------------------------------------------* * BITSTREAM DECODING *--------------------------------------------------------------------------------*/ @@ -670,10 +673,17 @@ void stereo_tcx_core_dec_fx( #endif IF( !bfi && st->hTonalMDCTConc != NULL ) { +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, st->Q_syn_factor, hTcxDec->L_frameTCX ); +#else TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, 0, hTcxDec->L_frameTCX ); +#endif } - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, st->Q_syn_factor, Aq_fx, bfi, 0 ); +#else decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, 0, Aq_fx, bfi, 0 ); +#endif IF( EQ_16( st->core, TCX_20_CORE ) ) { diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 81951104e..8a8d6b093 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -1310,7 +1310,11 @@ typedef struct Decoder_State Word16 Q_syn; Word16 Q_syn2; Word16 Q_syn_cng; +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Word16 Q_syn_factor; // This q_factor is used to avoid using fix Q0 for synth[] at the output of con_tcx_ivas_fx() and ivas_core_dec_fx(). For con_tcx_ivas_fx, it is used for two consecutive TCX concealment processes and It cannot be greater than 0. +#else Word16 Q_syn_factor; // This q_factor is used to avoid using fixed Q0 for synth[] at the output of con_tcx_ivas_fx(). It is then used for two consecutive TCX concealment processes. It cannot be greater than 0. +#endif Word16 prev_Q_syn; Word16 prev_Q_bwe_exc; -- GitLab From e7150d468a548a2e71492ac723a45c826ea68062 Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 17 Oct 2025 15:14:11 +0200 Subject: [PATCH 2/2] Removed q_win == 0 assertion. --- lib_dec/dec_tcx_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 6466fc4b0..194b30b9b 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4063,8 +4063,9 @@ void decoder_tcx_ivas_fx( move16(); q_winFB = st->Q_syn; move16(); - +#ifndef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE assert( q_win == 0 ); +#endif Scale_sig( synth_fx, L_frame_glob, sub( q_win, st->Q_syn ) ); // Scaling to Q_syn Scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_winFB, st->Q_syn ) ); // Scaling to Q_syn -- GitLab