diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 890e0e5c894ce3e9647abed4db0c47793360f597..a541ebf7bcf746f7f0737505c0ab931fed39e9b3 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -618,6 +618,7 @@ void ivas_wb_tbe_dec_fx( move16(); Word32 dummy2[HILBERT_MEM_SIZE]; Word16 f, inc; + Word64 W_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -853,17 +854,20 @@ void ivas_wb_tbe_dec_fx( move16(); /* restrict this to 21 due to the Q factor requireemnt of the random number generator (keep 1 bit headroom) */ } - prev_pow = 0; - move32(); + W_tmp = 0; + move64(); IF( st_fx->element_mode > EVS_MONO ) { tmp = sub( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + W_tmp = L_shl( 1407374848l /*0.00001f Q47*/, tmp ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ } FOR( i = 0; i < L_SHB_LAHEAD / 4; i++ ) { - prev_pow = L_mac0( prev_pow, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16))*/ + W_tmp = W_mac_16_16( W_tmp, hBWE_TD->state_syn_shbexc_fx[i], hBWE_TD->state_syn_shbexc_fx[i] ); /*Q(2*(st_fx->prev_Q_bwe_exc-16 + 1))*/ } + exp = W_norm( W_tmp ); + prev_pow = W_extract_h( W_shl( W_tmp, exp ) ); + exp = sub( add( add( shl( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), 1 ), exp ), 32 ); rescale_genWB_mem( st_fx, sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ) ); @@ -901,7 +905,7 @@ void ivas_wb_tbe_dec_fx( } Lscale = root_a_over_b_fx( curr_pow, shl_r( Q_bwe_exc_ext, 1 ), prev_pow, - shl_r( sub( st_fx->prev_Q_bwe_exc, 16 ), 1 ), &exp ); + exp, &exp ); FOR( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ ) { diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index ceb5dec1d7c40cd2a38764c512732d30c309f81d..9d0579d1243d17cdf9058de82941b6f0c453d91f 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -2463,19 +2463,23 @@ static void reduce_metadata_further_fx( } /* Determine if to merge over frequency instead of time */ - meanRatio = 0; - move32(); + W_tmp = 0; + move64(); FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { FOR( band = 0; band < numCodingBands; band++ ) { - meanRatio = L_add( meanRatio, Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ) ); // hMasa->data.q_energy - 1 + W_tmp = W_mac_32_16( W_tmp, Mpy_32_32( hqmetadata->q_direction[0].band_data[band].energy_ratio_fx[sf], energy[sf][band] ), 1 ); // hMasa->data.q_energy } } + shift = W_norm( W_tmp ); + meanRatio = W_extract_h( W_shl( W_tmp, shift ) ); // Q:sub( add( hMasa->data.q_energy, shift ), 32 ) + shift = sub( 31, sub( add( hMasa->data.q_energy, shift ), 32 ) ); + IF( totalEnergySum != 0 ) { meanRatio = BASOP_Util_Divide3232_Scale_newton( meanRatio, totalEnergySum, &exp ); - exp = add( add( exp, 1 ), tmp2 ); // 31 - (hMasa->data.q_energy - 1) - 31 - hMasa->data.q_energy - tmp2 => 1 + tmp2 + exp = add( exp, sub( shift, sub( 31, add( hMasa->data.q_energy, tmp2 ) ) ) ); // exp + (shift - (31 - hMasa->data.q_energy - tmp2)) => 1 + tmp2 } ELSE { diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index 9ad5f4a2cdb9a4bab773a1008a6b70cb948771af..d4dd73abe8ea2be7536ea15ce15c6270737b279f 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -285,10 +285,10 @@ static void convolve_tc_fx( L_sum = L_mult( g[0], h[n] ); /* Qx */ FOR( i = 1; i < len; i++ ) { - L_sum = L_mac( L_sum, g[i], h[n - i] ); /* Qx + 16 */ + L_sum = L_mac_sat( L_sum, g[i], h[n - i] ); /* Qx + 16 */ } - y[n] = round_fx( L_sum ); /* Qx */ + y[n] = round_fx_sat( L_sum ); /* Qx */ } } /*-------------------------------------------------------------------*