From d9ce89681efff3772a55e7b2503c43e7cbad4046 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Aug 2025 14:33:35 +0200 Subject: [PATCH 1/7] Replace divisions with constant denominator by multiplications --- lib_com/ivas_fb_mixer_fx.c | 15 ++-- lib_com/ivas_ism_com_fx.c | 15 ++-- lib_dec/ivas_corecoder_dec_reconfig_fx.c | 10 ++- lib_dec/ivas_cpe_dec_fx.c | 62 +++++++-------- lib_dec/ivas_dirac_dec_fx.c | 10 +-- lib_dec/ivas_init_dec_fx.c | 97 ++++++++++-------------- lib_dec/ivas_ism_metadata_dec_fx.c | 11 +-- lib_dec/ivas_ism_param_dec_fx.c | 9 +-- lib_dec/ivas_ism_renderer_fx.c | 22 +++--- lib_dec/ivas_mc_param_dec_fx.c | 7 +- lib_dec/ivas_mct_core_dec_fx.c | 6 +- lib_dec/ivas_spar_decoder_fx.c | 22 +++--- lib_dec/ivas_tcx_core_dec_fx.c | 5 +- lib_enc/core_enc_switch_fx.c | 5 +- lib_enc/hq_core_enc_fx.c | 3 +- lib_enc/init_enc_fx.c | 5 +- lib_enc/ivas_init_enc_fx.c | 38 ++++------ lib_enc/ivas_masa_enc_fx.c | 4 +- lib_enc/ivas_mct_enc_fx.c | 29 +++---- lib_enc/ivas_omasa_enc_fx.c | 5 +- lib_enc/ivas_osba_enc_fx.c | 7 +- lib_enc/ivas_spar_encoder_fx.c | 4 +- lib_enc/lib_enc_fx.c | 7 +- lib_enc/updt_enc_fx.c | 5 +- 24 files changed, 166 insertions(+), 237 deletions(-) diff --git a/lib_com/ivas_fb_mixer_fx.c b/lib_com/ivas_fb_mixer_fx.c index b55e069d7..a45795294 100644 --- a/lib_com/ivas_fb_mixer_fx.c +++ b/lib_com/ivas_fb_mixer_fx.c @@ -199,14 +199,13 @@ ivas_error ivas_FB_mixer_open_fx( { IVAS_FB_MIXER_HANDLE hFbMixer; Word16 i, j, frame_len, num_bands; - Word16 num_chs_alloc, exp; + Word16 num_chs_alloc; ivas_error error; error = IVAS_ERR_OK; move32(); - frame_len = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp ); - frame_len = shr( frame_len, sub( 15, exp ) ); + frame_len = extract_l( Mpy_32_32_r( sampling_rate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); hFbMixer = *hFbMixer_out; @@ -936,8 +935,9 @@ static Word16 ivas_calculate_abs_fr_fx( move64(); Word16 short_stride = pFb->fb_bin_to_band.short_stride; move16(); + Word32 res_dec1, res_frac, res_dec2; - iDiv_and_mod_32( sampling_rate, FRAMES_PER_SEC, &res_dec1, &res_frac, 0 ); + res_dec1 = Mpy_32_32_r( sampling_rate, ONE_BY_FRAMES_PER_SEC_Q31 ); iDiv_and_mod_32( res_dec1, short_stride, &res_dec2, &res_frac, 0 ); const Word16 num_bins_per_short_stride_bin = extract_l( res_dec2 ); iDiv_and_mod_32( res_dec1, pFb->fb_bin_to_band.num_cldfb_bands, &res_dec2, &res_frac, 0 ); @@ -1259,7 +1259,7 @@ static ivas_error ivas_filterbank_setup_fx( const Word32 sampling_rate, Word16 *index ) { - Word16 i, j, exp, tmp; + Word16 i, j, tmp; const Word32 *pAll_fb_fr_fx[2]; const Word16 *pAll_bins_start_offset = NULL; const Word16 *pAll_bins_per_band = NULL; @@ -1342,9 +1342,8 @@ static ivas_error ivas_filterbank_setup_fx( /*pFb->fb_bin_to_band.cldfb_stride = ( int16_t )( ( sampling_rate / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX );*/ /* equals num_cldfb_bands*/ // pFb->fb_bin_to_band.short_stride = extract_l( ( sampling_rate / FRAMES_PER_SEC ) / 4 ); - tmp = BASOP_Util_Divide3232_Scale( sampling_rate, FRAMES_PER_SEC, &exp ); - pFb->fb_bin_to_band.short_stride = shr( tmp, add( sub( 15, exp ), 2 ) ); - + tmp = extract_l( Mpy_32_32_r( sampling_rate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + pFb->fb_bin_to_band.short_stride = shr( tmp, 2 ); move16(); set32_fx( pFb->fb_bin_to_band.p_short_stride_bin_to_band_fx, 0, 2 * MDFT_FB_BANDS_240 ); diff --git a/lib_com/ivas_ism_com_fx.c b/lib_com/ivas_ism_com_fx.c index 5f1a13afb..1b61ee4ac 100644 --- a/lib_com/ivas_ism_com_fx.c +++ b/lib_com/ivas_ism_com_fx.c @@ -38,6 +38,7 @@ #include "prot_fx.h" #include "ivas_stat_com.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" @@ -144,9 +145,9 @@ ivas_error ivas_ism_config_fx( { /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */ // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); - bits_ism = extract_l( Mpy_32_32( 42949673, ism_total_brate ) ); // 42949673 is 1/FRAMES_PER_SEC in Q31 - tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); // Q15 - exp - set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); + bits_ism = extract_l( Mpy_32_32_r( ONE_BY_FRAMES_PER_SEC_Q31, ism_total_brate ) ); // Q0 + tmp1 = extract_l( Mpy_32_32_r( sub( bits_ism, bits_ism % n_ISms ), one_by_q_level[n_ISms] ) ); + set16_fx( bits_element, tmp1, n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); @@ -156,11 +157,9 @@ ivas_error ivas_ism_config_fx( { /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */ // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); - // 1 / 50 * 2 ^ 31 -- > 42949673, --> Q31, - //(Q31 +Q0) - Q31 --> Q0 - bits_ism = extract_l( Mpy_32_32( 42949673, ism_total_brate ) ); // 42949673 is 1/FRAMES_PER_SEC in Q31 - tmp1 = BASOP_Util_Divide1616_Scale( bits_ism, n_ISms, &exp ); // Q15 - exp - set16_fx( bits_element, shr( tmp1, sub( 15, exp ) ), n_ISms ); + bits_ism = extract_l( Mpy_32_32_r( ONE_BY_FRAMES_PER_SEC_Q31, ism_total_brate ) ); // Q0 + tmp1 = extract_l( Mpy_32_32_r( sub( bits_ism, bits_ism % n_ISms ), one_by_q_level[n_ISms] ) ); + set16_fx( bits_element, tmp1, n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); bitbudget_to_brate( bits_element, element_brate, n_ISms ); diff --git a/lib_dec/ivas_corecoder_dec_reconfig_fx.c b/lib_dec/ivas_corecoder_dec_reconfig_fx.c index 5b4c7f472..5deb57e8c 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig_fx.c +++ b/lib_dec/ivas_corecoder_dec_reconfig_fx.c @@ -33,6 +33,7 @@ #include "options.h" #include "ivas_cnst.h" #include "ivas_prot_fx.h" +#include "ivas_rom_com_fx.h" #include "prot_fx.h" #include #include "wmc_auto.h" @@ -56,7 +57,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( { Word16 n, sce_id, cpe_id, output_frame; Word16 nSCE_existing, nCPE_existing; - Word32 ivas_total_brate; + Word32 tmp_br, ivas_total_brate; Word16 nchan_transport_real; MC_MODE last_mc_mode; DECODER_CONFIG_HANDLE hDecoderConfig; @@ -409,9 +410,10 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* otherwise create extra dummy CPE */ ELSE { - Word32 quo, rem; - iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &quo, &rem, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, quo ) ), IVAS_ERR_OK ) ) + /* i = ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) */ + n = add( st_ivas->nSCE, st_ivas->nCPE ); + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[n] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index f8d229540..2c6e992d5 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -79,7 +79,6 @@ ivas_error ivas_cpe_dec_fx( ivas_error error; Word32 cpe_brate; Word32 element_brate_ref; - Word32 quo, rem; error = IVAS_ERR_OK; move32(); @@ -261,9 +260,9 @@ ivas_error ivas_cpe_dec_fx( { IF( hCPE->hStereoTD->tdm_LRTD_flag ) { - iDiv_and_mod_32( L_shr( hCPE->element_brate, 1 ), FRAMES_PER_SEC, &quo, &rem, 0 ); - sts[0]->bits_frame_nominal = extract_l( quo ); - sts[1]->bits_frame_nominal = extract_l( quo ); + i = extract_l( Mpy_32_32_r( L_shr( hCPE->element_brate, 1 ), ONE_BY_FRAMES_PER_SEC_Q31 ) ); + sts[0]->bits_frame_nominal = i; + sts[1]->bits_frame_nominal = i; move16(); move16(); } @@ -308,23 +307,22 @@ ivas_error ivas_cpe_dec_fx( move32(); IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - iDiv_and_mod_32( cpe_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata ); + i = extract_l( Mpy_32_32_r( cpe_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( i, 1 ), nb_bits_metadata ); IF( hCPE->brate_surplus < 0 ) { - iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); - quo = L_negate( quo ); + i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } ELSE { - iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + i = extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); } - sts[1]->bit_stream = sts[1]->bit_stream + extract_l( quo ); + sts[1]->bit_stream = sts[1]->bit_stream + i; } ELSE { - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata ); + i = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( i, 1 ), nb_bits_metadata ); } IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) @@ -353,9 +351,8 @@ ivas_error ivas_cpe_dec_fx( nb_bits = sub( nb_bits, nb_bits_metadata ); IF( hCPE->brate_surplus < 0 ) { - iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); - quo = L_negate( quo ); - nb_bits = add( nb_bits, extract_l( quo ) ); + i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); + nb_bits = add( nb_bits, i ); } } @@ -387,19 +384,17 @@ ivas_error ivas_cpe_dec_fx( /* signal bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; move16(); - iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - sts[1]->bits_frame_channel = extract_l( quo ); + sts[1]->bits_frame_channel = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); IF( hCPE->brate_surplus < 0 ) { - iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); - quo = L_negate( quo ); + i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } ELSE { - iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + i = extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); } - sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( quo ) ); + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, i ); move16(); IF( st_ivas->hQMetaData != NULL ) { @@ -417,14 +412,13 @@ ivas_error ivas_cpe_dec_fx( { IF( hCPE->brate_surplus < 0 ) { - iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); - quo = L_negate( quo ); + i = negate( extract_l( Mpy_32_32_r( L_abs( hCPE->brate_surplus ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } ELSE { - iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + i = extract_l( Mpy_32_32_r( hCPE->brate_surplus, ONE_BY_FRAMES_PER_SEC_Q31 ) ); } - brate_surplus[0] = L_shr( L_mult( extract_l( L_shr( quo, 1 ) ), FRAMES_PER_SEC ), 1 ); + brate_surplus[0] = L_shr( L_mult( shr( i, 1 ), FRAMES_PER_SEC ), 1 ); move32(); brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] ); move32(); @@ -455,10 +449,9 @@ ivas_error ivas_cpe_dec_fx( sts[n]->total_brate = hCPE->element_brate; move32(); } - iDiv_and_mod_32( sts[n]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - sts[n]->bits_frame_nominal = extract_l( quo ); - iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - sts[n]->bits_frame_channel = extract_l( L_shr( quo, sub( n_channels, 1 ) ) ); + sts[n]->bits_frame_nominal = extract_l( Mpy_32_32_r( sts[n]->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + i = extract_l( Mpy_32_32_r( hCPE->element_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + sts[n]->bits_frame_channel = shr( i, sub( n_channels, 1 ) ); move16(); move16(); @@ -469,14 +462,13 @@ ivas_error ivas_cpe_dec_fx( { IF( brate_surplus[n] < 0 ) { - iDiv_and_mod_32( L_abs( brate_surplus[n] ), FRAMES_PER_SEC, &quo, &rem, 0 ); - quo = L_negate( quo ); + i = negate( extract_l( Mpy_32_32_r( L_abs( brate_surplus[n] ), ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } ELSE { - iDiv_and_mod_32( brate_surplus[n], FRAMES_PER_SEC, &quo, &rem, 0 ); + i = extract_l( Mpy_32_32_r( brate_surplus[n], ONE_BY_FRAMES_PER_SEC_Q31 ) ); } - sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( quo ) ); + sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, i ); sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] ); move16(); move32(); @@ -580,8 +572,8 @@ ivas_error ivas_cpe_dec_fx( { tdm_configure_dec_fx( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata ); - iDiv_and_mod_32( sts[0]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - sts[1]->bit_stream = sts[0]->bit_stream + extract_l( quo ); + i = extract_l( Mpy_32_32_r( sts[0]->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + sts[1]->bit_stream = sts[0]->bit_stream + i; } ELSE { diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index 39bcf9039..48593af0d 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -1254,7 +1254,6 @@ void ivas_dirac_dec_read_BS_fx( { Word16 i, j, b, dir, orig_dirac_bands; Word16 next_bit_pos_orig; - Word32 quo, rem; test(); test(); @@ -1262,8 +1261,7 @@ void ivas_dirac_dec_read_BS_fx( { next_bit_pos_orig = st->next_bit_pos; move16(); - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - st->next_bit_pos = extract_l( L_sub( quo, 1 ) ); + st->next_bit_pos = sub( extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ), 1 ); move16(); if ( last_bit_pos > 0 ) { @@ -1358,11 +1356,11 @@ void ivas_dirac_dec_read_BS_fx( move16(); /* subtract mode signaling bits, since bitstream was moved after mode reading */ - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + i = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); #ifdef NONBE_FIX_1052_SBA_EXT - st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS ) ); + st->next_bit_pos = sub( sub( i, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS ); #else - st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS ) ); + st->next_bit_pos = sub( sub( i, 1 ), SID_FORMAT_NBITS ); #endif move16(); diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 144018523..952fd497d 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -38,6 +38,7 @@ #include "ivas_prot_rend_fx.h" #include "rom_com.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "ivas_stat_enc.h" #include "prot_fx.h" #include "wmc_auto.h" @@ -605,9 +606,8 @@ ivas_error ivas_dec_setup( move16(); nchan_ism = 1; move16(); - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - k = extract_l( L_sub( res_dec, 1 ) ); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + k = sub( k, 1 ); WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) { @@ -670,9 +670,8 @@ ivas_error ivas_dec_setup( ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { /* read number of MASA transport channels */ - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - IF( st_ivas->bit_stream[res_dec - 1] ) + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( st_ivas->bit_stream[k - 1] ) { st_ivas->nchan_transport = 2; move16(); @@ -686,7 +685,7 @@ ivas_error ivas_dec_setup( } #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT /* this should be non-zero if original input format was MASA_ISM_FORMAT */ - st_ivas->nchan_ism = add( st_ivas->bit_stream[L_sub( res_dec, 3 )], shl( st_ivas->bit_stream[L_sub( res_dec, 2 )], 1 ) ); + st_ivas->nchan_ism = add( st_ivas->bit_stream[sub( k, 3 )], shl( st_ivas->bit_stream[sub( k, 2 )], 1 ) ); IF( GT_16( st_ivas->nchan_ism, 0 ) ) { @@ -767,9 +766,8 @@ ivas_error ivas_dec_setup( move16(); /* for the DISC mode the number of objects are written at the end of the bitstream, in the MASA metadata */ - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 ); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); move16(); st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, st_ivas->nchan_ism ); move16(); @@ -790,9 +788,8 @@ ivas_error ivas_dec_setup( ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { /* the number of objects is written at the end of the bitstream, in the SBA metadata */ - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[res_dec - 1], 1 ), st_ivas->bit_stream[res_dec - 2] ), 1 ); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + st_ivas->nchan_ism = add( add( shl( st_ivas->bit_stream[k - 1], 1 ), st_ivas->bit_stream[k - 2] ), 1 ); move16(); /* read Ambisonic (SBA) planar flag */ @@ -938,9 +935,8 @@ ivas_error ivas_dec_setup( move16(); BREAK; case SID_MASA_2TC:; // empyt statement for declaration - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - IF( EQ_16( st_ivas->bit_stream[( res_dec - 1 ) - SID_FORMAT_NBITS], 1 ) ) + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( EQ_16( st_ivas->bit_stream[( k - 1 ) - SID_FORMAT_NBITS], 1 ) ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); @@ -1027,9 +1023,8 @@ ivas_error ivas_dec_setup( move16(); nchan_ism = 1; move16(); - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - k = extract_l( L_sub( L_sub( res_dec, 1 ), SID_FORMAT_NBITS ) ); + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + k = sub( sub( k, 1 ), SID_FORMAT_NBITS ); move16(); WHILE( st_ivas->bit_stream[k] && ( nchan_ism < MAX_NUM_OBJECTS ) ) @@ -1285,9 +1280,8 @@ static ivas_error ivas_read_format( case SID_MASA_2TC: st_ivas->ivas_format = MASA_FORMAT; move32(); - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - IF( EQ_32( st_ivas->bit_stream[res_dec - 1], 1 ) ) + k = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( EQ_32( st_ivas->bit_stream[k - 1], 1 ) ) { st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); @@ -1587,7 +1581,7 @@ ivas_error ivas_init_decoder_fx( Word16 sce_id, cpe_id; Word16 numCldfbAnalyses, numCldfbSyntheses; Word16 granularity, n_channels_transport_jbm; - Word32 output_Fs, ivas_total_brate; + Word32 output_Fs, ivas_total_brate, tmp_br; #ifdef NONBE_FIX_MC_LFE_LPF Word32 delay_ns; #else @@ -2007,9 +2001,8 @@ ivas_error ivas_init_decoder_fx( move16(); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2019,9 +2012,8 @@ ivas_error ivas_init_decoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, (res_dec) *CPE_CHANNELS ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2036,10 +2028,8 @@ ivas_error ivas_init_decoder_fx( test(); IF( st_ivas->sba_dirac_stereo_flag && ( st_ivas->nCPE == 0 ) ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); - - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nSCE] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2089,9 +2079,8 @@ ivas_error ivas_init_decoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, res_dec ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2101,9 +2090,8 @@ ivas_error ivas_init_decoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2226,9 +2214,8 @@ ivas_error ivas_init_decoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2243,9 +2230,8 @@ ivas_error ivas_init_decoder_fx( test(); IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[add( st_ivas->nSCE, st_ivas->nCPE )] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2412,9 +2398,8 @@ ivas_error ivas_init_decoder_fx( move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2459,9 +2444,8 @@ ivas_error ivas_init_decoder_fx( move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( res_dec, 1 ) ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -2496,10 +2480,8 @@ ivas_error ivas_init_decoder_fx( move16(); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); - - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[add( st_ivas->nSCE, st_ivas->nCPE )] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2609,9 +2591,8 @@ ivas_error ivas_init_decoder_fx( /* create CPE element for DFT Stereo like upmix */ IF( st_ivas->sba_dirac_stereo_flag ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &res_dec, &res_frac, 0 ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, res_dec ) ), IVAS_ERR_OK ) ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[add( st_ivas->nSCE, st_ivas->nCPE )] ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_ism_metadata_dec_fx.c b/lib_dec/ivas_ism_metadata_dec_fx.c index 17bc36346..876636be6 100644 --- a/lib_dec/ivas_ism_metadata_dec_fx.c +++ b/lib_dec/ivas_ism_metadata_dec_fx.c @@ -176,7 +176,7 @@ ivas_error ivas_ism_metadata_dec_fx( Word16 *ism_extmeta_cnt, /* i/o: Number of change frames observed */ DEC_CORE_HANDLE st0 ) /* i : core-coder handle */ { - Word16 ch, nb_bits_start = 0, last_bit_pos; + Word16 k, ch, nb_bits_start = 0, last_bit_pos; Word16 idx_radius; Word32 element_brate[MAX_NUM_OBJECTS], total_brate[MAX_NUM_OBJECTS]; Word16 ism_extmeta_bitstream; @@ -198,7 +198,6 @@ ivas_error ivas_ism_metadata_dec_fx( Word16 nbands, nblocks; Word16 md_diff_flag[MAX_NUM_OBJECTS]; ivas_error error; - Word32 res_dec, res_frac; move16(); push_wmops( "ism_meta_dec" ); @@ -208,8 +207,8 @@ ivas_error ivas_ism_metadata_dec_fx( move16(); nchan_transport_prev = *nchan_transport; move16(); - iDiv_and_mod_32( ism_total_brate, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - last_bit_pos = extract_l( L_sub( res_dec, 1 ) ); + k = extract_l( Mpy_32_32_r( ism_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + last_bit_pos = sub( k, 1 ); bstr_orig = st0->bit_stream; next_bit_pos_orig = st0->next_bit_pos; move16(); @@ -1307,9 +1306,7 @@ void ivas_ism_metadata_sid_dec_fx( } /* take into account padding bits as metadata bits to keep later bitrate checks valid */ - Word32 res_dec, res_frac; - iDiv_and_mod_32( IVAS_SID_5k2 - SID_2k40, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - nb_bits_metadata[*sce_id_dtx] = (Word16) res_dec; + nb_bits_metadata[*sce_id_dtx] = extract_l( Mpy_32_32_r( IVAS_SID_5k2 - SID_2k40, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); /* set the bitstream pointer to its original position */ diff --git a/lib_dec/ivas_ism_param_dec_fx.c b/lib_dec/ivas_ism_param_dec_fx.c index f9d03f6f9..a502307c2 100644 --- a/lib_dec/ivas_ism_param_dec_fx.c +++ b/lib_dec/ivas_ism_param_dec_fx.c @@ -926,16 +926,15 @@ void ivas_ism_dec_digest_tc_fx( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) || ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) && st_ivas->hDecoderConfig->Opt_Headrotation == 0 ) ) { - int16_t i; + Word16 i; Word32 azimuth_fx, elevation_fx; /* we have a full frame interpolator, adapt it */ /* for BE testing */ - Word32 res_dec, res_frac; - iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - IF( EQ_32( extract_l( res_dec ), st_ivas->hTcBuffer->n_samples_available ) ) + i = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + IF( EQ_16( i, st_ivas->hTcBuffer->n_samples_available ) ) { - Word16 interpolator_length = extract_l( res_dec ); + Word16 interpolator_length = i; test(); test(); diff --git a/lib_dec/ivas_ism_renderer_fx.c b/lib_dec/ivas_ism_renderer_fx.c index 3aad49c26..5bc310dd0 100644 --- a/lib_dec/ivas_ism_renderer_fx.c +++ b/lib_dec/ivas_ism_renderer_fx.c @@ -94,18 +94,14 @@ ivas_error ivas_ism_renderer_open_fx( IF( st_ivas->hDecoderConfig->Opt_tsm ) { - Word32 res_dec, res_frac; init_interpolator_length = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_CLDFB_TIMESLOTS * CLDFB_SLOT_NS ); move16(); - iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - interpolator_length = (UWord16) ( res_dec ); + interpolator_length = (UWord16) extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); } ELSE { - Word32 res_dec, res_frac; - iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - init_interpolator_length = (UWord16) ( res_dec ); + init_interpolator_length = (UWord16) extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); interpolator_length = init_interpolator_length; move16(); @@ -434,15 +430,17 @@ ivas_error ivas_omasa_separate_object_renderer_open( { set32_fx( st_ivas->hIsmRendererData->prev_gains_fx[i], 0, MAX_OUTPUT_CHANNELS ); } - Word32 res_dec1, res_frac1; - Word32 res_dec2, res_frac2; - iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &res_dec1, &res_frac1, 0 ); - iDiv_and_mod_32( res_dec1, MAX_PARAM_SPATIAL_SUBFRAMES, &res_dec2, &res_frac2, 0 ); - init_interpolator_length = extract_l( res_dec2 ); + + i = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + init_interpolator_length = shr( i, 2 ); // i / MAX_PARAM_SPATIAL_SUBFRAMES interpolator_length = init_interpolator_length; move16(); - st_ivas->hIsmRendererData->interpolator_fx = (Word16 *) malloc( sizeof( Word16 ) * init_interpolator_length ); + IF( ( st_ivas->hIsmRendererData->interpolator_fx = (Word16 *) malloc( sizeof( Word16 ) * init_interpolator_length ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for MASA ISM renderer interpolator \n" ) ); + } + st_ivas->hIsmRendererData->interpolator_len = init_interpolator_length; move16(); FOR( i = 0; i < interpolator_length; i++ ) diff --git a/lib_dec/ivas_mc_param_dec_fx.c b/lib_dec/ivas_mc_param_dec_fx.c index 73ba585d1..6c89a513e 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -252,12 +252,7 @@ ivas_error ivas_param_mc_dec_open_fx( *-----------------------------------------------------------------*/ // hParamMC->slot_size = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / CLDFB_NO_COL_MAX; - Word16 temp_e; - Word16 temp = BASOP_Util_Divide3232_Scale( output_Fs, FRAMES_PER_SEC, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0 - temp = BASOP_Util_Divide1616_Scale( temp, CLDFB_NO_COL_MAX, &temp_e ); - temp = shr( temp, sub( 15, temp_e ) ); // Going back to Q0 - hParamMC->slot_size = temp; + hParamMC->slot_size = shr( extract_l( Mpy_32_32_r( output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), 4 ); move16(); set16_fx( hParamMC->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS ); set16_fx( hParamMC->subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, DEFAULT_JBM_SUBFRAMES_5MS ); diff --git a/lib_dec/ivas_mct_core_dec_fx.c b/lib_dec/ivas_mct_core_dec_fx.c index 2762fc835..47cb02d1e 100644 --- a/lib_dec/ivas_mct_core_dec_fx.c +++ b/lib_dec/ivas_mct_core_dec_fx.c @@ -62,7 +62,7 @@ void ivas_mct_side_bits_fx( { Word16 ch, cpe_id, nChannels, i, k, nSubframes; Word16 nf_side_bits, availableBits, next_bit_pos, nf_bits; - Word16 chBitRatios[MCT_MAX_CHANNELS], tmp, scale; + Word16 chBitRatios[MCT_MAX_CHANNELS], tmp; Decoder_State *st, *sts[MCT_MAX_CHANNELS]; nf_side_bits = 0; @@ -142,9 +142,7 @@ void ivas_mct_side_bits_fx( } } - tmp = BASOP_Util_Divide3232_Scale( ivas_total_brate, FRAMES_PER_SEC, &scale ); - tmp = shr( tmp, sub( 15, scale ) ); - + tmp = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); availableBits = ( sub( sub( tmp, sts[0]->next_bit_pos ), nf_side_bits ) ); availableBits = sub( availableBits, nb_bits_metadata ); diff --git a/lib_dec/ivas_spar_decoder_fx.c b/lib_dec/ivas_spar_decoder_fx.c index 8832730ba..18e3fcb08 100644 --- a/lib_dec/ivas_spar_decoder_fx.c +++ b/lib_dec/ivas_spar_decoder_fx.c @@ -298,9 +298,8 @@ ivas_error ivas_spar_dec_open_fx( IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { /* get correct granularity in case of binaural rendering of the discrete objects with the td obj renderer */ - Word32 quo, rem; - iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, &quo, &rem, 0 ); - granularity = extract_l( quo ); /*Q0*/ + /* granularity = NS2SA( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ) */ + granularity = shr( extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), 2 ); /*Q0*/ } IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ), IVAS_ERR_OK ) ) @@ -379,7 +378,6 @@ ivas_error ivas_spar_dec_fx( Word16 next_bit_pos_orig, last_bit_pos; UWord16 bstr_meta[MAX_BITS_METADATA], *bit_stream_orig; ivas_error error; - Word32 quo, rem; push_wmops( "ivas_spar_decode" ); error = IVAS_ERR_OK; @@ -402,8 +400,8 @@ ivas_error ivas_spar_dec_fx( IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/ + i = extract_l( Mpy_32_32_r( hDecoderConfig->ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + last_bit_pos = sub( sub( i, 1 ), nb_bits_read[1] ); /*Q0*/ } ELSE { @@ -425,13 +423,13 @@ ivas_error ivas_spar_dec_fx( IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { - iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = sub( extract_l( L_sub( quo, 1 ) ), nb_bits_read[1] ); /*Q0*/ + i = extract_l( Mpy_32_32_r( hDecoderConfig->ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + last_bit_pos = sub( sub( i, 1 ), nb_bits_read[1] ); /*Q0*/ } ELSE { - iDiv_and_mod_32( hDecoderConfig->ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); - last_bit_pos = extract_l( L_sub( quo, 1 ) ); /*Q0*/ + i = extract_l( Mpy_32_32_r( hDecoderConfig->ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + last_bit_pos = sub( i, 1 ); /*Q0*/ } test(); @@ -1633,9 +1631,7 @@ void ivas_spar_dec_digest_tc_fx( } /* TD decorrelator */ - Word32 quo, rem; - iDiv_and_mod_32( st_ivas->hDecoderConfig->output_Fs, FRAMES_PER_SEC, &quo, &rem, 0 ); - default_frame = extract_l( quo ); /*Q0*/ + default_frame = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); nSamplesLeftForTD = nSamplesForRendering; /*Q0*/ move16(); nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ diff --git a/lib_dec/ivas_tcx_core_dec_fx.c b/lib_dec/ivas_tcx_core_dec_fx.c index 0be01f7b8..0f98e1774 100644 --- a/lib_dec/ivas_tcx_core_dec_fx.c +++ b/lib_dec/ivas_tcx_core_dec_fx.c @@ -219,8 +219,6 @@ void stereo_tcx_core_dec_fx( /*Concealment*/ Word16 bfi; - Word32 L_tmp, mod; - /*LPC*/ Word16 lsf_fx[( NB_DIV + 1 ) * M], lsp_fx[( NB_DIV + 1 ) * M], lspmid_fx[M], lsfmid_fx[M], lsf_tmp_fx[( NB_DIV + 1 ) * M]; Word16 lspnew_uw_fx[NB_DIV * M], lsfnew_uw_fx[NB_DIV * M]; @@ -262,8 +260,7 @@ void stereo_tcx_core_dec_fx( * Initializations *--------------------------------------------------------------------------------*/ - iDiv_and_mod_32( st->total_brate, FRAMES_PER_SEC, &L_tmp, &mod, 0 ); - total_nbbits = extract_l( L_tmp ); /* Q0 */ + total_nbbits = extract_l( Mpy_32_32_r( st->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); bitsRead = 0; move16(); LSF_Q_prediction = -1; /* to avoid compilation warnings Q0*/ diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index fb5fd037a..78ae3a2fb 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -235,7 +235,6 @@ void core_coder_mode_switch_ivas_fx( exp_res = 0; move16(); - if ( EQ_16( st->last_core, AMR_WB_CORE ) ) { bSwitchFromAmrwbIO = 1; @@ -266,9 +265,7 @@ void core_coder_mode_switch_ivas_fx( { st->sr_core = sr_core; move16(); - Word16 tmp = BASOP_Util_Divide3232_Scale( sr_core, FRAMES_PER_SEC, &exp_res ); - st->L_frame = shr( tmp, sub( 15, exp_res ) ); // Q0 - move16(); + st->L_frame = extract_l( Mpy_32_32_r( sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); st->tcxonly = getTcxonly_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); move16(); diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index b5e1abbca..026a9e046 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -329,8 +329,7 @@ void hq_core_enc_ivas_fx( * Write signaling information *--------------------------------------------------------------------------*/ - num_bits = BASOP_Util_Divide3232_Scale( st->total_brate, FRAMES_PER_SEC, &exp ); /* Q15-exp */ - num_bits = shr( num_bits, sub( 15, exp ) ); /* Q0 */ + num_bits = extract_l( Mpy_32_32_r( st->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); extra_unused = 0; move16(); diff --git a/lib_enc/init_enc_fx.c b/lib_enc/init_enc_fx.c index 0ee479a7c..2990c07eb 100644 --- a/lib_enc/init_enc_fx.c +++ b/lib_enc/init_enc_fx.c @@ -2144,9 +2144,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 ) ); + + Word16 frame_length = extract_l( Mpy_32_32_r( st->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); IF( GT_16( st->element_mode, EVS_MONO ) ) { diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index c4a917c23..7613c21f9 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -38,6 +38,7 @@ #include "ivas_prot_fx.h" #include "ivas_stat_enc.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #include "prot_fx_enc.h" @@ -441,7 +442,7 @@ ivas_error ivas_init_encoder_fx( Word16 nchan_inp_buff; Word16 sce_id, cpe_id; IVAS_FORMAT ivas_format; - Word32 input_Fs, ivas_total_brate; + Word32 input_Fs, ivas_total_brate, tmp_br; Word32 element_brate_tmp[MAX_NUM_OBJECTS]; ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; @@ -675,9 +676,8 @@ ivas_error ivas_init_encoder_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( ( error = create_sce_enc_fx( st_ivas, sce_id, res_dec ) ) != IVAS_ERR_OK ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -691,9 +691,8 @@ ivas_error ivas_init_encoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) { return error; } @@ -834,9 +833,8 @@ ivas_error ivas_init_encoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) { return error; } @@ -866,9 +864,8 @@ ivas_error ivas_init_encoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) { return error; } @@ -903,9 +900,8 @@ ivas_error ivas_init_encoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &res_dec, &res_frac, 0 ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hEncoderConfig->nchan_inp] ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) { return error; } @@ -940,9 +936,8 @@ ivas_error ivas_init_encoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &res_dec, &res_frac, 0 ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ) != IVAS_ERR_OK ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nCPE] ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -967,9 +962,8 @@ ivas_error ivas_init_encoder_fx( FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - Word32 res_dec, res_frac; - iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nCPE, st_ivas->nSCE ), &res_dec, &res_frac, 0 ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ) != IVAS_ERR_OK ) + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nSCE] ); + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 334feb7c5..0009bb4de 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -3010,7 +3010,7 @@ void ivas_masa_enc_reconfigure_fx( Word16 sce_id, cpe_id; Word32 ivas_total_brate; Word32 ism_total_brate; - Word32 tmp_br, tmp_mod; + Word32 tmp_br; ivas_total_brate = st_ivas->hEncoderConfig->ivas_total_brate; move32(); @@ -3031,7 +3031,7 @@ void ivas_masa_enc_reconfigure_fx( IF( NE_32( ivas_total_brate, st_ivas->hEncoderConfig->last_ivas_total_brate ) ) { - iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp_mod, 0 ); + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { copy_encoder_config_fx( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index 735e7e191..ea9422436 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -39,6 +39,7 @@ #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#include "ivas_rom_com_fx.h" #include "prot_fx_enc.h" #include "rom_com.h" @@ -238,12 +239,11 @@ ivas_error ivas_mct_enc_fx( { Word32 cp_bitrate; // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - cp_bitrate = L_shl( L_deposit_l( div_l( ivas_total_brate, hMCT->nchan_out_woLFE ) ), 2 ); // a/b => div_l(a, b/2) or (2 * div_l(a, b)) - + cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hMCT->nchan_out_woLFE * CPE_CHANNELS] ); IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - cp_bitrate = L_shl( L_deposit_l( div_l( ivas_total_brate, st_ivas->nchan_transport ) ), 2 ); // a/b => div_l(a, b/2) or (2 * div_l(a, b)) + cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport * CPE_CHANNELS] ); } IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) @@ -564,13 +564,13 @@ ivas_error create_mct_enc_fx( move16(); } - Word32 L_tmp; - iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), hMCT->nchan_out_woLFE, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; + cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hMCT->nchan_out_woLFE * CPE_CHANNELS] ); + IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), st_ivas->nchan_transport, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport * CPE_CHANNELS] ); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -708,13 +708,12 @@ ivas_error mct_enc_reconfigure_fx( } } - Word32 L_tmp; - iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), hMCT->nchan_out_woLFE, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; + cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hMCT->nchan_out_woLFE * CPE_CHANNELS] ); IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { - iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), st_ivas->nchan_transport, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; + cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport * CPE_CHANNELS] ); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -1213,25 +1212,19 @@ static ivas_error ivas_mc_enc_reconfig_fx( { new_brate_SCE = 0; move32(); - Word32 res_dec, res_frac; - iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); - new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); + new_brate_CPE = L_shl( Mpy_32_32_r( st_ivas->hEncoderConfig->ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ), 1 ); } ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { new_brate_SCE = 0; move32(); - Word32 res_dec, res_frac; - iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); - new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); + new_brate_CPE = L_shl( Mpy_32_32_r( st_ivas->hEncoderConfig->ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ), 1 ); } ELSE { new_brate_SCE = 0; /*st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport;*/ move32(); - Word32 res_dec, res_frac; - iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); - new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); + new_brate_CPE = L_shl( Mpy_32_32_r( st_ivas->hEncoderConfig->ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); } IF( NE_32( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ), IVAS_ERR_OK ) ) diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index 838ca1944..1d9384d4c 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -38,6 +38,7 @@ #include "ivas_prot_fx.h" #include "prot_fx.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" #ifdef DEBUGGING @@ -860,9 +861,7 @@ void ivas_set_ism_importance_interformat_fx( } } - Word32 quo, rem; - iDiv_and_mod_32( ism_total_brate, nchan_transport, &quo, &rem, 0 ); - + Word32 quo = Mpy_32_32_r( ism_total_brate, one_by_q_level[nchan_transport] ); /* do not use the low-rate core-coder mode at highest bit-rates */ if ( GT_32( quo, IVAS_48k ) ) { diff --git a/lib_enc/ivas_osba_enc_fx.c b/lib_enc/ivas_osba_enc_fx.c index 66231d6f7..36ad9af0c 100644 --- a/lib_enc/ivas_osba_enc_fx.c +++ b/lib_enc/ivas_osba_enc_fx.c @@ -122,10 +122,11 @@ ivas_error ivas_osba_enc_open_fx( { hOSba->input_data_mem_fx[i] = NULL; } + + input_frame = extract_l( Mpy_32_32_r( st_ivas->hEncoderConfig->input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + Word16 tmp_e; - Word32 tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( st_ivas->hEncoderConfig->input_Fs, FRAMES_PER_SEC, &tmp_e ) ); - tmp32 = L_shr( tmp32, sub( 15, tmp_e ) ); - input_frame = extract_l( tmp32 ); + Word32 tmp32; FOR( i = 0; i < input_frame; i++ ) { diff --git a/lib_enc/ivas_spar_encoder_fx.c b/lib_enc/ivas_spar_encoder_fx.c index 12e9d1510..fc7a6a578 100644 --- a/lib_enc/ivas_spar_encoder_fx.c +++ b/lib_enc/ivas_spar_encoder_fx.c @@ -715,9 +715,7 @@ static ivas_error ivas_spar_enc_process_fx( num_del_samples = hSpar->hFbMixer->fb_cfg->fb_latency; move16(); - Word32 res_dec, res_frac; - iDiv_and_mod_32( input_Fs, FRAMES_PER_SEC, &res_dec, &res_frac, 0 ); - input_frame = extract_l( res_dec ); + input_frame = extract_l( Mpy_32_32_r( input_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); sba_order = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); nchan_inp = ivas_sba_get_nchan_metadata_fx( sba_order, hEncoderConfig->ivas_total_brate ); diff --git a/lib_enc/lib_enc_fx.c b/lib_enc/lib_enc_fx.c index 295608d6f..35fca9b16 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -42,6 +42,7 @@ #include "ivas_prot_fx.h" #include "prot_fx.h" #include "prot_fx_enc.h" +#include "ivas_rom_com_fx.h" #include "wmc_auto.h" #include "ivas_rom_enc.h" @@ -2242,11 +2243,11 @@ static ivas_error sanitizeBandwidth_fx( IF( NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { - Word32 quo = 0, rem; + Word32 tmp_br = 0; move32(); IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) { - iDiv_and_mod_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism, &quo, &rem, 0 ); + tmp_br = Mpy_32_32_r( hEncoderConfig->ivas_total_brate, one_by_q_level[hEncoderConfig->nchan_ism] ); } test(); @@ -2254,7 +2255,7 @@ static ivas_error sanitizeBandwidth_fx( test(); test(); IF( EQ_16( max_bwidth_tmp, FB ) && ( ( NE_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO ) ) || - ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( quo, MIN_BRATE_FB_ISM ) ) ) ) + ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( tmp_br, MIN_BRATE_FB_ISM ) ) ) ) { max_bwidth_tmp = SWB; move16(); diff --git a/lib_enc/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index aed3bf812..78dac8afa 100644 --- a/lib_enc/updt_enc_fx.c +++ b/lib_enc/updt_enc_fx.c @@ -675,10 +675,7 @@ void updt_enc_common_ivas_fx( st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 ); move16(); - Word16 exp; - st->L_frame = BASOP_Util_Divide3232_Scale( st->sr_core, FRAMES_PER_SEC, &exp ); - move16(); - st->L_frame = shr( st->L_frame, sub( 15, exp ) ); + st->L_frame = extract_l( Mpy_32_32_r( st->sr_core, ONE_BY_FRAMES_PER_SEC_Q31 ) ); move16(); IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) -- GitLab From 76bfaec1725fb1706e07bea484b6c0aa075b7512 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Aug 2025 20:14:22 +0200 Subject: [PATCH 2/7] fix --- lib_enc/ivas_mct_enc_fx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index ea9422436..7e62208f8 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -239,11 +239,11 @@ ivas_error ivas_mct_enc_fx( { Word32 cp_bitrate; // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hMCT->nchan_out_woLFE * CPE_CHANNELS] ); + cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[hMCT->nchan_out_woLFE] ); IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport * CPE_CHANNELS] ); + cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[st_ivas->nchan_transport] ); } IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) @@ -565,12 +565,12 @@ ivas_error create_mct_enc_fx( } // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hMCT->nchan_out_woLFE * CPE_CHANNELS] ); + cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[hMCT->nchan_out_woLFE] ); IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport * CPE_CHANNELS] ); + cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[st_ivas->nchan_transport] ); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -709,11 +709,11 @@ ivas_error mct_enc_reconfigure_fx( } // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hMCT->nchan_out_woLFE * CPE_CHANNELS] ); + cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[hMCT->nchan_out_woLFE] ); IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport * CPE_CHANNELS] ); + cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[st_ivas->nchan_transport] ); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) -- GitLab From 2cc368d9c43f855437f8018fbf868c41deebc00b Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Aug 2025 20:45:14 +0200 Subject: [PATCH 3/7] fix --- lib_enc/ivas_enc_fx.c | 4 ++-- lib_enc/ivas_init_enc_fx.c | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib_enc/ivas_enc_fx.c b/lib_enc/ivas_enc_fx.c index 11368cec8..c73a1a6b0 100644 --- a/lib_enc/ivas_enc_fx.c +++ b/lib_enc/ivas_enc_fx.c @@ -38,6 +38,7 @@ #include "rom_com.h" #include "prot_fx.h" #include "ivas_rom_com.h" +#include "ivas_rom_com_fx.h" #ifdef DEBUGGING #include "debug.h" #endif @@ -87,8 +88,7 @@ ivas_error ivas_enc_fx( input_frame = extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ); IF( NE_16( nchan_inp, 1 ) ) { - n_samples_chan = div_l( L_deposit_l( n_samples ), nchan_inp ); /* Q0 */ - n_samples_chan = shl( n_samples_chan, 1 ); /* Q0 */ + n_samples_chan = extract_l( Mpy_32_32_r( n_samples, one_by_q_level[nchan_inp] ) ); /* Q0 */ } ELSE { diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index 7613c21f9..f05b320ae 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -674,9 +674,9 @@ ivas_error ivas_init_encoder_fx( } } + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); IF( ( error = create_sce_enc_fx( st_ivas, sce_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; @@ -689,10 +689,10 @@ ivas_error ivas_init_encoder_fx( } } + tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -831,10 +831,10 @@ ivas_error ivas_init_encoder_fx( } } + tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -862,10 +862,10 @@ ivas_error ivas_init_encoder_fx( st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); /* Q0 */ #endif + tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -898,10 +898,10 @@ ivas_error ivas_init_encoder_fx( st_ivas->nCPE = shr( hEncoderConfig->nchan_inp, CPE_CHANNELS_LOG2 ); /* Q0 */ move16(); + tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[hEncoderConfig->nchan_inp] ), 1 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[hEncoderConfig->nchan_inp] ); - IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ) != IVAS_ERR_OK ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -934,9 +934,9 @@ ivas_error ivas_init_encoder_fx( return error; } + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nCPE] ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nCPE] ); IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; @@ -960,9 +960,10 @@ ivas_error ivas_init_encoder_fx( return error; } + i = add( st_ivas->nCPE, st_ivas->nSCE ); + tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[i] ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nSCE] ); IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; -- GitLab From b839e856772480b5410ee6be895453d026eec945 Mon Sep 17 00:00:00 2001 From: vaclav Date: Fri, 22 Aug 2025 21:25:36 +0200 Subject: [PATCH 4/7] fix --- lib_enc/ivas_init_enc_fx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index f05b320ae..f4f10e001 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -898,7 +898,8 @@ ivas_error ivas_init_encoder_fx( st_ivas->nCPE = shr( hEncoderConfig->nchan_inp, CPE_CHANNELS_LOG2 ); /* Q0 */ move16(); - tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[hEncoderConfig->nchan_inp] ), 1 ); + i = sub( hEncoderConfig->nchan_inp, 1 ); + tmp_br = L_shl( Mpy_32_32_r( L_sub( ivas_total_brate, ivas_total_brate % i ), one_by_q_level[i] - 1 ), 1 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) -- GitLab From 1ca9814e66b7a25819142b6312e32948eb654fc0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 23 Aug 2025 10:51:22 +0200 Subject: [PATCH 5/7] revert some changes --- lib_dec/ivas_corecoder_dec_reconfig_fx.c | 10 +++--- lib_dec/ivas_init_dec_fx.c | 43 ++++++++++++++---------- lib_enc/ivas_init_enc_fx.c | 24 +++++++------ lib_enc/ivas_mct_enc_fx.c | 29 ++++++++++------ lib_enc/ivas_omasa_enc_fx.c | 5 +-- lib_enc/lib_enc_fx.c | 7 ++-- 6 files changed, 67 insertions(+), 51 deletions(-) diff --git a/lib_dec/ivas_corecoder_dec_reconfig_fx.c b/lib_dec/ivas_corecoder_dec_reconfig_fx.c index 5deb57e8c..5b4c7f472 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig_fx.c +++ b/lib_dec/ivas_corecoder_dec_reconfig_fx.c @@ -33,7 +33,6 @@ #include "options.h" #include "ivas_cnst.h" #include "ivas_prot_fx.h" -#include "ivas_rom_com_fx.h" #include "prot_fx.h" #include #include "wmc_auto.h" @@ -57,7 +56,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( { Word16 n, sce_id, cpe_id, output_frame; Word16 nSCE_existing, nCPE_existing; - Word32 tmp_br, ivas_total_brate; + Word32 ivas_total_brate; Word16 nchan_transport_real; MC_MODE last_mc_mode; DECODER_CONFIG_HANDLE hDecoderConfig; @@ -410,10 +409,9 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* otherwise create extra dummy CPE */ ELSE { - /* i = ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) */ - n = add( st_ivas->nSCE, st_ivas->nCPE ); - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[n] ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, tmp_br ) ), IVAS_ERR_OK ) ) + Word32 quo, rem; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &quo, &rem, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, quo ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index f16290d05..4a4d07ee1 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -1581,7 +1581,7 @@ ivas_error ivas_init_decoder_fx( Word16 sce_id, cpe_id; Word16 numCldfbAnalyses, numCldfbSyntheses; Word16 granularity, n_channels_transport_jbm; - Word32 output_Fs, ivas_total_brate, tmp_br; + Word32 output_Fs, ivas_total_brate, tmp_br, tmp32; #ifdef NONBE_FIX_MC_LFE_LPF Word32 delay_ns; #else @@ -2002,9 +2002,9 @@ ivas_error ivas_init_decoder_fx( st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas ); move16(); + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; @@ -2013,10 +2013,11 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2028,10 +2029,10 @@ ivas_error ivas_init_decoder_fx( } /* create CPE element for DFT Stereo like upmix */ + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &tmp_br, &tmp32, 0 ); test(); IF( st_ivas->sba_dirac_stereo_flag && ( st_ivas->nCPE == 0 ) ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nSCE] ); IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; @@ -2080,9 +2081,9 @@ ivas_error ivas_init_decoder_fx( } } + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; @@ -2091,10 +2092,11 @@ ivas_error ivas_init_decoder_fx( reset_indices_dec( st_ivas->hSCE[sce_id]->hCoreCoder[0] ); } + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2216,10 +2218,11 @@ ivas_error ivas_init_decoder_fx( move16(); } + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2231,10 +2234,10 @@ ivas_error ivas_init_decoder_fx( } /* create CPE element for DFT Stereo like upmix */ + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &tmp_br, &tmp32, 0 ); test(); IF( st_ivas->sba_dirac_stereo_flag && st_ivas->nCPE == 0 ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[add( st_ivas->nSCE, st_ivas->nCPE )] ); IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; @@ -2400,10 +2403,12 @@ ivas_error ivas_init_decoder_fx( move16(); st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); + + iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2446,10 +2451,13 @@ ivas_error ivas_init_decoder_fx( st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); + + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ); - IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, L_shl( tmp_br, 1 ) ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) + { return error; } @@ -2482,9 +2490,10 @@ ivas_error ivas_init_decoder_fx( st_ivas->hParamMC->proto_matrix_int_e = 0; move16(); + + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &tmp_br, &tmp32, 0 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[add( st_ivas->nSCE, st_ivas->nCPE )] ); IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; @@ -2593,9 +2602,9 @@ ivas_error ivas_init_decoder_fx( } /* create CPE element for DFT Stereo like upmix */ + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &tmp_br, &tmp32, 0 ); IF( st_ivas->sba_dirac_stereo_flag ) { - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[add( st_ivas->nSCE, st_ivas->nCPE )] ); IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; diff --git a/lib_enc/ivas_init_enc_fx.c b/lib_enc/ivas_init_enc_fx.c index f4f10e001..570fda04c 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -38,7 +38,6 @@ #include "ivas_prot_fx.h" #include "ivas_stat_enc.h" #include "ivas_rom_com.h" -#include "ivas_rom_com_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" #include "prot_fx_enc.h" @@ -442,10 +441,11 @@ ivas_error ivas_init_encoder_fx( Word16 nchan_inp_buff; Word16 sce_id, cpe_id; IVAS_FORMAT ivas_format; - Word32 input_Fs, ivas_total_brate, tmp_br; + Word32 input_Fs, ivas_total_brate; Word32 element_brate_tmp[MAX_NUM_OBJECTS]; ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; + Word32 tmp_br, tmp32; error = IVAS_ERR_OK; move32(); @@ -674,7 +674,7 @@ ivas_error ivas_init_encoder_fx( } } - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ); + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { IF( ( error = create_sce_enc_fx( st_ivas, sce_id, tmp_br ) ) != IVAS_ERR_OK ) @@ -689,7 +689,8 @@ ivas_error ivas_init_encoder_fx( } } - tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) @@ -831,7 +832,8 @@ ivas_error ivas_init_encoder_fx( } } - tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) @@ -862,7 +864,8 @@ ivas_error ivas_init_encoder_fx( st_ivas->nCPE = add( st_ivas->nCPE, shr( add( st_ivas->hEncoderConfig->nchan_ism, 1 ), 1 ) ); /* Q0 */ #endif - tmp_br = L_shl( Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); + iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) @@ -898,8 +901,8 @@ ivas_error ivas_init_encoder_fx( st_ivas->nCPE = shr( hEncoderConfig->nchan_inp, CPE_CHANNELS_LOG2 ); /* Q0 */ move16(); - i = sub( hEncoderConfig->nchan_inp, 1 ); - tmp_br = L_shl( Mpy_32_32_r( L_sub( ivas_total_brate, ivas_total_brate % i ), one_by_q_level[i] - 1 ), 1 ); + iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &tmp_br, &tmp32, 0 ); + tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) @@ -935,7 +938,7 @@ ivas_error ivas_init_encoder_fx( return error; } - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[st_ivas->nCPE] ); + iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &tmp_br, &tmp32, 0 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) @@ -961,8 +964,7 @@ ivas_error ivas_init_encoder_fx( return error; } - i = add( st_ivas->nCPE, st_ivas->nSCE ); - tmp_br = Mpy_32_32_r( ivas_total_brate, one_by_q_level[i] ); + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nCPE, st_ivas->nSCE ), &tmp_br, &tmp32, 0 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) diff --git a/lib_enc/ivas_mct_enc_fx.c b/lib_enc/ivas_mct_enc_fx.c index 7e62208f8..735e7e191 100644 --- a/lib_enc/ivas_mct_enc_fx.c +++ b/lib_enc/ivas_mct_enc_fx.c @@ -39,7 +39,6 @@ #include "prot_fx.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" -#include "ivas_rom_com_fx.h" #include "prot_fx_enc.h" #include "rom_com.h" @@ -239,11 +238,12 @@ ivas_error ivas_mct_enc_fx( { Word32 cp_bitrate; // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[hMCT->nchan_out_woLFE] ); + cp_bitrate = L_shl( L_deposit_l( div_l( ivas_total_brate, hMCT->nchan_out_woLFE ) ), 2 ); // a/b => div_l(a, b/2) or (2 * div_l(a, b)) + IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[st_ivas->nchan_transport] ); + cp_bitrate = L_shl( L_deposit_l( div_l( ivas_total_brate, st_ivas->nchan_transport ) ), 2 ); // a/b => div_l(a, b/2) or (2 * div_l(a, b)) } IF( st_ivas->hCPE[0]->hCoreCoder[0]->igf ) @@ -564,13 +564,13 @@ ivas_error create_mct_enc_fx( move16(); } + Word32 L_tmp; + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), hMCT->nchan_out_woLFE, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[hMCT->nchan_out_woLFE] ); - IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), st_ivas->nchan_transport, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[st_ivas->nchan_transport] ); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -708,12 +708,13 @@ ivas_error mct_enc_reconfigure_fx( } } + Word32 L_tmp; + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), hMCT->nchan_out_woLFE, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / hMCT->nchan_out_woLFE * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[hMCT->nchan_out_woLFE] ); IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ) { + iDiv_and_mod_32( L_shl( ivas_total_brate, 1 ), st_ivas->nchan_transport, &cp_bitrate, &L_tmp, 0 ); // cp_bitrate = ivas_total_brate / st_ivas->nchan_transport * CPE_CHANNELS; - cp_bitrate = Mpy_32_32_r( L_shl( ivas_total_brate, 1 ), one_by_q_level[st_ivas->nchan_transport] ); } FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -1212,19 +1213,25 @@ static ivas_error ivas_mc_enc_reconfig_fx( { new_brate_SCE = 0; move32(); - new_brate_CPE = L_shl( Mpy_32_32_r( st_ivas->hEncoderConfig->ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ), 1 ); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { new_brate_SCE = 0; move32(); - new_brate_CPE = L_shl( Mpy_32_32_r( st_ivas->hEncoderConfig->ivas_total_brate, one_by_q_level[sub( st_ivas->nchan_transport, 1 )] ), 1 ); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } ELSE { new_brate_SCE = 0; /*st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport;*/ move32(); - new_brate_CPE = L_shl( Mpy_32_32_r( st_ivas->hEncoderConfig->ivas_total_brate, one_by_q_level[st_ivas->nchan_transport] ), 1 ); + Word32 res_dec, res_frac; + iDiv_and_mod_32( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 ); + new_brate_CPE = imult3216( res_dec, CPE_CHANNELS ); } IF( NE_32( ( error = ivas_corecoder_enc_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, new_brate_SCE, new_brate_CPE, last_mc_mode ) ), IVAS_ERR_OK ) ) diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index 1d9384d4c..838ca1944 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -38,7 +38,6 @@ #include "ivas_prot_fx.h" #include "prot_fx.h" #include "ivas_rom_com.h" -#include "ivas_rom_com_fx.h" #include "ivas_rom_enc.h" #include "wmc_auto.h" #ifdef DEBUGGING @@ -861,7 +860,9 @@ void ivas_set_ism_importance_interformat_fx( } } - Word32 quo = Mpy_32_32_r( ism_total_brate, one_by_q_level[nchan_transport] ); + Word32 quo, rem; + iDiv_and_mod_32( ism_total_brate, nchan_transport, &quo, &rem, 0 ); + /* do not use the low-rate core-coder mode at highest bit-rates */ if ( GT_32( quo, IVAS_48k ) ) { diff --git a/lib_enc/lib_enc_fx.c b/lib_enc/lib_enc_fx.c index 35fca9b16..295608d6f 100644 --- a/lib_enc/lib_enc_fx.c +++ b/lib_enc/lib_enc_fx.c @@ -42,7 +42,6 @@ #include "ivas_prot_fx.h" #include "prot_fx.h" #include "prot_fx_enc.h" -#include "ivas_rom_com_fx.h" #include "wmc_auto.h" #include "ivas_rom_enc.h" @@ -2243,11 +2242,11 @@ static ivas_error sanitizeBandwidth_fx( IF( NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) { - Word32 tmp_br = 0; + Word32 quo = 0, rem; move32(); IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) ) { - tmp_br = Mpy_32_32_r( hEncoderConfig->ivas_total_brate, one_by_q_level[hEncoderConfig->nchan_ism] ); + iDiv_and_mod_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism, &quo, &rem, 0 ); } test(); @@ -2255,7 +2254,7 @@ static ivas_error sanitizeBandwidth_fx( test(); test(); IF( EQ_16( max_bwidth_tmp, FB ) && ( ( NE_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO ) ) || - ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( tmp_br, MIN_BRATE_FB_ISM ) ) ) ) + ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( quo, MIN_BRATE_FB_ISM ) ) ) ) { max_bwidth_tmp = SWB; move16(); -- GitLab From bb5eabca499579cc640d57c9e4eeb90d0a7688d2 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 23 Aug 2025 19:51:40 +0200 Subject: [PATCH 6/7] fix --- lib_dec/ivas_init_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 4a4d07ee1..52a88137c 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -2452,7 +2452,7 @@ ivas_error ivas_init_decoder_fx( st_ivas->element_mode_init = IVAS_CPE_MDCT; move16(); - iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &tmp_br, &tmp32, 0 ); + iDiv_and_mod_32( ivas_total_brate, sub( st_ivas->nchan_transport, 1 ), &tmp_br, &tmp32, 0 ); tmp_br = L_shl( tmp_br, CPE_CHANNELS_LOG2 ); FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { -- GitLab From c1821a85df0c642bd8383244891abea15dbd8833 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 26 Aug 2025 17:05:16 +0200 Subject: [PATCH 7/7] replace division by multiplication in ivas_ism_config_fx() --- lib_com/ivas_ism_com_fx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_com/ivas_ism_com_fx.c b/lib_com/ivas_ism_com_fx.c index 1b61ee4ac..4cb4b5df2 100644 --- a/lib_com/ivas_ism_com_fx.c +++ b/lib_com/ivas_ism_com_fx.c @@ -146,7 +146,7 @@ ivas_error ivas_ism_config_fx( /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */ // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); bits_ism = extract_l( Mpy_32_32_r( ONE_BY_FRAMES_PER_SEC_Q31, ism_total_brate ) ); // Q0 - tmp1 = extract_l( Mpy_32_32_r( sub( bits_ism, bits_ism % n_ISms ), one_by_q_level[n_ISms] ) ); + tmp1 = extract_h( Mpy_32_16_r( one_by_q_level[n_ISms], bits_ism ) ); set16_fx( bits_element, tmp1, n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); @@ -158,7 +158,7 @@ ivas_error ivas_ism_config_fx( /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */ // bits_ism = (Word16) ( ism_total_brate / FRAMES_PER_SEC ); bits_ism = extract_l( Mpy_32_32_r( ONE_BY_FRAMES_PER_SEC_Q31, ism_total_brate ) ); // Q0 - tmp1 = extract_l( Mpy_32_32_r( sub( bits_ism, bits_ism % n_ISms ), one_by_q_level[n_ISms] ) ); + tmp1 = extract_h( Mpy_32_16_r( one_by_q_level[n_ISms], bits_ism ) ); set16_fx( bits_element, tmp1, n_ISms ); bits_element[n_ISms - 1] = add( bits_element[n_ISms - 1], bits_ism % n_ISms ); // Q0 move16(); -- GitLab