diff --git a/apps/decoder.c b/apps/decoder.c index 20cef71ab9280d5f8f8e1c9d5ae8ca2bdc14a886..80c33f9eef0b4f1bf91738f4f7ad04ffb982248e 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -111,6 +111,9 @@ typedef struct int16_t orientation_tracking; int16_t Opt_non_diegetic_pan; float non_diegetic_pan_gain; +#ifdef IVAS_FLOAT_FIXED + Word16 non_diegetic_pan_gain_fx; /* Q15 */ +#endif bool renderConfigEnabled; char *renderConfigFilename; IVAS_DEC_COMPLEXITY_LEVEL complexityLevel; @@ -371,8 +374,13 @@ int main( *------------------------------------------------------------------------------------------*/ asked_frame_size = arg.renderFramesize; +#ifndef IVAS_FLOAT_FIXED if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.Opt_non_diegetic_pan, arg.non_diegetic_pan_gain, arg.Opt_dpid_on, arg.acousticEnvironmentId, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) +#else + if ( ( error = IVAS_DEC_Configure( hIvasDec, arg.output_Fs, arg.outputConfig, arg.tsmEnabled, arg.renderFramesize, arg.customLsOutputEnabled, arg.hrtfReaderEnabled, arg.enableHeadRotation, arg.enableExternalOrientation, arg.orientation_tracking, arg.renderConfigEnabled, arg.Opt_non_diegetic_pan, arg.non_diegetic_pan_gain_fx, + arg.Opt_dpid_on, arg.acousticEnvironmentId, arg.delayCompensationEnabled ) ) != IVAS_ERR_OK ) +#endif { fprintf( stderr, "\nConfigure failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) ); @@ -1064,6 +1072,17 @@ static bool parseCmdlIVAS_dec( return false; } } +#ifdef IVAS_FLOAT_FIXED + if ( arg->non_diegetic_pan_gain == 1.0f ) + { + arg->non_diegetic_pan_gain_fx = 32767; + } + else + { + arg->non_diegetic_pan_gain_fx = (Word16) ( arg->non_diegetic_pan_gain * ( 1u << 15 ) ); + } + +#endif i++; } else if ( strcmp( argv_to_upper, "-LEVEL" ) == 0 ) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index cb4ea8b34e1fef83f70f5901b5f9c80955e2c0f2..5d0864ce8ba017548e2d5f020fd2a0e7f86fd4bd 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -380,13 +380,14 @@ ivas_error ivas_output_buff_dec_fx( const Word16 nchan_out_buff_old, /* i : previous frame number of output channels */ const Word16 nchan_out_buff /* i : number of output channels */ ); -#endif // IVAS_FLOAT_FIXED +#else ivas_error ivas_output_buff_dec( float *p_output_f[], /* i/o: output audio buffers */ const int16_t nchan_out_buff_old, /* i : previous frame number of output channels*/ const int16_t nchan_out_buff /* i : number of output channels */ ); +#endif ivas_error stereo_dmx_evs_init_encoder( STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS, /* o : Stereo downmix for EVS encoder handle */ @@ -1066,6 +1067,12 @@ void ivas_jbm_dec_feed_tc_to_renderer( int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ float *data /* i/o: transport channels/output synthesis signal */ ); +void ivas_jbm_dec_feed_tc_to_renderer_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */ + Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ + Word32 *data /* i/o: transport channels/output synthesis signal */ +); ivas_error ivas_jbm_dec_set_discard_samples( Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */ @@ -4497,11 +4504,13 @@ ivas_error ivas_sba_digest_tc( float *data[] /* i : transport channel samples */ ); +#ifndef IVAS_FLOAT_FIXED void ivas_init_dec_get_num_cldfb_instances( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ int16_t *numCldfbAnalyses, /* o : number of CLDFB analysis instances */ int16_t *numCldfbSyntheses /* o : number of CLDFB synthesis instances */ ); +#endif // !IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED ivas_error ivas_cldfb_dec_reconfig_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 4cde97344461936ff7bd58ee2bea1d17a0288397..c0d8f21ed06a0d431c3032d9ce0a79f28d9ae529 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -669,6 +669,11 @@ Word16 param_mc_get_num_cldfb_syntheses_ivas_fx( Decoder_Struct *st_ivas /* i : Parametric MC handle */ ); #endif +void ivas_init_dec_get_num_cldfb_instances( + Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ + Word16 *numCldfbAnalyses, /* o : number of CLDFB analysis instances */ + Word16 *numCldfbSyntheses /* o : number of CLDFB synthesis instances */ +); /*file:ivas_init_dec_fx.c*/ void ivas_init_dec_get_num_cldfb_instances_ivas_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ diff --git a/lib_dec/gs_dec_amr_wb.c b/lib_dec/gs_dec_amr_wb.c index a6235c630117d9a2002effca6d1802e8000acb32..ef18c1238a72a067fee154cc07ed917685aa0ac6 100644 --- a/lib_dec/gs_dec_amr_wb.c +++ b/lib_dec/gs_dec_amr_wb.c @@ -42,6 +42,7 @@ #include "prot.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -428,3 +429,4 @@ void improv_amr_wb_gs( return; } +#endif diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 5ed51a26c6429c6b38ef68fe8b66e622682d8ea1..5104dcd24024feeefdd4e670965378bfabd7db65 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -1,2354 +1,2354 @@ -/****************************************************************************************************** - - (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -#include -#include "options.h" -#include -#include -#include "cnst.h" -#include "rom_com.h" -#include "prot.h" -#include "ivas_prot.h" -#include "ivas_prot_fx.h" -#include "ivas_rom_com.h" -#include "wmc_auto.h" -#ifdef IVAS_FLOAT_FIXED -#include "prot_fx.h" -#include "ivas_prot_fx.h" -#endif - -/*-------------------------------------------------------------------* - * ivas_core_dec() - * - * Principal IVAS core decoder routine, where number of core channels is 1 or 2 - *-------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED -ivas_error ivas_core_dec_fx( - 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 Word16 n_channels, /* i : number of channels to be decoded */ - Word32 *output_32_fx[], /* o : output synthesis signal */ - Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ - Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ -) -{ - Word16 i, n, output_frame; - Decoder_State **sts, *st; - STEREO_ICBWE_DEC_HANDLE hStereoICBWE; - STEREO_TD_DEC_DATA_HANDLE hStereoTD; - Word16 sharpFlag[CPE_CHANNELS]; - Word16 tmp_buffer_fx[L_FRAME48k]; - set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); - Word16 tmp16, tmp16_2, j; - tmp16 = 0; - move16(); - Word16 Q_white_exc; - Q_white_exc = 0; - move16(); - - Word16 tmps, incr; - Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; - - Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; - Word16 core_switching_flag[CPE_CHANNELS]; - - Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; - Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; - - Word16 unbits[CPE_CHANNELS]; - Word16 sid_bw[CPE_CHANNELS]; - FRAME_MODE frameMode[CPE_CHANNELS]; - Word16 tdm_LRTD_flag; - Word32 element_brate, output_Fs; - Word32 last_element_brate; - Word16 use_cldfb_for_dft; - Word32 *p_output_mem_fx; - Word16 flag_sec_CNA; - Word16 read_sid_info; - Word16 last_element_mode; - Word16 nchan_out; - Word32 *save_hb_synth_32_fx; - ivas_error error; - Word32 L_tmp; - Word16 Q_synth; - Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; - - Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; - Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; - - FOR( i = 0; i < CPE_CHANNELS; i++ ) - { - set16_fx( pitch_buf_fx[i], 0, NB_SUBFR16k ); - set16_fx( output_16_fx[i], 0, L_FRAME48k ); - } - - Word16 tdm_lsfQ_PCh_fx[M], tdm_lspQ_PCh_fx[M]; - Word32 conceal_eof_gain32; - -#ifdef BASOP_NOGLOB - Flag Overflow; -#endif - - error = IVAS_ERR_OK; - move32(); - push_wmops( "ivas_core_dec" ); - - /*------------------------------------------------------------------* - * General initialization - *-----------------------------------------------------------------*/ - - use_cldfb_for_dft = 0; - move16(); - tdm_LRTD_flag = -1; - move16(); - read_sid_info = 1; /* read SID by default */ - move16(); - - IF( hSCE != NULL ) - { - sts = hSCE->hCoreCoder; - hStereoICBWE = NULL; - element_brate = hSCE->element_brate; - move32(); - last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ - move32(); - last_element_mode = IVAS_SCE; - move16(); - hStereoTD = NULL; - p_output_mem_fx = NULL; - nchan_out = 1; - move16(); - test(); - IF( st_ivas != NULL && EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) - { - if ( NE_16( st_ivas->hISMDTX.sce_id_dtx, hSCE->sce_id ) ) - { - read_sid_info = 0; - move16(); - } - } - } - ELSE - { - sts = hCPE->hCoreCoder; - element_brate = hCPE->element_brate; - move32(); - last_element_brate = hCPE->last_element_brate; - move32(); - last_element_mode = hCPE->last_element_mode; - move16(); - hStereoICBWE = hCPE->hStereoICBWE; - hStereoTD = hCPE->hStereoTD; - p_output_mem_fx = hCPE->output_mem_fx[1]; - - nchan_out = hCPE->nchan_out; - move16(); - - if ( hCPE->hStereoTD != NULL ) - { - tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; - move16(); - } - - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) - { - test(); - IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) - { - use_cldfb_for_dft = 1; - move16(); - } - ELSE - { - use_cldfb_for_dft = 0; - move16(); - } - } - } - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbAna->Q_cldfb_state = Q10; - move16(); - } - IF( st->cldfbSynHB ) - { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbSynHB->Q_cldfb_state = Q10; - move16(); - } - } - - output_Fs = sts[0]->output_Fs; - move32(); - output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*------------------------------------------------------------------* - * Initialization per core-decoder channel - *-----------------------------------------------------------------*/ - - frameMode[n] = FRAMEMODE_NORMAL; - move32(); - st->rate_switching_reset = 0; - move16(); - st->mdct_sw = MODE1; - move16(); - sid_bw[n] = -1; - move16(); - core_switching_flag[n] = 0; - move16(); - sharpFlag[n] = 0; - move16(); - unbits[n] = 0; - move16(); - st->GSC_IVAS_mode = 0; - move16(); - st->element_brate = element_brate; - move32(); - st->use_partial_copy = 0; - move16(); - st->rf_flag = 0; - move16(); - st->rf_frame_type = RF_NO_DATA; - move16(); - - IF( EQ_16( st->bfi, 1 ) ) - { - frameMode[n] = FRAMEMODE_MISSING; - move32(); - st->coder_type = st->last_coder_type; - move16(); - } - ELSE - { - test(); - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ - { - st->coder_type = INACTIVE; - move16(); - } - st->extl = -1; - move16(); - st->flagGuidedAcelp = 0; - move16(); - } - - test(); - test(); - test(); - test(); - test(); -#ifdef NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID - IF( !st->bfi && st->prev_bfi && GT_32( st->total_brate, SID_2k40 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) -#else - IF( !st->bfi && st->prev_bfi && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) -#endif - { - conceal_eof_gain32 = L_shl( L_deposit_l( st->hTcxDec->conceal_eof_gain ), 1 ); - - FOR( i = 0; i < st->hTcxDec->L_frameTCX; i++ ) - { - L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); - L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); - L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); - st->hHQ_core->old_out_fx[i] = extract_l( L_tmp ); // Q0 - move16(); - } - - FOR( i = 0; i < st->L_frame; i++ ) - { - L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_LB_fx[i] ); - L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); - L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); - st->hHQ_core->old_out_LB_fx[i] = extract_l( L_tmp ); // Q0 - move16(); - } - } - - set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); - set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); - set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); - /*------------------------------------------------------------------* - * Decision matrix (selection of technologies) - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( NE_16( st->bfi, 1 ) ) - { - ivas_decision_matrix_dec_fx( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); - - synchonize_channels_mdct_sid_fx( sts, n ); - - IF( NE_16( 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 = L_mult0( st->L_frame, FRAMES_PER_SEC ); - move32(); - st->fscale_old = st->fscale; - move16(); - st->fscale = sr2fscale_fx( st->sr_core ); - move16(); - } - ELSE - { - frameMode[n] = FRAMEMODE_MISSING; - move32(); - } - } - ELSE IF( GE_16( st->element_mode, IVAS_SCE ) && EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_con_tcx, 1 ) ) - { - st->core = TCX_20_CORE; - move16(); - } - } /* n_channels loop */ - - /* MDCT stereo -> DFT stereo switching */ - test(); - test(); - IF( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) - { - Word16 ovl, fade_len; - IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) - { - Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); - 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 ); - Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); - } - IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) - { - ovl = mult( sts[0]->L_frame, 5120 ); /*STEREO_DFT32MS_OVL_16k/L_FRAME16k = 5/32 = 5120 (Q15)*/ - L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); - - fade_len = mult( sts[0]->L_frame, 12288 ); /* STEREO_MDCT2DFT_FADE_LEN_48k/L_FRAME16k = 3/8 = 12288 (Q15)*/ - L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); - } - } - - test(); - IF( hCPE != NULL && hCPE->hStereoCng != NULL ) - { - hCPE->hStereoCng->flag_cna_fade = 0; - move16(); - } - - test(); - test(); - test(); - IF( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) ) - { - save_hb_synth_32_fx = hSCE->save_hb_synth_fx; - } - ELSE - { - save_hb_synth_32_fx = NULL; - } - - /*------------------------------------------------------------------* - * Decode SID for MDCT-Stereo DTX mode - *-----------------------------------------------------------------*/ - - test(); - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) && EQ_32( sts[0]->total_brate, SID_2k40 ) ) - { - IF( sts[0]->cng_sba_flag ) - { - FdCngDecodeDiracMDCTStereoSID_fx( hCPE ); - } - ELSE - { - FdCngDecodeMDCTStereoSID_fx( hCPE ); - } - } - - /*------------------------------------------------------------------* - * Sanity check in combined format coding - *-----------------------------------------------------------------*/ - - test(); - test(); - IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) - { - ivas_combined_format_brate_sanity_fx( 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( EQ_16( st->bfi, 1 ) ) - { - st->nbLostCmpt = add( st->nbLostCmpt, 1 ); - move16(); - } - ELSE - { - IF( EQ_16( st->prev_bfi, 1 ) ) - { - st->prev_nbLostCmpt = st->nbLostCmpt; - move16(); - } - ELSE - { - st->prev_nbLostCmpt = 0; - move16(); - } - - st->nbLostCmpt = 0; - move16(); - } - st->enablePlcWaveadjust = 0; - move16(); - - IF( EQ_16( n, 1 ) ) - { - sts[1]->BER_detect = s_or( sts[1]->BER_detect, sts[0]->BER_detect ); - move16(); - } - - /*---------------------------------------------------------------------* - * Detect bandwidth switching - *---------------------------------------------------------------------*/ - - bandwidth_switching_detect_ivas_fx( st ); - - /*---------------------------------------------------------------------* - * Preprocessing (preparing) for ACELP/HQ core switching - *---------------------------------------------------------------------*/ - Word16 Q_olapBufferSynth, Q_olapBufferSynth2; - - Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ - Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ - move16(); - move16(); - - Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); - - IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) - { - return error; - } - - flag_sec_CNA = -1; - move16(); - IF( hCPE != NULL ) - { - flag_sec_CNA = sts[1]->flag_cna; - move16(); - } - - /*---------------------------------------------------------------------* - * ACELP core decoding - * TCX core decoding - * HQ core decoding - *---------------------------------------------------------------------*/ - - IF( EQ_16( st->core, ACELP_CORE ) ) - { - /* ACELP core decoder */ - Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; - set16_fx( output_16_fx[n], 0, L_FRAME48k ); - Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; - IF( save_hb_synth_32_fx ) - { - save_hb_synth_16_fx = save_hb_synth_fx_arr; - } - ELSE - { - save_hb_synth_16_fx = NULL; - } - - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbBPF ) - { - scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbBPF->Q_cldfb_state = Q10; - move16(); - } - IF( st->cldfbSyn ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); - st->cldfbSyn->Q_cldfb_state = Q10; - move16(); - } - - IF( st->hFdCngDec != NULL ) - { - Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); - st->hFdCngDec->msNoiseEst_exp = 27; - move16(); - - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); - } - - IF( hCPE == NULL ) - { - IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, NULL, read_sid_info ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - ELSE - { - IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE->hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) - { - return error; - } - } - - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); - Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ - st->cldfbAna->Q_cldfb_state = Q10; - move16(); - } - IF( st->cldfbBPF ) - { - scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbBPF->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbSyn ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbSyn->Q_cldfb_state = Q11; - move16(); - } - st->prev_Q_syn = st->Q_syn; - move16(); - - if ( save_hb_synth_32_fx ) - { - Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); - hSCE->q_save_hb_synth_fx = Q11; - move16(); - } - - Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q11, negate( Q1 ) ) ); - } - - Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); - - test(); - test(); - test(); - IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) - { - Word16 Qsyn_temp; - STEREO_CNG_DEC_HANDLE hStereoCng; - IVAS_FORMAT ivas_format; - - Qsyn_temp = st->Q_syn; - move16(); - st->Q_syn = 0; - move16(); - st->prev_Q_syn = st->Q_syn; - move16(); - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - move16(); - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - move16(); - st->mem_error = st->hBPF->pst_mem_deemp_err_fx; - move32(); - - /* TCX decoder */ - Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); - Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); - Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); - st->hFdCngDec->msNoiseEst_exp = 27; - move16(); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); - - IF( hCPE == NULL ) - { - hStereoCng = NULL; - } - ELSE - { - hStereoCng = hCPE->hStereoCng; - } - IF( st_ivas == NULL ) - { - ivas_format = 0; - move32(); - } - ELSE - { - ivas_format = st_ivas->ivas_format; - move32(); - } - stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); - st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; - move16(); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); - - IF( st->hTcxDec ) - { - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - move16(); - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - move16(); - st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; - move16(); - } - st->hBPF->pst_mem_deemp_err_fx = extract_l( st->mem_error ); - move16(); - } - - IF( EQ_16( st->core, HQ_CORE ) ) - { - /* HQ core decoder */ - Word16 Q_output; - - Q_output = 0; - move16(); - Q_synth = 0; - move16(); - - ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); - - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); -#ifdef MSAN_FIX - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); -#else - Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); -#endif - Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); - } - - /*---------------------------------------------------------------------* - * TD stereo updates - *---------------------------------------------------------------------*/ - - test(); - IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) - { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); - - td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, - tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc -#ifndef FIX_798_WRONG_CPY_OF_PITCH - , - Q6 -#endif - ); - - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); - } - - } /* n_channels loop */ - - - /*---------------------------------------------------------------------* - * MDCT stereo: joint TCX Core Decoding - *---------------------------------------------------------------------*/ - - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) ) - { - /* active-frame decoding */ - IF( GT_32( sts[0]->core_brate, SID_2k40 ) ) - { - IF( hMCT ) - { - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbSynHB ) - { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbSynHB->Q_cldfb_state = Q11; - move16(); - } - } - - pop_wmops(); - return error; - } - ELSE - { - Word16 e_sig; - Word16 ch; - - e_sig = 17; - move16(); - sts = hCPE->hCoreCoder; - FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) - { - st = sts[ch]; - - st->last_gain_syn_deemph = 0; - move16(); - IF( st->hHQ_core ) - { - st->hHQ_core->Q_fer_samples = 0; - move16(); - } -#ifdef FIX_778_STEREO_BRATE_SWITCHING - st->Q_syn = 0; - move16(); -#endif - st->prev_Q_syn = st->Q_syn; - move16(); - - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda_LB ) ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda ) ); - - IF( st->hTcxDec ) - { - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - move16(); - } - IF( st->hTcxDec ) - { - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - move16(); - } - } - - stereo_mdct_core_dec_fx( st_ivas, hCPE, output_32_fx, synth_16_fx ); - - FOR( ch = 0; ch < 2; ch++ ) - { - st = hCPE->hCoreCoder[ch]; - st->hHQ_core->Q_old_wtda_LB = st->Q_syn; - move16(); - st->hHQ_core->Q_old_wtda = st->Q_syn; - move16(); - } - -#ifdef MSAN_FIX - Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); - Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); -#else - Scale_sig( synth_16_fx[0], L_FRAME48k, sub( e_sig, 15 ) ); - Scale_sig( synth_16_fx[1], L_FRAME48k, sub( e_sig, 15 ) ); -#endif - } - } - /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ - ELSE IF( EQ_16( hCPE->nchan_out, 1 ) ) - { - sts[0] = hCPE->hCoreCoder[0]; - sts[1] = hCPE->hCoreCoder[1]; - - IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) - { - sts[0]->hHQ_core->exp_old_out = sub( 15, sts[0]->hHQ_core->Q_old_wtda ); - move16(); - sts[1]->hHQ_core->exp_old_out = sub( 15, sts[1]->hHQ_core->Q_old_wtda ); - move16(); - } - updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); - - IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) - { - sts[0]->hHQ_core->Q_old_wtda = sub( 15, sts[0]->hHQ_core->exp_old_out ); - move16(); - sts[1]->hHQ_core->Q_old_wtda = sub( 15, sts[1]->hHQ_core->exp_old_out ); - move16(); - } - } - - test(); - test(); -#ifdef NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES - /* On first good active frame after frameloss undo the whitening of the bg noise shape */ - IF( GT_32( sts[0]->core_brate, SID_2k40 ) && sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) -#else - IF( sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) - /* On first good frame after frameloss undo the whitening of the bg noise shape */ -#endif - { - FOR( n = 0; n < n_channels; ++n ) - { - IF( NE_16( sts[n]->last_core_bfi, ACELP_CORE ) ) - { - Scale_sig32( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27 ) ); - sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 27; - move16(); - - TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); - } - } - } - } - - /*---------------------------------------------------------------------* - * Stereo CNG updates - *---------------------------------------------------------------------*/ - - test(); - IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) - { - /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ - Word16 Q_c_PS_LT, Q_output; - Word32 c_PS_LT_fx; - - Q_c_PS_LT = 31; - move16(); - Q_output = 11; - move16(); - c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); - Q_c_PS_LT = Q31; - move16(); - - stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_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_fx = extract_h( c_PS_LT_fx ); - } - - /*---------------------------------------------------------------------* - * Postprocessing, BWEs and updates - *---------------------------------------------------------------------*/ - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - - /*---------------------------------------------------------------------* - * TD-BWE for ACELP to TCX transitions - *---------------------------------------------------------------------*/ - - /*core_switching_post_dec*/ - Q_synth = 0; - move16(); - if ( st->hHQ_core != NULL ) - { - st->hHQ_core->Q_old_postdec = 0; - move16(); - } - - /*------------------fix-to-fix-end-----------------------*/ - - Word16 output_mem_16_fx[L_FRAME48k]; - Word16 *p_output_mem_16; - - IF( p_output_mem_fx != NULL ) - { - p_output_mem_16 = output_mem_16_fx; - Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), negate( Q11 ) ); - } - ELSE - { - p_output_mem_16 = NULL; - set16_fx( output_mem_16_fx, 0, NS2SA( st->output_Fs, 3125000 ) ); - } - - Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q4, Q11 ) ); - - IF( st->hHQ_core != NULL ) - { - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); - st->hHQ_core->Q_old_wtda = 0; - move16(); - } - - /*size of synth is choosen as delay comp to start with*/ - /*-------------------cldfb-start-------------------------*/ - - IF( st->cldfbSyn != NULL ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); - st->cldfbSyn->Q_cldfb_state = Q4; - move16(); - } - - Word16 q_audio, old_syn_fx; - old_syn_fx = Q11; - move16(); - q_audio = Q12; - move16(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) - { - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && ( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) ) - { - GenTransition_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); - } - ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) - { - GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); - } - - /* Memories Scaling */ - Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); - } - - /* Memories Re-Scaling */ - IF( st->hBWE_TD != NULL ) - { - Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); - Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ) ); - } - /*---------------------------------------------------------------------* - * 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 */ - test(); - test(); - test(); - IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) - { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); - } - - IVAS_FORMAT ivas_format; - IF( st_ivas != NULL ) - { - ivas_format = st_ivas->ivas_format; - move32(); - } - ELSE - { - ivas_format = UNDEFINED_FORMAT; - move32(); - } - IF( hCPE != NULL ) - { - last_element_mode = hCPE->last_element_mode; - move16(); - } - ELSE - { - last_element_mode = IVAS_SCE; - move16(); - } - IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ivas_format, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) - { - return error; - } - - /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ - test(); - test(); - test(); - IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) - { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); - } - - /* 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 */ - test(); - test(); - test(); - test(); - test(); - test(); - IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) - { - Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); - } - /*---------------------------------------------------------------------* - * Pre-processing for bandwidth switching - *---------------------------------------------------------------------*/ - - ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); - - Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), Q11 ); - Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q11, Q4 ) ); - - - /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ - - IF( st->cldfbSyn != NULL ) - { - scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q11, Q4 ) ); - st->cldfbSyn->Q_cldfb_state = Q11; - move16(); - } - -#ifdef MSAN_FIX - Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); -#else - Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); -#endif - - /*------------------reset-code-start---------------------*/ - - test(); - test(); - IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) - { - test(); - if ( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) - { - st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; - move16(); - } - st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; - move16(); - st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; - move16(); - } - - /*---------------------------------------------------------------------* - * WB TBE decoding - * WB BWE decoding - *---------------------------------------------------------------------*/ - - Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; - Word16 Q_syn_hb; - - Q_input = 0; - move16(); - Q_hb_synth_fx = 0; - move16(); - Q_synth_fx = 0; - move16(); - - FD_BWE_DEC_HANDLE hBWE_FD; - hBWE_FD = st->hBWE_FD; - - Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, negate( Q11 ) ); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( Q11 ) ); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->extl, WB_TBE ) ) - { - /* WB TBE decoder */ - - ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) - { - /* do nothing */ - } - ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) - { - /* WB BWE decoder */ - Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); - } - - /* Memories Re-Scaling */ - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); - Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); - - IF( hBWE_FD != NULL ) - { - Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); - } - IF( st->hBWE_TD != NULL ) - { - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); - } - - /*---------------------------------------------------------------------* - * SWB(FB) TBE decoding - * SWB(FB) BWE decoding - *---------------------------------------------------------------------*/ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) - { - /* SWB TBE decoder */ - Q_white_exc = 0; - move16(); - - ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); - - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); - - IF( GT_16( Q_white_exc, 31 ) ) - { - Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); - Q_white_exc = 31; - move16(); - } - - /* FB TBE decoder */ - IF( EQ_16( st->extl, FB_TBE ) ) - { - fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); - } - } - ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) - { - /* SWB BWE decoder */ - Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); - - Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); - - Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); - } - - /*---------------------------------------------------------------------* - * FEC - recovery after lost HQ core (smoothing of the BWE component) - *---------------------------------------------------------------------*/ - - test(); - test(); - IF( st->prev_bfi && EQ_16( st->last_core, HQ_CORE ) && NE_16( st->extl, -1 ) ) - { - /*tmp = FRAC_BWE_SMOOTH/output_frame;*/ - tmp16 = shr( 410, shr( output_frame, 8 ) ); /* Q15 */ - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - tmp16 = 68; - move16(); - } - /*output_frame/FRAC_BWE_SMOOTH*/ - j = shr( output_frame, 1 ); - tmp16_2 = 0; - move16(); - FOR( i = 0; i < j; i++ ) - { - hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], tmp16_2 ); /* Q11 */ - move32(); -#ifdef BASOP_NOGLOB - tmp16_2 = add_o( tmp16_2, tmp16, &Overflow ); /* Q15 */ -#else - tmp16_2 = add( tmp16_2, tmp16 ); -#endif - } - } - - /*---------------------------------------------------------------------* - * SWB CNG - *---------------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) - { - /* SHB CNG decoder */ - Word16 synth_fxl[960]; /* Q-2 */ - Word16 q; - - q = 2; - move16(); - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( add( Q11, q ) ) ); -#ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); -#else - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); -#endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, sub( st->prev_Q_bwe_syn2, Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); - - swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); - - test(); - IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) - { - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); - } - -#ifndef FIX_826_PRECISION_LOST_AND_COMPL - Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); -#endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); - } - - /*-------------------------------------------------------------------* - * Inter-channel BWE decoding - *-------------------------------------------------------------------*/ - test(); - IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - Word16 q; - q = 11; - move16(); - - IF( hCPE->hStereoDft != NULL ) - { - hCPE->hStereoDft->td_gain_fx[0] = 1; - move32(); - } - Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( Q11, Q_white_exc ) ); - stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); -#ifdef MSAN_FIX - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag != 0 ) ) ) ) ) ) ) - { - Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); - Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); - } -#else - Scale_sig32( hb_synth_32_fx[0], L_FRAME48k, sub( Q11, q ) ); - Scale_sig32( hb_synth_32_fx[1], L_FRAME48k, sub( Q11, q ) ); -#endif - } - - IF( EQ_16( st->element_mode, EVS_MONO ) ) - { - /*----------------------------------------------------------------* - * BFI waveform adjustment - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) - { - tmps = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); - - waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, - &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, - st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); - - st->hPlcInfo->Pitch = 0; - move16(); - } - } - - /*----------------------------------------------------------------* - * Transition and synchronization of BWE components - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - test(); - IF( ( NE_16( st->extl, -1 ) && ( NE_16( 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( EQ_16( 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 - { - test(); - IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( 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 */ - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->last_core == ACELP_CORE ) && - ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && s_xor( st->core, st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) - { - /* switching between BWE and TBE technologies */ - incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); - tmp16 = 0; - move16(); - FOR( i = 0; i < tmps; i++ ) - { - hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], sin_table256_fx[tmp16] ); - move16(); - tmp16 = add( tmp16, incr ); - } - - set16_fx( st->hb_prev_synth_buffer_fx, 0, tmps ); - } - ELSE IF( LT_16( 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 = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); - tmp16 = 0; - move16(); - FOR( i = 0; i < tmps; i++ ) - { - -#ifndef FIX_826_PRECISION_LOST_AND_COMPL - tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ), 1 ) ) ); - move16(); - tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); - move16(); -#else - tmp_buffer_fx[i] = round_fx_sat( L_mac_sat( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ) ); - move16(); -#endif - - tmp16 = add( tmp16, incr ); - } - Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); - } - ELSE IF( GT_16( 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 = idiv1616( imult1616( L_FRAME, 2 ), add( shl( st->old_bwe_delay, 1 ), 1 ) ); - tmp16 = 0; - move16(); - FOR( i = 0; i < st->old_bwe_delay; i++ ) - { - tmp_buffer_fx[i] = mult_r( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); - move16(); - tmp16 = add( tmp16, incr ); - } - FOR( ; i < tmps; i++ ) - { - tmp_buffer_fx[i] = 0; - move16(); - } - tmp16 = 0; - move16(); - FOR( i = 0; i < st->old_bwe_delay; i++ ) - { - tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); - move16(); - tmp16 = add( tmp16, incr ); - } - - Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); - } - - test(); - test(); - test(); - IF( ( NE_16( st->element_mode, IVAS_CPE_TD ) && !use_cldfb_for_dft ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) - { - /* Delay hb_synth */ - Word32 hb_prev_synth_buffer_fx_32[111]; - - Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); - delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); - Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, negate( 11 ) ); - } - ELSE - { - Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); - } - - st->old_bwe_delay = tmps; - - /* SWB CNG/DTX - calculate SHB energy */ - test(); - test(); - test(); - IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && st->core == ACELP_CORE && st->hTdCngDec != NULL ) - { - Word16 exp; - Word32 fra; - SWITCH( output_frame ) - { - case L_FRAME8k: - tmp16 = 205; - move16(); - BREAK; /*Q15*/ - case L_FRAME16k: - tmp16 = 102; - move16(); - BREAK; /*Q15*/ - case L_FRAME32k: - tmp16 = 51; - move16(); - BREAK; /*Q15*/ - case L_FRAME48k: - tmp16 = 34; - move16(); - BREAK; /*Q15*/ - } - - L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ - - Word16 exp2; - exp = 20; - move16(); - Word32 L_tmp2 = sum2_32_fx( hb_synth_32_fx[n], output_frame, &exp ); - L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, 20, L_tmp2, exp, &exp ); - L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); - exp2 = norm_l( L_tmp ); - exp = sub( exp, exp2 ); - fra = BASOP_Util_Log2( L_shl_sat( L_tmp, exp2 ) ); - exp2 = norm_l( exp ); - L_tmp = L_shl( exp, exp2 ); - exp = sub( Q31, exp2 ); - L_tmp = BASOP_Util_Add_Mant32Exp( fra, 6, L_tmp, exp, &exp ); - // exp = sub( sub( 30, shl( sub( Q11, 0 ), 1 ) ), exp ); - L_tmp = Mpy_32_16_1( L_tmp, 24660 ); - exp = add( exp, 2 ); - st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 7 ) ) ); /*Q8*/ - move16(); - st->hTdCngDec->last_shb_ener_fx = L_shl_sat( L_tmp, sub( exp, 20 ) ); /*Q11*/ - move32(); - } - } - - test(); - IF( sba_dirac_stereo_flag && NE_16( 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( hCPE != NULL ) - { - FOR( Word32 ch_ind = 0; ch_ind < n_channels; ch_ind++ ) - { - IF( hCPE->hCoreCoder[ch_ind] != NULL ) - { - IF( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) - { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); - } - } - } - } - IF( hSCE != NULL ) - { - IF( hSCE->hCoreCoder[0] != NULL ) - { - IF( hSCE->hCoreCoder[0]->hHQ_core != NULL ) - { - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); - } - } - } - - Word16 exp_max; - Word32 output_fx_loc[L_FRAME48k]; - - exp_max = 0; - move16(); - IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) - { - test(); - IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || sba_dirac_stereo_flag ) - { - ivas_post_proc_fx( hSCE, hCPE, n, synth_32_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); - } - - /* update OLA buffers - needed for switching to DFT stereo */ - IF( !sba_dirac_stereo_flag ) - { - IF( hCPE != NULL ) - { - stereo_td2dft_update_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); - } - } - } - ELSE /* IVAS_CPE_DFT */ - { - Word16 q; - q = 11; - move16(); - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) - { - stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); - } - Word16 q_DFT[2] = { 3, 3 }; - move16(); - move16(); - - stereo_dft_dec_core_switching_fx( hCPE, output_32_fx[0], synth_32_fx[0], hb_synth_32_fx[0], DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); - - hCPE->hStereoDft->q_dft = s_min( q_DFT[0], q_DFT[1] ); - move16(); - - IF( DFT_fx != NULL ) - { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[0] ) ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); - } - - test(); - IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( 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_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); - } - } - - Copy32( synth_32_fx[n], output_32_fx[n], output_frame ); - - /*--------------------------------------------------------* - * Common updates - *--------------------------------------------------------*/ - - /*Scale Memories*/ - - test(); - test(); - test(); - test(); - test(); - IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) - { - Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; - move16(); - move16(); - move16(); - move16(); - move16(); - - Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( Q11 ) ); - st->q_prev_synth_buffer_fx = 0; - move16(); - - exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame ); - exp_ouput = add( exp_ouput, Q11 ); - exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - exp_prev_synth_buffer = add( exp_prev_synth_buffer, st->q_prev_synth_buffer_fx ); - exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ) ); - exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ) ); -#ifndef FIX_740_HQ_CORE_OVA - exp_synth_history += st->hTcxDec->q_synth_history_fx; -#endif - exp_max = s_min( exp_synth_history, exp_ouput ); - exp_max = s_min( exp_max, exp_prev_synth_buffer ); - exp_max = s_min( exp_max, exp_old_out ); - exp_max = s_min( exp_max, exp_delay_buf_out ); - - Copy32( output_32_fx[n], output_fx_loc, output_frame ); - - Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); - Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); - Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); - Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, st->Q_syn ) ); - - st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); - } - /* Save synthesis for HQ FEC */ - save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); - - /* Updates */ - - ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); - - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); - - } /* n_channels loop */ - - FOR( n = 0; n < n_channels; n++ ) - { - st = sts[n]; - IF( st->cldfbAna ) - { - scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbAna->Q_cldfb_state = Q11; - move16(); - } - IF( st->cldfbSynHB ) - { - scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); - st->cldfbSynHB->Q_cldfb_state = Q11; - move16(); - } - } - - 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; - } - -#ifdef NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID - if ( !st->bfi && st->prev_bfi && st->total_brate > SID_2k40 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) -#else - if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) -#endif - { - 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 ); - } - -#ifdef NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES - - /* On first good active frame after frameloss undo the whitening of the bg noise shape */ - if ( sts[0]->core_brate > SID_2k40 && sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) -#else - if ( sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) - /* On first good frame after frameloss undo the whitening of the bg noise shape */ -#endif - { - 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 +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +#include +#include "options.h" +#include +#include +#include "cnst.h" +#include "rom_com.h" +#include "prot.h" +#include "ivas_prot.h" +#include "ivas_prot_fx.h" +#include "ivas_rom_com.h" +#include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx.h" +#include "ivas_prot_fx.h" +#endif + +/*-------------------------------------------------------------------* + * ivas_core_dec() + * + * Principal IVAS core decoder routine, where number of core channels is 1 or 2 + *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_core_dec_fx( + 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 Word16 n_channels, /* i : number of channels to be decoded */ + Word32 *output_32_fx[], /* o : output synthesis signal */ + Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ + Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +) +{ + Word16 i, n, output_frame; + Decoder_State **sts, *st; + STEREO_ICBWE_DEC_HANDLE hStereoICBWE; + STEREO_TD_DEC_DATA_HANDLE hStereoTD; + Word16 sharpFlag[CPE_CHANNELS]; + Word16 tmp_buffer_fx[L_FRAME48k]; + set16_fx( tmp_buffer_fx, 0, L_FRAME48k ); + Word16 tmp16, tmp16_2, j; + tmp16 = 0; + move16(); + Word16 Q_white_exc; + Q_white_exc = 0; + move16(); + + Word16 tmps, incr; + Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; + + Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word16 core_switching_flag[CPE_CHANNELS]; + + Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; + Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; + + Word16 unbits[CPE_CHANNELS]; + Word16 sid_bw[CPE_CHANNELS]; + FRAME_MODE frameMode[CPE_CHANNELS]; + Word16 tdm_LRTD_flag; + Word32 element_brate, output_Fs; + Word32 last_element_brate; + Word16 use_cldfb_for_dft; + Word32 *p_output_mem_fx; + Word16 flag_sec_CNA; + Word16 read_sid_info; + Word16 last_element_mode; + Word16 nchan_out; + Word32 *save_hb_synth_32_fx; + ivas_error error; + Word32 L_tmp; + Word16 Q_synth; + Word16 output_16_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 hb_synth_16_fx[CPE_CHANNELS][L_FRAME48k]; + + Word16 synth_16_fx[CPE_CHANNELS][L_FRAME48k]; + Word32 synth_32_fx[CPE_CHANNELS][L_FRAME48k]; + + FOR( i = 0; i < CPE_CHANNELS; i++ ) + { + set16_fx( pitch_buf_fx[i], 0, NB_SUBFR16k ); + set16_fx( output_16_fx[i], 0, L_FRAME48k ); + } + + Word16 tdm_lsfQ_PCh_fx[M], tdm_lspQ_PCh_fx[M]; + Word32 conceal_eof_gain32; + +#ifdef BASOP_NOGLOB + Flag Overflow; +#endif + + error = IVAS_ERR_OK; + move32(); + push_wmops( "ivas_core_dec" ); + + /*------------------------------------------------------------------* + * General initialization + *-----------------------------------------------------------------*/ + + use_cldfb_for_dft = 0; + move16(); + tdm_LRTD_flag = -1; + move16(); + read_sid_info = 1; /* read SID by default */ + move16(); + + IF( hSCE != NULL ) + { + sts = hSCE->hCoreCoder; + hStereoICBWE = NULL; + element_brate = hSCE->element_brate; + move32(); + last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ + move32(); + last_element_mode = IVAS_SCE; + move16(); + hStereoTD = NULL; + p_output_mem_fx = NULL; + nchan_out = 1; + move16(); + test(); + IF( st_ivas != NULL && EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) + { + if ( NE_16( st_ivas->hISMDTX.sce_id_dtx, hSCE->sce_id ) ) + { + read_sid_info = 0; + move16(); + } + } + } + ELSE + { + sts = hCPE->hCoreCoder; + element_brate = hCPE->element_brate; + move32(); + last_element_brate = hCPE->last_element_brate; + move32(); + last_element_mode = hCPE->last_element_mode; + move16(); + hStereoICBWE = hCPE->hStereoICBWE; + hStereoTD = hCPE->hStereoTD; + p_output_mem_fx = hCPE->output_mem_fx[1]; + + nchan_out = hCPE->nchan_out; + move16(); + + if ( hCPE->hStereoTD != NULL ) + { + tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; + move16(); + } + + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) + { + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) + { + use_cldfb_for_dft = 1; + move16(); + } + ELSE + { + use_cldfb_for_dft = 0; + move16(); + } + } + } + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbAna->Q_cldfb_state = Q10; + move16(); + } + IF( st->cldfbSynHB ) + { + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); + } + } + + output_Fs = sts[0]->output_Fs; + move32(); + output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*------------------------------------------------------------------* + * Initialization per core-decoder channel + *-----------------------------------------------------------------*/ + + frameMode[n] = FRAMEMODE_NORMAL; + move32(); + st->rate_switching_reset = 0; + move16(); + st->mdct_sw = MODE1; + move16(); + sid_bw[n] = -1; + move16(); + core_switching_flag[n] = 0; + move16(); + sharpFlag[n] = 0; + move16(); + unbits[n] = 0; + move16(); + st->GSC_IVAS_mode = 0; + move16(); + st->element_brate = element_brate; + move32(); + st->use_partial_copy = 0; + move16(); + st->rf_flag = 0; + move16(); + st->rf_frame_type = RF_NO_DATA; + move16(); + + IF( EQ_16( st->bfi, 1 ) ) + { + frameMode[n] = FRAMEMODE_MISSING; + move32(); + st->coder_type = st->last_coder_type; + move16(); + } + ELSE + { + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + { + st->coder_type = INACTIVE; + move16(); + } + st->extl = -1; + move16(); + st->flagGuidedAcelp = 0; + move16(); + } + + test(); + test(); + test(); + test(); + test(); +#ifdef NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID + IF( !st->bfi && st->prev_bfi && GT_32( st->total_brate, SID_2k40 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) +#else + IF( !st->bfi && st->prev_bfi && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) +#endif + { + conceal_eof_gain32 = L_shl( L_deposit_l( st->hTcxDec->conceal_eof_gain ), 1 ); + + FOR( i = 0; i < st->hTcxDec->L_frameTCX; i++ ) + { + L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_fx[i] ); + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); + st->hHQ_core->old_out_fx[i] = extract_l( L_tmp ); // Q0 + move16(); + } + + FOR( i = 0; i < st->L_frame; i++ ) + { + L_tmp = Mpy_32_16_1( conceal_eof_gain32, st->hHQ_core->old_out_LB_fx[i] ); + L_tmp = Mpy_32_16_1( L_tmp, st->last_concealed_gain_syn_deemph ); + L_tmp = L_shl( L_tmp, st->last_concealed_gain_syn_deemph_e ); + st->hHQ_core->old_out_LB_fx[i] = extract_l( L_tmp ); // Q0 + move16(); + } + } + + set16_fx( voice_factors_fx[n], 0, NB_SUBFR16k ); + set32_fx( hb_synth_32_fx[n], 0, L_FRAME48k ); + set16_fx( hb_synth_16_fx[n], 0, L_FRAME48k ); + /*------------------------------------------------------------------* + * Decision matrix (selection of technologies) + *-----------------------------------------------------------------*/ + + test(); + test(); + IF( NE_16( st->bfi, 1 ) ) + { + ivas_decision_matrix_dec_fx( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); + + synchonize_channels_mdct_sid_fx( sts, n ); + + IF( NE_16( 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 = L_mult0( st->L_frame, FRAMES_PER_SEC ); + move32(); + st->fscale_old = st->fscale; + move16(); + st->fscale = sr2fscale_fx( st->sr_core ); + move16(); + } + ELSE + { + frameMode[n] = FRAMEMODE_MISSING; + move32(); + } + } + ELSE IF( GE_16( st->element_mode, IVAS_SCE ) && EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_con_tcx, 1 ) ) + { + st->core = TCX_20_CORE; + move16(); + } + } /* n_channels loop */ + + /* MDCT stereo -> DFT stereo switching */ + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) + { + Word16 ovl, fade_len; + IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) + { + Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); + 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 ); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); + } + IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) + { + ovl = mult( sts[0]->L_frame, 5120 ); /*STEREO_DFT32MS_OVL_16k/L_FRAME16k = 5/32 = 5120 (Q15)*/ + L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); + + fade_len = mult( sts[0]->L_frame, 12288 ); /* STEREO_MDCT2DFT_FADE_LEN_48k/L_FRAME16k = 3/8 = 12288 (Q15)*/ + L_lerp_fx_q11( hCPE->old_outLB_mdct_fx, hCPE->old_outLB_mdct_fx, fade_len, STEREO_MDCT2DFT_FADE_LEN_48k ); + } + } + + test(); + IF( hCPE != NULL && hCPE->hStereoCng != NULL ) + { + hCPE->hStereoCng->flag_cna_fade = 0; + move16(); + } + + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) ) + { + save_hb_synth_32_fx = hSCE->save_hb_synth_fx; + } + ELSE + { + save_hb_synth_32_fx = NULL; + } + + /*------------------------------------------------------------------* + * Decode SID for MDCT-Stereo DTX mode + *-----------------------------------------------------------------*/ + + test(); + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) && EQ_32( sts[0]->total_brate, SID_2k40 ) ) + { + IF( sts[0]->cng_sba_flag ) + { + FdCngDecodeDiracMDCTStereoSID_fx( hCPE ); + } + ELSE + { + FdCngDecodeMDCTStereoSID_fx( hCPE ); + } + } + + /*------------------------------------------------------------------* + * Sanity check in combined format coding + *-----------------------------------------------------------------*/ + + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) + { + ivas_combined_format_brate_sanity_fx( 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( EQ_16( st->bfi, 1 ) ) + { + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); + move16(); + } + ELSE + { + IF( EQ_16( st->prev_bfi, 1 ) ) + { + st->prev_nbLostCmpt = st->nbLostCmpt; + move16(); + } + ELSE + { + st->prev_nbLostCmpt = 0; + move16(); + } + + st->nbLostCmpt = 0; + move16(); + } + st->enablePlcWaveadjust = 0; + move16(); + + IF( EQ_16( n, 1 ) ) + { + sts[1]->BER_detect = s_or( sts[1]->BER_detect, sts[0]->BER_detect ); + move16(); + } + + /*---------------------------------------------------------------------* + * Detect bandwidth switching + *---------------------------------------------------------------------*/ + + bandwidth_switching_detect_ivas_fx( st ); + + /*---------------------------------------------------------------------* + * Preprocessing (preparing) for ACELP/HQ core switching + *---------------------------------------------------------------------*/ + Word16 Q_olapBufferSynth, Q_olapBufferSynth2; + + Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ + Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ + move16(); + move16(); + + Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); + + IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) + { + return error; + } + + flag_sec_CNA = -1; + move16(); + IF( hCPE != NULL ) + { + flag_sec_CNA = sts[1]->flag_cna; + move16(); + } + + /*---------------------------------------------------------------------* + * ACELP core decoding + * TCX core decoding + * HQ core decoding + *---------------------------------------------------------------------*/ + + IF( EQ_16( st->core, ACELP_CORE ) ) + { + /* ACELP core decoder */ + Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; + set16_fx( output_16_fx[n], 0, L_FRAME48k ); + Word16 save_hb_synth_fx_arr[L_FRAME48k], *save_hb_synth_16_fx; + IF( save_hb_synth_32_fx ) + { + save_hb_synth_16_fx = save_hb_synth_fx_arr; + } + ELSE + { + save_hb_synth_16_fx = NULL; + } + + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbBPF ) + { + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbBPF->Q_cldfb_state = Q10; + move16(); + } + IF( st->cldfbSyn ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); + st->cldfbSyn->Q_cldfb_state = Q10; + move16(); + } + + IF( st->hFdCngDec != NULL ) + { + Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); + st->hFdCngDec->msNoiseEst_exp = 27; + move16(); + + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); + } + + IF( hCPE == NULL ) + { + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, NULL, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE->hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); + Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ + st->cldfbAna->Q_cldfb_state = Q10; + move16(); + } + IF( st->cldfbBPF ) + { + scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbBPF->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbSyn ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbSyn->Q_cldfb_state = Q11; + move16(); + } + st->prev_Q_syn = st->Q_syn; + move16(); + + if ( save_hb_synth_32_fx ) + { + Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); + hSCE->q_save_hb_synth_fx = Q11; + move16(); + } + + Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q11, negate( Q1 ) ) ); + } + + Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); + + test(); + test(); + test(); + IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + Word16 Qsyn_temp; + STEREO_CNG_DEC_HANDLE hStereoCng; + IVAS_FORMAT ivas_format; + + Qsyn_temp = st->Q_syn; + move16(); + st->Q_syn = 0; + move16(); + st->prev_Q_syn = st->Q_syn; + move16(); + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + st->mem_error = st->hBPF->pst_mem_deemp_err_fx; + move32(); + + /* TCX decoder */ + Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); + Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); + Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); + st->hFdCngDec->msNoiseEst_exp = 27; + move16(); + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); + + IF( hCPE == NULL ) + { + hStereoCng = NULL; + } + ELSE + { + hStereoCng = hCPE->hStereoCng; + } + IF( st_ivas == NULL ) + { + ivas_format = 0; + move32(); + } + ELSE + { + ivas_format = st_ivas->ivas_format; + move32(); + } + stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); + st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; + move16(); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); + + IF( st->hTcxDec ) + { + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; + move16(); + } + st->hBPF->pst_mem_deemp_err_fx = extract_l( st->mem_error ); + move16(); + } + + IF( EQ_16( st->core, HQ_CORE ) ) + { + /* HQ core decoder */ + Word16 Q_output; + + Q_output = 0; + move16(); + Q_synth = 0; + move16(); + + ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); + + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); +#ifdef MSAN_FIX + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); +#else + Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); +#endif + Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); + } + + /*---------------------------------------------------------------------* + * TD stereo updates + *---------------------------------------------------------------------*/ + + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) + { + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); + + td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, + tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc +#ifndef FIX_798_WRONG_CPY_OF_PITCH + , + Q6 +#endif + ); + + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); + } + + } /* n_channels loop */ + + + /*---------------------------------------------------------------------* + * MDCT stereo: joint TCX Core Decoding + *---------------------------------------------------------------------*/ + + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) ) + { + /* active-frame decoding */ + IF( GT_32( sts[0]->core_brate, SID_2k40 ) ) + { + IF( hMCT ) + { + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbSynHB ) + { + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); + } + } + + pop_wmops(); + return error; + } + ELSE + { + Word16 e_sig; + Word16 ch; + + e_sig = 17; + move16(); + sts = hCPE->hCoreCoder; + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = sts[ch]; + + st->last_gain_syn_deemph = 0; + move16(); + IF( st->hHQ_core ) + { + st->hHQ_core->Q_fer_samples = 0; + move16(); + } +#ifdef FIX_778_STEREO_BRATE_SWITCHING + st->Q_syn = 0; + move16(); +#endif + st->prev_Q_syn = st->Q_syn; + move16(); + + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda_LB ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda ) ); + + IF( st->hTcxDec ) + { + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + } + IF( st->hTcxDec ) + { + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + } + } + + stereo_mdct_core_dec_fx( st_ivas, hCPE, output_32_fx, synth_16_fx ); + + FOR( ch = 0; ch < 2; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + st->hHQ_core->Q_old_wtda_LB = st->Q_syn; + move16(); + st->hHQ_core->Q_old_wtda = st->Q_syn; + move16(); + } + +#ifdef MSAN_FIX + Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); +#else + Scale_sig( synth_16_fx[0], L_FRAME48k, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], L_FRAME48k, sub( e_sig, 15 ) ); +#endif + } + } + /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ + ELSE IF( EQ_16( hCPE->nchan_out, 1 ) ) + { + sts[0] = hCPE->hCoreCoder[0]; + sts[1] = hCPE->hCoreCoder[1]; + + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) + { + sts[0]->hHQ_core->exp_old_out = sub( 15, sts[0]->hHQ_core->Q_old_wtda ); + move16(); + sts[1]->hHQ_core->exp_old_out = sub( 15, sts[1]->hHQ_core->Q_old_wtda ); + move16(); + } + updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); + + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) + { + sts[0]->hHQ_core->Q_old_wtda = sub( 15, sts[0]->hHQ_core->exp_old_out ); + move16(); + sts[1]->hHQ_core->Q_old_wtda = sub( 15, sts[1]->hHQ_core->exp_old_out ); + move16(); + } + } + + test(); + test(); +#ifdef NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES + /* On first good active frame after frameloss undo the whitening of the bg noise shape */ + IF( GT_32( sts[0]->core_brate, SID_2k40 ) && sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) +#else + IF( sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) + /* On first good frame after frameloss undo the whitening of the bg noise shape */ +#endif + { + FOR( n = 0; n < n_channels; ++n ) + { + IF( NE_16( sts[n]->last_core_bfi, ACELP_CORE ) ) + { + Scale_sig32( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27 ) ); + sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 27; + move16(); + + TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); + } + } + } + } + + /*---------------------------------------------------------------------* + * Stereo CNG updates + *---------------------------------------------------------------------*/ + + test(); + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) + { + /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ + Word16 Q_c_PS_LT, Q_output; + Word32 c_PS_LT_fx; + + Q_c_PS_LT = 31; + move16(); + Q_output = 11; + move16(); + c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); + Q_c_PS_LT = Q31; + move16(); + + stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_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_fx = extract_h( c_PS_LT_fx ); + } + + /*---------------------------------------------------------------------* + * Postprocessing, BWEs and updates + *---------------------------------------------------------------------*/ + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + + /*---------------------------------------------------------------------* + * TD-BWE for ACELP to TCX transitions + *---------------------------------------------------------------------*/ + + /*core_switching_post_dec*/ + Q_synth = 0; + move16(); + if ( st->hHQ_core != NULL ) + { + st->hHQ_core->Q_old_postdec = 0; + move16(); + } + + /*------------------fix-to-fix-end-----------------------*/ + + Word16 output_mem_16_fx[L_FRAME48k]; + Word16 *p_output_mem_16; + + IF( p_output_mem_fx != NULL ) + { + p_output_mem_16 = output_mem_16_fx; + Copy_Scale_sig_32_16( p_output_mem_fx, p_output_mem_16, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ), negate( Q11 ) ); + } + ELSE + { + p_output_mem_16 = NULL; + set16_fx( output_mem_16_fx, 0, NS2SA( st->output_Fs, 3125000 ) ); + } + + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q4, Q11 ) ); + + IF( st->hHQ_core != NULL ) + { + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); + st->hHQ_core->Q_old_wtda = 0; + move16(); + } + + /*size of synth is choosen as delay comp to start with*/ + /*-------------------cldfb-start-------------------------*/ + + IF( st->cldfbSyn != NULL ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); + st->cldfbSyn->Q_cldfb_state = Q4; + move16(); + } + + Word16 q_audio, old_syn_fx; + old_syn_fx = Q11; + move16(); + q_audio = Q12; + move16(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->hBWE_TD != NULL ) + { + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) && ( EQ_16( st->last_extl, SWB_TBE ) || EQ_16( st->last_extl, FB_TBE ) ) ) + { + GenTransition_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs, st->element_mode, st->L_frame, st->rf_flag, st->total_brate ); + } + ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) + { + GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); + } + + /* Memories Scaling */ + Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); + } + + /* Memories Re-Scaling */ + IF( st->hBWE_TD != NULL ) + { + Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); + Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ) ); + } + /*---------------------------------------------------------------------* + * 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 */ + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) + { + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); + } + + IVAS_FORMAT ivas_format; + IF( st_ivas != NULL ) + { + ivas_format = st_ivas->ivas_format; + move32(); + } + ELSE + { + ivas_format = UNDEFINED_FORMAT; + move32(); + } + IF( hCPE != NULL ) + { + last_element_mode = hCPE->last_element_mode; + move16(); + } + ELSE + { + last_element_mode = IVAS_SCE; + move16(); + } + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ivas_format, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) + { + return error; + } + + /* for FD-CNG we need the delay compensation in the synth, so do this afterwards */ + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) + { + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); + } + + /* 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 */ + test(); + test(); + test(); + test(); + test(); + test(); + IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) + { + Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); + } + /*---------------------------------------------------------------------* + * Pre-processing for bandwidth switching + *---------------------------------------------------------------------*/ + + ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); + + Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), Q11 ); + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q11, Q4 ) ); + + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + IF( st->cldfbSyn != NULL ) + { + scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q11, Q4 ) ); + st->cldfbSyn->Q_cldfb_state = Q11; + move16(); + } + +#ifdef MSAN_FIX + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); +#else + Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); +#endif + + /*------------------reset-code-start---------------------*/ + + test(); + test(); + IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) + { + test(); + if ( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) + { + st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; + move16(); + } + st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; + move16(); + st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; + move16(); + } + + /*---------------------------------------------------------------------* + * WB TBE decoding + * WB BWE decoding + *---------------------------------------------------------------------*/ + + Word16 Q_input, Q_hb_synth_fx, Q_synth_fx; + Word16 Q_syn_hb; + + Q_input = 0; + move16(); + Q_hb_synth_fx = 0; + move16(); + Q_synth_fx = 0; + move16(); + + FD_BWE_DEC_HANDLE hBWE_FD; + hBWE_FD = st->hBWE_FD; + + Copy_Scale_sig_32_16( output_32_fx[n], output_16_fx[n], L_FRAME48k, negate( Q11 ) ); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( Q11 ) ); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->extl, WB_TBE ) ) + { + /* WB TBE decoder */ + + ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); + } + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) + { + /* do nothing */ + } + ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) + { + /* WB BWE decoder */ + Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); + } + + /* Memories Re-Scaling */ + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); + Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); + + IF( hBWE_FD != NULL ) + { + Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); + } + IF( st->hBWE_TD != NULL ) + { + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); + } + + /*---------------------------------------------------------------------* + * SWB(FB) TBE decoding + * SWB(FB) BWE decoding + *---------------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) + { + /* SWB TBE decoder */ + Q_white_exc = 0; + move16(); + + ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); + + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); + + IF( GT_16( Q_white_exc, 31 ) ) + { + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); + Q_white_exc = 31; + move16(); + } + + /* FB TBE decoder */ + IF( EQ_16( st->extl, FB_TBE ) ) + { + fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); + } + } + ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) + { + /* SWB BWE decoder */ + Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); + + Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); + + Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); + } + + /*---------------------------------------------------------------------* + * FEC - recovery after lost HQ core (smoothing of the BWE component) + *---------------------------------------------------------------------*/ + + test(); + test(); + IF( st->prev_bfi && EQ_16( st->last_core, HQ_CORE ) && NE_16( st->extl, -1 ) ) + { + /*tmp = FRAC_BWE_SMOOTH/output_frame;*/ + tmp16 = shr( 410, shr( output_frame, 8 ) ); /* Q15 */ + IF( EQ_16( output_frame, L_FRAME48k ) ) + { + tmp16 = 68; + move16(); + } + /*output_frame/FRAC_BWE_SMOOTH*/ + j = shr( output_frame, 1 ); + tmp16_2 = 0; + move16(); + FOR( i = 0; i < j; i++ ) + { + hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], tmp16_2 ); /* Q11 */ + move32(); +#ifdef BASOP_NOGLOB + tmp16_2 = add_o( tmp16_2, tmp16, &Overflow ); /* Q15 */ +#else + tmp16_2 = add( tmp16_2, tmp16 ); +#endif + } + } + + /*---------------------------------------------------------------------* + * SWB CNG + *---------------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) + { + /* SHB CNG decoder */ + Word16 synth_fxl[960]; /* Q-2 */ + Word16 q; + + q = 2; + move16(); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( add( Q11, q ) ) ); +#ifdef MSAN_FIX + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); +#else + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); +#endif + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); + + swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); + + test(); + IF( st->core_brate == FRAME_NO_DATA || EQ_32( st->core_brate, SID_2k40 ) ) + { + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); + } + +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); +#endif + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); + } + + /*-------------------------------------------------------------------* + * Inter-channel BWE decoding + *-------------------------------------------------------------------*/ + test(); + IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + Word16 q; + q = 11; + move16(); + + IF( hCPE->hStereoDft != NULL ) + { + hCPE->hStereoDft->td_gain_fx[0] = 1; + move32(); + } + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( Q11, Q_white_exc ) ); + stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); +#ifdef MSAN_FIX + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag != 0 ) ) ) ) ) ) ) + { + Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); + Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); + } +#else + Scale_sig32( hb_synth_32_fx[0], L_FRAME48k, sub( Q11, q ) ); + Scale_sig32( hb_synth_32_fx[1], L_FRAME48k, sub( Q11, q ) ); +#endif + } + + IF( EQ_16( st->element_mode, EVS_MONO ) ) + { + /*----------------------------------------------------------------* + * BFI waveform adjustment + *----------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) + { + tmps = NS2SA_FX2( output_Fs, DELAY_CLDFB_NS ); + + waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, + &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, + st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); + + st->hPlcInfo->Pitch = 0; + move16(); + } + } + + /*----------------------------------------------------------------* + * Transition and synchronization of BWE components + *----------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + IF( ( NE_16( st->extl, -1 ) && ( NE_16( 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( EQ_16( 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 + { + test(); + IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( 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 */ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && st->last_core == ACELP_CORE ) && + ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && s_xor( st->core, st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) + { + /* switching between BWE and TBE technologies */ + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); + tmp16 = 0; + move16(); + FOR( i = 0; i < tmps; i++ ) + { + hb_synth_32_fx[n][i] = Mpy_32_16_1( hb_synth_32_fx[n][i], sin_table256_fx[tmp16] ); + move16(); + tmp16 = add( tmp16, incr ); + } + + set16_fx( st->hb_prev_synth_buffer_fx, 0, tmps ); + } + ELSE IF( LT_16( 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 = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); + tmp16 = 0; + move16(); + FOR( i = 0; i < tmps; i++ ) + { + +#ifndef FIX_826_PRECISION_LOST_AND_COMPL + tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ), 1 ) ) ); + move16(); + tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); + move16(); +#else + tmp_buffer_fx[i] = round_fx_sat( L_mac_sat( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ) ); + move16(); +#endif + + tmp16 = add( tmp16, incr ); + } + Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); + } + ELSE IF( GT_16( 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 = idiv1616( imult1616( L_FRAME, 2 ), add( shl( st->old_bwe_delay, 1 ), 1 ) ); + tmp16 = 0; + move16(); + FOR( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer_fx[i] = mult_r( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ); + move16(); + tmp16 = add( tmp16, incr ); + } + FOR( ; i < tmps; i++ ) + { + tmp_buffer_fx[i] = 0; + move16(); + } + tmp16 = 0; + move16(); + FOR( i = 0; i < st->old_bwe_delay; i++ ) + { + tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); + move16(); + tmp16 = add( tmp16, incr ); + } + + Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); + } + + test(); + test(); + test(); + IF( ( NE_16( st->element_mode, IVAS_CPE_TD ) && !use_cldfb_for_dft ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) + { + /* Delay hb_synth */ + Word32 hb_prev_synth_buffer_fx_32[111]; + + Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); + delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); + Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, negate( 11 ) ); + } + ELSE + { + Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); + } + + st->old_bwe_delay = tmps; + + /* SWB CNG/DTX - calculate SHB energy */ + test(); + test(); + test(); + IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && st->core == ACELP_CORE && st->hTdCngDec != NULL ) + { + Word16 exp; + Word32 fra; + SWITCH( output_frame ) + { + case L_FRAME8k: + tmp16 = 205; + move16(); + BREAK; /*Q15*/ + case L_FRAME16k: + tmp16 = 102; + move16(); + BREAK; /*Q15*/ + case L_FRAME32k: + tmp16 = 51; + move16(); + BREAK; /*Q15*/ + case L_FRAME48k: + tmp16 = 34; + move16(); + BREAK; /*Q15*/ + } + + L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ + + Word16 exp2; + exp = 20; + move16(); + Word32 L_tmp2 = sum2_32_fx( hb_synth_32_fx[n], output_frame, &exp ); + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, 20, L_tmp2, exp, &exp ); + L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); + exp2 = norm_l( L_tmp ); + exp = sub( exp, exp2 ); + fra = BASOP_Util_Log2( L_shl_sat( L_tmp, exp2 ) ); + exp2 = norm_l( exp ); + L_tmp = L_shl( exp, exp2 ); + exp = sub( Q31, exp2 ); + L_tmp = BASOP_Util_Add_Mant32Exp( fra, 6, L_tmp, exp, &exp ); + // exp = sub( sub( 30, shl( sub( Q11, 0 ), 1 ) ), exp ); + L_tmp = Mpy_32_16_1( L_tmp, 24660 ); + exp = add( exp, 2 ); + st->last_shb_ener_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 7 ) ) ); /*Q8*/ + move16(); + st->hTdCngDec->last_shb_ener_fx = L_shl_sat( L_tmp, sub( exp, 20 ) ); /*Q11*/ + move32(); + } + } + + test(); + IF( sba_dirac_stereo_flag && NE_16( 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( hCPE != NULL ) + { + FOR( Word32 ch_ind = 0; ch_ind < n_channels; ch_ind++ ) + { + IF( hCPE->hCoreCoder[ch_ind] != NULL ) + { + IF( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) + { + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); + } + } + } + } + IF( hSCE != NULL ) + { + IF( hSCE->hCoreCoder[0] != NULL ) + { + IF( hSCE->hCoreCoder[0]->hHQ_core != NULL ) + { + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); + } + } + } + + Word16 exp_max; + Word32 output_fx_loc[L_FRAME48k]; + + exp_max = 0; + move16(); + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + test(); + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || sba_dirac_stereo_flag ) + { + ivas_post_proc_fx( hSCE, hCPE, n, synth_32_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); + } + + /* update OLA buffers - needed for switching to DFT stereo */ + IF( !sba_dirac_stereo_flag ) + { + IF( hCPE != NULL ) + { + stereo_td2dft_update_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); + } + } + } + ELSE /* IVAS_CPE_DFT */ + { + Word16 q; + q = 11; + move16(); + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) + { + stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); + } + Word16 q_DFT[2] = { 3, 3 }; + move16(); + move16(); + + stereo_dft_dec_core_switching_fx( hCPE, output_32_fx[0], synth_32_fx[0], hb_synth_32_fx[0], DFT_fx, output_frame, use_cldfb_for_dft, 0, &q, q_DFT ); + + hCPE->hStereoDft->q_dft = s_min( q_DFT[0], q_DFT[1] ); + move16(); + + IF( DFT_fx != NULL ) + { + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[0] ) ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); + } + + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( 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_fx( hCPE, n, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], output_frame ); + } + } + + Copy32( synth_32_fx[n], output_32_fx[n], output_frame ); + + /*--------------------------------------------------------* + * Common updates + *--------------------------------------------------------*/ + + /*Scale Memories*/ + + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) + { + Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + + Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( Q11 ) ); + st->q_prev_synth_buffer_fx = 0; + move16(); + + exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame ); + exp_ouput = add( exp_ouput, Q11 ); + exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); + exp_prev_synth_buffer = add( exp_prev_synth_buffer, st->q_prev_synth_buffer_fx ); + exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ) ); + exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); + exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ) ); +#ifndef FIX_740_HQ_CORE_OVA + exp_synth_history += st->hTcxDec->q_synth_history_fx; +#endif + exp_max = s_min( exp_synth_history, exp_ouput ); + exp_max = s_min( exp_max, exp_prev_synth_buffer ); + exp_max = s_min( exp_max, exp_old_out ); + exp_max = s_min( exp_max, exp_delay_buf_out ); + + Copy32( output_32_fx[n], output_fx_loc, output_frame ); + + Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); + Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); + Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); + Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, st->Q_syn ) ); + + st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); + } + /* Save synthesis for HQ FEC */ + save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); + + /* Updates */ + + ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); + + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); + + } /* n_channels loop */ + + FOR( n = 0; n < n_channels; n++ ) + { + st = sts[n]; + IF( st->cldfbAna ) + { + scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbAna->Q_cldfb_state = Q11; + move16(); + } + IF( st->cldfbSynHB ) + { + scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); + st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); + } + } + + 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; + } + +#ifdef NONBE_MDCT_ST_PLC_DO_NOT_SCALE_OLD_OUT_IF_FIRST_GOOD_IS_SID + if ( !st->bfi && st->prev_bfi && st->total_brate > SID_2k40 && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) +#else + if ( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) +#endif + { + 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 ); + } + +#ifdef NONBE_MDCT_ST_DTX_SKIP_DEWHITENING_OF_NOISE_SHAPES_ON_SID_FRAMES + + /* On first good active frame after frameloss undo the whitening of the bg noise shape */ + if ( sts[0]->core_brate > SID_2k40 && sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) +#else + if ( sts[0]->bfi == 0 && sts[0]->prev_bfi == 1 ) + /* On first good frame after frameloss undo the whitening of the bg noise shape */ +#endif + { + 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 diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index cde4a83b8a3c54cb09a154c68ccf11304f84a08b..de856c8725de2a994aa4af949382795bc4a50d10 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -53,6 +53,7 @@ #include "ivas_prot_fx.h" #endif + /*-------------------------------------------------------------------* * ivas_dirac_dec_output_synthesis_cov_open() * @@ -1830,23 +1831,19 @@ Word16 computeMixingMatrices_fx( IF( LT_16( lengthCx, lengthCy ) ) { mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 1 ); - nL = lengthCy; move16(); nC = lengthCx; move16(); - svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); } ELSE { mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 0 ); - nL = lengthCx; move16(); nC = lengthCy; move16(); - svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 64b4810c61b33033152096da9d73571a7c6637fa..853a93d8341ad9281970d32ad227672fee9486ce 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -47,7 +47,6 @@ #define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif // IVAS_FLOAT_FIXED -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*-------------------------------------------------------------------* * Local function prototypes @@ -3123,11 +3122,6 @@ ivas_error ivas_init_decoder_fx( FOR( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) { /* note: these are intra-frame heap memories */ - IF( ( st_ivas->p_output_f[n] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); - } - set_zero( st_ivas->p_output_f[n], 48000 / FRAMES_PER_SEC ); IF( ( st_ivas->p_output_fx[n] = (Word32 *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); @@ -3137,7 +3131,6 @@ ivas_error ivas_init_decoder_fx( FOR( ; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ ) { - st_ivas->p_output_f[n] = NULL; st_ivas->p_output_fx[n] = NULL; } return error; @@ -4631,9 +4624,6 @@ void ivas_initialize_handles_dec( /* floating-point output audio buffers */ FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - st_ivas->p_output_f[i] = NULL; -#endif st_ivas->p_output_fx[i] = NULL; } @@ -4941,13 +4931,6 @@ void ivas_destroy_dec_fx( FOR( i = 0; i < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; i++ ) { -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF( st_ivas->p_output_f[i] != NULL ) - { - free( st_ivas->p_output_f[i] ); - st_ivas->p_output_f[i] = NULL; - } -#endif IF( st_ivas->p_output_fx[i] != NULL ) { free( st_ivas->p_output_fx[i] ); diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 1615a177618c63639672abf70f1b1e111a514f29..9f1f1bf1c7644173591688e9a23734c1b1b8e491 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -40,9 +40,8 @@ #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" #include "prot_fx.h" -#endif +#endif // IVAS_FLOAT_FIXED -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*-------------------------------------------------------------------------* * ivas_ism_bitrate_switching_dec() @@ -320,12 +319,6 @@ static ivas_error ivas_ism_bitrate_switching_dec_fx( { return error; } -#if 1 /* TODO: remove float code */ - if ( NE_32( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) - { - return error; - } -#endif } /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index e28a1214aef41047542358984d574657b9bec2ac..529a4033dc6b0cee89ea9fa57abbb772bdbeff62 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -44,8 +44,6 @@ #include "wmc_auto.h" #include "ivas_prot_fx.h" -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED - /*-----------------------------------------------------------------------* * Local functions diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 0a9a873fecd595966bc3b0db98403c509ec2f098..5586d72b1264493f9fcb578fe957a4160c606fda 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -45,7 +45,6 @@ #include "debug.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_rom_com_fx.h" -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED #endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------* diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 34039bb53f41bab04a63e77a302cf3bdee1ebb8b..3531d64ffbeddd8b1f1fe0c8a921c740ce81471e 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -2270,11 +2270,11 @@ ivas_error ivas_jbm_dec_tc( * Feed decoded transport channels and metadata to the IVAS JBM renderer routine *--------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -void ivas_jbm_dec_feed_tc_to_renderer( +void ivas_jbm_dec_feed_tc_to_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nSamplesForRendering, /* i : number of TC samples available for rendering */ int16_t *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/ - float *data /* i : transport channels */ + Word32 *data_fx /* i : transport channels */ ) { float data_f[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */ @@ -2282,8 +2282,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( #ifdef IVAS_FLOAT_FIXED Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* 'float' buffer for transport channels that will be directly converted with the CLDFB */ Word32 *p_data_f_fx[MAX_CLDFB_DIGEST_CHANNELS]; - Word32 *data_fx; - data_fx = (Word32 *) malloc( ( add( imult1616( nSamplesForRendering, st_ivas->hTcBuffer->nchan_transport_jbm ), s_min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ) ) ) * sizeof( Word32 ) ); IF( st_ivas->hTcBuffer ) { @@ -2307,10 +2305,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( IF( st_ivas->hDecoderConfig->Opt_tsm ) { -#ifdef IVAS_FLOAT_FIXED -#if 1 - floatToFixed_arrL( data, data_fx, 11, add( imult1616( nSamplesForRendering, st_ivas->hTcBuffer->nchan_transport_jbm ), s_min( st_ivas->hTcBuffer->nchan_transport_jbm, st_ivas->hTcBuffer->nchan_buffer_full ) ) ); -#endif ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11 ); #if 1 // To-be-removed @@ -2323,9 +2317,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } -#endif -#else - ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data, p_data_f ); #endif } ELSE @@ -2585,7 +2576,6 @@ void ivas_jbm_dec_feed_tc_to_renderer( ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); } } - free( data_fx ); pop_wmops(); return; @@ -2866,8 +2856,7 @@ ivas_error ivas_jbm_dec_render_fx( ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal ); - Word16 non_diegetic_pan_gain_fx = (Word16) ( 32767 * st_ivas->hDecoderConfig->non_diegetic_pan_gain ); - ivas_apply_non_diegetic_panning_fx( p_output_fx, non_diegetic_pan_gain_fx, *nSamplesRendered ); + ivas_apply_non_diegetic_panning_fx( p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered ); } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) { @@ -2894,8 +2883,7 @@ ivas_error ivas_jbm_dec_render_fx( } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - Word16 non_diegetic_pan_gain_fx = (Word16) ( 32767 * st_ivas->hDecoderConfig->non_diegetic_pan_gain ); - ivas_apply_non_diegetic_panning_fx( p_output_fx, non_diegetic_pan_gain_fx, *nSamplesRendered ); + ivas_apply_non_diegetic_panning_fx( p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered ); } ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { @@ -3332,17 +3320,6 @@ ivas_error ivas_jbm_dec_render_fx( // ftf changes IF( st_ivas->hParamMC->max_band_decorr > 0 ) { - // ftf for param_mc_protoSignalComputation_fx - FOR( Word16 x = 0; x < st_ivas->hParamMC->diff_proto_info->num_protos_diff; x++ ) - { - Word16 num_source_ch = st_ivas->hParamMC->diff_proto_info->num_source_chan_diff[x]; - move16(); - - Scale_sig32( st_ivas->hParamMC->diff_proto_info->proto_fac_fx[x], num_source_ch, Q30 - st_ivas->hParamMC->diff_proto_info->Q_proto_fac ); - st_ivas->hParamMC->diff_proto_info->Q_proto_fac = Q30; - move16(); - } - // ftf for ivas_dirac_dec_decorr_process_fx Word16 tmp; tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len ); diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 7a49db66745c9d7028995c4c120ec8dbfaf4524e..c8771a8dbbb739e45148e51e6f39be257cd76f31 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -1429,8 +1429,8 @@ ivas_error ivas_param_mc_dec_reconfig_fx( } ELSE { - Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); - Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); + Copy32( ivas_param_mc_conf[config_index].dmx_fac_fx, proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ) ); // proto_matrix_fx -> Q31 + Scale_sig32( proto_matrix_fx, imult1616( nchan_out_transport, nchan_transport ), -5 ); // proto_matrix_fx -> Q26 } test(); @@ -2265,6 +2265,7 @@ void ivas_param_mc_dec_close_fx( free( hParamMC->diff_proto_info->proto_fac_fx[i] ); hParamMC->diff_proto_info->proto_fac_fx[i] = NULL; } + free( hParamMC->diff_proto_info->source_chan_idx ); hParamMC->diff_proto_info->source_chan_idx = NULL; @@ -6262,6 +6263,7 @@ static void param_mc_set_num_synth_bands( * calculated the diffuse prototype information *-------------------------------------------------------------------------*/ + #ifdef IVAS_FLOAT_FIXED static ivas_error param_mc_get_diff_proto_info_fx( const Word32 *proto_mtx, /* i : protoype matrix for the synthesis */ @@ -6279,6 +6281,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( /* Initializations */ max_num_src_chan = 0; move16(); + set_zero_fx( proto_fac_fx, MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS ); IF( ( p_diff_proto_info->proto_index_diff = (Word16 *) malloc( nchan_out_cov * sizeof( Word16 ) ) ) == NULL ) { @@ -6295,6 +6298,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( /* we have at least one prototype, copy the first one */ p_diff_proto_info->num_protos_diff = 1; move16(); + mvr2r_inc_fixed( proto_mtx, nchan_out_cov, proto_fac_fx, nchan_out_cov, nchan_transport ); p_diff_proto_info->proto_index_diff[0] = 0; move16(); @@ -6345,7 +6349,9 @@ static ivas_error param_mc_get_diff_proto_info_fx( } proto_mtx_ptr += nchan_out_cov; } + mvr2r_inc_fixed( proto_mtx + cur_out_ch, nchan_out_cov, proto_fac_fx + p_diff_proto_info->num_protos_diff, nchan_out_cov, nchan_transport ); + p_diff_proto_info->proto_index_diff[cur_out_ch] = p_diff_proto_info->num_protos_diff; move16(); p_diff_proto_info->num_protos_diff = add( p_diff_proto_info->num_protos_diff, 1 ); @@ -6359,6 +6365,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } + IF( ( p_diff_proto_info->proto_fac_fx = (Word32 **) malloc( p_diff_proto_info->num_protos_diff * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -6371,6 +6378,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); } + IF( ( p_diff_proto_info->proto_fac_fx[cur_diff_proto] = (Word32 *) malloc( max_num_src_chan * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) ); @@ -6383,7 +6391,7 @@ static ivas_error param_mc_get_diff_proto_info_fx( { p_diff_proto_info->source_chan_idx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = cur_transport_ch; move16(); - p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = *proto_fac_ptr; + p_diff_proto_info->proto_fac_fx[cur_diff_proto][p_diff_proto_info->num_source_chan_diff[cur_diff_proto]] = L_shl( *proto_fac_ptr, 4 ); // (proto_fac_fx)Q26 + 4 = Q30 move16(); p_diff_proto_info->num_source_chan_diff[cur_diff_proto] = add( p_diff_proto_info->num_source_chan_diff[cur_diff_proto], 1 ); move16(); diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index ba2476750a941ca80fc434dc29eb0e90859f2cfe..15d83a8e4ce3e7d0bad849180dbbe009199ff226 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -547,12 +547,6 @@ ivas_error ivas_omasa_dec_config_fx( { return error; } -#ifndef IVAS_FLOAT_FIXED_TO_BE_REMOVED - IF( NE_32( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) - { - return error; - } -#endif } return IVAS_ERR_OK; diff --git a/lib_dec/ivas_qspherical_dec.c b/lib_dec/ivas_qspherical_dec.c index f64051f188fc05cfb4a3310e23f2de133d88f33e..993f01c52fdc9d08d1d95a0ac0a041dee17e595c 100644 --- a/lib_dec/ivas_qspherical_dec.c +++ b/lib_dec/ivas_qspherical_dec.c @@ -50,6 +50,7 @@ *----------------------------------------------------------------------*/ /*! r: decoded elevation value */ +#ifndef IVAS_FLOAT_FIXED float deindex_elevation( uint16_t *id_th, /* i : input index */ const int16_t no_bits, /* i : number of bits for the spherical grid */ @@ -98,6 +99,7 @@ float deindex_elevation( return theta_hat; } +#endif #ifdef IVAS_FLOAT_FIXED Word32 deindex_elevation_fx( diff --git a/lib_dec/ivas_rom_dec.c b/lib_dec/ivas_rom_dec.c index bf3c5dcf408017f5c28d1671a13c0581594d0d9a..f6f9a65c653b346fde87cbcc7eaa67e4f7c1d941 100644 --- a/lib_dec/ivas_rom_dec.c +++ b/lib_dec/ivas_rom_dec.c @@ -44,6 +44,7 @@ * DFT stereo ROM tables *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED const float dft_alpha_s[STEREO_DFT_BAND_MAX] = { .7f, .4f, .25f, .2f, .15f, .1f, .1f, .1f, .1f, .1f, .1f, .1f, .1f @@ -93,6 +94,7 @@ const float dft_ap_gains[5][3] = { 0.3f, -0.3f, 0.5f} }; +#endif // !IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED const Word16 dft_alpha_s_fx[STEREO_DFT_BAND_MAX] = { @@ -158,12 +160,14 @@ const int16_t dft_ap_delays[3][3] = {31, 37, 59} }; +#ifndef IVAS_FLOAT_FIXED const float dft_res_pred_weights[][STEREO_DFT_BAND_MAX] = { { 1.f, .75f, .5f, .4f, .4f }, { 1.f, 1.f, 1.f, 1.f, 0.f }, { 1.f, .5f, .4f, .4f } }; +#endif // !IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED const Word16 dft_res_pred_weights_fx[][STEREO_DFT_BAND_MAX] = @@ -175,6 +179,7 @@ const Word16 dft_res_pred_weights_fx[][STEREO_DFT_BAND_MAX] = #endif +#ifndef IVAS_FLOAT_FIXED const float dft_win232ms_8k[75] = { 0.0104718f, 0.0314108f, 0.0523360f, 0.0732382f, 0.0941083f, 0.1149372f, 0.1357156f, 0.1564345f, 0.1770847f, 0.1976573f, 0.2181432f, 0.2385335f, 0.2588190f, 0.2789911f, @@ -284,6 +289,7 @@ const float dft_win_8k[70] = 0.8155609f, 0.8283398f, 0.8407016f, 0.8526402f, 0.8641494f, 0.8752234f, 0.8858568f, 0.8960441f, 0.9057802f, 0.9150603f, 0.9238795f, 0.9322336f, 0.9401183f, 0.9475296f, 0.9544637f, 0.9609173f, 0.9668870f, 0.9723699f, 0.9773632f, 0.9818643f, 0.9858710f, 0.9893813f, 0.9923935f, 0.9949059f, 0.9969173f, 0.9984268f, 0.9994336f, 0.9999371f }; +#endif #ifdef IVAS_FLOAT_FIXED const Word16 dft_win232ms_8k_fx[75] = @@ -371,6 +377,7 @@ const int16_t cna_init_bands[CNA_INIT_NBANDS + 1] = 1, 4, 14, 33, 67, 171, 320 }; +#ifndef IVAS_FLOAT_FIXED const float max_smooth_gains1[SBA_DIRAC_STEREO_NUM_BANDS] = { 0.98f, 0.97f, 0.95f, 0.9f, 0.9f, 0.9f, 0.9f, 0.9f, 0.9f, 0.9f, 0.9f, 0.9f @@ -389,6 +396,7 @@ const float min_smooth_gains2[SBA_DIRAC_STEREO_NUM_BANDS] = { 0.5f, 0.5f, 0.5, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.3f, 0.3f, 0.3f }; +#endif // !IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED const Word16 max_smooth_gains1_fx[SBA_DIRAC_STEREO_NUM_BANDS] = @@ -548,6 +556,7 @@ const uint16_t * const sym_freq_ECSQ_tab_abs_lsbs[1 + 4] = *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED const float dirac_dithering_azi_scale[DIRAC_DIFFUSE_LEVELS] = { 6.716062e-01f, 1.011837e+00f, 1.799065e+00f, 2.824915e+00f, 4.800879e+00f, 9.206031e+00f, 1.469832e+01f, 2.566224e+01f @@ -557,6 +566,7 @@ const float dirac_dithering_ele_scale[DIRAC_DIFFUSE_LEVELS] = { 6.716062e-01f, 1.011804e+00f, 1.796875e+00f, 2.804382e+00f, 4.623130e+00f, 7.802667e+00f, 1.045446e+01f, 1.379538e+01f }; +#endif // !IVAS_FLOAT_FIXED #ifdef IVAS_FLOAT_FIXED /*Q10*/ @@ -574,11 +584,13 @@ const Word16 dirac_dithering_ele_scale_fx[DIRAC_DIFFUSE_LEVELS] = * FASTCONV and PARAMETRIC binaural renderer ROM tables *----------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED const float dmxmtx_table[BINAURAL_CHANNELS][11] = { { 1.0f, 0.0f, 0.70709997f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.70709997f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f }, }; +#endif // !IVAS_FLOAT_FIXED /*----------------------------------------------------------------------------------* * FASTCONV and PARAMETRIC binaural renderer ROM tables diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 6ed2b922a9720e59835195716440a94c1d967db5..e2da831bf1eef7c4013ff2a2a47936dd3b472774 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -792,7 +792,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( /* get new renderer type */ /* copy the logic from ivas_renderer_select(), because calling this function has too many side effects that would affect the flushing */ - IF( LE_16( ivas_get_sba_num_TCs( ivas_total_brate, sba_order_internal ), 2 ) ) + IF( LE_16( ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order_internal ), 2 ) ) { IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) ) { @@ -959,11 +959,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( ivas_pca_dec_init_fx( hSpar->hPCA ); } -#ifdef IVAS_FLOAT_FIXED ivas_spar_config_fx( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); -#else - ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); -#endif } ELSE { @@ -1065,7 +1061,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); move16(); - IF( ivas_get_hodirac_flag( ivas_total_brate, st_ivas->sba_analysis_order ) ) + IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ) { st_ivas->hSpar->enc_param_start_band = 0; move16(); @@ -1257,7 +1253,7 @@ ivas_error ivas_sba_dec_reconfigure_fx( tc_buffer_mode = TC_BUFFER_MODE_RENDERER; move16(); - tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); tc_nchan_to_allocate = tc_nchan_tc; move16(); test(); @@ -1358,16 +1354,10 @@ ivas_error ivas_sba_dec_reconfigure_fx( nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); - if ( NE_32( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) - { - return error; - } -#ifdef IVAS_FLOAT_FIXED if ( NE_32( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff_old, nchan_out_buff ) ), IVAS_ERR_OK ) ) { return error; } -#endif // IVAS_FLOAT_FIXED return error; } diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index 0ef56c856ea4389e20bdb7dd15167bd77efa766d..2db9ed6a09ff3a0cd2e67f7c2fe306622a0e6410 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -446,7 +446,7 @@ void ivas_param_mc_mc2sba_cldfb_fx( return; } -#endif // IVAS_FLOAT_FIXED +#else void ivas_param_mc_mc2sba_cldfb( IVAS_OUTPUT_SETUP hTransSetup, /* i : transported MC Format */ @@ -516,6 +516,7 @@ void ivas_param_mc_mc2sba_cldfb( return; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_sba_remapTCs() @@ -567,7 +568,7 @@ Word16 ivas_sba_remapTCs_fx( } return ( nchan_remapped ); } -#endif // IVAS_FLOAT_FIXED +#else int16_t ivas_sba_remapTCs( float *sba_data[], /* i/o: SBA signals */ Decoder_Struct *st_ivas, /* i/o: decoder struct */ @@ -611,6 +612,7 @@ int16_t ivas_sba_remapTCs( return ( nchan_remapped ); } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------------* * ivas_ism2sba_sf() @@ -802,8 +804,8 @@ ivas_error ivas_sba_linear_renderer_fx( return error; } -#endif // IVAS_FLOAT_FIXED +#else ivas_error ivas_sba_linear_renderer( float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t output_frame, /* i : output frame length per channel */ @@ -858,6 +860,7 @@ ivas_error ivas_sba_linear_renderer( return error; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * ivas_sba_mix_matrix_determiner() diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index 9d33f6dd74e679906d8c58e87b2a47e873a85a2e..491a89f285c1d1e6db2fbb4ab22a77c18d0abfd3 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -58,7 +58,7 @@ ivas_error ivas_sce_dec_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ) { - Word32 outputHB[1][L_FRAME48k]; /* 'float' buffer for output HB synthesis, one channel */ + Word32 outputHB[1][L_FRAME48k]; /*Word32 buffer for output HB synthesis, one channel */ SCE_DEC_HANDLE hSCE; Decoder_State *st; Word32 ivas_total_brate, last_ivas_total_brate; diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 437178df4fc7bd9645dbce0d4bfe49920d01f4b1..b50850cfbfa7d752bcbdfa3a37d3382e36384350 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -823,7 +823,6 @@ typedef struct ivas_param_mc_diff_proto_info_structure int16_t **source_chan_idx; #ifdef IVAS_FLOAT_FIXED Word32 **proto_fac_fx; - Word16 Q_proto_fac; #else float **proto_fac; #endif // IVAS_FLOAT_FIXED @@ -1485,12 +1484,16 @@ typedef struct decoder_config_structure int16_t Opt_RendConfigCustom; /* indicates whether Renderer configuration custom setup is used */ IVAS_HEAD_ORIENT_TRK_T orientation_tracking; /* indicates orientation tracking type */ int16_t Opt_non_diegetic_pan; /* indicates diegetic or not */ - float non_diegetic_pan_gain; /* non diegetic panning gain*/ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ - int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ - int16_t Opt_dpid_on; /* indicates whether Directivity pattern option is used */ - int16_t Opt_aeid_on; /* indicates whether Acoustic environment option is used */ - int16_t Opt_tsm; /* indicates whether time scaling modification is activated */ +#ifndef IVAS_FLOAT_FIXED + float non_diegetic_pan_gain; /* non diegetic panning gain*/ +#else + Word16 non_diegetic_pan_gain_fx; /* non diegetic panning gain*/ /* Q15 */ +#endif + int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + int16_t Opt_ExternalOrientation; /* indiates whether external orientations are used */ + int16_t Opt_dpid_on; /* indicates whether Directivity pattern option is used */ + int16_t Opt_aeid_on; /* indicates whether Acoustic environment option is used */ + int16_t Opt_tsm; /* indicates whether time scaling modification is activated */ IVAS_RENDER_FRAMESIZE render_framesize; int16_t Opt_delay_comp; /* flag indicating delay compensation active */ @@ -1536,7 +1539,9 @@ typedef struct Decoder_Struct #endif IVAS_LIMITER_HANDLE hLimiter; /* Limiter handle */ +#ifndef IVAS_FLOAT_FIXED float *p_output_f[MAX_OUTPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point output audio buffers */ +#endif // !IVAS_FLOAT_FIXED /* core-decoder modules */ int16_t nSCE; /* number of total SCEs */ diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 25d907d3c2792ef5acb49ee614f310643ca45b4b..87b938c4804d07d897c2a2237cb768d4076f1bca 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -49,42 +49,55 @@ * Local constants *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED #define A_GFILT 0.8f /* LP-filter coefficient for coherence and sidegain */ -#ifdef IVAS_FLOAT_FIXED +#else #define A_GFILT_FX ( Word16 )( 0x6666 ) /* LP-filter coefficient for coherence and sidegain */ #define ONE_MINUS_A_GFILT_FX ( Word16 )( 0x199A ) /* LP-filter coefficient for coherence and sidegain */ #endif #define SKIP_XFADE_FRAMES 2 /* DTX/CNG */ -#define MAX_K 50.0f -#define ONE_BY_MAX_K ( Word16 )( 0x028F ) -#define STEREO_TD_PS_CORR_FILT 0.8f +#ifndef IVAS_FLOAT_FIXED +#define MAX_K 50.0f +#else +#define MAX_K 50 +#endif +#define ONE_BY_MAX_K ( Word16 )( 0x028F ) +#ifndef IVAS_FLOAT_FIXED +#define STEREO_TD_PS_CORR_FILT 0.8f +#endif #define STEREO_TD_PS_CORR_FILT_FX 1717986918 #define STEREO_TD_PS_CORR_FILT_Q31 1717986944 #define ONE_MINUS_STEREO_TD_PS_CORR_FILT_Q31 429496704 -#define MAX_XFADE 50.0f -#ifdef IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED +#define MAX_XFADE 50.0f +#else #define MAX_XFADE_FX 50 #endif -#define CM_INIT 50 -#define CORR_INIT 8 -#define SID_INIT 6 -#define STEREO_CNA_LR_CORR_LT_FILT 0.95f /* long-term averaging factor for L/R correlation estimation in stereo CNA */ +#define CM_INIT 50 +#define CORR_INIT 8 +#define SID_INIT 6 +#ifndef IVAS_FLOAT_FIXED +#define STEREO_CNA_LR_CORR_LT_FILT 0.95f /* long-term averaging factor for L/R correlation estimation in stereo CNA */ +#endif #define STEREO_CNA_LR_CORR_LT_FILT_FX 2040109440 /* long-term averaging factor for L/R correlation estimation in stereo CNA */ -#define STEREO_CNA_ILD_LT_FILT 0.9f /* long-term averaging factor for ILD estimation in stereo CNA */ -#define STEREO_CNA_ILD_LT_FILT_FX 1932735283 /* long-term averaging factor for ILD estimation in stereo CNA */ -#define STEREO_CNA_SOFT_VAD_UP 0.7f /* long-term averaging factor for upward soft VAD update in stereo CNA */ -#define STEREO_CNA_SOFT_VAD_DN 0.95f /* long-term averaging factor for downward soft VAD update in stereo CNA */ - - #ifndef IVAS_FLOAT_FIXED +#define STEREO_CNA_ILD_LT_FILT 0.9f /* long-term averaging factor for ILD estimation in stereo CNA */ +#endif +#define STEREO_CNA_ILD_LT_FILT_FX 1932735283 /* long-term averaging factor for ILD estimation in stereo CNA */ +#ifndef IVAS_FLOAT_FIXED +#define STEREO_CNA_SOFT_VAD_UP 0.7f /* long-term averaging factor for upward soft VAD update in stereo CNA */ +#define STEREO_CNA_SOFT_VAD_DN 0.95f /* long-term averaging factor for downward soft VAD update in stereo CNA */ +#endif + /*------------------------------------------------------------------- * stereo_dft_dec_sid_coh() * * Decode coherence vector *-------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void stereo_dft_dec_sid_coh( Decoder_State *st, /* i/o: decoder state structure */ const int16_t nbands, /* i : number of DFT stereo bands */ @@ -1680,7 +1693,7 @@ void stereo_cng_compute_PScorr_fx( return; } -#endif +#else void stereo_cng_compute_PScorr( float *output[CPE_CHANNELS], /* i : Output signal */ @@ -1730,6 +1743,7 @@ void stereo_cng_compute_PScorr( return; } +#endif /*-------------------------------------------------------------------* diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index d981db15ef5d29ddc620e14ef3af4a40ba25a0e9..ef1084f61ff2fabdaa4d8ac0f3457295757525e1 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -2721,10 +2721,19 @@ void stereo_dft_generate_res_pred_fx( FOR( b = lb_stefi_start_band; b <= band0; b++ ) { + Word16 temp, temp_e; d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); - /* ToDo:Change the float operation here */ - d_long_ind = max( 4, (int16_t) ( ( STEREO_DFT_PAST_MAX + 4 - 1 ) * ( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f ) ) - 4; - move16(); + temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ + IF( temp_e < 0 ) + { + temp = shl( temp, temp_e ); + temp_e = 0; + move16(); + } + temp = shr( temp, 3 ); /*adding 3 as guard bit*/ + temp_e = add( temp_e, 3 ); + temp = shr( add( imult1616( ( STEREO_DFT_PAST_MAX + 4 - 1 ), temp ), shl( 1, sub( 14, temp_e ) ) ), sub( 15, temp_e ) ); /*( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f*/ /*Q0*/ + d_long_ind = sub( s_max( 4, temp ), 4 ); /* make sure d_short really corresponds to a shorter or equally long delay than d_long (e.g. not always the case for * STEREO_DFT_STEFFI_DELAY_SHORT=3 and STEREO_DFT_STEFFI_DELAY_LONG=4)*/ d_short_ind = s_max( d_short_ind, d_long_ind ); @@ -2971,9 +2980,18 @@ void stereo_dft_generate_res_pred_fx( { /* TCX/HQ core -> TCX/HQ core: business as usual */ d_short_ind = add( sub( STEREO_DFT_PAST_MAX, STEREO_DFT_STEFFI_DELAY_SHORT ), b & 1 ); - move16(); - d_long_ind = max( 4, (int16_t) ( ( STEREO_DFT_PAST_MAX + 4 - 1 ) * ( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f ) ) - 4; - move16(); + Word16 temp, temp_e; + temp = BASOP_Util_Divide1616_Scale( b, sub( hStereoDft->nbands, 1 ), &temp_e ); /*(float) b / ( hStereoDft->nbands - 1 )*/ + IF( temp_e < 0 ) + { + temp = shl( temp, temp_e ); + temp_e = 0; + move16(); + } + temp = shr( temp, 3 ); /*adding 3 as guard bit*/ + temp_e = add( temp_e, 3 ); + temp = shr( add( imult1616( ( STEREO_DFT_PAST_MAX + 4 - 1 ), temp ), shl( 1, sub( 14, temp_e ) ) ), sub( 15, temp_e ) ); /*( (float) b / ( hStereoDft->nbands - 1 ) ) + 0.5f*/ /*Q0*/ + d_long_ind = sub( s_max( 4, temp ), 4 ); /* make sure d_short really corresponds to a shorter or equally long delay than d_long (e.g. not always the case for * STEREO_DFT_STEFFI_DELAY_SHORT=3 and STEREO_DFT_STEFFI_DELAY_LONG=4)*/ d_short_ind = s_max( d_short_ind, d_long_ind ); diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index c9543e648bc2cd154130deadbc58d3a50ac80adb..7fa9a1207a16ebf9a3e5ce868dced85e227da460 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -3215,36 +3215,20 @@ void stereo_switching_dec( IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) && EQ_16( hCPE->nchan_out, 2 ) ) { /* reset CLDFB memories */ -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // cldfb_reset_memory_ivas( sts[0]->cldfbAna ); - // cldfb_reset_memory_ivas( sts[0]->cldfbBPF ); - // cldfb_reset_memory_ivas( sts[0]->cldfbSyn ); -#endif cldfb_reset_memory_fx( sts[0]->cldfbAna ); cldfb_reset_memory_fx( sts[0]->cldfbBPF ); cldfb_reset_memory_fx( sts[0]->cldfbSyn ); - // sts[0]->mem_deemph = 0; sts[0]->mem_deemph_fx = 0; move16(); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // sts[0]->tilt_code = 0.0f; - // sts[0]->gc_threshold = 0.0f; -#endif sts[0]->tilt_code_fx = 0; move16(); sts[0]->gc_threshold_fx = 0; move16(); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // set_f( sts[0]->mem_syn1, 0, M ); - // set_f( sts[0]->mem_syn2, 0, M ); - // set_f( sts[0]->mem_syn3, 0, M ); - // set_f( sts[0]->mem_syn_r_float, 0.0f, L_SYN_MEM ); -#endif set16_fx( sts[0]->mem_syn1_fx, 0, M ); set16_fx( sts[0]->mem_syn2_fx, 0, M ); @@ -3254,12 +3238,6 @@ void stereo_switching_dec( sts[1]->last_L_frame = sts[0]->last_L_frame; move16(); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - /* reset PCh memories */ - // set_f( sts[0]->old_exc, 0, L_EXC_MEM_DEC ); - // set_f( sts[0]->lsf_old, 0, M ); - // set_f( sts[0]->lsp_old, 0, M ); -#endif set16_fx( sts[0]->old_exc_fx, 0, L_EXC_MEM_DEC ); set16_fx( sts[0]->lsf_old_fx, 0, M ); @@ -3282,35 +3260,19 @@ void stereo_switching_dec( move32(); /* reset CLDFB memories */ -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // cldfb_reset_memory_ivas( sts[1]->cldfbAna ); - // cldfb_reset_memory_ivas( sts[1]->cldfbBPF ); - // cldfb_reset_memory_ivas( sts[1]->cldfbSyn ); -#endif cldfb_reset_memory_fx( sts[1]->cldfbAna ); cldfb_reset_memory_fx( sts[1]->cldfbBPF ); cldfb_reset_memory_fx( sts[1]->cldfbSyn ); - // sts[1]->mem_deemph = 0; sts[1]->mem_deemph_fx = 0; move16(); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // sts[1]->tilt_code = 0.0f; - // sts[1]->gc_threshold = 0.0f; -#endif sts[1]->tilt_code_fx = 0; move16(); sts[1]->gc_threshold_fx = 0; move16(); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // set_f( sts[1]->mem_syn1, 0, M ); - // set_f( sts[1]->mem_syn2, 0, M ); - // set_f( sts[1]->mem_syn3, 0, M ); - // set_f( sts[1]->mem_syn_r_float, 0.0f, L_SYN_MEM ); -#endif set16_fx( sts[1]->mem_syn1_fx, 0, M ); set16_fx( sts[1]->mem_syn2_fx, 0, M ); @@ -3330,10 +3292,6 @@ void stereo_switching_dec( sts[1]->last_coder_type = sts[0]->last_coder_type; move16(); -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // mvr2r( sts[0]->hHQ_core->old_out, sts[1]->hHQ_core->old_out, L_FRAME48k ); - // mvr2r( sts[0]->hTcxDec->old_syn_Overl_float, sts[1]->hTcxDec->old_syn_Overl_float, 256 ); -#endif #ifndef IVAS_FLOAT_FIXED mvr2r( sts[0]->delay_buf_out, sts[1]->delay_buf_out, HQ_DELTA_MAX * HQ_DELAY_COMP ); #endif // #ifndef IVAS_FLOAT_FIXED @@ -3350,10 +3308,6 @@ void stereo_switching_dec( } ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { -#ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - // set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); - // set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); -#endif set16_fx( sts[0]->old_exc_fx, 0, L_EXC_MEM_DEC ); set16_fx( sts[1]->old_exc_fx, 0, L_EXC_MEM_DEC ); } diff --git a/lib_dec/lib_dec.h b/lib_dec/lib_dec.h index ce7a654bd69592f4e46d05d44a2a5f44cef9ff97..ff917c20df8829c466f536a824987febe5dc201f 100644 --- a/lib_dec/lib_dec.h +++ b/lib_dec/lib_dec.h @@ -430,7 +430,11 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ +#ifdef IVAS_FLOAT_FIXED + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ +#else const float non_diegetic_pan_gain, /* i : non diegetic panning gain */ +#endif const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -527,7 +531,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const float quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality */ ); /*! r: error code */ diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index df292ea6da7af15b5c1364a6b07615cb35bc2a41..db77f15fc84b5d494016a5355b34284041626a93 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -77,11 +77,13 @@ struct IVAS_DEC bool Opt_VOIP; /* flag indicating VOIP mode with JBM */ Word16 tsm_scale; /* scale for TSM operation */ Word16 tsm_max_scaling; +#ifndef IVAS_FLOAT_FIXED + float *apaExecBuffer; /* Buffer for APA scaling */ float tsm_quality; - float *apaExecBuffer; /* Buffer for APA scaling */ // dependency for apa_exec function -#ifdef IVAS_FLOAT_FIXED +#else Word32 *apaExecBuffer_fx; /* Buffer for APA scaling */ + Word16 tsm_quality; /*Q14*/ #endif PCMDSP_APA_HANDLE hTimeScaler; bool needNewFrame; @@ -104,13 +106,13 @@ static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP ); #ifdef SUPPORT_JBM_TRACEFILE static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const UWord32 systemTimestamp_ms, const UWord16 extBufferedSamples, const Word32 output_Fs ); #endif -static ivas_error evs_dec_main( Decoder_Struct *st_ivas, const Word16 nOutSamples, float *floatBuf, Word16 *pcmBuf ); +static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, Word32 *floatBuf, Word16 *pcmBuf ); static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, Word16 *bitstream_format_internal, Word16 *sdp_hf_only, const bool is_voip_enabled ); static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig ); static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const UWord16 nTransportChannels, const UWord16 l_ts ); static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, UWord16 *nTcBufferGranularity, UWord8 *nTransportChannels, UWord8 *nOutChannels, UWord16 *nSamplesRendered, Word16 *data ); -static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, float *pcmBuf, Word32 *pcmBuf_fx, Word16 *nOutSamples ); -static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, float *pcmBuf ); +static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, Word32 *pcmBuf_fx, Word16 *nOutSamples ); +static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *pcmBuf ); static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const UWord16 nSamplesForRendering, UWord16 *nSamplesRendered, UWord16 *nSamplesAvailableNext, Word16 *pcmBuf ); static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, Word16 *nSamplesBuffered ); static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize ); @@ -146,14 +148,15 @@ ivas_error IVAS_DEC_Open( } hIvasDec = *phIvasDec; hIvasDec->hVoIP = NULL; +#ifndef IVAS_FLOAT_FIXED hIvasDec->apaExecBuffer = NULL; -#ifdef IVAS_FLOAT_FIXED +#else hIvasDec->apaExecBuffer_fx = NULL; #endif hIvasDec->hTimeScaler = NULL; hIvasDec->tsm_scale = 100; hIvasDec->tsm_max_scaling = 0; - hIvasDec->tsm_quality = 1.0f; + hIvasDec->tsm_quality = ONE_IN_Q14; /*1.f Q14*/ hIvasDec->needNewFrame = false; hIvasDec->nTransportChannelsOld = 0; hIvasDec->nSamplesAvailableNext = 0; @@ -297,7 +300,11 @@ static void init_decoder_config( hDecoderConfig->Opt_RendConfigCustom = 0; hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE; hDecoderConfig->Opt_non_diegetic_pan = 0; +#ifndef IVAS_FLOAT_FIXED hDecoderConfig->non_diegetic_pan_gain = 0; +#else + hDecoderConfig->non_diegetic_pan_gain_fx = 0; +#endif hDecoderConfig->Opt_tsm = 0; hDecoderConfig->Opt_delay_comp = 0; hDecoderConfig->Opt_ExternalOrientation = 0; @@ -317,6 +324,7 @@ static void init_decoder_config( move16(); move16(); move16(); + move16(); return; } @@ -351,11 +359,12 @@ void IVAS_DEC_Close( apa_exit( &( *phIvasDec )->hTimeScaler ); +#ifndef IVAS_FLOAT_FIXED IF( ( *phIvasDec )->apaExecBuffer != NULL ) { free( ( *phIvasDec )->apaExecBuffer ); } -#ifdef IVAS_FLOAT_FIXED +#else IF( ( *phIvasDec )->apaExecBuffer_fx != NULL ) { free( ( *phIvasDec )->apaExecBuffer_fx ); @@ -424,7 +433,7 @@ ivas_error IVAS_DEC_Configure( const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */ const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */ const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */ - const float non_diegetic_pan_gain, /* i : non diegetic panning gain */ + const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */ const Word16 Opt_dpid_on, /* i : enable directivity pattern option */ const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */ const Word16 delayCompensationEnabled /* i : enable delay compensation */ @@ -495,7 +504,7 @@ ivas_error IVAS_DEC_Configure( hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled; hDecoderConfig->Opt_RendConfigCustom = renderConfigEnabled; hDecoderConfig->Opt_non_diegetic_pan = Opt_non_diegetic_pan; - hDecoderConfig->non_diegetic_pan_gain = non_diegetic_pan_gain; + hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; hDecoderConfig->Opt_delay_comp = delayCompensationEnabled; hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation; hDecoderConfig->Opt_dpid_on = Opt_dpid_on; @@ -551,7 +560,7 @@ ivas_error IVAS_DEC_Configure( hIvasDec->nSamplesRendered = 0; hIvasDec->tsm_scale = 100; hIvasDec->tsm_max_scaling = 0; - hIvasDec->tsm_quality = 1.0f; + hIvasDec->tsm_quality = ONE_IN_Q14 /*1.0f Q14*/; move16(); move16(); move16(); @@ -872,15 +881,9 @@ ivas_error IVAS_DEC_FeedFrame_Serial( test(); IF( ( EQ_16( hIvasDec->st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_16( hIvasDec->st_ivas->mc_mode, MC_MODE_PARAMMC ) ) ) { - PARAM_MC_DEC_HANDLE hParamMC; - hParamMC = hIvasDec->st_ivas->hParamMC; MC_LS_SETUP mc_ls_setup; mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( hIvasDec->st_ivas->transport_config ); hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); - IF( hParamMC ) - { - hParamMC->diff_proto_info->Q_proto_fac = Q26; - } } test(); @@ -1092,25 +1095,34 @@ ivas_error IVAS_DEC_GetSamples( } /* IVAS decoder */ - IF( NE_32( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ), IVAS_ERR_OK ) ) { return error; } /* JBM */ IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { + float apaExecBuffer[APA_BUF]; + for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + { + apaExecBuffer[i] = fixedToFloat( hIvasDec->apaExecBuffer_fx[i], Q11 ); + } IF( apa_set_scale( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 ) { return IVAS_ERR_UNKNOWN; } - IF( apa_exec( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) + IF( apa_exec( hIvasDec->hTimeScaler, apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, apaExecBuffer, &nTimeScalerOutSamples ) != 0 ) { return IVAS_ERR_UNKNOWN; } assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) ); nSamplesTcsScaled = idiv1616( extract_l( nTimeScalerOutSamples ), nTransportChannels ); + for ( int i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i ) + { + hIvasDec->apaExecBuffer_fx[i] = float_to_fix( apaExecBuffer[i], Q11 ); + } } ELSE { @@ -1119,7 +1131,7 @@ ivas_error IVAS_DEC_GetSamples( } /* Feed decoded transport channels samples to the renderer */ - IF( NE_32( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ) ), IVAS_ERR_OK ) ) { return error; } @@ -1242,37 +1254,15 @@ static ivas_error IVAS_DEC_Setup( } } - IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( st_ivas->ivas_format == MC_FORMAT ) ) - { - IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) - { - IF( st_ivas->hParamMC ) - { - IF( st_ivas->hParamMC->diff_proto_info ) - { - st_ivas->hParamMC->diff_proto_info->Q_proto_fac = Q26; - } - } - } - } IF( NE_32( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) ) { return error; } IF( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMMC ) ) { - PARAM_MC_DEC_HANDLE hParamMC; - hParamMC = st_ivas->hParamMC; MC_LS_SETUP mc_ls_setup; mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config ); st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels( ivas_total_brate, mc_ls_setup ); - IF( hParamMC ) - { - IF( st_ivas->hParamMC->diff_proto_info ) - { - hParamMC->diff_proto_info->Q_proto_fac = Q26; - } - } } IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( !( EQ_16( st_ivas->ini_active_frame, 0 ) && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) ) && st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] && st_ivas->ivas_format == MASA_FORMAT && ( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || EQ_16( st_ivas->ini_active_frame, 0 ) ) ) @@ -1319,20 +1309,6 @@ static ivas_error IVAS_DEC_Setup( } } } - - IF( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) && ( st_ivas->ivas_format == MC_FORMAT ) ) - { - IF( st_ivas->mc_mode == MC_MODE_PARAMMC ) - { - IF( st_ivas->hParamMC ) - { - IF( st_ivas->hParamMC->diff_proto_info ) - { - st_ivas->hParamMC->diff_proto_info->Q_proto_fac = Q26; - } - } - } - } } *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm; @@ -1355,7 +1331,6 @@ static ivas_error IVAS_DEC_Setup( static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - float *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ Word16 *nOutSamples /* o : number of samples per channel written to output buffer */ ) @@ -1372,10 +1347,11 @@ static ivas_error IVAS_DEC_GetTcSamples( st_ivas = hIvasDec->st_ivas; *nOutSamples = (Word16) Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ); + move16(); IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - IF( NE_32( ( error = evs_dec_main( st_ivas, *nOutSamples, pcmBuf, NULL ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = evs_dec_main_fx( st_ivas, *nOutSamples, pcmBuf_fx, NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -1388,14 +1364,7 @@ static ivas_error IVAS_DEC_GetTcSamples( Decoder_State *st, **sts; /* used for bitstream handling */ Word16 nCPE, cpe_id; nCPE = st_ivas->nCPE; - DECODER_TC_BUFFER_HANDLE hTcBuffer = st_ivas->hTcBuffer; - Word16 n_ch_cldfb_tmp = hTcBuffer->nchan_transport_jbm - hTcBuffer->nchan_buffer_full; - Word16 num_freq_bands = 0; /* Float to Fixed */ - IF( pcmBuf != NULL ) - { - floatToFixed_arrL( pcmBuf, pcmBuf_fx, 11, (Word16) ( st_ivas->hTcBuffer->nchan_transport_jbm * st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) ); - } IF( st_ivas->hDecoderConfig->Opt_tsm == 0 ) { @@ -1407,7 +1376,6 @@ static ivas_error IVAS_DEC_GetTcSamples( } -#if 1 CPE_DEC_HANDLE hCPE; IF( ( ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) || ( st_ivas->mc_mode == MC_MODE_MCT ) || st_ivas->ivas_format == SBA_ISM_FORMAT || ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) || st_ivas->mc_mode == MC_MODE_PARAMMC ) && ( GT_16( st_ivas->nCPE, 1 ) ) ) { @@ -1441,36 +1409,6 @@ static ivas_error IVAS_DEC_GetTcSamples( } } - IF( NE_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) - { - - IF( st_ivas->ivas_format == ISM_FORMAT ) - { - IF( st_ivas->hSpatParamRendCom != NULL ) - { - num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands; - } - } - ELSE IF( st_ivas->ivas_format == MC_FORMAT ) - { - IF( st_ivas->hParamMC != NULL ) - { - num_freq_bands = st_ivas->hParamMC->num_freq_bands; - } - FOR( Word16 lp = 0; lp < n_ch_cldfb_tmp; lp++ ) - { - Word16 length = 15 * num_freq_bands * n_ch_cldfb_tmp + num_freq_bands * ( n_ch_cldfb_tmp - 1 ) + st_ivas->cldfbAnaDec[lp]->no_channels; - FOR( Word16 lp2 = 0; lp2 < length; lp2++ ) - { - /*st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx[lp2] = - floatToFixed(st_ivas->hParamMC->Cldfb_RealBuffer_tc[lp2], 6); - st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx[lp2] = - floatToFixed(st_ivas->hParamMC->Cldfb_ImagBuffer_tc[lp2], 6);*/ - } - } - } - } -#endif /* Function call: ivas_jbm_dec_tc function */ IF( NE_32( ( error = ivas_jbm_dec_tc_fx( st_ivas, pcmBuf_fx ) ), IVAS_ERR_OK ) ) @@ -1478,31 +1416,6 @@ static ivas_error IVAS_DEC_GetTcSamples( return error; } -#if 1 - /* Fixed to Float */ - IF( pcmBuf != NULL ) - { - fixedToFloat_arrL( pcmBuf_fx, pcmBuf, 11, (Word16) ( st_ivas->hTcBuffer->nchan_transport_jbm * st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ) ); - } - - IF( NE_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) ) - { - IF( st_ivas->ivas_format == ISM_FORMAT ) - { - IF( st_ivas->hSpatParamRendCom != NULL ) - { - num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands; - } - } - ELSE IF( st_ivas->ivas_format == MC_FORMAT ) - { - IF( st_ivas->hParamMC != NULL ) - { - num_freq_bands = st_ivas->hParamMC->num_freq_bands; - } - } - /*------------------------fix 2 flt----------------------*/ - } hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */ @@ -1514,8 +1427,6 @@ static ivas_error IVAS_DEC_GetTcSamples( sts = hCPE->hCoreCoder; FOR( n = 0; n < 2; n++ ) { - st = hCPE->hCoreCoder[n]; - sts = hCPE->hCoreCoder; /*-------------------cldfb-start-------------------------*/ /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -1523,30 +1434,18 @@ static ivas_error IVAS_DEC_GetTcSamples( { scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); sts[n]->cldfbAna->Q_cldfb_state = Q11; + move16(); } IF( sts[n]->cldfbSyn != NULL ) { scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); sts[n]->cldfbSyn->Q_cldfb_state = Q11; + move16(); } /*-------------------cldfb-end---------------------------*/ - - /* reset WB BWE buffers */ - - IF( NE_16( sts[n]->last_extl, WB_BWE ) && EQ_16( sts[n]->extl, WB_BWE ) && sts[n]->hBWE_FD != NULL ) - { - - IF( NE_16( sts[n]->last_extl, SWB_BWE ) && NE_16( sts[n]->last_extl, FB_BWE ) ) - { - sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; - } - sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; - sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; - } } } } -#endif // fixed to float } if ( hIvasDec->hasBeenFedFirstGoodFrame ) { @@ -1568,7 +1467,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ const Word16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */ Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call */ - float *pcmBuf /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ + Word32 *pcmBuf /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels */ ) { Decoder_Struct *st_ivas; @@ -1582,7 +1481,7 @@ static ivas_error IVAS_DEC_RendererFeedTcSamples( st_ivas = hIvasDec->st_ivas; /* feed the TCs to the IVAS renderer */ - ivas_jbm_dec_feed_tc_to_renderer( st_ivas, nSamplesForRendering, nSamplesResidual, pcmBuf ); + ivas_jbm_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesForRendering, nSamplesResidual, pcmBuf ); return IVAS_ERR_OK; } @@ -2795,7 +2694,7 @@ ivas_error IVAS_DEC_VoIP_SetScale( ivas_error IVAS_DEC_TSM_SetQuality( IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */ - const float quality /* i : target TSM quality */ + const Word16 quality /* i : target TSM quality */ ) { ivas_error error; @@ -2891,10 +2790,13 @@ ivas_error IVAS_DEC_VoIP_GetSamples( } #ifdef IVAS_FLOAT_FIXED - if ( GT_32( maxScaling, 20 ) ) + IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_EVS ) ) { - maxScaling = 20; - move16(); + if ( GT_32( maxScaling, 20 ) ) + { + maxScaling = 20; + move16(); + } } #endif maxScaling = Mult_32_32( imult3216( hDecoderConfig->output_Fs, (Word16) maxScaling ), INV_1000_Q31 ); @@ -3353,7 +3255,12 @@ static ivas_error printConfigInfo_dec( IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) { fprintf( stdout, "Output configuration: mono EVS bit-exact decoding to stereo\n" ); +#ifndef IVAS_FLOAT_FIXED fprintf( stdout, "Non-diegetic panning: %.2f\n", st_ivas->hDecoderConfig->non_diegetic_pan_gain * 90.f ); +#else + float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 ); + fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f ); +#endif } ELSE { @@ -3460,7 +3367,12 @@ static ivas_error printConfigInfo_dec( IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan ) { +#ifndef IVAS_FLOAT_FIXED fprintf( stdout, "Non-diegetic panning: %.2f\n", st_ivas->hDecoderConfig->non_diegetic_pan_gain * 90.f ); +#else + float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 ); + fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f ); +#endif // !IVAS_FLOAT_FIXED } IF( st_ivas->hDecoderConfig->Opt_dpid_on ) @@ -3524,19 +3436,17 @@ void IVAS_DEC_PrintDisclaimer( void ) * EVS codec main decoder fucntion *---------------------------------------------------------------------*/ -static ivas_error evs_dec_main( +static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, - float *floatBuf, + Word32 *Buf_fx, Word16 *pcmBuf ) { DEC_CORE_HANDLE *hCoreCoder; - float mixer_left, mixer_rigth; -#ifdef IVAS_FLOAT_FIXED + Word16 mixer_left_fx, mixer_right_fx; Word32 *p_output_fx[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; -#endif - float *p_output[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; - Word16 ch; + Word16 ch, n, i; + Word16 output_16[L_FRAME48k]; ivas_error error; hCoreCoder = st_ivas->hSCE[0]->hCoreCoder; @@ -3550,36 +3460,22 @@ static ivas_error evs_dec_main( FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ ) { - p_output[ch] = st_ivas->p_output_f[ch]; -#ifdef IVAS_FLOAT_FIXED p_output_fx[ch] = st_ivas->p_output_fx[ch]; -#endif } -#ifdef IVAS_FLOAT_FIXED - Word16 output_16[L_FRAME48k]; -#endif /* run the main EVS decoding routine */ IF( EQ_16( hCoreCoder[0]->codec_mode, MODE1 ) ) { IF( hCoreCoder[0]->Opt_AMR_WB ) { -#ifndef IVAS_FLOAT_FIXED - IF( ( error = amr_wb_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0] ) ) != IVAS_ERR_OK ) -#else IF( NE_32( ( error = amr_wb_dec_fx( output_16, hCoreCoder[0] ) ), IVAS_ERR_OK ) ) -#endif { return error; } } ELSE { -#ifndef IVAS_FLOAT_FIXED - IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) -#else IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) ) -#endif { return error; } @@ -3589,79 +3485,69 @@ static ivas_error evs_dec_main( { IF( hCoreCoder[0]->bfi == 0 ) { -#ifndef IVAS_FLOAT_FIXED - IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_NORMAL ) ) != IVAS_ERR_OK ) -#else IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) ) -#endif { return error; } } ELSE IF( EQ_16( hCoreCoder[0]->bfi, 2 ) ) { -#ifndef IVAS_FLOAT_FIXED - IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_FUTURE ) ) != IVAS_ERR_OK ) -#else IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_FUTURE ) ), IVAS_ERR_OK ) ) -#endif { return error; } } ELSE { -#ifndef IVAS_FLOAT_FIXED - IF( ( error = evs_dec( hCoreCoder[0], st_ivas->mem_hp20_out[0], p_output[0], FRAMEMODE_MISSING ) ) != IVAS_ERR_OK ) -#else IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_MISSING ) ), IVAS_ERR_OK ) ) -#endif { return error; } } } - st_ivas->BER_detect = hCoreCoder[0]->BER_detect; - move16(); -#ifdef IVAS_FLOAT_FIXED - FOR( Word16 i = 0; i < nOutSamples; i++ ) + FOR( i = 0; i < nOutSamples; i++ ) { - p_output[0][i] = output_16[i]; + p_output_fx[0][i] = L_shl( output_16[i], Q11 ); /* Q11 */ } -#endif + + st_ivas->BER_detect = hCoreCoder[0]->BER_detect; + move16(); IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ) { - mixer_left = ( st_ivas->hDecoderConfig->non_diegetic_pan_gain + 1.f ) * 0.5f; - mixer_rigth = 1.f - mixer_left; - v_multc( p_output[0], mixer_rigth, p_output[1], nOutSamples ); - v_multc( p_output[0], mixer_left, p_output[0], nOutSamples ); + mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); + mixer_right_fx = sub( MAX16B, mixer_left_fx ); + + v_multc_fixed_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */ + v_multc_fixed_16( p_output_fx[0], mixer_left_fx, p_output_fx[0], nOutSamples ); /* Q11 */ } IF( !st_ivas->hDecoderConfig->Opt_tsm ) { -#ifdef IVAS_FLOAT_FIXED - for ( int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) - { - floatToFixed_arrL( p_output[i], p_output_fx[i], Q11, nOutSamples ); - } ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples ); -#else - ivas_jbm_dec_copy_tc_no_tsm( st_ivas, p_output, nOutSamples ); -#endif } - ELSE IF( floatBuf != NULL ) + ELSE IF( Buf_fx != NULL ) { - /* BE workaround */ - Word16 pcm_buf_local[L_FRAME48k * MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN]; - - /* convert 'float' output data to 'short' */ - ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcm_buf_local ); - mvs2r( pcm_buf_local, floatBuf, nOutSamples * st_ivas->hDecoderConfig->nchan_out ); + FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) + { + FOR( i = 0; i < nOutSamples; i++ ) + { + Buf_fx[i * st_ivas->hDecoderConfig->nchan_out + n] = p_output_fx[n][i]; /* Does the same as above */ /* Q11 */ + move32(); + } + } } ELSE { - ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); + /* ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); */ + FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ ) + { + FOR( i = 0; i < nOutSamples; i++ ) + { + pcmBuf[i * st_ivas->hDecoderConfig->nchan_out + n] = extract_l( L_shr( p_output_fx[n][i], Q11 ) ); /* Does the same as above */ /* Q0 */ + move16(); + } + } } return IVAS_ERR_OK; @@ -3733,7 +3619,11 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( apa_buffer_size = hIvasDec->nSamplesFrame; move16(); +#ifndef IVAS_FLOAT_FIXED IF( hIvasDec->apaExecBuffer == NULL ) +#else + IF( hIvasDec->apaExecBuffer_fx == NULL ) +#endif { DECODER_CONFIG_HANDLE hDecoderConfig; @@ -3742,7 +3632,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( UWord16 wss, css; float startQuality; - startQuality = hIvasDec->tsm_quality; + startQuality = fixedToFloat( hIvasDec->tsm_quality, Q14 ); apa_buffer_size = APA_BUF_PER_CHANNEL; move16(); @@ -3797,6 +3687,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( } } +#ifndef IVAS_FLOAT_FIXED IF( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); @@ -3804,12 +3695,14 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); +#else IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * imult1616( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } set_zero_fx( hIvasDec->apaExecBuffer_fx, imult1616( apa_buffer_size, (Word16) nTransportChannels ) ); +#endif } } ELSE @@ -3822,6 +3715,7 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( } apa_buffer_size = APA_BUF_PER_CHANNEL; move16(); +#ifndef IVAS_FLOAT_FIXED free( hIvasDec->apaExecBuffer ); IF( ( hIvasDec->apaExecBuffer = malloc( sizeof( float ) * apa_buffer_size * nTransportChannels ) ) == NULL ) { @@ -3829,12 +3723,14 @@ static ivas_error IVAS_DEC_VoIP_reconfigure( } set_zero( hIvasDec->apaExecBuffer, apa_buffer_size * nTransportChannels ); +#else free( hIvasDec->apaExecBuffer_fx ); IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * imult1616( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" ); } set_zero_fx( hIvasDec->apaExecBuffer_fx, imult1616( apa_buffer_size, (Word16) nTransportChannels ) ); +#endif } /* realloc apa_exe_buffer */ } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 8e1a0ea4201189f2b685de33791df7cd8876e6bb..3308970ea88c2119860017f0202cf287a229e357 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -53,7 +53,6 @@ Word16 slot_fx[4] = { 32767, 16384, 10922, 8192 }; #endif -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*------------------------------------------------------------------------- * Local constants *------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 67a70fcb12706074d4104b9d6c0172e2893b20a7..7e142afe79e152e394479475b6f2c5b763d51ed2 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -43,7 +43,6 @@ #include "prot_fx.h" #endif -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*-------------------------------------------------------------------* * Local constants diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index f231cc0a708414864a60c60590b122f703b7840f..9778dc30f56cad1434a74ed2e9d9dce82053c8df 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -42,7 +42,6 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #include "prot_fx.h" -#define IVAS_FLOAT_FIXED_TO_BE_REMOVED /*------------------------------------------------------------------------- diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index a7c92ec704baf454684a8e516089890dc50c14cc..485e96a2a6ef4b1d633c913491f81371d32133e8 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -860,7 +860,7 @@ ivas_error ivas_output_buff_dec_fx( } return IVAS_ERR_OK; } -#endif // IVAS_FLOAT_FIXED +#else ivas_error ivas_output_buff_dec( float *p_output_f[], /* i/o: output audio buffers */ @@ -892,3 +892,4 @@ ivas_error ivas_output_buff_dec( return IVAS_ERR_OK; } +#endif