diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index 5d66ffed2cb23fd18ca2b50b3bca732ccb1fa900..55b662e8dc722c78218d63a88c4e06335f2ababc 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -1914,6 +1914,36 @@ void deleteCldfb_ivas( return; } +#ifdef IVAS_FLOAT_FIXED +void deleteCldfb_ivas_fx( + HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ +) +{ + HANDLE_CLDFB_FILTER_BANK hs = *h_cldfb; + + IF ( h_cldfb == NULL || *h_cldfb == NULL ) + { + return; + } + + IF ( hs->cldfb_state_fx ) + { + free( hs->cldfb_state_fx ); + } +#ifdef IVAS_FLOAT_FIXED // TODO : Will be removed later + IF ( hs->cldfb_state ) + { + free( hs->cldfb_state ); + } +#endif + + free( hs ); + *h_cldfb = NULL; + + return; +} +#endif + /*-------------------------------------------------------------------* * cldfb_init_proto_and_twiddles() diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 071738534c32b6eb26feccebd5d39480b36664c4..fd8692341c714a84d02be1a165f1b25ae0e0566e 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1661,3 +1661,26 @@ void ivas_DetectTonalComponents_fx( const PsychoacousticParameters* psychParamsCurrent ); #endif + +ivas_error stereo_dft_dec_create_fx( + STEREO_DFT_DEC_DATA_HANDLE *hStereoDft, /* i/o: decoder DFT stereo handle */ + const Word32 element_brate, /* i : element bitrate */ + const Word32 output_Fs, /* i : output sampling rate */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + const Word16 nchan_transport /* i : number of transport channels */ +); + +void stereo_cng_init_dec_fx( + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ + const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ +); + +ivas_error stereo_memory_dec_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + const Word32 output_Fs, /* i : output sampling rate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ + const Word16 nchan_transport /* i : number of transport channels*/ +); diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 9dda9c2ae07a63bc90479331356227188db42fbb..f8167bd317bd60d4a75da44786ed02b273c5bf41 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -8875,3 +8875,17 @@ void configureFdCngDec( const Word16 element_mode ); #endif + +void deleteCldfb_ivas_fx( + HANDLE_CLDFB_FILTER_BANK *h_cldfb /* i/o: filter bank handle */ +); + +void fd_bwe_dec_init_fx( + FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ +); + +void stereo_dft_dec_open( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ + const int32_t output_Fs, /* i : output sampling rate */ + const int16_t nchan_transport /* i : number of transport channels */ +); diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 38cc8afaf6a7a80e530722cd2896460175050ddc..c0171dbb328ac702c1d087d998a9a27078b682e6 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -387,8 +387,8 @@ void window_ola_fx( } FOR (i =0; i < n; i+=2) { - *p1++=round_fx(L_sub(L_deposit_h(*p4++),L_shl(*pa--,1))); - *p1++=round_fx(L_sub(L_deposit_h(*p4++),L_shl(*pa--,1))); + *p1++=round_fx_sat(L_sub_sat(L_deposit_h(*p4++),L_shl(*pa--,1))); + *p1++=round_fx_sat(L_sub_sat(L_deposit_h(*p4++),L_shl(*pa--,1))); /* paout[L/2 + i +1] = -ImdctOut[L - 1 - (i+1)]+OldauOut[i+L/2+1] ; paout[L/2 + i ] = -ImdctOut[L - 1 - i]+OldauOut[i+L/2]; */ } @@ -463,7 +463,7 @@ void window_ola_fx( } FOR (i =0; i < n; i++) { - *p1++=round_fx(L_sub_sat(L_deposit_h(*p4++),L_shl(*pa--,1))); + *p1++=round_fx_sat(L_sub_sat(L_deposit_h(*p4++),L_shl(*pa--,1))); /* paout[L/2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i+L/2]; */ } } diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 8abec2c7c1b51cd1ee5ce63f1c3c409f55ceb1c4..4dc07db54b5f64ff51dacea97d76ca78894fa5ce 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1210,6 +1210,10 @@ void HQ_core_dec_init( set16_fx(hHQ_core->old_out_fx, 0, L_FRAME48k); set16_fx(hHQ_core->old_out_LB_fx, 0, L_FRAME32k); +#ifdef IVAS_FLOAT_FIXED + set32_fx(hHQ_core->oldOut_fx, 0, L_FRAME48k); + set32_fx(hHQ_core->old_outLB_fx, 0, L_FRAME32k); +#endif hHQ_core->Q_old_wtda = 15; hHQ_core->Q_old_postdec = 0; hHQ_core->Q_old_wtda_LB = 0; diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index e64c0489c046eb8049eeeeb912b9c73efce825d2..1d8b37bd2da74ea717a4720780cecd7b377a582b 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -132,10 +132,170 @@ ivas_error ivas_cpe_dec_fx( * dynamically allocate data structures depending on the actual stereo mode *----------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED IF( ( error = stereo_memory_dec( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) { return error; } +#else +#if 1 // Float to fix conversions + float maxim = 0; + Word16 q_output_mem, q_buff_LBTCX_mem, q_input_mem_LB, q_old_out = 31, q_old_out_LB = 31, q_tcxltp_mem_in_float=15, q_tcxltp_gain_post_prev = 15; + q_output_mem = 11; + IF(hCPE->hStereoDft) + FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { + FOR(Word16 ind2 = 0; ind2 < s_max(hCPE->hStereoDft->dft32ms_ovl, hCPE->hStereoDft->dft32ms_ovl - NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS )); ind2++) { + hCPE->output_mem_fx[ind1][ind2] = (Word32)(hCPE->output_mem[ind1][ind2] * (1<hStereoDft) + FOR(Word16 ind1 = 0; ind1 < s_min(50, NS2SA( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS )); ind1++) { + hCPE->hStereoDft->buff_LBTCX_mem_fx[ind1] = (Word32)(hCPE->hStereoDft->buff_LBTCX_mem[ind1] * (1<hStereoDft && hCPE->input_mem_LB[0] && NE_16(hCPE->hCoreCoder[0]->last_core, ACELP_CORE)) + FOR(Word16 ind1 = 0; ind1 < s_min(NS2SA( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), 50); ind1++) { + hCPE->input_mem_LB_fx[0][ind1] = (Word32)(hCPE->input_mem_LB[0][ind1] * (1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) + FOR(Word16 ind2 = 0; ind2 < st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC; ind2++) { + maxim = fmaxf(fabsf(hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2]), maxim); + } + } + IF (maxim > 1.f) q_old_out = norm_l((Word32)maxim); + q_old_out -= 1; + FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { + IF(hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) + FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { + hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx[ind2] = (Word32)(hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2] * (1<hCoreCoder[ind1]->hHQ_core) + FOR(Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++) { + maxim = fmaxf(fabsf(hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2]), maxim); + } + } + IF (maxim > 1.f) q_old_out_LB = norm_l((Word32)maxim); + q_old_out_LB -= 1; + FOR(Word16 ind1 = 0; ind1 < 1; ind1++) { + IF(hCPE->hCoreCoder[ind1]->hHQ_core) + FOR(Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++) { + hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx[ind2] = (Word32)(hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2] * (1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[ind] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[ind] * (1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) { + IF(fabsf(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float) > 1) assert(0);//q_tcxltp_gain_post_prev = norm_s(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * (1 << q_tcxltp_gain_post_prev)); + } + FOR(Word16 ind2 = 0; ind2 < 2; ind2++) { + IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)(TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { + hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_32[ind] = (Word32)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_float[ind] * (1 << q_tcxltp_mem_in_float)); + } + IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)(L_FRAME48k * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { + hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1 << q_tcxltp_mem_in_float)); + } + IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) { + IF(fabsf(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float) > 1) assert(0);//q_tcxltp_gain_post_prev = norm_s(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float); + hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float * (1 << q_tcxltp_gain_post_prev)); + } + IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->cldfbSyn) + hCPE->hCoreCoder[ind2]->cldfbSyn->scale = (Word16)(hCPE->hCoreCoder[ind2]->cldfbSyn->scale_flt * (1u << norm_s((Word16)hCPE->hCoreCoder[0]->cldfbSyn->scale_flt))); + } + IF(hCPE->hStereoMdct) + hCPE->hStereoMdct->smooth_ratio_fx = (Word32)(hCPE->hStereoMdct->smooth_ratio * (ONE_IN_Q26)); + FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { + IF(hCPE->hCoreCoder[0] && hCPE->hCoreCoder[0]->hTcxDec) + hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_32[ind] = (Word32)(hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_float[ind] * (ONE_IN_Q11)); + IF(hCPE->hCoreCoder[1] && hCPE->hCoreCoder[1]->hTcxDec) + hCPE->hCoreCoder[1]->hTcxDec->old_syn_Overl_32[ind] = (Word32)(hCPE->hCoreCoder[1]->hTcxDec->old_syn_Overl_float[ind] * (ONE_IN_Q11)); + } + IF(hCPE->hStereoTD) + FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { + hCPE->hStereoTD->TCX_old_syn_Overl_fx[ind] = (Word32)(hCPE->hStereoTD->TCX_old_syn_Overl[ind] * (ONE_IN_Q11)); + } + +#endif // Float to fix conversions + + IF( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + { + return error; + } +#if 1 // Fix to float conversions + IF(hCPE->hStereoDft) + FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { + FOR(Word16 ind2 = 0; ind2 < s_max(hCPE->hStereoDft->dft32ms_ovl, hCPE->hStereoDft->dft32ms_ovl - NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS )); ind2++) { + hCPE->output_mem[ind1][ind2] = (float)hCPE->output_mem_fx[ind1][ind2] / (float)(1<input_mem_LB[0]) + FOR(Word16 ind1 = 0; ind1 < s_min(NS2SA( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ), 50); ind1++) { + hCPE->input_mem_LB[0][ind1] = (float)(hCPE->input_mem_LB_fx[0][ind1]) / (float)(1<hStereoDft) + FOR(Word16 ind1 = 0; ind1 < s_min(NS2SA( s_min( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, 16000 ), STEREO_DFT32MS_OVL_NS ), 50); ind1++) { + hCPE->hStereoDft->buff_LBTCX_mem[ind1] = (float)(hCPE->hStereoDft->buff_LBTCX_mem_fx[ind1]) / (float)(1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) + FOR(Word16 ind2 = 0; ind2 < 960; ind2++) { + hCPE->hCoreCoder[ind1]->hHQ_core->old_out[ind2] = (float)(hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx[ind2]) / (1<hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core) + FOR(Word16 ind2 = 0; ind2 < L_FRAME32k; ind2++) { + hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB[ind2] = (float)(hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx[ind2]) / (1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[ind] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[ind] / (float)(1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / (float)(1 << q_tcxltp_gain_post_prev); + FOR(Word16 ind2 = 0; ind2 < 2; ind2++) { + IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { + hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_float[ind] = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_in_32[ind] / (float)(1<hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) + FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { + hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) + hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev / (float)(1 << q_tcxltp_gain_post_prev); + } + IF(hCPE->hStereoMdct) + hCPE->hStereoMdct->smooth_ratio = hCPE->hStereoMdct->smooth_ratio_fx / (float)(ONE_IN_Q26); + FOR(Word16 ind = 0; ind < L_FRAME16k / 2; ind++) { + IF(hCPE->hCoreCoder[0] && hCPE->hCoreCoder[0]->hTcxDec) + hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_float[ind] = (float)hCPE->hCoreCoder[0]->hTcxDec->old_syn_Overl_32[ind] / (float)(ONE_IN_Q11); + IF(hCPE->hCoreCoder[1] && hCPE->hCoreCoder[1]->hTcxDec) + hCPE->hCoreCoder[1]->hTcxDec->old_syn_Overl_float[ind] = (float)hCPE->hCoreCoder[1]->hTcxDec->old_syn_Overl_32[ind] / (float)(ONE_IN_Q11); + } +#endif // Fix to float conversions +#endif /*------------------------------------------------------------------* * Initialization diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 81021a248b2d6391769d6b27e592cc5dc46ec585..a748116f40df8a2700448e72ea2d8ee092ff141b 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -377,8 +377,10 @@ typedef struct stereo_dec_cng Word32 olapBufferSynth22_32fx[FFTLEN]; /* overlap buffer for secondary channel CNA */ int16_t flag_cna_fade; /* flag enabling CNA fade out */ float maskingNoiseS[L_FRAME16k]; /* masking noise (CNA) for secondary channel */ + Word16 maskingNoiseS_fx[L_FRAME16k]; /* masking noise (CNA) for secondary channel */ int16_t enableSecCNA; /* flag enabling secondary channel CNA */ float c_PS_LT; /* long term cross-correlation between primary and secondary channel */ + Word16 c_PS_LT_fx; /* long term cross-correlation between primary and secondary channel */ // Assumed Q15 for initialization. Can be modified later if reqd. const int16_t *frameSize; /* Frame size in samples */ const int16_t *fftlen; /* FFT length used for the decomposition */ diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index f5fd395a10f4c19d6c372b3226d6479813000e87..07a74facabfe2e5b2062fa36328ee1b998532a49 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -1575,3 +1575,51 @@ void stereo_cng_init_dec( return; } +#ifdef IVAS_FLOAT_FIXED +void stereo_cng_init_dec_fx( + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: stereo CNG decoder structure */ + const Word16 *frameSize /* i : pointer to frameSize of channel 0 to be used for channel 1 */ +) +{ + hStereoCng->prev_sid_nodata = 0; + move16(); + set16_fx( hStereoCng->coh_fx, 8192 /*0.5 in Q14*/, STEREO_DFT_BAND_MAX + 1 ); + set16_fx( hStereoCng->cm_fx, 0, STEREO_DFT_BAND_MAX ); + hStereoCng->first_SID = 1; + move16(); + hStereoCng->first_SID_after_TD = 0; + move16(); + hStereoCng->active_frame_counter = 0; + move16(); + hStereoCng->xfade_frame_counter = 0; + move16(); + hStereoCng->xfade_length = 0; + move16(); + hStereoCng->nr_dft_frames = 0; + move16(); + hStereoCng->nr_corr_frames = 0; + move16(); + hStereoCng->nr_sid_frames = 0; + move16(); + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, FFTLEN ); + hStereoCng->flag_cna_fade = 0; + move16(); + set16_fx( hStereoCng->maskingNoiseS_fx, 0, L_FRAME16k ); + hStereoCng->enableSecCNA = 0; + move16(); + hStereoCng->c_PS_LT_fx = 16384; /* 0.5 in Q15 */ + hStereoCng->frameSize = frameSize; + move16(); + hStereoCng->last_act_element_mode = IVAS_CPE_DFT; + move16(); + +#if 1 + set_f( hStereoCng->olapBufferSynth22, 0.0f, FFTLEN ); + set_f( hStereoCng->coh, 0.5f, STEREO_DFT_BAND_MAX + 1 ); + set_zero( hStereoCng->cm, STEREO_DFT_BAND_MAX ); + hStereoCng->c_PS_LT = 0.5f; +#endif + + return; +} +#endif diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index fb45472e2681ce1f26cf33991e386cbb81688d10..f79052c2ed156d9973c7451e411875be885b3405 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -79,9 +79,6 @@ /*------------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------------*/ - -static void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const int32_t output_Fs, const int16_t nchan_transport ); - static void stereo_dft_compute_td_stefi_params( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const float samp_ratio ); static void stereo_dft_adapt_sf_delay( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, float *pPredGain ); @@ -373,7 +370,7 @@ ivas_error stereo_dft_dec_create( *-------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -static void stereo_dft_dec_open( +void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ const Word32 output_Fs, /* i : output sampling rate */ const Word16 nchan_transport /* i : number of transport channels */ @@ -501,7 +498,7 @@ static void stereo_dft_dec_open( return; } #else -static void stereo_dft_dec_open( +void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: decoder DFT stereo handle */ const int32_t output_Fs, /* i : output sampling rate */ const int16_t nchan_transport /* i : number of transport channels */ @@ -976,19 +973,19 @@ void stereo_dft_dec_destroy( hStereoDft = *hStereoDft_glob; - if ( hStereoDft->hConfig != NULL ) + IF ( hStereoDft->hConfig != NULL ) { free( hStereoDft->hConfig ); hStereoDft->hConfig = NULL; } - if ( hStereoDft->hBpf != NULL ) + IF ( hStereoDft->hBpf != NULL ) { free( hStereoDft->hBpf ); hStereoDft->hBpf = NULL; } - if ( hStereoDft->hTcxLtpDec != NULL ) + IF ( hStereoDft->hTcxLtpDec != NULL ) { free( hStereoDft->hTcxLtpDec ); hStereoDft->hTcxLtpDec = NULL; diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 8258b053fffa966d040972e16dbea681d24dbc20..e5e3ea8ef1797e80c165685894087b9804981d34 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -81,12 +81,6 @@ * Local function prototypes *-------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -static void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const Word32 output_Fs, const Word16 nchan_transport ); -#else -static void stereo_dft_dec_open( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const int32_t output_Fs, const int16_t nchan_transport ); -#endif - static void stereo_dft_compute_td_stefi_params_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, const Word16 samp_ratio ); static void stereo_dft_adapt_sf_delay_fx( STEREO_DFT_DEC_DATA_HANDLE hStereoDft, Word32 *pPredGain ); @@ -392,6 +386,10 @@ ivas_error stereo_dft_dec_create_fx( stereo_dft_dec_open_fx( hStereoDft_loc, output_Fs, nchan_transport ); +#if 1 // TODO: To be removed later + stereo_dft_dec_open( hStereoDft_loc, output_Fs, nchan_transport ); +#endif + *hStereoDft = hStereoDft_loc; return IVAS_ERR_OK; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index 83f386817b788f82315b0a3879c40eb3ccacf9df..3f840e6a70bde0aeb4b3a4d2a5f88b24e99b80e8 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -132,6 +132,97 @@ static ivas_error allocate_CoreCoder_TCX( return IVAS_ERR_OK; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error allocate_CoreCoder_TCX_fx( + DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ +) +{ + IF ( st->hTcxDec == NULL ) + { + IF ( ( st->hTcxDec = (TCX_DEC_HANDLE) malloc( sizeof( TCX_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for hTcxDec" ) ); + } + + reset_tcx_overl_buf_fx( st->hTcxDec ); + + set16_fx( st->hTcxDec->syn_OverlFB, 0, L_FRAME48k / 2 ); + set16_fx( st->hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); + set16_fx( st->hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME48k ); + +#if 1 // TODO: TO be removed later + reset_tcx_overl_buf( st->hTcxDec ); + set_zero( st->hTcxDec->syn_OverlFB_float, L_FRAME48k / 2 ); + set_zero( st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC ); + set_zero( st->hTcxDec->synth_history, L_PROT48k + L_FRAME48k ); +#endif + } + + IF ( st->hTcxCfg == NULL ) + { + IF ( ( st->hTcxCfg = (TCX_CONFIG_HANDLE) malloc( sizeof( TCX_config ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for hTcxCfg" ) ); + } + } + + /* allocated TCX-LTP structure for second channel */ + IF ( st->hTcxLtpDec == NULL ) + { + IF ( ( st->hTcxLtpDec = (TCX_LTP_DEC_HANDLE) malloc( sizeof( TCX_LTP_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for TCX-LTP handle\n" ) ); + } + + tcxltp_dec_init_fx( st->hTcxLtpDec, 0, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core ); + +#if 1 // TODO: TO be removed later + tcxltp_dec_init( st->hTcxLtpDec, 0, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core ); +#endif + } + + /* allocate HQ structure */ + IF ( st->hHQ_core == NULL ) + { + IF ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for HQ core\n" ) ); + } + + HQ_core_dec_init( st->hHQ_core ); +#if 1 // TODO: To be removed later + HQ_core_dec_init_flt( st->hHQ_core ); +#endif + } + + IF ( st->hIGFDec == NULL ) + { + IF ( ( st->hIGFDec = (IGF_DEC_INSTANCE_HANDLE) malloc( sizeof( IGFDEC_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IGF\n" ) ); + } + + st->igf = 0; + move16(); + init_igf_dec( st->hIGFDec ); + } + + IF ( st->hTonalMDCTConc == NULL ) + { + IF ( ( st->hTonalMDCTConc = (TonalMDCTConcealPtr) malloc( sizeof( TonalMDCTConceal_INSTANCE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for TonalMDCTConcealment\n" ) ); + } + } + + st->last_con_tcx = 0; + move16(); + st->hTonalMDCTConc->nSamples = 0; + move16(); + + return IVAS_ERR_OK; +} +#endif /*-------------------------------------------------------------------* * Function allocate_CoreCoder() @@ -219,6 +310,110 @@ static ivas_error allocate_CoreCoder( return error; } +#ifdef IVAS_FLOAT_FIXED +static ivas_error allocate_CoreCoder_fx( + DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ +) +{ + ivas_error error; + + error = IVAS_ERR_OK; + + IF ( st->hGSCDec == NULL ) + { + IF ( ( st->hGSCDec = (GSC_DEC_HANDLE) malloc( sizeof( GSC_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); + } + + GSC_dec_init( st->hGSCDec ); + +#if 1 // TODO: To be removed later + GSC_dec_init_ivas( st->hGSCDec ); +#endif + } + + IF ( st->hPFstat == NULL ) + { + IF ( ( st->hPFstat = (PFSTAT_HANDLE) malloc( sizeof( PFSTAT ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); + } + + Init_post_filter( st->hPFstat ); + st->psf_lp_noise_fx = 0; + move16(); + +#if 1 // TODO: To be removed later + Init_post_filter_ivas( st->hPFstat ); + st->psf_lp_noise = 0.0f; +#endif + } + + IF ( st->hMusicPF == NULL ) + { + IF ( ( st->hMusicPF = (MUSIC_POSTFILT_HANDLE) malloc( sizeof( MUSIC_POSTFILT_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LD music postflter\n" ) ); + } + + music_postfilt_init( st->hMusicPF ); + +#if 1 // TODO: To be removed later + music_postfilt_init_flt( st->hMusicPF ); +#endif + } + + IF ( st->hBPF == NULL ) + { + IF ( ( st->hBPF = (BPF_DEC_HANDLE) malloc( sizeof( BPF_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for BPF\n" ) ); + } + + bass_psfilter_init_fx( st->hBPF ); + +#if 1 // TODO: To be removed later + bass_psfilter_init( st->hBPF ); +#endif + } + + IF ( st->hBWE_zero == NULL ) + { + IF ( ( st->hBWE_zero = (ZERO_BWE_DEC_HANDLE) malloc( sizeof( ZERO_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n" ) ); + } + + hf_synth_init_fx( st->hBWE_zero ); + +#if 1 // TODO: To be removed later + hf_synth_init( st->hBWE_zero ); +#endif + } + + IF ( st->cldfbAna == NULL ) + { + /* open analysis for max. sampling rate 48kHz */ + IF ( ( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + IF ( st->cldfbBPF == NULL ) + { + /* open analysis BPF for max. internal sampling rate 16kHz */ + IF ( ( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + return error; +} +#endif + /*-------------------------------------------------------------------* * Function deallocate_CoreCoder_TCX() @@ -230,25 +425,25 @@ static void deallocate_CoreCoder_TCX( DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ ) { - if ( st->hTcxDec != NULL ) + IF ( st->hTcxDec != NULL ) { free( st->hTcxDec ); st->hTcxDec = NULL; } - if ( st->hTcxCfg != NULL ) + IF ( st->hTcxCfg != NULL ) { free( st->hTcxCfg ); st->hTcxCfg = NULL; } - if ( st->hIGFDec != NULL ) + IF ( st->hIGFDec != NULL ) { free( st->hIGFDec ); st->hIGFDec = NULL; } - if ( st->hTonalMDCTConc != NULL ) + IF ( st->hTonalMDCTConc != NULL ) { free( st->hTonalMDCTConc ); st->hTonalMDCTConc = NULL; @@ -312,7 +507,56 @@ static void deallocate_CoreCoder( return; } +#ifdef IVAS_FLOAT_FIXED +static void deallocate_CoreCoder_fx( + DEC_CORE_HANDLE st /* i/o: Core decoder state structure */ +) +{ + IF ( st->hGSCDec != NULL ) + { + free( st->hGSCDec ); + st->hGSCDec = NULL; + } + + IF ( st->hPFstat != NULL ) + { + free( st->hPFstat ); + st->hPFstat = NULL; + } + + IF ( st->hMusicPF != NULL ) + { + free( st->hMusicPF ); + st->hMusicPF = NULL; + } + IF ( st->hBPF != NULL ) + { + free( st->hBPF ); + st->hBPF = NULL; + } + + IF ( st->hBWE_zero != NULL ) + { + free( st->hBWE_zero ); + st->hBWE_zero = NULL; + } + + /* CLDFB BPF & resampling tools */ + IF ( NE_16(st->element_mode, IVAS_CPE_MDCT) ) + { + deleteCldfb_ivas_fx( &st->cldfbAna ); /* delete analysis at max. sampling rate 48kHz */ + deleteCldfb_ivas_fx( &st->cldfbBPF ); /* delete analysis BPF at max. internal sampling rate 16kHz */ + } + + IF ( NE_16(st->element_mode, IVAS_CPE_MDCT) ) + { + deallocate_CoreCoder_TCX( st ); + } + + return; +} +#endif /*-------------------------------------------------------------------* * Function cpy_tcx_ltp_data() @@ -337,6 +581,34 @@ static void cpy_tcx_ltp_data( return; } +#ifdef IVAS_FLOAT_FIXED +static void cpy_tcx_ltp_data_fx( + TCX_LTP_DEC_HANDLE hTcxLtpDecOld, /* i : TCX-LTP structure to copy from */ + TCX_LTP_DEC_HANDLE hTcxLtpDecNew, /* o : TCX-LTP structure to copy to */ + const int32_t output_Fs /* i : output sampling rate */ +) +{ + Word16 sz, e; + hTcxLtpDecNew->tcxltp_pitch_int_post_prev = hTcxLtpDecOld->tcxltp_pitch_int_post_prev; + move16(); + hTcxLtpDecNew->tcxltp_pitch_fr_post_prev = hTcxLtpDecOld->tcxltp_pitch_fr_post_prev; + move16(); + hTcxLtpDecNew->tcxltp_gain_post_prev = hTcxLtpDecOld->tcxltp_gain_post_prev; + move16(); + hTcxLtpDecNew->tcxltp_filt_idx_prev = hTcxLtpDecOld->tcxltp_filt_idx_prev; + move16(); + sz = BASOP_Util_Divide3232_Scale(TCXLTP_MAX_DELAY * output_Fs, 48000, &e); + sz = shr(sz, sub(15, e)); + mvs2s( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later + mvl2l( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); + sz = BASOP_Util_Divide3232_Scale(( L_FRAME48k * output_Fs ), 48000, &e); + sz = shr(sz, sub(15, e)); + mvs2s( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later + mvl2l( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); + + return; +} +#endif /*-------------------------------------------------------------------* @@ -1099,6 +1371,765 @@ ivas_error stereo_memory_dec( return error; } +#ifdef IVAS_FLOAT_FIXED +ivas_error stereo_memory_dec_fx( + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + CPE_DEC_HANDLE hCPE, /* i : CPE decoder structure */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + const Word32 output_Fs, /* i : output sampling rate */ + const IVAS_FORMAT ivas_format, /* i : IVAS format */ + const MC_MODE mc_mode, /* i : MC mode */ + const Word16 nchan_transport /* i : number of transport channels*/ +) +{ + DEC_CORE_HANDLE st; + Word16 i, n, delay_comp_DFT; + ivas_error error; + Word16 div_m, div_e; + + error = IVAS_ERR_OK; + + assert( GE_16(hCPE->last_element_mode, IVAS_CPE_DFT) && "Switching from SCE to CPE is not a valid configuration!" ); + + + hCPE->hCoreCoder[0]->element_mode = hCPE->element_mode; + move16(); + hCPE->hCoreCoder[1]->element_mode = hCPE->element_mode; + move16(); + + /*--------------------------------------------------------------* + * stereo switching (using parameters that will be freed) + *---------------------------------------------------------------*/ + + /* handling of DFT->TD switching */ + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) && ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) || EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) ) + { + delay_comp_DFT = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); + move16(); + + /* redressing of the DFT OLA part */ + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + FOR ( i = delay_comp_DFT; i < hCPE->hStereoDft->dft32ms_ovl; i++ ) + { + div_m = BASOP_Util_Divide3216_Scale(hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)], hCPE->hStereoDft->win32ms_fx[i_mult(STEREO_DFT32MS_STEP, (sub(add(sub(hCPE->hStereoDft->dft32ms_ovl, 1), delay_comp_DFT), i)))], &div_e); + hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)] = L_shl(div_m, add(div_e, 16)); + // hCPE->output_mem_fx[n][sub(i, delay_comp_DFT)] = hCPE->hStereoDft->win32ms_fx[i_mult(STEREO_DFT32MS_STEP, ( sub(add(sub(hCPE->hStereoDft->dft32ms_ovl, 1), delay_comp_DFT), i) ))]; + } + } + + IF ( NE_16(hCPE->hCoreCoder[0]->last_core, ACELP_CORE) ) + { + mvl2l( hCPE->hStereoDft->buff_LBTCX_mem_fx, hCPE->input_mem_LB_fx[0], NS2SA( i_mult(hCPE->hCoreCoder[0]->last_L_frame, FRAMES_PER_SEC), STEREO_DFT32MS_OVL_NS ) ); + } + } + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) && EQ_16(hCPE->element_mode, IVAS_CPE_DFT) ) + { + v_add_32( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, (int16_t) ( output_Fs / FRAMES_PER_SEC ) ); + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, 16384 /* 0.5 in Q15 */ , hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx, (int16_t) ( output_Fs / FRAMES_PER_SEC ) ); + + v_add_32( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); + v_multc_fixed_16( hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, 16384, hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k ); + } + + /*--------------------------------------------------------------* + * allocate/deallocate data structures + *---------------------------------------------------------------*/ + + IF ( NE_16(hCPE->element_mode, hCPE->last_element_mode) ) + { + /*--------------------------------------------------------------* + * switching CPE mode to DFT stereo + *---------------------------------------------------------------*/ + + IF ( EQ_16(hCPE->element_mode, IVAS_CPE_DFT) ) + { + /* deallocate data structure of the previous CPE mode */ + IF ( hCPE->hStereoTD != NULL ) + { + free( hCPE->hStereoTD ); + hCPE->hStereoTD = NULL; + } + + IF ( hCPE->hStereoMdct != NULL ) + { + free( hCPE->hStereoMdct ); + hCPE->hStereoMdct = NULL; + } + + /* deallocate secondary channel */ + deallocate_CoreCoder_fx( hCPE->hCoreCoder[1] ); + + /* allocate DFT stereo data structure */ + IF ( NE_16( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, 0, nchan_transport ) ), IVAS_ERR_OK ) ) + { + return error; + } + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) ) + { + cpy_tcx_ltp_data_fx( hCPE->hCoreCoder[1]->hTcxLtpDec, hCPE->hStereoDft->hTcxLtpDec, output_Fs ); + deleteFdCngDec( &hCPE->hCoreCoder[1]->hFdCngDec ); + } + + /* memory update - needed in TD stereo, TCX/HQ frame -> DFT stereo, ACELP frame switching */ + mvl2l( hCPE->input_mem_LB_fx[0], hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( s_min( hCPE->hCoreCoder[0]->last_L_frame * FRAMES_PER_SEC, 16000 ), STEREO_DFT32MS_OVL_NS ) ); + + /* allocate ICBWE structure */ + IF ( hCPE->hStereoICBWE == NULL ) + { + IF ( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); + } + + stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); + + } + + /* allocate HQ core */ + st = hCPE->hCoreCoder[0]; + IF ( st->hHQ_core == NULL ) + { + IF ( ( st->hHQ_core = (HQ_DEC_HANDLE) malloc( sizeof( HQ_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HQ core\n" ) ); + } + + HQ_core_dec_init( st->hHQ_core ); +#if 1 // TODO: to be removed later + HQ_core_dec_init_flt( st->hHQ_core ); +#endif + } + + /* allocate TD CNG handle */ + IF ( EQ_16(st->idchan, 0) && st->hTdCngDec == NULL ) + { + IF ( ( st->hTdCngDec = (TD_CNG_DEC_HANDLE) malloc( sizeof( TD_CNG_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) ); + } + + td_cng_dec_init( st ); +#if 1 // TODO: To be removed later + td_cng_dec_init_flt( st ); +#endif + } + } + + /*--------------------------------------------------------------* + * switching CPE mode to TD stereo + *---------------------------------------------------------------*/ + + IF ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) + { + /* deallocate data structure of the previous CPE mode */ + IF ( hCPE->hStereoDft != NULL ) + { + stereo_dft_dec_destroy( &( hCPE->hStereoDft ) ); + hCPE->hStereoDft = NULL; + } + + IF ( hCPE->hStereoMdct != NULL ) + { + free( hCPE->hStereoMdct ); + hCPE->hStereoMdct = NULL; + } + + /* deallocated TCX/IGF structures for second channel */ + deallocate_CoreCoder_TCX( hCPE->hCoreCoder[1] ); + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) ) + { + deleteFdCngDec( &hCPE->hCoreCoder[1]->hFdCngDec ); + } + + /* allocate TD stereo data structure */ + IF ( hCPE->hStereoTD != NULL ) + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: TD Stereo memory already allocated\n" ); + } + + IF ( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); + } + + stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); + + /* allocate CoreCoder secondary channel */ + IF ( NE_16(( error = allocate_CoreCoder( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) + { + return error; + } + } + + /*--------------------------------------------------------------* + * allocate DFT/TD stereo structures after MDCT stereo frame + *---------------------------------------------------------------*/ + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_MDCT) && ( EQ_16(hCPE->element_mode, IVAS_CPE_DFT) || EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) ) + { + /* deallocated TCX-LTP for second channel */ + st = hCPE->hCoreCoder[1]; + IF ( st->hTcxLtpDec != NULL ) + { + free( st->hTcxLtpDec ); + st->hTcxLtpDec = NULL; + } + + IF ( EQ_16(st->element_mode, IVAS_CPE_TD) ) + { + /* re-use an existing buffer for MDCT->TD stereo switching */ + Word16 nZeros, len; + nZeros = (Word16) ( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + move16(); + len = NS2SA( st->output_Fs, 3000000 ); + move16(); + mvl2l( st->hHQ_core->oldOut_fx + nZeros, hCPE->output_mem_fx[1], len ); + } + + /* deallocated HQ-core for second channel */ + IF ( st->hHQ_core != NULL ) + { + free( st->hHQ_core ); + st->hHQ_core = NULL; + } + + /* allocate DFT stereo mono DMX data structure */ + IF ( EQ_16(hCPE->nchan_out, 1) && hCPE->hStereoDftDmx == NULL ) + { + IF ( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); + } + + stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); + + } + + /* allocate TCA data structure */ + IF ( NE_16(hCPE->nchan_out, 1) && hCPE->hStereoTCA == NULL ) + { + IF ( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); + } + + stereo_tca_init_dec_fx( hCPE->hStereoTCA ); + + } + + st = hCPE->hCoreCoder[0]; + + /* allocate primary channel substructures */ + IF ( NE_16(( error = allocate_CoreCoder_fx( st ) ), IVAS_ERR_OK) ) + { + return error; + } + + /* allocate BWEs for primary channel */ + IF ( st->hBWE_TD == NULL ) + { + IF ( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); + } + + td_bwe_dec_init_fx( st, st->hBWE_TD, st->output_Fs ); + +#if 1 // TODO: To be removed later + td_bwe_dec_init( st->hBWE_TD, -1, st->output_Fs ); +#endif + + st->prev_Q_bwe_exc = 31; + st->prev_Qx = 0; + st->prev_ener_fx_Q = 31; + st->prev_frame_pow_exp = 0; + + IF ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); + } + + fd_bwe_dec_init_fx( st->hBWE_FD ); + +#if 1 // TODO: To be removed later + fd_bwe_dec_init_flt( st->hBWE_FD ); +#endif + + st->hBWE_FD->old_wtda_swb_fx_exp = 0; + st->hBWE_FD->mem_imdct_exp_fx = 0; + st->prev_Q_synth = 0; + } + + /* Allocated FD_CNG instance for primary channel*/ + IF ( st->hFdCngDec == NULL ) + { + /* Create FD_CNG instance */ + IF ( ( error = createFdCngDec( &st->hFdCngDec ) ) != IVAS_ERR_OK ) + { + return error; + } + + initFdCngDec( st, st->cldfbSyn->scale ); + + configureFdCngDec_fx( st->hFdCngDec, st->bwidth, st->total_brate, st->L_frame, st->last_L_frame, st->element_mode ); + } + + /* allocate stereo CNG structure */ + IF ( hCPE->hStereoCng == NULL ) + { + IF ( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); + } + stereo_cng_init_dec_fx( hCPE->hStereoCng, &st->hFdCngDec->hFdCngCom->frameSize ); + } + } + + /*--------------------------------------------------------------* + * switching CPE mode to MDCT stereo + *---------------------------------------------------------------*/ + + IF ( EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + { + Word32 tmpF_buff[L_FRAME16k / 2]; + TCX_LTP_DEC_DATA tcxLtpTmp; + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_TD) ) + { + mvl2l( hCPE->hStereoTD->TCX_old_syn_Overl_fx, tmpF_buff, L_FRAME16k / 2 ); + } + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) + { + cpy_tcx_ltp_data( hCPE->hStereoDft->hTcxLtpDec, &tcxLtpTmp, output_Fs ); + } + + /* deallocate data structure of the previous CPE mode */ + IF ( hCPE->hStereoDft != NULL ) + { + stereo_dft_dec_destroy( &( hCPE->hStereoDft ) ); + hCPE->hStereoDft = NULL; + } + + IF ( hCPE->hStereoTD != NULL ) + { + free( hCPE->hStereoTD ); + hCPE->hStereoTD = NULL; + } + + IF ( hCPE->hStereoDftDmx != NULL ) + { + free( hCPE->hStereoDftDmx ); + hCPE->hStereoDftDmx = NULL; + } + + IF ( hCPE->hStereoICBWE != NULL ) + { + free( hCPE->hStereoICBWE ); + hCPE->hStereoICBWE = NULL; + } + + /* de-allocate stereo CNG structure */ + IF ( hCPE->hStereoCng != NULL ) + { + free( hCPE->hStereoCng ); + hCPE->hStereoCng = NULL; + } + + FOR ( i = 0; i < CPE_CHANNELS; i++ ) + { + st = hCPE->hCoreCoder[i]; + st->element_mode = hCPE->element_mode; + move16(); + + /* deallocate core-decoder substructures */ + deallocate_CoreCoder_fx( st ); + + st->first_CNG = 0; + move16(); + } + + /* allocate CLDFB structures for second channel */ + st = hCPE->hCoreCoder[1]; + + IF ( st->cldfbAna == NULL ) + { + IF ( NE_16(( error = openCldfb_ivas_fx( &st->cldfbAna, CLDFB_ANALYSIS, 48000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK) ) + { + return error; + } + } + + IF ( st->cldfbBPF == NULL ) + { + /* open analysis BPF for max. internal sampling rate 16kHz */ + IF ( NE_16(( error = openCldfb_ivas_fx( &st->cldfbBPF, CLDFB_ANALYSIS, 16000, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK) ) + { + return error; + } + } + + /* allocate Fd-Cng structure for second channel */ + IF ( NE_16(( error = createFdCngDec( &st->hFdCngDec ) ), IVAS_ERR_OK) ) + { + return error; + } + + /* Init FD-CNG */ + initFdCngDec( st, st->cldfbSyn->scale); +#if 1 // TODO: To be removed later + initFdCngDec_flt( st ); +#endif + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) + { + st->last_core = ACELP_CORE; /* needed to set-up TCX core in SetTCXModeInfo() */ + } + + /*Allocate CoreCoder TCX modules for second channel */ + IF ( NE_16(( error = allocate_CoreCoder_TCX_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) + { + return error; + } + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) + { + IF ( EQ_16(hCPE->nchan_out, 1) ) + { + cpy_tcx_ltp_data( hCPE->hCoreCoder[0]->hTcxLtpDec, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); + } + ELSE + { + cpy_tcx_ltp_data( &tcxLtpTmp, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); + } + } + + IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_TD) ) + { + mvl2l( tmpF_buff, st->hTcxDec->old_syn_Overl_32, L_FRAME16k / 2 ); + } + + set16_fx(st->hTcxDec->FBTCXdelayBuf, 0, 111); + st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA(st->output_Fs, PH_ECU_MEM_NS); + st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS); + +#if 1 // To be removed later + set_f( st->hTcxDec->FBTCXdelayBuf_float, 0.0f, 111 ); + st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS ); + st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); +#endif + + /* allocate and initialize MDCT stereo structure */ + IF ( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); + } + IF ( EQ_16(ivas_format, STEREO_FORMAT) && hCPE->element_brate <= MAX_MDCT_ITD_BRATE ) + { + hCPE->hStereoMdct->use_itd = 1; + move16(); + } + ELSE + { + hCPE->hStereoMdct->use_itd = 0; + move16(); + } + hCPE->hStereoMdct->reverse_dmx = 0; + move16(); + hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + move32(); + + } + } + + /*--------------------------------------------------------------* + * normal TD / LRTD switching + *---------------------------------------------------------------*/ + + IF ( EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) + { + IF ( EQ_16(hCPE->hCoreCoder[0]->bfi, 0) ) + { + st = hCPE->hCoreCoder[1]; + hCPE->hStereoTD->tdm_LRTD_flag = get_indice_st( hCPE->hCoreCoder[0], hCPE->element_brate + hCPE->brate_surplus, (int16_t) ( ( hCPE->element_brate / FRAMES_PER_SEC ) - nb_bits_metadata + ( hCPE->brate_surplus / FRAMES_PER_SEC ) - TDM_SECONDARY_SIGNALLING - TDM_RATIO_BITS - TDM_LP_REUSE_BITS - TDM_LR_CONTENT_BITS ), TDM_LR_CONTENT_BITS ); + + IF ( NE_16(hCPE->hStereoTD->tdm_LRTD_flag, 0) ) + { + /* deallocate ICBWE structure */ + IF ( hCPE->hStereoICBWE != NULL ) + { + free( hCPE->hStereoICBWE ); + hCPE->hStereoICBWE = NULL; + } + + /* allocate BWEs for secondary channel */ + IF ( st->hBWE_TD == NULL ) + { + IF ( ( st->hBWE_TD = (TD_BWE_DEC_HANDLE) malloc( sizeof( TD_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD BWE\n" ) ); + } + + td_bwe_dec_init_fx( st, st->hBWE_TD, st->output_Fs ); +#if 1 // TODO: To be removed later + td_bwe_dec_init( st->hBWE_TD, -1, st->output_Fs ); +#endif + st->prev_Q_bwe_exc = 31; + st->prev_Qx = 0; + st->prev_ener_fx_Q = 31; + st->prev_frame_pow_exp = 0; + + IF ( ( st->hBWE_FD = (FD_BWE_DEC_HANDLE) malloc( sizeof( FD_BWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FD BWE\n" ) ); + } + + fd_bwe_dec_init_fx( st->hBWE_FD ); + +#if 1 // TODO: To be removed later + fd_bwe_dec_init_flt( st->hBWE_FD ); +#endif + + st->hBWE_FD->old_wtda_swb_fx_exp = 0; + st->hBWE_FD->mem_imdct_exp_fx = 0; + st->prev_Q_synth = 0; + } + } + ELSE /* tdm_LRTD_flag == 0 */ + { + /* deallocate BWEs for secondary channel */ + IF ( st->hBWE_TD != NULL ) + { + IF ( st->hBWE_TD != NULL ) + { + free( st->hBWE_TD ); + st->hBWE_TD = NULL; + } + + IF ( st->hBWE_FD != NULL ) + { + free( st->hBWE_FD ); + st->hBWE_FD = NULL; + } + } + + /* allocate ICBWE structure */ + IF ( hCPE->hStereoICBWE == NULL ) + { + IF ( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); + } + + stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); + } + } + } + } + + /*--------------------------------------------------------------* + * MDCT stereo bitrate switching + *---------------------------------------------------------------*/ + + IF ( EQ_16(ivas_format, STEREO_FORMAT) && EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + { + IF ( LE_32(hCPE->element_brate, MAX_MDCT_ITD_BRATE) && GT_32(ivas_total_brate, IVAS_SID_5k2) ) + { + IF ( EQ_16(hCPE->hStereoMdct->use_itd, 0) ) + { + IF ( hCPE->hStereoTCA == NULL ) + { + /* allocate TCA data structure */ + IF ( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); + } + } + + stereo_tca_init_dec_fx( hCPE->hStereoTCA ); + } + + hCPE->hStereoMdct->use_itd = 1; + move16(); + } + ELSE + { + /* de-allocate TCA data structure */ + IF ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_5k2 && hCPE->hStereoTCA != NULL ) + { + free( hCPE->hStereoTCA ); + hCPE->hStereoTCA = NULL; + hCPE->hStereoMdct->use_itd = 0; + move16(); + } + ELSE IF ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_5k2 ) + { + hCPE->hStereoMdct->itd_fx = 0; + move32(); + } + ELSE + { + hCPE->hStereoMdct->use_itd = 0; + move16(); + } + } + } + + /*--------------------------------------------------------------* + * Bitrate switching in MASA format + *---------------------------------------------------------------*/ + + IF ( ( EQ_16(ivas_format, MASA_FORMAT) || EQ_16(ivas_format, MASA_ISM_FORMAT) ) && EQ_16(nchan_transport, 2) ) + { + IF ( EQ_16(hCPE->nchan_out, 1) ) + { + IF ( hCPE->hStereoDftDmx == NULL ) + { + IF ( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); + } + + stereo_dft_dmx_out_reset_fx(hCPE->hStereoDftDmx); + } + +#if 1 // TODO: To be removed later + IF ( hCPE->prev_synth_chs[1] != NULL ) + { + free( hCPE->prev_synth_chs[1] ); + hCPE->prev_synth_chs[1] = NULL; + } +#endif + IF (hCPE->prev_synth_chs_fx[1] != NULL) + { + free(hCPE->prev_synth_chs_fx[1]); + hCPE->prev_synth_chs_fx[1] = NULL; + } + + IF ( hCPE->hStereoTCA != NULL ) + { + free( hCPE->hStereoTCA ); + hCPE->hStereoTCA = NULL; + } + } + ELSE /* nchan_out == 2 */ + { + IF ( hCPE->hStereoDftDmx != NULL ) + { + free( hCPE->hStereoDftDmx ); + hCPE->hStereoDftDmx = NULL; + } + +#if 1 // TODO : To be removed later + IF ( hCPE->prev_synth_chs[1] == NULL ) + { + st = hCPE->hCoreCoder[1]; + IF ( ( hCPE->prev_synth_chs[1] = (float *) malloc( sizeof( float ) * NS2SA( st->output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) ); + } + set_zero( hCPE->prev_synth_chs[1], NS2SA( st->output_Fs, FRAME_SIZE_NS ) ); + } +#endif + + IF (hCPE->prev_synth_chs_fx[1] == NULL) + { + st = hCPE->hCoreCoder[1]; + IF ((hCPE->prev_synth_chs_fx[1] = (Word32 *)malloc(sizeof(Word32) * NS2SA(st->output_Fs, FRAME_SIZE_NS))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n")); + } + set32_fx(hCPE->prev_synth_chs_fx[1],0, NS2SA(st->output_Fs, FRAME_SIZE_NS)); + } + + IF ( hCPE->hStereoICBWE == NULL && EQ_16(hCPE->element_mode, IVAS_CPE_DFT) ) + { + IF ( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE \n" ) ); + } + + stereo_icBWE_init_dec_fx(hCPE->hStereoICBWE); + } + + IF ( hCPE->hStereoTCA == NULL && ( EQ_16(hCPE->element_mode, IVAS_CPE_DFT) || EQ_16(hCPE->element_mode, IVAS_CPE_TD) ) ) + { + IF ( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); + } + + stereo_tca_init_dec_fx( hCPE->hStereoTCA ); + } + + IF ( EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + { + IF ( hCPE->hStereoTCA != NULL ) + { + /* note: in MASA, hCPE->hStereoMdct->itd = 0 */ + free( hCPE->hStereoTCA ); + hCPE->hStereoTCA = NULL; + } + + IF ( hCPE->hStereoICBWE != NULL ) + { + free( hCPE->hStereoICBWE ); + hCPE->hStereoICBWE = NULL; + } + } + } + } + + /*--------------------------------------------------------------* + * Bitrate switching in MASA format + *---------------------------------------------------------------*/ + + IF ( EQ_16(ivas_format, MC_FORMAT) && EQ_16(hCPE->element_mode, IVAS_CPE_MDCT) ) + { + IF ( EQ_16(mc_mode, MC_MODE_MCT) || EQ_16(mc_mode, MC_MODE_PARAMUPMIX) ) + { + /* deallocate the FdCNG handle */ + FOR ( i = 0; i < CPE_CHANNELS; ++i ) + { + deleteFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ); + } + } + ELSE + { + /* allocate the FdCNG handle (for noise estimation for TCX PLC fadeout)*/ + FOR ( i = 0; i < CPE_CHANNELS; ++i ) + { + IF ( hCPE->hCoreCoder[i]->cldfbSyn == NULL ) /* could be NULL when we had the MCT LFE channel */ + { + IF ( NE_16(( error = openCldfb_ivas_fx( &hCPE->hCoreCoder[i]->cldfbSyn, CLDFB_SYNTHESIS, hCPE->hCoreCoder[i]->output_Fs, CLDFB_PROTOTYPE_1_25MS ) ), IVAS_ERR_OK) ) + { + return error; + } + } + + IF ( hCPE->hCoreCoder[i]->hFdCngDec == NULL ) + { + IF ( NE_16(( error = createFdCngDec( &hCPE->hCoreCoder[i]->hFdCngDec ) ), IVAS_ERR_OK) ) + { + return error; + } + initFdCngDec( hCPE->hCoreCoder[i], hCPE->hCoreCoder[i]->cldfbSyn->scale ); +#if 1 + initFdCngDec_flt( hCPE->hCoreCoder[i] ); +#endif + } + } + } + } + + return error; +} +#endif + /*-------------------------------------------------------------------* * Function synchro_synthesis() diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index ccaccb78ddea78240e39738049c4ef429397d2cb..b7867342a6fe1b4a3a00b7d90216e3476aedb61e 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -612,6 +612,7 @@ typedef struct tcx_dec_structure float old_syn_Overl_float[L_FRAME32k / 2]; Word16 old_syn_Overl[L_FRAME32k / 2]; + Word32 old_syn_Overl_32[L_FRAME32k / 2]; float syn_Overl_TDAC_float[L_FRAME32k / 2]; Word16 syn_Overl_TDAC[L_FRAME32k / 2]; @@ -1560,7 +1561,7 @@ typedef struct fd_bwe_dec_structure Word16 prev_mode_fx; float prev_SWB_fenv[SWB_FENV]; - //Word16 prev_SWB_fenv_fx[SWB_FENV]; + Word16 prev_SWB_fenv_fx[SWB_FENV]; float prev_Energy; Word16 prev_Energy_fx; @@ -1594,10 +1595,10 @@ typedef struct fd_bwe_dec_structure Word16 prev_flag_fx; float last_wb_bwe_ener; - //Word16 last_wb_bwe_ener_fx; + Word16 last_wb_bwe_ener_fx; float prev_fb_ener_adjust; - //Word16 prev_fb_ener_adjust_fx; + Word16 prev_fb_ener_adjust_fx; //Word16 prev_frame_pow_exp; //Word16 prev_Qx; diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index 8422aa5b065c1b795134a04d9ef4c4de17cbfa64..cd4b855d02c9920d70d4be4c276fed2165a30282 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -39,6 +39,7 @@ #include #include "cnst.h" #include "prot.h" +#include "prot_fx2.h" #include "rom_com.h" #include "basop_util.h" #include "basop_proto_func.h" @@ -787,3 +788,43 @@ void fd_bwe_dec_init_flt( return; } + +#ifdef IVAS_FLOAT_FIXED +void fd_bwe_dec_init_fx( + FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ +) +{ + set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME48k ); + set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + hBWE_FD->prev_mode = NORMAL; + move16(); + set16_fx( hBWE_FD->prev_SWB_fenv_fx, 0, SWB_FENV ); + hBWE_FD->prev_Energy_fx = 0; + move16(); + hBWE_FD->prev_L_swb_norm = 8; + move16(); + hBWE_FD->Seed = 21211; + move16(); + hBWE_FD->prev_frica_flag = 0; + move16(); + set16_fx( hBWE_FD->mem_imdct_fx, 0, L_FRAME48k ); + hBWE_FD->prev_td_energy_fx = 0; + move16(); + hBWE_FD->prev_weight_fx = 0; + move16(); + hBWE_FD->prev_flag = 0; + move16(); + hBWE_FD->last_wb_bwe_ener_fx = 0; + move16(); + hBWE_FD->prev_Energy_wb_fx = 0; + move32(); + + hBWE_FD->mem_deemph_old_syn_fx = 0; + move16(); + + hBWE_FD->prev_fb_ener_adjust_fx = 0; + move16(); + + return; +} +#endif