From ce6edaf74e9b4244c2fc948e2fb49d2d03e438d4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 22 Mar 2024 16:34:54 +0530 Subject: [PATCH] stereo_tcx_core_dec updates Intermediate conversions present inside stereo_tcx_core_dec moved out. --- lib_com/float_to_fix_ops.c | 1187 ++++++++++++++++++- lib_com/ivas_prot.h | 2 + lib_com/ivas_prot_fx.h | 18 + lib_com/prot_fx2.h | 9 + lib_dec/TonalComponentDetection_fx.c | 3 +- lib_dec/dec_LPD.c | 8 + lib_dec/dec_tcx_fx.c | 35 +- lib_dec/fd_cng_dec.c | 3 + lib_dec/ivas_core_dec.c | 22 +- lib_dec/ivas_tcx_core_dec.c | 1635 ++++++++------------------ lib_dec/stat_dec.h | 8 +- 11 files changed, 1752 insertions(+), 1178 deletions(-) diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index dfa7879c0..3c9ec9474 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -1,4 +1,5 @@ #include +#include #include #include #include "options.h" @@ -147,7 +148,7 @@ Word16 Q_factor_arrL(float *x, Word16 l) void stereo_tcx_dec_mode_switch_reconf_To_fixed( Decoder_State *st, Word16 tofix, - Word16 last_element_mode ) + Word16 last_element_mode) { bool reconf = ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || ( st->bwidth != st->last_bwidth ) || @@ -535,7 +536,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( fixedToFloat_arr( st->GainShape_Delay, hBWE_TD->GainShape_Delay, Q_GainShape_Delay, 8 ); fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); - bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); + //bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); if ( ( st->bwidth == SWB || st->bwidth == FB ) && st->igf && ( st->bwidth == SWB || st->bwidth == FB ) ) { hBWE_TD->prev_pow_exc16kWhtnd = (float) hBWE_TD->prev_pow_exc16kWhtnd_fx / 32767; @@ -829,4 +830,1186 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( } } } + +void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( + Decoder_State *st, + Word16 tofix, + Word16 last_element_mode ) +{ + TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec = st->hTcxDec; + bool reconf = ( st->bits_frame_nominal != st->last_bits_frame_nominal ) || + ( st->bwidth != st->last_bwidth ) || + ( st->last_core != TCX_20_CORE && st->last_core != TCX_10_CORE && !( st->prev_bfi == 1 && st->last_core == ACELP_CORE && st->last_con_tcx == 1 ) ) || + ( st->idchan == 1 && st->element_mode == IVAS_CPE_MDCT && last_element_mode != IVAS_CPE_MDCT ); + if ( reconf ) + { + + H_IGF_GRID hGrid; + IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; + hPrivateData = &st->hIGFDec->igfData; + H_IGF_INFO hIGFInfo = &hPrivateData->igfInfo; + ACELP_config *pConfigAcelp = &( st->acelp_cfg ); + Word16 i = 0, + Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, Q_mem_syn_r = 0, Q_old_exc = 0, Q_fer_samples = 0, + Q_mem_syn2 = 0, Q_cldfbAna_cldfb_state = 0, Q_cldfbBPF_cldfb_state = 0, Q_cldfbSyn_cldfb_state = 0, Q_cldfbSynHB_cldfb_state = 0, + Q_state_lpc_syn = 0, Q_state_syn_shbexc = 0, Q_mem_stp_swb = 0, Q_mem_zero_swb = 0, Q_pst_old_syn = 0, Q_mem_stp = 0, Q_mem_pf_in = 0, + Q_mem_res2 = 0, delay_comp = 0, Q_loBuffer = 0; + Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ) - 1; + // Word16 Q_lsf_cng = Q_factor( 6400 ); + // Word16 Q_old_enr_LP = Q_factor( st->old_enr_LP_float ); + Word16 Q_old_enr_LP = 3; + Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0, Q_tcxltp_gain_post_prev = 0; + TD_BWE_DEC_HANDLE hBWE_TD = st->hBWE_TD; + Word16 Q_old_bwe_exc = 0, Q_bwe_non_lin_prev_scale = 0, Q_mem_genSHBexc_filt_down_wb2 = 0, Q_mem_genSHBexc_filt_down_wb3 = 0, Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_mem_genSHBexc_filt_down_shb = 0, Q_syn_overlap = 0, Q_mem_csfilt = 0, Q_tbe_demph = 0, Q_tbe_premph = 0, Q_gain_prec_swb = 0, Q_GainShape_Delay = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0, Q_prev_fb_ener_adjust = 0, Q_fb_state_lpc_syn = 0, Q_fbbwe_hpf_mem = 0, Q_prev_fbbwe_ratio = 0, Q_fb_tbe_demph = 0, + Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; + + if ( tofix ) + { + hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; + floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); + hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); + hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; + floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); + hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); + hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; + floatToFixed_arr( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor = (Word16) floatToFixed( hGrid->gFactor_flt, 14 ); + hGrid->fFactor = (Word16) floatToFixed( hGrid->fFactor_flt, 14 ); + hGrid->lFactor = (Word16) floatToFixed( hGrid->lFactor_flt, 14 ); + delay_comp = NS2SA_fx2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/ + st->sr_core = getCoreSamplerateMode2( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format ); + st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, 15 ); + Q_syn = 0; + Q_old_exc = Q_factor_arr( st->old_exc, L_EXC_MEM_DEC ) - 1; + Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ) - 1; + Q_mem_syn2 = Q_mem_syn_r; + floatToFixed_arr( st->old_exc, st->old_exc_fx, Q_old_exc, L_EXC_MEM_DEC ); + floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn_r, L_SYN_MEM ); + floatToFixed_arr( st->syn_float, st->syn, Q_syn, M + 1 ); + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, 15, M ); + floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, 15, M ); + floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn2, M ); + FOR( i = 0; i < M; i++ ) + { + st->mem_MA_fx[i] = (Word16) floatToFixed( (float) ( st->mem_MA[i] * 2.56 ), 0 ); + st->mem_AR_fx[i] = (Word16) floatToFixed( (float) ( st->mem_AR[i] * 2.56 ), 0 ); + st->lsf_old_fx[i] = (Word16) floatToFixed( (float) ( st->lsf_old[i] * 2.56 / st->scale ), 0 ); + st->lsfold_uw[i] = (Word16) floatToFixed( (float) ( st->lsfold_uw_float[i] * 2.56 / st->scale ), 0 ); + } + IF( st->hTcxCfg ) + { + st->hTcxCfg->preemph_fac = (Word16) floatToFixed( st->hTcxCfg->preemph_fac_flt, 15 ); + st->hTcxCfg->sq_rounding = (Word16) floatToFixed( st->hTcxCfg->sq_rounding_flt, 15 ); + st->hTcxCfg->bandwidth = (Word16) floatToFixed( st->hTcxCfg->bandwidth_flt, 15 ); + st->hTcxCfg->na_scale = (Word16) floatToFixed( st->hTcxCfg->na_scale_flt, 15 ); + + Word16 n = st->L_frame; + Word16 n0 = shr( imult1616( n, 9 ), 5 ); + Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[i], 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_trunc[n1 - n / 2 - 1 - i].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_flt[n / 2 + i], 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_flt[i], 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_flt[i], 15 ); + } + n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); + n0 = shr( imult1616( n, 9 ), 5 ); + n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB[i] = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[i], 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i], 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re = (Word16) floatToFixed( st->hTcxCfg->tcx_aldo_window_2_FB_flt[i], 15 ); + } + } + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + { + st->old_pitch_buf_fx[i] = floatToFixed( st->old_pitch_buf[i], 16 ); + } + IF( st->hTcxDec ) + { + st->hTcxDec->Q_old_syn_Overl = 0; + st->hTcxDec->Q_syn_Overl_TDAC = 0; + st->hTcxDec->Q_syn_Overl = 0; + st->hTcxDec->Q_syn_Overl_TDACFB = 0; + st->hTcxDec->Q_syn_OverlFB = 0; + Q_old_synth = 0; + Q_synth_history = 0; + floatToFixed_arr( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, st->hTcxDec->Q_old_syn_Overl, L_FRAME32k / 2 ); + floatToFixed_arr( st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, st->hTcxDec->Q_syn_Overl_TDAC, L_FRAME32k / 2 ); + floatToFixed_arr( st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, st->hTcxDec->Q_syn_Overl, L_FRAME32k / 2 ); + floatToFixed_arr( st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, st->hTcxDec->Q_syn_Overl_TDACFB, L_FRAME_MAX / 2 ); + floatToFixed_arr( st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->hTcxDec->Q_syn_OverlFB, L_FRAME_MAX / 2 ); + floatToFixed_arr( st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); + floatToFixed_arr( st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, Q_synth_history, L_PROT48k + L_FRAME_MAX ); + Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); + st->hTcxDec->old_gaintcx_bfi = (Word16) floatToFixed( st->hTcxDec->old_gaintcx_bfi_float, Q_old_gaintcx_bfi ); + st->hTcxDec->L_frameTCX = extract_l( Mult_32_16( st->output_Fs, 0x0290 ) ); + st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + st->output_frame_fx = st->hTcxDec->L_frameTCX; + st->hTcxDec->CngLevelBackgroundTrace_bfi_fx = floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, 15 ); + st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, 14 ); + st->hTcxDec->LastFrameLevel_bfi_fx = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 ); + FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) + { + st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16) floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); + } + st->hTcxDec->cummulative_damping_tcx = (Word16) floatToFixed( st->hTcxDec->cummulative_damping_tcx_float, 15 ); + } + IF( st->hHQ_core ) + { + st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; + st->hHQ_core->Q_old_out = 0; + st->hHQ_core->Q_old_outLB = 0; + floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); + floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->hHQ_core->Q_old_out, L_FRAME48k ); + floatToFixed_arr( st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->hHQ_core->Q_old_outLB, L_FRAME32k ); + } + IF( st->cldfbAna ) + { + Q_cldfbAna_cldfb_state = Q_factor_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_fx, Q_cldfbAna_cldfb_state, st->cldfbAna->cldfb_state_length ); + } + IF( st->cldfbBPF ) + { + Q_cldfbBPF_cldfb_state = Q_factor_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q_cldfbBPF_cldfb_state, st->cldfbBPF->cldfb_state_length ); + } + IF( st->cldfbSyn ) + { + Q_cldfbSyn_cldfb_state = Q_factor_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q_cldfbSyn_cldfb_state, st->cldfbSyn->cldfb_state_length ); + } + IF( st->cldfbSynHB ) + { + Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length ) - 1; + floatToFixed_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); + } + floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1 ); + st->tilt_code_fx = (Word16) floatToFixed( st->tilt_code, 15 ); + IF( st->hBPF ) + { + Q_pst_old_syn = Q_syn; + Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); + floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, Q_pst_old_syn, NBPSF_PIT_MAX ); + } + IF( st->hPFstat ) + { + Q_mem_stp = Q_factor_arr( st->hPFstat->mem_stp_flt, L_SUBFR ) - 1; + Q_mem_pf_in = Q_factor_arr( st->hPFstat->mem_pf_in_flt, L_SUBFR ) - 1; + Q_mem_res2 = Q_factor_arr( st->hPFstat->mem_res2_flt, DECMEM_RES2 ) - 1; + floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, Q_mem_stp, L_SUBFR ); + floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, Q_mem_pf_in, L_SUBFR ); + floatToFixed_arr( st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, Q_mem_res2, DECMEM_RES2 ); + st->hPFstat->gain_prec = (Word16) floatToFixed( st->hPFstat->gain_prec_flt, 14 ); // 1.f + } + + st->last_concealed_gain_syn_deemph = (Word16) floatToFixed( st->last_concealed_gain_syn_deemph_float, 14 ); + st->old_enr_LP = (Word16) floatToFixed( st->old_enr_LP_float, Q_old_enr_LP ); + st->enr_old_fx = (Word16) floatToFixed( st->enr_old, 0 ); + floatToFixed_arr( st->previoussynth, st->previoussynth_fx, 0, 960 ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_cng[i] = (Word16) floatToFixed( st->lsf_cng_float[i] * 2.56f / st->scale, 0 ); + st->lsf_adaptive_mean_fx[i] = (Word16) floatToFixed( st->lsf_adaptive_mean[i] * 2.56f / st->scale, 0 ); + st->lsfoldbfi0_fx[i] = (Word16) floatToFixed( st->lsfoldbfi0[i] * 2.56f / st->scale, 0 ); + st->lsfoldbfi1_fx[i] = (Word16) floatToFixed( st->lsfoldbfi1[i] * 2.56f / st->scale, 0 ); + } + IF( st->hTcxLtpDec ) + { + Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); + Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); + Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); + st->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) floatToFixed( st->hTcxLtpDec->tcxltp_gain_post_prev_float, Q_tcxltp_gain_post_prev ); + floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_in_float, st->hTcxLtpDec->tcxltp_mem_in, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); + floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_out_float, st->hTcxLtpDec->tcxltp_mem_out, Q_tcxltp_mem_out, L_FRAME48k ); + } + + + floatToFixed_arr( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM ); + // st->last_gain_syn_deemph = floatToFixed(st->last_gain_syn_deemph_float, 14); + st->last_gain_syn_deemph = 0; + IF( hBWE_TD ) + { + Q_old_bwe_exc = Q_factor_arr( hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); + floatToFixed_arr( hBWE_TD->old_bwe_exc, hBWE_TD->old_bwe_exc_fx, Q_old_bwe_exc, PIT16k_MAX * 2 ); + Q_bwe_non_lin_prev_scale = Q_factor_L( hBWE_TD->bwe_non_lin_prev_scale ); + hBWE_TD->bwe_non_lin_prev_scale_fx = floatToFixed( hBWE_TD->bwe_non_lin_prev_scale, Q_bwe_non_lin_prev_scale ); + Q_mem_genSHBexc_filt_down_wb2 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, 7 ); + floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, Q_mem_genSHBexc_filt_down_wb2, 7 ); + Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); + floatToFixed_arr( hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_shb_fx, Q_state_lsyn_filt_shb, 6 ); + Q_mem_genSHBexc_filt_down_wb3 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, 7 ); + floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, Q_mem_genSHBexc_filt_down_wb3, 7 ); + Q_state_lsyn_filt_dwn_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_dwn_shb, 6 ); + floatToFixed_arr( hBWE_TD->state_lsyn_filt_dwn_shb, hBWE_TD->state_lsyn_filt_dwn_shb_fx, Q_state_lsyn_filt_dwn_shb, 6 ); + Q_mem_resamp_HB = Q_factor_arr( hBWE_TD->mem_resamp_HB, 13 ); + floatToFixed_arr( hBWE_TD->mem_resamp_HB, hBWE_TD->mem_resamp_HB_fx, Q_mem_resamp_HB, 13 ); + hBWE_TD->prev_pow_exc16kWhtnd_fx = (Word16) floatToFixed( hBWE_TD->prev_pow_exc16kWhtnd, 15 ); + hBWE_TD->prev_mix_factor_fx = (Word16) floatToFixed( hBWE_TD->prev_mix_factor, 15 ); + Q_mem_genSHBexc_filt_down_shb = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, 7 ); + floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, Q_mem_genSHBexc_filt_down_shb, 7 ); + Q_state_lpc_syn = Q_factor_arr( hBWE_TD->state_lpc_syn, 10 ); + floatToFixed_arr( hBWE_TD->state_lpc_syn, hBWE_TD->state_lpc_syn_fx, Q_state_lpc_syn, 10 ); + Q_state_syn_shbexc = Q_factor_arr( hBWE_TD->state_syn_shbexc, 20 ); + floatToFixed_arr( hBWE_TD->state_syn_shbexc, hBWE_TD->state_syn_shbexc_fx, Q_state_syn_shbexc, 20 ); + Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); + floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, Q_syn_overlap, 20 ); + Q_mem_csfilt = Q_factor_arrL( hBWE_TD->mem_csfilt, 2 ); + floatToFixed_arrL( hBWE_TD->mem_csfilt, hBWE_TD->mem_csfilt_fx, Q_mem_csfilt, 2 ); + Q_tbe_demph = Q_factor( (Word16) hBWE_TD->tbe_demph ); + Q_tbe_premph = Q_factor( (Word16) hBWE_TD->tbe_premph ); + Q_gain_prec_swb = Q_factor( (Word16) hBWE_TD->gain_prec_swb ); + Q_mem_stp_swb = Q_factor_arr( hBWE_TD->mem_stp_swb, 10 ); + Q_GainShape_Delay = Q_factor_arr( hBWE_TD->GainShape_Delay, 8 ); + Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); + Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); + Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); + Q_fbbwe_hpf_mem = Q_factor_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], 16 ); + Q_prev_fbbwe_ratio = Q_factor( (Word16) hBWE_TD->prev_fbbwe_ratio ); + st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); + floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, Q_fb_state_lpc_syn, 10 ); + floatToFixed_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], &hBWE_TD->fbbwe_hpf_mem_fx[0][0], Q_fbbwe_hpf_mem, 16 ); + hBWE_TD->prev_fbbwe_ratio_fx = (Word16) floatToFixed( hBWE_TD->prev_fbbwe_ratio, Q_prev_fbbwe_ratio ); + Q_fb_tbe_demph = Q_factor( (Word16) hBWE_TD->fb_tbe_demph ); + hBWE_TD->fb_tbe_demph_fx = (Word16) floatToFixed( hBWE_TD->fb_tbe_demph, Q_fb_tbe_demph ); + hBWE_TD->tbe_demph_fx = (Word16) floatToFixed( hBWE_TD->tbe_demph, Q_tbe_demph ); + hBWE_TD->tbe_premph_fx = (Word16) floatToFixed( hBWE_TD->tbe_premph, Q_tbe_premph ); + hBWE_TD->gain_prec_swb_fx = (Word16) floatToFixed( hBWE_TD->gain_prec_swb, 14 ); + floatToFixed_arr( hBWE_TD->GainShape_Delay, st->GainShape_Delay, Q_GainShape_Delay, 8 ); + floatToFixed_arr( hBWE_TD->int_3_over_2_tbemem_dec, hBWE_TD->int_3_over_2_tbemem_dec_fx, Q_int_3_over_2_tbemem_dec, INTERP_3_2_MEM_LEN ); + floatToFixed_arr( hBWE_TD->mem_resamp_HB_32k, hBWE_TD->mem_resamp_HB_32k_fx, Q_mem_resamp_HB_32k, 7 ); + Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); + floatToFixed_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, Q_genSHBsynth_Hilbert_Mem, 21 ); + Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); + floatToFixed_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, Q_genSHBsynth_state_lsyn_filt_shb_local, 6 ); + floatToFixed_arr( hBWE_TD->mem_stp_swb, hBWE_TD->mem_stp_swb_fx, Q_mem_stp_swb, 10 ); + Q_mem_zero_swb = Q_factor_arr( hBWE_TD->mem_zero_swb, LPC_SHB_ORDER ); + floatToFixed_arr( hBWE_TD->mem_zero_swb, hBWE_TD->mem_zero_swb_fx, Q_mem_zero_swb, LPC_SHB_ORDER ); + } + IF( st->hTECDec ) + { + Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); + floatToFixed_arr( st->hTECDec->loBuffer_flt, st->hTECDec->loBuffer, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); + } + st->TcxBandwidth = (Word16) floatToFixed( st->TcxBandwidth_float, 15 ); + + /*==========*/ + for ( int p = 0; p < hTcxDec->old_synth_len; p++ ) + { + hTcxDec->old_synth[p] = (Word16) ( hTcxDec->old_synth_float[p] ); + } + for ( int p = 0; p < hTcxDec->old_synth_lenFB; p++ ) + { + hTcxDec->old_synthFB_fx[p] = (Word16) ( hTcxDec->old_synthFB[p] ); + } + + st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); + st->hTcxDec->tcxltp_second_last_pitch = floatToFixed( st->hTcxDec->tcxltp_second_last_pitch_float, 16 ); + st->hTcxDec->tcxltp_third_last_pitch = floatToFixed( st->hTcxDec->tcxltp_third_last_pitch_float, 16 ); + st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); + floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); + floatToFixed_arr( st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2 ); + if ( st->hTonalMDCTConc != NULL ) + { + floatToFixed_arr( st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, 0, st->hTonalMDCTConc->nSamples ); + } + + st->Q_syn = 0; + + for ( int p = 0; p < M; p++ ) + { + st->mem_MA_fx[p] = (Word16) ( st->mem_MA[p] * 2.56 ); + st->mem_AR_fx[p] = (Word16) ( st->mem_AR[p] * 2.56 ); + st->lsf_cng[p] = (Word16) ( st->lsf_cng_float[p] * 2.56 / st->scale ); + st->old_lsf_q_cng[p] = (Word16) ( st->old_lsf_q_cng_float[p] * 2.56 / st->scale ); + st->lsf_old_fx[p] = (Word16) ( st->lsf_old[p] * 2.56 / st->scale ); + } + if ( st->gamma_float == GAMMA1_FLT ) + { + st->inv_gamma = GAMMA1_INV; + } + else if ( st->gamma_float == GAMMA16k_FLT ) + { + st->inv_gamma = GAMMA16k_INV; + } + + floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); + for ( int p = 0; p < M; p++ ) + { + st->lsfold_uw[p] = (Word16) ( st->lsfold_uw_float[p] * 2.56 / st->scale ); + } + for ( i = 0; i < M; i++ ) + { + st->lsf_adaptive_mean_fx[i] = (Word16) ( st->lsf_adaptive_mean[i] * ( 2.56f / st->scale ) ); + } + st->stab_fac_fx = (Word16) floatToFixed( st->stab_fac, Q15 ); + + for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) + { + st->old_pitch_buf_fx[p] = (Word32) ( st->old_pitch_buf[p] * ONE_IN_Q16 ); + } + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + } + st->prev_Q_syn = st->Q_syn; + st->old_fpitchFB = (Word32) ( st->old_fpitchFB_float * ONE_IN_Q16 ); + st->old_fpitch = (Word32) ( st->old_fpitch_float * ONE_IN_Q16 ); + st->stab_fac_fx = (Word16) ( st->stab_fac * MAX_16 ); + st->lp_gainp_fx = (Word16) floatToFixed( st->lp_gainp, Q14 ); + + floatToFixed_arr( st->old_lsp_q_cng_float, st->old_lsp_q_cng, Q15, M ); + floatToFixed_arr( st->lsp_q_cng_float, st->lsp_q_cng, Q15, M ); + + st->hTcxDec->gainHelper = (Word16) floatToFixed( st->hTcxDec->gainHelper_float, Q14 ); + st->hTcxDec->gainHelper_e = 1; + st->hTcxDec->stepCompensate = (Word16) floatToFixed( st->hTcxDec->stepCompensate_float, Q14 ); + st->hTcxDec->stepCompensate_e = 1; + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); + st->hTcxDec->damping = (Word16) floatToFixed( st->hTcxDec->damping_float, Q14 ); + st->bfi_pitch_fx = (Word16) floatToFixed( st->bfi_pitch, Q5 ); + st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); + if ( st->hPlcInfo ) + { + st->hPlcInfo->step_concealgain_fx = (Word16) floatToFixed( st->hPlcInfo->step_concealgain, Q15 ); + } + st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, Q14 ); + st->hTcxDec->conCngLevelBackgroundTrace = (Word16) floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, Q15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); + st->hTcxDec->conLastFrameLevel = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 - st->hTcxDec->conLastFrameLevel_e ); + if ( st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + if ( st->hPlcInfo ) + { + st->hPlcInfo->recovery_gain = (Word16) floatToFixed( st->hPlcInfo->recovery_gain_float, Q14 ); + st->hPlcInfo->step_concealgain_fx = (Word16) floatToFixed( st->hPlcInfo->step_concealgain, Q15 ); + } + floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + floatToFixed_arr( st->mem_pitch_gain_float, st->mem_pitch_gain, Q15, 2 * NB_SUBFR16k + 2 ); + floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); + floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M ); + floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM ); + floatToFixed_arr( st->syn_float, st->syn, 0, M + 1 ); + + floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); + + st->lp_ener_bfi_fx = (Word16) floatToFixed( st->lp_ener_bfi, Q8 ); + st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); + st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); + if ( hTcxLtpDec->tcxltp ) + { + hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); + } + st->classifier_Q_mem_syn = Q5; + floatToFixed_arr( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM ); + + floatToFixed_arr( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), 0, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); + floatToFixed_arr( st->lsp_q_cng_float, st->lsp_q_cng, Q15, M ); + for ( int p = 0; p < M; p++ ) + { + st->lsf_q_cng[p] = (Word16) ( st->lsf_q_cng_float[p] * ( 2.56f / st->scale ) ); + } + + floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); + IF( st->hTdCngDec != NULL ) + { + floatToFixed_arr( st->hTdCngDec->ho_lsp_circ, st->hTdCngDec->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); + floatToFixed_arrL( st->hTdCngDec->ho_env_circ, st->hTdCngDec->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); + floatToFixed_arrL( st->hTdCngDec->ho_ener_circ, st->hTdCngDec->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); + } + + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); + floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1 ); + floatToFixed_arr( st->mem_Aq_float, st->mem_Aq, Q12, ( NB_SUBFR16k ) * ( M + 1 ) ); + if ( !st->tcxonly ) + { + floatToFixed_arr( st->p_bpf_noise_buf_float, st->p_bpf_noise_buf, 0, L_FRAME_16k ); + } + floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); + floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, 0, L_SUBFR ); + floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, 0, L_SUBFR ); + st->lp_noise = floatToFixed( st->lp_noise_float, Q16 ); + st->lp_error_ener = floatToFixed( st->hBPF->pst_lp_ener, Q16 ); + st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); + st->hPFstat->gain_prec = (Word16) floatToFixed( st->hPFstat->gain_prec_flt, Q14 ); + + if ( st->hFdCngDec != NULL && ( st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= MAX_ACELP_BRATE ) + { + for ( int p = 0; p < PERIODOGLEN; p++ ) + { + st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + } + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) + { + st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + } + st->hFdCngDec->msNoiseEst_exp = 31 - Q4; + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + { + st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); + st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); + st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + } + for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) + { + if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) + { + st->hFdCngDec->msMinBuf[p] = MAX_32; + } + else + { + st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); + } + } + + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 + for ( int p = 0; p < FFTCLDFBLEN; p++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; + st->hFdCngDec->partNoiseShape_exp = 31 - Q4; + for ( int p = 0; p < NPART; p++ ) + { + st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); + } + for ( int p = 0; p < 24; p++ ) + { + st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); + } + st->hFdCngDec->lp_noise = floatToFixed( st->hFdCngDec->lp_noise_float, Q23 ); + st->hFdCngDec->lp_speech = floatToFixed( st->hFdCngDec->lp_speech_float, Q23 ); + } + /*===========*/ + } + else + { + Q_old_exc = st->Q_exc; + Q_mem_syn_r = 0; + Q_mem_syn2 = Q_mem_syn_r; + Q_syn = st->Q_syn; + hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; + fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); + hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); + hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_TRAN]; + fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); + hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); + hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); + hGrid = &hIGFInfo->grid[IGF_GRID_LB_SHORT]; + fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); + hGrid->gFactor_flt = fixedToFloat( hGrid->gFactor, 14 ); + hGrid->fFactor_flt = fixedToFloat( hGrid->fFactor, 14 ); + hGrid->lFactor_flt = fixedToFloat( hGrid->lFactor, 14 ); + IF( st->hIGFDec ) + { + st->hIGFDec->virtualSpec_float = &st->hIGFDec->virtualSpecBuf[0]; + st->hIGFDec->igfData.pSpecFlat_float = &st->hIGFDec->igfData.pSpecFlatBuf[0]; + st->hIGFDec->igfData.igfInfo.nfSeed = &st->hIGFDec->igfData.igfInfo.nfSeedBuf[0]; + } + st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); + st->TcxBandwidth_float = fixedToFloat( st->TcxBandwidth, 15 ); + IF( EQ_32( st->sr_core, INT_FS_16k ) ) + { + st->gamma_float = GAMMA16k_FLT; + move16(); + } + ELSE IF( GT_32( st->sr_core, INT_FS_16k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + st->gamma_float = GAMMA16k_FLT; + move16(); + } + ELSE + { + st->gamma_float = GAMMA1_FLT; + move16(); + } + IF( st->hBWE_TD != NULL ) + { + Q_old_bwe_exc = Q_factor_arr( hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); + Q_bwe_non_lin_prev_scale = Q_factor_L( hBWE_TD->bwe_non_lin_prev_scale ); + Q_mem_genSHBexc_filt_down_wb2 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, 7 ); + Q_state_lsyn_filt_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_shb, 6 ); + Q_mem_genSHBexc_filt_down_wb3 = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, 7 ); + Q_state_lsyn_filt_dwn_shb = Q_factor_arr( hBWE_TD->state_lsyn_filt_dwn_shb, 6 ); + Q_mem_resamp_HB = Q_factor_arr( hBWE_TD->mem_resamp_HB, 13 ); + Q_mem_genSHBexc_filt_down_shb = Q_factor_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, 7 ); + Q_state_lpc_syn = Q_factor_arr( hBWE_TD->state_lpc_syn, 10 ); + Q_state_syn_shbexc = Q_factor_arr( hBWE_TD->state_syn_shbexc, 20 ); + Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); + Q_mem_csfilt = Q_factor_arrL( hBWE_TD->mem_csfilt, 2 ); + Q_tbe_demph = Q_factor( (Word16) hBWE_TD->tbe_demph ); + Q_tbe_premph = Q_factor( (Word16) hBWE_TD->tbe_premph ); + Q_gain_prec_swb = Q_factor( (Word16) hBWE_TD->gain_prec_swb ); + Q_mem_stp_swb = Q_factor_arr( hBWE_TD->mem_stp_swb, 10 ); + Q_GainShape_Delay = Q_factor_arr( hBWE_TD->GainShape_Delay, 8 ); + Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); + Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); + Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); + Q_fbbwe_hpf_mem = Q_factor_arrL( &hBWE_TD->fbbwe_hpf_mem[0][0], 16 ); + Q_prev_fbbwe_ratio = Q_factor( (Word16) hBWE_TD->prev_fbbwe_ratio ); + Q_fb_tbe_demph = Q_factor( (Word16) hBWE_TD->fb_tbe_demph ); + Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); + Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); + Q_mem_zero_swb = Q_factor_arr( hBWE_TD->mem_zero_swb, LPC_SHB_ORDER ); + fixedToFloat_arr( st->hBWE_TD->prev_lsf_diff_fx, st->hBWE_TD->prev_lsf_diff, 15, LPC_SHB_ORDER - 2 ); + st->hBWE_TD->prev_tilt_para = 0.0f; + fixedToFloat_arr( st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, 15, M + 1 ); + fixedToFloat_arr( hBWE_TD->old_bwe_exc_fx, hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); + hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( hBWE_TD->bwe_non_lin_prev_scale_fx, Q_bwe_non_lin_prev_scale ); + fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2, Q_mem_genSHBexc_filt_down_wb2, 7 ); + fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3, Q_mem_genSHBexc_filt_down_wb3, 7 ); + fixedToFloat_arr( hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb, Q_state_lsyn_filt_shb, 6 ); + fixedToFloat_arr( hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb, Q_state_lsyn_filt_dwn_shb, 6 ); + fixedToFloat_arr( hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB, Q_mem_resamp_HB, 13 ); + fixedToFloat_arr( hBWE_TD->state_syn_shbexc_fx, hBWE_TD->state_syn_shbexc, Q_state_syn_shbexc, 20 ); + fixedToFloat_arrL( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_csfilt, Q_mem_csfilt, 2 ); + fixedToFloat_arr( hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_shb, Q_mem_genSHBexc_filt_down_shb, 7 ); + fixedToFloat_arr( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap, Q_syn_overlap, 20 ); + fixedToFloat_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, Q_genSHBsynth_state_lsyn_filt_shb_local, HILBERT_MEM_SIZE ); + fixedToFloat_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_Hilbert_Mem, Q_genSHBsynth_Hilbert_Mem, HILBERT_MEM_SIZE ); + hBWE_TD->tbe_demph = fixedToFloat( hBWE_TD->tbe_demph_fx, Q_tbe_demph ); + hBWE_TD->tbe_premph = fixedToFloat( hBWE_TD->tbe_premph_fx, Q_tbe_premph ); + fixedToFloat_arr( st->GainShape_Delay, hBWE_TD->GainShape_Delay, Q_GainShape_Delay, 8 ); + fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); + fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); + // bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); + if ( ( st->bwidth == SWB || st->bwidth == FB ) && st->igf && ( st->bwidth == SWB || st->bwidth == FB ) ) + { + hBWE_TD->prev_pow_exc16kWhtnd = (float) hBWE_TD->prev_pow_exc16kWhtnd_fx / 32767; + hBWE_TD->prev_mix_factor = (float) hBWE_TD->prev_mix_factor_fx / 32767; + } + st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); + hBWE_TD->fb_tbe_demph = fixedToFloat( hBWE_TD->fb_tbe_demph_fx, Q_fb_tbe_demph ); + fixedToFloat_arrL( &hBWE_TD->fbbwe_hpf_mem_fx[0][0], &hBWE_TD->fbbwe_hpf_mem[0][0], Q_fbbwe_hpf_mem, 16 ); + hBWE_TD->prev_fbbwe_ratio = fixedToFloat( hBWE_TD->prev_fbbwe_ratio_fx, Q_prev_fbbwe_ratio ); + fixedToFloat_arr( hBWE_TD->state_lpc_syn_fx, hBWE_TD->state_lpc_syn, Q_state_lpc_syn, LPC_SHB_ORDER ); + fixedToFloat_arr( hBWE_TD->state_syn_shbexc_fx, hBWE_TD->state_syn_shbexc, Q_state_syn_shbexc, L_SHB_LAHEAD ); + fixedToFloat_arr( hBWE_TD->mem_stp_swb_fx, hBWE_TD->mem_stp_swb, Q_mem_stp_swb, LPC_SHB_ORDER ); + fixedToFloat_arr( hBWE_TD->mem_zero_swb_fx, hBWE_TD->mem_zero_swb, Q_mem_zero_swb, LPC_SHB_ORDER ); + hBWE_TD->gain_prec_swb = fixedToFloat( hBWE_TD->gain_prec_swb_fx, 14 ); + } + st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); + IF( st->hTECDec != NULL ) + { + FOR( i = 0; i < CLDFB_NO_COL_MAX; i++ ) + { + st->hTECDec->pGainTemp[i] = 0; + } + Q_loBuffer = Q_factor_arr( st->hTECDec->loBuffer_flt, MAX_TEC_SMOOTHING_DEG ); + fixedToFloat_arr( st->hTECDec->loBuffer, st->hTECDec->loBuffer_flt, Q_loBuffer, MAX_TEC_SMOOTHING_DEG ); + } + IF( st->hTcxCfg ) + { + st->hTcxCfg->preemph_fac_flt = fixedToFloat( st->hTcxCfg->preemph_fac, 15 ); + st->hTcxCfg->sq_rounding_flt = fixedToFloat( st->hTcxCfg->sq_rounding, 15 ); + st->hTcxCfg->bandwidth_flt = fixedToFloat( st->hTcxCfg->bandwidth, 15 ); + st->hTcxCfg->na_scale_flt = fixedToFloat( st->hTcxCfg->na_scale, 15 ); + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_flt[st->hTcxCfg->tcx_mdct_window_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_windowFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_windowFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_windowFB_flt[st->hTcxCfg->tcx_mdct_window_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_windowFB[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_trans_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_trans[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_trans_flt[st->hTcxCfg->tcx_mdct_window_trans_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_trans[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_trans_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_transFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_transFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_transFB_flt[st->hTcxCfg->tcx_mdct_window_trans_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_transFB[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_half_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_half[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_half_flt[st->hTcxCfg->tcx_mdct_window_half_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_half[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_half_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_halfFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_halfFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_halfFB_flt[st->hTcxCfg->tcx_mdct_window_half_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_halfFB[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_length / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_minimum_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimum[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_minimum_flt[st->hTcxCfg->tcx_mdct_window_min_length - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimum[i].v.re, 15 ); + } + FOR( i = 0; i < st->hTcxCfg->tcx_mdct_window_min_lengthFB / 2; i++ ) + { + st->hTcxCfg->tcx_mdct_window_minimumFB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.im, 15 ); + st->hTcxCfg->tcx_mdct_window_minimumFB_flt[st->hTcxCfg->tcx_mdct_window_min_lengthFB - i - 1] = fixedToFloat( st->hTcxCfg->tcx_mdct_window_minimumFB[i].v.re, 15 ); + } + Word16 n = st->L_frame; + Word16 n0 = shr( imult1616( n, 9 ), 5 ); + Word16 n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + Word16 n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_trunc[i - n0].v.im, 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_trunc[n1 - n / 2 - 1 - i].v.re, 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2[i].v.im, 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2[n2 - i - 1].v.re, 15 ); + } + n = NS2SA_fx2( st->output_Fs, FRAME_SIZE_NS ); + n0 = shr( imult1616( n, 9 ), 5 ); + n1 = shr( imult1616( n, 23 ), 5 ); /* left slope length */ + n2 = shr( imult1616( n, 14 ), 5 ); /* right slope length */ + FOR( i = 0; i < n0; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB[i], 15 ); + } + FOR( i = n0; i < n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[i - n0].v.im, 15 ); + } + FOR( i = 0; i < n1 - n / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_1_FB_flt[n / 2 + i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_1_FB_trunc[n1 - n / 2 - i - 1].v.re, 15 ); + } + FOR( i = 0; i < n2 / 2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[i].v.im, 15 ); + } + FOR( i = n2 / 2; i < n2; i++ ) + { + st->hTcxCfg->tcx_aldo_window_2_FB_flt[i] = fixedToFloat( st->hTcxCfg->tcx_aldo_window_2_FB[n2 - i - 1].v.re, 15 ); + } + st->hTcxCfg->tcx_aldo_window_1_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_flt + NS2SA( st->sr_core, N_ZERO_MDCT_NS ); + st->hTcxCfg->tcx_aldo_window_1_FB_trunc_flt = st->hTcxCfg->tcx_aldo_window_1_FB_flt + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ); + } + IF( st->hTcxDec ) + { + Q_old_synth = Q_syn; + // Q_synth_history = Q_factor_arr( st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX ); + Q_synth_history = 0; + st->hTcxDec->Q_old_syn_Overl = st->Q_syn + 1; + fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, st->hTcxDec->Q_old_syn_Overl, L_FRAME32k / 2 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl_TDAC, st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->Q_syn_Overl_TDAC, 320 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->hTcxDec->Q_syn_Overl, 320 ); + fixedToFloat_arr( st->hTcxDec->syn_Overl_TDACFB, st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->Q_syn_Overl_TDACFB, 480 ); + fixedToFloat_arr( st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->hTcxDec->Q_syn_OverlFB, 480 ); + fixedToFloat_arr( st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, Q_old_synth, OLD_SYNTH_INTERNAL_DEC ); + fixedToFloat_arr( st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, Q_synth_history, L_PROT48k + L_FRAME_MAX ); + fixedToFloat_arr( st->hTcxDec->ltpGainMemory_fx, st->hTcxDec->ltpGainMemory, 15, N_LTP_GAIN_MEMS ); + st->hTcxDec->tcxltp_second_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_second_last_pitch, 16 ); + st->hTcxDec->tcxltp_third_last_pitch_float = fixedToFloat( st->hTcxDec->tcxltp_third_last_pitch, 16 ); + Word16 Q_old_gaintcx_bfi = Q_factor( st->hTcxDec->old_gaintcx_bfi_float ); + st->hTcxDec->old_gaintcx_bfi_float = fixedToFloat( st->hTcxDec->old_gaintcx_bfi, Q_old_gaintcx_bfi ); + st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, 14 ); + st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, 15 ); + st->hTcxDec->conCngLevelBackgroundTrace = (Word16) st->hTcxDec->CngLevelBackgroundTrace_bfi_fx; + st->hTcxDec->conCngLevelBackgroundTrace_e = 0; + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->LastFrameLevel_bfi_fx, 15 ); + st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; + st->hTcxDec->conLastFrameLevel_e = 0; + FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) + { + st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); + st->hTcxDec->conNoiseLevelMemory[i] = st->hTcxDec->NoiseLevelMemory_bfi_fx[i]; + } + st->hTcxDec->cummulative_damping_tcx_float = fixedToFloat( st->hTcxDec->cummulative_damping_tcx, 15 ); + } + fixedToFloat_arr( st->syn, st->syn_float, Q_syn, M + 1 ); + fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, L_EXC_MEM_DEC ); + fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn_r, L_SYN_MEM ); + fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, 15, M ); + fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn2, M ); + fixedToFloat_arr( st->lspold_uw, st->lspold_uw_float, 15, M ); + FOR( i = 0; i < M; i++ ) + { + st->mem_AR[i] = fixedToFloat( L_mult( st->mem_AR_fx[i], 100 ), 9 ); + st->mem_MA[i] = fixedToFloat( L_mult( st->mem_MA_fx[i], 100 ), 9 ); + st->lsfold_uw_float[i] = (float) st->lsfold_uw[i] / ( 2.56f / st->scale ); + st->lsf_old[i] = (float) st->lsf_old_fx[i] / ( 2.56f / st->scale ); + } + IF( st->hHQ_core ) + { + fixedToFloat_arr( st->hHQ_core->old_out_fx, st->hHQ_core->old_out, st->hHQ_core->Q_old_out, L_FRAME48k ); + fixedToFloat_arr( st->hHQ_core->old_out_LB_fx, st->hHQ_core->old_outLB, st->hHQ_core->Q_old_outLB, L_FRAME32k ); + } + IF( st->cldfbAna ) + { + Q_cldfbAna_cldfb_state = Q_factor_arrL( st->cldfbAna->cldfb_state, st->cldfbAna->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q_cldfbAna_cldfb_state, st->cldfbAna->cldfb_state_length ); + } + IF( st->cldfbBPF ) + { + Q_cldfbBPF_cldfb_state = Q_factor_arrL( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_state, Q_cldfbBPF_cldfb_state, st->cldfbBPF->cldfb_state_length ); + } + IF( st->cldfbSyn ) + { + Q_cldfbSyn_cldfb_state = Q_factor_arrL( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q_cldfbSyn_cldfb_state, st->cldfbSyn->cldfb_state_length ); + } + IF( st->cldfbSynHB ) + { + Q_cldfbSynHB_cldfb_state = Q_factor_arrL( st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_length ) - 1; + fixedToFloat_arrL( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q_cldfbSynHB_cldfb_state, st->cldfbSynHB->cldfb_state_length ); + } + Word16 scale_fac = 15 - norm_s( st->old_Aq_12_8_fx[0] - 1 ); + // Scale_sig( st->old_Aq_12_8_fx, M + 1, scale_fac ); + fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, scale_fac, M + 1 ); + st->tilt_code = fixedToFloat( st->tilt_code_fx, 15 ); + IF( st->hBPF ) + { + Q_pst_old_syn = Q_syn; + Q_pst_old_syn = Q_factor_arr( st->hBPF->pst_old_syn, NBPSF_PIT_MAX ); + fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); + st->hBPF->pst_mem_deemp_err = 0; + } + IF( st->hPFstat ) + { + Q_mem_stp = Q_factor_arr( st->hPFstat->mem_stp_flt, L_SUBFR ) - 1; + Q_mem_pf_in = Q_factor_arr( st->hPFstat->mem_pf_in_flt, L_SUBFR ) - 1; + Q_mem_res2 = Q_factor_arr( st->hPFstat->mem_res2_flt, DECMEM_RES2 ) - 1; + fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, Q_mem_stp, L_SUBFR ); + fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, Q_mem_pf_in, L_SUBFR ); + fixedToFloat_arr( st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, Q_mem_res2, DECMEM_RES2 ); + st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, 14 ); // 1.f + } + // Q_lsf_cng = Q_factor( 6400 ); + st->past_gpit_float = fixedToFloat( st->past_gpit, 0 ); + st->past_gcode_float = fixedToFloat( st->past_gcode, 0 ); + st->gc_threshold = fixedToFloat( st->gc_threshold_fx, 0 ); + fixedToFloat_arr( st->lspold_cng, st->lspold_cng_float, 15, M ); + fixedToFloat_arr( st->Aq_cng, st->Aq_cng_float, 2, M ); + FOR( i = 0; i < M; i++ ) + { + st->lsf_cng_float[i] = fixedToFloat( (Word32) ( st->lsf_cng[i] / 2.56f / st->scale ), 0 ); + st->lsf_q_cng_float[i] = fixedToFloat( (Word32) ( st->lsf_q_cng[i] / ( 2.56f / st->scale ) ), 0 ); + st->old_lsf_q_cng_float[i] = fixedToFloat( (Word32) ( st->old_lsf_q_cng[i] / ( 2.56f / st->scale ) ), 0 ); + } + fixedToFloat_arr( st->lsp_q_cng, st->lsp_q_cng_float, 15, M ); + fixedToFloat_arr( st->old_lsp_q_cng, st->old_lsp_q_cng_float, 15, M ); + fixedToFloat_arr( st->mem_syn_unv_back, st->mem_syn_unv_back_float, 0, M ); + fixedToFloat_arr( st->mem_Aq, st->mem_Aq_float, 0, NB_SUBFR16k * ( M + 1 ) ); + if ( st->last_gain_syn_deemph == 16384 ) + { + st->last_gain_syn_deemph_float = 1; + } + st->last_concealed_gain_syn_deemph_float = fixedToFloat( st->last_concealed_gain_syn_deemph, 14 ); + st->lp_ener_bfi = fixedToFloat( st->lp_ener_FER_fx, 8 ); + FOR( i = 0; i < M; i++ ) + { + // st->lsf_adaptive_mean[i] = fixedToFloat( L_mult( st->lsf_adaptive_mean_fx[i], 100 ), 9 ); + // st->lsfoldbfi0[i] = fixedToFloat( L_mult( st->lsfoldbfi0_fx[i], 100 ), 9 ); + // st->lsfoldbfi1[i] = fixedToFloat( L_mult( st->lsfoldbfi1_fx[i], 100 ), 9 ); + st->lsf_adaptive_mean[i] = (float) st->lsf_adaptive_mean_fx[i] / ( 2.56f / st->scale ); + st->lsfoldbfi1[i] = (float) st->lsfoldbfi1_fx[i] / ( 2.56f / st->scale ); + st->lsfoldbfi0[i] = (float) st->lsfoldbfi0_fx[i] / ( 2.56f / st->scale ); + } + st->old_enr_LP_float = fixedToFloat( st->old_enr_LP, Q_old_enr_LP ); + st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); + st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); + st->lp_gainp = fixedToFloat( st->lp_gainp_fx, 14 ); + st->cummulative_damping_float = 1; + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + { + st->old_pitch_buf[i] = fixedToFloat( st->old_pitch_buf_fx[i], 16 ); + } + FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) + { + st->mem_pitch_gain_float[i] = 1; + } + st->old_fpitch_float = fixedToFloat( st->old_fpitch, 16 ); + FOR( i = 0; i < 8; i++ ) + { + st->dispMem[i] = 0; + } + st->voice_fac_float = st->voice_fac; /* purely unvoiced */ + IF( st->hTcxLtpDec != NULL ) + { + Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); + Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); + Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); + fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); + fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, Q_tcxltp_mem_out, L_FRAME48k ); + st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, Q_tcxltp_gain_post_prev ); + } + IF( st->hTonalMDCTConc ) + { + FOR( i = 0; i < FDNS_NPTS; i++ ) + { + st->hTonalMDCTConc->scaleFactorsBackground_flt[i] = fixedToFloat( st->hTonalMDCTConc->scaleFactorsBackground[i], 15 ); + } + } + IF( st->hPlcInfo ) + { + FOR( i = 0; i < L_FRAME_MAX; i++ ) + { + st->hPlcInfo->data_reci2[i] = fixedToFloat( st->hPlcInfo->data_reci2_fx[i], 0 ); + } + } + st->old_fpitchFB_float = fixedToFloat( st->old_fpitchFB, 16 ); + + IF( pConfigAcelp != NULL ) + { + pConfigAcelp->formant_enh_num_flt = fixedToFloat( pConfigAcelp->formant_enh_num, 15 ); + pConfigAcelp->formant_enh_den_flt = fixedToFloat( pConfigAcelp->formant_enh_den, 15 ); + st->acelp_cfg_rf.formant_enh_num_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_num, 15 ); + st->acelp_cfg_rf.formant_enh_den_flt = fixedToFloat( st->acelp_cfg_rf.formant_enh_den, 15 ); + if ( st->mem_syn_clas_estim != NULL ) + { + fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, L_SYN_MEM_CLAS_ESTIM ); + } + } + } + } +} + +void fixed_to_float_stereo_tcx_core_dec( + Decoder_State *st, + float *signal_out ) +{ + TCX_DEC_HANDLE hTcxDec = st->hTcxDec; + Word16 q_Aq; + fixedToFloat_arr( st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2 ); + st->hTcxDec->tcxltp_last_gain_unmodified_float = (Word16) fixedToFloat( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + + if ( EQ_16( st->core, ACELP_CORE ) ) + { + for ( int p = 0; p < M + 1; p++ ) + { + st->old_Aq_12_8[p] = (float) st->old_Aq_12_8_fx[p] / ( 1u << ( 15 - ( norm_s( st->old_Aq_12_8_fx[0] - 1 ) ) ) ); + } + for ( int p = 0; p < M; p++ ) + { + st->mem_syn2[p] = (float) st->mem_syn2_fx[p]; + } + for ( int p = 0; p < M + 1; p++ ) + { + st->syn_float[p] = (float) st->syn[p] / (float) pow( 2, st->Q_syn ); + } + for ( int p = 0; p < L_EXC_MEM_DEC; p++ ) + { + st->old_exc[p] = (float) st->old_exc_fx[p] / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) + { + st->old_pitch_buf[p] = (float) st->old_pitch_buf_fx[p] / ONE_IN_Q16; + } + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->syn_OverlFB_float[p] = (float) st->hTcxDec->syn_OverlFB[p] / (float) pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_float[p] = (float) st->hTcxDec->syn_Overl[p] / (float) pow( 2, st->Q_syn ); + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * (float) pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * (float) pow( 2, st->Q_syn ); + } + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); + } + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + for ( int p = 0; p < 60; p++ ) + { + st->mem_syn_r_float[p] = (float) ( st->mem_syn_r[p] ); + } + st->preemph_fac_float = (float) st->preemph_fac / MAX_16; + st->lp_gainc = (float) st->Mode2_lp_gainc / ONE_IN_Q16; + st->lp_gainp = (float) st->Mode2_lp_gainp / ONE_IN_Q29; + st->cummulative_damping_float = (float) st->cummulative_damping / MAX_16; + st->old_enr_LP_float = (float) st->old_enr_LP / ONE_IN_Q3; + st->bfi_pitch = (float) st->bfi_pitch_fx / ONE_IN_Q6; + + fixedToFloat_arr( &st->mem_pitch_gain[2], &st->mem_pitch_gain_float[2], Q14, st->nb_subfr ); + if ( !st->tcxonly ) + { + for ( int p = 0; p < shr( st->L_frame, 6 ); p++ ) + { + q_Aq = 15 - ( norm_s( st->Aq_cng[p * ( M + 1 )] - 1 ) ); + fixedToFloat_arr( st->Aq_cng + p * ( M + 1 ), st->Aq_cng_float + p * ( M + 1 ), q_Aq, ( M + 1 ) ); + } + } + IF( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + { + for ( int p = 0; p < st->nb_subfr; p++ ) + { + q_Aq = 15 - ( norm_s( st->mem_Aq[p * ( M + 1 )] - 1 ) ); + fixedToFloat_arr( st->mem_Aq + p * ( M + 1 ), st->mem_Aq_float + p * ( M + 1 ), q_Aq, ( M + 1 ) ); + } + } + } + + if ( st->rate_switching_reset ) + { + q_Aq = 15 - ( norm_s( st->old_Aq_12_8_fx[0] - 1 ) ); + fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, q_Aq, M + 1 ); + } + + for ( int p = 0; p < M; p++ ) + { + st->lsf_old[p] = (float) st->lsf_old_fx[p] / ( 2.56f / st->scale ); + st->lsp_old[p] = (float) st->lsp_old_fx[p] / ONE_IN_Q15; + } + + if ( st->lpcQuantization ) + { + st->safety_net = st->safety_net_fx; + st->mid_lsf_int = st->mid_lsf_int_fx; + } + + for ( int p = 0; p < M; p++ ) + { + st->mem_MA[p] = (float) st->mem_MA_fx[p] / 2.56f; + st->mem_AR[p] = (float) st->mem_AR_fx[p] / 2.56f; + st->lsf_adaptive_mean[p] = (float) st->lsf_adaptive_mean_fx[p] / ( 2.56f / st->scale ); + st->lsfoldbfi1[p] = (float) st->lsfoldbfi1_fx[p] / ( 2.56f / st->scale ); + st->lsfoldbfi0[p] = (float) st->lsfoldbfi0_fx[p] / ( 2.56f / st->scale ); + st->lsf_q_cng_float[p] = (float) st->lsf_q_cng[p] / ( 2.56f / st->scale ); + st->old_lsf_q_cng_float[p] = (float) st->old_lsf_q_cng[p] / ( 2.56f / st->scale ); + } + + st->stab_fac = fixedToFloat( st->stab_fac_fx, Q15 ); + fixedToFloat_arr( st->lsp_q_cng, st->lsp_q_cng_float, Q15, M ); + + fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, st->Q_syn, M ); + fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, st->Q_syn, L_SYN_MEM ); + fixedToFloat_arr( st->syn, st->syn_float, 0, M + 1 ); + fixedToFloat_arr( st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC ); + hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat( hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, Q14 ); + st->bfi_pitch = fixedToFloat( st->bfi_pitch_fx, Q6 ); + st->old_fpitch_float = fix_to_float( st->old_fpitch, Q16 ); + for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) + { + st->hTcxDec->NoiseLevelMemory_bfi[p] = fixedToFloat( st->hTcxDec->conNoiseLevelMemory[p], 15 - st->hTcxDec->conNoiseLevelMemory_e[p] ); + } + fixedToFloat_arr( st->mem_pitch_gain, st->mem_pitch_gain_float, Q15, 2 * NB_SUBFR16k + 2 ); + fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); + st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); + st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->conLastFrameLevel, 15 - st->hTcxDec->conLastFrameLevel_e ); + for ( int p = 0; p < st->nb_subfr; p++ ) + { + Word16 q_Aq_2 = 15 - ( norm_s( st->mem_Aq[p * ( M + 1 )] - 1 ) ); + fixedToFloat_arr( st->mem_Aq + p * ( M + 1 ), st->mem_Aq_float + p * ( M + 1 ), q_Aq_2, ( M + 1 ) ); + } + if ( st->hPlcInfo ) + { + st->hPlcInfo->recovery_gain_float = fixedToFloat( st->hPlcInfo->recovery_gain, Q14 ); + st->hPlcInfo->step_concealgain = fixedToFloat( st->hPlcInfo->step_concealgain_fx, Q15 ); + } + + fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM ); + st->lp_ener_bfi = fixedToFloat( st->lp_ener_bfi_fx, Q8 ); + + st->enr_old = (float) st->enr_old_fx; + + st->old_enr_LP_float = (float) ( st->old_enr_LP / pow( 2, Q3 ) ); + + fixedToFloat_arr( hTcxDec->old_synth, hTcxDec->old_synth_float, 0, hTcxDec->old_synth_len ); + fixedToFloat_arr( hTcxDec->synth_history_fx, hTcxDec->synth_history, 0, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + fixedToFloat_arr( hTcxDec->old_synthFB_fx, hTcxDec->old_synthFB, 0, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) + hTcxDec->old_synth_lenFB ); + fixedToFloat_arr( st->old_lsp_q_cng, st->old_lsp_q_cng_float, Q15, M ); + fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); + fixedToFloat_arr( st->lspold_uw, st->lspold_uw_float, Q15, M ); + for ( int p = 0; p < M; p++ ) + { + st->lsfold_uw_float[p] = (float) st->lsfold_uw[p] / ( 2.56f / st->scale ); + } + + IF( !st->tcxonly && st->hTdCngDec != NULL ) + { + fixedToFloat_arr( st->hTdCngDec->ho_lsp_circ_fx, st->hTdCngDec->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); + fixedToFloat_arrL( st->hTdCngDec->ho_env_circ_fx, st->hTdCngDec->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); + fixedToFloat_arrL( st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, Q6, HO_HIST_SIZE ); + } + + st->last_voice_factor = st->last_voice_factor_fx; + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); + fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, 0, L_SUBFR ); + fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, 0, L_SUBFR ); + st->hBPF->pst_lp_ener = fixedToFloat( st->lp_error_ener, Q16 ); + st->hBPF->pst_mem_deemp_err = fixedToFloat( st->mem_error, Q16 ); + st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); + + /*=================================*/ + if ( st->hFdCngDec != NULL && ( st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= MAX_ACELP_BRATE ) + { + st->lp_noise_float = fixedToFloat( st->lp_noise, Q23 ); + st->hFdCngDec->lp_noise_float = fixedToFloat( st->hFdCngDec->lp_noise, Q23 ); + st->hFdCngDec->lp_speech_float = fixedToFloat( st->hFdCngDec->lp_speech, Q23 ); + if ( st->element_mode != IVAS_CPE_TD || ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 ) ) + { + if ( ( ( st->m_frame_type == ACTIVE_FRAME ) && ( ( st->bfi == 0 && + ( signal_out == NULL || + ( *signal_out( -FLT_MAX ) && + *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) < FLT_MAX && + *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && + ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && + !( st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode ) ) || + ( st->element_mode == IVAS_CPE_TD ) ) && + ( !st->BER_detect ) ) || + ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && ( st->hFdCngDec->hFdCngCom->active_frame_counter > 0 ) ) || ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) ) ) || + ( st->m_frame_type == ZERO_FRAME ) ) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); + st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) + { + st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); + } + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); + } + for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) + { + st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); + } + for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) + { + st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); + } + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + { + st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); + st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); + st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); + st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); + } + if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) + { + for ( int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++ ) + { + st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); + } + } + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) + { + for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) + { + if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) + { + st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 + } + } + for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) + { + st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); + st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); + st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); + st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); + st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); + if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) + { + st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 + } + if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) + { + st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); + } + if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) + { + st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; + } + else + { + st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); + } + } + } + int A_cng_q = 14; + if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) + { + A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ); + } + for ( int p = 0; p < M; p++ ) + { + st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); + st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); + } + } + } + } +} #endif // IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index db8bec884..40d2b2d07 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -556,6 +556,7 @@ void stereo_tcx_core_enc( const int16_t vad_hover_flag /* i : VAD hangover flag */ ); +#ifndef IVAS_FLOAT_FIXED void stereo_tcx_core_dec( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ @@ -570,6 +571,7 @@ void stereo_tcx_core_dec( const int16_t nchan_out, /* i : number of output channels */ const IVAS_FORMAT ivas_format /* i : IVAS format */ ); +#endif // !IVAS_FLOAT_FIXED void stereo_tcx_init_dec( Decoder_State *st, /* i/o: decoder state structure */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 360e98ec4..28ad8b9f0 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1733,4 +1733,22 @@ UWord32 ivas_syn_output_fx( const Word16 n_channels, /* i : number of output channels */ Word16 *synth_out /* o : integer 16 bits synthesis signal */ ); + +#ifdef IVAS_FLOAT_FIXED +void stereo_tcx_core_dec_fx( + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ + Word16 *signal_out, /* o : synthesis @internal_Fs, Q0 */ + Word16 *signal_outFB, /* o : synthesis @output_Fs, Q0 */ + Word32 pitch_buf[], /* o : floating pitch for each subframe, Q6 */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const Word16 last_element_mode, /* i : last element mode */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const Word16 nchan_out, /* i : number of output channels */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ +); +#endif // IVAS_FLOAT_FIXED + #endif diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index e83f04424..bd35315f6 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -68,6 +68,15 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( Word16 tofix, Word16 last_element_mode ); +void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( + Decoder_State *st, + Word16 tofix, + Word16 last_element_mode); + +void fixed_to_float_stereo_tcx_core_dec( + Decoder_State *st, + float *signal_out +); // Float to Word32 Word32 float_to_fix( float number, Word32 Q ); // Word32 to Float diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index 5ca18f758..a63be1eb9 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -1029,7 +1029,8 @@ static void findTonalComponents( } /* Side lobe increase must be 2 times smaller than the decrease to the foot */ /* Eq. to 2.0f*powerSpectrum[lowerIdx-1]/powerSpectrum[lowerIdx] > powerSpectrum[lowerIdx]/powerSpectrum[j] */ - IF (GT_32( Mpy_32_32(L_shl(powerSpectrum[upperIdx+1], 1), powerSpectrum[j]), Mpy_32_32(powerSpectrum[upperIdx], powerSpectrum[upperIdx]))) + /*IF (GT_32( Mpy_32_32(L_shl(powerSpectrum[upperIdx+1], 1), powerSpectrum[j]), Mpy_32_32(powerSpectrum[upperIdx], powerSpectrum[upperIdx])))*/ + IF( GT_64( W_mult_32_32( L_shl( powerSpectrum[upperIdx + 1], 1 ), powerSpectrum[j] ), W_mult_32_32( powerSpectrum[upperIdx], powerSpectrum[upperIdx] ) ) ) { BREAK; } diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index 49ec4a114..d96f5a800 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -594,6 +594,10 @@ void decoder_LPD_flt( floatToFixed_arr(synth, synth_fx, 0, st->L_frame); floatToFixed_arr(synthFB, synthFB_fx, 0, hTcxDec->L_frameTCX); floatToFixed_arr(Aq, Aq_fx, Q12, M+1); + st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + st->preemph_fac = float_to_fix16(st->preemph_fac_float, Q15); + st->hTcxLtpDec->tcxltp_gain = float_to_fix16( st->hTcxLtpDec->tcxltp_gain_float, Q15 ); + st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); //decoder_tcx_fx( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, 0 ); decoder_tcx_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], bfi, 0, 0 ); @@ -633,6 +637,10 @@ void decoder_LPD_flt( floatToFixed_arr(synth, synth_fx, 0, st->L_frame + k * L_frame / 2); floatToFixed_arr(synthFB, synthFB_fx, 0, hTcxDec->L_frameTCX + k * L_frameTCX / 2); floatToFixed_arr(Aq, Aq_fx, Q12, M + 1); + st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + st->preemph_fac = float_to_fix16(st->preemph_fac_float, Q15); + st->hTcxLtpDec->tcxltp_gain = float_to_fix16( st->hTcxLtpDec->tcxltp_gain_float, Q15 ); + st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); //decoder_tcx_fx( st, prm, Aq, Aind, &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], bfi, k, 0 ); decoder_tcx_fx( st, prm, Aq_fx, Aind, &synth_fx[k * L_frame / 2], &synthFB_fx[k * L_frameTCX / 2], bfi, k, 0 ); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index a5ff481b5..28686b454 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3226,10 +3226,10 @@ void decoder_tcx_fx( #ifdef IVAS_FLOAT_FIXED /* TODO: Temporary inits. Remove float dependency */ st->gamma = float_to_fix16( st->gamma_float, Q15 ); - st->preemph_fac = float_to_fix16( st->preemph_fac_float, Q15 ); + //st->preemph_fac = float_to_fix16( st->preemph_fac_float, Q15 ); st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); st->Mode2_lp_gainp = float_to_fix( st->lp_gainp, Q16 ); - st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 ); + //st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 ); st->hTcxCfg->na_scale = float_to_fix16( st->hTcxCfg->na_scale_flt, Q15 ); st->hTcxCfg->sq_rounding = float_to_fix16( st->hTcxCfg->sq_rounding_flt, Q15 ); st->hTcxLtpDec->tcxltp_gain = float_to_fix16( st->hTcxLtpDec->tcxltp_gain_float, Q15 ); @@ -3277,21 +3277,6 @@ void decoder_tcx_fx( dbgwrite_txt(&(st->hTcxDec->damping_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_dampingFact.txt", NULL); dbgwrite_txt(&(st->lp_gainp), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_lpGainp.txt", NULL); #endif -#else - //decoder_tcx_invQ( st, prm, A, Aind, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &xn_buf[0], &fUseTns, &tnsData, &gain_tcx, &prm_sqQ, &nf_seed, bfi, frame_cnt ); -#if 0 - dbgwrite_txt(x, L_frameTCX, "logs\\dir\\Float_code_decoderTcxInvQ_x.txt", NULL); - dbgwrite_txt(xn_buf, max(max(L_frame, L_spec), L_frameTCX), "logs\\dir\\Float_code_decoderTcxInvQ_xnBuf.txt", NULL); - dbgwrite_txt(gainlpc2, FDNS_NPTS, "logs\\dir\\Float_code_decoderTcxInvQ_gainlpc2.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->stepCompensate_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_stepCompensate.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->gainHelper_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_gainHelper.txt", NULL); - dbgwrite_txt(&(st->last_concealed_gain_syn_deemph_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_lastConcealedGainSynDeemph.txt", NULL); - dbgwrite_txt(&(st->last_gain_syn_deemph_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_lastGainSynDeemph.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->old_gaintcx_bfi_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_oldGaintcxBfi.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->cummulative_damping_tcx_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_cummulativeDampingTcx.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->damping_float), 1, "logs\\dir\\Float_code_decoderTcxInvQ_dampingFact.txt", NULL); - dbgwrite_txt(&(st->lp_gainp), 1, "logs\\dir\\Float_code_decoderTcxInvQ_lpGainp.txt", NULL); -#endif #endif #ifdef IVAS_FLOAT_FIXED @@ -3301,8 +3286,8 @@ void decoder_tcx_fx( f2me_16( gainlpc2[j], &gainlpc2_fx[j], &gainlpc2_e[j] ); } f2me_16( gain_tcx, &gain_tcx_fx, &gain_tcx_e ); - st->hTcxLtpDec->tcxltp_gain = float_to_fix16( st->hTcxLtpDec->tcxltp_gain_float, Q15 ); - st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); + //st->hTcxLtpDec->tcxltp_gain = float_to_fix16( st->hTcxLtpDec->tcxltp_gain_float, Q15 ); + //st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) { st->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( st->hTcxDec->ltpGainMemory[l], Q15 ); @@ -3313,8 +3298,6 @@ void decoder_tcx_fx( st->hTcxDec->ltpGainMemory[l] = fix16_to_float( st->hTcxDec->ltpGainMemory_fx[l], Q15 ); } me2f_buf( x_fx, x_e, x, N_MAX ); -#else - //decoder_tcx_noisefilling( st, NULL, A, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, &x[0], &gainlpc2[0], &tmp_concealment_method, gain_tcx, prm_sqQ, nf_seed, bfi, 0, frame_cnt ); #endif #ifdef IVAS_FLOAT_FIXED @@ -3370,8 +3353,6 @@ void decoder_tcx_fx( me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpecBuf, (N_MAX_TCX - IGF_START_MN)); me2f_buf(x_fx, x_e, x, x_len); // Fixed to float ends here -#else - //decoder_tcx_noiseshaping_igf( st, L_spec, L_frame, L_frameTCX, left_rect, &x[0], &gainlpc2[0], &tmp_concealment_method, bfi ); #endif #ifdef IVAS_FLOAT_FIXED @@ -3381,10 +3362,10 @@ void decoder_tcx_fx( FOR(Word16 ind = 0; ind < 1200; ind++) maximum = fmaxf(maximum, fabsf(x[ind])); if(maximum>=1.f) q = norm_l((Word32)maximum) - 5; FOR(Word16 ind = 0; ind < 1200; ind++) x_fx_[ind] = (Word32)(x[ind] * (1 << q)); + decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx_, fUseTns, &tnsData, bfi, frame_cnt, 0 ); + FOR(Word16 ind = 0; ind < 1200; ind++) x[ind] = (float)(x_fx_[ind]) / (float)(1 << q); -#else - //decoder_tcx_tns( st, L_frame_glob, L_spec, L_frame, L_frameTCX, &x[0], fUseTns, &tnsData, bfi, frame_cnt, 0 ); #endif #ifdef IVAS_FLOAT_FIXED @@ -3503,11 +3484,7 @@ void decoder_tcx_fx( st->hTcxDec->tcxltp_second_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_second_last_pitch, 16); st->old_fpitch_float = fix_to_float(st->old_fpitch, 16); st->old_fpitchFB_float = fix_to_float(st->old_fpitchFB, 16); - // -#else - //decoder_tcx_imdct( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x[0], &xn_buf[0], MDCT_IV, - // fUseTns, &synth[0], &synthFB[0], bfi, frame_cnt, sba_dirac_stereo_flag ); #endif } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index fe75a28b2..dd7126fc2 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -561,6 +561,9 @@ void configureFdCngDec_fx( hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping; move16(); + BASOP_getTables(&hsCom->olapWinAna, NULL, NULL, shr(hsCom->fftlen, 1)); + BASOP_getTables(&hsCom->olapWinSyn, NULL, NULL, shr(hsCom->fftlen, 2)); + SWITCH ( hsCom->fftlen ) { case 512: diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index da29a4795..80c921da1 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -163,6 +163,9 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED Word16 hb_synth_fx[6][L_FRAME48k]; /*not sure about number of channels so kept it as 6 will change it later*/ Word32 hb_synth_32[6][L_FRAME48k]; + Word16 output_16fx[CPE_CHANNELS][L_FRAME48k]; + Word16 synth_16fx[CPE_CHANNELS][L_FRAME48k]; + Word32 pitch_buf_32fx[CPE_CHANNELS][NB_SUBFR16k]; #endif error = IVAS_ERR_OK; @@ -826,13 +829,28 @@ ivas_error ivas_core_dec( #endif } - if ( ( st->core == TCX_20_CORE || st->core == TCX_10_CORE ) && st->element_mode != IVAS_CPE_MDCT ) +#ifdef IVAS_FLOAT_FIXED + IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - stereo_tcx_dec_mode_switch_reconf_To_fixed(st, 1, last_element_mode); + stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st, 1, last_element_mode); + + /* TCX decoder */ + stereo_tcx_core_dec_fx( st, frameMode[n], output_16fx[n], synth_16fx[n], pitch_buf_32fx[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 ); + + fixedToFloat_arr( output_16fx[n], output[n], 0, st->L_frame ); + fixedToFloat_arr( synth_16fx[n], synth[n], 0, st->hTcxDec->L_frameTCX ); + fixedToFloat_arrL( pitch_buf_32fx[n], pitch_buf[n], Q6, NB_SUBFR16k ); + stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st, 0, last_element_mode); + fixed_to_float_stereo_tcx_core_dec( st, output[n] ); + } +#else + 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 ); } +#endif // IVAS_FLOAT_FIXED if ( st->core == HQ_CORE ) { diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 3b44fa529..f4119e60d 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -49,7 +49,9 @@ * Local prototypes *-------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void dec_prm_tcx( Decoder_State *st, int16_t param[], int16_t param_lpc[], int16_t *total_nbbits, const int16_t last_element_mode, int16_t *bitsRead ); +#endif // !IVAS_FLOAT_FIXED static void stereo_tcx_dec_mode_switch_reconf( Decoder_State *st, const int16_t MCT_flag, const int16_t last_element_mode ); @@ -237,61 +239,49 @@ void stereo_tcx_init_dec( } +#ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* - * stereo_tcx_core_dec() + * stereo_tcx_core_dec_fx() * * stereo TCX decoder *-------------------------------------------------------------------*/ -void stereo_tcx_core_dec( +void stereo_tcx_core_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ const FRAME_MODE frameMode, /* i : Decoder frame mode */ - float *signal_out, /* o : synthesis @internal_Fs */ - float *signal_outFB, /* o : synthesis @output_Fs */ - float pitch_buf[], /* o : floating pitch for each subframe */ - const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + Word16 *signal_out_fx, /* o : synthesis @internal_Fs, Q0 */ + Word16 *signal_outFB_fx, /* o : synthesis @output_Fs, Q0 */ + Word32 pitch_buf_fx[], /* o : floating pitch for each subframe, Q6 */ + const Word16 sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ - const int16_t last_element_mode, /* i : last element mode */ - const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ + const Word16 last_element_mode, /* i : last element mode */ + const Word16 flag_sec_CNA, /* i : CNA flag for secondary channel */ STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ - const int16_t nchan_out, /* i : number of output channels */ + const Word16 nchan_out, /* i : number of output channels */ const IVAS_FORMAT ivas_format /* i : IVAS format */ ) { - int16_t i, k; + Word16 i, k; /*Bitstream*/ - int16_t total_nbbits, bitsRead; - int16_t *prm, param[DEC_NPRM_DIV * NB_DIV]; - int16_t param_lpc[NPRM_LPC_NEW]; + Word16 total_nbbits, bitsRead; + Word16 *prm, param[DEC_NPRM_DIV * NB_DIV]; + Word16 param_lpc[NPRM_LPC_NEW]; /*LPC*/ - int16_t LSF_Q_prediction; /* o : LSF prediction mode */ - float lsf[( NB_DIV + 1 ) * M], lsp[( NB_DIV + 1 ) * M], lspmid[M], lsfmid[M]; - float lspnew_uw[NB_DIV * M], lsfnew_uw[NB_DIV * M]; - float Aq[( NB_SUBFR16k + 1 ) * ( M + 1 )]; - int16_t pitch[NB_SUBFR16k]; - float pit_gain[NB_SUBFR16k]; + Word16 LSF_Q_prediction; /* o : LSF prediction mode */ + Word16 pitch[NB_SUBFR16k]; Word16 Aind[M + 1], lspind[M]; - /*Synth*/ - float synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; - float *synth; - float synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; - float *synthFB; - /*Concealment*/ - int16_t bfi; + Word16 bfi; - float psd[L_FRAME16k], psd_part[NPART_SHAPING]; -#ifdef IVAS_FLOAT_FIXED Word32 L_tmp, mod; /*LPC*/ Word16 lsf_fx[( NB_DIV + 1 ) * M], lsp_fx[( NB_DIV + 1 ) * M], lspmid_fx[M], lsfmid_fx[M]; Word16 lspnew_uw_fx[NB_DIV * M], lsfnew_uw_fx[NB_DIV * M]; Word16 Aq_fx[( NB_SUBFR16k + 1 ) * ( M + 1 )]; - Word16 q_Aq; Word16 pit_gain_fx[NB_SUBFR16k]; /*Synth*/ @@ -303,7 +293,6 @@ void stereo_tcx_core_dec( Word32 psd_fx[L_FRAME16k]; Word32 psd_part_fx[NPART_SHAPING]; Word16 psd_part_e; -#endif // IVAS_FLOAT_FIXED TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; @@ -323,99 +312,43 @@ void stereo_tcx_core_dec( * Initialization or re-configuration of Stereo TCX *--------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED - stereo_tcx_init_dec( st, 0, last_element_mode ); - - /*--------------------------------------------------------------------------------* - * Initializations - *--------------------------------------------------------------------------------*/ - - total_nbbits = (int16_t) ( st->total_brate / FRAMES_PER_SEC ); - bitsRead = 0; - LSF_Q_prediction = -1; /* to avoid compilation warnings */ - - if ( frameMode == FRAMEMODE_NORMAL ) - { - st->m_decodeMode = DEC_NO_FRAM_LOSS; - bfi = 0; - } - - if ( frameMode == FRAMEMODE_MISSING ) - { - st->m_decodeMode = DEC_CONCEALMENT_EXT; - bfi = 1; - } -#else - stereo_tcx_init_dec_fx(st, 0, last_element_mode); - - stereo_tcx_dec_mode_switch_reconf_To_fixed(st, 0, last_element_mode); - -#endif // IVAS_FLOAT_FIXED - - /* for bass postfilter */ - if ( st->tcxonly ) - { - st->p_bpf_noise_buf_float = NULL; - } - else - { - st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; - set_s(pitch, L_SUBFR, st->nb_subfr); - set_zero(pit_gain, st->nb_subfr); - } - - /* Initialize pointers */ - synth = synth_buf + hTcxDec->old_synth_len; - synthFB = synth_bufFB + hTcxDec->old_synth_lenFB; - mvr2r( hTcxDec->old_synth_float, synth_buf, hTcxDec->old_synth_len ); - mvr2r( hTcxDec->old_synthFB, synth_bufFB, hTcxDec->old_synth_lenFB ); - set_zero( synth, L_FRAME_PLUS + M ); - set_zero( synthFB, L_FRAME_PLUS + M ); - -#ifdef IVAS_FLOAT_FIXED - - for ( int p = 0; p < hTcxDec->old_synth_len; p++ ) - { - hTcxDec->old_synth[p] = (Word16) ( hTcxDec->old_synth_float[p] ); - } - for ( int p = 0; p < hTcxDec->old_synth_lenFB; p++ ) - { - hTcxDec->old_synthFB_fx[p] = (Word16) ( hTcxDec->old_synthFB[p] + 0.5f ); - } + stereo_tcx_init_dec_fx( st, 0, last_element_mode ); - /*=================================*/ /*--------------------------------------------------------------------------------* * Initializations *--------------------------------------------------------------------------------*/ - //total_nbbits = (Word16) ( st->total_brate / FRAMES_PER_SEC ); iDiv_and_mod_32( st->total_brate, FRAMES_PER_SEC, &L_tmp, &mod, 0 ); total_nbbits = (Word16) L_tmp; bitsRead = 0; LSF_Q_prediction = -1; /* to avoid compilation warnings */ - IF ( frameMode == FRAMEMODE_NORMAL ) + IF( EQ_32(frameMode, FRAMEMODE_NORMAL) ) { st->m_decodeMode = DEC_NO_FRAM_LOSS; bfi = 0; } - IF ( frameMode == FRAMEMODE_MISSING ) + IF( EQ_32(frameMode, FRAMEMODE_MISSING) ) { st->m_decodeMode = DEC_CONCEALMENT_EXT; bfi = 1; } /* for bass postfilter */ - IF(st->tcxonly) + IF( st->tcxonly ) { - st->p_bpf_noise_buf_32 = NULL; + st->p_bpf_noise_buf_32 = NULL; + // To be removed + st->p_bpf_noise_buf_float = NULL; } ELSE { st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32; st->p_bpf_noise_buf = st->bpf_noise_buf; - set_s(pitch, L_SUBFR, st->nb_subfr); - set16_fx(pit_gain_fx, 0, st->nb_subfr); + set_s( pitch, L_SUBFR, st->nb_subfr ); + set16_fx( pit_gain_fx, 0, st->nb_subfr ); + // To be removed + st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; } /* Initialize pointers */ @@ -430,139 +363,55 @@ void stereo_tcx_core_dec( * BITSTREAM DECODING *--------------------------------------------------------------------------------*/ - IF ( !bfi ) + IF( !bfi ) { st->second_last_core = st->last_core; dec_prm_tcx_ivas_fx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); - - stereo_tcx_dec_mode_switch_reconf_To_fixed(st, 0, last_element_mode); - } -#else - /*--------------------------------------------------------------------------------* - * BITSTREAM DECODING - *--------------------------------------------------------------------------------*/ - - if ( !bfi ) - { - st->second_last_core = st->last_core; - - dec_prm_tcx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); } -#endif // IVAS_FLOAT_FIXED - else + ELSE { - if ( st->nbLostCmpt > 1 ) + IF( GT_16( st->nbLostCmpt, 1 ) ) { st->flagGuidedAcelp = 0; } /* PLC: [Common: mode decision] * PLC: Decide which Concealment to use. Update pitch lags if needed */ -#ifdef IVAS_FLOAT_FIXED_ - st->hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( st->hTcxDec->tcxltp_last_gain_unmodified_float, 15 ); - st->hTcxDec->tcxltp_second_last_pitch = floatToFixed( st->hTcxDec->tcxltp_second_last_pitch_float, 16 ); - st->hTcxDec->tcxltp_third_last_pitch = floatToFixed( st->hTcxDec->tcxltp_third_last_pitch_float, 16 ); - st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); - floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); - floatToFixed_arr( st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2 ); - st->last_good = st->last_good; - floatToFixed_arr( st->hTonalMDCTConc->pTCI_float->phaseDiff_float, st->hTonalMDCTConc->pTCI_fix->phaseDiff, Q12, MAX_NUMBER_OF_IDX ); - floatToFixed_arr( st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float, st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted, Q13, MAX_NUMBER_OF_IDX * GROUP_LENGTH ); - st->hTonalMDCTConc->pTCI_fix->numIndexes = st->hTonalMDCTConc->pTCI_float->numIndexes; - for ( int p = 0; p < MAX_NUMBER_OF_IDX; p++ ) - { - st->hTonalMDCTConc->pTCI_fix->indexOfTonalPeak[p] = st->hTonalMDCTConc->pTCI_float->indexOfTonalPeak[p]; - st->hTonalMDCTConc->pTCI_fix->lowerIndex[p] = st->hTonalMDCTConc->pTCI_float->lowerIndex[p]; - st->hTonalMDCTConc->pTCI_fix->upperIndex[p] = st->hTonalMDCTConc->pTCI_float->upperIndex[p]; - } - floatToFixed_arr(st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, Q2,st->hTonalMDCTConc->nSamples ); - /*=============================================*/ - st->core = GetPLCModeDecision( st ); - /*=============================================*/ - fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); - fixedToFloat_arr( st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2 ); - st->hTonalMDCTConc->pTCI_float->numIndexes = st->hTonalMDCTConc->pTCI_fix->numIndexes; - fixedToFloat_arr( st->hTonalMDCTConc->pTCI_fix->phaseDiff, st->hTonalMDCTConc->pTCI_float->phaseDiff_float, Q12, MAX_NUMBER_OF_IDX ); - fixedToFloat_arr( st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted, st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float, Q13, MAX_NUMBER_OF_IDX * GROUP_LENGTH ); - for ( int p = 0; p < MAX_NUMBER_OF_IDX; p++ ) - { - st->hTonalMDCTConc->pTCI_float->indexOfTonalPeak[p] = st->hTonalMDCTConc->pTCI_fix->indexOfTonalPeak[p]; - st->hTonalMDCTConc->pTCI_float->lowerIndex[p] = st->hTonalMDCTConc->pTCI_fix->lowerIndex[p]; - st->hTonalMDCTConc->pTCI_float->upperIndex[p] = st->hTonalMDCTConc->pTCI_fix->upperIndex[p]; - } -#else - st->core = GetPLCModeDecision_flt( st ); -#endif // IVAS_FLOAT_FIXED - } - -#ifdef IVAS_FLOAT_FIXED - float scale = 1.f; - if ( st->lpcQuantization && st->prev_lpcQuantization ) - { - st->scale = 1.f; - scale = 1.f; - } - else if ( st->lpcQuantization && st->prev_lpcQuantization == 0 ) - { - scale = 1.f; - } - else if ( !st->lpcQuantization ) - { - st->scale = (float) st->sr_core / INT_FS_12k8; - scale = (float) st->sr_core / INT_FS_12k8; - } - for ( int p = 0; p < M; p++ ) - { - st->mem_MA_fx[p] = (Word16) ( st->mem_MA[p] * 2.56 ); - st->mem_AR_fx[p] = (Word16) ( st->mem_AR[p] * 2.56 ); - st->lsf_cng[p] = (Word16) ( st->lsf_cng_float[p] * 2.56 / st->scale ); - st->old_lsf_q_cng[p] = (Word16) ( st->old_lsf_q_cng_float[p] * 2.56 / st->scale ); - st->lsf_old_fx[p] = (Word16) ( st->lsf_old[p] * 2.56 / st->scale ); - st->lsp_old_fx[p] = (Word16) ( st->lsp_old[p] * MAX_16 ); - } - if ( st->gamma_float == GAMMA1_FLT ) - { - st->inv_gamma = GAMMA1_INV; - } - else if ( st->gamma_float == GAMMA16k_FLT ) - { - st->inv_gamma = GAMMA16k_INV; - } - - floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); - for ( int p = 0; p < M; p++ ) - { - st->lsfold_uw[p] = (Word16) ( st->lsfold_uw_float[p] * 2.56 / st->scale ); + st->core = GetPLCModeDecision_ivas_fx( st ); } - for ( i = 0; i < M; i++ ) - { - st->lsf_adaptive_mean_fx[i] = (Word16) ( st->lsf_adaptive_mean[i] * ( 2.56f / st->scale ) ); - } - st->stab_fac_fx = (Word16) floatToFixed( st->stab_fac, Q15 ); - /*=============================================*/ - for (int p = 0; p < 2 * NB_SUBFR16k + 2; p++) - { - st->old_pitch_buf_fx[p] = (Word32)(st->old_pitch_buf[p] * ONE_IN_Q16); - } - for (int p = 0; p < st->L_frame; p++) +#if 1 // TO BE REMOVED + IF( bfi && ( NE_16( st->last_core, -1 ) && EQ_16( st->nbLostCmpt, 1 ) ) ) { - st->hTcxDec->old_excFB_fx[p] = (Word16)(st->hTcxDec->old_excFB[p] * (1u << st->Q_exc)); + IF( !( st->rf_flag && st->use_partial_copy && ( EQ_16( st->rf_frame_type, RF_TCXTD1 ) || EQ_16( st->rf_frame_type, RF_TCXTD2 ) ) ) ) + { + IF( st->hTonalMDCTConc != NULL && st->last_core == TCX_20_CORE && st->second_last_core == TCX_20_CORE && ( ( st->old_fpitch_float <= 0.5f * st->L_frame ) || ( st->hTcxDec->tcxltp_last_gain_unmodified_float <= 0.4f ) ) + /* it is fine to call the detection even if no ltp information + is available, meaning that st->old_fpitch == + st->tcxltp_second_last_pitch == st->L_frame */ + && ( st->old_fpitch_float == st->hTcxDec->tcxltp_second_last_pitch_float ) && !st->last_tns_active && !st->second_last_tns_active ) + { + st->hTonalMDCTConc->pTCI_float->numIndexes = st->hTonalMDCTConc->pTCI_fix->numIndexes; + FOR( i = 0; i < st->hTonalMDCTConc->pTCI_fix->numIndexes; ++i ) + { + st->hTonalMDCTConc->pTCI_float->indexOfTonalPeak[i] = st->hTonalMDCTConc->pTCI_fix->indexOfTonalPeak[i]; + st->hTonalMDCTConc->pTCI_float->lowerIndex[i] = st->hTonalMDCTConc->pTCI_fix->lowerIndex[i]; + st->hTonalMDCTConc->pTCI_float->upperIndex[i] = st->hTonalMDCTConc->pTCI_fix->upperIndex[i]; + } + FOR( i = 0; i < st->hTonalMDCTConc->pTCI_fix->numIndexes; i++ ) + { + st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i] = fixedToFloat( st->hTonalMDCTConc->pTCI_fix->phaseDiff[i], Q12 ); + } + FOR( i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++ ) + { + st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i] = fixedToFloat( st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted[i], Q13 ); + } + } + } } - st->prev_Q_syn = st->Q_syn; - st->last_good = st->last_good; - st->old_fpitchFB = (Word32)(st->old_fpitchFB_float * ONE_IN_Q16); - st->old_fpitch = (Word32)(st->old_fpitch_float * ONE_IN_Q16); - st->stab_fac_fx = (Word16)(st->stab_fac * MAX_16); - st->lp_gainp_fx = (Word16)floatToFixed(st->lp_gainp, Q14); +#endif // 1 - floatToFixed_arr(lsp, lsp_fx, Q15, 2 * M); - floatToFixed_arr(st->old_lsp_q_cng_float, st->old_lsp_q_cng, Q15, M); - floatToFixed_arr(st->lsp_q_cng_float, st->lsp_q_cng, Q15, M); - floatToFixed_arr( synth, synth_fx, 0, st->L_frame ); - floatToFixed_arr( synthFB, synthFB_fx, 0, hTcxDec->L_frameTCX ); - /*====================================*/ /*--------------------------------------------------------------------------------* * LPC PARAMETERS *--------------------------------------------------------------------------------*/ @@ -607,7 +456,17 @@ void stereo_tcx_core_dec( } lpc_unquantize( st, lsf_fx, lsp_fx, M, param_lpc, lspmid_fx, lsfmid_fx, AUDIO, &LSF_Q_prediction ); - // st->prev_lpcQuantization = st->lpcQuantization; + // To be removed + IF( !st->lpcQuantization ) + { + st->scale = (float) st->sr_core / INT_FS_12k8; + } + ELSE + { + st->scale = 1.f; + } + + st->prev_lpcQuantization = st->lpcQuantization; FOR( k = 0; k < st->numlpc; ++k ) { @@ -631,8 +490,9 @@ void stereo_tcx_core_dec( { /* PLC: [LPD: LPC concealment] Conceal the LPC from the lost frame */ const Word16 *lsfBase; /* base for differential lsf coding */ + st->scale = 1.f; // To be removed - IF( st->tcxonly == 0 || st->core < TCX_10_CORE ) + IF( EQ_16( st->tcxonly, 0 ) || LT_16( st->core, TCX_10_CORE ) ) { st->numlpc = 1; } @@ -641,7 +501,7 @@ void stereo_tcx_core_dec( st->numlpc = 2; } - IF( st->nbLostCmpt == 1 ) + IF( EQ_16( st->nbLostCmpt, 1 ) ) { Copy( st->lsf_old_fx, st->old_lsf_q_cng, M ); Copy( st->lsp_old_fx, st->old_lsp_q_cng, M ); @@ -715,10 +575,11 @@ void stereo_tcx_core_dec( lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); st->con_tcx = 1; - set16_fx( &st->mem_pitch_gain[2], st->lp_gainp_fx, st->nb_subfr ); + // set16_fx( &st->mem_pitch_gain[2], st->lp_gainp_fx, st->nb_subfr ); + set16_fx( &st->mem_pitch_gain[2], extract_l( L_shr( st->Mode2_lp_gainp, 15 ) ), st->nb_subfr ); /* LPC for ACELP/BWE */ - IF( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { Copy( Aq_fx, st->mem_Aq, st->nb_subfr * ( M + 1 ) ); } @@ -745,7 +606,6 @@ void stereo_tcx_core_dec( { st->stab_fac_fx = lsf_stab_fx( &lsf_fx[M], &lsf_fx[0], 0, st->L_frame ); } - st->prev_lpcQuantization = st->lpcQuantization; IF( hTcxDec->enableTcxLpc ) { @@ -814,161 +674,387 @@ void stereo_tcx_core_dec( } } - /*============================================*/ - if( EQ_16( st->core, ACELP_CORE ) ) + /*--------------------------------------------------------------------------------* + * Post-processing + *--------------------------------------------------------------------------------*/ + + IF( EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, TCX_20_CORE ) ) { - if ( ( EQ_16( st->nbLostCmpt, 1 ) ) || hTcxDec->tcxConceal_recalc_exc ) + IF( st->enablePlcWaveadjust || /* bfi */ + ( GE_32( st->last_total_brate, HQ_48k ) && /* recovery */ + EQ_16( st->last_codec_mode, MODE2 ) ) ) { - for ( int p = 0; p < st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M; p++ ) - { - synthFB[p - ( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )] = (float) synthFB_fx[p - ( st->hTcxDec->L_frameTCX / 2 + hTcxDec->pit_max_TCX + 2 * M )]; - } - } - else - { - for ( int p = 0; p < st->hTcxDec->L_frameTCX; p++ ) + /* waveform adjustment */ + concealment_signal_tuning_fx( bfi, st->core, synthFB_fx, &st->plcInfo, st->nbLostCmpt, st->prev_bfi, st->hTonalMDCTConc->secondLastPcmOut, st->last_core_bfi, st->hTonalMDCTConc->lastPcmOut, st ); + + IF( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) ) { - synthFB[p - ( st->hTcxDec->L_frameTCX )] = (float) synthFB_fx[p - ( st->hTcxDec->L_frameTCX )]; + lerp( synthFB_fx, synth_fx, st->L_frame, hTcxDec->L_frameTCX ); + + IF( !bfi && st->prev_bfi ) + { + st->hPlcInfo->Pitch = 0; + } } } - for ( int p = 0; p < M + 1; p++ ) - { - st->old_Aq_12_8[p] = (float) st->old_Aq_12_8_fx[p] / ( 1u << ( 15 - ( norm_s( st->old_Aq_12_8_fx[0] - 1 ) ) ) ); - } - for ( int p = 0; p < M; p++ ) - { - st->mem_syn2[p] = (float) st->mem_syn2_fx[p]; - } - for ( int p = 0; p < M + 1; p++ ) - { - st->syn_float[p] = (float) st->syn[p] / pow( 2, st->Q_syn ); - } - for ( int p = 0; p < L_EXC_MEM_DEC; p++ ) - { - st->old_exc[p] = (float) st->old_exc_fx[p] / ( 1u << st->Q_exc ); - } - for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) - { - st->old_pitch_buf[p] = (float) st->old_pitch_buf_fx[p] / ONE_IN_Q16; - } - for ( int p = 0; p < st->L_frame / 2; p++ ) - { - st->hTcxDec->syn_OverlFB_float[p] = (float) st->hTcxDec->syn_OverlFB[p] / pow( 2, st->Q_syn ); - st->hTcxDec->syn_Overl_float[p] = (float) st->hTcxDec->syn_Overl[p] / pow( 2, st->Q_syn ); - st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); - st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * pow( 2, st->Q_syn ); - st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * pow( 2, st->Q_syn ); - } - for ( int p = 0; p < st->L_frame; p++ ) - { - st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); - st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->hHQ_core->Q_old_wtda ); - } - for ( int p = 0; p < st->L_frame; p++ ) - { - st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); - } - for ( int p = 0; p < 60; p++ ) - { - st->mem_syn_r_float[p] = (float) ( st->mem_syn_r[p] ); - } - st->preemph_fac_float = (float) st->preemph_fac / MAX_16; - st->lp_gainc = (float) st->Mode2_lp_gainc / ONE_IN_Q16; - st->lp_gainp = (float) st->Mode2_lp_gainp / ONE_IN_Q29; - st->cummulative_damping_float = (float) st->cummulative_damping / MAX_16; - st->old_enr_LP_float = (float) st->old_enr_LP / ONE_IN_Q3; - st->bfi_pitch = (float) st->bfi_pitch_fx / ONE_IN_Q6; - fixedToFloat_arr( synth_fx, synth, 0, hTcxDec->L_frameTCX ); - fixedToFloat_arr( &st->mem_pitch_gain[2], &st->mem_pitch_gain_float[2], Q14, st->nb_subfr ); - if ( !st->tcxonly ) + IF( !bfi && st->hTonalMDCTConc != NULL ) { - for ( int p = 0; p < shr( st->L_frame, 6 ); p++ ) - { - q_Aq = 15 - ( norm_s( Aq_fx[p * ( M + 1 )] - 1 ) ); - fixedToFloat_arr( Aq_fx + p * ( M + 1 ), Aq + p * ( M + 1 ), q_Aq, ( M + 1 ) ); - q_Aq = 15 - ( norm_s( st->Aq_cng[p * ( M + 1 )] - 1 ) ); - fixedToFloat_arr( st->Aq_cng + p * ( M + 1 ), st->Aq_cng_float + p * ( M + 1 ), q_Aq, ( M + 1 ) ); - } + TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, hTcxDec->L_frameTCX ); + // To be removed + fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2 ); + fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples ); } - IF( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + + decoder_tcx_post( st, synth_fx, synthFB_fx, Aq_fx, bfi ); + + IF( EQ_16( st->core, TCX_20_CORE ) ) { - for ( int p = 0; p < st->nb_subfr; p++ ) + /* LPC Interpolation for BWE/post-processing */ + IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) { - q_Aq = 15 - ( norm_s( st->mem_Aq[p * ( M + 1 )] - 1 ) ); - fixedToFloat_arr( st->mem_Aq + p * ( M + 1 ), st->mem_Aq_float + p * ( M + 1 ), q_Aq, ( M + 1 ) ); + int_lsp_fx( st->L_frame, st->lspold_uw, lspnew_uw_fx, Aq_fx, M, interpol_frac_fx, 0 ); + Copy( Aq_fx, st->mem_Aq, st->nb_subfr * ( M + 1 ) ); } } } - /*======================================*/ - if ( st->rate_switching_reset ) + /* PLC: [Common: Classification] */ + /* the classifier buffer is always updated if the sr is at + 16000 or below - the classification itself is just performed if(!st->tcxonly ) */ + IF( LE_32( st->sr_core, INT_FS_16k ) ) { - q_Aq = 15 - ( norm_s( st->old_Aq_12_8_fx[0] - 1 ) ); - fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, q_Aq, M + 1 ); - st->scale = scale; - } + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || ( st->tcxonly && st->bfi ) ) + { + Word16 pitch_C[4]; - for ( int p = 0; p < M; p++ ) - { - st->lsf_old[p] = (float) st->lsf_old_fx[p] / ( 2.56f / st->scale ); - st->lsp_old[p] = (float) st->lsp_old_fx[p] / ONE_IN_Q15; - } + /* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */ + set16_fx( pitch_C, shl( round_fx( st->old_fpitch ), Q6 ), 4 ); - for ( int p = 0; p < M * ( 1 + st->numlpc ); p++ ) - { - lsf[p] = (float) lsf_fx[p] / ( 2.56f / scale ); - lsp[p] = (float) lsp_fx[p] / ONE_IN_Q15; - } - if ( st->lpcQuantization ) - { - st->safety_net = st->safety_net_fx; - st->mid_lsf_int = st->mid_lsf_int_fx; - } - if ( st->lpcQuantization && st->acelp_cfg.midLpc && st->core == ACELP_CORE && st->rate_switching_reset == 0 || st->rate_switching_reset ) - { - for ( int p = 0; p < M; p++ ) - { - lsfmid[p] = (float) lsfmid_fx[p] / 2.56f; - lspmid[p] = (float) lspmid_fx[p] / ONE_IN_Q15; + /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ + Word16 prev_codec_mode = st->codec_mode; + st->codec_mode = MODE2; + FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->tcxonly ? GENERIC : st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_bfi_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 /*st->core_brate*/, st->Q_syn, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); + st->codec_mode = prev_codec_mode; } } - for ( int p = 0; p < M; p++ ) + + /*--------------------------------------------------------------------------------* + * Updates + *--------------------------------------------------------------------------------*/ + + IF( bfi && NE_16( st->last_core, ACELP_CORE ) ) { - st->mem_MA[p] = (float) st->mem_MA_fx[p] / 2.56f; - st->mem_AR[p] = (float) st->mem_AR_fx[p] / 2.56f; - st->lsf_adaptive_mean[p] = (float) st->lsf_adaptive_mean_fx[p] / ( 2.56f / st->scale ); - st->lsfoldbfi1[p] = (float) st->lsfoldbfi1_fx[p] / ( 2.56f / st->scale ); - st->lsfoldbfi0[p] = (float) st->lsfoldbfi0_fx[p] / ( 2.56f / st->scale ); - st->lsf_q_cng_float[p] = (float) st->lsf_q_cng[p] / ( 2.56f / st->scale ); - st->old_lsf_q_cng_float[p] = (float) st->old_lsf_q_cng[p] / ( 2.56f / st->scale ); + /* Update FEC_scale_syn parameters */ + IF( hTcxLtpDec->tcxltp_gain_float == 0 ) + { + frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr( st->L_frame, 1 ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); + } + ELSE + { + frame_ener_fx( st->L_frame, st->clas_dec, synth_fx, extract_l( L_shr( st->old_fpitch, 16 ) ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); + } } - st->stab_fac = fixedToFloat( st->stab_fac_fx, Q15 ); - for ( int p = 0; p < M * st->numlpc; p++ ) + IF( !bfi && GE_16( st->clas_dec, VOICED_TRANSITION ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) { - lsfnew_uw[p] = (float) lsfnew_uw_fx[p] / ( 2.56f / st->scale ); + /* use latest LPC set */ + st->old_enr_LP = Enr_1_Az_fx( Aq_fx, L_SUBFR ); // Q3 } - fixedToFloat_arr( lspnew_uw_fx, lspnew_uw, Q15, st->numlpc * M ); - fixedToFloat_arr( st->lsp_q_cng, st->lsp_q_cng_float, Q15, M ); - q_Aq = 15 - ( norm_s( Aq_fx[0] - 1 ) ); - fixedToFloat_arr( Aq_fx, Aq, q_Aq, M + 1 ); - fixedToFloat_arr( synth_fx, synth, 0, st->L_frame ); - fixedToFloat_arr( synthFB_fx, synthFB, 0, hTcxDec->L_frameTCX ); + /* Update past buffers */ + Copy( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len ); + Copy( hTcxDec->old_synthFB_fx + hTcxDec->L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); + Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); + Copy( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); -#else - /*--------------------------------------------------------------------------------* - * LPC PARAMETERS - *--------------------------------------------------------------------------------*/ + Copy( &lspnew_uw_fx[( st->numlpc - 1 ) * M], st->lspold_uw, M ); + Copy( &lsfnew_uw_fx[( st->numlpc - 1 ) * M], st->lsfold_uw, M ); - st->acelp_cfg.midLpc = 0; + IF( EQ_16( bfi, 1 ) ) + { + Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery */ + Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery */ + } + ELSE + { + Copy( &lsp_fx[st->numlpc * M], st->lsp_old_fx, M ); + Copy( &lsf_fx[st->numlpc * M], st->lsf_old_fx, M ); + } + Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); + Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); - if ( !bfi ) + /* Update CNG parameters */ + IF( !st->tcxonly && st->hTdCngDec != NULL ) { - if ( hTcxDec->enableTcxLpc ) - { + /* update CNG parameters in active frames */ + IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) + { + Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_h[M + 1], r_l[M + 1], tmp, lsptmp[M], q_r; + assert( st->L_frame == L_FRAME ); + + Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); + tmp = synth_fx[L_FRAME - L_LP - 1]; + E_UTIL_f_preemph2( 0, buf, st->preemph_fac, L_LP, &tmp ); + autocorr_fx( buf, M, r_h, r_l, &q_r, L_LP, Assym_window_W16fx, 0, 0 ); + lag_wind( r_h, r_l, M, INT_FS_12k8, LAGW_WEAK ); + E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); + E_LPC_a_lsp_conversion( A, lsptmp, &lspnew_uw_fx[0], M ); + Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 0 ); + + IF( st->hTdCngDec != NULL ) + { + cng_params_upd_ivas_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); + } + } + ELSE IF( st->hTdCngDec != NULL ) + { + cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); + } + /* Set 16k LSP flag for CNG buffer */ + st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); + } + + st->last_is_cng = 0; + + /* Postfiltering */ + post_decoder( st, synth_buf_fx, pit_gain_fx, pitch, signal_out_fx, st->p_bpf_noise_buf ); + + IF( signal_outFB_fx ) + { + Copy( synthFB_fx, signal_outFB_fx, hTcxDec->L_frameTCX ); + } + + IF( !bfi ) + { + IF( st->enablePlcWaveadjust ) + { + st->hPlcInfo->nbLostCmpt = 0; + } + + IF( NE_16( param[1 + NOISE_FILL_RANGES], 0 ) ) + { + Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ + tcxltp_pitch_tmp = L_shr( tcxltp_pitch_tmp, 10 ); // Q6 + set32_fx( pitch_buf_fx, tcxltp_pitch_tmp, NB_SUBFR16k ); + } + ELSE + { + set32_fx( pitch_buf_fx, L_shl( L_SUBFR, 6 ), NB_SUBFR16k ); + } + } + + IF( bfi ) + { + /*"LPD dec - All BFI"*/ + bitsRead = 0; /*to avoid empty counting */ + } + + /* updates */ + st->last_voice_factor_fx = 0; + st->last_coder_type = st->coder_type; + + /* -------------------------------------------------------------- * + * In FFT domain: perform noise estimation during active frames + * -------------------------------------------------------------- */ + + IF( st->hFdCngDec != NULL && ( EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) && LE_32( st->total_brate, MAX_ACELP_BRATE ) ) + { + noisy_speech_detection( st->hFdCngDec, st->VAD && EQ_16( st->m_frame_type, ACTIVE_FRAME ), signal_out_fx, 0 ); + + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), + st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01 ); + st->lp_noise = st->hFdCngDec->lp_noise; + // To be removed + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; + + IF( NE_16( st->element_mode, IVAS_CPE_TD ) ) + { + IF( EQ_32( ivas_format, ISM_FORMAT ) ) + { + Word16 buffer[L_FRAME16k]; + lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); + ApplyFdCng_fx( buffer, 0 /* Q of buffer */, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + } + ELSE + { + ApplyFdCng_fx( signal_out_fx, 0, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + } + } + + /* Generate additional comfort noise to mask potential coding artefacts */ + IF( EQ_16( st->m_frame_type, ACTIVE_FRAME ) && st->flag_cna && !st->cna_dirac_flag ) + { + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( nchan_out, 2 ) ) + { + IF( NE_16( st->element_mode, last_element_mode ) ) + { + /* Clear memory for secondary channel CNA */ + set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2 ); + } + expand_range( st->hFdCngDec->msPsd, psd_part_fx, &psd_part_e, st->hFdCngDec->nFFTpart_shaping ); + scalebands_fx( psd_part_fx, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand, psd_fx, 1 ); + // generate_stereo_masking_noise_fx( signal_out, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); + generate_stereo_masking_noise_16fx( signal_out_fx, 0, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); + } + ELSE IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) + { + // generate_masking_noise_flt( signal_out, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); + generate_masking_noise( signal_out_fx, 0, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0 ); + } + } + + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 0 ) ) + { + ApplyFdCng_fx( signal_out_fx, 0, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + } + } + + pop_wmops(); + return; +} +#else +/*-------------------------------------------------------------------* + * stereo_tcx_core_dec() + * + * stereo TCX decoder + *-------------------------------------------------------------------*/ + +void stereo_tcx_core_dec( + Decoder_State *st, /* i/o: decoder state structure */ + const FRAME_MODE frameMode, /* i : Decoder frame mode */ + float *signal_out, /* o : synthesis @internal_Fs */ + float *signal_outFB, /* o : synthesis @output_Fs */ + float pitch_buf[], /* o : floating pitch for each subframe */ + const int16_t sba_dirac_stereo_flag, /* i : signal stereo output for SBA DirAC */ + STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i/o: TD stereo decoder handle */ + const int16_t last_element_mode, /* i : last element mode */ + const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */ + const int16_t nchan_out, /* i : number of output channels */ + const IVAS_FORMAT ivas_format /* i : IVAS format */ +) +{ + int16_t i, k; + + /*Bitstream*/ + int16_t total_nbbits, bitsRead; + int16_t *prm, param[DEC_NPRM_DIV * NB_DIV]; + int16_t param_lpc[NPRM_LPC_NEW]; + + /*LPC*/ + int16_t LSF_Q_prediction; /* o : LSF prediction mode */ + float lsf[( NB_DIV + 1 ) * M], lsp[( NB_DIV + 1 ) * M], lspmid[M], lsfmid[M]; + float lspnew_uw[NB_DIV * M], lsfnew_uw[NB_DIV * M]; + float Aq[( NB_SUBFR16k + 1 ) * ( M + 1 )]; + float pit_gain[NB_SUBFR16k]; + int16_t pitch[NB_SUBFR16k]; + Word16 Aind[M + 1], lspind[M]; + + /*Synth*/ + float synth_buf[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; + float *synth; + float synth_bufFB[OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M]; + float *synthFB; + + /*Concealment*/ + int16_t bfi; + + float psd[L_FRAME16k], psd_part[NPART_SHAPING]; + + TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec = st->hTcxDec; + + push_wmops( "stereo_tcx_core_dec" ); + + /*Sanity check*/ + assert( !( st->total_brate == FRAME_NO_DATA || st->total_brate == SID_2k40 ) ); /*Active frame*/ + assert( st->rf_flag == 0 ); + assert( st->prev_use_partial_copy == 0 ); /* No channel aware mode */ + assert( st->codec_mode == MODE1 ); /* must be in Mode 1 */ + assert( st->mdct_sw == MODE1 ); /* must be switched to TCX in MODE1 */ + + bfi = 0; + + /*--------------------------------------------------------------------------------* + * Initialization or re-configuration of Stereo TCX + *--------------------------------------------------------------------------------*/ + + stereo_tcx_init_dec( st, 0, last_element_mode ); + + /*--------------------------------------------------------------------------------* + * Initializations + *--------------------------------------------------------------------------------*/ + + total_nbbits = (int16_t) ( st->total_brate / FRAMES_PER_SEC ); + bitsRead = 0; + LSF_Q_prediction = -1; /* to avoid compilation warnings */ + + if ( frameMode == FRAMEMODE_NORMAL ) + { + st->m_decodeMode = DEC_NO_FRAM_LOSS; + bfi = 0; + } + + if ( frameMode == FRAMEMODE_MISSING ) + { + st->m_decodeMode = DEC_CONCEALMENT_EXT; + bfi = 1; + } + + /* for bass postfilter */ + if ( st->tcxonly ) + { + st->p_bpf_noise_buf_float = NULL; + } + else + { + st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; + set_s( pitch, L_SUBFR, st->nb_subfr ); + set_zero( pit_gain, st->nb_subfr ); + } + + /* Initialize pointers */ + synth = synth_buf + hTcxDec->old_synth_len; + synthFB = synth_bufFB + hTcxDec->old_synth_lenFB; + mvr2r( hTcxDec->old_synth_float, synth_buf, hTcxDec->old_synth_len ); + mvr2r( hTcxDec->old_synthFB, synth_bufFB, hTcxDec->old_synth_lenFB ); + set_zero( synth, L_FRAME_PLUS + M ); + set_zero( synthFB, L_FRAME_PLUS + M ); + + /*--------------------------------------------------------------------------------* + * BITSTREAM DECODING + *--------------------------------------------------------------------------------*/ + + if ( !bfi ) + { + st->second_last_core = st->last_core; + + dec_prm_tcx( st, param, param_lpc, &total_nbbits, last_element_mode, &bitsRead ); + } + else + { + if ( st->nbLostCmpt > 1 ) + { + st->flagGuidedAcelp = 0; + } + + /* PLC: [Common: mode decision] + * PLC: Decide which Concealment to use. Update pitch lags if needed */ + st->core = GetPLCModeDecision_flt( st ); + } + + /*--------------------------------------------------------------------------------* + * LPC PARAMETERS + *--------------------------------------------------------------------------------*/ + + st->acelp_cfg.midLpc = 0; + + if ( !bfi ) + { + if ( hTcxDec->enableTcxLpc ) + { int16_t tcx_lpc_cdk; if ( bfi && st->use_partial_copy && st->rf_frame_type == RF_TCXFD ) { @@ -1157,445 +1243,86 @@ void stereo_tcx_core_dec( lsp2a_stab( &lsp[M], Aq, M ); } } - if ( !bfi && hTcxDec->tcx_lpc_shaped_ari ) - { - basop_E_LPC_f_lsp_a_conversion( lspind, Aind, M ); - } - - /* TCX decoder */ - decoder_tcx_flt( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, sba_dirac_stereo_flag ); - } - - /*--------------------------------------------------------------------------------* - * TCX10 - *--------------------------------------------------------------------------------*/ - - if ( st->core == TCX_10_CORE ) - { - prm = NULL; /* just to avoid MSVC warnings */ - - for ( k = 0; k < 2; k++ ) - { - /* Set pointer to parameters */ - prm = param + ( k * DEC_NPRM_DIV ); - - /* Stability Factor */ - if ( !bfi ) - { - st->stab_fac = lsf_stab( &lsf[( k + 1 ) * M], &lsf[k * M], 0, st->L_frame ); - } - - lsp2a_stab( &lsp[( k + 1 ) * M], Aq, M ); - { - IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); - } - - /* TCX decoder */ - decoder_tcx_flt( st, prm, Aq, Aind, &synth[k * st->L_frame / 2], &synthFB[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag ); - } - } -#endif - - /*--------------------------------------------------------------------------------* - * Post-processing - *--------------------------------------------------------------------------------*/ - - if ( st->core == TCX_10_CORE || st->core == TCX_20_CORE ) - { - if ( st->enablePlcWaveadjust || /* bfi */ - ( st->last_total_brate >= HQ_48k && /* recovery */ - st->last_codec_mode == MODE2 ) ) - { - /* waveform adjustment */ - concealment_signal_tuning( st, bfi, synthFB, st->last_core_bfi ); - - if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL ) - { - lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); - - if ( !bfi && st->prev_bfi ) - { - st->hPlcInfo->Pitch = 0; - } - } - } - -#ifdef IVAS_FLOAT_FIXED_ - floatToFixed_arr( st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, 0, st->hTonalMDCTConc->nSamples / 2 ); - floatToFixed_arr( st->hTonalMDCTConc->lastPcmOut_float, st->hTonalMDCTConc->lastPcmOut, 0, st->hTonalMDCTConc->nSamples ); - floatToFixed_arr( synthFB, synthFB_fx, 4, hTcxDec->L_frameTCX ); - - if ( !bfi && st->hTonalMDCTConc != NULL ) - { - TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, hTcxDec->L_frameTCX ); - } - - fixedToFloat_arr( st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 4, st->hTonalMDCTConc->nSamples / 2 ); - fixedToFloat_arr( st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 4, st->hTonalMDCTConc->nSamples ); -#else - if ( !bfi && st->hTonalMDCTConc != NULL ) - { - TonalMDCTConceal_SaveTimeSignal_ivas( st->hTonalMDCTConc, synthFB, hTcxDec->L_frameTCX ); - } -#endif // IVAS_FLOAT_FIXED -#ifdef IVAS_FLOAT_FIXED - Word16 q_Aq_2; - float max = (float) fabs( Aq[0] ); - for ( int p = 1; p < M + 1; p++ ) - { - if ( max < fabs( Aq[p] ) ) - max = (float) ( fabs( Aq[p] ) ); - } - q_Aq = norm_s( (Word16) max ); - floatToFixed_arr( Aq, Aq_fx, q_Aq, M + 1 ); - - st->hTcxDec->gainHelper = (Word16) floatToFixed( st->hTcxDec->gainHelper_float, Q14 ); - st->hTcxDec->gainHelper_e = 1; - st->hTcxDec->stepCompensate = (Word16) floatToFixed( st->hTcxDec->stepCompensate_float, Q14 ); - st->hTcxDec->stepCompensate_e = 1; - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); - st->hTcxDec->damping = (Word16) floatToFixed( st->hTcxDec->damping_float, Q14 ); - st->bfi_pitch_fx = (Word16) floatToFixed( st->bfi_pitch, Q5 ); - st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); - if ( st->hPlcInfo ) - { - st->hPlcInfo->step_concealgain_fx = (Word16) floatToFixed( st->hPlcInfo->step_concealgain, Q15 ); - } - st->hTcxDec->conceal_eof_gain = (Word16) floatToFixed( st->hTcxDec->conceal_eof_gain_float, Q14 ); - st->hTcxDec->conCngLevelBackgroundTrace = (Word16) floatToFixed( st->hTcxDec->CngLevelBackgroundTrace_bfi, Q15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); - st->hTcxDec->conLastFrameLevel = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 - st->hTcxDec->conLastFrameLevel_e ); - if ( st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) - { - set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); - } - floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - floatToFixed_arr( st->mem_pitch_gain_float, st->mem_pitch_gain, Q15, 2 * NB_SUBFR16k + 2 ); - floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); - floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M ); - floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM ); - floatToFixed_arr( st->syn_float, st->syn, 0, M + 1 ); - floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); - floatToFixed_arr( synth, synth_fx, 0, st->L_frame ); - floatToFixed_arr( synthFB, synthFB_fx, 0, st->hTcxDec->L_frameTCX ); - - floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); - floatToFixed_arr( lspnew_uw, lspnew_uw_fx, Q15, M ); - - /*=========================================*/ - decoder_tcx_post( st, synth_fx, synthFB_fx, Aq_fx, bfi ); - - IF( EQ_16( st->core, TCX_20_CORE ) ) - { - /* LPC Interpolation for BWE/post-processing */ - IF( st->narrowBand || EQ_32( st->sr_core, INT_FS_12k8 ) || EQ_32( st->sr_core, INT_FS_16k ) ) - { - int_lsp_fx( st->L_frame, st->lspold_uw, lspnew_uw_fx, Aq_fx, M, interpol_frac_fx, 0 ); - Copy( Aq_fx, st->mem_Aq, st->nb_subfr * ( M + 1 ) ); - } - } - /*=================================*/ - for ( int p = 0; p < st->nb_subfr; p++ ) - { - q_Aq_2 = 15 - ( norm_s( Aq_fx[p * ( M + 1 )] - 1 ) ); - fixedToFloat_arr( Aq_fx + p * ( M + 1 ), Aq + p * ( M + 1 ), q_Aq_2, ( M + 1 ) ); - fixedToFloat_arr( st->mem_Aq + p * ( M + 1 ), st->mem_Aq_float + p * ( M + 1 ), q_Aq_2, ( M + 1 ) ); - } - fixedToFloat_arr( synth_fx, synth, 0, st->L_frame ); - fixedToFloat_arr( synthFB_fx, synthFB, 0, st->hTcxDec->L_frameTCX ); - fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, st->Q_syn, M ); - fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, st->Q_syn, L_SYN_MEM ); - fixedToFloat_arr( st->syn, st->syn_float, 0, M + 1 ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC ); - hTcxDec->tcxltp_last_gain_unmodified_float = fixedToFloat( hTcxDec->tcxltp_last_gain_unmodified, Q15 ); - st->hTcxLtpDec->tcxltp_gain_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain, Q15 ); - st->hTcxDec->conceal_eof_gain_float = fixedToFloat( st->hTcxDec->conceal_eof_gain, Q14 ); - if ( st->hPlcInfo ) - { - st->hPlcInfo->recovery_gain_float = fixedToFloat( st->hPlcInfo->recovery_gain, Q14 ); - st->hPlcInfo->step_concealgain = fixedToFloat( st->hPlcInfo->step_concealgain_fx, Q15 ); - } - st->bfi_pitch = fixedToFloat( st->bfi_pitch_fx, Q6 ); - st->old_fpitch_float = fix_to_float( st->old_fpitch, Q16 ); - fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, q_Aq, M + 1 ); - fixedToFloat_arr( st->mem_pitch_gain, st->mem_pitch_gain_float, Q15, 2 * NB_SUBFR16k + 2 ); - fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); - st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); - st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->conLastFrameLevel, 15 - st->hTcxDec->conLastFrameLevel_e ); - for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) - { - st->hTcxDec->NoiseLevelMemory_bfi[p] = fixedToFloat( st->hTcxDec->conNoiseLevelMemory[p], 15 - st->hTcxDec->conNoiseLevelMemory_e[p] ); - } -#else - decoder_tcx_post_flt( st, synth, synthFB, Aq, bfi, 0 ); - - if ( st->core == TCX_20_CORE ) - { - /* LPC Interpolation for BWE/post-processing */ - if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) - { - int_lsp( st->L_frame, st->lspold_uw_float, lspnew_uw, Aq, M, interpol_frac_12k8, 0 ); - mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) ); - } - } -#endif // IVAS_FLOAT_FIXED - } - - /* PLC: [Common: Classification] */ - /* the classifier buffer is always updated if the sr is at - 16000 or below - the classification itself is just performed if(!st->tcxonly ) */ -#ifdef IVAS_FLOAT_FIXED - /*=============================================*/ - double max_val = 0; - for ( int j = 0; j <= M; j++ ) - { - max_val = max( max_val, fabs( Aq[j] ) ); - } - if ( fabs( max_val ) < 1.0f ) - q_Aq = Q15; - else - q_Aq = norm_s( (Word16) max_val ); - for ( int j = 0; j <= M; j++ ) - { - Aq_fx[j] = (Word16) ( Aq[j] * pow( 2, q_Aq ) ); - } - - st->lp_ener_bfi_fx = (Word16) floatToFixed( st->lp_ener_bfi, Q8 ); - st->old_fpitch = floatToFixed( st->old_fpitch_float, Q16 ); - st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, Q15 ); - if ( hTcxLtpDec->tcxltp ) - { - hTcxDec->tcxltp_last_gain_unmodified = (Word16) floatToFixed( hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); - } - st->classifier_Q_mem_syn = Q5; - floatToFixed_arr( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM ); - st->Q_syn = 0; - floatToFixed_arr( synth, synth_fx, st->Q_syn, st->L_frame ); - - floatToFixed_arr( synth_buf + st->L_frame, synth_buf_fx + st->L_frame, 0, hTcxDec->old_synth_len ); - floatToFixed_arr( hTcxDec->old_synthFB + hTcxDec->L_frameTCX - NS2SA( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->old_synthFB_fx + hTcxDec->L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), 0, NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ); - floatToFixed_arr( synth_bufFB + hTcxDec->L_frameTCX, synth_bufFB_fx + hTcxDec->L_frameTCX, 0, hTcxDec->old_synth_lenFB ); - floatToFixed_arr( st->hHQ_core->old_out + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), 0, NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); - floatToFixed_arr( lspnew_uw, lspnew_uw_fx, Q15, NB_DIV * M ); - floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); - floatToFixed_arr( &lsp[st->numlpc * M], &lsp_fx[st->numlpc * M], Q15, M ); - floatToFixed_arr( st->lsp_q_cng_float, st->lsp_q_cng, Q15, M ); - for ( int p = 0; p < M; p++ ) - { - lsfnew_uw_fx[( st->numlpc - 1 ) * M + p] = (Word16) ( lsfnew_uw[( st->numlpc - 1 ) * M + p] * 1.28f ); - lsf_fx[st->numlpc * M + p] = (Word16) ( lsf[st->numlpc * M + p] * 1.28f ); - st->lsfold_uw[p] = (Word16) ( st->lsfold_uw_float[p] * 1.28f ); - st->lsf_q_cng[p] = (Word16) ( st->lsf_q_cng_float[p] * 1.28f ); - } - floatToFixed_arr( synth + L_FRAME - L_LP - 1, synth_fx + L_FRAME - L_LP - 1, 0, L_LP + 1 ); - floatToFixed_arr( &lsp[M], &lsp_fx[M], Q15, M ); - st->Q_exc = 1; - floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); - IF( st->hTdCngDec != NULL ) - { - floatToFixed_arr( st->hTdCngDec->ho_lsp_circ, st->hTdCngDec->ho_lsp_circ_fx, Q15, HO_HIST_SIZE * M ); - floatToFixed_arrL( st->hTdCngDec->ho_env_circ, st->hTdCngDec->ho_env_circ_fx, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); - floatToFixed_arrL( st->hTdCngDec->ho_ener_circ, st->hTdCngDec->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); - } - - Word16 signal_out_buf_fx[L_FRAME48k], signal_outFB_fx[L_FRAME48k]; - Word32 pitch_buf_fx[NB_SUBFR16k]; - Word16 *signal_out_fx = signal_out_buf_fx; - floatToFixed_arr( synth_buf, synth_buf_fx, 0, OLD_SYNTH_SIZE_DEC + L_FRAME_PLUS + M ); - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1 ); - floatToFixed_arr( st->mem_Aq_float, st->mem_Aq, Q12, ( NB_SUBFR16k ) * ( M + 1 ) ); - if ( !st->tcxonly ) - { - floatToFixed_arr( st->p_bpf_noise_buf_float, st->p_bpf_noise_buf, 0, L_FRAME_16k ); - } - floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); - floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, 0, L_SUBFR ); - floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, 0, L_SUBFR ); - st->lp_noise = floatToFixed( st->lp_noise_float, Q16 ); - st->lp_error_ener = floatToFixed( st->hBPF->pst_lp_ener, Q16 ); - st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); - st->hPFstat->gain_prec = (Word16) floatToFixed( st->hPFstat->gain_prec_flt, Q14 ); - - /*=============================================*/ - IF( LE_32( st->sr_core, INT_FS_16k ) ) - { - IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || ( st->tcxonly && st->bfi ) ) - { - Word16 pitch_C[4]; - - /* note: the classifier needs the pitch only for tcx_only == 0, i.e. not for TCX10 */ - set16_fx( pitch_C, shl( round_fx( st->old_fpitch ), Q6 ), 4 ); - - /* note: codec_mode is forced to MODE2, since FEC_clas_estim() considers only TCX being in Mode2*/ - Word16 prev_codec_mode = st->codec_mode; - st->codec_mode = MODE2; - FEC_clas_estim_fx( st, 0, st->L_frame, &st->clas_dec, st->tcxonly ? GENERIC : st->core_ext_mode, pitch_C, synth_fx, &st->lp_ener_bfi_fx, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 /*st->core_brate*/, st->Q_syn, NULL, st->mem_syn_clas_estim_fx, &st->classifier_Q_mem_syn, hTcxLtpDec->tcxltp ? hTcxDec->tcxltp_last_gain_unmodified : MIN_16, CLASSIFIER_TCX, bfi, st->last_core_brate, -1 ); - st->codec_mode = prev_codec_mode; - } - } - - - /*--------------------------------------------------------------------------------* - * Updates - *--------------------------------------------------------------------------------*/ - - IF( bfi && NE_16( st->last_core, ACELP_CORE ) ) - { - /* Update FEC_scale_syn parameters */ - IF( hTcxLtpDec->tcxltp_gain_float == 0 ) - { - frame_ener_fx( st->L_frame, UNVOICED, synth_fx, shr( st->L_frame, 1 ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); - } - ELSE - { - frame_ener_fx( st->L_frame, st->clas_dec, synth_fx, extract_l( L_shr( st->old_fpitch, 16 ) ), &st->enr_old_fx, st->L_frame, 0, 0, 0 ); - } - } - - IF( !bfi && GE_16( st->clas_dec, VOICED_TRANSITION ) && LT_16( st->clas_dec, INACTIVE_CLAS ) ) - { - /* use latest LPC set */ - st->old_enr_LP = Enr_1_Az_fx( Aq_fx, L_SUBFR ); // Q3 - } - - /* Update past buffers */ - Copy( synth_buf_fx + st->L_frame, hTcxDec->old_synth, hTcxDec->old_synth_len ); - Copy( hTcxDec->old_synthFB_fx + hTcxDec->L_frameTCX - NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ), hTcxDec->synth_history_fx, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); - Copy( synth_bufFB_fx + hTcxDec->L_frameTCX, hTcxDec->old_synthFB_fx, hTcxDec->old_synth_lenFB ); - Copy( st->hHQ_core->old_out_fx + NS2SA_fx2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->old_synthFB_fx + hTcxDec->old_synth_lenFB, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ); - - Copy( &lspnew_uw_fx[( st->numlpc - 1 ) * M], st->lspold_uw, M ); - Copy( &lsfnew_uw_fx[( st->numlpc - 1 ) * M], st->lsfold_uw, M ); - - IF( EQ_16( bfi, 1 ) ) - { - Copy( st->lspold_uw, st->lsp_old_fx, M ); /* for recovery */ - Copy( st->lsfold_uw, st->lsf_old_fx, M ); /* for recovery */ - } - ELSE - { - Copy( &lsp_fx[st->numlpc * M], st->lsp_old_fx, M ); - Copy( &lsf_fx[st->numlpc * M], st->lsf_old_fx, M ); - } - Copy( st->lsp_q_cng, st->old_lsp_q_cng, M ); - Copy( st->lsf_q_cng, st->old_lsf_q_cng, M ); - - /* Update CNG parameters */ - IF( !st->tcxonly && st->hTdCngDec != NULL ) - { - /* update CNG parameters in active frames */ - IF( EQ_16( st->bwidth, NB ) && hTcxDec->enableTcxLpc && NE_16( st->core, ACELP_CORE ) ) - { - Word16 buf[L_LP], res[L_FRAME], A[M + 1], r_h[M + 1], r_l[M + 1], tmp, lsptmp[M], q_r; - assert( st->L_frame == L_FRAME ); - - Copy( synth_fx + L_FRAME - L_LP, buf, L_LP ); - tmp = synth_fx[L_FRAME - L_LP - 1]; - E_UTIL_f_preemph2( 0, buf, st->preemph_fac, L_LP, &tmp ); - autocorr_fx( buf, M, r_h, r_l, &q_r, L_LP, Assym_window_W16fx, 0, 0 ); - lag_wind( r_h, r_l, M, INT_FS_12k8, LAGW_WEAK ); - E_LPC_lev_dur( r_h, r_l, A, NULL, M, NULL ); - E_LPC_a_lsp_conversion( A, lsptmp, &lspnew_uw_fx[0], M ); - Residu3_fx( A, buf + L_LP - L_FRAME, res, L_FRAME, 0 ); - - IF( st->hTdCngDec != NULL ) - { - cng_params_upd_ivas_fx( lsptmp, res, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); - } - } - ELSE IF( st->hTdCngDec != NULL ) + if ( !bfi && hTcxDec->tcx_lpc_shaped_ari ) { - cng_params_upd_ivas_fx( &lsp_fx[M], st->old_exc_fx + L_EXC_MEM_DEC - st->L_frame, st->L_frame, &st->hTdCngDec->ho_circ_ptr, st->hTdCngDec->ho_ener_circ_fx, &st->hTdCngDec->ho_circ_size, st->hTdCngDec->ho_lsp_circ_fx, st->Q_exc, DEC, st->hTdCngDec->ho_env_circ_fx, NULL, NULL, NULL, NULL, st->last_active_brate, st->element_mode, st->hFdCngDec->hFdCngCom->CngBandwidth ); + basop_E_LPC_f_lsp_a_conversion( lspind, Aind, M ); } - /* Set 16k LSP flag for CNG buffer */ - st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = ( st->L_frame == L_FRAME ? 0 : 1 ); - } - st->last_is_cng = 0; + /* TCX decoder */ + decoder_tcx_flt( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, sba_dirac_stereo_flag ); + } - /* Postfiltering */ - post_decoder( st, synth_buf_fx, pit_gain_fx, pitch, signal_out_fx, st->p_bpf_noise_buf ); + /*--------------------------------------------------------------------------------* + * TCX10 + *--------------------------------------------------------------------------------*/ - IF( signal_outFB ) + if ( st->core == TCX_10_CORE ) { - Copy( synthFB_fx, signal_outFB_fx, hTcxDec->L_frameTCX ); - } + prm = NULL; /* just to avoid MSVC warnings */ - IF( !bfi ) - { - IF( st->enablePlcWaveadjust ) + for ( k = 0; k < 2; k++ ) { - st->hPlcInfo->nbLostCmpt = 0; - } + /* Set pointer to parameters */ + prm = param + ( k * DEC_NPRM_DIV ); - IF( NE_16( param[1 + NOISE_FILL_RANGES], 0 ) ) - { - Word32 tcxltp_pitch_tmp = L_add( L_deposit_h( hTcxLtpDec->tcxltp_pitch_int ), L_shl( L_deposit_l( div_s( hTcxLtpDec->tcxltp_pitch_fr, st->pit_res_max ) ), 1 ) ); /*15Q16*/ - tcxltp_pitch_tmp = L_shr( tcxltp_pitch_tmp, 10 ); // Q6 - set32_fx( pitch_buf_fx, tcxltp_pitch_tmp, NB_SUBFR16k ); - } - ELSE - { - set32_fx( pitch_buf_fx, L_shl( L_SUBFR, 6 ), NB_SUBFR16k ); - } - } + /* Stability Factor */ + if ( !bfi ) + { + st->stab_fac = lsf_stab( &lsf[( k + 1 ) * M], &lsf[k * M], 0, st->L_frame ); + } - IF( bfi ) - { - /*"LPD dec - All BFI"*/ - bitsRead = 0; /*to avoid empty counting */ + lsp2a_stab( &lsp[( k + 1 ) * M], Aq, M ); + { + IGFDecRestoreTCX10SubFrameData_flt( st->hIGFDec, k ); + } + + /* TCX decoder */ + decoder_tcx_flt( st, prm, Aq, Aind, &synth[k * st->L_frame / 2], &synthFB[k * hTcxDec->L_frameTCX / 2], bfi, k, sba_dirac_stereo_flag ); + } } - /* updates */ - st->last_voice_factor_fx = 0; - st->last_coder_type = st->coder_type; - /*====================================*/ + /*--------------------------------------------------------------------------------* + * Post-processing + *--------------------------------------------------------------------------------*/ + if ( st->core == TCX_10_CORE || st->core == TCX_20_CORE ) + { + if ( st->enablePlcWaveadjust || /* bfi */ + ( st->last_total_brate >= HQ_48k && /* recovery */ + st->last_codec_mode == MODE2 ) ) + { + /* waveform adjustment */ + concealment_signal_tuning( st, bfi, synthFB, st->last_core_bfi ); - fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM ); - st->lp_ener_bfi = fixedToFloat( st->lp_ener_bfi_fx, Q8 ); + if ( ( bfi || st->prev_bfi ) && st->hPlcInfo->Pitch && st->hPlcInfo->concealment_method == TCX_NONTONAL ) + { + lerp_flt( synthFB, synth, st->L_frame, hTcxDec->L_frameTCX ); - st->enr_old = (float) st->enr_old_fx; + if ( !bfi && st->prev_bfi ) + { + st->hPlcInfo->Pitch = 0; + } + } + } - st->old_enr_LP_float = (float) ( st->old_enr_LP / pow( 2, Q3 ) ); + if ( !bfi && st->hTonalMDCTConc != NULL ) + { + TonalMDCTConceal_SaveTimeSignal_ivas( st->hTonalMDCTConc, synthFB, hTcxDec->L_frameTCX ); + } - fixedToFloat_arr( hTcxDec->old_synth, hTcxDec->old_synth_float, 0, hTcxDec->old_synth_len ); - fixedToFloat_arr( hTcxDec->synth_history_fx, hTcxDec->synth_history, 0, NS2SA_fx2( st->output_Fs, PH_ECU_MEM_NS ) ); - fixedToFloat_arr( hTcxDec->old_synthFB_fx, hTcxDec->old_synthFB, 0, NS2SA_fx2( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) + hTcxDec->old_synth_lenFB ); - fixedToFloat_arr( st->old_lsp_q_cng, st->old_lsp_q_cng_float, Q15, M ); - fixedToFloat_arr( st->lsp_old_fx, st->lsp_old, Q15, M ); - fixedToFloat_arr( st->lspold_uw, st->lspold_uw_float, Q15, M ); - for ( int p = 0; p < M; p++ ) - { - st->lsf_old[p] = (float) st->lsf_old_fx[p] / 1.28f; - st->lsfold_uw_float[p] = (float) st->lsfold_uw[p] / 1.28f; - st->old_lsf_q_cng_float[p] = (float) st->old_lsf_q_cng[p] / 1.28f; - } + decoder_tcx_post_flt( st, synth, synthFB, Aq, bfi, 0 ); - IF( !st->tcxonly && st->hTdCngDec != NULL ) - { - fixedToFloat_arr( st->hTdCngDec->ho_lsp_circ_fx, st->hTdCngDec->ho_lsp_circ, Q15, HO_HIST_SIZE * M ); - fixedToFloat_arrL( st->hTdCngDec->ho_env_circ_fx, st->hTdCngDec->ho_env_circ, Q6, HO_HIST_SIZE * NUM_ENV_CNG ); - fixedToFloat_arrL( st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, Q6, HO_HIST_SIZE ); + if ( st->core == TCX_20_CORE ) + { + /* LPC Interpolation for BWE/post-processing */ + if ( st->narrowBand || st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) + { + int_lsp( st->L_frame, st->lspold_uw_float, lspnew_uw, Aq, M, interpol_frac_12k8, 0 ); + mvr2r( Aq, st->mem_Aq_float, st->nb_subfr * ( M + 1 ) ); + } + } } - st->last_voice_factor = st->last_voice_factor_fx; - fixedToFloat_arr( signal_out_fx, signal_out, 0, st->L_frame ); - fixedToFloat_arr( signal_outFB_fx, signal_outFB, 0, hTcxDec->L_frameTCX ); - fixedToFloat_arrL( pitch_buf_fx, pitch_buf, Q6, NB_SUBFR16k ); - if ( !st->tcxonly ) - { - fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); - } - fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); - fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, 0, L_SUBFR ); - fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, 0, L_SUBFR ); - st->hBPF->pst_lp_ener = fixedToFloat( st->lp_error_ener, Q16 ); - st->hBPF->pst_mem_deemp_err = fixedToFloat( st->mem_error, Q16 ); - st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); -#else if ( st->sr_core <= INT_FS_16k ) { if ( st->core == TCX_20_CORE || st->core == TCX_10_CORE || ( st->tcxonly && st->bfi ) ) @@ -1688,7 +1415,7 @@ void stereo_tcx_core_dec( st->last_is_cng = 0; /* Postfiltering */ - post_decoder_flt( st, synth_buf, pit_gain, pitch, signal_out, st->p_bpf_noise_buf_float); + post_decoder_flt( st, synth_buf, pit_gain, pitch, signal_out, st->p_bpf_noise_buf_float ); if ( signal_outFB ) { @@ -1721,7 +1448,6 @@ void stereo_tcx_core_dec( /* updates */ st->last_voice_factor = 0.0f; st->last_coder_type = st->coder_type; -#endif // IVAS_FLOAT_FIXED /* -------------------------------------------------------------- * * In FFT domain: perform noise estimation during active frames @@ -1729,206 +1455,12 @@ void stereo_tcx_core_dec( if ( st->hFdCngDec != NULL && ( st->sr_core == INT_FS_12k8 || st->sr_core == INT_FS_16k ) && st->total_brate <= MAX_ACELP_BRATE ) { -#ifdef IVAS_FLOAT_FIXED - st->hFdCngDec->lp_noise = floatToFixed( st->hFdCngDec->lp_noise_float, Q23 ); - st->hFdCngDec->lp_speech = floatToFixed( st->hFdCngDec->lp_speech_float, Q23 ); - - noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, signal_out_fx, 0 ); - - st->hFdCngDec->lp_noise_float = fixedToFloat( st->hFdCngDec->lp_noise, Q23 ); - st->hFdCngDec->lp_speech_float = fixedToFloat( st->hFdCngDec->lp_speech, Q23 ); -#else noisy_speech_detection_flt( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, signal_out ); -#endif // IVAS_FLOAT_FIXED st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; -#ifdef IVAS_FLOAT_FIXED - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), - st->hFdCngDec->hFdCngCom->flag_noisy_speech * Q31_0_01 ); -#endif - st->lp_noise_float = st->hFdCngDec->lp_noise_float; - -#ifdef IVAS_FLOAT_FIXED - Word16 /*signal_out_fx[L_FRAME48k], signal_outFB_fx[L_FRAME48k],*/ q_buf = 1; - - if ( ivas_format == ISM_FORMAT ) - { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - signal_outFB_fx[p] = (Word16) ( signal_outFB[p] * ( 1u << q_buf ) ); - } - } - else - { - for ( int p = 0; p < L_FRAME48k; p++ ) - { - signal_out_fx[p] = (Word16) ( signal_out[p] * ( 1u << q_buf ) ); - } - } - for ( int p = 0; p < st->L_frame; p++ ) - { - st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - st->hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } - } + st->lp_noise_float = st->hFdCngDec->lp_noise_float; - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - for ( int p = 0; p < FFTCLDFBLEN; p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; - st->hFdCngDec->partNoiseShape_exp = 31 - Q4; - for ( int p = 0; p < NPART; p++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); - } - for ( int p = 0; p < 24; p++ ) - { - st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); - } - /*=================================*/ - if ( st->element_mode != IVAS_CPE_TD ) - { - IF( EQ_32( ivas_format, ISM_FORMAT ) ) - { - Word16 buffer[L_FRAME16k]; - lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); - ApplyFdCng_fx( buffer, q_buf /* Q of buffer */, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); - } - ELSE - { - ApplyFdCng_fx( signal_out_fx, q_buf, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); - } - } - /*=================================*/ - if ( ( ( st->m_frame_type == ACTIVE_FRAME ) && ( ( st->bfi == 0 && - ( signal_out == NULL || - ( *signal_out( -FLT_MAX ) && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && - ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && - !( st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode ) ) || - ( st->element_mode == IVAS_CPE_TD ) ) && - ( !st->BER_detect ) ) || - ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && ( st->hFdCngDec->hFdCngCom->active_frame_counter > 0 ) ) || ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) ) ) || - ( st->m_frame_type == ZERO_FRAME ) ) - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); - st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) - { - st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); - st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); - st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) - { - for ( int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++ ) - { - st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - } - } - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) - { - for ( int p = 0; p < MSNUMSUBFR * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 - } - if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); - } - if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); - } - } - } - if ( sum_f( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) > 0.01f ) - { - if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) - { - int A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ); - for ( int p = 0; p < M; p++ ) - { - st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); - st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); - } - } - } - } -#else if ( st->element_mode != IVAS_CPE_TD ) { if ( ivas_format == ISM_FORMAT ) @@ -1942,9 +1474,7 @@ void stereo_tcx_core_dec( ApplyFdCng_flt( signal_out, NULL, NULL, NULL, st, st->bfi, 0 ); } } -#endif // IVAS_FLOAT_FIXED -#ifndef IVAS_FLOAT_FIXED /* Generate additional comfort noise to mask potential coding artefacts */ if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna && !st->cna_dirac_flag ) { @@ -1959,199 +1489,24 @@ void stereo_tcx_core_dec( scalebands_flt( psd_part, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand, psd, 1 ); generate_stereo_masking_noise( signal_out, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); } -#else - /* Generate additional comfort noise to mask potential coding artefacts */ - if ( st->m_frame_type == ACTIVE_FRAME && st->flag_cna && !st->cna_dirac_flag ) - { - if ( st->element_mode == IVAS_CPE_TD && nchan_out == 2 ) - { - if ( st->element_mode != last_element_mode ) - { - /* Clear memory for secondary channel CNA */ - set16_fx( hStereoCng->olapBufferSynth22_fx, 0, st->hFdCngDec->hFdCngCom->frameSize / 2 ); - // to be removed - set_f( hStereoCng->olapBufferSynth22, 0.0f, st->hFdCngDec->hFdCngCom->frameSize / 2 ); - } - expand_range( st->hFdCngDec->msPsd, psd_part_fx, &psd_part_e, st->hFdCngDec->nFFTpart_shaping ); - scalebands_fx( psd_part_fx, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->midband_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand, psd_fx, 1 ); - generate_stereo_masking_noise_fx( signal_out, st, hStereoTD, flag_sec_CNA, 0, hStereoCng, nchan_out ); - } -#endif else if ( st->element_mode != IVAS_CPE_DFT ) { generate_masking_noise_flt( signal_out, st->hFdCngDec->hFdCngCom, st->hFdCngDec->hFdCngCom->frameSize, 0, 0, 0, st->element_mode, hStereoCng, nchan_out ); } } - -#ifdef IVAS_FLOAT_FIXED - q_buf = 1; - - for ( int p = 0; p < L_FRAME48k; p++ ) - { - signal_out_fx[p] = (Word16) ( signal_out[p] * ( 1u << q_buf ) ); - } - for ( int p = 0; p < st->L_frame; p++ ) - { - st->hFdCngDec->hFdCngCom->periodog[p] = (Word32) ( st->hFdCngDec->hFdCngCom->periodog_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - st->hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - st->hFdCngDec->msPeriodog[p] = (Word32) ( st->hFdCngDec->msPeriodog_float[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } - } - - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 - for ( int p = 0; p < FFTCLDFBLEN; p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; - st->hFdCngDec->partNoiseShape_exp = 31 - Q4; - for ( int p = 0; p < 24; p++ ) - { - st->hFdCngDec->hFdCngCom->sidNoiseEst[p] = (Word32) ( st->hFdCngDec->hFdCngCom->sidNoiseEst_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->sidNoiseEstExp ) ) ); - st->hFdCngDec->partNoiseShape[p] = (Word32) ( st->hFdCngDec->partNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->partNoiseShape_exp ) ) ); - } - if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 ) - { - ApplyFdCng_fx( signal_out_fx, q_buf, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); - } - if (st->element_mode == IVAS_CPE_TD && st->idchan == 0) - { - if ( ( ( st->m_frame_type == ACTIVE_FRAME ) && ( ( st->bfi == 0 && - ( signal_out == NULL || - ( *signal_out( -FLT_MAX ) && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) < FLT_MAX && - *( signal_out + st->hFdCngDec->hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) && - ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && st->hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) && - !( st->cng_type == LP_CNG && st->hFdCngDec->flag_dtx_mode ) ) || - ( st->element_mode == IVAS_CPE_TD ) ) && - ( !st->BER_detect ) ) || - ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && ( st->hFdCngDec->hFdCngCom->active_frame_counter > 0 ) ) || ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) ) ) || - ( st->m_frame_type == ZERO_FRAME ) ) - { - st->hTcxDec->CngLevelBackgroundTrace_bfi = fix_to_float( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx, ( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ); - st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand; p++ ) - { - st->hFdCngDec->hFdCngCom->periodog_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->periodog[p] / (float) ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->periodog_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPsd_exp_fft ) ) ); - st->hFdCngDec->msNoiseEst_float[p] = (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ); - st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) - { - for ( int p = 0; p < L_FRAME16k - st->hFdCngDec->hFdCngCom->startBand; p++ ) - { - st->hFdCngDec->smoothed_psd[st->hFdCngDec->hFdCngCom->startBand + p] = ( (float) st->hFdCngDec->smoothed_psd_fx[st->hFdCngDec->hFdCngCom->startBand + p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - } - } - IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) ) - { - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 - } - if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); - } - if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); - } - } - } - int A_cng_q = 14; - for ( int p = 0; p < M; p++ ) - { - st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q) ); - st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); - } - } - } -#else if ( st->element_mode == IVAS_CPE_TD && st->idchan == 0 ) { ApplyFdCng_flt( signal_out, NULL, NULL, NULL, st, st->bfi, 0 ); } -#endif // IVAS_FLOAT_FIXED } -#ifdef IVAS_FLOAT_FIXED - st->scale = scale; -#endif // IVAS_FLOAT_FIXED pop_wmops(); return; } +#endif // IVAS_FLOAT_FIXED - +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * Function dec_prm_tcx() * @@ -2268,7 +1623,7 @@ static void dec_prm_tcx( return; } - +#endif // IVAS_FLOAT_FIXED /*-----------------------------------------------------------------* * Function stereo_tcx_dec_mode_switch_reconf() * diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index f60baa9e4..5043c28e2 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -317,10 +317,10 @@ typedef struct typedef struct { - UWord16 numIndexes; - UWord16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; - UWord16 lowerIndex[MAX_NUMBER_OF_IDX]; - UWord16 upperIndex[MAX_NUMBER_OF_IDX]; + Word16 numIndexes; + Word16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; + Word16 lowerIndex[MAX_NUMBER_OF_IDX]; + Word16 upperIndex[MAX_NUMBER_OF_IDX]; Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ -- GitLab