diff --git a/lib_com/ivas_fb_mixer_fx.c b/lib_com/ivas_fb_mixer_fx.c index b55e069d7deb8c63ba5af5f69170ddf2dfcf3057..a457952947ff81f0851fb1d27fa81953b2e24fa5 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 5f1a13afb7ca1a431d823a6d5461813e136c34a0..4cb4b5df2ca091d0c60195b4bebe71a552ef078a 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_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(); @@ -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_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(); bitbudget_to_brate( bits_element, element_brate, n_ISms ); diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index a149f78b3b0de6836ef7b36ef250a63440048ec7..ac16c4a2d4d94abc8729404d6be2e33bbfff0bfe 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -88,7 +88,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(); @@ -269,9 +268,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(); } @@ -316,23 +315,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 ) ) @@ -365,9 +363,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 ); } } @@ -399,19 +396,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 ) { @@ -429,14 +424,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(); @@ -467,10 +461,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(); @@ -481,14 +474,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(); @@ -586,8 +578,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 8d033c851a04451987322738106ff5c2c7b97de2..47c69e891d8c537f5e22da548122e00b73dfc7ee 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -1248,7 +1248,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(); @@ -1256,8 +1255,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 ) { @@ -1347,8 +1345,8 @@ 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 ); - st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS ) ); + i = extract_l( Mpy_32_32_r( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + st->next_bit_pos = sub( sub( i, 1 ), SID_FORMAT_NBITS + SBA_PLANAR_BITS + SBA_ORDER_BITS ); move16(); /* 1 bit flag for signaling metadata to read */ diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 5a87800f7e941d32a6d9f05a69bf7dea6a507313..6d1b09d21d918ea3cba1bee1a5416ebde3f9e4ee 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" @@ -583,9 +584,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 ) ) { @@ -635,9 +635,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(); @@ -650,7 +649,7 @@ ivas_error ivas_dec_setup( move16(); } /* 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 ) ) { @@ -719,9 +718,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(); @@ -742,9 +740,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 */ @@ -879,9 +876,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(); @@ -955,9 +951,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 ) ) @@ -1207,9 +1202,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(); @@ -1502,7 +1496,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, tmp32; Word32 delay_ns; AUDIO_CONFIG output_config; DECODER_CONFIG_HANDLE hDecoderConfig; @@ -1863,11 +1857,10 @@ 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++ ) { - 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 ) ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -1875,11 +1868,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++ ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -1891,13 +1884,11 @@ 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 ) ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -1945,11 +1936,10 @@ 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++ ) { - 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 ) ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -1957,11 +1947,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++ ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2068,11 +2058,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++ ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2084,12 +2074,11 @@ 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 ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2254,11 +2243,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++ ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2301,11 +2291,13 @@ ivas_error ivas_init_decoder_fx( 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++ ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) + { return error; } @@ -2338,12 +2330,11 @@ 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++ ) { - 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 ) ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, tmp_br ) ), IVAS_ERR_OK ) ) { return error; } @@ -2451,11 +2442,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 ); 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 ) ) + 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 17bc36346f7f6efd58cdafdbbf5095f71e52c5cd..876636be645f70deb1a751b5763dbfe7d71221c2 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 1b7435305f4817f52f9976367c91b48e40d2b329..a7a95b5a677a4345c9991e836599acfd37904f49 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 a0fa5a3d59934aa287810ff2cec588cc9e36e1dc..11a06abd496fb5e39b958facbbad0700779a5c30 100644 --- a/lib_dec/ivas_ism_renderer_fx.c +++ b/lib_dec/ivas_ism_renderer_fx.c @@ -90,18 +90,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(); @@ -430,15 +426,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 608440286b2d778c0a2ff5bb3dfc61573fc92bd6..243377a498dbcba545268605ebfa8bb7ada48930 100644 --- a/lib_dec/ivas_mc_param_dec_fx.c +++ b/lib_dec/ivas_mc_param_dec_fx.c @@ -248,12 +248,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 2762fc835de4fabc7fcfac06fdcafd3958054922..47cb02d1ecfa3da721314e6dd869eeec7ad85c9c 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 7c3d425242b4da4855b7663ffb5b9ccff22c0dd5..d0c22e7b6c8f1e07df8a62282775d6e621f6a833 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 { @@ -421,13 +419,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(); @@ -1626,9 +1624,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 7cb567771f5280f58f23831eccabc20166a7a831..af35143c262ede95611fea4b1546eebe8cf691d7 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]; @@ -266,8 +264,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 fb5fd037a51694a3422381d0784d3368ed1f37e3..78ae3a2fbecdd97b9f0756503e20fba149c1d11b 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 b5e1abbca2d5383df9a9a9538635b2e2cad57058..026a9e046bfc68f50c7525706cbb01b9a3a59e5e 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 0ee479a7cf59f692fc95738e97befb45c88daecd..2990c07eb6a3657afb18d9638ac3e701e0709515 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_enc_fx.c b/lib_enc/ivas_enc_fx.c index 11368cec8f39d7fb776803aa4529e5a570ad68ca..c73a1a6b0b181b90cbc8a2b84afa491b390ecb60 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 5a3592ad2bf0cf154f080bfc5e3c358378f814d5..bad3361d0818cf3725e137ff2bc4443196efeecd 100644 --- a/lib_enc/ivas_init_enc_fx.c +++ b/lib_enc/ivas_init_enc_fx.c @@ -433,6 +433,7 @@ ivas_error ivas_init_encoder_fx( Word32 element_brate_tmp[MAX_NUM_OBJECTS]; ENCODER_CONFIG_HANDLE hEncoderConfig; ivas_error error; + Word32 tmp_br, tmp32; error = IVAS_ERR_OK; move32(); @@ -661,11 +662,10 @@ ivas_error ivas_init_encoder_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++ ) { - 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 ) + IF( ( error = create_sce_enc_fx( st_ivas, sce_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -677,11 +677,11 @@ ivas_error ivas_init_encoder_fx( } } + 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++ ) { - 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 ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -812,11 +812,11 @@ ivas_error ivas_init_encoder_fx( } } + 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++ ) { - 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 ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -840,11 +840,11 @@ ivas_error ivas_init_encoder_fx( st_ivas->nCPE = shr_r( n_all, 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++ ) { - 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 ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -877,11 +877,11 @@ ivas_error ivas_init_encoder_fx( st_ivas->nCPE = shr( hEncoderConfig->nchan_inp, CPE_CHANNELS_LOG2 ); /* Q0 */ move16(); + 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++ ) { - 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 ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -914,11 +914,10 @@ ivas_error ivas_init_encoder_fx( return error; } + 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++ ) { - 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 ) + IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, tmp_br ) ) != IVAS_ERR_OK ) { return error; } @@ -941,11 +940,10 @@ ivas_error ivas_init_encoder_fx( return error; } + 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++ ) { - 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 ) + 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 2f765fe058b6debab7c39d7da857f622f3d25a5a..6299fc55cceae0ac5e954bd9362e652bd61b3157 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -2948,7 +2948,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(); @@ -2969,7 +2969,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_osba_enc_fx.c b/lib_enc/ivas_osba_enc_fx.c index 5ab29f617e527fd1fdf35a7533cf9a1ae08b0e2a..424e56e4d26131d02790cb5aaa22c67f863e9507 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 04b4049a7eefa7d12d9752309c5cdbc10ad741df..481b969b70cc3e830d3fe8346613775ad9e90243 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/updt_enc_fx.c b/lib_enc/updt_enc_fx.c index aed3bf81271924fb7dbf5f7228293c5434829f37..78dac8afab9f60e3ffefca2b8d3d41f2ad5b1ceb 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 ) )