From 9e7855a4205c5dc772e9e9aec440133ff2e293cb Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 29 Aug 2025 10:37:57 +0200 Subject: [PATCH 1/4] fix within FIX_1320_STACK_CPE_DECODER --- lib_dec/ivas_mdct_core_dec_fx.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 40dac596b..4744a906d 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1268,7 +1268,11 @@ void ivas_mdct_core_reconstruct_fx( // norm(synth_buf) >= q_syn - q_win // norm(synth_buf) + q_win >= q_syn +#ifdef FIX_1320_STACK_CPE_DECODER + sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS_INTERNAL ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); +#else sf = s_min( getScaleFactor16( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ) ), getScaleFactor16( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ) ) ); +#endif q_syn = add( sub( sf, 1 ), s_min( q_win, q_winFB ) ); st->Q_syn = q_syn; move16(); @@ -1278,7 +1282,11 @@ void ivas_mdct_core_reconstruct_fx( sf = s_min( getScaleFactor16( st->hHQ_core->old_out_fx, L_FRAME48k ), getScaleFactor16( st->hHQ_core->old_out_LB_fx, L_FRAME32k ) ); st->Q_syn = add( sf, s_min( q_win, q_winFB ) ); - Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn +#ifdef FIX_1320_STACK_CPE_DECODER + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS_INTERNAL ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn +#else + Scale_sig( synth_buf_fx, add( add( st->hTcxDec->old_synth_len, L_FRAME_PLUS ), M ), sub( q_syn, q_win ) ); // st->hTcxDec->q_old_synth -> q_syn +#endif Scale_sig( synth_bufFB_fx, add( add( st->hTcxDec->old_synth_lenFB, L_FRAME_PLUS ), M ), sub( q_syn, q_winFB ) ); // st->hTcxDec->q_old_synth -> q_syn // Scale_sig( st->syn, M + 1, add( st->Q_syn, 2 ) ); Scale_sig( st->syn, M + 1, sub( st->Q_syn, q_win ) ); -- GitLab From 49ca5538b180f773cdd5b8ad07f8c3de9c8d10b0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 29 Aug 2025 16:19:18 +0200 Subject: [PATCH 2/4] enable again FIX_1320_STACK_CPE_DECODER + port FIX_1946_CRASH_JBM_PROCESSING within it --- lib_com/options.h | 4 +--- lib_dec/ivas_cpe_dec_fx.c | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index c75d8e226..d6d9a5603 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -89,9 +89,7 @@ #define NONBE_1302_FIX_OMASA_JBM_FLUSH /* VA: issue 1302: fix OMASA JBM bitrate switching flush in binaural output */ #define NONBE_1328_FIX_NON_LINEARITY /* VA: Fix possible issue when computing bwe_exc_extended and previous frame were almost 0, float issue 1328 */ #define FIX_1319_STACK_SBA_DECODER /* VA: issue 1319: Optimize the definition of buffer lengths in the SBA decoder */ -//de-activate FIX_1320_STACK_CPE_DECODER due to sanitizer issues in #1986; also review needed for patch within FIX_1946_CRASH_JBM_PROCESSING, which gets partially disabled -//#define FIX_1320_STACK_CPE_DECODER /* VA: issue 1320: Optimize the stack memory consumption in the CPE decoder */ - +#define FIX_1320_STACK_CPE_DECODER /* VA: issue 1320: Optimize the stack memory consumption in the CPE decoder */ #define FIX_1984_SAT_IN_PSYCHAD /* VA: Issue 1984: proposal to fix an assert */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index a618a8d79..a149f78b3 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -981,7 +981,11 @@ static ivas_error stereo_dft_dec_main( IF( NE_16( shift, 31 ) ) { +#ifdef FIX_1946_CRASH_JBM_PROCESSING + shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q17 ); /* Q17 for guard bits */ +#else shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q16 ); /* Q16 for guard bits */ +#endif IF( GT_16( shift, hCPE->hStereoDft->q_dft ) ) { -- GitLab From 1fbc54865bac7d311db9d4c5a34d842df260bd1c Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sat, 30 Aug 2025 22:09:13 +0200 Subject: [PATCH 3/4] [debugging] temporarily disable part of FIX_1320_STACK_CPE_DECODER, to see whether this restores BE for all test cases; wrapped in FIX_1320_STACK_CPE_DECODER_CHECK_BE, which is locally defined in ivas_core_dec_fx() --- lib_dec/ivas_core_dec_fx.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 92a032ce1..a332b3a4c 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -76,9 +76,14 @@ ivas_error ivas_core_dec_fx( set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); Word16 tmps, incr; +#define FIX_1320_STACK_CPE_DECODER_CHECK_BE #ifdef FIX_1320_STACK_CPE_DECODER - Word32 *bwe_exc_extended_fx[CPE_CHANNELS] = { NULL, NULL }; Word16 flag_bwe_bws; +#ifdef FIX_1320_STACK_CPE_DECODER_CHECK_BE + Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; +#else + Word32 *bwe_exc_extended_fx[CPE_CHANNELS] = { NULL, NULL }; +#endif #else Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; #endif @@ -297,7 +302,9 @@ ivas_error ivas_core_dec_fx( set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); #ifdef FIX_1320_STACK_CPE_DECODER +#ifndef FIX_1320_STACK_CPE_DECODER_CHECK_BE bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */ +#endif #endif /*------------------------------------------------------------------* @@ -1019,15 +1026,19 @@ ivas_error ivas_core_dec_fx( } /* Memories Re-Scaling */ +#ifndef FIX_1320_STACK_CPE_DECODER_CHECK_BE #ifdef FIX_1320_STACK_CPE_DECODER test(); test(); - IF( EQ_16( st->extl, WB_TBE ) || ( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) ) + IF( EQ_16( st->extl, WB_TBE ) || ( ( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) ) ) { +#endif #endif Copy_Scale_sig_16_32_no_sat( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 +#ifndef FIX_1320_STACK_CPE_DECODER_CHECK_BE #ifdef FIX_1320_STACK_CPE_DECODER } +#endif #endif Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], synth_32_fx[n], output_frame, sub( Q11, Q_synth_fx ) ); // Q11 -- GitLab From bc5009c739ecc05aca796c0875feccc5e9fb666b Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 1 Sep 2025 09:04:46 +0200 Subject: [PATCH 4/4] updates to separate BE and non-BE changes --- lib_dec/ivas_core_dec_fx.c | 50 ++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index a332b3a4c..de83e8a07 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -76,14 +76,9 @@ ivas_error ivas_core_dec_fx( set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); Word16 tmps, incr; -#define FIX_1320_STACK_CPE_DECODER_CHECK_BE #ifdef FIX_1320_STACK_CPE_DECODER - Word16 flag_bwe_bws; -#ifdef FIX_1320_STACK_CPE_DECODER_CHECK_BE - Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; -#else + Word16 flag_bwe_bws, flaf_swb_tbe; Word32 *bwe_exc_extended_fx[CPE_CHANNELS] = { NULL, NULL }; -#endif #else Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; #endif @@ -302,9 +297,7 @@ ivas_error ivas_core_dec_fx( set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); #ifdef FIX_1320_STACK_CPE_DECODER -#ifndef FIX_1320_STACK_CPE_DECODER_CHECK_BE bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */ -#endif #endif /*------------------------------------------------------------------* @@ -988,6 +981,24 @@ ivas_error ivas_core_dec_fx( Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; Word16 Q_syn_hb, sf; +#ifdef FIX_1320_STACK_CPE_DECODER + flaf_swb_tbe = 0; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + if ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) + { + flaf_swb_tbe = 1; + move16(); + } +#endif + sf = getScaleFactor32( output_32_fx[n], L_FRAME48k ); Q_input = 0; @@ -1012,7 +1023,6 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->extl, WB_TBE ) ) { /* WB TBE decoder */ - ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); } ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) @@ -1026,19 +1036,13 @@ ivas_error ivas_core_dec_fx( } /* Memories Re-Scaling */ -#ifndef FIX_1320_STACK_CPE_DECODER_CHECK_BE #ifdef FIX_1320_STACK_CPE_DECODER - test(); - test(); - IF( EQ_16( st->extl, WB_TBE ) || ( ( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) ) ) + IF( !flaf_swb_tbe ) { -#endif #endif Copy_Scale_sig_16_32_no_sat( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); // Q11 -#ifndef FIX_1320_STACK_CPE_DECODER_CHECK_BE #ifdef FIX_1320_STACK_CPE_DECODER } -#endif #endif Copy_Scale_sig_16_32_no_sat( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); // Q11 // Q_input can get value <= -5 Copy_Scale_sig_16_32_no_sat( synth_16_fx[n], synth_32_fx[n], output_frame, sub( Q11, Q_synth_fx ) ); // Q11 @@ -1061,6 +1065,7 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); + test(); flag_bwe_bws = ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && st->bfi == 0 ); move16(); #endif @@ -1068,7 +1073,11 @@ ivas_error ivas_core_dec_fx( Q_white_exc = 0; move16(); -#ifndef FIX_1320_STACK_CPE_DECODER +#ifdef FIX_1320_STACK_CPE_DECODER + test(); + test(); + IF( flaf_swb_tbe ) +#else test(); test(); test(); @@ -1076,7 +1085,6 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); -#endif test(); test(); test(); @@ -1088,6 +1096,7 @@ ivas_error ivas_core_dec_fx( test(); test(); IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) +#endif { /* SWB TBE decoder */ ivas_swb_tbe_dec_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 ); @@ -1109,7 +1118,7 @@ ivas_error ivas_core_dec_fx( } } #ifdef FIX_1320_STACK_CPE_DECODER - ELSE IF( st->extl == SWB_BWE || st->extl == FB_BWE || flag_bwe_bws ) + ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || flag_bwe_bws ) #else ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) #endif @@ -1126,11 +1135,10 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); - IF( ( st->core == ACELP_CORE && ( st->extl == -1 || st->extl == SWB_CNG ) ) && flag_bwe_bws == 0 ) + IF( ( st->core == ACELP_CORE && ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) ) ) && flag_bwe_bws == 0 ) { set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); } - #endif /*---------------------------------------------------------------------* -- GitLab