From bfd0340d8f003cbbd00b4c0be575d310e4381224 Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 17 Oct 2025 14:22:17 +0200 Subject: [PATCH 01/21] 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 02/21] 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 From 81cdb4b62d9d8fb3a41441cef95c363b5230ca64 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 20 Oct 2025 12:02:30 +0200 Subject: [PATCH 03/21] Scaling st->old_exc_fx using st->Q_syn_factor from the previous frame in acelp_core_dec_fx(). --- lib_dec/acelp_core_dec_fx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 00d6ce926..bb6ab41b2 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -297,7 +297,13 @@ ivas_error acelp_core_dec_fx( move16(); tmp_noise_fx = 0; move16(); +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Copy_Scale_sig( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); /*Q_exc*/ + st->Q_syn_factor = 0; + move16(); +#else Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ +#endif exc_fx = old_exc_fx + L_EXC_MEM_DEC; IF( st->hWIDec != NULL ) -- GitLab From 38244a544bf597ad69f2f4b3273ee08d232eedcc Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 20 Oct 2025 14:32:41 +0200 Subject: [PATCH 04/21] Add synth_q to decoder_tcx_ivas_fx() arguments --- lib_com/prot_fx.h | 3 +++ lib_dec/dec_tcx_fx.c | 13 +++++++++---- lib_dec/ivas_tcx_core_dec_fx.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 32b8a00ee..85984d53d 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -9101,6 +9101,9 @@ void decoder_tcx_ivas_fx( Word16 Aind[], Word16 synth_fx[], Word16 synthFB_fx[], +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Word16 *synth_q, +#endif const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 194b30b9b..397ba6390 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3970,10 +3970,16 @@ void decoder_tcx_IGF_stereo_fx( void decoder_tcx_ivas_fx( Decoder_State *st, Word16 prm[], - Word16 A_fx[], // Q: 14 - norm_s(A_fx[0]) - Word16 Aind[], // Q: 14 - norm_s(Aind[0]) + Word16 A_fx[], // Q: 14 - norm_s(A_fx[0]) + Word16 Aind[], // Q: 14 - norm_s(Aind[0]) +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Word16 synth_fx[], + Word16 synthFB_fx[], + Word16 *synth_q, +#else Word16 synth_fx[], // Q_syn Word16 synthFB_fx[], // Q_syn +#endif const Word16 bfi, const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ) @@ -4080,8 +4086,7 @@ void decoder_tcx_ivas_fx( 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; + *synth_q = 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 ) ); diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 722ce3217..8402e37f0 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -234,7 +234,9 @@ void stereo_tcx_core_dec_fx( Word16 *synth_fx; Word16 synth_bufFB_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB_fx; - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Word16 synth_q[2]; +#endif Word32 psd_fx[L_FRAME16k]; Word32 psd_part_fx[NPART_SHAPING]; Word16 psd_part_e; @@ -599,7 +601,13 @@ void stereo_tcx_core_dec_fx( } /* TCX decoder */ +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], &synth_q[0], bfi, 0, sba_dirac_stereo_flag ); + st->Q_syn_factor = sub( synth_q[0], st->Q_syn ); + st->Q_syn = synth_q[0]; +#else decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], bfi, 0, sba_dirac_stereo_flag ); +#endif } /*--------------------------------------------------------------------------------* @@ -628,8 +636,27 @@ void stereo_tcx_core_dec_fx( } /* TCX decoder */ +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * ( hTcxDec->L_frameTCX / 2 )], &synth_q[k], bfi, k, sba_dirac_stereo_flag ); + } + + Word16 q_min, q_shift; + + q_min = s_min( synth_q[0], synth_q[1] ); + st->Q_syn_factor = sub( q_min, st->Q_syn ); + st->Q_syn = q_min; + + q_shift = sub( q_min, synth_q[0] ); + scale_sig( &synth_fx[0], shr( st->L_frame, 1 ), q_shift ); + scale_sig( &synthFB_fx[0], shr( hTcxDec->L_frameTCX, 1 ), q_shift ); + + q_shift = sub( q_min, synth_q[1] ); + scale_sig( &synth_fx[shr( st->L_frame, 1 )], shr( st->L_frame, 1 ), q_shift ); + scale_sig( &synthFB_fx[shr( hTcxDec->L_frameTCX, 1 )], shr( hTcxDec->L_frameTCX, 1 ), q_shift ); +#else decoder_tcx_ivas_fx( st, prm, Aq_fx, Aind, &synth_fx[k * st->L_frame / 2], &synthFB_fx[k * ( hTcxDec->L_frameTCX / 2 )], bfi, k, sba_dirac_stereo_flag ); } +#endif } /*--------------------------------------------------------------------------------* -- GitLab From 7daf30aeeae398af45b0ff23f7f80f0a6084646d Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 20 Oct 2025 16:11:55 +0200 Subject: [PATCH 05/21] Handle uninitialized st->Q_syn_factor cases in ACELP mode. --- lib_dec/acelp_core_dec_fx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index bb6ab41b2..56aab21c0 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -298,7 +298,14 @@ ivas_error acelp_core_dec_fx( tmp_noise_fx = 0; move16(); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - Copy_Scale_sig( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); /*Q_exc*/ + if ( NE_32( st->last_core, TCX_10_CORE ) || NE_32( st->last_core, TCX_20_CORE ) ) // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized + { + Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ + } + else + { + Copy_Scale_sig( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); /*Q_exc*/ + } st->Q_syn_factor = 0; move16(); #else -- GitLab From a8ae56a3f338e7d9e12977e73bfb6e9d998fa23e Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 20 Oct 2025 17:12:23 +0200 Subject: [PATCH 06/21] Fix if-condition in scaling st->old_exc_fx in ACLEP mode. --- lib_dec/acelp_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 56aab21c0..2f2a86765 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -298,7 +298,7 @@ ivas_error acelp_core_dec_fx( tmp_noise_fx = 0; move16(); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( NE_32( st->last_core, TCX_10_CORE ) || NE_32( st->last_core, TCX_20_CORE ) ) // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized + if ( NE_32( st->last_core, TCX_10_CORE ) && NE_32( st->last_core, TCX_20_CORE ) ) // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized { Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ } -- GitLab From 064cb25c165fbdb9f771d624badd7c7b56712335 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 21 Oct 2025 17:29:01 +0200 Subject: [PATCH 07/21] Fix q_min calculation in decoder_tcx_ivas_fx() --- lib_dec/dec_tcx_fx.c | 4 ++-- lib_dec/ivas_tcx_core_dec_fx.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 397ba6390..599475923 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4081,8 +4081,8 @@ void decoder_tcx_ivas_fx( /* 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 ); + Word16 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ), + add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) ); 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 ) ); diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 8402e37f0..4b437bf6a 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -701,13 +701,13 @@ void stereo_tcx_core_dec_fx( 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 ); + TonalMDCTConceal_SaveTimeSignal_ivas_fx( st->hTonalMDCTConc, synthFB_fx, st->Q_syn, 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 ); + decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, st->Q_syn, Aq_fx, bfi, 0 ); #else decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, 0, Aq_fx, bfi, 0 ); #endif -- GitLab From 7a9c1c4bc074643ebd1add8ebb329d0ee08732c3 Mon Sep 17 00:00:00 2001 From: naghibza Date: Wed, 22 Oct 2025 14:51:33 +0200 Subject: [PATCH 08/21] Replace scale_sig() with Scale_sig() to reduce regressions, as it may have better precision. --- lib_dec/dec_tcx_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 599475923..a8db9f9cc 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4084,8 +4084,8 @@ void decoder_tcx_ivas_fx( Word16 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ), add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) ); 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 ) ); + Scale_sig( synth_fx, L_frame_glob, sub( q_min, q_win ) ); + Scale_sig( synthFB_fx, L_frameTCX_glob, sub( q_min, q_winFB ) ); *synth_q = q_min; #else Scale_sig( synth_fx, L_frame_glob, sub( st->Q_syn, q_win ) ); -- GitLab From a5befdfc3b8af70b99cbe78c5fd283760680386b Mon Sep 17 00:00:00 2001 From: naghibza Date: Thu, 23 Oct 2025 16:23:07 +0200 Subject: [PATCH 09/21] Scale synth buffer in con_tcx_fx() using st->Q_syn_factor --- lib_dec/er_dec_tcx_fx.c | 21 +++++++++++++++++++-- lib_dec/ivas_tcx_core_dec_fx.c | 13 ++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 7cb4f897b..c84ffe6d5 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -190,9 +190,16 @@ void con_tcx_fx( IF( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) { /* apply pre-emphasis to the signal */ +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + mem = shl( synth[( -( ( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ +#else mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ +#endif move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + scale_sig( &( synth[-( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ +#endif st->Mode2_lp_gainc = L_deposit_l( 0 ); st->Mode2_lp_gainp = get_gain2( synth - shl( L_subfr, 1 ), synth - add( shl( L_subfr, 1 ), Tc ), shl( L_subfr, 1 ) ); /*Q16*/ @@ -231,9 +238,16 @@ void con_tcx_fx( ELSE { /* apply pre-emphasis to the signal */ - mem = synth[( -L_frame - 1 )]; /*Q0*/ +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/ +#else + mem = synth[( -L_frame - 1 )]; /*Q0*/ +#endif move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ +#endif Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ offset = shr( L_frame, 1 ); @@ -247,7 +261,10 @@ void con_tcx_fx( Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + st->Q_syn_factor = 0; + move16(); +#endif /*-----------------------------------------------------------------* * PLC: Construct the harmonic part of excitation *-----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 4b437bf6a..6ee4bfe18 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -311,10 +311,7 @@ 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 *--------------------------------------------------------------------------------*/ @@ -340,7 +337,13 @@ void stereo_tcx_core_dec_fx( st->core = GetPLCModeDecision_ivas_fx( st ); /* Q0 */ move16(); } - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + IF( st->core != ACELP_CORE ) + { + st->Q_syn_factor = 0; + move16(); + } +#endif /*--------------------------------------------------------------------------------* * LPC envelope decoding *--------------------------------------------------------------------------------*/ -- GitLab From a0b60fbcf22031d442a1ebc9420dc2a00db56c1a Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 24 Oct 2025 13:11:44 +0200 Subject: [PATCH 10/21] Reset st->Q_syn_factor in HQ_CORE mode. --- lib_dec/er_dec_tcx_fx.c | 4 ++-- lib_dec/ivas_core_dec_fx.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index c84ffe6d5..9efe57497 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -191,7 +191,7 @@ void con_tcx_fx( { /* apply pre-emphasis to the signal */ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - mem = shl( synth[( -( ( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ + mem = shl_sat( synth[( -( ( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ #else mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ #endif @@ -239,7 +239,7 @@ void con_tcx_fx( { /* apply pre-emphasis to the signal */ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/ + mem = shl_sat( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/ #else mem = synth[( -L_frame - 1 )]; /*Q0*/ #endif diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index cbf346b7d..e9af72c0e 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -625,6 +625,10 @@ ivas_error ivas_core_dec_fx( move16(); Q_synth = 0; move16(); +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + st->Q_syn_factor = 0; + move16(); +#endif 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 ); -- GitLab From 1dc57f01a0813a2122608eb8a3f8f8175eb67a13 Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 24 Oct 2025 14:49:07 +0200 Subject: [PATCH 11/21] Scale tmp_deemph using st->Q_syn_factor. --- lib_dec/er_dec_tcx_fx.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 9efe57497..2b20e454f 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -191,7 +191,7 @@ void con_tcx_fx( { /* apply pre-emphasis to the signal */ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - mem = shl_sat( synth[( -( ( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ + mem = shl( synth[( -( ( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ #else mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ #endif @@ -239,7 +239,7 @@ void con_tcx_fx( { /* apply pre-emphasis to the signal */ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - mem = shl_sat( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/ + mem = shl( synth[( -L_frame - 1 )], st->Q_syn_factor ); /*Q0*/ #else mem = synth[( -L_frame - 1 )]; /*Q0*/ #endif @@ -261,10 +261,7 @@ void con_tcx_fx( Copy_Scale_sig( hTcxDec->old_excFB_fx, &( exc[-( L_subfr * 2 )] ), add( shl( L_subfr, 1 ), offset ), sub( Q_exc, st->Q_exc ) ); /*Q_exc*/ } } -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - st->Q_syn_factor = 0; - move16(); -#endif + /*-----------------------------------------------------------------* * PLC: Construct the harmonic part of excitation *-----------------------------------------------------------------*/ @@ -783,9 +780,15 @@ void con_tcx_fx( syn = buf + M; /*Q_syn*/ Copy( synth - M, buf, M ); /*Q_syn*/ - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Word16 scf = norm_s( tmp_deemph ); + new_Q = sub( Q_exc, 4 ); + new_Q = s_max( new_Q, -1 ); + new_Q = s_min( new_Q, scf ); +#else new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); +#endif tmp16 = s_min( new_Q, st->prev_Q_syn ); st->prev_Q_syn = new_Q; @@ -796,8 +799,17 @@ void con_tcx_fx( move16(); Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ - +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) + { + Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf; + } + tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) ); + st->Q_syn_factor = 0; + move16(); +#else tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/ +#endif st->Q_syn = Q_syn; move16(); -- GitLab From 0efb3891d86c9715201a6ea664412ec7e493993c Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 24 Oct 2025 15:27:40 +0200 Subject: [PATCH 12/21] Fix mem calculation in con_tcx_fx() --- lib_dec/er_dec_tcx_fx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 2b20e454f..1a9eab553 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -105,7 +105,11 @@ void con_tcx_fx( Word16 pre_emph_buf; Word16 hp_filt[L_FIR_FER2]; Word16 alpha; +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + Word16 tmp_deemph, gain, gainCNG, gain_inov, scf; +#else Word16 tmp_deemph, gain, gainCNG, gain_inov; +#endif Word16 *pt_exc, *pt1_exc; Word16 Tc, tmpSeed; Word16 fUseExtrapolatedPitch; @@ -191,14 +195,14 @@ void con_tcx_fx( { /* apply pre-emphasis to the signal */ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - mem = shl( synth[( -( ( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ + mem = shl( synth[( -( ( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )], st->Q_syn_factor ); /*Q0*/ #else mem = synth[( -( ( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + M + M ) ) - 1 )]; /*Q0*/ #endif move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - scale_sig( &( synth[-( ( shr( L_frame, 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ + scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ #endif st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -781,7 +785,7 @@ void con_tcx_fx( syn = buf + M; /*Q_syn*/ Copy( synth - M, buf, M ); /*Q_syn*/ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - Word16 scf = norm_s( tmp_deemph ); + scf = norm_s( tmp_deemph ); new_Q = sub( Q_exc, 4 ); new_Q = s_max( new_Q, -1 ); new_Q = s_min( new_Q, scf ); -- GitLab From f3e8dfb52b28b1c82c5eb32b202452cf3458f805 Mon Sep 17 00:00:00 2001 From: naghibza Date: Fri, 24 Oct 2025 17:25:56 +0200 Subject: [PATCH 13/21] Fix st->Q_syn using st->Q_syn_factor in acelp_core_dec_fx.c. --- lib_dec/acelp_core_dec_fx.c | 1 + lib_dec/er_dec_tcx_fx.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 2f2a86765..458024e4a 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -305,6 +305,7 @@ ivas_error acelp_core_dec_fx( else { Copy_Scale_sig( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); /*Q_exc*/ + st->Q_syn = add( st->Q_syn, st->Q_syn_factor ); } st->Q_syn_factor = 0; move16(); diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 1a9eab553..b1ad90a30 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -202,7 +202,7 @@ void con_tcx_fx( move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ + Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ #endif st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -250,7 +250,7 @@ void con_tcx_fx( move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ + Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ #endif Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ -- GitLab From cb2ce5f2efd6742f6e31a326c4ba0b6888dd5797 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 27 Oct 2025 13:08:07 +0100 Subject: [PATCH 14/21] Set st->Q_syn_factor when no secondary channel existed in the previous frame. --- lib_dec/acelp_core_dec_fx.c | 14 -------------- lib_dec/ivas_core_dec_fx.c | 10 ++++++++++ lib_dec/ivas_stereo_switching_dec_fx.c | 4 ++++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index 458024e4a..00d6ce926 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -297,21 +297,7 @@ ivas_error acelp_core_dec_fx( move16(); tmp_noise_fx = 0; move16(); -#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( NE_32( st->last_core, TCX_10_CORE ) && NE_32( st->last_core, TCX_20_CORE ) ) // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized - { - Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ - } - else - { - Copy_Scale_sig( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); /*Q_exc*/ - st->Q_syn = add( st->Q_syn, st->Q_syn_factor ); - } - st->Q_syn_factor = 0; - move16(); -#else Copy( st->old_exc_fx, old_exc_fx, L_EXC_MEM_DEC ); /*Q_exc*/ -#endif exc_fx = old_exc_fx + L_EXC_MEM_DEC; IF( st->hWIDec != NULL ) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index e9af72c0e..3f11089a6 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -522,6 +522,16 @@ ivas_error ivas_core_dec_fx( Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); // Qx } +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + if ( ( EQ_32( st->last_core, TCX_10_CORE ) || EQ_32( st->last_core, TCX_20_CORE ) ) || // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized + ( GT_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( ( EQ_32( sts[0]->last_core, TCX_10_CORE ) || EQ_32( sts[0]->last_core, TCX_20_CORE ) ) ) ) ) // in this case sts[1] gets it value from sts[0] + { + Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); + st->Q_syn = add( st->Q_syn, st->Q_syn_factor ); + } + st->Q_syn_factor = 0; + move16(); +#endif IF( NE_32( ( error = acelp_core_dec_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_dec/ivas_stereo_switching_dec_fx.c b/lib_dec/ivas_stereo_switching_dec_fx.c index da6adcf33..76041da39 100644 --- a/lib_dec/ivas_stereo_switching_dec_fx.c +++ b/lib_dec/ivas_stereo_switching_dec_fx.c @@ -1951,6 +1951,10 @@ void stereo_switching_dec( Copy( sts[0]->old_exc_fx, sts[1]->old_exc_fx, L_EXC_MEM_DEC ); /* Q_exc */ sts[1]->Q_exc = sts[0]->Q_exc; move16(); +#ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE + sts[1]->Q_syn_factor = sts[0]->Q_syn_factor; + move16(); +#endif sts[1]->Q_exc_cng = sts[0]->Q_exc_cng; move16(); sts[1]->prev_Q_exc = sts[0]->prev_Q_exc; -- GitLab From eddfd665e142c7395df8aaecf76d2de6d0082500 Mon Sep 17 00:00:00 2001 From: naghibza Date: Mon, 27 Oct 2025 13:30:51 +0100 Subject: [PATCH 15/21] Handle hCPE == NULL condition --- lib_dec/ivas_core_dec_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 3f11089a6..4b507827f 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -523,8 +523,8 @@ ivas_error ivas_core_dec_fx( } #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( ( EQ_32( st->last_core, TCX_10_CORE ) || EQ_32( st->last_core, TCX_20_CORE ) ) || // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized - ( GT_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( ( EQ_32( sts[0]->last_core, TCX_10_CORE ) || EQ_32( sts[0]->last_core, TCX_20_CORE ) ) ) ) ) // in this case sts[1] gets it value from sts[0] + if ( ( EQ_32( st->last_core, TCX_10_CORE ) || EQ_32( st->last_core, TCX_20_CORE ) ) || // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized + ( hCPE != NULL && ( GT_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( ( EQ_32( sts[0]->last_core, TCX_10_CORE ) || EQ_32( sts[0]->last_core, TCX_20_CORE ) ) ) ) ) ) // in this case sts[1] gets it value from sts[0] { Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); st->Q_syn = add( st->Q_syn, st->Q_syn_factor ); -- GitLab From 3f0458ecbe3ab68eca732d848e293c092f9f5df7 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 28 Oct 2025 10:12:25 +0100 Subject: [PATCH 16/21] Exclude EVS_MONO from dynamic scaling of the synthesis buffer. --- lib_dec/dec_tcx_fx.c | 19 +++++++++++++------ lib_dec/ivas_core_dec_fx.c | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index a8db9f9cc..6e5a7723c 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4081,12 +4081,19 @@ void decoder_tcx_ivas_fx( /* Scaling up again */ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - Word16 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ), - add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) ); - 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 ) ); - *synth_q = q_min; + IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness + { + Word16 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ), + add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) ); + 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 ) ); + *synth_q = q_min; + } + ELSE + { + *synth_q = st->Q_syn; + } #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 ) ); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 4b507827f..1fd7cb0f3 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -523,8 +523,8 @@ ivas_error ivas_core_dec_fx( } #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( ( EQ_32( st->last_core, TCX_10_CORE ) || EQ_32( st->last_core, TCX_20_CORE ) ) || // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized - ( hCPE != NULL && ( GT_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( ( EQ_32( sts[0]->last_core, TCX_10_CORE ) || EQ_32( sts[0]->last_core, TCX_20_CORE ) ) ) ) ) ) // in this case sts[1] gets it value from sts[0] + IF( ( EQ_32( st->last_core, TCX_10_CORE ) || EQ_32( st->last_core, TCX_20_CORE ) ) || // st->Q_syn_factor is set in TCX mode; otherwise, it may be uninitialized + ( hCPE != NULL && ( GT_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && ( ( EQ_32( sts[0]->last_core, TCX_10_CORE ) || EQ_32( sts[0]->last_core, TCX_20_CORE ) ) ) ) ) ) // In this case, sts[1] gets its value from sts[0]. { Scale_sig( st->old_exc_fx, L_EXC_MEM_DEC, negate( st->Q_syn_factor ) ); st->Q_syn = add( st->Q_syn, st->Q_syn_factor ); -- GitLab From c509a87358776bf789ed8dfc262552588c3ff8b7 Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 28 Oct 2025 10:34:08 +0100 Subject: [PATCH 17/21] Fix synth scaling in EVS_MONO. --- lib_dec/dec_tcx_fx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 6e5a7723c..48fa391c5 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4092,6 +4092,8 @@ void decoder_tcx_ivas_fx( } 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 ) ); *synth_q = st->Q_syn; } #else -- GitLab From 0c197e5e0f36f9296fa6617d7559adaaba73797b Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 28 Oct 2025 11:01:32 +0100 Subject: [PATCH 18/21] Exclude EVS_MONO from dynamic scaling of the synthesis buffer to preserve bit-exactness. --- lib_dec/er_dec_tcx_fx.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index b1ad90a30..5d22b96c5 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -785,10 +785,21 @@ void con_tcx_fx( syn = buf + M; /*Q_syn*/ Copy( synth - M, buf, M ); /*Q_syn*/ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - scf = norm_s( tmp_deemph ); - new_Q = sub( Q_exc, 4 ); - new_Q = s_max( new_Q, -1 ); - new_Q = s_min( new_Q, scf ); + IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness + { + scf = norm_s( tmp_deemph ); + new_Q = sub( Q_exc, 4 ); + new_Q = s_max( new_Q, -1 ); + new_Q = s_min( new_Q, scf ); + } + ELSE + { + new_Q = sub( Q_exc, 3 ); + new_Q = s_max( new_Q, -1 ); + + scf = 0; + move16(); + } #else new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); @@ -804,7 +815,7 @@ void con_tcx_fx( Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) + if ( NE_32( st->element_mode, EVS_MONO ) && GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) { Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf; } -- GitLab From b9ac7db87ccb18a90ee17dc7faa35f7fba6a670c Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 28 Oct 2025 12:18:33 +0100 Subject: [PATCH 19/21] Exclude EVS_MONO from dynamic scaling of the synthesis buffer in con_tcx_fx() to preserve evs bit-exactness. --- lib_dec/er_dec_tcx_fx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 5d22b96c5..6320bfdf1 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -202,7 +202,10 @@ void con_tcx_fx( move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ + if ( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness + { + Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ + } #endif st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -250,7 +253,10 @@ void con_tcx_fx( move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ + if ( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness + { + Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ + } #endif Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ -- GitLab From d0da6b437038fa4f701ce33b726fe9c49396edaf Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 28 Oct 2025 15:31:50 +0100 Subject: [PATCH 20/21] Fix tmp_deemph scaling in EVS_MONO mode. --- lib_dec/er_dec_tcx_fx.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 6320bfdf1..2c197d23d 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -202,10 +202,7 @@ void con_tcx_fx( move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-( ( ( L_frame / 2 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), st->preemph_fac, add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), &mem, 1 ); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness - { - Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ - } + Scale_sig( &( synth[-( ( shr( L_frame, 1 ) + hTcxDec->pit_max_TCX ) + 2 * M )] ), add( add( shr( L_frame, 1 ), hTcxDec->pit_max_TCX ), shl( M, 1 ) ), negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ #endif st->Mode2_lp_gainc = L_deposit_l( 0 ); @@ -253,10 +250,7 @@ void con_tcx_fx( move16(); Q_exc = E_UTIL_f_preemph3( &( synth[-L_frame] ), st->preemph_fac, L_frame, &mem, 1 ); #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness - { - Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ - } + Scale_sig( &synth[-L_frame], L_frame, negate( st->Q_syn_factor ) ); /*Q0, Setting back to Q0, as the following calculations are implemented assuming synth is in Q0 */ #endif Copy( st->old_Aq_12_8_fx, A_local, M + 1 ); /*Q12*/ @@ -821,11 +815,18 @@ void con_tcx_fx( Copy_Scale_sig( buf, mem_syn, M, exp_scale ); /*Q: tmp16*/ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - if ( NE_32( st->element_mode, EVS_MONO ) && GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) + IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness { - Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf; + if ( GT_16( sub( Q_syn, st->Q_syn_factor ), scf ) ) + { + Q_syn = add( scf, st->Q_syn_factor ); // so that (Q_syn - st->Q_syn_factor) = scf; + } + tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) ); + } + ELSE + { + tmp_deemph = shl_sat( tmp_deemph, Q_syn ); /*Q_syn*/ } - tmp_deemph = shl( tmp_deemph, sub( Q_syn, st->Q_syn_factor ) ); st->Q_syn_factor = 0; move16(); #else -- GitLab From efbd8a7883f8d0db7870cf32bf84fe9b3f18255e Mon Sep 17 00:00:00 2001 From: naghibza Date: Tue, 28 Oct 2025 16:15:33 +0100 Subject: [PATCH 21/21] Remove EVS_MONO condition from decoder_tcx_ivas_fx() as it is unnecessary --- lib_dec/dec_tcx_fx.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 48fa391c5..a8db9f9cc 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -4081,21 +4081,12 @@ void decoder_tcx_ivas_fx( /* Scaling up again */ #ifdef FIX_1793_DEC_MC_TO_MONO_SCALING_ISSUE - IF( NE_32( st->element_mode, EVS_MONO ) ) // to keep evs bit-exactness - { - Word16 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ), - add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) ); - 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 ) ); - *synth_q = 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 ) ); - *synth_q = st->Q_syn; - } + Word16 q_min = s_min( add( q_win, getScaleFactor16( synth_fx, L_frame_glob ) ), + add( q_winFB, getScaleFactor16( synthFB_fx, L_frameTCX_glob ) ) ); + 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 ) ); + *synth_q = 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 ) ); -- GitLab