diff --git a/lib_com/options.h b/lib_com/options.h index c75d8e226f6d7b632592c0c96fe407f3d32f0c1e..d6d9a56032b6854e291b9ac452276798d3e5eac8 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_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 92a032ce1c12c47f8f1c7084d710e1580de38837..de83e8a072fb3e427a731d888b2d1f7a899646b8 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -77,8 +77,8 @@ ivas_error ivas_core_dec_fx( Word16 tmps, incr; #ifdef FIX_1320_STACK_CPE_DECODER + Word16 flag_bwe_bws, flaf_swb_tbe; Word32 *bwe_exc_extended_fx[CPE_CHANNELS] = { NULL, NULL }; - Word16 flag_bwe_bws; #else Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; #endif @@ -981,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; @@ -1005,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 ) @@ -1020,9 +1037,7 @@ ivas_error ivas_core_dec_fx( /* Memories Re-Scaling */ #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 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 @@ -1050,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 @@ -1057,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(); @@ -1065,7 +1085,6 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); -#endif test(); test(); test(); @@ -1077,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 ); @@ -1098,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 @@ -1115,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 /*---------------------------------------------------------------------* diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index a618a8d792fe4108f311548d9ae1bcb2fcf0f9f0..a149f78b3b0de6836ef7b36ef250a63440048ec7 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 ) ) { diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 40dac596b25fb10ffc9fe1153d9e108cebb04019..4744a906dbc2ce05a0e9255ff305155008e2691c 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 ) );