From 5d6c4273cc92830101bcee51323aebfe8d07c07a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 29 Apr 2024 08:43:53 +0530 Subject: [PATCH] Float code cleanup changes --- lib_com/calc_st_com.c | 4 +- lib_com/ivas_ism_com.c | 26 +- lib_com/ivas_prot.h | 21 +- lib_com/prot.h | 10 - lib_com/swb_tbe_com.c | 2 +- lib_dec/cng_dec.c | 78 ++- lib_dec/core_dec_init.c | 663 ++++++++++++++++++- lib_dec/core_dec_switch.c | 2 +- lib_dec/fd_cng_dec.c | 70 +- lib_dec/igf_dec_fx.c | 6 - lib_dec/init_dec.c | 66 +- lib_dec/ivas_binRenderer_internal.c | 256 ++++++- lib_dec/ivas_jbm_dec.c | 56 +- lib_dec/ivas_mc_param_dec.c | 293 +++++++- lib_dec/ivas_spar_md_dec.c | 273 +++++++- lib_dec/jbm_pcmdsp_apa.c | 362 +++++++++- lib_dec/jbm_pcmdsp_window.c | 137 ++-- lib_dec/jbm_pcmdsp_window.h | 10 +- lib_dec/swb_tbe_dec_fx.c | 1 - lib_dec/tonalMDCTconcealment.c | 3 +- lib_rend/ivas_dirac_dec_binaural_functions.c | 52 +- lib_rend/ivas_reflections.c | 91 ++- lib_rend/ivas_stat_rend.h | 4 +- 23 files changed, 2207 insertions(+), 279 deletions(-) diff --git a/lib_com/calc_st_com.c b/lib_com/calc_st_com.c index 4a1369c10..3c263838c 100644 --- a/lib_com/calc_st_com.c +++ b/lib_com/calc_st_com.c @@ -95,14 +95,14 @@ static void calc_rc0_h( /*---------------------------------------------------------------------------- - * calc_st_filt_fx() + * calc_st_filt() * * computes impulse response of A(gamma2) / A(gamma1) * controls gain : computation of energy impulse response as * SUMn (abs (h[n])) and computes parcor0 *---------------------------------------------------------------------------- */ -void calc_st_filt_fx( +void calc_st_filt( const float *apond2, /* i : coefficients of numerator */ const float *apond1, /* i : coefficients of denominator */ float *parcor0, /* o : 1st parcor calcul. on composed filter */ diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 45057f786..873e7c609 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -787,6 +787,16 @@ void ivas_ism_reset_metadata_enc( return; } + +void ivas_ism_reset_metadata_API( + ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ +) +{ + ivas_ism_reset_metadata_enc(hIsmMeta); + + return; +} + #else void ivas_ism_reset_metadata( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ @@ -802,6 +812,15 @@ void ivas_ism_reset_metadata( return; } + +void ivas_ism_reset_metadata_API( + ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ +) +{ + ivas_ism_reset_metadata(hIsmMeta); + + return; +} #endif /*-------------------------------------------------------------------* @@ -810,14 +829,7 @@ void ivas_ism_reset_metadata( * Reset ISM metadata parameters *-------------------------------------------------------------------*/ -void ivas_ism_reset_metadata_API( - ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ -) -{ - ivas_ism_reset_metadata_enc( hIsmMeta ); - return; -} /*-------------------------------------------------------------------* diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 77c676e8d..ddaddc3e1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -503,7 +503,7 @@ ivas_error ivas_core_enc( const int16_t ivas_format, /* i : IVAS format */ const int16_t flag_16k_smc /* i : flag to indicate if the OL SMC is run at 16 kHz */ ); - +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_core_dec( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ @@ -515,6 +515,20 @@ ivas_error ivas_core_dec( Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ); +#else +ivas_error ivas_core_dec( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ + const int16_t n_channels, /* i : number of channels to be decoded */ + float *output[], /* o : output synthesis signal */ + float outputHB[][L_FRAME48k], /* o : output HB synthesis signal */ + float DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ + const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ +); +#endif + void encod_gen_2sbfr( Encoder_State *st, /* i/o: state structure */ @@ -1095,11 +1109,10 @@ void bitbudget_to_brate( void ivas_ism_reset_metadata( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */ ); -#ifdef IVAS_FLOAT_FIXED //to be removed when converting encoder + void ivas_ism_reset_metadata_enc( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle */ ); -#endif void ivas_ism_reset_metadata_API( ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handles */ ); @@ -4982,7 +4995,7 @@ void FdCngEncodeDiracMDCTStereoSID( CPE_ENC_HANDLE hCPE /* i/o: CPE encoder state structure */ ); -void FdCngDecodeDiracMDCTStereoSID_fx( +void FdCngDecodeDiracMDCTStereoSID( CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */ ); diff --git a/lib_com/prot.h b/lib_com/prot.h index 86cfc35c1..bc84c7a92 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -2530,16 +2530,6 @@ void calc_st_filt( const int16_t extl /* i : extension layer info */ ); -void calc_st_filt_fx( - const float *apond2, /* i : coefficients of numerator */ - const float *apond1, /* i : coefficients of denominator */ - float *parcor0, /* o : 1st parcor calcul. on composed filter */ - float *sig_ltp_ptr, /* i/o: input of 1/A(gamma1) : scaled by 1/g0 */ - float *mem_zero, /* i/o: All zero memory */ - const int16_t L_subfr, /* i : the length of subframe */ - const int16_t extl /* i : extension layer info */ - -); void scale_st_ivas( const float *sig_in, /* i : postfilter input signal */ diff --git a/lib_com/swb_tbe_com.c b/lib_com/swb_tbe_com.c index 1bdb0fa10..b27fb86b2 100644 --- a/lib_com/swb_tbe_com.c +++ b/lib_com/swb_tbe_com.c @@ -743,7 +743,7 @@ void PostShortTerm( sig_ltp[0] = *ptr_mem_stp; /* Control short term pst filter gain and compute parcor0 */ - calc_st_filt_fx( apond2, apond1, &parcor0, sig_ltp + 1, mem_zero, L_SUBFR16k, SWB_TBE ); + calc_st_filt( apond2, apond1, &parcor0, sig_ltp + 1, mem_zero, L_SUBFR16k, SWB_TBE ); /* 1/A(gamma1) filtering, mem_stp is updated */ syn_filt( apond1, LPC_SHB_ORDER, sig_ltp + 1, sig_ltp + 1, L_SUBFR16k, mem_stp, 1 ); diff --git a/lib_dec/cng_dec.c b/lib_dec/cng_dec.c index a6a2e306b..a09cc90fc 100644 --- a/lib_dec/cng_dec.c +++ b/lib_dec/cng_dec.c @@ -766,7 +766,7 @@ static void shb_CNG_decod( * * *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void td_cng_dec_init( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) @@ -843,4 +843,80 @@ void td_cng_dec_init( return; } +#else +void td_cng_dec_init( + DEC_CORE_HANDLE st /* i/o: decoder state structure */ +) +{ + int16_t i; + TD_CNG_DEC_HANDLE hTdCngDec; + + hTdCngDec = st->hTdCngDec; + + hTdCngDec->cng_seed = RANDOM_INITSEED; + hTdCngDec->cng_ener_seed = RANDOM_INITSEED; + hTdCngDec->cng_ener_seed1 = RANDOM_INITSEED; + hTdCngDec->old_enr_index = -1; + hTdCngDec->Enew = 0.0f; + mvr2r(st->lsp_old, st->lspCNG, M); + hTdCngDec->last_allow_cn_step = 0; + hTdCngDec->shb_cng_ener = -6.02f; + if (st->element_mode != EVS_MONO) + { + set_f(hTdCngDec->shb_lpcCNG, 0.0f, LPC_SHB_ORDER + 1); + hTdCngDec->shb_lpcCNG[0] = 1.0f; + hTdCngDec->shb_cng_gain = -82.0; /* a dB value approximately corresponding to shb index 0(used as index -15) */ + } + + hTdCngDec->wb_cng_ener = -6.02f; + hTdCngDec->last_wb_cng_ener = -6.02f; + hTdCngDec->last_shb_cng_ener = -6.02f; + hTdCngDec->swb_cng_seed = RANDOM_INITSEED; + hTdCngDec->ho_hist_ptr = -1; + hTdCngDec->ho_sid_bw = 0; + set_f(hTdCngDec->ho_lsp_hist, 0, HO_HIST_SIZE * M); + set_f(hTdCngDec->ho_ener_hist, 0, HO_HIST_SIZE); + set_f(hTdCngDec->ho_env_hist, 0, HO_HIST_SIZE * NUM_ENV_CNG); + hTdCngDec->ho_hist_size = 0; + hTdCngDec->act_cnt = 0; + hTdCngDec->ho_circ_ptr = -1; + set_f(hTdCngDec->ho_lsp_circ, 0, HO_HIST_SIZE * M); + set_f(hTdCngDec->ho_ener_circ, 0, HO_HIST_SIZE); + set_f(hTdCngDec->ho_env_circ, 0, HO_HIST_SIZE * NUM_ENV_CNG); + hTdCngDec->ho_circ_size = 0; + + set_s(hTdCngDec->ho_16k_lsp, 0, HO_HIST_SIZE); + st->CNG_mode = -1; + hTdCngDec->act_cnt2 = 0; + hTdCngDec->num_ho = 0; + set_f(hTdCngDec->lp_env, 0.0f, NUM_ENV_CNG); + set_f(hTdCngDec->exc_mem, 0.0f, 24); + set_f(hTdCngDec->exc_mem1, 0.0f, 30); + set_f(hTdCngDec->old_env, 0.0f, NUM_ENV_CNG); + + for (i = 0; i < LPC_SHB_ORDER; i++) + { + if (st->element_mode != EVS_MONO) + { + hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)(i + 1)) / ((float)(LPC_SHB_ORDER + 1)); + } + else + { + hTdCngDec->lsp_shb_prev[i] = 0.5f * ((float)i) / ((float)LPC_SHB_ORDER); + } + hTdCngDec->lsp_shb_prev_prev[i] = hTdCngDec->lsp_shb_prev[i]; + } + + hTdCngDec->shb_dtx_count = 0; + hTdCngDec->trans_cnt = 0; + hTdCngDec->burst_cnt = 0; + + hTdCngDec->last_shb_ener = 0.001f; + + + set_f(hTdCngDec->interpol_3_2_cng_dec, 0.0f, INTERP_3_2_MEM_LEN); + + return; +} +#endif #endif \ No newline at end of file diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index 4c6e4be3e..112074bcc 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -47,7 +47,7 @@ * * Initialization of state variables *-----------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void open_decoder_LPD( Decoder_State *st, /* i/o: decoder state structure */ const int32_t total_brate, /* i : total bitrate */ @@ -782,7 +782,668 @@ void open_decoder_LPD( return; } +#else +void open_decoder_LPD( + Decoder_State *st, /* i/o: decoder state structure */ + const int32_t total_brate, /* i : total bitrate */ + const int32_t last_total_brate, /* i : last total bitrate */ + const int16_t bwidth, /* i : audio bandwidth */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t last_element_mode, /* i : last element mode */ + const int16_t is_init /* i : indicate call during initialization */ +) +{ + int16_t i; + int16_t mem_syn_r_size_old; + int16_t mem_syn_r_size_new; + int16_t fscaleFB; + int16_t encoderLookahead, encoderLookaheadFB; + TCX_LTP_DEC_HANDLE hTcxLtpDec = st->hTcxLtpDec; + TCX_DEC_HANDLE hTcxDec = st->hTcxDec; + + if (st->codec_mode != MODE1) /*already updated in MODE1*/ + { + st->fscale_old = st->fscale; + } + + st->sr_core = getCoreSamplerateMode2_flt(st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format); + st->fscale = sr2fscale(st->sr_core); + fscaleFB = sr2fscale(st->output_Fs); + + /* initializing variables for frame lengths etc. right in the beginning */ + st->L_frame = (int16_t)(st->sr_core / FRAMES_PER_SEC); + if (st->ini_frame == 0) + { + st->last_L_frame = st->L_frame_past = st->L_frame; + } + if (st->hTcxDec != NULL) + { + st->hTcxDec->L_frameTCX = (int16_t)(st->output_Fs / FRAMES_PER_SEC); + if (st->ini_frame == 0) + { + st->L_frameTCX_past = st->hTcxDec->L_frameTCX; + } + } + + st->tcxonly = getTcxonly_ivas(st->element_mode, total_brate, MCT_flag, st->is_ism_format); + + /* the TD TCX PLC in MODE1 still runs with 80ms subframes */ + if ((st->element_mode == EVS_MONO && st->L_frame == L_FRAME16k && total_brate <= ACELP_32k) || (st->element_mode > EVS_MONO && st->L_frame == L_FRAME16k && total_brate <= MAX_ACELP_BRATE) || (st->tcxonly && (st->sr_core == 32000 || st->sr_core == 16000))) + { + st->nb_subfr = NB_SUBFR16k; + } + else + { + st->nb_subfr = NB_SUBFR; + } + st->bits_frame = (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f); + st->TcxBandwidth_float = getTcxBandwidth_flt(bwidth); + st->narrowBand = (bwidth == NB) ? 1 : 0; + encoderLookahead = (L_LOOK_12k8 * st->fscale) / FSCALE_DENOM; + encoderLookaheadFB = (L_LOOK_12k8 * fscaleFB) / FSCALE_DENOM; + + if (st->element_mode == IVAS_CPE_MDCT) + { + st->pit_res_max = initPitchLagParameters(12800, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / 12800); + hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / 12800); + } + else + { + st->pit_res_max = initPitchLagParameters(st->sr_core, &st->pit_min, &st->pit_fr1, &st->pit_fr1b, &st->pit_fr2, &st->pit_max); + if (hTcxDec != NULL) + { + hTcxDec->pit_max_TCX = (int16_t)(st->pit_max * st->output_Fs / st->sr_core); + hTcxDec->pit_min_TCX = (int16_t)(st->pit_min * st->output_Fs / st->sr_core); + } + } + + if (st->ini_frame == 0) + { + st->pit_res_max_past = st->pit_res_max; + } + + /*Preemphasis param*/ + if (st->fscale < (16000 * FSCALE_DENOM) / 12800) + { + st->preemph_fac_float = PREEMPH_FAC_FLT; /*NB*/ + } + else if (st->fscale < (24000 * FSCALE_DENOM) / 12800) + { + st->preemph_fac_float = PREEMPH_FAC_16k_FLT; /*WB*/ + } + else + { + st->preemph_fac_float = PREEMPH_FAC_SWB_FLT; /*SWB*/ + } + + if (st->sr_core == INT_FS_16k) + { + st->gamma_float = GAMMA16k_FLT; + } + else if (st->sr_core > INT_FS_16k && st->element_mode == IVAS_CPE_MDCT) + { + st->gamma_float = GAMMA16k_FLT; + } + else + { + st->gamma_float = GAMMA1_FLT; + } + + /* LPC quantization */ + if (st->sr_core <= INT_FS_16k && st->tcxonly == 0) + { + st->lpcQuantization = 1; + } + else + { + st->lpcQuantization = 0; + } + + if (st->tcxonly == 0) + { + st->numlpc = 1; + } + else + { + st->numlpc = 2; + } + + /* Initialize TBE */ + st->prev_coder_type = GENERIC; + if (st->hBWE_TD != NULL) + { + set_f(st->hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2); + st->hBWE_TD->prev_tilt_para = 0.0f; + set_zero(st->hBWE_TD->cur_sub_Aq, M + 1); + } + + if (st->hIGFDec != NULL) + { + if (!is_init || st->element_mode != IVAS_CPE_MDCT) + { + init_tcx_cfg(st->hTcxCfg, total_brate, st->sr_core, st->output_Fs, st->L_frame, st->bwidth, st->hTcxDec->L_frameTCX, st->fscale, encoderLookahead, encoderLookaheadFB, st->preemph_fac_float, st->tcxonly, st->rf_flag, st->igf, st->hIGFDec->infoIGFStopFreq, st->element_mode, st->ini_frame, MCT_flag); + } + else + { + st->hTcxCfg->tcx_curr_overlap_mode = st->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; + st->hTcxCfg->last_aldo = 1; + } + } + + if (st->hTECDec != NULL) + { + resetTecDec(st->hTECDec); + } + + if (st->element_mode != IVAS_SCE) + { + st->flag_cna = 0; + } + if (st->ini_frame == 0) + { + st->flag_cna = 0; + st->last_flag_cna = 0; + } + + /* Static vectors to zero */ + if (st->ini_frame == 0) + { + st->last_is_cng = 0; + + st->rate_switching_reset = 0; + + if (st->hTcxDec != NULL) + { + reset_tcx_overl_buf(st->hTcxDec); + + set_zero(st->hTcxDec->syn_OverlFB_float, L_FRAME_MAX / 2); + set_zero(st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC); + + set_zero(st->hTcxDec->synth_history, L_PROT48k + L_FRAME_MAX); + } + + set_zero(st->syn_float, M + 1); + + set_zero(st->mem_syn_r_float, L_SYN_MEM); + + mem_syn_r_size_old = 0; /* just to avoid MSVC warnings */ + mem_syn_r_size_new = 0; /* just to avoid MSVC warnings */ + + st->con_tcx = 0; + } + else + { + /* Reset old_synth in case of core sampling rate switching and Mode 1/2 switching*/ + if (st->hTcxDec != NULL && ((st->L_frame != st->last_L_frame) || (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO))) + { + set_zero(st->hTcxDec->old_synth_float, OLD_SYNTH_INTERNAL_DEC); + } + + /*Compute size of old and new memories*/ + mem_syn_r_size_old = (int16_t)(1.25 * st->last_L_frame / 20.f); + mem_syn_r_size_new = (int16_t)(1.25 * st->L_frame / 20.f); + + /*Reset LPC mem*/ + if ((st->L_frame != st->last_L_frame) || (st->last_core == AMR_WB_CORE) || (st->last_core == HQ_CORE)) + { + set_zero(st->mem_MA, M); + if (st->sr_core == INT_FS_16k) + { + mvr2r(GEWB2_Ave, st->mem_AR, M); + } + else + { + mvr2r(GEWB_Ave, st->mem_AR, M); + } + } + + /*Mode 1/2 switching*/ + if (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO) + { + mvr2r(st->lsp_old, st->lspold_uw_float, M); + mvr2r(st->lsf_old, st->lsfold_uw_float, M); + set_zero(st->syn_float, M); + } + if (st->last_core == AMR_WB_CORE) + { + st->last_core = ACELP_CORE; + st->last_core_bfi = ACELP_CORE; + } + + if (((st->element_mode != IVAS_CPE_DFT) || (st->element_mode == IVAS_CPE_DFT && st->prev_bfi)) && st->last_codec_mode == MODE1 && st->last_core == ACELP_CORE) + { + /* Switching from Mode 1 ACELP */ + st->last_core_bfi = ACELP_CORE; + acelp_plc_mdct_transition(st); + } + + if (st->last_codec_mode == MODE2 && + st->L_frame != st->last_L_frame && + ((st->m_frame_type == SID_FRAME && st->last_core > ACELP_CORE) || + (st->last_core > ACELP_CORE && st->core > ACELP_CORE) || st->prev_bfi)) + { + lerp_flt(st->hHQ_core->old_outLB, st->hHQ_core->old_outLB, st->L_frame, st->last_L_frame); + } + + /* Rate switching */ + if (st->last_codec_mode == MODE1 && st->last_core == HQ_CORE) + { + /* Switching from MDCT */ + + /*Reset of ACELP memories*/ + st->rate_switching_reset = 1; + st->tilt_code = TILT_CODE_FLT; + set_zero(st->old_exc, L_EXC_MEM_DEC); + set_zero(st->syn_float, 1 + M); + set_zero(st->mem_syn2, M); + + /*OLA -> zero */ + if (st->hTcxDec != NULL) + { + reset_tcx_overl_buf(st->hTcxDec); + } + if (st->hTcxCfg != NULL) + { + mvr2r(st->hHQ_core->old_out + NS2SA(st->output_Fs, N_ZERO_MDCT_NS), st->hTcxDec->syn_OverlFB_float, st->hTcxCfg->tcx_mdct_window_lengthFB); + st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/ + st->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; + } + + /*OLA for Mode 2 TCX always reset in Mode switching cases*/ + if (st->hHQ_core != NULL) + { + set_f(st->hHQ_core->old_outLB, 0, st->L_frame); + } + + st->last_core_bfi = TCX_20_CORE; + + if (st->hPFstat != NULL) + { + st->hPFstat->on = 0; + } + + /* reset CLDFB memories */ + cldfb_reset_memory_ivas(st->cldfbAna); + cldfb_reset_memory_ivas(st->cldfbBPF); + cldfb_reset_memory_ivas(st->cldfbSyn); + if (st->cldfbSynHB != NULL) + { + cldfb_reset_memory_ivas(st->cldfbSynHB); + } + } + else if ((st->L_frame != st->last_L_frame) && (st->L_frame <= L_FRAME16k) && (st->last_L_frame <= L_FRAME16k)) /* Rate switching between 12.8 and 16 kHz*/ + { + /*Interpolation of ACELP memories*/ + + /* convert quantized LSP vector */ + st->rate_switching_reset = lsp_convert_poly(st->lsp_old, st->L_frame, 0); + lsp2a_stab(st->lsp_old, st->old_Aq_12_8, M); + + lsp2lsf(st->lsp_old, st->lsf_old, M, st->sr_core); + mvr2r(st->lsp_old, st->lspold_uw_float, M); + mvr2r(st->lsf_old, st->lsfold_uw_float, M); + + if (!st->last_con_tcx) + { + synth_mem_updt2_flt(st->L_frame, st->last_L_frame, st->old_exc, st->mem_syn_r_float, st->mem_syn2, NULL, DEC); + } + + /*mem of deemphasis stayed unchanged.*/ + } + else if (st->L_frame != st->last_L_frame) /* Rate switching involving TCX only modes */ + { + /*Partial reset of ACELP memories*/ + st->rate_switching_reset = 1; + + /*reset partly some memories*/ + st->tilt_code = TILT_CODE_FLT; + if (!st->last_con_tcx) + { + set_zero(st->old_exc, L_EXC_MEM_DEC); + } + set_zero(st->old_Aq_12_8, M + 1); + + /*Resamp others memories*/ + /*Size of LPC syn memory*/ + lerp_flt(st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_old, st->mem_syn_r_float + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + mvr2r(st->mem_syn_r_float + L_SYN_MEM - M, st->mem_syn2, M); + } + /* update of lsf_old only needed in BASOP */ + /* else if( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */ + /* { */ + /* lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */ + /* } */ + } + + if (st->last_bwidth == NB && st->bwidth != NB && st->ini_frame != 0) + { + st->rate_switching_reset = 1; + } + + if (st->hTcxDec != NULL) + { + st->hTcxDec->old_synth_len = 2 * st->L_frame; + st->hTcxDec->old_synth_lenFB = 2 * st->hTcxDec->L_frameTCX; + } + + /* bass pf reset */ + st->bpf_gain_param = 0; + if (st->hBPF != NULL) + { + set_f(st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX); + } + + /* Formant postfilter */ + if (st->ini_frame == 0) + { + /* do nothing */ + } + else if (st->last_codec_mode == MODE2) + { + if (!st->tcxonly) + { + if (st->hPFstat->on) + { + lerp_flt(st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + lerp_flt(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + } + else + { + set_zero(st->hPFstat->mem_stp_flt, L_SYN_MEM); + set_zero(st->hPFstat->mem_pf_in_flt, L_SYN_MEM); + st->hPFstat->reset = 1; + st->hPFstat->gain_prec_flt = 1.f; + } + } + else if (st->hPFstat->on) + { + lerp_flt(st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + lerp_flt(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + } + } + else + { + /*codec mode switching*/ + + /*reset post-filter except for Narrowband*/ + if (((int16_t)(st->output_Fs / FRAMES_PER_SEC)) != L_FRAME8k) + { + if (st->hPFstat != NULL) + { + st->hPFstat->reset = 1; + if (st->hPFstat->on != 0) + { + st->hPFstat->reset = 0; + lerp_flt(st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_stp_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + lerp_flt(st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_old, st->hPFstat->mem_pf_in_flt + L_SYN_MEM - mem_syn_r_size_new, mem_syn_r_size_new, mem_syn_r_size_old); + } + } + } + else + { + /*feed last value old_synth as it is used for pre-emphasis mem*/ + if (st->hTcxDec != NULL) + { + st->hTcxDec->old_synth_float[st->hTcxDec->old_synth_len - 1] = st->syn_float[M]; + } + if (st->hBPF != NULL) + { + st->hBPF->pst_old_syn[NBPSF_PIT_MAX - 1] = st->syn_float[M]; + } + } + } + + /* lsf and lsp initialization */ + if (st->ini_frame == 0) + { + mvr2r(st->lsp_old, st->lspold_uw_float, M); + mvr2r(st->lsf_old, st->lsfold_uw_float, M); + + set_zero(st->lsf_cng_float, M); + } + + st->seed_tcx_plc = RANDOM_INITSEED; + st->past_gpit_float = 0.0f; + st->past_gcode_float = 0.0f; + st->gc_threshold = 0.0f; + + lsf2lsp(st->lsf_cng_float, st->lspold_cng_float, M, INT_FS_12k8); + lsp2a_stab(st->lspold_cng_float, st->Aq_cng_float, M); + st->plcBackgroundNoiseUpdated = 0; + mvr2r(st->lsf_old, st->lsf_q_cng_float, M); + mvr2r(st->lsf_old, st->old_lsf_q_cng_float, M); + mvr2r(st->lsp_old, st->lsp_q_cng_float, M); + mvr2r(st->lsp_old, st->old_lsp_q_cng_float, M); + set_zero(st->mem_syn_unv_back_float, M); + st->last_gain_syn_deemph_float = 1.f; + + if (st->last_codec_mode == MODE1 || st->ini_frame == 0) + { + /* this assumes that MODE1 fades out in the frequency domain - + otherwise some data from MODE1 would be needed here */ + st->last_concealed_gain_syn_deemph_float = 1.f; + if (hTcxDec != NULL) + { + hTcxDec->conceal_eof_gain_float = 1.0f; + } + } + /* Post processing */ + set_zero(st->mem_Aq_float, NB_SUBFR16k * (M + 1)); + + st->lp_ener_bfi = 60.0f; + if (st->ini_frame == 0) + { + st->prev_bfi = 0; + st->last_core_bfi = -1; + if (st->hTcxDec != NULL) + { + hTcxDec->tcxConceal_recalc_exc = 0; + } + } + st->prev_old_bfi = 0; + + if (st->hTcxDec != NULL) + { + st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0; + st->hTcxDec->tnsActive[0] = st->hTcxDec->tnsActive[1] = 0; + set_f(st->hTcxDec->ltpGainMemory, 0.0f, N_LTP_GAIN_MEMS); + } + + mvr2r(st->lsf_old, st->lsf_adaptive_mean, M); + mvr2r(st->lsf_old, st->lsfoldbfi0, M); + mvr2r(st->lsf_old, st->lsfoldbfi1, M); + + st->clas_dec = UNVOICED_CLAS; + + if (!st->last_con_tcx) + { + st->old_enr_LP_float = 0.0f; /* LP filter E of last good voiced frame or local LP filter E in TD TCX PLC */ + } + + if (st->prev_bfi) + { + /* calculate energy at the end of the previous frame */ + if (st->core == ACELP_CORE && st->last_core == HQ_CORE) + { + fer_energy(st->hTcxDec->L_frameTCX, UNVOICED_CLAS, st->previoussynth, -1, &st->enr_old, 1); + } + } + else + { + st->last_good = UNVOICED_CLAS; /* last good received frame for concealment */ + st->enr_old = 0.0f; /* energy at the end of the previous frame */ + } + st->lp_gainc = 0.0f; + st->lp_gainp = 0.0f; + + if (st->hTcxDec != NULL) + { + st->hTcxDec->prev_widow_left_rect = 0; + + if (is_init || MCT_flag || !(st->element_mode == IVAS_CPE_MDCT && st->element_mode == last_element_mode)) + { + st->hTcxDec->CngLevelBackgroundTrace_bfi = PLC_MIN_CNG_LEV_FLT; + st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; + st->hTcxDec->CurrLevelIndex_bfi = 0; + st->hTcxDec->LastFrameLevel_bfi = PLC_MIN_CNG_LEV_FLT; + set_f(st->hTcxDec->NoiseLevelMemory_bfi, PLC_MIN_CNG_LEV_FLT, PLC_MIN_STAT_BUFF_SIZE); + + st->hTcxDec->cummulative_damping_tcx_float = 1.0f; + } + } + + st->cummulative_damping_float = 1.0f; + + for (i = 0; i < 2 * NB_SUBFR16k + 2; i++) + { + st->old_pitch_buf[i] = (float)st->pit_min; + } + + for (i = 0; i < 2 * NB_SUBFR16k + 2; i++) + { + st->mem_pitch_gain_float[i] = 1.f; + } + + st->old_fpitch_float = (float)st->pit_min; + + st->rate_switching_init = 1; + + st->reset_mem_AR = 0; + + /* For phase dispersion */ + set_zero(st->dispMem, 8); + + st->voice_fac_float = -1; /* purely unvoiced */ + + /* TCX-LTP */ + if (hTcxLtpDec != NULL) + { + tcxltp_dec_init(hTcxLtpDec, st->ini_frame, st->last_codec_mode, st->element_mode, st->pit_max, st->sr_core); + } + + /* TCX */ + if (hTcxDec != NULL) + { + st->old_fpitchFB_float = (float)hTcxDec->pit_min_TCX; + + if (st->ini_frame == 0 || (st->last_codec_mode == MODE1 && st->element_mode == EVS_MONO)) + { + hTcxDec->tcxltp_last_gain_unmodified_float = 0.f; + } + + /* TCX */ + hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri(total_brate, st->rf_flag, st->element_mode); + + hTcxDec->envWeighted = 0; + } + + if (st->hBPF != NULL) + { + st->hBPF->pst_mem_deemp_err = 0.0f; + } + + if (st->tcxonly) + { + st->p_bpf_noise_buf_float = NULL; + } + else + { + st->p_bpf_noise_buf_float = st->bpf_noise_buf_float; + } + + if (bwidth == SWB && (total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) + { + st->tec_tfa = 1; + } + else + { + st->tec_tfa = 0; + } + + st->tec_flag = 0; + st->tfa_flag = 0; + + /* needed in decoder to read the bitstream */ + st->enableGplc = 0; + + st->flagGuidedAcelp = 0; + st->tonal_mdct_plc_active = 0; + st->T0_4th = L_SUBFR; + st->guidedT0 = st->T0_4th; + + if (st->hPlcInfo != NULL && total_brate >= HQ_48k && st->element_mode == EVS_MONO) + { + st->enablePlcWaveadjust = 1; + + if (st->hTcxDec != NULL && (st->ini_frame == 0 || last_total_brate < HQ_48k || st->last_codec_mode == MODE1 || st->force_lpd_reset)) + { + concealment_init(st->hTcxDec->L_frameTCX, st->hPlcInfo); + } + } + else + { + st->enablePlcWaveadjust = 0; + } + + /* PLC: [TCX: Tonal Concealment] */ + if (st->hTonalMDCTConc != NULL && !(st->element_mode > EVS_MONO && st->ini_frame != 0 && st->hTonalMDCTConc->nSamples == st->hTcxDec->L_frameTCX)) + { + st->hTonalMDCTConc->nScaleFactors = 0; + st->hTonalMDCTConc->nSamples = 0; + st->hTonalMDCTConc->lastPcmOut_float = 0x0; + st->hTonalMDCTConc->lastBlockData.tonalConcealmentActive = 0; + st->hTonalMDCTConc->lastBlockData.nSamples = 0; + + TonalMDCTConceal_Init_ivas(st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg); + } + + st->last_tns_active = 0; + st->second_last_tns_active = 0; + st->second_last_core = -1; + + if (st->hTcxCfg != NULL && + st->element_mode != EVS_MONO) + { + st->hTcxCfg->fIsTNSAllowed = getTnsAllowed(is_init ? total_brate : st->bits_frame_nominal * FRAMES_PER_SEC, st->igf, st->element_mode); + } + if (hTcxDec != NULL) + { + hTcxDec->tcxltp_second_last_pitch_float = st->old_fpitch_float; + hTcxDec->tcxltp_third_last_pitch_float = st->old_fpitch_float; + } + + if ((total_brate == ACELP_9k60 || total_brate == ACELP_16k40 || total_brate == ACELP_24k40) && st->element_mode == EVS_MONO) + { + st->dec_glr = 1; + } + else + { + st->dec_glr = 0; + } + + st->dec_glr_idx = 0; + + st->VAD = 0; + if (hTcxDec != NULL) + { + hTcxDec->enableTcxLpc = 1; + + hTcxDec->old_gaintcx_bfi_float = 0.0f; + + hTcxDec->tcx_hm_LtpPitchLag = -1; + } + + if (st->hTcxCfg != NULL) + { + st->hTcxCfg->na_scale_flt = 1.f; + } + + return; +} + +#endif /*-----------------------------------------------------------------------* * tcxltp_dec_init() * diff --git a/lib_dec/core_dec_switch.c b/lib_dec/core_dec_switch.c index 9a7cfd3a3..a6e1ef258 100644 --- a/lib_dec/core_dec_switch.c +++ b/lib_dec/core_dec_switch.c @@ -122,8 +122,8 @@ void mode_switch_decoder_LPD( if ( fscale != st->fscale || switchWB || bSwitchFromAmrwbIO || st->last_codec_mode == MODE1 || st->force_lpd_reset ) { /* Init Decoder */ - Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; #ifdef IVAS_FLOAT_FIXED + Word16 Q_syn_Overl_TDAC = 0, Q_fer_samples = 0, Q_syn_Overl = 0, Q_syn_Overl_TDACFB = 0, Q_syn_OverlFB = 0, Q_old_out = 0, Q_old_outLB = 0, Q_old_Aq_12_8 = 0; open_decoder_LPD_ivas_fx(st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0, &Q_syn_Overl_TDAC, &Q_fer_samples, &Q_syn_Overl, &Q_syn_Overl_TDACFB, &Q_syn_OverlFB, &Q_old_out, &Q_old_outLB, &Q_old_Aq_12_8); #endif open_decoder_LPD( st, total_brate, last_total_brate, bwidth, MCT_flag, last_element_mode, 0 ); diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index b77405658..80cfcdce9 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -116,7 +116,7 @@ ivas_error createFdCngDec( * * Initialize an instance of type FD_CNG *-------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void initFdCngDec( DEC_CORE_HANDLE st /* i/o: decoder state structure */ ) @@ -203,7 +203,75 @@ void initFdCngDec( return; } +#else +void initFdCngDec( + DEC_CORE_HANDLE st /* i/o: decoder state structure */ +) +{ + HANDLE_FD_CNG_DEC hFdCngDec; + + hFdCngDec = st->hFdCngDec; + + /* Initialize common */ + initFdCngCom_flt(hFdCngDec->hFdCngCom, st->cldfbSyn->scale_flt); + + /* Set some counters and flags */ + hFdCngDec->flag_dtx_mode = 0; + hFdCngDec->lp_noise_float = -20.f; + hFdCngDec->lp_speech_float = 25.f; + + /* Initialize noise estimation algorithm */ + set_f(hFdCngDec->bandNoiseShape_float, 0.0f, FFTLEN2); + set_f(hFdCngDec->partNoiseShape_float, 0.0f, NPART); + set_f(hFdCngDec->msPeriodog_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msAlpha_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msBminWin_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msBminSubWin_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msPsd_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msNoiseFloor_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msNoiseEst_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msMinBuf_float, FLT_MAX, MSNUMSUBFR * NPART_SHAPING); + set_f(hFdCngDec->msCurrentMin_float, FLT_MAX, NPART_SHAPING); + set_f(hFdCngDec->msCurrentMinOut_float, FLT_MAX, NPART_SHAPING); + set_f(hFdCngDec->msCurrentMinSubWindow_float, FLT_MAX, NPART_SHAPING); + set_s(hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING); + set_s(hFdCngDec->msNewMinFlag, 0, NPART_SHAPING); + set_f(hFdCngDec->msPsdFirstMoment_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msPsdSecondMoment_float, 0.0f, NPART_SHAPING); + hFdCngDec->msPeriodogBufPtr = 0; + set_f(hFdCngDec->msPeriodogBuf_float, 0.0f, MSBUFLEN * NPART_SHAPING); + set_f(hFdCngDec->msLogPeriodog_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->msLogNoiseEst_float, 0.0f, NPART_SHAPING); + set_f(hFdCngDec->psize_shaping_float, 0.0f, NPART_SHAPING); + hFdCngDec->nFFTpart_shaping = 0; + + set_f(hFdCngDec->hFdCngCom->sidNoiseEstLp_flt, 0.0f, NPART); + + set_f(hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k); + set_f(hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING); + + hFdCngDec->ms_last_inactive_bwidth = NB; + hFdCngDec->ms_cnt_bw_up = 0; + + hFdCngDec->cna_LR_LT = 0.5f; + hFdCngDec->cna_ILD_LT = 0.0f; + hFdCngDec->first_cna_noise_updated = 0; + hFdCngDec->first_cna_noise_update_cnt = 0; + hFdCngDec->cna_nbands = CNA_INIT_NBANDS; + mvs2s(cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1); + hFdCngDec->cna_act_fact = 1.0f; + hFdCngDec->cna_rescale_fact = 0.0f; + hFdCngDec->cna_seed = 5687; + set_zero(hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX); + set_zero(hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX); + + st->CNG_mode = -1; + mvr2r(st->lsp_old, st->lspCNG, M); + + return; +} +#endif #ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * configureFdCngDec() diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 390929312..8f32c1179 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -4140,7 +4140,6 @@ void IGFDecCopyLPCFlatSpectrum_fx( { IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData; H_IGF_GRID hGrid; - int16_t i; IF( hInstance ) { @@ -4154,11 +4153,6 @@ void IGFDecCopyLPCFlatSpectrum_fx( Copy32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine ); - ///* TODO: remove float dependency */ - //for ( i = hGrid->minSrcSubband - IGF_MID_WHITENING_LEVEL2; i < hGrid->startLine; i++ ) - //{ - // hPrivateData->pSpecFlat_float[i] = me2f( hPrivateData->pSpecFlat[i], hPrivateData->pSpecFlat_exp ); - //} } } diff --git a/lib_dec/init_dec.c b/lib_dec/init_dec.c index 258536bce..e2ff37a54 100644 --- a/lib_dec/init_dec.c +++ b/lib_dec/init_dec.c @@ -48,13 +48,13 @@ #include "prot_fx2.h" #include "ivas_prot_fx.h" #endif -#ifndef IVAS_FLOAT_FIXED + /*----------------------------------------------------------------------* * init_decoder() * * Initialization of static variables for the decoder *----------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error init_decoder( Decoder_State *st, /* o : Decoder static variables structure */ const int16_t idchan, /* i : channel ID */ @@ -104,8 +104,6 @@ ivas_error init_decoder( /* LSF initilalizations */ mvr2r( GEWB_Ave, st->mem_AR, M ); - init_lvq_fx(st->offset_scale1_fx, st->offset_scale2_fx, st->offset_scale1_p_fx, st->offset_scale2_p_fx, st->no_scales_fx, st->no_scales_p_fx); - set_f( st->mem_MA, 0, M ); set_f( st->dispMem, 0, 8 ); @@ -134,9 +132,6 @@ ivas_error init_decoder( st->stab_fac = 0.0f; st->stab_fac_smooth = 0.0f; set_f( st->agc_mem2, 0, 2 ); -#ifdef IVAS_FLOAT_FIXED - set16_fx(st->agc_mem_fx, 0, 2); -#endif set_f( st->mem_syn3, 0, M ); st->stab_fac_smooth_lt = 0.0f; st->log_energy_diff_lt = 0.0f; @@ -196,31 +191,6 @@ ivas_error init_decoder( st->old_bfi_cnt = 0; -#ifdef IVAS_FLOAT_FIXED - /* Initializaing Q factors*/ - st->Q_syn = 0; - move16(); - st->Q_syn2 = 0; - move16(); - st->Q_syn_cng = 0; - move16(); - st->prev_Q_syn = 0; - move16(); - st->prev_Q_syn_fr = 0; - move16(); - st->Q_exc = 0; - move16(); - st->Q_exc_cng = 0; - move16(); - st->prev_Q_exc = 0; - move16(); - st->prev_Q_exc_fr = 0; - move16(); - st->Q_stat_noise_ge = GE_SHIFT; - move16(); - st->Q_stat_noise = 0; - move16(); -#endif /*-----------------------------------------------------------------* * parameters for AC mode (GSC) *-----------------------------------------------------------------*/ @@ -272,16 +242,9 @@ ivas_error init_decoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for NB/formant postflter\n" ) ); } -#ifdef IVAS_FLOAT_FIXED - Init_post_filter_fx(st->hPFstat);//fixed - st->psf_lp_noise_fx = 0; - /*to be cleaned up*/ - Init_post_filter_ivas(st->hPFstat); - st->psf_lp_noise = 0.0f; -#else + Init_post_filter_ivas( st->hPFstat ); st->psf_lp_noise = 0.0f; -#endif } else { @@ -374,9 +337,6 @@ ivas_error init_decoder( } /* HQ core initialization */ -#ifdef IVAS_FLOAT_FIXED - HQ_core_dec_init_fx( st->hHQ_core ); -#endif HQ_core_dec_init_flt( st->hHQ_core ); if ( st->element_mode == EVS_MONO ) @@ -432,9 +392,6 @@ ivas_error init_decoder( } fd_bwe_dec_init_flt( st->hBWE_FD ); -#ifdef IVAS_FLOAT_FIXED - fd_bwe_dec_init(st, st->hBWE_FD); -#endif } else { @@ -588,10 +545,6 @@ ivas_error init_decoder( st->old_Es_pred = 0; set_f( st->old_Aq_12_8 + 1, 0, M ); st->old_Aq_12_8[0] = 1; -#ifdef IVAS_FLOAT_FIXED - set16_fx( st->old_Aq_12_8_fx + 1, 0, M ); - st->old_Aq_12_8_fx[0] = ONE_IN_Q12; -#endif /*-----------------------------------------------------------------* * SC-VBR parameters @@ -652,11 +605,6 @@ ivas_error init_decoder( st->hTcxDec->old_synthFB = st->hTcxDec->synth_history + NS2SA( st->output_Fs, PH_ECU_MEM_NS ); st->hTcxDec->prev_good_synth = st->hTcxDec->old_synthFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ); -#ifdef IVAS_FLOAT_FIXED - set16_fx(st->hTcxDec->FBTCXdelayBuf, 0, 111); - st->hTcxDec->old_synthFB_fx = st->hTcxDec->synth_history_fx + NS2SA( st->output_Fs, PH_ECU_MEM_NS ); - st->hTcxDec->prev_good_synth_fx = st->hTcxDec->old_synthFB_fx + NS2SA(st->output_Fs, PH_ECU_LOOKAHEAD_NS); -#endif } else { @@ -766,20 +714,12 @@ ivas_error init_decoder( /* Init FD-CNG */ initFdCngDec( st ); -#ifdef IVAS_FLOAT_FIXED - st->cldfbSyn->scale = (Word16) ( st->cldfbSyn->scale_flt * ( 1u << norm_s( (Word16) st->cldfbSyn->scale_flt ) ) ); - initFdCngDec_fx( st, st->cldfbSyn->scale ); -#endif // IVAS_FLOAT_FIXED } else { st->hFdCngDec = NULL; } -#ifdef IVAS_FLOAT_FIXED - st->cngTDLevel = 0; - st->cngTDLevel_e = 0; -#endif // IVAS_FLOAT_FIXED st->cngTDLevel_float = 0.f; st->lp_noise_float = -20.0f; st->force_lpd_reset = 0; diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index a00781fac..02f158a3d 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -232,7 +232,6 @@ static void ivas_binRenderer_filterModule_fx( #define NUM_TAPS_F0_5 ( Word16 )( 48 ) // (int16_t) ceil( 0.5f * hBinRenConvModule->numTaps ) #define NUM_TAPS_F0_4 ( Word16 )( 39 ) // (int16_t) ceil( 0.4f * hBinRenConvModule->numTaps ) #define NUM_TAPS_F0_3 ( Word16 )( 29 ) // (int16_t) ceil( 0.3f * hBinRenConvModule->numTaps ) -#endif static ivas_error ivas_binRenderer_convModuleOpen( BINAURAL_RENDERER_HANDLE hBinRenderer, @@ -696,7 +695,262 @@ static ivas_error ivas_binRenderer_convModuleOpen( return IVAS_ERR_OK; } +#else + +static ivas_error ivas_binRenderer_convModuleOpen( + BINAURAL_RENDERER_HANDLE hBinRenderer, + const int16_t renderer_type, + const int16_t isLoudspeaker, + const AUDIO_CONFIG input_config, + const HRTFS_FASTCONV_HANDLE hHrtf +) +{ + int16_t bandIdx, chIdx; + BINRENDERER_CONV_MODULE_HANDLE hBinRenConvModule; + + /*-----------------------------------------------------------------* + * prepare library opening + *-----------------------------------------------------------------*/ + + if ((hBinRenConvModule = (BINRENDERER_CONV_MODULE_HANDLE)malloc(sizeof(BINRENDERER_CONV_MODULE))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if (!isLoudspeaker) + { + hBinRenderer->nInChannels = audioCfg2channels(input_config); + } + else + { + /* Note: needs to be revisited if multiple LFE support is required */ + hBinRenderer->nInChannels = (audioCfg2channels(input_config) - isLoudspeaker); + } + + if (renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) + { + hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; + + /* Use variable order filtering */ + bandIdx = 0; + for (; bandIdx < 5; bandIdx++) + { + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + } + for (; bandIdx < 10; bandIdx++) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.6f * hBinRenConvModule->numTaps); + } + for (; bandIdx < 20; bandIdx++) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.5f * hBinRenConvModule->numTaps); + } + for (; bandIdx < 30; bandIdx++) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.4f * hBinRenConvModule->numTaps); + } + for (; bandIdx < hBinRenderer->conv_band; bandIdx++) + { + hBinRenConvModule->numTapsArray[bandIdx] = (int16_t)ceilf(0.3f * hBinRenConvModule->numTaps); + } + } + else + { + if (hBinRenderer->ivas_format == SBA_FORMAT) + { + hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; + } + else + { + hBinRenConvModule->numTaps = BINAURAL_NTAPS; + } + + /* Use fixed order filtering */ + bandIdx = 0; + for (; bandIdx < hBinRenderer->conv_band; bandIdx++) + { + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + } + } + + /* allocate memory for filter states */ + if ((hBinRenConvModule->filterTapsLeftReal = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + if ((hBinRenConvModule->filterTapsLeftImag = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterTapsRightReal = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterTapsRightImag = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + for (bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++) + { + if ((hBinRenConvModule->filterTapsLeftReal[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterTapsLeftImag[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterTapsRightReal[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterTapsRightImag[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + } + + + if ((hBinRenConvModule->filterStatesLeftReal = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterStatesLeftImag = (float ***)malloc(hBinRenderer->conv_band * sizeof(float **))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + for (bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++) + { + if ((hBinRenConvModule->filterStatesLeftReal[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterStatesLeftImag[bandIdx] = (float **)malloc(hBinRenderer->nInChannels * sizeof(float *))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + for (chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++) + { + if ((hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx] = (float *)malloc(hBinRenConvModule->numTapsArray[bandIdx] * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + + if ((hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx] = (float *)malloc(hBinRenConvModule->numTapsArray[bandIdx] * sizeof(float))) == NULL) + { + return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Convolution Module \n")); + } + } + } + + /* set memories */ + for (bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++) + { + for (chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++) + { + int16_t tmp = 0; + + if (isLoudspeaker) + { + if (input_config == IVAS_AUDIO_CONFIG_5_1) + { + tmp = channelIndex_CICP6[chIdx]; + } + else if (input_config == IVAS_AUDIO_CONFIG_7_1) + { + tmp = channelIndex_CICP12[chIdx]; + } + else if (input_config == IVAS_AUDIO_CONFIG_5_1_2) + { + tmp = channelIndex_CICP14[chIdx]; + } + else if (input_config == IVAS_AUDIO_CONFIG_5_1_4) + { + tmp = channelIndex_CICP16[chIdx]; + } + else if (input_config == IVAS_AUDIO_CONFIG_7_1_4) + { + tmp = channelIndex_CICP19[chIdx]; + } + } + + if (renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) + { + /* set the memories to zero */ + set_zero(hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx]); + set_zero(hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTapsArray[bandIdx]); + if (isLoudspeaker) + { + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftBRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftBRIRImag[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightBRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightBRIRImag[bandIdx][tmp]; + } + } + else + { + /* set the memories to zero */ + set_zero(hBinRenConvModule->filterStatesLeftReal[bandIdx][chIdx], hBinRenConvModule->numTaps); + set_zero(hBinRenConvModule->filterStatesLeftImag[bandIdx][chIdx], hBinRenConvModule->numTaps); + if (isLoudspeaker) + { + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal[bandIdx][tmp]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag[bandIdx][tmp]; + } + else + { + if (input_config == IVAS_AUDIO_CONFIG_HOA3) + { + /* HOA3 filter coefficients */ + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3[bandIdx][chIdx]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA3[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3[bandIdx][chIdx]; + } + else if (input_config == IVAS_AUDIO_CONFIG_HOA2) + { + /* HOA2 filter coefficients */ + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA2[bandIdx][chIdx]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_HOA2[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA2[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA2[bandIdx][chIdx]; + } + else if (input_config == IVAS_AUDIO_CONFIG_FOA) + { + /* FOA filter coefficients */ + hBinRenConvModule->filterTapsLeftReal[bandIdx][chIdx] = hHrtf->leftHRIRReal_FOA[bandIdx][chIdx]; + hBinRenConvModule->filterTapsLeftImag[bandIdx][chIdx] = hHrtf->leftHRIRImag_FOA[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightReal[bandIdx][chIdx] = hHrtf->rightHRIRReal_FOA[bandIdx][chIdx]; + hBinRenConvModule->filterTapsRightImag[bandIdx][chIdx] = hHrtf->rightHRIRImag_FOA[bandIdx][chIdx]; + } + else + { + return IVAS_ERR_INVALID_INPUT_FORMAT; + } + } + } + } + } + + + hBinRenderer->hBinRenConvModule = hBinRenConvModule; + + return IVAS_ERR_OK; +} +#endif /*-------------------------------------------------------------------------* * ivas_init_binaural_hrtf() diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 263c50c45..3b06fadda 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -322,24 +322,7 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio_fx[j] = float_to_fix16( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio[j], Q14 ); } } - IF( st_ivas->hSpatParamRendCom != NULL ) - { - FOR( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - FOR( j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ ) - { - st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->diffuseness_vector[i][j], 30 ); - st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio1[i][j], 30 ); - IF( EQ_16( st_ivas->hQMetaData->no_directions, 2 ) ) - { - st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio2[i][j], 30 ); - st_ivas->hSpatParamRendCom->spreadCoherence2_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence2[i][j], 15 ); - } - st_ivas->hSpatParamRendCom->surroundingCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->surroundingCoherence[i][j], 15 ); - st_ivas->hSpatParamRendCom->spreadCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence[i][j], 15 ); - } - } - } + // Float to fix conversion ends here. IF( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) @@ -1130,24 +1113,7 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio_fx[j] = float_to_fix16( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio[j], Q14 ); } } - IF( st_ivas->hSpatParamRendCom != NULL ) - { - FOR( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - FOR( j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ ) - { - st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->diffuseness_vector[i][j], 30 ); - st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio1[i][j], 30 ); - IF( EQ_16( st_ivas->hQMetaData->no_directions, 2 ) ) - { - st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio2[i][j], 30 ); - st_ivas->hSpatParamRendCom->spreadCoherence2_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence2[i][j], 15 ); - } - st_ivas->hSpatParamRendCom->surroundingCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->surroundingCoherence[i][j], 15 ); - st_ivas->hSpatParamRendCom->spreadCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence[i][j], 15 ); - } - } - } + FOR( n = 0; n < tmp_nchan_ism; n++ ) { set32_fx( p_output_fx[n], 0, L_FRAME48k ); @@ -2654,24 +2620,6 @@ ivas_error ivas_jbm_dec_tc( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio_fx[j] = float_to_fix16( st_ivas->hMasa->hMasaLfeSynth->lfeToTotalEnergyRatio[j], Q14 ); } } - IF( st_ivas->hSpatParamRendCom != NULL ) - { - FOR( i = 0; i < st_ivas->hSpatParamRendCom->dirac_md_buffer_length; i++ ) - { - FOR( j = 0; j < st_ivas->hSpatParamRendCom->num_freq_bands; j++ ) - { - st_ivas->hSpatParamRendCom->diffuseness_vector_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->diffuseness_vector[i][j], 30 ); - st_ivas->hSpatParamRendCom->energy_ratio1_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio1[i][j], 30 ); - IF( EQ_16( st_ivas->hQMetaData->no_directions, 2 ) ) - { - st_ivas->hSpatParamRendCom->energy_ratio2_fx[i][j] = float_to_fix( st_ivas->hSpatParamRendCom->energy_ratio2[i][j], 30 ); - st_ivas->hSpatParamRendCom->spreadCoherence2_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence2[i][j], 15 ); - } - st_ivas->hSpatParamRendCom->surroundingCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->surroundingCoherence[i][j], 15 ); - st_ivas->hSpatParamRendCom->spreadCoherence_fx[i][j] = float_to_fix16( st_ivas->hSpatParamRendCom->spreadCoherence[i][j], 15 ); - } - } - } // Float to fix conversion ends here. IF( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 4019334a3..09d03335f 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -2206,7 +2206,7 @@ void ivas_param_mc_dec_read_BS( * * *------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_param_mc_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ @@ -2439,7 +2439,7 @@ void ivas_param_mc_dec_digest_tc_fx( return; } - +#endif void ivas_param_mc_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -2680,7 +2680,7 @@ void ivas_param_mc_dec_digest_tc( * * Parametric MC decoding process *------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_param_mc_dec_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ @@ -3190,6 +3190,289 @@ void ivas_param_mc_dec_render( } +#else +void ivas_param_mc_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */ + uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */ + uint16_t *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ + float *output_f[] /* o : rendered time signal */ +) +{ + PARAM_MC_DEC_HANDLE hParamMC; + int16_t i, ch; + int16_t subframe_idx; + int16_t slot_idx, slot_idx_start, slot_idx_start_cldfb_synth, first_sf, last_sf, slots_to_render; + int16_t nchan_transport, nchan_out_transport, nchan_out_cldfb; + int16_t nchan_out_cov; + /*CLDFB*/ + float Cldfb_RealBuffer[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer[MAX_INTERN_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + /*Decorrelator*/ + float onset_filter[MAX_CICP_CHANNELS * CLDFB_NO_CHANNELS_MAX]; + /* format converter */ + int16_t channel_active[MAX_OUTPUT_CHANNELS]; + uint16_t nband_synth, nbands_to_zero; + uint16_t nchan_out_init; + uint32_t output_Fs; + + hParamMC = st_ivas->hParamMC; + assert(hParamMC); + + push_wmops("param_mc_dec_render"); + + set_s(channel_active, 0, MAX_CICP_CHANNELS); + nchan_transport = st_ivas->nchan_transport; + nchan_out_transport = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + nchan_out_init = nchan_out_transport; + output_Fs = st_ivas->hDecoderConfig->output_Fs; + + if (st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) + { + nchan_out_cldfb = BINAURAL_CHANNELS; + set_s(channel_active, 1, nchan_out_cldfb); + if (st_ivas->hCombinedOrientationData) + { + nchan_out_init = MAX_INTERN_CHANNELS; + } + nchan_out_cov = st_ivas->hTransSetup.nchan_out_woLFE + st_ivas->hTransSetup.num_lfe; + } + else if (hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB) + { + nchan_out_cov = nchan_out_transport; + nchan_out_cldfb = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + } + else if (hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO) + { + nchan_out_cov = st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe; + nchan_out_cldfb = nchan_out_cov; + set_s(channel_active, 1, nchan_out_cov); + } + else + { + nchan_out_cov = nchan_out_transport; + nchan_out_cldfb = nchan_out_transport; + set_s(channel_active, 1, nchan_out_cov); + } + + /* set everything to zero that will not be decoded */ + nband_synth = hParamMC->band_grouping[hParamMC->num_param_bands_synth]; + nbands_to_zero = hParamMC->num_freq_bands - nband_synth; + for (ch = 0; ch < nchan_out_init; ch++) + { + for (slot_idx = 0; slot_idx < JBM_CLDFB_SLOTS_IN_SUBFRAME; slot_idx++) + { + set_zero(&(Cldfb_RealBuffer[ch][slot_idx][nband_synth]), nbands_to_zero); + set_zero(&(Cldfb_ImagBuffer[ch][slot_idx][nband_synth]), nbands_to_zero); + } + } + + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = min(hParamMC->num_slots - hParamMC->slots_rendered, nSamplesAsked / NS2SA(output_Fs, CLDFB_SLOT_NS)); + *nSamplesRendered = slots_to_render * NS2SA(output_Fs, CLDFB_SLOT_NS); + first_sf = hParamMC->subframes_rendered; + last_sf = first_sf; + while (slots_to_render > 0) + { + slots_to_render -= hParamMC->subframe_nbslots[last_sf]; + last_sf++; + } + if (st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC) + { + for (subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++) + { + slots_to_render += hParamMC->subframe_nbslots[subframe_idx]; + } + } + slot_idx_start = hParamMC->slots_rendered; + slot_idx_start_cldfb_synth = 0; + for (subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++) + { + for (slot_idx = 0; slot_idx < hParamMC->subframe_nbslots[subframe_idx]; slot_idx++, hParamMC->slots_rendered++) + { + + if (hParamMC->max_band_decorr > 0) + { + /*-----------------------------------------------------------------* + * protoype signal computation + *-----------------------------------------------------------------*/ + + param_mc_protoSignalComputation(&hParamMC->Cldfb_RealBuffer_tc[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], + &hParamMC->Cldfb_ImagBuffer_tc[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], + hParamMC->proto_frame_f, hParamMC->diff_proto_info, + hParamMC->num_freq_bands); + + /*-----------------------------------------------------------------* + * frequency domain decorrelation + *-----------------------------------------------------------------*/ + + /* decorrelate prototype frame */ + ivas_dirac_dec_decorr_process(hParamMC->num_freq_bands, + hParamMC->num_outputs_diff, + hParamMC->diff_proto_info->num_protos_diff, + DIRAC_SYNTHESIS_COV_MC_LS, + nchan_transport, + hParamMC->proto_frame_f, + hParamMC->diff_proto_info->num_protos_diff, + hParamMC->diff_proto_info->proto_index_diff, + hParamMC->proto_frame_dec_f, + onset_filter, + hParamMC->h_freq_domain_decorr_ap_params, + hParamMC->h_freq_domain_decorr_ap_state); + + /* copy decorrelated frame directly to output CLDFB buffer, acts also as intermediate */ + /* memory for the decorrelated signal */ + ivas_param_mc_dec_copy_diffuse_proto(hParamMC, Cldfb_RealBuffer, Cldfb_ImagBuffer, nchan_out_cov, slot_idx); + } + + /*-----------------------------------------------------------------* + * output synthesis + *-----------------------------------------------------------------*/ + + ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot(&hParamMC->Cldfb_RealBuffer_tc[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], + &hParamMC->Cldfb_ImagBuffer_tc[hParamMC->slots_rendered * nchan_transport * hParamMC->num_freq_bands], + Cldfb_RealBuffer, Cldfb_ImagBuffer, + hParamMC->h_output_synthesis_cov_state.mixing_matrix, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, slot_idx, slot_idx + slot_idx_start, + nchan_transport, nchan_out_cov, hParamMC); + + if ((st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM)) + { + if ( + st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV) + { + ivas_param_mc_mc2sba_cldfb(st_ivas->hTransSetup, hParamMC->hoa_encoder, slot_idx, Cldfb_RealBuffer, Cldfb_ImagBuffer, nband_synth, GAIN_LFE); + } + else + { + /* remove LFE */ + uint16_t idx_out; + uint16_t idx_lfe; + IVAS_OUTPUT_SETUP hLsSetup; + + hLsSetup = st_ivas->hTransSetup; + + /* If LFE should be rendered, add it to other channels before removing */ + if (st_ivas->hBinRenderer->render_lfe) + { + for (idx_lfe = 0; idx_lfe < hLsSetup.num_lfe; idx_lfe++) + { + /* Copy just the first band of LFE*/ + v_multc(Cldfb_RealBuffer[hLsSetup.index_lfe[idx_lfe]][slot_idx], (GAIN_LFE / hLsSetup.nchan_out_woLFE), Cldfb_RealBuffer[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1); + v_multc(Cldfb_ImagBuffer[hLsSetup.index_lfe[idx_lfe]][slot_idx], (GAIN_LFE / hLsSetup.nchan_out_woLFE), Cldfb_ImagBuffer[hLsSetup.index_lfe[idx_lfe]][slot_idx], 1); + + for (ch = 0; ch < (hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe); ch++) + { + if (hLsSetup.index_lfe[idx_lfe] != ch) + { + v_add(Cldfb_RealBuffer[ch][slot_idx], Cldfb_RealBuffer[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_RealBuffer[ch][slot_idx], 1); + v_add(Cldfb_ImagBuffer[ch][slot_idx], Cldfb_ImagBuffer[hLsSetup.index_lfe[idx_lfe]][slot_idx], Cldfb_ImagBuffer[ch][slot_idx], 1); + } + } + } + } + + idx_out = 0; + idx_lfe = 0; + + for (ch = 0; ch < (hLsSetup.nchan_out_woLFE + hLsSetup.num_lfe); ch++) + { + if ((hLsSetup.num_lfe > 0) && (hLsSetup.index_lfe[idx_lfe] == ch)) + { + if (idx_lfe < (hLsSetup.num_lfe - 1)) + { + idx_lfe++; + } + } + else if (ch != idx_out) + { + mvr2r(Cldfb_RealBuffer[ch][slot_idx], Cldfb_RealBuffer[idx_out][slot_idx], nband_synth); + mvr2r(Cldfb_ImagBuffer[ch][slot_idx], Cldfb_ImagBuffer[idx_out][slot_idx], nband_synth); + idx_out++; + } + else + { + idx_out++; + } + } + } + } + } + + if (st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) + { + + ivas_binRenderer(st_ivas->hBinRenderer, + st_ivas->hCombinedOrientationData, + hParamMC->subframe_nbslots[subframe_idx], + Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural, Cldfb_RealBuffer, Cldfb_ImagBuffer); + + + /* update combined orientation access index */ + ivas_combined_orientation_update_index(st_ivas->hCombinedOrientationData, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx]); + } + else if (hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_CLDFB) + { + /* format conversion*/ + ivas_lssetupconversion_process_param_mc(st_ivas, hParamMC->subframe_nbslots[subframe_idx], Cldfb_RealBuffer, Cldfb_ImagBuffer, channel_active); + } + + /* CLDFB synthesis */ + for (ch = 0; ch < nchan_out_cldfb; ch++) + { + float *RealBuffer[16]; + float *ImagBuffer[16]; + + if (channel_active[ch]) + { + /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + for (i = 0; i < hParamMC->subframe_nbslots[subframe_idx]; i++) + { + if (st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) + { + RealBuffer[i] = Cldfb_RealBuffer_Binaural[ch][i]; + ImagBuffer[i] = Cldfb_ImagBuffer_Binaural[ch][i]; + } + else + { + RealBuffer[i] = Cldfb_RealBuffer[ch][i]; + ImagBuffer[i] = Cldfb_ImagBuffer[ch][i]; + } + } + + cldfbSynthesis_ivas(RealBuffer, ImagBuffer, &(output_f[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands]), + hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx], st_ivas->cldfbSynDec[ch]); + } + else + { + set_f(&(output_f[ch][slot_idx_start_cldfb_synth * hParamMC->num_freq_bands]), 0.0f, hParamMC->num_freq_bands * hParamMC->subframe_nbslots[subframe_idx]); + } + } + slot_idx_start += hParamMC->subframe_nbslots[subframe_idx]; + slot_idx_start_cldfb_synth += hParamMC->subframe_nbslots[subframe_idx]; + } + + if (st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC) + { + ivas_mc2sba(st_ivas->hIntSetup, output_f, output_f, hParamMC->num_freq_bands * slots_to_render, st_ivas->hOutSetup.ambisonics_order, 0.f); + } + + /* update */ + if (hParamMC->slots_rendered == hParamMC->num_slots) + { + hParamMC->hMetadataPMC->last_coded_bwidth = hParamMC->hMetadataPMC->coded_bwidth; + param_mc_update_mixing_matrices(hParamMC, hParamMC->h_output_synthesis_cov_state.mixing_matrix, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, nchan_transport, nchan_out_cov); + } + hParamMC->subframes_rendered = last_sf; + *nSamplesAvailableNext = (hParamMC->num_slots - hParamMC->slots_rendered) * NS2SA(output_Fs, CLDFB_SLOT_NS); + pop_wmops(); + + return; +} + + +#endif /*------------------------------------------------------------------------- * ivas_param_mc_dec() * @@ -3217,9 +3500,9 @@ void ivas_param_mc_dec( nSamplesAsked = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); ivas_param_mc_dec_digest_tc( st_ivas, DEFAULT_JBM_CLDFB_TIMESLOTS, output_f ); - +#ifdef IVAS_FLOAT_FIXED me2f_buf_16(st_ivas->hParamMC->h_output_synthesis_params.interpolator_fx, 0, st_ivas->hParamMC->h_output_synthesis_params.interpolator, DEFAULT_JBM_CLDFB_TIMESLOTS ); - +#endif ivas_param_mc_dec_render( st_ivas, nSamplesAsked, &nSamplesRendered, &nSamplesAvailableNext, output_f ); /* set handle pointers back to NULL */ diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 123a083d8..2bd011811 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -3623,7 +3623,7 @@ static ivas_error ivas_deindex_real_index_fx( * * *-----------------------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void ivas_spar_to_dirac( Decoder_Struct *st_ivas, ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ @@ -4068,3 +4068,274 @@ void ivas_spar_to_dirac( return; } + +#else +void ivas_spar_to_dirac( + Decoder_Struct *st_ivas, + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t dtx_vad, /* i : DTX frame flag */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t bw, /* i : band joining factor */ + const int16_t dyn_active_w_flag) +{ + DIRAC_DEC_HANDLE hDirAC; + int16_t start_band, end_band, band, qmf_band_start, qmf_band_end; + int16_t block, b; + int16_t *band_grouping; + float diffuseness[IVAS_MAX_NUM_BANDS]; + int16_t sba_order_internal; + float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES]; + int16_t azi[IVAS_MAX_NUM_BANDS]; + int16_t ele[IVAS_MAX_NUM_BANDS]; + float dvx[IVAS_MAX_NUM_BANDS], dvy[IVAS_MAX_NUM_BANDS], dvz[IVAS_MAX_NUM_BANDS]; + float radius; + float en_ratio, res_pow; + int16_t num_slots_in_subfr; + int16_t tmp_write_idx_param_band; + int16_t tmp_write_idx_band; + float pred_re_20ms[IVAS_MAX_NUM_BANDS][IVAS_SPAR_MAX_CH - 1]; + int16_t pred_idx; + int16_t *dirac_to_spar_md_bands; + int16_t enc_param_start_band; + int16_t active_w_vlbr; + int16_t i, num_subframes; + int16_t active_w; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + + active_w = (dyn_active_w_flag == 1) || (hMdDec->spar_md_cfg.active_w == 1); + sba_order_internal = min(st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER); + start_band = 0; + end_band = min(num_bands_out, SPAR_DIRAC_SPLIT_START_BAND) / bw; + + hDirAC = st_ivas->hDirAC; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; + enc_param_start_band = st_ivas->hSpar->enc_param_start_band / bw; + active_w_vlbr = (st_ivas->hDecoderConfig->ivas_total_brate < IVAS_24k4) ? 1 : 0; + + if (hDirAC != NULL && ivas_get_hodirac_flag(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order) == 0) + { + band_grouping = hDirAC->band_grouping; + num_slots_in_subfr = st_ivas->hDirAC->hConfig->dec_param_estim ? CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES : 1; + + for (band = start_band; band < end_band; band++) + { + float PR[3], Pd[3], dvnorm, g_pred; + + PR[0] = hMdDec->spar_md.band_coeffs[band].pred_re[2]; + PR[1] = hMdDec->spar_md.band_coeffs[band].pred_re[0]; + PR[2] = hMdDec->spar_md.band_coeffs[band].pred_re[1]; + g_pred = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + if (g_pred <= EPSILON) + { + dvx[band] = 1.0f; + dvy[band] = 0.0f; + dvz[band] = 0.0f; + } + else + { + g_pred = sqrtf(g_pred); + dvnorm = 1.0f / g_pred; + dvx[band] = PR[0] * dvnorm; + dvy[band] = PR[1] * dvnorm; + dvz[band] = PR[2] * dvnorm; + } + + radius = sqrtf(dvx[band] * dvx[band] + dvy[band] * dvy[band]); + azi[band] = (int16_t)(max(-180.0f, min(180.0f, atan2f(dvy[band], dvx[band]) / EVS_PI * 180.0f)) + 0.5f); + ele[band] = (int16_t)(max(-90.0f, min(180.0f, atan2f(dvz[band], radius) / EVS_PI * 180.0f)) + 0.5f); + + if (st_ivas->nchan_transport == 1) + { + float w_en_norm, f_scale; + if (active_w) + { + if (dtx_vad == 0) + { + f_scale = IVAS_ACTIVEW_DM_F_SCALE_DTX; + } + else + { + f_scale = (active_w_vlbr) ? IVAS_ACTIVEW_DM_F_SCALE_VLBR : IVAS_ACTIVEW_DM_F_SCALE; + } + } + else + { + f_scale = 0.0f; + } + + w_en_norm = (1.0f - (f_scale * g_pred * g_pred)); + w_en_norm *= w_en_norm; + + Pd[0] = hMdDec->spar_md.band_coeffs[band].P_re[1]; + Pd[1] = hMdDec->spar_md.band_coeffs[band].P_re[0]; + Pd[2] = hMdDec->spar_md.band_coeffs[band].P_re[2]; + en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + res_pow = w_en_norm + en_ratio + (Pd[0] * Pd[0] + Pd[1] * Pd[1] + Pd[2] * Pd[2]); + res_pow *= 0.5f; + hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; + hMdDec->spar_md.ref_pow_slow[band] = 0.75f * hMdDec->spar_md.ref_pow_slow[band] + 0.25f * res_pow; + en_ratio = sqrtf(hMdDec->spar_md.en_ratio_slow[band]) / (hMdDec->spar_md.ref_pow_slow[band] + EPSILON); + } + else + { + en_ratio = PR[0] * PR[0] + PR[1] * PR[1] + PR[2] * PR[2]; + hMdDec->spar_md.en_ratio_slow[band] = 0.75f * hMdDec->spar_md.en_ratio_slow[band] + 0.25f * en_ratio; + en_ratio = sqrtf(hMdDec->spar_md.en_ratio_slow[band]); + } + diffuseness[band] = 1.0f - en_ratio; /*compute diffuseness*/ + diffuseness[band] = ((diffuseness[band] < 1.0f) ? ((diffuseness[band] < 0.0f) ? 0.f : diffuseness[band]) : 1.0f); + } + + for (band = start_band; band < end_band; band++) + { + int16_t azi_dith, ele_dith; + tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; + + en_ratio = 1.0f - diffuseness[band]; + masa_sq(1.0f - en_ratio, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS); + + qmf_band_start = band_grouping[band]; + qmf_band_end = band_grouping[band + 1]; + + for (block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++) + { + int16_t ts_start, ts_end, ts; + + ts_start = DirAC_block_grouping[block]; + ts_end = DirAC_block_grouping[block + 1]; + for (b = qmf_band_start; b < qmf_band_end; b++) + { + + azi_dith = azi[band]; + ele_dith = ele[band]; + + hSpatParamRendCom->energy_ratio1[block][b] = en_ratio; + tmp_write_idx_band = tmp_write_idx_param_band; + + if (hDirAC->hConfig->dec_param_estim == FALSE) + { + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; + } + else + { + for (ts = ts_start; ts < ts_end; ts++) + { + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->diffuseness_vector[tmp_write_idx_band][b] = diffuseness[band]; + tmp_write_idx_band = (tmp_write_idx_band + 1) % hSpatParamRendCom->dirac_md_buffer_length; + } + } + } + tmp_write_idx_param_band = (tmp_write_idx_param_band + num_slots_in_subfr) % hSpatParamRendCom->dirac_md_buffer_length; + } + } + + /* update buffer write index */ + if (hDirAC->hConfig->dec_param_estim == FALSE) + { + hDirAC->spar_to_dirac_write_idx = (hDirAC->spar_to_dirac_write_idx + MAX_PARAM_SPATIAL_SUBFRAMES) % hSpatParamRendCom->dirac_md_buffer_length; + } + else + { + hDirAC->spar_to_dirac_write_idx = (hDirAC->spar_to_dirac_write_idx + CLDFB_NO_COL_MAX) % hSpatParamRendCom->dirac_md_buffer_length; + } + } + else + { + band = end_band; + } + + /*read DirAC metadata, convert DirAC to SPAR*/ + for (; band < num_bands_out / bw; band++) + { + int16_t dirac_band_idx; + + dirac_band_idx = dirac_to_spar_md_bands[band] - enc_param_start_band; + + num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; + if (st_ivas->hQMetaData->useLowerRes) + { + num_subframes = 1; + } + + for (block = 0; block < num_subframes; block++) + { + if (st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] < 0.f) + { + st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block] += 360.f; + } + azi_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[block]; + ele_dirac[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation[block]; + } + + diffuseness[band] = 1.0f - st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio[0]; + } + + /* DirAC MD averaged over 4 subframes and converted to SPAR format similar to encoder processing */ + if (hMdDec->spar_md_cfg.nchan_transport > 1) + { + ivas_get_spar_md_from_dirac(azi_dirac, ele_dirac, diffuseness, 1, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out, (hMdDec->spar_hoa_md_flag) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag); + + /* temporarily copy frame-wise prediction coefficients in DirAC bands*/ + for (pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++) + { + for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) + { + pred_re_20ms[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re[pred_idx]; + } + } + } + + int16_t num_md_sub_frames; + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes(sba_order_internal, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate); + ivas_get_spar_md_from_dirac(azi_dirac, ele_dirac, diffuseness, num_md_sub_frames, NULL, &hMdDec->spar_md, &hMdDec->spar_md_cfg, end_band, num_bands_out / bw, (hMdDec->spar_hoa_md_flag) ? 1 : sba_order_internal, dtx_vad, NULL, st_ivas->hQMetaData->useLowerRes, active_w_vlbr, dyn_active_w_flag); + + if (st_ivas->hQMetaData->useLowerRes && dtx_vad) + { + for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) + { + for (block = 1; block < num_md_sub_frames; block++) + { + for (i = 0; i < FOA_CHANNELS - 1; i++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[i] = hMdDec->spar_md.band_coeffs[band].pred_re[i]; + } + for (i = 0; i < FOA_CHANNELS - 1; i++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].P_re[i] = hMdDec->spar_md.band_coeffs[band].P_re[i]; + } + } + } + } + + /* expand DirAC TC 20ms MD for residual channels to all subframes*/ + for (block = 0; block < num_md_sub_frames; block++) + { + for (band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++) + { + for (pred_idx = 0; pred_idx < FOA_CHANNELS - 1; pred_idx++) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ + { + if (ivas_is_res_channel(pred_idx + 1, hMdDec->spar_md_cfg.nchan_transport)) + { + /* use 20ms coefficients only for residual channels */ + hMdDec->spar_md.band_coeffs[band + block * IVAS_MAX_NUM_BANDS].pred_re[pred_idx] = pred_re_20ms[band][pred_idx]; + } + } + } + } + + for (b = end_band * bw; b < num_bands_out; b++) + { + hMdDec->valid_bands[b] = 1; + } + + return; +} + +#endif \ No newline at end of file diff --git a/lib_dec/jbm_pcmdsp_apa.c b/lib_dec/jbm_pcmdsp_apa.c index f57b00307..1586051d6 100644 --- a/lib_dec/jbm_pcmdsp_apa.c +++ b/lib_dec/jbm_pcmdsp_apa.c @@ -338,7 +338,7 @@ bool apa_set_rate( /* (the resulting maximum pitch is then p_min+l_search = 240 samples at 16 kHz) */ ps->l_search = ( ps->rate / 80 ) * ps->num_channels; -#if 1 +#ifdef IVAS_FLOAT_FIXED ps->win_fx = pcmdsp_window_hann_640; move16(); ps->l_halfwin_fx = 320; @@ -1465,6 +1465,7 @@ static bool copy_frm( * ******************************************************************************** */ +#ifdef IVAS_FLOAT_FIXED static bool shrink_frm( apa_state_t *ps, const float frm_in[], @@ -1486,7 +1487,7 @@ static bool shrink_frm( /* only 2nd input frame is used */ frm_in += l_frm; -#if 1 +#ifdef IVAS_FLOAT_FIXED Word16 frm_in_fx[960*4]; for ( i = 0; i < l_frm/*960*ps->num_channels*/; i++ ) { @@ -1542,7 +1543,7 @@ static bool shrink_frm( else { /* find synch */ -#if 1 +#ifdef IVAS_FLOAT_FIXED Word16 energyQ8; Word32 qualityQ16=0; //ps->signalScaleForCorrelation += 2; @@ -1630,8 +1631,147 @@ static bool shrink_frm( return 0; } +#else +static bool shrink_frm( + apa_state_t *ps, + const float frm_in[], + uint16_t maxScaling, + float frm_out[], + uint16_t *l_frm_out ) +{ + bool findSynchResult = 0; + int16_t xtract, l_rem, s_start, s_end; + uint16_t i; + uint16_t over; + float energy, quality = 0.0f; + uint16_t l_frm; + uint16_t l_seg; + + l_frm = ps->l_frm; + l_seg = ps->l_seg; + + /* only 2nd input frame is used */ + frm_in += l_frm; + + /* set search range */ + s_start = ( ps->p_min / ps->num_channels ) * ps->num_channels; + s_end = s_start + ps->l_search; + if ( ( s_end + l_seg ) >= l_frm ) + { + s_end = ( l_frm - l_seg ); + } + + /* calculate overlap position */ + if ( isSilence( frm_in, l_seg, 10 ) ) + { + /* maximum scaling */ + energy = -65; + quality = 5; + if ( ps->evs_compat_mode == false ) + { + + xtract = maxScaling; + /* take samples already in the renderer buf into account */ + xtract += ps->l_r_buf; + /* snap to renderer time slot borders */ + xtract -= ( ps->l_ts - ( l_frm - xtract + ps->l_r_buf ) % ps->l_ts ); + while ( xtract < 0 ) + { + xtract += ps->l_ts; + } + while ( xtract > ( s_end - ps->num_channels ) ) + { + /* exceeded the possible shrinking, go back one renderer ts*/ + xtract -= ps->l_ts; + } + } + else if ( maxScaling != 0U && s_end > maxScaling + 1 ) + { + xtract = maxScaling; + } + else + { + /* set to last valid element (i.e. element[len - 1] but note for stereo last element is last pair of samples) */ + xtract = s_end - ps->num_channels; + } + } + else + { + /* find synch */ + findSynchResult = find_synch( ps, frm_in, l_frm, s_start, (uint16_t) ( s_end - s_start ), 0, l_seg, 0, &energy, &quality, &xtract ); + } + /* assert synch_pos is cleanly divisible by number of channels */ + assert( xtract % ps->num_channels == 0 ); + + /* set frame overlappable - reset if necessary */ + over = 1; + /* test whether frame has sufficient quality */ + if ( quality < ( ps->targetQuality - ( ps->bad_frame_count * 0.1f ) + ( ps->good_frame_count * 0.2f ) ) ) + { + /* not sufficient */ + over = 0; + if ( ps->bad_frame_count < ps->qualityred ) + { + ++ps->bad_frame_count; + } + if ( ps->good_frame_count > 0U ) + { + --ps->good_frame_count; + } + } + else + { + /* sufficient quality */ + if ( ps->bad_frame_count > 0U ) + { + --ps->bad_frame_count; + } + if ( ps->good_frame_count < ps->qualityrise ) + { + ++ps->good_frame_count; + } + } + + /* Calculate output data */ + if ( over && xtract ) + { + if ( findSynchResult == 1 ) + { + return 1; + } + if ( ps->evs_compat_mode == true ) + { + overlapAddEvs( frm_in, frm_in + xtract, frm_out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + } + else + { + overlapAdd( frm_in, frm_in + xtract, frm_out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + } + } + else + { + xtract = 0; + for ( i = 0; i < l_seg; i++ ) + { + frm_out[i] = frm_in[i]; + } + } + + /* append remaining samples */ + l_rem = l_frm - xtract - l_seg; + for ( i = 0; i < l_rem; i++ ) + { + frm_out[l_seg + i] = frm_in[l_frm - l_rem + i]; + } + + /* set output length */ + *l_frm_out = l_seg + l_rem; + + return 0; +} +#endif /* ******************************************************************************** * @@ -1652,6 +1792,7 @@ static bool shrink_frm( * ******************************************************************************** */ +#ifdef IVAS_FLOAT_FIXED static bool extend_frm( apa_state_t *ps, const float frm_in[], @@ -1751,7 +1892,7 @@ static bool extend_frm( over[n] = 0; /* don't search/overlap (just copy down) */ } } -#if 1 +#ifdef IVAS_FLOAT_FIXED Word16 frm_in_fx[1920*2*2*2]; Word16 max_flag = 0; for ( i = 0; i < 2*l_frm; i++ ) @@ -1796,7 +1937,7 @@ static bool extend_frm( } else { -#if 1 +#ifdef IVAS_FLOAT_FIXED Word16 energyQ8=0,*frmInScaled; Word32 qualityQ16=0; frmInScaled = ps->frmInScaled; @@ -1912,3 +2053,214 @@ static bool extend_frm( return 0; } + +#else +static bool extend_frm( + apa_state_t *ps, + const float frm_in[], + float frm_out[], + uint16_t *l_frm_out ) +{ + bool findSynchResult = 0; + uint16_t l_frm_out_target; + uint16_t n, i; + int16_t N; + int16_t s[MAXN + 2], s_max, s_min; + int16_t xtract[MAXN + 2], sync_start, s_end; + uint16_t over[MAXN + 2]; + int16_t l_rem; + int16_t s_start = 0; + float energy, quality = 0.0f; + uint16_t l_frm, l_seg; + const float *fadeOut, *fadeIn; + float *out; + + + l_frm = ps->l_frm; + l_seg = ps->l_seg; + + /* number of segments/iterations */ + l_frm_out_target = (uint16_t) ( (float) l_frm * 1.5f ); + N = ( l_frm_out_target / l_seg ) - 1; + if ( N < 1 ) + { + N = 1; + } + if ( N > MAXN ) + { + return 1; + } + /* calculate equally spaced search regions */ + /* s[n] are given relative to 2nd frame and point to the start of */ + /* the search region. The first segment (n=1) will not be moved. */ + /* Hence, the iterations will start with n=2. */ + s_min = -( ps->l_search ) - ( ps->p_min ); + /* (make sure not to exceed array dimension) */ + if ( l_frm + s_min < 0 ) + { + s_min = -( l_frm ); + } + s_max = l_frm - 2 * l_seg - ps->l_search; + if ( s_max < s_min ) + { + N = 1; + } + /* for just one segment start at s_min */ + if ( N == 1 ) + { + s[2] = s_min; + } + /* else, spread linear in between s_min and s_max */ + /* (including s_min and s_max) */ + else + { + for ( n = 2; n <= ( N + 1 ); n++ ) + { + s[n] = s_min + ( ( s_max - s_min ) * ( n - 2 ) ) / ( N - 1 ); + } + } + + /* + * Planning Phase + */ + + xtract[1] = -( l_seg ); /* make sync_start=0 in 1st iteration */ + n = 2; + + /* define synch segment (to be correlated with search region) */ + sync_start = xtract[n - 1] + l_seg; + over[n] = 1; /* will be reset if overlap is not required */ + /* check end of search region: should be at least p_min */ + /* samples on the left of synch_start */ + if ( ( s[n] + ps->l_search ) < ( sync_start - ( ps->p_min ) ) ) + { + s_start = s[n]; + s_end = s_start + ps->l_search; + } + else + { + /* shrink search region to enforce minimum shift */ + s_end = sync_start - ( ps->p_min ); + if ( s[n] + ps->l_search < sync_start ) + { + s_start = s[n]; /* just do it with normal start position */ + } + else if ( n == ( N + 1 ) ) /* move search region left for last segment */ + { + s_start = s_end - ( ps->l_search - ps->p_min ); + } + else + { + over[n] = 0; /* don't search/overlap (just copy down) */ + } + } + + if ( over[n] ) + { + /* calculate overlap position */ + if ( isSilence( frm_in, l_seg, 10 ) ) + { + /* maximum scaling */ + energy = -65; + quality = 5; + xtract[n] = s_start + ps->num_channels; + if ( ps->evs_compat_mode == false ) + { + /* take renderer buffer samples into accout */ + xtract[n] += ps->l_r_buf; + /* snap to next renderer time slot border to resynchronize */ + xtract[n] -= ( ( N - 1 ) * l_seg - xtract[n] + ps->l_r_buf ) % ps->l_ts; + } + } + else + { + /* find synch */ + findSynchResult = find_synch( ps, frm_in, 2 * l_frm, s_start, s_end - s_start, sync_start, l_seg, l_frm, &energy, &quality, &xtract[n] ); + } + /* assert synch_pos is cleanly divisible by number of channels */ + assert( xtract[n] % ps->num_channels == 0 ); + + /* test for sufficient quality */ + if ( quality < ( ps->targetQuality - ( ps->bad_frame_count * 0.1f ) + ( ps->good_frame_count * 0.2f ) ) ) + { + /* not sufficient */ + over[n] = 0; + xtract[n] = sync_start; + if ( ps->bad_frame_count < ps->qualityred ) + { + ++ps->bad_frame_count; + } + if ( ps->good_frame_count > 0U ) + { + --ps->good_frame_count; + } + } + else + { + /* sufficient quality */ + if ( ps->bad_frame_count > 0U ) + { + --ps->bad_frame_count; + } + if ( ps->good_frame_count < ps->qualityrise ) + { + ++ps->good_frame_count; + } + } + if ( findSynchResult ) + { + return 1; + } + } + else + { + xtract[n] = sync_start; + } + + + /* Calculate output data */ + for ( n = 2; n <= N; n++ ) + { + if ( over[n] && xtract[n - 1] + l_seg != xtract[n] ) + { + /* mix 2nd half of previous segment with 1st half of current segment */ + fadeOut = frm_in + l_frm + xtract[n - 1] + l_seg; + fadeIn = frm_in + l_frm + xtract[n]; + out = frm_out + ( n - 2 ) * l_seg; + if ( ps->evs_compat_mode == true ) + { + overlapAddEvs( fadeOut, fadeIn, out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + } + else + { + overlapAdd( fadeOut, fadeIn, out, l_seg, ps->num_channels, ps->win + ps->l_halfwin, ps->win ); + } + } + else + { + /* just copy down 1st half of current segment (= 2nd half of previous segment) */ + float *frm_out_ptr; + const float *frm_in_ptr; + frm_out_ptr = &( frm_out[( n - 2 ) * l_seg] ); + frm_in_ptr = &( frm_in[l_frm + xtract[n]] ); + for ( i = 0; i < l_seg; i++ ) + { + frm_out_ptr[i] = frm_in_ptr[i]; + } + } + } + + /* append remaining samples */ + l_rem = l_frm - ( xtract[N] + l_seg ); + for ( i = 0; i < l_rem; i++ ) + { + frm_out[( N - 1 ) * l_seg + i] = frm_in[2 * l_frm - l_rem + i]; + } + + /* set output length */ + *l_frm_out = ( N - 1 ) * l_seg + l_rem; + + return 0; +} + +#endif \ No newline at end of file diff --git a/lib_dec/jbm_pcmdsp_window.c b/lib_dec/jbm_pcmdsp_window.c index 40a2a3664..3b38ba115 100644 --- a/lib_dec/jbm_pcmdsp_window.c +++ b/lib_dec/jbm_pcmdsp_window.c @@ -75,7 +75,7 @@ void hannWindow( * * Overlap/Add of two signal with a given window *-----------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED void overlapAdd( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin, Word16 hannIncrementor ) { Word32 fdOutVal, fdInVal; @@ -102,84 +102,89 @@ void overlapAdd( const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word1 } } -void overlapAdd_ivas( - const float *fadeOut, - const float *fadeIn, - float *out, - uint16_t n, - uint16_t nChannels, - const float *fadeOutWin, - const float *fadeInWin ) +#else +void overlapAdd( + const float *fadeOut, + const float *fadeIn, + float *out, + uint16_t n, + uint16_t nChannels, + const float *fadeOutWin, + const float *fadeInWin) { - float fdOutVal, fdInVal; - int16_t i, j, hannIter; - float combinedVal; - - for ( j = 0; j < nChannels; j++ ) + float fdOutVal, fdInVal; + int16_t i, j, hannIter; + float combinedVal; + + for (j = 0; j < nChannels; j++) + { + /* reset Hann window iterator to beginning (both channels use same window) */ + hannIter = 0; + for (i = j; i < n; i += nChannels) { - /* reset Hann window iterator to beginning (both channels use same window) */ - hannIter = 0; - for ( i = j; i < n; i += nChannels ) - { - fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; - fdInVal = fadeIn[i] * fadeInWin[hannIter]; - /* round combinedVal value (taking care of sign) */ - combinedVal = fdInVal + fdOutVal; - out[i] = combinedVal; - hannIter++; - } + fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; + fdInVal = fadeIn[i] * fadeInWin[hannIter]; + /* round combinedVal value (taking care of sign) */ + combinedVal = fdInVal + fdOutVal; + out[i] = combinedVal; + hannIter++; } + } - return; + return; } void overlapAddEvs( - const float *fadeOut, - const float *fadeIn, - float *out, - uint16_t n, - uint16_t nChannels, - const float *fadeOutWin, - const float *fadeInWin ) + const float *fadeOut, + const float *fadeIn, + float *out, + uint16_t n, + uint16_t nChannels, + const float *fadeOutWin, + const float *fadeInWin) { - float fdOutVal, fdInVal; - int16_t i, j, hannIter; - float combinedVal; - - for ( j = 0; j < nChannels; j++ ) + float fdOutVal, fdInVal; + int16_t i, j, hannIter; + float combinedVal; + + for (j = 0; j < nChannels; j++) + { + /* reset Hann window iterator to beginning (both channels use same window) */ + hannIter = 0; + for (i = j; i < n; i += nChannels) { - /* reset Hann window iterator to beginning (both channels use same window) */ - hannIter = 0; - for ( i = j; i < n; i += nChannels ) - { - fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; - fdInVal = fadeIn[i] * fadeInWin[hannIter]; - /* round combinedVal value (taking care of sign) */ - - combinedVal = floorf( ( fdInVal + fdOutVal ) + 0.5f ); - if ( fdInVal + fdOutVal < 0.0 ) - { - combinedVal = ceilf( ( fdInVal + fdOutVal ) - 0.5f ); - } + fdOutVal = fadeOut[i] * fadeOutWin[hannIter]; + fdInVal = fadeIn[i] * fadeInWin[hannIter]; + /* round combinedVal value (taking care of sign) */ + + combinedVal = floorf((fdInVal + fdOutVal) + 0.5f); + if (fdInVal + fdOutVal < 0.0) + { + combinedVal = ceilf((fdInVal + fdOutVal) - 0.5f); + } + + /* saturate value */ + if (combinedVal > MAX16B_FLT) + { + combinedVal = MAX16B_FLT; + } + else if (combinedVal < MIN16B_FLT) + { + combinedVal = MIN16B_FLT; + } + + out[i] = combinedVal; + + hannIter++; + } + } - /* saturate value */ - if ( combinedVal > MAX16B_FLT ) - { - combinedVal = MAX16B_FLT; - } - else if ( combinedVal < MIN16B_FLT ) - { - combinedVal = MIN16B_FLT; - } + return; +} - out[i] = combinedVal; +#endif - hannIter++; - } - } - return; -} #ifdef IVAS_FLOAT_FIXED void overlapAdd_fx(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, diff --git a/lib_dec/jbm_pcmdsp_window.h b/lib_dec/jbm_pcmdsp_window.h index bbd490b84..4b604b70f 100644 --- a/lib_dec/jbm_pcmdsp_window.h +++ b/lib_dec/jbm_pcmdsp_window.h @@ -61,12 +61,14 @@ void hannWindow( uint16_t n, float *w ); * @param[in] nChannels number of channels * @param[in] fadeOutWin window for fade out * @param[in] fadeInWin window for fade in */ -void overlapAdd_ivas( const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin ); -void overlapAddEvs( const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin ); +#ifndef IVAS_FLOAT_FIXED +void overlapAdd(const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin); +void overlapAddEvs(const float *fadeOut, const float *fadeIn, float *out, uint16_t n, uint16_t nChannels, const float *fadeOutWin, const float *fadeInWin); +#else void overlapAdd(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, - Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin, Word16 hannIncrementor); -#ifdef IVAS_FLOAT_FIXED + Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin, Word16 hannIncrementor); + void overlapAdd_fx(const Word16 *fadeOut, const Word16 *fadeIn, Word16 *out, Word16 n, Word16 nChannels, const Word16 *fadeOutWin, const Word16 *fadeInWin ); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 70722637e..eb81feee4 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -5084,7 +5084,6 @@ void td_bwe_dec_init_fx( } set16_fx(hBWE_TD->mem_resamp_HB_fx, 0, INTERP_3_1_MEM_LEN); - set32_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); set16_fx(hBWE_TD->mem_resamp_HB_32k_fx, 0, 2 * ALLPASSSECTIONS_STEEP + 1); set32_fx(hBWE_TD->mem_resamp_HB_32k_fx_32, 0, 2 * ALLPASSSECTIONS_STEEP + 1); diff --git a/lib_dec/tonalMDCTconcealment.c b/lib_dec/tonalMDCTconcealment.c index ff1de4d86..98b367a4b 100644 --- a/lib_dec/tonalMDCTconcealment.c +++ b/lib_dec/tonalMDCTconcealment.c @@ -98,8 +98,9 @@ ivas_error TonalMDCTConceal_Init_ivas( hTonalMDCTConc->nSamples = nSamples; hTonalMDCTConc->nSamplesCore = nSamplesCore; hTonalMDCTConc->nScaleFactors = nScaleFactors; - +#ifdef IVAS_FLOAT_FIXED set32_fx( hTonalMDCTConc->scaleFactorsBackground_fx, 0, FDNS_NPTS ); +#endif #ifndef IVAS_FLOAT_FIXED set_zero( hTonalMDCTConc->scaleFactorsBackground_flt, FDNS_NPTS ); hTonalMDCTConc->scf_fadeout_flt = 1.0f; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index c4d70edf8..48d74e8f8 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -163,6 +163,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( int16_t j, k, bin; float binCenterFreq, tmpFloat; ivas_error error; + float frequency_axis[CLDFB_NO_CHANNELS_MAX]; hDiracDecBin = st_ivas->hDiracDecBin; if ( hDiracDecBin == NULL ) @@ -188,10 +189,6 @@ ivas_error ivas_dirac_dec_init_binaural_data( { set_zero( hDiracDecBin->processMtxRe[j][k], nBins ); set_zero( hDiracDecBin->processMtxIm[j][k], nBins ); -#ifdef IVAS_FLOAT_FIXED //must be removed// - set_zero(hDiracDecBin->processMtxRePrev[j][k], nBins); - set_zero(hDiracDecBin->processMtxImPrev[j][k], nBins); -#endif } for ( k = 0; k < BINAURAL_CHANNELS; k++ ) @@ -279,47 +276,22 @@ ivas_error ivas_dirac_dec_init_binaural_data( if ( !hDiracDecBin->useTdDecorr && !( st_ivas->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM ) ) { -#ifdef IVAS_FLOAT_FIXED - Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; - ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, output_Fs, nBins ); - - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDiracDecBin->h_freq_domain_decorr_ap_params ), - &( hDiracDecBin->h_freq_domain_decorr_ap_state ), - nBins, - BINAURAL_CHANNELS, - BINAURAL_CHANNELS, - DIRAC_SYNTHESIS_PSD_LS, - frequency_axis_fx, - BINAURAL_CHANNELS, - output_Fs ) ) != IVAS_ERR_OK ) - { - return error; - } -#else - Word16 frequency_axis[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis( frequency_axis, output_Fs, nBins ); - - if ((error = ivas_dirac_dec_decorr_open(&(hDiracDecBin->h_freq_domain_decorr_ap_params), - &(hDiracDecBin->h_freq_domain_decorr_ap_state), - nBins, - BINAURAL_CHANNELS, - BINAURAL_CHANNELS, - DIRAC_SYNTHESIS_PSD_LS, - frequency_axis, - BINAURAL_CHANNELS, - output_Fs)) != IVAS_ERR_OK) + if ( ( error = ivas_dirac_dec_decorr_open( &( hDiracDecBin->h_freq_domain_decorr_ap_params ), + &( hDiracDecBin->h_freq_domain_decorr_ap_state ), + nBins, + BINAURAL_CHANNELS, + BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, + frequency_axis, + BINAURAL_CHANNELS, + output_Fs ) ) != IVAS_ERR_OK ) { return error; } -#endif - } -#ifdef IVAS_FLOAT_FIXED - hDiracDecBin->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); -#else hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); -#endif st_ivas->hDiracDecBin = hDiracDecBin; @@ -341,11 +313,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ } -#ifdef IVAS_FLOAT_FIXED - if ( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) -#endif { return error; } diff --git a/lib_rend/ivas_reflections.c b/lib_rend/ivas_reflections.c index 7a82e922c..dcb41e6aa 100644 --- a/lib_rend/ivas_reflections.c +++ b/lib_rend/ivas_reflections.c @@ -600,7 +600,7 @@ ivas_error ivas_er_encoder_init( Function computes reflections using the shoebox library and sets up the circular buffers structure for the early reflections process *-----------------------------------------------------------------------------------------*/ - +#ifdef IVAS_FLOAT_FIXED ivas_error ivas_er_compute_reflections( er_struct_t *reflections ) { @@ -751,6 +751,95 @@ ivas_error ivas_er_compute_reflections( return error; } + +#else +ivas_error ivas_er_compute_reflections( + er_struct_t *reflections) +{ + ivas_error error = IVAS_ERR_OK; + uint16_t circ_len, i, j; + float tmp; + + reflections->is_ready = 0; + + /* Disabled case */ + if (reflections->audio_config == IVAS_AUDIO_CONFIG_INVALID) + { + return error; + } + + /* Run shoebox with current reflection parameters */ + ivas_shoebox_set_scene(&(reflections->shoebox_lib), &(reflections->shoebox_data), reflections->shoebox_lib.cal.list_orig, + reflections->source_positions, reflections->is_cartesian, reflections->is_relative); + + /* Convert reflection times in seconds to samples and keep track of max */ + circ_len = 0; + for (i = 0; i < reflections->shoebox_data.n_sources; i++) + { + for (j = 0; j < reflections->shoebox_data.n_ref; j++) + { + tmp = reflections->shoebox_data.times.data[j + (i * reflections->shoebox_data.n_ref)]; + tmp = roundf(tmp * reflections->output_Fs); + reflections->shoebox_data.times.data[j + (i * reflections->shoebox_data.n_ref)] = tmp; + circ_len = ((uint16_t)tmp > circ_len) ? (uint16_t)tmp : circ_len; + } + } + + /* 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; + circ_len += (uint16_t)reflections->max_frame_size; + + /* If circ buffers exist and size is the same, reset memory to all zeros */ + /* If size is different, reallocate circ buffers */ + /* Otherwise allocate new circ buffers */ + if (reflections->circ_buffers) + { + if (reflections->circ_len == circ_len) + { + /* circ buffers exist and size is the same */ + set_f(reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len); + } + else + { + /* circ buffers exist but size is different */ + reflections->circ_len = circ_len; + free(reflections->circ_buffers); + if ((reflections->circ_buffers = (float *)malloc(reflections->shoebox_data.n_sources * reflections->circ_len * sizeof(float))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers"); + } + set_f(reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len); + } + } + else + { + /* circ buffers do not exist */ + reflections->circ_len = circ_len; + if ((reflections->circ_buffers = (float *)malloc(reflections->shoebox_data.n_sources * reflections->circ_len * sizeof(float))) == NULL) + { + return IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections buffers"); + } + set_f(reflections->circ_buffers, 0.0f, reflections->shoebox_data.n_sources * reflections->circ_len); + } + + + /* Initialize circular buffer insertion point */ + reflections->circ_insert = reflections->circ_len - (uint16_t)reflections->max_frame_size; + + /* Get total reflections number */ + reflections->n_total_reflections = reflections->shoebox_data.n_sources * reflections->shoebox_data.n_ref; + + /* Check that reflection buffers were allocated */ + if (error != IVAS_ERR_OK) + { + return error; + } + + return error; +} + +#endif + #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 3cd0917bf..f8e577f69 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1426,13 +1426,15 @@ typedef struct er_struct_t Word32 output_Fs_fx; Word32 source_positions_fx[75]; Word32 user_origin_fx[3]; //is not needed + Word32 *circ_buffers; #else float source_positions[75]; float user_origin[3]; float output_Fs; + float *circ_buffers; #endif - Word32 *circ_buffers; + UWord16 *closest_ch_idx; shoebox_output_t shoebox_data; shoebox_obj_t shoebox_lib; -- GitLab