From fc107808fa90b569933c57283569f625d935ec4d Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 28 Jun 2024 12:12:13 +0530 Subject: [PATCH 1/2] Removed usage of division and used multiplication at points possible. --- lib_com/cnst.h | 3 +- lib_com/ivas_cnst.h | 2 + lib_com/ivas_dirac_com.c | 7 +- lib_com/ivas_ism_com.c | 13 ++-- lib_com/ivas_masa_com.c | 10 +-- lib_com/ivas_spar_com.c | 34 ++++------ lib_com/rom_com.c | 24 +++---- lib_dec/acelp_core_dec_ivas_fx.c | 9 ++- lib_dec/cng_dec_fx.c | 4 +- lib_dec/dec_tcx_fx.c | 6 +- lib_dec/er_dec_tcx_fx.c | 6 +- lib_dec/fd_cng_dec.c | 12 +--- lib_dec/hq_core_dec_fx.c | 4 +- lib_dec/ivas_ism_param_dec.c | 15 ++-- lib_dec/ivas_jbm_dec.c | 13 ++-- lib_dec/ivas_lfe_plc_fx.c | 14 ++-- lib_dec/ivas_masa_dec.c | 23 +++---- lib_dec/ivas_mct_dec.c | 8 +-- lib_dec/ivas_mct_dec_mct_fx.c | 4 +- lib_dec/ivas_omasa_dec.c | 4 +- lib_dec/ivas_sba_dec.c | 6 +- lib_dec/ivas_spar_md_dec.c | 11 ++- lib_dec/ivas_stereo_dft_dec_fx.c | 11 +-- lib_dec/ivas_stereo_switching_dec.c | 10 +-- lib_enc/init_enc.c | 9 ++- lib_enc/ivas_core_pre_proc_front.c | 4 +- lib_enc/ivas_stereo_dft_enc.c | 15 ++-- lib_enc/ivas_stereo_mdct_stereo_enc.c | 5 +- lib_rend/ivas_crend.c | 6 +- lib_rend/ivas_dirac_ana.c | 6 +- lib_rend/ivas_dirac_output_synthesis_dec.c | 4 +- lib_rend/ivas_dirac_rend.c | 79 +++++++++------------- lib_rend/ivas_efap.c | 21 +----- lib_rend/ivas_limiter.c | 7 +- lib_rend/ivas_objectRenderer.c | 5 +- lib_rend/ivas_omasa_ana.c | 10 ++- lib_rend/ivas_reverb.c | 51 +++++++------- lib_rend/ivas_rotation.c | 7 +- lib_rend/ivas_stat_rend.h | 6 +- lib_rend/ivas_vbap.c | 31 ++------- lib_rend/lib_rend.c | 6 +- 41 files changed, 216 insertions(+), 309 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index a1ec42fb9..55eafef53 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -575,7 +575,7 @@ enum #define FRAMES_PER_SEC 50 #ifdef IVAS_FLOAT_FIXED #define MAX_PARAM_SPATIAL_SUB_FRAMES_PER_SEC 200 //(FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES) -#define ONE_BY_FRAMES_PER_SEC_Q31 ((Word32)(0x028F5C29)) +#define ONE_BY_FRAMES_PER_SEC_Q31 ( 42949673 ) #define FRAMES_PER_SEC_BY_2 (FRAMES_PER_SEC >> 1) #endif #define INV_FRAME_PER_SEC_Q15 656 @@ -607,6 +607,7 @@ enum #define N_WS2N_FRAMES 40 /* number of frames for attenuation during the band-width switching */ #define N_NS2W_FRAMES 20 /* number of frames for attenuation during the band-width switching */ +#define ONE_BY_N_NS2W_FRAMES_Q15 ( 1638 ) /*----------------------------------------------------------------------------------* * Coder types (only for ACELP core when not running in AMR-WB IO mode) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 1b6940be5..d82507787 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1681,6 +1681,8 @@ typedef enum #define DEG_360_IN_Q22 (360 << Q22) #define DEG_180_IN_Q22 (180 << Q22) #define DEG_90_IN_Q22 (90 << Q22) +#define ONE_BY_360_Q31 ( 5965232 ) +#define ONE_BY_180_Q31 ( 11930465 ) /* ----- Enums - TD Renderer ----- */ diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 8a37462d4..b87592d22 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -639,10 +639,9 @@ void ivas_get_dirac_sba_max_md_bits_fx( } ELSE { - //*bits_frame_nominal = (int16_t) ( sba_total_brate / FRAMES_PER_SEC ); - Word16 tmp_exp = 0, tmp; - tmp = BASOP_Util_Divide3232_Scale( sba_total_brate, FRAMES_PER_SEC, &tmp_exp ); - *bits_frame_nominal = shr( tmp, 15 - tmp_exp ); + /* *bits_frame_nominal = (int16_t) ( sba_total_brate / FRAMES_PER_SEC ); */ + *bits_frame_nominal = extract_l( Mpy_32_32( sba_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + move16(); *metadata_max_bits = MAX16B; /* no limit */ } Word32 var1 = L_mult0( *metadata_max_bits, nbands ); diff --git a/lib_com/ivas_ism_com.c b/lib_com/ivas_ism_com.c index 6f0b03286..aab90fab5 100644 --- a/lib_com/ivas_ism_com.c +++ b/lib_com/ivas_ism_com.c @@ -52,8 +52,11 @@ #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC ) -#define BETA_ISM_LOW_IMP 0.6f -#define BETA_ISM_MEDIUM_IMP 0.8f +#define BETA_ISM_LOW_IMP 0.6f +#define BETA_ISM_LOW_IMP_Q31 ( 1288490189 ) +#define BETA_ISM_MEDIUM_IMP 0.8f +#define BETA_ISM_MEDIUM_IMP_Q31 ( 1717986918 ) +#define BETA_ISM_MEDIUM_IMP_BY_8_Q31 ( 214748365 ) #define MAX_BRATE_TCX_32k 48000 #define BITS_IVAS_512k ( IVAS_512k / FRAMES_PER_SEC ) @@ -585,15 +588,13 @@ ivas_error ivas_ism_config_fx( ELSE IF( EQ_16( ism_imp[ch], ISM_LOW_IMP ) ) { // tmp = (Word16) ( BETA_ISM_LOW_IMP * bits_CoreCoder[ch] ); - tmp1 = BASOP_Util_Divide1616_Scale( bits_CoreCoder[ch], 5, &exp ); - tmp = shr( mult( tmp1, 24576 ), ( 15 - exp + 13 ) - 15 ); + tmp = extract_l( Mpy_32_32( BETA_ISM_LOW_IMP_Q31, bits_CoreCoder[ch] ) ); tmp = s_max( limit, tmp ); } ELSE IF( EQ_16( ism_imp[ch], ISM_MEDIUM_IMP ) ) { // tmp = (Word16) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] ); - tmp1 = BASOP_Util_Divide1616_Scale( bits_CoreCoder[ch], 5, &exp ); - tmp = shr( mult( tmp1, 16384 ), ( 15 - exp + 12 ) - 15 ); + tmp = extract_l( Mpy_32_32( BETA_ISM_MEDIUM_IMP_BY_8_Q31, L_shl( bits_CoreCoder[ch], Q3 ) ) ); tmp = s_max( limit, tmp ); } ELSE /* ism_imp[ch] == ISM_HIGH_IMP */ diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index bbfc3d69c..388dd6a60 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -179,7 +179,7 @@ void ivas_masa_set_elements_fx( const Word32 ism_total_brate /* i : initial ISM total bitrate */ ) { - Word16 tmp, tmp_e; + Word16 tmp; IF( EQ_16( nchan_transport, 2 ) ) { @@ -232,12 +232,12 @@ void ivas_masa_set_elements_fx( move16(); } } - tmp = BASOP_Util_Divide3216_Scale( ivas_total_brate, FRAMES_PER_SEC, &tmp_e ); - hQMetaData->bits_frame_nominal = shr( tmp, negate( add( 1, tmp_e ) ) ); // Q0 + /* hQMetaData->bits_frame_nominal = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ); */ + hQMetaData->bits_frame_nominal = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) ) { - tmp = BASOP_Util_Divide3216_Scale( ism_total_brate, FRAMES_PER_SEC, &tmp_e ); - tmp = shr( tmp, negate( add( 1, tmp_e ) ) ); // Q0 + /* hQMetaData->bits_frame_nominal -= (int16_t) ( ism_total_brate / FRAMES_PER_SEC ); */ + tmp = extract_l( Mpy_32_32( ism_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); hQMetaData->bits_frame_nominal = sub( hQMetaData->bits_frame_nominal, tmp ); } } diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index aa762741c..0b4639a3e 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -6422,15 +6422,6 @@ void ivas_spar_set_bitrate_config( } #ifdef IVAS_FLOAT_FIXED -static Word32 ceil32_fx( Word32 var1, Word16 q ) -{ - Word32 ans, temp; - ans = L_shr( var1, q ); - temp = L_shl( ans, q ); - IF( GT_32( ans, temp ) ) - return ans; - ELSE return L_add( ans, 1 ); -} void ivas_spar_set_bitrate_config_fx( ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ const Word16 table_idx, /* i : config. table index */ @@ -6482,16 +6473,16 @@ void ivas_spar_set_bitrate_config_fx( Word16 div1; FOR( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { - div1 = BASOP_Util_Divide3232_Scale( ivas_spar_br_table_consts[table_idx].core_brs[i][0], FRAMES_PER_SEC, &temp ); - total_bits = add( total_bits, shr( div1, sub( 15, temp ) ) ); - div1 = BASOP_Util_Divide3232_Scale( ivas_spar_br_table_consts[table_idx].core_brs[i][1], FRAMES_PER_SEC, &temp ); - max_bits = add( max_bits, shr( div1, sub( 15, temp ) ) ); + /* total_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC ); */ + total_bits = add( total_bits, extract_l( Mpy_32_32( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + /* max_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][1] / FRAMES_PER_SEC ); */ + max_bits = add( max_bits, extract_l( Mpy_32_32( ivas_spar_br_table_consts[table_idx].core_brs[i][1], ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } - - div1 = BASOP_Util_Divide3232_Scale( ivas_total_brate, FRAMES_PER_SEC, &temp ); - pSpar_md_cfg->tgt_bits_per_blk = sub( shr( div1, sub( 15, temp ) ), add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), total_bits ) ); - pSpar_md_cfg->max_bits_per_blk = sub( shr( div1, sub( 15, temp ) ), add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); + /* (int16_t) ( ivas_total_brate / FRAMES_PER_SEC ) */ + div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + pSpar_md_cfg->tgt_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), total_bits ) ); + pSpar_md_cfg->max_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); md_coding_bits_header = add( SPAR_NUM_CODING_STRAT_BITS, pSpar_md_cfg->quant_strat_bits ); @@ -6507,11 +6498,10 @@ void ivas_spar_set_bitrate_config_fx( bands_bw = 1; } - div1 = BASOP_Util_Divide3232_Scale( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), IVAS_MAX_NUM_BANDS, &temp ); - pSpar_md_cfg->tgt_bits_per_blk = (Word16) ceil32_fx( div1, 15 - temp ); - - div1 = BASOP_Util_Divide3232_Scale( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), IVAS_MAX_NUM_BANDS, &temp ); - pSpar_md_cfg->max_bits_per_blk = (Word16) ceil32_fx( div1, 15 - temp ); + /* pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->tgt_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS ); */ + pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); + /* pSpar_md_cfg->max_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->max_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS ); */ + pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); pSpar_md_cfg->tgt_bits_per_blk = add( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); pSpar_md_cfg->max_bits_per_blk = add( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index 9590726d1..22589b96f 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -11007,22 +11007,22 @@ const SCALE_SETUP scaleTable_cn_only[SIZE_SCALE_TABLE_CN] = #endif const SCALE_SETUP scaleTable_cn_dirac[15] = { - { 0, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, -24576 }, - { 0, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, -20480 }, - { 0, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, -16384 }, - { 0, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, -12288 }, + { 0, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 0, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 0, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 0, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, { 0, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - { 1, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, -24576 }, - { 1, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, -20480 }, - { 1, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, -16384 }, - { 1, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, -12288 }, + { 1, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 1, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 1, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 1, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, { 1, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 }, - { 2, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, -24576 }, - { 2, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, -20480 }, - { 2, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, -16384 }, - { 2, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, -12288 }, + { 2, 0, 13200, -3.0f, 16306/*0.9952622652 Q14*/ /*-3.0f*/, 16306 }, + { 2, 13200, 16400, -2.5f, 12751/*0.7782794237 Q14*/ /*-2.5f*/, 12751 }, + { 2, 16400, 24400, -2.0f, 9583/*0.5848932266 Q14*/ /*-2.0f*/, 9583 }, + { 2, 24400, 32000, -1.5f, 6759/*0.4125375748 Q14*/ /*-1.5f*/, 6759 }, { 2, 32000,512001, 0.0f, 0/*0.0000000000 Q14*/ /* 0.0f*/, 0 } }; const float scaleTable_cn_only_amrwbio_flt[SIZE_SCALE_TABLE_CN_AMRWB][2] = diff --git a/lib_dec/acelp_core_dec_ivas_fx.c b/lib_dec/acelp_core_dec_ivas_fx.c index 905db1091..422d9c5c6 100644 --- a/lib_dec/acelp_core_dec_ivas_fx.c +++ b/lib_dec/acelp_core_dec_ivas_fx.c @@ -133,8 +133,6 @@ ivas_error acelp_core_dec_ivas_fx( Word16 *old_exc_s_fx; /* Start of last excitation frame */ Word16 *p_tdm_Pri_pitch_buf_fx; Word16 local_element_mode; - Word16 tmp_e = 0; - move16(); ivas_error error; Word32 bpf_error_signal_fx[L_FRAME16k]; @@ -158,9 +156,10 @@ ivas_error acelp_core_dec_ivas_fx( } push_wmops( "acelp_core_dec" ); - tmp = BASOP_Util_Divide3232_Scale( st->output_Fs, FRAMES_PER_SEC, &tmp_e ); - output_frame = shr( tmp, sub( 15, tmp_e ) ); - // output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); + + /* output_frame = (int16_t) ( st->output_Fs / FRAMES_PER_SEC ); */ + output_frame = extract_l( Mpy_32_32( st->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + /*----------------------------------------------------------------* * stereo SID and CNG frames processing *----------------------------------------------------------------*/ diff --git a/lib_dec/cng_dec_fx.c b/lib_dec/cng_dec_fx.c index d6b5984a6..cfaf7af5e 100644 --- a/lib_dec/cng_dec_fx.c +++ b/lib_dec/cng_dec_fx.c @@ -1530,11 +1530,11 @@ void td_cng_dec_init_ivas_fx( { IF( NE_16( st->element_mode, EVS_MONO ) ) { - hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( add( i, 1 ), 1 ), LPC_SHB_ORDER + 1 ); + hTdCngDec->lsp_shb_prev_fx[i] = ivas_lsp_shb_prev_tbl_fx[i]; } ELSE { - hTdCngDec->lsp_shb_prev_fx[i] = div_s( shr( i, 1 ), LPC_SHB_ORDER ); + hTdCngDec->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; } hTdCngDec->lsp_shb_prev_prev_fx[i] = hTdCngDec->lsp_shb_prev_fx[i]; move16(); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index cc2de5052..ca3f1dca6 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1784,11 +1784,9 @@ void decoder_tcx_post_ivas_fx( Decoder_State *st_fx, } ELSE IF( GT_16( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) { - Word16 tmp, q_tmp; - tmp = BASOP_Util_Divide1616_Scale( sub( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ), MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN, &q_tmp ); - q_tmp = sub( 15, q_tmp ); - gainCNG = extract_l( L_shr( L_mult0( gainCNG, sub( shl( 1, q_tmp ), tmp ) ), q_tmp ) ); // gainCNG *= 1.f - (float) sub( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; + tmp32 = L_sub( ONE_IN_Q31, imult3216( 107374182 /* 1 / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN in Q31*/, sub( st_fx->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) ); /* Q31 */ + gainCNG = extract_l( Mpy_32_32( gainCNG, tmp32 ) ); } } } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index 8849f7b63..c3cf2f0ab 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1780,11 +1780,9 @@ void con_tcx_ivas_fx( } ELSE IF( GT_16( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) { - Word16 tmp, q_tmp; - tmp = BASOP_Util_Divide1616_Scale( sub( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ), MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN, &q_tmp ); - q_tmp = sub( 15, q_tmp ); - gainCNG = extract_l( L_shr( L_mult0( gainCNG, sub( shl( 1, q_tmp ), tmp ) ), q_tmp ) ); // gainCNG *= 1.f - (float)(st->nbLostCmpt - MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME) / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN; + L_tmp = L_sub( ONE_IN_Q31, imult3216( 107374182 /* 1 / MDCT_ST_PLC_FADEOUT_TO_ZERO_LEN in Q31*/, sub( st->nbLostCmpt, MDCT_ST_PLC_FADEOUT_MAX_CONC_FRAME ) ) ); /* Q31 */ + gainCNG = extract_l( Mpy_32_32( gainCNG, L_tmp ) ); } } #endif diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 063a91269..3eca9decd 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -2727,14 +2727,8 @@ void generate_masking_noise_lb_dirac_fx( } } - Word16 exp; - Word16 div1 = BASOP_Util_Divide1616_Scale( negate( scaleTable_cn_dirac[i].scale_ivas ), shl( 10, Q11 ), &exp ); - exp = add( exp, sub( sub( 15, 13 ), sub( 15, 11 ) ) ); - Word32 scale_temp = BASOP_util_Pow2( Mpy_32_16_1( LOG_10_BASE_2, div1 ), add( exp, 2 ), &exp ); - scale_temp = L_sub( scale_temp, L_shl( 1, sub( Q31, exp ) ) ); - scale = L_shl( scale_temp, sub( exp, Q1 ) ); // Q30 - - scale = Mpy_32_32( scale, hFdCngCom->likelihood_noisy_speech_32fx ); // Q30 + scale = L_deposit_h( scaleTable_cn_dirac[i].scale_ivas ); /* Q30 */ + scale = Mpy_32_32( scale, hFdCngCom->likelihood_noisy_speech_32fx ); /* Q30 */ } } @@ -2968,7 +2962,7 @@ void generate_masking_noise_dirac_ivas_fx( } } - scale_fx = L_sub( pow_10_q11[shr( negate( scaleTable_cn_dirac[i].scale_ivas ) / 10, 13 - 7 )], 2048 ); // Q11 + scale_fx = L_shr( scaleTable_cn_dirac[i].scale_ivas, Q3 ); /* Q11 */ scale_fx = Mpy_32_16_1( scale_fx, hFdCngCom->likelihood_noisy_speech ); } } diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index e13071294..20e198bb7 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -131,7 +131,7 @@ void hq_core_dec_fx( { hHQ_core->HqVoicing = 0; move16(); - IF( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) + IF ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { hHQ_core->HqVoicing = 1; move16(); @@ -865,7 +865,7 @@ void ivas_hq_core_dec_fx( } ELSE { - ener_match = div_s( st_fx->bws_cnt1, N_NS2W_FRAMES ); /*Q15*/ + ener_match = imult1616( st_fx->bws_cnt1, ONE_BY_N_NS2W_FRAMES_Q15 ); /*Q15*/ } IF( is_transient ) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 1d3614c37..3124f80a5 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -115,7 +115,7 @@ static void ivas_param_ism_dec_dequant_powrat_fx( { FOR( slot_idx = 0; slot_idx < hParamIsm->nblocks[band_idx]; slot_idx++ ) { - hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( div_s( ( hParamIsm->power_ratios_idx[band_idx][slot_idx] ), ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) ), 1 ), 16384 ); + hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] = add( shr( imult1616( hParamIsm->power_ratios_idx[band_idx][slot_idx], 4681 /* ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ) in Q15 */ ), 1 ), 16384 ); /* Q15 */ move16(); hParamIsmDec->power_ratios_fx[band_idx][slot_idx][1] = sub( 32767, hParamIsmDec->power_ratios_fx[band_idx][slot_idx][0] ); move16(); @@ -978,7 +978,7 @@ ivas_error ivas_param_ism_dec_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { - Word16 i, scale, tmp; + Word16 i; PARAM_ISM_DEC_HANDLE hParamIsmDec; IVAS_OUTPUT_SETUP hOutSetup; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -1025,8 +1025,9 @@ ivas_error ivas_param_ism_dec_open_fx( * set input parameters *-----------------------------------------------------------------*/ - tmp = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &scale ); // FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); - hSpatParamRendCom->slot_size = shr( tmp, 15 - scale ); + /* hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ + hSpatParamRendCom->slot_size = extract_l( L_shr( Mpy_32_32( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ), 4 ) ); + move16(); set_s( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set_s( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; @@ -1034,10 +1035,10 @@ ivas_error ivas_param_ism_dec_open_fx( move16(); hSpatParamRendCom->slots_rendered = 0; move16(); - hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - tmp = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &scale ); - hSpatParamRendCom->num_freq_bands = shr( tmp, 15 - scale ); + /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ + hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); + move16(); hParamIsmDec->hParamIsm->nbands = MAX_PARAM_ISM_NBANDS; diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 2aae1ebfd..85963d371 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -5465,8 +5465,8 @@ ivas_error ivas_jbm_dec_tc_buffer_open_fx( } ELSE { - tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &tmp_e ); - n_samp_full = shr( tmp, sub( 15, tmp_e ) ); // Q0 + /* n_samp_full = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */ + n_samp_full = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); n_samp_residual = 0; move16(); } @@ -5936,19 +5936,18 @@ void ivas_jbm_dec_td_renderers_adapt_subframes( Word16 nMaxSlotsPerSubframe, nSlotsAvailable, tmp, exp, tmp1, tmp2, s1, s2; UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe; - // nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; - tmp = BASOP_Util_Divide3216_Scale( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &exp ); - tmp = shr( tmp, -1 - exp ); + /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; */ + tmp = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp ); nMaxSlotsPerSubframe = shr( tmp, ( 15 - exp ) ); - // nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; + /* nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */ tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp ); nSlotsAvailable = shr( tmp, ( 15 - exp ) ); st_ivas->hTcBuffer->num_slots = nSlotsAvailable; move16(); - // st_ivas->hTcBuffer->n_samples_available = nSlotsAvailable * st_ivas->hTcBuffer->n_samples_granularity; + /* st_ivas->hTcBuffer->n_samples_available = nSlotsAvailable * st_ivas->hTcBuffer->n_samples_granularity; */ st_ivas->hTcBuffer->n_samples_available = i_mult( nSlotsAvailable, st_ivas->hTcBuffer->n_samples_granularity ); nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] ); st_ivas->hTcBuffer->nb_subframes = 0; diff --git a/lib_dec/ivas_lfe_plc_fx.c b/lib_dec/ivas_lfe_plc_fx.c index 7c1d59d5d..25a3444ec 100644 --- a/lib_dec/ivas_lfe_plc_fx.c +++ b/lib_dec/ivas_lfe_plc_fx.c @@ -930,7 +930,7 @@ void ivas_lfe_tdplc_fx( const Word32 *pWindow_coeffs_fx; Word32 output_Fs; Word16 i, fade_len, full_len, dct_len, zero_pad_len, plc_fdel, rec_frame_len; - Word16 fdel_dsf_ratio, prevsynth_q_fx, rec_frame_q, temp, temp_q, idx, exp; + Word16 prevsynth_q_fx, rec_frame_q, temp_q, idx, exp; output_Fs = L_mult0( output_frame, FRAMES_PER_SEC ); fade_len = hLFE->pWindow_state->fade_len; @@ -943,11 +943,10 @@ void ivas_lfe_tdplc_fx( move16(); pWindow_coeffs_fx = hLFE->pWindow_state->pWindow_coeffs_fx; - temp = BASOP_Util_Divide3232_Scale( Mpy_32_32( L_shl( LFE_PLC_FDEL, 22 ), L_shl( output_Fs, 9 ) ), 48000, &temp_q ); - plc_fdel = shr( temp, sub( 15, temp_q ) ); - - temp = BASOP_Util_Divide3232_Scale( output_Fs, 48000, &temp_q ); - rec_frame_len = shl( mult( LFE_PLC_RECLEN_48K, temp ), temp_q ); + /* plc_fdel = (int16_t) ( LFE_PLC_FDEL * output_Fs / 48000 ); */ + plc_fdel = extract_l( Mpy_32_32( output_Fs, 13421773 /* ( LFE_PLC_FDEL / 48000 ) in Q31 */ ) ); + /* rec_frame_len = (int16_t) ( LFE_PLC_RECLEN_48K * output_Fs / 48000 ); */ + rec_frame_len = extract_l( Mpy_32_32_r( output_Fs, 77846282 /* LFE_PLC_RECLEN_48K / 48000 in Q31 */ ) ); Copy32( prevsynth, prevsynth_fx, LFE_PLC_BUFLEN ); exp = L_norm_arr( prevsynth_fx, LFE_PLC_BUFLEN ); @@ -957,8 +956,7 @@ void ivas_lfe_tdplc_fx( recover_samples_fx( hLFE->bfi_count, prevsynth_fx, prevsynth_q_fx, rec_frame_fx, &rec_frame_q ); - fdel_dsf_ratio = shl( div_l( LFE_PLC_FDEL, LFE_PLC_DSF ), 1 ); - set_s( mem_fx, 0, shl( fdel_dsf_ratio, 1 ) ); + set16_fx( mem_fx, 0, 2 * LFE_PLC_FDEL / LFE_PLC_DSF ); Copy_Scale_sig_32_16( prevsynth_fx, prevsynth_16_fx, LFE_PLC_BUFLEN, -16 ); // Q5 = Q21 - Q16 Copy_Scale_sig_32_16( rec_frame_fx, rec_frame_16_fx, LFE_PLC_RECLEN, 0 ); // Q5 diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index a6f797e0a..9dff654ad 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -606,7 +606,7 @@ ivas_error ivas_masa_decode_fx( ivas_error error; Word16 obj; Word16 i, ch, ism_imp; - Word16 dirac_bs_md_write_idx; + Word16 dirac_bs_md_write_idx, tmp; Word32 masa_total_brate; dirac_bs_md_write_idx = 0; @@ -653,10 +653,8 @@ ivas_error ivas_masa_decode_fx( next_bit_pos_orig = st->next_bit_pos; move16(); - Word16 tmp, tmp_e; - tmp = BASOP_Util_Divide3232_Scale( masa_brate, FRAMES_PER_SEC, &tmp_e ); - tmp = shr( tmp, sub( 15, tmp_e ) ); - assert( masa_brate / FRAMES_PER_SEC == tmp ); + /* masa_brate / FRAMES_PER_SEC */ + tmp = extract_l( Mpy_32_32( masa_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( EQ_32( masa_brate, IVAS_SID_5k2 ) ) { @@ -2312,12 +2310,11 @@ static ivas_error init_lfe_synth_data_fx( Word16 bufferSize; Word16 i; Word16 slot_size; - Word16 tmp, tmp_e; /* Ring buffer for the filterbank of the LFE synthesis. * The filterbank is using moving average lowpass filter with the crossover of 120 Hz. */ - tmp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &tmp_e ); - bufferSize = shr( tmp, sub( 15, tmp_e ) ); // Q0 + /* bufferSize = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES ); */ + bufferSize = extract_l( Mpy_32_32_r( output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); IF( ( hMasa->hMasaLfeSynth->lfeSynthRingBuffer_fx = (Word32 *) malloc( bufferSize * sizeof( Word32 ) ) ) == NULL ) { @@ -2376,8 +2373,8 @@ static ivas_error init_lfe_synth_data_fx( hMasa->hMasaLfeSynth->transportGainPrev_fx = MAX_WORD16; move16(); - tmp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC * CLDFB_NO_COL_MAX, &tmp_e ); - slot_size = shr( tmp, sub( 15, tmp_e ) ); // Q0 + /* slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ + slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX ) */ ) ); FOR( i = 0; i < slot_size; i++ ) { @@ -3042,8 +3039,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( sts[0]->bit_stream = bit_stream + num_bits; // num_bits += (int16_t)(st_ivas->hSCE[sce_id]->element_brate / FRAMES_PER_SEC); - tmp = BASOP_Util_Divide3216_Scale( st_ivas->hSCE[sce_id]->element_brate, FRAMES_PER_SEC, &tmp_e ); - tmp = shr( tmp, negate( add( 1, tmp_e ) ) ); + tmp = extract_l( Mpy_32_32( st_ivas->hSCE[sce_id]->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); num_bits = add( num_bits, tmp ); test(); @@ -3086,8 +3082,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( sts[0]->bit_stream = bit_stream + num_bits; // num_bits += (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); - tmp = BASOP_Util_Divide3216_Scale( st_ivas->hCPE[cpe_id]->element_brate, FRAMES_PER_SEC, &tmp_e ); - tmp = shr( tmp, negate( add( 1, tmp_e ) ) ); + tmp = extract_l( Mpy_32_32( st_ivas->hCPE[cpe_id]->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); num_bits = add( num_bits, tmp ); test(); diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 235543277..b8c544a57 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1059,8 +1059,8 @@ ivas_error mct_dec_reconfigure_fx( IF( NE_32( st->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) ) { - tmp = BASOP_Util_Divide3232_Scale( st_ivas->hCPE[cpe_id]->element_brate, FRAMES_PER_SEC, &tmp_exp ); - st->bits_frame_nominal = shr( tmp, sub( 15, tmp_exp ) ); + /* st->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[cpe_id]->element_brate / FRAMES_PER_SEC ); */ + st->bits_frame_nominal = extract_l( Mpy_32_32( st_ivas->hCPE[cpe_id]->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); st->igf = getIgfPresent_fx( st->element_mode, st->bits_frame_nominal * FRAMES_PER_SEC, st->bwidth, st->rf_flag ); // no floating point so directly pluggable move16(); @@ -1074,8 +1074,8 @@ ivas_error mct_dec_reconfigure_fx( } /*Initialize MCT block data */ - tmp = BASOP_Util_Divide1616_Scale( hMCT->nchan_out_woLFE, CPE_CHANNELS, &tmp_exp ); - max_blocks = shr( tmp, sub( 15, tmp_exp ) ); + /* max_blocks = hMCT->nchan_out_woLFE / 2; */ + max_blocks = shr( hMCT->nchan_out_woLFE, 1 ); FOR( n = 0; n < max_blocks; n++ ) { diff --git a/lib_dec/ivas_mct_dec_mct_fx.c b/lib_dec/ivas_mct_dec_mct_fx.c index 9c3dced33..83c66b62e 100644 --- a/lib_dec/ivas_mct_dec_mct_fx.c +++ b/lib_dec/ivas_mct_dec_mct_fx.c @@ -197,8 +197,8 @@ static void applyGlobalILD_fx( { IF( hMCT->lowE_ch[ch] ) { - tmp = BASOP_Util_Divide3216_Scale( L_shl( hMCT->mc_global_ild[ch], Q26 ), SMDCT_ILD_RANGE, &tmp_e ); // Q26 - qratio = L_shr( (Word32) tmp, negate( add( 1, tmp_e ) ) ); + /* qratio = (float) hMCT->mc_global_ild[ch] / SMDCT_ILD_RANGE; */ + qratio = L_shl( hMCT->mc_global_ild[ch], Q26 - SMDCT_GLOBAL_ILD_BITS ); /* Q26 */ } ELSE { diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index d239baccc..01a1e4554 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -951,8 +951,8 @@ void ivas_set_surplus_brate_dec( ism_total_brate_ref = L_add( ism_total_brate_ref, st_ivas->hSCE[n]->element_brate ); } - bits_ism = BASOP_Util_Divide3216_Scale( ism_total_brate_ref, FRAMES_PER_SEC, &tmp ); - bits_ism = shr( bits_ism, negate( add( tmp, 1 ) ) ); // bring down to Q0. + /* bits_ism = (int16_t) ( ism_total_brate_ref / FRAMES_PER_SEC ); */ + bits_ism = extract_l( Mpy_32_32( ism_total_brate_ref, ONE_BY_FRAMES_PER_SEC_Q31 ) ); tmp = 0; move16(); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 5dda982b8..2d985870b 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -1743,10 +1743,10 @@ void ivas_sba_dec_digest_tc_fx( Word32 *decorr_signal[BINAURAL_CHANNELS]; Word32 *p_tc[2 * BINAURAL_CHANNELS]; Word16 q_format = 14; - Word16 exp = 0; move16(); - default_frame = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &exp ); - default_frame = shr( default_frame, sub( Q15, exp ) ); + + /* default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */ + default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); nSamplesLeftForTD = nSamplesForRendering; move16(); diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 44a771249..0bc16f201 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -55,7 +55,7 @@ /* PLC constants */ static const int16_t ivas_spar_dec_plc_num_frames_keep = 9; -static const int16_t ivas_spar_dec_plc_num_frames_fade_out = 9; +// static const int16_t ivas_spar_dec_plc_num_frames_fade_out = 9; static const int16_t ivas_spar_dec_plc_per_frame_ramp_down_gain_dB = 3; static const int16_t ivas_spar_dec_plc_max_num_frames_ramp_down = 33; static const int16_t ivas_spar_dec_plc_spatial_target[IVAS_SPAR_MAX_CH] = { 1, 0, 0, 0, 0, 0, 0, 0 }; @@ -1752,10 +1752,9 @@ void ivas_spar_smooth_md_dtx_fx( Word16 j, k, b, dmx_ch; Word16 ramp_fx; Word32 tar_fx, prev_fx, new_val_fx; - Word16 tmp, tmp_e; - tmp = BASOP_Util_Divide1616_Scale( hMdDec->dtx_md_smoothing_cntr, IVAS_DEFAULT_DTX_CNG_RAMP, &tmp_e ); - ramp_fx = shl_sat( tmp, tmp_e ); /* Q15 */ + /* ramp = (float)hMdDec->dtx_md_smoothing_cntr / IVAS_DEFAULT_DTX_CNG_RAMP; */ + ramp_fx = i_mult_sat( hMdDec->dtx_md_smoothing_cntr, 4096 /* 1 / IVAS_DEFAULT_DTX_CNG_RAMP in Q15 */ ); /* Q15 */ FOR( b = 0; b < num_bands_out; b++ ) { @@ -4121,8 +4120,8 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( Q_gain = sub( 31, exp_gain ); FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { - post_matrix_fx[i] = add( shl( 1, norm_nff ), mult( s_min( mult( shl( num_fade_frames, norm_nff ), div_s( 1, ivas_spar_dec_plc_num_frames_fade_out ) ), shl( 1, norm_nff ) ), shl( sub( ivas_spar_dec_plc_spatial_target[i], 1 ), 15 ) ) ); /*Q=norm_nff*/ - post_matrix_fx[i] = Mult_32_16( gain_fx, (Word16) post_matrix_fx[i] ); /*Q_gain+norm_nff-15*/ + post_matrix_fx[i] = add( shl( 1, norm_nff ), mult( s_min( mult( shl( num_fade_frames, norm_nff ), 3640 /* 1 / ivas_spar_dec_plc_num_frames_fade_out in Q15 */ ), shl( 1, norm_nff ) ), shl( sub( ivas_spar_dec_plc_spatial_target[i], 1 ), 15 ) ) ); /*Q=norm_nff*/ + post_matrix_fx[i] = Mult_32_16( gain_fx, (Word16) post_matrix_fx[i] ); /*Q_gain+norm_nff-15*/ } Q_post_matrix = sub( add( Q_gain, norm_nff ), 15 ); /* apply the post matrix */ diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index 2238d768f..f319c2703 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -1273,13 +1273,8 @@ void stereo_dft_dec_res_fx( } ELSE { - Word16 q_div; /* For first good frame, ola memory contains extended ECU buffer -- need to crossfade instead of OLA */ - step = BASOP_Util_Divide3232_Scale( 1, STEREO_DFT_OVL_8k, &q_div ); - IF( NE_16( q_div, 0 ) ) - { - step = shl( step, q_div ); - } + step = 468; /* 1 / STEREO_DFT_OVL_8k in Q15 */ fac = 0; move16(); FOR( i = 0; i < STEREO_DFT_OVL_8k; i++ ) @@ -3353,11 +3348,11 @@ void stereo_dft_dec_read_BS_fx( /* read number of bands in the bitstream - depends on the audio bandwidth and not to output_Fs */ IF( hStereoDft->frame_sid ) { - NFFT_inner = mult_r( inner_frame_tbl[bwidth], divide1616( STEREO_DFT32MS_N_MAX, L_FRAME48k ) ); + NFFT_inner = imult1616( inner_frame_tbl[bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); } ELSE { - NFFT_inner = mult_r( inner_frame_tbl[st->bwidth], divide1616( STEREO_DFT32MS_N_MAX, L_FRAME48k ) ); + NFFT_inner = imult1616( inner_frame_tbl[st->bwidth], STEREO_DFT32MS_N_MAX / L_FRAME48k ); } /* Use coarse band partition in inactive frames */ diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index f3253d728..514d5c520 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -579,7 +579,7 @@ static void cpy_tcx_ltp_data_fx( const int32_t output_Fs /* i : output sampling rate */ ) { - Word16 sz, e; + Word16 sz; hTcxLtpDecNew->tcxltp_pitch_int_post_prev = hTcxLtpDecOld->tcxltp_pitch_int_post_prev; move16(); hTcxLtpDecNew->tcxltp_pitch_fr_post_prev = hTcxLtpDecOld->tcxltp_pitch_fr_post_prev; @@ -588,12 +588,12 @@ static void cpy_tcx_ltp_data_fx( move16(); hTcxLtpDecNew->tcxltp_filt_idx_prev = hTcxLtpDecOld->tcxltp_filt_idx_prev; move16(); - sz = BASOP_Util_Divide3232_Scale( TCXLTP_MAX_DELAY * output_Fs, 48000, &e ); - sz = shr( sz, sub( 15, e ) ); + /* (int16_t) ( ( TCXLTP_MAX_DELAY * output_Fs ) / 48000 ) */ + sz = extract_l( Mpy_32_32_r( TCXLTP_MAX_DELAY * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); mvs2s( hTcxLtpDecOld->tcxltp_mem_in, hTcxLtpDecNew->tcxltp_mem_in, sz ); // TODO: One of these will be removed later mvl2l( hTcxLtpDecOld->tcxltp_mem_in_32, hTcxLtpDecNew->tcxltp_mem_in_32, sz ); - sz = BASOP_Util_Divide3232_Scale( ( L_FRAME48k * output_Fs ), 48000, &e ); - sz = shr( sz, sub( 15, e ) ); + /* (int16_t) ( ( L_FRAME48k * output_Fs ) / 48000 ) */ + sz = extract_l( Mpy_32_32_r( L_FRAME48k * output_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); mvs2s( hTcxLtpDecOld->tcxltp_mem_out, hTcxLtpDecNew->tcxltp_mem_out, sz ); // TODO: One of these will be removed later mvl2l( hTcxLtpDecOld->tcxltp_mem_out_32, hTcxLtpDecNew->tcxltp_mem_out_32, sz ); diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index c76392ff9..c5d5a39a5 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -1131,8 +1131,8 @@ ivas_error init_encoder_ivas_fx( st->input_buff_fx = st->hSignalBuf->input_buff; set16_fx( st->input_buff_fx, 0, add( L_FRAME48k, add( L_FRAME48k, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ) ) ); st->old_input_signal_fx = st->input_buff_fx; - Word16 temp; - Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); + /* st->input_Fs / FRAMES_PER_SEC */ + Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( EQ_16( st->element_mode, EVS_MONO ) ) { @@ -1694,9 +1694,8 @@ ivas_error init_encoder_ivas_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Transient Detection\n" ) ); } - Word16 temp; - Word16 frame_length = BASOP_Util_Divide3232_Scale( st->input_Fs, FRAMES_PER_SEC, &temp ); - frame_length = shr( frame_length, sub( 15, temp ) ); + /* (int16_t) ( st->input_Fs / FRAMES_PER_SEC ) */ + Word16 frame_length = extract_l( Mpy_32_32( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( GT_16( st->element_mode, EVS_MONO ) ) { diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 25f6959b7..2dc9d607c 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -865,7 +865,7 @@ static void calculate_energy_buffer_fx( Word16 temp_q2 = norm_s( hCPE->hStereoDft->NFFT ); band_res_dft_fx = div_l( L_shl( input_Fs, temp_q1 ), shl( hCPE->hStereoDft->NFFT, temp_q2 ) ); - chan_width_f_fx = div_l( 24000, CLDFB_NO_CHANNELS_MAX ); + chan_width_f_fx = 24000 / CLDFB_NO_CHANNELS_MAX; chan_width_bins_fx = L_shl( (Word32) div_s( chan_width_f_fx, band_res_dft_fx ), ( sub( add( temp_q1, 1 ), temp_q2 ) ) ); // Q16 pDFT_DMX_fx = hCPE->hStereoDft->DFT_fx[0]; @@ -928,7 +928,7 @@ static void calculate_energy_buffer( Word16 temp_q2 = norm_s( hCPE->hStereoDft->NFFT ); band_res_dft_fx = div_l( L_shl( input_Fs, temp_q1 ), shl( hCPE->hStereoDft->NFFT, temp_q2 ) ); - chan_width_f_fx = div_l( 24000, CLDFB_NO_CHANNELS_MAX ); + chan_width_f_fx = 24000 / CLDFB_NO_CHANNELS_MAX; chan_width_bins_fx = L_shl( (Word32) div_s( chan_width_f_fx, band_res_dft_fx ), ( sub( add( temp_q1, 1 ), temp_q2 ) ) ); // Q16 pDFT_DMX = hCPE->hStereoDft->DFT[0]; // to be removed diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 2d48fa86d..aebe83ca1 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -458,8 +458,8 @@ static void stereo_dft_enc_open_fx( Word16 win[STEREO_DFT_OVL_MAX]; /*Sizes*/ - Word16 div_e; - Word16 input_Fs_48k = BASOP_Util_Divide3232_Scale( input_Fs, 48000, &div_e ); + /* input_Fs / 48000 */ + Word16 input_Fs_48k = extract_l( Mpy_32_32( input_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); // input_Fs_48k = shr(input_Fs_48k, sub(15, div_e)); @@ -475,8 +475,8 @@ static void stereo_dft_enc_open_fx( win[STEREO_DFT_OVL_MAX - 1 - i] = win_p[i].v.re; win[i] = win_p[i].v.im; } - hStereoDft->win_ana_energy_fx = sub( hStereoDft->N, hStereoDft->dft_ovl ); // e = div_e - hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, sub( 15, div_e ) ); // Q = 15 + hStereoDft->win_ana_energy_fx = sub( hStereoDft->N, hStereoDft->dft_ovl ); // e = div_e + hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); // Q = 15 hStereoDft->win_ana_energy_fx = add( hStereoDft->win_ana_energy_fx, shl( sum_s( win, hStereoDft->dft_ovl ), 1 ) ); // Q = 15 hStereoDft->win_ana_energy_fx = shr( hStereoDft->win_ana_energy_fx, 15 ); @@ -534,11 +534,8 @@ static void stereo_dft_enc_open_fx( set_zero_fx( hStereoDft->output_mem_res_8k_fx, STEREO_DFT_OVL_8k ); /*Bands: find the number of bands, Nyquist freq. is not taken into account*/ - - Word16 inner_frame_tbl_L_frame = BASOP_Util_Divide1616_Scale( inner_frame_tbl[max_bwidth], L_FRAME48k, &div_e ); - inner_frame_tbl_L_frame = shr( inner_frame_tbl_L_frame, sub( 15, div_e ) ); - - NFFT_inner = i_mult( STEREO_DFT_N_MAX_ENC, inner_frame_tbl_L_frame ); + /* NFFT_inner = STEREO_DFT_N_MAX_ENC * inner_frame_tbl[max_bwidth] / L_FRAME48k; */ + NFFT_inner = imult1616( inner_frame_tbl[max_bwidth], STEREO_DFT_N_MAX_ENC / L_FRAME48k ); hStereoDft->nbands = stereo_dft_band_config_fx( hStereoDft->band_limits, hStereoDft->hConfig->band_res, NFFT_inner, ENC ); hStereoDft->nbands_dmx = stereo_dft_band_config_fx( hStereoDft->band_limits_dmx, 1, NFFT_inner, ENC ); diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc.c b/lib_enc/ivas_stereo_mdct_stereo_enc.c index 62206ccc3..1c6aa5e86 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc.c @@ -115,9 +115,8 @@ static void dft_ana_init_fx( ) { Word16 div1; - Word16 div_e; - div1 = BASOP_Util_Divide3232_Scale( input_Fs, 48000, &div_e ); - div1 = shr( div1, sub( 15, div_e ) ); + /* input_Fs / 48000 */ + div1 = extract_l( Mpy_32_32_r( input_Fs, 44739 /* 1 / 48000 in Q31 */ ) ); hDft_ana->N = i_mult( STEREO_DFT_HOP_MAX_ENC, div1 ); hDft_ana->NFFT = i_mult( STEREO_DFT_N_MAX_ENC, div1 ); diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index 3f345bc5f..c50a45f7b 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -3086,7 +3086,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, scale; + Word16 nchan_in, nchan_out; const Word32 *pIn; Word32 *pFreq_buf_re, *pFreq_buf_im; const Word32 *pFreq_filt_re, *pFreq_filt_im; @@ -3109,8 +3109,8 @@ static ivas_error ivas_rend_crendConvolver( return error; } - subframe_length = (Word16) BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &scale ); - subframe_length = shr( subframe_length, 15 - scale ); + /* subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; */ + subframe_length = extract_l( Mpy_32_32_r( output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); lfe_idx_in = -1; move16(); diff --git a/lib_rend/ivas_dirac_ana.c b/lib_rend/ivas_dirac_ana.c index 19cbbfe59..8e52a997a 100644 --- a/lib_rend/ivas_dirac_ana.c +++ b/lib_rend/ivas_dirac_ana.c @@ -477,10 +477,8 @@ static void ivas_dirac_param_est_ana_fx( Word16 exp = 0, exp_div = 0; // Word16 exp2; num_freq_bands = hDirAC->nbands; - Word16 tmp_e; - Word16 tmp = BASOP_Util_Divide3216_Scale( input_frame, CLDFB_NO_COL_MAX, &tmp_e ); - tmp = shr( tmp, negate( add( 1, tmp_e ) ) ); - l_ts = tmp; + /* l_ts = input_frame / CLDFB_NO_COL_MAX; */ + l_ts = shr( input_frame, 4 ); numAnalysisChannels = FOA_CHANNELS; move16(); move16(); diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 8ae785ac5..f999f8919 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -137,6 +137,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( uint16_t num_diffuse_responses; Word16 tmp_fx; Word16 temp_alpha_synthesis_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 interpolator_tbl[JBM_CLDFB_SLOTS_IN_SUBFRAME] = { 8192, 16384, 24576, MAX16B }; /* idx / JBM_CLDFB_SLOTS_IN_SUBFRAME Q15 */ /* pointers to structs for allocation */ DIRAC_OUTPUT_SYNTHESIS_PARAMS *dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); @@ -337,7 +338,8 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( /* compute interpolator */ FOR( idx = 1; idx <= JBM_CLDFB_SLOTS_IN_SUBFRAME; ++idx ) { - dirac_output_synthesis_params->interpolator_fx[idx - 1] = div_s( idx, JBM_CLDFB_SLOTS_IN_SUBFRAME ); + dirac_output_synthesis_params->interpolator_fx[idx - 1] = interpolator_tbl[idx - 1]; /* Q15 */ + move16(); } /* prepare diffuse response function */ diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 6cb2491d7..eadb0f81d 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -361,21 +361,11 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( *hSpatParamRendCom_out = hSpatParamRendCom; } - Word16 tmp1, tmp2, var1, var2; - - Word16 exp_tmp1 = 0; - move16(); - tmp1 = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &exp_tmp1 ); - Word16 exp_tmp2 = 0; - move16(); - tmp2 = BASOP_Util_Divide1616_Scale( tmp1, CLDFB_NO_COL_MAX, &exp_tmp2 ); - exp_tmp2 = add( exp_tmp2, sub( exp_tmp1, 15 ) ); - Word16 exp_tmp3 = 0; - move16(); - IF( EQ_32( flag_config, DIRAC_OPEN ) ) { - hSpatParamRendCom->slot_size = shr( tmp2, 15 - exp_tmp2 ); // exp_tmp2 + /* hSpatParamRendCom->slot_size = (int16_t) ( ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX ); */ + hSpatParamRendCom->slot_size = extract_l( Mpy_32_32( output_Fs, 2684355 /* 1 / ( FRAMES_PER_SEC * CLDFB_NO_COL_MAX) in Q31 */ ) ); + move16(); set16_fx( hSpatParamRendCom->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set16_fx( hSpatParamRendCom->subframe_nbslots, JBM_CLDFB_SLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); hSpatParamRendCom->nb_subframes = DEFAULT_JBM_SUBFRAMES_5MS; @@ -385,9 +375,9 @@ ivas_error ivas_spat_hSpatParamRendCom_config_fx( hSpatParamRendCom->slots_rendered = 0; move16(); hSpatParamRendCom->num_slots = DEFAULT_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME; - var1 = BASOP_Util_Divide3232_Scale( output_Fs, CLDFB_BANDWIDTH, &exp_tmp3 ); - var2 = shl( 1, sub( 15, add( exp_tmp3, 1 ) ) ); - hSpatParamRendCom->num_freq_bands = shr( add( var1, var2 ), sub( 15, exp_tmp3 ) ); + /* hSpatParamRendCom->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ + hSpatParamRendCom->num_freq_bands = extract_l( Mpy_32_32( output_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); + move16(); hSpatParamRendCom->numSimultaneousDirections = 0; move16(); hSpatParamRendCom->numParametricDirections = 0; @@ -2949,15 +2939,15 @@ void protoSignalComputation2_fx( { IF( EQ_16( stereo_type_detect->type_change_direction, MASA_STEREO_SPACED_MICS ) ) { - interpolatorSpaced_fx = BASOP_Util_Divide1616_Scale( stereo_type_detect->interpolator, MASA_STEREO_INTERPOLATION_SLOTS, &exp ); - interpolatorSpaced_fx = shl( interpolatorSpaced_fx, exp ); // Q15 - interpolatorDmx_fx = sub( MAX16B, interpolatorSpaced_fx ); // Q15 + /* interpolatorSpaced = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); */ + interpolatorSpaced_fx = i_mult_sat( stereo_type_detect->interpolator, 2048 /* 1 / MASA_STEREO_INTERPOLATION_SLOTS in Q15 */ ); /* Q15 */ + interpolatorDmx_fx = sub( MAX16B, interpolatorSpaced_fx ); /* Q15 */ } ELSE { - interpolatorDmx_fx = BASOP_Util_Divide1616_Scale( stereo_type_detect->interpolator, MASA_STEREO_INTERPOLATION_SLOTS, &exp ); - interpolatorDmx_fx = shl( interpolatorDmx_fx, exp ); // Q15 - interpolatorSpaced_fx = sub( MAX16B, interpolatorDmx_fx ); // Q15 + /* interpolatorDmx = ( (float) ( stereo_type_detect->interpolator ) ) / ( (float) MASA_STEREO_INTERPOLATION_SLOTS ); */ + interpolatorDmx_fx = i_mult_sat( stereo_type_detect->interpolator, 2048 /* 1 / MASA_STEREO_INTERPOLATION_SLOTS in Q15 */ ); /* Q15 */ + interpolatorSpaced_fx = sub( MAX16B, interpolatorDmx_fx ); /* Q15 */ } } @@ -4533,7 +4523,6 @@ void ivas_masa_stereotype_detection_fx( Word32 min_sum_temp_fx; Word32 lr_total_bb_temp_fx; Word32 lr_total_hi_temp_fx; - Word16 exp; Word32 temp; lr_total_bb_ratio_db_fx = stereo_type_detect->lr_total_bb_ratio_db_fx; @@ -4544,26 +4533,25 @@ void ivas_masa_stereotype_detection_fx( move32(); subtract_target_ratio_db_fx = stereo_type_detect->subtract_target_ratio_db_fx; move32(); - exp = 0; - move16(); /* Determine if the determined features match the spaced mic type */ change_to_spaced_selection = 0; move16(); IF( LT_32( subtract_target_ratio_db_fx, -THREE_Q21 ) ) { + /* subtract_temp = ( -subtract_target_ratio_db - 3.0f ) / 3.0f; */ temp = L_sub( L_shr( -subtract_target_ratio_db_fx, 1 ), L_shr( THREE_Q21, 1 ) ); - subtract_temp_fx = BASOP_Util_Divide3232_Scale( temp, THREE_Q21, &exp ); - subtract_temp_fx = L_shl( subtract_temp_fx, add( exp, 1 ) ); // Q15 + subtract_temp_fx = Mpy_32_32( temp, 715827883 /* 1 / 3.0f in Q31 */ ); + subtract_temp_fx = L_shl( subtract_temp_fx, 1 ); /* Q21 */ - min_sum_temp_fx = BASOP_Util_Divide3232_Scale( -min_sum_total_ratio_db_fx, SIX_Q21, &exp ); - min_sum_temp_fx = L_shl( min_sum_temp_fx, exp ); // Q15 + /* min_sum_temp = max( -min_sum_total_ratio_db / 6.0f, 0.0f ); */ + min_sum_temp_fx = Mpy_32_32_r( -min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ min_sum_temp_fx = L_max( min_sum_temp_fx, 0 ); - lr_total_bb_temp_fx = BASOP_Util_Divide3232_Scale( lr_total_bb_ratio_db_fx, SIX_Q21, &exp ); - lr_total_bb_temp_fx = L_shl( lr_total_bb_temp_fx, exp ); // Q15 + /* lr_total_bb_temp = lr_total_bb_ratio_db / 6.0f; */ + lr_total_bb_temp_fx = Mpy_32_32_r( lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ - change_to_spaced_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); // Q15 + change_to_spaced_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */ IF( GE_32( change_to_spaced_fx, ONE_IN_Q15 ) ) { @@ -4577,16 +4565,16 @@ void ivas_masa_stereotype_detection_fx( move16(); IF( GT_32( subtract_target_ratio_db_fx, 0 ) ) { - subtract_temp_fx = BASOP_Util_Divide3232_Scale( subtract_target_ratio_db_fx, THREE_Q21, &exp ); - subtract_temp_fx = L_shl( subtract_temp_fx, exp ); // Q15 + /* subtract_temp = subtract_target_ratio_db / 3.0f; */ + subtract_temp_fx = Mpy_32_32( subtract_target_ratio_db_fx, 715827883 /* 1 / 3.0f in Q31 */ ); /* Q21 */ - min_sum_temp_fx = BASOP_Util_Divide3232_Scale( L_add( min_sum_total_ratio_db_fx, ONE_IN_Q21 ), SIX_Q21, &exp ); - min_sum_temp_fx = L_shl( min_sum_temp_fx, exp ); // Q15 + /* min_sum_temp = ( min_sum_total_ratio_db + 1.0f ) / 6.0f; */ + min_sum_temp_fx = Mpy_32_32_r( L_add( min_sum_total_ratio_db_fx, ONE_IN_Q21 ), 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ - lr_total_bb_temp_fx = BASOP_Util_Divide3232_Scale( -lr_total_bb_ratio_db_fx, SIX_Q21, &exp ); - lr_total_bb_temp_fx = L_shl( lr_total_bb_temp_fx, exp ); // Q15 + /* lr_total_bb_temp = -lr_total_bb_ratio_db / 6.0f; */ + lr_total_bb_temp_fx = Mpy_32_32_r( -lr_total_bb_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); /* Q21 */ - change_to_downmix_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); // Q15 + change_to_downmix_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_bb_temp_fx ); /* Q21 */ IF( GE_32( change_to_downmix_fx, ONE_IN_Q15 ) ) { @@ -4598,15 +4586,14 @@ void ivas_masa_stereotype_detection_fx( /* Determine if the determined features match the downmix type, according to another metric */ IF( LT_32( lr_total_hi_ratio_db_fx, -25165824 ) ) // 25165824 = 12.0 in Q21 { - // 8388608 = 4.0 in Q21 - subtract_temp_fx = BASOP_Util_Divide3232_Scale( L_add( subtract_target_ratio_db_fx, 8388608 ), THREE_Q21, &exp ); - subtract_temp_fx = L_shl( subtract_temp_fx, exp ); // Q15 + /* subtract_temp = ( subtract_target_ratio_db + 4.0f ) / 3.0f; */ + subtract_temp_fx = Mpy_32_32( L_add( subtract_target_ratio_db_fx, 8388608 /* 4.0 in Q21 */ ), 715827883 /* 1 / 3.0f in Q31 */ ); - min_sum_temp_fx = BASOP_Util_Divide3232_Scale( min_sum_total_ratio_db_fx, THREE_Q21, &exp ); - min_sum_temp_fx = L_shl( min_sum_temp_fx, exp ); // Q15 + /* min_sum_temp = min_sum_total_ratio_db / 6.0f; */ + min_sum_temp_fx = Mpy_32_32_r( min_sum_total_ratio_db_fx, 357913941 /* 1 / 6.0f in Q31 */ ); - lr_total_hi_temp_fx = BASOP_Util_Divide3232_Scale( L_sub( -lr_total_hi_ratio_db_fx, 25165824 ), THREE_Q21, &exp ); // 25165824 = 12.0 in Q21 - lr_total_hi_temp_fx = L_shl( lr_total_hi_temp_fx, exp ); // Q15 + /* lr_total_hi_temp = ( -lr_total_hi_ratio_db - 12.0f ) / 3.0f; */ + lr_total_hi_temp_fx = Mpy_32_32( L_sub( -lr_total_hi_ratio_db_fx, 25165824 /* 12.0 in Q21 */ ), 715827883 /* 1 / 3.0f in Q31 */ ); change_to_downmix2_fx = L_add( L_add( subtract_temp_fx, min_sum_temp_fx ), lr_total_hi_temp_fx ); // Q15 diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 37be6a48a..3632adde4 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -4453,24 +4453,9 @@ static void sph2cart_fx( ) { Word16 azi_temp, ele_temp; - IF( GE_32( azi, 0 ) ) - { - azi_temp = div_l( L_shr( azi, Q6 ), 360 ); - } - ELSE - { - azi_temp = div_l( L_negate( L_shr( azi, Q6 ) ), 360 ); - azi_temp = negate( azi_temp ); - } - IF( GE_32( ele, 0 ) ) - { - ele_temp = div_l( L_shr( ele, Q6 ), 360 ); - } - ELSE - { - ele_temp = div_l( L_negate( L_shr( ele, Q6 ) ), 360 ); - ele_temp = negate( ele_temp ); - } + + azi_temp = extract_l( L_shr( Mpy_32_32( azi, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ + ele_temp = extract_l( L_shr( Mpy_32_32( ele, ONE_BY_360_Q31 ), Q7 ) ); /* Q15 */ pos[0] = Mpy_32_16( getCosWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); pos[1] = Mpy_32_16( getSineWord16R2( azi_temp ), 0, getCosWord16R2( ele_temp ) ); diff --git a/lib_rend/ivas_limiter.c b/lib_rend/ivas_limiter.c index e7b2153dc..4d42d645c 100644 --- a/lib_rend/ivas_limiter.c +++ b/lib_rend/ivas_limiter.c @@ -350,8 +350,7 @@ static Word16 detect_strong_saturations_fx( { IF( LT_32( *frame_gain, 322122547 ) ) // Q30 of 0.3 is compared { - //*frame_gain /= 3.0f; - *frame_gain = L_shl( divide3216( *frame_gain, 24576 ), 14 ); // Q30 + *frame_gain = Mpy_32_16_1( *frame_gain, 10923 /* 1/3 in Q15 */ ); // Q30 } ELSE { @@ -421,7 +420,7 @@ ivas_error ivas_limiter_open( assert( 0 ); } - hLimiter->attack_constant_fx = attack_cnst_fx; + hLimiter->attack_constant_fx = attack_cnst_fx; /* Q31 */ hLimiter->strong_saturation_count = 0; for ( i = 0; i < max_num_channels; ++i ) @@ -650,7 +649,7 @@ void limiter_process_fx( output = hLimiter->channel_ptrs_fx; num_channels = hLimiter->num_channels; // sampling_rate = hLimiter->sampling_rate; - attack_constant = hLimiter->attack_constant_fx; + attack_constant = hLimiter->attack_constant_fx; /* Q31 */ /*-----------------------------------------------------------------* * Find highest absolute peak sample value *-----------------------------------------------------------------*/ diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index e244107e8..70a9cad10 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -1045,10 +1045,9 @@ ivas_error TDREND_Update_object_positions_fx( IF( hIsmMetaData[nS]->non_diegetic_flag ) { - Word16 tmp, tmp_e; Pos_fx[0] = 0; - tmp = BASOP_Util_Divide3232_Scale( hIsmMetaData[nS]->azimuth_fx, 377487360 /* 90.f in Q22 */, &tmp_e ); - Pos_fx[1] = shr( tmp, sub( 6, tmp_e ) ); // Q25 + /* Pos[1] = hIsmMetaData[nS]->azimuth / 90.f; */ + Pos_fx[1] = L_shl( Mpy_32_32_r( hIsmMetaData[nS]->azimuth_fx, 23860929 /* 1 / 90.f in Q31 */ ), Q3 ); /* Q25 */ Pos_fx[2] = 0; IF( ( error = TDREND_MIX_SRC_SetPos_fx( hBinRendererTd, nS, Pos_fx ) ) != IVAS_ERR_OK ) diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index b83e6cb5e..f5aa07318 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -124,8 +124,8 @@ ivas_error ivas_omasa_ana_open( /* Determine band grouping */ mvs2s( MASA_band_grouping_24, hOMasa->band_grouping, 24 + 1 ); - maxBin = (Word16) BASOP_Util_Divide3232_Scale( input_Fs, 800, &scale ); - maxBin = shr( maxBin, sub( 15, scale ) ); + /* maxBin = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ + maxBin = extract_l( Mpy_32_32( input_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); FOR( i = 1; i < hOMasa->nbands + 1; i++ ) { @@ -193,10 +193,8 @@ ivas_error ivas_omasa_ana_open( set32_fx( hOMasa->prev_object_dm_gains_fx[i], INV_SQRT_2_Q31, MASA_MAX_TRANSPORT_CHANNELS ); } - input_frame = BASOP_Util_Divide3232_Scale( input_Fs, FRAMES_PER_SEC, &scale ); - input_frame = shr( input_frame, sub( 15, scale ) ); - - + /* input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); */ + input_frame = extract_l( Mpy_32_32( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); FOR( i = 0; i < input_frame; i++ ) { hOMasa->interpolator_fx[i] = BASOP_Util_Divide1616_Scale( i, input_frame, &scale ); diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index 6b7afe97f..35752d092 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -396,8 +396,8 @@ static void ivas_binaural_reverb_setReverbTimes_fx( Word32 binCenterFreq_fx, diffuseFieldICC_fx, tmpVal_fx, attenuationFactorPerSample_fx, L_tmp; Word32 intendedEnergy_fx, actualizedEnergy_fx, energyBuildup_fx, currentEnergy_fx, attenuationFactorPerSampleSq_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 tmp, tmp_exp, scale, tmpVal_exp, attenuationFactorPerSample_exp, attenuationFactorPerSampleSq_exp, energyBuildup_exp, currentEnergy_exp, intendedEnergy_exp, actualizedEnergy_exp; + Word16 sine_inp, norm, div_exp1, div1, sine, binCenterFreq_exp; Word16 reverb_exp = 0; move16(); @@ -417,36 +417,34 @@ static void ivas_binaural_reverb_setReverbTimes_fx( binCenterFreq_fx = L_shr( L_tmp, 1 ); // divide by 2 IF( EQ_16( bin, 0 ) ) { - diffuseFieldICC_fx = 1073741824; // 2 ^ 30, Q30 + diffuseFieldICC_fx = ONE_IN_Q31; 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 = add( scale, sub( binCenterFreq_exp, 31 ) ); + /* binCenterFreq / 550.0f */ + L_tmp = Mpy_32_32( binCenterFreq_fx, 3904516 /* 1 / 550 in Q31 */ ); + norm = norm_l( L_tmp ); + tmp = extract_h( L_shl( L_tmp, norm ) ); tmp = add( mult( EVS_PI_FX, tmp ), EPSILLON_FX ); // to avoid divide by 0 issue - tmp_exp = add( exp, 2 ); + tmp_exp = sub( add( binCenterFreq_exp, 2 ), norm ); 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 = add( scale, sub( 0, tmp_exp ) ); + div1 = shl( div1, div_exp1 ); /* Q15 */ - tmp = BASOP_Util_Divide3232_Scale( binCenterFreq_fx, 2700, &scale ); - scale = add( scale, sub( binCenterFreq_exp, 31 ) ); - - L_tmp = L_sub( L_shl( 1, sub( 15, scale ) ), tmp ); + /* binCenterFreq / 2700.0f */ + L_tmp = Mpy_32_32( binCenterFreq_fx, 795364 /* 1 / 2700 in Q31 */ ); norm = norm_l( L_tmp ); + L_tmp = L_shl( L_tmp, norm ); /* Q31 */ - L_tmp = L_shl( L_tmp, norm ); - sub_res = extract_h( L_tmp ); - sub_exp = sub( scale, sub( norm, 16 ) ); + /* ( 1.0f - binCenterFreq / 2700.0f ) */ + L_tmp = L_sub( ONE_IN_Q31, L_tmp ); /* Q31 */ - diffuseFieldICC_fx = L_deposit_h( mult( sub_res, div1 ) ); - diffuseFieldICC_exp = add( div_exp1, sub_exp ); + diffuseFieldICC_fx = Mpy_32_16_1( L_tmp, div1 ); /* Q31 */ hReverb->highestBinauralCoherenceBin = bin; move16(); @@ -456,18 +454,20 @@ static void ivas_binaural_reverb_setReverbTimes_fx( diffuseFieldICC_fx = 0; move32(); - diffuseFieldICC_exp = 0; - move16(); } /* Mixing gains to generate a diffuse-binaural sound based on incoherent sound */ - + /* tmpVal = ( 1.0f - sqrtf( 1.0f - powf( diffuseFieldICC, 2.0 ) ) ) / 2.0f; */ L_tmp = Mpy_32_32( diffuseFieldICC_fx, diffuseFieldICC_fx ); // square - L_tmp = BASOP_Util_Add_Mant32Exp( 1073741824, 1, L_negate( L_tmp ), diffuseFieldICC_exp + diffuseFieldICC_exp, &scale ); + L_tmp = L_sub( ONE_IN_Q31, L_tmp ); + scale = 0; L_tmp = Sqrt32( L_tmp, &scale ); - tmpVal_fx = L_shr( BASOP_Util_Add_Mant32Exp( 1073741824, 1, L_negate( L_tmp ), scale, &tmpVal_exp ), 1 ); + L_tmp = L_shl( L_tmp, scale ); /* Q31 */ + tmpVal_fx = L_shr( L_sub( ONE_IN_Q31, L_tmp ), 1 ); + tmpVal_exp = 0; + move16(); - IF( BASOP_Util_Cmp_Mant32Exp( diffuseFieldICC_fx, diffuseFieldICC_exp, 0, 0 ) == 1 ) + IF( diffuseFieldICC_fx > 0 ) { exp = tmpVal_exp; L_tmp = Sqrt32( L_abs( tmpVal_fx ), &exp ); @@ -480,12 +480,13 @@ static void ivas_binaural_reverb_setReverbTimes_fx( hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_negate( L_shl( L_tmp, exp ) ); // Q31 } + /* hReverb->binauralCoherenceDirectGains[bin] = sqrtf( 1.0f - fabsf( tmpVal ) ); */ exp = tmpVal_exp; - L_tmp = BASOP_Util_Add_Mant32Exp( 1073741824, 1, L_negate( L_abs( tmpVal_fx ) ), tmpVal_exp, &exp ); + L_tmp = L_sub( ONE_IN_Q31, L_abs( tmpVal_fx ) ); L_tmp = Sqrt32( L_abs( L_tmp ), &exp ); hReverb->binauralCoherenceDirectGains_fx[bin] = L_shl( L_tmp, exp ); // making as Q31 - /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ + /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ L_tmp = Mpy_32_32( 1677721600, revTimes_fx[bin] ); // e10 --> 800 * 2^21, + e0 tmp = BASOP_Util_Divide3232_Scale( 1073741824, L_tmp, &scale ); scale = add( scale, sub( 1, 10 ) ); diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 0f452810b..5290f0abb 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -2056,8 +2056,6 @@ ivas_error ivas_combined_orientation_open( { Word16 i; Word16 j; - Word16 tmp_e = 0, tmp; - move16(); IVAS_QUATERNION identity; IVAS_VECTOR3 origo; identity.w_fx = ONE_IN_Q31; @@ -2153,10 +2151,9 @@ ivas_error ivas_combined_orientation_open( ( *hCombinedOrientationData )->subframe_idx = 0; move16(); - tmp = BASOP_Util_Divide3232_Scale( fs, MAX_PARAM_SPATIAL_SUB_FRAMES_PER_SEC, &tmp_e ); - ( *hCombinedOrientationData )->subframe_size = shr( tmp, sub( 15, tmp_e ) ); + /* ( *hCombinedOrientationData )->subframe_size = (int16_t) ( fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); */ + ( *hCombinedOrientationData )->subframe_size = extract_l( Mpy_32_32_r( fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) ); move16(); - // ( *hCombinedOrientationData )->subframe_size = (int16_t) ( fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); ( *hCombinedOrientationData )->cur_subframe_samples_rendered = 0; move16(); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 87b4f6d36..a44a5077a 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -2249,11 +2249,11 @@ typedef struct Word32 **channel_ptrs_fx; Word32 sampling_rate; // float gain; - Word32 gain_fx; + Word32 gain_fx; /* Q30 */ // float release_heuristic; - Word32 release_heuristic_fx; + Word32 release_heuristic_fx; /* Q30 */ // float attack_constant; - Word32 attack_constant_fx; + Word32 attack_constant_fx; /* Q31 */ Word16 strong_saturation_count; } IVAS_LIMITER, *IVAS_LIMITER_HANDLE; diff --git a/lib_rend/ivas_vbap.c b/lib_rend/ivas_vbap.c index 7a51c4aa8..a69c70609 100644 --- a/lib_rend/ivas_vbap.c +++ b/lib_rend/ivas_vbap.c @@ -1645,15 +1645,8 @@ static enum VirtualSpeakerNodeType check_need_of_virtual_speaker_node_fx( IF( EQ_16( Flag1, (Word16) -1 ) ) { Word16 azi_temp; - IF( GE_32( speaker_node_azi_deg_fx[ch], 0 ) ) - { - azi_temp = div_l( L_shr( speaker_node_azi_deg_fx[ch], Q7 ), 180 ); - } - ELSE - { - azi_temp = div_l( L_negate( L_shr( speaker_node_azi_deg_fx[ch], Q7 ) ), 180 ); - azi_temp = negate( azi_temp ); - } + + azi_temp = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); /* Q15 */ Word16 cos_res = getCosWord16R2( azi_temp ); // Q15 @@ -1834,15 +1827,7 @@ static void init_speaker_node_direction_data_fx( speaker_node_data[ch].azi_deg_fx = speaker_node_azi_deg_fx[ch]; move32(); - IF( GE_32( speaker_node_azi_deg_fx[ch], 0 ) ) - { - azi_rad_fx = div_l( L_shr( speaker_node_azi_deg_fx[ch], Q7 ), 180 ); - } - ELSE - { - azi_rad_fx = div_l( L_negate( L_shr( speaker_node_azi_deg_fx[ch], Q7 ) ), 180 ); - azi_rad_fx = negate( azi_rad_fx ); - } + azi_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_azi_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); test(); IF( GE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), -5 ) && LE_32( L_shr( speaker_node_ele_deg_fx[ch], 22 ), 5 ) ) { @@ -1858,15 +1843,7 @@ static void init_speaker_node_direction_data_fx( { speaker_node_data[ch].ele_deg_fx = speaker_node_ele_deg_fx[ch]; move32(); - IF( GE_32( speaker_node_ele_deg_fx[ch], 0 ) ) - { - ele_rad_fx = div_l( L_shr( speaker_node_ele_deg_fx[ch], Q7 ), 180 ); - } - ELSE - { - ele_rad_fx = div_l( L_negate( L_shr( speaker_node_ele_deg_fx[ch], Q7 ) ), 180 ); - ele_rad_fx = negate( ele_rad_fx ); - } + ele_rad_fx = extract_l( L_shr( Mpy_32_32( speaker_node_ele_deg_fx[ch], ONE_BY_180_Q31 ), Q8 ) ); IF( LT_16( ele_rad_fx, 0 ) ) { diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index a29613c09..88706683c 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -174,7 +174,7 @@ typedef struct OMASA_ANA_HANDLE hOMasa; uint16_t total_num_objects; #ifdef IVAS_FLOAT_FIXED - Word32 ism_metadata_delay_ms_fx; + Word32 ism_metadata_delay_ms_fx; /* Q0 */ #else float ism_metadata_delay_ms; #endif @@ -8955,7 +8955,7 @@ static ivas_error renderIsmToBinaural( Word16 exp = *outAudio.pq_fact; push_wmops( "renderIsmToBinaural" ); /* Metadata Delay to sync with audio delay converted from ms to 5ms (1000/50/4) subframe index */ - ism_md_subframe_update_ext = div_l( ismInput->ism_metadata_delay_ms_fx, ( 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ) ); + ism_md_subframe_update_ext = extract_l( Mpy_32_32( ismInput->ism_metadata_delay_ms_fx, 429496730 /* 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES in Q31 */ ) ); copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpTDRendBuffer ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) @@ -9412,7 +9412,7 @@ static ivas_error renderIsmToBinauralReverb( push_wmops( "renderIsmToBinauralRoom" ); /* Metadata Delay to sync with audio delay converted from ms to 5ms (1000/50/4) subframe index */ - ism_md_subframe_update_ext = div_l( ismInput->ism_metadata_delay_ms_fx, ( 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES ) ); + ism_md_subframe_update_ext = extract_l( Mpy_32_32( ismInput->ism_metadata_delay_ms_fx, 429496730 /* 1000 / FRAMES_PER_SEC / MAX_PARAM_SPATIAL_SUBFRAMES in Q31 */ ) ); copyBufferTo2dArray_fx( ismInput->base.inputBuffer, tmpRendBuffer_fx ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i ) -- GitLab From 44acc3d27f5d76d7e47ccaef01910619b78d0313 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 28 Jun 2024 12:19:29 +0530 Subject: [PATCH 2/2] clang formatting changes --- lib_dec/hq_core_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 20e198bb7..1dc75f434 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -131,7 +131,7 @@ void hq_core_dec_fx( { hHQ_core->HqVoicing = 0; move16(); - IF ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) + IF( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { hHQ_core->HqVoicing = 1; move16(); -- GitLab