From d96b7c28b123fb58670d4db8d95e585c834c8eb1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 3 Mar 2024 01:52:40 +0530 Subject: [PATCH] Core coder updates --- lib_com/ivas_prot.h | 13 + lib_com/ivas_prot_fx.h | 7 - lib_dec/ivas_core_dec.c | 1335 +++++++++++++++++++----- lib_dec/ivas_mct_dec.c | 65 +- lib_dec/ivas_sba_dirac_stereo_dec_fx.c | 2 +- lib_dec/ivas_stereo_switching_dec.c | 633 +++++------ 6 files changed, 1348 insertions(+), 707 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index fc5d9eb97..8acefc5b4 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3258,12 +3258,25 @@ void stereo_td2dft_update( const int16_t output_frame /* i : frame length */ ); +void stereo_td2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const int16_t n, /* i : channel number */ + Word32 output_fx[], /* i/o: synthesis @internal Fs */ + Word32 synth_fx[], /* i/o: synthesis @output Fs */ + Word32 hb_synth_fx[], /* i/o: hb synthesis */ + const int16_t output_frame /* i : frame length */ +); void stereo_mdct2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float output0[], /* i/o: synthesis @internal Fs, ch0 */ float synth0[] /* i/o: synthesis @output Fs, ch0 */ ); +void stereo_mdct2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 */ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ +); /*! r: number of bits written */ int16_t write_GR0( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 2afc0ed2b..94df1d68b 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -983,13 +983,6 @@ void stereo_dft_dec_fx( const Word16 num_md_sub_frames /* i : number of MD subframes */ ); -void synchro_synthesis_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : Number of samples */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ -); void ivas_ls_setup_conversion_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index eaa9b94c5..2a4a86560 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -53,7 +53,7 @@ * * Principal IVAS core decoder routine, where number of core channels is 1 or 2 *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_core_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ @@ -74,7 +74,7 @@ ivas_error ivas_core_dec( float synth[CPE_CHANNELS][L_FRAME48k]; float tmp_buffer[L_FRAME48k]; #ifdef IVAS_FLOAT_FIXED - set_zero(tmp_buffer, L_FRAME48k); + set_zero( tmp_buffer, L_FRAME48k ); #endif int16_t tmps, incr; float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; @@ -239,14 +239,18 @@ ivas_error ivas_core_dec( if ( sts[0]->L_frame != sts[0]->last_L_frame ) { lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame ); + L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); } if ( sts[0]->L_frame != L_FRAME16k ) { ovl = (int16_t) ( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k ); + L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); + fade_len = (int16_t) ( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); + L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); } } @@ -268,7 +272,7 @@ ivas_error ivas_core_dec( * Decode SID for MDCT-Stereo DTX mode *-----------------------------------------------------------------*/ - if (sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40) + if ( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) { #ifdef IVAS_FLOAT_FIXED FOR( Word16 ch = 0; ch < CPE_CHANNELS; ++ch ) @@ -648,61 +652,63 @@ ivas_error ivas_core_dec( sts[0] = hCPE->hCoreCoder[0]; sts[1] = hCPE->hCoreCoder[1]; - if (hCPE->last_element_brate <= IVAS_SID_5k2) + if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) { - for (int j = 0; j < output_frame; j++) + for ( int j = 0; j < output_frame; j++ ) { - max_synth = max(max_synth, fabs(synth[0][j])); + max_synth = max( max_synth, fabs( synth[0][j] ) ); } - if ((Word16)max_synth != 0) + if ( (Word16) max_synth != 0 ) { - Q_syn = norm_s((Word16)max_synth); + Q_syn = norm_s( (Word16) max_synth ); } - for (int j = 0; j < output_frame; j++) + for ( int j = 0; j < output_frame; j++ ) { - synth_fx[0][j] = float_to_fix16(synth[0][j], Q_syn); + synth_fx[0][j] = float_to_fix16( synth[0][j], Q_syn ); } - for (int j = 0; j < output_frame; j++) + for ( int j = 0; j < output_frame; j++ ) { - max_output = max(max_output, fabs(output[0][j])); + max_output = max( max_output, fabs( output[0][j] ) ); } - if ((Word32)max_output != 0) + if ( (Word32) max_output != 0 ) { - Q_output = norm_l((Word32)max_output); + Q_output = norm_l( (Word32) max_output ); } - for (int j = 0; j < output_frame; j++) + for ( int j = 0; j < output_frame; j++ ) { - output_fx[0][j] = float_to_fix(output[0][j], Q_output); + output_fx[0][j] = float_to_fix( output[0][j], Q_output ); } } f2me_buf( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); f2me_buf( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst, &sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp, NPART ); - if (hCPE->last_element_brate <= IVAS_SID_5k2) { - f2me_buf_16(sts[0]->hTcxLtpDec->tcxltp_mem_in_float, sts[0]->hTcxLtpDec->tcxltp_mem_in, &sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, TCXLTP_MAX_DELAY); - f2me_buf_16(sts[1]->hTcxLtpDec->tcxltp_mem_in_float, sts[1]->hTcxLtpDec->tcxltp_mem_in, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_in, TCXLTP_MAX_DELAY); - f2me_buf_16(sts[0]->hTcxLtpDec->tcxltp_mem_out_float, sts[0]->hTcxLtpDec->tcxltp_mem_out, &sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, L_FRAME48k); - f2me_buf_16(sts[1]->hTcxLtpDec->tcxltp_mem_out_float, sts[1]->hTcxLtpDec->tcxltp_mem_out, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_out, L_FRAME48k); + if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) + { + f2me_buf_16( sts[0]->hTcxLtpDec->tcxltp_mem_in_float, sts[0]->hTcxLtpDec->tcxltp_mem_in, &sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, TCXLTP_MAX_DELAY ); + f2me_buf_16( sts[1]->hTcxLtpDec->tcxltp_mem_in_float, sts[1]->hTcxLtpDec->tcxltp_mem_in, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_in, TCXLTP_MAX_DELAY ); + f2me_buf_16( sts[0]->hTcxLtpDec->tcxltp_mem_out_float, sts[0]->hTcxLtpDec->tcxltp_mem_out, &sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, L_FRAME48k ); + f2me_buf_16( sts[1]->hTcxLtpDec->tcxltp_mem_out_float, sts[1]->hTcxLtpDec->tcxltp_mem_out, &sts[1]->hTcxLtpDec->exp_tcxltp_mem_out, L_FRAME48k ); - f2me_buf_16(sts[0]->delay_buf_out, sts[0]->delay_buf_out_fx, &sts[0]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP); /*To remove exp component Q0*/ - f2me_buf_16(sts[1]->delay_buf_out, sts[1]->delay_buf_out_fx, &sts[1]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP); - f2me_buf_16(sts[0]->hHQ_core->old_out, sts[0]->hHQ_core->old_out_fx, &sts[0]->hHQ_core->exp_old_out, L_FRAME48k); - f2me_buf_16(sts[1]->hHQ_core->old_out, sts[1]->hHQ_core->old_out_fx, &sts[1]->hHQ_core->exp_old_out, L_FRAME48k); + f2me_buf_16( sts[0]->delay_buf_out, sts[0]->delay_buf_out_fx, &sts[0]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); /*To remove exp component Q0*/ + f2me_buf_16( sts[1]->delay_buf_out, sts[1]->delay_buf_out_fx, &sts[1]->exp_delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); + f2me_buf_16( sts[0]->hHQ_core->old_out, sts[0]->hHQ_core->old_out_fx, &sts[0]->hHQ_core->exp_old_out, L_FRAME48k ); + f2me_buf_16( sts[1]->hHQ_core->old_out, sts[1]->hHQ_core->old_out_fx, &sts[1]->hHQ_core->exp_old_out, L_FRAME48k ); } updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_fx[0], output_fx[1], synth_fx ); me2f_buf( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART ); me2f_buf( sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEstExp, sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst_flt, NPART ); - if (hCPE->last_element_brate <= IVAS_SID_5k2) { - me2f_buf_16(sts[0]->hTcxLtpDec->tcxltp_mem_in, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, sts[0]->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY); - me2f_buf_16(sts[0]->hTcxLtpDec->tcxltp_mem_out, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, sts[0]->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k); - me2f_buf_16(sts[0]->delay_buf_out_fx, sts[0]->exp_delay_buf_out, sts[0]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP); /*To remove exp component Q0*/ - me2f_buf_16(sts[0]->hHQ_core->old_out_fx, sts[0]->hHQ_core->exp_old_out, sts[0]->hHQ_core->old_out, L_FRAME48k); - me2f_buf_16(sts[1]->hHQ_core->old_out_fx, sts[1]->hHQ_core->exp_old_out, sts[1]->hHQ_core->old_out, L_FRAME48k); + if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) + { + me2f_buf_16( sts[0]->hTcxLtpDec->tcxltp_mem_in, sts[0]->hTcxLtpDec->exp_tcxltp_mem_in, sts[0]->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); + me2f_buf_16( sts[0]->hTcxLtpDec->tcxltp_mem_out, sts[0]->hTcxLtpDec->exp_tcxltp_mem_out, sts[0]->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); + me2f_buf_16( sts[0]->delay_buf_out_fx, sts[0]->exp_delay_buf_out, sts[0]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); /*To remove exp component Q0*/ + me2f_buf_16( sts[0]->hHQ_core->old_out_fx, sts[0]->hHQ_core->exp_old_out, sts[0]->hHQ_core->old_out, L_FRAME48k ); + me2f_buf_16( sts[1]->hHQ_core->old_out_fx, sts[1]->hHQ_core->exp_old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); } for ( i = 1; i < CPE_CHANNELS; i++ ) @@ -753,9 +759,9 @@ ivas_error ivas_core_dec( { sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); } - for (int p = 0; p < FDNS_NPTS; p++) + for ( int p = 0; p < FDNS_NPTS; p++ ) { - sts[n]->hTonalMDCTConc->scaleFactorsBackground_fx[p] = (Word32)(sts[n]->hTonalMDCTConc->scaleFactorsBackground_flt[p] * ONE_IN_Q16); + sts[n]->hTonalMDCTConc->scaleFactorsBackground_fx[p] = (Word32) ( sts[n]->hTonalMDCTConc->scaleFactorsBackground_flt[p] * ONE_IN_Q16 ); } TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); @@ -788,33 +794,33 @@ ivas_error ivas_core_dec( Word16 Q_c_PS_LT = 31, Q_output = 31; double max_output_fx = 0; - for (i = 0; i < CPE_CHANNELS; i++) + for ( i = 0; i < CPE_CHANNELS; i++ ) { - for (int j = 0; j < L_FRAME16k; j++) + for ( int j = 0; j < L_FRAME16k; j++ ) { - max_output_fx = max(max_output_fx, fabs(output[i][j])); + max_output_fx = max( max_output_fx, fabs( output[i][j] ) ); } } - if ((Word32)max_output_fx != 0) + if ( (Word32) max_output_fx != 0 ) { - Q_output = norm_l((Word32)max_output_fx); + Q_output = norm_l( (Word32) max_output_fx ); } - for (i = 0; i < CPE_CHANNELS; i++) + for ( i = 0; i < CPE_CHANNELS; i++ ) { - for (int j = 0; j < L_FRAME16k; j++) + for ( int j = 0; j < L_FRAME16k; j++ ) { - output_fx[i][j] = float_to_fix(output[i][j], Q_output); + output_fx[i][j] = float_to_fix( output[i][j], Q_output ); } } - if ((Word32)hCPE->hStereoCng->c_PS_LT != 0) + if ( (Word32) hCPE->hStereoCng->c_PS_LT != 0 ) { - Q_c_PS_LT = norm_l((Word32)hCPE->hStereoCng->c_PS_LT); + Q_c_PS_LT = norm_l( (Word32) hCPE->hStereoCng->c_PS_LT ); } - Word32 c_PS_LT_fx = float_to_fix(hCPE->hStereoCng->c_PS_LT, Q_c_PS_LT); + Word32 c_PS_LT_fx = float_to_fix( hCPE->hStereoCng->c_PS_LT, Q_c_PS_LT ); - stereo_cng_compute_PScorr_fx(output_fx[0], output_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame); + stereo_cng_compute_PScorr_fx( output_fx[0], output_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); hCPE->hStereoCng->c_PS_LT = fix_to_float( c_PS_LT_fx, Q_c_PS_LT ); #ifdef DUMPS_ENABLED @@ -962,7 +968,7 @@ ivas_error ivas_core_dec( Word32 *hb_synth_1 = (Word32 *) malloc( sizeof( Word32 ) * L_FRAME48k ); Word32 tmp_buffer_fx[L_FRAME48k]; #ifdef IVAS_FLOAT_FIXED - set32_fx(tmp_buffer_fx, 0, L_FRAME48k); + set32_fx( tmp_buffer_fx, 0, L_FRAME48k ); #endif Word32 voice_factor_fx[NB_SUBFR16k]; Word16 q = 16; @@ -1154,302 +1160,383 @@ ivas_error ivas_core_dec( * - updates for potential TD->DFT stereo switching *----------------------------------------------------------------*/ - if ( st->element_mode != IVAS_CPE_DFT ) + // TO DO delete below + Word32 output_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 hb_synth_fx[CPE_CHANNELS][L_FRAME48k]; + + FOR( int ch_ind = 0; ch_ind < n_channels; ch_ind++ ) { - if ( st->element_mode != IVAS_CPE_MDCT || sba_dirac_stereo_flag ) + FOR( int ind = 0; ind < L_FRAME48k; ind++ ) { -#ifdef IVAS_FLOAT_FIXED - Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; - for ( int k = 0; k < output_frame; k++ ) + output_fx[ch_ind][ind] = (Word32) ( output[ch_ind][ind] * ( 1 << 11 ) ); + synth_fx[ch_ind][ind] = (Word32) ( synth[ch_ind][ind] * ( 1 << 11 ) ); + hb_synth_fx[ch_ind][ind] = (Word32) ( hb_synth[ch_ind][ind] * ( 1 << 11 ) ); + } + } + Word16 q_DFT[2] = { 3, 3 }; + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; + + IF( DFT != NULL ) + { + FOR( int ind = 0; ind < CPE_CHANNELS; ind++ ) + { + FOR( int j = 0; j < STEREO_DFT_BUF_MAX; j++ ) { - synth_fx[n][k] = (Word32) ( synth[n][k] * ONE_IN_Q14 ); + DFT_fx[ind][j] = (Word32) ( DFT[ind][j] * ( 1 << q_DFT[ind] ) ); } - IF( hSCE != NULL ) + } + } + + if ( hCPE != NULL ) + { + FOR( int ch_ind = 0; ch_ind < n_channels; ch_ind++ ) + { + if ( hCPE->hCoreCoder[ch_ind] != NULL ) { - for ( int k = 0; k < output_frame; k++ ) + if ( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) { - hSCE->hCoreCoder[n]->hHQ_core->oldOut_fx[k] = (Word32) ( hSCE->hCoreCoder[n]->hHQ_core->old_out[k] * ONE_IN_Q14 ); - if ( k < 111 ) + FOR( int ind = 0; ind < L_FRAME32k; ind++ ) { - hSCE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hSCE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ONE_IN_Q14 ); + hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx[ind] = hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB[ind] * ( 1 << 11 ); } - if ( k < HQ_DELTA_MAX * HQ_DELAY_COMP ) + FOR( int ind = 0; ind < L_FRAME48k; ind++ ) { - hSCE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hSCE->hCoreCoder[n]->delay_buf_out[k] * ONE_IN_Q14 ); + hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx[ind] = (Word32) ( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out[ind] * ( 1 << 11 ) ); } - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[k] = (Word32)(hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[k] * ONE_IN_Q14); - if (k < TCXLTP_MAX_DELAY) + } + FOR( int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++ ) + { + hCPE->hCoreCoder[ch_ind]->delay_buf_out32_fx[ind] = (Word32) ( hCPE->hCoreCoder[ch_ind]->delay_buf_out[ind] * ( 1 << 11 ) ); + } + if ( hCPE->hCoreCoder[ch_ind]->p_bpf_noise_buf_float != NULL ) + { + FOR( int ind = 0; ind < L_FRAME16k; ind++ ) { - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[k] = (Word32)(hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[k] * ONE_IN_Q14); + hCPE->hCoreCoder[ch_ind]->p_bpf_noise_buf_32[ind] = (Word32) ( hCPE->hCoreCoder[ch_ind]->p_bpf_noise_buf_float[ind] * ( 1 << 11 ) ); } } - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } - ELSE + if ( hCPE->input_mem[ch_ind] ) { - if ( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) + FOR( int ind = 0; ind < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ); ind++ ) { - if ( !( NE_16( hCPE->hCoreCoder[n]->core, TCX_20_CORE ) && NE_16( hCPE->hCoreCoder[n]->core, TCX_10_CORE ) ) ) - { - for ( int k = 0; k < output_frame; k++ ) - { - hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->hHQ_core->old_out[k] * ONE_IN_Q14 ); - if ( k < 111 ) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ONE_IN_Q14 ); - } - if ( k < HQ_DELTA_MAX * HQ_DELAY_COMP ) - { - hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ONE_IN_Q14 ); - } - } - } - for ( int k = 0; k < output_frame; k++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[k] * ONE_IN_Q14 ); - if ( k < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[k] * ONE_IN_Q14 ); - } - } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); + hCPE->input_mem_fx[ch_ind][ind] = (Word32) ( hCPE->input_mem[ch_ind][ind] * ( 1 << 11 ) ); } - if ( !( ( hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[0]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) + } + if ( hCPE->input_mem_LB[ch_ind] ) + { + FOR( int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ONE_IN_Q14 ); - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ONE_IN_Q14 ); - } - if (p < NS2SA(hCPE->hCoreCoder[n]->output_Fs, STEREO_DFT32MS_OVL_NS)) - { - hCPE->output_mem_fx[0][p] = (Word32)(hCPE->output_mem[0][p] * ONE_IN_Q14); - hCPE->output_mem_fx[1][p] = (Word32)(hCPE->output_mem[1][p] * ONE_IN_Q14); - } - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); + hCPE->input_mem_LB_fx[ch_ind][ind] = (Word32) ( hCPE->input_mem_LB[ch_ind][ind] * ( 1 << 11 ) ); } } - - ivas_post_proc_fx( hSCE, hCPE, n, synth_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); - - for ( int k = 0; k < output_frame; k++ ) + if ( hCPE->input_mem_BPF[0] != NULL ) + { + FOR( int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_BPF_fx[0][ind] = (Word32) ( hCPE->input_mem_BPF[0][ind] * ( 1 << 11 ) ); + } + } + IF(hCPE->output_mem[ch_ind] != NULL) { - synth[n][k] = (float) synth_fx[n][k] / ONE_IN_Q14; + FOR(Word32 k = 0; k < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); k++) + { + hCPE->output_mem_fx[ch_ind][k] = (Word32)(hCPE->output_mem[ch_ind][k] * (1 << OUTPUT_Q)); + } } - IF( hSCE != NULL ) + IF( hCPE->hStereoDft != NULL ) { - for ( int k = 0; k < output_frame; k++ ) + FOR( int ind = 0; ind < NS2SA( 16000, DELAY_BWE_TOTAL_NS ); ind++ ) { - hSCE->hCoreCoder[n]->hHQ_core->old_out[k] = (float) hSCE->hCoreCoder[n]->hHQ_core->oldOut_fx[k] / ONE_IN_Q14; - if ( k < 111 ) - { - hSCE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hSCE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ONE_IN_Q14; - } - if ( k < ( HQ_DELTA_MAX * HQ_DELAY_COMP ) ) - { - hSCE->hCoreCoder[n]->delay_buf_out[k] = (float) hSCE->hCoreCoder[n]->delay_buf_out32_fx[k] / ONE_IN_Q14; - } - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[k] = (float)hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[k] / ONE_IN_Q14; - if (k < TCXLTP_MAX_DELAY) - { - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[k] = (float)hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[k] / ONE_IN_Q14; - } + hCPE->hStereoDft->ap_delay_mem_fx[ind] = (Word32) ( hCPE->hStereoDft->ap_delay_mem[ind] * ( 1 << 11 ) ); + } + FOR( int ind = 0; ind < NS2SA( 16000, STEREO_DFT32MS_OVL_NS ); ind++ ) + { + hCPE->hStereoDft->buff_LBTCX_mem_fx[ind] = (Word32) ( hCPE->hStereoDft->buff_LBTCX_mem[ind] * ( 1 << 11 ) ); } - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hSCE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + IF(hCPE->hStereoDft->hTcxLtpDec != NULL) + { + FOR(Word32 p = 0; p < L_FRAME48k; p++) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * (1u << OUTPUT_Q)); + } + FOR(Word32 p = 0; p < TCXLTP_MAX_DELAY; p++) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); + } + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); + } + + } + IF(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec != NULL) + { + FOR(Word32 p = 0; p < L_FRAME48k; p++) + { + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_out_float[p] * (1u << OUTPUT_Q)); + } + FOR(Word32 p = 0; p < TCXLTP_MAX_DELAY; p++) + { + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); + } + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); + } + IF(hCPE->hCoreCoder[ch_ind]->hTcxDec != NULL) + { + FOR(Word32 k = 0; k < 111; k++) + { + hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32)(hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_float[k] * (1 << OUTPUT_Q)); + } } - ELSE + } + } + if ( hSCE != NULL ) + { + if ( hSCE->hCoreCoder[0] != NULL ) + { + if ( hSCE->hCoreCoder[0]->hHQ_core != NULL ) { - if ( hCPE->hCoreCoder[n]->hTcxLtpDec != NULL ) + FOR( int ind = 0; ind < L_FRAME32k; ind++ ) { - if ( !( NE_16( hCPE->hCoreCoder[n]->core, TCX_20_CORE ) && NE_16( hCPE->hCoreCoder[n]->core, TCX_10_CORE ) ) ) - { - for ( int k = 0; k < 111; k++ ) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ONE_IN_Q14; - } - } - for ( int k = 0; k < output_frame; k++ ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[k] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[k] / ONE_IN_Q14; - if ( k < TCXLTP_MAX_DELAY ) - { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[k] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[k] / ONE_IN_Q14; - } - } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx[ind] = hSCE->hCoreCoder[0]->hHQ_core->old_outLB[ind] * ( 1 << 11 ); } - if ( !( ( hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[0]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) + FOR( int ind = 0; ind < L_FRAME48k; ind++ ) { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; - if ( p < TCXLTP_MAX_DELAY ) - { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ONE_IN_Q14; - } - if (p < NS2SA(hCPE->hCoreCoder[n]->output_Fs, STEREO_DFT32MS_OVL_NS)) - { - hCPE->output_mem[0][p] = (float)hCPE->output_mem_fx[0][p] / ONE_IN_Q14; - hCPE->output_mem[1][p] = (float)hCPE->output_mem_fx[1][p] / ONE_IN_Q14; - } - } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx[ind] = (Word32) ( hSCE->hCoreCoder[0]->hHQ_core->old_out[ind] * ( 1 << 11 ) ); } } -#else - ivas_post_proc( hSCE, hCPE, n, synth[n], NULL, output_frame, sba_dirac_stereo_flag ); -#endif // IVAS_FLOAT_FIXED + FOR( int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++ ) + { + hSCE->hCoreCoder[0]->delay_buf_out32_fx[ind] = (Word32) ( hSCE->hCoreCoder[0]->delay_buf_out[ind] * ( 1 << 11 ) ); + } + IF(hSCE->hCoreCoder[0]->hTcxDec != NULL) + { + FOR(Word32 k = 0; k < 111; k++) + { + hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32)(hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[k] * (1 << OUTPUT_Q)); + } + } + IF(hSCE->hCoreCoder[0]->hTcxLtpDec != NULL) + { + FOR(Word32 p = 0; p < L_FRAME48k; p++) + { + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] * (1u << OUTPUT_Q)); + } + FOR(Word32 p = 0; p < TCXLTP_MAX_DELAY; p++) + { + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); + } + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain = (Word16)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); + } + } + } + + + if ( st->element_mode != IVAS_CPE_DFT ) + { + + if ( st->element_mode != IVAS_CPE_MDCT || sba_dirac_stereo_flag ) + { + ivas_post_proc_fx( hSCE, hCPE, n, synth_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); + } /* update OLA buffers - needed for switching to DFT stereo */ if ( !sba_dirac_stereo_flag ) { - stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); + if ( hCPE != NULL ) + { + stereo_td2dft_update_fx( hCPE, n, &output_fx[n], &synth_fx[n], &hb_synth_fx[n], output_frame ); + } } } else /* IVAS_CPE_DFT */ { + Word16 q = 11; if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) { - stereo_mdct2dft_update( hCPE, output[0], synth[0] ); - } -#ifdef IVAS_FLOAT_FIXED - Word16 q = 11, q_DFT[2] = { 3, 3 }; - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; - Word32 synth_fx[L_FRAME48k]; - Word32 hb_synth_fx[L_FRAME48k]; - Word32 output_fx[960]; - FOR( int ind = 0; ind < 960; ind++ ) - { - output_fx[ind] = (Word32) ( output[0][ind] * ( 1 << q ) ); + stereo_mdct2dft_update_fx( hCPE, output_fx[0], synth_fx[0] ); } - IF( hCPE->hCoreCoder[0] != NULL ) - FOR( int ind = 0; ind < L_FRAME32k; ind++ ) + stereo_dft_dec_core_switching_fx( hCPE, output_fx[0], synth_fx[0], hb_synth_fx[0], DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); + + if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) { - hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx[ind] = (Word32) ( hCPE->hCoreCoder[0]->hHQ_core->old_outLB[ind] * ( 1 << q ) ); + /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ + stereo_td2dft_update_fx( hCPE, n, &output_fx[n], &synth_fx[n], &hb_synth_fx[n], output_frame ); } - IF( ( hCPE->hCoreCoder[0] != NULL ) && ( hCPE->hCoreCoder[0]->p_bpf_noise_buf_32 != NULL ) ) - FOR( int ind = 0; ind < L_FRAME16k; ind++ ) + } + + Copy32( synth_fx[n], output_fx[n], output_frame ); + + // TO DO delete below + FOR( int ch_ind = 0; ch_ind < n_channels; ch_ind++ ) + { + FOR( i = 0; i < L_FRAME48k; i++ ) { - hCPE->hCoreCoder[0]->p_bpf_noise_buf_32[ind] = (Word32) ( hCPE->hCoreCoder[0]->p_bpf_noise_buf_float[ind] * ( 1 << q ) ); + output[ch_ind][i] = (float) output_fx[ch_ind][i] / (float) ( 1 << 11 ); + synth[ch_ind][i] = (float) synth_fx[ch_ind][i] / (float) ( 1 << 11 ); + hb_synth[ch_ind][i] = (float) hb_synth_fx[ch_ind][i] / (float) ( 1 << 11 ); } - IF( DFT != NULL ) - FOR( int ind = 0; ind < CPE_CHANNELS; ind++ ) + } + IF( DFT != NULL ) + { + FOR( i = 0; i < CPE_CHANNELS; i++ ) { - FOR( int j = 0; j < STEREO_DFT_BUF_MAX; j++ ) + FOR( Word16 j = 0; j < STEREO_DFT_BUF_MAX; j++ ) { - DFT_fx[ind][j] = (Word32) ( DFT[ind][j] * ( 1 << q_DFT[ind] ) ); + DFT[i][j] = (float) DFT_fx[i][j] / (float) ( 1 << q_DFT[i] ); } } + } + if ( hCPE != NULL ) + { - FOR( int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - hCPE->input_mem_BPF_fx[0][ind] = (Word32) ( hCPE->input_mem_BPF[0][ind] * ( 1 << q ) ); - FOR( int ind = 0; ind < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ); ind++ ) - hCPE->input_mem_fx[0][ind] = (Word32) ( hCPE->input_mem[0][ind] * ( 1 << q ) ); - FOR( int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - hCPE->input_mem_LB_fx[0][ind] = (Word32) ( hCPE->input_mem_LB[0][ind] * ( 1 << q ) ); - FOR( int ind = 0; ind < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ); ind++ ) - hCPE->input_mem_fx[1][ind] = (Word32) ( hCPE->input_mem[1][ind] * ( 1 << q ) ); - FOR( int ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) - hCPE->input_mem_LB_fx[1][ind] = (Word32) ( hCPE->input_mem_LB[1][ind] * ( 1 << q ) ); - IF( hCPE->hStereoDft != NULL ) - FOR( int ind = 0; ind < NS2SA( 16000, DELAY_BWE_TOTAL_NS ); ind++ ) - { - hCPE->hStereoDft->ap_delay_mem_fx[ind] = (Word32) ( hCPE->hStereoDft->ap_delay_mem[ind] * ( 1 << q ) ); - } - FOR( int ind = 0; ind < hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC; ind++ ) - { - synth_fx[ind] = (Word32) ( synth[0][ind] * ( 1 << q ) ); - hb_synth_fx[ind] = (Word32) ( hb_synth[0][ind] * ( 1 << q ) ); - } - IF( hCPE->hCoreCoder[0] != NULL ) - FOR( int ind = 0; ind < L_FRAME48k; ind++ ) - { - hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx[ind] = (Word32) ( hCPE->hCoreCoder[0]->hHQ_core->old_out[ind] * ( 1 << q ) ); - } - IF( hCPE->hStereoDft != NULL ) - FOR( int ind = 0; ind < NS2SA( 16000, STEREO_DFT32MS_OVL_NS ); ind++ ) - { - hCPE->hStereoDft->buff_LBTCX_mem_fx[ind] = (Word32) ( hCPE->hStereoDft->buff_LBTCX_mem[ind] * ( 1 << q ) ); - } - // Function call goes here - stereo_dft_dec_core_switching_fx( hCPE, output_fx, synth_fx, hb_synth_fx, DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); - IF( DFT != NULL ) + FOR( int ch_ind = 0; ch_ind < n_channels; ch_ind++ ) { - FOR( i = 0; i < CPE_CHANNELS; i++ ) + if ( hCPE->hCoreCoder[ch_ind] != NULL ) + { + if ( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) + { + FOR( int ind = 0; ind < L_FRAME32k; ind++ ) + { + hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB[ind] = (float) hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx[ind] / (float) ( 1 << 11 ); + } + FOR( int ind = 0; ind < L_FRAME48k; ind++ ) + { + hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out[ind] = (float) hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx[ind] / (float) ( 1 << 11 ); + } + } + FOR( int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++ ) + { + hCPE->hCoreCoder[ch_ind]->delay_buf_out[ind] = (float) hCPE->hCoreCoder[ch_ind]->delay_buf_out32_fx[ind] / (float) ( 1 << 11 ); + } + if ( hCPE->hCoreCoder[ch_ind]->p_bpf_noise_buf_float != NULL ) + { + FOR( int ind = 0; ind < L_FRAME16k; ind++ ) + { + hCPE->hCoreCoder[ch_ind]->p_bpf_noise_buf_float[ind] = (float) hCPE->hCoreCoder[0]->p_bpf_noise_buf_32[ind] / (float) ( 1 << 11 ); + } + } + IF(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec != NULL) + { + FOR(Word32 p = 0; p < L_FRAME48k; p++) + { + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_out_32[p] / (1u << OUTPUT_Q); + } + FOR(Word32 p = 0; p < TCXLTP_MAX_DELAY; p++) + { + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); + } + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; + hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + } + IF(hCPE->hCoreCoder[ch_ind]->hTcxDec != NULL) + { + FOR(Word32 k = 0; k < 111; k++) + { + hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hCPE->hCoreCoder[ch_ind]->hTcxDec->FBTCXdelayBuf_32[k] / (1 << OUTPUT_Q); + } + } + } + if ( hCPE->input_mem_fx[ch_ind] ) { - FOR( Word16 j = 0; j < STEREO_DFT_BUF_MAX; j++ ) + FOR( i = 0; i < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ); i++ ) { - DFT[i][j] = (float) DFT_fx[i][j] / (float) ( 1 << q_DFT[i] ); + hCPE->input_mem[ch_ind][i] = (float) hCPE->input_mem_fx[ch_ind][i] / (float) ( 1 << 11 ); + } + } + IF(hCPE->output_mem[ch_ind] != NULL) + { + FOR(Word32 k = 0; k < NS2SA(hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS); k++) + { + hCPE->output_mem[ch_ind][k] = (float)hCPE->output_mem_fx[ch_ind][k] / (1u << 11); + } + } + if ( hCPE->input_mem_LB[ch_ind] ) + { + FOR( i = 0; i < STEREO_DFT32MS_OVL_16k; i++ ) + { + hCPE->input_mem_LB[ch_ind][i] = (float) hCPE->input_mem_LB_fx[ch_ind][i] / (float) ( 1 << 11 ); + } + } + if ( hCPE->input_mem_BPF[0] != NULL ) + { + FOR( i = 0; i < STEREO_DFT32MS_OVL_16k; i++ ) + hCPE->input_mem_BPF[0][i] = (float) hCPE->input_mem_BPF_fx[0][i] / (float) ( 1 << 11 ); + } + IF( hCPE->hStereoDft != NULL ) + { + FOR( int ind = 0; ind < NS2SA( 16000, DELAY_BWE_TOTAL_NS ); ind++ ) + { + hCPE->hStereoDft->ap_delay_mem[ind] = (float) hCPE->hStereoDft->ap_delay_mem_fx[ind] / (float) ( 1 << 11 ); + } + FOR( int ind = 0; ind < NS2SA( 16000, STEREO_DFT32MS_OVL_NS ); ind++ ) + { + hCPE->hStereoDft->buff_LBTCX_mem[ind] = (float) hCPE->hStereoDft->buff_LBTCX_mem_fx[ind] / (float) ( 1 << 11 ); + } + + IF(hCPE->hStereoDft->hTcxLtpDec != NULL) + { + FOR(Word32 p = 0; p < L_FRAME48k; p++) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / (1u << OUTPUT_Q); + } + FOR(Word32 p = 0; p < TCXLTP_MAX_DELAY; p++) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); + } + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } } - FOR( i = 0; i < STEREO_DFT32MS_OVL_16k; i++ ) - hCPE->input_mem_BPF[0][i] = (float) hCPE->input_mem_BPF_fx[0][i] / (float) ( 1 << q ); - FOR( i = 0; i < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ); i++ ) - hCPE->input_mem[0][i] = (float) hCPE->input_mem_fx[0][i] / (float) ( 1 << q ); - FOR( i = 0; i < STEREO_DFT32MS_OVL_16k; i++ ) - hCPE->input_mem_LB[0][i] = (float) hCPE->input_mem_LB_fx[0][i] / (float) ( 1 << q ); - FOR( i = 0; i < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ); i++ ) - hCPE->input_mem[1][i] = (float) hCPE->input_mem_fx[1][i] / (float) ( 1 << q ); - FOR( i = 0; i < STEREO_DFT32MS_OVL_16k; i++ ) - hCPE->input_mem_LB[1][i] = (float) hCPE->input_mem_LB_fx[1][i] / (float) ( 1 << q ); - IF( hCPE->hStereoDft != NULL ) - FOR( i = 0; i < NS2SA( 16000, DELAY_BWE_TOTAL_NS ); i++ ) - { - hCPE->hStereoDft->ap_delay_mem[i] = (float) hCPE->hStereoDft->ap_delay_mem_fx[i] / (float) ( 1 << q ); - } - IF( ( hCPE->hCoreCoder[0] != NULL ) && ( hCPE->hCoreCoder[0]->p_bpf_noise_buf_32 != NULL ) ) - FOR( i = 0; i < L_FRAME16k; i++ ) - { - hCPE->hCoreCoder[0]->p_bpf_noise_buf_float[i] = (float) hCPE->hCoreCoder[0]->p_bpf_noise_buf_32[i] / (float) ( 1 << q ); - } - FOR( i = 0; i < 960; i++ ) - { - output[0][i] = (float) output_fx[i] / (float) ( 1 << q ); - } - FOR( i = 0; i < hCPE->hCoreCoder[0]->output_Fs / FRAMES_PER_SEC; i++ ) - { - synth[0][i] = (float) synth_fx[i] / (float) ( 1 << q ); - hb_synth[0][i] = (float) hb_synth_fx[i] / (float) ( 1 << q ); - } - IF( hCPE->hCoreCoder[0] != NULL ) - FOR( i = 0; i < L_FRAME48k; i++ ) - { - hCPE->hCoreCoder[0]->hHQ_core->old_out[i] = (float) hCPE->hCoreCoder[0]->hHQ_core->oldOut_fx[i] / (float) ( 1 << q ); - } - IF( hCPE->hStereoDft != NULL ) - FOR( i = 0; i < NS2SA( 16000, STEREO_DFT32MS_OVL_NS ); i++ ) - { - hCPE->hStereoDft->buff_LBTCX_mem[i] = (float) hCPE->hStereoDft->buff_LBTCX_mem_fx[i] / (float) ( 1 << q ); - } - IF( hCPE->hCoreCoder[0] != NULL ) - FOR( i = 0; i < L_FRAME32k; i++ ) - { - hCPE->hCoreCoder[0]->hHQ_core->old_outLB[i] = (float) hCPE->hCoreCoder[0]->hHQ_core->old_outLB_fx[i] / (float) ( 1 << q ); - } -#else - stereo_dft_dec_core_switching( hCPE, output[0], synth[0], hb_synth[0], DFT, output_frame, use_cldfb_for_dft, 0 ); -#endif + } - if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + if ( hSCE != NULL ) + { + if ( hSCE->hCoreCoder[0] != NULL ) { - /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ - stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); + if ( hSCE->hCoreCoder[0]->hHQ_core != NULL ) + { + FOR( int ind = 0; ind < L_FRAME32k; ind++ ) + { + hSCE->hCoreCoder[0]->hHQ_core->old_outLB[ind] = (float) hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx[ind] / (float) ( 1 << 11 ); + } + FOR( int ind = 0; ind < L_FRAME48k; ind++ ) + { + hSCE->hCoreCoder[0]->hHQ_core->old_out[ind] = (float) hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx[ind] / (float) ( 1 << 11 ); + } + } + FOR( int ind = 0; ind < HQ_DELTA_MAX * HQ_DELAY_COMP; ind++ ) + { + hSCE->hCoreCoder[0]->delay_buf_out[ind] = (float) hSCE->hCoreCoder[0]->delay_buf_out32_fx[ind] / (float) ( 1 << 11 ); + } + IF(hSCE->hCoreCoder[0]->hTcxDec != NULL) + { + FOR(Word32 k = 0; k < 111; k++) + { + hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hSCE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[k] / (1 << OUTPUT_Q); + } + } + IF(hSCE->hCoreCoder[0]->hTcxLtpDec != NULL) + { + FOR(Word32 p = 0; p < L_FRAME48k; p++) + { + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] / (1u << OUTPUT_Q); + } + FOR(Word32 p = 0; p < TCXLTP_MAX_DELAY; p++) + { + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); + } + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; + hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + } } } - mvr2r( synth[n], output[n], output_frame ); - /*--------------------------------------------------------* * Common updates *--------------------------------------------------------*/ @@ -1457,7 +1544,7 @@ ivas_error ivas_core_dec( /* Save synthesis for HQ FEC */ #ifdef IVAS_FLOAT_FIXED Word32 exp_max = 0; - Word32 output_fx[L_FRAME48k]; + Word32 output_fx_loc[L_FRAME48k]; if ( ( st->codec_mode == MODE1 && st->hTcxDec != NULL ) && ( ( st->core == ACELP_CORE && !( st->bfi == 1 && st->con_tcx == 1 ) ) || st->core == HQ_CORE ) ) { double max_prev_synth_buffer = 0.0f, max_old_out = 0.0f, max_delay_buf_out = 0.0f, max_ouput = 0.0f, max_synth_history = 0.0f; @@ -1509,7 +1596,7 @@ ivas_error ivas_core_dec( { frexp( max_synth_history, &exp_synth_history ); } - + /*Find a commen maximum exp*/ exp_max = max( exp_synth_history, exp_ouput ); exp_max = max( exp_max, exp_prev_synth_buffer ); @@ -1534,17 +1621,18 @@ ivas_error ivas_core_dec( } for ( i = 0; i < output_frame; i++ ) { - f2fix( &output[n][i], &output_fx[i], exp_max ); + f2fix( &output[n][i], &output_fx_loc[i], exp_max ); } } - save_synthesis_hq_fec_fx( st, output_fx, output_frame, hCPE ); + save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); + save_synthesis_hq_fec(st, output[n], output_frame, hCPE); if ( ( st->codec_mode == MODE1 && st->hTcxDec != NULL ) && ( ( st->core == ACELP_CORE && !( st->bfi == 1 && st->con_tcx == 1 ) ) || st->core == HQ_CORE ) ) { /*dumps*/ float track = 0; - for ( i = 0; i < 2 * output_frame + NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS); i++ ) + for ( i = 0; i < 2 * output_frame + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); i++ ) { - fix2f_16( &st->hTcxDec->synth_history_fx[i], &track, exp_max ); + fix2f_16( &st->hTcxDec->synth_history_fx[i], &track, exp_max ); fix2f_16( &st->hTcxDec->synth_history_fx[i], &st->hTcxDec->synth_history[i], exp_max ); #ifdef DUMPS_ENABLED @@ -1566,3 +1654,682 @@ ivas_error ivas_core_dec( pop_wmops(); return error; } +#else +ivas_error ivas_core_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + const int16_t n_channels, /* i : number of channels to be decoded */ + float *output[], /* o : output synthesis signal */ + float hb_synth[][L_FRAME48k], /* o : output HB synthesis signal */ + float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +) +{ + int16_t i, n, output_frame; + Decoder_State **sts, *st; + STEREO_ICBWE_DEC_HANDLE hStereoICBWE; + STEREO_TD_DEC_DATA_HANDLE hStereoTD; + int16_t sharpFlag[CPE_CHANNELS]; + float synth[CPE_CHANNELS][L_FRAME48k]; + float tmp_buffer[L_FRAME48k]; + int16_t tmps, incr; + float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; + float voice_factors[CPE_CHANNELS][NB_SUBFR16k]; + int16_t core_switching_flag[CPE_CHANNELS]; + float old_syn_12k8_16k[CPE_CHANNELS][L_FRAME16k]; + float tmp; + float pitch_buf[CPE_CHANNELS][NB_SUBFR16k]; + int16_t unbits[CPE_CHANNELS]; + int16_t sid_bw[CPE_CHANNELS]; + FRAME_MODE frameMode[CPE_CHANNELS]; + float tdm_lspQ_PCh[M], tdm_lsfQ_PCh[M]; + int16_t tdm_LRTD_flag; + int32_t element_brate, output_Fs; + int32_t last_element_brate; + int16_t use_cldfb_for_dft; + float *p_output_mem; + int16_t flag_sec_CNA; + int16_t read_sid_info; + int16_t last_element_mode; + int16_t nchan_out; + float *save_hb_synth; + ivas_error error; + + error = IVAS_ERR_OK; + push_wmops( "ivas_core_dec" ); + + /*------------------------------------------------------------------* + * General initialization + *-----------------------------------------------------------------*/ + + use_cldfb_for_dft = 0; + tdm_LRTD_flag = -1; + read_sid_info = 1; /* read SID by default */ + + if ( hSCE != NULL ) + { + sts = hSCE->hCoreCoder; + hStereoICBWE = NULL; + element_brate = hSCE->element_brate; + last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ + last_element_mode = IVAS_SCE; + hStereoTD = NULL; + p_output_mem = NULL; + nchan_out = 1; + if ( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) + { + if ( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) + { + read_sid_info = 0; + } + } + } + else + { + sts = hCPE->hCoreCoder; + element_brate = hCPE->element_brate; + last_element_brate = hCPE->last_element_brate; + last_element_mode = hCPE->last_element_mode; + hStereoICBWE = hCPE->hStereoICBWE; + hStereoTD = hCPE->hStereoTD; + p_output_mem = hCPE->output_mem[1]; + nchan_out = hCPE->nchan_out; + + if ( hCPE->hStereoTD != NULL ) + { + tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; + } + + if ( sts[0]->element_mode == IVAS_CPE_DFT ) + { + use_cldfb_for_dft = ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ? 1 : 0; + } + } + + output_Fs = sts[0]->output_Fs; + output_frame = (int16_t) ( output_Fs / FRAMES_PER_SEC ); + + for ( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initialization per core-decoder channel + *-----------------------------------------------------------------*/ + + frameMode[n] = FRAMEMODE_NORMAL; + st->rate_switching_reset = 0; + + st->mdct_sw = MODE1; + + sid_bw[n] = -1; + core_switching_flag[n] = 0; + sharpFlag[n] = 0; + unbits[n] = 0; + st->GSC_IVAS_mode = 0; + st->element_brate = element_brate; + + st->use_partial_copy = 0; + st->rf_flag = 0; + st->rf_frame_type = RF_NO_DATA; + + if ( st->bfi == 1 ) + { + frameMode[n] = FRAMEMODE_MISSING; + st->coder_type = st->last_coder_type; + } + else + { + if ( !( st->element_mode == IVAS_CPE_TD && n == 1 ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + { + st->coder_type = INACTIVE; + } + st->extl = -1; + st->flagGuidedAcelp = 0; + } + + if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) + { + v_multc( st->hHQ_core->old_out, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_out, st->hTcxDec->L_frameTCX ); + v_multc( st->hHQ_core->old_outLB, st->hTcxDec->conceal_eof_gain_float * st->last_concealed_gain_syn_deemph_float, st->hHQ_core->old_outLB, st->L_frame ); + } + + set_f( voice_factors[n], 0.f, NB_SUBFR16k ); + set_f( hb_synth[n], 0.0f, L_FRAME48k ); + + /*------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *-----------------------------------------------------------------*/ + + if ( st->bfi != 1 ) + { + ivas_decision_matrix_dec( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); + + synchonize_channels_mdct_sid( sts, n ); + + if ( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ + { + st->sr_core = st->L_frame * FRAMES_PER_SEC; + st->fscale_old = st->fscale; + st->fscale = sr2fscale( st->sr_core ); + } + else + { + frameMode[n] = FRAMEMODE_MISSING; + } + } + else if ( st->element_mode >= IVAS_SCE && st->prev_bfi == 1 && st->last_con_tcx == 1 ) + { + st->core = TCX_20_CORE; + } + } /* n_channels loop */ + + /* MDCT stereo -> DFT stereo switching */ + if ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) + { + int16_t ovl, fade_len; + if ( sts[0]->L_frame != sts[0]->last_L_frame ) + { + lerp_flt( sts[0]->hHQ_core->old_outLB, sts[0]->hHQ_core->old_outLB, sts[0]->L_frame, sts[0]->last_L_frame ); + } + if ( sts[0]->L_frame != L_FRAME16k ) + { + ovl = (int16_t) ( STEREO_DFT32MS_OVL_16k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); + lerp_flt( hCPE->input_mem_LB[0], hCPE->input_mem_LB[0], ovl, STEREO_DFT32MS_OVL_16k ); + + fade_len = (int16_t) ( STEREO_MDCT2DFT_FADE_LEN_48k * ( (float) sts[0]->L_frame / L_FRAME16k ) ); + lerp_flt( hCPE->old_outLB_mdct, hCPE->old_outLB_mdct, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); + } + } + + if ( hCPE != NULL && hCPE->hStereoCng != NULL ) + { + hCPE->hStereoCng->flag_cna_fade = 0; + } + + if ( sba_dirac_stereo_flag && hSCE && sts[0]->total_brate <= SID_2k40 && sts[0]->cng_type == FD_CNG ) + { + save_hb_synth = hSCE->save_hb_synth; + } + else + { + save_hb_synth = NULL; + } + + /*------------------------------------------------------------------* + * Decode SID for MDCT-Stereo DTX mode + *-----------------------------------------------------------------*/ + + if ( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) + { + if ( sts[0]->cng_sba_flag ) + { + FdCngDecodeDiracMDCTStereoSID( hCPE ); + } + else + { + FdCngDecodeMDCTStereoSID( hCPE ); + } + } + + /*------------------------------------------------------------------* + * Sanity check in combined format coding + *-----------------------------------------------------------------*/ + + if ( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); + } + + /*------------------------------------------------------------------* + * Core Decoding + *-----------------------------------------------------------------*/ + + for ( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initialization + *-----------------------------------------------------------------*/ + + if ( st->bfi == 1 ) + { + st->nbLostCmpt++; + } + else + { + if ( st->prev_bfi == 1 ) + { + st->prev_nbLostCmpt = st->nbLostCmpt; + } + else + { + st->prev_nbLostCmpt = 0; + } + + st->nbLostCmpt = 0; + } + st->enablePlcWaveadjust = 0; + + if ( n == 1 ) + { + sts[1]->BER_detect |= sts[0]->BER_detect; + } + + /*---------------------------------------------------------------------* + * Detect bandwidth switching + *---------------------------------------------------------------------*/ + + bandwidth_switching_detect( st ); + + /*---------------------------------------------------------------------* + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + + if ( ( error = core_switching_pre_dec( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate ) ) != IVAS_ERR_OK ) + { + return error; + } + + flag_sec_CNA = -1; + if ( hCPE != NULL ) + { + flag_sec_CNA = sts[1]->flag_cna; + } + + /*---------------------------------------------------------------------* + * ACELP core decoding + * TCX core decoding + * HQ core decoding + *---------------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE ) + { + /* ACELP core decoder */ + if ( ( error = acelp_core_dec( st, output[n], synth[n], save_hb_synth, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], sharpFlag[n], pitch_buf[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh, tdm_lsfQ_PCh, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) + { + /* TCX decoder */ + stereo_tcx_core_dec( st, frameMode[n], output[n], synth[n], pitch_buf[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hCPE == NULL ? NULL : hCPE->hStereoCng, nchan_out, st_ivas == NULL ? 0 : st_ivas->ivas_format ); + } + + if ( st->core == HQ_CORE ) + { + /* HQ core decoder */ + hq_core_dec( st, synth[n], output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output[n] ); + } + + /*---------------------------------------------------------------------* + * TD stereo updates + *---------------------------------------------------------------------*/ + + if ( st->element_mode == IVAS_CPE_TD && n == 0 ) + { + td_stereo_param_updt( st->lsp_old, st->lsf_old, st->old_pitch_buf + st->nb_subfr, tdm_lspQ_PCh, tdm_lsfQ_PCh, hStereoTD->tdm_Pri_pitch_buf, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc ); + } + + } /* n_channels loop */ + + /*---------------------------------------------------------------------* + * MDCT stereo: joint TCX Core Decoding + *---------------------------------------------------------------------*/ + + if ( sts[0]->element_mode == IVAS_CPE_MDCT ) + { + /* active-frame decoding */ + if ( sts[0]->core_brate > SID_2k40 ) + { + if ( hMCT ) + { + pop_wmops(); + + return error; + } + else + { + stereo_mdct_core_dec( st_ivas, hCPE, output, synth ); + } + } + /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ + else if ( hCPE->nchan_out == 1 ) + { + updateBuffersForDmxMdctStereo( hCPE, output_frame, output, synth ); + } + + if ( sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) + { + /* On first good frame after frameloss undo the whitening of the bg noise shape */ + for ( n = 0; n < n_channels; ++n ) + { + if ( sts[n]->last_core_bfi != ACELP_CORE ) + { + TonalMdctConceal_whiten_noise_shape_ivas( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); + } + } + } + } + + /*---------------------------------------------------------------------* + * Stereo CNG updates + *---------------------------------------------------------------------*/ + + if ( sts[0]->element_mode == IVAS_CPE_TD && hCPE->hStereoCng != NULL ) + { + stereo_cng_compute_PScorr( output, &hCPE->hStereoCng->c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); + } + + /*---------------------------------------------------------------------* + * Postprocessing, BWEs and updates + *---------------------------------------------------------------------*/ + + for ( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*---------------------------------------------------------------------* + * TD-BWE for ACELP to TCX transitions + *---------------------------------------------------------------------*/ + + if ( st->last_core == ACELP_CORE && ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) && st->hBWE_TD != NULL ) + { + if ( ( st->bwidth == SWB || st->bwidth == FB ) && ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE ) ) + { + GenTransition( st->hBWE_TD, hb_synth[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); + } + else if ( st->bwidth == WB && st->last_extl == WB_TBE ) + { + GenTransition_WB( st->hBWE_TD, hb_synth[n], output_Fs ); + } + } + + /*---------------------------------------------------------------------* + * Postprocessing for ACELP/MDCT core switching + *---------------------------------------------------------------------*/ + + /* save synth and output in case of SBA DirAC stereo output as core switching is done outside of core decoder */ + if ( sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT && !( st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) ) + { + mvr2r( synth[n], hSCE->save_synth, output_frame ); + } + + if ( ( error = core_switching_post_dec( st, synth[n], output[n], p_output_mem, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ + if ( sba_dirac_stereo_flag && hSCE && st->core_brate == SID_2k40 && st->cng_type == FD_CNG ) + { + mvr2r( synth[n], hSCE->save_synth, output_frame ); + } + + /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ + if ( n == 0 && st->element_mode == IVAS_CPE_MDCT && st->last_core == ACELP_CORE && st->core != ACELP_CORE && ( nchan_out == 1 || ( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_DFT ) ) ) + { + mvr2r( sts[0]->previoussynth, sts[1]->previoussynth, st->hTcxDec->L_frameTCX ); + } + + /*---------------------------------------------------------------------* + * Pre-processing for bandwidth switching + *---------------------------------------------------------------------*/ + + bw_switching_pre_proc( st, old_syn_12k8_16k[n], last_element_brate, nchan_out ); + + /*---------------------------------------------------------------------* + * WB TBE decoding + * WB BWE decoding + *---------------------------------------------------------------------*/ + + if ( st->extl == WB_TBE ) + { + /* WB TBE decoder */ + wb_tbe_dec( st, bwe_exc_extended[n], voice_factors[n], hb_synth[n] ); + } + else if ( st->element_mode == IVAS_CPE_TD && n == 1 && !tdm_LRTD_flag && st->extl != -1 && st->bws_cnt == 0 && st->extl_brate == 0 ) + { + /* do nothing */ + } + else if ( st->extl == WB_BWE && st->bws_cnt == 0 ) + { + /* WB BWE decoder */ + wb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame, voice_factors[n], pitch_buf[n] ); + } + + /*---------------------------------------------------------------------* + * SWB(FB) TBE decoding + * SWB(FB) BWE decoding + *---------------------------------------------------------------------*/ + + if ( st->extl == SWB_TBE || st->extl == FB_TBE || ( st->coder_type != AUDIO && st->coder_type != INACTIVE && st->core_brate >= SID_2k40 && st->core == ACELP_CORE && !st->con_tcx && output_Fs >= 32000 && st->bwidth > NB && st->bws_cnt > 0 ) ) + { + /* SWB TBE decoder */ + swb_tbe_dec( st, hStereoICBWE, bwe_exc_extended[n], voice_factors[n], old_syn_12k8_16k[n], tmp_buffer /*fb_exc*/, hb_synth[n], pitch_buf[n] ); + + /* FB TBE decoder */ + if ( st->extl == FB_TBE ) + { + fb_tbe_dec( st, tmp_buffer /*fb_exc*/, hb_synth[n], tmp_buffer /*fb_synth_ref*/, output_frame ); + } + } + else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) + { + /* SWB BWE decoder */ + swb_bwe_dec_flt( st, output[n], synth[n], hb_synth[n], use_cldfb_for_dft, output_frame ); + } + + /*---------------------------------------------------------------------* + * FEC - recovery after lost HQ core (smoothing of the BWE component) + *---------------------------------------------------------------------*/ + + if ( st->prev_bfi && st->last_core == HQ_CORE && st->extl != -1 ) + { + tmp = FRAC_BWE_SMOOTH / output_frame; + + for ( i = 0; i < output_frame / FRAC_BWE_SMOOTH; i++ ) + { + hb_synth[n][i] *= ( i * tmp ); + } + } + + /*---------------------------------------------------------------------* + * SWB CNG + *---------------------------------------------------------------------*/ + + if ( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) + { + /* SHB CNG decoder */ + swb_CNG_dec( st, synth[n], hb_synth[n], sid_bw[n] ); + } + + /*-------------------------------------------------------------------* + * Inter-channel BWE decoding + *-------------------------------------------------------------------*/ + + if ( n == 0 && st->element_mode >= IVAS_CPE_DFT ) + { + stereo_icBWE_dec( hCPE, hb_synth[0], hb_synth[1], tmp_buffer /*fb_synth_ref*/, voice_factors[0], output_frame ); + } + + if ( st->element_mode == EVS_MONO ) + { + /*----------------------------------------------------------------* + * BFI waveform adjustment + *----------------------------------------------------------------*/ + + if ( st->core == ACELP_CORE && !st->bfi && st->prev_bfi && st->last_total_brate >= HQ_48k && st->last_codec_mode == MODE2 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hPlcInfo->concealment_method == TCX_NONTONAL && st->hPlcInfo->nbLostCmpt < 4 ) + { + tmps = NS2SA( output_Fs, DELAY_CLDFB_NS ); + + waveform_adj2( st->hPlcInfo, st->hTonalMDCTConc->secondLastPcmOut_float, synth[n] + tmps, tmps, st->hPlcInfo->nbLostCmpt + 1, st->bfi ); + + st->hPlcInfo->Pitch = 0; + } + } + + /*----------------------------------------------------------------* + * Transition and synchronization of BWE components + *----------------------------------------------------------------*/ + + if ( ( st->extl != -1 && ( st->extl != IGF_BWE || st->last_core == ACELP_CORE ) ) || ( st->bws_cnt > 0 && st->core == ACELP_CORE ) ) + { + /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ + if ( st->L_frame == L_FRAME ) + { + /* TBE on top of ACELP@12.8kHz */ + tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_12k8_NS ); + } + else + { + if ( st->extl == SWB_BWE_HIGHRATE || st->extl == FB_BWE_HIGHRATE ) + { + /* HR SWB BWE on top of ACELP@16kHz */ + tmps = NS2SA( output_Fs, DELAY_BWE_TOTAL_NS ); + } + else + { + /* TBE on top of ACELP@16kHz */ + tmps = NS2SA( output_Fs, MAX_DELAY_TBE_NS - DELAY_SWB_TBE_16k_NS ); + } + } + + /* Smooth transitions when switching between different technologies */ + if ( !( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || st->core == HQ_CORE ) && st->last_core == ACELP_CORE ) && + ( st->extl != st->last_extl || ( st->extl == st->last_extl && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( st->extl == SWB_CNG && st->last_extl == SWB_TBE ) && ( st->element_mode != IVAS_CPE_TD || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) ) + { + /* switching between BWE and TBE technologies */ + incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + for ( i = 0; i < tmps; i++ ) + { + hb_synth[n][i] *= sin_table256[i * incr]; + } + + set_f( st->hb_prev_synth_buffer, 0.0f, tmps ); + } + else if ( tmps < st->old_bwe_delay ) + { + /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ + incr = (int16_t) ( L_FRAME / ( tmps + 0.5f ) ); + for ( i = 0; i < tmps; i++ ) + { + tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr] + + st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + } + + mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); + } + else if ( tmps > st->old_bwe_delay ) + { + /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ + incr = (int16_t) ( L_FRAME / ( st->old_bwe_delay + 0.5f ) ); + for ( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer[i] = st->hb_prev_synth_buffer[i] * sin_table256[255 - i * incr]; + } + + for ( ; i < tmps; i++ ) + { + tmp_buffer[i] = 0.0f; + } + + for ( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer[tmps - 1 - i] += st->hb_prev_synth_buffer[st->old_bwe_delay - 1 - i] * sin_table256[i * incr]; + } + + mvr2r( tmp_buffer, st->hb_prev_synth_buffer, tmps ); + } + + if ( ( st->element_mode != IVAS_CPE_TD && !use_cldfb_for_dft ) || ( hCPE->element_mode == IVAS_CPE_TD && tdm_LRTD_flag ) ) + { + /* Delay hb_synth */ + delay_signal_float( hb_synth[n], output_frame, st->hb_prev_synth_buffer, tmps ); + } + else + { + mvr2r( hb_synth[n] + output_frame - tmps, st->hb_prev_synth_buffer, tmps ); + } + + st->old_bwe_delay = tmps; + if ( st->hBWE_TD != NULL ) + { + mvr2r( hb_synth[n], st->hBWE_TD->old_hb_synth, output_frame ); + } + + /* SWB CNG/DTX - calculate SHB energy */ + if ( output_frame >= L_FRAME32k && st->extl > SWB_CNG && st->core == ACELP_CORE && st->hTdCngDec != NULL ) + { + st->hTdCngDec->last_shb_ener = sum2_f( hb_synth[n], output_frame ) + 0.001f; + st->hTdCngDec->last_shb_ener /= (float) output_frame; + st->hTdCngDec->last_shb_ener = 10 * log10f( st->hTdCngDec->last_shb_ener ); + } + } + + if ( sba_dirac_stereo_flag && st->element_mode != IVAS_CPE_MDCT ) + { + /* for SBA DirAC stereo output DFT Stereo core switching and updates are done in ivas_sba_dirac_stereo_dec() as hCPE is not available at this point */ + break; + } + + /*----------------------------------------------------------------* + * Post-processing + * - TCX-LTP Postfilter (except DFT stereo) + * - core switching in DFT stereo + * - updates for potential TD->DFT stereo switching + *----------------------------------------------------------------*/ + + if ( st->element_mode != IVAS_CPE_DFT ) + { + if ( st->element_mode != IVAS_CPE_MDCT || sba_dirac_stereo_flag ) + { + ivas_post_proc( hSCE, hCPE, n, synth[n], NULL, output_frame, sba_dirac_stereo_flag ); + } + + /* update OLA buffers - needed for switching to DFT stereo */ + if ( !sba_dirac_stereo_flag ) + { + stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); + } + } + else /* IVAS_CPE_DFT */ + { + if ( hCPE->last_element_mode == IVAS_CPE_MDCT ) + { + stereo_mdct2dft_update( hCPE, output[0], synth[0] ); + } + + stereo_dft_dec_core_switching( hCPE, output[0], synth[0], hb_synth[0], DFT, output_frame, use_cldfb_for_dft, 0 ); + + if ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) + { + /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ + stereo_td2dft_update( hCPE, n, output[n], synth[n], hb_synth[n], output_frame ); + } + } + + mvr2r( synth[n], output[n], output_frame ); + + /*--------------------------------------------------------* + * Common updates + *--------------------------------------------------------*/ + + /* Save synthesis for HQ FEC */ + save_synthesis_hq_fec( st, output[n], output_frame, hCPE ); + + /* Updates */ + updt_dec_common( st, NORMAL_HQ_CORE, -1, output[n] ); + + } /* n_channels loop */ + + + pop_wmops(); + return error; +} +#endif \ No newline at end of file diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 70b7f1dc2..0f8eb79b5 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -280,45 +280,46 @@ ivas_error ivas_mct_dec( { #ifdef IVAS_FLOAT_FIXED Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 q = 11; for ( int p = 0; p < L_FRAME48k; p++ ) { - synth_fx[n][p] = (Word32) ( synth[n][p] * ONE_IN_Q14 ); + synth_fx[n][p] = (Word32) ( synth[n][p] * ( 1u << q ) ); if ( p < NS2SA( hCPE->hCoreCoder[n]->output_Fs, STEREO_DFT32MS_OVL_NS ) ) { - hCPE->output_mem_fx[0][p] = (Word32) ( hCPE->output_mem[0][p] * ONE_IN_Q14 ); - hCPE->output_mem_fx[1][p] = (Word32) ( hCPE->output_mem[1][p] * ONE_IN_Q14 ); + hCPE->output_mem_fx[0][p] = (Word32) ( hCPE->output_mem[0][p] * ( 1u << q ) ); + hCPE->output_mem_fx[1][p] = (Word32) ( hCPE->output_mem[1][p] * ( 1u << q ) ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } - if (!(NE_16(hCPE->hCoreCoder[n]->core, TCX_20_CORE) && NE_16(hCPE->hCoreCoder[n]->core, TCX_10_CORE))) + if ( !( NE_16( hCPE->hCoreCoder[n]->core, TCX_20_CORE ) && NE_16( hCPE->hCoreCoder[n]->core, TCX_10_CORE ) ) ) { - for (int k = 0; k < output_frame; k++) - { - hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx[k] = (Word32)(hCPE->hCoreCoder[n]->hHQ_core->old_out[k] * ONE_IN_Q14); - if (k < 111) + for ( int k = 0; k < output_frame; k++ ) { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32)(hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ONE_IN_Q14); - } - if (k < HQ_DELTA_MAX * HQ_DELAY_COMP) - { - hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32)(hCPE->hCoreCoder[n]->delay_buf_out[k] * ONE_IN_Q14); + hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->hHQ_core->old_out[k] * ( 1u << q ) ); + if ( k < 111 ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] * ( 1u << q ) ); + } + if ( k < HQ_DELTA_MAX * HQ_DELAY_COMP ) + { + hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] = (Word32) ( hCPE->hCoreCoder[n]->delay_buf_out[k] * ( 1u << q ) ); + } } - } } if ( !( ( hCPE->hCoreCoder[n]->element_mode != IVAS_CPE_DFT && !( st_ivas->sba_dirac_stereo_flag && hCPE->hCoreCoder[n]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[n]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) { for ( int p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ONE_IN_Q14 ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ONE_IN_Q14 ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); @@ -328,33 +329,33 @@ ivas_error ivas_mct_dec( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); for ( int p = 0; p < 111; p++ ) { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[p] * ( 1u << q ) ); } ivas_post_proc_fx( NULL, hCPE, n, synth_fx[n], NULL, output_frame, 1 ); for ( int p = 0; p < L_FRAME48k; p++ ) { - synth[n][p] = (float) synth_fx[n][p] / ONE_IN_Q14; + synth[n][p] = (float) synth_fx[n][p] / ( 1u << q ); if ( p < NS2SA( hCPE->hCoreCoder[n]->output_Fs, STEREO_DFT32MS_OVL_NS ) ) { - hCPE->output_mem[0][p] = (float) hCPE->output_mem_fx[0][p] / ONE_IN_Q14; - hCPE->output_mem[1][p] = (float) hCPE->output_mem_fx[1][p] / ONE_IN_Q14; + hCPE->output_mem[0][p] = (float) hCPE->output_mem_fx[0][p] / ( 1u << q ); + hCPE->output_mem[1][p] = (float) hCPE->output_mem_fx[1][p] / ( 1u << q ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ONE_IN_Q14; + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); } } - if (!(NE_16(hCPE->hCoreCoder[n]->core, TCX_20_CORE) && NE_16(hCPE->hCoreCoder[n]->core, TCX_10_CORE))) + if ( !( NE_16( hCPE->hCoreCoder[n]->core, TCX_20_CORE ) && NE_16( hCPE->hCoreCoder[n]->core, TCX_10_CORE ) ) ) { - for (int k = 0; k < 111; k++) - { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ONE_IN_Q14; - } + for ( int k = 0; k < 111; k++ ) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float) hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / ( 1u << q ); + } } hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; @@ -362,10 +363,10 @@ ivas_error ivas_mct_dec( { for ( int p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); } } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; @@ -470,7 +471,7 @@ ivas_error ivas_mct_dec( } save_synthesis_hq_fec_fx( sts[n], output_fx, output_frame, hCPE ); - + save_synthesis_hq_fec(sts[n], output[cpe_id * CPE_CHANNELS + n], output_frame, hCPE); if ( ( sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL ) && ( ( sts[n]->core == ACELP_CORE && !( sts[n]->bfi == 1 && sts[n]->con_tcx == 1 ) ) || sts[n]->core == HQ_CORE ) ) { /*dumps*/ diff --git a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c index 627e70b8c..9489f54ce 100644 --- a/lib_dec/ivas_sba_dirac_stereo_dec_fx.c +++ b/lib_dec/ivas_sba_dirac_stereo_dec_fx.c @@ -1182,7 +1182,7 @@ void ivas_sba_dirac_stereo_dec_fx( stereo_dft_dec_synthesize_fx( hCPE, DFT, 1, output[1], output_frame ); } - synchro_synthesis_fx( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); + synchro_synthesis_fixed_clean( st_ivas->hDecoderConfig->ivas_total_brate, hCPE, output, output_frame, 1 /*st_ivas->sba_dirac_stereo_flag*/ ); /* output scaling */ IF ( EQ_16(sba_mono_flag, 0) ) diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index ec9d619f5..0de7d716b 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -1192,35 +1192,36 @@ void synchro_synthesis( { #ifdef IVAS_FLOAT_FIXED Word32 *output_fx[2]; + Word16 q = 11; Word32 op[2][L_FRAME48k]; output_fx[0] = op[0]; output_fx[1] = op[1]; for ( int p = 0; p < L_FRAME48k; p++ ) { - output_fx[0][p] = (Word32) ( output[0][p] * ONE_IN_Q14 ); - output_fx[1][p] = (Word32) ( output[1][p] * ONE_IN_Q14 ); + output_fx[0][p] = (Word32) ( output[0][p] * ( 1u << q ) ); + output_fx[1][p] = (Word32) ( output[1][p] * ( 1u << q ) ); if ( p < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ) { - hCPE->output_mem_fx[0][p] = (Word32) ( hCPE->output_mem[0][p] * ONE_IN_Q14 ); - hCPE->output_mem_fx[1][p] = (Word32) ( hCPE->output_mem[1][p] * ONE_IN_Q14 ); + hCPE->output_mem_fx[0][p] = (Word32) ( hCPE->output_mem[0][p] * ( 1u << q ) ); + hCPE->output_mem_fx[1][p] = (Word32) ( hCPE->output_mem[1][p] * ( 1u << q ) ); } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } if ( !( ( hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[0]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) { for ( int p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ONE_IN_Q14 ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ONE_IN_Q14 ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); @@ -1230,26 +1231,26 @@ void synchro_synthesis( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); for ( int p = 0; p < 111; p++ ) { - hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float[p] * ( 1u << q ) ); } ivas_post_proc_fx( NULL, hCPE, 0, output_fx[0], output_fx, output_frame, sba_dirac_stereo_flag ); for ( int p = 0; p < L_FRAME48k; p++ ) { - output[0][p] = (float) output_fx[0][p] / ONE_IN_Q14; - output[1][p] = (float) output_fx[1][p] / ONE_IN_Q14; + output[0][p] = (float) output_fx[0][p] / ( 1u << q ); + output[1][p] = (float) output_fx[1][p] / ( 1u << q ); if ( p < NS2SA( output_Fs, STEREO_DFT32MS_OVL_NS ) ) { - hCPE->output_mem[0][p] = (float) hCPE->output_mem_fx[0][p] / ONE_IN_Q14; - hCPE->output_mem[1][p] = (float) hCPE->output_mem_fx[1][p] / ONE_IN_Q14; + hCPE->output_mem[0][p] = (float) hCPE->output_mem_fx[0][p] / ( 1u << q ); + hCPE->output_mem[1][p] = (float) hCPE->output_mem_fx[1][p] / ( 1u << q ); } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; + hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / ONE_IN_Q14; + hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); } } hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; @@ -1258,10 +1259,10 @@ void synchro_synthesis( { for ( int p = 0; p < L_FRAME48k; p++ ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); } } hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; @@ -1469,37 +1470,38 @@ void synchro_synthesis( #ifdef IVAS_FLOAT_FIXED Word32 *output_fx[2]; Word32 op[2][L_FRAME48k]; + Word16 q = 11; output_fx[0] = op[0]; output_fx[1] = op[1]; for ( int p = 0; p < L_FRAME48k; p++ ) { - output_fx[0][p] = (Word32) ( output[0][p] * ONE_IN_Q14 ); - output_fx[1][p] = (Word32) ( output[1][p] * ONE_IN_Q14 ); + output_fx[0][p] = (Word32) ( output[0][p] * ( 1u << q ) ); + output_fx[1][p] = (Word32) ( output[1][p] * ( 1u << q ) ); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << q ) ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); for ( int p = 0; p < 111; p++ ) { - hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[p] * ONE_IN_Q14 ); + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[p] * ( 1u << q ) ); } ivas_post_proc_fx( NULL, hCPE, n, output_fx[n], output_fx, output_frame, 0 ); for ( int p = 0; p < L_FRAME48k; p++ ) { - output[0][p] = (float) output_fx[0][p] / ONE_IN_Q14; - output[1][p] = (float) output_fx[1][p] / ONE_IN_Q14; + output[0][p] = (float) output_fx[0][p] / ( 1u << q ); + output[1][p] = (float) output_fx[1][p] / ( 1u << q ); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ONE_IN_Q14; + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); if ( p < TCXLTP_MAX_DELAY ) { - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ONE_IN_Q14; + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); } } hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; @@ -1558,361 +1560,6 @@ void synchro_synthesis( return; } -#ifdef IVAS_FLOAT_FIXED -void synchro_synthesis_fx( - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ - Word32 *output[CPE_CHANNELS], /* i/o: output synthesis signal */ - const Word16 output_frame, /* i : Number of samples */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ -) -{ - Word16 n, delay_comp_TD, delay_comp_DFT; - Word32 output_Fs; - Decoder_State **sts; - Word16 i, delay_cldfb, dft32ms_ovl; - Word32 *p_output_mem[CPE_CHANNELS]; - Word32 tmp_out[CPE_CHANNELS][NS2SA( 48000, DELAY_CLDFB_NS )]; - Word32 tmp_out_TD[CPE_CHANNELS][STEREO_DFT32MS_OVL_MAX]; - Word32 tmp_out_TD2[CPE_CHANNELS][STEREO_DFT32MS_OVL_MAX]; - Word16 use_cldfb_for_last_dft; - Word16 dft_mono_brate_switch; - Word16 delay_diff; - Word32 tmpF; - Word16 nChannels; - - sts = hCPE->hCoreCoder; - output_Fs = sts[0]->output_Fs; - - use_cldfb_for_last_dft = 0; - if ( ( hCPE->element_mode != IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_24k4 ) /* note: this is to mimic the DFT stereo condition "hCPE->hStereoDft->hConfig->res_cod_mode == 0" in last frame */ - || ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) - { - use_cldfb_for_last_dft = 1; - } - - dft_mono_brate_switch = 0; - if ( hCPE->element_mode == IVAS_CPE_DFT && ( hCPE->last_element_mode == IVAS_CPE_DFT || hCPE->last_element_mode == IVAS_CPE_MDCT ) && hCPE->nchan_out == 1 && hCPE->element_brate != hCPE->last_element_brate ) - { - if ( hCPE->last_element_brate >= IVAS_32k && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) - { - dft_mono_brate_switch = -1; /* switch from residual coding mode or MDCT Stereo */ - } - else if ( hCPE->last_element_brate <= IVAS_24k4 && hCPE->hStereoDft->hConfig->res_cod_mode > STEREO_DFT_RES_COD_OFF ) - { - dft_mono_brate_switch = 1; /* switch to residual coding mode*/ - } - } - - if ( use_cldfb_for_last_dft ) - { - if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_TD && ( ivas_total_brate > IVAS_SID_5k2 || hCPE->nchan_out == 2 ) ) - { - stereo_tca_scale_R_channel( hCPE, output[0], output_frame ); - } - } - - /* set delays */ - delay_comp_DFT = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); - delay_comp_TD = NS2SA( output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); - delay_diff = delay_comp_TD - delay_comp_DFT; - - dft32ms_ovl = (int16_t) ( ( STEREO_DFT32MS_OVL_MAX * output_Fs ) / 48000 ); - delay_cldfb = NS2SA( output_Fs, DELAY_CLDFB_NS ); - - /* initialize pointers */ - if ( hCPE->element_mode >= IVAS_CPE_DFT && hCPE->output_mem[0] != NULL ) - { - for ( n = 0; n < CPE_CHANNELS; n++ ) - { - p_output_mem[n] = (Word32 *) hCPE->output_mem[n]; - } - } - - /*----------------------------------------------------------------* - * DFT stereo synchro - *----------------------------------------------------------------*/ - - if ( hCPE->element_mode == IVAS_CPE_DFT || sba_dirac_stereo_flag ) - { - /* handling of bitrate switching from residual (using DFT) to non-residual mode (using CLDFB) for mono output - as in DFT->TD switching */ - if ( dft_mono_brate_switch == -1 ) - { - for ( i = delay_comp_DFT; i < delay_comp_TD; i++ ) - { - sts[0]->prev_synth_buffer[i] = (Float32) ( p_output_mem[0][i - delay_comp_DFT] ); - } - - for ( i = delay_comp_TD; i < delay_comp_TD + delay_cldfb; i++ ) - { - tmp_out[0][i - delay_comp_TD] = p_output_mem[0][i - delay_comp_DFT]; - } - } - - if ( hCPE->nchan_out == 1 && hCPE->last_element_mode == IVAS_CPE_MDCT ) - { - v_add( sts[0]->prev_synth_buffer, sts[1]->prev_synth_buffer, sts[0]->prev_synth_buffer, delay_comp_DFT ); - v_multc( sts[0]->prev_synth_buffer, INV_SQRT_2, sts[0]->prev_synth_buffer, delay_comp_DFT ); - } - - if ( use_cldfb_for_last_dft ) - { - /* delay CLDFB-based mono output (<= 24.4 kbps) to be aligned with DFT-based mono output (32 kbps), needed to avoid discontinuities with TCX-LTP. */ - mvr2r( sts[0]->prev_synth_buffer + delay_comp_DFT, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float, delay_diff ); - delay_signal_float( output[0], output_frame, hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float, delay_diff ); - } - - if ( hCPE->element_mode != IVAS_CPE_MDCT ) - { - ivas_post_proc( NULL, hCPE, 0, output[0], output, output_frame, sba_dirac_stereo_flag ); - } - - /* zero padding in order to synchronize the upmixed DFT stereo synthesis with the TD/MDCT stereo synthesis */ - for ( n = 0; n < hCPE->nchan_out; n++ ) - { - if ( sba_dirac_stereo_flag ) - { - delay_signal_float( output[n], output_frame, hCPE->prev_synth[n], delay_comp_DFT ); - } - else - { - delay_signal_float( output[n], output_frame, sts[n]->prev_synth_buffer, delay_comp_DFT ); - } - } - - if ( use_cldfb_for_last_dft ) - { - mvr2r( hCPE->hCoreCoder[0]->hTcxDec->FBTCXdelayBuf_float, sts[0]->prev_synth_buffer + delay_comp_DFT, delay_diff ); - } - - /* handling of TD->DFT switching */ - for ( n = 0; n < hCPE->nchan_out; n++ ) - { - if ( ( hCPE->last_element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag && dft_mono_brate_switch != -1 ) || dft_mono_brate_switch == 1 ) - { - Word32 *pPrev_synth; - Word16 inv_fade_len = 1.f / delay_diff; - - /* cross-fading between TD synchro memory and the DFT output */ - if ( sba_dirac_stereo_flag ) - { - pPrev_synth = hCPE->prev_synth_fx[n]; - } - else - { - pPrev_synth = sts[n]->prev_synth_buffer; - } - - if ( hCPE->last_element_mode != IVAS_CPE_MDCT ) - { - for ( i = delay_comp_DFT; i < delay_comp_TD; i++ ) - { - output[n][i] = ( pPrev_synth[i] * ( delay_comp_TD - i ) + output[n][i] * ( i - delay_comp_DFT ) ) * inv_fade_len; - } - } - } - else if ( dft_mono_brate_switch == -1 ) - { - float inv_fade_len_1 = 1.0f / (float) delay_diff; - float inv_fade_len_2 = 1.0f / (float) delay_cldfb; - - for ( i = 0; i < delay_diff; i++ ) - { - output[0][i + delay_comp_DFT] = (Word32) ( ( output[0][i + delay_comp_DFT] * ( delay_diff - i ) + p_output_mem[0][i] * i ) * inv_fade_len_1 ); - } - - for ( i = 0; i < delay_cldfb; i++ ) - { - output[0][i + delay_comp_TD] = (Word32) ( ( tmp_out[0][i] * ( delay_cldfb - i ) + output[0][i + delay_comp_TD] * i ) * inv_fade_len_2 ); - } - } - } - } - - /*----------------------------------------------------------------* - * TD/MDCT stereo synchro - *----------------------------------------------------------------*/ - - if ( sba_dirac_stereo_flag ) - { - return; - } - - if ( hCPE->element_mode == IVAS_CPE_TD || hCPE->element_mode == IVAS_CPE_MDCT ) - { - /* handling of DFT->TD switching */ - if ( hCPE->last_element_mode == IVAS_CPE_DFT && !use_cldfb_for_last_dft && hCPE->output_mem[0] != NULL ) - { - /* use redressed DFT stereo OLA part to reconstruct the TD stereo synchro memory */ - for ( n = 0; n < hCPE->nchan_out; n++ ) - { - for ( i = delay_comp_DFT; i < delay_comp_TD; i++ ) - { - sts[n]->prev_synth_buffer[i] = (Float32) p_output_mem[n][i - delay_comp_DFT]; - } - - for ( i = delay_comp_TD; i < delay_comp_TD + delay_cldfb; i++ ) - { - tmp_out[n][i - delay_comp_TD] = p_output_mem[n][i - delay_comp_DFT]; - } - } - } - - /* if previous frame had only one channel copy buffers to other channel */ - if ( hCPE->nchan_out == 1 && hCPE->element_mode == IVAS_CPE_MDCT && hCPE->last_element_mode == IVAS_CPE_DFT ) - { - mvr2r( sts[0]->prev_synth_buffer, sts[1]->prev_synth_buffer, delay_comp_TD ); - mvr2r( tmp_out[0], tmp_out[1], delay_cldfb ); - mvr2r( p_output_mem[0], p_output_mem[1], delay_diff ); - } - - /*----------------------------------------------------------------* - * update DFT synthesis overlap memory @output_Fs; needed for TD->DFT stereo switching - *----------------------------------------------------------------*/ - - /* resample LB synthesis to output_Fs */ - if ( hCPE->element_mode != IVAS_CPE_MDCT && !use_cldfb_for_last_dft ) - { - for ( n = 0; n < hCPE->nchan_out; n++ ) - { - if ( sts[n]->core == ACELP_CORE ) - { - lerp_flt( hCPE->input_mem_LB[n], tmp_out_TD[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); - } - else /* TCX/HQ core */ - { - lerp_flt( hCPE->input_mem_LB[n], tmp_out_TD[n], dft32ms_ovl, NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ) ); - - /* use TCX synchro memory (perfect signal is available) */ - for ( i = delay_diff; i < dft32ms_ovl; i++ ) - { - tmp_out_TD[n][i] = (Word32) sts[n]->delay_buf_out[i - delay_diff]; - } - } - } - - if ( hCPE->nchan_out == CPE_CHANNELS ) - { - /* upmix the resampled LB / the TCX synchro memory */ - tdm_upmix_plain( tmp_out_TD2[0], tmp_out_TD2[1], tmp_out_TD[0], tmp_out_TD[1], tdm_ratio_tabl[hCPE->hStereoTD->tdm_last_ratio_idx], tdm_den_ratio_tabl[hCPE->hStereoTD->tdm_last_ratio_idx], 0, dft32ms_ovl, 1 ); - } - else - { - mvr2r( tmp_out_TD[0], tmp_out_TD2[0], dft32ms_ovl ); - } - - for ( n = 0; n < hCPE->nchan_out; n++ ) - { - if ( sts[0]->core == ACELP_CORE ) /* ACELP core in primary channel */ - { - tmpF = 1.0f / (float) delay_diff; - - /* cross-fading between regular output synthesis and lerp_flt() resampled synthesis in 3.125 - 1.25 ms OLA part */ - for ( i = 0; i < delay_diff; i++ ) - { - p_output_mem[n][i] = ( output[n][output_frame - dft32ms_ovl + delay_cldfb + i] * ( delay_diff - i ) + tmp_out_TD2[n][i] * i ) * tmpF; - } - } - else /* TCX core */ - { - /* reconstruct the 3.125 - 1.25 ms OLA part */ - for ( i = 0; i < delay_diff; i++ ) - { - p_output_mem[n][i] = output[n][output_frame - dft32ms_ovl + delay_cldfb + i]; - } - } - - /* reconstruct the last 1.25 ms part of OLA window */ - for ( i = delay_diff; i < dft32ms_ovl; i++ ) - { - p_output_mem[n][i] = tmp_out_TD2[n][i]; - } - } - } - - /*----------------------------------------------------------------* - * zero padding TD/MDCT synthesis in order to synchronize - * the upmixed TD/MDCT stereo synthesis with the DFT stereo synthesis - *----------------------------------------------------------------*/ - - if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->stereo_switching_counter == 0 && hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_24k4 ) - { - float step; - tmpF = 1.0f; - step = 0.5f / delay_comp_TD; - - /* for the first switching frame from DFT to TD, downmix memory too */ - for ( n = 0; n < delay_comp_TD; n++ ) - { - sts[0]->prev_synth_buffer[n] = ( sts[0]->prev_synth_buffer[n] ) * tmpF; - tmpF -= step; - } - } - - if ( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->nchan_out == 1 && !is_DTXrate( hCPE->element_brate ) && is_DTXrate( hCPE->last_element_brate ) ) - { - mvr2r( sts[0]->prev_synth_buffer, sts[1]->prev_synth_buffer, delay_comp_TD ); - } - - nChannels = ( hCPE->element_mode == IVAS_CPE_MDCT ) ? 2 : hCPE->nchan_out; - for ( n = 0; n < nChannels; n++ ) - { - if ( hCPE->element_mode == IVAS_CPE_MDCT ) - { - mvr2r( sts[n]->prev_synth_buffer + delay_comp_DFT, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, delay_diff ); - delay_signal_float( output[n], output_frame, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, delay_diff ); - ivas_post_proc( NULL, hCPE, n, output[n], output, output_frame, 0 ); - delay_signal_float( output[n], output_frame, sts[n]->prev_synth_buffer, delay_comp_DFT ); - mvr2r( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, sts[n]->prev_synth_buffer + delay_comp_DFT, delay_diff ); - } - else - { - delay_signal_float( output[n], output_frame, sts[n]->prev_synth_buffer, delay_comp_TD ); - } - } - - /* handling of DFT->TD switching */ - if ( hCPE->last_element_mode == IVAS_CPE_DFT && !use_cldfb_for_last_dft ) - { - if ( hCPE->element_mode == IVAS_CPE_TD && hCPE->hStereoCng->prev_sid_nodata ) - { - for ( n = 0; n < hCPE->nchan_out; n++ ) - { - tmpF = 1.0f / (float) delay_cldfb; - - for ( i = 0; i < delay_cldfb; i++ ) - { - tmp_out[n][i] = tmp_out[n][i] * ( delay_cldfb - i ) * tmpF; - } - } - } - - /* cross-fading between DFT OLA memory and TD output */ - for ( n = 0; n < nChannels; n++ ) - { - if ( hCPE->element_mode == IVAS_CPE_MDCT ) - { - tmpF = 1.0f / (float) delay_diff; - - for ( i = 0; i < delay_diff; i++ ) - { - output[n][i + delay_comp_DFT] = ( output[n][i + delay_comp_DFT] * ( delay_diff - i ) + p_output_mem[n][i] * i ) * tmpF; - } - } - - tmpF = 1.0f / (float) delay_cldfb; - - for ( i = 0; i < delay_cldfb; i++ ) - { - output[n][i + delay_comp_TD] = ( tmp_out[n][i] * ( delay_cldfb - i ) + output[n][i + delay_comp_TD] * i ) * tmpF; - } - } - } - } - - return; -} -#endif #ifdef IVAS_FLOAT_FIXED void synchro_synthesis_fixed( @@ -3567,7 +3214,7 @@ void stereo_switching_dec( * * update OLA buffers - needed for switching from TD stereo to DFT stereo *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void stereo_td2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ const int16_t n, /* i : channel number */ @@ -3686,14 +3333,138 @@ void stereo_td2dft_update( return; } +#else +void stereo_td2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word16 n, /* i : channel number */ + Word32 output_fx[], /* i/o: synthesis @internal Fs */ + Word32 synth_fx[], /* i/o: synthesis @output Fs */ + Word32 hb_synth_fx[], /* i/o: hb synthesis */ + const Word16 output_frame /* i : frame length */ +) +{ + Word16 ovl, ovl_TCX, dft32ms_ovl, hq_delay_comp; + Word16 ns, nsLB; + Word16 old_out_len, old_outLB_len; + Decoder_State **sts; + + IF( hCPE == NULL ) + { + return; + } + + /* initialization */ + sts = hCPE->hCoreCoder; + ovl = NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + dft32ms_ovl = (Word16) ( ( STEREO_DFT32MS_OVL_MAX * sts[0]->output_Fs ) / 48000 ); + hq_delay_comp = NS2SA( sts[0]->output_Fs, DELAY_CLDFB_NS ); + + IF( hCPE->element_mode >= IVAS_CPE_DFT && hCPE->element_mode != IVAS_CPE_MDCT ) + { + IF( sts[n]->core == ACELP_CORE ) + { + IF( n == 0 ) + { + /* update DFT analysis overlap memory @internal_fs: core synthesis */ + Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); + + /* update DFT analysis overlap memory @internal_fs: BPF */ + IF( sts[n]->p_bpf_noise_buf_32 ) + { + Copy32( sts[n]->p_bpf_noise_buf_32 + sts[n]->L_frame - ovl, hCPE->input_mem_BPF_fx[n], ovl ); + } + + + /* update DFT analysis overlap memory @output_Fs: BWE */ + IF( sts[n]->extl != -1 || ( sts[n]->bws_cnt > 0 && sts[n]->core == ACELP_CORE ) ) + { + Copy32( hb_synth_fx + output_frame - dft32ms_ovl, hCPE->input_mem_fx[n], dft32ms_ovl ); + } + } + ELSE + { + /* update DFT analysis overlap memory @internal_fs: core synthesis, secondary channel */ + Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); + } + } + ELSE /* TCX core */ + { + /* LB-TCX synthesis */ + Copy32( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], ovl ); + + /* BPF */ + IF( n == 0 && sts[n]->p_bpf_noise_buf_32 ) + { + Copy32( sts[n]->p_bpf_noise_buf_32 + sts[n]->L_frame - ovl, hCPE->input_mem_BPF_fx[n], ovl ); + } + + /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ + IF( sts[n]->hTcxDec != NULL ) + { + ovl_TCX = NS2SA( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], ovl_TCX - hq_delay_comp ); + Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); + } + } + } + ELSE IF( hCPE->element_mode == IVAS_CPE_MDCT && hCPE->input_mem[0] != NULL ) + { + + /* update DFT stereo OLA memories */ + /*set_zero( hCPE->input_mem_LB[n], STEREO_DFT32MS_OVL_16k );*/ + L_lerp_fx_q11( output_fx + sts[n]->L_frame - ovl, hCPE->input_mem_LB_fx[n], STEREO_DFT32MS_OVL_16k, ovl ); + + + /* TCX synthesis (it was already delayed in TD stereo in core_switching_post_dec()) */ + IF( sts[n]->hTcxDec != NULL ) + { + ovl_TCX = NS2SA( sts[n]->hTcxDec->L_frameTCX * FRAMES_PER_SEC, STEREO_DFT32MS_OVL_NS ); + Copy32( synth_fx + sts[n]->hTcxDec->L_frameTCX + hq_delay_comp - ovl_TCX, hCPE->input_mem_fx[n], ovl_TCX - hq_delay_comp ); + Copy32( sts[n]->delay_buf_out32_fx, hCPE->input_mem_fx[n] + ovl_TCX - hq_delay_comp, hq_delay_comp ); + } + + IF( n == 1 ) + { + nsLB = NS2SA( sts[n]->L_frame * FRAMES_PER_SEC, N_ZERO_MDCT_NS ); + ns = NS2SA( sts[n]->output_Fs, N_ZERO_MDCT_NS ); + old_outLB_len = (Word16) ( ( 3 * STEREO_MDCT2DFT_FADE_LEN_48k * sts[0]->L_frame * FRAMES_PER_SEC ) / 48000 ); + old_out_len = (Word16) ( ( STEREO_MDCT2DFT_FADE_LEN_48k * sts[0]->output_Fs ) / 48000 ); + + /* update buffers used for fading when switching to DFT Stereo */ + v_add_fx( sts[0]->hHQ_core->old_outLB_fx + nsLB, sts[1]->hHQ_core->old_outLB_fx + nsLB, hCPE->old_outLB_mdct_fx, old_outLB_len ); + L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, STEREO_MDCT2DFT_FADE_LEN_48k, old_outLB_len ); + for ( int i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) + { + hCPE->old_outLB_mdct_fx[i] = L_shr( hCPE->old_outLB_mdct_fx[i], 1 ); + } + v_add_fx( sts[0]->hHQ_core->oldOut_fx + ns, sts[1]->hHQ_core->oldOut_fx + ns, hCPE->old_out_mdct_fx, old_out_len ); + for ( int i = 0; i < STEREO_MDCT2DFT_FADE_LEN_48k; i++ ) + { + hCPE->old_out_mdct_fx[i] = L_shr( hCPE->old_out_mdct_fx[i], 1 ); + } + } + IF( n == 0 ) + { + set32_fx( hCPE->input_mem_BPF_fx[n], 0, STEREO_DFT32MS_OVL_16k ); + } + } + + /* update ovl buffer for possible switching from TD stereo SCh ACELP frame to MDCT stereo TCX frame */ + IF( hCPE->element_mode == IVAS_CPE_TD && n == 1 && sts[n]->hTcxDec == NULL ) + { + Copy32( output_fx + sts[n]->L_frame / 2, hCPE->hStereoTD->TCX_old_syn_Overl_fx, sts[n]->L_frame / 2 ); + } + return; +} +#endif /*-------------------------------------------------------------------* * Function stereo_mdct2dft_update() * * update OLA buffers - needed for switching from MDCT stereo to DFT stereo *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void stereo_mdct2dft_update( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ float output0[], /* i/o: synthesis @internal Fs, ch0 */ @@ -3729,8 +3500,104 @@ void stereo_mdct2dft_update( return; } +#else +void stereo_mdct2dft_update_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + Word32 output0_fx[], /* i/o: synthesis @internal Fs, ch0 */ + Word32 synth0_fx[] /* i/o: synthesis @output Fs, ch0 */ +) +{ + int16_t i; + int16_t fade_len, fade_len_LB; + Word32 tmpF_fx = 0; + Decoder_State *st; + if ( hCPE == NULL ) + { + return; + } + + st = hCPE->hCoreCoder[0]; + + fade_len = (int16_t) ( ( STEREO_MDCT2DFT_FADE_LEN_48k * st->output_Fs ) / 48000 ); + fade_len_LB = (int16_t) ( 3 * ( STEREO_MDCT2DFT_FADE_LEN_48k * st->L_frame * FRAMES_PER_SEC ) / 48000 ); + switch ( st->output_Fs ) + { + case 16000: + tmpF_fx = 53687092; + break; + case 32000: + tmpF_fx = 26843546; + break; + case 48000: + tmpF_fx = 17895698; + break; + } + for ( i = 0; i < fade_len; i++ ) + { + Word32 descen_gain; + if ( i == 0 ) + { + descen_gain = ONE_IN_Q31; + } + else + { + descen_gain = ( fade_len - i ) * tmpF_fx; + } + + Word32 temp_a = Mpy_32_32( hCPE->old_out_mdct_fx[i], descen_gain ); + Word32 ascend_gain = i * tmpF_fx; + Word32 temp_b = Mpy_32_32( synth0_fx[i], ascend_gain ); + synth0_fx[i] = L_add_sat( temp_a, temp_b ); + } + + switch ( st->L_frame ) + { + case 80: + tmpF_fx = 71582792; + break; + case 160: + tmpF_fx = 35791396; + break; + case 256: + tmpF_fx = 22369622; + break; + case 320: + tmpF_fx = 17895698; + break; + case 512: + tmpF_fx = 11184811; + break; + case 640: + tmpF_fx = 8947849; + break; + case 960: + tmpF_fx = 5965232; + break; + default: + assert( 0 ); + } + for ( i = 0; i < fade_len_LB; i++ ) + { + Word32 descen_gain; + if ( i == 0 ) + { + descen_gain = ONE_IN_Q31; + } + else + { + descen_gain = ( fade_len_LB - i ) * tmpF_fx; + } + Word32 temp_a = Mpy_32_32( hCPE->old_outLB_mdct_fx[i], descen_gain ); + Word32 ascend_gain = i * tmpF_fx; + Word32 temp_b = Mpy_32_32( output0_fx[i], ascend_gain ); + output0_fx[i] = L_add_sat( temp_a, temp_b ); + } + + return; +} +#endif static float ncross_corr_self( float *signal, const int16_t x, -- GitLab