diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 24af77e23a54efdc584eb71b2661e9994449b0d8..0e1f6dcea1be6550ae9344a514ce5ed92ae73ff6 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -668,6 +668,9 @@ enum #define ACELP_TCX_TRANS_NS 1250000 /* Duration of the ACELP->TCX overlap - 1.25 ms */ #define L_FRAME_MAX L_FRAME48k /* Max 20ms frame size @48kHz */ #define L_FRAME_PLUS 1200 /* Max frame size (long TCX frame) */ +#ifdef FIX_1320_STACK_CPE_DECODER +#define L_FRAME_PLUS_INTERNAL 800 /* Max frame size (long TCX frame) at maximum internal sampling rate */ +#endif #define L_MDCT_OVLP_MAX NS2SA( 48000, ACELP_LOOK_NS ) /* = Max mdct overlap */ #define N_TCX10_MAX 480 /* Max size of TCX10 MDCT spectrum */ #define BITS_TEC 1 /* number of bits for TEC */ diff --git a/lib_com/options.h b/lib_com/options.h index 5700d1f0cc6aace8d7b5c49e36ab6b2ad2fc692f..0201286a2361818130eb746e651f50d5049979b9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,6 +84,7 @@ #define FIX_1129_EXT_REND_OUTPUT_HIGH /* Philips: issue 1129: External renderer BINAURAL_ROOM_REVERB format output level too high compared to internal rendering 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 */ +#define FIX_1320_STACK_CPE_DECODER /* VA: issue 1320: Optimize the stack memory consumption in the CPE decoder */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 5549cc809ad29574368e183f5c9d4d96a91604f3..6a06df2678b6e665c8bc76554d4def55120bf8da 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -36,7 +36,11 @@ void decoder_LPD_fx( ) { Word16 *param_lpc; +#ifdef FIX_1320_STACK_CPE_DECODER + Word16 synth_buf[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M]; +#else Word16 synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; +#endif Word16 *synth; Word16 synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB; @@ -114,7 +118,11 @@ void decoder_LPD_fx( synth = synth_buf + hTcxDec->old_synth_len; /*st->old_synth: Q_0*/ Copy( hTcxDec->old_synth, synth_buf, hTcxDec->old_synth_len ); +#ifdef FIX_1320_STACK_CPE_DECODER + set16_fx( synth, 0, L_FRAME_PLUS_INTERNAL + M ); +#else set16_fx( synth, 0, L_FRAME_PLUS + M ); +#endif synthFB = synth_bufFB + hTcxDec->old_synth_lenFB; Copy( hTcxDec->old_synthFB_fx, synth_bufFB, hTcxDec->old_synth_lenFB ); diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index d9eefa33a52aa408c1e69fc43f4bf2e955b7eab9..92a032ce1c12c47f8f1c7084d710e1580de38837 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -76,7 +76,12 @@ ivas_error ivas_core_dec_fx( set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); Word16 tmps, incr; +#ifdef FIX_1320_STACK_CPE_DECODER + 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 Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; // Q15 Word16 core_switching_flag[CPE_CHANNELS]; @@ -291,6 +296,9 @@ ivas_error ivas_core_dec_fx( set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); 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 + bwe_exc_extended_fx[n] = hb_synth_32_fx[n]; /* note: reuse the buffer */ +#endif /*------------------------------------------------------------------* * Decision matrix (selection of technologies) @@ -1011,9 +1019,18 @@ ivas_error ivas_core_dec_fx( } /* Memories Re-Scaling */ - 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 - 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 +#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 ) ) + { +#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 +#ifdef FIX_1320_STACK_CPE_DECODER + } +#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 IF( hBWE_FD != NULL ) { @@ -1029,9 +1046,18 @@ ivas_error ivas_core_dec_fx( * SWB(FB) BWE decoding *---------------------------------------------------------------------*/ +#ifdef FIX_1320_STACK_CPE_DECODER + 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 + Q_white_exc = 0; move16(); +#ifndef FIX_1320_STACK_CPE_DECODER test(); test(); test(); @@ -1039,6 +1065,7 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); +#endif test(); test(); test(); @@ -1070,7 +1097,11 @@ ivas_error ivas_core_dec_fx( fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); } } +#ifdef FIX_1320_STACK_CPE_DECODER + ELSE IF( st->extl == SWB_BWE || 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 { /* SWB BWE decoder */ Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); @@ -1080,6 +1111,17 @@ ivas_error ivas_core_dec_fx( Copy_Scale_sig_32_16( hBWE_FD->L_old_wtda_swb_fx32, hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); // old_wtda_swb_fx_exp } +#ifdef FIX_1320_STACK_CPE_DECODER + test(); + test(); + test(); + IF( ( st->core == ACELP_CORE && ( st->extl == -1 || st->extl == SWB_CNG ) ) && flag_bwe_bws == 0 ) + { + set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); + } + +#endif + /*---------------------------------------------------------------------* * FEC - recovery after lost HQ core (smoothing of the BWE component) *---------------------------------------------------------------------*/ @@ -1170,6 +1212,7 @@ ivas_error ivas_core_dec_fx( } } +#ifndef FIX_1320_STACK_CPE_DECODER IF( EQ_16( st->element_mode, EVS_MONO ) ) { /*----------------------------------------------------------------* @@ -1200,7 +1243,7 @@ ivas_error ivas_core_dec_fx( move16(); } } - +#endif /*----------------------------------------------------------------* * Transition and synchronization of BWE components *----------------------------------------------------------------*/ @@ -1219,6 +1262,7 @@ ivas_error ivas_core_dec_fx( } ELSE { +#ifndef FIX_1320_STACK_CPE_DECODER test(); IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) { @@ -1227,9 +1271,12 @@ ivas_error ivas_core_dec_fx( } ELSE { +#endif /* TBE on top of ACELP@16kHz */ tmps = NS2SA_FX2( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); +#ifndef FIX_1320_STACK_CPE_DECODER } +#endif } /* Smooth transitions when switching between different technologies */ @@ -1454,8 +1501,12 @@ ivas_error ivas_core_dec_fx( test(); test(); test(); +#ifdef FIX_1320_STACK_CPE_DECODER + IF( st->hTcxDec != NULL && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) +#else test(); IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( ( st->core == ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) +#endif { Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; move16(); @@ -1500,24 +1551,20 @@ ivas_error ivas_core_dec_fx( Scale_sig( st->delay_buf_out_fx, NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); // Q0 - } /* n_channels loop */ - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - IF( st->cldfbAna ) + IF( st->cldfbAna != NULL ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, ( Q11 - Q10 ) ); // Q11 st->cldfbAna->Q_cldfb_state = Q11; move16(); } - IF( st->cldfbSynHB ) + IF( st->cldfbSynHB != NULL ) { scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, ( Q11 - Q10 ) ); // Q11 st->cldfbSynHB->Q_cldfb_state = Q11; move16(); } - } + + } /* n_channels loop */ pop_wmops(); return error; diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 02068c9cfd20c56e5d1a3997ea7359175dea0ea8..a5e71297268f93c900cd7da5eb06ae59d4ec813f 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -51,6 +51,10 @@ static void read_stereo_mode_and_bwidth_fx( CPE_DEC_HANDLE hCPE, const Decoder_S static void stereo_mode_combined_format_dec_fx( const Decoder_Struct *st_ivas, CPE_DEC_HANDLE hCPE ); +#ifdef FIX_1320_STACK_CPE_DECODER +static ivas_error stereo_dft_dec_main( CPE_DEC_HANDLE hCPE, const Word32 ivas_total_brate, const Word16 n_channels, Word32 *p_res_buf_fx, Word32 *output[], Word32 outputHB[][L_FRAME48k], const Word16 output_frame, const Word32 output_Fs ); +#endif + /*--------------------------------------------------------------------------* * ivas_cpe_dec_fx() @@ -71,8 +75,12 @@ ivas_error ivas_cpe_dec_fx( Word16 last_bwidth; Word16 tdm_ratio_idx; Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */ +#ifdef FIX_1320_STACK_CPE_DECODER + Word32 *res_buf_fx = NULL; /* Q8 */ +#else Word16 q_res_buf; - Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */ + Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */ +#endif CPE_DEC_HANDLE hCPE; STEREO_DFT_CONFIG_DATA_HANDLE hConfigDft; Decoder_State **sts; @@ -84,8 +92,10 @@ ivas_error ivas_cpe_dec_fx( error = IVAS_ERR_OK; move32(); +#ifndef FIX_1320_STACK_CPE_DECODER q_res_buf = Q8; move16(); +#endif push_wmops( "ivas_cpe_dec" ); @@ -345,6 +355,10 @@ ivas_error ivas_cpe_dec_fx( } ELSE { +#ifdef FIX_1320_STACK_CPE_DECODER + res_buf_fx = outputHB_fx[0]; /* note: temporarily reused buffer */ + +#endif test(); IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { @@ -613,6 +627,12 @@ ivas_error ivas_cpe_dec_fx( test(); IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hConfigDft->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { +#ifdef FIX_1320_STACK_CPE_DECODER + IF( NE_32( ( error = stereo_dft_dec_main( hCPE, ivas_total_brate, n_channels, res_buf_fx, output, outputHB_fx, output_frame, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; // q_dft set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX ); set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); @@ -777,6 +797,7 @@ ivas_error ivas_cpe_dec_fx( hCPE->q_output_mem_fx[n] = Q11; move16(); } +#endif } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { @@ -816,7 +837,6 @@ ivas_error ivas_cpe_dec_fx( * Update parameters for stereo CNA *----------------------------------------------------------------*/ - // stereo_cna_update_params( hCPE, output_flt, output_frame, tdm_ratio_idx ); stereo_cna_update_params_fx( hCPE, output, output_frame, tdm_ratio_idx ); /*----------------------------------------------------------------* @@ -850,7 +870,6 @@ ivas_error ivas_cpe_dec_fx( stereo_tca_dec_fx( hCPE, output, output_frame ); - /*----------------------------------------------------------------* * Common Stereo updates *----------------------------------------------------------------*/ @@ -882,6 +901,205 @@ ivas_error ivas_cpe_dec_fx( return error; } +#ifdef FIX_1320_STACK_CPE_DECODER + +/*------------------------------------------------------------------------- + * stereo_dft_dec_main() + * + * DFT decoder main function + *-------------------------------------------------------------------------*/ + +static ivas_error stereo_dft_dec_main( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 n_channels, /* i : number of channels to be decoded */ + Word32 *p_res_buf_fx, /* i : DFT stereo residual S signal */ + Word32 *output[], /* o : output synthesis signal */ + Word32 outputHB_fx[][L_FRAME48k], /* o : output HB synthesis signal */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word32 output_Fs /* i : output sampling rate */ +) +{ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; + Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */ + Word16 n; + Word16 q_res_buf, q_dft; + Decoder_State *st0; + ivas_error error; + Word16 shift; + Word32 tmp1, tmp2; + Word16 shift1, shift2; + + st0 = hCPE->hCoreCoder[0]; + + q_res_buf = Q8; + move16(); + + set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX ); + set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); + + /* copy from temporary buffer */ + test(); + IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st0->bfi ) + { + Copy32( p_res_buf_fx, res_buf_fx, STEREO_DFT_N_8k ); + } + + /* core decoder */ + IF( NE_32( ( error = ivas_core_dec_fx( NULL, NULL, hCPE, NULL, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* Scaling of DFT's */ + maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 ); + maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 ); + + IF( tmp1 == 0 ) + { + shift1 = Q31; + move16(); + } + ELSE + { + shift1 = norm_l( tmp1 ); + } + IF( tmp2 == 0 ) + { + shift2 = Q31; + move16(); + } + ELSE + { + shift2 = norm_l( tmp2 ); + } + shift = s_min( shift1, shift2 ); + + IF( NE_16( shift, 31 ) ) + { + shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q16 ); /* Q16 for guard bits */ + + IF( GT_16( shift, hCPE->hStereoDft->q_dft ) ) + { + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift + hCPE->hStereoDft->q_dft = shift; + move16(); + } + } + ELSE + { + hCPE->hStereoDft->q_dft = Q8; + move16(); + } + + /* DFT Stereo residual decoding */ + test(); + IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st0->bfi ) + { + Word16 q; + Word16 q_out_DFT[2]; + + q = Q11; + move16(); + + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), -( Q10 ) ); // Q16->Q6 + + stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] ); + + Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), 10 ); // Q6->Q16 + + Scale_sig32( output[1], L_FRAME8k, ( Q11 - Q15 ) ); // Q15 -> Q11 + + q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft; + move16(); + move16(); + + stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT ); + + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); // q_dft + } + + /* DFT stereo CNG */ + q_dft = hCPE->hStereoDft->q_dft; + move16(); + stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft ); + + /* decoding */ + IF( EQ_16( hCPE->nchan_out, 1 ) ) + { + IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) + { + hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; + move16(); + FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) + { + hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + move16(); + } + hCPE->hStereoDft->first_frame = 0; + move16(); + } + + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft + hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; + move16(); + stereo_dft_unify_dmx_fx( hCPE->hStereoDft, st0, DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata ); + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15 + hCPE->hStereoDft->q_res_cod_mem_fx = Q15; + move16(); + } + ELSE + { + IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) + { + hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; + move16(); + FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) + { + hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + move16(); + } + hCPE->hStereoDft->first_frame = 0; + move16(); + } + + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft + hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; + move16(); + + stereo_dft_dec_fx( hCPE->hStereoDft, st0, DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15 + hCPE->hStereoDft->q_res_cod_mem_fx = Q15; + move16(); + } + + FOR( n = 0; n < hCPE->nchan_out; n++ ) + { + Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft + hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft; + move16(); + } + + /* synthesis iFFT */ + FOR( n = 0; n < hCPE->nchan_out; n++ ) + { + stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame ); + } + + FOR( n = 0; n < hCPE->nchan_out; n++ ) + { + Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11 + hCPE->q_output_mem_fx[n] = Q11; + move16(); + } + + return IVAS_ERR_OK; +} + +#endif /*------------------------------------------------------------------------- * create_cpe_dec_fx() diff --git a/lib_dec/ivas_mdct_core_dec_fx.c b/lib_dec/ivas_mdct_core_dec_fx.c index 4e080bb2fe4e9fb3615a1ca5a7e7d81a6c6f68ed..40dac596b25fb10ffc9fe1153d9e108cebb04019 100644 --- a/lib_dec/ivas_mdct_core_dec_fx.c +++ b/lib_dec/ivas_mdct_core_dec_fx.c @@ -1085,23 +1085,27 @@ void ivas_mdct_core_invQ_fx( *-----------------------------------------------------------------*/ void ivas_mdct_core_reconstruct_fx( - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *x_fx[][NB_DIV], - /* i/o: synthesis @internal_FS */ // Q(q_x) - Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME_PLUS], - /* o : synthesis @output_FS */ // e_sig - Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ - const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 *x_fx[][NB_DIV], /* i/o: synthesis @internal_FS Q(q_x) */ + Word16 signal_outFB_fx[CPE_CHANNELS][L_FRAME_PLUS], /* o : synthesis @output_FS e_sig */ + Word16 fUseTns[CPE_CHANNELS][NB_DIV], /* i : flage TNS enabled */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0)*/ Word16 q_x, Word16 e_sig[CPE_CHANNELS] ) { Word16 ch, k, bfi; Decoder_State **sts, *st; + /* Framing */ Word16 L_frame[CPE_CHANNELS], L_frameTCX[CPE_CHANNELS], nSubframes[CPE_CHANNELS]; Word16 L_frame_global[CPE_CHANNELS], L_frame_globalTCX[CPE_CHANNELS]; + /* Synth */ +#ifdef FIX_1320_STACK_CPE_DECODER + Word16 synth_buf_fx[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M]; +#else Word16 synth_buf_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; +#endif Word16 *synth_fx; Word16 synth_bufFB_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB_fx; @@ -1109,6 +1113,7 @@ void ivas_mdct_core_reconstruct_fx( move16(); Word16 q_win = 0; Word16 q_winFB = 0; + /* TCX */ Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; // Q(-2) Word16 tcx_offset[CPE_CHANNELS]; @@ -1171,7 +1176,11 @@ void ivas_mdct_core_reconstruct_fx( } q_syn = st->hTcxDec->q_old_synth; move16(); +#ifdef FIX_1320_STACK_CPE_DECODER + set16_fx( synth_fx, 0, L_FRAME_PLUS_INTERNAL + M ); +#else set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); +#endif set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); IF( st->core != ACELP_CORE ) { diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index 8a1d339d427537c73ec2be05c7d8ff4b856aacf6..b2a894a34286b4c3a56972f9b2849ebc849c4d48 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -176,7 +176,7 @@ void stereo_mdct_core_dec_fx( Word16 x_len[CPE_CHANNELS][NB_DIV]; /*needed to allocate N_MAX to prevent stereo switching crash */ - Word32 x_0_buf_fx[CPE_CHANNELS][N_MAX]; + Word32 x_0_buf_fx[CPE_CHANNELS][N_MAX]; /* note: in FLP, this buffer is shared with signal_outFB_tmp_fx[][] */ Word32 *x_0_fx[CPE_CHANNELS][NB_DIV]; /* Concealment */ @@ -229,6 +229,7 @@ void stereo_mdct_core_dec_fx( set32_fx( x_0_buf_fx[ch], 0, N_MAX ); x_0_fx[ch][0] = &x_0_buf_fx[ch][0]; x_0_fx[ch][1] = &x_0_buf_fx[ch][0] + L_FRAME48k / 2; + nTnsBitsTCX10[ch][0] = 0; move16(); nTnsBitsTCX10[ch][1] = 0; diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 0be01f7b88612b359fb0b5b88b1fda3028fdeceb..81b67ec10b994dec97c8656a0c502079912cba02 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -228,7 +228,11 @@ void stereo_tcx_core_dec_fx( Word16 pit_gain_fx[NB_SUBFR16k]; /*Synth*/ +#ifdef FIX_1320_STACK_CPE_DECODER + Word16 synth_buf_fx[OLD_SYNTH_INTERNAL_DEC + L_FRAME_PLUS_INTERNAL + M]; +#else Word16 synth_buf_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; +#endif Word16 *synth_fx; Word16 synth_bufFB_fx[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; Word16 *synthFB_fx; @@ -302,7 +306,11 @@ void stereo_tcx_core_dec_fx( synthFB_fx = synth_bufFB_fx + hTcxDec->old_synth_lenFB; Copy_Scale_sig( hTcxDec->old_synth, synth_buf_fx, hTcxDec->old_synth_len, negate( st->Q_syn ) ); /* q_old_synth - st->Q_syn */ Copy( hTcxDec->old_synthFB_fx, synth_bufFB_fx, hTcxDec->old_synth_lenFB ); /* q_old_synthFB */ +#ifdef FIX_1320_STACK_CPE_DECODER + set16_fx( synth_fx, 0, L_FRAME_PLUS_INTERNAL + M ); +#else set16_fx( synth_fx, 0, L_FRAME_PLUS + M ); +#endif set16_fx( synthFB_fx, 0, L_FRAME_PLUS + M ); /*--------------------------------------------------------------------------------*