From 30de5886ed078d4b0f1c30d7544179b1e0e8f57c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Sun, 19 May 2024 20:29:22 +0530 Subject: [PATCH] MSAN fixes for stereo, isma, omasa, osba, float cleanup [x] MSAN fix for stereo format errors [x] MSAN fixes for ISM format errors [x] MSAN fixes for OSBA and OMASA errors [x] Float code cleanup in lib_rend [x] MSAN fix for test_sba_enc_system cases --- lib_com/fd_cng_com.c | 10 - lib_com/float_to_fix_ops.c | 4 +- lib_com/ivas_prot_fx.h | 3 + lib_com/ivas_spar_com.c | 6 +- lib_com/ivas_spar_com_quant_util.c | 170 ++++++++------ lib_com/swb_tbe_com_fx.c | 2 +- lib_dec/core_switching_dec_fx.c | 6 +- lib_dec/dec_gen_voic_fx.c | 2 +- lib_dec/ivas_binRenderer_internal.c | 70 +++--- lib_dec/ivas_dirac_dec.c | 80 +++---- lib_dec/ivas_jbm_dec.c | 1 + lib_dec/ivas_omasa_dec.c | 20 ++ lib_dec/ivas_spar_decoder.c | 73 ++++-- lib_dec/swb_bwe_dec_fx.c | 14 +- lib_rend/ivas_crend.c | 116 +++++----- lib_rend/ivas_dirac_dec_binaural_functions.c | 13 +- lib_rend/ivas_dirac_output_synthesis_dec.c | 105 +++------ lib_rend/ivas_dirac_rend.c | 59 ++--- lib_rend/ivas_efap.c | 192 ++++++++-------- lib_rend/ivas_orient_trk.c | 44 ++-- lib_rend/ivas_prot_rend.h | 3 +- lib_rend/ivas_reverb.c | 220 +++++++++++++------ lib_rend/ivas_rotation.c | 123 ++++++----- 23 files changed, 729 insertions(+), 607 deletions(-) diff --git a/lib_com/fd_cng_com.c b/lib_com/fd_cng_com.c index 7f8411445..eba4a7980 100644 --- a/lib_com/fd_cng_com.c +++ b/lib_com/fd_cng_com.c @@ -51,9 +51,7 @@ * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void mhvals_flt( const int16_t d, float *m ); -#endif static void getmidbands( int16_t *part, const int16_t npart, int16_t *midband, float *psize_flt, float *psize_inv_flt ); @@ -93,7 +91,6 @@ void initFdCngCom_flt( const float scale ) { -#ifndef IVAS_FLOAT_FIXED /* Calculate FFT scaling factor */ hFdCngCom->scalingFactor_flt = 1 / ( scale * scale * 8.f ); @@ -104,7 +101,6 @@ void initFdCngCom_flt( /* Initialize the comfort noise generation */ set_f( hFdCngCom->fftBuffer_flt, 0.0f, FFTLEN ); -#endif UNUSED_PARAM(scale); set_f( hFdCngCom->cngNoiseLevel_flt, 0.0f, FFTCLDFBLEN ); set_f( hFdCngCom->olapBufferSynth2_flt, 0.0f, FFTLEN ); @@ -137,7 +133,6 @@ void initFdCngCom_flt( hFdCngCom->seed2 = 1; hFdCngCom->seed3 = 2; hFdCngCom->CngBitrate = -1; -#ifndef IVAS_FLOAT_FIXED /* Initialize noise estimation algorithm */ set_f( hFdCngCom->periodog_flt, 0.0f, PERIODOGLEN ); mhvals_flt( MSNUMSUBFR * MSSUBFRLEN, &( hFdCngCom->msM_win_flt ) ); @@ -147,17 +142,14 @@ void initFdCngCom_flt( set_f( hFdCngCom->msSlope_flt, 0.0f, 2 ); set_f( hFdCngCom->msQeqInvAv_flt, 0.0f, 2 ); hFdCngCom->init_old_flt = 0; -#endif hFdCngCom->msFrCnt_init_counter = 0; hFdCngCom->msFrCnt_init_thresh = 1; hFdCngCom->offsetflag = 0; hFdCngCom->msFrCnt = MSSUBFRLEN; hFdCngCom->msMinBufferPtr = 0; -#ifndef IVAS_FLOAT_FIXED set_f( hFdCngCom->msAlphaCor_flt, 0.3f, 2 ); hFdCngCom->coherence_flt = 0.5f; -#endif return; } @@ -1217,7 +1209,6 @@ void SynthesisSTFT_dirac_fx( * Compute some values used in the bias correction of the minimum statistics algorithm *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void mhvals_flt( const int16_t d, float *m ) @@ -1257,7 +1248,6 @@ static void mhvals_flt( return; } -#endif /*------------------------------------------------------------------- * rand_gauss_flt() diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 9da36155b..57c6ded70 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -12,11 +12,11 @@ Word32 floatToFixed(float f, Word16 Q) if (f == 1.0f && Q == Q31) return MAXVAL_WORD32; if (Q < 0) - return (Word32)((float)(f) / (float)(((unsigned)1) << (-Q)) + (f >= 0 ? 0.5 : -0.5)); + return (Word32)((float)(f) / (double)(1llu << (-Q)) + (f >= 0 ? 0.5 : -0.5)); else { Word64 result_32; - result_32=(Word64)(f * (float)((unsigned int)1 << Q) + (f >= 0 ? 0.5 : -0.5)); + result_32=(Word64)(f * (double)(1llu << Q) + (f >= 0 ? 0.5 : -0.5)); if (result_32 > MAX_32) return MAX_32; if (result_32 < MIN_32) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 814fde0dd..c1c36e15b 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2107,6 +2107,9 @@ void td_bwe_dec_init_ivas_fx( void ivas_dirac_dec_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ +#ifdef MSAN_FIX + Word32 *output_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ +#endif // MSAN_FIX const int16_t nchan_transport, /* i : number of transport channels */ float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 2f867f212..624d8e345 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -6644,8 +6644,10 @@ void ivas_spar_set_bitrate_config_fx( pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; -#if 1 //Some issues - ivas_spar_get_uniform_quant_strat(pSpar_md_cfg, table_idx); +#ifdef IVAS_FLOAT_FIXED + ivas_spar_get_uniform_quant_strat_fx( pSpar_md_cfg, table_idx ); +#else + ivas_spar_get_uniform_quant_strat( pSpar_md_cfg, table_idx ); #endif pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode(MAX_QUANT_STRATS); diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 763eb9d84..79e55940a 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -135,7 +135,6 @@ void ivas_quantise_real_values_fx( } -#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_spar_get_uniform_quant_strat() * @@ -214,73 +213,120 @@ void ivas_spar_get_uniform_quant_strat( return; } -#else -void ivas_spar_get_uniform_quant_strat( - ivas_spar_md_com_cfg *pSpar_md_com_cfg, - const Word16 table_idx) + + +#ifdef IVAS_FLOAT_FIXED +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_get_uniform_quant_strat_fx() + * + * Sets the quant strat values + *-----------------------------------------------------------------------------------------*/ +void ivas_spar_get_uniform_quant_strat_fx( + ivas_spar_md_com_cfg *pSpar_md_com_cfg, + const Word16 table_idx ) { - Word16 i; - Word16 active_w = ivas_spar_br_table_consts[table_idx].active_w; - Word16 PQ_q_lvl, C_q_lvl, Pr_q_lvl, Pc_q_lvl; + Word16 i; + Word16 active_w = ivas_spar_br_table_consts[table_idx].active_w; + move16(); + Word16 PQ_q_lvl, C_q_lvl, Pr_q_lvl, Pc_q_lvl; - pSpar_md_com_cfg->num_quant_strats = MAX_QUANT_STRATS; + pSpar_md_com_cfg->num_quant_strats = MAX_QUANT_STRATS; + move16(); - for ( i = 0; i < pSpar_md_com_cfg->num_quant_strats; i++ ) - { - PQ_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; - C_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; - Pr_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; - Pc_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][3]; - - if ( active_w ) - { - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -322122547;//1.2*Q28 - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = 322122547;//1.2*Q28 - - pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -214748364; - pSpar_md_com_cfg->quant_strat[i].C.max_fx = 214748364;//.8*Q28 - - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = 214748364;//.8*Q28 - - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -214748364;//.8*Q28 - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 214748364; //.8*Q28 - } - else - { - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; - pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; - pSpar_md_com_cfg->quant_strat[i].PR.min_fx = -ONE_IN_Q28; - - pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; - pSpar_md_com_cfg->quant_strat[i].C.max_fx = 2 *ONE_IN_Q28; - pSpar_md_com_cfg->quant_strat[i].C.min_fx = -2*ONE_IN_Q28; - - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; - pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; - - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; - pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; //.5* Q28 - pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = -ONE_IN_Q27;//.5* Q28 - } - } + FOR( i = 0; i < pSpar_md_com_cfg->num_quant_strats; i++ ) + { + PQ_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; + move16(); + C_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; + move16(); + Pr_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; + move16(); + Pc_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][3]; + move16(); - return; + if ( active_w ) + { + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = L_negate( 322122547 ); // -1.2*Q28 + move32(); + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = 322122547; // 1.2*Q28 + move32(); + + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].C.min_fx = L_negate( 214748364 ); //-.8*Q28 + move32(); + pSpar_md_com_cfg->quant_strat[i].C.max_fx = 214748364; //.8*Q28 + move32(); + + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; + move32(); + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = 214748364; //.8*Q28 + move32(); + + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = L_negate( 214748364 ); //-.8*Q28 + move32(); + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = 214748364; //.8*Q28 + move32(); + } + else + { + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].PR.max_fx = ONE_IN_Q28; // Q28 + move32(); + pSpar_md_com_cfg->quant_strat[i].PR.min_fx = L_negate( ONE_IN_Q28 ); // Q28 + move32(); + + pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].C.max_fx = ONE_IN_Q29; // Q28 + move32(); + pSpar_md_com_cfg->quant_strat[i].C.min_fx = L_negate( ONE_IN_Q29 ); // Q28 + move32(); + + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_r.max_fx = ONE_IN_Q28; // Q28 + move32(); + pSpar_md_com_cfg->quant_strat[i].P_r.min_fx = 0; // Q28 + move32(); + + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl; + move16(); + pSpar_md_com_cfg->quant_strat[i].P_c.max_fx = ONE_IN_Q27; // Q28 + move32(); + pSpar_md_com_cfg->quant_strat[i].P_c.min_fx = L_negate( ONE_IN_Q27 ); // Q28 + move32(); + } + } + + return; } #endif + + /*-----------------------------------------------------------------------------------------* * Function ivas_map_prior_coeffs_quant() * diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 300433048..97a0ff3d2 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -761,7 +761,7 @@ static void filt_mu_fx( tmp = sub(32767 , tmp); exp = norm_s(tmp); tmp = div_s(shl(1,sub(14,exp)),tmp);/*(14 - exp) */ - ga = shl(tmp ,exp);/*Q14 */ + ga = shl_sat(tmp ,exp);/*Q14 */ /* ga = (float) 1. / ((float) 1. - (float) fabs (mu)); */ diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 252bec195..2cf9bcc3a 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1863,7 +1863,7 @@ ivas_error core_switching_post_dec_ivas_fx( nzeroes = i_mult2( delta, N_ZERO_8 ); shift = i_mult2( Fs_kHz, 3 ); test(); - IF( st_fx->prev_bfi && hHQ_core->HqVoicing && st_fx->hHQ_core != NULL && st_fx->last_core == HQ_CORE ) + IF( st_fx->prev_bfi && st_fx->hHQ_core != NULL && hHQ_core->HqVoicing && st_fx->last_core == HQ_CORE ) { Copy_Scale_sig( hHQ_core->fer_samples_fx, &hHQ_core->old_out_fx[nzeroes], shift, *Qsynth ); } @@ -1945,8 +1945,8 @@ ivas_error core_switching_post_dec_ivas_fx( move16(); } - IF( ( NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || ( NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) || - ( ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_extl, SWB_TBE ) ) && st_fx->extl < 0 && NE_16( st_fx->core, HQ_CORE ) ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) && ( ( NE_16( st_fx->prev_coder_type, INACTIVE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) || ( NE_16( st_fx->prev_coder_type, AUDIO ) && EQ_16( st_fx->coder_type, AUDIO ) ) ) && st_fx->bws_cnt > 0 ) ) + IF( ( st_fx->hBWE_FD != NULL ) && ( ( NE_16( st_fx->last_extl, SWB_BWE ) && EQ_16( st_fx->extl, SWB_BWE ) ) || ( NE_16( st_fx->last_extl, FB_BWE ) && EQ_16( st_fx->extl, FB_BWE ) ) || + ( ( EQ_16( st_fx->last_core, HQ_CORE ) || EQ_16( st_fx->last_extl, SWB_TBE ) ) && st_fx->extl < 0 && NE_16( st_fx->core, HQ_CORE ) ) || ( EQ_16( st_fx->last_core, ACELP_CORE ) && EQ_16( st_fx->core, ACELP_CORE ) && ( ( NE_16( st_fx->prev_coder_type, INACTIVE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) || ( NE_16( st_fx->prev_coder_type, AUDIO ) && EQ_16( st_fx->coder_type, AUDIO ) ) ) && st_fx->bws_cnt > 0 ) ) ) { set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); hBWE_FD->old_wtda_swb_fx_exp = 0; diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index 7b43ca054..8e016830a 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -248,7 +248,7 @@ ivas_error decod_gen_voic_fx( Word32 Ltmp1; /* Contribution from AVQ layer */ Ltmp1 = L_mult(gain_preQ_fx, code_preQ_fx[i]); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl(Ltmp1,tmp1_fx); /* Q16 + Q_exc */ + Ltmp1 = L_shl_sat(Ltmp1,tmp1_fx); /* Q16 + Q_exc */ /* Compute exc2 */ #ifdef BASOP_NOGLOB diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index d3b86d78b..e7fd85edf 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -257,52 +257,52 @@ static ivas_error ivas_binRenderer_convModuleOpen( ELSE { /* Note: needs to be revisited if multiple LFE support is required */ - hBinRenderer->nInChannels = ( audioCfg2channels( input_config ) - isLoudspeaker ); + hBinRenderer->nInChannels = sub( audioCfg2channels( input_config ), isLoudspeaker ); } - IF( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF(EQ_16( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM )) { - hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; + hBinRenConvModule->numTaps = BINAURAL_NTAPS_MAX; move16(); /* Use variable order filtering */ - bandIdx = 0; + bandIdx = 0; move16(); FOR( ; bandIdx < 5; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; move16(); } FOR( ; bandIdx < 10; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_6; + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_6; move16(); } FOR( ; bandIdx < 20; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_5; + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_5; move16(); } FOR( ; bandIdx < 30; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_4; + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_4; move16(); } FOR( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_3; + hBinRenConvModule->numTapsArray[bandIdx] = NUM_TAPS_F0_3; move16(); } } ELSE { - IF( hBinRenderer->ivas_format == SBA_FORMAT ) + IF( EQ_16(hBinRenderer->ivas_format, SBA_FORMAT )) { - hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; + hBinRenConvModule->numTaps = BINAURAL_NTAPS_SBA; move16(); } ELSE { - hBinRenConvModule->numTaps = BINAURAL_NTAPS; + hBinRenConvModule->numTaps = BINAURAL_NTAPS; move16(); } /* Use fixed order filtering */ - bandIdx = 0; + bandIdx = 0; move16(); FOR( ; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; + hBinRenConvModule->numTapsArray[bandIdx] = hBinRenConvModule->numTaps; move16(); } } @@ -406,38 +406,38 @@ static ivas_error ivas_binRenderer_convModuleOpen( { FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - Word16 tmp = 0; + Word16 tmp = 0; move16(); IF( isLoudspeaker ) { - IF( input_config == IVAS_AUDIO_CONFIG_5_1 ) + IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_5_1 )) { - tmp = channelIndex_CICP6[chIdx]; + tmp = channelIndex_CICP6[chIdx]; move16(); } - ELSE IF( input_config == IVAS_AUDIO_CONFIG_7_1 ) + ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_7_1 )) { - tmp = channelIndex_CICP12[chIdx]; + tmp = channelIndex_CICP12[chIdx]; move16(); } - ELSE IF( input_config == IVAS_AUDIO_CONFIG_5_1_2 ) + ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_5_1_2 )) { - tmp = channelIndex_CICP14[chIdx]; + tmp = channelIndex_CICP14[chIdx]; move16(); } - ELSE IF( input_config == IVAS_AUDIO_CONFIG_5_1_4 ) + ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_5_1_4 )) { - tmp = channelIndex_CICP16[chIdx]; + tmp = channelIndex_CICP16[chIdx]; move16(); } - ELSE IF( input_config == IVAS_AUDIO_CONFIG_7_1_4 ) + ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_7_1_4 )) { - tmp = channelIndex_CICP19[chIdx]; + tmp = channelIndex_CICP19[chIdx]; move16(); } } - IF( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + IF( EQ_16(renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM )) { /* set the memories to zero */ - set_l( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] ); - set_l( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] ); - set_s( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx], 31, hBinRenConvModule->numTapsArray[bandIdx] ); + set32_fx( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] ); + set32_fx( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTapsArray[bandIdx] ); + set16_fx( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx], 31, hBinRenConvModule->numTapsArray[bandIdx] ); IF( isLoudspeaker ) { hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftBRIRReal_fx[bandIdx][tmp]; @@ -449,9 +449,9 @@ static ivas_error ivas_binRenderer_convModuleOpen( ELSE { /* set the memories to zero */ - set_l( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps ); - set_l( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps ); - set_s( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx], 31, hBinRenConvModule->numTaps ); + set32_fx( hBinRenConvModule->filterStatesLeftReal_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps ); + set32_fx( hBinRenConvModule->filterStatesLeftImag_fx[bandIdx][chIdx], 0, hBinRenConvModule->numTaps ); + set16_fx( hBinRenConvModule->Q_filterStatesLeft[bandIdx][chIdx], 31, hBinRenConvModule->numTaps ); IF( isLoudspeaker ) { hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_fx[bandIdx][tmp]; @@ -461,7 +461,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( } ELSE { - IF( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_HOA3 )) { /* HOA3 filter coefficients */ hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA3_fx[bandIdx][chIdx]; @@ -469,7 +469,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA3_fx[bandIdx][chIdx]; hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA3_fx[bandIdx][chIdx]; } - ELSE IF( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_HOA2 )) { /* HOA2 filter coefficients */ hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_HOA2_fx[bandIdx][chIdx]; @@ -477,7 +477,7 @@ static ivas_error ivas_binRenderer_convModuleOpen( hBinRenConvModule->filterTapsRightReal_fx[bandIdx][chIdx] = hHrtf->rightHRIRReal_HOA2_fx[bandIdx][chIdx]; hBinRenConvModule->filterTapsRightImag_fx[bandIdx][chIdx] = hHrtf->rightHRIRImag_HOA2_fx[bandIdx][chIdx]; } - ELSE IF( input_config == IVAS_AUDIO_CONFIG_FOA ) + ELSE IF( EQ_16(input_config, IVAS_AUDIO_CONFIG_FOA )) { /* FOA filter coefficients */ hBinRenConvModule->filterTapsLeftReal_fx[bandIdx][chIdx] = hHrtf->leftHRIRReal_FOA_fx[bandIdx][chIdx]; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index ff1a6655f..80f3e11ed 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1625,14 +1625,14 @@ ivas_error ivas_dirac_dec_config_fx( /* Solve and setup flags for inits */ dec_config_flag = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; - output_Fs = st_ivas->hDecoderConfig->output_Fs; + output_Fs = st_ivas->hDecoderConfig->output_Fs; move32(); hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; - sparfoa_flag = 0; + sparfoa_flag = 0; move16(); IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) { - sparfoa_flag = 1; + sparfoa_flag = 1; move16(); } IF( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) @@ -1641,25 +1641,26 @@ ivas_error ivas_dirac_dec_config_fx( } /* This is required for parambin */ - IF( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + test(); test(); + IF( EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC) || EQ_16(st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM) || EQ_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC )) { - st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; + st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; move16(); } - dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim; + dec_param_estim_new = st_ivas->hDirAC->hConfig->dec_param_estim; move16(); /* Setup renderers and meta */ /* First, free everything if in reconfig and not the active renderer */ - need_parambin = 0; + need_parambin = 0; move16(); SWITCH( st_ivas->renderer_type ) { case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: case RENDERER_STEREO_PARAMETRIC: - need_parambin = 1; + need_parambin = 1; move16(); BREAK; default: - need_parambin = 0; + need_parambin = 0; move16(); } IF( !need_parambin ) @@ -1667,7 +1668,7 @@ ivas_error ivas_dirac_dec_config_fx( ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); } - need_dirac_rend = 0; + need_dirac_rend = 0; move16(); SWITCH( st_ivas->renderer_type ) { case RENDERER_DIRAC: @@ -1677,56 +1678,37 @@ ivas_error ivas_dirac_dec_config_fx( case RENDERER_SBA_LINEAR_DEC: case RENDERER_OSBA_AMBI: case RENDERER_OSBA_LS: - need_dirac_rend = 1; + need_dirac_rend = 1; move16(); BREAK; default: - need_dirac_rend = 0; + need_dirac_rend = 0; move16(); } IF( !need_dirac_rend ) { -#ifdef IVAS_FLOAT_FIXED ivas_dirac_rend_close_fx( &st_ivas->hDirACRend ); -#else - ivas_dirac_rend_close( &st_ivas->hDirACRend ); -#endif } IF( !sparfoa_flag ) { common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp; -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_spat_hSpatParamRendCom_config( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, - st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif IF( need_dirac_rend ) { rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp; -#ifdef IVAS_FLOAT_FIXED IF( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) { return error; } -#else - if ( ( error = ivas_dirac_rend_config( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) - { - return error; - } -#endif } IF( need_parambin ) { - IF( st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) + IF( NE_16(st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC )) { /*WIP*/ IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) @@ -1760,40 +1742,17 @@ ivas_error ivas_dirac_dec_config_fx( { IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params == NULL ) { - //float frequency_axis[CLDFB_NO_CHANNELS_MAX]; -#ifdef IVAS_FLOAT_FIXED Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); - /*FOR( int i = 0; i < st_ivas->hSpatParamRendCom->num_freq_bands; i++ ) - { - frequency_axis[i] = (float) frequency_axis_fx[i]; - }*/ - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) { return error; } -#else - - ivas_dirac_dec_get_frequency_axis( frequency_axis, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); - - IF((error = ivas_dirac_dec_decorr_open(&(st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params), &(st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, - DIRAC_SYNTHESIS_PSD_LS, frequency_axis, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs)) != IVAS_ERR_OK) - { - return error; - } -#endif - } } - -#ifdef IVAS_FLOAT_FIXED st_ivas->hDiracDecBin->reqularizationFactor_fx = configure_reqularization_factor_fx( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); -#else - st_ivas->hDiracDecBin->reqularizationFactor = configure_reqularization_factor( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate ); -#endif } } } @@ -3442,7 +3401,11 @@ void ivas_dirac_dec_render_fx( FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { +#ifdef MSAN_FIX + ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local, output_f_local_fx, nchan_transport, NULL, NULL ); +#else ivas_dirac_dec_render_sf_fx( st_ivas, output_f_local, nchan_transport, NULL, NULL ); +#endif // MSAN_FIX n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size ); @@ -3577,6 +3540,9 @@ void ivas_dirac_dec_render( void ivas_dirac_dec_render_sf_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ +#ifdef MSAN_FIX + Word32 *output_buf_fx[], /* i/o: synthesized core-coder transport channels/DirAC output */ +#endif // MSAN_FIX const int16_t nchan_transport, /* i : number of transport channels */ float *pppQMfFrame_ts_re[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX], float *pppQMfFrame_ts_im[IVAS_MAX_FB_MIXER_IN_CH][CLDFB_NO_COL_MAX] ) @@ -5143,7 +5109,9 @@ void ivas_dirac_dec_render_sf_fx( #ifdef IVAS_FLOAT_FIXED //////////////////////////////////////////////// FLOAT TO FIXED ///////////////////////////////////////////// +#ifndef MSAN_FIX Word32 output_buf_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; +#endif // MSAN_FIX if (st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM) { // Float to fixed @@ -5172,10 +5140,12 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add(outchannels, 1); } +#ifndef MSAN_FIX for (i = 0; i < outchannels; i++) { floatToFixed_arrL(output_f[i], output_buf_fx[i], Q11, L_FRAME48k); } +#endif } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// #endif diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 2a7614384..289027ca4 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -153,6 +153,7 @@ ivas_error ivas_jbm_dec_tc( { st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; #if 1 // TODO: To be removed later + set_zero(st_ivas->p_output_f[n], L_FRAME48k); st_ivas->hTcBuffer->tc[n] = st_ivas->p_output_f[n]; #ifndef MSAN_FIX floatToFixed_arrL( st_ivas->hTcBuffer->tc[n], st_ivas->hTcBuffer->tc_fx[n], Q11, L_FRAME48k ); diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 8e5411073..04d732ee9 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -1417,10 +1417,17 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( ivas_error error; float *p_sepobj[MAX_NUM_OBJECTS]; float *tc_local[MAX_TRANSPORT_CHANNELS]; +#ifdef MSAN_FIX + Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; + Word32 data_separated_objects_fx[MAX_NUM_OBJECTS][L_FRAME48k]; +#endif // MSAN_FIX for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) { p_sepobj[n] = &data_separated_objects[n][0]; +#ifdef MSAN_FIX + p_sepobj_fx[n] = &data_separated_objects_fx[n][0]; +#endif // MSAN_FIX } /* Delay the object signals to match the CLDFB delay. Delay the whole buffer with the first rendering call of the stretched buffer. */ @@ -1454,6 +1461,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( #ifdef IVAS_FLOAT_FIXED #if 1 /* TODO: remove float to fix conversions */ Word16 q_factor = Q11; +#ifndef MSAN_FIX Word32 rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k]; Word32 *p_rend_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS]; for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) @@ -1464,6 +1472,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( p_rend_output_fx[i][j] = floatToFixed(p_sepobj[i][j], Q11); } } +#endif Word16 n_tc; if (st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT) n_tc = st_ivas->nchan_ism; @@ -1474,16 +1483,27 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm( floatToFixed_arrL(st_ivas->hTcBuffer->tc[ch], st_ivas->hTcBuffer->tc_fx[ch], Q11, L_FRAME48k); } #endif +#ifdef MSAN_FIX + IF( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } +#else IF ( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_rend_output_fx, q_factor, *nSamplesRendered ) ) != IVAS_ERR_OK ) { return error; } +#endif #if 1 /* TODO: remove fixed to float conversions */ for (int i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++) { for (int j = 0; j < L_FRAME48k; j++) { +#ifdef MSAN_FIX + p_sepobj[i][j] = fixedToFloat(p_sepobj_fx[i][j], Q11); +#else p_sepobj[i][j] = fixedToFloat(p_rend_output_fx[i][j], Q11); +#endif } } #endif diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 494a6a035..7bbf1b85a 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -3205,17 +3205,34 @@ void ivas_spar_dec_upmixer_sf_fx( } #ifdef IVAS_FLOAT_FIXED /*Fixed to float */ - FOR ( in_ch = 0; in_ch < numch_in; in_ch++ ) - { - FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) - { - FOR ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) - { - cldfb_in_ts_re[in_ch][ts][i] = (float) ( cldfb_in_ts_re_fx[in_ch][ts][i] ) / (float) ( 1LL << 6 ); /*Resultant q is 6*/ - cldfb_in_ts_im[in_ch][ts][i] = (float) ( cldfb_in_ts_im_fx[in_ch][ts][i] ) / (float) ( 1LL << 6 ); /*Resultant q is 6*/ - } - } - } + IF(NE_16(hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA)) + { + FOR(in_ch = 0; in_ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; in_ch++) + { + FOR(ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++) + { + FOR(i = 0; i < CLDFB_NO_CHANNELS_MAX; i++) + { + cldfb_in_ts_re[in_ch][ts][i] = (float)(cldfb_in_ts_re_fx[in_ch][ts][i]) / (float)(1LL << 6); /*Resultant q is 6*/ + cldfb_in_ts_im[in_ch][ts][i] = (float)(cldfb_in_ts_im_fx[in_ch][ts][i]) / (float)(1LL << 6); /*Resultant q is 6*/ + } + } + } + } + ELSE + { + FOR ( in_ch = 0; in_ch < numch_in; in_ch++ ) + { + FOR ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + { + FOR ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) + { + cldfb_in_ts_re[in_ch][ts][i] = (float) ( cldfb_in_ts_re_fx[in_ch][ts][i] ) / (float) ( 1LL << 6 ); /*Resultant q is 6*/ + cldfb_in_ts_im[in_ch][ts][i] = (float) ( cldfb_in_ts_im_fx[in_ch][ts][i] ) / (float) ( 1LL << 6 ); /*Resultant q is 6*/ + } + } + } + } #endif IF ( NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_FOA) && NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_STEREO) && NE_16(hDecoderConfig->output_config , IVAS_AUDIO_CONFIG_MONO) ) { @@ -3224,7 +3241,11 @@ void ivas_spar_dec_upmixer_sf_fx( fixedToFloat_arrL( output_fx[ch], output[ch], Q11, out_len ); p_output[ch] = output[ch]; } +#ifdef MSAN_FIX + ivas_dirac_dec_render_sf_fx( st_ivas, p_output, output_fx, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im ); +#else ivas_dirac_dec_render_sf_fx( st_ivas, p_output, nchan_internal, cldfb_in_ts_re, cldfb_in_ts_im ); +#endif // MSAN_FIX FOR( Word16 ch = 0; ch < add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); ch++ ) { floatToFixed_arrL( output[ch], output_fx[ch], Q11, out_len ); @@ -3242,14 +3263,28 @@ void ivas_spar_dec_upmixer_sf_fx( } } #ifdef MSAN_FIX - FOR( out_ch = 0; out_ch < st_ivas->hOutSetup.nchan_out_woLFE; out_ch++ ) - { - FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) - { - floatToFixed_arrL( cldfb_in_ts_re[out_ch][ts], cldfb_in_ts_re_fx[out_ch][ts], Q6, num_cldfb_bands ); - floatToFixed_arrL( cldfb_in_ts_im[out_ch][ts], cldfb_in_ts_im_fx[out_ch][ts], Q6, num_cldfb_bands ); - } - } + IF(NE_16(hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA)) + { + FOR(out_ch = 0; out_ch < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; out_ch++) + { + FOR(ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++) + { + floatToFixed_arrL(cldfb_in_ts_re[out_ch][ts], cldfb_in_ts_re_fx[out_ch][ts], Q6, num_cldfb_bands); + floatToFixed_arrL(cldfb_in_ts_im[out_ch][ts], cldfb_in_ts_im_fx[out_ch][ts], Q6, num_cldfb_bands); + } + } + } + ELSE + { + FOR( out_ch = 0; out_ch < st_ivas->hOutSetup.nchan_out_woLFE; out_ch++ ) + { + FOR( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ ) + { + floatToFixed_arrL( cldfb_in_ts_re[out_ch][ts], cldfb_in_ts_re_fx[out_ch][ts], Q6, num_cldfb_bands ); + floatToFixed_arrL( cldfb_in_ts_im[out_ch][ts], cldfb_in_ts_im_fx[out_ch][ts], Q6, num_cldfb_bands ); + } + } + } #else FOR( out_ch = 0; out_ch < numch_out_dirac; out_ch++ ) { diff --git a/lib_dec/swb_bwe_dec_fx.c b/lib_dec/swb_bwe_dec_fx.c index 5773b3010..306643818 100644 --- a/lib_dec/swb_bwe_dec_fx.c +++ b/lib_dec/swb_bwe_dec_fx.c @@ -399,7 +399,11 @@ Word16 ivas_wb_bwe_dec_fx( output_frame ); *Qpost = sub( new_input_fx_exp, 15 ); /* DCT of the ACELP core synthesis */ +#ifdef MSAN_FIX + direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, L_FRAME16k, &new_input_fx_exp, st_fx->element_mode ); +#else direct_transform_fx( L_wtda_synth_fx, ysynth_32, 0, output_frame, &new_input_fx_exp, st_fx->element_mode ); +#endif } /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */ scl = sub( 16 + MAX_Q_NEW_INPUT, new_input_fx_exp ); @@ -408,11 +412,19 @@ Word16 ivas_wb_bwe_dec_fx( { /* Yes */ /* Calc Room to Upscale */ +#ifdef MSAN_FIX + Q_syn = Find_Max_Norm32( ysynth_32, L_FRAME16k ); +#else Q_syn = Find_Max_Norm32( ysynth_32, output_frame ); +#endif /* Stay within MAX_Q_NEW_INPUT */ scl = s_min( Q_syn, scl ); } +#ifdef MSAN_FIX + Copy_Scale_sig32_16( ysynth_32, ysynth_fx, L_FRAME16k, scl ); +#else Copy_Scale_sig32_16( ysynth_32, ysynth_fx, output_frame, scl ); +#endif Q_syn = add( sub( new_input_fx_exp, 16 ), scl ); IF( !st_fx->bfi ) { @@ -705,7 +717,7 @@ Word16 swb_bwe_gain_deq_fx( /* o : BWE class */ FOR( n_band = 0; n_band < SWB_TENV; n_band++ ) { index = (Word16)get_next_indice(st_fx, 4 ); - SWB_tenv[n_band] = shl(1, index); + SWB_tenv[n_band] = shl_sat(1, index); move16(); } diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index e2596eacb..ad97eeeae 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -3088,7 +3088,7 @@ static ivas_error ivas_rend_crendConvolver( Word16 subframe_length, idx_in; Word16 lfe_idx_in; Word16 offset, offset_in, offset_diffuse; - Word16 nchan_in, nchan_out; + Word16 nchan_in, nchan_out, scale; const Word32 *pIn; Word32 *pFreq_buf_re, *pFreq_buf_im; const Word32 *pFreq_filt_re, *pFreq_filt_im; @@ -3101,54 +3101,58 @@ static ivas_error ivas_rend_crendConvolver( hCrend = pCrend->hCrend; - if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) ) { return error; } - if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) ) { return error; } - subframe_length = (Word16) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; + subframe_length = (Word16) BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &scale ); + subframe_length = shr(subframe_length, 15 - scale); lfe_idx_in = -1; - if ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) + move16(); + IF ( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) ) { - if ( inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) + IF ( NE_32( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { lfe_idx_in = LFE_CHANNEL; + move16(); } - else + ELSE { assert( 0 && "Custom LS not supported in CRend" ); } } - offset = hCrend->delay_line_rw_index * subframe_length; /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */ + offset = imult1616( hCrend->delay_line_rw_index, subframe_length ); /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */ offset_diffuse = hCrend->diffuse_delay_line_rw_index * subframe_length; /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */ - if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + IF ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { set_val_Word32( &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse], 0, subframe_length ); set_val_Word32( &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse], 0, subframe_length ); } i = 0; - for ( idx_in = 0; idx_in < nchan_in; idx_in++ ) + move16(); + FOR ( idx_in = 0; idx_in < nchan_in; idx_in++ ) { pIn = &pcm_in[idx_in][i_ts * subframe_length]; - if ( idx_in != lfe_idx_in ) + IF ( idx_in != lfe_idx_in ) { - if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + IF ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset]; pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset]; - for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ ) + FOR ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ ) { pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_re[k] ); pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_im[k] ); @@ -3167,53 +3171,56 @@ static ivas_error ivas_rend_crendConvolver( } } - for ( j = 0; j < nchan_out; j++ ) + FOR ( j = 0; j < nchan_out; j++ ) { set_val_Word32( tmp_out_re, 0, subframe_length ); set_val_Word32( tmp_out_im, 0, subframe_length ); i = 0; - for ( idx_in = 0; idx_in < nchan_in; idx_in++ ) + move16(); + FOR ( idx_in = 0; idx_in < nchan_in; idx_in++ ) { - if ( idx_in != lfe_idx_in ) + IF ( NE_16( idx_in, lfe_idx_in ) ) { offset = 0; - for ( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ ) + move16(); + FOR ( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ ) { - offset_in = ( hCrend->delay_line_rw_index + pCrend->hHrtfCrend->max_num_iterations - pCrend->hHrtfCrend->num_iterations[i][j] + m + 1 ); + offset_in = add( add( hCrend->delay_line_rw_index, sub( pCrend->hHrtfCrend->max_num_iterations, pCrend->hHrtfCrend->num_iterations[i][j] ) ), add( m, 1 )); offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations ); - offset_in = offset_in * subframe_length; + offset_in = imult1616( offset_in, subframe_length ); pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in]; pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset_in]; pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; - for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ ) + FOR ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ ) { tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ) << 2, tmp_out_re[k] ); tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ) << 2, tmp_out_im[k] ); } - offset = offset + k; + offset = add( offset, k ); } - i++; + i = add( i, 1 ); } } offset = 0; - for ( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ ) + move16(); + FOR ( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ ) { - offset_diffuse = ( hCrend->diffuse_delay_line_rw_index + m + 1 ); + offset_diffuse = add( hCrend->diffuse_delay_line_rw_index, add( m, 1 ) ); offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0]; - offset_diffuse = offset_diffuse * subframe_length; + offset_diffuse = imult1616( offset_diffuse, subframe_length ); pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; - for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ ) + FOR ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ ) { tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), tmp_out_re[k] ); tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), tmp_out_im[k] ); } - offset = offset + k; + offset = add( offset, k ); } ivas_imdft_fx( tmp_out_re, tmp_out_im, pOut, subframe_length ); @@ -3222,18 +3229,18 @@ static ivas_error ivas_rend_crendConvolver( dbgwrite_txt( pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL ); #endif pFreq_buf_re = &pcm_out[j][i_ts * subframe_length]; - for ( k = 0; k < subframe_length; k++ ) + FOR ( k = 0; k < subframe_length; k++ ) { pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); hCrend->prev_out_buffer_fx[j][k] = pOut[k + subframe_length]; } } - hCrend->delay_line_rw_index++; + hCrend->delay_line_rw_index = add( hCrend->delay_line_rw_index, 1 ); hCrend->delay_line_rw_index = hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations ); - if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) + IF ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 ) { - hCrend->diffuse_delay_line_rw_index++; + hCrend->diffuse_delay_line_rw_index = add( hCrend->diffuse_delay_line_rw_index, 1); hCrend->diffuse_delay_line_rw_index = hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] ); } @@ -3443,7 +3450,7 @@ ivas_error ivas_rend_crendProcess( hCrend = pCrend->hCrend; combinedOrientationEnabled = 0; - if ( hCombinedOrientationData != NULL ) + IF ( hCombinedOrientationData != NULL ) { FOR ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { @@ -3468,15 +3475,19 @@ ivas_error ivas_rend_crendProcess( { case 48000: subframe_len = L_SUBFRAME_48k; + move16(); BREAK; case 32000: subframe_len = L_SUBFRAME_32k; + move16(); BREAK; case 16000: subframe_len = L_SUBFRAME_16k; + move16(); BREAK; case 8000: subframe_len = L_SUBFRAME_8k; + move16(); BREAK; default: BREAK; @@ -3491,12 +3502,12 @@ ivas_error ivas_rend_crendProcess( FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { /* Early Reflections */ - if ( hCrend->reflections != NULL ) + IF ( hCrend->reflections != NULL ) { test(); IF( EQ_16( hCrend->reflections->use_er, 1 ) && EQ_16(hCrend->reflections->is_ready , 1) ) { - IF ( ( error = ivas_er_process( hCrend->reflections, subframe_len, subframe_idx, output_fx, inConfig ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, subframe_idx, output_fx, inConfig ) ), IVAS_ERR_OK ) ) { return error; } @@ -3504,7 +3515,7 @@ ivas_error ivas_rend_crendProcess( } } - if ( hDecoderConfig && combinedOrientationEnabled ) + IF ( hDecoderConfig && combinedOrientationEnabled ) { /* Orientation tracking */ @@ -3717,7 +3728,7 @@ ivas_error ivas_rend_crendProcessSubframe( combinedOrientationEnabled = 0; IF ( hCombinedOrientationData != NULL ) { - if ( hCombinedOrientationData->enableCombinedOrientation[0] != 0 ) + IF ( NE_16( hCombinedOrientationData->enableCombinedOrientation[0], 0 ) ) { combinedOrientationEnabled = 1; } @@ -3726,12 +3737,12 @@ ivas_error ivas_rend_crendProcessSubframe( push_wmops( "ivas_rend_crendProcessSubframe" ); inConfigType = getAudioConfigType( inConfig ); - IF ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) ) { return error; } - IF ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) ) { return error; } @@ -3749,22 +3760,24 @@ ivas_error ivas_rend_crendProcessSubframe( /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ slots_to_render = min( hTcBuffer->num_slots - hTcBuffer->slots_rendered, n_samples_to_render / slot_size ); first_sf = hTcBuffer->subframes_rendered; + move16(); last_sf = first_sf; + move16(); - while ( slots_to_render > 0 ) + WHILE ( slots_to_render > 0 ) { - slots_to_render -= hTcBuffer->subframe_nbslots[last_sf]; - last_sf++; + slots_to_render = sub( slots_to_render, hTcBuffer->subframe_nbslots[last_sf] ); + last_sf = add(last_sf, 1); } FOR ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { - subframe_len = hTcBuffer->subframe_nbslots[subframe_idx] * hTcBuffer->n_samples_granularity; + subframe_len = imult1616( hTcBuffer->subframe_nbslots[subframe_idx], hTcBuffer->n_samples_granularity ); /* Early Reflections */ IF ( hCrend->reflections != NULL ) { IF ( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 ) { - IF ( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ), IVAS_ERR_OK ) ) { return error; } @@ -3778,25 +3791,22 @@ ivas_error ivas_rend_crendProcessSubframe( MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL SBA SPAR -> BINAURAL or BINAURAL_ROOM */ - IF ( inConfig == IVAS_AUDIO_CONFIG_FOA || inConfig == IVAS_AUDIO_CONFIG_HOA2 || inConfig == IVAS_AUDIO_CONFIG_HOA3 ) + IF ( EQ_32( inConfig, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) ) { rotateFrame_shd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, 0 ); } /* Rotation in SD for MC -> BINAURAL_ROOM */ ELSE IF ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup ) { - //Word16 nchan; - //nchan = hIntSetup->nchan_out_woLFE + hIntSetup->num_lfe; - rotateFrame_sd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, hEFAPdata, 0 ); } } - IF( ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) + IF( EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) ) { - if ( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local_fx, p_pcm_tmp_fx, output_Fs, 0 ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local_fx, p_pcm_tmp_fx, output_Fs, 0 ) ), IVAS_ERR_OK ) ) { return error; @@ -3804,7 +3814,7 @@ ivas_error ivas_rend_crendProcessSubframe( IF ( pCrend->hCrend->hReverb != NULL ) { - if ( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, tc_local_fx, p_pcm_tmp_fx, 0 ) ) != IVAS_ERR_OK ) + IF ( NE_32( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, tc_local_fx, p_pcm_tmp_fx, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -3818,7 +3828,7 @@ ivas_error ivas_rend_crendProcessSubframe( { p_pcm_tmp_fx[ch] += subframe_len; } - hTcBuffer->slots_rendered += hTcBuffer->subframe_nbslots[subframe_idx]; + hTcBuffer->slots_rendered = add( hTcBuffer->subframe_nbslots[subframe_idx], hTcBuffer->slots_rendered ); } ELSE { @@ -3830,9 +3840,9 @@ ivas_error ivas_rend_crendProcessSubframe( IF ( pCrend->hCrend->hReverb != NULL ) { *pCrend->p_io_qfactor -= 2; - for (int i = nchan_out; i < nchan_in; i++) + FOR (Word16 i = nchan_out; i < nchan_in; i++) { - for (int j = 0; j < n_samples_to_render; j++) + FOR (Word16 j = 0; j < n_samples_to_render; j++) { output[i][j] = (Word32)L_shr(output[i][j], 2); } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 39d7df4e5..3fb71bb4d 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -179,7 +179,7 @@ static void ivas_masa_ext_rend_parambin_internal( MASA_EXT_REND_HANDLE hMasaExtR * * Initialize parametric binaural renderer *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_dec_init_binaural_data( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ @@ -263,11 +263,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( if ( hDiracDecBin->hReverb != NULL && ( ( hDiracDecBin->hReverb->numBins != nBins ) || ( hDiracDecBin->hReverb->blockSize != CLDFB_SLOTS_PER_SUBFRAME ) ) ) { -#ifdef IVAS_FLOAT_FIXED - ivas_binaural_reverb_close_fx( &( hDiracDecBin->hReverb ) ); -#else ivas_binaural_reverb_close( &( hDiracDecBin->hReverb ) ); -#endif } if ( hDiracDecBin->hReverb == NULL ) @@ -353,8 +349,7 @@ ivas_error ivas_dirac_dec_init_binaural_data( } return IVAS_ERR_OK; } - -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_dirac_dec_init_binaural_data_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ @@ -562,11 +557,7 @@ void ivas_dirac_dec_close_binaural_data( IF( ( *hBinaural )->hReverb != NULL ) { -#ifdef IVAS_FLOAT_FIXED ivas_binaural_reverb_close_fx( &( ( *hBinaural )->hReverb ) ); -#else - ivas_binaural_reverb_close( &( ( *hBinaural )->hReverb ) ); -#endif } ivas_td_decorr_dec_close( &( ( *hBinaural )->hTdDecorr ) ); diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 1311f5ed9..421048ba9 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -61,7 +61,6 @@ #define DIRECTION_SMOOTHNESS_ALPHA 0.01f #define DIRECTION_SMOOTHNESS_ALPHA_Q31 (Word32)(0.01f * ONE_IN_Q31) - /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ @@ -76,7 +75,7 @@ static void computeTargetPSDs_diffuse_fx( const Word16 num_channels, const Word1 static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 start_band, const Word32 *diffuse_power_factor, const Word32 *reference_power, const Word16 *q_reference_power, const Word32 *diffuse_responses_square, Word32 *cy_auto_diff_smooth, Word16 *q_cy_auto_diff_smooth ); static void computeTargetPSDs_diffuse_with_onsets_fx( const Word16 num_channels, const Word16 num_freq_bands, const Word16 num_decorr_freq_bands, const Word16 *proto_frame_diff_index, const Word32 *diffuse_power_factor, const Word32 *reference_power, const Word16 *q_reference_power, const Word32 *diffuse_responses_square, const Word32 *onset_filter, Word32 *cy_auto_diff_smooth, Word16 *q_cy_auto_diff_smooth ); -#endif +#else static void computeTargetPSDs_direct( const int16_t num_channels, const int16_t num_freq_bands, const float *direct_power_factor, const float *reference_power, const float *direct_responses, const float *direct_responses_square, float *cy_auto_dir_smooth, float *cy_cross_dir_smooth ); @@ -87,7 +86,7 @@ static void computeTargetPSDs_diffuse( const int16_t num_channels, const int16_t static void computeTargetPSDs_diffuse_subframe( const int16_t num_channels, const int16_t num_freq_bands, const int16_t start_band, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, float *cy_auto_diff_smooth ); static void computeTargetPSDs_diffuse_with_onsets( const int16_t num_channels, const int16_t num_freq_bands, const int16_t num_decorr_freq_bands, const int16_t *proto_frame_diff_index, const float *diffuse_power_factor, const float *reference_power, const float *diffuse_responses_square, const float *onset_filter, float *cy_auto_diff_smooth ); - +#endif #ifndef IVAS_FLOAT_FIXED static void computeAlphaSynthesis( float *alpha_synthesis, const int16_t averaging_length_ms, const float maxAlpha, int16_t *numAlphas, const int16_t slot_size, const int16_t num_freq_bands, const float *frequency_axis, const int32_t output_Fs ); #endif @@ -101,12 +100,13 @@ static void spreadCoherencePanningVbap_fx( const int16_t azimuth, const int16_t static void normalizePanningGains_fx( Word32 *direct_response_fx, Word16 *q_direct_res, const Word16 num_channels_dir ); #endif +#ifndef IVAS_FLOAT_FIXED static void spreadCoherencePanningHoa( const int16_t azimuth, const int16_t elevation, const float spreadCoh, float *direct_response, const int16_t num_channels_dir, const int16_t ambisonics_order ); static void spreadCoherencePanningVbap( const int16_t azimuth, const int16_t elevation, const float spreadCoh, float *direct_response, const int16_t num_channels_dir, const VBAP_HANDLE hVBAPdata ); static void normalizePanningGains( float *direct_response, const int16_t num_channels_dir ); - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_output_synthesis_open() @@ -1284,7 +1284,7 @@ void ivas_dirac_dec_output_synthesis_close_fx( * * *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_output_synthesis_process_slot( const float *reference_power, /* i : Estimated power */ const float *onset, /* i : onset filter */ @@ -1517,8 +1517,7 @@ void ivas_dirac_dec_output_synthesis_process_slot( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_dirac_dec_output_synthesis_process_slot_fx( const Word32 *reference_power, /* i : Estimated power */ const Word16 q_reference_power, /* i : Estimated power */ @@ -2627,7 +2626,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( return; } -#endif +#else /*------------------------------------------------------------------------- @@ -3007,11 +3006,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( if ( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { float *p_real, *p_imag; -#ifndef IVAS_FLOAT_FIXED const float *hoa_decoder; -#else - const Word32 *hoa_decoder; -#endif hoa_decoder = hDirACRend->hoa_decoder; @@ -3024,22 +3019,12 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( { p_out_real = output_real + l * num_channels_dir; p_out_imag = output_imag + l * num_channels_dir; -#ifndef IVAS_FLOAT_FIXED p_real[l] = *( p_out_real++ ) * hoa_decoder[0]; p_imag[l] = *( p_out_imag++ ) * hoa_decoder[0]; -#else - p_real[l] = *( p_out_real++ ) * ( (float) hoa_decoder[0] ) / ONE_IN_Q29; - p_imag[l] = *( p_out_imag++ ) * ( (float) hoa_decoder[0] ) / ONE_IN_Q29; -#endif for ( i = 1; i < num_channels_dir; i++ ) { -#ifndef IVAS_FLOAT_FIXED p_real[l] += *( p_out_real++ ) * hoa_decoder[i]; p_imag[l] += *( p_out_imag++ ) * hoa_decoder[i]; -#else - p_real[l] += *( p_out_real++ ) * ( (float) hoa_decoder[i] ) / ONE_IN_Q29; - p_imag[l] += *( p_out_imag++ ) * ( (float) hoa_decoder[i] ) / ONE_IN_Q29; -#endif } } hoa_decoder += 16; @@ -3088,7 +3073,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_gain_shd( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -3715,7 +3700,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( return; } -#endif +#else /*------------------------------------------------------------------------- @@ -4076,7 +4061,7 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -4352,7 +4337,7 @@ static void ivas_dirac_dec_get_response_split_order_fx( return; } -#endif +#else /*------------------------------------------------------------------------- * ivas_dirac_dec_get_response_split_order() * @@ -4514,7 +4499,7 @@ static void ivas_dirac_dec_get_response_split_order( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_compute_directional_responses() @@ -5070,7 +5055,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( ismDirect_fx = L_add( ismDirect_fx, hMasaIsm->energy_ratio_ism_fx[dir][md_idx][k] ); } - totalDirect_fx = L_add( masaDirect_fx, ismDirect_fx ); + totalDirect_fx = L_add_sat( masaDirect_fx, ismDirect_fx ); // saturating as 1.0 (Q30) + 1.0 (Q30) is observed Word16 var_a = 0, var_b = 0; move16(); var_a = BASOP_Util_Divide3232_Scale( masaDirect_fx, totalDirect_fx, &exp_1 ); @@ -5205,7 +5190,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( return; } -#endif +#else void ivas_dirac_dec_compute_directional_responses( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common spatial renderer data handle */ @@ -5554,7 +5539,7 @@ void ivas_dirac_dec_compute_directional_responses( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_compute_gain_factors() * @@ -6039,7 +6024,7 @@ static void computeTargetPSDs_direct_fx( return; } -#endif +#else static void computeTargetPSDs_direct( const int16_t num_channels, @@ -6074,7 +6059,7 @@ static void computeTargetPSDs_direct( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_direct_subframe_fx( const Word16 num_channels, @@ -6113,7 +6098,7 @@ static void computeTargetPSDs_direct_subframe_fx( return; } -#endif +#else static void computeTargetPSDs_direct_subframe( @@ -6145,7 +6130,7 @@ static void computeTargetPSDs_direct_subframe( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_diffuse_fx( @@ -6187,7 +6172,7 @@ static void computeTargetPSDs_diffuse_fx( return; } -#endif +#else static void computeTargetPSDs_diffuse( const int16_t num_channels, @@ -6217,7 +6202,7 @@ static void computeTargetPSDs_diffuse( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_diffuse_subframe_fx( const Word16 num_channels, @@ -6249,7 +6234,7 @@ static void computeTargetPSDs_diffuse_subframe_fx( return; } -#endif +#else static void computeTargetPSDs_diffuse_subframe( @@ -6277,7 +6262,7 @@ static void computeTargetPSDs_diffuse_subframe( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void computeTargetPSDs_diffuse_with_onsets_fx( @@ -6350,7 +6335,7 @@ static void computeTargetPSDs_diffuse_with_onsets_fx( return; } -#endif +#else static void computeTargetPSDs_diffuse_with_onsets( @@ -6392,7 +6377,7 @@ static void computeTargetPSDs_diffuse_with_onsets( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void computeAlphaSynthesis_fx(Word16 *alpha_synthesis_fx, const Word16 averaging_length_ms, const Word16 maxAlpha_fx, Word16 *numAlphas, const Word16 slot_size, const Word16 num_freq_bands, Word16 *frequency_axis_fx, const Word32 output_Fs) { @@ -6571,7 +6556,7 @@ static void spreadCoherencePanningHoa_fx( return; } -#endif +#else static void spreadCoherencePanningHoa( const int16_t azimuth, @@ -6614,7 +6599,7 @@ static void spreadCoherencePanningHoa( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void spreadCoherencePanningVbap_fx( const Word16 azimuth, @@ -6694,7 +6679,7 @@ static void spreadCoherencePanningVbap_fx( return; } -#endif +#else static void spreadCoherencePanningVbap( const int16_t azimuth, @@ -6707,12 +6692,6 @@ static void spreadCoherencePanningVbap( int16_t i; float direct_response_left[MAX_OUTPUT_CHANNELS]; float direct_response_right[MAX_OUTPUT_CHANNELS]; -#ifdef IVAS_FLOAT_FIXED - Word32 direct_response_left_fx[MAX_OUTPUT_CHANNELS]; - Word32 direct_response_right_fx[MAX_OUTPUT_CHANNELS]; - set32_fx(direct_response_left_fx, 0, MAX_OUTPUT_CHANNELS); - set32_fx(direct_response_right_fx, 0, MAX_OUTPUT_CHANNELS); -#endif float gainCenter; float gainSide; @@ -6723,35 +6702,12 @@ static void spreadCoherencePanningVbap( return; } -#ifdef IVAS_FLOAT_FIXED - Word32 direct_response_fx[MAX_OUTPUT_CHANNELS]; - set32_fx( direct_response_fx, 0, MAX_OUTPUT_CHANNELS ); - vbap_determine_gains_fx( hVBAPdata, direct_response_fx, azimuth, elevation, 0 ); - FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) - { - direct_response[i] = fix_to_float( direct_response_fx[i], Q29 ); - } -#else vbap_determine_gains( hVBAPdata, direct_response, azimuth, elevation, 0 ); -#endif if ( spreadCoh > 0.f ) { -#ifdef IVAS_FLOAT_FIXED - vbap_determine_gains_fx(hVBAPdata, direct_response_left_fx, azimuth + 30, elevation, 0); - FOR(i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - direct_response_left[i] = fix_to_float(direct_response_left_fx[i], Q29); - } - vbap_determine_gains_fx(hVBAPdata, direct_response_right_fx, azimuth - 30, elevation, 0); - FOR(i = 0; i < MAX_OUTPUT_CHANNELS; i++) - { - direct_response_right[i] = fix_to_float(direct_response_right_fx[i], Q29); - } -#else vbap_determine_gains( hVBAPdata, direct_response_left, azimuth + 30, elevation, 0 ); vbap_determine_gains( hVBAPdata, direct_response_right, azimuth - 30, elevation, 0 ); -#endif if ( spreadCoh < 0.5f ) { @@ -6772,7 +6728,7 @@ static void spreadCoherencePanningVbap( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static void normalizePanningGains_fx( Word32 *direct_response_fx, @@ -6811,7 +6767,7 @@ static void normalizePanningGains_fx( return; } -#endif +#else static void normalizePanningGains( float *direct_response, @@ -6830,3 +6786,4 @@ static void normalizePanningGains( return; } +#endif \ No newline at end of file diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 94cd7e02a..50a0bbcc5 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -676,21 +676,13 @@ ivas_error ivas_spat_hSpatParamRendCom_config( hSpatParamRendCom->render_to_md_map[map_idx] = hSpatParamRendCom->dirac_read_idx + map_idx / num_slots_in_subfr; } } -#ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 1 ) ) != IVAS_ERR_OK ) -#endif { return error; } if ( ivas_format == MASA_FORMAT || ivas_format == MASA_ISM_FORMAT || ( ( ivas_format == SBA_FORMAT || ivas_format == SBA_ISM_FORMAT ) && hodirac_flag ) ) { -#ifdef IVAS_FLOAT_FIXED - IF ( ( error = ivas_dirac_allocate_parameters_fx( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) -#else if ( ( error = ivas_dirac_allocate_parameters( hSpatParamRendCom, 2 ) ) != IVAS_ERR_OK ) -#endif { return error; } @@ -2094,7 +2086,7 @@ void compute_hoa_encoder_mtx_fx( return; } -#endif +#else void compute_hoa_encoder_mtx( const float *azimuth, @@ -2114,13 +2106,13 @@ void compute_hoa_encoder_mtx( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_get_frequency_axis() * * DirAC decoding initialization *------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void ivas_dirac_dec_get_frequency_axis( float *frequency_axis, const int32_t output_Fs, @@ -2138,8 +2130,7 @@ void ivas_dirac_dec_get_frequency_axis( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void ivas_dirac_dec_get_frequency_axis_fx( Word16 *frequency_axis, /* Q0 */ const Word32 output_Fs, @@ -2165,7 +2156,7 @@ void ivas_dirac_dec_get_frequency_axis_fx( * * *-------------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED void initDiffuseResponses( float *diffuse_response_function, const int16_t num_channels, @@ -2271,8 +2262,7 @@ void initDiffuseResponses( return; } - -#ifdef IVAS_FLOAT_FIXED +#else void initDiffuseResponses_fx( Word16 *diffuse_response_function_fx, const Word16 num_channels, @@ -2657,7 +2647,7 @@ void protoSignalComputation_shd_fx( return; } -#endif +#else /*------------------------------------------------------------------------- * protoSignalComputation_shd() * @@ -2818,7 +2808,7 @@ void protoSignalComputation_shd( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -2921,7 +2911,7 @@ void protoSignalComputation1_fx( return; } -#endif +#else /*------------------------------------------------------------------------- * protoSignalComputation1() * @@ -2960,7 +2950,7 @@ void protoSignalComputation1( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * protoSignalComputation2_fx() @@ -3723,7 +3713,7 @@ void protoSignalComputation2_fx( return; } -#endif +#else /*------------------------------------------------------------------------- * protoSignalComputation2() * @@ -4049,7 +4039,7 @@ void protoSignalComputation2( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * protoSignalComputation4_fx() @@ -4222,11 +4212,7 @@ void protoSignalComputation4( const int16_t slot_index, const int16_t num_outputs_diff, const int16_t num_freq_bands, -#ifndef IVAS_FLOAT_FIXED const float *mtx_hoa_decoder, -#else - const Word32 *mtx_hoa_decoder, -#endif const int16_t nchan_transport, const int16_t *sba_map_tc_ind ) { @@ -4254,13 +4240,8 @@ void protoSignalComputation4( proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] = 0.f; for ( n = 0; n < nchan_transport; n++ ) { -#ifndef IVAS_FLOAT_FIXED proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]]; -#else - proto_frame_f[2 * l * num_freq_bands + 2 * k] += RealBuffer[n][0][k] * ( (float) mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]] ) / ONE_IN_Q29; - proto_frame_f[2 * l * num_freq_bands + 2 * k + 1] += ImagBuffer[n][0][k] * ( (float) mtx_hoa_decoder[l * 16 + sba_map_tc_ind[n]] ) / ONE_IN_Q29; -#endif } } } @@ -4412,7 +4393,7 @@ void ivas_dirac_dec_compute_diffuse_proto_fx( return; } -#endif +#else void ivas_dirac_dec_compute_diffuse_proto( DIRAC_REND_HANDLE hDirACRend, const int16_t num_freq_bands, @@ -4488,7 +4469,7 @@ void ivas_dirac_dec_compute_diffuse_proto( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -4714,7 +4695,7 @@ void ivas_masa_init_stereotype_detection_fx( return; } -#endif +#else void ivas_masa_init_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ) { @@ -4750,7 +4731,7 @@ void ivas_masa_init_stereotype_detection( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- * ivas_masa_stereotype_detection_fx() @@ -4889,7 +4870,7 @@ void ivas_masa_stereotype_detection_fx( return; } -#endif +#else /*------------------------------------------------------------------------- * ivas_masa_stereotype_detection() * @@ -4987,7 +4968,7 @@ void ivas_masa_stereotype_detection( return; } - +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -5414,7 +5395,7 @@ void rotateAziEle_DirAC_fx( return; } -#endif +#else /*------------------------------------------------------------------------- * rotateAziEle_DirAC() * @@ -5458,7 +5439,7 @@ void rotateAziEle_DirAC( return; } - +#endif /* A reduced rewrite of the corresponding decoder side function */ #ifndef IVAS_FLOAT_FIXED static void ivas_masa_ext_dirac_render_sf( diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index be1678638..c712da4b5 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -191,6 +191,7 @@ ivas_error efap_init_data_fx( error = IVAS_ERR_OK; /* Basic init checks */ + test(); IF( !speaker_node_azi_deg || !speaker_node_ele_deg ) { hEFAPdata = NULL; @@ -233,10 +234,10 @@ ivas_error efap_init_data_fx( * Initialize values *-----------------------------------------------------------------*/ - efap->numSpk = num_speaker_nodes; + efap->numSpk = num_speaker_nodes; move16(); /* The number of vertex is first set to the number of LS but will evolve further */ - efap->vtxData.numVtx = num_speaker_nodes; + efap->vtxData.numVtx = num_speaker_nodes; move16(); /* Loudspeaker configuration */ mvl2l( speaker_node_azi_deg, efap->aziSpk, num_speaker_nodes ); @@ -377,8 +378,8 @@ void efap_determine_gains_fx( Word32 normBuffer; /* Resetting bufferShort and bufferLong */ - set_l( hEFAPdata->bufferShort_fx, 0, hEFAPdata->numSpk ); - set_l( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); + set32_fx( hEFAPdata->bufferShort_fx, 0, hEFAPdata->numSpk ); + set32_fx( hEFAPdata->bufferLong_fx, 0, hEFAPdata->vtxData.numVtx ); /* Wrap angles to correct range */ panning_wrap_angles_fixed( azi_deg, ele_deg, &azi_wrap_int, &ele_wrap_int ); @@ -388,10 +389,10 @@ void efap_determine_gains_fx( IF( EQ_16( efap_mode, EFAP_MODE_EFAP ) ) { - normBuffer = 0; + normBuffer = 0; move16(); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = 0; + hEFAPdata->bufferShort_fx[j] = 0; move16(); /* Multiplying by the downmixMatrix */ FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) { @@ -399,7 +400,7 @@ void efap_determine_gains_fx( } normBuffer = L_add_sat( normBuffer, Mpy_32_32( hEFAPdata->bufferShort_fx[j], hEFAPdata->bufferShort_fx[j] ) ); // Q29 } - Word16 exp = 2; + Word16 exp = 2; move16(); normBuffer = ISqrt32( normBuffer, &exp ); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) @@ -410,10 +411,10 @@ void efap_determine_gains_fx( } ELSE { - normBuffer = 0; + normBuffer = 0; move16(); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - hEFAPdata->bufferShort_fx[j] = 0; + hEFAPdata->bufferShort_fx[j] = 0; move16(); /* Multiplying by the downmixMatrix */ FOR( i = 0; i < hEFAPdata->vtxData.numVtx; ++i ) { @@ -421,12 +422,12 @@ void efap_determine_gains_fx( } normBuffer = L_add_sat( normBuffer, L_shr( hEFAPdata->bufferShort_fx[j], Q1 ) ); // Q29 } - Word16 exp = 2; + Word16 exp = 2; move16(); normBuffer = Inv16( (Word16) L_shr( normBuffer, Q16 ), &exp ); FOR( j = 0; j < hEFAPdata->numSpk; ++j ) { - Word16 exp_temp = exp + 1; + Word16 exp_temp = add(exp, 1); hEFAPdata->bufferShort_fx[j] = Sqrt32( Mpy_32_16_1( hEFAPdata->bufferShort_fx[j], (Word16) normBuffer ), &exp_temp ); hEFAPdata->bufferShort_fx[j] = L_shl( hEFAPdata->bufferShort_fx[j], sub( exp_temp, 1 ) ); // Q30 } @@ -528,6 +529,7 @@ void efap_free_data( Word16 i, dim1; void **p_dmTranspose; + test(); IF( hEFAPdata == NULL || *hEFAPdata == NULL ) { return; @@ -636,10 +638,10 @@ static ivas_error poly_init_fx( const Word16 efip_flag /* i : flag to indicate whether initialization is for EFIP (used for ALLRAD) */ ) { - int16_t n, m, j; - int16_t finalLength, lengthTri2PolyPS; - int16_t lengthTri2PolySorted[EFAP_MAX_POLY_SET]; - int16_t sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM]; + Word16 n, m, j; + Word16 finalLength, lengthTri2PolyPS; + Word16 lengthTri2PolySorted[EFAP_MAX_POLY_SET]; + Word16 sortedChan[EFAP_MAX_POLY_SET][EFAP_MAX_CHAN_NUM]; Word32 tmpMax, tmpMin; ivas_error error; @@ -650,7 +652,7 @@ static ivas_error poly_init_fx( FOR( n = 0; n < EFAP_MAX_POLY_SET; n++ ) { - set_s( sortedChan[n], 0, EFAP_MAX_CHAN_NUM ); + set16_fx( sortedChan[n], 0, EFAP_MAX_CHAN_NUM ); } /* Computing the different ghost vertex, the downmix matrix and the triangle array */ @@ -665,7 +667,7 @@ static ivas_error poly_init_fx( IF( GT_32( efap->vtxData.vertexArray[n].ele, L_sub( Q22_90_DEG, 4 ) ) || LT_32( efap->vtxData.vertexArray[n].ele, L_sub( 4, Q22_90_DEG ) ) ) { - efap->vtxData.vertexArray[n].isNaN = 1; + efap->vtxData.vertexArray[n].isNaN = 1; move16(); } } @@ -673,22 +675,22 @@ static ivas_error poly_init_fx( tri_to_poly_fx( efap->vtxData.vertexArray, efap->polyData.triArray, efap->vtxData.numVtx, efap->polyData.numTri, sortedChan, &lengthTri2PolyPS, lengthTri2PolySorted ); /* Completing the polyData Structure */ - finalLength = -1; + finalLength = -1; move16(); FOR( n = 0; n < lengthTri2PolyPS; ++n ) { - m = finalLength + 1; + m = add(finalLength, 1); /* Complete the fields of the polygon */ FOR( j = 0; j < lengthTri2PolySorted[n]; ++j ) { - efap->polyData.polysetArray[m].chan[j] = sortedChan[n][j]; - efap->polyData.polysetArray[m].polyAzi[j] = efap->vtxData.vertexArray[sortedChan[n][j]].azi; - efap->polyData.polysetArray[m].polyEle[j] = efap->vtxData.vertexArray[sortedChan[n][j]].ele; - efap->polyData.polysetArray[m].isNaN[j] = efap->vtxData.vertexArray[sortedChan[n][j]].isNaN; + efap->polyData.polysetArray[m].chan[j] = sortedChan[n][j]; move16(); + efap->polyData.polysetArray[m].polyAzi[j] = efap->vtxData.vertexArray[sortedChan[n][j]].azi; move32(); + efap->polyData.polysetArray[m].polyEle[j] = efap->vtxData.vertexArray[sortedChan[n][j]].ele; move32(); + efap->polyData.polysetArray[m].isNaN[j] = efap->vtxData.vertexArray[sortedChan[n][j]].isNaN; move16(); } - efap->polyData.polysetArray[m].numChan = lengthTri2PolySorted[n]; + efap->polyData.polysetArray[m].numChan = lengthTri2PolySorted[n]; move16(); /* In case tmpMax - tmpMin > 180, wrap polygon azimuth */ maximum_l( efap->polyData.polysetArray[m].polyAzi, lengthTri2PolySorted[n], &tmpMax ); @@ -722,7 +724,7 @@ static ivas_error poly_init_fx( finalLength = add( finalLength, 1 ); /* Updating the number of polygons */ - efap->polyData.numPoly = finalLength; + efap->polyData.numPoly = finalLength; move16(); return error; @@ -1132,7 +1134,7 @@ static void initial_polyeder_fx( } /* 2. attempt to create a triangle with nonzero area */ - tmp = 0; + tmp = 0; move16(); v_sub_fixed( vtxData->vertexArray[tetrahedron[1]].pos, vtxData->vertexArray[tetrahedron[0]].pos, tmp1, 3, 1 ); WHILE( LT_16( tetrahedron[2], numVtx ) ) { @@ -1403,19 +1405,19 @@ static void add_ghost_speakers_fx( vtxDmxType = EFAP_DMX_INTENSITY; numVertex = *numVtx; - maxAngle = 13421773; //(1.f / 160.0f) in Q31 + maxAngle = 13421773; move32();//(1.f / 160.0f) in Q31 /* Extracting Azi and Ele for computation purposes */ FOR( i = 0; i < numVertex; ++i ) { - ele[i] = vertexArray[i].ele; + ele[i] = vertexArray[i].ele; move32(); } /* ADD VOG IF NECESSERAY (i.e. if the elevation of the highest LS is < 90 deg) */ - a = 0; + a = 0; move16(); maximum_l( ele, numVertex, &tmpEle ); - lengthVertGhst = 0; + lengthVertGhst = 0; move16(); IF( LT_32( tmpEle, Q22_90_DEG ) ) { IF( efip_flag ) @@ -1457,7 +1459,7 @@ static void add_ghost_speakers_fx( } /* LIST ALL SURROUNDING loudspeakers */ - k = 0; + k = 0; move16(); FOR( i = 0; i < numVertex; ++i ) { @@ -1468,21 +1470,21 @@ static void add_ghost_speakers_fx( } } - lengthHorGhst = 0; + lengthHorGhst = 0; move16(); IF( EQ_16( k, 0 ) ) /* no speakers found: add a triangle of ghost speakers */ { - add_vertex_fx( vertexArray, 0, 0, numVertex + a, EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_120_DEG, 0, numVertex + a + 1, EFAP_DMX_INTENSITY ); - add_vertex_fx( vertexArray, Q22_240_DEG, 0, numVertex + a + 2, EFAP_DMX_INTENSITY ); - a += 3; - lengthHorGhst += 3; + add_vertex_fx( vertexArray, 0, 0, add(numVertex, a), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_120_DEG, 0, add(add(numVertex, a), 1), EFAP_DMX_INTENSITY ); + add_vertex_fx( vertexArray, Q22_240_DEG, 0, add(add(numVertex, a), 2), EFAP_DMX_INTENSITY ); + a = add(a, 3); + lengthHorGhst = add(lengthHorGhst, 3); } ELSE IF( EQ_16( k, 1 ) ) /* only one speaker found: add two ghost speakers to complete a triangle */ { add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_120_DEG ), 0, numVertex + a, EFAP_DMX_INTENSITY ); add_vertex_fx( vertexArray, L_add( tmpAzi[0], Q22_240_DEG ), 0, numVertex + a + 1, EFAP_DMX_INTENSITY ); - a += 2; - lengthHorGhst += 2; + a = add(a, 2); + lengthHorGhst = add(lengthHorGhst, 2); } ELSE /* fill gaps greater than maxAngle */ { @@ -1704,7 +1706,7 @@ static void add_vertex_to_convex_hull_fx( Word16 surface[3]; Word32 numHullVtx; Word32 centroid[3]; - const Word32 threshold = -268; // -1e-6f in Q28 + const Word32 threshold = -268; move32();// -1e-6f in Q28 Word32 tmpDist; EFAP_LS_TRIANGLE triArrayNew[EFAP_MAX_POLY_SET]; @@ -1715,8 +1717,8 @@ static void add_vertex_to_convex_hull_fx( } /* Compute the centroid of the current convex hull */ - numHullVtx = 0; - set_l( centroid, 0, 3 ); + numHullVtx = 0; move32(); + set32_fx( centroid, 0, 3 ); FOR( i = 0; i < vtxData->numVtx; i++ ) { IF( vtxInHull[i] ) @@ -1738,15 +1740,15 @@ static void add_vertex_to_convex_hull_fx( centroid[2] = L_shl( centroid[2], 4 ); /* Processing */ - k = 0; - l = 0; + k = 0; move16(); + l = 0; move16(); FOR( i = 0; i < *szTri; ++i ) { tmpDist = vertex_distance_fx( vtxData->vertexArray, triArray[i], vtxIdx ); // Q28 IF( GT_32( tmpDist, threshold ) ) { - visible[k] = i; + visible[k] = i; move16(); ++k; } ELSE @@ -1760,9 +1762,9 @@ static void add_vertex_to_convex_hull_fx( FOR( i = 0; i < numEdges[0]; i += 2 ) { - surface[0] = edges[i]; - surface[1] = edges[i + 1]; - surface[2] = vtxIdx; + surface[0] = edges[i]; move16(); + surface[1] = edges[i + 1]; move16(); + surface[2] = vtxIdx; move16(); flip_plane_fx( vtxData->vertexArray, surface, centroid ); @@ -1778,7 +1780,7 @@ static void add_vertex_to_convex_hull_fx( *szTri = l; /* Flag the vertex as added to the hull */ - vtxInHull[vtxIdx] = 1; + vtxInHull[vtxIdx] = 1; move16(); return; } #endif @@ -1808,29 +1810,29 @@ static void visible_edges_fx( /* Set counter and counterTranspose to 0 */ FOR( i = 0; i < EFAP_MAX_SIZE_TMP_BUFF; i++ ) { - set_s( counter[i], 0, EFAP_MAX_SIZE_TMP_BUFF ); - set_s( counterTranspose[i], 0, EFAP_MAX_SIZE_TMP_BUFF ); + set16_fx( counter[i], 0, EFAP_MAX_SIZE_TMP_BUFF ); + set16_fx( counterTranspose[i], 0, EFAP_MAX_SIZE_TMP_BUFF ); } /* Finding the max vertex */ FOR( i = 0; i < numSurface; ++i ) { - tmpMax[i] = triArray[visible[i]].LS[0]; + tmpMax[i] = triArray[visible[i]].LS[0]; move16(); FOR( j = 1; j < 3; ++j ) { IF( tmpMax[i] < triArray[visible[i]].LS[j] ) { - tmpMax[i] = triArray[visible[i]].LS[j]; + tmpMax[i] = triArray[visible[i]].LS[j]; move16(); } } } maxVertex = tmpMax[maximum_s( tmpMax, numSurface, NULL )]; FOR( i = 0; i < numSurface; ++i ) { - tmpSurface[0] = triArray[visible[i]].LS[0]; - tmpSurface[1] = triArray[visible[i]].LS[1]; - tmpSurface[2] = triArray[visible[i]].LS[2]; - tmpSurface[3] = triArray[visible[i]].LS[0]; + tmpSurface[0] = triArray[visible[i]].LS[0]; move16(); + tmpSurface[1] = triArray[visible[i]].LS[1]; move16(); + tmpSurface[2] = triArray[visible[i]].LS[2]; move16(); + tmpSurface[3] = triArray[visible[i]].LS[0]; move16(); FOR( j = 0; j < 3; ++j ) { @@ -1858,15 +1860,15 @@ static void visible_edges_fx( { IF( counter[a][b] == 1 ) { - edges[k] = a; - edges[k + 1] = b; - k += 2; + edges[k] = a; move16(); + edges[k + 1] = b; move16(); + k = add(k, 2); } } } /* Outputs */ - *numEdges = k; + *numEdges = k; move16(); return; } @@ -2199,10 +2201,10 @@ static void remap_ghosts_fx( Word32 tmpMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; Word32 tmpNewMat[EFAP_MAX_SIZE_TMP_BUFF][EFAP_MAX_SIZE_TMP_BUFF]; Word32 tmpDist; - const Word32 thresh = 214748; // 1e-4f in Q31 + const Word32 thresh = 214748; move32();// 1e-4f in Q31 - set_l( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); - set_l( tmpVec2, 0, EFAP_MAX_SIZE_TMP_BUFF ); + set32_fx( tmpVec, 0, EFAP_MAX_SIZE_TMP_BUFF ); + set32_fx( tmpVec2, 0, EFAP_MAX_SIZE_TMP_BUFF ); /* Finding unused ghosts (i.e. ghost speakers that aren't used for triangulation */ FOR( g = numVtx - 1; g > numSpk - 1; --g ) @@ -2235,8 +2237,8 @@ static void remap_ghosts_fx( /* Initializing tmpMat as the identity matrix */ FOR( i = 0; i < numTot; ++i ) { - set_l( tmpMat[i], 0, numTot ); - set_l( tmpNewMat[i], 0, numTot ); + set32_fx( tmpMat[i], 0, numTot ); + set32_fx( tmpNewMat[i], 0, numTot ); tmpMat[i][i] = 0x7fffffff; tmpNewMat[i][i] = 0x7fffffff; @@ -2299,7 +2301,7 @@ static void remap_ghosts_fx( } ELSE { - Word16 exp = 0; + Word16 exp = 0; move16(); Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); tmp_sqrt = L_shl( tmp_sqrt, exp ); downmixMatrixTranspose[j][i] = tmp_sqrt; @@ -2324,7 +2326,7 @@ static void remap_ghosts_fx( } ELSE { - Word16 exp = 0; + Word16 exp = 0; move16(); Word32 tmp_sqrt = Sqrt32( tmpNewMat[j][i], &exp ); tmp_sqrt = L_shl( tmp_sqrt, exp ); downmixMatrixTranspose[j][i] = tmp_sqrt; @@ -2335,7 +2337,7 @@ static void remap_ghosts_fx( } /* Output */ - *numVertex = numTot; + *numVertex = numTot; move16(); return; } @@ -2507,7 +2509,7 @@ static void efap_panning_fx( /* Computing the norm of the tmp buffer */ normTmpBuff = dotp_fixed( tmpBuff, tmpBuff, numChan ); - Word16 exp = 0; + Word16 exp = 0; move16(); normTmpBuff = ISqrt32( normTmpBuff, &exp ); /* Updating the buffer structure */ @@ -2697,9 +2699,9 @@ static Word32 get_tri_gain_fx( tmpDot1 = dotp_fixed( tmpN, tmpSub1, 2 ); // Q13 - Word16 exp = Q13; + Word16 exp = Q13; move16(); Word32 inv_tmpDot2 = L_shl( tmpDot1, norm_l( tmpDot1 ) ); - exp = exp - norm_l( tmpDot1 ); + exp = sub(exp, norm_l( tmpDot1 )); Word16 inv_tmpDot1 = Inv16( (Word16) L_shr( inv_tmpDot2, Q16 ), &exp ); v_multc_fixed( tmpN, L_shl( inv_tmpDot1, Q16 + exp ), N, 2 ); @@ -2709,7 +2711,7 @@ static Word32 get_tri_gain_fx( /* Set gains <= -60dB to 0 to avoid problems in SVD */ IF( LT_32( L_abs( gain ), 1 ) ) { - gain = 0; + gain = 0; move32(); } return gain; // Q18 } @@ -2806,14 +2808,14 @@ static void add_vertex_fx( /* IdxEleTmp */ tmp = L_abs( vtxArray[pos].ele ); - idxEleTmp = tmp; + idxEleTmp = tmp; move16(); idxEleTmp = L_sub( Q22_90_DEG, idxEleTmp ); /* Final Idx */ vtxArray[pos].idx = add( (Word16) idxAziTmp, i_mult( 181, (Word16) L_shr( idxEleTmp, Q22 ) ) ); /* Setting the nan flag to 0 */ - vtxArray[pos].isNaN = 0; + vtxArray[pos].isNaN = 0; move16(); /* Set the default downmix type */ vtxArray[pos].dmxType = dmxType; @@ -3070,7 +3072,7 @@ static Word32 point_plane_distance_fx( // returns output in Q28 /* Dot Product */ tmpNorm = dotp_fixed( resultCross, resultCross, 3 ); // Q27 - Word16 exp = 4; + Word16 exp = 4; move16(); tmpNorm = ISqrt32( tmpNorm, &exp ); // Q29 v_sub_fixed( X, P1, tmpDot1, 3, 1 ); // Q30 v_multc_fixed( resultCross, tmpNorm, tmpDot2, 3 ); // Q29 - exp @@ -3255,7 +3257,7 @@ static Word16 get_neighbours_fx( mvs2s( triArray[i].LS, tmpTriArray[i].LS, 3 ); } - k = 0; + k = 0; move16(); WHILE( 1 ) { IF( EQ_16(find_int_in_tri_fx( tmpTriArray, vtxIdx, numTri, tmpPos ), 0 ) ) @@ -3282,7 +3284,7 @@ static Word16 get_neighbours_fx( /* Creating the output vector, by eliminating redundancies and also deleting the indice == vtxIdx*/ neighbours[0] = tmpNeighbours[0]; - j = 1; + j = 1; move16(); FOR( i = 1; i < k; ++i ) { @@ -3444,12 +3446,12 @@ static void tri_to_poly_fx( Word32 dist; - lenPolySet = 0; + lenPolySet = 0; move16(); /* Sorting the polygons */ FOR( i = 0; i < numTri; ++i ) { /* search for coplanar vertices and add them to the polygon */ - lenPoly = 0; + lenPoly = 0; move16(); FOR( j = 0; j < numVtx; ++j ) { dist = L_abs( point_plane_distance_fx( @@ -3467,8 +3469,8 @@ static void tri_to_poly_fx( } /* search existing polygons to determine whether the new one already exists/is a subset or is a superset */ - found = 0; - replaceIdx = -1; + found = 0; move16(); + replaceIdx = -1; move16(); FOR( j = 0; j < lenPolySet; ++j ) { found = compare_poly_fx( sortedChan[j], sortedLengths[j], poly, lenPoly ); @@ -3507,7 +3509,7 @@ static void tri_to_poly_fx( } /* Output */ - *outLengthPS = lenPolySet; + *outLengthPS = lenPolySet; move16(); mvs2s( sortedLengths, outLengthSorted, EFAP_MAX_POLY_SET ); return; } @@ -3621,7 +3623,7 @@ static Word16 compare_poly_fx( Word16 i, j; Word16 count; - count = 0; + count = 0; move16(); FOR( i = 0; i < lenOld; ++i ) { @@ -3828,7 +3830,7 @@ static void sort_channels_vertex_fx( /* First Base Vector */ v_sub_fixed( P2, P1, tmpU, 3, 1 ); // tmpU Q30 - Word16 exp1 = 2; + Word16 exp1 = 2; move16(); normU = ISqrt32( dotp_fixed( tmpU, tmpU, 3 ), &exp1 ); // normU = L_shl_sat( normU, exp ); //normU Q31 v_multc_fixed( tmpU, normU, U, 3 ); // U Q30 - exp1 @@ -3843,7 +3845,7 @@ static void sort_channels_vertex_fx( } v_sub_fixed( tmpV1, tmpV2, tmpV3, 3, 0 ); // tmpV3 Q30 - Word16 exp2 = 2; + Word16 exp2 = 2; move16(); normV = ISqrt32( dotp_fixed( tmpV3, tmpV3, 3 ), &exp2 ); v_multc_fixed( tmpV3, normV, V, 3 ); // V Q30 - exp2 @@ -4001,7 +4003,7 @@ static Word16 get_poly_num_fx( Word32 dist_tmp; Word32 pos[3]; - num_poly = 0; + num_poly = 0; move16(); sph2cart_fx( P[0], P[1], &pos[0] ); @@ -4030,8 +4032,8 @@ static Word16 get_poly_num_fx( } /* select the polygon with the smallest distance */ - found_poly = poly_tmp[0]; - dist_tmp = poly_dist[0]; + found_poly = poly_tmp[0]; move16(); + dist_tmp = poly_dist[0]; move16(); FOR( i = 1; i < num_poly; i++ ) { IF( LT_32( poly_dist[i], dist_tmp ) ) @@ -4145,11 +4147,11 @@ static Word16 in_poly_fx( /* Angles are in Q22 */ IF( poly.isNaN[0] ) { - A[0] = P[0]; + A[0] = P[0]; move32(); } ELSE { - A[0] = poly.polyAzi[0]; + A[0] = poly.polyAzi[0]; move32(); } A[1] = poly.polyEle[0]; @@ -4304,20 +4306,20 @@ static Word16 in_tri_fx( { FOR( Word32 j = 0; j < 2; j++ ) { - matInv_exp[i][j] = 31; + matInv_exp[i][j] = 31; move16(); IF( NE_32( matInv[i][j], 0 ) ) { matInv_exp[i][j] = norm_l( matInv[i][j] ); } } - matInv_exp_final[i] = min( matInv_exp[i][0], matInv_exp[i][1] ); - P_minus_A_exp[i] = 31; + matInv_exp_final[i] = s_min( matInv_exp[i][0], matInv_exp[i][1] ); + P_minus_A_exp[i] = 31; move16(); IF( NE_32( P_minus_A[i], 0 ) ) { P_minus_A_exp[i] = norm_l( P_minus_A[i] ); } } - P_minus_A_exp_final = min( P_minus_A_exp[0], P_minus_A_exp[1] ); + P_minus_A_exp_final = s_min( P_minus_A_exp[0], P_minus_A_exp[1] ); S[0] = L_add( L_shr( Mpy_32_32( L_shl( matInv[0][0], matInv_exp_final[0] ), L_shl( P_minus_A[0], P_minus_A_exp_final ) ), Q1 ), L_shr( Mpy_32_32( L_shl( matInv[0][1], matInv_exp_final[0] ), L_shl( P_minus_A[1], P_minus_A_exp_final ) ), Q1 ) ); diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 172c4d30c..d869e2df8 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -884,9 +884,9 @@ ivas_error ivas_orient_trk_Init_fx( { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } - identity_fx.w_fx = ONE_IN_Q31; - identity_fx.x_fx = identity_fx.y_fx = identity_fx.z_fx = 0; - identity_fx.q_fact = Q31; + identity_fx.w_fx = ONE_IN_Q31; move32(); + identity_fx.x_fx = identity_fx.y_fx = identity_fx.z_fx = 0; move32(); move32(); + identity_fx.q_fact = Q31; move16(); /* configuration parameters */ pOTR->centerAdaptationRate_fx = C_ADP_RATE_Q31; @@ -898,8 +898,8 @@ ivas_error ivas_orient_trk_Init_fx( /* initial adaptivity filter coefficient, will be auto-adapted */ // pOTR->alpha = sinf( PI2 * pOTR->offCenterAdaptationRate / OTR_UPDATE_RATE ); /* start adaptation at off-center rate = fastest rate */ - pOTR->alpha_fx = 33731208; // Q31 - pOTR->Q_alpha = Q31; + pOTR->alpha_fx = 33731208; move32();// Q31 + pOTR->Q_alpha = Q31; move16(); pOTR->trkRot = identity_fx; pOTR->absAvgRot = identity_fx; /* Use frontal and horiontal orientation as reference orientation, unless/until overridden */ @@ -1336,7 +1336,7 @@ ivas_error ivas_orient_trk_Process_fx( Word32 rateRange_fx; Word32 cutoffFrequency_fx, cutoff_prod; Word16 q_cutoff_prod = 0; - Word32 alpha_fx = L_shl( pOTR->alpha_fx, Q30 - pOTR->Q_alpha ); + Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub(Q30, pOTR->Q_alpha) ); IF( pOTR == NULL || pTrkRot == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; @@ -1359,9 +1359,9 @@ ivas_error ivas_orient_trk_Process_fx( Word32 div; div = L_deposit_h( BASOP_Util_Divide3232_Scale( pOTR->centerAdaptationRate_fx, updateRate_fx, &scale_e ) ); - scale_e = scale_e - 8; // e+e1-e2// + scale_e = sub(scale_e, 8); // e+e1-e2// // here div value is less so we can use sandwitch rule of sine// - pOTR->alpha_fx = div; + pOTR->alpha_fx = div; move32(); /* Compute relative orientation = (absolute orientation) - (reference orientation) */ QuaternionInverse_fx( pOTR->refRot, &pOTR->trkRot ); QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); @@ -1373,18 +1373,16 @@ ivas_error ivas_orient_trk_Process_fx( /* Compute relative orientation = (absolute orientation) - (average absolute orientation) */ QuaternionInverse_fx( pOTR->absAvgRot, &pOTR->trkRot ); - Word32 angle_fx, relativeOrientationRate_fx = 0; + Word32 angle_fx, relativeOrientationRate_fx = 0; move32(); QuaternionProduct_fx( pOTR->trkRot, absRot, &pOTR->trkRot ); angle_fx = QuaternionAngle_fx( absRot, pOTR->trkRot ); // Q29 - Word16 result_e = 0; + Word16 result_e = 0; move16(); Word16 temp_result = BASOP_Util_Divide3232_Scale( angle_fx, pOTR->adaptationAngle_fx, &result_e ); relativeOrientationRate_fx = L_deposit_h( temp_result ); - Word32 one_fx = 1073741824; - Word16 temp = 1; - f2me( 1.0, &one_fx, &temp ); + Word32 one_fx = 1073741824; move32(); IF( GT_32( relativeOrientationRate_fx, one_fx ) ) { - relativeOrientationRate_fx = 1; + relativeOrientationRate_fx = 1; move32(); } /* Compute range of the adaptation rate between center = lower rate and off-center = higher rate */ @@ -1392,29 +1390,29 @@ ivas_error ivas_orient_trk_Process_fx( /* 'if' assumed to perform comparison to 0 */ IF( GT_32( 0, rateRange_fx ) ) { - rateRange_fx = 0; + rateRange_fx = 0;move32(); } - IF( relativeOrientationRate_fx == 1 ) + IF( EQ_32(relativeOrientationRate_fx, 1 )) { - cutoff_prod = rateRange_fx; - q_cutoff_prod = Q31; + cutoff_prod = rateRange_fx;move32(); + q_cutoff_prod = Q31; move16(); } ELSE { cutoff_prod = Mpy_32_32( relativeOrientationRate_fx, rateRange_fx ); - q_cutoff_prod = Q31 + ( 31 - result_e ) - 31; + q_cutoff_prod = add(Q31, sub(sub( 31, result_e ), 31)); } Word16 temp_diff; - temp_diff = 31 - q_cutoff_prod; + temp_diff = sub(31, q_cutoff_prod); cutoff_prod = L_shl( cutoff_prod, temp_diff ); /* Compute adaptivity cutoff frequency: interpolate between minimum (center) and maximum (off-center) values */ cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); cutoff_prod = Mpy_32_32( cutoffFrequency_fx, PI2_C_Q28 ); - q_cutoff_prod = 31 + 28 - 31; + q_cutoff_prod = sub(add(31, 28), 31); temp_result = BASOP_Util_Divide3232_Scale( cutoff_prod, updateRate_fx, &result_e ); - result_e = result_e + ( 23 - q_cutoff_prod ); + result_e = add(result_e, sub( 23, q_cutoff_prod )); pOTR->alpha_fx = L_deposit_h( temp_result ); - pOTR->Q_alpha = Q31 - result_e; + pOTR->Q_alpha = sub(Q31, result_e); BREAK; default: result = IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Non-supported orientation tracking adaptation type" ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index ebb3e8c4b..6cdabb683 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -355,11 +355,12 @@ void ivas_masa_ext_rend_parambin_render( float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t num_subframes /* i : number of subframes to render */ ); +#ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_dec_init_binaural_data( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ ); -#ifdef IVAS_FLOAT_FIXED +#else ivas_error ivas_dirac_dec_init_binaural_data_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : HRTF structure for rendering */ diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index b85a8cce1..01e97442f 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -399,9 +399,11 @@ static void ivas_binaural_reverb_setReverbTimes_fx( Word16 tmp, tmp_exp, diffuseFieldICC_exp, scale, tmpVal_exp, attenuationFactorPerSample_exp, attenuationFactorPerSampleSq_exp, energyBuildup_exp, currentEnergy_exp, intendedEnergy_exp, actualizedEnergy_exp; Word16 sine_inp, norm, sub_res, sub_exp, div_exp1, div1, sine, binCenterFreq_exp; Word16 reverb_exp = 0; + move16(); hReverb->binRend_RandNext = (UWord16) BIN_REND_RANDOM_SEED; hReverb->highestBinauralCoherenceBin = 0; + move16(); FOR ( bin = 0; bin < hReverb->numBins; bin++ ) { @@ -409,32 +411,34 @@ static void ivas_binaural_reverb_setReverbTimes_fx( Word16 exp; tmp_exp = BASOP_Util_Add_MantExp(bin, 15, 1, 14, &tmp); tmp = BASOP_Util_Divide3232_Scale(L_deposit_h(tmp), L_deposit_h(hReverb->numBins), &exp); - exp = exp + ( tmp_exp - 15); + exp = add( exp, sub( tmp_exp, 15) ); L_tmp = Mpy_32_16_1(output_Fs, tmp); - binCenterFreq_exp = 31 + exp; + binCenterFreq_exp = sub(31, exp); binCenterFreq_fx = L_shr(L_tmp, 1); // divide by 2 - IF ( bin == 0 ) + IF ( EQ_16( bin, 0 ) ) { diffuseFieldICC_fx = 1073741824; // 2 ^ 30, Q30 + move32(); diffuseFieldICC_exp = 1; + move16(); } ELSE IF ( BASOP_Util_Cmp_Mant32Exp(binCenterFreq_fx, binCenterFreq_exp, 2700, 31 ) == -1) { tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 550, &scale); - exp = scale + ( binCenterFreq_exp - 31 ); + exp = add( scale, sub( binCenterFreq_exp, 31 ) ); tmp = add(mult(EVS_PI_FX, tmp), EPSILLON_FX); // to avoid divide by 0 issue - tmp_exp = exp + 2; + tmp_exp = add( exp, 2 ); - sine_inp = wrap_rad_fixed(L_shl(tmp, tmp_exp - 2)); + sine_inp = wrap_rad_fixed(L_shl(tmp, sub( tmp_exp, 2))); sine = getSinWord16(sine_inp); // Q15 div1 = BASOP_Util_Divide1616_Scale(sine, tmp, &scale); - div_exp1 = scale + ( 0 - tmp_exp); + div_exp1 = add( scale, sub( 0, tmp_exp)); tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 2700, &scale); - scale = scale + (binCenterFreq_exp - 31); + scale = add(scale, sub(binCenterFreq_exp, 31)); - L_tmp = L_sub(L_shl(1, (15 - scale)), tmp); + L_tmp = L_sub(L_shl(1, sub(15, scale)), tmp); norm = norm_l(L_tmp); L_tmp = L_shl(L_tmp, norm); @@ -442,15 +446,18 @@ static void ivas_binaural_reverb_setReverbTimes_fx( sub_exp = sub(scale, sub(norm, 16)); diffuseFieldICC_fx = L_deposit_h(mult(sub_res, div1)); - diffuseFieldICC_exp = div_exp1 + sub_exp; + diffuseFieldICC_exp = add(div_exp1, sub_exp); hReverb->highestBinauralCoherenceBin = bin; + move16(); } ELSE { diffuseFieldICC_fx = 0; + move32(); diffuseFieldICC_exp = 0; + move16(); } /* Mixing gains to generate a diffuse-binaural sound based on incoherent sound */ @@ -481,9 +488,9 @@ static void ivas_binaural_reverb_setReverbTimes_fx( L_tmp = Mpy_32_32(1677721600, revTimes_fx[bin]); // e10 --> 800 * 2^21, + e0 tmp = BASOP_Util_Divide3232_Scale(1073741824, L_tmp, &scale); - scale = scale + ( 1 - 10 ); + scale = add(scale, sub( 1, 10 )); L_tmp = Mpy_32_16_1(-1610612736, tmp); // * -3 - scale = 2 + scale; + scale = add( 2, scale ); L_tmp = Mpy_32_32(1783446563, L_tmp); // scale + 2 attenuationFactorPerSample_fx = BASOP_util_Pow2(L_tmp, scale + 2, &attenuationFactorPerSample_exp ); @@ -491,7 +498,7 @@ static void ivas_binaural_reverb_setReverbTimes_fx( scale = norm_l(hReverb->loopBufLength[bin]); tmp_mul = L_shl(hReverb->loopBufLength[bin], scale); L_tmp = BASOP_Util_Log2( attenuationFactorPerSample_fx ); - L_tmp = L_add(L_tmp, attenuationFactorPerSample_exp * (1 << 25)); + L_tmp = L_add(L_tmp, L_shl( attenuationFactorPerSample_exp, 25)); L_tmp = Mpy_32_32(L_tmp, tmp_mul); hReverb->loopAttenuationFactor_fx[bin] = BASOP_util_Pow2(L_tmp, 6 + 31 - scale, &exp); hReverb->loopAttenuationFactor_fx[bin] = L_shl(hReverb->loopAttenuationFactor_fx[bin], exp); // making as Q31 @@ -503,19 +510,28 @@ static void ivas_binaural_reverb_setReverbTimes_fx( * may affect the spectrum of the output. The spectral effect is therefore monitored and compensated for. */ intendedEnergy_fx = 0; + move32(); intendedEnergy_exp = 0; + move16(); actualizedEnergy_fx = 0; + move32(); actualizedEnergy_exp = 0; + move16(); FOR ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { energyBuildup_fx = 0; + move32(); energyBuildup_exp = 0; + move16(); currentEnergy_fx = 1073741824; + move32(); currentEnergy_exp = 1; + move16(); tap = 0; + move16(); FOR ( sample = 0; sample < hReverb->loopBufLength[bin]; sample++ ) { @@ -533,7 +549,7 @@ static void ivas_binaural_reverb_setReverbTimes_fx( { IF(BASOP_Util_Cmp_Mant32Exp(energyBuildup_fx, energyBuildup_exp, 1, 31) >= 0) { /* Four efficient phase operations: n*pi/2, n=0,1,2,3 */ - hReverb->tapPhaseShiftType[bin][ch][tap] = (int16_t)(binRend_rand(hReverb) % 4); + hReverb->tapPhaseShiftType[bin][ch][tap] = (Word16)(binRend_rand(hReverb) % 4); /* Set the tapPointer to point to the determined sample at the loop buffer */ hReverb->tapPointersReal_fx[bin][ch][tap] = &(hReverb->loopBufReal_fx[bin][sample]); @@ -541,7 +557,7 @@ static void ivas_binaural_reverb_setReverbTimes_fx( energyBuildup_fx = BASOP_Util_Add_Mant32Exp(energyBuildup_fx, energyBuildup_exp, L_negate(1073741824), 1, &energyBuildup_exp); /* A tap is added, thus remove its energy from the buildup */ - tap++; + tap = add( tap, 1); actualizedEnergy_fx = BASOP_Util_Add_Mant32Exp(actualizedEnergy_fx, actualizedEnergy_exp, 1073741824, 1, &actualizedEnergy_exp); } @@ -553,26 +569,28 @@ static void ivas_binaural_reverb_setReverbTimes_fx( } hReverb->taps[bin][ch] = tap; /* Number of taps determined at the above random procedure */ + move16(); } /* The decorrelator design and IIR attenuation rate affects the energy of reverb, which is compensated here */ reverb_exp = 0; + move16(); hReverb->reverbEqGains_fx[bin] = Sqrt32(revEnes_fx[bin], &reverb_exp); /* Determined reverb spectrum */ hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); tmp = BASOP_Util_Divide3232_Scale(intendedEnergy_fx, actualizedEnergy_fx, &tmp_exp); - tmp_exp = tmp_exp + (intendedEnergy_exp - actualizedEnergy_exp); + tmp_exp = add(tmp_exp, sub(intendedEnergy_exp, actualizedEnergy_exp)); hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); L_tmp = Sqrt32(L_deposit_h(tmp), &tmp_exp); hReverb->reverbEqGains_fx[bin] = Mpy_32_32(hReverb->reverbEqGains_fx[bin], L_tmp); - reverb_exp = reverb_exp + tmp_exp; + reverb_exp = add(reverb_exp, tmp_exp); L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(attenuationFactorPerSampleSq_fx), attenuationFactorPerSampleSq_exp, &tmp_exp); L_tmp = Mpy_32_32(L_tmp, 1073741824); // tmp_exp + 1 - tmp_exp = tmp_exp + 0; + tmp_exp = add(tmp_exp, 0); L_tmp = Sqrt32(L_tmp, &tmp_exp); hReverb->reverbEqGains_fx[bin] = Mpy_32_32(L_tmp, hReverb->reverbEqGains_fx[bin]); - reverb_exp = reverb_exp + tmp_exp; + reverb_exp = add( reverb_exp, tmp_exp ); hReverb->reverbEqGains_fx[bin] = L_shl(hReverb->reverbEqGains_fx[bin], reverb_exp); // making as Q31 } return; @@ -603,8 +621,11 @@ static ivas_error compute_feedback_matrix_fx( FOR( j = 0; j < x; j++ ) { pFeedbackMatrix[( i + x ) * n + j] = pFeedbackMatrix[i * n + j]; + move32(); pFeedbackMatrix[i * n + j + x] = pFeedbackMatrix[i * n + j]; + move32(); pFeedbackMatrix[( i + x ) * n + j + x] = -pFeedbackMatrix[i * n + j]; + move32(); } } } @@ -628,11 +649,15 @@ static void compute_2_out_extract_matrix_fx( Word16 i; ff = 1; + move16(); + FOR( i = 0; i < n; i++ ) { pExtractMatrix[i] = 1; + move16(); pExtractMatrix[i + n] = ff; - ff = -ff; + move16(); + ff = negate(ff); } return; @@ -921,11 +946,13 @@ static void calc_predelay_fx( IF ( LT_16(predelay , 0) ) { predelay = 0; + move16(); } IF ( LT_16(output_frame , predelay) ) { predelay = output_frame; + move16(); } pParams->pre_delay = predelay; @@ -986,17 +1013,19 @@ static ivas_error compute_t60_coeffs_fx( Word16 target_gains_db_exp[RV_LENGTH_NR_FC]; error = IVAS_ERR_OK; tf_T60_len = nr_fc_fft_filter; - len = pParams->t60_filter_order + 1; + move16(); + len = add( pParams->t60_filter_order, 1 ); pFc_fx = pParams->pFc_fx; targetT60_fx = pParams->pRt60_fx; targetT60_e = pParams->pRt60_e; + move16(); FOR (bin_idx = 0; bin_idx < tf_T60_len; bin_idx++) { norm_f_fx[bin_idx] = BASOP_Util_Divide3232_Scale(pFc_fx[bin_idx], freq_Nyquist_fx, &norm_f_e); - norm_f_e = norm_f_e + (17 - 31); - norm_f_fx[bin_idx] = shl(norm_f_fx[bin_idx], norm_f_e - 1); // making Q14 + norm_f_e = add( norm_f_e, sub( 17, 31 ) ); + norm_f_fx[bin_idx] = shl(norm_f_fx[bin_idx], sub( norm_f_e, 1) ); // making Q14 } FOR ( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) @@ -1010,12 +1039,14 @@ static ivas_error compute_t60_coeffs_fx( tmp = BASOP_Util_Divide3232_Scale(L_deposit_h(loop_delay_sec_fx), targetT60_fx[bin_idx], &target_gains_db_exp[bin_idx]); target_gains_db_exp[bin_idx] = target_gains_db_exp[bin_idx] + (loop_delay_sec_fx_exp - targetT60_e[bin_idx]); target_gains_db_fx[bin_idx] = mult( -30720, tmp ); // -60 in Q9 -> -30720 - target_gains_db_exp[bin_idx] = target_gains_db_exp[bin_idx] + 6; // Q9 -> e6 + target_gains_db_exp[bin_idx] = add( target_gains_db_exp[bin_idx], 6 ); // Q9 -> e6 tmp = BASOP_Util_Cmp_Mant32Exp( L_deposit_h(target_gains_db_fx[bin_idx]), target_gains_db_exp[bin_idx], -2013265920, 7); IF (tmp < 0) { target_gains_db_fx[bin_idx] = -30720; + move16(); target_gains_db_exp[bin_idx] = 7; + move16(); } } @@ -1023,6 +1054,7 @@ static ivas_error compute_t60_coeffs_fx( pCoeffs_b_fx = &pParams->pT60_filter_coeff_fx[2 * len * loop_idx]; Word16 val = target_gains_db_exp[0]; + move16(); FOR (Word16 i = 1; i < nr_fc_fft_filter; i++) { val = s_max(val, target_gains_db_exp[i]); @@ -1038,10 +1070,10 @@ static ivas_error compute_t60_coeffs_fx( } } - len = ( pParams->t60_filter_order + 1 ) >> 1; /* == floor( (order+1) / 2) */ + len = shr( ( add( pParams->t60_filter_order, 1 ) ), 1 ); /* == floor( (order+1) / 2) */ FOR ( loop_idx = 0; loop_idx < pParams->nr_loops; loop_idx++ ) { - pParams->pLoop_delays[loop_idx] -= len; + pParams->pLoop_delays[loop_idx] = sub( pParams->pLoop_delays[loop_idx], len ); } return error; } @@ -1166,7 +1198,7 @@ static void calc_low_shelf_first_order_filter_fx( cos_val = getCosWord16(shl(tmp, 1)); // Q14 tan_val = BASOP_Util_Divide1616_Scale(sine_val, cos_val, &tan_exp); - tan_exp = tan_exp + (0 - 1); + tan_exp = add( tan_exp, sub(0, 1) ); Word16 gain_fx; gain_fx = BASOP_Util_Divide1616_Scale(lin_gain_lf, lin_gain_hf, &gain_exp); @@ -1175,21 +1207,23 @@ static void calc_low_shelf_first_order_filter_fx( { tmp = mult(tan_val, gain_fx); - norm_num0 = tan_exp + gain_exp; + norm_num0 = add( tan_exp, gain_exp ); L_tmp = L_add(L_shl(1, sub( 15, norm_num0) ), tmp); shift = norm_l(L_tmp); L_tmp = L_shl(L_tmp, shift); tmp = extract_h(L_tmp); pNum[0] = tmp; + move16(); norm_num0 = sub( norm_num0, sub(shift, 16) ); tmp = mult(tan_val, gain_fx); - norm_num1 = tan_exp + gain_exp; + norm_num1 = add( tan_exp, gain_exp ); L_tmp = L_sub(tmp, L_shl(1, sub(15, norm_num1))); shift = norm_l(L_tmp); L_tmp = L_shl(L_tmp, shift); tmp = extract_h(L_tmp); pNum[1] = tmp; + move16(); norm_num1 = sub( norm_num1, sub(shift, 16) ); L_tmp = L_add(L_shl(1, sub( 15, tan_exp) ), tan_val); @@ -1197,6 +1231,7 @@ static void calc_low_shelf_first_order_filter_fx( L_tmp = L_shl(L_tmp, shift); tmp = extract_h(L_tmp); pDen[0] = tmp; + move16(); norm_den0 = sub( tan_exp, sub(shift, 16 ) ); L_tmp = L_sub(tan_val, L_shl(1, sub( 15, tan_exp ) ) ); @@ -1204,6 +1239,7 @@ static void calc_low_shelf_first_order_filter_fx( L_tmp = L_shl(L_tmp, shift); tmp = extract_h(L_tmp); pDen[1] = tmp; + move16(); norm_den1 = sub(tan_exp, sub(shift, 16)); } ELSE @@ -1361,29 +1397,38 @@ static ivas_error calc_jot_t60_coeffs_fx( Word16 f0_fx, tmp_fx, lf_target_gain_dB_fx, hf_target_gain_dB_fx, mid_crossing_gain_dB_fx; Word16 lin_gain_lf_fx, lin_gain_hf_fx, shift, expl, exph; int16_t f_idx, e = pH_dB_exp; + move16(); uint16_t n_points_lf, n_points_hf; lf_target_gain_dB_fx = 0; + move16(); hf_target_gain_dB_fx = 0; + move16(); Word32 minval_fx = 1455191552; + move32(); Word16 minval_e = 67, exp; + move16(); Word32 L_tmpl = 0, L_tmph = 0; + move32(); + move32(); n_points_lf = 0; + move16(); n_points_hf = 0; - Word16 minidx_fx = nrFrequencies - 1; + move16(); + Word16 minidx_fx = sub( nrFrequencies, 1 ); FOR ( f_idx = 0; f_idx < nrFrequencies; f_idx++ ) { IF( GE_16( pFrequencies_fx[f_idx], ref_lf_min_norm_fx ) && LE_16( pFrequencies_fx[f_idx], ref_lf_max_norm_fx ) ) { L_tmpl = L_add( L_tmpl, pH_dB_fx[f_idx] ); - n_points_lf++; + n_points_lf = add(n_points_lf, 1); } IF( GE_16( pFrequencies_fx[f_idx], ref_hf_min_norm_fx ) && LE_16( pFrequencies_fx[f_idx], ref_hf_max_norm_fx ) ) { L_tmph = L_add(L_tmph, pH_dB_fx[f_idx]); - n_points_hf++; + n_points_hf = add(n_points_hf, 1); } } shift = norm_l(L_tmpl); @@ -1404,10 +1449,10 @@ static ivas_error calc_jot_t60_coeffs_fx( } lf_target_gain_dB_fx = BASOP_Util_Divide1616_Scale( lf_target_gain_dB_fx, n_points_lf, &e ); - expl = e + (expl - 15 ); + expl = add( e, sub(expl, 15 )); hf_target_gain_dB_fx = BASOP_Util_Divide1616_Scale(hf_target_gain_dB_fx, n_points_hf, &e); - exph = e + ( exph - 15 ); + exph = add( e, sub( exph, 15 )); e = BASOP_Util_Add_MantExp(lf_target_gain_dB_fx, expl, negate( hf_target_gain_dB_fx ), exph, &tmp_fx); exp = BASOP_Util_Add_MantExp(hf_target_gain_dB_fx, exph, tmp_fx, e - 1, &mid_crossing_gain_dB_fx); @@ -1424,11 +1469,14 @@ static ivas_error calc_jot_t60_coeffs_fx( { minval_fx = L_deposit_h(tmp1); minval_e = e; + move16(); minidx_fx = f_idx; + move16(); } } f0_fx = pFrequencies_fx[minidx_fx]; + move16(); tmp_fx = mult(lf_target_gain_dB_fx, 5443); // expl L_tmp = BASOP_util_Pow2(L_deposit_h(tmp_fx), expl, &e); @@ -1436,7 +1484,7 @@ static ivas_error calc_jot_t60_coeffs_fx( tmp_fx = mult(hf_target_gain_dB_fx, 5443); // exph L_tmp = BASOP_util_Pow2(L_deposit_h(tmp_fx), exph, &e); - lin_gain_hf_fx = (Word16)L_shr(L_tmp, 16 - e); + lin_gain_hf_fx = (Word16)L_shr(L_tmp, sub(16, e)); /* call low-pass iir shelf */ calc_low_shelf_first_order_filter_fx( pCoeffB_fx, pCoeffA_fx, f0_fx, lin_gain_lf_fx, lin_gain_hf_fx ); @@ -1796,7 +1844,7 @@ static ivas_error set_mixer_level_fx( const UWord16 channel, const Word16 level[] ) { - uint16_t branch_idx; + UWord16 branch_idx; IF ( channel >= BINAURAL_CHANNELS ) { return IVAS_ERR_INTERNAL; @@ -1827,6 +1875,7 @@ static void clear_buffers_fx( delay_line = &( hReverb->delay_line[branch_idx] ); set_val_Word32( delay_line->pBuffer_fx, 0, delay_line->MaxDelay ); delay_line->BufferPos = 0; + move16(); iirFilter = &( hReverb->t60[branch_idx] ); set_val_Word32( iirFilter->pBuffer_fx, 0, iirFilter->MaxTaps ); @@ -1851,17 +1900,23 @@ static void set_fft_and_datablock_sizes_fx( IF( EQ_16( subframe_len, 240 /*L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES*/ ) ) { hReverb->fft_size = IVAS_REVERB_FFT_SIZE_48K; + move16(); hReverb->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_48K; + move16(); } ELSE IF( EQ_16( subframe_len, 160 /*L_FRAME32k / MAX_PARAM_SPATIAL_SUBFRAMES*/ ) ) { hReverb->fft_size = IVAS_REVERB_FFT_SIZE_32K; + move16(); hReverb->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_32K; + move16(); } ELSE IF( EQ_16( subframe_len, 80 /*L_FRAME16k / MAX_PARAM_SPATIAL_SUBFRAMES*/ ) ) { hReverb->fft_size = IVAS_REVERB_FFT_SIZE_16K; + move16(); hReverb->num_fft_subblocks = IVAS_REVERB_FFT_N_SUBBLOCKS_16K; + move16(); } ELSE { @@ -2053,7 +2108,7 @@ static void set_reverb_acoustic_data_fx( { L_tmp = Mpy_32_32(pRt60_fx[bin_idx], ln_1e6_inverted_fx ); // exp = pRt60_e[bin_idx] + 0 exp_argument_fx = BASOP_Util_Divide3232_Scale(delay_diff_fx, L_tmp, &exp_argument_e); - exp_argument_e = exp_argument_e + (4 - pRt60_e[bin_idx]); // Q27 -> e4 + exp_argument_e = add( exp_argument_e, sub(4, pRt60_e[bin_idx])); // Q27 -> e4 /* Limit exponent to approx +/-100 dB in case of incoherent value of delay_diff, to prevent overflow */ // 23 in Q26 @@ -2085,10 +2140,12 @@ static void set_reverb_acoustic_data_fx( tmp_exp = add( exp_argument_e, 1 ); L_tmp = BASOP_util_Pow2(L_deposit_h(tmp), tmp_exp, &pow_exp); L_tmp = Mpy_32_32( L_tmp, pDsr_fx[bin_idx] ); - tmp_exp = tmp_exp + pDsr_e[bin_idx]; + tmp_exp = add( tmp_exp, pDsr_e[bin_idx] ); pDsr_fx[bin_idx] = L_tmp; + move32(); pDsr_e[bin_idx] = tmp_exp; + move16(); } return; @@ -2194,7 +2251,9 @@ static ivas_error setup_FDN_branches_fx( ivas_rev_delay_line_init( &( hReverb->delay_line[branch_idx] ), hReverb->loop_delay_buffer_fx[branch_idx], init_loop_delay[branch_idx], pParams->pLoop_delays[branch_idx] ); ivas_reverb_iir_filt_init( &( hReverb->t60[branch_idx] ), IVAS_REV_MAX_IIR_FILTER_LENGTH ); hReverb->mixer_fx[0][branch_idx] = 0; + move16(); hReverb->mixer_fx[1][branch_idx] = 0; + move16(); } clear_buffers_fx( hReverb ); nr_coefs = add(pParams->t60_filter_order , 1); @@ -2334,6 +2393,7 @@ ivas_error ivas_reverb_open_fx( output_frame = extract_l(Mult_32_16( output_Fs , INV_FRAME_PER_SEC_Q15)); subframe_len = shr(output_frame , 2); /*output_frame / MAX_PARAM_SPATIAL_SUBFRAMES*/ predelay_bf_len = output_frame; + move16(); nr_fc_input = hRenderConfig->roomAcoustics.nBands; /* Allocate main reverb. handle */ @@ -2363,6 +2423,7 @@ ivas_error ivas_reverb_open_fx( } pState->nr_of_branches = IVAS_REV_MAX_NR_BRANCHES; + move16(); set_fft_and_datablock_sizes_fx( pState, subframe_len ); nr_fc_fft_filter = add( extract_l( L_shr( pState->fft_size, 1 ) ), 1 ); @@ -2401,7 +2462,7 @@ ivas_error ivas_reverb_open_fx( set_reverb_acoustic_data_fx( ¶ms, input_audio_config, hHrtf, &hRenderConfig->roomAcoustics, subframe_len, nr_fc_input, nr_fc_fft_filter ); Scale_sig32( params.pFc_fx, nr_fc_fft_filter, -2 ); - for ( int i = 0; i < nr_fc_fft_filter; i++ ) + FOR ( Word16 i = 0; i < nr_fc_fft_filter; i++ ) { params.pRt60_fx[i] = L_abs(params.pRt60_fx[i]); params.pDsr_fx[i] = L_abs(params.pDsr_fx[i]); @@ -2432,8 +2493,8 @@ ivas_error ivas_reverb_open_fx( /* Compute target levels (gains) for the coloration filters */ Word32 *pHrtf_avg_pwr_response_l_const = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); Word32 *pHrtf_avg_pwr_response_r_const = (Word32*)malloc(nr_fc_fft_filter * sizeof(Word32*)); - Word16 lenT60_filter_coeff = add(params.t60_filter_order, 1); - lenT60_filter_coeff = add(i_mult(shl(lenT60_filter_coeff, 1), sub(params.nr_loops, 1)), add(lenT60_filter_coeff, 2)); + Word16 lenT60_filter_coeff = add(params.t60_filter_order, 1); + lenT60_filter_coeff = add(i_mult(shl(lenT60_filter_coeff, 1), sub(params.nr_loops, 1)), add(lenT60_filter_coeff, 2)); Word32 *pT60_filter_coeff = (Word32*)malloc((lenT60_filter_coeff) * sizeof(Word32*)); @@ -2466,6 +2527,7 @@ ivas_error ivas_reverb_open_fx( /* === to be used for subsequent audio signal processing === */ pState->do_corr_filter = params.do_corr_filter; + move16(); /* clear & init jot reverb fft filters */ IF ( ( error = initialize_reverb_filters_fx( pState ) ) != IVAS_ERR_OK ) @@ -2476,7 +2538,9 @@ ivas_error ivas_reverb_open_fx( IF ( pState->do_corr_filter ) { q_pFft_wf_filter_ch0_fx = 31; + move16(); q_pFft_wf_filter_ch1_fx = 31; + move16(); /* Computing correlation filters on the basis of target IA coherence */ FOR (int i = 0; i < nr_fc_fft_filter; i++) { pFft_wf_filter_ch0_fx[i][0] = L_shl_sat(pFft_wf_filter_ch0_fx[i][0] , 8); @@ -2938,7 +3002,9 @@ static void reverb_block_fx( FOR( i = 0; i < inner_bsize; i++ ) { pO0[i] = 0; + move16(); pO1[i] = 0; + move16(); } /* feedback network: */ @@ -2963,7 +3029,7 @@ static void reverb_block_fx( FOR( ns = 0; ns < inner_bsize; ns++ ) { - pFeedback_input_fx[ns] = pIn[ns] >> 3; // to make the Qfactor similar to pOutput + pFeedback_input_fx[ns] = L_shr( pIn[ns], 3 ); // to make the Qfactor similar to pOutput } FOR( j = 0; j < nr_branches; j++ ) @@ -2985,8 +3051,8 @@ static void reverb_block_fx( // Applying guard bits for the DoRTFT inside the post_fft_filter function FOR( k = 0; k < hReverb->fft_filter_ols.block_size; k++ ) { - pOut0_fx[k] = (Word32) pOut0_fx[k] >> ( r_shift ); - pOut1_fx[k] = (Word32) pOut1_fx[k] >> ( r_shift ); + pOut0_fx[k] = (Word32) L_shr( pOut0_fx[k], ( r_shift ) ); + pOut1_fx[k] = (Word32) L_shr( pOut1_fx[k], ( r_shift ) ); } /* Applying FFT filter to each sub-frame */ FOR( blk_idx = 0; blk_idx < hReverb->num_fft_subblocks; blk_idx++ ) @@ -3632,7 +3698,7 @@ void ivas_binaural_reverb_processSubframe_fx( ) { /* Declare the required variables */ - int16_t idx, bin, ch, sample, invertSampleIndex, tapIdx, *phaseShiftTypePr; + Word16 idx, bin, ch, sample, invertSampleIndex, tapIdx, *phaseShiftTypePr; // float **tapRealPr, **tapImagPr; Word32 **tapRealPr_fx, **tapImagPr_fx; push_wmops( "binaural_reverb" ); @@ -3657,7 +3723,7 @@ void ivas_binaural_reverb_processSubframe_fx( idx = hReverb->preDelayBufferIndex; FOR( sample = 0; sample < numSlots; sample++ ) { - invertSampleIndex = numSlots - sample - 1; + invertSampleIndex = sub(sub( numSlots, sample ), 1 ); FOR( bin = 0; bin < hReverb->numBins; bin++ ) { @@ -3689,6 +3755,7 @@ void ivas_binaural_reverb_processSubframe_fx( idx = ( idx + 1 ) % hReverb->preDelayBufferLength; } hReverb->preDelayBufferIndex = idx; + move16(); /* 3) Perform the filtering/decorrelating, using complex and sparse FIR filtering */ FOR( bin = 0; bin < hReverb->numBins; bin++ ) @@ -3764,17 +3831,21 @@ void ivas_binaural_reverb_processSubframe_fx( FOR( sample = 0; sample < numSlots; sample++ ) { /* Audio was in the temporally inverted order for convolution, re-invert audio to output */ - invertSampleIndex = numSlots - sample - 1; + invertSampleIndex = sub( sub( numSlots, sample ), 1 ); FOR( bin = 0; bin < hReverb->numBins; bin++ ) { outReal[ch][sample][bin] = hReverb->outputBufferReal_fx[bin][ch][invertSampleIndex]; // Q_in + Q30 + move32(); outImag[ch][sample][bin] = hReverb->outputBufferImag_fx[bin][ch][invertSampleIndex]; // Q_in + Q30 + move32(); } FOR( ; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) { outReal[ch][sample][bin] = 0; + move32(); outImag[ch][sample][bin] = 0; + move32(); } } } @@ -3800,10 +3871,10 @@ static ivas_error ivas_binaural_reverb_open_fx( const Word16 preDelay /* i : reverb pre-delay in CLDFB slots */ ) { - int16_t bin, chIdx, k, len; + Word16 bin, chIdx, k, len, scale, tmp; REVERB_STRUCT_HANDLE hReverb; - if ( ( *hReverbPr = (REVERB_STRUCT_HANDLE) malloc( sizeof( REVERB_STRUCT ) ) ) == NULL ) + IF ( ( *hReverbPr = (REVERB_STRUCT_HANDLE) malloc( sizeof( REVERB_STRUCT ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } @@ -3811,26 +3882,35 @@ static ivas_error ivas_binaural_reverb_open_fx( hReverb = *hReverbPr; hReverb->useBinauralCoherence = 1; + move16(); hReverb->preDelayBufferLength = 1; + move16(); hReverb->preDelayBufferIndex = 0; + move16(); hReverb->numBins = numBins; + move16(); hReverb->blockSize = numCldfbSlotsPerFrame; + move16(); - for ( k = 0; k < REVERB_PREDELAY_MAX + 1; k++ ) + FOR ( k = 0; k < REVERB_PREDELAY_MAX + 1; k++ ) { set32_fx( hReverb->preDelayBufferReal_fx[k], 0, hReverb->numBins ); set32_fx( hReverb->preDelayBufferImag_fx[k], 0, hReverb->numBins ); } - for ( bin = 0; bin < hReverb->numBins; bin++ ) + FOR ( bin = 0; bin < hReverb->numBins; bin++ ) { /* Loop Buffer */ - hReverb->loopBufLengthMax[bin] = (int16_t) ( 500 / ( 1 + bin ) + ( CLDFB_NO_CHANNELS_MAX - bin ) ); - len = hReverb->loopBufLengthMax[bin] + hReverb->blockSize; + tmp = BASOP_Util_Divide1616_Scale(500, add(bin, 1), &scale); + tmp = shr(tmp, sub( 15, scale) ); + hReverb->loopBufLengthMax[bin] = add( tmp, sub( CLDFB_NO_CHANNELS_MAX, bin ) ); + //hReverb->loopBufLengthMax[bin] = (Word16) ( 500 / ( 1 + bin ) + ( CLDFB_NO_CHANNELS_MAX - bin ) ); - if ( ( hReverb->loopBufReal_fx[bin] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + len = add( hReverb->loopBufLengthMax[bin], hReverb->blockSize ); + + IF ( ( hReverb->loopBufReal_fx[bin] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } @@ -3849,36 +3929,38 @@ static ivas_error ivas_binaural_reverb_open_fx( Word32 L_tmp_BufLength = L_shl( L_shr( Mpy_32_32( revTimes_fx[bin], 1258291200 /*150.0 in Q23*/ ), 23 ), 23 ); L_tmp_BufLength = L_add( Mpy_32_32( 1556925645 /*1.45 in Q30*/, L_tmp_BufLength ), ONE_IN_Q22 ); hReverb->loopBufLength[bin] = (Word16) L_shr( L_tmp_BufLength, 22 ); - hReverb->loopBufLength[bin] = min( hReverb->loopBufLength[bin], hReverb->loopBufLengthMax[bin] ); + hReverb->loopBufLength[bin] = s_min( hReverb->loopBufLength[bin], hReverb->loopBufLengthMax[bin] ); /* Sparse Filter Tap Locations */ - for ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) + FOR ( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { len = hReverb->loopBufLength[bin]; + move16(); - if ( ( hReverb->tapPhaseShiftType[bin][chIdx] = (int16_t *) malloc( len * sizeof( int16_t ) ) ) == NULL ) + IF ( ( hReverb->tapPhaseShiftType[bin][chIdx] = (Word16 *) malloc( len * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } set_s( hReverb->tapPhaseShiftType[bin][chIdx], 0, len ); - if ( ( hReverb->tapPointersReal_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) + IF ( ( hReverb->tapPointersReal_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - if ( ( hReverb->tapPointersImag_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) + IF ( ( hReverb->tapPointersImag_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } len = hReverb->blockSize; - if ( ( hReverb->outputBufferReal_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + move16(); + IF ( ( hReverb->outputBufferReal_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } - if ( ( hReverb->outputBufferImag_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) + IF ( ( hReverb->outputBufferImag_fx[bin][chIdx] = (Word32 *) malloc( len * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } @@ -3887,12 +3969,6 @@ static ivas_error ivas_binaural_reverb_open_fx( } } - /*Word32 *revTimes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); - Word32 *revEnes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); - FOR(int i = 0; i < hReverb->numBins; i++) { - revTimes_fx[i] = (Word32)(revTimes[i] * ONE_IN_Q31); - revEnes_fx[i] = (Word32)(revEnes[i] * ONE_IN_Q31); - }*/ ivas_binaural_reverb_setReverbTimes_fx( hReverb, sampling_rate, revTimes_fx, revEnes_fx ); /*free(revTimes_fx); @@ -4104,7 +4180,7 @@ ivas_error ivas_binaural_reverb_open_fastconv_fx( { return error; } - preDelay = (int16_t) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); + preDelay = (Word16) roundf( 48000.0f * roomAcoustics->acousticPreDelay / CLDFB_NO_CHANNELS_MAX ); floatToFixed_arrL(t60_flt, t60, Q31, CLDFB_NO_CHANNELS_MAX); floatToFixed_arrL(ene_flt, ene, Q31, CLDFB_NO_CHANNELS_MAX); } @@ -4113,6 +4189,7 @@ ivas_error ivas_binaural_reverb_open_fastconv_fx( revTimes = hHrtfFastConv->fastconvReverberationTimes_fx; revEne = hHrtfFastConv->fastconvReverberationEneCorrections_fx; preDelay = 10; + move16(); } error = ivas_binaural_reverb_open_fx( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay ); @@ -4170,8 +4247,8 @@ ivas_error ivas_binaural_reverb_open_fastconv( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_binaural_reverb_open_parambin( REVERB_STRUCT_HANDLE *hReverbPr, /* i/o: binaural reverb handle */ - const int16_t numBins, /* i : number of CLDFB bins */ - const int16_t numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ + const Word16 numBins, /* i : number of CLDFB bins */ + const Word16 numCldfbSlotsPerFrame, /* i : number of CLDFB slots per frame */ IVAS_ROOM_ACOUSTICS_CONFIG_DATA *roomAcoustics, /* i/o: room acoustics parameters */ const int32_t sampling_rate, /* i : sampling rate */ const HRTFS_PARAMBIN_HANDLE hHrtfParambin /* i : Parametric binauralizer HRTF handle */ @@ -4182,7 +4259,7 @@ ivas_error ivas_binaural_reverb_open_parambin( const Word32 *revEne; Word32 t60[CLDFB_NO_CHANNELS_MAX]; Word32 ene[CLDFB_NO_CHANNELS_MAX]; - int16_t preDelay; + Word16 preDelay; error = IVAS_ERR_OK; @@ -4203,6 +4280,7 @@ ivas_error ivas_binaural_reverb_open_parambin( revTimes = hHrtfParambin->parametricReverberationTimes_fx; revEne = hHrtfParambin->parametricReverberationEneCorrections_fx; preDelay = 10; + move16(); } error = ivas_binaural_reverb_open_fx( hReverbPr, numBins, numCldfbSlotsPerFrame, sampling_rate, revTimes, revEne, preDelay ); diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index e9f05808f..33874261e 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -1804,10 +1804,6 @@ ivas_error ivas_external_orientation_open( Word16 i; IVAS_QUATERNION identity; -#if 0 // to be removed later - identity.w = 1.0f; - identity.x = identity.y = identity.z = 0.0f; -#endif identity.w_fx = ONE_IN_Q31; move32(); identity.x_fx = 0; @@ -1925,11 +1921,6 @@ ivas_error ivas_combined_orientation_open( Word16 tmp_e = 0, tmp; IVAS_QUATERNION identity; IVAS_VECTOR3 origo; -#if 0 // to be removed later - identity.w = 1.0f; - identity.x = identity.y = identity.z = 0.0f; - origo.x = origo.y = origo.z = 0.0f; -#endif identity.w_fx = ONE_IN_Q31; move32(); identity.x_fx = 0; @@ -3038,28 +3029,42 @@ static Word32 SHrot_p_fx( { Word16 ri1 = 0, rim1 = 0, ri0 = 0, R_lm1_1 = 0, R_lm1_2 = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + Word32 p = 0; + move32(); + ri1 = SHrotmat[i + 1 + 1][1 + 1 + 1]; + move16(); rim1 = SHrotmat[i + 1 + 1][-1 + 1 + 1]; + move16(); ri0 = SHrotmat[i + 1 + 1][0 + 1 + 1]; + move16(); - if ( b == -l ) + IF ( EQ_16( b, -l ) ) { R_lm1_1 = R_lm1[a + l - 1][0]; + move16(); R_lm1_2 = R_lm1[a + l - 1][2 * l - 2]; + move16(); p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); } - else + ELSE { - if ( b == l ) + IF ( EQ_16( b, l ) ) { - R_lm1_1 = R_lm1[a + l - 1][2 * l - 2]; + R_lm1_1 = R_lm1[a + l - 1][sub( shl( l, 1 ), 2 ) ]; R_lm1_2 = R_lm1[a + l - 1][0]; p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); } - else + ELSE { R_lm1_1 = R_lm1[a + l - 1][b + l - 1]; + move16(); p = L_mult0( ri0, R_lm1_1 ); } } @@ -3216,27 +3221,27 @@ static Word32 SHrot_v_fx( Word32 p0, p1; Word16 d; - if ( m == 0 ) + IF ( EQ_16( m, 0 ) ) { p0 = SHrot_p_fx( 1, l, 1, n, SHrotmat, R_lm1 ); // Q28 p1 = SHrot_p_fx( -1, l, -1, n, SHrotmat, R_lm1 ); // Q28 - result = L_add( p0, p1 ) / 2; // converting to Q27 + result = L_shr( L_add( p0, p1 ), 2 ); // converting to Q27 } - else + ELSE { - if ( m > 0 ) + IF ( GT_16( m, 0 ) ) { d = ( m == 1 ) ? 1 : 0; p0 = (Word32) SHrot_p_fx( 1, l, m - 1, n, SHrotmat, R_lm1 ); p1 = (Word32) SHrot_p_fx( -1, l, -m + 1, n, SHrotmat, R_lm1 ); - result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[1 + d] ), p1, ( 1 - d ) * ( 1 << 14 ) ); // Q27 + result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[1 + d] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 } - else + ELSE { d = ( m == -1 ) ? 1 : 0; p0 = (Word32) SHrot_p_fx( 1, l, m + 1, n, SHrotmat, R_lm1 ); p1 = (Word32) SHrot_p_fx( -1, l, -m - 1, n, SHrotmat, R_lm1 ); - result = Madd_32_16_r( Mpy_32_16_r( p0, ( 1 - d ) * ( 1 << 14 ) ), p1, square_root16_table[1 + d] ); // Q27 + result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[1 + d] ); // Q27 } } return result; // Q27 @@ -3251,20 +3256,20 @@ static Word32 SHrot_w_fx( { Word32 result, p0, p1; - if ( m == 0 ) + IF ( EQ_16( m, 0 ) ) { printf( "ERROR should not be called\n" ); return 0; } - else + ELSE { - if ( m > 0 ) + IF ( GT_16( m, 0 ) ) { p0 = SHrot_p_fx( 1, l, m + 1, n, SHrotmat, R_lm1 ); p1 = SHrot_p_fx( -1, l, -m - 1, n, SHrotmat, R_lm1 ); result = L_add( p0, p1 ); } - else + ELSE { p0 = SHrot_p_fx( 1, l, m - 1, n, SHrotmat, R_lm1 ); p1 = SHrot_p_fx( -1, l, -m + 1, n, SHrotmat, R_lm1 ); @@ -3291,17 +3296,31 @@ void SHrotmatgen_fx( ) { Word16 d = 0; + move16(); Word16 band_idx = 0; + move16(); Word16 i, j; Word16 l, m, n; Word16 absm; Word16 sqdenom = 0, sql2mm2 = 0, sqdabsm = 0, sqlabsm = 0; Word16 u = 0, v = 0, w = 0; + move16(); + move16(); + move16(); + move16(); + move16(); + move16(); + Word32 u32_fx = 0, v32_fx = 0, w32_fx = 0; + move32(); + move32(); + move32(); + Word16 R_lm1[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; Word16 R_l[HEADROT_SHMAT_DIM][HEADROT_SHMAT_DIM]; Word32 result; SHrotmat[0][0] = ONE_IN_Q14; + move16(); SHrotmat[1][1] = extract_h( Rmat[1][1] ); SHrotmat[1][2] = extract_h( Rmat[1][2] ); @@ -3315,77 +3334,83 @@ void SHrotmatgen_fx( SHrotmat[3][2] = extract_h( Rmat[0][2] ); SHrotmat[3][3] = extract_h( Rmat[0][0] ); - for ( i = 0; i < 2 * 1 + 1; i++ ) + FOR ( i = 0; i < 2 * 1 + 1; i++ ) { - for ( j = 0; j < 2 * 1 + 1; j++ ) + FOR ( j = 0; j < 2 * 1 + 1; j++ ) { R_lm1[i][j] = SHrotmat[i + 1][j + 1]; + move16(); } } band_idx = 4; - for ( l = 2; l <= order; l++ ) + move16(); + FOR ( l = 2; l <= order; l++ ) { set_val_Word16( &R_l[0][0], 0, HEADROT_SHMAT_DIM2 ); - for ( m = -l; m <= l; m++ ) + FOR ( m = -l; m <= l; m++ ) { d = ( m == 0 ) ? 1 : 0; absm = (Word16) abs( m ); - sql2mm2 = square_root30_q12[( l * l - m * m )]; - sqdabsm = square_root30_q12[( ( 1 + d ) * ( l + absm - 1 ) * ( l + absm ) )]; - sqlabsm = square_root30_q12[( ( l - absm - 1 ) * ( l - absm ) )]; - for ( n = -l; n <= l; n++ ) + sql2mm2 = square_root30_q12[imult1616(shl(l, 1), sub(shl(l, 1), 1))]; + sqdabsm = square_root30_q12[imult1616((1 + d), imult1616(sub(add( l, absm), 1), add(l, absm)))]; + sqlabsm = square_root30_q12[imult1616( sub( l, sub( absm, 1 ) ), sub( l, absm ) )]; + + FOR ( n = -l; n <= l; n++ ) { - if ( abs( n ) == l ) + IF ( EQ_16( abs_s( n ), l ) ) { - sqdenom = square_root30_q12[( ( 2 * l ) * ( 2 * l - 1 ) )]; + sqdenom = square_root30_q12[imult1616( shl( l, 1 ), sub( shl( l, 1 ), 1 ) )]; } - else + ELSE { - sqdenom = square_root30_q12[( l * l - n * n )]; + sqdenom = square_root30_q12[sub(imult1616( l, l ), imult1616( n, n) )]; } - u = div_l( (Word32) ( sql2mm2 * ( 1 << 15 ) ), sqdenom ); // Q14 - v = div_l( (Word32) ( sqdabsm * ( 1 << 14 ) ), sqdenom ) * ( 1 - 2 * d ); // Q14 - w = div_l( (Word32) ( sqlabsm * ( 1 << 14 ) ), sqdenom ) * ( 1 - d ) * -1; // Q14 - if ( u != 0 ) + u = div_l( L_shl( (Word32) sql2mm2, 15 ), sqdenom ); // Q14 + v = imult1616( div_l( L_shl( (Word32) sqdabsm, 14 ), sqdenom ), sub( 1, shl( d, 1 ) ) ); // Q14 + w = imult1616( div_l( L_shl( (Word32) sqlabsm, 14 ), sqdenom ), negate( sub( 1, d ) ) ); // Q14 + + IF ( NE_16( u, 0 ) ) { result = SHrot_u_fx( l, m, n, SHrotmat, R_lm1 ); // Q28 u32_fx = Mpy_32_16_r( result, u ); // Q27 } - if ( v != 0 ) + IF ( NE_16( v, 0 ) ) { result = SHrot_v_fx( l, m, n, SHrotmat, R_lm1 ); v32_fx = Mpy_32_16_r( result, v ); // Q26 } - if ( w != 0 ) + IF ( NE_16( w, 0 ) ) { result = SHrot_w_fx( l, m, n, SHrotmat, R_lm1 ); w32_fx = Mpy_32_16_r( result, w ); // Q27 } // Addind and converting to 16 bit integer of Q14 - R_l[m + l][n + l] = extract_h( L_add( L_add( u32_fx >> 1, v32_fx ), w32_fx >> 1 ) * ( 1 << 4 ) ); // Q14 + R_l[m + l][n + l] = extract_h( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ) * L_shl( 1, 4 ) ); // Q14 } } - for ( i = 0; i < 2 * l + 1; i++ ) + FOR ( i = 0; i < 2 * l + 1; i++ ) { - for ( j = 0; j < 2 * l + 1; j++ ) + FOR ( j = 0; j < 2 * l + 1; j++ ) { SHrotmat[band_idx + i][band_idx + j] = R_l[i][j]; + move16(); } } - for ( i = 0; i < 2 * l + 1; i++ ) + FOR ( i = 0; i < 2 * l + 1; i++ ) { - for ( j = 0; j < 2 * l + 1; j++ ) + FOR ( j = 0; j < 2 * l + 1; j++ ) { R_lm1[i][j] = R_l[i][j]; + move16(); } } - band_idx += 2 * l + 1; + band_idx = add( shl( l, 1 ), 1 ); } return; -- GitLab