From 1175563c9537990c3f2458509ec13f3d6cbb59e8 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 27 Jun 2025 14:25:22 +0530 Subject: [PATCH 1/2] Fix for 3GPP issue 1749: Use of divide1616 and idivide1616 with constant denominator Link #1749 --- lib_com/cnst.h | 8 +++++++- lib_com/ivas_cnst.h | 7 +++++++ lib_com/ivas_transient_det_fx.c | 6 ++++-- lib_dec/ivas_dirac_dec_fx.c | 2 +- lib_dec/ivas_masa_dec_fx.c | 2 +- lib_dec/ivas_spar_md_dec_fx.c | 2 +- lib_dec/swb_tbe_dec_fx.c | 8 ++++---- lib_dec/tonalMDCTconcealment_fx.c | 15 +++++++++++---- lib_enc/ext_sig_ana_fx.c | 6 +++++- lib_enc/inov_enc_fx.c | 2 +- lib_enc/ivas_dirac_enc_fx.c | 2 +- lib_enc/ivas_init_enc_fx.c | 2 +- lib_enc/ivas_ism_metadata_enc_fx.c | 5 +++-- lib_enc/ivas_masa_enc_fx.c | 2 +- lib_enc/ivas_mc_paramupmix_enc_fx.c | 2 +- lib_enc/ivas_mcmasa_enc_fx.c | 4 ++-- lib_enc/ivas_mct_enc_fx.c | 18 +++++++++--------- lib_enc/ivas_omasa_enc_fx.c | 2 +- lib_enc/ivas_qmetadata_enc_fx.c | 4 ++-- lib_enc/ivas_spar_encoder_fx.c | 2 +- lib_enc/ivas_spar_md_enc_fx.c | 8 +++++--- lib_rend/ivas_dirac_output_synthesis_dec_fx.c | 4 ++-- lib_rend/ivas_mcmasa_ana_fx.c | 2 +- 23 files changed, 72 insertions(+), 43 deletions(-) diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 6030b53bd..792df3946 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -226,6 +226,7 @@ enum{ #define ONE_BY_L_FRAME32k_Q31 3355443 #define ONE_BY_L_FRAME25_6k_Q31 4194304 #define ONE_BY_L_FRAME16k_Q31 6710886 +#define ONE_BY_L_FRAME16k_Q15 102 #define ONE_BY_L_FRAME_Q31 8388608 #define ONE_BY_240_Q31 8947849 #define ONE_BY_L_FRAME8k_Q31 13421772 @@ -680,6 +681,7 @@ enum #define NUM_DCT_LENGTH 24 #define NB_DIV 2 /* number of division (subframes) per 20ms frame */ +#define NB_DIV_LOG2 1 /* To be used for shift operation instead of division */ #define L_MDCT_HALF_OVLP_MAX L_MDCT_OVLP_MAX - 48000 / 200 /* Size of HALF overlap window slope @ 48 kHz */ #define L_MDCT_MIN_OVLP_MAX 60 /* Size of the MDCT minimal overlap @ 48 kHz - 1.25ms */ #define L_MDCT_TRANS_OVLP_MAX NS2SA( 48000, ACELP_TCX_TRANS_NS ) /* Size of the ACELP->MDCT transition overlap - 1.25ms */ @@ -708,6 +710,7 @@ enum #define L_FRAME 256 /* frame size at 12.8kHz */ #define NB_SUBFR 4 /* number of subframes per frame */ #define L_SUBFR ( L_FRAME / NB_SUBFR ) /* subframe size */ +#define L_SUBFR_LOG2 6 /* To be used for shift operation instead of division */ #define L_SUBFR_Q6 ((L_FRAME/NB_SUBFR)*64) /* subframe size */ #define L_SUBFR_Q16 ((L_FRAME/NB_SUBFR)*65536) /* subframe size */ @@ -788,6 +791,7 @@ enum #endif #define CLDFB_NO_CHANNELS_MAX_FX 30720 /*Q9*/ #define CLDFB_NO_COL_MAX 16 /* CLDFB resampling - max number of CLDFB col., == IVAS_CLDFB_NO_COL_MAX */ +#define CLDFB_NO_COL_MAX_LOG2 4 /* To be used for shift operation instead of division */ #define CLDFB_NO_COL_MAX_SWITCH 6 /* CLDFB resampling - max number of CLDFB col. for switching */ #define CLDFB_NO_COL_MAX_SWITCH_BFI 10 /* CLDFB resampling - max number of CLDFB col. for switching, BFI */ #define CLDFB_OVRLP_MIN_SLOTS 3 /* CLDFB resampling - minimize processing to minimum required for transition frame ACELP->TCX/HQ */ @@ -1533,6 +1537,7 @@ enum #define INTERP_3_2_MEM_LEN 15 #define L_SHB_LAHEAD 20 /* Size of lookahead for SHB */ #define NUM_SHB_SUBFR 16 +#define NUM_SHB_SUBFR_LOG2 4 /* To be used for shift operation instead of division */ #define LPC_SHB_ORDER 10 #define LPC_WHTN_ORDER 4 /* Order of whitening filter for SHB excitation */ #define SHB_OVERLAP_LEN ( L_FRAME16k - L_SHB_LAHEAD ) / ( NUM_SHB_SUBFR - 1 ) @@ -3092,7 +3097,8 @@ extern const Word16 Idx2Freq_Tbl[]; #define FS_32K_IN_NS_Q31 68719 #define FS_16K_IN_NS_Q31 34360 -#define ONE_BY_THREE_Q15 10923 /* 1/3.f in Q15 */ +#define ONE_BY_THREE_Q15 10923 /* 1/3.f in Q15 */ +#define ONE_BY_TEN_Q15 3277 /* 1/10.f in Q15 */ #define THREE_Q21 6291456 #define SIX_Q21 12582912 diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index d3e52ec16..18816a94a 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -166,6 +166,7 @@ typedef enum #define BINAURAL_CHANNELS 2 /* number of channels for binaural output configuration */ #define CPE_CHANNELS 2 /* number of CPE (stereo) channels */ +#define CPE_CHANNELS_LOG2 1 /* To be used for the shift operation instead of division */ #define FOA_CHANNELS 4 /* number of FOA channels */ #define HOA2_CHANNELS 9 #define HOA3_CHANNELS 16 @@ -198,6 +199,7 @@ typedef enum #define MAX_JBM_SUBFRAMES_5MS 8 #define DEFAULT_JBM_SUBFRAMES_5MS 4 #define JBM_CLDFB_SLOTS_IN_SUBFRAME 4 +#define JBM_CLDFB_SLOTS_IN_SUBFRAME_LOG2 2 /* To be used for shift operation instead of division */ #define MAX_JBM_CLDFB_TIMESLOTS 32 #define DEFAULT_JBM_CLDFB_TIMESLOTS 16 #define MAX_JBM_L_FRAME48k 1920 @@ -934,12 +936,14 @@ typedef enum { #define MDFT_FB_BANDS_240 240 #define CLDFB_TO_MDFT_FAC 4 #define MDFT_NO_COL_MAX 4 +#define MDFT_NO_COL_MAX_LOG2 2 /* To be used for shift operation instead of division */ /*----------------------------------------------------------------------------------* * General Parametric Coding Constants *----------------------------------------------------------------------------------*/ #define MAX_PARAM_SPATIAL_SUBFRAMES 4 /* Maximum number of subframes for parameteric spatial coding */ +#define MAX_PARAM_SPATIAL_SUBFRAMES_LOG2 2 /* To be used for shift operation instead of division */ #define L_SPATIAL_SUBFR_48k (L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES) #define CLDFB_SLOTS_PER_SUBFRAME ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ) /* Number of CLDFB slots per subframe */ @@ -970,6 +974,7 @@ typedef enum { #define DIRAC_MAX_NBANDS 12 /* Maximum number of frequency bands for the DirAC Side Parameter decoding */ #define DIRAC_LOW_BANDRES_STEP 2 /* always combine two bands for low band resolution in the DirAC parameter coding */ #define DIRAC_NO_COL_AVG_DIFF 32 /* Number of slots for averaging intensity vector for diffuseness computation */ +#define DIRAC_NO_COL_AVG_DIFF_LOG2 5 /* To be used for shift operation instead of division */ #define DIRAC_DIFFUSE_LEVELS 8 /* Size of the diffuseness alphabet (constant value) */ #define INV_DIRAC_DIFFUSE_LEVELS_Q13 1170 /* 1/(DIRAC_DIFFUSE_LEVELS - 1) in Q13 */ #define DIRAC_DITH_SEED 29680 @@ -1687,6 +1692,7 @@ typedef enum #define DEG_180_IN_Q22 ( 180 << Q22 ) // Q22 #define DEG_90_IN_Q22 ( 90 << Q22 ) // Q22 #define ONE_BY_360_Q31 ( 5965232 ) // Q31 +#define ONE_BY_360_Q15 ( 91 ) // Q15 #define ONE_BY_180_Q31 ( 11930465 ) // Q31 /* ----- Enums - TD Renderer ----- */ @@ -1860,6 +1866,7 @@ typedef enum #define SPAR_DIRAC_SPLIT_START_BAND 8 #define DIRAC_TO_SPAR_HBR_PRED_CHS (FOA_CHANNELS - 1) #define SPAR_DTX_BANDS 2 +#define SPAR_DTX_BANDS_LOG2 1 /* To be used for shift operation instead of division */ #define DIRAC_DTX_BANDS 2 #define SPAR_DIRAC_DTX_BANDS ( SPAR_DTX_BANDS + DIRAC_DTX_BANDS ) #define CLDFB_PAR_WEIGHT_START_BAND 7 diff --git a/lib_com/ivas_transient_det_fx.c b/lib_com/ivas_transient_det_fx.c index fb8679ebc..cc1b1771b 100644 --- a/lib_com/ivas_transient_det_fx.c +++ b/lib_com/ivas_transient_det_fx.c @@ -292,7 +292,7 @@ void ivas_transient_det_process_fx( ) { Word32 in_duck_gain[L_FRAME48k]; - Word16 num_sf, sf, sf_samp, idx; + Word16 num_sf, sf, sf_samp, idx, num_sf_log2; Word32 mem = hTranDet->in_duck_gain; /*Q30*/ move32(); @@ -309,7 +309,9 @@ void ivas_transient_det_process_fx( num_sf = 16; /*Q0*/ move16(); - sf_samp = idiv1616( frame_len, num_sf ); /*Q0*/ + num_sf_log2 = 4; /* To be used for shift operation instead of division */ + move16(); + sf_samp = shr( frame_len, num_sf_log2 ); /*Q0*/ FOR( sf = 1; sf <= num_sf; sf++ ) { idx = sub( imult1616( sf_samp, sf ), 1 ); diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index 48fce8b95..ba7741712 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -3102,7 +3102,7 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( idiv1616( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */ + hDirACRend->index_buffer_intensity = add( sub( hDirACRend->index_buffer_intensity, i_mult( shr( hDirACRend->index_buffer_intensity, DIRAC_NO_COL_AVG_DIFF_LOG2 ), DIRAC_NO_COL_AVG_DIFF ) ), 1 ); /* averaging_length = 32 */ move16(); } diff --git a/lib_dec/ivas_masa_dec_fx.c b/lib_dec/ivas_masa_dec_fx.c index e61e51262..457c040c3 100644 --- a/lib_dec/ivas_masa_dec_fx.c +++ b/lib_dec/ivas_masa_dec_fx.c @@ -2042,7 +2042,7 @@ void ivas_spar_param_to_masa_param_mapping_fx( } ELSE { - sf = idiv1616( hSpar->render_to_md_map[slot_idx + slot_idx_start], JBM_CLDFB_SLOTS_IN_SUBFRAME ); + sf = shr( hSpar->render_to_md_map[slot_idx + slot_idx_start], JBM_CLDFB_SLOTS_IN_SUBFRAME_LOG2 ); } IF( LT_16( sf, SPAR_META_DELAY_SUBFRAMES ) ) diff --git a/lib_dec/ivas_spar_md_dec_fx.c b/lib_dec/ivas_spar_md_dec_fx.c index 36b77732a..ad1fb4c3a 100644 --- a/lib_dec/ivas_spar_md_dec_fx.c +++ b/lib_dec/ivas_spar_md_dec_fx.c @@ -1715,7 +1715,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { *nB = SPAR_DTX_BANDS; move16(); - *bands_bw = idiv1616( num_bands, *nB ); /*Q0*/ + *bands_bw = shr( num_bands, SPAR_DTX_BANDS_LOG2 ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 679e206e0..06da2a83d 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -4269,7 +4269,7 @@ void ivas_dequantizeSHBparams_fx_9_1( move16(); IF( i != 0 ) { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); } Q_subgain[i] = Q_subgain[idx]; move16(); @@ -4597,7 +4597,7 @@ static void dequantizeSHBparams_fx_9_1( move16(); IF( i != 0 ) { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); } Q_subgain[i] = Q_subgain[idx]; move16(); @@ -6644,7 +6644,7 @@ void ivas_swb_tbe_dec_fx( move16(); IF( i != 0 ) { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); } GainShape_fx[i] = GainShape_tmp_fx[idx]; move16(); @@ -6688,7 +6688,7 @@ void ivas_swb_tbe_dec_fx( move16(); IF( i != 0 ) { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); + idx = shr( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR_LOG2 ); } GainShape_fx[i] = GainShape_fx[idx]; move16(); diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index fd6cf7835..f61fe276e 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -2886,7 +2886,7 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( HANDLE_FD_CNG_COM hFdCngCom; Word16 *rnd_c, *rnd; Word16 crossOverFreq, i, save_rnd_c, max_noise_line; - Word16 c, c_inv, inc; + Word16 c, c_inv, inc, inc_log2; Word32 noise_shape_buffer[L_FRAME48k]; Word16 noise_shape_buffer_e[L_FRAME48k]; Word16 start_idx, stop_idx, noise_shape_buffer_common_exp = MIN16B_FLT_FX, last_scf_e, temp_e; @@ -2994,14 +2994,21 @@ void TonalMdctConceal_create_concealment_noise_ivas_fx( IF( GT_16( st->core, TCX_20_CORE ) ) { inc = 2; + inc_log2 = 1; + move16(); + move16(); + start_idx = shr( hFdCngCom->startBand, inc_log2 ); + stop_idx = shr( hFdCngCom->stopFFTbin, inc_log2 ); } ELSE { inc = 1; + start_idx = hFdCngCom->startBand; + stop_idx = hFdCngCom->stopFFTbin; + move16(); + move16(); + move16(); } - move16(); - start_idx = idiv1616( hFdCngCom->startBand, inc ); - stop_idx = idiv1616( hFdCngCom->stopFFTbin, inc ); FOR( i = 0; i < start_idx; i++ ) { diff --git a/lib_enc/ext_sig_ana_fx.c b/lib_enc/ext_sig_ana_fx.c index 49d757be3..87fa6a451 100644 --- a/lib_enc/ext_sig_ana_fx.c +++ b/lib_enc/ext_sig_ana_fx.c @@ -1031,7 +1031,11 @@ void core_signal_analysis_high_bitrate_ivas_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { Word16 scale; - L_subframe = idiv1616( L_frameTCX, nSubframes ); /* Q0 */ + L_subframe = L_frameTCX; /* Q0 */ /* L_subframe = idiv1616( L_frameTCX, nSubframes ); */ + IF( EQ_16( nSubframes, 2 ) ) + { + L_subframe = shr( L_frameTCX, 1 ); + } test(); IF( EQ_16( transform_type[frameno], TCX_20 ) && NE_16( st->hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) ) diff --git a/lib_enc/inov_enc_fx.c b/lib_enc/inov_enc_fx.c index 01ba794ea..216ca3860 100644 --- a/lib_enc/inov_enc_fx.c +++ b/lib_enc/inov_enc_fx.c @@ -597,7 +597,7 @@ Word16 inov_encode_ivas_fx( IF( i_subfr != 0 ) { idx = idiv1616( i_subfr, L_subfr ); - idx2 = idiv1616( i_subfr, L_SUBFR ); + idx2 = shr( i_subfr, L_SUBFR_LOG2 ); } IF( LT_16( st_fx->acelp_cfg.fixed_cdk_index[idx], ACELP_FIXED_CDK_NB ) ) diff --git a/lib_enc/ivas_dirac_enc_fx.c b/lib_enc/ivas_dirac_enc_fx.c index be15b5048..3aa010d42 100644 --- a/lib_enc/ivas_dirac_enc_fx.c +++ b/lib_enc/ivas_dirac_enc_fx.c @@ -998,7 +998,7 @@ void ivas_dirac_param_est_enc_fx( diffuseness_vector_q = 0; move16(); - l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); /* Q0 */ + l_ts = shr( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES_LOG2 ); /* Q0 */ IF( useLowerRes ) { q_direction->cfg.nblocks = 1; diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index 2285acc0c..ddbea7b40 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -874,7 +874,7 @@ ivas_error ivas_init_encoder_fx( { st_ivas->nSCE = 0; move16(); - st_ivas->nCPE = idiv1616( hEncoderConfig->nchan_inp, CPE_CHANNELS ); /* Q0 */ + st_ivas->nCPE = shr( hEncoderConfig->nchan_inp, CPE_CHANNELS_LOG2 ); /* Q0 */ move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) diff --git a/lib_enc/ivas_ism_metadata_enc_fx.c b/lib_enc/ivas_ism_metadata_enc_fx.c index 594871b29..d7751aa4d 100644 --- a/lib_enc/ivas_ism_metadata_enc_fx.c +++ b/lib_enc/ivas_ism_metadata_enc_fx.c @@ -48,7 +48,8 @@ * Local constants *-----------------------------------------------------------------------*/ -#define ISM_NUM_PARAM 5 /* number of coded metadata parameters */ +#define ISM_NUM_PARAM 5 /* number of coded metadata parameters */ +#define ONE_BY_ISM_NUM_PARAM_Q15 6554 /* To be used for shift operation instead of division */ #define ISM_MAX_AZIMUTH_DIFF_IDX ( ISM_AZIMUTH_NBITS - 1 /*zero*/ - 1 /*sign*/ ) #define ISM_MAX_ELEVATION_DIFF_IDX ( ISM_ELEVATION_NBITS - 1 /*zero*/ - 1 /*sign*/ ) @@ -613,7 +614,7 @@ ivas_error ivas_ism_metadata_enc_fx( pos_zero = add( pos_zero, 1 ); } - ch = idiv1616( abs_next, ISM_NUM_PARAM ); + ch = mult( abs_next, ONE_BY_ISM_NUM_PARAM_Q15 ); IF( abs_next % ISM_NUM_PARAM == 0 ) { diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index fb86dee7a..35c57c42b 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -786,7 +786,7 @@ void ivas_masa_estimate_energy_fx( move16(); Word16 q_buf; maxBin = extract_l( Mpy_32_32( 134217728 /*CLDFB_NO_CHANNELS_MAX / L_FRAME48k in Q31*/, input_frame ) ); - l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); + l_ts = shr( input_frame, CLDFB_NO_COL_MAX_LOG2 ); FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { diff --git a/lib_enc/ivas_mc_paramupmix_enc_fx.c b/lib_enc/ivas_mc_paramupmix_enc_fx.c index cad29b146..c1f735704 100644 --- a/lib_enc/ivas_mc_paramupmix_enc_fx.c +++ b/lib_enc/ivas_mc_paramupmix_enc_fx.c @@ -855,7 +855,7 @@ static ivas_error ivas_mc_paramupmix_param_est_enc_fx( } // l_ts = input_frame / MAX_PARAM_SPATIAL_SUBFRAMES; - l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); + l_ts = shr( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES_LOG2 ); move16(); Word16 gb = find_guarded_bits_fx( l_ts ); diff --git a/lib_enc/ivas_mcmasa_enc_fx.c b/lib_enc/ivas_mcmasa_enc_fx.c index ab86efb8d..7d261d4e4 100644 --- a/lib_enc/ivas_mcmasa_enc_fx.c +++ b/lib_enc/ivas_mcmasa_enc_fx.c @@ -957,10 +957,10 @@ void ivas_mcmasa_param_est_enc_fx( set_zero_fx( Chnl_ImagBuffer_fx[i], DIRAC_NO_FB_BANDS_MAX ); } - num_freq_bins = idiv1616( input_frame, MDFT_NO_COL_MAX ); + num_freq_bins = shr( input_frame, MDFT_NO_COL_MAX_LOG2 ); num_freq_bands = hMcMasa->nbands; move16(); - l_ts = idiv1616( input_frame, MDFT_NO_COL_MAX ); + l_ts = shr( input_frame, MDFT_NO_COL_MAX_LOG2 ); set16_fx( q_vdv, 31, MASA_FREQUENCY_BANDS ); set16_fx( out_exp, 30, MASA_FREQUENCY_BANDS ); diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index ee9353379..23a70ef97 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -287,11 +287,11 @@ ivas_error ivas_mct_enc_fx( Word16 length, ch, nCPE; IF( ( hMCT->nchan_out_woLFE % 2 ) == 0 ) { - nCPE = idiv1616( hMCT->nchan_out_woLFE, 2 ); + nCPE = shr( hMCT->nchan_out_woLFE, 1 ); } ELSE { - nCPE = add( idiv1616( hMCT->nchan_out_woLFE, 2 ), 1 ); + nCPE = add( shr( hMCT->nchan_out_woLFE, 1 ), 1 ); } FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) @@ -313,12 +313,12 @@ ivas_error ivas_mct_enc_fx( } ELSE { - length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); // st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / NB_DIV + length = shr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV_LOG2 ); // st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX / NB_DIV } IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) { - length = add( length, idiv1616( length, 4 ) ); + length = add( length, shr( length, 2 ) ); } IF( hMCT->p_orig_spectrum_long_fx[cpe_id][ch] ) { @@ -359,11 +359,11 @@ ivas_error ivas_mct_enc_fx( } ELSE { - length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); + length = shr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV_LOG2 ); } IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) { - length = add( length, idiv1616( length, 4 ) ); + length = add( length, shr( length, 2 ) ); } Word16 norm = L_norm_arr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX ); q_spec = s_min( q_spec, add( sub( 31, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e ), norm ) ); @@ -391,7 +391,7 @@ ivas_error ivas_mct_enc_fx( } ELSE { - length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); + length = shr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV_LOG2 ); } scale_sig32( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX, sub( q_spec, sub( 31, st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_e ) ) ); // q_spec @@ -404,7 +404,7 @@ ivas_error ivas_mct_enc_fx( IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) { - length = add( length, idiv1616( length, 4 ) ); + length = add( length, shr( length, 2 ) ); } FOR( Word16 k = 0; k <= ( ( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->core == TCX_20_CORE ) ? 1 : NB_DIV ) - 1; k++ ) @@ -433,7 +433,7 @@ ivas_error ivas_mct_enc_fx( } ELSE { - length = idiv1616( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV ); + length = shr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->L_frameTCX, NB_DIV_LOG2 ); } Word16 e_spec = sub( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_e[0], L_norm_arr( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->hTcxEnc->spectrum_long_fx, N_MAX ) ); IF( st_ivas->hCPE[cpe_id]->hCoreCoder[ch]->last_core == ACELP_CORE ) diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index 1d14eecc9..e09a1fb36 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -1046,7 +1046,7 @@ static void ivas_omasa_param_est_enc_fx( dir_v_e = MIN_16; num_freq_bins = hOMasa->cldfbAnaEnc[0]->no_channels; num_freq_bands = hOMasa->nbands; - l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); + l_ts = shr( input_frame, CLDFB_NO_COL_MAX_LOG2 ); move16(); move16(); move16(); diff --git a/lib_enc/ivas_qmetadata_enc_fx.c b/lib_enc/ivas_qmetadata_enc_fx.c index 15adcee9c..68695120e 100644 --- a/lib_enc/ivas_qmetadata_enc_fx.c +++ b/lib_enc/ivas_qmetadata_enc_fx.c @@ -370,7 +370,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( { no_TF = add( imult1616( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), imult1616( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); test(); - IF( EQ_16( all_coherence_zero, 0 ) && GE_16( sub( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), idiv1616( imult1616( 43, no_TF ), 10 ) ), sum16_fx( bits_diff, ndirections ) ), MASA_MIN_BITS_SURR_COH ) ) + IF( EQ_16( all_coherence_zero, 0 ) && GE_16( sub( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), mult( imult1616( 43, no_TF ), ONE_BY_TEN_Q15 ) ), sum16_fx( bits_diff, ndirections ) ), MASA_MIN_BITS_SURR_COH ) ) { bits_surround_coh = encode_surround_coherence_fx( hQMetaData, hMetaData ); } @@ -396,7 +396,7 @@ ivas_error ivas_qmetadata_enc_encode_fx( { no_TF = imult1616( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); test(); - IF( EQ_16( all_coherence_zero, 0 ) && GE_16( sub( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), idiv1616( imult1616( 43, no_TF ), 10 ) ), bits_diff[0] ), MASA_MIN_BITS_SURR_COH ) ) + IF( EQ_16( all_coherence_zero, 0 ) && GE_16( sub( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), mult( imult1616( 43, no_TF ), ONE_BY_TEN_Q15 ) ), bits_diff[0] ), MASA_MIN_BITS_SURR_COH ) ) { bits_surround_coh = encode_surround_coherence_fx( hQMetaData, hMetaData ); } diff --git a/lib_enc/ivas_spar_encoder_fx.c b/lib_enc/ivas_spar_encoder_fx.c index 3b380f2eb..8143a8c33 100644 --- a/lib_enc/ivas_spar_encoder_fx.c +++ b/lib_enc/ivas_spar_encoder_fx.c @@ -788,7 +788,7 @@ static ivas_error ivas_spar_enc_process_fx( shift = s_min( shift, L_norm_arr( data_fx[i], input_frame ) ); } - l_ts = idiv1616( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES ); + l_ts = shr( input_frame, MAX_PARAM_SPATIAL_SUBFRAMES_LOG2 ); Word16 gb = find_guarded_bits_fx( l_ts ); FOR( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) diff --git a/lib_enc/ivas_spar_md_enc_fx.c b/lib_enc/ivas_spar_md_enc_fx.c index a293b870a..28a0dc9a4 100644 --- a/lib_enc/ivas_spar_md_enc_fx.c +++ b/lib_enc/ivas_spar_md_enc_fx.c @@ -479,7 +479,7 @@ ivas_error ivas_spar_md_enc_process_fx( Word32 pred_coeffs_re_local_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 k, bwidth, num_bands, num_bands_full, num_bands_bw; Word16 active_w, nchan_transport, dmx_switch, strat; - Word16 nB, bands_bw, packed_ok = 0; + Word16 nB, bands_bw, bands_bw_log2, packed_ok = 0; move16(); ivas_strats_t cs[MAX_CODING_STRATS]; Word16 code_strat; @@ -585,7 +585,7 @@ ivas_error ivas_spar_md_enc_process_fx( { nB = SPAR_DTX_BANDS; move16(); - bands_bw = idiv1616( num_bands, nB ); + bands_bw = shr( num_bands, SPAR_DTX_BANDS_LOG2 ); ivas_band_mixer_fx( cov_real_fx, cov_real_q, num_ch, &num_bands, bands_bw ); } @@ -593,7 +593,9 @@ ivas_error ivas_spar_md_enc_process_fx( { bands_bw = 2; move16(); - nB = idiv1616( num_bands, bands_bw ); + bands_bw_log2 = 1; + move16(); + nB = shr( num_bands, bands_bw_log2 ); ivas_band_mixer_fx( cov_real_fx, cov_real_q, num_ch, &num_bands, bands_bw ); } diff --git a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c index 19823d7c6..a0fa343a2 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec_fx.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec_fx.c @@ -3100,7 +3100,7 @@ static void ivas_dirac_dec_get_response_split_order_fx( } ELSE { - tmp = idiv1616( add( azimuth, 180 ), 360 ); + tmp = mult( add( azimuth, 180 ), ONE_BY_360_Q15 ); /* idiv1616( add( azimuth, 180 ), 360 ) */ } index_azimuth = sub( add( azimuth, 180 ), i_mult( tmp, 360 ) ); // index_azimuth = (azimuth + 180) % 360 index_elevation = add( elevation, 90 ); @@ -3226,7 +3226,7 @@ static void ivas_dirac_dec_get_response_split_order_fx( } ELSE { - tmp = idiv1616( add( index_azimuth, 180 ), 360 ); + tmp = mult( add( index_azimuth, 180 ), ONE_BY_360_Q15 ); } index_azimuth = sub( add( index_azimuth, 180 ), i_mult( tmp, 360 ) ); // index_azimuth = (index_azimuth + 180) % 360 diff --git a/lib_rend/ivas_mcmasa_ana_fx.c b/lib_rend/ivas_mcmasa_ana_fx.c index b2b4039f3..a0d6beb26 100644 --- a/lib_rend/ivas_mcmasa_ana_fx.c +++ b/lib_rend/ivas_mcmasa_ana_fx.c @@ -575,7 +575,7 @@ void ivas_mcmasa_param_est_ana_fx( move16(); num_freq_bands = hMcMasa->nbands; move16(); - l_ts = idiv1616( input_frame, CLDFB_NO_COL_MAX ); + l_ts = shr( input_frame, CLDFB_NO_COL_MAX_LOG2 ); numAnalysisChannels = sub( nchan_inp, 1 ); set16_fx( q_vdv, 31, MASA_FREQUENCY_BANDS ); -- GitLab From c69147d53447df41898e6119d90aca451fa1e761 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 27 Jun 2025 14:31:02 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_com/ivas_transient_det_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/ivas_transient_det_fx.c b/lib_com/ivas_transient_det_fx.c index cc1b1771b..39dee9314 100644 --- a/lib_com/ivas_transient_det_fx.c +++ b/lib_com/ivas_transient_det_fx.c @@ -309,7 +309,7 @@ void ivas_transient_det_process_fx( num_sf = 16; /*Q0*/ move16(); - num_sf_log2 = 4; /* To be used for shift operation instead of division */ + num_sf_log2 = 4; /* To be used for shift operation instead of division */ move16(); sf_samp = shr( frame_len, num_sf_log2 ); /*Q0*/ FOR( sf = 1; sf <= num_sf; sf++ ) -- GitLab