diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 236d608590bf4d998dfe873f2bdd8eee81ce3fc9..a79d0594536c55d668762cb9f0f7a0919138ee42 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -544,7 +544,7 @@ static void ivas_get_pred_coeffs_enc_fx( Word16 i, j, k, b; Word32 abs_value; Word32 w_norm_fac; - Word32 one_in_q, L_tmp; + Word32 L_tmp; Word16 q_tmp, e_tmp; Word64 abs_value64, tmp64; Word16 q_ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -628,35 +628,29 @@ static void ivas_get_pred_coeffs_enc_fx( e_tmp = sub( 31, sub( add( q_pPred_temp[k], tmp_shift ), 32 ) ); L_tmp = Sqrt32( W_extract_h( W_shl( pPred_temp[k], tmp_shift ) ), &e_tmp ); // Q=31-e_tmp - one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); // 1 in Q(31-e_tmp) - - IF( LT_32( one_in_q, L_tmp ) ) + IF( BASOP_Util_Cmp_Mant32Exp( L_tmp, e_tmp, ONE_IN_Q31, 0 ) <= 0 ) { - div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); // Q=15-s_div - move16(); - div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 - move16(); - div_factor_e[k] = 0; - move16(); - } - ELSE - { - div_factor[k] = ONE_IN_Q15 - 1; /*1 in Q15*/ - move16(); - div_factor_e[k] = 0; + L_tmp = ONE_IN_Q31; + move32(); + e_tmp = 0; move16(); } + + div_factor[k] = BASOP_Util_Divide3232_Scale( 1, L_tmp, &s_div ); // exp(0-e_tmp+s_div) + move16(); + div_factor[k] = shl( div_factor[k], sub( add( s_div, 30 ), e_tmp ) ); // Q = Q14 + move16(); } - tmp_shift = 31; + tmp_shift = Q30; // To avoid saturation for Q31 move16(); FOR( i = 0; i < pred_dim; i++ ) { FOR( k = start_band; k < end_band; k++ ) { - IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 /*1 in Q15*/ ) ) + IF( NE_16( div_factor[k], ONE_IN_Q14 /*1 in Q14*/ ) ) { - ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] + ppPred_coeffs_re[i][k] = L_shl( Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ), 1 ); // Q = q_ppPred_coeffs_re[i][k] move32(); } ppDM_Fv_re[i][k] = 0; @@ -678,7 +672,7 @@ static void ivas_get_pred_coeffs_enc_fx( } *q_pred_coeffs = tmp_shift; move16(); - *q_dm_fv_re = 31; + *q_dm_fv_re = 30; // To avoid saturation in Q31 move16(); } ELSE @@ -1152,9 +1146,9 @@ static void ivas_get_pred_coeffs_enc_fx( } } - *q_pred_coeffs = 31; + *q_pred_coeffs = 30; // To avoid saturation in Q31 move16(); - *q_dm_fv_re = 31; + *q_dm_fv_re = 30; // To avoid saturation in Q31 move16(); FOR( i = 0; i < pred_dim; i++ ) @@ -1987,11 +1981,11 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re + tmp_p2_re[j][j][b] = L_shl( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re move32(); - max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); // q=q_pred_coeffs_re } } + max_val_tmp_p2 = L_shl( 1, q_pred_coeffs_re ); // q=q_pred_coeffs_re FOR( j = 1; j < in_chans; j++ ) { @@ -2015,11 +2009,11 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p1_re[j][j][b] = L_shl_sat( 1, q_dm_fv_re ); // q=q_dm_fv_re + tmp_p1_re[j][j][b] = L_shl( 1, q_dm_fv_re ); // q=q_dm_fv_re move32(); - max_val = L_max( max_val, L_abs( tmp_p1_re[j][j][b] ) ); // q=q_dm_fv_re } } + max_val = L_shl( 1, q_dm_fv_re ); // q=q_dm_fv_re FOR( j = 1; j < in_chans; j++ ) { @@ -5055,7 +5049,7 @@ void ivas_get_spar_md_from_dirac_fx( { Word32 en_ratio_fac_sq = 0; 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] ); // q30 + cov_real_dirac_fx[i][j][band] = Mpy_32_32( L_shl( Mpy_32_32( en_ratio_fac_fx, response_avg_fx[i] ), 1 ), response_avg_fx[j] ); // q30 move32(); IF( LE_16( hSpar_md_cfg->nchan_transport, 2 ) ) @@ -5804,7 +5798,7 @@ Word32 local_result_table[91][9] /*q30*/ = { 284546880, }, { - -1073741824, + -1073741823, 759250176, 379625056, -929887680, @@ -6300,7 +6294,7 @@ Word32 local_result_table[91][9] /*q30*/ = { }, { -66, - 1073741824, + 1073741823, -759250112, -81, 929887872, @@ -6313,12 +6307,12 @@ Word32 local_result_table[91][9] /*q30*/ = { Word32 local_result_table_2[91][9] /*q30*/ = { { - -1073741824, + -1073741823, 0, - 1073741824, + 1073741823, 0, 0, - -1073741824, + -1073741823, 0, 0, 0, @@ -7376,28 +7370,25 @@ void ivas_dirac_dec_get_response_fx( f_fx = 1; move16(); } - cos_1_fx = dirac_gains_trg_term_fx[az][0]; // q31 - move32(); - cos_2_fx = Mpy_32_32( cos_1_fx, cos_1_fx ); // q31 - sin_1_fx = dirac_gains_trg_term_fx[az][1]; // q31 - move32(); + cos_1_fx = L_shr( dirac_gains_trg_term_fx[az][0], 1 ); // q30 + cos_2_fx = L_shl( Mpy_32_32( cos_1_fx, cos_1_fx ), 1 ); // q30 + sin_1_fx = L_shr( dirac_gains_trg_term_fx[az][1], 1 ); // q30 if ( EQ_32( f_fx, -1 ) ) { - sin_1_fx = L_negate( sin_1_fx ); // q31 - move32(); + sin_1_fx = L_negate( sin_1_fx ); // q30 } - cos_az_fx[0] = cos_1_fx; // q31 + cos_az_fx[0] = cos_1_fx; // q30 move32(); - cos_az_fx[1] = L_shl_sat( L_sub( cos_2_fx, ONE_IN_Q30 /*0.5 q31*/ ), 1 ); /*q31*/ + cos_az_fx[1] = L_shl( L_sub( cos_2_fx, ONE_IN_Q29 /*0.5 q30*/ ), 1 ); /*q30*/ 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 ) /* cos_az_fx[0]/2 q31*/ ), 1 ); /*q31*/ + cos_az_fx[2] = L_sub( L_shl( Mpy_32_32( cos_1_fx, cos_az_fx[1] ), 2 ), cos_az_fx[0] /* cos_az_fx[0] q30*/ ); /*q30*/ move32(); - sin_az_fx[0] = sin_1_fx; /*q31*/ + sin_az_fx[0] = sin_1_fx; /*q30*/ move32(); - sin_az_fx[1] = L_shl_sat( Mpy_32_32( sin_1_fx, cos_1_fx ), 1 ); /*q31*/ + sin_az_fx[1] = L_shl( Mpy_32_32( sin_1_fx, cos_1_fx ), 2 ); /*q30*/ move32(); - sin_az_fx[2] = L_shl_sat( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q29 /*1/4 q31*/ ) ), 2 ); /*q31*/ + sin_az_fx[2] = L_shl( Mpy_32_32( sin_1_fx, L_sub( cos_2_fx, ONE_IN_Q28 /*1/4 q30*/ ) ), 3 ); /*q30*/ move32(); response_fx[0] = L_shl_sat( 1, Q_out ); // Q_out @@ -7414,11 +7405,11 @@ void ivas_dirac_dec_get_response_fx( move16(); c_fx_better = local_result_table[el][a]; // q30 move32(); - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - 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[b1] = L_shl( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); } @@ -7433,10 +7424,10 @@ void ivas_dirac_dec_get_response_fx( { c_fx_better = L_negate( c_fx_better ); // q30 } - response_fx[b] = L_shl_sat( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl( Mpy_32_32( c_fx_better, sin_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); b1 = sub( b1_2, m ); - 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[b1] = L_shl( Mpy_32_32( c_fx_better, cos_az_fx[l - m - 1] ), sub( Q_out, 29 ) ); // Q_out move32(); } @@ -7453,7 +7444,7 @@ void ivas_dirac_dec_get_response_fx( move32(); } } - response_fx[b] = L_shl_sat( c_fx_better, sub( Q_out, 30 ) ); // Q_out + response_fx[b] = L_shl( c_fx_better, sub( Q_out, 30 ) ); // Q_out move32(); } diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 1e867d4dbda9aa38b500d26e4f49f8b606adf687..a492fcf6512449898abab1b5f66a7f180949410d 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -684,14 +684,14 @@ static void ps_pred_process_sf( vsim_fx = qmf_side_im_fx[ismp][iqmf]; // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6 - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); // Q6 - qmf_side_re_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); // Q6 + res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); // Q6 + qmf_side_re_fx[ismp][iqmf] = L_add( res_a, res_b ); // Q6 move32(); - res_a = L_shl_sat( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6 - res_b = L_shl_sat( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); // Q6 - qmf_side_im_fx[ismp][iqmf] = L_add_sat( res_a, res_b ); + res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6 + res_b = L_shl( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); // Q6 + qmf_side_im_fx[ismp][iqmf] = L_add( res_a, res_b ); move32(); ismp = add( ismp, 1 ); @@ -778,10 +778,10 @@ static void ivas_mc_paramupmix_dec_sf( move32(); move32(); - Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add_sat( qlim_fx, qrim_fx ); - Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlre_fx, qrre_fx ); - Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub_sat( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add( qlim_fx, qrim_fx ); + Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlre_fx, qrre_fx ); + Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlim_fx, qrim_fx ); move32(); move32(); move32(); diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index ccf81a09d724cfaaa8578b4809793662e5bade04..1867e4263c838d343c37f1db4fbf00f2ea75411b 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -181,12 +181,12 @@ void ivas_sba_prototype_renderer_fx( FOR( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ ) { /* accumulate contributions from all SPAR bands */ - cldfb_par_fx = L_add_sat( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // hMdDec->Q_mixer_matrix + cldfb_par_fx = L_add( cldfb_par_fx, Mpy_32_32( mixer_mat_fx[out_ch][in_ch][spar_band], bin2band->pp_cldfb_weights_per_spar_band_fx[cldfb_band][spar_band] ) ); // hMdDec->Q_mixer_matrix } } - out_re_fx[out_ch] = L_add_sat( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 - out_im_fx[out_ch] = L_add_sat( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 + out_re_fx[out_ch] = L_add( out_re_fx[out_ch], Mpy_32_32( inRe_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 + out_im_fx[out_ch] = L_add( out_im_fx[out_ch], Mpy_32_32( inIm_fx[in_ch][ts][cldfb_band], cldfb_par_fx ) ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 move32(); move32(); } @@ -195,8 +195,8 @@ void ivas_sba_prototype_renderer_fx( /*update CLDFB data with the parameter-modified data*/ FOR( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { - inRe_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_re_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer - inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer + inRe_fx[out_ch][ts][cldfb_band] = L_shl( out_re_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer + inIm_fx[out_ch][ts][cldfb_band] = L_shl( out_im_fx[out_ch], 1 ); // hMdDec->Q_mixer_matrix+q_cldfb[i][j] -31 +1; + q1 //to keep constat q to entire buffer move32(); move32(); } @@ -228,7 +228,7 @@ void ivas_sba_prototype_renderer_fx( { FOR( b = 0; b < num_spar_bands; b++ ) { - hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][add( b, imult1616( md_sf, IVAS_MAX_NUM_BANDS ) )]; + hSpar->hMdDec->mixer_mat_prev_fx[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat_fx[out_ch][in_ch][b + ( md_sf * IVAS_MAX_NUM_BANDS )]; move32(); } }