From a86fbcb48097994ac7e2e3aa0782269afdb0c37b Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 26 Mar 2024 21:30:02 +0530 Subject: [PATCH] Integration of fixed point sub-functions 8 [x] decoder_tcx_fx - clean up of intermediate float to fixed and fixed to float conversions. [x] fb_tbe_dec integration. [x] Converted 5 functions in ivas_cov_smooth.c file. [x] Added fixes for issues 711,714 and 715. --- lib_com/float_to_fix_ops.c | 525 ++++++++++++++++++++------------ lib_com/ivas_cov_smooth.c | 196 +++++++++++- lib_com/ivas_prot.h | 35 +++ lib_com/ivas_stat_com.h | 3 + lib_com/options.h | 2 + lib_com/prot_fx1.h | 7 + lib_com/prot_fx2.h | 24 +- lib_com/tools_fx.c | 49 +++ lib_dec/dec_LPD.c | 148 +++++++++ lib_dec/dec_tcx_fx.c | 294 +++--------------- lib_dec/gs_dec_fx.c | 4 + lib_dec/ivas_core_dec.c | 57 +++- lib_dec/ivas_stereo_icbwe_dec.c | 8 + lib_dec/ivas_tcx_core_dec.c | 1 - lib_dec/swb_bwe_dec_fx.c | 6 + lib_dec/swb_tbe_dec_fx.c | 77 +++++ lib_enc/ivas_enc_cov_handler.c | 160 +++++++++- 17 files changed, 1127 insertions(+), 469 deletions(-) diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index edbcce09a..bdf66d46a 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -144,6 +144,42 @@ Word16 Q_factor_arrL(float *x, Word16 l) } return Q; } + +#ifdef IVAS_FLOAT_FIXED +Word16 L_get_q( float f ) +{ + if ( fabsf( f ) > (float) INT_MAX ) + { + return sub( sub( W_norm( (Word64) f ), 32 ), 0 ); + } + else + { + return sub( norm_l( (Word32) f ), 0 ); + } +} + +Word16 L_get_q_buf( float *ptr_flt, Word16 length ) +{ + Word16 k; + float ftemp = 0.0; + + for ( k = 0; k < length; k++ ) + { + if ( fabsf( ptr_flt[k] ) > ftemp ) + ftemp = fabsf( ptr_flt[k] ); + } + + if ( ftemp > (float) INT_MAX ) + { + return sub( sub( W_norm( (Word64) ftemp ), 32 ), 0 ); + } + else + { + return sub( norm_l( (Word32) ftemp ), 0 ); + } +} +#endif + #ifdef IVAS_FLOAT_FIXED void stereo_tcx_dec_mode_switch_reconf_To_fixed( Decoder_State *st, @@ -834,10 +870,21 @@ 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 ) + Word16 last_element_mode, + const FRAME_MODE frameMode) { TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; TCX_DEC_HANDLE hTcxDec = st->hTcxDec; + Word16 i=0, bfi=0; + IF(EQ_32(frameMode, FRAMEMODE_NORMAL)) + { + bfi = 0; + } + + IF(EQ_32(frameMode, FRAMEMODE_MISSING)) + { + bfi = 1; + } 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 ) ) || @@ -850,7 +897,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( hPrivateData = &st->hIGFDec->igfData; H_IGF_INFO hIGFInfo = &hPrivateData->igfInfo; ACELP_config *pConfigAcelp = &( st->acelp_cfg ); - Word16 i = 0, + 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, @@ -1131,197 +1178,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } 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_lsfbfi) ); - } - 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 { @@ -1721,6 +1577,251 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } } } + + if ( tofix ) + { + /*==========*/ + 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_lsfbfi ) ); + } + 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 ); + } + + st->gamma = float_to_fix16( st->gamma_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->Mode2_lp_gainp = float_to_fix( st->lp_gainp, Q29 ); + // 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->inv_gamma = FL2WORD16_SCALE(1 / st->gamma_float, 1); + st->hTcxCfg->preemph_fac = FL2WORD16( st->hTcxCfg->preemph_fac_flt ); + f2me_16( st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e ); + f2me_16( st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e ); + //st->last_concealed_gain_syn_deemph = float_to_fix16( st->last_concealed_gain_syn_deemph_float, Q14 ); + //st->last_concealed_gain_syn_deemph_e = 1; + f2me_16( st->hTcxDec->old_gaintcx_bfi_float, &st->hTcxDec->old_gaintcx_bfi, &st->hTcxDec->old_gaintcx_bfi_e ); + + FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) + { + st->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( st->hTcxDec->ltpGainMemory[l], Q15 ); + } + st->hTonalMDCTConc->lastPitchLag = float_to_fix( st->hTonalMDCTConc->lastPitchLag_float, Q16 ); + // st->hTonalMDCTConc->nFramesLost = float_to_fix16(st->hTonalMDCTConc->nFramesLost_float, Q1); + /*===========*/ + IF(bfi && st->tonal_mdct_plc_active && NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + FOR(Word16 i = 0; i < FDNS_NPTS; i++) + { + f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); + st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); + } + } + + IF(st->enablePlcWaveadjust) + { + f2me_buf(st->hPlcInfo->data_reci2, st->hPlcInfo->data_reci2_fx, &st->hPlcInfo->data_reci2_scale, st->hPlcInfo->L_frameTCX); + } + + // u8bit to 16bit + FOR(int l = 0; l < IGF_START_MX; l++) + { + st->hIGFDec->infoTCXNoise_evs[l] = (Word16)st->hIGFDec->infoTCXNoise[l]; + } + + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); + + floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, st->Q_syn + 1, L_FRAME32k / 2); + floatToFixed_arr(st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, st->Q_syn, 320); + floatToFixed_arr(st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, st->Q_syn+1, 320); + floatToFixed_arr(st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, st->Q_syn, 480); + floatToFixed_arr(st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->Q_syn, 480); + } } void fixed_to_float_stereo_tcx_core_dec( @@ -2011,5 +2112,43 @@ void fixed_to_float_stereo_tcx_core_dec( } } } + + st->last_gain_syn_deemph_float = fixedToFloat(st->last_gain_syn_deemph, 15 - st->last_gain_syn_deemph_e); + st->hTcxDec->old_gaintcx_bfi_float = fixedToFloat(st->hTcxDec->old_gaintcx_bfi, 15 - st->hTcxDec->old_gaintcx_bfi_e); + st->hTcxDec->cummulative_damping_tcx_float = fix16_to_float(st->hTcxDec->cummulative_damping_tcx, Q15); + st->hTcxDec->damping_float = fix16_to_float(st->hTcxDec->damping, Q14); + st->hTcxDec->stepCompensate_float = fixedToFloat(st->hTcxDec->stepCompensate, 15 - st->hTcxDec->stepCompensate_e); + st->hTcxDec->gainHelper_float = fixedToFloat(st->hTcxDec->gainHelper, 15 - st->hTcxDec->gainHelper_e); + FOR(Word16 l = 0; l < N_LTP_GAIN_MEMS; l++) + { + st->hTcxDec->ltpGainMemory[l] = fix16_to_float(st->hTcxDec->ltpGainMemory_fx[l], Q15); + } + st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); + st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); + me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpecBuf, (N_MAX_TCX - IGF_START_MN)); + st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); + st->hTcxDec->tcxltp_second_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_second_last_pitch, 16); + st->old_fpitchFB_float = fix_to_float(st->old_fpitchFB, 16); + st->last_concealed_gain_syn_deemph_float = fix16_to_float( st->last_concealed_gain_syn_deemph, 15 - st->last_concealed_gain_syn_deemph_e ); + IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) + { + + FOR( Word16 ind = 0; ind < 640; ind++ ) + { + st->hHQ_core->old_outLB[ind] = (float) st->hHQ_core->old_out_LB_fx[ind] / ( (float) pow( 2, st->hHQ_core->Q_old_wtda ) ); + } + FOR( Word16 ind = 0; ind < 960; ind++ ) + { + st->hHQ_core->old_out[ind] = (float) st->hHQ_core->old_out_fx[ind] / ( (float) pow( 2, st->hHQ_core->Q_old_wtda ) ); + } + FOR( Word16 ind = 0; ind < L_FRAME32k / 2; ind++ ) + { + st->hTcxDec->syn_Overl_float[ind] = (float) st->hTcxDec->syn_Overl[ind] / ( (float) pow( 2, st->Q_syn + 1 ) ); + } + FOR( Word16 ind = 0; ind < L_FRAME_MAX / 2; ind++ ) + { + st->hTcxDec->syn_OverlFB_float[ind] = (float) st->hTcxDec->syn_OverlFB[ind] / ( (float) pow( 2, st->Q_syn ) ); + } + } } #endif // IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_cov_smooth.c b/lib_com/ivas_cov_smooth.c index 0c6ec7631..2f9a462e8 100644 --- a/lib_com/ivas_cov_smooth.c +++ b/lib_com/ivas_cov_smooth.c @@ -60,7 +60,7 @@ static Word32 ivas_calculate_update_factor_fx( FOR( k = 0; k < active_bins; k++ ) { - update_factor_temp += p_bin_to_band[k]; // Q22 + update_factor_temp = L_add( update_factor_temp, p_bin_to_band[k] ); // Q22 } return update_factor_temp; @@ -109,27 +109,33 @@ static void ivas_calculate_smoothning_factor_fx( Word16 tmp, exp_diff = 0; tmp = BASOP_Util_Divide3232_Scale( update_factor, L_shl( L_deposit_l( min_pool_size ), Q22 ), &exp_diff ); // (Q15 - exp_diff) - *Smoothing_factor = L_shl_sat( L_deposit_l( tmp ), add( Q13, exp_diff ) ); // Q28 + *Smoothing_factor = L_shl_sat( L_deposit_l( tmp ), add( Q16, exp_diff ) ); // Q31 + move32(); IF( NE_32( smooth_mode, COV_SMOOTH_MC ) ) { IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { smooth_fact = (Word32) ( 0.5f * ONE_IN_Q31 ); + move32(); } ELSE { smooth_fact = (Word32) ( 0.75f * ONE_IN_Q31 ); + move32(); } L_tmp = Mpy_32_16_1( smooth_fact, add( j, 1 ) ); // (Q31 , Q0) -> Q16 - *Smoothing_factor = Mpy_32_32( *Smoothing_factor, L_tmp ); // (Q28, Q16) -> Q13 - *Smoothing_factor = L_shl_sat( *Smoothing_factor, Q15 ); // Q28 + *Smoothing_factor = Mpy_32_32( *Smoothing_factor, L_tmp ); // (Q31, Q16) -> Q16 + move32(); + *Smoothing_factor = L_shl_sat( *Smoothing_factor, Q15 ); // Q31 + move32(); } - IF( *Smoothing_factor > max_update_rate ) // Q28 + IF( GT_32( *Smoothing_factor, max_update_rate ) ) // Q31 { *Smoothing_factor = max_update_rate; + move32(); } return; @@ -200,7 +206,6 @@ static void ivas_set_up_cov_smoothing_fx( Word16 active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; update_factor = ivas_calculate_update_factor_fx( pFb->fb_bin_to_band.pFb_bin_to_band_fx[j], active_bins ); ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); - hCovState->pSmoothing_factor[j] = (float) hCovState->pSmoothing_factor_fx[j] / ONE_IN_Q28; } } ELSE @@ -211,11 +216,11 @@ static void ivas_set_up_cov_smoothing_fx( Word16 active_bins = pFb->fb_bin_to_band.p_short_stride_num_bins_per_band[j]; update_factor = ivas_calculate_update_factor_fx( p_bin_to_band, active_bins ); ivas_calculate_smoothning_factor_fx( &hCovState->pSmoothing_factor_fx[j], update_factor, min_pool_size, max_update_rate, smooth_mode, ivas_total_brate, j ); - hCovState->pSmoothing_factor[j] = (float) hCovState->pSmoothing_factor_fx[j] / ONE_IN_Q28; } } hCovState->prior_bank_idx = -1; + move16(); return; } @@ -286,14 +291,15 @@ ivas_error ivas_spar_covar_smooth_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } - if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL ) +#ifdef IVAS_FLOAT_FIXED + IF( ( hCovState->pSmoothing_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } -#ifdef IVAS_FLOAT_FIXED - IF( ( hCovState->pSmoothing_factor_fx = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) +#else + if ( ( hCovState->pSmoothing_factor = (float *) malloc( sizeof( float ) * cov_smooth_cfg->max_bands ) ) == NULL ) { - return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } #endif @@ -306,6 +312,13 @@ ivas_error ivas_spar_covar_smooth_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder" ); } set_zero( hCovState->pPrior_cov_real[i][j], cov_smooth_cfg->max_bands ); +#ifdef IVAS_FLOAT_FIXED + if ( ( hCovState->pPrior_cov_real_fx[i][j] = (Word32 *) malloc( sizeof( Word32 ) * cov_smooth_cfg->max_bands ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); + } + set_zero_fx( hCovState->pPrior_cov_real_fx[i][j], cov_smooth_cfg->max_bands ); +#endif } } @@ -339,11 +352,12 @@ void ivas_spar_covar_smooth_enc_close( if ( hCovState != NULL ) { - free( hCovState->pSmoothing_factor ); - hCovState->pSmoothing_factor = NULL; #ifdef IVAS_FLOAT_FIXED free( hCovState->pSmoothing_factor_fx ); hCovState->pSmoothing_factor_fx = NULL; +#else + free( hCovState->pSmoothing_factor ); + hCovState->pSmoothing_factor = NULL; #endif for ( i = 0; i < nchan_inp; i++ ) @@ -352,6 +366,10 @@ void ivas_spar_covar_smooth_enc_close( { free( hCovState->pPrior_cov_real[i][j] ); hCovState->pPrior_cov_real[i][j] = NULL; +#ifdef IVAS_FLOAT_FIXED + free( hCovState->pPrior_cov_real_fx[i][j] ); + hCovState->pPrior_cov_real_fx[i][j] = NULL; +#endif } } @@ -363,6 +381,120 @@ void ivas_spar_covar_smooth_enc_close( } +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------------------------* + * Function ivas_compute_smooth_cov_fx() + * + * Compute smooth covariance real/imag. + *-----------------------------------------------------------------------------------------*/ + +static void ivas_compute_smooth_cov_fx( + ivas_cov_smooth_state_t *hCovState, + ivas_filterbank_t *pFb, + Word32 *pCov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 *pPrior_cov_buf[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word32 fac, + const Word16 start_band, + const Word16 end_band, + const Word16 num_ch, + const Word16 transient_det[2], + Word16 q_cov[][IVAS_SPAR_MAX_CH] ) +{ + Word16 i, j, k; + Word16 prev_idx = hCovState->prior_bank_idx; + Word32 factor = 0, L_tmp, L_tmp1; + Word16 sm_b; + Word16 non_sm_b_idx; + sm_b = BAND_SMOOTH_REST_START_IDX; + + assert( end_band <= pFb->filterbank_num_bands ); + + IF( EQ_16( prev_idx, -1 ) || EQ_16( transient_det[1], 1 ) ) + { + FOR( i = 0; i < num_ch; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 + pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( q_cov[i][i], Q31 ) ) ); + move32(); + } + } + } + ELSE IF( EQ_16( transient_det[0], 1 ) ) + { + non_sm_b_idx = s_min( sm_b, end_band ); + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + IF( EQ_16( i, j ) ) + { + factor = fac; + move32(); + } + ELSE + { + factor = 0; + move32(); + } + + FOR( k = start_band; k < non_sm_b_idx; k++ ) + { + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + pCov_buf[i][j][k] = L_add( L_tmp, L_tmp1 ); + move32(); + L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_cov[i][j], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_cov[i][j] + pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); + move32(); + } + } + } + FOR( i = 0; i < num_ch; i++ ) + { + FOR( k = non_sm_b_idx; k < end_band; k++ ) + { + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], fac ); // (Q31, Q31) -> Q31 + pCov_buf[i][i][k] = L_add( pCov_buf[i][i][k], L_shl( L_tmp, sub( q_cov[i][i], Q31 ) ) ); + move32(); + } + } + } + ELSE IF( EQ_16( prev_idx, 0 ) ) + { + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + IF( EQ_16( i, j ) ) + { + factor = fac; + move32(); + } + ELSE + { + factor = 0; + move32(); + } + + FOR( k = start_band; k < end_band; k++ ) + { + L_tmp = Mpy_32_32( hCovState->pSmoothing_factor_fx[k], pCov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + L_tmp1 = Mpy_32_32( L_sub( ONE_IN_Q31, hCovState->pSmoothing_factor_fx[k] ), pPrior_cov_buf[i][j][k] ); // (Q31, q_cov[i][j]) -> q_cov[i][j] + pCov_buf[i][j][k] = L_add( L_tmp, L_tmp1 ); + move32(); + L_tmp = L_shl( Mpy_32_32( hCovState->pSmoothing_factor_fx[k], factor ), sub( q_cov[i][j], Q31 ) ); // ((Q31, Q31) -> Q31) -> q_cov[i][j] + pCov_buf[i][j][k] = L_add( pCov_buf[i][j][k], L_tmp ); + move32(); + } + } + } + } + + return; +} +#else /*-----------------------------------------------------------------------------------------* * Function ivas_compute_smooth_cov() * @@ -454,8 +586,45 @@ static void ivas_compute_smooth_cov( return; } +#endif + + +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------------------------* + * Function ivas_cov_smooth_process_fx() + * + * Covariance smoothing process + *-----------------------------------------------------------------------------------------*/ + +void ivas_cov_smooth_process_fx( + ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 start_band, + const Word16 end_band, + const Word16 num_ch, + const Word16 transient_det[2], + Word16 q_cov[][IVAS_SPAR_MAX_CH] ) +{ + Word16 i, j; + Word16 num_bands = end_band - start_band; + + ivas_compute_smooth_cov_fx( hCovState, pFb, cov_real, hCovState->pPrior_cov_real_fx, (Word32) ( 1e-20f * ONE_IN_Q31 ), start_band, end_band, num_ch, transient_det, q_cov ); + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + mvl2l( &cov_real[i][j][start_band], &hCovState->pPrior_cov_real_fx[i][j][start_band], num_bands ); + } + } + hCovState->prior_bank_idx = 0; + move16(); + return; +} +#else /*-----------------------------------------------------------------------------------------* * Function ivas_cov_smooth_process() * @@ -488,3 +657,4 @@ void ivas_cov_smooth_process( return; } +#endif diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 070b04e13..030047e15 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5305,6 +5305,27 @@ void ivas_spar_covar_enc_close( const int16_t nchan_inp /* i : number of input channels */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_enc_cov_handler_process( + ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ + float **ppIn_FR_real, + float **ppIn_FR_imag, + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const int16_t start_band, + const int16_t end_band, + const int16_t num_ch, + const int16_t dtx_vad, + const int16_t transient_det[2], + const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH], + int16_t *res_ind, + const int16_t *remix_order, + int16_t *dyn_active_w_flag, + const int16_t nchan_transport, + const int16_t is_sba +); +#else void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ float **ppIn_FR_real, @@ -5324,6 +5345,7 @@ void ivas_enc_cov_handler_process( const int16_t nchan_transport, const int16_t is_sba ); +#endif ivas_error ivas_spar_covar_smooth_enc_open( ivas_cov_smooth_state_t **hCovState, /* i/o: SPAR Covar. smoothing handle */ @@ -5339,6 +5361,18 @@ void ivas_spar_covar_smooth_enc_close( const int16_t nchan_inp /* i : number of input channels */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_cov_smooth_process_fx( + ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const Word16 start_band, + const Word16 end_band, + const Word16 num_ch, + const Word16 transient_det[2], + Word16 q_cov[][IVAS_SPAR_MAX_CH] +); +#else void ivas_cov_smooth_process( ivas_cov_smooth_state_t *hCovState, /* i/o: Covariance state handle */ float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -5348,6 +5382,7 @@ void ivas_cov_smooth_process( const int16_t num_ch, const int16_t transient_det[2] ); +#endif /* Transient detector module */ ivas_error ivas_transient_det_open( diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index e68d016b1..af6923849 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -354,9 +354,12 @@ typedef struct ivas_cov_smooth_state_t { float *pPrior_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; int16_t prior_bank_idx; +#ifndef IVAS_FLOAT_FIXED float *pSmoothing_factor; +#endif int16_t num_bins; #ifdef IVAS_FLOAT_FIXED + Word32 *pPrior_cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *pSmoothing_factor_fx; #endif diff --git a/lib_com/options.h b/lib_com/options.h index 086de2889..5f23bf45b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -95,6 +95,8 @@ #define NONBE_FIX_819_DOUBLE_PREC_COMB_FORMATS /* VA: issue 820: Double precision arithmetic in combined formats */ #define NONBE_FIX_849_OMASA_BFI_CRASH /* VA: issue 849: fix OMASA 2TC and FEC crashes */ #define IVAS_FLOAT_FIXED +#define FIX_TMP_714 +#define BASOP_NOGLOB_TMP_715 #define EVS_FUNC_MODIFIED //#define DEBUGGING //#define DBG_WAV_WRITER diff --git a/lib_com/prot_fx1.h b/lib_com/prot_fx1.h index a5e46bc24..3654f330a 100644 --- a/lib_com/prot_fx1.h +++ b/lib_com/prot_fx1.h @@ -119,6 +119,13 @@ void Copy_Scale_sig_16_32( const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ ); +void Copy_Scale_sig_16_32_no_sat( + const Word16 x[], /* i : signal to scale input Qx */ + Word32 y[], /* o : scaled signal output Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ +); + void Copy_Scale_sig_32_16( const Word32 x[], /* i : signal to scale i Qx */ Word16 y[], /* o : scaled signal output Qx */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index e5946de40..68d285dc7 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -69,9 +69,10 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( Word16 last_element_mode ); void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( - Decoder_State *st, - Word16 tofix, - Word16 last_element_mode); + Decoder_State *st, + Word16 tofix, + Word16 last_element_mode, + const FRAME_MODE frameMode); void fixed_to_float_stereo_tcx_core_dec( Decoder_State *st, @@ -124,6 +125,13 @@ void fix2f_16(Word16 *var_fix, float *var_flt, Word32 expo); void f2fix(float *var_flt, Word32 *var_fix, Word32 expo); void fix2f(Word32 *var_fix, float *var_flt, Word32 expo); +#ifdef IVAS_FLOAT_FIXED +// Get max Q factor for a float value before sat in 32-bit +Word16 L_get_q( float f ); +// Get max Q factor for a float buffer before sat in 32-bit +Word16 L_get_q_buf( float *ptr_flt, Word16 length ); +#endif + Word32 Mult_32_16( Word32 a, Word16 b); @@ -5571,6 +5579,16 @@ void fb_tbe_dec_fx( Word16 hb_synth_exp ); +void fb_tbe_dec_ivas_fx( + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Word16 Q_fb_exc, + Word32 *hb_synth, /* o : high-band synthesis */ + Word16 hb_synth_exp, + Word16 *fb_synth_ref, + Word16 Q_fb_synth_ref, + Word16 output_frame); + void tbe_read_bitstream_fx( Decoder_State *st_fx /* i/o: encoder state structure */ ); diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index ac9804ee6..0b58ff40d 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -698,6 +698,55 @@ void Copy_Scale_sig_16_32( move32();/* saturation can occur here */ } } + +void Copy_Scale_sig_16_32_no_sat( + const Word16 x[], /* i : signal to scale input Qx */ + Word32 y[], /* o : scaled signal output Qx */ + const Word16 lg, /* i : size of x[] Q0 */ + const Word16 exp0 /* i : exponent: x = round(x << exp) Qx ?exp */ +) +{ + Word16 i; + Word32 L_tmp; +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; +#endif + + + IF (exp0 == 0) + { + FOR (i = 0; i < lg; i++) + { + y[i] = L_deposit_l(x[i]); + } + return; + } + IF (exp0 < 0) + { + /*Should not happen */ + FOR (i = 0; i < lg; i++) + { +#ifdef BASOP_NOGLOB + y[i] = L_deposit_l(shl_o(x[i], exp0, &Overflow)); +#else + y[i] = L_deposit_l(shl(x[i], exp0)); +#endif + } + return; + } +#ifdef BASOP_NOGLOB + L_tmp = L_shl_o(1,exp0-1, &Overflow); +#else + tmp = shl(1,exp0); +#endif + FOR (i = 0; i < lg; i++) + { + //y[i] = L_mult0(x[i], L_tmp); + y[i] = W_extract_l(W_mult_32_16(L_tmp, x[i])); + move32();/* saturation can occur here */ + } +} + void Copy_Scale_sig_32_16( const Word32 x[], /* i : signal to scale input Qx */ Word16 y[], /* o : scaled signal output Qx */ diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index d96f5a800..1e53cbb8c 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -599,11 +599,86 @@ void decoder_LPD_flt( 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->gamma = float_to_fix16(st->gamma_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->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); + st->inv_gamma = FL2WORD16_SCALE(1 / st->gamma_float, 1); + st->hTcxCfg->preemph_fac = FL2WORD16(st->hTcxCfg->preemph_fac_flt); + f2me_16(st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e); + f2me_16(st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e); + f2me_16(st->hTcxDec->old_gaintcx_bfi_float, &st->hTcxDec->old_gaintcx_bfi, &st->hTcxDec->old_gaintcx_bfi_e); + + FOR(Word16 l = 0; l < N_LTP_GAIN_MEMS; l++) + { + st->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16(st->hTcxDec->ltpGainMemory[l], Q15); + } + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16(st->hTcxDec->tcxltp_last_gain_unmodified_float, Q15); + st->old_fpitch = float_to_fix(st->old_fpitch_float, Q16); + st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); + IF( bfi && st->tonal_mdct_plc_active && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + FOR( Word16 ii = 0; ii < st->hTonalMDCTConc->pTCI_float->numIndexes; ii++ ) + { + float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[ii]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI_fix->phaseDiff[ii] = float_to_fix16( pd, Q12 ); + } + FOR( Word16 ii = 0; ii < MAX_NUMBER_OF_IDX * GROUP_LENGTH; ii++ ) + { + float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[ii]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted[ii] = (Word16) ( pd * ( 1u << Q13 ) ); + } + } + IF(bfi && st->tonal_mdct_plc_active && NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + FOR(Word16 i = 0; i < FDNS_NPTS; i++) + { + f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); + st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); + } + } + + IF(st->enablePlcWaveadjust) + { + f2me_buf(st->hPlcInfo->data_reci2, st->hPlcInfo->data_reci2_fx, &st->hPlcInfo->data_reci2_scale, st->hPlcInfo->L_frameTCX); + } + + // u8bit to 16bit + FOR(int l = 0; l < IGF_START_MX; l++) + { + st->hIGFDec->infoTCXNoise_evs[l] = (Word16)st->hIGFDec->infoTCXNoise[l]; + } + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); + //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 ); fixedToFloat_arr(synth_fx, synth, 0, st->L_frame); fixedToFloat_arr(synthFB_fx, synthFB, 0, hTcxDec->L_frameTCX); + FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) + { + st->hTcxDec->ltpGainMemory[l] = fix16_to_float( st->hTcxDec->ltpGainMemory_fx[l], Q15 ); + } + st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); + st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); + // 16bit to u8bit + FOR(Word16 l = 0; l < IGF_START_MX; l++) + { + st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; + } + me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpecBuf, (N_MAX_TCX - IGF_START_MN)); + st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); + 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_flt( st, prm, Aq, Aind, &synth[0], &synthFB[0], bfi, 0, 0 ); #endif @@ -642,11 +717,84 @@ void decoder_LPD_flt( 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->gamma = float_to_fix16(st->gamma_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->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); + st->inv_gamma = FL2WORD16_SCALE(1 / st->gamma_float, 1); + st->hTcxCfg->preemph_fac = FL2WORD16(st->hTcxCfg->preemph_fac_flt); + f2me_16(st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e); + f2me_16(st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e); + f2me_16(st->hTcxDec->old_gaintcx_bfi_float, &st->hTcxDec->old_gaintcx_bfi, &st->hTcxDec->old_gaintcx_bfi_e); + FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) + { + st->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( st->hTcxDec->ltpGainMemory[l], Q15 ); + } + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); + st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); + st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); + IF( bfi && st->tonal_mdct_plc_active && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + FOR( Word16 ii = 0; ii < st->hTonalMDCTConc->pTCI_float->numIndexes; ii++ ) + { + float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[ii]; + if ( pd >= PI2 ) + pd = fmodf( pd, PI2 ) - PI2; + st->hTonalMDCTConc->pTCI_fix->phaseDiff[ii] = float_to_fix16( pd, Q12 ); + } + FOR( Word16 ii = 0; ii < MAX_NUMBER_OF_IDX * GROUP_LENGTH; ii++ ) + { + float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[ii]; + pd = fmodf( pd, PI2 ); + st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted[ii] = (Word16) ( pd * ( 1u << Q13 ) ); + } + } + IF(bfi && st->tonal_mdct_plc_active && NE_16(st->element_mode, IVAS_CPE_MDCT)) + { + FOR(Word16 i = 0; i < FDNS_NPTS; i++) + { + f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); + st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); + } + } + + IF(st->enablePlcWaveadjust) + { + f2me_buf(st->hPlcInfo->data_reci2, st->hPlcInfo->data_reci2_fx, &st->hPlcInfo->data_reci2_scale, st->hPlcInfo->L_frameTCX); + } + + // u8bit to 16bit + FOR(int l = 0; l < IGF_START_MX; l++) + { + st->hIGFDec->infoTCXNoise_evs[l] = (Word16)st->hIGFDec->infoTCXNoise[l]; + } + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); + //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 ); fixedToFloat_arr(synth_fx, synth, 0, st->L_frame + k * L_frame / 2); fixedToFloat_arr(synthFB_fx, synthFB, 0, hTcxDec->L_frameTCX + k * L_frameTCX / 2); + FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) + { + st->hTcxDec->ltpGainMemory[l] = fix16_to_float( st->hTcxDec->ltpGainMemory_fx[l], Q15 ); + } + st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); + st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); + // 16bit to u8bit + FOR(Word16 l = 0; l < IGF_START_MX; l++) + { + st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; + } + me2f_buf(st->hIGFDec->virtualSpec, st->hIGFDec->virtualSpec_e, st->hIGFDec->virtualSpecBuf, (N_MAX_TCX - IGF_START_MN)); + st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); + 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_flt( st, prm, Aq, Aind, &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], bfi, k, 0 ); #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 28686b454..fa596afba 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3180,26 +3180,22 @@ void decoder_tcx_fx( const Word16 frame_cnt, const Word16 sba_dirac_stereo_flag ) { - float x[N_MAX] = { 0 }; - //float A[M+1]; Word32 x_fx[N_MAX]; - Word16 x_e; - float gainlpc2[FDNS_NPTS]; + Word16 x_e = 30; Word16 gainlpc2_fx[FDNS_NPTS]; Word16 gainlpc2_e[FDNS_NPTS]; - float gain_tcx = 0; Word16 gain_tcx_e = 0, gain_tcx_fx = 0; Word16 fUseTns, L_frame_glob, L_frameTCX_glob; STnsData tnsData; Word16 tcx_offset, tcx_offsetFB, L_frame, L_frameTCX; Word16 left_rect, L_spec, tmp_concealment_method, nf_seed; const Word16 *prm_sqQ; - float xn_buf[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; Word16 xn_buf_fx[L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX]; /* Q14 */ + Word16 shift; + Word16 x_len; + Word16 q_x = Q11, q_win = -2; - set_f( x, 0.0, N_MAX ); set32_fx( x_fx, 0, N_MAX ); - set_f( gainlpc2, 0.0, FDNS_NPTS ); set16_fx( gainlpc2_fx, 0, FDNS_NPTS ); set16_fx( gainlpc2_e, 0, FDNS_NPTS ); @@ -3217,275 +3213,65 @@ void decoder_tcx_fx( nf_seed = 0; fUseTns = 0; /* flag that is set if TNS data is present */ - set_f( xn_buf, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); - set16_fx( xn_buf_fx, 0, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX ); init_tcx_info_fx( st, L_frame_glob, L_frameTCX_glob, frame_cnt, bfi, &tcx_offset, &tcx_offsetFB, &L_frame, &L_frameTCX, &left_rect, &L_spec ); -#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->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->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 ); - st->inv_gamma = FL2WORD16_SCALE( 1 / st->gamma_float, 1 ); - st->hTcxCfg->preemph_fac = FL2WORD16( st->hTcxCfg->preemph_fac_flt ); - f2me_16( st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e ); - f2me_16( st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e ); - f2me_16( st->hTcxDec->old_gaintcx_bfi_float, &st->hTcxDec->old_gaintcx_bfi, &st->hTcxDec->old_gaintcx_bfi_e ); - /* end temp init*/ - decoder_tcx_invQ_fx( st, prm, A_fx, Aind, L_spec, L_frame, L_frameTCX, x_fx, &x_e, gainlpc2_fx, gainlpc2_e, &xn_buf_fx[0], &fUseTns, &tnsData, &gain_tcx_fx, &gain_tcx_e, &prm_sqQ, &nf_seed, bfi, frame_cnt ); - /* TODO: remove float dependency */ - st->hTcxDec->stepCompensate_float = me2f_16( st->hTcxDec->stepCompensate, st->hTcxDec->stepCompensate_e ); - st->hTcxDec->gainHelper_float = me2f_16( st->hTcxDec->gainHelper, st->hTcxDec->gainHelper_e ); - st->last_concealed_gain_syn_deemph_float = me2f_16( st->last_concealed_gain_syn_deemph, st->last_concealed_gain_syn_deemph_e ); - st->last_gain_syn_deemph_float = me2f_16( st->last_gain_syn_deemph, st->last_gain_syn_deemph_e ); - st->hTcxDec->old_gaintcx_bfi_float = me2f_16( st->hTcxDec->old_gaintcx_bfi, st->hTcxDec->old_gaintcx_bfi_e ); - - st->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( st->hTcxDec->cummulative_damping_tcx, Q15 ); - st->hTcxDec->damping_float = fix16_to_float( st->hTcxDec->damping, Q14 ); - st->lp_gainp = fix_to_float( st->Mode2_lp_gainp, Q16 ); - - me2f_buf( x_fx, x_e, x, L_frameTCX ); - gain_tcx = me2f_16( gain_tcx_fx, gain_tcx_e ); - FOR ( Word16 j = 0; j < FDNS_NPTS; j++ ) - { - gainlpc2[j] = me2f_16( gainlpc2_fx[j], gainlpc2_e[j] ); - } - FOR ( Word16 j = 0; j < max( max( L_frame, L_spec ), L_frameTCX ); j++ ) - { - xn_buf[j] = fix16_to_float( xn_buf_fx[j], Q14 ); - } - -#if 0 - dbgwrite_txt(x, L_frameTCX, "logs\\dir\\Fixed_code_decoderTcxInvQ_x.txt", NULL); - dbgwrite_txt(xn_buf, max(max(L_frame, L_spec), L_frameTCX), "logs\\dir\\Fixed_code_decoderTcxInvQ_xnBuf.txt", NULL); - dbgwrite_txt(gainlpc2, FDNS_NPTS, "logs\\dir\\Fixed_code_decoderTcxInvQ_gainlpc2.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->stepCompensate_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_stepCompensate.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->gainHelper_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_gainHelper.txt", NULL); - dbgwrite_txt(&(st->last_concealed_gain_syn_deemph_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_lastConcealedGainSynDeemph.txt", NULL); - dbgwrite_txt(&(st->last_gain_syn_deemph_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_lastGainSynDeemph.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->old_gaintcx_bfi_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_oldGaintcxBfi.txt", NULL); - dbgwrite_txt(&(st->hTcxDec->cummulative_damping_tcx_float), 1, "logs\\dir\\Fixed_code_decoderTcxInvQ_cummulativeDampingTcx.txt", NULL); - 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 -#endif + shift = Find_Max_Norm32( x_fx, N_MAX ); + move16(); + Scale_sig32( x_fx, N_MAX, shift ); + x_e = sub( x_e, shift ); + move16(); -#ifdef IVAS_FLOAT_FIXED - f2me_buf( x, x_fx, &x_e, N_MAX ); - FOR( Word16 j = 0; j < FDNS_NPTS; j++ ) - { - 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 ); - FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - st->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( st->hTcxDec->ltpGainMemory[l], Q15 ); - } decoder_tcx_noisefilling_fx( st, NULL, 0, A_fx, L_frameTCX_glob, L_spec, L_frame, L_frameTCX, x_fx, &x_e, gainlpc2_fx, gainlpc2_e, &tmp_concealment_method, gain_tcx_fx, gain_tcx_e, prm_sqQ, nf_seed, bfi, 0, frame_cnt ); - FOR( Word16 l = 0; l < N_LTP_GAIN_MEMS; l++ ) - { - st->hTcxDec->ltpGainMemory[l] = fix16_to_float( st->hTcxDec->ltpGainMemory_fx[l], Q15 ); - } - me2f_buf( x_fx, x_e, x, N_MAX ); -#endif -#ifdef IVAS_FLOAT_FIXED - // Float to fix starts here - Word16 x_len; - IF(bfi && st->tonal_mdct_plc_active && NE_16(st->element_mode, IVAS_CPE_MDCT)) - { - FOR(Word16 i = 0; i < st->hTonalMDCTConc->pTCI_float->numIndexes; i++) - { - float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; - if (pd >= PI2) - pd = fmodf(pd, PI2) - PI2; - st->hTonalMDCTConc->pTCI_fix->phaseDiff[i] = float_to_fix16(pd, Q12); - } - FOR(Word16 i = 0; i < MAX_NUMBER_OF_IDX * GROUP_LENGTH; i++) - { - float pd = st->hTonalMDCTConc->pTCI_float->phase_currentFramePredicted_float[i]; - pd = fmodf(pd, PI2); - st->hTonalMDCTConc->pTCI_fix->phase_currentFramePredicted[i] = (Word16)(pd * (1u << Q13)); - } - FOR(Word16 i = 0; i < FDNS_NPTS; i++) - { - f2me_16(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_float[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors[i], &st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); - st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e = s_max(st->hTonalMDCTConc->secondLastBlockData.scaleFactors_max_e, st->hTonalMDCTConc->secondLastBlockData.scaleFactors_exp[i]); - } - } - st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16(st->hTcxDec->tcxltp_last_gain_unmodified_float, Q15); - st->old_fpitch = float_to_fix(st->old_fpitch_float, Q16); - st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); + decoder_tcx_noiseshaping_igf_fx( st, L_spec, L_frame, L_frameTCX, left_rect, x_fx, &x_e, &x_len, gainlpc2_fx, gainlpc2_e, &tmp_concealment_method, bfi ); - IF(st->enablePlcWaveadjust) - { - f2me_buf(st->hPlcInfo->data_reci2, st->hPlcInfo->data_reci2_fx, &st->hPlcInfo->data_reci2_scale, st->hPlcInfo->L_frameTCX); - } + shift = Find_Max_Norm32( x_fx, N_MAX ) - 5; + move16(); + Scale_sig32( x_fx, N_MAX, shift ); + x_e = sub( x_e, shift ); + move16(); - // u8bit to 16bit - FOR(int l = 0; l < IGF_START_MX; l++) - { - st->hIGFDec->infoTCXNoise_evs[l] = (Word16)st->hIGFDec->infoTCXNoise[l]; - } - // Float to fix ends here + decoder_tcx_tns_fx( st, L_frame_glob, L_spec, L_frame, L_frameTCX, x_fx, fUseTns, &tnsData, bfi, frame_cnt, 0 ); - decoder_tcx_noiseshaping_igf_fx( st, L_spec, L_frame, L_frameTCX, left_rect, x_fx, &x_e, &x_len, gainlpc2_fx, gainlpc2_e, &tmp_concealment_method, bfi ); + Scale_sig32( x_fx, N_MAX, sub( x_e, 20 ) ); // Scaling x_fx to Q11 + Scale_sig( xn_buf_fx, L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX, -16 ); // Scaling xn_buf_fx to Q-2 + x_e = sub( 31, 11 ); + move16(); - // Fixed to float starts here - st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); - st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); - // 16bit to u8bit - FOR(Word16 l = 0; l < IGF_START_MX; l++) + IF( NE_16( st->igf, 0 ) ) { - st->hIGFDec->infoTCXNoise[l] = (uint8_t)st->hIGFDec->infoTCXNoise_evs[l]; + Scale_sig32( st->hIGFDec->virtualSpec, ( N_MAX_TCX - IGF_START_MN ), ( st->hIGFDec->virtualSpec_e - x_e ) ); + st->hIGFDec->virtualSpec_e = x_e; } - 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 -#endif -#ifdef IVAS_FLOAT_FIXED - Word32 x_fx_[1200]; - Word16 q = 26; - float maximum = 0; - 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); -#endif + /* Scaling down buffers for decoder_tcx_imdct_fx*/ + Scale_sig( st->hTcxDec->syn_Overl, 320, -( st->Q_syn + 1 + 2 ) ); // Scaling to Q-2 + Scale_sig( st->hTcxDec->syn_Overl_TDAC, 320, -( st->Q_syn + 2 ) ); // Scaling to Q-2 + Scale_sig( st->hTcxDec->syn_Overl_TDACFB, 480, -( st->Q_syn + 2 ) ); // Scaling to Q-2 + Scale_sig( st->hTcxDec->syn_OverlFB, 480, -( st->Q_syn + 2 ) ); // Scaling to Q-2 + Scale_sig( st->hTcxDec->old_syn_Overl, 320, -( st->Q_syn + 1 + 2 ) ); // Scaling to Q-2 + Scale_sig( st->hHQ_core->old_out_LB_fx, 640, -( st->hHQ_core->Q_old_wtda + 2 ) ); // Scaling to Q-2 + Scale_sig( st->hHQ_core->old_out_fx, 960, -( st->hHQ_core->Q_old_wtda + 2 ) ); // Scaling to Q-2 -#ifdef IVAS_FLOAT_FIXED - Word16 q_x = Q11, q_win = -2; + Copy_Scale_sig_16_32_no_sat( st->old_Aq_12_8_fx, st->old_Aq_12_8_fx_32, M + 1, ( 28 - ( 15 - norm_s( st->old_Aq_12_8_fx[0] - 1 ) ) ) ); - FOR(Word16 i = 0; i < s_min(s_max(s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX, L_spec)), L_frame), 1200); i++) { - x_fx[i] = (Word32)(x[i] * (1 << q_x)); - } - FOR (Word16 ind = 0; ind < 2040; ind++) { - xn_buf_fx[ind] = (Word16)(xn_buf[ind] / 4.f); - } - x_e = 31 - q_x; - st->hIGFDec->virtualSpec_e = x_e; - IF ( NE_16(st->igf, 0) ) - FOR(Word16 i = 0; i < s_min(st->hIGFDec->infoIGFStopLine - st->hIGFDec->infoIGFStartLine, 856); i++) { - st->hIGFDec->virtualSpec_fx[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] = (Word32)(st->hIGFDec->virtualSpec_float[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] * (1 << (31 - st->hIGFDec->virtualSpec_e))); - } - - FOR( Word16 ind = 0; ind < 320; ind++ ) - { - st->hTcxDec->syn_Overl[ind] = (Word16)(st->hTcxDec->syn_Overl_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->syn_Overl_TDAC[ind] = (Word16)(st->hTcxDec->syn_Overl_TDAC_float[ind] / (1<<(-q_win))); - } - FOR( Word16 ind = 0; ind < 480; ind++ ) - { - st->hTcxDec->syn_OverlFB[ind] = (Word16)(st->hTcxDec->syn_OverlFB_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 480; ind++) { - st->hTcxDec->syn_Overl_TDACFB[ind] = (Word16)(st->hTcxDec->syn_Overl_TDACFB_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 640; ind++) { - st->hHQ_core->old_out_LB_fx[ind] = (Word16)(st->hHQ_core->old_outLB[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 17; ind++) { - st->old_Aq_12_8_fx_32[ind] = (Word32)(st->old_Aq_12_8[ind] * (1<<28)); - } - FOR( Word16 ind = 0; ind < M + 1; ind++ ) - { - st->old_Aq_12_8_fx[ind] = (Word16) ( st->old_Aq_12_8[ind] * 4096.f ); - } - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->old_syn_Overl[ind] = (Word16)(st->hTcxDec->old_syn_Overl_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->syn_Overl_TDAC[ind] = (Word16)(st->hTcxDec->syn_Overl_TDAC_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 480; ind++) { - st->hTcxDec->syn_OverlFB[ind] = (Word16)(st->hTcxDec->syn_OverlFB_float[ind] / (1<<(-q_win))); - } - FOR(Word16 ind = 0; ind < 320; ind++) { - st->hTcxDec->syn_Overl[ind] = (Word16)(st->hTcxDec->syn_Overl_float[ind] / (1<<(-q_win))); - } - st->hTcxDec->conceal_eof_gain = (Word16)(st->hTcxDec->conceal_eof_gain_float * 16384.f); - st->last_concealed_gain_syn_deemph = (Word16)(st->last_concealed_gain_syn_deemph_float * 32767.f); - float maxim = 0; - IF(st->hFdCngDec && st->hFdCngDec->hFdCngCom) { - FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) - { - maxim = fmaxf(maxim, fabsf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind])); - } - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; - IF(L_abs((Word32)maxim)!=0) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - norm_l((Word32)maxim); - FOR(Word16 ind = 0; ind < FFTCLDFBLEN; ind++) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * (1LL<<(31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); - } - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); - } - FOR(Word16 ind = 0; ind < 960; ind++) { - st->hHQ_core->old_out_fx[ind] = (Word16)(st->hHQ_core->old_out[ind] / (1<<(-q_win))); - } -/*=======================================*/ - /*Scaling down the synth and synthFB buffers for decoder_tcx_imdct_fx */ - FOR( Word16 ind = 0; ind < L_frame_glob; ind++ ) - { - synth_fx[ind] = shr( synth_fx[ind], 2 ); - } - FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) - { - synthFB_fx[ind] = shr( synthFB_fx[ind], 2 ); - } + Scale_sig( synth_fx, L_frame_glob, -2 ); // Scaling to Q-2 + Scale_sig( synthFB_fx, L_frameTCX_glob, -2 ); // Scaling to Q-2 decoder_tcx_imdct_fx( st, L_frame_glob, L_frameTCX_glob, L_spec, tcx_offset, tcx_offsetFB, L_frame, L_frameTCX, left_rect, &x_fx[0], q_x, xn_buf_fx, q_win, MDCT_IV, fUseTns, &synth_fx[0], &synthFB_fx[0], bfi, frame_cnt, sba_dirac_stereo_flag ); /* Scaling up again */ - FOR( Word16 ind = 0; ind < L_frame_glob; ind++ ) - { - synth_fx[ind] = shl_sat( synth_fx[ind], 2 ); - } - FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) - { - synthFB_fx[ind] = shl_sat( synthFB_fx[ind], 2 ); - } - /*=======================================*/ - IF(st->igf) me2f_buf(x_fx, x_e, x, s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX, L_spec) ) ); - - FOR(Word16 ind = 0; ind < 17; ind++) { - st->old_Aq_12_8[ind] = (float)(st->old_Aq_12_8_fx[ind]) / (float)(1<<12); - } - FOR(Word16 ind = 0; ind < 640; ind++) { - st->hHQ_core->old_outLB[ind] = (float)st->hHQ_core->old_out_LB_fx[ind] * (1<<(-q_win)); - } - FOR(Word16 ind = 0; ind < 960; ind++) { - st->hHQ_core->old_out[ind] = (float)st->hHQ_core->old_out_fx[ind] * (1<<(-q_win)); - } - IF ( EQ_16(st->hTcxCfg->last_aldo, 0) ) FOR(Word16 ind = 0; ind < L_FRAME32k / 2; ind++) { - st->hTcxDec->syn_Overl_float[ind] = (float)st->hTcxDec->syn_Overl[ind] * (1<<(-q_win)); - } - IF ( EQ_16(st->hTcxCfg->last_aldo, 0) ) FOR(Word16 ind = 0; ind < L_FRAME_MAX / 2; ind++) { - st->hTcxDec->syn_OverlFB_float[ind] = (float)st->hTcxDec->syn_OverlFB[ind] * (1<<(-q_win)); - } - st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); - 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); - -#endif + Scale_sig( synth_fx, L_frame_glob, 2 ); + Scale_sig( synthFB_fx, L_frameTCX_glob, 2 ); + Scale_sig( st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, ( st->Q_syn + 2 ) ); + Scale_sig( st->hTcxDec->syn_Overl, L_FRAME32k / 2, ( st->Q_syn + 1 + 2 ) ); + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, ( st->hHQ_core->Q_old_wtda + 2 ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, ( st->hHQ_core->Q_old_wtda + 2 ) ); } /*-------------------------------------------------------------------* diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 5ff8ae1e9..db2cd59da 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -1565,7 +1565,11 @@ void gsc_dec_ivas_fx( } IF(concat_out[j] < 0) { +#ifdef BASOP_NOGLOB_TMP_715 + seed_init = add_sat( seed_init, 3 ); +#else seed_init = add(seed_init,3); +#endif move16(); } } diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 3af6bacd7..b7cfa694a 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -821,7 +821,7 @@ ivas_error ivas_core_dec( #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_2( st, 1, last_element_mode); + stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st, 1, last_element_mode, frameMode[n]); /* 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 ); @@ -830,7 +830,7 @@ ivas_error ivas_core_dec( 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); + stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st, 0, last_element_mode, frameMode[n]); fixed_to_float_stereo_tcx_core_dec( st, output[n] ); } #else @@ -2024,7 +2024,60 @@ ivas_error ivas_core_dec( /* FB TBE decoder */ if ( st->extl == FB_TBE ) { +#ifdef IVAS_FLOAT_FIXED + /*------------------------flt-2-fix-------------------------------------*/ + st->Q_syn = 0; + floatToFixed_arrL( hb_synth[n], hb_synth_32[n], st->Q_syn, L_FRAME48k ); + //Word16 Q_fbbwe_hpf = 11; /*assumed can change*/ + if ( hBWE_TD != NULL ) + { + hBWE_TD->fbbwe_hpf_mem_fx_Q[0] = norm_arr_l(hBWE_TD->fbbwe_hpf_mem[0], 4); + hBWE_TD->fbbwe_hpf_mem_fx_Q[1] = norm_arr_l(hBWE_TD->fbbwe_hpf_mem[1], 4); + hBWE_TD->fbbwe_hpf_mem_fx_Q[2] = norm_arr_l(hBWE_TD->fbbwe_hpf_mem[2], 4); + hBWE_TD->fbbwe_hpf_mem_fx_Q[3] = norm_arr_l(hBWE_TD->fbbwe_hpf_mem[3], 4); + hBWE_TD->idxGain_fx = hBWE_TD->idxGain; + hBWE_TD->prev_fbbwe_ratio_fx = floatToFixed( hBWE_TD->prev_fbbwe_ratio, 0 ); + floatToFixed_arrL( hBWE_TD->fbbwe_hpf_mem[0], hBWE_TD->fbbwe_hpf_mem_fx[0], hBWE_TD->fbbwe_hpf_mem_fx_Q[0], 4 ); + floatToFixed_arrL( hBWE_TD->fbbwe_hpf_mem[1], hBWE_TD->fbbwe_hpf_mem_fx[1], hBWE_TD->fbbwe_hpf_mem_fx_Q[1], 4 ); + floatToFixed_arrL( hBWE_TD->fbbwe_hpf_mem[2], hBWE_TD->fbbwe_hpf_mem_fx[2], hBWE_TD->fbbwe_hpf_mem_fx_Q[2], 4 ); + floatToFixed_arrL( hBWE_TD->fbbwe_hpf_mem[3], hBWE_TD->fbbwe_hpf_mem_fx[3], hBWE_TD->fbbwe_hpf_mem_fx_Q[3], 4 ); + } + /*------------------------flt-2-fix-------------------------------------*/ + + fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/,Q_white_exc, hb_synth_32[n], st->Q_syn ,tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); + + /*------------------------fix-2-flt-------------------------------------*/ + if (Q_white_exc > 31) { + Scale_sig(tmp_buffer_fx, L_FRAME48k, 31 - Q_white_exc); + } + fixedToFloat_arr( tmp_buffer_fx, tmp_buffer, min(Q_white_exc,31), L_FRAME48k ); + fixedToFloat_arrL( hb_synth_32[n], hb_synth[n], st->Q_syn, L_FRAME48k ); + if ( hBWE_TD != NULL ) + { + hBWE_TD->idxGain = hBWE_TD->idxGain_fx; + hBWE_TD->prev_fbbwe_ratio = fixedToFloat(hBWE_TD->prev_fbbwe_ratio_fx, 0); + for ( int lp = 0; lp < 4; lp++ ) + { + if ( hBWE_TD->fbbwe_hpf_mem_fx_Q[lp] < 0 ) + { + for ( int lp2 = 0; lp2 < 4; lp2++ ) + { + hBWE_TD->fbbwe_hpf_mem[lp][lp2] = (float) hBWE_TD->fbbwe_hpf_mem_fx[lp][lp2] * ( (long long int) 1 << hBWE_TD->fbbwe_hpf_mem_fx_Q[lp] ); + } + } + else + { + for ( int lp2 = 0; lp2 < 4; lp2++ ) + { + hBWE_TD->fbbwe_hpf_mem[lp][lp2] = (float) hBWE_TD->fbbwe_hpf_mem_fx[lp][lp2] / ( (long long int) 1 << hBWE_TD->fbbwe_hpf_mem_fx_Q[lp] ); + } + } + } + } + /*------------------------fix-2-flt-------------------------------------*/ +#else fb_tbe_dec( st, tmp_buffer /*fb_exc*/, hb_synth[n], tmp_buffer /*fb_synth_ref*/, output_frame ); +#endif } } else if ( st->extl == SWB_BWE || st->extl == FB_BWE || ( output_Fs >= 32000 && st->core == ACELP_CORE && st->bwidth > NB && st->bws_cnt > 0 && !st->ppp_mode_dec && !( st->nelp_mode_dec == 1 && st->bfi == 1 ) ) ) diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index 75b89bf70..f36a83056 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -1100,7 +1100,11 @@ void stereo_icBWE_dec_fx( { IF( LE_16( ratio_L_fx, 29490 ) ) { +#ifdef FIX_TMP_714 + tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 +#else tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 +#endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 IF( tmp < 4096 ) @@ -1246,7 +1250,11 @@ void stereo_icBWE_dec_fx( { IF( LE_16( ratio_L_fx, 29490 ) ) { +#ifdef FIX_TMP_714 + tmp = mult_r( ratio_L_fx, ratio_L_fx ); // Q15 +#else tmp = mult_r( sub( 32767, ratio_L_fx ), sub( 32767, ratio_L_fx ) ); // Q15 +#endif tmp = mult_r( tmp, gsMapping_fx ); // Q14 tmp = mult_r( tmp, gsMapping_fx ); // Q13 IF( LT_16( tmp, 4096 ) ) diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index f4119e60d..568d9a5d7 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -640,7 +640,6 @@ void stereo_tcx_core_dec_fx( } /* TCX decoder */ - /* TODO: move the internal conversions outside */ decoder_tcx_fx( st, prm, Aq_fx, Aind, &synth_fx[0], &synthFB_fx[0], bfi, 0, sba_dirac_stereo_flag ); } diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 06b1e6821..a35ee72a0 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -722,7 +722,13 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ /*tmp = indice[1]*DIM_TR2*/ tmp = shl(indice[1],1); +#ifdef BASOP_NOGLOB + quant_tmp[1] = add_sat( shr( add_sat( quant_tmp[0], quant_tmp[2] ), 1 ), Env_TR_Cdbk2_fx[tmp] ); + /* To prevent an unnecessary saturation, it would be better to write the code as below, but might have an impact on EVS bit exactness */ + /* quant_tmp[1] = add( extract_h( L_mac( L_mult( quant_tmp[0], 16384 ), quant_tmp[2], 16384 ) ), Env_TR_Cdbk2_fx[tmp] ); */ +#else quant_tmp[1] = add(shr(add(quant_tmp[0], quant_tmp[2]),1), Env_TR_Cdbk2_fx[tmp]); +#endif move16();/*Q8 */ quant_tmp[3] = add(quant_tmp[2],Env_TR_Cdbk2_fx[add(tmp,1)]); move16();/*Q8 */ diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 77c4ef1b3..249130b70 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -4454,6 +4454,83 @@ void fb_tbe_dec_fx( return; } +#ifdef IVAS_FLOAT_FIXED +void fb_tbe_dec_ivas_fx( + Decoder_State *st, /* i/o: encoder state structure */ + const Word16 fb_exc[], /* i : FB excitation from the SWB part */ + Word16 Q_fb_exc, + Word32 *hb_synth, /* o : high-band synthesis */ + Word16 hb_synth_exp, + Word16 *fb_synth_ref, + Word16 Q_fb_synth_ref, + Word16 output_frame ) + +{ + Word16 i; + Word16 ratio = 0; + Word32 fb_exc_energy = 0; + Word32 L_tmp; + Word16 fb_synth[L_FRAME48k]; + TD_BWE_DEC_HANDLE hBWE_TD; + hBWE_TD = st->hBWE_TD; + + /* decode FB slope information */ + test(); + test(); + if ( output_frame == L_FRAME48k ) + { + IF( EQ_16( st->extl, FB_TBE ) && !st->bfi ) + { + IF( EQ_16( st->codec_mode, MODE2 ) ) + { + i = hBWE_TD->idxGain_fx; + move16(); + } + ELSE + { + i = (Word16) get_next_indice( st, 4 ); + } +#ifdef BASOP_NOGLOB + ratio = shl_sat( 1, i ); +#else + ratio = shl( 1, i ); +#endif + } + ELSE if ( EQ_16( st->extl, FB_TBE ) && st->bfi ) + { + ratio = hBWE_TD->prev_fbbwe_ratio_fx; + move16(); + } + } + ELSE + { + IF( !st->bfi ) + { + st->next_bit_pos = add( st->next_bit_pos, NUM_BITS_FB_FRAMEGAIN ); + } + + return; + } + fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); + + /* FB TBE synthesis */ + synthesise_fb_high_band_fx( fb_exc, Q_fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio_fx ), hBWE_TD->fbbwe_hpf_mem_fx, hBWE_TD->fbbwe_hpf_mem_fx_Q, hb_synth_exp ); + + IF (GE_16(st->element_mode, IVAS_CPE_DFT) && EQ_16(st->idchan, 0)) + { + Copy_Scale_sig(fb_synth,fb_synth_ref,L_FRAME48k, sub(Q_fb_synth_ref , hb_synth_exp)); //scaling is required + } + /* add the fb_synth component to the hb_synth component */ + /* v_add_fx( hb_synth, fb_synth, hb_synth, L_FRAME48k );*/ + FOR( i = 0; i < L_FRAME48k; i++ ) + { + hb_synth[i] = L_add( hb_synth[i], L_deposit_l(fb_synth[i])); + move16(); + } + return; +} +#endif + void tbe_read_bitstream_fx( Decoder_State *st_fx ) diff --git a/lib_enc/ivas_enc_cov_handler.c b/lib_enc/ivas_enc_cov_handler.c index 9a11ad984..d017a28bf 100644 --- a/lib_enc/ivas_enc_cov_handler.c +++ b/lib_enc/ivas_enc_cov_handler.c @@ -36,6 +36,9 @@ #include "ivas_prot.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx2.h" +#endif /*------------------------------------------------------------------------------------------* * Local constants @@ -81,7 +84,7 @@ ivas_error ivas_spar_covar_enc_open( cov_smooth_cfg.max_bands = IVAS_MAX_NUM_BANDS; #ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = (Word32) ( MAX_UPDATE_RATE * ONE_IN_Q28 ); // Q28 + cov_smooth_cfg.max_update_rate_fx = (Word32) ( MAX_UPDATE_RATE * ONE_IN_Q31 ); // Q31 #else cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE; #endif @@ -89,7 +92,8 @@ ivas_error ivas_spar_covar_enc_open( if ( smooth_mode == COV_SMOOTH_MC ) { #ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = (Word32) ( 1.0f * ONE_IN_Q28 ); // Q28 + // Note: (Word32) ( 1.0f * ONE_IN_Q31 ) overflows to INT_MIN + cov_smooth_cfg.max_update_rate_fx = ONE_IN_Q31; // Q31 #else cov_smooth_cfg.max_update_rate = 1.0f; #endif @@ -102,7 +106,7 @@ ivas_error ivas_spar_covar_enc_open( } #ifdef IVAS_FLOAT_FIXED - cov_smooth_cfg.max_update_rate_fx = (Word32) ( MAX_UPDATE_RATE_DTX * ONE_IN_Q28 ); // Q28 + cov_smooth_cfg.max_update_rate_fx = (Word32) ( MAX_UPDATE_RATE_DTX * ONE_IN_Q31 ); // Q31 #else cov_smooth_cfg.max_update_rate = MAX_UPDATE_RATE_DTX; #endif @@ -274,6 +278,28 @@ static int16_t ivas_spar_get_activeW_flag( * Encoder covariance handler process call *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error ivas_enc_cov_handler_process( + ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ + float **ppIn_FR_real, + float **ppIn_FR_imag, + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + ivas_filterbank_t *pFb, /* i/o: FB handle */ + const int16_t start_band, + const int16_t end_band, + const int16_t num_ch, + const int16_t dtx_vad, + const int16_t transient_det[2], + const int16_t HOA_md_ind[IVAS_SPAR_MAX_CH], + int16_t *res_ind, + const int16_t *remix_order, + int16_t *dyn_active_w_flag, + const int16_t nchan_transport, + const int16_t is_sba + +) +#else void ivas_enc_cov_handler_process( ivas_enc_cov_handler_state_t *hCovEnc, /* i/o: SPAR Covar. encoder handle */ float **ppIn_FR_real, @@ -294,9 +320,14 @@ void ivas_enc_cov_handler_process( const int16_t is_sba ) +#endif { int16_t i, j; int16_t dtx_cov_flag; +#ifdef IVAS_FLOAT_FIXED + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], *cov_dtx_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word16 q_cov[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#endif dtx_cov_flag = ( dtx_vad == 1 ) ? 0 : 1; @@ -328,7 +359,53 @@ void ivas_enc_cov_handler_process( } } +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + if ( ( cov_real_fx[i][j] = (Word32 *) malloc( sizeof( Word32 ) * pFb->filterbank_num_bands ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); + } + set_zero_fx( cov_real_fx[i][j], pFb->filterbank_num_bands ); + if ( ( cov_dtx_real_fx[i][j] = (Word32 *) malloc( sizeof( Word32 ) * pFb->filterbank_num_bands ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR COV encoder Fixed" ); + } + set_zero_fx( cov_dtx_real_fx[i][j], pFb->filterbank_num_bands ); + } + set_s( q_cov[i], 0, num_ch ); + } + + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + q_cov[i][j] = L_get_q_buf( hCovEnc->pCov_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); + q_cov[i][j] = min( q_cov[i][j], L_get_q_buf( cov_real[i][j], pFb->filterbank_num_bands ) ); + floatToFixed_arrL( cov_real[i][j], cov_real_fx[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + floatToFixed_arrL( hCovEnc->pCov_state->pPrior_cov_real[i][j], hCovEnc->pCov_state->pPrior_cov_real_fx[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + } + } +#endif + +#ifdef IVAS_FLOAT_FIXED + ivas_cov_smooth_process_fx( hCovEnc->pCov_state, cov_real_fx, pFb, start_band, end_band, num_ch, transient_det, q_cov ); +#else ivas_cov_smooth_process( hCovEnc->pCov_state, cov_real, pFb, start_band, end_band, num_ch, transient_det ); +#endif + +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + fixedToFloat_arrL( cov_real_fx[i][j], cov_real[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + fixedToFloat_arrL( hCovEnc->pCov_state->pPrior_cov_real_fx[i][j], hCovEnc->pCov_state->pPrior_cov_real[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + } + } +#endif if ( dtx_cov_flag == 0 ) { @@ -347,14 +424,74 @@ void ivas_enc_cov_handler_process( { if ( ( transient_det[0] == 0 ) && ( transient_det[1] == 0 ) ) { +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < num_ch; i++ ) + { + set_s( q_cov[i], 0, num_ch ); + for ( j = 0; j < num_ch; j++ ) + { + q_cov[i][j] = L_get_q_buf( hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); + q_cov[i][j] = min( q_cov[i][j], L_get_q_buf( cov_dtx_real[i][j], pFb->filterbank_num_bands ) ); + floatToFixed_arrL( cov_dtx_real[i][j], cov_dtx_real_fx[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + floatToFixed_arrL( hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + } + } +#endif + +#ifdef IVAS_FLOAT_FIXED + ivas_cov_smooth_process_fx( hCovEnc->pCov_dtx_state, cov_dtx_real_fx, pFb, start_band, end_band, num_ch, transient_det, q_cov ); +#else ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); +#endif + +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + fixedToFloat_arrL( cov_dtx_real_fx[i][j], cov_dtx_real[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + fixedToFloat_arrL( hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + } + } +#endif + hCovEnc->prior_dtx_present = 1; } else { if ( hCovEnc->prior_dtx_present == 0 ) { +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < num_ch; i++ ) + { + set_s( q_cov[i], 0, num_ch ); + for ( j = 0; j < num_ch; j++ ) + { + q_cov[i][j] = L_get_q_buf( hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], pFb->filterbank_num_bands ); + q_cov[i][j] = min( q_cov[i][j], L_get_q_buf( cov_dtx_real[i][j], pFb->filterbank_num_bands ) ); + floatToFixed_arrL( cov_dtx_real[i][j], cov_dtx_real_fx[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + floatToFixed_arrL( hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + } + } +#endif + +#ifdef IVAS_FLOAT_FIXED + ivas_cov_smooth_process_fx( hCovEnc->pCov_dtx_state, cov_dtx_real_fx, pFb, start_band, end_band, num_ch, transient_det, q_cov ); +#else ivas_cov_smooth_process( hCovEnc->pCov_dtx_state, cov_dtx_real, pFb, start_band, end_band, num_ch, transient_det ); +#endif + +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + fixedToFloat_arrL( cov_dtx_real_fx[i][j], cov_dtx_real[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + fixedToFloat_arrL( hCovEnc->pCov_dtx_state->pPrior_cov_real_fx[i][j], hCovEnc->pCov_dtx_state->pPrior_cov_real[i][j], q_cov[i][j], pFb->filterbank_num_bands ); + } + } +#endif + hCovEnc->prior_dtx_present = 1; } else @@ -372,7 +509,24 @@ void ivas_enc_cov_handler_process( } } +#ifdef IVAS_FLOAT_FIXED + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + free( cov_real_fx[i][j] ); + cov_real_fx[i][j] = NULL; + free( cov_dtx_real_fx[i][j] ); + cov_dtx_real_fx[i][j] = NULL; + } + } +#endif + +#ifdef IVAS_FLOAT_FIXED + return IVAS_ERR_OK; +#else return; +#endif } -- GitLab