From 28a402cec9fc80289fb650eb1fc99933fb014bcc Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 9 Apr 2024 22:02:24 +0530 Subject: [PATCH 1/4] Integration of fixed point sub-functions 15 [x] Overflow fix for st->mem_preemp_pre_q_fx [x] shoebox updates [x] Making variable Qs from Decoder_State structure common [x] ivas_dirac_dec_compute_directional_responses intermediate conv removal [x] stereo_icbwe_dec q alignment [x] Removes redundant flags/variables from structures [x] compute t60 coeffs converted to fixed point [x] SBA path intermediate conversions cleanup [x] ivas_mct_dec converto fixed point [x] ivas_dirac_dec_decorrelate_slot and its sub functions converted to fixed point [x] ivas_lfe_enc converted to fixed point. --- lib_com/cnst.h | 5 +- lib_com/enhancer_fx.c | 4 +- lib_com/fd_cng_com.c | 73 ++ lib_com/float_to_fix_ops.c | 416 +------ lib_com/ivas_cnst.h | 14 + lib_com/ivas_prot.h | 85 +- lib_com/ivas_prot_fx.h | 16 +- lib_com/ivas_tools.c | 94 +- lib_com/prot.h | 11 +- lib_com/prot_fx2.h | 12 +- lib_com/stat_com.h | 1 - lib_com/swb_bwe_com_lr_fx.c | 18 +- lib_dec/FEC_HQ_core_fx.c | 114 +- lib_dec/FEC_fx.c | 14 +- lib_dec/LD_music_post_filter_fx.c | 20 +- lib_dec/acelp_core_dec.c | 173 +-- lib_dec/acelp_core_dec_fx.c | 2 +- lib_dec/acelp_core_dec_ivas_fx.c | 762 +------------ lib_dec/acelp_core_switch_dec_fx.c | 20 +- lib_dec/amr_wb_dec.c | 48 +- lib_dec/amr_wb_dec_fx.c | 6 +- lib_dec/bass_psfilter_fx.c | 26 +- lib_dec/core_dec_switch.c | 4 - lib_dec/core_dec_switch_fx.c | 8 - lib_dec/core_switching_dec.c | 8 +- lib_dec/core_switching_dec_fx.c | 30 +- lib_dec/dec_LPD.c | 4 - lib_dec/dec_gen_voic_fx.c | 9 +- lib_dec/dec_higher_acelp_fx.c | 53 +- lib_dec/dec_tran_fx.c | 7 +- lib_dec/dec_uv_fx.c | 2 +- lib_dec/evs_dec.c | 49 +- lib_dec/evs_dec_fx.c | 2 +- lib_dec/fd_cng_dec.c | 190 ++++ lib_dec/fd_cng_dec_fx.c | 2 +- lib_dec/gs_dec_fx.c | 88 +- lib_dec/hq_core_dec_fx.c | 154 +-- lib_dec/hq_hr_dec_fx.c | 56 +- lib_dec/hq_lr_dec_fx.c | 10 +- lib_dec/init_dec.c | 9 +- lib_dec/init_dec_fx.c | 7 +- lib_dec/ivas_core_dec.c | 293 ++--- lib_dec/ivas_cpe_dec_fx.c | 5 - lib_dec/ivas_dirac_dec.c | 76 +- lib_dec/ivas_init_dec.c | 9 +- lib_dec/ivas_jbm_dec.c | 530 ++++++++- lib_dec/ivas_mct_core_dec.c | 102 ++ lib_dec/ivas_mct_dec.c | 1043 +++++++++++++++++- lib_dec/ivas_mdct_core_dec.c | 14 +- lib_dec/ivas_sba_dec.c | 246 +++++ lib_dec/ivas_sba_rendering_internal.c | 32 +- lib_dec/ivas_sce_dec_fx.c | 3 +- lib_dec/ivas_spar_decoder.c | 133 +++ lib_dec/ivas_spar_md_dec.c | 16 +- lib_dec/ivas_stat_dec.h | 11 +- lib_dec/ivas_stereo_icbwe_dec.c | 45 +- lib_dec/ivas_stereo_mdct_core_dec.c | 9 + lib_dec/ivas_stereo_mdct_core_dec_fx.c | 55 +- lib_dec/ivas_stereo_switching_dec.c | 6 +- lib_dec/ivas_tcx_core_dec.c | 12 - lib_dec/ivas_td_low_rate_dec.c | 43 +- lib_dec/nelp_dec_fx.c | 2 +- lib_dec/stat_dec.h | 139 ++- lib_dec/swb_bwe_dec_lr_fx.c | 20 +- lib_dec/swb_tbe_dec.c | 17 +- lib_dec/swb_tbe_dec_fx.c | 2 + lib_dec/tcx_utils_dec_fx.c | 1 + lib_dec/updt_dec_fx.c | 19 +- lib_dec/voiced_dec_fx.c | 32 +- lib_enc/ivas_agc_enc.c | 181 +-- lib_enc/ivas_enc.c | 51 +- lib_enc/ivas_lfe_enc.c | 433 ++++++++ lib_enc/ivas_stat_enc.h | 4 + lib_enc/swb_bwe_enc_lr_fx.c | 12 +- lib_rend/ivas_crend.c | 53 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 93 +- lib_rend/ivas_dirac_decorr_dec.c | 480 +++++++- lib_rend/ivas_dirac_onsets_dec.c | 214 +++- lib_rend/ivas_dirac_output_synthesis_dec.c | 627 +++++++---- lib_rend/ivas_prot_rend.h | 42 +- lib_rend/ivas_reflections.c | 201 +++- lib_rend/ivas_reverb.c | 356 +++++- lib_rend/ivas_rotation.c | 19 +- lib_rend/ivas_shoebox.c | 7 +- lib_rend/ivas_stat_rend.h | 69 +- lib_rend/ivas_td_decorr.c | 8 +- lib_rend/ivas_vbap.c | 2 +- lib_rend/lib_rend.c | 2 +- 88 files changed, 5669 insertions(+), 2726 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 2e99561e7..b0a482d1c 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -127,6 +127,8 @@ #define ONE_IN_Q30 1073741824 #define ONE_IN_Q31 0x7fffffff #define MINUS_ONE_IN_Q31 -2147483648 +#define TWO_IN_Q29 1073741824 +#define FOUR_IN_Q28 1073741824 #define MAX_WORD16 32767 #define ONE_IN_Q62 (Word64)0x4000000000000000 @@ -2991,7 +2993,8 @@ enum #define SYNC_BAD_FRAME (UWord16) 0x6B20 /* synchronization word of a "bad" frame */ #define G192_BIN0 (UWord16) 0x007F /* binary "0" according to ITU-T G.192 */ #define G192_BIN1 (UWord16) 0x0081 /* binary "1" according to ITU-T G.192 */ - +#define DEGREE_180 (Word32)(180.0 *ONE_IN_Q23) +#define DEGREE_360 (Word32)(360.0 *ONE_IN_Q23) extern const Word16 Idx2Freq_Tbl[]; #if 0 //TO do add in rom_com diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index d53a92951..316c28dc9 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -443,7 +443,7 @@ void enhancer_ivas_fx( sc = 6; move16(); - gain_code_hi = round_fx(L_shl(L_tmp, add(Q_exc, 3))); /* in Q_exc */ + gain_code_hi = extract_h(L_shl_sat(L_tmp, add(Q_exc, 3))); /* in Q_exc */ /*------------------------------------------------------------* * pitch enhancer @@ -458,7 +458,7 @@ void enhancer_ivas_fx( /* Copy(code, exc2, L_SUBFR) */ FOR(i = 0; i < L_SUBFR; i++) { - pt_exc2[i] = round_fx(L_shl(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */ + pt_exc2[i] = extract_h(L_shl_sat(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */ } } ELSE diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index fe70ad299..b07d1cf6b 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -1126,7 +1126,80 @@ void SynthesisSTFT_dirac_flt( return; } +#ifdef IVAS_FLOAT_FIXED +void SynthesisSTFT_dirac_fx( + Word32 *fftBuffer, /* i : FFT bins */ + Word32 *timeDomainOutput, + Word32 *olapBuffer, + const Word16 *olapWin, + const Word16 samples_out, + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +) +{ + Word16 i; + Word32 buf[M + 1 + 320], tmp; + + /* Perform IFFT */ + RFFTN_fx( fftBuffer, hFdCngCom->fftSineTab_fx, hFdCngCom->fftlen, 1 ); + + /* Handle overlap in P/S domain for stereo */ + Copy32( olapBuffer + hFdCngCom->frameSize, olapBuffer, hFdCngCom->frameSize ); + set32_fx( olapBuffer + hFdCngCom->frameSize, 0, hFdCngCom->frameSize ); /*olapBuffer, fftBuffer, olapWin*/ + + FOR ( i = shr(hFdCngCom->frameSize, 2); i < i_mult(3, shr(hFdCngCom->frameSize, 2)); i++ ) + { + olapBuffer[i] = L_add(olapBuffer[i], Mpy_32_16_1(fftBuffer[i], olapWin[i - hFdCngCom->frameSize / 4])); + } + FOR ( ; i < i_mult(5, shr(hFdCngCom->frameSize, 2)); i++ ) + { + olapBuffer[i] = fftBuffer[i]; move32(); + } + + FOR ( ; i < i_mult(7, shr(hFdCngCom->frameSize, 2)); i++ ) + { + olapBuffer[i] = fftBuffer[i]; move32(); + } + + FOR ( ; i < hFdCngCom->fftlen; i++ ) + { + olapBuffer[i] = 0; move32(); + } + + Word32 fftScale = 0; move32(); + SWITCH(hFdCngCom->fftlen) + { + case 640: + fftScale = FFT_SCALING_640; move32(); + break; + case 512: + fftScale = FFT_SCALING_512; move32(); + break; + default: + assert(!"Not supported FFT length!"); + } + + /* Get time-domain signal */ + v_multc_fixed(olapBuffer + hFdCngCom->frameSize / 4, fftScale, timeDomainOutput, samples_out); // Q_in - 9 + + /* Get excitation */ + v_multc_fixed(olapBuffer + (hFdCngCom->frameSize / 4) - (M + 1), fftScale, buf, M + 1 + hFdCngCom->frameSize); + tmp = buf[0]; + preemph_ivas_fx( buf + 1, PREEMPH_FAC, M + hFdCngCom->frameSize, &tmp ); + residu_ivas_fx( hFdCngCom->A_cng, Q13, M, buf + 1 + M, hFdCngCom->exc_cng_32fx, hFdCngCom->frameSize ); + /* update and window olapBuf if we have a output frame that is shorter than the default frame size...*/ + IF ( LT_16(samples_out, hFdCngCom->frameSize )) + { + Copy32( olapBuffer + samples_out, olapBuffer + hFdCngCom->frameSize, i_mult(3, shr(hFdCngCom->frameSize, 2))); + } + FOR ( i = i_mult(5, shr(hFdCngCom->frameSize, 2)); i < i_mult(7, shr(hFdCngCom->frameSize, 2)); i++ ) + { + olapBuffer[i] = Mpy_32_16_1(olapBuffer[i], olapWin[i - 3 * hFdCngCom->frameSize / 4]); + } + + return; +} +#endif /*------------------------------------------------------------------- * mhvals_flt() * diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index b3791bbba..cf3d63323 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -199,16 +199,16 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( 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_old_Aq_12_8 = 12, 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; + Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, Q_fer_samples = 0, + Q_cldfbAna_cldfb_state = 0, Q_cldfbBPF_cldfb_state = 0, Q_cldfbSyn_cldfb_state = 0, Q_cldfbSynHB_cldfb_state = 0, + Q_old_Aq_12_8 = 12, Q_pst_old_syn = 0, + delay_comp = 0, Q_loBuffer = 0; + Word16 Q_lsf_cng = Q_factor( 6400 ); Word16 Q_old_enr_LP = Q_factor( st->old_enr_LP_float ); 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, + Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_tbe_demph = 0, Q_tbe_premph = 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_fb_tbe_demph = 0, Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; if ( tofix ) @@ -233,21 +233,12 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( st->L_frame = extract_l( Mult_32_16( st->sr_core, 0x0290 ) ); st->preemph_fac = (Word16) floatToFixed( st->preemph_fac_float, 15 ); Q_syn = Q_factor_arr( st->syn_float, 17 ); - 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 ) { @@ -369,35 +360,24 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( 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, Q_old_Aq_12_8, 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 - } - floatToFixed_arr( st->lsf_cng_float, st->lsf_cng, Q_lsf_cng, M ); + //floatToFixed_arr( st->lsf_cng_float, st->lsf_cng, Q_lsf_cng, M ); 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_adaptive_mean_fx[i] = (Word16) floatToFixed( st->lsf_adaptive_mean[i] / 100, 8 ); - st->lsfoldbfi0_fx[i] = (Word16) floatToFixed( st->lsfoldbfi0[i] / 100, 8 ); - st->lsfoldbfi1_fx[i] = (Word16) floatToFixed( st->lsfoldbfi1[i] / 100, 8 ); - } + //FOR( i = 0; i < M; i++ ) + //{ + //st->lsf_adaptive_mean_fx[i] = (Word16) floatToFixed( st->lsf_adaptive_mean[i] / 100, 8 ); + //st->lsfoldbfi0_fx[i] = (Word16) floatToFixed( st->lsfoldbfi0[i] / 100, 8 ); + //st->lsfoldbfi1_fx[i] = (Word16) floatToFixed( st->lsfoldbfi1[i] / 100, 8 ); + //} IF( st->hTcxLtpDec ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); @@ -409,67 +389,37 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( } - floatToFixed_arr( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 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 ) { @@ -480,9 +430,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( } else { - 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; Q_syn = Q_factor_arr( st->syn_float, 17 ); hGrid = &hIGFInfo->grid[IGF_GRID_LB_NORM]; fixedToFloat_arr( &hGrid->whiteningThreshold[0][0], &hGrid->whiteningThreshold_flt[0][0], 13, IGF_MAX_TILES * 2 ); @@ -524,69 +471,38 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( } 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 ) @@ -723,17 +639,11 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( 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 ) { @@ -763,7 +673,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( Word16 scale_fac = norm_s( st->old_Aq_12_8_fx[0] ) - 2; 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, Q_old_Aq_12_8, M + 1 ); - st->tilt_code = fixedToFloat( st->tilt_code_fx, 15 ); IF( st->hBPF ) { Q_pst_old_syn = Q_syn; @@ -771,44 +680,22 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( 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 ); - fixedToFloat_arr( st->lsf_cng, st->lsf_cng_float, Q_lsf_cng, M ); 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->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_q_cng_float[i] = fixedToFloat( L_mult( st->lsf_q_cng[i], 100 ), 9 ); - st->old_lsf_q_cng_float[i] = fixedToFloat( L_mult( st->old_lsf_q_cng[i], 100 ), 9 ); - } - 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->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 ) ); + //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->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, 0 ); @@ -818,10 +705,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( { 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++ ) { @@ -859,10 +743,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( 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 ); - } } } } @@ -899,17 +779,15 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ); + Q_old_synth = 0, Q_syn = 0, Q_synth_history = 0, Q_old_exc = 0, Q_fer_samples = 0, + Q_cldfbAna_cldfb_state = 0, Q_cldfbBPF_cldfb_state = 0, Q_cldfbSyn_cldfb_state = 0, Q_cldfbSynHB_cldfb_state = 0, + Q_pst_old_syn = 0, + delay_comp = 0, Q_loBuffer = 0; + 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, + Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_tbe_demph = 0, Q_tbe_premph = 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_fb_tbe_demph = 0, Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; if ( tofix ) @@ -934,21 +812,12 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ) { @@ -1070,35 +939,17 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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_lsfbfi, 0 ); - st->lsfoldbfi0_fx[i] = (Word16) floatToFixed( st->lsfoldbfi0[i] * 2.56f / st->scale_lsfbfi, 0); - st->lsfoldbfi1_fx[i] = (Word16)floatToFixed(st->lsfoldbfi1[i] * 2.56f / st->scale_lsfbfi, 0 ); - } IF( st->hTcxLtpDec ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); @@ -1110,67 +961,37 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } - 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 ) { @@ -1183,8 +1004,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ); @@ -1226,69 +1045,38 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } 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 ) @@ -1433,17 +1221,11 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ) { @@ -1473,7 +1255,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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; @@ -1481,47 +1262,22 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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->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->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 ) ); + //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_lsfbfi); - st->lsfoldbfi1[i] = (float)st->lsfoldbfi1_fx[i] / (2.56f / st->scale_lsfbfi); - st->lsfoldbfi0[i] = (float)st->lsfoldbfi0_fx[i] / (2.56f / st->scale_lsfbfi); - } 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 ); @@ -1531,10 +1287,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( { 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++ ) { @@ -1572,10 +1325,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ); - } } } } @@ -1597,7 +1346,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ); @@ -1609,9 +1357,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( { 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 ) { @@ -1622,16 +1367,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ); + //floatToFixed_arr( st->lspold_uw_float, st->lspold_uw, Q15, M ); for ( int p = 0; p < 2 * NB_SUBFR16k + 2; p++ ) { @@ -1644,11 +1380,10 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ); + //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; @@ -1656,7 +1391,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ) { @@ -1677,14 +1411,9 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ); @@ -1692,17 +1421,8 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( { 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 ); @@ -1712,18 +1432,13 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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 ) { @@ -1769,8 +1484,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( { 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 ); @@ -1778,7 +1491,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( 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); @@ -1832,7 +1544,6 @@ void fixed_to_float_stereo_tcx_core_dec( { 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 ) ) @@ -1841,18 +1552,10 @@ void fixed_to_float_stereo_tcx_core_dec( { 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; @@ -1874,18 +1577,12 @@ void fixed_to_float_stereo_tcx_core_dec( { 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++ ) @@ -1894,14 +1591,6 @@ void fixed_to_float_stereo_tcx_core_dec( 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 ) @@ -1912,7 +1601,6 @@ void fixed_to_float_stereo_tcx_core_dec( 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; } @@ -1926,45 +1614,26 @@ void fixed_to_float_stereo_tcx_core_dec( { 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_lsfbfi); - st->lsfoldbfi1[p] = (float) st->lsfoldbfi1_fx[p] / ( 2.56f / st->scale_lsfbfi); - st->lsfoldbfi0[p] = (float) st->lsfoldbfi0_fx[p] / ( 2.56f / st->scale_lsfbfi); - 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; @@ -1976,13 +1645,7 @@ void fixed_to_float_stereo_tcx_core_dec( st->hTcxDec->q_synth_history_fx = 0; 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 ) { @@ -1991,24 +1654,16 @@ void fixed_to_float_stereo_tcx_core_dec( 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 && @@ -2111,7 +1766,6 @@ void fixed_to_float_stereo_tcx_core_dec( 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 ) ); } } } diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 978d32f39..dd9fd1662 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -50,9 +50,11 @@ #define _180_OVER_PI_Q25 1922527233 #define _180_OVER_PI_FX (Word32) (( 180.0f / EVS_PI ) *ONE_IN_Q10) #define PI_OVER_4_Q29 421657440 +#define _180_OVER_PI_Q9 ( 29335 ) #define PI_OVER_Q29 1686629760 #define Q31_0_99 2126008811 #define Q31_0_01 21474836 +#define PI_OVER_180_FX (Word32) (( EVS_PI / 180.0f ) * ONE_IN_Q31) #endif #define PI_OVER_4_Q29 421657440 #define PI_OVER_Q29 1686629760 @@ -983,6 +985,12 @@ typedef enum #define DIRAC_ONSET_ALPHA 0.95f #define DIRAC_ONSET_BETA 0.995f #define DIRAC_ONSET_GAIN 4.0f +#ifdef IVAS_FLOAT_FIXED +#define DIRAC_ONSET_ALPHA_FX 31129//Q15 +#define DIRAC_ONSET_BETA_FX 32604 //Q15 +#define ONE_DIRAC_ONSET_BETA_FX 163 //Q15 +#define DIRAC_ONSET_GAIN_FX 16384 //Q12 +#endif #define DELAY_DIRAC_ENC_CMP_NS 9500000L /* Delay to be compensated on DirAC encoder */ #define DELAY_DIRAC_SPAR_ENC_CMP_NS 500000L /* here we may set the 24 samples (at 48 kHz) additional delay to something else, leave as is for now*/ @@ -1501,6 +1509,12 @@ typedef enum #define IVAS_LFE_SHIFT_BITS 5 #define IVAS_LFE_BITRATE_5000 5000 #define IVAS_LFE_ABS_SUM_FLT_THR (0.000001f) + +#ifdef IVAS_FLOAT_FIXED +#define IVAS_LFE_ABS_SUM_FLT_THR_Q42 4398047 +#endif // IVAS_FLOAT_FIXED + + #define IVAS_ZERO_PAD_LEN_MULT_FAC (0.5f) #define IVAS_ZERO_PAD_LEN_MULT_FAC_fx 16384 //0.5*Q15 diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 79cbbeabb..49d0b5f9c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3198,13 +3198,11 @@ void mvr2r_inc_fixed_one( ); void mvr2r_inc_fixed( - const float x[], /* i : input vector */ const Word32 x_fx[], /* i : input vector */ - const int16_t x_inc, /* i : increment for vector x[] */ - float y[], /* o : output vector */ + const int16_t x_inc, /* i : increment for vector x[] */ Word32 y_fx[], /* o : output vector */ - const int16_t y_inc, /* i : increment for vector y[] */ - const int16_t n /* i : vector size */ + const int16_t y_inc, /* i : increment for vector y[] */ + const int16_t n /* i : vector size */ ); #endif void v_add_inc( @@ -3230,6 +3228,16 @@ void v_mult_inc_fx( const Word16 y_inc, /* i : increment for vector y[i] */ const Word16 N /* i : Vector length */ ); + +void v_add_inc_fx( + const Word32 x1[], /* i : Input vector 1 */ + const Word16 x_inc, /* i : Increment for input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 N /* i : Vector length */ +); #endif void v_mult_inc( @@ -3274,7 +3282,18 @@ void v_min_fx( Word16 *y_q_fx, const Word16 N /* i : Vector length */ ); + +void v_mult_inc_fixed( + const Word32 x1_fx[], /* i : Input vector 1 */ + const Word16 x1_inc, /* i : Increment for input vector 1 */ + const Word32 x2_fx[], /* i : Input vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 1 */ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 y_inc, /* i : increment for vector y[i] */ + const Word16 N /* i : Vector length */ +); #endif + void v_min( const float x1[], /* i : Input vector 1 */ const float x2[], /* i : Input vector 2 */ @@ -4275,7 +4294,14 @@ void generate_masking_noise_lb_dirac( const int16_t nCldfbTs, /* i : number of CLDFB slots that will be rendered */ const int16_t cna_flag /* i : CNA flag for LB and HB */ ); - +#ifdef IVAS_FLOAT_FIXED +void generate_masking_noise_lb_dirac_fx( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ + const Word16 cna_flag /* i : CNA flag for LB and HB */ +); +#endif #ifdef IVAS_FLOAT_FIXED void ivas_dirac_dec_close_fx( DIRAC_DEC_HANDLE *hDirAC_out @@ -4840,8 +4866,7 @@ void ivas_sba_mix_matrix_determiner_fx( const Word16 bfi, /* i : BFI flag */ const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix */ - Word16* Q_mixer_mat + const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix */ ); #endif // IVAS_FLOAT_FIXED @@ -5081,11 +5106,22 @@ void ivas_spar_dec_agc_pca_fx( const Word16 output_frame /* i : output frame length */ ); #endif +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_dec_set_render_map_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +); +#endif void ivas_spar_dec_set_render_map( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const int16_t nCldfbTs /* i : number of CLDFB time slots */ ); - +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_dec_set_render_params_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ +); +#endif void ivas_spar_dec_set_render_params( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t n_cldfb_slots /* i : number of cldfb slots in this frame */ @@ -5097,13 +5133,26 @@ void ivas_spar_dec_digest_tc( const int16_t nCldfbSlots, /* i : number of CLDFB slots */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); - +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 nCldfbSlots, /* i : number of CLDFB slots */ + const Word16 nSamplesForRendering /* i : number of samples provided */ +); +#endif void ivas_sba_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const int16_t nCldfbSlots, /* i : number of CLDFB slots */ const int16_t nSamplesForRendering /* i : number of samples provided */ ); - +#ifdef IVAS_FLOAT_FIXED +void ivas_sba_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nCldfbSlots, /* i : number of CLDFB slots */ + const Word16 nSamplesForRendering /* i : number of samples provided */ +); +#endif ivas_error ivas_sba_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -5343,8 +5392,7 @@ void ivas_spar_dec_gen_umx_mat_fx( const Word16 nchan_transport, /* i : number of transport channels */ const Word16 num_bands_out, /* i : number of output bands */ const Word16 bfi, /* i : bad frame indicator */ - const Word16 num_md_sub_frames, - Word16 * Q_mixer_mat + const Word16 num_md_sub_frames ); #endif // IVAS_FLOAT_FIXED @@ -6518,6 +6566,17 @@ void ivas_lfe_enc( BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_enc_fx( + LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ + Word32 data_lfe_ch[], /* i : input LFE signal */ + Word16 q_data_lfe_ch, /* i : Q of input LFE signal */ + const Word16 input_frame, /* i : input frame length per channel */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +); +#endif // IVAS_FLOAT_FIXED + + ivas_error ivas_create_lfe_dec( LFE_DEC_HANDLE *hLFE_out, /* o : IVAS LFE decoder structure */ const int32_t output_Fs, /* i : output sampling rate */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f191f8026..543c1ab50 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1328,8 +1328,8 @@ void stereo_icBWE_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs */ Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs */ - const Word32 *fb_synth_ref, /* i : ref. high-band synthesis 16-20 kHz */ - const Word32 *voice_factors, /* i : voicing factors */ + const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz */ + const Word16 *voice_factors_fx, /* i : voicing factors */ const Word16 output_frame, /* i : frame length */ Word16 *Q_syn ); @@ -1959,6 +1959,18 @@ void TDREND_SPATIAL_VecMapToNewCoordSystem_fx( Word32 *LisRelPosAbs /* o : Transformed vector ignoring orientation */ ); +void ivas_mct_side_bits_fx( + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ + const Word16 nCPE, /* i : number of CPEs */ + Decoder_State *st0, /* i : decoder handle for Bstr */ + const Word16 bfi, /* i : BFI flag */ + UWord16 *bitstream, /* o : bitstream indices */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +); + + #endif // IVAS_FLOAT_FIXED #endif diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index ed61b7ade..727320628 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -269,49 +269,49 @@ void mvr2r_inc_fixed_one( } void mvr2r_inc_fixed( - const float x[], /* i : input vector */ - const Word32 x_fx[], /* i : input vector */ - const Word16 x_inc, /* i : increment for vector x[] */ - float y[], /* o : output vector */ - Word32 y_fx[], /* o : output vector */ - const Word16 y_inc, /* i : increment for vector y[] */ - const Word16 n /* i : vector size */ + const Word32 x_fx[], /* i : input vector */ + const Word16 x_inc, /* i : increment for vector x[] */ + Word32 y_fx[], /* o : output vector */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 n /* i : vector size */ ) { Word16 i; Word16 ix; Word16 iy; - IF (n <= 0) + IF( LE_16( n, 0 ) ) { /* cannot transfer vectors with size 0 */ return; } - IF (y_fx < x_fx) + IF( y_fx < x_fx ) { ix = 0; + move16(); iy = 0; - FOR (i = 0; i < n; i++) + move16(); + FOR( i = 0; i < n; i++ ) { y_fx[iy] = x_fx[ix]; - y[iy] = x[ix]; + move32(); - ix += x_inc; - iy += y_inc; + ix = add( ix, x_inc ); + iy = add( iy, y_inc ); } } ELSE { - ix = (n - 1) * x_inc; - iy = (n - 1) * y_inc; - FOR (i = n - 1; i >= 0; i--) + ix = i_mult( sub( n, 1 ), x_inc ); + iy = i_mult( sub( n, 1 ), y_inc ); + FOR( i = n - 1; i >= 0; i-- ) { y_fx[iy] = x_fx[ix]; - y[iy] = x[ix]; + move32(); - ix -= x_inc; - iy -= y_inc; + ix = sub( ix, x_inc ); + iy = sub( iy, y_inc ); } } @@ -395,6 +395,33 @@ void v_add_inc( return; } +#ifdef IVAS_FLOAT_FIXED +// for same q// +void v_add_inc_fx( + const Word32 x1[], /* i : Input vector 1 */ + const Word16 x_inc, /* i : Increment for input vector 1 */ + const Word32 x2[], /* i : Input vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 2 */ + Word32 y[], /* o : Output vector that contains vector 1 + vector 2 */ + const Word16 y_inc, /* i : increment for vector y[] */ + const Word16 N /* i : Vector length */ +) +{ + Word16 i; + Word16 ix1 = 0; + Word16 ix2 = 0; + Word16 iy = 0; + Word16 e_result; + FOR( i = 0; i < N; i++ ) + { + y[iy] = L_add(x1[ix1], x2[ix2]); + ix1 += x_inc; + ix2 += x2_inc; + iy += y_inc; + } + return; +} +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* @@ -433,7 +460,36 @@ void v_mult_inc_fx( return; } + +//when buffers have constant q/ +void v_mult_inc_fixed( + const Word32 x1_fx[], /* i : Input vector 1 */ + const Word16 x1_inc, /* i : Increment for input vector 1 */ + const Word32 x2_fx[], /* i : Input vector 2 */ + const Word16 x2_inc, /* i : Increment for input vector 1 */ + Word32 y_fx[], /* o : Output vector that contains vector 1 .* vector 2 */ + const Word16 y_inc, /* i : increment for vector y[i] */ + const Word16 N /* i : Vector length */ +) +{ + Word16 i; + Word16 ix1 = 0; + Word16 ix2 = 0; + Word16 iy = 0; + + FOR(i = 0; i < N; i++) + { + y_fx[iy] = Mpy_32_32(x1_fx[ix1], x2_fx[ix2]); + + ix1 = add(ix1, x1_inc); + ix2 = add(ix2, x2_inc); + iy = add(iy, y_inc); + } + + return; +} #endif + /*-------------------------------------------------------------------* * v_mult_inc() * diff --git a/lib_com/prot.h b/lib_com/prot.h index 7ff6c5cf4..3d00ba7ee 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -8891,7 +8891,16 @@ void SynthesisSTFT_dirac_flt( const int16_t samples_out, HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ ); - +#ifdef IVAS_FLOAT_FIXED +void SynthesisSTFT_dirac_fx( + Word32 *fftBuffer, /* i : FFT bins */ + Word32 *timeDomainOutput, + Word32 *olapBuffer, + const Word16 *olapWin, + const Word16 samples_out, + HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ +); +#endif void generate_masking_noise_dirac( HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index b55135baf..b91a07fb6 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -1750,7 +1750,7 @@ void noise_extr_corcod_fx( Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ - Word16 prev_hqswb_clas_fx, /* i : Q0 classification information */ + Word16 prev_hqswb_clas, /* i : Q0 classification information */ Word16 *prev_ni_ratio_fx, /* i : Q15 noise paraemeter */ Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ ); @@ -1868,11 +1868,11 @@ void updat_prev_frm_fx( Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ const Word16 is_transient_fx, /* i: signal class information */ Word16 hqswb_clas_fx, /* i: signal class information */ - Word16 *prev_hqswb_clas_fx, /* o: update signal class information */ + Word16 *prev_hqswb_clas, /* o: update signal class information */ Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ - Word16 *prev_frm_hfe2_fx, /* o: update harmonics */ - Word16 *prev_stab_hfe2_fx, /* o: update harmonics */ + Word16 *prev_frm_hfe2, /* o: update harmonics */ + Word16 *prev_stab_hfe2, /* o: update harmonics */ Word16 bws_cnt /* i: band width detector */ ); @@ -8131,8 +8131,8 @@ void generate_comfort_noise_dec_hf_ivas_fx( Word16 lowlength_fx, /* i : Lowband Length */ Word16 highlength_fx, /* i : Highband Length */ const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ Word16 band_width_fx[], /* i : subband bandwidth */ const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ Word16 *ni_seed_fx /* i/o: random seed */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index dde27ce88..ce5353b20 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -461,7 +461,6 @@ typedef struct Word16 exp_cldfb_periodog; Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ - //Word16 q_cngNoiseLevel; Word16 cngNoiseLevelExp; int16_t seed; /* Seed memory (for random function) */ diff --git a/lib_com/swb_bwe_com_lr_fx.c b/lib_com/swb_bwe_com_lr_fx.c index 35e0f39f8..e44c342df 100644 --- a/lib_com/swb_bwe_com_lr_fx.c +++ b/lib_com/swb_bwe_com_lr_fx.c @@ -2001,7 +2001,7 @@ void noise_extr_corcod_fx( Word16 sspectra_diff_fx[], /* o : Qss non tonal infomration for gap filling */ Word16 sspectra_ni_fx[], /* o : Qss smoothed core coder */ const Word16 fLenLow_fx, /* i : Q0 low frequency bands width */ - Word16 prev_hqswb_clas_fx, /* i : Q0 classification information */ + Word16 prev_hqswb_clas, /* i : Q0 classification information */ Word16 *prev_ni_ratio_fx, /* i : Q15 noise parameter */ Word16 *Qss /* o : Q0 Q value for sspectra_*_fx */ ) @@ -2106,7 +2106,7 @@ void noise_extr_corcod_fx( ni_ratio_cur_fx = mult_r(ni_ratio_cur_fx, br_adj_fx); } - IF(EQ_16(prev_hqswb_clas_fx, HQ_HARMONIC)) + IF(EQ_16(prev_hqswb_clas, HQ_HARMONIC)) { IF(GT_16(ni_ratio_cur_fx, *prev_ni_ratio_fx)) { @@ -3328,11 +3328,11 @@ void updat_prev_frm_fx( Word16 bwidth_fx, /* i: NB/WB/SWB indicator */ const Word16 is_transient_fx, /* i: signal class information */ Word16 hqswb_clas_fx, /* i: signal class information */ - Word16 *prev_hqswb_clas_fx, /* o: update signal class information */ + Word16 *prev_hqswb_clas, /* o: update signal class information */ Word16 prev_SWB_peak_pos_fx[], /* o: update core coder last coded peaks*/ Word16 prev_SWB_peak_pos_tmp_fx[], /* o: update core coder last coded peaks*/ - Word16 *prev_frm_hfe2_fx, /* o: update harmonics */ - Word16 *prev_stab_hfe2_fx, /* o: update harmonics */ + Word16 *prev_frm_hfe2, /* o: update harmonics */ + Word16 *prev_stab_hfe2, /* o: update harmonics */ Word16 bws_cnt_fx /* i: band width detector */ ) { @@ -3395,19 +3395,19 @@ void updat_prev_frm_fx( IF((EQ_32(L_bwe_br, HQ_16k40) || EQ_32(L_bwe_br, HQ_13k20)) && EQ_16(bwidth_fx, SWB)) { - *prev_hqswb_clas_fx = hqswb_clas_fx; + *prev_hqswb_clas = hqswb_clas_fx; move16(); IF(NE_16(hqswb_clas_fx, HQ_HARMONIC)) { - *prev_frm_hfe2_fx = 0; + *prev_frm_hfe2 = 0; move16(); - *prev_stab_hfe2_fx = 0; + *prev_stab_hfe2 = 0; move16(); } } ELSE { - *prev_hqswb_clas_fx = is_transient_fx; + *prev_hqswb_clas = is_transient_fx; move16(); } diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index 7d21bf4bb..ac61b2fcd 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -215,13 +215,13 @@ void HQ_FEC_processing_fx( } /* Sign prediction in 4-dim bands up to 1.6 kHz*/ - IF (hHQ_core->old_is_transient_fx[1] == 0) + IF (hHQ_core->old_is_transient[1] == 0) { - IF (hHQ_core->old_is_transient_fx[2] == 0) + IF (hHQ_core->old_is_transient[2] == 0) { FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) { - IF (GE_16(hHQ_nbfec->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES)) + IF (GE_16(hHQ_nbfec->prev_sign_switch[sfm], HQ_FEC_SIGN_THRES)) { FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) { @@ -235,7 +235,7 @@ void HQ_FEC_processing_fx( { FOR (sfm = 0; sfm < HQ_FEC_SIGN_SFM; sfm++) { - IF (GE_16(hHQ_nbfec->prev_sign_switch_fx[sfm], HQ_FEC_SIGN_THRES_TRANS)) + IF (GE_16(hHQ_nbfec->prev_sign_switch[sfm], HQ_FEC_SIGN_THRES_TRANS)) { FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) { @@ -250,7 +250,7 @@ void HQ_FEC_processing_fx( { FOR (i = RANDOM_START*8; i < output_frame; i++) { - IF(Random(&hHQ_nbfec->HQ_FEC_seed_fx) < 0) + IF(Random(&hHQ_nbfec->HQ_FEC_seed) < 0) { t_audio_q_fx[i] = L_negate(t_audio_q_fx[i]); move32(); @@ -260,7 +260,7 @@ void HQ_FEC_processing_fx( } ELSE { - IF(hHQ_core->old_is_transient_fx[1] ) /* hangover */ + IF(hHQ_core->old_is_transient[1] ) /* hangover */ { FOR (i=0; i < output_frame; i++) { @@ -281,7 +281,7 @@ void HQ_FEC_processing_fx( FOR (i = RANDOM_START*8; i < output_frame; i++) { hHQ_nbfec->old_coeffs_fx[i] = Mult_32_16(hHQ_nbfec->old_coeffs_fx[i], 23170); - IF (Random(&hHQ_nbfec->HQ_FEC_seed_fx) < 0) + IF (Random(&hHQ_nbfec->HQ_FEC_seed) < 0) { t_audio_q_fx[i] = L_negate(hHQ_nbfec->old_coeffs_fx[i]); move32(); @@ -390,7 +390,7 @@ void HQ_FEC_processing_fx( } /* Scaling for core band */ - FEC_scaling_fx(hHQ_nbfec->old_coeffs_fx, t_audio_q_fx, hHQ_nbfec->Norm_gain_fx, &hHQ_nbfec->HQ_FEC_seed_fx, nb_sfm, sfm_start, sfm_end ); + FEC_scaling_fx(hHQ_nbfec->old_coeffs_fx, t_audio_q_fx, hHQ_nbfec->Norm_gain_fx, &hHQ_nbfec->HQ_FEC_seed, nb_sfm, sfm_start, sfm_end ); } @@ -437,16 +437,16 @@ void ivas_HQ_FEC_Mem_update_fx( IF( is_transient ) { - set16_fx( hHQ_nbfec->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM ); - set16_fx( hHQ_nbfec->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM ); + set16_fx( hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM ); + set16_fx( hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM ); } ELSE { FOR( j = 0; j < HQ_FEC_SIGN_SFM; j++ ) { - hHQ_nbfec->prev_sign_switch_fx[j] = hHQ_nbfec->prev_sign_switch_2_fx[j]; + hHQ_nbfec->prev_sign_switch[j] = hHQ_nbfec->prev_sign_switch_2[j]; move16(); - hHQ_nbfec->prev_sign_switch_2_fx[j] = 0; + hHQ_nbfec->prev_sign_switch_2[j] = 0; move16(); FOR( i = 0; i < HQ_FEC_BAND_SIZE; i++ ) @@ -456,9 +456,9 @@ void ivas_HQ_FEC_Mem_update_fx( test(); IF( ( GT_32( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) && LT_32( t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) ) || ( LT_32( hHQ_nbfec->old_coeffs_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) && GT_32( t_audio_q_fx[i + j * HQ_FEC_BAND_SIZE], 0 ) ) ) { - hHQ_nbfec->prev_sign_switch_fx[j] = add( hHQ_nbfec->prev_sign_switch_fx[j], 1 ); + hHQ_nbfec->prev_sign_switch[j] = add( hHQ_nbfec->prev_sign_switch[j], 1 ); move16(); - hHQ_nbfec->prev_sign_switch_2_fx[j] = add( hHQ_nbfec->prev_sign_switch_2_fx[j], 1 ); + hHQ_nbfec->prev_sign_switch_2[j] = add( hHQ_nbfec->prev_sign_switch_2[j], 1 ); move16(); } } @@ -564,13 +564,13 @@ void ivas_HQ_FEC_Mem_update_fx( } /* Apply Hysteresis to prevent frequent mode changing */ - IF( EQ_16( hHQ_nbfec->stat_mode_old_fx, stat_mode_curr ) ) + IF( EQ_16( hHQ_nbfec->stat_mode_old, stat_mode_curr ) ) { - hHQ_nbfec->stat_mode_out_fx = stat_mode_curr; + hHQ_nbfec->stat_mode_out = stat_mode_curr; move16(); } - hHQ_nbfec->stat_mode_old_fx = stat_mode_curr; + hHQ_nbfec->stat_mode_old = stat_mode_curr; move16(); /* Find max. band index (Minimum value means maximum energy) */ @@ -647,24 +647,24 @@ void ivas_HQ_FEC_Mem_update_fx( test(); test(); test(); - IF( ( LT_16( Min_ind, 5 ) ) && ( LT_16( abs_s( sub( Min_ind, hHQ_nbfec->old_Min_ind_fx ) ), 2 ) ) && ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_90P_fx ) ) && ( !st_fx->bfi ) && ( !st_fx->prev_bfi ) && ( !st_fx->prev_old_bfi ) && ( !is_transient ) && ( !hHQ_core->old_is_transient_fx[1] ) && ( EQ_16( hHQ_nbfec->prev_last_core, HQ_CORE ) ) && ( EQ_16( st_fx->last_core, HQ_CORE ) ) ) + IF( ( LT_16( Min_ind, 5 ) ) && ( LT_16( abs_s( sub( Min_ind, hHQ_nbfec->old_Min_ind ) ), 2 ) ) && ( LT_16( hHQ_nbfec->diff_energy_fx, ED_THRES_90P_fx ) ) && ( !st_fx->bfi ) && ( !st_fx->prev_bfi ) && ( !st_fx->prev_old_bfi ) && ( !is_transient ) && ( !hHQ_core->old_is_transient[1] ) && ( EQ_16( hHQ_nbfec->prev_last_core, HQ_CORE ) ) && ( EQ_16( st_fx->last_core, HQ_CORE ) ) ) { - hHQ_nbfec->phase_mat_flag_fx = 1; + hHQ_nbfec->phase_mat_flag = 1; move16(); test(); IF( ( EQ_16( Min_ind, 0 ) ) && ( LT_16( Max_ind, 3 ) ) ) { - hHQ_nbfec->phase_mat_flag_fx = 0; + hHQ_nbfec->phase_mat_flag = 0; move16(); } } ELSE { - hHQ_nbfec->phase_mat_flag_fx = 0; + hHQ_nbfec->phase_mat_flag = 0; move16(); } - hHQ_nbfec->old_Min_ind_fx = Min_ind; + hHQ_nbfec->old_Min_ind = Min_ind; move16(); FOR( i = 0; i < L_FRAME8k; i++ ) @@ -674,11 +674,11 @@ void ivas_HQ_FEC_Mem_update_fx( } } - hHQ_core->old_is_transient_fx[2] = hHQ_core->old_is_transient_fx[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; move16(); - hHQ_core->old_is_transient_fx[1] = hHQ_core->old_is_transient_fx[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; move16(); - hHQ_core->old_is_transient_fx[0] = is_transient; + hHQ_core->old_is_transient[0] = is_transient; move16(); return; @@ -726,16 +726,16 @@ void HQ_FEC_Mem_update_fx( IF (is_transient) { - set16_fx(hHQ_nbfec->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM); - set16_fx(hHQ_nbfec->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM); + set16_fx(hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM); + set16_fx(hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM); } ELSE { FOR (j = 0; j < HQ_FEC_SIGN_SFM; j++) { - hHQ_nbfec->prev_sign_switch_fx[j] = hHQ_nbfec->prev_sign_switch_2_fx[j]; + hHQ_nbfec->prev_sign_switch[j] = hHQ_nbfec->prev_sign_switch_2[j]; move16(); - hHQ_nbfec->prev_sign_switch_2_fx[j] = 0; + hHQ_nbfec->prev_sign_switch_2[j] = 0; move16(); FOR (i = 0; i < HQ_FEC_BAND_SIZE; i++) @@ -746,9 +746,9 @@ void HQ_FEC_Mem_update_fx( IF ((hHQ_nbfec->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]>0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]<0) || (hHQ_nbfec->old_coeffs_fx[i+j*HQ_FEC_BAND_SIZE]<0 && t_audio_q_fx[i+j*HQ_FEC_BAND_SIZE]>0)) { - hHQ_nbfec->prev_sign_switch_fx[j] = add(hHQ_nbfec->prev_sign_switch_fx[j], 1); + hHQ_nbfec->prev_sign_switch[j] = add(hHQ_nbfec->prev_sign_switch[j], 1); move16(); - hHQ_nbfec->prev_sign_switch_2_fx[j] = add(hHQ_nbfec->prev_sign_switch_2_fx[j], 1); + hHQ_nbfec->prev_sign_switch_2[j] = add(hHQ_nbfec->prev_sign_switch_2[j], 1); move16(); } } @@ -855,13 +855,13 @@ void HQ_FEC_Mem_update_fx( } /* Apply Hysteresis to prevent frequent mode changing */ - IF(EQ_16(hHQ_nbfec->stat_mode_old_fx, stat_mode_curr)) + IF(EQ_16(hHQ_nbfec->stat_mode_old, stat_mode_curr)) { - hHQ_nbfec->stat_mode_out_fx = stat_mode_curr; + hHQ_nbfec->stat_mode_out = stat_mode_curr; move16(); } - hHQ_nbfec->stat_mode_old_fx = stat_mode_curr; + hHQ_nbfec->stat_mode_old = stat_mode_curr; move16(); /* Find max. band index (Minimum value means maximum energy) */ @@ -937,25 +937,25 @@ void HQ_FEC_Mem_update_fx( test(); test(); test(); - IF ((LT_16(Min_ind, 5))&&(LT_16(abs_s(sub(Min_ind, hHQ_nbfec->old_Min_ind_fx)),2))&&(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_90P_fx))&&(!st_fx->bfi)&&(!st_fx->prev_bfi)&&(!st_fx->prev_old_bfi) - &&(!is_transient)&&(!hHQ_core->old_is_transient_fx[1]) && (hHQ_nbfec->prev_last_core==HQ_CORE) && (st_fx->last_core==HQ_CORE)) + IF ((LT_16(Min_ind, 5))&&(LT_16(abs_s(sub(Min_ind, hHQ_nbfec->old_Min_ind)),2))&&(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_90P_fx))&&(!st_fx->bfi)&&(!st_fx->prev_bfi)&&(!st_fx->prev_old_bfi) + &&(!is_transient)&&(!hHQ_core->old_is_transient[1]) && (hHQ_nbfec->prev_last_core==HQ_CORE) && (st_fx->last_core==HQ_CORE)) { - hHQ_nbfec->phase_mat_flag_fx = 1; + hHQ_nbfec->phase_mat_flag = 1; move16(); test(); if ((Min_ind == 0)&&(LT_16(Max_ind, 3))) { - hHQ_nbfec->phase_mat_flag_fx = 0; + hHQ_nbfec->phase_mat_flag = 0; move16(); } } ELSE { - hHQ_nbfec->phase_mat_flag_fx = 0; + hHQ_nbfec->phase_mat_flag = 0; move16(); } - hHQ_nbfec->old_Min_ind_fx = Min_ind; + hHQ_nbfec->old_Min_ind = Min_ind; move16(); } @@ -965,11 +965,11 @@ void HQ_FEC_Mem_update_fx( move32(); } - hHQ_core->old_is_transient_fx[2] = hHQ_core->old_is_transient_fx[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; move16(); - hHQ_core->old_is_transient_fx[1] = hHQ_core->old_is_transient_fx[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; move16(); - hHQ_core->old_is_transient_fx[0] = is_transient; + hHQ_core->old_is_transient[0] = is_transient; move16(); return; @@ -1228,7 +1228,7 @@ static Word16 FEC_phase_matching_fx( } set16_fx(ImdctOutWin_fx, 0, 2*L); - pos = Search_Max_Corr_fx(st_fx->old_auOut_2fr_fx, st_fx->old_Min_ind_fx, L); + pos = Search_Max_Corr_fx(st_fx->old_auOut_2fr_fx, st_fx->old_Min_ind, L); IF (pos == 0) { @@ -1815,36 +1815,36 @@ void time_domain_FEC_HQ_fx( test(); test(); test(); - IF( (EQ_16(st_fx->nbLostCmpt, 1))&&(EQ_16(hHQ_nbfec->phase_mat_flag_fx,1))&&(EQ_16(hHQ_nbfec->phase_mat_next_fx,0))) + IF( (EQ_16(st_fx->nbLostCmpt, 1))&&(EQ_16(hHQ_nbfec->phase_mat_flag,1))&&(EQ_16(hHQ_nbfec->phase_mat_next,0))) { IF (FEC_phase_matching_fx(hHQ_nbfec, wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx) ) { /* window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 ); */ window_ola_fx(wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, ALDO_WINDOW, ALDO_WINDOW, 0, 0, 0 ); - hHQ_nbfec->phase_mat_next_fx = 0; + hHQ_nbfec->phase_mat_next = 0; move16(); } ELSE { - hHQ_nbfec->phase_mat_next_fx = 1; + hHQ_nbfec->phase_mat_next = 1; move16(); *Q_synth = 0; move16(); } } - ELSE IF((EQ_16(st_fx->prev_bfi, 1))&&(st_fx->bfi==0)&&(EQ_16(hHQ_nbfec->phase_mat_next_fx,1))) + ELSE IF((EQ_16(st_fx->prev_bfi, 1))&&(st_fx->bfi==0)&&(EQ_16(hHQ_nbfec->phase_mat_next,1))) { FEC_phase_matching_nextgood_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, mean_en_high_fx); - hHQ_nbfec->phase_mat_next_fx = 0; + hHQ_nbfec->phase_mat_next = 0; move16(); *Q_synth = 0; move16(); } - ELSE IF((EQ_16(st_fx->prev_bfi, 1))&&(EQ_16(st_fx->bfi,1))&&(EQ_16(hHQ_nbfec->phase_mat_next_fx,1))) + ELSE IF((EQ_16(st_fx->prev_bfi, 1))&&(EQ_16(st_fx->bfi,1))&&(EQ_16(hHQ_nbfec->phase_mat_next,1))) { FEC_phase_matching_burst_fx( wtda_audio_fx, out_fx, hHQ_core->old_out_fx, hHQ_nbfec->old_out_pha_fx, hHQ_nbfec->prev_oldauOut_fx); - hHQ_nbfec->phase_mat_next_fx = 1; + hHQ_nbfec->phase_mat_next = 1; move16(); *Q_synth = 0; move16(); @@ -1856,7 +1856,7 @@ void time_domain_FEC_HQ_fx( IF (st_fx->bfi == 0 && EQ_16(st_fx->prev_bfi, 1)) { test(); - IF((EQ_16(hHQ_nbfec->stat_mode_out_fx, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx)))/* Q11 */ + IF((EQ_16(hHQ_nbfec->stat_mode_out, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx)))/* Q11 */ { Word16 tmp; @@ -1879,20 +1879,20 @@ void time_domain_FEC_HQ_fx( { /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0); */ window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); } } ELSE /* if(st->bfi == 1) */ { test(); - IF( (EQ_16(hHQ_nbfec->stat_mode_out_fx, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx))) + IF( (EQ_16(hHQ_nbfec->stat_mode_out, 1))||(LT_16(hHQ_nbfec->diff_energy_fx,ED_THRES_50P_fx))) { /* if( window_ola_bfi( wtda_audio, out, st->oldIMDCTout, st->old_out, output_frame, st->prev_oldauOut, N_LEAD_NB) ) */ IF( Repetition_smoothing_fx( wtda_audio_fx, out_fx, hHQ_nbfec->oldIMDCTout_fx, hHQ_core->old_out_fx, output_frame, hHQ_nbfec->prev_oldauOut_fx, N_LEAD_NB) ) { /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0);*/ window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); } ELSE { @@ -1904,10 +1904,10 @@ void time_domain_FEC_HQ_fx( { /*window_ola( wtda_audio, out, st->old_out, output_frame, 0, 0, 0 );*/ window_ola_fx( wtda_audio_fx, out_fx, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); } } - hHQ_nbfec->phase_mat_next_fx = 0; + hHQ_nbfec->phase_mat_next = 0; move16(); } diff --git a/lib_dec/FEC_fx.c b/lib_dec/FEC_fx.c index 6098e531b..df091bd70 100644 --- a/lib_dec/FEC_fx.c +++ b/lib_dec/FEC_fx.c @@ -32,7 +32,7 @@ void gain_dec_bfi_fx(Word16 *past_qua_en); /* _ (Word16) st_fx->bfi_pitch_fx : LP filter coefficient */ /* _ (Word16) st_fx->upd_cnt : FEC counter of frames since last update*/ /* _ (Word16) st_fx->last_coder_type: previous coder type */ -/* _ (Word16) st_fx->Last_GSC_pit_band_idx_fx: AC mode (GSC)Last pitch band index*/ +/* _ (Word16) st_fx->Last_GSC_pit_band_idx: AC mode (GSC)Last pitch band index*/ /* _ (Word16) st_fx->stab_fac_fx : LSF stability factor Q15 */ /* _ (Word16) st_fx->tilt_code : tilt of code Q15 */ /* _ (Word16) st_fx->last_voice_factor : coding type Q12 */ @@ -292,7 +292,7 @@ void FEC_exc_estim_fx( ELSE IF( EQ_16(st_fx->last_coder_type,AUDIO)||EQ_16(st_fx->last_good,INACTIVE_CLAS)) { test(); - IF( hGSCDec->Last_GSC_pit_band_idx_fx > 0 && GT_16(st_fx->nbLostCmpt,1)) + IF( hGSCDec->Last_GSC_pit_band_idx > 0 && GT_16(st_fx->nbLostCmpt,1)) { alpha = 26214; move16(); @@ -392,7 +392,7 @@ void FEC_exc_estim_fx( test(); test(); IF( (GE_16(st_fx->last_good,UNVOICED_TRANSITION)&<_16(st_fx->last_good,INACTIVE_CLAS))|| - ( (EQ_16(st_fx->last_coder_type,AUDIO) || EQ_16(st_fx->last_good,INACTIVE_CLAS) ) && hGSCDec->Last_GSC_pit_band_idx_fx > 0) ) + ( (EQ_16(st_fx->last_coder_type,AUDIO) || EQ_16(st_fx->last_good,INACTIVE_CLAS) ) && hGSCDec->Last_GSC_pit_band_idx > 0) ) { pt_exc = exc; @@ -498,9 +498,9 @@ void FEC_exc_estim_fx( } test(); test(); - IF( (EQ_16(st_fx->last_coder_type,AUDIO)||EQ_16(st_fx->last_good,INACTIVE_CLAS))&& hGSCDec->Last_GSC_pit_band_idx_fx>0) + IF( (EQ_16(st_fx->last_coder_type,AUDIO)||EQ_16(st_fx->last_good,INACTIVE_CLAS))&& hGSCDec->Last_GSC_pit_band_idx>0) { - Diff_len = mfreq_loc_div_25[hGSCDec->Last_GSC_pit_band_idx_fx]; + Diff_len = mfreq_loc_div_25[hGSCDec->Last_GSC_pit_band_idx]; move16(); /* Transform to frequency domain */ @@ -538,10 +538,10 @@ void FEC_exc_estim_fx( move16(); /* Replication of the last spectrum, with a slight downscaling of its dynamic */ if (st_fx->element_mode == EVS_MONO) { - gsc_dec_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc); + gsc_dec_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc); } else { - gsc_dec_ivas_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx_fx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc); + gsc_dec_ivas_fx(st_fx, exc_dct_in, hGSCDec->Last_GSC_pit_band_idx, Diff_len, 0, st_fx->L_frame / L_SUBFR, st_fx->last_coder_type, &last_bin_fx, lsf_new, NULL, st_fx->Q_exc); } *tmp_noise = shr_r(st_fx->lp_gainc_fx,3); /*Q0*/ /* Transform back to time domain */ diff --git a/lib_dec/LD_music_post_filter_fx.c b/lib_dec/LD_music_post_filter_fx.c index e92b6cb04..819c72804 100644 --- a/lib_dec/LD_music_post_filter_fx.c +++ b/lib_dec/LD_music_post_filter_fx.c @@ -97,7 +97,7 @@ void LD_music_post_filter_fx * Find signal classification *------------------------------------------------------------------------*/ music_flag2 = stab_est_fx( LG_etot, hMusicPF->LDm_lt_diff_etot_fx, &hMusicPF->LDm_mem_etot_fx - , &hMusicPF->LDm_nb_thr_3_fx, &hMusicPF->LDm_nb_thr_1_fx, hMusicPF->LDm_thres_fx, &hMusicPF->LDm_last_music_flag_fx, 1 ); + , &hMusicPF->LDm_nb_thr_3, &hMusicPF->LDm_nb_thr_1, hMusicPF->LDm_thres_fx, &hMusicPF->LDm_last_music_flag, 1 ); test(); if ( LT_32(core_brate,ACELP_6k60)||NE_16(Last_coder_type,AUDIO)) @@ -107,16 +107,16 @@ void LD_music_post_filter_fx move16(); } - hMusicPF->last_nonfull_music_fx = add(hMusicPF->last_nonfull_music_fx,1); + hMusicPF->last_nonfull_music = add(hMusicPF->last_nonfull_music,1); move16(); if( LT_16(music_flag2,4)) { - hMusicPF->last_nonfull_music_fx = 0; + hMusicPF->last_nonfull_music = 0; move16(); } - hMusicPF->last_nonfull_music_fx = s_min( 51, hMusicPF->last_nonfull_music_fx); + hMusicPF->last_nonfull_music = s_min( 51, hMusicPF->last_nonfull_music); /*------------------------------------------------------------------------* * Remapping of bands @@ -281,7 +281,7 @@ void LD_music_post_filter_fx } } { - IF( GT_16(hMusicPF->last_nonfull_music_fx,40)) + IF( GT_16(hMusicPF->last_nonfull_music,40)) { max_ovf_2k = 5120; /*1.25 Q12*/ move16(); max_ovf_4k = 6144; /*1.5 Q12*/ move16(); @@ -360,7 +360,7 @@ void LD_music_post_filter_fx } } } - ELSE IF( GT_16(hMusicPF->last_nonfull_music_fx,25)) + ELSE IF( GT_16(hMusicPF->last_nonfull_music,25)) { /* When unsure on content type only slight clean-up allowed, no overshoot allowed */ FOR(; i < DCT_L_POST; i++) @@ -981,7 +981,7 @@ void music_postfilt_init( f_db = add(f_db, shr(1, add(e_db, 1))); hMusicPF->LDm_enh_min_ns_gain_fx = shl(f_db, e_db); - hMusicPF->LDm_last_music_flag_fx = 0; + hMusicPF->LDm_last_music_flag = 0; move16(); set16_fx(hMusicPF->LDm_lt_diff_etot_fx, 0, MAX_LT); @@ -994,9 +994,9 @@ void music_postfilt_init( hMusicPF->LDm_thres_fx[3] = TH_3_MIN_FX; move16(); - hMusicPF->LDm_nb_thr_1_fx = 0; + hMusicPF->LDm_nb_thr_1 = 0; move16(); - hMusicPF->LDm_nb_thr_3_fx = 0; + hMusicPF->LDm_nb_thr_3 = 0; move16(); hMusicPF->LDm_mem_etot_fx = 0; move16(); @@ -1016,7 +1016,7 @@ void music_postfilt_init( } set16_fx(hMusicPF->filt_lfE_fx, 4096, DCT_L_POST); move16(); - hMusicPF->last_nonfull_music_fx = 0; + hMusicPF->last_nonfull_music = 0; move16(); hMusicPF->Old_ener_Q = 0; move16(); diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index df77ebd8d..c3160355e 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -1208,10 +1208,7 @@ ivas_error acelp_core_dec( if ( st->last_bwidth == NB && st->hPFstat != NULL ) { floatToFixed_arr( pitch_buf, pitch_buf_tmp, Q6, NB_SUBFR16k ); - st->psf_lp_noise_fx = (Word16) floatToFixed( st->psf_lp_noise, Q8 ); } - st->lp_noise = floatToFixed( st->lp_noise_float, Q23 ); - /*---------------------*/ test(); IF( EQ_16( st->last_bwidth, NB ) && st->hPFstat != NULL ) { @@ -1223,20 +1220,6 @@ ivas_error acelp_core_dec( move16(); nb_post_filt( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, st->coder_type, st->BER_detect, 0 ); /*----ftf conversions---*/ - if ( !st->BER_detect ) - { - if ( st->coder_type == INACTIVE ) - { - st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q8 ); - } - } - - if ( prev_reset == 1 ) - { - st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); - fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, st->Q_syn, L_SYN_MEM ); - fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SYN_MEM ); - } /*---------------------*/ #else nb_post_filt_ivas( st->L_frame, L_SUBFR, st->hPFstat, &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, st->coder_type, st->BER_detect, 0 ); @@ -1250,12 +1233,6 @@ ivas_error acelp_core_dec( nb_post_filt( st->L_frame, st->hPFstat, &st->psf_lp_noise_fx, tmp_noise_fx, syn_fx, Aq_fx, pitch_buf_tmp, AUDIO, st->BER_detect, 0 ); /*----ftf conversions---*/ - if ( prev_reset == 1 ) - { - st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); - fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, st->Q_syn, L_SYN_MEM ); - fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SYN_MEM ); - } /*---------------------*/ #else nb_post_filt_ivas( st->L_frame, L_SUBFR, st->hPFstat, &st->psf_lp_noise, tmp_noise, syn, Aq, pitch_buf, AUDIO, st->BER_detect, 0 ); @@ -1266,9 +1243,6 @@ ivas_error acelp_core_dec( { #ifdef IVAS_FLOAT_FIXED st->psf_lp_noise_fx = round_fx( L_shl( st->lp_noise, 1 ) ); - /*----ftf conversions---*/ - st->psf_lp_noise = fix16_to_float( st->psf_lp_noise_fx, Q8 ); - /*---------------------*/ #else st->psf_lp_noise = st->lp_noise_float; #endif @@ -1385,27 +1359,11 @@ ivas_error acelp_core_dec( temp_buf_fx[i] = float_to_fix16_thrld( temp_buf[i], st->Q_syn ); } set16_fx( st->hPFstat->mem_zero, 0, M ); - if ( st->hPFstat ) - { - floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, st->Q_syn, L_SUBFR ); - floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, st->Q_syn, L_SUBFR ); - floatToFixed_arr( st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, DECMEM_RES2 ); - floatToFixed_arr( st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, M ); - st->hPFstat->gain_prec = float_to_fix16( st->hPFstat->gain_prec_flt, Q14 ); - } /*---------------------*/ formant_post_filt_fx( st->hPFstat, temp_buf_fx + L_SYN_MEM, Aq_fx, syn_fx, st->L_frame, st->lp_noise, st->total_brate, 0 ); /*----ftf conversions---*/ - if ( st->hPFstat ) - { - fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, st->Q_syn, L_SUBFR ); - fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SUBFR ); - fixedToFloat_arr( st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, DECMEM_RES2 ); - fixedToFloat_arr( st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, M ); - st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); - } fixedToFloat_arr( syn_fx, syn, st->Q_syn, st->L_frame ); /*---------------------*/ #else @@ -1419,7 +1377,6 @@ ivas_error acelp_core_dec( { #ifdef IVAS_FLOAT_FIXED /*----ftf conversions---*/ - floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, st->Q_syn, L_SUBFR ); floatToFixed_arr( syn, syn_fx, st->Q_syn, L_SUBFR ); floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); /*---------------------*/ @@ -1437,7 +1394,6 @@ ivas_error acelp_core_dec( if ( st->hPFstat ) { fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SUBFR ); - st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); } fixedToFloat_arr( temp_buf_fx, temp_buf, st->Q_syn, L_FRAME16k + L_SYN_MEM ); @@ -1652,7 +1608,7 @@ ivas_error acelp_core_dec( 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 ) ); + //st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); } } } @@ -1873,7 +1829,7 @@ ivas_error acelp_core_dec( 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 ) ); + //st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); } } } @@ -2026,10 +1982,7 @@ ivas_error acelp_core_dec( // Float to fixed tmp_Q_syn = -1; // Q0 + one guard bit = Q(-1) - st->stab_fac_fx = float_to_fix16( st->stab_fac, Q15 ); - st->stab_fac_smooth_fx = float_to_fix16( st->stab_fac_smooth, Q15 ); st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed( st->hBPF->pst_mem_deemp_err, tmp_Q_syn ); - st->hBPF->pst_lp_ener_fx = float_to_fix16( st->hBPF->pst_lp_ener, Q8 ); st->hBPF->psf_att_fx = float_to_fix16( st->hBPF->psf_att, Q15 ); for ( i = 0; i < st->L_frame; i++ ) { @@ -2046,8 +1999,6 @@ ivas_error acelp_core_dec( for ( i = 0; i < L_TRACK_HIST; i++ ) { st->hBPF->mem_mean_pit_fx[i] = float_to_fix16( st->hBPF->mem_mean_pit[i], 0 ); - st->hBPF->Track_on_hist_fx[i] = st->hBPF->Track_on_hist[i]; - st->hBPF->vibrato_hist_fx[i] = st->hBPF->vibrato_hist[i]; } Word16 bpf_error_signal_fx_temp[L_FRAME16k]; @@ -2074,8 +2025,6 @@ ivas_error acelp_core_dec( } // Fixed to float - st->hBPF->pst_lp_ener = fix16_to_float( st->hBPF->pst_lp_ener_fx, Q8 ); - st->stab_fac_smooth = fix16_to_float( st->stab_fac_smooth_fx, Q15 ); st->hBPF->mem_mean_pit[0] = fix16_to_float( st->hBPF->mem_mean_pit_fx[0], Q4 ); st->hBPF->psf_att = fix16_to_float( st->hBPF->psf_att_fx, Q15 ); for ( i = 0; i < NBPSF_PIT_MAX; i++ ) @@ -2086,11 +2035,6 @@ ivas_error acelp_core_dec( { bpf_error_signal[i] = fixedToFloat( bpf_error_signal_fx[i], tmp_Q_syn + 16 ); } - for ( i = 0; i < L_TRACK_HIST; i++ ) - { - st->hBPF->Track_on_hist[i] = st->hBPF->Track_on_hist_fx[i]; - st->hBPF->vibrato_hist[i] = st->hBPF->vibrato_hist_fx[i]; - } #else bass_psfilter( st->hBPF, st->Opt_AMR_WB, syn, st->L_frame, pitch_buf, st->bpf_off, st->stab_fac, &st->stab_fac_smooth, st->coder_type, bpf_error_signal ); #endif @@ -2666,7 +2610,6 @@ ivas_error acelp_core_dec( Copy32( tmp_bwe_exc_extended_fx + L_FRAME32k, tmp_old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); // Fixed to float - st->hBWE_TD->bwe_non_lin_prev_scale = fix_to_float( st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q30 ); me2f_buf( tmp_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, bwe_exc_extended, L_FRAME32k + NL_BUFF_OFFSET ); me2f_buf( tmp_old_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ); #else @@ -2684,119 +2627,7 @@ ivas_error acelp_core_dec( * Updates *----------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED - ////////////////////////////////////// Float to fix starts here //////////////////////////////////////////////// - Word16 tmp_Q_exc = 0; - Word16 tmp_old_exc_fx[L_EXC_DEC]; // Q_exc - Word16 tmp_old_bwe_exc_fx[((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)]; // Q_exc - Word16 tmp_pitch_buf_fx[NB_SUBFR16k]; // Q6 - Word16 tmp_Es_pred_fx; // Q8 - Word16 tmp_Aq_fx[NB_SUBFR16k * (M + 1)]; // Q12 - Word16 tmp_lsf_new_fx[M]; // Qx2.56 - Word16 tmp_lsp_new_fx[M]; // Q15 - Word16 tmp_voice_factors_fx[NB_SUBFR16k]; // Q15 - Word16 tmp_gain_buf_fx[NB_SUBFR16k]; // Q14 - - floatToFixed_arr(old_exc, tmp_old_exc_fx, tmp_Q_exc, L_EXC_DEC); - floatToFixed_arr(old_bwe_exc, tmp_old_bwe_exc_fx, tmp_Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)); - floatToFixed_arr(pitch_buf, tmp_pitch_buf_fx, Q6, NB_SUBFR16k); - tmp_Es_pred_fx = float_to_fix16(Es_pred, Q8); - floatToFixed_arr(Aq, tmp_Aq_fx, Q12, NB_SUBFR16k * (M + 1)); - for (i = 0; i < M; i++) - { - tmp_lsf_new_fx[i] = (Word16)(lsf_new[i] * 2.56f); - } - floatToFixed_arr(lsp_new, tmp_lsp_new_fx, Q15, M); - floatToFixed_arr(voice_factors, tmp_voice_factors_fx, Q15, NB_SUBFR16k); - floatToFixed_arr(gain_buf, tmp_voice_factors_fx, Q14, NB_SUBFR16k); - st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - st->coder_type = st->coder_type; - if (st->hGSCDec != NULL) - { - st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; - st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx; - } - st->GSC_noisy_speech = st->GSC_noisy_speech; - st->last_ppp_mode_dec = st->last_ppp_mode_dec; - st->ppp_mode_dec = st->ppp_mode_dec; - st->nelp_mode_dec = st->nelp_mode_dec; - st->vbr_hw_BWE_disable_dec = st->vbr_hw_BWE_disable_dec; - // just outputs: - if (st->hGSCDec != NULL) - { - st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev; - floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN); - floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, M); - } - st->last_coder_type = st->last_coder_type; - st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - if (st->hHQ_core != NULL) - st->hHQ_core->HqVoicing_fx = st->hHQ_core->HqVoicing; - st->old_ppp_mode = st->old_ppp_mode; - st->last_ppp_mode_dec = st->last_ppp_mode_dec; - st->last_nelp_mode_dec = st->last_nelp_mode_dec; - st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec; - floatToFixed_arr(st->old_exc, st->old_exc_fx, tmp_Q_exc, L_EXC_MEM_DEC); - for (i = 0; i < M; i++) - { - st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f); - } - floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M); - st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15); - 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); - for (i = 0; i < M; i++) - { - st->lsfoldbfi1[i] = (Word16)(st->lsfoldbfi1_fx[i] * 2.56f); - st->lsfoldbfi0[i] = (Word16)(st->lsfoldbfi0_fx[i] * 2.56f); - } - floatToFixed_arr(st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1); - st->old_Es_pred_fx = float_to_fix16(st->old_Es_pred, Q8); - ////////////////////////////////////// Float to fix ends here //////////////////////////////////////////////// - - updt_dec_fx( st, tmp_old_exc_fx, tmp_pitch_buf_fx, tmp_Es_pred_fx, tmp_Aq_fx, tmp_lsf_new_fx, tmp_lsp_new_fx, tmp_voice_factors_fx, tmp_old_bwe_exc_fx, tmp_gain_buf_fx ); - - ////////////////////////////////////// Fixed to float starts here //////////////////////////////////////////// - st->last_coder_type = st->last_coder_type; - if (st->hGSCDec != NULL) - { - st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx; - st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx; - } - st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - if (st->hHQ_core != NULL) - st->hHQ_core->HqVoicing = st->hHQ_core->HqVoicing_fx; - st->old_ppp_mode = st->old_ppp_mode; - st->last_ppp_mode_dec = st->last_ppp_mode_dec; - st->last_nelp_mode_dec = st->last_nelp_mode_dec; - st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec; - fixedToFloat_arr(st->old_exc_fx, st->old_exc, tmp_Q_exc, L_EXC_MEM_DEC); - IF(!st->Opt_AMR_WB && st->hBWE_TD != NULL) - fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, tmp_Q_exc, PIT16k_MAX * 2); - for (i = 0; i < M; i++) - { - st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - } - fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M); - st->last_voice_factor = fix16_to_float(st->last_voice_factor_fx, Q15); - if (st->hGSCDec != NULL) - { - fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, M); - fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN); - } - 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); - for (i = 0; i < M; i++) - { - st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f; - st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f; - } - fixedToFloat_arr(st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M+1); - st->old_Es_pred = fix16_to_float(st->old_Es_pred_fx, Q8); - ////////////////////////////////////// Fixed to float ends here ////////////////////////////////////////////// -#else updt_dec( st, old_exc, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, voice_factors, old_bwe_exc, gain_buf ); -#endif #ifdef IVAS_FLOAT_FIXED IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) diff --git a/lib_dec/acelp_core_dec_fx.c b/lib_dec/acelp_core_dec_fx.c index a85c99454..a80a0853c 100644 --- a/lib_dec/acelp_core_dec_fx.c +++ b/lib_dec/acelp_core_dec_fx.c @@ -1170,7 +1170,7 @@ ivas_error acelp_core_dec_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 1f363033a..0c2ce8fc8 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -632,7 +632,7 @@ ivas_error acelp_core_dec_ivas_fx( } //st->bfi_pitch *= tmpF; //st->bfi_pitch_frame = L_FRAME; - st->bfi_pitch_fx32 = Mpy_32_16_1(st->bfi_pitch_fx32, tmpF_fx); + st->bfi_pitch = mult_r(st->bfi_pitch, tmpF_fx); st->bfi_pitch_frame = L_FRAME; move16(); } @@ -658,22 +658,15 @@ ivas_error acelp_core_dec_ivas_fx( } //st->bfi_pitch *= tmpF; //st->bfi_pitch_frame = L_FRAME16k; - st->bfi_pitch_fx32 = Mpy_32_16_1( L_shl( st->bfi_pitch_fx32, exp ), tmpF_fx ); + st->bfi_pitch = mult_r( shl_sat( st->bfi_pitch, exp ), tmpF_fx ); st->bfi_pitch_frame = L_FRAME16k; move16(); } } - if (st->bfi_pitch_fx32 > MAX_16) { - assert(0 && "st->bfi_pitch_fx (Word16,Q6) is overflowing"); - } - else { - st->bfi_pitch_fx = extract_l(st->bfi_pitch_fx32); - } /*Local fix2float (to be removed)*/ /*fixedToFloat_arr(old_exc_fx, old_exc, st->Q_exc, L_EXC_DEC); fixedToFloat_arr(old_exc2_fx, old_exc2, st->Q_exc, L_FRAME16k + L_EXC_MEM); - fixedToFloat_arr(old_bwe_exc_fx, old_bwe_exc, st->Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)); fixedToFloat_arr(gain_buf_fx, gain_buf, Q14, NB_SUBFR16k);*/ if ( st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0 ) @@ -856,8 +849,10 @@ ivas_error acelp_core_dec_ivas_fx( move16(); } i = st->Q_exc; - Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, - st->L_frame* HIBND_ACB_L_FAC, 0, &(st->Q_exc), st->Q_subfr, NULL, 0, INACTIVE); + IF (st->hMusicPF && st->hGSCDec) { + Rescale_exc(st->hMusicPF->dct_post_old_exc_fx, exc_fx, bwe_exc_fx, st->hGSCDec->last_exc_dct_in_fx, st->L_frame, + st->L_frame* HIBND_ACB_L_FAC, 0, &(st->Q_exc), st->Q_subfr, NULL, 0, INACTIVE); + } Rescale_mem(st->Q_exc, &st->prev_Q_syn, &st->Q_syn, st->mem_syn2_fx, st->mem_syn_clas_estim_fx, delta_mem_scale, &st->mem_deemph_fx, st->hBPF->pst_old_syn_fx, &st->hBPF->pst_mem_deemp_err_fx, &st->agc_mem_fx[1], st->hPFstat, 0, 0, NULL); Copy_Scale_sig(exc2_fx, exc2_fx, st->L_frame, sub(st->Q_exc, i)); @@ -1131,6 +1126,7 @@ ivas_error acelp_core_dec_ivas_fx( { //tdm_low_rate_dec( st, dct_exc_tmp, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, lsf_new ); tdm_low_rate_dec_fx( st, dct_exc_tmp_fx/*, &tmp_noise*/, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, lsf_new_fx, st->Q_exc ); + tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ } else /* GENERIC */ { @@ -1387,7 +1383,7 @@ ivas_error acelp_core_dec_ivas_fx( /* LSF estimation and A(z) calculation */ //lsf_dec_bfi_flt( MODE1, lsf_new, st->lsf_old, st->lsf_adaptive_mean, NULL, st->mem_MA, st->mem_AR, st->stab_fac, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, st->bwidth ); - lsf_dec_bfi(MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx_fx, st->Opt_AMR_WB, 0, st->bwidth); + lsf_dec_bfi(MODE1, lsf_new_fx, st->lsf_old_fx, st->lsf_adaptive_mean_fx, NULL, st->mem_MA_fx, st->mem_AR_fx, st->stab_fac_fx, st->last_coder_type, st->L_frame, st->last_good, st->nbLostCmpt, 0, NULL, NULL, NULL, st->hGSCDec->Last_GSC_pit_band_idx, st->Opt_AMR_WB, 0, st->bwidth); //FEC_lsf2lsp_interp_flt( st, st->L_frame, Aq, lsf_new, lsp_new ); FEC_lsf2lsp_interp(st, st->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx); @@ -1779,7 +1775,6 @@ ivas_error acelp_core_dec_ivas_fx( if (st->idchan == 0) { - //st->lp_noise_float = st->hFdCngDec->lp_noise_float; st->lp_noise = st->hFdCngDec->lp_noise; move32(); } @@ -2296,133 +2291,6 @@ ivas_error acelp_core_dec_ivas_fx( bpf_pitch_coherence(st, pitch_buf); #endif - if (!(st->element_mode == IVAS_CPE_MDCT && st->bpf_off)) - { -#ifdef IVAS_FLOAT_FIXED - /////////////////////////////////////////////////////////////////////////////// - //Word16 pst_old_syn_exp; - //Word16 tmp_syn_exp; - //Word16 tmp_syn_fx[1]; // temporary. just one element because retro_interp4_5 only accesses syn[0] - - //// Get exponents. - //f2me_buf_16(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, &pst_old_syn_exp, NBPSF_PIT_MAX); - //f2me_16(syn[0], &tmp_syn_fx[0], &tmp_syn_exp); - //tmp_syn_exp = s_max(tmp_syn_exp, pst_old_syn_exp); // max exp btween syn and pst_old_syn - - //// Float to fix - //for (i = 0; i < NBPSF_PIT_MAX; i++) - //{ - // st->hBPF->pst_old_syn_fx[i] = (Word16)(st->hBPF->pst_old_syn[i] * pow(2, 15 - tmp_syn_exp)); - //} - //tmp_syn_fx[0] = (Word16)(syn[0] * pow(2, 15 - tmp_syn_exp)); - /////////////////////////////////////////////////////////////////////////////// - - //test(); - //IF(NE_16(st->L_frame, st->last_L_frame) && NE_16(st->last_codec_mode, MODE2)) - //{ - // IF(EQ_16(st->L_frame, L_FRAME)) - // { - // retro_interp5_4_fx(st->hBPF->pst_old_syn_fx); - // } - // ELSE IF(EQ_16(st->L_frame, L_FRAME16k)) - // { - // retro_interp4_5_fx(tmp_syn_fx, st->hBPF->pst_old_syn_fx); - // } - //} - - //// Fixed to float - //me2f_buf_16(st->hBPF->pst_old_syn_fx, tmp_syn_exp, st->hBPF->pst_old_syn, NBPSF_PIT_MAX); -#else - if (st->L_frame != st->last_L_frame && st->last_codec_mode != MODE2) - { - if (st->L_frame == L_FRAME) - { - retro_interp5_4(st->hBPF->pst_old_syn); - } - else if (st->L_frame == L_FRAME16k) - { - retro_interp4_5(syn, st->hBPF->pst_old_syn); - } - } -#endif - /* bass post-filter */ -#ifdef IVAS_FLOAT_FIXED - //Word16 tmp_syn_fx2[L_FRAME16k + L_SUBFR]; - //Word16 tmp_Q_syn; - //Word16 tmp_pitch_buf_fx[NB_SUBFR16k]; - - //// Float to fixed - //tmp_Q_syn = -1; // Q0 + one guard bit = Q(-1) - //st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); - //st->stab_fac_smooth_fx = float_to_fix16(st->stab_fac_smooth, Q15); - //st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, tmp_Q_syn); - //st->hBPF->pst_lp_ener_fx = float_to_fix16(st->hBPF->pst_lp_ener, Q8); - //st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15); - //for (i = 0; i < st->L_frame; i++) - //{ - // tmp_syn_fx2[i] = (Word16)floatToFixed(syn[i], tmp_Q_syn); - //} - //for (i = 0; i < NBPSF_PIT_MAX; i++) - //{ - // st->hBPF->pst_old_syn_fx[i] = (Word16)floatToFixed(st->hBPF->pst_old_syn[i], tmp_Q_syn); - //} - //for (i = 0; i < NB_SUBFR16k; i++) - //{ - // tmp_pitch_buf_fx[i] = (Word16)floatToFixed(pitch_buf[i], Q6); - //} - //for (i = 0; i < L_TRACK_HIST; i++) - //{ - // st->hBPF->mem_mean_pit_fx[i] = float_to_fix16(st->hBPF->mem_mean_pit[i], 0); - // st->hBPF->Track_on_hist_fx[i] = st->hBPF->Track_on_hist[i]; - // st->hBPF->vibrato_hist_fx[i] = st->hBPF->vibrato_hist[i]; - //} - - //Word16 bpf_error_signal_fx_temp[L_FRAME16k]; - //for (i = 0; i < L_FRAME16k; i++) - //{ - // bpf_error_signal_fx_temp[i] = extract_h(bpf_error_signal_fx[i]); - //} - - //bass_psfilter_fx(st->hBPF, - // st->Opt_AMR_WB, - // tmp_syn_fx2, - // st->L_frame, - // tmp_pitch_buf_fx, // Q6 - // st->bpf_off, - // st->stab_fac_fx, // Q15 - // &st->stab_fac_smooth_fx, // Q15 - // st->coder_type, - // tmp_Q_syn, - // bpf_error_signal_fx_temp); - - //for (i = 0; i < L_FRAME16k; i++) - //{ - // bpf_error_signal_fx[i] = L_deposit_h(bpf_error_signal_fx_temp[i]); - //} - - //// Fixed to float - //st->hBPF->pst_lp_ener = fix16_to_float(st->hBPF->pst_lp_ener_fx, Q8); - //st->stab_fac_smooth = fix16_to_float(st->stab_fac_smooth_fx, Q15); - //st->hBPF->mem_mean_pit[0] = fix16_to_float(st->hBPF->mem_mean_pit_fx[0], Q4); - //st->hBPF->psf_att = fix16_to_float(st->hBPF->psf_att_fx, Q15); - //for (i = 0; i < NBPSF_PIT_MAX; i++) - //{ - // st->hBPF->pst_old_syn[i] = fixedToFloat(st->hBPF->pst_old_syn_fx[i], tmp_Q_syn); - //} - //for (i = 0; i < L_FRAME16k; i++) - //{ - // bpf_error_signal[i] = fixedToFloat(bpf_error_signal_fx[i], tmp_Q_syn + 16); - //} - //for (i = 0; i < L_TRACK_HIST; i++) - //{ - // st->hBPF->Track_on_hist[i] = st->hBPF->Track_on_hist_fx[i]; - // st->hBPF->vibrato_hist[i] = st->hBPF->vibrato_hist_fx[i]; - //} -#else - bass_psfilter(st->hBPF, st->Opt_AMR_WB, syn, st->L_frame, pitch_buf, st->bpf_off, st->stab_fac, &st->stab_fac_smooth, st->coder_type, bpf_error_signal); -#endif - } - IF( !( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->bpf_off ) ) { @@ -2794,8 +2662,6 @@ ivas_error acelp_core_dec_ivas_fx( /* save synthesis - needed in case of core switching */ //mvr2r(synth, st->previoussynth, output_frame); Copy32(synth_fx, st->previoussynth_fx_32, output_frame); //Q0 - st->Q_syn2 = 0; - } else @@ -2865,19 +2731,7 @@ ivas_error acelp_core_dec_ivas_fx( } addBassPostFilter_fx(tmp_bpf_error_signal_fx + st->L_frame - nSamples, tmp, realBuffer_fx, imagBuffer_fx, st->cldfbBPF); - // Fixed to float - /*for (i = 0; i < CLDFB_NO_COL_MAX; i++) - { - for (j = 0; j < CLDFB_NO_CHANNELS_MAX; j++) - { - realBuffer[i][j] = fixedToFloat(realBuffer_fx[i][j], q_bpf_error_signal - 6); - imagBuffer[i][j] = fixedToFloat(imagBuffer_fx[i][j], q_bpf_error_signal - 6); - } - } - for (i = 0; i < cldfb_state_offset; i++) - { - st->cldfbBPF->cldfb_state[i] = fix_to_float(st->cldfbBPF->cldfb_state_fx[i], q_bpf_error_signal); - }*/ + Scale_sig32(st->cldfbBPF->cldfb_state_fx, cldfb_state_offset, -(q_bpf_error_signal - Q10)); //Q10 #else addBassPostFilter(bpf_error_signal + st->L_frame - nSamples, st->bpf_off ? 0 : nSamples, realBuffer, imagBuffer, st->cldfbBPF); @@ -2945,6 +2799,8 @@ ivas_error acelp_core_dec_ivas_fx( //mvr2r(syn, output, st->L_frame); Copy(psyn_fx, output_fx, st->L_frame); } + + st->Q_syn2 = 0; /*-----------------------------------------------------------------* * Bandwidth extension 6kHz-7kHz @@ -2963,20 +2819,7 @@ ivas_error acelp_core_dec_ivas_fx( ( EQ_16( st->extl, -1 ) || EQ_16( st->extl, SWB_CNG ) || ( EQ_16( st->extl, WB_BWE ) && st->extl_brate == 0 && NE_16( st->coder_type, AUDIO ) ) ) ) ) { Word16 tmp_exp = 0; - /* floatToFixed_arr( Aq, Aq_fx, Q12, NB_SUBFR16k * ( M + 1 ) ); - Word16 exc_fx[L_FRAME + L_SUBFR], exp_exc = 0, Q_exc = 0; - f2me_buf_16( exc, exc_fx, &exp_exc, L_FRAME ); - Q_exc = 15 - exp_exc; - Word16 Q_syn2 = 0; - Word16 synth_fx[L_FRAME48k]; - floatToFixed_arr( syn, psyn_fx, Q_syn2, L_FRAME + L_SUBFR ); - floatToFixed_arr( synth, synth_fx, Q_syn2, L_FRAME + L_SUBFR );*/ - - /*floatToFixed_arr( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_syn2, NS2SA( 16000, DELAY_CLDFB_NS ) - 15 ); - floatToFixed_arr( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN ); - floatToFixed_arr( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, 0, M ); - floatToFixed_arr( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, -2 - tmp_exp, L_FIR - 1 ); - floatToFixed_arr( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_syn2, 6 );*/ + //Word16 output_subfr = output_frame / NB_SUBFR; Copy_Scale_sig_32_16(synth_fx, synth_fx16, 0, L_FRAME48k); hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, @@ -2992,14 +2835,6 @@ ivas_error acelp_core_dec_ivas_fx( { Scale_sig( st->hBWE_zero->mem_hf_fx, L_FIR - 1, -tmp_exp ); } - - /*fixedToFloat_arr( synth_fx, synth, Q_syn2, output_subfr ); - fixedToFloat_arr( psyn_fx, syn, Q_syn2 - 2, L_SUBFR ); - fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, 0, NS2SA( 16000, DELAY_CLDFB_NS ) - 15 ); - fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, 0, INTERP_3_1_MEM_LEN ); - fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, 0, M ); - fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, -2 - tmp_exp, L_FIR - 1 ); - fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_syn2, 6 );*/ } ELSE { @@ -3040,36 +2875,7 @@ ivas_error acelp_core_dec_ivas_fx( if (!st->ppp_mode_dec && (st->idchan == 0 || st->element_mode != IVAS_CPE_TD || (st->idchan == 1 && st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag))) { #ifdef IVAS_FLOAT_FIXED - //Word16 voice_factors_fx[5]; - //Word32 tmp_bwe_exc_extended_fx[L_FRAME32k + NL_BUFF_OFFSET]; - //Word32 tmp_old_bwe_exc_extended_fx[NL_BUFF_OFFSET]; - //Word16 e1, e2; - //set32_fx( tmp_bwe_exc_extended_fx, 0, L_FRAME32k + NL_BUFF_OFFSET ); - - //// Extract exponents. - //f2me_buf_16( bwe_exc, bwe_exc_fx, &e1, L_FRAME32k ); - //f2me_buf( st->hBWE_TD->old_bwe_exc_extended, tmp_old_bwe_exc_extended_fx, &e2, NL_BUFF_OFFSET ); - //st->Q_exc = 15 - s_max( e1, e2 ); - //st->Q_exc = s_min( st->Q_exc, 14 ); // non_linearity_fx function crashes if Q == 15 - //// Float to fixed - //for ( i = 0; i < ( st->L_frame == L_FRAME16k ? 5 : 4 ); i++ ) - //{ - // voice_factors_fx[i] = float_to_fix16( voice_factors[i], Q15 ); - //} - //for ( i = 0; i < NL_BUFF_OFFSET; i++ ) - //{ - // tmp_old_bwe_exc_extended_fx[i] = floatToFixed( st->hBWE_TD->old_bwe_exc_extended[i], 2 * st->Q_exc ); - //} - //for ( i = 0; i < L_FRAME32k; i++ ) - //{ - // bwe_exc_fx[i] = (Word16)floatToFixed( bwe_exc[i], st->Q_exc ); - // if (bwe_exc[i] != 0 && bwe_exc_fx[i] == 0) - // { - // // NOTE: This is done to avoid zero values when float values are too small. - // // Else it will lead to a crash later in Interpolate_allpass_steep_32. - // bwe_exc_fx[i] = 1; - // } - //} + ///* update buffer memory */ //Copy32( tmp_old_bwe_exc_extended_fx, tmp_bwe_exc_extended_fx, NL_BUFF_OFFSET ); @@ -3082,7 +2888,6 @@ ivas_error acelp_core_dec_ivas_fx( //Copy32( tmp_bwe_exc_extended_fx + L_FRAME32k, tmp_old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); //// Fixed to float - //st->hBWE_TD->bwe_non_lin_prev_scale = fix_to_float( st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q30 ); //me2f_buf( tmp_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, bwe_exc_extended, L_FRAME32k + NL_BUFF_OFFSET ); //me2f_buf( tmp_old_bwe_exc_extended_fx, 31 - 2 * st->Q_exc, st->hBWE_TD->old_bwe_exc_extended, NL_BUFF_OFFSET ); Copy_Scale_sig_32_16(bwe_exc_extended_fx + L_FRAME32k, st->hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET, -(2 * st->Q_exc)); @@ -3102,115 +2907,9 @@ ivas_error acelp_core_dec_ivas_fx( *----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED - ////////////////////////////////////// Float to fix starts here //////////////////////////////////////////////// - //Word16 tmp_Q_exc = 0; - //Word16 tmp_old_exc_fx[L_EXC_DEC]; // Q_exc - //Word16 tmp_old_bwe_exc_fx[((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)]; // Q_exc - //Word16 tmp_pitch_buf_fx[NB_SUBFR16k]; // Q6 - //Word16 tmp_Es_pred_fx; // Q8 - //Word16 tmp_Aq_fx[NB_SUBFR16k * (M + 1)]; // Q12 - //Word16 tmp_lsf_new_fx[M]; // Qx2.56 - //Word16 tmp_lsp_new_fx[M]; // Q15 - //Word16 tmp_voice_factors_fx[NB_SUBFR16k]; // Q15 - //Word16 tmp_gain_buf_fx[NB_SUBFR16k]; // Q14 - - //floatToFixed_arr(old_exc, tmp_old_exc_fx, tmp_Q_exc, L_EXC_DEC); - //floatToFixed_arr(old_bwe_exc, tmp_old_bwe_exc_fx, tmp_Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)); - //floatToFixed_arr(pitch_buf, tmp_pitch_buf_fx, Q6, NB_SUBFR16k); - //tmp_Es_pred_fx = float_to_fix16(Es_pred, Q8); - //floatToFixed_arr(Aq, tmp_Aq_fx, Q12, NB_SUBFR16k * (M + 1)); - //for (i = 0; i < M; i++) - //{ - // tmp_lsf_new_fx[i] = (Word16)(lsf_new[i] * 2.56f); - //} - //floatToFixed_arr(lsp_new, tmp_lsp_new_fx, Q15, M); - //floatToFixed_arr(voice_factors, tmp_voice_factors_fx, Q15, NB_SUBFR16k); - //floatToFixed_arr(gain_buf, tmp_voice_factors_fx, Q14, NB_SUBFR16k); - //st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - //st->coder_type_fx = st->coder_type; - //if (st->hGSCDec != NULL) - //{ - // st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; - // st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx; - //} - //st->GSC_noisy_speech = st->GSC_noisy_speech; - //st->last_ppp_mode_dec = st->last_ppp_mode_dec; - //st->ppp_mode_dec = st->ppp_mode_dec; - //st->nelp_mode_dec = st->nelp_mode_dec; - //st->vbr_hw_BWE_disable_dec = st->vbr_hw_BWE_disable_dec; - //// just outputs: - //if (st->hGSCDec != NULL) - //{ - // st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev; - // floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN); - // floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, M); - //} - //st->last_coder_type_fx = st->last_coder_type; - //st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - //if (st->hHQ_core != NULL) - // st->hHQ_core->HqVoicing_fx = st->hHQ_core->HqVoicing; - //st->old_ppp_mode = st->old_ppp_mode; - //st->last_ppp_mode_dec = st->last_ppp_mode_dec; - //st->last_nelp_mode_dec_fx = st->last_nelp_mode_dec; - //st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec; - //floatToFixed_arr(st->old_exc, st->old_exc_fx, tmp_Q_exc, L_EXC_MEM_DEC); - //for (i = 0; i < M; i++) - //{ - // st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f); - //} - //floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M); - //st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15); - //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); - //for (i = 0; i < M; i++) - //{ - // st->lsfoldbfi1[i] = (Word16)(st->lsfoldbfi1_fx[i] * 2.56f); - // st->lsfoldbfi0[i] = (Word16)(st->lsfoldbfi0_fx[i] * 2.56f); - //} - //floatToFixed_arr(st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1); - //st->old_Es_pred_fx = float_to_fix16(st->old_Es_pred, Q8); - ////////////////////////////////////// Float to fix ends here //////////////////////////////////////////////// updt_dec_fx( st, old_exc_fx, pitch_buf_fx, Es_pred_fx, Aq_fx, lsf_new_fx, lsp_new_fx, voice_factors_fx, old_bwe_exc_fx, gain_buf_fx ); - ////////////////////////////////////// Fixed to float starts here //////////////////////////////////////////// - /*st->last_coder_type = st->last_coder_type_fx; - if (st->hGSCDec != NULL) - { - st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx; - st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx; - } - st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - if (st->hHQ_core != NULL) - st->hHQ_core->HqVoicing = st->hHQ_core->HqVoicing_fx; - st->old_ppp_mode = st->old_ppp_mode; - st->last_ppp_mode_dec = st->last_ppp_mode_dec; - st->last_nelp_mode_dec = st->last_nelp_mode_dec; - st->last_vbr_hw_BWE_disable_dec = st->last_vbr_hw_BWE_disable_dec; - fixedToFloat_arr(st->old_exc_fx, st->old_exc, tmp_Q_exc, L_EXC_MEM_DEC); - IF(!st->Opt_AMR_WB && st->hBWE_TD != NULL) - fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, tmp_Q_exc, PIT16k_MAX * 2); - for (i = 0; i < M; i++) - { - st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - } - fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M); - st->last_voice_factor = fix16_to_float(st->last_voice_factor_fx, Q15); - if (st->hGSCDec != NULL) - { - fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, M); - fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN); - } - 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); - for (i = 0; i < M; i++) - { - st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f; - st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f; - } - fixedToFloat_arr(st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M+1); - st->old_Es_pred = fix16_to_float(st->old_Es_pred_fx, Q8);*/ - ////////////////////////////////////// Fixed to float ends here ////////////////////////////////////////////// #else updt_dec( st, old_exc, pitch_buf, Es_pred, Aq, lsf_new, lsp_new, voice_factors, old_bwe_exc, gain_buf ); #endif @@ -3219,29 +2918,10 @@ ivas_error acelp_core_dec_ivas_fx( IF( GT_32( st->core_brate, SID_2k40 ) && st->hTdCngDec != NULL && st->hFdCngDec != NULL ) { ///* update CNG parameters in active frames */ - //Word16 lsp_new_fx[M]; - //Word16 exc_fx[L_EXC_DEC], Q_exc, exp_exc; - //f2me_buf_16( exc, exc_fx, &exp_exc, st->L_frame ); - //Q_exc = 15 - exp_exc; - //floatToFixed_arr( lsp_new, lsp_new_fx, Q15, M ); - //floatToFixed_arr( exc, exc_fx, Q_exc, st->L_frame ); - //floatToFixed_arrL( st->hTdCngDec->ho_ener_circ, st->hTdCngDec->ho_ener_circ_fx, Q6, HO_HIST_SIZE ); - //st->hTdCngDec->ho_circ_size = st->hTdCngDec->ho_circ_size; - //st->hTdCngDec->ho_circ_ptr = st->hTdCngDec->ho_circ_ptr; - //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 ); - cng_params_upd_ivas_fx( lsp_new_fx, exc_fx, 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 ); - //fixedToFloat_arr( lsp_new_fx, lsp_new, Q15, M ); - //fixedToFloat_arr( exc_fx, exc, Q_exc, st->L_frame ); - //fixedToFloat_arrL( st->hTdCngDec->ho_ener_circ_fx, st->hTdCngDec->ho_ener_circ, Q6, HO_HIST_SIZE ); - //st->hTdCngDec->ho_circ_size = st->hTdCngDec->ho_circ_size; - //st->hTdCngDec->ho_circ_ptr = st->hTdCngDec->ho_circ_ptr; - //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 ); /* Set 16k LSP flag for CNG buffer */ st->hTdCngDec->ho_16k_lsp[st->hTdCngDec->ho_circ_ptr] = 0; @@ -3280,54 +2960,7 @@ ivas_error acelp_core_dec_ivas_fx( { st->hFdCngDec->hFdCngCom->A_cng[0] = ONE_IN_Q12; } - /*for (i = 0; i < L_FRAME16k; i++) - { - bpf_error_signal[i] = fixedToFloat(bpf_error_signal_16fx[i], st->Q_syn); - }*/ - /*for (int nsf = 0; nsf < NB_SUBFR16k; nsf++) - { - fixedToFloat_arr(Aq_fx + (nsf * (M + 1)), Aq + (nsf * (M + 1)), Q14 - norm_s(Aq_fx[nsf * (M + 1)]), (M + 1)); - }*/ - /*printf("\n"); - for (int nm = 0; nm < M + 1; nm++) { - printf("%f ", Aq[nm]); - }*/ - // Aq_fx[0] = ONE_IN_Q12; - /*for (i = 0; i < M; i++) - { - lsf_new[i] = lsf_new_fx[i] / 2.56f; - }*/ - /*fixedToFloat_arr(lsp_new_fx, lsp_new, Q15, M); - fixedToFloat_arr(lsp_mid_fx, lsp_mid, Q15, M);*/ - /*float *tdm_lsfQ_PCh_out = (float *)tdm_lsfQ_PCh; - for (int idx = 0; idx < M; idx++) - { - tdm_lsfQ_PCh_out[idx] = tdm_lsfQ_PCh_fx[idx] / 2.56f; - } - fixedToFloat_arr(tdm_lspQ_PCh_fx, (float *)tdm_lspQ_PCh, Q15, M);*/ - /*printf("\n"); - for (int nm = 0; nm < M; nm++) { - printf("%f ", lsf_new[nm]); - }*/ - //fixedToFloat_arr(old_exc_fx, old_exc, st->Q_exc, L_EXC_DEC); // exc_fx - //fixedToFloat_arr(old_exc2_fx, old_exc2, st->Q_exc, L_FRAME16k + L_EXC_MEM); // exc2_fx - //fixedToFloat_arr(old_bwe_exc_fx, old_bwe_exc, st->Q_exc, ((PIT16k_MAX + (L_FRAME16k + 1) + L_SUBFR16k) * 2)); // bwe_exc_fx - //fixedToFloat_arr(syn_tmp_fx, syn_tmp, st->Q_syn, L_FRAME16k + L_SUBFR); // psyn_fx - //// fixedToFloat_arr(syn1_tmp_fx, syn1_tmp, st->Q_syn, L_FRAME16k + 2); - //fixedToFloat_arr(temp_buf_fx, temp_buf, -1, L_FRAME16k + L_SYN_MEM); - //Es_pred = fixedToFloat(Es_pred_fx, Q8); - // enr_q = fixedToFloat(enr_q_fx, 0); - - // fixedToFloat_arr(dct_exc_tmp_fx, dct_exc_tmp, st->Q_exc, L_FRAME16k); - // if (p_tdm_Pri_pitch_buf_fx) fixedToFloat_arr(p_tdm_Pri_pitch_buf_fx, p_tdm_Pri_pitch_buf, Q6, NB_SUBFR); - /*fixedToFloat_arr(gain_buf_fx, gain_buf, Q14, NB_SUBFR16k); - tmp_noise = fixedToFloat(tmp_noise_fx, 0);*/ - // fixedToFloat_arr(mem_tmp_fx, mem_tmp, st->Q_syn, M); - /*fixedToFloat_arr(pitch_buf_out_fx, pitch_buf, Q6, NB_SUBFR16k); - fixedToFloat_arr(voice_factors_fx, voice_factors, Q15, NB_SUBFR16k); - fixedToFloat_arr(old_syn_12k8_16k_fx, old_syn_12k8_16k, -1, st->L_frame);*/ - - /*---------------------*/ + } return error; @@ -3335,44 +2968,24 @@ ivas_error acelp_core_dec_ivas_fx( void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) { Word16 i; - st->Q_exc = 0; - st->Q_exc_cng = 0; - st->prev_Q_exc = 0; - st->prev_Q_exc_fr = 0; - set_s(st->Q_subfr, 0, L_Q_MEM); - st->Q_syn = 0; - st->Q_syn_cng = 0; - st->classifier_Q_mem_syn = 0; st->coder_type = st->coder_type; st->last_coder_type = st->last_coder_type; st->last_core_from_bs = st->last_core_from_bs; -#if 1 floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M); - floatToFixed_arr(st->lspCNG, st->lspCNG_fx, Q15, M); st->lp_ener_fx = floatToFixed(st->lp_ener, Q6); for (i = 0; i < M; i++) { - st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f); st->mem_MA_fx[i] = (Word16)(st->mem_MA[i] * 2.56f); st->mem_AR_fx[i] = (Word16)(st->mem_AR[i] * 2.56f); - st->lsfoldbfi1_fx[i] = (Word16)(st->lsfoldbfi1[i] * 2.56f); - st->lsfoldbfi0_fx[i] = (Word16)(st->lsfoldbfi0[i] * 2.56f); - st->lsf_adaptive_mean_fx[i] = (Word16)(st->lsf_adaptive_mean[i] * 2.56f); } - floatToFixed_arr(st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC); - floatToFixed_arr(st->mem_syn1, st->mem_syn1_fx, -1, M); - floatToFixed_arr(st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M); - floatToFixed_arr(st->mem_syn3, st->mem_syn3_fx, st->Q_syn_cng, M); - floatToFixed_arr(st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM); - st->mem_preemp_preQ_fx = float_to_fix16(st->mem_preemp_preQ, Q10); + st->mem_preemp_preQ_fx = float_to_fix16(st->mem_preemp_preQ, Q_AVQ_OUT); floatToFixed_arrL(st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2); - //st->bfi_pitch_fx = float_to_fix16(st->bfi_pitch, Q6); - st->bfi_pitch_fx32 = floatToFixed(st->bfi_pitch, Q6); + if (hStereoCng) { floatToFixed_arr(hStereoCng->olapBufferSynth22, hStereoCng->olapBufferSynth22_fx, st->Q_syn, FFTLEN); } /* st->mem_deemph_fx will need to be handled with proper Q */ st->mem_deemph_fx = (Word16)floatToFixed((Word16)check_bounds_l((Word32)st->mem_deemph, -32768, 32767), st->Q_syn); - floatToFixed_arr(st->agc_mem2, st->agc_mem_fx, st->prev_Q_syn - 1, 2); + //floatToFixed_arr(st->agc_mem2, st->agc_mem_fx, st->prev_Q_syn - 1, 2); floatToFixed_arr(st->Aq_cng_float, st->Aq_cng, Q12, M + 1); /*Flags (should be unified!)*/ @@ -3392,24 +3005,17 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /* dec_exc */ st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); - st->tilt_code_fx = float_to_fix16(st->tilt_code, Q15); - floatToFixed_arr(st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k); st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0); st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16); floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6); - st->gc_threshold_fx = floatToFixed(st->gc_threshold, Q16); - st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); st->prev_gain_pit_dec_fx = float_to_fix16(st->prev_gain_pit_dec, Q14); st->prev_tilt_code_dec_fx = float_to_fix16(st->prev_tilt_code_dec, Q15); st->lp_gainp_fx = float_to_fix16(st->lp_gainp, Q14); st->past_gpit = float_to_fix16(st->past_gpit_float, Q14); /* Bad frame */ - floatToFixed_arr(st->lspold_s, st->lspold_s_fx, Q15, M); - floatToFixed_arr(st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2); - st->min_alpha_fx = float_to_fix16(st->min_alpha, Q15); + st->ge_sm_fx = (Word16)floatToFixed(st->ge_sm, st->Q_stat_noise_ge); - st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15); /* After dec_exc */ @@ -3418,12 +3024,9 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte st->old_enr_LP = (Word16)floatToFixed((Word16)check_bounds_l((Word32)st->old_enr_LP_float, -32768, 32767), Q3); st->lp_ener_FEC_av = floatToFixed(st->lp_ener_FEC_av_float, 0); st->lp_ener_FEC_max = floatToFixed(st->lp_ener_FEC_max_float, 0); - floatToFixed_arr(st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM); st->exc_pe_fx = (Word16)floatToFixed(st->exc_pe, st->Q_stat_noise); - st->psf_lp_noise_fx = float_to_fix16(st->psf_lp_noise, Q8); - st->lp_noise = floatToFixed(st->lp_noise_float, Q23); floatToFixed_arr(st->syn_float, st->syn, 0, M + 1); - floatToFixed_arr(st->lspold_cng_float, st->lspold_cng, Q15, M); + //floatToFixed_arr(st->lspold_cng_float, st->lspold_cng, Q15, M); /* CLDFB */ Word16 old_len_ana, old_len_bpf; @@ -3441,7 +3044,6 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte floatToFixed_arrL(st->cldfbSynHB->cldfb_state, st->cldfbSynHB->cldfb_state_fx, Q10, st->cldfbSynHB->p_filter_length); floatToFixed_arrL(st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q10, st->cldfbSyn->p_filter_length); - st->stab_fac_smooth_fx = float_to_fix16(st->stab_fac_smooth, Q15); //Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels); floatToFixed_arrL(st->previoussynth, st->previoussynth_fx_32, 0, L_FRAME48k); @@ -3451,9 +3053,6 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte floatToFixed_arr(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, st->Q_syn2 - 1, NBPSF_PIT_MAX); st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, st->Q_syn2 - 1); floatToFixed_arr(st->hBPF->mem_mean_pit, st->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST); - Copy(st->hBPF->Track_on_hist, st->hBPF->Track_on_hist_fx, L_TRACK_HIST); - Copy(st->hBPF->vibrato_hist, st->hBPF->vibrato_hist_fx, L_TRACK_HIST); - st->hBPF->pst_lp_ener_fx = float_to_fix16(st->hBPF->pst_lp_ener, Q8); st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15); } @@ -3529,7 +3128,6 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte //TdCng if (st->hTdCngDec) { - st->hTdCngDec->Enew_fx = floatToFixed(st->hTdCngDec->Enew, Q6); st->hTdCngDec->ho_hist_size = st->hTdCngDec->ho_hist_size; st->hTdCngDec->act_cnt2 = st->hTdCngDec->act_cnt2; st->hTdCngDec->act_cnt = st->hTdCngDec->act_cnt; @@ -3545,15 +3143,6 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte floatToFixed_arr(st->hTdCngDec->exc_mem1, st->hTdCngDec->exc_mem1_fx, st->Q_exc, 30); } - /*PFSTAT_HANDLE*/ - if (st->hPFstat) { - floatToFixed_arr(st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, st->Q_syn, L_SUBFR); - floatToFixed_arr(st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, st->Q_syn, L_SUBFR); - floatToFixed_arr(st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, DECMEM_RES2); - floatToFixed_arr(st->hPFstat->mem_zero_flt, st->hPFstat->mem_zero, st->Q_syn, M); - st->hPFstat->gain_prec = float_to_fix16(st->hPFstat->gain_prec_flt, Q14); - } - /*WI_DEC_HANDLE*/ if (st->hWIDec) { floatToFixed_arr(st->hWIDec->old_exc2, st->hWIDec->old_exc2_fx, st->prev_Q_exc_fr, L_EXC_MEM); @@ -3562,10 +3151,8 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /*TD_BWE_DEC_HANDLE*/ if (st->hBWE_TD) { - floatToFixed_arr(st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, st->Q_exc, PIT16k_MAX * 2); floatToFixed_arr(st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1); floatToFixed_arr(st->hBWE_TD->old_bwe_exc_extended, st->hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET); - st->hBWE_TD->bwe_non_lin_prev_scale_fx = floatToFixed(st->hBWE_TD->bwe_non_lin_prev_scale, Q30); } /*GSC_DEC_HANDLE*/ @@ -3576,16 +3163,11 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte else { st->hGSCDec->Last_frame_ener_fx = floatToFixed(st->hGSCDec->Last_frame_ener, 0); } - st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx; - st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit; floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN16k); - st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev; floatToFixed_arr(st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN16k); floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME16k); - st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME16k); // st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0); - Copy(st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6); } /*TCX_DEC_HANDLE*/ @@ -3603,11 +3185,7 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte floatToFixed_arrL(st->hMusicPF->LDm_enh_lf_EO, st->hMusicPF->LDm_enh_lf_EO_fx, Q10, VOIC_BINS_HR); floatToFixed_arr(st->hMusicPF->LDm_lt_diff_etot, st->hMusicPF->LDm_lt_diff_etot_fx, Q15, MAX_LT); st->hMusicPF->LDm_mem_etot_fx = float_to_fix16(st->hMusicPF->LDm_mem_etot, Q8); - st->hMusicPF->LDm_nb_thr_3_fx = st->hMusicPF->LDm_nb_thr_3; - st->hMusicPF->LDm_nb_thr_1_fx = st->hMusicPF->LDm_nb_thr_1; floatToFixed_arr(st->hMusicPF->LDm_thres, st->hMusicPF->LDm_thres_fx, Q12, 4); - st->hMusicPF->LDm_last_music_flag_fx = st->hMusicPF->LDm_last_music_flag; - st->hMusicPF->last_nonfull_music_fx = st->hMusicPF->last_nonfull_music; floatToFixed_arrL(st->hMusicPF->LDm_bckr_noise, st->hMusicPF->LDm_bckr_noise_fx, Q10, MBANDS_GN_LD); } @@ -3617,130 +3195,6 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte st->hBWE_FD->mem_deemph_old_syn_fx = extract_l( floatToFixed( st->hBWE_FD->mem_deemph_old_syn, -1 ) ); } -#else - st->Q_exc = 0; - st->Q_syn = 0; - for (i = 0; i < M; i++) { - st->lsf_old_fx[i] = (Word16)(st->lsf_old[i] * 2.56f); - st->mem_MA_fx[i] = (Word16)(st->mem_MA[i] * 2.56f); - st->mem_AR_fx[i] = (Word16)(st->mem_AR[i] * 2.56f); - st->lsfoldbfi1_fx[i] = (Word16)(st->lsfoldbfi1[i] * 2.56f); - st->lsfoldbfi0_fx[i] = (Word16)(st->lsfoldbfi0[i] * 2.56f); - st->lsf_adaptive_mean_fx[i] = (Word16)(st->lsf_adaptive_mean[i] * 2.56f); - } - floatToFixed_arr(st->lsp_old, st->lsp_old_fx, Q15, M); - st->tilt_code_fx = float_to_fix16(st->tilt_code, Q15); - floatToFixed_arr(st->old_exc, st->old_exc_fx, st->prev_Q_exc, L_EXC_MEM_DEC); - floatToFixed_arr(st->mem_syn1, st->mem_syn1_fx, -1, M); - floatToFixed_arr(st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M); - floatToFixed_arr(st->mem_syn3, st->mem_syn3_fx, st->Q_syn, M); - st->mem_deemph_fx = (Word16)floatToFixed(st->mem_deemph, st->Q_syn); - st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); - st->stab_fac_smooth_fx = float_to_fix16(st->stab_fac_smooth, Q15); - floatToFixed_arr(st->agc_mem2, st->agc_mem_fx, st->Q_syn - 1, 2); - //st->mid_lsf_int = st->mid_lsf_int; - st->safety_net = st->safety_net; - //st->GSC_noisy_speech = st->GSC_noisy_speech; - //st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - st->gc_threshold_fx = floatToFixed(st->gc_threshold, Q16); - st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0); - st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16); - floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6); - //st->unv_cnt = st->unv_cnt; - //st->uv_count = st->uv_count; - //st->act_count = st->act_count; - st->ge_sm_fx = (Word16)floatToFixed(st->ge_sm, st->Q_stat_noise_ge); - floatToFixed_arr(st->lspold_s, st->lspold_s_fx, Q15, M); - //st->noimix_seed = st->noimix_seed; - st->min_alpha_fx = float_to_fix16(st->min_alpha, Q15); - st->exc_pe_fx = (Word16)floatToFixed(st->exc_pe, st->Q_stat_noise); - st->lp_gainp_fx = float_to_fix16(st->lp_gainp, Q14); - st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); - st->lp_ener_fx = floatToFixed(st->lp_ener, Q6); - st->enr_old_fx = floatToFixed(st->enr_old, 0); - st->bfi_pitch_fx = float_to_fix16(st->bfi_pitch, Q6); - floatToFixed_arrL(st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2); - st->lp_ener_FEC_av = floatToFixed(st->lp_ener_FEC_av_float, 0); - st->lp_ener_FEC_max = floatToFixed(st->lp_ener_FEC_max_float, 0); - st->old_enr_LP = float_to_fix16(st->old_enr_LP_float, st->Q_exc); - //st->last_good = st->last_good; - st->lp_ener_FER_fx = float_to_fix16(st->lp_ener_bfi, Q8); - //st->relax_prev_lsf_interp = st->relax_prev_lsf_interp; - floatToFixed_arr(st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, st->Q_syn, L_SYN_MEM_CLAS_ESTIM); - // cldfbAna - // cldfbBPF - // cldfbSyn - st->perc_bwddec = float_to_fix16(st->perc_bwddec_float, Q14); - st->avg_nrg_LT = floatToFixed(st->avg_nrg_LT_float, 0); - st->Ng_ener_ST_fx = float_to_fix16(st->ng_ener_ST, Q8); - st->mem_preemp_preQ_fx = float_to_fix16(st->mem_preemp_preQ, 0); - //st->last_nq_preQ = st->last_nq_preQ; - st->psf_lp_noise_fx = float_to_fix16(st->psf_lp_noise, Q8); - st->last_voice_factor_fx = float_to_fix16(st->last_voice_factor, Q15); - floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1, st->L_frame / 2); - floatToFixed_arr(st->Aq_cng_float, st->Aq_cng, 0, (NB_SUBFR16k + 1)*(M + 1)); - floatToFixed_arr(st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, st->Q_exc, PIT16k_MAX * 2); - floatToFixed_arr(st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q14, M + 1); - floatToFixed_arr(st->syn_float, st->syn, 0, M + 1); - /*GSC_DEC_HANDLE*/ - if (st->hGSCDec) { - st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx; - st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit; - floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q15, MBANDS_GN); - st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev; - floatToFixed_arr(st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN); - if (st->hGSCDec->Last_frame_ener >= (float)MAX_32) { - st->hGSCDec->Last_frame_ener_fx = MAX_32; - } - else { - st->hGSCDec->Last_frame_ener_fx = float_to_fix(st->hGSCDec->Last_frame_ener, 0); - } - floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME); - st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; - floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME); - st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, Q8); - Copy(st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6); - } - /*ZERO_BWE_DEC_HANDLE*/ - if (st->hBWE_zero) { - st->hBWE_zero->seed2_fx = st->hBWE_zero->seed2; - floatToFixed_arr(st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, st->Q_syn, 4); - floatToFixed_arr(st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, st->Q_syn, L_FIR - 1); - floatToFixed_arr(st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, st->Q_syn, M); - floatToFixed_arr(st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, st->Q_syn, NS2SA(16000, DELAY_CLDFB_NS)); - floatToFixed_arr(st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, st->Q_syn, INTERP_3_1_MEM_LEN); - } - /*WI_DEC_HANDLE*/ - if (st->hWIDec) { - floatToFixed_arr(st->hWIDec->old_exc2, st->hWIDec->old_exc2_fx, st->Q_exc, L_EXC_MEM); - floatToFixed_arr(st->hWIDec->old_syn2, st->hWIDec->old_syn2_fx, st->Q_syn, L_EXC_MEM); - } - /*BPF_DEC_HANDLE*/ - floatToFixed_arr(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, st->Q_syn, NBPSF_PIT_MAX); - st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, st->Q_syn); - st->hBPF->pst_lp_ener_fx = float_to_fix16(st->hBPF->pst_lp_ener, Q8); - Copy(st->hBPF->Track_on_hist, st->hBPF->Track_on_hist_fx, L_TRACK_HIST); - Copy(st->hBPF->vibrato_hist, st->hBPF->vibrato_hist_fx, L_TRACK_HIST); - st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15); - floatToFixed_arr(st->hBPF->mem_mean_pit, st->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST); - /*PFSTAT_HANDLE*/ - floatToFixed_arr(st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, st->Q_syn, L_SUBFR); - floatToFixed_arr(st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, st->Q_syn, L_SUBFR); - floatToFixed_arr(st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, DECMEM_RES2); - floatToFixed_arr(st->hPFstat->mem_res2_flt, st->hPFstat->mem_res2, st->Q_syn, M); - st->hPFstat->gain_prec = float_to_fix16(st->hPFstat->gain_prec_flt, Q14); - /*Missing parameters*/ - st->prev_gain_pit_dec_fx = float_to_fix16(st->prev_gain_pit_dec, Q14); - floatToFixed_arr(st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k); - floatToFixed_arr(st->previoussynth, st->previoussynth_fx, 0, L_FRAME48k); - floatToFixed_arr(st->old_Aq_12_8, st->old_Aq_12_8_fx, Q14, M + 1); - st->old_Es_pred_fx = float_to_fix16(st->old_Es_pred, Q8); - floatToFixed_arr(st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2); - floatToFixed_arr(st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM); - floatToFixed_arr(st->bpf_noise_buf_float, st->bpf_noise_buf, st->Q_syn, L_FRAME16k); - st->prev_tilt_code_dec_fx = float_to_fix16(st->prev_tilt_code_dec, Q15); - st->last_coder_type = st->last_coder_type; -#endif } void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hStereoCng) { @@ -3748,32 +3202,19 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte st->last_core_from_bs = st->last_core_from_bs; st->prev_Q_syn = st->Q_syn; - st->Q_syn2 = st->Q_syn; -#if 1 + fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M); - fixedToFloat_arr(st->lspCNG_fx, st->lspCNG, Q15, M); st->lp_ener = fixedToFloat(st->lp_ener_fx, Q6); for (i = 0; i < M; i++) { - st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f; st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f; - st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f; - st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f; - st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56f; } - fixedToFloat_arr(st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC); - fixedToFloat_arr(st->mem_syn1_fx, st->mem_syn1, -1, M); - fixedToFloat_arr(st->mem_syn2_fx, st->mem_syn2, st->Q_syn, M); - fixedToFloat_arr(st->mem_syn3_fx, st->mem_syn3, st->Q_syn_cng, M); - fixedToFloat_arr(st->mem_syn_r, st->mem_syn_r_float, st->Q_syn, L_SYN_MEM); fixedToFloat_arrL(st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2); - st->mem_preemp_preQ = fixedToFloat(st->mem_preemp_preQ_fx, Q10); - st->bfi_pitch = fixedToFloat(st->bfi_pitch_fx, Q6); + st->mem_preemp_preQ = fixedToFloat(st->mem_preemp_preQ_fx, Q_AVQ_OUT); if (hStereoCng) { fixedToFloat_arr(hStereoCng->olapBufferSynth22_fx, hStereoCng->olapBufferSynth22, st->Q_syn, FFTLEN); } st->mem_deemph = fixedToFloat(st->mem_deemph_fx, st->Q_syn); - fixedToFloat_arr(st->agc_mem_fx, st->agc_mem2, st->Q_syn - 1, 2); fixedToFloat_arr(st->Aq_cng, st->Aq_cng_float, Q14 - norm_s(st->Aq_cng[0]), M + 1); /*Flags (should be unified!)*/ @@ -3793,13 +3234,10 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /* dec_exc */ st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); - st->tilt_code = fixedToFloat(st->tilt_code_fx, Q15); - fixedToFloat_arr(st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k); st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0); st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16); fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6); - st->gc_threshold = fixedToFloat(st->gc_threshold_fx, Q16); - st->stab_fac = fixedToFloat(st->stab_fac_fx, Q15); + st->prev_gain_pit_dec = fixedToFloat(st->prev_gain_pit_dec_fx, Q14); st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); st->lp_gainp = fixedToFloat(st->lp_gainp_fx, Q14); @@ -3807,11 +3245,7 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte st->past_gpit_float = fixedToFloat(st->past_gpit, Q14); /* Bad frame */ - fixedToFloat_arr(st->lspold_s_fx, st->lspold_s, Q15, M); - fixedToFloat_arr(st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2); - st->min_alpha = fixedToFloat(st->min_alpha_fx, Q15); st->ge_sm = fixedToFloat(st->ge_sm_fx, st->Q_stat_noise_ge); - st->last_voice_factor = fixedToFloat(st->last_voice_factor_fx, Q15); st->exc_pe = fixedToFloat(st->exc_pe_fx, st->Q_stat_noise); @@ -3821,11 +3255,7 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte st->old_enr_LP_float = fixedToFloat(st->old_enr_LP, Q3); st->lp_ener_FEC_av_float = fixedToFloat(st->lp_ener_FEC_av, 0); st->lp_ener_FEC_max_float = fixedToFloat(st->lp_ener_FEC_max, 0); - fixedToFloat_arr(st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, st->classifier_Q_mem_syn, L_SYN_MEM_CLAS_ESTIM); - st->psf_lp_noise = fixedToFloat(st->psf_lp_noise_fx, Q8); - st->lp_noise_float = fixedToFloat(st->lp_noise, Q23); fixedToFloat_arr(st->syn, st->syn_float, 0, M + 1); - fixedToFloat_arr(st->lspold_cng, st->lspold_cng_float, Q15, M); /* CLDFB */ Word16 new_len; @@ -3836,7 +3266,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arrL(st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_state, Q10, st->cldfbSynHB->p_filter_length); fixedToFloat_arrL(st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_state, Q10, st->cldfbSyn->p_filter_length); - st->stab_fac_smooth = fixedToFloat(st->stab_fac_smooth_fx, Q15); //Word16 offset = sub(st->cldfbAna->p_filter_length, st->cldfbAna->no_channels); IF(st->p_bpf_noise_buf_32) { @@ -3850,9 +3279,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arr(st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, st->Q_syn2 - 1, NBPSF_PIT_MAX); st->hBPF->pst_mem_deemp_err = fixedToFloat(st->hBPF->pst_mem_deemp_err_fx, st->Q_syn2 - 1); fixedToFloat_arr(st->hBPF->mem_mean_pit_fx, st->hBPF->mem_mean_pit, Q4, L_TRACK_HIST); - Copy(st->hBPF->Track_on_hist_fx, st->hBPF->Track_on_hist, L_TRACK_HIST); - Copy(st->hBPF->vibrato_hist_fx, st->hBPF->vibrato_hist, L_TRACK_HIST); - st->hBPF->pst_lp_ener = fixedToFloat(st->hBPF->pst_lp_ener_fx, Q8); st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15); } @@ -3975,7 +3401,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte //TdCng if (st->hTdCngDec) { - st->hTdCngDec->Enew = fixedToFloat(st->hTdCngDec->Enew_fx, Q6); st->hTdCngDec->ho_hist_size = st->hTdCngDec->ho_hist_size; st->hTdCngDec->act_cnt2 = st->hTdCngDec->act_cnt2; st->hTdCngDec->act_cnt = st->hTdCngDec->act_cnt; @@ -3991,15 +3416,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arr(st->hTdCngDec->exc_mem1_fx, st->hTdCngDec->exc_mem1, st->Q_exc, 30); } - /*PFSTAT_HANDLE*/ - if (st->hPFstat) { - fixedToFloat_arr(st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, st->Q_syn, L_SUBFR); - fixedToFloat_arr(st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SUBFR); - fixedToFloat_arr(st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, DECMEM_RES2); - fixedToFloat_arr(st->hPFstat->mem_zero, st->hPFstat->mem_zero_flt, st->Q_syn, M); - st->hPFstat->gain_prec_flt = fixedToFloat(st->hPFstat->gain_prec, Q14); - } - /*WI_DEC_HANDLE*/ if (st->hWIDec) { fixedToFloat_arr(st->hWIDec->old_exc2_fx, st->hWIDec->old_exc2, st->prev_Q_exc_fr, L_EXC_MEM); @@ -4008,25 +3424,18 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /*TD_BWE_DEC_HANDLE*/ if (st->hBWE_TD) { - fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, st->Q_exc, PIT16k_MAX * 2); fixedToFloat_arr(st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1); fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_extended_fx, st->hBWE_TD->old_bwe_exc_extended, 0, NL_BUFF_OFFSET); - st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat(st->hBWE_TD->bwe_non_lin_prev_scale_fx, Q30); } /*GSC_DEC_HANDLE*/ if (st->hGSCDec) { st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, 0); - st->hGSCDec->seed_tcx = st->hGSCDec->seed_tcx_fx; - st->hGSCDec->cor_strong_limit = st->hGSCDec->cor_strong_limit_fx; fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN16k); - st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx; fixedToFloat_arr(st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN16k); fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME16k); - st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx; fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME16k); st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, 0); - Copy(st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6); } /*TCX_DEC_HANDLE*/ @@ -4044,11 +3453,7 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arrL(st->hMusicPF->LDm_enh_lf_EO_fx, st->hMusicPF->LDm_enh_lf_EO, Q10, VOIC_BINS_HR); fixedToFloat_arr(st->hMusicPF->LDm_lt_diff_etot_fx, st->hMusicPF->LDm_lt_diff_etot, Q15, MAX_LT); st->hMusicPF->LDm_mem_etot = fixedToFloat(st->hMusicPF->LDm_mem_etot_fx, Q8); - st->hMusicPF->LDm_nb_thr_3 = st->hMusicPF->LDm_nb_thr_3_fx; - st->hMusicPF->LDm_nb_thr_1 = st->hMusicPF->LDm_nb_thr_1_fx; fixedToFloat_arr(st->hMusicPF->LDm_thres_fx, st->hMusicPF->LDm_thres, Q12, 4); - st->hMusicPF->LDm_last_music_flag = st->hMusicPF->LDm_last_music_flag_fx; - st->hMusicPF->last_nonfull_music = st->hMusicPF->last_nonfull_music_fx; fixedToFloat_arrL(st->hMusicPF->LDm_bckr_noise_fx, st->hMusicPF->LDm_bckr_noise, Q10, MBANDS_GN_LD); } @@ -4057,129 +3462,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte fixedToFloat_arr(st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, -1); } - -#else - Word32 i; - for (i = 0; i < M; i++) { - st->lsf_old[i] = st->lsf_old_fx[i] / 2.56f; - st->mem_MA[i] = st->mem_MA_fx[i] / 2.56f; - st->mem_AR[i] = st->mem_AR_fx[i] / 2.56f; - st->lsfoldbfi1[i] = st->lsfoldbfi1_fx[i] / 2.56f; - st->lsfoldbfi0[i] = st->lsfoldbfi0_fx[i] / 2.56f; - st->lsf_adaptive_mean[i] = st->lsf_adaptive_mean_fx[i] / 2.56f; - } - fixedToFloat_arr(st->lsp_old_fx, st->lsp_old, Q15, M); - st->tilt_code = fixedToFloat(st->tilt_code_fx, Q15); - fixedToFloat_arr(st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC); - fixedToFloat_arr(st->mem_syn1_fx, st->mem_syn1, -1, M); - fixedToFloat_arr(st->mem_syn2_fx, st->mem_syn2, st->Q_syn, M); - fixedToFloat_arr(st->mem_syn3_fx, st->mem_syn3, st->Q_syn, M); - st->mem_deemph = fixedToFloat(st->mem_deemph_fx, st->Q_syn); - st->stab_fac = fixedToFloat(st->stab_fac_fx, Q15); - st->stab_fac_smooth = fixedToFloat(st->stab_fac_smooth_fx, Q15); - fixedToFloat_arr(st->agc_mem_fx, st->agc_mem2, st->Q_syn - 1, 2); - //st->mid_lsf_int = st->mid_lsf_int; - st->safety_net = st->safety_net; - //st->GSC_noisy_speech = st->GSC_noisy_speech; - //st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; - st->gc_threshold = fixedToFloat(st->gc_threshold_fx, Q16); - st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0); - st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16); - fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6); - //st->unv_cnt = st->unv_cnt; - //st->uv_count = st->uv_count; - //st->act_count = st->act_count; - st->ge_sm = fixedToFloat(st->ge_sm_fx, st->Q_stat_noise_ge); - fixedToFloat_arr(st->lspold_s_fx, st->lspold_s, Q15, M); - //st->noimix_seed = st->noimix_seed; - st->min_alpha = fixedToFloat(st->min_alpha_fx, Q15); - st->exc_pe = fixedToFloat(st->exc_pe_fx, st->Q_stat_noise); - st->lp_gainp = fixedToFloat(st->lp_gainp_fx, Q14); - st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); - st->lp_ener = fixedToFloat(st->lp_ener_fx, Q6); - st->enr_old = fixedToFloat(st->enr_old_fx, 0); - st->bfi_pitch = fixedToFloat(st->bfi_pitch_fx, Q6); - fixedToFloat_arrL(st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2); - st->lp_ener_FEC_av_float = fixedToFloat(st->lp_ener_FEC_av, 0); - st->lp_ener_FEC_max_float = fixedToFloat(st->lp_ener_FEC_max, 0); - st->old_enr_LP_float = fixedToFloat(st->old_enr_LP, st->Q_exc); - //st->last_good = st->last_good; - st->lp_ener_bfi = fixedToFloat(st->lp_ener_FER_fx, Q8); - //st->relax_prev_lsf_interp = st->relax_prev_lsf_interp; - fixedToFloat_arr(st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, st->Q_syn, L_SYN_MEM_CLAS_ESTIM); - // cldfbAna - // cldfbBPF - // cldfbSyn - st->perc_bwddec_float = fixedToFloat(st->perc_bwddec, Q14); - st->avg_nrg_LT_float = fixedToFloat(st->avg_nrg_LT, 0); - st->ng_ener_ST = fixedToFloat(st->Ng_ener_ST_fx, Q8); - st->mem_preemp_preQ = fixedToFloat(st->mem_preemp_preQ_fx, 0); - //st->last_nq_preQ = st->last_nq_preQ; - st->psf_lp_noise = fixedToFloat(st->psf_lp_noise_fx, Q8); - st->last_voice_factor = fixedToFloat(st->last_voice_factor_fx, Q15); - fixedToFloat_arr(st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, -1, st->L_frame / 2); - fixedToFloat_arr(st->Aq_cng, st->Aq_cng_float, 0, (NB_SUBFR16k + 1)*(M + 1)); - fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, st->Q_exc, PIT16k_MAX * 2); - fixedToFloat_arr(st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q14, M + 1); - fixedToFloat_arr(st->syn, st->syn_float, 0, M + 1); - /*GSC_DEC_HANDLE*/ - if (st->hGSCDec) { - st->hGSCDec->seed_tcx = st->hGSCDec->seed_tcx_fx; - st->hGSCDec->cor_strong_limit = st->hGSCDec->cor_strong_limit_fx; - fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q15, MBANDS_GN); - st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx; - fixedToFloat_arr(st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN); - st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, 0); - fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME); - st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx; - fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME); - st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, Q8); - Copy(st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6); - } - /*ZERO_BWE_DEC_HANDLE*/ - if (st->hBWE_zero) { - st->hBWE_zero->seed2 = st->hBWE_zero->seed2_fx; - fixedToFloat_arr(st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, st->Q_syn, 4); - fixedToFloat_arr(st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, st->Q_syn, L_FIR - 1); - fixedToFloat_arr(st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, st->Q_syn, M); - fixedToFloat_arr(st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, st->Q_syn, NS2SA(16000, DELAY_CLDFB_NS)); - fixedToFloat_arr(st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, st->Q_syn, INTERP_3_1_MEM_LEN); - } - /*WI_DEC_HANDLE*/ - if (st->hWIDec) { - fixedToFloat_arr(st->hWIDec->old_exc2_fx, st->hWIDec->old_exc2, st->Q_exc, L_EXC_MEM); - fixedToFloat_arr(st->hWIDec->old_syn2_fx, st->hWIDec->old_syn2, st->Q_syn, L_EXC_MEM); - } - /*BPF_DEC_HANDLE*/ - if (st->hBPF) { - fixedToFloat_arr(st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, st->Q_syn, NBPSF_PIT_MAX); - st->hBPF->pst_mem_deemp_err = fixedToFloat(st->hBPF->pst_mem_deemp_err_fx, st->Q_syn); - st->hBPF->pst_lp_ener = fixedToFloat(st->hBPF->pst_lp_ener_fx, Q8); - Copy(st->hBPF->Track_on_hist_fx, st->hBPF->Track_on_hist, L_TRACK_HIST); - Copy(st->hBPF->vibrato_hist_fx, st->hBPF->vibrato_hist, L_TRACK_HIST); - st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15); - fixedToFloat_arr(st->hBPF->mem_mean_pit_fx, st->hBPF->mem_mean_pit, Q4, L_TRACK_HIST); - } - /*PFSTAT_HANDLE*/ - if (st->hPFstat) { - fixedToFloat_arr(st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, st->Q_syn, L_SUBFR); - fixedToFloat_arr(st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, st->Q_syn, L_SUBFR); - fixedToFloat_arr(st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, DECMEM_RES2); - fixedToFloat_arr(st->hPFstat->mem_res2, st->hPFstat->mem_res2_flt, st->Q_syn, M); - st->hPFstat->gain_prec_flt = fixedToFloat(st->hPFstat->gain_prec, Q14); - } - /*Missing parameters*/ - st->prev_gain_pit_dec = fixedToFloat(st->prev_gain_pit_dec_fx, Q14); - fixedToFloat_arr(st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k); - fixedToFloat_arr(st->previoussynth_fx, st->previoussynth, 0, L_FRAME48k); - fixedToFloat_arr(st->old_Aq_12_8_fx, st->old_Aq_12_8, Q14, M + 1); - st->old_Es_pred = fixedToFloat(st->old_Es_pred_fx, Q8); - fixedToFloat_arr(st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2); - fixedToFloat_arr(st->mem_syn_r, st->mem_syn_r_float, st->Q_syn, L_SYN_MEM); - fixedToFloat_arr(st->bpf_noise_buf, st->bpf_noise_buf_float, st->Q_syn, L_FRAME16k); - st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); - st->last_coder_type = st->last_coder_type; -#endif } static void rescale_fdCngDec(HANDLE_FD_CNG_DEC hFdCngDec, Word16 Exp_diff) { diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index dba2c46ff..1f45db97c 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -446,7 +446,7 @@ ivas_error acelp_core_switch_dec_bfi_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi(MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq, lsf_new, lsp_new); @@ -542,8 +542,8 @@ ivas_error acelp_core_switch_dec_bfi_fx( tmp_float3 = st_fx->stab_fac_smooth_fx; move16(); Copy(hBPF->mem_mean_pit_fx,tmp_float4, L_TRACK_HIST); - Copy(hBPF->Track_on_hist_fx,tmp_float5, L_TRACK_HIST); - Copy(hBPF->vibrato_hist_fx,tmp_float6, L_TRACK_HIST); + Copy(hBPF->Track_on_hist,tmp_float5, L_TRACK_HIST); + Copy(hBPF->vibrato_hist,tmp_float6, L_TRACK_HIST); tmp_float7 = hBPF->psf_att_fx; move16(); @@ -552,8 +552,8 @@ ivas_error acelp_core_switch_dec_bfi_fx( Copy(tmp_float, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX); Copy(tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST); - Copy(tmp_float5, hBPF->Track_on_hist_fx, L_TRACK_HIST); - Copy(tmp_float6, hBPF->vibrato_hist_fx, L_TRACK_HIST); + Copy(tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST); + Copy(tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST); hBPF->psf_att_fx = tmp_float7 ; /*----------------------------------------------------------------* * Resamping to the output sampling frequency @@ -687,7 +687,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi(MODE1, lsf_new, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq, lsf_new, lsp_new); @@ -783,8 +783,8 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( tmp_float3 = st_fx->stab_fac_smooth_fx; move16(); Copy(hBPF->mem_mean_pit_fx,tmp_float4, L_TRACK_HIST); - Copy(hBPF->Track_on_hist_fx,tmp_float5, L_TRACK_HIST); - Copy(hBPF->vibrato_hist_fx,tmp_float6, L_TRACK_HIST); + Copy(hBPF->Track_on_hist,tmp_float5, L_TRACK_HIST); + Copy(hBPF->vibrato_hist,tmp_float6, L_TRACK_HIST); tmp_float7 = hBPF->psf_att_fx; move16(); @@ -793,8 +793,8 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy(tmp_float, hBPF->pst_old_syn_fx, NBPSF_PIT_MAX); Copy(tmp_float4, hBPF->mem_mean_pit_fx, L_TRACK_HIST); - Copy(tmp_float5, hBPF->Track_on_hist_fx, L_TRACK_HIST); - Copy(tmp_float6, hBPF->vibrato_hist_fx, L_TRACK_HIST); + Copy(tmp_float5, hBPF->Track_on_hist, L_TRACK_HIST); + Copy(tmp_float6, hBPF->vibrato_hist, L_TRACK_HIST); hBPF->psf_att_fx = tmp_float7 ; /*----------------------------------------------------------------* * Resamping to the output sampling frequency diff --git a/lib_dec/amr_wb_dec.c b/lib_dec/amr_wb_dec.c index 80febf6f5..2a0db250d 100644 --- a/lib_dec/amr_wb_dec.c +++ b/lib_dec/amr_wb_dec.c @@ -165,29 +165,28 @@ ivas_error amr_wb_dec_flt( } /* Updates in case of HQ -> AMR-WB IO switching */ -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_ #if 1 /*Float to fix conversions*/ Word16 nchan_out = -1; Word16 last_element_brate = -1; - Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, + Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_old_exc, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ Q_mem_syn2 = Q_factor_arr( st->mem_syn2, M ); - Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); + //Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ); - Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); - Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); + //Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); + Q_mem_syn = 0; + //Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); Q_syn = Q_factor_arr( st->syn_float, M + 1 ); Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) ) - 1; Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); floatToFixed_arr16( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); + //floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); + //floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); floatToFixed_arr16( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); st->mem_deemph_fx = (Word16) floatToFixed( st->mem_deemph, Q_mem_deemph ); - st->psf_lp_noise_fx = (Word16) floatToFixed( st->psf_lp_noise, Q7 ); /*Used floatToFixed because does not give error in case of garbage value*/ - st->lp_noise = float_to_fix16( st->lp_noise_float, Q7 ); floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); IF( st->hBPF ) { @@ -196,12 +195,6 @@ ivas_error amr_wb_dec_flt( floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); } - IF( st->hBWE_TD ) - { - Q_old_bwe_exc = Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); - st->hBWE_TD->bwe_non_lin_prev_scale_fx = float_to_fix( st->hBWE_TD->bwe_non_lin_prev_scale, 30 ); - floatToFixed_arr32( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx_32, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } IF( st->hBWE_zero ) { Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); @@ -271,10 +264,6 @@ ivas_error amr_wb_dec_flt( floatToFixed_arr16( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 258 ); FOR( i = 0; i < M; i++ ) { - st->lsf_old_fx[i] = (Word16)float_to_fix16( ( st->lsf_old[i] * (2.56f / st->scale)), 0); - st->lsfoldbfi1_fx[i] = (Word16)float_to_fix16((st->lsfoldbfi1[i] * (2.56f / st->scale_lsfbfi)), 0); - st->lsfoldbfi0_fx[i] = (Word16)float_to_fix16((st->lsfoldbfi0[i] * (2.56f / st->scale_lsfbfi)), 0); - st->lsf_adaptive_mean_fx[i] = (Word16)float_to_fix16((st->lsf_adaptive_mean[i] * (2.56f / st->scale_lsfbfi)), 0); st->lsp_old_fx[i] = float_to_fix16(st->lsp_old[i], 15); st->mem_AR_fx[i] = (Word16)float_to_fix16( ( st->mem_AR[i] * 2.56f ), 0 ); st->mem_MA_fx[i] = (Word16) ( ( st->mem_MA[i] * 2.56f ) ); @@ -290,8 +279,8 @@ ivas_error amr_wb_dec_flt( } IF( st->cldfbBPF ) floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); - Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; - floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); + //Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; + //floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); st->enr_old_fx = (Word32) st->enr_old; st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); @@ -313,10 +302,10 @@ ivas_error amr_wb_dec_flt( return error; } #if 1 /*Fixed to float function changes*/ - fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); - fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); + //fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); + fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, -1, M ); + //fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); - st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q7 ); /*psf_lp_noise_fx has Q7*/ fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, 258 ); @@ -326,15 +315,11 @@ ivas_error amr_wb_dec_flt( { st->mem_MA[i] = (float) ( st->mem_MA_fx[i] / 2.56f ); st->mem_AR[i] = (float) ( st->mem_AR_fx[i] / 2.56f ); - st->lsf_old[i] = (float) ( st->lsf_old_fx[i] / (2.56f / st->scale)); - st->lsfoldbfi1[i] = (float)(st->lsfoldbfi1_fx[i] / (2.56f / st->scale_lsfbfi)); - st->lsfoldbfi0[i] = (float)(st->lsfoldbfi0_fx[i] / (2.56f / st->scale_lsfbfi)); - st->lsf_adaptive_mean[i] = (float)(st->lsf_adaptive_mean_fx[i] / (2.56f / st->scale_lsfbfi)); st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); } fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn, L_SYN_MEM ); fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn, M ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); + //fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); IF( st->hBPF ) { fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); @@ -350,11 +335,6 @@ ivas_error amr_wb_dec_flt( } IF( st->hBWE_FD ) fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - IF( st->hBWE_TD ) - { - st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( st->hBWE_TD->bwe_non_lin_prev_scale_fx, 30 ); - fixedToFloat_arrL( st->hBWE_TD->old_bwe_exc_fx_32, st->hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } IF( st->hBWE_zero ) { fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index fbdbf258f..63d0d75e8 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -588,7 +588,7 @@ ivas_error amr_wb_dec_fx( * Improvement for unvoiced and audio signals *------------------------------------------------------------*/ - improv_amr_wb_gs_fx(amr_io_class, st_fx->coder_type, st_fx->core_brate, &st_fx->hGSCDec->seed_tcx_fx, st_fx->hAmrwb_IO->old_Aq_fx, st_fx->mem_syn2_fx, st_fx->hAmrwb_IO->lt_voice_fac_fx, + improv_amr_wb_gs_fx(amr_io_class, st_fx->coder_type, st_fx->core_brate, &st_fx->hGSCDec->seed_tcx, st_fx->hAmrwb_IO->old_Aq_fx, st_fx->mem_syn2_fx, st_fx->hAmrwb_IO->lt_voice_fac_fx, locattack, Aq_fx, exc2_fx, st_fx->Q_exc, mem_tmp_fx, syn_fx, st_fx->Q_syn, pitch_buf_fx, st_fx->hAmrwb_IO->Last_ener_fx, st_fx->rate_switching_reset, st_fx->last_coder_type); FOR( i = 0; i < DCT_L_POST; i++ ) @@ -647,7 +647,7 @@ ivas_error amr_wb_dec_fx( /* LSF estimation and A(z) calculation */ lsf_dec_bfi( MODE1, lsf_new_fx, st_fx->lsf_old_fx, st_fx->lsf_adaptive_mean_fx, NULL, st_fx->mem_MA_fx, st_fx->mem_AR_fx, st_fx->stab_fac_fx, st_fx->last_coder_type, st_fx->L_frame, st_fx->last_good, - st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx_fx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); + st_fx->nbLostCmpt, 0, NULL, NULL, NULL, st_fx->hGSCDec->Last_GSC_pit_band_idx, st_fx->Opt_AMR_WB, 0, st_fx->bwidth); FEC_lsf2lsp_interp( st_fx, st_fx->L_frame, Aq_fx, lsf_new_fx, lsp_new_fx ); /* calculation of excitation signal */ @@ -1024,7 +1024,7 @@ ivas_error amr_wb_dec_fx( move16(); test(); - IF( st_fx->prev_bfi && hHQ_core->HqVoicing_fx ) + IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { Copy_Scale_sig(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps,negate(st_fx->Q_syn2)); } diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index 7a5d8476b..c796af9b8 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -39,8 +39,8 @@ void bass_psfilter_init_fx( hBPF->pst_lp_ener_fx = 0; move16();/*0 in Q8 */ set16_fx(hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX); - set16_fx(hBPF->Track_on_hist_fx, 0, L_TRACK_HIST); - set16_fx(hBPF->vibrato_hist_fx, 0, L_TRACK_HIST); + set16_fx(hBPF->Track_on_hist, 0, L_TRACK_HIST); + set16_fx(hBPF->vibrato_hist, 0, L_TRACK_HIST); set16_fx(hBPF->mem_mean_pit_fx, 80, L_TRACK_HIST); hBPF->psf_att_fx = 32767; @@ -189,13 +189,13 @@ void bass_psfilter_fx( move16(); } - tmp = sum16_fx(hBPF->Track_on_hist_fx,L_TRACK_HIST); + tmp = sum16_fx(hBPF->Track_on_hist,L_TRACK_HIST); #ifdef BASOP_NOGLOB TrackOnR = round_fx_sat(L_shl_sat(L_mult0(tmp,3277),16)); /*Q15 */ #else TrackOnR = round_fx(L_shl(L_mult0(tmp,3277),16)); /*Q15 */ #endif - vibratR = sum16_fx(hBPF->vibrato_hist_fx,L_TRACK_HIST); /*Q0 */ + vibratR = sum16_fx(hBPF->vibrato_hist,L_TRACK_HIST); /*Q0 */ alp_tmp = sub(32767,TrackOnR); /*Q15 */ @@ -323,10 +323,10 @@ void bass_psfilter_fx( { Lcorr0 = L_mult0( syn_fx[j], syn2_fx[j]); Lener0 = L_mult0(syn2_fx[j], syn2_fx[j]); - Lcorr0 = L_mac0(Lcorr0, syn_fx[j+1], syn2_fx[j+1]); - Lener0 = L_mac0(Lener0, syn2_fx[j+1], syn2_fx[j+1]); + Lcorr0 = L_mac0_sat(Lcorr0, syn_fx[j+1], syn2_fx[j+1]); + Lener0 = L_mac0_sat(Lener0, syn2_fx[j+1], syn2_fx[j+1]); - Lcorr = L_add(Lcorr, L_shr(Lcorr0, 4)); + Lcorr = L_add_sat(Lcorr, L_shr(Lcorr0, 4)); Lener = L_add(Lener, L_shr(Lener0, 4)); /* this loop is not efficient but it provide a respectable precision while avoiding overflow. */ @@ -403,7 +403,7 @@ void bass_psfilter_fx( exp2 = sub(exp, exp2); /* exponent num - exponent denom */ /* alpha = corr / ener */ #ifdef BASOP_NOGLOB - alpha = shr_sat(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ + alpha = shr_sat(div_s(round_fx_sat(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ #else alpha = shr(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ #endif @@ -452,7 +452,7 @@ void bass_psfilter_fx( FOR (i=0; i< subfr_len; i++) { /*syn2_fx[i] = alpha*(syn_fx[i]-syn2_fx[i]); */ - tmp = sub(syn_fx[i],syn2_fx[i]); + tmp = sub_sat(syn_fx[i],syn2_fx[i]); #ifdef BASOP_NOGLOB syn2_fx[i] = mult_sat(alpha, shl_sat(tmp, 1)); #else @@ -708,15 +708,15 @@ void bass_psfilter_fx( FOR( i = L_TRACK_HIST-1; i > 0; i-- ) { - hBPF->Track_on_hist_fx[i] = hBPF->Track_on_hist_fx[i-1]; + hBPF->Track_on_hist[i] = hBPF->Track_on_hist[i-1]; move16(); - hBPF->vibrato_hist_fx[i] = hBPF->vibrato_hist_fx[i-1]; + hBPF->vibrato_hist[i] = hBPF->vibrato_hist[i-1]; move16(); } - hBPF->Track_on_hist_fx[i] = Track_on; + hBPF->Track_on_hist[i] = Track_on; move16(); - hBPF->vibrato_hist_fx[i] = vibrato; + hBPF->vibrato_hist[i] = vibrato; move16(); Copy( syn_buf_fx+L_frame, hBPF->pst_old_syn_fx, nbpsf_pit_max ); diff --git a/lib_dec/core_dec_switch.c b/lib_dec/core_dec_switch.c index 8c74d7fa5..ee8ae2088 100644 --- a/lib_dec/core_dec_switch.c +++ b/lib_dec/core_dec_switch.c @@ -162,10 +162,6 @@ void mode_switch_decoder_LPD_flt( lsp2lsf( st->lsp_old, st->lsfoldbfi1, M, st->sr_core ); mvr2r( st->lsfoldbfi1, st->lsfoldbfi0, M ); mvr2r( st->lsfoldbfi1, st->lsf_adaptive_mean, M ); -#ifdef IVAS_FLOAT_FIXED - // To be removed - st->scale_lsfbfi = (float) st->sr_core / INT_FS_12k8; -#endif // IVAS_FLOAT_FIXED; if ( st->igf && st->hBWE_TD != NULL ) { diff --git a/lib_dec/core_dec_switch_fx.c b/lib_dec/core_dec_switch_fx.c index 2a3a0afba..a8923e07d 100644 --- a/lib_dec/core_dec_switch_fx.c +++ b/lib_dec/core_dec_switch_fx.c @@ -410,18 +410,10 @@ void mode_switch_decoder_LPD_ivas_fx( IF( EQ_16( st->tcxonly, 0 ) ) { lsp2lsf_fx( st->lsp_old_fx, st->lsfoldbfi1_fx, M, extract_l( st->sr_core ) ); -#ifdef IVAS_FLOAT_FIXED - // To be removed - st->scale_lsfbfi = (float) st->sr_core / INT_FS_12k8; -#endif // IVAS_FLOAT_FIXED } ELSE { E_LPC_lsp_lsf_conversion( st->lsp_old_fx, st->lsfoldbfi1_fx, M ); -#ifdef IVAS_FLOAT_FIXED - // To be removed - st->scale_lsfbfi = (float) st->sr_core / INT_FS_12k8; -#endif // IVAS_FLOAT_FIXED } Copy( st->lsfoldbfi1_fx, st->lsfoldbfi0_fx, M ); Copy( st->lsfoldbfi1_fx, st->lsf_adaptive_mean_fx, M ); diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 1ed958a73..e878a1cba 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -100,7 +100,7 @@ ivas_error core_switching_pre_dec_ivas_fx( st->hBPF->pst_mem_deemp_err_32 = 0; move32(); } - st->psf_lp_noise_fx = (Word16) st->lp_noise; + st->psf_lp_noise_fx = round_fx(L_shl(st->lp_noise, 1)); move16(); /* reset old HB synthesis buffer */ @@ -118,7 +118,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( st->hBWE_TD != NULL && NE_16( st->last_core, ACELP_CORE ) ) { /* reset BWE memories */ - set32_fx( st->hBWE_TD->old_bwe_exc_fx_32, 0, PIT16k_MAX * 2 ); + set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); } @@ -452,7 +452,7 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( st->hBWE_TD != NULL ) { - set32_fx( st->hBWE_TD->old_bwe_exc_fx_32, 0, PIT16k_MAX * 2 ); + set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } IF( GT_32( st->output_Fs, 16000 ) && st->hBWE_zero != NULL ) @@ -472,7 +472,7 @@ ivas_error core_switching_pre_dec_ivas_fx( { st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; move32(); - set32_fx( st->hBWE_TD->old_bwe_exc_fx_32, 0, PIT16k_MAX * 2 ); + set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); } #if 1 st->tilt_code = 0.0f; diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index dbb1ed21c..e5064a1fe 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -243,7 +243,7 @@ void bw_switching_pre_proc_fx( } ELSE { - IF( st_fx->hHQ_core->old_is_transient_fx[0] ) + IF( st_fx->hHQ_core->old_is_transient[0] ) { L_tmp = L_deposit_l(0); FOR ( i=0; i<32; i++ ) @@ -562,7 +562,7 @@ ivas_error core_switching_pre_dec_fx( set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); - hHQ_core->last_max_pos_pulse_fx = 0; + hHQ_core->last_max_pos_pulse = 0; move16(); IF(GT_32(st_fx->output_Fs, 16000)) @@ -594,13 +594,13 @@ ivas_error core_switching_pre_dec_fx( { set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); - hHQ_core->last_max_pos_pulse_fx = 0; + hHQ_core->last_max_pos_pulse = 0; move16(); set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - hHQ_core->prev_frm_hfe2_fx = 0; + hHQ_core->prev_frm_hfe2 = 0; move16(); - hHQ_core->prev_stab_hfe2_fx = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); } } @@ -612,8 +612,8 @@ ivas_error core_switching_pre_dec_fx( /*switch off Hq Voicing as it was not uodated in MODE2*/ IF(hHQ_core != NULL) { - hHQ_core->oldHqVoicing_fx = 0; - hHQ_core->HqVoicing_fx = 0; + hHQ_core->oldHqVoicing = 0; + hHQ_core->HqVoicing = 0; move16();move16(); } @@ -914,11 +914,11 @@ ivas_error core_switching_pre_dec_fx( set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse_fx = 0; + hHQ_core->last_max_pos_pulse = 0; set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM ); - hHQ_core->prev_frm_hfe2_fx = 0; - hHQ_core->prev_stab_hfe2_fx = 0; + hHQ_core->prev_frm_hfe2 = 0; + hHQ_core->prev_stab_hfe2 = 0; IF( GT_32(st_fx->output_Fs,16000)) { @@ -1313,7 +1313,7 @@ ivas_error core_switching_post_dec_fx( tmp = i_mult2(delta, N_ZERO_8); shift = i_mult2(Fs_kHz, 3); test(); - IF( st_fx->prev_bfi && hHQ_core->HqVoicing_fx ) + IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { Copy_Scale_sig(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[tmp], shift, *Qsynth ); } @@ -1332,13 +1332,13 @@ ivas_error core_switching_post_dec_fx( } set16_fx( st_fx->delay_buf_out_fx, 0, HQ_DELTA_MAX*HQ_DELAY_COMP ); - hHQ_core->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing = 0; move16(); set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - hHQ_core->prev_frm_hfe2_fx = 0; + hHQ_core->prev_frm_hfe2 = 0; move16(); - hHQ_core->prev_stab_hfe2_fx = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); } @@ -1858,7 +1858,7 @@ ivas_error core_switching_post_dec_ivas_fx( nzeroes = i_mult2( delta, N_ZERO_8 ); shift = i_mult2( Fs_kHz, 3 ); test(); - IF( st_fx->prev_bfi && hHQ_core->HqVoicing_fx && st_fx->hHQ_core != NULL && st_fx->last_core == HQ_CORE ) + IF( st_fx->prev_bfi && hHQ_core->HqVoicing && st_fx->hHQ_core != NULL && st_fx->last_core == HQ_CORE ) { Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nzeroes], shift, *Qsynth ); } diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index 1e53cbb8c..4ce51f46b 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -594,7 +594,6 @@ 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 ); @@ -603,7 +602,6 @@ void decoder_LPD_flt( //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); @@ -712,7 +710,6 @@ 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 ); @@ -721,7 +718,6 @@ void decoder_LPD_flt( //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); diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 489aba798..5203f0016 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -684,7 +684,7 @@ ivas_error decod_gen_voic_ivas_fx( IF(EQ_16(L_frame, L_FRAME)) /* Rescaling for 12.8k core */ { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL)?&bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type); } @@ -704,7 +704,12 @@ ivas_error decod_gen_voic_ivas_fx( IF(gain_preQ_fx != 0) { - tmp1_fx = add(15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc); + if (st_fx->element_mode == EVS_MONO) { + tmp1_fx = add(15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc); + } + else { + tmp1_fx = add(15 - Q_AVQ_OUT - 2, st_fx->Q_exc); + } FOR(i = 0; i < L_SUBFR; i++) { Word32 Ltmp1; diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index 5b9c65f97..5f5a3970f 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -123,15 +123,22 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE_AVQ AVQ_demuxdec_fx(st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos); + Word16 q_Code_preQ; + IF (st_fx->element_mode == EVS_MONO) { + q_Code_preQ = Q_AVQ_OUT_DEC; + } + ELSE { + q_Code_preQ = Q_AVQ_OUT; + } #else AVQ_demuxdec_fx(st_fx, code_preQ, &nBits, 8, nq ); #endif FOR( i=0; ielement_mode, EVS_MONO) && NE_16(st_fx->coder_type, INACTIVE) && GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && !harm_flag_acelp && code_preQ[0] != 0) - { - //PMT("Fixed point taking accound of the scaling needs to be done here ") - IF (GT_16(abs_s(st_fx->last_code_preq), shl_sat(abs_s(code_preQ[0]),4))) - { - st_fx->mem_preemp_preQ /= 16; - } - ELSE IF (GT_16(abs_s((st_fx->last_code_preq)), shl_sat(abs_s(code_preQ[0]),3))) - { - st_fx->mem_preemp_preQ /= 8; - } - } - - st_fx->last_code_preq = (Word16)code_preQ[L_SUBFR - 1]; -#endif /*--------------------------------------------------------------* * Preemphasise *--------------------------------------------------------------*/ @@ -187,6 +177,23 @@ void transf_cdbk_dec_fx( st_fx->last_nq_preQ = nq[7]; move16(); +#ifdef IVAS_CODE_AVQ + /* TD pre-quantizer: in extreme cases at subframe boundaries, lower the preemphasis memory to avoid a saturation */ + IF(GT_16(st_fx->element_mode, EVS_MONO) && NE_16(st_fx->coder_type, INACTIVE) && GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC) && LE_32(st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD) && !harm_flag_acelp && code_preQ[0] != 0) + { + //PMT("Fixed point taking accound of the scaling needs to be done here ") + IF(GT_16(abs_s(st_fx->last_code_preq), shl_sat(abs_s(code_preQ[0]), 4))) + { + st_fx->mem_preemp_preQ_fx = shr(st_fx->mem_preemp_preQ_fx, 4); + } + ELSE IF(GT_16(abs_s((st_fx->last_code_preq)), shl_sat(abs_s(code_preQ[0]), 3))) + { + st_fx->mem_preemp_preQ_fx = shr(st_fx->mem_preemp_preQ_fx, 3); + } + } + + st_fx->last_code_preq = (Word16)code_preQ[L_SUBFR - 1]; +#endif preemph_fx( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx); /*--------------------------------------------------------------* * Compute normalized prequantizer excitation gain for FEC @@ -207,7 +214,7 @@ void transf_cdbk_dec_fx( } ELSE { - exp16 = sub(exp16, Q_AVQ_OUT_DEC*2 + 6); /* exp: (code_preQ in Q_AVQ_OUT_DEC), -6 (/L_SUBFR) */ + exp16 = sub(exp16, q_Code_preQ *2 + 6); /* exp: (code_preQ in q_Code_preQ), -6 (/L_SUBFR) */ L_tmp = Isqrt_lc(L_tmp, &exp16); tmp16 = extract_h(L_tmp); exp16 = 15 - 10 - exp16; /* tmp16 in Q10+exp16*/ diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index d53ab6b2b..cf28f654d 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -187,7 +187,12 @@ void decod_tran_fx( *-----------------------------------------------------------------*/ IF(GE_32(st_fx->core_brate, MIN_BRATE_AVQ_EXC)) { - tmp1_fx = add(15-Q_AVQ_OUT_DEC-2,st_fx->Q_exc); + IF (st_fx->element_mode == EVS_MONO) { + tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); + } + ELSE { + tmp1_fx = add(15 - Q_AVQ_OUT - 2, st_fx->Q_exc); + } FOR( i = 0; i < L_SUBFR; i++ ) { L_tmp = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q10 -> Q13*/ diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index d31cda7a0..58a9db842 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -206,7 +206,7 @@ void decod_unvoiced_ivas_fx( exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];*/ //Q16 exc2_fx[i + i_subfr_fx] = shl( mult_r( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 2 ); // Q_exc exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), Q10 - Q_exc ) ) ); // Q_exc - exc_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - Q_exc ) ) ); // Q_exc + exc_fx[i + i_subfr_fx] = add_sat( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - Q_exc ) ) ); // Q_exc } //Scale_sig(code_fx, L_SUBFR, 3); //Q12 } diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 815d398a6..28adaf8ac 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -281,28 +281,28 @@ ivas_error evs_dec_flt( * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_ #if 1 /*Float to fix conversions*/ Word16 nchan_out = -1; Word16 last_element_brate = -1; - Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, - Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_old_exc, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, + Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, + Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ Q_mem_syn2 = Q_factor_arr( st->mem_syn2, M ); - Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); + //Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ); - Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); - Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); + //Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); + Q_mem_syn = 0; + //Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); Q_syn = Q_factor_arr( st->syn_float, M + 1 ); Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) ) - 1; Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); floatToFixed_arr16( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); + //floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); + //floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); floatToFixed_arr16( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); st->mem_deemph_fx = (Word16) floatToFixed( st->mem_deemph, Q_mem_deemph ); - st->psf_lp_noise_fx = (Word16) floatToFixed( st->psf_lp_noise, Q7 ); /*Used floatToFixed because does not give error in case of garbage value*/ st->lp_noise = float_to_fix16( st->lp_noise_float, Q7 ); floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); IF( st->hBPF ) @@ -312,12 +312,6 @@ ivas_error evs_dec_flt( floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); } - IF( st->hBWE_TD ) - { - Q_old_bwe_exc = Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); - st->hBWE_TD->bwe_non_lin_prev_scale_fx = float_to_fix( st->hBWE_TD->bwe_non_lin_prev_scale, 30 ); - floatToFixed_arr32( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx_32, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } IF( st->hBWE_zero ) { Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); @@ -387,10 +381,6 @@ ivas_error evs_dec_flt( floatToFixed_arr16( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 258 ); FOR( i = 0; i < M; i++ ) { - st->lsf_old_fx[i] = float_to_fix16( ( st->lsf_old[i] * (2.56f / st->scale)), 0); - st->lsfoldbfi1_fx[i] = float_to_fix16((st->lsfoldbfi1[i] * (2.56f / st->scale_lsfbfi)), 0); - st->lsfoldbfi0_fx[i] = float_to_fix16((st->lsfoldbfi0[i] * (2.56f / st->scale_lsfbfi)), 0); - st->lsf_adaptive_mean_fx[i] = float_to_fix16((st->lsf_adaptive_mean[i] * (2.56f / st->scale_lsfbfi)), 0 ); st->lsp_old_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); st->mem_AR_fx[i] = float_to_fix16( ( st->mem_AR[i] * 2.56f ), 0 ); st->mem_MA_fx[i] = (Word16) ( ( st->mem_MA[i] * 2.56f ) ); @@ -406,8 +396,8 @@ ivas_error evs_dec_flt( } IF( st->cldfbBPF ) floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); - Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; - floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); + //Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; + //floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); st->enr_old_fx = (Word32) st->enr_old; st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); @@ -429,10 +419,9 @@ ivas_error evs_dec_flt( return error; } #if 1 /*Fixed to float function changes*/ - fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); - fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); + //fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); + //fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); - st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q7 ); /*psf_lp_noise_fx has Q7*/ fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, 258 ); @@ -442,15 +431,11 @@ ivas_error evs_dec_flt( { st->mem_MA[i] = (float) ( st->mem_MA_fx[i] / 2.56f ); st->mem_AR[i] = (float)(st->mem_AR_fx[i] / 2.56f ); - st->lsf_old[i] = (float)(st->lsf_old_fx[i] / (2.56f / st->scale)); - st->lsfoldbfi1[i] = (float)(st->lsfoldbfi1_fx[i] / (2.56f / st->scale_lsfbfi)); - st->lsfoldbfi0[i] = (float)(st->lsfoldbfi0_fx[i] / (2.56f / st->scale_lsfbfi)); - st->lsf_adaptive_mean[i] = (float)(st->lsf_adaptive_mean_fx[i] / (2.56f / st->scale_lsfbfi)); st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); } fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn, L_SYN_MEM ); fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn, M ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); + //fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); IF( st->hBPF ) { fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); @@ -466,11 +451,6 @@ ivas_error evs_dec_flt( } IF( st->hBWE_FD ) fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - IF( st->hBWE_TD ) - { - st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( st->hBWE_TD->bwe_non_lin_prev_scale_fx, 30 ); - fixedToFloat_arrL( st->hBWE_TD->old_bwe_exc_fx_32, st->hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } IF( st->hBWE_zero ) { fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); @@ -560,7 +540,6 @@ ivas_error evs_dec_flt( q_audio = norm - gb; ivas_bw_switching_pre_proc_fx(st, -1, 1, old_syn_12k8_16k_fx, 11, q_audio); st->enerLH = fixedToFloat(st->enerLH_fx, st->enerLH_fx_Q); // Q / 2 - st->tilt_wb = fix16_to_float(st->tilt_wb_fx, 11); st->enerLL = fixedToFloat(st->enerLL_fx, st->enerLL_fx_Q ); #else bw_switching_pre_proc( st, old_syn_12k8_16k, -1, 1 ); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 368eb3331..cd52ac0e8 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1171,7 +1171,7 @@ ivas_error evs_dec_fx( move16(); test(); - IF( st_fx->prev_bfi && hHQ_core->HqVoicing_fx ) + IF( st_fx->prev_bfi && hHQ_core->HqVoicing ) { Copy(hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nz], tmps); } diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index dd7126fc2..8b48daa3d 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -3145,7 +3145,37 @@ void generate_masking_noise_lb_dirac( fftBuffer[1] = 0.f; /* Perform STFT synthesis */ +#ifdef IVAS_FLOAT_FIXED + Word32 fftBuffer_fx[FFTLEN], timeDomainBuffer_fx[L_FRAME16k]; + Word16 exp = Q14; + for (i = 0; i < hFdCngCom->fftlen; i++) + { + fftBuffer_fx[i] = float_to_fix(fftBuffer[i], exp); + } + for (i = 0; i < hFdCngCom->fftlen; i++) + { + hFdCngCom->olapBufferSynth2_fx[i] = float_to_fix(hFdCngCom->olapBufferSynth2_flt[i], exp); + } + + SynthesisSTFT_dirac_fx(fftBuffer_fx, timeDomainBuffer_fx + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom); + + for (i = 0; i < hFdCngCom->fftlen; i++) + { + hFdCngCom->olapBufferSynth2_flt[i] = fix_to_float(hFdCngCom->olapBufferSynth2_fx[i], exp); + } + exp = exp - 9; + for (i = 0; i < hFdCngCom->frameSize; i++) + { + tdBuffer[i] = fix_to_float(timeDomainBuffer_fx[i], exp); + } + + for (i = 0; i < hFdCngCom->frameSize; i++) + { + hFdCngCom->exc_cng_flt[i] = fix_to_float(hFdCngCom->exc_cng_32fx[i], exp); + } +#else SynthesisSTFT_dirac_flt( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_flt, hFdCngCom->olapWinSyn_flt, n_samples_out_loop, hFdCngCom ); +#endif } @@ -3157,7 +3187,37 @@ void generate_masking_noise_lb_dirac( set_f( fftBuffer, 0.f, hFdCngCom->fftlen ); /* Perform STFT synthesis */ +#ifdef IVAS_FLOAT_FIXED + Word32 fftBuffer_fx[FFTLEN], timeDomainBuffer_fx[L_FRAME16k]; + Word16 exp = Q14; + for (i = 0; i < hFdCngCom->fftlen; i++) + { + fftBuffer_fx[i] = float_to_fix(fftBuffer[i], exp); + } + for (i = 0; i < hFdCngCom->fftlen; i++) + { + hFdCngCom->olapBufferSynth2_fx[i] = float_to_fix(hFdCngCom->olapBufferSynth2_flt[i], exp); + } + + SynthesisSTFT_dirac_fx(fftBuffer_fx, timeDomainBuffer_fx + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn, n_samples_out_loop, hFdCngCom); + + for (i = 0; i < hFdCngCom->fftlen; i++) + { + hFdCngCom->olapBufferSynth2_flt[i] = fix_to_float(hFdCngCom->olapBufferSynth2_fx[i], exp); + } + exp = exp - 9; + for (i = 0; i < hFdCngCom->frameSize; i++) + { + tdBuffer[i] = fix_to_float(timeDomainBuffer_fx[i], exp); + } + + for (i = 0; i < hFdCngCom->frameSize; i++) + { + hFdCngCom->exc_cng_flt[i] = fix_to_float(hFdCngCom->exc_cng_32fx[i], exp); + } +#else SynthesisSTFT_dirac_flt( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_flt, hFdCngCom->olapWinSyn_flt, n_samples_out_loop, hFdCngCom ); +#endif } n_samples_out -= hFdCngCom->frameSize; @@ -3170,7 +3230,137 @@ void generate_masking_noise_lb_dirac( return; } +#ifdef IVAS_FLOAT_FIXED +void generate_masking_noise_lb_dirac_fx( + HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */ + Word32 *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */ + const Word16 nCldfbTs, /* i : number of CLDFB slots that will be rendered */ + const Word16 cna_flag /* i : CNA flag for LB and HB */ +) +{ + Word16 i; + Word32 *cngNoiseLevel = hFdCngCom->cngNoiseLevel; + Word32 *fftBuffer = hFdCngCom->fftBuffer; + Word32 *ptr_r; + Word32 *ptr_i; + Word32 *ptr_level; + Word16 *seed = &( hFdCngCom->seed ); + Word32 scale; + Word16 n_samples_out, n_samples_start, n_samples_out_loop; + + push_wmops( "fd_cng_dirac" ); + + /* Init */ + scale = 0; + n_samples_out = i_mult(shr(hFdCngCom->frameSize, 4), nCldfbTs); + n_samples_start = 0; + Word16 exp_out = Q15; + /*LB CLDFB - CNA from STFT*/ + IF ( cna_flag ) + { + /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */ + IF ( GT_32(hFdCngCom->likelihood_noisy_speech_32fx, DELTA_MASKING_NOISE_Q31 )) + { + /* Compute additional CN level */ + FOR ( i = 0; i < 15; i++ ) + { + test(); test(); + IF ( ( EQ_16(hFdCngCom->CngBandwidth, scaleTable_cn_dirac[i].bwmode )) && + GE_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateFrom ) && + LT_32( hFdCngCom->CngBitrate, scaleTable_cn_dirac[i].bitrateTo ) ) + { + break; + } + } + + Word16 exp; + Word16 div1 = BASOP_Util_Divide1616_Scale(negate(scaleTable_cn_dirac[i].scale_ivas), L_shl(10, Q11), &exp); + exp = add(exp, sub(sub( 15, 13) , sub(15, 11))); + Word32 scale_temp = BASOP_util_Pow2(Mpy_32_16_1(LOG_10_BASE_2, div1), add(exp, 2), &exp); + scale_temp = L_sub(scale_temp, L_shl(1, Q31 - exp)); + scale = L_shl(scale_temp, exp - Q1); // Q30 + + scale = Mpy_32_32(scale, hFdCngCom->likelihood_noisy_speech_32fx); //Q30 + } + } + + /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/ + test(); test(); + IF ( cna_flag && tdBuffer != NULL ) + { + WHILE ( GT_16(n_samples_out, 0 )) + { + n_samples_out_loop = s_min( hFdCngCom->frameSize, n_samples_out ); + IF ( NE_16(scale, 0 )) + { + /*Generate LF comfort noise only at first slot, for the whole frame*/ + ptr_level = cngNoiseLevel; + + /* Generate Gaussian random noise in real and imaginary parts of the FFT bins + Amplitudes are adjusted to the estimated noise level cngNoiseLevel_flt in each bin */ + IF ( EQ_16(hFdCngCom->startBand, 0 )) + { + rand_gauss_fx( &fftBuffer[0], seed, exp_out); + ptr_r = fftBuffer + 2; + + Word16 exp2 = 31 - hFdCngCom->cngNoiseLevelExp; + Word32 sqr = Sqrt32(L_shr(Mpy_32_32(scale, *ptr_level), 1), &exp2); /* DC component in FFT */ + sqr = L_shl(sqr, exp2); + fftBuffer[0] = Mpy_32_32(fftBuffer[0], sqr); /* DC component in FFT */ + ptr_level++; + } + ELSE + { + fftBuffer[0] = 0; + set32_fx( fftBuffer + 2, 0, shl(sub( hFdCngCom->startBand, 1 ), 1) ); + ptr_r = fftBuffer + shl(hFdCngCom->startBand, 1); + } + ptr_i = ptr_r + 1; + + FOR ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ ) + { + rand_gauss_fx(ptr_r, seed, exp_out); + Word16 exp2 = sub(31, hFdCngCom->cngNoiseLevelExp); + Word32 mpy2 = Sqrt32(Mpy_32_32(scale, *ptr_level), &exp2); + (*ptr_r) = L_shl(Mpy_32_32(*ptr_r, mpy2), exp2); // hFdCngCom->fftBuffer_exp + exp2 - 31 + ptr_r += 2; + + /* Imaginary part in FFT bins */ + rand_gauss_fx(ptr_i, seed, exp_out); + (*ptr_i) = L_shl(Mpy_32_32(*ptr_i, mpy2), exp2); + ptr_i += 2; + } + /* Remaining FFT bins are set to zero */ + set32_fx( fftBuffer + shl(hFdCngCom->stopFFTbin,1), 0, sub(hFdCngCom->fftlen, shl(hFdCngCom->stopFFTbin, 1)) ); + /* Nyquist frequency is discarded */ + fftBuffer[1] = 0; + + /* Perform STFT synthesis */ + SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); + + } + + ELSE + { + /* very low level case - update random seeds */ + generate_masking_noise_update_seed( hFdCngCom ); + + set32_fx( fftBuffer, 0, hFdCngCom->fftlen ); + /* Perform STFT synthesis */ + SynthesisSTFT_dirac_fx( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2_fx, hFdCngCom->olapWinSyn_fx, n_samples_out_loop, hFdCngCom ); + } + hFdCngCom->fftBuffer_exp = sub(31, 15); + n_samples_out = sub(n_samples_out, hFdCngCom->frameSize); + n_samples_start = add(n_samples_start, hFdCngCom->frameSize); + } + } + + pop_wmops(); + + return; +} +#endif /*------------------------------------------------------------------- * generate_masking_noise_hf_cldfb() * diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index b215d98b4..b1fd76821 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1759,7 +1759,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl_sat( cngNoiseLevel[j], s ); move32(); } } diff --git a/lib_dec/gs_dec_fx.c b/lib_dec/gs_dec_fx.c index 2b352dd1a..a0a3c8fbe 100644 --- a/lib_dec/gs_dec_fx.c +++ b/lib_dec/gs_dec_fx.c @@ -111,9 +111,9 @@ void decod_audio_fx( { nb_subfr = NB_SUBFR; move16(); - hGSCDec->cor_strong_limit_fx = 0; + hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); #ifdef ADD_LRTD if (st_fx->GSC_IVAS_mode >= 1) @@ -139,11 +139,11 @@ void decod_audio_fx( { IF( LE_32(st_fx->core_brate,ACELP_8k00)) { - hGSCDec->noise_lev_fx = add((Word16)get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2); + hGSCDec->noise_lev = add((Word16)get_next_indice( st_fx, 2 ), NOISE_LEVEL_SP2); } ELSE { - hGSCDec->noise_lev_fx = add((Word16)get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0); + hGSCDec->noise_lev = add((Word16)get_next_indice( st_fx, 3 ), NOISE_LEVEL_SP0); } /*---------------------------------------------------------------* @@ -158,7 +158,7 @@ void decod_audio_fx( else #endif { - hGSCDec->cor_strong_limit_fx = 1; + hGSCDec->cor_strong_limit = 1; move16(); nb_subfr = SWNB_SUBFR; move16(); @@ -179,7 +179,7 @@ void decod_audio_fx( { nb_subfr = 2 * SWNB_SUBFR; move16(); - hGSCDec->cor_strong_limit_fx = 0; + hGSCDec->cor_strong_limit = 0; move16(); } #ifdef ADD_LRTD @@ -256,7 +256,7 @@ void decod_audio_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; move16(); } - hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; move16(); @@ -324,7 +324,7 @@ void decod_audio_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; move16(); - hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; move16(); } @@ -608,9 +608,9 @@ void decod_audio_ivas_fx( { nb_subfr = NB_SUBFR; move16(); - hGSCDec->cor_strong_limit_fx = 0; + hGSCDec->cor_strong_limit = 0; move16(); - hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); #if 1//def ADD_LRTD if (st_fx->GSC_IVAS_mode >= 1) @@ -619,15 +619,15 @@ void decod_audio_ivas_fx( { nb_subfr = 2; } - hGSCDec->noise_lev_fx = NOISE_LEVEL_SP2; + hGSCDec->noise_lev = NOISE_LEVEL_SP2; if (st_fx->GSC_IVAS_mode == 3) /* Music like */ { - hGSCDec->noise_lev_fx = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; } else if (st_fx->GSC_noisy_speech == 0) /* speech like but not noisy */ { - hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3; + hGSCDec->noise_lev = NOISE_LEVEL_SP3; } } #endif @@ -636,11 +636,11 @@ void decod_audio_ivas_fx( { IF(LE_32(st_fx->core_brate,ACELP_8k00)) { - hGSCDec->noise_lev_fx = add((Word16)get_next_indice(st_fx, 2), NOISE_LEVEL_SP2); + hGSCDec->noise_lev = add((Word16)get_next_indice(st_fx, 2), NOISE_LEVEL_SP2); } ELSE { - hGSCDec->noise_lev_fx = add((Word16)get_next_indice(st_fx, 3), NOISE_LEVEL_SP0); + hGSCDec->noise_lev = add((Word16)get_next_indice(st_fx, 3), NOISE_LEVEL_SP0); } /*---------------------------------------------------------------* @@ -649,13 +649,13 @@ void decod_audio_ivas_fx( #if 1//def ADD_LRTD if (st_fx->L_frame == L_FRAME16k && (st_fx->core_brate <= ACELP_13k20 || st_fx->coder_type == INACTIVE)) { - hGSCDec->cor_strong_limit_fx = 0; + hGSCDec->cor_strong_limit = 0; nb_subfr = 1; } else #endif { - hGSCDec->cor_strong_limit_fx = 1; + hGSCDec->cor_strong_limit = 1; move16(); nb_subfr = SWNB_SUBFR; move16(); @@ -676,7 +676,7 @@ void decod_audio_ivas_fx( { nb_subfr = 2 * SWNB_SUBFR; move16(); - hGSCDec->cor_strong_limit_fx = 0; + hGSCDec->cor_strong_limit = 0; move16(); } #if 1//def ADD_LRTD @@ -753,7 +753,7 @@ void decod_audio_ivas_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; move16(); } - hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; move16(); @@ -821,7 +821,7 @@ void decod_audio_ivas_fx( Diff_len = mfreq_loc_div_25[pit_band_idx]; move16(); - hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; move16(); } @@ -1167,7 +1167,7 @@ void gsc_dec_fx( { FOR( i=0; iL_frame; i++ ) { - L_tmp = L_shr(L_mult(Random(&hGSCDec->seed_tcx_fx),26214),5); /*Q10*/ + L_tmp = L_shr(L_mult(Random(&hGSCDec->seed_tcx),26214),5); /*Q10*/ L_tmp = L_mac(L_tmp, hGSCDec->Last_GSC_spectrum_fx[i],6554); hGSCDec->Last_GSC_spectrum_fx[i] = round_fx(L_tmp); /*Q10*/ } @@ -1187,7 +1187,7 @@ void gsc_dec_fx( * PVQ decoder *--------------------------------------------------------------------------------------*/ - bands_and_bit_alloc_fx(hGSCDec->cor_strong_limit_fx, hGSCDec->noise_lev_fx, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, + bands_and_bit_alloc_fx(hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); @@ -1245,7 +1245,7 @@ void gsc_dec_fx( } } - hGSCDec->seed_tcx_fx = seed_init; + hGSCDec->seed_tcx = seed_init; move16(); } test(); @@ -1292,7 +1292,7 @@ void gsc_dec_fx( else #endif { - freq_dnw_scaling_fx(hGSCDec->cor_strong_limit_fx, st_fx->coder_type, hGSCDec->noise_lev_fx, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame); + freq_dnw_scaling_fx(hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame); } } @@ -1300,9 +1300,9 @@ void gsc_dec_fx( * Estimate noise level *--------------------------------------------------------------------------------------*/ - highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev_fx, pit_band_idx, exc_diffQ, - &hGSCDec->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band_fx, bitallocation_exc, st_fx->bfi, coder_type, + highband_exc_dct_in_fx( st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, + &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, + hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx , st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); @@ -1481,7 +1481,7 @@ void gsc_dec_ivas_fx( { FOR(i = 0; i < st_fx->L_frame; i++) { - L_tmp = L_shr(L_mult(Random(&hGSCDec->seed_tcx_fx), 26214), 5); /*Q10*/ + L_tmp = L_shr(L_mult(Random(&hGSCDec->seed_tcx), 26214), 5); /*Q10*/ L_tmp = L_mac(L_tmp, hGSCDec->Last_GSC_spectrum_fx[i], 6554); hGSCDec->Last_GSC_spectrum_fx[i] = round_fx(L_tmp); /*Q10*/ } @@ -1501,7 +1501,7 @@ void gsc_dec_ivas_fx( * PVQ decoder *--------------------------------------------------------------------------------------*/ - bands_and_bit_alloc_ivas_fx(hGSCDec->cor_strong_limit_fx, hGSCDec->noise_lev_fx, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, + bands_and_bit_alloc_ivas_fx(hGSCDec->cor_strong_limit, hGSCDec->noise_lev, st_fx->core_brate, Diff_len, bit, &bit, Ener_per_bd_iQ, max_ener_band, bits_per_bands, &nb_subbands, NULL, NULL, &pvq_len, coder_type, st_fx->bwidth, st_fx->GSC_noisy_speech, st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode); @@ -1574,7 +1574,7 @@ void gsc_dec_ivas_fx( } } - hGSCDec->seed_tcx_fx = seed_init; + hGSCDec->seed_tcx = seed_init; move16(); } test(); @@ -1623,7 +1623,7 @@ void gsc_dec_ivas_fx( ELSE #endif { - freq_dnw_scaling_fx(hGSCDec->cor_strong_limit_fx, st_fx->coder_type, hGSCDec->noise_lev_fx, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame); + freq_dnw_scaling_fx(hGSCDec->cor_strong_limit, st_fx->coder_type, hGSCDec->noise_lev, st_fx->core_brate, exc_diffQ, Qexc_diffQ, st_fx->L_frame); } } @@ -1631,9 +1631,9 @@ void gsc_dec_ivas_fx( * Estimate noise level *--------------------------------------------------------------------------------------*/ - highband_exc_dct_in_ivas_fx(st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev_fx, pit_band_idx, exc_diffQ, - &hGSCDec->seed_tcx_fx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, - hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band_fx, bitallocation_exc, st_fx->bfi, coder_type, + highband_exc_dct_in_ivas_fx(st_fx->core_brate, mfreq_bindiv_loc, *last_bin, Diff_len, hGSCDec->noise_lev, pit_band_idx, exc_diffQ, + &hGSCDec->seed_tcx, Ener_per_bd_iQ, nb_subfr, exc_dct_in, st_fx->last_coder_type, bitallocation_band, lsf_new, + hGSCDec->last_exc_dct_in_fx, &hGSCDec->last_ener_fx, hGSCDec->last_bitallocation_band, bitallocation_exc, st_fx->bfi, coder_type, st_fx->bwidth, exc_wo_nf, Qexc_diffQ, Q_exc, st_fx->GSC_noisy_speech, hGSCDec->lt_ener_per_band_fx , st_fx->L_frame, st_fx->element_mode, st_fx->GSC_IVAS_mode ); @@ -1656,13 +1656,13 @@ void GSC_dec_init( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx_fx = 15687; - hGSCDec->cor_strong_limit_fx = 1; + hGSCDec->seed_tcx = 15687; + hGSCDec->cor_strong_limit = 1; move16(); move16(); - hGSCDec->noise_lev_fx = NOISE_LEVEL_SP0; - hGSCDec->Last_GSC_pit_band_idx_fx = 0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; + hGSCDec->Last_GSC_pit_band_idx = 0; move16(); move16(); @@ -1679,7 +1679,7 @@ void GSC_dec_init( #endif hGSCDec->last_ener_fx = 0; move16(); - set16_fx(hGSCDec->last_bitallocation_band_fx, 0, 6); + set16_fx(hGSCDec->last_bitallocation_band, 0, 6); hGSCDec->Last_frame_ener_fx = MAX_32; move32(); @@ -1691,22 +1691,22 @@ void GSC_dec_init_ivas_fx( GSC_DEC_HANDLE hGSCDec /* i/o: GSC data handle */ ) { - hGSCDec->seed_tcx_fx = 15687; + hGSCDec->seed_tcx = 15687; move16(); - hGSCDec->cor_strong_limit_fx = 1; + hGSCDec->cor_strong_limit = 1; move16(); set16_fx(hGSCDec->old_y_gain_fx, 0, MBANDS_GN); - hGSCDec->noise_lev_fx = NOISE_LEVEL_SP0; + hGSCDec->noise_lev = NOISE_LEVEL_SP0; move16(); set16_fx(hGSCDec->Last_GSC_spectrum_fx, 0, L_FRAME16k); - hGSCDec->Last_GSC_pit_band_idx_fx = 0; + hGSCDec->Last_GSC_pit_band_idx = 0; move16(); set16_fx(hGSCDec->lt_ener_per_band_fx, 4096, MBANDS_GN16k); /*Q12*/ set16_fx(hGSCDec->last_exc_dct_in_fx, 0, L_FRAME16k); hGSCDec->last_ener_fx = 0; move16(); - set16_fx(hGSCDec->last_bitallocation_band_fx, 0, 6); + set16_fx(hGSCDec->last_bitallocation_band, 0, 6); hGSCDec->Last_frame_ener_fx = MAX_32; move32(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index a7a3f7a14..2c3fe9332 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -118,22 +118,22 @@ void hq_core_dec_fx( num_bits = sub(num_bits, st_fx->next_bit_pos); /* set FEC parameters */ - flag_uv = sub(1, hHQ_core->HqVoicing_fx); + flag_uv = sub(1, hHQ_core->HqVoicing); /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF ( !(core_switching_flag) && GT_32(st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) { - hHQ_core->HqVoicing_fx = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); num_bits = sub(num_bits, 1); } ELSE { - hHQ_core->HqVoicing_fx = 0; + hHQ_core->HqVoicing = 0; move16(); if ( GT_32(st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG)) { - hHQ_core->HqVoicing_fx = 1; + hHQ_core->HqVoicing = 1; move16(); } } @@ -153,11 +153,11 @@ void hq_core_dec_fx( IF ( st_fx->bfi == 0) { - hHQ_core->ph_ecu_HqVoicing_fx = 0; + hHQ_core->ph_ecu_HqVoicing = 0; move16(); if ( GE_16(output_frame, L_FRAME16k)) { - hHQ_core->ph_ecu_HqVoicing_fx = hHQ_core->HqVoicing_fx; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; move16(); } } @@ -173,13 +173,13 @@ void hq_core_dec_fx( IF( EQ_16(st_fx->bfi, 1)) { - is_transient = hHQ_core->old_is_transient_fx[0]; + is_transient = hHQ_core->old_is_transient[0]; move16(); IF ( GE_16(output_frame, L_FRAME16k)) /* Apply phase ecu for WB, SWB and FB */ { /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ - hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs_fx, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p_fx, hHQ_core->plocs_fx, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, - &hHQ_core->last_fec_fx, hHQ_core->ph_ecu_HqVoicing_fx, &hHQ_core->ph_ecu_active_fx, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient_fx, hHQ_core->mag_chg_1st_fx, + hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, + &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); } ELSE @@ -188,9 +188,9 @@ void hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient_fx[2] = hHQ_core->old_is_transient_fx[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; move16(); - hHQ_core->old_is_transient_fx[1] = hHQ_core->old_is_transient_fx[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; move16(); IF ( GE_16(output_frame, L_FRAME16k)) @@ -203,7 +203,7 @@ void hq_core_dec_fx( flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing_fx = sub(1, flag_uv); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub(1, flag_uv); /* safety setting for HQ->ACELP switch logic */ set16_fx(hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -215,7 +215,7 @@ void hq_core_dec_fx( { set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse_fx = 0; + hHQ_core->last_max_pos_pulse = 0; move16(); } @@ -427,15 +427,15 @@ void hq_core_dec_fx( test(); test(); test(); - IF( (EQ_16(st_fx->prev_bfi, 1)||EQ_16(st_fx->bfi,1))&& hHQ_core->old_is_transient_fx[2]==0&&EQ_16(st_fx->last_core,HQ_CORE)&&EQ_16(st_fx->last_codec_mode,MODE1)) + IF( (EQ_16(st_fx->prev_bfi, 1)||EQ_16(st_fx->bfi,1))&& hHQ_core->old_is_transient[2]==0&&EQ_16(st_fx->last_core,HQ_CORE)&&EQ_16(st_fx->last_codec_mode,MODE1)) { time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); } ELSE { window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing_fx , hHQ_core->oldgapsynth_fx ); - hHQ_nbfec->phase_mat_next_fx = 0; + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing , hHQ_core->oldgapsynth_fx ); + hHQ_nbfec->phase_mat_next = 0; move16(); } @@ -456,7 +456,7 @@ void hq_core_dec_fx( Q_audio = 15; move16(); window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active_fx, hHQ_core->oldHqVoicing_fx, hHQ_core->oldgapsynth_fx ); + ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); *Q_synth = Q_audio; move16(); } @@ -464,7 +464,7 @@ void hq_core_dec_fx( { /* no BFI or baseline PLC active */ window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active_fx, hHQ_core->oldHqVoicing_fx, hHQ_core->oldgapsynth_fx); + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx); } #ifdef ADD_IVAS_HQ_CODE if (st->element_mode > EVS_MONO) @@ -521,27 +521,27 @@ void hq_core_dec_fx( IF (GE_16(output_frame, L_FRAME16k)) { - IF (EQ_16(hHQ_core->ph_ecu_HqVoicing_fx, 1)) + IF (EQ_16(hHQ_core->ph_ecu_HqVoicing, 1)) { - hHQ_core->oldHqVoicing_fx = 1; + hHQ_core->oldHqVoicing = 1; move16(); Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); } ELSE { - hHQ_core->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing = 0; move16(); } } ELSE { - hHQ_core->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing = 0; move16(); } if( EQ_16(st_fx->nbLostCmpt, FRAMECTTOSTART_MDCT)) { - hHQ_core->HqVoicing_fx = 0; + hHQ_core->HqVoicing = 0; move16(); } @@ -704,22 +704,22 @@ void ivas_hq_core_dec_fx( num_bits = sub( num_bits, st_fx->next_bit_pos ); /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing_fx ); + flag_uv = sub( 1, hHQ_core->HqVoicing ); /* subtract the number of bits for pitch & gain at higher bitrates */ test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing_fx = get_next_indice( st_fx, 1 ); + hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); num_bits = sub( num_bits, 1 ); } ELSE { - hHQ_core->HqVoicing_fx = 0; + hHQ_core->HqVoicing = 0; move16(); IF( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing_fx = 1; + hHQ_core->HqVoicing = 1; move16(); } } @@ -736,11 +736,11 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 0 ) ) { - hHQ_core->ph_ecu_HqVoicing_fx = 0; + hHQ_core->ph_ecu_HqVoicing = 0; move16(); IF( GE_16( output_frame, L_FRAME16k ) ) { - hHQ_core->ph_ecu_HqVoicing_fx = hHQ_core->HqVoicing_fx; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; move16(); } } @@ -756,13 +756,13 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) ) { - is_transient = hHQ_core->old_is_transient_fx[0]; + is_transient = hHQ_core->old_is_transient[0]; move16(); IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ - ivas_hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs_fx, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p_fx, hHQ_core->plocs_fx, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, - &hHQ_core->last_fec_fx, hHQ_core->ph_ecu_HqVoicing_fx, &hHQ_core->ph_ecu_active_fx, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient_fx, hHQ_core->mag_chg_1st_fx, + ivas_hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, + &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); } ELSE @@ -771,9 +771,9 @@ void ivas_hq_core_dec_fx( output_frame, sfm_start, sfm_end ); } - hHQ_core->old_is_transient_fx[2] = hHQ_core->old_is_transient_fx[1]; + hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; move16(); - hHQ_core->old_is_transient_fx[1] = hHQ_core->old_is_transient_fx[0]; + hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; move16(); IF( GE_16( output_frame, L_FRAME16k ) ) @@ -786,7 +786,7 @@ void ivas_hq_core_dec_fx( flag_uv = 1; move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing_fx = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ + hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic */ set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ } } @@ -798,7 +798,7 @@ void ivas_hq_core_dec_fx( { set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse_fx = 0; + hHQ_core->last_max_pos_pulse = 0; move16(); } @@ -1046,15 +1046,15 @@ void ivas_hq_core_dec_fx( test(); test(); test(); - IF( ( EQ_16( st_fx->prev_bfi, 1 ) || EQ_16( st_fx->bfi, 1 ) ) && EQ_16( hHQ_core->old_is_transient_fx[2], 0 ) && EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) ) + IF( ( EQ_16( st_fx->prev_bfi, 1 ) || EQ_16( st_fx->bfi, 1 ) ) && EQ_16( hHQ_core->old_is_transient[2], 0 ) && EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) ) { time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); } ELSE { window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing_fx, hHQ_core->oldgapsynth_fx ); - hHQ_nbfec->phase_mat_next_fx = 0; + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + hHQ_nbfec->phase_mat_next = 0; move16(); } @@ -1075,7 +1075,7 @@ void ivas_hq_core_dec_fx( Q_audio = 15; move16(); window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active_fx, hHQ_core->oldHqVoicing_fx, hHQ_core->oldgapsynth_fx ); + ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); *Q_synth = Q_audio; move16(); } @@ -1083,7 +1083,7 @@ void ivas_hq_core_dec_fx( { /* no BFI or baseline PLC active */ window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active_fx, hHQ_core->oldHqVoicing_fx, hHQ_core->oldgapsynth_fx ); + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); } IF( st_fx->element_mode > EVS_MONO ) { @@ -1133,27 +1133,27 @@ void ivas_hq_core_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) { - IF( EQ_16( hHQ_core->ph_ecu_HqVoicing_fx, 1 ) ) + IF( EQ_16( hHQ_core->ph_ecu_HqVoicing, 1 ) ) { - hHQ_core->oldHqVoicing_fx = 1; + hHQ_core->oldHqVoicing = 1; move16(); Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); } ELSE { - hHQ_core->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing = 0; move16(); } } ELSE { - hHQ_core->oldHqVoicing_fx = 0; + hHQ_core->oldHqVoicing = 0; move16(); } IF( EQ_16( st_fx->nbLostCmpt, FRAMECTTOSTART_MDCT ) ) { - hHQ_core->HqVoicing_fx = 0; + hHQ_core->HqVoicing = 0; move16(); } @@ -1221,23 +1221,23 @@ void HQ_core_dec_init( hHQ_core->Q_old_outLB = 0; hHQ_core->last_hq_core_type = -1; - set16_fx(hHQ_core->old_is_transient_fx, 0, 3); + set16_fx(hHQ_core->old_is_transient, 0, 3); - hHQ_core->mem_norm_fx[0] = 31; - set16_fx(hHQ_core->mem_norm_fx + 1, 39, SFM_N_ENV_STAB - 1); - hHQ_core->mem_env_delta_fx = 0; - hHQ_core->no_att_hangover_fx = 0; + hHQ_core->mem_norm[0] = 31; + set16_fx(hHQ_core->mem_norm + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta = 0; + hHQ_core->no_att_hangover = 0; move16(); move16(); move16(); move16(); hHQ_core->energy_lt_fx = 2457600; /*Q13*/ - hHQ_core->hq_generic_seed_fx = RANDOM_INITSEED; + hHQ_core->hq_generic_seed = RANDOM_INITSEED; set16_fx(hHQ_core->prev_noise_level_fx, 0, 2); - hHQ_core->prev_hqswb_clas_fx = HQ_NORMAL; - hHQ_core->prev_R_fx = 0; + hHQ_core->prev_hqswb_clas = HQ_NORMAL; + hHQ_core->prev_R = 0; move16(); set32_fx(hHQ_core->prev_coeff_out_fx, 0, L_HQ_WB_BWE); set16_fx(hHQ_core->prev_SWB_peak_pos_fx, 0, SPT_SHORTEN_SBNUM); - hHQ_core->HqVoicing_fx = 0; + hHQ_core->HqVoicing = 0; set16_fx(hHQ_core->fer_samples_fx, 0, L_FRAME48k); set32_fx(hHQ_core->prev_env_fx, 0, SFM_N_WB); set32_fx(hHQ_core->prev_normq_fx, 0, SFM_N_WB); @@ -1245,15 +1245,15 @@ void HQ_core_dec_init( set32_fx(hHQ_core->last_ni_gain_fx, 0, BANDS_MAX); set16_fx(hHQ_core->last_env_fx, 0, BANDS_MAX); - hHQ_core->last_max_pos_pulse_fx = 0; + hHQ_core->last_max_pos_pulse = 0; move16(); hHQ_core->Q_fer_samples = 0; reset_preecho_dec_fx(hHQ_core); - hHQ_core->prev_frm_hfe2_fx = 0; + hHQ_core->prev_frm_hfe2 = 0; move16(); - hHQ_core->prev_stab_hfe2_fx = 0; + hHQ_core->prev_stab_hfe2 = 0; move16(); hHQ_core->prev_ni_ratio_fx = 16384; /*Q15*/ move16(); @@ -1263,29 +1263,29 @@ void HQ_core_dec_init( /*----------------------------------------------------------------------------------* * HQ FEC *----------------------------------------------------------------------------------*/ - hHQ_core->time_offs_fx = 0; + hHQ_core->time_offs = 0; set16_fx(hHQ_core->X_sav_fx, 0, PH_ECU_SPEC_SIZE); hHQ_core->Q_X_sav = 0; - hHQ_core->num_p_fx = 0; + hHQ_core->num_p = 0; - //set16_fx(hHQ_core->plocs_fx, 0, MAX_PLOCS); + //set16_fx(hHQ_core->plocs, 0, MAX_PLOCS); //set32_fx(hHQ_core->plocsi_fx, 0, MAX_PLOCS); hHQ_core->env_stab_fx = 0x6000; /*0.75 Q15*/ - hHQ_core->mem_norm_hqfec_fx[0] = 31; + hHQ_core->mem_norm_hqfec[0] = 31; move16(); - set16_fx(hHQ_core->mem_norm_hqfec_fx + 1, 39, SFM_N_ENV_STAB - 1); - hHQ_core->mem_env_delta_hqfec_fx = 0; + set16_fx(hHQ_core->mem_norm_hqfec + 1, 39, SFM_N_ENV_STAB - 1); + hHQ_core->mem_env_delta_hqfec = 0; hHQ_core->env_stab_plc_fx = 0; set16_fx(hHQ_core->env_stab_state_p_fx, INV_NUM_ENV_STAB_PLC_STATES, NUM_ENV_STAB_PLC_STATES); - hHQ_core->envstabplc_hocnt_fx = 0; + hHQ_core->envstabplc_hocnt = 0; set16_fx(hHQ_core->mag_chg_1st_fx, 32767, LGW_MAX); set16_fx(hHQ_core->Xavg_fx, 0, LGW_MAX); hHQ_core->beta_mute_fx = BETA_MUTE_FAC_INI; - hHQ_core->last_fec_fx = 0; - hHQ_core->ph_ecu_HqVoicing_fx = 0; - hHQ_core->oldHqVoicing_fx = 0; + hHQ_core->last_fec = 0; + hHQ_core->ph_ecu_HqVoicing = 0; + hHQ_core->oldHqVoicing = 0; set16_fx(hHQ_core->oldgapsynth_fx, 0, L_FRAME48k); - hHQ_core->ph_ecu_active_fx = 0; + hHQ_core->ph_ecu_active = 0; hHQ_core->ni_seed_forfec = 0; hHQ_core->ber_occured_in_pvq = 0; move16(); move16(); move16(); move16(); move16(); @@ -1308,12 +1308,12 @@ void HQ_nbfec_init( hHQ_nbfec->prev_last_core = -1; hHQ_nbfec->diff_energy_fx = 0; - hHQ_nbfec->stat_mode_out_fx = 0; - hHQ_nbfec->stat_mode_old_fx = 0; + hHQ_nbfec->stat_mode_out = 0; + hHQ_nbfec->stat_mode_old = 0; move16(); move16(); - hHQ_nbfec->phase_mat_flag_fx = 0; - hHQ_nbfec->phase_mat_next_fx = 0; - hHQ_nbfec->old_Min_ind_fx = 0; + hHQ_nbfec->phase_mat_flag = 0; + hHQ_nbfec->phase_mat_next = 0; + hHQ_nbfec->old_Min_ind = 0; move16(); move16(); move16(); move16(); set16_fx(hHQ_nbfec->old_auOut_2fr_fx, 0, L_FRAME8k * 2); set16_fx(hHQ_nbfec->old_out_pha_fx[0], 0, N_LEAD_NB); @@ -1334,11 +1334,11 @@ void HQ_nbfec_init( } set16_fx(hHQ_nbfec->Norm_gain_fx, 1, SFM_N_NB); - hHQ_nbfec->HQ_FEC_seed_fx = RANDOM_INITSEED; + hHQ_nbfec->HQ_FEC_seed = RANDOM_INITSEED; set16_fx(hHQ_nbfec->energy_MA_Curr_fx, 100, 2); - set16_fx(hHQ_nbfec->prev_sign_switch_fx, 0, HQ_FEC_SIGN_SFM); - set16_fx(hHQ_nbfec->prev_sign_switch_2_fx, 0, HQ_FEC_SIGN_SFM); + set16_fx(hHQ_nbfec->prev_sign_switch, 0, HQ_FEC_SIGN_SFM); + set16_fx(hHQ_nbfec->prev_sign_switch_2, 0, HQ_FEC_SIGN_SFM); set32_fx(hHQ_nbfec->old_coeffs_fx, 0, L_FRAME8k); set32_fx(hHQ_nbfec->oldIMDCTout_fx, 0, L_FRAME8k / 2); diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index b12d99ded..165136356 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -253,18 +253,18 @@ void ivas_hq_hr_dec_fx( test(); IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) { - hHQ_core->mem_env_delta_fx = 0; + hHQ_core->mem_env_delta = 0; move16(); } ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm_fx, &hHQ_core->mem_env_delta_fx, csw_flag1 ); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); } ELSE { - hHQ_core->mem_norm_fx[0] = 31; + hHQ_core->mem_norm[0] = 31; move16(); - hHQ_core->mem_env_delta_fx = 0; + hHQ_core->mem_env_delta = 0; move16(); } @@ -282,10 +282,10 @@ void ivas_hq_hr_dec_fx( } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec_fx, &hHQ_core->mem_env_delta_hqfec_fx, csw_flag1 ); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt_fx ); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /*------------------------------------------------------------------* * Bit allocation @@ -354,9 +354,9 @@ void ivas_hq_hr_dec_fx( } } - har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2_fx, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2_fx ); + har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2 ); - hHQ_core->prev_frm_hfe2_fx = har_freq_est2; + hHQ_core->prev_frm_hfe2 = har_freq_est2; move16(); } @@ -366,9 +366,9 @@ void ivas_hq_hr_dec_fx( IF ( NE_16(*hqswb_clas, HQ_HARMONIC)||NE_16(*hqswb_clas,HQ_HVQ)||flag_dis==0) // TV2VE -> always reset in floating point code, is it OK #endif { - hHQ_core->prev_frm_hfe2_fx = 0; /*reset*/ + hHQ_core->prev_frm_hfe2 = 0; /*reset*/ move16(); - hHQ_core->prev_stab_hfe2_fx = 0; /*reset*/ + hHQ_core->prev_stab_hfe2 = 0; /*reset*/ move16(); } @@ -376,10 +376,10 @@ void ivas_hq_hr_dec_fx( * Spectral filling *------------------------------------------------------------------*/ ivas_fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, - &hHQ_core->no_att_hangover_fx, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed_fx, hq_generic_exc_clas, - core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R_fx, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient_fx[0], + &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, + core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, - &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas_fx, num_sfm, hHQ_core->prev_env_Q, num_env_bands, st_fx->element_mode ); + &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands, st_fx->element_mode ); enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); @@ -395,7 +395,7 @@ void ivas_hq_hr_dec_fx( ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas_fx = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; move16(); return; @@ -518,18 +518,18 @@ void hq_hr_dec_fx( test(); IF( EQ_16(*hqswb_clas, HQ_HVQ)) { - hHQ_core->mem_env_delta_fx = 0; + hHQ_core->mem_env_delta = 0; move16(); } ELSE IF (EQ_16(length, L_FRAME32k) || csw_flag2 ) { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm_fx, &hHQ_core->mem_env_delta_fx, csw_flag1); + env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1); } ELSE { - hHQ_core->mem_norm_fx[0] = 31; + hHQ_core->mem_norm[0] = 31; move16(); - hHQ_core->mem_env_delta_fx = 0; + hHQ_core->mem_env_delta = 0; move16(); } @@ -547,10 +547,10 @@ void hq_hr_dec_fx( } ELSE { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec_fx, &hHQ_core->mem_env_delta_hqfec_fx, csw_flag1); + hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1); } } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx(s_min(hHQ_core->env_stab_fx, sub(32767, stab_trans_fx[L_STAB_TBL-1])), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt_fx); + hHQ_core->env_stab_plc_fx = env_stab_smo_fx(s_min(hHQ_core->env_stab_fx, sub(32767, stab_trans_fx[L_STAB_TBL-1])), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt); /*------------------------------------------------------------------* * Bit allocation @@ -619,9 +619,9 @@ void hq_hr_dec_fx( } } - har_est_fx( t_audio_q, 300 ,&har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2_fx, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2_fx ); + har_est_fx( t_audio_q, 300 ,&har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2 ); - hHQ_core->prev_frm_hfe2_fx = har_freq_est2; + hHQ_core->prev_frm_hfe2 = har_freq_est2; move16(); } @@ -631,18 +631,18 @@ void hq_hr_dec_fx( IF ( NE_16(*hqswb_clas, HQ_HARMONIC)||NE_16(*hqswb_clas,HQ_HVQ)||flag_dis==0) // TV2VE -> always reset in floating point code, is it OK #endif { - hHQ_core->prev_frm_hfe2_fx = 0; /*reset*/ move16(); - hHQ_core->prev_stab_hfe2_fx = 0; /*reset*/ move16(); + hHQ_core->prev_frm_hfe2 = 0; /*reset*/ move16(); + hHQ_core->prev_stab_hfe2 = 0; /*reset*/ move16(); } /*------------------------------------------------------------------* * Spectral filling *------------------------------------------------------------------*/ fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, - &hHQ_core->no_att_hangover_fx, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed_fx, hq_generic_exc_clas, - core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R_fx, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient_fx[0], + &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, + core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, - &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas_fx, num_sfm, hHQ_core->prev_env_Q, num_env_bands + &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands ,st_fx->element_mode); enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); @@ -659,7 +659,7 @@ void hq_hr_dec_fx( hq_pred_hb_bws_fx(st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ - hHQ_core->prev_hqswb_clas_fx = *hqswb_clas; + hHQ_core->prev_hqswb_clas = *hqswb_clas; move16(); return; diff --git a/lib_dec/hq_lr_dec_fx.c b/lib_dec/hq_lr_dec_fx.c index 34203c87c..21f7faa35 100644 --- a/lib_dec/hq_lr_dec_fx.c +++ b/lib_dec/hq_lr_dec_fx.c @@ -255,7 +255,7 @@ void hq_lr_dec_fx( test(); IF(( EQ_32(L_bwe_br, HQ_16k40)||EQ_32(L_bwe_br,HQ_13k20))&&EQ_16(st_fx->bwidth,SWB)) { - IF( NE_16(hHQ_core->prev_hqswb_clas_fx, HQ_NORMAL)) + IF( NE_16(hHQ_core->prev_hqswb_clas, HQ_NORMAL)) { j = 0; move16(); @@ -869,7 +869,7 @@ void hq_lr_dec_fx( Copy32( L_y2, L_y2_ni, band_end[bands_fx-1]+1 ); hq2_noise_inject_fx( L_y2_ni, band_start, band_end, band_width, Ep_fx, L_Rk, npulses_fx, ni_seed_fx, bands_fx, 0, bw_low, bw_high, enerL_fx, enerH_fx, - hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse_fx, p2a_flags_fx, p2a_bands_fx, + hHQ_core->last_ni_gain_fx, hHQ_core->last_env_fx, &hHQ_core->last_max_pos_pulse, p2a_flags_fx, p2a_bands_fx, hqswb_clas_fx, st_fx->bwidth, L_bwe_br ); test(); @@ -882,7 +882,7 @@ void hq_lr_dec_fx( preset_hq2_swb_fx( hqswb_clas_fx, band_end, &har_bands_fx, p2a_bands_fx,length_fx, bands_fx, &lowlength_fx, &highlength_fx, L_m ); swb_bwe_dec_lr_fx(st_fx, L_y2, SWB_BWE_LR_Qs, L_m, L_bwe_br, bands_fx, band_start, band_end, L_band_energy, SWB_BWE_LR_Qbe, - p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, har_bands_fx, &hHQ_core->prev_frm_hfe2_fx, &hHQ_core->prev_stab_hfe2_fx + p2a_flags_fx, hqswb_clas_fx, lowlength_fx, highlength_fx, har_bands_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2 , band_width, L_y2_ni, &ni_seed_fx); post_hq2_swb_fx( L_m, lowlength_fx, highlength_fx, hqswb_clas_fx, har_bands_fx, bands_fx, p2a_flags_fx, band_start, band_end, L_y2, npulses_fx ); @@ -934,8 +934,8 @@ void hq_lr_dec_fx( set16_fx(st_fx->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV); } - updat_prev_frm_fx( L_y2, L_yout, L_bwe_br, length_fx, inner_frame, bands_fx, st_fx->bwidth, *is_transient_fx, hqswb_clas_fx, &hHQ_core->prev_hqswb_clas_fx, - hHQ_core->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &hHQ_core->prev_frm_hfe2_fx, &hHQ_core->prev_stab_hfe2_fx, st_fx->bws_cnt ); + updat_prev_frm_fx( L_y2, L_yout, L_bwe_br, length_fx, inner_frame, bands_fx, st_fx->bwidth, *is_transient_fx, hqswb_clas_fx, &hHQ_core->prev_hqswb_clas, + hHQ_core->prev_SWB_peak_pos_fx, prev_SWB_peak_pos_tmp_fx, &hHQ_core->prev_frm_hfe2, &hHQ_core->prev_stab_hfe2, st_fx->bws_cnt ); return; } diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index fb8dff651..609a82bc1 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -48,7 +48,7 @@ #include "prot_fx2.h" #include "ivas_prot_fx.h" #endif - +#ifndef IVAS_FLOAT_FIXED /*----------------------------------------------------------------------* * init_decoder() * @@ -129,11 +129,6 @@ ivas_error init_decoder( st->mem_deemph = 0.0f; -#ifdef IVAS_FLOAT_FIXED - st->scale = 1.f; - st->scale_lsfbfi = 1.f; -#endif // IVAS_FLOAT_FIXED - set_f( st->mem_syn1, 0, M ); set_f( st->mem_syn2, 0, M ); st->stab_fac = 0.0f; @@ -808,7 +803,7 @@ ivas_error init_decoder( return error; } - +#endif /*----------------------------------------------------------------------* * reset_preecho_dec() diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 086048ac8..c633007de 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -957,7 +957,7 @@ ivas_error init_decoder_ivas_fx( st_fx->lp_gainp = 0.0f; st_fx->lp_gainc = 0.0f; - set_f(st_fx->old_exc, 0, L_EXC_MEM_DEC); + //set_f(st_fx->old_exc, 0, L_EXC_MEM_DEC); } #endif @@ -970,8 +970,6 @@ ivas_error init_decoder_ivas_fx( //++To be removed #ifdef IVAS_FLOAT_FIXED - st_fx->scale = 1.f; - st_fx->scale_lsfbfi = 1.f; mvr2r( GEWB_Ave, st_fx->lsf_old, M ); lsf2lsp( st_fx->lsf_old, st_fx->lsp_old, M, INT_FS_12k8 ); #endif//IVAS_FLOAT_FIXED @@ -1339,8 +1337,7 @@ ivas_error init_decoder_ivas_fx( td_cng_dec_init_ivas_fx( st_fx ); #if 1 // Fix to float conversions - st_fx->hTdCngDec->Enew = fix_to_float(st_fx->hTdCngDec->Enew_fx, 6); - fixedToFloat_arr(st_fx->lspCNG_fx, st_fx->lspCNG, 15, M); + //fixedToFloat_arr(st_fx->lspCNG_fx, st_fx->lspCNG, 15, M); st_fx->hTdCngDec->shb_cng_ener = fix_to_float(st_fx->hTdCngDec->shb_cng_ener_fx_32, 11); fixedToFloat_arr(st_fx->hTdCngDec->shb_lpcCNG_fx, st_fx->hTdCngDec->shb_lpcCNG, 15, LPC_SHB_ORDER + 1); st_fx->hTdCngDec->shb_cng_gain = fix_to_float(st_fx->hTdCngDec->shb_cng_gain_fx_32, 11); diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 4520b5785..a8d0dc483 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -113,6 +113,8 @@ ivas_error ivas_core_dec( Word16 tmp_buffer_fx[L_FRAME48k]; set_s(tmp_buffer_fx, 0, L_FRAME48k); Word16 tmp16, tmp16_2, j; + Word16 Q_white_exc; + Q_white_exc = 0; #endif int16_t tmps, incr; float bwe_exc_extended[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; @@ -529,26 +531,17 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED #if 1 /*Float to fix conversions*/ - Word16 Q_mem_syn2, Q_mem_syn1, Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_old_bwe_exc = 0, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, - Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_old_exc, Q_mem_syn_r = 15, Q_olapBufferSynth = 15, + Word16 Q_mem_syn, Q_agc_mem, Q_syn, Q_pst_old_syn = 0, Q_pst_mem_deemp_err = 0, Q_hb_prev_synth_buffer, Q_mem_hf = 0, Q_mem_syn_hf = 0, Q_mem_hp400 = 0, Q_delay_syn_hf = 0, Q_mem_hp_interp = 0, + Q_old_syn_12k8_16k = 0, Q_prev_env = 0, Q_FBTCXdelayBuf = 15, Q_prev_synth_buffer, Q_syn_Overl = 15, Q_fer_samples = 15, Q_old_syn_Overl = 15, Q_olapBufferAna = 15, Q_olapBufferSynth = 15, Q_olapBufferSynth2 = 15, Q_old_synthFB = 15, Q_mem_deemph = 15; /*Initializing with max values to avoid warnings*/ - Q_mem_syn2 = Q_factor_arr( st->mem_syn2, M ); - Q_mem_syn1 = Q_factor_arr( st->mem_syn1, M ); - Q_mem_syn_r = Q_factor_arr( st->mem_syn_r_float, L_SYN_MEM ); - //Q_mem_syn = s_min( s_min( Q_mem_syn2, Q_mem_syn1 ), Q_mem_syn_r ); Q_mem_syn = 0; - Q_agc_mem = Q_factor_arr( st->agc_mem2, 2 ); + Q_agc_mem = 0; Q_syn = Q_factor_arr( st->syn_float, M + 1 ); Q_mem_deemph = s_min( Q_syn, Q_factor( st->mem_deemph ) ) - 1; Q_hb_prev_synth_buffer = Q_factor_arr( st->hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); Q_prev_synth_buffer = Q_factor_arr( st->prev_synth_buffer, 96 ); - floatToFixed_arr16( st->mem_syn2, st->mem_syn2_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->mem_syn1, st->mem_syn1_fx, Q_mem_syn, M ); - floatToFixed_arr16( st->agc_mem2, st->agc_mem_fx, Q_agc_mem, 2 ); floatToFixed_arr( st->syn_float, st->syn, Q_mem_deemph, M + 1 ); st->mem_deemph_fx = (Word16) floatToFixed( st->mem_deemph, Q_mem_deemph ); - st->psf_lp_noise_fx = (Word16) floatToFixed( st->psf_lp_noise, Q7 ); /*Used floatToFixed because does not give error in case of garbage value*/ - st->lp_noise = float_to_fix16( st->lp_noise_float, Q7 ); floatToFixed_arr( st->hb_prev_synth_buffer, st->hb_prev_synth_buffer_fx, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); IF( st->hBPF ) { @@ -557,12 +550,6 @@ ivas_error ivas_core_dec( floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); } - IF( st->hBWE_TD ) - { - Q_old_bwe_exc = Q_factor_arrL( st->hBWE_TD->old_bwe_exc, PIT16k_MAX * 2 ); - st->hBWE_TD->bwe_non_lin_prev_scale_fx = float_to_fix( st->hBWE_TD->bwe_non_lin_prev_scale, 30 ); - floatToFixed_arr32( st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx_32, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } IF( st->hBWE_zero ) { Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); @@ -629,14 +616,9 @@ ivas_error ivas_core_dec( { floatToFixed_arr32( st->cldfbSyn->cldfb_state, st->cldfbSyn->cldfb_state_fx, Q11, st->cldfbSyn->cldfb_state_length ); } - Word16 Q_mem_syn_clas_estim = Q_factor_arr( st->mem_syn_clas_estim, 258 ) - 1; - floatToFixed_arr16( st->mem_syn_clas_estim, st->mem_syn_clas_estim_fx, Q_mem_syn_clas_estim, 258 ); + FOR( i = 0; i < M; i++ ) { - st->lsf_old_fx[i] = float_to_fix16( ( st->lsf_old[i] * (2.56f / st->scale)), 0); - st->lsfoldbfi1_fx[i] = float_to_fix16((st->lsfoldbfi1[i] * (2.56f / st->scale_lsfbfi)), 0); - st->lsfoldbfi0_fx[i] = float_to_fix16((st->lsfoldbfi0[i] * (2.56f / st->scale_lsfbfi)), 0); - st->lsf_adaptive_mean_fx[i] = float_to_fix16((st->lsf_adaptive_mean[i] * (2.56f / st->scale_lsfbfi)), 0 ); st->lsp_old_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); st->mem_AR_fx[i] = float_to_fix16( ( st->mem_AR[i] * 2.56f ), 0 ); st->mem_MA_fx[i] = (Word16) ( ( st->mem_MA[i] * 2.56f ) ); @@ -652,15 +634,15 @@ ivas_error ivas_core_dec( } IF( st->cldfbBPF ) floatToFixed_arr32( st->cldfbBPF->cldfb_state, st->cldfbBPF->cldfb_state_fx, Q11, st->cldfbBPF->cldfb_state_length ); - Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; - floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); + //Q_old_exc = Q_factor_arr( st->old_exc, 480 ) - 1; + //floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); st->enr_old_fx = (Word32) st->enr_old; st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); st->stab_fac_smooth_lt_fx = float_to_fix( st->stab_fac_smooth_lt, Q15 ); st->lp_ener_fx = float_to_fix( st->lp_ener, Q6 ); st->lp_gainc_fx = (Word16) L_min( 32767, float_to_fix( st->lp_gainc, 3 ) ); - floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); + //floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); IF( ( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) ) && ( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) ) ) { IF( EQ_16( nchan_out, 1 ) && EQ_16( st->element_mode, IVAS_CPE_DFT ) && LE_32( st->element_brate, IVAS_24k4 ) && GT_32( last_element_brate, IVAS_24k4 ) ) @@ -675,29 +657,19 @@ ivas_error ivas_core_dec( return error; } #if 1 /*Fixed to float function changes*/ - fixedToFloat_arr( st->mem_syn1_fx, st->mem_syn1, Q_mem_syn, M ); - fixedToFloat_arr( st->agc_mem_fx, st->agc_mem2, Q_agc_mem, 2 ); st->mem_deemph = fixedToFloat( st->mem_deemph_fx, Q_mem_deemph ); - st->psf_lp_noise = fixedToFloat( st->psf_lp_noise_fx, Q7 ); /*psf_lp_noise_fx has Q7*/ fixedToFloat_arr( st->hb_prev_synth_buffer_fx, st->hb_prev_synth_buffer, Q_hb_prev_synth_buffer, NS2SA( 48000, DELAY_BWE_TOTAL_NS ) ); fixedToFloat_arr( st->prev_synth_buffer_fx, st->prev_synth_buffer, Q_prev_synth_buffer, 96 ); st->q_prev_synth_buffer_fx = Q_prev_synth_buffer; - fixedToFloat_arr( st->mem_syn_clas_estim_fx, st->mem_syn_clas_estim, Q_mem_syn_clas_estim, 258 ); st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); /*Q3*/ FOR( i = 0; i < M; i++ ) { st->mem_MA[i] = (float) ( st->mem_MA_fx[i] / 2.56f ); st->mem_AR[i] = (float) ( st->mem_AR_fx[i] / 2.56f ); - st->lsf_old[i] = (float) ( st->lsf_old_fx[i] / (2.56f / st->scale)); - st->lsfoldbfi1[i] = (float)(st->lsfoldbfi1_fx[i] / (2.56f / st->scale_lsfbfi)); - st->lsfoldbfi0[i] = (float)(st->lsfoldbfi0_fx[i] / (2.56f / st->scale_lsfbfi)); - st->lsf_adaptive_mean[i] = (float)(st->lsf_adaptive_mean_fx[i] / (2.56f / st->scale_lsfbfi)); st->lsp_old[i] = fixedToFloat( st->lsp_old_fx[i], 15 ); } - fixedToFloat_arr( st->mem_syn_r, st->mem_syn_r_float, Q_mem_syn, L_SYN_MEM ); - fixedToFloat_arr( st->mem_syn2_fx, st->mem_syn2, Q_mem_syn, M ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, Q_old_exc, 480 ); + IF( st->hBPF ) { fixedToFloat_arrL( st->hBPF->pst_old_syn_32, st->hBPF->pst_old_syn, Q_pst_old_syn, NBPSF_PIT_MAX ); @@ -713,11 +685,6 @@ ivas_error ivas_core_dec( } IF( st->hBWE_FD ) fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - IF( st->hBWE_TD ) - { - st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat( st->hBWE_TD->bwe_non_lin_prev_scale_fx, 30 ); - fixedToFloat_arrL( st->hBWE_TD->old_bwe_exc_fx_32, st->hBWE_TD->old_bwe_exc, Q_old_bwe_exc, PIT16k_MAX * 2 ); - } IF( st->hBWE_zero ) { fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); @@ -803,7 +770,7 @@ ivas_error ivas_core_dec( } /* fix2float, to be removed */ acelp_decoder_state_fix2float(st, hCPE == NULL ? NULL : hCPE->hStereoCng); - fixedToFloat_arr(output_fx, output[n], 0, L_FRAME48k); + fixedToFloat_arr(output_fx, output[n], st->Q_syn2, L_FRAME48k); fixedToFloat_arr(synth_fx, synth[n], 0, L_FRAME48k); if (save_hb_synth) { fixedToFloat_arr(save_hb_synth_fx, save_hb_synth, 0, L_FRAME48k); @@ -828,9 +795,13 @@ 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 ) ) { + Word16 Qsyn_temp = st->Q_syn; //Q gets change in below function. stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st, 1, last_element_mode, frameMode[n]); /* TCX decoder */ + Scale_sig(st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp); + Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp); + 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 ); @@ -861,8 +832,8 @@ ivas_error ivas_core_dec( hHQ_core = st->hHQ_core; - st->Q_syn = 0; - st->Q_exc = 0; + //st->Q_syn = 0; + //st->Q_exc = 0; st->hHQ_core->Q_old_wtda = -1; st->hHQ_core->Q_old_wtda_LB = -1; @@ -877,8 +848,6 @@ ivas_error ivas_core_dec( floatToFixed_arr( hHQ_core->oldgapsynth, hHQ_core->oldgapsynth_fx, 0, L_FRAME32k ); floatToFixed_arr( st->old_Aq_12_8, st->old_Aq_12_8_fx, Q12, M + 1 ); 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 ); - floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); floatToFixed_arrL( hHQ_core->prev_normq, hHQ_core->prev_normq_fx, Q14, SFM_N_WB ); FOR( i = 0; i < SFM_N_WB; ++i ) { @@ -889,41 +858,41 @@ ivas_error ivas_core_dec( floatToFixed_arrL( hHQ_core->prev_coeff_out, hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); FOR( i = 0; i < 3; ++i ) { - hHQ_core->old_is_transient_fx[i] = hHQ_core->old_is_transient[i]; + hHQ_core->old_is_transient[i] = hHQ_core->old_is_transient[i]; } hHQ_core->prev_ni_ratio_fx = (Word16) floatToFixed( hHQ_core->prev_ni_ratio, Q15 ); hHQ_core->mean_prev_nc_fx = floatToFixed( hHQ_core->mean_prev_nc, 0 ); hHQ_core->wmold_hb_fx = (Word16) floatToFixed( hHQ_core->wmold_hb, Q15 ); hHQ_core->mean_prev_hb_fx = floatToFixed( hHQ_core->mean_prev_hb, 0 ); hHQ_core->memfilt_lb_fx = (Word16) floatToFixed( hHQ_core->memfilt_lb, 0 ); - hHQ_core->HqVoicing_fx = hHQ_core->HqVoicing; - hHQ_core->ph_ecu_HqVoicing_fx = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->prev_hqswb_clas_fx = hHQ_core->prev_hqswb_clas; - hHQ_core->hq_generic_seed_fx = hHQ_core->hq_generic_seed; + hHQ_core->HqVoicing = hHQ_core->HqVoicing; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; + hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) { - hHQ_core->mem_norm_fx[i] = hHQ_core->mem_norm[i]; - hHQ_core->mem_norm_hqfec_fx[i] = hHQ_core->mem_norm_hqfec[i]; + hHQ_core->mem_norm[i] = hHQ_core->mem_norm[i]; + hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec[i]; } - hHQ_core->mem_env_delta_fx = hHQ_core->mem_env_delta; - hHQ_core->mem_env_delta_hqfec_fx = hHQ_core->mem_env_delta_hqfec; - hHQ_core->no_att_hangover_fx = hHQ_core->no_att_hangover; - hHQ_core->oldHqVoicing_fx = hHQ_core->oldHqVoicing; + hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; + hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; + hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; + hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; floatToFixed_arr( hHQ_core->env_stab_state_p, hHQ_core->env_stab_state_p_fx, Q15, NUM_ENV_STAB_PLC_STATES ); - hHQ_core->envstabplc_hocnt_fx = hHQ_core->envstabplc_hocnt; + hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; floatToFixed_arr( st->hTcxDec->prev_good_synth - tmp_size, st->hTcxDec->prev_good_synth_fx - tmp_size, 0, 2 * output_frame + tmp_size ); - hHQ_core->time_offs_fx = hHQ_core->time_offs; + hHQ_core->time_offs = hHQ_core->time_offs; floatToFixed_arr( hHQ_core->X_sav, hHQ_core->X_sav_fx, hHQ_core->Q_X_sav, PH_ECU_SPEC_SIZE ); - hHQ_core->num_p_fx = hHQ_core->num_p; + hHQ_core->num_p = hHQ_core->num_p; FOR( i = 0; i < MAX_PLOCS; ++i ) { - hHQ_core->plocs_fx[i] = hHQ_core->plocs[i]; + hHQ_core->plocs[i] = hHQ_core->plocs[i]; } floatToFixed_arrL( hHQ_core->plocsi, hHQ_core->plocsi_fx, Q16, MAX_PLOCS ); hHQ_core->env_stab_fx = (Word16) floatToFixed( hHQ_core->env_stab, Q15 ); - hHQ_core->last_fec_fx = hHQ_core->last_fec; - hHQ_core->ph_ecu_HqVoicing_fx = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->ph_ecu_active_fx = hHQ_core->ph_ecu_active; + hHQ_core->last_fec = hHQ_core->last_fec; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; floatToFixed_arr( hHQ_core->mag_chg_1st, hHQ_core->mag_chg_1st_fx, Q15, LGW_MAX ); floatToFixed_arr( hHQ_core->Xavg, hHQ_core->Xavg_fx, 0, LGW_MAX ); hHQ_core->mean_prev_fx = floatToFixed(hHQ_core->mean_prev, 0); @@ -945,8 +914,6 @@ ivas_error ivas_core_dec( fixedToFloat_arr( hHQ_core->oldgapsynth_fx, hHQ_core->oldgapsynth, 0, L_FRAME32k ); // Check fixedToFloat_arr( st->old_Aq_12_8_fx, st->old_Aq_12_8, Q12, M + 1 ); // Check 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 ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC ); fixedToFloat_arrL( hHQ_core->prev_normq_fx, hHQ_core->prev_normq, Q14, SFM_N_WB ); FOR( i = 0; i < SFM_N_WB; ++i ) { @@ -957,41 +924,41 @@ ivas_error ivas_core_dec( fixedToFloat_arrL( hHQ_core->prev_coeff_out_fx, hHQ_core->prev_coeff_out, Q12, L_HQ_WB_BWE ); FOR( i = 0; i < 3; ++i ) { - hHQ_core->prev_coeff_out[i] = hHQ_core->old_is_transient_fx[i]; + hHQ_core->prev_coeff_out[i] = hHQ_core->old_is_transient[i]; } hHQ_core->prev_ni_ratio = fixedToFloat( hHQ_core->prev_ni_ratio_fx, Q15 ); hHQ_core->mean_prev_nc = fixedToFloat( hHQ_core->mean_prev_nc_fx, 0 ); hHQ_core->wmold_hb = fixedToFloat( hHQ_core->wmold_hb_fx, Q15 ); hHQ_core->mean_prev_hb = fixedToFloat( hHQ_core->mean_prev_hb_fx, 0 ); hHQ_core->memfilt_lb = fixedToFloat( hHQ_core->memfilt_lb_fx, 0 ); - hHQ_core->HqVoicing = hHQ_core->HqVoicing_fx; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing_fx; - hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas_fx; - hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed_fx; + hHQ_core->HqVoicing = hHQ_core->HqVoicing; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; + hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) { - hHQ_core->mem_norm[i] = hHQ_core->mem_norm_fx[i]; - hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec_fx[i]; + hHQ_core->mem_norm[i] = hHQ_core->mem_norm[i]; + hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec[i]; } - hHQ_core->mem_env_delta = hHQ_core->mem_env_delta_fx; - hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec_fx; - hHQ_core->no_att_hangover = hHQ_core->no_att_hangover_fx; - hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing_fx; + hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; + hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; + hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; + hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; fixedToFloat_arr( hHQ_core->env_stab_state_p_fx, hHQ_core->env_stab_state_p, Q15, NUM_ENV_STAB_PLC_STATES ); - hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt_fx; + hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; fixedToFloat_arr( st->hTcxDec->prev_good_synth_fx - tmp_size, st->hTcxDec->prev_good_synth - tmp_size, 0, 2 * output_frame + tmp_size ); - hHQ_core->time_offs = hHQ_core->time_offs_fx; + hHQ_core->time_offs = hHQ_core->time_offs; fixedToFloat_arr( hHQ_core->X_sav_fx, hHQ_core->X_sav, hHQ_core->Q_X_sav, PH_ECU_SPEC_SIZE ); - hHQ_core->num_p = hHQ_core->num_p_fx; + hHQ_core->num_p = hHQ_core->num_p; FOR( i = 0; i < MAX_PLOCS; ++i ) { - hHQ_core->plocs[i] = hHQ_core->plocs_fx[i]; + hHQ_core->plocs[i] = hHQ_core->plocs[i]; } fixedToFloat_arrL( hHQ_core->plocsi_fx, hHQ_core->plocsi, Q16, MAX_PLOCS ); hHQ_core->env_stab = fixedToFloat( hHQ_core->env_stab_fx, Q15 ); - hHQ_core->last_fec = hHQ_core->last_fec_fx; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing_fx; - hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active_fx; + hHQ_core->last_fec = hHQ_core->last_fec; + hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; fixedToFloat_arr( hHQ_core->mag_chg_1st_fx, hHQ_core->mag_chg_1st, Q15, LGW_MAX ); fixedToFloat_arr( hHQ_core->Xavg_fx, hHQ_core->Xavg, 0, LGW_MAX ); hHQ_core->beta_mute = fixedToFloat( hHQ_core->beta_mute_fx, Q15 ); @@ -1012,11 +979,11 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ Word16 lsp_old_PCh_fx[M], tdm_lspQ_PCh_fx[M]; - Word16 tdm_lsfQ_PCh_fx[M], lsf_old_PCh_fx[M]; + Word16 tdm_lsfQ_PCh_fx[M]/*, lsf_old_PCh_fx[M]*/; FOR( i = 0; i < M; i++ ) { lsp_old_PCh_fx[i] = float_to_fix16( st->lsp_old[i], 15 ); - lsf_old_PCh_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f ); + //lsf_old_PCh_fx[i] = (Word16) ( st->lsf_old[i] * 2.56f ); tdm_lsfQ_PCh_fx[i] = (Word16) ( tdm_lsfQ_PCh[i] * 2.56f ); } @@ -1033,7 +1000,7 @@ ivas_error ivas_core_dec( { old_pitch_buf_fx[i] = float_to_fix16( st->old_pitch_buf[i], Q_var ); } - td_stereo_param_updt_fx( lsp_old_PCh_fx, lsf_old_PCh_fx, old_pitch_buf_fx + st->nb_subfr, + td_stereo_param_updt_fx( lsp_old_PCh_fx, st->lsf_old_fx, old_pitch_buf_fx + st->nb_subfr, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q_var ); for ( i = 0; i < M; i++ ) { @@ -1440,20 +1407,11 @@ ivas_error ivas_core_dec( /*-------------------cldfb-end---------------------------*/ - st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); - floatToFixed_arr(st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC); + //floatToFixed_arr(st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC); IF(st->hWIDec != NULL) { floatToFixed_arr(st->hWIDec->old_exc2, st->hWIDec->old_exc2_fx, st->Q_exc, L_EXC_MEM); } - if (st->hBWE_TD != NULL) - { - floatToFixed_arr(st->hBWE_TD->old_bwe_exc, st->hBWE_TD->old_bwe_exc_fx, st->Q_exc, PIT16k_MAX * 2); - } - if (st->hGSCDec != NULL) - { - st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; - } if (st->hMusicPF != NULL) { floatToFixed_arr(st->hMusicPF->dct_post_old_exc, st->hMusicPF->dct_post_old_exc_fx, st->Q_exc, DCT_L_POST - OFFSET2); @@ -1462,9 +1420,6 @@ ivas_error ivas_core_dec( floatToFixed_arr(st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, st->Q_syn2 - 1, NBPSF_PIT_MAX); st->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(st->hBPF->pst_mem_deemp_err, st->Q_syn2 - 1); floatToFixed_arr(st->hBPF->mem_mean_pit, st->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST); - Copy(st->hBPF->Track_on_hist, st->hBPF->Track_on_hist_fx, L_TRACK_HIST); - Copy(st->hBPF->vibrato_hist, st->hBPF->vibrato_hist_fx, L_TRACK_HIST); - st->hBPF->pst_lp_ener_fx = float_to_fix16(st->hBPF->pst_lp_ener, Q8); st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15); } @@ -1557,7 +1512,7 @@ ivas_error ivas_core_dec( { mvr2r(synth[n], hSCE->save_synth, output_frame); } - fixedToFloat_arr(st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC); + //fixedToFloat_arr(st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC); if (st->hMusicPF != NULL) { fixedToFloat_arr(st->hMusicPF->dct_post_old_exc_fx, st->hMusicPF->dct_post_old_exc, st->Q_exc, DCT_L_POST - OFFSET2); @@ -1566,9 +1521,6 @@ ivas_error ivas_core_dec( fixedToFloat_arr(st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, st->Q_syn2 - 1, NBPSF_PIT_MAX); st->hBPF->pst_mem_deemp_err = fixedToFloat(st->hBPF->pst_mem_deemp_err_fx, st->Q_syn2 - 1); fixedToFloat_arr(st->hBPF->mem_mean_pit_fx, st->hBPF->mem_mean_pit, Q4, L_TRACK_HIST); - Copy(st->hBPF->Track_on_hist_fx, st->hBPF->Track_on_hist, L_TRACK_HIST); - Copy(st->hBPF->vibrato_hist_fx, st->hBPF->vibrato_hist, L_TRACK_HIST); - st->hBPF->pst_lp_ener = fixedToFloat(st->hBPF->pst_lp_ener_fx, Q8); st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15); } @@ -1611,11 +1563,9 @@ ivas_error ivas_core_dec( /*------------------reset-code-start---------------------*/ /*reset function flags*/ - Word8 reset_wb_tbe_extras = 0; Word8 reset_wb_tbe_synth = 0; Word8 reset_swb_tbe = 0; Word8 reset_swb_tbe_synth = 0; - Word8 reset_fb_tbe_synth = 0; if (st->hBWE_FD != NULL) { @@ -1667,8 +1617,6 @@ ivas_error ivas_core_dec( reset_swb_tbe = 1; reset_swb_tbe_synth = 1; - fixedToFloat_arr(st->GainShape_Delay, st->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2); - IF(EQ_16(output_frame, L_FRAME16k)) { /* reset in case that SWB TBE layer is transmitted, but the output x`x`is 16kHz sampled */ @@ -1676,46 +1624,23 @@ ivas_error ivas_core_dec( } fixedToFloat_arr(st->hBWE_TD->int_3_over_2_tbemem_dec_fx, st->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); st->hBWE_TD->prev_pow_exc16kWhtnd = (float)st->hBWE_TD->prev_pow_exc16kWhtnd_fx / 32767; - st->hBWE_TD->prev_mix_factor = (float)st->hBWE_TD->prev_mix_factor_fx / 32767; - } - ELSE IF((EQ_16(st->extl, SWB_TBE) || EQ_16(st->extl, FB_TBE)) && - (NE_32(st->last_total_brate, st->total_brate) || NE_16(st->last_bwidth, st->bwidth) || - NE_16(st->last_codec_mode, MODE1) || NE_16(st->rf_flag, st->rf_flag_last))) - { - fixedToFloat_arr(st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER); // setting to zero - fixedToFloat_arr(st->hBWE_TD->state_syn_shbexc_fx, st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD); // setting to zero - fixedToFloat_arr(st->hBWE_TD->mem_stp_swb_fx, st->hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER); // setting to zero - fixedToFloat_arr(st->hBWE_TD->mem_zero_swb_fx, st->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER); // setting to zero - st->hBWE_TD->gain_prec_swb = fixedToFloat(st->hBWE_TD->gain_prec_swb_fx, 14); /* Q14 = 1 */ } ELSE IF(st->hBWE_TD != NULL && (st->last_core == TCX_20_CORE || st->last_core == TCX_10_CORE)) { /*------------TBEreset_dec_ivas_fx-start------------------*/ - IF(NE_16(st->last_core, ACELP_CORE)) - { - fixedToFloat_arr(st->hBWE_TD->old_bwe_exc_fx, st->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2); // setting to zero - st->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat(st->hBWE_TD->bwe_non_lin_prev_scale_fx, 0); // setting to zero - } IF(EQ_16(st->bwidth, WB)) { - reset_wb_tbe_extras = 1; reset_wb_tbe_synth = 1; - fixedToFloat_arr(st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb, 0, 7); // setting to zero - fixedToFloat_arr(st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, 0, 10); // setting to zero - fixedToFloat_arr(st->hBWE_TD->state_syn_shbexc_fx, st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4); fixedToFloat_arr(st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); - fixedToFloat_arrL(st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, 0, 2); } ELSE IF(EQ_16(st->bwidth, SWB) || EQ_16(st->bwidth, FB)) { reset_swb_tbe = 1; reset_swb_tbe_synth = 1; - fixedToFloat_arr(st->GainShape_Delay, st->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2); // setting to zero fixedToFloat_arr(st->hBWE_TD->int_3_over_2_tbemem_dec_fx, st->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); // setting to zero fixedToFloat_arr(st->hBWE_TD->mem_resamp_HB_32k_fx, st->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero st->hBWE_TD->prev_pow_exc16kWhtnd = (float)st->hBWE_TD->prev_pow_exc16kWhtnd_fx / 32767; /*Q15 1.f*/ - st->hBWE_TD->prev_mix_factor = (float)st->hBWE_TD->prev_mix_factor_fx / 32767; /*Q15 1.f */ IF(EQ_16(st->bwidth, FB)) { @@ -1725,7 +1650,6 @@ ivas_error ivas_core_dec( } fixedToFloat_arr(st->hBWE_TD->fb_state_lpc_syn_fx, st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); st->hBWE_TD->fb_tbe_demph = fixedToFloat(st->hBWE_TD->fb_tbe_demph_fx, 0); // setting to zero - reset_fb_tbe_synth = 1; } } /*------------TBEreset_dec_ivas_fx-end--------------------*/ @@ -1735,42 +1659,27 @@ ivas_error ivas_core_dec( { fixedToFloat_arr(st->hBWE_TD->fb_state_lpc_syn_fx, st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); st->hBWE_TD->fb_tbe_demph = fixedToFloat(st->hBWE_TD->fb_tbe_demph_fx, 0); // setting to zero - reset_fb_tbe_synth = 1; } IF(NE_16(st->last_extl, WB_TBE) && EQ_16(st->extl, WB_TBE)) { - reset_wb_tbe_extras = 1; reset_wb_tbe_synth = 1; - fixedToFloat_arr(st->hBWE_TD->state_syn_shbexc_fx, st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4); // setting to zero fixedToFloat_arr(st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero - fixedToFloat_arrL(st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, 0, 2); // setting to zero } IF(reset_swb_tbe) { - fixedToFloat_arrL(st->hBWE_TD->mem_csfilt_fx, st->hBWE_TD->mem_csfilt, 0, 2); // setting to zero - fixedToFloat_arr(st->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, st->hBWE_TD->mem_genSHBexc_filt_down_shb, 0, (2 * ALLPASSSECTIONS_STEEP + 1)); // setting to zero - fixedToFloat_arr(st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER); // setting to zero fixedToFloat_arr(st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero - fixedToFloat_arr(st->hBWE_TD->state_syn_shbexc_fx, st->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD); // setting to zero - fixedToFloat_arr(st->hBWE_TD->mem_stp_swb_fx, st->hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER); // setting to zero st->hBWE_TD->tbe_demph = fixedToFloat(st->hBWE_TD->tbe_demph_fx, 0); // setting to zero st->hBWE_TD->tbe_premph = fixedToFloat(st->hBWE_TD->tbe_premph_fx, 0); // setting to zero - st->hBWE_TD->gain_prec_swb = fixedToFloat(st->hBWE_TD->gain_prec_swb_fx, 14); // setting to zero } IF(reset_swb_tbe_synth) { fixedToFloat_arrL(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, st->hBWE_TD->genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE); // setting to zero // setting to zero fixedToFloat_arr(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero } - IF(reset_wb_tbe_extras) - { - fixedToFloat_arr(st->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero - fixedToFloat_arr(st->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, st->hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero - } IF(reset_wb_tbe_synth) { fixedToFloat_arr(st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero @@ -1778,14 +1687,6 @@ ivas_error ivas_core_dec( // fixedToFloat(st->hBWE_TD->state_32and48k_WB_upsample_fx, st->hBWE_TD->state_32and48k_WB_upsample,0, 2 * ALLPASSSECTIONS_STEEP); buffer not there in float code* fixedToFloat_arr(st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN); // setting to zero } - IF(reset_fb_tbe_synth) - { - fixedToFloat_arrL(st->hBWE_TD->fbbwe_hpf_mem_fx[0], st->hBWE_TD->fbbwe_hpf_mem[0], 0, 4); // setting to zero - fixedToFloat_arrL(st->hBWE_TD->fbbwe_hpf_mem_fx[1], st->hBWE_TD->fbbwe_hpf_mem[1], 0, 4); // setting to zero - fixedToFloat_arrL(st->hBWE_TD->fbbwe_hpf_mem_fx[2], st->hBWE_TD->fbbwe_hpf_mem[2], 0, 4); // setting to zero - fixedToFloat_arrL(st->hBWE_TD->fbbwe_hpf_mem_fx[3], st->hBWE_TD->fbbwe_hpf_mem[3], 0, 4); // setting to zero - st->hBWE_TD->prev_fbbwe_ratio = fixedToFloat(st->hBWE_TD->prev_fbbwe_ratio_fx, 0); // scaling unknown setting to 1 - } } /* Interp_3_2 CNG buffers reset */ IF(st->hTdCngDec != NULL && EQ_32(st->output_Fs, 48000) && ((GT_32(st->last_core_brate, SID_2k40)) && (EQ_32(st->core_brate, FRAME_NO_DATA) || EQ_32(st->core_brate, SID_2k40)))) @@ -1811,7 +1712,6 @@ ivas_error ivas_core_dec( } st->enerLH = fixedToFloat(st->enerLH_fx, st->enerLH_fx_Q); // Q / 2 - st->tilt_wb = fix16_to_float(st->tilt_wb_fx, 11); st->enerLL = fixedToFloat(st->enerLL_fx, st->enerLL_fx_Q); #endif /*---------------------------------------------------------------------* @@ -1833,8 +1733,8 @@ ivas_error ivas_core_dec( Word32 hb_synth_fx32[L_FRAME48k]; Word16 Q_syn_hb; - st->Q_syn = 0; - st->Q_exc = 8; + //st->Q_syn = 0; + //st->Q_exc = 8; Q_input = 0; Q_hb_synth_fx = 0; Q_synth_fx = 0; @@ -1846,12 +1746,10 @@ ivas_error ivas_core_dec( FD_BWE_DEC_HANDLE hBWE_FD; hBWE_FD = st->hBWE_FD; - st->tilt_wb_fx = (Word16) floatToFixed( st->tilt_wb, Q11 ); st->prev_tilt_code_dec_fx = (Word16) floatToFixed( st->prev_tilt_code_dec, Q15 ); floatToFixed_arr( voice_factors[n], voice_factors_fx[n], Q15, NB_SUBFR16k ); floatToFixed_arr( pitch_buf[n], pitch_buf_fx[n], Q6, NB_SUBFR16k ); st->attenu_fx = (Word16) ( st->attenu1 * ( 1 << 15 ) ); - floatToFixed_arr( &st->tilt_swb, &st->tilt_swb_fx, Q11, 1 ); st->cummulative_damping = float_to_fix16( st->cummulative_damping_float, Q15 ); st->prev_ener_shb_fx = float_to_fix16( st->prev_ener_shb, 1 ); st->enerLH_fx = floatToFixed( st->enerLH, 0 ); // Check if Q_syn2 @@ -1867,28 +1765,14 @@ ivas_error ivas_core_dec( IF( hBWE_TD != NULL ) { hBWE_TD->GainFrame_prevfrm_fx = floatToFixed( hBWE_TD->GainFrame_prevfrm, Q18 ); - floatToFixed_arr( hBWE_TD->lsp_prevfrm, hBWE_TD->lsp_prevfrm_fx, Q15, LPC_SHB_ORDER ); - hBWE_TD->GainAttn_fx = (Word16) floatToFixed( hBWE_TD->GainAttn, Q15 ); - - floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arr( hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, ( st->prev_Q_bwe_exc - 16 ), 2 * ALLPASSSECTIONS_STEEP + 1 ); - floatToFixed_arrL( hBWE_TD->mem_csfilt, hBWE_TD->mem_csfilt_fx, st->prev_Q_bwe_exc, 2 ); floatToFixed_arr( hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_shb_fx, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP ); floatToFixed_arr( hBWE_TD->state_lsyn_filt_dwn_shb, hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP ); floatToFixed_arr( hBWE_TD->mem_resamp_HB, hBWE_TD->state_32and48k_WB_upsample_fx, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP ); floatToFixed_arr( hBWE_TD->mem_resamp_HB, hBWE_TD->mem_resamp_HB_fx, st->prev_Qx, INTERP_3_1_MEM_LEN ); - floatToFixed_arr( &st->hBWE_TD->prev_tilt_para, &st->hBWE_TD->prev_tilt_para_fx, Q10, 1 ); floatToFixed_arr( &st->hBWE_TD->tilt_swb_fec, &st->hBWE_TD->tilt_swb_fec_fx, Q11, 1 ); - floatToFixed_arr( &st->hBWE_TD->tilt_mem, &st->hBWE_TD->tilt_mem_fx, Q12, 1 ); - st->hBWE_TD->prev_GainShape_fx = float_to_fix16( st->hBWE_TD->prev_GainShape, Q15 ); - st->hBWE_TD->gain_prec_swb_fx = float_to_fix16( st->hBWE_TD->gain_prec_swb, Q14 ); - floatToFixed_arr( st->hBWE_TD->swb_lsp_prev_interp, st->hBWE_TD->swb_lsp_prev_interp_fx, Q15, LPC_SHB_ORDER ); - floatToFixed_arr( st->hBWE_TD->prev_lsf_diff, st->hBWE_TD->prev_lsf_diff_fx, Q15, LPC_SHB_ORDER - 2 ); - floatToFixed_arr( st->hBWE_TD->GainShape_Delay, st->hBWE_TD->GainShape_Delay_fx, Q15, NUM_SHB_SUBFR / 2 ); floatToFixed_arr( st->hBWE_TD->cur_sub_Aq, st->hBWE_TD->cur_sub_Aq_fx, Q12, M + 1 ); st->hBWE_TD->prev1_shb_ener_sf_fx = floatToFixed( st->hBWE_TD->prev1_shb_ener_sf, 0 ); // recheck @@ -1898,24 +1782,17 @@ ivas_error ivas_core_dec( st->hBWE_TD->prev_mixFactors_fx = float_to_fix16( st->hBWE_TD->prev_mixFactors, Q15 ); // recheck floatToFixed_arr( hBWE_TD->old_bwe_exc_extended, hBWE_TD->old_bwe_exc_extended_fx, st->prev_Q_bwe_exc - 16, NL_BUFF_OFFSET ); - floatToFixed_arr( hBWE_TD->mem_stp_swb, hBWE_TD->mem_stp_swb_fx, st->prev_Q_bwe_exc - 16, LPC_SHB_ORDER ); - floatToFixed_arr( hBWE_TD->mem_zero_swb, hBWE_TD->mem_zero_swb_fx, st->prev_Q_bwe_exc - 16, LPC_SHB_ORDER ); hBWE_TD->tbe_premph_fx = (Word16) check_bounds_l( floatToFixed( hBWE_TD->tbe_premph, st->prev_Q_bwe_exc - 16 ), -32768, 32767 ); hBWE_TD->tbe_demph_fx = (Word16) check_bounds_l( floatToFixed( hBWE_TD->tbe_demph, st->prev_Q_bwe_exc - 16 - NOISE_QADJ ), -32768, 32767 ); hBWE_TD->fb_tbe_demph_fx = (Word16) check_bounds_l( floatToFixed( hBWE_TD->fb_tbe_demph, st->prev_Q_bwe_exc_fb ), -32768, 32767 ); floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, st->prev_Q_bwe_exc_fb - 16 - 4, LPC_SHB_ORDER ); - hBWE_TD->prev_mix_factor_fx = float_to_fix16( hBWE_TD->prev_mix_factor, Q15 ); - - hBWE_TD->prev_fbbwe_ratio_fx = floatToFixed( hBWE_TD->prev_fbbwe_ratio, 0 ); hBWE_TD->prev_wb_bwe_frame_pow_fx = floatToFixed( hBWE_TD->prev_wb_bwe_frame_pow, st->prev_frame_pow_exp ); floatToFixed_arr( hBWE_TD->old_tbe_synth, hBWE_TD->old_tbe_synth_fx, st->prev_Qx, L_SHB_TRANSITION_LENGTH ); - floatToFixed_arr( hBWE_TD->state_syn_shbexc, hBWE_TD->state_syn_shbexc_fx, st->prev_Q_bwe_syn, L_SHB_LAHEAD ); // Check hBWE_TD->prev_pow_exc16kWhtnd_fx32 = floatToFixed( hBWE_TD->prev_pow_exc16kWhtnd, 0 ); - floatToFixed_arr( st->hBWE_TD->state_lpc_syn, st->hBWE_TD->state_lpc_syn_fx, st->prev_Q_bwe_syn, 10 ); // Check floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, st->prev_Q_bwe_syn2, L_SHB_LAHEAD ); // Check for ( int i = 0; i < INTERP_3_2_MEM_LEN; i++ ) @@ -2034,7 +1911,7 @@ ivas_error ivas_core_dec( IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && GT_16( st->bws_cnt, 0 ) ) ) { /* SWB TBE decoder */ - Word16 Q_white_exc; + Q_white_exc = 0; ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx, tmp_buffer_fx /*fb_exc*/, hb_synth_fx32, pitch_buf_fx[n], &Q_white_exc ); Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); // Check @@ -2122,7 +1999,6 @@ ivas_error ivas_core_dec( } #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - st->tilt_wb = fixedToFloat(st->tilt_wb_fx, Q11); st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); fixedToFloat_arr(voice_factors_fx[n], voice_factors[n], Q15, NB_SUBFR16k); fixedToFloat_arr(pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k); @@ -2142,29 +2018,13 @@ ivas_error ivas_core_dec( IF(hBWE_TD != NULL) { hBWE_TD->GainFrame_prevfrm = fixedToFloat(hBWE_TD->GainFrame_prevfrm_fx, Q18); - fixedToFloat_arr(hBWE_TD->lsp_prevfrm_fx, hBWE_TD->lsp_prevfrm, Q15, LPC_SHB_ORDER); - hBWE_TD->GainAttn = fixedToFloat(hBWE_TD->GainAttn_fx, Q15); - - fixedToFloat_arr(hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->mem_genSHBexc_filt_down_shb, (st->prev_Q_bwe_exc - 16), 2 * ALLPASSSECTIONS_STEEP + 1); - fixedToFloat_arr(hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb2, (st->prev_Q_bwe_exc - 16), 2 * ALLPASSSECTIONS_STEEP + 1); - fixedToFloat_arr(hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3, (st->prev_Q_bwe_exc - 16), 2 * ALLPASSSECTIONS_STEEP + 1); - - fixedToFloat_arrL(hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_csfilt, st->prev_Q_bwe_exc, 2); fixedToFloat_arr(hBWE_TD->state_lsyn_filt_shb_fx, hBWE_TD->state_lsyn_filt_shb, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP); fixedToFloat_arr(hBWE_TD->state_lsyn_filt_dwn_shb_fx, hBWE_TD->state_lsyn_filt_dwn_shb, st->prev_Qx, 2 * ALLPASSSECTIONS_STEEP); fixedToFloat_arr(hBWE_TD->mem_resamp_HB_fx, hBWE_TD->mem_resamp_HB, st->prev_Qx, INTERP_3_1_MEM_LEN); - fixedToFloat_arr(&st->hBWE_TD->prev_tilt_para_fx, &st->hBWE_TD->prev_tilt_para, Q10, 1); fixedToFloat_arr(&st->hBWE_TD->tilt_swb_fec_fx, &st->hBWE_TD->tilt_swb_fec, Q11, 1); - fixedToFloat_arr(&st->hBWE_TD->tilt_mem_fx, &st->hBWE_TD->tilt_mem, Q12, 1); - fixedToFloat_arr(&st->tilt_swb_fx, &st->tilt_swb, Q11, 1); - st->hBWE_TD->prev_GainShape = fixedToFloat(st->hBWE_TD->prev_GainShape_fx, Q15); - st->hBWE_TD->gain_prec_swb = fixedToFloat(st->hBWE_TD->gain_prec_swb_fx, Q14); - fixedToFloat_arr(st->hBWE_TD->swb_lsp_prev_interp_fx, st->hBWE_TD->swb_lsp_prev_interp, Q15, LPC_SHB_ORDER); - fixedToFloat_arr(st->hBWE_TD->prev_lsf_diff_fx, st->hBWE_TD->prev_lsf_diff, Q15, LPC_SHB_ORDER - 2); - fixedToFloat_arr(st->hBWE_TD->GainShape_Delay_fx, st->hBWE_TD->GainShape_Delay, Q15, NUM_SHB_SUBFR / 2); fixedToFloat_arr(st->hBWE_TD->cur_sub_Aq_fx, st->hBWE_TD->cur_sub_Aq, Q12, M + 1); st->hBWE_TD->prev1_shb_ener_sf = fixedToFloat(st->hBWE_TD->prev1_shb_ener_sf_fx, 0); // recheck @@ -2174,8 +2034,6 @@ ivas_error ivas_core_dec( st->hBWE_TD->prev_mixFactors = fixedToFloat(st->hBWE_TD->prev_mixFactors_fx, Q15); // recheck fixedToFloat_arr(hBWE_TD->old_bwe_exc_extended_fx, hBWE_TD->old_bwe_exc_extended, st->prev_Q_bwe_exc - 16, NL_BUFF_OFFSET); - fixedToFloat_arr(hBWE_TD->mem_stp_swb_fx, hBWE_TD->mem_stp_swb, st->prev_Q_bwe_exc - 16, LPC_SHB_ORDER); - fixedToFloat_arr(hBWE_TD->mem_zero_swb_fx, hBWE_TD->mem_zero_swb, st->prev_Q_bwe_exc - 16, LPC_SHB_ORDER); hBWE_TD->tbe_premph = fixedToFloat(hBWE_TD->tbe_premph_fx, st->prev_Q_bwe_exc - 16); hBWE_TD->tbe_demph = fixedToFloat(hBWE_TD->tbe_demph_fx, st->prev_Q_bwe_exc - 16 - NOISE_QADJ); @@ -2193,15 +2051,9 @@ ivas_error ivas_core_dec( hBWE_TD->fb_tbe_demph = 0; set_f(hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); } - hBWE_TD->prev_mix_factor = fixedToFloat(hBWE_TD->prev_mix_factor_fx, Q15); - - hBWE_TD->prev_fbbwe_ratio = fixedToFloat(hBWE_TD->prev_fbbwe_ratio_fx, 0); - hBWE_TD->prev_wb_bwe_frame_pow = fixedToFloat(hBWE_TD->prev_wb_bwe_frame_pow_fx, st->prev_frame_pow_exp); - fixedToFloat_arr(hBWE_TD->state_syn_shbexc_fx, hBWE_TD->state_syn_shbexc, (st->prev_Q_bwe_syn), L_SHB_LAHEAD); // Check hBWE_TD->prev_pow_exc16kWhtnd = fixedToFloat(hBWE_TD->prev_pow_exc16kWhtnd_fx32, 0); - fixedToFloat_arr(st->hBWE_TD->state_lpc_syn_fx, st->hBWE_TD->state_lpc_syn, st->prev_Q_bwe_syn, 10); // Check fixedToFloat_arr(hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap, st->prev_Q_bwe_syn2, L_SHB_LAHEAD); // Check for (int i = 0; i < INTERP_3_2_MEM_LEN; i++) @@ -2339,16 +2191,11 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED Word32 *hb_synth_0 = (Word32 *) malloc( sizeof( Word32 ) * L_FRAME48k ); Word32 *hb_synth_1 = (Word32 *) malloc( sizeof( Word32 ) * L_FRAME48k ); - Word32 tmp_buffer_fx[L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED - set32_fx( tmp_buffer_fx, 0, L_FRAME48k ); -#endif - Word32 voice_factor_fx[NB_SUBFR16k]; - Word16 q = 16; + Word16 q = 11; floatToFixed_arrL( hb_synth[0], hb_synth_0, q, L_FRAME48k ); floatToFixed_arrL( hb_synth[1], hb_synth_1, q, L_FRAME48k ); - floatToFixed_arrL( tmp_buffer, tmp_buffer_fx, 16, L_FRAME48k ); - floatToFixed_arrL( voice_factors[0], voice_factor_fx, 16, NB_SUBFR16k ); + + if ( hCPE->hStereoDft != NULL ) { floatToFixed_arrL( hCPE->hStereoDft->hb_stefi_sig, hCPE->hStereoDft->hb_stefi_sig_fx, q, L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS ) ); @@ -2368,16 +2215,9 @@ ivas_error ivas_core_dec( hCPE->hStereoTCA->targetGain_fx = (Word32) ( hCPE->hStereoTCA->targetGain * ( 1u << 29 ) ); } - if ( hCPE->hStereoICBWE != NULL ) - { - floatToFixed_arrL( hCPE->hStereoICBWE->nlExc16k, hCPE->hStereoICBWE->nlExc16k_fx, 18, L_FRAME16k ); - floatToFixed_arrL( hCPE->hStereoICBWE->mixExc16k, hCPE->hStereoICBWE->mixExc16k_fx, 18, L_FRAME16k ); - floatToFixed_arrL( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, 20, LPC_SHB_ORDER + 1 ); - floatToFixed_arr( hCPE->hStereoICBWE->gshapeRef, hCPE->hStereoICBWE->gshapeRef_fx, 15, NUM_SHB_SUBFR ); - hCPE->hStereoICBWE->gFrameRef_fx = (Word32) ( hCPE->hStereoICBWE->gFrameRef * ( 1u << 19 ) ); - } - stereo_icBWE_dec_fx( hCPE, hb_synth_0, hb_synth_1, tmp_buffer_fx /*fb_synth_ref*/, voice_factor_fx, output_frame, &q ); + Scale_sig( tmp_buffer_fx, L_FRAME48k, Q11 - Q_white_exc ); + stereo_icBWE_dec_fx( hCPE, hb_synth_0, hb_synth_1, tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); fixedToFloat_arrL( hb_synth_0, hb_synth[0], q, L_FRAME48k ); @@ -2740,7 +2580,6 @@ ivas_error ivas_core_dec( Word32 exp_max = 0; Word32 output_fx_loc[L_FRAME48k]; - floatToFixed_arr(st->tilt_code_dec, st->tilt_code_dec_fx, 15, 5); floatToFixed_arr(st->old_synth_sw, st->old_synth_sw_fx, -2, 429); st->prev_tilt_code_dec_fx = floatToFixed(st->prev_tilt_code_dec, Q15); FOR(Word16 ind = 0; ind < 16; ind++) { diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 6bf647f57..e6d910aa2 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -730,13 +730,9 @@ ivas_error ivas_cpe_dec_fx( floatToFixed_arr(hCPE->hCoreCoder[0]->old_pitch_buf, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); hCPE->hStereoDft->hBpf->psf_att_fx = (Word16)floatToFixed(hCPE->hStereoDft->hBpf->psf_att, Q15); hCPE->hStereoDft->stab_fac_smooth_res_fx = floatToFixed(hCPE->hStereoDft->stab_fac_smooth_res, Q31); - Copy(hCPE->hStereoDft->hBpf->Track_on_hist, hCPE->hStereoDft->hBpf->Track_on_hist_fx, sizeof(hCPE->hStereoDft->hBpf->Track_on_hist_fx) / sizeof(hCPE->hStereoDft->hBpf->Track_on_hist_fx[0])); - Copy(hCPE->hStereoDft->hBpf->vibrato_hist, hCPE->hStereoDft->hBpf->vibrato_hist_fx, sizeof(hCPE->hStereoDft->hBpf->vibrato_hist_fx) / sizeof(hCPE->hStereoDft->hBpf->vibrato_hist_fx[0])); stereo_dft_dec_res_fx(hCPE, res_buf_fx, Q8, output_fix); - Copy(hCPE->hStereoDft->hBpf->vibrato_hist_fx, hCPE->hStereoDft->hBpf->vibrato_hist, sizeof(hCPE->hStereoDft->hBpf->vibrato_hist_fx) / sizeof(hCPE->hStereoDft->hBpf->vibrato_hist_fx[0])); - Copy(hCPE->hStereoDft->hBpf->Track_on_hist_fx, hCPE->hStereoDft->hBpf->Track_on_hist, sizeof(hCPE->hStereoDft->hBpf->Track_on_hist_fx) / sizeof(hCPE->hStereoDft->hBpf->Track_on_hist_fx[0])); hCPE->hStereoDft->stab_fac_smooth_res = fixedToFloat(hCPE->hStereoDft->stab_fac_smooth_res_fx, Q15); hCPE->hStereoDft->hBpf->psf_att = fixedToFloat(hCPE->hStereoDft->hBpf->psf_att_fx, Q15); fixedToFloat_arr(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); @@ -831,7 +827,6 @@ ivas_error ivas_cpe_dec_fx( hCPE->hStereoDft->first_frame = 0; } - sts[0]->stab_fac_fx = (Word16)floatToFixed(sts[0]->stab_fac, 15); sts[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(sts[0]->hFdCngDec->cna_rescale_fact, 15); sts[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(sts[0]->hFdCngDec->cna_act_fact, 15); floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index cd7f29bee..400245996 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3506,6 +3506,18 @@ void ivas_dirac_dec_render_sf( float diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; #ifdef IVAS_FLOAT_FIXED Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 *p_Rmat_fx; + /////////////////////////////////// to be removed //////////////////////////////////////////////// + if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) + { + p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; + floatToFixed_arrL( &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0], p_Rmat_fx, Q29, 9 ); + } + else + { + p_Rmat_fx = 0; + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////// #endif DIRAC_DEC_STACK_MEM DirAC_mem; @@ -3703,7 +3715,17 @@ void ivas_dirac_dec_render_sf( surCohRatio_fx[i] = float_to_fix( surCohRatio[i], Q_surCohRatio ); } } - + ////////////////////////////////////// to be removed ///////////////////////////////// + IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) + { + IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) + { + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[md_idx], hSpatParamRendCom->energy_ratio1_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[md_idx], hSpatParamRendCom->energy_ratio2_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + } + ///////////////////////////////////////////////////////////////////////////////////// ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, hDirACRend, st_ivas->hVBAPdata, @@ -3715,8 +3737,27 @@ void ivas_dirac_dec_render_sf( surCohRatio_fx, Q_surCohRatio, st_ivas->hCombinedOrientationData->shd_rot_max_order, - p_Rmat, + p_Rmat_fx, hodirac_flag ); + ///////////////////////////////////// to be removed ////////////////////////////////////////////// + IF( st_ivas->hMasa == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + + IF( hodirac_flag ) + { + fixedToFloat_arrL( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], &hDirACRend->h_output_synthesis_psd_state.direct_responses[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + ELSE + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_square, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////// #else ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, hDirACRend, @@ -3754,7 +3795,17 @@ void ivas_dirac_dec_render_sf( surCohRatio_fx[i] = float_to_fix( surCohRatio[i], Q_surCohRatio ); } } - + ////////////////////////////////////// to be removed ///////////////////////////////// + IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) + { + IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) + { + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[md_idx], hSpatParamRendCom->energy_ratio1_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[md_idx], hSpatParamRendCom->energy_ratio2_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + } + ///////////////////////////////////////////////////////////////////////////////////// ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, hDirACRend, st_ivas->hVBAPdata, @@ -3768,6 +3819,25 @@ void ivas_dirac_dec_render_sf( 0, NULL, hodirac_flag ); + ///////////////////////////////////// to be removed ////////////////////////////////////////////// + IF( st_ivas->hMasa == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + + IF( hodirac_flag ) + { + fixedToFloat_arrL( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], &hDirACRend->h_output_synthesis_psd_state.direct_responses[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + ELSE + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_square, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + //////////////////////////////////////////////////////////////////////////////////////////////////////////// #else ivas_dirac_dec_compute_directional_responses( hSpatParamRendCom, hDirACRend, diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index ea95d1fcb..e1722348f 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2847,11 +2847,14 @@ void ivas_destroy_dec( { free( st_ivas->p_output_f[i] ); st_ivas->p_output_f[i] = NULL; + } #ifdef IVAS_FLOAT_FIXED - free( st_ivas->p_output_fx[i] ); - st_ivas->p_output_fx[i] = NULL; -#endif + IF(st_ivas->p_output_fx[i] != NULL) + { + free(st_ivas->p_output_fx[i]); + st_ivas->p_output_fx[i] = NULL; } +#endif } /* main IVAS handle */ diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index cfe423a23..a3cc93a72 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -809,14 +809,12 @@ ivas_error ivas_jbm_dec_tc( { nchan_remapped = nchan_out; - if ( st_ivas->ivas_format == SBA_FORMAT ) + IF ( EQ_16(st_ivas->ivas_format, SBA_FORMAT )) { -#ifndef IVAS_FLOAT_FIXED - ivas_agc_dec_process( st_ivas->hSpar->hAgcDec, p_output, p_output, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &p_output[0][0], output_frame, "flt_ivas_agc_dec_process_output.txt", NULL ); -#endif // DUMPS_ENABLED -#else +#ifdef IVAS_FLOAT_FIXED + + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate); +#if 1 /*Float to Fixed changes */ FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) { output_fx[i] = malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( Word32 ) ); @@ -825,33 +823,137 @@ ivas_error ivas_jbm_dec_tc( output_fx[i][j] = (Word32) ( p_output[i][j] * ONE_IN_Q14 ); } } - - ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( output_fx ), ( output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); - - FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) + Word16 ch, i; + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + Word16 num_bands_out, nchan_transport; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_out = nchan_transport; + Word16 j, b, i_ts, num_out_ch; + num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; + hSpar->hMdDec->Q_mixer_mat = 31; + Word16 num_in_ch; + num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, Q_factor_L(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) { - FOR( Word16 j = 0; j < output_frame; j++ ) + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_C_re_fx = s_min(Q_C_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_P_re_fx = s_min(Q_P_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, s_min(Q_C_re_fx, Q_P_re_fx)); + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) { - p_output[i][j] = (float) output_fx[i][j] / ONE_IN_Q11; + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } } +#endif + ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( output_fx ), ( output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame ); -#ifdef DUMPS_ENABLED - dbgwrite_txt( &p_output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); -#endif // DUMPS_ENABLED + IF (st_ivas->hSpar->hPCA != NULL) + { + ivas_pca_dec_fx(st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, output_fx); + } + ivas_spar_dec_gen_umx_mat_fx(st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, num_md_sub_frames); - FOR( Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ ) +#if 1 /*Fixed to float changes */ + FOR(Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++) { - free( output_fx[i] ); + FOR(Word16 j = 0; j < output_frame; j++) + { + p_output[i][j] = (float)output_fx[i][j] / ONE_IN_Q11; + } } -#endif // !IVAS_FLOAT_FIXED + FOR(Word16 i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++) + { + free(output_fx[i]); + } + + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + st_ivas->hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat(st_ivas->hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], st_ivas->hSpar->hMdDec->Q_mixer_mat); + } + } + } + } +#endif +#else + ivas_agc_dec_process(st_ivas->hSpar->hAgcDec, p_output, p_output, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame); if ( st_ivas->hSpar->hPCA != NULL ) { ivas_pca_dec( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, p_output ); } - ivas_spar_dec_gen_umx_mat( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) ); + ivas_spar_dec_gen_umx_mat(st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes(st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate)); +#endif } #ifndef IVAS_FLOAT_FIXED @@ -902,8 +1004,6 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_smoothed_nrg = Q6;//hCPE->hStereoDft->q_dft; hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - - st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15); floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); @@ -1158,7 +1258,128 @@ ivas_error ivas_jbm_dec_tc( if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) { num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ); +#ifdef IVAS_FLOAT_FIXED +#if 1 + Word16 ch, i; + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + Word16 Q_p_output = 14; + Word16 num_bands_out, nchan_transport; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + nchan_out = nchan_transport; + FOR(ch = 0; ch < nchan_transport; ch++) + { + FOR(i = 0; i < output_frame; i++) + { + p_output_fix[ch][i] = floatToFixed(p_output[ch][i], Q_p_output); + } + } + Word16 j, b, i_ts, num_out_ch; + num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; + hSpar->hMdDec->Q_mixer_mat = 31; + Word16 num_in_ch; + num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, Q_factor_L(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_C_re_fx = s_min(Q_C_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_P_re_fx = s_min(Q_P_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, s_min(Q_C_re_fx, Q_P_re_fx)); + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + } +#endif + ivas_sba_mix_matrix_determiner_fx(st_ivas->hSpar, p_output_fix, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames); +#if 1 /*Fixed to float changes */ + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat(hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + } + FOR(Word16 c = 0; c < nchan_transport; c++) + { + FOR(j = 0; j < output_frame; j++) + { + p_output[c][j] = (float)p_output_fix[c][j]; + } + } +#endif +#else ivas_sba_mix_matrix_determiner( st_ivas->hSpar, p_output, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames ); +#endif } else if ( st_ivas->renderer_type != RENDERER_DISABLE ) { @@ -1183,6 +1404,7 @@ ivas_error ivas_jbm_dec_tc( { p_output[i][j] = (float)p_output_fix[i][j] / ONE_IN_Q11; } + //dbgwrite_txt_flt(p_output[i], output_frame, "p_output.txt"); } #else ivas_spar_dec_agc_pca(st_ivas, p_output, output_frame); @@ -1218,7 +1440,29 @@ ivas_error ivas_jbm_dec_tc( else if ( st_ivas->ivas_format == SBA_FORMAT && ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { /* loudness correction */ +#ifdef IVAS_FLOAT_FIXED + + Word16 Q_p_output = 31; + for ( int i = 0; i < st_ivas->nchan_transport; i++ ) + { + Q_p_output = s_min( Q_p_output, Q_factor_arrL( p_output[i], output_frame ) ); + } + for ( int i = 0; i < st_ivas->nchan_transport; i++ ) + { + floatToFixed_arrL( p_output[i], p_output_fix[i], Q_p_output, output_frame ); + } + + ivas_dirac_dec_binaural_sba_gain_fx(p_output_fix, nchan_remapped, output_frame); + + Q_p_output = Q_p_output - 1; + for (int i = 0; i < st_ivas->nchan_transport; i++) + { + fixedToFloat_arrL(p_output_fix[i], p_output[i], Q_p_output, output_frame); + } +#else ivas_dirac_dec_binaural_sba_gain( p_output, nchan_remapped, output_frame ); +#endif + } } else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) @@ -1748,7 +1992,6 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15); floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); @@ -2021,7 +2264,8 @@ ivas_error ivas_jbm_dec_tc( } Word16 j, b, i_ts, num_out_ch; num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; - Word16 Q_C_re_fx = 31, Q_P_re_fx = 31, Q_mixer_mat = 31; + Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; + hSpar->hMdDec->Q_mixer_mat = 31; Word16 num_in_ch; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) @@ -2032,7 +2276,7 @@ ivas_error ivas_jbm_dec_tc( { FOR( b = 0; b < num_bands_out; b++ ) { - Q_mixer_mat = s_min( Q_mixer_mat, Q_factor_L( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] ) ); + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, Q_factor_L( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] ) ); } } } @@ -2063,7 +2307,7 @@ ivas_error ivas_jbm_dec_tc( } } } - Q_mixer_mat = s_min( Q_mixer_mat, s_min( Q_C_re_fx, Q_P_re_fx ) ); + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, s_min( Q_C_re_fx, Q_P_re_fx ) ); FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -2072,7 +2316,7 @@ ivas_error ivas_jbm_dec_tc( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } @@ -2082,7 +2326,7 @@ ivas_error ivas_jbm_dec_tc( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } @@ -2092,13 +2336,13 @@ ivas_error ivas_jbm_dec_tc( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } } #endif - ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, &Q_mixer_mat ); + ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames); #if 1 /*Fixed to float changes */ FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { @@ -2108,7 +2352,7 @@ ivas_error ivas_jbm_dec_tc( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat( hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat( hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } @@ -2829,7 +3073,6 @@ ivas_error ivas_jbm_dec_tc( hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft; } - st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->stab_fac, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact, 15); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx = (Word16)floatToFixed(st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact, 15); floatToFixed_arrL(&hCPE->hStereoDft->res_gains_ind[0][0], &hCPE->hStereoDft->res_gains_ind_fx[0][0], Q26, sizeof(hCPE->hStereoDft->res_gains_ind_fx) / sizeof(hCPE->hStereoDft->res_gains_ind_fx[0][0])); @@ -3469,7 +3712,230 @@ void ivas_jbm_dec_feed_tc_to_renderer( } else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) { +#ifdef IVAS_FLOAT_FIXED +#if 1 + Word16 num_in_ch, num_bands_out, nchan_transport, num_md_sub_frames, ch, i, j, b, i_ts, num_out_ch; + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; + hSpar->hMdDec->Q_mixer_mat = 31; + num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, Q_factor_L(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_C_re_fx = s_min(Q_C_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_P_re_fx = s_min(Q_P_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, s_min(Q_C_re_fx, Q_P_re_fx)); + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + } + + + IF(hSpar->hMdDec->td_decorr_flag && !(EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM))) + { + Word16 ch_sba_idx = 0; + IF(EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT)) + { + IF(EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC)) + { + ch_sba_idx = st_ivas->nchan_ism; move16(); + } + } + st_ivas->hTcBuffer->q_tc_fx = 14; + for (int i = 0; i < ivas_sba_get_nchan_metadata(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate) + ch_sba_idx; i++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], st_ivas->hTcBuffer->q_tc_fx, min(nSamplesForRendering, (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC))); + } + } + } + + if (st_ivas->hDiracDecBin != NULL && (st_ivas->hDiracDecBin->useTdDecorr)) + { + st_ivas->hTcBuffer->q_tc_fx = 14; + int16_t nSamplesLeftForTD, default_frame; + default_frame = (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); + nSamplesLeftForTD = nSamplesForRendering; + int size = 0; + + while (nSamplesLeftForTD) + { + int16_t nSamplesToDecorr = min(nSamplesLeftForTD, default_frame); + size += nSamplesToDecorr; + nSamplesLeftForTD -= nSamplesToDecorr; + } + size = s_max(size, default_frame); + for (int ch_idx = 0; ch_idx < BINAURAL_CHANNELS + 2; ch_idx++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch_idx], st_ivas->hTcBuffer->tc_fx[ch_idx], st_ivas->hTcBuffer->q_tc_fx, size); + } + } + nchan_transport = st_ivas->nchan_transport; + if (st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && (st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 || (st_ivas->hDecoderConfig->ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE > 0 && st_ivas->hCPE[0]->nchan_out == 1))) + { + nchan_transport = 1; /* Only one channel transported */ + } + + if (((st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT) && st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag) || + ((st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC) && (nchan_transport == 1 && st_ivas->nchan_transport != 2 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag))) + { + Word32 max_cngNoiseLevel = 0; + Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; + FOR(int i = 0; i < FFTCLDFBLEN; i++) + { + max_cngNoiseLevel = L_max(L_abs((Word32)st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[i]), max_cngNoiseLevel); + } + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = norm_l(max_cngNoiseLevel); + + floatToFixed_arr(st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, Q13, M + 1); + + floatToFixed_arrL(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, st->hFdCngDec->hFdCngCom->cngNoiseLevel, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN); + + for (int i = 0; i < FFTLEN; i++) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx[i] = float_to_fix(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt[i], 15); + } + } +#endif + ivas_sba_dec_digest_tc_fx(st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available); + +#if 1 + if (st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) + { + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + st_ivas->hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat(st_ivas->hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], st_ivas->hSpar->hMdDec->Q_mixer_mat); + } + } + } + } + + IF(hSpar->hMdDec->td_decorr_flag && !(EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM))) + { + Word16 ch_sba_idx = 0; + IF(EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT)) + { + IF(EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC)) + { + ch_sba_idx = st_ivas->nchan_ism; move16(); + } + } + for (int i = 0; i < ivas_sba_get_nchan_metadata(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate) + ch_sba_idx; i++) + { + fixedToFloat_arrL(st_ivas->hTcBuffer->tc_fx[i], st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->q_tc_fx, min(nSamplesForRendering, (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC))); + } + } + } + + if (st_ivas->hDiracDecBin != NULL && (st_ivas->hDiracDecBin->useTdDecorr)) + { + st_ivas->hTcBuffer->q_tc_fx = 14; + int16_t nSamplesLeftForTD, default_frame; + default_frame = (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC); + nSamplesLeftForTD = nSamplesForRendering; + int size = 0; + + while (nSamplesLeftForTD) + { + int16_t nSamplesToDecorr = min(nSamplesLeftForTD, default_frame); + size += nSamplesToDecorr; + nSamplesLeftForTD -= nSamplesToDecorr; + } + size = s_max(size, default_frame); + for (int ch_idx = 0; ch_idx < BINAURAL_CHANNELS + 2; ch_idx++) + { + fixedToFloat_arrL(st_ivas->hTcBuffer->tc_fx[ch_idx], st_ivas->hTcBuffer->tc[ch_idx], st_ivas->hTcBuffer->q_tc_fx, size); + } + } + + if (((st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT) && st_ivas->nchan_transport == 1 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag) || + ((st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC) && (nchan_transport == 1 && st_ivas->nchan_transport != 2 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag))) + { + Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; + fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 15, st->hFdCngDec->hFdCngCom->fftlen); + fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->fftBuffer, st->hFdCngDec->hFdCngCom->fftBuffer_flt, 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp, st->hFdCngDec->hFdCngCom->fftlen); + + fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->exc_cng_32fx, st->hFdCngDec->hFdCngCom->exc_cng_flt, 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp - 9, st->hFdCngDec->hFdCngCom->frameSize); + fixedToFloat_arrL(st_ivas->hTcBuffer->tc_fx[1], st_ivas->hTcBuffer->tc[1], 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp - 9, st->hFdCngDec->hFdCngCom->frameSize); + } +#endif +#else ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); +#endif } else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) { diff --git a/lib_dec/ivas_mct_core_dec.c b/lib_dec/ivas_mct_core_dec.c index 4a3147df6..2196423cc 100644 --- a/lib_dec/ivas_mct_core_dec.c +++ b/lib_dec/ivas_mct_core_dec.c @@ -157,6 +157,108 @@ void ivas_mct_side_bits( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_mct_side_bits_fx( + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + CPE_DEC_HANDLE hCPE[MCT_MAX_BLOCKS], /* i/o: CPE decoder structure */ + const Word16 nCPE, /* i : number of CPEs */ + Decoder_State *st0, /* i : decoder handle for Bstr */ + const Word16 bfi, /* i : BFI flag */ + UWord16 *bitstream, /* o : bitstream indices */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +) +{ + Word16 ch, cpe_id, nChannels, i, k, nSubframes; + Word16 nf_side_bits, availableBits, next_bit_pos, nf_bits; + Word16 chBitRatios[MCT_MAX_CHANNELS]; + Decoder_State *st, *sts[MCT_MAX_CHANNELS]; + + nf_side_bits = 0; + nChannels = hMCT->nchan_out_woLFE; + + /*initializations */ + FOR ( (cpe_id = 0, i = 0); cpe_id < nCPE; cpe_id++ ) + { + FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + sts[i] = hCPE[cpe_id]->hCoreCoder[ch]; + i = add(i, 1); + move16(); + } + } + + /*first read IFG bits */ + IF ( !bfi && st0->igf ) + { + FOR ( ch = 0; ch < nChannels; ch++ ) + { + st = sts[ch]; + IF ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + continue; + } + + mdct_read_IGF_bits_fx( st, st0 ); + } + } + + /*read MCT data and calculate frame bits per channel */ + FOR ( ch = 0; ch < (Word16) ( hMCT->nchan_out_woLFE * 0.5 ); ch++ ) + { + initMdctStereoDecData_fx( hMCT->hBlockData[ch]->hStereoMdct, st0->igf, st0->hIGFDec->igfData.igfInfo.grid, hCPE[0]->element_brate, st0->bwidth ); + } + + IF ( !bfi ) + { + availableBits = 0; + + ivas_mct_dec_mct_fx( hMCT, sts, nChannels ); + + /*read channel bitrate ratios from bitstream*/ + FOR ( ch = 0; ch < nChannels; ch++ ) + { + st = sts[ch]; + + IF ( st->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + chBitRatios[ch] = 0; + st->bits_frame_channel = 0; + continue; + } + chBitRatios[ch] = get_next_indice_fx( sts[0], NBBITS_MCT_RATIO ); + + nSubframes = ( st->core == TCX_10_CORE ) ? NB_DIV : 1; + + FOR ( k = 0; k < nSubframes; k++ ) + { + nf_side_bits += ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + } + } + + availableBits = (Word16) ( ( ivas_total_brate / FRAMES_PER_SEC ) - sts[0]->next_bit_pos - nf_side_bits ); + availableBits -= nb_bits_metadata; + + splitAvailableBitsMCT( (void **) sts, availableBits, chBitRatios, DEC, nChannels ); + + next_bit_pos = sts[0]->next_bit_pos; + FOR ( ch = 1; ch < nChannels; ch++ ) + { + nf_bits = ( sts[ch - 1]->core == TCX_20_CORE ? 1 : NB_DIV ) * ( NBITS_TCX_GAIN + NOISE_FILL_RANGES * NBITS_NOISE_FILL_LEVEL ); + + IF ( chBitRatios[ch - 1] == 0 ) /* indicates LFE with no content */ + { + nf_bits = 0; + } + next_bit_pos += sts[ch - 1]->bits_frame_channel + nf_bits; + sts[ch]->bit_stream = bitstream + next_bit_pos; + } + } + + return; +} +#endif + /*-------------------------------------------------------------------* * ivas_mct_core_dec() diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 6d7de2f6f..cc792a407 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -62,6 +62,7 @@ static ivas_error ivas_mc_dec_reconfig( Decoder_Struct *st_ivas, uint16_t *nSamp * Multi-channel Coding Tool (MCT) decoding routine *--------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_mct_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output[], /* o : output synthesis signal */ @@ -216,7 +217,6 @@ ivas_error ivas_mct_dec( sts[ch]->gamma = float_to_fix16( sts[ch]->gamma_float, Q15 ); sts[ch]->preemph_fac = float_to_fix16( sts[ch]->preemph_fac_float, Q15 ); sts[ch]->Mode2_lp_gainp = float_to_fix( sts[ch]->lp_gainp, Q16 ); - sts[ch]->stab_fac_fx = float_to_fix16( sts[ch]->stab_fac, Q15 ); sts[ch]->hTcxCfg->na_scale = float_to_fix16( sts[ch]->hTcxCfg->na_scale_flt, Q15 ); sts[ch]->hTcxCfg->sq_rounding = float_to_fix16( sts[ch]->hTcxCfg->sq_rounding_flt, Q15 ); sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); @@ -273,7 +273,6 @@ ivas_error ivas_mct_dec( sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - sts[ch]->stab_fac = fix16_to_float( sts[ch]->stab_fac_fx, Q15 ); fixedToFloat_arr( Aq_fx[cpe_id][ch], Aq[cpe_id][ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); // 16bit to u8bit FOR( Word16 l = 0; l < IGF_START_MX; l++ ) @@ -798,6 +797,1046 @@ ivas_error ivas_mct_dec( pop_wmops(); return error; } +#else +ivas_error ivas_mct_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + float *output[], /* o : output synthesis signal */ + const Word16 output_frame, /* i : output frame length per channel */ + const Word16 nb_bits_metadata /* i : number of metadata bits */ +) +{ + Word16 n, nCPE, cpe_id; + MCT_DEC_HANDLE hMCT; + CPE_DEC_HANDLE hCPE; + float *x[CPE_CHANNELS][NB_DIV]; + Word16 param[MCT_MAX_BLOCKS][CPE_CHANNELS][DEC_NPRM_DIV * NB_DIV]; + Word16 param_lpc[MCT_MAX_BLOCKS][CPE_CHANNELS][NPRM_LPC_NEW]; + Word16 p_param[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Word16 nTnsBitsTCX10[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Word16 fUseTns[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; + Decoder_State **sts; + float synth[CPE_CHANNELS][L_FRAME_PLUS]; + int32_t ivas_total_brate; + ivas_error error; + + +#if 1 // Float to fix + + Decoder_State *st; + Word32 *output_fx[16]; + Word16 q_output = 11; + Word32 output_lfe_ch_fx[L_FRAME48k]; + FOR(Word16 i = 0; i < 12; i++) if(output[i]) { + output_fx[i] = malloc( sizeof( Word32 ) * L_FRAME48k ); + floatToFixed_arrL(output[i], output_fx[i], Q11, L_FRAME48k); + } + Word16 Aq_fx[MCT_MAX_BLOCKS][CPE_CHANNELS][( NB_SUBFR16k + 1 ) * ( M + 1 )]; + Word16 ch, k, l, i, j; + + Word32 *x_fx[CPE_CHANNELS][NB_DIV]; + Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]; + Word16 x_len[CPE_CHANNELS][NB_DIV] = { 0 }; + FOR(cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + FOR( i = 0; i < CPE_CHANNELS; ++i ) + { + FOR( j = 0; j < NB_DIV; ++j ) + { + x_e[i][j] = 20; + } + } + + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + st = hCPE->hCoreCoder[ch]; + IF(st->hTonalMDCTConc) + { + + FOR( i = 0; i < st->hTonalMDCTConc->nScaleFactors; i++) + { + st->hTonalMDCTConc->scaleFactorsBackground_fx[i] = float_to_fix(st->hTonalMDCTConc->scaleFactorsBackground_flt[i], 15); + } + st->hTonalMDCTConc->scf_fadeout = float_to_fix16(st->hTonalMDCTConc->scf_fadeout_flt, 15); + if (hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active) + { + FOR( 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]); + } + FOR( i = 0; i < 30; i++) + { + float pd = st->hTonalMDCTConc->pTCI_float->phaseDiff_float[i]; + if (pd >= PI2) + pd = fmodf(pd, PI2) - PI2; + st->hTonalMDCTConc->pTCI_fix->phaseDiff[i] = (Word16)floatToFixed(pd, Q12); + } + FOR( 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)); + } + //st->hTonalMDCTConc->nFramesLost = float_to_fix16( st->hTonalMDCTConc->nFramesLost, Q1 ); + } + f2me(st->hTonalMDCTConc->last_block_nrg_flt, &st->hTonalMDCTConc->last_block_nrg, &st->hTonalMDCTConc->last_block_nrg_exp); + } + st->old_fpitch = float_to_fix(st->old_fpitch_float, 16); + st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16(st->hTcxDec->tcxltp_last_gain_unmodified_float, 15); + + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + sts[ch]->gamma = (Word16)floatToFixed( sts[ch]->gamma_float, Q15 ); + sts[ch]->preemph_fac = (Word16)floatToFixed( sts[ch]->preemph_fac_float, Q15 ); + sts[ch]->Mode2_lp_gainp = floatToFixed( sts[ch]->lp_gainp, Q16 ); + sts[ch]->stab_fac_fx = (Word16)floatToFixed( sts[ch]->stab_fac, Q15 ); + sts[ch]->hTcxCfg->na_scale = (Word16)floatToFixed( sts[ch]->hTcxCfg->na_scale_flt, Q15 ); + sts[ch]->hTcxCfg->sq_rounding = (Word16)floatToFixed( sts[ch]->hTcxCfg->sq_rounding_flt, Q15 ); + sts[ch]->hTcxLtpDec->tcxltp_gain = (Word16)floatToFixed( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); + sts[ch]->inv_gamma = (Word16)floatToFixed( 1 / sts[ch]->gamma_float, Q14 ); + sts[ch]->hTcxCfg->preemph_fac = (Word16)floatToFixed( sts[ch]->hTcxCfg->preemph_fac_flt, Q15 ); + f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); + f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e ); + f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e ); + + sts[ch]->hTonalMDCTConc->lastPitchLag = float_to_fix( sts[ch]->hTonalMDCTConc->lastPitchLag_float, Q16 ); + // u8bit to 16bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[ch]->hIGFDec->infoTCXNoise_evs[l] = (Word16) sts[ch]->hIGFDec->infoTCXNoise[l]; + } + FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) + { + sts[ch]->hTcxDec->ltpGainMemory_fx[l] = float_to_fix16( sts[ch]->hTcxDec->ltpGainMemory[l], Q15 ); + } + sts[ch]->hTcxDec->cummulative_damping_tcx = float_to_fix16( sts[ch]->hTcxDec->cummulative_damping_tcx_float, Q15 ); + } + } + FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) + { + IF( sts[ch]->rate_switching_reset ) + { + floatToFixed_arr( sts[ch]->lsp_old, sts[ch]->lsp_old_fx, Q15, M ); + } + } + } + + IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev) f2me_buf(st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt); + IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev) f2me_buf(st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], &st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->sfbCnt); + IF(st_ivas->hParamMC && st_ivas->hParamMC->icld_q) floatToFixed_arr16(st_ivas->hParamMC->icld_q, st_ivas->hParamMC->icld_q_fx, 8, st_ivas->hParamMC->hMetadataPMC->num_parameter_bands * st_ivas->hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe); + IF(st_ivas->hParamMC && st_ivas->hParamMC->ls_conv_dmx_matrix) floatToFixed_arr32(st_ivas->hParamMC->ls_conv_dmx_matrix, st_ivas->hParamMC->ls_conv_dmx_matrix_fx, 15, st_ivas->hDecoderConfig->nchan_out * (st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe)); + IF(st_ivas->hLsSetUpConversion) FOR(Word16 chOutIdx = 0; chOutIdx < st_ivas->hDecoderConfig->nchan_out; chOutIdx++) + { + FOR(Word16 chInIdx = 0; chInIdx < st_ivas->nchan_transport; chInIdx++) + { + st_ivas->hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx] = float_to_fix(st_ivas->hLsSetUpConversion->dmxMtx[chInIdx][chOutIdx], 30); /*Q30*/ + } + } +#endif //Float to fix + + push_wmops( "ivas_mct_dec" ); + + error = IVAS_ERR_OK; + nCPE = st_ivas->nCPE; + move16(); + hMCT = st_ivas->hMCT; + + ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); + + IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) + { + /* save LFE channel */ + mvl2l( output_fx[LFE_CHANNEL], output_lfe_ch_fx, output_frame ); + } + + IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && EQ_16(st_ivas->mc_mode, MC_MODE_MCT) && EQ_16(st_ivas->bfi, 0) ) + { + /* get the number of channels from the signalled MC LS setup */ + n = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); + + IF ( NE_16(n, st_ivas->nchan_transport) ) + { + /* IVAS_fmToDo: more work needed for switching the number of transport channels */ + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: wrong number of transport channels signalled in MC format!" ); + } + } + + FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + /*initialize param_lpc buffer*/ + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + set_s( param_lpc[cpe_id][n], 0, NPRM_LPC_NEW ); + } + + set32_fx( &output_fx[0][0], 0, L_FRAME48k ); + set32_fx( &output_fx[1][0], 0, L_FRAME48k ); + + IF( ( error = ivas_cpe_dec_fx( st_ivas, cpe_id, &output_fx[0], output_frame, 0, &q_output ) ) != IVAS_ERR_OK ) + { + return error; + } + + IF ( EQ_16(cpe_id, 0) ) + { + st_ivas->hCPE[0]->hCoreCoder[0]->total_brate = ivas_total_brate; /* set high enough to read the whole side-info; total_brate is rewritten later in ivas_mdct_core_invQ() */ + move32(); + } + + IF ( EQ_16(st_ivas->bfi, 0) ) + { + ivas_mdct_dec_side_bits_frame_channel_fx( st_ivas->hCPE[cpe_id], param_lpc[cpe_id], p_param[cpe_id], st_ivas->hCPE[0]->hCoreCoder[0], nTnsBitsTCX10[cpe_id], param[cpe_id], 1, + (Word16) GT_16( i_mult(add( cpe_id, 1 ), CPE_CHANNELS ), hMCT->nchan_out_woLFE ) ); + + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); + test(); + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); + test(); + } + } + + /* MCT side bits decoder */ + ivas_mct_side_bits_fx( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); + + FOR ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect, st_ivas->BER_detect); + test(); + st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect = s_or(st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect, st_ivas->BER_detect); + test(); + + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + shr( L_FRAME48k, 1 ); + + set32_fx( x_fx[n][0], 0, shr(L_FRAME48k, 1) ); + set32_fx( x_fx[n][1], 0, shr(L_FRAME48k, 1) ); + } + + ivas_mdct_core_invQ_fx( st_ivas->hCPE[cpe_id], nTnsBitsTCX10[cpe_id], p_param[cpe_id], param_lpc[cpe_id], param[cpe_id], + fUseTns[cpe_id], tnsData[cpe_id], x_fx, x_e, x_fx, x_e, x_len, Aq_fx[cpe_id], NULL, 1 ); + + FOR(ch = 0; ch < CPE_CHANNELS; ch++) + { + Word16 subFrames = (st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_10_CORE) ? NB_DIV : 1; + FOR(k = 0; k < subFrames; ++k) + { + Scale_sig32(x_fx[ch][k], shr(L_FRAME48k, subFrames - 1), sub(x_e[ch][k], 20)); + } + } + + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect); + test(); + st_ivas->BER_detect = s_or(st_ivas->BER_detect, st_ivas->hCPE[cpe_id]->hCoreCoder[1]->BER_detect); + test(); + } + + + /* MCT core decoder */ + Word16 q_x[MAX_TRANSPORT_CHANNELS]; + set16_fx(q_x, Q12, MAX_TRANSPORT_CHANNELS); + // Scaling output buffer to q_x + FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) + { + Scale_sig32(output_fx[i], L_FRAME48k, sub(q_x[i], Q11) ); + } + ivas_mct_core_dec(hMCT, st_ivas->hCPE, nCPE, output_fx, q_x); + // Scaling output buffer back to Q11 + FOR ( i = 0; i < hMCT->nchan_out_woLFE; ++i) + { + Scale_sig32(output_fx[i], L_FRAME48k, sub(Q11, q_x[i]) ); + } + + + /* for sba to stereo output disable any further processing for TCs > 2 as it is not needed*/ + IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) + { + FOR ( cpe_id = 1; cpe_id < nCPE; cpe_id++ ) + { + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_IGNORE; + } + } + } + + Word32 Aq_fx_32[6][2][102]; + /* MCT reconstruction and CoreCoder updates */ + FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + hCPE = st_ivas->hCPE[cpe_id]; + + FOR(n = 0; n < CPE_CHANNELS; n++) + { + Copy_Scale_sig_16_32(Aq_fx[cpe_id][n], Aq_fx_32[cpe_id][n], 102, sub(Q16, Q12)); + x_fx[n][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_fx[n][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + x_e[n][0] = 20; + move16(); + x_e[n][1] = 20; + move16(); + } + + ivas_mdct_core_tns_ns_fx(hCPE, fUseTns[cpe_id], tnsData[cpe_id], x_fx, Aq_fx_32[cpe_id], 1, x_e); + + FOR(Word16 ind = 0; ind < 2; ind++) + { + Word16 nSubFrames = EQ_16(hCPE->hCoreCoder[ind]->core, TCX_20_CORE) ? 1 : NB_DIV; + Scale_sig32(x_fx[ind][0], shr(L_FRAME48k, sub(nSubFrames, 1)), sub(x_e[ind][0], 20)); + IF(nSubFrames == 2) { + Scale_sig32(x_fx[ind][1], shr(L_FRAME48k, 1), sub(x_e[ind][1], 20)); + } + } + } + + + IF ( EQ_16(st_ivas->renderer_type, RENDERER_MC) ) + { + /* Equalization in MDCT Domain */ + ivas_ls_setup_conversion_process_mdct_fx( st_ivas, output_fx); + } + ELSE IF(EQ_16(st_ivas->renderer_type, RENDERER_MC_PARAMMC) && (EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO) || EQ_16(st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO))) + { + Word16 x_all_e[MAX_CICP_CHANNELS][NB_DIV] = { 0 }; + Word32 *x_all_fx[MAX_CICP_CHANNELS][NB_DIV]; + FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + FOR(n = 0; n < CPE_CHANNELS; n++) + { + x_all_fx[n + cpe_id * CPE_CHANNELS][0] = output_fx[n + cpe_id * CPE_CHANNELS]; + x_all_fx[n + cpe_id * CPE_CHANNELS][1] = output_fx[n + cpe_id * CPE_CHANNELS] + (L_FRAME48k / 2); + x_all_e[n + cpe_id * CPE_CHANNELS][1] = 20; + move16(); + x_all_e[n + cpe_id * CPE_CHANNELS][0] = 20; + move16(); + } + } + + ivas_ls_setup_conversion_process_mdct_param_mc_fx(st_ivas, x_all_fx, x_all_e); + + FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + FOR(n = 0; n < CPE_CHANNELS; n++) + { + Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][0], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][0], 20)); + Scale_sig32(x_all_fx[n + cpe_id * CPE_CHANNELS][1], shr(L_FRAME48k, 1), sub(x_all_e[n + cpe_id * CPE_CHANNELS][1], 20)); + } + } + + } + + +#if 1 /*Fixed to float conversions*/ + + FOR(cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + FOR( ch = 0; ch < CPE_CHANNELS; ch++) + { + st = hCPE->hCoreCoder[ch]; + IF( sts[ch]->mct_chan_mode == MCT_CHAN_MODE_IGNORE ) + { + sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); + sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); + sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); + } + IF( sts[ch]->mct_chan_mode != MCT_CHAN_MODE_IGNORE ) + { + sts[ch]->lp_gainp = fix_to_float( sts[ch]->Mode2_lp_gainp, Q16 ); + sts[ch]->hTonalMDCTConc->lastPitchLag_float = fix_to_float( sts[ch]->hTonalMDCTConc->lastPitchLag, Q16 ); + sts[ch]->hTonalMDCTConc->nFramesLost_float = fix16_to_float( sts[ch]->hTonalMDCTConc->nFramesLost, Q1 ); + sts[ch]->hTcxDec->damping_float = fix16_to_float( sts[ch]->hTcxDec->damping, Q14 ); + sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); + sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); + sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); + sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); + sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); + sts[ch]->stab_fac = fix16_to_float( sts[ch]->stab_fac_fx, Q15 ); + // 16bit to u8bit + FOR( l = 0; l < IGF_START_MX; l++ ) + { + sts[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t) sts[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + FOR( l = 0; l < N_LTP_GAIN_MEMS; l++ ) + { + sts[ch]->hTcxDec->ltpGainMemory[l] = fix16_to_float( sts[ch]->hTcxDec->ltpGainMemory_fx[l], Q15 ); + } + + IF( !sts[0]->bfi || ( sts[0]->bfi && sts[ch]->core != ACELP_CORE ) ) + { + me2f_buf( sts[ch]->hIGFDec->virtualSpec, sts[ch]->hIGFDec->virtualSpec_e, sts[ch]->hIGFDec->virtualSpec_float, ( N_MAX_TCX - IGF_START_MN ) ); + } + sts[ch]->hTcxDec->cummulative_damping_tcx_float = fix16_to_float( sts[ch]->hTcxDec->cummulative_damping_tcx, Q15 ); + } + IF( sts[ch]->rate_switching_reset ) + { + Word16 old_Aq_12_8_e = norm_s( sts[ch]->old_Aq_12_8_fx[0] ); + fixedToFloat_arr( sts[ch]->old_Aq_12_8_fx, sts[ch]->old_Aq_12_8, ( 15 - old_Aq_12_8_e ), M + 1 ); + } + IF(st->hTonalMDCTConc != NULL) + { + st->hTonalMDCTConc->scf_fadeout_flt = fixedToFloat(st->hTonalMDCTConc->scf_fadeout, 15); + st->hTonalMDCTConc->last_block_nrg_flt = me2f(st->hTonalMDCTConc->last_block_nrg, st->hTonalMDCTConc->last_block_nrg_exp); + st->hTonalMDCTConc->lastPitchLag_float = fixedToFloat(st->hTonalMDCTConc->lastPitchLag, Q16); + if (hCPE->hCoreCoder[ch]->bfi && st->tonal_mdct_plc_active) + { + st->hTonalMDCTConc->nFramesLost_float = fix16_to_float(st->hTonalMDCTConc->nFramesLost, Q1); + } + } + } + } + + IF (st_ivas->hCPE[0]->hCoreCoder[0]->igf) + { + IF (!hMCT->currBlockDataCnt) + { + FOR (cpe_id = 0; cpe_id < nCPE; cpe_id++) + { + FOR ( ch = 0; ch < CPE_CHANNELS; ch++) + { + IF(st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->igf) + { + me2f_buf(st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_e, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->virtualSpec_float, (N_MAX_TCX - IGF_START_MN)); + FOR( l = 0; l < IGF_START_MX; l++) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise[l] = (uint8_t)st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hIGFDec->infoTCXNoise_evs[l]; + } + } + } + } + } + } + + IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->targetEnergyPrev) me2f_buf(st_ivas->hLsSetUpConversion->targetEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->te_prev_exp, st_ivas->hLsSetUpConversion->targetEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt); + IF(st_ivas->hLsSetUpConversion && st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx) me2f_buf(st_ivas->hLsSetUpConversion->dmxEnergyPrev_fx[0], st_ivas->hLsSetUpConversion->dmx_prev_exp, st_ivas->hLsSetUpConversion->dmxEnergyPrev[0], st_ivas->hLsSetUpConversion->sfbCnt); +#endif /*Fixed to float conversions*/ + +#if 1 + + FOR( i = 0; i < 12; i++) if(output[i]) { + fixedToFloat_arrL(output_fx[i], output[i], Q11, L_FRAME48k); + } +#endif + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) + { + hCPE = st_ivas->hCPE[cpe_id]; + sts = hCPE->hCoreCoder; + + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + x[n][0] = output[n + cpe_id * CPE_CHANNELS]; + x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); + } + + ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); + + /*----------------------------------------------------------------* + * CoreCoder Post-processing and updates + *----------------------------------------------------------------*/ + Word32 synth_fx[CPE_CHANNELS][L_FRAME48k]; + Word16 Q_synth = 0; + Word16 q = 11; +#ifndef IVAS_CODE_TO_BE_REMOVED + FOR( n = 0; n < 2; n++) + { + floatToFixed_arrL(synth[n], synth_fx[n], Q11, L_FRAME48k); + IF(hCPE->hCoreCoder[n]->hTcxLtpDec) { + floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q, L_FRAME48k); + floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q, TCXLTP_MAX_DELAY); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); + floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111); + } + floatToFixed_arrL(hCPE->hCoreCoder[n]->delay_buf_out, hCPE->hCoreCoder[n]->delay_buf_out32_fx, Q11, HQ_DELTA_MAX * HQ_DELAY_COMP); + + + + /*cldfb struct*/ + + /*------------------fix-to-fix-start---------------------*/ + /*core_switching_post_dec*/ + if (sts[n]->hHQ_core != NULL) + { + sts[n]->hHQ_core->Q_old_postdec = 0; + sts[n]->hHQ_core->Q_old_wtda = 0; + } + + /*------------------fix-to-fix-end-----------------------*/ + + + IF(hCPE->output_mem[0] != NULL) + { + floatToFixed_arrL(hCPE->output_mem[0], hCPE->output_mem_fx[0], Q11, NS2SA(sts[n]->output_Fs, 3125000)); + } + IF(hCPE->output_mem[1] != NULL) + { + floatToFixed_arrL(hCPE->output_mem[1], hCPE->output_mem_fx[1], Q11, NS2SA(sts[n]->output_Fs, 3125000)); + } + + floatToFixed_arrL(output[cpe_id * CPE_CHANNELS + n], output_fx[cpe_id * CPE_CHANNELS + n], 4, L_FRAME48k); + + Word16 tmp = extract_l(L_shr(sts[n]->output_Fs, 13)); + Word16 Fs_kHz = shl(add(tmp, 1), 3); + + Word16 delta = 1; + move16(); + IF(GE_16(output_frame, L_FRAME16k)) + { + delta = shr(Fs_kHz, 3); + } + + if (sts[n]->hBWE_FD != NULL) + { + sts[n]->hBWE_FD->mem_deemph_old_syn_fx = (Word16)floatToFixed(sts[n]->hBWE_FD->mem_deemph_old_syn, 0); + } + IF(sts[n]->hHQ_core != NULL) + { + floatToFixed_arr(sts[n]->hHQ_core->old_out, sts[n]->hHQ_core->old_out_fx, 0, L_FRAME48k); + floatToFixed_arr(sts[n]->hHQ_core->fer_samples, sts[n]->hHQ_core->fer_samples_fx, 0, NS2SA(sts[n]->output_Fs, 3000000)); + FOR(i = 0; i < SFM_N_WB; ++i) + { + sts[n]->hHQ_core->prev_env_fx[i] = floatToFixed(sts[n]->hHQ_core->prev_env[i], sts[n]->hHQ_core->prev_env_Q[i]); + } + floatToFixed_arrL(sts[n]->hHQ_core->prev_normq, sts[n]->hHQ_core->prev_normq_fx, 14, SFM_N_WB); + } + floatToFixed_arr(sts[n]->previoussynth, sts[n]->previoussynth_fx, 0, L_FRAME48k); + floatToFixed_arr(sts[n]->delay_buf_out, sts[n]->delay_buf_out_fx, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); + + if (sts[n]->hTcxDec != NULL) + { + sts[n]->hTcxDec->conceal_eof_gain = (Word16)floatToFixed(sts[n]->hTcxDec->conceal_eof_gain_float, 14); + } + + /*size of synth is choosen as delay comp to start with*/ + // synth //Q0 -> Qsynth + // output_fx //Q ? + // delay_buf_buf //Q0 -> Q_old_postdec + // fer_samples //Q0 -> Q? + /*-------------------cldfb-start-------------------------*/ + + floatToFixed_arrL(sts[n]->bpf_noise_buf_float, sts[n]->bpf_noise_buf_32, 11, L_FRAME_16k); + if (sts[n]->cldfbAna != NULL) + { + floatToFixed_arrL(sts[n]->cldfbAna->cldfb_state, sts[n]->cldfbAna->cldfb_state_fx, 10, sts[n]->cldfbAna->cldfb_size); + } + if (sts[n]->cldfbSyn != NULL) + { + floatToFixed_arrL(sts[n]->cldfbSyn->cldfb_state, sts[n]->cldfbSyn->cldfb_state_fx, 4, sts[n]->cldfbSyn->p_filter_length); + } + if (sts[n]->cldfbBPF != NULL) + { + floatToFixed_arrL(sts[n]->cldfbBPF->cldfb_state, sts[n]->cldfbBPF->cldfb_state_fx, 11, sts[n]->cldfbBPF->cldfb_size); + } + + /*-------------------cldfb-end---------------------------*/ + + sts[n]->stab_fac_fx = float_to_fix16(sts[n]->stab_fac, Q15); + floatToFixed_arr(sts[n]->old_exc, sts[n]->old_exc_fx, sts[n]->Q_exc, L_EXC_MEM_DEC); + IF(sts[n]->hWIDec != NULL) + { + floatToFixed_arr(sts[n]->hWIDec->old_exc2, sts[n]->hWIDec->old_exc2_fx, sts[n]->Q_exc, L_EXC_MEM); + } + if (sts[n]->hBWE_TD != NULL) + { + floatToFixed_arr(sts[n]->hBWE_TD->old_bwe_exc, sts[n]->hBWE_TD->old_bwe_exc_fx, sts[n]->Q_exc, PIT16k_MAX * 2); + } + if (sts[n]->hMusicPF != NULL) + { + floatToFixed_arr(sts[n]->hMusicPF->dct_post_old_exc, sts[n]->hMusicPF->dct_post_old_exc_fx, sts[n]->Q_exc, DCT_L_POST - OFFSET2); + } + if (sts[n]->hBPF) { + floatToFixed_arr(sts[n]->hBPF->pst_old_syn, sts[n]->hBPF->pst_old_syn_fx, sts[n]->Q_syn2 - 1, NBPSF_PIT_MAX); + sts[n]->hBPF->pst_mem_deemp_err_fx = (Word16)floatToFixed(sts[n]->hBPF->pst_mem_deemp_err, sts[n]->Q_syn2 - 1); + floatToFixed_arr(sts[n]->hBPF->mem_mean_pit, sts[n]->hBPF->mem_mean_pit_fx, Q4, L_TRACK_HIST); + sts[n]->hBPF->pst_lp_ener_fx = float_to_fix16(sts[n]->hBPF->pst_lp_ener, Q8); + sts[n]->hBPF->psf_att_fx = float_to_fix16(sts[n]->hBPF->psf_att, Q15); + } + + floatToFixed_arr(sts[n]->prev_synth_buffer, sts[n]->prev_synth_buffer_fx, 0, NS2SA(48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS)); + floatToFixed_arr(sts[n]->hTcxDec->synth_history, sts[n]->hTcxDec->synth_history_fx, 0, 2 * output_frame - NS2SA(sts[n]->output_Fs, DELAY_CLDFB_NS) + NS2SA(sts[n]->output_Fs, PH_ECU_MEM_NS)); + } + + + Word16 output_q = OUTPUT_Q; + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] * ( 1u << output_q ) ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); + } + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); + } + } + + IF( hCPE->output_mem[n] != NULL ) + { + FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem_fx[n][k] = (Word32) ( hCPE->output_mem[n][k] * ( 1 << output_q ) ); + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB_fx[n][ind] = (Word32) ( hCPE->input_mem_LB[n][ind] * ( 1 << output_q ) ); + } + } + + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + { + hCPE->prev_hb_synth_fx[n][k] = (Word32) ( hCPE->prev_hb_synth[n][k] * ( 1 << output_q ) ); + } + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); + } + } +#endif + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + + IF ( NE_16(st_ivas->sba_dirac_stereo_flag, 0) && ( NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) || GE_16(cpe_id, sub(nCPE, 2)) ) ) + { + + Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, hCPE->hCoreCoder[n]->hHQ_core->oldOut_fx, output_frame, Q11); + ivas_post_proc_fx( NULL, hCPE, n, synth_fx[n], NULL, output_frame, 1 ); + + } + + /* Postprocessing for ACELP/MDCT core switching and synchronization */ + Word16 synth_fx16[L_FRAME48k]; + Word16 output_mem_fx[L_FRAME48k]; + IF( hCPE->output_mem[1] != NULL ) + { + Copy_Scale_sig_32_16( hCPE->output_mem_fx[1], output_mem_fx, NS2SA( sts[n]->output_Fs, 3125000 ), sub(0, Q11) ); + } + ELSE + { + set16_fx( output_mem_fx, 0, NS2SA( sts[n]->output_Fs, 3125000 ) ); + } + + Copy_Scale_sig_32_16(synth_fx[n], synth_fx16, L_FRAME48k, sub(Q_synth, Q11)); + + IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx16, output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) + { + return error; + } + + Copy_Scale_sig_16_32(synth_fx16, output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); + + /* Save synthesis for HQ FEC */ + Word32 output_fx_[L_FRAME48k]; + mvl2l(output_fx[cpe_id * CPE_CHANNELS + n], output_fx_, L_FRAME48k); + Scale_sig32(output_fx_, L_FRAME48k, sub(Q16, Q11)); + save_synthesis_hq_fec_fx( sts[n], output_fx_, output_frame, hCPE ); + + /* CoreCoder common updates */ + ivas_updt_dec_common_fx( hCPE->hCoreCoder[n], NORMAL_HQ_CORE, -1, output_fx[cpe_id * CPE_CHANNELS + n], 11 ); + + } /* n_channels loop */ + + FOR(n = 0; n < 2; n++) { + IF(hCPE->hCoreCoder[n]) + { + Copy_Scale_sig_16_32(hCPE->hCoreCoder[n]->delay_buf_out_fx, hCPE->hCoreCoder[n]->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11); + } + } + + /* synthesis synchronization between stereo modes */ + IF ( EQ_16(st_ivas->sba_dirac_stereo_flag, 0) || ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) && LE_16(cpe_id, sub(nCPE, 2)) ) ) + { + synchro_synthesis_fixed_clean( ivas_total_brate, hCPE, output_fx + cpe_id * CPE_CHANNELS, output_frame, 0 ); + } + +#ifndef IVAS_CODE_TO_BE_REMOVED + FOR(n = 0; n < 2; n++) + { + fixedToFloat_arrL(output_fx[cpe_id * CPE_CHANNELS + n], output[cpe_id * CPE_CHANNELS + n], Q11, L_FRAME48k); + } + FOR( n = 0; n < 2; n++) + { + fixedToFloat_arrL(output_fx[cpe_id * CPE_CHANNELS + n], output[cpe_id * CPE_CHANNELS + n], Q11, L_FRAME48k); + fixedToFloat_arr(sts[n]->old_exc_fx, sts[n]->old_exc, sts[n]->Q_exc, L_EXC_MEM_DEC); + if (sts[n]->hMusicPF != NULL) + { + fixedToFloat_arr(sts[n]->hMusicPF->dct_post_old_exc_fx, sts[n]->hMusicPF->dct_post_old_exc, sts[n]->Q_exc, DCT_L_POST - OFFSET2); + } + if (sts[n]->hBPF) { + fixedToFloat_arr(sts[n]->hBPF->pst_old_syn_fx, sts[n]->hBPF->pst_old_syn, sts[n]->Q_syn2 - 1, NBPSF_PIT_MAX); + sts[n]->hBPF->pst_mem_deemp_err = fixedToFloat(sts[n]->hBPF->pst_mem_deemp_err_fx, sts[n]->Q_syn2 - 1); + fixedToFloat_arr(sts[n]->hBPF->mem_mean_pit_fx, sts[n]->hBPF->mem_mean_pit, Q4, L_TRACK_HIST); + sts[n]->hBPF->pst_lp_ener = fixedToFloat(sts[n]->hBPF->pst_lp_ener_fx, Q8); + sts[n]->hBPF->psf_att = fixedToFloat(sts[n]->hBPF->psf_att_fx, Q15); + } + + /*-------------------cldfb-start-------------------------*/ + + /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ + + if (sts[n]->cldfbAna != NULL) + { + fixedToFloat_arrL(sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_state, 10, sts[n]->cldfbAna->cldfb_state_length); + } + if (sts[n]->cldfbSyn != NULL) + { + fixedToFloat_arrL(sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_state, 4, sts[n]->cldfbSyn->p_filter_length); + } + if (sts[n]->cldfbBPF != NULL) + { + fixedToFloat_arrL(sts[n]->cldfbBPF->cldfb_state_fx, sts[n]->cldfbBPF->cldfb_state, 11, sts[n]->cldfbBPF->cldfb_state_length); + } + + /*-------------------cldfb-end---------------------------*/ + + //fixedToFloat_arr(sts[n]->delay_buf_out_fx, sts[n]->delay_buf_out, 0, HQ_DELTA_MAX * HQ_DELAY_COMP); + IF(sts[n]->hHQ_core != NULL) + { + fixedToFloat_arr(sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k); + fixedToFloat_arr(sts[n]->hHQ_core->fer_samples_fx, sts[n]->hHQ_core->fer_samples, 0, NS2SA(sts[n]->output_Fs, 3000000)); + FOR(i = 0; i < SFM_N_WB; ++i) + { + sts[n]->hHQ_core->prev_env[i] = fixedToFloat(sts[n]->hHQ_core->prev_env_fx[i], sts[n]->hHQ_core->prev_env_Q[i]); + } + fixedToFloat_arrL(sts[n]->hHQ_core->prev_normq_fx, sts[n]->hHQ_core->prev_normq, 14, SFM_N_WB); + } + fixedToFloat_arr(sts[n]->previoussynth_fx, sts[n]->previoussynth, 0, L_FRAME48k); + + + + /*------------------reset-code-start---------------------*/ + + /*reset function flags*/ + Word8 reset_wb_tbe_extras = 0; + Word8 reset_wb_tbe_synth = 0; + Word8 reset_swb_tbe = 0; + Word8 reset_swb_tbe_synth = 0; + Word8 reset_fb_tbe_synth = 0; + + if (sts[n]->hBWE_FD != NULL) + { + sts[n]->hBWE_FD->mem_deemph_old_syn = fixedToFloat(sts[n]->hBWE_FD->mem_deemph_old_syn_fx, 0); + } + + IF(sts[n]->bws_cnt == 0 || (sts[n]->bws_cnt > 0 && NE_16(sts[n]->coder_type, INACTIVE) && NE_16(sts[n]->coder_type, AUDIO))) + { + sts[n]->attenu1 = fixedToFloat(sts[n]->attenu_fx, 15); + } + IF((NE_16(sts[n]->last_extl, SWB_BWE) && EQ_16(sts[n]->extl, SWB_BWE)) || (NE_16(sts[n]->last_extl, FB_BWE) && EQ_16(sts[n]->extl, FB_BWE)) || + ((EQ_16(sts[n]->last_core, HQ_CORE) || EQ_16(sts[n]->last_extl, SWB_TBE)) && sts[n]->extl < 0 && NE_16(sts[n]->core, HQ_CORE)) || (EQ_16(sts[n]->last_core, ACELP_CORE) && EQ_16(sts[n]->core, ACELP_CORE) && ((NE_16(sts[n]->prev_coder_type, INACTIVE) && EQ_16(sts[n]->coder_type, INACTIVE)) || (NE_16(sts[n]->prev_coder_type, AUDIO) && EQ_16(sts[n]->coder_type, AUDIO))) && sts[n]->bws_cnt > 0)) + { + fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); + + + sts[n]->hBWE_FD->prev_Energy = fixedToFloat(sts[n]->hBWE_FD->prev_Energy_fx, 0); // setting to zero + sts[n]->hBWE_FD->prev_frica_flag = sts[n]->hBWE_FD->prev_frica_flag; // fixed + sts[n]->hBWE_FD->prev_td_energy = sts[n]->hBWE_FD->prev_td_energy_fx; // setting to zero + sts[n]->hBWE_FD->prev_weight = fixedToFloat(sts[n]->hBWE_FD->prev_weight_fx, 15); // 6554; /*0.2 in Q15*/ + sts[n]->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(sts[n]->prev_fb_ener_adjust_fx, 0); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero + } + + /* reset WB BWE buffers */ + + IF(NE_16(sts[n]->last_extl, WB_BWE) && EQ_16(sts[n]->extl, WB_BWE) && sts[n]->hBWE_FD != NULL) + { + // set16_fx( sts[n]->hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); + fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); + + IF(NE_16(sts[n]->last_extl, SWB_BWE) && NE_16(sts[n]->last_extl, FB_BWE)) + { + sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; + } + sts[n]->hBWE_FD->prev_Energy_wb = (float)sts[n]->hBWE_FD->prev_Energy_wb_fx; + sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; + sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; + fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero + } + + /* reset TBE buffers */ + if (sts[n]->hBWE_TD != NULL) + { + IF(((EQ_16(sts[n]->extl, SWB_TBE) || EQ_16(sts[n]->extl, FB_TBE) || EQ_16(sts[n]->extl, SWB_CNG)) && + (NE_16(sts[n]->L_frame, sts[n]->last_L_frame) || (NE_16(sts[n]->last_extl, SWB_TBE) && NE_16(sts[n]->last_extl, FB_TBE)) || EQ_16(sts[n]->last_core, HQ_CORE))) || + (LT_16(sts[n]->bwidth, sts[n]->last_bwidth) && NE_16(sts[n]->last_extl, SWB_TBE)) || sts[n]->old_ppp_mode || ((EQ_16(sts[n]->prev_coder_type, AUDIO) || EQ_16(sts[n]->prev_coder_type, INACTIVE)) && sts[n]->bws_cnt > 0) || (sts[n]->bws_cnt == 0 && EQ_16(sts[n]->prev_bws_cnt, N_WS2N_FRAMES))) + { + + reset_swb_tbe = 1; + reset_swb_tbe_synth = 1; + + fixedToFloat_arr(sts[n]->GainShape_Delay, sts[n]->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2); + + IF(EQ_16(output_frame, L_FRAME16k)) + { + /* reset in case that SWB TBE layer is transmitted, but the output x`x`is 16kHz sampled */ + fixedToFloat_arr(sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); + } + fixedToFloat_arr(sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); + sts[n]->hBWE_TD->prev_pow_exc16kWhtnd = (float)sts[n]->hBWE_TD->prev_pow_exc16kWhtnd_fx / 32767; + sts[n]->hBWE_TD->prev_mix_factor = (float)sts[n]->hBWE_TD->prev_mix_factor_fx / 32767; + } + ELSE IF((EQ_16(sts[n]->extl, SWB_TBE) || EQ_16(sts[n]->extl, FB_TBE)) && + (NE_32(sts[n]->last_total_brate, sts[n]->total_brate) || NE_16(sts[n]->last_bwidth, sts[n]->bwidth) || + NE_16(sts[n]->last_codec_mode, MODE1) || NE_16(sts[n]->rf_flag, sts[n]->rf_flag_last))) + { + fixedToFloat_arr(sts[n]->hBWE_TD->state_lpc_syn_fx, sts[n]->hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->state_syn_shbexc_fx, sts[n]->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->mem_stp_swb_fx, sts[n]->hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->mem_zero_swb_fx, sts[n]->hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER); // setting to zero + sts[n]->hBWE_TD->gain_prec_swb = fixedToFloat(sts[n]->hBWE_TD->gain_prec_swb_fx, 14); /* Q14 = 1 */ + } + ELSE IF(sts[n]->hBWE_TD != NULL && (sts[n]->last_core == TCX_20_CORE || sts[n]->last_core == TCX_10_CORE)) + { + /*------------TBEreset_dec_ivas_fx-start------------------*/ + IF(NE_16(sts[n]->last_core, ACELP_CORE)) + { + fixedToFloat_arr(sts[n]->hBWE_TD->old_bwe_exc_fx, sts[n]->hBWE_TD->old_bwe_exc, 0, PIT16k_MAX * 2); // setting to zero + sts[n]->hBWE_TD->bwe_non_lin_prev_scale = fixedToFloat(sts[n]->hBWE_TD->bwe_non_lin_prev_scale_fx, 0); // setting to zero + } + IF(EQ_16(sts[n]->bwidth, WB)) + { + reset_wb_tbe_extras = 1; + reset_wb_tbe_synth = 1; + + fixedToFloat_arr(sts[n]->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, sts[n]->hBWE_TD->mem_genSHBexc_filt_down_shb, 0, 7); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->state_lpc_syn_fx, sts[n]->hBWE_TD->state_lpc_syn, 0, 10); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->state_syn_shbexc_fx, sts[n]->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4); + fixedToFloat_arr(sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); + fixedToFloat_arrL(sts[n]->hBWE_TD->mem_csfilt_fx, sts[n]->hBWE_TD->mem_csfilt, 0, 2); + } + ELSE IF(EQ_16(sts[n]->bwidth, SWB) || EQ_16(sts[n]->bwidth, FB)) + { + reset_swb_tbe = 1; + reset_swb_tbe_synth = 1; + fixedToFloat_arr(sts[n]->GainShape_Delay, sts[n]->hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->int_3_over_2_tbemem_dec_fx, sts[n]->hBWE_TD->int_3_over_2_tbemem_dec, 0, INTERP_3_2_MEM_LEN); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->mem_resamp_HB_32k_fx, sts[n]->hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero + sts[n]->hBWE_TD->prev_pow_exc16kWhtnd = (float)sts[n]->hBWE_TD->prev_pow_exc16kWhtnd_fx / 32767; /*Q15 1.f*/ + sts[n]->hBWE_TD->prev_mix_factor = (float)sts[n]->hBWE_TD->prev_mix_factor_fx / 32767; /*Q15 1.f */ + + IF(EQ_16(sts[n]->bwidth, FB)) + { + IF(sts[n]->hBWE_FD != NULL) + { + sts[n]->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(sts[n]->prev_fb_ener_adjust_fx, 0); + } + fixedToFloat_arr(sts[n]->hBWE_TD->fb_state_lpc_syn_fx, sts[n]->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + sts[n]->hBWE_TD->fb_tbe_demph = fixedToFloat(sts[n]->hBWE_TD->fb_tbe_demph_fx, 0); // setting to zero + reset_fb_tbe_synth = 1; + } + } + /*------------TBEreset_dec_ivas_fx-end--------------------*/ + } + + IF(EQ_16(sts[n]->extl, FB_TBE) && (NE_16(sts[n]->last_extl, FB_TBE) || NE_16(sts[n]->L_frame, sts[n]->last_L_frame))) + { + fixedToFloat_arr(sts[n]->hBWE_TD->fb_state_lpc_syn_fx, sts[n]->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); + sts[n]->hBWE_TD->fb_tbe_demph = fixedToFloat(sts[n]->hBWE_TD->fb_tbe_demph_fx, 0); // setting to zero + reset_fb_tbe_synth = 1; + } + + + IF(NE_16(sts[n]->last_extl, WB_TBE) && EQ_16(sts[n]->extl, WB_TBE)) + { + reset_wb_tbe_extras = 1; + reset_wb_tbe_synth = 1; + fixedToFloat_arr(sts[n]->hBWE_TD->state_syn_shbexc_fx, sts[n]->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero + fixedToFloat_arrL(sts[n]->hBWE_TD->mem_csfilt_fx, sts[n]->hBWE_TD->mem_csfilt, 0, 2); // setting to zero + } + + IF(reset_swb_tbe) + { + fixedToFloat_arrL(sts[n]->hBWE_TD->mem_csfilt_fx, sts[n]->hBWE_TD->mem_csfilt, 0, 2); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->mem_genSHBexc_filt_down_shb_fx, sts[n]->hBWE_TD->mem_genSHBexc_filt_down_shb, 0, (2 * ALLPASSSECTIONS_STEEP + 1)); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->state_lpc_syn_fx, sts[n]->hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->syn_overlap_fx, sts[n]->hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->state_syn_shbexc_fx, sts[n]->hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->mem_stp_swb_fx, sts[n]->hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER); // setting to zero + + sts[n]->hBWE_TD->tbe_demph = fixedToFloat(sts[n]->hBWE_TD->tbe_demph_fx, 0); // setting to zero + sts[n]->hBWE_TD->tbe_premph = fixedToFloat(sts[n]->hBWE_TD->tbe_premph_fx, 0); // setting to zero + sts[n]->hBWE_TD->gain_prec_swb = fixedToFloat(sts[n]->hBWE_TD->gain_prec_swb_fx, 14); // setting to zero + } + IF(reset_swb_tbe_synth) + { + fixedToFloat_arrL(sts[n]->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, sts[n]->hBWE_TD->genSHBsynth_Hilbert_Mem, 0, HILBERT_MEM_SIZE); // setting to zero // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, sts[n]->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero + } + IF(reset_wb_tbe_extras) + { + fixedToFloat_arr(sts[n]->hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, sts[n]->hBWE_TD->mem_genSHBexc_filt_down_wb2, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->mem_genSHBexc_filt_down_wb3_fx, sts[n]->hBWE_TD->mem_genSHBexc_filt_down_wb3, 0, 2 * ALLPASSSECTIONS_STEEP + 1); // setting to zero + } + IF(reset_wb_tbe_synth) + { + fixedToFloat_arr(sts[n]->hBWE_TD->state_lsyn_filt_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero + fixedToFloat_arr(sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb_fx, sts[n]->hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP); // setting to zero + // fixedToFloat(sts[n]->hBWE_TD->state_32and48k_WB_upsample_fx, sts[n]->hBWE_TD->state_32and48k_WB_upsample,0, 2 * ALLPASSSECTIONS_STEEP); buffer not there in float code* + fixedToFloat_arr(sts[n]->hBWE_TD->mem_resamp_HB_fx, sts[n]->hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN); // setting to zero + } + IF(reset_fb_tbe_synth) + { + fixedToFloat_arrL(sts[n]->hBWE_TD->fbbwe_hpf_mem_fx[0], sts[n]->hBWE_TD->fbbwe_hpf_mem[0], 0, 4); // setting to zero + fixedToFloat_arrL(sts[n]->hBWE_TD->fbbwe_hpf_mem_fx[1], sts[n]->hBWE_TD->fbbwe_hpf_mem[1], 0, 4); // setting to zero + fixedToFloat_arrL(sts[n]->hBWE_TD->fbbwe_hpf_mem_fx[2], sts[n]->hBWE_TD->fbbwe_hpf_mem[2], 0, 4); // setting to zero + fixedToFloat_arrL(sts[n]->hBWE_TD->fbbwe_hpf_mem_fx[3], sts[n]->hBWE_TD->fbbwe_hpf_mem[3], 0, 4); // setting to zero + sts[n]->hBWE_TD->prev_fbbwe_ratio = fixedToFloat(sts[n]->hBWE_TD->prev_fbbwe_ratio_fx, 0); // scaling unknown setting to 1 + } + } + /* Interp_3_2 CNG buffers reset */ + IF(sts[n]->hTdCngDec != NULL && EQ_32(sts[n]->output_Fs, 48000) && ((GT_32(sts[n]->last_core_brate, SID_2k40)) && (EQ_32(sts[n]->core_brate, FRAME_NO_DATA) || EQ_32(sts[n]->core_brate, SID_2k40)))) + { + fixedToFloat_arr(sts[n]->interpol_3_2_cng_dec_fx, sts[n]->hTdCngDec->interpol_3_2_cng_dec, 0, INTERP_3_2_MEM_LEN); + } + + /*------------------reset-code-end-----------------------*/ + + + for (int p = 0; p < L_FRAME48k; p++) + { + + IF(hCPE->hCoreCoder[n]->hTcxLtpDec) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float[p] = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32[p] / (1u << q); + if (p < TCXLTP_MAX_DELAY) + { + hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << q); + } + } + } + if (hCPE->hCoreCoder[n]->hTcxDec) + { + for (k = 0; k < 111; k++) + { + hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / (1u << q); + } + } + IF(hCPE->hCoreCoder[n]->hTcxLtpDec) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; + IF(hCPE->hCoreCoder[n]->hTcxLtpDec) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + + if ((sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL) && ((sts[n]->core == ACELP_CORE && !(sts[n]->bfi == 1 && sts[n]->con_tcx == 1)) || sts[n]->core == HQ_CORE)) + { + fixedToFloat_arr(sts[n]->hTcxDec->synth_history_fx, sts[n]->hTcxDec->synth_history, 0, output_frame); + } + + + fixedToFloat_arr(sts[n]->old_synth_sw_fx, sts[n]->old_synth_sw, -2, 429); + FOR(Word16 ind = 0; ind < 16; ind++) { + sts[n]->mem_AR[ind] = sts[n]->mem_AR_fx[ind] / 2.56f; + } + sts[n]->prev_tilt_code_dec = fixedToFloat(sts[n]->prev_tilt_code_dec_fx, Q15); + + floatToFixed_arr(sts[n]->tilt_code_dec, sts[n]->tilt_code_dec_fx, Q15, 5); + floatToFixed_arr(sts[n]->old_synth_sw, sts[n]->old_synth_sw_fx, -2, 429); + sts[n]->prev_tilt_code_dec_fx = (Word16)floatToFixed(sts[n]->prev_tilt_code_dec, Q15); + FOR(Word16 ind = 0; ind < 16; ind++) { + sts[n]->mem_AR_fx[ind] = (Word16)(sts[n]->mem_AR[ind] * 2.56f); + } + fixedToFloat_arr(sts[n]->old_synth_sw_fx, sts[n]->old_synth_sw, 0, 429); + } + + IF( hCPE->hStereoDft != NULL ) + { + IF( hCPE->hStereoDft->hTcxLtpDec != NULL ) + { + FOR( Word32 p = 0; p < L_FRAME48k; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << output_q ); + } + FOR( Word32 p = 0; p < TCXLTP_MAX_DELAY; p++ ) + { + hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); + } + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; + hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; + } + } + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + IF( hCPE->output_mem[n] != NULL ) + { + FOR( k = 0; k < NS2SA( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->output_mem[n][k] = (float) hCPE->output_mem_fx[n][k] / ( 1u << 11 ); + } + } + IF( hCPE->hCoreCoder[n] != NULL ) + { + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) + { + hCPE->hCoreCoder[n]->prev_synth_buffer[k] = (float) hCPE->hCoreCoder[n]->prev_synth_buffer32_fx[k] / ( 1 << output_q ); + } + FOR( k = 0; k < HQ_DELTA_MAX * HQ_DELAY_COMP; k++ ) + { + hCPE->hCoreCoder[n]->delay_buf_out[k] = (float) hCPE->hCoreCoder[n]->delay_buf_out32_fx[k] / ( 1 << output_q ); + } + } + IF( hCPE->input_mem[n] != NULL ) + { + FOR( Word32 ind = 0; ind < STEREO_DFT32MS_OVL_16k; ind++ ) + { + hCPE->input_mem_LB[n][ind] = ( (float) hCPE->input_mem_LB_fx[n][ind] / ( 1 << output_q ) ); + } + } + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ); k++ ) + { + hCPE->prev_hb_synth[n][k] = (float) hCPE->prev_hb_synth_fx[n][k] / ( 1 << output_q ); + } + FOR( k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ); k++ ) + { + hCPE->prev_synth[n][k] = (float) hCPE->prev_synth_fx[n][k] / ( 1 << output_q ); + } + } +#endif + } + + /* move channels after LFE to correct output for multi-channel MCT */ + FOR(Word16 ind = 0; ind < 12; ind++) if(output[ind]) { + floatToFixed_arrL(output[ind], output_fx[ind], Q11, 960); + } + IF ( EQ_16(st_ivas->ivas_format, MC_FORMAT) && ( EQ_16(st_ivas->mc_mode, MC_MODE_MCT) || EQ_16(st_ivas->mc_mode, MC_MODE_PARAMUPMIX) ) ) + { + Word32 tmp[L_FRAME48k]; + + /*save center channel output*/ + mvl2l( output_fx[hMCT->nchan_out_woLFE - 1], tmp, output_frame ); + + FOR ( n = hMCT->nchan_out_woLFE - 1; n >= LFE_CHANNEL; n-- ) + { + mvl2l( output_fx[n - 1], output_fx[n + 1], output_frame ); + } + mvl2l( tmp, output_fx[LFE_CHANNEL - 1], output_frame ); + + /* save LFE channel */ + mvl2l( output_lfe_ch_fx, output_fx[LFE_CHANNEL], output_frame ); + } + + FOR(i = 0; i < 12; i++) if(output[i]) { + fixedToFloat_arrL(output_fx[i], output[i], Q11, L_FRAME48k); + free(output_fx[i]); + } + pop_wmops(); + return error; +} +#endif /*------------------------------------------------------------------------- diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 427f11513..f83aa7108 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -513,6 +513,10 @@ void ivas_mdct_dec_side_bits_frame_channel_fx( { /* Initialization or re-configuration of Stereo TCX */ stereo_tcx_init_dec_fx( sts[ch], 1, hCPE->last_element_mode ); + +#if 1 // TODO: To be removed later + stereo_tcx_init_dec( sts[ch], 1, hCPE->last_element_mode ); +#endif } sts[ch]->enablePlcWaveadjust = 0; } @@ -704,7 +708,16 @@ void ivas_mdct_dec_side_bits_frame_channel( if ( MCT_flag ) { /* Initialization or re-configuration of Stereo TCX */ +#ifdef IVAS_FLOAT_FIXED + /* stereo_tcx_dec_mode_switch_reconf_To_fixed is for intermediatery conversions which is needed to be removed */ + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); + /*============*/ + stereo_tcx_init_dec_fx( sts[ch], 1, hCPE->last_element_mode ); + /*============*/ + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); +#else stereo_tcx_init_dec( sts[ch], 1, hCPE->last_element_mode ); +#endif // IVAS_FLOAT_FIXED } sts[ch]->enablePlcWaveadjust = 0; } @@ -1727,7 +1740,6 @@ void ivas_mdct_core_invQ( 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); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index f8dc39f52..38063766d 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -759,7 +759,149 @@ void ivas_sba_dec_digest_tc( if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) { +#if 0 + Word16 num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); +#if 1 + Word16 ch, i; + SPAR_DEC_HANDLE hSpar = st_ivas->hSpar; + Word16 num_bands_out, nchan_transport; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + Word16 j, b, i_ts, num_out_ch; + num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; + hSpar->hMdDec->Q_mixer_mat = 31; + Word16 num_in_ch; + num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, Q_factor_L(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_C_re_fx = s_min(Q_C_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + Q_P_re_fx = s_min(Q_P_re_fx, Q_factor_L(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS])); + } + } + } + } + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, s_min(Q_C_re_fx, Q_P_re_fx)); + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < nchan_transport; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = nchan_transport; j < num_out_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed(hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat); + } + } + } + } + + + IF(hSpar->hMdDec->td_decorr_flag && !(EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM))) + { + Word16 ch_sba_idx = 0; + IF(EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT)) + { + IF(EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC)) + { + ch_sba_idx = st_ivas->nchan_ism; move16(); + } + } + st_ivas->hTcBuffer->q_tc_fx = 14; + for (int i = 0; i < ivas_sba_get_nchan_metadata(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate) + ch_sba_idx; i++) + { + floatToFixed_arrL(st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->tc_fx[i], st_ivas->hTcBuffer->q_tc_fx, min(nSamplesForRendering, (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC))); + } + } +#endif + ivas_spar_dec_digest_tc_fx(st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering); + +#if 1 + FOR(i_ts = 0; i_ts < num_md_sub_frames; i_ts++) + { + FOR(i = 0; i < num_out_ch; i++) + { + FOR(j = 0; j < num_in_ch; j++) + { + FOR(b = 0; b < num_bands_out; b++) + { + st_ivas->hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat(st_ivas->hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], st_ivas->hSpar->hMdDec->Q_mixer_mat); + } + } + } + } + + IF(hSpar->hMdDec->td_decorr_flag && !(EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM))) + { + Word16 ch_sba_idx = 0; + IF(EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT)) + { + IF(EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC)) + { + ch_sba_idx = st_ivas->nchan_ism; move16(); + } + } + for (int i = 0; i < ivas_sba_get_nchan_metadata(st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate) + ch_sba_idx; i++) + { + fixedToFloat_arrL(st_ivas->hTcBuffer->tc_fx[i], st_ivas->hTcBuffer->tc[i], st_ivas->hTcBuffer->q_tc_fx, min(nSamplesForRendering, (int16_t)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC))); + } + } + +#endif +#else ivas_spar_dec_digest_tc( st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering ); +#endif } if ( st_ivas->hDiracDecBin != NULL && ( st_ivas->hDiracDecBin->useTdDecorr ) ) @@ -848,12 +990,116 @@ void ivas_sba_dec_digest_tc( ( ( st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) && ( nchan_transport == 1 && st_ivas->nchan_transport != 2 && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; +#if 0 +#if 1 + Word32 max_cngNoiseLevel = 0; + FOR(int i = 0; i < FFTCLDFBLEN; i++) + { + max_cngNoiseLevel = L_max(L_abs((Word32)st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[i]), max_cngNoiseLevel); + } + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = norm_l(max_cngNoiseLevel); + + floatToFixed_arr(st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, Q13, M + 1); + + floatToFixed_arrL(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt, st->hFdCngDec->hFdCngCom->cngNoiseLevel, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp, FFTCLDFBLEN); + + for (int i = 0; i < FFTLEN; i++) + { + st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx[i] = float_to_fix(st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt[i], 15); + } + +#endif + generate_masking_noise_lb_dirac_fx(st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc_fx[1], nCldfbSlots, st->cna_dirac_flag && st->flag_cna); + +#if 1 + fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->olapBufferSynth2_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth2_flt, 15, st->hFdCngDec->hFdCngCom->fftlen); + fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->fftBuffer, st->hFdCngDec->hFdCngCom->fftBuffer_flt, 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp, st->hFdCngDec->hFdCngCom->fftlen); + + fixedToFloat_arrL(st->hFdCngDec->hFdCngCom->exc_cng_32fx, st->hFdCngDec->hFdCngCom->exc_cng_flt, 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp - 9, st->hFdCngDec->hFdCngCom->frameSize); + fixedToFloat_arrL(st_ivas->hTcBuffer->tc_fx[1], st_ivas->hTcBuffer->tc[1], 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp - 9, st->hFdCngDec->hFdCngCom->frameSize); + +#endif +#else generate_masking_noise_lb_dirac( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc[1], nCldfbSlots, st->cna_dirac_flag && st->flag_cna ); +#endif } return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_sba_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nCldfbSlots, /* i : number of CLDFB slots */ + const Word16 nSamplesForRendering /* i : number of samples provided */ +) +{ + Word16 ch_idx, nchan_transport; + + /* set the md map */ + IF ( st_ivas->hDirAC ) + { + ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); + } + test(); + IF ( EQ_16(st_ivas->ivas_format, SBA_FORMAT) || EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT )) + { + ivas_spar_dec_digest_tc_fx(st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering); + } + test(); + IF ( st_ivas->hDiracDecBin != NULL && ( st_ivas->hDiracDecBin->useTdDecorr ) ) + { + Word16 nSamplesLeftForTD, default_frame; + Word32 *decorr_signal[BINAURAL_CHANNELS]; + Word32 *p_tc[2 * BINAURAL_CHANNELS]; + Word16 q_format = 14; + default_frame = (Word16)(st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + nSamplesLeftForTD = nSamplesForRendering; move16(); + + FOR ( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) + { + decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx + BINAURAL_CHANNELS]; move32(); + p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; move32(); + } + + WHILE ( nSamplesLeftForTD ) + { + Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); + + IF ( st_ivas->hDiracDecBin->hTdDecorr ) + { + ivas_td_decorr_process_fx( st_ivas->hDiracDecBin->hTdDecorr, p_tc, decorr_signal, nSamplesToDecorr, &q_format ); + } + + FOR ( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ ) + { + decorr_signal[ch_idx] += nSamplesToDecorr; + p_tc[ch_idx] += nSamplesToDecorr; + } + nSamplesLeftForTD = sub(nSamplesLeftForTD, nSamplesToDecorr); + } + } + + /* if we have a late CNG generation, do it here */ + nchan_transport = st_ivas->nchan_transport; move16(); + + test(); test(); test(); test(); test(); + IF ( EQ_16(st_ivas->ivas_format, MASA_FORMAT) && LT_32(st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE) && ( GT_32(st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2) || ( LE_32(st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2) && GT_16(st_ivas->nCPE, 0) && EQ_16(st_ivas->hCPE[0]->nchan_out, 1) ) ) ) + { + nchan_transport = 1; move16();/* Only one channel transported */ + } + + test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); test(); + IF ( ( ( NE_16(st_ivas->ivas_format, SBA_FORMAT) && NE_16(st_ivas->ivas_format, SBA_ISM_FORMAT) ) && EQ_16(st_ivas->nchan_transport, 1) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag ) || + ( (EQ_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) ) && (EQ_16(nchan_transport, 1) && NE_16(st_ivas->nchan_transport, 2) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) ) + { + Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; + generate_masking_noise_lb_dirac_fx( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc_fx[1], nCldfbSlots, st->cna_dirac_flag && st->flag_cna ); + } + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_sba_dec_render() diff --git a/lib_dec/ivas_sba_rendering_internal.c b/lib_dec/ivas_sba_rendering_internal.c index cc5a03f6b..196c3de1b 100644 --- a/lib_dec/ivas_sba_rendering_internal.c +++ b/lib_dec/ivas_sba_rendering_internal.c @@ -778,12 +778,13 @@ void ivas_sba_mix_matrix_determiner_fx( const Word16 bfi, /* i : BFI flag */ const Word16 nchan_remapped, /* i : num channels after remapping of TCs */ const Word16 output_frame, /* i : output frame length */ - const Word16 num_md_sub_frames, /* i : number of subframes in mixing matrix*/ - Word16 *Q_mixer_mat ) + const Word16 num_md_sub_frames /* i : number of subframes in mixing matrix*/ + ) { Word16 i, ch; Word16 num_bands_out, nchan_transport, nchan_out; Word16 Q_p_output = 14; + move16(); Word32 temp_fx; /* Convert numeric range */ FOR( ch = 0; ch < nchan_remapped; ch++ ) @@ -791,23 +792,29 @@ void ivas_sba_mix_matrix_determiner_fx( FOR( i = 0; i < output_frame; i++ ) { temp_fx = output_fx[ch][i]; + move32(); temp_fx = L_shr( temp_fx + L_shl( 1, Q_p_output - 1 ), Q_p_output ); IF( GT_32( temp_fx, MAX16B ) ) { temp_fx = MAX16B; + move32(); } ELSE IF( LT_32( temp_fx, ( -1 * PCM16_TO_FLT_FAC_FX ) ) ) { temp_fx = ( -1 * PCM16_TO_FLT_FAC_FX ); + move32(); } temp_fx = Mult_32_32( MAX_32 / PCM16_TO_FLT_FAC_FX, L_shl( temp_fx, Q_p_output ) ); output_fx[ch][i] = temp_fx; + move32(); } } /* AGC */ nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + move16(); nchan_out = nchan_transport; + move16(); ivas_agc_dec_process_fx( hSpar->hAgcDec, ( output_fx ), ( output_fx ), nchan_transport, output_frame ); #ifdef DUMPS_ENABLED dbgwrite_txt( &output[0][0], output_frame, "fix_ivas_agc_dec_process_output.txt", NULL ); @@ -823,8 +830,8 @@ void ivas_sba_mix_matrix_determiner_fx( } /* Mixing matrix determiner */ - num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; - ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames, Q_mixer_mat ); + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; move16(); + ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); return; } #endif // IVAS_FLOAT_FIXED @@ -917,7 +924,8 @@ void ivas_sba_mix_matrix_determiner( #if 1 /*Float to fixed changes */ Word16 j, b, i_ts, num_out_ch; num_out_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; - Word16 Q_C_re_fx = 31, Q_P_re_fx = 31, Q_mixer_mat = 31; + Word16 Q_C_re_fx = 31, Q_P_re_fx = 31; + hSpar->hMdDec->Q_mixer_mat = 31; Word16 num_in_ch; num_in_ch = hSpar->hMdDec->spar_md_cfg.num_umx_chs; FOR ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) @@ -928,7 +936,7 @@ void ivas_sba_mix_matrix_determiner( { FOR( b = 0; b < num_bands_out; b++ ) { - Q_mixer_mat = s_min( Q_mixer_mat, Q_factor_L( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] ) ); + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, Q_factor_L( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] ) ); } } } @@ -959,7 +967,7 @@ void ivas_sba_mix_matrix_determiner( } } } - Q_mixer_mat = s_min( Q_mixer_mat, s_min( Q_C_re_fx, Q_P_re_fx ) ); + hSpar->hMdDec->Q_mixer_mat = s_min(hSpar->hMdDec->Q_mixer_mat, s_min( Q_C_re_fx, Q_P_re_fx ) ); FOR ( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { FOR( i = 0; i < num_out_ch; i++ ) @@ -968,7 +976,7 @@ void ivas_sba_mix_matrix_determiner( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } @@ -978,7 +986,7 @@ void ivas_sba_mix_matrix_determiner( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->spar_coeffs.C_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.C_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } @@ -988,13 +996,13 @@ void ivas_sba_mix_matrix_determiner( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->spar_coeffs.P_re_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = floatToFixed( hSpar->hMdDec->spar_coeffs.P_re[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } } #endif - ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames ,&Q_mixer_mat); + ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames); #if 1 /*Fixed to float changes */ FOR( i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { @@ -1004,7 +1012,7 @@ void ivas_sba_mix_matrix_determiner( { FOR( b = 0; b < num_bands_out; b++ ) { - hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat( hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], Q_mixer_mat ); + hSpar->hMdDec->mixer_mat[i][j][b + i_ts * IVAS_MAX_NUM_BANDS] = fixedToFloat( hSpar->hMdDec->mixer_mat_fx[i][j][b + i_ts * IVAS_MAX_NUM_BANDS], hSpar->hMdDec->Q_mixer_mat ); } } } diff --git a/lib_dec/ivas_sce_dec_fx.c b/lib_dec/ivas_sce_dec_fx.c index e13507d91..f6b79f95a 100644 --- a/lib_dec/ivas_sce_dec_fx.c +++ b/lib_dec/ivas_sce_dec_fx.c @@ -411,8 +411,7 @@ ivas_error create_sce_dec( td_cng_dec_init_ivas_fx( st ); #if 1 // Fix to float conversions - st->hTdCngDec->Enew = fix_to_float(st->hTdCngDec->Enew_fx, 6); - fixedToFloat_arr(st->lspCNG_fx, st->lspCNG, 15, M); + //fixedToFloat_arr(st->lspCNG_fx, st->lspCNG, 15, M); st->hTdCngDec->shb_cng_ener = fix_to_float(st->hTdCngDec->shb_cng_ener_fx_32, 11); fixedToFloat_arr(st->hTdCngDec->shb_lpcCNG_fx, st->hTdCngDec->shb_lpcCNG, 15, LPC_SHB_ORDER + 1); st->hTdCngDec->shb_cng_gain = fix_to_float(st->hTdCngDec->shb_cng_gain_fx_32, 11); diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index f055671f0..2f26de0b4 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -2056,7 +2056,37 @@ void ivas_spar_dec_set_render_map( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_dec_set_render_map_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word16 nCldfbTs /* i : number of CLDFB time slots */ +) +{ + SPAR_DEC_HANDLE hSpar; + + hSpar = st_ivas->hSpar; + + /* adapt subframes */ + hSpar->num_slots = nCldfbTs; move16(); + hSpar->slots_rendered = 0; move16(); + hSpar->subframes_rendered = 0; move16(); + + set16_fx( hSpar->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); + ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpar->subframe_nbslots, &hSpar->nb_subframes ); + /* copy also to tc buffer */ + /* only for non-combined formats and combinded formats w/o discrete objects */ + IF ( !( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT) && EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC) ) ) + { + st_ivas->hTcBuffer->nb_subframes = hSpar->nb_subframes; move16(); + Copy( hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpar->nb_subframes ); + } + + ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, 1, 0, DEFAULT_JBM_CLDFB_TIMESLOTS, hSpar->render_to_md_map ); + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_spar_dec_upmixer() @@ -2082,7 +2112,26 @@ void ivas_spar_dec_set_render_params( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_dec_set_render_params_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 n_cldfb_slots /* i : number of cldfb slots in this frame */ +) +{ + SPAR_DEC_HANDLE hSpar; + Word16 nchan_transport; + Word16 num_bands_out; + + hSpar = st_ivas->hSpar; + nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport; + num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands; + ivas_spar_dec_gen_umx_mat_fx( hSpar->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate )); + ivas_spar_dec_set_render_map_fx( st_ivas, n_cldfb_slots ); + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_spar_dec_digest_tc() @@ -2201,7 +2250,91 @@ void ivas_spar_dec_digest_tc( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_spar_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + const Word16 nCldfbSlots, /* i : number of CLDFB slots */ + const Word16 nSamplesForRendering /* i : number of samples provided */ +) +{ + SPAR_DEC_HANDLE hSpar; + hSpar = st_ivas->hSpar; + test(); test(); + IF ( hSpar->hMdDec->td_decorr_flag && !( EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) ) ) + { + Word16 nchan_internal, ch; + Word16 ch_sba_idx; + Word16 nSamplesLeftForTD, default_frame; + Word32 *pPcm_tmp[MAX_SPAR_INTERNAL_CHANNELS]; + Word32 *p_tc[MAX_SPAR_INTERNAL_CHANNELS]; + Word32 Pcm_tmp[MAX_SPAR_INTERNAL_CHANNELS][L_FRAME48k]; + Word32 i, j; + Word16 q_format = Q14; + + ch_sba_idx = 0; move16(); + IF ( EQ_16(st_ivas->ivas_format, SBA_ISM_FORMAT )) + { + IF ( EQ_16(st_ivas->ism_mode, ISM_SBA_MODE_DISC )) + { + ch_sba_idx = st_ivas->nchan_ism; move16(); + } + } + + /* TD decorrelator */ + default_frame = (Word16) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); + nSamplesLeftForTD = nSamplesForRendering; + nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + + FOR ( ch = 0; ch < nchan_internal; ch++ ) + { + pPcm_tmp[ch] = Pcm_tmp[ch]; + p_tc[ch] = st_ivas->hTcBuffer->tc_fx[ch + ch_sba_idx]; move32(); + } + + WHILE ( nSamplesLeftForTD ) + { + Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); + + IF ( hSpar->hTdDecorr ) + { + + ivas_td_decorr_process_fx( hSpar->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr, &q_format ); + st_ivas->hTcBuffer->q_tc_fx = s_min(st_ivas->hTcBuffer->q_tc_fx, q_format); + IF ( GE_16(hSpar->hTdDecorr->num_apd_outputs, sub( nchan_internal, nchan_transport )) ) + { + FOR ( ch = 0; ch < sub(nchan_internal, nchan_transport); ch++ ) + { + Copy32( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr ); + } + } + ELSE + { + FOR ( ch = 0; ch < sub(nchan_internal, nchan_transport); ch++ ) + { + set32_fx( p_tc[nchan_internal - 1 - ch], 0, nSamplesToDecorr ); + } + FOR ( ch = 0; ch < hSpar->hTdDecorr->num_apd_outputs; ch++ ) + { + Copy32( pPcm_tmp[hSpar->hTdDecorr->num_apd_outputs - 1 - ch], p_tc[nchan_internal - 1 - ch], nSamplesToDecorr ); + } + } + } + FOR ( ch = 0; ch < nchan_internal; ch++ ) + { + p_tc[ch] = p_tc[ch] + nSamplesToDecorr; + } + + nSamplesLeftForTD = sub(nSamplesLeftForTD, nSamplesToDecorr); + } + } + + ivas_spar_dec_set_render_params_fx(st_ivas, nCldfbSlots); + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_spar_dec_upmixer() diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 22943ea60..aa98e0ae1 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -77,7 +77,7 @@ static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_ static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *hMdDec, const int16_t num_bands, const int16_t bfi, const int16_t num_md_sub_frames ); #ifdef IVAS_FLOAT_FIXED -static void ivas_spar_dec_compute_ramp_down_post_matrix_fx(ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands, const Word16 bfi, const Word16 num_md_sub_frames,Word16 *Q_mixer_mat); +static void ivas_spar_dec_compute_ramp_down_post_matrix_fx(ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands, const Word16 bfi, const Word16 num_md_sub_frames); #endif // IVAS_FLOAT_FIXED static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, const int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, const int16_t numch_out, const int16_t num_md_sub_frames ); @@ -1934,8 +1934,7 @@ void ivas_spar_dec_gen_umx_mat_fx( const Word16 nchan_transport, /* i : number of transport channels */ const Word16 num_bands_out, /* i : number of output bands */ const Word16 bfi, /* i : bad frame indicator */ - const Word16 num_md_sub_frames, - Word16 *Q_mixer_mat ) + const Word16 num_md_sub_frames ) { Word16 i, j, b, i_ts, num_out_ch; num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; @@ -1982,7 +1981,7 @@ void ivas_spar_dec_gen_umx_mat_fx( } } } - ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec, num_bands_out, bfi, num_md_sub_frames, Q_mixer_mat ); + ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec, num_bands_out, bfi, num_md_sub_frames); return; } #endif // IVAS_FLOAT_FIXED @@ -2908,8 +2907,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( ivas_spar_md_dec_state_t *hMdDec, const Word16 num_bands_out, const Word16 bfi, - const Word16 num_md_sub_frames, - Word16 *Q_mixer_mat ) + const Word16 num_md_sub_frames) { Word16 num_in_ch, num_out_ch, i, j, b; num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; @@ -2945,13 +2943,13 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( gain_dB = -imult1616(s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ) , ivas_spar_dec_plc_per_frame_ramp_down_gain_dB); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ Word16 exp_gain = 0; /*stores exponent for gain_fx*/ gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216(13421773/*=2^28/20*/, gain_dB ), 27213/*=log2(10)*2^13*/ ), 5, &exp_gain ); - Q_gain = 31 - exp_gain; + Q_gain = sub(31, exp_gain); FOR ( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { post_matrix_fx[i] = add( shl( 1, norm_nff ), mult( s_min( mult( shl( num_fade_frames, norm_nff ), div_s( 1, ivas_spar_dec_plc_num_frames_fade_out ) ), shl( 1, norm_nff ) ), shl( sub( ivas_spar_dec_plc_spatial_target[i], 1 ), 15 ) ) ); /*Q=norm_nff*/ post_matrix_fx[i] = Mult_32_16( gain_fx, (Word16)post_matrix_fx[i] ); /*Q_gain+norm_nff-15*/ } - Q_post_matrix = Q_gain + norm_nff - 15; + Q_post_matrix = sub(add(Q_gain, norm_nff), 15); /* apply the post matrix */ FOR ( Word16 i_ts = 0; i_ts < num_md_sub_frames; i_ts++ ) { @@ -2966,7 +2964,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( } } } - *Q_mixer_mat = Q_post_matrix + *Q_mixer_mat - 31; + hMdDec->Q_mixer_mat = sub(add(Q_post_matrix, hMdDec->Q_mixer_mat), 31); } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 94ba28e0b..9b392f758 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -866,6 +866,7 @@ typedef struct ivas_spar_md_dec_state_t Word16 mix_mat_dim_0_1; Word16 mix_mat_dim_2; Word32 mixer_mat_prev2_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; + Word16 Q_mixer_mat; #endif } ivas_spar_md_dec_state_t; @@ -1246,6 +1247,7 @@ typedef struct decoder_tc_buffer_structure #ifdef IVAS_FLOAT_FIXED Word32 *tc_buffer_fx; /* the buffer itself */ Word32 *tc_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* pointers into the buffer to the beginning of each tc Q11 for ivas */ // VE2SB: TBV + Word16 q_tc_fx; #endif TC_BUFFER_MODE tc_buffer_mode; /* mode of the buffer (no buffering, render buffering, out buffering) */ int16_t nchan_transport_jbm; /* number of TCs after TC decoding */ @@ -1354,10 +1356,6 @@ typedef struct Decoder_Struct IVAS_LIMITER_HANDLE hLimiter; /* Limiter handle */ float *p_output_f[MAX_OUTPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point output audio buffers */ -#ifdef IVAS_FLOAT_FIXED - Word32 **mem_hp20_out_fx; - Word32 *p_output_fx[MAX_OUTPUT_CHANNELS+MAX_NUM_OBJECTS]; /* floating-point output audio buffers */ -#endif /* core-decoder modules */ int16_t nSCE; /* number of total SCEs */ @@ -1430,7 +1428,10 @@ typedef struct Decoder_Struct int32_t last_active_ivas_total_brate; int16_t ism_extmeta_active; /* Extended metadata active in decoder */ int16_t ism_extmeta_cnt; /* Change frame counter for extended metadata */ - +#ifdef IVAS_FLOAT_FIXED + Word32 **mem_hp20_out_fx; + Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; /* floating-point output audio buffers */ +#endif } Decoder_Struct; /* clang-format on */ diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index f36a83056..c2e2f4393 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -534,8 +534,8 @@ void stereo_icBWE_dec_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *synthRef_fx, /* i/o: Reference channel HB synthesis at output Fs Q_syn/Q_syn - 1 */ Word32 *synth_fx, /* o : Non reference channel HB synthesis at output Fs Q_syn/Q_syn - 1 */ - const Word32 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Qx */ - const Word32 *voice_factors_fx, /* i : voicing factors */ + const Word16 *fb_synth_ref_fx, /* i : ref. high-band synthesis 16-20 kHz Qx */ + const Word16 *voice_factors_fx, /* i : voicing factors Q15 */ const Word16 output_frame, /* i : frame length */ Word16 *Q_syn /* i : Q of synth and synthRef buffers */ ) @@ -546,9 +546,9 @@ void stereo_icBWE_dec_fx( Word32 excSHB_nonref_fx[L_FRAME16k]; Word32 shb_synth_nonref_fx[L_FRAME16k + L_SHB_LAHEAD]; Word32 error_fx[L_FRAME32k]; - Word32 nlMixFac_fx[NB_SUBFR16k]; + Word16 nlMixFac_fx[NB_SUBFR16k]; Word16 specMapping_fx; - Word32 fb_synth_nonref_fx[L_FRAME48k]; + Word16 fb_synth_nonref_fx[L_FRAME48k]; Word32 prev_pow_fx, curr_pow_fx, maxVal1, maxVal; Word16 scale_fx, e_scale_fx; Word16 alpha_fx, winSlope_fx, winLen_fx; @@ -561,6 +561,7 @@ void stereo_icBWE_dec_fx( Word16 shift_prev_pow, synthRef_shift; Word32 L_tmp; Word16 tmp; + Word32 L_nlExc16k, L_mixExc16k; STEREO_DFT_DEC_DATA_HANDLE hStereoDft = hCPE->hStereoDft; STEREO_ICBWE_DEC_HANDLE hStereoICBWE = hCPE->hStereoICBWE; @@ -674,7 +675,7 @@ void stereo_icBWE_dec_fx( } - set32_fx( fb_synth_nonref_fx, 0, L_FRAME48k ); + set16_fx( fb_synth_nonref_fx, 0, L_FRAME48k ); /* core switching reset */ test(); @@ -813,13 +814,13 @@ void stereo_icBWE_dec_fx( test(); IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && EQ_16( st->flag_ACELP16k, 1 ) ) { - Copy32( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); + Copy( voice_factors_fx, nlMixFac_fx, NB_SUBFR16k ); //Q15 IF( hCPE->hStereoDftDmx != NULL ) { test(); IF( LT_32( hCPE->hStereoDftDmx->targetGain_fx, 268435456 ) || GT_32( hCPE->hStereoDftDmx->targetGain_fx, 1073741824 ) ) { - v_multc_fixed_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); + v_multc_fixed_16_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); } } ELSE @@ -827,7 +828,7 @@ void stereo_icBWE_dec_fx( test(); IF( LT_32( hCPE->hStereoTCA->targetGain_fx, 268435456 ) || GT_32( hCPE->hStereoTCA->targetGain_fx, 1073741824 ) ) { - v_multc_fixed_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); + v_multc_fixed_16_16( voice_factors_fx, 16384, nlMixFac_fx, NB_SUBFR16k ); } } @@ -855,14 +856,14 @@ void stereo_icBWE_dec_fx( { tmp = 0; move16(); - temp1_fx = Sqrt16( extract_l( L_shr( nlMixFac_fx[i], 1 ) ), &tmp ); + temp1_fx = Sqrt16( nlMixFac_fx[i] , &tmp ); IF( LT_16( tmp, 0 ) ) { temp1_fx = shl( temp1_fx, tmp ); } tmp = 0; move16(); - temp2_fx = Sqrt16( sub( 32767, extract_l( L_shr( nlMixFac_fx[i], 1 ) ) ), &tmp ); + temp2_fx = Sqrt16( sub( 32767, nlMixFac_fx[i] ), &tmp ); IF( LT_16( tmp, 0 ) ) { temp2_fx = shl( temp2_fx, tmp ); @@ -871,7 +872,12 @@ void stereo_icBWE_dec_fx( FOR( j = 0; j < L_FRAME16k / nbSubFr; j++ ) { - excSHB_nonref_fx[k] = L_add( Mpy_32_16_1( hStereoICBWE->nlExc16k_fx[k], temp1_fx ), Mpy_32_16_1( hStereoICBWE->mixExc16k_fx[k], temp2_fx ) ); // Q18 + // common Q for addition + L_nlExc16k = L_deposit_l( hStereoICBWE->nlExc16k_fx[k] ); // prev_q_bwe_exc - 16 + L_mixExc16k = L_deposit_l( hStereoICBWE->mixExc16k_fx[k] ); // Q_exc + L_nlExc16k = L_shl( L_nlExc16k, 18 - ( st->prev_Q_bwe_exc - 16 ) ); // Q18 + L_mixExc16k = L_shl( L_mixExc16k, 18 - st->Q_exc ); // Q18 + excSHB_nonref_fx[k] = L_add( Mpy_32_16_1( L_nlExc16k, temp1_fx ), Mpy_32_16_1( L_mixExc16k, temp2_fx ) ); // Q18 move32(); k++; } @@ -882,13 +888,13 @@ void stereo_icBWE_dec_fx( move16(); Q_syn_shb = FindScale( hStereoICBWE->mem_syn_shb_nonref_fx, LPC_SHB_ORDER, hStereoICBWE->prev_Q_syn_shb_nonref, Q_syn_shb ); - Q_syn_shb = FindScale( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 20, Q_syn_shb ); + Q_syn_shb = FindScale( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, 12, Q_syn_shb ); Q_syn_shb = FindScale( excSHB_nonref_fx, L_FRAME16k, 18, Q_syn_shb ); Q_syn_shb = FindScale( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, hStereoICBWE->prev_Q_lpc_shbsynth, Q_syn_shb ); Q_syn_shb = sub( Q_syn_shb, 3 ); // gaurded bits - Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 20 ) ); + Scale_sig32( hStereoICBWE->lpSHBRef_fx, LPC_SHB_ORDER + 1, sub( Q_syn_shb, 12 ) ); Scale_sig32( excSHB_nonref_fx, L_FRAME16k, sub( Q_syn_shb, 18 ) ); Scale_sig32( hStereoICBWE->mem_lpc_shbsynth_nonref_fx, LPC_SHB_ORDER, sub( Q_syn_shb, hStereoICBWE->prev_Q_lpc_shbsynth ) ); Scale_sig32( hStereoICBWE->mem_syn_shb_nonref_fx, L_SHB_LAHEAD, sub( Q_syn_shb, hStereoICBWE->prev_Q_syn_shb_nonref ) ); @@ -1010,8 +1016,7 @@ void stereo_icBWE_dec_fx( Scale_sig32( shb_synth_nonref_fx, L_FRAME16k + L_SHB_LAHEAD, tmp - Q_syn_shb ); Scale_sig32( hStereoICBWE->mem_syn_shb_ola_nonref_fx, L_SHB_LAHEAD, tmp - hStereoICBWE->prev_Q_syn_shb_ola ); - - ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( hStereoICBWE->gFrameRef_fx, mult_r( gsMapping_fx, 29492 ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); + ScaleShapedSHB_32( SHB_OVERLAP_LEN, shb_synth_nonref_fx, hStereoICBWE->mem_syn_shb_ola_nonref_fx, hStereoICBWE->gshapeRef_fx, ( Mpy_32_16_1( L_shl(hStereoICBWE->gFrameRef_fx,1), mult_r( gsMapping_fx, 29492 ) ) ), window_shb_fx, subwin_shb_fx, &tmp, &temp1_fx ); hStereoICBWE->prev_Q_syn_shb_ola = tmp; move16(); @@ -1020,7 +1025,7 @@ void stereo_icBWE_dec_fx( IF( EQ_16( st->extl, FB_TBE ) ) { - v_multc_fixed_16( fb_synth_ref_fx, gsMapping_fx, fb_synth_nonref_fx, L_FRAME48k ); + v_multc_fixed_16_16( fb_synth_ref_fx, gsMapping_fx, fb_synth_nonref_fx, L_FRAME48k ); } /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */ @@ -1203,7 +1208,13 @@ void stereo_icBWE_dec_fx( test(); IF( EQ_16( st->extl, FB_TBE ) && EQ_32( st->output_Fs, 48000 ) ) { - v_add_fixed( fb_synth_nonref_fx, synth_fx, synth_fx, L_FRAME48k, 0 ); + + //v_add( fb_synth_nonref_fx, synth_fx, synth_fx, L_FRAME48k, 0 ); + FOR( i = 0; i < L_FRAME48k; i++ ) + { + synth_fx[i] = L_add( synth_fx[i], L_deposit_l( fb_synth_nonref_fx[i] ) ); + move32(); + } } /* copy to outputHB and reset hb_synth values */ diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index bf0ac1cb4..d294cbead 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -247,7 +247,16 @@ void stereo_mdct_core_dec( for ( ch = 0; ch < nChannels; ch++ ) { /* Initialization or re-configuration of Stereo TCX */ +#ifdef IVAS_FLOAT_FIXED + /* stereo_tcx_dec_mode_switch_reconf_To_fixed is for intermediatery conversions which is needed to be removed */ + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 1, hCPE->last_element_mode ); + /*============*/ + stereo_tcx_init_dec_fx( sts[ch], 0, hCPE->last_element_mode ); + /*============*/ + stereo_tcx_dec_mode_switch_reconf_To_fixed( sts[ch], 0, hCPE->last_element_mode ); +#else stereo_tcx_init_dec( sts[ch], 0, hCPE->last_element_mode ); +#endif // IVAS_FLOAT_FIXED sts[ch]->hTcxDec->tnsActive[0] = sts[ch]->hTcxDec->tnsActive[1] = 0; sts[ch]->enablePlcWaveadjust = 0; set_zero( signal_out_tmp[ch], L_FRAME_PLUS ); diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index d24d6db9e..46def24ac 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -261,7 +261,6 @@ void stereo_mdct_core_dec_fx( sts[ch]->gamma = float_to_fix16( sts[ch]->gamma_float, Q15 ); sts[ch]->preemph_fac = float_to_fix16( sts[ch]->preemph_fac_float, Q15 ); sts[ch]->Mode2_lp_gainp = float_to_fix( sts[ch]->lp_gainp, Q16 ); - sts[ch]->stab_fac_fx = float_to_fix16( sts[ch]->stab_fac, Q15 ); sts[ch]->hTcxCfg->na_scale = float_to_fix16( sts[ch]->hTcxCfg->na_scale_flt, Q15 ); sts[ch]->hTcxCfg->sq_rounding = float_to_fix16( sts[ch]->hTcxCfg->sq_rounding_flt, Q15 ); sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); @@ -322,7 +321,6 @@ void stereo_mdct_core_dec_fx( sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); - sts[ch]->stab_fac = fix16_to_float( sts[ch]->stab_fac_fx, Q15 ); fixedToFloat_arr( Aq_fx[ch], Aq[ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); // 16bit to u8bit FOR( l = 0; l < IGF_START_MX; l++ ) @@ -834,12 +832,10 @@ void stereo_mdct_core_dec_fx( IF(st->hTcxDec) st->hTcxDec->stepCompensate_e = 1; st->preemph_fac = float_to_fix16( st->preemph_fac_float, Q15 ); IF(st->hTcxDec) st->hTcxDec->damping = float_to_fix16( st->hTcxDec->damping_float, Q14 ); - st->bfi_pitch_fx = float_to_fix16( st->bfi_pitch, Q5 ); st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); st->prev_Q_syn = st->Q_syn; st->old_fpitchFB = (Word32) ( st->old_fpitchFB_float * ONE_IN_Q16 ); - st->stab_fac_fx = (Word16) ( st->stab_fac * MAX_16 ); IF(hCPE->hStereoMdct) hCPE->hStereoMdct->lastCoh_fx = (Word16)(hCPE->hStereoMdct->lastCoh * (1<<14)); st->lp_gainp_fx = float_to_fix16(st->lp_gainp, 14); IF(st->hTonalMDCTConc) st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); @@ -850,21 +846,16 @@ void stereo_mdct_core_dec_fx( IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, -1 - st->Q_syn, L_FRAME_MAX / 2); IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, -1 - st->Q_syn, L_FRAME32k / 2); IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1 - st->Q_syn, L_FRAME32k / 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->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, -1, M + 1 ); - floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); + //floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); IF(st->hTcxDec) st->hTcxDec->tcxltp_third_last_pitch = float_to_fix(st->hTcxDec->tcxltp_third_last_pitch_float, 16); IF(st->hTcxDec) st->hTcxDec->tcxltp_second_last_pitch = float_to_fix(st->hTcxDec->tcxltp_second_last_pitch_float, 16); IF(st->hTcxDec) st->hTcxLtpDec->tcxltp_gain = (Word16)floatToFixed(st->hTcxLtpDec->tcxltp_gain_float, Q15); - IF(st->hPFstat) floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, 0, L_SUBFR ); - IF(st->hPFstat) floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, 0, L_SUBFR ); - IF(st->hBPF) st->lp_error_ener= floatToFixed( st->hBPF->pst_lp_ener, Q16 ); IF(st->hBPF) st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); - IF(st->hPFstat) st->hPFstat->gain_prec = (Word16)floatToFixed( st->hPFstat->gain_prec_flt, Q14 ); - st->last_voice_factor_fx = (Word16)floatToFixed(st->last_voice_factor, 6); IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_excFB, st->hTcxDec->old_excFB_fx, st->Q_exc, st->L_frame); st->Mode2_lp_gainc = (Word32) (st->lp_gainc * ONE_IN_Q16); @@ -878,19 +869,9 @@ void stereo_mdct_core_dec_fx( } IF(st->hBPF) floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); - f2me_buf_16(st->lsp_q_cng_float, st->lsp_q_cng, &e_lsp, 16); - f2me_buf_16(st->lsf_q_cng_float, st->lsf_q_cng, &e_lsf, 16); - floatToFixed_arr(st->old_lsp_q_cng_float, st->old_lsp_q_cng, 15-e_lsp, 16); - floatToFixed_arr(st->old_lsf_q_cng_float, st->old_lsf_q_cng, 15-e_lsf, 16); - floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); - floatToFixed_arr( st->mem_Aq_float, st->mem_Aq, Q12, ( NB_SUBFR16k ) * ( M + 1 ) ); - IF(st->hPFstat) floatToFixed_arr( st->hPFstat->mem_pf_in_flt, st->hPFstat->mem_pf_in, 0, L_SUBFR ); - IF(st->hPFstat) floatToFixed_arr( st->hPFstat->mem_stp_flt, st->hPFstat->mem_stp, 0, L_SUBFR ); - st->lp_noise = floatToFixed( st->lp_noise_float, Q16 ); - IF(st->hBPF) st->lp_error_ener = floatToFixed( st->hBPF->pst_lp_ener, Q16 ); + IF(st->hBPF) st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); - IF(st->hPFstat) st->hPFstat->gain_prec = (Word16) floatToFixed( st->hPFstat->gain_prec_flt, Q14 ); IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, st->Q_syn, 1280); IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_synthFB, st->hTcxDec->old_synthFB_fx, st->Q_syn, s_max(st->hTcxDec->L_frameTCX, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ))); @@ -937,7 +918,6 @@ void stereo_mdct_core_dec_fx( IF(st->hTcxDec) floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); IF(st->hTcxDec) st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; IF(st->hTcxDec) st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - floatToFixed_arr( st->mem_pitch_gain_float, st->mem_pitch_gain, Q14, 2 * NB_SUBFR16k + 2 ); floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); IF(st->hTcxDec) for ( int p = 0; p < st->L_frame; p++ ) { @@ -965,15 +945,11 @@ void stereo_mdct_core_dec_fx( IF(st->igf && nSubframes[ch] > 1) me2f_buf(x_fx_[ch][1], 31 - q_x, x[ch][1], s_min(s_max(st->hIGFDec->infoIGFStopLine, s_max(L_frameTCX[ch], L_spec[ch])), 600) ); fixedToFloat_arr(st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2); fixedToFloat_arr(st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2); - 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, st->Q_syn, M + 1 ); - fixedToFloat_arr( st->old_exc_fx, st->old_exc, st->Q_exc, L_EXC_MEM_DEC ); st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); 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->bfi_pitch = fix16_to_float( st->bfi_pitch_fx, Q6 ); st->old_fpitchFB_float = fix_to_float(st->old_fpitchFB, 16); st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); st->hTcxLtpDec->tcxltp_gain_float = fix16_to_float( st->hTcxLtpDec->tcxltp_gain, Q15 ); @@ -981,12 +957,8 @@ void stereo_mdct_core_dec_fx( FOR(Word16 ind = 0; ind < 17; ind++) { st->old_Aq_12_8[ind] = (float)(st->old_Aq_12_8_fx[ind]) / (float)(1<<12); } - IF(st->hPFstat) fixedToFloat_arr( st->hPFstat->mem_pf_in, st->hPFstat->mem_pf_in_flt, 0, L_SUBFR ); - IF(st->hPFstat) fixedToFloat_arr( st->hPFstat->mem_stp, st->hPFstat->mem_stp_flt, 0, L_SUBFR ); - IF(st->hBPF) st->hBPF->pst_lp_ener = fixedToFloat( st->lp_error_ener, Q16 ); + IF(st->hBPF) st->hBPF->pst_mem_deemp_err = fixedToFloat( st->mem_error, Q16 ); - IF(st->hPFstat) st->hPFstat->gain_prec_flt = fixedToFloat( st->hPFstat->gain_prec, Q14 ); - st->last_voice_factor = fix16_to_float(st->last_voice_factor_fx, 6); 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 ); @@ -1013,8 +985,7 @@ void stereo_mdct_core_dec_fx( } IF(st->hBPF && st->hBPF->pst_old_syn) fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); st->enr_old = (float)st->enr_old_fx; - me2f_buf_16(st->old_lsp_q_cng, e_lsp, st->old_lsp_q_cng_float, 16); - me2f_buf_16(st->old_lsf_q_cng, e_lsf, st->old_lsf_q_cng_float, 16); + //me2f_buf_16(st->old_lsp_q_cng, e_lsp, st->old_lsp_q_cng_float, 16); fixedToFloat_arr(st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280); fixedToFloat_arr(st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, st->Q_syn, NS2SA( st->output_Fs, PH_ECU_MEM_NS )); @@ -1030,7 +1001,6 @@ void stereo_mdct_core_dec_fx( st->hPlcInfo->recovery_gain_float = fix16_to_float( st->hPlcInfo->recovery_gain, Q14 ); st->hPlcInfo->step_concealgain = fix16_to_float( st->hPlcInfo->step_concealgain_fx, Q15 ); } - fixedToFloat_arr( st->mem_pitch_gain, st->mem_pitch_gain_float, Q14, 2 * NB_SUBFR16k + 2 ); fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); IF(st->hTcxDec) st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16(st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e); //st->hTcxDec->CngLevelBackgroundTrace_bfi = fix16_to_float( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); @@ -1042,7 +1012,14 @@ void stereo_mdct_core_dec_fx( IF(st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float) fixedToFloat_arr(st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, -2, st->hTonalMDCTConc->nSamples); IF( bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) fixedToFloat_arr(st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, -2, st->hTonalMDCTConc->nSamples / 2); } - // + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 2; j++ ) + { + free(x_fx_[i][j]); + } + } + #else ivas_mdct_core_reconstruct( hCPE, x, signal_outFB_tmp, fUseTns, 0 ); #endif @@ -1732,8 +1709,8 @@ static void run_min_stats_fx( 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 ) ); - st->lsf_cng_float[p] = ( (float) st->lsf_cng[p] / 2.56f ); // Q2.56 + //st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); + //st->lsf_cng_float[p] = ( (float) st->lsf_cng[p] / 2.56f ); // Q2.56 } } } diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index b8870625e..e7b6b59d5 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -4212,7 +4212,7 @@ void stereo_switching_dec( #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED /* populate PCh memories into the SCh */ - mvr2r( sts[0]->old_exc, sts[1]->old_exc, L_EXC_MEM_DEC ); + //mvr2r( sts[0]->old_exc, sts[1]->old_exc, L_EXC_MEM_DEC ); mvr2r( sts[0]->lsf_old, sts[1]->lsf_old, M ); mvr2r( sts[0]->lsp_old, sts[1]->lsp_old, M ); #endif @@ -4244,8 +4244,8 @@ void stereo_switching_dec( ELSE IF( hCPE->element_mode == IVAS_CPE_TD && hCPE->last_element_mode == IVAS_CPE_MDCT ) { #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); - set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); + //set_f( sts[0]->old_exc, 0.0f, L_EXC_MEM_DEC ); + //set_f( sts[1]->old_exc, 0.0f, L_EXC_MEM_DEC ); #endif set16_fx( sts[0]->old_exc_fx, 0, L_EXC_MEM_DEC ); set16_fx( sts[1]->old_exc_fx, 0, L_EXC_MEM_DEC ); diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 568d9a5d7..54c87e520 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -456,17 +456,6 @@ void stereo_tcx_core_dec_fx( } lpc_unquantize( st, lsf_fx, lsp_fx, M, param_lpc, lspmid_fx, lsfmid_fx, AUDIO, &LSF_Q_prediction ); - // 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 ) { @@ -490,7 +479,6 @@ void stereo_tcx_core_dec_fx( { /* 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( EQ_16( st->tcxonly, 0 ) || LT_16( st->core, TCX_10_CORE ) ) { diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 4505e7fcf..67c87d77b 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -172,22 +172,14 @@ void tdm_low_rate_dec( st->Q_exc = 0; /*hGSCDec float2fix*/ - st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx; - st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit; floatToFixed_arr(st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN); - st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev; floatToFixed_arr(st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN); st->hGSCDec->Last_frame_ener_fx = st->hGSCDec->Last_frame_ener < MAX_32 ? floatToFixed(st->hGSCDec->Last_frame_ener, Q3) : MAX_32; floatToFixed_arr(st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME); - st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; floatToFixed_arr(st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME); //st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0); - Copy(st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); - st->bfi_pitch_fx = float_to_fix16(st->bfi_pitch, 0); - st->tilt_code_fx = float_to_fix16(st->tilt_code, Q15); - floatToFixed_arr(st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k); st->last_good = st->last_good; st->Last_GSC_noisy_speech_flag = st->Last_GSC_noisy_speech_flag; st->last_coder_type = st->last_coder_type; @@ -222,22 +214,14 @@ void tdm_low_rate_dec( } /*hGSCDec fix2float*/ - st->hGSCDec->seed_tcx = st->hGSCDec->seed_tcx_fx; - st->hGSCDec->cor_strong_limit = st->hGSCDec->cor_strong_limit_fx; fixedToFloat_arr(st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN); - st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx; fixedToFloat_arr(st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN); st->hGSCDec->Last_frame_ener = fixedToFloat(st->hGSCDec->Last_frame_ener_fx, Q3); fixedToFloat_arr(st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME); - st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx; fixedToFloat_arr(st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME); st->hGSCDec->last_ener = fixedToFloat(st->hGSCDec->last_ener_fx, 0); - Copy(st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); - st->bfi_pitch = fixedToFloat(st->bfi_pitch_fx, 0); - st->tilt_code = fixedToFloat(st->tilt_code_fx, Q15); - fixedToFloat_arr(st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k); /*hGSCDec end*/ *tmp_noise = st->lp_gainc; @@ -276,10 +260,10 @@ void tdm_low_rate_dec_fx( st->GSC_IVAS_mode = 0; st->GSC_noisy_speech = 1; - hGSCDec->noise_lev_fx = 14; + hGSCDec->noise_lev = 14; pit_band_idx = 10 + BAND1k2; - hGSCDec->Last_GSC_pit_band_idx_fx = pit_band_idx; + hGSCDec->Last_GSC_pit_band_idx = pit_band_idx; //st->tilt_code = 0.0f; st->tilt_code_fx = 0; @@ -291,7 +275,6 @@ void tdm_low_rate_dec_fx( set_s(pitch_buf, shl(L_SUBFR, Q6), NB_SUBFR); st->bpf_off = 1; - //st->bfi_pitch = (int16_t)(mean(pitch_buf, 4) + 0.5f); st->bfi_pitch_fx = mean_fx(pitch_buf, 4); st->bfi_pitch_frame = L_FRAME; Diff_len = L_FRAME / 2; @@ -376,7 +359,6 @@ void tdm_low_rate_dec_fx( * Channel aware mode parameters *--------------------------------------------------------------------------------------*/ - //set_f(st->tilt_code_dec, 0, NB_SUBFR16k); set_s(st->tilt_code_dec_fx, 0, NB_SUBFR16k); return; @@ -523,22 +505,14 @@ void decod_gen_2sbfr( st->Q_exc = 0; /*hGSCDec float2fix*/ - st->hGSCDec->seed_tcx_fx = st->hGSCDec->seed_tcx; - st->hGSCDec->cor_strong_limit_fx = st->hGSCDec->cor_strong_limit; floatToFixed_arr( st->hGSCDec->old_y_gain, st->hGSCDec->old_y_gain_fx, Q12, MBANDS_GN ); - st->hGSCDec->noise_lev_fx = st->hGSCDec->noise_lev; floatToFixed_arr( st->hGSCDec->lt_ener_per_band, st->hGSCDec->lt_ener_per_band_fx, Q12, MBANDS_GN ); st->hGSCDec->Last_frame_ener_fx = st->hGSCDec->Last_frame_ener < MAX_32 ? floatToFixed( st->hGSCDec->Last_frame_ener, Q3 ) : MAX_32; floatToFixed_arr( st->hGSCDec->Last_GSC_spectrum, st->hGSCDec->Last_GSC_spectrum_fx, Q10, L_FRAME ); - st->hGSCDec->Last_GSC_pit_band_idx_fx = st->hGSCDec->Last_GSC_pit_band_idx; floatToFixed_arr( st->hGSCDec->last_exc_dct_in, st->hGSCDec->last_exc_dct_in_fx, st->Q_exc, L_FRAME ); // st->hGSCDec->last_ener_fx = float_to_fix16(st->hGSCDec->last_ener, 0); - Copy( st->hGSCDec->last_bitallocation_band, st->hGSCDec->last_bitallocation_band_fx, 6 ); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc_fx = float_to_fix16( st->lp_gainc, Q3 ); - st->bfi_pitch_fx = float_to_fix16( st->bfi_pitch, 0 ); - st->tilt_code_fx = float_to_fix16( st->tilt_code, Q15 ); - floatToFixed_arr( st->tilt_code_dec, st->tilt_code_dec_fx, Q15, NB_SUBFR16k ); st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0); st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16); floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6); @@ -547,9 +521,6 @@ void decod_gen_2sbfr( st->last_coder_type = st->last_coder_type; /*hGSCDec end*/ - st->gc_threshold_fx = floatToFixed(st->gc_threshold, Q16); - st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); - Word16 Aq_fx[NB_SUBFR16k * (M + 1)]; Word16 pitch_buf_fx[NB_SUBFR16k]; Word16 voice_factors_fx[5]; @@ -583,28 +554,18 @@ void decod_gen_2sbfr( } /*hGSCDec fix2float*/ - st->hGSCDec->seed_tcx = st->hGSCDec->seed_tcx_fx; - st->hGSCDec->cor_strong_limit = st->hGSCDec->cor_strong_limit_fx; fixedToFloat_arr( st->hGSCDec->old_y_gain_fx, st->hGSCDec->old_y_gain, Q12, MBANDS_GN ); - st->hGSCDec->noise_lev = st->hGSCDec->noise_lev_fx; fixedToFloat_arr( st->hGSCDec->lt_ener_per_band_fx, st->hGSCDec->lt_ener_per_band, Q12, MBANDS_GN ); st->hGSCDec->Last_frame_ener = fixedToFloat( st->hGSCDec->Last_frame_ener_fx, Q3 ); fixedToFloat_arr( st->hGSCDec->Last_GSC_spectrum_fx, st->hGSCDec->Last_GSC_spectrum, Q10, L_FRAME ); - st->hGSCDec->Last_GSC_pit_band_idx = st->hGSCDec->Last_GSC_pit_band_idx_fx; fixedToFloat_arr( st->hGSCDec->last_exc_dct_in_fx, st->hGSCDec->last_exc_dct_in, st->Q_exc, L_FRAME ); st->hGSCDec->last_ener = fixedToFloat( st->hGSCDec->last_ener_fx, 0 ); - Copy( st->hGSCDec->last_bitallocation_band_fx, st->hGSCDec->last_bitallocation_band, 6 ); st->GSC_noisy_speech = st->GSC_noisy_speech; st->lp_gainc = fixedToFloat( st->lp_gainc_fx, Q3 ); - st->bfi_pitch = fixedToFloat( st->bfi_pitch_fx, 0 ); - st->tilt_code = fixedToFloat( st->tilt_code_fx, Q15 ); - fixedToFloat_arr( st->tilt_code_dec_fx, st->tilt_code_dec, Q15, NB_SUBFR16k ); st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0); st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16); fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6); /*hGSCDec end*/ - st->gc_threshold = fixedToFloat(st->gc_threshold_fx, Q16); - st->stab_fac = fixedToFloat(st->stab_fac_fx, Q15); #endif } diff --git a/lib_dec/nelp_dec_fx.c b/lib_dec/nelp_dec_fx.c index 62f8c0632..bcafca8b4 100644 --- a/lib_dec/nelp_dec_fx.c +++ b/lib_dec/nelp_dec_fx.c @@ -254,7 +254,7 @@ void nelp_decoder_fx( Decoder_State *st_fx, Word16 *exc_nelp, Word16 *exc, Word1 normalize_arr(Gains, &qGain, 10, 4); } - generate_nelp_excitation_fx(&(hSC_VBR->nelp_dec_seed_fx), Gains, ptr, gain_fac); + generate_nelp_excitation_fx(&(hSC_VBR->nelp_dec_seed), Gains, ptr, gain_fac); /* o: ptr = nelp_exc in Q=qGain, qGain = 0 always for NB */ test(); diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 0c3ccaf06..7d630efd1 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -701,16 +701,16 @@ typedef struct tcx_dec_structure typedef struct gsc_dec_structure { int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ - Word16 seed_tcx_fx; /* AC mode (GSC) - seed for noise fill Q0*/ + //Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill Q0*/ int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - Word16 cor_strong_limit_fx; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + //Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ int16_t noise_lev; /* AC mode (GSC) - noise level */ - Word16 noise_lev_fx; /* AC mode (GSC) - noise level Q0*/ + //Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ float lt_ener_per_band[MBANDS_GN16k]; Word16 lt_ener_per_band_fx[MBANDS_GN16k]; /* Q12 */ @@ -722,7 +722,7 @@ typedef struct gsc_dec_structure Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ - Word16 Last_GSC_pit_band_idx_fx; /* AC mode (GSC) - Last pitch band index Q0*/ + //Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ @@ -731,7 +731,7 @@ typedef struct gsc_dec_structure Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ - Word16 last_bitallocation_band_fx[6]; /* AC mode (GSC) - previous bit allocation of each band */ + //Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ } GSC_DEC_DATA, *GSC_DEC_HANDLE; @@ -766,13 +766,13 @@ typedef struct ld_music_postfilt_structure Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ int16_t LDm_last_music_flag; /* LD music post-filter - last music flag */ - Word16 LDm_last_music_flag_fx; /* LD music post-filter - last music flag */ + //Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ int16_t LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ - Word16 LDm_nb_thr_1_fx; /* LD music post-filter - number of consecutives frames of level 1 */ + //Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutives frames of level 1 */ int16_t LDm_nb_thr_3; - Word16 LDm_nb_thr_3_fx; + //Word16 LDm_nb_thr_3; float dct_post_old_exc[DCT_L_POST - OFFSET2]; Word16 dct_post_old_exc_fx[DCT_L_POST - OFFSET2]; @@ -799,7 +799,7 @@ typedef struct ld_music_postfilt_structure Word16 filt_lfE_fx[DCT_L_POST]; int16_t last_nonfull_music; - Word16 last_nonfull_music_fx; + //Word16 last_nonfull_music; Word16 Old_ener_Q; /* Old energy scaling factor */ @@ -827,10 +827,10 @@ typedef struct bass_postfilt_structure Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ int16_t Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - Word16 Track_on_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + //Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ int16_t vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - Word16 vibrato_hist_fx[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + //Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ float psf_att; /* Bass post-filter - post filter attenuation factor */ Word16 psf_att_fx; /* Bass post-filter - post filter attenuation factor */ @@ -984,7 +984,7 @@ typedef struct td_cng_dec_structure typedef struct sc_vbr_dec_structure { int16_t firstTime_voiceddec; - Word16 firstTime_voiceddec_fx; /*Q0*/ + //Word16 firstTime_voiceddec; /*Q0*/ /* DTFS variables */ float dtfs_dec_a[MAXLAG_WI]; @@ -994,13 +994,13 @@ typedef struct sc_vbr_dec_structure Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ int16_t dtfs_dec_lag; - Word16 dtfs_dec_lag_fx; + //Word16 dtfs_dec_lag; int16_t dtfs_dec_nH; - Word16 dtfs_dec_nH_fx; + //Word16 dtfs_dec_nH; int16_t dtfs_dec_nH_4kHz; - Word16 dtfs_dec_nH_4kHz_fx; /*Q0*/ + //Word16 dtfs_dec_nH_4kHz; /*Q0*/ float dtfs_dec_upper_cut_off_freq_of_interest; @@ -1042,7 +1042,7 @@ typedef struct sc_vbr_dec_structure int16_t nelp_dec_seed; - Word16 nelp_dec_seed_fx; /* Q0*/ + //Word16 nelp_dec_seed; /* Q0*/ Word16 FadeScale_fx; /*Q15*/ @@ -1063,20 +1063,20 @@ typedef struct hq_nbfec_structure Word16 diff_energy_fx; int16_t stat_mode_out; - Word16 stat_mode_out_fx; + //Word16 stat_mode_out; int16_t stat_mode_old; - Word16 stat_mode_old_fx; + //Word16 stat_mode_old; int16_t phase_mat_flag; - Word16 phase_mat_flag_fx; + //Word16 phase_mat_flag; int16_t phase_mat_next; - Word16 phase_mat_next_fx; + //Word16 phase_mat_next; int16_t old_Min_ind; - Word16 old_Min_ind_fx; + //Word16 old_Min_ind; float old_auOut_2fr[L_FRAME8k * 2]; Word16 old_auOut_2fr_fx[L_FRAME8k * 2]; @@ -1098,16 +1098,16 @@ typedef struct hq_nbfec_structure int16_t HQ_FEC_seed; - Word16 HQ_FEC_seed_fx; + //Word16 HQ_FEC_seed; float energy_MA_Curr[2]; Word16 energy_MA_Curr_fx[2]; int16_t prev_sign_switch[HQ_FEC_SIGN_SFM]; - Word16 prev_sign_switch_fx[HQ_FEC_SIGN_SFM]; + //Word16 prev_sign_switch[HQ_FEC_SIGN_SFM]; int16_t prev_sign_switch_2[HQ_FEC_SIGN_SFM]; - Word16 prev_sign_switch_2_fx[HQ_FEC_SIGN_SFM]; + //Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ Word32 old_coeffs_fx[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ @@ -1152,32 +1152,32 @@ typedef struct hq_dec_structure int16_t last_hq_core_type; //Word16 last_hq_core_type; /*Q0*/ - int16_t old_is_transient[3]; /* HQ core - previous transient flag (for FEC and BWE/NF) */ - Word16 old_is_transient_fx[3]; /* HQ core - previous transient flag (for FEC) */ + //int16_t old_is_transient[3]; /* HQ core - previous transient flag (for FEC and BWE/NF) */ + Word16 old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ - int16_t mem_norm[SFM_N_ENV_STAB]; - Word16 mem_norm_fx[SFM_N_ENV_STAB]; /* Q0 */ + //int16_t mem_norm[SFM_N_ENV_STAB]; + Word16 mem_norm[SFM_N_ENV_STAB]; /* Q0 */ - int16_t mem_env_delta; - Word16 mem_env_delta_fx; /* Q11 */ + //int16_t mem_env_delta; + Word16 mem_env_delta; /* Q11 */ - int16_t no_att_hangover; - Word16 no_att_hangover_fx; /* Q0 */ + //int16_t no_att_hangover; + Word16 no_att_hangover; /* Q0 */ float energy_lt; Word32 energy_lt_fx; /* Q13 */ - int16_t hq_generic_seed; - Word16 hq_generic_seed_fx; + //int16_t hq_generic_seed; + Word16 hq_generic_seed; float prev_noise_level[2]; Word16 prev_noise_level_fx[2]; /* Q15 */ - int16_t prev_hqswb_clas; - Word16 prev_hqswb_clas_fx; + //int16_t prev_hqswb_clas; + Word16 prev_hqswb_clas; - int16_t prev_R; /* the table of bit allocation of last frame */ - Word16 prev_R_fx; /* the table of bit allocation of last frame */ + //int16_t prev_R; /* the table of bit allocation of last frame */ + Word16 prev_R; /* the table of bit allocation of last frame */ float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; @@ -1186,8 +1186,8 @@ typedef struct hq_dec_structure Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; - int16_t HqVoicing; - Word16 HqVoicing_fx; + //int16_t HqVoicing; + Word16 HqVoicing; float fer_samples[L_FRAME48k]; Word16 fer_samples_fx[L_FRAME48k]; @@ -1206,8 +1206,8 @@ typedef struct hq_dec_structure float last_env[BANDS_MAX]; Word16 last_env_fx[BANDS_MAX]; - int16_t last_max_pos_pulse; - Word16 last_max_pos_pulse_fx; + //int16_t last_max_pos_pulse; + Word16 last_max_pos_pulse; /* pre-echo reduction */ float memfilt_lb; @@ -1233,11 +1233,11 @@ typedef struct hq_dec_structure int16_t pastpre; - int16_t prev_frm_hfe2; - Word16 prev_frm_hfe2_fx; + //int16_t prev_frm_hfe2; + Word16 prev_frm_hfe2; - int16_t prev_stab_hfe2; - Word16 prev_stab_hfe2_fx; + //int16_t prev_stab_hfe2; + Word16 prev_stab_hfe2; float prev_ni_ratio; Word16 prev_ni_ratio_fx; /* 15 */ @@ -1251,19 +1251,19 @@ typedef struct hq_dec_structure *----------------------------------------------------------------------------------*/ /* HQ PHASE ECU internal state */ - int16_t time_offs; - Word16 time_offs_fx; + //int16_t time_offs; + Word16 time_offs; float X_sav[PH_ECU_SPEC_SIZE]; Word16 X_sav_fx[PH_ECU_SPEC_SIZE]; Word16 Q_X_sav; - int16_t num_p; - Word16 num_p_fx; + //int16_t num_p; + Word16 num_p; - int16_t plocs[MAX_PLOCS]; - Word16 plocs_fx[MAX_PLOCS]; + //int16_t plocs[MAX_PLOCS]; + Word16 plocs[MAX_PLOCS]; float plocsi[MAX_PLOCS]; Word32 plocsi_fx[MAX_PLOCS]; @@ -1271,11 +1271,11 @@ typedef struct hq_dec_structure float env_stab; Word16 env_stab_fx; - int16_t mem_norm_hqfec[SFM_N_ENV_STAB]; - Word16 mem_norm_hqfec_fx[SFM_N_ENV_STAB]; + //int16_t mem_norm_hqfec[SFM_N_ENV_STAB]; + Word16 mem_norm_hqfec[SFM_N_ENV_STAB]; - int16_t mem_env_delta_hqfec; - Word16 mem_env_delta_hqfec_fx; + //int16_t mem_env_delta_hqfec; + Word16 mem_env_delta_hqfec; float env_stab_plc; Word16 env_stab_plc_fx; @@ -1283,8 +1283,8 @@ typedef struct hq_dec_structure float env_stab_state_p[NUM_ENV_STAB_PLC_STATES]; Word16 env_stab_state_p_fx[NUM_ENV_STAB_PLC_STATES]; - int16_t envstabplc_hocnt; - Word16 envstabplc_hocnt_fx; + //int16_t envstabplc_hocnt; + Word16 envstabplc_hocnt; float mag_chg_1st[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ Word16 mag_chg_1st_fx[LGW_MAX]; /* i/o: per band magnitude modifier for transients*/ @@ -1295,20 +1295,20 @@ typedef struct hq_dec_structure float beta_mute; /* Factor for long-term mute */ Word16 beta_mute_fx; /* Factor for long-term mute */ - int16_t last_fec; - Word16 last_fec_fx; + //int16_t last_fec; + Word16 last_fec; - int16_t ph_ecu_HqVoicing; - Word16 ph_ecu_HqVoicing_fx; + //int16_t ph_ecu_HqVoicing; + Word16 ph_ecu_HqVoicing; - int16_t oldHqVoicing; - Word16 oldHqVoicing_fx; + //int16_t oldHqVoicing; + Word16 oldHqVoicing; float oldgapsynth[L_FRAME48k]; Word16 oldgapsynth_fx[L_FRAME48k]; - int16_t ph_ecu_active; /* Set to 1 if Phase ECU was used in last bad frame; Set to 2 if TCX TD PLC was used */ - Word16 ph_ecu_active_fx; /* Set if Phase ECU was used in last bad frame */ + //int16_t ph_ecu_active; /* Set to 1 if Phase ECU was used in last bad frame; Set to 2 if TCX TD PLC was used */ + Word16 ph_ecu_active; /* Set if Phase ECU was used in last bad frame */ int16_t ni_seed_forfec; @@ -1384,7 +1384,6 @@ typedef struct td_bwe_dec_structure float old_bwe_exc[PIT16k_MAX * 2]; /* old excitation */ Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - Word32 old_bwe_exc_fx_32[PIT16k_MAX * 2]; /*Q_exc*/ int16_t bwe_seed[2]; //Word16 bwe_seed[2]; /*Q0*/ @@ -2012,7 +2011,6 @@ typedef struct Decoder_State float bfi_pitch; /* FEC - pitch for FEC */ Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - Word32 bfi_pitch_fx32; /* FEC - pitch for FEC */ int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ //Word16 bfi_pitch_frame_fx; /*FEC - frame length when pitch for FEC is saved Q0*/ @@ -2547,11 +2545,6 @@ typedef struct Decoder_State /* LPC quantization */ int16_t lpcQuantization; -#ifdef IVAS_FLOAT_FIXED - Word16 prev_lpcQuantization; /*temporary check if for last frame lpcQuantization was set or not, to be removed */ - float scale; /*temporary for lpc_unquantize fixed point implementation, to be removed */ - float scale_lsfbfi; /*temporary for lpc_unquantize fixed point implementation, to be removed */ -#endif // IVAS_FLOAT_FIXED int16_t numlpc; /* Bandwidth */ diff --git a/lib_dec/swb_bwe_dec_lr_fx.c b/lib_dec/swb_bwe_dec_lr_fx.c index 8c5f7eedb..56ff265a6 100644 --- a/lib_dec/swb_bwe_dec_lr_fx.c +++ b/lib_dec/swb_bwe_dec_lr_fx.c @@ -82,8 +82,8 @@ static void DecodeSWBSubbands_fx( const Word16 hqswb_clas_fx, /* i : class information */ const Word16 har_bands_fx, /* i : number of LF harmonic bands */ const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ Word16 band_width_fx[], /* i : subband band widths */ const Word32 L_spectra_ni[], /* i/o: core coder with sparseness filled */ Word16 *ni_seed_fx /* i/o: random seed for search buffer NI */ @@ -130,12 +130,12 @@ static void DecodeSWBSubbands_fx( IF( EQ_16(hqswb_clas_fx, HQ_HARMONIC)) { - pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2_fx, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2_fx ); - noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas_fx, &(hHQ_core->prev_ni_ratio_fx), &Qss); + pos_max_hfe2 = har_est_fx( L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2 ); + noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &(hHQ_core->prev_ni_ratio_fx), &Qss); IF( flag_dis == 0 ) { test(); - if( NE_16(har_freq_est2, SWB_HAR_RAN1)||NE_16(har_freq_est2,*prev_frm_hfe2_fx)) + if( NE_16(har_freq_est2, SWB_HAR_RAN1)||NE_16(har_freq_est2,*prev_frm_hfe2)) { har_freq_est2 = add(har_freq_est2, lagIndices_fx[0]); } @@ -168,12 +168,12 @@ static void DecodeSWBSubbands_fx( IF( flag_dis == 0 ) { - *prev_frm_hfe2_fx = 0; + *prev_frm_hfe2 = 0; move16(); } ELSE { - *prev_frm_hfe2_fx = har_freq_est2; + *prev_frm_hfe2 = har_freq_est2; move16(); } @@ -283,8 +283,8 @@ void swb_bwe_dec_lr_fx( Word16 lowlength_fx, /* i : Lowband Length */ Word16 highlength_fx, /* i : Highband Length */ const Word16 har_bands_fx, /* i : Number of LF harmonic bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ Word16 band_width_fx[], /* i : subband bandwidth */ const Word32 L_y2_ni[], /* i/o: Sparse filled corecoder */ Word16 *ni_seed_fx /* i/o: random seed */ @@ -321,7 +321,7 @@ void swb_bwe_dec_lr_fx( DecodeSWBSubbands_fx(st_fx,st_fx->hHQ_core,L_m, QsL,swb_lowband_fx, swb_highband_fx, nBands_fx, wBands_fx, subband_offsets_fx, lagIndices_fx, lagGains_fx, QlagGains,BANDS_fx, band_start_fx, band_end_fx, L_band_energy, Qbe, p2a_flags_fx, hqswb_clas_fx, har_bands_fx, subband_search_offset_fx, - prev_frm_hfe2_fx, prev_stab_hfe2_fx, band_width_fx, L_y2_ni, ni_seed_fx); + prev_frm_hfe2, prev_stab_hfe2, band_width_fx, L_y2_ni, ni_seed_fx); p_L_m = &L_m[sub(allband_fx, 1)]; *p_L_m = Mult_32_16(*p_L_m, 2028); diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index c7f19c062..a9df85450 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -579,9 +579,9 @@ static void gradientGainShape( /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */ FOR(j = 0; j < 3; j++) { - GainGrad0[j] = sub(shr(hBWE_TD->GainShape_Delay_fx[j + 1], 1), shr(hBWE_TD->GainShape_Delay_fx[j], 1)); + GainGrad0[j] = sub(shr(st_fx->GainShape_Delay[j + 1], 1), shr(st_fx->GainShape_Delay[j], 1)); move16(); /* Q14 */ - GainGrad1[j] = sub(shr(hBWE_TD->GainShape_Delay_fx[j + 5], 1), shr(hBWE_TD->GainShape_Delay_fx[j + 4], 1)); + GainGrad1[j] = sub(shr(st_fx->GainShape_Delay[j + 5], 1), shr(st_fx->GainShape_Delay[j + 4], 1)); move16(); /* Q14 */ GainGradFEC[j + 1] = add(mult_r(GainGrad0[j], 13107), mult_r(GainGrad1[j], 19660)); move16(); /* Q14 */ @@ -610,17 +610,17 @@ static void gradientGainShape( test(); IF((st_fx->prev_coder_type == UNVOICED || st_fx->last_good == UNVOICED_CLAS) && GainGradFEC[0] > 0) { - GainShapeTemp[0] = add(shr(hBWE_TD->GainShape_Delay_fx[7], 1), GainGradFEC[0]); + GainShapeTemp[0] = add(shr(st_fx->GainShape_Delay[7], 1), GainGradFEC[0]); move16(); } ELSE IF(GainGradFEC[0] > 0) { - GainShapeTemp[0] = add(shr(hBWE_TD->GainShape_Delay_fx[7], 1), mult_r(GainGradFEC[0], 16384)); + GainShapeTemp[0] = add(shr(st_fx->GainShape_Delay[7], 1), mult_r(GainGradFEC[0], 16384)); move16(); /* Q14 */ } ELSE { - GainShapeTemp[0] = shr(hBWE_TD->GainShape_Delay_fx[7], 1); + GainShapeTemp[0] = shr(st_fx->GainShape_Delay[7], 1); move16(); /* Q14 */ } @@ -1103,7 +1103,7 @@ void ivas_swb_tbe_dec_fx( } /* WB/SWB bandwidth switching */ - IF( ( st->tilt_wb > 5 && st->clas_dec == UNVOICED_CLAS ) || st->tilt_wb > 10 ) + IF( ( st->tilt_wb_fx > 10240 && st->clas_dec == UNVOICED_CLAS ) || st->tilt_wb_fx > 20480) { test(); test(); @@ -1403,10 +1403,10 @@ void ivas_swb_tbe_dec_fx( } /* get the gainshape delay */ - Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); + Copy( &st->GainShape_Delay[4], &st->GainShape_Delay[0], NUM_SHB_SUBFR / 4 ); FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { - hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape_fx[i * 4]; + st->GainShape_Delay[i + 4] = GainShape_fx[i * 4]; move16(); } @@ -4611,7 +4611,6 @@ void td_bwe_dec_init( /* init. SHB buffers */; set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) ); - set32_fx( hBWE_TD->old_bwe_exc_fx_32, 0, ( PIT16k_MAX * 2 ) ); hBWE_TD->bwe_seed[0] = 23; /* 1; */ hBWE_TD->bwe_seed[1] = 59; /* 10000; */ set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index b38885ad5..f7a9fac44 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -514,6 +514,8 @@ void ResetSHBbuffer_Dec_fx( Decoder_State* st_fx /* i/o: SHB encoder structure * hBWE_TD->gain_prec_swb_fx = 16384;/*Q14 =1*/ set16_fx( &st_fx->GainShape_Delay[0], 0, NUM_SHB_SUBFR / 2 ); + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ + set16_fx(hBWE_TD->old_core_synth_fx, 0, L_FRAME16k); set16_fx(hBWE_TD->old_tbe_synth_fx, 0, L_SHB_TRANSITION_LENGTH); hBWE_TD->tilt_swb_fec_fx = 0; diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index a3761f2cb..e2edbd8d2 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -56,6 +56,7 @@ void tcx_decoder_memory_update( tmp = synth[-M - 1]; move16(); st->Q_syn = E_UTIL_f_preemph3(synth - M, preemph, add(M, L_frame_glob), &tmp, 1); + st->Q_syn = s_min(st->Q_syn, 8); st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; Copy(synth + sub(L_frame_glob, M), st->mem_syn2_fx, M); Copy(synth + sub(L_frame_glob, L_SYN_MEM), st->mem_syn_r, L_SYN_MEM); diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 4aeff98b8..49b7eed64 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -59,9 +59,9 @@ void updt_dec_fx( test(); IF (st_fx->hGSCDec != NULL ) { - IF ((NE_16(st_fx->coder_type, AUDIO) || st_fx->Last_GSC_noisy_speech_flag != 0) && st_fx->hGSCDec->Last_GSC_pit_band_idx_fx > 0) + IF ((NE_16(st_fx->coder_type, AUDIO) || st_fx->Last_GSC_noisy_speech_flag != 0) && st_fx->hGSCDec->Last_GSC_pit_band_idx > 0) { - st_fx->hGSCDec->Last_GSC_pit_band_idx_fx = 0; + st_fx->hGSCDec->Last_GSC_pit_band_idx = 0; move16(); /*The temporal contribution of the GSC is meaningless after 1 frame lost for inactive & unvoiced content */ } } @@ -102,13 +102,13 @@ void updt_dec_fx( test(); IF(st_fx->hGSCDec != NULL && st_fx->coder_type != AUDIO && st_fx->coder_type != INACTIVE) { - st_fx->hGSCDec->noise_lev_fx = NOISE_LEVEL_SP3; + st_fx->hGSCDec->noise_lev = NOISE_LEVEL_SP3; move16(); set16_fx(st_fx->hGSCDec->old_y_gain_fx, 0, MBANDS_GN); FOR(i = 0; i < L_FRAME; i++) { - Word16 tmp_seed = st_fx->hGSCDec->seed_tcx_fx; + Word16 tmp_seed = st_fx->hGSCDec->seed_tcx; move16(); st_fx->hGSCDec->Last_GSC_spectrum_fx[i] = shr_r(Random(&tmp_seed), 5); move16(); /*Q10*/ @@ -167,12 +167,12 @@ void updt_dec_fx( { IF(NE_16(st_fx->last_core, HQ_CORE)) { - hHQ_core->HqVoicing_fx = 1; + hHQ_core->HqVoicing = 1; move16(); test(); if (!st_fx->Opt_AMR_WB && EQ_16(st_fx->coder_type, UNVOICED)) { - hHQ_core->HqVoicing_fx = 0; + hHQ_core->HqVoicing = 0; move16(); } } @@ -249,6 +249,7 @@ void updt_IO_switch_dec_fx( hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &hBWE_TD->tbe_demph_fx, &hBWE_TD->tbe_premph_fx , hBWE_TD->mem_stp_swb_fx,&(hBWE_TD->gain_prec_swb_fx) ); set16_fx( st_fx->GainShape_Delay, 0, NUM_SHB_SUBFR/2 ); + hBWE_TD->prev_mix_factor_fx = 32767; /*Q15 1.f*/ swb_tbe_reset_synth_fx(hBWE_TD->genSHBsynth_Hilbert_Mem_fx, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx ); } @@ -287,7 +288,7 @@ void updt_IO_switch_dec_fx( /* reset the unvoiced/audio signal improvement memories */ IF(st_fx->hGSCDec != NULL) { - st_fx->hGSCDec->seed_tcx_fx = 15687; + st_fx->hGSCDec->seed_tcx = 15687; } move16(); st_fx->hAmrwb_IO->UV_cnt_fx = 30; @@ -340,7 +341,7 @@ void updt_IO_switch_dec_fx( /* reset the unvoiced/audio signal improvement memories */ IF(st_fx->hGSCDec != NULL) { - st_fx->hGSCDec->seed_tcx_fx = 15687; + st_fx->hGSCDec->seed_tcx = 15687; } Copy(st_fx->hAmrwb_IO->lt_diff_etot_fx, tmp_buf, MAX_LT); @@ -967,7 +968,7 @@ void ivas_updt_dec_common_fx( st_fx->log_energy_diff_lt = fixedToFloat(st_fx->log_energy_diff_lt_fx, Q15); if (st_fx->core == HQ_CORE) { - st_fx->stab_fac_fx = extract_l(L_min(MAX_16, L_shr(L_add(STAB_FAC_EST1_FX, Madd_32_16(Mpy_32_16_1(STAB_FAC_EST2_FX , st_fx->hHQ_core->mem_env_delta_fx), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx)), Q15))); + st_fx->stab_fac_fx = extract_l(L_min(MAX_16, L_shr(L_add(STAB_FAC_EST1_FX, Madd_32_16(Mpy_32_16_1(STAB_FAC_EST2_FX , st_fx->hHQ_core->mem_env_delta), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx)), Q15))); st_fx->stab_fac_fx = s_max(0, st_fx->stab_fac_fx); } st_fx->stab_fac_smooth_lt_fx = L_add(L_mult(ENV_SMOOTH_FAC_FX , st_fx->stab_fac_fx), diff --git a/lib_dec/voiced_dec_fx.c b/lib_dec/voiced_dec_fx.c index e4ebaf4e2..3dadaf71c 100644 --- a/lib_dec/voiced_dec_fx.c +++ b/lib_dec/voiced_dec_fx.c @@ -114,17 +114,17 @@ ivas_error ppp_voiced_decoder_fx( /* Initialization */ - IF (hSC_VBR->firstTime_voiceddec_fx) + IF (hSC_VBR->firstTime_voiceddec) { - hSC_VBR->firstTime_voiceddec_fx=0; + hSC_VBR->firstTime_voiceddec=0; move16(); /* (st_fx->PREV_CW_D) = DTFS_new();*/ - hSC_VBR->dtfs_dec_lag_fx = 0; + hSC_VBR->dtfs_dec_lag = 0; move16(); - hSC_VBR->dtfs_dec_nH_fx = 0; + hSC_VBR->dtfs_dec_nH = 0; move16(); - hSC_VBR->dtfs_dec_nH_4kHz_fx = 0; + hSC_VBR->dtfs_dec_nH_4kHz = 0; move16(); hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx = 3300; move16(); @@ -285,11 +285,11 @@ ivas_error ppp_voiced_decoder_fx( ELSE { /* Copy DTFS related parameters from 'st' to 'dtfs_temp' structure */ - dtfs_temp_fx->lag_fx = hSC_VBR->dtfs_dec_lag_fx; + dtfs_temp_fx->lag_fx = hSC_VBR->dtfs_dec_lag; move16(); - dtfs_temp_fx->nH_fx = hSC_VBR->dtfs_dec_nH_fx; + dtfs_temp_fx->nH_fx = hSC_VBR->dtfs_dec_nH; move16(); - dtfs_temp_fx->nH_4kHz_fx = hSC_VBR->dtfs_dec_nH_4kHz_fx; + dtfs_temp_fx->nH_4kHz_fx = hSC_VBR->dtfs_dec_nH_4kHz; move16(); dtfs_temp_fx->upper_cut_off_freq_of_interest_fx = hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx; move16(); @@ -372,11 +372,11 @@ ivas_error ppp_voiced_decoder_fx( DTFS_copy_fx(dtfs_temp_fx, *CURRP_Q_D_FX); /* Copy DTFS related parameters from 'dtfs_temp' to 'st' structure */ - hSC_VBR->dtfs_dec_lag_fx = dtfs_temp_fx->lag_fx; + hSC_VBR->dtfs_dec_lag = dtfs_temp_fx->lag_fx; move16(); - hSC_VBR->dtfs_dec_nH_fx = dtfs_temp_fx->nH_fx; + hSC_VBR->dtfs_dec_nH = dtfs_temp_fx->nH_fx; move16(); - hSC_VBR->dtfs_dec_nH_4kHz_fx = dtfs_temp_fx->nH_4kHz_fx; + hSC_VBR->dtfs_dec_nH_4kHz = dtfs_temp_fx->nH_4kHz_fx; move16(); hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx = dtfs_temp_fx->upper_cut_off_freq_of_interest_fx; move16(); @@ -404,15 +404,15 @@ void sc_vbr_dec_init( SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle */ ) { - hSC_VBR->nelp_dec_seed_fx = 0; - hSC_VBR->firstTime_voiceddec_fx = 1; + hSC_VBR->nelp_dec_seed = 0; + hSC_VBR->firstTime_voiceddec = 1; /* DTFS variables */ set16_fx(hSC_VBR->dtfs_dec_a_fx, 0, MAXLAG_WI); set16_fx(hSC_VBR->dtfs_dec_b_fx, 0, MAXLAG_WI); - hSC_VBR->dtfs_dec_lag_fx = 0; - hSC_VBR->dtfs_dec_nH_fx = 0; - hSC_VBR->dtfs_dec_nH_4kHz_fx = 0; + hSC_VBR->dtfs_dec_lag = 0; + hSC_VBR->dtfs_dec_nH = 0; + hSC_VBR->dtfs_dec_nH_4kHz = 0; hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest_fx = 0; hSC_VBR->dtfs_dec_upper_cut_off_freq_fx = 0; hSC_VBR->ph_offset_D_fx = 0; diff --git a/lib_enc/ivas_agc_enc.c b/lib_enc/ivas_agc_enc.c index 9b059aefb..8fbeabc18 100644 --- a/lib_enc/ivas_agc_enc.c +++ b/lib_enc/ivas_agc_enc.c @@ -58,6 +58,8 @@ #ifdef IVAS_FLOAT_FIXED static Word16 ceil_fx( Word16 inp, Word16 Q ); +static Word32 pow32_fx(Word16 inp, Word16 indx); +static Word16 BASOP_Util_Cmp_Mant32Exp_sat(Word32 a_m, Word16 a_e, Word32 b_m, Word16 b_e); static Word16 ceil_fx( Word16 inp, Word16 Q ) { Word16 ret; @@ -84,98 +86,97 @@ static Word16 ceil_fx( Word16 inp, Word16 Q ) return ret; } -Word16 BASOP_Util_Cmp_Mant32Exp_sat /*!< o: flag: result of comparison */ -/* 0, if a == b */ -/* 1, if a > b */ -/* -1, if a < b */ -(Word32 a_m, /*!< i: Mantissa of 1st operand a */ - Word16 a_e, /*!< i: Exponent of 1st operand a */ - Word32 b_m, /*!< i: Mantissa of 2nd operand b */ - Word16 b_e) /*!< i: Exponent of 2nd operand b */ +Word16 BASOP_Util_Cmp_Mant32Exp_sat /*!< o: flag: result of comparison */ + /* 0, if a == b */ + /* 1, if a > b */ + /* -1, if a < b */ + ( Word32 a_m, /*!< i: Mantissa of 1st operand a */ + Word16 a_e, /*!< i: Exponent of 1st operand a */ + Word32 b_m, /*!< i: Mantissa of 2nd operand b */ + Word16 b_e ) /*!< i: Exponent of 2nd operand b */ { - Word32 diff_m; - Word16 diff_e, shift, result; - - - - /* - This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. - If both values are identical, 0 is returned. - If a is greater b, 1 is returned. - If a is less than b, -1 is returned. - */ - - /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ - shift = norm_l(a_m); - if (shift) - a_m = L_shl(a_m, shift); - if (shift) - a_e = sub(a_e, shift); - - shift = norm_l(b_m); - if (shift) - b_m = L_shl(b_m, shift); - if (shift) - b_e = sub(b_e, shift); - - /* align exponent, if any mantissa is zero */ - if (!a_m) - { - a_e = b_e; - move16(); - } - if (!b_m) - { - b_e = a_e; - move16(); - } - - BASOP_SATURATE_WARNING_OFF_EVS - diff_m = L_sub_sat( a_m, b_m ); - BASOP_SATURATE_WARNING_ON_EVS - diff_e = sub( a_e, b_e ); - - test(); - IF( diff_m == 0 && diff_e == 0 ) - { - return 0; - } - - /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ - result = sub( 0, 1 ); - - IF( a_m >= 0 ) - { - /* a is positive */ - if ( b_m < 0 ) - { - result = 1; - move16(); - } - - test(); - test(); - test(); - if ( ( b_m >= 0 ) && ( ( diff_e > 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) - { - result = 1; - move16(); - } - } - ELSE - { - /* a is negative */ - test(); - test(); - test(); - if ( ( b_m < 0 ) && ( ( diff_e < 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) - { - result = 1; - move16(); - } - } - return result; + Word32 diff_m; + Word16 diff_e, shift, result; + + + /* + This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. + If both values are identical, 0 is returned. + If a is greater b, 1 is returned. + If a is less than b, -1 is returned. + */ + + /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ + shift = norm_l( a_m ); + if ( shift ) + a_m = L_shl( a_m, shift ); + if ( shift ) + a_e = sub( a_e, shift ); + + shift = norm_l( b_m ); + if ( shift ) + b_m = L_shl( b_m, shift ); + if ( shift ) + b_e = sub( b_e, shift ); + + /* align exponent, if any mantissa is zero */ + if ( !a_m ) + { + a_e = b_e; + move16(); + } + if ( !b_m ) + { + b_e = a_e; + move16(); + } + + BASOP_SATURATE_WARNING_OFF_EVS + diff_m = L_sub_sat( a_m, b_m ); + BASOP_SATURATE_WARNING_ON_EVS + diff_e = sub( a_e, b_e ); + + test(); + IF( diff_m == 0 && diff_e == 0 ) + { + return 0; + } + + /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ + result = sub( 0, 1 ); + + IF( a_m >= 0 ) + { + /* a is positive */ + if ( b_m < 0 ) + { + result = 1; + move16(); + } + + test(); + test(); + test(); + if ( ( b_m >= 0 ) && ( ( diff_e > 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) + { + result = 1; + move16(); + } + } + ELSE + { + /* a is negative */ + test(); + test(); + test(); + if ( ( b_m < 0 ) && ( ( diff_e < 0 ) || ( diff_e == 0 && diff_m > 0 ) ) ) + { + result = 1; + move16(); + } + } + return result; } Word32 pow32_fx( Word16 inp, Word16 indx ) diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index d9e8c5680..41d6bca9e 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -31,6 +31,7 @@ *******************************************************************************************************/ #include +#include #include "options.h" #include "cnst.h" #include "ivas_cnst.h" @@ -432,7 +433,31 @@ ivas_error ivas_enc( { st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; +#ifdef IVAS_FLOAT_FIXED + Word16 q_data_lfe_ch; + Word32 data_lfe_ch_fx[L_FRAME48k]; + float max_val = 0; + + for (int i = 0; i < input_frame; i++) { + if (max_val < (float)fabs(data_f[LFE_CHANNEL][i])) + max_val = (float)fabs(data_f[LFE_CHANNEL][i]); + } + + if ((Word32)max_val == 0) + q_data_lfe_ch = 31; + else + q_data_lfe_ch = norm_l((Word32)max_val); + + + for (int i = 0; i < input_frame; i++) { + data_lfe_ch_fx[i] = (Word32)(data_f[LFE_CHANNEL][i] * (1 << q_data_lfe_ch)); + } + + ivas_lfe_enc_fx( st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr ); +#else ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); +#endif // IVAS_FLOAT_FIXED + } if ( st_ivas->mc_mode == MC_MODE_MCT ) @@ -448,7 +473,31 @@ ivas_error ivas_enc( ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame ); st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr; - ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); + +#ifdef IVAS_FLOAT_FIXED + Word16 q_data_lfe_ch; + Word32 data_lfe_ch_fx[L_FRAME48k]; + float max_val = 0; + + for (int i = 0; i < input_frame; i++) { + if (max_val < (float)fabs(data_f[LFE_CHANNEL][i])) + max_val = (float)fabs(data_f[LFE_CHANNEL][i]); + } + + if ((Word32)max_val == 0) + q_data_lfe_ch = 31; + else + q_data_lfe_ch = norm_l((Word32)max_val); + + + for (int i = 0; i < input_frame; i++) { + data_lfe_ch_fx[i] = (Word32)(data_f[LFE_CHANNEL][i] * (1 << q_data_lfe_ch)); + } + + ivas_lfe_enc_fx(st_ivas->hLFE, data_lfe_ch_fx, q_data_lfe_ch, input_frame, st_ivas->hLFE->hBstr); +#else + ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr ); +#endif // IVAS_FLOAT_FIXED if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK ) { diff --git a/lib_enc/ivas_lfe_enc.c b/lib_enc/ivas_lfe_enc.c index 2995d6733..b36d349cb 100644 --- a/lib_enc/ivas_lfe_enc.c +++ b/lib_enc/ivas_lfe_enc.c @@ -39,6 +39,13 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "prot_fx1.h" +#include "prot_fx2.h" +#include "ivas_prot_fx.h" +#endif // IVAS_FLOAT_FIXED + + /*-----------------------------------------------------------------------------------------* * Function ivas_lfe_arith_coding() @@ -313,6 +320,308 @@ static void ivas_lfe_enc_quant( } +#ifdef IVAS_FLOAT_FIXED + +static void ivas_lfe_enc_quant_fx( + LFE_ENC_HANDLE hLFE, + Word32 *pLfe_dct, + Word16 q_pLfe_dct, + BSTR_ENC_HANDLE hBstr ) +{ + Word16 bits_written; + Word16 nb_ind_tot; + UWord16 quant_strategy, write_bit; + Word16 num_quant_strategies; + Word16 shift_bits; + Word16 values[IVAS_LFE_MAX_NUM_DCT_COEFFS << 1]; + Word32 temp_lfe_dct[IVAS_LFE_MAX_NUM_DCT_COEFFS]; + Word16 target_bits; + Word16 base2_num_bits_tot; + Word16 coding_strategy; + Word16 bits_written_arith_enc; + Word16 next_ind_pos_arith_enc; + Word16 num_ele_per_grp = IVAS_LFE_NUM_COEFFS_IN_SUBGRP << 1; + move16(); + + target_bits = (Word16) ( IVAS_LFE_BITRATE_5000 / FRAMES_PER_SEC ); + move16(); + + write_bit = 0; + move16(); + num_quant_strategies = IVAS_MAX_NUM_QUANT_STRATS; + move16(); + shift_bits = IVAS_LFE_SHIFT_BITS; + move16(); + bits_written = hBstr->nb_bits_tot; + move16(); + nb_ind_tot = hBstr->nb_ind_tot; + move16(); + + + FOR( quant_strategy = 0; quant_strategy < num_quant_strategies; quant_strategy++ ) + { + Word16 q_tmp, q_res_e, q_lfe_abs_sum; + Word32 tmp; + Word64 lfe_abs_sum; + Word16 num_dct_pass_bins; + Word16 max_of_vals, num_groups; + Word16 shift; + UWord16 min_shift, i, j; + UWord16 max_shift; + UWord16 max_value, num_lfe_ele; + UWord16 all_zeros_dct; + + q_lfe_abs_sum = q_pLfe_dct; + move16(); + lfe_abs_sum = 0; + move64(); + coding_strategy = 0; + move16(); + num_dct_pass_bins = ivas_lfe_num_dct_pass_bins_tbl[quant_strategy]; + move16(); + max_of_vals = 0; + move16(); + num_groups = shr( num_dct_pass_bins, 1 ); + shift = 0; + move16(); + min_shift = ivas_lfe_min_shift_tbl[quant_strategy]; + move16(); + max_shift = (UWord16) L_add( min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE, sub( shl( 1, shift_bits ), 1 ) ); + num_lfe_ele = num_dct_pass_bins * IVAS_LFE_NUM_COEFFS_IN_SUBGRP; + move16(); + all_zeros_dct = 0; + move16(); + max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][0]; + move16(); + + Copy32( &pLfe_dct[IVAS_LFE_MAX_NUM_DCT_PASS_BINS], &pLfe_dct[num_dct_pass_bins], num_dct_pass_bins ); + + FOR( i = 0; i < num_groups; i++ ) + { + temp_lfe_dct[4 * i] = pLfe_dct[2 * i]; + move32(); + lfe_abs_sum = W_add( lfe_abs_sum, abs( temp_lfe_dct[4 * i] ) ); + temp_lfe_dct[4 * i + 1] = pLfe_dct[2 * i + 1]; + move32(); + lfe_abs_sum = W_add( lfe_abs_sum, abs( temp_lfe_dct[4 * i + 1] ) ); + + temp_lfe_dct[4 * i + 2] = pLfe_dct[2 * i + num_dct_pass_bins]; + move32(); + lfe_abs_sum = W_add( lfe_abs_sum, abs( temp_lfe_dct[4 * i + 2] ) ); + temp_lfe_dct[4 * i + 3] = pLfe_dct[2 * i + num_dct_pass_bins + 1]; + move32(); + lfe_abs_sum = W_add( lfe_abs_sum, abs( temp_lfe_dct[4 * i + 3] ) ); + } + + IF( LE_64( lfe_abs_sum, W_shr( IVAS_LFE_ABS_SUM_FLT_THR_Q42, sub( 42, q_pLfe_dct ) ) ) ) + { + shift = max_shift; + move16(); + } + ELSE + { + q_tmp = W_norm( lfe_abs_sum ); + IF( LT_16( q_tmp, 32 ) ) + { + q_tmp = sub( 32, q_tmp ); + lfe_abs_sum = W_shr( lfe_abs_sum, q_tmp ); + q_lfe_abs_sum = sub( q_lfe_abs_sum, q_tmp ); + } + + tmp = BASOP_Util_Divide3232_Scale( max_value, W_extract_l( lfe_abs_sum ), &q_tmp ); + tmp = L_shl( tmp, sub( q_lfe_abs_sum, sub( 15, q_tmp ) ) ); /* Q0 (max_value / lfe_abs_sum) */ + + /* log2_f(max_value / lfe_abs_sum) -> Q25 */ + tmp = BASOP_Util_Log2( tmp ); + tmp = L_add( tmp, 1040187392 ) /* (31<<25) -> 1040187392 */; /* Q25 */ + + /* IVAS_LFE_SHIFTS_PER_DOUBLE * log2_f(max_value / lfe_abs_sum) */ + tmp = Mpy_32_16_1( tmp, IVAS_LFE_SHIFTS_PER_DOUBLE ); /* 25-15 -> Q10 */ + + shift = extract_l( L_shr( tmp, 10 ) ); /* Q0 */ + } + + shift = max( min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE, min( max_shift, shift ) ); + move16(); + + WHILE( 1 ) + { + IF( EQ_32( shift, max_shift ) ) + { + /* write all LFE bits as 0 */ + all_zeros_dct = 1; + move16(); + BREAK; + } + ELSE + { + max_of_vals = 0; + move16(); + FOR( i = 0; i < num_lfe_ele; i++ ) + { + tmp = BASOP_Util_Divide1616_Scale( shift, IVAS_LFE_SHIFTS_PER_DOUBLE, &q_tmp ); /*Q = 15 - q_tmp*/ + q_tmp = sub( 15, q_tmp ); + + tmp = BASOP_util_Pow2( tmp, sub( 31, q_tmp ), &q_res_e ); + q_tmp = sub( 31, q_res_e ); + + tmp = Mpy_32_32( temp_lfe_dct[i], tmp ); /* q_tmp + q_pLfe_dct - 31 */ + q_tmp = sub( add( q_tmp, q_pLfe_dct ), 31 ); + + IF( LT_32( tmp, 0 ) ) + { + values[i] = add( extract_l( L_shr( L_sub( tmp, L_shl( 1 /*0.5 Q1-> 1*/, sub( q_tmp, 1 ) ) ), q_tmp ) ), 1 ); + move16(); + } + ELSE + { + values[i] = extract_l( L_shr( L_add( tmp, L_shl( 1 /*0.5 Q1-> 1*/, sub( q_tmp, 1 ) ) ), q_tmp ) ); + move16(); + } + + IF( LT_32( max_of_vals, abs( values[i] ) ) ) + { + max_of_vals = (Word16) abs( values[i] ); + move16(); + } + } + } + IF( LE_32( max_of_vals, max_value ) ) + { + BREAK; + } + shift = sub( shift, 1 ); + } + + IF( LT_32( shift, min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE ) ) + { + CONTINUE; + } + + IF( NE_32( all_zeros_dct, 1 ) ) + { + push_next_indice( hBstr, all_zeros_dct, 1 ); + push_next_indice( hBstr, quant_strategy, 1 ); + push_next_indice( hBstr, (UWord16) L_sub( shift, min_shift * IVAS_LFE_SHIFTS_PER_DOUBLE ), shift_bits ); + } + ELSE + { + push_next_indice( hBstr, all_zeros_dct, 1 ); + hLFE->lfe_bits = sub( hBstr->nb_bits_tot, bits_written ); + return; + } + + FOR( i = 0; i < num_lfe_ele; i++ ) + { + IF( LT_16( values[i], 0 ) ) + { + write_bit = 1; + move16(); + values[i] = add( values[i], 1 ); + } + ELSE + { + write_bit = 0; + move16(); + } + + values[i] = (Word16) abs( values[i] ); + move16(); + + push_next_indice( hBstr, write_bit, 1 ); + } + + bits_written_arith_enc = hBstr->nb_bits_tot; + move16(); + next_ind_pos_arith_enc = hBstr->nb_ind_tot; + move16(); + push_next_indice( hBstr, coding_strategy, 1 ); + base2_num_bits_tot = sub( hBstr->nb_bits_tot, bits_written ); + + ivas_lfe_arith_coding( hLFE, hBstr, quant_strategy, values ); + + FOR( i = 0; i < num_groups; i++ ) + { + Word16 base2_num_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i]; + move16(); + base2_num_bits_tot = extract_l( L_add( base2_num_bits_tot, L_mult0( num_ele_per_grp, base2_num_bits ) ) ); + } + + IF( LT_16( base2_num_bits_tot, sub( hBstr->nb_bits_tot, bits_written ) ) ) + { + test(); + IF( EQ_32( quant_strategy, sub( num_quant_strategies, 1 ) ) || GE_16( add( target_bits, IVAS_LFE_ID_BITS ), base2_num_bits_tot ) ) + { + /* reset bits buffer and code the indices with base 2 coding */ + FOR( j = hBstr->nb_ind_tot - 1; j >= next_ind_pos_arith_enc; j-- ) + { + hBstr->ind_list[j].nb_bits = -1; + move16(); + } + hBstr->nb_ind_tot = next_ind_pos_arith_enc; + move16(); + hBstr->nb_bits_tot = bits_written_arith_enc; + move16(); + coding_strategy = 1; + move16(); + push_next_indice( hBstr, coding_strategy, 1 ); + + FOR( i = 0; i < num_groups; i++ ) + { + Word16 base2_write_bits = hLFE->lfe_enc_indices_coeffs_tbl[quant_strategy][i]; + move16(); + Word16 offset = 4 * i; + move16(); + max_value = ivas_lfe_num_ele_in_coder_models[quant_strategy][i]; + move16(); + + FOR( j = 0; j < num_ele_per_grp; j++ ) + { + IF( values[L_add( j, offset )] > max_value ) + { + values[L_add( j, offset )] = max_value; + move16(); + } + push_next_indice( hBstr, values[j + offset], base2_write_bits ); + } + } + BREAK; + } + } + ELSE + { + IF( GE_16( add( target_bits, IVAS_LFE_ID_BITS ), sub( hBstr->nb_bits_tot, bits_written ) ) ) + { + BREAK; + } + ELSE + { + IF( LT_32( quant_strategy, sub( num_quant_strategies, 1 ) ) ) + { + FOR( j = hBstr->nb_ind_tot - 1; j >= nb_ind_tot; j-- ) + { + hBstr->ind_list[j].nb_bits = -1; + move16(); + } + + hBstr->nb_bits_tot = bits_written; + move16(); + hBstr->nb_ind_tot = nb_ind_tot; + move16(); + } + } + } + } + + /* bits spent for LFE coding */ + hLFE->lfe_bits = sub( hBstr->nb_bits_tot, bits_written ); + + return; +} + +#endif // IVAS_FLOAT_FIXED + + /*-----------------------------------------------------------------------------------------* * Function ivas_lfe_enc() * @@ -361,6 +670,110 @@ void ivas_lfe_enc( return; } +#ifdef IVAS_FLOAT_FIXED + +void ivas_lfe_enc_fx( + LFE_ENC_HANDLE hLFE, /* i/o: LFE encoder handle */ + Word32 data_lfe_ch[], /* i : input LFE signal */ + Word16 q_data_lfe_ch, /* i : Q of input LFE signal */ + const Word16 input_frame, /* i : input frame length per channel */ + BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ +) +{ + Word32 t_audio_fx[L_FRAME48k]; + Word32 wtda_audio_fx[L_FRAME48k]; + Word32 lfe_dct_fx[IVAS_LFE_MAX_NUM_DCT_COEFFS]; + Word16 num_dct_pass_bins; + Word16 fade_len, full_len, dct_len, zero_pad_len; + Word16 q_out1, q_out2, q_tmp1, q_tmp2; + const Word32 *pWindow_coeffs_fx; + + /* Initializations */ + num_dct_pass_bins = IVAS_LFE_MAX_NUM_DCT_PASS_BINS; + move16(); + fade_len = hLFE->pWindow_state->fade_len; + move16(); + full_len = hLFE->pWindow_state->full_len; + move16(); + dct_len = hLFE->pWindow_state->dct_len; + move16(); + zero_pad_len = hLFE->pWindow_state->zero_pad_len; + move16(); + + pWindow_coeffs_fx = hLFE->pWindow_state->pWindow_coeffs_fx; + + + IF( LT_16( q_data_lfe_ch, hLFE->q_old_wtda_audio ) ) + { + Scale_sig32( hLFE->old_wtda_audio_fx, fade_len, sub( q_data_lfe_ch, hLFE->q_old_wtda_audio ) ); + hLFE->q_old_wtda_audio = q_data_lfe_ch; + move16(); + } + + IF( GT_16( q_data_lfe_ch, hLFE->q_old_wtda_audio ) ) + { + Scale_sig32( data_lfe_ch, input_frame, sub( hLFE->q_old_wtda_audio, q_data_lfe_ch ) ); + q_data_lfe_ch = hLFE->q_old_wtda_audio; + move16(); + } + + + /* Windowing */ + ivas_dct_windowing_fx( fade_len, full_len, dct_len, zero_pad_len, pWindow_coeffs_fx, input_frame, wtda_audio_fx, hLFE->old_wtda_audio_fx, data_lfe_ch ); + + q_out1 = Find_Max_Norm32( wtda_audio_fx, input_frame ); + q_out1 = sub( q_out1, find_guarded_bits_fx( dct_len ) ); + Scale_sig32( wtda_audio_fx, input_frame, q_out1 ); + q_out1 = add( q_data_lfe_ch, q_out1 ); + + ivas_mdct_fx( wtda_audio_fx, t_audio_fx, dct_len, &q_out1 ); + + Copy32( t_audio_fx, lfe_dct_fx, num_dct_pass_bins ); + + /* windowing */ + ivas_dct_windowing_fx( fade_len, full_len, dct_len, zero_pad_len, pWindow_coeffs_fx, input_frame, wtda_audio_fx, hLFE->old_wtda_audio_fx, data_lfe_ch + dct_len ); + + /* mdct */ + q_out2 = Find_Max_Norm32( wtda_audio_fx, input_frame ); + q_out2 = sub( q_out2, find_guarded_bits_fx( dct_len ) ); + Scale_sig32( wtda_audio_fx, input_frame, q_out2 ); + q_out2 = add( q_data_lfe_ch, q_out2 ); + ivas_mdct_fx( wtda_audio_fx, t_audio_fx, dct_len, &q_out2 ); + + Copy32( t_audio_fx, lfe_dct_fx + num_dct_pass_bins, num_dct_pass_bins ); + + q_tmp1 = Find_Max_Norm32( lfe_dct_fx, num_dct_pass_bins ); + q_tmp2 = Find_Max_Norm32( lfe_dct_fx + num_dct_pass_bins, num_dct_pass_bins ); + + IF( GT_16( q_out1, q_out2 ) ) + { + Scale_sig32( lfe_dct_fx + num_dct_pass_bins, num_dct_pass_bins, min( q_tmp2, sub( q_out1, q_out2 ) ) ); + q_out2 = add( q_out2, min( q_tmp2, sub( q_out1, q_out2 ) ) ); + IF( GT_16( q_out1, q_out2 ) ) + { + Scale_sig32( lfe_dct_fx, num_dct_pass_bins, sub( q_out2, q_out1 ) ); + q_out1 = q_out2; + move16(); + } + } + ELSE IF( LT_16( q_out1, q_out2 ) ) + { + Scale_sig32( lfe_dct_fx, num_dct_pass_bins, min( q_tmp1, sub( q_out2, q_out1 ) ) ); + q_out1 = add( q_out1, min( q_tmp1, sub( q_out2, q_out1 ) ) ); + IF( LT_16( q_out1, q_out2 ) ) + { + Scale_sig32( lfe_dct_fx + num_dct_pass_bins, num_dct_pass_bins, sub( q_out1, q_out2 ) ); + q_out1 = q_out2; + move16(); + } + } + + ivas_lfe_enc_quant_fx( hLFE, lfe_dct_fx, q_out1, hBstr ); + + return; +} + +#endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * ivas_create_lfe_enc() @@ -405,6 +818,17 @@ ivas_error ivas_create_lfe_enc( set_zero( hLFE->old_wtda_audio, NS2SA( input_Fs, IVAS_LFE_FADE_NS ) ); +#ifdef IVAS_FLOAT_FIXED + if ((hLFE->old_wtda_audio_fx = (Word32 *)malloc(sizeof(hLFE->old_wtda_audio_fx[0]) * NS2SA(input_Fs, IVAS_LFE_FADE_NS))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for LFE memory\n")); + } + + set32_fx(hLFE->old_wtda_audio_fx, 0, NS2SA(input_Fs, IVAS_LFE_FADE_NS)); + hLFE->q_old_wtda_audio = 31; +#endif // IVAS_FLOAT_FIXED + + /*-----------------------------------------------------------------* * LFE Window: allocate and initialize *-----------------------------------------------------------------*/ @@ -462,6 +886,15 @@ void ivas_lfe_enc_close( free( ( *hLFE )->old_wtda_audio ); ( *hLFE )->old_wtda_audio = NULL; } + +#ifdef IVAS_FLOAT_FIXED + if ((*hLFE)->old_wtda_audio_fx != NULL) + { + free((*hLFE)->old_wtda_audio_fx); + (*hLFE)->old_wtda_audio_fx = NULL; + } +#endif // IVAS_FLOAT_FIXED + if ( ( *hLFE )->pWindow_state ) { free( ( *hLFE )->pWindow_state ); diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 789c5a27f..37742b73f 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -1345,6 +1345,10 @@ typedef struct ivas_lfe_enc_data_structure int16_t lfe_enc_indices_coeffs_tbl[IVAS_MAX_NUM_QUANT_STRATS][IVAS_MAX_NUM_DCT_COEF_GROUPS]; int16_t lfe_bits; float *old_wtda_audio; +#ifdef IVAS_FLOAT_FIXED + Word32 *old_wtda_audio_fx; + Word16 q_old_wtda_audio; +#endif // IVAS_FLOAT_FIXED } LFE_ENC_DATA, *LFE_ENC_HANDLE; diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 5ef07cc1a..9c5a3bae5 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -867,8 +867,8 @@ static void EncodeSWBSubbands_fx( Word16 *prev_frm_index_fx, /* i : clas information */ const Word16 har_bands_fx, /* i/o: Index of the previous Frame */ const Word16 *subband_search_offset_fx, /* i : Number of harmonic LF bands */ - Word16 *prev_frm_hfe2_fx, /* i/o: */ - Word16 *prev_stab_hfe2_fx, /* i/o: */ + Word16 *prev_frm_hfe2, /* i/o: */ + Word16 *prev_stab_hfe2, /* i/o: */ const Word16 band_width_fx[], /* i : band width */ const Word32 L_spectra_ni[], /* i : Qs noise injected spectra */ Word16 *ni_seed_fx /* i/o: random seed */ @@ -914,7 +914,7 @@ static void EncodeSWBSubbands_fx( IF(EQ_16(hqswb_clas_fx, HQ_HARMONIC)) { - pos_max_hfe2 = har_est_fx(L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2_fx, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2_fx); + pos_max_hfe2 = har_est_fx(L_spectra, fLenLow_fx, &har_freq_est1, &har_freq_est2, &flag_dis, prev_frm_hfe2, subband_search_offset_fx, sbWidth_fx, prev_stab_hfe2); noise_extr_corcod_fx(L_spectra, L_spectra_ni, sspectra_fx, sspectra_diff_fx, sspectra_ni_fx, fLenLow_fx, hHQ_core->prev_hqswb_clas, &hHQ_core->prev_ni_ratio_fx, &Qss); /* Find best indices for each group */ getswbindices_har_fx( @@ -931,7 +931,7 @@ static void EncodeSWBSubbands_fx( IF(flag_dis == 0) { test(); - if (NE_16(har_freq_est2, SWB_HAR_RAN1) || NE_16(har_freq_est2, *prev_frm_hfe2_fx)) + if (NE_16(har_freq_est2, SWB_HAR_RAN1) || NE_16(har_freq_est2, *prev_frm_hfe2)) { har_freq_est2 = add(har_freq_est2, lagIndices_fx[0]); move16(); @@ -950,12 +950,12 @@ static void EncodeSWBSubbands_fx( IF(flag_dis == 0) { - *prev_frm_hfe2_fx = 0; + *prev_frm_hfe2 = 0; move16(); } ELSE { - *prev_frm_hfe2_fx = har_freq_est2; + *prev_frm_hfe2 = har_freq_est2; move16(); } diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index e6a656414..31ab5a3e1 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -2123,12 +2123,6 @@ static ivas_error ivas_shoebox_data_init( hShoeboxData->size[i] = 0; move16(); } -#if 1/*To be removed later:floating point initialization*/ - FOR ( i = 0; i < 150; i++ ) - { - hShoeboxData->data[i] = 0.0f; - } -#endif return IVAS_ERR_OK; } #else @@ -2274,19 +2268,6 @@ static ivas_error ivas_shoebox_config_init_params( hShoeboxConfig->list_orig_fx[i] = 0; move32(); } -#if 1/*To be removed later :floating point initializations*/ - hShoeboxConfig->room_L = 0.0f; - hShoeboxConfig->room_W = 0.0f; - hShoeboxConfig->room_H = 0.0f; - FOR ( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ ) - { - hShoeboxConfig->abs_coeff[i] = 0.0f; - } - FOR ( i = 0; i < 3; i++ ) - { - hShoeboxConfig->list_orig[i] = 0.0f; - } -#endif return IVAS_ERR_OK; } #else @@ -2383,24 +2364,7 @@ static ivas_error ivas_shoebox_obj_init( { return error; } -#if 1/*To be removed later: Floating point initializations*/ - FOR ( i = 0; i < 75; i++ ) - { - hShoeboxObj->src_pos[i] = 0.0f; - } - FOR ( i = 0; i < 25; i++ ) - { - hShoeboxObj->src_dist[i] = 0.0f; - } - FOR ( i = 0; i < 3; i++ ) - { - hShoeboxObj->list_pos[i] = 0.0f; - } - hShoeboxObj->radius = 0.0f; - hShoeboxObj->min_wall_dist = 0.0f; - hShoeboxObj->soundspeed = 0.0f; - hShoeboxObj->air_coeff = 0.0f; -#endif + return IVAS_ERR_OK; } #else @@ -2514,17 +2478,6 @@ static ivas_error ivas_er_init_handle( { return error; } -#if 1 - reflections->output_Fs = 0.0f; - FOR ( i = 0; i < 75; i++ ) - { - reflections->source_positions[i] = 0.0f; - } - FOR ( i = 0; i < 3; i++ ) - { - reflections->user_origin[i] = fixedToFloat( reflections->user_origin_fx[i], Q22 ); - } -#endif return IVAS_ERR_OK; } #else @@ -2914,7 +2867,11 @@ ivas_error ivas_rend_openCrend( hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity; /* Set sample rate and frame size */ +#ifndef IVAS_FLOAT_FIXED hCrend->reflections->output_Fs = (float) output_Fs; +#else + hCrend->reflections->output_Fs_fx = (Word32) output_Fs; +#endif hCrend->reflections->max_frame_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ); #ifdef IVAS_FLOAT_FIXED hRendCfg->roomAcoustics.dimensions.x_fx = hRendCfg->roomAcoustics.dimensions.x * 4194304; // Q10.22, min value:1, max :999.0 diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index c0ce7af10..eb3ce6ccf 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -99,6 +99,10 @@ static void ivas_dirac_dec_binaural_internal( Decoder_Struct *st_ivas, COMBINED_ static void ivas_dirac_dec_decorrelate_slot( DIRAC_DEC_BIN_HANDLE hDiracDecBin, const int16_t num_freq_bands, const int16_t slot, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float decRe[][CLDFB_NO_CHANNELS_MAX], float decIm[][CLDFB_NO_CHANNELS_MAX] ); +#ifdef IVAS_FLOAT_FIXED +static void ivas_dirac_dec_decorrelate_slot_fx(DIRAC_DEC_BIN_HANDLE hDiracDecBin, const Word16 num_freq_bands, const Word16 slot, Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 q_inp, Word32 decRe[][CLDFB_NO_CHANNELS_MAX], Word32 decIm[][CLDFB_NO_CHANNELS_MAX]); +#endif + static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked, const MASA_ISM_DATA_HANDLE hMasaIsmData ); static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked, const int16_t nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData ); @@ -1266,6 +1270,65 @@ static void ivas_dirac_dec_decorrelate_slot( return; } +#ifdef IVAS_FLOAT_FIXED +static void ivas_dirac_dec_decorrelate_slot_fx( + DIRAC_DEC_BIN_HANDLE hDiracDecBin, + const Word16 num_freq_bands, + const Word16 slot, + Word32 inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word16 q_inp, + Word32 decRe[][CLDFB_NO_CHANNELS_MAX], + Word32 decIm[][CLDFB_NO_CHANNELS_MAX] ) +{ + Word16 offset, ch, bin; + Word32 onset_filter_fx[BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, 60 bins */ + Word32 decorrelatedFrameInterleaved_fx[2 * BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, real + imag, 60 bins */ + Word32 protoFrame_fx[2 * BINAURAL_CHANNELS * CLDFB_NO_CHANNELS_MAX]; /* 2 ch, real + imag, 60 bins */ + Word16 q_decorrelatedFrameInterleaved, q_protoFrame; + const Word16 protoIndexDir[BINAURAL_CHANNELS] = { 0, 1 }; + q_protoFrame = q_inp; + /* Decorrelation needs interleaved data. Copy left and right signals to proto_frame_f */ + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + offset = imult1616( imult1616( num_freq_bands, BINAURAL_CHANNELS ), ch ); + FOR( bin = 0; bin < num_freq_bands; bin++ ) + { + protoFrame_fx[( bin * BINAURAL_CHANNELS ) + offset] = inRe[ch][slot][bin]; + protoFrame_fx[( bin * BINAURAL_CHANNELS ) + offset + 1] = inIm[ch][slot][bin]; + } + } + + /* Decorrelate proto signal to decorrelatedFrameInterleaved */ + ivas_dirac_dec_decorr_process_fx( num_freq_bands, + BINAURAL_CHANNELS, + BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, + BINAURAL_CHANNELS, + protoFrame_fx, + q_protoFrame, + BINAURAL_CHANNELS, + protoIndexDir, + decorrelatedFrameInterleaved_fx, + &q_decorrelatedFrameInterleaved, + onset_filter_fx, + hDiracDecBin->h_freq_domain_decorr_ap_params, + hDiracDecBin->h_freq_domain_decorr_ap_state ); + + /* De-interleave decorrelated signals*/ + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + offset = num_freq_bands * BINAURAL_CHANNELS * ch; + FOR( bin = 0; bin < num_freq_bands; bin++ ) + { + decRe[ch][bin] = decorrelatedFrameInterleaved_fx[( bin * BINAURAL_CHANNELS ) + offset]; + decIm[ch][bin] = decorrelatedFrameInterleaved_fx[( bin * BINAURAL_CHANNELS ) + offset + 1]; + } + } + //q_decorrelatedFrameInterleaved will be same as q_inp/q_protoFrame // + return; +} +#endif static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, @@ -2006,7 +2069,35 @@ static void ivas_dirac_dec_binaural_process_output( interpVal += 1.0f / (float) nSlots; if ( !hDiracDecBin->useTdDecorr && max_band_decorr > 0 ) { - ivas_dirac_dec_decorrelate_slot( hDiracDecBin, nBins, slot, inRe, inIm, decSlotRe, decSlotIm ); +#ifdef IVAS_FLOAT_FIXED + Word16 q_inp; + //q_inp = Q6;// fixed Q6 giving high distortion in o/p// + Word32 decSlotRe_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX], decSlotIm_fx[BINAURAL_CHANNELS][CLDFB_NO_CHANNELS_MAX]; + Word32 inRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], inIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word16 q_inp_1 = s_min(Q_factor_arrL(inRe[0][slot], nBins), Q_factor_arrL(inIm[0][slot], nBins)); + Word16 q_inp_2 = s_min(Q_factor_arrL(inRe[1][slot], nBins), Q_factor_arrL(inIm[1][slot], nBins)); + q_inp = s_min(q_inp_1, q_inp_2); + FOR(Word16 cha = 0; cha < BINAURAL_CHANNELS; cha++) + { + FOR(Word16 ind = 0; ind < nBins; ind++) + { + inRe_fx[cha][slot][ind] = float_to_fix(inRe[cha][slot][ind], q_inp); + inIm_fx[cha][slot][ind] = float_to_fix(inIm[cha][slot][ind], q_inp); + } + } + ivas_dirac_dec_decorrelate_slot_fx( hDiracDecBin, nBins, slot, inRe_fx, inIm_fx, q_inp, decSlotRe_fx, decSlotIm_fx); + FOR (Word16 ch_t = 0; ch_t < BINAURAL_CHANNELS; ch_t++) + { + FOR (Word16 bin_t = 0; bin_t < nBins; bin_t++) + { + decSlotRe[ch_t][bin_t] = fix_to_float(decSlotRe_fx[ch_t][bin_t],q_inp); + decSlotIm[ch_t][bin_t] = fix_to_float(decSlotIm_fx[ch_t][bin_t], q_inp); + } + } + +#else + ivas_dirac_dec_decorrelate_slot(hDiracDecBin, nBins, slot, inRe, inIm, decSlotRe, decSlotIm); +#endif } for ( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) diff --git a/lib_rend/ivas_dirac_decorr_dec.c b/lib_rend/ivas_dirac_decorr_dec.c index d070205aa..f50aeb074 100644 --- a/lib_rend/ivas_dirac_decorr_dec.c +++ b/lib_rend/ivas_dirac_decorr_dec.c @@ -53,7 +53,11 @@ #define DIRAC_DUCK_ALPHA 0.8f #define DIRAC_DUCK_GAMMA 1.5f - +#ifdef IVAS_FLOAT_FIXED +#define DIRAC_DUCK_GAMMA_FX 1610612736 // Q30 +#define DIRAC_DUCK_ALPHA_FX 1717986944 //Q31 +#define ONE_M_DIRAC_DUCK_ALPHA 429496736 //Q31 +#endif /*------------------------------------------------------------------------- * Local function prototypes @@ -586,11 +590,12 @@ ivas_error ivas_dirac_dec_decorr_open_fx( set_f( freq_domain_decorr_ap_state->direct_energy_smooth, 0.0f, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); set_f( freq_domain_decorr_ap_state->reverb_energy_smooth, 0.0f, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); #endif - IF( ( freq_domain_decorr_ap_state->decorr_buffer_fx = (Word16 *) malloc( sizeof( Word16 ) * 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ) ) == NULL ) + IF( ( freq_domain_decorr_ap_state->decorr_buffer_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } - set16_fx( freq_domain_decorr_ap_state->decorr_buffer_fx, 0, 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ); + set32_fx( freq_domain_decorr_ap_state->decorr_buffer_fx, 0, 2 * buffer_size_decorr * num_outputs_diff * freq_domain_decorr_ap_params->max_band_decorr ); + freq_domain_decorr_ap_state->q_decorr_buffer = Q31; IF( ( freq_domain_decorr_ap_params->filter_coeff_num_real_fx = (Word16 *) malloc( sizeof( Word16 ) * ( ap_filter_length[split_band_index_start] + 1 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) { @@ -612,17 +617,18 @@ ivas_error ivas_dirac_dec_decorr_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } - IF( ( freq_domain_decorr_ap_state->direct_energy_smooth_fx = (Word16 *) malloc( sizeof( Word16 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + IF( ( freq_domain_decorr_ap_state->direct_energy_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } - IF( ( freq_domain_decorr_ap_state->reverb_energy_smooth_fx = (Word16 *) malloc( sizeof( Word16 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) + IF( ( freq_domain_decorr_ap_state->reverb_energy_smooth_fx = (Word32 *) malloc( sizeof( Word32 ) * freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD decorrelator\n" ) ); } - set16_fx( freq_domain_decorr_ap_state->direct_energy_smooth_fx, 0, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); - set16_fx( freq_domain_decorr_ap_state->reverb_energy_smooth_fx, 0, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); + set32_fx( freq_domain_decorr_ap_state->direct_energy_smooth_fx, 0, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); + set32_fx( freq_domain_decorr_ap_state->reverb_energy_smooth_fx, 0, freq_domain_decorr_ap_params->max_band_decorr * num_outputs_diff ); + freq_domain_decorr_ap_state->q_direct_energy_smooth = freq_domain_decorr_ap_state->q_reverb_energy_smooth = Q31; /* compute filter coefficients */ FOR ( k = 0; k < freq_domain_decorr_ap_params->num_split_frequency_bands; k++ ) @@ -971,6 +977,462 @@ void ivas_dirac_dec_decorr_process( return; } +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_decorr_process_fx( + const Word16 num_freq_bands, + Word16 num_channels, + const Word16 num_protos_diff, + const DIRAC_SYNTHESIS_CONFIG synthesisConf, + const Word16 nchan_transport, /* i : number of transport channels*/ + const Word32 *input_frame_fx, + Word16 q_input_frame, + const Word16 num_protos_dir, + const Word16 *proto_index_dir, + Word32 *frame_dec_fx, + Word16 *q_frame_dec, + Word32 *onset_filter_fx, + HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params, + HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state ) +{ + + Word16 ch_idx, k, l, idx_in_out, max_band_decorr; + Word16 split_bands_idx, band_idx, decorr_buffer_len, time_idx; + Word16 offset, idx_filter, incr_aux; + Word16 k_1, k_2, num_bands, filter_length, pre_delay, decorr_buffer_step; + Word32 aux_buffer_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; + Word32 direct_energy_fx[MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; + Word32 frame_ma_fx[2 * ( DIRAC_MAX_DECORR_FILTER_LEN + 1 )]; + Word32 *p_frame_dec_fx, *decorr_buffer_fx; + Word16 *phase_coeff_real_fx, *phase_coeff_imag_fx; + Word16 *filter_coeff_num_real_fx, *filter_coeff_den_real_fx; + Word32 *decorr_buffer_start_ptr_fx, *decorr_buffer_ptr_fx; + Word32 input_real_fx, input_imag_fx, filter_frame_imag_fx, filter_frame_real_fx; + Word16 q_aux_buffer, q_onset_dec, q_frame_f; + + push_wmops( "dirac_decorr_process" ); + + /* check handles */ + IF( h_freq_domain_decorr_ap_params == NULL || h_freq_domain_decorr_ap_state == NULL ) + { + return; + } + + /* check input data */ + IF( input_frame_fx == NULL ) + { + return; + } + + /* check result arrays */ + IF( frame_dec_fx == NULL ) + { + return; + } + + + /*-----------------------------------------------------------------* + * ********** processing ********** + *-----------------------------------------------------------------*/ + + /*-----------------------------------------------------------------* + * collect some often used parameters + *-----------------------------------------------------------------*/ + + IF( synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + num_channels = sub( num_channels, nchan_transport ); + } + + + /*-----------------------------------------------------------------* + * detect and remove onsets + *-----------------------------------------------------------------*/ + + /* compute power */ + q_onset_dec = h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector; + Word16 max_band_decorr_temp = h_freq_domain_decorr_ap_params->h_onset_detection_power_params.max_band_decorr; + + Word16 q_shift, guarded_bits; + guarded_bits = find_guarded_bits_fx( 2 ); + FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) + { + v_mult_fixed( &input_frame_fx[2 * ch_idx * num_freq_bands], &input_frame_fx[2 * ch_idx * num_freq_bands], &aux_buffer_fx[2 * ch_idx * max_band_decorr_temp], 2 * max_band_decorr_temp ); + } + q_aux_buffer = q_input_frame + q_input_frame - 31; + + q_shift = getScaleFactor32( aux_buffer_fx, 2 * num_protos_dir * max_band_decorr_temp ) - guarded_bits; + + FOR( Word16 j = 0; j < 2 * num_protos_dir * max_band_decorr_temp; j++ ) + { + aux_buffer_fx[j] = L_shl( aux_buffer_fx[j], q_shift ); + } + q_aux_buffer += q_shift; + + FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) + { + v_add_inc_fx( &aux_buffer_fx[2 * ch_idx * max_band_decorr_temp], 2, &aux_buffer_fx[2 * ch_idx * max_band_decorr_temp + 1], 2, &aux_buffer_fx[ch_idx * max_band_decorr_temp], 1, max_band_decorr_temp ); + } + /* compute onset filter */ + max_band_decorr = h_freq_domain_decorr_ap_params->max_band_decorr; + + set32_fx( onset_filter_fx, ONE_IN_Q31, num_protos_diff * num_freq_bands ); + + Word16 q_temp = s_min( q_onset_dec, q_aux_buffer ); + + IF( NE_16( q_temp, q_onset_dec ) ) + { + FOR( Word16 i = 0; i < num_protos_diff * max_band_decorr_temp; i++ ) + { + h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx[i] = L_shr( h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_2_fx[i], q_onset_dec - q_temp ); + h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx[i] = L_shr( h_freq_domain_decorr_ap_state->h_onset_detection_power_state.onset_detector_1_fx[i], q_onset_dec - q_temp ); + } + } + IF( NE_16( q_temp, q_aux_buffer ) ) + { + FOR( Word16 i = 0; i < 2 * num_protos_diff * max_band_decorr_temp; i++ ) + { + aux_buffer_fx[i] = L_shr( aux_buffer_fx[i], q_aux_buffer - q_temp ); + } + } + q_aux_buffer = q_temp; + h_freq_domain_decorr_ap_state->h_onset_detection_power_state.q_onset_detector = q_temp; + + ivas_dirac_dec_onset_detection_process_fx( aux_buffer_fx, q_aux_buffer, onset_filter_fx, num_protos_diff, h_freq_domain_decorr_ap_params->h_onset_detection_power_params, h_freq_domain_decorr_ap_state->h_onset_detection_power_state ); + // q_onset_filter is Q31// + + /* Apply decorrelator if num_channels is greater than 0 */ + IF( GT_16( num_channels, 0 ) ) + { + /* remove onsets from prototype frame */ + FOR( ch_idx = 0; ch_idx < num_protos_dir; ch_idx++ ) + { + //** this might effect when max_band_decorr is not equal to max_band_decorr_temp// + v_mult_inc_fixed( &input_frame_fx[2 * ch_idx * num_freq_bands], 2, &onset_filter_fx[ch_idx * num_freq_bands], 1, &aux_buffer_fx[2 * ch_idx * max_band_decorr], 2, max_band_decorr ); + + v_mult_inc_fixed( &input_frame_fx[2 * ch_idx * num_freq_bands + 1], 2, &onset_filter_fx[ch_idx * num_freq_bands], 1, &aux_buffer_fx[2 * ch_idx * max_band_decorr + 1], 2, max_band_decorr ); + } + q_aux_buffer = q_input_frame; + + /*-----------------------------------------------------------------* + * all pass based decorrelation + *-----------------------------------------------------------------*/ + + /* compute decorrelated output frame */ + /* output is the first frame of the state */ + decorr_buffer_len = sub( add( h_freq_domain_decorr_ap_params->filter_length[0], h_freq_domain_decorr_ap_params->pre_delay[0] ), 1 ); + Word16 q_decorr_buf = h_freq_domain_decorr_ap_state->q_decorr_buffer; + p_frame_dec_fx = frame_dec_fx; + decorr_buffer_fx = h_freq_domain_decorr_ap_state->decorr_buffer_fx; + phase_coeff_real_fx = h_freq_domain_decorr_ap_params->phase_coeff_real_fx; // Q14 + phase_coeff_imag_fx = h_freq_domain_decorr_ap_params->phase_coeff_imag_fx; // Q14 + incr_aux = imult1616( 2, sub( num_freq_bands, max_band_decorr ) ); + + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + /* final phase rotation */ + FOR( k = 0; k < max_band_decorr; k++ ) + { + *p_frame_dec_fx = L_sub( Mpy_32_16_1( ( *decorr_buffer_fx ), ( *phase_coeff_real_fx ) ), Mpy_32_16_1( ( *( decorr_buffer_fx + 1 ) ), ( *phase_coeff_imag_fx ) ) ); + p_frame_dec_fx++; + *p_frame_dec_fx = L_add( Mpy_32_16_1( ( *decorr_buffer_fx ), ( *phase_coeff_imag_fx ) ), Mpy_32_16_1( ( *( decorr_buffer_fx + 1 ) ), ( *phase_coeff_real_fx ) ) ); + p_frame_dec_fx++; + phase_coeff_imag_fx++; + phase_coeff_real_fx++; + decorr_buffer_fx += 2; + } + p_frame_dec_fx += incr_aux; + } + q_frame_f = sub( q_decorr_buf, 1 ); + /* update state */ + + FOR( time_idx = 0; time_idx < sub( decorr_buffer_len, 1 ); time_idx++ ) + { + Copy32( &h_freq_domain_decorr_ap_state->decorr_buffer_fx[2 * ( time_idx + 1 ) * max_band_decorr * num_channels], &h_freq_domain_decorr_ap_state->decorr_buffer_fx[2 * (time_idx) *max_band_decorr * num_channels], 2 * max_band_decorr * num_channels ); + } + set32_fx( &h_freq_domain_decorr_ap_state->decorr_buffer_fx[2 * ( decorr_buffer_len - 1 ) * max_band_decorr * num_channels], 0, 2 * max_band_decorr * num_channels ); + + Word16 decorr_buff_tot_len = imult1616( imult1616( shl( decorr_buffer_len, 1 ), max_band_decorr ), num_channels ); + + guarded_bits = s_max( find_guarded_bits_fx( 2 ), 3 ); + q_shift = getScaleFactor32( h_freq_domain_decorr_ap_state->decorr_buffer_fx, decorr_buff_tot_len ) - guarded_bits; + Scale_sig32( h_freq_domain_decorr_ap_state->decorr_buffer_fx, decorr_buff_tot_len, q_shift ); + q_decorr_buf = q_decorr_buf + q_shift; + + q_shift = getScaleFactor32( aux_buffer_fx, 2 * num_protos_dir * max_band_decorr_temp ); + + FOR( Word16 j = 0; j < 2 * num_protos_dir * max_band_decorr_temp; j++ ) + { + aux_buffer_fx[j] = L_shl( aux_buffer_fx[j], q_shift ); + } + q_aux_buffer += q_shift; + + // q of aux buff must be greater than 3 than decorr buffer// + IF( GE_16( q_decorr_buf, q_aux_buffer ) ) + { + Scale_sig32( h_freq_domain_decorr_ap_state->decorr_buffer_fx, decorr_buff_tot_len, negate( q_decorr_buf - q_aux_buffer + 3 ) ); + q_decorr_buf = q_decorr_buf + negate( q_decorr_buf - q_aux_buffer + 3 ); + } + ELSE + { + IF( GT_16( sub( q_aux_buffer, q_decorr_buf ), 3 ) ) + { + Scale_sig32( aux_buffer_fx, 2 * num_protos_dir * max_band_decorr_temp, negate( sub( sub( q_aux_buffer, q_decorr_buf ), 3 ) ) ); + } + ELSE + { + Scale_sig32( h_freq_domain_decorr_ap_state->decorr_buffer_fx, decorr_buff_tot_len, negate( 3 - ( q_aux_buffer - q_decorr_buf ) ) ); + q_decorr_buf = q_decorr_buf + negate( 3 - ( q_aux_buffer - q_decorr_buf ) ); + } + } + + q_aux_buffer = add( q_decorr_buf, 3 ); + + /* calculate all pass */ + FOR( split_bands_idx = 0; split_bands_idx < h_freq_domain_decorr_ap_params->num_split_frequency_bands; split_bands_idx++ ) + { + k_1 = h_freq_domain_decorr_ap_params->split_frequency_bands[split_bands_idx]; + k_2 = h_freq_domain_decorr_ap_params->split_frequency_bands[add( split_bands_idx, 1 )]; + num_bands = sub( k_2, k_1 ); + filter_length = h_freq_domain_decorr_ap_params->filter_length[split_bands_idx]; + pre_delay = h_freq_domain_decorr_ap_params->pre_delay[split_bands_idx]; + decorr_buffer_step = imult1616( num_channels, max_band_decorr ); + + FOR( k = 0; k < num_bands; ++k ) + { + band_idx = add( k_1, k ); + + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + idx_filter = add( ( imult1616( band_idx, imult1616( h_freq_domain_decorr_ap_params->filter_length[0], num_channels ) ) ), imult1616( ch_idx, h_freq_domain_decorr_ap_params->filter_length[0] ) ); + filter_coeff_num_real_fx = &h_freq_domain_decorr_ap_params->filter_coeff_num_real_fx[idx_filter]; // Q12 + filter_coeff_den_real_fx = &h_freq_domain_decorr_ap_params->filter_coeff_den_real_fx[idx_filter]; // Q12 + decorr_buffer_start_ptr_fx = &h_freq_domain_decorr_ap_state->decorr_buffer_fx[2 * ( ch_idx * max_band_decorr + band_idx )]; + input_real_fx = aux_buffer_fx[2 * ( proto_index_dir[ch_idx] * max_band_decorr + band_idx )]; // q_aux + input_imag_fx = aux_buffer_fx[2 * ( proto_index_dir[ch_idx] * max_band_decorr + band_idx ) + 1]; // q_aux + + /* MA part of filter impulse response */ + FOR( l = 0; l < filter_length; l++ ) + { + frame_ma_fx[2 * l] = Mpy_32_16_1( input_real_fx, filter_coeff_num_real_fx[l] ); // Q_qux -3 = q_deorr + // frame_ma_fx[2 * l] = L_shr(frame_ma_fx[2 * l],3); // scaling to q_decorr_buf + frame_ma_fx[2 * l + 1] = Mpy_32_16_1( input_imag_fx, filter_coeff_num_real_fx[l] ); // Q_qux - 3 = q_deorr + // frame_ma_fx[2 * l + 1] = L_shr(frame_ma_fx[2 * l + 1], 3); // scaling to q_decorr_buf + } + decorr_buffer_ptr_fx = decorr_buffer_start_ptr_fx + 2 * ( sub( pre_delay, 1 ) ) * decorr_buffer_step; + + /*add MA part to state */ + decorr_buffer_ptr_fx[0] = L_add( decorr_buffer_ptr_fx[0], frame_ma_fx[0] ); + decorr_buffer_ptr_fx[1] = L_add( decorr_buffer_ptr_fx[1], frame_ma_fx[1] ); + + /*get values for AR part */ + filter_frame_real_fx = decorr_buffer_ptr_fx[0]; // q_decorr + filter_frame_imag_fx = decorr_buffer_ptr_fx[1]; // q_deocrr + + decorr_buffer_ptr_fx += 2 * decorr_buffer_step; + + FOR( l = 1; l < filter_length; l++ ) + { + // q adjustment needed// + decorr_buffer_ptr_fx[0] = L_add( decorr_buffer_ptr_fx[0], frame_ma_fx[2 * l] ); // q_decorr + Word32 temp_1 = Mpy_32_16_1( filter_frame_real_fx, filter_coeff_den_real_fx[l] ); // q_decorr - 3 + temp_1 = L_shl( temp_1, 3 ); // q_decorr + decorr_buffer_ptr_fx[0] = L_sub( decorr_buffer_ptr_fx[0], temp_1 ); // q_deocor + decorr_buffer_ptr_fx[1] = L_add( decorr_buffer_ptr_fx[1], frame_ma_fx[2 * l + 1] ); // q_decorr + Word32 temp_2 = Mpy_32_16_1( filter_frame_imag_fx, filter_coeff_den_real_fx[l] ); // q_decorr - 3 + temp_2 = L_shl( temp_2, 3 ); // q_decorr + decorr_buffer_ptr_fx[1] = L_sub( decorr_buffer_ptr_fx[1], temp_2 ); // q_decorr + decorr_buffer_ptr_fx += imult1616( 2, decorr_buffer_step ); + } + } + } + } + h_freq_domain_decorr_ap_state->q_decorr_buffer = q_decorr_buf; + /*-----------------------------------------------------------------* + * onset/diffuse energy ratio conservation + *-----------------------------------------------------------------*/ + + Word16 q_direct_energy; + Word64 aux_64[2 * MAX_OUTPUT_CHANNELS * CLDFB_NO_CHANNELS_MAX]; + Word16 e_reverb_energy_smooth, e_direct_energy_smooth; + Word16 offset1, offset2; + Word16 norm = 63; + e_reverb_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_reverb_energy_smooth ); + e_direct_energy_smooth = sub( 31, h_freq_domain_decorr_ap_state->q_direct_energy_smooth ); + + // scaling to get max precision for aux_buffer values// + q_shift = L_norm_arr( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels ); + Scale_sig32( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels, q_shift ); + q_frame_f = add( q_frame_f, q_shift ); + + + IF( h_freq_domain_decorr_ap_params->use_ducker ) + { + /* compute direct power w/o onsets for the energy ratio, signal is still in the aux buffer */ + v_mult_fixed( aux_buffer_fx, aux_buffer_fx, aux_buffer_fx, 2 * max_band_decorr * num_protos_dir ); // 2 *q_aux -31 + + q_aux_buffer = sub( imult1616( 2, q_aux_buffer ), 31 ); + + // if this scaling is eliminated overflow is happening fot v_add_inc_fix + q_shift = L_norm_arr( aux_buffer_fx, 2 * num_protos_dir * max_band_decorr ) - find_guarded_bits_fx( 2 ); + Scale_sig32( aux_buffer_fx, 2 * num_protos_dir * max_band_decorr_temp, q_shift ); + q_aux_buffer = add( q_aux_buffer, q_shift ); + + v_add_inc_fx( &aux_buffer_fx[0], 2, &aux_buffer_fx[1], 2, direct_energy_fx, 1, imult1616( num_protos_dir, max_band_decorr ) ); + + q_direct_energy = q_aux_buffer; + + /* calculate the power of the decorrelated signal */ + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + offset1 = 2 * ch_idx * num_freq_bands; + offset2 = 2 * ch_idx * max_band_decorr; + FOR( Word16 i = 0; i < 2 * max_band_decorr; i++ ) + { + aux_64[offset2 + i] = W_mult0_32_32( frame_dec_fx[offset1 + i], frame_dec_fx[offset1 + i] ); + norm = s_min( norm, W_norm( aux_64[offset2 + i] ) ); + } + } + + FOR( Word16 i = 0; i < 2 * num_channels * max_band_decorr; i++ ) + { + aux_buffer_fx[i] = W_extract_h( W_shl( aux_64[i], norm - find_guarded_bits_fx( 2 ) ) ); + } + q_aux_buffer = add( imult1616( 2, q_frame_f ), sub( sub( norm, 1 ), 32 ) ); + + + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + v_add_inc_fx( &aux_buffer_fx[2 * ch_idx * max_band_decorr], 2, &aux_buffer_fx[2 * ch_idx * max_band_decorr + 1], 2, &aux_buffer_fx[ch_idx * max_band_decorr], 1, max_band_decorr ); + } + + /* smooth energies */ + v_multc_fixed( aux_buffer_fx, ONE_M_DIRAC_DUCK_ALPHA, aux_buffer_fx, imult1616( num_channels, max_band_decorr ) ); // q_aux_buffer + + v_multc_fixed( h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, DIRAC_DUCK_ALPHA_FX, h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616( num_channels, max_band_decorr ) ); // same-q + + v_add_fixed_me( aux_buffer_fx, 31 - q_aux_buffer, h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, e_reverb_energy_smooth, h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, &e_reverb_energy_smooth, imult1616( num_channels, max_band_decorr ), 0 ); + h_freq_domain_decorr_ap_state->q_reverb_energy_smooth = sub( 31, e_reverb_energy_smooth ); + + v_multc_fixed( direct_energy_fx, ONE_M_DIRAC_DUCK_ALPHA, direct_energy_fx, imult1616( num_protos_dir, max_band_decorr ) ); // same q + + v_multc_fixed( h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, DIRAC_DUCK_ALPHA_FX, h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616( num_protos_dir, max_band_decorr ) ); // same q + + v_add_fixed_me( direct_energy_fx, 31 - q_direct_energy, h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, e_direct_energy_smooth, h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, &e_direct_energy_smooth, imult1616( num_protos_dir, max_band_decorr ), 0 ); + h_freq_domain_decorr_ap_state->q_direct_energy_smooth = sub( 31, e_direct_energy_smooth ); + + // scaling energy buffers for better precision for higher values// + q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr)); + Scale_sig32(h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, imult1616(num_protos_dir, max_band_decorr), q_shift); + h_freq_domain_decorr_ap_state->q_direct_energy_smooth = h_freq_domain_decorr_ap_state->q_direct_energy_smooth + q_shift; + + + q_shift = L_norm_arr(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr)); + Scale_sig32(h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, imult1616(num_channels, max_band_decorr), q_shift); + h_freq_domain_decorr_ap_state->q_reverb_energy_smooth = h_freq_domain_decorr_ap_state->q_reverb_energy_smooth + q_shift; + + e_reverb_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_reverb_energy_smooth); + e_direct_energy_smooth = sub(31 , h_freq_domain_decorr_ap_state->q_direct_energy_smooth); + + // this step is b/c we are left shifting frame_dec_fx at the end of below for loop/ + q_shift = sub( L_norm_arr( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels ), 2 ); + Scale_sig32( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels, q_shift ); + q_frame_f = add( q_frame_f, q_shift ); + + FOR( ch_idx = 0; ch_idx < num_channels; ch_idx++ ) + { + Word32 *frame_dec_fx_ptr = &frame_dec_fx[ch_idx * 2 * num_freq_bands]; + Word16 cur_proto_index = imult1616( proto_index_dir[ch_idx], max_band_decorr ); + Word16 cur_reverb_index = imult1616( ch_idx, max_band_decorr ); + Word32 *reverb_energy_smooth_ptr = &h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx[cur_reverb_index]; // q_aux + Word32 *direct_energy_smooth_ptr = &h_freq_domain_decorr_ap_state->direct_energy_smooth_fx[cur_proto_index]; // Q_aux + + FOR( band_idx = 0; band_idx < max_band_decorr; band_idx++ ) + { + Word16 duck_gain = 32767, e_duck_gain = 0; + Word32 direct_energy_loc = direct_energy_smooth_ptr[band_idx]; + Word32 reverb_energy_loc = reverb_energy_smooth_ptr[band_idx]; + + Word32 temp_1 = Mpy_32_32( direct_energy_loc, DIRAC_DUCK_GAMMA_FX ); // e+1 + Word32 temp_2 = Mpy_32_32( reverb_energy_loc, DIRAC_DUCK_GAMMA_FX ); // e+1 + Word16 comp_flag_1 = BASOP_Util_Cmp_Mant32Exp( reverb_energy_loc, e_reverb_energy_smooth, temp_1, e_direct_energy_smooth + 1 ); + Word16 comp_flag_2 = BASOP_Util_Cmp_Mant32Exp( direct_energy_loc, e_direct_energy_smooth, temp_2, e_reverb_energy_smooth + 1 ); + IF( EQ_16( comp_flag_1, 1 ) ) + { + duck_gain = BASOP_Util_Divide3232_Scale( temp_1, L_add( reverb_energy_loc, EPSILON_FX ), &e_duck_gain ); + e_duck_gain = e_duck_gain + ( e_direct_energy_smooth + 1 - e_reverb_energy_smooth ); + + duck_gain = Sqrt16( duck_gain, &e_duck_gain ); + + duck_gain = shl( duck_gain, sub( e_duck_gain, 1 ) ); // Q14 + + frame_dec_fx_ptr[2 * band_idx] = L_shl( Mpy_32_16_1( frame_dec_fx_ptr[2 * band_idx], duck_gain ), 1 ); // q_frame_f + frame_dec_fx_ptr[2 * band_idx + 1] = L_shl( Mpy_32_16_1( frame_dec_fx_ptr[2 * band_idx + 1], duck_gain ), 1 ); // q_frame_f + } + ELSE IF( EQ_16( comp_flag_2, 1 ) ) + { + + duck_gain = BASOP_Util_Divide3232_Scale( direct_energy_loc, L_add( temp_2, EPSILON_FX ), &e_duck_gain ); + e_duck_gain = e_duck_gain + ( e_direct_energy_smooth - e_reverb_energy_smooth - 1 ); + + duck_gain = Sqrt16( duck_gain, &e_duck_gain ); + Word16 comp_flag = BASOP_Util_Cmp_Mant32Exp( duck_gain, e_duck_gain, 16384, 2 ); + IF( EQ_16( comp_flag, 1 ) ) + { + duck_gain = 16384; // 2inQ13 + } + ELSE + { + duck_gain = shl( duck_gain, sub( e_duck_gain, 2 ) ); // Q13 + } + frame_dec_fx_ptr[2 * band_idx] = L_shl( Mpy_32_16_1( frame_dec_fx_ptr[2 * band_idx], duck_gain ), 2 ); // q_frame_dec + frame_dec_fx_ptr[2 * band_idx + 1] = L_shl( Mpy_32_16_1( frame_dec_fx_ptr[2 * band_idx + 1], duck_gain ), 2 ); // q_frame_dec + } + } + } + } + + /*-----------------------------------------------------------------* + * add back onsets + *-----------------------------------------------------------------*/ + + q_shift = q_input_frame - q_frame_f; + Scale_sig32( frame_dec_fx, ( 2 * max_band_decorr + incr_aux ) * num_channels, q_shift ); // scaling it to input q + q_frame_f = q_input_frame; + + + IF( EQ_16( h_freq_domain_decorr_ap_params->add_back_onsets_on, 1 ) ) + { + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + offset = imult1616( proto_index_dir[ch_idx], num_freq_bands ); + + FOR( k = 0; k < max_band_decorr; ++k ) + { + aux_buffer_fx[2 * k] = Mpy_32_32( input_frame_fx[2 * offset + 2 * k], L_sub( ONE_IN_Q31, onset_filter_fx[offset + k] ) ); + aux_buffer_fx[2 * k + 1] = Mpy_32_32( input_frame_fx[2 * offset + 2 * k + 1], L_sub( ONE_IN_Q31, onset_filter_fx[offset + k] ) ); // q_input_f + } + + v_add_fx( &frame_dec_fx[ch_idx * 2 * num_freq_bands], aux_buffer_fx, &frame_dec_fx[ch_idx * 2 * num_freq_bands], 2 * max_band_decorr ); + } + } + + /* avoid decorrelation above maximum frequency -> set to zero the remaining frequencies*/ + FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) + { + /* calc output indices */ + idx_in_out = 2 * ( add( imult1616( ch_idx, num_freq_bands ), h_freq_domain_decorr_ap_params->max_band_decorr ) ); + + /* copy to output signal */ + set32_fx( &frame_dec_fx[idx_in_out], 0, 2 * sub( num_freq_bands, h_freq_domain_decorr_ap_params->max_band_decorr ) ); + } + *q_frame_dec = q_frame_f; + } /*end of decorrelator*/ + + pop_wmops(); + + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_decorr_close() @@ -980,7 +1442,7 @@ void ivas_dirac_dec_decorr_process( void ivas_dirac_dec_decorr_close( HANDLE_DIRAC_DECORR_PARAMS *ph_freq_domain_decorr_ap_params, - HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state) + HANDLE_DIRAC_DECORR_STATE *ph_freq_domain_decorr_ap_state ) { DIRAC_ONSET_DETECTION_STATE *dirac_onset_detection_state; @@ -988,7 +1450,7 @@ void ivas_dirac_dec_decorr_close( * check input handles *-----------------------------------------------------------------*/ - if (ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL) + if ( ph_freq_domain_decorr_ap_params == NULL || ph_freq_domain_decorr_ap_state == NULL ) { return; } diff --git a/lib_rend/ivas_dirac_onsets_dec.c b/lib_rend/ivas_dirac_onsets_dec.c index f8a919a06..5142488a8 100644 --- a/lib_rend/ivas_dirac_onsets_dec.c +++ b/lib_rend/ivas_dirac_onsets_dec.c @@ -50,6 +50,129 @@ * onset detection *------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static Word16 BASOP_Util_Cmp_Mant32Exp_sat(Word32 a_m, Word16 a_e, Word32 b_m, Word16 b_e); +Word16 BASOP_Util_Cmp_Mant32Exp_sat /*!< o: flag: result of comparison */ + /* 0, if a == b */ + /* 1, if a > b */ + /* -1, if a < b */ + (Word32 a_m, /*!< i: Mantissa of 1st operand a */ + Word16 a_e, /*!< i: Exponent of 1st operand a */ + Word32 b_m, /*!< i: Mantissa of 2nd operand b */ + Word16 b_e) /*!< i: Exponent of 2nd operand b */ + +{ + Word32 diff_m; + Word16 diff_e, shift, result; + + + /* + This function compares two input parameters, both represented by a 32-bit mantissa and a 16-bit exponent. + If both values are identical, 0 is returned. + If a is greater b, 1 is returned. + If a is less than b, -1 is returned. + */ + + /* Check, if both mantissa and exponents are identical, when normalized: return 0 */ + shift = norm_l(a_m); + if (shift) + a_m = L_shl(a_m, shift); + if (shift) + a_e = sub(a_e, shift); + + shift = norm_l(b_m); + if (shift) + b_m = L_shl(b_m, shift); + if (shift) + b_e = sub(b_e, shift); + + /* align exponent, if any mantissa is zero */ + if (!a_m) + { + a_e = b_e; + move16(); + } + if (!b_m) + { + b_e = a_e; + move16(); + } + + BASOP_SATURATE_WARNING_OFF_EVS + diff_m = L_sub_sat(a_m, b_m); + BASOP_SATURATE_WARNING_ON_EVS + diff_e = sub(a_e, b_e); + + test(); + IF(diff_m == 0 && diff_e == 0) + { + return 0; + } + + /* Check sign, exponent and mantissa to identify, whether a is greater b or not */ + result = sub(0, 1); + + IF(a_m >= 0) + { + /* a is positive */ + if (b_m < 0) + { + result = 1; + move16(); + } + + test(); + test(); + test(); + if ((b_m >= 0) && ((diff_e > 0) || (diff_e == 0 && diff_m > 0))) + { + result = 1; + move16(); + } + } + ELSE + { + /* a is negative */ + test(); + test(); + test(); + if ((b_m < 0) && ((diff_e < 0) || (diff_e == 0 && diff_m > 0))) + { + result = 1; + move16(); + } + } + return result; +} + +Word32 pow32_fx(Word16 inp, Word16 indx) +{ + Word32 temp_1, temp_2; + IF(EQ_16(indx, 1)) + { + return L_deposit_h(inp); + } + ELSE IF(EQ_16(indx, 0)) + { + return ONE_IN_Q31; + } + ELSE + { + temp_1 = L_mult(inp, inp); // Q31 + temp_2 = temp_1; + FOR(int i = 0; i < (shr(indx, 1)); i++) + { + temp_1 = Mpy_32_32(temp_1, temp_1); // Q31 + } + IF(s_and(indx, 1)) + { + temp_1 = Mpy_32_32(temp_2, temp_1); // Q31 + } + } + return temp_1; +} +#endif + ivas_error ivas_dirac_dec_onset_detection_open( const int16_t num_protos_diff, const int16_t num_freq_bands, @@ -69,17 +192,17 @@ ivas_error ivas_dirac_dec_onset_detection_open( /* memory allocation */ #ifdef IVAS_FLOAT_FIXED - IF((dirac_onset_detection_state->onset_detector_1_fx = (Word16 *)malloc(sizeof(Word16) * num_protos_diff * dirac_onset_detection_params->max_band_decorr)) == NULL) + IF((dirac_onset_detection_state->onset_detector_1_fx = (Word32 *)malloc(sizeof(Word32) * num_protos_diff * dirac_onset_detection_params->max_band_decorr)) == NULL) { return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n")); } - IF((dirac_onset_detection_state->onset_detector_2_fx = (Word16 *)malloc(sizeof(Word16) * num_protos_diff * dirac_onset_detection_params->max_band_decorr)) == NULL) + IF((dirac_onset_detection_state->onset_detector_2_fx = (Word32 *)malloc(sizeof(Word32) * num_protos_diff * dirac_onset_detection_params->max_band_decorr)) == NULL) { return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n")); } /* init to zero */ - set16_fx(dirac_onset_detection_state->onset_detector_1_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); - set16_fx(dirac_onset_detection_state->onset_detector_2_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); + set32_fx(dirac_onset_detection_state->onset_detector_1_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); + set32_fx(dirac_onset_detection_state->onset_detector_2_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); #endif /*to be cleand up*/ IF((dirac_onset_detection_state->onset_detector_1 = (float *)malloc(sizeof(float) * num_protos_diff * dirac_onset_detection_params->max_band_decorr)) == NULL) @@ -118,17 +241,18 @@ ivas_error ivas_dirac_dec_onset_detection_open_fx( /* memory allocation */ #ifdef IVAS_FLOAT_FIXED - IF( ( dirac_onset_detection_state->onset_detector_1_fx = (Word16 *) malloc( sizeof( Word16 ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL ) + IF( ( dirac_onset_detection_state->onset_detector_1_fx = (Word32 *) malloc( sizeof( Word32 ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) ); } - IF( ( dirac_onset_detection_state->onset_detector_2_fx = (Word16 *) malloc( sizeof( Word16 ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL ) + IF( ( dirac_onset_detection_state->onset_detector_2_fx = (Word32 *) malloc( sizeof( Word32 ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for onset detection\n" ) ); } /* init to zero */ - set16_fx(dirac_onset_detection_state->onset_detector_1_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); - set16_fx(dirac_onset_detection_state->onset_detector_2_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); + set32_fx(dirac_onset_detection_state->onset_detector_1_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); + set32_fx(dirac_onset_detection_state->onset_detector_2_fx, 0, num_protos_diff * dirac_onset_detection_params->max_band_decorr); + dirac_onset_detection_state->q_onset_detector = Q31; #endif /*to be cleand up*/ IF( ( dirac_onset_detection_state->onset_detector_1 = (float *) malloc( sizeof( float ) * num_protos_diff * dirac_onset_detection_params->max_band_decorr ) ) == NULL ) @@ -195,3 +319,77 @@ void ivas_dirac_dec_onset_detection_process( return; } + +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_onset_detection_process_fx( + const Word32 *input_power_f, + Word16 q_input_power, + Word32 *onset_filter, + const Word16 num_protos_diff, + DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params, + DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state ) +{ + Word16 b, ch_idx, result; + Word16 tmp_fx; + Word32 tmp32_fx; + Word32 *p_onset_detector_1_fx, *p_onset_detector_2_fx; + Word16 q_result,e_scale; + + p_onset_detector_1_fx = h_dirac_onset_detection_state.onset_detector_1_fx;//Q0 + p_onset_detector_2_fx = h_dirac_onset_detection_state.onset_detector_2_fx;//Q0 + + FOR( ch_idx = 0; ch_idx < num_protos_diff; ch_idx++ ) + { + FOR( b = 0; b < h_dirac_onset_detection_params.max_band_decorr; b++ ) + { + /*detector 1: envelope max*/ + *p_onset_detector_1_fx = Mpy_32_16_1(*p_onset_detector_1_fx, DIRAC_ONSET_ALPHA_FX); //same Q0 + //Word16 comp_flag = BASOP_Util_Cmp_Mant32Exp_sat( *p_onset_detector_1_fx, 31 - q_p_onset_detector_1, *input_power_f, 31- q_input_power); + IF(GT_32(*p_onset_detector_1_fx, *input_power_f)) + { + *p_onset_detector_1_fx = *p_onset_detector_1_fx; + } + ELSE + { + *p_onset_detector_1_fx = *input_power_f; + } + + /*detector 2: envelope min*/ + *p_onset_detector_2_fx = L_add(Mpy_32_16_1( *p_onset_detector_2_fx,DIRAC_ONSET_BETA_FX ), Mpy_32_16_1(*p_onset_detector_1_fx,ONE_DIRAC_ONSET_BETA_FX)); + IF(LT_32(*p_onset_detector_2_fx, *p_onset_detector_1_fx)) + *p_onset_detector_2_fx = *p_onset_detector_2_fx; + ELSE + { + *p_onset_detector_2_fx = *p_onset_detector_1_fx; + } + + IF(EQ_32(*p_onset_detector_1_fx, 0)) + *p_onset_detector_1_fx = L_add(*p_onset_detector_1_fx, EPSILON_FX); + /*onset filter limited between 0 and 1*/ + tmp_fx = BASOP_Util_Divide3232_Scale(*p_onset_detector_2_fx, *p_onset_detector_1_fx, &e_scale); + tmp32_fx = L_mult0(tmp_fx, DIRAC_ONSET_GAIN_FX); + q_result = 12 + 15 - e_scale; + IF(LT_32(tmp32_fx, 0)) + { + tmp32_fx = 0; + } + Word16 comp_flag = BASOP_Util_Cmp_Mant32Exp_sat(tmp32_fx, e_scale + 4, ONE_IN_Q30, 1); + IF(EQ_16(comp_flag, 1) || EQ_16(comp_flag, 0)) + tmp32_fx = ONE_IN_Q31; + ELSE + { + tmp32_fx = L_shl(tmp32_fx, e_scale + 4); + } + onset_filter[b] = tmp32_fx; + + input_power_f++; + p_onset_detector_1_fx++; + p_onset_detector_2_fx++; + } + + onset_filter += h_dirac_onset_detection_params.num_freq_bands; + } + + return; +} +#endif diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 92a60a28a..0328f0d1b 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -81,7 +81,7 @@ static void computeAlphaSynthesis_fx( Word16 *alpha_synthesis_fx, const int16_t static void spreadCoherencePanningHoa_fx( const Word16 azimuth, const Word16 elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response_hoa, const Word16 num_channels_dir, const Word16 ambisonics_order ); -static void spreadCoherencePanningVbap_fx( const int16_t azimuth, const int16_t elevation, const float spreadCoh, const Word16 spreadCoh_fx, float *direct_response, Word32 *direct_response_fx, Word16 *Q_direct_response, const int16_t num_channels_dir, const VBAP_HANDLE hVBAPdata ); +static void spreadCoherencePanningVbap_fx( const int16_t azimuth, const int16_t elevation, const Word16 spreadCoh_fx, Word32 *direct_response_fx, Word16 *Q_direct_response, const int16_t num_channels_dir, const VBAP_HANDLE hVBAPdata ); static void normalizePanningGains_fx( Word32 *direct_response_fx, Word16 *q_direct_res, const Word16 num_channels_dir ); #endif @@ -2303,6 +2303,275 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_dirac_dec_get_response_split_order_fx() + * + * calculate reponse, 1 degree resolution + *------------------------------------------------------------------------*/ + +static void ivas_dirac_dec_get_response_split_order_fx( + const Word16 azimuth, + const Word16 elevation, + Word32 *response, + const Word16 shd_rot_max_order, + const Word32 *p_Rmat /*Q29*/, + Word16 *q_response ) +{ + Word16 index_azimuth, index_elevation; + Word16 el, e, az; + Word32 cos_1, cos_2, sin_1, cos_az[3]; + Word32 sin_az[3]; + Word32 f, c; + Word16 l, m; + Word16 b, b1, b_2, b1_2, a; + Word32 dv_0, dv_1, dv_2, dv_r_0, dv_r_1, dv_r_2; + Word32 w; + Word16 tmp; + Word32 temp; + Word16 exp; + + push_wmops( "ivas_dirac_dec_get_response_split_order" ); + + tmp = idiv1616( add( azimuth, 180 ), 360 ); + index_azimuth = sub( add( azimuth, 180 ), i_mult( tmp, 360 ) ); // index_azimuth = (azimuth + 180) % 360 + index_elevation = add( elevation, 90 ); + + IF( GT_16( index_elevation, 90 ) ) + { + e = -ONE_IN_Q14; + move16(); + el = sub( 180, index_elevation ); + } + ELSE + { + e = ONE_IN_Q14; + move16(); + el = index_elevation; + move16(); + } + + IF( GT_16( index_azimuth, 180 ) ) + { + az = sub( 360, index_azimuth ); + f = -ONE_IN_Q30; + move32(); + } + ELSE + { + az = index_azimuth; + move16(); + f = ONE_IN_Q30; + move32(); + } + + // dirac_gains_trg_term_int Q30 + cos_1 = L_shr( dirac_gains_trg_term_int[az][0], 1 ); // Q29 + cos_2 = L_shl( Mpy_32_32( cos_1, cos_1 ), 2 ); // Q29 + sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29] + + cos_az[0] = cos_1; // Q29 + move32(); + cos_az[1] = L_shl( L_sub( Mpy_32_32( TWO_IN_Q29, cos_2 ), ONE_IN_Q27 ), 2 ); // Q29 + move32(); + cos_az[2] = L_sub( L_shl( Mpy_32_32( Mpy_32_32( TWO_IN_Q29, cos_1 ), cos_az[1] ), 4 ), cos_az[0] ); // Q29 + move32(); + + sin_az[0] = sin_1; // Q29 + move32(); + sin_az[1] = L_shl( Mpy_32_32( Mpy_32_32( sin_1, TWO_IN_Q29 ), cos_1 ), 4 ); // Q29 + move32(); + sin_az[2] = L_shl( Mpy_32_32( sin_1, L_sub( Mpy_32_32( FOUR_IN_Q28, cos_2 ), ONE_IN_Q26 ) ), 5 ); // Q29 + move32(); + + response[0] = ONE_IN_Q29; + move32(); + + FOR( l = 1; l <= shd_rot_max_order; l++ ) + { + b_2 = i_mult( l, l ); + b1_2 = add( b_2, i_mult( 2, l ) ); + FOR( m = 0; m < l; m += 2 ) + { + b = add( b_2, m ); + a = dirac_gains_P_idx[b]; + move16(); + + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 + + response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), 6 ); // Q29 + move32(); + + b1 = sub( b1_2, m ); + response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), 6 ); // Q29 + move32(); + } + + FOR( m = 1; m < l; m += 2 ) + { + b = add( b_2, m ); + a = dirac_gains_P_idx[b]; + move16(); + + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 + c = Mpy_32_16_1( c, e ); // Q24 + + response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), 7 ); // Q29 + move32(); + + b1 = sub( b1_2, m ); + response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), 7 ); // Q29 + move32(); + } + + b = add( b_2, l ); + a = dirac_gains_P_idx[b]; + move16(); + + c = L_shl( Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ), 3 ); // Q29 + IF( EQ_16( sub( l, i_mult( idiv1616( l, 2 ), 2 ) ), 1 ) ) + { + c = L_shl( Mpy_32_16_1( c, e ), 1 ); // Q29 + } + + response[b] = c; // Q29 + move32(); + } + + /*Conversion spherical to cartesian coordinates*/ + w = -dirac_gains_trg_term_int[el][1]; // Q30 + move32(); + dv_0 = Mpy_32_32( w, cos_1 ); // Q28 + dv_1 = Mpy_32_32( w, sin_1 ); // Q28 + dv_2 = L_shr( Mpy_32_16_1( dirac_gains_trg_term_int[el][0], e ), 1 ); // Q28 + + /*Rotation mtx multiplication*/ + dv_r_0 = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat[0], dv_0 ), p_Rmat[1], dv_1 ), p_Rmat[2], dv_2 ); // Q26 + dv_r_1 = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat[3], dv_0 ), p_Rmat[4], dv_1 ), p_Rmat[5], dv_2 ); // Q26 + dv_r_2 = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat[6], dv_0 ), p_Rmat[7], dv_1 ), p_Rmat[8], dv_2 ); // Q26 + + tmp = BASOP_util_atan2( dv_r_1, dv_r_0, 0 ); // Q13 + index_azimuth = shr( mult( tmp, _180_OVER_PI_Q9 ), 7 ); // Q0; + + tmp = idiv1616( add( index_azimuth, 180 ), 360 ); + index_azimuth = sub( add( index_azimuth, 180 ), i_mult( tmp, 360 ) ); // index_azimuth = (index_azimuth + 180) % 360 + + temp = L_add( Mpy_32_32( dv_r_0, dv_r_0 ), Mpy_32_32( dv_r_1, dv_r_1 ) ); // Q21 + exp = sub( 31, Q21 ); + temp = Sqrt32( temp, &exp ); + + tmp = BASOP_util_atan2( dv_r_2, temp, sub( sub( 31, Q26 ), exp ) ); // Q13 + index_elevation = shr( mult( tmp, _180_OVER_PI_Q9 ), Q7 ); // Q0 + index_elevation = add( index_elevation, 90 ); + + IF( GT_16( index_elevation, 90 ) ) + { + e = -ONE_IN_Q14; + move16(); + el = sub( 180, index_elevation ); + } + ELSE + { + e = ONE_IN_Q14; + move16(); + el = index_elevation; + move16(); + } + + IF( GT_16( index_azimuth, 180 ) ) + { + az = sub( 360, index_azimuth ); + f = -ONE_IN_Q30; + move32(); + } + ELSE + { + az = index_azimuth; + move16(); + f = ONE_IN_Q30; + move32(); + } + + // dirac_gains_trg_term_int Q30 + cos_1 = L_shr( dirac_gains_trg_term_int[az][0], 1 ); // Q29 + cos_2 = L_shl( Mpy_32_32( cos_1, cos_1 ), 2 ); // Q29 + sin_1 = Mpy_32_32( f, dirac_gains_trg_term_int[az][1] ); // Q29 + + cos_az[0] = cos_1; // Q29 + move32(); + cos_az[1] = L_shl( L_sub( Mpy_32_32( TWO_IN_Q29, cos_2 ), ONE_IN_Q27 ), 2 ); // Q29 + move32(); + cos_az[2] = L_sub( L_shl( Mpy_32_32( Mpy_32_32( TWO_IN_Q29, cos_1 ), cos_az[1] ), 4 ), cos_az[0] ); // Q29 + move32(); + + sin_az[0] = sin_1; // Q29 + move32(); + sin_az[1] = L_shl( Mpy_32_32( Mpy_32_32( sin_1, TWO_IN_Q29 ), cos_1 ), 4 ); // Q29 + move32(); + sin_az[2] = L_shl( Mpy_32_32( sin_1, L_sub( Mpy_32_32( FOUR_IN_Q28, cos_2 ), ONE_IN_Q26 ) ), 5 ); // Q29 + move32(); + + FOR( l = shd_rot_max_order + 1; l <= 3; l++ ) + { + b_2 = i_mult( l, l ); + b1_2 = add( b_2, i_mult( 2, l ) ); + + FOR( m = 0; m < l; m += 2 ) + { + b = add( b_2, m ); + a = dirac_gains_P_idx[b]; + move16(); + + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 + + response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), 6 ); // Q29 + move32(); + + b1 = sub( b1_2, m ); + response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), 6 ); // Q29 + move32(); + } + + FOR( m = 1; m < l; m += 2 ) + { + b = add( b_2, m ); + a = dirac_gains_P_idx[b]; + move16(); + + c = Mpy_32_32( Mpy_32_32( SQRT2_FIXED, dirac_gains_norm_term_int[a] ), dirac_gains_Pnm_int[el][a] ); // Q25 + c = Mpy_32_16_1( c, e ); // Q24 + + response[b] = L_shl( Mpy_32_32( c, sin_az[l - m - 1] ), 7 ); // Q29 + move32(); + + b1 = sub( b1_2, m ); + response[b1] = L_shl( Mpy_32_32( c, cos_az[l - m - 1] ), 7 ); // Q29 + move32(); + } + + b = add( b_2, l ); + a = dirac_gains_P_idx[b]; + move16(); + + c = L_shl( Mpy_32_32( dirac_gains_norm_term_int[a], dirac_gains_Pnm_int[el][a] ), 3 ); // Q29 + + IF( EQ_16( sub( l, i_mult( idiv1616( l, 2 ), 2 ) ), 1 ) ) + { + c = L_shl( Mpy_32_16_1( c, e ), 1 ); // Q29 + } + + response[b] = c; // Q29 + move32(); + } + + *q_response = Q29; + move32(); + + pop_wmops(); + + return; +} +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_get_response_split_order() * @@ -2484,34 +2753,47 @@ void ivas_dirac_dec_compute_directional_responses_fx( const Word32 *surCohRatio_fx, Word16 Q_surCohRatio, const Word16 shd_rot_max_order, /* i : split-order rotation method */ - const float *p_Rmat, /* i : rotation matrix */ + const Word32 *p_Rmat, /* i : rotation matrix */ const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ) { Word16 k, l, i; Word16 num_channels_dir; const Word16 *azimuth2, *elevation2; - float direct_response_hoa[MAX_OUTPUT_CHANNELS]; /* number of output channels (HOA 3rd order) -> 16 */ - float direct_response_ls[MAX_OUTPUT_CHANNELS]; - float direct_response_square[MAX_OUTPUT_CHANNELS]; - float *direct_response; - float direct_response_dir2[MAX_OUTPUT_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED - Word16 exp_surCohRatio = 31 - Q_surCohRatio; + + Word32 direct_response_hoa_fx[MAX_OUTPUT_CHANNELS]; /* number of output channels (HOA 3rd order) -> 16 */ Word32 direct_response_ls_fx[MAX_OUTPUT_CHANNELS]; - Word16 Q_direct_response_ls = Q31, exp_direct_response_ls = 0; + Word32 direct_response_square_fx[MAX_OUTPUT_CHANNELS]; Word32 direct_response_dir2_fx[MAX_OUTPUT_CHANNELS]; - Word16 Q_direct_response_dir2 = Q31, exp_direct_response_dir2 = 0; - Word32 direct_response_hoa_fx[MAX_OUTPUT_CHANNELS]; - Word16 Q_direct_response_hoa = Q31, exp_direct_response_hoa = 0; - Word32 totalDirect_fx; Word32 directRatio_fx[MASA_MAXIMUM_DIRECTIONS]; -#endif - + Word16 Q_direct_response_ls, exp_direct_response_ls; + Word16 Q_direct_response_dir2, exp_direct_response_dir2; + Word16 Q_direct_response_hoa, exp_direct_response_hoa; + Word16 direct_response_square_q, direct_response_q; + Word16 exp_surCohRatio = sub( 31, Q_surCohRatio ); + Word32 totalDirect_fx; + Word32 *direct_response_fx; Word16 codingBand; Word16 dipole_freq_range[2]; MASA_TRANSPORT_SIGNAL_TYPE transport_signal_type; + Q_direct_response_ls = Q31; + move16(); + exp_direct_response_ls = 0; + move16(); + Q_direct_response_dir2 = Q31; + move16(); + exp_direct_response_dir2 = 0; + move16(); + Q_direct_response_hoa = Q31; + move16(); + exp_direct_response_hoa = 0; + move16(); + direct_response_square_q = Q31; + move16(); + direct_response_q = Q29; + move16(); + azimuth2 = NULL; elevation2 = NULL; transport_signal_type = MASA_STEREO_NOT_DEFINED; @@ -2537,42 +2819,38 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); } - codingBand = negate(1); + codingBand = negate( 1 ); assert( num_channels_dir <= MAX_OUTPUT_CHANNELS && "Number of channels is too high" ); FOR( k = 0; k < hSpatParamRendCom->num_freq_bands; ++k ) { - IF( masa_band_mapping != NULL && EQ_16( k, MASA_band_grouping_24[masa_band_mapping[codingBand + 1]] ) ) + IF( masa_band_mapping != NULL && EQ_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) ) { codingBand = add( codingBand, 1 ); } IF( masa_band_mapping != NULL && GT_16( k, MASA_band_grouping_24[masa_band_mapping[codingBand]] ) && - LT_16( k, MASA_band_grouping_24[masa_band_mapping[codingBand + 1]] ) && + LT_16( k, MASA_band_grouping_24[masa_band_mapping[add( codingBand, 1 )]] ) && NE_16( k, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ) ) { /* Panning gains have to be computed only for the first bin of the coding band in MASA, for other bins the previous values can be used */ IF( NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k - 1], - hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k - 1], + hSpatParamRendCom->num_freq_bands, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], + hSpatParamRendCom->num_freq_bands, num_channels_dir ); } - mvr2r_inc( &hDirACRend->h_output_synthesis_psd_state.direct_responses[k - 1], - hSpatParamRendCom->num_freq_bands, - &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], - hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k - 1], + hSpatParamRendCom->num_freq_bands, + &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], + hSpatParamRendCom->num_freq_bands, num_channels_dir ); } ELSE { /* HOA3 PANNING */ IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) { - /*TODO : Clean up*/ - set_f( direct_response_hoa, 1.0f, MAX_OUTPUT_CHANNELS ); - set_f( direct_response_dir2, 1.0f, MAX_OUTPUT_CHANNELS ); - set32_fx( direct_response_hoa_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); set32_fx( direct_response_dir2_fx, ONE_IN_Q29, MAX_OUTPUT_CHANNELS ); @@ -2587,11 +2865,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( IF( p_Rmat != 0 ) { - ivas_dirac_dec_get_response_split_order( azimuth[k], elevation[k], direct_response_hoa, shd_rot_max_order, p_Rmat ); + ivas_dirac_dec_get_response_split_order_fx( azimuth[k], elevation[k], direct_response_hoa_fx, shd_rot_max_order, p_Rmat, &Q_direct_response_hoa ); IF( hodirac_flag ) { - ivas_dirac_dec_get_response_split_order( azimuth2[k], elevation2[k], direct_response_dir2, shd_rot_max_order, p_Rmat ); + ivas_dirac_dec_get_response_split_order_fx( azimuth2[k], elevation2[k], direct_response_dir2_fx, shd_rot_max_order, p_Rmat, &Q_direct_response_dir2 ); } } ELSE @@ -2606,19 +2884,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_hoa[i] = fix_to_float( direct_response_hoa_fx[i], Q_direct_response_hoa ); - } - mvr2r_inc( direct_response_hoa, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); IF( hodirac_flag ) { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_dir2[i] = fix_to_float( direct_response_dir2_fx[i], Q_direct_response_dir2 ); - } - mvr2r_inc( direct_response_dir2, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k + hSpatParamRendCom->num_freq_bands * num_channels_dir], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_dir2_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[add( k, i_mult( hSpatParamRendCom->num_freq_bands, num_channels_dir ) )], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } } ELSE IF( ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) && ( masa_band_mapping != NULL ) ) || @@ -2627,10 +2897,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( /* Synthesize the first direction */ IF( GT_16( Q_direct_response_hoa, Q29 ) ) { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_hoa_fx[i] = L_shr( direct_response_hoa_fx[i], abs_s( Q_direct_response_hoa - Q29 ) ); - } + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_hoa, Q29 ) ); Q_direct_response_hoa = Q29; move16(); exp_direct_response_hoa = sub( 31, Q_direct_response_hoa ); @@ -2646,10 +2913,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( { IF( GT_16( Q_direct_response_dir2, Q29 ) ) { - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_dir2_fx[i] = L_shr( direct_response_dir2_fx[i], abs_s( Q_direct_response_dir2 - Q29 ) ); - } + Scale_sig32( direct_response_dir2_fx, MAX_OUTPUT_CHANNELS, sub( Q_direct_response_dir2, Q29 ) ); Q_direct_response_dir2 = Q29; move16(); exp_direct_response_dir2 = sub( 31, Q_direct_response_dir2 ); @@ -2662,7 +2926,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); /* Combine gains from the two directions */ totalDirect_fx = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); - IF( totalDirect_fx == 0 ) + IF( EQ_32( totalDirect_fx, 0 ) ) { totalDirect_fx = EPSILON_FIX; move32(); @@ -2701,10 +2965,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word16 max_exp = MIN16B; move16(); - FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - max_exp = s_max( max_exp, exp_arr[l] ); - } + maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], max_exp - exp_arr[l] ); @@ -2742,7 +3003,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word32 temp_1 = 0; Word16 exp_temp = 0, exp_arr[MAX_OUTPUT_CHANNELS]; - set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS); + set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { temp_1 = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q28 @@ -2752,10 +3013,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); } Word16 max_exp = MIN16B; - FOR( l = 0; l < num_channels_dir; l++ ) - { - max_exp = s_max( max_exp, exp_arr[l] ); - } + maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { direct_response_ism_fx[l] = L_shr( direct_response_ism_fx[l], max_exp - exp_arr[l] ); @@ -2767,11 +3025,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word16 exp_1 = 0, exp_2 = 0; masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; move32(); - IF( masaDirect_fx == 0 ) + IF( EQ_32( masaDirect_fx, 0 ) ) { masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); } - IF( hSpatParamRendCom->numParametricDirections == 2 ) + IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); } @@ -2812,16 +3070,13 @@ void ivas_dirac_dec_compute_directional_responses_fx( Word16 max_exp = MIN16B; move16(); - FOR( l = 0; l < num_channels_dir; l++ ) - { - max_exp = s_max( max_exp, exp_arr[l] ); - } + maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], max_exp - exp_arr[l] ); move32(); } - Q_direct_response_hoa = sub(31 , max_exp); + Q_direct_response_hoa = sub( 31, max_exp ); exp_direct_response_hoa = max_exp; move16(); } @@ -2844,47 +3099,48 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); } Word16 max_exp = MIN_16; - FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - max_exp = s_max( max_exp, exp_arr[l] ); - } + maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { direct_response_hoa_fx[l] = L_shr( direct_response_hoa_fx[l], max_exp - exp_arr[l] ); move32(); } - Q_direct_response_hoa = sub(31 , max_exp); + Q_direct_response_hoa = sub( 31, max_exp ); exp_direct_response_hoa = max_exp; move16(); } - /* Set computed gains */ - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_hoa[i] = me2f( direct_response_hoa_fx[i], exp_direct_response_hoa ); - } + Q_direct_response_hoa = sub( Q31, exp_direct_response_hoa ); - direct_response = direct_response_hoa; + Scale_sig32( direct_response_hoa_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_hoa ) ); + direct_response_q = Q29; + move16(); + + direct_response_fx = direct_response_hoa_fx; IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { - v_mult( direct_response, direct_response, direct_response_square, num_channels_dir ); - mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - IF( transport_signal_type == MASA_STEREO_SPACED_MICS ) + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + + IF( EQ_16( transport_signal_type, MASA_STEREO_SPACED_MICS ) ) { - direct_response[0] = 1.0f; - IF( k >= dipole_freq_range[0] && k < dipole_freq_range[1] ) + direct_response_fx[0] = ONE_IN_Q29; + move32(); + IF( GE_16( k, dipole_freq_range[0] ) && LT_16( k, dipole_freq_range[1] ) ) { - direct_response[1] = 1.0f; + direct_response_fx[1] = ONE_IN_Q29; + move32(); } } ELSE { - set_f( direct_response, 1.0f, hDirACRend->num_protos_ambi ); + set32_fx( direct_response_fx, ONE_IN_Q29, hDirACRend->num_protos_ambi ); } } - mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } ELSE { @@ -2895,21 +3151,18 @@ void ivas_dirac_dec_compute_directional_responses_fx( ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ { /* Synthesize the first direction */ - spreadCoherencePanningVbap_fx( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence[md_idx][k], hSpatParamRendCom->spreadCoherence_fx[md_idx][k], - direct_response_ls, direct_response_ls_fx, &Q_direct_response_ls, num_channels_dir, hVBAPdata ); + spreadCoherencePanningVbap_fx( azimuth[k], elevation[k], hSpatParamRendCom->spreadCoherence_fx[md_idx][k], + direct_response_ls_fx, &Q_direct_response_ls, num_channels_dir, hVBAPdata ); normalizePanningGains_fx( direct_response_ls_fx, &Q_direct_response_ls, num_channels_dir ); exp_direct_response_ls = sub( 31, Q_direct_response_ls ); /* Synthesize the second direction and combine the gains */ IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) { - spreadCoherencePanningVbap_fx( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2[md_idx][k], hSpatParamRendCom->spreadCoherence2_fx[md_idx][k], direct_response_dir2, direct_response_dir2_fx, &Q_direct_response_dir2, num_channels_dir, hVBAPdata ); + spreadCoherencePanningVbap_fx( azimuth2[k], elevation2[k], hSpatParamRendCom->spreadCoherence2_fx[md_idx][k], direct_response_dir2_fx, &Q_direct_response_dir2, num_channels_dir, hVBAPdata ); normalizePanningGains_fx( direct_response_dir2_fx, &Q_direct_response_dir2, num_channels_dir ); /* Combine gains from the two directions */ - /*TODO: Remove float code*/ - hSpatParamRendCom->energy_ratio1_fx[md_idx][k] = float_to_fix( hSpatParamRendCom->energy_ratio1[md_idx][k], Q30 ); - hSpatParamRendCom->energy_ratio2_fx[md_idx][k] = float_to_fix( hSpatParamRendCom->energy_ratio2[md_idx][k], Q30 ); Word32 test = L_add( hSpatParamRendCom->energy_ratio1_fx[md_idx][k], hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); IF( EQ_32( test, 0 ) ) @@ -2955,10 +3208,8 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); } - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - exp_max = s_max( exp_max, exp_table[i] ); - } + maximum_fx( exp_table, MAX_OUTPUT_CHANNELS, &exp_max ); + FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { direct_response_ls_fx[i] = L_shr( direct_response_ls_fx[i], exp_max - exp_table[i] ); @@ -3001,19 +3252,16 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( l = 0; l < num_channels_dir; l++ ) { tmp = Mpy_32_32( direct_response_temp_fx[l], hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); // Q30 * 2 - 31 - direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, 31 - ( 60 - 31 ), &exp_tmp ); + direct_response_ism_fx[l] = BASOP_Util_Add_Mant32Exp( direct_response_ism_fx[l], 0, tmp, sub( 31, sub( 60, 31 ) ), &exp_tmp ); move32(); - Q_arr[l] = sub(31 , exp_tmp); + Q_arr[l] = sub( 31, exp_tmp ); move16(); } Word16 Q_min = MAX16B; + minimum_fx( Q_arr, num_channels_dir, &Q_min ); FOR( i = 0; i < num_channels_dir; i++ ) { - Q_min = s_min( Q_min, Q_arr[i] ); - } - FOR( i = 0; i < num_channels_dir; i++ ) - { - direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub(Q_arr[i] , Q_min) ); + direct_response_ism_fx[i] = L_shr( direct_response_ism_fx[i], sub( Q_arr[i], Q_min ) ); move32(); } Q_direct_response_temp = Q_min; @@ -3025,11 +3273,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); masaDirect_fx = hSpatParamRendCom->energy_ratio1_fx[md_idx][k]; move32(); - IF( EQ_32(masaDirect_fx , 0 )) + IF( EQ_32( masaDirect_fx, 0 ) ) { masaDirect_fx = L_add( masaDirect_fx, EPSILLON_FX ); } - IF( EQ_32(hSpatParamRendCom->numParametricDirections , 2 )) + IF( EQ_32( hSpatParamRendCom->numParametricDirections, 2 ) ) { masaDirect_fx = L_add( masaDirect_fx, hSpatParamRendCom->energy_ratio2_fx[md_idx][k] ); } @@ -3056,13 +3304,13 @@ void ivas_dirac_dec_compute_directional_responses_fx( move16(); Word16 exp_arr[MAX_OUTPUT_CHANNELS], exp_temp_3 = 0; move16(); - //set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS); - set16_fx(exp_arr, exp_direct_response_ls, MAX_OUTPUT_CHANNELS); + // set16_fx( exp_arr, 0, MAX_OUTPUT_CHANNELS); + set16_fx( exp_arr, exp_direct_response_ls, MAX_OUTPUT_CHANNELS ); FOR( l = 0; l < num_channels_dir; l++ ) { direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], directRatio_fx[0] ); move32(); - exp_arr[l] = add(exp_direct_response_ls , exp_1); + exp_arr[l] = add( exp_direct_response_ls, exp_1 ); move16(); temp_2 = Mpy_32_32( directRatio_fx[1], direct_response_ism_fx[l] ); temp_3 = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], temp_2, exp_2 + 31 - Q_direct_response_temp, &exp_temp_3 ); @@ -3074,10 +3322,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } Word16 max_exp = MIN16B; - FOR( l = 0; l < num_channels_dir; l++ ) - { - max_exp = s_max( max_exp, exp_arr[l] ); - } + maximum_fx( exp_arr, num_channels_dir, &max_exp ); FOR( l = 0; l < num_channels_dir; l++ ) { direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], max_exp - exp_arr[l] ); @@ -3098,7 +3343,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( num_channels_surrCoh = num_channels_dir; move16(); - num_channels_surrCoh = sub(num_channels_surrCoh , hDirACRend->num_ele_spk_no_diffuse_rendering); + num_channels_surrCoh = sub( num_channels_surrCoh, hDirACRend->num_ele_spk_no_diffuse_rendering ); Word32 temp = 0, final = 0; move32(); @@ -3119,13 +3364,13 @@ void ivas_dirac_dec_compute_directional_responses_fx( direct_response_ls_fx[l] = Mpy_32_32( direct_response_ls_fx[l], temp ); // exp_direct_response_ls + exp_temp move32(); - exp_arr[l] = add(exp_direct_response_ls , exp_temp); + exp_arr[l] = add( exp_direct_response_ls, exp_temp ); move16(); - IF( hDirACRend->diffuse_response_function[l] > 0.f ) //TODO: clean up + IF( GT_16( hDirACRend->diffuse_response_function_fx[l], 0 ) ) { exp_temp_a = 0; temp_a = BASOP_Util_Divide3216_Scale( surCohRatio_fx[k], num_channels_surrCoh, &exp_temp_a ); - exp_temp_a = add(exp_temp_a , sub( exp_surCohRatio , 15 )); + exp_temp_a = add( exp_temp_a, sub( exp_surCohRatio, 15 ) ); temp_a = Sqrt16( temp_a, &exp_temp_a ); final_exp = 0; final = BASOP_Util_Add_Mant32Exp( direct_response_ls_fx[l], exp_arr[l], L_deposit_h( temp_a ), exp_temp_a, &final_exp ); @@ -3138,10 +3383,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( max_exp = MIN16B; move16(); - FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - max_exp = s_max( max_exp, exp_arr[l] ); - } + maximum_fx( exp_arr, MAX_OUTPUT_CHANNELS, &max_exp ); FOR( l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) { direct_response_ls_fx[l] = L_shr( direct_response_ls_fx[l], max_exp - exp_arr[l] ); @@ -3156,16 +3398,17 @@ void ivas_dirac_dec_compute_directional_responses_fx( normalizePanningGains_fx( direct_response_ls_fx, &Q_direct_response_ls, num_channels_dir ); exp_direct_response_ls = sub( 31, Q_direct_response_ls ); + Scale_sig32( direct_response_ls_fx, MAX_OUTPUT_CHANNELS, sub( Q29, Q_direct_response_ls ) ); + direct_response_q = Q29; + move16(); + /* Set computed gains */ - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response_ls[i] = fix_to_float( direct_response_ls_fx[i], Q_direct_response_ls ); - } - direct_response = direct_response_ls; - v_mult( direct_response, direct_response, direct_response_square, num_channels_dir ); + direct_response_fx = direct_response_ls_fx; + v_mult_fixed( direct_response_fx, direct_response_fx, direct_response_square_fx, num_channels_dir ); + direct_response_square_q = sub( add( direct_response_q, direct_response_q ), 31 ); - mvr2r_inc( direct_response_square, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); - mvr2r_inc( direct_response, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_square_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); + mvr2r_inc_fixed( direct_response_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); } ELSE { @@ -3174,6 +3417,11 @@ void ivas_dirac_dec_compute_directional_responses_fx( } } + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = direct_response_q; + move16(); + hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = direct_response_square_q; + move16(); + return; } #endif @@ -4078,11 +4326,11 @@ static void spreadCoherencePanningHoa_fx( IF( LT_16( spreadCoh_fx, ONE_IN_Q14 ) ) { /*gainCenter = (3 - 4*spreadCoh )/3*/ - var_a = sub( 24576 /*3 in Q13*/, spreadCoh_fx ); // Q13 - var_a = mult( var_a, float_to_fix16( 0.33333333f, Q15 ) ); // Q13 + var_a = sub( 24576 /*3 in Q13*/, spreadCoh_fx ); // Q13 + var_a = mult( var_a, ONE_BY_THREE_Q15 ); // Q13 - gainCenter_fx = L_deposit_h( shr( var_a, 2 ) ); // Q11 + 16 = Q27 - gainSide_fx = L_deposit_h( mult( spreadCoh_fx, float_to_fix16( 0.33333333f, Q15 ) ) ); // Q14 + 16 (reduce Q by 1 to *2) = Q30 + gainCenter_fx = L_deposit_h( shr( var_a, 2 ) ); // Q11 + 16 = Q27 + gainSide_fx = L_deposit_h( mult( spreadCoh_fx, ONE_BY_THREE_Q15 ) ); // Q14 + 16 (reduce Q by 1 to *2) = Q30 exp_Gain_side = 31 - Q30; exp_Gain_center = 31 - Q27; } @@ -4171,111 +4419,78 @@ static void spreadCoherencePanningHoa( #ifdef IVAS_FLOAT_FIXED static void spreadCoherencePanningVbap_fx( - const int16_t azimuth, - const int16_t elevation, - const float spreadCoh, + const Word16 azimuth, + const Word16 elevation, const Word16 spreadCoh_fx, - float *direct_response, Word32 *direct_response_fx, Word16 *Q_direct_response, - const int16_t num_channels_dir, + const Word16 num_channels_dir, const VBAP_HANDLE hVBAPdata) { int16_t i; - float direct_response_left[MAX_OUTPUT_CHANNELS]; - float direct_response_right[MAX_OUTPUT_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED Word32 direct_response_left_fx[MAX_OUTPUT_CHANNELS]; Word32 direct_response_right_fx[MAX_OUTPUT_CHANNELS]; set32_fx(direct_response_left_fx, 0, MAX_OUTPUT_CHANNELS); set32_fx(direct_response_right_fx, 0, MAX_OUTPUT_CHANNELS); Word32 gainCenter_fx; Word32 gainSide_fx; -#endif - float gainCenter; - float gainSide; - if (hVBAPdata == NULL) + IF( hVBAPdata == NULL ) { /* Distribute signal to all channels if VBAP is not properly initialized. */ Word16 exp_tmp = 0; - Word16 var_temp = ISqrt16(num_channels_dir, &exp_tmp); - set32_fx(direct_response_fx, var_temp, num_channels_dir); - *Q_direct_response = 31 - exp_tmp; - - set_f(direct_response, inv_sqrt(num_channels_dir), num_channels_dir); + move16(); + Word16 var_temp = ISqrt16( num_channels_dir, &exp_tmp ); + set32_fx( direct_response_fx, var_temp, num_channels_dir ); + *Q_direct_response = sub( 31, exp_tmp ); return; } -#ifdef IVAS_FLOAT_FIXED - set32_fx(direct_response_fx, 0, MAX_OUTPUT_CHANNELS); - vbap_determine_gains_fx(hVBAPdata, direct_response_fx, azimuth, elevation, 0); + + set32_fx( direct_response_fx, 0, MAX_OUTPUT_CHANNELS ); + vbap_determine_gains_fx( hVBAPdata, direct_response_fx, azimuth, elevation, 0 ); *Q_direct_response = Q29; -#else - vbap_determine_gains(hVBAPdata, direct_response, azimuth, elevation, 0); -#endif + move16(); - if (spreadCoh > 0.f) + IF( GT_16( spreadCoh_fx, 0 ) ) { -#ifdef IVAS_FLOAT_FIXED - vbap_determine_gains_fx(hVBAPdata, direct_response_left_fx, azimuth + 30, elevation, 0); - FOR(i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - direct_response_left[i] = fix_to_float(direct_response_left_fx[i], Q29); - } - vbap_determine_gains_fx(hVBAPdata, direct_response_right_fx, azimuth - 30, elevation, 0); - FOR(i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - direct_response_right[i] = fix_to_float(direct_response_right_fx[i], Q29); - } -#else - vbap_determine_gains(hVBAPdata, direct_response_left, azimuth + 30, elevation, 0); - vbap_determine_gains(hVBAPdata, direct_response_right, azimuth - 30, elevation, 0); -#endif - Word32 var1 = 0, var2 = 0; - Word16 var_a = 0, var_b = 0; - if (spreadCoh < 0.5f) - { -#ifdef IVAS_FLOAT_FIXED - var_a = mult(spreadCoh_fx, INV_SQRT3_FX); //Q14 - var_b = sub(ONE_IN_Q14, spreadCoh_fx);//Q14 - gainCenter_fx = L_deposit_h(add(var_a, var_b)); //Q30 - gainSide_fx = L_deposit_h(var_a);//Q30 + vbap_determine_gains_fx( hVBAPdata, direct_response_left_fx, azimuth + 30, elevation, 0 ); + vbap_determine_gains_fx( hVBAPdata, direct_response_right_fx, azimuth - 30, elevation, 0 ); - gainCenter = fix_to_float(gainCenter_fx, Q30); - gainSide = fix_to_float(gainSide_fx, Q30); -#else - gainCenter = (1.0f - 2.0f * spreadCoh) + 2.0f * spreadCoh * INV_SQRT3; - gainSide = 2.0f * spreadCoh * INV_SQRT3; -#endif + Word32 var1 = 0; + move32(); + Word32 var2 = 0; + move32(); + Word16 var_a = 0; + move16(); + Word16 var_b = 0; + move16(); + IF( LT_16( spreadCoh_fx, 16384 ) ) // 16384 = 0.5 in Q15 + { + var_a = mult( spreadCoh_fx, INV_SQRT3_FX ); // Q14 + var_b = sub( ONE_IN_Q14, spreadCoh_fx ); // Q14 + gainCenter_fx = L_deposit_h( add( var_a, var_b ) ); // Q30 + gainSide_fx = L_deposit_h( var_a ); // Q30 } - else + ELSE { -#ifdef IVAS_FLOAT_FIXED - var_a = sub(ONE_IN_Q14, shr(spreadCoh_fx,1)); //Q13 - gainCenter_fx = L_shl(L_deposit_h(var_a), 1);//Q30 + var_a = sub( ONE_IN_Q14, shr( spreadCoh_fx, 1 ) ); // Q13 + gainCenter_fx = L_shl( L_deposit_h( var_a ), 1 ); // Q30 gainSide_fx = ONE_IN_Q30; - - gainCenter = fix_to_float(gainCenter_fx, Q30); - gainSide = fix_to_float(gainSide_fx, Q30); -#else - gainCenter = 2.0f - 2.0f * spreadCoh; - gainSide = 1.0f; -#endif + move32(); } Word32 var3 = 0; + move32(); *Q_direct_response = Q28; - for (i = 0; i < num_channels_dir; i++) + move16(); + FOR( i = 0; i < num_channels_dir; i++ ) { -#ifdef IVAS_FLOAT_FIXED - var1 = L_add(direct_response_left_fx[i], direct_response_right_fx[i]); // Q29 - var2 = Mpy_32_32(var1, gainSide_fx); // Q28 - var3 = Mpy_32_32(direct_response_fx[i], gainCenter_fx); // Q28 - direct_response_fx[i] = L_add(var3, var2); // Q28 -#else - direct_response[i] = direct_response[i] * gainCenter + (direct_response_left[i] + direct_response_right[i]) * gainSide; -#endif + var1 = L_add( direct_response_left_fx[i], direct_response_right_fx[i] ); // Q29 + var2 = Mpy_32_32( var1, gainSide_fx ); // Q28 + var3 = Mpy_32_32( direct_response_fx[i], gainCenter_fx ); // Q28 + direct_response_fx[i] = L_add( var3, var2 ); // Q28 + move32(); } } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 94e2de1f3..52d0340eb 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -560,6 +560,17 @@ void ivas_dirac_dec_onset_detection_process( DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_onset_detection_process_fx( + const Word32 *input_power_f, + Word16 q_input_power, + Word32 *onset_filter, + const Word16 num_protos_diff, + DIRAC_ONSET_DETECTION_PARAMS h_dirac_onset_detection_params, + DIRAC_ONSET_DETECTION_STATE h_dirac_onset_detection_state +); +#endif + ivas_error ivas_dirac_dec_decorr_open( DIRAC_DECORR_PARAMS **ph_freq_domain_decorr_ap_params, DIRAC_DECORR_STATE **ph_freq_domain_decorr_ap_state, @@ -587,6 +598,25 @@ void ivas_dirac_dec_decorr_process( HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state ); +#ifdef IVAS_FLOAT_FIXED +void ivas_dirac_dec_decorr_process_fx( + const Word16 num_freq_bands, + Word16 num_channels, + const Word16 num_protos_diff, + const DIRAC_SYNTHESIS_CONFIG synthesisConf, + const Word16 nchan_transport, /* i : number of transport channels */ + const Word32 *input_frame_fx, + Word16 q_inp_frame, + const Word16 num_protos_dir, + const Word16 *proto_index_dir, + Word32 *frame_dec_fx, + Word16 *q_frame_dec, + Word32 *onset_filter_fx, + HANDLE_DIRAC_DECORR_PARAMS h_freq_domain_decorr_ap_params, + HANDLE_DIRAC_DECORR_STATE h_freq_domain_decorr_ap_state +); +#endif + void ivas_dirac_dec_decorr_close( HANDLE_DIRAC_DECORR_PARAMS *ph_dirac_decorr_params, HANDLE_DIRAC_DECORR_STATE *ph_dirac_decorr_state @@ -745,16 +775,16 @@ void ivas_dirac_dec_compute_directional_responses_fx( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ DIRAC_REND_HANDLE hDirACRend, /* i/o: DirAC renderer handle */ const VBAP_HANDLE hVBAPdata, /* i : VBAP structure */ - const Word16 *masa_band_mapping, /* i : Band mapping for MASA, NULL assumes not using MASA in any form */ + const Word16 *masa_band_mapping, /* i : Band mapping for MASA, NULL assumes not using MASA in any form */ MASA_ISM_DATA_HANDLE hMasaIsm, /* i : MASA_ISM data structure */ const Word16 *azimuth, const Word16 *elevation, const Word16 md_idx, const Word32 *surCohRatio_fx, Word16 Q_surCohRatio, - const Word16 shd_rot_max_order, /* i : split-order rotation method */ - const float *p_Rmat, /* i : rotation matrix */ - const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ + const Word16 shd_rot_max_order, /* i : split-order rotation method */ + const Word32 *p_Rmat, /* i : rotation matrix */ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ ); #endif @@ -1884,6 +1914,10 @@ float deg2rad( float degrees ); +Word32 deg2rad_fx( + Word32 degrees +); + float rad2deg( float radians ); diff --git a/lib_rend/ivas_reflections.c b/lib_rend/ivas_reflections.c index 12e1c1959..7a82e922c 100644 --- a/lib_rend/ivas_reflections.c +++ b/lib_rend/ivas_reflections.c @@ -177,14 +177,6 @@ ivas_error ivas_er_init( { return error; } -#ifdef IVAS_FLOAT_FIXED - for ( i = 0; i < reflections->shoebox_data.n_sources; i++ ) - { - reflections->source_positions[i * 3 + 0] = (float) reflections->source_positions_fx[i * 3 + 0]; - reflections->source_positions[i * 3 + 1] = (float) reflections->source_positions_fx[i * 3 + 1]; - reflections->source_positions[i * 3 + 2] = (float) reflections->source_positions_fx[i * 3 + 2] / ONE_IN_Q30; // table i - } -#endif /* Compute the static reflections (first frame) */ IF( ( error = ivas_er_compute_reflections( reflections ) ) != IVAS_ERR_OK ) @@ -250,9 +242,9 @@ ivas_error ivas_er_set_reflections_mode( reflections->source_positions[1] = 0; reflections->source_positions[2] = ER_RADIUS; #else - reflections->source_positions[0] = 0; - reflections->source_positions[1] = 0; - reflections->source_positions[2] = ER_RADIUS_FX; + reflections->source_positions_fx[0] = 0; + reflections->source_positions_fx[1] = 0; + reflections->source_positions_fx[2] = ER_RADIUS_FX; #endif break; case IVAS_AUDIO_CONFIG_STEREO: @@ -382,7 +374,7 @@ ivas_error ivas_er_set_reflections_mode( Function that initializes the er encoder *-----------------------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_er_encoder_init( er_struct_t *reflections ) { @@ -417,16 +409,10 @@ ivas_error ivas_er_encoder_init( { src_idx = ( j > LFE_CHANNEL ) ? j - 1 : j; -#ifndef IVAS_FLOAT_FIXED p_x_src = reflections->source_positions[src_idx * 3 + 2] * ( cosf( reflections->source_positions[src_idx * 3 + 1] ) * cosf( reflections->source_positions[src_idx * 3] ) ); p_y_src = reflections->source_positions[src_idx * 3 + 2] * ( cosf( reflections->source_positions[src_idx * 3 + 1] ) * sinf( reflections->source_positions[src_idx * 3] ) ); p_z_src = reflections->source_positions[src_idx * 3 + 2] * sinf( reflections->source_positions[src_idx * 3 + 1] ); -#else - p_x_src = reflections->source_positions[src_idx * 3 + 2] * ( shoebox_sin_cos_tbl[(int32_t) ( reflections->source_positions[src_idx * 3 + 1] )][1] * shoebox_sin_cos_tbl[(int32_t) ( reflections->source_positions[src_idx * 3] )][1] ); - p_y_src = reflections->source_positions[src_idx * 3 + 2] * ( shoebox_sin_cos_tbl[(int32_t) ( reflections->source_positions[src_idx * 3 + 1] )][1] * shoebox_sin_cos_tbl[(int32_t) ( reflections->source_positions[src_idx * 3] )][0] ); - p_z_src = reflections->source_positions[src_idx * 3 + 2] * shoebox_sin_cos_tbl[(int32_t) ( reflections->source_positions[src_idx * 3 + 1] )][0]; -#endif tmp = ( p_x_src - p_x ) * ( p_x_src - p_x ); tmp += ( p_y_src - p_y ) * ( p_y_src - p_y ); tmp += ( p_z_src - p_z ) * ( p_z_src - p_z ); @@ -455,7 +441,158 @@ ivas_error ivas_er_encoder_init( return error; } +#else + +ivas_error ivas_er_encoder_init( + er_struct_t *reflections ) +{ + ivas_error error = IVAS_ERR_OK; + Word16 i, j, src_idx; + Word16 min_index_fx = 0; + Word32 rad_el_angle, rad_az_angle, tmp_data_fx, p_x_src_fx, p_y_src_fx, p_z_src_fx; + Word16 el_angle_cos, az_angle_cos, el_angle_sin, az_angle_sin; + Word32 p_x_fx, p_y_fx, p_z_fx, tmp_fx, tmp_data, dist_fx, min_dist_fx = 0; + Word32 *src_pos_ptr_fx; + Word16 q_format, tmp16, min_qformat = 0; + + + IF( reflections == NULL ) + { + return IVAS_ERR_FAILED_ALLOC; + } + + IF( EQ_32( getAudioConfigType( reflections->audio_config ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) + { + /* Compute MC-snap location (closest channel position to reflection direction) */ + FOR( i = 0; i < reflections->n_total_reflections; i++ ) + { + /* Compute cartesian points for reflection (from degrees) */ + + p_x_fx = reflections->shoebox_data.el_angle.data_fx[i]; + p_y_fx = reflections->shoebox_data.az_angle.data_fx[i]; + move32(); + move32(); + + rad_el_angle = deg2rad_fx( p_x_fx ); // Q23 + rad_az_angle = deg2rad_fx( p_y_fx ); // Q23 + + + rad_el_angle = L_shr( rad_el_angle, 10 ); // Q13 + rad_az_angle = L_shr( rad_az_angle, 10 ); // Q13 + el_angle_cos = getCosWord16( extract_l( rad_el_angle ) ); // Q14 + az_angle_cos = getCosWord16( extract_l( rad_az_angle ) ); // Q14 + + + el_angle_sin = getSinWord16( extract_l( rad_el_angle ) ); // In:Q13, O/p: Q:15 + az_angle_sin = getSinWord16( extract_l( rad_az_angle ) ); // In:Q13, O/p: Q:15 + + + p_x_fx = L_shl( mult( el_angle_cos, az_angle_cos ), 1 ); // Q.14 *Q.14= Q13 + p_y_fx = mult( el_angle_cos, az_angle_sin ); // Q.14 *Q.15= Q.14 + // Multiplicatio with ER_RADIUS is ignored , as ER_RADIUS=1; + p_z_fx = L_shr( el_angle_sin, 1 ); //// Q.15 + + + /* Calculate the euclidean distance to each point in the config ls setup */ + FOR( j = 0; j < reflections->nchan_out; j++ ) + { + /* Ignore LFE */ + IF( NE_16( j, LFE_CHANNEL ) ) + { + src_idx = GT_16( j, LFE_CHANNEL ) ? sub( j, 1 ) : j; + + src_pos_ptr_fx = &reflections->source_positions_fx[src_idx * 3 + 0]; + move32(); + + tmp_data_fx = Mpy_32_32( shoebox_sin_cos_tbl_fx[( src_pos_ptr_fx[1] )][1], shoebox_sin_cos_tbl_fx[( src_pos_ptr_fx[0] )][1] ); //.29 = .30 * .30 + p_x_src_fx = Mpy_32_32( src_pos_ptr_fx[2], tmp_data_fx ); // .28 =.29*.30 + tmp_data_fx = Mpy_32_32( shoebox_sin_cos_tbl_fx[( src_pos_ptr_fx[1] )][1], shoebox_sin_cos_tbl_fx[( src_pos_ptr_fx[0] )][0] ); //.29 = .30 * .30 + p_y_src_fx = Mpy_32_32( src_pos_ptr_fx[2], tmp_data_fx ); // .28 =.29*.30 + p_z_src_fx = Mpy_32_32( src_pos_ptr_fx[2], shoebox_sin_cos_tbl_fx[( src_pos_ptr_fx[1] )][0] ); //.29 = .30 * .30 + + p_x_src_fx = L_shr( p_x_src_fx, 14 ); + move32(); + p_y_src_fx = L_shr( p_y_src_fx, 14 ); + move32(); + p_z_src_fx = L_shr( p_z_src_fx, 15 ); + move32(); + + tmp_data = L_sub( p_x_src_fx, p_x_fx ); + tmp16 = extract_l( tmp_data ); // Q.14 + tmp16 = shr( tmp16, 1 ); // Q.13 + tmp_fx = L_mult( tmp16, tmp16 ); // Q.27 + + tmp_data = L_sub( p_y_src_fx, p_y_fx ); + tmp16 = extract_l( tmp_data ); // Q.14 + tmp16 = shr( tmp16, 1 ); // Q.13 + tmp_fx = L_mac( tmp_fx, tmp16, tmp16 ); // Q.27 + + + tmp_data = L_sub( p_z_src_fx, p_z_fx ); + tmp16 = extract_l( tmp_data ); // Q.14 + tmp16 = shr( tmp16, 1 ); // Q.13 + tmp_fx = L_mac( tmp_fx, tmp16, tmp16 ); // Q.27 + q_format = Q31 - Q27; + dist_fx = Sqrt32( tmp_fx, &q_format ); + if ( EQ_32( dist_fx, 0 ) ) + { + q_format = 0; + move16(); + } + if ( LE_16( q_format, 0 ) ) + { + dist_fx = L_shl( dist_fx, q_format ); // Q31 + q_format = 0; + move16(); + } + /* Save index of closest channel */ + IF( EQ_16( src_idx, 0 ) ) + { + min_dist_fx = dist_fx; + min_qformat = q_format; + min_index_fx = j; + move32(); + move16(); + move16(); + } + else + { + if ( LE_16( q_format, min_qformat ) ) + { + if ( EQ_16( q_format, min_qformat ) ) + { + if ( LT_32( dist_fx, min_dist_fx ) ) + { + min_dist_fx = dist_fx; + min_index_fx = j; + move32(); + move16(); + } + } + else + { + min_dist_fx = dist_fx; + min_index_fx = j; + min_qformat = q_format; + move32(); + move16(); + move16(); + } + } + } + } + } + + reflections->closest_ch_idx[i] = (uint16_t) min_index_fx; + move16(); + } + } + + return error; +} + +#endif /*-----------------------------------------------------------------------------------------* Function ivas_er_compute_reflections() @@ -469,7 +606,12 @@ ivas_error ivas_er_compute_reflections( { ivas_error error = IVAS_ERR_OK; uint16_t circ_len, i, j; +#ifndef IVAS_FLOAT_FIXED float tmp; +#else + UWord32 tmp_fx, tmp_fx1; + UWord16 tmp_fx_hi, tmp_fx_lo; +#endif reflections->is_ready = 0; @@ -490,6 +632,8 @@ ivas_error ivas_er_compute_reflections( /* Convert reflection times in seconds to samples and keep track of max */ circ_len = 0; +#ifndef IVAS_FLOAT_FIXED + for ( i = 0; i < reflections->shoebox_data.n_sources; i++ ) { for ( j = 0; j < reflections->shoebox_data.n_ref; j++ ) @@ -500,6 +644,25 @@ ivas_error ivas_er_compute_reflections( circ_len = ( (uint16_t) tmp > circ_len ) ? (uint16_t) tmp : circ_len; } } +#else + + FOR( i = 0; i < reflections->shoebox_data.n_sources; i++ ) + { + FOR( j = 0; j < reflections->shoebox_data.n_ref; j++ ) + { + tmp_fx = reflections->shoebox_data.times.data_fx[j + ( i * reflections->shoebox_data.n_ref )]; + tmp_fx_hi = extract_h( tmp_fx ); + tmp_fx_lo = extract_l( tmp_fx ); + Mpy_32_16_uu( tmp_fx, (UWord16) reflections->output_Fs_fx, &tmp_fx1, &tmp_fx_lo ); + tmp_fx1 = (UWord32) L_add( tmp_fx1, 0x20 ); + tmp_fx1 = L_shr( tmp_fx1, 6 ); + reflections->shoebox_data.times.data_fx[j + ( i * reflections->shoebox_data.n_ref )] = tmp_fx1; + circ_len = ( (uint16_t) tmp_fx1 > circ_len ) ? (uint16_t) tmp_fx1 : circ_len; + } + } + + +#endif /* If max delay is less than max frame size, use max frame size to compute circ buffer length */ circ_len = ( circ_len > (uint16_t) reflections->max_frame_size ) ? circ_len : (uint16_t) reflections->max_frame_size; @@ -694,7 +857,7 @@ ivas_error ivas_er_process( { ref_no = j + ( i * n_ref ); ref_gain = (Word32) reflections->shoebox_data.gains.data_fx[ref_no]; - ref_delay = (UWord16) reflections->shoebox_data.times.data[ref_no]; + ref_delay = (UWord16) reflections->shoebox_data.times.data_fx[ref_no]; ref_out_idx = reflections->closest_ch_idx[ref_no]; /* Determine start idx of reflection in circ buffer based on diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 271872a89..d588bb708 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -68,6 +68,11 @@ #define REF_LF_MAX ( 250.0f ) #define REF_HF_MIN ( 5000.0f ) #define REF_HF_MAX ( 7950.0f ) + +#define REF_LF_MIN_FX ( 100 ) +#define REF_LF_MAX_FX ( 250 ) +#define REF_HF_MIN_FX ( 5000 ) +#define REF_HF_MAX_FX ( 7950 ) #define LF_BIAS ( 0.5f ) #define DEFAULT_SRC_DIST ( 1.5f ) /* default source distance [m] for reverb dmx factor computing */ @@ -105,10 +110,18 @@ typedef struct ivas_reverb_params_t Word16 pLoop_extract_matrix_fx[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES]; /* Mix [S][L] matrix from feedback loops to outputs. */ /* In Matlab: [S x L] - Currently S=2, later may be more than 2 for speaker playback. */ Word16 t60_filter_order; /* Filter order (length of vector) */ float pT60_filter_coeff[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH]; /* Filters [][] in feedback loops, controlling T60. */ +#ifdef IVAS_FLOAT_FIXED + Word16 pT60_filter_coeff_fx[MAX_NR_OUTPUTS * IVAS_REV_MAX_NR_BRANCHES * IVAS_REV_MAX_IIR_FILTER_LENGTH]; +#endif /* In Matlab: IIR: [(2 * L) x ( + 1)] (odd: b-vector, even: a-vector) */ /* In Matlab: FIR: [L x ] */ float *pFc; /* Center frequencies for FFT filter design */ float *pRt60; /* RT60 values at these frequencies */ +#ifdef IVAS_FLOAT_FIXED + Word32 *pFc_fx; /* Center frequencies for FFT filter design */ + Word32 *pRt60_fx; /* RT60 values at these frequencies */ + Word16 *pRt60_e; /* exponents of RT60 values at these frequencies */ +#endif float *pDsr; /* DSR values at these frequencies */ float *pHrtf_avg_pwr_response_l; /* The HRTF set's average left ear power response */ float *pHrtf_avg_pwr_response_r; /* The HRTF set's average right ear power response */ @@ -158,8 +171,11 @@ typedef struct ivas_reverb_params_t * Static functions declarations *------------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static ivas_error calc_jot_t60_coeffs( float *pH_dB, const uint16_t nrFrequencies, float *pFrequencies, float *pCoeffA, float *pCoeffB, const float fNyquist ); - +#else +static ivas_error calc_jot_t60_coeffs_fx(Word16 *pH_dB_fx, Word16 pH_dB_exp, const UWord16 nrFrequencies, Word16 *pFrequencies_fx, Word16 *pCoeffA_fx, Word16 *pCoeffB_fx, const Word16 fNyquist_fx); +#endif /*------------------------------------------------------------------------- * binRend_rand() @@ -741,7 +757,87 @@ static void calc_predelay( * * Calculate Jot reverb's T60 filter coefficients *-----------------------------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +static ivas_error compute_t60_coeffs_fx( + ivas_reverb_params_t *pParams, + const Word16 nr_fc_fft_filter, + const Word32 output_Fs ) +{ + Word16 bin_idx, loop_idx, tf_T60_len, len; + ivas_error error; + + Word16 loop_delay_sec_fx, inv_hfs_fx, norm_f_e, tmp; + Word32 freq_Nyquist_fx = L_shr(output_Fs, 1); + Word16 target_gains_db_fx[RV_LENGTH_NR_FC], target_gains_exp; + Word16 norm_f_fx[RV_LENGTH_NR_FC]; + Word32 *targetT60_fx, *pFc_fx; + Word16 *pCoeffs_a_fx, *pCoeffs_b_fx, *targetT60_e; + Word16 target_gains_db_exp[RV_LENGTH_NR_FC]; + error = IVAS_ERR_OK; + tf_T60_len = nr_fc_fft_filter; + len = pParams->t60_filter_order + 1; + + pFc_fx = pParams->pFc_fx; + targetT60_fx = pParams->pRt60_fx; + targetT60_e = pParams->pRt60_e; + Word16 pRt60_e; + + FOR (bin_idx = 0; bin_idx < tf_T60_len; bin_idx++) + { + norm_f_fx[bin_idx] = BASOP_Util_Divide3232_Scale(pFc_fx[bin_idx], freq_Nyquist_fx, &norm_f_e); + norm_f_e = norm_f_e + (17 - 31); + norm_f_fx[bin_idx] = shl(norm_f_fx[bin_idx], norm_f_e - 1); // making Q14 + } + + FOR ( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) + { + + Word16 loop_delay_sec_fx_exp; + loop_delay_sec_fx = BASOP_Util_Divide3232_Scale( pParams->pLoop_delays[loop_idx], output_Fs, &loop_delay_sec_fx_exp); + + FOR ( bin_idx = 0; bin_idx < tf_T60_len; bin_idx++ ) + { + tmp = BASOP_Util_Divide3232_Scale(L_deposit_h(loop_delay_sec_fx), targetT60_fx[bin_idx], &target_gains_db_exp[bin_idx]); + target_gains_db_exp[bin_idx] = target_gains_db_exp[bin_idx] + (loop_delay_sec_fx_exp - targetT60_e[bin_idx]); + target_gains_db_fx[bin_idx] = mult( -30720, tmp ); // -60 in Q9 -> -30720 + target_gains_db_exp[bin_idx] = target_gains_db_exp[bin_idx] + 6; // Q9 -> e6 + + tmp = BASOP_Util_Cmp_Mant32Exp( L_deposit_h(target_gains_db_fx[bin_idx]), target_gains_db_exp[bin_idx], -2013265920, 7); + IF (tmp < 0) { + target_gains_db_fx[bin_idx] = -2013265920; + target_gains_db_exp[bin_idx] = 7; + } + } + + pCoeffs_a_fx = &pParams->pT60_filter_coeff_fx[2 * len * loop_idx + len]; + pCoeffs_b_fx = &pParams->pT60_filter_coeff_fx[2 * len * loop_idx]; + + Word16 val = target_gains_db_exp[0]; + + FOR (Word16 i = 1; i < nr_fc_fft_filter; i++) { + val = s_max(val, target_gains_db_exp[i]); + } + FOR ( Word16 i = 0; i < nr_fc_fft_filter; i++) { + target_gains_db_fx[i] = shr(target_gains_db_fx[i], sub(val, target_gains_db_exp[i])); + } + + IF ( ( error = calc_jot_t60_coeffs_fx(target_gains_db_fx, val, tf_T60_len, norm_f_fx, pCoeffs_a_fx, pCoeffs_b_fx, extract_l(freq_Nyquist_fx )) ) != IVAS_ERR_OK ) + { + return error; + } + } + + len = ( pParams->t60_filter_order + 1 ) >> 1; /* == floor( (order+1) / 2) */ + for ( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) + { + pParams->pLoop_delays[loop_idx] -= len; + } + return error; +} +#endif + +#ifndef IVAS_FLOAT_FIXED static ivas_error compute_t60_coeffs( ivas_reverb_params_t *pParams, const int16_t nr_fc_fft_filter, @@ -795,7 +891,7 @@ static ivas_error compute_t60_coeffs( return error; } - +#endif /*-----------------------------------------------------------------------------------------* * Function calc_low_shelf_first_order_filter() @@ -803,6 +899,7 @@ static ivas_error compute_t60_coeffs( * Calculate 1st order low shelf filter *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void calc_low_shelf_first_order_filter( float *pNum, float *pDen, @@ -838,7 +935,120 @@ static void calc_low_shelf_first_order_filter( return; } +#endif + +#ifdef IVAS_FLOAT_FIXED +static void calc_low_shelf_first_order_filter_fx( + Word16 *pNum, /* Q14 */ + Word16 *pDen, /* Q14 */ + const Word16 f0, + const Word16 lin_gain_lf, + const Word16 lin_gain_hf ) +{ + Word16 sine_val, shift; + Word16 cos_val, tmp, tan_val, tan_exp, gain_exp, exp, norm_num0, norm_num1, norm_den0, norm_den1, num0, num1, den0, den1; + Word32 L_tmp; + + tmp = mult( EVS_PI_BY_2_FX, f0 ); + sine_val = getSinWord16(shl(tmp, 1)); // Q15 + + tmp = mult(EVS_PI_BY_2_FX, f0); + cos_val = getCosWord16(shl(tmp, 1)); // Q14 + + tan_val = BASOP_Util_Divide1616_Scale(sine_val, cos_val, &tan_exp); + tan_exp = tan_exp + (0 - 1); + + Word16 gain_fx; + gain_fx = BASOP_Util_Divide1616_Scale(lin_gain_lf, lin_gain_hf, &gain_exp); + + IF ( gain_fx < 16384) + { + + tmp = mult(tan_val, gain_fx); + norm_num0 = tan_exp + gain_exp; + L_tmp = L_add(L_shl(1, sub( 15, norm_num0) ), tmp); + shift = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, shift); + tmp = extract_h(L_tmp); + pNum[0] = tmp; + norm_num0 = sub( norm_num0, sub(shift, 16) ); + + tmp = mult(tan_val, gain_fx); + norm_num1 = tan_exp + gain_exp; + L_tmp = L_sub(tmp, L_shl(1, sub(15, norm_num1))); + shift = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, shift); + tmp = extract_h(L_tmp); + pNum[1] = tmp; + norm_num1 = sub( norm_num1, sub(shift, 16) ); + + L_tmp = L_add(L_shl(1, sub( 15, tan_exp) ), tan_val); + shift = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, shift); + tmp = extract_h(L_tmp); + pDen[0] = tmp; + norm_den0 = sub( tan_exp, sub(shift, 16 ) ); + + L_tmp = L_sub(tan_val, L_shl(1, sub( 15, tan_exp ) ) ); + shift = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, shift); + tmp = extract_h(L_tmp); + pDen[1] = tmp; + norm_den1 = sub(tan_exp, sub(shift, 16)); + } + ELSE + { + L_tmp = L_add( L_shl(1, (sub( 15, tan_exp ) ) ), tan_val ); + shift = norm_l(L_tmp); + L_tmp = L_shl( L_tmp, shift ); + tmp = extract_h(L_tmp); + pNum[0] = tmp; + norm_num0 = sub( tan_exp, sub( shift, 16) ); + + L_tmp = L_sub( tan_val, L_shl(1, (sub( 15, tan_exp ) ) ) ); + shift = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, shift); + tmp = extract_h(L_tmp); + pNum[1] = tmp; + norm_num1 = sub(tan_exp, sub(shift, 16)); + + tmp = BASOP_Util_Divide1616_Scale(tan_val, gain_fx, &exp); + exp = add( exp, sub(tan_exp, gain_exp) ); + L_tmp = L_add( L_shl(1, sub(15, exp)), tmp ); + shift = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, shift); + tmp = extract_h(L_tmp); + pDen[0] = tmp; + norm_den0 = sub(exp, sub(shift, 16 )) ; + + tmp = BASOP_Util_Divide1616_Scale(tan_val, gain_fx, &exp); + exp = add( exp, sub(tan_exp, gain_exp)); + L_tmp = L_sub( tmp, 1 * L_shl(1, sub(15, exp)) ); + shift = norm_l(L_tmp); + L_tmp = L_shl(L_tmp, shift); + tmp = extract_h(L_tmp); + pDen[1] = tmp; + norm_den1 = sub(exp, sub(shift, 16)); + } + + /* Normalize and adjust gain to match target amplitudes */ + pNum[0] = mult(BASOP_Util_Divide1616_Scale(pNum[0], pDen[0], &exp), lin_gain_hf); + norm_num0 = add( exp, sub(norm_num0, norm_den0) ); + pNum[1] = mult(BASOP_Util_Divide1616_Scale(pNum[1], pDen[0], &exp), lin_gain_hf); + norm_num1 = add( exp, sub(norm_num1, norm_den0) ); + + pDen[1] = BASOP_Util_Divide1616_Scale(pDen[1], pDen[0], &exp); + norm_den1 = add( exp, sub(norm_den1, norm_den0) ); + + pNum[0] = shr(pNum[0],1 - norm_num0); + pNum[1] = shr(pNum[1],1 - norm_num1); + pDen[1] = shr(pDen[1],1 - norm_den1); + pDen[0] = shl(1, 14); + return; +} + +#endif /*-----------------------------------------------------------------------------------------* * Function calc_jot_t60_coeffs() @@ -846,6 +1056,8 @@ static void calc_low_shelf_first_order_filter( * Calculate Jot reverb's T60 filters *-----------------------------------------------------------------------------------------*/ + +#ifndef IVAS_FLOAT_FIXED static ivas_error calc_jot_t60_coeffs( float *pH_dB, const uint16_t nrFrequencies, @@ -912,7 +1124,116 @@ static ivas_error calc_jot_t60_coeffs( return IVAS_ERR_OK; } +#endif + +#ifdef IVAS_FLOAT_FIXED +static ivas_error calc_jot_t60_coeffs_fx( + Word16 *pH_dB_fx, + Word16 pH_dB_exp, + const UWord16 nrFrequencies, + Word16 *pFrequencies_fx, + Word16 *pCoeffA_fx, /* Q14 */ + Word16 *pCoeffB_fx, /* Q14 */ + const Word16 fNyquist_fx ) +{ + Word16 scale1, scale2, scale3, scale4; + Word16 ref_lf_min_norm_fx = BASOP_Util_Divide1616_Scale(REF_LF_MIN_FX, fNyquist_fx, &scale1); + Word16 ref_lf_max_norm_fx = BASOP_Util_Divide1616_Scale(REF_LF_MAX_FX, fNyquist_fx, &scale2); + Word16 ref_hf_min_norm_fx = BASOP_Util_Divide1616_Scale(REF_HF_MIN_FX, fNyquist_fx, &scale3); + Word16 ref_hf_max_norm_fx = BASOP_Util_Divide1616_Scale(REF_HF_MAX_FX, fNyquist_fx, &scale4); + + ref_lf_min_norm_fx = shl(ref_lf_min_norm_fx, scale1 - 1); // Q14 + ref_lf_max_norm_fx = shl(ref_lf_max_norm_fx, scale2 - 1); + ref_hf_min_norm_fx = shl(ref_hf_min_norm_fx, scale3 - 1); + ref_hf_max_norm_fx = shl(ref_hf_max_norm_fx, scale4 - 1); + + Word32 L_tmp; + Word16 f0_fx, tmp_fx, lf_target_gain_dB_fx, hf_target_gain_dB_fx, mid_crossing_gain_dB_fx; + Word16 lin_gain_lf_fx, lin_gain_hf_fx, shift, expl, exph, addl; + int16_t f_idx, minidx, e = pH_dB_exp; + uint16_t n_points_lf, n_points_hf; + + lf_target_gain_dB_fx = 0; + hf_target_gain_dB_fx = 0; + Word32 minval_fx = 1455191552; + Word16 minval_e = 67, exp; + + Word32 L_tmpl = 0, L_tmph = 0; + minidx = nrFrequencies - 1; + n_points_lf = 0; + n_points_hf = 0; + Word16 minidx_fx = nrFrequencies - 1; + + FOR ( f_idx = 0; f_idx < nrFrequencies; f_idx++ ) + { + IF ( ( pFrequencies_fx[f_idx] >= ref_lf_min_norm_fx ) && ( pFrequencies_fx[f_idx] <= ref_lf_max_norm_fx ) ) + { + L_tmpl = L_add( L_tmpl, pH_dB_fx[f_idx] ); + n_points_lf++; + } + IF ( ( pFrequencies_fx[f_idx] >= ref_hf_min_norm_fx ) && ( pFrequencies_fx[f_idx] <= ref_hf_max_norm_fx ) ) + { + L_tmph = L_add(L_tmph, pH_dB_fx[f_idx]); + n_points_hf++; + } + } + shift = norm_l(L_tmpl); + L_tmpl = L_shl(L_tmpl, shift); + tmp_fx = extract_h(L_tmpl); + expl = sub(e, sub(shift, 16)); + lf_target_gain_dB_fx = tmp_fx; + + shift = norm_l(L_tmph); + L_tmph = L_shl(L_tmph, shift); + tmp_fx = extract_h(L_tmph); + exph = sub(e, sub(shift, 16)); + hf_target_gain_dB_fx = tmp_fx; + + IF ( ( n_points_lf == 0 ) || ( n_points_hf == 0 ) ) + { + return IVAS_ERR_INTERNAL; + } + + lf_target_gain_dB_fx = BASOP_Util_Divide1616_Scale( lf_target_gain_dB_fx, n_points_lf, &e ); + expl = e + (expl - 15 ); + + hf_target_gain_dB_fx = BASOP_Util_Divide1616_Scale(hf_target_gain_dB_fx, n_points_hf, &e); + exph = e + ( exph - 15 ); + + e = BASOP_Util_Add_MantExp(lf_target_gain_dB_fx, expl, negate( hf_target_gain_dB_fx ), exph, &tmp_fx); + exp = BASOP_Util_Add_MantExp(hf_target_gain_dB_fx, exph, tmp_fx, e - 1, &mid_crossing_gain_dB_fx); + + FOR ( f_idx = 1; f_idx < nrFrequencies - 1; f_idx++ ) + { + Word16 tmp1; + e = BASOP_Util_Add_MantExp(pH_dB_fx[f_idx], pH_dB_exp, negate(mid_crossing_gain_dB_fx), exp, &tmp_fx); + tmp1 = abs_s(tmp_fx); + tmp_fx = BASOP_Util_Cmp_Mant32Exp(L_deposit_h(tmp1), e, minval_fx, minval_e); + + IF (tmp_fx == -1) + { + minval_fx = L_deposit_h(tmp1); + minval_e = e; + minidx_fx = f_idx; + } + } + + f0_fx = pFrequencies_fx[minidx_fx]; + + tmp_fx = mult(lf_target_gain_dB_fx, 5443); // expl + L_tmp = BASOP_util_Pow2(L_deposit_h(tmp_fx), expl, &e); + lin_gain_lf_fx = (Word16)L_shr(L_tmp, 16 - e); + + tmp_fx = mult(hf_target_gain_dB_fx, 5443); // exph + L_tmp = BASOP_util_Pow2(L_deposit_h(tmp_fx), exph, &e); + lin_gain_hf_fx = (Word16)L_shr(L_tmp, 16 - e); + + /* call low-pass iir shelf */ + calc_low_shelf_first_order_filter_fx( pCoeffB_fx, pCoeffA_fx, f0_fx, lin_gain_lf_fx, lin_gain_hf_fx ); + return IVAS_ERR_OK; +} +#endif /*-----------------------------------------------------------------------------------------* * Function initialize_reverb_filters() @@ -1768,11 +2089,40 @@ ivas_error ivas_reverb_open( #endif // IVAS_FLOAT_FIXED /* set up jot reverb 60 filters - must be set up after set_reverb_acoustic_data() */ + +#ifdef IVAS_FLOAT_FIXED + float *pCoeffs = params.pT60_filter_coeff; + Word16 *pCoeffs_fx = params.pT60_filter_coeff_fx; + params.pRt60_fx = (Word32 *)malloc(sizeof(Word32) * nr_fc_fft_filter); + params.pFc_fx = (Word32 *)malloc(sizeof(Word32) * nr_fc_fft_filter); + params.pRt60_e = (Word16 *)malloc(sizeof(Word16) * nr_fc_fft_filter); + for (int i = 0; i < nr_fc_fft_filter; i++) + { + params.pFc_fx[i] = (Word32)(params.pFc[i] * ONE_IN_Q14); + } + + for (int i = 0; i < nr_fc_fft_filter; i++) + { + f2me(params.pRt60[i], ¶ms.pRt60_fx[i], ¶ms.pRt60_e[i]); + } + + for (int i = 0; i < 64; i++) { + pCoeffs_fx[i] = pCoeffs[i] * ( 1 << 14); + } + if ( ( error = compute_t60_coeffs_fx( ¶ms, nr_fc_fft_filter, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + for (int i = 0; i < 64; i++) { + pCoeffs[i] = (float)pCoeffs_fx[i] / (1 << 14); + } +#else + /* set up jot reverb 60 filters - must be set up after set_reverb_acoustic_data() */ if ( ( error = compute_t60_coeffs( ¶ms, nr_fc_fft_filter, output_Fs ) ) != IVAS_ERR_OK ) { return error; } - +#endif /* Compute target levels (gains) for the coloration filters */ #ifdef IVAS_FLOAT_FIXED Word32 *pFc = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index dfb11cf86..35d6b41bf 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -328,14 +328,29 @@ float deg2rad( return PI_OVER_180 * degrees; } +#ifdef IVAS_FLOAT_FIXED +Word32 deg2rad_fx( + Word32 degrees ) +{ + while ( degrees >= DEGREE_180 ) + { + degrees = degrees - DEGREE_360; + } + while ( degrees <= -DEGREE_180 ) + { + degrees = degrees + DEGREE_360; + } + return Mpy_32_32( PI_OVER_180_FX, degrees ); +} +#endif /*------------------------------------------------------------------------- * rad2deg() * * Converts normalized radians to degrees *------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + float rad2deg( float radians ) { @@ -350,7 +365,7 @@ float rad2deg( return _180_OVER_PI * radians; } -#else +#ifdef IVAS_FLOAT_FIXED Word32 rad2deg_fx( Word32 radians ) { diff --git a/lib_rend/ivas_shoebox.c b/lib_rend/ivas_shoebox.c index 197364bef..0e27d6cad 100644 --- a/lib_rend/ivas_shoebox.c +++ b/lib_rend/ivas_shoebox.c @@ -481,7 +481,7 @@ static void shoebox_get_coord_fx( { FOR ( n = 0; n < loop_ub; n++ ) { - fcnOutput_data[n] = deg2rad( src_pos_data[k + n] ); // not needed //Reshma + fcnOutput_data[n] = deg2rad( src_pos_data[k + n] ); // not needed } } #endif @@ -1062,11 +1062,6 @@ void ivas_shoebox_set_scene( result_gain =L_sub( product , pro_pd_air_coeff); ER_PARAMS->gains.data_fx[rcoselev - 1] = result_gain; - - ER_PARAMS->times.data[( (int32_t) rcoselev ) - 1] = (float) ER_PARAMS->times.data_fx[( (int32_t) rcoselev ) - 1] / 4194304.0; - ER_PARAMS->az_angle.data[( (int32_t) rcoselev ) - 1] = (float) ER_PARAMS->az_angle.data_fx[( (int32_t) rcoselev ) - 1] / 8388608.0; - ER_PARAMS->el_angle.data[( (int32_t) rcoselev ) - 1] = (float) ER_PARAMS->el_angle.data_fx[( (int32_t) rcoselev ) - 1] / 8388608.0; - // ER_PARAMS->gains.data[( (int32_t) rcoselev ) - 1] = (float) ER_PARAMS->gains.data_fx[( (int32_t) rcoselev ) - 1] / 4194304.0; } } return; diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index efc72703b..9bb629f03 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -146,8 +146,9 @@ typedef struct dirac_onset_detection_state_structure float *onset_detector_1; float *onset_detector_2; #ifdef IVAS_FLOAT_FIXED - Word16 *onset_detector_1_fx; - Word16 *onset_detector_2_fx; + Word32 *onset_detector_1_fx; + Word32 *onset_detector_2_fx; + Word16 q_onset_detector; #endif } DIRAC_ONSET_DETECTION_STATE; @@ -188,9 +189,12 @@ typedef struct dirac_decorr_state_structure float *direct_energy_smooth; float *reverb_energy_smooth; #ifdef IVAS_FLOAT_FIXED - Word16 *decorr_buffer_fx; - Word16 *direct_energy_smooth_fx; - Word16 *reverb_energy_smooth_fx; + Word32 *decorr_buffer_fx; + Word16 q_decorr_buffer; + Word32 *direct_energy_smooth_fx; + Word16 q_direct_energy_smooth; + Word32 *reverb_energy_smooth_fx; + Word16 q_reverb_energy_smooth; #endif DIRAC_ONSET_DETECTION_STATE h_onset_detection_power_state; @@ -359,7 +363,9 @@ typedef struct dirac_output_synthesis_state_structure #ifdef IVAS_FLOAT_FIXED /* only pointer to local buffers */ Word32 *direct_responses_fx; /* direct responses for DOA of current frame. Size: num_freq_bands*num_channels. */ + Word16 direct_responses_q; Word32 *direct_responses_square_fx; + Word16 direct_responses_square_q; Word16 *diffuse_responses_square_fx; /* squared diffuse responses. Size: num_channels. */ /* only pointer to local buffers */ @@ -1229,17 +1235,19 @@ typedef struct ivas_reverb_state_t /* Structure to hold the original bitstream metadata */ typedef struct { +#ifndef IVAS_FLOAT_FIXED float room_L; float room_W; float room_H; float abs_coeff[IVAS_ROOM_ABS_COEFF]; float list_orig[3]; - +#else Word32 room_L_fx; Word32 room_W_fx; Word32 room_H_fx; Word32 abs_coeff_fx[IVAS_ROOM_ABS_COEFF]; Word32 list_orig_fx[3]; +#endif } shoebox_config_t; /* Structure to hold the corrected( bounded ) source and listener positions */ @@ -1252,10 +1260,16 @@ typedef struct uint16_t MAX_SOURCES; uint16_t max_bands; uint16_t REF_ORDER; + +#ifndef IVAS_FLOAT_FIXED float src_pos[75]; float src_dist[25]; float list_pos[3]; -#ifdef IVAS_FLOAT_FIXED + float radius; + float min_wall_dist; + float soundspeed; + float air_coeff; +#else Word32 src_dist_fx[25]; Word32 list_pos_fx[3]; Word32 src_pos_fx[75]; @@ -1265,18 +1279,16 @@ typedef struct Word32 air_coeff_fx; #endif // IVAS_FLOAT_FIXED uint16_t nSrc; - float radius; - float min_wall_dist; - float soundspeed; - float air_coeff; + shoebox_config_t cal; } shoebox_obj_t; typedef struct shoebox_data_t { +#ifndef IVAS_FLOAT_FIXED float data[150]; -#ifdef IVAS_FLOAT_FIXED +#else Word32 data_fx[150]; #endif Word32 size[1]; @@ -1298,7 +1310,7 @@ typedef struct /*----------------------------------------------------------------------------------* * Reflections structure *----------------------------------------------------------------------------------*/ -#ifdef IVAS_FLOAT_FIXED + /* Structure to hold the original source positions */ typedef struct er_struct_t { @@ -1319,10 +1331,12 @@ typedef struct er_struct_t Word32 output_Fs_fx; Word32 source_positions_fx[75]; Word32 user_origin_fx[3]; //is not needed -#endif - float output_Fs; +#else float source_positions[75]; float user_origin[3]; + float output_Fs; +#endif + Word32 *circ_buffers; UWord16 *closest_ch_idx; shoebox_output_t shoebox_data; @@ -1330,32 +1344,7 @@ typedef struct er_struct_t } er_struct_t; -#else -typedef struct er_struct_t -{ - AUDIO_CONFIG audio_config; - int16_t nchan_out; - uint16_t use_er; - uint32_t lowComplexity; - uint16_t n_LC_sources; - uint16_t *LC_mixing; - uint16_t is_ready; - uint16_t circ_len; - uint16_t circ_insert; - uint16_t n_total_reflections; - uint16_t is_cartesian; - uint16_t is_relative; - uint32_t max_frame_size; - float output_Fs; - float source_positions[75]; - float user_origin[3]; - float *circ_buffers; - uint16_t *closest_ch_idx; - shoebox_output_t shoebox_data; - shoebox_obj_t shoebox_lib; -} er_struct_t; -#endif /*----------------------------------------------------------------------------------* * TD ISM Object Renderer structure *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_td_decorr.c b/lib_rend/ivas_td_decorr.c index 079b2bd30..4bb8cc49e 100644 --- a/lib_rend/ivas_td_decorr.c +++ b/lib_rend/ivas_td_decorr.c @@ -846,9 +846,9 @@ void ivas_td_decorr_process_fx( FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[0][j] = Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ); + ppOut_pcm[0][j] = L_shl(Mpy_32_32( ppOut_pcm[0][j], in_duck_gain[j] ), 1); } - *q_format -= Q1; + *q_format -= 0; } FOR( i = 1; i < hTdDecorr->num_apd_outputs; i++ ) @@ -866,10 +866,10 @@ void ivas_td_decorr_process_fx( { FOR( j = 0; j < output_frame; j++ ) { - ppOut_pcm[i][j] = Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ); + ppOut_pcm[i][j] = L_shl(Mpy_32_32( ppOut_pcm[i][j], out_duck_gain[j] ), 1); } } - *q_format -= Q1; + *q_format -= 0; } return; diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index b45c4549c..a579af75d 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -881,7 +881,7 @@ void vbap_determine_gains_fx( back_virtual_speaker_node_division_gains_fx = hVBAPdata->back_virtual_speaker_node_division_gains_fx; } - panning_wrap_angles_fixed( (Word32) azi_deg * ( 1 << 22 ), (Word32) ele_deg * ( 1 << 22 ), &azi_temp_fx, &ele_temp_fx ); + panning_wrap_angles_fixed( L_shl( azi_deg, 22 ), L_shl( ele_deg, 22 ), &azi_temp_fx, &ele_temp_fx ); azi_norm = L_shr( Mpy_32_16_1( azi_temp_fx, 91 ), 7 ); ele_norm = L_shr( Mpy_32_16_1( ele_temp_fx, 91 ), 7 ); diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 2e04b8a91..21bb1e7fc 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7340,7 +7340,7 @@ static ivas_error renderIsmToBinauralRoom( nchan = hCrend->reflections->shoebox_data.n_sources + 1; for ( i = 0; i < 150; i++ ) { - hCrend->reflections->shoebox_data.gains.data_fx[i] = (Word32) ( hCrend->reflections->shoebox_data.gains.data[i] * ONE_IN_Q31 ); + hCrend->reflections->shoebox_data.gains.data_fx[i] = L_shl( hCrend->reflections->shoebox_data.gains.data_fx[i], 9 ); } } } -- GitLab From 9259962e7bedc87f4a567c702b3234cc903a5253 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 10 Apr 2024 09:51:26 +0530 Subject: [PATCH 2/4] EVS bitexactness test fix --- lib_com/enhancer_fx.c | 4 ++-- lib_com/prot_fx2.h | 1 - lib_dec/acelp_core_dec_ivas_fx.c | 2 +- lib_dec/bass_psfilter_fx.c | 10 +++++----- lib_dec/dec_gen_voic_fx.c | 4 ++-- lib_dec/dec_uv_fx.c | 18 ++++++++++++++---- lib_dec/fd_cng_dec_fx.c | 2 +- lib_dec/tcx_utils_dec_fx.c | 1 - 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/lib_com/enhancer_fx.c b/lib_com/enhancer_fx.c index 316c28dc9..d53a92951 100644 --- a/lib_com/enhancer_fx.c +++ b/lib_com/enhancer_fx.c @@ -443,7 +443,7 @@ void enhancer_ivas_fx( sc = 6; move16(); - gain_code_hi = extract_h(L_shl_sat(L_tmp, add(Q_exc, 3))); /* in Q_exc */ + gain_code_hi = round_fx(L_shl(L_tmp, add(Q_exc, 3))); /* in Q_exc */ /*------------------------------------------------------------* * pitch enhancer @@ -458,7 +458,7 @@ void enhancer_ivas_fx( /* Copy(code, exc2, L_SUBFR) */ FOR(i = 0; i < L_SUBFR; i++) { - pt_exc2[i] = extract_h(L_shl_sat(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */ + pt_exc2[i] = round_fx(L_shl(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */ } } ELSE diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index b91a07fb6..362e51c91 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -7992,7 +7992,6 @@ void generate_comfort_noise_dec_hf_ivas_fx( Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 Q_exc, Word16 *gain_buf ); diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 0c2ce8fc8..b2aa20736 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1156,7 +1156,7 @@ ivas_error acelp_core_dec_ivas_fx( /* UNVOICED frames */ //decod_unvoiced( st, Aq, Es_pred, uc_two_stage_flag, &tmp_noise, pitch_buf, voice_factors, exc, exc2, bwe_exc, gain_buf ); //decod_unvoiced_fx( st, Aq_fx, st->coder_type, &tmp_noise_fx, pitch_buf_out_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx); - decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, st->Q_exc, gain_buf_fx); + decod_unvoiced_ivas_fx( st, Aq_fx, Es_pred_fx, uc_two_stage_flag, st->coder_type, &tmp_noise_fx, pitch_buf_fx, voice_factors_fx, exc_fx, exc2_fx, bwe_exc_fx, gain_buf_fx); tmp_noise_fx = shr_r(st->lp_gainc_fx, 3); /*Q0*/ } else if ( st->ppp_mode_dec) diff --git a/lib_dec/bass_psfilter_fx.c b/lib_dec/bass_psfilter_fx.c index c796af9b8..92a25f21c 100644 --- a/lib_dec/bass_psfilter_fx.c +++ b/lib_dec/bass_psfilter_fx.c @@ -323,10 +323,10 @@ void bass_psfilter_fx( { Lcorr0 = L_mult0( syn_fx[j], syn2_fx[j]); Lener0 = L_mult0(syn2_fx[j], syn2_fx[j]); - Lcorr0 = L_mac0_sat(Lcorr0, syn_fx[j+1], syn2_fx[j+1]); - Lener0 = L_mac0_sat(Lener0, syn2_fx[j+1], syn2_fx[j+1]); + Lcorr0 = L_mac0(Lcorr0, syn_fx[j+1], syn2_fx[j+1]); + Lener0 = L_mac0(Lener0, syn2_fx[j+1], syn2_fx[j+1]); - Lcorr = L_add_sat(Lcorr, L_shr(Lcorr0, 4)); + Lcorr = L_add(Lcorr, L_shr(Lcorr0, 4)); Lener = L_add(Lener, L_shr(Lener0, 4)); /* this loop is not efficient but it provide a respectable precision while avoiding overflow. */ @@ -403,7 +403,7 @@ void bass_psfilter_fx( exp2 = sub(exp, exp2); /* exponent num - exponent denom */ /* alpha = corr / ener */ #ifdef BASOP_NOGLOB - alpha = shr_sat(div_s(round_fx_sat(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ + alpha = shr_sat(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ #else alpha = shr(div_s(round_fx(L_shl(Ltmp, exp)), tmp2), exp2); /*Q15 */ #endif @@ -452,7 +452,7 @@ void bass_psfilter_fx( FOR (i=0; i< subfr_len; i++) { /*syn2_fx[i] = alpha*(syn_fx[i]-syn2_fx[i]); */ - tmp = sub_sat(syn_fx[i],syn2_fx[i]); + tmp = sub(syn_fx[i],syn2_fx[i]); #ifdef BASOP_NOGLOB syn2_fx[i] = mult_sat(alpha, shl_sat(tmp, 1)); #else diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 5203f0016..37d61e921 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -684,7 +684,7 @@ ivas_error decod_gen_voic_ivas_fx( IF(EQ_16(L_frame, L_FRAME)) /* Rescaling for 12.8k core */ { - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL)?&bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type); } @@ -692,7 +692,7 @@ ivas_error decod_gen_voic_ivas_fx( { L_tmp_GC = L_max(gain_code_fx, L_shl(gain_preQ_fx,16)); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, + Rescale_exc(hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * 2, L_tmp_GC, &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type); } diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 58a9db842..fa92f1634 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -119,7 +119,6 @@ void decod_unvoiced_ivas_fx( Word16 *exc_fx, /* Q_X o : adapt. excitation exc */ Word16 *exc2_fx, /* Q_X o : adapt. excitation/total exc */ Word16 *bwe_exc_fx, /* Q_X i/o: excitation for SWB TBE */ - Word16 Q_exc, Word16 *gain_buf ) { @@ -189,7 +188,7 @@ void decod_unvoiced_ivas_fx( gain_dec_gacelp_uv(index, code_fx, code2_fx, Es_pred_fx, L_SUBFR, &gain_pit_fx, &gain_code_fx, &gain_code2_fx, &(st_fx->past_gpit), &norm_gain_code_fx, &gain_inov_fx); //st->tilt_code = est_tilt(exc + i_subfr, gain_pit, code, gain_code, &voice_fac, L_SUBFR, 0); - st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_exc, L_SUBFR, 0); + st_fx->tilt_code_fx = est_tilt_ivas_fx(exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0); /* update LP filtered gains for the case of frame erasures */ //lp_gain_updt(i_subfr, gain_pit, norm_gain_code, &st->lp_gainp, &st->lp_gainc, L_FRAME); @@ -199,14 +198,25 @@ void decod_unvoiced_ivas_fx( * - Find the total excitation. * *-------------------------------------------------------*/ + IF(EQ_16(st_fx->L_frame, L_FRAME)) + { + Rescale_exc(st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); + } + ELSE + { + Rescale_exc(st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); + } + for (int i = 0; i < L_SUBFR; i++) { /*exc2[i + i_subfr] = gain_pit * exc[i + i_subfr]; //Q14 exc2[i + i_subfr] += gain_code2 * code2[i]; //Q16 exc[i + i_subfr] = exc2[i + i_subfr] + gain_code * code[i];*/ //Q16 exc2_fx[i + i_subfr_fx] = shl( mult_r( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 2 ); // Q_exc - exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), Q10 - Q_exc ) ) ); // Q_exc - exc_fx[i + i_subfr_fx] = add_sat( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - Q_exc ) ) ); // Q_exc + exc2_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code2_fx, code2_fx[i] ), Q10 - st_fx->Q_exc) ) ); // Q_exc + exc_fx[i + i_subfr_fx] = add( exc2_fx[i + i_subfr_fx], extract_l( L_shr( Mpy_32_16_1( gain_code_fx, code_fx[i] ), Q10 - st_fx->Q_exc) ) ); // Q_exc } //Scale_sig(code_fx, L_SUBFR, 3); //Q12 } diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index b1fd76821..b215d98b4 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1759,7 +1759,7 @@ Word16 ApplyFdCng_fx( { FOR( ; j <= hFdCngCom->part[k]; j++ ) { - cngNoiseLevel[j] = L_shl_sat( cngNoiseLevel[j], s ); + cngNoiseLevel[j] = L_shl( cngNoiseLevel[j], s ); move32(); } } diff --git a/lib_dec/tcx_utils_dec_fx.c b/lib_dec/tcx_utils_dec_fx.c index e2edbd8d2..a3761f2cb 100644 --- a/lib_dec/tcx_utils_dec_fx.c +++ b/lib_dec/tcx_utils_dec_fx.c @@ -56,7 +56,6 @@ void tcx_decoder_memory_update( tmp = synth[-M - 1]; move16(); st->Q_syn = E_UTIL_f_preemph3(synth - M, preemph, add(M, L_frame_glob), &tmp, 1); - st->Q_syn = s_min(st->Q_syn, 8); st->prev_Q_syn = st->Q_syn = st->Q_syn - 1; Copy(synth + sub(L_frame_glob, M), st->mem_syn2_fx, M); Copy(synth + sub(L_frame_glob, L_SYN_MEM), st->mem_syn_r, L_SYN_MEM); -- GitLab From d4bdd3a0f8eb3ea3d93d0aec3a62b05e1765129c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 10 Apr 2024 10:03:51 +0530 Subject: [PATCH 3/4] Updated max function usage with L_max --- lib_dec/dec_uv_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index fa92f1634..f8a069799 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -201,12 +201,12 @@ void decod_unvoiced_ivas_fx( IF(EQ_16(st_fx->L_frame, L_FRAME)) { Rescale_exc(st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); + L_SUBFR, L_SUBFR* HIBND_ACB_L_FAC, L_max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); } ELSE { Rescale_exc(st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], (bwe_exc_fx != NULL) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); + L_SUBFR, L_SUBFR * 2, L_max(gain_code2_fx, gain_code_fx), &(st_fx->Q_exc), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED); } for (int i = 0; i < L_SUBFR; i++) -- GitLab From 5d78d24a8171b42c8f633929a6ebcc8cc77f6122 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 10 Apr 2024 12:37:09 +0530 Subject: [PATCH 4/4] Crash fix for -10dB streams --- lib_dec/acelp_core_dec_ivas_fx.c | 5 +++++ lib_dec/fd_cng_dec_fx.c | 28 ++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index b2aa20736..2e3027b23 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -1817,7 +1817,12 @@ ivas_error acelp_core_dec_ivas_fx( //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; // Q4 //floatToFixed_arrL(st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); //Scale_sig(syn_tmp_fx, L_FRAME16k + L_SUBFR, 0 - st->Q_syn); //Q0 + Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - Q27); + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q4; // Q4 + Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEst, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27); + Scale_sig32(st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART, st->hFdCngDec->hFdCngCom->sidNoiseEstExp - Q27); + st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 /*==========================================================*/ //ApplyFdCng_fx( syn_fx + L_SUBFR, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index b215d98b4..dfad52f14 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1531,18 +1531,8 @@ Word16 ApplyFdCng_fx( } test(); test(); - W_tmp = 0; - FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) - { - W_tmp = W_add( W_tmp, L_shr( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); - } - L_tmp = W_extract_h( W_shl( W_tmp, 32 ) ); - L_tmp_exp = 31; -#ifdef BASOP_NOGLOB - IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( L_shl_o( L_tmp, L_tmp_exp, &Overflow ) > 21474836 /*0.01f Q31*/ ) ) -#else - IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) && ( L_shl( L_tmp, L_tmp_exp ) > 21474836 /*0.01f Q31*/ ) ) -#endif + + IF( EQ_16( concealWholeFrame, 1 ) && EQ_16( st->nbLostCmpt, 1 ) ) { /* always set psychParameters for MDCT-Stereo ... */ IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->hTonalMDCTConc != NULL ) @@ -1550,6 +1540,19 @@ Word16 ApplyFdCng_fx( st->hTonalMDCTConc->psychParams = EQ_16( st->core, TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10; } /* update isf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/ + W_tmp = 0; + FOR( j = hFdCngCom->startBand; j < hFdCngCom->stopFFTbin; j++ ) + { + W_tmp = W_add( W_tmp, L_shr( cngNoiseLevel[j], sub( 31, *cngNoiseLevel_exp ) ) ); + } + L_tmp = W_extract_h( W_shl( W_tmp, 32 ) ); + L_tmp_exp = 31; +#ifdef BASOP_NOGLOB + IF(L_shl_o(L_tmp, L_tmp_exp, &Overflow) > 21474836 /*0.01f Q31*/) +#else + IF( L_shl( L_tmp, L_tmp_exp ) > 21474836 /*0.01f Q31*/ ) +#endif + { IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && NE_16( st->core, ACELP_CORE ) ) { TonalMdctConceal_whiten_noise_shape_ivas_fx( st, L_frame, ON_FIRST_LOST_FRAME ); @@ -1566,6 +1569,7 @@ Word16 ApplyFdCng_fx( st->plcBackgroundNoiseUpdated = 1; move16(); } + } BREAK; case SID_FRAME: -- GitLab