From 02f044cc0a7eb13ac31e7490420f70a21be48e08 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 22 Jul 2024 20:04:08 +0530 Subject: [PATCH] BASOP changes for lib_com files --- lib_com/ivas_fb_mixer.c | 4 + lib_com/ivas_prot.h | 14 +- lib_com/ivas_prot_fx.h | 22 + lib_com/ivas_spar_com.c | 1281 ++++++++++++++++--------- lib_com/ivas_stereo_dft_com.c | 12 +- lib_com/ivas_stereo_eclvq_com_fx.c | 5 + lib_com/ivas_stereo_ica_com_fx.c | 124 ++- lib_com/ivas_stereo_mdct_bands_com.c | 113 ++- lib_com/ivas_stereo_mdct_stereo_com.c | 4 +- lib_com/ivas_stereo_psychlpc_com.c | 14 +- lib_com/ivas_stereo_td_bit_alloc.c | 620 +++++++----- lib_com/ivas_transient_det.c | 115 ++- lib_com/lag_wind.c | 5 +- lib_dec/ivas_sba_dec.c | 4 + lib_dec/ivas_spar_decoder.c | 4 + lib_enc/ivas_mct_core_enc.c | 4 + lib_enc/ivas_osba_enc.c | 4 + lib_enc/ivas_sba_enc.c | 4 + lib_enc/ivas_spar_encoder.c | 8 + lib_enc/ivas_spar_md_enc.c | 4 + 20 files changed, 1549 insertions(+), 816 deletions(-) diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index 59b62491c..d448ed8de 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -116,7 +116,11 @@ int16_t ivas_get_num_bands_from_bw_idx( static Word16 ivas_get_num_bands( const Word32 sampling_rate ) { +#ifdef IVAS_FLOAT_FIXED + Word16 bwidth = ivas_get_bw_idx_from_sample_rate_fx( sampling_rate ); +#else Word16 bwidth = ivas_get_bw_idx_from_sample_rate( sampling_rate ); +#endif Word16 num_active_bands = ivas_get_num_bands_from_bw_idx( bwidth ); return num_active_bands; diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index e476e3a49..3cfacb4b1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5492,13 +5492,13 @@ ivas_error ivas_spar_dec( ); void ivas_spar_config( - int32_t ivas_total_brate, /* i : codec total bitrate */ - const int16_t sba_order, /* i : Ambisonic (SBA) order */ - int16_t *nchan_transport, /* o : number of transport channels */ - int16_t *nSCE, /* o : number of SCEs */ - int16_t *nCPE, /* o : number of CPEs */ - int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ - const int16_t sid_format /* i : IVAS format indicator from SID frame */ + int32_t ivas_total_brate, /* i : codec total bitrate */ + const int16_t sba_order, /* i : Ambisonic (SBA) order */ + int16_t *nchan_transport, /* o : number of transport channels */ + int16_t *nSCE, /* o : number of SCEs */ + int16_t *nCPE, /* o : number of CPEs */ + int32_t *core_nominal_brate, /* o : core-coding nominal bitrate */ + const int16_t sid_format /* i : IVAS format indicator from SID frame */ ); #ifdef IVAS_FLOAT_FIXED ivas_error ivas_sba_linear_renderer_fx( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index c24ad3237..9ea7a8264 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -2517,3 +2517,25 @@ void stereo_coder_tcx_fx( const Word16 mct_on, /* i : flag mct block (1) or stereo (0) */ Word16 q_spec ); #endif + +void ivas_spar_config_fx( + Word32 ivas_total_brate, /* i : codec total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word16 *nchan_transport, /* o : number of transport channels */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE, /* o : number of CPEs */ + Word32 *core_nominal_brate, /* o : core-coding nominal bitrate */ + const Word16 sid_format /* i : IVAS format indicator from SID frame */ +); + +Word16 ivas_get_bw_idx_from_sample_rate_fx( + const Word32 sampling_rate /* i : sampling rate */ +); + +void ivas_spar_bitrate_dist_fx( + Word32 core_brates_act[], /* o : bitrates per core-coder */ + const Word16 nAvailBits, /* i : number of available bits */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 bwidth /* i : audio bandwidth */ +); diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 485424125..2a29c6074 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -128,6 +128,7 @@ static void ivas_calc_mat_inv( float in_re[MAX_MAT_DIM][MAX_MAT_DIM], const int1 *-----------------------------------------------------------------------------------------*/ /*! r: audio BW index */ +#ifndef IVAS_FLOAT_FIXED int16_t ivas_get_bw_idx_from_sample_rate( const int32_t sampling_rate /* i : sampling rate */ ) @@ -152,6 +153,35 @@ int16_t ivas_get_bw_idx_from_sample_rate( return bwidth; } +#else +Word16 ivas_get_bw_idx_from_sample_rate_fx( + const Word32 sampling_rate /* i : sampling rate */ +) +{ + Word16 bwidth = 0; + move16(); + + SWITCH( sampling_rate ) + { + case 16000: + bwidth = WB; + move16(); + BREAK; + case 32000: + bwidth = SWB; + move16(); + BREAK; + case 48000: + bwidth = FB; + move16(); + BREAK; + default: + assert( !"Unsupported sample rate!" ); + } + + return bwidth; +} +#endif /*------------------------------------------------------------------------- * ivas_spar_config() @@ -159,6 +189,7 @@ int16_t ivas_get_bw_idx_from_sample_rate( * SPAR configuration function *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_config( int32_t ivas_total_brate, /* i : codec total bitrate */ const int16_t sba_order, /* i : Ambisonic (SBA) order */ @@ -217,6 +248,84 @@ void ivas_spar_config( return; } +#else +void ivas_spar_config_fx( + Word32 ivas_total_brate, /* i : codec total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + Word16 *nchan_transport, /* o : number of transport channels */ + Word16 *nSCE, /* o : number of SCEs */ + Word16 *nCPE, /* o : number of CPEs */ + Word32 *core_nominal_brate, /* o : core-coding nominal bitrate */ + const Word16 sid_format /* i : IVAS format indicator from SID frame */ +) +{ + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + IF( EQ_16( sid_format, SID_SBA_1TC ) ) + { + *nchan_transport = 1; + move16(); + } + ELSE + { + *nchan_transport = 2; + move16(); + } + } + ELSE + { + *nchan_transport = ivas_get_sba_num_TCs( ivas_total_brate, sba_order ); + move16(); + } + + IF( GT_16( *nchan_transport, 1 ) ) + { + *nCPE = shr( add( *nchan_transport, 1 ), 1 ); + move16(); + } + ELSE + { + *nCPE = 0; + move16(); + } + + *nSCE = max( 0, sub( *nchan_transport, shl( *nCPE, 1 ) ) ); + move16(); + + IF( EQ_16( *nchan_transport, 1 ) ) + { + /* map SPAR SID bitrate to SPAR active bitrate */ + IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) + { + ivas_total_brate = IVAS_32k; + move32(); + } + assert( ivas_total_brate == IVAS_32k || ivas_total_brate == IVAS_24k4 || ivas_total_brate == IVAS_16k4 || ivas_total_brate == IVAS_13k2 ); + IF( EQ_32( ivas_total_brate, IVAS_32k ) ) + { + *core_nominal_brate = ACELP_24k40; + move32(); + } + ELSE IF( EQ_32( ivas_total_brate, IVAS_24k4 ) ) + { + *core_nominal_brate = ACELP_16k40; + move32(); + } + ELSE IF( EQ_32( ivas_total_brate, IVAS_16k4 ) ) + { + *core_nominal_brate = ACELP_13k20; + move32(); + } + ELSE IF( EQ_32( ivas_total_brate, IVAS_13k2 ) ) + { + *core_nominal_brate = ACELP_9k60; + move32(); + } + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_get_spar_table_idx() @@ -283,14 +392,21 @@ Word16 ivas_get_spar_table_idx_fx( { Word16 table_idx = 0, ind1[IVAS_SPAR_BR_TABLE_LEN]; Word16 i, j = 0, ind2 = -1; + move16(); + move16(); + move16(); FOR( i = 0; i < IVAS_SPAR_BR_TABLE_LEN; i++ ) { ind1[j] = 0; + move16(); + test(); IF( ( EQ_32( ivas_spar_br_table_consts[i].ivas_total_brate, ivas_total_brate ) ) && ( EQ_16( ivas_spar_br_table_consts[i].sba_order, sba_order ) ) ) { - ind1[j++] = i; + ind1[j] = i; + j = add( j, 1 ); + move16(); } } @@ -299,6 +415,7 @@ Word16 ivas_get_spar_table_idx_fx( IF( EQ_16( ivas_spar_br_table_consts[ind1[i]].bwidth, bwidth ) ) { ind2 = i; + move16(); BREAK; } } @@ -306,15 +423,18 @@ Word16 ivas_get_spar_table_idx_fx( assert( ind2 >= 0 ); /* to check if bw entry is present */ table_idx = ind1[ind2]; + move16(); IF( ind != NULL ) { *ind = ind2; + move16(); } IF( bitlen != NULL ) { - *bitlen = ivas_get_bits_to_encode( j - 1 ); + *bitlen = ivas_get_bits_to_encode( sub( j, 1 ) ); + move16(); } return table_idx; @@ -352,6 +472,7 @@ Word16 ivas_get_sba_num_TCs_fx( table_idx = ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); return nchan_transport; } @@ -600,46 +721,67 @@ static void ivas_get_pred_coeffs_fx( Word16 pred_dim = sub( in_chans, 1 ); Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; - w_norm_fac = EQ_16( from_dirac, 1 ) ? ONE_IN_Q29 : 3 * ONE_IN_Q29; // Q29 + IF( EQ_16( from_dirac, 1 ) ) + { + w_norm_fac = ONE_IN_Q29; + move32(); + } + ELSE + { + w_norm_fac = 3 * ONE_IN_Q29; + move32(); + } tmp_shift = Q30; - IF( EQ_16( active_w, 0 ) ) + move16(); + IF( active_w == 0 ) { Word32 pPred_temp[IVAS_MAX_NUM_BANDS]; Word16 q_pred_temp; prev_tmp_shift = 31; + move16(); set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); FOR( k = start_band; k < end_band; k++ ) { div_factor[k] = L_max( 1, cov_real[0][0][k] ); + move32(); tmp_shift = Q30; + move16(); IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) { div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - if ( LT_16( s_div, 0 ) ) + move32(); + IF( s_div < 0 ) { - div_shift = 15 + ( s_div ); + div_shift = add( 15, s_div ); tmp_shift = Q30; + move16(); } - else + ELSE { div_shift = 15; - tmp_shift = Q30 - s_div; + move16(); + tmp_shift = sub( Q30, s_div ); } div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move16(); IF( LT_16( tmp_shift, prev_tmp_shift ) ) { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], prev_tmp_shift - tmp_shift ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); } prev_tmp_shift = tmp_shift; + move16(); } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], tmp_shift - prev_tmp_shift ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); tmp_shift = prev_tmp_shift; + move16(); } } } @@ -648,68 +790,87 @@ static void ivas_get_pred_coeffs_fx( { FOR( k = start_band; k < end_band; k++ ) { - ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + ppPred_coeffs_re[i][k] = Mpy_32_32( cov_real[add( i, 1 )][0][k], div_factor[k] ); // Q30 + temp_shift - 31 => tmp_shift - 1 + move32(); // IVAS_CALCULATE_SQ_ABS_N( ppPred_coeffs_re[i][k], abs_value ); abs_value = Mpy_32_32( ppPred_coeffs_re[i][k], ppPred_coeffs_re[i][k] ); // Q = 2*tmp_shift - 2 - 31 pPred_temp[k] = L_add( pPred_temp[k], abs_value ); // Q= 2*tmp_shift - 2 - 31 + move32(); } } - *q_pred_coeffs = tmp_shift - 1; + *q_pred_coeffs = sub( tmp_shift, 1 ); + move16(); + FOR( k = start_band; k < end_band; k++ ) { - q_pred_temp = 31 - ( 2 * ( *q_pred_coeffs ) - 31 ); + q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); + move32(); IF( LT_16( q_pred_temp, 1 ) ) { - pPred_temp[k] = L_shr( pPred_temp[k], abs_s( q_pred_temp ) + 1 ); // Q30 + pPred_temp[k] = L_shr( pPred_temp[k], add( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); q_pred_temp = 1; + move16(); } ELSE IF( GT_16( q_pred_temp, 1 ) ) { - pPred_temp[k] = L_shl( pPred_temp[k], abs_s( q_pred_temp ) - 1 ); // Q30 + pPred_temp[k] = L_shl( pPred_temp[k], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); q_pred_temp = 1; + move16(); } - one_in_q = L_shl( 1, ( 31 - q_pred_temp ) ); + one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); IF( LT_32( one_in_q, pPred_temp[k] ) ) { div_factor[k] = pPred_temp[k]; + move32(); div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( one_in_q, div_factor[k], &s_div ) ); - if ( LT_16( s_div, 0 ) ) + move32(); + IF( s_div < 0 ) { - div_shift = 15 + ( s_div ); + div_shift = add( 15, s_div ); tmp_shift = Q30; + move16(); } - else + ELSE { div_shift = 15; - tmp_shift = Q30 - s_div; + move16(); + tmp_shift = sub( Q30, s_div ); } div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); } ELSE { div_factor[k] = one_in_q; - tmp_shift = ( 31 - q_pred_temp ); + move32(); + tmp_shift = sub( 31, q_pred_temp ); } IF( LT_16( tmp_shift, prev_tmp_shift ) ) { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], prev_tmp_shift - tmp_shift ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); } prev_tmp_shift = tmp_shift; + move16(); } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], tmp_shift - prev_tmp_shift ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); tmp_shift = prev_tmp_shift; + move16(); } } @@ -718,11 +879,14 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { ppPred_coeffs_re[i][k] = Mpy_32_32( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_pred_coeffs + tmp_shift -31 + move32(); ppDM_Fv_re[i][k] = 0; + move32(); } } - *q_pred_coeffs = *q_pred_coeffs + tmp_shift - 31; + *q_pred_coeffs = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); *q_dm_fv_re = 0; + move16(); } ELSE { @@ -737,14 +901,21 @@ static void ivas_get_pred_coeffs_fx( prev_tmp_shift = 31; dm_alpha_e = 0; Word16 dm_beta_re_e = 0; + move32(); + move16(); + move16(); + move16(); + IF( EQ_16( dyn_active_w_flag, 1 ) ) { activew_quad_thresh = ONE_IN_Q29; + move32(); } ELSE { activew_quad_thresh = IVAS_LIN_ACTIVEW_QUAD_ACTIVEW_THRESH_Q29; + move32(); } g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 @@ -757,50 +928,65 @@ static void ivas_get_pred_coeffs_fx( // IVAS_CALCULATE_SQ_ABS_N( cov_real[i][0][k], abs_value ); abs_value = Mpy_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q29 dm_alpha[k] = L_add( dm_alpha[k], abs_value ); // Q29 + move32(); } } FOR( k = start_band; k < end_band; k++ ) { - dm_alpha_e = 31 - Q29; + dm_alpha_e = sub( 31, Q29 ); dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); - IF( LT_16( dm_alpha_e, 0 ) ) + move32(); + IF( dm_alpha_e < 0 ) { dm_alpha[k] = L_shr( dm_alpha[k], abs_s( dm_alpha_e ) ); + move32(); dm_alpha_e = 0; + move16(); } - ELSE IF( GT_16( dm_alpha_e, 0 ) ) + ELSE IF( dm_alpha_e > 0 ) { dm_alpha[k] = L_shl( dm_alpha[k], abs_s( dm_alpha_e ) ); + move32(); dm_alpha_e = 0; + move16(); } div_factor[k] = L_max( dm_alpha[k], 1 ); + move32(); div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - if ( LT_16( s_div, 0 ) ) + move32(); + IF( s_div < 0 ) { - div_shift = 15 + ( s_div ); + div_shift = add( 15, s_div ); tmp_shift = Q30; + move16(); } - else + ELSE { div_shift = 15; - tmp_shift = Q30 - s_div; + move16(); + tmp_shift = sub( Q30, s_div ); } div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + move32(); IF( LT_16( tmp_shift, prev_tmp_shift ) ) { FOR( p = start_band; p < k; p++ ) { - div_factor[p] = L_shr( div_factor[p], prev_tmp_shift - tmp_shift ); + div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); + move32(); } prev_tmp_shift = tmp_shift; + move16(); } ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) { - div_factor[k] = L_shr( div_factor[k], tmp_shift - prev_tmp_shift ); + div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); + move32(); tmp_shift = prev_tmp_shift; + move16(); } } @@ -809,16 +995,27 @@ static void ivas_get_pred_coeffs_fx( FOR( k = start_band; k < end_band; k++ ) { dm_v_re[i][k] = Mpy_32_32( cov_real[i + 1][0][k], div_factor[k] ); // Q30 + Qb - 31 = tmp_shift - 1 + move32(); } } - IF( EQ_16( dtx_vad, 0 ) ) + IF( dtx_vad == 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + move32(); } ELSE { - dm_f_local = ( active_w_vlbr ) ? IVAS_ACTIVEW_DM_F_VLBR_Q30 : IVAS_ACTIVEW_DM_F_Q30; + IF( active_w_vlbr ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_VLBR_Q30; + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_Q30; + move32(); + } } FOR( b = start_band; b < end_band; b++ ) @@ -832,11 +1029,13 @@ static void ivas_get_pred_coeffs_fx( Word32 re; // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - re = Mpy_32_32( cov_real[j + 1][k][b], dm_v_re[k - 1][b] ); // Q30 + Q_div_factor - 1 - 31 - real[j] = L_add( real[j], re ); // tmp_shift - 2 + re = Mpy_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); // Q30 + Q_div_factor - 1 - 31 + real[j] = L_add( real[j], re ); // tmp_shift - 2 + move32(); } } dm_beta_re = 0; + move32(); FOR( k = 0; k < pred_dim; k++ ) { Word32 re; @@ -845,37 +1044,45 @@ static void ivas_get_pred_coeffs_fx( dm_beta_re = L_add( dm_beta_re, re ); // Q = 2*tmp_shift - 3 - 31 } - dm_beta_re_e = 31 - ( 2 * tmp_shift - 3 - 31 ); + dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); dm_w = cov_real[0][0][b]; // Q30 + move32(); den_f = L_max( dm_w, 1 ); passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); - div_shift = 15 - ( 31 - dm_alpha_e - Q30 ) + s_div - 1; + div_shift = add( ( sub( 15, ( sub( ( sub( 31, dm_alpha_e ) ), Q30 ) ) ) ), sub( s_div, 1 ) ); passive_g = L_shl( passive_g, div_shift ); // Q = 29 IF( EQ_16( dyn_active_w_flag, 1 ) ) { dm_alpha[b] = 0; + move32(); dm_w = 0; + move32(); FOR( i = 0; i < pred_dim; i++ ) { dm_v_re[i][b] = 0; + move32(); } IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) { - dm_v_re[res_ind - 1][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + move32(); } ELSE { - dm_v_re[res_ind - 1][b] = MAX_32; + dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + move32(); } passive_g = activew_quad_thresh; + move32(); } IF( LT_32( passive_g, activew_quad_thresh ) ) { /*linear activeW*/ dm_y = 0; + move32(); FOR( k = 1; k < in_chans; k++ ) { @@ -885,31 +1092,37 @@ static void ivas_get_pred_coeffs_fx( den_f = L_max( den_f, Mpy_32_32( w_norm_fac, dm_w ) ); // Q28 DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + 31 - dm_alpha_e - 31 + den_f_e - 31 => den_f_e - dm_alpha_e - 1 + move32(); - div_shift = 15 - ( 30 - (dm_alpha_e) -28 ) + s_div; + div_shift = add( ( sub( 15, ( sub( ( sub( 30, dm_alpha_e ) ), 28 ) ) ) ), s_div ); DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + move32(); L_tmp1 = L_add( L_shr( dm_w, 1 ), Mpy_32_32( dm_alpha[b], DM_F[b] ) ); /* Q 29*/ L_tmp2 = Mpy_32_32( Mpy_32_32( DM_F[b], DM_F[b] ), dm_beta_re ); - L_tmp2_q = 29 + 2 * tmp_shift - 65; // simplified equation for calculating Q of L_tmp2 - L_tmp2 = L_shl( L_tmp2, ( 29 - L_tmp2_q ) ); + L_tmp2_q = add( 29, sub( shl( tmp_shift, 1 ), 65 ) ); // simplified equation for calculating Q of L_tmp2 + L_tmp2 = L_shl( L_tmp2, sub( 29, L_tmp2_q ) ); den_f = L_add( L_tmp1, L_tmp2 ); // Q29 den_f = L_max( den_f, 1 ); den_f_e = 29; + move16(); L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); - L_tmp2_q = 30 + 2 * tmp_shift - 34 - 31; - L_tmp2 = L_shl( L_tmp2, ( 30 - dm_alpha_e - L_tmp2_q ) ); - L_tmp1 = L_shr( dm_alpha[b], ( 31 - dm_alpha_e - 30 ) ); + L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 30, dm_alpha_e ) ), L_tmp2_q ) ) ); + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 30 ) ) ); L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q30 dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q30 + den_f_e - 31 - div_shift = 15 - ( 30 - ( den_f_e ) ) + s_div; + move32(); + div_shift = add( sub( 15, ( sub( 30, den_f_e ) ) ), s_div ); dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + move32(); } ELSE { @@ -923,18 +1136,21 @@ static void ivas_get_pred_coeffs_fx( sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ val_e = 4; + move16(); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, 4, Mpy_32_32( dm_beta_re, dm_beta_re ), 2 * dm_beta_re_e, &val_e ); sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, L_negate( L_shl( Mpy_32_32( Mpy_32_32( dm_beta_re, g_th_sq ), dm_w ), 2 ) ), add( dm_beta_re_e, 4 + 1 ), &val_e ); // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); - IF( LT_16( val_e, 0 ) ) + IF( val_e < 0 ) { sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); } - ELSE IF( GT_16( val_e, 0 ) ) + ELSE IF( val_e > 0 ) { sqrt_val = L_shl( sqrt_val, abs_s( val_e ) ); val_e = 0; + move16(); } num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, 0, &num_f_e ); @@ -942,10 +1158,13 @@ static void ivas_get_pred_coeffs_fx( den_f_e = add( dm_beta_re_e, 4 ); den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 + move32(); DM_F[b] = BASOP_Util_Divide3232_Scale_cadence( Mpy_32_32( dm_g[b], num_f ), den_f, &s_dm_f ); + move32(); s_dm_f = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); /*Resultant exp for DM_F s_dm_f +( 2 + num_f_e ) - den_f_e*/ div_shift = sub( s_dm_f, 1 ); DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 + move32(); } } @@ -954,11 +1173,15 @@ static void ivas_get_pred_coeffs_fx( FOR( b = start_band; b < end_band; b++ ) { ppPred_coeffs_re[i][b] = Mpy_32_32( dm_v_re[i][b], dm_g[b] ); // Q = tmp_shift - 1 + 30 - 31 + move32(); ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + move32(); } } - *q_pred_coeffs = tmp_shift - 2; - *q_dm_fv_re = tmp_shift - 2; + *q_pred_coeffs = sub( tmp_shift, 2 ); + move16(); + *q_dm_fv_re = sub( tmp_shift, 2 ); + move16(); } return; @@ -1070,12 +1293,12 @@ static void ivas_get_Wscaling_factor_fx( set32_fx( postpred_cov_re[ch], 0, IVAS_SPAR_MAX_CH ); } - IF( EQ_16( dtx_vad, 0 ) ) + IF( dtx_vad == 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; // Q31 move32(); } - ELSE IF( NE_16( active_w_vlbr, 0 ) ) + ELSE IF( active_w_vlbr != 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; // Q31 move32(); @@ -1092,7 +1315,7 @@ static void ivas_get_Wscaling_factor_fx( move32(); test(); - IF( EQ_16( active_w, 1 ) && EQ_16( dyn_active_w_flag, 0 ) ) + IF( EQ_16( active_w, 1 ) && ( dyn_active_w_flag == 0 ) ) { Word16 guard_bits, q_Gw_sq, q_g_sq, q_min, tmp_exp; Word32 Gw_sq, g_sq, tmp; @@ -1110,7 +1333,7 @@ static void ivas_get_Wscaling_factor_fx( guard_bits = find_guarded_bits_fx( num_ch ); - FOR( ch = 0; ch < num_ch - 1; ch++ ) + FOR( ch = 0; ch < sub( num_ch, 1 ); ch++ ) { abs_val = L_shr( Mpy_32_32( pred_coeffs_re[ch][b], pred_coeffs_re[ch][b] ), guard_bits ); g_sq = L_add( g_sq, abs_val ); @@ -1143,6 +1366,7 @@ static void ivas_get_Wscaling_factor_fx( tmp = L_shr( tmp, sub( q_tmp, q_min ) ); pWscale[b] = Mpy_32_32( L_add( Gw_sq, tmp ), ONE_IN_Q30 /* 0.5 in Q31*/ ); + move32(); q_pWscale[b] = q_Gw_sq; move16(); } @@ -1323,7 +1547,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][0][b] = -pred_coeffs_re[j - 1][b]; + tmp_p2_re[j][0][b] = L_negate( pred_coeffs_re[sub( j, 1 )][b] ); move32(); max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][0][b] ) ); } @@ -1351,7 +1575,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[0][j][b] = dm_fv_re[j - 1][b]; + tmp_p1_re[0][j][b] = dm_fv_re[sub( j, 1 )][b]; move32(); max_val = L_max( max_val, L_abs( tmp_p1_re[0][j][b] ) ); } @@ -1376,6 +1600,7 @@ void ivas_create_fullr_dmx_mat_fx( } } *q_mixer_mat = sub( add( q_dm_fv_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); + move16(); } ELSE { @@ -1391,6 +1616,7 @@ void ivas_create_fullr_dmx_mat_fx( } } *q_mixer_mat = q_pred_coeffs_re; + move16(); } IF( NE_16( remix_unmix_order, 3 ) ) @@ -1593,13 +1819,15 @@ static void ivas_calc_post_pred_per_band_fx( FOR( j = 0; j < num_ch; j++ ) { tmp_re = 0; + move64(); FOR( k = 0; k < num_ch; k++ ) { tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), guard_bits ) ); } - IF( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { tmp_re = 0; + move64(); } temp_mat[i][j] = W_extract_l( W_shr( tmp_re, q_mixer_mat ) ); // Q = (q_cov_real - guard_bits) move32(); @@ -1633,7 +1861,7 @@ static void ivas_calc_post_pred_per_band_fx( tmp_re = W_add( tmp_re, W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ) ); } - IF( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) { tmp_re = 0; move64(); @@ -1645,6 +1873,7 @@ static void ivas_calc_post_pred_per_band_fx( } *q_postpred_cov_re = sub( q_temp_mat, guard_bits ); + move16(); FOR( i = 0; i < num_ch; i++ ) { @@ -1888,29 +2117,29 @@ static void ivas_calc_p_coeffs_per_band_fx( set32_fx( pSparMd->band_coeffs[b_ts_idx].P_re_fx, 0, IVAS_SPAR_MAX_CH - 1 ); pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = 0; move16(); - FOR( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) + FOR( i = 0; i < sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ); i++ ) { - set32_fx( recon_uu_re[i], 0, IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); + set32_fx( recon_uu_re[i], 0, sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ) ); } FOR( i = num_dmx; i < num_ch; i++ ) { FOR( j = num_dmx; j < num_ch; j++ ) { - cov_uu_re[i - num_dmx][j - num_dmx] = postpred_cov_re[i][j]; + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; move32(); } } q_cov_uu_re = q_postpred_cov_re; move16(); - IF( dtx_vad == 1 ) + IF( EQ_16( dtx_vad, 1 ) ) { FOR( i = 1; i < num_dmx; i++ ) { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; move32(); } } @@ -1929,6 +2158,10 @@ static void ivas_calc_p_coeffs_per_band_fx( recon_uu_re[0][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ), q_C_re ) ); recon_uu_re[1][0] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ), q_C_re ) ); recon_uu_re[1][1] = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ), q_C_re ) ); + move32(); + move32(); + move32(); + move32(); FOR( i = 0; i < 2; i++ ) { @@ -1960,8 +2193,10 @@ static void ivas_calc_p_coeffs_per_band_fx( move32(); re2 = W_extract_l( W_shr( W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ), q_C_re ) ); recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + move32(); cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + move32(); } ELSE IF( EQ_16( num_dmx, 4 ) ) { @@ -1992,7 +2227,7 @@ static void ivas_calc_p_coeffs_per_band_fx( } /* Step 2: cov_uu - recon_uu */ - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { FOR( j = 0; j < num_ch - num_dmx; j++ ) { @@ -2007,7 +2242,7 @@ static void ivas_calc_p_coeffs_per_band_fx( move32(); test(); - IF( EQ_16( dtx_vad, 0 ) && EQ_16( num_dmx, 1 ) ) + if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; move32(); @@ -2018,7 +2253,7 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { - trace = L_add( trace, L_abs( cov_uu_re[i - num_dmx][i - num_dmx] ) ); + trace = L_add( trace, L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ); } factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); @@ -2037,7 +2272,7 @@ static void ivas_calc_p_coeffs_per_band_fx( IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[i - num_dmx][j - num_dmx], factor ), 15 ) ); + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_l( W_shr( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), 15 ) ); move32(); } ELSE @@ -2054,8 +2289,8 @@ static void ivas_calc_p_coeffs_per_band_fx( FOR( i = num_dmx; i < num_ch; i++ ) { cov_uu_re_exp = sub( 31, q_cov_uu_re ); - cov_uu_re[i - num_dmx][i - num_dmx] = Sqrt32( L_max( 0, cov_uu_re[i - num_dmx][i - num_dmx] ), &cov_uu_re_exp ); - cov_uu_re[i - num_dmx][i - num_dmx] = L_shl( cov_uu_re[i - num_dmx][i - num_dmx], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); + cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = Sqrt32( L_max( 0, cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ), &cov_uu_re_exp ); + cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] = L_shl( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )], sub( q_cov_uu_re, sub( 31, cov_uu_re_exp ) ) ); move32(); move32(); } @@ -2067,7 +2302,7 @@ static void ivas_calc_p_coeffs_per_band_fx( { IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re_fx[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + pSparMd->band_coeffs[b_ts_idx].P_re_fx[sub( j, num_dmx )] = cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )]; move32(); } } @@ -2201,9 +2436,9 @@ static void ivas_calc_c_coeffs_per_band_fx( b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); - IF( EQ_16( dtx_vad, 0 ) ) + IF( dtx_vad == 0 ) { - set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); return; @@ -2213,7 +2448,7 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_ud_re[i - num_dmx][j - 1] = postpred_cov_re[i][j]; + cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; move32(); } } @@ -2222,7 +2457,8 @@ static void ivas_calc_c_coeffs_per_band_fx( { FOR( j = 1; j < num_dmx; j++ ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); } } @@ -2240,40 +2476,40 @@ static void ivas_calc_c_coeffs_per_band_fx( IF( LE_32( abs_trace, IVAS_FIX_EPS ) ) { /* protection from cases when variance of residual channels is very small */ - set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); } ELSE { - FOR( i = 0; i < num_dmx - 1; i++ ) + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) { cov_dd_re[i][i] = L_add( trace_cov_dd_re, cov_dd_re[i][i] ); move32(); } test(); - IF( EQ_16( ivas_is_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, num_dmx - 1 ), 1 ) && LT_16( num_dmx, FOA_CHANNELS ) ) + IF( EQ_16( ivas_is_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, sub( num_dmx, 1 ) ), 1 ) && LT_16( num_dmx, FOA_CHANNELS ) ) { - set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) ); + set32_fx( &pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], 0, imult1616( sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ), sub( IVAS_SPAR_MAX_DMX_CHS, 1 ) ) ); pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = 0; move16(); } ELSE { - ivas_calc_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, num_dmx - 1, cov_dd_re_inv, &q_cov_dd_re_inv ); + ivas_calc_mat_inv_fx( cov_dd_re, q_post_pred_cov_re, sub( num_dmx, 1 ), cov_dd_re_inv, &q_cov_dd_re_inv ); Word16 tmp; Word64 max_val = 1; move64(); Word64 C_re_fx[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - FOR( j = 0; j < num_dmx - 1; j++ ) + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { C_re_fx[i][j] = 0; move64(); - FOR( k = 0; k < num_dmx - 1; k++ ) + FOR( k = 0; k < sub( num_dmx, 1 ); k++ ) { C_re_fx[i][j] = W_add_nosat( C_re_fx[i][j], W_mult0_32_32( cov_ud_re[i][k], cov_dd_re_inv[k][j] ) ); move64(); @@ -2287,15 +2523,16 @@ static void ivas_calc_c_coeffs_per_band_fx( tmp = s_max( sub( 32, W_norm( max_val ) ), 0 ); - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - FOR( j = 0; j < num_dmx - 1; j++ ) + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][j] = W_extract_l( W_shr( C_re_fx[i][j], tmp ) ); move32(); } } pSparMd->band_coeffs[b_ts_idx].q_C_re_fx = sub( add( q_cov_dd_re_inv, q_post_pred_cov_re ), tmp ); + move16(); } } @@ -2398,15 +2635,15 @@ void ivas_calc_c_p_coeffs_fx( IF( dyn_active_w_flag ) { - FOR( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) { - FOR( j = 0; j < num_dmx - 1; j++ ) + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = 0; move32(); } } - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = 0; move16(); } IF( EQ_16( compute_p_flag, 1 ) ) @@ -2418,10 +2655,10 @@ void ivas_calc_c_p_coeffs_fx( { FOR( i = num_dmx; i < num_ch; i++ ) { - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[i - num_dmx] = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[sub( i, num_dmx )] = 0; move32(); } - pSparMd->band_coeffs[band_idx + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = 0; + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = 0; move16(); } } @@ -2511,6 +2748,7 @@ static void ivas_calc_mat_det_fx( re1 = W_mult0_32_32( in_re[0][1], W_extract_h( re ) ); *det_re = W_sub_nosat( *det_re, re1 ); + move64(); re1 = W_mult0_32_32( in_re[1][0], in_re[2][1] ); re2 = W_mult0_32_32( in_re[1][1], in_re[2][0] ); @@ -2519,8 +2757,10 @@ static void ivas_calc_mat_det_fx( re1 = W_mult0_32_32( in_re[0][2], W_extract_h( re ) ); *det_re = W_add_nosat( *det_re, re1 ); + move64(); *q_det_re = add( q_in_re, sub( add( q_in_re, q_in_re ), 32 ) ); + move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_2 ) ) { @@ -2528,7 +2768,9 @@ static void ivas_calc_mat_det_fx( re1 = W_mult0_32_32( in_re[0][0], in_re[1][1] ); re2 = W_mult0_32_32( in_re[0][1], in_re[1][0] ); *det_re = W_sub_nosat( re1, re2 ); + move64(); *q_det_re = add( q_in_re, q_in_re ); + move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_1 ) ) { @@ -2774,13 +3016,18 @@ static void ivas_calc_mat_inv_fx( out_re[0][0] = Mpy_32_16_1( in_re[1][1], one_by_det ); - out_re[0][1] = -Mpy_32_16_1( in_re[0][1], one_by_det ); + out_re[0][1] = L_negate( Mpy_32_16_1( in_re[0][1], one_by_det ) ); - out_re[1][0] = -Mpy_32_16_1( in_re[1][0], one_by_det ); + out_re[1][0] = L_negate( Mpy_32_16_1( in_re[1][0], one_by_det ) ); out_re[1][1] = Mpy_32_16_1( in_re[0][0], one_by_det ); + move32(); + move32(); + move32(); + move32(); *q_out_re = sub( q_in_re, add( q_tmp, q_det_re ) ); // Q = (15-(q_tmp + q_det_re)) + q_in_re - 15 + move16(); } ELSE IF( EQ_16( dim, IVAS_MAT_DIM_3 ) ) { @@ -2798,7 +3045,7 @@ static void ivas_calc_mat_inv_fx( det_re = W_shr( det_re, q_tmp ); q_det_re = sub( q_det_re, q_tmp ); - IF( EQ_64( det_re, 0 ) ) + if ( det_re == 0 ) { det_re = 1; move64(); @@ -2832,6 +3079,7 @@ static void ivas_calc_mat_inv_fx( } } *q_out_re = sub( add( sub( q_W_tmp, 32 ), q_one_by_det ), 15 ); + move16(); } ELSE { @@ -2901,7 +3149,7 @@ static Word16 ivas_is_mat_inv_fx( det = W_mult0_32_32( W_extract_l( det_re ), W_extract_l( det_re ) ); - IF( LE_64( det, IVAS_FIX_EPS ) ) + if ( LE_64( det, IVAS_FIX_EPS ) ) { is_det_zero = 1; move16(); @@ -3013,25 +3261,24 @@ void ivas_compute_spar_params_fx( q_tmp = sub( 15, tmp_exp ); tmp = sub( add( q_pred_coeffs, q_tmp ), 15 ); - FOR( i = 0; i < num_ch - 1; i++ ) + FOR( i = 0; i < sub( num_ch, 1 ); i++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re[i][b], onebyscale_fx ); move32(); - IF( LT_16( tmp, 0 ) ) + IF( tmp < 0 ) { - tmp = -tmp; - move16(); - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], add( tmp, 22 ) ); + tmp = negate( tmp ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shl( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], add( tmp, 22 ) ); move32(); } ELSE { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].pred_re_fx[i], sub( tmp, 22 ) ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i], sub( tmp, 22 ) ); move32(); } } // hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = sub(add(q_pred_coeffs, q_tmp), 15); - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_pred_re_fx = Q22; + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = Q22; move16(); FOR( i = 0; i < num_ch; i++ ) @@ -3043,22 +3290,22 @@ void ivas_compute_spar_params_fx( FOR( b = start_band; b < end_band; b++ ) { - ndm = hSparCfg->num_dmx_chans_per_band[b * bands_bw]; + ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; move16(); IF( NE_16( ndm, num_ch ) ) { ivas_calc_c_p_coeffs_fx( hSparMd, cov_real, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); - Word16 q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx; + Word16 q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx; IF( NE_16( ndm, 1 ) ) { #ifdef MSAN_FIX - FOR( i = 0; i < num_ch - ndm; i++ ) + FOR( i = 0; i < sub( num_ch, ndm ); i++ ) { - FOR( int j = 0; j < ndm - 1; j++ ) + FOR( Word16 j = 0; j < sub( ndm, 1 ); j++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].C_re_fx[i][j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j], sub( q_tmp, 22 ) ); move32(); } } @@ -3071,16 +3318,20 @@ void ivas_compute_spar_params_fx( } } #endif - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_C_re_fx = Q22; + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_C_re_fx = Q22; + move16(); } - q_tmp = hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx; + q_tmp = hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx; + move16(); - for ( int j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) + FOR( Word16 j = 0; j < sub( IVAS_SPAR_MAX_CH, 1 ); j++ ) { - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j] = L_shr( hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].P_re_fx[j], sub( q_tmp, 22 ) ); + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = L_shr( hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j], sub( q_tmp, 22 ) ); + move32(); } - hSparMd->band_coeffs[b + i_ts * IVAS_MAX_NUM_BANDS].q_P_re_fx = Q22; + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = Q22; + move16(); } } @@ -3120,515 +3371,490 @@ void ivas_get_spar_md_from_dirac_fx( const int16_t dyn_active_w_flag ) { - int16_t num_ch, band, i, j; - int16_t block, ch; + Word16 num_ch, band, i, j; + Word16 block, ch; - // float response_avg[MAX_OUTPUT_CHANNELS]; Word32 response_avg_fx[MAX_OUTPUT_CHANNELS]; - // float response[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; Word32 response_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MAX_OUTPUT_CHANNELS]; - // float cov_real_dirac[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; Word32 cov_real_dirac_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; - // float *pCov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 *pCov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - // float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 q_dm_fv_re_fx = 0; - // float Wscale[IVAS_MAX_NUM_BANDS]; - Word16 q_Wscale[IVAS_MAX_NUM_BANDS] = { 0 }; - Word32 Wscale_fx[IVAS_MAX_NUM_BANDS] = { 0 }; - // float mixer_mat_local[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; Word32 mixer_mat_local_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; - // float **ppMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH]; Word32 **ppMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH]; - // float *pMixer_mat[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word32 *pMixer_mat_fx[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; Word16 q_ppMixer_mat = 0; - // float en_ratio_fac, diff_norm_order1, diff_norm_order2, diff_norm_order3; Word32 en_ratio_fac_fx, diff_norm_order1_fx, diff_norm_order2_fx, diff_norm_order3_fx; - int16_t active_w; + Word16 active_w; + move16(); + move16(); - int16_t ndm, foa_ch, hoa2_ch; - // float P_dir_fact[IVAS_SPAR_MAX_CH - 1]; + Word16 ndm, foa_ch, hoa2_ch; Word32 P_dir_fact_fx[IVAS_SPAR_MAX_CH - 1]; - const int16_t *remix_order; + const Word16 *remix_order; + set16_fx( q_Wscale, 0, IVAS_MAX_NUM_BANDS ); + set32_fx( Wscale_fx, 0, IVAS_MAX_NUM_BANDS ); remix_order = remix_order_set[hSpar_md_cfg->remix_unmix_order]; num_ch = ivas_sba_get_nchan_metadata_fx( order, IVAS_256k /*dummy value as order is always 1 in this function*/ ); hoa2_ch = ivas_sba_get_nchan_metadata_fx( SBA_HOA2_ORDER, IVAS_256k /*dummy value as order is always 1 in this function*/ ); - // hoa2_ch max 6 foa_ch = FOA_CHANNELS; - // foa_ch 4; - // diff_norm_order1 = 3.0f; + move16(); diff_norm_order1_fx = 3; - // diff_norm_order2 = 5.0f; + move32(); diff_norm_order2_fx = 5; - // diff_norm_order3 = 7.0f; + move32(); diff_norm_order3_fx = 7; + move32(); - for ( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) + FOR( i = 0; i < IVAS_MAX_FB_MIXER_OUT_CH; i++ ) { - for ( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) + FOR( j = 0; j < IVAS_MAX_SPAR_FB_MIXER_IN_CH; j++ ) { - // pMixer_mat[i][j] = mixer_mat_local[i][j]; pMixer_mat_fx[i][j] = mixer_mat_local_fx[i][j]; + move32(); } - // ppMixer_mat[i] = pMixer_mat[i]; ppMixer_mat_fx[i] = pMixer_mat_fx[i]; + move32(); } - if ( ( start_band >= 6 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) || ( useLowerRes && start_band >= 3 && hSpar_md_cfg->nchan_transport <= 2 && ( dtx_vad == 1 ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GE_16( start_band, 6 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) || ( useLowerRes && GE_16( start_band, 3 ) && LE_16( hSpar_md_cfg->nchan_transport, 2 ) && ( EQ_16( dtx_vad, 1 ) ) ) ) { - // float P_norm[3]; Word32 P_norm_fx[3]; - int16_t idx; + Word16 idx; - ndm = hSpar_md_cfg->num_dmx_chans_per_band[start_band - 1]; - // ndm max value of 4 - // P_norm[0] = 0.0f; + ndm = hSpar_md_cfg->num_dmx_chans_per_band[sub( start_band, 1 )]; + move16(); P_norm_fx[0] = 0; - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + move32(); + FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - // use 64bit if low precission - // P_norm[0] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_norm_fx[0] = P_norm_fx[0] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_norm_fx[0] = L_add( P_norm_fx[0], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + move32(); } - // P_norm[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); - // P_norm_fx[0] *= diff_norm_order1 / min( diff_norm_order1, max( 0, foa_ch - ndm ) ); - P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, foa_ch - ndm ) )] ); + P_norm_fx[0] = Mpy_32_32( L_shl( P_norm_fx[0], 3 ), diff_norm_order1_table[min( diff_norm_order1_fx, max( 0, sub( foa_ch, ndm ) ) )] ); + move32(); - // P_norm[1] = 0.0f; P_norm_fx[1] = 0; - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + move32(); + FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - // P_norm[1] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_norm_fx[1] = P_norm_fx[1] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_norm_fx[1] = L_add( P_norm_fx[1], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + move32(); } - // P_norm[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); - // P_norm_fx[1] *= diff_norm_order2 / min( diff_norm_order2, max( 0, min( num_ch, hoa2_ch ) - ndm ) ); - P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, min( num_ch, hoa2_ch ) - ndm ) )] ); - + P_norm_fx[1] = Mpy_32_32( L_shl( P_norm_fx[1], 3 ), diff_norm_order2_table[min( diff_norm_order2_fx, max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ) )] ); + move32(); - // P_norm[2] = 0.0f; P_norm_fx[2] = 0; - for ( ; i < num_ch - ndm; i++ ) + move32(); + FOR( ; i < sub( num_ch, ndm ); i++ ) { - // P_norm[2] += hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_norm_fx[2] = P_norm_fx[2] + Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); + P_norm_fx[2] = L_add( P_norm_fx[2], Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ) ); + move32(); } - // P_norm[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); - // P_norm_fx[2] *= diff_norm_order3 / min( diff_norm_order3, max( 0, num_ch - ndm ) ); - P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, num_ch - ndm ) )] ); + P_norm_fx[2] = Mpy_32_32( L_shl( P_norm_fx[2], 3 ), diff_norm_order3_table[min( diff_norm_order3_fx, max( 0, sub( num_ch, ndm ) ) )] ); + move32(); - for ( i = 0; i < max( 0, foa_ch - ndm ); i++ ) + FOR( i = 0; i < max( 0, sub( foa_ch, ndm ) ); i++ ) { - idx = remix_order[i + ndm] - ndm; - // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[0] ); - if ( P_dir_fact_fx[idx] == 0 ) + idx = sub( remix_order[add( i, ndm )], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + move32(); + IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; + move32(); } - else + ELSE { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[0], IVAS_FIX_EPS ) ); + move32(); P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + move32(); } } - for ( ; i < max( 0, min( num_ch, hoa2_ch ) - ndm ); i++ ) + FOR( ; i < max( 0, sub( min( num_ch, hoa2_ch ), ndm ) ); i++ ) { - idx = remix_order[i + ndm] - ndm; - // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[1] ); - if ( P_dir_fact_fx[idx] == 0 ) + idx = sub( remix_order[add( i, ndm )], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; + move32(); } - else + ELSE { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[1], IVAS_FIX_EPS ) ); + move32(); P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + move32(); } } - for ( ; i < num_ch - ndm; i++ ) + FOR( ; i < sub( num_ch, ndm ); i++ ) { - idx = remix_order[i + ndm] - ndm; - // P_dir_fact[idx] = hSpar_md->band_coeffs[start_band - 1].P_re[i] * hSpar_md->band_coeffs[start_band - 1].P_re[i]; - P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[start_band - 1].P_re_fx[i], hSpar_md->band_coeffs[start_band - 1].P_re_fx[i] ); - // P_dir_fact[idx] = P_dir_fact[idx] / max( IVAS_FLT_EPS, P_norm[2] ); - if ( P_dir_fact_fx[idx] == 0 ) + idx = sub( remix_order[add( i, ndm )], ndm ); + P_dir_fact_fx[idx] = Mpy_32_32( hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i], hSpar_md->band_coeffs[sub( start_band, 1 )].P_re_fx[i] ); + move32(); + IF( P_dir_fact_fx[idx] == 0 ) { P_dir_fact_fx[idx] = 0; + move32(); } - else + ELSE { P_dir_fact_fx[idx] = divide3232( P_dir_fact_fx[idx], max( P_norm_fx[2], IVAS_FIX_EPS ) ); + move32(); P_dir_fact_fx[idx] = L_shl( P_dir_fact_fx[idx], 15 ); + move32(); } } } - for ( int16_t i_ts = 0; i_ts < n_ts; i_ts++ ) + FOR( Word16 i_ts = 0; i_ts < n_ts; i_ts++ ) { - for ( band = start_band; band < end_band; band++ ) + FOR( band = start_band; band < end_band; band++ ) { ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); /*SPAR from DirAC*/ - // set_f( response_avg, 0.0f, MAX_OUTPUT_CHANNELS ); set32_fx( response_avg_fx, 0, MAX_OUTPUT_CHANNELS ); - if ( n_ts > 1 ) + IF( GE_16( n_ts, 1 ) ) { - // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][i_ts], (int16_t) ele_dirac[band][i_ts], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][i_ts], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][i_ts], Q22 ), response_avg_fx, order, Q30 ); - /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); - }*/ + ivas_dirac_dec_get_response_fx( extract_l( L_shr( azi_dirac_fx[band][i_ts], Q22 ) ), extract_l( L_shr( ele_dirac_fx[band][i_ts], Q22 ) ), response_avg_fx, order, Q30 ); } - else if ( useLowerRes ) + ELSE IF( useLowerRes ) { - // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][0], (int16_t) ele_dirac[band][0], response_avg, order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][0], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][0], Q22 ), response_avg_fx, order, Q30 ); - /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - response_avg[l] = (float) response_avg_fx[l] / ( 1 << 30 ); - }*/ + ivas_dirac_dec_get_response_fx( extract_l( L_shr( azi_dirac_fx[band][0], Q22 ) ), extract_l( L_shr( ele_dirac_fx[band][0], Q22 ) ), response_avg_fx, order, Q30 ); } - else + ELSE { - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - // ivas_dirac_dec_get_response( (int16_t) azi_dirac[band][block], (int16_t) ele_dirac[band][block], &( response[block][0] ), order ); - ivas_dirac_dec_get_response_fx( (int16_t) L_shr( azi_dirac_fx[band][block], Q22 ), (int16_t) L_shr( ele_dirac_fx[band][block], Q22 ), &( response_fx[block][0] ), order, Q30 ); - /*for ( int l = 0; l < MAX_OUTPUT_CHANNELS; l++ ) - { - response[block][l] = (float) response_fx[block][l] / ( 1 << 30 ); - }*/ + ivas_dirac_dec_get_response_fx( extract_l( L_shr( azi_dirac_fx[band][block], Q22 ) ), extract_l( L_shr( ele_dirac_fx[band][block], Q22 ) ), &( response_fx[block][0] ), order, Q30 ); } /* average responses in all subframes*/ { - // float norm; Word32 norm_fx; Word16 norm_q; - int16_t num_ch_order, hoa2_ch_order; + Word16 num_ch_order, hoa2_ch_order; num_ch_order = ivas_sba_get_nchan_fx( order, 0 ); hoa2_ch_order = ivas_sba_get_nchan_fx( SBA_HOA2_ORDER, 0 ); - for ( ch = 0; ch < num_ch_order; ch++ ) + FOR( ch = 0; ch < num_ch_order; ch++ ) { Word64 temp = 0; - for ( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) + move64(); + FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { - // response_avg[ch] += response[block][ch]; - temp = temp + response_fx[block][ch]; + temp = W_add( temp, W_deposit32_l( response_fx[block][ch] ) ); } - // response_avg[ch] /= MAX_PARAM_SPATIAL_SUBFRAMES; response_avg_fx[ch] = W_extract_l( W_shr( temp, 2 ) ); + move32(); } /*normalize 1st order*/ - // norm = 0.0f; norm_fx = 0; + move32(); norm_q = 0; - for ( ch = 1; ch < foa_ch; ch++ ) + move16(); + FOR( ch = 1; ch < foa_ch; ch++ ) { - // norm += response_avg[ch] * response_avg[ch]; - norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); } - norm_q = 31 - ( 30 + 30 - 31 ); - // norm = max( EPSILON, sqrtf( norm ) ); - if ( norm_fx ) + norm_q = sub( 31, ( sub( add( 30, 30 ), 31 ) ) ); + IF( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); } - else + ELSE { norm_fx = EPSILON_FX; + move32(); } - if ( norm_q < 0 ) + IF( norm_q <= 0 ) { - norm_fx = L_shr( norm_fx, ( -1 * norm_q ) ); + norm_fx = L_shr( norm_fx, ( negate( norm_q ) ) ); norm_q = 0; + move16(); } - norm_fx = L_shr( norm_fx, 1 - norm_q ); - for ( ch = 1; ch < foa_ch; ch++ ) + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + FOR( ch = 1; ch < foa_ch; ch++ ) { - // response_avg[ch] /= norm; - if ( norm_fx < EPSILON_FX_THR ) + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { - if ( response_avg_fx[ch] != 0 ) + IF( response_avg_fx[ch] != 0 ) { response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); + move32(); } response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); } - else if ( response_avg_fx[ch] > norm_fx ) + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { response_avg_fx[ch] = ONE_IN_Q30; + move32(); } - else + ELSE { response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + move32(); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); } - // response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); } /*normalize 2nd order*/ - // norm = 0.0f; norm_fx = 0; - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + move32(); + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - // norm += response_avg[ch] * response_avg[ch]; - norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); } - norm_q = 31 - ( 29 + 29 - 31 ); - // norm = max( EPSILON, sqrtf( norm ) ); - if ( norm_fx ) + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); } - else + ELSE { norm_fx = EPSILON_FX; + move32(); } - if ( norm_q < 0 ) + IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, -1 * norm_q ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); norm_q = 0; + move16(); } - norm_fx = L_shr( norm_fx, 1 - norm_q ); - for ( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + FOR( ch = foa_ch; ch < min( hoa2_ch_order, num_ch_order ); ch++ ) { - if ( norm_fx < EPSILON_FX_THR ) + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { response_avg_fx[ch] = response_avg_fx[ch]; response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); + move32(); + move32(); } - else if ( response_avg_fx[ch] > norm_fx ) + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { response_avg_fx[ch] = ONE_IN_Q30; + move32(); } - else + ELSE { response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); + move32(); } - // response_avg[ch] = (float)response_avg_fx[ch] / (1 << 30); } /*normalize 3rd order*/ - // norm = 0.0f; - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - // norm += response_avg[ch] * response_avg[ch]; - norm_fx = norm_fx + Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ); + norm_fx = L_add( norm_fx, Mpy_32_32( response_avg_fx[ch], response_avg_fx[ch] ) ); } - norm_q = 31 - ( 29 + 29 - 31 ); - // norm = max( EPSILON, sqrtf( norm ) ); - if ( norm_fx ) + norm_q = sub( 31, ( sub( add( 29, 29 ), 31 ) ) ); + IF( norm_fx ) { norm_fx = Sqrt32( norm_fx, &norm_q ); } - else + ELSE { norm_fx = EPSILON_FX; + move32(); } - if ( norm_q < 0 ) + IF( norm_q < 0 ) { - norm_fx = L_shr( norm_fx, -1 * norm_q ); + norm_fx = L_shr( norm_fx, negate( norm_q ) ); norm_q = 0; + move16(); } - norm_fx = L_shr( norm_fx, 1 - norm_q ); - for ( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) + norm_fx = L_shr( norm_fx, sub( 1, norm_q ) ); + FOR( ch = hoa2_ch_order; ch < num_ch_order; ch++ ) { - // response_avg[ch] /= norm; - if ( norm_fx < EPSILON_FX_THR ) + IF( LT_32( norm_fx, EPSILON_FX_THR ) ) { response_avg_fx[ch] = response_avg_fx[ch]; response_avg_fx[ch] = divide3232( response_avg_fx[ch], EPSILON_FX_THR ); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); + move32(); + move32(); } - else if ( response_avg_fx[ch] > norm_fx ) + ELSE IF( GT_32( response_avg_fx[ch], norm_fx ) ) { response_avg_fx[ch] = ONE_IN_Q30; + move32(); } - else + ELSE { response_avg_fx[ch] = divide3232( response_avg_fx[ch], norm_fx ); + move32(); response_avg_fx[ch] = L_shl( response_avg_fx[ch], 15 ); + move32(); } - // response_avg[ch] = (float) response_avg_fx[ch] / ( 1 << 30 ); } } } - for ( i = FOA_CHANNELS + 1; i < num_ch; i++ ) + FOR( i = add( FOA_CHANNELS, 1 ); i < num_ch; i++ ) { - // response_avg[i] = response_avg[HOA_keep_ind[i]]; response_avg_fx[i] = response_avg_fx[HOA_keep_ind[i]]; + move32(); } - // en_ratio_fac = ( 1.0f - diffuseness[band] ); - en_ratio_fac_fx = ( ONE_IN_Q31 - L_shl_sat( diffuseness_fx[band], 1 ) ); // assuming q of dissusion 30 - for ( i = 0; i < num_ch; i++ ) + en_ratio_fac_fx = L_sub( ONE_IN_Q31, L_shl_sat( diffuseness_fx[band], 1 ) ); // assuming q of dissusion 30 + + FOR( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { - if ( i == 0 ) + IF( i == 0 ) { - // cov_real_dirac[i][i][band] = 1.0f; cov_real_dirac_fx[i][i][band] = ONE_IN_Q30; + move32(); } - else + ELSE { Word32 en_ratio_fac_sq = 0; - // cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; + move32(); cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl_sat( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); + move32(); - if ( hSpar_md_cfg->nchan_transport <= 2 ) + IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) { - - // cov_real_dirac[i][j][band] *= en_ratio_fac; cov_real_dirac_fx[i][j][band] = Mpy_32_32( cov_real_dirac_fx[i][j][band], en_ratio_fac_fx ); - if ( ( i >= ndm ) && ( dtx_vad == 1 ) ) + move32(); + test(); + IF( ( GE_16( i, ndm ) ) && ( EQ_16( dtx_vad, 1 ) ) ) { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), P_dir_fact_fx[i - ndm] ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) * P_dir_fact[i - ndm]; + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), P_dir_fact_fx[sub( i, ndm )] ) ); + move32(); } - else + ELSE { - if ( i < foa_ch ) + IF( LT_16( i, foa_ch ) ) { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order1; + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_THREE_Q31 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + move32(); } - else if ( i < hoa2_ch ) + ELSE IF( LT_16( i, hoa2_ch ) ) { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order2; + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_FIVE_Q31 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + move32(); } - else + ELSE { en_ratio_fac_sq = Mpy_32_32( en_ratio_fac_fx, en_ratio_fac_fx ); - Word32 temp = Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( temp, 1 ); - // cov_real_dirac[i][j][band] += ( 1.0f - ( en_ratio_fac * en_ratio_fac ) ) / diff_norm_order3; + Word32 temp = Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_sq ), ONE_BY_SEVEN_Q31 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( temp, 1 ) ); + move32(); } } } - else + ELSE { - if ( i < foa_ch ) + IF( LT_16( i, foa_ch ) ) { - // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order1; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_THREE_Q31 ), 1 ) ); + move32(); } - else if ( i < hoa2_ch ) + ELSE IF( LT_16( i, hoa2_ch ) ) { - // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order2; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_FIVE_Q31 ), 1 ) ); + move32(); } - else + ELSE { - // cov_real_dirac[i][j][band] += ( 1.0f - en_ratio_fac ) / diff_norm_order3; - cov_real_dirac_fx[i][j][band] = cov_real_dirac_fx[i][j][band] + L_shr( Mpy_32_32( ( ONE_IN_Q31 - en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ); + cov_real_dirac_fx[i][j][band] = L_add( cov_real_dirac_fx[i][j][band], L_shr( Mpy_32_32( L_sub( ONE_IN_Q31, en_ratio_fac_fx ), ONE_BY_SEVEN_Q31 ), 1 ) ); + move32(); } } } } - else + ELSE { - // cov_real_dirac[i][j][band] = en_ratio_fac * response_avg[i] * response_avg[j]; cov_real_dirac_fx[i][j][band] = L_shl_sat( Mpy_32_32( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), response_avg_fx[j] ), 1 ); + move32(); } } } } - for ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - // pCov_real[i][j] = cov_real_dirac[i][j]; pCov_real_fx[i][j] = cov_real_dirac_fx[i][j]; + move32(); } } - /*static int frame_counter; - frame_counter++; - if (frame_counter > 500) - { - frame_counter = frame_counter; - }*/ - - active_w = ( dyn_active_w_flag == 1 ) || ( hSpar_md_cfg->active_w == 1 ); - - // #ifdef IVAS_FLOAT_FIXED + test(); + active_w = ( EQ_16( dyn_active_w_flag, 1 ) ) || ( EQ_16( hSpar_md_cfg->active_w, 1 ) ); ivas_compute_spar_params_fx( pCov_real_fx, Q30, dm_fv_re_fx, &q_dm_fv_re_fx, i_ts, ppMixer_mat_fx, &q_ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale_fx, q_Wscale, 1, dyn_active_w_flag ); - // #else - // for (int i = 0; i < num_ch; i++) - // { - // for (int j = 0; j < num_ch; j++) - // { - // for (int k = start_band; k < end_band; k++) - // { - // cov_real_dirac[i][j][k] = (float)cov_real_dirac_fx[i][j][k] / (1 << 30); - // } - // } - // } - - // ivas_compute_spar_params( pCov_real, dm_fv_re, i_ts, ppMixer_mat, start_band, end_band, dtx_vad, num_ch, 1, active_w, active_w_vlbr, hSpar_md_cfg, hSpar_md, Wscale, 1, dyn_active_w_flag ); - // - //#endif // IVAS_FLOAT_FIXED - - if ( mixer_mat_fx != NULL ) + IF( mixer_mat_fx != NULL ) { - for ( band = start_band; band < end_band; band++ ) + FOR( band = start_band; band < end_band; band++ ) { ndm = hSpar_md_cfg->num_dmx_chans_per_band[band]; + move16(); - for ( i = 0; i < ndm; i++ ) + FOR( i = 0; i < ndm; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = ppMixer_mat_fx[i][j][band]; + mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = ppMixer_mat_fx[i][j][band]; + move32(); } } - for ( i = ndm; i < num_ch; i++ ) + FOR( i = ndm; i < num_ch; i++ ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[i][j][band + i_ts * IVAS_MAX_NUM_BANDS] = 0; + mixer_mat_fx[i][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = 0; + move32(); } } - if ( ( ndm == 1 ) && ( Wscale_d != NULL ) ) + test(); + IF( ( EQ_16( ndm, 1 ) ) && ( Wscale_d != NULL ) ) { - for ( j = 0; j < num_ch; j++ ) + FOR( j = 0; j < num_ch; j++ ) { - mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS] = Mpy_32_32( mixer_mat_fx[0][j][band + i_ts * IVAS_MAX_NUM_BANDS], Wscale_d[band] ); + mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )] = Mpy_32_32( mixer_mat_fx[0][j][add( band, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )], Wscale_d[band] ); + move32(); } } } @@ -6083,147 +6309,140 @@ void ivas_dirac_dec_get_response_fx( const Word16 ambisonics_order, Word16 Q_out ) { - // float response[MAX_OUTPUT_CHANNELS]; - int16_t index_azimuth, index_elevation; - int16_t el, e, az; - // float cos_1, cos_2, sin_1, cos_az[3]; + Word16 index_azimuth, index_elevation; + Word16 el, e, az; Word32 cos_1_fx, cos_2_fx, sin_1_fx, cos_az_fx[3]; - // float sin_az[3]; Word32 sin_az_fx[3]; - // float f, c; Word32 f_fx; Word32 c_fx_better; - int16_t l, m; - int16_t b, b1, b_2, b1_2, a; + Word16 l, m; + Word16 b, b1, b_2, b1_2, a; - index_azimuth = ( azimuth + 180 ) % 360; - index_elevation = elevation + 90; - e = index_elevation > 90 ? -1 : 1; - el = index_elevation > 90 ? 180 - index_elevation : index_elevation; - az = index_azimuth > 180 ? 360 - index_azimuth : index_azimuth; - // f = index_azimuth > 180 ? -1.0f : 1.0f; - f_fx = index_azimuth > 180 ? -1 : 1; - // cos_1 = dirac_gains_trg_term[az][0]; + index_azimuth = add( azimuth, 180 ) % 360; + move16(); + index_elevation = add( elevation, 90 ); + IF( GT_16( index_elevation, 90 ) ) + { + e = -1; + move16(); + } + ELSE + { + e = 1; + move16(); + } + + IF( GT_16( index_elevation, 90 ) ) + { + el = sub( 180, index_elevation ); + move16(); + } + ELSE + { + el = index_elevation; + move16(); + } + + IF( GT_16( index_azimuth, 180 ) ) + { + az = sub( 360, index_azimuth ); + move16(); + } + ELSE + { + az = index_azimuth; + move16(); + } + + IF( GT_16( index_azimuth, 180 ) ) + { + f_fx = -1; + move16(); + } + ELSE + { + f_fx = 1; + move16(); + } cos_1_fx = dirac_gains_trg_term_fx[az][0]; - // cos_2 = cos_1 * cos_1; + move32(); cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); - // sin_1 = f * dirac_gains_trg_term[az][1]; sin_1_fx = dirac_gains_trg_term_fx[az][1]; - if ( f_fx == -1 ) + move32(); + + if ( EQ_32( f_fx, -1 ) ) { sin_1_fx = L_negate( sin_1_fx ); + move32(); } - // cos_az[0] = cos_1; cos_az_fx[0] = cos_1_fx; - // cos_az[1] = 2.0f * cos_2 - 1.0f; - cos_az_fx[1] = L_shl_sat( ( cos_2_fx - ONE_IN_Q30 ), 1 ); - // cos_az[2] = 2.0f * cos_1 * cos_az[1] - cos_az[0]; - cos_az_fx[2] = L_shl_sat( ( Mpy_32_32( cos_1_fx, cos_az_fx[1] ) - L_shr( cos_az_fx[0], 1 ) ), 1 ); - // sin_az[0] = sin_1; + move32(); + cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 ), 1 ); + move32(); + cos_az_fx[2] = L_shl_sat( L_sub( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), L_shr( cos_az_fx[0], 1 ) ), 1 ); + move32(); sin_az_fx[0] = sin_1_fx; - // sin_az[1] = sin_1 * 2.0f * cos_1; + move32(); sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); - // sin_az[2] = sin_1 * ( 4.0f * cos_2 - 1.0f ); - sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, ( cos_2_fx - ONE_IN_Q29 ) ), 2 ); + move32(); + sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 ) ), 2 ); + move32(); - // response[0] = 1.0f; response_fx[0] = L_shl_sat( 1, Q_out ); - /* Un-optimized code - for reference */ - /* for( l = 1; l<= ambisonics_order; l++ ) */ - /* { */ - /* int16_t b, b1, a; */ - /* float c; */ - /* for( m = 0; m < l; m++ ) */ - /* { */ - /* b = l*l+m; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - - /* if( m%2 == 1 ) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c * sin_az[l-m-1]; */ - - /* b1 = l*l+2*l-m; */ - /* response[b1] = c * cos_az[l-m-1]; */ - - /* } */ - - /* b = l*l+l; */ - /* a = dirac_gains_P_idx[b]; */ - /* c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; */ - /* if( l%2 == 1) */ - /* { */ - /* c = c*e; */ - /* } */ - - /* response[b] = c; */ - /* } */ + move32(); - for ( l = 1; l <= ambisonics_order; l++ ) + FOR( l = 1; l <= ambisonics_order; l++ ) { - b_2 = l * l; - b1_2 = l * l + 2 * l; - for ( m = 0; m < l; m += 2 ) + b_2 = imult1616( l, l ); + b1_2 = add( imult1616( l, l ), shl( l, 1 ) ); + FOR( m = 0; m < l; m += 2 ) { - b = b_2 + m; + b = add( b_2, m ); a = dirac_gains_P_idx[b]; - // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - // c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); + move16(); c_fx_better = local_result_table[el][a]; - // response[b] = c * sin_az[l - m - 1]; - // response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + move32(); + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); - b1 = b1_2 - m; - // response[b1] = c * cos_az[l - m - 1]; - // response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + b1 = sub( b1_2, m ); + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); } - for ( m = 1; m < l; m += 2 ) + FOR( m = 1; m < l; m += 2 ) { - b = b_2 + m; + b = add( b_2, m ); a = dirac_gains_P_idx[b]; - // c = SQRT2 * dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - // c_fx = Mpy_32_32( SQRT2_FIXED, Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ) ); + move16(); c_fx_better = local_result_table[el][a]; - if ( e == -1 ) + move32(); + if ( EQ_16( e, -1 ) ) { - // c_fx = L_negate( c_fx ); c_fx_better = L_negate( c_fx_better ); } - // c = c * e; - - // response[b] = c * sin_az[l - m - 1]; - // response_fx[b] = Mpy_32_32( L_shl( c_fx, 3 ), sin_az_fx[l - m - 1] ); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out - b1 = b1_2 - m; - // response[b1] = c * cos_az[l - m - 1]; - // response_fx[b1] = Mpy_32_32( L_shl( c_fx, 3 ), cos_az_fx[l - m - 1] ); - response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); + b1 = sub( b1_2, m ); + response_fx[b1] = L_shl_sat( Mpy_32_32( c_fx_better, cos_az_fx[sub( sub( l, m ), 1 )] ), sub( Q_out, 30 ) ); // Q_out + move32(); } - b = b_2 + l; + b = add( b_2, l ); a = dirac_gains_P_idx[b]; - // c = dirac_gains_norm_term[a] * dirac_gains_Pnm[el][a]; - // c_fx = Mpy_32_32( dirac_gains_norm_term_fx[a], dirac_gains_Pnm_int[el][a] ); + move16(); c_fx_better = local_result_table_2[el][a]; - if ( l % 2 == 1 ) + move32(); + IF( EQ_16( ( l % 2 ), 1 ) ) { - // c = c * e; - if ( e == -1 ) + if ( EQ_16( e, -1 ) ) { - // c_fx = L_negate( c_fx ); c_fx_better = L_negate( c_fx_better ); + move32(); } } - - // response[b] = c; - // response_fx[b] = L_shl( c_fx, 2 ); response_fx[b] = L_shl_sat( c_fx_better, sub( Q_out, 30 ) ); // Q_out + move32(); } return; @@ -6247,7 +6466,7 @@ Word16 ivas_get_bits_to_encode( WHILE( val ) { - bits_req++; + bits_req = add( bits_req, 1 ); val = L_shr( val, 1 ); } @@ -6445,39 +6664,45 @@ void ivas_spar_set_bitrate_config_fx( Word16 bands_bw; pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); FOR( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { pSpar_md_cfg->max_freq_per_chan[i] = ivas_spar_br_table_consts[table_idx].fpcs; + move16(); } pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; + move16(); pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; -#ifdef IVAS_FLOAT_FIXED + move16(); + ivas_spar_get_uniform_quant_strat_fx( pSpar_md_cfg, table_idx ); -#else - ivas_spar_get_uniform_quant_strat( pSpar_md_cfg, table_idx ); -#endif + pSpar_md_cfg->quant_strat_bits = ivas_get_bits_to_encode( MAX_QUANT_STRATS ); + move16(); /* BLOCK: getEntropyCoderModels */ pSpar_md_cfg->remix_unmix_order = ivas_spar_br_table_consts[table_idx].dmx_str; + move16(); /* bits per block*/ total_bits = 0; + move16(); max_bits = 0; + move16(); ivas_total_brate = ivas_spar_br_table_consts[table_idx].ivas_total_brate; + move32(); sba_order = ivas_spar_br_table_consts[table_idx].sba_order; + move16(); ivas_get_spar_table_idx_fx( ivas_total_brate, sba_order, ivas_spar_br_table_consts[table_idx].bwidth, &length, &code ); Word16 temp; Word16 div1; FOR( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) { - /* total_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][0] / FRAMES_PER_SEC ); */ total_bits = add( total_bits, extract_l( Mpy_32_32( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); - /* max_bits += (int16_t) ( ivas_spar_br_table_consts[table_idx].core_brs[i][1] / FRAMES_PER_SEC ); */ max_bits = add( max_bits, extract_l( Mpy_32_32( ivas_spar_br_table_consts[table_idx].core_brs[i][1], ONE_BY_FRAMES_PER_SEC_Q31 ) ) ); } @@ -6485,28 +6710,36 @@ void ivas_spar_set_bitrate_config_fx( div1 = extract_l( Mpy_32_32( ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); pSpar_md_cfg->tgt_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), total_bits ) ); pSpar_md_cfg->max_bits_per_blk = sub( div1, add( add( add( add( add( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, SBA_PLANAR_BITS ), 0 ), SBA_ORDER_BITS ), length ), max_bits ) ); + move16(); + move16(); md_coding_bits_header = add( SPAR_NUM_CODING_STRAT_BITS, pSpar_md_cfg->quant_strat_bits ); pSpar_md_cfg->tgt_bits_per_blk = sub( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); pSpar_md_cfg->max_bits_per_blk = sub( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); + move16(); + move16(); IF( LT_32( ivas_total_brate, IVAS_24k4 ) ) { bands_bw = 2; + move16(); } ELSE { bands_bw = 1; + move16(); } - /* pSpar_md_cfg->tgt_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->tgt_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS ); */ pSpar_md_cfg->tgt_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->tgt_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); - /* pSpar_md_cfg->max_bits_per_blk = (int16_t) ceilf( ( 1.0f * pSpar_md_cfg->max_bits_per_blk * num_bands ) / IVAS_MAX_NUM_BANDS ); */ pSpar_md_cfg->max_bits_per_blk = extract_l( Mpy_32_32( i_mult( pSpar_md_cfg->max_bits_per_blk, num_bands ), 178956971 /* 1 / IVAS_MAX_NUM_BANDS in Q31 */ ) ); pSpar_md_cfg->tgt_bits_per_blk = add( pSpar_md_cfg->tgt_bits_per_blk, md_coding_bits_header ); pSpar_md_cfg->max_bits_per_blk = add( pSpar_md_cfg->max_bits_per_blk, md_coding_bits_header ); + move16(); + move16(); + move16(); + move16(); IF( enc_flag ) { @@ -6514,13 +6747,24 @@ void ivas_spar_set_bitrate_config_fx( IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) { quant_strat = QUANT_STRAT_0; + move16(); } ELSE { quant_strat = QUANT_STRAT_2; + move16(); } - num_PR_bits_dirac_bands = ( EQ_16( dirac2spar_md_flag, 1 ) ) ? sub( num_bands, SPAR_DIRAC_SPLIT_START_BAND ) : 0; + IF( EQ_16( dirac2spar_md_flag, 1 ) ) + { + num_PR_bits_dirac_bands = sub( num_bands, SPAR_DIRAC_SPLIT_START_BAND ); + move16(); + } + ELSE + { + num_PR_bits_dirac_bands = 0; + move16(); + } div1 = BASOP_Util_Divide3232_Scale( num_PR_bits_dirac_bands, bands_bw, &temp ); num_PR_bits_dirac_bands = shr( div1, sub( 15, temp ) ); num_PR_bits_dirac_bands = s_max( 0, num_PR_bits_dirac_bands ); @@ -6528,8 +6772,10 @@ void ivas_spar_set_bitrate_config_fx( n_input = ivas_sba_get_nchan_metadata_fx( sba_order, ivas_total_brate ); n_dmx = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); n_dec = sub( n_input, n_dmx ); bits_PR = ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][0]; + move16(); num_PR_bits_dirac_bands = i_mult( num_PR_bits_dirac_bands, bits_PR ); bits_PR = i_mult( bits_PR, sub( n_input, 1 ) ); bits_C = i_mult( ivas_spar_br_table_consts_fx[table_idx].q_lvls[quant_strat][1], i_mult( sub( n_dmx, 1 ), n_dec ) ); @@ -6552,6 +6798,7 @@ void ivas_spar_set_bitrate_config_fx( IF( EQ_16( pSpar_md_cfg->nchan_transport, 1 ) ) { agc_bits = AGC_BITS_PER_CH; + move16(); } ELSE { @@ -6561,11 +6808,14 @@ void ivas_spar_set_bitrate_config_fx( ELSE { agc_bits = AGC_SIGNALLING_BITS; + move16(); } + test(); IF( EQ_32( ivas_total_brate, PCA_BRATE ) && EQ_32( sba_order, SBA_FOA_ORDER ) ) { pca_bits = 1; + move16(); IF( pca_flag ) { pca_bits = add( pca_bits, sub( add( IVAS_PCA_QBITS, IVAS_PCA_QBITS ), 1 ) ); @@ -6574,9 +6824,11 @@ void ivas_spar_set_bitrate_config_fx( ELSE { pca_bits = 0; + move16(); } pSpar_md_cfg->max_md_bits_spar = add( add( pSpar_md_cfg->max_bits_per_blk, agc_bits ), pca_bits ); + move16(); } return; @@ -6588,6 +6840,7 @@ void ivas_spar_set_bitrate_config_fx( * Set SPAR bitrate distribution *-----------------------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_spar_bitrate_dist( int32_t core_brates_act[], /* o : bitrates per core-coder */ const int16_t nAvailBits, /* i : number of available bits */ @@ -6671,3 +6924,99 @@ void ivas_spar_bitrate_dist( return; } + +#else +void ivas_spar_bitrate_dist_fx( + Word32 core_brates_act[], /* o : bitrates per core-coder */ + const Word16 nAvailBits, /* i : number of available bits */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order */ + const Word16 bwidth /* i : audio bandwidth */ +) +{ + Word16 i, nchan_transport, table_idx, bitlen; + Word16 core_bits_act[FOA_CHANNELS], core_range_bits[FOA_CHANNELS]; + Word16 sum_core_act_bits, residual_bits, overflow_bits; + + table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order, bwidth, &bitlen, NULL ); + + nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; + move16(); + + sum_core_act_bits = 0; + move16(); + FOR( i = 0; i < nchan_transport; i++ ) + { + core_bits_act[i] = extract_l( Mpy_32_16_1( ivas_spar_br_table_consts[table_idx].core_brs[i][0], INV_FRAME_PER_SEC_Q15 ) ); + move16(); + + sum_core_act_bits = add( sum_core_act_bits, core_bits_act[i] ); + } + + residual_bits = sub( nAvailBits, sum_core_act_bits ); + + /* First compute core-coder bits as per bitrate distribution table and MD bitrate*/ + IF( residual_bits > 0 ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][2], ivas_spar_br_table_consts[table_idx].core_brs[i][0] ), INV_FRAME_PER_SEC_Q15 ) ); + move16(); + core_bits_act[i] = add( core_bits_act[i], min( residual_bits, core_range_bits[i] ) ); + move16(); + residual_bits = sub( residual_bits, core_range_bits[i] ); + + IF( residual_bits <= 0 ) + { + BREAK; + } + } + } + ELSE + { + FOR( i = 0; i < nchan_transport; i++ ) + { + core_range_bits[i] = extract_l( Mpy_32_16_1( L_sub( ivas_spar_br_table_consts[table_idx].core_brs[i][0], ivas_spar_br_table_consts[table_idx].core_brs[i][1] ), INV_FRAME_PER_SEC_Q15 ) ); + move16(); + } + + overflow_bits = negate( residual_bits ); + + FOR( i = 0; i < nchan_transport; i++ ) + { + core_bits_act[sub( sub( nchan_transport, 1 ), i )] = sub( core_bits_act[sub( sub( nchan_transport, 1 ), i )], min( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ) ); + move16(); + overflow_bits = sub( overflow_bits, core_range_bits[sub( sub( nchan_transport, 1 ), i )] ); + + IF( overflow_bits <= 0 ) + { + BREAK; + } + } + + IF( overflow_bits > 0 ) + { + Word16 overflow_bits_ch; + overflow_bits_ch = idiv1616( overflow_bits, nchan_transport ); + + FOR( i = 0; i < nchan_transport; i++ ) + { + core_bits_act[i] = sub( core_bits_act[i], overflow_bits_ch ); + move16(); + overflow_bits = sub( overflow_bits, overflow_bits_ch ); + } + + core_bits_act[sub( nchan_transport, 1 )] = sub( core_bits_act[sub( nchan_transport, 1 )], max( 0, overflow_bits ) ); + move16(); + } + } + + FOR( i = 0; i < nchan_transport; i++ ) + { + core_brates_act[i] = L_mult0( core_bits_act[i], FRAMES_PER_SEC ); + move32(); + } + + return; +} +#endif diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c index 595d8f1db..b315083d8 100644 --- a/lib_com/ivas_stereo_dft_com.c +++ b/lib_com/ivas_stereo_dft_com.c @@ -43,6 +43,7 @@ #include "ivas_prot_fx.h" #endif +#define INV_FPS 655 // Q15 /*------------------------------------------------------------------------- * stereo_dft_config() * @@ -73,7 +74,7 @@ void stereo_dft_config_fx( move16(); /* ITD, IPD and residual coding is not used in SID/No data */ - IF( EQ_32( brate, FRAME_NO_DATA ) ) + IF( brate == FRAME_NO_DATA ) { *bits_frame_nominal = FRAME_NO_DATA; move16(); @@ -324,15 +325,16 @@ Word16 stereo_dft_band_config_fx( Word16 nbands; /*sanity check*/ - assert( ( EQ_16( band_res, 1 ) || EQ_16( band_res, 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" ); + assert( ( EQ_16( band_res, 1 ) || ( band_res == 0 ) || EQ_16( band_res, 2 ) ) && "stereo DFT: Parameter band resolution not supported!\n" ); band_limits[0] = 1; move16(); nbands = 0; move16(); - WHILE( LT_16( band_limits[nbands++], shr( NFFT, 1 ) ) ) + WHILE( LT_16( band_limits[nbands], shr( NFFT, 1 ) ) ) { - IF( EQ_16( band_res, 0 ) ) + nbands = add( nbands, 1 ); + IF( band_res == 0 ) { assert( 0 && "stereo DFT: band config failed!\n" ); } @@ -367,7 +369,7 @@ Word16 stereo_dft_band_config_fx( assert( ( LT_16( nbands, STEREO_DFT_ERB8_BANDS ) ) && "stereo DFT: band config failed!\n" ); } } - nbands = sub( nbands, 1 ); + band_limits[nbands] = shr( NFFT, 1 ); /*Nyquist Freq*/ move16(); diff --git a/lib_com/ivas_stereo_eclvq_com_fx.c b/lib_com/ivas_stereo_eclvq_com_fx.c index 1fd3ce5a4..c72cc5510 100644 --- a/lib_com/ivas_stereo_eclvq_com_fx.c +++ b/lib_com/ivas_stereo_eclvq_com_fx.c @@ -54,8 +54,11 @@ void ECSQ_init_instance_fx( void *ac_handle ) { ecsq_inst->config_index = config_index; + move16(); ecsq_inst->encoding_active = 1; + move16(); ecsq_inst->bit_count_estimate = 0; + move32(); ecsq_inst->ac_handle = ac_handle; return; @@ -73,6 +76,7 @@ Word32 ECSQ_dequantize_gain_fx( Word32 global_gain; Word32 L_tmp, L_prod; Word16 gg_e, tmp_e = 16; + move16(); /* pow(10.0, index * ECLVQ_INV_GLOBAL_GAIN_FACTOR) = pow(2.0,(index * ECLVQ_INV_GLOBAL_GAIN_FACTOR)*3.321928 */ L_prod = Mpy_32_16_1( ECLVQ_INV_GLOBAL_GAIN_FACTOR_Q24, shl( index, 8 ) ); /* Q17 */ @@ -103,6 +107,7 @@ void ECSQ_dequantize_vector_fx( FOR( i = 0; i < N; ++i ) { output[i] = Mpy_32_16_1( global_gain, input[i] ); + move32(); } return; diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index a4881b800..f5f4c423d 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -133,11 +133,19 @@ static void interpTargetChannel_fx( Word32 spread_factor2_fx; Word64 tempD1_fx, tempD2_fx; - d = sub( prevShift, currShift ); - signShift = GE_16( d, 0 ) ? ( 1 ) : ( -1 ); - move16(); + d = negate( sub( currShift, prevShift ) ); + IF( d >= 0 ) + { + signShift = 1; + move16(); + } + ELSE + { + signShift = -1; + move16(); + } - IF( EQ_16( d, 0 ) ) + IF( d == 0 ) { /* this can happen in DFT->TD switching */ return; @@ -187,21 +195,21 @@ static void interpTargetChannel_fx( ptr1_fx = target_fx; ptr2_fx = tempBuff1_fx + ( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; - FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < ( N + N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i++ ) + FOR( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < imult1616( ( add( add( N, N_MAX_SHIFT_CHANGE ), 1 ) ), INTERP_FACTOR1 ); i++ ) { - IF( i & 0x1 ) + IF( s_and( i, 0x1 ) ) { ptr2_fx[i] = 0; move32(); /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */ /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */ - lim1 = add( shr( ( i - SINC_ORDER1 ), 1 ), 1 ); + lim1 = add( shr( sub( i, SINC_ORDER1 ), 1 ), 1 ); - lim2 = shr( ( i + SINC_ORDER1 ), 1 ); + lim2 = shr( add( i, SINC_ORDER1 ), 1 ); FOR( j = lim1; j <= lim2; j++ ) { - ptr2_fx[i] = L_add( Mpy_32_32( win_fx[j * INTERP_FACTOR1 - i], ptr1_fx[j] ), ptr2_fx[i] ); + ptr2_fx[i] = L_add( Mpy_32_32( win_fx[sub( imult1616( j, INTERP_FACTOR1 ), i )], ptr1_fx[j] ), ptr2_fx[i] ); move32(); } } @@ -216,17 +224,35 @@ static void interpTargetChannel_fx( ptr1_fx = ptr2_fx; ptr2_fx = tempBuff2_fx; - tempD1_fx = table_D1_pointer[L_abs( d )]; - move64(); - tempD2_fx = 3 * table_D1_pointer[L_abs( d )]; - move64(); + tempD1_fx = W_deposit32_l( table_D1_pointer[L_abs( d )] ); + tempD2_fx = W_mult0_32_32( 3, table_D1_pointer[L_abs( d )] ); - tempF1_fx = L_sub( d * factor_fx, ( EQ_16( signShift, 1 ) ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ); - FOR( k = 0; k < N - 1; k++ ) + IF( EQ_16( signShift, 1 ) ) { - Word32 local = ( ( (Word64) tempF1_fx * spread_factor2_fx ) >> 31 ) - ONE_IN_Q12; - Word32 sign_local = GT_32( local, 0 ) ? 1 : -1; - Word32 local_int = (Word32) W_shr( W_abs( local ), 12 ); + tempF1_fx = ONE_IN_Q12; + move32(); + } + ELSE + { + tempF1_fx = -ONE_IN_Q12; + move32(); + } + tempF1_fx = L_sub( imult3216( factor_fx, d ), tempF1_fx ); + FOR( k = 0; k < sub( N, 1 ); k++ ) + { + Word32 local = L_sub( W_extract_l( W_shr( W_mult0_32_32( tempF1_fx, spread_factor2_fx ), 31 ) ), ONE_IN_Q12 ); + Word32 sign_local; + IF( local > 0 ) + { + sign_local = 1; + move32(); + } + ELSE + { + sign_local = -1; + move32(); + } + Word32 local_int = W_extract_l( W_shr( W_abs( local ), 12 ) ); Word32 res_a1, res_a2, res_a3; Word32 res_b1, res_b2, res_b3; Word32 res_c1, res_c2, res_c3; @@ -235,24 +261,24 @@ static void interpTargetChannel_fx( Word64 res_a, res_b, res_c, res_d; Word64 tempa, tempb; Word64 mult_a_D1, mult_b_D2; - local_int = sign_local * local_int; - local_int_scaled = local_int << 12; - lim1 = (Word16) local_int; - IF( local_int_scaled > local ) + local_int = W_extract_l( W_mult0_32_32( sign_local, local_int ) ); + local_int_scaled = W_deposit32_l( L_shl( local_int, 12 ) ); + lim1 = extract_l( local_int ); + if ( W_sub( local_int_scaled, local ) > 0 ) { - lim1--; + lim1 = sub( lim1, 1 ); } y_fx[0] = ptr1_fx[lim1]; move32(); - y_fx[1] = ptr1_fx[lim1 + 1]; + y_fx[1] = ptr1_fx[add( lim1, 1 )]; move32(); - y_fx[2] = ptr1_fx[lim1 + 2]; + y_fx[2] = ptr1_fx[add( lim1, 2 )]; move32(); - y_fx[3] = ptr1_fx[lim1 + 3]; + y_fx[3] = ptr1_fx[add( lim1, 3 )]; move32(); - x_fx[0] = lim1 * interp_factor2_fx; + x_fx[0] = imult3216( interp_factor2_fx, lim1 ); move32(); x_fx[1] = L_add( x_fx[0], interp_factor2_fx ); move32(); @@ -265,38 +291,49 @@ static void interpTargetChannel_fx( res_a1 = L_sub( tempF1_fx, x_fx[0] ); res_a2 = L_sub( tempF1_fx, x_fx[1] ); res_a3 = L_sub( tempF1_fx, x_fx[2] ); - res_a = ( ( (Word64) res_a1 * res_a2 ) >> 12 ) * res_a3; - res_a = ( y_fx[3] * ( res_a >> 16 ) ); + res_a = W_shr( W_mult0_32_32( res_a1, res_a2 ), 12 ) * res_a3; + res_a = ( y_fx[3] * W_shr( res_a, 16 ) ); res_b1 = L_sub( tempF1_fx, x_fx[1] ); res_b2 = L_sub( tempF1_fx, x_fx[2] ); res_b3 = L_sub( tempF1_fx, x_fx[3] ); - res_b = ( ( (Word64) res_b1 * res_b2 ) >> 12 ) * res_b3; - res_b = ( y_fx[0] * ( res_b >> 16 ) ); + res_b = W_shr( W_mult0_32_32( res_b1, res_b2 ), 12 ) * res_b3; + res_b = ( y_fx[0] * W_shr( res_b, 16 ) ); res_c1 = L_sub( tempF1_fx, x_fx[0] ); res_c2 = L_sub( tempF1_fx, x_fx[2] ); res_c3 = L_sub( tempF1_fx, x_fx[3] ); - res_c = ( ( (Word64) res_c1 * res_c2 ) >> 12 ) * res_c3; - res_c = ( y_fx[1] * ( res_c >> 16 ) ); + res_c = W_shr( W_mult0_32_32( res_c1, res_c2 ), 12 ) * res_c3; + res_c = ( y_fx[1] * W_shr( res_c, 16 ) ); res_d1 = L_sub( tempF1_fx, x_fx[0] ); res_d2 = L_sub( tempF1_fx, x_fx[1] ); res_d3 = L_sub( tempF1_fx, x_fx[3] ); - res_d = ( ( (Word64) res_d1 * res_d2 ) >> 12 ) * res_d3; - res_d = ( y_fx[2] * ( res_d >> 16 ) ); + res_d = W_shr( W_mult0_32_32( res_d1, res_d2 ), 12 ) * res_d3; + res_d = ( y_fx[2] * W_shr( res_d, 16 ) ); tempa = W_sub( res_a, res_b ); tempb = W_sub( res_c, res_d ); - mult_a_D1 = ( tempD1_fx * ( tempa >> 14 ) ) >> 15; - mult_b_D2 = ( tempD2_fx * ( tempb >> 14 ) ) >> 15; - ptr2_fx[k] = (Word32) ( ( mult_a_D1 + mult_b_D2 ) >> 14 ); // 38-14 - tempF1_fx = (Word32) W_add( tempF1_fx, L_sub( factor_fx, ( EQ_16( signShift, 1 ) ? ONE_IN_Q12 : -( ONE_IN_Q12 ) ) ) ); + mult_a_D1 = W_shr( ( tempD1_fx * W_shr( tempa, 14 ) ), 15 ); + mult_b_D2 = W_shr( ( tempD2_fx * W_shr( tempb, 14 ) ), 15 ); + ptr2_fx[k] = W_extract_l( ( W_shr( W_add( mult_a_D1, mult_b_D2 ), 14 ) ) ); // 38-14 + move32(); + + IF( EQ_16( signShift, 1 ) ) + { + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, ONE_IN_Q12 ) ) ); + move32(); + } + ELSE + { + tempF1_fx = W_extract_l( W_add( tempF1_fx, L_sub( factor_fx, -ONE_IN_Q12 ) ) ); + move32(); + } } ptr1_fx = target_fx; - Copy32( ptr2_fx, ptr1_fx, N - 1 ); + Copy32( ptr2_fx, ptr1_fx, sub( N, 1 ) ); return; } @@ -321,15 +358,14 @@ static void targetCh_AlignStereoDFT_fx( Word32 fadeOutBuff_fx[L_SHIFT_ADAPT_MAX]; Word32 fadeInBuff_fx[L_SHIFT_ADAPT_MAX]; - d = sub( prevShift, currShift ); + d = negate( sub( currShift, prevShift ) ); Copy32( target_fx + d, fadeOutBuff_fx, L_shift_adapt ); Copy32( target_fx, fadeInBuff_fx, L_shift_adapt ); - IF( GT_16( L_shift_adapt, 0 ) ) + IF( L_shift_adapt > 0 ) { alpha_fx = 0; - move32(); SWITCH( L_shift_adapt ) { case 596: @@ -385,7 +421,7 @@ void adjustTargetSignal_fx( { /* inter-frame shift variation and target shifting */ - IF( EQ_16( method, 0 ) ) + IF( method == 0 ) { interpTargetChannel_fx( target_fx, prevShift, currShift, L_shift_adapt ); } diff --git a/lib_com/ivas_stereo_mdct_bands_com.c b/lib_com/ivas_stereo_mdct_bands_com.c index 7fa5c100d..1cc569461 100644 --- a/lib_com/ivas_stereo_mdct_bands_com.c +++ b/lib_com/ivas_stereo_mdct_bands_com.c @@ -84,13 +84,22 @@ void stereo_mdct_init_bands_fx( { tcx_mode = tmp_tcx_mode; move16(); - L_frameTCX = EQ_16( tcx_mode, TCX_20_CORE ) ? L_frame : ( L_frame / 2 ); - move16(); + + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + L_frameTCX = L_frame; + move16(); + } + ELSE + { + L_frameTCX = shr( L_frame, 1 ); + move16(); + } } ELSE { /*transition frame*/ - L_frameTCX = add( L_frame, L_frame / 4 ); + L_frameTCX = add( L_frame, shr( L_frame, 2 ) ); tcx_mode = TCX_20_CORE; move16(); } @@ -100,10 +109,27 @@ void stereo_mdct_init_bands_fx( { sfbParam.steBands = mdctStereoBands_32000_640; - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[0] : sfbParam.steBands->bndCnt_TCX10[0]; - move16(); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[0]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[0]; + move16(); + } - sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + sfbWidths = sfbParam.steBands->bandLengthsTCX20; + move16(); + } + ELSE + { + sfbWidths = sfbParam.steBands->bandLengthsTCX10; + move16(); + } } ELSE { @@ -114,15 +140,40 @@ void stereo_mdct_init_bands_fx( SWITCH( L_frame ) { case L_FRAME32k: - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[1] : sfbParam.steBands->bndCnt_TCX10[1]; - move16(); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[1]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[1]; + move16(); + } BREAK; case L_FRAME25_6k: - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[2] : sfbParam.steBands->bndCnt_TCX10[2]; - move16(); + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[2]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[2]; + move16(); + } BREAK; case L_FRAME16k: - cnt = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bdnCnt_TCX20[3] : sfbParam.steBands->bndCnt_TCX10[3]; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + cnt = sfbParam.steBands->bdnCnt_TCX20[3]; + move16(); + } + ELSE + { + cnt = sfbParam.steBands->bndCnt_TCX10[3]; + move16(); + } move16(); BREAK; default: @@ -130,7 +181,16 @@ void stereo_mdct_init_bands_fx( return; } - sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.steBands->bandLengthsTCX20 : sfbParam.steBands->bandLengthsTCX10; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + sfbWidths = sfbParam.steBands->bandLengthsTCX20; + move16(); + } + ELSE + { + sfbWidths = sfbParam.steBands->bandLengthsTCX10; + move16(); + } } ELSE { @@ -151,7 +211,16 @@ void stereo_mdct_init_bands_fx( return; } - sfbWidths = EQ_16( tcx_mode, TCX_20_CORE ) ? sfbParam.lpcBndsParam->bandLengthsTCX20 : sfbParam.lpcBndsParam->bandLengthsTCX10; + IF( EQ_16( tcx_mode, TCX_20_CORE ) ) + { + sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX20; + move16(); + } + ELSE + { + sfbWidths = sfbParam.lpcBndsParam->bandLengthsTCX10; + move16(); + } cnt = 64; move16(); } @@ -181,7 +250,17 @@ void stereo_mdct_init_bands_fx( IF( igf ) { Word16 sfbOldCnt = *sfbCnt; - Word16 igfSfbStep = hIgfGrid->infoIsRefined ? 2 : 1; + Word16 igfSfbStep; + IF( hIgfGrid->infoIsRefined ) + { + igfSfbStep = 2; + move16(); + } + ELSE + { + igfSfbStep = 1; + move16(); + } Word16 k; move16(); move16(); @@ -213,7 +292,7 @@ void stereo_mdct_init_bands_fx( move16(); /* better save than sorry, overwrite anything that is left above */ - FOR( i = *sfbCnt + 1; i < sfbOldCnt + 1; i++ ) + FOR( i = add( *sfbCnt, 1 ); i < add( sfbOldCnt, 1 ); i++ ) { sfbOffset[i] = 0; move16(); @@ -224,9 +303,9 @@ void stereo_mdct_init_bands_fx( IF( LT_16( sfbOffset[*sfbCnt], L_frameTCX ) ) { Word16 nMissingBins = sub( L_frameTCX, sfbOffset[*sfbCnt] ); - if ( LT_16( sfbWidths[i] / 2, nMissingBins ) ) + if ( LT_16( shr( sfbWidths[i], 1 ), nMissingBins ) ) { - ( *sfbCnt )++; + *sfbCnt = add( *sfbCnt, 1 ); } sfbOffset[*sfbCnt] = L_frameTCX; move16(); diff --git a/lib_com/ivas_stereo_mdct_stereo_com.c b/lib_com/ivas_stereo_mdct_stereo_com.c index a17ba876f..f28c69b22 100644 --- a/lib_com/ivas_stereo_mdct_stereo_com.c +++ b/lib_com/ivas_stereo_mdct_stereo_com.c @@ -56,10 +56,10 @@ void splitAvailableBits_fx( Word16 *bits_ch1 /* o : bits for channel 1 */ ) { - assert( split_ratio >= 1 && split_ratio < SMDCT_BITRATE_RATIO_RANGE ); + assert( split_ratio >= 1 && LT_16( split_ratio, SMDCT_BITRATE_RATIO_RANGE ) ); /* *bits_ch0 = split_ratio * total_bits / SMDCT_BITRATE_RATIO_RANGE; */ - *bits_ch0 = extract_l( L_mult0( split_ratio, total_bits ) / SMDCT_BITRATE_RATIO_RANGE ); + *bits_ch0 = extract_l( L_shr( L_mult0( split_ratio, total_bits ), 3 ) ); move16(); /* for SBA mode bias the distribution towards the W channel */ test(); diff --git a/lib_com/ivas_stereo_psychlpc_com.c b/lib_com/ivas_stereo_psychlpc_com.c index fce1f62ab..33b6c20db 100644 --- a/lib_com/ivas_stereo_psychlpc_com.c +++ b/lib_com/ivas_stereo_psychlpc_com.c @@ -84,6 +84,8 @@ ivas_error PsychoacousticParameters_Init( pPsychParams->nBins = nBins; pPsychParams->nBands = nBands; + move16(); + move16(); IF( !isWarped ) { @@ -164,14 +166,22 @@ void SetCurrentPsychParams( const Word16 last_frame_was_concealed_cng, TCX_CONFIG_HANDLE hTcxCfg ) { - IF( EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) && EQ_16( last_frame_was_concealed_cng, 0 ) ) + test(); + IF( EQ_16( hTcxCfg->tcx_last_overlap_mode, TRANSITION_OVERLAP ) && ( last_frame_was_concealed_cng == 0 ) ) { assert( core == TCX_20_CORE ); hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX20AfterACELP; } ELSE { - hTcxCfg->psychParamsCurrent = ( EQ_16( core, TCX_10_CORE ) ) ? &hTcxCfg->psychParamsTCX10 : &hTcxCfg->psychParamsTCX20; + IF( EQ_16( core, TCX_10_CORE ) ) + { + hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX10; + } + ELSE + { + hTcxCfg->psychParamsCurrent = &hTcxCfg->psychParamsTCX20; + } } return; diff --git a/lib_com/ivas_stereo_td_bit_alloc.c b/lib_com/ivas_stereo_td_bit_alloc.c index a03100b25..36f2cfc81 100644 --- a/lib_com/ivas_stereo_td_bit_alloc.c +++ b/lib_com/ivas_stereo_td_bit_alloc.c @@ -438,373 +438,477 @@ void tdm_bit_alloc( #else void tdm_bit_alloc( - const Word16 ivas_format, /* i : IVAS format */ - const Word16 ism_mode, /* i : ISM mode in combined format */ - const int32_t element_brate_wo_meta, /* i : element bitrate without metadata */ - const Word16 tdm_lp_reuse_flag, /* i : LPC reusage flag */ - Word32 *total_brate_pri, /* o : Allocated primary channel bitrate */ - Word32 *total_brate_sec, /* o : Allocated secondary channel bitrate */ - Word16 *tdm_low_rate_mode, /* o : secondary channel low rate mode flag*/ - const Word16 coder_type, /* i : secondary channel coder type */ - const Word16 ener_ratio_idx, /* i : correlation ratio indexe */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 bwidth_pri, /* i : bandwidth of the primary channel */ - const Word16 bwidth_sec, /* i : bandwidth of the secondary channel */ - const Word16 flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan.*/ - const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ - const Word16 coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ - const Word16 tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ + const Word16 ivas_format, /* i : IVAS format */ + const Word16 ism_mode, /* i : ISM mode in combined format */ + const Word32 element_brate_wo_meta, /* i : element bitrate without metadata */ + const Word16 tdm_lp_reuse_flag, /* i : LPC reusage flag */ + Word32 *total_brate_pri, /* o : Allocated primary channel bitrate */ + Word32 *total_brate_sec, /* o : Allocated secondary channel bitrate */ + Word16 *tdm_low_rate_mode, /* o : secondary channel low rate mode flag*/ + const Word16 coder_type, /* i : secondary channel coder type */ + const Word16 ener_ratio_idx, /* i : correlation ratio indexe */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 bwidth_pri, /* i : bandwidth of the primary channel */ + const Word16 bwidth_sec, /* i : bandwidth of the secondary channel */ + const Word16 flag_ACELP16k_pri, /* i : ACELP@16kHz core flag, primary chan.*/ + const Word16 tdm_LRTD_flag, /* i : LRTD stereo mode flag */ + const Word16 coder_type0, /* i : coder type (temporary in the encoder, from bitstream in decoder) */ + const Word16 tdm_inst_ratio_idx_ref /* i : instantaneous correlation ratio idx */ ) { Word16 idx, four_subfr_fcb, two_subfr_fcb; Word32 bit_rate_diff_fx; - Word16 BWE_brate, tmp_bits; + Word32 BWE_brate; + Word16 tmp_bits; Word16 tdm_inst_ratio_idx = tdm_inst_ratio_idx_ref; - IF( tdm_inst_ratio_idx == TDM_NQ ) + move16(); + if ( EQ_16( tdm_inst_ratio_idx, TDM_NQ ) ) { tdm_inst_ratio_idx = LRTD_STEREO_MID_IS_PRIM; /* Bit rate almost split half and half*/ + move16(); } /* Decision on using the low rate mode or the normal mode */ /* default is using the low rate mode for the secondary channel coding*/ /* UC and IC are automatically coded with low rate mode */ *tdm_low_rate_mode = 1; + move16(); /* Allocating different bitrate to channels */ idx = 0; - IF( element_brate_wo_meta <= IVAS_13k2 ) + move16(); + IF( LE_32( element_brate_wo_meta, IVAS_13k2 ) ) { idx = 0; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_16k4 ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) { idx = 1; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_24k4 ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_24k4 ) ) { idx = 2; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_32k ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_32k ) ) { idx = 3; + move16(); } - ELSE IF( element_brate_wo_meta <= IVAS_48k ) + ELSE IF( LE_32( element_brate_wo_meta, IVAS_48k ) ) { idx = 4; + move16(); } - IF( coder_type == UNVOICED && tdm_bit_allc_tbl[idx][coder_type] >= 4200 ) + test(); + if ( EQ_16( coder_type, UNVOICED ) && GE_16( tdm_bit_allc_tbl[idx][coder_type], 4200 ) ) { *tdm_low_rate_mode = 0; + move16(); } /* Secondary channel based bitrate allocation */ *total_brate_sec = tdm_bit_allc_tbl[idx][coder_type]; - + move16(); + + test(); + test(); + test(); + test(); + test(); + test(); /* secondary channel bitrate allocation based on the energy scaling ratio */ - IF( ( ( ivas_format != MASA_ISM_FORMAT || ism_mode == ISM_MODE_NONE ) && ( ( coder_type != UNVOICED ) || tdm_LRTD_flag == 1 ) ) || ( ivas_format == MASA_ISM_FORMAT && ism_mode != ISM_MODE_NONE && coder_type > UNVOICED ) ) + IF( ( ( NE_16( ivas_format, MASA_ISM_FORMAT ) || ism_mode == ISM_MODE_NONE ) && ( ( NE_16( coder_type, UNVOICED ) ) || EQ_16( tdm_LRTD_flag, 1 ) ) ) || ( EQ_16( ivas_format, MASA_ISM_FORMAT ) && ism_mode != ISM_MODE_NONE && GT_16( coder_type, UNVOICED ) ) ) { - bit_rate_diff_fx = ( element_brate_wo_meta - 2 * *total_brate_sec ); + bit_rate_diff_fx = L_sub( element_brate_wo_meta, L_shl( *total_brate_sec, 1 ) ); - IF( tdm_LRTD_flag == 1 ) /* > element_brate > STEREO_22k or CT0 not used */ + IF( EQ_16( tdm_LRTD_flag, 1 ) ) /* > element_brate > STEREO_22k or CT0 not used */ { /* further adjustment in function of the energy/correlation ratio */ IF( coder_type == INACTIVE ) { Word32 res_fix = 0; - res_fix = Mpy_32_32( 644245095, ( element_brate_wo_meta - 500 ) ); - res_fix = ( ( res_fix / 100 ) * 100 ); + move32(); + res_fix = Mpy_32_32( 644245095, L_sub( element_brate_wo_meta, 500 ) ); + res_fix = imult3216( Mpy_32_16_1( L_abs( res_fix ), 328 ), 100 ); + if ( res_fix < 0 ) + { + res_fix = L_negate( res_fix ); + } *total_brate_sec = max( *total_brate_sec, res_fix ); + move32(); - //*total_brate_sec = max(*total_brate_sec, (int16_t)(0.3f * (element_brate_wo_meta - 500) / 100) * 100); - tmp_bits = (Word16) ( -abs( tdm_inst_ratio_idx - 16 ) * 200 * idx ); + tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( idx, 200 ) ); } ELSE { Word32 res_fix = 0; - res_fix = Mpy_32_32( 1073741824, ( element_brate_wo_meta - 500 ) ); - res_fix = ( ( res_fix / 100 ) * 100 ); + move32(); + res_fix = Mpy_32_32( 1073741824, L_sub( element_brate_wo_meta, 500 ) ); + res_fix = imult3216( Mpy_32_16_1( L_abs( res_fix ), 328 ), 100 ); + if ( res_fix < 0 ) + { + res_fix = L_negate( res_fix ); + } *total_brate_sec = max( *total_brate_sec, res_fix ); + move32(); - //*total_brate_sec = max(*total_brate_sec, (int16_t)(0.5f * (element_brate_wo_meta - 500) / 100) * 100); - /* tmp_bits = -abs(tdm_inst_ratio_idx-16)*200*idx; */ - tmp_bits = (Word16) ( -abs( tdm_inst_ratio_idx - 16 ) * 100 * idx ); + tmp_bits = imult1616( negate( abs_s( sub( tdm_inst_ratio_idx, 16 ) ) ), imult1616( 100, idx ) ); } /* tmp_bits should be subtract from the secondary channel bitrate */ /* IF the primary channel doesn't correspond to the channel having the highest correlation to the mono- inverse the bitrate compensation */ - IF( ( ener_ratio_idx >= LRTD_STEREO_MID_IS_PRIM && tdm_inst_ratio_idx < LRTD_STEREO_MID_IS_PRIM ) || ( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM && tdm_inst_ratio_idx >= LRTD_STEREO_MID_IS_PRIM ) ) + test(); + test(); + test(); + if ( ( GE_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) && LT_16( tdm_inst_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) || ( LT_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) && GE_16( tdm_inst_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) ) { - tmp_bits *= -1; + tmp_bits = negate( tmp_bits ); } bit_rate_diff_fx = tmp_bits; + move16(); } - ELSE{ - IF( ener_ratio_idx < LRTD_STEREO_MID_IS_PRIM ){ - - bit_rate_diff_fx = ( LRTD_STEREO_MID_IS_PRIM - ener_ratio_idx ) * bit_rate_diff_fx; - bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); - bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation - } - ELSE - { - bit_rate_diff_fx = ( ener_ratio_idx - LRTD_STEREO_MID_IS_PRIM ) * bit_rate_diff_fx; - bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); - bit_rate_diff_fx = bit_rate_diff_fx / 10; // basop gives very minor deviation - } -} -/*bit_rate_diff2 = ((Word16)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/ -*total_brate_sec += ( (Word16) ( bit_rate_diff_fx / 100 ) * 100 ); -*total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); + ELSE + { + IF( LT_16( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ) + { -IF( coder_type == INACTIVE && tdm_LRTD_flag == 0 ) -{ - *total_brate_sec = min( *total_brate_sec, MIN_BRATE_SWB_BWE ); -} + bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( LRTD_STEREO_MID_IS_PRIM, ener_ratio_idx ) ); + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); + bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 ); + if ( bit_rate_diff_fx < 0 ) + { + bit_rate_diff_fx = L_negate( bit_rate_diff_fx ); + } + } + ELSE + { + bit_rate_diff_fx = imult3216( bit_rate_diff_fx, sub( ener_ratio_idx, LRTD_STEREO_MID_IS_PRIM ) ); + bit_rate_diff_fx = L_shr( bit_rate_diff_fx, 1 ); + bit_rate_diff_fx = Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 3277 ); + if ( bit_rate_diff_fx < 0 ) + { + bit_rate_diff_fx = L_negate( bit_rate_diff_fx ); + } + } + } + /*bit_rate_diff2 = ((Word16)(10.f*(-0.5f*ener_ratio_LR+0.5f)*bit_rate_diff)/100)*100;*/ + Word32 temp = imult3216( Mpy_32_16_1( L_abs( bit_rate_diff_fx ), 328 ), 100 ); + if ( bit_rate_diff_fx < 0 ) + { + temp = L_negate( temp ); + } + *total_brate_sec = L_add( *total_brate_sec, temp ); + move32(); -IF( ( ener_ratio_idx <= 1 || ener_ratio_idx >= 29 ) && coder_type >= UNVOICED ) -{ - Word16 delta_brate = 0; + *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[idx][coder_type] ); + move32(); - IF( bwidth_pri > WB ) - { - delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE */ - IF( element_brate_wo_meta <= IVAS_16k4 ) + test(); + IF( ( coder_type == INACTIVE ) && tdm_LRTD_flag == 0 ) { - delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE */ + *total_brate_sec = min( *total_brate_sec, MIN_BRATE_SWB_BWE ); + move32(); } - } - IF( element_brate_wo_meta <= IVAS_13k2 ) - { - *total_brate_sec = max( *total_brate_sec, 5600 + delta_brate ); /* ~42-47 % of the total bitrate */ - } - ELSE IF( element_brate_wo_meta <= IVAS_16k4 ) - { - *total_brate_sec = max( *total_brate_sec, 6500 + delta_brate ); /* ~40-43 % of the total bitrate */ - } - ELSE IF( element_brate_wo_meta <= IVAS_24k4 ) - { - *total_brate_sec = max( *total_brate_sec, 9000 + delta_brate ); /* ~37-39 % of the total bitrate */ - } - ELSE - { - *total_brate_sec = max( *total_brate_sec, 9600 + delta_brate ); /* ~30-32% of the total bitrate */ - } -} -ELSE -{ - *total_brate_sec = min( *total_brate_sec, Mpy_32_32( 9663677, element_brate_wo_meta ) * 100 ); -} + test(); + test(); + IF( ( LE_16( ener_ratio_idx, 1 ) || GE_16( ener_ratio_idx, 29 ) ) && GE_16( coder_type, UNVOICED ) ) + { + Word16 delta_brate = 0; + move16(); -*total_brate_sec = min( *total_brate_sec, 18000 ); -} -ELSE IF( coder_type == UNVOICED ) -{ - IF( tdm_lp_reuse_flag == 0 ) - { - *total_brate_sec += ( 31 + 5 ) * FRAMES_PER_SEC; - } -} + IF( GT_16( bwidth_pri, WB ) ) + { + delta_brate = 600; /* To slightly compensate for SWB BWE instead of WB BWE */ + move16(); + if ( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) + { + delta_brate = 1250; /* To compensate for SWB BWE instead of WB BWE */ + move16(); + } + } -IF( coder_type <= UNVOICED ) -{ - *total_brate_sec = min( *total_brate_sec, MAX_TDM_UC_BRATE ); + IF( LE_32( element_brate_wo_meta, IVAS_13k2 ) ) + { + *total_brate_sec = max( *total_brate_sec, add( 5600, delta_brate ) ); /* ~42-47 % of the total bitrate */ + move32(); + } + ELSE IF( LE_32( element_brate_wo_meta, IVAS_16k4 ) ) + { + *total_brate_sec = max( *total_brate_sec, add( 6500, delta_brate ) ); /* ~40-43 % of the total bitrate */ + move32(); + } + ELSE IF( LE_32( element_brate_wo_meta, IVAS_24k4 ) ) + { + *total_brate_sec = max( *total_brate_sec, add( 9000, delta_brate ) ); /* ~37-39 % of the total bitrate */ + move32(); + } + ELSE + { + *total_brate_sec = max( *total_brate_sec, add( 9600, delta_brate ) ); /* ~30-32% of the total bitrate */ + move32(); + } + } + ELSE + { + *total_brate_sec = min( *total_brate_sec, Mpy_32_32( 9663677, element_brate_wo_meta ) * 100 ); + move32(); + } - IF( *total_brate_sec >= TDM_UC_NORMAL_MODE_MBRATE && tdm_lp_reuse_flag == 0 ) - { - *tdm_low_rate_mode = 0; - } - ELSE IF( *total_brate_sec >= TDM_UC_NORMAL_MODE_MBRATE_LP_R ) - { - *tdm_low_rate_mode = 0; + *total_brate_sec = min( *total_brate_sec, 18000 ); + move32(); } - ELSE IF( ( tdm_lp_reuse_flag == 0 && *total_brate_sec < TDM_UC_NORMAL_MODE_MINBR_LP_R && coder_type == UNVOICED ) || ( tdm_lp_reuse_flag == 0 && *total_brate_sec < ( tdm_bit_allc_tbl[idx][0] + MID_LP_BRATE ) ) ) + ELSE IF( coder_type == UNVOICED ) { - *total_brate_sec += MID_LP_BRATE; + IF( tdm_lp_reuse_flag == 0 ) + { + *total_brate_sec = L_add( *total_brate_sec, imult3216( FRAMES_PER_SEC, 36 ) ); + move32(); + } } -} -/* verify that primary channel bitrate is higher than the minimum supported bitrate */ -IF( flag_ACELP16k_pri ) -{ - BWE_brate = SWB_TBE_1k75; - IF( element_brate_wo_meta < IVAS_24k4 ) + IF( coder_type <= UNVOICED ) { - BWE_brate = SWB_TBE_1k10; + *total_brate_sec = min( *total_brate_sec, MAX_TDM_UC_BRATE ); + move32(); + + test(); + test(); + test(); + test(); + test(); + IF( GE_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MBRATE ) && tdm_lp_reuse_flag == 0 ) + { + *tdm_low_rate_mode = 0; + move16(); + } + ELSE IF( GE_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MBRATE_LP_R ) ) + { + *tdm_low_rate_mode = 0; + move16(); + } + ELSE IF( ( tdm_lp_reuse_flag == 0 && LT_32( *total_brate_sec, TDM_UC_NORMAL_MODE_MINBR_LP_R ) && EQ_16( coder_type, UNVOICED ) ) || ( tdm_lp_reuse_flag == 0 && LE_32( *total_brate_sec, L_deposit_l( add( tdm_bit_allc_tbl[idx][0], MID_LP_BRATE ) ) ) ) ) + { + *total_brate_sec = L_add( *total_brate_sec, MID_LP_BRATE ); + move32(); + } } - IF( bwidth_pri > WB && tdm_LRTD_flag == 0 ) - { - BWE_brate += ( STEREO_BITS_ICBWE + STEREO_ICBWE_MSFLAG_BITS ) * FRAMES_PER_SEC; - } - IF( bwidth_pri > SWB && tdm_LRTD_flag == 1 ) + /* verify that primary channel bitrate is higher than the minimum supported bitrate */ + IF( flag_ACELP16k_pri ) { - BWE_brate += 300; - } + BWE_brate = SWB_TBE_1k75; + move32(); - IF( bwidth_pri == FB ) - { - BWE_brate += ( FB_TBE_1k8 - SWB_TBE_1k75 ); - } + test(); + test(); + if ( LT_32( element_brate_wo_meta, IVAS_24k4 ) ) + { + BWE_brate = SWB_TBE_1k10; + move32(); + } - IF( element_brate_wo_meta - *total_brate_sec - BWE_brate < 14000 ) - { - *total_brate_sec = element_brate_wo_meta - 14000 - BWE_brate; - } -} -ELSE -{ - BWE_brate = SWB_TBE_1k75; - IF( bwidth_pri == WB ) - { - BWE_brate = WB_BWE_0k35; - IF( tdm_LRTD_flag == 0 ) + test(); + if ( GT_16( bwidth_pri, WB ) && tdm_LRTD_flag == 0 ) { - BWE_brate += 250; /* ICA Brate */ + BWE_brate = L_add( BWE_brate, ( STEREO_BITS_ICBWE + STEREO_ICBWE_MSFLAG_BITS ) * FRAMES_PER_SEC ); + } + test(); + if ( GT_16( bwidth_pri, SWB ) && EQ_16( tdm_LRTD_flag, 1 ) ) + { + BWE_brate = L_add( BWE_brate, 300 ); } - } - ELSE IF( tdm_LRTD_flag == 0 ) - { - BWE_brate += 350; /* ICA Brate */ - } -} -IF( coder_type0 == TRANSITION ) -{ - IF( element_brate_wo_meta > IVAS_13k2 ) - { - *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( ACELP_8k00 + BWE_brate ) ); + if ( EQ_16( bwidth_pri, FB ) ) + { + BWE_brate = L_add( BWE_brate, ( FB_TBE_1k8 - SWB_TBE_1k75 ) ); + } + + IF( LT_32( ( L_sub( ( L_sub( element_brate_wo_meta, *total_brate_sec ) ), BWE_brate ) ), 14000 ) ) + { + *total_brate_sec = L_sub( element_brate_wo_meta, L_add( 14000, BWE_brate ) ); + move32(); + } } ELSE { - *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( ACELP_7k20 + BWE_brate ) ); - } -} -ELSE -{ - *total_brate_sec = min( *total_brate_sec, element_brate_wo_meta - ( 5900 + BWE_brate ) ); -} - -IF( coder_type == INACTIVE ) -{ - *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ -} -ELSE -{ - *total_brate_sec = max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ -} - -/* Secondary channel bitrate adjusment */ -/* First, adjust the bitrate depending of what is transmitted */ -/* Second, choose the number of subframe for ACELP core depending of the targetted bitratre */ -/* Finally, verify that the concordance between the number of subframe, the parameters sent and the bitrate available */ -IF( coder_type == GENERIC /* || coder_type == AUDIO*/ ) -{ - /* Adjust the bitrate depending of what is transmitted */ - /* IF LPC are transmitted, ensure enough bits are used */ - IF( tdm_lp_reuse_flag == 0 ) - { - /* Pitch is transmitted as well, further increase the bitrate */ - IF( tdm_Pitch_reuse_flag == 0 ) + BWE_brate = SWB_TBE_1k75; + move32(); + IF( EQ_16( bwidth_pri, WB ) ) { - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); - - IF( tdm_LRTD_flag == 1 && bwidth_sec == SWB ) + BWE_brate = WB_BWE_0k35; + move32(); + if ( tdm_LRTD_flag == 0 ) { - /* ensure that there are enough bits to code SWB TBE_1k10 as well */ - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 ); + BWE_brate = L_add( BWE_brate, 250 ); /* ICA Brate */ } } - ELSE /* only LPC is tranmitted -> IF ( *total_brate_sec < MIN_SEC_BRATE+MIN_SEC_LPC_RATE ) */ + ELSE IF( tdm_LRTD_flag == 0 ) { - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + BWE_brate = L_add( BWE_brate, 350 ); /* ICA Brate */ } } - ELSE IF( /*tdm_lp_reuse_flag == 1*/ tdm_Pitch_reuse_flag == 0 ) - { - *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE ); - } - /* Choose between 2 and 4 subfr, depending of the bitrate available and prevent the gap between the 2 atlernative */ - IF( tdm_LRTD_flag == 1 ) + IF( EQ_16( coder_type0, TRANSITION ) ) { - four_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); - two_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); + IF( GT_32( element_brate_wo_meta, IVAS_13k2 ) ) + { + *total_brate_sec = min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_8k00, BWE_brate ) ) ); + move32(); + } + ELSE + { + *total_brate_sec = min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( ACELP_7k20, BWE_brate ) ) ); + move32(); + } } ELSE { - four_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); - two_subfr_fcb = (Word16) ( *total_brate_sec - ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ); + *total_brate_sec = min( *total_brate_sec, L_sub( element_brate_wo_meta, L_add( 5900, BWE_brate ) ) ); + move32(); } - IF( tdm_lp_reuse_flag == 0 ) + IF( coder_type == INACTIVE ) { - four_subfr_fcb -= MIN_SEC_LPC_RATE; - two_subfr_fcb -= MIN_SEC_LPC_RATE; + *total_brate_sec = max( *total_brate_sec, tdm_bit_allc_tbl[0][0] ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ + move32(); } - - IF( tdm_Pitch_reuse_flag == 0 ) + ELSE { - four_subfr_fcb -= ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC ); - two_subfr_fcb -= MIN_SEC_ACB_RATE; + *total_brate_sec = max( *total_brate_sec, 3500 ); /* sanity check to ensure the secondary channel always gets the minimal bitrate it needs */ + move32(); } - /* Too much bits for the 2 subfr model but not enough for the the 4 subfr model -> slightly reduce the 2nd channel bitrate */ - IF( two_subfr_fcb > 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC && four_subfr_fcb < MIN_4SUBFR_FCB_RATE * FRAMES_PER_SEC ) + /* Secondary channel bitrate adjusment */ + /* First, adjust the bitrate depending of what is transmitted */ + /* Second, choose the number of subframe for ACELP core depending of the targetted bitratre */ + /* Finally, verify that the concordance between the number of subframe, the parameters sent and the bitrate available */ + IF( EQ_16( coder_type, GENERIC ) /* || coder_type == AUDIO*/ ) { - IF( tdm_LRTD_flag == 1 ) + /* Adjust the bitrate depending of what is transmitted */ + /* IF LPC are transmitted, ensure enough bits are used */ + IF( tdm_lp_reuse_flag == 0 ) { - *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + /* Pitch is transmitted as well, further increase the bitrate */ + IF( tdm_Pitch_reuse_flag == 0 ) + { + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + move32(); + + test(); + IF( EQ_16( tdm_LRTD_flag, 1 ) && EQ_16( bwidth_sec, SWB ) ) + { + /* ensure that there are enough bits to code SWB TBE_1k10 as well */ + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SEC_LPC_RATE + MIN_SIGN_RATE + SWB_TBE_1k10 ); + move32(); + } + } + ELSE /* only LPC is tranmitted -> IF ( *total_brate_sec < MIN_SEC_BRATE+MIN_SEC_LPC_RATE ) */ + { + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_LPC_RATE + MIN_SIGN_RATE ); + move32(); + } + } + ELSE IF( /*tdm_lp_reuse_flag == 1*/ tdm_Pitch_reuse_flag == 0 ) + { + *total_brate_sec = max( *total_brate_sec, MIN_FCB_SECRATE2 + MIN_SEC_ACB_RATE + MIN_SIGN_RATE ); + move32(); + } + + /* Choose between 2 and 4 subfr, depending of the bitrate available and prevent the gap between the 2 atlernative */ + IF( EQ_16( tdm_LRTD_flag, 1 ) ) + { + four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); + two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); } ELSE { - *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + four_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 4 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); + two_subfr_fcb = extract_l( L_sub( *total_brate_sec, ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC ) ); } IF( tdm_lp_reuse_flag == 0 ) { - *total_brate_sec += MIN_SEC_LPC_RATE; + four_subfr_fcb = sub( four_subfr_fcb, MIN_SEC_LPC_RATE ); + two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_LPC_RATE ); } IF( tdm_Pitch_reuse_flag == 0 ) { - *total_brate_sec += MIN_SEC_ACB_RATE; + four_subfr_fcb = sub( four_subfr_fcb, ( MIN_SEC_ACB_RATE + 10 * FRAMES_PER_SEC ) ); + two_subfr_fcb = sub( two_subfr_fcb, MIN_SEC_ACB_RATE ); } - } - ELSE IF( four_subfr_fcb >= ( 40 ) * FRAMES_PER_SEC ) /* Enough bits to have minimally 2 x 12 + 2*7 bits FCB */ - { - *tdm_low_rate_mode = 0; /* Use normal rate mode */ - } - ELSE /* Possible slight increase of secondary channel bit budget to compensate for FCB limited flexibility */ - { - Word16 tmp_rate, i; - tmp_rate = two_subfr_fcb; - idx = NB_RATE_POSS - 2; - for ( i = 0; i < NB_RATE_POSS; i++ ) + /* Too much bits for the 2 subfr model but not enough for the the 4 subfr model -> slightly reduce the 2nd channel bitrate */ + test(); + IF( GT_16( two_subfr_fcb, 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC ) && LT_16( four_subfr_fcb, MIN_4SUBFR_FCB_RATE * FRAMES_PER_SEC ) ) { - IF( tmp_rate <= fast_FCB_rates_2sfr[i] ) + IF( EQ_16( tdm_LRTD_flag, 1 ) ) { - idx = i; - break; + *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS - STEREO_BITS_TCA + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + move32(); + } + ELSE + { + *total_brate_sec = 2 * MAX_SC_FCB_RATE * FRAMES_PER_SEC + ( TDM_SIGNAL_BITS_READ_FROM_THE_END_OF_BS + 1 + 2 * MIN_GAIN_BITS ) * FRAMES_PER_SEC; + move32(); + } + + IF( tdm_lp_reuse_flag == 0 ) + { + *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_LPC_RATE ); + move32(); + } + + IF( tdm_Pitch_reuse_flag == 0 ) + { + *total_brate_sec = L_add( *total_brate_sec, MIN_SEC_ACB_RATE ); + move32(); } } - *total_brate_sec += ( fast_FCB_rates_2sfr[idx] - tmp_rate ); - } - /* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ - IF( element_brate_wo_meta - *total_brate_sec == ACELP_13k20 ) - { - *total_brate_sec += 100; + ELSE IF( GE_16( four_subfr_fcb, 40 * FRAMES_PER_SEC ) ) /* Enough bits to have minimally 2 x 12 + 2*7 bits FCB */ + { + *tdm_low_rate_mode = 0; /* Use normal rate mode */ + move16(); + } + ELSE /* Possible slight increase of secondary channel bit budget to compensate for FCB limited flexibility */ + { + Word16 tmp_rate, i; + tmp_rate = two_subfr_fcb; + move16(); + idx = sub( NB_RATE_POSS, 2 ); + + FOR( i = 0; i < NB_RATE_POSS; i++ ){ + IF( LE_16( tmp_rate, fast_FCB_rates_2sfr[i] ) ){ + idx = i; + move16(); + BREAK; + } } + *total_brate_sec = L_add( *total_brate_sec, sub( fast_FCB_rates_2sfr[idx], tmp_rate ) ); + move32(); +} +/* To prevent 13.2 kb/s for primary channel as some bitstream issues arrise with it */ +IF( EQ_32( L_sub( element_brate_wo_meta, *total_brate_sec ), ACELP_13k20 ) ) +{ + *total_brate_sec = L_add( *total_brate_sec, 100 ); + move32(); +} } /* prevent 2.4 kb/s and 2.8 kb/s as they are reserved bitrates for DTX and VBR */ -IF( *total_brate_sec == PPP_NELP_2k80 || *total_brate_sec == SID_2k40 ) +test(); +IF( EQ_32( *total_brate_sec, PPP_NELP_2k80 ) || EQ_32( *total_brate_sec, SID_2k40 ) ) { - *total_brate_sec -= 100; + *total_brate_sec = L_sub( *total_brate_sec, 100 ); + move32(); } -*total_brate_pri = element_brate_wo_meta - *total_brate_sec; +*total_brate_pri = L_sub( element_brate_wo_meta, *total_brate_sec ); +move32(); return; } @@ -882,13 +986,13 @@ void td_stereo_param_updt_fx( { Word16 i; /* Copy some primary channel information into the secondary channel structure for later usage */ - IF( tdm_use_IAWB_Ave_lpc == 1 ) + IF( EQ_16( tdm_use_IAWB_Ave_lpc, 1 ) ) { /*not being assert*/ Copy( IAWB_Ave_fx, tdm_lsfQ_PCh_fx, M ); lsf2lsp_fx( tdm_lsfQ_PCh_fx, tdm_lspQ_PCh_fx, M, INT_FS_12k8 ); } - ELSE IF( flag_ACELP16k == 1 ) + ELSE IF( EQ_16( flag_ACELP16k, 1 ) ) { Copy( lsp_old_PCh_fx, tdm_lspQ_PCh_fx, M ); lsp_convert_poly_fx( tdm_lspQ_PCh_fx, L_FRAME, 0 ); @@ -904,6 +1008,7 @@ void td_stereo_param_updt_fx( { Word16 tmp16; Word16 mult_factor = 26214 /*0.8f in Q15*/; + move16(); FOR( i = 0; i < NB_SUBFR; i++ ) { tmp16 = mult_r( pitch_buf_PCh_fx[i], mult_factor ); /* Convert 16kHz to 12.8 kHz pitch values */ @@ -966,6 +1071,7 @@ static void tdm_SCh_LSF_intra_pred_zero_bits_fx( FOR( i = 0; i < M; i++ ) { pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); + move16(); } return; @@ -1021,29 +1127,38 @@ static void tdm_SCh_LSF_intra_pred_tri_diag_mat_fx( v_sub_16( lsf_SCh_fx, lsf_mean_in_fx, lsf_tmp_fx, M ); lsf_tmp_ptr1_fx = lsf_tmp_fx; + lsf_SCh_ptr_fx = lsf_SCh_fx; + lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; - *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 + *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 + move16(); *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( *lsf_tmp_ptr1_fx, *prd_ptr_fx++ ) ); // Q2.56 + 15 -15 + move16(); lsf_SCh_ptr_fx++; - FOR( i = 1; i < M - 1; i++ ) + FOR( i = 1; i < sub( M, 1 ); i++ ) { lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; // Q2.56 *lsf_SCh_ptr_fx = mult_r( *lsf_tmp_ptr1_fx++, *prd_ptr_fx++ ); // Q2.56 + 15 -15 + move16(); lsf_tmp_ptr2_fx = lsf_tmp_ptr1_fx; *lsf_SCh_ptr_fx = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx++ ), ( *prd_ptr_fx++ ) ) ); + move16(); ( *lsf_SCh_ptr_fx ) = add( *lsf_SCh_ptr_fx, mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx++ ) ) ); + move16(); lsf_SCh_ptr_fx++; } lsf_tmp_ptr1_fx = lsf_tmp_ptr2_fx; *lsf_SCh_ptr_fx = mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ); + move16(); lsf_tmp_ptr1_fx++; prd_ptr_fx++; *lsf_SCh_ptr_fx = add( mult_r( ( *lsf_tmp_ptr1_fx ), ( *prd_ptr_fx ) ), *lsf_SCh_ptr_fx ); + move16(); v_add_16( lsf_SCh_fx, lsf_mean_out_fx, lsf_SCh_fx, M ); @@ -1114,25 +1229,30 @@ void tdm_SCh_LSF_intra_pred_fx( { Word16 fixed_beta; - IF( element_brate <= IVAS_13k2 ) + IF( LE_32( element_brate, IVAS_13k2 ) ) { fixed_beta = 28508; // 0.87f in Q15 + move16(); } - ELSE IF( element_brate <= IVAS_16k4 ) + ELSE IF( LE_32( element_brate, IVAS_16k4 ) ) { fixed_beta = 30801; // 0.94f in Q15 + move16(); } ELSE IF( element_brate <= IVAS_24k4 ) { fixed_beta = 29818; // 0.91f in Q15 + move16(); } - ELSE IF( element_brate <= IVAS_32k ) + ELSE IF( LE_32( element_brate, IVAS_32k ) ) { fixed_beta = 30146; // 0.92f in Q15 + move16(); } ELSE { fixed_beta = 29818; // 0.91f in Q15 + move16(); } tdm_SCh_LSF_intra_pred_zero_bits_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_PRED_QNT_fx, fixed_beta ); @@ -1204,11 +1324,13 @@ static void tdm_SCh_LSF_intra_pred_one_bit_dec_fx( Word16 beta_fx; beta_fx = Beta_Q_x_fx[beta_index_fx]; // Q15 + move16(); /* pulling the LSFs closer to the avergae */ FOR( i = 0; i < M; i++ ) { pred_lsf_SCh_fx[i] = add( mult_r( beta_fx, tdm_lsfQ_PCh_fx[i] ), mult_r( sub( 32767, beta_fx ), lsf_mean_fx[i] ) ); + move16(); } return; @@ -1264,11 +1386,15 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( Word16 A_temp_fx[M]; Word16 B_temp_fx[M]; Word32 WD_fx[2] = { 0 }; + move32(); + move32(); FOR( i = 0; i < M; i++ ) { A_temp_fx[i] = sub( lsf_SCh_fx[i], lsf_mean_fx[i] ); + move16(); B_temp_fx[i] = sub( lsf_mean_fx[i], tdm_lsfQ_PCh_fx[i] ); + move16(); } FOR( i = 0; i < M; i++ ) @@ -1280,16 +1406,20 @@ static void tdm_SCh_LSF_intra_pred_one_bit_enc_fx( Word32 Beta_Q_x1 = L_mult( Beta_Q_x_fx[1], Beta_Q_x_fx[1] ); // Q31 WD_fx[0] = L_add( WD_fx[0], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[0] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x0 ) ) ); + move32(); WD_fx[1] = L_add( WD_fx[1], L_add( L_add( wgt_A_temp, Mpy_32_16_1( L_shl( wgt_AB_temp, 1 ), Beta_Q_x_fx[1] ) ), Mpy_32_32( wgt_B_temp, Beta_Q_x1 ) ) ); + move32(); } - IF( WD_fx[0] < WD_fx[1] ) + IF( LT_32( WD_fx[0], WD_fx[1] ) ) { *beta_index = 0; + move16(); } ELSE { *beta_index = 1; + move16(); } tdm_SCh_LSF_intra_pred_one_bit_dec_fx( tdm_lsfQ_PCh_fx, pred_lsf_SCh_fx, tdm_LSF_MEAN_RE_USE_fx, Beta_Q_x_fx, *beta_index ); @@ -1382,7 +1512,7 @@ void tdm_SCh_lsf_reuse_fx( Beta_Q1bit_re_use_fx = tdm_Beta_Q1bit_re_use_48k_fx; } - IF( EQ_16( enc_dec, ENC ) ) + IF( enc_dec == ENC ) { tdm_SCh_LSF_intra_pred_one_bit_enc_fx( lsf_new_fx, tdm_lsfQ_PCh_fx, lsf_new_fx, tdm_LSF_MEAN_RE_USE_fx, lsf_wgts_fx, Beta_Q1bit_re_use_fx, beta_index ); } diff --git a/lib_com/ivas_transient_det.c b/lib_com/ivas_transient_det.c index de238aa5b..86093edcd 100644 --- a/lib_com/ivas_transient_det.c +++ b/lib_com/ivas_transient_det.c @@ -138,8 +138,10 @@ static void ivas_transient_det_init( #endif #ifdef IVAS_FLOAT_FIXED - hTranDet->in_duck_gain = 1073741824; // Q30 + hTranDet->in_duck_gain = 1073741824; // Q30 + move32(); hTranDet->out_duck_gain = 1073741824; // Q30 + move32(); #else hTranDet->in_duck_gain = 1.0f; hTranDet->out_duck_gain = 1.0f; @@ -212,68 +214,104 @@ static void ivas_transient_det_init( case 48000: /*env_hpf*/ filt_coeff_arr_fx[0][0] = IVAS_C_HPF_48k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_48k_fx; + move32(); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_48k_fx ); + move32(); filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_48k_fx; + move32(); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_48k_fx ); + move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_48k_fx; + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_48k_fx ); + move32(); filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_48k_fx; + move32(); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_48k_fx ); + move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_48k_fx; + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_48k_fx ); + move32(); filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_48k_fx; + move32(); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_48k_fx ); + move32(); hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_48k_fx; + move32(); hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_48k_fx; + move32(); BREAK; case 32000: /*env_hpf*/ filt_coeff_arr_fx[0][0] = IVAS_C_HPF_32k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_32k_fx; + move32(); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_32k_fx ); + move32(); filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_32k_fx; + move32(); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_32k_fx ); + move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_32k_fx; + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_32k_fx ); + move32(); filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_32k_fx; + move32(); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_32k_fx ); + move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_32k_fx; + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_32k_fx ); + move32(); filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_32k_fx; + move32(); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_32k_fx ); + move32(); hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_32k_fx; + move32(); hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_32k_fx; + move32(); BREAK; case 16000: /*env_hpf*/ filt_coeff_arr_fx[0][0] = IVAS_C_HPF_16k_fx; - filt_coeff_arr_fx[0][1] = -IVAS_C_HPF_16k_fx; + move32(); + filt_coeff_arr_fx[0][1] = L_negate( IVAS_C_HPF_16k_fx ); + move32(); filt_coeff_arr_fx[0][3] = ONE_IN_Q30; - filt_coeff_arr_fx[0][4] = -IVAS_C_HPF_16k_fx; + move32(); + filt_coeff_arr_fx[0][4] = L_negate( IVAS_C_HPF_16k_fx ); + move32(); /*env_fast*/ - filt_coeff_arr_fx[1][0] = ONE_IN_Q30 - IVAS_C_FAST_16k_fx; + filt_coeff_arr_fx[1][0] = L_sub( ONE_IN_Q30, IVAS_C_FAST_16k_fx ); + move32(); filt_coeff_arr_fx[1][3] = ONE_IN_Q30; - filt_coeff_arr_fx[1][4] = -IVAS_C_FAST_16k_fx; + move32(); + filt_coeff_arr_fx[1][4] = L_negate( IVAS_C_FAST_16k_fx ); + move32(); /*env_slow*/ - filt_coeff_arr_fx[2][0] = ONE_IN_Q30 - IVAS_C_SLOW_16k_fx; + filt_coeff_arr_fx[2][0] = L_sub( ONE_IN_Q30, IVAS_C_SLOW_16k_fx ); + move32(); filt_coeff_arr_fx[2][3] = ONE_IN_Q30; - filt_coeff_arr_fx[2][4] = -IVAS_C_SLOW_16k_fx; + move32(); + filt_coeff_arr_fx[2][4] = L_negate( IVAS_C_SLOW_16k_fx ); + move32(); hTranDet->in_duck_coeff = IVAS_C_IN_DUCK_16k_fx; + move32(); hTranDet->out_duck_coeff = IVAS_C_OUT_DUCK_16k_fx; + move32(); BREAK; @@ -292,6 +330,7 @@ static void ivas_transient_det_init( hTranDet->duck_mult_fac = IVAS_TDET_DUCK_MULT_FAC; + move32(); return; } @@ -333,6 +372,7 @@ void ivas_transient_det_close( ivas_trans_det_state_t **hTranDet /* i/o: Transient detector handle */ ) { + test(); IF( hTranDet == NULL || *hTranDet == NULL ) { return; @@ -361,25 +401,32 @@ void ivas_transient_det_process_fx( Word32 in_duck_gain[L_FRAME48k]; Word16 num_sf, sf, sf_samp, idx; Word32 mem = hTranDet->in_duck_gain; + move32(); ivas_td_decorr_get_ducking_gains_fx( hTranDet, pIn_pcm, in_duck_gain, NULL, frame_len, IVAS_TDET_ONLY ); transient_det[0] = 0; + move16(); transient_det[1] = 0; - IF( GT_32( L_sub( mem, hTranDet->in_duck_gain ), IVAS_TDET_PARM_TRANS_THR ) ) + move16(); + if ( GT_32( L_sub( mem, hTranDet->in_duck_gain ), IVAS_TDET_PARM_TRANS_THR ) ) { transient_det[0] = 1; + move16(); } num_sf = 16; - sf_samp = frame_len / num_sf; + move16(); + sf_samp = idiv1616( frame_len, num_sf ); FOR( sf = 1; sf <= num_sf; sf++ ) { - idx = ( sf_samp * sf ) - 1; - IF( GT_32( L_sub( mem, in_duck_gain[idx] ), IVAS_POINT_ONE_ONE_IN_Q30 ) ) + idx = sub( imult1616( sf_samp, sf ), 1 ); + if ( GT_32( L_sub( mem, in_duck_gain[idx] ), IVAS_POINT_ONE_ONE_IN_Q30 ) ) { transient_det[1] = 1; + move16(); } mem = in_duck_gain[idx]; + move32(); } return; @@ -471,11 +518,13 @@ static Word32 ivas_calc_duck_gain_fx( IF( LT_32( Mpy_32_32( duck_mult_fac, env_1 ), Mpy_32_32( L_shr( duck_gain_out, 1 ), env_2 ) ) ) { - IF( EQ_32( env_1, 0 ) || EQ_32( env_2, 0 ) ) + test(); + IF( ( env_1 == 0 ) || ( env_2 == 0 ) ) { duck_gain_out = 0; + move32(); } - else + ELSE { duck_gain_out = Mpy_32_32( duck_mult_fac, L_shl( (Word32) ( divide3232( env_1, env_2 ) ), Q16 ) ); duck_gain_out = L_shl( duck_gain_out, Q1 ); @@ -566,14 +615,20 @@ void ivas_td_decorr_get_ducking_gains_fx( const Word16 tdet_flag ) { Word16 i, q = Q14; + move16(); Word32 e_fast_fx[L_FRAME48k], e_slow_fx[L_FRAME48k]; Word32 in_duck_gain = hTranDet->in_duck_gain; + move32(); Word32 out_duck_gain = hTranDet->out_duck_gain; + move32(); Word32 in_duck_coeff = hTranDet->in_duck_coeff; + move32(); Word32 out_duck_coeff = hTranDet->out_duck_coeff; + move32(); Word32 duck_mult_fac = hTranDet->duck_mult_fac; + move32(); - mvl2l( pIn_pcm, e_fast_fx, frame_len ); + Copy32( pIn_pcm, e_fast_fx, frame_len ); /* env hpf */ ivas_filter_process_fx( &hTranDet->env_hpf, e_fast_fx, frame_len, q ); @@ -583,7 +638,9 @@ void ivas_td_decorr_get_ducking_gains_fx( FOR( i = 0; i < frame_len; i++ ) { e_fast_fx[i] = L_add( L_abs( e_fast_fx[i] ), L_shr( IVAS_TDET_PARM_ENV_EPS_fx, q_factor_diff ) ); + move32(); e_slow_fx[i] = e_fast_fx[i]; + move32(); } /* env fast*/ @@ -598,8 +655,10 @@ void ivas_td_decorr_get_ducking_gains_fx( { in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); pIn_duck_gains[i] = in_duck_gain; + move32(); } hTranDet->in_duck_gain = in_duck_gain; + move32(); } ELSE { @@ -607,11 +666,15 @@ void ivas_td_decorr_get_ducking_gains_fx( { in_duck_gain = ivas_calc_duck_gain_fx( in_duck_gain, in_duck_coeff, e_slow_fx[i], e_fast_fx[i], duck_mult_fac ); pIn_duck_gains[i] = in_duck_gain; + move32(); out_duck_gain = ivas_calc_duck_gain_fx( out_duck_gain, out_duck_coeff, e_fast_fx[i], e_slow_fx[i], duck_mult_fac ); pOut_duck_gains[i] = out_duck_gain; + move32(); } hTranDet->in_duck_gain = in_duck_gain; + move32(); hTranDet->out_duck_gain = out_duck_gain; + move32(); } return; diff --git a/lib_com/lag_wind.c b/lib_com/lag_wind.c index 5e289b34f..9cd51345a 100644 --- a/lib_com/lag_wind.c +++ b/lib_com/lag_wind.c @@ -230,7 +230,7 @@ void lag_wind( FOR( i = 1; i <= m; i++ ) { - tmp = Mpy_32( r_h[i], r_l[i], wnd_h[i - 1], wnd_l[i - 1] ); + tmp = Mpy_32( r_h[i], r_l[i], wnd_h[sub( i, 1 )], wnd_l[sub( i, 1 )] ); L_Extract( tmp, &r_h[i], &r_l[i] ); } } @@ -283,7 +283,8 @@ void lag_wind_32( FOR( i = 1; i <= m; i++ ) { - r[i] = Mpy_32_32( r[i], wnd[i - 1] ); + r[i] = Mpy_32_32( r[i], wnd[sub( i, 1 )] ); + move32(); } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 5bc296fbc..42ff82c70 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -959,7 +959,11 @@ ivas_error ivas_sba_dec_reconfigure_fx( ivas_pca_dec_init_fx( hSpar->hPCA ); } +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#else ivas_spar_config( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#endif } ELSE { diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 007074796..37bcdbea0 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -414,7 +414,11 @@ ivas_error ivas_spar_dec_open_fx( * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#else ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#endif SWITCH( sba_order_internal ) { diff --git a/lib_enc/ivas_mct_core_enc.c b/lib_enc/ivas_mct_core_enc.c index cc18b15cf..6482d11de 100644 --- a/lib_enc/ivas_mct_core_enc.c +++ b/lib_enc/ivas_mct_core_enc.c @@ -112,7 +112,11 @@ static void AdjustChannelRatios( float cur_ratio, tar_ratio, sum_ratio, sum_tar_ratio; int16_t ratio_diff, i; +#ifdef IVAS_FLOAT_FIXED + ivas_spar_bitrate_dist_fx( temp_brs, nAvailBits, ivas_total_brate, sba_order, (Word16) FB ); +#else ivas_spar_bitrate_dist( temp_brs, nAvailBits, ivas_total_brate, sba_order, (int16_t) FB ); +#endif sum_ratio = 0.0f; for ( i = 0; i < nChannels; i++ ) diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index 8e65a938f..b170b0066 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -354,7 +354,11 @@ ivas_error ivas_osba_enc_reconfig( } } +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#else ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#endif hSpar = st_ivas->hSpar; diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 5d77849e8..21953637e 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -258,7 +258,11 @@ ivas_error ivas_sba_enc_reconfigure( } } +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#else ivas_spar_config( ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, -1 ); +#endif hSpar = st_ivas->hSpar; diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 29ec47922..1b5b215f7 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -214,7 +214,11 @@ ivas_error ivas_spar_enc_open( * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#else ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#endif if ( st_ivas->nchan_transport == 1 ) { @@ -404,7 +408,11 @@ ivas_error ivas_spar_enc_open_fx( * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED + ivas_spar_config_fx( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#else ivas_spar_config( hEncoderConfig->ivas_total_brate, min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#endif IF( EQ_16( st_ivas->nchan_transport, 1 ) ) { diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 88dc5ffc8..8b896e397 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -688,7 +688,11 @@ ivas_error ivas_spar_md_enc_process( active_w = ( hMdEnc->spar_md_cfg.active_w == 1 ) || ( dyn_active_w_flag == 1 ); nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; +#ifdef IVAS_FLOAT_FIXED + bwidth = ivas_get_bw_idx_from_sample_rate_fx( hEncoderConfig->input_Fs ); +#else bwidth = ivas_get_bw_idx_from_sample_rate( hEncoderConfig->input_Fs ); +#endif bwidth = min( bwidth, hEncoderConfig->max_bwidth ); int16_t active_w_vlbr; active_w_vlbr = ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) ? 1 : 0; -- GitLab