From 490a54a57f7efd7c4cab1b37ecb08eefbe2d8ad1 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 22:07:35 +0530 Subject: [PATCH 1/2] Q-info updates, MSAN error fixes --- lib_com/ivas_prot_fx.h | 36 + lib_com/ivas_spar_com.c | 2495 ++++++++++++++++++++---- lib_com/prot_fx.h | 106 +- lib_com/rom_com.c | 4 +- lib_com/rom_com.h | 4 +- lib_dec/d_gain2p.c | 14 +- lib_dec/d_gain2p_fx.c | 29 +- lib_dec/dec4t64.c | 31 +- lib_dec/dec4t64_fx.c | 22 +- lib_dec/dec_LPD_fx.c | 54 +- lib_dec/dec_ace_fx.c | 107 +- lib_dec/dec_acelp_fx.c | 30 +- lib_dec/dec_acelp_tcx_main_fx.c | 43 +- lib_dec/dec_amr_wb_fx.c | 24 +- lib_dec/dec_gen_voic_fx.c | 238 +-- lib_dec/dec_higher_acelp_fx.c | 31 +- lib_dec/dec_tcx.c | 96 +- lib_dec/dec_tran_fx.c | 28 +- lib_dec/dec_uv_fx.c | 8 +- lib_dec/dlpc_avq_fx.c | 9 +- lib_dec/igf_dec_fx.c | 348 ++-- lib_dec/igf_scf_dec_fx.c | 50 +- lib_dec/init_dec_fx.c | 106 +- lib_dec/inov_dec_fx.c | 57 +- lib_dec/ivas_mono_dmx_renderer.c | 20 +- lib_dec/ivas_objectRenderer_internal.c | 14 +- lib_dec/ivas_omasa_dec.c | 42 +- lib_dec/ivas_osba_dec.c | 8 +- lib_dec/ivas_out_setup_conversion.c | 101 +- lib_dec/ivas_qmetadata_dec.c | 1059 +++++----- lib_dec/ivas_spar_md_dec.c | 702 +++---- lib_dec/ivas_stat_dec.h | 22 +- lib_dec/peak_vq_dec_fx.c | 25 +- lib_dec/pit_dec_fx.c | 58 +- lib_dec/pitch_extr_fx.c | 8 +- lib_dec/post_dec_fx.c | 73 +- lib_dec/ppp_dec_fx.c | 20 +- lib_dec/pvq_core_dec_fx.c | 40 +- lib_dec/pvq_decode_fx.c | 4 + lib_dec/range_dec_fx.c | 24 +- lib_dec/rom_dec.c | 34 +- lib_dec/rom_dec.h | 59 +- lib_dec/rst_dec_fx.c | 10 +- lib_dec/stat_dec.h | 740 +++---- lib_dec/stat_noise_uv_dec_fx.c | 12 +- lib_enc/acelp_core_enc.c | 4 +- lib_enc/ivas_core_enc.c | 9 +- lib_enc/ivas_core_pre_proc_front.c | 12 + lib_enc/ivas_cpe_enc.c | 3 + lib_enc/ivas_spar_encoder.c | 6 +- lib_enc/ivas_spar_md_enc.c | 78 +- lib_rend/ivas_efap.c | 4 + lib_rend/ivas_objectRenderer_vec.c | 46 +- lib_rend/ivas_omasa_ana.c | 106 +- lib_rend/ivas_orient_trk.c | 66 +- lib_rend/ivas_prot_rend.h | 32 +- lib_rend/ivas_rom_rend.c | 2 +- lib_rend/ivas_rom_rend.h | 72 +- lib_rend/ivas_rotation.c | 216 +- lib_rend/ivas_sba_rendering.c | 32 +- 60 files changed, 4913 insertions(+), 2820 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 513f686a7..07f548f32 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -692,6 +692,28 @@ Word16 masa_sq_fx( const Word16 cb_sz /* i : codebook size */ ); +void ivas_compute_spar_params_enc_fx( + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale, + Word16 *q_Wscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ); + void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1998,6 +2020,20 @@ Word16 set_ACELP_flag_IVAS( const Word16 cng_type /* i : CNG type */ ); +void ivas_calc_c_p_coeffs_enc_fx( + ivas_spar_md_t *pSparMd, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad, + const Word16 compute_p_flag, + const Word16 dyn_active_w_flag ); + void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 31e787a78..1cea89b76 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -87,6 +87,51 @@ *------------------------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED +static void ivas_get_pred_coeffs_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_pred_coeffs, + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + const Word16 active_w_vlbr, + const Word16 dtx_vad, + const Word16 from_dirac, + const Word16 dyn_active_w_flag, + const Word16 res_ind ); + +static void ivas_get_Wscaling_factor_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 *pNum_dmx, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + Word32 *pWscale, + Word16 *q_pWscale, + const Word16 dyn_active_w_flag ); + +static void ivas_calc_post_pred_per_band_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 band_idx, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_postpred_cov_re ); static void ivas_get_pred_coeffs_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -696,10 +741,13 @@ static void ivas_get_pred_coeffs( * Calculation of prediction coefficients *-----------------------------------------------------------------------------------------*/ -static void ivas_get_pred_coeffs_fx( +static void ivas_get_pred_coeffs_enc_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_pred_coeffs, Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, const Word16 in_chans, const Word16 start_band, const Word16 end_band, @@ -708,203 +756,166 @@ static void ivas_get_pred_coeffs_fx( const Word16 dtx_vad, const Word16 from_dirac, const Word16 dyn_active_w_flag, - const Word16 res_ind, - Word16 *q_pred_coeffs, - Word16 *q_dm_fv_re ) + const Word16 res_ind ) { - Word16 i, j, k, b, p; + Word16 i, j, k, b; Word32 abs_value; Word32 w_norm_fac; - Word32 one_in_q; - Word32 div_factor[IVAS_MAX_NUM_BANDS]; + Word32 one_in_q, 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]; + Word16 div_factor[IVAS_MAX_NUM_BANDS]; + Word16 div_factor_e[IVAS_MAX_NUM_BANDS]; Word16 pred_dim = sub( in_chans, 1 ); - Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; + Word16 tmp_shift, s_div, div_shift; IF( EQ_16( from_dirac, 1 ) ) { - w_norm_fac = ONE_IN_Q29; + w_norm_fac = 1; move32(); } ELSE { - w_norm_fac = 3 * ONE_IN_Q29; + w_norm_fac = 3; move32(); } - tmp_shift = Q30; - move16(); + IF( active_w == 0 ) { - Word32 pPred_temp[IVAS_MAX_NUM_BANDS]; - Word16 q_pred_temp; - prev_tmp_shift = 31; - move16(); + Word64 pPred_temp[IVAS_MAX_NUM_BANDS]; + Word16 q_pPred_temp[IVAS_MAX_NUM_BANDS]; - set32_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + set64_fx( pPred_temp, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( q_pPred_temp, 31, 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; + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( 1, cov_real[0][0][k] ), &s_div ); move16(); - IF( NE_32( cov_real[0][0][k], ONE_IN_Q30 ) ) + + div_factor_e[k] = sub( add( s_div, q_cov_real[0][0][k] ), 31 ); + move16(); + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) { - div_factor[k] = L_deposit_l( BASOP_Util_Divide3232_Scale( ONE_IN_Q31, div_factor[k], &s_div ) ); - move32(); - IF( s_div < 0 ) + tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 != 0 ) { - div_shift = add( 15, s_div ); - tmp_shift = Q30; + ppPred_coeffs_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 + move32(); + q_ppPred_coeffs_re[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); move16(); } ELSE { - div_shift = 15; + ppPred_coeffs_re[i][k] = 0; + move32(); + q_ppPred_coeffs_re[i][k] = 31; 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 ) ) + // 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*q_ppPred_coeffs_re[i][k] - 31 + q_tmp = sub( shl( q_ppPred_coeffs_re[i][k], 1 ), 31 ); + + IF( GE_16( q_tmp, q_pPred_temp[k] ) ) { - FOR( p = start_band; p < k; p++ ) - { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); - } - prev_tmp_shift = tmp_shift; - move16(); + abs_value = L_shr( abs_value, sub( q_tmp, q_pPred_temp[k] ) ); } - ELSE IF( GT_16( tmp_shift, prev_tmp_shift ) ) + ELSE { - div_factor[k] = L_shr( div_factor[k], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; + pPred_temp[k] = W_shr( pPred_temp[k], sub( q_pPred_temp[k], q_tmp ) ); + move64(); + q_pPred_temp[k] = q_tmp; move16(); } - } - } - - FOR( i = 0; i < pred_dim; i++ ) - { - FOR( k = start_band; k < end_band; k++ ) - { - 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(); + pPred_temp[k] = W_add( pPred_temp[k], abs_value ); // Q = q_pPred_temp[k] + move64(); } } - *q_pred_coeffs = sub( tmp_shift, 1 ); - move16(); FOR( k = start_band; k < end_band; k++ ) { - q_pred_temp = sub( 31, sub( shl( *q_pred_coeffs, 1 ), 31 ) ); - pPred_temp[k] = Sqrt32( pPred_temp[k], &q_pred_temp ); - move32(); + tmp_shift = W_norm( pPred_temp[k] ); + 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 ); - IF( LT_16( q_pred_temp, 1 ) ) + one_in_q = L_shl_sat( 1, sub( 31, e_tmp ) ); + + IF( LT_32( one_in_q, L_tmp ) ) { - pPred_temp[k] = L_shr( pPred_temp[k], add( abs_s( q_pred_temp ), 1 ) ); // Q30 - move32(); - q_pred_temp = 1; + div_factor[k] = BASOP_Util_Divide3232_Scale( one_in_q, L_tmp, &s_div ); + move16(); + div_factor[k] = shl_sat( div_factor[k], s_div ); // Q = Q15 + move16(); + div_factor_e[k] = 0; move16(); } - ELSE IF( GT_16( q_pred_temp, 1 ) ) + ELSE { - pPred_temp[k] = L_shl( pPred_temp[k], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 - move32(); - q_pred_temp = 1; + div_factor[k] = ONE_IN_Q15 - 1; + move16(); + div_factor_e[k] = 0; move16(); } + } - one_in_q = L_shl( 1, sub( 31, q_pred_temp ) ); - - IF( LT_32( one_in_q, pPred_temp[k] ) ) + tmp_shift = 31; + move16(); + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; 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 ) ); - move32(); - IF( s_div < 0 ) - { - div_shift = add( 15, s_div ); - tmp_shift = Q30; - move16(); - } - ELSE + IF( NE_16( div_factor[k], ONE_IN_Q15 - 1 ) ) { - div_shift = 15; - move16(); - tmp_shift = sub( Q30, s_div ); + ppPred_coeffs_re[i][k] = Mpy_32_16_1( ppPred_coeffs_re[i][k], div_factor[k] ); // Q = q_ppPred_coeffs_re[i][k] + move32(); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift - move32(); - } - ELSE - { - div_factor[k] = one_in_q; + ppDM_Fv_re[i][k] = 0; move32(); - tmp_shift = sub( 31, q_pred_temp ); - } - IF( LT_16( tmp_shift, prev_tmp_shift ) ) - { - FOR( p = start_band; p < k; p++ ) + IF( ppPred_coeffs_re[i][k] != 0 ) { - div_factor[p] = L_shr( div_factor[p], sub( prev_tmp_shift, tmp_shift ) ); - move32(); + tmp_shift = s_min( tmp_shift, add( norm_l( ppPred_coeffs_re[i][k] ), q_ppPred_coeffs_re[i][k] ) ); } - prev_tmp_shift = tmp_shift; - move16(); - } - ELSE IF( GT_16( 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(); } } - FOR( i = 0; i < pred_dim; i++ ) { 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; + ppPred_coeffs_re[i][k] = L_shr( ppPred_coeffs_re[i][k], sub( q_ppPred_coeffs_re[i][k], tmp_shift ) ); move32(); } } - *q_pred_coeffs = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); - *q_dm_fv_re = 0; + *q_pred_coeffs = tmp_shift; + move16(); + *q_dm_fv_re = 31; move16(); } ELSE { + Word64 dm_alpha64[IVAS_MAX_NUM_BANDS]; + Word64 real64[IVAS_SPAR_MAX_CH - 1]; + Word64 re, dm_y; + Word16 dm_beta_re_q; + Word16 dm_alpha64_q[IVAS_MAX_NUM_BANDS]; + Word16 dm_v_re_q[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word32 dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - Word32 real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; - Word32 dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; - Word32 num_f, den_f, passive_g /*, inv_den_f*/; + Word32 dm_g[IVAS_MAX_NUM_BANDS]; + Word16 real64_q[IVAS_SPAR_MAX_CH - 1]; + Word32 dm_f_local, dm_w, DM_F[IVAS_MAX_NUM_BANDS]; + Word16 DM_F_q[IVAS_MAX_NUM_BANDS], dm_g_q[IVAS_MAX_NUM_BANDS]; + Word32 num_f, den_f, passive_g, dm_beta_re /*, inv_den_f*/; Word32 activew_quad_thresh, g_th_sq; Word32 L_tmp1, L_tmp2; - Word16 L_tmp2_q; - Word16 dm_alpha_e, den_f_e, s_dm_f; - prev_tmp_shift = 31; - dm_alpha_e = 0; - Word16 dm_beta_re_e = 0; - move32(); - move16(); - move16(); - move16(); - + Word16 L_tmp1_q, L_tmp2_q; + Word16 den_f_e, s_dm_f; IF( EQ_16( dyn_active_w_flag, 1 ) ) { @@ -919,72 +930,91 @@ static void ivas_get_pred_coeffs_fx( g_th_sq = Mpy_32_32( activew_quad_thresh, activew_quad_thresh ); // Q27 set32_fx( dm_alpha, 0, IVAS_MAX_NUM_BANDS ); + set64_fx( dm_alpha64, 0, IVAS_MAX_NUM_BANDS ); + set16_fx( dm_alpha64_q, 31, IVAS_MAX_NUM_BANDS ); FOR( i = 1; i < in_chans; i++ ) { FOR( k = start_band; k < end_band; k++ ) { // 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(); + abs_value64 = W_mult0_32_32( cov_real[i][0][k], cov_real[i][0][k] ); // Q = 2 * q_cov_real[i][0][k] + tmp_shift = W_norm( abs_value64 ); + IF( abs_value64 != 0 ) + { + q_tmp = sub( add( shl( q_cov_real[i][0][k], 1 ), tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + IF( LT_16( q_tmp, dm_alpha64_q[k] ) ) + { + dm_alpha64[k] = W_add( W_shr( dm_alpha64[k], sub( dm_alpha64_q[k], q_tmp ) ), W_extract_h( W_shl( abs_value64, tmp_shift ) ) ); + move64(); + dm_alpha64_q[k] = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_alpha64_q[k] ); + IF( LT_16( tmp_shift, 63 ) ) + { + dm_alpha64[k] = W_add( dm_alpha64[k], W_shr( abs_value64, tmp_shift ) ); + move64(); + } + } } } FOR( k = start_band; k < end_band; k++ ) { - dm_alpha_e = 31 - Q29; - dm_alpha[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); - move32(); - - 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 ) ); - move32(); - IF( s_div < 0 ) + tmp_shift = W_norm( dm_alpha64[k] ); + IF( dm_alpha64[k] != 0 ) { - div_shift = add( 15, sub( s_div, dm_alpha_e ) ); - tmp_shift = Q30; - move16(); + e_tmp = sub( 31, sub( add( dm_alpha64_q[k], tmp_shift ), 32 ) ); } ELSE { - div_shift = 15; + e_tmp = 0; move16(); - tmp_shift = sub( Q30, sub( s_div, dm_alpha_e ) ); } - div_factor[k] = L_shl( div_factor[k], div_shift ); // Q = tmp_shift + dm_alpha[k] = Sqrt32( W_extract_h( W_shl( dm_alpha64[k], tmp_shift ) ), &e_tmp ); move32(); + dm_alpha64_q[k] = sub( 31, e_tmp ); + move16(); - IF( LT_16( tmp_shift, prev_tmp_shift ) ) - { - FOR( p = start_band; p < k; p++ ) - { - 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], sub( tmp_shift, prev_tmp_shift ) ); - move32(); - tmp_shift = prev_tmp_shift; - move16(); - } + div_factor[k] = BASOP_Util_Divide3232_Scale( ONE_IN_Q31, L_max( dm_alpha[k], 1 ), &s_div ); + move16(); + + div_factor_e[k] = sub( add( dm_alpha64_q[k], s_div ), 31 ); + move16(); } FOR( i = 0; i < pred_dim; i++ ) { 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(); - } - } - + tmp64 = W_mult_32_16( cov_real[add( i, 1 )][0][k], div_factor[k] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 != 0 ) + { + dm_v_re[i][k] = W_extract_h( W_shl( tmp64, tmp_shift ) ); // 1 + q_cov_real[i+1][0][k] + tmp_shift + 15 - div_factor_e[k] - 32 + move32(); + dm_v_re_q[i][k] = add( sub( add( q_cov_real[add( i, 1 )][0][k], tmp_shift ), div_factor_e[k] ), 1 + 15 - 32 ); + move16(); + } + ELSE + { + dm_v_re[i][k] = 0; + move32(); + dm_v_re_q[i][k] = 31; + move16(); + } + } + } + IF( dtx_vad == 0 ) { dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; @@ -1006,60 +1036,121 @@ static void ivas_get_pred_coeffs_fx( FOR( b = start_band; b < end_band; b++ ) { - set32_fx( real, 0, pred_dim ); + set64_fx( real64, 0, pred_dim ); + set16_fx( real64_q, 31, pred_dim ); FOR( j = 0; j < pred_dim; j++ ) { FOR( k = 1; k < in_chans; k++ ) { - Word32 re; - // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); - 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(); + re = W_mult0_32_32( cov_real[add( j, 1 )][k][b], dm_v_re[sub( k, 1 )][b] ); + tmp_shift = W_norm( re ); + IF( re != 0 ) + { + q_tmp = sub( add( add( q_cov_real[add( j, 1 )][k][b], dm_v_re_q[sub( k, 1 )][b] ), tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, real64_q[j] ) ) + { + real64[j] = W_add( W_shr( real64[j], sub( real64_q[j], q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + move64(); + real64_q[j] = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), real64_q[j] ); + IF( LT_16( tmp_shift, 63 ) ) + { + real64[j] = W_add( real64[j], W_shr( re, tmp_shift ) ); + move64(); + } + } } } - dm_beta_re = 0; - move32(); + + tmp64 = 0; + move64(); + dm_beta_re_q = 31; + move16(); FOR( k = 0; k < pred_dim; k++ ) { - Word32 re; // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); - re = Mpy_32_32( real[k], dm_v_re[k][b] ); // Q = 2*tmp_shift - 3 - 31 - dm_beta_re = L_add( dm_beta_re, re ); // Q = 2*tmp_shift - 3 - 31 + tmp_shift = W_norm( real64[k] ); + re = W_mult0_32_32( W_extract_h( W_shl( real64[k], tmp_shift ) ), dm_v_re[k][b] ); + q_tmp = sub( add( add( real64_q[k], dm_v_re_q[k][b] ), tmp_shift ), 32 ); + tmp_shift = W_norm( re ); + IF( re != 0 ) + { + q_tmp = sub( add( q_tmp, tmp_shift ), 32 ); + } + ELSE + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, dm_beta_re_q ) ) + { + tmp64 = W_add( W_shr( tmp64, sub( dm_beta_re_q, q_tmp ) ), W_extract_h( W_shl( re, tmp_shift ) ) ); + dm_beta_re_q = q_tmp; + move16(); + } + ELSE + { + tmp_shift = sub( add( q_tmp, sub( 32, tmp_shift ) ), dm_beta_re_q ); + IF( LT_16( tmp_shift, 63 ) ) + { + tmp64 = W_add( tmp64, W_shr( re, tmp_shift ) ); + } + } + } + tmp_shift = W_norm( tmp64 ); + dm_beta_re = W_extract_h( W_shl( tmp64, tmp_shift ) ); + IF( tmp64 != 0 ) + { + dm_beta_re_q = sub( add( dm_beta_re_q, tmp_shift ), 32 ); + } + ELSE + { + dm_beta_re_q = 31; + move16(); } - dm_beta_re_e = sub( 31, ( sub( sub( shl( tmp_shift, 1 ), 3 ), 31 ) ) ); - dm_w = cov_real[0][0][b]; // Q30 + dm_w = cov_real[0][0][b]; // q_cov_real[0][0][b] move32(); den_f = L_max( dm_w, 1 ); - passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); + passive_g = L_deposit_l( BASOP_Util_Divide3232_Scale( dm_alpha[b], den_f, &s_div ) ); // dm_alpha64_q[b] - q_cov_real[0][0][b] + 15 - s_div - 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 + div_shift = sub( Q29, add( sub( dm_alpha64_q[b], q_cov_real[0][0][b] ), sub( 15, s_div ) ) ); + passive_g = L_shl_sat( passive_g, div_shift ); // Q = 29 IF( EQ_16( dyn_active_w_flag, 1 ) ) { dm_alpha[b] = 0; move32(); + dm_alpha64_q[b] = 0; + move16(); dm_w = 0; move32(); FOR( i = 0; i < pred_dim; i++ ) { dm_v_re[i][b] = 0; move32(); + dm_v_re_q[i][b] = 31; + move16(); } - IF( NE_16( sub( tmp_shift, 1 ), 31 ) ) - { - dm_v_re[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); - move32(); - } - ELSE - { - dm_v_re[sub( res_ind, 1 )][b] = MAX_32; - move32(); - } + dm_v_re[sub( res_ind, 1 )][b] = MAX_32; + move32(); + dm_v_re_q[i][b] = 31; + move16(); + passive_g = activew_quad_thresh; move32(); } @@ -1069,46 +1160,168 @@ static void ivas_get_pred_coeffs_fx( /*linear activeW*/ dm_y = 0; move32(); + q_tmp = 31; + move16(); FOR( k = 1; k < in_chans; k++ ) { - dm_y = L_add( dm_y, L_shr( cov_real[k][k][b], 2 ) ); // Q28 + IF( GT_16( q_tmp, q_cov_real[k][k][b] ) ) + { + dm_y = W_add( W_shr( dm_y, sub( q_tmp, q_cov_real[k][k][b] ) ), cov_real[k][k][b] ); + q_tmp = q_cov_real[k][k][b]; + move16(); + } + ELSE + { + dm_y = W_add( dm_y, L_shr( cov_real[k][k][b], sub( q_cov_real[k][k][b], q_tmp ) ) ); + } + } + tmp64 = W_mult0_32_32( w_norm_fac, dm_w ); + IF( LT_16( q_tmp, q_cov_real[0][0][b] ) ) + { + tmp64 = W_shr( tmp64, sub( q_cov_real[0][0][b], q_tmp ) ); + } + ELSE + { + q_tmp = q_cov_real[0][0][b]; + move16(); + dm_y = W_shr( dm_y, sub( q_tmp, q_cov_real[0][0][b] ) ); } - den_f = L_max( dm_y, 1 ); // Q28 - 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(); + if ( GT_64( tmp64, dm_y ) ) + { + dm_y = tmp64; + move16(); + } - div_shift = add( ( sub( 15, ( sub( ( sub( 30, dm_alpha_e ) ), 28 ) ) ) ), s_div ); + tmp_shift = W_norm( dm_y ); + IF( dm_y == 0 ) + { + tmp_shift = 32; + move16(); + den_f = W_extract_l( dm_y ); + } + ELSE + { + den_f = W_extract_h( W_shl( dm_y, tmp_shift ) ); // q_tmp + tmp_shift - 32 + } - DM_F[b] = L_shl( DM_F[b], div_shift ); // Q30 - move32(); + den_f = L_max( den_f, 1 ); - DM_F[b] = L_min( ONE_IN_Q30, DM_F[b] ); + DM_F[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( Mpy_32_32( dm_f_local, dm_alpha[b] ), den_f, &s_div ) ); // Q30 + dm_alpha64_q[b] - 31 - q_tmp - tmp_shift + 32 + 15 - s_div 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 = 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 ) ); + DM_F_q[b] = add( sub( sub( dm_alpha64_q[b], add( q_tmp, tmp_shift ) ), s_div ), ( 30 - 31 + 32 + 15 ) ); + move16(); + + IF( LT_32( ONE_IN_Q30, L_shl_sat( DM_F[b], sub( Q30, DM_F_q[b] ) ) ) ) + { + DM_F[b] = ONE_IN_Q31; + move32(); + DM_F_q[b] = Q31; + move16(); + } + + tmp64 = W_mult0_32_32( DM_F[b], DM_F[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + tmp64 = W_mult0_32_32( W_extract_h( tmp64 ), dm_beta_re ); // 2 * DM_F_q[b] + tmp_shift - 32 + dm_beta_re_q + q_tmp = sub( add( add( shl( DM_F_q[b], 1 ), tmp_shift ), dm_beta_re_q ), 32 ); + tmp_shift = sub( W_norm( tmp64 ), 2 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp2 = W_extract_h( tmp64 ); + L_tmp2_q = sub( add( q_tmp, tmp_shift ), 32 ); + + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], DM_F[b] ), 1 ); + tmp_shift = sub( W_norm( tmp64 ), 2 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); + + IF( LT_16( L_tmp2_q, L_tmp1_q ) ) + { + L_tmp1 = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + L_tmp1_q = L_tmp2_q; + move16(); + } + ELSE + { + L_tmp1 = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + } + + tmp_shift = sub( norm_l( dm_w ), 1 ); + L_tmp2 = L_shl( dm_w, tmp_shift ); + L_tmp2_q = add( q_cov_real[0][0][b], tmp_shift ); + + IF( LT_16( L_tmp2_q, L_tmp1_q ) ) + { + den_f = L_add( L_shr( L_tmp1, sub( L_tmp1_q, L_tmp2_q ) ), L_tmp2 ); + den_f_e = sub( 31, L_tmp2_q ); + } + ELSE + { + den_f = L_add( L_tmp1, L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + den_f_e = sub( 31, L_tmp1_q ); + } - den_f = L_add( L_tmp1, L_tmp2 ); // Q29 den_f = L_max( den_f, 1 ); - den_f_e = 31 - 29; - move16(); - L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); - L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); - L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); - L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); - L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + tmp64 = W_mult0_32_32( DM_F[b], dm_beta_re ); + tmp_shift = sub( W_norm( tmp64 ), 1 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp2_q = sub( add( add( DM_F_q[b], dm_beta_re_q ), tmp_shift ), 32 ); + L_tmp2 = W_extract_h( tmp64 ); - dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div - move32(); - div_shift = add( sub( 15, ( sub( 29, sub( 31, den_f_e ) ) ) ), s_div ); - dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + tmp_shift = sub( norm_l( dm_alpha[b] ), 1 ); + + IF( LT_16( L_tmp2_q, add( dm_alpha64_q[b], tmp_shift ) ) ) + { + L_tmp1 = L_add( L_shr( dm_alpha[b], sub( dm_alpha64_q[b], L_tmp2_q ) ), L_tmp2 ); + L_tmp1_q = L_tmp2_q; + move16(); + } + ELSE + { + L_tmp1_q = add( dm_alpha64_q[b], tmp_shift ); + L_tmp1 = L_add( L_shl( dm_alpha[b], tmp_shift ), L_shr( L_tmp2, sub( L_tmp2_q, L_tmp1_q ) ) ); + } + + dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // L_tmp1_q - (31 - den_f_e) + (15 - s_div) move32(); + dm_g_q[b] = add( sub( add( L_tmp1_q, den_f_e ), s_div ), 15 - 31 ); + move16(); } ELSE { @@ -1117,67 +1330,591 @@ static void ivas_get_pred_coeffs_fx( Word16 num_f_e; /* quadratic activeW */ + tmp64 = W_shl( W_mult0_32_32( dm_alpha[b], activew_quad_thresh ), 1 ); + tmp_shift = sub( W_norm( tmp64 ), 1 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + L_tmp1 = W_extract_h( tmp64 ); // DM_F_q[b] + dm_alpha64_q[b] + tmp_shift - 32 + L_tmp1_q = sub( add( add( DM_F_q[b], dm_alpha64_q[b] ), tmp_shift ), 32 ); - num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, sub( 31, dm_beta_re_q ), L_negate( L_tmp1 ), sub( 31, L_tmp1_q ), &num_f_e ); - sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); /*Q27*/ - val_e = 4; + sqrt_val = L_shl( Mpy_32_32( Mpy_32_32( dm_alpha[b], dm_alpha[b] ), g_th_sq ), 2 ); + val_e = sub( 31, sub( add( sub( shl( dm_alpha64_q[b], 1 ), 31 ), 27 ), 31 ) ); 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 ); + sqrt_val = BASOP_Util_Add_Mant32Exp( sqrt_val, val_e, Mpy_32_32( dm_beta_re, dm_beta_re ), sub( 31, shl( dm_beta_re_q, 1 ) ), &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 ) ), sub( 31, sub( add( sub( add( dm_beta_re_q, 27 ), 31 ), q_cov_real[0][0][b] ), 31 ) ), &val_e ); // val_e = norm_l( sqrt_val ); sqrt_val = Sqrt32( sqrt_val, &val_e ); - IF( val_e < 0 ) - { - sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); - } - 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 ); + + num_f = BASOP_Util_Add_Mant32Exp( num_f, num_f_e, sqrt_val, val_e, &num_f_e ); den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); - den_f_e = add( dm_beta_re_e, 4 ); + den_f_e = add( sub( 31, dm_beta_re_q ), 4 ); den_f = L_max( den_f, 1 ); dm_g[b] = activew_quad_thresh; // Q29 move32(); + dm_g_q[b] = Q29; + move16(); 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(); + DM_F_q[b] = add( s_dm_f, sub( add( 2, num_f_e ), den_f_e ) ); + move16(); } } + *q_pred_coeffs = 31; + move16(); + *q_dm_fv_re = 31; + move16(); + FOR( i = 0; i < pred_dim; i++ ) { 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 + tmp64 = W_mult0_32_32( dm_v_re[i][b], dm_g[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + ppPred_coeffs_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + dm_g_q[b] + tmp_shift - 32 move32(); - ppDM_Fv_re[i][b] = Mpy_32_32( dm_v_re[i][b], DM_F[b] ); + q_ppPred_coeffs_re[i][b] = sub( add( add( dm_v_re_q[i][b], dm_g_q[b] ), tmp_shift ), 32 ); + move16(); + + tmp64 = W_mult0_32_32( dm_v_re[i][b], DM_F[b] ); + tmp_shift = W_norm( tmp64 ); + IF( tmp64 == 0 ) + { + tmp_shift = 32; + move16(); + } + ELSE + { + tmp64 = W_shl( tmp64, tmp_shift ); + } + ppDM_Fv_re[i][b] = W_extract_h( tmp64 ); // Q = dm_v_re_q[i][b] + DM_F_q[b] + tmp_shift - 32 + move32(); + dm_v_re_q[i][b] = sub( add( add( dm_v_re_q[i][b], DM_F_q[b] ), tmp_shift ), 32 ); + move16(); + + *q_pred_coeffs = s_min( *q_pred_coeffs, q_ppPred_coeffs_re[i][b] ); + move16(); + *q_dm_fv_re = s_min( *q_dm_fv_re, dm_v_re_q[i][b] ); + move16(); + } + } + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( b = start_band; b < end_band; b++ ) + { + ppPred_coeffs_re[i][b] = L_shr( ppPred_coeffs_re[i][b], sub( q_ppPred_coeffs_re[i][b], *q_pred_coeffs ) ); + move32(); + ppDM_Fv_re[i][b] = L_shr( ppDM_Fv_re[i][b], sub( dm_v_re_q[i][b], *q_dm_fv_re ) ); move32(); } } - *q_pred_coeffs = sub( tmp_shift, 2 ); - move16(); - *q_dm_fv_re = sub( tmp_shift, 2 ); - move16(); } return; } -#endif // IVAS_FLOAT_FIXED - -/*-----------------------------------------------------------------------------------------* - * Function ivas_get_Wscaling_factor() - * +static void ivas_get_pred_coeffs_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ppPred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word32 ppDM_Fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + const Word16 in_chans, + const Word16 start_band, + const Word16 end_band, + const Word16 active_w, + const Word16 active_w_vlbr, + const Word16 dtx_vad, + const Word16 from_dirac, + const Word16 dyn_active_w_flag, + const Word16 res_ind, + Word16 *q_pred_coeffs, + Word16 *q_dm_fv_re ) +{ + Word16 i, j, k, b, p; + Word32 abs_value; + Word32 w_norm_fac; + Word32 one_in_q; + Word32 div_factor[IVAS_MAX_NUM_BANDS]; + Word16 pred_dim = sub( in_chans, 1 ); + Word16 tmp_shift, prev_tmp_shift, s_div, div_shift; + + 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; + 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 ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, s_div ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + 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], 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], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + 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 = sub( tmp_shift, 1 ); + move16(); + + FOR( k = start_band; k < end_band; k++ ) + { + 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], 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], sub( abs_s( q_pred_temp ), 1 ) ); // Q30 + move32(); + q_pred_temp = 1; + move16(); + } + + 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 ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, s_div ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + 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; + 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], 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], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + 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 = sub( add( *q_pred_coeffs, tmp_shift ), 31 ); + *q_dm_fv_re = 0; + move16(); + } + ELSE + { + Word32 dm_alpha[IVAS_MAX_NUM_BANDS], dm_v_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + Word32 real[IVAS_SPAR_MAX_CH - 1], dm_beta_re = 0, dm_g[IVAS_MAX_NUM_BANDS]; + Word32 dm_f_local, dm_w, dm_y, DM_F[IVAS_MAX_NUM_BANDS]; + Word32 num_f, den_f, passive_g /*, inv_den_f*/; + Word32 activew_quad_thresh, g_th_sq; + Word32 L_tmp1, L_tmp2; + Word16 L_tmp2_q; + Word16 dm_alpha_e, den_f_e, s_dm_f; + 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 + + set32_fx( dm_alpha, 0, IVAS_MAX_NUM_BANDS ); + + FOR( i = 1; i < in_chans; i++ ) + { + FOR( k = start_band; k < end_band; k++ ) + { + // 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[k] = Sqrt32( dm_alpha[k], &dm_alpha_e ); + move32(); + + 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 ) ); + move32(); + IF( s_div < 0 ) + { + div_shift = add( 15, sub( s_div, dm_alpha_e ) ); + tmp_shift = Q30; + move16(); + } + ELSE + { + div_shift = 15; + move16(); + tmp_shift = sub( Q30, sub( s_div, dm_alpha_e ) ); + } + 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], 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], sub( tmp_shift, prev_tmp_shift ) ); + move32(); + tmp_shift = prev_tmp_shift; + move16(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + 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( dtx_vad == 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_DTX_Q30; + move32(); + } + ELSE + { + 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++ ) + { + set32_fx( real, 0, pred_dim ); + + FOR( j = 0; j < pred_dim; j++ ) + { + FOR( k = 1; k < in_chans; k++ ) + { + Word32 re; + + // IVAS_RMULT_FLOAT( cov_real[j + 1][k][b], dm_v_re[k - 1][b], re ); + 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; + // IVAS_RMULT_FLOAT( real[k], dm_v_re[k][b], re ); + re = Mpy_32_32( real[k], dm_v_re[k][b] ); // Q = 2*tmp_shift - 3 - 31 + dm_beta_re = L_add( dm_beta_re, re ); // Q = 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 = 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[sub( res_ind, 1 )][b] = L_shl( 1, sub( tmp_shift, 1 ) ); + move32(); + } + ELSE + { + 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++ ) + { + dm_y = L_add( dm_y, L_shr( cov_real[k][k][b], 2 ) ); // Q28 + } + den_f = L_max( dm_y, 1 ); // Q28 + 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 = 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 = 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 = 31 - 29; + move16(); + L_tmp2 = Mpy_32_32( DM_F[b], dm_beta_re ); + L_tmp2_q = add( 30, sub( ( sub( shl( tmp_shift, 1 ), 34 ) ), 31 ) ); + L_tmp2 = L_shl( L_tmp2, ( sub( ( sub( 29, dm_alpha_e ) ), L_tmp2_q ) ) ); + L_tmp1 = L_shr( dm_alpha[b], ( sub( ( sub( 31, dm_alpha_e ) ), 29 ) ) ); + L_tmp1 = L_add( L_tmp1, L_tmp2 ); // Q29 + + dm_g[b] = L_deposit_l( BASOP_Util_Divide3232_Scale( L_tmp1, den_f, &s_div ) ); // Q29 + den_f_e - 31 + 15 - s_div + move32(); + div_shift = add( sub( 15, ( sub( 29, sub( 31, den_f_e ) ) ) ), s_div ); + dm_g[b] = L_shl( dm_g[b], div_shift ); // Q30 + move32(); + } + ELSE + { + Word32 sqrt_val; + Word16 val_e; + Word16 num_f_e; + + /* quadratic activeW */ + + num_f = BASOP_Util_Add_Mant32Exp( dm_beta_re, dm_beta_re_e, L_negate( L_shl( Mpy_32_32( dm_alpha[b], activew_quad_thresh ), 1 ) ), add( dm_alpha_e, ( 31 - Q29 ) ), &num_f_e ); + + 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( val_e < 0 ) + { + sqrt_val = L_shr( sqrt_val, abs_s( val_e ) ); + } + 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 ); + + den_f = L_shl( Mpy_32_32( dm_beta_re, g_th_sq ), 1 ); + 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(); + } + } + + FOR( i = 0; i < pred_dim; i++ ) + { + 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 = sub( tmp_shift, 2 ); + move16(); + *q_dm_fv_re = sub( tmp_shift, 2 ); + move16(); + } + + return; +} +#endif // IVAS_FLOAT_FIXED + + +/*-----------------------------------------------------------------------------------------* + * Function ivas_get_Wscaling_factor() + * * Calculation of scaling factor for post predicted W channel *-----------------------------------------------------------------------------------------*/ @@ -1248,6 +1985,118 @@ static void ivas_get_Wscaling_factor( #ifdef IVAS_FLOAT_FIXED +static void ivas_get_Wscaling_factor_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 q_pred_coeffs_re, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 *pNum_dmx, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + Word32 *pWscale, + Word16 *q_pWscale, + const Word16 dyn_active_w_flag ) +{ + Word16 b, ch, q_tmp, q_postpred_cov_re; + Word32 dm_f_local, abs_val; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + q_postpred_cov_re = 0; + move16(); + + FOR( ch = 0; ch < IVAS_SPAR_MAX_CH; ch++ ) + { + set32_fx( postpred_cov_re[ch], 0, IVAS_SPAR_MAX_CH ); + } + + IF( dtx_vad == 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; // Q31 + move32(); + } + ELSE IF( active_w_vlbr != 0 ) + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; // Q31 + move32(); + } + ELSE + { + dm_f_local = IVAS_ACTIVEW_DM_F_SCALE_FX; // Q31 + move32(); + } + + FOR( b = start_band; b < end_band; b++ ) + { + pWscale[b] = 1; + move32(); + q_pWscale[b] = 0; + move16(); + + test(); + 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; + + g_sq = 0; + move32(); + + IF( NE_16( num_ch, pNum_dmx[i_mult( b, bands_bw )] ) ) + { + ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, b, postpred_cov_re, &q_postpred_cov_re ); + } + + Gw_sq = BASOP_Util_Divide3232_Scale( cov_real[0][0][b], L_max( postpred_cov_re[0][0], IVAS_FIX_EPS ), &tmp_exp ); + q_Gw_sq = add( sub( 15, tmp_exp ), sub( q_cov_real[0][0][b], q_postpred_cov_re ) ); + + guard_bits = find_guarded_bits_fx( num_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 ); + } + q_g_sq = sub( add( q_pred_coeffs_re, q_pred_coeffs_re ), add( 31, guard_bits ) ); + + tmp = Mpy_32_32( ONE_IN_Q30 /*4 in Q28*/, Mpy_32_32( dm_f_local, g_sq ) ); + q_tmp = sub( q_g_sq, 3 ); + + q_min = s_min( q_Gw_sq, q_tmp ); + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + tmp = L_add( L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ), tmp ); + + tmp_exp = sub( 31, q_min ); + tmp = Sqrt32( tmp, &tmp_exp ); + q_tmp = sub( 31, tmp_exp ); + + tmp_exp = sub( 31, q_Gw_sq ); + Gw_sq = Sqrt32( Gw_sq, &tmp_exp ); + q_Gw_sq = sub( 31, tmp_exp ); + + q_min = s_min( q_Gw_sq, q_tmp ); + Gw_sq = L_shr( Gw_sq, sub( q_Gw_sq, q_min ) ); + q_Gw_sq = q_min; + move16(); + + tmp = L_shr( tmp, sub( q_tmp, q_min ) ); + + pWscale[b] = L_add( Mpy_32_32( Gw_sq, ONE_IN_Q30 /* 0.5 in Q31*/ ), Mpy_32_32( tmp, ONE_IN_Q30 /* 0.5 in Q31*/ ) ); + move32(); + q_pWscale[b] = q_Gw_sq; + move16(); + } + } + + return; +} + static void ivas_get_Wscaling_factor_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1522,7 +2371,7 @@ void ivas_create_fullr_dmx_mat_fx( { FOR( b = start_band; b < end_band; b++ ) { - tmp_p2_re[j][j][b] = L_shl( 1, q_pred_coeffs_re ); + tmp_p2_re[j][j][b] = L_shl_sat( 1, q_pred_coeffs_re ); move32(); max_val_tmp_p2 = L_max( max_val_tmp_p2, L_abs( tmp_p2_re[j][j][b] ) ); } @@ -1722,33 +2571,198 @@ static void ivas_calc_post_pred_per_band( } } - /* num_ch x num_ch mult */ - for ( i = 0; i < num_ch; i++ ) + /* num_ch x num_ch mult */ + for ( i = 0; i < num_ch; i++ ) + { + for ( j = i; j < num_ch; j++ ) + { + for ( k = 0; k < num_ch; k++ ) + { + IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); + postpred_cov_re[i][j] += tmp_re; + } + } + } + + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < i; j++ ) + { + postpred_cov_re[i][j] = postpred_cov_re[j][i]; + } + } + + return; +} + + +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_post_pred_per_band_enc_fx( + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 band_idx, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_postpred_cov_re ) +{ + Word16 i, j, k, guard_bits, tmp, q_temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], q_tmp_re, q_W_tmp; + Word32 dmx_mat_conj[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 temp_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + Word32 max_val; + Word64 tmp_re, W_tmp; + Word16 q_postpred_cov_re_per_value[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + dmx_mat_conj[i][j] = mixer_mat[j][i][band_idx]; + move32(); + } + } + + FOR( i = 0; i < num_ch; i++ ) + { + set32_fx( temp_mat[i], 0, num_ch ); + set32_fx( postpred_cov_re[i], 0, num_ch ); + } + + max_val = 1; + move32(); + /* num_ch x num_ch mult */ + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = 0; j < num_ch; j++ ) + { + tmp_re = 0; + move64(); + q_tmp_re = 31; + move16(); + FOR( k = 0; k < num_ch; k++ ) + { + W_tmp = W_shr( W_mult0_32_32( cov_real[i][k][band_idx], dmx_mat_conj[k][j] ), q_mixer_mat ); + IF( LT_16( q_cov_real[i][k][band_idx], q_tmp_re ) ) + { + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_cov_real[i][k][band_idx] ) ), W_tmp ); + q_tmp_re = q_cov_real[i][k][band_idx]; + move16(); + } + ELSE + { + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_cov_real[i][k][band_idx], q_tmp_re ) ) ); + } + } + IF( tmp_re == 0 ) + { + q_temp_mat[i][j] = 31; + move16(); + temp_mat[i][j] = 0; + move32(); + } + ELSE + { + q_temp_mat[i][j] = q_tmp_re; + move16(); + q_tmp_re = W_norm( tmp_re ); + temp_mat[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + move32(); + q_temp_mat[i][j] = sub( add( q_temp_mat[i][j], q_tmp_re ), 32 ); + move16(); + } + max_val = L_max( max_val, L_abs( temp_mat[i][j] ) ); + } + } + + guard_bits = find_guarded_bits_fx( num_ch ); + + tmp = norm_l( max_val ); + IF( LT_16( tmp, guard_bits ) ) + { + guard_bits = sub( guard_bits, tmp ); + } + ELSE + { + guard_bits = 0; + move16(); + } + + *q_postpred_cov_re = 31; + move16(); + /* num_ch x num_ch mult */ + FOR( i = 0; i < num_ch; i++ ) + { + FOR( j = i; j < num_ch; j++ ) + { + tmp_re = 0; + move64(); + q_tmp_re = 31; + move16(); + FOR( k = 0; k < num_ch; k++ ) + { + W_tmp = W_shr( W_mult0_32_32( mixer_mat[i][k][band_idx], temp_mat[k][j] ), guard_bits ); + q_W_tmp = sub( add( q_temp_mat[k][j], q_mixer_mat ), guard_bits ); + IF( LT_16( q_W_tmp, q_tmp_re ) ) + { + tmp_re = W_add( W_shr( tmp_re, sub( q_tmp_re, q_W_tmp ) ), W_tmp ); + q_tmp_re = q_W_tmp; + move16(); + } + ELSE + { + tmp_re = W_add( tmp_re, W_shr( W_tmp, sub( q_W_tmp, q_tmp_re ) ) ); + } + } + + if ( LT_64( W_abs( tmp_re ), L_shl( IVAS_FIX_EPS, guard_bits ) ) ) + { + tmp_re = 0; + move64(); + } + + q_postpred_cov_re_per_value[i][j] = q_tmp_re; + move16(); + q_tmp_re = W_norm( tmp_re ); + postpred_cov_re[i][j] = W_extract_h( W_shl( tmp_re, q_tmp_re ) ); + move32(); + q_postpred_cov_re_per_value[i][j] = sub( add( q_tmp_re, q_postpred_cov_re_per_value[i][j] ), 32 ); + move16(); + *q_postpred_cov_re = s_min( *q_postpred_cov_re, q_postpred_cov_re_per_value[i][j] ); + move16(); + } + } + + FOR( i = 0; i < num_ch; i++ ) { - for ( j = i; j < num_ch; j++ ) + FOR( j = i; j < num_ch; j++ ) { - for ( k = 0; k < num_ch; k++ ) + IF( postpred_cov_re[i][j] >= 0 ) { - IVAS_RMULT_FLOAT( mixer_mat[i][k][band_idx], temp_mat[k][j], tmp_re ); - postpred_cov_re[i][j] += tmp_re; + postpred_cov_re[i][j] = L_shr( postpred_cov_re[i][j], sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ); + move32(); + } + ELSE + { + postpred_cov_re[i][j] = L_negate( L_shr( L_negate( postpred_cov_re[i][j] ), sub( q_postpred_cov_re_per_value[i][j], *q_postpred_cov_re ) ) ); + move32(); } } } - for ( i = 0; i < num_ch; i++ ) + FOR( i = 0; i < num_ch; i++ ) { - for ( j = 0; j < i; j++ ) + FOR( j = 0; j < i; j++ ) { postpred_cov_re[i][j] = postpred_cov_re[j][i]; + move32(); } } return; } - -#ifdef IVAS_FLOAT_FIXED - static void ivas_calc_post_pred_per_band_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, @@ -1897,166 +2911,672 @@ static void ivas_calc_p_coeffs_per_band( set_zero( recon_uu_re[i], 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]; - } - } + 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]; + } + } + + if ( 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]; + } + } + + if ( num_dmx == 2 ) + { + float re1, re2; + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); + + for ( i = 0; i < 2; i++ ) + { + for ( j = 0; j < 2; j++ ) + { + cov_uu_re[i][j] -= recon_uu_re[i][j]; + } + } + } + else if ( num_dmx == 3 ) + { + float re1[2], re2; + set_f( re1, 0, 2 ); + + for ( j = 0; j < 2; j++ ) + { + for ( k = 0; k < 2; k++ ) + { + float re; + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); + re1[j] += re; + } + } + + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); + recon_uu_re[0][0] = re2; + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); + recon_uu_re[0][0] += re2; + + cov_uu_re[0][0] -= recon_uu_re[0][0]; + } + else if ( num_dmx == 4 ) + { + /* Step 1: Multiply C * cov_dd * C' */ + float re1[3], re; + + for ( i = 0; i < num_ch - num_dmx; i++ ) + { + set_f( re1, 0, 3 ); + for ( m = 0; m < num_dmx - 1; m++ ) + { + for ( k = 0; k < num_dmx - 1; k++ ) + { + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); + re1[m] += re; + } + } + for ( j = 0; j < num_ch - num_dmx; j++ ) + { + for ( m = 0; m < num_dmx - 1; m++ ) + { + IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); + recon_uu_re[i][j] += re; + } + } + } + + /* Step 2: cov_uu - recon_uu */ + for ( i = 0; i < num_ch - num_dmx; i++ ) + { + for ( j = 0; j < num_ch - num_dmx; j++ ) + { + cov_uu_re[i][j] -= recon_uu_re[i][j]; + } + } + } + } + + p_norm_scaling = IVAS_P_NORM_SCALING; + + if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) + { + p_norm_scaling = IVAS_P_NORM_SCALING_DTX; + } + + trace = 0.0f; + + for ( i = num_dmx; i < num_ch; i++ ) + { + float tmp_out; + IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); + trace += tmp_out; + } + + factor = max( 1e-20f, postpred_cov_re[0][0] ); + factor = max( factor, ( p_norm_scaling * trace ) ); + factor = 1 / factor; + + /* normalise Hermitian (except for rounding) cov_uu */ + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + if ( i == j ) + { + /* force diagonal to be real */ + cov_uu_re[i - num_dmx][j - num_dmx] *= factor; + } + else + { + /* set off-diag elements to zero */ + cov_uu_re[i - num_dmx][j - num_dmx] = 0; + } + } + } + + /* take sqrt of max of diags and zero */ + for ( i = num_dmx; i < num_ch; i++ ) + { + cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); + /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ + } + + /* save into MD struct */ + for ( i = num_dmx; i < num_ch; i++ ) + { + for ( j = num_dmx; j < num_ch; j++ ) + { + if ( i == j ) + { + pSparMd->band_coeffs[b_ts_idx].P_re[j - num_dmx] = cov_uu_re[i - num_dmx][j - num_dmx]; + } + } + } + } + + return; +} + +#ifdef IVAS_FLOAT_FIXED + +static void ivas_calc_p_coeffs_per_band_enc_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_postpred_cov_re, + const Word16 num_ch, + const Word16 dtx_vad, + const Word16 num_dmx, + const Word16 band_idx ) +{ + Word16 i, j, k; + Word16 m; + Word32 factor; + Word32 recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; + Word16 q_recon_uu_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS]; + Word64 trace, W_tmp; + Word16 q_factor, q_tmp, q_tmp1; + Word32 tmp; + Word32 p_norm_scaling; + Word16 q_cov_uu_re, q_cov_dd_re; + Word32 cov_dd_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word32 cov_uu_re[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word16 q_cov_uu_re_per_value[IVAS_SPAR_MAX_CH - 1][IVAS_SPAR_MAX_CH - 1]; + Word16 b_ts_idx; + + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); + + IF( NE_16( num_dmx, num_ch ) ) + { + 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 < sub( IVAS_SPAR_MAX_CH, IVAS_SPAR_MAX_DMX_CHS ); i++ ) + { + 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[sub( i, num_dmx )][sub( j, num_dmx )] = postpred_cov_re[i][j]; + move32(); + } + } + q_cov_uu_re = q_postpred_cov_re; + move16(); + + IF( EQ_16( dtx_vad, 1 ) ) + { + FOR( i = 1; i < num_dmx; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + q_cov_dd_re = q_postpred_cov_re; + move16(); + + Word16 q_C_re = pSparMd->band_coeffs[b_ts_idx].q_C_re_fx; + move16(); + + IF( EQ_16( num_dmx, 2 ) ) + { + Word32 re1, re2; + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], cov_dd_re[0][0] ); + q_tmp1 = W_norm( W_tmp ); + re1 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp1 = 31; + move16(); + } + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], cov_dd_re[0][0] ); + q_tmp = W_norm( W_tmp ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1 ); + q_recon_uu_re[0][0] = W_norm( W_tmp ); + move16(); + recon_uu_re[0][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][0] ) ); + move32(); + q_recon_uu_re[0][0] = sub( add( add( q_C_re, q_recon_uu_re[0][0] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[0][0] = 31; + move16(); + } + + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re1 ); + q_recon_uu_re[0][1] = W_norm( W_tmp ); + move16(); + recon_uu_re[0][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[0][1] ) ); + move32(); + q_recon_uu_re[0][1] = sub( add( add( q_C_re, q_recon_uu_re[0][1] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[0][1] = 31; + move16(); + } - if ( dtx_vad == 1 ) - { - for ( i = 1; i < num_dmx; i++ ) - { - for ( j = 1; j < num_dmx; j++ ) + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re2 ); + q_recon_uu_re[1][0] = W_norm( W_tmp ); + move16(); + recon_uu_re[1][0] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][0] ) ); + move32(); + q_recon_uu_re[1][0] = sub( add( add( q_C_re, q_recon_uu_re[1][0] ), q_tmp ), 32 ); + move16(); + if ( W_tmp == 0 ) { - cov_dd_re[i - 1][j - 1] = postpred_cov_re[i][j]; + q_recon_uu_re[1][0] = 31; + move16(); } - } - if ( num_dmx == 2 ) - { - float re1, re2; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[1][0], re2 ); + q_recon_uu_re[1][1] = W_norm( W_tmp ); + move16(); + recon_uu_re[1][1] = W_extract_h( W_shl( W_tmp, q_recon_uu_re[1][1] ) ); + move32(); + q_recon_uu_re[1][1] = sub( add( add( q_C_re, q_recon_uu_re[1][1] ), q_tmp1 ), 32 ); + move16(); + if ( W_tmp == 0 ) + { + q_recon_uu_re[1][1] = 31; + move16(); + } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], cov_dd_re[0][0], re1 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], cov_dd_re[0][0], re2 ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1, recon_uu_re[0][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re1, recon_uu_re[0][1] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re2, recon_uu_re[1][0] ); - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[1][0], re2, recon_uu_re[1][1] ); + q_tmp = 31; + move16(); + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 2; j++ ) + { + q_tmp = s_min( q_tmp, q_recon_uu_re[i][j] ); + } + } + q_tmp = sub( s_min( q_tmp, q_cov_uu_re ), 1 ); - for ( i = 0; i < 2; i++ ) + FOR( i = 0; i < 2; i++ ) { - for ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - cov_uu_re[i][j] -= recon_uu_re[i][j]; + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + move32(); } } + q_cov_uu_re = q_tmp; + move16(); } - else if ( num_dmx == 3 ) + ELSE IF( EQ_16( num_dmx, 3 ) ) { - float re1[2], re2; - set_f( re1, 0, 2 ); + Word32 re1[2], re2; + Word16 q_re1[2]; + set32_fx( re1, 0, 2 ); + set16_fx( q_re1, 31, 2 ); - for ( j = 0; j < 2; j++ ) + FOR( j = 0; j < 2; j++ ) { - for ( k = 0; k < 2; k++ ) + FOR( k = 0; k < 2; k++ ) { - float re; + Word32 re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][k], cov_dd_re[k][j] ); + q_tmp = sub( W_norm( W_tmp ), 1 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][k], cov_dd_re[k][j], re ); - re1[j] += re; + IF( LT_16( q_tmp, q_re1[j] ) ) + { + re1[j] = L_shr( re1[j], sub( q_re1[j], q_tmp ) ); + move32(); + q_re1[j] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_re1[j] ) ); + } + re1[j] = L_add( re1[j], re ); + move32(); } } - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][0], re1[0], re2 ); + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][0], re1[0] ); + q_tmp = sub( W_norm( W_tmp ), 1 ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[0] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } recon_uu_re[0][0] = re2; - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[0][1], re1[1], re2 ); - recon_uu_re[0][0] += re2; + move32(); - cov_uu_re[0][0] -= recon_uu_re[0][0]; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[0][1], re1[1] ); + q_tmp1 = sub( W_norm( W_tmp ), 1 ); + re2 = W_extract_h( W_shl( W_tmp, q_tmp1 ) ); + q_tmp1 = sub( add( add( q_C_re, q_tmp1 ), q_re1[1] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp1 = 31; + move16(); + } + + IF( LT_16( q_tmp, q_tmp1 ) ) + { + re2 = L_shr( re2, sub( q_tmp1, q_tmp ) ); + } + ELSE + { + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_tmp1 ) ); + move32(); + q_tmp = q_tmp1; + move16(); + } + + recon_uu_re[0][0] = L_add( recon_uu_re[0][0], re2 ); + move32(); + + IF( LT_16( q_cov_uu_re, q_tmp ) ) + { + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], sub( q_tmp, q_cov_uu_re ) ); + move32(); + } + ELSE + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re, q_tmp ) ); + move32(); + } + } + q_cov_uu_re = q_tmp; + move16(); + } + + IF( recon_uu_re[0][0] != 0 ) + { + test(); + IF( W_norm( recon_uu_re[0][0] ) == 0 || W_norm( cov_uu_re[0][0] ) == 0 ) + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = num_dmx; j < num_ch; j++ ) + { + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], 1 ); + move32(); + } + } + q_cov_uu_re = sub( q_cov_uu_re, 1 ); + recon_uu_re[0][0] = L_shr( recon_uu_re[0][0], 1 ); + move32(); + } + } + + cov_uu_re[0][0] = L_sub( cov_uu_re[0][0], recon_uu_re[0][0] ); + move32(); } - else if ( num_dmx == 4 ) + ELSE IF( EQ_16( num_dmx, 4 ) ) { /* Step 1: Multiply C * cov_dd * C' */ - float re1[3], re; + Word32 re1[3], re; + Word16 q_re1[3]; - for ( i = 0; i < num_ch - num_dmx; i++ ) + FOR( i = 0; i < num_ch - num_dmx; i++ ) { - set_f( re1, 0, 3 ); - for ( m = 0; m < num_dmx - 1; m++ ) + set32_fx( re1, 0, 3 ); + set16_fx( q_re1, 31, 3 ); + set16_fx( q_recon_uu_re[i], 31, IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ); + FOR( m = 0; m < num_dmx - 1; m++ ) { - for ( k = 0; k < num_dmx - 1; k++ ) + FOR( k = 0; k < num_dmx - 1; k++ ) { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[i][k], cov_dd_re[k][m], re ); - re1[m] += re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[i][k], cov_dd_re[k][m] ); + q_tmp = sub( W_norm( W_tmp ), 2 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_cov_dd_re ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, q_re1[m] ) ) + { + re1[m] = L_shr( re1[m], sub( q_re1[m], q_tmp ) ); + move32(); + q_re1[m] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_re1[m] ) ); + } + IF( re != 0 ) + { + test(); + IF( W_norm( re ) == 0 || W_norm( re1[m] ) == 0 ) + { + re1[m] = L_shr( re1[m], 1 ); + move32(); + q_re1[m] = sub( q_re1[m], 1 ); + move16(); + re = L_shr( re, 1 ); + } + } + + re1[m] = L_add( re1[m], re ); + move32(); } } - for ( j = 0; j < num_ch - num_dmx; j++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - for ( m = 0; m < num_dmx - 1; m++ ) + FOR( m = 0; m < num_dmx - 1; m++ ) { - IVAS_RMULT_FLOAT( pSparMd->band_coeffs[b_ts_idx].C_re[j][m], re1[m], re ); - recon_uu_re[i][j] += re; + W_tmp = W_mult0_32_32( pSparMd->band_coeffs[b_ts_idx].C_re_fx[j][m], re1[m] ); + q_tmp = sub( W_norm( W_tmp ), 2 ); + re = W_extract_h( W_shl( W_tmp, q_tmp ) ); + q_tmp = sub( add( add( q_C_re, q_tmp ), q_re1[m] ), 32 ); + if ( W_tmp == 0 ) + { + q_tmp = 31; + move16(); + } + + IF( LT_16( q_tmp, q_recon_uu_re[i][j] ) ) + { + recon_uu_re[i][j] = L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ); + move32(); + q_recon_uu_re[i][j] = q_tmp; + move16(); + } + ELSE + { + re = L_shr( re, sub( q_tmp, q_recon_uu_re[i][j] ) ); + } + IF( re != 0 ) + { + test(); + IF( W_norm( re ) == 0 || W_norm( recon_uu_re[i][j] ) == 0 ) + { + re1[m] = L_shr( re1[m], 1 ); + move32(); + q_recon_uu_re[i][j] = sub( q_recon_uu_re[i][j], 1 ); + move16(); + re = L_shr( re, 1 ); + } + } + recon_uu_re[i][j] = L_add( recon_uu_re[i][j], re ); + move32(); } } } + q_tmp = 31; + move16(); + FOR( i = 0; i < num_ch - num_dmx; i++ ) + { + FOR( j = 0; j < num_ch - num_dmx; j++ ) + { + q_tmp = s_min( q_tmp, q_recon_uu_re[i][j] ); + } + } + q_tmp = sub( s_min( q_tmp, q_cov_uu_re ), 1 ); + /* 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++ ) + FOR( j = 0; j < num_ch - num_dmx; j++ ) { - cov_uu_re[i][j] -= recon_uu_re[i][j]; + cov_uu_re[i][j] = L_sub( L_shr( cov_uu_re[i][j], sub( q_cov_uu_re, q_tmp ) ), L_shr( recon_uu_re[i][j], sub( q_recon_uu_re[i][j], q_tmp ) ) ); + move32(); } } + q_cov_uu_re = q_tmp; + move16(); } } - p_norm_scaling = IVAS_P_NORM_SCALING; + p_norm_scaling = IVAS_P_NORM_SCALING_FX; + move32(); - if ( ( dtx_vad == 0 ) && ( num_dmx == 1 ) ) + test(); + if ( ( dtx_vad == 0 ) && EQ_16( num_dmx, 1 ) ) { - p_norm_scaling = IVAS_P_NORM_SCALING_DTX; + p_norm_scaling = IVAS_P_NORM_SCALING_DTX_FX; + move32(); } - trace = 0.0f; + trace = 0; + move64(); - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - float tmp_out; - IVAS_CALCULATE_RABS( cov_uu_re[i - num_dmx][i - num_dmx], tmp_out ); - trace += tmp_out; + trace = W_add( trace, W_deposit32_l( L_abs( cov_uu_re[sub( i, num_dmx )][sub( i, num_dmx )] ) ) ); } - factor = max( 1e-20f, postpred_cov_re[0][0] ); - factor = max( factor, ( p_norm_scaling * trace ) ); - factor = 1 / factor; + factor = L_max( IVAS_FIX_EPS, postpred_cov_re[0][0] ); + q_factor = q_postpred_cov_re; + move16(); + IF( trace != 0 ) + { + q_factor = W_norm( trace ); + tmp = Mpy_32_32( p_norm_scaling, W_extract_h( W_shl( trace, q_factor ) ) ); + q_factor = sub( add( q_postpred_cov_re, q_factor ), 32 ); + IF( GT_16( q_factor, q_postpred_cov_re ) ) + { + tmp = L_shr( tmp, sub( q_factor, q_postpred_cov_re ) ); + q_factor = q_postpred_cov_re; + move16(); + } + ELSE + { + factor = L_shr( factor, sub( q_postpred_cov_re, q_factor ) ); + } + factor = L_max( factor, tmp ); + } + + Word16 factor_exp = 0; + move16(); + factor = BASOP_Util_Divide3232_Scale( 1, factor, &factor_exp ); + factor_exp = add( factor_exp, q_factor ); /* normalise Hermitian (except for rounding) cov_uu */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { /* force diagonal to be real */ - cov_uu_re[i - num_dmx][j - num_dmx] *= factor; + W_tmp = W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ); + q_tmp = 32; + move16(); + if ( W_tmp != 0 ) + { + q_tmp = W_norm( W_tmp ); + } + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = W_extract_h( W_shl( W_mult0_32_32( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], factor ), q_tmp ) ); + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = sub( add( add( q_cov_uu_re, sub( 15, factor_exp ) ), q_tmp ), 32 ); + move16(); } - else + ELSE { /* set off-diag elements to zero */ - cov_uu_re[i - num_dmx][j - num_dmx] = 0; + cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )] = 0; + move16(); } } } + Word16 cov_uu_re_exp; + q_tmp = 31; + move16(); /* take sqrt of max of diags and zero */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - cov_uu_re[i - num_dmx][i - num_dmx] = sqrtf( max( 0.0f, cov_uu_re[i - num_dmx][i - num_dmx] ) ); - /* cov_uu_im[i - num_dmx][i - num_dmx] = 0; */ + cov_uu_re_exp = sub( 31, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); + 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 ); + move32(); + q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] = sub( 31, cov_uu_re_exp ); + move16(); + q_tmp = s_min( q_tmp, q_cov_uu_re_per_value[sub( i, num_dmx )][sub( i, num_dmx )] ); } /* save into MD struct */ - for ( i = num_dmx; i < num_ch; i++ ) + FOR( i = num_dmx; i < num_ch; i++ ) { - for ( j = num_dmx; j < num_ch; j++ ) + FOR( j = num_dmx; j < num_ch; j++ ) { - if ( i == j ) + IF( EQ_16( i, j ) ) { - pSparMd->band_coeffs[b_ts_idx].P_re[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 )] = L_shr( cov_uu_re[sub( i, num_dmx )][sub( j, num_dmx )], sub( q_cov_uu_re_per_value[sub( i, num_dmx )][sub( j, num_dmx )], q_tmp ) ); + move32(); } } } + pSparMd->band_coeffs[b_ts_idx].q_P_re_fx = q_tmp; + move16(); } return; } -#ifdef IVAS_FLOAT_FIXED - static void ivas_calc_p_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, @@ -2282,6 +3802,7 @@ static void ivas_calc_p_coeffs_per_band_fx( return; } + #endif // IVAS_FLOAT_FIXED @@ -2382,6 +3903,156 @@ static void ivas_calc_c_coeffs_per_band( #ifdef IVAS_FLOAT_FIXED +static void ivas_calc_c_coeffs_per_band_enc_fx( + ivas_spar_md_t *pSparMd, + const Word16 i_ts, + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 q_post_pred_cov_re, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad ) +{ + Word16 i, j, k; + + /* worst case for cov_ud is actually 12 x 3 */ + Word32 cov_ud_re[IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS][IVAS_SPAR_MAX_DMX_CHS - 1]; + Word32 cov_dd_re[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word32 cov_dd_re_inv[FOA_CHANNELS - 1][FOA_CHANNELS - 1]; + Word16 q_cov_dd_re_inv; + Word32 trace_cov_dd_re, max_val; + Word16 q_tmp; + Word32 abs_trace; + Word16 b_ts_idx; + + b_ts_idx = add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) ); + + IF( dtx_vad == 0 ) + { + 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; + } + + FOR( i = num_dmx; i < num_ch; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + cov_ud_re[sub( i, num_dmx )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + + max_val = 0; + move32(); + + FOR( i = 1; i < num_dmx; i++ ) + { + FOR( j = 1; j < num_dmx; j++ ) + { + IF( EQ_16( i, j ) ) + { + max_val = L_max( max_val, postpred_cov_re[i][j] ); + } + cov_dd_re[sub( i, 1 )][sub( j, 1 )] = postpred_cov_re[i][j]; + move32(); + } + } + + trace_cov_dd_re = 0; + move32(); + + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + trace_cov_dd_re = L_add( trace_cov_dd_re, Mpy_32_32( cov_dd_re[i][i], 10737418 /* 0.005f in Q31*/ ) ); + } + + abs_trace = L_abs( trace_cov_dd_re ); + + 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, 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 + { + q_tmp = 1; + move16(); + IF( norm_l( max_val ) > 0 ) + { + q_tmp = 0; + move16(); + } + trace_cov_dd_re = L_shr( trace_cov_dd_re, q_tmp ); + FOR( i = 0; i < sub( num_dmx, 1 ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + cov_dd_re[i][j] = L_shr( cov_dd_re[i][j], q_tmp ); // q_post_pred_cov_re - q_tmp + move32(); + } + } + + 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, 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, 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, sub( q_post_pred_cov_re, q_tmp ), sub( num_dmx, 1 ), cov_dd_re_inv, &q_cov_dd_re_inv ); + + Word16 tmp; + Word64 W_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 < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + C_re_fx[i][j] = 0; + move64(); + 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(); + } + IF( LT_64( W_max_val, W_abs( C_re_fx[i][j] ) ) ) + { + W_max_val = W_abs( C_re_fx[i][j] ); + } + } + } + + tmp = s_max( sub( 32, W_norm( W_max_val ) ), 0 ); + + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + 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(); + } + } + + return; +} + static void ivas_calc_c_coeffs_per_band_fx( ivas_spar_md_t *pSparMd, const Word16 i_ts, @@ -2570,6 +4241,65 @@ void ivas_calc_c_p_coeffs( #ifdef IVAS_FLOAT_FIXED +void ivas_calc_c_p_coeffs_enc_fx( + ivas_spar_md_t *pSparMd, + Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + const Word16 i_ts, + Word32 ***mixer_mat, + Word16 q_mixer_mat, + const Word16 num_ch, + const Word16 num_dmx, + const Word16 band_idx, + const Word16 dtx_vad, + const Word16 compute_p_flag, + const Word16 dyn_active_w_flag ) +{ + Word16 i, j, q_postpred_cov_re; + Word32 postpred_cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] = { 0 }; + + IF( NE_16( num_dmx, num_ch ) ) + { + ivas_calc_post_pred_per_band_enc_fx( cov_real, q_cov_real, mixer_mat, q_mixer_mat, num_ch, band_idx, postpred_cov_re, &q_postpred_cov_re ); + + IF( NE_16( num_dmx, 1 ) ) + { + ivas_calc_c_coeffs_per_band_enc_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, num_dmx, band_idx, dtx_vad ); + } + + IF( dyn_active_w_flag ) + { + FOR( i = 0; i < sub( num_ch, num_dmx ); i++ ) + { + FOR( j = 0; j < sub( num_dmx, 1 ); j++ ) + { + pSparMd->band_coeffs[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[i][j] = 0; + move32(); + } + } + 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 ) ) + { + ivas_calc_p_coeffs_per_band_enc_fx( pSparMd, i_ts, postpred_cov_re, q_postpred_cov_re, num_ch, dtx_vad, num_dmx, band_idx ); + } + + IF( dyn_active_w_flag ) + { + FOR( i = num_dmx; i < num_ch; i++ ) + { + 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[add( band_idx, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_P_re_fx = 0; + move16(); + } + } + + return; +} + void ivas_calc_c_p_coeffs_fx( ivas_spar_md_t *pSparMd, Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -3184,6 +4914,85 @@ void ivas_compute_spar_params( } #ifdef IVAS_FLOAT_FIXED + +void ivas_compute_spar_params_enc_fx( + Word32 *cov_real_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word16 *q_cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + Word32 dm_fv_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + Word16 *q_dm_fv_re, + const Word16 i_ts, + Word32 ***mixer_mat_fx, + Word16 *q_mixer_mat, + const Word16 start_band, + const Word16 end_band, + const Word16 dtx_vad, + const Word16 num_ch, + const Word16 bands_bw, + const Word16 active_w, + const Word16 active_w_vlbr, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + Word32 *pWscale, + Word16 *q_Wscale, + const Word16 from_dirac, + const Word16 dyn_active_w_flag ) +{ + Word16 b, i, ndm; + Word16 q_pred_coeffs_re; + Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; + + ivas_get_pred_coeffs_enc_fx( cov_real_fx, q_cov_real, pred_coeffs_re_fx, &q_pred_coeffs_re, dm_fv_re_fx, q_dm_fv_re, num_ch, start_band, end_band, active_w, active_w_vlbr, dtx_vad, from_dirac, dyn_active_w_flag, hSparMd->res_ind ); + + ivas_create_fullr_dmx_mat_fx( pred_coeffs_re_fx, q_pred_coeffs_re, dm_fv_re_fx, *q_dm_fv_re, mixer_mat_fx, q_mixer_mat, num_ch, start_band, end_band, active_w, hSparCfg ); + + ivas_get_Wscaling_factor_enc_fx( cov_real_fx, q_cov_real, pred_coeffs_re_fx, q_pred_coeffs_re, mixer_mat_fx, *q_mixer_mat, start_band, end_band, dtx_vad, num_ch, hSparCfg->num_dmx_chans_per_band, bands_bw, active_w, active_w_vlbr, pWscale, q_Wscale, dyn_active_w_flag ); + + FOR( b = start_band; b < end_band; b++ ) + { + Word16 tmp_exp, q_tmp, tmp; + IF( pWscale[b] == 0 ) + { + pWscale[b] = 1; + move32(); + q_Wscale[b] = 15; + move16(); + } + + Word16 onebyscale_fx = BASOP_Util_Divide3232_Scale( 1, pWscale[b], &tmp_exp ); + q_tmp = sub( sub( 15, tmp_exp ), q_Wscale[b] ); + + tmp = sub( add( q_pred_coeffs_re, q_tmp ), 15 ); + FOR( i = 0; i < sub( num_ch, 1 ); i++ ) + { + hSparMd->band_coeffs[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = Mpy_32_16_1( pred_coeffs_re_fx[i][b], onebyscale_fx ); + 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[add( b, imult1616( i_ts, IVAS_MAX_NUM_BANDS ) )].q_pred_re_fx = tmp; + move16(); + + FOR( i = 0; i < num_ch; i++ ) + { + mixer_mat_fx[0][i][b] = W_extract_l( W_shr( W_mult0_32_32( mixer_mat_fx[0][i][b], pWscale[b] ), q_Wscale[b] ) ); + move32(); + } + } + + FOR( b = start_band; b < end_band; b++ ) + { + ndm = hSparCfg->num_dmx_chans_per_band[imult1616( b, bands_bw )]; + move16(); + + IF( NE_16( ndm, num_ch ) ) + { + ivas_calc_c_p_coeffs_enc_fx( hSparMd, cov_real_fx, q_cov_real, i_ts, mixer_mat_fx, *q_mixer_mat, num_ch, ndm, b, dtx_vad, 1, dyn_active_w_flag ); + } + } + + return; +} + + void ivas_compute_spar_params_fx( Word32 *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], Word16 q_cov_real, diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 9c2e272e4..20a851b29 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -6930,18 +6930,18 @@ void dec_pit_exc_ivas_fx( #ifdef IVAS_FLOAT_FIXED // pit_dec_fx.c -Word32 Mode2_pit_decode( /* o: floating pitch value */ +Word32 Mode2_pit_decode( /* o: pitch value Q16 */ const Word16 coder_type, /* i: coding model */ Word16 i_subfr, /* i: subframe index */ Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch Q0 */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch Q0 */ + Word16 *T0_res, /* i/o: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0 */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search Q0 */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, @@ -6950,9 +6950,9 @@ Word32 Mode2_pit_decode( /* o: floating pitch value Word16 pit_res_max ); void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 *T0_res, /* o: pitch resolution Q0 */ Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ Word16 pit_min, Word16 pit_fr1, @@ -6960,11 +6960,11 @@ void Mode2_abs_pit_dec( Word16 pit_res_max ); void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 T0_res, /* i: pitch resolution Q0 */ + Word16 *T0_min, /* i: delta search min Q0 */ + Word16 *T0_min_frac, /* i: delta search min Q0 */ Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ); @@ -7001,8 +7001,8 @@ Word16 pit_decode_ivas_fx( /* o : floating p Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ); void pit_Q_dec_fx( @@ -7077,33 +7077,32 @@ void limit_T0_voiced( // inov_dec.c void inov_decode_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code /* o : algebraic excitation */ - , - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ); #ifdef IVAS_FLOAT_FIXED void inov_decode_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ); #endif #ifdef IVAS_FLOAT_FIXED @@ -7779,7 +7778,7 @@ void hvq_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 num_bits, /* i : Number of available bits */ const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *noise_level, /* o : Noise level in Q15 */ Word16 *peak_idx, /* o : Peak position vector */ @@ -7976,19 +7975,21 @@ Word16 FEC_pos_dec_fx( // post_dec.h void post_decoder( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ); + Word16 synth_buf[], /* Q0 */ + Word16 pit_gain[], /* Q14 */ + Word16 pitch[], /* Q0 */ + Word16 signal_out[], /* Q0 */ + Word16 *bpf_noise_buf /* Q0 */ +); void post_decoder_ivas_fx( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ); + Word16 synth_buf[], // Q0 + Word16 pit_gain[], // Q14 + Word16 pitch[], // Q0 + Word16 signal_out[], // Q0 + Word16 *bpf_noise_buf // Q0 +); void cldfb_synth_set_bandsToZero( Decoder_State *st, @@ -8283,13 +8284,12 @@ void swb_hr_noise_fill_fx( #ifdef IVAS_FLOAT_FIXED // stat_noise_uv_dec_fx.c void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2 /* i/o: excitation buffer */ - , - const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector Q15 */ + Word16 *lsp_mid, /* i : mid-frame LSP vector Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q = 14 - norm_s(Aq[0]) */ + Word16 *exc2, /* i/o: excitation buffer, Q = st_fx->Q_exc */ + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ); #endif diff --git a/lib_com/rom_com.c b/lib_com/rom_com.c index a496c0dd1..450c166cb 100644 --- a/lib_com/rom_com.c +++ b/lib_com/rom_com.c @@ -34696,7 +34696,7 @@ const float PowerCB_NB[64][2] = { 0.95166016f, 1.0351563f, }, }; -const Word16 PowerCB_WB_fx[128] = +const Word16 PowerCB_WB_fx[128] = /* Q11 */ { -3371, -1712, -170, 350, @@ -34764,7 +34764,7 @@ const Word16 PowerCB_WB_fx[128] = 1238, 2446 }; -const Word16 PowerCB_NB_fx[128] = +const Word16 PowerCB_NB_fx[128] = /* Q11 */ { -3349, -2784, -784, 385, diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 3bf5740f5..993e213b3 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1401,8 +1401,8 @@ extern const Word16 AmpCB2_NB_fx[64 * ( NUM_ERB_NB - 13 )]; extern const float PowerCB_WB[64][2]; extern const float PowerCB_NB[64][2]; -extern const Word16 PowerCB_WB_fx[128]; -extern const Word16 PowerCB_NB_fx[128]; +extern const Word16 PowerCB_WB_fx[128]; // Q11 +extern const Word16 PowerCB_NB_fx[128]; // Q11 extern const float sinc[8][12]; extern const Word16 sinc_fx[8][12]; diff --git a/lib_dec/d_gain2p.c b/lib_dec/d_gain2p.c index bd2366c9a..59b879058 100644 --- a/lib_dec/d_gain2p.c +++ b/lib_dec/d_gain2p.c @@ -42,12 +42,13 @@ #include "rom_com.h" #include "wmc_auto.h" +#ifndef IVAS_FLOAT_FIXED /*--------------------------------------------------------------------------* * Mode2_gain_dec_mless_flt * * Decoding of pitch and codebook gains without updating long term energies *-------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void Mode2_gain_dec_mless_flt( const int16_t index, /* i : index of quantizer */ const float code[], /* i : Innovative code vector */ @@ -132,7 +133,6 @@ static void Mode2_gain_dec_mless_flt( return; } -#endif /*---------------------------------------------------------------------* @@ -140,7 +140,7 @@ static void Mode2_gain_dec_mless_flt( * * Decoding of pitch and codebook gains for Unvoiced mode *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void gain_dec_uv( const int16_t index, /* i/o: Quantization index vector */ const float *code, /* i : algebraic code excitation */ @@ -179,15 +179,13 @@ static void gain_dec_uv( return; } -#endif - /*---------------------------------------------------------------------* * gain_dec_gacelp_uv * * Decoding of pitch and codebook gains for Unvoiced mode *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void gain_dec_gacelp_uv( int16_t index, /* i/o: Quantization index vector */ const float *code, /* i : algebraic code excitation */ @@ -239,15 +237,13 @@ void gain_dec_gacelp_uv( return; } -#endif - /*---------------------------------------------------------------------* * decode_acelp_gains * * *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void decode_acelp_gains( const float *code, const int16_t gains_mode, diff --git a/lib_dec/d_gain2p_fx.c b/lib_dec/d_gain2p_fx.c index b93accc72..fe916acf3 100644 --- a/lib_dec/d_gain2p_fx.c +++ b/lib_dec/d_gain2p_fx.c @@ -17,18 +17,19 @@ * private functions * *********************/ static Word32 calc_gcode0_fx( - Word16 *gcode0, - Word16 *exp_gcode0 ) + Word16 *gcode0, // Q8 + Word16 *exp_gcode0 // Q0 +) { Word32 L_tmp; /*gcode0 = (float)pow(10.0,(gcode0)*0.05);*/ /* predicted gain */ - L_tmp = L_mult( *gcode0, 5443 /*0.166096f Q15*/ ); - *exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); + L_tmp = L_mult( *gcode0, 5443 /*0.166096f Q15*/ ); // Q24 + *exp_gcode0 = add( 1, extract_l( L_shr( L_tmp, 24 ) ) ); // Q0 move16(); - L_tmp = L_lshl( L_tmp, 7 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_lshl( L_tmp, 7 ); // Q31 + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF-> 1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); *gcode0 = round_fx( L_tmp ); @@ -81,7 +82,6 @@ static void Mode2_gain_dec_mless_fx( /**gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode);*/ L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); - move16(); #ifdef BASOP_NOGLOB *gain_inov = round_fx_sat( L_shl_sat( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ #else @@ -176,9 +176,8 @@ static void gain_dec_uv_fx( *-----------------------------------------------------------------*/ /* *gain_inov = 1.0f / (float)sqrt( ( dot_product( code, code, lcode ) + 0.01f ) / lcode );*/ L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); - move16(); *gain_inov = round_fx( L_shl( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ - + move16(); /*-----------------------------------------------------------------* * Decode pitch gain *-----------------------------------------------------------------*/ @@ -192,7 +191,7 @@ static void gain_dec_uv_fx( L_tmp = L_mac( -167197708l /*-0.166096*30.0f Q25*/, shl( index, 16 - 7 ), 10341 /*0.166096f*1.9f Q15*/ ); i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); L_tmp = L_lshl( L_tmp, 6 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF ->1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); L_tmp = L_shl( L_tmp, sub( i, ( 31 - 16 ) ) ); /* Q16 */ @@ -290,7 +289,7 @@ static void gain_dec_gacelp_uv_fx( * past gains for error concealment *-----------------------------------------------------------------*/ index2 = shr( index, 5 ); - index = s_and( index, 0x1F ); + index = s_and( index, 0x1F ); // 0x1F -> 31 /**gain_code= (float)pow(10.f,(((index*1.25f)-20.f)/20.f))*gcode;*/ @@ -298,10 +297,10 @@ static void gain_dec_gacelp_uv_fx( i = add( 1, extract_l( L_shr( L_tmp, 25 ) ) ); L_tmp = L_lshl( L_tmp, 6 ); - L_tmp = L_and( 0x7FFFFFFF, L_tmp ); + L_tmp = L_and( 0x7FFFFFFF, L_tmp ); // 0x7FFFFFFF-> 1 in Q31 L_tmp = Pow2( 30, round_fx( L_tmp ) ); - L_tmp = L_shl( L_tmp, i - ( 31 - 16 ) ); /* Q16 */ + L_tmp = L_shl( L_tmp, sub( i, ( 31 - 16 ) ) ); /* Q16 */ /* *past_gcode = L_tmp * pred_nrg_frame; */ i = norm_l( L_tmp ); @@ -421,10 +420,10 @@ void d_gain_pred_fx( move16(); } - if ( GT_16( nrg_mode, 2 ) ) + IF( GT_16( nrg_mode, 2 ) ) { - move16(); *Es_pred = extract_l( L_mac( -335544320l /* -20.f Q24*/, indice, 224 /* 1.75f Q7*/ ) ); /*(Q8 - ((Q0*Q7)=Q8))*/ + move16(); } return; diff --git a/lib_dec/dec4t64.c b/lib_dec/dec4t64.c index 9563ac643..90e870436 100644 --- a/lib_dec/dec4t64.c +++ b/lib_dec/dec4t64.c @@ -41,12 +41,11 @@ #include "ivas_prot.h" #include "rom_com.h" #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void add_pulses( const int16_t pos[], const int16_t nb_pulse, const int16_t track, float code[] ); static void dec_1p_N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void dec_2p_2N1( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); @@ -56,7 +55,6 @@ static void dec_4p_4N( const int32_t index, const int16_t N, const int16_t offse static void dec_5p_5N( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void dec_6p_6N2( const int32_t index, const int16_t N, const int16_t offset, int16_t pos[] ); static void fcb_decode_PI( int32_t code_index, int16_t sector_6p[], const int16_t pulse_num ); -#endif /*----------------------------------------------------------------------------------* * dec_acelp_4t64() @@ -73,7 +71,6 @@ static void fcb_decode_PI( int32_t code_index, int16_t sector_6p[], const int16_ * See cod4t64.c for more details of the algebraic code. *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void dec_acelp_4t64( Decoder_State *st, /* i/o: decoder state structure */ int16_t nbbits, /* i : number of bits per codebook */ @@ -264,7 +261,6 @@ void dec_acelp_4t64( return; } -#endif /*-------------------------------------------------------* * add_pulses() @@ -272,7 +268,6 @@ void dec_acelp_4t64( * Add decoded pulses to the codeword *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void add_pulses( const int16_t pos[], /* i : pulse position */ const int16_t nb_pulse, /* i : nb. of pulses */ @@ -297,14 +292,13 @@ static void add_pulses( return; } -#endif /*-------------------------------------------------------* * dec_1p_N1() * * Decode 1 pulse with N+1 bits *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void dec_1p_N1( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -377,8 +371,6 @@ void dec_2p_2N1( return; } -#endif - /*-------------------------------------------------------* * dec_3p_3N1() @@ -386,7 +378,6 @@ void dec_2p_2N1( * Decode 3 pulses with 3*N+1 bits: *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void dec_3p_3N1( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -534,14 +525,13 @@ static void dec_5p_5N( return; } -#endif /*-------------------------------------------------------* * dec_6p_6N2() * * Decode 6 pulses with 6*N+2 bits: *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void dec_6p_6N2( const int32_t index, /* i : quantization index */ const int16_t N, /* i : nb. of bits */ @@ -697,7 +687,7 @@ static void fcb_decode_position( return; } -#endif + /*---------------------------------------------------------------------* * fcb_decode_PI() @@ -706,7 +696,7 @@ static void fcb_decode_position( *---------------------------------------------------------------------*/ /*! r: return pulse position number */ -#ifndef IVAS_FLOAT_FIXED + static void fcb_decode_PI( int32_t code_index, /* i : fcb index information */ int16_t sector_6p[], /* o : decoded pulse position */ @@ -746,13 +736,12 @@ static void fcb_decode_PI( return; } -#endif + /*---------------------------------------------------------------------* * Read FCB index * *---------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED void D_ACELP_decode_43bit( uint16_t idxs[], float code[], @@ -788,7 +777,6 @@ void D_ACELP_decode_43bit( return; } -#endif /*-------------------------------------------------------* * dec_1p_N1() @@ -796,7 +784,6 @@ void D_ACELP_decode_43bit( * Decode 1 pulse with N+1 bits *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED static void dec_1p_N1_L_subfr( const int32_t index, /* i : quantization index */ const int16_t nb_pos, /* i : number of positions */ @@ -820,7 +807,6 @@ static void dec_1p_N1_L_subfr( return; } -#endif /*-------------------------------------------------------* * add_pulses() @@ -828,7 +814,7 @@ static void dec_1p_N1_L_subfr( * Add decoded pulses to the codeword *-------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + static void add_pulses_L_subfr( const int16_t nb_pos, /* i : number of positions */ const int16_t pos[], /* i : pulse position */ @@ -854,14 +840,13 @@ static void add_pulses_L_subfr( return; } -#endif /*----------------------------------------------------------------------------------* * dec_acelp_fast() * * fast algebraic codebook decoder *----------------------------------------------------------------------------------*/ -#ifndef IVAS_FLOAT_FIXED + void dec_acelp_fast( Decoder_State *st, /* i/o: decoder state structure */ const int16_t cdk_index, /* i : codebook index */ diff --git a/lib_dec/dec4t64_fx.c b/lib_dec/dec4t64_fx.c index 517b4f0b2..32774bd8e 100644 --- a/lib_dec/dec4t64_fx.c +++ b/lib_dec/dec4t64_fx.c @@ -244,7 +244,7 @@ static void add_pulses_fx( const Word16 pos[], /* i: pulse position */ const Word16 nb_pulse, /* i: nb. of pulses */ const Word16 track, /* i: no. of the tracks */ - Word16 code[] /* i/o: decoded codevector */ + Word16 code[] /* i/o: decoded codevector Q9*/ ) { @@ -690,17 +690,17 @@ static void fcb_decode_position_fx( FOR( i = 0; i < pos_num - 1; i++ ) { /* k = PI_select_table[16-l][temp] - k ;*/ - k = L_sub( PI_select_table[L_sub( 16, l )][temp], k ); + k = L_sub( PI_select_table[( 16 - l )][temp], k ); - FOR( ; PI_select_table[L_sub( 16, l )][temp] >= k; l += 2 ); + FOR( ; PI_select_table[( 16 - l )][temp] >= k; l += 2 ); - IF( GT_32( k, PI_select_table[L_sub( 17, l )][temp] ) ) + IF( GT_32( k, PI_select_table[( 17 - l )][temp] ) ) { l = L_sub( l, 1 ); } /* k = PI_select_table[17-l][temp--] - k ;*/ - k = L_sub( PI_select_table[L_sub( 17, l )][temp], k ); + k = L_sub( PI_select_table[( 17 - l )][temp], k ); temp = sub( temp, 1 ); pos_vector[i] = extract_l( L_sub( l, 1 ) ); move16(); @@ -1067,7 +1067,7 @@ static void add_pulses_L_subfr_fx( const Word16 pos[], /* i : pulse position */ const Word16 nb_pulse, /* i : nb. of pulses */ const Word16 track, /* i : no. of the tracks */ - Word16 code[] /* i/o: decoded codevector */ + Word16 code[] /* i/o: decoded codevector Q12 */ ) { Word16 i, k; @@ -1095,7 +1095,7 @@ static void add_pulses_L_subfr_fx( void dec_acelp_fast_fx( Decoder_State *st, /* i/o: decoder state structure */ const Word16 cdk_index, /* i : codebook index */ - Word16 code[], /* o : algebraic (fixed) codebook excitation */ + Word16 code[], /* o : algebraic (fixed) codebook excitation Q9*/ const Word16 L_subfr /* i : subframe length */ ) { @@ -1204,19 +1204,19 @@ void dec_acelp_fast_fx( i0 = shl( s_and( shr( index, 7 ), ( NB_POS_FCB_2T_128 - 1 ) ), 1 ); i1 = add( shl( s_and( index, ( NB_POS_FCB_2T_128 - 1 ) ), 1 ), 1 ); - code[i0] = -512; + code[i0] = -512; //-1 in Q9 move16(); IF( EQ_16( s_and( index, 0x2000 ), 0 ) ) { - code[i0] = 512; + code[i0] = 512; // 1 in Q9 move16(); } - code[i1] = -512; + code[i1] = -512; //-1 in Q9 move16(); IF( EQ_16( s_and( index, 0x40 ), 0 ) ) { - code[i1] = 512; + code[i1] = 512; // 1 in Q9 move16(); } } diff --git a/lib_dec/dec_LPD_fx.c b/lib_dec/dec_LPD_fx.c index 7a8abdd83..8e65aaa8e 100644 --- a/lib_dec/dec_LPD_fx.c +++ b/lib_dec/dec_LPD_fx.c @@ -27,12 +27,12 @@ void decoder_LPD_fx( Word16 signal_outFB[], /* o : synthesis @output_FS */ Word16 *total_nbbits, /* i/o: number of bits / decoded bits */ Decoder_State *st, /* i/o: decoder memory state pointer */ - Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer Q0 */ Word16 bfi, /* i : BFI flag */ Word16 *bitsRead, /* o : number of read bits */ Word16 param[], /* o : buffer of parameters */ - Word16 *pitch_buf, /* i/o: floating pitch values for each subfr*/ - Word16 *voice_factors, /* o : voicing factors */ + Word16 *pitch_buf, /* i/o: floating pitch values for each subfr Q6*/ + Word16 *voice_factors, /* o : voicing factors Q15*/ Word16 *ptr_bwe_exc /* o : excitation for SWB TBE */ ) { @@ -171,11 +171,12 @@ void decoder_LPD_fx( move16(); st->flagGuidedAcelp = 0; move16(); - st->nbLostCmpt++; + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); move16(); st->core_brate = st->last_core_brate; move16(); st->core = GetPLCModeDecision_fx( st ); + move16(); } } ELSE @@ -285,7 +286,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && LT_32( lsp_diff, 52428 ) && GT_32( lsp_diff, 3932 ) && EQ_16( st->next_coder_type, GENERIC ) && !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && GE_16( st->rf_frame_type, RF_GENPRED ) ) { Copy( &lsp[0], &lsp[M], M ); } @@ -300,7 +301,7 @@ void decoder_LPD_fx( Copy( &lsf[( k + 1 ) * M], &xsfnew_uw[k * M], M ); } } - ELSE IF( ( hTcxDec->enableTcxLpc != 0 && NE_16( st->core, ACELP_CORE ) ) || ( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) + ELSE IF( ( hTcxDec->enableTcxLpc != 0 && ( st->core != ACELP_CORE ) ) || ( bfi && st->use_partial_copy && EQ_16( st->rf_frame_type, RF_TCXFD ) ) ) { Word16 tcx_lpc_cdk; test(); @@ -350,7 +351,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( EQ_16( st->prev_use_partial_copy, 1 ) && EQ_16( st->last_core, ACELP_CORE ) && EQ_16( st->core, ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) + IF( EQ_16( st->prev_use_partial_copy, 1 ) && ( st->last_core == ACELP_CORE ) && ( st->core == ACELP_CORE ) && GE_16( st->prev_rf_frame_type, RF_GENPRED ) && EQ_16( st->coder_type, UNVOICED ) ) { test(); IF( st->lpcQuantization && st->acelp_cfg.midLpc ) @@ -376,11 +377,11 @@ void decoder_LPD_fx( FOR( i = 0; i < M; i++ ) { move16(); - st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[add( imult1616( k, M ), i )], 10923 /*1.0f/3.0f Q15*/ ) ); + st->lsf_adaptive_mean_fx[i] = add( add( mult_r( st->lsfoldbfi1_fx[i], 10923 /*1.0f/3.0f Q15*/ ), mult_r( st->lsfoldbfi0_fx[i], 10923 /*1.0f/3.0f Q15*/ ) ), mult_r( xsfnew_uw[( k * M ) + i], 10923 /*1.0f/3.0f Q15*/ ) ); move16(); st->lsfoldbfi1_fx[i] = st->lsfoldbfi0_fx[i]; move16(); - st->lsfoldbfi0_fx[i] = xsfnew_uw[add( imult1616( k, M ), i )]; + st->lsfoldbfi0_fx[i] = xsfnew_uw[( k * M ) + i]; } } } @@ -414,20 +415,20 @@ void decoder_LPD_fx( FOR( k = 0; k < st->numlpc; k++ ) { - Copy( &xsfnew_uw[k * M], &lsf[add( k, 1 ) * M], M ); + Copy( &xsfnew_uw[k * M], &lsf[( k + 1 ) * M], M ); IF( st->tcxonly ) { - E_LPC_lsf_lsp_conversion( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M ); + E_LPC_lsf_lsp_conversion( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M ); E_LPC_lsf_lsp_conversion( st->lsf_q_cng, st->lsp_q_cng, M ); } ELSE { - lsf2lsp_fx( &lsf[add( k, 1 ) * M], &lsp[add( k, 1 ) * M], M, st->sr_core ); + lsf2lsp_fx( &lsf[( k + 1 ) * M], &lsp[( k + 1 ) * M], M, st->sr_core ); lsf2lsp_fx( st->lsf_q_cng, st->lsp_q_cng, M, st->sr_core ); } - Copy( &lsp[add( k, 1 ) * M], &xspnew_uw[imult1616( k, M )], M ); + Copy( &lsp[( k + 1 ) * M], &xspnew_uw[( k * M )], M ); } } @@ -448,14 +449,14 @@ void decoder_LPD_fx( IF( st->enablePlcWaveadjust ) { - if ( EQ_16( st->core, ACELP_CORE ) ) + if ( ( st->core == ACELP_CORE ) ) { st->tonality_flag = 0; move16(); } if ( bfi ) { - st->plcInfo.nbLostCmpt++; + st->plcInfo.nbLostCmpt = add( st->plcInfo.nbLostCmpt, 1 ); move16(); } } @@ -485,6 +486,7 @@ void decoder_LPD_fx( IF( bfi == 0 ) { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); + move16(); } test(); @@ -537,7 +539,7 @@ void decoder_LPD_fx( test(); test(); test(); - if ( EQ_16( st->clas_dec, UNVOICED_CLAS ) || EQ_16( st->clas_dec, SIN_ONSET ) || EQ_16( st->clas_dec, INACTIVE_CLAS ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) + if ( ( st->clas_dec == UNVOICED_CLAS ) || EQ_16( st->clas_dec, SIN_ONSET ) || EQ_16( st->clas_dec, INACTIVE_CLAS ) || EQ_16( st->coder_type, GENERIC ) || EQ_16( st->coder_type, TRANSITION ) ) { st->relax_prev_lsf_interp = 1; move16(); @@ -565,7 +567,7 @@ void decoder_LPD_fx( } test(); - IF( bfi != 0 && NE_16( st->last_core, ACELP_CORE ) ) + IF( bfi != 0 && ( st->last_core != ACELP_CORE ) ) { /* PLC: [TCX: TD PLC] */ #ifdef IVAS_CODE_CNG_FIX185_PLC_FADEOUT @@ -616,8 +618,8 @@ void decoder_LPD_fx( { move16(); move16(); - st->mem_pitch_gain[sub( add( 2, ( sub( shl( st->nb_subfr, 1 ), 1 ) ) ), i )] = st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )]; - st->mem_pitch_gain[sub( add( 2, sub( st->nb_subfr, 1 ) ), i )] = pit_gain[i]; + st->mem_pitch_gain[2 + ( 2 * st->nb_subfr - 1 ) - i] = st->mem_pitch_gain[( ( 2 + ( st->nb_subfr - 1 ) ) - i )]; + st->mem_pitch_gain[2 + ( st->nb_subfr - 1 ) - i] = pit_gain[i]; } } } @@ -662,10 +664,12 @@ void decoder_LPD_fx( IF( st->tcxonly != 0 ) { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, L_FRAME ); + move16(); } ELSE { st->stab_fac_fx = lsf_stab_fx( &lsf[M], &lsf[0], 0, st->L_frame ); + move16(); } } @@ -724,16 +728,17 @@ void decoder_LPD_fx( /* Stability Factor */ IF( bfi == 0 ) { - st->stab_fac_fx = lsf_stab_fx( &lsf[( add( k, 1 ) ) * M], &lsf[k * M], 0, L_FRAME ); + st->stab_fac_fx = lsf_stab_fx( &lsf[( ( k + 1 ) ) * M], &lsf[k * M], 0, L_FRAME ); + move16(); } - E_LPC_f_lsp_a_conversion( &lsp[( add( k, 1 ) ) * M], Aq, M ); + E_LPC_f_lsp_a_conversion( &lsp[( ( k + 1 ) ) * M], Aq, M ); /* TCX decoder */ IGFDecRestoreTCX10SubFrameData( st->hIGFDec, k ); decoder_tcx_fx( st->hTcxCfg, prm, Aq, Aind, shr( L_frame, 1 ), shr( L_frameTCX, 1 ), - shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[shr( imult1616( k, L_frame ), 1 )], &synthFB[shr( imult1616( k, L_frameTCX ), 1 )], st, st->coder_type, bfi, k, st->stab_fac_fx ); + shr( st->hTcxCfg->tcx_coded_lines, 1 ), &synth[k * L_frame / 2], &synthFB[k * L_frameTCX / 2], st, st->coder_type, bfi, k, st->stab_fac_fx ); } } @@ -756,7 +761,7 @@ void decoder_LPD_fx( test(); test(); test(); - IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( EQ_16( st->plcInfo.concealment_method, TCX_NONTONAL ) ) ) + IF( ( bfi || st->prev_bfi ) && st->plcInfo.Pitch_fx && ( ( st->plcInfo.concealment_method == TCX_NONTONAL ) ) ) { lerp( synthFB, synth, L_frame, L_frameTCX ); test(); @@ -917,6 +922,7 @@ void decoder_LPD_fx( } /* use latest LPC set */ st->old_enr_LP = Enr_1_Az_fx( Aq + offset, L_SUBFR ); /*Q3*/ + move16(); } @@ -1001,7 +1007,7 @@ void decoder_LPD_fx( { if ( !bfi ) { - st->plcInfo.nbLostCmpt = extract_l( L_deposit_l( 0 ) ); + st->plcInfo.nbLostCmpt = 0; move16(); } diff --git a/lib_dec/dec_ace_fx.c b/lib_dec/dec_ace_fx.c index 1ba8222ea..81f2f14fd 100644 --- a/lib_dec/dec_ace_fx.c +++ b/lib_dec/dec_ace_fx.c @@ -22,15 +22,15 @@ void decoder_acelp_fx( Decoder_State *st, Word16 prm[], /* i : parameters */ Word16 A[], /* i : coefficients NxAz[M+1] */ - ACELP_config acelp_cfg, /* i : ACELP config */ + ACELP_config acelp_cfg, /* i : ACELP config Q12 */ Word16 synth[], /* i/o: synth[-2*LFAC..L_DIV] Q0 */ Word16 *pT, /* o : pitch for all subframe Q0 */ Word16 *pgainT, /* o : pitch gain for all subfr 1Q14 */ Word16 stab_fac, /* i : stability of isf */ - Word16 *pitch_buffer, /* o : pitch values for each subfr. */ - Word16 *voice_factors, /* o : voicing factors */ + Word16 *pitch_buffer, /* o : pitch values for each subfr. Q6 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ const Word16 LSF_Q_prediction, /* i : LSF prediction mode */ - Word16 *bwe_exc /* o : excitation for SWB TBE */ + Word16 *bwe_exc /* o : excitation for SWB TBE Q_exc */ ) { Word16 i, j, i_subfr; @@ -46,7 +46,7 @@ void decoder_acelp_fx( Word32 pitch_buf[NB_SUBFR16k]; Word16 dummy_pitch_buf[NB_SUBFR16k]; Word16 gain_inov; - Word16 mem_back[M]; + Word16 mem_back[M]; // Q_mem_back Word16 update_flg; Word16 Q_mem_back; /*Q format of mem_back*/ Word16 h1[L_FRAME_16k / 4 + 1]; @@ -61,9 +61,12 @@ void decoder_acelp_fx( /*Q formats of buffers */ Word16 prev_Q_syn; Word32 gain_code2 = 0; + move32(); Word16 code2[L_SUBFR]; Word16 error = 0; - Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 gain_preQ = 0; /* Gain of prequantizer excitation */ + move16(); Word16 code_preQ[L_SUBFR]; /* Prequantizer excitation */ Word16 lp_flag; @@ -96,6 +99,8 @@ void decoder_acelp_fx( move16(); move16(); move16(); + move16(); + move16(); gain_pit = 0; gain_code = 0; move16(); @@ -106,7 +111,9 @@ void decoder_acelp_fx( gain_code2 = 0; prev_gain_pit = 0; + move16(); tmp_noise = 0; + move16(); IF( EQ_16( st->nb_subfr, 4 ) ) { @@ -132,14 +139,16 @@ void decoder_acelp_fx( weights[3] = 8738 /*(float)4/15 Q15*/; weights[4] = 10923 /*float)5/15 Q15*/; } - st->Mode2_lp_gainp = L_deposit_l( 0 ); - st->Mode2_lp_gainc = L_deposit_l( 0 ); + st->Mode2_lp_gainp = 0; + move32(); + st->Mode2_lp_gainc = 0; + move32(); avoid_lpc_burst_on_recovery = 0; move16(); test(); test(); - IF( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) + if ( st->last_con_tcx && ( NE_16( st->L_frameTCX_past, st->L_frame ) ) && ( st->last_core != 0 ) ) { avoid_lpc_burst_on_recovery = 1; move16(); @@ -152,9 +161,10 @@ void decoder_acelp_fx( /* Reset phase dispersion */ - IF( GT_16( st->last_core_bfi, ACELP_CORE ) ) + IF( st->last_core_bfi > ACELP_CORE ) { - st->dm_fx.prev_gain_code = L_deposit_l( 0 ); + st->dm_fx.prev_gain_code = 0; + move32(); set16_fx( st->dm_fx.prev_gain_pit, 0, 6 ); st->dm_fx.prev_state = 0; move16(); @@ -179,11 +189,11 @@ void decoder_acelp_fx( IF( LT_16( st->old_enr_LP, enr_LP ) ) { ratio = div_s( st->old_enr_LP, enr_LP ); /* Q15 */ - IF( LT_16( ratio, 26215 ) ) + IF( LT_16( ratio, 26215 /*.8f in Q15*/ ) ) { FOR( i = 0; i < L_EXC_MEM_DEC; i++ ) { - st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); + st->old_exc_fx[i] = mult_r( st->old_exc_fx[i], ratio ); // Q_exc move16(); } } @@ -203,7 +213,7 @@ void decoder_acelp_fx( exc = exc_buf + L_EXC_MEM_DEC; Copy( st->old_exc_fx, exc_buf, L_EXC_MEM_DEC ); *( exc + st->L_frame ) = 0; - + move16(); /* Init syn buffer */ syn = syn_buf + M; Copy( st->mem_syn2_fx, syn_buf, M ); @@ -212,7 +222,7 @@ void decoder_acelp_fx( * Fast recovery flag *------------------------------------------------------------------------*/ test(); - IF( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) + if ( st->prev_bfi && EQ_16( st->coder_type, VOICED ) ) { /*Force BPF to be applied fully*/ st->bpf_gain_param = 3; @@ -277,7 +287,7 @@ void decoder_acelp_fx( *-------------------------------------------------------*/ test(); - IF( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 ) + if ( EQ_16( st->use_partial_copy, 1 ) && st->acelp_cfg.gains_mode[idx] == 0 ) { gain_pit = prev_gain_pit; move16(); @@ -338,7 +348,7 @@ void decoder_acelp_fx( move16(); T0_res = 1; move16(); - pitch_buf[idx] = L_deposit_h( L_SUBFR ); + pitch_buf[idx] = L_deposit_h( L_SUBFR ); // Q16 move32(); } @@ -347,7 +357,7 @@ void decoder_acelp_fx( tbe_celp_exc( st->L_frame, i_subfr, T0, T0_frac, &error, bwe_exc ); } - pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); + pitch_buffer[idx] = shl( add( shl( T0, 2 ), T0_frac ), 4 ); // Q6 move16(); /*-------------------------------------------------------* @@ -386,7 +396,8 @@ void decoder_acelp_fx( } ELSE { - gain_code2 = L_deposit_l( 0 ); + gain_code2 = 0; + move32(); set16_fx( code2, 0, L_SUBFR ); } @@ -398,14 +409,16 @@ void decoder_acelp_fx( decode_acelp_gains_fx( code, acelp_cfg.gains_mode[idx], Es_pred, &gain_pit, &gain_code, &prm, &( st->past_gpit ), &( st->past_gcode ), &gain_inov, L_SUBFR, code2, &gain_code2 ); } - IF( st->use_partial_copy && st->rf_frame_type == RF_ALLPRED ) + test(); + if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_ALLPRED ) ) { st->past_gcode = 0; move32(); } - IF( st->use_partial_copy && st->rf_frame_type == RF_NOPRED ) + test(); + if ( st->use_partial_copy && EQ_16( st->rf_frame_type, RF_NOPRED ) ) { - st->past_gpit = 67; + st->past_gpit = 67; //.004089f in Q14 move32(); } IF( st->igf != 0 ) @@ -449,21 +462,36 @@ void decoder_acelp_fx( * - Find the total excitation. * *-------------------------------------------------------*/ gain_code_tmp = gain_code; + move32(); gain_pit_tmp = gain_pit; - IF( i_subfr == 0 ) + move16(); + if ( i_subfr == 0 ) { gain_code_pre = 0; + move32(); } - IF( EQ_16( st->core, ACELP_CORE ) && EQ_16( st->last_core, ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) + test(); + test(); + test(); + IF( ( st->core == ACELP_CORE ) && ( st->last_core == ACELP_CORE ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - IF( i_subfr > 0 && GT_16( gain_pit, 20152 ) && GT_16( st->prev_tilt_code_dec_fx, 6553 ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( i_subfr > 0 && GT_16( gain_pit, 20152 /*1.23 in Q14*/ ) && GT_16( st->prev_tilt_code_dec_fx, 6553 /*1.23 in Q15*/ ) && EQ_16( st->next_coder_type, VOICED ) && ( EQ_16( st->use_partial_copy, 1 ) || EQ_16( st->prev_use_partial_copy, 1 ) ) ) { - gain_pit = mult( gain_pit, sub( 26214, mult( i_subfr, 51 ) ) ); + gain_pit = mult( gain_pit, sub( 26214 /*.8f in Q15*/, mult( i_subfr, 51 /*1.0f/640 in Q15*/ ) ) ); } ELSE IF( !st->prev_use_partial_copy && EQ_16( st->last_coder_type, UNVOICED ) && NE_16( st->next_coder_type, UNVOICED ) && LT_32( gain_code, gain_code_pre ) ) { gain_code = 0; + move32(); } } gain_code_pre = gain_code; @@ -475,17 +503,18 @@ void decoder_acelp_fx( tmp2 = shr( L_SUBFR, 1 ); FOR( j = 0; j < 2; j++ ) { - FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) + FOR( i = ( tmp2 - ( L_SUBFR / 2 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14, gain_code in Q16; exc Q_new */ Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); Ltmp = L_shl( Ltmp, add( 5, st->Q_exc ) ); Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); #ifdef BASOP_NOGLOB - exc2[add( i, i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); + exc2[( i + i_subfr )] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); #else exc2[i + i_subfr] = round_fx( L_shl( Ltmp, 1 ) ); #endif + move16(); Ltmp2 = Mpy_32_16_1( gain_code, code[i] ); Ltmp2 = L_shl( Ltmp2, add( 5, st->Q_exc ) ); Ltmp = L_add( Ltmp, Ltmp2 ); @@ -497,10 +526,11 @@ void decoder_acelp_fx( #endif BASOP_SATURATE_WARNING_ON_EVS #ifdef BASOP_NOGLOB - exc[add( i, i_subfr )] = round_fx_sat( Ltmp ); + exc[( i + i_subfr )] = round_fx_sat( Ltmp ); #else exc[i + i_subfr] = round_fx( Ltmp ); #endif + move16(); } tmp2 = L_SUBFR; move16(); @@ -556,7 +586,7 @@ void decoder_acelp_fx( * - update pitch lag for guided ACELP * *----------------------------------------------------------*/ test(); - IF( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) + if ( st->enableGplc && EQ_16( shr( i_subfr, 6 ), sub( st->nb_subfr, 1 ) ) ) { st->T0_4th = T0; move16(); @@ -611,8 +641,10 @@ void decoder_acelp_fx( /* impulse response level = gain introduced by synthesis+deemphasis */ Ltmp = Dot_productSq16HQ( 0, h1, L_SUBFR, &st->last_gain_syn_deemph_e ); st->last_gain_syn_deemph_e = add( st->last_gain_syn_deemph_e, 10 /*scaling of h1[0] and E_UTIL_synthesis * 2*/ ); + move16(); #ifdef BASOP_NOGLOB - st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); + st->last_gain_syn_deemph = round_fx_sat( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); // Q(15-last_gain_syn_deemph_e - (16)) + move16(); #else st->last_gain_syn_deemph = round_fx( Sqrt32( Ltmp, &st->last_gain_syn_deemph_e ) ); #endif @@ -660,14 +692,14 @@ void decoder_acelp_fx( move16(); } - Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); + Scale_sig( mem_back, M, sub( st->Q_syn, Q_mem_back ) ); // Q_syn force_scale_syn = 0; move16(); + test(); test(); - test(); - IF( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) ) + if ( ( EQ_16( st->clas_dec, ONSET ) ) || ( ( GE_16( st->last_good, VOICED_TRANSITION ) ) && ( LT_16( st->last_good, INACTIVE_CLAS ) ) ) ) { force_scale_syn = 1; move16(); @@ -704,11 +736,12 @@ void decoder_acelp_fx( FOR( i_subfr = 0; i_subfr < st->L_frame; i_subfr += L_SUBFR ) { Word16 idx = 0; + move16(); IF( i_subfr != 0 ) { idx = idiv1616( i_subfr, L_SUBFR ); } - *pT++ = round_fx( pitch_buf[idx] ); + *pT++ = round_fx( pitch_buf[idx] ); // Q0 } @@ -721,8 +754,10 @@ void decoder_acelp_fx( move16(); hTcxDec->tcxltp_third_last_pitch = hTcxDec->tcxltp_second_last_pitch; + move32(); hTcxDec->tcxltp_second_last_pitch = st->old_fpitch; - st->old_fpitch = pitch_buf[sub( shr( st->L_frame, 6 ), 1 )]; + move32(); + st->old_fpitch = pitch_buf[( ( st->L_frame >> 6 ) - 1 )]; move32(); diff --git a/lib_dec/dec_acelp_fx.c b/lib_dec/dec_acelp_fx.c index 8379eec7e..f65ee4bf7 100644 --- a/lib_dec/dec_acelp_fx.c +++ b/lib_dec/dec_acelp_fx.c @@ -24,7 +24,7 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 *---------------------------------------------------------------------*/ void D_ACELP_indexing_fx( - Word16 code[], + Word16 code[], // Q9 PulseConfig config, Word16 num_tracks, Word16 index[], @@ -142,7 +142,7 @@ void D_ACELP_indexing_fx( ELSE { fcb_pulse_track_joint_decode_fx( idxs, wordcnt, index_n, pulsestrack, num_tracks ); - FOR( track = sub( num_tracks, 1 ); track >= 1; track-- ) + FOR( track = ( num_tracks - 1 ); track >= 1; track-- ) { pulses = pulsestrack[track]; move16(); @@ -152,12 +152,13 @@ void D_ACELP_indexing_fx( /* divide by number of possible states: rest is actual state and * the integer part goes to next track */ s = index_n[track]; + move32(); /* decode state to actual pulse positions on track */ D_ACELP_decode_arithtrack_fx( code + track, s, pulses, num_tracks, 16 ); } ELSE /* track is empty */ { - FOR( k = track; k < imult1616( 16, num_tracks ); k += num_tracks ) + FOR( k = track; k < ( 16 * num_tracks ); k += num_tracks ) { code[k] = 0; move16(); @@ -209,12 +210,12 @@ static void D_ACELP_decode_arithtrack_fx( Word16 v[], Word32 s, Word16 p, Word16 FOR( ; p; p-- ) /* one pulse placed, so one less left */ { - IF( LT_32( s, pulsestostates[k][sub( p, 1 )] ) ) + IF( LT_32( s, pulsestostates[k][p - 1] ) ) { BREAK; } - s = L_sub( s, pulsestostates[k][sub( p, 1 )] ); + s = L_sub( s, pulsestostates[k][p - 1] ); IF( v[idx] != 0 ) /* there is a pulse here already = sign is known */ { @@ -271,7 +272,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[4] = 1; move16(); - IF( GE_16( indx_flag, track_num ) ) + if ( GE_16( indx_flag, track_num ) ) { hi_to_low[4] = 9; move16(); @@ -279,7 +280,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in hi_to_low[7] = 1; move16(); - IF( GE_16( indx_flag_2, 1 ) ) + if ( GE_16( indx_flag_2, 1 ) ) { hi_to_low[7] = 9; move16(); @@ -289,7 +290,8 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in { IF( GE_16( indx_flag, track_num ) ) { - index = L_deposit_l( 0 ); + index = 0; + move32(); IF( GE_16( indx_flag_2, 1 ) ) { FOR( track = sub( wordcnt, 1 ); track >= 6; track-- ) @@ -320,8 +322,9 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in } ELSE { - index = L_deposit_l( 0 ); - FOR( track = sub( wordcnt, 1 ); track >= 2; track-- ) + index = 0; + move32(); + FOR( track = ( wordcnt - 1 ); track >= 2; track-- ) { index = L_add( L_lshl( index, 16 ), (UWord32) idxs[track] ); } @@ -340,7 +343,7 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in pulse_num1 = pulse_num[track_num1]; move16(); index = L_add( L_lshl( index, hi_to_low[pulse_num1] ), L_lshr( index_n[track_num1], low_len[pulse_num1] ) ); - FOR( track = sub( track_num, 1 ); track > 0; track-- ) + FOR( track = ( track_num - 1 ); track > 0; track-- ) { track_num1 = sub( track, 1 ); pulse_num0 = pulse_num[track_num1]; @@ -361,8 +364,9 @@ void fcb_pulse_track_joint_decode_fx( UWord16 *idxs, Word16 wordcnt, UWord32 *in } ELSE { - index = L_deposit_l( 0 ); - FOR( track = sub( wordcnt, 1 ); track >= 0; track-- ) + index = 0; + move32(); + FOR( track = ( wordcnt - 1 ); track >= 0; track-- ) { index = (UWord32) W_add( UL_lshl( index, 16 ), (UWord32) idxs[track] ); } diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index ad7117763..9a14aaf7b 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -56,7 +56,7 @@ static void decode_frame_type_fx( Decoder_State *st { /* ZERO Frame */ - IF( EQ_32( st->total_brate, FRAME_NO_DATA ) ) + IF( ( st->total_brate == FRAME_NO_DATA ) ) { st->bwidth = st->last_bwidth; move16(); @@ -68,7 +68,8 @@ static void decode_frame_type_fx( Decoder_State *st ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) { st->cng_type = get_next_indice( st, 1 ); - IF( NE_16( st->cng_type, FD_CNG ) ) + move16(); + if ( NE_16( st->cng_type, FD_CNG ) ) { st->BER_detect = 1; move16(); @@ -83,7 +84,7 @@ static void decode_frame_type_fx( Decoder_State *st frame_len_indicator = get_next_indice( st, 1 ); IF( EQ_16( st->bwidth, NB ) ) { - IF( frame_len_indicator ) + if ( frame_len_indicator ) { st->BER_detect = 1; move16(); @@ -103,7 +104,7 @@ static void decode_frame_type_fx( Decoder_State *st st->L_frame = L_FRAME16k; move16(); test(); - IF( st->last_total_brate == ACELP_16k40 || st->last_total_brate == ACELP_24k40 ) + IF( EQ_32( st->last_total_brate, ACELP_16k40 ) || EQ_32( st->last_total_brate, ACELP_24k40 ) ) { st->total_brate = st->last_total_brate; move32(); @@ -152,12 +153,15 @@ static void decode_frame_type_fx( Decoder_State *st /* Get bandwidth mode */ st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + move16(); st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); } ELSE { st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); } IF( GT_16( st->bwidth, FB ) ) @@ -184,7 +188,7 @@ static void decode_frame_type_fx( Decoder_State *st Word16 dummyBit; dummyBit = (Word8) get_next_indice( st, 1 ); move16(); - IF( dummyBit != 0 ) + if ( dummyBit != 0 ) { st->BER_detect = 1; move16(); @@ -201,7 +205,7 @@ static void decode_frame_type_fx( Decoder_State *st IF( NE_16( st->last_codec_mode, MODE2 ) || !st->BER_detect ) { /* Mode or Rate Change */ - test(); + test(); test(); IF( ( EQ_16( st->m_frame_type, ACTIVE_FRAME ) || EQ_16( st->m_frame_type, SID_FRAME ) ) && ( s_or( s_or( s_or( s_or( (Word16) NE_32( st->total_brate, st->last_total_brate ), (Word16) NE_16( st->bwidth, st->last_bwidth ) ), (Word16) EQ_16( st->last_codec_mode, MODE1 ) ), (Word16) NE_16( st->rf_flag, st->rf_flag_last ) ), st->force_lpd_reset ) ) ) @@ -229,6 +233,7 @@ static void decode_frame_type_fx( Decoder_State *st IF( EQ_16( st->bwidth, NB ) ) { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); + move16(); } ELSE { @@ -262,7 +267,7 @@ static void decode_frame_type_fx( Decoder_State *st { FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 20480 /*1.25f in Q14*/ ); move16(); } } @@ -270,7 +275,7 @@ static void decode_frame_type_fx( Decoder_State *st { FOR( n = 0; n < shl( st->L_frame, 1 ); n++ ) { - st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 ); + st->hFdCngDec->hFdCngCom->olapBufferSynth[n] = mult_r( shl( st->hFdCngDec->hFdCngCom->olapBufferSynth[n], 1 ), 26214 /* 1/1.25 in Q15*/ ); move16(); } } @@ -301,12 +306,12 @@ static void decode_frame_type_fx( Decoder_State *st Word16 dec_acelp_tcx_frame_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 *concealWholeFrame, /* i/o: concealment flag */ - Word16 *pcmBuf, /* o : synthesis */ - Word16 *bpf_noise_buf, /* i/o: BPF noise buffer */ - Word16 *pcmbufFB, /* o : synthesis @output_FS */ - Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation */ - Word16 *voice_factors, /* o : voicing factors */ - Word16 pitch_buf[] /* o : floating pitch for each subframe */ + Word16 *pcmBuf, /* o : synthesis Q0 */ + Word16 *bpf_noise_buf, /* i/o: BPF noise buffer Qx */ + Word16 *pcmbufFB, /* o : synthesis @output_FS Qx */ + Word32 bwe_exc_extended[], /* i/o: bandwidth extended excitation Q0 */ + Word16 *voice_factors, /* o : voicing factors Q15 */ + Word16 pitch_buf[] /* o : floating pitch for each subframe Q6 */ #ifdef IVAS_CODE_CNG , STEREO_CNG_DEC_HANDLE hStereoCng /* i : stereo CNG handle */ @@ -352,10 +357,15 @@ Word16 dec_acelp_tcx_frame_fx( { Word16 m_frame_type = st->m_frame_type; + move16(); Word16 bwidth = st->bwidth; + move16(); Word16 cng_type = st->cng_type; + move16(); Word16 L_frame = st->L_frame; + move16(); Word32 total_brate = st->last_total_brate; + move32(); decode_frame_type_fx( st #ifdef IVAS_CODE_CNG @@ -383,7 +393,7 @@ Word16 dec_acelp_tcx_frame_fx( move16(); st->L_frame = L_frame; move16(); - IF( st->ini_frame != 0 ) + if ( st->ini_frame != 0 ) { st->total_brate = total_brate; move32(); @@ -398,7 +408,7 @@ Word16 dec_acelp_tcx_frame_fx( test(); test(); - IF( ( NE_16( st->bwidth, st->last_bwidth ) ) || ( NE_16( st->rf_flag, st->rf_flag_last ) ) || ( NE_32( st->total_brate, st->last_total_brate ) ) ) + if ( ( NE_16( st->bwidth, st->last_bwidth ) ) || ( NE_16( st->rf_flag, st->rf_flag_last ) ) || ( NE_32( st->total_brate, st->last_total_brate ) ) ) { st->force_lpd_reset = 1; move16(); @@ -412,6 +422,7 @@ Word16 dec_acelp_tcx_frame_fx( IF( st->ini_frame == 0 && st->hTcxCfg != NULL ) { st->hTcxCfg->tcx_coded_lines = getNumTcxCodedLines( SWB ); + move16(); } } ELSE diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index ea3fa74f5..5e047e425 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -17,12 +17,12 @@ void decod_amr_wb_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ - const Word16 *Aq_fx, /* i : LP filter coefficients */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ + const Word16 *Aq_fx, /* i : LP filter coefficients Q12 */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6*/ + Word16 *exc_fx, /* i/o: adapt. excitation exc Qx */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Qx */ Word16 hf_gain_fx[NB_SUBFR], /* o : decoded HF gain */ - Word16 *voice_factors_fx, /* o : voicing factors */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ Word16 *gain_buf /* o : floating pitch gain for each subframe Q14 */ ) { @@ -50,13 +50,14 @@ void decod_amr_wb_fx( p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ - L_Voice_fac_ave = L_deposit_l( 0 ); + L_Voice_fac_ave = 0; + move32(); pitch_limit_flag = 0; move16(); /* always restrained pitch Q range in IO mode */ lp_flag = NORMAL_OPERATION; move16(); /* always restrained pitch Q range in IO mode */ - IF( LT_32( st_fx->core_brate, ACELP_11k60 ) ) + if ( LT_32( st_fx->core_brate, ACELP_11k60 ) ) { lp_flag = LOW_PASS; move16(); /* always restrained pitch Q range in IO mode */ @@ -77,7 +78,6 @@ void decod_amr_wb_fx( 0, NULL #endif ); - move16(); /*--------------------------------------------------------------* * Find the adaptive codebook vector *--------------------------------------------------------------*/ @@ -139,7 +139,7 @@ void decod_amr_wb_fx( /*voice_fac = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac;*/ L_tmp = L_mult( VF_2nd_PARAM_FX, mult_r( voice_fac_fx, voice_fac_fx ) ); L_tmp = L_mac( L_tmp, VF_1st_PARAM_FX, voice_fac_fx ); - voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); + voice_fac_fx = mac_r( L_tmp, VF_0th_PARAM_FX, 32767 ); // 1.0f in Q15 Word16 idx; idx = 0; @@ -150,17 +150,17 @@ void decod_amr_wb_fx( } /*voice_factors[i_subfr/L_SUBFR] = min( max(0.0f, voice_fac), 1.0f);*/ - voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 ); + voice_factors_fx[idx] = s_min( s_max( 0, voice_fac_fx ), 32767 /*1.0f in Q15*/ ); // Q15 move16(); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; - L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); + L_Voice_fac_ave = L_mac( L_Voice_fac_ave, 8192, voice_fac_fx ); // .25f in Q15 gain_buf[idx] = gain_pit_fx; move16(); } - hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); + hAmrwb_IO->lt_voice_fac_fx = round_fx( L_Voice_fac_ave ); // Q0 move16(); return; diff --git a/lib_dec/dec_gen_voic_fx.c b/lib_dec/dec_gen_voic_fx.c index f5fdb1dea..363c3a2d8 100644 --- a/lib_dec/dec_gen_voic_fx.c +++ b/lib_dec/dec_gen_voic_fx.c @@ -41,34 +41,41 @@ ivas_error decod_gen_voic_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12 */ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *pitch_buf_fx, /* o : floating pitch values for each subframe Q6 */ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ Word16 *unbits, /* number of unused bits */ - Word16 *gain_buf ) + Word16 *gain_buf /*Q14*/ +) { Word16 T0_fx, T0_frac_fx, T0_min_fx, T0_max_fx; /* integer pitch variables */ Word16 gain_pit_fx = 0; /* pitch gain Q14 */ - Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ - Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ - Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ - Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ - Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ - Word16 voice_fac_fx; /* voicing factor Q15 */ - Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ + move16(); + Word32 gain_code_fx = 0; /* gain/normalized gain of the algebraic excitation Q16 */ + move32(); + Word32 norm_gain_code_fx = 0; /* normalized gain of the algebraic excitation Q16 */ + move32(); + Word16 gain_inov_fx = 0; /* Innovation gain Q12 */ + move16(); + Word32 gc_mem[NB_SUBFR - 1]; /* gain_code from previous subframes */ + Word16 gp_mem[NB_SUBFR - 1]; /* gain_pitch from previous subframes */ + Word16 voice_fac_fx; /* voicing factor Q15 */ + Word16 code_fx[L_SUBFR]; /* algebraic codevector Q12 */ const Word16 *p_Aq_fx; /* Pointer to frame LP coefficient Q12 */ Word16 *pt_pitch_fx; /* pointer to floating pitch Q6 */ Word16 i_subfr_fx, i; /* tmp variables */ Word16 error_fx = 0; - Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); + Word16 gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + move16(); Word16 code_preQ_fx[L_SUBFR]; /* Prequantizer excitation */ Word32 norm_gain_preQ_fx; Word16 pitch_limit_flag_fx; @@ -105,14 +112,8 @@ ivas_error decod_gen_voic_fx( MUSIC_POSTFILT_HANDLE hMusicPF; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); hMusicPF = st_fx->hMusicPF; @@ -142,12 +143,10 @@ ivas_error decod_gen_voic_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; - move16(); + move32(); gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -179,7 +178,7 @@ ivas_error decod_gen_voic_fx( *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) { gain_code_fx = 0; move16(); @@ -209,14 +208,14 @@ ivas_error decod_gen_voic_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); + st_fx->tilt_code_fx = est_tilt_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc ); // Q15 move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) { transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } @@ -266,20 +265,21 @@ ivas_error decod_gen_voic_fx( /* Compute exc2 */ #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); // Q_exc+Q14+1+1 + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); + move16(); + /* gain_pit in Q14 */ + L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ + L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+Q15 +1 + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc move16(); #else L_tmp = L_shl( L_tmp, 5 ); @@ -316,7 +316,7 @@ ivas_error decod_gen_voic_fx( *----------------------------------------------------------------*/ test(); - IF( GT_32( st_fx->core_brate, ACELP_32k ) || EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GT_32( st_fx->core_brate, ACELP_32k ) || ( st_fx->coder_type == INACTIVE ) ) { Copy( exc_fx + i_subfr_fx, exc2_fx + i_subfr_fx, L_SUBFR ); } @@ -327,9 +327,8 @@ ivas_error decod_gen_voic_fx( } p_Aq_fx += ( M + 1 ); - move16(); pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; // Q14 move16(); } @@ -371,9 +370,7 @@ ivas_error decod_gen_voic_fx( shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; - move16(); p_syn = syn_tmp_fx + shft_curr; - move16(); curr_res_nrg = L_deposit_l( 1 ); curr_spch_nrg = L_deposit_l( 1 ); @@ -394,22 +391,22 @@ ivas_error decod_gen_voic_fx( IF( prev_res_nrg > 0 ) { expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); - expa = sub( 30, expa + ( 2 * st_fx->prev_Q_exc_fr ) ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr -16+expa +1*/ + expa = sub( 30, add( expa, ( shl( st_fx->prev_Q_exc_fr, 1 ) ) ) ); expb = norm_l( curr_res_nrg ); #ifdef BASOP_NOGLOB - fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); + fracb = round_fx_sat( L_shl_sat( curr_res_nrg, expb ) ); /* 2*st_fx->Q_exc +expb+1 -16*/ #else fracb = round_fx( L_shl( curr_res_nrg, expb ) ); #endif expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - enratio = div_s( fracb, fraca ); + enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qenratio = sub( 15, exp1 ); } @@ -425,22 +422,22 @@ ivas_error decod_gen_voic_fx( IF( prev_spch_nrg > 0 ) { expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr +expa+1-16*/ expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); #ifdef BASOP_NOGLOB - fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); + fracb = round_fx_sat( L_shl_sat( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb-16 */ #else fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); #endif expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb) +scale expb = sub( expb, scale ); - sp_enratio = div_s( fracb, fraca ); + sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qsp_enratio = sub( 15, exp1 ); } @@ -461,7 +458,7 @@ ivas_error decod_gen_voic_fx( LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ + LT_16( pitch_buf_fx[NB_SUBFR16k - 1], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -470,12 +467,12 @@ ivas_error decod_gen_voic_fx( pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) { return error; } @@ -492,14 +489,14 @@ ivas_error decod_gen_voic_fx( ph_offset_fx = 0; move16(); - if ( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc /* update bwe_exc for SWB-TBE */ FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) @@ -551,18 +548,18 @@ ivas_error decod_gen_voic_ivas_fx( Decoder_State *st_fx, /* i/o: decoder static memory */ const Word16 L_frame, /* i : length of the frame */ const Word16 sharpFlag_fx, /* i : formant sharpening flag */ - const Word16 *Aq_fx, /* i : LP filter coefficient */ - const Word16 Es_pred_fx, /* i : predicted scaled innov. energy */ + const Word16 *Aq_fx, /* i : LP filter coefficient Q12*/ + const Word16 Es_pred_fx, /* i : predicted scaled innov. energy Q8 */ const Word16 do_WI_fx, /* i : do interpolation after a FER */ - Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe */ - Word16 *voice_factors_fx, /* o : voicing factors */ - Word16 *exc_fx, /* i/o: adapt. excitation exc */ - Word16 *exc2_fx, /* i/o: adapt. excitation/total exc */ - Word16 *bwe_exc_fx, /* o : excitation for SWB TBE */ + Word16 *pitch_buf_fx, /* o : Word16 pitch values for each subframe Q6*/ + Word16 *voice_factors_fx, /* o : voicing factors Q15 */ + Word16 *exc_fx, /* i/o: adapt. excitation exc Q_exc */ + Word16 *exc2_fx, /* i/o: adapt. excitation/total exc Q_exc */ + Word16 *bwe_exc_fx, /* o : excitation for SWB TBE Q_exc */ Word16 *unbits, /* number of unused bits */ Word16 *gain_buf, const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { @@ -624,11 +621,11 @@ ivas_error decod_gen_voic_ivas_fx( gain_preQ_fx = 0; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif move16(); - move16(); - move16(); - move16(); + move32(); + move32(); move16(); move16(); move16(); @@ -661,12 +658,10 @@ ivas_error decod_gen_voic_ivas_fx( * ACELP subframe loop *------------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - move16(); /* pointer to interpolated LPC parameters */ - pt_pitch_fx = pitch_buf_fx; - move16(); /* pointer to the pitch buffer */ + p_Aq_fx = Aq_fx; /* pointer to interpolated LPC parameters */ + pt_pitch_fx = pitch_buf_fx; /* pointer to the pitch buffer */ norm_gain_preQ_fx = 0; - move16(); + move32(); gain_preQ_fx = 0; move16(); set16_fx( code_preQ_fx, 0, L_SUBFR ); @@ -701,7 +696,7 @@ ivas_error decod_gen_voic_ivas_fx( *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && NE_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && ( st_fx->coder_type != INACTIVE ) ) { gain_code_fx = 0; move16(); @@ -731,14 +726,14 @@ ivas_error decod_gen_voic_ivas_fx( { gain_dec_mless_fx( st_fx, L_frame, st_fx->coder_type, i_subfr_fx, -1, code_fx, Es_pred_fx, &gain_pit_fx, &gain_code_fx, &gain_inov_fx, &norm_gain_code_fx ); } - st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); + st_fx->tilt_code_fx = est_tilt_ivas_fx( exc_fx + i_subfr_fx, gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, st_fx->Q_exc, L_SUBFR, 0 ); // Q15 move16(); /*-----------------------------------------------------------------* * Transform domain contribution decoding *-----------------------------------------------------------------*/ test(); - IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( GE_32( st_fx->total_brate, MAX_GSC_INACTIVE_BRATE ) && ( st_fx->coder_type == INACTIVE ) ) { transf_cdbk_dec_fx( st_fx, harm_flag_acelp, i_subfr_fx, Es_pred_fx, gain_code_fx, &gain_preQ_fx, &norm_gain_preQ_fx, code_preQ_fx, unbits ); } @@ -752,15 +747,31 @@ ivas_error decod_gen_voic_ivas_fx( IF( EQ_16( L_frame, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + IF( ( bwe_exc_fx != NULL ) ) + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * HIBND_ACB_L_FAC], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } + ELSE + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } } ELSE /* Rescaling for 16k core */ { L_tmp_GC = L_max( gain_code_fx, L_shl( gain_preQ_fx, 16 ) ); /* Chose the maximum of gain_code or the prequantizer excitation x4 to keep some room*/ - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[i_subfr_fx * 2] : NULL, hGSCDec->last_exc_dct_in_fx, - L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + IF( bwe_exc_fx != NULL ) + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], &bwe_exc_fx[i_subfr_fx * 2], hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } + ELSE + { + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], NULL, hGSCDec->last_exc_dct_in_fx, + L_SUBFR, L_SUBFR * 2, L_tmp_GC, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, st_fx->coder_type ); + } } gain_code16 = round_fx( L_shl( gain_code_fx, st_fx->Q_exc ) ); /*Q_exc*/ @@ -793,21 +804,20 @@ ivas_error decod_gen_voic_ivas_fx( /* Compute exc2 */ #ifdef BASOP_NOGLOB L_tmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); - exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); - move16(); + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc #else L_tmp = L_shl( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); exc2_fx[i + i_subfr_fx] = round_fx( L_add( L_tmp, Ltmp1 ) ); #endif - - /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gain_code16, code_fx[i] ); + move16(); + /* gain_pit in Q14 */ + L_tmp = L_mult( gain_code16, code_fx[i] ); // Q_exc+Q9+1 #ifdef BASOP_NOGLOB - L_tmp = L_shl_sat( L_tmp, 5 ); - L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); - L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ + L_tmp = L_shl_sat( L_tmp, 5 ); // Q_exc+Q9+1+5 + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); // Q_exc+16 + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here */ - exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( L_tmp, Ltmp1 ) ); // Q_exc move16(); #else L_tmp = L_shl( L_tmp, 5 ); @@ -863,7 +873,7 @@ ivas_error decod_gen_voic_ivas_fx( p_Aq_fx += ( M + 1 ); move16(); pt_pitch_fx++; - gain_buf[idx] = gain_pit_fx; + gain_buf[idx] = gain_pit_fx; // Q14 move16(); } @@ -878,11 +888,11 @@ ivas_error decod_gen_voic_ivas_fx( p_exc = st_fx->hWIDec->old_exc2_fx + shft_prev; p_syn = st_fx->hWIDec->old_syn2_fx + shft_prev; - move16(); - move16(); - prev_res_nrg = L_deposit_l( 1 ); - prev_spch_nrg = L_deposit_l( 1 ); + prev_res_nrg = 1; + move32(); + prev_spch_nrg = 1; + move32(); FOR( i = 0; i < rint_bfi_pitch; i++ ) { #ifdef BASOP_NOGLOB @@ -905,12 +915,12 @@ ivas_error decod_gen_voic_ivas_fx( shft_curr = sub( st_fx->L_frame, rint_pitch ); /*Q0*/ p_exc = exc2_fx + shft_curr; - move16(); p_syn = syn_tmp_fx + shft_curr; - move16(); - curr_res_nrg = L_deposit_l( 1 ); - curr_spch_nrg = L_deposit_l( 1 ); + curr_res_nrg = 1; + move32(); + curr_spch_nrg = 1; + move32(); FOR( i = 0; i < rint_pitch; i++ ) { curr_res_nrg = L_mac0( curr_res_nrg, *p_exc, *p_exc ); /* 2*st_fx->Q_exc */ @@ -923,18 +933,18 @@ ivas_error decod_gen_voic_ivas_fx( IF( prev_res_nrg > 0 ) { expa = norm_l( prev_res_nrg ); - fraca = extract_h( L_shl( prev_res_nrg, expa ) ); + fraca = extract_h( L_shl( prev_res_nrg, expa ) ); /* 2*st_fx->prev_Q_exc_fr +expa -16*/ expa = sub( 30, add( expa, shl( st_fx->prev_Q_exc_fr, 1 ) ) ); expb = norm_l( curr_res_nrg ); - fracb = round_fx( L_shl( curr_res_nrg, expb ) ); + fracb = round_fx( L_shl( curr_res_nrg, expb ) ); /* 2*st_fx->prev_Q_exc_fr +expb -16*/ expb = sub( 30, add( expb, shl( st_fx->Q_exc, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - enratio = div_s( fracb, fraca ); + enratio = div_s( fracb, fraca ); // Q(15-(expb-expa) exp1 = sub( expb, expa ); Qenratio = sub( 15, exp1 ); } @@ -950,18 +960,18 @@ ivas_error decod_gen_voic_ivas_fx( IF( prev_spch_nrg > 0 ) { expa = norm_l( prev_spch_nrg ); - fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); + fraca = extract_h( L_shl( prev_spch_nrg, expa ) ); /* 2*st_fx->prev_Q_syn_fr -16 +expa */ expa = sub( 30, add( expa, shl( st_fx->prev_Q_syn_fr, 1 ) ) ); expb = norm_l( curr_spch_nrg ); - fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); + fracb = round_fx( L_shl( curr_spch_nrg, expb ) ); /* 2*st_fx->Q_syn +expb -16*/ expb = sub( 30, add( expb, shl( st_fx->Q_syn, 1 ) ) ); scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); + fracb = shl( fracb, scale ); // Q(15-expb)+scale expb = sub( expb, scale ); - sp_enratio = div_s( fracb, fraca ); + sp_enratio = div_s( fracb, fraca ); // Q(15-(expb-expa)) exp1 = sub( expb, expa ); Qsp_enratio = sub( 15, exp1 ); } @@ -982,7 +992,7 @@ ivas_error decod_gen_voic_ivas_fx( LT_16( shl_ro( enratio, sub( 10, Qenratio ), &Overflow ), 15360 ) && /*compare with 15.0 in Q10*/ GT_16( shl_ro( sp_enratio, sub( 15, Qsp_enratio ), &Overflow ), 4915 ) && /*compare with 0.15 in Q15*/ LT_16( st_fx->bfi_pitch_fx, 9600 ) && /*Q6*/ - LT_16( pitch_buf_fx[sub( NB_SUBFR16k, 1 )], 9600 ) ) /*Q6*/ + LT_16( pitch_buf_fx[( NB_SUBFR16k - 1 )], 9600 ) ) /*Q6*/ #else IF( GT_16( shl_r( enratio, 15 - Qenratio ), 8192 ) && /*compare with 0.25 in Q15*/ LT_16( shl_r( enratio, 10 - Qenratio ), 15360 ) && /*compare with 15.0 in Q10*/ @@ -991,12 +1001,12 @@ ivas_error decod_gen_voic_ivas_fx( pitch_buf_fx[sub( NB_SUBFR16k, 1 )] < 9600 ) /*Q6*/ #endif { - IF( ( error = DTFS_new_fx( &PREVP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &PREVP ) ), IVAS_ERR_OK ) ) { return error; } - IF( ( error = DTFS_new_fx( &CURRP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = DTFS_new_fx( &CURRP ) ), IVAS_ERR_OK ) ) { return error; } @@ -1013,14 +1023,14 @@ ivas_error decod_gen_voic_ivas_fx( ph_offset_fx = 0; move16(); - IF( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = WIsyn_fx( *PREVP, CURRP, dummy2, &( ph_offset_fx ), out_fx, (Word16) st_fx->L_frame, 1, S_fx, C_fx, pf_temp1, pf_temp2, pf_temp, pf_n2 ) ), IVAS_ERR_OK ) ) { return error; } - Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); - Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); + Copy_Scale_sig( out_fx, exc2_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc + Copy_Scale_sig( out_fx, exc_fx, st_fx->L_frame, st_fx->Q_exc ); // Q_exc /* update bwe_exc for SWB-TBE */ FOR( i_subfr_fx = 0; i_subfr_fx < L_frame; i_subfr_fx += L_SUBFR ) diff --git a/lib_dec/dec_higher_acelp_fx.c b/lib_dec/dec_higher_acelp_fx.c index 51a7ab962..febbaa477 100644 --- a/lib_dec/dec_higher_acelp_fx.c +++ b/lib_dec/dec_higher_acelp_fx.c @@ -35,6 +35,7 @@ void transf_cdbk_dec_fx( Word16 qdct; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; + move32(); #endif #ifdef IVAS_CODE Word16 avq_bit_sFlag; @@ -45,7 +46,7 @@ void transf_cdbk_dec_fx( avq_bit_sFlag = 0; move16(); - if ( GT_16( st_fx->element_mode, EVS_MONO ) ) + if ( ( st_fx->element_mode > EVS_MONO ) ) { move16(); avq_bit_sFlag = 1; @@ -55,7 +56,7 @@ void transf_cdbk_dec_fx( * Set bit-allocation *--------------------------------------------------------------*/ - nBits = st_fx->acelp_cfg.AVQ_cdk_bits[shr( i_subfr, 6 )]; + nBits = st_fx->acelp_cfg.AVQ_cdk_bits[( i_subfr >> 6 )]; move16(); /* increase # of AVQ allocated bits by unused bits from the previous subframe */ @@ -67,19 +68,19 @@ void transf_cdbk_dec_fx( index = (Word16) get_next_indice_fx( st_fx, G_AVQ_BITS ); - IF( EQ_16( st_fx->coder_type, INACTIVE ) ) + IF( ( st_fx->coder_type == INACTIVE ) ) { IF( GT_32( st_fx->core_brate, 56000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_64k_Q12, G_AVQ_DELTA_INACT_64k_Q12 >> 1 ); // Q12 } ELSE IF( GT_32( st_fx->core_brate, 42000 ) ) { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_48k_Q12, G_AVQ_DELTA_INACT_48k_Q12 >> 1 ); // Q12 } ELSE { - gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1 ); + gain16 = usdequant_fx( index, G_AVQ_MIN_INACT_Q12, G_AVQ_DELTA_INACT_Q12 >> 1 ); // Q12 } L_tmp = Mult_32_16( gain_code, gain16 ); /* Q16 * Q12 - 15 -> Q13*/ @@ -97,17 +98,17 @@ void transf_cdbk_dec_fx( test(); IF( GT_32( st_fx->core_brate, ACELP_24k40 ) && LE_32( st_fx->core_brate, 42000 ) ) { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); + gain16 = gain_dequant_fx( index, G_AVQ_MIN_32kbps_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); // Q0 } ELSE { - gain16 = gain_dequant_fx( index, G_AVQ_MIN_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); + gain16 = gain_dequant_fx( index, G_AVQ_MIN_Q15, G_AVQ_MAX_Q0, G_AVQ_BITS, &exp16 ); // Q0 } IF( Es_pred < 0 ) { - tmp16 = shr( negate( Es_pred ), 2 ); - L_tmp = L_mult( gain16, tmp16 ); /* Q0*Q8 -> Q9*/ + tmp16 = shr( negate( Es_pred ), 2 ); // Q8 + L_tmp = L_mult( gain16, tmp16 ); /* Q0*Q8 -> Q9*/ } ELSE { @@ -124,7 +125,7 @@ void transf_cdbk_dec_fx( test(); test(); test(); - IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || EQ_16( st_fx->coder_type, INACTIVE ) ) ) + IF( avq_bit_sFlag && GT_16( nBits, 85 ) && !harm_flag_acelp && ( EQ_16( st_fx->coder_type, GENERIC ) || EQ_16( st_fx->coder_type, TRANSITION ) || ( st_fx->coder_type == INACTIVE ) ) ) { trgtSvPos = 2; avq_bit_sFlag = 2; @@ -139,7 +140,7 @@ void transf_cdbk_dec_fx( #ifdef IVAS_CODE_AVQ AVQ_demuxdec_fx( st_fx, code_preQ, &nBits, 8, nq, avq_bit_sFlag, trgtSvPos ); Word16 q_Code_preQ; - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { q_Code_preQ = Q_AVQ_OUT_DEC; move16(); @@ -172,7 +173,7 @@ void transf_cdbk_dec_fx( test(); test(); - IF( EQ_16( st_fx->coder_type, INACTIVE ) || GT_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) || harm_flag_acelp ) + IF( ( st_fx->coder_type == INACTIVE ) || GT_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) || harm_flag_acelp ) { qdct = 0; move16(); @@ -203,7 +204,7 @@ void transf_cdbk_dec_fx( test(); test(); test(); - IF( st_fx->element_mode > EVS_MONO && NE_16( st_fx->coder_type, INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) + IF( st_fx->element_mode > EVS_MONO && ( st_fx->coder_type != INACTIVE ) && GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) && LE_32( st_fx->core_brate, MAX_BRATE_AVQ_EXC_TD ) && !harm_flag_acelp && code_preQ[0] != 0 ) { // PMT("Fixed point taking accound of the scaling needs to be done here ") IF( GT_16( abs_s( st_fx->last_code_preq ), shl_sat( abs_s( code_preQ[0] ), 4 ) ) ) @@ -218,7 +219,7 @@ void transf_cdbk_dec_fx( } } - st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); + st_fx->last_code_preq = extract_h( code_preQ[L_SUBFR - 1] ); // q_Code_preQ-16 move16(); #endif PREEMPH_FX( code_preQ, FAC_PRE_AVQ_FX, L_SUBFR, &st_fx->mem_preemp_preQ_fx ); diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 79efe8356..f32a383a5 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -1,3 +1,4 @@ + /****************************************************************************************************** (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, @@ -1559,7 +1560,7 @@ void decoder_tcx_tns_fx( const Word16 L_spec, const Word16 L_frame, const Word16 L_frameTCX, - Word32 x_fx[N_MAX], + Word32 x_fx[N_MAX], // Qx const Word16 fUseTns, /* i : flag that is set if TNS data is present */ STnsData *tnsData, const Word16 bfi, /* i : Bad frame indicator */ @@ -1947,9 +1948,10 @@ void decoder_tcx_imdct_fx( TCX_DEC_HANDLE hTcxDec = st->hTcxDec; TCX_CONFIG_HANDLE hTcxCfg = st->hTcxCfg; Word16 predictionGain_fx; - Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; + Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; // q_a_itf Word16 q_a_itf = 15; - Word16 x_e = 31 - q_x; + Word16 x_e = sub(31, q_x); + move16(); /*-----------------------------------------------------------------* * Initializations @@ -1963,18 +1965,23 @@ void decoder_tcx_imdct_fx( index = hTcxCfg->tcx_last_overlap_mode; /* backup last TCX overlap mode */ move16(); - IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && NE_16( st->tcxonly, 0 ) && NE_16( frame_cnt, 0 ) && EQ_16( bfi, 0 ) && NE_16( st->last_core, ACELP_CORE ) ) + test(); + test(); + test(); + test(); + IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && ( st->tcxonly != 0 ) && ( frame_cnt != 0 ) && ( bfi == 0 ) && ( st->last_core != ACELP_CORE ) ) { /* fix sub-window overlap */ hTcxCfg->tcx_last_overlap_mode = hTcxCfg->tcx_curr_overlap_mode; move16(); } - IF( NE_16( st->igf, 0 ) ) + IF( st->igf != 0 ) { proc = st->hIGFDec->flatteningTrigger; move16(); + test(); IF( proc && fUseTns != 0 ) { proc = 0; @@ -1998,18 +2005,32 @@ void decoder_tcx_imdct_fx( move16(); /* interleave again for ITF */ + test(); IF( EQ_16( L_frame, shr( st->L_frame, 1 ) ) && st->tcxonly ) { - IF( ( hTcxCfg->fIsTNSAllowed && NE_16( fUseTns, 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) + test(); + test(); + test(); + IF( ( hTcxCfg->fIsTNSAllowed && ( fUseTns != 0 ) && NE_16( bfi, 1 ) ) || GT_16( L_spec, L_frameTCX ) ) { L = L_spec; move16(); } - IF( ( EQ_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) || - ( EQ_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) && EQ_16( frame_cnt, 0 ) && EQ_16( index, 0 ) ) ) ) || - ( NE_16( bfi, 0 ) && ( NE_16( hTcxCfg->tcx_last_overlap_mode, FULL_OVERLAP ) && - NE_16( hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( ( bfi == 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) || + ( ( hTcxCfg->tcx_curr_overlap_mode == FULL_OVERLAP ) && ( frame_cnt == 0 ) && ( index == 0 ) ) ) ) || + ( ( bfi != 0 ) && ( ( hTcxCfg->tcx_last_overlap_mode != FULL_OVERLAP ) && + ( hTcxCfg->tcx_curr_overlap_mode != FULL_OVERLAP ) ) ) ) { isTCX5 = 1; move16(); @@ -2022,7 +2043,7 @@ void decoder_tcx_imdct_fx( { IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) ) { - x_itf_fx[j - IGF_START_MN] = x_fx[j]; + x_itf_fx[j - IGF_START_MN] = x_fx[j]; // q_x move32(); x_fx[j] = st->hIGFDec->virtualSpec_fx[j - IGF_START_MN]; move32(); @@ -2035,9 +2056,9 @@ void decoder_tcx_imdct_fx( FOR( j = startLine; j < endLine; j++ ) { - IF( st->hIGFDec->flag_sparse[j - IGF_START_MN] == 2 ) + IF( EQ_16( st->hIGFDec->flag_sparse[j - IGF_START_MN], 2 ) ) { - x_fx[j] = x_itf_fx[j - IGF_START_MN]; + x_fx[j] = x_itf_fx[j - IGF_START_MN]; // q_x move32(); } } @@ -2059,25 +2080,26 @@ void decoder_tcx_imdct_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { set32_fx( x_tmp_fx, 0, L_FRAME_PLUS ); - Copy32( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); - Copy32( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); + Copy32( x_fx, x_tmp_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); // q_x + Copy32( x_fx, xn_bufFB_fx, s_min( L_FRAME48k, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ) ); // q_x } - ELSE IF( EQ_16( st->element_mode, EVS_MONO ) ) + ELSE IF( ( st->element_mode == EVS_MONO ) ) { - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x } ELSE { - Copy32( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, x_tmp_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x } - IF( NE_16( st->igf, 0 ) ) + IF( ( st->igf != 0 ) ) { set32_fx( xn_bufFB_fx + st->hIGFDec->infoIGFStartLine, 0, L_frameTCX - st->hIGFDec->infoIGFStartLine ); } - IF( st->element_mode != IVAS_CPE_DFT && !sba_dirac_stereo_flag ) + test(); + IF( NE_16(st->element_mode, IVAS_CPE_DFT) && !sba_dirac_stereo_flag ) { IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, @@ -2086,18 +2108,22 @@ void decoder_tcx_imdct_fx( } /* Generate additional comfort noise to mask potential coding artefacts */ - IF( NE_16( st->flag_cna, 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->cna_dirac_flag, 0 ) ) + test(); + test(); + test(); + IF( ( st->flag_cna != 0 ) && NE_16( st->element_mode, IVAS_CPE_TD ) && NE_16( st->element_mode, IVAS_CPE_DFT ) && ( st->cna_dirac_flag == 0 ) ) { generate_masking_noise_mdct_ivas_fx( x_fx, &x_e, st->hFdCngDec->hFdCngCom ); FOR( Word16 ind = 0; ind < L_frame; ind++ ) { - x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); + x_fx[ind] = L_shr( x_fx[ind], sub( 31, add( x_e, q_x ) ) ); // q_x } } - IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || NE_16( sba_dirac_stereo_flag, 0 ) ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || ( sba_dirac_stereo_flag != 0 ) ) { - Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); + Copy32( x_fx, xn_bufFB_fx, s_max( L_spec, s_max( L_frame, L_frameTCX ) ) ); // q_x IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, hTcxCfg->tcx_mdct_window_half, hTcxCfg->tcx_mdct_window_minimum, hTcxCfg->tcx_mdct_window_trans, hTcxCfg->tcx_mdct_window_half_length, hTcxCfg->tcx_mdct_window_min_length, index, kernelType, left_rect, tcx_offset, overlap, L_frame, L_frameTCX, shr( s_max( L_frameTCX, L_spec ), 1 ), L_frame_glob, frame_cnt, bfi, st->hHQ_core->old_out_LB_fx, 0, st, 0, acelp_zir_fx, q_win ); @@ -2105,9 +2131,10 @@ void decoder_tcx_imdct_fx( FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx_16[ind] = (Word16) L_shr( xn_bufFB_fx[ind], ( q_x - q_win ) ); + xn_bufFB_fx_16[ind] = extract_l( L_shr( xn_bufFB_fx[ind], sub( q_x, q_win ) ) ); // q_x + move16(); } - IF( NE_16( st->element_mode, EVS_MONO ) ) + IF( st->element_mode != EVS_MONO ) { IMDCT_ivas_fx( x_tmp_fx, q_x, hTcxDec->syn_OverlFB, hTcxDec->syn_Overl_TDACFB, xn_bufFB_fx_16, hTcxCfg->tcx_aldo_window_1_FB, hTcxCfg->tcx_aldo_window_1_FB_trunc, hTcxCfg->tcx_aldo_window_2_FB, hTcxCfg->tcx_mdct_window_halfFB, hTcxCfg->tcx_mdct_window_minimumFB, hTcxCfg->tcx_mdct_window_transFB, hTcxCfg->tcx_mdct_window_half_lengthFB, hTcxCfg->tcx_mdct_window_min_lengthFB, index, @@ -2121,12 +2148,13 @@ void decoder_tcx_imdct_fx( } FOR( Word16 ind = 0; ind < L_MDCT_OVLP_MAX + L_FRAME_PLUS + L_MDCT_OVLP_MAX; ind++ ) { - xn_bufFB_fx[ind] = L_shl( xn_bufFB_fx_16[ind], ( q_x - q_win ) ); + xn_bufFB_fx[ind] = L_shl( xn_bufFB_fx_16[ind], sub( q_x, q_win ) ); // Q_x } - IF( EQ_16( bfi, 0 ) ) + IF( ( bfi == 0 ) ) { Word16 res_m, res_e = 0; + move16(); st->second_last_tns_active = st->last_tns_active; move16(); st->last_tns_active = hTcxCfg->fIsTNSAllowed & fUseTns; @@ -2157,20 +2185,20 @@ void decoder_tcx_imdct_fx( } /* Update old_syn_overl */ - IF( EQ_16( hTcxCfg->last_aldo, 0 ) ) + IF( hTcxCfg->last_aldo == 0 ) { - Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); + Copy( xn_buf_fx + L_frame, hTcxDec->syn_Overl, overlap ); // Q(-2) FOR( Word16 ind = 0; ind < overlapFB; ind++ ) { - hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, L_frameTCX )], sub( q_x, q_win ) ); + hTcxDec->syn_OverlFB[ind] = (Word16) L_shr( xn_bufFB_fx[( ind + L_frameTCX )], sub( q_x, q_win ) ); // q_x } } /* Output */ - Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); + Copy( xn_buf_fx + sub( shr( overlap, 1 ), tcx_offset ), synth_fx, L_frame_glob ); // Q(-2) FOR( Word16 ind = 0; ind < L_frameTCX_glob; ind++ ) { - synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[add( ind, sub( shr( overlapFB, 1 ), tcx_offsetFB ) )], sub( q_x, q_win ) ); + synthFB_fx[ind] = (Word16) L_shr( xn_bufFB_fx[( ind + ( ( overlapFB >> 1 ) - tcx_offsetFB ) )], sub( q_x, q_win ) ); // q_x } diff --git a/lib_dec/dec_tran_fx.c b/lib_dec/dec_tran_fx.c index f92ef8904..a9ea119ba 100644 --- a/lib_dec/dec_tran_fx.c +++ b/lib_dec/dec_tran_fx.c @@ -82,24 +82,22 @@ void decod_tran_fx( gain_code_fx = 0; /* Quantized algebraic codeebook gain */ move32(); - norm_gain_code_fx = 0; /* normalized algebraic codeebook gain */ + norm_gain_code_fx = 0; /* normalized algebraic codeebook gain Q16 */ move32(); - gain_pit_fx = 0; /* Quantized pitch gain */ + gain_pit_fx = 0; /* Quantized pitch gain Q14 */ move16(); gain_inov_fx = 0; /* inovation gain */ move16(); - gain_preQ_fx = 0; /* Gain of prequantizer excitation */ + gain_preQ_fx = 0; /* Gain of prequantizer excitation Q2 */ move16(); - gain_preQ_fx = 0; - move16(); - set16_fx( code_preQ_fx, 0, L_SUBFR ); + set16_fx( code_preQ_fx, 0, L_SUBFR ); // Q10 /*----------------------------------------------------------------* * ACELP subframe loop *----------------------------------------------------------------*/ - p_Aq_fx = Aq_fx; - pt_pitch_fx = pitch_buf_fx; + p_Aq_fx = Aq_fx; // Q12 + pt_pitch_fx = pitch_buf_fx; // Q6 Jopt_flag = 0; move16(); norm_gain_preQ_fx = 0; @@ -116,9 +114,9 @@ void decod_tran_fx( IF( i_subfr == 0 && GT_16( st_fx->Q_exc, 2 ) ) { tmp16 = sub( 2, st_fx->Q_exc ); - Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 ); - Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); - Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); + Scale_sig( exc_fx - L_EXC_MEM, L_EXC_MEM, tmp16 ); // Q2 + Scale_sig( bwe_exc_fx - PIT16k_MAX * 2, PIT16k_MAX * 2, tmp16 ); // Q2 + Scale_sig( hGSCDec->last_exc_dct_in_fx, L_FRAME, tmp16 ); // Q2 st_fx->Q_exc = add( st_fx->Q_exc, tmp16 ); move16(); } @@ -213,7 +211,7 @@ void decod_tran_fx( #endif IF( EQ_16( L_frame_fx, L_FRAME ) ) /* Rescaling for 12.8k core */ { - Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[shr( imult1616( i_subfr, 2 * HIBND_ACB_L_FAC ), 1 )], hGSCDec->last_exc_dct_in_fx, + Rescale_exc( hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr], &bwe_exc_fx[( ( i_subfr * 2 * HIBND_ACB_L_FAC ) >> 1 )], hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, gain_code_fx, &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr, st_fx->coder_type ); } ELSE /* Rescaling for 16k core */ @@ -230,7 +228,7 @@ void decod_tran_fx( *-----------------------------------------------------------------*/ IF( GE_32( st_fx->core_brate, MIN_BRATE_AVQ_EXC ) ) { - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode == EVS_MONO ) ) { tmp1_fx = add( 15 - Q_AVQ_OUT_DEC - 2, st_fx->Q_exc ); } @@ -296,9 +294,9 @@ void decod_tran_fx( } p_Aq_fx += ( M + 1 ); pt_pitch_fx++; - st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; + st_fx->tilt_code_dec_fx[tmp_idx] = st_fx->tilt_code_fx; // Q15 move16(); - gain_buf[tmp_idx] = gain_pit_fx; + gain_buf[tmp_idx] = gain_pit_fx; // Q14 move16(); } diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 7edc512f7..231b0cb73 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -84,14 +84,14 @@ void decod_unvoiced_fx( Word16 tmp_idx = 0; move16(); - if ( i_subfr_fx != 0 ) + IF ( i_subfr_fx != 0 ) { tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); } voice_factors_fx[tmp_idx] = 0; move16(); - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; @@ -217,7 +217,7 @@ void decod_unvoiced_ivas_fx( IF( EQ_16( st_fx->L_frame, L_FRAME ) ) { - Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, + Rescale_exc( st_fx->hMusicPF->dct_post_old_exc_fx, &exc_fx[i_subfr_fx], ( bwe_exc_fx != NULL ) ? &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )] : NULL, st_fx->hGSCDec->last_exc_dct_in_fx, L_SUBFR, L_SUBFR * HIBND_ACB_L_FAC, L_max( gain_code2_fx, gain_code_fx ), &( st_fx->Q_exc ), st_fx->Q_subfr, exc2_fx, i_subfr_fx, UNVOICED ); } ELSE @@ -262,7 +262,7 @@ void decod_unvoiced_ivas_fx( } voice_factors_fx[tmp_idx] = 0; move16(); - interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[shr( imult1616( i_subfr_fx, 2 * HIBND_ACB_L_FAC ), 1 )], L_SUBFR ); + interp_code_5over2_fx( &exc_fx[i_subfr_fx], &bwe_exc_fx[( ( i_subfr_fx * 2 * HIBND_ACB_L_FAC ) >> 1 )], L_SUBFR ); p_Aq_fx += ( M + 1 ); pt_pitch_fx++; diff --git a/lib_dec/dlpc_avq_fx.c b/lib_dec/dlpc_avq_fx.c index 1f4a7117b..c38d0b9a3 100644 --- a/lib_dec/dlpc_avq_fx.c +++ b/lib_dec/dlpc_avq_fx.c @@ -48,9 +48,9 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[last + i] = 0; } - vlpc_1st_dec( p_index[0], &LSF_Q[last] ); + vlpc_1st_dec( p_index[0], &LSF_Q[last] ); // LSF_Q[last] -> Q2.56 p_index++; - vlpc_2st_dec( &LSF_Q[last], &p_index[0], 0, sr_core ); + vlpc_2st_dec( &LSF_Q[last], &p_index[0], 0, sr_core ); // Q2.56 nbi = add( 2, add( p_index[0], p_index[1] ) ); p_index += nbi; @@ -70,7 +70,7 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[i] = 0; } - vlpc_1st_dec( p_index[0], &LSF_Q[0] ); + vlpc_1st_dec( p_index[0], &LSF_Q[0] ); ////Q2.56 p_index++; vlpc_2st_dec( &LSF_Q[0], &p_index[0], 0, sr_core ); } @@ -82,7 +82,7 @@ Word16 dlpc_avq_fx( move16(); LSF_Q[i] = LSF_Q[M + i]; } - vlpc_2st_dec( &LSF_Q[0], &p_index[0], 3, sr_core ); + vlpc_2st_dec( &LSF_Q[0], &p_index[0], 3, sr_core ); ////Q2.56 } nbi = add( 2, add( p_index[0], p_index[1] ) ); p_index += nbi; @@ -425,6 +425,7 @@ Word16 decode_lpc_avq_ivas_fx( test(); test(); test(); + test(); IF( NE_16( element_mode, IVAS_CPE_MDCT ) || ( !( sns_low_br_mode && ( ( stereo_mode == 0 ) || EQ_16( stereo_mode, 1 ) ) ) && !( ( q_type == 0 ) && EQ_16( param_lpc[j - 1], -2 ) ) ) ) { /* 2 bits to specify Q2,Q3,Q4,ext */ diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index 74299beae..463875a1c 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -38,45 +38,45 @@ static Word16 IGF_getScaleFactor32Cond( /**< ou Word32 tmp32; - x_max = 0; + x_max = 0; // Q31 move32(); - x_min = 0; + x_min = 0; // Q31 move32(); FOR( i = 0; i < len_x; i++ ) { - tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ + tmp32 = L_add( x[i], 0 ); /*L_and(x[i], cond[i]);*/ // Q31 - if ( cond[i] == 0 ) + IF( cond[i] == 0 ) { - tmp32 = L_deposit_h( 0 ); + tmp32 = L_deposit_h( 0 ); // Q31 } - if ( tmp32 >= 0 ) + IF( tmp32 >= 0 ) { - x_max = L_max( x_max, tmp32 ); + x_max = L_max( x_max, tmp32 ); // Q31 } - if ( tmp32 < 0 ) + IF( tmp32 < 0 ) { - x_min = L_min( x_min, tmp32 ); + x_min = L_min( x_min, tmp32 ); // Q31 } } - i_max = 0x20; + i_max = 0x20; // Q0 move16(); - i_min = 0x20; + i_min = 0x20; // Q0 move16(); - if ( x_max != 0 ) + IF( x_max != 0 ) { - i_max = norm_l( x_max ); + i_max = norm_l( x_max ); // Q0 } - if ( x_min != 0 ) + IF( x_min != 0 ) { - i_min = norm_l( x_min ); + i_min = norm_l( x_min ); // Q0 } - i = s_and( s_min( i_max, i_min ), 0x1F ); + i = s_and( s_min( i_max, i_min ), 0x1F ); // Q0 return i; } @@ -87,7 +87,7 @@ measures TCX noise static Word16 IGF_replaceTCXNoise_1( /**< out: Q0 | number of noise bands */ const Word32 *in, /**< in: Q31 | MDCT spectrum */ Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 *totalNoiseNrg /**< out: | measured noise energy */ @@ -107,32 +107,30 @@ static Word16 IGF_replaceTCXNoise_1( /**< ou nE = 0; move32(); - FOR( sb = start; sb < stop; sb++ ) - { - IF( TCXNoise[sb] ) - { - tmp16 = extract_h( L_shl( in[sb], s_l ) ); - } - IF( TCXNoise[sb] ) - { - nE = L_mac( nE, tmp16, tmp16 ); - } - if ( TCXNoise[sb] ) - { - noise = add( noise, 1 ); - } - } + FOR( sb = start; sb < stop; sb++ ){ + IF( TCXNoise[sb] ){ + tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l +} +IF( TCXNoise[sb] ) +{ + nE = L_mac( nE, tmp16, tmp16 ); // Q31 + s_l +} +IF( TCXNoise[sb] ) +{ + noise = add( noise, 1 ); // Q0 +} +} - *totalNoiseNrg = nE; - move32(); +*totalNoiseNrg = nE; // Q31 + s_l +move32(); - return noise; +return noise; } static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q0 | number of noise bands */ const Word32 *in, /**< in: Q31 | MDCT spectrum */ Word16 s_l, /**< in: Q0 | noise headroom */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 *totalNoiseNrg, /**< out: | measured noise energy */ @@ -156,15 +154,15 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q { IF( TCXNoise[sb] ) { - tmp16 = extract_h( L_shl( in[sb], s_l ) ); + tmp16 = extract_h( L_shl( in[sb], s_l ) ); // Q31 + s_l } IF( TCXNoise[sb] ) { - nE = W_mac_16_16( nE, tmp16, tmp16 ); + nE = W_mac_16_16( nE, tmp16, tmp16 ); // Q31 + s_l } - if ( TCXNoise[sb] ) + IF( TCXNoise[sb] ) { - noise = add( noise, 1 ); + noise = add( noise, 1 ); // Q0 } } @@ -181,7 +179,7 @@ static Word16 ivas_IGF_replaceTCXNoise_1_fx( /**< out: Q /**********************************************************************/ /* replaces TCX noise **************************************************************************/ -static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: | MDCT spectrum */ +static void IGF_replaceTCXNoise_2( Word32 *in, /**< in/out: Q31 | MDCT spectrum */ const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ const Word16 start, /**< in: Q0 | start MDCT subband index */ const Word16 stop, /**< in: Q0 | stop MDCT subband index */ @@ -206,55 +204,55 @@ static void IGF_replaceTCXNoise_2( Word32 *in, /**< in { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 } IF( TCXNoise[sb] ) { - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); } IF( TCXNoise[sb] ) { - val = shr( val, 5 ); + val = shr( val, 5 ); // Q-5 } IF( TCXNoise[sb] ) { - rE = L_mac( rE, val, val ); + rE = L_mac( rE, val, val ); // Q-9 } } - totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); + totalNoiseNrg = L_shr( totalNoiseNrg, 1 ); // Q-9 /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q-9 } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } /* make sure that rE is never smaller than totalNoiseNrg */ - L_tmp = L_sub( rE, totalNoiseNrg ); + L_tmp = L_sub( rE, totalNoiseNrg ); // Q-9 if ( L_tmp < 0 ) { - rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ + rE = totalNoiseNrg; /* save move32() -> use L_add(x, 0) = x; */ // Q-9 move32(); } - g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); - g = shl( g, 1 ); + g = getSqrtWord32( L_mult( divide3232( totalNoiseNrg, rE ), 8192 /*1.0f / 4.0f Q15*/ ) ); // ((Q15 + Q15 + Q1) / 2) -> Q15 + g = shl( g, 1 ); // Q16 FOR( sb = start; sb < stop; sb++ ) { IF( TCXNoise[sb] ) { - in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); + in[sb] = L_shr( L_mult( extract_l( in[sb] ), g ), s_l ); // Q15 + Q16 + Q1 - s_l move32(); } } @@ -293,12 +291,12 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 move16(); - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); - val = shr( val, 5 ); - rE = L_mac( rE, val, val ); + val = shr( val, 5 ); // Q-5 + rE = L_mac( rE, val, val ); // Q-9 n_noise_bands_tile = add( n_noise_bands_tile, 1 ); } } @@ -311,17 +309,17 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); + L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); g = Sqrt16( tmp, &tmp_e ); @@ -349,13 +347,13 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in **************************************************************************/ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /**< in/out: | MDCT spectrum */ Word16 *in_e_arr, /**< in/out: | MDCT spectrum exp */ - const Word16 *TCXNoise, /**< in: | tcx noise indicator vector */ - const Word16 start, /**< in: | start MDCT subband index */ - const Word16 stop, /**< in: | stop MDCT subband index */ + const Word16 *TCXNoise, /**< in: Q0 | tcx noise indicator vector */ + const Word16 start, /**< in: Q0 | start MDCT subband index */ + const Word16 stop, /**< in: Q0 | stop MDCT subband index */ Word32 totalNoiseNrg, /**< in: | measured noise energy */ Word16 totalNoiseNrg_e, /**< in: | measured noise energy exp */ - const Word16 n_noise_bands, /**< in: | number of noise bands in src */ - Word16 *nfSeed /**< in: | random generator noise seed */ + const Word16 n_noise_bands, /**< in: Q0 | number of noise bands in src */ + Word16 *nfSeed /**< in: Q0 | random generator noise seed */ ) { Word16 sb; @@ -377,14 +375,14 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, { IF( TCXNoise[sb] ) { - val = Random( nfSeed ); + val = Random( nfSeed ); // Q0 move16(); - in[sb] = L_deposit_l( val ); + in[sb] = L_deposit_l( val ); // Q0 move32(); in_e_arr[sb] = 31; move16(); - val = shr( val, 5 ); - rE = L_mac( rE, val, val ); + val = shr( val, 5 ); // Q-5 + rE = L_mac( rE, val, val ); // Q-9 n_noise_bands_tile = add( n_noise_bands_tile, 1 ); } } @@ -397,17 +395,17 @@ static void IGF_replaceTCXNoise_2_new_ivas_with_var_shift( Word32 *in, /* make sure that rE is never 0 */ if ( rE == 0 ) { - rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ + rE = L_add( totalNoiseNrg, 0 ); /* save move32() -> use L_add(x, 0) = x; */ // Q31 - totalNoiseNrg_e } /* if totalNoiseNrg == 0, then rE must be at least 0x00010000, otherwise division by 0 will occur */ if ( totalNoiseNrg == 0 ) { - rE = L_max( rE, 0x00010000 ); + rE = L_max( rE, 0x00010000 ); // Q-9 } Word16 tmp, tmp_e; - L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); + L_tmp = Mpy_32_16_1( totalNoiseNrg, noise_band_ratio ); // Q31 - totalNoiseNrg_e tmp = BASOP_Util_Divide3232_Scale( L_tmp, rE, &tmp_e ); tmp_e = add( tmp_e, sub( totalNoiseNrg_e, 40 ) ); g = Sqrt16( tmp, &tmp_e ); @@ -441,23 +439,23 @@ static void IGF_decode_whitening_level( Decoder_State *st, Word16 tmp; - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 if ( tmp == 0 ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_MID; // Q0 move16(); return; } - tmp = get_next_indice_fx( st, 1 ); - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; + tmp = get_next_indice_fx( st, 1 ); // Q0 + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_STRONG; // Q0 move16(); if ( tmp == 0 ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } } @@ -469,7 +467,7 @@ static void IGF_decode_temp_flattening_trigger( Decoder_State *st, IGF_DEC_INSTANCE_HANDLE hInstance /**< in: | instance handle of IGF Deccoder */ ) { - hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); + hInstance->flatteningTrigger = get_next_indice_fx( st, 1 ); // Q0 move16(); } @@ -520,7 +518,7 @@ static void IGF_convert_exponent_per_idx_to_per_tile( H_IGF_GRID hGrid, FOR( j = start; j < stop; j++ ) { - igfSpec[j] = L_shr( igfSpec[j], sub( max_e, igfSpec_e_per_idx[j] ) ); + igfSpec[j] = L_shr( igfSpec[j], sub( max_e, igfSpec_e_per_idx[j] ) ); // Q31 - max_e move32(); } @@ -593,7 +591,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( i = strt_cpy; i < hGrid->startLine; i++ ) { - abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); + abs_sum = L_add( abs_sum, L_abs( src_spec[i] ) ); // Q31 - src_spec_e } /* fill igf_spec with random noise */ @@ -604,7 +602,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); } } @@ -612,7 +610,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < startLine; i++ ) { - igf_spec[tb++] = 0; + igf_spec[tb++] = 0; // Q0 move32(); } } @@ -672,7 +670,7 @@ static void IGF_prep( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { - igf_spec[tb] = sel_spec[strt_cpy]; + igf_spec[tb] = sel_spec[strt_cpy]; // Q31 - igf_spec_e move32(); strt_cpy = add( strt_cpy, 1 ); } @@ -744,14 +742,14 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in strt_cpy = hGrid->sbWrap[tile_idx]; move16(); - IF( GT_16( element_mode, EVS_MONO ) ) + IF( element_mode > EVS_MONO ) { - tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); - stop = add( strt_cpy, tile_width ); + tile_width = sub( hGrid->swb_offset[hGrid->sfbWrap[tile_idx + 1]], hGrid->swb_offset[hGrid->sfbWrap[tile_idx]] ); // Q0 + stop = add( strt_cpy, tile_width ); // Q0 } ELSE { - stop = hGrid->startLine; + stop = hGrid->startLine; // Q0 move16(); } @@ -764,18 +762,18 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( i = strt_cpy; i < stop; i++ ) { - abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ + abs_sum = L_add_sat( abs_sum, L_abs( src_spec[i] ) ); /* saturation since it just checks if abs_sum is greater than zero*/ // Q31 - src_spec_e } /* fill igf_spec with random noise */ - tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; + tb = hGrid->swb_offset[hGrid->sfbWrap[tile_idx]]; // Q0 move16(); IF( abs_sum != 0 ) { FOR( i = strt_cpy; i < stop; i++ ) { - igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_spec[tb++] = L_deposit_l( Random( hInfo->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); } } @@ -783,7 +781,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( i = strt_cpy; i < stop; i++ ) { - igf_spec[tb++] = 0; + igf_spec[tb++] = 0; // Q0 move32(); } } @@ -797,7 +795,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* medium whitening detected */ IF( EQ_16( IGF_WHITENING_MID, hPrivateData->currWhiteningLevel[tile_idx] ) ) { - IF( GT_16( element_mode, EVS_MONO ) ) + IF( element_mode > EVS_MONO ) { IF( n_noise_bands != 0 ) { @@ -879,7 +877,7 @@ static void IGF_prep_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { FOR( tb = hGrid->swb_offset[sfb]; tb < hGrid->swb_offset[sfb + 1]; tb++ ) { - igf_spec[tb] = sel_spec[strt_cpy]; + igf_spec[tb] = sel_spec[strt_cpy]; // Q31 - igf_spec_e move32(); strt_cpy = add( strt_cpy, 1 ); } @@ -895,9 +893,9 @@ prepare IGF spectrum in stereo static void IGF_prepStereo( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataL, /* i : IGF private data handle */ IGF_DEC_PRIVATE_DATA_HANDLE hPrivateDataR, /* i : IGF private data handle */ - const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength */ - const Word16 *TCXNoiseL, /* i : left TCX noise vector */ - const Word16 *TCXNoiseR, /* i : right TCX noise vector */ + const Word16 igfGridIdx, /* i : in case of CELP->TCX switching, use 1.25 framelength Q0 */ + const Word16 *TCXNoiseL, /* i : left TCX noise vector Q0 */ + const Word16 *TCXNoiseR, /* i : right TCX noise vector Q0 */ Word32 *igf_specL_fx, /* i/o: prepared left IGF spectrum */ Word16 *igf_specL_e_arr, /* i/o: prepared left IGF spectrum exponents for each index */ Word32 *igf_specR_fx, /* i/o: prepared right IGF spectrum */ @@ -906,7 +904,7 @@ static void IGF_prepStereo( const Word16 src_specL_e, /* i : left source spectrum exp */ const Word32 *src_specR_fx, /* i : right source spectrum */ const Word16 src_specR_e, /* i : right source spectrum exp */ - const Word16 *coreMsMask /* i : line wise ms Mask */ + const Word16 *coreMsMask /* i : line wise ms Mask Q0 */ ) { H_IGF_GRID hGrid; @@ -916,11 +914,15 @@ static void IGF_prepStereo( const Word32 c_fx = SQRT2_OVER_2_FIXED; // Q31 Word16 selectionL = 0; // 0 -> IGF, 1 -> pSpecFlat Word16 selectionR = 0; // 0 -> IGF, 1 -> pSpecFlat + move32(); + move16(); + move16(); hInfoL = &hPrivateDataL->igfInfo; hInfoR = &hPrivateDataR->igfInfo; hGrid = &hPrivateDataL->igfInfo.grid[igfGridIdx]; swb_offset = hGrid->swb_offset; + move16(); FOR( tile_idx = 0; tile_idx < hGrid->nTiles; tile_idx++ ) { @@ -938,7 +940,7 @@ static void IGF_prepStereo( FOR( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ ) { - igf_specL_fx[tb] = L_deposit_l( Random( hInfoL->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_specL_fx[tb] = L_deposit_l( Random( hInfoL->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); igf_specL_e_arr[tb] = 31; move16(); @@ -1059,8 +1061,8 @@ static void IGF_prepStereo( } ELSE /* MS/DR -> LR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specL_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, tmpR, selR_e, &tmp_e ); move32(); igf_specL_e_arr[tb] = tmp_e; @@ -1071,8 +1073,8 @@ static void IGF_prepStereo( { IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specL_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, tmpR, selR_e, &tmp_e ); move32(); igf_specL_e_arr[tb] = tmp_e; @@ -1101,7 +1103,7 @@ static void IGF_prepStereo( FOR( tb = swb_offset[hGrid->sfbWrap[tile_idx]]; tb < swb_offset[hGrid->sfbWrap[tile_idx + 1]]; tb++ ) { - igf_specR_fx[tb] = L_deposit_l( Random( hInfoR->nfSeed ) ); /* 31Q0, fill LSBs */ + igf_specR_fx[tb] = L_deposit_l( Random( hInfoR->nfSeed ) ); /* 31Q0, fill LSBs */ // Q0 move32(); igf_specR_e_arr[tb] = 31; move16(); @@ -1225,8 +1227,8 @@ static void IGF_prepStereo( } ELSE /* MS/DR -> LR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); move32(); igf_specR_e_arr[tb] = tmp_e; @@ -1237,8 +1239,8 @@ static void IGF_prepStereo( { IF( EQ_16( coreMsMask[strt_cpy], 0 ) ) /* LR->MS/DR */ { - tmpL = Mpy_32_32( selL, c_fx ); - tmpR = Mpy_32_32( selR, c_fx ); + tmpL = Mpy_32_32( selL, c_fx ); // Q31 - selL_e + tmpR = Mpy_32_32( selR, c_fx ); // Q31 - selR_e igf_specR_fx[tb] = BASOP_Util_Add_Mant32Exp( tmpL, selL_e, L_negate( tmpR ), selR_e, &tmp_e ); move32(); igf_specR_e_arr[tb] = tmp_e; @@ -1493,11 +1495,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* initialize variables */ - w0 = 6586; + w0 = 6586; // Q15 move16(); - w1 = 12747; + w1 = 12747; // Q15 move16(); - w2 = 13435; + w2 = 13435; // Q15 move16(); dE = 0; move16(); @@ -1571,8 +1573,8 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); // Q31 - dE_e Overflow = 0; move16(); L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); @@ -1582,7 +1584,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_c = L_macNs( L_c, 0, 0 ); #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &shift ); + L_tmp = norm_llQ31( L_c, L_tmp, &shift ); // Q31 /* float: dE = (float)sqrt(dE / 24.f); basop: */ shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ dE = Sqrt16norm( extract_h( L_tmp ), &shift ); @@ -1610,7 +1612,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( tb = add( sfb, 1 ); tb < tmp_loop; tb++ ) + FOR( tb = sfb + 1; tb < tmp_loop; tb++ ) { sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], sN_e[sfb], @@ -1642,7 +1644,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr( sfb, 1 )]; + gn = hPrivateData->igf_curr[sfb >> 1]; // Q15 move16(); move16(); gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ @@ -1875,11 +1877,11 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[s_min( add( add( sfb, tb ), 1 ), stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min( add( sfb, tb ), stop_sfb )] ); + width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); - tmp = dS[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; - tmp_e = dS_e[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; + tmp = dS[min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); @@ -1976,7 +1978,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /*--- check gains /spectrum exponents for possible overflows --- */ /* get tile index */ - if ( LE_16( hGrid->sfbWrap[add( tileIdx, 1 )], sfb ) ) + IF( LE_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2026,7 +2028,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb++ ) { /* get tile index */ - if ( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) + IF( EQ_16( hGrid->sfbWrap[tileIdx + 1], sfb ) ) { tileIdx = add( tileIdx, 1 ); } @@ -2106,7 +2108,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *spectrum_e ); tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2119,7 +2121,7 @@ static void IGF_appl( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { shift = sub( L_tmp_e, *virtualSpec_e ); tmp = sub( sub( norm_l( L_tmp ), shift ), 32 ); - if ( tmp < 0 ) + IF( tmp < 0 ) { L_tmp2 = L_shl( L_tmp, shift ); } @@ -2209,11 +2211,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in /* initialize variables */ - w0 = 6586; + w0 = 6586; // Q15 move16(); - w1 = 12747; + w1 = 12747; // Q15 move16(); - w2 = 13435; + w2 = 13435; // Q15 move16(); dE = 0; move16(); @@ -2289,8 +2291,8 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in { Carry = 0; move16(); -#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ - L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); +#ifdef BASOP_NOGLOB /* Critical Carry/Overflow*/ + L_tmp = L_add_co( L_tmp, energyTmp[tb], &Carry, &Overflow ); // Q31 - dE_e Overflow = 0; L_c = L_macNs_co( L_c, 0, 0, &Carry, &Overflow ); #else @@ -2299,7 +2301,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in L_c = L_macNs( L_c, 0, 0 ); #endif } - L_tmp = norm_llQ31( L_c, L_tmp, &shift ); + L_tmp = norm_llQ31( L_c, L_tmp, &shift ); // Q31 /* float: dE = (float)sqrt(dE / 24.f); basop: */ shift = add( sub( shift, 4 ), dE_e ); /* x/24 = (x >> 4) * 1/1.5 */ dE = Sqrt16norm( extract_h( L_tmp ), &shift ); @@ -2331,7 +2333,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( sfb = start_sfb; sfb < stop_sfb; sfb += hopsize ) { tmp_loop = s_min( add( sfb, hopsize ), stop_sfb ); - FOR( tb = add( sfb, 1 ); tb < tmp_loop; tb++ ) + FOR( tb = sfb + 1; tb < tmp_loop; tb++ ) { sN[sfb] = BASOP_Util_Add_Mant32Exp( sN[sfb], sN_e[sfb], @@ -2346,9 +2348,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in &pN_e[sfb] ); move32(); sN[tb] = L_deposit_l( 0 ); - move32(); pN[tb] = L_deposit_l( 0 ); - move32(); } } } @@ -2365,7 +2365,7 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in width_e = sub( 15, shift ); /* initial value of width_e is 15, -> width = 15Q0 */ /* float: gn = 0.25f * igf_curr - 4.f; basop: */ - gn = hPrivateData->igf_curr[shr( sfb, 1 )]; + gn = hPrivateData->igf_curr[sfb >> 1]; // Q15 move16(); move16(); gn_e = 13; /* set exponent of igf_curr to 13 = 15 - 2; -> igf_curr = igf_curr * 0.25, virtual division by 4 */ @@ -2587,11 +2587,11 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in FOR( tb = 0; tb < hopsize; tb++ ) { /* calculate of the current sfb width */ - width = sub( hGrid->swb_offset[s_min( add( add( sfb, tb ), 1 ), stop_sfb )], /* 15Q0 | width is Q0 */ - hGrid->swb_offset[s_min( add( sfb, tb ), stop_sfb )] ); + width = sub( hGrid->swb_offset[min( sfb + tb + 1, stop_sfb )], /* 15Q0 | width is Q0 */ + hGrid->swb_offset[min( sfb + tb, stop_sfb )] ); - tmp = dS[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; - tmp_e = dS_e[s_min( add( sfb, tb ), sub( stop_sfb, 1 ) )]; + tmp = dS[min( sfb + tb, stop_sfb - 1 )]; + tmp_e = dS_e[min( sfb + tb, stop_sfb - 1 )]; move16(); move16(); @@ -2796,8 +2796,10 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); FOR( i = 0; i < hGrid->stopLine; i++ ) { - if ( spectrum[i] != 0 ) + IF( spectrum[i] != 0 ) + { max_e = s_max( max_e, sub( spec_e_arr[i], norm_l( spectrum[i] ) ) ); + } } FOR( i = 0; i < hGrid->stopLine; i++ ) { @@ -2811,8 +2813,10 @@ static void IGF_appl_ivas( IGF_DEC_PRIVATE_DATA_HANDLE hPrivateData, /**< in move16(); FOR( i = hGrid->startLine - IGF_START_MN; i < hGrid->stopLine - IGF_START_MN; i++ ) { - if ( virtualSpec[i] ) + IF( virtualSpec[i] ) + { max_e = s_max( max_e, sub( vspec_e_arr[i], norm_l( virtualSpec[i] ) ) ); + } } FOR( i = hGrid->startLine - IGF_START_MN; i < hGrid->stopLine - IGF_START_MN; i++ ) { @@ -2864,9 +2868,9 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in } FOR( j = start; j < stop - level; j++ ) { - tmp_16 = extract_h( L_shl( in[j + level], s_l ) ); // in_e - s_l - ak = L_mac( ak, tmp_16, tmp_16 ); // 2 * (in_e - s_l) - ak_norm = Mpy_32_16_r( ak, 2185 ); + tmp_16 = extract_h( L_shl( in[j + level], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) + ak_norm = Mpy_32_16_r( ak, 2185 /* 1/15 in Q15 */ ); // e: 2 * (in_e - s_l) tmp_16 = sub( 31, norm_l( ak_norm ) ); if ( ak == 0 ) @@ -2877,11 +2881,11 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in tmp_16 = s_min( 14, sub( 15, shr( tmp_16, 1 ) ) ); div = shl( 1, tmp_16 ); - out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); // e: in_e - s_l move32(); - tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); - ak = L_msu( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); // e: in_e - s_l + ak = L_msu( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } nrm_i = 0; @@ -2889,7 +2893,7 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in FOR( ; j < stop; j++ ) { - ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); + ak_norm = Mpy_32_16_r( ak, nrm_tab[nrm_i++] ); // e: 2 * (in_e - s_l) tmp_16 = sub( 31, norm_l( ak_norm ) ); if ( ak == 0 ) @@ -2907,10 +2911,10 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in move16(); } - out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); + out[j] = Mpy_32_16_1( L_shl( in[j], s_l ), div ); // e: in_e - s_l move32(); - tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); - ak = L_msu( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j - level], s_l ) ); // e: in_e - s_l + ak = L_msu( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } } @@ -2923,12 +2927,12 @@ static void IGF_getWhiteSpectralData( const Word32 *in, /**< in static void IGF_getWhiteSpectralData_ivas( const Word32 *in, /* i : MDCT spectrum */ const Word16 in_e, /* i : MDCT spectrum exp */ - Word16 s_l, /* i : getScaleFactor32() of in */ + Word16 s_l, /* i : getScaleFactor32() of in Q0 */ Word32 *out, /* o : whitened spectrum */ Word16 *out_e, /* o : whitened spectrum exp */ - const Word16 start, /* i : start MDCT subband index */ - const Word16 stop, /* i : stop MDCT subband index */ - const Word16 level /* i : whitening strength */ + const Word16 start, /* i : start MDCT subband index Q0 */ + const Word16 stop, /* i : stop MDCT subband index Q0 */ + const Word16 level /* i : whitening strength Q0 */ ) { Word16 i; @@ -2963,8 +2967,8 @@ static void IGF_getWhiteSpectralData_ivas( move32(); FOR( j = i - level; j < i + level + 1; j++ ) { - tmp_16 = extract_h( L_shl( in[j], s_l ) ); - ak = L_mac( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } ak = L_deposit_h( BASOP_Util_Divide3216_Scale( ak, add( shl( level, 1 ), 1 ), &tmp_e ) ); ak_e = add( tmp_e, sub( shl( sub( in_e, s_l ), 1 ), 15 ) ); // tmp_e + 2 * (in_e - s_l) - 15 @@ -2986,8 +2990,8 @@ static void IGF_getWhiteSpectralData_ivas( FOR( j = i - level; j < stop; j++ ) { - tmp_16 = extract_h( L_shl( in[j], s_l ) ); - ak = L_mac( ak, tmp_16, tmp_16 ); + tmp_16 = extract_h( L_shl( in[j], s_l ) ); // e: in_e - s_l + ak = L_mac( ak, tmp_16, tmp_16 ); // e: 2 * (in_e - s_l) } ak = L_deposit_h( BASOP_Util_Divide3216_Scale( ak, sub( stop, sub( i, level ) ), &tmp_e ) ); ak_e = add( tmp_e, sub( shl( sub( in_e, s_l ), 1 ), 15 ) ); // tmp_e + 2 * (in_e - s_l) - 15 @@ -3004,7 +3008,7 @@ static void IGF_getWhiteSpectralData_ivas( move16(); FOR( i = start; i < stop; i++ ) { - out[i] = L_shr( in[i], *out_e - out_e_arr[i] ); + out[i] = L_shr( in[i], sub( *out_e, out_e_arr[i] ) ); move32(); } @@ -3153,20 +3157,20 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in /* set/reset all values to default = IGF_WHITENING_OFF */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } IF( isIndepFrame == 0 ) { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( tmp == 1 ) { FOR( p = 0; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; // Q0 move16(); } } @@ -3181,7 +3185,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in } ELSE { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( EQ_16( tmp, 1 ) ) @@ -3195,7 +3199,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in { FOR( p = 1; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; // Q0 move16(); } } @@ -3204,7 +3208,7 @@ void IGFDecReadData_ivas_fx( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in /* save current level for concealment */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; + hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; // Q0 move16(); } @@ -3238,27 +3242,27 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins /* set/reset all values to default = IGF_WHITENING_OFF */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; + hPrivateData->currWhiteningLevel[p] = IGF_WHITENING_OFF; // Q0 move16(); } IF( isIndepFrame == 0 ) { - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 } IF( EQ_16( tmp, 1 ) ) { FOR( p = 0; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->prevWhiteningLevel[p]; // Q0 move16(); } } ELSE { IGF_decode_whitening_level( st, hPrivateData, 0 ); - tmp = get_next_indice_fx( st, 1 ); + tmp = get_next_indice_fx( st, 1 ); // Q0 IF( EQ_16( tmp, 1 ) ) { FOR( p = 1; p < nT; p++ ) @@ -3270,7 +3274,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins { FOR( p = 1; p < nT; p++ ) { - hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; + hPrivateData->currWhiteningLevel[p] = hPrivateData->currWhiteningLevel[0]; // Q0 move16(); } } @@ -3279,7 +3283,7 @@ void IGFDecReadData( const IGF_DEC_INSTANCE_HANDLE hInstance, /**< in: | ins /* save current level for concealment */ FOR( p = 0; p < IGF_MAX_TILES; p++ ) { - hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; + hPrivateData->prevWhiteningLevel[p] = hPrivateData->currWhiteningLevel[p]; // Q0 move16(); } @@ -3312,7 +3316,7 @@ void IGFDecReadLevel( /**< ou hGrid = &hPrivateData->igfInfo.grid[igfGridIdx]; m_igfSfbStart = hGrid->startSfb; move16(); - IGFAllZero = get_next_indice_fx( st, 1 ); + IGFAllZero = get_next_indice_fx( st, 1 ); // Q0 IF( IGFAllZero == 0 ) { @@ -4256,7 +4260,7 @@ void IGFDecCopyLPCFlatSpectrum_fx( hPrivateData->pSpecFlat_exp = 30; move16(); - Copy_Scale_sig32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine, sub( pSpectrumFlat_exp, 20 ) ); + Copy_Scale_sig32( pSpectrumFlat, hPrivateData->pSpecFlat, hGrid->startLine, sub( pSpectrumFlat_exp, 20 ) ); // Q11 } } diff --git a/lib_dec/igf_scf_dec_fx.c b/lib_dec/igf_scf_dec_fx.c index e7e4fecb3..fe670df56 100644 --- a/lib_dec/igf_scf_dec_fx.c +++ b/lib_dec/igf_scf_dec_fx.c @@ -52,7 +52,7 @@ static Word16 quant_ctx_fx( result = s_min( abs_s( ctx ), IGF_CTX_OFFSET ); /* limit the absolute value to IGF_CTX_OFFSET */ - if ( ctx < 0 ) /* add the sign back, if needed */ + IF( ctx < 0 ) /* add the sign back, if needed */ { result = negate( result ); } @@ -90,7 +90,7 @@ static Word16 arith_decode_bits_fx( static Word16 arith_decode_residual_fx( IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */ Decoder_State *st, /* i/o: pointer to decoder state */ - const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used */ + const UWord16 *cumulativeFrequencyTable, /* i: cumulative frequency table to be used Q0 */ Word16 tableOffset /* i: offset used to align the table */ ) { @@ -100,49 +100,49 @@ static Word16 arith_decode_residual_fx( move16(); /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */ - val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); + val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); // Q0 /* meaning of the values of val: */ /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */ test(); IF( ( val != 0 ) && ( NE_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) ) { - x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ + x = add( val, -1 + IGF_MIN_ENC_SEPARATE ); /* (val - 1) + IGF_MIN_ENC_SEPARATE */ // Q0 - x = sub( x, tableOffset ); + x = sub( x, tableOffset ); // Q0 return x; } /* decode one of the tails of the distribution */ /* decode extra with 4 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 4 ); - IF( EQ_16( extra, 15 ) ) /* escape code 15 to indicate extra >= 15 */ + extra = arith_decode_bits_fx( hPrivateData, st, 4 ); // Q0 + IF( EQ_16( extra, 15 ) ) /* escape code 15 to indicate extra >= 15 */ { /* decode addtional extra with 6 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 6 ); - IF( EQ_16( extra, 63 ) ) /* escape code 63 to indicate extra >= 63 */ + extra = arith_decode_bits_fx( hPrivateData, st, 6 ); // Q0 + IF( EQ_16( extra, 63 ) ) /* escape code 63 to indicate extra >= 63 */ { /* decode safety extra with 7 bits */ - extra = arith_decode_bits_fx( hPrivateData, st, 7 ); + extra = arith_decode_bits_fx( hPrivateData, st, 7 ); // Q0 extra = add( 63, extra ); } - extra = add( 15, extra ); + extra = add( 15, extra ); // Q0 } - if ( val == 0 ) + IF( val == 0 ) { /* escape code 0 to indicate x <= IGF_MIN_ENC_SEPARATE - 1 */ - x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); + x = sub( IGF_MIN_ENC_SEPARATE - 1, extra ); // Q0 } - if ( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) + IF( EQ_16( val, IGF_SYMBOLS_IN_TABLE - 1 ) ) { /* escape code (IGF_SYMBOLS_IN_TABLE - 1) to indicate x >= IGF_MAX_ENC_SEPARATE + 1 */ - x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); + x = add( IGF_MAX_ENC_SEPARATE + 1, extra ); // Q0 } - x = sub( x, tableOffset ); + x = sub( x, tableOffset ); // Q0 return x; } @@ -193,7 +193,7 @@ static void decode_sfe_vector_fx( res = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, (const UWord16 *) hPrivateData->cf_se00 ); pred = arith_decode_bits_fx( hPrivateData, st, 2 ); /* LSBs as 2 bit raw */ - x[f] = add( shl( res, 2 ), pred ); + x[f] = add( shl( res, 2 ), pred ); // Q0 move16(); } ELSE IF( EQ_16( f, 1 ) ) @@ -203,8 +203,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se01, hPrivateData->cf_off_se01 ); - x[f] = add( x[0], res ); - move16(); /* f - increment is 0, pred = b */ + x[f] = add( x[0], res ); // Q0 + move16(); /* f - increment is 0, pred = b */ } ELSE { @@ -219,8 +219,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se02 + index1, hPrivateData->cf_off_se02[index2] ); - x[f] = add( x[prev_offset], res ); - move16(); /* pred = b */ + x[f] = add( x[prev_offset], res ); // Q0 + move16(); /* pred = b */ } } ELSE @@ -233,8 +233,8 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se10, hPrivateData->cf_off_se10 ); - x[f] = add( prev_x[f], res ); - move16(); /* pred = a */ + x[f] = add( prev_x[f], res ); // Q0 + move16(); /* pred = a */ } ELSE { @@ -257,7 +257,7 @@ static void decode_sfe_vector_fx( st, hPrivateData->cf_se11 + index1, hPrivateData->cf_off_se11[index2] ); - x[f] = add( pred, res ); + x[f] = add( pred, res ); // Q0 move16(); } } @@ -301,7 +301,7 @@ main decoder function void IGFSCFDecoderDecode( IGFSCFDEC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ Decoder_State *st, /* i/o: pointer to decoder state */ - int16_t *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ + Word16 *sfe, /* o : ptr to an array which will contain the decoded quantized coefficients */ const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 indepFlag /* i : if 1 on input the decoder will be forced to reset, if 0 on input the decoder will be forced to encode without a reset */ diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index 167da45f6..4cdefd6b0 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -86,29 +86,29 @@ ivas_error init_decoder_fx( set16_fx( st_fx->mem_MA_fx, 0, M ); - st_fx->dm_fx.prev_state = 0; - move16(); /* This corresponds to st_fx->dispMem in FLP */ - st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); + st_fx->dm_fx.prev_state = 0; // Q0 + move16(); /* This corresponds to st_fx->dispMem in FLP */ + st_fx->dm_fx.prev_gain_code = L_deposit_l( 0 ); // Q16 FOR( i = 2; i < 8; i++ ) { - st_fx->dm_fx.prev_gain_pit[i - 2] = 0; + st_fx->dm_fx.prev_gain_pit[i - 2] = 0; // Q14 move16(); } - st_fx->tilt_code_fx = 0; + st_fx->tilt_code_fx = 0; // Q15 move16(); - st_fx->gc_threshold_fx = L_deposit_l( 0 ); + st_fx->gc_threshold_fx = L_deposit_l( 0 ); // Q16 st_fx->last_good = UNVOICED_CLAS; move16(); st_fx->clas_dec = UNVOICED_CLAS; move16(); - st_fx->lp_gainp_fx = 0; + st_fx->lp_gainp_fx = 0; // Q14 move16(); - st_fx->lp_gainc_fx = 0; + st_fx->lp_gainc_fx = 0; // Q3 move16(); - set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); + set16_fx( st_fx->old_exc_fx, 0, L_EXC_MEM_DEC ); // Q_exc /* AVQ pre-quantizer memory */ st_fx->mem_preemp_preQ_fx = 0; @@ -118,7 +118,7 @@ ivas_error init_decoder_fx( st_fx->use_acelp_preq = 0; move16(); - st_fx->mem_deemph_fx = 0; + st_fx->mem_deemph_fx = 0; // Q_syn move16(); /*-----------------------------------------------------------------* * SWB BWE parameters @@ -178,13 +178,12 @@ ivas_error init_decoder_fx( st_fx->hBWE_FD_HR = NULL; } set16_fx( st_fx->mem_syn1_fx, 0, M ); - move16(); set16_fx( st_fx->mem_syn2_fx, 0, M ); - st_fx->stab_fac_fx = 0; + st_fx->stab_fac_fx = 0; // Q15 move16(); - st_fx->stab_fac_smooth_fx = 0; + st_fx->stab_fac_smooth_fx = 0; // Q15 move16(); - set16_fx( st_fx->agc_mem_fx, 0, 2 ); + set16_fx( st_fx->agc_mem_fx, 0, 2 ); // Q0 set32_fx( st_fx->L_mem_hp_out_fx, 0, 5 ); set16_fx( st_fx->mem_syn3_fx, 0, M ); @@ -197,7 +196,7 @@ ivas_error init_decoder_fx( move16(); st_fx->GSC_noisy_speech = 0; move16(); - st_fx->last_voice_factor_fx = 0; + st_fx->last_voice_factor_fx = 0; // Q6 move16(); set16_fx( st_fx->prev_lpc_wb_fx, 0, LPC_SHB_ORDER_WB ); @@ -251,30 +250,31 @@ ivas_error init_decoder_fx( } Init_post_filter_fx( st_fx->hPFstat ); - st_fx->psf_lp_noise_fx = 0; + st_fx->psf_lp_noise_fx = 0; // Q8 + move16(); } ELSE { st_fx->hPFstat = NULL; } - st_fx->psf_lp_noise_fx = 0; + st_fx->psf_lp_noise_fx = 0; // Q8 move16(); /* FEC */ st_fx->scaling_flag = 0; move16(); - st_fx->lp_ener_FEC_av = 500000; + st_fx->lp_ener_FEC_av = 500000; // Q0 move32(); - st_fx->lp_ener_FEC_max = 500000; + st_fx->lp_ener_FEC_max = 500000; // Q0 move32(); st_fx->prev_bfi = 0; move16(); - st_fx->lp_ener_FER_fx = 15360; - move16(); /*60 in Q8*/ - st_fx->old_enr_LP = 0; + st_fx->lp_ener_FER_fx = 15360; // Q8 + move16(); /*60 in Q8*/ + st_fx->old_enr_LP = 0; // Q5 move16(); - st_fx->lp_ener_fx = L_deposit_l( 0 ); - st_fx->enr_old_fx = L_deposit_l( 0 ); + st_fx->lp_ener_fx = L_deposit_l( 0 ); // Q6 + st_fx->enr_old_fx = L_deposit_l( 0 ); // Q0 st_fx->bfi_pitch_fx = L_SUBFR_Q6; move16(); st_fx->bfi_pitch_frame = L_SUBFR; @@ -287,8 +287,8 @@ ivas_error init_decoder_fx( FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; - move32(); /*15Q16*/ + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; // Q16 + move32(); /*15Q16*/ } st_fx->upd_cnt = MAX_UPD_CNT; @@ -315,12 +315,12 @@ ivas_error init_decoder_fx( move16(); st_fx->act_count = 3; move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); + Copy( st_fx->lsp_old_fx, st_fx->lspold_s_fx, M ); // Q15 st_fx->noimix_seed = RANDOM_INITSEED; move16(); - st_fx->min_alpha_fx = 32767; - move16(); /*1; Q15*/ - st_fx->exc_pe_fx = 0; + st_fx->min_alpha_fx = 32767; // Q15 + move16(); /*1; Q15*/ + st_fx->exc_pe_fx = 0; // Q_stat_noise move16(); #ifdef MSAN_FIX st_fx->Q_stat_noise = 31; @@ -370,14 +370,14 @@ ivas_error init_decoder_fx( move16(); /* RXDTX handeler previous frametype flag for G.192 format AMRWB SID_FIRST detection */ st_fx->first_CNG = 0; move16(); - Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); - st_fx->shb_cng_ener_fx = -1541; + Copy( st_fx->lsp_old_fx, st_fx->lspCNG_fx, M ); // Q15 + st_fx->shb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->wb_cng_ener_fx = -1541; + st_fx->wb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->last_wb_cng_ener_fx = -1541; + st_fx->last_wb_cng_ener_fx = -1541; // Q8 move16(); - st_fx->last_shb_cng_ener_fx = -1541; + st_fx->last_shb_cng_ener_fx = -1541; // Q8 move16(); st_fx->swb_cng_seed = RANDOM_INITSEED; move16(); @@ -388,13 +388,12 @@ ivas_error init_decoder_fx( move32(); st_fx->last_CNG_L_frame = L_FRAME; move16(); - move16(); FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { - st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; + st_fx->lsp_shb_prev_fx[i] = lsp_shb_prev_tbl_fx[i]; // Q15 move16(); - st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; + st_fx->lsp_shb_prev_prev_fx[i] = st_fx->lsp_shb_prev_fx[i]; // Q15 move16(); } @@ -404,12 +403,12 @@ ivas_error init_decoder_fx( move16(); st_fx->trans_cnt_fx = 0; move16(); - st_fx->last_shb_ener_fx = 0; + st_fx->last_shb_ener_fx = 0; // Q8 move16(); /* HF (6-7kHz) BWE */ move16(); - st_fx->Q_stat_noise_ge = GE_SHIFT; + st_fx->Q_stat_noise_ge = GE_SHIFT; // Q of ge_sm_fx move16(); st_fx->cngTDLevel = 0; move16(); @@ -448,15 +447,12 @@ ivas_error init_decoder_fx( ELSE { st_fx->hHQ_nbfec = NULL; - move16(); } } ELSE { st_fx->hHQ_core = NULL; st_fx->hHQ_nbfec = NULL; - move16(); - move16(); } st_fx->Qprev_synth_buffer_fx = 15; move16(); @@ -521,7 +517,7 @@ ivas_error init_decoder_fx( move16(); move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); set16_fx( st_fx->prev_synth_buffer_fx, 0, NS2SA_FX2( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); @@ -557,14 +553,14 @@ ivas_error init_decoder_fx( st_fx->hBWE_TD = NULL; } - st_fx->tilt_swb_fx = 0; + st_fx->tilt_swb_fx = 0; // Q24 move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); - st_fx->prev_ener_shb_fx = 0; + st_fx->prev_ener_shb_fx = 0; // Q1 move16(); - st_fx->prev_enerLH_fx = 0; + st_fx->prev_enerLH_fx = 0; // Q1 move16(); st_fx->enerLH_fx = L_deposit_l( 0 ); st_fx->enerLL_fx = L_deposit_l( 0 ); @@ -578,7 +574,7 @@ ivas_error init_decoder_fx( move16(); st_fx->bws_cnt1 = N_NS2W_FRAMES; move16(); - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; // Q15 move16(); st_fx->last_inner_frame = L_FRAME8k; move16(); @@ -1038,7 +1034,7 @@ ivas_error init_decoder_ivas_fx( FOR( i = 0; i < 2 * NB_SUBFR16k; i++ ) { - st_fx->old_pitch_buf_fx[i] = L_shl( L_SUBFR, 16 ); /*15Q16*/ + st_fx->old_pitch_buf_fx[i] = L_SUBFR << 16; /*15Q16*/ move32(); } @@ -1077,7 +1073,7 @@ ivas_error init_decoder_ivas_fx( st_fx->prev_coder_type = GENERIC; move16(); - st_fx->tilt_wb_fx = 0; + st_fx->tilt_wb_fx = 0; // Q11 move16(); st_fx->last_voice_factor_fx = 0; @@ -1341,11 +1337,11 @@ ivas_error init_decoder_ivas_fx( * WB/SWB bandwidth switching parameters *-----------------------------------------------------------------*/ - st_fx->tilt_swb_fx = 0; + st_fx->tilt_swb_fx = 0; // Q24 move16(); - st_fx->prev_ener_shb_fx = 0; + st_fx->prev_ener_shb_fx = 0; // Q1 move16(); - st_fx->prev_enerLH_fx = 0; + st_fx->prev_enerLH_fx = 0; // Q1 move16(); st_fx->enerLH_fx = L_deposit_l( 0 ); st_fx->enerLL_fx = L_deposit_l( 0 ); @@ -1359,7 +1355,7 @@ ivas_error init_decoder_ivas_fx( move16(); st_fx->bws_cnt1 = N_NS2W_FRAMES; move16(); - st_fx->attenu_fx = 3277; + st_fx->attenu_fx = 3277; // Q15 move16(); st_fx->last_inner_frame = L_FRAME8k; move16(); diff --git a/lib_dec/inov_dec_fx.c b/lib_dec/inov_dec_fx.c index 05f7f9809..96ebf8ec7 100644 --- a/lib_dec/inov_dec_fx.c +++ b/lib_dec/inov_dec_fx.c @@ -41,16 +41,16 @@ void inov_decode_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ) { Word16 nBits; @@ -85,7 +85,7 @@ void inov_decode_fx( { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; // Q0 move16(); IF( EQ_16( nBits, 8 ) ) @@ -110,19 +110,19 @@ void inov_decode_fx( } ELSE { - wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); // Q0 move16(); - bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0 move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, 16 ) ); + indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, 16 ) ); // Q0 move16(); } IF( bitcnt ) { - indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, bitcnt ) ); + indexing_indices[i] = extract_l( get_next_indice_fx( st_fx, bitcnt ) ); // Q0 move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; @@ -136,7 +136,7 @@ void inov_decode_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; // Q0 move16(); IF( EQ_16( nBits, 7 ) ) @@ -226,16 +226,16 @@ void inov_decode_fx( void inov_decode_ivas_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : core bitrate */ - const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode */ - const Word16 L_frame, /* i : length of the frame */ - const Word16 sharpFlag, /* i : formant sharpening flag */ - const Word16 i_subfr, /* i : subframe index */ + const Word32 core_brate, /* i : core bitrate Q0 */ + const Word16 Opt_AMR_WB, /* i : flag indicating AMR-WB IO mode Q0 */ + const Word16 L_frame, /* i : length of the frame Q0 */ + const Word16 sharpFlag, /* i : formant sharpening flag Q0 */ + const Word16 i_subfr, /* i : subframe index Q0 */ const Word16 *p_Aq, /* i : LP filter coefficients Q12 */ const Word16 tilt_code, /* i : tilt of the excitation of previous subframe Q15 */ const Word16 pt_pitch, /* i : pointer to current subframe fractional pitch Q6*/ - Word16 *code, /* o : algebraic excitation */ - const Word16 L_subfr /* i : subframe length */ + Word16 *code, /* o : algebraic excitation Q12 */ + const Word16 L_subfr /* i : subframe length Q0 */ ) { Word16 nBits; @@ -270,7 +270,8 @@ void inov_decode_ivas_fx( { IF( EQ_16( L_subfr, 2 * L_SUBFR ) ) { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_subfr]; // Q0 + move16(); IF( EQ_16( nBits, 8 ) ) { @@ -281,7 +282,7 @@ void inov_decode_ivas_fx( dec_acelp_fast_fx( st_fx, nBits, code, L_subfr ); } } - ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( EQ_16( st_fx->idchan, 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) + ELSE IF( ( EQ_16( st_fx->idchan, 1 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 7 ) ) || ( ( st_fx->idchan == 0 ) && LE_16( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR], 3 ) ) ) { IF( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] == 0 ) { @@ -294,18 +295,20 @@ void inov_decode_ivas_fx( } ELSE { - wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); + wordcnt = shr( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 4 ); // Q0 move16(); - bitcnt = ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ) & 15; + bitcnt = s_and( ACELP_FIXED_CDK_BITS( st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR] ), 15 ); // Q0 move16(); // PMT("CONDITION above is missing -> idchan") FOR( i = 0; i < wordcnt; i++ ) { - indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); + indexing_indices[i] = get_next_indice_fx( st_fx, 16 ); // Q0 + move16(); } IF( bitcnt ) { - indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); + indexing_indices[i] = get_next_indice_fx( st_fx, bitcnt ); // Q0 + move16(); } config = PulseConfTable[st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]]; D_ACELP_indexing_fx( code, config, NB_TRACK_FCB_4T, indexing_indices, &st_fx->BER_detect ); @@ -318,7 +321,7 @@ void inov_decode_ivas_fx( } ELSE { - nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; + nBits = st_fx->acelp_cfg.fixed_cdk_index[i_subfr / L_SUBFR]; // Q0 move16(); IF( EQ_16( nBits, 7 ) ) diff --git a/lib_dec/ivas_mono_dmx_renderer.c b/lib_dec/ivas_mono_dmx_renderer.c index 57a658f4b..b6c8d0273 100644 --- a/lib_dec/ivas_mono_dmx_renderer.c +++ b/lib_dec/ivas_mono_dmx_renderer.c @@ -213,7 +213,7 @@ void ivas_mono_downmix_render_passive( #else void ivas_mono_downmix_render_passive_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono output Qin = 11/ Qout = 8*/ const Word16 output_frame /* i : output frame length */ ) { @@ -353,7 +353,7 @@ void ivas_mono_downmix_render_passive_fx( } ELSE { - eq_fx = 16384; + eq_fx = 16384; // 0.5.Q15 move16(); } @@ -415,7 +415,7 @@ void ivas_mono_stereo_downmix_mcmasa( #else void ivas_mono_stereo_downmix_mcmasa_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output */ + Word32 *output_f_fx[], /* i/o: synthesized core-coder transport channels/mono or stereo output Q11*/ Word16 output_frame /* i : output frame length per channel */ ) { @@ -429,8 +429,8 @@ void ivas_mono_stereo_downmix_mcmasa_fx( test(); IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 2 ) && st_ivas->hOutSetup.separateChannelEnabled ) { - v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[0], output_frame ); - v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[1], output_frame ); + v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[0], output_frame ); // Q11 + v_multc_acc_32_16( output_f_fx[st_ivas->hOutSetup.separateChannelIndex], INV_SQRT2_FX_Q15, output_f_fx[1], output_frame ); // Q11 } /* Mono downmix */ ELSE IF( EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) ) @@ -438,7 +438,7 @@ void ivas_mono_stereo_downmix_mcmasa_fx( /* Downmix L and R to dmx_tmp */ FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { - v_multc_acc_32_16( output_f_fx[i], INV_SQRT2_FX_Q15, dmx_tmp_fx, output_frame ); + v_multc_acc_32_16( output_f_fx[i], INV_SQRT2_FX_Q15, dmx_tmp_fx, output_frame ); // Q11 } /* Add center channel */ IF( st_ivas->hOutSetup.separateChannelEnabled ) @@ -447,7 +447,7 @@ void ivas_mono_stereo_downmix_mcmasa_fx( } /* Move to output */ - Copy32( dmx_tmp_fx, output_f_fx[0], output_frame ); + Copy32( dmx_tmp_fx, output_f_fx[0], output_frame ); // Q11 } return; @@ -483,13 +483,13 @@ void ivas_apply_non_diegetic_panning( #else void ivas_apply_non_diegetic_panning_fx( Word32 *output_f_fx[], /* i/o: core-coder transport mono channel/stereo output */ - const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain */ - const Word16 output_frame /* i : output frame length per channel */ + const Word16 non_diegetic_pan_gain_fx, /* i : non-diegetic panning gain Q15*/ + const Word16 output_frame /* i : output frame length per channel Q11*/ ) { Word16 pan_left_fx, pan_right_fx; - pan_left_fx = add( mult( non_diegetic_pan_gain_fx, 16348 ), 16348 ); + pan_left_fx = add( mult( non_diegetic_pan_gain_fx, 16384 ), 16384 ); // 0.5.Q15 = 16384 pan_right_fx = sub( 32767, pan_left_fx ); v_multc_fixed( output_f_fx[0], L_shl( L_deposit_l( pan_right_fx ), 16 ), output_f_fx[1], output_frame ); diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index ecc449182..e304edf6c 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -95,7 +95,7 @@ ivas_error ivas_td_binaural_open( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output[], /* i/o: SCE channels / Binaural synthesis */ + Word32 *output[], /* i/o: SCE channels / Binaural synthesis Q11*/ const Word16 output_frame /* i : output frame length */ ) { @@ -169,9 +169,9 @@ ivas_error ivas_td_binaural_renderer( #ifdef IVAS_FLOAT_FIXED ivas_error ivas_td_binaural_renderer_sf_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis */ - const int16_t n_samples_granularity /* i : granularity of the renderer/buffer */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + Word32 *output_fx[], /* i/o: SCE channels / Binaural synthesis Q11*/ + const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */ ) { Word16 first_sf, last_sf, subframe_idx; @@ -245,7 +245,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { - output_fx_local[ch] = output_fx[ch]; + output_fx_local[ch] = output_fx[ch]; // Q11 } slot_size = st_ivas->hTcBuffer->n_samples_granularity; @@ -342,7 +342,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( scale_sig32( tc_local_fx[i], st_ivas->hReverb->full_block_size, -4 ); // Q11 - 4 = Q7 } - IF( NE_32( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_reverb_process_fx( st_ivas->hReverb, st_ivas->transport_config, 0, tc_local_fx, p_reverb_signal_fx, 0 ) ), IVAS_ERR_OK ) ) // Q(p_reverb_signal_fx) = 11 { return error; } @@ -370,7 +370,7 @@ ivas_error ivas_td_binaural_renderer_sf_fx( IF( st_ivas->hRenderConfig != NULL && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { /* add reverb to rendered signals */ - v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); + v_add_32( reverb_signal_fx[0], output_fx_local[0], output_fx_local[0], output_frame ); // Q11 v_add_32( reverb_signal_fx[1], output_fx_local[1], output_fx_local[1], output_frame ); } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index bb0e65b26..4771a8055 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -131,16 +131,16 @@ ivas_error ivas_omasa_data_open_fx( { hMasaIsmData->ismPreprocMatrix_fx[ch][ch][bin] = 32767; /* 1.0f in Q15 */ move16(); - hMasaIsmData->ismPreprocMatrix_fx[1 - ch][ch][bin] = 0; + hMasaIsmData->ismPreprocMatrix_fx[1 - ch][ch][bin] = 0; // Q15 move16(); - hMasaIsmData->eneMoveIIR_fx[ch][bin] = 0; + hMasaIsmData->eneMoveIIR_fx[ch][bin] = 0; // Q22 move32(); - hMasaIsmData->enePreserveIIR_fx[ch][bin] = 0; + hMasaIsmData->enePreserveIIR_fx[ch][bin] = 0; // Q22 move32(); } - hMasaIsmData->preprocEneTarget_fx[bin] = 0; + hMasaIsmData->preprocEneTarget_fx[bin] = 0; // Q19 move32(); - hMasaIsmData->preprocEneRealized_fx[bin] = 0; + hMasaIsmData->preprocEneRealized_fx[bin] = 0; // Q19 move32(); } @@ -152,9 +152,9 @@ ivas_error ivas_omasa_data_open_fx( { hMasaIsmData->ism_is_edited[ch] = 0; move16(); - hMasaIsmData->q_elevation_old_fx[ch] = 0; + hMasaIsmData->q_elevation_old_fx[ch] = 0; // Q22 move32(); - hMasaIsmData->q_azimuth_old_fx[ch] = 0; + hMasaIsmData->q_azimuth_old_fx[ch] = 0; // Q22 move32(); } @@ -227,7 +227,7 @@ void ivas_omasa_data_close_fx( { FOR( i = 0; i < ( *hMasaIsmData )->delayBuffer_nchan; i++ ) { - free( ( *hMasaIsmData )->delayBuffer_fx[i] ); + free( ( *hMasaIsmData )->delayBuffer_fx[i] ); // Q11 } free( ( *hMasaIsmData )->delayBuffer_fx ); ( *hMasaIsmData )->delayBuffer_fx = NULL; @@ -253,7 +253,7 @@ ivas_error ivas_omasa_dec_config_fx( UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *num_src, Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal Qx*/ ) { Word16 k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; @@ -362,14 +362,14 @@ ivas_error ivas_omasa_dec_config_fx( FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - ism_total_brate = L_add( ism_total_brate, sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )] ); + ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); } brate_SCE = 0; move32(); IF( st_ivas->nSCE > 0 ) { - brate_SCE = sep_object_brate[sub( k, 2 )][sub( st_ivas->nSCE, 1 )]; + brate_SCE = sep_object_brate[k - 2][st_ivas->nSCE - 1]; move32(); } brate_CPE = L_sub( ivas_total_brate, ism_total_brate ); @@ -954,7 +954,7 @@ void ivas_set_surplus_brate_dec( tmp = idiv1616( bits_ism, st_ivas->nchan_ism ); } set16_fx( bits_element, tmp, st_ivas->nchan_ism ); - bits_element[sub( st_ivas->nchan_ism, 1 )] = add( bits_element[sub( st_ivas->nchan_ism, 1 )], bits_ism % st_ivas->nchan_ism ); + bits_element[st_ivas->nchan_ism - 1] = add( bits_element[st_ivas->nchan_ism - 1], bits_ism % st_ivas->nchan_ism ); move16(); bitbudget_to_brate( bits_element, element_brate, st_ivas->nchan_ism ); @@ -1136,12 +1136,12 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( { // azimuth_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->azimuth + 0.5f ); // elevation_ism = (int16_t) ( st_ivas->hIsmMetaData[n]->elevation + 0.5f ); - azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->azimuth_fx ), 22 ) ); + azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->azimuth_fx /*Q22*/ ), 22 ) ); // Q0 if ( st_ivas->hIsmMetaData[n]->azimuth_fx < 0 ) { azimuth_ism = negate( azimuth_ism ); } - elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->elevation_fx ), 22 ) ); + elevation_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[n]->elevation_fx /*Q22*/ ), 22 ) ); // Q0 if ( st_ivas->hIsmMetaData[n]->elevation_fx < 0 ) { elevation_ism = negate( elevation_ism ); @@ -1243,7 +1243,7 @@ void ivas_omasa_dirac_rend_jbm_fx( UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_f[] /* o : rendered time signal */ + Word32 *output_f[] /* o : rendered time signal Q11*/ ) { Word16 subframes_rendered; @@ -1367,15 +1367,15 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( UWord16 *nSamplesRendered, /* o : number of samples rendered */ UWord16 *nSamplesAvailable, /* o : number of samples still to render */ const Word16 nchan_transport, /* i : number of transport channels */ - Word32 *output_fx[] /* o : rendered time signal */ + Word32 *output_fx[] /* o : rendered time signal Q11*/ ) { Word16 n; - Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; + Word16 gain_fx = OMASA_TDREND_MATCHING_GAIN_FX; // Q15 move16(); ivas_error error; Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS]; - Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; + Word32 *p_sepobj_fx[MAX_NUM_OBJECTS]; // Q11 Word32 data_separated_objects_fx[MAX_NUM_OBJECTS][L_FRAME48k]; move16(); @@ -1393,7 +1393,7 @@ ivas_error ivas_omasa_dirac_td_binaural_jbm_fx( FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; + tc_local_fx[n] = st_ivas->hTcBuffer->tc_fx[n + 2]; // Q11 v_multc_fixed_16( tc_local_fx[n], gain_fx, tc_local_fx[n], tcBufferSize ); delay_signal_fx( tc_local_fx[n], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer_fx[n], st_ivas->hMasaIsmData->delayBuffer_size ); @@ -1449,13 +1449,13 @@ void ivas_omasa_rearrange_channels( } #else void ivas_omasa_rearrange_channels_fx( - Word32 *output[], /* o : output synthesis signal */ + Word32 *output[], /* o : output synthesis signal Q11*/ const Word16 nchan_transport_ism, /* o : number of ISM TCs */ const Word16 output_frame /* i : output frame length per channel */ ) { Word16 n; - Word32 tmp_buff[CPE_CHANNELS][L_FRAME48k]; + Word32 tmp_buff[CPE_CHANNELS][L_FRAME48k]; // Q11 Copy32( output[0], tmp_buff[0], output_frame ); Copy32( output[1], tmp_buff[1], output_frame ); diff --git a/lib_dec/ivas_osba_dec.c b/lib_dec/ivas_osba_dec.c index b45bd339c..d5fc88441 100644 --- a/lib_dec/ivas_osba_dec.c +++ b/lib_dec/ivas_osba_dec.c @@ -199,7 +199,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */ - Word32 *output_fx[], /* o : rendered time signal */ + Word32 *output_fx[], /* o : rendered time signal Q11*/ Word16 out_len /*Store the length of values in each channel*/ ) { @@ -232,7 +232,7 @@ ivas_error ivas_osba_dirac_td_binaural_jbm_fx( Word16 i; FOR( i = 0; i < nSamplesAsked; i++ ) { - output_fx[n][i] = L_add( L_shr( output_fx[add( channel_offset, n )][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); + output_fx[n][i] = L_add( L_shr( output_fx[channel_offset + n][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) ); move32(); } } @@ -355,7 +355,7 @@ ivas_error ivas_osba_render_sf_fx( const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */ UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */ UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render */ - Word32 *p_output[] /* o : rendered time signal */ + Word32 *p_output[] /* o : rendered time signal Q11*/ ) { Word16 n; @@ -370,7 +370,7 @@ ivas_error ivas_osba_render_sf_fx( FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { - v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); + v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); // Q11 } IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output, 960 ) ), IVAS_ERR_OK ) ) diff --git a/lib_dec/ivas_out_setup_conversion.c b/lib_dec/ivas_out_setup_conversion.c index d386b3c85..14da4b0fa 100644 --- a/lib_dec/ivas_out_setup_conversion.c +++ b/lib_dec/ivas_out_setup_conversion.c @@ -72,20 +72,20 @@ #ifdef IVAS_FLOAT_FIXED static void ivas_lssetupconversion_computeEQFactor_fx( - Word32 *outputEnergy, - Word32 *inputEnergy, + Word32 *outputEnergy, // Q0 + Word32 *inputEnergy, // Q0 Word32 *EQ ) { IF( GE_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MAX_SQ_Q28, *inputEnergy ) ) ) { - *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MAX_Q29, 1 ); + *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MAX_Q29, 1 ); // Q30 move32(); return; } IF( LE_32( L_shr( *outputEnergy, 3 ), Mpy_32_32( LS_OUT_CONV_CLIP_FACTOR_MIN_SQ_Q28, *inputEnergy ) ) ) { - *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MIN_Q29, 1 ); + *EQ = L_shl_sat( LS_OUT_CONV_CLIP_FACTOR_MIN_Q29, 1 ); // Q30 move32(); return; } @@ -93,7 +93,7 @@ static void ivas_lssetupconversion_computeEQFactor_fx( test(); IF( ( *outputEnergy == 0 ) && ( *inputEnergy == 0 ) ) { - *EQ = ONE_IN_Q30; + *EQ = ONE_IN_Q30; // Q30 move32(); return; } @@ -360,7 +360,7 @@ static void get_custom_ls_conversion_matrix_fx( } ELSE { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = tmp_gains[ch_out_woLFE]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = tmp_gains[ch_out_woLFE]; // Q30 move32(); } } @@ -488,12 +488,12 @@ static ivas_error get_ls_conversion_matrix_fx( { IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) ) { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_mono_fx[k][ch_out]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_mono_fx[k][ch_out]; // Q30 move32(); } ELSE { - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_stereo_fx[k][ch_out]; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = ls_conversion_cicpX_stereo_fx[k][ch_out]; // Q30 move32(); } } @@ -520,7 +520,7 @@ static ivas_error get_ls_conversion_matrix_fx( { index = conversion_matrix_fx[k].index; move16(); - value = conversion_matrix_fx[k].value; + value = conversion_matrix_fx[k].value; // Q30 move16(); IF( index != 0 ) @@ -533,8 +533,9 @@ static ivas_error get_ls_conversion_matrix_fx( move16(); } ch_out = index % nchan_out; + move16(); - hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = value; + hLsSetUpConversion->dmxMtx_fx[ch_in][ch_out] = value; // Q30 move32(); } } @@ -1026,14 +1027,14 @@ void ivas_ls_setup_conversion_fx( Decoder_Struct *st_ivas, /* i : IVAS decoder structure */ const Word16 input_chans, /* i : number of input channels to the renderer */ const Word16 output_frame, /* i : frame length */ - Word32 *input[], /* i : LS input/output synthesis signal */ - Word32 *output[] /* i/o: LS input/output synthesis signal */ + Word32 *input[], /* i : LS input/output synthesis signal Q16*/ + Word32 *output[] /* i/o: LS input/output synthesis signal Q16*/ ) { Word16 chInIdx, chOutIdx, idx; LSSETUP_CONVERSION_HANDLE hLsSetUpConversion; Word32 dmxCoeff, tmpVal; - Word32 output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 output_tmp[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // Q16 push_wmops( "LS_Renderer" ); @@ -1207,8 +1208,8 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - x[chInIdx][0] = output[chInIdx]; - x[chInIdx][1] = output[chInIdx] + L_FRAME48k / 2; + x[chInIdx][0] = output[chInIdx]; // Q(q_output) + x[chInIdx][1] = output[chInIdx] + L_FRAME48k / 2; // Q(q_output) } /* Assign all the declared handles*/ @@ -1250,7 +1251,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; // Q30 move32(); test(); @@ -1265,10 +1266,10 @@ void ivas_ls_setup_conversion_process_mdct_fx( /* Convert the signal resolution to TCX20 */ /* initially, set pointers to input; if conversion occurs in (sub)frame, set to convertRes */ - pTmp[0] = x[chInIdx][0]; + pTmp[0] = x[chInIdx][0]; // Q(q_output) sig[0] = pTmp[0]; pTmp[1] = x[chInIdx][1]; - sig[1] = pTmp[1]; + sig[1] = pTmp[1]; // Q(q_output) /* convert (sub)frames to higher frequency resolution */ IF( NE_16( transform_type[chInIdx][0], TCX_20 ) ) @@ -1295,7 +1296,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( move32(); FOR( i = 1; i < frameSize - 1; i++ ) { - mdst[i] = L_sub( sig[0][i + 1], sig[0][i - 1] ); + mdst[i] = L_sub( sig[0][i + 1], sig[0][i - 1] ); // Q(q_output) } FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) @@ -1361,9 +1362,9 @@ void ivas_ls_setup_conversion_process_mdct_fx( move32(); dmxEnergy[bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[bandIdx] ), Mpy_32_32( ( ONE_IN_Q31 - LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] ) ); move32(); - hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy[bandIdx]; + hLsSetUpConversion->targetEnergyPrev_fx[0][bandIdx] = targetEnergy[bandIdx]; // exp( hLsSetUpConversion->te_prev_exp) (Q0 here) move32(); - hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; + hLsSetUpConversion->dmxEnergyPrev_fx[0][bandIdx] = dmxEnergy[bandIdx]; // exp( hLsSetUpConversion->dmx_prev_exp) (Q0) move32(); hLsSetUpConversion->te_prev_exp = 31; move16(); @@ -1399,7 +1400,7 @@ void ivas_ls_setup_conversion_process_mdct_fx( move16(); /* Compute Eq gains */ - ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); + ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[bandIdx], &dmxEnergy[bandIdx], &eqGain ); // Q(eqGain) = 30 FOR( binIdx = start; binIdx < stop; binIdx++ ) { x[chInIdx][0][binIdx] = Mpy_32_32( L_shl( x[chInIdx][0][binIdx], 1 ), eqGain ); // Q - 1 @@ -1870,15 +1871,16 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { IF( NE_16( mct_chan_mode[idx], MCT_CHAN_MODE_IGNORE ) ) { - real_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( sig_fx[idx][0][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ - imag_in_buffer_fx[add( i, i_mult( num_bands, idx ) )] = L_shr( mdst_fx[idx][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + real_in_buffer_fx[i + ( num_bands * idx )] = L_shr( sig_fx[idx][0][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ + imag_in_buffer_fx[i + ( num_bands * idx )] = L_shr( mdst_fx[idx][band], sub( max_e, x_e[idx][0] ) ); /*Setting the exponent to max_e*/ move32(); move32(); } } } Word16 shift = 1; - FOR( i = 0; i < i_mult( num_bands, nchan_transport ); ++i ) + move16(); + FOR( i = 0; i < num_bands * nchan_transport; ++i ) { real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], shift ); move32(); @@ -1898,11 +1900,13 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { DMXEne_fx = 0; + move16(); set_zero_fx( cy_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); set_zero_fx( Nrqq_fx, MAX_OUTPUT_CHANNELS ); set_zero_fx( target_ch_ener_fx, MAX_OUTPUT_CHANNELS ); /* Step 1.2, get target channel energies for the transported format as in ivas_param_mc_get_mono_stereo_mixing_matrices(), Nrqq calculation */ ild_q_fx = hParamMC->icld_q_fx + imult1616( bandIdx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ); + move16(); FOR( chInIdx = 0; chInIdx < nchan_transport_format; chInIdx++ ) { Word32 ref_ener_fx = 0; @@ -1914,7 +1918,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[chInIdx][ref_channel_cnt]; move16(); - ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][add( ref_channel_idx, i_mult( ref_channel_idx, nchan_transport ) )] ); /*Exponent=output_exp*/ + ref_ener_fx = L_add( ref_ener_fx, cx_fx[bandIdx][ref_channel_idx + ( ref_channel_idx * nchan_transport )] ); /*Exponent=output_exp*/ } Word32 temp; temp = BASOP_util_Pow2( L_mult0( ild_q_fx[chInIdx], 2721 /*log2(10)*(2^13)/10*/ ), exp_in, &exp_out ); @@ -1927,17 +1931,17 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( { FOR( i = 0; i < nchan_transport_format; i++ ) { - target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], L_shl( Mpy_32_32( Nrqq_fx[i], hParamMC->ls_conv_dmx_matrix_fx[add( chOutIdx, i_mult( i, nchan_out ) )] ), 1 ) ); /*output_exp + 2*/ + target_ch_ener_fx[chOutIdx] = L_add( target_ch_ener_fx[chOutIdx], L_shl( Mpy_32_32( Nrqq_fx[i], hParamMC->ls_conv_dmx_matrix_fx[chOutIdx + ( i * nchan_out )] ), 1 ) ); /*output_exp + 2*/ move32(); } - cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] = target_ch_ener_fx[chOutIdx]; + cy_fx[chOutIdx + ( nchan_out * chOutIdx )] = target_ch_ener_fx[chOutIdx]; move32(); } /* Step 1.4 final target energy for the band would then be the sum over the diagonal of Cy*/ FOR( chOutIdx = 0; chOutIdx < nchan_out; chOutIdx++ ) { - targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[add( chOutIdx, i_mult( nchan_out, chOutIdx ) )] ); /*exp=output_exp+2*/ + targetEnergy_fx[bandIdx] = L_add( targetEnergy_fx[bandIdx], cy_fx[chOutIdx + ( nchan_out * chOutIdx )] ); /*exp=output_exp+2*/ move32(); } @@ -2066,7 +2070,7 @@ void ivas_ls_setup_conversion_process_mdct_param_mc_fx( FOR( binIdx = start_tcx5; binIdx < stop_tcx5; binIdx++ ) { - x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][add( binIdx, shr( frameSize, 2 ) )], eqGain_fx ), 1 ); + x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )] = L_shl( Mult_32_32( x_fx[chInIdx][subFrameIdx][binIdx + ( frameSize >> 2 )], eqGain_fx ), 1 ); move32(); } } @@ -2416,8 +2420,8 @@ void ivas_ls_setup_conversion_process_mdct_param_mc( void ivas_lssetupconversion_process_param_mc_fx( Decoder_Struct *st_ivas, /* i/o: LS setup conversion renderer handle */ const Word16 num_timeslots, - Word32 Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ - Word32 Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals */ + Word32 Cldfb_RealBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals Q6*/ + Word32 Cldfb_ImagBuffer_InOut[MAX_CICP_CHANNELS][PARAM_MC_MAX_NSLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i/o: LS signals Q6*/ Word16 channel_active[MAX_CICP_CHANNELS] /* i : bitmap indicating which output channels are active */ ) { @@ -2463,15 +2467,15 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( k = 0; k < hLsSetUpConversion->sfbCnt; ++k ) { - Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); - Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); // Q(6 + q_output) + Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shl( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); // Q(6 + q_output) } } /* copy buffers */ FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - Copy32( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); - Copy32( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); + Copy32( Cldfb_RealBuffer_InOut[chInIdx][slotIdx], Cldfb_RealBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); // Q(6 + q_output) + Copy32( Cldfb_ImagBuffer_InOut[chInIdx][slotIdx], Cldfb_ImagBuffer_tmp[chInIdx], CLDFB_NO_CHANNELS_MAX ); // Q(6 + q_output) } /* set the buffers to zero */ FOR( chOutIdx = 0; chOutIdx < outChannels; chOutIdx++ ) @@ -2488,7 +2492,7 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( chInIdx = 0; chInIdx < inChannels; chInIdx++ ) { - dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; + dmxCoeff = hLsSetUpConversion->dmxMtx_fx[chInIdx][chOutIdx]; // Q30 move32(); IF( dmxCoeff == 0 ) { @@ -2496,13 +2500,14 @@ void ivas_lssetupconversion_process_param_mc_fx( } ELSE { - channel_active[chOutIdx] |= 1; + channel_active[chOutIdx] = s_or( 1, channel_active[chOutIdx] ); + move16(); FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_RealBuffer_tmp[chInIdx][bandIdx] ); + tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_RealBuffer_tmp[chInIdx][bandIdx] ); // Q(6 + q_output) Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] = L_add( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx], tmpDMXSig ); move32(); - targetEnergy[chOutIdx][bandIdx] = L_add( targetEnergy[chOutIdx][bandIdx], Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); + targetEnergy[chOutIdx][bandIdx] = L_add( targetEnergy[chOutIdx][bandIdx], Mpy_32_32( tmpDMXSig, tmpDMXSig ) ); // Q((6 + q_output)*2 - 31) move32(); tmpDMXSig = Mpy_32_32( L_shl_sat( dmxCoeff, 1 ), Cldfb_ImagBuffer_tmp[chInIdx][bandIdx] ); @@ -2522,12 +2527,12 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpReal = Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx]; // Q(6 + q_output) move32(); - tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; + tmpImag = Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx]; // Q(6 + q_output) move32(); - dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( tmpReal, tmpReal ), Mpy_32_32( tmpImag, tmpImag ) ); + dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( tmpReal, tmpReal ), Mpy_32_32( tmpImag, tmpImag ) ); // Q((6 + q_output)*2 - 31) move32(); } } @@ -2544,9 +2549,9 @@ void ivas_lssetupconversion_process_param_mc_fx( move32(); dmxEnergy[chOutIdx][bandIdx] = L_add( Mpy_32_32( LS_OUT_CONV_SMOOTHING_FACTOR_Q31, dmxEnergy[chOutIdx][bandIdx] ), Mpy_32_32( L_sub( ONE_IN_Q31, LS_OUT_CONV_SMOOTHING_FACTOR_Q31 ), hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] ) ); move32(); - hLsSetUpConversion->targetEnergyPrev_fx[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; + hLsSetUpConversion->targetEnergyPrev_fx[chOutIdx][bandIdx] = targetEnergy[chOutIdx][bandIdx]; // Q0 move32(); - hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; + hLsSetUpConversion->dmxEnergyPrev_fx[chOutIdx][bandIdx] = dmxEnergy[chOutIdx][bandIdx]; // Q0 move32(); hLsSetUpConversion->te_prev_exp = 31; move16(); @@ -2560,9 +2565,9 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( k = 0; k < hLsSetUpConversion->sfbCnt; ++k ) { - Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_RealBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_RealBuffer_InOut[i][slotIdx][k], q_output ); // Q6 move32(); - Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); + Cldfb_ImagBuffer_InOut[i][slotIdx][k] = L_shr( Cldfb_ImagBuffer_InOut[i][slotIdx][k], q_output ); // Q6 move32(); } } @@ -2574,7 +2579,7 @@ void ivas_lssetupconversion_process_param_mc_fx( { FOR( bandIdx = 0; bandIdx < hLsSetUpConversion->sfbCnt; bandIdx++ ) { - ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); + ivas_lssetupconversion_computeEQFactor_fx( &targetEnergy[chOutIdx][bandIdx], &dmxEnergy[chOutIdx][bandIdx], &EQ ); // Q(EQ) = Q30 Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx] = Mpy_32_32( L_shl( Cldfb_RealBuffer_InOut[chOutIdx][slotIdx][bandIdx], 1 ), EQ ); move32(); Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx] = Mpy_32_32( L_shl( Cldfb_ImagBuffer_InOut[chOutIdx][slotIdx][bandIdx], 1 ), EQ ); diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 4de07342c..f213a059d 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -123,9 +123,9 @@ static int16_t read_coherence_data( uint16_t *bitstream, int16_t *p_bit_pos, IVA /*! r: number of bits read */ Word16 ivas_qmetadata_dec_decode( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ - const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ + const Word16 hodirac_flag /* i : flag to indicate HO-DirAC mode Q0*/ ) { Word16 d, b, m; @@ -171,7 +171,7 @@ Word16 ivas_qmetadata_dec_decode( IF( hQMetaData->coherence_flag ) { /* read if coherence is zero */ - all_coherence_zero = bitstream[( *index )--]; + all_coherence_zero = bitstream[( *index )--]; /*Q0*/ move16(); bits_no_dirs_coh = add( bits_no_dirs_coh, 1 ); } @@ -181,20 +181,20 @@ Word16 ivas_qmetadata_dec_decode( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { /* Read which bands have 2 directions */ - hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; + hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; /*Q0*/ move16(); set_c( (Word8 *) hQMetaData->twoDirBands, 0, hQMetaData->q_direction[0].cfg.nbands ); d = *index; move16(); - dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); - p[0] = dif_p[0]; + p[0] = dif_p[0]; /*Q0*/ move16(); hQMetaData->twoDirBands[p[0]] = 1; move16(); FOR( b = 1; b < hQMetaData->numTwoDirBands; b++ ) { - dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); move16(); @@ -219,7 +219,7 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - dfRatio_bits[dir2band] = ivas_get_df_ratio_bits_hodirac( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); + dfRatio_bits[dir2band] = ivas_get_df_ratio_bits_hodirac( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); /*Q0*/ move16(); dir2band = add( dir2band, 1 ); } @@ -239,13 +239,13 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - dfRatio_bits[dir2band] = ivas_get_df_ratio_bits( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); + dfRatio_bits[dir2band] = ivas_get_df_ratio_bits( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] ); /*Q0*/ move16(); dir2band = add( dir2band, 1 ); } } - bits_diff_sum = add( bits_diff_sum, ivas_qmetadata_entropy_decode_df_ratio( bitstream, index, &( hQMetaData->q_direction[1] ), dfRatio_bits ) ); + bits_diff_sum = add( bits_diff_sum, ivas_qmetadata_entropy_decode_df_ratio( bitstream, index, &( hQMetaData->q_direction[1] ), dfRatio_bits ) ); /*Q0*/ } } @@ -265,14 +265,14 @@ Word16 ivas_qmetadata_dec_decode( diffRatio_fx = diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; // Q30 move32(); - dfRatio_qsteps = shl( 1, dfRatio_bits[dir2band] ); + dfRatio_qsteps = shl( 1, dfRatio_bits[dir2band] ); /*1 << dfRatio_bits[dir2band]*/ /* already encoded as total and ratios in HO-DirAC */ IF( hodirac_flag ) { dfRatio_fx = usdequant_fx( hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0], 0 /* Q15 */, inv_dfRatio_qsteps[dfRatio_qsteps] ); // Q15 dir1ratio_fx = L_sub( ONE_IN_Q30, diffRatio_fx ); - dir2ratio_fx = L_shl( (Word32) dfRatio_fx, Q15 ); + dir2ratio_fx = L_shl( (Word32) dfRatio_fx, Q15 ); /*Q30*/ } ELSE { @@ -284,17 +284,17 @@ Word16 ivas_qmetadata_dec_decode( /* Requantize the 1 - dirRatio separately for each direction to obtain inverted dirRatio index. These are used in further decoding. */ - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir1ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir1ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); IF( hodirac_flag ) { Word16 tmp_fx; - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = usquant_fx( extract_h( dir2ratio_fx ), &tmp_fx, 0, INV_DIRAC_DIFFUSE_LEVELS_Q13, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = usquant_fx( extract_h( dir2ratio_fx ), &tmp_fx, 0, INV_DIRAC_DIFFUSE_LEVELS_Q13, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } ELSE { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir2ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0] = masa_sq_fx( L_sub( ONE_IN_Q30, dir2ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } @@ -302,15 +302,15 @@ Word16 ivas_qmetadata_dec_decode( { hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = dir1ratio_fx; // Q30 move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[m] = dir2ratio_fx; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_fx[m] = dir2ratio_fx; /*Q30*/ move32(); - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[m] = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[m] = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; /*Q0*/ move16(); } @@ -319,13 +319,13 @@ Word16 ivas_qmetadata_dec_decode( ELSE { /* 1dir band */ - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); /*Q30*/ move32(); FOR( m = 1; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } } @@ -336,13 +336,13 @@ Word16 ivas_qmetadata_dec_decode( /* With 1dir band, the decoded index is directly diffuseness and we can decode to direct-to-total ratio with 1 - diff. */ FOR( b = hQMetaData->q_direction[0].cfg.start_band; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]] ); /*Q30*/ move32(); FOR( m = 1; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); - hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); } } @@ -363,18 +363,18 @@ Word16 ivas_qmetadata_dec_decode( { Word16 index_dirRatio1Inv, index_dirRatio2Inv, index_dirRatio1Inv_mod, index_dirRatio2Inv_mod; - index_dirRatio1Inv = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + index_dirRatio1Inv = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - index_dirRatio2Inv = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; + index_dirRatio2Inv = hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index[0]; /*Q0*/ move16(); masa_compensate_two_dir_energy_ratio_index_fx( index_dirRatio1Inv, index_dirRatio2Inv, &index_dirRatio1Inv_mod, &index_dirRatio2Inv_mod, hodirac_flag ); FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = index_dirRatio1Inv_mod; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = index_dirRatio1Inv_mod; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[index_dirRatio1Inv_mod]; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[index_dirRatio1Inv_mod]; /*Q0*/ move16(); bits_dir_raw_pre[0] = add( bits_dir_raw_pre[0], hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] ); move16(); @@ -382,9 +382,9 @@ Word16 ivas_qmetadata_dec_decode( FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[m] = index_dirRatio2Inv_mod; + hQMetaData->q_direction[1].band_data[dir2band].energy_ratio_index_mod[m] = index_dirRatio2Inv_mod; /*Q0*/ move16(); - hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] = bits_direction_masa[index_dirRatio2Inv_mod]; + hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] = bits_direction_masa[index_dirRatio2Inv_mod]; /*Q0*/ move16(); bits_dir_raw_pre[1] = add( bits_dir_raw_pre[1], hQMetaData->q_direction[1].band_data[dir2band].bits_sph_idx[m] ); move16(); @@ -396,9 +396,9 @@ Word16 ivas_qmetadata_dec_decode( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_direction_masa[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]]; /*Q0*/ move16(); bits_dir_raw_pre[0] = add( bits_dir_raw_pre[0], hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] ); move16(); @@ -408,12 +408,12 @@ Word16 ivas_qmetadata_dec_decode( IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - no_TF = add( i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), i_mult2( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); - tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); + no_TF = add( i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ), i_mult2( hQMetaData->q_direction[1].cfg.nbands, hQMetaData->q_direction[1].cfg.nblocks ) ); /*Q0*/ + tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); /*Q16*/ test(); IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { - bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); + bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); /*Q0*/ } ELSE { @@ -429,16 +429,16 @@ Word16 ivas_qmetadata_dec_decode( } } bits_no_dirs_coh = add( bits_no_dirs_coh, bits_sur_coherence ); - total_bits_1dir = extract_l( L_mult0( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ) ) / no_TF ); + total_bits_1dir = extract_l( L_mult0( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ) ) / no_TF ); /*Q0*/ } ELSE { - no_TF = i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); - tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); + no_TF = i_mult2( hQMetaData->q_direction[0].cfg.nbands, hQMetaData->q_direction[0].cfg.nblocks ); /*Q0*/ + tmp32 = L_sub( L_deposit_h( sub( sub( hQMetaData->metadata_max_bits, bits_no_dirs_coh ), bits_diff_sum ) ), L_mult0( 17612 /* 4.2998046875f in Q12 */, shl( no_TF, 4 ) ) ); /*Q16*/ test(); IF( !all_coherence_zero && GE_32( tmp32, L_deposit_h( MASA_MIN_BITS_SURR_COH ) ) ) { - bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); + bits_sur_coherence = read_surround_coherence( bitstream, index, hQMetaData ); /*Q0*/ } ELSE { @@ -466,18 +466,18 @@ Word16 ivas_qmetadata_dec_decode( FOR( d = 0; d < hQMetaData->no_directions; d++ ) { q_direction = &hQMetaData->q_direction[d]; - nbands = q_direction->cfg.nbands; + nbands = q_direction->cfg.nbands; /*Q0*/ move16(); - nblocks = q_direction->cfg.nblocks; + nblocks = q_direction->cfg.nblocks; /*Q0*/ move16(); - start_band = q_direction->cfg.start_band; + start_band = q_direction->cfg.start_band; /*Q0*/ move16(); - diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; + diffuseness_index_max_ec_frame = diffuseness_index_max_ec_frame_pre[0]; /*Q0*/ move16(); IF( d == 0 ) { - bits_diff = bits_diff_sum; + bits_diff = bits_diff_sum; /*Q0*/ move16(); } ELSE @@ -485,7 +485,7 @@ Word16 ivas_qmetadata_dec_decode( bits_diff = 0; move16(); } - bits_dir_raw = bits_dir_raw_pre[d]; + bits_dir_raw = bits_dir_raw_pre[d]; /*Q0*/ move16(); /* Read coherence, if any */ @@ -494,7 +494,7 @@ Word16 ivas_qmetadata_dec_decode( IF( all_coherence_zero == 0 ) { - bits_coherence = read_coherence_data_fx( bitstream, index, hQMetaData, d, 0 ); + bits_coherence = read_coherence_data_fx( bitstream, index, hQMetaData, d, 0 ); /*Q0*/ } ELSE { @@ -514,7 +514,7 @@ Word16 ivas_qmetadata_dec_decode( } /* Read 2D signaling*/ - q_direction->not_in_2D = bitstream[( *index )--]; + q_direction->not_in_2D = bitstream[( *index )--]; /*Q0*/ move16(); signal_bits = 1; move16(); @@ -545,7 +545,7 @@ Word16 ivas_qmetadata_dec_decode( { bits_dir = 0; move16(); - raw_flag[0] = bitstream[( *index )--]; + raw_flag[0] = bitstream[( *index )--]; /*Q0*/ move16(); bits_dir = add( bits_dir, 1 ); @@ -565,7 +565,7 @@ Word16 ivas_qmetadata_dec_decode( move16(); FOR( b = start_band; b < nbands; b++ ) { - raw_flag[b] = bitstream[( *index )--]; + raw_flag[b] = bitstream[( *index )--]; /*Q0*/ move16(); bits_dir = add( bits_dir, 1 ); } @@ -597,7 +597,7 @@ Word16 ivas_qmetadata_dec_decode( { FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) { - bits_temp[i][j] = q_direction->band_data[i].bits_sph_idx[j]; + bits_temp[i][j] = q_direction->band_data[i].bits_sph_idx[j]; /*Q0*/ move16(); } } @@ -608,7 +608,7 @@ Word16 ivas_qmetadata_dec_decode( { FOR( j = 0; j < q_direction->cfg.nblocks; j++ ) { - q_direction->band_data[i].bits_sph_idx[j] = bits_temp[i][j]; + q_direction->band_data[i].bits_sph_idx[j] = bits_temp[i][j]; /*Q0*/ move16(); } } @@ -632,7 +632,7 @@ Word16 ivas_qmetadata_dec_decode( IF( hQMetaData->is_masa_ivas_format == 0 ) { - reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ); + reduce_bits = sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ); /*Q0*/ ind_order[0] = -1; move16(); } @@ -640,7 +640,7 @@ Word16 ivas_qmetadata_dec_decode( { ind_order[0] = 0; move16(); - reduce_bits = s_min( add( i_mult2( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ) ); + reduce_bits = s_min( add( i_mult2( nbands, nblocks ), MASA_BIT_REDUCT_PARAM ), sub( bits_dir_raw, sub( sub( sub( total_bits_1dir, bits_diff ), bits_coherence ), signal_bits ) ) ); /*Q0*/ IF( GT_16( reduce_bits, sub( bits_dir_raw, i_mult2( nbands, nblocks ) ) ) ) { reduce_bits = sub( bits_dir_raw, i_mult2( nbands, nblocks ) ); @@ -649,7 +649,7 @@ Word16 ivas_qmetadata_dec_decode( only_reduce_bits_direction_fx( &dummy, q_direction, reduce_bits, nbands, nblocks, ind_order ); /* Read directions */ - bits_dir = read_directions_fx( q_direction, (UWord8) nbands, (UWord8) nblocks, bitstream, index, ind_order ); + bits_dir = read_directions_fx( q_direction, (UWord8) nbands, (UWord8) nblocks, bitstream, index, ind_order ); /*Q0*/ } IF( bits_coherence > 0 ) @@ -671,7 +671,7 @@ Word16 ivas_qmetadata_dec_decode( } IF( d == 0 ) { - total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( start_index_0, *index ) ); + total_bits_1dir = sub( hQMetaData->metadata_max_bits, sub( start_index_0, *index ) ); /*Q0*/ } bits_dir_target = add( bits_dir_target, bits_dir_raw ); @@ -688,39 +688,39 @@ Word16 ivas_qmetadata_dec_decode( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); /*Q30*/ IF( LT_32( hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0], 7 ) ) { FOR( m = 0; m < nblocks; m++ ) { - Word32 a1 = hQMetaData->q_direction[1].band_data[b].azimuth_fx[m]; + Word32 a1 = hQMetaData->q_direction[1].band_data[b].azimuth_fx[m]; /*Q22*/ move32(); - a1 = L_shr( hQMetaData->q_direction[1].band_data[b].azimuth_fx[m], 1 ); - Word32 b1 = hQMetaData->q_direction[0].band_data[b].azimuth_fx[m]; + a1 = L_shr( hQMetaData->q_direction[1].band_data[b].azimuth_fx[m], 1 ); /*Q21*/ + Word32 b1 = hQMetaData->q_direction[0].band_data[b].azimuth_fx[m]; /*Q22*/ move32(); - b1 = L_shr( hQMetaData->q_direction[0].band_data[b].azimuth_fx[m], 1 ); - Word32 c = L_shr( DEGREE_180_Q_22, 1 ); + b1 = L_shr( hQMetaData->q_direction[0].band_data[b].azimuth_fx[m], 1 ); /*Q21*/ + Word32 c = L_shr( DEGREE_180_Q_22, 1 ); /*Q21*/ a1 = L_add( a1, L_sub( b1, c ) ); IF( GE_32( a1, L_shr( DEGREE_180_Q_22, 1 ) ) ) { - a1 = L_sub( a1, L_shr( DEGREE_360_Q_22, 1 ) ); + a1 = L_sub( a1, L_shr( DEGREE_360_Q_22, 1 ) ); /*Q21*/ } IF( LT_32( a1, L_shr( -DEGREE_180_Q_22, 1 ) ) ) { - a1 = L_add( a1, L_shr( DEGREE_360_Q_22, 1 ) ); + a1 = L_add( a1, L_shr( DEGREE_360_Q_22, 1 ) ); /*Q21*/ } - hQMetaData->q_direction[1].band_data[b].azimuth_fx[m] = L_shl( a1, 1 ); + hQMetaData->q_direction[1].band_data[b].azimuth_fx[m] = L_shl( a1, 1 ); /*Q22*/ move32(); } } IF( hQMetaData->q_direction[1].coherence_band_data != NULL ) { - mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); + mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); /*Q0*/ } d = sub( d, 1 ); } @@ -744,12 +744,12 @@ Word16 ivas_qmetadata_dec_decode( { Word32 ratioSum_flt_fx; - ratioSum_flt_fx = L_add( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0] ); + ratioSum_flt_fx = L_add( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0] ); /*Q30*/ IF( GT_32( ratioSum_flt_fx, ONE_IN_Q30 ) ) { - set32_fx( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); - set32_fx( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); + set32_fx( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); /*Q30*/ + set32_fx( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, L_shl( (Word32) divide3232( hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[0], ratioSum_flt_fx ), 15 ) /* Q30 */, nblocks ); /*Q30*/ } } } @@ -761,12 +761,12 @@ Word16 ivas_qmetadata_dec_decode( IF( GT_16( bits_dir_used, bits_dir_target ) ) { - hQMetaData->dir_comp_ratio_fx = MAX_WORD16; + hQMetaData->dir_comp_ratio_fx = MAX_WORD16; /*Q15*/ move16(); } ELSE { - hQMetaData->dir_comp_ratio_fx = divide3232( bits_dir_used, bits_dir_target ); + hQMetaData->dir_comp_ratio_fx = divide3232( bits_dir_used, bits_dir_target ); /*Q15*/ } return sub( start_index_0, *index ); } @@ -1334,8 +1334,8 @@ int16_t ivas_qmetadata_dec_decode( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dec_decode_hr_384_512( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: hQMetaData handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ const SPHERICAL_GRID_DATA *sph_grid16, /* i : spherical grid for deindexing */ const Word16 bits_sph_idx, const Word16 bits_sp_coh, @@ -1357,11 +1357,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( /* read number of higher inactive/not encoded bands */ IF( bitstream[( *index )--] ) { - codedBands = sub( sub( MASA_MAXIMUM_CODING_SUBBANDS, ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 1 ) ), 1 ); + codedBands = sub( sub( MASA_MAXIMUM_CODING_SUBBANDS, ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 1 ) ), 1 ); /*Q0*/ } ELSE { - codedBands = MASA_MAXIMUM_CODING_SUBBANDS; + codedBands = MASA_MAXIMUM_CODING_SUBBANDS; /*Q0*/ move16(); } FOR( b = codedBands; b < ncoding_bands_config; b++ ) @@ -1419,10 +1419,10 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); } } - sf_nbands0 = hQMetaData->q_direction[0].cfg.nbands; + sf_nbands0 = hQMetaData->q_direction[0].cfg.nbands; /*Q0*/ move16(); - hQMetaData->q_direction[0].cfg.nbands = codedBands; + hQMetaData->q_direction[0].cfg.nbands = codedBands; /*Q0*/ move16(); /*Coherence flag decoding*/ @@ -1431,11 +1431,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( hQMetaData->coherence_flag ) { /* read if coherence is zero */ - all_coherence_zero = bitstream[( *index )--]; + all_coherence_zero = bitstream[( *index )--]; /*Q0*/ move16(); } - hQMetaData->all_coherence_zero = (UWord8) all_coherence_zero; + hQMetaData->all_coherence_zero = (UWord8) all_coherence_zero; /*Q0*/ IF( EQ_32( hQMetaData->no_directions, 2 ) ) { @@ -1446,19 +1446,19 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_16( bits_sph_idx, 11 ) && EQ_32( hQMetaData->no_directions, 2 ) ) { /* Read which bands have 2 directions */ - hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; + hQMetaData->q_direction[1].cfg.nbands = hQMetaData->numTwoDirBands; /*Q0*/ move16(); - sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; + sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; /*Q0*/ move16(); if ( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) { - hQMetaData->q_direction[1].cfg.nbands = codedBands; + hQMetaData->q_direction[1].cfg.nbands = codedBands; /*Q0*/ move16(); } set_c( (Word8 *) hQMetaData->twoDirBands, 0, hQMetaData->q_direction[0].cfg.nbands ); d = *index; move16(); - dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[0] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[0] = dif_p[0]; move16(); @@ -1466,7 +1466,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( move16(); FOR( b = 1; b < hQMetaData->q_direction[1].cfg.nbands; b++ ) { - dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); + dif_p[b] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, MASA_MAXIMUM_CODING_SUBBANDS, 0 ); /*Q0*/ move16(); p[b] = add( add( p[b - 1], dif_p[b] ), 1 ); move16(); @@ -1478,11 +1478,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( test(); IF( EQ_16( bits_sph_idx, 16 ) && EQ_32( hQMetaData->no_directions, 2 ) ) { - sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; + sf_nbands1 = hQMetaData->q_direction[1].cfg.nbands; /*Q0*/ move16(); IF( GT_16( hQMetaData->q_direction[1].cfg.nbands, codedBands ) ) { - hQMetaData->q_direction[1].cfg.nbands = codedBands; + hQMetaData->q_direction[1].cfg.nbands = codedBands; /*Q0*/ move16(); } } @@ -1498,7 +1498,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - W_nrg_ratio[0][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[0][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[0].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); } } @@ -1511,11 +1511,11 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); /* Scale energy ratios that sum to over one */ - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { @@ -1536,7 +1536,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - pos_2dir_band[d] = b; + pos_2dir_band[d] = b; /*Q0*/ move16(); d = add( d, 1 ); } @@ -1551,16 +1551,16 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); + W_nrg_ratio[1][b][m] = W_sub( ONE_IN_Q62, diffuseness_reconstructions_hr_fx[hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]] ); /*Q62*/ move64(); - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][pos_2dir_band[b]][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][pos_2dir_band[b]][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { - W_nrg_ratio[0][pos_2dir_band[b]][m] = W_shl( (Word64) ( W_nrg_ratio[0][pos_2dir_band[b]][m] / ratioSum ), 30 ); + W_nrg_ratio[0][pos_2dir_band[b]][m] = W_shl( (Word64) ( W_nrg_ratio[0][pos_2dir_band[b]][m] / ratioSum ), 30 ); /*Q62*/ move64(); - W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); + W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); } } @@ -1574,9 +1574,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]; + hQMetaData->q_direction[1].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[1].band_data[b].energy_ratio_index[m]; /*Q0*/ move16(); - hQMetaData->q_direction[1].band_data[b].bits_sph_idx[m] = bits_sph_idx; + hQMetaData->q_direction[1].band_data[b].bits_sph_idx[m] = bits_sph_idx; /*Q0*/ move16(); } } @@ -1586,9 +1586,9 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; + hQMetaData->q_direction[0].band_data[b].energy_ratio_index_mod[m] = hQMetaData->q_direction[0].band_data[b].energy_ratio_index[0]; /*Q0*/ move16(); - hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_sph_idx; + hQMetaData->q_direction[0].band_data[b].bits_sph_idx[m] = bits_sph_idx; /*Q0*/ move16(); } } @@ -1659,14 +1659,14 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( IF( EQ_16( hQMetaData->twoDirBands[b], 1 ) ) { - Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); - Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); + Copy32( hQMetaData->q_direction[1].band_data[d].azimuth_fx, hQMetaData->q_direction[1].band_data[b].azimuth_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].elevation_fx, hQMetaData->q_direction[1].band_data[b].elevation_fx, nblocks ); /*Q22*/ + Copy32( hQMetaData->q_direction[1].band_data[d].energy_ratio_fx, hQMetaData->q_direction[1].band_data[b].energy_ratio_fx, nblocks ); /*Q30*/ Copy64( W_nrg_ratio[1][d], W_nrg_ratio[1][b], nblocks ); IF( hQMetaData->q_direction[1].coherence_band_data != NULL ) { - mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); + mvc2c( hQMetaData->q_direction[1].coherence_band_data[d].spread_coherence, hQMetaData->q_direction[1].coherence_band_data[b].spread_coherence, nblocks ); /*Q0*/ } d = sub( d, 1 ); } @@ -1691,12 +1691,12 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { Word32 ratioSum; - ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); + ratioSum = W_round64_L( W_add( W_nrg_ratio[0][b][m], W_nrg_ratio[1][b][m] ) ); /*Q30*/ IF( GT_32( ratioSum, ONE_IN_Q30 ) ) { - W_nrg_ratio[0][b][m] = W_shl( (Word64) ( W_nrg_ratio[0][b][m] / ratioSum ), 30 ); + W_nrg_ratio[0][b][m] = W_shl( (Word64) ( W_nrg_ratio[0][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); - W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); + W_nrg_ratio[1][b][m] = W_shl( (Word64) ( W_nrg_ratio[1][b][m] / ratioSum ), 30 ); /*Q62*/ move64(); } } @@ -1708,7 +1708,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[0].cfg.nblocks; m++ ) { - hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); + hQMetaData->q_direction[0].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[0][b][m] ); /*Q30*/ move32(); } } @@ -1729,7 +1729,7 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( { FOR( m = 0; m < hQMetaData->q_direction[1].cfg.nblocks; m++ ) { - hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); + hQMetaData->q_direction[1].band_data[b].energy_ratio_fx[m] = W_round64_L( W_nrg_ratio[1][b][m] ); /*Q30*/ move32(); } } @@ -1747,15 +1747,15 @@ Word16 ivas_qmetadata_dec_decode_hr_384_512( /* Store status information for renderer use */ hQMetaData->ec_flag = 0; move16(); - hQMetaData->dir_comp_ratio_fx = MAX_WORD16; + hQMetaData->dir_comp_ratio_fx = MAX_WORD16; /*Q15*/ move16(); - hQMetaData->q_direction[0].cfg.nbands = sf_nbands0; + hQMetaData->q_direction[0].cfg.nbands = sf_nbands0; /*Q0*/ move16(); IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - hQMetaData->q_direction[1].cfg.nbands = sf_nbands1; + hQMetaData->q_direction[1].cfg.nbands = sf_nbands1; /*Q0*/ move16(); } @@ -2105,11 +2105,11 @@ int16_t ivas_qmetadata_dec_decode_hr_384_512( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_dec_sid_decode( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, /* i/o: bitstream position */ - const Word16 nchan_transport, /* i : number of transport channels */ - Word16 *element_mode, /* o : element mode */ - const Word16 ivas_format /* i : IVAS format */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /* i/o: bitstream position Q0*/ + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + Word16 *element_mode, /* o : element mode Q0*/ + const Word16 ivas_format /* i : IVAS format Q0*/ ) { Word16 b, m, i; @@ -2142,7 +2142,7 @@ Word16 ivas_qmetadata_dec_sid_decode( test(); IF( EQ_16( ivas_format, MASA_FORMAT ) && EQ_16( nchan_transport, 2 ) ) { - b = bitstream[( *index )--]; + b = bitstream[( *index )--]; /*Q0*/ move16(); IF( b ) { @@ -2169,7 +2169,7 @@ Word16 ivas_qmetadata_dec_sid_decode( move16(); } - nblocks = q_direction->cfg.nblocks; /* only 1 block transmitted but up to 4 blocks re-generated */ + nblocks = q_direction->cfg.nblocks; /* only 1 block transmitted but up to 4 blocks re-generated Q0*/ move16(); start_band = 0; /* start from band 0 */ move16(); @@ -2177,7 +2177,7 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Read 2D signaling*/ IF( NE_16( ivas_format, SBA_FORMAT ) ) { - q_direction->not_in_2D = bitstream[( *index )--]; + q_direction->not_in_2D = bitstream[( *index )--]; /*Q0*/ move16(); } ELSE @@ -2193,14 +2193,14 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Decode diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( DIRAC_DIFFUSE_LEVELS, 4 ) ), 4 ); + diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( DIRAC_DIFFUSE_LEVELS, 4 ) ), 4 ); /*Q0*/ move16(); - q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; + q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; /*Q0*/ move16(); - q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[diffuseness_index[b]]; + q_direction->band_data[b].bits_sph_idx[0] = bits_direction_masa[diffuseness_index[b]]; /*Q0*/ move16(); - bits_dir = extract_l( L_add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ) ); - q_direction->band_data[b].azimuth_m_alphabet[0] = no_phi_masa[q_direction->band_data[b].bits_sph_idx[0] - 1][0]; + bits_dir = extract_l( L_add( bits_dir, q_direction->band_data[b].bits_sph_idx[0] ) ); /*Q0*/ + q_direction->band_data[b].azimuth_m_alphabet[0] = no_phi_masa[q_direction->band_data[b].bits_sph_idx[0] - 1][0]; /*Q0*/ move16(); } @@ -2260,7 +2260,7 @@ Word16 ivas_qmetadata_dec_sid_decode( /* Decode diffuseness*/ FOR( b = start_band; b < nbands; b++ ) { - diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 4 ), 4 ); + diffuseness_index[b] = (UWord16) L_add( ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 4 ), 4 ); /*Q0*/ move16(); q_direction->band_data[b].energy_ratio_index[0] = diffuseness_index[b]; move16(); @@ -2273,11 +2273,11 @@ Word16 ivas_qmetadata_dec_sid_decode( FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[diffuseness_index[b]] ); + q_direction->band_data[b].energy_ratio_fx[0] = L_sub( ONE_IN_Q30, diffuseness_reconstructions_fx[diffuseness_index[b]] ); /*Q30*/ move32(); FOR( i = 0; i < nblocks; i++ ) { - q_direction->band_data[b].energy_ratio_fx[i] = q_direction->band_data[b].energy_ratio_fx[0]; + q_direction->band_data[b].energy_ratio_fx[i] = q_direction->band_data[b].energy_ratio_fx[0]; /*Q30*/ move32(); } } @@ -2304,11 +2304,11 @@ Word16 ivas_qmetadata_dec_sid_decode( ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( avg_azimuth_fx, avg_elevation_fx, avg_direction_vector_fx ); ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[nblocks - 1], q_direction->band_data[b].elevation_fx[nblocks - 1], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); /*Q25*/ FOR( m = 0; m < nblocks - 1; m++ ) { - v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); + v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); } ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, sub( 30, 5 ), &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); @@ -2324,14 +2324,14 @@ Word16 ivas_qmetadata_dec_sid_decode( q_direction->band_data[b].azimuth_m_alphabet[0] = shl( 1, extract_l( L_min( 5, q_direction->band_data[b].bits_sph_idx[0] ) ) ); move16(); } - q_direction->band_data[b].azimuth_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, q_direction->band_data[b].azimuth_m_alphabet[0] ); + q_direction->band_data[b].azimuth_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, q_direction->band_data[b].azimuth_m_alphabet[0] ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[0] = add( ivas_qmetadata_dereorder_generic( q_direction->band_data[b].azimuth_index[0] ), shr( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ) ); + q_direction->band_data[b].azimuth_index[0] = add( ivas_qmetadata_dereorder_generic( q_direction->band_data[b].azimuth_index[0] ), shr( q_direction->band_data[b].azimuth_m_alphabet[0], 1 ) ); /*Q0*/ move16(); - temp_result = div_s( ( shl( q_direction->band_data[b].azimuth_index[0], 6 ) ), ( shl( q_direction->band_data[b].azimuth_m_alphabet[0], 6 ) ) ); - temp_result = Mpy_32_16_1( DEGREE_360_Q_22, (Word16) temp_result ); - avg_azimuth_fx = L_sub( temp_result, DEGREE_180_Q_22 ); + temp_result = div_s( ( shl( q_direction->band_data[b].azimuth_index[0], 6 ) ), ( shl( q_direction->band_data[b].azimuth_m_alphabet[0], 6 ) ) ); /*Q15*/ + temp_result = Mpy_32_16_1( DEGREE_360_Q_22, (Word16) temp_result ); /*Q22*/ + avg_azimuth_fx = L_sub( temp_result, DEGREE_180_Q_22 ); /*Q22*/ avg_elevation_fx = 0; move32(); @@ -2339,11 +2339,11 @@ Word16 ivas_qmetadata_dec_sid_decode( ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( avg_azimuth_fx, avg_elevation_fx, avg_direction_vector_fx ); ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[nblocks - 1], q_direction->band_data[b].elevation_fx[nblocks - 1], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_shr_32( avg_direction_vector_fx, avg_direction_vector_fx, 3, 5 ); /*Q25*/ FOR( m = 0; m < nblocks - 1; m++ ) { - v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); + v_add_32( direction_vector_fx, avg_direction_vector_fx, direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m] ); } ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, 30 - 5, &q_direction->band_data[b].azimuth_fx[nblocks - 1], &q_direction->band_data[b].elevation_fx[nblocks - 1] ); @@ -2598,9 +2598,9 @@ int16_t ivas_qmetadata_dec_sid_decode( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_diffuseness_huff_ec_decode_fx( - const UWord16 *bitstream, - Word16 *index, - Word16 av ) + const UWord16 *bitstream, /*Q0*/ + Word16 *index, /*Q0*/ + Word16 av /*Q0*/ ) { Word16 val; @@ -2680,10 +2680,10 @@ static int16_t ivas_diffuseness_huff_ec_decode( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_diffuseness( - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction, - UWord16 *diffuseness_index_max_ec_frame ) + UWord16 *diffuseness_index_max_ec_frame /*Q0*/ ) { Word16 b; UWord16 dif_min; @@ -2706,7 +2706,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( move16(); FOR( b = 0; b < MASA_BITS_ER; b++ ) { - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } *diffuseness_index_max_ec_frame = 5; @@ -2722,21 +2722,21 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( { IF( bitstream[( *index )--] ) /* dif_have_unique_value */ { - dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value */ + dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /* dif_unique_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = dif_min; + q_direction->band_data[b].energy_ratio_index[0] = dif_min; /*Q0*/ move16(); } } ELSE /* all diffuseness values are dif_min_value or dif_min_value + 1 */ { - dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value */ + dif_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS - 1 ); /* dif_min_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( dif_min, bitstream[( *index )--] ); /* dif_bit_offset_values */ + q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( dif_min, bitstream[( *index )--] ); /* dif_bit_offset_values Q0*/ move16(); } } @@ -2750,7 +2750,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( move16(); FOR( b = 0; b < MASA_BITS_ER; b++ ) { - av = add( av, i_mult( (Word16) bitstream[( *index )--], shl( 1, sub( sub( MASA_BITS_ER, 1 ), b ) ) ) ); + av = add( av, i_mult( (Word16) bitstream[( *index )--], shl( 1, sub( sub( MASA_BITS_ER, 1 ), b ) ) ) ); /*Q0*/ } dif_min = DIRAC_DIFFUSE_LEVELS; @@ -2758,7 +2758,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( /* read average removed data (average is added inside)*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_diffuseness_huff_ec_decode_fx( bitstream, index, av ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_diffuseness_huff_ec_decode_fx( bitstream, index, av ); /*Q0*/ move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); move16(); @@ -2772,7 +2772,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness( FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); dif_min = (UWord16) L_min( dif_min, q_direction->band_data[b].energy_ratio_index[0] ); move16(); @@ -2895,8 +2895,8 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction ) { Word16 b, k; @@ -2922,7 +2922,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( move16(); FOR( b = 0; b < MASA_BITS_ER_HR; b++ ) { - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( (UWord16) L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( (UWord16) L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } @@ -2933,7 +2933,7 @@ static Word16 ivas_qmetadata_entropy_decode_diffuseness_hr_512( { FOR( k = 0; k < nblocks; k++ ) { - q_direction->band_data[b].energy_ratio_index[k] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, HR_MASA_ER_LEVELS ); + q_direction->band_data[b].energy_ratio_index[k] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, HR_MASA_ER_LEVELS ); /*Q0*/ move16(); } } @@ -2990,10 +2990,10 @@ static int16_t ivas_qmetadata_entropy_decode_diffuseness_hr_512( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_df_ratio( - UWord16 *bitstream, - Word16 *index, + UWord16 *bitstream, /*Q0*/ + Word16 *index, /*Q0*/ IVAS_QDIRECTION *q_direction, - Word16 *dfRatio_bits ) + Word16 *dfRatio_bits /*Q0*/ ) { Word16 b; Word16 bits_raw; @@ -3021,7 +3021,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( FOR( b = 0; b < dfRatio_bits[0]; b++ ) { // q_direction->band_data[0].energy_ratio_index[0] = ( q_direction->band_data[0].energy_ratio_index[0] << 1 ) + bitstream[( *index )--]; - q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); + q_direction->band_data[0].energy_ratio_index[0] = (UWord16) L_add( L_shl( q_direction->band_data[0].energy_ratio_index[0], 1 ), bitstream[( *index )--] ); /*Q0*/ move16(); } return dfRatio_bits[0]; @@ -3055,7 +3055,7 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( ec_mode = 0; move16(); } - max_alphabet_size = shl( 1, max_dfRatio_bits ); + max_alphabet_size = shl( 1, max_dfRatio_bits ); /* 1 << max_dfRatio_bits */ dec_mode = 2; /* Default to raw decoding */ move16(); @@ -3088,27 +3088,27 @@ static Word16 ivas_qmetadata_entropy_decode_df_ratio( { FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, (UWord16) L_shl( 1, dfRatio_bits[b] ) ); + q_direction->band_data[b].energy_ratio_index[0] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, (UWord16) L_shl( 1, dfRatio_bits[b] ) ); /*Q0*/ move16(); } } ELSE IF( EQ_16( dec_mode, 1 ) ) /* One value decoding */ { - ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size ); /* dif_unique_value */ + ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size ); /* dif_unique_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = ratio_min; + q_direction->band_data[b].energy_ratio_index[0] = ratio_min; /*Q0*/ move16(); } } ELSE /* Bandwise 1-bit diff decoding */ { - ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size - 1 ); /* dif_min_value */ + ratio_min = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, max_alphabet_size - 1 ); /* dif_min_value Q0*/ FOR( b = start_band; b < nbands; b++ ) { - q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( ratio_min, bitstream[( *index )--] ); /* dif_bit_offset_values */ + q_direction->band_data[b].energy_ratio_index[0] = (UWord16) L_add( ratio_min, bitstream[( *index )--] ); /* dif_bit_offset_values Q0*/ move16(); } } @@ -3237,13 +3237,13 @@ static int16_t ivas_qmetadata_entropy_decode_df_ratio( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_entropy_decode_dir_fx( - IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const UWord16 diffuseness_index_max_ec_frame, - const Word16 nbands, - const Word16 start_band, - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const UWord16 diffuseness_index_max_ec_frame, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 b, m; @@ -3281,19 +3281,19 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } diff_idx_min = s_min( diff_idx_min, diff_idx ); IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - elev_alph[b] = no_theta_masa[sub( bits_direction_masa[diff_idx], 3 )]; + elev_alph[b] = no_theta_masa[( bits_direction_masa[diff_idx] - 3 )]; /*Q0*/ move16(); } ELSE { - elev_alph[b] = sub( shl( no_theta_masa[sub( bits_direction_masa[diff_idx], 3 )], 1 ), 1 ); + elev_alph[b] = sub( shl( no_theta_masa[( bits_direction_masa[diff_idx] - 3 )], 1 ), 1 ); /*Q0*/ move16(); } @@ -3316,11 +3316,11 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( q_direction->band_data[b].elevation_index[m] = 0; move16(); - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][0]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][0]; /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph[b][m] ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3339,15 +3339,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_alphabet = no_theta_masa[sub( bits_direction_masa[diff_idx_min], 3 )]; + avg_elevation_alphabet = no_theta_masa[( bits_direction_masa[diff_idx_min] - 3 )]; /*Q0*/ move16(); - avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); + avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); /*Q0*/ } ELSE { - avg_elevation_alphabet = sub( shl( no_theta_masa[sub( bits_direction_masa[diff_idx_min], 3 )], 1 ), 1 ); + avg_elevation_alphabet = sub( shl( no_theta_masa[( bits_direction_masa[diff_idx_min] - 3 )], 1 ), 1 ); /*Q0*/ avg_elevation_idx = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_elevation_alphabet ); - avg_elevation_idx = add( ivas_qmetadata_dereorder_generic( avg_elevation_idx ), shr( avg_elevation_alphabet, 1 ) ); + avg_elevation_idx = add( ivas_qmetadata_dereorder_generic( avg_elevation_idx ), shr( avg_elevation_alphabet, 1 ) ); /*Q0*/ } gr_param_elev = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 4 + 1 ); @@ -3366,27 +3366,27 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ } ELSE { - avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ /*reorder elevation indexing*/ - tmp_index = sub( avg_elevation_index_projected, shr( elev_alph[b], 1 ) ); + tmp_index = sub( avg_elevation_index_projected, shr( elev_alph[b], 1 ) ); /*Q0*/ IF( tmp_index < 0 ) { - tmp_index = negate( tmp_index * 2 ); + tmp_index = negate( imult1616( tmp_index, 2 ) ); } ELSE IF( tmp_index > 0 ) { - tmp_index = sub( ( tmp_index * 2 ), 1 ); + tmp_index = sub( imult1616( tmp_index, 2 ), 1 ); } avg_elevation_index_projected = tmp_index; move16(); @@ -3394,23 +3394,23 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( FOR( m = 0; m < nblocks; m++ ) { - q_direction->band_data[b].elevation_index[m] = avg_elevation_index_projected; + q_direction->band_data[b].elevation_index[m] = avg_elevation_index_projected; /*Q0*/ move16(); /*deduce aplhabet for azimuth*/ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3429,7 +3429,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -3438,11 +3438,11 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( Word16 tmp_index; IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); - tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, sub( shl( elev_alph[b], 1 ), 1 ), gr_param_elev ); + avg_elevation_index_projected = ivas_chan_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ + tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, sub( shl( elev_alph[b], 1 ), 1 ), gr_param_elev ); /*Q0*/ IF( s_and( tmp_index, 1 ) ) { - tmp_index = add( avg_elevation_index_projected, shr( add( tmp_index, 1 ), 1 ) ); + tmp_index = add( avg_elevation_index_projected, shr( add( tmp_index, 1 ), 1 ) ); /*Q0*/ } ELSE { @@ -3452,15 +3452,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( move16(); /*deduce aplhabet for azimuth*/ - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); + avg_elevation_index_projected = ivas_dirac_project_elevation_index( avg_elevation_idx, avg_elevation_alphabet, elev_alph[b] ); /*Q0*/ - tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, elev_alph[b], gr_param_elev ); - tmp_index = ivas_qmetadata_ReorderElevationDecoded( tmp_index, avg_elevation_index_projected, elev_alph[b] ); + tmp_index = ivas_qmetadata_DecodeExtendedGR( bitstream, index, elev_alph[b], gr_param_elev ); /*Q0*/ + tmp_index = ivas_qmetadata_ReorderElevationDecoded( tmp_index, avg_elevation_index_projected, elev_alph[b] ); /*Q0*/ /*reorder elevation indexing*/ tmp_index = sub( tmp_index, elev_alph[b] / 2 ); @@ -3476,12 +3476,12 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( move16(); /*deduce aplhabet for azimuth*/ - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][extract_l( L_shr( L_add( q_direction->band_data[b].elevation_index[m], 1 ), 1 ) )]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3501,7 +3501,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -3513,17 +3513,17 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( /*deduce alphabet for azimuth*/ IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][q_direction->band_data[b].elevation_index[m]]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][q_direction->band_data[b].elevation_index[m]]; /*Q0*/ move16(); } ELSE { - azith_alph[b][m] = no_phi_masa[sub( bits_direction_masa[diff_idx], 1 )][add( q_direction->band_data[b].elevation_index[m], 1 ) / 2]; + azith_alph[b][m] = no_phi_masa[( bits_direction_masa[diff_idx] - 1 )][add( q_direction->band_data[b].elevation_index[m], 1 ) / 2]; /*Q0*/ move16(); } /*decode elevation*/ - q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].elevation_fx[m] = deindex_elevation_fx( &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3531,14 +3531,14 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } /*Azimuth*/ - avg_azimuth_alphabet = no_phi_masa[sub( bits_direction_masa[diff_idx_min], 1 )][0]; /* average azimuth is quantized on the equatorial plane */ + avg_azimuth_alphabet = no_phi_masa[( bits_direction_masa[diff_idx_min] - 1 )][0]; /* average azimuth is quantized on the equatorial plane Q0*/ move16(); - avg_azimuth_index = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_azimuth_alphabet ); - avg_azimuth_index = ivas_qmetadata_dereorder_generic( avg_azimuth_index ); - avg_azimuth_index = add( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ); + avg_azimuth_index = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, avg_azimuth_alphabet ); /*Q0*/ + avg_azimuth_index = ivas_qmetadata_dereorder_generic( avg_azimuth_index ); /*Q0*/ + avg_azimuth_index = add( avg_azimuth_index, shr( avg_azimuth_alphabet, 1 ) ); /*Q0*/ - gr_param_azith = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 5 + 1 ); - IF( EQ_32( gr_param_azith, 5 ) ) /* all the azimuth distances are zero */ + gr_param_azith = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, 5 + 1 ); /*Q0*/ + IF( EQ_32( gr_param_azith, 5 ) ) /* all the azimuth distances are zero */ { FOR( b = start_band; b < nbands; b++ ) { @@ -3546,7 +3546,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { FOR( m = 0; m < nblocks; m++ ) { - q_direction->band_data[b].azimuth_index[m] = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); /*Q0*/ move16(); IF( EQ_16( azith_alph[b][m], 1 ) ) @@ -3556,7 +3556,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -3579,15 +3579,15 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) && EQ_16( idx, MASA_LIMIT_IDX_AVG_AZI ) && GT_16( nblocks, 1 ) ) { - use_adapt_avg = bitstream[*index]; + use_adapt_avg = bitstream[*index]; /*Q0*/ move16(); ( *index ) = sub( *index, 1 ); move16(); } - avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, azith_alph[b][m], gr_param_azith ); + avg_azimuth_index_projected = ivas_dirac_project_azimuth_index( avg_azimuth_index, avg_azimuth_alphabet, azith_alph[b][m] ); /*Q0*/ + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeExtendedGR( bitstream, index, azith_alph[b][m], gr_param_azith ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_ReorderElevationDecoded( q_direction->band_data[b].azimuth_index[m], avg_azimuth_index_projected, azith_alph[b][m] ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_ReorderElevationDecoded( q_direction->band_data[b].azimuth_index[m], avg_azimuth_index_projected, azith_alph[b][m] ); /*Q0*/ move16(); IF( EQ_16( azith_alph[b][m], 1 ) ) @@ -3597,7 +3597,7 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( } ELSE { - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->band_data[b].elevation_index[m], 0, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } @@ -3607,8 +3607,8 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( IF( LT_16( idx, MASA_LIMIT_IDX_AVG_AZI ) ) { ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); /*Q25*/ } ELSE { @@ -3618,16 +3618,16 @@ static Word16 ivas_qmetadata_entropy_decode_dir_fx( { FOR( Word16 l = 0; l < 3; l++ ) { - avg_direction_vector_fx[l] = L_shr( avg_direction_vector_fx[l], 1 ); + avg_direction_vector_fx[l] = L_shr( avg_direction_vector_fx[l], 1 ); /*0.5f*/ move32(); } } /*compute the average direction per already coded subband */ ivas_qmetadata_azimuth_elevation_to_direction_vector_fx( q_direction->band_data[b].azimuth_fx[m], q_direction->band_data[b].elevation_fx[m], direction_vector_fx ); - v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); - v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); + v_shr_32( direction_vector_fx, direction_vector_fx, 3, 5 ); /*Q25*/ + v_add_32( avg_direction_vector_fx, direction_vector_fx, avg_direction_vector_fx, 3 ); /*Q25*/ ivas_qmetadata_direction_vector_to_azimuth_elevation_fx( avg_direction_vector_fx, 30 - 5, &avg_azimuth_fx, &avg_elevation_fx ); - avg_azimuth_index = quantize_phi_fx( L_add( avg_azimuth_fx, DEGREE_180_Q_22 ), 0, &avg_azimuth_fx, avg_azimuth_alphabet ); + avg_azimuth_index = quantize_phi_fx( L_add( avg_azimuth_fx, DEGREE_180_Q_22 ), 0, &avg_azimuth_fx, avg_azimuth_alphabet ); /*Q0*/ } } idx = add( idx, 1 ); @@ -3996,11 +3996,11 @@ static int16_t ivas_qmetadata_entropy_decode_dir( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_raw_decode_dir_512_fx( - IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const Word16 nbands, - const Word16 start_band, + IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ const SPHERICAL_GRID_DATA *sph_grid16 /* i : spherical grid for deindexing */ ) { @@ -4088,11 +4088,11 @@ static int16_t ivas_qmetadata_raw_decode_dir_512( #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_raw_decode_dir_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - UWord16 *bitstream, /* i : bitstream */ - Word16 *index, - const Word16 nbands, - const Word16 start_band, - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *index, /*Q0*/ + const Word16 nbands, /*Q0*/ + const Word16 start_band, /*Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 b, m, azith_alph; @@ -4120,7 +4120,7 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( } ELSE { - diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; + diff_idx = q_direction->band_data[b].energy_ratio_index_mod[0]; /*Q0*/ move16(); } @@ -4130,11 +4130,11 @@ static Word16 ivas_qmetadata_raw_decode_dir_fx( move32(); q_direction->band_data[b].elevation_index[m] = 0; move16(); - azith_alph = no_phi_masa[bits_direction_masa[diff_idx] - 1][0]; + azith_alph = no_phi_masa[bits_direction_masa[diff_idx] - 1][0]; /*Q0*/ move16(); - q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph ); + q_direction->band_data[b].azimuth_index[m] = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, azith_alph ); /*Q0*/ move16(); - q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[b].azimuth_fx[m] = deindex_azimuth_fx( q_direction->band_data[b].azimuth_index[m], q_direction->band_data[b].bits_sph_idx[m], 0, 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -4207,9 +4207,9 @@ static int16_t ivas_qmetadata_raw_decode_dir( /*! r: Value read from the bitstream */ #ifdef IVAS_FLOAT_FIXED static UWord16 ivas_qmetadata_DecodeQuasiUniform( - const UWord16 *bitstream, /* i : pointer to the bitstream to read */ - Word16 *index, /* i : position in the bitstream to start reading (gets updated with reading) */ - const UWord16 alphabet_size /* i : size of the alphabet, used to calculate the number of bits needed */ + const UWord16 *bitstream, /* i : pointer to the bitstream to read Q0*/ + Word16 *index, /* i : position in the bitstream to start reading (gets updated with reading) Q0*/ + const UWord16 alphabet_size /* i : size of the alphabet, used to calculate the number of bits needed Q0*/ ) { Word16 i, bits; @@ -4223,12 +4223,12 @@ static UWord16 ivas_qmetadata_DecodeQuasiUniform( move16(); FOR( i = 0; i < bits; i++ ) { - value = (UWord16) L_add( (UWord16) L_shl( value, 1 ), bitstream[( *index )--] ); + value = (UWord16) L_add( (UWord16) L_shl( value, 1 ), bitstream[( *index )--] ); /*Q0*/ } IF( GE_32( value, tresh ) ) { - value = (UWord16) L_add( (UWord16) L_sub( (UWord16) L_shl( value, 1 ), tresh ), bitstream[( *index )--] ); + value = (UWord16) L_add( (UWord16) L_sub( (UWord16) L_shl( value, 1 ), tresh ), bitstream[( *index )--] ); /*Q0*/ } return value; @@ -4273,7 +4273,7 @@ static uint16_t ivas_qmetadata_DecodeQuasiUniform( #ifdef IVAS_FLOAT_FIXED Word16 ivas_qmetadata_DecodeExtendedGR( - UWord16 *bitstream, /* i : pointer to the bitstream to read */ + UWord16 *bitstream, /* i : pointer to the bitstream to read Q0*/ Word16 *index, /* i/o: position in the bitstream to start reading (gets updated with reading) */ const Word16 alph_size, /* i : size of the alphabet, used to calculate the number of bits needed */ const Word16 gr_param /* i : GR parameter that indicates the limit for the most significant bits (msb) */ @@ -4283,10 +4283,10 @@ Word16 ivas_qmetadata_DecodeExtendedGR( UWord16 value; Word16 msb, lsb; - msb_size = shr( add( alph_size, sub( shl( 1, gr_param ), 1 ) ), gr_param ); /* ceil division */ + msb_size = shr( add( alph_size, sub( shl( 1, gr_param ), 1 ) ), gr_param ); /* ceil division Q0*/ IF( LE_16( msb_size, 3 ) ) { - value = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, alph_size ); + value = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, alph_size ); /*Q0*/ } ELSE { @@ -4303,7 +4303,7 @@ Word16 ivas_qmetadata_DecodeExtendedGR( IF( EQ_16( msb, sub( msb_size, 1 ) ) ) { - lsb = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( alph_size, shl( sub( msb_size, 1 ), gr_param ) ) ); + lsb = ivas_qmetadata_DecodeQuasiUniform( bitstream, index, sub( alph_size, shl( sub( msb_size, 1 ), gr_param ) ) ); /*Q0*/ } ELSE { @@ -4313,11 +4313,11 @@ Word16 ivas_qmetadata_DecodeExtendedGR( move16(); FOR( i = 0; i < gr_param; i++ ) { - lsb = extract_l( L_add( shl( lsb, 1 ), bitstream[( *index )--] ) ); + lsb = extract_l( L_add( shl( lsb, 1 ), bitstream[( *index )--] ) ); /*Q0*/ } } - value = (UWord16) add( shl( msb, gr_param ), lsb ); + value = (UWord16) add( shl( msb, gr_param ), lsb ); /*Q0*/ } return value; @@ -4378,15 +4378,15 @@ int16_t ivas_qmetadata_DecodeExtendedGR( /*! r: Elevation index as it will be read by the dequantizer */ #ifdef IVAS_FLOAT_FIXED static Word16 ivas_qmetadata_ReorderElevationDecoded( - const Word16 elev_dist, /* i : Distance to the average extracted from the bitstream */ - const Word16 elev_avg, /* i : Average value over time-blocks extracted from the bitstream */ - const Word16 elev_alph /* i : elevation alphabet */ + const Word16 elev_dist, /* i : Distance to the average extracted from the bitstream Q0*/ + const Word16 elev_avg, /* i : Average value over time-blocks extracted from the bitstream Q0*/ + const Word16 elev_alph /* i : elevation alphabet Q0*/ ) { Word16 dist_reorder; Word16 elev_index_reorder; - dist_reorder = ivas_qmetadata_dereorder_generic( elev_dist ); + dist_reorder = ivas_qmetadata_dereorder_generic( elev_dist ); /*Q0*/ elev_index_reorder = add( elev_avg, dist_reorder ); IF( elev_index_reorder < 0 ) @@ -4398,7 +4398,7 @@ static Word16 ivas_qmetadata_ReorderElevationDecoded( elev_index_reorder = sub( elev_index_reorder, elev_alph ); } - return elev_index_reorder; + return elev_index_reorder; /*Q0*/ } #else static int16_t ivas_qmetadata_ReorderElevationDecoded( @@ -4435,11 +4435,11 @@ static int16_t ivas_qmetadata_ReorderElevationDecoded( #ifdef IVAS_FLOAT_FIXED static Word16 read_directions_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - const UWord8 coding_subbands, /* i : number of directions */ - const UWord8 masa_subframes, /* i : number of tiles */ - UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, - Word16 *ind_order ) + const UWord8 coding_subbands, /* i : number of directions Q0*/ + const UWord8 masa_subframes, /* i : number of tiles Q0*/ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /*Q0*/ + Word16 *ind_order /*Q0*/ ) { Word16 j, k, allowed_bits, last_j, nbits, fixed_rate; Word16 i; @@ -4459,14 +4459,14 @@ static Word16 read_directions_fx( IF( GT_16( coding_subbands, 1 ) ) { - j = ind_order[sub( coding_subbands, 1 )]; + j = ind_order[( coding_subbands - 1 )]; move16(); allowed_bits = 0; move16(); FOR( k = 0; k < masa_subframes; k++ ) { - allowed_bits = extract_l( L_add( allowed_bits, q_direction->band_data[j].bits_sph_idx[k] ) ); + allowed_bits = extract_l( L_add( allowed_bits, q_direction->band_data[j].bits_sph_idx[k] ) ); /*Q0*/ } last_j = sub( j, (Word16) ( allowed_bits == 0 ) ); @@ -4475,7 +4475,7 @@ static Word16 read_directions_fx( { i = ind_order[j]; move16(); - bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; /*Q0*/ nbits = 0; move16(); @@ -4524,13 +4524,13 @@ static Word16 read_directions_fx( FOR( k = 0; k < masa_subframes; k++ ) { - q_direction->band_data[i].bits_sph_idx[k] = bits_dir0[k]; + q_direction->band_data[i].bits_sph_idx[k] = bits_dir0[k]; /*Q0*/ move16(); IF( GT_16( bits_dir0[k], 2 ) ) { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[bits_dir0[k] - 3]; + q_direction->band_data[i].elevation_m_alphabet[k] = no_theta_masa[bits_dir0[k] - 3]; /*Q0*/ move16(); } ELSE @@ -4550,7 +4550,7 @@ static Word16 read_directions_fx( { IF( EQ_32( byteBuffer, 1 ) ) { - nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); + nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); /*Q0*/ } ELSE { @@ -4581,9 +4581,9 @@ static Word16 read_directions_fx( { /* decode elevation */ - nbits = add( nbits, decode_elevation_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_elevation_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ /* decode azimuth */ - nbits = add( nbits, decode_azimuth_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_azimuth_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ } } } @@ -4600,7 +4600,7 @@ static Word16 read_directions_fx( } ELSE { - last_j = q_direction->cfg.start_band; + last_j = q_direction->cfg.start_band; /*Q0*/ move16(); } @@ -4609,15 +4609,15 @@ static Word16 read_directions_fx( { i = ind_order[j]; move16(); - bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[i].bits_sph_idx; /*Q0*/ nbits = 0; move16(); - allowed_bits = sum16_fx( bits_dir0, q_direction->cfg.nblocks ); + allowed_bits = sum16_fx( bits_dir0, q_direction->cfg.nblocks ); /*Q0*/ test(); IF( allowed_bits > 0 && EQ_16( masa_subframes, 1 ) ) { - nbits = add( nbits, decode_fixed_rate_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); + nbits = add( nbits, decode_fixed_rate_fx( q_direction, bitstream, &bit_pos, i, masa_subframes ) ); /*Q0*/ } ELSE { @@ -4631,7 +4631,7 @@ static Word16 read_directions_fx( { IF( GT_16( bits_dir0[k], use_vq ) ) { - use_vq = bits_dir0[k]; + use_vq = bits_dir0[k]; /*Q0*/ move16(); max_nb_idx = k; move16(); @@ -4658,7 +4658,7 @@ static Word16 read_directions_fx( test(); IF( EQ_32( byteBuffer, 1 ) || LE_16( use_vq, 1 ) ) { - nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); + nbits = read_common_direction_fx( bitstream, q_direction, i, masa_subframes, allowed_bits, &bit_pos ); /*Q0*/ } ELSE { @@ -4692,7 +4692,7 @@ static Word16 read_directions_fx( } } - nbits = decode_azimuth2D_fx( q_direction, bitstream, coding_subbands, &bit_pos, masa_subframes ); + nbits = decode_azimuth2D_fx( q_direction, bitstream, coding_subbands, &bit_pos, masa_subframes ); /*Q0*/ } nbits = sub( *pbit_pos, bit_pos ); *pbit_pos = bit_pos; @@ -4936,10 +4936,10 @@ static int16_t read_directions( #ifdef IVAS_FLOAT_FIXED static Word16 decode_azimuth_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, /* i/o: current position in bitstream */ - const Word16 idx_subband, /* i : subband index */ - const Word16 masa_subframes /* i : number of tiles */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /* i/o: current position in bitstream Q0*/ + const Word16 idx_subband, /* i : subband index Q0*/ + const Word16 masa_subframes /* i : number of tiles Q0*/ ) { Word16 bit_pos, nbits, k; @@ -5006,18 +5006,18 @@ static Word16 decode_azimuth_fx( { byteBuffer = bitstream[bit_pos--]; move16(); - q_direction->band_data[idx_subband].azimuth_index[k] = byteBuffer; + q_direction->band_data[idx_subband].azimuth_index[k] = byteBuffer; /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( L_mult0( q_direction->band_data[idx_subband].azimuth_index[k], -180 ), Q22 ); + q_direction->band_data[idx_subband].azimuth_fx[k] = L_shl( L_mult0( q_direction->band_data[idx_subband].azimuth_index[k], -180 ), Q22 ); /*Q22*/ move32(); } ELSE { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], sub( MASA_GR_ORD_AZ, (Word16) EQ_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 2 ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], sub( MASA_GR_ORD_AZ, (Word16) EQ_32( q_direction->band_data[idx_subband].bits_sph_idx[k], 2 ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5026,7 +5026,7 @@ static Word16 decode_azimuth_fx( ELSE { /* read bit to check if min removed encoding */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q22*/ move16(); bit_pos = sub( bit_pos, 1 ); IF( byteBuffer == 0 ) /* regular GR coding5 */ @@ -5043,9 +5043,9 @@ static Word16 decode_azimuth_fx( { IF( GT_16( no_phi_masa[L_sub( q_direction->band_data[idx_subband].bits_sph_idx[k], 1 )][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ, byteBuffer ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ, byteBuffer ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } ELSE @@ -5069,12 +5069,12 @@ static Word16 decode_azimuth_fx( { /* min removed GR coding */ /* read GR_order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); /* read min index value */ maximum_s( q_direction->band_data[idx_subband].azimuth_m_alphabet, masa_subframes, &max_val ); - min_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, max_val, MASA_GR_ORD_AZ ); + min_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, max_val, MASA_GR_ORD_AZ ); /*Q0*/ FOR( k = 0; k < masa_subframes; k++ ) { @@ -5082,11 +5082,11 @@ static Word16 decode_azimuth_fx( { IF( GT_16( no_phi_masa[q_direction->band_data[idx_subband].bits_sph_idx[k] - 1][q_direction->band_data[idx_subband].elevation_index[k]], 1 ) ) { - q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ - 1, byteBuffer ) ) ); + q_direction->band_data[idx_subband].azimuth_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[idx_subband].azimuth_m_alphabet[k], extract_l( L_sub( MASA_GR_ORD_AZ - 1, byteBuffer ) ) ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_index[k] = (UWord16) L_add( q_direction->band_data[idx_subband].azimuth_index[k], min_idx ); + q_direction->band_data[idx_subband].azimuth_index[k] = (UWord16) L_add( q_direction->band_data[idx_subband].azimuth_index[k], min_idx ); /*Q0*/ move16(); - q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); + q_direction->band_data[idx_subband].azimuth_fx[k] = deindex_azimuth_fx( q_direction->band_data[idx_subband].azimuth_index[k], q_direction->band_data[idx_subband].bits_sph_idx[k], q_direction->band_data[idx_subband].elevation_index[k], 1, q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } ELSE @@ -5278,10 +5278,10 @@ static int16_t decode_azimuth( #ifdef IVAS_FLOAT_FIXED static Word16 decode_elevation_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : input bitstream */ - Word16 *pbit_pos, /* i/o: current position to be read in bitstream*/ - const Word16 j, /* i : subband index */ - const Word16 masa_subframes /* i : number of tiles */ + UWord16 *bitstream, /* i : input bitstream Q0*/ + Word16 *pbit_pos, /* i/o: current position to be read in bitstream Q0*/ + const Word16 j, /* i : subband index Q0*/ + const Word16 masa_subframes /* i : number of tiles Q0*/ ) { Word16 nr_NO_INDEX, nbits; @@ -5308,7 +5308,7 @@ static Word16 decode_elevation_fx( { IF( LE_32( q_direction->band_data[j].bits_sph_idx[k], 2 ) ) { - q_direction->band_data[j].elevation_index[k] = MASA_NO_INDEX; + q_direction->band_data[j].elevation_index[k] = MASA_NO_INDEX; /*Q0*/ move16(); nr_NO_INDEX = add( nr_NO_INDEX, 1 ); q_direction->band_data[j].elevation_fx[k] = 0; @@ -5320,12 +5320,12 @@ static Word16 decode_elevation_fx( { IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3]; + q_direction->band_data[j].elevation_m_alphabet[k] = no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3]; /*Q0*/ move16(); } ELSE { - q_direction->band_data[j].elevation_m_alphabet[k] = shl( no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3], 1 ) - 1; + q_direction->band_data[j].elevation_m_alphabet[k] = shl( no_theta_masa[q_direction->band_data[j].bits_sph_idx[k] - 3], 1 ) - 1; /*Q0*/ move16(); } } @@ -5346,7 +5346,7 @@ static Word16 decode_elevation_fx( IF( EQ_32( byteBuffer, 1 ) ) /* same value */ { /* read value */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); byteBuffer = (UWord16) L_add( L_shl( byteBuffer, 1 ), bitstream[bit_pos] ); @@ -5359,9 +5359,9 @@ static Word16 decode_elevation_fx( { IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].elevation_index[k] = same_idx; + q_direction->band_data[j].elevation_index[k] = same_idx; /*Q0*/ move16(); - q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5369,18 +5369,18 @@ static Word16 decode_elevation_fx( ELSE { /* not same; decode mean removed GR */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); move16(); - GR_ord_elevation = extract_l( L_sub( MASA_GR_ORD_EL, byteBuffer ) ); + GR_ord_elevation = extract_l( L_sub( MASA_GR_ORD_EL, byteBuffer ) ); /*Q0*/ FOR( k = 0; k < masa_subframes; k++ ) { IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].elevation_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[j].elevation_m_alphabet[k], GR_ord_elevation ); + q_direction->band_data[j].elevation_index[k] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, q_direction->band_data[j].elevation_m_alphabet[k], GR_ord_elevation ); /*Q0*/ move16(); - q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); + q_direction->band_data[j].elevation_fx[k] = deindex_elevation_fx( &q_direction->band_data[j].elevation_index[k], q_direction->band_data[j].bits_sph_idx[k], q_direction->cfg.mc_ls_setup ); /*Q22*/ move32(); } } @@ -5394,9 +5394,9 @@ static Word16 decode_elevation_fx( IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) && LE_16( no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]], 1 ) ) { - q_direction->band_data[j].azimuth_index[k] = MASA_NO_INDEX; + q_direction->band_data[j].azimuth_index[k] = MASA_NO_INDEX; /*Q0*/ move16(); - q_direction->band_data[j].azimuth_m_alphabet[k] = 1; + q_direction->band_data[j].azimuth_m_alphabet[k] = 1; /*Q0*/ move16(); } ELSE @@ -5405,12 +5405,12 @@ static Word16 decode_elevation_fx( move16(); IF( LT_32( q_direction->band_data[j].elevation_index[k], MASA_NO_INDEX ) ) { - q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]]; + q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][q_direction->band_data[j].elevation_index[k]]; /*Q0*/ move16(); } ELSE { - q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][0]; + q_direction->band_data[j].azimuth_m_alphabet[k] = no_phi_masa[sub( q_direction->band_data[j].bits_sph_idx[k], 1 )][0]; /*Q0*/ move16(); q_direction->band_data[j].elevation_index[k] = 0; move16(); @@ -5548,10 +5548,10 @@ static int16_t decode_elevation( #ifdef IVAS_FLOAT_FIXED static Word16 decode_fixed_rate_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata */ - const UWord16 *bitstream, /* i : bitstream to be read */ - Word16 *pbit_pos, /* i/o: position in bitstream */ - const Word16 b, /* i : subband index */ - const Word16 nblocks /* i : number of tiles in subband */ + const UWord16 *bitstream, /* i : bitstream to be read Q0*/ + Word16 *pbit_pos, /* i/o: position in bitstream Q0*/ + const Word16 b, /* i : subband index Q0*/ + const Word16 nblocks /* i : number of tiles in subband Q0*/ ) { Word16 nbits, m, i; @@ -5566,13 +5566,13 @@ static Word16 decode_fixed_rate_fx( move16(); FOR( i = 0; i < q_direction->band_data[b].bits_sph_idx[m]; i++ ) { - value = (UWord16) L_add( L_shl( value, 1 ), bitstream[( *pbit_pos )--] ); + value = (UWord16) L_add( L_shl( value, 1 ), bitstream[( *pbit_pos )--] ); /*Q0*/ move16(); } - q_direction->band_data[b].spherical_index[m] = value; + q_direction->band_data[b].spherical_index[m] = value; /*Q0*/ move16(); - nbits = extract_l( L_add( nbits, q_direction->band_data[b].bits_sph_idx[m] ) ); + nbits = extract_l( L_add( nbits, q_direction->band_data[b].bits_sph_idx[m] ) ); /*Q0*/ deindex_spherical_component_fx( q_direction->band_data[b].spherical_index[m], &q_direction->band_data[b].azimuth_fx[m], &q_direction->band_data[b].elevation_fx[m], &q_direction->band_data[b].azimuth_index[m], &q_direction->band_data[b].elevation_index[m], q_direction->band_data[b].bits_sph_idx[m], q_direction->cfg.mc_ls_setup ); } @@ -5628,10 +5628,10 @@ static int16_t decode_fixed_rate( #ifdef IVAS_FLOAT_FIXED static Word16 decode_azimuth2D_fx( IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - UWord16 *bitstream, /* i : bitstream to be read */ - const Word16 coding_subbands, /* i : number of subbands */ - Word16 *pbit_pos, - const Word16 no_frames ) + UWord16 *bitstream, /* i : bitstream to be read Q0*/ + const Word16 coding_subbands, /* i : number of subbands Q0*/ + Word16 *pbit_pos, /*Q0*/ + const Word16 no_frames /*Q0*/ ) { Word16 i, j, k; Word16 allowed_bits, nbits; @@ -5646,7 +5646,7 @@ static Word16 decode_azimuth2D_fx( move16(); FOR( j = 0; j < coding_subbands; j++ ) { - bits_dir0 = (Word16 *) q_direction->band_data[j].bits_sph_idx; + bits_dir0 = (Word16 *) q_direction->band_data[j].bits_sph_idx; /*Q0*/ allowed_bits = sum16_fx( bits_dir0, no_frames ); IF( allowed_bits > 0 ) @@ -5675,7 +5675,7 @@ static Word16 decode_azimuth2D_fx( set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_frames ); FOR( k = 0; k < s_min( allowed_bits, no_frames ); k++ ) { - q_direction->band_data[j].azimuth_fx[k] = L_shl( L_mult0( -180, bitstream[bit_pos] ), Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_shl( L_mult0( -180, bitstream[bit_pos] ), Q22 ); /*Q22*/ move32(); bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); @@ -5683,7 +5683,7 @@ static Word16 decode_azimuth2D_fx( } ELSE { - nbits = add( nbits, read_truncGR_azimuth_fx( bitstream, q_direction, j, no_frames, &bit_pos ) ); + nbits = add( nbits, read_truncGR_azimuth_fx( bitstream, q_direction, j, no_frames, &bit_pos ) ); /*Q0*/ } } ELSE @@ -5694,7 +5694,7 @@ static Word16 decode_azimuth2D_fx( move16(); FOR( i = 0; i < bits_dir0[k]; i++ ) { - Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos] ); + Buffer = (UWord16) L_add( L_shl( Buffer, 1 ), bitstream[bit_pos] ); /*Q0*/ bit_pos = sub( bit_pos, 1 ); } @@ -5702,15 +5702,15 @@ static Word16 decode_azimuth2D_fx( IF( NE_32( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].azimuth_fx[k] = L_sub( L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer, L_shl( 180, Q22 ) ); + q_direction->band_data[j].azimuth_fx[k] = L_sub( W_extract_l( W_mult0_32_32( L_shl( 360, sub( Q22, bits_dir0[k] ) ), Buffer ) ), L_shl( 180, Q22 ) ); /*Q22*/ move32(); q_direction->band_data[j].azimuth_fx[k] = companding_azimuth_fx( q_direction->band_data[j].azimuth_fx[k], q_direction->cfg.mc_ls_setup, - (Word16) GT_32( q_direction->band_data[j].elevation_fx[k], L_shl( MC_MASA_THR_ELEVATION, 22 ) ), -1 ); + (Word16) GT_32( q_direction->band_data[j].elevation_fx[k], L_shl( MC_MASA_THR_ELEVATION, 22 ) ), -1 ); /*Q22*/ move32(); } ELSE { - q_direction->band_data[j].azimuth_fx[k] = L_shl( 360, sub( Q22, bits_dir0[k] ) ) * Buffer - L_shl( 180, Q22 ); + q_direction->band_data[j].azimuth_fx[k] = L_sub( W_extract_l( W_mult0_32_32( L_shl( 360, sub( Q22, bits_dir0[k] ) ), Buffer ) ), L_shl( 180, Q22 ) ); /*Q22*/ move32(); } } @@ -5823,8 +5823,8 @@ static int16_t decode_azimuth2D( #ifdef IVAS_FLOAT_FIXED static void set_zero_direction_fx( IVAS_QDIRECTION *q_direction, - const Word16 idx_band, - const Word16 len ) + const Word16 idx_band, /*Q0*/ + const Word16 len /*Q0*/ ) { Word16 k; @@ -5874,11 +5874,11 @@ static void set_zero_direction( #ifdef IVAS_FLOAT_FIXED static Word16 read_truncGR_azimuth_fx( - UWord16 *bitstream, /* i : bitstream to be read */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ IVAS_QDIRECTION *q_direction, /* i/o: quantized metadata structure */ - const Word16 j, /* i : subband index */ - const Word16 no_subframes, /* i : number of tiles */ - Word16 *pbit_pos /* i/o: position in bitstream */ + const Word16 j, /* i : subband index Q0*/ + const Word16 no_subframes, /* i : number of tiles Q0*/ + Word16 *pbit_pos /* i/o: position in bitstream Q0*/ ) { Word16 i; @@ -5886,7 +5886,7 @@ static Word16 read_truncGR_azimuth_fx( UWord16 idx; Word16 no_symb, allowed_bits; - allowed_bits = sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ); + allowed_bits = sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ); /*Q0*/ nbits = 0; move16(); IF( LE_16( allowed_bits, add( no_subframes, 1 ) ) ) @@ -5900,7 +5900,7 @@ static Word16 read_truncGR_azimuth_fx( } ELSE { - q_direction->band_data[j].azimuth_fx[i] = ( -180 * ONE_IN_Q22 ); + q_direction->band_data[j].azimuth_fx[i] = ( -180 * ONE_IN_Q22 ); /*Q22*/ move32(); } nbits = add( nbits, 1 ); @@ -5928,21 +5928,21 @@ static Word16 read_truncGR_azimuth_fx( FOR( i = 0; i < no_subframes; i++ ) { idx = ivas_qmetadata_DecodeExtendedGR( bitstream, pbit_pos, no_symb, 0 ); - q_direction->band_data[j].azimuth_index[i] = idx; + q_direction->band_data[j].azimuth_index[i] = idx; /*Q0*/ move16(); IF( NE_16( q_direction->cfg.mc_ls_setup, MC_LS_SETUP_INVALID ) ) { - q_direction->band_data[j].azimuth_fx[i] = cb_azi_chan_fx[(UWord16) L_shr( (UWord16) L_add( idx, 1 ), 1 )]; + q_direction->band_data[j].azimuth_fx[i] = cb_azi_chan_fx[(UWord16) ( (UWord16) ( idx + 1 ) / 2 )]; /*Q22*/ move32(); IF( L_and( idx, 1 ) > 0 ) { - q_direction->band_data[j].azimuth_fx[i] = L_negate( q_direction->band_data[j].azimuth_fx[i] ); + q_direction->band_data[j].azimuth_fx[i] = L_negate( q_direction->band_data[j].azimuth_fx[i] ); /*Q22*/ move32(); } } ELSE { - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[idx]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[idx]; /*Q22*/ move32(); } } @@ -6030,12 +6030,12 @@ static int16_t read_truncGR_azimuth( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_common_direction_fx( - UWord16 *bitstream, /* i : bitstream to be read */ + UWord16 *bitstream, /* i : bitstream to be read Q0*/ IVAS_QDIRECTION *q_direction, /* i/o: quantized direction structure */ - const Word16 j, /* i : subband index */ - const Word16 no_subframes, /* i : number of tiles */ - const Word16 bits_total, /* i : number of bits for subband directional data */ - Word16 *pbit_pos /* i/o: position in bitstream */ + const Word16 j, /* i : subband index Q0*/ + const Word16 no_subframes, /* i : number of tiles Q0*/ + const Word16 bits_total, /* i : number of bits for subband directional data Q0*/ + Word16 *pbit_pos /* i/o: position in bitstream Q0*/ ) { Word16 nbits; @@ -6059,10 +6059,10 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < s_min( no_subframes, bits_total ); i++ ) { - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos--]; /*Q0*/ move16(); /*qdirection->azimuth_index[j][i] = (uint16_t)byteBuffer; */ - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; /*Q22*/ move32(); nbits = add( nbits, 1 ); } @@ -6074,7 +6074,7 @@ static Word16 read_common_direction_fx( } - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_el = 1; @@ -6083,7 +6083,7 @@ static Word16 read_common_direction_fx( /* elevation is already set to 0*/ IF( EQ_32( byteBuffer, 1 ) ) { - byteBuffer = bitstream[bit_pos--]; + byteBuffer = bitstream[bit_pos--]; /*Q0*/ move16(); bits_el = add( bits_el, 1 ); nbits = add( nbits, 1 ); @@ -6091,7 +6091,7 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < no_subframes; i++ ) { - q_direction->band_data[j].elevation_fx[i] = delta_theta_masa_fx[2]; + q_direction->band_data[j].elevation_fx[i] = delta_theta_masa_fx[2]; /*Q22*/ move32(); } } @@ -6105,7 +6105,7 @@ static Word16 read_common_direction_fx( { FOR( i = 0; i < no_subframes; i++ ) { - q_direction->band_data[j].elevation_fx[i] = L_negate( delta_theta_masa_fx[2] ); + q_direction->band_data[j].elevation_fx[i] = L_negate( delta_theta_masa_fx[2] ); /*Q22*/ move32(); } } @@ -6117,13 +6117,13 @@ static Word16 read_common_direction_fx( nbits = add( nbits, 1 ); IF( byteBuffer == 0 ) { - set32_fx( q_direction->band_data[j].elevation_fx, ( 90 * ONE_IN_Q22 ), no_subframes ); - set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( 90 * ONE_IN_Q22 ), no_subframes ); /*Q22*/ + set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); /*Q22*/ } ELSE { - set32_fx( q_direction->band_data[j].elevation_fx, ( -90 * ONE_IN_Q22 ), no_subframes ); - set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); + set32_fx( q_direction->band_data[j].elevation_fx, ( -90 * ONE_IN_Q22 ), no_subframes ); /*Q22*/ + set32_fx( q_direction->band_data[j].azimuth_fx, 0, no_subframes ); /*Q22*/ } *pbit_pos = bit_pos; move16(); @@ -6133,18 +6133,18 @@ static Word16 read_common_direction_fx( } } - bits_el = sub( sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ), bits_el ); + bits_el = sub( sum16_fx( (Word16 *) q_direction->band_data[j].bits_sph_idx, no_subframes ), bits_el ); /*Q0*/ IF( LE_16( bits_el, add( no_subframes, 1 ) ) ) { nbits = add( nbits, s_min( no_subframes, bits_el ) ); FOR( i = 0; i < s_min( no_subframes, bits_el ); i++ ) { - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); /*qdirection->azimuth_index[j][i] = (uint16_t) byteBuffer; */ - q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; + q_direction->band_data[j].azimuth_fx[i] = azimuth_cb_fx[byteBuffer]; /*Q22*/ move32(); } } @@ -6279,9 +6279,9 @@ static int16_t read_common_direction( #ifdef IVAS_FLOAT_FIXED static void decode_spread_coherence_fx( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: quantized metadata structure */ - Word16 idx_d, /* i : direction index */ - const Word16 no_frames, /* i : number of time subframes */ - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding */ + Word16 idx_d, /* i : direction index Q0*/ + const Word16 no_frames, /* i : number of time subframes Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 i, j; @@ -6309,21 +6309,21 @@ static void decode_spread_coherence_fx( { IF( LE_16( coding_subbands_0, 8 ) ) { - Copy( MASA_grouping_8_to_5, MASA_grouping, 8 ); + Copy( MASA_grouping_8_to_5, MASA_grouping, 8 ); /*Q0*/ } ELSE IF( LE_16( coding_subbands_0, 12 ) ) { - Copy( MASA_grouping_12_to_5, MASA_grouping, 12 ); + Copy( MASA_grouping_12_to_5, MASA_grouping, 12 ); /*Q0*/ } ELSE IF( LE_16( coding_subbands_0, 18 ) ) { - Copy( MASA_grouping_18_to_5, MASA_grouping, 18 ); + Copy( MASA_grouping_18_to_5, MASA_grouping, 18 ); /*Q0*/ } ELSE { IF( LE_16( coding_subbands_0, 24 ) ) { - Copy( MASA_grouping_24_to_5, MASA_grouping, 24 ); + Copy( MASA_grouping_24_to_5, MASA_grouping, 24 ); /*Q0*/ } } } @@ -6351,7 +6351,7 @@ static void decode_spread_coherence_fx( FOR( i = 0; i < coding_subbands; i++ ) { - var_azi_fx = var_32_fx( q_direction->band_data[i].azimuth_fx, no_frames, 22 ); + var_azi_fx = var_32_fx( q_direction->band_data[i].azimuth_fx, no_frames, 22 ); /*Q22*/ IF( hrmasa_flag ) { minimum_s( (Word16 *) ( q_direction->band_data[i].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); @@ -6359,13 +6359,13 @@ static void decode_spread_coherence_fx( } ELSE { - min_index = q_direction->band_data[i].energy_ratio_index[0]; + min_index = q_direction->band_data[i].energy_ratio_index[0]; /*Q0*/ move16(); } IF( LT_64( var_azi_fx, L_shl( MASA_DELTA_AZI_DCT0, 22 ) ) ) { - idx_sub_cb = i_mult( MASA_NO_CV_COH, min_index ); + idx_sub_cb = i_mult( MASA_NO_CV_COH, min_index ); /*Q0*/ } ELSE { @@ -6378,12 +6378,12 @@ static void decode_spread_coherence_fx( IF( LT_16( coding_subbands, coding_subbands_0 ) ) { assert( EQ_16( idx_d, 1 ) ); - dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[two_dir_band[i]], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; + dct_coh_fx[i][1] = coherence_cb1_masa_fx[( ( MASA_grouping[two_dir_band[i]] * MASA_NO_CV_COH1 ) + q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; /*Q21*/ move32(); } ELSE { - dct_coh_fx[i][1] = coherence_cb1_masa_fx[L_add( L_mult0( MASA_grouping[i], MASA_NO_CV_COH1 ), q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; + dct_coh_fx[i][1] = coherence_cb1_masa_fx[( ( MASA_grouping[i] * MASA_NO_CV_COH1 ) + q_direction->coherence_band_data[i].spread_coherence_dct1_index )]; /*Q21*/ move32(); } @@ -6520,13 +6520,13 @@ static void decode_spread_coherence( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static ivas_error read_huf( - Word16 *num_bits_read, - const UWord16 *bitstream, /* i : bitstream to be read */ - UWord16 *out, /* o : decoded value */ - const Word16 start_pos, /* i : starting position for reading */ - const Word16 len, /* i : number of codewords */ - const Word16 *huff_code, /* i : Huffman table */ - const Word16 max_len /* i : maximum codeword length */ + Word16 *num_bits_read, /*Q0*/ + const UWord16 *bitstream, /* i : bitstream to be read Q0*/ + UWord16 *out, /* o : decoded value Q0*/ + const Word16 start_pos, /* i : starting position for reading Q0*/ + const Word16 len, /* i : number of codewords Q0*/ + const Word16 *huff_code, /* i : Huffman table Q0*/ + const Word16 max_len /* i : maximum codeword length Q0*/ ) { Word16 done = 0, end_pos; @@ -6543,9 +6543,9 @@ static ivas_error read_huf( move16(); WHILE( !done && LT_16( nbits, max_len ) ) { - ByteBuffer = bitstream[end_pos--]; + ByteBuffer = bitstream[end_pos--]; /*Q0*/ move16(); - val = add( shl( val, 1 ), ByteBuffer & 1 ); + val = add( shl( val, 1 ), ByteBuffer & 1 ); /*Q0*/ nbits = add( nbits, 1 ); FOR( i = 0; i < len; i++ ) { @@ -6614,12 +6614,12 @@ static ivas_error read_huf( *-------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED static Word16 read_GR_min_removed_data( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ - const Word16 *no_cv_vec, - const Word16 no_data, - Word16 *decoded_idx, - const Word16 no_symb ) + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ + const Word16 *no_cv_vec, /*Q0*/ + const Word16 no_data, /*Q0*/ + Word16 *decoded_idx, /*Q0*/ + const Word16 no_symb /*Q0*/ ) { Word16 j; Word16 bit_pos; @@ -6631,7 +6631,7 @@ static Word16 read_GR_min_removed_data( move16(); /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); nbits = 1; @@ -6640,7 +6640,7 @@ static Word16 read_GR_min_removed_data( /* read min index */ bits_GR = bit_pos; move16(); - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_symb, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, no_symb, 0 ); /*Q0*/ nbits = add( nbits, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -6650,7 +6650,7 @@ static Word16 read_GR_min_removed_data( move16(); IF( GT_16( no_cv_vec[j], 1 ) ) { - decoded_idx[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), extract_l( L_and( byteBuffer, 1 ) ) ); + decoded_idx[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), extract_l( L_and( byteBuffer, 1 ) ) ); /*Q0*/ move16(); nbits = add( nbits, sub( bits_GR, bit_pos ) ); } @@ -6737,12 +6737,12 @@ static int16_t read_GR_min_removed_data( #ifdef IVAS_FLOAT_FIXED static Word16 decode_fixed_rate_composed_index_coherence_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ - const Word16 no_bands, - Word16 *no_cv_vec, - UWord16 *decoded_index, - const Word16 no_symb ) + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ + const Word16 no_bands, /*Q0*/ + Word16 *no_cv_vec, /*Q0*/ + UWord16 *decoded_index, /*Q0*/ + const Word16 no_symb /*Q0*/ ) { /* fixed rate */ UWord64 no_cb; @@ -6774,13 +6774,13 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( { IF( GT_16( no_cv_vec[j], no_vals_local ) ) { - no_cv_vec[j] = no_vals_local; + no_cv_vec[j] = no_vals_local; /*Q0*/ move16(); } } } - half_no_bands = shr( no_bands, 1 ); + half_no_bands = shr( no_bands, 1 ); /* no_bands / 2 */ IF( GT_16( sum16_fx( no_cv_vec, no_bands ), MASA_COH_LIMIT_2IDX ) ) { no_cb = 1; @@ -6788,7 +6788,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < half_no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); @@ -6796,7 +6796,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = half_no_bands; j < no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec1 = (Word16) ceil_log_2( no_cb ); @@ -6807,7 +6807,7 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bands; j++ ) { - no_cb *= no_cv_vec[j]; + no_cb *= no_cv_vec[j]; /*Q0*/ move16(); } no_bits_vec = (Word16) ceil_log_2( no_cb ); @@ -6820,7 +6820,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec ); @@ -6831,7 +6833,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec1; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec1 ); decode_combined_index_fx( idx_fr, &no_cv_vec[half_no_bands], &temp_index[half_no_bands], half_no_bands ); @@ -6842,7 +6846,9 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos--]; + idx_fr = ( idx_fr << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); + move64(); } nbits = add( nbits, no_bits_vec ); decode_combined_index_fx( idx_fr, no_cv_vec, temp_index, no_bands ); @@ -6850,12 +6856,12 @@ static Word16 decode_fixed_rate_composed_index_coherence_fx( FOR( j = 0; j < no_bands; j++ ) { - decoded_index[j] = temp_index[j]; + decoded_index[j] = temp_index[j]; /*Q0*/ move16(); } nbits = sub( *p_bit_pos, bit_pos ); - *p_bit_pos = bit_pos; + *p_bit_pos = bit_pos; /*Q0*/ move16(); return nbits; @@ -6979,11 +6985,11 @@ static int16_t decode_fixed_rate_composed_index_coherence( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_coherence_data_hr_512_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - const Word16 idx_dir, /* i : direction index */ - const Word16 nbits_coh ) + const Word16 idx_dir, /* i : direction index Q0*/ + const Word16 nbits_coh /*Q0*/ ) { Word16 j, k, i; Word16 nbands, nblocks; @@ -7012,18 +7018,18 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); /*Q0*/ ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )]; + GR_param = bitstream[( *p_bit_pos )]; /*Q0*/ move16(); ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { - decoded_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, shl( cb_size, 1 ), GR_param ); + decoded_idx = ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, shl( cb_size, 1 ), GR_param ); /*Q0*/ IF( EQ_16( s_and( decoded_idx, 1 ), 1 ) ) { decoded_idx = add( shr( add( decoded_idx, 1 ), 1 ), min_index ); @@ -7033,7 +7039,7 @@ static Word16 read_coherence_data_hr_512_fx( decoded_idx = add( negate( shr( decoded_idx, 1 ) ), min_index ); } decoded_idx_fx = L_shl( decoded_idx, 9 ); - hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); /*Q0*/ move16(); } } @@ -7044,21 +7050,21 @@ static Word16 read_coherence_data_hr_512_fx( move16(); FOR( i = 0; i < nbits_coh; i++ ) { - min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); + min_index = add( shl( min_index, 1 ), bitstream[( *p_bit_pos )] ); /*Q0*/ ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); } /* read GR param */ - GR_param = bitstream[( *p_bit_pos )]; + GR_param = bitstream[( *p_bit_pos )]; /*Q0*/ move16(); ( *p_bit_pos ) = sub( ( *p_bit_pos ), 1 ); move16(); FOR( j = 0; j < nbands; j++ ) { - decoded_idx = add( ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, cb_size - min_index, GR_param ), min_index ); - decoded_idx_fx = L_shl( decoded_idx, 9 ); - hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); + decoded_idx = add( ivas_qmetadata_DecodeExtendedGR( bitstream, p_bit_pos, cb_size - min_index, GR_param ), min_index ); /*Q0*/ + decoded_idx_fx = L_shl( decoded_idx, 9 ); /*Q9*/ + hQMetaData->q_direction[idx_dir].coherence_band_data[j].spread_coherence[k] = (UWord8) L_add( Mpy_32_32( decoded_idx_fx, delta_fx ), L_shr( delta_fx, 23 ) ); /*Q0*/ move16(); } } @@ -7151,11 +7157,11 @@ static int16_t read_coherence_data_hr_512( /*! r: number of bits read */ #ifdef IVAS_FLOAT_FIXED static Word16 read_coherence_data_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - const Word16 idx_dir, /* i : direction index */ - const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding*/ + const Word16 idx_dir, /* i : direction index Q0*/ + const Word16 hrmasa_flag /* i : flag indicating high-rate MASA MD coding Q0*/ ) { Word16 j; @@ -7180,7 +7186,7 @@ static Word16 read_coherence_data_fx( coding_subbands = hQMetaData->q_direction[idx_dir].cfg.nbands; move16(); - extra_cv = idiv1616( coding_subbands, MASA_FACTOR_CV_COH ); + extra_cv = idiv1616( coding_subbands, MASA_FACTOR_CV_COH ); /*Q0*/ move16(); q_direction = &( hQMetaData->q_direction[idx_dir] ); bit_pos = *p_bit_pos; @@ -7194,11 +7200,11 @@ static Word16 read_coherence_data_fx( { IF( hrmasa_flag ) { - idx_ER = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], 1 ) ), extra_cv ) ); + idx_ER = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], 1 ) ), extra_cv ) ); /*Q0*/ } ELSE { - idx_ER = extract_l( L_add( L_sub( 7, q_direction->band_data[j].energy_ratio_index_mod[0] ), extra_cv ) ); + idx_ER = extract_l( L_add( L_sub( 7, q_direction->band_data[j].energy_ratio_index_mod[0] ), extra_cv ) ); /*Q0*/ } no_cv_vec[j] = add( idx_ER, 1 ); move16(); @@ -7213,7 +7219,7 @@ static Word16 read_coherence_data_fx( return 0; } - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); nbits = add( nbits, 1 ); @@ -7221,20 +7227,20 @@ static Word16 read_coherence_data_fx( IF( L_and( byteBuffer, 1 ) ) { /* decode GR min removed */ - nbits = add( nbits, read_GR_min_removed_data( bitstream, &bit_pos, no_cv_vec, coding_subbands, decoded_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv ) ); + nbits = add( nbits, read_GR_min_removed_data( bitstream, &bit_pos, no_cv_vec, coding_subbands, decoded_idx, MASA_MAX_NO_CV_SUR_COH + extra_cv ) ); /*Q0*/ FOR( j = 0; j < coding_subbands; j++ ) { IF( GT_16( no_cv_vec[j], 1 ) ) { - num = i_mult( decoded_idx[j], 255 ); + num = i_mult( decoded_idx[j], 255 ); /*Q0*/ move16(); - den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); + den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); /*Q0*/ q_den = norm_s( den ); q_num = sub( norm_s( num ), 1 ); - res = div_s( shl( num, q_num ), shl( den, q_den ) ); + res = div_s( shl( num, q_num ), shl( den, q_den ) ); /*Q15*/ q_res = add( sub( 15, q_den ), q_num ); - res = L_shl( res, sub( 16, q_res ) ); - q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + res = L_shl( res, sub( 16, q_res ) ); /*Q16*/ + q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); /*Q0*/ move16(); } ELSE @@ -7248,20 +7254,20 @@ static Word16 read_coherence_data_fx( { UWord16 decoded_index[MASA_MAXIMUM_CODING_SUBBANDS]; /* decode joint index */ - nbits = add( nbits, decode_fixed_rate_composed_index_coherence_fx( bitstream, &bit_pos, coding_subbands, no_cv_vec, decoded_index, add( MASA_NO_CV_COH, coding_subbands / MASA_FACTOR_CV_COH ) ) ); + nbits = add( nbits, decode_fixed_rate_composed_index_coherence_fx( bitstream, &bit_pos, coding_subbands, no_cv_vec, decoded_index, add( MASA_NO_CV_COH, coding_subbands / MASA_FACTOR_CV_COH ) ) ); /*Q0*/ FOR( j = 0; j < coding_subbands; j++ ) { IF( GT_16( no_cv_vec[j], 1 ) ) { - num = i_mult( decoded_index[j], 255 ); + num = i_mult( decoded_index[j], 255 ); /*Q0*/ move16(); - den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); + den = extract_l( L_add( L_sub( 7, L_shr( q_direction->band_data[j].energy_ratio_index_mod[0], hrmasa_flag ) ), coding_subbands / MASA_FACTOR_CV_COH ) ); /*Q0*/ q_den = norm_s( den ); q_num = sub( norm_s( num ), 1 ); - res = div_s( shl( num, q_num ), shl( den, q_den ) ); + res = div_s( shl( num, q_num ), shl( den, q_den ) ); /*Q15*/ q_res = add( sub( 15, q_den ), q_num ); - res = L_shl( res, sub( 16, q_res ) ); - q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); + res = L_shl( res, sub( 16, q_res ) ); /*Q16*/ + q_direction->coherence_band_data[j].spread_coherence[0] = (UWord8) ( round_fx( res ) ); /*Q0*/ move16(); } ELSE @@ -7278,14 +7284,14 @@ static Word16 read_coherence_data_fx( { IF( hrmasa_flag ) { - minimum_s( (Word16 *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); - no_cv_vec[j] = len_cb_dct0_masa[shr( min_index, 1 )]; - move16(); /* spread coherence DCT0*/ + minimum_s( (Word16 *) ( q_direction->band_data[j].energy_ratio_index ), q_direction->cfg.nblocks, &min_index ); /*Q0*/ + no_cv_vec[j] = len_cb_dct0_masa[( min_index / 2 )]; /*Q0*/ + move16(); /* spread coherence DCT0*/ } ELSE { - no_cv_vec[j] = len_cb_dct0_masa[q_direction->band_data[j].energy_ratio_index[0]]; - move16(); /* spread coherence DCT0*/ + no_cv_vec[j] = len_cb_dct0_masa[q_direction->band_data[j].energy_ratio_index[0]]; /*Q0*/ + move16(); /* spread coherence DCT0*/ } } @@ -7301,7 +7307,7 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 no_cb = 1; move64(); @@ -7311,13 +7317,14 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec1 = ceil_log_2( no_cb ); // (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); + no_bits_vec1 = ceil_log_2( no_cb ); // (int16_t) ceilf( logf( (float) no_cb ) * INV_LOG_2 ); Q0 dct0_index = 0; move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7330,7 +7337,8 @@ static Word16 read_coherence_data_fx( move64(); FOR( j = 0; j < no_bits_vec1; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7340,7 +7348,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { - q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; + q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; /*Q0*/ move16(); } } @@ -7358,16 +7366,17 @@ static Word16 read_coherence_data_fx( move64(); } - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 /* read joint index for DCT0 */ - no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); + no_bits_vec = ceil_log_2( no_cb ); // (int16_t)ceilf(logf((float)no_cb) * INV_LOG_2); Q0 dct0_index = 0; move64(); FOR( j = 0; j < no_bits_vec; j++ ) { - dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos--]; + dct0_index = ( dct0_index << 1 ) + bitstream[bit_pos]; /*Q0*/ + bit_pos = sub( bit_pos, 1 ); move64(); } @@ -7379,7 +7388,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { - q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; + q_direction->coherence_band_data[j].spread_coherence_dct0_index = spr_coh_temp_index[j]; /*Q0*/ move16(); } } @@ -7388,7 +7397,7 @@ static Word16 read_coherence_data_fx( FOR( j = 0; j < coding_subbands; j++ ) { bits_GR = bit_pos; - idx_dct1[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, shl( MASA_NO_CV_COH1, 1 ), 0 ); + idx_dct1[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, shl( MASA_NO_CV_COH1, 1 ), 0 ); /*Q0*/ move16(); nbits = add( nbits, sub( bits_GR, bit_pos ) ); } @@ -7404,12 +7413,12 @@ static Word16 read_coherence_data_fx( { IF( L_and( idx_dct1[j], 1 ) ) { - q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_add( idx_dct1[j], 1 ), 1 ), av_index ); + q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_add( idx_dct1[j], 1 ), 1 ), av_index ); /*Q0*/ move16(); } ELSE { - q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( -idx_dct1[j], 1 ), av_index ); + q_direction->coherence_band_data[j].spread_coherence_dct1_index = (UWord16) L_add( L_shr( L_negate( idx_dct1[j] ), 1 ), av_index ); /*Q0*/ move16(); } } @@ -7819,8 +7828,8 @@ static int16_t read_surround_coherence( } #else static Word16 read_surround_coherence( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData /* i/o: quantized metadata structure */ ) { @@ -7857,16 +7866,16 @@ static Word16 read_surround_coherence( idx = s_max( sub( d, 1 ), 0 ); IF( EQ_16( hQMetaData->twoDirBands[j], 1 ) ) { - error_ratio_surr = L_sub( L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), q_direction[1].band_data[idx].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ), q_direction[1].band_data[idx].energy_ratio_fx[0] ); /*Q30*/ } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); /*Q30*/ } } ELSE { - error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); + error_ratio_surr = L_sub( ONE_IN_Q30, q_direction[0].band_data[j].energy_ratio_fx[0] ); /*Q30*/ } IF( error_ratio_surr <= 0 ) @@ -7875,12 +7884,12 @@ static Word16 read_surround_coherence( move32(); no_cv_vec[j] = 1; move16(); - idx_ER[j] = masa_sq_fx( 0, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + idx_ER[j] = masa_sq_fx( 0, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); } ELSE { - idx_ER[j] = masa_sq_fx( error_ratio_surr, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); + idx_ER[j] = masa_sq_fx( error_ratio_surr, diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); /*Q0*/ move16(); no_cv_vec[j] = add( idx_cb_sur_coh_masa[idx_ER[j]], 2 ); move16(); @@ -7906,7 +7915,7 @@ static Word16 read_surround_coherence( } /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); move16(); bits_sur_coherence = add( bits_sur_coherence, 1 ); @@ -7915,14 +7924,14 @@ static Word16 read_surround_coherence( { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ bits_GR = bit_pos; move16(); - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); /*Q0*/ bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -7933,7 +7942,7 @@ static Word16 read_surround_coherence( /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); /*Q30*/ move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } @@ -7948,16 +7957,16 @@ static Word16 read_surround_coherence( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = add( idx_sur_coh[j], min_index ); + hQMetaData->surcoh_band_data[j].sur_coherence_index = add( idx_sur_coh[j], min_index ); /*Q0*/ move16(); } ELSE { - hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; /*Q0*/ move16(); } - hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * 8 ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } } @@ -7971,7 +7980,7 @@ static Word16 read_surround_coherence( FOR( j = 0; j < coding_subbands; j++ ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; /*Q0*/ move16(); } @@ -7980,7 +7989,7 @@ static Word16 read_surround_coherence( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[add( shl( idx_cb_sur_coh_masa[idx_ER[j]], 3 ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[0] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * 8 ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } ELSE @@ -7995,7 +8004,7 @@ static Word16 read_surround_coherence( { FOR( k = 1; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++ ) { - hQMetaData->surcoh_band_data[j].surround_coherence[k] = hQMetaData->surcoh_band_data[j].surround_coherence[0]; + hQMetaData->surcoh_band_data[j].surround_coherence[k] = hQMetaData->surcoh_band_data[j].surround_coherence[0]; /*Q0*/ move16(); } } @@ -8181,10 +8190,10 @@ static int16_t read_surround_coherence_hr( } #else static Word16 read_surround_coherence_hr_fx( - UWord16 *bitstream, /* i : bitstream */ - Word16 *p_bit_pos, /* i : position in the bitstream */ + UWord16 *bitstream, /* i : bitstream Q0*/ + Word16 *p_bit_pos, /* i : position in the bitstream Q0*/ IVAS_QMETADATA *hQMetaData, /* i/o: quantized metadata structure */ - Word64 energy_ratio[][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] ) + Word64 energy_ratio[][MASA_MAXIMUM_CODING_SUBBANDS][MAX_PARAM_SPATIAL_SUBFRAMES] /*Q62*/ ) { Word16 coding_subbands; Word16 no_cv_vec[MASA_MAXIMUM_CODING_SUBBANDS]; @@ -8216,15 +8225,15 @@ static Word16 read_surround_coherence_hr_fx( error_ratio_surr_fx = ONE_IN_Q62; IF( EQ_32( hQMetaData->no_directions, 2 ) ) { - d = add( d, hQMetaData->twoDirBands[j] ); + d = add( d, hQMetaData->twoDirBands[j] ); /*Q0*/ idx = s_max( sub( d, 1 ), 0 ); error_ratio_surr_fx = W_sub( W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ), - energy_ratio[1][idx][sf] * hQMetaData->twoDirBands[j] ); + energy_ratio[1][idx][sf] * hQMetaData->twoDirBands[j] ); /*Q62*/ } ELSE { - error_ratio_surr_fx = W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ); + error_ratio_surr_fx = W_sub( ONE_IN_Q62, energy_ratio[0][j][sf] ); /*Q62*/ } IF( LE_64( error_ratio_surr_fx, ( 461168601842 ) ) ) // 1e-7 in Q62 @@ -8238,8 +8247,10 @@ static Word16 read_surround_coherence_hr_fx( } ELSE { - idx_ER[j] = 7; // masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); - no_cv_vec[j] = idx_cb_sur_coh_masa[idx_ER[j]] + 2; + idx_ER[j] = 7; // masa_sq( error_ratio_surr, diffuseness_thresholds, DIRAC_DIFFUSE_LEVELS ); + no_cv_vec[j] = add( idx_cb_sur_coh_masa[idx_ER[j]], 2 ); /*Q0*/ + move16(); + move16(); } } @@ -8261,7 +8272,7 @@ static Word16 read_surround_coherence_hr_fx( ELSE { /* read how the surround coherence is encoded */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); @@ -8270,14 +8281,14 @@ static Word16 read_surround_coherence_hr_fx( { /* GR decoding */ /* read GR order */ - byteBuffer = bitstream[bit_pos]; + byteBuffer = bitstream[bit_pos]; /*Q0*/ move16(); bit_pos = sub( bit_pos, 1 ); bits_sur_coherence = add( bits_sur_coherence, 1 ); /* read min index */ bits_GR = bit_pos; - min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); + min_index = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, MASA_MAX_NO_CV_SUR_COH, 0 ); /*Q0*/ bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); /* read GR data */ @@ -8288,7 +8299,7 @@ static Word16 read_surround_coherence_hr_fx( /* decoding for min removed */ IF( GT_16( no_cv_vec[j], 1 ) ) { - idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); + idx_sur_coh[j] = ivas_qmetadata_DecodeExtendedGR( bitstream, &bit_pos, sub( no_cv_vec[j], min_index ), ( byteBuffer & 1 ) ); /*Q0*/ move16(); bits_sur_coherence = add( bits_sur_coherence, sub( bits_GR, bit_pos ) ); } @@ -8303,14 +8314,14 @@ static Word16 read_surround_coherence_hr_fx( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = (UWord16) L_add( (Word32) idx_sur_coh[j], L_deposit_l( min_index ) ); + hQMetaData->surcoh_band_data[j].sur_coherence_index = (UWord16) L_add( (Word32) idx_sur_coh[j], L_deposit_l( min_index ) ); /*Q0*/ move16(); - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; move16(); } ELSE { - hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = idx_sur_coh[j]; /*Q0*/ move16(); hQMetaData->surcoh_band_data[j].surround_coherence[sf] = 0; move16(); @@ -8327,7 +8338,7 @@ static Word16 read_surround_coherence_hr_fx( FOR( j = 0; j < coding_subbands; j++ ) { - hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; + hQMetaData->surcoh_band_data[j].sur_coherence_index = sur_coh_temp_index[j]; /*Q0*/ move16(); } @@ -8336,7 +8347,7 @@ static Word16 read_surround_coherence_hr_fx( { IF( GT_16( no_cv_vec[j], 1 ) ) { - hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[L_add( L_mult0( idx_cb_sur_coh_masa[idx_ER[j]], MASA_MAX_NO_CV_SUR_COH ), hQMetaData->surcoh_band_data[j].sur_coherence_index )]; + hQMetaData->surcoh_band_data[j].surround_coherence[sf] = sur_coherence_cb_masa[( ( idx_cb_sur_coh_masa[idx_ER[j]] * MASA_MAX_NO_CV_SUR_COH ) + hQMetaData->surcoh_band_data[j].sur_coherence_index )]; /*Q0*/ move16(); } ELSE @@ -8367,10 +8378,10 @@ static Word16 read_surround_coherence_hr_fx( #ifdef IVAS_FLOAT_FIXED static void decode_combined_index_fx( - UWord64 comb_index, /* i : index to be decoded */ - const Word16 *no_cv_vec, /* i : number of codewords for each element*/ - UWord16 *index, /* o : decoded indexes */ - const Word16 len /* i : number of elements */ + UWord64 comb_index, /* i : index to be decoded Q0*/ + const Word16 *no_cv_vec, /* i : number of codewords for each element Q0*/ + UWord16 *index, /* o : decoded indexes Q0*/ + const Word16 len /* i : number of elements Q0*/ ) { Word16 i; @@ -8426,12 +8437,12 @@ static void decode_combined_index( #ifdef IVAS_FLOAT_FIXED static void read_stream_dct_coeffs_omasa_fx( - Word16 *q_idx, + Word16 *q_idx, /*Q0*/ Word32 *q_dct_data_fx, - const Word16 len_stream, - UWord16 *bit_stream, - Word16 *index, - const Word16 first_line ) + const Word16 len_stream, /*Q0*/ + UWord16 *bit_stream, /*Q0*/ + Word16 *index, /*Q0*/ + const Word16 first_line /*Q0*/ ) { Word16 sign, nbits; Word16 i, j, i_min; @@ -8448,7 +8459,7 @@ static void read_stream_dct_coeffs_omasa_fx( IF( !first_line ) { /* read sign */ - sign = bit_stream[( *index )--]; + sign = bit_stream[( *index )--]; /*Q0*/ move16(); IF( !sign ) { @@ -8462,10 +8473,10 @@ static void read_stream_dct_coeffs_omasa_fx( /* read DCT 0 component */ FOR( i = 0; i < BITS_MASA2TOTTAL_DCT0; i++ ) { - q_idx[0] = add( shl( q_idx[0], 1 ), bit_stream[( *index )--] ); + q_idx[0] = add( shl( q_idx[0], 1 ), bit_stream[( *index )--] ); /*Q0*/ move16(); } - q_idx[0] = i_mult( q_idx[0], sign ); + q_idx[0] = i_mult( q_idx[0], sign ); /*Q0*/ move16(); IF( q_idx[0] != 0 ) @@ -8479,14 +8490,14 @@ static void read_stream_dct_coeffs_omasa_fx( move16(); FOR( i = 0; i < j; i++ ) { - i_min = extract_l( L_add( shl( i_min, 1 ), bit_stream[( *index )--] ) ); + i_min = extract_l( L_add( shl( i_min, 1 ), bit_stream[( *index )--] ) ); /*Q0*/ } nbits = add( nbits, j ); /* read GR orders */ - GR1 = extract_l( L_add( bit_stream[( *index )--], 1 ) ); + GR1 = extract_l( L_add( bit_stream[( *index )--], 1 ) ); /*Q0*/ IF( EQ_16( GR1, 2 ) ) { - GR2 = bit_stream[( *index )--]; + GR2 = bit_stream[( *index )--]; /*Q0*/ move16(); } ELSE @@ -8498,25 +8509,25 @@ static void read_stream_dct_coeffs_omasa_fx( /* read GR data */ FOR( i = 1; i <= i_min; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); /*Q0*/ move16(); } - FOR( i = add( i_min, 1 ); i < len_stream; i++ ) + FOR( i = ( i_min + 1 ); i < len_stream; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR2 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR2 ); /*Q0*/ move16(); } } ELSE { /* read GR order (only one) */ - GR1 = bit_stream[( *index )]; + GR1 = bit_stream[( *index )]; /*Q0*/ move16(); ( *index ) = sub( ( *index ), 1 ); move16(); FOR( i = 1; i < len_stream; i++ ) { - q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); + q_idx[i] = ivas_qmetadata_DecodeExtendedGR( bit_stream, index, 100, GR1 ); /*Q0*/ move16(); } } @@ -8529,12 +8540,12 @@ static void read_stream_dct_coeffs_omasa_fx( { IF( s_and( q_idx[i], 1 ) == 0 ) { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, negate( shl( q_idx[i], 6 ) ) ), 2 ); /*Q25*/ move32(); } ELSE { - q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); + q_dct_data_fx[i] = L_shl( Mpy_32_16_1( step, shl( q_idx[i] + 1, 6 ) ), 2 ); /*Q25*/ move32(); } } @@ -8648,11 +8659,11 @@ static void read_stream_dct_coeffs_omasa( #ifdef IVAS_FLOAT_FIXED void ivas_omasa_decode_masa_to_total_fx( - UWord16 *bit_stream, - Word16 *index, - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], - const Word16 nbands, - const Word16 nblocks ) + UWord16 *bit_stream, /*Q0*/ + Word16 *index, /*Q0*/ + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*Q30*/ + const Word16 nbands, /*Q0*/ + const Word16 nblocks /*Q0*/ ) { Word16 i, j, k; Word16 q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; @@ -8675,7 +8686,7 @@ void ivas_omasa_decode_masa_to_total_fx( set16_fx( q_idx, 0, i_mult( nbands, nblocks ) ); FOR( i = 0; i < n_streams; i++ ) { - read_stream_dct_coeffs_omasa_fx( &q_idx[L_mult0( i, len_stream )], &q_dct_data_fx[L_mult0( i, len_stream )], len_stream, bit_stream, index, i == 0 ); + read_stream_dct_coeffs_omasa_fx( &q_idx[( i * len_stream )], &q_dct_data_fx[( i * len_stream )], len_stream, bit_stream, index, i == 0 ); } /* inverse DCT2 transform */ @@ -8683,19 +8694,19 @@ void ivas_omasa_decode_masa_to_total_fx( { case 4: matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q25*/ BREAK; case 5: matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 8: matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 12: matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); - Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); + Copy32( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q25*/ BREAK; case 20: matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); @@ -8717,7 +8728,7 @@ void ivas_omasa_decode_masa_to_total_fx( { masa_to_total_energy_ratio_fx[i][j] = L_max( 0, q_dct_data_fx[k] ); // Q30 move32(); - masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); + masa_to_total_energy_ratio_fx[i][j] = L_min( ONE_IN_Q30, masa_to_total_energy_ratio_fx[i][j] ); /*Q30*/ move32(); k = add( k, 1 ); } @@ -8729,7 +8740,7 @@ void ivas_omasa_decode_masa_to_total_fx( { FOR( j = 0; j < nbands; j++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[0][j]; /*Q30*/ move32(); } } @@ -8741,7 +8752,7 @@ void ivas_omasa_decode_masa_to_total_fx( { FOR( i = 0; i < nblocks; i++ ) { - masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; + masa_to_total_energy_ratio_fx[i][j] = masa_to_total_energy_ratio_fx[i][0]; /*Q30*/ move32(); } } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index a2f308441..886db7651 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -261,8 +261,8 @@ ivas_error ivas_spar_md_dec_matrix_open( #else ivas_error ivas_spar_md_dec_matrix_open_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 num_md_sub_frames /* i : number of MD subframes */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 num_md_sub_frames /* i : number of MD subframes Q0*/ ) { Word16 i, j; @@ -437,9 +437,9 @@ ivas_error ivas_spar_md_dec_matrix_open_fx( /*! r: number of MD subframes */ #ifdef IVAS_FLOAT_FIXED Word16 ivas_get_spar_dec_md_num_subframes( - const Word16 sba_order, /* i : Ambisonic (SBA) order */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word32 ivas_last_active_brate /* i : IVAS last active bitrate */ + const Word16 sba_order, /* i : Ambisonic (SBA) order Q0*/ + const Word32 ivas_total_brate, /* i : IVAS total bitrate Q0*/ + const Word32 ivas_last_active_brate /* i : IVAS last active bitrate Q0*/ ) { Word16 num_subframes; @@ -464,7 +464,7 @@ Word16 ivas_get_spar_dec_md_num_subframes( move16(); } - return ( num_subframes ); + return ( num_subframes ); /*Q0*/ } #else int16_t ivas_get_spar_dec_md_num_subframes( @@ -504,10 +504,10 @@ int16_t ivas_get_spar_dec_md_num_subframes( ivas_error ivas_spar_md_dec_open( ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 sba_order, /* i : SBA order */ - const Word16 sid_format, /* i : SID format */ - const Word32 last_active_ivas_total_brate /* i : IVAS last active bitrate */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 sba_order, /* i : SBA order Q0*/ + const Word16 sid_format, /* i : SID format Q0*/ + const Word32 last_active_ivas_total_brate /* i : IVAS last active bitrate Q0*/ ) { ivas_spar_md_dec_state_t *hMdDec; @@ -522,7 +522,7 @@ ivas_error ivas_spar_md_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, hDecoderConfig->ivas_total_brate, last_active_ivas_total_brate ); /*Q0*/ IF( NE_32( ( error = ivas_spar_md_dec_matrix_open_fx( hMdDec, num_channels, num_md_sub_frames ) ), IVAS_ERR_OK ) ) { @@ -533,7 +533,7 @@ ivas_error ivas_spar_md_dec_open( { IF( EQ_16( sid_format, SID_SBA_2TC ) ) { - hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_48k, sba_order, SPAR_CONFIG_BW, NULL, NULL ); + hMdDec->table_idx = ivas_get_spar_table_idx( IVAS_48k, sba_order, SPAR_CONFIG_BW, NULL, NULL ); /*Q0*/ move16(); } ELSE @@ -681,7 +681,7 @@ void ivas_spar_md_dec_matrix_close( #else void ivas_spar_md_dec_matrix_close_fx( ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ - const Word16 num_channels /* i : number of internal channels */ + const Word16 num_channels /* i : number of internal channels Q0*/ ) { Word16 i, j; @@ -814,11 +814,11 @@ void ivas_spar_md_dec_close( return; } -Word32 pFC_8k[IVAS_MAX_NUM_BANDS] = { 33, 100, 166, 233, 300, 366, 433, 566, 866, 1333, 2033, 3233 }; -Word32 pFC_12k[IVAS_MAX_NUM_BANDS] = { 53, 160, 266, 373, 480, 586, 693, 906, 1386, 2133, 3253, 5173 }; -Word32 pFC_16k[IVAS_MAX_NUM_BANDS] = { 66, 200, 333, 466, 600, 733, 866, 1133, 1733, 2666, 4066, 6466 }; -Word32 pFC_32k[IVAS_MAX_NUM_BANDS] = { 133, 400, 666, 933, 1200, 1466, 1733, 2266, 3466, 5333, 8133, 12933 }; -Word32 pFC_48k[IVAS_MAX_NUM_BANDS] = { 199, 600, 1000, 1400, 1800, 2200, 2600, 3400, 5200, 8000, 12200, 19400 }; +Word32 pFC_8k[IVAS_MAX_NUM_BANDS] = { 33, 100, 166, 233, 300, 366, 433, 566, 866, 1333, 2033, 3233 }; /*Q0*/ +Word32 pFC_12k[IVAS_MAX_NUM_BANDS] = { 53, 160, 266, 373, 480, 586, 693, 906, 1386, 2133, 3253, 5173 }; /*Q0*/ +Word32 pFC_16k[IVAS_MAX_NUM_BANDS] = { 66, 200, 333, 466, 600, 733, 866, 1133, 1733, 2666, 4066, 6466 }; /*Q0*/ +Word32 pFC_32k[IVAS_MAX_NUM_BANDS] = { 133, 400, 666, 933, 1200, 1466, 1733, 2266, 3466, 5333, 8133, 12933 }; /*Q0*/ +Word32 pFC_48k[IVAS_MAX_NUM_BANDS] = { 199, 600, 1000, 1400, 1800, 2200, 2600, 3400, 5200, 8000, 12200, 19400 }; /*Q0*/ #ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -921,8 +921,8 @@ ivas_error ivas_spar_md_dec_init( ivas_error ivas_spar_md_dec_init( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ - const Word16 num_channels, /* i : number of internal channels */ - const Word16 sba_order /* i : SBA order */ + const Word16 num_channels, /* i : number of internal channels Q0*/ + const Word16 sba_order /* i : SBA order Q0*/ ) { Word16 i, j; @@ -952,23 +952,23 @@ ivas_error ivas_spar_md_dec_init( IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) ) { - pFC_fx = pFC_8k; + pFC_fx = pFC_8k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 12800 ) ) { - pFC_fx = pFC_12k; + pFC_fx = pFC_12k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 16000 ) ) { - pFC_fx = pFC_16k; + pFC_fx = pFC_16k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 32000 ) ) { - pFC_fx = pFC_32k; + pFC_fx = pFC_32k; /*Q0*/ } ELSE IF( EQ_32( hDecoderConfig->output_Fs, 48000 ) ) { - pFC_fx = pFC_48k; + pFC_fx = pFC_48k; /*Q0*/ } ELSE { @@ -988,9 +988,9 @@ ivas_error ivas_spar_md_dec_init( } /* DTX quant init */ - PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; + PR_minmax_fx[0] = hMdDec->spar_md_cfg.quant_strat[0].PR.min_fx; /*Q28*/ move32(); - PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; + PR_minmax_fx[1] = hMdDec->spar_md_cfg.quant_strat[0].PR.max_fx; /*Q28*/ move32(); ivas_spar_quant_dtx_init_fx( &hMdDec->spar_md, PR_minmax_fx ); @@ -1058,17 +1058,17 @@ ivas_error ivas_spar_md_dec_init( static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *hMdDec, const Word16 nchan_transport, - Word32 *pFC ) + Word32 *pFC /*Q0*/ ) { Word16 i, j, nchan, dmx_ch; FOR( i = 0; i < nchan_transport; i++ ) { - hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; + hMdDec->spar_md_cfg.max_freq_per_chan[i] = ivas_spar_br_table_consts[hMdDec->table_idx].fpcs; /*Q0*/ move16(); } - nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); + nchan = ivas_sba_get_nchan_metadata_fx( ivas_spar_br_table_consts[hMdDec->table_idx].sba_order, ivas_spar_br_table_consts[hMdDec->table_idx].ivas_total_brate ); /*Q0*/ SWITCH( nchan ) { @@ -1090,7 +1090,7 @@ static ivas_error ivas_spar_set_dec_config( BREAK; } - hMdDec->spar_md_cfg.num_umx_chs = nchan; + hMdDec->spar_md_cfg.num_umx_chs = nchan; /*Q0*/ move16(); dmx_ch = 0; @@ -1107,13 +1107,13 @@ static ivas_error ivas_spar_set_dec_config( } } - hMdDec->spar_md_cfg.num_dmx_chans_per_band[i] = hMdDec->spar_md_cfg.nchan_transport; + hMdDec->spar_md_cfg.num_dmx_chans_per_band[i] = hMdDec->spar_md_cfg.nchan_transport; /*Q0*/ move16(); - hMdDec->spar_md_cfg.num_decorr_per_band[i] = sub( nchan, hMdDec->spar_md_cfg.nchan_transport ); + hMdDec->spar_md_cfg.num_decorr_per_band[i] = sub( nchan, hMdDec->spar_md_cfg.nchan_transport ); /*Q0*/ move16(); } - hMdDec->spar_md_cfg.nchan_transport = dmx_ch; + hMdDec->spar_md_cfg.nchan_transport = dmx_ch; /*Q0*/ move16(); return IVAS_ERR_OK; @@ -1248,11 +1248,11 @@ static void ivas_dec_mono_sba_handling_fx( { FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; ++block ) { - Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 azimuth_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; /*Q22*/ move32(); - Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; + Word32 elevation_fx = st_ivas->hQMetaData->q_direction[0].band_data[b].azimuth_fx[block]; /*Q22*/ move32(); - Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; + Word32 energy_ratio_fx = st_ivas->hQMetaData->q_direction[0].band_data[0].energy_ratio_fx[block]; /*Q30*/ move32(); test(); @@ -1290,7 +1290,7 @@ static void ivas_dec_mono_sba_handling_fx( set32_fx( st_ivas->hSpatParamRendCom->energy_ratio2_fx[block], 0, st_ivas->hSpatParamRendCom->num_freq_bands ); } /* Set Diffuseness values to be 1.0 */ - set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); + set32_fx( st_ivas->hSpatParamRendCom->diffuseness_vector_fx[block], ONE_IN_Q30, st_ivas->hSpatParamRendCom->num_freq_bands ); /*Q30*/ } } } @@ -1310,8 +1310,8 @@ static void ivas_dec_mono_sba_handling_fx( void ivas_spar_md_dec_process_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 sba_order /* i : Ambisonic (SBA) order */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 sba_order /* i : Ambisonic (SBA) order Q0*/ ) { Word16 j, k, b, bw, dtx_vad, nB, i_ts; @@ -1334,28 +1334,28 @@ void ivas_spar_md_dec_process_fx( move16(); } - num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); + num_md_chs = ivas_sba_get_nchan_metadata_fx( sba_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/ - num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); + num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ); /*Q0*/ test(); IF( GT_16( hMdDec->spar_md_cfg.nchan_transport, 1 ) && LE_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { hMdDec->spar_md.res_ind = 0; move16(); - dyn_active_w_flag = get_next_indice_fx( st0, 1 ); + dyn_active_w_flag = get_next_indice_fx( st0, 1 ); /*Q0*/ IF( EQ_16( dyn_active_w_flag, 1 ) ) { IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 2 ) ) { - hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); + hMdDec->spar_md.res_ind = get_next_indice_fx( st0, 1 ); /*Q0*/ move16(); - hMdDec->spar_md.res_ind = add( hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind ); + hMdDec->spar_md.res_ind = add( hMdDec->spar_md_cfg.nchan_transport, hMdDec->spar_md.res_ind ); /*Q0*/ move16(); } ELSE IF( EQ_16( hMdDec->spar_md_cfg.nchan_transport, 3 ) ) { - hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; + hMdDec->spar_md.res_ind = remix_order_set[hMdDec->spar_md_cfg.remix_unmix_order][hMdDec->spar_md_cfg.nchan_transport]; /*Q0*/ move16(); } } @@ -1402,7 +1402,7 @@ void ivas_spar_md_dec_process_fx( { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; + hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j] = hMdDec->spar_md.band_coeffs[b].pred_re_fx[j]; /*Q22*/ move32(); } @@ -1410,14 +1410,14 @@ void ivas_spar_md_dec_process_fx( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; + hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].C_re_fx[j][k] = hMdDec->spar_md.band_coeffs[b].C_re_fx[j][k]; /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; + hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].P_re_fx[j] = hMdDec->spar_md.band_coeffs[b].P_re_fx[j]; /*Q22*/ move32(); } } @@ -1634,9 +1634,9 @@ Word16 ivas_spar_chk_zero_coefs_fx( Word16 ndec, ndm; hMdDec = st_ivas->hSpar->hMdDec; - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; /*Q0*/ move16(); FOR( b = 0; b < min( hMdDec->spar_md.num_bands, SPAR_DIRAC_SPLIT_START_BAND ); b++ ) @@ -1684,8 +1684,8 @@ Word16 ivas_spar_chk_zero_coefs_fx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_smooth_md_dtx_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 num_md_sub_frames /* i : number of metadata subframes */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 num_md_sub_frames /* i : number of metadata subframes Q0*/ ) { Word16 j, k, b, dmx_ch; @@ -1734,14 +1734,14 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; /*Q0*/ move16(); FOR( j = 1; j < FOA_CHANNELS; j++ ) { FOR( k = dmx_ch; k < FOA_CHANNELS; k++ ) { - hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.P_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1750,7 +1750,7 @@ void ivas_spar_smooth_md_dtx_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ + hMdDec->spar_coeffs.C_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][b]; /* Q22 */ move32(); } } @@ -1843,14 +1843,14 @@ void ivas_spar_smooth_md_dtx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_setup_md_smoothing_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 num_md_sub_frames /* i : number of metadata subframes */ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 num_md_sub_frames /* i : number of metadata subframes Q0*/ ) { /* copy the coeffs */ Word16 num_channels, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + num_channels = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); FOR( i = 0; i < num_channels; i++ ) @@ -1981,7 +1981,7 @@ void ivas_spar_update_md_hist_fx( { Word16 num_channels, i, j, k; - num_channels = hMdDec->spar_md_cfg.num_umx_chs; + num_channels = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); FOR( i = 0; i < num_channels; i++ ) @@ -2327,14 +2327,14 @@ static void ivas_get_spar_matrices( static void ivas_get_spar_matrices_fx( ivas_spar_md_dec_state_t *hMdDec, - const Word16 num_bands_out, - const Word16 n_ts, - const Word16 bw, - const Word16 dtx_vad, - const Word16 nB, - const Word16 numch_out, - const Word16 active_w_vlbr, - const Word16 dyn_active_w_flag ) + const Word16 num_bands_out, /*Q0*/ + const Word16 n_ts, /*Q0*/ + const Word16 bw, /*Q0*/ + const Word16 dtx_vad, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 numch_out, /*Q0*/ + const Word16 active_w_vlbr, /*Q0*/ + const Word16 dyn_active_w_flag /*Q0*/ ) { Word16 num_bands, dmx_ch, split_band; Word16 i, j, k, m, b, i_ts, active_w; @@ -2359,7 +2359,7 @@ static void ivas_get_spar_matrices_fx( { FOR( b = 0; b < num_bands; b++ ) { - hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; + hMdDec->mixer_mat_prev_fx[0][i][j][b] = hMdDec->mixer_mat_fx[i][j][b]; /*hMdDec->Q_mixer_mat*/ move32(); } } @@ -2397,8 +2397,8 @@ static void ivas_get_spar_matrices_fx( FOR( j = 0; j < numch_out; j++ ) { - set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); - set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][i_mult( i_ts, IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.C_re_fx[i][j][( i_ts * IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); + set32_fx( &hMdDec->spar_coeffs.P_re_fx[i][j][( i_ts * IVAS_MAX_NUM_BANDS )], 0, IVAS_MAX_NUM_BANDS ); } } num_bands = s_min( num_bands, nB ); @@ -2409,7 +2409,7 @@ static void ivas_get_spar_matrices_fx( Word32 tmp_C1_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_C2_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; Word32 tmp_dm_re_fx[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; - dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( bw, b )]; + dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( bw * b )]; /*Q0*/ move16(); FOR( j = 0; j < numch_out; j++ ) @@ -2418,9 +2418,9 @@ static void ivas_get_spar_matrices_fx( set_zero_fx( tmp_C2_re_fx[j], numch_out ); set_zero_fx( tmp_dm_re_fx[j], numch_out ); - tmp_C1_re_fx[j][j] = ONE_IN_Q22; - tmp_C2_re_fx[j][j] = ONE_IN_Q22; - tmp_dm_re_fx[j][j] = ONE_IN_Q22; + tmp_C1_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ + tmp_C2_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ + tmp_dm_re_fx[j][j] = ONE_IN_Q22; /*Q22*/ move32(); move32(); move32(); @@ -2428,7 +2428,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1]; // Q.22 + tmp_C1_re_fx[j][0] = hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1]; // Q.22 move32(); } @@ -2437,7 +2437,7 @@ static void ivas_get_spar_matrices_fx( FOR( j = 1; j < numch_out; j++ ) { - tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, L_negate( hMdDec->spar_md.band_coeffs[add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1] ) ); // Q31 *Q22=Q22 + tmp_C2_re_fx[0][j] = Mpy_32_32( active_w_dm_fac_fx, L_negate( hMdDec->spar_md.band_coeffs[( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[j - 1] ) ); // Q31 *Q22=Q22 move32(); } re_fx = Mpy_32_32( tmp_C2_re_fx[0][1], tmp_C1_re_fx[1][0] ); // Q22 *Q22 =Q13 @@ -2456,22 +2456,22 @@ static void ivas_get_spar_matrices_fx( move32(); } - tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; + tmp_dm_re_fx[0][1] = tmp_C2_re_fx[0][1]; /*Q22*/ move32(); - tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; + tmp_dm_re_fx[0][2] = tmp_C2_re_fx[0][2]; /*Q22*/ move32(); - tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; + tmp_dm_re_fx[0][3] = tmp_C2_re_fx[0][3]; /*Q22*/ move32(); - tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; + tmp_dm_re_fx[1][0] = tmp_C1_re_fx[1][0]; /*Q22*/ move32(); - tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; + tmp_dm_re_fx[2][0] = tmp_C1_re_fx[2][0]; /*Q22*/ move32(); - tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; + tmp_dm_re_fx[3][0] = tmp_C1_re_fx[3][0]; /*Q22*/ move32(); IF( NE_16( hMdDec->spar_md_cfg.remix_unmix_order, 3 ) ) @@ -2506,7 +2506,7 @@ static void ivas_get_spar_matrices_fx( FOR( k = 0; k < dmx_ch; k++ ) { - tmpC_re_fx[k][k] = ONE_IN_Q22; + tmpC_re_fx[k][k] = ONE_IN_Q22; /*Q22*/ move32(); } @@ -2543,9 +2543,9 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpP_re_fx[m][k] ); // Q30*Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], tmpP_re_fx[m][k] ); // Q30*Q22 = Q21 + re_fx = L_shl( re_fx, 1 ); /*Q22*/ + hMdDec->spar_coeffs.P_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.P_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )], re_fx ); /*Q22*/ move32(); } } @@ -2558,16 +2558,16 @@ static void ivas_get_spar_matrices_fx( { FOR( m = 0; m < numch_out; m++ ) { - re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], tmpC_re_fx[m][k] ); // Q30* Q22 - re_fx = L_shl( re_fx, 1 ); - hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], re_fx ); + re_fx = Mpy_32_32( hMdDec->mixer_mat_fx[j][m][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], tmpC_re_fx[m][k] ); // Q30* Q22 = Q21 + re_fx = L_shl( re_fx, 1 ); /*Q22*/ + hMdDec->spar_coeffs.C_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_add( hMdDec->spar_coeffs.C_re_fx[j][k][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )], re_fx ); /*Q22*/ move32(); } } } - hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = - L_max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][add( i_mult( b, bw ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] ); + hMdDec->spar_coeffs.C_re_fx[0][0][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = + L_max( 0, hMdDec->spar_coeffs.C_re_fx[0][0][( ( b * bw ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] ); /*Q22*/ move32(); } } @@ -2575,7 +2575,7 @@ static void ivas_get_spar_matrices_fx( /* band mixing */ IF( EQ_16( bw, IVAS_RED_BAND_FACT ) ) { - FOR( b = 0; b < num_bands_out; b = add( b, bw ) ) + FOR( b = 0; b < num_bands_out; b = ( b + bw ) ) { dmx_ch = hMdDec->spar_md_cfg.num_dmx_chans_per_band[b]; move16(); @@ -2583,7 +2583,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = dmx_ch; k < numch_out; k++ ) { - hMdDec->spar_coeffs.P_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; + hMdDec->spar_coeffs.P_re_fx[j][k][( ( b + 1 ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.P_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )]; /*Q22*/ move32(); } } @@ -2592,7 +2592,7 @@ static void ivas_get_spar_matrices_fx( { FOR( k = 0; k < dmx_ch; k++ ) { - hMdDec->spar_coeffs.C_re_fx[j][k][add( add( b, 1 ), i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )]; + hMdDec->spar_coeffs.C_re_fx[j][k][( ( b + 1 ) + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = hMdDec->spar_coeffs.C_re_fx[j][k][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )]; /*Q22*/ move32(); } } @@ -2641,23 +2641,23 @@ static void ivas_mat_col_rearrange( *-----------------------------------------------------------------------------------------*/ static void ivas_mat_col_rearrange_fx( - Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], - const Word16 order[IVAS_SPAR_MAX_CH], - const Word16 i_ts, - Word32 ***mixer_mat, - const Word16 bands, - const Word16 num_ch ) + Word32 in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], /*Q22*/ + const Word16 order[IVAS_SPAR_MAX_CH], /*Q0*/ + const Word16 i_ts, /*Q0*/ + Word32 ***mixer_mat, /*Q30*/ + const Word16 bands, /*Q0*/ + const Word16 num_ch /*Q0*/ ) { Word16 i, j, idx; FOR( i = 0; i < num_ch; i++ ) { - idx = order[i]; + idx = order[i]; /*Q0*/ move16(); FOR( j = 0; j < num_ch; j++ ) { - mixer_mat[j][i][add( bands, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( in_re[j][idx], Q8 ); + mixer_mat[j][i][( bands + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( in_re[j][idx], Q8 ); /*Q30*/ move32(); } } @@ -2674,10 +2674,10 @@ static void ivas_mat_col_rearrange_fx( #ifdef IVAS_FLOAT_FIXED void ivas_spar_dec_gen_umx_mat_fx( ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 nchan_transport, /* i : number of transport channels */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bfi, /* i : bad frame indicator */ - const Word16 num_md_sub_frames ) + const Word16 nchan_transport, /* i : number of transport channels Q0*/ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 bfi, /* i : bad frame indicator Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 i, j, b, i_ts, num_out_ch; num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; @@ -2692,7 +2692,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2703,7 +2703,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.P_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2717,7 +2717,7 @@ void ivas_spar_dec_gen_umx_mat_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], Q8 ); + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl_sat( hMdDec->spar_coeffs.C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], Q8 ); /*Q30*/ move32(); } } @@ -2791,47 +2791,47 @@ void ivas_spar_dec_gen_umx_mat( static void ivas_spar_md_band_upmix( ivas_band_coeffs_t *band_coeffs, - Word16 *nB, - Word16 *bands_bw, - Word16 *valid_bands, - Word16 bw_final, - Word16 ndec, - Word16 ndm ) + Word16 *nB, /*Q0*/ + Word16 *bands_bw, /*Q0*/ + Word16 *valid_bands, /*Q0*/ + Word16 bw_final, /*Q0*/ + Word16 ndec, /*Q0*/ + Word16 ndm /*Q0*/ ) { Word16 i, ii, jj, b, idx, bw_fact; - bw_fact = idiv1616( *bands_bw, bw_final ); + bw_fact = idiv1616( *bands_bw, bw_final ); /*Q0*/ FOR( i = sub( *nB, 1 ); i >= 0; i-- ) { FOR( b = sub( bw_fact, 1 ); b >= 0; b-- ) { - idx = add( i_mult( i, bw_fact ), b ); - FOR( ii = 0; ii < sub( add( ndec, ndm ), 1 ); ii++ ) + idx = add( i_mult( i, bw_fact ), b ); /*Q0*/ + FOR( ii = 0; ii < ( ( ndec + ndm ) - 1 ); ii++ ) { - band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; + band_coeffs[idx].pred_re_fx[ii] = band_coeffs[i].pred_re_fx[ii]; /*Q22*/ move32(); } FOR( ii = 0; ii < ndec; ii++ ) { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; + band_coeffs[idx].C_re_fx[ii][jj] = band_coeffs[i].C_re_fx[ii][jj]; /*Q22*/ move32(); } } FOR( jj = 0; jj < ndec; jj++ ) { - band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; + band_coeffs[idx].P_re_fx[jj] = band_coeffs[i].P_re_fx[jj]; /*Q22*/ move32(); } - valid_bands[idx] = valid_bands[i]; + valid_bands[idx] = valid_bands[i]; /*Q0*/ move16(); } } - *nB = idiv1616( i_mult( ( *nB ), ( *bands_bw ) ), bw_final ); + *nB = idiv1616( i_mult( ( *nB ), ( *bands_bw ) ), bw_final ); /*Q0*/ move16(); - *bands_bw = bw_final; + *bands_bw = bw_final; /*Q0*/ move16(); return; @@ -3081,11 +3081,11 @@ static void ivas_spar_dec_parse_md_bs( static void ivas_spar_dec_parse_md_bs_fx( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, - Word16 *nB, - Word16 *bands_bw, - Word16 *dtx_vad, - const Word32 ivas_total_brate, - const Word16 sba_inactive_mode ) + Word16 *nB, /*Q0*/ + Word16 *bands_bw, /*Q0*/ + Word16 *dtx_vad, /*Q0*/ + const Word32 ivas_total_brate, /*Q0*/ + const Word16 sba_inactive_mode /*Q0*/ ) { Word16 i, j, k, num_bands; Word16 ii, jj, ndec, ndm; @@ -3111,7 +3111,7 @@ static void ivas_spar_dec_parse_md_bs_fx( IF( GE_32( ivas_total_brate, BRATE_SPAR_Q_STRAT ) ) { /*only one bit written for quantization strategy to indicate either a fixed quantization strategy or dtx_vad==0 */ - qsi = get_next_indice_fx( st0, 1 ); + qsi = get_next_indice_fx( st0, 1 ); /*Q0*/ if ( EQ_32( qsi, 1 ) ) { *dtx_vad = 0; @@ -3144,14 +3144,14 @@ static void ivas_spar_dec_parse_md_bs_fx( move16(); } - hMdDec->dtx_vad = *dtx_vad; + hMdDec->dtx_vad = *dtx_vad; /*Q0*/ move16(); IF( *dtx_vad == 0 ) { *nB = SPAR_DTX_BANDS; move16(); - *bands_bw = idiv1616( num_bands, *nB ); + *bands_bw = idiv1616( num_bands, *nB ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) @@ -3183,9 +3183,9 @@ static void ivas_spar_dec_parse_md_bs_fx( IF( NE_16( *bands_bw, 1 ) ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[0]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[0]; /*Q0*/ move16(); ivas_spar_md_band_upmix( hMdDec->spar_md.band_coeffs, @@ -3202,7 +3202,7 @@ static void ivas_spar_dec_parse_md_bs_fx( qs = hMdDec->spar_md_cfg.quant_strat[qsi]; - strat = get_next_indice_fx( st0, 3 ); + strat = get_next_indice_fx( st0, 3 ); /*Q0*/ no_ec = 0; move16(); @@ -3211,7 +3211,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = add( strat, 1 ); move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { @@ -3225,7 +3225,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = sub( strat, 1 ); move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { @@ -3241,14 +3241,14 @@ static void ivas_spar_dec_parse_md_bs_fx( { *bands_bw = 2; move16(); - *nB = idiv1616( num_bands, *bands_bw ); + *nB = idiv1616( num_bands, *bands_bw ); /*Q0*/ move16(); FOR( i = 0; i < *nB; i++ ) { do_diff[i] = 0; move16(); - do_repeat[i] = extract_l( EQ_16( ( strat % 2 ), ( add( i, 1 ) % 2 ) ) ); + do_repeat[i] = extract_l( EQ_16( ( strat % 2 ), ( add( i, 1 ) % 2 ) ) ); /*Q0*/ move16(); } } @@ -3261,7 +3261,7 @@ static void ivas_spar_dec_parse_md_bs_fx( FOR( i = 0; i < *nB; i++ ) { - do_diff[i] = extract_l( NE_16( s_and( add( i, 1 ), 3 ), sub( strat, 4 ) ) ); + do_diff[i] = extract_l( NE_16( s_and( add( i, 1 ), 3 ), sub( strat, 4 ) ) ); /*Q0*/ move16(); do_repeat[i] = 0; move16(); @@ -3285,9 +3285,9 @@ static void ivas_spar_dec_parse_md_bs_fx( FOR( i = 0; i < *nB; i++ ) { - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[i_mult( ( *bands_bw ), i )]; + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[( ( *bands_bw ) * i )]; /*Q0*/ move16(); - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[i_mult( ( *bands_bw ), i )]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[( ( *bands_bw ) * i )]; /*Q0*/ move16(); ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].pred_index_re, qs.PR.q_levels[0], qs.PR.min_fx, qs.PR.max_fx, hMdDec->spar_md.band_coeffs[i].pred_re_fx, sub( add( ndm, ndec ), 1 ) ); @@ -3298,7 +3298,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; + quant_fx[j] = hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj]; /*Q22*/ move32(); j = add( j, 1 ); } @@ -3312,7 +3312,7 @@ static void ivas_spar_dec_parse_md_bs_fx( { FOR( jj = 0; jj < sub( ndm, 1 ); jj++ ) { - hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; + hMdDec->spar_md.band_coeffs[i].C_re_fx[ii][jj] = quant_fx[j]; /*Q22*/ move32(); j = add( j, 1 ); } @@ -3321,19 +3321,19 @@ static void ivas_spar_dec_parse_md_bs_fx( ivas_deindex_real_index_fx( hMdDec->spar_md.band_coeffs_idx[i].decd_index_re, qs.P_r.q_levels[0], qs.P_r.min_fx, qs.P_r.max_fx, hMdDec->spar_md.band_coeffs[i].P_re_fx, sub( add( ndm, ndec ), 1 ) ); /* Store prior coefficient indices */ - FOR( j = 0; j < sub( add( ndm, ndec ), 1 ); j++ ) + FOR( j = 0; j < ( ( ndm + ndec ) - 1 ); j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].pred_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; /*Q0*/ move16(); } - FOR( j = 0; j < i_mult( ndec, sub( ndm, 1 ) ); j++ ) + FOR( j = 0; j < ( ndec * ( ndm - 1 ) ); j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].drct_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].drct_index_re[j]; /*Q0*/ move16(); } FOR( j = 0; j < ndec; j++ ) { - hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; + hMdDec->spar_md_prev.band_coeffs_idx[i].decd_index_re[j] = hMdDec->spar_md.band_coeffs_idx[i].decd_index_re[j]; /*Q0*/ move16(); } test(); @@ -3380,13 +3380,13 @@ static void ivas_spar_dec_parse_md_bs_fx( #ifdef IVAS_FLOAT_FIXED static void ivas_decode_arith_bs( ivas_spar_md_dec_state_t *hMdDec, - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const UWord16 qsi, - const Word16 nB, - const Word16 bands_bw, - Word16 *pDo_diff, - const Word16 strat, - const Word32 ivas_total_brate ) + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const UWord16 qsi, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 bands_bw, /*Q0*/ + Word16 *pDo_diff, /*Q0*/ + const Word16 strat, /*Q0*/ + const Word32 ivas_total_brate /*Q0*/ ) { Word16 i, ndm, ndec; Word16 j; @@ -3430,7 +3430,7 @@ static void ivas_decode_arith_bs( } ELSE { - pred_cell_dims[i].dim1 = add( ndm, sub( ndec, 1 ) ); + pred_cell_dims[i].dim1 = add( ndm, sub( ndec, 1 ) ); /*Q0*/ move16(); IF( hMdDec->spar_hoa_md_flag && hMdDec->spar_hoa_dirac2spar_md_flag ) { @@ -3480,7 +3480,7 @@ static void ivas_decode_arith_bs( FOR( j = 0; j < pred_cell_dims[i].dim1; j++ ) { hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j] = - hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j + ( FOA_CHANNELS - 1 )]; + hMdDec->spar_md_prev.band_coeffs_idx_mapped[i].pred_index_re[j + ( FOA_CHANNELS - 1 )]; /*Q0*/ move16(); } } @@ -3504,7 +3504,7 @@ static void ivas_decode_arith_bs( FOR( j = pred_cell_dims[i].dim1 - 1; j >= 0; j-- ) { hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j + ( FOA_CHANNELS - 1 )] = - hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; + hMdDec->spar_md.band_coeffs_idx[i].pred_index_re[j]; /*Q0*/ move16(); } FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) @@ -3554,8 +3554,8 @@ static void ivas_decode_arith_bs( static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, - const Word16 nB, - Word16 *pSymbol_re, + const Word16 nB, /*Q0*/ + Word16 *pSymbol_re, /*Q0*/ ivas_cell_dim_t *pCell_dims, const ivas_coeffs_type_t coeff_type ) { @@ -3592,8 +3592,8 @@ static void ivas_fill_band_coeffs_idx( IF( NE_16( coeff_type, DECX_COEFF ) ) { - len = imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ); - Copy( pSymbol_re, pPtr_idx, len ); + len = imult1616( pCell_dims[i].dim1, pCell_dims[i].dim2 ); /*Q0*/ + Copy( pSymbol_re, pPtr_idx, len ); /*Q0*/ pSymbol_re += len; } } @@ -3611,9 +3611,9 @@ static void ivas_fill_band_coeffs_idx( static void ivas_decode_huffman_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const UWord16 qsi, - const Word16 nB, - const Word16 bands_bw ) + const UWord16 qsi, /*Q0*/ + const Word16 nB, /*Q0*/ + const Word16 bands_bw /*Q0*/ ) { Word16 i, j; Word16 ndm, ndec; @@ -3621,13 +3621,13 @@ static void ivas_decode_huffman_bs( FOR( i = 0; i < nB; i++ ) { - ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; - ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; + ndm = hMdDec->spar_md_cfg.num_dmx_chans_per_band[bands_bw * i]; /*Q0*/ + ndec = hMdDec->spar_md_cfg.num_decorr_per_band[bands_bw * i]; /*Q0*/ move16(); move16(); pred_dim = sub( add( ndec, ndm ), 1 ); - drct_dim = imult1616( ndec, sub( ndm, 1 ) ); + drct_dim = imult1616( ndec, sub( ndm, 1 ) ); /*Q0*/ decd_dim = ndec; pred_offset = 0; move16(); @@ -3674,13 +3674,13 @@ static void ivas_decode_huffman_bs( } static void ivas_spar_plc_get_band_age( - const Word16 *valid_bands, - Word16 *base_band_age, - const Word16 num_bands, - Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 *all_valid, - Word16 *b_idx ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + const Word16 num_bands, /*Q0*/ + Word16 last_valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 *all_valid, /*Q0*/ + Word16 *b_idx /*Q0*/ ) { Word16 b, idx; @@ -3700,7 +3700,7 @@ static void ivas_spar_plc_get_band_age( } ELSE { - base_band_age[b] = add( base_band_age[b], 1 ); /* increment the age of invalid bands */ + base_band_age[b] = add( base_band_age[b], 1 ); /* increment the age of invalid bands */ /*Q0*/ IF( GT_16( base_band_age[b], 3 ) ) { @@ -3751,17 +3751,17 @@ static void ivas_spar_get_plc_interp_weights( #else static void ivas_spar_get_plc_interp_weights_fx( - Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], - Word16 last_valid_band_idx, - Word16 idx, - Word16 b, - Word16 *w, - Word16 *id0, - Word16 *id1 ) + Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], /*Q0*/ + Word16 last_valid_band_idx, /*Q0*/ + Word16 idx, /*Q0*/ + Word16 b, /*Q0*/ + Word16 *w, /*Q15*/ + Word16 *id0, /*Q0*/ + Word16 *id1 /*Q0*/ ) { IF( last_valid_band_idx < 0 ) /* Extrapolation */ { - *id1 = valid_band_idx[0]; + *id1 = valid_band_idx[0]; /*Q0*/ move16(); *id0 = 0; move16(); @@ -3770,18 +3770,18 @@ static void ivas_spar_get_plc_interp_weights_fx( } ELSE IF( EQ_16( last_valid_band_idx, idx ) ) /* Extrapolation */ { - *id1 = valid_band_idx[last_valid_band_idx]; + *id1 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); - *id0 = valid_band_idx[last_valid_band_idx]; + *id0 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); *w = 0; move16(); } ELSE /* Interpolation */ { - *id0 = valid_band_idx[last_valid_band_idx]; + *id0 = valid_band_idx[last_valid_band_idx]; /*Q0*/ move16(); - *id1 = valid_band_idx[last_valid_band_idx + 1]; + *id1 = valid_band_idx[last_valid_band_idx + 1]; /*Q0*/ move16(); IF( sub( b, *id0 ) == 0 ) { @@ -3790,7 +3790,7 @@ static void ivas_spar_get_plc_interp_weights_fx( } ELSE { - *w = divide3232( sub( b, *id0 ), sub( *id1, *id0 ) ); + *w = divide3232( sub( b, *id0 ), sub( *id1, *id0 ) ); /*Q0*/ move16(); } } @@ -3808,11 +3808,11 @@ static void ivas_spar_get_plc_interp_weights_fx( static void ivas_spar_md_fill_invalid_bands_fx( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, - const Word16 *valid_bands, - Word16 *base_band_age, - const Word16 num_bands, - const Word16 num_channels, - const Word16 num_md_sub_frames ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + const Word16 num_bands, /*Q0*/ + const Word16 num_channels, /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 i, j, b, all_valid; Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; @@ -3839,9 +3839,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( j = 0; j < num_channels; j++ ) { - pSpar_coeffs->C_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id1], w_fx ) ); + pSpar_coeffs->C_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->C_re_fx[i][j][id1], w_fx ) ); /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id1], w_fx ) ); + pSpar_coeffs->P_re_fx[i][j][b] = L_add( Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id0], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pSpar_coeffs->P_re_fx[i][j][id1], w_fx ) ); /*Q22*/ move32(); } } @@ -3854,9 +3854,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( j = 0; j < num_channels; j++ ) { - pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][b] = pSpar_coeffs_prev->C_re_fx[i][j][b]; /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][b] = pSpar_coeffs_prev->P_re_fx[i][j][b]; /*Q22*/ move32(); } } @@ -3872,9 +3872,9 @@ static void ivas_spar_md_fill_invalid_bands_fx( { FOR( i_ts = 1; i_ts < num_md_sub_frames; i_ts++ ) { - pSpar_coeffs->C_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->C_re_fx[i][j][b]; + pSpar_coeffs->C_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->C_re_fx[i][j][b]; /*Q22*/ move32(); - pSpar_coeffs->P_re_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->P_re_fx[i][j][b]; + pSpar_coeffs->P_re_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = pSpar_coeffs->P_re_fx[i][j][b]; /*Q22*/ move32(); } } @@ -3969,10 +3969,10 @@ static void ivas_spar_md_fill_invalid_bands( static void ivas_spar_md_fill_invalid_bandcoeffs( ivas_band_coeffs_t *pBand_coeffs, ivas_band_coeffs_t *pBand_coeffs_prev, - const Word16 *valid_bands, - Word16 *base_band_age, - Word16 *first_valid_frame, - const Word16 num_bands ) + const Word16 *valid_bands, /*Q0*/ + Word16 *base_band_age, /*Q0*/ + Word16 *first_valid_frame, /*Q0*/ + const Word16 num_bands /*Q0*/ ) { Word16 j, k, b, all_valid; Word16 valid_band_idx[IVAS_MAX_NUM_BANDS], idx = -1; @@ -4001,7 +4001,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); + pBand_coeffs[b].pred_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].pred_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].pred_re_fx[j], w_fx ) ); /*Q22*/ move32(); } @@ -4009,14 +4009,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); + pBand_coeffs[b].C_re_fx[j][k] = L_add( Mpy_32_16_1( pBand_coeffs[id0].C_re_fx[j][k], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].C_re_fx[j][k], w_fx ) ); /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); + pBand_coeffs[b].P_re_fx[j] = L_add( Mpy_32_16_1( pBand_coeffs[id0].P_re_fx[j], sub( MAX_WORD16, w_fx ) ), Mpy_32_16_1( pBand_coeffs[id1].P_re_fx[j], w_fx ) ); /*Q22*/ move32(); } } @@ -4026,7 +4026,7 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; + pBand_coeffs[b].pred_re_fx[j] = pBand_coeffs_prev[b].pred_re_fx[j]; /*Q22*/ move32(); } @@ -4034,14 +4034,14 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( { FOR( k = 0; k < IVAS_SPAR_MAX_DMX_CHS - 1; k++ ) { - pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; + pBand_coeffs[b].C_re_fx[j][k] = pBand_coeffs_prev[b].C_re_fx[j][k]; /*Q22*/ move32(); } } FOR( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ ) { - pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; + pBand_coeffs[b].P_re_fx[j] = pBand_coeffs_prev[b].P_re_fx[j]; /*Q22*/ move32(); } } @@ -4147,13 +4147,13 @@ static void ivas_spar_md_fill_invalid_bandcoeffs( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( ivas_spar_md_dec_state_t *hMdDec, - const Word16 num_bands_out, - const Word16 bfi, - const Word16 num_md_sub_frames ) + const Word16 num_bands_out, /*Q0*/ + const Word16 bfi, /*Q0*/ + const Word16 num_md_sub_frames /*Q0*/ ) { Word16 num_in_ch, num_out_ch, i, j, b; - num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; - num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; + num_in_ch = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ + num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/ move16(); move16(); IF( bfi == 0 ) @@ -4170,7 +4170,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( hMdDec->spar_plc_num_lost_frames = add( hMdDec->spar_plc_num_lost_frames, 1 ); move16(); - hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ + hMdDec->spar_plc_num_lost_frames = s_min( hMdDec->spar_plc_num_lost_frames, 100 ); /*hMdDec->spar_plc_num_lost_frames is always <=100*/ /*Q0*/ move16(); IF( GT_16( hMdDec->spar_plc_num_lost_frames, ivas_spar_dec_plc_num_frames_keep ) ) /*if control enters then ivas_spar_dec_plc_num_frames_keep<100 */ @@ -4186,8 +4186,8 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( norm_nff = norm_s( num_fade_frames ); gain_dB = negate( imult1616( s_min( num_fade_frames, ivas_spar_dec_plc_max_num_frames_ramp_down ), ivas_spar_dec_plc_per_frame_ramp_down_gain_dB ) ); /*abs(gain_dB)<99*/ /*Q(gain_dB)=7Q24*/ Word16 exp_gain = 0; - move16(); /*stores exponent for gain_fx*/ - gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); + move16(); /*stores exponent for gain_fx*/ + gain_fx = BASOP_util_Pow2( Mult_32_16( imult3216( 13421773 /*=2^28/20*/, gain_dB ), 27213 /*=log2(10)*2^13*/ ), 5, &exp_gain ); /*Q_gain*/ Q_gain = sub( 31, exp_gain ); FOR( i = 0; i < IVAS_SPAR_MAX_CH; i++ ) { @@ -4208,7 +4208,7 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix_fx( { FOR( b = 0; b < num_bands_out; b++ ) { - hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )] = L_shl( Mult_32_32( hMdDec->mixer_mat_fx[i][j][add( b, i_mult( i_ts, IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ), sub( Q30, hMdDec->Q_mixer_mat ) ); // Q30 + hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )] = L_shl( Mult_32_32( hMdDec->mixer_mat_fx[i][j][( b + ( i_ts * IVAS_MAX_NUM_BANDS ) )], post_matrix_fx[i] ), sub( Q30, hMdDec->Q_mixer_mat ) ); // Q30 move32(); } } @@ -4294,9 +4294,9 @@ static void ivas_spar_dec_compute_ramp_down_post_matrix( #ifdef IVAS_FLOAT_FIXED static void ivas_spar_unquant_dtx_indicies( ivas_spar_md_t *pSpar_md, - const Word16 nB, - const Word16 bw, - Word16 *ndm_per_band ) + const Word16 nB, /*Q0*/ + const Word16 bw, /*Q0*/ + Word16 *ndm_per_band /*Q0*/ ) { Word16 i, b; Word16 q_lvl; @@ -4304,34 +4304,34 @@ static void ivas_spar_unquant_dtx_indicies( Word16 idx; Word32 pr_min_max_fx[2]; - pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; + pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; /*Q28*/ move32(); - pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; /*Q28*/ move32(); FOR( b = 0; b < nB; b++ ) { FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) { - q_lvl = dtx_pr_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + q_lvl = dtx_pr_real_q_levels[( ndm_per_band[( bw * b )] - 1 )][i]; /*Q0*/ move16(); - idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; + idx = pSpar_md->band_coeffs_idx[b].pred_index_re[i]; /*Q0*/ move16(); ivas_deindex_real_index_fx( &idx, q_lvl, pr_min_max_fx[0], pr_min_max_fx[1], &val_fx, 1 ); - pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; + pSpar_md->band_coeffs[b].pred_re_fx[i] = val_fx; /*Q22*/ move32(); } - FOR( i = 0; i < sub( FOA_CHANNELS, ndm_per_band[i_mult( bw, b )] ); i++ ) + FOR( i = 0; i < ( FOA_CHANNELS - ndm_per_band[( bw - b )] ); i++ ) { - q_lvl = dtx_pd_real_q_levels[sub( ndm_per_band[i_mult( bw, b )], 1 )][i]; + q_lvl = dtx_pd_real_q_levels[( ndm_per_band[( bw * b )] - 1 )][i]; /*Q0*/ move16(); - idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; + idx = pSpar_md->band_coeffs_idx[b].decd_index_re[i]; /*Q0*/ move16(); ivas_deindex_real_index_fx( &idx, q_lvl, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &val_fx, 1 ); - pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; + pSpar_md->band_coeffs[b].P_re_fx[i] = val_fx; /*Q22*/ move32(); } } @@ -4385,11 +4385,11 @@ static void ivas_spar_unquant_dtx_indicies( #ifdef IVAS_FLOAT_FIXED static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, - Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ - const Word16 bw, - const Word16 num_bands, - Word16 *num_dmx_per_band, - Word16 *num_dec_per_band ) + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const Word16 bw, /*Q0*/ + const Word16 num_bands, /*Q0*/ + Word16 *num_dmx_per_band, /*Q0*/ + Word16 *num_dec_per_band /*Q0*/ ) { Word16 i, j, ndec, ndm; Word32 val_fx; @@ -4398,18 +4398,18 @@ static void ivas_parse_parameter_bitstream_dtx( Word16 pr_q_lvls, pr, pd, pd_q_lvls, pr_pd_bits; Word16 zero_pad_bits, sid_bits_len; - sid_bits_len = st0->next_bit_pos; + sid_bits_len = st0->next_bit_pos; /*Q0*/ move16(); - pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; + pr_min_max_fx[0] = pSpar_md->min_max_fx[0]; /*Q28*/ move32(); - pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; + pr_min_max_fx[1] = pSpar_md->min_max_fx[1]; /*Q28*/ move32(); FOR( i = 0; i < num_bands; i++ ) { - ndec = num_dec_per_band[i_mult( bw, i )]; + ndec = num_dec_per_band[( bw * i )]; move16(); - ndm = num_dmx_per_band[i_mult( bw, i )]; + ndm = num_dmx_per_band[( bw * i )]; move16(); FOR( j = 0; j < FOA_CHANNELS - 1; j++ ) @@ -4417,13 +4417,13 @@ static void ivas_parse_parameter_bitstream_dtx( Word16 pr_idx_1, pr_idx_2, pd_idx_1, pd_idx_2; UWord16 value; - pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; + pr_idx_1 = pr_pr_idx_pairs[ndm - 1][j][0]; /*Q0*/ move16(); - pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; + pr_idx_2 = pr_pr_idx_pairs[ndm - 1][j][1]; /*Q0*/ move16(); - pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; + pd_idx_1 = pr_pd_idx_pairs[ndm - 1][j][0]; /*Q0*/ move16(); - pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; + pd_idx_2 = pr_pd_idx_pairs[ndm - 1][j][1]; /*Q0*/ move16(); test(); @@ -4431,7 +4431,7 @@ static void ivas_parse_parameter_bitstream_dtx( test(); IF( pr_idx_1 != 0 || pd_idx_1 != 0 || pr_idx_2 != 0 || pd_idx_2 != 0 ) { - pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; + pr_q_lvls = dtx_pr_real_q_levels[ndm - 1][pd_idx_1 - 1]; /*Q0*/ move16(); IF( GT_16( add( j, 1 ), ndec ) ) @@ -4441,17 +4441,17 @@ static void ivas_parse_parameter_bitstream_dtx( } ELSE { - pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; + pd_q_lvls = dtx_pd_real_q_levels[ndm - 1][pd_idx_2 - 1]; /*Q0*/ move16(); } - pr_pd_bits = ivas_get_bits_to_encode( L_mult0( pd_q_lvls, pr_q_lvls ) ); + pr_pd_bits = ivas_get_bits_to_encode( L_mult0( pd_q_lvls, pr_q_lvls ) ); /*Q0*/ - value = get_next_indice_fx( st0, pr_pd_bits ); + value = get_next_indice_fx( st0, pr_pd_bits ); /*Q0*/ IF( value != 0 ) { - pr = idiv1616( value, pd_q_lvls ); + pr = idiv1616( value, pd_q_lvls ); /*Q0*/ } ELSE { @@ -4459,23 +4459,23 @@ static void ivas_parse_parameter_bitstream_dtx( move16(); } pd = extract_l( L_sub( value, i_mult( pr, pd_q_lvls ) ) ); - val_fx = dtx_pd_real_min_max_fx[0]; + val_fx = dtx_pd_real_min_max_fx[0]; /*Q0*/ move32(); ivas_quantise_real_values_fx( &val_fx, pd_q_lvls, dtx_pd_real_min_max_fx[0], dtx_pd_real_min_max_fx[1], &idx, &val_fx, 1 ); pd = add( pd, idx ); - val_fx = pr_min_max_fx[0]; + val_fx = pr_min_max_fx[0]; /*Q28*/ move32(); ivas_quantise_real_values_fx( &val_fx, pr_q_lvls, pr_min_max_fx[0], pr_min_max_fx[1], &idx, &val_fx, 1 ); pr = add( pr, idx ); if ( LE_16( add( j, 1 ), ndec ) ) { - pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1] = pd; + pSpar_md->band_coeffs_idx[i].decd_index_re[pd_idx_2 - 1] = pd; /*Q0*/ move16(); } - pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1] = pr; + pSpar_md->band_coeffs_idx[i].pred_index_re[pd_idx_1 - 1] = pr; /*Q0*/ move16(); } } @@ -4633,12 +4633,12 @@ static ivas_error ivas_deindex_real_index( #else static ivas_error ivas_deindex_real_index_fx( - const Word16 *index, - const Word16 q_levels, - const Word32 min_value, - const Word32 max_value, - Word32 *quant, - const Word16 dim ) + const Word16 *index, /*Q0*/ + const Word16 q_levels, /*Q0*/ + const Word32 min_value, /*Q28*/ + const Word32 max_value, /*Q28*/ + Word32 *quant, /*Q22*/ + const Word16 dim /*Q0*/ ) { Word16 i; Word32 q_step_fx; @@ -4658,7 +4658,7 @@ static ivas_error ivas_deindex_real_index_fx( ELSE { q_step_fx = L_sub( max_value, min_value ); - q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[q_levels - 1] ); + q_step_fx = Mpy_32_32( q_step_fx, one_by_q_level[q_levels - 1] /*Q31*/ ); /*Q28*/ FOR( i = 0; i < dim; i++ ) { quant[i] = Mpy_32_32( L_shl( index[i], 31 - 6 ), q_step_fx ); //(25+28)-31 = 22 @@ -4949,10 +4949,10 @@ void ivas_spar_to_dirac( #else void ivas_spar_to_dirac_fx( Decoder_Struct *st_ivas, - ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ - const Word16 dtx_vad, /* i : DTX frame flag */ - const Word16 num_bands_out, /* i : number of output bands */ - const Word16 bw, /* i : band joining factor */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle Q0*/ + const Word16 dtx_vad, /* i : DTX frame flag Q0*/ + const Word16 num_bands_out, /* i : number of output bands Q0*/ + const Word16 bw, /* i : band joining factor Q0*/ const Word16 dyn_active_w_flag ) { DIRAC_DEC_HANDLE hDirAC; @@ -4994,17 +4994,17 @@ void ivas_spar_to_dirac_fx( move16(); start_band = 0; move16(); - end_band = idiv1616( s_min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ), bw ); + end_band = idiv1616( s_min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ), bw ); /*Q0*/ hDirAC = st_ivas->hDirAC; hSpatParamRendCom = st_ivas->hSpatParamRendCom; - dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; /*Q0*/ move16(); IF( st_ivas->hSpar->enc_param_start_band > 0 ) { - enc_param_start_band = idiv1616( st_ivas->hSpar->enc_param_start_band, bw ); + enc_param_start_band = idiv1616( st_ivas->hSpar->enc_param_start_band, bw ); /*Q0*/ } ELSE { @@ -5044,13 +5044,13 @@ void ivas_spar_to_dirac_fx( Word32 PR_fx[3], Pd_fx[3], dvnorm_fx, g_pred_fx; Word16 q_g_pred; Word16 q_dvnorm; - PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; + PR_fx[0] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[2]; /*Q22*/ move32(); - PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; + PR_fx[1] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[0]; /*Q22*/ move32(); - PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; + PR_fx[2] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[1]; /*Q22*/ move32(); - g_pred_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); + g_pred_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); /*q_g_pred*/ q_g_pred = Q22 + Q22 - Q31; move16(); q_dvnorm = sub( Q31, q_g_pred ); @@ -5058,7 +5058,7 @@ void ivas_spar_to_dirac_fx( move16(); IF( LE_32( g_pred_fx, EPSILON_FIX ) ) { - dvx_fx[band] = ONE_IN_Q22; + dvx_fx[band] = ONE_IN_Q22; /*Q22*/ move32(); dvy_fx[band] = 0; move32(); @@ -5076,8 +5076,8 @@ void ivas_spar_to_dirac_fx( } ELSE { - dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); - g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); + dvnorm_fx = ISqrt32( g_pred_fx, &q_dvnorm ); /*Q31 - q_dvnorm*/ + g_pred_fx = Sqrt32( g_pred_fx, &q_g_pred ); /*Q31 - q_g_pred*/ IF( q_g_pred < 0 ) { g_pred_fx = L_shr( g_pred_fx, negate( q_g_pred ) ); @@ -5085,70 +5085,70 @@ void ivas_spar_to_dirac_fx( move16(); } - dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); + dvx_fx[band] = Mpy_32_32( PR_fx[0], dvnorm_fx ); /*q_1*/ move32(); - dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); + dvy_fx[band] = Mpy_32_32( PR_fx[1], dvnorm_fx ); /*q_1*/ move32(); - dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); + dvz_fx[band] = Mpy_32_32( PR_fx[2], dvnorm_fx ); /*q_1*/ move32(); Word16 q_1 = sub( add( 22, sub( 31, q_dvnorm ) ), 31 ); - Word32 temp = L_add( Mpy_32_32( dvx_fx[band], dvx_fx[band] ), Mpy_32_32( dvy_fx[band], dvy_fx[band] ) ); + Word32 temp = L_add( Mpy_32_32( dvx_fx[band], dvx_fx[band] ), Mpy_32_32( dvy_fx[band], dvy_fx[band] ) ); /*q2*/ Word16 q2 = sub( add( q_1, q_1 ), 31 ); Word16 q_temp = sub( 31, q2 ); radius_fx = Sqrt32( temp, &q_temp ); - Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); - Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); + Word16 check_azi_fx = BASOP_util_atan2( dvy_fx[band], dvx_fx[band], 0 ); /*Q13*/ + Word32 check_azi_fx_32 = L_shl( check_azi_fx, 16 ); /*Q29*/ Word16 check_azi_fx_res; IF( check_azi_fx_32 < 0 ) { - check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 ) ); + check_azi_fx_res = negate( divide3232( L_negate( check_azi_fx_32 ), 1686629760 /*3.145f in Q29*/ ) ); /*Q15*/ } ELSE { - check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 ); + check_azi_fx_res = divide3232( check_azi_fx_32, 1686629760 /*3.145f in Q29*/ ); /*Q15*/ } - Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); - azi_intermediate = L_add( azi_intermediate, ONE_IN_Q21 ); + Word32 azi_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_azi_fx_res ); /*Q22*/ + azi_intermediate = L_add( azi_intermediate, ONE_IN_Q21 ); /*Q22*/ Word16 azi_res; IF( azi_intermediate < 0 ) { - azi_res = negate( extract_l( L_shr( L_negate( azi_intermediate ), 22 ) ) ); + azi_res = negate( extract_l( L_shr( L_negate( azi_intermediate ), 22 ) ) ); /*Q0*/ } ELSE { - azi_res = extract_l( L_shr( azi_intermediate, 22 ) ); + azi_res = extract_l( L_shr( azi_intermediate, 22 ) ); /*Q0*/ } - Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, sub( add( 9, q_dvnorm ), q_temp ) ); - Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); + Word16 check_ele_fx = BASOP_util_atan2( dvz_fx[band], radius_fx, sub( add( 9, q_dvnorm ), q_temp ) ); /*Q13*/ + Word32 check_ele_fx_32 = L_shl( check_ele_fx, 16 ); /*Q29*/ Word16 check_ele_fx_res; IF( check_azi_fx_32 < 0 ) { - check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 ) ); + check_ele_fx_res = negate( divide3232( L_negate( check_ele_fx_32 ), 1686629760 /*3.145f in Q29*/ ) ); /*Q15*/ } ELSE { - check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 ); + check_ele_fx_res = divide3232( check_ele_fx_32, 1686629760 /*3.145f in Q29*/ ); /*Q15*/ } - Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); - ele_intermediate = L_add( ele_intermediate, ONE_IN_Q21 ); + Word32 ele_intermediate = Mpy_32_16_1( DEGREE_180_Q_22, check_ele_fx_res ); /*Q22*/ + ele_intermediate = L_add( ele_intermediate, ONE_IN_Q21 ); /*Q22*/ Word16 ele_res; IF( ele_intermediate < 0 ) { - ele_res = negate( extract_l( L_shr( L_negate( ele_intermediate ), 22 ) ) ); + ele_res = negate( extract_l( L_shr( L_negate( ele_intermediate ), 22 ) ) ); /*Q0*/ } ELSE { - ele_res = extract_l( L_shr( ele_intermediate, 22 ) ); + ele_res = extract_l( L_shr( ele_intermediate, 22 ) ); /*Q0*/ } - azi[band] = s_max( -180, s_min( 180, azi_res ) ); + azi[band] = s_max( -180, s_min( 180, azi_res ) ); /*Q0*/ move16(); - ele[band] = s_max( -90, s_min( 180, ele_res ) ); + ele[band] = s_max( -90, s_min( 180, ele_res ) ); /*Q0*/ move16(); } @@ -5160,19 +5160,19 @@ void ivas_spar_to_dirac_fx( { IF( dtx_vad == 0 ) { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_DTX_FX; /*Q31*/ move32(); } ELSE { IF( active_w_vlbr ) { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_VLBR_FX; /*Q31*/ move32(); } ELSE { - f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; + f_scale_fx = IVAS_ACTIVEW_DM_F_SCALE_FX; /*Q31*/ move32(); } } @@ -5183,42 +5183,42 @@ void ivas_spar_to_dirac_fx( move32(); } - Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); + Word32 temp_result = Mpy_32_32( Mpy_32_32( f_scale_fx, g_pred_fx ), g_pred_fx ); /*Q31 - q_g_pred*/ temp_result = L_sub( L_shr( ONE_IN_Q31, q_g_pred ), temp_result ); - w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); + w_en_norm_fx = Mpy_32_32( temp_result, temp_result ); /*q_w_en_norm_fx*/ q_w_en_norm_fx = add( q_g_pred, q_g_pred ); - Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; + Pd_fx[0] = hMdDec->spar_md.band_coeffs[band].P_re_fx[1]; /*Q22*/ move32(); - Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; + Pd_fx[1] = hMdDec->spar_md.band_coeffs[band].P_re_fx[0]; /*Q22*/ move32(); - Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; + Pd_fx[2] = hMdDec->spar_md.band_coeffs[band].P_re_fx[2]; /*Q22*/ move32(); en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); // 22+22-31 = 13 Word32 Pd_temp_res = L_add( L_add( Mpy_32_32( Pd_fx[0], Pd_fx[0] ), Mpy_32_32( Pd_fx[1], Pd_fx[1] ) ), Mpy_32_32( Pd_fx[2], Pd_fx[2] ) ); // q = 22+22-31 = 13 - res_pow_fx = L_add( L_shr( w_en_norm_fx, sub( sub( 31, q_w_en_norm_fx ), 13 ) ), L_add( en_ratio_fx, Pd_temp_res ) ); + res_pow_fx = L_add( L_shr( w_en_norm_fx, sub( sub( 31, q_w_en_norm_fx ), 13 ) ), L_add( en_ratio_fx, Pd_temp_res ) ); /*Q13*/ - res_pow_fx = L_shr( res_pow_fx, 1 ); + res_pow_fx = L_shr( res_pow_fx, 1 ); /*Q13*/ - hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, en_ratio_fx ) ); /*Q13*/ move32(); - hMdDec->spar_md.ref_pow_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.ref_pow_slow_fx[band] ), Mpy_32_32( 536870912, res_pow_fx ) ); + hMdDec->spar_md.ref_pow_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.ref_pow_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, res_pow_fx ) ); /*Q13*/ move32(); en_ratio_q = 31 - 13; move16(); - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); /*Q31 - en_ratio_q*/ IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, negate( en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, negate( en_ratio_q ) ); /*Q31*/ en_ratio_q = 0; move16(); } - Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( sub( sub( 31, en_ratio_q ), 13 ) ) ); + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, ( sub( sub( 31, en_ratio_q ), 13 ) ) ); /*Q13*/ IF( GT_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { diffuseness_fx[band] = 0; @@ -5226,39 +5226,39 @@ void ivas_spar_to_dirac_fx( } ELSE IF( en_ratio_fx_scaled == 0 ) { - diffuseness_fx[band] = ONE_IN_Q30; + diffuseness_fx[band] = ONE_IN_Q30; /*1.0f in Q30*/ move32(); } ELSE IF( EQ_32( en_ratio_fx_scaled, hMdDec->spar_md.ref_pow_slow_fx[band] ) ) { - diffuseness_fx[band] = ONE_IN_Q30; + diffuseness_fx[band] = ONE_IN_Q30; /*1.0f in Q30*/ move32(); } ELSE { - en_ratio_fx = divide3232( en_ratio_fx_scaled, L_add( hMdDec->spar_md.ref_pow_slow_fx[band], EPSILON_FX ) ); - en_ratio_fx = L_shl( en_ratio_fx, 15 ); + en_ratio_fx = divide3232( en_ratio_fx_scaled, L_add( hMdDec->spar_md.ref_pow_slow_fx[band], EPSILON_FX ) ); /*Q15*/ + en_ratio_fx = L_shl( en_ratio_fx, 15 ); /*Q30*/ diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx ); move32(); } } ELSE { - en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); + en_ratio_fx = L_add( L_add( Mpy_32_32( PR_fx[0], PR_fx[0] ), Mpy_32_32( PR_fx[1], PR_fx[1] ) ), Mpy_32_32( PR_fx[2], PR_fx[2] ) ); /*Q13*/ - hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912, en_ratio_fx ) ); + hMdDec->spar_md.en_ratio_slow_fx[band] = L_add( Mpy_32_32( 1610612736 /*0.75f in Q31*/, hMdDec->spar_md.en_ratio_slow_fx[band] ), Mpy_32_32( 536870912 /*0.25f in Q31*/, en_ratio_fx ) ); move32(); en_ratio_q = 31 - 13; move16(); - en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); + en_ratio_fx = Sqrt32( hMdDec->spar_md.en_ratio_slow_fx[band], &en_ratio_q ); /*Q31 - en_ratio_q*/ IF( en_ratio_q < 0 ) { - en_ratio_fx = L_shr( en_ratio_fx, ( -en_ratio_q ) ); + en_ratio_fx = L_shr( en_ratio_fx, ( -en_ratio_q ) ); /*Q31*/ en_ratio_q = 0; move16(); } - Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); + Word32 en_ratio_fx_scaled = L_shr( en_ratio_fx, 1 ); /*Q30*/ IF( GT_32( en_ratio_fx_scaled, ONE_IN_Q30 ) ) { diffuseness_fx[band] = 0; @@ -5266,7 +5266,7 @@ void ivas_spar_to_dirac_fx( } ELSE { - diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx_scaled ); + diffuseness_fx[band] = L_sub( ONE_IN_Q30, en_ratio_fx_scaled ); /*Q30*/ move32(); } } @@ -5278,60 +5278,60 @@ void ivas_spar_to_dirac_fx( tmp_write_idx_param_band = hDirAC->spar_to_dirac_write_idx; move16(); - en_ratio_fx = L_sub( ONE_IN_Q30, diffuseness_fx[band] ); + en_ratio_fx = L_sub( ONE_IN_Q30, diffuseness_fx[band] ); /*Q30*/ masa_sq_fx( L_sub( ONE_IN_Q30, en_ratio_fx ), diffuseness_thresholds_fx, DIRAC_DIFFUSE_LEVELS ); - qmf_band_start = band_grouping[band]; + qmf_band_start = band_grouping[band]; /*Q0*/ move16(); - qmf_band_end = band_grouping[band + 1]; + qmf_band_end = band_grouping[band + 1]; /*Q0*/ move16(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { Word16 ts_start, ts_end, ts; - ts_start = DirAC_block_grouping[block]; + ts_start = DirAC_block_grouping[block]; /*Q0*/ move16(); ts_end = DirAC_block_grouping[block + 1]; move16(); - FOR( b = qmf_band_start; b < qmf_band_end; b++ ) + FOR( b = qmf_band_start; b < qmf_band_end; b++ ) /*Q0*/ { - azi_dith = azi[band]; + azi_dith = azi[band]; /*Q0*/ move16(); - ele_dith = ele[band]; + ele_dith = ele[band]; /*Q0*/ move16(); - hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; + hSpatParamRendCom->energy_ratio1_fx[block][b] = en_ratio_fx; /*Q30*/ move32(); - tmp_write_idx_band = tmp_write_idx_param_band; + tmp_write_idx_band = tmp_write_idx_param_band; /*Q0*/ move16(); IF( hDirAC->hConfig->dec_param_estim == FALSE ) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; /*Q0*/ move16(); - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; /*Q0*/ move16(); - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; /*Q30*/ move32(); } ELSE { FOR( ts = ts_start; ts < ts_end; ts++ ) { - hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; + hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele_dith; /*Q0*/ move16(); - hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; + hSpatParamRendCom->azimuth[tmp_write_idx_band][b] = azi_dith; /*Q0*/ move16(); - hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; + hSpatParamRendCom->diffuseness_vector_fx[tmp_write_idx_band][b] = diffuseness_fx[band]; /*Q30*/ move32(); - tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; + tmp_write_idx_band = add( tmp_write_idx_band, 1 ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } } @@ -5344,12 +5344,12 @@ void ivas_spar_to_dirac_fx( /* update buffer write index */ IF( hDirAC->hConfig->dec_param_estim == FALSE ) { - hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } ELSE { - hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; + hDirAC->spar_to_dirac_write_idx = add( hDirAC->spar_to_dirac_write_idx, CLDFB_NO_COL_MAX ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/ move16(); } } @@ -5364,7 +5364,7 @@ void ivas_spar_to_dirac_fx( { Word16 dirac_band_idx; - dirac_band_idx = sub( dirac_to_spar_md_bands[band], enc_param_start_band ); + dirac_band_idx = sub( dirac_to_spar_md_bands[band], enc_param_start_band ); /*Q0*/ num_subframes = MAX_PARAM_SPATIAL_SUBFRAMES; move16(); @@ -5380,17 +5380,17 @@ void ivas_spar_to_dirac_fx( IF( st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] < 0 ) { st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] = - L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); + L_add( L_shl( 360, 22 ), st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block] ); /*Q22*/ move32(); } - azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; + azi_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].azimuth_fx[block]; /*Q22*/ move32(); - ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; + ele_dirac_fx[band][block] = st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].elevation_fx[block]; /*Q22*/ move32(); } - diffuseness_fx[band] = L_sub( ONE_IN_Q30, st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); + diffuseness_fx[band] = L_sub( ONE_IN_Q30, st_ivas->hQMetaData->q_direction->band_data[dirac_band_idx].energy_ratio_fx[0] ); /*Q30*/ move32(); } @@ -5415,7 +5415,7 @@ void ivas_spar_to_dirac_fx( { FOR( band = SPAR_DIRAC_SPLIT_START_BAND; band < IVAS_MAX_NUM_BANDS; band++ ) { - pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; + pred_re_20ms_fx[band][pred_idx] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[pred_idx]; /*Q22*/ move32(); } } @@ -5446,12 +5446,12 @@ void ivas_spar_to_dirac_fx( { FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[i] = hMdDec->spar_md.band_coeffs[band].pred_re_fx[i]; /*Q22*/ move32(); } FOR( i = 0; i < FOA_CHANNELS - 1; i++ ) /* pred coefficient index (index 0, 1, 2 predicts Y, Z, X respectively) */ { - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].P_re_fx[i] = hMdDec->spar_md.band_coeffs[band].P_re_fx[i]; /*Q22*/ move32(); } } @@ -5468,7 +5468,7 @@ void ivas_spar_to_dirac_fx( IF( ivas_is_res_channel( add( pred_idx, 1 ), hMdDec->spar_md_cfg.nchan_transport ) ) { /* use 20ms coefficients only for residual channels */ - hMdDec->spar_md.band_coeffs[add( band, i_mult( block, IVAS_MAX_NUM_BANDS ) )].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; + hMdDec->spar_md.band_coeffs[( band + ( block * IVAS_MAX_NUM_BANDS ) )].pred_re_fx[pred_idx] = pred_re_20ms_fx[band][pred_idx]; /*Q22*/ move32(); } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 4575cf543..07d7fd3c5 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -312,13 +312,13 @@ typedef struct stereo_dft_dec_data_struct #ifdef IVAS_FLOAT_FIXED Word32 smooth_dmx_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ Word32 smooth_res_nrg_fx[STEREO_DFT_BAND_MAX]; /* Q(q_smoothed_nrg) */ - Word32 td_gain_fx[STEREO_DFT_CORE_HIST_MAX]; + Word32 td_gain_fx[STEREO_DFT_CORE_HIST_MAX]; /* Q(q_td_gain) */ #endif #ifdef IVAS_FLOAT_FIXED - Word32 hb_stefi_sig_fx[L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS )]; - Word32 hb_nrg_fx[STEREO_DFT_CORE_HIST_MAX]; - Word32 hb_nrg_subr_fx[STEREO_DFT_NBDIV]; + Word32 hb_stefi_sig_fx[L_FRAME48k + NS2SA( 48000, STEREO_DFT_TD_STEFI_DELAY_NS )]; /* Q(q_hb_stefi_sig_fx) */ + Word32 hb_nrg_fx[STEREO_DFT_CORE_HIST_MAX]; /* Q(q_hb_nrg) */ + Word32 hb_nrg_subr_fx[STEREO_DFT_NBDIV]; /* Q(q_hb_nrg_subr) */ Word16 Q_nrg_subr; Word16 prev_Q_stefi_sig; @@ -700,10 +700,10 @@ typedef struct param_ism_rendering { #ifdef IVAS_FLOAT_FIXED Word16 *proto_matrix_fx; - Word16 *interpolator_fx; /* Q15 */ - Word32 *Cldfb_RealBuffer_tc_fx; + Word16 *interpolator_fx; /* Q15 */ + Word32 *Cldfb_RealBuffer_tc_fx; /* Q31 - Cldfb_RealBuffer_tc_exp */ Word16 Cldfb_RealBuffer_tc_exp; - Word32 *Cldfb_ImagBuffer_tc_fx; + Word32 *Cldfb_ImagBuffer_tc_fx; /* Q31 - Cldfb_ImagBuffer_tc_exp */ Word16 Cldfb_ImagBuffer_tc_exp; Word32 mixing_matrix_lin_fx[CLDFB_NO_CHANNELS_MAX][PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX]; Word16 exp_mixing_matrix_lin_fx[CLDFB_NO_CHANNELS_MAX]; @@ -1263,10 +1263,10 @@ typedef struct ivas_lfe_dec_data_structure typedef struct renderer_struct { #ifdef IVAS_FLOAT_FIXED - Word32 prev_gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; - Word16 *interpolator_fx; + Word32 prev_gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; /*Q30*/ + Word16 *interpolator_fx; /*Q15*/ Word16 interpolator_len; - Word32 gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; + Word32 gains_fx[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; /*Q30*/ #else float prev_gains[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; float *interpolator; @@ -1285,7 +1285,7 @@ typedef struct ivas_binaural_rendering_struct #ifndef IVAS_FLOAT_FIXED float *hoa_dec_mtx; /* pointer to HOA decoder mtx */ #else - Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ + Word32 *hoa_dec_mtx; /* pointer to HOA decoder mtx */ /*Q29*/ #endif int8_t rotInCldfb; /* Flag to enable rotation within bin Renderer in CLDFB*/ int16_t max_band; /* band upto which rendering is performed */ diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index d3fa428b2..9a3251836 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -28,7 +28,7 @@ void hvq_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ const Word16 num_bits, /* i : Number of available bits */ const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *noise_level, /* o : Noise level in Q15 */ Word16 *peak_idx, /* o : Peak position vector */ @@ -68,7 +68,7 @@ static void peak_vq_dec_fx( Word32 *coefs_out, /* o : Output coefficient vector Q12 */ const Word32 core_brate, /* i : Core bitrate */ const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 *ynrm, /* i : Envelope coefficients */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ Word16 *R, /* i/o: Bit allocation/updated bit allocation */ Word16 *vq_peak_idx, /* o : Peak position vector */ Word16 *Npeaks, /* o : Number of peaks */ @@ -241,8 +241,8 @@ static void peak_vq_dec_fx( move16(); } - peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; - move32(); /* Q12 move16(); */ + peak_gains_fx[i] = dicn_pg_fx[pgain_difidx[i]]; // Q12 + move32(); if ( res_vec[vq_peak_idx[i]] < 0 ) { peak_gains_fx[i] = L_negate( peak_gains_fx[i] ); @@ -256,12 +256,12 @@ static void peak_vq_dec_fx( move16(); FOR( i = 0; i < vq_peaks; i++ ) { - peak_gains_fx[i] = L_shl( peak_gains_fx[i], 2 ); - move32(); /* Q12 */ + peak_gains_fx[i] = L_shl( peak_gains_fx[i], 2 ); // Q12 -> Q14 + move32(); /* Use floating point operation to deal with wide dynamic range. * 32-bit mantissa is used here. It should be even more accurate than * the floating-point reference code with 24-bit mantissa! */ - tmp = L_shl( dicn_pg_fx[pgain_difidx[i]], 2 ); + tmp = L_shl( dicn_pg_fx[pgain_difidx[i]], 2 ); // Q14 expPeakGains = norm_l( tmp ); manPeakGains = L_shl( tmp, expPeakGains ); Mpy_32_32_ss( manPeakGains, manPeakGains, &manPkEnrg, &lsb ); /* peak_gains square */ @@ -478,7 +478,7 @@ static Word16 hvq_dec_pos_fx( mode = get_next_indice_fx( st_fx, 1 ); num_bits = add( num_bits, 1 ); - IF( EQ_16( mode, HVQ_CP_DELTA ) ) + IF( ( mode == HVQ_CP_DELTA ) ) { huff_dec_fx( st_fx, num_peaks, HVQ_CP_HUFF_MAX_CODE, HVQ_CP_HUFF_NUM_LEN, hvq_cp_huff_thres, hvq_cp_huff_offset, hvq_cp_huff_tab, delta ); @@ -490,7 +490,7 @@ static Word16 hvq_dec_pos_fx( peak_idx[0] = sub( delta[0], HVQ_CP_HUFF_OFFSET ); move16(); /* safety check in case of bit errors */ - IF( peak_idx[0] < 2 ) + IF( LT_16( peak_idx[0], 2 ) ) { peak_idx[0] = 2; move16(); @@ -541,10 +541,10 @@ static Word16 hvq_dec_pos_fx( j = 0; move16(); /* safety check in case of bit errors */ - test(); FOR( i = 0; i < length && j < num_peaks; i++ ) { - if ( EQ_16( pos_vec[i], 1 ) ) + test(); + IF( EQ_16( pos_vec[i], 1 ) ) { pos_vec[i] = i_mult2( pos_vec[i], sign_vec[j++] ); move16(); @@ -605,7 +605,8 @@ static Word16 sparse_dec_pos_fx( move16(); } tmp = i_mult2( j, HVQ_CP_L1_LEN ); - FOR( i = sub( s_min( i_mult2( add( j, 1 ), HVQ_CP_L1_LEN ), length ), 1 ); i >= tmp; i-- ) + FOR( i = ( s_min( ( j + 1 ) * HVQ_CP_L1_LEN, length ) - 1 ); + i >= tmp; i-- ) { out[i] = s_and( val, 1 ); move16(); diff --git a/lib_dec/pit_dec_fx.c b/lib_dec/pit_dec_fx.c index a68cba5a8..a2b5a7618 100644 --- a/lib_dec/pit_dec_fx.c +++ b/lib_dec/pit_dec_fx.c @@ -17,18 +17,18 @@ * Decode pitch lag *----------------------------------------------------------*/ -Word32 Mode2_pit_decode( /* o: floating pitch value */ +Word32 Mode2_pit_decode( /* o: pitch value Q16 */ const Word16 coder_type, /* i: coding model */ Word16 i_subfr, /* i: subframe index */ Word16 L_subfr, - Word16 **pt_indice, /* i/o: quantization indices pointer */ - Word16 *T0, /* i/o: close loop integer pitch */ - Word16 *T0_frac, /* o: close loop fractional part of the pitch */ - Word16 *T0_res, /* i/o: pitch resolution */ - Word16 *T0_min, /* i/o: lower limit for close-loop search */ - Word16 *T0_min_frac, /* i/o: lower limit for close-loop search */ - Word16 *T0_max, /* i/o: higher limit for close-loop search */ - Word16 *T0_max_frac, /* i/o: higher limit for close-loop search */ + Word16 **pt_indice, /* i/o: quantization indices pointer */ + Word16 *T0, /* i/o: close loop integer pitch Q0 */ + Word16 *T0_frac, /* o: close loop fractional part of the pitch Q0 */ + Word16 *T0_res, /* i/o: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_min_frac, /* i/o: lower limit for close-loop search Q0 */ + Word16 *T0_max, /* i/o: higher limit for close-loop search Q0 */ + Word16 *T0_max_frac, /* i/o: higher limit for close-loop search Q0 */ Word16 pit_min, Word16 pit_fr1, Word16 pit_fr1b, @@ -156,8 +156,8 @@ Word32 Mode2_pit_decode( /* o: floating pitch value *-------------------------------------------------------*/ assert( *T0_res > 0 || *T0_res <= 6 ); - /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ - pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); + /*pitch = (float)(*T0) + (float)(*T0_frac)/(float)(*T0_res);*/ /* save subframe pitch values */ + pitch = L_mac( L_deposit_h( *T0 ), *T0_frac, inv_T0_res[*T0_res] ); // Q16 return pitch; @@ -171,9 +171,9 @@ Word32 Mode2_pit_decode( /* o: floating pitch value *---------------------------------------------------------------------*/ void Mode2_abs_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 *T0_res, /* o: pitch resolution */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 *T0_res, /* o: pitch resolution Q0 */ Word16 **pt_indice, /* i/o: pointer to Vector of Q indexes */ Word16 pit_min, Word16 pit_fr1, @@ -197,14 +197,14 @@ void Mode2_abs_pit_dec( res = pit_res_max; move16(); - if ( EQ_16( pit_res_max, 6 ) ) + IF( EQ_16( pit_res_max, 6 ) ) { res = shr( res, 1 ); } *T0 = mult( index, inv_T0_res[res] ); move16(); - if ( EQ_16( pit_res_max, 6 ) ) + IF( EQ_16( pit_res_max, 6 ) ) { *T0 = shr( *T0, 1 ); move16(); @@ -250,11 +250,11 @@ void Mode2_abs_pit_dec( * Decode delta pitch *---------------------------------------------------------------------*/ void Mode2_delta_pit_dec( - Word16 *T0, /* o: integer pitch lag */ - Word16 *T0_frac, /* o: pitch fraction */ - Word16 T0_res, /* i: pitch resolution */ - Word16 *T0_min, /* i/o: delta search min */ - Word16 *T0_min_frac, /* i: delta search min */ + Word16 *T0, /* o: integer pitch lag Q0 */ + Word16 *T0_frac, /* o: pitch fraction Q0 */ + Word16 T0_res, /* i: pitch resolution Q0 */ + Word16 *T0_min, /* i/o: delta search min Q0 */ + Word16 *T0_min_frac, /* i: delta search min Q0 */ Word16 **pt_indice /* i/o: pointer to Vector of Q indexes */ ) { @@ -277,7 +277,7 @@ void Mode2_delta_pit_dec( *T0 = mult( add( index, *T0_min_frac ), inv_T0_res[res] ); move16(); - if ( EQ_16( T0_res, 6 ) ) + IF( EQ_16( T0_res, 6 ) ) { *T0 = shr( *T0, 1 ); move16(); @@ -614,12 +614,12 @@ Word16 pit_decode_ivas_fx( /* o : floating p Word16 *T0_min, /* i/o: delta search min for sf 2 & 4 */ Word16 *T0_max, /* i/o: delta search max for sf 2 & 4 */ const Word16 L_subfr, /* i : subframe length */ - const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ - const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer */ + const Word16 tdm_Pitch_reuse_flag, /* i : primary channel pitch reuse flag */ + const Word16 tdm_Pri_pitch_buf[] /* i : primary channel pitch buffer Q6 */ ) { Word16 pitch; /*Q2*/ - Word16 pitch_index, nBits, pit_flag; + Word16 pitch_index, nBits, pit_flag, tmp; pitch_index = 0; move16(); @@ -683,7 +683,8 @@ Word16 pit_decode_ivas_fx( /* o : floating p /* find the number of bits */ IF( i_subfr ) { - nBits = st_fx->acelp_cfg.pitch_bits[idiv1616( i_subfr, L_subfr )]; + tmp = idiv1616( i_subfr, L_subfr ); + nBits = st_fx->acelp_cfg.pitch_bits[tmp]; } ELSE { @@ -762,7 +763,7 @@ Word16 pit_decode_ivas_fx( /* o : floating p move16(); move16(); pit_tmp1 = tdm_Pri_pitch_buf[isubfridx]; /*tdm_Pri_pitch_buf in Q6 ->pit_tmp1 and 2 in Q6 too */ - pit_tmp2 = tdm_Pri_pitch_buf[shr( add( i_subfr, 1 ), 6 )]; + pit_tmp2 = tdm_Pri_pitch_buf[( i_subfr + 1 ) / L_SUBFR]; /*loc_T0 = (int16_t)(0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]);*/ loc_T0 = mac_r( L_mult( 16384, pit_tmp1 ), 16384, pit_tmp2 ); /*loc_frac = (int16_t)(((0.5f * tdm_Pri_pitch_buf[i_subfr / L_SUBFR] + 0.5f * tdm_Pri_pitch_buf[(i_subfr + L_SUBFR) / L_SUBFR]) - loc_T0) * 4.0f);*/ @@ -771,6 +772,7 @@ Word16 pit_decode_ivas_fx( /* o : floating p { /*loc_T0 = (int16_t)tdm_Pri_pitch_buf[i_subfr / L_SUBFR];*/ loc_T0 = tdm_Pri_pitch_buf[isubfridx]; /*Q6*/ + move16(); /*loc_frac = (int16_t)((tdm_Pri_pitch_buf[i_subfr / L_SUBFR] - loc_T0) * 4.0f);*/ } loc_frac = shr( sub( loc_T0, shl( shr( loc_T0, 6 ), 6 ) ), 4 ); /* Final result in Q 2*/ @@ -1004,7 +1006,7 @@ void pit16k_Q_dec_fx( *T0 = add( PIT16k_FR2_EXTEND_10b, shr( index, 1 ) ); move16(); *T0_frac = sub( index, shl( sub( *T0, PIT16k_FR2_EXTEND_10b ), 1 ) ); - ( *T0_frac ) = shl( *T0_frac, 1 ); + ( *T0_frac ) = shl( *T0_frac, 1 ); //( *T0_frac ) *= 2; move16(); } } diff --git a/lib_dec/pitch_extr_fx.c b/lib_dec/pitch_extr_fx.c index 4831d087c..f1e69ae68 100644 --- a/lib_dec/pitch_extr_fx.c +++ b/lib_dec/pitch_extr_fx.c @@ -16,11 +16,11 @@ * ------------------- Q15 * PIT_MAX x Fact *-------------------------------------------------------------------*/ - +#ifndef IVAS_FLOAT_FIXED #define PIT_MAX_DIV_8k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) #define PIT_MAX_DIV_12k8( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_12k8 * fact ) ) #define PIT_MAX_DIV_16k( num, fact ) ( -( num * 32768 ) / ( PIT_MAX_16k * fact ) ) - +#endif /*-----------------------------------------------------------------* * Pitch prediction for frame erasure using linear fitting * @@ -76,7 +76,7 @@ void pitch_pred_linear_fit( { FOR( i = 0; i < 2 * NB_SUBFR + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2 * NB_SUBFR + 1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR + 1 - i]; // Q16 move32(); } } @@ -84,7 +84,7 @@ void pitch_pred_linear_fit( { FOR( i = 0; i < 2 * NB_SUBFR16k + 2; i++ ) { - mem_lag[i] = old_pitch_buf[2 * NB_SUBFR16k + 1 - i]; + mem_lag[i] = old_pitch_buf[2 * NB_SUBFR16k + 1 - i]; // Q16 move32(); } } diff --git a/lib_dec/post_dec_fx.c b/lib_dec/post_dec_fx.c index bf9e51a87..f37a86ea1 100644 --- a/lib_dec/post_dec_fx.c +++ b/lib_dec/post_dec_fx.c @@ -23,11 +23,12 @@ static void bass_pf_1sf_delay( Word16 *syn, Word16 *T_sf, Word16 *gainT_sf, Word void post_decoder( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ) + Word16 synth_buf[], /* Q0 */ + Word16 pit_gain[], /* Q14 */ + Word16 pitch[], /* Q0 */ + Word16 signal_out[], /* Q0 */ + Word16 *bpf_noise_buf /* Q0 */ +) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -81,7 +82,7 @@ void post_decoder( ELSE { /*Formant enhancement*/ - IF( EQ_16( st->last_bwidth, NB ) ) + IF( ( st->last_bwidth == NB ) ) { Copy( synth, synth2_pe, L_frame ); tmp = synth[-1]; @@ -106,7 +107,7 @@ void post_decoder( st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( ( st->bwidth == NB ) ) { st->hPFstat->on = 1; move16(); @@ -174,11 +175,12 @@ void post_decoder( void post_decoder_ivas_fx( Decoder_State *st, - Word16 synth_buf[], - Word16 pit_gain[], - Word16 pitch[], - Word16 signal_out[], - Word16 *bpf_noise_buf ) + Word16 synth_buf[], // Q0 + Word16 pit_gain[], // Q14 + Word16 pitch[], // Q0 + Word16 signal_out[], // Q0 + Word16 *bpf_noise_buf // Q0 +) { Word16 L_frame, nb_subfr; Word16 *synth, *synth2; @@ -268,7 +270,7 @@ void post_decoder_ivas_fx( st->hPFstat->reset = 1; move16(); } - IF( EQ_16( st->bwidth, NB ) ) + IF( ( st->bwidth == NB ) ) { st->hPFstat->on = 1; move16(); @@ -406,12 +408,12 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_mult( syn[sub( add( i, i_subfr ), T )], 0x4000 ); - tmp32 = L_mac( tmp32, syn[add( add( i, i_subfr ), T )], 0x4000 ); + tmp32 = L_mult( syn[( i + i_subfr ) - T], 0x4000 ); + tmp32 = L_mac( tmp32, syn[( i + i_subfr ) + T], 0x4000 ); tmp16 = round_fx( L_shl( tmp32, s1 ) ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -426,9 +428,9 @@ static void bass_pf_1sf_delay( Word64 nrg64 = W_deposit32_l( nrg ); FOR( i = lg; i < l_subfr; i++ ) { - tmp16 = shl( syn[sub( add( i, i_subfr ), T )], s1 ); /* Q0+s1 */ - tmp64 = W_mac0_16_16( tmp64, shl( syn[add( i, i_subfr )], s1 ), tmp16 ); /* Q0+2*s1 */ - nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ + tmp16 = shl( syn[( i + i_subfr ) - T], s1 ); /* Q0+s1 */ + tmp64 = W_mac0_16_16( tmp64, shl( syn[i + i_subfr], s1 ), tmp16 ); /* Q0+2*s1 */ + nrg64 = W_mac0_16_16( nrg64, tmp16, tmp16 ); /* Q0+2*s1 */ } tmp = W_sat_l( tmp64 ); nrg = W_sat_l( nrg64 ); @@ -468,10 +470,10 @@ static void bass_pf_1sf_delay( Word64 ener2_64 = W_deposit32_l( ener2 ); FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, gain, syn[sub( add( i, i_subfr ), T )] ); - tmp32 = L_msu0( tmp32, gain, syn[add( add( i, i_subfr ), T )] ); + tmp32 = L_msu0( 0, gain, syn[( i + i_subfr ) - T] ); + tmp32 = L_msu0( tmp32, gain, syn[( i + i_subfr ) + T] ); #ifdef BASOP_NOGLOB - tmp16 = mac_r_sat( tmp32, gain, syn[add( i, i_subfr )] ); /* Q0 */ + tmp16 = mac_r_sat( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #else tmp16 = mac_r( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ #endif @@ -498,8 +500,8 @@ static void bass_pf_1sf_delay( FOR( i = lg; i < l_subfr; i++ ) { #ifdef BASOP_NOGLOB - tmp32 = L_mult0( gain, syn[add( i, i_subfr )] ); - tmp32 = L_msu0_sat( tmp32, gain, syn[sub( add( i, i_subfr ), T )] ); /* Q0 */ + tmp32 = L_mult0( gain, syn[i + i_subfr] ); + tmp32 = L_msu0_sat( tmp32, gain, syn[( i + i_subfr ) - T] ); /* Q0 */ tmp16 = round_fx_sat( tmp32 ); lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); @@ -582,11 +584,11 @@ static void bass_pf_1sf_delay( { FOR( i = 0; i < lg; i++ ) { - tmp32 = L_msu0( 0, tmp16, syn[sub( add( i, i_subfr ), T )] ); + tmp32 = L_msu0( 0, tmp16, syn[( i + i_subfr ) - T] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[add( add( i, i_subfr ), T )] ); - tmp32 = L_mac_sat( tmp32, tmp16, syn[add( i, i_subfr )] ); - bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[( i + i_subfr ) + T] ); + tmp32 = L_mac_sat( tmp32, tmp16, syn[i + i_subfr] ); + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr + T] ); @@ -600,10 +602,10 @@ static void bass_pf_1sf_delay( { FOR( i = lg; i < l_subfr; i++ ) { - tmp32 = L_mult0( tmp16, syn[add( i, i_subfr )] ); + tmp32 = L_mult0( tmp16, syn[i + i_subfr] ); #ifdef BASOP_NOGLOB - tmp32 = L_msu0_sat( tmp32, tmp16, syn[sub( add( i, i_subfr ), T )] ); - bpf_noise_buf[add( i, i_subfr )] = round_fx_sat( tmp32 ); /* Q0 */ + tmp32 = L_msu0_sat( tmp32, tmp16, syn[i + i_subfr - T] ); + bpf_noise_buf[i + i_subfr] = round_fx_sat( tmp32 ); /* Q0 */ move16(); #else tmp32 = L_msu0( tmp32, tmp16, syn[i + i_subfr - T] ); @@ -686,7 +688,7 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < sub( st->cldfbSyn->no_channels, st->cldfbSyn->bandsToZero ); i++ ) + FOR( i = 0; i < ( st->cldfbSyn->no_channels - st->cldfbSyn->bandsToZero ); i++ ) { nrgQ31 = 0; move32(); @@ -746,7 +748,7 @@ void cldfb_synth_set_bandsToZero( move16(); } - FOR( i = 0; i < sub( WBcnt, 1 ); i++ ) + FOR( i = 0; i < ( WBcnt - 1 ); i++ ) { st->flag_buffer[i] = st->flag_buffer[i + 1]; move16(); @@ -789,7 +791,8 @@ void cldfb_synth_set_bandsToZero( { test(); test(); - IF( ( st->perc_bwddec >= perc_detect || ( st->perc_bwddec >= perc_miss && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ + test(); + IF( ( GE_16( st->perc_bwddec, perc_detect ) || ( GE_16( st->perc_bwddec, perc_miss ) && st->last_flag_filter_NB ) ) && ( sum16_fx( st->flag_buffer, WBcnt ) != 0 ) ) /*decision hysterysis*/ { st->cldfbSyn->bandsToZero = sub( st->cldfbSyn->no_channels, 10 ); move16(); diff --git a/lib_dec/ppp_dec_fx.c b/lib_dec/ppp_dec_fx.c index 88cc99e2c..437927d7c 100644 --- a/lib_dec/ppp_dec_fx.c +++ b/lib_dec/ppp_dec_fx.c @@ -60,12 +60,12 @@ static void DTFS_dequant_cw_fx( IF( EQ_16( num_erb_fx, NUM_ERB_NB ) ) { - PowerCB_fx = PowerCB_NB_fx; + PowerCB_fx = PowerCB_NB_fx; // Q11 move16(); } ELSE IF( EQ_16( num_erb_fx, NUM_ERB_WB ) ) { - PowerCB_fx = PowerCB_WB_fx; + PowerCB_fx = PowerCB_WB_fx; // Q11 move16(); } @@ -75,11 +75,11 @@ static void DTFS_dequant_cw_fx( curr_erb_fx[0] = mult_r( curr_erb_fx[1], 9830 ); /* 0.3 inQ15 leaves curr_erb in Q13 */ move16(); - curr_erb_fx[sub( num_erb_fx, 2 )] = mult_r( curr_erb_fx[sub( num_erb_fx, 3 )], 9830 ); /* Q13 */ + curr_erb_fx[num_erb_fx - 2] = mult_r( curr_erb_fx[num_erb_fx - 3], 9830 ); /* Q13 */ move16(); - curr_erb_fx[sub( num_erb_fx, 1 )] = 0; + curr_erb_fx[num_erb_fx - 1] = 0; move16(); erb_slot_fx( X_fx->lag_fx, slot_fx, mfreq_fx, num_erb_fx ); @@ -101,9 +101,13 @@ static void DTFS_dequant_cw_fx( /* This logic adjusts difference between Q formats of both bands */ IF( n < 0 ) - rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + { + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + } ELSE IF( n > 0 ) + { rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); + } DTFS_to_erb_fx( *X_fx, lasterbD_fx ); @@ -203,9 +207,13 @@ static void DTFS_dequant_cw_fx( IF( n < 0 ) - rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + { + rshiftHarmBand_fx( X_fx, 2828, X_fx->upper_cut_off_freq_fx, n ); + } ELSE IF( n > 0 ) + { rshiftHarmBand_fx( X_fx, 0, 2828, sub( Qh, Ql ) ); + } } /*===================================================================*/ /* FUNCTION : void ppp_quarter_decoder_fx () */ diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 530c2c5b9..121c472fe 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -25,7 +25,7 @@ static void pvq_decode_band_fx( PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 *pulse_vector, /* i/o: decoded integer shape vector */ Word16 *npulses, /* i/o: number of pulses */ - Word16 *coefs_quant, /* i/o: decoded coefficients buffer */ + Word16 *coefs_quant, /* i/o: decoded coefficients buffer Qx */ const Word16 sfmsize, /* i : band length */ const Word16 band_bits, /* i : assigned bit budget */ Word16 *bits_left, /* i/o: number of bits / bits remaining */ @@ -112,14 +112,14 @@ static void pvq_decode_band_fx( void pvq_decode_frame_fx( Decoder_State *st_fx, - Word16 *coefs_quant, /* o : quantized coefficients */ + Word16 *coefs_quant, /* o : quantized coefficients Qx */ Word16 *npulses, /* o : number of pulses per band */ Word16 *pulse_vector, /* o : non-normalized pulse shapes */ const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ const Word16 *sfmsize, /* i : band sizes */ const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band */ + const Word16 *R, /* i : bitallocation per band Q3 */ const Word16 pvq_bits, /* i : number of bits avaiable */ const Word16 core /* i : core */ ) @@ -134,6 +134,7 @@ void pvq_decode_frame_fx( Word16 strict_bits; PVQ_DEC_DATA pvq_dec; PVQ_DEC_HANDLE hPVQ = &pvq_dec; + move16(); rc_dec_init_fx( st_fx, hPVQ, pvq_bits ); @@ -174,8 +175,8 @@ void pvq_decode_frame_fx( move16(); IF( R[is] > 0 ) { - bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, bands_to_code - coded_bands, sfmsize[is], R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool ); /* outputs */ + bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, sub( bands_to_code, coded_bands ), sfmsize[is], R[is], bit_pool, /* inputs */ + &band_bits, &bits_left, &bit_pool ); /* outputs */ pvq_decode_band_fx( st_fx, hPVQ, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, @@ -209,7 +210,7 @@ Word16 ivas_pvq_core_dec_fx( const Word16 *sfm_start, const Word16 *sfm_end, const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ + Word16 coefs_quant[], /* o : output MDCT, Q_coefs */ Word16 *Q_coefs, Word16 bits_tot, Word16 nb_sfm, @@ -227,16 +228,16 @@ Word16 ivas_pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - IF( st_fx->hHQ_core != NULL ) + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->ber_occured_in_pvq = 0; move16(); } - R_upd = shl( bits_tot, 3 ); + R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 ivas_assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr( R_upd, 3 ); + pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); @@ -245,7 +246,7 @@ Word16 ivas_pvq_core_dec_fx( { FOR( i = 0; i < nb_sfm; i++ ) { - IF( LE_16( npulses[i], 0 ) ) + IF( ( npulses[i] <= 0 ) ) { Rs[i] = 0; move16(); /* Update Rs in case no pulses were assigned */ @@ -257,7 +258,7 @@ Word16 ivas_pvq_core_dec_fx( { ord[i] = i; move16(); - IF( LE_16( npulses[i], 0 ) ) + if ( ( npulses[i] <= 0 ) ) { R[i] = 0; move16(); /* Update in case no pulses were assigned */ @@ -272,7 +273,7 @@ Word16 ivas_pvq_core_dec_fx( fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred ); IF( st_fx->hHQ_core != NULL ) { - IF( NE_16( st_fx->hHQ_core->ber_occured_in_pvq, 0 ) ) + IF( ( st_fx->hHQ_core->ber_occured_in_pvq != 0 ) ) { set16_fx( fg_pred, 1, nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ } @@ -307,16 +308,16 @@ Word16 pvq_core_dec_fx( Word16 gain_bits_array[NB_SFM]; Word16 fg_pred[NB_SFM_MAX]; - IF( st_fx->hHQ_core != NULL ) + if ( st_fx->hHQ_core != NULL ) { st_fx->hHQ_core->ber_occured_in_pvq = 0; move16(); } - R_upd = shl( bits_tot, 3 ); + R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr( R_upd, 3 ); + pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); @@ -375,7 +376,7 @@ void decode_energies_fx( Word16 *dim_part, Word16 *bits_part, Word16 *g_part, /* Q15 */ - short qband, + Word16 qband, Word16 *bits_left, Word16 dim, const Word16 strict_bits ) @@ -485,12 +486,13 @@ static void densitySymbolIndexDecode_fx( { /* odd density exit */ *index_phi = -1; + move16(); return; } sym_freq = L_deposit_l( 1 ); - angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] ); + angle = atan2_fx( SQRT_DIM_fx[opp_sz], SQRT_DIM_fx[near_sz] ); // Q13 #ifdef BASOP_NOGLOB angle = shl_o( angle, 1, &Overflow ); #else @@ -526,7 +528,7 @@ static void densitySymbolIndexDecode_fx( Mpy_32_16_ss( acc, density_c, &acc, &lsb ); acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48 bits; upshift 16 bits; keep 32 MSB. */ acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add( L_add( acc, (Word32) density ), 1L ); + tot = L_add( L_add( acc, L_deposit_l( density ) ), 1L ); dec_freq = rc_decode_fx( &st_fx->BER_detect, hPVQ, tot ); @@ -577,7 +579,7 @@ static void densitySymbolIndexDecode_fx( tmp1 = L_mult0( tmp2, tmp2 ); tmp1 = L_add( tmp1, acc ); tmp2 = getSqrtWord32( tmp1 ); /* floor */ - if ( L_msu0( tmp1, tmp2, tmp2 ) != 0 ) + IF( L_msu0( tmp1, tmp2, tmp2 ) != 0 ) { tmp2 = add( tmp2, 1 ); /* convert to ceil */ } diff --git a/lib_dec/pvq_decode_fx.c b/lib_dec/pvq_decode_fx.c index ca8c8ed0a..5c97d8679 100644 --- a/lib_dec/pvq_decode_fx.c +++ b/lib_dec/pvq_decode_fx.c @@ -46,6 +46,8 @@ void pvq_decode_fx( { entry.lead_sign_ind = (Word16) rc_dec_bits_fx( st_fx, hPVQ, 1 ); entry.index = rc_dec_uniform_fx( st_fx, hPVQ, entry.size ); + move16(); + move32(); IF( st_fx->hHQ_core != NULL ) { @@ -66,6 +68,8 @@ void pvq_decode_fx( { entry.lead_sign_ind = (Word16) rc_dec_bits_fx( st_fx, hPVQ, 1 ); /* always a single sign bit */ entry.index = L_deposit_l( 0 ); + move16(); + move32(); } mpvq_decode_vec_fx( &entry, h_mem, y ); diff --git a/lib_dec/range_dec_fx.c b/lib_dec/range_dec_fx.c index e53e5cc58..d92e0d1d9 100644 --- a/lib_dec/range_dec_fx.c +++ b/lib_dec/range_dec_fx.c @@ -23,23 +23,26 @@ static Word16 rc_dec_read_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ ); void rc_dec_init_fx( Decoder_State *st_fx, /* i/o: Decoder State */ PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - Word16 tot_bits /* i : Total bit budget */ + Word16 tot_bits /* i : Total bit budget Q0 */ ) { Word16 i; hPVQ->rc_low = L_deposit_l( 0 ); + move32(); hPVQ->rc_range = 0xffffffff; move32(); hPVQ->rc_num_bits = 0; move16(); hPVQ->rc_offset = add( tot_bits, st_fx->next_bit_pos ); + move16(); hPVQ->rc_end = hPVQ->rc_offset; move16(); FOR( i = 0; i < 4; i++ ) { hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); + move32(); } } @@ -52,7 +55,7 @@ void rc_dec_init_fx( UWord32 rc_decode_fx( /* o : Decoded cumulative frequency */ Word16 *BER_detect, /* o : Bit error detection flag */ PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - UWord32 tot /* i : Total cumulative frequency */ + UWord32 tot /* i : Total cumulative frequency Q0 */ ) { UWord32 inv, lsb, val, UL_tmp1, UL_tmp2; @@ -62,6 +65,7 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency inv = UL_inverse( tot, &exp ); Mpy_32_32_uu( hPVQ->rc_range, inv, &( hPVQ->rc_help ), &lsb ); /*0+exp-32*/ hPVQ->rc_help = UL_lshr( hPVQ->rc_help, sub( exp, 32 ) ); + move32(); exp_den = norm_ul( hPVQ->rc_help ); UL_tmp2 = UL_lshl( hPVQ->rc_help, exp_den ); @@ -76,7 +80,7 @@ UWord32 rc_decode_fx( /* o : Decoded cumulative frequency UL_tmp2 = UL_Mpy_32_32( UL_addNsD( val, 1 ), hPVQ->rc_help ); UL_tmp1 = UL_subNsD( hPVQ->rc_low, UL_tmp1 ); UL_tmp2 = UL_subNsD( hPVQ->rc_low, UL_tmp2 ); - if ( UL_tmp2 < UL_tmp1 ) + IF( LT_64( UL_tmp2, UL_tmp1 ) ) { val = UL_addNsD( val, 1 ); } @@ -108,13 +112,18 @@ void rc_dec_update_fx( { hPVQ->rc_low = UL_subNsD( hPVQ->rc_low, UL_Mpy_32_32( cum_freq, hPVQ->rc_help ) ); /*0+0*/ hPVQ->rc_range = UL_Mpy_32_32( hPVQ->rc_help, sym_freq ); + move32(); + move32(); - WHILE( hPVQ->rc_range < 1 << 24 ) + WHILE( LT_64( hPVQ->rc_range, 1 << 24 ) ) { L_sub( 0, 0 ); /* For comparision in while*/ hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, 8 ); hPVQ->rc_low = UL_addNsD( UL_lshl( hPVQ->rc_low, 8 ), UL_deposit_l( rc_dec_read_fx( st_fx, hPVQ ) ) ); hPVQ->rc_range = UL_lshl( hPVQ->rc_range, 8 ); + move16(); + move32(); + move32(); } } @@ -133,17 +142,21 @@ Word32 rc_dec_bits_fx( /* i : Decoded value */ Word32 value; hPVQ->rc_num_bits = add( hPVQ->rc_num_bits, bits ); + move16(); IF( GT_16( bits, 16 ) ) { hPVQ->rc_offset = sub( hPVQ->rc_offset, sub( bits, 16 ) ); + move16(); value = UL_lshl( UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, sub( bits, 16 ) ) ), 16 ); hPVQ->rc_offset = sub( hPVQ->rc_offset, 16 ); + move16(); value = UL_or( value, UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, 16 ) ) ); } ELSE { hPVQ->rc_offset = sub( hPVQ->rc_offset, bits ); + move16(); value = UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, bits ) ); } @@ -164,7 +177,7 @@ UWord32 rc_dec_uniform_fx( /* i : Decoded value */ { UWord32 value; Word16 n; - n = sub( 32, norm_ul( tot - 1 ) ); + n = sub( 32, norm_ul( UL_subNsD( tot, 1 ) ) ); IF( LE_16( n, 8 ) ) { @@ -195,6 +208,7 @@ void rc_dec_finish_fx( ) { st_fx->next_bit_pos = hPVQ->rc_end; + move16(); } /*-------------------------------------------------------------------* diff --git a/lib_dec/rom_dec.c b/lib_dec/rom_dec.c index 8ae4a7462..a317678a4 100644 --- a/lib_dec/rom_dec.c +++ b/lib_dec/rom_dec.c @@ -49,11 +49,11 @@ #ifndef IVAS_FLOAT_FIXED const float h_low[5] = { -0.0125f, 0.1090f, 0.7813f, 0.1090f, -0.0125f }; #endif -const Word16 h_low_fx[5] = +const Word16 h_low_fx[5] = /* Q15 */ { -410, 3572, 25602, 3572, -410 }; -const Word16 inv_sqi[15] = +const Word16 inv_sqi[15] = /* Q15 */ { 8192, /* 1/4 */ 3641, /* 1/9 */ @@ -74,7 +74,7 @@ const Word16 inv_sqi[15] = /*-------------------------------------------------------------------* * index square used in fec_adapt_codebook *-------------------------------------------------------------------*/ -const Word16 sqi[15] = +const Word16 sqi[15] = /* Q0 */ { 4, /* 2 */ 9, /* 3 */ @@ -129,19 +129,19 @@ const float lsf_tab[LPC_SHB_ORDER] = 0.31293656f, 0.34594478f, 0.38072862f, 0.410051247f, 0.44525622f }; #endif -const Word16 lsf_tab_fx[LPC_SHB_ORDER] = +const Word16 lsf_tab_fx[LPC_SHB_ORDER] = /* Q15 */ { 2315, 3920, 5546, 6759, 7978, 10254, 11336, 12476, 13437, 14590 }; -const Word16 POW_ATT_TABLE0[OFF_FRAMES_LIMIT + 1] = +const Word16 POW_ATT_TABLE0[OFF_FRAMES_LIMIT + 1] = /* Q15 */ { 32767, 31293, 29885, 28540, 27255, 26029, 24857, 23738, 22670, 21650, 20675, 19745, 18856, 18007, 17197, 16423, 8211, 4106, 2053, 1026, 513, 257, 128, 64, 32, 16, 8, 4, 2, 1, 0 }; -const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = +const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = /* Q15 */ { 32767, 31656, 30581, 29543, 28540, 27571, 26635, 25731, 24857, 24013, 23198, 22410, 21650, 20915, 20205, 19519, 9759, 4880, 2440, 1220, @@ -150,7 +150,7 @@ const Word16 POW_ATT_TABLE1[OFF_FRAMES_LIMIT + 1] = /* frequency group start bins for transient analysis */ /* 125 375 750 1250 2000 4000 8000 16000 24000 */ const Word16 gw[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; -const Word16 gw_fx[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* frequency group start bins for transient analysis */ +const Word16 gw_fx[LGW_MAX] = { 1, 3, 6, 10, 16, 32, 64, 128, 192 }; /* Q0 frequency group start bins for transient analysis */ const Word16 gw_len_inv_fx[LGW_MAX - 1] = /* Q15 */ { @@ -226,7 +226,7 @@ const float w_hamm16k_2[L_TRANA16k/2] = }; #endif -const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = +const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = /* Q15 */ { 2621, 2623, 2630, 2640, 2654, 2672, 2694, 2721, 2751, 2785, 2824, 2866, 2913, 2963, 3017, 3076, @@ -254,7 +254,7 @@ const Word16 w_hamm48k_2_fx[L_TRANA48k / 2] = 32654, 32682, 32707, 32727, 32743, 32755, 32763, 32767 }; -const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = +const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = /* Q15 */ { 2621, 2626, 2640, 2663, 2695, 2736, 2786, 2845, 2913, 2991, 3077, 3172, 3276, 3388, 3509, 3639, @@ -274,7 +274,7 @@ const Word16 w_hamm32k_2_fx[L_TRANA32k / 2] = 32511, 32575, 32630, 32675, 32712, 32739, 32758, 32767 }; -const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = +const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = /* Q15 */ { 2621, 2640, 2695, 2787, 2916, 3080, 3281, 3516, 3787, 4091, 4429, 4799, 5201, 5633, 6095, 6585, @@ -285,7 +285,7 @@ const Word16 w_hamm16k_2_fx[L_TRANA16k / 2] = 28549, 29053, 29529, 29976, 30393, 30780, 31134, 31455, 31742, 31995, 32213, 32396, 32543, 32653, 32727, 32763 }; - +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k] = { 0.080000000000000f, 0.080027462973758f, 0.080109848615839f, 0.080247147089046f, 0.080439341999361f, 0.080686410397899f, 0.080988322783646f, 0.081345043106986f, @@ -325,7 +325,8 @@ const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k] = 0.993417713086533f, 0.994237922201026f, 0.995003893384487f, 0.995715535176712f, 0.996372762604660f, 0.996975497192592f, 0.997523666971448f, 0.998017206487434f, 0.998456056809844f, 0.998840165538090f, 0.999169486807964f, 0.999443981297112f, 0.999663616229731f, 0.999828365380479f, 0.999938209077610f, 0.999993134205322f }; -const Word16 w_hamm_sana48k_2_fx[288] = +#endif +const Word16 w_hamm_sana48k_2_fx[288] = /* Q15 */ { 2621, 2622, 2625, 2630, 2636, 2644, 2654, 2666, 2679, 2694, 2711, 2730, 2751, 2773, 2797, 2823, @@ -364,6 +365,7 @@ const Word16 w_hamm_sana48k_2_fx[288] = 32552, 32579, 32604, 32628, 32649, 32669, 32687, 32703, 32717, 32730, 32741, 32750, 32757, 32762, 32766, 32767 }; +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k] = { 0.080000000000000f, 0.080061898522781f, 0.080247577432747f, 0.080556986759243f, 0.080990043232791f, 0.081546630307495f, 0.082226598192408f, 0.083029763891845f, @@ -391,7 +393,7 @@ const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k] = 0.985208504353495f, 0.987046796215483f, 0.988764777050081f, 0.990361984507393f, 0.991837988740540f, 0.993192392521341f, 0.994424831347216f, 0.995534973539285f, 0.996522520331626f, 0.997387205951684f, 0.998128797691797f, 0.998747095971820f, 0.999241934392838f, 0.999613179781951f, 0.999860732228111f, 0.999984525109009f }; - +#endif const Word16 w_hamm_sana32k_2_fx[L_PROT_HAMM_LEN2_32k] = /* Q15 */ { 2621, 2623, 2630, 2640, 2654, 2672, 2694, 2721, @@ -419,7 +421,7 @@ const Word16 w_hamm_sana32k_2_fx[L_PROT_HAMM_LEN2_32k] = /* Q15 */ 32283, 32344, 32400, 32452, 32501, 32545, 32585, 32622, 32654, 32682, 32707, 32727, 32743, 32755, 32763, 32767 }; - +#ifndef IVAS_FLOAT_FIXED const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k] = { 0.080000000000000f, 0.080248875229243f, 0.080995231617495f, 0.082238261557724f, 0.083976620009229f, 0.086208425953062f, 0.088931264427414f, 0.092142189140766f, @@ -435,7 +437,7 @@ const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k] = 0.941486723514159f, 0.948653981707932f, 0.955379049234843f, 0.961654649126531f, 0.967473990768381f, 0.972830777247415f, 0.977719212165966f, 0.982134005913770f, 0.986070381391670f, 0.989524079180756f, 0.992491362151336f, 0.994969019506760f, 0.996954370257714f, 0.998445266123226f, 0.999440093855253f, 0.999937776984316f }; - +#endif const Word16 w_hamm_sana16k_2_fx[L_PROT_HAMM_LEN2_16k] = /* Q15 */ { 2621, 2630, 2654, 2695, 2752, 2825, 2914, 3019, @@ -471,8 +473,10 @@ const Word16 inv_tbl_2n_minus1[] = { -1, -1, /* Bits = 0 and 1 are not used */ /* er_dec_tcx.c */ +#ifndef IVAS_FLOAT_FIXED const float h_high3_32_flt[L_FIR_FER2] = {-0.0517f, -0.0587f, -0.0820f, -0.1024f, -0.1164f, 0.8786f, -0.1164f, -0.1024f, -0.0820f, -0.0587f, -0.0517f}; const float h_high3_16_flt[L_FIR_FER2] = { 0.f, -0.0205f, -0.0651f, -0.1256f, -0.1792f, 0.8028f, -0.1792f, -0.1256f, -0.0651f, -0.0205f, 0.f }; +#endif const Word16 h_high3_32[L_FIR_FER2] = { -1694/*-0.0517f Q15*/, -1923/*-0.0587f Q15*/, -2687/*-0.0820f Q15*/, -3355/*-0.1024f Q15*/, -3814/*-0.1164f Q15*/, 28790/*0.8786f Q15*/, -3814/*-0.1164f Q15*/, -3355/*-0.1024f Q15*/, -2687/*-0.0820f Q15*/, -1923/*-0.0587f Q15*/, -1694/*-0.0517f Q15*/ }; const Word16 h_high3_16[L_FIR_FER2] = { 0/* 0.f Q15*/, -672/*-0.0205f Q15*/, -2133/*-0.0651f Q15*/, -4116/*-0.1256f Q15*/, -5872/*-0.1792f Q15*/, 26306/*0.8028f Q15*/, -5872/*-0.1792f Q15*/, -4116/*-0.1256f Q15*/, -2133/*-0.0651f Q15*/, -672/*-0.0205f Q15*/, 0/* 0.f Q15*/ }; const Word16 T_256DIV_L_Frame[] = diff --git a/lib_dec/rom_dec.h b/lib_dec/rom_dec.h index 908a7f289..44f45905e 100644 --- a/lib_dec/rom_dec.h +++ b/lib_dec/rom_dec.h @@ -44,52 +44,55 @@ #ifndef IVAS_FLOAT_FIXED extern const float h_low[]; /* LP filter for filtering periodic part of excitation in artificial onset construction after FEC */ #endif -extern const Word16 h_low_fx[5]; -extern const Word16 inv_sqi[15]; -extern const Word16 sqi[15]; -extern const int16_t mult_avq_tab[]; -extern const int16_t shift_avq_tab[]; - -extern const int16_t hntable[55]; -extern const int16_t hetable[57]; -extern const int16_t hestable[15]; +extern const Word16 h_low_fx[5]; // Q15 +extern const Word16 inv_sqi[15]; // Q15 +extern const Word16 sqi[15]; // Q0 +extern const Word16 mult_avq_tab[]; // Q0 +extern const Word16 shift_avq_tab[]; // Q0 + +extern const Word16 hntable[55]; +extern const Word16 hetable[57]; +extern const Word16 hestable[15]; #ifndef IVAS_FLOAT_FIXED extern const float lsf_tab[LPC_SHB_ORDER]; #endif -extern const Word16 lsf_tab_fx[LPC_SHB_ORDER]; +extern const Word16 lsf_tab_fx[LPC_SHB_ORDER]; // Q15 -extern const Word16 POW_ATT_TABLE0[]; -extern const Word16 POW_ATT_TABLE1[]; -extern const int16_t gw[LGW_MAX]; -extern const Word16 gw_fx[LGW_MAX]; -extern const Word16 gw_len_inv_fx[LGW_MAX - 1]; +extern const Word16 POW_ATT_TABLE0[]; // Q15 +extern const Word16 POW_ATT_TABLE1[]; // Q15 +extern const Word16 gw[LGW_MAX]; // Q0 +extern const Word16 gw_fx[LGW_MAX]; // Q0 +extern const Word16 gw_len_inv_fx[LGW_MAX - 1]; // Q15 extern const Word16 GR_POW_HEADROOM[]; -extern const int16_t ivas_gwlpr[LGW_MAX]; +extern const Word16 ivas_gwlpr[LGW_MAX]; #ifndef IVAS_FLOAT_FIXED extern const float w_hamm48k_2[L_TRANA48k / 2]; extern const float w_hamm32k_2[L_TRANA32k / 2]; extern const float w_hamm16k_2[L_TRANA16k / 2]; #endif -extern const Word16 w_hamm48k_2_fx[]; -extern const Word16 w_hamm32k_2_fx[]; -extern const Word16 w_hamm16k_2_fx[]; - +extern const Word16 w_hamm48k_2_fx[]; // Q15 +extern const Word16 w_hamm32k_2_fx[]; // Q15 +extern const Word16 w_hamm16k_2_fx[]; // Q15 +#ifndef IVAS_FLOAT_FIXED extern const float w_hamm_sana32k_2[L_PROT_HAMM_LEN2_32k]; extern const float w_hamm_sana16k_2[L_PROT_HAMM_LEN2_16k]; extern const float w_hamm_sana48k_2[L_PROT_HAMM_LEN2_48k]; +#endif extern const Word16 swb_hr_inv_frm_len[4]; /* in Q19 */ extern const Word16 inv_tbl_2n_minus1[]; -extern const Word16 w_hamm_sana48k_2_fx[]; -extern const Word16 w_hamm_sana32k_2_fx[]; -extern const Word16 w_hamm_sana16k_2_fx[]; +extern const Word16 w_hamm_sana48k_2_fx[]; // Q15 +extern const Word16 w_hamm_sana32k_2_fx[]; // Q15 +extern const Word16 w_hamm_sana16k_2_fx[]; // Q15 +#ifndef IVAS_FLOAT_FIXED extern const float h_high3_32_flt[L_FIR_FER2]; extern const float h_high3_16_flt[L_FIR_FER2]; -extern const Word16 h_high3_32[L_FIR_FER2]; -extern const Word16 h_high3_16[L_FIR_FER2]; -extern const Word16 T_256DIV_L_Frame[]; +#endif +extern const Word16 h_high3_32[L_FIR_FER2]; // Q15 +extern const Word16 h_high3_16[L_FIR_FER2]; // Q15 +extern const Word16 T_256DIV_L_Frame[]; // Q0 -extern const Word16 pcmdsp_window_hann_960[960]; -extern const Word16 pcmdsp_window_hann_640[640]; +extern const Word16 pcmdsp_window_hann_960[960]; // Q15 +extern const Word16 pcmdsp_window_hann_640[640]; // Q15 #endif diff --git a/lib_dec/rst_dec_fx.c b/lib_dec/rst_dec_fx.c index f348b56bc..4a43c7fd3 100644 --- a/lib_dec/rst_dec_fx.c +++ b/lib_dec/rst_dec_fx.c @@ -16,9 +16,9 @@ *----------------------------------------------------------------------------------*/ void CNG_reset_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pitch_buf, /* o : floating pitch for each subframe */ - Word16 *voice_factors /* o : voicing factors */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 *pitch_buf, /* o : floating pitch for each subframe Q6 */ + Word16 *voice_factors /* o : voicing factors Q15 */ ) { Word16 tmp, exp; @@ -44,12 +44,12 @@ void CNG_reset_dec_fx( move16(); /* LP-filtered pitch gain set to 0 */ - st_fx->lp_gainp_fx = 0; + st_fx->lp_gainp_fx = 0; // Q14 move16(); /* convert CNG energy into CNG gain for ACELP FEC */ /* st->lp_gainc = sqrt( st->lp_ener ); */ - st_fx->lp_gainc_fx = 0; + st_fx->lp_gainc_fx = 0; // Q3 move16(); IF( st_fx->lp_ener_fx != 0 ) diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index b6d153746..9304dc325 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -130,8 +130,8 @@ typedef struct #endif Word32 msCurrentMinSubWindow[NPART_SHAPING]; - int16_t msLocalMinFlag[NPART_SHAPING]; - int16_t msNewMinFlag[NPART_SHAPING]; + Word16 msLocalMinFlag[NPART_SHAPING]; + Word16 msNewMinFlag[NPART_SHAPING]; #ifndef IVAS_FLOAT_FIXED float msPsdFirstMoment_float[NPART_SHAPING]; #endif @@ -159,10 +159,10 @@ typedef struct #endif Word16 msLogNoiseEst[NPART_SHAPING]; - int16_t npart_shaping; /* Number of partitions */ - int16_t nFFTpart_shaping; /* Number of hybrid spectral partitions */ - int16_t part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ - int16_t midband_shaping[NPART_SHAPING]; /* Central band of each partition */ + Word16 npart_shaping; /* Number of partitions */ + Word16 nFFTpart_shaping; /* Number of hybrid spectral partitions */ + Word16 part_shaping[NPART_SHAPING]; /* Partition upper boundaries (band indices starting from 0) */ + Word16 midband_shaping[NPART_SHAPING]; /* Central band of each partition */ Word16 psize_shaping[NPART_SHAPING]; /* Partition sizes */ @@ -194,8 +194,8 @@ typedef struct #endif Word32 msPeriodog_ST_fx[NPART_SHAPING]; /* stereo CNA - short-term periodogram */ Word16 msPeriodog_ST_exp; /* exponent of stereo CNA - short-term periodogram */ - int16_t ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ - int16_t ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ + Word16 ms_last_inactive_bwidth; /* stereo CNA - bandwidth from the last inactive frame */ + Word16 ms_cnt_bw_up; /* stereo CNA - downward counter of frames since the last NB->WB switch */ #ifndef IVAS_FLOAT_FIXED float cna_LR_LT; /* stereo CNA - long-term L/R correlation factor calculated on stereo upmix */ #endif @@ -208,20 +208,20 @@ typedef struct float cna_g_state[STEREO_DFT_BAND_MAX]; /* stereo CNA - side gains from the last inactive frame */ float cna_cm[STEREO_DFT_BAND_MAX]; /* stereo CNA - coherence from the last inactive frame */ #endif - int16_t first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ - int16_t first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ - int16_t cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ + Word16 first_cna_noise_updated; /* stereo CNA - flag indicating that comfort noise has been properly initialized during warmup */ + Word16 first_cna_noise_update_cnt; /* stereo CNA - counter of CN initialization frames */ + Word16 cna_nbands; /* stereo CNA - number of frequency bands used by the CNA in DFT stereo mode */ - int16_t cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ + Word16 cna_band_limits[STEREO_DFT_BAND_MAX + 1]; /* stereo CNA - band limits used by the CNA in DFT stereo mode */ #ifndef IVAS_FLOAT_FIXED float cna_act_fact; /* stereo CNA - long-term signal activity factor (0-1) */ #endif #ifndef IVAS_FLOAT_FIXED float cna_rescale_fact; /* stereo CNA - CN energy re-scaling factor to maintain decoded energy */ #endif - int16_t cna_seed; /* stereo CNA - seed for random CN generator */ + Word16 cna_seed; /* stereo CNA - seed for random CN generator */ - int16_t flag_dtx_mode; + Word16 flag_dtx_mode; #ifndef IVAS_FLOAT_FIXED float lp_speech_float; #endif @@ -239,7 +239,7 @@ typedef struct #endif Word16 msPeriodogBuf[MSBUFLEN * NPART_SHAPING]; - int16_t msPeriodogBufPtr; + Word16 msPeriodogBufPtr; Word32 smoothed_psd_fx[L_FRAME16k]; /* stereo CNA - periodogram smoothed with IIR filter */ #ifdef IVAS_FLOAT_FIXED @@ -258,17 +258,17 @@ typedef struct typedef struct { - int16_t L_frameTCX; + Word16 L_frameTCX; Word16 FrameSize; - int16_t Pitch; + Word16 Pitch; Word16 Pitch_fx; - int16_t T_bfi; + Word16 T_bfi; Word8 T_bfi_fx; - int16_t Transient[MAX_POST_LEN]; - int16_t TCX_Tonality[DEC_STATE_LEN]; + Word16 Transient[MAX_POST_LEN]; + Word16 TCX_Tonality[DEC_STATE_LEN]; #ifndef IVAS_FLOAT_FIXED float outx_new_n1; #endif @@ -300,7 +300,7 @@ typedef struct #endif Word32 ener_fx; - int16_t zp; + Word16 zp; Word16 zp_fx; #ifndef IVAS_FLOAT_FIXED float recovery_gain_float; @@ -311,14 +311,14 @@ typedef struct #endif Word16 step_concealgain_fx; - int16_t concealment_method; + Word16 concealment_method; - int16_t subframe; + Word16 subframe; Word16 subframe_fx; - int16_t nbLostCmpt; + Word16 nbLostCmpt; - int16_t seed; + Word16 seed; } T_PLCInfo, *T_PLCInfo_HANDLE; @@ -329,8 +329,8 @@ typedef struct typedef struct { - uint16_t nSamples; - uint16_t nSamplesCore; + UWord16 nSamples; + UWord16 nSamplesCore; Float32 *spectralData_float; Word16 *spectralData; @@ -345,17 +345,17 @@ typedef struct Word16 scaleFactors_max_e; Word16 gain_tcx_exp; - int16_t blockIsValid; - int16_t blockIsConcealed; - int16_t tonalConcealmentActive; + Word16 blockIsValid; + Word16 blockIsConcealed; + Word16 tonalConcealmentActive; } blockData; typedef struct { - uint16_t numIndexes; - uint16_t indexOfTonalPeak[MAX_NUMBER_OF_IDX]; - uint16_t lowerIndex[MAX_NUMBER_OF_IDX]; - uint16_t upperIndex[MAX_NUMBER_OF_IDX]; + UWord16 numIndexes; + UWord16 indexOfTonalPeak[MAX_NUMBER_OF_IDX]; + UWord16 lowerIndex[MAX_NUMBER_OF_IDX]; + UWord16 upperIndex[MAX_NUMBER_OF_IDX]; Word16 phaseDiff[MAX_NUMBER_OF_IDX]; // Q12 /* This one can be stored with 16 bits in range 0..2*PI */ @@ -371,10 +371,10 @@ typedef struct tonalmdctconceal { TCX_config *tcx_cfg; void *pMDSTData; - int16_t nSamples; - int16_t nSamplesCore; - int16_t nNonZeroSamples; - int16_t nScaleFactors; + Word16 nSamples; + Word16 nSamplesCore; + Word16 nNonZeroSamples; + Word16 nScaleFactors; #ifndef IVAS_FLOAT_FIXED float lastPitchLag_float; @@ -452,20 +452,20 @@ typedef struct tonalmdctconceal typedef struct { - int16_t bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ - int16_t prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ - int16_t scfCountLongBlock[IGF_NOF_GRIDS]; - int16_t t; - int32_t bitrate; - const uint16_t *cf_se00; - const uint16_t *cf_se01; - int16_t cf_off_se01; - const uint16_t *cf_se02; - const int16_t *cf_off_se02; - const uint16_t *cf_se10; - int16_t cf_off_se10; - const uint16_t *cf_se11; - const int16_t *cf_off_se11; + Word16 bitsRead; /* after a call bitsRead contains the number of bits consumed by the decoder */ + Word16 prev[64]; /* no more than 64 SCFs for the IGF energy envelope of one block */ + Word16 scfCountLongBlock[IGF_NOF_GRIDS]; + Word16 t; + Word32 bitrate; + const UWord16 *cf_se00; + const UWord16 *cf_se01; + Word16 cf_off_se01; + const UWord16 *cf_se02; + const Word16 *cf_off_se02; + const UWord16 *cf_se10; + Word16 cf_off_se10; + const UWord16 *cf_se11; + const Word16 *cf_off_se11; Tastat acState; } IGFSCFDEC_INSTANCE, *IGFSCFDEC_INSTANCE_HANDLE; @@ -488,11 +488,11 @@ typedef struct igfdec_private_data_struct Word16 igf_pN_e[IGF_MAX_SFB]; - int16_t igf_curr[IGF_MAX_SFB]; /* current igf energies */ - int16_t igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ - int16_t igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ - int16_t igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ - int16_t igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; + Word16 igf_curr[IGF_MAX_SFB]; /* current igf energies */ + Word16 igf_prev[IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + Word16 igf_curr_subframe[IGF_MAX_SUBFRAMES][IGF_TRANS_FAK][IGF_MAX_SFB]; /* current igf energies per subframe*/ + Word16 igf_prev_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_SFB]; /* needed for concealment or indepflag==0 */ + Word16 igf_flatteningTrigger_subframe[IGF_MAX_SUBFRAMES]; /* spectral whitening: */ #ifndef IVAS_FLOAT_FIXED @@ -503,19 +503,19 @@ typedef struct igfdec_private_data_struct Word32 pSpecFlatBuf_fx[IGF_START_MX]; /* Q31 | MDCT spectrum before LPC shaping */ Word16 pSpecFlat_exp; - int16_t restrict_hopsize; + Word16 restrict_hopsize; - int16_t currWhiteningLevel[IGF_MAX_TILES]; - int16_t prevWhiteningLevel[IGF_MAX_TILES]; /* needed for concealment */ - int16_t currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; - int16_t prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* needed for concealment */ + Word16 currWhiteningLevel[IGF_MAX_TILES]; + Word16 prevWhiteningLevel[IGF_MAX_TILES]; /* needed for concealment */ + Word16 currWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; + Word16 prevWhiteningLevel_subframe[IGF_MAX_SUBFRAMES][IGF_MAX_TILES]; /* needed for concealment */ #ifndef IVAS_FLOAT_FIXED float totalNoiseNrg_float; #endif Word32 totalNoiseNrg; Word16 totalNoiseNrg_exp; - int16_t n_noise_bands; + Word16 n_noise_bands; Word16 headroom_TCX_noise_white; Word16 headroom_TCX_noise; @@ -524,29 +524,29 @@ typedef struct igfdec_private_data_struct #endif Word32 totalNoiseNrg_off; Word16 totalNoiseNrg_off_exp; - int16_t n_noise_bands_off; + Word16 n_noise_bands_off; /* IGF SCF decoding: */ IGFSCFDEC_INSTANCE hArithSCFdec; /* concealment: */ - int16_t frameLossCounter; + Word16 frameLossCounter; } IGFDEC_PRIVATE_DATA, *IGF_DEC_PRIVATE_DATA_HANDLE; typedef struct igfdec_instance_struct { - int16_t isIGFActive; - int16_t infoIGFAllZero; - int16_t infoIGFStopLine; - int16_t infoIGFStartLine; - int16_t infoIGFStopFreq; - int16_t infoIGFStartFreq; + Word16 isIGFActive; + Word16 infoIGFAllZero; + Word16 infoIGFStopLine; + Word16 infoIGFStartLine; + Word16 infoIGFStopFreq; + Word16 infoIGFStartFreq; Word16 *infoTCXNoise_ptr; Word16 infoTCXNoise_evs[IGF_START_MX]; - int16_t *flag_sparse; - int16_t flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; + Word16 *flag_sparse; + Word16 flag_sparseBuf[N_MAX_TCX - IGF_START_MN]; #ifndef IVAS_FLOAT_FIXED float *virtualSpec_float; // needed in MCT path float virtualSpecBuf[N_MAX_TCX - IGF_START_MN]; @@ -555,7 +555,7 @@ typedef struct igfdec_instance_struct Word32 virtualSpec[N_MAX_TCX - IGF_START_MN]; /* Q31 | buffer for temp flattening */ Word16 virtualSpec_e; /* | exponent of virtualSpec */ - int16_t flatteningTrigger; + Word16 flatteningTrigger; IGFDEC_PRIVATE_DATA igfData; } IGFDEC_INSTANCE, *IGF_DEC_INSTANCE_HANDLE; @@ -589,14 +589,14 @@ typedef struct tec_dec_structure typedef struct tcx_ltp_dec_structure { /* TCX-LTP */ - int16_t tcxltp; + Word16 tcxltp; #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_float; #endif Word16 tcxltp_gain; /* Q15 */ - int16_t tcxltp_pitch_int; - int16_t tcxltp_pitch_fr; + Word16 tcxltp_pitch_int; + Word16 tcxltp_pitch_fr; #ifndef IVAS_FLOAT_FIXED float tcxltp_mem_in_float[TCXLTP_MAX_DELAY]; #endif @@ -615,15 +615,15 @@ typedef struct tcx_ltp_dec_structure #endif - int16_t tcxltp_pitch_int_post_prev; - int16_t tcxltp_pitch_fr_post_prev; + Word16 tcxltp_pitch_int_post_prev; + Word16 tcxltp_pitch_fr_post_prev; #ifndef IVAS_FLOAT_FIXED float tcxltp_gain_post_prev_float; #endif // #ifndef IVAS_FLOAT_FIXED Word16 tcxltp_gain_post_prev; - int16_t tcxltp_filt_idx_prev; + Word16 tcxltp_filt_idx_prev; } TCX_LTP_DEC_DATA, *TCX_LTP_DEC_HANDLE; @@ -634,8 +634,8 @@ typedef struct tcx_ltp_dec_structure typedef struct tcx_dec_structure { - int16_t enableTcxLpc; /* global toggle for the TCX LPC quantizer */ - int16_t envWeighted; /* are is{p,f}_old[] weighted or not? */ + Word16 enableTcxLpc; /* global toggle for the TCX LPC quantizer */ + Word16 envWeighted; /* are is{p,f}_old[] weighted or not? */ /* tonal PLC */ #ifndef IVAS_FLOAT_FIXED @@ -650,20 +650,20 @@ typedef struct tcx_dec_structure #endif Word16 tcxltp_last_gain_unmodified; /* Q15 */ - int16_t tcx_hm_LtpPitchLag; - int16_t tcx_lpc_shaped_ari; + Word16 tcx_hm_LtpPitchLag; + Word16 tcx_lpc_shaped_ari; - int16_t pit_min_TCX; - int16_t pit_max_TCX; + Word16 pit_min_TCX; + Word16 pit_max_TCX; - int16_t L_frameTCX; + Word16 L_frameTCX; #ifndef IVAS_FLOAT_FIXED float old_excFB[L_FRAME48k]; /* old excitation FB */ #endif Word16 old_excFB_fx[L_FRAME48k]; /* old excitation FB */ - int16_t old_synth_len; - int16_t old_synth_lenFB; + Word16 old_synth_len; + Word16 old_synth_lenFB; #ifndef IVAS_FLOAT_FIXED float old_synth_float[OLD_SYNTH_INTERNAL_DEC]; /* synthesis memory */ #endif @@ -716,25 +716,25 @@ typedef struct tcx_dec_structure /*TCX resisual Q*/ - int16_t resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ + Word16 resQBits[NB_DIV]; /* number of bits read for the residual Quantization in TCX*/ /* PLC */ - int16_t noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ - int16_t tnsActive[NB_DIV]; + Word16 noise_filling_index[NB_DIV]; /* PLC - last decoded noise filling index */ + Word16 tnsActive[NB_DIV]; #ifndef IVAS_FLOAT_FIXED float ltpGainMemory[N_LTP_GAIN_MEMS]; /* for smoothing noiseTransWidth */ #endif Word16 ltpGainMemory_fx[N_LTP_GAIN_MEMS]; /* Q15 */ - uint16_t kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ + UWord16 kernel_type[2]; /* transform kernel type in each subframe (MDCT or MDST) */ - int16_t prev_widow_left_rect; + Word16 prev_widow_left_rect; /* state variables for the minimum statistics used for PLC */ #ifndef IVAS_FLOAT_FIXED float CngLevelBackgroundTrace_bfi; /* PLC - long term gain estimate for background level, used for PLC fade out */ float NoiseLevelMemory_bfi[PLC_MIN_STAT_BUFF_SIZE]; #endif - int16_t NoiseLevelIndex_bfi; - int16_t CurrLevelIndex_bfi; + Word16 NoiseLevelIndex_bfi; + Word16 CurrLevelIndex_bfi; Word16 conCngLevelBackgroundTrace; /* Q15 long term gain estimate for background level, used for PLC fade out */ Word16 conCngLevelBackgroundTrace_e; @@ -774,7 +774,7 @@ typedef struct tcx_dec_structure #endif Word16 stepCompensate, stepCompensate_e; - int16_t tcxConceal_recalc_exc; + Word16 tcxConceal_recalc_exc; #ifndef IVAS_FLOAT_FIXED float cummulative_damping_tcx_float; #endif @@ -790,18 +790,18 @@ typedef struct tcx_dec_structure typedef struct gsc_dec_structure { - int16_t seed_tcx; /* AC mode (GSC) - seed for noise fill */ + Word16 seed_tcx; /* AC mode (GSC) - seed for noise fill */ - int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ - // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ + // Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ #ifndef IVAS_FLOAT_FIXED float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ #endif Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ - int16_t noise_lev; /* AC mode (GSC) - noise level */ - // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ + Word16 noise_lev; /* AC mode (GSC) - noise level */ + // Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ #ifndef IVAS_FLOAT_FIXED float lt_ener_per_band[MBANDS_GN16k]; @@ -818,8 +818,8 @@ typedef struct gsc_dec_structure #endif Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ - int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ - // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ + Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ + // Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ #ifndef IVAS_FLOAT_FIXED float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ @@ -831,8 +831,8 @@ typedef struct gsc_dec_structure #endif Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ - int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ - // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ + // Word16 last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ } GSC_DEC_DATA, *GSC_DEC_HANDLE; @@ -869,11 +869,11 @@ typedef struct ld_music_postfilt_structure #endif Word16 LDm_mem_etot_fx; /* LD music post-filter - total energy memory */ - int16_t LDm_last_music_flag; /* LD music post-filter - last music flag */ + Word16 LDm_last_music_flag; /* LD music post-filter - last music flag */ - int16_t LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ + Word16 LDm_nb_thr_1; /* LD music post-filter - number of consecutive frames of level 1 */ - int16_t LDm_nb_thr_3; + Word16 LDm_nb_thr_3; #ifndef IVAS_FLOAT_FIXED float dct_post_old_exc[DCT_L_POST - OFFSET2]; @@ -914,7 +914,7 @@ typedef struct ld_music_postfilt_structure #endif Word16 filt_lfE_fx[DCT_L_POST]; - int16_t last_nonfull_music; + Word16 last_nonfull_music; Word16 Old_ener_Q; /* Old energy scaling factor */ @@ -942,10 +942,10 @@ typedef struct bass_postfilt_structure #endif Word16 pst_lp_ener_fx; /* Bass post-filter - long-term energy Q8*/ - int16_t Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ + Word16 Track_on_hist[L_TRACK_HIST]; /* Bass post-filter - History of half frame usage */ - int16_t vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ - // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ + // Word16 vibrato_hist[L_TRACK_HIST]; /* Bass post-filter - History of frames declared as vibrato */ #ifndef IVAS_FLOAT_FIXED float psf_att; /* Bass post-filter - post filter attenuation factor */ #endif @@ -964,27 +964,27 @@ typedef struct bass_postfilt_structure typedef struct td_cng_dec_structure { - int16_t cng_seed; /* DTX/CNG - seed for white noise random generator */ - // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ + Word16 cng_seed; /* DTX/CNG - seed for white noise random generator */ + // Word16 cng_seed; /*CNG and DTX - seed for white noise random generator*/ #ifndef IVAS_FLOAT_FIXED float Enew; /* DTX/CNG - decoded residual energy */ #endif Word32 Enew_fx; /* CNG and DTX - decoded residual energy Q6*/ - int16_t old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ + Word16 old_enr_index; /* DTX/CNG - index of last encoded CNG energy */ - int16_t cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ + Word16 cng_ener_seed; /* DTX/CNG - seed for random generator for variation of excitation energy */ - int16_t cng_ener_seed1; + Word16 cng_ener_seed1; - int16_t last_allow_cn_step; + Word16 last_allow_cn_step; - int16_t ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_hist_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ + Word16 ho_hist_ptr; /* DTX/CNG - pointer for averaging buffers */ - int32_t ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ - // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ + Word32 ho_sid_bw; /* DTX/CNG - SID bandwidth flags */ + // Word32 ho_sid_bw; /* CNG and DTX - SID bandwidth flags */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_hist[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ #endif @@ -999,12 +999,12 @@ typedef struct td_cng_dec_structure Word32 ho_env_hist_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t act_cnt; /* DTX/CNG - counter of active frames */ + Word16 act_cnt; /* DTX/CNG - counter of active frames */ - int16_t ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ + Word16 ho_circ_size; /* DTX/CNG - size of DTX hangover history buffer for averaging, <0,HO_HIST_SIZE> */ - int16_t ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ - // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ + Word16 ho_circ_ptr; /* DTX/CNG - pointer for averaging buffers */ + // Word16 ho_circ_ptr; /* CNG and DTX - pointer for averaging buffers */ #ifndef IVAS_FLOAT_FIXED float ho_lsp_circ[HO_HIST_SIZE * M]; /* DTX/CNG - old LSP buffer for averaging */ @@ -1020,14 +1020,14 @@ typedef struct td_cng_dec_structure Word32 ho_env_circ_fx[HO_HIST_SIZE * NUM_ENV_CNG]; - int16_t num_ho; /* DTX/CNG - number of selected hangover frames */ + Word16 num_ho; /* DTX/CNG - number of selected hangover frames */ - int16_t ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ + // Word16 ho_16k_lsp[HO_HIST_SIZE]; /* DTX/CNG - 16k LSPs flags */ - int16_t act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ - // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ + // Word16 act_cnt2; /* DTX/CNG - counter of active frames for CNG_mode switching */ #ifndef IVAS_FLOAT_FIXED float old_env[20]; #endif @@ -1063,13 +1063,13 @@ typedef struct td_cng_dec_structure float last_wb_cng_ener; float last_shb_cng_ener; #endif - int16_t swb_cng_seed; + Word16 swb_cng_seed; #ifndef IVAS_FLOAT_FIXED float lsp_shb_prev_prev[LPC_SHB_ORDER]; float lsp_shb_prev[LPC_SHB_ORDER]; #endif - int16_t shb_dtx_count; - int16_t trans_cnt; + Word16 shb_dtx_count; + Word16 trans_cnt; #ifdef IVAS_FLOAT_FIXED Word16 interpol_3_2_cng_dec_fx[INTERP_3_2_MEM_LEN]; @@ -1083,7 +1083,7 @@ typedef struct td_cng_dec_structure Word16 lsp_shb_prev_prev_fx[LPC_SHB_ORDER]; // Q(14) #endif - int16_t burst_cnt; + Word16 burst_cnt; #ifndef IVAS_FLOAT_FIXED float last_shb_ener; #endif @@ -1103,7 +1103,7 @@ typedef struct td_cng_dec_structure typedef struct sc_vbr_dec_structure { - int16_t firstTime_voiceddec; + Word16 firstTime_voiceddec; /* DTFS variables */ #ifndef IVAS_FLOAT_FIXED @@ -1115,11 +1115,11 @@ typedef struct sc_vbr_dec_structure #endif Word16 dtfs_dec_b_fx[MAXLAG_WI]; /*Variable Q format in dtfs_dec_Q*/ - int16_t dtfs_dec_lag; + Word16 dtfs_dec_lag; - int16_t dtfs_dec_nH; + Word16 dtfs_dec_nH; - int16_t dtfs_dec_nH_4kHz; + Word16 dtfs_dec_nH_4kHz; #ifndef IVAS_FLOAT_FIXED float dtfs_dec_upper_cut_off_freq_of_interest; @@ -1172,7 +1172,7 @@ typedef struct sc_vbr_dec_structure Word16 shape3_filt_mem_dec_fx[10]; /* qfm currently Q0*/ - int16_t nelp_dec_seed; + Word16 nelp_dec_seed; Word16 FadeScale_fx; /*Q15*/ @@ -1185,24 +1185,24 @@ typedef struct sc_vbr_dec_structure typedef struct hq_nbfec_structure { - int16_t prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ - // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ + Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ + // Word16 prev_last_core; /* !!! note: the parameter is identical to last_core in IVAS */ #ifndef IVAS_FLOAT_FIXED float diff_energy; #endif Word16 diff_energy_fx; - int16_t stat_mode_out; + Word16 stat_mode_out; - int16_t stat_mode_old; + Word16 stat_mode_old; - int16_t phase_mat_flag; + Word16 phase_mat_flag; - int16_t phase_mat_next; + Word16 phase_mat_next; - int16_t old_Min_ind; + Word16 old_Min_ind; #ifndef IVAS_FLOAT_FIXED float old_auOut_2fr[L_FRAME8k * 2]; @@ -1232,16 +1232,16 @@ typedef struct hq_nbfec_structure /*Word16 old_hqswb_clas;*/ /* only used in inactive code, where it might probably be replaced by old_hqswb_clas_fx */ - int16_t HQ_FEC_seed; + Word16 HQ_FEC_seed; #ifndef IVAS_FLOAT_FIXED float energy_MA_Curr[2]; #endif Word16 energy_MA_Curr_fx[2]; - int16_t prev_sign_switch[HQ_FEC_SIGN_SFM]; + Word16 prev_sign_switch[HQ_FEC_SIGN_SFM]; - int16_t prev_sign_switch_2[HQ_FEC_SIGN_SFM]; + Word16 prev_sign_switch_2[HQ_FEC_SIGN_SFM]; #ifndef IVAS_FLOAT_FIXED float old_coeffs[L_FRAME8k]; /* HQ core - old coefficients (for FEC) */ @@ -1288,7 +1288,7 @@ typedef struct hq_dec_structure Word16 Q_old_wtda; Word16 Q_old_postdec; /*scaling of the output of core_switching_post_dec_fx() */ - int16_t last_hq_core_type; + Word16 last_hq_core_type; Word16 old_is_transient[3]; /* HQ core - previous transient flag (for FEC) */ @@ -1317,7 +1317,7 @@ typedef struct hq_dec_structure #ifndef IVAS_FLOAT_FIXED float prev_coeff_out[L_HQ_WB_BWE]; /* the highest coefficients of last frame */ #endif - int16_t prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; + Word16 prev_SWB_peak_pos[SPT_SHORTEN_SBNUM]; Word32 prev_coeff_out_fx[L_HQ_WB_BWE]; /* Q12 */ /* the coefficients of last frame */ Word16 prev_SWB_peak_pos_fx[SPT_SHORTEN_SBNUM]; @@ -1386,9 +1386,9 @@ typedef struct hq_dec_structure #endif Word16 wmold_hb_fx; /* Q15 */ - int16_t prevflag; + Word16 prevflag; - int16_t pastpre; + Word16 pastpre; Word16 prev_frm_hfe2; @@ -1477,9 +1477,9 @@ typedef struct hq_dec_structure Word16 ph_ecu_active; /* Set if Phase ECU was used in last bad frame */ - int16_t ni_seed_forfec; + Word16 ni_seed_forfec; - int16_t ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ + Word16 ber_occured_in_pvq; /* flag for BER detection from PVQ routines */ } HQ_DEC_DATA, *HQ_DEC_HANDLE; @@ -1491,7 +1491,7 @@ typedef struct hq_dec_structure typedef struct zero_bwe_dec_structure { - int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ + Word16 seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ #ifndef IVAS_FLOAT_FIXED float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ @@ -1575,7 +1575,7 @@ typedef struct td_bwe_dec_structure #endif Word16 old_bwe_exc_fx[PIT16k_MAX * 2]; /*Q_exc*/ - int16_t bwe_seed[2]; + Word16 bwe_seed[2]; #ifndef IVAS_FLOAT_FIXED float bwe_non_lin_prev_scale; @@ -1649,7 +1649,7 @@ typedef struct td_bwe_dec_structure #endif Word16 prev_mix_factor_fx; /* mixing factor in the previous frame */ - int16_t syn_dm_phase; + Word16 syn_dm_phase; #ifndef IVAS_FLOAT_FIXED float fbbwe_hpf_mem[4][4]; @@ -1758,27 +1758,27 @@ typedef struct td_bwe_dec_structure /* quantized data */ - int16_t lsf_idx[NUM_Q_LSF]; + Word16 lsf_idx[NUM_Q_LSF]; - int16_t m_idx; + Word16 m_idx; - int16_t grid_idx; + Word16 grid_idx; - int16_t idxSubGains; + Word16 idxSubGains; - int16_t idxFrameGain; + Word16 idxFrameGain; - int16_t idx_shb_fr_gain; + Word16 idx_shb_fr_gain; - int16_t idx_res_gs[NB_SUBFR16k]; + Word16 idx_res_gs[NB_SUBFR16k]; - int16_t idx_mixFac; + Word16 idx_mixFac; - int16_t lsf_WB; + Word16 lsf_WB; - int16_t gFrame_WB; + Word16 gFrame_WB; - int16_t idxGain; + Word16 idxGain; #ifndef IVAS_FLOAT_FIXED float old_core_synth[L_FRAME16k]; @@ -1838,7 +1838,7 @@ typedef struct fd_bwe_dec_structure #endif Word16 mem_deemph_old_syn_fx; - int16_t prev_mode; + Word16 prev_mode; #ifndef IVAS_FLOAT_FIXED float prev_SWB_fenv[SWB_FENV]; @@ -1854,13 +1854,13 @@ typedef struct fd_bwe_dec_structure #endif Word32 prev_Energy_wb_fx; - int16_t prev_L_swb_norm; + Word16 prev_L_swb_norm; - int16_t Seed; + Word16 Seed; Word16 memExp1; - int16_t prev_frica_flag; + Word16 prev_frica_flag; #ifndef IVAS_FLOAT_FIXED float mem_imdct[L_FRAME48k]; @@ -1879,7 +1879,7 @@ typedef struct fd_bwe_dec_structure #endif Word16 prev_weight_fx; - int16_t prev_flag; + Word16 prev_flag; #ifndef IVAS_FLOAT_FIXED float last_wb_bwe_ener; @@ -1899,7 +1899,7 @@ typedef struct fd_bwe_dec_structure typedef struct hr_swb_bwe_dec_structure { - int16_t bwe_highrate_seed; + Word16 bwe_highrate_seed; Word16 bwe_highrate_seed_fx; #ifndef IVAS_FLOAT_FIXED @@ -1909,7 +1909,7 @@ typedef struct hr_swb_bwe_dec_structure Word16 t_audio_prev_fx_exp[NUM_TIME_SWITCHING_BLOCKS]; - int16_t old_is_transient_hr_bwe; + Word16 old_is_transient_hr_bwe; Word16 old_is_transient_hr_bwe_fx; #ifndef IVAS_FLOAT_FIXED @@ -1929,12 +1929,12 @@ typedef struct hr_swb_bwe_dec_structure typedef struct pvq_dec_structure { - uint32_t rc_low; - uint32_t rc_range; - uint32_t rc_help; - int16_t rc_num_bits; - int16_t rc_offset; - int16_t rc_end; + UWord32 rc_low; + UWord32 rc_range; + UWord32 rc_help; + Word16 rc_num_bits; + Word16 rc_offset; + Word16 rc_end; } PVQ_DEC_DATA, *PVQ_DEC_HANDLE; @@ -1960,7 +1960,7 @@ typedef struct amrwb_io_dec_structure #endif Word16 fmerit_w_sm_fx; /* HF BWE - fmerit parameter memory */ - int16_t frame_count; /* HF BWE - frame count */ + Word16 frame_count; /* HF BWE - frame count */ Word16 frame_count_fx; /* HF BWE - frame count */ #ifndef IVAS_FLOAT_FIXED float ne_min; /* HF BWE - minimum Noise gate - short-term energy */ @@ -1987,13 +1987,13 @@ typedef struct amrwb_io_dec_structure #endif Word16 unvoicing_sm_fx; /* HF BWE - smoothed unvoiced parameter */ - int16_t unvoicing_flag; /* HF BWE - unvoiced flag */ + Word16 unvoicing_flag; /* HF BWE - unvoiced flag */ Word16 unvoicing_flag_fx; /* HF BWE - unvoiced flag */ - int16_t voicing_flag; /* HF BWE - voiced flag */ + Word16 voicing_flag; /* HF BWE - voiced flag */ Word16 voicing_flag_fx; /* HF BWE - voiced flag */ - int16_t start_band_old; /* HF BWE - previous start point for copying frequency band */ + Word16 start_band_old; /* HF BWE - previous start point for copying frequency band */ Word16 start_band_old_fx; /* HF BWE - previous start point for copying frequency band */ #ifndef IVAS_FLOAT_FIXED float OptCrit_old; /* HF BWE - previous criterion value for deciding the start point */ @@ -2001,7 +2001,7 @@ typedef struct amrwb_io_dec_structure Word32 OptCrit_old_fx; /* HF BWE - previous criterion value for deciding the start point */ /* Improvement of unvoiced and audio signals in AMR-WB IO mode */ - int16_t UV_cnt; /* number of consecutives frames classified as UV */ + Word16 UV_cnt; /* number of consecutives frames classified as UV */ Word16 UV_cnt_fx; /* number of consecutives frames classified as UV */ #ifndef IVAS_FLOAT_FIXED float LT_UV_cnt; /* long-term consecutives frames classified as UV */ @@ -2051,75 +2051,75 @@ typedef struct Decoder_State * Common parameters *----------------------------------------------------------------------------------*/ - int16_t idchan; /* channel ID (audio channel number) */ - int16_t element_mode; /* element mode */ - int32_t element_brate; /* element bitrate */ - int16_t codec_mode; /* Mode 1 or 2 */ - int16_t mdct_sw_enable; /* MDCT switching enable flag */ - int16_t mdct_sw; /* MDCT switching indicator */ - int16_t last_codec_mode; /* last used codec mode */ + Word16 idchan; /* channel ID (audio channel number) */ + Word16 element_mode; /* element mode */ + Word32 element_brate; /* element bitrate */ + Word16 codec_mode; /* Mode 1 or 2 */ + Word16 mdct_sw_enable; /* MDCT switching enable flag */ + Word16 mdct_sw; /* MDCT switching indicator */ + Word16 last_codec_mode; /* last used codec mode */ - uint16_t *bit_stream; /* pointer to bitstream buffer */ + UWord16 *bit_stream; /* pointer to bitstream buffer */ - int16_t next_bit_pos; /* position of the next bit to be read from the bitstream */ + Word16 next_bit_pos; /* position of the next bit to be read from the bitstream */ Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */ Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */ Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */ Word16 total_num_bits; /* == st->total_brate / 50 */ - int16_t BER_detect; /* flag to signal detected bit error in the bitstream */ + Word16 BER_detect; /* flag to signal detected bit error in the bitstream */ - int32_t output_Fs; /* output sampling rate */ + Word32 output_Fs; /* output sampling rate */ Word16 output_frame_fx; /* Output frame length Q0*/ - int32_t total_brate; /* total bitrate in kbps of the codec */ + Word32 total_brate; /* total bitrate in kbps of the codec */ - int32_t last_total_brate; /* last total bitrate in kbps of the codec */ - // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ + Word32 last_total_brate; /* last total bitrate in kbps of the codec */ + // Word32 last_total_brate_fx; /* last total bitrate in kbps of the codec Q0*/ - int32_t last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ + Word32 last_total_brate_ber; /* last total bitrate in kbps of the codec - used only when first frame is lost and BER is detected afterwards */ - int16_t bits_frame_nominal; /* avg bits per frame on active frame */ - int32_t last_bits_frame_nominal; /* last avg bits per frame on active frame */ - int16_t flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ - int16_t bits_frame_channel; /* bits frame channel */ - int16_t side_bits_frame_channel; /* bits frame channel */ + Word16 bits_frame_nominal; /* avg bits per frame on active frame */ + Word32 last_bits_frame_nominal; /* last avg bits per frame on active frame */ + Word16 flag_ACELP16k; /* flag indicating use of ACELP core at 16kHz internal sampling rate */ + Word16 bits_frame_channel; /* bits frame channel */ + Word16 side_bits_frame_channel; /* bits frame channel */ - int16_t core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ + Word16 core; /* core (ACELP_CORE, TCX_20_CORE, TCX_10_CORE, HQ_CORE, AMR_WB_CORE) */ - int16_t coder_type; /* coder type */ - int16_t transform_type[2]; /* TCX20/10/5 mode in each subframe */ + Word16 coder_type; /* coder type */ + Word16 transform_type[2]; /* TCX20/10/5 mode in each subframe */ - int32_t core_brate; /* core bitrate */ + Word32 core_brate; /* core bitrate */ - int32_t last_core_brate; /* previous frame core bitrate */ + Word32 last_core_brate; /* previous frame core bitrate */ - int16_t extl; /* extension layer */ + Word16 extl; /* extension layer */ - int16_t extl_orig; /* extension layer */ + Word16 extl_orig; /* extension layer */ - int16_t last_extl; /* previous extension layer */ + Word16 last_extl; /* previous extension layer */ - int32_t extl_brate; /* extension layer bitrate */ + Word32 extl_brate; /* extension layer bitrate */ - int32_t extl_brate_orig; /* extension layer bitrate */ + Word32 extl_brate_orig; /* extension layer bitrate */ - int16_t L_frame; /* ACELP core internal frame length */ + Word16 L_frame; /* ACELP core internal frame length */ - int16_t bwidth; /* encoded signal bandwidth */ + Word16 bwidth; /* encoded signal bandwidth */ - int16_t Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ + Word16 Opt_AMR_WB; /* flag indicating AMR-WB IO mode */ Word16 Opt_VOIP_fx; /* flag indicating VOIP mode with JBM */ - int16_t ini_frame; /* initialization frames counter */ + Word16 ini_frame; /* initialization frames counter */ - int16_t prev_coder_type; /* coding type of last frame */ - int16_t low_rate_mode; /* low-rate mode flag */ - int16_t last_low_rate_mode; /* previous frame low-rate mode flag */ - int16_t inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ + Word16 prev_coder_type; /* coding type of last frame */ + Word16 low_rate_mode; /* low-rate mode flag */ + Word16 last_low_rate_mode; /* previous frame low-rate mode flag */ + Word16 inactive_coder_type_flag; /* inactive coder type flag (0 = AVQ / 1 = GSC) */ Word16 CNG_fx; /* RXDTX handler: CNG=1, nonCNG=0 */ Word16 prev_ft_speech_fx; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */ @@ -2167,13 +2167,13 @@ typedef struct Decoder_State Word16 stab_fac_smooth_fx; /* low-pass filtered stability factor Q15*/ - int16_t last_coder_type; /* previous coder type */ + Word16 last_coder_type; /* previous coder type */ Word16 agc_mem_fx[2]; /* memory of AGC for saturation control Q0*/ - int16_t mid_lsf_int; + Word16 mid_lsf_int; - int16_t safety_net; + Word16 safety_net; #ifndef IVAS_FLOAT_FIXED float stab_fac; /* LSF stability factor */ @@ -2198,11 +2198,11 @@ typedef struct Decoder_State Word32 L_mem_hp_out_fx[5]; /* hp filter memory for synthesis */ - int16_t GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ + Word16 GSC_noisy_speech; /* AC mode (GSC) - flag to indicate GSC on SWB noisy speech */ - int16_t GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ + Word16 GSC_IVAS_mode; /* AC mode (GSC) - GSC IVAS mode */ - int16_t Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ + Word16 Last_GSC_noisy_speech_flag; /* AC mode (GSC) - mem of the past flag to indicate GSC osn SWB noisy speech */ GSC_DEC_HANDLE hGSCDec; @@ -2217,17 +2217,17 @@ typedef struct Decoder_State ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ - int16_t unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ + Word16 unv_cnt; /* Stationary noise UV modification - unvoiced frame counter */ - int16_t uv_count; /* Stationary noise UV modification - unvoiced counter */ + Word16 uv_count; /* Stationary noise UV modification - unvoiced counter */ - int16_t act_count; /* Stationary noise UV modification - activation counter */ + Word16 act_count; /* Stationary noise UV modification - activation counter */ Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ - int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ + Word16 noimix_seed; /* Stationary noise UV modification - mixture seed */ Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ @@ -2244,21 +2244,21 @@ typedef struct Decoder_State Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ - int16_t bfi; /* FEC - bad frame indicator */ + Word16 bfi; /* FEC - bad frame indicator */ - int16_t prev_bfi; /* FEC - previous bad frame indicator */ + Word16 prev_bfi; /* FEC - previous bad frame indicator */ - int16_t prev_old_bfi; /* FEC - previous old bad frame indicator */ + Word16 prev_old_bfi; /* FEC - previous old bad frame indicator */ - int16_t seed; /* FEC - seed for random generator for excitation */ - // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ + Word16 seed; /* FEC - seed for random generator for excitation */ + // Word16 seed_fx; /* FEC - seed for random generator for excitation Q0*/ #ifndef IVAS_FLOAT_FIXED float lp_ener_bfi; /* FEC - long-term active-signal average energy */ float lp_ener; /* FEC - low-pass filtered energy */ #endif - int16_t last_good; /* FEC - clas of last good received */ + Word16 last_good; /* FEC - clas of last good received */ Word16 lp_gainp_fx; /* FEC - low-pass filtered pitch gain Q14 */ @@ -2277,14 +2277,14 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 bfi_pitch_fx; /* FEC - pitch for FEC */ - int16_t bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ + Word16 bfi_pitch_frame; /* FEC - frame length when pitch for FEC is saved */ Word16 old_pitch_buf_16_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values Q6 */ Word32 old_pitch_buf_fx[2 * NB_SUBFR16k + 2]; /* FEC - buffer of old subframe pitch values 15Q16 */ - int16_t upd_cnt; /* FEC - counter of frames since last update */ + Word16 upd_cnt; /* FEC - counter of frames since last update */ - int16_t scaling_flag; /* FEC - flag to indicate energy control of syn */ + Word16 scaling_flag; /* FEC - flag to indicate energy control of syn */ Word32 lp_ener_FEC_av; /* FEC - averaged voiced signal energy Q0 */ @@ -2292,8 +2292,8 @@ typedef struct Decoder_State Word16 old_enr_LP; /* FEC - LP filter gain Q5*/ - int16_t prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ - int16_t mode_lvq; /* FEC - index for LSF mean vector*/ + Word16 prev_nbLostCmpt; /* FEC - compt for number of consecutive lost frame at the previous frame*/ + Word16 mode_lvq; /* FEC - index for LSF mean vector*/ #ifndef IVAS_FLOAT_FIXED float old_enr_LP_float; /* FEC - LP filter gain */ @@ -2310,21 +2310,21 @@ typedef struct Decoder_State Word16 lsf_adaptive_mean_fx[M]; /* FEC - adaptive mean LSF vector for FEC (Qx2.56)*/ - int16_t decision_hyst; /* FEC - hysteresis of the music/speech decision */ + Word16 decision_hyst; /* FEC - hysteresis of the music/speech decision */ Word16 lp_ener_FER_fx; /* FEC - long-term active-signal average energy Q8*/ WI_DEC_HANDLE hWIDec; - int16_t relax_prev_lsf_interp; + Word16 relax_prev_lsf_interp; #ifndef IVAS_FLOAT_FIXED float mem_syn_clas_estim[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_syn_clas_estim_fx[L_SYN_MEM_CLAS_ESTIM]; /* FEC - memory of the synthesis signal for frame class estimation */ - int16_t bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ + Word16 bpf_off; /* Bass post-filter - do not use BPF when this flag is set to 1 */ BPF_DEC_HANDLE hBPF; /* Bass post-filter handle */ @@ -2337,8 +2337,8 @@ typedef struct Decoder_State HANDLE_CLDFB_FILTER_BANK cldfbSynHB; /* high band synthesis filter bank needed in SBA2Stereo DTX handling */ - int16_t last_active_bandsToZero_bwdec; - int16_t last_flag_filter_NB; + Word16 last_active_bandsToZero_bwdec; + Word16 last_flag_filter_NB; #ifndef IVAS_FLOAT_FIXED float perc_bwddec_float; @@ -2347,23 +2347,23 @@ typedef struct Decoder_State #endif // 0 Word16 perc_bwddec; /*Q14*/ - int16_t active_frame_cnt_bwddec; - int16_t flag_buffer[20]; - int16_t total_frame_cnt_bwddec; + Word16 active_frame_cnt_bwddec; + Word16 flag_buffer[20]; + Word16 total_frame_cnt_bwddec; Word32 avg_nrg_LT; Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ - int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ + Word16 last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ Word16 mem_preemp_preQ_fx; /* ACELP@16kHz - prequantizer preemhasis memory */ - int16_t last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ + Word16 last_nq_preQ; /* ACELP@16kHz - AVQ subquantizer number of the last sub-band of the last subframe */ - int16_t last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ + Word16 last_code_preq; /* ACELP@16kHz - last coefficient of the pre-quantizer contribution */ - int16_t use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ + Word16 use_acelp_preq; /* ACELP@16kHz - flag of prequantizer usage */ /* NB and formant post-filter */ @@ -2380,35 +2380,35 @@ typedef struct Decoder_State Word16 last_voice_factor_fx; /* Q6*/ - int16_t old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ + Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ /*----------------------------------------------------------------------------------* * DTX and TD CNG parameters *----------------------------------------------------------------------------------*/ - int16_t first_CNG; /* DTX/CNG - first CNG frame flag */ + Word16 first_CNG; /* DTX/CNG - first CNG frame flag */ - int16_t cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ + Word16 cng_type; /* DTX/CNG - flag indicating LP or CLDFB based SID/CNG */ - int16_t last_vad; + Word16 last_vad; - int32_t last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ + Word32 last_active_brate; /* DTX/CNG - last active frame bitrate used for CNG_mode control */ - int16_t last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ - // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ + Word16 last_CNG_L_frame; /* DTX/CNG - last CNG frame length */ + // Word16 last_CNG_L_frame_fx; /* DTX/CNG - last CNG frame length */ - int16_t CNG_mode; /* DTX/CNG - mode for DTX configuration */ - // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ + Word16 CNG_mode; /* DTX/CNG - mode for DTX configuration */ + // Word16 CNG_mode_fx; /* DTX/CNG - mode for DTX configuration */ #ifndef IVAS_FLOAT_FIXED float lspCNG[M]; /* DTX/CNG - LP filtered ISPs */ #endif // #ifndef IVAS_FLOAT_FIXED Word16 lspCNG_fx[M]; /* CNG and DTX - LP filtered ISPs Q15*/ - int16_t active_cnt; + Word16 active_cnt; TD_CNG_DEC_HANDLE hTdCngDec; - int16_t masa_sid_format; + Word16 masa_sid_format; /*----------------------------------------------------------------------------------* * AMR-WB IO mode parameters @@ -2422,13 +2422,13 @@ typedef struct Decoder_State SC_VBR_DEC_HANDLE hSC_VBR; - int16_t last_ppp_mode_dec; + Word16 last_ppp_mode_dec; - int16_t ppp_mode_dec; + Word16 ppp_mode_dec; - int16_t last_nelp_mode_dec; + Word16 last_nelp_mode_dec; - int16_t nelp_mode_dec; + Word16 nelp_mode_dec; Word16 prev_gain_pit_dec_fx; /*Q14*/ @@ -2440,9 +2440,9 @@ typedef struct Decoder_State Word16 prev_tilt_code_dec_fx; /*Q15*/ - int16_t vbr_hw_BWE_disable_dec; + Word16 vbr_hw_BWE_disable_dec; - int16_t last_vbr_hw_BWE_disable_dec; + Word16 last_vbr_hw_BWE_disable_dec; /*----------------------------------------------------------------------------------* * channel-aware mode @@ -2450,21 +2450,21 @@ typedef struct Decoder_State Word16 tilt_code_dec_fx[NB_SUBFR16k]; - int16_t rf_frame_type; - int16_t use_partial_copy; - int16_t prev_use_partial_copy; - int16_t rf_flag; - int16_t rf_flag_last; + Word16 rf_frame_type; + Word16 use_partial_copy; + Word16 prev_use_partial_copy; + Word16 rf_flag; + Word16 rf_flag_last; - int16_t rf_fec_offset; - int16_t next_coder_type; - int16_t prev_rf_frame_type; - int16_t rf_target_bits; + Word16 rf_fec_offset; + Word16 next_coder_type; + Word16 prev_rf_frame_type; + Word16 rf_target_bits; - int16_t rf_indx_nelp_fid; - int16_t rf_indx_nelp_iG1; - int16_t rf_indx_nelp_iG2[2]; - int16_t rf_indx_tbeGainFr; + Word16 rf_indx_nelp_fid; + Word16 rf_indx_nelp_iG1; + Word16 rf_indx_nelp_iG2[2]; + Word16 rf_indx_tbeGainFr; /*----------------------------------------------------------------------------------* * HR SWB BWE parameters @@ -2479,12 +2479,12 @@ typedef struct Decoder_State HQ_DEC_HANDLE hHQ_core; - int16_t last_core; + Word16 last_core; - int16_t last_core_from_bs; /* last frame core as coded in TCX bitstream */ - // Word16 last_core_bs_fx; + Word16 last_core_from_bs; /* last frame core as coded in TCX bitstream */ + // Word16 last_core_bs_fx; - int16_t last_L_frame_ori; + Word16 last_L_frame_ori; Word16 previoussynth_fx[L_FRAME48k]; Word32 previoussynth_fx_32[L_FRAME48k]; @@ -2518,14 +2518,14 @@ typedef struct Decoder_State TD_BWE_DEC_HANDLE hBWE_TD; - int16_t old_bwe_delay; + Word16 old_bwe_delay; Word16 hb_prev_synth_buffer_fx[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; /* WB/SWB bandwidth switching */ - Word16 tilt_wb_fx; + Word16 tilt_wb_fx; // Q11 - Word16 tilt_swb_fx; + Word16 tilt_swb_fx; // Q24 #ifndef IVAS_FLOAT_FIXED float hb_prev_synth_buffer[NS2SA( 48000, DELAY_BWE_TOTAL_NS )]; @@ -2538,25 +2538,25 @@ typedef struct Decoder_State float enerLH; float enerLL; #endif - Word16 prev_ener_shb_fx; + Word16 prev_ener_shb_fx; // Q1 Word32 enerLH_fx; Word16 enerLH_fx_Q; - Word32 prev_enerLH_fx; + Word32 prev_enerLH_fx; // Q1 Word32 enerLL_fx; Word16 enerLL_fx_Q; - Word32 prev_enerLL_fx; + Word32 prev_enerLL_fx; // Q1 - int16_t prev_fractive; + Word16 prev_fractive; - int16_t prev_bws_cnt; + Word16 prev_bws_cnt; - int16_t bws_cnt; + Word16 bws_cnt; - int16_t bws_cnt1; + Word16 bws_cnt1; #ifndef IVAS_FLOAT_FIXED float attenu1; @@ -2564,9 +2564,9 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 attenu_fx; - int16_t last_inner_frame; + Word16 last_inner_frame; - int16_t last_bwidth; + Word16 last_bwidth; Word16 t_audio_q_fx[L_FRAME]; @@ -2654,19 +2654,19 @@ typedef struct Decoder_State * Mode 2 *----------------------------------------------------------------------------------*/ - int16_t force_lpd_reset; + Word16 force_lpd_reset; ACELP_config acelp_cfg; /* ACELP configuration set for each frame */ ACELP_config acelp_cfg_rf; /* ACELP configuration for RF frame */ TCX_CONFIG_HANDLE hTcxCfg; /* TCX config */ - int16_t bits_frame; /* bit per frame overall */ - int16_t bits_frame_core; /* bit per frame for the core */ - int16_t narrowBand; + Word16 bits_frame; /* bit per frame overall */ + Word16 bits_frame_core; /* bit per frame for the core */ + Word16 narrowBand; Word16 bits_common; /* read bits from header and LPC*/ - int16_t last_is_cng; + Word16 last_is_cng; #ifndef IVAS_FLOAT_FIXED float *acelp_zir; @@ -2676,16 +2676,16 @@ typedef struct Decoder_State #endif Word16 syn[M + 1]; - int16_t bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ + Word16 bpf_gain_param; /* bass post-filter gain factor parameter (0->noBpf)*/ - int16_t L_frame_past; - int16_t L_frameTCX_past; + Word16 L_frame_past; + Word16 L_frameTCX_past; Word16 lsfold_uw[M]; /* old lsf (unweighted) */ Word16 lspold_uw[M]; /* old lsp (unweighted) */ - int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ + Word16 seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ #ifndef IVAS_FLOAT_FIXED float lsfold_uw_float[M]; /* old lsf (unweighted) */ @@ -2720,7 +2720,7 @@ typedef struct Decoder_State Word16 mem_syn_unv_back[M]; /* filter memory for unvoiced synth */ - int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ + Word16 plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ #ifndef IVAS_FLOAT_FIXED float mem_syn_unv_back_float[M]; /* filter memory for unvoiced synth */ @@ -2737,19 +2737,19 @@ typedef struct Decoder_State /* variables for framing */ - int16_t nb_subfr; + Word16 nb_subfr; - int16_t fscale; - int16_t fscale_old; - int32_t sr_core; + Word16 fscale; + Word16 fscale_old; + Word32 sr_core; - int16_t pit_min; - int16_t pit_fr1; - int16_t pit_fr1b; - int16_t pit_fr2; - int16_t pit_max; - int16_t pit_res_max; - int16_t pit_res_max_past; + Word16 pit_min; + Word16 pit_fr1; + Word16 pit_fr1b; + Word16 pit_fr2; + Word16 pit_max; + Word16 pit_res_max; + Word16 pit_res_max_past; /*Preemphasis factor*/ Word16 preemph_fac; /*0Q15*/ @@ -2771,14 +2771,14 @@ typedef struct Decoder_State Word16 mem_Aq[( NB_SUBFR16k ) * ( M + 1 )]; /* Q12 */ /* Error concealment */ - int16_t last_core_bfi; /* PLC - mode in previous frame */ - int16_t nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ + Word16 last_core_bfi; /* PLC - mode in previous frame */ + Word16 nbLostCmpt; /* PLC - compt for number of consecutive lost frame */ Word32 old_fpitch; /* last pitch of previous frame */ /*15Q16*/ Word32 old_fpitchFB; /* PLC - last pitch of previous FB frame (depends on output sr) */ /*15Q16*/ - int16_t clas_dec; /* PLC - frame class at the decoder */ + Word16 clas_dec; /* PLC - frame class at the decoder */ #ifndef IVAS_FLOAT_FIXED float old_fpitch_float; /* PLC - last pitch of previous frame (as transmitted) */ @@ -2790,7 +2790,7 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_pitch_gain[2 * NB_SUBFR16k + 2]; /* Pitch gain memory Q14 */ - int16_t plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ + Word16 plc_use_future_lag; /* PLC - flag indicating if info (pitch lag / pitch gain) about future frame is usable */ Word32 Mode2_lp_gainc; /* 15Q16 low passed code gain used for concealment*/ Word32 Mode2_lp_gainp; /* 15Q16 low passed pitch gain used for concealment*/ @@ -2803,16 +2803,16 @@ typedef struct Decoder_State Word16 prev_widow_left_rect; - int16_t reset_mem_AR; + Word16 reset_mem_AR; Word16 classifier_Q_mem_syn; /*scalingfactor of mem_syn_clas_estim_fx in MODE2 */ - int16_t rate_switching_init; + Word16 rate_switching_init; /* LPC quantization */ - int16_t lpcQuantization; - int16_t numlpc; + Word16 lpcQuantization; + Word16 numlpc; /* Bandwidth */ #ifndef IVAS_FLOAT_FIXED @@ -2825,17 +2825,17 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 voice_fac; - int16_t tcxonly; + Word16 tcxonly; - int16_t last_ctx_hm_enabled; + Word16 last_ctx_hm_enabled; struct tonalmdctconceal tonalMDCTconceal; TonalMDCTConcealPtr hTonalMDCTConc; - int16_t tonal_mdct_plc_active; - int16_t last_tns_active; - int16_t second_last_tns_active; - int16_t second_last_core; + Word16 tonal_mdct_plc_active; + Word16 last_tns_active; + Word16 second_last_tns_active; + Word16 second_last_core; /* parameters for switching */ #ifndef IVAS_FLOAT_FIXED @@ -2843,7 +2843,7 @@ typedef struct Decoder_State #endif // #ifndef IVAS_FLOAT_FIXED Word16 mem_syn_r[L_SYN_MEM]; /*LPC synthesis memory needed for rate switching*/ - int16_t rate_switching_reset; + Word16 rate_switching_reset; Word16 bpf_noise_buf[L_FRAME_16k]; Word32 bpf_noise_buf_32[L_FRAME_16k]; @@ -2854,44 +2854,44 @@ typedef struct Decoder_State Word16 *p_bpf_noise_buf; Word32 *p_bpf_noise_buf_32; - int16_t enableGplc; - int16_t flagGuidedAcelp; - int16_t T0_4th; - int16_t guidedT0; + Word16 enableGplc; + Word16 flagGuidedAcelp; + Word16 T0_4th; + Word16 guidedT0; - int16_t enablePlcWaveadjust; - int16_t tonality_flag; + Word16 enablePlcWaveadjust; + Word16 tonality_flag; T_PLCInfo_HANDLE hPlcInfo; T_PLCInfo plcInfo; - int16_t VAD; - int16_t flag_cna; - int16_t last_flag_cna; + Word16 VAD; + Word16 flag_cna; + Word16 last_flag_cna; #ifndef IVAS_FLOAT_FIXED float lp_noise_float; #endif // #ifndef IVAS_FLOAT_FIXED Word32 lp_noise; - int16_t seed_acelp; - int16_t core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ + Word16 seed_acelp; + Word16 core_ext_mode; /*GC,VC,UC,TC: core extended mode used for PLC or Acelp-external modules.*/ - int16_t dec_glr; - int16_t dec_glr_idx; + Word16 dec_glr; + Word16 dec_glr_idx; DEC_MODE m_decodeMode; - uint8_t m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - uint8_t m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + UWord8 m_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ + UWord8 m_old_frame_type; /*ZERO_FRAME/SID_FRAME/ACTIVE_FRAME*/ - int16_t old_ppp_mode; + Word16 old_ppp_mode; - int16_t con_tcx; - int16_t last_con_tcx; + Word16 con_tcx; + Word16 last_con_tcx; Word16 prev_Q_exc_fr; Word16 prev_Q_syn_fr; - int16_t writeFECoffset; + Word16 writeFECoffset; /*----------------------------------------------------------------------------------* * Frequency-domain-based CNG @@ -2904,7 +2904,7 @@ typedef struct Decoder_State *----------------------------------------------------------------------------------*/ IGF_DEC_INSTANCE_HANDLE hIGFDec; - int16_t igf; + Word16 igf; CLDFB_SCALE_FACTOR scaleFactor; @@ -2912,9 +2912,9 @@ typedef struct Decoder_State * TEC *----------------------------------------------------------------------------------*/ - int16_t tec_tfa; - int16_t tec_flag; - int16_t tfa_flag; + Word16 tec_tfa; + Word16 tec_flag; + Word16 tfa_flag; TEC_DEC_HANDLE hTECDec; #if 0 //not needed above structure has same variable @@ -2924,16 +2924,16 @@ typedef struct Decoder_State * IVAS parameters *----------------------------------------------------------------------------------*/ - int16_t tdm_LRTD_flag; /* LRTD stereo mode flag */ - int16_t cna_dirac_flag; /* CNA in DirAC flag */ - int16_t cng_sba_flag; /* CNG in SBA flag */ + Word16 tdm_LRTD_flag; /* LRTD stereo mode flag */ + Word16 cna_dirac_flag; /* CNA in DirAC flag */ + Word16 cng_sba_flag; /* CNG in SBA flag */ /* MCT Channel mode indication: LFE, ignore channel? */ // note_ : one extra value in evs ivas macro code MCT_CHAN_MODE mct_chan_mode; - int16_t cng_ism_flag; /* CNG in ISM format flag */ - int16_t is_ism_format; /* Indication whether the codec operates in ISM format */ + Word16 cng_ism_flag; /* CNG in ISM format flag */ + Word16 is_ism_format; /* Indication whether the codec operates in ISM format */ Word16 last_element_mode; /* element mode */ // Word16 coder_type; /* low-rate mode flag */ diff --git a/lib_dec/stat_noise_uv_dec_fx.c b/lib_dec/stat_noise_uv_dec_fx.c index c1749a536..6c7705cfc 100644 --- a/lib_dec/stat_noise_uv_dec_fx.c +++ b/lib_dec/stat_noise_uv_dec_fx.c @@ -13,12 +13,12 @@ * Modifies excitation signal in UC mode when the noise is stationary *---------------------------------------------------------*/ void stat_noise_uv_dec_fx( - Decoder_State *st_fx, /* i/o: Decoder static memory */ - Word16 *lsp_new, /* i : end-frame LSP vector */ - Word16 *lsp_mid, /* i : mid-frame LSP vector */ - Word16 *Aq, /* o : A(z) quantized for the 4 subframes */ - Word16 *exc2, /* i/o: excitation buffer */ - const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ + Decoder_State *st_fx, /* i/o: Decoder static memory */ + Word16 *lsp_new, /* i : end-frame LSP vector Q15 */ + Word16 *lsp_mid, /* i : mid-frame LSP vector Q15 */ + Word16 *Aq, /* o : A(z) quantized for the 4 subframes Q = 14 - norm_s(Aq[0]) */ + Word16 *exc2, /* i/o: excitation buffer, Q = st_fx->Q_exc */ + const Word16 uc_two_stage_flag /* i : flag indicating two-stage UC */ ) { Word16 noisiness = 0, i; diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 95a187a6e..a814ff029 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -168,7 +168,9 @@ ivas_error acelp_core_enc( // Word16 next_force_sf_bck_fx; Word32 q_env_fx[NUM_ENV_CNG]; // Word16 coder_type; - +#ifdef MSAN_FIX + set32_fx( q_env_fx, 0, NUM_ENV_CNG ); +#endif Word16 exc3_fx[L_FRAME16k]; Word16 syn1_fx[L_FRAME16k]; Word16 *tdm_Pri_pitch_buf_fx; diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 6effecd94..d601c6fa2 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -1304,12 +1304,15 @@ ivas_error ivas_core_enc( f2me_buf_16( hCPE->hStereoICBWE->shbSynthRef, hCPE->hStereoICBWE->shbSynthRef_fx, &hCPE->hStereoICBWE->shbSynthRef_e, L_LOOK_16k ); // shb_speech_ref_e f2me( hCPE->hStereoICBWE->icbweRefEner, &hCPE->hStereoICBWE->icbweRefEner_fx, &hCPE->hStereoICBWE->icbweRefEner_e ); - scale_factor = Q_factor_arrL( hCPE->hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 ) - 1; scale_factor = s_min( scale_factor, Q_factor_arrL( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, LPC_SHB_ORDER ) ); - floatToFixed_arr32( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, scale_factor, LPC_SHB_ORDER + 1 ); floatToFixed_arr32( hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref, hCPE->hStereoICBWE->mem_lpc_shbsynth_nonref_fx, scale_factor, LPC_SHB_ORDER ); +#ifdef MSAN_FIX + f2me_buf( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, &hCPE->hStereoICBWE->lpSHBRef_e, LPC_SHB_ORDER + 1 ); +#else + scale_factor = Q_factor_arrL( hCPE->hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 ) - 1; + floatToFixed_arr32( hCPE->hStereoICBWE->lpSHBRef, hCPE->hStereoICBWE->lpSHBRef_fx, scale_factor, LPC_SHB_ORDER + 1 ); hCPE->hStereoICBWE->lpSHBRef_e = 31 - scale_factor; - +#endif #endif stereo_icBWE_enc_ivas_fx( hCPE, shb_speech_fx32, 31 - q_shb_speech_fx32, new_swb_speech_buffer_fx, 31 - q_new_swb_speech_buffer, voice_factors_fx32[0] ); diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 917c185cd..3cdbd36a0 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -1091,7 +1091,19 @@ ivas_error pre_proc_front_ivas_fx( Word16 realBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 imagBuffer16[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word32 realBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#ifdef MSAN_FIX + for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + { + set32_fx( realBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); + } +#endif Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; +#ifdef MSAN_FIX + for ( Word16 k = 0; k < CLDFB_NO_COL_MAX; k++ ) + { + set32_fx( imagBuffer_fx[k], 0, CLDFB_NO_CHANNELS_MAX ); + } +#endif Word16 sf_energySum[CLDFB_NO_CHANNELS_MAX]; Word16 max_e; diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 62fb9ae70..7f79fdbc2 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -240,6 +240,9 @@ ivas_error ivas_cpe_enc( move16(); Word16 front_create_flag = 0; move16(); +#ifdef MSAN_FIX + set_f( band_energies_LR, 0, 2 * NB_BANDS ); +#endif #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( n = 0; n < CPE_CHANNELS; n++ ) { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 582595208..6777a8527 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -933,14 +933,14 @@ static ivas_error ivas_spar_cov_md_process( { for ( i = 0; i < IVAS_SPAR_MAX_CH - 1; i++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], Q22 ); - hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], Q22 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_P_re_fx ); + hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], hSpar->hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx ); } for ( i = 0; i < IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS; i++ ) { for ( j = 0; j < IVAS_SPAR_MAX_DMX_CHS - 1; j++ ) { - hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], Q22 ); + hSpar->hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hSpar->hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], hSpar->hMdEnc->spar_md.band_coeffs[b].q_C_re_fx ); } } } diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 4e8a5ba3f..13c9bdc0a 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -754,8 +754,8 @@ ivas_error ivas_spar_md_enc_process_fx( ) { Word32 pred_coeffs_re_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; - 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; Word16 i, j, b, qsi, ndm, ndec, num_ch, num_quant_strats; Word32 pred_coeffs_re_local_fx[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; Word16 k, bwidth, num_bands, num_bands_full, num_bands_bw; @@ -768,7 +768,12 @@ ivas_error ivas_spar_md_enc_process_fx( Indice *ind_list_tmp; Word16 md_indices_allocated; Word16 max_num_indices_tmp; + Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; + Word16 q_Wscale[IVAS_MAX_NUM_BANDS]; +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS float Wscale[IVAS_MAX_NUM_BANDS]; + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; +#endif /*extra 16 bits for arithmetic coder as overshoot check is after a symbol is written*/ md_indices_allocated = add( hMdEnc->spar_md_cfg.max_bits_per_blk, IVAS_SPAR_ARITH_OVERSHOOT_BITS ); @@ -919,7 +924,77 @@ ivas_error ivas_spar_md_enc_process_fx( } #endif +#ifdef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ ) + { + f2me( cov_real[i][j][k], &cov_real_fx[i][j][k], &cov_real_q[i][j][k] ); + cov_real_q[i][j][k] = 31 - cov_real_q[i][j][k]; + } + } + } + +#endif + ivas_compute_spar_params_enc_fx( cov_real_fx, cov_real_q, dm_fv_re_fx, &q_dm_fv_re, 0, hMdEnc->mixer_mat_fx, &hMdEnc->q_mixer_mat_fx, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale_fx, q_Wscale, 0, dyn_active_w_flag ); +#ifdef IVAS_FLOAT_FIXED_CONVERSIONS + for ( i = 0; i < num_ch - 1; i++ ) + { + for ( j = 0; j < nB; j++ ) + { + dm_fv_re[i][j] = fixedToFloat_32( dm_fv_re_fx[i][j], q_dm_fv_re ); + } + } + for ( i = 0; i < num_ch; i++ ) + { + for ( j = 0; j < num_ch; j++ ) + { + for ( b = 0; b < nB; b++ ) + { + hMdEnc->mixer_mat[i][j][b] = fixedToFloat_32( hMdEnc->mixer_mat_fx[i][j][b], hMdEnc->q_mixer_mat_fx ); + } + } + } + Word16 q_tmp; + for ( b = 0; b < nB; b++ ) + { + Wscale[b] = fixedToFloat_32( Wscale_fx[b], q_Wscale[b] ); + for ( i = 0; i < num_ch - 1; i++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_pred_re_fx; + hMdEnc->spar_md.band_coeffs[b].pred_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].pred_re_fx[i], q_tmp ); + } + + ndm = hMdEnc->spar_md_cfg.num_dmx_chans_per_band[b * bands_bw]; + if ( ndm != num_ch ) + { + for ( i = 0; i < num_ch - ndm; i++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_P_re_fx; + hMdEnc->spar_md.band_coeffs[b].P_re[i] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].P_re_fx[i], q_tmp ); + } + if ( ndm != 1 ) + { + for ( i = 0; i < num_ch - ndm; i++ ) + { + for ( j = 0; j < ndm - 1; j++ ) + { + q_tmp = hMdEnc->spar_md.band_coeffs[b].q_C_re_fx; + hMdEnc->spar_md.band_coeffs[b].C_re[i][j] = fixedToFloat_32( hMdEnc->spar_md.band_coeffs[b].C_re_fx[i][j], q_tmp ); + } + } + } + } + } +#endif +#else ivas_compute_spar_params( cov_real, dm_fv_re, 0, hMdEnc->mixer_mat, 0, nB, dtx_vad, num_ch, bands_bw, active_w, active_w_vlbr, &hMdEnc->spar_md_cfg, &hMdEnc->spar_md, Wscale, 0, dyn_active_w_flag ); +#endif + #ifdef IVAS_FLOAT_FIXED_CONVERSIONS for ( b = 0; b < num_bands; b++ ) { @@ -1070,7 +1145,6 @@ ivas_error ivas_spar_md_enc_process_fx( hMdEnc->spar_md.band_coeffs[b].P_quant_re[ii] = fix_to_float( hMdEnc->spar_md.band_coeffs[b].P_quant_re_fx[ii], Q28 ); } } - Word32 Wscale_fx[IVAS_MAX_NUM_BANDS]; Word16 Wscale_e, dm_fv_re_q = Q31, mixer_q = Q31; f2me_buf( Wscale, Wscale_fx, &Wscale_e, (Word32) num_bands ); diff --git a/lib_rend/ivas_efap.c b/lib_rend/ivas_efap.c index 1b0f31f9b..ddaf6a41a 100644 --- a/lib_rend/ivas_efap.c +++ b/lib_rend/ivas_efap.c @@ -2626,6 +2626,10 @@ static void efap_panning_fx( move32(); P[1] = ele; move32(); + set32_fx( tmpBuff, 0, EFAP_MAX_CHAN_NUM ); + set32_fx( aziPoly, 0, EFAP_MAX_CHAN_NUM ); + set32_fx( elePoly, 0, EFAP_MAX_CHAN_NUM ); + set16_fx( chan, 0, EFAP_MAX_CHAN_NUM ); /* Finding in which polygon the point is */ polyIdx = get_poly_num_fx( P, polyData ); diff --git a/lib_rend/ivas_objectRenderer_vec.c b/lib_rend/ivas_objectRenderer_vec.c index 5491d10bc..a83637fc2 100644 --- a/lib_rend/ivas_objectRenderer_vec.c +++ b/lib_rend/ivas_objectRenderer_vec.c @@ -142,7 +142,7 @@ void TDREND_SPATIAL_VecNormalize( #ifdef IVAS_FLOAT_FIXED void TDREND_SPATIAL_VecNormalize_fx( - const Word32 *Vec_p_fx, /* i : Input vector Qx */ + const Word32 *Vec_p_fx, /* i : Input vector q */ Word16 q, /* i : Input vector Q-factor */ Word32 *VecNorm_p_fx /* o : Normalised output vector Q30 */ ) @@ -155,21 +155,21 @@ void TDREND_SPATIAL_VecNormalize_fx( exp = shl( sub( 31, q ), 1 ); scaler_fx = ISqrt32( sqrd_sum, &exp ); - VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); + VecNorm_p_fx[0] = Mpy_32_32( scaler_fx, Vec_p_fx[0] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); - VecNorm_p_fx[1] = Mpy_32_32( scaler_fx, Vec_p_fx[1] ); + VecNorm_p_fx[1] = Mpy_32_32( scaler_fx, Vec_p_fx[1] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); - VecNorm_p_fx[2] = Mpy_32_32( scaler_fx, Vec_p_fx[2] ); + VecNorm_p_fx[2] = Mpy_32_32( scaler_fx, Vec_p_fx[2] ); // Q: ( q + ( 31 - exp ) ) - 31 move32(); exp = add( exp, sub( 31, q ) ); // Since vector is normalised, all values will be <= 1. Hence making all values in Q30 shift = sub( exp, 1 ); - VecNorm_p_fx[0] = L_shl( VecNorm_p_fx[0], shift ); + VecNorm_p_fx[0] = L_shl( VecNorm_p_fx[0], shift ); // Q30 move32(); - VecNorm_p_fx[1] = L_shl( VecNorm_p_fx[1], shift ); + VecNorm_p_fx[1] = L_shl( VecNorm_p_fx[1], shift ); // Q30 move32(); - VecNorm_p_fx[2] = L_shl( VecNorm_p_fx[2], shift ); + VecNorm_p_fx[2] = L_shl( VecNorm_p_fx[2], shift ); // Q30 move32(); return; @@ -197,11 +197,11 @@ void TDREND_SPATIAL_VecMapToNewCoordSystem_fx( v_sub_32( Vec_p, TranslVec_p, LisRelPosAbs, 3 ); /* Evalute the relative Vec in the coordinates of the Orientation vectors, */ /* which form an orthonormal basis */ - MappedVec_p[0] = dotp_fixed( LisRelPosAbs, DirVec_p, 3 ); + MappedVec_p[0] = dotp_fixed( LisRelPosAbs, DirVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); - MappedVec_p[1] = dotp_fixed( LisRelPosAbs, RightVec_p, 3 ); + MappedVec_p[1] = dotp_fixed( LisRelPosAbs, RightVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); - MappedVec_p[2] = dotp_fixed( LisRelPosAbs, UpVec_p, 3 ); + MappedVec_p[2] = dotp_fixed( LisRelPosAbs, UpVec_p, 3 ); // Q: Qy + Qy - Q31 move32(); return; } @@ -285,15 +285,15 @@ int16_t TDREND_SPATIAL_EvalOrthonormOrient( #ifdef IVAS_FLOAT_FIXED Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( - Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ - Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ - Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ - const Word32 *FrontVec_p_fx, /* i : Input front vector */ - const Word32 *UpVec_p_fx, /* i : Input up vector */ - const Word16 orient_q /* i : Input up Q-factor */ + Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ + Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ + Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ + const Word32 *FrontVec_p_fx, /* i : Input front vector Qx */ + const Word32 *UpVec_p_fx, /* i : Input up vector orient_q */ + const Word16 orient_q /* i : Input up Q-factor */ ) { - Word32 tmp_fx[9]; + Word32 tmp_fx[9]; // Q30 Word16 orientation_updated; orientation_updated = FALSE; @@ -310,22 +310,22 @@ Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( /* Evaluate the orthonormal right vector */ /* through the cross product of the front and the up vectors */ - RightVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[2] ), Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[1] ) ), 1 ); + RightVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[2] ), Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[1] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - RightVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[0] ), Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[2] ) ), 1 ); + RightVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[2], UpVec_p_fx[0] ), Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[2] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - RightVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[1] ), Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[0] ) ), 1 ); + RightVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( FrontVecON_p_fx[0], UpVec_p_fx[1] ), Mpy_32_32( FrontVecON_p_fx[1], UpVec_p_fx[0] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); TDREND_SPATIAL_VecNormalize_fx( RightVecON_p_fx, orient_q, RightVecON_p_fx ); // RightVecON_p_fx -> Q30 /* Evaluate the orthonormal up vector */ /* through the cross product of the front and the right vectors */ - UpVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1 ); + UpVecON_p_fx[0] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[2] ), Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[1] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - UpVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1 ); + UpVecON_p_fx[1] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[2], FrontVecON_p_fx[0] ), Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[2] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); - UpVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1 ); + UpVecON_p_fx[2] = L_shl_sat( L_sub( Mpy_32_32( RightVecON_p_fx[0], FrontVecON_p_fx[1] ), Mpy_32_32( RightVecON_p_fx[1], FrontVecON_p_fx[0] ) ), 1 ); // Q: ( Q30 + Q30 - Q31 ) + Q1 -> Q30 move32(); TDREND_SPATIAL_VecNormalize_fx( UpVecON_p_fx, orient_q, UpVecON_p_fx ); // UpVecON_p_fx -> Q30 diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index da163f570..1d7e191b4 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -124,7 +124,7 @@ ivas_error ivas_omasa_ana_open( Copy( MASA_band_grouping_24, hOMasa->band_grouping, 24 + 1 ); /* maxBin = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); */ - maxBin = extract_l( Mpy_32_32( input_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); + maxBin = extract_l( Mpy_32_32( input_Fs, 2684355 /* INV_CLDFB_BANDWIDTH in Q31 */ ) ); // Q: ( ( Q0 + Q31 ) - Q31 ) -> Q0 FOR( i = 1; i < hOMasa->nbands + 1; i++ ) { @@ -853,9 +853,9 @@ static void ivas_omasa_param_est_ana_fx( FOR( Word16 ind = 0; ind < CLDFB_NO_CHANNELS_MAX; ind++ ) { - Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], 4 ); + Chnl_RealBuffer_fx[i][ind] = L_shr( Chnl_RealBuffer_fx[i][ind], 4 ); // Q: in_q - 4 move32(); - Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], 4 ); + Chnl_ImagBuffer_fx[i][ind] = L_shr( Chnl_ImagBuffer_fx[i][ind], 4 ); // Q: in_q - 4 move32(); } @@ -875,8 +875,8 @@ static void ivas_omasa_param_est_ana_fx( { FOR( i = 0; i < nchan_ism; i++ ) { - L_tmp1 = Mpy_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ); - L_tmp2 = Mpy_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ); + L_tmp1 = Mpy_32_32( Chnl_RealBuffer_fx[i][j], Chnl_RealBuffer_fx[i][j] ); // Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 + L_tmp2 = Mpy_32_32( Chnl_ImagBuffer_fx[i][j], Chnl_ImagBuffer_fx[i][j] ); // Chnl_ImagBuffer_q + Chnl_ImagBuffer_q - 31 hOMasa->energy_fx[block_m_idx][band_m_idx] = L_add( hOMasa->energy_fx[block_m_idx][band_m_idx], L_add( L_tmp1, L_tmp2 ) ); // Chnl_RealBuffer_q + Chnl_RealBuffer_q - 31 move32(); hOMasa->energy_q = sub( add( Chnl_RealBuffer_q, Chnl_RealBuffer_q ), 31 ); @@ -893,39 +893,39 @@ static void ivas_omasa_param_est_ana_fx( FOR( i = 1; i < nchan_ism; i++ ) { - v_add_fixed( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0 ); - v_add_fixed( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0 ); + v_add_fixed( Chnl_RealBuffer_fx[i], Foa_RealBuffer_fx[0], Foa_RealBuffer_fx[0], num_freq_bins, 0 ); // Q: Chnl_RealBuffer_q + v_add_fixed( Chnl_ImagBuffer_fx[i], Foa_ImagBuffer_fx[0], Foa_ImagBuffer_fx[0], num_freq_bins, 0 ); // Q: Chnl_ImagBuffer_q } /* Y */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[1][0] ), Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_RealBuffer_fx[1], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[1][i], Foa_ImagBuffer_fx[1], num_freq_bins ); // Q: Chnl_ImagBuffer_q } /* Z */ - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[2][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[2][i], Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q } - v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); - v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); + v_multc_fixed( Chnl_RealBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_RealBuffer_fx[2], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_fixed( Chnl_ImagBuffer_fx[0], L_deposit_h( hOMasa->chnlToFoaMtx_fx[3][0] ), Foa_ImagBuffer_fx[2], num_freq_bins ); // Q: Chnl_ImagBuffer_q FOR( i = 1; i < nchan_ism; i++ ) { - v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); - v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); + v_multc_acc_32_16( Chnl_RealBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_RealBuffer_fx[3], num_freq_bins ); // Q: Chnl_RealBuffer_q + v_multc_acc_32_16( Chnl_ImagBuffer_fx[i], hOMasa->chnlToFoaMtx_fx[3][i], Foa_ImagBuffer_fx[3], num_freq_bins ); // Q: Chnl_ImagBuffer_q } /* Direction estimation */ @@ -933,9 +933,9 @@ static void ivas_omasa_param_est_ana_fx( { FOR( j = 0; j < CLDFB_NO_CHANNELS_MAX; j++ ) { - Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); + Foa_RealBuffer_fx[i][j] = L_shr( Foa_RealBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) move32(); - Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); + Foa_ImagBuffer_fx[i][j] = L_shr( Foa_ImagBuffer_fx[i][j], 5 ); // Q: ( Chnl_RealBuffer_q - 5 ) move32(); } } @@ -948,7 +948,7 @@ static void ivas_omasa_param_est_ana_fx( /* Power estimation for diffuseness */ - computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx, num_freq_bands ); // 2*inputq - 30 + computeReferencePower_ana_fx( hOMasa->band_grouping, Foa_RealBuffer_fx, Foa_ImagBuffer_fx, reference_power_fx, num_freq_bands ); // 2 * inputq - 30 reference_power_q = sub( shl( Chnl_ImagBuffer_q, 1 ), 30 ); /* Fill buffers of length "averaging_length" time slots for intensity and energy */ @@ -960,33 +960,33 @@ static void ivas_omasa_param_est_ana_fx( FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { /* only real part needed */ - Copy32( intensity_real_fx[i], &( hOMasa->buffer_intensity_real_fx[i][sub( index, 1 )][0] ), num_freq_bands ); + Copy32( intensity_real_fx[i], &( hOMasa->buffer_intensity_real_fx[i][index - 1][0] ), num_freq_bands ); // intensity_q } - hOMasa->buffer_intensity_real_q[sub( index, 1 )] = intensity_q; + hOMasa->buffer_intensity_real_q[index - 1] = intensity_q; move16(); - Copy32( reference_power_fx, &( hOMasa->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); - hOMasa->buffer_energy_q[sub( index, 1 )] = reference_power_q; + Copy32( reference_power_fx, &( hOMasa->buffer_energy_fx[( index - 1 ) * num_freq_bands] ), num_freq_bands ); + hOMasa->buffer_energy_q[index - 1] = reference_power_q; move16(); computeDiffuseness_fixed( hOMasa->buffer_intensity_real_fx, hOMasa->buffer_energy_fx, num_freq_bands, diffuseness_vector_fx, hOMasa->buffer_intensity_real_q, hOMasa->buffer_energy_q, &diffuseness_q ); FOR( band_m_idx = 0; band_m_idx < hOMasa->nbands; band_m_idx++ ) { - norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( 1073741824, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 + norm_tmp_fx = Mpy_32_32( reference_power_fx[band_m_idx], L_sub( ONE_IN_Q30, diffuseness_vector_fx[band_m_idx] ) ); // reference_power_q + 30 - 31 norm_tmp_q = sub( add( reference_power_q, 30 ), 31 ); - hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[0][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); - hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[1][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[1][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); - hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); + hOMasa->direction_vector_m_fx[2][block_m_idx][band_m_idx] = L_add( hOMasa->direction_vector_m_fx[0][block_m_idx][band_m_idx], Mpy_32_32( norm_tmp_fx, direction_vector_fx[2][band_m_idx] ) ); // Q: hOMasa->direction_vector_m_q: ( ( norm_tmp_q + direction_q ) - 31 ) move32(); hOMasa->direction_vector_m_q = sub( add( norm_tmp_q, direction_q ), 31 ); - diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[band_m_idx], diffuseness_vector_fx[band_m_idx] ) ); + diffuseness_m_fx[band_m_idx] = L_add( diffuseness_m_fx[band_m_idx], Mpy_32_32( reference_power_fx[band_m_idx], diffuseness_vector_fx[band_m_idx] ) ); // diffuseness_m_q: ( ( reference_power_q + diffuseness_q ) - 31 ); move32(); diffuseness_m_q = sub( add( reference_power_q, diffuseness_q ), 31 ); renormalization_factor_diff_fx[band_m_idx] = L_add( renormalization_factor_diff_fx[band_m_idx], reference_power_fx[band_m_idx] ); @@ -1033,7 +1033,7 @@ static void ivas_omasa_param_est_ana_fx( diffuseness_m_fx[band_m_idx] = 0; move32(); } - energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); + energyRatio_fx[block_m_idx][band_m_idx] = L_sub( L_shl( 1, diffuseness_m_q ), diffuseness_m_fx[band_m_idx] ); // Q: diffuseness_m_q move32(); } @@ -1092,8 +1092,8 @@ static void ivas_omasa_dmx_fx( FOR( i = 0; i < nchan_ism; i++ ) { - azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); - elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); + azimuth_fx = extract_l( L_shr( ism_azimuth_fx[i], Q22 ) ); // Q0 + elevation_fx = extract_l( L_shr( ism_elevation_fx[i], Q22 ) ); // Q0 ivas_ism_get_stereo_gains_fx( azimuth_fx, elevation_fx, &gains_fx[0], &gains_fx[1] ); @@ -1111,10 +1111,10 @@ static void ivas_omasa_dmx_fx( scale = BASOP_Util_Add_MantExp( 16384, 1, negate( g1_fx ), 0, &g2_fx ); tmp1 = mult( g1_fx, gains_fx[j] ); - tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); + tmp2 = mult( g2_fx, (Word16) L_shr( prev_gains_fx[i][j], 16 ) ); // Q: ( ( ( 15 - scale ) + ( Q31 - Q16 ) ) - Q15 ) -> ( 15 - scale ) scale = BASOP_Util_Add_MantExp( tmp1, 0, tmp2, scale, &tmp1 ); - L_tmp = data_in_f_fx[i][k]; + L_tmp = data_in_f_fx[i][k]; // data_in_q move32(); tmp_e = sub( 31, *data_in_q ); move16(); @@ -1139,7 +1139,7 @@ static void ivas_omasa_dmx_fx( FOR( l = 0; l < L_FRAME48k; l++ ) { - data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); + data_out_f_fx[j][l] = L_shr( data_out_f_fx[j][l], sub( max_e, in_e[l] ) ); // exponent: max_e, Q: ( 15 - max_e ) move32(); } data_e[j] = max_e; @@ -1165,7 +1165,7 @@ static void ivas_omasa_dmx_fx( { FOR( j = 0; j < input_frame; j++ ) { - data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], sub( max_e, data_e[i] ) ); + data_out_f_fx[i][j] = L_shr( data_out_f_fx[i][j], sub( max_e, data_e[i] ) ); // exponent: max_e, Q: ( 15 - max_e ) move32(); } } @@ -1245,11 +1245,11 @@ static void ivas_omasa_dmx( *--------------------------------------------------------------------------*/ void computeIntensityVector_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Qx */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input sig Qx */ + const Word16 num_frequency_bands, /* i : Number of frequency bands */ + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity 2 * Qx -31 */ ) { /* Reminder @@ -1276,14 +1276,14 @@ void computeIntensityVector_ana_fx( FOR( j = brange[0]; j < brange[1]; j++ ) { - real = Cldfb_RealBuffer[0][j]; - img = Cldfb_ImagBuffer[0][j]; + real = Cldfb_RealBuffer[0][j]; // Qx + img = Cldfb_ImagBuffer[0][j]; // Qx /* Intensity is XYZ order, audio is WYZX order. */ - intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[0][i] = L_add( intensity_real[0][i], L_add( Mpy_32_32( Cldfb_RealBuffer[3][j], real ), Mpy_32_32( Cldfb_ImagBuffer[3][j], img ) ) ); // output Q = 2 * Qx -31 move32(); - intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[1][i] = L_add( intensity_real[1][i], L_add( Mpy_32_32( Cldfb_RealBuffer[1][j], real ), Mpy_32_32( Cldfb_ImagBuffer[1][j], img ) ) ); // output Q = 2 * Qx -31 move32(); - intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q= 2* input_q -31 + intensity_real[2][i] = L_add( intensity_real[2][i], L_add( Mpy_32_32( Cldfb_RealBuffer[2][j], real ), Mpy_32_32( Cldfb_ImagBuffer[2][j], img ) ) ); // output Q = 2 * Qx -31 move32(); } } @@ -1345,11 +1345,11 @@ void computeIntensityVector_ana( *--------------------------------------------------------------------------*/ void computeReferencePower_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - Word32 *reference_power, /* o : Estimated power */ - const Word16 num_freq_bands /* i : Number of frequency bands */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal input_q */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal input_q */ + Word32 *reference_power, /* o : Estimated power 2 * inputq - 31 */ + const Word16 num_freq_bands /* i : Number of frequency bands */ ) { Word16 brange[2]; diff --git a/lib_rend/ivas_orient_trk.c b/lib_rend/ivas_orient_trk.c index 7cc330e67..334f52ee3 100644 --- a/lib_rend/ivas_orient_trk.c +++ b/lib_rend/ivas_orient_trk.c @@ -125,13 +125,13 @@ void QuaternionProduct_fx( IVAS_QUATERNION tmp; // once verify// - tmp.w_fx = L_sub( ( L_sub( Mpy_32_32( q1.w_fx, q2.w_fx ), Mpy_32_32( q1.x_fx, q2.x_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.y_fx ), Mpy_32_32( q1.z_fx, q2.z_fx ) ) ) ); + tmp.w_fx = L_sub( ( L_sub( Mpy_32_32( q1.w_fx, q2.w_fx ), Mpy_32_32( q1.x_fx, q2.x_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.y_fx ), Mpy_32_32( q1.z_fx, q2.z_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.x_fx = L_add( ( L_add( Mpy_32_32( q1.w_fx, q2.x_fx ), Mpy_32_32( q1.x_fx, q2.w_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.z_fx ), Mpy_32_32( q1.z_fx, q2.y_fx ) ) ) ); + tmp.x_fx = L_add( ( L_add( Mpy_32_32( q1.w_fx, q2.x_fx ), Mpy_32_32( q1.x_fx, q2.w_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.z_fx ), Mpy_32_32( q1.z_fx, q2.y_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.y_fx = L_add( ( L_sub( Mpy_32_32( q1.w_fx, q2.y_fx ), Mpy_32_32( q1.x_fx, q2.z_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.w_fx ), Mpy_32_32( q1.z_fx, q2.x_fx ) ) ) ); + tmp.y_fx = L_add( ( L_sub( Mpy_32_32( q1.w_fx, q2.y_fx ), Mpy_32_32( q1.x_fx, q2.z_fx ) ) ), ( L_add( Mpy_32_32( q1.y_fx, q2.w_fx ), Mpy_32_32( q1.z_fx, q2.x_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); - tmp.z_fx = L_sub( ( L_add( Mpy_32_32( q1.w_fx, q2.z_fx ), Mpy_32_32( q1.x_fx, q2.y_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.x_fx ), Mpy_32_32( q1.z_fx, q2.w_fx ) ) ) ); + tmp.z_fx = L_sub( ( L_add( Mpy_32_32( q1.w_fx, q2.z_fx ), Mpy_32_32( q1.x_fx, q2.y_fx ) ) ), ( L_sub( Mpy_32_32( q1.y_fx, q2.x_fx ), Mpy_32_32( q1.z_fx, q2.w_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 move32(); tmp.q_fact = sub( add( q1.q_fact, q2.q_fact ), 31 ); move16(); @@ -164,7 +164,7 @@ static Word32 QuaternionDotProduct_fx( Word32 result = 0; move32(); - result = L_add( ( L_add( Mpy_32_32( q1.x_fx, q2.x_fx ), Mpy_32_32( q1.y_fx, q2.y_fx ) ) ), ( L_add( Mpy_32_32( q1.z_fx, q2.z_fx ), Mpy_32_32( q1.w_fx, q2.w_fx ) ) ) ); + result = L_add( ( L_add( Mpy_32_32( q1.x_fx, q2.x_fx ), Mpy_32_32( q1.y_fx, q2.y_fx ) ) ), ( L_add( Mpy_32_32( q1.z_fx, q2.z_fx ), Mpy_32_32( q1.w_fx, q2.w_fx ) ) ) ); // ( q1.q_fact + q2.q_fact ) - 31 *q_fact = sub( add( q1.q_fact, q2.q_fact ), 31 ); move16(); @@ -223,13 +223,13 @@ static void QuaternionDivision_fx( result_q = sub( s_min( s_min( w_q, x_q ), s_min( y_q, z_q ) ), 1 ); // gaurdbits// - r->w_fx = L_shr( r->w_fx, sub( w_q, result_q ) ); + r->w_fx = L_shr( r->w_fx, sub( w_q, result_q ) ); // result_q move32(); - r->x_fx = L_shr( r->x_fx, sub( x_q, result_q ) ); + r->x_fx = L_shr( r->x_fx, sub( x_q, result_q ) ); // result_q move32(); - r->y_fx = L_shr( r->y_fx, sub( y_q, result_q ) ); + r->y_fx = L_shr( r->y_fx, sub( y_q, result_q ) ); // result_q move32(); - r->z_fx = L_shr( r->z_fx, sub( z_q, result_q ) ); + r->z_fx = L_shr( r->z_fx, sub( z_q, result_q ) ); // result_q move32(); r->q_fact = result_q; move16(); @@ -355,21 +355,21 @@ void QuaternionSlerp_fx( cosPhi = QuaternionDotProduct_fx( r1, r2, &q_dot ); q_min = s_min( r1.q_fact, r2.q_fact ); - r1.w_fx = L_shr( r1.w_fx, sub( r1.q_fact, q_min ) ); + r1.w_fx = L_shr( r1.w_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.x_fx = L_shr( r1.x_fx, sub( r1.q_fact, q_min ) ); + r1.x_fx = L_shr( r1.x_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.y_fx = L_shr( r1.y_fx, sub( r1.q_fact, q_min ) ); + r1.y_fx = L_shr( r1.y_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r1.z_fx = L_shr( r1.z_fx, sub( r1.q_fact, q_min ) ); + r1.z_fx = L_shr( r1.z_fx, sub( r1.q_fact, q_min ) ); // q_min move32(); - r2.w_fx = L_shr( r2.w_fx, sub( r2.q_fact, q_min ) ); + r2.w_fx = L_shr( r2.w_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.x_fx = L_shr( r2.x_fx, sub( r2.q_fact, q_min ) ); + r2.x_fx = L_shr( r2.x_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.y_fx = L_shr( r2.y_fx, sub( r2.q_fact, q_min ) ); + r2.y_fx = L_shr( r2.y_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); - r2.z_fx = L_shr( r2.z_fx, sub( r2.q_fact, q_min ) ); + r2.z_fx = L_shr( r2.z_fx, sub( r2.q_fact, q_min ) ); // q_min move32(); r1.q_fact = r2.q_fact = q_min; move16(); @@ -406,7 +406,7 @@ void QuaternionSlerp_fx( } ELSE { - temp_32 = L_sub( L_shr( ONE_IN_Q31, sub( 62, 2 * q_dot ) ), ( Mpy_32_32( cosPhi, cosPhi ) ) ); + temp_32 = L_sub( L_shr( ONE_IN_Q31, sub( 62, shl( q_dot, 1 ) ) ), ( Mpy_32_32( cosPhi, cosPhi ) ) ); // exp: sin_e sin_e = sub( 62, shl( q_dot, 1 ) ); sinPhi = Sqrt32( temp_32, &sin_e ); @@ -416,10 +416,12 @@ void QuaternionSlerp_fx( temp_16 = extract_h( temp_32 ); // Q13 s1 = getSineWord16R2( mult( temp_16, 20860 ) ); // Q15 + // 2 / pi in Q15 -> 20860 temp_32 = L_shl( Mpy_32_16_1( t_fx, phi ), 1 ); // Q29 temp_16 = extract_h( temp_32 ); // Q13 s2 = getSineWord16R2( mult( temp_16, 20860 ) ); // Q15 + // 2 / pi in Q15 -> 20860 tmp_quat.w_fx = L_add( Mpy_32_16_1( r1.w_fx, s1 ), Mpy_32_16_1( r2.w_fx, s2 ) ); // q_min move32(); @@ -606,11 +608,11 @@ static IVAS_VECTOR3 VectorSubtract_fx( z_qfact = sub( 31, e_result ); q_result = sub( s_min( s_min( x_qfact, y_qfact ), z_qfact ), 1 ); // guardbit// - result.x_fx = L_shr( result.x_fx, sub( x_qfact, q_result ) ); + result.x_fx = L_shr( result.x_fx, sub( x_qfact, q_result ) ); // q_result move32(); - result.y_fx = L_shr( result.y_fx, sub( y_qfact, q_result ) ); + result.y_fx = L_shr( result.y_fx, sub( y_qfact, q_result ) ); // q_result move32(); - result.z_fx = L_shr( result.z_fx, sub( z_qfact, q_result ) ); + result.z_fx = L_shr( result.z_fx, sub( z_qfact, q_result ) ); // q_result move32(); result.q_fact = q_result; move16(); @@ -645,11 +647,11 @@ static IVAS_VECTOR3 VectorCrossProduct_fx( { IVAS_VECTOR3 result_fx; - result_fx.x_fx = L_sub( Mpy_32_32( p1.y_fx, p2.z_fx ), Mpy_32_32( p1.z_fx, p2.y_fx ) ); + result_fx.x_fx = L_sub( Mpy_32_32( p1.y_fx, p2.z_fx ), Mpy_32_32( p1.z_fx, p2.y_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); - result_fx.y_fx = L_sub( Mpy_32_32( p1.z_fx, p2.x_fx ), Mpy_32_32( p1.x_fx, p2.z_fx ) ); + result_fx.y_fx = L_sub( Mpy_32_32( p1.z_fx, p2.x_fx ), Mpy_32_32( p1.x_fx, p2.z_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); - result_fx.z_fx = L_sub( Mpy_32_32( p1.x_fx, p2.y_fx ), Mpy_32_32( p1.y_fx, p2.x_fx ) ); + result_fx.z_fx = L_sub( Mpy_32_32( p1.x_fx, p2.y_fx ), Mpy_32_32( p1.y_fx, p2.x_fx ) ); // Q: ( p1.q_fact + p2.q_fact ) - 31 move32(); result_fx.q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); move16(); @@ -680,7 +682,7 @@ static Word32 VectorDotProduct_fx( Word32 result_fx = 0; move32(); - result_fx = L_add( L_add( Mpy_32_32( p1.x_fx, p2.x_fx ), Mpy_32_32( p1.y_fx, p2.y_fx ) ), Mpy_32_32( p1.z_fx, p2.z_fx ) ); + result_fx = L_add( L_add( Mpy_32_32( p1.x_fx, p2.x_fx ), Mpy_32_32( p1.y_fx, p2.y_fx ) ), Mpy_32_32( p1.z_fx, p2.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 *q_fact = sub( add( p1.q_fact, p2.q_fact ), 31 ); move16(); @@ -707,7 +709,7 @@ static Word32 VectorLength_fx( { Word32 result_fx = 0; move32(); - result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); + result_fx = L_add( L_add( Mpy_32_32( p.x_fx, p.x_fx ), Mpy_32_32( p.y_fx, p.y_fx ) ), Mpy_32_32( p.z_fx, p.z_fx ) ); // // Q: ( p1.q_fact + p2.q_fact ) - 31 *q_fact = sub( add( p.q_fact, p.q_fact ), 31 ); move16(); @@ -758,11 +760,11 @@ static IVAS_VECTOR3 VectorNormalize_fx( z_qfact = sub( Q31, add( scale, sub( q_len, p.q_fact ) ) ); q_result = s_min( s_min( x_qfact, y_qfact ), z_qfact ); - result_fx.x_fx = L_shr( result_fx.x_fx, sub( x_qfact, q_result ) ); + result_fx.x_fx = L_shr( result_fx.x_fx, sub( x_qfact, q_result ) ); // Q: q_result move32(); - result_fx.y_fx = L_shr( result_fx.y_fx, sub( y_qfact, q_result ) ); + result_fx.y_fx = L_shr( result_fx.y_fx, sub( y_qfact, q_result ) ); // Q: q_result move32(); - result_fx.z_fx = L_shr( result_fx.z_fx, sub( z_qfact, q_result ) ); + result_fx.z_fx = L_shr( result_fx.z_fx, sub( z_qfact, q_result ) ); // Q: q_result move32(); result_fx.q_fact = q_result; move16(); @@ -1411,7 +1413,7 @@ ivas_error ivas_orient_trk_Process_fx( Word32 cutoffFrequency_fx, cutoff_prod; Word16 q_cutoff_prod = 0; move16(); - Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub( Q30, pOTR->Q_alpha ) ); + Word32 alpha_fx = L_shl( pOTR->alpha_fx, sub( Q30, pOTR->Q_alpha ) ); // Q30 test(); IF( pOTR == NULL || pTrkRot == NULL ) @@ -1460,7 +1462,7 @@ ivas_error ivas_orient_trk_Process_fx( move16(); Word16 temp_result = BASOP_Util_Divide3232_Scale( angle_fx, pOTR->adaptationAngle_fx, &result_e ); relativeOrientationRate_fx = L_deposit_h( temp_result ); - Word32 one_fx = 1073741824; + Word32 one_fx = ONE_IN_Q30; move32(); IF( GT_32( relativeOrientationRate_fx, one_fx ) ) @@ -1493,7 +1495,7 @@ ivas_error ivas_orient_trk_Process_fx( temp_diff = sub( 31, q_cutoff_prod ); cutoff_prod = L_shl( cutoff_prod, temp_diff ); /* Compute adaptivity cutoff frequency: interpolate between minimum (center) and maximum (off-center) values */ - cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); + cutoffFrequency_fx = L_add( pOTR->centerAdaptationRate_fx, cutoff_prod ); // Q31 cutoff_prod = Mpy_32_32( cutoffFrequency_fx, PI2_C_Q28 ); q_cutoff_prod = ( ( 31 + 28 ) - 31 ); temp_result = BASOP_Util_Divide3232_Scale( cutoff_prod, updateRate_fx, &result_e ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index b3dde9603..a3c6d0e1b 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1552,12 +1552,12 @@ void TDREND_SPATIAL_VecMapToNewCoordSystem( #ifdef IVAS_FLOAT_FIXED Word16 TDREND_SPATIAL_EvalOrthonormOrient_fx( - Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ - Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ - Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ - const Word32 *FrontVec_p_fx, /* i : Input front vector */ - const Word32 *UpVec_p_fx, /* i : Input up vector */ - const Word16 orient_q /* i : Input up Q-factor */ + Word32 *FrontVecON_p_fx, /* i/o: Normalized front vector Q30 */ + Word32 *UpVecON_p_fx, /* i/o: Normalized up vector Q30 */ + Word32 *RightVecON_p_fx, /* i/o: Normalized right vector Q30 */ + const Word32 *FrontVec_p_fx, /* i : Input front vector Qx */ + const Word32 *UpVec_p_fx, /* i : Input up vector orient_q */ + const Word16 orient_q /* i : Input up Q-factor */ ); #endif /*! r: Flag if the orientation has been updated */ @@ -2751,11 +2751,11 @@ void ivas_omasa_ana_close( ); #ifdef IVAS_FLOAT_FIXED void computeIntensityVector_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - const Word16 num_frequency_bands, /* i : Number of frequency bands */ - Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Qx */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal Qx */ + const Word16 num_frequency_bands, /* i : Number of frequency bands */ + Word32 intensity_real[DIRAC_NUM_DIMS][MASA_FREQUENCY_BANDS] /* o : Intensity vector 2 * Qx -31 */ ); #endif void computeIntensityVector_ana( @@ -2767,11 +2767,11 @@ void computeIntensityVector_ana( ); #ifdef IVAS_FLOAT_FIXED void computeReferencePower_ana_fx( - const Word16 *band_grouping, /* i : Band grouping for estimation */ - Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal */ - Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal */ - Word32 *reference_power, /* o : Estimated power */ - const Word16 num_freq_bands /* i : Number of frequency bands */ + const Word16 *band_grouping, /* i : Band grouping for estimation */ + Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal input_q */ + Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Imag part of input signal input_q */ + Word32 *reference_power, /* o : Estimated power */ + const Word16 num_freq_bands /* i : Number of frequency bands 2 * input_q - 31 */ ); #endif void computeReferencePower_ana( diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index caaea5173..3012dad11 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -1155,7 +1155,7 @@ const float ivas_reverb_default_DSR[IVAS_REVERB_DEFAULT_N_BANDS] = 6.2001e-08f, 2.8483e-08f, 2.6267e-08f }; -Word32 release_cnst_table[4][201] = // Q31 +const Word32 release_cnst_table[4][201] = // Q31 { { 1913946752, diff --git a/lib_rend/ivas_rom_rend.h b/lib_rend/ivas_rom_rend.h index 904078982..ff45a7955 100644 --- a/lib_rend/ivas_rom_rend.h +++ b/lib_rend/ivas_rom_rend.h @@ -49,15 +49,15 @@ extern const float diffuse_response_CICP6[5]; extern const float diffuse_response_CICP14[7]; extern const float diffuse_response_CICP16[9]; #else -extern const Word32 ls_azimuth_4d4_fx[8]; -extern const Word32 ls_elevation_4d4_fx[8]; -extern const Word16 diffuse_response_CICP6_fx[5]; -extern const Word16 diffuse_response_CICP14_fx[7]; -extern const Word16 diffuse_response_CICP16_fx[9]; +extern const Word32 ls_azimuth_4d4_fx[8]; /*Q-22*/ +extern const Word32 ls_elevation_4d4_fx[8]; /*Q-22*/ +extern const Word16 diffuse_response_CICP6_fx[5]; /*Q-15*/ +extern const Word16 diffuse_response_CICP14_fx[7]; /*Q-15*/ +extern const Word16 diffuse_response_CICP16_fx[9]; /*Q-15*/ #endif -extern const int16_t ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; -extern const int16_t ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 ap_pre_delay[DIRAC_DECORR_NUM_SPLIT_BANDS]; +extern const Word16 ap_filter_length[DIRAC_DECORR_NUM_SPLIT_BANDS]; #ifndef IVAS_FLOAT_FIXED extern const float ap_lattice_delta_phi[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; extern const float ap_lattice_coeffs_1[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; @@ -66,26 +66,26 @@ extern const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM extern const float *const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS]; extern const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; #else -extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; -extern const Word16 ap_lattice_coeffs_1_fx[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; -extern const Word16 ap_lattice_coeffs_2_fx[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; -extern const Word16 ap_lattice_coeffs_3_fx[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; +extern const Word16 ap_lattice_delta_phi_fx[DIRAC_MAX_NUM_DECORR_FILTERS * DIRAC_MAX_DECORR_FILTER_LEN]; /*Q-14*/ +extern const Word16 ap_lattice_coeffs_1_fx[DIRAC_DECORR_FILTER_LEN_1 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ +extern const Word16 ap_lattice_coeffs_2_fx[DIRAC_DECORR_FILTER_LEN_2 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ +extern const Word16 ap_lattice_coeffs_3_fx[DIRAC_DECORR_FILTER_LEN_3 * DIRAC_MAX_NUM_DECORR_FILTERS]; /*Q-15*/ extern const Word16 *const ap_lattice_coeffs_fx[DIRAC_DECORR_NUM_SPLIT_BANDS]; -extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; +extern const Word16 ap_split_frequencies_fx[DIRAC_DECORR_NUM_SPLIT_BANDS + 1]; /*Q-14*/ #endif -extern const int16_t sba_map_tc[11]; -extern const int16_t sba_map_tc_512[11]; +extern const Word16 sba_map_tc[11]; /*Q-0*/ +extern const Word16 sba_map_tc_512[11]; /*Q-0*/ /*----------------------------------------------------------------------------------* * FASTCONV and PARAMETRIC binaural renderer ROM tables *----------------------------------------------------------------------------------*/ -extern const int16_t channelIndex_CICP6[5]; -extern const int16_t channelIndex_CICP12[7]; -extern const int16_t channelIndex_CICP14[7]; -extern const int16_t channelIndex_CICP16[9]; -extern const int16_t channelIndex_CICP19[11]; +extern const Word16 channelIndex_CICP6[5]; /*Q-0*/ +extern const Word16 channelIndex_CICP12[7]; /*Q-0*/ +extern const Word16 channelIndex_CICP14[7]; /*Q-0*/ +extern const Word16 channelIndex_CICP16[9]; /*Q-0*/ +extern const Word16 channelIndex_CICP19[11]; /*Q-0*/ #ifndef IVAS_FLOAT_FIXED /* These are equalization values for spread and surround coherent sounds, approximating the spectrum @@ -104,17 +104,17 @@ extern const float diffuseFieldCoherenceDifferenceZ[BINAURAL_COHERENCE_DIFFERENC #else /* These are equalization values for spread and surround coherent sounds, approximating the spectrum * for such sounds at anechoic multichannel listening. */ -extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; -extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; +extern const Word16 surCohEne_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-13*/ +extern const Word16 spreadCohEne05_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-13*/ +extern const Word16 spreadCohEne1_fx[MASA_NUM_DEFINED_SUR_SPR_COH_ENE_BINS]; /*Q-14*/ /* Values for low-bit-rate equalization */ -extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; +extern const Word32 lowBitRateBinauralEQ_fx[LOW_BIT_RATE_BINAURAL_EQ_BINS]; /*Q-31*/ /* Diffuse field binaural coherence directional adjustment values */ -extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; -extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; -extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; +extern const Word32 diffuseFieldCoherenceDifferenceX_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ +extern const Word32 diffuseFieldCoherenceDifferenceY_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ +extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFERENCE_BINS]; /*Q-31*/ #endif // IVAS_FLOAT_FIXED @@ -122,7 +122,7 @@ extern const Word32 diffuseFieldCoherenceDifferenceZ_fx[BINAURAL_COHERENCE_DIFFE * TD ISM Object renderer *----------------------------------------------------------------------------------*/ -extern const int16_t HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; +extern const Word16 HRTF_MODEL_N_CPTS_VAR[HRTF_MODEL_N_SECTIONS]; #ifndef IVAS_FLOAT_FIXED extern const float SincTable[321]; @@ -166,27 +166,27 @@ extern const float t_design_11_azimuth[70]; extern const float t_design_11_elevation[70]; #else /* SN3D norm (Fixed) */ -extern const Word32 norm_sn3d_hoa3_int[16]; +extern const Word32 norm_sn3d_hoa3_int[16]; /*Q-29*/ /* Order 11 t-design (Fixed) */ -extern const Word32 t_design_11_azimuth_int[70]; -extern const Word32 t_design_11_elevation_int[70]; +extern const Word32 t_design_11_azimuth_int[70]; /*Q-22*/ +extern const Word32 t_design_11_elevation_int[70]; /*Q-22*/ #endif /*----------------------------------------------------------------------* * Reverberator ROM tables *-----------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED -extern const Word32 ivas_reverb_default_fc_fx[]; -extern const Word32 ivas_reverb_default_RT60_fx[]; -extern const Word32 ivas_reverb_default_DSR_fx[]; +extern const Word32 ivas_reverb_default_fc_fx[]; /*Q-16*/ +extern const Word32 ivas_reverb_default_RT60_fx[]; /*Q-26*/ +extern const Word32 ivas_reverb_default_DSR_fx[]; /*Q-30*/ #endif extern const float ivas_reverb_default_fc[]; extern const float ivas_reverb_default_RT60[]; extern const float ivas_reverb_default_DSR[]; -extern Word32 release_cnst_table[4][201]; // Q31 +extern const Word32 release_cnst_table[4][201]; // Q31 /*----------------------------------------------------------------------------------* * Renderer SBA & MC enc/dec matrices @@ -208,8 +208,8 @@ extern const float ls_conversion_cicpX_stereo[12][2]; /* Mapping table of input config : output config with corresponding matrix */ extern const LS_CONVERSION_MAPPING ls_conversion_mapping[]; #else -extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; -extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; +extern const Word32 ls_conversion_cicpX_mono_fx[12][1]; /*Q-30*/ +extern const Word32 ls_conversion_cicpX_stereo_fx[12][2]; /*Q-30*/ /* Mapping table of input config : output config with corresponding matrix */ extern const LS_CONVERSION_MAPPING_FX ls_conversion_mapping_fx[]; diff --git a/lib_rend/ivas_rotation.c b/lib_rend/ivas_rotation.c index 874fa8bf0..e68653484 100644 --- a/lib_rend/ivas_rotation.c +++ b/lib_rend/ivas_rotation.c @@ -272,7 +272,7 @@ void QuatToRotMat_fx( Word32 Rmat[3][3] /* o : real-space rotation matrix for this rotation 2*Qx-32 */ ) { - Word32 w = quat.w_fx; + Word32 w = quat.w_fx; // Qx move32(); Word32 x = quat.x_fx; move32(); @@ -288,7 +288,7 @@ void QuatToRotMat_fx( Word32 yy = L_shr( Mpy_32_32( y, y ), 1 ); Word32 zz = L_shr( Mpy_32_32( z, z ), 1 ); - Word32 wx = Mpy_32_32( w, x ); + Word32 wx = Mpy_32_32( w, x ); // 2 * Qx - 31 Word32 wz = Mpy_32_32( w, z ); Word32 wy = Mpy_32_32( w, y ); @@ -297,21 +297,21 @@ void QuatToRotMat_fx( Word32 yz = Mpy_32_32( y, z ); - Rmat[0][0] = L_sub( L_sub( L_add( ww, xx ), yy ), zz ); + Rmat[0][0] = L_sub( L_sub( L_add( ww, xx ), yy ), zz ); // 2 * Qx - 31 - 1 = 2*Qx-32 move32(); Rmat[0][1] = L_sub( xy, wz ); move32(); Rmat[0][2] = L_add( xz, wy ); move32(); - Rmat[1][0] = L_add( xy, wz ); + Rmat[1][0] = L_add( xy, wz ); // 2 * Qx - 32 move32(); Rmat[1][1] = L_sub( L_add( L_sub( ww, xx ), yy ), zz ); move32(); Rmat[1][2] = L_sub( yz, wx ); move32(); - Rmat[2][0] = L_sub( xz, wy ); + Rmat[2][0] = L_sub( xz, wy ); // 2 * Qx - 32 move32(); Rmat[2][1] = L_add( yz, wx ); move32(); @@ -372,13 +372,13 @@ void Euler2Quat( #else void Euler2Quat_fx( - const Word32 yaw, /* i : yaw (x) */ - const Word32 pitch, /* i : pitch (y) */ - const Word32 roll, /* i : roll (z) */ - IVAS_QUATERNION *quat /* o : quaternion describing the rotation */ + const Word32 yaw, /* i : yaw (x) Q22 */ + const Word32 pitch, /* i : pitch (y) Q22 */ + const Word32 roll, /* i : roll (z) Q22 */ + IVAS_QUATERNION *quat /* o : quaternion describing the rotation Q19 */ ) { - Word16 cr = getCosWord16( extract_l( L_shr_r( roll, 10 ) ) ); + Word16 cr = getCosWord16( extract_l( L_shr_r( roll, 10 ) ) ); // Q14 Word16 sr = getSinWord16( extract_l( L_shr_r( roll, 10 ) ) ); Word16 cp = getCosWord16( extract_l( L_shr_r( pitch, 10 ) ) ); Word16 sp = getSinWord16( extract_l( L_shr_r( pitch, 10 ) ) ); @@ -487,7 +487,7 @@ void rotateAziEle_fx( Word16 *azi, /* o : rotated azimuth Q0 */ Word16 *ele, /* o : rotated elevation Q0 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30*/ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n; @@ -511,19 +511,19 @@ void rotateAziEle_fx( } temp_16 = ele_in; move16(); - w_fx = cosine_table_Q31[abs_s( temp_16 )]; + w_fx = cosine_table_Q31[abs_s( temp_16 )]; // Q31 move32(); temp_16 = azi_in; move16(); - dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); + dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); // Q31 move32(); temp_16 = azi_in; move16(); - dv_fx[1] = Mpy_32_32( w_fx, sine_table_Q31[add( temp_16, 180 )] ); + dv_fx[1] = Mpy_32_32( w_fx, sine_table_Q31[add( temp_16, 180 )] ); // Q31 move32(); temp_16 = ele_in; move16(); - dv_fx[2] = sine_table_Q31[add( temp_16, 180 )]; + dv_fx[2] = sine_table_Q31[add( temp_16, 180 )]; // Q31 move32(); /*Rotation mtx multiplication*/ FOR( n = 0; n < 3; n++ ) @@ -538,7 +538,7 @@ void rotateAziEle_fx( move32(); x = dv_r_fx[0]; move32(); - radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); + radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); // Q14 if ( y <= 0 ) { @@ -549,11 +549,11 @@ void rotateAziEle_fx( { IF( radian < 0 ) { - angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); // Q0 } ELSE { - angle = sub( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = sub( 180, extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); // Q0 } IF( radian == 0 ) { @@ -565,7 +565,7 @@ void rotateAziEle_fx( } ELSE { - angle = extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 24 ) ); + angle = extract_l( L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 24 ) ); // Q0 } *azi = s_max( -180, min( 180, angle ) ); @@ -578,7 +578,7 @@ void rotateAziEle_fx( move32(); x = sqrt_fx; move32(); - radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); + radian = atan2_fx( L_abs( L_shr( y, 15 ) ), L_abs( L_shr( x, 15 ) ) ); // Q14 if ( y <= 0 ) { radian = negate( radian ); @@ -588,11 +588,11 @@ void rotateAziEle_fx( { IF( radian < 0 ) { - angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); + angle = negate( add( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ) ); // Q0 } ELSE { - angle = sub( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); + angle = sub( 180, extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ) ); // Q0 } IF( radian == 0 ) { @@ -604,10 +604,10 @@ void rotateAziEle_fx( } ELSE { - angle = extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ); + angle = extract_l( L_shr( Mpy_32_16_r( _180_OVER_PI_Q25, radian ), ( 24 ) ) ); // Q0 } - *ele = s_max( -90, s_min( 90, angle ) ); + *ele = s_max( -90, s_min( 90, angle ) ); // Q0 move16(); } ELSE @@ -630,7 +630,7 @@ void rotateAziEle_fx_frac_az_el( Word32 *azi, /* o : rotated azimuth Q22 */ Word32 *ele, /* o : rotated elevation Q22 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n, radian; // temp_16; @@ -654,8 +654,8 @@ void rotateAziEle_fx_frac_az_el( } azi_in_q13 = extract_l( L_shr( Mpy_32_32( azi_in, PI_OVER_180_FX ), Q9 ) ); ele_in_q13 = extract_l( L_shr( Mpy_32_32( ele_in, PI_OVER_180_FX ), Q9 ) ); - w_fx = getCosWord16( ele_in_q13 ); // Q14 - dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); + w_fx = getCosWord16( ele_in_q13 ); // Q14 + dv_fx[0] = L_mult( w_fx, getCosWord16( azi_in_q13 ) ); // Q28 move32(); IF( EQ_32( dv_fx[0], ONE_IN_Q29 ) ) { @@ -667,7 +667,7 @@ void rotateAziEle_fx_frac_az_el( dv_fx[0] = L_shl( dv_fx[0], 2 ); move32(); } - dv_fx[1] = L_mult( w_fx, getSinWord16( azi_in_q13 ) ); + dv_fx[1] = L_mult( w_fx, getSinWord16( azi_in_q13 ) ); // Q28 move32(); IF( EQ_32( dv_fx[1], ONE_IN_Q30 ) ) { @@ -679,7 +679,7 @@ void rotateAziEle_fx_frac_az_el( dv_fx[1] = L_shl( dv_fx[1], 1 ); move32(); } - dv_fx[2] = L_deposit_l( getSinWord16( ele_in_q13 ) ); + dv_fx[2] = L_deposit_l( getSinWord16( ele_in_q13 ) ); // Q14 move32(); IF( EQ_32( dv_fx[2], ONE_IN_Q15 ) ) { @@ -726,7 +726,7 @@ void rotateAziEle_fx_frac_az_el( move32(); x = sqrt_fx; move32(); - radian = BASOP_util_atan2( y, x, 0 ); + radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 @@ -762,7 +762,7 @@ void rotateAziEle_fixed( Word32 *azi, /* o : rotated azimuth Q22 */ Word32 *ele, /* o : rotated elevation Q22 */ Word32 Rmat_fx[3][3], /* i : real-space rotation matrix Q30 */ - const Word16 isPlanar /* i : is rotation planar and elevation meaningless? */ + const Word16 isPlanar /* i : is rotation planar and elevation meaningless? Q0*/ ) { Word16 n, radian, temp_16; @@ -789,7 +789,7 @@ void rotateAziEle_fixed( move32(); temp_16 = azi_in; move16(); - dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs_s( temp_16 )] ); + dv_fx[0] = Mpy_32_32( w_fx, cosine_table_Q31[abs( temp_16 )] ); move32(); temp_16 = azi_in; move16(); @@ -815,7 +815,19 @@ void rotateAziEle_fixed( radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 - + /* Handeled roudning off operation*/ + IF( angle > 0 ) + { + temp = L_add( angle, ONE_IN_Q21 /* 0.5 in Q22*/ ); + temp_16 = extract_l( L_shr( temp, Q22 ) ); + angle = L_shl( temp_16, Q22 ); // Q22 + } + ELSE + { + temp = L_sub( angle, ONE_IN_Q21 /* 0.5 in Q22*/ ); + temp_16 = add( extract_l( L_shr( temp, Q22 ) ), 1 ); + angle = L_shl( temp_16, Q22 ); // Q22 + } *azi = L_max( L_shl( -180, 22 ), L_min( L_shl( 180, 22 ), angle ) ); // Q22 move32(); if ( LE_32( L_abs( *azi ), ONE_IN_Q22 ) ) @@ -830,7 +842,7 @@ void rotateAziEle_fixed( move32(); x = sqrt_fx; move32(); - radian = BASOP_util_atan2( y, x, 0 ); + radian = BASOP_util_atan2( y, x, 0 ); // Q13 angle = L_shr( Mpy_32_16_1( _180_OVER_PI_Q25, radian ), 1 ); // Q22 @@ -911,9 +923,9 @@ void rotateAziEle( void rotateFrame_shd( COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : head and external orientation combined handle */ Word32 *output[], /* i/o: unrotated HOA3 signal buffer in TD Q11 */ - const Word16 subframe_len, /* i : subframe length per channel */ + const Word16 subframe_len, /* i : subframe length per channel Q0 */ const IVAS_OUTPUT_SETUP hTransSetup, /* i : format for rotation */ - const Word16 subframe_idx /* i : subframe index */ + const Word16 subframe_idx /* i : subframe index Q0 */ ) { // Not yet tested, no test cases entering the function. @@ -934,7 +946,7 @@ void rotateFrame_shd( SWITCH( subframe_len ) { case L_SUBFRAME_48k: - tmp = Q31_BY_SUB_FRAME_240; + tmp = Q31_BY_SUB_FRAME_240; // Q31 move32(); BREAK; case L_SUBFRAME_32k: @@ -989,7 +1001,7 @@ void rotateFrame_shd( FOR( m = m1; m < m2; m++ ) { /* crossfade with previous rotation gains */ - tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ) /*Q30*/, output[m][add( offset, i )] /*Q11*/ ) ); + tmp = L_add( Mpy_32_32( Mpy_32_16_r( cross_fade[i], SHrotmat[n][m] ) /*Q30*/, output[m][offset + i] /*Q11*/ ), Mpy_32_32( Mpy_32_16_r( L_sub( ONE_IN_Q31, cross_fade[i] ), SHrotmat_prev[n][m] ) /*Q30*/, output[m][offset + i] /*Q11*/ ) ); tmpRot[n - m1] = L_add( L_shl( tmp, 1 ), tmpRot[n - m1] ); // Q11 } } @@ -997,7 +1009,7 @@ void rotateFrame_shd( /* write back the result */ FOR( n = m1; n < m2; n++ ) { - output[n][add( offset, i )] = tmpRot[n - m1]; // Q11 + output[n][offset + i] = tmpRot[n - m1]; // Q11 move32(); } m1 = m2; @@ -1028,7 +1040,7 @@ void rotateFrame_shd( MVR2R_WORD32( hCombinedOrientationData->Rmat_fx[subframe_idx][i], hCombinedOrientationData->Rmat_prev_fx[i], - 3 ); + 3 ); // Q14 } return; @@ -1239,8 +1251,8 @@ void rotateFrame_sd( test(); IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); - elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); // Q0->Q22 + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); // Q0->Q22 efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); @@ -1274,8 +1286,8 @@ void rotateFrame_sd( IF( hEFAPdata != NULL && ( NE_16( extract_l( L_shr( hTransSetup.ls_azimuth_fx[ch_in_woLFE], Q22 ) ), azimuth ) || NE_16( extract_l( L_shr( hTransSetup.ls_elevation_fx[ch_in_woLFE], Q22 ) ), elevation ) ) ) { - azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); - elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); + azimuth_fx = L_shl( L_deposit_l( azimuth ), Q22 ); // Q0->Q22 + elevation_fx = L_shl( L_deposit_l( elevation ), Q22 ); // Q0->Q22 efap_determine_gains_fx( hEFAPdata, tmp_gains_fx, azimuth_fx, elevation_fx, EFAP_MODE_EFAP ); FOR( ch_out = 0; ch_out < nchan; ch_out++ ) @@ -1327,14 +1339,14 @@ void rotateFrame_sd( FOR( i = 0; i < 3; i++ ) { MVR2R_WORD32( - hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i], + hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx][i], // Q30 hCombinedOrientationData->Rmat_prev_fx[i], 3 ); } /* copy to output */ FOR( ch_out = 0; ch_out < nchan; ch_out++ ) { - MVR2R_WORD32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); + MVR2R_WORD32( &output_tmp_fx[ch_out][offset], &output[ch_out][offset], subframe_len ); // Q11 } pop_wmops(); @@ -1545,9 +1557,9 @@ void rotateFrame_shd_cldfb( move32(); FOR( m = m1; m < m2; m++ ) { - temp1 = Mpy_32_16_r( Cldfb_RealBuffer[m][i][iBand], SHrotmat[n][m] ); - temp2 = Mpy_32_16_r( Cldfb_ImagBuffer[m][i][iBand], SHrotmat[n][m] ); - realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(x + 14 - 15) + temp1 = Mpy_32_16_r( Cldfb_RealBuffer[m][i][iBand], SHrotmat[n][m] ); // Q(x + 14 - 15) + temp2 = Mpy_32_16_r( Cldfb_ImagBuffer[m][i][iBand], SHrotmat[n][m] ); // Q(x + 14 - 15) + realRot[n - m1] = L_add( temp1, realRot[n - m1] ); // Q(x + 14 - 15) move32(); imagRot[n - m1] = L_add( temp2, imagRot[n - m1] ); // Q(x + 14 - 15) move32(); @@ -1856,7 +1868,7 @@ void rotateFrame_sd_cldfb_fixed( ELSE { set32_fx( gains_fx[n], 0, nInChannels ); - gains_fx[n][n] = 0x7fffffff; // Q31 + gains_fx[n][n] = 0x7fffffff; // 1 in Q31 move32(); } } @@ -1868,7 +1880,7 @@ void rotateFrame_sd_cldfb_fixed( set32_fx( imagRot_fx[n], 0, shl( nb_band, 2 ) ); FOR( m = 0; m < nInChannels; m++ ) { - g1_fx = gains_fx[m][n]; + g1_fx = gains_fx[m][n]; // Q31 move32(); p_realRot_fx = realRot_fx[n]; p_imagRot_fx = imagRot_fx[n]; @@ -2505,13 +2517,13 @@ ivas_error combine_external_and_head_orientations( Word16 l_shift = 0; move16(); l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); - hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); // q_fact+l_shift move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); move16(); @@ -2601,9 +2613,9 @@ ivas_error combine_external_and_head_orientations( /* Save the current orientations */ IF( hExtOrientationData != NULL ) { - IF( hExtOrientationData->enableExternalOrientation[sub( hExtOrientationData->num_subframes, 1 )] > 0 ) + IF( hExtOrientationData->enableExternalOrientation[hExtOrientationData->num_subframes - 1] > 0 ) { - hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[sub( hExtOrientationData->num_subframes, 1 )]; + hCombinedOrientationData->Quaternion_prev_extOrientation = hExtOrientationData->Quaternions[hExtOrientationData->num_subframes - 1]; } ELSE { @@ -2696,13 +2708,13 @@ ivas_error combine_external_and_head_orientations( FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ ) { l_shift = s_min( s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].w_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].x_fx ) ), s_min( Q_factor_L_32( hCombinedOrientationData->Quaternions[i].y_fx ), Q_factor_L_32( hCombinedOrientationData->Quaternions[i].z_fx ) ) ); - hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].w_fx = L_shl( hCombinedOrientationData->Quaternions[i].w_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].x_fx = L_shl( hCombinedOrientationData->Quaternions[i].x_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].y_fx = L_shl( hCombinedOrientationData->Quaternions[i].y_fx, l_shift ); // q_fact+l_shift move32(); - hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); + hCombinedOrientationData->Quaternions[i].z_fx = L_shl( hCombinedOrientationData->Quaternions[i].z_fx, l_shift ); // q_fact+l_shift move32(); hCombinedOrientationData->Quaternions[i].q_fact = add( hCombinedOrientationData->Quaternions[i].q_fact, l_shift ); move16(); @@ -2989,7 +3001,7 @@ static void external_target_interpolation_fx( { IF( i > 0 ) { - IF( hExtOrientationData->enableExternalOrientation[sub( i, 1 )] == 0 ) + IF( hExtOrientationData->enableExternalOrientation[i - 1] == 0 ) { IVAS_QUATERNION identity; identity.w_fx = ONE_IN_Q31; @@ -3002,13 +3014,13 @@ static void external_target_interpolation_fx( move16(); hCombinedOrientationData->Quaternions_ext_interpolation_start = identity; } - ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[sub( i, 1 )], 2 ) ) + ELSE IF( EQ_16( hExtOrientationData->enableExternalOrientation[i - 1], 2 ) ) { hCombinedOrientationData->Quaternions_ext_interpolation_start = hCombinedOrientationData->Quaternion_frozen_ext; } ELSE { - hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[sub( i, 1 )]; + hCombinedOrientationData->Quaternions_ext_interpolation_start = hExtOrientationData->Quaternions[i - 1]; } } ELSE @@ -3187,10 +3199,10 @@ static bool are_orientations_same_fx( test(); test(); test(); - IF( EQ_16( Flag_1, 1 ) || - EQ_16( Flag_2, 1 ) || - EQ_16( Flag_3, 1 ) || - EQ_16( Flag_4, 1 ) ) + if ( EQ_16( Flag_1, 1 ) || + EQ_16( Flag_2, 1 ) || + EQ_16( Flag_3, 1 ) || + EQ_16( Flag_4, 1 ) ) { orientationsAreSame = false; move16(); @@ -3248,34 +3260,36 @@ static Word32 SHrot_p_fx( Word32 p = 0; move32(); - ri1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( 1, 1 ), 1 )]; + ri1 = SHrotmat[i + 1 + 1][1 + 1 + 1]; // Q14 move16(); - rim1 = SHrotmat[add( add( i, 1 ), 1 )][add( add( -1, 1 ), 1 )]; + rim1 = SHrotmat[i + 1 + 1][-1 + 1 + 1]; // Q14 move16(); - ri0 = SHrotmat[add( add( i, 1 ), 1 )][add( 1, 1 )]; + ri0 = SHrotmat[i + 1 + 1][0 + 1 + 1]; // Q14 move16(); IF( EQ_16( b, -l ) ) { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][0]; + R_lm1_1 = R_lm1[a + l - 1][0]; // Q14 move16(); - R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; + R_lm1_2 = R_lm1[a + l - 1][2 * l - 2]; // Q14 move16(); - p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); + p = L_mac0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); // Q28 } ELSE { IF( EQ_16( b, l ) ) { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( shl( l, 1 ), 2 )]; - R_lm1_2 = R_lm1[sub( add( a, l ), 1 )][0]; - p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); + R_lm1_1 = R_lm1[a + l - 1][2 * l - 2]; // Q14 + move16(); + R_lm1_2 = R_lm1[a + l - 1][0]; // Q14 + move16(); + p = L_msu0( L_mult0( ri1, R_lm1_1 ), rim1, R_lm1_2 ); // Q28 } ELSE { - R_lm1_1 = R_lm1[sub( add( a, l ), 1 )][sub( add( b, l ), 1 )]; + R_lm1_1 = R_lm1[a + l - 1][b + l - 1]; move16(); - p = L_mult0( ri0, R_lm1_1 ); + p = L_mult0( ri0, R_lm1_1 ); // Q28 } } @@ -3450,9 +3464,9 @@ static Word32 SHrot_v_fx( d = 1; move16(); } - p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, add( negate( m ), 1 ), n, SHrotmat, R_lm1 ); - result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[add( 1, d )] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, add( negate( m ), 1 ), n, SHrotmat, R_lm1 ); // Q28 + result = Msub_32_16_r( Mpy_32_16_r( p0, square_root16_table[1 + d] ), p1, shl( sub( 1, d ), 14 ) ); // Q27 } ELSE { @@ -3465,7 +3479,7 @@ static Word32 SHrot_v_fx( } p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); - result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[add( 1, d )] ); // Q27 + result = Madd_32_16_r( Mpy_32_16_r( p0, shl( sub( 1, d ), 14 ) ), p1, square_root16_table[1 + d] ); // Q27 } } return result; // Q27 @@ -3490,15 +3504,15 @@ static Word32 SHrot_w_fx( { IF( m > 0 ) { - p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); - result = L_add( p0, p1 ); + p0 = SHrot_p_fx( 1, l, add( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, negate( add( m, 1 ) ), n, SHrotmat, R_lm1 ); // Q28 + result = L_add( p0, p1 ); // Q28 } ELSE { - p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); - p1 = SHrot_p_fx( -1, l, sub( 1, m ), n, SHrotmat, R_lm1 ); - result = L_sub( p0, p1 ); + p0 = SHrot_p_fx( 1, l, sub( m, 1 ), n, SHrotmat, R_lm1 ); // Q28 + p1 = SHrot_p_fx( -1, l, sub( 1, m ), n, SHrotmat, R_lm1 ); // Q28 + result = L_sub( p0, p1 ); // Q28 } } @@ -3555,21 +3569,21 @@ void SHrotmatgen_fx( SHrotmat[0][0] = ONE_IN_Q14; move16(); - SHrotmat[1][1] = extract_h( Rmat[1][1] ); + SHrotmat[1][1] = extract_h( Rmat[1][1] ); // Q14 move16(); SHrotmat[1][2] = extract_h( Rmat[1][2] ); move16(); SHrotmat[1][3] = extract_h( Rmat[1][0] ); move16(); - SHrotmat[2][1] = extract_h( Rmat[2][1] ); + SHrotmat[2][1] = extract_h( Rmat[2][1] ); // Q14 move16(); SHrotmat[2][2] = extract_h( Rmat[2][2] ); move16(); SHrotmat[2][3] = extract_h( Rmat[2][0] ); move16(); - SHrotmat[3][1] = extract_h( Rmat[0][1] ); + SHrotmat[3][1] = extract_h( Rmat[0][1] ); // Q14 move16(); SHrotmat[3][2] = extract_h( Rmat[0][2] ); move16(); @@ -3580,7 +3594,7 @@ void SHrotmatgen_fx( { FOR( j = 0; j < 2 * 1 + 1; j++ ) { - R_lm1[i][j] = SHrotmat[i + 1][j + 1]; + R_lm1[i][j] = SHrotmat[i + 1][j + 1]; // Q14 move16(); } } @@ -3600,23 +3614,23 @@ void SHrotmatgen_fx( } absm = extract_l( L_abs( m ) ); - sql2mm2 = square_root30_q12[sub( imult1616( l, l ), imult1616( m, m ) )]; + sql2mm2 = square_root30_q12[l * l - m * m]; // Q12 move16(); - sqdabsm = square_root30_q12[imult1616( add( 1, d ), imult1616( sub( add( l, absm ), 1 ), add( l, absm ) ) )]; + sqdabsm = square_root30_q12[( 1 + d ) * ( l + absm - 1 ) * ( l + absm )]; // Q12 move16(); - sqlabsm = square_root30_q12[imult1616( sub( l, add( absm, 1 ) ), sub( l, absm ) )]; + sqlabsm = square_root30_q12[( ( l - ( absm + 1 ) ) * ( l - absm ) )]; // Q12 move16(); FOR( n = -l; n <= l; n++ ) { IF( EQ_16( abs_s( n ), l ) ) { - sqdenom = square_root30_q12[imult1616( shl( l, 1 ), sub( shl( l, 1 ), 1 ) )]; + sqdenom = square_root30_q12[( ( 2 * l ) * ( 2 * l - 1 ) )]; // Q12 move16(); } ELSE { - sqdenom = square_root30_q12[sub( imult1616( l, l ), imult1616( n, n ) )]; + sqdenom = square_root30_q12[( l * l - n * n )]; // Q12 move16(); } @@ -3641,7 +3655,7 @@ void SHrotmatgen_fx( w32_fx = Mpy_32_16_r( result, w ); // Q27 } // Addind and converting to 16 bit integer of Q14 - R_l[add( m, l )][add( n, l )] = extract_h( L_shl( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ), 4 ) ); // Q14 + R_l[m + l][n + l] = extract_h( L_shl( L_add( L_add( L_shr( u32_fx, 1 ), v32_fx ), L_shr( w32_fx, 1 ) ), 4 ) ); // Q14 move16(); } } @@ -3650,7 +3664,7 @@ void SHrotmatgen_fx( { FOR( j = 0; j < 2 * l + 1; j++ ) { - SHrotmat[add( band_idx, i )][add( band_idx, j )] = R_l[i][j]; + SHrotmat[band_idx + i][band_idx + j] = R_l[i][j]; // Q14 move16(); } } @@ -3832,7 +3846,7 @@ void ivas_combined_orientation_update_index( hCombinedOrientationData->cur_subframe_samples_rendered = add( hCombinedOrientationData->cur_subframe_samples_rendered, samples_rendered ); move16(); div_result = BASOP_Util_Divide3216_Scale( hCombinedOrientationData->cur_subframe_samples_rendered, hCombinedOrientationData->subframe_size, &exp ); - hCombinedOrientationData->subframe_idx = add( hCombinedOrientationData->subframe_idx, shl( div_result, exp + 1 ) ); + hCombinedOrientationData->subframe_idx = add( hCombinedOrientationData->subframe_idx, shl( div_result, add( exp, 1 ) ) ); move16(); hCombinedOrientationData->cur_subframe_samples_rendered = hCombinedOrientationData->cur_subframe_samples_rendered % hCombinedOrientationData->subframe_size; move16(); diff --git a/lib_rend/ivas_sba_rendering.c b/lib_rend/ivas_sba_rendering.c index 380faaf9f..4a23da243 100644 --- a/lib_rend/ivas_sba_rendering.c +++ b/lib_rend/ivas_sba_rendering.c @@ -111,8 +111,8 @@ void ivas_sba_prototype_renderer_fx( { FOR( Word16 j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) { - scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); - scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); + scale_sig32( inRe_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); // q_cldfb -> q_cldfb + 2 -norm_q + scale_sig32( inIm_fx[i][j], CLDFB_NO_CHANNELS_MAX, sub( norm_q, 2 ) ); // q_cldfb -> q_cldfb + 2 -norm_q q_cldfb[i][j] = sub( add( q_cldfb[i][j], norm_q ), 2 ); move16(); } @@ -170,7 +170,7 @@ void ivas_sba_prototype_renderer_fx( { spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band]; move16(); - cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // q30 + cldfb_par_fx = mixer_mat_fx[out_ch][in_ch][spar_band]; // hMdDec->Q_mixer_matrix move32(); } ELSE @@ -180,12 +180,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] ) ); // q30 + 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 } } - 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 ) ); // q30+q_cldfb[i][j]; - 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 ) ); // q30+q_cldfb[i][j + 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 move32(); move32(); } @@ -194,8 +194,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 ); // q30+q_cldfb[i][j]; + q1 //to keep constat q to entire buffer - inIm_fx[out_ch][ts][cldfb_band] = L_shl_sat( out_im_fx[out_ch], 1 ); + 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 move32(); move32(); } @@ -216,10 +216,10 @@ void ivas_sba_prototype_renderer_fx( move16(); hSpar->i_subframe = s_min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); move16(); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); - Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], hSpar->hMdDec->mixer_mat_prev_fx[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], hSpar->hMdDec->mixer_mat_prev_fx[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], hSpar->hMdDec->mixer_mat_prev_fx[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat + Copy32( hSpar->hMdDec->mixer_mat_prev_fx[4][0][0], hSpar->hMdDec->mixer_mat_prev_fx[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); // Q_mixer_mat FOR( out_ch = 0; out_ch < numch_out; out_ch++ ) { @@ -252,9 +252,9 @@ void ivas_sba_prototype_renderer_fx( Word32 temp_signal_fx[CLDFB_NO_CHANNELS_MAX]; FOR( Word16 idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + temp_signal_fx[idx] = L_add( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); - inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); + inRe_fx[1][ts][idx] = L_sub( L_shr( inRe_fx[0][ts][idx], 1 ), L_shr( inRe_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); inRe_fx[0][ts][idx] = temp_signal_fx[idx]; move32(); @@ -262,9 +262,9 @@ void ivas_sba_prototype_renderer_fx( FOR( Word16 idx = 0; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { - temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + temp_signal_fx[idx] = L_add( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); - inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); + inIm_fx[1][ts][idx] = L_sub( L_shr( inIm_fx[0][ts][idx], 1 ), L_shr( inIm_fx[1][ts][idx], 1 ) ); // q_cldfb[][]-1 move32(); inIm_fx[0][ts][idx] = temp_signal_fx[idx]; move32(); -- GitLab From dcda39c4082a8674b079fc5e6373ec179368c12a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 22 Oct 2024 22:10:18 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_dec/dec_tcx.c | 6 +++--- lib_dec/dec_uv_fx.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index f32a383a5..3481c797d 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -1950,7 +1950,7 @@ void decoder_tcx_imdct_fx( Word16 predictionGain_fx; Word16 A_itf_fx[ITF_MAX_FILTER_ORDER + 1]; // q_a_itf Word16 q_a_itf = 15; - Word16 x_e = sub(31, q_x); + Word16 x_e = sub( 31, q_x ); move16(); /*-----------------------------------------------------------------* @@ -2017,7 +2017,7 @@ void decoder_tcx_imdct_fx( move16(); } - test(); + test(); test(); test(); test(); @@ -2099,7 +2099,7 @@ void decoder_tcx_imdct_fx( } test(); - IF( NE_16(st->element_mode, IVAS_CPE_DFT) && !sba_dirac_stereo_flag ) + IF( NE_16( st->element_mode, IVAS_CPE_DFT ) && !sba_dirac_stereo_flag ) { IMDCT_ivas_fx( xn_bufFB_fx, q_x, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, xn_buf_fx, hTcxCfg->tcx_aldo_window_1, hTcxCfg->tcx_aldo_window_1_trunc, hTcxCfg->tcx_aldo_window_2, diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 231b0cb73..bdddeb791 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -84,7 +84,7 @@ void decod_unvoiced_fx( Word16 tmp_idx = 0; move16(); - IF ( i_subfr_fx != 0 ) + IF( i_subfr_fx != 0 ) { tmp_idx = idiv1616( i_subfr_fx, L_SUBFR ); } -- GitLab