diff --git a/lib_com/options.h b/lib_com/options.h index 4c6109723b038344e32550192f5030734050ec02..1cb0ac3e3de09537aa555ce1b8a7e775a24bb72b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -73,7 +73,8 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ -#define ISSUE_1836_replace_overflow_libcom /* FhG: replace overflow operators by non-overflow-alternatives in lib_com - BE */ +#define ISSUE_1836_replace_overflow_libcom /* FhG: BE - replace overflow operators by non-overflow-alternatives in lib_com */ +#define ISSUE_1867_replace_overflow_libenc /* FhG: BE - replace overflow operators by non-overflow-alternatives all over the lib_enc module */ #define FIX_1942_ASSERTION_LOWSHELF /* FhG: Modified the target_gains_db_fx calculation in compute_t60_coeffs_fx() */ #define FIX_1944_CRASH_FOR_STEREO /* FhG: improve TonalMDCTConceal_InsertNoise calculation precision */ #define FIX_1970_SBA_CRASH /* Dlb: Fix for issue 1970, SBA crash */ diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 23ebe81b4d37279cf863887fe2824471fb0026e0..9b0bae1e5803d75d8a5baea5b8cbadbbfe320276 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -168,7 +168,7 @@ void stat_noise_uv_mod_fx( { exctilt = calc_tilt_fx( &Exc2_local[i_subfr], En_shift, L_SUBFR ); /*Q15 */ #ifdef ISSUE_1836_replace_overflow_libcom - exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ //??Sat + exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ #else exctilt = mult( shl_o( sub( TILT_COMP_LIM_FX, min_alpha ), 2, &Overflow ), exctilt ); /*Q15 */ #endif @@ -197,7 +197,7 @@ void stat_noise_uv_mod_fx( tmp_den = shl( tmp_den, tmp_shift ); tmp_res = div_s( tmp_nom, tmp_den ); #ifdef ISSUE_1836_replace_overflow_libcom - tmp_res = shl_sat( tmp_res, tmp_shift ); //??Sat + tmp_res = shl_sat( tmp_res, tmp_shift ); #else tmp_res = shl_o( tmp_res, tmp_shift, &Overflow ); #endif diff --git a/lib_enc/acelp_core_switch_enc_fx.c b/lib_enc/acelp_core_switch_enc_fx.c index 98e56252c1334a11abe233bc424e80599dac37e3..dac68df1ed195bbf15638e4c819bb080f63ff8b2 100644 --- a/lib_enc/acelp_core_switch_enc_fx.c +++ b/lib_enc/acelp_core_switch_enc_fx.c @@ -726,9 +726,11 @@ static void bwe_switch_enc_fx( Word16 synth_subfr_bwe_fx[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ Word16 n, L; BSTR_ENC_HANDLE hBstr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif hBstr = st_fx->hBstr; L = NS2SA_FX2( st_fx->input_Fs, FRAME_SIZE_NS ); @@ -845,7 +847,11 @@ static void bwe_switch_enc_fx( L_tmp1 = L_mult( tmp, E2_fx ); /*30-q_tmp1+q_tmp2 */ q_tmp2 = sub( q_tmp1, q_tmp2 ); /*30-q_tmp2 */ L_tmp1 = L_shl( L_tmp1, sub( q_tmp2, 24 ) ); - gain_fx = round_fx_o( Isqrt( L_tmp1 ), &Overflow ); /*Q12 */ +#ifdef ISSUE_1867_replace_overflow_libenc + gain_fx = round_fx_sat( Isqrt( L_tmp1 ) ); /*Q12 */ +#else + gain_fx = round_fx_o( Isqrt( L_tmp1 ), &Overflow ); /*Q12 */ +#endif ind1_fx = usquant_fx( gain_fx, &gain_fx, shr( MINVALUEOFFIRSTGAIN_FX, 1 ), shr( DELTAOFFIRSTGAIN_FX, 4 ), ( 1 << NOOFGAINBITS1 ) ); /* Q0 */ push_indice( hBstr, IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); @@ -872,9 +878,11 @@ static void bwe_switch_enc_ivas_fx( Word16 synth_subfr_bwe_fx[SWITCH_MAX_GAP]; /* synthesized bwe for core switching */ Word16 n, L; BSTR_ENC_HANDLE hBstr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif hBstr = st_fx->hBstr; L = NS2SA_FX2( st_fx->input_Fs, FRAME_SIZE_NS ); @@ -988,7 +996,11 @@ static void bwe_switch_enc_ivas_fx( L_tmp1 = L_mult( tmp, E2_fx ); /*30-q_tmp1+q_tmp2 */ q_tmp2 = sub( q_tmp1, q_tmp2 ); /*30-q_tmp2 */ L_tmp1 = L_shl( L_tmp1, sub( q_tmp2, 24 ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + gain_fx = round_fx_sat( Isqrt( L_tmp1 ) ); /*Q12 */ +#else gain_fx = round_fx_o( Isqrt( L_tmp1 ), &Overflow ); /*Q12 */ +#endif ind1_fx = usquant_fx( gain_fx, &gain_fx, shr( MINVALUEOFFIRSTGAIN_FX, 1 ), shr( DELTAOFFIRSTGAIN_FX, 4 ), ( 1 << NOOFGAINBITS1 ) ); push_indice( hBstr, IND_CORE_SWITCHING_AUDIO_GAIN, ind1_fx, NOOFGAINBITS1 ); diff --git a/lib_enc/acelp_enc_util_fx.c b/lib_enc/acelp_enc_util_fx.c index 7f57b55da9f685b3d5800308105bf66c623742fe..ad8e7e6cd75cc8af7f6330c5b7014c6095616c55 100644 --- a/lib_enc/acelp_enc_util_fx.c +++ b/lib_enc/acelp_enc_util_fx.c @@ -161,8 +161,10 @@ void E_ACELP_conv( { Word16 i, k; Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif FOR( k = 0; k < L_SUBFR; k++ ) { @@ -174,8 +176,12 @@ void E_ACELP_conv( /*cn2[k]-=cn2[i]*h2[k-i];*/ L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*h2 4Q11*/ } - L_tmp = W_sat_l( L_tmp_64 ); /* 4Q11 */ + L_tmp = W_sat_l( L_tmp_64 ); /* 4Q11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + cn2[k] = round_fx_sat( L_shl_sat( L_tmp, 5 ) ); /* Q0 */ +#else cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow ); /* Q0 */ +#endif } } @@ -187,8 +193,10 @@ void E_ACELP_conv_ivas_fx( { Word16 i, k; Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif FOR( k = 0; k < L_SUBFR; k++ ) { @@ -200,8 +208,12 @@ void E_ACELP_conv_ivas_fx( /*cn2[k]-=cn2[i]*h2[k-i];*/ L_tmp_64 = W_msu0_16_16( L_tmp_64, cn2[i], h2[k - i] ); /*Qnew + 11*/ } - L_tmp = W_sat_l( L_tmp_64 ); /* Qnew + 11 */ + L_tmp = W_sat_l( L_tmp_64 ); /* Qnew + 11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + cn2[k] = round_fx_sat( L_shl_sat( L_tmp, 5 ) ); /* Qnew*/ +#else cn2[k] = round_fx_o( L_shl_o( L_tmp, 5, &Overflow ), &Overflow ); /* Qnew*/ +#endif move16(); } } diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 5f8137368b433003840d4527f5cbc3f7da29288d..666d7865c8c7326d1a5c076690f59354cb12da24 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -898,10 +898,12 @@ static void find_enr( Word32 etot; Word16 exp_etot; Word32 *tmpptr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif ptR = &data[1]; /* first real */ @@ -948,9 +950,13 @@ static void find_enr( /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ - BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ - *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); /* Q_new + QSCALE - 2 */ - move32(); /* scaled by Q_new + QSCALE - 2 */ + BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef ISSUE_1867_replace_overflow_libenc + *ptE = L_shl_sat( Ltmp, diff_scaleM2 ); /* Q_new + QSCALE - 2 */ +#else + *ptE = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); /* Q_new + QSCALE - 2 */ +#endif + move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; /*band[i] += *ptE++;*/ *Bin_E = *ptE; @@ -974,9 +980,13 @@ static void find_enr( exp_band = sub( exp_band, shift_to_norm ); exp_band = sub( diff_scaleP1, exp_band ); - BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ - band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); /* Q15 + exp_band */ - move32(); /* band scaled by Q_new + QSCALE */ + BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef ISSUE_1867_replace_overflow_libenc + band[i] = L_shl_sat( Ltmp1, exp_band ); /* Q15 + exp_band */ +#else + band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); /* Q15 + exp_band */ +#endif + move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; test(); @@ -1025,9 +1035,13 @@ static void find_enr( /* *ptE *= 4.0 / (L_FFT*L_FFT) */ /* normalization - corresponds to FFT normalization by 2/L_FFT */ - BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ + BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef ISSUE_1867_replace_overflow_libenc + *Bin_E = L_shl_sat( Ltmp, diff_scaleM2 ); /* Q_new + QSCALE */ +#else *Bin_E = L_shl_o( Ltmp, diff_scaleM2, &Overflow ); /* Q_new + QSCALE */ - move32(); /* scaled by Q_new + QSCALE - 2 */ +#endif + move32(); /* scaled by Q_new + QSCALE - 2 */ BASOP_SATURATE_WARNING_ON_EVS; Bin_E++; Ltmp1 = L_add( Ltmp1, Ltmp ); @@ -1048,7 +1062,11 @@ static void find_enr( exp_band = sub( exp_band, shift_to_norm ); exp_band = sub( diff_scaleP1, exp_band ); BASOP_SATURATE_WARNING_OFF_EVS; /* saturation seems to have no effect (tested by simulation) */ +#ifdef ISSUE_1867_replace_overflow_libenc + band[i] = L_shl_sat( Ltmp1, exp_band ); +#else band[i] = L_shl_o( Ltmp1, exp_band, &Overflow ); +#endif move32(); /* band scaled by Q_new + QSCALE */ BASOP_SATURATE_WARNING_ON_EVS; diff --git a/lib_enc/ari_hm_enc_fx.c b/lib_enc/ari_hm_enc_fx.c index d62dcf141923e2ecdd303bf6abab6f2acd623843..4beac647d5a1d3c2d184b8467e4c45eecb265e2f 100644 --- a/lib_enc/ari_hm_enc_fx.c +++ b/lib_enc/ari_hm_enc_fx.c @@ -241,9 +241,11 @@ Word16 SearchPeriodicityIndex_fx( Word32 Lag; Word16 s, tmp, tmp2, tmp3; Word32 tmp32; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Debug init (not instrumented) */ @@ -457,7 +459,11 @@ Word16 SearchPeriodicityIndex_fx( tmp32 = L_mult0( Score, NumToConsider ); /* -> 16Q15 */ tmp = sub( norm_l( tmp32 ), 1 ); tmp2 = norm_l( AbsTotal ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp3 = div_s( round_fx_sat( L_shl( tmp32, tmp ) ), round_fx_sat( L_shl( AbsTotal, tmp2 ) ) ); +#else tmp3 = div_s( round_fx_o( L_shl_o( tmp32, tmp, &Overflow ), &Overflow ), round_fx_o( L_shl_o( AbsTotal, tmp2, &Overflow ), &Overflow ) ); +#endif *RelativeScore = shr_sat( tmp3, add( sub( tmp, tmp2 ), 2 ) ); /* -> 2Q13 */ move16(); } diff --git a/lib_enc/arith_coder_enc_fx.c b/lib_enc/arith_coder_enc_fx.c index bb02c3001f99d9ba4edc2cec3fd80417ffff0561..a9955e6f69979a1c608ae6891d07a797f616826f 100644 --- a/lib_enc/arith_coder_enc_fx.c +++ b/lib_enc/arith_coder_enc_fx.c @@ -48,10 +48,12 @@ static Word16 tcx_arith_estimate_scale( { Word16 scale, tmp, k, s, s1; Word32 L_tmp, accu; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /* compute normalised standard deviation and determine approximate scale */ @@ -72,7 +74,11 @@ static Word16 tcx_arith_estimate_scale( s1 = norm_l( abs_spectrum[k] ); } +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = mult_r( round_fx_sat( L_shl( abs_spectrum[k], s1 ) ), envelope[k] ); +#else tmp = mult_r( round_fx_o( L_shl( abs_spectrum[k], s1 ), &Overflow ), envelope[k] ); +#endif L_tmp = L_mult0( tmp, tmp ); tmp = sub( shl( s1, 1 ), 1 ); @@ -367,6 +373,12 @@ static Word16 tcx_arith_rateloop( Word32 L_tmp; Word16 tmp, tmp3; Word32 tmp2; +#ifndef ISSUE_1867_replace_overflow_libenc +#ifdef BASOP_NOGLOB_DECLARE_LOCAL + Flag Overflow = 0; + move32(); +#endif +#endif scale = tcx_arith_estimate_scale( abs_spectrum, abs_spectrum_e, L_frame, envelope, envelope_e, &tmp ); diff --git a/lib_enc/avq_cod_fx.c b/lib_enc/avq_cod_fx.c index 31de693283422167ee0d765f33cdb8fbe0a773ca..8433e77abe610eb2841607b917fe2a1a47e3728d 100644 --- a/lib_enc/avq_cod_fx.c +++ b/lib_enc/avq_cod_fx.c @@ -33,8 +33,10 @@ void AVQ_cod_fx( /* o: comfort noise gain factor Word16 ebits[NSV_MAX], e_ebits, f_ebits, e_tmp, f_tmp, tmp16, l_8; Word32 Lener, Ltmp, Lgain, x1[8]; Word16 tot_est_bits, Q_in; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif Q_in = sub( Q_in_ref, 1 ); move16(); @@ -51,7 +53,11 @@ void AVQ_cod_fx( /* o: comfort noise gain factor Lener = L_shl( 4, shl( Q_in, 1 ) ); /* to set ebits >= 0 */ FOR( i = 0; i < 8; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + Lener = L_mac_sat( Lener, xri[l * 8 + i], xri[l * 8 + i] ); +#else Lener = L_mac_o( Lener, xri[l * 8 + i], xri[l * 8 + i], &Overflow ); +#endif } /* estimated bit consumption when gain=1 */ /* ebits[l] = 5.0 * FAC_LOG2 * (Word16)log10(ener * 0.5) */ diff --git a/lib_enc/bass_psfilter_enc_fx.c b/lib_enc/bass_psfilter_enc_fx.c index 15421594a35655eba9f85a3a9fb972235026ea13..7a056dd132fe774997eb43f6b6bc1b4284b162f3 100644 --- a/lib_enc/bass_psfilter_enc_fx.c +++ b/lib_enc/bass_psfilter_enc_fx.c @@ -36,10 +36,12 @@ Word16 bass_pf_enc_fx( Word32 cross_n_d, nrg_n; const Word16 *pFilt; Word32 ener2; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif IF( NE_16( l_frame, L_FRAME16k ) ) @@ -153,6 +155,16 @@ Word16 bass_pf_enc_fx( FOR( i = 0; i < lg; i++ ) { tmp32 = L_msu0( 0, gain, syn[i + i_subfr - T] ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp32 = L_msu0_sat( tmp32, gain, syn[i + i_subfr + T] ); + tmp16 = mac_r_sat( tmp32, gain, syn[i + i_subfr] ); /* Q0 */ + + lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); + lp_error = L_mac_sat( lp_error, tmp16, 0x1000 ); /* Q13 */ + + tmp16 = round_fx_sat( L_shl_sat( lp_error, s1 ) ); /* Q0+s1-3 */ + ener2 = L_mac0_sat( ener2, tmp16, tmp16 ); /* Q0+(s1-3)*2 */ +#else tmp32 = L_msu0_o( tmp32, gain, syn[i + i_subfr + T], &Overflow ); tmp16 = mac_ro( tmp32, gain, syn[i + i_subfr], &Overflow ); /* Q0 */ @@ -161,6 +173,7 @@ Word16 bass_pf_enc_fx( tmp16 = round_fx_o( L_shl_o( lp_error, s1, &Overflow ), &Overflow ); /* Q0+s1-3 */ ener2 = L_mac0_o( ener2, tmp16, tmp16, &Overflow ); /* Q0+(s1-3)*2 */ +#endif } } @@ -169,13 +182,23 @@ Word16 bass_pf_enc_fx( FOR( i = lg; i < l_subfr; i++ ) { tmp32 = L_mult0( gain, syn[i + i_subfr] ); - tmp32 = L_msu0_o( tmp32, gain, syn[i + i_subfr - T], &Overflow ); /* Q0 */ +#ifdef ISSUE_1867_replace_overflow_libenc + 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*/ ); + lp_error = L_mac_sat( lp_error, tmp16, 0x1000 ); /* Q13 */ + + tmp16 = round_fx_sat( L_shl_sat( lp_error, s1 ) ); /* Q0+s1-3 */ + ener2 = L_mac0_sat( ener2, tmp16, tmp16 ); /* Q0+(s1-3)*2 */ +#else + tmp32 = L_msu0_o( tmp32, gain, syn[i + i_subfr - T], &Overflow ); /* Q0 */ tmp16 = round_fx_o( tmp32, &Overflow ); lp_error = Mpy_32_16_1( lp_error, 29491 /*0.9f Q15*/ ); lp_error = L_mac_o( lp_error, tmp16, 0x1000, &Overflow ); /* Q13 */ - tmp16 = round_fx_o( L_shl_o( lp_error, s1, &Overflow ), &Overflow ); /* Q0+s1-3 */ - ener2 = L_mac0_o( ener2, tmp16, tmp16, &Overflow ); /* Q0+(s1-3)*2 */ + tmp16 = round_fx_o( L_shl_o( lp_error, s1, &Overflow ), &Overflow ); /* Q0+s1-3 */ + ener2 = L_mac0_o( ener2, tmp16, tmp16, &Overflow ); /* Q0+(s1-3)*2 */ +#endif } } @@ -236,7 +259,11 @@ Word16 bass_pf_enc_fx( tmp32 = L_mac( tmp32, tmp16, syn[i + i_subfr] ); noise_in[i] = round_fx( L_shl( tmp32, s2 ) ); /* Q0+s2 */ +#ifdef ISSUE_1867_replace_overflow_libenc + error_in[i] = sub_sat( orig[i + i_subfr], syn[i + i_subfr] ); /*Q0*/ +#else error_in[i] = sub_o( orig[i + i_subfr], syn[i + i_subfr], &Overflow ); /*Q0*/ +#endif move16(); } } @@ -250,7 +277,11 @@ Word16 bass_pf_enc_fx( noise_in[i] = round_fx( L_shl( tmp32, s2 ) ); /* Q0+s2 */ move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + error_in[i] = sub_sat( orig[i + i_subfr], syn[i + i_subfr] ); /*Q0*/ +#else error_in[i] = sub_o( orig[i + i_subfr], syn[i + i_subfr], &Overflow ); /*Q0*/ +#endif move16(); } } diff --git a/lib_enc/bw_detect_fx.c b/lib_enc/bw_detect_fx.c index 7aeb3f77ff1087f0d6ad2f56e9b3ffcc79724feb..6ec7c626b3b1ef007d81f0983a26c60368d2e6db 100644 --- a/lib_enc/bw_detect_fx.c +++ b/lib_enc/bw_detect_fx.c @@ -67,9 +67,11 @@ void bw_detect_fx( const Word32 *pt32; Word32 max_NB32, max_WB32, max_SWB32, max_FB32, mean_NB32, mean_WB32, mean_SWB32, mean_FB32; /* Q11*/ /* we need Word32 for the new cldfb energy vectors */ Word16 bwd_count_wider_bw; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 lp_noise_fx; @@ -127,8 +129,12 @@ void bw_detect_fx( cldfb_bin[i] = L_deposit_l( 1 ); move32(); } - L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ + L_tmp = BASOP_Util_Log2( cldfb_bin[0] ); /*(log2(660423549*2^(-31))/64)*2^31*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_add_sat( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ) ); /* Q25 */ +#else L_tmp = L_add_o( L_tmp, L_shl( L_deposit_l( cldfb_bin_Exp[0] ), 31 - LD_DATA_SCALE ), &Overflow ); /* Q25 */ +#endif cldfb_bin[0] = Mpy_32_16_1( L_tmp, 9864 /*1.0f/3.3219280948873623478703194294894f Q15*/ ); move32(); /* 1/log2(10) */ /* Q25 */ @@ -297,7 +303,11 @@ void bw_detect_fx( FOR( i = 0; i < BWD_TOTAL_WIDTH; i++ ) { - spect[i] = round_fx_o( L_shr_sat( spect32[i], Q_dct ), &Overflow ); +#ifdef ISSUE_1867_replace_overflow_libenc + spect[i] = round_fx_sat( L_shr_sat( spect32[i], Q_dct ) ); +#else + spect[i] = round_fx_o( L_shr_o( spect32[i], Q_dct, &Overflow ), &Overflow ); +#endif move16(); } Q_dct = -2; @@ -335,7 +345,11 @@ void bw_detect_fx( pt1 = &spect[i_mult2( i, bin_width )]; FOR( j = 0; j < bin_width; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + sum32 = L_mac0_sat( sum32, *pt1, *pt1 ); +#else sum32 = L_mac0_o( sum32, *pt1, *pt1, &Overflow ); +#endif pt1++; } tmp_1 = BASOP_Util_Cmp_Mant32Exp( sum32, E_spect_bin, MAX_32, Q31 - 41 ); /* Any sum32 in Q_dct if it is less than MAX_32 in Q41 will be less than 0.001 */ diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index ed3663732c2f4317fcaf436f3094ed71e17c6351..37770ce9e66b8f920bbf12773b63745be9e8f409 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -108,9 +108,11 @@ void CNG_enc_fx( st_lp_sp_enr = hTdCngEnc->lp_sp_enr_fx; move16(); Word16 lp_ener_thr_scale; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Temp variables for floating point functions */ @@ -635,7 +637,11 @@ void CNG_enc_fx( FOR( i = 0; i < M; i++ ) { dev = abs_s( sub( lsp_tmp[i], lsp_new[i] ) ); /*Q15 */ - dist = add_o( dist, dev, &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + dist = add_sat( dist, dev ); /*Q15 */ +#else + dist = add_o( dist, dev, &Overflow ); /*Q15 */ +#endif if ( GT_16( dev, max_dev ) ) { max_dev = dev; @@ -765,10 +771,16 @@ void CNG_enc_fx( FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mult_sat( *ptR, *ptR ); /* 2*Q_new+1 */ + L_tmp = L_add_sat( L_tmp, L_mult_sat( *ptI, *ptI ) ); /* 2*Q_new+1 */ + L_tmp = L_add_sat( L_tmp, L_tmp ); /* 2*Q_new+1 */ +#else L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_new+1 */ L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_new+1 */ L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_new+1 */ - L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_new+1 */ +#endif + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_new+1 */ tmp1 = add( add( Q_new, Q_new ), 1 ); env[i] = L_shr( L_tmp, sub( tmp1, 6 ) ); move32(); /* Q6 */ @@ -1044,9 +1056,13 @@ void CNG_enc_fx( /* d += (env[j] - CNG_details_codebook_fx[i][j]) * (env[j] - CNG_details_codebook_fx[i][j]);*/ L_tmp = L_sub( env[j], L_deposit_l( CNG_details_codebook_fx[i][j] ) ); /* Q6 */ exp = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp ); /*Q(exp+6)*/ - tmp1 = extract_h( L_tmp ); /*Q(exp+6-16)=exp-10*/ - L_tmp = L_mult_o( tmp1, tmp1, &Overflow ); /*Q(2*exp - 19)*/ + L_tmp = L_shl( L_tmp, exp ); /*Q(exp+6)*/ + tmp1 = extract_h( L_tmp ); /*Q(exp+6-16)=exp-10*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mult_sat( tmp1, tmp1 ); /*Q(2*exp - 19)*/ +#else + L_tmp = L_mult_o( tmp1, tmp1, &Overflow ); /*Q(2*exp - 19)*/ +#endif L_tmp = L_shr( L_tmp, sub( add( exp, exp ), 36 ) ); /* Q17 */ d = L_add( d, L_tmp ); } @@ -1233,9 +1249,11 @@ void CNG_enc_ivas_fx( Word64 w_temp; Word32 inv_frame_len; Word32 L_ener; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif step_inv = 0; move16(); @@ -1939,10 +1957,16 @@ void CNG_enc_ivas_fx( FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* env[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mult_sat( *ptR, *ptR ); /* 2*Q_new+1 */ + L_tmp = L_add_sat( L_tmp, L_mult_sat( *ptI, *ptI ) ); /* 2*Q_new+1 */ + L_tmp = L_add_sat( L_tmp, L_tmp ); /* 2*Q_new+1 */ +#else L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_new+1 */ L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_new+1 */ L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_new+1 */ - L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_new+1 */ +#endif + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_new+1 */ tmp1 = add( add( Q_new, Q_new ), 1 ); env[i] = L_shr( L_tmp, sub( tmp1, 6 ) ); move32(); /* Q6 */ @@ -2242,9 +2266,13 @@ void CNG_enc_ivas_fx( /* d += (env[j] - CNG_details_codebook_fx[i][j]) * (env[j] - CNG_details_codebook_fx[i][j]);*/ L_tmp = L_sub( env[j], L_deposit_l( CNG_details_codebook_fx[i][j] ) ); /* Q6 */ exp = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp ); /*Q(exp+6)*/ - tmp1 = extract_h( L_tmp ); /*Q(exp+6-16)=exp-10*/ - L_tmp = L_mult_o( tmp1, tmp1, &Overflow ); /*Q(2*exp - 19)*/ + L_tmp = L_shl( L_tmp, exp ); /*Q(exp+6)*/ + tmp1 = extract_h( L_tmp ); /*Q(exp+6-16)=exp-10*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mult_sat( tmp1, tmp1 ); /*Q(2*exp - 19)*/ +#else + L_tmp = L_mult_o( tmp1, tmp1, &Overflow ); /*Q(2*exp - 19)*/ +#endif L_tmp = L_shr( L_tmp, sub( add( exp, exp ), 36 ) ); /* Q17 */ d = L_add( d, L_tmp ); /* Q17 */ } @@ -2511,9 +2539,11 @@ static Word16 shb_DTX_fx( DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif shb_new_speech_fx = shb_old_speech_fx + ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4; Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4 ); @@ -2531,7 +2561,11 @@ static Word16 shb_DTX_fx( wb_ener_fx = L_deposit_l( 0 ); FOR( i = 0; i < st_fx->L_frame; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + wb_ener_fx = L_mac_sat( wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i] ); +#else wb_ener_fx = L_mac_o( wb_ener_fx, syn_12k8_16k[i], syn_12k8_16k[i], &Overflow ); +#endif } wb_ener_fx = L_add( Mpy_32_16_1( wb_ener_fx, 128 ), 1 ); /* 128 in Q15, wb_ener_fx in Q1 */ @@ -2540,7 +2574,11 @@ static Word16 shb_DTX_fx( fra = Log2_norm_lc( L_shl( wb_ener_fx, exp ) ); exp = sub( 30 - 1, exp ); wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - log_wb_ener_fx = round_fx_o( L_shl_o( wb_ener_fx, 10, &Overflow ), &Overflow ); /* log_wb_ener_fx in Q8 */ +#ifdef ISSUE_1867_replace_overflow_libenc + log_wb_ener_fx = round_fx_sat( L_shl_sat( wb_ener_fx, 10 ) ); /* log_wb_ener_fx in Q8 */ +#else + log_wb_ener_fx = round_fx_o( L_shl_o( wb_ener_fx, 10, &Overflow ), &Overflow ); /* log_wb_ener_fx in Q8 */ +#endif exp = norm_l( shb_ener_fx ); fra = Log2_norm_lc( L_shl( shb_ener_fx, exp ) ); exp = sub( 30 - 1, exp ); @@ -2559,7 +2597,11 @@ static Word16 shb_DTX_fx( move16(); } - log_shb_ener_fx = sub_o( round_fx_o( L_shl_o( shb_ener_fx, 10, &Overflow ), &Overflow ), att, &Overflow ); /* log_shb_ener_fx in Q8 */ +#ifdef ISSUE_1867_replace_overflow_libenc + log_shb_ener_fx = sub_sat( round_fx_sat( L_shl_sat( shb_ener_fx, 10 ) ), att ); /* log_shb_ener_fx in Q8 */ +#else + log_shb_ener_fx = sub_o( round_fx_o( L_shl_o( shb_ener_fx, 10, &Overflow ), &Overflow ), att, &Overflow ); /* log_shb_ener_fx in Q8 */ +#endif IF( hDtxEnc->first_CNG == 0 ) { hTdCngEnc->mov_wb_cng_ener_fx = log_wb_ener_fx; @@ -2968,10 +3010,11 @@ static Word16 shb_DTX_ivas_fx( TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; - +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif shb_new_speech_fx = shb_old_speech_fx + ( ACELP_LOOK_12k8 + L_SUBFR ) * 5 / 4; @@ -2990,7 +3033,11 @@ static Word16 shb_DTX_ivas_fx( wb_ener_fx = L_deposit_l( 0 ); FOR( i = 0; i < st->L_frame; i++ ) { - wb_ener_fx = L_mac_o( wb_ener_fx, syn_12k8_16k_fx[i], syn_12k8_16k_fx[i], &Overflow ); // ( Q0 + Q0 + Q1 ) --> Q1 due to left shift in L_mac +#ifdef ISSUE_1867_replace_overflow_libenc + wb_ener_fx = L_mac_sat( wb_ener_fx, syn_12k8_16k_fx[i], syn_12k8_16k_fx[i] ); // ( Q0 + Q0 + Q1 ) --> Q1 due to left shift in L_mac +#else + wb_ener_fx = L_mac_o( wb_ener_fx, syn_12k8_16k_fx[i], syn_12k8_16k_fx[i], &Overflow ); // ( Q0 + Q0 + Q1 ) --> Q1 due to left shift in L_mac +#endif } wb_ener_fx = L_add( Mpy_32_16_1( wb_ener_fx, 128 ), 1 ); /* 128 in Q15, wb_ener_fx in Q1 */ @@ -3000,7 +3047,11 @@ static Word16 shb_DTX_ivas_fx( exp = sub( 30 - 1, exp ); wb_ener_fx = Mpy_32_16( exp, fra, LG10 ); - log_wb_ener_fx = round_fx_o( L_shl_o( wb_ener_fx, 10, &Overflow ), &Overflow ); /* log_wb_ener_fx in Q8 */ +#ifdef ISSUE_1867_replace_overflow_libenc + log_wb_ener_fx = round_fx_sat( L_shl_sat( wb_ener_fx, 10 ) ); /* log_wb_ener_fx in Q8 */ +#else + log_wb_ener_fx = round_fx_o( L_shl_o( wb_ener_fx, 10, &Overflow ), &Overflow ); /* log_wb_ener_fx in Q8 */ +#endif exp = norm_l( shb_ener_fx ); fra = Log2_norm_lc( L_shl( shb_ener_fx, exp ) ); exp = sub( 30 - 1, exp ); @@ -3024,8 +3075,11 @@ static Word16 shb_DTX_ivas_fx( move16(); } - +#ifdef ISSUE_1867_replace_overflow_libenc + log_shb_ener_fx = sub_sat( round_fx_sat( L_shl_sat( shb_ener_fx, 10 ) ), att_fx ); /* log_shb_ener_fx in Q8 */ +#else log_shb_ener_fx = sub_o( round_fx_o( L_shl_o( shb_ener_fx, 10, &Overflow ), &Overflow ), att_fx, &Overflow ); /* log_shb_ener_fx in Q8 */ +#endif IF( st->hDtxEnc->first_CNG == 0 ) { diff --git a/lib_enc/cod2t32_fx.c b/lib_enc/cod2t32_fx.c index 5c3684429219ea5042ee5ccf5c034765eba522d0..156b38ce491a042e737d03d6ee5a89d8bd9b3f04 100644 --- a/lib_enc/cod2t32_fx.c +++ b/lib_enc/cod2t32_fx.c @@ -47,9 +47,11 @@ void acelp_2t32_fx( Word32 L_tmp; Word16 rrixix[NB_TRACK_FCB_2T][NB_POS_FCB_2T]; Word16 rrixiy[MSIZE]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*----------------------------------------------------------------* * Compute rrixix[][] needed for the codebook search. @@ -63,11 +65,19 @@ void acelp_2t32_fx( L_cor = L_deposit_h( 1 ); FOR( i = 0; i < NB_POS_FCB_2T; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_cor = L_mac_sat( L_cor, *ptr_h1, *ptr_h1 ); +#else L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow ); +#endif ptr_h1++; *p1-- = extract_h( L_cor ); move16(); /*Q9 Q7*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_cor = L_mac_sat( L_cor, *ptr_h1, *ptr_h1 ); +#else L_cor = L_mac_o( L_cor, *ptr_h1, *ptr_h1, &Overflow ); +#endif ptr_h1++; *p0-- = extract_h( L_cor ); move16(); /*Q9 Q7*/ @@ -108,17 +118,28 @@ void acelp_2t32_fx( L_cor = L_mult( *ptr_h1++, *ptr_h2++ ); // Q(12+12+1) FOR( i = k; i < NB_POS_FCB_2T - 1; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + *p1 = round_fx_sat( L_cor ); // Q(25-16) + L_cor = L_mac_sat( L_cor, *ptr_h1++, *ptr_h2++ ); + *p0 = round_fx_sat( L_cor ); // Q(9) + L_cor = L_mac_sat( L_cor, *ptr_h1++, *ptr_h2++ ); +#else *p1 = round_fx_o( L_cor, &Overflow ); // Q(25-16) L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); *p0 = round_fx_o( L_cor, &Overflow ); // Q(9) L_cor = L_mac_o( L_cor, *ptr_h1++, *ptr_h2++, &Overflow ); +#endif move16(); move16(); p1 -= ( NB_POS_FCB_2T + 1 ); p0 -= ( NB_POS_FCB_2T + 1 ); } +#ifdef ISSUE_1867_replace_overflow_libenc + *p1 = round_fx_sat( L_cor ); // Q9 +#else *p1 = round_fx_o( L_cor, &Overflow ); // Q9 +#endif pos -= NB_POS_FCB_2T; move16(); pos2--; @@ -221,9 +242,15 @@ void acelp_2t32_fx( FOR( i1 = 1; i1 < L_SUBFR; i1 += STEP ) { ps2 = add( ps1, dn_p[i1] ); +#ifdef ISSUE_1867_replace_overflow_libenc + alp2 = add_sat( alp1, add_sat( *p1++, *p2++ ) ); + sq = mult( ps2, ps2 ); + s = L_msu_sat( L_mult( alpk, sq ), psk, alp2 ); +#else alp2 = add_o( alp1, add_o( *p1++, *p2++, &Overflow ), &Overflow ); sq = mult( ps2, ps2 ); s = L_msu_o( L_mult( alpk, sq ), psk, alp2, &Overflow ); +#endif IF( s > 0 ) { psk = sq; diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index e1914aeb5bb7b2e51f123b8f0ca042512c174644..5dae2f7f09fcecaa0f02f51d065e9c24b32a09f3 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -75,9 +75,11 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * Word16 dummy = 0; move16(); ACELP_config *acelp_cfg; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif acelp_cfg = &( st->acelp_cfg ); @@ -351,13 +353,22 @@ Word16 coder_acelp_fx( /* o : SEGSNR for CL decision * Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); Ltmp = L_shl( Ltmp, Q_new_p5 ); Ltmp = L_mac( Ltmp, gain_pit, exc[i + i_subfr] ); +#ifdef ISSUE_1867_replace_overflow_libenc + exc2[i] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); +#else exc2[i] = round_fx_sat( L_shl_o( Ltmp, 1, &Overflow ) ); +#endif move16(); Ltmp2 = Mpy_32_16_1( gain_code, code[i] ); Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); Ltmp = L_add_sat( Ltmp, Ltmp2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here */ + exc[i + i_subfr] = round_fx_sat( Ltmp ); +#else Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here */ exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); +#endif move16(); } /*-----------------------------------------------------------------* diff --git a/lib_enc/core_enc_ol_fx.c b/lib_enc/core_enc_ol_fx.c index bd9d5375f1d74b5f8e1a142a3dbc997ac1ade924..020af121c46ce2d64e56e4ae8522642797e56098 100644 --- a/lib_enc/core_enc_ol_fx.c +++ b/lib_enc/core_enc_ol_fx.c @@ -82,10 +82,13 @@ void core_encode_openloop_fx( Word16 lsp_old_q_rf[M + 1], lsf_old_q_rf[M + 1]; (void) vad_hover_flag; (void) vad_flag_dtx; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif + TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; RF_ENC_HANDLE hRF = st->hRF; @@ -552,7 +555,11 @@ void core_encode_openloop_fx( /*v_sub(lsf_uq_rf, lsf_q_1st_rf, lsf_q_d_rf, M);*/ FOR( i = 0; i < M; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + lsf_q_d_rf[i] = shl_sat( mult_r( sub_sat( lsf_uq_rf[i], lsf_q_1st_rf[i] ), 25600 ), 5 ); +#else lsf_q_d_rf[i] = shl_sat( mult_r( sub_o( lsf_uq_rf[i], lsf_q_1st_rf[i], &Overflow ), 25600 ), 5 ); +#endif move16(); /*input value is in Qx2.56, convert to Q6 to match table, quantizer table kept at Q6 to avoid losing precision */ /*Assume this difference data max range can be represented by Q6*/ @@ -753,9 +760,11 @@ static void closest_centroid_rf( Word16 tmp, tmpL; Word64 werr_64; Word32 L_tmp, best_werr, werr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif ind_vec[0] = 0; @@ -771,8 +780,13 @@ static void closest_centroid_rf( tmpL = i_mult2( i, length ); FOR( j = 0; j < length; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = sub_sat( data[j], quantizer[tmpL + j] ); + L_tmp = L_mult_sat( tmp, tmp ); +#else tmp = sub_o( data[j], quantizer[tmpL + j], &Overflow ); L_tmp = L_mult_o( tmp, tmp, &Overflow ); +#endif werr_64 = W_mac_32_16( werr_64, L_tmp, weights[j] ); } werr = W_sat_m( werr_64 ); @@ -824,9 +838,11 @@ void core_acelp_tcx20_switching_fx( Word16 snr_tcx, snr_acelp, dsnr; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; SP_MUS_CLAS_HANDLE hSpMusClas = st->hSpMusClas; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Check minimum pitch for quantization */ @@ -1103,7 +1119,11 @@ void core_acelp_tcx20_switching_fx( FOR( j = 0; j < L_SUBFR; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + tmp32 = L_mac0_sat( tmp32, st->wspeech_enc[i + j], st->wspeech_enc[i + j] ); +#else tmp32 = L_mac0_o( tmp32, st->wspeech_enc[i + j], st->wspeech_enc[i + j], &Overflow ); +#endif } tmp32 = L_shr( BASOP_Util_Log2( tmp32 ), 9 ); /* 15Q16 */ tmp32 = L_add( tmp32, L_sub( 0x1F0000, L_shl( L_deposit_h( add( Q_new, sub( shift, 1 ) ) ), 1 ) ) ); /* wspeech_enc scaling */ @@ -1121,7 +1141,11 @@ void core_acelp_tcx20_switching_fx( tcx_snr = L_shl( Mpy_32_16_1( tcx_snr, 0x6054 ), 2 ); /* 0x6054 -> 10/log2(10) (2Q13) */ BASOP_SATURATE_WARNING_OFF_EVS +#ifdef ISSUE_1867_replace_overflow_libenc + snr_tcx = round_fx_sat( L_shl_sat( tcx_snr, 8 ) ); /* 7Q8 */ +#else snr_tcx = round_fx_o( L_shl_o( tcx_snr, 8, &Overflow ), &Overflow ); /* 7Q8 */ +#endif BASOP_SATURATE_WARNING_ON_EVS /*--------------------------------------------------------------* @@ -1155,11 +1179,19 @@ void core_acelp_tcx20_switching_fx( FOR( j = 0; j < L_SUBFR; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + signal = L_mac0_sat( signal, st->wspeech_enc[i + j], st->wspeech_enc[i + j] ); + + tmp16 = round_fx_sat( L_shl_sat( Mpy_32_16_r( gain, st->wspeech_enc[i + j - T0] ), 15 ) ); + tmp16 = sub_sat( st->wspeech_enc[i + j], tmp16 ); + noise = L_mac0_sat( noise, tmp16, tmp16 ); +#else signal = L_mac0_o( signal, st->wspeech_enc[i + j], st->wspeech_enc[i + j], &Overflow ); tmp16 = round_fx_o( L_shl_o( Mpy_32_16_r( gain, st->wspeech_enc[i + j - T0] ), 15, &Overflow ), &Overflow ); tmp16 = sub_o( st->wspeech_enc[i + j], tmp16, &Overflow ); noise = L_mac0_o( noise, tmp16, tmp16, &Overflow ); +#endif } /* Assume always 4 sub frames. */ /*assert( (st->L_frame / L_SUBFR) == 4);*/ @@ -1212,7 +1244,11 @@ void core_acelp_tcx20_switching_fx( test(); if ( ( GT_16( snr_acelp, snr_tcx ) ) && ( LT_16( snr_acelp, add( snr_tcx, 512 /*2.0f Q8*/ ) ) ) && +#ifdef ISSUE_1867_replace_overflow_libenc + ( LT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 416 /*3.25f Q7*/ ) || EQ_16( stab_fac, 0x7fff /*1 Q15*/ ) || +#else ( LT_16( add_o( st->prevTempFlatness_fx, currFlatness, &Overflow ), 416 /*3.25f Q7*/ ) || EQ_16( stab_fac, 0x7fff /*1 Q15*/ ) || +#endif ( EQ_32( st->sr_core, INT_FS_12k8 ) && EQ_16( st->sp_aud_decision0, 1 ) && LT_16( add_sat( st->prevTempFlatness_fx, currFlatness ), 2560 /*20.f Q7*/ ) ) ) && ( LE_16( st->acelpFramesCount, 6 ) ) ) { diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 56b22c2069b96dd3ce2e6b283ebd2c5e7ccfb8ca..135d560d16fd5005c0ee426840836d377042b6b3 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -31,9 +31,11 @@ void corr_xh_fx( { Word16 i, j, k; Word32 L_tmp, y32[L_SUBFR], L_maxloc, L_tot; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -47,7 +49,11 @@ void corr_xh_fx( L_tmp = L_mac( 1L, x[i], h[0] ); /* 1 -> to avoid null dn[] Qx+15*/ FOR( j = i; j < L_SUBFR - 1; j++ ) { - L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); /*Qx+15*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, x[j + 1], h[j + 1 - i] ); /*Qx+15*/ +#else + L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); /*Qx+15*/ +#endif } y32[i] = L_tmp; /*Qx+15*/ @@ -57,8 +63,13 @@ void corr_xh_fx( } /* tot += 3*max / 8 */ L_maxloc = L_shr( L_maxloc, 2 ); - L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ - L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add_sat( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ +#else + L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ + L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#endif } /* Find the number of right shifts to do on y32[] so that */ @@ -82,9 +93,11 @@ void corr_hh_ivas_fx( { Word16 i, j, k; Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -98,7 +111,11 @@ void corr_hh_ivas_fx( L_tmp = L_mac( 1L, shr( h[i], 3 ), shr( h[0], 3 ) ); /* 1 -> to avoid null dn[] */ // 2*(15 - norm_s(h[0]) -3) - 1 FOR( j = i; j < L_subfr - 1; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, shr( h[j + 1], 3 ), shr( h[j + 1 - i], 3 ) ); // 2*(15 - norm_s(h[0]) -3) - 1 //?sat +#else L_tmp = L_mac_o( L_tmp, shr( h[j + 1], 3 ), shr( h[j + 1 - i], 3 ), &Overflow ); // 2*(15 - norm_s(h[0]) -3) - 1 +#endif } y32[i] = L_tmp; // 2*(15 - norm_s(h[0]) -3) - 1 @@ -108,8 +125,13 @@ void corr_hh_ivas_fx( } /* tot += 3*max / 8 */ L_maxloc = L_shr( L_maxloc, 2 ); - L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ - L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add_sat( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ +#else + L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ + L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#endif } /* Find the number of right shifts to do on y32[] so that */ @@ -139,9 +161,11 @@ void corr_xh_ivas_fx( { Word16 i, j, k; Word32 L_tmp, y32[L_SUBFR * 2], L_maxloc, L_tot; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /* first keep the result on 32 bits and find absolute maximum */ @@ -155,7 +179,11 @@ void corr_xh_ivas_fx( L_tmp = L_mac( 0, x[i], h[0] ); // Qx+(14 - norm_s(h[0])) + 1 FOR( j = i; j < L_subfr - 1; j++ ) { - L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); // Qx+(14 - norm_s(h[0])) + 1 +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, x[j + 1], h[j + 1 - i] ); // Qx+(14 - norm_s(h[0])) + 1 +#else + L_tmp = L_mac_o( L_tmp, x[j + 1], h[j + 1 - i], &Overflow ); // Qx+(14 - norm_s(h[0])) + 1 +#endif } y32[i] = L_tmp; // Qx+(14 - norm_s(h[0])) + 1 @@ -165,8 +193,13 @@ void corr_xh_ivas_fx( } /* tot += 3*max / 8 */ L_maxloc = L_shr( L_maxloc, 2 ); - L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ - L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tot = L_add_sat( L_tot, L_maxloc ); /* +max/4 */ + L_tot = L_add_sat( L_tot, L_shr( L_maxloc, 1 ) ); /* +max/8 */ +#else + L_tot = L_add_o( L_tot, L_maxloc, &Overflow ); /* +max/4 */ + L_tot = L_add_o( L_tot, L_shr( L_maxloc, 1 ), &Overflow ); /* +max/8 */ +#endif } /* Find the number of right shifts to do on y32[] so that */ diff --git a/lib_enc/detect_transient_fx.c b/lib_enc/detect_transient_fx.c index 51f1cb47692fb74518524ee8f876adfb4082a58e..8a95627042e909e9ff6cc187e94c10e814fb1b62 100644 --- a/lib_enc/detect_transient_fx.c +++ b/lib_enc/detect_transient_fx.c @@ -62,22 +62,34 @@ static void hp_filter_fx( { Word16 i; Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /*y[0] = 0.4931f * *oldy + 0.7466f*(x[0] - *oldx); */ - L_tmp = L_mult( sub_o( x[0], *oldx, &Overflow ), 24465 /*0.7466f in Q15*/ ); /*Q_new+16 */ - L_tmp = L_mac_sat( L_tmp, *oldy, 16158 /*0.4931f in Q15*/ ); /*Q_new+16 */ - y[0] = round_fx_sat( L_tmp ); /*Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mult( sub_sat( x[0], *oldx ), 24465 /*0.7466f in Q15*/ ); /*Q_new+16 */ +#else + L_tmp = L_mult( sub_o( x[0], *oldx, &Overflow ), 24465 /*0.7466f in Q15*/ ); /*Q_new+16 */ +#endif + L_tmp = L_mac_sat( L_tmp, *oldy, 16158 /*0.4931f in Q15*/ ); /*Q_new+16 */ + y[0] = round_fx_sat( L_tmp ); /*Q_new */ FOR( i = 1; i < L; i++ ) { /*y[i] = 0.4931f*y[i-1] + 0.7466f*(x[i] - x[i-1]); */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mult( sub_sat( x[i], x[i - 1] ), 24465 /*0.7466f in Q15*/ ); /*Q_new+16 */ + L_tmp = L_mac_sat( L_tmp, y[i - 1], 16158 /*0.4931f in Q15*/ ); /*Q_new+16 */ + y[i] = round_fx_sat( L_tmp ); /*Q_new */ +#else L_tmp = L_mult( sub_o( x[i], x[i - 1], &Overflow ), 24465 /*0.7466f in Q15*/ ); /*Q_new+16 */ L_tmp = L_mac_o( L_tmp, y[i - 1], 16158 /*0.4931f in Q15*/, &Overflow ); /*Q_new+16 */ y[i] = round_fx_o( L_tmp, &Overflow ); /*Q_new */ +#endif } *oldx = x[L - 1]; @@ -117,9 +129,11 @@ Word16 detect_transient_fx( Word32 E_low_fx, E_high_fx; Word16 temp16, Thres_fx = 0; Word16 exp; +#ifdef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif shift = 0; @@ -151,7 +165,11 @@ Word16 detect_transient_fx( FOR( i = 0; i < L / 4; i++ ) { /*EnergyLT += out_filt[i] * out_filt[i]; */ +#ifdef ISSUE_1867_replace_overflow_libenc + EnergyLT = L_mac0_sat( EnergyLT, out_filt_fx[i], out_filt_fx[i] ); /*2Q_new */ +#else EnergyLT = L_mac0_o( EnergyLT, out_filt_fx[i], out_filt_fx[i], &Overflow ); /*2Q_new */ +#endif } } ELSE @@ -170,14 +188,27 @@ Word16 detect_transient_fx( FOR( i = 0; i < L / 4; i++ ) { temp16 = extract_l( L_shr( out_filt_fx[i + blk * ( L / 4 )], 12 ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + Energy_fx = L_add_sat( Energy_fx, L_mult0( temp16, temp16 ) ); +#else Energy_fx = L_add_o( Energy_fx, L_mult0( temp16, temp16 ), &Overflow ); - temp16 = shr( in_fx[i + blk * ( L / 4 )], Q_new ); /*Q0*/ - Energy_in_fx[blk + 1] = L_add_o( Energy_in_fx[blk + 1], L_mult0( temp16, temp16 ), &Overflow ); /*Q0*/ +#endif + temp16 = shr( in_fx[i + blk * ( L / 4 )], Q_new ); /*Q0*/ +#ifdef ISSUE_1867_replace_overflow_libenc + Energy_in_fx[blk + 1] = L_add_sat( Energy_in_fx[blk + 1], L_mult0( temp16, temp16 ) ); /*Q0*/ +#else + Energy_in_fx[blk + 1] = L_add_o( Energy_in_fx[blk + 1], L_mult0( temp16, temp16 ), &Overflow ); /*Q0*/ +#endif move32(); } - E_in_fx = L_add_o( E_in_fx, Energy_in_fx[blk + 1], &Overflow ); /*Q0*/ - E_out_fx = L_add_o( E_out_fx, Energy_fx, &Overflow ); /*Q0*/ +#ifdef ISSUE_1867_replace_overflow_libenc + E_in_fx = L_add_sat( E_in_fx, Energy_in_fx[blk + 1] ); /*Q0*/ + E_out_fx = L_add_sat( E_out_fx, Energy_fx ); /*Q0*/ +#else + E_in_fx = L_add_o( E_in_fx, Energy_in_fx[blk + 1], &Overflow ); /*Q0*/ + E_out_fx = L_add_o( E_out_fx, Energy_fx, &Overflow ); /*Q0*/ +#endif Thres_fx = 2185; /*1 /15 Q15*/ move16(); @@ -201,13 +232,21 @@ Word16 detect_transient_fx( FOR( i = 0; i < L / 8; i++ ) { /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ - L_tmp = L_mac0_o( L_tmp, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )], &Overflow ); /*2Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac0_sat( L_tmp, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )] ); /*2Q_new */ +#else + L_tmp = L_mac0_o( L_tmp, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )], &Overflow ); /*2Q_new */ +#endif } L_tmp2 = L_deposit_l( 0 ); FOR( ; i < L / 4; i++ ) { /*Energy += out_filt_fx[i + blk*(L/4)] * out_filt_fx[i + blk*(L/4)]; */ - L_tmp2 = L_mac0_o( L_tmp2, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )], &Overflow ); /*2Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp2 = L_mac0_sat( L_tmp2, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )] ); /*2Q_new */ +#else + L_tmp2 = L_mac0_o( L_tmp2, out_filt_fx[i + blk * ( L / 4 )], out_filt_fx[i + blk * ( L / 4 )], &Overflow ); /*2Q_new */ +#endif } Overflow = 0; move16(); @@ -218,10 +257,14 @@ Word16 detect_transient_fx( shift = 1; move16(); } +#ifndef ISSUE_1867_replace_overflow_libenc Overflow = 0; move16(); Energy = L_add_o( L_shr( L_tmp, shift ), L_shr( L_tmp2, shift ), &Overflow ); /*2Q_new - shift*/ +#else + Energy = L_add_sat( L_shr( L_tmp, shift ), L_shr( L_tmp2, shift ) ); /*2Q_new - shift*/ +#endif test(); IF( EQ_16( st_fx->extl, SWB_BWE ) || EQ_16( st_fx->extl, FB_BWE ) ) { @@ -262,7 +305,11 @@ Word16 detect_transient_fx( } /*EnergyLT = 0.75f*EnergyLT + 0.25f*Energy; */ /*0.75f*EnergyLT in Q0 //0.25f*Energy in Q0 */ +#ifdef ISSUE_1867_replace_overflow_libenc + EnergyLT = L_add_sat( Mult_32_16( EnergyLT, 24576 /*0.75f in Q15*/ ), Mult_32_16( Energy, shl( 8192 /*0.25 in Q15*/, shift ) ) ); /*2Q_new */ +#else EnergyLT = L_add_o( Mult_32_16( EnergyLT, 24576 /*0.75f in Q15*/ ), Mult_32_16( Energy, shl( 8192 /*0.25 in Q15*/, shift ) ), &Overflow ); /*2Q_new */ +#endif } } st_fx->EnergyLT_fx = EnergyLT; diff --git a/lib_enc/dtx_fx.c b/lib_enc/dtx_fx.c index 442c548e9152804088fd2bdfcbed2ace7c3f6afc..e7ac422add45e2c71e556d621728ed98962ba894 100644 --- a/lib_enc/dtx_fx.c +++ b/lib_enc/dtx_fx.c @@ -74,9 +74,11 @@ void dtx_ivas_fx( TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word32 total_brate_ref; @@ -461,7 +463,11 @@ void dtx_ivas_fx( speech++; FOR( i = 1; i < L_FRAME / 16; i++ ) { - L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); /*2*Q_speech*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac0_sat( L_tmp, *speech, *speech ); /*2*Q_speech*/ +#else + L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); /*2*Q_speech*/ +#endif speech++; } hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /* Q(-7) */ @@ -631,9 +637,11 @@ void dtx_fx( TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; Word16 last_br_cng_flag, last_br_flag, br_dtx_flag; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif IF( st_fx->dtx_sce_sba != 0 ) @@ -931,7 +939,11 @@ void dtx_fx( speech++; FOR( i = 1; i < L_FRAME / 16; i++ ) { - L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); /*2*Q_speech*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac0_sat( L_tmp, *speech, *speech ); /*2*Q_speech*/ +#else + L_tmp = L_mac0_o( L_tmp, *speech, *speech, &Overflow ); /*2*Q_speech*/ +#endif speech++; } hDtxEnc->frame_ener_fx = L_add( hDtxEnc->frame_ener_fx, L_shr( L_tmp, Q_speech2 ) ); /*Q(-7) */ @@ -1236,8 +1248,10 @@ void dtx_hangover_control_fx( VAD_HANDLE hVAD = st_fx->hVAD; DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /* get current frame exc energy in log2 */ @@ -1407,7 +1421,11 @@ void dtx_hangover_control_fx( move16(); FOR( j = 0; j < m; j++ ) { - lsp_est[i] = add_o( lsp_est[i], tmp[j * M + i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + lsp_est[i] = add_sat( lsp_est[i], tmp[j * M + i] ); /*Q15 */ +#else + lsp_est[i] = add_o( lsp_est[i], tmp[j * M + i], &Overflow ); /*Q15 */ +#endif } lsp_est[i] = sub( lsp_est[i], tmp[max_idx[0] * M + i] ); /*Q15 */ @@ -1423,12 +1441,20 @@ void dtx_hangover_control_fx( move16(); FOR( j = 0; j < m; j++ ) { - lsp_est[i] = add_o( lsp_est[i], tmp[j * M + i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + lsp_est[i] = add_sat( lsp_est[i], tmp[j * M + i] ); /*Q15 */ +#else + lsp_est[i] = add_o( lsp_est[i], tmp[j * M + i], &Overflow ); /*Q15 */ +#endif } +#ifdef ISSUE_1867_replace_overflow_libenc + lsp_est[i] = sub_sat( lsp_est[i], add_sat( tmp[max_idx[0] * M + i], tmp[max_idx[1] * M + i] ) ); /*Q15 */ +#else lsp_est[i] = sub_o( lsp_est[i], add_o( tmp[max_idx[0] * M + i], tmp[max_idx[1] * M + i], &Overflow ), &Overflow ); /*Q15 */ - S_tmp = div_s( 1, sub( m, 2 ) ); /*Q15 */ - lsp_est[i] = mult_r( lsp_est[i], S_tmp ); /*Q15 */ +#endif + S_tmp = div_s( 1, sub( m, 2 ) ); /*Q15 */ + lsp_est[i] = mult_r( lsp_est[i], S_tmp ); /*Q15 */ } } @@ -1436,8 +1462,12 @@ void dtx_hangover_control_fx( move16(); FOR( i = 0; i < M; i++ ) { - Dlsp_n2e = add_o( Dlsp_n2e, abs_s( sub( lsp_new_fx[i], lsp_est[i] ) ), &Overflow ); /*Q15 */ - lsp_est[i] = add( mult_r( 26214, lsp_est[i] ), mult_r( 6554, lsp_new_fx[i] ) ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Dlsp_n2e = add_sat( Dlsp_n2e, abs_s( sub( lsp_new_fx[i], lsp_est[i] ) ) ); /*Q15 */ +#else + Dlsp_n2e = add_o( Dlsp_n2e, abs_s( sub( lsp_new_fx[i], lsp_est[i] ) ), &Overflow ); /*Q15 */ +#endif + lsp_est[i] = add( mult_r( 26214, lsp_est[i] ), mult_r( 6554, lsp_new_fx[i] ) ); /*Q15 */ } /* get deviation of CNG parameters between newly estimated and current state memory */ @@ -1449,7 +1479,11 @@ void dtx_hangover_control_fx( FOR( i = 0; i < M; i++ ) { S_tmp = abs_s( sub( hDtxEnc->lspCNG_fx[i], lsp_est[i] ) ); /*Q15 */ - Dlsp = add_o( Dlsp, S_tmp, &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Dlsp = add_sat( Dlsp, S_tmp ); /*Q15 */ +#else + Dlsp = add_o( Dlsp, S_tmp, &Overflow ); /*Q15 */ +#endif IF( GT_16( S_tmp, S_max ) ) { S_max = S_tmp; /*Q15 */ diff --git a/lib_enc/enc_acelp_fx.c b/lib_enc/enc_acelp_fx.c index f1c87722b113848d62d60c2551f3e0d09be515a9..2053a12932c98eae3e56db050da6d6886e9bc3fa 100644 --- a/lib_enc/enc_acelp_fx.c +++ b/lib_enc/enc_acelp_fx.c @@ -58,9 +58,11 @@ void E_ACELP_h_vec_corr1_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 trac Word16 *dn2; Word16 *p0, *p1, *p2; Word32 L_sum; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif dn2 = &dn2_pos[( track * 8 )]; /*Q0*/ @@ -75,20 +77,36 @@ void E_ACELP_h_vec_corr1_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 trac p2 = &vec[dn]; /*Qx*/ FOR( j = dn; j < L_SUBFR - 1; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_sum = L_mac_sat( L_sum, *p1++, *p2++ ); /*2*Qx+1*/ +#else L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); /*2*Qx+1*/ +#endif } - corr = mac_ro( L_sum, *p1++, *p2++, &Overflow ); /*Q9*/ +#ifdef ISSUE_1867_replace_overflow_libenc + corr = mac_r_sat( L_sum, *p1++, *p2++ ); /*Q9*/ +#else + corr = mac_ro( L_sum, *p1++, *p2++, &Overflow ); /*Q9*/ +#endif /*cor[dn >> 2] = sign[dn] * s + p0[dn >> 2];*/ j = shr( dn, 2 ); if ( sign[dn] > 0 ) { - corr = add_o( p0[j], corr, &Overflow ); /*Q9*/ +#ifdef ISSUE_1867_replace_overflow_libenc + corr = add_sat( p0[j], corr ); /*Q9*/ +#else + corr = add_o( p0[j], corr, &Overflow ); /*Q9*/ +#endif } if ( sign[dn] < 0 ) { - corr = sub_o( p0[j], corr, &Overflow ); /*Q9*/ +#ifdef ISSUE_1867_replace_overflow_libenc + corr = sub_sat( p0[j], corr ); /*Q9*/ +#else + corr = sub_o( p0[j], corr, &Overflow ); /*Q9*/ +#endif } cor[j] = corr; /*Q9*/ @@ -102,9 +120,11 @@ void E_ACELP_h_vec_corr2_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 trac Word16 i, j, pos, corr; Word16 *p0, *p1, *p2; Word32 L_sum; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif p0 = rrixix[track]; /*Q9*/ @@ -118,12 +138,30 @@ void E_ACELP_h_vec_corr2_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 trac p2 = &vec[pos]; /*Qx*/ FOR( j = pos; j < L_SUBFR - 1; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_sum = L_mac_sat( L_sum, *p1++, *p2++ ); /* 2*Qx+1 */ +#else L_sum = L_mac_o( L_sum, *p1++, *p2++, &Overflow ); /* 2*Qx+1 */ +#endif } - corr = mac_ro( L_sum, *p1++, *p2++, &Overflow ); /*Q9*/ +#ifdef ISSUE_1867_replace_overflow_libenc + corr = mac_r_sat( L_sum, *p1++, *p2++ ); /*Q9*/ +#else + corr = mac_ro( L_sum, *p1++, *p2++, &Overflow ); /*Q9*/ +#endif /*cor[i] = s * sign[track] + p0[i];*/ +#ifdef ISSUE_1867_replace_overflow_libenc + if ( sign[pos] > 0 ) + { + corr = add_sat( *p0++, corr ); /*Q9*/ + } + if ( sign[pos] < 0 ) + { + corr = sub_sat( *p0++, corr ); /*Q9*/ + } +#else if ( sign[pos] > 0 ) { corr = add_o( *p0++, corr, &Overflow ); /*Q9*/ @@ -132,6 +170,7 @@ void E_ACELP_h_vec_corr2_fx( Word16 h[] /*Qx*/, Word16 vec[] /*Qx*/, UWord8 trac { corr = sub_o( *p0++, corr, &Overflow ); /*Q9*/ } +#endif cor[i] = corr; /*Q9*/ move16(); @@ -174,10 +213,12 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix /*Q0*/, UWord8 track_x /*Q0* Word32 xy_save; Word16 check = 0; /* debug code not instrumented */ +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /* eight dn2 max positions per track */ @@ -195,7 +236,11 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix /*Q0*/, UWord8 track_x /*Q0* sqk[0] = -1; move16(); x2 = shr( pos_x[0], 2 ); /*Qdn*/ +#ifdef ISSUE_1867_replace_overflow_libenc + if ( mac_r_sat( L_mac_sat( L_mac_sat( alp0, cor_x[x2], _1_ ), cor_y[0], _1_ ), rrixiy[track_x][( x2 * 16 )], _1_ ) < 0 ) +#else if ( mac_ro( L_mac_o( L_mac_o( alp0, cor_x[x2], _1_, &Overflow ), cor_y[0], _1_, &Overflow ), rrixiy[track_x][( x2 * 16 )], _1_, &Overflow ) < 0 ) +#endif { sqk[0] = 1; move16(); @@ -215,7 +260,11 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix /*Q0*/, UWord8 track_x /*Q0* ps1 = add( ps0, dn[x] ); /*Qdn*/ /*alp1 = alp0 + cor_x[x2];*/ - alp1 = L_mac_o( alp0, cor_x[x2], _1_, &Overflow ); /*Q22*/ +#ifdef ISSUE_1867_replace_overflow_libenc + alp1 = L_mac_sat( alp0, cor_x[x2], _1_ ); /*Q22*/ +#else + alp1 = L_mac_o( alp0, cor_x[x2], _1_, &Overflow ); /*Q22*/ +#endif p1 = cor_y; /*Qx*/ p2 = &rrixiy[track_x][( x2 * 16 )]; /*Q9*/ @@ -227,9 +276,14 @@ static void E_ACELP_2pulse_search( Word16 nb_pos_ix /*Q0*/, UWord8 track_x /*Q0* move16(); /*alp2 = alp1 + (*p1++) + (*p2++);*/ - alp2 = L_mac_o( alp1, *p1++, _1_, &Overflow ); /*Qx+12+1*/ - alp2_16 = mac_ro( alp2, *p2++, _1_, &Overflow ); /*Q6*/ - alpk[1 - ik] = alp2_16; /*Q6*/ +#ifdef ISSUE_1867_replace_overflow_libenc + alp2 = L_mac_sat( alp1, *p1++, _1_ ); /*Qx+12+1*/ + alp2_16 = mac_r_sat( alp2, *p2++, _1_ ); /*Q6*/ +#else + alp2 = L_mac_o( alp1, *p1++, _1_, &Overflow ); /*Qx+12+1*/ + alp2_16 = mac_ro( alp2, *p2++, _1_, &Overflow ); /*Q6*/ +#endif + alpk[1 - ik] = alp2_16; /*Q6*/ move16(); /*sq = ps2 * ps2;*/ @@ -523,19 +577,29 @@ Word16 E_ACELP_xy1_corr_fx( Word16 xn[] /*Q15-exp_xn*/, Word16 y1[] /*Q15-exp_xn Word16 i, Q_xn; Word16 xy, yy, exp_xy, exp_yy, gain; Word32 L_off; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif L_off = L_shr( 10737418l /*0.01f/2.0f Q31*/, s_min( add( exp_xn, exp_xn ), 31 ) ); L_off = L_max( 1, L_off ); /* ensure at least a '1' */ /* Compute scalar product t1: */ - yy = round_fx_o( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ), &Overflow ); /*Q15 - exp_yy*/ +#ifdef ISSUE_1867_replace_overflow_libenc + yy = round_fx_sat( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ) ); /*Q15 - exp_yy*/ +#else + yy = round_fx_o( Dot_product15_offs( y1, y1, L_subfr, &exp_yy, L_off ), &Overflow ); /*Q15 - exp_yy*/ +#endif /* Compute scalar product t0: */ - xy = round_fx_o( Dot_product12_offs( xn, y1, L_subfr, &exp_xy, L_off ), &Overflow ); /*Q15 - exp_xy*/ +#ifdef ISSUE_1867_replace_overflow_libenc + xy = round_fx_sat( Dot_product12_offs( xn, y1, L_subfr, &exp_xy, L_off ) ); /*Q15 - exp_xy*/ +#else + xy = round_fx_o( Dot_product12_offs( xn, y1, L_subfr, &exp_xy, L_off ), &Overflow ); /*Q15 - exp_xy*/ +#endif /* Compute doubled format out of the exponent */ Q_xn = shl( sub( 15, exp_xn ), 1 ); g_corr->y1y1 = yy; @@ -577,7 +641,11 @@ Word16 E_ACELP_xy1_corr_fx( Word16 xn[] /*Q15-exp_xn*/, Word16 y1[] /*Q15-exp_xn Word16 tmp, exp_tmp, exp_div; /* Compute scalar product */ - tmp = round_fx_o( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ), &Overflow ); /*Q15 - exp_tmp*/ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = round_fx_sat( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ) ); /*Q15 - exp_tmp*/ +#else + tmp = round_fx_o( Dot_product12_offs( xn, xn, L_subfr, &exp_tmp, 1 ), &Overflow ); /*Q15 - exp_tmp*/ +#endif /* gain_p_snr = sqrt(/) */ tmp = BASOP_Util_Divide1616_Scale( tmp, yy, &exp_div ); exp_tmp = add( sub( exp_tmp, exp_yy ), exp_div ); @@ -587,7 +655,11 @@ Word16 E_ACELP_xy1_corr_fx( Word16 xn[] /*Q15-exp_xn*/, Word16 y1[] /*Q15-exp_xn /* Note: shl works as shl or shr. */ exp_tmp = sub( exp_tmp, 1 ); BASOP_SATURATE_WARNING_OFF_EVS +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = round_fx_sat( L_shl_sat( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp ) ); /*Q14*/ +#else tmp = round_fx_o( L_shl_o( Mpy_32_16_1( 1717986944l /*ACELP_GAINS_CONST Q31*/, tmp ), exp_tmp, &Overflow ), &Overflow ); /*Q14*/ +#endif BASOP_SATURATE_WARNING_ON_EVS gain = s_min( gain, tmp ); /*Q14*/ @@ -684,9 +756,11 @@ void E_ACELP_codebook_target_update_fx( Word16 *x /*Q_xn*/, Word16 *x2 /*Q_xn*/, { Word16 i, Q15_flag; Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif assert( gain >= 0 ); @@ -704,9 +778,17 @@ void E_ACELP_codebook_target_update_fx( Word16 *x /*Q_xn*/, Word16 *x2 /*Q_xn*/, L_tmp = L_deposit_h( x[i] ); /*Q_xn+16*/ if ( Q15_flag == 0 ) { - L_tmp = L_msu_o( L_tmp, y[i], gain, &Overflow ); /*Q_xn+15*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_msu_sat( L_tmp, y[i], gain ); /*Q_xn+15*/ +#else + L_tmp = L_msu_o( L_tmp, y[i], gain, &Overflow ); /*Q_xn+15*/ +#endif } - x2[i] = msu_ro( L_tmp, y[i], gain, &Overflow ); /*Q_xn*/ +#ifdef ISSUE_1867_replace_overflow_libenc + x2[i] = msu_r_sat( L_tmp, y[i], gain ); /*Q_xn*/ +#else + x2[i] = msu_ro( L_tmp, y[i], gain, &Overflow ); /*Q_xn*/ +#endif move16(); } } @@ -740,10 +822,12 @@ void E_ACELP_pulsesign( const Word16 cn[] /*Q_xn*/, Word16 dn[] /*Qdn*/, Word16 Word16 signs[3]; Word16 *ptr16; Word16 val, index; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /* calculate energy for normalization of cn[] and dn[] */ @@ -752,8 +836,12 @@ void E_ACELP_pulsesign( const Word16 cn[] /*Q_xn*/, Word16 dn[] /*Qdn*/, Word16 FOR( i = 1; i < L_subfr; i++ ) { - Lval = L_mac0_o( Lval, cn[i], cn[i], &Overflow ); /*2*Q_xn*/ - Lcor = L_mac0( Lcor, dn[i], dn[i] ); /*2*Qdn*/ +#ifdef ISSUE_1867_replace_overflow_libenc + Lval = L_mac0_sat( Lval, cn[i], cn[i] ); /*2*Q_xn*/ +#else + Lval = L_mac0_o( Lval, cn[i], cn[i], &Overflow ); /*2*Q_xn*/ +#endif + Lcor = L_mac0( Lcor, dn[i], dn[i] ); /*2*Qdn*/ } e_dn = 31; @@ -769,8 +857,13 @@ void E_ACELP_pulsesign( const Word16 cn[] /*Q_xn*/, Word16 dn[] /*Qdn*/, Word16 if ( i > 0 ) Lcor = L_shr( Lcor, i ); - k_dn = round_fx_o( Lval, &Overflow ); /*Q15 - e_dn*/ - k_cn = round_fx_o( Lcor, &Overflow ); /*Q15 - e_cn*/ +#ifdef ISSUE_1867_replace_overflow_libenc + k_dn = round_fx_sat( Lval ); /*Q15 - e_dn*/ + k_cn = round_fx_sat( Lcor ); /*Q15 - e_cn*/ +#else + k_dn = round_fx_o( Lval, &Overflow ); /*Q15 - e_dn*/ + k_cn = round_fx_o( Lcor, &Overflow ); /*Q15 - e_cn*/ +#endif k_cn = mult_r( 0x2000, k_cn ); /* 1 in Q13 */ k_dn = mult_r( alp, k_dn ); /* alp in Q13 */ @@ -788,9 +881,13 @@ void E_ACELP_pulsesign( const Word16 cn[] /*Q_xn*/, Word16 dn[] /*Qdn*/, Word16 FOR( i = 0; i < L_subfr; i++ ) { /*cor = (s * cn[i]) + (alp * dn[i]); MULT(1);MAC(1);*/ - Lcor = L_mult( cn[i], k_cn ); /*Q_xn + Q15 - e_cn + 1*/ - Lcor = L_mac( Lcor, dn[i], k_dn ); /*Qdn + Q15 - e_dn + 1*/ - val = round_fx_o( L_shl_o( Lcor, 4, &Overflow ), &Overflow ); /*shifting by 4 may overflow but improves accuracy Qdn + 4 - e_dn*/ + Lcor = L_mult( cn[i], k_cn ); /*Q_xn + Q15 - e_cn + 1*/ + Lcor = L_mac( Lcor, dn[i], k_dn ); /*Qdn + Q15 - e_dn + 1*/ +#ifdef ISSUE_1867_replace_overflow_libenc + val = round_fx_sat( L_shl_sat( Lcor, 4 ) ); /*shifting by 4 may overflow but improves accuracy Qdn + 4 - e_dn*/ +#else + val = round_fx_o( L_shl_o( Lcor, 4, &Overflow ), &Overflow ); /*shifting by 4 may overflow but improves accuracy Qdn + 4 - e_dn*/ +#endif index = shr( val, 15 ); sign[i] = ptr16[index]; /*Q15*/ @@ -1086,10 +1183,12 @@ void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const Word32 s, L_tmp; Word16 nb_pulse, nb_pulse_m2; Word16 check = 0; /* debug code not instrumented */ +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif alp = config->alp; /* Q13 */ /* initial value for energy of all fixed pulses */ @@ -1128,7 +1227,11 @@ void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const BASOP_SATURATE_WARNING_OFF_EVS FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_mac_o( L_tmp, H[i], H[i], &Overflow ); /*Q25*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, H[i], H[i] ); /*Q25*/ +#else + L_tmp = L_mac_o( L_tmp, H[i], H[i], &Overflow ); /*Q25*/ +#endif } val = extract_h( L_tmp ); /*Q9*/ BASOP_SATURATE_WARNING_ON_EVS @@ -1278,7 +1381,11 @@ void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const L_tmp = L_mult( vec[0], vec[0] ); /*Q25+2*scale*/ FOR( i = 1; i < L_SUBFR; i++ ) - L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); /*Q25+2*scale*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, vec[i], vec[i] ); /*Q25+2*scale*/ +#else + L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); /*Q25+2*scale*/ +#endif alp = round_fx( L_shr( L_tmp, 3 ) ); /*Q6+2*scale*/ @@ -1335,7 +1442,11 @@ void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const FOR( i = 0; i < L_SUBFR; i++ ) { tmp = add( *p0++, *p1++ ); - vec[i] = add_o( vec[i], tmp, &Overflow ); /* can saturate here. */ +#ifdef ISSUE_1867_replace_overflow_libenc + vec[i] = add_sat( vec[i], tmp ); /* can saturate here. */ +#else + vec[i] = add_o( vec[i], tmp, &Overflow ); /* can saturate here. */ +#endif move16(); } } @@ -1385,7 +1496,11 @@ void E_ACELP_4tsearch_fx( Word16 dn[] /*Qdn*/, const Word16 cn[] /*Q_xn*/, const } FOR( i = 0; i < L_SUBFR; i++ ) { - y[i] = add_o( y[i], *p0++, &Overflow ); /*Q12+scale*/ +#ifdef ISSUE_1867_replace_overflow_libenc + y[i] = add_sat( y[i], *p0++ ); /*Q12+scale*/ +#else + y[i] = add_o( y[i], *p0++, &Overflow ); /*Q12+scale*/ +#endif move16(); } } diff --git a/lib_enc/enc_acelpx_fx.c b/lib_enc/enc_acelpx_fx.c index 3d095934115a5fdfaf92371f213de30c94dff048..cd06a4d1570f0aa926351f869f2085a521de6167 100644 --- a/lib_enc/enc_acelpx_fx.c +++ b/lib_enc/enc_acelpx_fx.c @@ -139,9 +139,11 @@ static void E_ACELP_2pulse_searchx_fx( Word32 alp0, alp1, alp2, s; Word16 *pR, sgnx; Word16 sqk[2], alpk[2], ik; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* eight dn2 max positions per track */ @@ -167,8 +169,11 @@ static void E_ACELP_2pulse_searchx_fx( { sgnx = negate( sgnx ); } +#ifdef ISSUE_1867_replace_overflow_libenc + if ( mac_r_sat( L_mac_sat( L_mac_sat( alp0, cor[x], sign[x] ), cor[track_y], sign[track_y] ), R[track_y - x], sgnx ) < 0 ) +#else if ( mac_ro( L_mac_o( L_mac_o( alp0, cor[x], sign[x], &Overflow ), cor[track_y], sign[track_y], &Overflow ), R[track_y - x], sgnx, &Overflow ) < 0 ) - +#endif { sqk[0] = 1; move16(); @@ -188,9 +193,13 @@ static void E_ACELP_2pulse_searchx_fx( /* dn[x] has only nb_pos_ix positions saved */ /*ps1 = ps0 + dn[x]; INDIRECT(1);ADD(1);*/ ps1 = add_sat( ps0, dn[x] ); /*Qdn*/ - /*alp1 = alp0 + 2*sgnx*cor[x]; INDIRECT(1);MULT(1); MAC(1);*/ - alp1 = L_mac_o( alp0, cor[x], sgnx, &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ - pR = R - x; /*Q9+scale*/ + /*alp1 = alp0 + 2*sgnx*cor[x]; INDIRECT(1);MULT(1); MAC(1);*/ +#ifdef ISSUE_1867_replace_overflow_libenc + alp1 = L_mac_sat( alp0, cor[x], sgnx ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#else + alp1 = L_mac_o( alp0, cor[x], sgnx, &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#endif + pR = R - x; /*Q9+scale*/ FOR( y = track_y; y < L_SUBFR; y += 4 ) { @@ -204,14 +213,26 @@ static void E_ACELP_2pulse_searchx_fx( assert( sgnx != 0 ); alp2_16 = 0; - alp2 = L_mac_o( alp1, cor[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#ifdef ISSUE_1867_replace_overflow_libenc + alp2 = L_mac_sat( alp1, cor[y], sign[y] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#else + alp2 = L_mac_o( alp1, cor[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#endif if ( sgnx > 0 ) { - alp2_16 = mac_ro( alp2, pR[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#ifdef ISSUE_1867_replace_overflow_libenc + alp2_16 = mac_r_sat( alp2, pR[y], sign[y] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#else + alp2_16 = mac_ro( alp2, pR[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#endif } if ( sgnx < 0 ) { - alp2_16 = msu_ro( alp2, pR[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#ifdef ISSUE_1867_replace_overflow_libenc + alp2_16 = msu_r_sat( alp2, pR[y], sign[y] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#else + alp2_16 = msu_ro( alp2, pR[y], sign[y], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#endif } alpk[1 - ik] = alp2_16; /* Qalp */ move16(); @@ -223,7 +244,11 @@ static void E_ACELP_2pulse_searchx_fx( /*s = (alpk * sq) - (sqk * alp2); MULT(1);MAC(1);*/ +#ifdef ISSUE_1867_replace_overflow_libenc + s = L_msu_sat( L_mult( alpk[ik], sq ), sqk[ik], alp2_16 ); /* Q_sq = Q_sqk, Q_alpk = Q_alp */ +#else s = L_msu_o( L_mult( alpk[ik], sq ), sqk[ik], alp2_16, &Overflow ); /* Q_sq = Q_sqk, Q_alpk = Q_alp */ +#endif if ( s > 0 ) { ik = sub( 1, ik ); @@ -281,9 +306,11 @@ static void E_ACELP_1pulse_searchx_fx( Word16 ntracks, t; Word16 sqk[2], alpk[2], ik; move16(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* save these to limit memory searches */ /*alp0 = *alp + R[0]; INDIRECT(1);*/ @@ -299,7 +326,11 @@ static void E_ACELP_1pulse_searchx_fx( sqk[0] = -1; ik = 0; move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + if ( mac_r_sat( alp0, cor[tracks[0]], sign[tracks[0]] ) < 0 ) +#else if ( mac_ro( alp0, cor[tracks[0]], sign[tracks[0]], &Overflow ) < 0 ) +#endif { sqk[0] = 1; move16(); @@ -323,8 +354,12 @@ static void E_ACELP_1pulse_searchx_fx( ps1 = add( ps0, dn[x] ); /* alp1 = alp0 + 2*sign[x]*cor[x]; MAC(1); MULT(1);*/ assert( sign[x] == sign_val_1 << 1 || sign[x] == -( sign_val_1 << 1 ) ); - alp1 = mac_ro( alp0, cor[x], sign[x], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ - alpk[1 - ik] = alp1; /* Qalp */ +#ifdef ISSUE_1867_replace_overflow_libenc + alp1 = mac_r_sat( alp0, cor[x], sign[x] ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#else + alp1 = mac_ro( alp0, cor[x], sign[x], &Overflow ); /* Qalp = (Q_R=Q_cor)*Q_signval */ +#endif + alpk[1 - ik] = alp1; /* Qalp */ move16(); @@ -334,7 +369,11 @@ static void E_ACELP_1pulse_searchx_fx( move16(); /*s = (alpk[ik] * sq) - (sqk[ik] * alp1); MULT(1);MAC(1);*/ +#ifdef ISSUE_1867_replace_overflow_libenc + s = L_msu_sat( L_mult_sat( alpk[ik], sq ), sqk[ik], alp1 ); /* Q9+Qalp+1 */ +#else s = L_msu_o( L_mult_o( alpk[ik], sq, &Overflow ), sqk[ik], alp1, &Overflow ); /* Q9+Qalp+1 */ +#endif if ( s > 0 ) { ik = sub( 1, ik ); diff --git a/lib_enc/enc_amr_wb_fx.c b/lib_enc/enc_amr_wb_fx.c index 481bc51ebe768624e4d20cd3e0760f9e9849e2fe..3dda4ec9f5dd7feb904e463156272a237a04f8c8 100644 --- a/lib_enc/enc_amr_wb_fx.c +++ b/lib_enc/enc_amr_wb_fx.c @@ -64,9 +64,11 @@ void encod_amr_wb_fx( AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; BSTR_ENC_HANDLE hBstr = st->hBstr; LPD_state_HANDLE hLPDmem = st->hLPDmem; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*------------------------------------------------------------------* @@ -190,14 +192,23 @@ void encod_amr_wb_fx( &gain_inov, &norm_gain_code, g_corr, clip_gain, hAmrwb_IO->past_qua_en_fx ); gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->clip_var_fx ); - Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ +#ifdef ISSUE_1867_replace_overflow_libenc + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); /*Q0*/ +#else + Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ +#endif hLPDmem->tilt_code = Est_tilt2( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); /*Q15*/ FOR( i = 0; i < L_SUBFR; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + exc2[i + i_subfr] = round_fx_sat( L_shl_sat( L_mult( gain_pit, exc[i + i_subfr] ), 1 ) ); /*Q_new*/ +#else exc2[i + i_subfr] = round_fx_o( L_shl_o( L_mult( gain_pit, exc[i + i_subfr] ), 1, &Overflow ), &Overflow ); /*Q_new*/ +#endif move16(); } @@ -224,8 +235,13 @@ void encod_amr_wb_fx( L_tmp = L_mult( gcode16, code[i] ); /*Q10*/ L_tmp = L_shl_sat( L_tmp, 5 ); /*Q15*/ L_tmp = L_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); /* Q_new+15 */ - L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here Q_new+15*/ - exc[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /*Q_new*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here Q_new+15*/ + exc[i + i_subfr] = round_fx_sat( L_tmp ); /*Q_new*/ +#else + L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here Q_new+15*/ + exc[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /*Q_new*/ +#endif move16(); } diff --git a/lib_enc/enc_gen_voic_fx.c b/lib_enc/enc_gen_voic_fx.c index b382ee46d59c22c97f2ada5c02c2a04bb8599188..b425b2c28ebe2cfeb794cf147fcc93419d17d789 100644 --- a/lib_enc/enc_gen_voic_fx.c +++ b/lib_enc/enc_gen_voic_fx.c @@ -144,9 +144,11 @@ void encod_gen_voic_fx( Word16 shift_wsp; Word16 harm_flag_acelp; Word16 lp_select, lp_flag, L_frame; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -281,7 +283,11 @@ void encod_gen_voic_fx( } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_fx;*/ +#ifdef ISSUE_1867_replace_overflow_libenc + hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#else hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit_fx, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#endif /*-----------------------------------------------------------------* * Transform domain contribution encoding - active frames @@ -333,8 +339,13 @@ void encod_gen_voic_fx( } gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); - Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ - gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ +#ifdef ISSUE_1867_replace_overflow_libenc + Lgcode = L_shl_sat( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); /*Q0*/ +#else + Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ +#endif hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */ move16(); @@ -370,20 +381,35 @@ void encod_gen_voic_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* Contribution from AVQ layer */ - Ltmp1 = L_mult_o( gain_preQ_fx, code_preQ_fx[i], &Overflow ); /* Q2 + Q6 -> Q9*/ - Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp1 = L_mult_sat( gain_preQ_fx, code_preQ_fx[i] ); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); /* Q16 + Q_exc */ +#else + Ltmp1 = L_mult_o( gain_preQ_fx, code_preQ_fx[i], &Overflow ); /* Q2 + Q6 -> Q9*/ + Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ +#endif /* Compute exc2 */ - Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); /* Q16 */ - exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1 ); /* Q16 */ + exc2_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); /* Q0 */ +#else + Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); /* Q16 */ + exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ +#endif move16(); /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ - Ltmp = L_shl( Ltmp, 5 ); /* Q15 */ - Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */ - Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ - exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ + Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ + Ltmp = L_shl( Ltmp, 5 ); /* Q15 */ + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); /* Q0 */ +#else + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */ +#endif } } ELSE @@ -396,11 +422,18 @@ void encod_gen_voic_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ - Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 */ - Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); /* Q15 */ - Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ - exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */ + Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 */ + Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* Q15 */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp ); /* Q0 */ +#else + Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 */ + Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); /* Q15 */ + Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */ +#endif } } @@ -509,9 +542,11 @@ void encod_gen_voic_ivas_fx( Word16 harm_flag_acelp; Word16 lp_select, lp_flag, L_frame; Word16 q_h1; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -706,8 +741,13 @@ void encod_gen_voic_ivas_fx( } gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx ); - Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ +#ifdef ISSUE_1867_replace_overflow_libenc + Lgcode = L_shl_sat( gain_code_fx, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); +#else + Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_o( Lgcode, &Overflow ); +#endif hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, gain_code_fx, &voice_fac_fx, Q_new, L_SUBFR, 0 ); /* Q15 */ move16(); @@ -758,20 +798,35 @@ void encod_gen_voic_ivas_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* Contribution from AVQ layer */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp1 = L_mult_sat( gain_preQ_fx, code_preQ_fx[i] ); + Ltmp1 = L_shl_sat( Ltmp1, tmp1_fx ); +#else Ltmp1 = L_mult_o( gain_preQ_fx, code_preQ_fx[i], &Overflow ); Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); +#endif /* Compute exc2 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = 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( Ltmp, Ltmp1 ) ); +#else Ltmp = L_shl_o( L_mult( gain_pit_fx, exc_fx[i + i_subfr_fx] ), 1, &Overflow ); exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); +#endif move16(); /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ - Ltmp = L_shl( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ - Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/ + Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ + Ltmp = L_shl( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ + Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1 */ /* saturation can occur here Q16*/ + exc_fx[i + i_subfr_fx] = round_fx_sat( L_add_sat( Ltmp, Ltmp1 ) ); +#else Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /*Qnew + 14 + 1 +1 */ /* saturation can occur here Q16*/ exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); +#endif move16(); } } @@ -786,11 +841,18 @@ void encod_gen_voic_ivas_fx( { /* code in Q9, gain_pit in Q14 */ /*gcode16 in Qnew*/ - Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ + Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ + Ltmp = L_mac_sat( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /*Qnew + 14 + 1*/ + Ltmp = L_shl_sat( Ltmp, 1 ); /*Qnew + 14 + 1 +1 */ + exc_fx[i + i_subfr_fx] = round_fx_sat( Ltmp ); +#else Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /*Qnew + 9+ 1+5 */ Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &Overflow ); /*Qnew + 14 + 1*/ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /*Qnew + 14 + 1 +1 */ exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); +#endif } } /*-----------------------------------------------------------------* diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index 0e79baa5f9e95e0db27ac770b18f5b93fcd35c09..cb0fd969ef3ddb016cff833d3fb37a18855a4b7c 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -165,9 +165,11 @@ void coder_acelp_rf_fx( Word16 prev_gain_pit; Word16 rf_coder_type; Word16 lp_select; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif RF_ENC_HANDLE hRF = st->hRF; @@ -440,7 +442,16 @@ void coder_acelp_rf_fx( * Update memory of the weighting filter *-----------------------------------------------------------------*/ /* st_fx->_rf_mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ - Ltmp = Mpy_32_16_1( gain_code, y2[L_SUBFR - 1] ); /* Q10 */ + Ltmp = Mpy_32_16_1( gain_code, y2[L_SUBFR - 1] ); /* Q10 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, add( 5, Q_xn ) ); /* Q15 + Q_xn */ + Ltmp = L_mac_sat( Ltmp, y1[L_SUBFR - 1], gain_pit ); /* Q15 + Q_xn */ + /* Add Gaussian contribution*/ + Ltmp2 = Mpy_32_16_1( gain_code2, y22[L_SUBFR - 1] ); /* Q10 */ + Ltmp2 = L_shl_sat( Ltmp2, add( 5, Q_xn ) ); /* Q15 + Q_xn */ + Ltmp = L_add_sat( Ltmp, Ltmp2 ); /* Q15 + Q_xn */ + hRF->rf_mem_w0 = sub_sat( xn[L_SUBFR - 1], round_fx_sat( L_shl_sat( Ltmp, 1 ) ) ); /* Q_xn */ +#else Ltmp = L_shl_o( Ltmp, add( 5, Q_xn ), &Overflow ); /* Q15 + Q_xn */ Ltmp = L_mac_o( Ltmp, y1[L_SUBFR - 1], gain_pit, &Overflow ); /* Q15 + Q_xn */ /* Add Gaussian contribution*/ @@ -448,6 +459,7 @@ void coder_acelp_rf_fx( Ltmp2 = L_shl_o( Ltmp2, add( 5, Q_xn ), &Overflow ); /* Q15 + Q_xn */ Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); /* Q15 + Q_xn */ hRF->rf_mem_w0 = sub_o( xn[L_SUBFR - 1], round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ), &Overflow ); /* Q_xn */ +#endif move16(); hRF->rf_mem_w0 = shr_sat( hRF->rf_mem_w0, shift ); /*Qnew-1*/ @@ -462,16 +474,28 @@ void coder_acelp_rf_fx( FOR( i = sub( tmp2, shr( L_SUBFR, 1 ) ); i < tmp2; i++ ) { /* code in Q9, gain_pit in Q14; exc Q_new */ - Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */ - Ltmp = L_shl_o( Ltmp, Q_new_p5, &Overflow ); /* Q15 + Q_new */ - Ltmp = L_mac_o( Ltmp, gain_pit, exc_rf[i + i_subfr], &Overflow ); /* Q15 + Q_new */ - exc2[i] = round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ); /* Q_new */ + Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, Q_new_p5 ); /* Q15 + Q_new */ + Ltmp = L_mac_sat( Ltmp, gain_pit, exc_rf[i + i_subfr] ); /* Q15 + Q_new */ + exc2[i] = round_fx_sat( L_shl_sat( Ltmp, 1 ) ); /* Q_new */ + move16(); + Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); /* Q10 */ + Ltmp2 = L_shl_sat( Ltmp2, Q_new_p5 ); /* Q15 + Q_new */ + Ltmp = L_add_sat( Ltmp, Ltmp2 ); /* Q15 + Q_new */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new*/ + exc_rf[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ +#else + Ltmp = L_shl_o( Ltmp, Q_new_p5, &Overflow ); /* Q15 + Q_new */ + Ltmp = L_mac_o( Ltmp, gain_pit, exc_rf[i + i_subfr], &Overflow ); /* Q15 + Q_new */ + exc2[i] = round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ); /* Q_new */ move16(); Ltmp2 = Mpy_32_16_1( gain_code_vect[j], code[i] ); /* Q10 */ Ltmp2 = L_shl_o( Ltmp2, Q_new_p5, &Overflow ); /* Q15 + Q_new */ Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); /* Q15 + Q_new */ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new*/ exc_rf[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */ +#endif move16(); } tmp2 = L_SUBFR; diff --git a/lib_enc/enc_higher_acelp_fx.c b/lib_enc/enc_higher_acelp_fx.c index 2a0b0e7b10437d8209305578dde2e02c7d176fab..7a88d1619d4bbadb2fa118e5df632685699f76c3 100644 --- a/lib_enc/enc_higher_acelp_fx.c +++ b/lib_enc/enc_higher_acelp_fx.c @@ -85,7 +85,11 @@ void transf_cdbk_enc_fx( *--------------------------------------------------------------*/ IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { +#ifdef ISSUE_1867_replace_overflow_libenc + gcode16 = round_fx_sat( L_shl_sat( gain_code, Q_new ) ); +#else gcode16 = round_fx_o( L_shl_o( gain_code, Q_new, &Overflow ), &Overflow ); +#endif FOR( i = 0; i < L_SUBFR; i++ ) { /*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/ @@ -179,8 +183,12 @@ void transf_cdbk_enc_fx( { m_corr = div_s( 16384, m_den ); e_corr = sub( 14 + 4, e_den ); - Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ +#ifdef ISSUE_1867_replace_overflow_libenc + stmp = round_fx_sat( L_shl_sat( Ltmp, 16 ) ); /* Q12 */ +#else stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12 */ +#endif } ELSE { @@ -435,7 +443,11 @@ void transf_cdbk_enc_ivas_fx( *--------------------------------------------------------------*/ IF( EQ_16( st_fx->coder_type, INACTIVE ) ) { +#ifdef ISSUE_1867_replace_overflow_libenc + gcode16 = round_fx_sat( L_shl_sat( gain_code, Q_new ) ); +#else gcode16 = round_fx_o( L_shl_o( gain_code, Q_new, &Overflow ), &Overflow ); +#endif FOR( i = 0; i < L_SUBFR; i++ ) { /*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/ @@ -528,8 +540,12 @@ void transf_cdbk_enc_ivas_fx( { m_corr = div_s( 16384, m_den ); e_corr = sub( 14 + 4, e_den ); - Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ + Ltmp = L_shr( Mult_32_16( Ltmp, m_corr ), e_corr ); /*Q12*/ +#ifdef ISSUE_1867_replace_overflow_libenc + stmp = round_fx_sat( L_shl_sat( Ltmp, 16 ) ); /* Q12 */ +#else stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12 */ +#endif } ELSE { diff --git a/lib_enc/enc_pit_exc_fx.c b/lib_enc/enc_pit_exc_fx.c index da8db9147a6592fea2c9be43ceba68875b8f86c7..0f79d6e0231fcf238054b9d555e1a13027d27f6e 100644 --- a/lib_enc/enc_pit_exc_fx.c +++ b/lib_enc/enc_pit_exc_fx.c @@ -104,9 +104,11 @@ void enc_pit_exc_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*------------------------------------------------------------------* @@ -295,7 +297,11 @@ void enc_pit_exc_fx( } /*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ +#ifdef ISSUE_1867_replace_overflow_libenc + hSpMusClas->lowrate_pitchGain = round_fx_sat( L_mac_sat( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit ) ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#else hSpMusClas->lowrate_pitchGain = round_fx_o( L_mac_o( L_mult( 29491, hSpMusClas->lowrate_pitchGain ), 6554, gain_pit, &Overflow ), &Overflow ); /*Q14*Q16(0.1) + Q15 -> Q15*/ +#endif gpit_tmp = gain_pit; move16(); /*Q14*/ @@ -373,13 +379,22 @@ void enc_pit_exc_fx( IF( use_fcb != 0 ) { - Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ - Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); /* Q15 + Q_new + shift */ + Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); /* Q15 + Q_new + shift */ Ltmp = L_negate( Ltmp ); - Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); /* Q_new + Q15 + shift */ - Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); /* Q_new + Q15 + shift */ - Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); /* Q_new + 15 */ - hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */ + Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 ); /* Q_new + Q15 + shift */ + Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); /* Q_new + Q15 + shift */ + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); /* Q_new + 15 */ + hLPDmem->mem_w0 = round_fx_sat( Ltmp ); /*Q_new-1 */ +#else + Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); /* Q15 + Q_new + shift */ + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); /* Q_new + Q15 + shift */ + Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); /* Q_new + Q15 + shift */ + Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); /* Q_new + 15 */ + hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */ +#endif move16(); } ELSE @@ -401,11 +416,18 @@ void enc_pit_exc_fx( FOR( i = 0; i < L_subfr; i++ ) { /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ + Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 + Q_new */ + Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q_new + Q16*/ + exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ +#else Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 + Q_new */ Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q_new + Q16*/ exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */ +#endif move16(); } } @@ -591,9 +613,11 @@ void enc_pit_exc_ivas_fx( BSTR_ENC_HANDLE hBstr = st_fx->hBstr; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*------------------------------------------------------------------* @@ -860,12 +884,21 @@ void enc_pit_exc_ivas_fx( IF( use_fcb != 0 ) { Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); - Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); // Q_new+14+shift +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, add( 5, shift ) ); // Q_new+14+shift Ltmp = L_negate( Ltmp ); - Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); // Q_new-1+15+shift - Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); // Q_new-1+15+shift - Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); // Q_new+15 - hGSCEnc->mem_w0_tmp_fx = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */ + Ltmp = L_mac_sat( Ltmp, xn[L_subfr - 1], 16384 ); // Q_new-1+15+shift + Ltmp = L_msu_sat( Ltmp, y1[L_subfr - 1], gain_pit ); // Q_new-1+15+shift + Ltmp = L_shl_sat( Ltmp, sub( 1, shift ) ); // Q_new+15 + hGSCEnc->mem_w0_tmp_fx = round_fx_sat( Ltmp ); /*Q_new-1 */ +#else + Ltmp = L_shl_o( Ltmp, add( 5, shift ), &Overflow ); // Q_new+14+shift + Ltmp = L_negate( Ltmp ); + Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); // Q_new-1+15+shift + Ltmp = L_msu_o( Ltmp, y1[L_subfr - 1], gain_pit, &Overflow ); // Q_new-1+15+shift + Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); // Q_new+15 + hGSCEnc->mem_w0_tmp_fx = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */ +#endif } ELSE { @@ -885,11 +918,18 @@ void enc_pit_exc_ivas_fx( FOR( i = 0; i < L_subfr; i++ ) { /* code in Q9, gain_pit in Q14 */ - Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ + Ltmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( Ltmp, 5 ); /* Q15 + Q_new */ + Ltmp = L_mac_sat( Ltmp, exc[i + i_subfr], gain_pit ); /* Q15 + Q_new */ + Ltmp = L_shl_sat( Ltmp, 1 ); /* saturation can occur here Q16 + Q_new */ + exc[i + i_subfr] = round_fx_sat( Ltmp ); /* Q_new */ +#else Ltmp = L_shl_o( Ltmp, 5, &Overflow ); /* Q15 + Q_new */ Ltmp = L_mac_o( Ltmp, exc[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new */ exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */ +#endif move16(); } } diff --git a/lib_enc/enc_tran_fx.c b/lib_enc/enc_tran_fx.c index 3e15713702a394a6542a14cc302b582dada09086..e04d42331a9bb71b35bf1fa0bf2d67c5c29bab01 100644 --- a/lib_enc/enc_tran_fx.c +++ b/lib_enc/enc_tran_fx.c @@ -93,9 +93,11 @@ Word16 encod_tran_fx( Word16 L_frame_fx; Word16 shift_wsp; Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; @@ -228,8 +230,13 @@ Word16 encod_tran_fx( } gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); +#ifdef ISSUE_1867_replace_overflow_libenc + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); +#else Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_o( Lgcode, &Overflow ); +#endif hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ /*-----------------------------------------------------------------* * Update memory of the weighting filter @@ -277,11 +284,18 @@ Word16 encod_tran_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ + L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, 5 ); /* Q15 + Q_new */ + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr], gain_pit ); /* Q15 + Q_new */ + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here Q16 + Q_new */ + exc_fx[i + i_subfr] = round_fx_sat( L_tmp ); /* Q_new */ +#else L_tmp = L_shl_o( L_tmp, 5, &Overflow ); /* Q15 + Q_new */ L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */ L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new */ exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /* Q_new */ +#endif } /*-----------------------------------------------------------------* @@ -293,14 +307,22 @@ Word16 encod_tran_fx( tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ - L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ + L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ + tmp_fx = round_fx_sat( L_tmp ); + exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); /* Q_exc */ + move16(); + exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); /* Q_exc */ + move16(); +#else + L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ tmp_fx = round_fx_o( L_tmp, &Overflow ); - exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */ move16(); exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */ move16(); +#endif } } @@ -467,9 +489,11 @@ Word16 encod_tran_ivas_fx( Word16 shift_wsp; Word32 L_tmp; Word16 q_h1; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif BSTR_ENC_HANDLE hBstr = st_fx->hBstr; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; @@ -610,8 +634,13 @@ Word16 encod_tran_ivas_fx( } gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit, st_fx->clip_var_fx ); +#ifdef ISSUE_1867_replace_overflow_libenc + Lgcode = L_shl_sat( gain_code, Q_new ); /* scaled gain_code with Qnew -> Q16*/ + gcode16 = round_fx_sat( Lgcode ); +#else Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ gcode16 = round_fx_o( Lgcode, &Overflow ); +#endif hLPDmem->tilt_code = est_tilt_ivas_fx( &exc_fx[i_subfr], gain_pit, code, gain_code, &voice_fac, Q_new, L_SUBFR, 0 ); // Q15 /*-----------------------------------------------------------------* * Update memory of the weighting filter @@ -659,11 +688,18 @@ Word16 encod_tran_ivas_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /* code in Q9, gain_pit in Q14 */ - L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ + L_tmp = L_mult( gcode16, code[i] ); /* Q10 + Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, 5 ); /* Q15 + Q_new */ + L_tmp = L_mac_sat( L_tmp, exc_fx[i + i_subfr], gain_pit ); /* Q15 + Q_new */ + L_tmp = L_shl_sat( L_tmp, 1 ); /* saturation can occur here Q16 + Q_new */ + exc_fx[i + i_subfr] = round_fx_sat( L_tmp ); /* Q_new */ +#else L_tmp = L_shl_o( L_tmp, 5, &Overflow ); /* Q15 + Q_new */ L_tmp = L_mac_o( L_tmp, exc_fx[i + i_subfr], gain_pit, &Overflow ); /* Q15 + Q_new */ L_tmp = L_shl_o( L_tmp, 1, &Overflow ); /* saturation can occur here Q16 + Q_new */ exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /* Q_new */ +#endif } /*-----------------------------------------------------------------* @@ -675,13 +711,22 @@ Word16 encod_tran_ivas_fx( tmp1_fx = add( 16 - ( 2 + Q_AVQ_OUT_DEC + 1 ), Q_new ); FOR( i = 0; i < L_SUBFR; i++ ) { - L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ - L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ + L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, tmp1_fx ); /* Q16 + Q_exc */ + tmp_fx = round_fx_sat( L_tmp ); + + exc2_fx[i + i_subfr] = add_sat( exc2_fx[i + i_subfr], tmp_fx ); /* Q_exc */ + move16(); + exc_fx[i + i_subfr] = add_sat( exc_fx[i + i_subfr], tmp_fx ); /* Q_exc */ +#else + L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ tmp_fx = round_fx_o( L_tmp, &Overflow ); exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */ move16(); exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */ +#endif move16(); } } diff --git a/lib_enc/find_tar_fx.c b/lib_enc/find_tar_fx.c index 989f309d2f2a5ee0305103ec476bc9ca9416ba80..0fec2c42479ea010499ffdacc4d400cc165f30bc 100644 --- a/lib_enc/find_tar_fx.c +++ b/lib_enc/find_tar_fx.c @@ -134,7 +134,11 @@ void find_targets_fx( { Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ } - h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); /* Q11 + s */ +#ifdef ISSUE_1867_replace_overflow_libenc + h1[i] = round_fx( L_shl_sat( Ltmp, s ) ); /* Q11 + s */ +#else + h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); /* Q11 + s */ +#endif } Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= M; j++ ) @@ -181,9 +185,11 @@ void find_targets_ivas_fx( Word32 h1_32[6 * L_SUBFR]; Word16 sf; Word64 Ltmp64; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /*------------------------------------------------------------------------* * Find the target vector for excitation search: @@ -250,14 +256,20 @@ void find_targets_ivas_fx( } set32_fx( h1_32, 0, L_subfr ); +#ifndef ISSUE_1867_replace_overflow_libenc Overflow = 0; move16(); +#endif FOR( i = 0; i < M; i++ ) { Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= i; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_sat( h1_32[i - j], s ) ) ); /* Q27 */ +#else Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_o( h1_32[i - j], s, &Overflow ) ) ); /* Q27 */ +#endif } h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */ move32(); @@ -266,17 +278,29 @@ void find_targets_ivas_fx( Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ FOR( j = 1; j <= M; j++ ) { - Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_o( h1_32[i - j], s, &Overflow ) ) ); /* Q27 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_sat( h1_32[i - j], s ) ) ); /* Q27 */ +#else + Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_o( h1_32[i - j], s, &Overflow ) ) ); /* Q27 */ +#endif } h1_32[M] = W_extract_l( Ltmp64 ); /* Q27 */ move32(); FOR( i = M + 1; i < L_subfr; i++ ) { - Ltmp64 = W_msu_16_16( 0, Aqs[1], extract_h( L_shl_o( h1_32[i - 1], s, &Overflow ) ) ); /* Q27 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp64 = W_msu_16_16( 0, Aqs[1], extract_h( L_shl_sat( h1_32[i - 1], s ) ) ); /* Q27 */ +#else + Ltmp64 = W_msu_16_16( 0, Aqs[1], extract_h( L_shl_o( h1_32[i - 1], s, &Overflow ) ) ); /* Q27 */ +#endif FOR( j = 2; j <= M; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_sat( h1_32[i - j], s ) ) ); /* Q27 */ +#else Ltmp64 = W_msu_16_16( Ltmp64, Aqs[j], extract_h( L_shl_o( h1_32[i - j], s, &Overflow ) ) ); /* Q27 */ +#endif } h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */ move32(); diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index c5fb6d2e1a8a9687338933812204ecff0e60908e..56078ec1eaf8b25faf54ec72f4a98b254dd219ef 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -44,9 +44,11 @@ void find_tilt_fx( Word16 scaling; move32(); move32(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*-----------------------------------------------------------------* * Initializations @@ -108,8 +110,13 @@ void find_tilt_fx( /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ Ltmp = L_mult( voicing[1], 16384 /* 0.5 in Q15 */ ); /* Q31 */ Ltmp = L_mac( Ltmp, voicing[2], 16384 /* 0.5 in Q15 */ ); /* Q31 */ - Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); /* Q31 */ - mean_voi = round_fx_o( Ltmp, &Overflow ); /* Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_mac_sat( Ltmp, corr_shift, 32767 ); /* Q31 */ + mean_voi = round_fx_sat( Ltmp ); /* Q15 */ +#else + Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); /* Q31 */ + mean_voi = round_fx_o( Ltmp, &Overflow ); /* Q15 */ +#endif /*f0 = INT_FS_FX / pitch[2];*/ e_tmp = norm_s( pitch[2] ); @@ -155,13 +162,22 @@ void find_tilt_fx( tmp = sub( freq, f2 ); IF( L_mac0( -(Word32) TH_D_FX * TH_D_FX, tmp, tmp ) < 0 ) { +#ifdef ISSUE_1867_replace_overflow_libenc + lp_E = L_add_sat( *pt_E, lp_E ); /* Q_new + QSCALE - 2 */ +#else lp_E = L_add_o( *pt_E, lp_E, &Overflow ); /* Q_new + QSCALE - 2 */ - m_cnt = add( m_cnt, 1 ); /* Q0 */ +#endif + m_cnt = add( m_cnt, 1 ); /* Q0 */ } pt_E++; } +#ifdef ISSUE_1867_replace_overflow_libenc + f1 = add_sat( f1, f0 ); + f2 = add_sat( f2, f0 ); +#else f1 = add_o( f1, f0, &Overflow ); f2 = add_o( f2, f0, &Overflow ); +#endif } /*lp_E = lp_E / (float)cnt - lp_bckr;*/ e_tmp = sub( norm_l( lp_E ), 1 ); @@ -175,7 +191,11 @@ void find_tilt_fx( m_tmp = div_s( m_tmp, m_cnt ); /* exp(e_tmp + e_cnt) */ e_tmp = sub( e_tmp, e_cnt ); +#ifdef ISSUE_1867_replace_overflow_libenc + lp_E = L_sub_sat( L_shr_sat( m_tmp, sub( e_tmp, 1 ) ), lp_bckr ); /* Q_new + QSCALE */ +#else lp_E = L_sub_o( L_shr_sat( m_tmp, sub( e_tmp, 1 ) ), lp_bckr, &Overflow ); /* Q_new + QSCALE */ +#endif pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame */ } @@ -216,7 +236,11 @@ void find_tilt_fx( IF( EQ_16( bwidth, NB ) ) /* For NB input, compensate for the missing bands */ { +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( ee[i], 3 ); +#else Ltmp = L_shl_o( ee[i], 3, &Overflow ); +#endif IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ { Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ @@ -271,9 +295,11 @@ void find_tilt_ivas_fx( Word64 sum; Word16 inv_bands, q_lp_E; Word32 Le_min_scaled, Ltmp2; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move32(); move32(); @@ -344,10 +370,15 @@ void find_tilt_ivas_fx( hp_bckr = L_add_sat( L_shl_sat( hp_bckr, 1 ), hp_bckr ); /* Q_new */ } /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ - Ltmp = L_mult( voicing[1], 16384 /* 0.5 in Q15 */ ); // Q31 - Ltmp = L_mac( Ltmp, voicing[2], 16384 /* 0.5 in Q15 */ ); // Q31 + Ltmp = L_mult( voicing[1], 16384 /* 0.5 in Q15 */ ); // Q31 + Ltmp = L_mac( Ltmp, voicing[2], 16384 /* 0.5 in Q15 */ ); // Q31 +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_mac_sat( Ltmp, corr_shift, 32767 /* 1.0f in Q15 */ ); // Q31 + mean_voi = round_fx_sat( Ltmp ); // Q15 +#else Ltmp = L_mac_o( Ltmp, corr_shift, 32767 /* 1.0f in Q15 */, &Overflow ); // Q31 mean_voi = round_fx_o( Ltmp, &Overflow ); // Q15 +#endif /*f0 = INT_FS_FX / pitch[2];*/ e_tmp = norm_s( pitch[2] ); @@ -399,8 +430,13 @@ void find_tilt_ivas_fx( } pt_E++; } +#ifdef ISSUE_1867_replace_overflow_libenc + f1 = add_sat( f1, f0 ); + f2 = add_sat( f2, f0 ); +#else f1 = add_o( f1, f0, &Overflow ); f2 = add_o( f2, f0, &Overflow ); +#endif } /*lp_E = lp_E / (float)cnt - lp_bckr;*/ e_tmp = sub( W_norm( sum ), 1 ); @@ -468,8 +504,12 @@ void find_tilt_ivas_fx( IF( bwidth == NB ) /* For NB input, compensate for the missing bands */ { +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_shl_sat( ee[i], 3 ); /* Q6 */ +#else Ltmp = L_shl_o( ee[i], 3, &Overflow ); /* Q6 */ - IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ +#endif + IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ { Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/ ee[i] = L_shl_sat( Ltmp, 3 ); /* Q6 */ diff --git a/lib_enc/find_uv_fx.c b/lib_enc/find_uv_fx.c index 89db87ef2b9ddcb57b7f7848d8c86d194c18d3e5..401b64cb55346e5cd824b8d5c9d1e2c2d1034478 100644 --- a/lib_enc/find_uv_fx.c +++ b/lib_enc/find_uv_fx.c @@ -115,9 +115,11 @@ Word16 find_uv_fx( /* o : coding type */ Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE; NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 Last_Resort; @@ -197,9 +199,13 @@ Word16 find_uv_fx( /* o : coding type */ * Average voicing (normalized correlation) *-----------------------------------------------------------------*/ - /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ - mean_ee = L_add_o( L_add_o( st_fx->ee_old_fx, ee[0], &Overflow ), ee[1], &Overflow ); /* Q6 */ - mean_ee = Mult_32_16( mean_ee, 10923 /* 1/3 in Q15 */ ); /*Q6*/ + /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ +#ifdef ISSUE_1867_replace_overflow_libenc + mean_ee = L_add_sat( L_add_sat( st_fx->ee_old_fx, ee[0] ), ee[1] ); /* Q6 */ +#else + mean_ee = L_add_o( L_add_o( st_fx->ee_old_fx, ee[0], &Overflow ), ee[1], &Overflow ); /* Q6 */ +#endif + mean_ee = Mult_32_16( mean_ee, 10923 /* 1/3 in Q15 */ ); /*Q6*/ /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ ); /* Q31 */ @@ -224,7 +230,11 @@ Word16 find_uv_fx( /* o : coding type */ { dE2_th = 21 << 10; move32(); - if ( GE_16( add_o( mean_voi3, corr_shift, &Overflow ), 22282 /* 0.68 in Q15 */ ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ +#ifdef ISSUE_1867_replace_overflow_libenc + if ( GE_16( add_sat( mean_voi3, corr_shift ), 22282 /* 0.68 in Q15 */ ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ +#else + if ( GE_16( add_o( mean_voi3, corr_shift, &Overflow ), 22282 /* 0.68 in Q15 */ ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ +#endif { nb_cond = 0; move16(); @@ -303,7 +313,11 @@ Word16 find_uv_fx( /* o : coding type */ test(); if ( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], L_shl( E_MIN_FX, Q_new ) ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ - ( LT_16( add_o( st_fx->voicing_fx[0], corr_shift, &Overflow ), voi_th ) ) ) ) /* normalized correlation is low */ +#ifdef ISSUE_1867_replace_overflow_libenc + ( LT_16( add_sat( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) ) /* normalized correlation is low */ +#else + ( LT_16( add_o( st_fx->voicing_fx[0], corr_shift, &Overflow ), voi_th ) ) ) ) /* normalized correlation is low */ +#endif { tmp_offset_flag = 0; move16(); @@ -379,16 +393,21 @@ Word16 find_uv_fx( /* o : coding type */ test(); test(); test(); - if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ +#ifdef ISSUE_1867_replace_overflow_libenc + if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ +#else + if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ +#endif + ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); @@ -408,16 +427,20 @@ Word16 find_uv_fx( /* o : coding type */ test(); test(); test(); +#ifdef ISSUE_1867_replace_overflow_libenc + if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ +#else if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.8 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ +#endif + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.8 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); @@ -610,9 +633,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE; NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 Last_Resort; Word16 vadnoise; @@ -713,9 +738,13 @@ Word16 find_uv_ivas_fx( /* o : coding typ * Average voicing (normalized correlation) *-----------------------------------------------------------------*/ - /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ - mean_ee = L_add_o( L_add_o( st_fx->ee_old_fx, ee[0], &Overflow ), ee[1], &Overflow ); /* Q6 */ - mean_ee = Mult_32_16( mean_ee, 10923 ); /*Q6*/ + /*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ +#ifdef ISSUE_1867_replace_overflow_libenc + mean_ee = L_add_sat( L_add_sat( st_fx->ee_old_fx, ee[0] ), ee[1] ); /* Q6 */ +#else + mean_ee = L_add_o( L_add_o( st_fx->ee_old_fx, ee[0], &Overflow ), ee[1], &Overflow ); /* Q6 */ +#endif + mean_ee = Mult_32_16( mean_ee, 10923 ); /*Q6*/ /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ Ltmp0 = L_mult( st_fx->voicing_fx[0], 10923 /* 1/3 in Q15 */ ); /* Q31 */ @@ -740,7 +769,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ { dE2_th = 21 << 10; move32(); - if ( GE_16( add_o( mean_voi3, corr_shift, &Overflow ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ +#ifdef ISSUE_1867_replace_overflow_libenc + if ( GE_16( add_sat( mean_voi3, corr_shift ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ +#else + if ( GE_16( add_o( mean_voi3, corr_shift, &Overflow ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/ +#endif { nb_cond = 0; move16(); @@ -819,9 +852,16 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); test(); - IF( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ - ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ - ( LT_16( add_o( st_fx->voicing_fx[0], corr_shift, &Overflow ), voi_th ) ) ) ) /* normalized correlation is low */ +#ifdef ISSUE_1867_replace_overflow_libenc + IF( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ + ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ + ( LT_16( add_sat( st_fx->voicing_fx[0], corr_shift ), voi_th ) ) ) ) + /* normalized correlation is low */ +#else + IF( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ + ( ( LT_32( ee[0], ee0_th ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy is concentrated in high frequencies provided that some energy is present in HF */ + ( LT_16( add_o( st_fx->voicing_fx[0], corr_shift, &Overflow ), voi_th ) ) ) ) /* normalized correlation is low */ +#endif { tmp_offset_flag = 0; move16(); @@ -897,16 +937,30 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); test(); - IF( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - flag_low_relE ) /* low relative frame energy (only for SC-VBR) */ +#ifdef ISSUE_1867_replace_overflow_libenc + IF( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_sat( st_fx->voicing_fx[2], corr_shift ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) +#else + IF( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22282 /* 0.68 in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ + ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 /* 0.79 in Q15 */ ) ) && /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 640 /* 10.0f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], ee1_th ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) &&*/ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 237568 /* 29.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) || /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + flag_low_relE ) +#endif + /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); @@ -923,16 +977,20 @@ Word16 find_uv_ivas_fx( /* o : coding typ test(); test(); test(); +#ifdef ISSUE_1867_replace_overflow_libenc + if ( ( ( LT_16( add_sat( mean_voi3, corr_shift ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ +#else if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */ - /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ - ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ - ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ - ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ - /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ - ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ - ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ - ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ - || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ +#endif + /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ + ( LT_32( ee[0], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[0], E_min_th ) ) && /* energy concentrated in high frequencies provided that some energy is present in HF... */ + ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */ + ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */ + /*( st_fx->music_hysteresis_fx == 0 ) && */ /* ... and in segment after AUDIO frames */ + ( LE_32( dE1, 245760 /* 30.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ + ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) && /* + one frame hysteresis */ + ( st_fx->spike_hyst < 0 ) ) /* Avoid after sharp energy spikes followed by decay (e.g. castanets) */ + || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 /* 30.0f in Q13 */ ) ) ) ) /* low relative frame energy (only for SC-VBR) */ { coder_type = UNVOICED; move16(); diff --git a/lib_enc/gain_enc_fx.c b/lib_enc/gain_enc_fx.c index 868374446a02808b79d4a5e0881aee1ba3a8148d..68d467f50fe278445c4e90e0a2b0d72109ee92e7 100644 --- a/lib_enc/gain_enc_fx.c +++ b/lib_enc/gain_enc_fx.c @@ -64,9 +64,11 @@ void Es_pred_enc_fx( Word16 s0, s1, ener_dB, mean_ener_code16; const Word16 *qua_table; Word32 ener_fx, Lmean_ener_code, Ltmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Lmean_ener_code = L_deposit_l( 0 ); @@ -95,7 +97,11 @@ void Es_pred_enc_fx( FOR( i = 1; i < L_SUBFR; i++ ) { tmp16 = mult_r( res[i_subfr + i], 8192 /* 1 in Q13 */ ); /* remove 2bits Q_new - 2*/ +#ifdef ISSUE_1867_replace_overflow_libenc + ener_fx = L_mac_sat( ener_fx, tmp16, tmp16 ); +#else ener_fx = L_mac_o( ener_fx, tmp16, tmp16, &Overflow ); +#endif } /* ener = 10 * (float)log10(ener / (float)L_SUBFR) */ @@ -177,7 +183,11 @@ void Es_pred_enc_fx( FOR( i = 1; i < size; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + tmp16_2 = abs_s( sub_sat( mean_ener_code16, qua_table[i] ) ); +#else tmp16_2 = abs_s( sub_o( mean_ener_code16, qua_table[i], &Overflow ) ); +#endif IF( LT_16( tmp16_2, tmp16 ) ) { tmp16 = tmp16_2; @@ -233,9 +243,11 @@ void gain_enc_mless_fx( Word16 exp1, exp2; Word16 exp_num, exp_den, exp_div, frac_den; Word32 L_frac_num, L_frac_den, L_div; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*-----------------------------------------------------------------* @@ -399,7 +411,11 @@ void gain_enc_mless_fx( L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ exp_div = sub( exp_num, exp_den ); +#ifdef ISSUE_1867_replace_overflow_libenc + *gain_pit = round_fx_sat( L_shl_sat( L_div, add( exp, exp_div ) ) ); /*Q14*/ +#else *gain_pit = round_fx_o( L_shl_o( L_div, add( exp, exp_div ), &Overflow ), &Overflow ); /*Q14*/ +#endif L_tmp1 = L_shr( L_mult( coeff[1], coeff[4] ), 2 ); /*Q31*/ exp1 = add( exp_coeff[1], exp_coeff[4] ); @@ -424,7 +440,11 @@ void gain_enc_mless_fx( L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ exp_div = sub( exp_num, exp_den ); +#ifdef ISSUE_1867_replace_overflow_libenc + *gain_code = L_shl_sat( L_div, sub( add( exp, exp_div ), 14 ) ); +#else *gain_code = L_shl_o( L_div, sub( add( exp, exp_div ), 14 ), &Overflow ); +#endif move32(); /*Q16*/ *gain_pit = s_max( G_PITCH_MIN_TC192_Q14, s_min( *gain_pit, G_PITCH_MAX_TC192_Q14 ) ); @@ -453,8 +473,12 @@ void gain_enc_mless_fx( index = gain_quant_fx( gain_code, &gain_code16, LG10_G_CODE_MIN_TC192_Q14, LG10_G_CODE_MAX_TC192_Q13, nBits2, &expg ); push_indice( hBstr, IND_GAIN_CODE, index, nBits2 ); - L_tmp = L_mult( gain_code16, gcode0 ); /*Q0*Q0 -> Q1*/ - *gain_code = L_shl_o( L_tmp, add( add( expg, exp_gcode0 ), 15 ), &Overflow ); /*Q16*/ + L_tmp = L_mult( gain_code16, gcode0 ); /*Q0*Q0 -> Q1*/ +#ifdef ISSUE_1867_replace_overflow_libenc + *gain_code = L_shl_sat( L_tmp, add( add( expg, exp_gcode0 ), 15 ) ); /*Q16*/ +#else + *gain_code = L_shl_o( L_tmp, add( add( expg, exp_gcode0 ), 15 ), &Overflow ); /*Q16*/ +#endif } ELSE { @@ -572,9 +596,11 @@ void gain_enc_SQ_fx( Word16 exp1, exp2; Word16 exp_num, exp_den, exp_div, frac_den; Word32 L_frac_num, L_frac_den, L_div; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*-----------------------------------------------------------------* @@ -679,7 +705,11 @@ void gain_enc_SQ_fx( L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ exp1 = add( exp_coeff[0], exp_coeff[2] ); - L_tmp2 = L_mult_o( coeff[4], coeff[4], &Overflow ); /*Q31*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp2 = L_mult_sat( coeff[4], coeff[4] ); /*Q31*/ +#else + L_tmp2 = L_mult_o( coeff[4], coeff[4], &Overflow ); /*Q31*/ +#endif exp2 = add( exp_coeff[4], exp_coeff[4] ); IF( GT_16( exp1, exp2 ) ) @@ -721,24 +751,32 @@ void gain_enc_SQ_fx( exp_num = exp2; move16(); } - L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_frac_num = L_sub_sat( L_tmp2, L_tmp1 ); /*Q31*/ +#else + L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#endif L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ exp_div = sub( exp_num, exp_den ); +#ifdef ISSUE_1867_replace_overflow_libenc + *gain_pit = round_fx_sat( L_shl_sat( L_div, add( exp, exp_div ) ) ); /*Q14*/ +#else *gain_pit = round_fx_o( L_shl_o( L_div, add( exp, exp_div ), &Overflow ), &Overflow ); /*Q14*/ +#endif #ifdef FIX_1978_SAT_MISSING_IN_GAIN_ENC L_tmp1 = L_mult_sat( coeff[1], coeff[4] ); /*Q31*/ #else - L_tmp1 = L_mult( coeff[1], coeff[4] ); /*Q31*/ + L_tmp1 = L_mult( coeff[1], coeff[4] ); /*Q31*/ #endif exp1 = add( exp_coeff[1], exp_coeff[4] ); #ifdef FIX_1978_SAT_MISSING_IN_GAIN_ENC L_tmp2 = L_mult_sat( coeff[0], coeff[3] ); /*Q31*/ #else - L_tmp2 = L_mult( coeff[0], coeff[3] ); /*Q31*/ + L_tmp2 = L_mult( coeff[0], coeff[3] ); /*Q31*/ #endif exp2 = add( exp_coeff[0], exp_coeff[3] ); @@ -754,7 +792,11 @@ void gain_enc_SQ_fx( exp_num = exp2; move16(); } - L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#ifdef ISSUE_1867_replace_overflow_libenc + L_frac_num = L_sub_sat( L_tmp2, L_tmp1 ); /*Q31*/ +#else + L_frac_num = L_sub_o( L_tmp2, L_tmp1, &Overflow ); /*Q31*/ +#endif L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ exp_div = sub( exp_num, exp_den ); @@ -841,9 +883,11 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quant Word16 index, exp_gain, frac_gain, wtmp; Word16 enr_q, wenr; Word32 Ltmp, enr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*enr = 20.0 * log10(*gain + 0.001) codebook gain in dB */ exp_gain = norm_l( *gain ); @@ -875,7 +919,11 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quant Ltmp = Pow2( 14, frac_gain ); /* Put 14 as exponent */ exp_gain = sub( exp_gain, 14 ); /* Retreive exponent of wtmp */ +#ifdef ISSUE_1867_replace_overflow_libenc + *gain = L_shl_sat( Ltmp, add( 16, exp_gain ) ); +#else *gain = L_shl_o( Ltmp, add( 16, exp_gain ), &Overflow ); +#endif move32(); /*Q16*/ return index; @@ -1094,10 +1142,12 @@ static Word16 Find_Opt_gainQ_fx( Word16 exp_max[5]; Word16 exp_code, e_max; Word32 L_tmp, L_tmp1; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /*----------------------------------------------------------------* @@ -1192,7 +1242,11 @@ static Word16 Find_Opt_gainQ_fx( L_tmp = L_mac( L_tmp, coeff[3], g_code ); /* 15 - coeff_exp + 13 - 1 */ L_tmp = L_mac( L_tmp, coeff[4], g_pit_cod ); /* 15 - coeff_exp + 13 - 1 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = L_sub_sat( L_tmp, dist_min ); +#else L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow ); +#endif if ( L_tmp1 < 0 ) { index = i; @@ -1725,9 +1779,11 @@ void gain_enc_amr_wb_fx( Word16 exp_max[5], tmp, nBits; Word32 L_tmp, dist_min, L_inov, L_tmp1; const Word16 *t_qua_gain, *p; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*----------------------------------------------------------------* @@ -1960,7 +2016,11 @@ void gain_enc_amr_wb_fx( L_tmp = L_mac( L_tmp, coeff[3], g_code ); /* 15 - coeff_exp + 13 - 1 */ L_tmp = L_mac( L_tmp, coeff[4], g_pit_cod ); /* 15 - coeff_exp + 13 - 1 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = L_sub_sat( L_tmp, dist_min ); +#else L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow ); +#endif /* splitting the if cost half the complexity of using IF macro */ if ( L_tmp1 < 0 ) { @@ -1982,8 +2042,12 @@ void gain_enc_amr_wb_fx( g_code = *p++; /* selected code gain in Q11 */ move16(); - L_tmp = L_mult( g_code, gcode0 ); /* Q11*Q0 -> Q12 */ + L_tmp = L_mult( g_code, gcode0 ); /* Q11*Q0 -> Q12 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, add( exp_gcode0, 4 ) ); /* Q12 -> Q16 */ +#else L_tmp = L_shl_o( L_tmp, add( exp_gcode0, 4 ), &Overflow ); /* Q12 -> Q16 */ +#endif *gain_code = L_tmp; /* gain of code in Q16 */ move16(); diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index a19bc4439bf877cb28ca6658806929d5b7221d12..08514875ce237cbafbfd52a72034324caab48c9e 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -60,9 +60,11 @@ Word16 gaus_encode_fx( Word32 Ltmp; Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ Word16 exp, tmp, tmp_idx; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*----------------------------------------------------------------* @@ -98,7 +100,11 @@ Word16 gaus_encode_fx( /*----------------------------------------------------------------* * Total excitation for Unvoiced coders *----------------------------------------------------------------*/ +#ifdef ISSUE_1867_replace_overflow_libenc + gcode = round_fx_sat( L_shl_sat( *gain_code, Q_new ) ); /* scaled gain_code with Qnew */ +#else gcode = round_fx_o( L_shl_o( *gain_code, Q_new, &Overflow ), &Overflow ); /* scaled gain_code with Qnew */ +#endif FOR( i = 0; i < L_SUBFR; i++ ) { exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); /* Q_new */ @@ -191,9 +197,11 @@ void gauss2v_fx( Word16 gxx, gcc, index_delta, delta, m_sign, inv_delta; Word16 hg[190], Gaus_dico2[190]; Word16 shiftP3; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*----------------------------------------------------------------* @@ -424,8 +432,13 @@ void gauss2v_fx( cor2_norm = norm_l( cor2 ); eneri_norm = norm_l( eneri ); +#ifdef ISSUE_1867_replace_overflow_libenc + cor2_mantissa = round_fx_sat( L_shl_sat( cor2, cor2_norm ) ); + eneri_mantissa = round_fx_sat( L_shl_sat( eneri, eneri_norm ) ); +#else cor2_mantissa = round_fx_o( L_shl_o( cor2, cor2_norm, &Overflow ), &Overflow ); eneri_mantissa = round_fx_o( L_shl_o( eneri, eneri_norm, &Overflow ), &Overflow ); +#endif difference_norm = sub( add( cor2_norm, enerw_norm ), add( cor2w_norm, eneri_norm ) ); update_best = 0; @@ -594,7 +607,11 @@ void gauss2v_fx( /* Gain must be output in a 32-bit variable as a Q16 */ /* Compensate for Q_new */ +#ifdef ISSUE_1867_replace_overflow_libenc + *gain = L_shl_sat( Portion, sub( 13, Q_new ) ); /* Q16 */ +#else *gain = L_shl_o( Portion, sub( 13, Q_new ), &Overflow ); /* Q16 */ +#endif move32(); return; diff --git a/lib_enc/gp_clip_fx.c b/lib_enc/gp_clip_fx.c index d7614473b32a086f9d0171d2ae510f9d5f941316..05d385fe78de7ac707856b295e80ac12e50be42e 100644 --- a/lib_enc/gp_clip_fx.c +++ b/lib_enc/gp_clip_fx.c @@ -114,9 +114,11 @@ Word16 gp_clip_fx( Word32 ener; Word32 L_tmp; Word16 thres; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif clip = 0; @@ -142,10 +144,18 @@ Word16 gp_clip_fx( } } +#ifdef ISSUE_1867_replace_overflow_libenc + ener = L_mac_sat( 1L, xn[0], xn[0] ); +#else ener = L_mac_o( 1L, xn[0], xn[0], &Overflow ); +#endif FOR( i = 1; i < L_SUBFR; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + ener = L_mac_sat( ener, xn[i], xn[i] ); +#else ener = L_mac_o( ener, xn[i], xn[i], &Overflow ); +#endif } /* ener = 10.0f*(float)log10(ener) */ @@ -334,9 +344,11 @@ Word16 Mode2_gp_clip_fx( Word16 clip, tmp, exp_xn; Word16 i; Word32 wener, Ltmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move16(); clip = 0; @@ -355,7 +367,11 @@ Word16 Mode2_gp_clip_fx( FOR( i = 0; i < L_subfr; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + wener = L_mac0_sat( wener, xn[i], xn[i] ); +#else wener = L_mac0_o( wener, xn[i], xn[i], &Overflow ); +#endif } /*wener = 10.0f*(float)log10(wener);*/ diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 7bf52970d7ff5f02edcaa6417a2b8b3d89cdf2c4..c666840dfb0953dd598ebc8bfe90dfd3383218a8 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -1329,9 +1329,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ Word32 L_tmp, ener_max, ener_mean; Word16 tmp, exp2, tmp2, tmp1, exp1, exp3; Word16 scale; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif ener_mean = L_shl( 1, shl( Qnew, 1 ) ); /*2*Qnew*/ @@ -1341,7 +1343,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ { L_tmp = L_mult0( vec[j], vec[j] ); /*2*Qnew*/ ener_max = L_max( ener_max, L_tmp ); +#ifdef ISSUE_1867_replace_overflow_libenc + ener_mean = L_add_sat( ener_mean, L_tmp ); +#else ener_mean = L_add_o( ener_mean, L_tmp, &Overflow ); +#endif } /*dyn = 10.0f * (ener_max / ener_mean);*/ ener_mean = Mult_32_16( ener_mean, div_s( 1, lvec ) ); /*2*Qnew*/ @@ -1349,7 +1355,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ IF( ener_mean > 0 ) { exp1 = norm_l( ener_mean ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = round_fx_sat( L_shl( ener_mean, exp1 ) ); +#else tmp1 = round_fx_o( L_shl( ener_mean, exp1 ), &Overflow ); +#endif exp1 = sub( 30, exp1 ); exp2 = norm_l( ener_max ); diff --git a/lib_enc/guided_plc_enc_fx.c b/lib_enc/guided_plc_enc_fx.c index 81e50d099bc1149557b3ae1395749726e41d0ea5..50932734cedfb35226c981816594fe1999161ac5 100644 --- a/lib_enc/guided_plc_enc_fx.c +++ b/lib_enc/guided_plc_enc_fx.c @@ -43,10 +43,12 @@ static void coderLookAheadInnovation( move32(); move16(); move16(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /* Debug init (not instrumented) */ @@ -165,7 +167,11 @@ static void coderLookAheadInnovation( ps_e = add( alp_e, ps_e ); BASOP_SATURATE_WARNING_OFF_EVS +#ifdef ISSUE_1867_replace_overflow_libenc + max_ps_tmp = L_shl_sat( max_ps, sub( max_ps_e, ps_e ) ); +#else max_ps_tmp = L_shl_o( max_ps, sub( max_ps_e, ps_e ), &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS @@ -442,10 +448,12 @@ void updateSpecPowDiffuseIdx_fx( { Word16 min_gp; Word16 k; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif move32(); @@ -455,14 +463,22 @@ void updateSpecPowDiffuseIdx_fx( FOR( k = 1; k < 4; k++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + st->mean_gc[1] = L_add_sat( st->mean_gc[1], st->gain_code[k] ); +#else st->mean_gc[1] = L_add_o( st->mean_gc[1], st->gain_code[k], &Overflow ); +#endif move32(); min_gp = s_min( min_gp, st->bpf_gainT[k] ); } /* Suppress saturation warning in threshold comparison. */ test(); +#ifdef ISSUE_1867_replace_overflow_libenc + if ( LT_32( st->mean_gc[1], L_add_sat( st->mean_gc[0], Mpy_32_16_r( st->mean_gc[0], 3211 /*0.098 Q15*/ ) ) ) || GT_16( min_gp, 13435 /*0.82 Q14*/ ) ) +#else if ( LT_32( st->mean_gc[1], L_add_o( st->mean_gc[0], Mpy_32_16_r( st->mean_gc[0], 3211 /*0.098 Q15*/ ), &Overflow ) ) || GT_16( min_gp, 13435 /*0.82 Q14*/ ) ) +#endif { move16(); st->glr_idx[0] = 0; diff --git a/lib_enc/hf_cod_amrwb_fx.c b/lib_enc/hf_cod_amrwb_fx.c index e21a8bd677e665f1e9d36c61d1311074ee56c165..9de30e99a5db45ae1c957f523c646d76efd613e4 100644 --- a/lib_enc/hf_cod_amrwb_fx.c +++ b/lib_enc/hf_cod_amrwb_fx.c @@ -86,8 +86,10 @@ void hf_cod_fx( Word32 L_tmp; Word16 *pt1; const Word16 *pt2; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /* Original speech signal as reference for high band gain quantisation */ @@ -107,10 +109,14 @@ void hf_cod_fx( ener_exc_fx = dot_prod_satcontr( exc_fx, exc_fx, Q_exc, Q_exc, &q1, L_SUBFR ); ener_hf_fx = dot_prod_satcontr( HF_fx, HF_fx, -3, -3, &q2, L_SUBFR16k ); - scale_fx = div_s( shl( 1, 14 ), ener_exc_fx ); /*Q(29-q1) */ - L_tmp = L_mult( ener_hf_fx, scale_fx ); /*30-q1+q2 */ - q2 = sub( q1, q2 ); /*30-q2 */ - scale_fx = round_fx( Isqrt( L_shl_o( L_tmp, sub( q2, 26 ), &Overflow ) ) ); /*Q13 */ + scale_fx = div_s( shl( 1, 14 ), ener_exc_fx ); /*Q(29-q1) */ + L_tmp = L_mult( ener_hf_fx, scale_fx ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ +#ifdef ISSUE_1867_replace_overflow_libenc + scale_fx = round_fx( Isqrt( L_shl_sat( L_tmp, sub( q2, 26 ) ) ) ); /*Q13 */ +#else + scale_fx = round_fx( Isqrt( L_shl_o( L_tmp, sub( q2, 26 ), &Overflow ) ) ); /*Q13 */ +#endif pt1 = HF_fx; @@ -183,10 +189,14 @@ void hf_cod_fx( ener_hf_fx = dot_prod_satcontr( HF_syn_fx, HF_syn_fx, 0, 0, &q2, L_SUBFR16k ); ener_input_fx = dot_prod_satcontr( HF_SP_fx, HF_SP_fx, 0, 0, &q1, L_SUBFR16k ); - HF_calc_gain_fx = div_s( shl( 1, 14 ), ener_input_fx ); /*Q(29-q1) */ - L_tmp = L_mult( ener_hf_fx, HF_calc_gain_fx ); /*30-q1+q2 */ - q2 = sub( q1, q2 ); /*30-q2 */ + HF_calc_gain_fx = div_s( shl( 1, 14 ), ener_input_fx ); /*Q(29-q1) */ + L_tmp = L_mult( ener_hf_fx, HF_calc_gain_fx ); /*30-q1+q2 */ + q2 = sub( q1, q2 ); /*30-q2 */ +#ifdef ISSUE_1867_replace_overflow_libenc + HF_calc_gain_fx = round_fx_sat( Isqrt( L_shl_sat( L_tmp, sub( q2, 20 ) ) ) ); /*Q10 */ +#else HF_calc_gain_fx = round_fx_o( Isqrt( L_shl_sat( L_tmp, sub( q2, 20 ) ) ), &Overflow ); /*Q10 */ +#endif /* set energy of HF synthesis to energy of original HF: diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index aa2c319f1e9a936c00473a70f6caae499410ee37..c8799784b359f8d2d100e8664a44b4b5a4a57e3d 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -652,9 +652,11 @@ void hvq_classifier_ivas_fx( Word16 num_peak_cands, high, low; Word16 sharp[HVQ_NSUB_32k]; Word16 peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[HVQ_NSUB_32k]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif Word16 temp_e = 0; move16(); @@ -808,7 +810,11 @@ void hvq_classifier_ivas_fx( sharp[i] = extract_h( L_shl( L_tmp, shift ) ); /* 30-s+s-8-16 -> Q6 */ move16(); /*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ +#ifdef ISSUE_1867_replace_overflow_libenc + sharp_dist = add_sat( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ) ); /* Q6 */ +#else sharp_dist = add_o( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ), &Overflow ); /* Q6 */ +#endif if ( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) ) { num_sharp_bands = add( num_sharp_bands, 1 ); @@ -1085,9 +1091,11 @@ void hvq_classifier_fx( Word16 num_peak_cands, high, low; Word16 sharp[HVQ_NSUB_32k]; Word16 peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[HVQ_NSUB_32k]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif L_input_max = L_deposit_l( 0 ); set32_fx( L_thr, 0, L_FRAME16k ); @@ -1240,7 +1248,11 @@ void hvq_classifier_fx( move16(); /*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ +#ifdef ISSUE_1867_replace_overflow_libenc + sharp_dist = add_sat( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ) ); +#else sharp_dist = add_o( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ), &Overflow ); +#endif IF( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) ) { num_sharp_bands = add( num_sharp_bands, 1 ); diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index af27806820f6ba1cf295ffb130523b8cbaa3a377..7dc3000c828dcf4d2aaaa26268f90b4aede92340 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -272,10 +272,12 @@ void hq_lr_enc_fx( Word16 beta_fx; /*Q14 1.05f; */ HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif set32_fx( L_y2, 0x0L, L_FRAME48k ); @@ -606,9 +608,13 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = Mult_32_16( Ep_vari_fx, 3277 ); /*13+15-15=13 */ - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( 12, exp ), &Overflow ); /*Q(13+exp-15 +12-exp +4 = 14) */ - tmp2 = extract_h( Ep_avrg_fx ); /*Q13-16=-3 */ + L_tmp = Mult_32_16( Ep_vari_fx, 3277 ); /*13+15-15=13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( Mult_32_16( L_tmp, tmp ), sub( 12, exp ) ); /*Q(13+exp-15 +12-exp +4 = 14) */ +#else + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( 12, exp ), &Overflow ); /*Q(13+exp-15 +12-exp +4 = 14) */ +#endif + tmp2 = extract_h( Ep_avrg_fx ); /*Q13-16=-3 */ IF( tmp2 != 0 ) { exp = norm_s( tmp2 ); @@ -623,10 +629,14 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp2 = Mult_32_16( Ep_vari_fx, 6554 ); /*13+15-15=13 */ - L_tmp2 = L_shl_o( Mult_32_16( L_tmp2, tmp2 ), sub( 13, exp ), &Overflow ); /*Q(13+exp-15 +13-exp +3 = 14) */ - L_tmp = L_min( L_tmp, L_tmp2 ); /*Q14 */ - tmp = extract_l( L_min( L_tmp, 13107 ) ); /*Q14 */ + L_tmp2 = Mult_32_16( Ep_vari_fx, 6554 ); /*13+15-15=13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp2 = L_shl_sat( Mult_32_16( L_tmp2, tmp2 ), sub( 13, exp ) ); /*Q(13+exp-15 +13-exp +3 = 14) */ +#else + L_tmp2 = L_shl_o( Mult_32_16( L_tmp2, tmp2 ), sub( 13, exp ), &Overflow ); /*Q(13+exp-15 +13-exp +3 = 14) */ +#endif + L_tmp = L_min( L_tmp, L_tmp2 ); /*Q14 */ + tmp = extract_l( L_min( L_tmp, 13107 ) ); /*Q14 */ alpha_fx = add( 16384, tmp ); } IF( EQ_16( hHQ_core->last_bitalloc_max_band[j++], 1 ) ) @@ -647,10 +657,14 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = L_shl_o( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ), &Overflow ); /*Q(13+exp-15 +14-exp+2 = 14) */ - L_tmp = L_max( L_tmp, 16384 ); /*Q14 */ - tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*Q14 */ - alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=Q14 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ +#else + L_tmp = L_shl_o( Mult_32_16( Ep_avrg_fx, tmp ), sub( 14, exp ), &Overflow ); /*Q(13+exp-15 +14-exp+2 = 14) */ +#endif + L_tmp = L_max( L_tmp, 16384 ); /*Q14 */ + tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*Q14 */ + alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=Q14 */ } ELSE { @@ -670,11 +684,15 @@ void hq_lr_enc_fx( exp = 0; move16(); } - L_tmp = L_shl_o( Mult_32_16( Ep_tmp_fx[i], tmp2 ), sub( 19, exp ), &Overflow ); /*Q(13+exp-15 +19-exp +3 = 20) */ - L_tmp = Mult_32_16( L_tmp, shl( sub( bands_fx, lowband ), 9 ) ); /*20 +9 -15 =Q14 */ - L_tmp = L_max( L_tmp, 13926 ); /*Q14 */ - tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*Q14 */ - alpha_fx = shl( mult( alpha_fx, tmp2 ), 1 ); /*14+14-15+1 =Q14 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( Mult_32_16( Ep_tmp_fx[i], tmp2 ), sub( 19, exp ) ); /*Q(13+exp-15 +19-exp +3 = 20) */ +#else + L_tmp = L_shl_o( Mult_32_16( Ep_tmp_fx[i], tmp2 ), sub( 19, exp ), &Overflow ); /*Q(13+exp-15 +19-exp +3 = 20) */ +#endif + L_tmp = Mult_32_16( L_tmp, shl( sub( bands_fx, lowband ), 9 ) ); /*20 +9 -15 =Q14 */ + L_tmp = L_max( L_tmp, 13926 ); /*Q14 */ + tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*Q14 */ + alpha_fx = shl( mult( alpha_fx, tmp2 ), 1 ); /*14+14-15+1 =Q14 */ } L_band_energy_tmp[i] = L_shl( Mult_32_16( L_band_energy_tmp[i], alpha_fx ), 1 ); /*Q(Q_band_energy+14-15 +1= Q_band_energy) */ move32(); @@ -749,7 +767,11 @@ void hq_lr_enc_fx( bit_budget_fx = sub( bit_budget_fx, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not Q0*/ FOR( i = 0; i < bands_fx; i++ ) { - Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); /* Q15 */ +#else + Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */ +#endif move32(); } IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) @@ -781,7 +803,11 @@ void hq_lr_enc_fx( IF( GE_16( i, lowband ) && add( sub( i, bands_fx ), p2a_bands_fx ) < 0 ) { Ep_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[( i - 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif } IF( GE_16( i, highband ) ) @@ -849,8 +875,12 @@ void hq_lr_enc_fx( IF( EQ_16( hHQ_core->last_bitalloc_max_band[sub( i, add( tmp, 1 ) )], 1 ) ) { tmp = sub( tmp, lowband ); - L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ - tmp = extract_h( L_shl_o( L_tmp, 16, &Overflow ) ); /*Q0 */ + L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = extract_h( L_shl_sat( L_tmp, 16 ) ); /*Q0 */ +#else + tmp = extract_h( L_shl_o( L_tmp, 16, &Overflow ) ); /*Q0 */ +#endif IF( tmp != 0 ) { exp = norm_s( tmp ); @@ -911,11 +941,19 @@ void hq_lr_enc_fx( { IF( GE_16( i, lowband ) ) { - Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif } ELSE { - Ep_avrgL_fx = L_add_o( Ep_avrgL_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrgL_fx = L_add_o( Ep_avrgL_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) ) { Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ @@ -1179,8 +1217,10 @@ void hq_lr_enc_ivas_fx( Word32 L_band_energy_tmp[BANDS_MAX]; UWord16 lo; Word16 Q_band_energy; +#ifndef ISSUE_1867_replace_overflow_libenc Flag Overflow; move32(); +#endif BSTR_ENC_HANDLE hBstr = st->hBstr; HQ_ENC_HANDLE hHQ_core = st->hHQ_core; @@ -1448,7 +1488,11 @@ void hq_lr_enc_ivas_fx( } ELSE { - Ep_avrgL_fx = L_add_o( Ep_avrgL_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrgL_fx = L_add_o( Ep_avrgL_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) { Ep_peak_fx = Ep_tmp_fx[i]; /*Q15 */ @@ -1572,10 +1616,14 @@ void hq_lr_enc_ivas_fx( move16(); } Mpy_32_16_ss( Ep_avrg_fx, tmp, &L_tmp, &lo ); - L_tmp = L_shl_o( L_tmp, sub( 14, exp ), &Overflow ); /*Q(13+exp-15 +14-exp+2 = 14) */ - L_tmp = L_max( L_tmp, 16384 ); /*14 */ - tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */ - alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, sub( 14, exp ) ); /*Q(13+exp-15 +14-exp+2 = 14) */ +#else + L_tmp = L_shl_o( L_tmp, sub( 14, exp ), &Overflow ); /*Q(13+exp-15 +14-exp+2 = 14) */ +#endif + L_tmp = L_max( L_tmp, 16384 ); /*14 */ + tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */ + alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */ } ELSE { @@ -1619,7 +1667,11 @@ void hq_lr_enc_ivas_fx( { IF( sub( i, lowband ) >= 0 ) { - Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif } ELSE { @@ -1661,8 +1713,12 @@ void hq_lr_enc_ivas_fx( Mpy_32_16_ss( Ep_peak_fx, tmp, &L_tmp, &lo ); Mpy_32_16_ss( L_tmp, lowband, &L_tmp, &lo ); Mpy_32_16_ss( L_tmp, 18842, &L_tmp, &lo ); - L_tmp = L_shl_o( L_tmp, sub( 27, exp ), &Overflow ); /*Q14 0.5 */ - tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, sub( 27, exp ) ); /*Q14 0.5 */ +#else + L_tmp = L_shl_o( L_tmp, sub( 27, exp ), &Overflow ); /*Q14 0.5 */ +#endif + tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */ Mpy_32_16_ss( L_band_energy_tmp[i], tmp2, &L_tmp, &lo ); L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */ move32(); @@ -1685,7 +1741,11 @@ void hq_lr_enc_ivas_fx( bit_budget = sub( bit_budget, 2 ); /* bits in high bands to indicate the last 2 subbands is allocated bits or not */ FOR( i = 0; i < bands; i++ ) { - Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_tmp_fx[i] = L_shl_sat( Ep_tmp_fx[i], 2 ); /* Q15 */ +#else + Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */ +#endif move32(); } IF( EQ_32( st->core_brate, ACELP_13k20 ) ) @@ -1721,7 +1781,11 @@ void hq_lr_enc_ivas_fx( IF( sub( i, lowband ) >= 0 && add( sub( i, bands ), p2a_bands ) < 0 ) { Ep_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*Q15 */ - Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif } IF( sub( i, highband ) >= 0 ) @@ -1754,7 +1818,11 @@ void hq_lr_enc_ivas_fx( tmp = sub( bands, p2a_bands ); tmp = sub( tmp, lowband ); /*Q0 */ - tmp1 = extract_h( L_shl_o( Ep_avrg_fx, 1, &Overflow ) ); /*Q0 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ +#else + tmp1 = extract_h( L_shl_o( Ep_avrg_fx, 1, &Overflow ) ); /*Q0 */ +#endif IF( tmp1 != 0 ) { exp = norm_s( tmp1 ); @@ -1793,7 +1861,11 @@ void hq_lr_enc_ivas_fx( { tmp = sub( tmp, lowband ); Mpy_32_16_ss( Ep_tmp_fx[i], tmp, &L_tmp, &lo ); - tmp = extract_h( L_shl_o( L_tmp, 16, &Overflow ) ); /*Q0 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = extract_h( L_shl_sat( L_tmp, 16 ) ); /*Q0 */ +#else + tmp = extract_h( L_shl_o( L_tmp, 16, &Overflow ) ); /*Q0 */ +#endif IF( tmp != 0 ) { exp = norm_s( tmp ); @@ -1818,7 +1890,11 @@ void hq_lr_enc_ivas_fx( { tmp = sub( tmp, lowband ); - tmp1 = extract_h( L_shl_o( Ep_avrg_fx, 1, &Overflow ) ); /*Q0 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = extract_h( L_shl_sat( Ep_avrg_fx, 1 ) ); /*Q0 */ +#else + tmp1 = extract_h( L_shl_o( Ep_avrg_fx, 1, &Overflow ) ); /*Q0 */ +#endif IF( tmp1 != 0 ) { exp = norm_s( tmp1 ); @@ -1857,11 +1933,19 @@ void hq_lr_enc_ivas_fx( { IF( sub( i, lowband ) >= 0 ) { - Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrg_fx = L_add_sat( Ep_avrg_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif } ELSE { - Ep_avrgL_fx = L_add_o( Ep_avrgL_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ep_avrgL_fx = L_add_sat( Ep_avrgL_fx, Ep_tmp_fx[i] ); /*Q15 */ +#else + Ep_avrgL_fx = L_add_o( Ep_avrgL_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */ +#endif IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 ) { Ep_peak_fx = Ep_tmp_fx[i]; /* Q15 */ @@ -1886,7 +1970,11 @@ void hq_lr_enc_ivas_fx( move16(); FOR( i = 0; i < lowband; i++ ) { - tmp = extract_h( L_shl_o( Ep_avrgL_fx, 1, &Overflow ) ); /*Q0 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = extract_h( L_shl_sat( Ep_avrgL_fx, 1 ) ); /*Q0 */ +#else + tmp = extract_h( L_shl_o( Ep_avrgL_fx, 1, &Overflow ) ); /*Q0 */ +#endif IF( tmp != 0 ) { exp = norm_s( tmp ); @@ -3394,9 +3482,11 @@ static Word16 p2a_threshold_quant_fx( Word32 L_p2a; Word16 p2a_fx; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif exp_safe = 4; /* never happen overflow. */ @@ -3464,7 +3554,11 @@ static Word16 p2a_threshold_quant_fx( /* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */ L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */ - p2a_fx = round_fx_o( L_shl_o( L_p2a, 13, &Overflow ), &Overflow ); /* 27 -16 -> 11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + p2a_fx = round_fx_sat( L_shl_sat( L_p2a, 13 ) ); /* 27 -16 -> 11 */ +#else + p2a_fx = round_fx_o( L_shl_o( L_p2a, 13, &Overflow ), &Overflow ); /* 27 -16 -> 11 */ +#endif } IF( LE_16( p2a_fx, p2a_th_fx ) ) @@ -3514,9 +3608,11 @@ static Word16 p2a_threshold_quant_ivas_fx( Word32 L_p2a; Word16 p2a_fx; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif exp_safe = 4; /* never happen overflow. */ @@ -3583,7 +3679,11 @@ static Word16 p2a_threshold_quant_ivas_fx( /* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */ L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */ - p2a_fx = round_fx_o( L_shl_o( L_p2a, 13, &Overflow ), &Overflow ); /* 27 -16 -> 11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + p2a_fx = round_fx_sat( L_shl_sat( L_p2a, 13 ) ); /* 27 -16 -> 11 */ +#else + p2a_fx = round_fx_o( L_shl_o( L_p2a, 13, &Overflow ), &Overflow ); /* 27 -16 -> 11 */ +#endif } IF( LE_16( p2a_fx, p2a_th_fx ) ) @@ -3650,9 +3750,11 @@ static void mdct_spectrum_fine_gain_enc_fx( Word16 d_fx; Word16 dmin_fx; Word16 imin_fx; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Fine gain quantization on only the most significant energy bands */ @@ -3723,9 +3825,13 @@ static void mdct_spectrum_fine_gain_enc_fx( exp_normn = norm_l( L_Exy ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_l( L_Eyy ); +#ifdef ISSUE_1867_replace_overflow_libenc + gamma_fx = div_l( L_shl( L_Exy, exp_normn ), round_fx_sat( L_shl( L_Eyy, exp_normd ) ) ); /* Qgamma */ +#else gamma_fx = div_l( L_shl_o( L_Exy, exp_normn, &Overflow ), round_fx_o( L_shl_o( L_Eyy, exp_normd, &Overflow ), &Overflow ) ); /* Qgamma */ - Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ - gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ +#endif + Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ + gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ dmin_fx = 32767; move16(); @@ -3812,9 +3918,11 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( Word16 d_fx; Word16 dmin_fx; Word16 imin_fx; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Fine gain quantization on only the most significant energy bands */ @@ -3885,9 +3993,13 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( exp_normn = norm_l( L_Exy ); exp_normn = sub( exp_normn, 1 ); exp_normd = norm_l( L_Eyy ); +#ifdef ISSUE_1867_replace_overflow_libenc + gamma_fx = div_l( L_shl( L_Exy, exp_normn ), round_fx_sat( L_shl( L_Eyy, exp_normd ) ) ); /* Qgamma */ +#else gamma_fx = div_l( L_shl_o( L_Exy, exp_normn, &Overflow ), round_fx_o( L_shl_o( L_Eyy, exp_normd, &Overflow ), &Overflow ) ); /* Qgamma */ - Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ - gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ +#endif + Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ + gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ dmin_fx = 32767; move16(); diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 1c0af21213bbab385cc9d409102abcd8aa2daf9c..60cf0159a7cb65c07e85301813f0efa04a6f4bc1 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -49,9 +49,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3; Word16 manPeMean, manNfMean, manNfpe, man; Word16 tmp16, adjust; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif bits_used = 0; move16(); @@ -118,7 +120,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits nf_cnt = add( nf_cnt, 1 ); /* Q0 */ } - pe_mean = L_add_o( pe_mean, pe, &Overflow ); /* in Q12 and always positive */ +#ifdef ISSUE_1867_replace_overflow_libenc + pe_mean = L_add_sat( pe_mean, pe ); /* in Q12 and always positive */ +#else + pe_mean = L_add_o( pe_mean, pe, &Overflow ); /* in Q12 and always positive */ +#endif } IF( pe_mean > 0 ) @@ -145,8 +151,12 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits acc = L_mult( tmp16, HVQ_NFPE_FACTOR_CUBE_FX ); /* in Q(12+6+1) = Q19 */ expNfpe3 = extract_l( L_mult0( expNfpe, 3 ) ); /* Cube operation */ /* Number of bits required to adjust to Q15 */ - adjust = add( 19 - ( 15 + 16 ), expNfpe3 ); /* +16 is due to the following extract_h(). */ + adjust = add( 19 - ( 15 + 16 ), expNfpe3 ); /* +16 is due to the following extract_h(). */ +#ifdef ISSUE_1867_replace_overflow_libenc + noise_level[i] = extract_h( L_shr_sat( acc, adjust ) ); /* noise_level[] in Q15 */ +#else noise_level[i] = extract_h( L_shr_sat( acc, adjust ) ); /* noise_level[] in Q15 */ +#endif move16(); q_noise_level_idx[i] = quant_lc_fx( noise_level[i], &q_noise_level[i] ); move16(); @@ -226,9 +236,11 @@ Word16 hvq_enc_fx( /*o : Consumed bits Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3; Word16 manPeMean, manNfMean, manNfpe, man; Word16 tmp16, adjust; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif bits_used = 0; move16(); @@ -295,7 +307,11 @@ Word16 hvq_enc_fx( /*o : Consumed bits nf_cnt = add( nf_cnt, 1 ); /* Q0 */ } - pe_mean = L_add_o( pe_mean, pe, &Overflow ); /* in Q12 and always positive */ +#ifdef ISSUE_1867_replace_overflow_libenc + pe_mean = L_add_sat( pe_mean, pe ); /* in Q12 and always positive */ +#else + pe_mean = L_add_o( pe_mean, pe, &Overflow ); /* in Q12 and always positive */ +#endif } IF( pe_mean > 0 ) diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index c57f5ffb014c41b53f7a2caeff06cac9fcd422e3..2a96904e1ad651c9bdba754ee6ef004bee6d9d34 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -93,9 +93,11 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< Word16 tmp_exp; Word32 L_tmp; Word16 shift; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* initialize variables */ @@ -218,8 +220,13 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< move16(); } +#ifdef ISSUE_1867_replace_overflow_libenc + BASOP_Util_Divide_MantExp( round_fx_sat( sfbEnergyTileR[sfb] ), sfbEnergyTileR_exp[sfb], width, 15, &gain, &gain_exp ); + BASOP_Util_Divide_MantExp( round_fx_sat( sfbEnergyC[sfb] ), sfbEnergyC_exp[sfb], round_fx_sat( sfbEnergyTileC[sfb] ), sfbEnergyTileC_exp[sfb], &tmp, &tmp_exp ); +#else BASOP_Util_Divide_MantExp( round_fx_o( sfbEnergyTileR[sfb], &Overflow ), sfbEnergyTileR_exp[sfb], width, 15, &gain, &gain_exp ); BASOP_Util_Divide_MantExp( round_fx_o( sfbEnergyC[sfb], &Overflow ), sfbEnergyC_exp[sfb], round_fx_o( sfbEnergyTileC[sfb], &Overflow ), sfbEnergyTileC_exp[sfb], &tmp, &tmp_exp ); +#endif L_tmp = L_mult( gain, tmp ); gain_exp = add( gain_exp, tmp_exp ); } @@ -247,7 +254,11 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< L_tmp = BASOP_Util_Log2( L_tmp ); L_tmp = L_add( L_tmp, L_deposit_h( shl( gain_exp, 15 - 6 ) ) ); shift = norm_l( L_tmp ); +#ifdef ISSUE_1867_replace_overflow_libenc + gain = round_fx_sat( L_shl( L_tmp, shift ) ); +#else gain = round_fx_o( L_shl_o( L_tmp, shift, &Overflow ), &Overflow ); +#endif gain_exp = sub( 7, shift ); gain_exp = BASOP_Util_Add_MantExp( gain, gain_exp, 32767 /*16 Q11*/, 4, &gain ); gain_exp = BASOP_Util_Add_MantExp( gain, gain_exp, 0x4000, 0, &gain ); @@ -442,8 +453,13 @@ void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< ou /* May overflow - just for threshold comparison */ /* negate because the negated may be 1 larger in abs, */ /* so whenever compared to the negation of a maximum possible pPowerspectrum, it is still larger */ +#ifdef ISSUE_1867_replace_overflow_libenc + highPassEner_Ovfl = L_shl_sat( L_negate( highPassEner ), sub( *highPassEner_exp, pPowerSpectrum_exp ) ); + L_tmp = L_add_sat( pPowerSpectrum[i - 1], highPassEner_Ovfl ); +#else highPassEner_Ovfl = L_shl_o( L_negate( highPassEner ), sub( *highPassEner_exp, pPowerSpectrum_exp ), &Overflow ); L_tmp = L_add_o( pPowerSpectrum[i - 1], highPassEner_Ovfl, &Overflow ); +#endif if ( L_tmp >= 0 ) { diff --git a/lib_enc/ivas_tcx_core_enc_fx.c b/lib_enc/ivas_tcx_core_enc_fx.c index da141f473432c7384c43abc984a1f67b800d5514..c48cb87fe2383a7b626a59f7eb1190f7a7777627 100644 --- a/lib_enc/ivas_tcx_core_enc_fx.c +++ b/lib_enc/ivas_tcx_core_enc_fx.c @@ -753,7 +753,9 @@ Word16 ivas_acelp_tcx20_switching_fx( Word32 offset_tcx, target; Word32 y_fx[N_MAX]; Word32 tcx_snr; +#ifndef ISSUE_1867_replace_overflow_libenc Flag Overflow; +#endif Word32 gain, noise; Word16 noise_e = 0; move16(); @@ -1241,7 +1243,11 @@ Word16 ivas_acelp_tcx20_switching_fx( test(); if ( ( GT_32( snr_acelp, tcx_snr ) ) && ( LT_32( snr_acelp, L_add( tcx_snr, 131072 /*2.0f Q16*/ ) ) ) && +#ifdef ISSUE_1867_replace_overflow_libenc + ( LT_32( L_add_sat( st->prevTempFlatness_32fx, currFlatness ), 6815744 /*3.25f Q21*/ ) || EQ_16( stab_fac, 0x7fff ) || +#else ( LT_32( L_add_o( st->prevTempFlatness_32fx, currFlatness, &Overflow ), 6815744 /*3.25f Q21*/ ) || EQ_16( stab_fac, 0x7fff ) || +#endif ( !flag_16k_smc && ( st->sp_aud_decision0 > 0 ) && LT_32( L_add_sat( st->prevTempFlatness_32fx, currFlatness ), 41943040 /*20.f Q21*/ ) ) ) && ( LE_16( st->Nb_ACELP_frames, 6 ) ) ) { diff --git a/lib_enc/lsf_enc_fx.c b/lib_enc/lsf_enc_fx.c index 1e9a2a511d5593eaa3d269e43371e283ecf0838d..8d6801bc5dde71aa26f12d6f8ad8a6566b6af0e0 100644 --- a/lib_enc/lsf_enc_fx.c +++ b/lib_enc/lsf_enc_fx.c @@ -766,8 +766,10 @@ static Word16 qlsf_Mode_Select_fx( Word32 temp32, En = 0; Word16 safety_net; Word16 i, cs, cl; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /* calculate the prediction residual */ @@ -784,7 +786,11 @@ static Word16 qlsf_Mode_Select_fx( { pred_pow2[i] = shl( pred1[i], cs ); move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + En = L_mac_sat( En, mult( pred_pow2[i], shl_sat( w[i], 2 ) ), pred_pow2[i] ); /* 2.56*2.56 at Q-4 */ +#else En = L_mac_o( En, mult( pred_pow2[i], shl_sat( w[i], 2 ) ), pred_pow2[i], &Overflow ); /* 2.56*2.56 at Q-4 */ +#endif } cs = shl( cs, 1 ); @@ -1964,8 +1970,10 @@ static void first_VQstages( Word16 *pTmp_short, idx_buf[2 * LSFMBEST * MAX_VQ_STAGES], parents[LSFMBEST], counter = 0, j, m, s, c, c2, p_max, *indices[2]; Word16 maxC = LSFMBEST; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /*float dd[16];*/ @@ -1992,9 +2000,13 @@ static void first_VQstages( L_tmp = L_deposit_l( 0 ); FOR( j = 0; j < N; j++ ) { - L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */ - L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ - L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = L_shl_sat( L_mult0( u[j], w[j] ), 7 ); /*x2.56 + Q8 + Q7 */ +#else + L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */ +#endif + L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ + L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ } set32_fx( dist[1], L_tmp, maxC ); @@ -2154,8 +2166,10 @@ static void first_VQstages_ivas_fx( Word16 *pTmp_short, idx_buf[2 * LSFMBEST * MAX_VQ_STAGES], parents[LSFMBEST], counter = 0, j, m, s, c, c2, p_max, *indices[2]; Word16 maxC = LSFMBEST; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /*float dd[16];*/ @@ -2182,9 +2196,13 @@ static void first_VQstages_ivas_fx( L_tmp = L_deposit_l( 0 ); FOR( j = 0; j < N; j++ ) { - L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */ - L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ - L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = L_shl_sat( L_mult0( u[j], w[j] ), 7 ); /*x2.56 + Q8 + Q7 */ +#else + L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */ +#endif + L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ + L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ } set32_fx( dist[1], L_shr( L_tmp, 1 ), maxC ); /*Q-1 + x2.56 +x2.56 */ @@ -2544,7 +2562,7 @@ static Word32 vq_lvq_lsf_enc_ivas_fx( #ifdef FIX_1979_SAT_MISSING_IN_LSF_ENC L_tmp = L_mac_sat( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ #else - L_tmp = L_mac( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ + L_tmp = L_mac( L_tmp, mult( diff[j], shl_sat( w[j], 1 ) ), diff[j] ); /*(2.56+Q5+ Q10 -Q15) + 2.56+ Q5 + Q1 = 2.56 + 2.56 + Q6 */ #endif } e[i] = L_tmp; @@ -3320,8 +3338,10 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx( Word16 error_svq_fx[M], error_svq_q_fx[M]; Word16 cl, cs; Word32 temp_l; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif IF( EQ_16( safety_net, 1 ) ) { @@ -3394,7 +3414,11 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx( { yy_fx[i] = shl( yy_fx[i], cs ); move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + temp_l = L_mac_sat( temp_l, mult( yy_fx[i], shl_sat( w_fx[i], 2 ) ), yy_fx[i] ); +#else temp_l = L_mac_o( temp_l, mult( yy_fx[i], shl_sat( w_fx[i], 2 ) ), yy_fx[i], &Overflow ); +#endif } cs = shl( cs, 1 ); temp_l = L_shr( temp_l, cs ); @@ -3413,14 +3437,20 @@ static void FFT_Mid_Interpol_16k_fx( ) { Word16 i; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif FOR( i = 0; i < L_FFT / 2; i++ ) { /* Interpolation */ +#ifdef ISSUE_1867_replace_overflow_libenc + Bin_Ener_mid[i] = L_shr( L_add_sat( Bin_Ener_old[i], Bin_Ener[i] ), 1 ); +#else Bin_Ener_mid[i] = L_shr( L_add_o( Bin_Ener_old[i], Bin_Ener[i], &Overflow ), 1 ); +#endif /* Memory update */ Bin_Ener_old[i] = Bin_Ener[i]; @@ -3485,8 +3515,10 @@ static void lsf_mid_enc_fx( Word32 L_tmp; Word16 tmp, k1; const Word16 *ratio = NULL; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /* convert LSPs to LSFs */ @@ -3599,8 +3631,13 @@ static void lsf_mid_enc_fx( /* err += wghts[j] * ftemp * ftemp; */ /* tmp is usually very small, we can have some extra precision with very rare saturation */ tmp = shl_sat( tmp, 4 ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = mult_r_sat( tmp, tmp ); + err = L_mac_sat( err, tmp, shl_sat( wghts[j], 2 ) ); +#else tmp = mult_ro( tmp, tmp, &Overflow ); err = L_mac_o( err, tmp, shl_sat( wghts[j], 2 ), &Overflow ); +#endif } /* err = L_shl(err,Wscale); */ err = Mult_32_16( err, LSF_1_OVER_256SQ ); @@ -3662,8 +3699,10 @@ static void lsf_mid_enc_ivas_fx( Word32 L_tmp; Word16 tmp, k1; const Word16 *ratio = NULL; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /* convert LSPs to LSFs */ @@ -3785,8 +3824,13 @@ static void lsf_mid_enc_ivas_fx( /* err += wghts[j] * ftemp * ftemp; */ /* tmp is usually very small, we can have some extra precision with very rare saturation */ tmp = shl_sat( tmp, 4 ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = mult_r_sat( tmp, tmp ); + err = L_mac_sat( err, tmp, shl_sat( wghts[j], 2 ) ); +#else tmp = mult_ro( tmp, tmp, &Overflow ); err = L_mac_o( err, tmp, shl_sat( wghts[j], 2 ), &Overflow ); +#endif } /* err = L_shl(err,Wscale); */ err = Mult_32_16( err, LSF_1_OVER_256SQ ); diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 8e04e86d9e10435a9bb24017cfeb8c653a41bb5a..0cb31e6f0aeb8cf33a2927e93fec8c359d535c13 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -1578,8 +1578,10 @@ void midlsf_enc_fx( Word32 err, err_min, L_tmp; Word16 k, k1, j, tmp, size, qlsf[M], wghts[M]; const Word16 *ratio; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif IF( EQ_16( coder_type, UNVOICED ) ) @@ -1631,10 +1633,18 @@ void midlsf_enc_fx( /* err += wghts[j] * ftemp * ftemp; */ /* tmp is usually very small, we can have some extra precision with very rare saturation */ tmp = shl_sat( tmp, 4 ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = mult_r_sat( tmp, tmp ); +#else tmp = mult_ro( tmp, tmp, &Overflow ); +#endif err = L_mac( err, tmp, wghts[j] ); } +#ifdef ISSUE_1867_replace_overflow_libenc + err = L_shl_sat( err, 2 ); +#else err = L_shl_o( err, 2, &Overflow ); +#endif /* err = L_shl(err,Wscale); */ err = Mult_32_16( err, LSF_1_OVER_256SQ ); diff --git a/lib_enc/mdct_classifier_fx.c b/lib_enc/mdct_classifier_fx.c index ea06878c12f389f63c66e199003cebe35938f4ad..790ec7aa8db0985304b0d493b99aace1fc44c3e6 100644 --- a/lib_enc/mdct_classifier_fx.c +++ b/lib_enc/mdct_classifier_fx.c @@ -118,8 +118,10 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision Word16 exp, exp1, exp2, exp3; Word32 L_tmp, L_tmp1; TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif test(); { @@ -356,7 +358,11 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); test(); +#ifdef ISSUE_1867_replace_overflow_libenc + IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_sat( avrg_H1, 1 ) ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( L_tmp, exp ), L_shl( avrg_l, exp1 ) ) ) || GT_32( Mult_32_32( L_shl( L_tmp1, exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) ) +#else IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_o( avrg_H1, 1, &Overflow ) ) ) || ( LT_32( Mult_32_32( L_shl_o( peak_l, exp, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( L_tmp, exp, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) || GT_32( Mult_32_32( L_shl_o( L_tmp1, exp2, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( peak_h, exp2, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) ) ) +#endif { condition3 = 1; move16(); @@ -450,7 +456,11 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision test(); test(); test(); +#ifdef ISSUE_1867_replace_overflow_libenc + IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_sat( gain1_tmp, 1 ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_sat( gain2_tmp, 1 ) ) ) ) ) +#else IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_o( gain1_tmp, 1, &Overflow ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_o( gain2_tmp, 1, &Overflow ) ) ) ) ) +#endif { clas_final = hTcxEnc->clas_final_old; move16(); @@ -543,8 +553,10 @@ Word16 mdct_classifier_ivas_fx( Word16 exp, exp1, exp2, exp3; Word32 gain1_tmp = 0, gain2_tmp = 0; Word32 L_tmp, L_tmp1; +#ifndef ISSUE_1867_replace_overflow_libenc Flag Overflow = 0; move16(); +#endif move16(); move16(); @@ -888,7 +900,11 @@ Word16 mdct_classifier_ivas_fx( test(); test(); test(); +#ifdef ISSUE_1867_replace_overflow_libenc + IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_sat( avrg_H1, 1 ) ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( L_tmp, exp ), L_shl( avrg_l, exp1 ) ) ) || GT_32( Mult_32_32( L_shl( L_tmp1, exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) ) +#else IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_o( avrg_H1, 1, &Overflow ) ) ) || ( LT_32( Mult_32_32( L_shl_o( peak_l, exp, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( L_tmp, exp, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) || GT_32( Mult_32_32( L_shl_o( L_tmp1, exp2, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( peak_h, exp2, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) ) ) +#endif { condition3 = 1; move16(); @@ -989,7 +1005,11 @@ Word16 mdct_classifier_ivas_fx( test(); test(); +#ifdef ISSUE_1867_replace_overflow_libenc + IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_sat( gain1_tmp, 1 ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_sat( gain2_tmp, 1 ) ) ) ) ) +#else IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_o( gain1_tmp, 1, &Overflow ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_o( gain2_tmp, 1, &Overflow ) ) ) ) ) +#endif { clas_final = hTcxEnc->clas_final_old; move16(); diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 665ee5edf2212f65e35f6b46db88e99745cdd034..ba68b685208adcafee3a7dfaf8ae74fead13a6f7 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -41,9 +41,11 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity Word32 L_acc; Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum; Word16 mean_dyn; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*------------------------------------------------------------------* @@ -212,7 +214,11 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity IF( EQ_16( i, ind_mins[k] ) ) { /* include the last peak point (new minimum) to the corr. sum */ +#ifdef ISSUE_1867_replace_overflow_libenc + Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] ); +#else Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow ); +#endif /* calculation of the norm. peak correlation */ test(); @@ -263,9 +269,15 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity k++; } +#ifdef ISSUE_1867_replace_overflow_libenc + Lcorx2 = L_mac_sat( Lcorx2, S[i], S[i] ); + Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] ); + Lcorxy = L_mac_sat( Lcorxy, S[i], old_S[i] ); +#else Lcorx2 = L_mac_o( Lcorx2, S[i], S[i], &Overflow ); Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow ); Lcorxy = L_mac_o( Lcorxy, S[i], old_S[i], &Overflow ); +#endif } Copy( S, old_S, ind_mins[0] ); @@ -384,9 +396,11 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni Word32 L_acc; Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum; Word16 mean_dyn; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*------------------------------------------------------------------* @@ -549,7 +563,11 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni IF( EQ_16( i, ind_mins[k] ) ) { /* include the last peak point (new minimum) to the corr. sum */ +#ifdef ISSUE_1867_replace_overflow_libenc + Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] ); +#else Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow ); +#endif /* calculation of the norm. peak correlation */ test(); @@ -600,9 +618,15 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni k++; } +#ifdef ISSUE_1867_replace_overflow_libenc + Lcorx2 = L_mac_sat( Lcorx2, S[i], S[i] ); + Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] ); + Lcorxy = L_mac_sat( Lcorxy, S[i], old_S[i] ); +#else Lcorx2 = L_mac_o( Lcorx2, S[i], S[i], &Overflow ); Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow ); Lcorxy = L_mac_o( Lcorxy, S[i], old_S[i], &Overflow ); +#endif } Copy( S, old_S, ind_mins[0] ); diff --git a/lib_enc/nelp_enc_fx.c b/lib_enc/nelp_enc_fx.c index 39119117598387b0be7081d46dd47b4c72c5a87a..9d192500f9f83c415b6ad3031c9c9b99b9959163 100644 --- a/lib_enc/nelp_enc_fx.c +++ b/lib_enc/nelp_enc_fx.c @@ -354,9 +354,11 @@ void nelp_encoder_fx( move32(); Word16 BP1_ORDER; Word16 rf_flag; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -422,7 +424,11 @@ void nelp_encoder_fx( E1_fx = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME; i++ ) { - E1_fx = L_mac0_o( E1_fx, in_fx[i], in_fx[i], &Overflow ); /*Q(qE1+qE1) */ +#ifdef ISSUE_1867_replace_overflow_libenc + E1_fx = L_mac0_sat( E1_fx, in_fx[i], in_fx[i] ); /*Q(qE1+qE1) */ +#else + E1_fx = L_mac0_o( E1_fx, in_fx[i], in_fx[i], &Overflow ); /*Q(qE1+qE1) */ +#endif } qE1 = shl( qE1, 1 ); @@ -438,7 +444,11 @@ void nelp_encoder_fx( EL1_fx = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + EL1_fx = L_mac0_sat( EL1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qIn) */ +#else EL1_fx = L_mac0_o( EL1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qIn) */ +#endif } qEL1 = shl( qEL1, 1 ); @@ -454,7 +464,11 @@ void nelp_encoder_fx( EH1_fx = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + EH1_fx = L_mac0_sat( EH1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH1) */ +#else EH1_fx = L_mac0_o( EH1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qEH1) */ +#endif } qEH1 = 2 * qEH1; move16(); @@ -470,7 +484,11 @@ void nelp_encoder_fx( Ltemp = L_deposit_l( 0 ); FOR( j = (Word16) ( i * lag ); j < (Word16) ( ( i + 1 ) * lag ); j++ ) { - Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ +#else + Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#endif } /*Gains[i] = (float) sqrt(Gains[i]/lag); */ @@ -494,7 +512,11 @@ void nelp_encoder_fx( Ltemp = L_deposit_l( 0 ); FOR( j = (Word16) ( i * lag ); j < L_FRAME; j++ ) { - Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ +#else + Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#endif } /*Gains[i] = (float) sqrt(Gains[i]/(L_FRAME-(lag*i))); */ @@ -1099,9 +1121,11 @@ void nelp_encoder_ivas_fx( move32(); Word16 BP1_ORDER; Word16 rf_flag; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -1169,7 +1193,11 @@ void nelp_encoder_ivas_fx( E1_fx = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME; i++ ) { - E1_fx = L_mac0_o( E1_fx, in_fx[i], in_fx[i], &Overflow ); /*Q(qE1+qE1) */ +#ifdef ISSUE_1867_replace_overflow_libenc + E1_fx = L_mac0_sat( E1_fx, in_fx[i], in_fx[i] ); /*Q(qE1+qE1) */ +#else + E1_fx = L_mac0_o( E1_fx, in_fx[i], in_fx[i], &Overflow ); /*Q(qE1+qE1) */ +#endif } qE1 = shl( qE1, 1 ); @@ -1184,7 +1212,11 @@ void nelp_encoder_ivas_fx( EL1_fx = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + EL1_fx = L_mac0_sat( EL1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qIn) */ +#else EL1_fx = L_mac0_o( EL1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qIn) */ +#endif } qEL1 = shl( qEL1, 1 ); @@ -1200,7 +1232,11 @@ void nelp_encoder_ivas_fx( EH1_fx = L_deposit_l( 0 ); FOR( i = 0; i < L_FRAME; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + EH1_fx = L_mac0_sat( EH1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH1) */ +#else EH1_fx = L_mac0_o( EH1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qEH1) */ +#endif } qEH1 = shl( qEH1, 1 ); move16(); @@ -1215,7 +1251,11 @@ void nelp_encoder_ivas_fx( Ltemp = L_deposit_l( 0 ); FOR( j = (Word16) ( i * lag ); j < (Word16) ( ( i + 1 ) * lag ); j++ ) { - Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ +#else + Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#endif } /*Gains[i] = (float) sqrt(Gains[i]/lag); */ @@ -1239,7 +1279,11 @@ void nelp_encoder_ivas_fx( Ltemp = L_deposit_l( 0 ); FOR( j = i_mult( i, lag ); j < L_FRAME; j++ ) { - Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */ +#else + Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */ +#endif } /*Gains[i] = (float) sqrt(Gains[i]/(L_FRAME-(lag*i))); */ diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index 0446c3078c1273daab3af74fb6065fcfb9bef500..fb07df485a5f63e9f9df553bfc626e90bdcac6dd 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -102,12 +102,16 @@ static Word16 noise_est_ln_q8_fx( { Word16 e_ener, f_ener; Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif L_tmp = L_add_o( L_enr, L_shl( (Word32) 1L, q_new_plus_q_scale ), &Overflow ); /* +1.0f */ +#else + L_tmp = L_add_sat( L_enr, L_shl( (Word32) 1L, q_new_plus_q_scale ) ); /* +1.0f */ +#endif if ( flag_add1p0 == 0 ) { L_tmp = L_add( L_enr, 0 ); /* +0 , no offset */ @@ -664,8 +668,10 @@ void noise_est_down_fx( Word16 scale; Word32 totalNoise_temp; Word32 L_Etot, L_Etot_last, L_Etot_v_h2, L_Etot_v; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif L_Etot = L_shl( Etot, 16 ); /*Q24 for later AR1 computations*/ @@ -681,7 +687,11 @@ void noise_est_down_fx( totalNoise_temp = L_deposit_l( 0 ); FOR( i = min_band; i <= max_band; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + totalNoise_temp = L_add_sat( totalNoise_temp, bckr[i] ); /*Q_new+QSCALE*/ +#else totalNoise_temp = L_add_o( totalNoise_temp, bckr[i], &Overflow ); /*Q_new+QSCALE*/ +#endif } totalNoise_temp = L_max( totalNoise_temp, L_shl( e_min, 4 ) ); @@ -705,7 +715,11 @@ void noise_est_down_fx( FOR( i = 0; i < NB_BANDS; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_add_sat( L_shr_r( *pt1, 1 ), L_shr_r( *pt2, 1 ) ); +#else Ltmp = L_add_o( L_shr_r( *pt1, 1 ), L_shr_r( *pt2, 1 ), &Overflow ); +#endif /*Ltmp = L_shr_r(L_add(*pt1,*pt2),1);*/ enr[i] = Ltmp; move32(); /*Q_new+QSCALE*/ @@ -1003,9 +1017,11 @@ void noise_est_fx( } GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*-----------------------------------------------------------------* @@ -1101,8 +1117,13 @@ void noise_est_fx( Ltmp = L_deposit_h( corr_shift ); Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 ); +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_mac_sat( Ltmp, st_fx->voicing_fx[1], 10923 ); + wtmp = mac_r_sat( Ltmp, st_fx->voicing_fx[2], 10923 ); +#else Ltmp = L_mac_o( Ltmp, st_fx->voicing_fx[1], 10923, &Overflow ); wtmp = mac_ro( Ltmp, st_fx->voicing_fx[2], 10923, &Overflow ); +#endif tmp_pc = pc; move16(); @@ -1155,7 +1176,11 @@ void noise_est_fx( FOR( i = 10; i <= st_fx->max_band; i++ ) { Lnum = L_max( *pt1, *pt2 ); /* Don't need if anymore */ +#ifdef ISSUE_1867_replace_overflow_libenc + Lsum_den = L_add_sat( Lsum_den, Lnum ); +#else Lsum_den = L_add_o( Lsum_den, Lnum, &Overflow ); +#endif Ltmpden = L_min( *pt1, *pt2 ); if ( Ltmpden == 0 ) { @@ -1269,9 +1294,13 @@ void noise_est_fx( tmp = s_max( relE, 0 ); /* Q8 */ /* alpha = 0.064f * ftemp + 0.75f; */ - Ltmp = Mult_32_16( (Word32) 137438953L, tmp ); /* Q31(.064)+Q8+1-16 --> Q24 */ - Ltmp = L_mac( Ltmp, 256, 24576 ); /* Q8+Q15(.75)+1 --> Q24 */ - alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/ + Ltmp = Mult_32_16( (Word32) 137438953L, tmp ); /* Q31(.064)+Q8+1-16 --> Q24 */ + Ltmp = L_mac( Ltmp, 256, 24576 ); /* Q8+Q15(.75)+1 --> Q24 */ +#ifdef ISSUE_1867_replace_overflow_libenc + alpha = round_fx_sat( L_shl_sat( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/ +#else + alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/ +#endif /*if( alpha > 0.999f { alpha = 0.999f;} */ alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ @@ -1306,9 +1335,14 @@ void noise_est_fx( /* + 1.0f added to reduce sensitivity to non stationarity in low energies */ /* tmp_enr = enr[i] + 1.0f; */ tmp_Q = add( Q_new, Q_SCALE ); - Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ - L_tmp_enr = L_add_o( enr[i], Ltmp, &Overflow ); /* enr scale dynamic */ - L_tmp_ave_enr = L_add_o( hNoiseEst->ave_enr_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ + Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp_enr = L_add_sat( enr[i], Ltmp ); /* enr scale dynamic */ + L_tmp_ave_enr = L_add_sat( hNoiseEst->ave_enr_fx[i], Ltmp ); /* ave__enr scale dynamic */ +#else + L_tmp_enr = L_add_o( enr[i], Ltmp, &Overflow ); /* enr scale dynamic */ + L_tmp_ave_enr = L_add_o( hNoiseEst->ave_enr_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ +#endif IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */ { @@ -1347,10 +1381,14 @@ void noise_est_fx( } */ /* ave_enr2:: calculation of another non-stationarity measure (following attacks) */ - Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ - /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ + Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */ + /*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp_ave_enr2 = L_add_sat( hNoiseEst->ave_enr2_fx[i], Ltmp ); /* ave__enr scale dynamic */ +#else L_tmp_ave_enr2 = L_add_o( hNoiseEst->ave_enr2_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */ - IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */ +#endif + IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */ { Lnum = L_max( L_tmp_enr, L_tmp_ave_enr2 ); Lden = L_min( L_tmp_enr, L_tmp_ave_enr2 ); @@ -1381,7 +1419,11 @@ void noise_est_fx( /* log_enr = (float)ln_fx(enr[i]); */ log_enr16 = noise_est_ln_q8_fx( enr[i], 0, tmp_Q ); wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + *non_staX = add_sat( *non_staX, wtmp ); +#else *non_staX = add_o( *non_staX, wtmp, &Overflow ); +#endif move16(); /* Q8 */ hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16; move16(); @@ -1397,7 +1439,11 @@ void noise_est_fx( tmp_floor = LN_E_MIN_PLUS_ONE_FX; move16(); /* non dynamic init constant in Q8 */ tmp_floor = noise_est_ln_q8_fx( hNoiseEst->bckr_fx[i], 1, tmp_Q ); +#ifdef ISSUE_1867_replace_overflow_libenc + non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ +#else non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#endif } ELSE /*ini_frame < 100*/ { @@ -1406,7 +1452,11 @@ void noise_est_fx( tmp_floor = LN_E_MIN_PLUS_ONE_FX; move16(); /* non dynamic init constant in Q8 */ tmp_floor = noise_est_ln_q8_fx( E_MIN_FX, 1, tmp_Q ); +#ifdef ISSUE_1867_replace_overflow_libenc + non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ +#else non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#endif } } @@ -1516,9 +1566,14 @@ void noise_est_fx( /*epsP_0_2 = max(0 , min(8, epsP[0] / epsP[2])); */ Ltmp = eps_quota_fx( epsP_h[0], epsP_l[0], - epsP_h[2], epsP_l[2], 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ - epsP_0_2 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ + epsP_h[2], epsP_l[2], 12 ); /* Word32 Q12 */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ +#ifdef ISSUE_1867_replace_overflow_libenc + epsP_0_2 = round_fx_sat( L_shl_sat( Ltmp, 16 ) ); + /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ +#else + epsP_0_2 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */ +#endif BASOP_SATURATE_WARNING_ON_EVS epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */ @@ -1555,10 +1610,14 @@ void noise_est_fx( /* epsP_2_16 = max(0 , min(8, epsP[2] / epsP[16])); */ Ltmp = eps_quota_fx( epsP_h[2], epsP_l[2], - epsP_h[16], epsP_l[16], 12 ); /* Word32 Q12 */ - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ - epsP_2_16 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , - NB saturation in Q12 sets max value to 7,999 */ + epsP_h[16], epsP_l[16], 12 ); /* Word32 Q12 */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/ +#ifdef ISSUE_1867_replace_overflow_libenc + epsP_2_16 = round_fx_sat( L_shl_sat( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 ,*/ +#else + epsP_2_16 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 ,*/ +#endif + /*NB saturation in Q12 sets max value to 7,999 */ BASOP_SATURATE_WARNING_ON_EVS epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */ @@ -1680,7 +1739,11 @@ void noise_est_fx( *-----------------------------------------------------------------*/ Ltmp = L_mult( st_fx->voicing_fx[0], 16384 ); Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 ); +#ifdef ISSUE_1867_replace_overflow_libenc + cor_tmp = mac_r_sat( Ltmp, corr_shift, MAX_16 ); +#else cor_tmp = mac_ro( Ltmp, corr_shift, MAX_16, &Overflow ); +#endif LepsP = eps_quota_fx( epsP_h[2], epsP_l[2], epsP_h[16], epsP_l[16], 11 ); /* L_epsP in Q11 */ @@ -2283,9 +2346,11 @@ void noise_est_ivas_fx( Le_min_scaled = L_shl( E_MIN_FXQ31, sub( q_fr_bands, Q31 ) ); // q_fr_bands GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Check if LR-VAD */ @@ -2402,8 +2467,13 @@ void noise_est_ivas_fx( Ltmp = L_deposit_h( corr_shift ); Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 ); +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp = L_mac_sat( Ltmp, st_fx->voicing_fx[1], 10923 ); + wtmp = mac_r_sat( Ltmp, st_fx->voicing_fx[2], 10923 ); +#else Ltmp = L_mac_o( Ltmp, st_fx->voicing_fx[1], 10923, &Overflow ); wtmp = mac_ro( Ltmp, st_fx->voicing_fx[2], 10923, &Overflow ); +#endif tmp_pc = pc; move16(); @@ -2615,7 +2685,11 @@ void noise_est_ivas_fx( /* alpha = 0.064f * ftemp + 0.75f; */ Ltmp = Madd_32_16( 12582912 /* 0.75 in Q24*/, 137438953, tmp ); // Q24 - alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/ +#ifdef ISSUE_1867_replace_overflow_libenc + alpha = round_fx_sat( L_shl_sat( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/ +#else + alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/ +#endif /*if( alpha > 0.999f { alpha = 0.999f;} */ alpha = s_min( alpha, 32735 ); /*.999 in Q15*/ @@ -2768,7 +2842,11 @@ void noise_est_ivas_fx( IF( LT_16( ini_frame, 100 ) ) { +#ifdef ISSUE_1867_replace_overflow_libenc + non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, LN_E_MIN_PLUS_ONE_FX ) ) ); /* Q8 */ +#else non_staB = add_o( non_staB, abs_s( sub( tmp_enr, LN_E_MIN_PLUS_ONE_FX ) ), &Overflow ); /* Q8 */ +#endif } ELSE /*ini_frame < 100*/ { @@ -2790,7 +2868,11 @@ void noise_est_ivas_fx( Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15 tmp_floor = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */ } - non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#ifdef ISSUE_1867_replace_overflow_libenc + non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */ +#else + non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */ +#endif } } diff --git a/lib_enc/normalizecoefs_fx.c b/lib_enc/normalizecoefs_fx.c index ea394f54bd29ca2e04f9320d4a5196335a727b69..1dcf6b6e2fc71319aa587875835a7adfcf5ecf0f 100644 --- a/lib_enc/normalizecoefs_fx.c +++ b/lib_enc/normalizecoefs_fx.c @@ -29,9 +29,11 @@ void normalizecoefs_fx( Word16 *pcoefs16; Word32 *pcoefs; Word16 subvec_start, subvec_end, num_coefs; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif pcoefs = coefs; pcoefs16 = coefs_norm; @@ -55,7 +57,11 @@ void normalizecoefs_fx( *pcoefs = Mpy_32_16_1( *pcoefs, INV2POWHALF ); move32(); } +#ifdef ISSUE_1867_replace_overflow_libenc + *pcoefs16++ = round_fx_sat( L_shl_sat( *pcoefs++, 16 - k ) ); /* Q12 */ +#else *pcoefs16++ = round_fx_o( L_shl_o( *pcoefs++, 16 - k, &Overflow ), &Overflow ); /* Q12 */ +#endif move16(); } } diff --git a/lib_enc/pit_enc_fx.c b/lib_enc/pit_enc_fx.c index d67ec74eb7cda9c98103f78bf70a4dcc4704fdd3..33dc719e1c14415f1c874b76a94e94dab302a955 100644 --- a/lib_enc/pit_enc_fx.c +++ b/lib_enc/pit_enc_fx.c @@ -964,9 +964,11 @@ void norm_corr_ivas_fx( Word16 h_e, e_max; Word32 L_tmp; Word64 W_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif k = negate( t_min ); @@ -989,7 +991,11 @@ void norm_corr_ivas_fx( L_tmp = L_mac( 0, xn[0], excf[0] ); FOR( i = 1; i < L_subfr; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, xn[i], excf[i] ); // (Q_new - 1) + (Q_new - h_e) + 1 +#else L_tmp = L_mac_o( L_tmp, xn[i], excf[i], &Overflow ); // (Q_new - 1) + (Q_new - h_e) + 1 +#endif } exp = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp ); @@ -1060,9 +1066,11 @@ void norm_corr_fx( Word16 corr, exp_corr, norm, exp_norm, exp, scale; Word16 excf[L_FRAME16k]; Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif k = negate( t_min ); @@ -1074,10 +1082,18 @@ void norm_corr_fx( conv_fx( &exc[k], h, excf, L_subfr ); /* Compute rounded down 1/sqrt(energy of xn[]) */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( 1, xn[0], xn[0] ); +#else L_tmp = L_mac_o( 1, xn[0], xn[0], &Overflow ); +#endif FOR( i = 1; i < L_subfr; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, xn[i], xn[i] ); +#else L_tmp = L_mac_o( L_tmp, xn[i], xn[i], &Overflow ); +#endif } exp = norm_l( L_tmp ); exp = sub( 30, exp ); @@ -1096,7 +1112,11 @@ void norm_corr_fx( L_tmp = L_mac( 1, xn[0], excf[0] ); FOR( i = 1; i < L_subfr; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, xn[i], excf[i] ); +#else L_tmp = L_mac_o( L_tmp, xn[i], excf[i], &Overflow ); +#endif } exp = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp ); @@ -1107,7 +1127,11 @@ void norm_corr_fx( L_tmp = L_mac( 1, excf[0], excf[0] ); FOR( i = 1; i < L_subfr; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, excf[i], excf[i] ); +#else L_tmp = L_mac_o( L_tmp, excf[i], excf[i], &Overflow ); +#endif } exp = norm_l( L_tmp ); diff --git a/lib_enc/pitch_ol2_fx.c b/lib_enc/pitch_ol2_fx.c index c0c17ec6333267c793f6fb0fe8cd044cd652454e..88393a51453a54948fbe1d0562fd7ccd7549a76f 100644 --- a/lib_enc/pitch_ol2_fx.c +++ b/lib_enc/pitch_ol2_fx.c @@ -50,9 +50,11 @@ void pitch_ol2_fx( Word32 R1, R2; Word16 R0, exp_R0, exp_R1, exp_R2, j; Word16 pit_max; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* initialization */ @@ -82,8 +84,13 @@ void pitch_ol2_fx( pt_cor_fx = cor_fx; FOR( t = t_min; t <= t_max; t++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + t0 = L_shl_sat( *pt_cor_32++, exp3 ); + *pt_cor_fx++ = round_fx_sat( t0 ); +#else t0 = L_shl_o( *pt_cor_32++, exp3, &Overflow ); *pt_cor_fx++ = round_fx_o( t0, &Overflow ); +#endif move16(); } @@ -189,7 +196,11 @@ void pitch_ol2_fx( exp_R2 = norm_l( R2 ); R2 = L_shl( R2, exp_R2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + R1 = L_mult_sat( round_fx_sat( R1 ), round_fx_sat( R2 ) ); +#else R1 = L_mult_o( round_fx_o( R1, &Overflow ), round_fx_o( R2, &Overflow ), &Overflow ); +#endif i = norm_l( R1 ); R1 = L_shl( R1, i ); @@ -199,11 +210,19 @@ void pitch_ol2_fx( R1 = Isqrt_lc( R1, &exp_R1 ); +#ifdef ISSUE_1867_replace_overflow_libenc + R1 = L_mult( R0, round_fx_sat( R1 ) ); +#else R1 = L_mult( R0, round_fx_o( R1, &Overflow ) ); +#endif exp_R0 = sub( 31, exp_R0 ); exp_R0 = sub( add( exp_R0, exp_R1 ), exp3 ); +#ifdef ISSUE_1867_replace_overflow_libenc + *voicing_fr_fx = round_fx_sat( L_shl_sat( R1, exp_R0 ) ); /*Q15*/ +#else *voicing_fr_fx = round_fx_o( L_shl_o( R1, exp_R0, &Overflow ), &Overflow ); /*Q15*/ +#endif move16(); } ELSE @@ -243,9 +262,11 @@ void StableHighPitchDetect_fx( Word16 tmp, tmp1, exp, diff16, cor_max16, exp1, exp2, pit_min_up; Word32 L_tmp, L_tmp1; Word16 Top; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/ @@ -295,21 +316,35 @@ void StableHighPitchDetect_fx( tmp = div_s( 16384, tmp ); /*Q(15+exp)*/ BASOP_SATURATE_WARNING_OFF_EVS diff = L_negate( L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + BASOP_SATURATE_WARNING_ON_EVS + diff16 = round_fx_sat( diff ); +#else BASOP_SATURATE_WARNING_ON_EVS diff16 = round_fx_o( diff, &Overflow ); +#endif } ELSE { tmp = div_s( 16384, tmp ); /*Q(15+exp)*/ BASOP_SATURATE_WARNING_OFF_EVS diff = L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + BASOP_SATURATE_WARNING_ON_EVS + diff16 = round_fx_sat( diff ); +#else BASOP_SATURATE_WARNING_ON_EVS diff16 = round_fx_o( diff, &Overflow ); +#endif } } ELSE { +#ifdef ISSUE_1867_replace_overflow_libenc + diff16 = round_fx_sat( L_shl_sat( diff, 25 ) ); +#else diff16 = round_fx_o( L_shl_o( diff, 25, &Overflow ), &Overflow ); +#endif } test(); test(); @@ -386,7 +421,11 @@ void StableHighPitchDetect_fx( L_tmp1 = Isqrt_lc( L_tmp1, &exp ); /*Q(31-exp)*/ cor_max = Mult_32_32( cor_max, L_tmp1 ); exp = 31 - ( shl( Q_new, 1 ) + 1 ) - ( 31 - exp ) + 31; +#ifdef ISSUE_1867_replace_overflow_libenc + cor_max16 = round_fx_sat( L_shl_sat( cor_max, exp ) ); /*Q15*/ +#else cor_max16 = round_fx_o( L_shl_o( cor_max, exp, &Overflow ), &Overflow ); /*Q15*/ +#endif /**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/ *voicing0_sm = round_fx( L_mac( L_mult( 24576 /*.75f Q15*/, *voicing0_sm ), 8192 /*.25f Q15*/, cor_max16 ) ); move16(); @@ -451,9 +490,11 @@ void StableHighPitchDetect_ivas_fx( Word16 tmp, tmp1, exp, diff16, cor_max16, exp1, exp2, pit_min_up; Word32 L_tmp, L_tmp1; Word16 Top; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/ @@ -510,21 +551,35 @@ void StableHighPitchDetect_ivas_fx( tmp = div_s( 16384, tmp ); /*Q(15+exp)*/ BASOP_SATURATE_WARNING_OFF_EVS diff = L_negate( L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + BASOP_SATURATE_WARNING_ON_EVS + diff16 = round_fx_sat( diff ); +#else BASOP_SATURATE_WARNING_ON_EVS diff16 = round_fx_o( diff, &Overflow ); +#endif } ELSE { tmp = div_s( 16384, tmp ); /*Q(15+exp)*/ BASOP_SATURATE_WARNING_OFF_EVS diff = L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + BASOP_SATURATE_WARNING_ON_EVS + diff16 = round_fx_sat( diff ); +#else BASOP_SATURATE_WARNING_ON_EVS diff16 = round_fx_o( diff, &Overflow ); +#endif } } ELSE { +#ifdef ISSUE_1867_replace_overflow_libenc + diff16 = round_fx_sat( L_shl_sat( diff, 25 ) ); +#else diff16 = round_fx_o( L_shl_o( diff, 25, &Overflow ), &Overflow ); +#endif } test(); test(); @@ -610,7 +665,11 @@ void StableHighPitchDetect_ivas_fx( L_tmp1 = Isqrt_lc( L_tmp1, &exp ); /*Q(31-exp)*/ cor_max = Mult_32_32( cor_max, L_tmp1 ); exp = add( sub( sub( 31, add( shl( Q_new, 1 ), 1 ) ), sub( 31, exp ) ), 31 ); +#ifdef ISSUE_1867_replace_overflow_libenc + cor_max16 = round_fx_sat( L_shl_sat( cor_max, exp ) ); /*Q15*/ +#else cor_max16 = round_fx_o( L_shl_o( cor_max, exp, &Overflow ), &Overflow ); /*Q15*/ +#endif /**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/ *voicing0_sm = round_fx( L_mac( L_mult( 24576 /*.75f Q15*/, *voicing0_sm ), 8192 /*.25f Q15*/, cor_max16 ) ); move16(); diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index 56647f7b12030b02e8d4c2733102b9d9d4e95792..5f8147e22db198d27e276dc4bd436f909f917f13 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -183,8 +183,10 @@ void pitch_ol_fx( const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; Word16 pit_min_coding; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /*--------------------------------------------------------------* @@ -737,7 +739,11 @@ void pitch_ol_fx( enr1_exp = 0; move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + enr1 = add_sat( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1 ); +#else enr1 = add_o( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1, &Overflow ); +#endif enr2 = L_mult( enr0[j], enr1 ); enr2_exp = norm_l( enr2 ); @@ -773,7 +779,11 @@ void pitch_ol_fx( move16(); /* selected moving vector */ enr1_exp = 0; move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + enr1 = add_sat( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1 ); +#else enr1 = add_o( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1, &Overflow ); +#endif enr2 = L_mult( enr0_1[j], enr1 ); enr2_exp = norm_l( enr2 ); @@ -868,7 +878,11 @@ void pitch_ol_fx( move16(); pitch_tmp[i] = pitchX[i][ind]; move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); +#else cor_tmp[i] = add_o( corX[i][ind], corr_shift, &Overflow ); +#endif move16(); /* Higher is the neighbour's correlation, higher is the weighting */ @@ -882,7 +896,11 @@ void pitch_ol_fx( move16(); pitch_tmp[i + NHFR] = pitchX[i][ind1]; move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); +#else cor_tmp[i + NHFR] = add_o( corX[i][ind1], corr_shift, &Overflow ); +#endif move16(); /* Higher is the neighbour's correlation, higher is the weighting */ @@ -1103,8 +1121,10 @@ void pitch_ol_ivas_fx( const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1; Word16 pit_min_coding; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif Word16 new_q; new_q = sub( 63, shl( qwsp, 1 ) ); @@ -1707,7 +1727,12 @@ void pitch_ol_ivas_fx( enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/ Ltmp = Mpy_32_16_1( enr1, cor_buf[ind] ); - corX[i][j] = extract_h( L_shl_o( Ltmp, add( enr1_exp, cor_buf_exp[ind] ), &Overflow ) ); // Q15 +#ifdef ISSUE_1867_replace_overflow_libenc + corX[i][j] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind] ) ) ); // Q15 +#else + + corX[i][j] = extract_h( L_shl_o( Ltmp, add( enr1_exp, cor_buf_exp[ind] ), &Overflow ) ); // Q15 +#endif move16(); Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind] ); @@ -1750,7 +1775,11 @@ void pitch_ol_ivas_fx( enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr1_exp*/ Ltmp = Mpy_32_16_1( enr1, cor_buf[ind1 + len_x] ); +#ifdef ISSUE_1867_replace_overflow_libenc + corX[i][j + NSECT] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind1 + len_x] ) ) ); // Q15 +#else corX[i][j + NSECT] = extract_h( L_shl_o( Ltmp, add( enr1_exp, cor_buf_exp[ind1 + len_x] ), &Overflow ) ); // Q15 +#endif move16(); Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x] ); @@ -1827,7 +1856,11 @@ void pitch_ol_ivas_fx( move16(); pitch_tmp[i] = pitchX[i][ind]; move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + cor_tmp[i] = add_sat( corX[i][ind], corr_shift ); +#else cor_tmp[i] = add_o( corX[i][ind], corr_shift, &Overflow ); +#endif move16(); /* Higher is the neighbour's correlation, higher is the weighting */ @@ -1841,7 +1874,11 @@ void pitch_ol_ivas_fx( move16(); pitch_tmp[i + NHFR] = pitchX[i][ind1]; move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift ); +#else cor_tmp[i + NHFR] = add_o( corX[i][ind1], corr_shift, &Overflow ); +#endif move16(); /* Higher is the neighbour's correlation, higher is the weighting */ diff --git a/lib_enc/ppp_enc_fx.c b/lib_enc/ppp_enc_fx.c index d6dc8b6d68adcec9c2466e1069b658ce85791c7e..515182aa8857560637015806c4e65091b90843a8 100644 --- a/lib_enc/ppp_enc_fx.c +++ b/lib_enc/ppp_enc_fx.c @@ -622,9 +622,11 @@ static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X Word16 n, fshift_fx, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI]; Word32 corr_fx; Word32 maxcorr_fx, wcorr_fx, diff_corr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif IF( LT_16( X1_fx.lag_fx, X2_fx.lag_fx ) ) { @@ -663,9 +665,15 @@ static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X FOR( k = 0; k <= HalfLag; k++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + corr_fx = L_mac_sat( corr_fx, ab1[k], C_fx[temp % ( 4 * X2_fx.lag_fx )] ); + corr_fx = L_mac_sat( corr_fx, ab2[k], S_fx[temp % ( 4 * X2_fx.lag_fx )] ); + temp = add_sat( temp, temp1 ); +#else corr_fx = L_mac_o( corr_fx, ab1[k], C_fx[temp % ( 4 * X2_fx.lag_fx )], &Overflow ); corr_fx = L_mac_o( corr_fx, ab2[k], S_fx[temp % ( 4 * X2_fx.lag_fx )], &Overflow ); temp = add_o( temp, temp1, &Overflow ); +#endif } temp = sub( 32767, extract_l( L_shr( L_mult( 82, abs_s( n ) ), 1 ) ) ); /* Q15 */ Qcorr = norm_l( corr_fx ); @@ -675,23 +683,40 @@ static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X move16(); } - temp1 = round_fx_o( (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ), &Overflow ); /* Q(Qcorr-16) */ - wcorr_fx = L_mult_o( temp1, temp, &Overflow ); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ +#ifdef ISSUE_1867_replace_overflow_libenc + temp1 = round_fx_sat( (Word32) L_shl_sat( corr_fx, Qcorr ) ); /* Q(Qcorr-16) */ + wcorr_fx = L_mult_sat( temp1, temp ); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ +#else + temp1 = round_fx_o( (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ), &Overflow ); /* Q(Qcorr-16) */ + wcorr_fx = L_mult_o( temp1, temp, &Overflow ); /* Q(Qcorr-16+15+1)=Q(Qcorr) */ +#endif IF( GE_16( Qmaxcorr, Qcorr ) ) { +#ifdef ISSUE_1867_replace_overflow_libenc + diff_corr = L_sub_sat( wcorr_fx, L_shl_sat( maxcorr_fx, sub( Qcorr, Qmaxcorr ) ) ); /* Qcorr */ +#else diff_corr = L_sub_o( wcorr_fx, L_shl_o( maxcorr_fx, sub( Qcorr, Qmaxcorr ), &Overflow ), &Overflow ); /* Qcorr */ +#endif } ELSE { +#ifdef ISSUE_1867_replace_overflow_libenc + diff_corr = L_sub_sat( L_shl_sat( wcorr_fx, sub( Qmaxcorr, Qcorr ) ), maxcorr_fx ); /* Qmaxcorr */ +#else diff_corr = L_sub_o( L_shl_o( wcorr_fx, sub( Qmaxcorr, Qcorr ), &Overflow ), maxcorr_fx, &Overflow ); /* Qmaxcorr */ +#endif } if ( diff_corr > 0 ) { fshift_fx = n; move16(); - maxcorr_fx = (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ); /* Qcorr */ +#ifdef ISSUE_1867_replace_overflow_libenc + maxcorr_fx = (Word32) L_shl_sat( corr_fx, Qcorr ); /* Qcorr */ +#else + maxcorr_fx = (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ); /* Qcorr */ +#endif Qmaxcorr = Qcorr; move16(); } @@ -739,9 +764,11 @@ static void LPCPowSpect_fx( Word32 Ltemp, Lw; Word32 Lacc; Word16 tmp, exp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif FOR( k = 0; k < Nf; k++ ) { @@ -773,11 +800,17 @@ static void LPCPowSpect_fx( t1 = add( t1, (Word16) L_shr( Ltemp, 16 ) ); /* t1 is interpolated cos(w) */ Ltemp = L_shr( L_mult( LPC[i], t1 ), 1 ); /* Ltemp in Q27 */ - Re = L_add_o( Re, Ltemp, &Overflow ); /* Re=1-sum(LPC[i]*cos(Lw)); */ - Ltemp = L_add_o( Lw, 0x6000, &Overflow ); /* add 0.75, which is 3pi/2 to convert sin to cos */ - Ltemp = L_shl_o( Ltemp, 10, &Overflow ); /* Q25 */ - w = extract_h( Ltemp ); /* w is equivalent cos index */ - dl = extract_l( Ltemp ); /* dl is 6 bit left-over for interpolation */ +#ifdef ISSUE_1867_replace_overflow_libenc + Re = L_add_sat( Re, Ltemp ); /* Re=1-sum(LPC[i]*cos(Lw)); */ + Ltemp = L_add_sat( Lw, 0x6000 ); /* add 0.75, which is 3pi/2 to convert sin to cos */ + Ltemp = L_shl_sat( Ltemp, 10 ); /* Q25 */ +#else + Re = L_add_o( Re, Ltemp, &Overflow ); /* Re=1-sum(LPC[i]*cos(Lw)); */ + Ltemp = L_add_o( Lw, 0x6000, &Overflow ); /* add 0.75, which is 3pi/2 to convert sin to cos */ + Ltemp = L_shl_o( Ltemp, 10, &Overflow ); /* Q25 */ +#endif + w = extract_h( Ltemp ); /* w is equivalent cos index */ + dl = extract_l( Ltemp ); /* dl is 6 bit left-over for interpolation */ w = s_and( w, 511 ); t1 = cos_table[w]; /*t2=cos_table[s_and(add(w,1),511)]; */ @@ -797,8 +830,13 @@ static void LPCPowSpect_fx( t1 = add( t1, (Word16) L_shr( Ltemp, 16 ) ); /* t1 is interpolated cos(w) */ Ltemp = L_shr( L_mult( LPC[i], t1 ), 1 ); /* Ltemp in Q27 */ - Im = L_sub_o( Im, Ltemp, &Overflow ); /* Im=sum(LPC[i]*sin(Lw)) */ - Lw = L_add_o( Lw, freq[k], &Overflow ); /* Lw=(i+1)*freq[k] */ +#ifdef ISSUE_1867_replace_overflow_libenc + Im = L_sub_sat( Im, Ltemp ); /* Im=sum(LPC[i]*sin(Lw)) */ + Lw = L_add_sat( Lw, freq[k] ); /* Lw=(i+1)*freq[k] */ +#else + Im = L_sub_o( Im, Ltemp, &Overflow ); /* Im=sum(LPC[i]*sin(Lw)) */ + Lw = L_add_o( Lw, freq[k], &Overflow ); /* Lw=(i+1)*freq[k] */ +#endif } /* If necessary, we can block-normalize Re and Im to improve precision */ dh = extract_h( Re ); @@ -813,7 +851,11 @@ static void LPCPowSpect_fx( ELSE Lacc = L_mult0( dh, dl ); - Lacc = L_add_o( L_shr( Lacc, 15 ), L_shr( L_mult_o( dh, dh, &Overflow ), 1 ), &Overflow ); /* Lacc=Re*Re */ +#ifdef ISSUE_1867_replace_overflow_libenc + Lacc = L_add_sat( L_shr( Lacc, 15 ), L_shr( L_mult_sat( dh, dh ), 1 ) ); /* Lacc=Re*Re */ +#else + Lacc = L_add_o( L_shr( Lacc, 15 ), L_shr( L_mult_o( dh, dh, &Overflow ), 1 ), &Overflow ); /* Lacc=Re*Re */ +#endif dh = extract_h( Im ); dl = extract_l( Im ); @@ -844,7 +886,11 @@ static void LPCPowSpect_fx( move16(); } Ltemp = L_deposit_h( tmp ); +#ifdef ISSUE_1867_replace_overflow_libenc + out[k] = round_fx_sat( L_shl_sat( Ltemp, negate( add( exp, 8 ) ) ) ); +#else out[k] = round_fx_o( L_shl_o( Ltemp, negate( add( exp, 8 ) ), &Overflow ), &Overflow ); +#endif move16(); /* out[k] = shl(tmp,-exp-8); in Q7 */ diff --git a/lib_enc/pvq_encode_fx.c b/lib_enc/pvq_encode_fx.c index e989067048836a0c59074edb501cffd7a49cd677..fe53cacc3c6d4cd50b76c0ee7241400bcd5ce36b 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -60,9 +60,11 @@ static Word16 one_pulse_search( UWord32 UL_left_l, UL_right_l, UL_dummy; Word32 L_tmp; UWord16 u_sgn; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif en_tmp = en_dn_shift; /* dummy assignment to avoid compiler warning for unused parameter */ @@ -85,9 +87,14 @@ static Word16 one_pulse_search( FOR( i = 0; i < dim; i++ ) /* FOR 3 ops */ { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp_corr = L_shl_sat( L_mac_sat( *L_xy_ptr, 1, x_abs[i] ), corr_up_shift ); /* actual in-loop target value, 2 ops */ + corr_tmp = round_fx_sat( L_tmp_corr ); /* 1 op */ +#else L_tmp_corr = L_shl_o( L_mac_o( *L_xy_ptr, 1, x_abs[i], &Overflow ), corr_up_shift, &Overflow ); /* actual in-loop target value, 2 ops */ corr_tmp = round_fx_o( L_tmp_corr, &Overflow ); /* 1 op */ - corr_sq_tmp = mult( corr_tmp, corr_tmp ); /* CorrSq, is a 16bit for low compelxity cross multiplication 1 op */ +#endif + corr_sq_tmp = mult( corr_tmp, corr_tmp ); /* CorrSq, is a 16bit for low compelxity cross multiplication 1 op */ L_tmp_en_lc = L_mac( *L_yy_ptr, 1, y[i] ); /*Q1 result , energy may span up to ~14+1(Q1)+1(sign)=16 bits, 1 op */ /* extract_l without shift can always be used for this section as energy is guaranteed to stay in the lower word, 1 op */ @@ -202,9 +209,11 @@ void pvq_encode_ivas_fx( Word16 neg_gain_norm, shift_tot; Word16 high_pulse_density_flag; PvqEntry entry; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif L_proj_fac = 4096; @@ -359,8 +368,13 @@ void pvq_encode_ivas_fx( } Mpy_32_16_ss( L_isqrt, tmp, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) +1 */ Mpy_32_16_ss( L_tmp, neg_gain_norm, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) *Q15 +1 */ - L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */ - xq[i] = round_fx_o( L_tmp, &Overflow ); /* Q15, array move */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */ + xq[i] = round_fx_sat( L_tmp ); /* Q15, array move */ +#else + L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */ + xq[i] = round_fx_o( L_tmp, &Overflow ); /* Q15, array move */ +#endif move16(); L_xq[i] = L_tmp; /* Q31 currently unused */ move32(); @@ -410,9 +424,11 @@ void pvq_encode_fx( Word16 neg_gain_norm, shift_tot; Word16 high_pulse_density_flag; PvqEntry entry; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif L_proj_fac = 4096; @@ -567,8 +583,13 @@ void pvq_encode_fx( } Mpy_32_16_ss( L_isqrt, tmp, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) +1 */ Mpy_32_16_ss( L_tmp, neg_gain_norm, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) *Q15 +1 */ - L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */ - xq[i] = round_fx_o( L_tmp, &Overflow ); /* Q15, array move */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */ + xq[i] = round_fx_sat( L_tmp ); /* Q15, array move */ +#else + L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */ + xq[i] = round_fx_o( L_tmp, &Overflow ); /* Q15, array move */ +#endif move16(); L_xq[i] = L_tmp; /* Q31 currently unused */ move32(); diff --git a/lib_enc/q_gain2p_fx.c b/lib_enc/q_gain2p_fx.c index 4618483d26b649a5e066f1dc307655f4bec5c505..ed1eea4c1de337423669b93615f5c15845ec52c8 100644 --- a/lib_enc/q_gain2p_fx.c +++ b/lib_enc/q_gain2p_fx.c @@ -145,10 +145,12 @@ static Word16 gain_enc( /* o : quantization pitch index const Word16 *p; const Word16 *t_qua_gain; Word32 L_tmp, dist_min, L_tmp1; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); #endif +#endif assert( ( func_type != FUNC_GAIN_ENC_UV ) && ( func_type != FUNC_GAIN_ENC_GACELP_UV ) ); @@ -165,7 +167,11 @@ static Word16 gain_enc( /* o : quantization pitch index /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 ); move16(); +#ifdef ISSUE_1867_replace_overflow_libenc + *gain_inov = round_fx_sat( L_shl_sat( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */ +#else *gain_inov = round_fx_o( L_shl_o( L_tmp, 15 - 3, &Overflow ), &Overflow ); /* gain_inov in Q12 */ +#endif move16(); /*----------------------------------------------------------------* * calculate the predicted gain code @@ -377,7 +383,11 @@ static Word16 gain_enc( /* o : quantization pitch index /* Here, we use L_mult0 to compensate the factor 0.5 applied to coeff[1..4] before */ L_tmp = L_add( L_tmp, L_shr( L_mult0( p[2 * i + 0], p[2 * i + 0] ), shr_coeff0 ) ); L_tmp = L_sub( L_tmp, L_shr( L_mult( p[2 * i + 0], coeff1 ), shr_coeff1 ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = L_sub_sat( L_tmp, dist_min ); +#else L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS if ( L_tmp1 < 0 ) { @@ -397,13 +407,21 @@ static Word16 gain_enc( /* o : quantization pitch index L_tmp = L_mult( g_code, gcode0 ); /* Q11*Q15 -> Q27 */ exp_gcode0 = add( exp_gcode0, -11 ); +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, exp_gcode0 ); /* Q27 -> Q16 */ +#else L_tmp = L_shl_o( L_tmp, exp_gcode0, &Overflow ); /* Q27 -> Q16 */ +#endif *gain_code = L_tmp; move32(); /* Q16/Q12 => Q5 */ L_tmp = L_deposit_h( BASOP_Util_Divide3216_Scale( L_tmp, *gain_inov, &i ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + *past_gcode = L_shl_sat( L_tmp, sub( i, 15 - 12 ) ); +#else *past_gcode = L_shl_o( L_tmp, sub( i, 15 - 12 ), &Overflow ); +#endif move16(); return index; @@ -436,9 +454,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch ind Word16 index2; const Word16 log2_scale = 16; move16(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif pred_nrg_frame = 0; /* to suppress compilation warnings */ g_code2 = 0; /* to suppress compilation warnings */ @@ -595,7 +615,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch ind } s1 = norm_l( *gain_code ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = round_fx_sat( L_shl( *gain_code, s1 ) ); +#else tmp1 = round_fx_o( L_shl_o( *gain_code, s1, &Overflow ), &Overflow ); +#endif s1 = sub( 15, s1 ); tmp1 = mult_r( mult_r( tmp1, tmp1 ), g_coeff->y2y2 ); @@ -608,7 +632,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch ind L_tmp1 = L_add( L_tmp, 0 ); s1 = norm_l( *gain_code ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = round_fx_sat( L_shl( *gain_code, s1 ) ); +#else tmp1 = round_fx_o( L_shl_o( *gain_code, s1, &Overflow ), &Overflow ); +#endif s1 = sub( 15, s1 ); c_index2 = 0x7FFF; diff --git a/lib_enc/qlpc_stoch_fx.c b/lib_enc/qlpc_stoch_fx.c index d6f0b504f8f2c5ebc0aea689ff87b5eaac0a7ad0..444f188f6efd7d80fcf58551234282c785f164df 100644 --- a/lib_enc/qlpc_stoch_fx.c +++ b/lib_enc/qlpc_stoch_fx.c @@ -399,9 +399,11 @@ void Unified_weighting_fx( Word16 nf_fx; Word32 Bin_Ener_160_fx[160]; const Word32 *Freq_w_Table_fx, *Bin_Ener_fx; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*Config. weighting*/ @@ -441,7 +443,11 @@ void Unified_weighting_fx( L_tmp = L_deposit_l( 0 ); FOR( i = 95; i < 127; i++ ) { - L_tmp = L_add_o( L_tmp, Bin_Ener_160_fx[i], &Overflow ); /* Q_ener */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_add_sat( L_tmp, Bin_Ener_160_fx[i] ); /* Q_ener */ +#else + L_tmp = L_add_o( L_tmp, Bin_Ener_160_fx[i], &Overflow ); /* Q_ener */ +#endif } L_tmp = L_shr( L_tmp, 5 ); @@ -522,7 +528,11 @@ void Unified_weighting_fx( } ELSE { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_deposit_l( sub_sat( w_fft_fx[i], min_fx ) ), 13 ); /* Q21 */ +#else L_tmp = L_shl_o( L_deposit_l( sub_o( w_fft_fx[i], min_fx, &Overflow ) ), 13, &Overflow ); /* Q21 */ +#endif exp = norm_l( L_tmp ); frac = round_fx( L_shl( L_tmp, exp ) ); exp = sub( add( exp, 21 ), 30 ); diff --git a/lib_enc/scale_enc_fx.c b/lib_enc/scale_enc_fx.c index 2f3cd18338af7c7145123d6507512b60cba3f80d..ab0492e6ef6e663bec07a1fa98ae83cf60968844 100644 --- a/lib_enc/scale_enc_fx.c +++ b/lib_enc/scale_enc_fx.c @@ -86,9 +86,11 @@ void Preemph_scaled( Word16 mu, shift, QVal; Word32 L_tmp, L_maxloc; Word16 Q_min; +#if !defined( ISSUE_1867_replace_overflow_libenc ) #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*---------------------------------------------------------------* @@ -97,8 +99,13 @@ void Preemph_scaled( *---------------------------------------------------------------*/ BASOP_SATURATE_WARNING_OFF_EVS + +#ifdef ISSUE_1867_replace_overflow_libenc + QVal = shl_sat( 1, sub( 15, bits ) ); //?sat +#else Overflow = 0; QVal = shl_sat( 1, sub( 15, bits ) ); +#endif BASOP_SATURATE_WARNING_ON_EVS mu = shr( Preemph_factor, bits ); /* Q15 --> Q(15-bits) */ @@ -115,7 +122,11 @@ void Preemph_scaled( /* Equivalent to tmp = max((abs(x[i] - mu*x[i-1]),tmp) * finds the max of preemphasized signal */ L_tmp = L_mult( new_speech[i], QVal ); +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_msu_sat( L_tmp, new_speech[i - 1], mu ); +#else L_tmp = L_msu_o( L_tmp, new_speech[i - 1], mu, &Overflow ); +#endif L_tmp = L_abs( L_tmp ); L_maxloc = L_max( L_tmp, L_maxloc ); } @@ -165,7 +176,11 @@ void Preemph_scaled( FOR( i = sub( Lframe, 1 ); i > 0; i-- ) { L_tmp = L_mult( new_speech[i], QVal ); +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_msu_sat( L_tmp, new_speech[i - 1], mu ); +#else L_tmp = L_msu_o( L_tmp, new_speech[i - 1], mu, &Overflow ); +#endif L_tmp = L_shl( L_tmp, *Q_new ); new_speech[i] = round_fx_sat( L_tmp ); // Q_new } @@ -198,8 +213,10 @@ Word32 Scale_mem_pre_proc( /* o : Min energy scaled { Word16 i; Word32 e_min_scaled; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE ) ) ), 1 ), 1 ); @@ -229,12 +246,21 @@ Word32 Scale_mem_pre_proc( /* o : Min energy scaled /* Do scaling and valide minimum energy value */ FOR( i = 0; i < NB_BANDS; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + enrO[i] = L_max( L_shl_sat( enrO[i], Q_exp ), e_min_scaled ); + bckr[i] = L_max( L_shl_sat( bckr[i], Q_exp ), e_min_scaled ); + ave_enr[i] = L_max( L_shl_sat( ave_enr[i], Q_exp ), e_min_scaled ); + ave_enr2[i] = L_max( L_shl_sat( ave_enr2[i], Q_exp ), e_min_scaled ); + st_fr_bands1[i] = L_max( L_shl_sat( st_fr_bands1[i], Q_exp ), e_min_scaled ); + st_fr_bands2[i] = L_max( L_shl_sat( st_fr_bands2[i], Q_exp ), e_min_scaled ); +#else enrO[i] = L_max( L_shl_o( enrO[i], Q_exp, &Overflow ), e_min_scaled ); bckr[i] = L_max( L_shl_o( bckr[i], Q_exp, &Overflow ), e_min_scaled ); ave_enr[i] = L_max( L_shl_o( ave_enr[i], Q_exp, &Overflow ), e_min_scaled ); ave_enr2[i] = L_max( L_shl_o( ave_enr2[i], Q_exp, &Overflow ), e_min_scaled ); st_fr_bands1[i] = L_max( L_shl_o( st_fr_bands1[i], Q_exp, &Overflow ), e_min_scaled ); st_fr_bands2[i] = L_max( L_shl_o( st_fr_bands2[i], Q_exp, &Overflow ), e_min_scaled ); +#endif move32(); move32(); move32(); diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index 46693bfe0381e8af458a385fab86077fa2644418..68aadc1da7f591e8e90bf506054b0f2a9ac7ce29 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -65,9 +65,11 @@ void set_impulse_fx( Word16 krit_fx, krit_max_fx, gain16; Word32 Lrr, Ldd, Ltmp, Ltmp1; const Word16 *pt_Glt; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif krit_max_fx = -32768; move16(); @@ -119,12 +121,21 @@ void set_impulse_fx( /* nominator & DEnominator row <0> */ FOR( i = 0; i < L_SUBFR; i++ ) { - Lrr = L_mac_o( Lrr, gh_fx[i], gh_fx[i], &Overflow ); // Q27 - Ldd = L_mac_o( Ldd, gh_fx[i], xn_fx[i], &Overflow ); // Q27 +#ifdef ISSUE_1867_replace_overflow_libenc + Lrr = L_mac_sat( Lrr, gh_fx[i], gh_fx[i] ); // Q27 + Ldd = L_mac_sat( Ldd, gh_fx[i], xn_fx[i] ); // Q27 +#else + Lrr = L_mac_o( Lrr, gh_fx[i], gh_fx[i], &Overflow ); // Q27 + Ldd = L_mac_o( Ldd, gh_fx[i], xn_fx[i], &Overflow ); // Q27 +#endif } rr_fx[start1] = Lrr; move32(); - dd_fx[start1] = round_fx_o( Ldd, &Overflow ); // Q11 +#ifdef ISSUE_1867_replace_overflow_libenc + dd_fx[start1] = round_fx_sat( Ldd ); // Q11 +#else + dd_fx[start1] = round_fx_o( Ldd, &Overflow ); // Q11 +#endif rr_fx[start1] = L_max( rr_fx[start1], 1 ); FOR( i = add( start1, 1 ); i < L_IMPULSE2; i++ ) @@ -138,15 +149,25 @@ void set_impulse_fx( gh_fx[j] = mac_r( L_deposit_h( gh_fx[j - 1] ), Glottal_cdbk_fx[m * L_IMPULSE + L_IMPULSE2 - i], h_orig_fx[j] ); // Q13 move16(); - Lrr = L_mac_o( Lrr, gh_fx[j], gh_fx[j], &Overflow ); // Q27 - Ldd = L_mac_o( Ldd, gh_fx[j], xn_fx[j], &Overflow ); // Q27 +#ifdef ISSUE_1867_replace_overflow_libenc + Lrr = L_mac_sat( Lrr, gh_fx[j], gh_fx[j] ); // Q27 + Ldd = L_mac_sat( Ldd, gh_fx[j], xn_fx[j] ); // Q27 +#else + Lrr = L_mac_o( Lrr, gh_fx[j], gh_fx[j], &Overflow ); // Q27 + Ldd = L_mac_o( Ldd, gh_fx[j], xn_fx[j], &Overflow ); // Q27 +#endif } gh_fx[0] = mult_r( Glottal_cdbk_fx[m * L_IMPULSE + L_IMPULSE2 - i], h_orig_fx[0] ); // Q13 move16(); - Lrr = L_mac_o( Lrr, gh_fx[0], gh_fx[0], &Overflow ); // Q27 - Ldd = L_mac_o( Ldd, gh_fx[0], xn_fx[0], &Overflow ); // Q27 - dd_fx[i] = round_fx_sat( Ldd ); // Q11 +#ifdef ISSUE_1867_replace_overflow_libenc + Lrr = L_mac_sat( Lrr, gh_fx[0], gh_fx[0] ); // Q27 + Ldd = L_mac_sat( Ldd, gh_fx[0], xn_fx[0] ); // Q27 +#else + Lrr = L_mac_o( Lrr, gh_fx[0], gh_fx[0], &Overflow ); // Q27 + Ldd = L_mac_o( Ldd, gh_fx[0], xn_fx[0], &Overflow ); // Q27 +#endif + dd_fx[i] = round_fx_sat( Ldd ); // Q11 rr_fx[i] = L_max( Lrr, 1 ); move32(); /* move rr and dd into rr[i] and dd[i] */ @@ -179,8 +200,11 @@ void set_impulse_fx( FOR( i = L_SUBFR - 2; i >= start2; i-- ) { /*rr[i] = rr[i+1] + gh[L_SUBFR+L_IMPULSE2-1-i]*gh[L_SUBFR+L_IMPULSE2-1-i];*/ - rr_fx[i] = L_mac_o( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], - gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], &Overflow ); // Q27 +#ifdef ISSUE_1867_replace_overflow_libenc + rr_fx[i] = L_mac_sat( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i] ); // Q27 +#else + rr_fx[i] = L_mac_o( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], &Overflow ); // Q27 +#endif move32(); } /* nominator rows */ diff --git a/lib_enc/speech_music_classif_fx.c b/lib_enc/speech_music_classif_fx.c index e2c8f59ffcd6ffbc872fde234cfeb83dee1555e2..76f2467a364a600d13fdfac33cd3639ec1081ed1 100644 --- a/lib_enc/speech_music_classif_fx.c +++ b/lib_enc/speech_music_classif_fx.c @@ -662,9 +662,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis Word16 tmp1, tmp2, exp2, scale, exp3; SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas; HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /*------------------------------------------------------------------* @@ -794,10 +796,18 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis sum_PS = L_deposit_l( 0 ); FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + sum_PS = L_add_sat( sum_PS, PS[i] ); +#else sum_PS = L_add_o( sum_PS, PS[i], &Overflow ); +#endif } exp1 = norm_l( sum_PS ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = round_fx_sat( L_shl( sum_PS, exp1 ) ); +#else tmp1 = round_fx_o( L_shl( sum_PS, exp1 ), &Overflow ); +#endif exp1 = sub( 30, exp1 ); FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ ) @@ -805,7 +815,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis /*PS_norm[i] = PS[i] / sum_PS;*/ /*dPS[i] = (float)fabs(PS_norm[i] - st->past_PS[i]);*/ exp2 = norm_l( PS[i] ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp2 = round_fx_sat( L_shl( PS[i], exp2 ) ); +#else tmp2 = round_fx_o( L_shl( PS[i], exp2 ), &Overflow ); +#endif exp2 = sub( 30, exp2 ); scale = shr( sub( tmp1, tmp2 ), 15 ); @@ -866,7 +880,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis ELSE { exp1 = norm_l( L_add( dPS[i], 336 ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = round_fx_sat( L_shl_sat( L_add( dPS[i], 336 ), exp1 ) ); +#else tmp1 = round_fx_o( L_shl_o( L_add( dPS[i], 336 ), exp1, &Overflow ), &Overflow ); +#endif exp1 = sub( 30, exp1 ); exp2 = norm_l( mx ); @@ -923,7 +941,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis FOR( i = 0; i < N_FEATURES; i++ ) { /**pFV = pSF[0] * *pFV + pSF[1];*/ +#ifdef ISSUE_1867_replace_overflow_libenc + *pFV = round_fx_sat( L_shl_sat( L_mac( pSF_a[i], *pFV, pSF_m[i] ), ishift[i] ) ); +#else *pFV = round_fx_o( L_shl_o( L_mac( pSF_a[i], *pFV, pSF_m[i] ), ishift[i], &Overflow ), &Overflow ); +#endif move16(); pFV++; } @@ -954,7 +976,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis FOR( p = 0; p < N_FEATURES; p++ ) { /* xm[p] = FV[p] - m_speech[k*N_FEATURES+p];*/ +#ifdef ISSUE_1867_replace_overflow_libenc + xm[p] = sub_sat( FV[p], m_speech_fx[k * N_FEATURES + p] ); +#else xm[p] = sub_o( FV[p], m_speech_fx[k * N_FEATURES + p], &Overflow ); +#endif move16(); /*Q15 */ } @@ -970,7 +996,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis FOR( p = 0; p < N_FEATURES; p++ ) { /*xm[p] = FV[p] - m_noise[k*N_FEATURES+p];*/ +#ifdef ISSUE_1867_replace_overflow_libenc + xm[p] = sub_sat( FV[p], m_noise_fx[k * N_FEATURES + p] ); +#else xm[p] = sub_o( FV[p], m_noise_fx[k * N_FEATURES + p], &Overflow ); +#endif move16(); /*Q15 */ } @@ -985,7 +1015,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis FOR( p = 0; p < N_FEATURES; p++ ) { /*xm[p] = FV[p] - m_music[k*N_FEATURES+p];*/ +#ifdef ISSUE_1867_replace_overflow_libenc + xm[p] = sub_sat( FV[p], m_music_fx[k * N_FEATURES + p] ); +#else xm[p] = sub_o( FV[p], m_music_fx[k * N_FEATURES + p], &Overflow ); +#endif move16(); /*Q15 */ } @@ -999,7 +1033,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis /* calculate log-probability */ /*log(0.0001)-0.5f * N_FEATURES * LOG_PI2 in Q9 */ - lps = extract_h( L_shl_o( L_sub( max_s, LOG_PROB_CONST ), 16 - 1, &Overflow ) ); /*Q9 */ +#ifdef ISSUE_1867_replace_overflow_libenc + lps = extract_h( L_shl_sat( L_sub( max_s, LOG_PROB_CONST ), 16 - 1 ) ); /*Q9 */ +#else + lps = extract_h( L_shl_o( L_sub( max_s, LOG_PROB_CONST ), 16 - 1, &Overflow ) ); /*Q9 */ +#endif lps = s_max( lps, -10832 ); lpm = extract_h( L_shl( L_sub( max_m, LOG_PROB_CONST ), 16 - 1 ) ); /*Q9 */ @@ -1007,7 +1045,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis /* lpn = (float)log(pyn) - 0.5f * N_FEATURES * (float)log(2*PI); */ - lpn = extract_h( L_shl_o( L_sub( max_n, LOG_PROB_CONST ), 16 - 1, &Overflow ) ); /*Q9 */ +#ifdef ISSUE_1867_replace_overflow_libenc + lpn = extract_h( L_shl_sat( L_sub( max_n, LOG_PROB_CONST ), 16 - 1 ) ); /*Q9 */ +#else + lpn = extract_h( L_shl_o( L_sub( max_n, LOG_PROB_CONST ), 16 - 1, &Overflow ) ); /*Q9 */ +#endif lpn = s_max( lpn, -10832 ); *high_lpn_flag_ptr = 0; @@ -1459,9 +1501,11 @@ static Word16 attack_det_fx( /* o : attack flag Word16 i, j, tmp, tmp1, attack, exp1; Word32 L_tmp, etmp, etmp2, finc[ATT_NSEG]; Word16 att_3lsub_pos; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif att_3lsub_pos = ATT_3LSUB_POS; @@ -1479,7 +1523,11 @@ static Word16 attack_det_fx( /* o : attack flag FOR( j = 1; j < ATT_SEG_LEN; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac0_sat( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j] ); /*2*Qx */ +#else L_tmp = L_mac0_o( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j], &Overflow ); /*2*Qx */ +#endif } finc[i] = L_tmp; @@ -1504,7 +1552,11 @@ static Word16 attack_det_fx( /* o : attack flag FOR( i = 1; i < att_3lsub_pos; i++ ) { - L_tmp = L_add_o( L_tmp, L_shr_sat( finc[i], Qx ), &Overflow ); /*Qx */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_add_sat( L_tmp, L_shr_sat( finc[i], Qx ) ); /*Qx */ +#else + L_tmp = L_add_o( L_tmp, L_shr_sat( finc[i], Qx ), &Overflow ); /*Qx */ +#endif } L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(14-exp1+Qx) */ etmp = L_shl( L_tmp, sub( exp1, 14 ) ); /*Qx */ @@ -1516,7 +1568,11 @@ static Word16 attack_det_fx( /* o : attack flag L_tmp = L_shr_sat( finc[attack], Qx ); /*Qx */ FOR( i = 1; i < tmp1; i++ ) { - L_tmp = L_add_o( L_tmp, L_shr_sat( finc[i + attack], Qx ), &Overflow ); /*Qx */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_add_sat( L_tmp, L_shr_sat( finc[i + attack], Qx ) ); /*Qx */ +#else + L_tmp = L_add_o( L_tmp, L_shr_sat( finc[i + attack], Qx ), &Overflow ); /*Qx */ +#endif } L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(14-exp1+Qx) */ etmp2 = L_shl( L_tmp, sub( exp1, 14 ) ); /*Qx */ @@ -2615,9 +2671,11 @@ static Word16 attack_det_ivas_fx( /* o : attack flag Word64 W_tmp; Word16 q_diff; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif att_3lsub_pos = ATT_3LSUB_POS; @@ -2635,7 +2693,11 @@ static Word16 attack_det_ivas_fx( /* o : attack flag FOR( j = 1; j < ATT_SEG_LEN; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac0_sat( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j] ); /*2*Qx */ +#else L_tmp = L_mac0_o( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j], &Overflow ); /*2*Qx */ +#endif } finc[i] = L_tmp; @@ -3676,9 +3738,11 @@ static void spec_analysis_fx( Word16 peak_idx[65]; Word16 valey_idx[65]; Word16 p2v[65]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* find spectral peaks */ @@ -3762,7 +3826,15 @@ static void spec_analysis_fx( test(); IF( GT_16( peak_idx[k], valey_idx[i] ) && LT_16( peak_idx[k], valey_idx[i + 1] ) ) { +#ifdef ISSUE_1867_replace_overflow_libenc + p2v[k] = sub_sat( shl_sat( peak[k], 1 ), add_sat( valley[i], valley[i + 1] ) ); +#else +#ifdef ISSUE_1796_replace_shl_o p2v[k] = sub_o( shl_sat( peak[k], 1 ), add_o( valley[i], valley[i + 1], &Overflow ), &Overflow ); +#else + p2v[k] = sub_o( shl_o( peak[k], 1, &Overflow ), add_o( valley[i], valley[i + 1], &Overflow ), &Overflow ); +#endif +#endif move16(); k = add( k, 1 ); } diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index 598745ebd34f60402923f6bb31109b1fa60934b9..38a36083ef6b9ee1131a2684c7ab0a937bf6fe71 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -50,9 +50,11 @@ void stat_noise_uv_enc_fx( Word16 noisiness = 0; move16(); Word16 num, den, expn, expd; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif test(); test(); @@ -65,12 +67,20 @@ void stat_noise_uv_enc_fx( *-----------------------------------------------------------------*/ /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */ expn = sub( norm_l( LepsP[0] ), 1 ); +#ifdef ISSUE_1867_replace_overflow_libenc + num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/ +#else num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/ +#endif expd = norm_l( LepsP[1] ); +#ifdef ISSUE_1867_replace_overflow_libenc + den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/ +#else den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/ - num = div_s( num, den ); /*expn-expd+15*/ - num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ - num = sub( num, 1024 ); /*num - 1*/ +#endif + num = div_s( num, den ); /*expn-expd+15*/ + num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ + num = sub( num, 1024 ); /*num - 1*/ test(); IF( NE_16( st_fx->bwidth, NB ) ) @@ -123,9 +133,11 @@ void stat_noise_uv_enc_ivas_fx( Word16 noisiness = 0; move16(); Word16 num, den, expn, expd; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif test(); test(); @@ -138,12 +150,20 @@ void stat_noise_uv_enc_ivas_fx( *-----------------------------------------------------------------*/ /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */ expn = sub( norm_l( LepsP[0] ), 1 ); +#ifdef ISSUE_1867_replace_overflow_libenc + num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/ +#else num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/ +#endif expd = norm_l( LepsP[1] ); +#ifdef ISSUE_1867_replace_overflow_libenc + den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/ +#else den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/ - num = div_s( num, den ); /*expn-expd+15*/ - num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ - num = sub( num, 1024 ); /*num - 1*/ +#endif + num = div_s( num, den ); /*expn-expd+15*/ + num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ + num = sub( num, 1024 ); /*num - 1*/ test(); IF( NE_16( st_fx->bwidth, NB ) ) diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 2b2c809a9837b449d812759564a996d1d535d609..b8936db2bba1a5f151032e32b3b5a5652b5502b6 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -303,9 +303,11 @@ void swb_bwe_enc_ivas_fx( Word16 fb_ener_adjust_fx; Word16 ener_adjust_quan_fx = 0; move16(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 fb_band_begin; Word16 q_new_input_hp; @@ -408,7 +410,11 @@ void swb_bwe_enc_ivas_fx( *----------------------------------------------------------------------*/ /* tilt returned in Q24 goto to Q11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tilt_nb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3 ) ); +#else tilt_nb_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3, &Overflow ), &Overflow ); +#endif /*---------------------------------------------------------------------* * SWB BWE encoding * FB BWE encoding @@ -542,8 +548,12 @@ void swb_bwe_enc_ivas_fx( exp1 = norm_l( L_tmp ); L_tmp = L_shl( L_tmp, exp1 ); exp = sub( sub( 31, exp1 ), sub( 30, exp ) ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ + L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ +#ifdef ISSUE_1867_replace_overflow_libenc + fb_ener_adjust_fx = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ +#else fb_ener_adjust_fx = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ +#endif } ELSE { @@ -623,9 +633,11 @@ void swb_bwe_enc_fx( Word16 fb_ener_adjust_fx; Word16 ener_adjust_quan_fx = 0; move16(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -683,7 +695,11 @@ void swb_bwe_enc_fx( *----------------------------------------------------------------------*/ /* tilt returned in Q24 goto to Q11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tilt_nb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3 ) ); +#else tilt_nb_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3, &Overflow ), &Overflow ); +#endif /*---------------------------------------------------------------------* * SWB BWE encoding * FB BWE encoding @@ -805,8 +821,12 @@ void swb_bwe_enc_fx( L_tmp = L_shl( L_tmp, exp1 ); // exp = 31 - exp1 - ( 30 - exp ); exp = add( 31 - 30, sub( exp, exp1 ) ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ + L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */ +#ifdef ISSUE_1867_replace_overflow_libenc + fb_ener_adjust_fx = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ +#else fb_ener_adjust_fx = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ +#endif } ELSE { @@ -1007,9 +1027,11 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class Word16 sharplimit; Word16 numsharp, num, den; Word16 numharmonic, tmp, expn, expd, scale; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -1046,16 +1068,28 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class { IF( hBWE_FD->prev_global_gain_fx == 0 ) { - gain_tmp = round_fx_o( L_shl_o( fGain, 30, &Overflow ), &Overflow ); /*Q14 */ +#ifdef ISSUE_1867_replace_overflow_libenc + gain_tmp = round_fx_sat( L_shl_sat( fGain, 30 ) ); /*Q14 */ +#else + gain_tmp = round_fx_o( L_shl_o( fGain, 30, &Overflow ), &Overflow ); /*Q14 */ +#endif } ELSE { expn = norm_l( fGain ); +#ifdef ISSUE_1867_replace_overflow_libenc + num = extract_h( L_shl( fGain, expn ) ); +#else num = extract_h( L_shl_o( fGain, expn, &Overflow ) ); +#endif expn = sub( sub( 30, expn ), shl( Q_shb, 1 ) ); expd = norm_l( hBWE_FD->prev_global_gain_fx ); +#ifdef ISSUE_1867_replace_overflow_libenc + den = extract_h( L_shl( hBWE_FD->prev_global_gain_fx, expd ) ); +#else den = extract_h( L_shl_o( hBWE_FD->prev_global_gain_fx, expd, &Overflow ) ); +#endif expd = sub( sub( 30, expd ), shl( st_fx->prev_Q_shb, 1 ) ); scale = shr( sub( den, num ), 15 ); @@ -1153,9 +1187,13 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class move16(); } expd = norm_s( den ); - tmp = div_s( shl( 1, sub( 14, expd ) ), den ); /*Q(29-expd-Q_syn) */ - L_tmp = L_mult( tmp, peak ); /*Q(30-expd) */ + tmp = div_s( shl( 1, sub( 14, expd ) ), den ); /*Q(29-expd-Q_syn) */ + L_tmp = L_mult( tmp, peak ); /*Q(30-expd) */ +#ifdef ISSUE_1867_replace_overflow_libenc + sharp = round_fx_sat( L_shl_sat( L_tmp, sub( expd, 4 ) ) ); /*Q10 */ +#else sharp = round_fx_o( L_shl_o( L_tmp, sub( expd, 4 ), &Overflow ), &Overflow ); /*Q10 */ +#endif } ELSE { @@ -1351,9 +1389,11 @@ static void vqWithCand_w_fx( const Word16 *p_E_ROM_dico; Word16 dist, temp1; Word32 L_dist, L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif IF( flag ) { @@ -1370,14 +1410,22 @@ static void vqWithCand_w_fx( FOR( i = 0; i < E_ROM_dico_size; i++ ) { - dist = sub_o( x[0], *p_E_ROM_dico++, &Overflow ); /*Q8 */ - L_dist = L_mult( dist, w[0] ); /*Q22 */ - L_dist = Mult_32_16( L_dist, dist ); /*Q15 */ - L_dist = L_shr( L_dist, 10 ); /*Q5 */ +#ifdef ISSUE_1867_replace_overflow_libenc + dist = sub_sat( x[0], *p_E_ROM_dico++ ); /*Q8 */ +#else + dist = sub_o( x[0], *p_E_ROM_dico++, &Overflow ); /*Q8 */ +#endif + L_dist = L_mult( dist, w[0] ); /*Q22 */ + L_dist = Mult_32_16( L_dist, dist ); /*Q15 */ + L_dist = L_shr( L_dist, 10 ); /*Q5 */ FOR( j = 1; j < dim; j++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + temp1 = sub_sat( x[j], *p_E_ROM_dico++ ); +#else temp1 = sub_o( x[j], *p_E_ROM_dico++, &Overflow ); +#endif L_tmp = L_mult( temp1, w[j] ); /*Q22 */ L_tmp = Mult_32_16( L_tmp, temp1 ); /*Q15 */ L_dist = L_add( L_dist, L_shr( L_tmp, 10 ) ); /*Q5 */ @@ -1652,9 +1700,11 @@ static void msvq_interpol_fx( Word16 quant_select[SWB_FENV], w_env11[SWB_FENV / 2], w_env12[SWB_FENV / 2], tmp; Word32 L_tmp, distCand[N_CAND], L_dist, L_minDist; Word16 synth_energy[SWB_FENV]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Extract target vector */ @@ -1695,13 +1745,21 @@ static void msvq_interpol_fx( /* Extract vector for odd position */ FOR( n_band = 0; n_band < DIM11; n_band++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + quant_tmp[n_band] = add_sat( quant_tmp1[n_band], quant_tmp2[n_band] ); +#else quant_tmp[n_band] = add_o( quant_tmp1[n_band], quant_tmp2[n_band], &Overflow ); +#endif move16(); } FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ); /*Q8 */ +#else tmp = add_o( quant_tmp[n_band], quant_tmp[n_band + 1], &Overflow ); /*Q8 */ +#endif tmp = shr( tmp, 1 ); quant_tmp2[n_band] = sub( env_temp12[n_band], tmp ); move16(); /*Q8 */ @@ -1724,7 +1782,11 @@ static void msvq_interpol_fx( FOR( n_band = 0; n_band < DIM12 - 1; n_band++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ); +#else tmp = add_o( quant_tmp[n_band], quant_tmp[n_band + 1], &Overflow ); +#endif tmp = shr( tmp, 1 ); quant_select[( n_band << 1 ) + 1] = add( tmp, quant_tmp2[n_band] ); move16(); /*Q8 */ @@ -1784,9 +1846,11 @@ static void msvq_interpol_2_fx( Word16 quant_select[SWB_FENV], w_env11[SWB_FENV / 2], w_env12[SWB_FENV / 2]; Word32 L_tmp, distCand[N_CAND], L_dist, L_minDist; Word16 synth_energy[SWB_FENV]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Extract target vector */ FOR( n_band = 0; n_band < DIM11 - 1; n_band++ ) @@ -1844,9 +1908,17 @@ static void msvq_interpol_2_fx( move16(); FOR( n_band = 1; n_band < DIM12 - 1; n_band++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + tmp_q = add_sat( quant_tmp[n_band - 1], quant_tmp[n_band] ); +#else tmp_q = add_o( quant_tmp[n_band - 1], quant_tmp[n_band], &Overflow ); +#endif tmp_q = shr( tmp_q, 1 ); +#ifdef ISSUE_1867_replace_overflow_libenc + quant_tmp2[n_band] = sub_sat( env_temp12[n_band], tmp_q ); +#else quant_tmp2[n_band] = sub_o( env_temp12[n_band], tmp_q, &Overflow ); +#endif move16(); } @@ -1867,9 +1939,17 @@ static void msvq_interpol_2_fx( move16(); /*Q8 */ FOR( n_band = 1; n_band < DIM12 - 1; n_band++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + tmp_q = add_sat( quant_tmp[n_band - 1], quant_tmp[n_band] ); +#else tmp_q = add_o( quant_tmp[n_band - 1], quant_tmp[n_band], &Overflow ); +#endif tmp_q = shr( tmp_q, 1 ); +#ifdef ISSUE_1867_replace_overflow_libenc + quant_select[( n_band << 1 ) - 1] = add_sat( quant_tmp2[n_band], tmp_q ); +#else quant_select[( n_band << 1 ) - 1] = add_o( quant_tmp2[n_band], tmp_q, &Overflow ); +#endif } L_dist = L_deposit_l( 0 ); @@ -1931,9 +2011,11 @@ static void calculate_Tonality_fx( Word16 org_spec[80], gen_spec[80]; Word32 L_log_gm_org, L_log_gm_gen; Word16 l_shift; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* to reduce dynamic range of original spectrum */ @@ -2039,7 +2121,11 @@ static void calculate_Tonality_fx( L_tmp2 = Mpy_32_16_1( L_log_gm_org, inv_len ); /* Q14 */ L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + *SFM_org = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */ +#else *SFM_org = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#endif move16(); *SFM_org = s_max( 0, s_min( *SFM_org, 24547 ) ); move16(); /*0.0001 and 5.993 in Q12 */ @@ -2060,7 +2146,11 @@ static void calculate_Tonality_fx( L_tmp2 = Mpy_32_16_1( L_log_gm_gen, inv_len ); /* Q14 */ L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + *SFM_gen = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */ +#else *SFM_gen = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#endif move16(); *SFM_gen = s_max( 0, s_min( *SFM_gen, 24547 ) ); move16(); /*0.0001 and 5.993 in Q12 */ @@ -2089,9 +2179,11 @@ static void calculate_Tonality_ivas_fx( Word16 org_spec[80], gen_spec[80]; Word32 L_log_gm_org, L_log_gm_gen; Word16 l_shift; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* to reduce dynamic range of original spectrum */ @@ -2197,7 +2289,11 @@ static void calculate_Tonality_ivas_fx( L_tmp2 = Mpy_32_16_1( L_log_gm_org, inv_len ); /* Q14 */ L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + *SFM_org = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */ +#else *SFM_org = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#endif move16(); *SFM_org = s_max( 0, s_min( *SFM_org, 24547 ) ); move16(); /*0.0001 and 5.993 in Q12 */ @@ -2218,7 +2314,11 @@ static void calculate_Tonality_ivas_fx( L_tmp2 = Mpy_32_16_1( L_log_gm_gen, inv_len ); /* Q14 */ L_tmp = L_sub( L_tmp1, L_tmp2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + *SFM_gen = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */ +#else *SFM_gen = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */ +#endif move16(); *SFM_gen = s_max( 0, s_min( *SFM_gen, 24547 ) ); move16(); /*0.0001 and 5.993 in Q12 */ @@ -2606,9 +2706,11 @@ static Word16 SWB_BWE_encoding_fx( Word16 SWB_tenv_tmp_fx[SWB_TENV]; Word16 max_fx; Word16 energy_factor_fx[SWB_FENV], w_env_fx[SWB_FENV]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; @@ -2651,7 +2753,11 @@ static Word16 SWB_BWE_encoding_fx( } /* tilt returned in Q24 go to Q11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tilt_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3 ) ); +#else tilt_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3, &Overflow ), &Overflow ); +#endif test(); test(); IF( EQ_16( IsTransient, 1 ) && ( GT_16( tilt_fx, 16384 ) || GT_16( st_fx->clas, 1 ) ) ) @@ -2755,7 +2861,11 @@ static Word16 SWB_BWE_encoding_fx( L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &expn ); /*31-expn */ +#ifdef ISSUE_1867_replace_overflow_libenc + Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, sub( expn, 1 ) ) ); /*Q14 */ +#else Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, sub( expn, 1 ), &Overflow ), &Overflow ); /*Q14 */ +#endif } ELSE { @@ -2767,7 +2877,11 @@ static Word16 SWB_BWE_encoding_fx( { L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */ - Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, 2 ) ); /*Q15 */ +#else + Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */ +#endif } ELSE IF( GT_16( Rat_tenv_fx, 16384 ) ) { @@ -3051,9 +3165,11 @@ static Word16 SWB_BWE_encoding_ivas_fx( Word16 SWB_tenv_tmp_fx[SWB_TENV]; Word16 max_fx; Word16 energy_factor_fx[SWB_FENV], w_env_fx[SWB_FENV]; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 inner_frame; Word16 q_shift; @@ -3114,7 +3230,11 @@ static Word16 SWB_BWE_encoding_ivas_fx( } /* tilt returned in Q24 go to Q11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tilt_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3 ) ); +#else tilt_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3, &Overflow ), &Overflow ); +#endif test(); test(); IF( EQ_16( IsTransient, 1 ) && ( GT_16( tilt_fx, 16384 ) || GT_16( st_fx->clas, 1 ) ) ) @@ -3219,7 +3339,11 @@ static Word16 SWB_BWE_encoding_ivas_fx( expn = sub( sub( 30, expn ), sub( shl( Q_insig_lp, 1 ), 7 ) ); expd = norm_l( WB_tenv_syn_fx ); +#ifdef ISSUE_1867_replace_overflow_libenc + den = round_fx_sat( L_shl( WB_tenv_syn_fx, expd ) ); +#else den = round_fx_o( L_shl( WB_tenv_syn_fx, expd ), &Overflow ); +#endif expd = sub( sub( 30, expd ), sub( shl( Q_insig_lp, 1 ), 7 ) ); scale = shr( sub( den, num ), 15 ); @@ -3232,7 +3356,11 @@ static Word16 SWB_BWE_encoding_ivas_fx( L_tmp = L_deposit_h( tmp ); L_tmp = Isqrt_lc( L_tmp, &expn ); /*31-expn */ +#ifdef ISSUE_1867_replace_overflow_libenc + Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, sub( expn, 1 ) ) ); /*Q14 */ +#else Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, sub( expn, 1 ), &Overflow ), &Overflow ); /*Q14 */ +#endif } ELSE { @@ -3242,8 +3370,12 @@ static Word16 SWB_BWE_encoding_ivas_fx( IF( LT_16( Rat_tenv_fx, 8192 ) ) { - L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */ - Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */ + L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, 2 ) ); /*Q15 */ +#else + Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */ +#endif } ELSE IF( GT_16( Rat_tenv_fx, 16384 ) ) { diff --git a/lib_enc/swb_bwe_enc_hr_fx.c b/lib_enc/swb_bwe_enc_hr_fx.c index dc962d1bc18e35f997468a694c58084d2a9acb96..6541b30fa0ce280e5675536d032d12b8b1292a54 100644 --- a/lib_enc/swb_bwe_enc_hr_fx.c +++ b/lib_enc/swb_bwe_enc_hr_fx.c @@ -117,9 +117,11 @@ void swb_bwe_enc_hr_fx( #else Word32 L_t_audio_tmp_fx[L_FRAME48k]; #endif +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD; BSTR_ENC_HANDLE hBstr = st_fx->hBstr; @@ -768,7 +770,11 @@ void swb_bwe_enc_hr_fx( { L_tmp = L_mult( temp, t_audio_fx[i] ); L_tmp = L_shr_sat( L_tmp, temp2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + t_audio_fx[i] = round_fx_sat( L_tmp ); +#else t_audio_fx[i] = round_fx_o( L_tmp, &Overflow ); +#endif move16(); } diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 3c92c7f895dc010ace1e3d01e5e96c687ad91e8e..ad178ab55171e24fc809772c6eb82fee24d20062 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -698,9 +698,11 @@ static void gethar_noisegn_fx( Word16 temp_lo, temp_hi; Word16 Qg; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /*Generate HF noise*/ genhf_noise_fx( noise_flr_fx, Qss, L_xSynth_har, QsL, sspectra_fx, bands, har_bands, har_freq_est2, pos_max_hfe2, pul_res_fx, pk_sf_fx, fLenLow, @@ -782,9 +784,14 @@ static void gethar_noisegn_fx( exp = sub( exp, Qsqrt ); L_temp = L_Comp( exp, frac ); - L_temp = Mpy_32_16_1( L_temp, 19728 ); /* log(2)/log(10)=.30102999566398119521 = 19728.3(Q16) Q(0+16+1)=Q17 */ + L_temp = Mpy_32_16_1( L_temp, 19728 ); /* log(2)/log(10)=.30102999566398119521 = 19728.3(Q16) Q(0+16+1)=Q17 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_temp = L_shl_sat( L_temp, 13 ); /* Q17+13=30 30-16=14 */ + g_fx = round_fx_sat( L_temp ); +#else L_temp = L_shl_o( L_temp, 13, &Overflow ); /* Q17+13=30 30-16=14 */ g_fx = round_fx_o( L_temp, &Overflow ); +#endif } gqlevs_fx = 4; diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index d5c546c35569fdb118a0cef6e1c31b2fde915e2f..490d80aae077122702158ca499a250bd948a3a8d 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -745,9 +745,11 @@ void wb_tbe_enc_fx( Word16 avg_voice_fac; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; RF_ENC_HANDLE hRF = st_fx->hRF; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /*Word16 att = 32767;*/ @@ -1214,8 +1216,13 @@ void wb_tbe_enc_fx( exp = norm_s( voicingBufAvg_fx ); tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ L_tmp = L_mult( pitBufAvg_fx, tmp ); /* (21-exp) */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, add( exp, 10 ) ); + tmp = round_fx_sat( L_tmp ); /* Q15 */ +#else L_tmp = L_shl_o( L_tmp, add( exp, 10 ), &Overflow ); tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ +#endif } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ @@ -1345,9 +1352,11 @@ void wb_tbe_enc_ivas_fx( Word16 dummy = 0; Word16 avg_voice_fac; TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif move16(); @@ -1379,7 +1388,11 @@ void wb_tbe_enc_ivas_fx( FOR( j = 0; j < L_SUBFR16k; j = j + 4 ) { L_tmp = L_mult( hb_old_speech[i], ola_win_shb_switch_fold_fx[j] ); +#ifdef ISSUE_1867_replace_overflow_libenc + hb_old_speech[i] = mac_r_sat( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j] ); +#else hb_old_speech[i] = mac_ro( L_tmp, hb_speech[k], ola_win_shb_switch_fold_fx[L_SUBFR16k - 4 - j], &Overflow ); +#endif move16(); i--; k++; @@ -1867,8 +1880,13 @@ void wb_tbe_enc_ivas_fx( exp = norm_s( voicingBufAvg_fx ); tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ L_tmp = L_mult( pitBufAvg_fx, tmp ); /* (21-exp) */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_shl_sat( L_tmp, add( exp, 10 ) ); + tmp = round_fx_sat( L_tmp ); /* Q15 */ +#else L_tmp = L_shl_o( L_tmp, add( exp, 10 ), &Overflow ); - tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ + tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ +#endif } tmp = s_max( s_min( tmp, 32767 ), 22938 ); /* Q15 */ @@ -2049,9 +2067,11 @@ void swb_tbe_enc_fx( Word16 tilt_para; Word16 Q_bwe_exc_fb; Word16 n_subfr_saturation; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; RF_ENC_HANDLE hRF = st_fx->hRF; @@ -2519,8 +2539,13 @@ void swb_tbe_enc_fx( curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ + curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ +#else prev_pow_fx = L_mac0_o( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i], &Overflow ); /* 2*Q_bwe_exc */ curr_pow_fx = L_mac0_o( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], &Overflow ); /* 2*Q_bwe_exc */ +#endif } if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) @@ -2554,12 +2579,20 @@ void swb_tbe_enc_fx( { FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { - tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ + tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ +#else + L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ +#endif tmp = sub( 32767 /*1.0f Q15*/, tmp ); Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ +#else + shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ +#endif move16(); } } @@ -2568,11 +2601,19 @@ void swb_tbe_enc_fx( FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); - L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ +#else + L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ +#endif tmp = sub( 32767 /*1.0f Q15*/, tmp ); Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ +#else + shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ +#endif move16(); } } @@ -2801,9 +2842,13 @@ void swb_tbe_enc_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ /* sd_uq_q*pitBufAvg */ - L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ - tmp = round_fx_o( L_shl_o( L_tmp, 31 - ( 7 - exp ), &Overflow ), &Overflow ); /* Q15 */ + L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ +#else + tmp = round_fx_o( L_shl_o( L_tmp, 31 - ( 7 - exp ), &Overflow ), &Overflow ); /* Q15 */ +#endif } tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); @@ -2991,9 +3036,11 @@ void swb_tbe_enc_ivas_fx( Word16 tilt_para_fx; Word16 Q_bwe_exc_fb; Word16 n_subfr_saturation; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif Env_error_fx = 0; @@ -3852,8 +3899,12 @@ void swb_tbe_enc_ivas_fx( FOR( i = 0; i < L_SHB_LAHEAD; i++ ) { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ - shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ +#ifdef ISSUE_1867_replace_overflow_libenc + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ +#else + shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ +#endif move16(); } IF( exp < 0 ) @@ -3870,12 +3921,20 @@ void swb_tbe_enc_ivas_fx( { FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { - tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ + tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ +#else + L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ +#endif tmp = sub( 32767 /*1.0f Q15*/, tmp ); L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ +#else + shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ +#endif move16(); } } @@ -3884,11 +3943,19 @@ void swb_tbe_enc_ivas_fx( FOR( ; i < L_SHB_LAHEAD + 10; i++ ) { tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); - L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ +#else + L_tmp1 = Mult_32_16( L_shl_o( 1, sub( 31, exp ), &Overflow ), tmp ); /* Q31-exp */ +#endif tmp = sub( 32767 /*1.0f Q15*/, tmp ); L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ + L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ +#else + shaped_shb_excitation_fx[i] = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /* Q_bwe_exc */ +#endif move16(); } } @@ -4395,9 +4462,13 @@ void swb_tbe_enc_ivas_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ /* sd_uq_q*pitBufAvg */ - L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ - tmp = round_fx_o( L_shl_o( L_tmp, 31 - ( 7 - exp ), &Overflow ), &Overflow ); /* Q15 */ + L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ +#else + tmp = round_fx_o( L_shl_o( L_tmp, 31 - ( 7 - exp ), &Overflow ), &Overflow ); /* Q15 */ +#endif } tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); @@ -4552,9 +4623,11 @@ static void EstimateSHBFrameGain_fx( Word16 exp_out; Word16 tmp; Word16 scaling = 0; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif move16(); @@ -4665,27 +4738,47 @@ static void EstimateSHBFrameGain_fx( FOR( i = 0; i < l_shb_lahead; i++ ) { - sig = mult_ro( oriSHB[i], win_shb[i], &Overflow ); /* Q_oriSHB */ - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_orisHB*/ - sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[i] ), &Overflow ); /*Q_synSHB */ - synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_synSHB */ +#ifdef ISSUE_1867_replace_overflow_libenc + sig = mult_r_sat( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_orisHB*/ + sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB */ +#else + sig = mult_ro( oriSHB[i], win_shb[i], &Overflow ); /* Q_oriSHB */ + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_orisHB*/ + sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[i] ), &Overflow ); /*Q_synSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_synSHB */ +#endif } FOR( ; i < l_frame; i++ ) { - oriNrg = L_mac0_o( oriNrg, oriSHB[i], oriSHB[i], &Overflow ); /* 2*Q_oriSHB */ - sig = round_fx_o( mod_syn[i], &Overflow ); /* Q_oriSHB */ - synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ +#ifdef ISSUE_1867_replace_overflow_libenc + oriNrg = L_mac0_sat( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ + sig = round_fx_sat( mod_syn[i] ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB */ +#else + oriNrg = L_mac0_o( oriNrg, oriSHB[i], oriSHB[i], &Overflow ); /* 2*Q_oriSHB */ + sig = round_fx_o( mod_syn[i], &Overflow ); /* Q_oriSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ +#endif } tmp = add( l_frame, l_shb_lahead ); FOR( ; i < tmp; i++ ) { - sig = mult_ro( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i], &Overflow ); /* Q_oriSHB */ - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ +#ifdef ISSUE_1867_replace_overflow_libenc + sig = mult_r_sat( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB */ + sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB */ +#else + sig = mult_ro( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i], &Overflow ); /* Q_oriSHB */ + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ), &Overflow ); /* Q_oriSHB */ synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ +#endif } IF( EQ_32( oriNrg, MAX_32 ) ) { @@ -4694,18 +4787,33 @@ static void EstimateSHBFrameGain_fx( move32(); FOR( i = 0; i < l_shb_lahead; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#else sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#endif } FOR( ; i < l_frame; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + sig = shl_sat( oriSHB[i], scaling ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#else sig = shl_sat( oriSHB[i], scaling ); oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#endif } FOR( ; i < tmp; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#else + sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#endif } } L_tmp = root_a_over_b_fx( oriNrg, 2 * Q_oriSHB, synNrg, 2 * Q_synSHB, &exp_out ); @@ -4741,9 +4849,11 @@ static void EstimateSHBFrameGain_ivas_fx( Word16 exp_out; Word16 tmp; Word16 scaling = 0; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move16(); @@ -4854,27 +4964,47 @@ static void EstimateSHBFrameGain_ivas_fx( FOR( i = 0; i < l_shb_lahead; i++ ) { - sig = mult_ro( oriSHB[i], win_shb[i], &Overflow ); /* Q_oriSHB */ - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_orisHB*/ - sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[i] ), &Overflow ); /*Q_synSHB */ - synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_synSHB - 2*/ +#ifdef ISSUE_1867_replace_overflow_libenc + sig = mult_r_sat( oriSHB[i], win_shb[i] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_orisHB*/ + sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[i] ) ); /*Q_synSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_synSHB - 2*/ +#else + sig = mult_ro( oriSHB[i], win_shb[i], &Overflow ); /* Q_oriSHB */ + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_orisHB*/ + sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[i] ), &Overflow ); /*Q_synSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_synSHB - 2*/ +#endif } FOR( ; i < l_frame; i++ ) { - oriNrg = L_mac0_o( oriNrg, oriSHB[i], oriSHB[i], &Overflow ); /* 2*Q_oriSHB */ - sig = round_fx_o( mod_syn[i], &Overflow ); /* Q_oriSHB */ - synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB - 2*/ +#ifdef ISSUE_1867_replace_overflow_libenc + oriNrg = L_mac0_sat( oriNrg, oriSHB[i], oriSHB[i] ); /* 2*Q_oriSHB */ + sig = round_fx_sat( mod_syn[i] ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ +#else + oriNrg = L_mac0_o( oriNrg, oriSHB[i], oriSHB[i], &Overflow ); /* 2*Q_oriSHB */ + sig = round_fx_o( mod_syn[i], &Overflow ); /* Q_oriSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB - 2*/ +#endif } tmp = add( l_frame, l_shb_lahead ); FOR( ; i < tmp; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + sig = mult_r_sat( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i] ); /* Q_oriSHB */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB */ + sig = round_fx_sat( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ) ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2*Q_oriSHB - 2*/ +#else sig = mult_ro( oriSHB[i], win_shb[l_frame + l_shb_lahead - 1 - i], &Overflow ); /* Q_oriSHB */ oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB */ sig = round_fx_o( Mult_32_16( mod_syn[i], win_shb[l_frame + l_shb_lahead - 1 - i] ), &Overflow ); /* Q_oriSHB */ synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB - 2*/ +#endif } IF( EQ_32( oriNrg, MAX_32 ) ) { @@ -4883,18 +5013,33 @@ static void EstimateSHBFrameGain_ivas_fx( move32(); FOR( i = 0; i < l_shb_lahead; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#else sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[i] ); oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#endif } FOR( ; i < l_frame; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + sig = shl_sat( oriSHB[i], scaling ); + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#else sig = shl_sat( oriSHB[i], scaling ); oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#endif } FOR( ; i < tmp; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2*Q_oriSHB + 2*scaling */ +#else + sig = mult_r( shl_sat( oriSHB[i], scaling ), win_shb[l_frame + l_shb_lahead - 1 - i] ); + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2*Q_oriSHB + 2*scaling */ +#endif } } L_tmp = root_a_over_b_fx( oriNrg, shl( Q_oriSHB, 1 ), synNrg, sub( shl( Q_synSHB, 1 ), 2 ), &exp_out ); @@ -5008,9 +5153,11 @@ static void EstimateSHBGainShape_fx( Word16 length_tmp; Word32 L_tmp, normFact; Word16 scaling = 0; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move32(); move16(); @@ -5128,26 +5275,44 @@ static void EstimateSHBGainShape_fx( j = i_mult2( join_length, i ); FOR( k = 0; k < length; k++ ) { - sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ - synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ + sig = mult_r( oriSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ +#ifdef ISSUE_1867_replace_overflow_libenc + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ +#else + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + k], subwin[k + 1] ); /* Q_oriSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ +#endif } FOR( k = 0; k < ( join_length - length ); k++ ) { - sig = mult_r( oriSHB[length + j + k], 32767 ); /* Q_oriSHB */ - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ - sig = mult_r( synSHB[length + j + k], 32767 ); /* Q_oriSHB */ - synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ + sig = mult_r( oriSHB[length + j + k], 32767 ); /* Q_oriSHB */ +#ifdef ISSUE_1867_replace_overflow_libenc + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[length + j + k], 32767 ); /* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ +#else + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[length + j + k], 32767 ); /* Q_oriSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ +#endif } FOR( k = 0; k < length; k++ ) { sig = mult_r( oriSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ - oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ +#ifdef ISSUE_1867_replace_overflow_libenc + oriNrg = L_mac0_sat( oriNrg, sig, sig ); /* 2* Q_oriSHB */ sig = mult_r( synSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ - synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ + synNrg = L_mac0_sat( synNrg, sig, sig ); /* 2* Q_oriSHB */ +#else + oriNrg = L_mac0_o( oriNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ + sig = mult_r( synSHB[j + join_length + k], subwin[length - k - 1] ); /* Q_oriSHB */ + synNrg = L_mac0_o( synNrg, sig, sig, &Overflow ); /* 2* Q_oriSHB */ +#endif } /* Only implemented in SWB because the length of samples in SWB frame is longer, more likely to saturate */ scaling = 0; @@ -5194,8 +5359,13 @@ static void EstimateSHBGainShape_fx( FOR( i = 0; i < num_gains; i++ ) { - subgain[i] = round_fx_o( L_shl_o( L_subgain[i], sub( norm[i], n_max + 1 ), &Overflow ), &Overflow ); /* Q(14-n_max) */ - L_sum_gain = L_mac0_o( L_sum_gain, subgain[i], subgain[i], &Overflow ); /* Q(28-2*n_max) */ +#ifdef ISSUE_1867_replace_overflow_libenc + subgain[i] = round_fx_sat( L_shl_sat( L_subgain[i], sub( norm[i], n_max + 1 ) ) ); /* Q(14-n_max) */ + L_sum_gain = L_mac0_sat( L_sum_gain, subgain[i], subgain[i] ); /* Q(28-2*n_max) */ +#else + subgain[i] = round_fx_o( L_shl_o( L_subgain[i], sub( norm[i], n_max + 1 ), &Overflow ), &Overflow ); /* Q(14-n_max) */ + L_sum_gain = L_mac0_o( L_sum_gain, subgain[i], subgain[i], &Overflow ); /* Q(28-2*n_max) */ +#endif move16(); } @@ -5209,8 +5379,12 @@ static void EstimateSHBGainShape_fx( { FOR( i = 0; i < num_gains; i++ ) { - L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ - subgain[i] = s_max( round_fx_o( L_shl_o( L_tmp, add( n, n_max + 1 ), &Overflow ), &Overflow ), 3277 /*0.1f Q15*/ ); /* Q15 */ + L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ +#ifdef ISSUE_1867_replace_overflow_libenc + subgain[i] = s_max( round_fx_sat( L_shl_sat( L_tmp, add( n, n_max + 1 ) ) ), 3277 /*0.1f Q15*/ ); /* Q15 */ +#else + subgain[i] = s_max( round_fx_o( L_shl_o( L_tmp, add( n, n_max + 1 ), &Overflow ), &Overflow ), 3277 /*0.1f Q15*/ ); /* Q15 */ +#endif move16(); } } @@ -5218,8 +5392,12 @@ static void EstimateSHBGainShape_fx( { FOR( i = 0; i < num_gains; i++ ) { - L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ - subgain[i] = round_fx_o( L_shl_o( L_tmp, add( n, n_max + 1 ), &Overflow ), &Overflow ); /* Q15 */ + L_tmp = Mpy_32_16_1( normFact, subgain[i] ); /*Q(31-n) * Q(31-norm[i]) */ /* Q(30-n-n_max) */ +#ifdef ISSUE_1867_replace_overflow_libenc + subgain[i] = round_fx_sat( L_shl_sat( L_tmp, add( n, n_max + 1 ) ) ); /* Q15 */ +#else + subgain[i] = round_fx_o( L_shl_o( L_tmp, add( n, n_max + 1 ), &Overflow ), &Overflow ); /* Q15 */ +#endif move16(); } } @@ -6849,9 +7027,11 @@ static void first_VQstages_fx( move16(); Word16 maxC = LSFMBEST; move16(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /*float dd[16];*/ @@ -6878,9 +7058,13 @@ static void first_VQstages_fx( L_tmp = L_deposit_l( 0 ); FOR( j = 0; j < N; j++ ) { - L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */ - L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ - L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp1 = L_shl_sat( L_mult0( u[j], w[j] ), 7 ); /*x2.56 + Q8 + Q7 */ +#else + L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */ +#endif + L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */ + L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */ } set32_fx( dist[1], L_tmp, maxC ); @@ -7368,9 +7552,11 @@ void fb_tbe_enc_fx( Word16 tmp, tmp1, tmp2, exp, exp2, exp_norm; Word16 s_max_value, exp_temp, i; TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif s_max_value = 0; FOR( i = 0; i < L_FRAME48k; i++ ) @@ -7405,9 +7591,13 @@ void fb_tbe_enc_fx( Copy( hBWE_TD->old_input_fhb_fx, input_fhb, Sample_Delay_HP ); Copy( tmp_vec, input_fhb + Sample_Delay_HP, L_FRAME48k - Sample_Delay_HP ); Copy( tmp_vec + L_FRAME48k - Sample_Delay_HP, hBWE_TD->old_input_fhb_fx, Sample_Delay_HP ); - temp2 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ + temp2 = sum2_fx_mod( input_fhb, L_FRAME48k / 2 ); /* Q11 */ +#ifdef ISSUE_1867_replace_overflow_libenc + temp2 = L_add_sat( temp2, L_shl_sat( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ) ) ); /* Q11 */ +#else temp2 = L_add_o( temp2, L_shl_o( hBWE_TD->prev_fb_energy_fx, sub( sub( add( exp_temp, exp_temp ), 6 ), hBWE_TD->prev_fb_energy_fx_Q ), &Overflow ), &Overflow ); /* Q11 */ - hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q11*/ +#endif + hBWE_TD->prev_fb_energy_fx = sum2_fx_mod( input_fhb + L_FRAME48k / 2, L_FRAME48k / 2 ); /*Q11*/ hBWE_TD->prev_fb_energy_fx_Q = sub( add( exp_temp, exp_temp ), 6 ); fb_exc_energy = sum2_fx_mod( fb_exc, L_FRAME16k ); /* Q(2*Q_fb_exc+1 -7) */ diff --git a/lib_enc/tcx_ltp_enc_fx.c b/lib_enc/tcx_ltp_enc_fx.c index 3cb55ba25ac4f44f2abc05215aa5ae9b1157c96b..a3d8620a4f111b5e91c36642e581ec2fb22af553 100644 --- a/lib_enc/tcx_ltp_enc_fx.c +++ b/lib_enc/tcx_ltp_enc_fx.c @@ -491,10 +491,12 @@ static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_fra { Word32 corr, ener; Word16 i, g, s1, s2, tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif s1 = sub( getScaleFactor16( speech, L_frame ), 4 ); @@ -522,13 +524,21 @@ static void tcx_ltp_find_gain( Word16 *speech, Word16 *pred_speech, Word16 L_fra ener = L_shl( ener, tmp ); s2 = sub( s2, tmp ); +#ifdef ISSUE_1867_replace_overflow_libenc + g = divide1616( round_fx_sat( corr ), round_fx_sat( ener ) ); +#else g = divide1616( round_fx_o( corr, &Overflow ), round_fx_o( ener, &Overflow ) ); +#endif BASOP_SATURATE_WARNING_OFF_EVS g = shl_sat( g, sub( s1, s2 ) ); BASOP_SATURATE_WARNING_ON_EVS /* Quantize gain */ +#ifdef ISSUE_1867_replace_overflow_libenc + g = shr( sub_sat( g, 0x1000 ), 13 ); +#else g = shr( sub_o( g, 0x1000, &Overflow ), 13 ); +#endif g = s_max( g, -1 ); *gain_index = g; @@ -543,9 +553,11 @@ static void tcx_ltp_find_gain_ivas_fx( Word16 *speech /*Qx*/, Word16 *pred_speec { Word32 corr, ener; Word16 i, g, s1, s2, tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif s1 = sub( getScaleFactor16( speech, L_frame ), 4 ); @@ -573,7 +585,11 @@ static void tcx_ltp_find_gain_ivas_fx( Word16 *speech /*Qx*/, Word16 *pred_speec ener = L_shl( ener, tmp ); s2 = sub( s2, tmp ); +#ifdef ISSUE_1867_replace_overflow_libenc + g = divide1616( round_fx_sat( corr ), round_fx_sat( ener ) ); +#else g = divide1616( round_fx_o( corr, &Overflow ), round_fx_o( ener, &Overflow ) ); +#endif BASOP_SATURATE_WARNING_OFF_EVS g = shl_sat( g, sub( s1, s2 ) ); /*Q15*/ BASOP_SATURATE_WARNING_ON_EVS @@ -627,10 +643,12 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, Word16 buf_zir[M + L_SUBFR], *zir; Word16 Aest[M + 1]; Word16 alpha, step; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif norm_corr = 0; @@ -791,10 +809,18 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, FOR( n = 0; n < L_subfr; n++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + speech_ltp[n] = sub_sat( speech[n], mult_r_sat( *gain, mult_r_sat( alpha, pred_speech[n] ) ) ); +#else speech_ltp[n] = sub_o( speech[n], mult_ro( *gain, mult_ro( alpha, pred_speech[n], &Overflow ), &Overflow ), &Overflow ); +#endif move16(); BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1867_replace_overflow_libenc + alpha = add_sat( alpha, step ); +#else alpha = add_o( alpha, step, &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } } @@ -845,7 +871,11 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, FOR( n = 0; n < L_subfr; n++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + speech_ltp[n] = add_sat( sub_sat( speech[n], mult_r_sat( *gain, pred_speech[n] ) ), zir[n] ); +#else speech_ltp[n] = add_o( sub_o( speech[n], mult_ro( *gain, pred_speech[n], &Overflow ), &Overflow ), zir[n], &Overflow ); +#endif move16(); } } @@ -863,7 +893,11 @@ void tcx_ltp_encode_fx( Word16 tcxltp_on, { FOR( n = L_subfr; n < L_frame; n++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + speech_ltp[n] = sub_sat( speech[n], mult( *gain, pred_speech[n] ) ); +#else speech_ltp[n] = sub_o( speech[n], mult( *gain, pred_speech[n] ), &Overflow ); +#endif move16(); } } @@ -906,8 +940,10 @@ void tcx_ltp_encode_ivas_fx( Word16 Aest_fx[M + 1]; Word16 exponent; Word16 sqr; +#ifndef ISSUE_1867_replace_overflow_libenc Flag Overflow = 0; move32(); +#endif TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; @@ -1202,7 +1238,11 @@ void tcx_ltp_encode_ivas_fx( FOR( n = 0; n < L_subfr; n++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + speech_ltp_fx[n] = sub_sat( speech_fx[n], mult_r_sat( hTcxEnc->tcxltp_gain, mult_r_sat( alpha_fx, pred_speech_fx[n] ) ) ); +#else speech_ltp_fx[n] = sub_o( speech_fx[n], mult_ro( hTcxEnc->tcxltp_gain, mult_ro( alpha_fx, pred_speech_fx[n], &Overflow ), &Overflow ), &Overflow ); +#endif move16(); alpha_fx = add_sat( alpha_fx, step_fx ); } @@ -1252,7 +1292,11 @@ void tcx_ltp_encode_ivas_fx( FOR( n = 0; n < L_subfr; n++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + speech_ltp_fx[n] = add_sat( sub_sat( speech_fx[n], mult_r_sat( hTcxEnc->tcxltp_gain, pred_speech_fx[n] ) ), zir_fx[n] ); +#else speech_ltp_fx[n] = add_o( sub_o( speech_fx[n], mult_ro( hTcxEnc->tcxltp_gain, pred_speech_fx[n], &Overflow ), &Overflow ), zir_fx[n], &Overflow ); +#endif move16(); } } @@ -1270,7 +1314,11 @@ void tcx_ltp_encode_ivas_fx( { FOR( n = L_subfr; n < L_frame; n++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + speech_ltp_fx[n] = sub_sat( speech_fx[n], mult( hTcxEnc->tcxltp_gain, pred_speech_fx[n] ) ); +#else speech_ltp_fx[n] = sub_o( speech_fx[n], mult( hTcxEnc->tcxltp_gain, pred_speech_fx[n] ), &Overflow ); +#endif move16(); } } diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 62ba1cd95e79e49fd38289549661eace59f9f94d..b8f187205de3b3e3ef02d87751b1a40c061dbdc6 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -287,21 +287,31 @@ static void detectLowpassFac( const Word32 *powerSpec, Word16 powerSpec_e, Word1 { Word16 i, tmp; Word32 threshold; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif threshold = 256l /*0.1f * 2*NORM_MDCT_FACTOR Q3*/; /* Q3 */ move32(); BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturation, because threshold is being compared to powerSpec[i] below. */ +#ifdef ISSUE_1867_replace_overflow_libenc + threshold = L_shl_sat( threshold, sub( 28, powerSpec_e ) ); +#else threshold = L_shl_o( threshold, sub( 28, powerSpec_e ), &Overflow ); +#endif IF( rectWin != 0 ) { /* compensate for bad side-lobe attenuation with asymmetric windows */ +#ifdef ISSUE_1867_replace_overflow_libenc + threshold = L_shl_sat( threshold, 1 ); +#else threshold = L_shl_o( threshold, 1, &Overflow ); +#endif } BASOP_SATURATE_WARNING_ON_EVS @@ -2494,9 +2504,11 @@ void tcx_noise_factor_ivas_fx( Word16 att; /* noise level attenuation factor for transient windows */ Word32 xMax; Word16 exp_spQ[N_MAX]; +#if !defined( ISSUE_1867_replace_overflow_libenc ) #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif assert( nTransWidth <= 16 ); @@ -2746,7 +2758,11 @@ void tcx_noise_factor_ivas_fx( tmp4 = BASOP_Util_Divide3232_Scale_newton( Mpy_32_16_1( sqErrorNrg, att ), n, &s ); s = add( add( exp_sqErrorNrg, -15 ), s ); BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1867_replace_overflow_libenc + tmp4 = L_shl_sat( tmp4, s ); +#else tmp4 = L_shl_o( tmp4, s, &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS; } ELSE diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index 05b35813a5bb1efb1a2507cc5e2f7daa65a565cf..ce7a9074db16cd7c24b09d87272484e734ee6d41 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -76,9 +76,11 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, Word16 idx1; Word16 nSubdivisions; Word16 iSubdivisions; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move16(); @@ -125,7 +127,11 @@ Word16 DetectTnsFilt_fx( STnsConfig const *pTnsConfig, /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1867_replace_overflow_libenc + tmp32 = L_sub( L_shl_sat( L_tmp, s_min( 31, sub( shift, 24 - 31 * 2 ) ) ), 3277l /*HLM_MIN_NRG Q7*/ ); +#else tmp32 = L_sub( L_shl_o( L_tmp, s_min( 31, sub( shift, 24 - 31 * 2 ) ), &Overflow ), 3277l /*HLM_MIN_NRG Q7*/ ); +#endif BASOP_SATURATE_WARNING_ON_EVS; /* get pre-shift for autocorrelation */ @@ -441,9 +447,11 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur Word16 idx1; Word16 nSubdivisions; Word16 iSubdivisions; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move16(); @@ -490,7 +498,11 @@ Word16 DetectTnsFilt_ivas_fx( STnsConfig const *pTnsConfig, /* i : TNS Configur /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1867_replace_overflow_libenc + tmp32 = L_sub( L_shl_sat( L_tmp, s_min( 31, sub( shift, 24 - 31 * 2 ) ) ), 3277l /*HLM_MIN_NRG Q7*/ ); +#else tmp32 = L_sub( L_shl_o( L_tmp, s_min( 31, sub( shift, 24 - 31 * 2 ) ), &Overflow ), 3277l /*HLM_MIN_NRG Q7*/ ); +#endif BASOP_SATURATE_WARNING_ON_EVS; /* get pre-shift for autocorrelation */ diff --git a/lib_enc/transition_enc_fx.c b/lib_enc/transition_enc_fx.c index 1d2250526cada0edf8fa464e231c00fd7907fcea..2e63fffec93d2bf2476caa40140ff371866597a1 100644 --- a/lib_enc/transition_enc_fx.c +++ b/lib_enc/transition_enc_fx.c @@ -2204,9 +2204,11 @@ static void gain_trans_enc_fx( ) { Word16 i, imax, istart, tmp16, gain_trans, gscale; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif istart = 0; @@ -2215,11 +2217,19 @@ static void gain_trans_enc_fx( move16(); gscale = 7; move16(); - gain_trans = extract_h( L_shl_o( gain_trans32, 16, &Overflow ) ); /* Q7 */ +#ifdef ISSUE_1867_replace_overflow_libenc + gain_trans = extract_h( L_shl_sat( gain_trans32, 16 ) ); /* Q7 */ +#else + gain_trans = extract_h( L_shl_o( gain_trans32, 16, &Overflow ) ); /* Q7 */ +#endif IF( GT_32( L_abs( gain_trans32 ), 29862L ) ) { +#ifdef ISSUE_1867_replace_overflow_libenc + gain_trans = extract_h( L_shl_sat( gain_trans32, 16 - 3 ) ); /* Q4 */ +#else gain_trans = extract_h( L_shl_o( gain_trans32, 16 - 3, &Overflow ) ); /* Q4 */ +#endif istart = 4; move16(); imax = N_GAIN_TC - 1; @@ -2252,7 +2262,11 @@ static void gain_trans_enc_fx( FOR( i = 0; i < L_SUBFR; i++ ) { /*exc[i] *= (*gain_trans);*/ +#ifdef ISSUE_1867_replace_overflow_libenc + exc[i] = round_fx_sat( L_shl_sat( L_mult( exc[i], gain_trans ), tmp16 ) ); +#else exc[i] = round_fx_o( L_shl_o( L_mult( exc[i], gain_trans ), tmp16, &Overflow ), &Overflow ); +#endif move16(); } @@ -2278,9 +2292,11 @@ void tc_classif_enc_fx( { Word32 temp; Word16 T_op, i; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif T_op = pitch; @@ -2356,7 +2372,11 @@ void tc_classif_enc_fx( L_sum = L_mac_sat( 1L, res[0], res[0] ); FOR( i = 1; i < len; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_sum = L_mac0_sat( L_sum, res[i], res[i] ); +#else L_sum = L_mac0_o( L_sum, res[i], res[i], &Overflow ); +#endif } aver = L_sum; /*Q = 2*Q_new */ move32(); @@ -2369,8 +2389,13 @@ void tc_classif_enc_fx( L_temp1 = Mult_32_16( temp, 8192 ); /* Q=31-exp */ test(); +#ifdef ISSUE_1867_replace_overflow_libenc + IF( GT_32( temp2, L_shl_sat( L_temp2, ( 31 - exp2 ) - ( 31 - exp ) ) ) && + LT_32( aver, L_shl_sat( L_temp1, ( 31 - exp_aver ) - ( 31 - exp ) ) ) ) +#else IF( GT_32( temp2, L_shl_o( L_temp2, ( 31 - exp2 ) - ( 31 - exp ), &Overflow ) ) && LT_32( aver, L_shl_o( L_temp1, ( 31 - exp_aver ) - ( 31 - exp ), &Overflow ) ) ) +#endif { *position = position_tmp; move16(); diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 3591301753b937028e1b5c7dcd2b06150a7c0ac0..9883d9fae5366185dbfa83f79b66104cd0b73ea2 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -208,9 +208,11 @@ static void sign_thr_snr_acc_fx( { /*if( snr >= sign_thr ) */ Word32 L_tmp; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif L_tmp = L_deposit_l( min_snr ); @@ -218,8 +220,13 @@ static void sign_thr_snr_acc_fx( { L_tmp = L_add( L_snr, 0 ); /* Q4 */ } - BASOP_SATURATE_WARNING_OFF_EVS /* may saturate in BASOP */ - *L_snr_sum = L_add_o( *L_snr_sum, L_tmp, &Overflow ); /* Q4 */ + BASOP_SATURATE_WARNING_OFF_EVS /* may saturate in BASOP */ +#ifdef ISSUE_1867_replace_overflow_libenc + *L_snr_sum = L_add_sat( *L_snr_sum, L_tmp ); + /* Q4 */ +#else + *L_snr_sum = L_add_o( *L_snr_sum, L_tmp, &Overflow ); /* Q4 */ +#endif move32(); BASOP_SATURATE_WARNING_ON_EVS } @@ -695,9 +702,11 @@ Word16 wb_vad_fx( Word32 L_accum_ener_H; Word16 vad_bwidth_fx; Word16 last_7k2_coder_type; +#if !defined( ISSUE_1867_replace_overflow_libenc ) #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif if ( hNoiseEst == NULL ) @@ -1043,19 +1052,35 @@ Word16 wb_vad_fx( tmp = shl_sat( snr, 5 ); /* Q8 -> Q13 */ IF( LT_16( i, 2 ) ) { - tmp = add_o( tmp, delta1, &Overflow ); /*Q13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = add_sat( tmp, delta1 ); /*Q13 */ +#else + tmp = add_o( tmp, delta1, &Overflow ); /*Q13 */ +#endif } ELSE IF( LT_16( i, 7 ) ) { - tmp = add_o( tmp, delta2, &Overflow ); /*Q13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = add_sat( tmp, delta2 ); /*Q13 */ +#else + tmp = add_o( tmp, delta2, &Overflow ); /*Q13 */ +#endif } ELSE IF( LT_16( i, 18 ) ) { - tmp = add_o( tmp, delta3, &Overflow ); /*Q13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = add_sat( tmp, delta3 ); /*Q13 */ +#else + tmp = add_o( tmp, delta3, &Overflow ); /*Q13 */ +#endif } ELSE { - tmp = add_o( tmp, delta4, &Overflow ); /*Q13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp = add_sat( tmp, delta4 ); /*Q13 */ +#else + tmp = add_o( tmp, delta4, &Overflow ); /*Q13 */ +#endif } tmp1 = tmp; @@ -1063,7 +1088,11 @@ Word16 wb_vad_fx( sub( 0, 0 ); if ( LT_16( i, 7 ) ) { - tmp1 = add_o( tmp, 3277, &Overflow ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp1 = add_sat( tmp, 3277 ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#else + tmp1 = add_o( tmp, 3277, &Overflow ); /*.4 in Q13 ftmp1 = ftmp + 0.4f; */ +#endif } tmp = s_min( tmp, 16384 ); /* Q13, ftmp = min(ftmp, 2.0f); */ @@ -1147,11 +1176,19 @@ Word16 wb_vad_fx( /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ IF( LT_16( i, 3 ) ) { - L_accum_ener_L = L_add_o( L_accum_ener_L, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_accum_ener_L = L_add_sat( L_accum_ener_L, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ +#else + L_accum_ener_L = L_add_o( L_accum_ener_L, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#endif } ELSE { - L_accum_ener_H = L_add_o( L_accum_ener_H, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_accum_ener_H = L_add_sat( L_accum_ener_H, hNoiseEst->bckr_fx[i] ); /*Q_new+QSCALE */ +#else + L_accum_ener_H = L_add_o( L_accum_ener_H, hNoiseEst->bckr_fx[i], &Overflow ); /*Q_new+QSCALE */ +#endif } /* Identify the outlier band */ @@ -1245,7 +1282,11 @@ Word16 wb_vad_fx( } } /*st_fx->snr_sum_vad_fx = 0.5f * st->snr_sum_vad + 0.5f * snr_sum_ol;*/ +#ifdef ISSUE_1867_replace_overflow_libenc + hVAD->L_snr_sum_vad_fx = L_shr( L_add_sat( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol ), 1 ); /*Q4*/ +#else hVAD->L_snr_sum_vad_fx = L_shr( L_add_o( hVAD->L_snr_sum_vad_fx, L_snr_sum_ol, &Overflow ), 1 ); /*Q4*/ +#endif move32(); /* snr_sum_ol = 10.0f * (float)log10( snr_sum_ol ); */ @@ -1359,7 +1400,11 @@ Word16 wb_vad_fx( thr1_ol = thr1; move16(); L_tmp2 = Msub_32_16( (Word32) 614, L_snr_outlier, 20972 ); /* .6*1024= */ /* 0.6 Q26(Q10 in high word) - Q4*Q21+1 */ - tmp2 = round_fx( L_shl_o( L_tmp2, 14, &Overflow ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#ifdef ISSUE_1867_replace_overflow_libenc + tmp2 = round_fx( L_shl_sat( L_tmp2, 14 ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#else + tmp2 = round_fx( L_shl_o( L_tmp2, 14, &Overflow ) ); /* Q10(high word)+ 14 -16 --> Q8*/ +#endif IF( L_tmp2 > 0 ) { thr1_ol = add( thr1_ol, tmp2 ); /* Q24 >>16 + Q8 */ @@ -1929,9 +1974,11 @@ Word16 wb_vad_ivas_fx( Word16 last_7k2_coder_type; Word16 q_shift, q_ener, q_diff1, q_diff2; Word16 q_L_snr_sum_ol, e_snr, f_snr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 L_msnr_e = 0, L_mssnr_e = 0, L_mssnr_hov_e = 0, L_msnr18_e = 0, L_msnr19_e = 0; move16(); /*L_msnr_e*/ @@ -2397,11 +2444,19 @@ Word16 wb_vad_ivas_fx( /* accumulate background noise energy in bands [0-2] and in bands [3-19]*/ IF( LT_16( i, 3 ) ) { - L_accum_ener_L = L_add_o( L_accum_ener_L, hNoiseEst->bckr_fx[i], &Overflow ); /* hNoiseEst->q_bckr */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_accum_ener_L = L_add_sat( L_accum_ener_L, hNoiseEst->bckr_fx[i] ); /* hNoiseEst->q_bckr */ +#else + L_accum_ener_L = L_add_o( L_accum_ener_L, hNoiseEst->bckr_fx[i], &Overflow ); /* hNoiseEst->q_bckr */ +#endif } ELSE { - L_accum_ener_H = L_add_o( L_accum_ener_H, hNoiseEst->bckr_fx[i], &Overflow ); /*hNoiseEst->q_bckr */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_accum_ener_H = L_add_sat( L_accum_ener_H, hNoiseEst->bckr_fx[i] ); /*hNoiseEst->q_bckr */ +#else + L_accum_ener_H = L_add_o( L_accum_ener_H, hNoiseEst->bckr_fx[i], &Overflow ); /*hNoiseEst->q_bckr */ +#endif } /* Identify the outlier band */ @@ -2414,8 +2469,12 @@ Word16 wb_vad_ivas_fx( move16(); move16(); } - } /* end of band loop */ - L_snr_sum_HE_SAD = L_shl_o( L_snr_sum_HE_SAD, sub( 4, q_snr_sum_HE_SAD ), &Overflow ); // q_snr_sum_HE_SAD->q4 + } /* end of band loop */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_snr_sum_HE_SAD = L_shl_sat( L_snr_sum_HE_SAD, sub( 4, q_snr_sum_HE_SAD ) ); // q_snr_sum_HE_SAD->q4 +#else + L_snr_sum_HE_SAD = L_shl_o( L_snr_sum_HE_SAD, sub( 4, q_snr_sum_HE_SAD ), &Overflow ); // q_snr_sum_HE_SAD->q4 +#endif snr_sumt = extract_h( L_shl( L_snr_sumt, Q4 ) ); // Q16 -> Q4 diff --git a/lib_enc/vad_param_updt_fx.c b/lib_enc/vad_param_updt_fx.c index 464903a03a6b45a7e9e241b4c900901bd290b801..8cafb40da2e7edc026b6c10d8dc8c001c37b0d0a 100644 --- a/lib_enc/vad_param_updt_fx.c +++ b/lib_enc/vad_param_updt_fx.c @@ -34,9 +34,11 @@ void vad_param_updt_fx( Word16 i, ini_frame, corr_shift_temp[2]; VAD_HANDLE hVAD; DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif corr_shift_temp[0] = corr_shift; /*Q15*/ @@ -164,9 +166,14 @@ void vad_param_updt_fx( /* (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift */ L_tmp = L_mult( st_fx->voicing_fx[0], 10923 ); L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 ); - L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 ); /*Q15 */ + L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 ); /*Q15 */ +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, corr_shift_temp[i], 32767 ); /*Q15 */ + voice_tmp = round_fx_sat( L_tmp ); /*Q15 */ +#else L_tmp = L_mac_o( L_tmp, corr_shift_temp[i], 32767, &Overflow ); /*Q15 */ voice_tmp = round_fx_o( L_tmp, &Overflow ); /*Q15 */ +#endif /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */ pitch_tmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) ); /*Q0 */ diff --git a/lib_enc/vbr_average_rate_fx.c b/lib_enc/vbr_average_rate_fx.c index 28371b2d716d2cd26f8cba81e5bdc40929ed02cb..907b30209a3f9a17fac53992800f9b690e7d2b4c 100644 --- a/lib_enc/vbr_average_rate_fx.c +++ b/lib_enc/vbr_average_rate_fx.c @@ -49,9 +49,11 @@ void update_average_rate_fx( Word16 tmp; Word32 L_tmp; Word32 L_tmp1, L_tmp2; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 exp, recip, Qrecip; @@ -258,7 +260,11 @@ void update_average_rate_fx( /* sum the total number of bits (in kbytes) * 10 here */ /*st->sum_of_rates += (hSC_VBR->core_brate / 1000.0f) * 10; */ L_tmp = L_shl( Mult_32_16( core_brate_fx, 20972 ), 7 ); /*Q13*/ +#ifdef ISSUE_1867_replace_overflow_libenc + hSC_VBR->sum_of_rates_fx = L_add_sat( hSC_VBR->sum_of_rates_fx, L_tmp ); +#else hSC_VBR->sum_of_rates_fx = L_add_o( hSC_VBR->sum_of_rates_fx, L_tmp, &Overflow ); +#endif move32(); return; } diff --git a/lib_enc/vlpc_2st_cod_fx.c b/lib_enc/vlpc_2st_cod_fx.c index 2ea4df5a991b85e437dfbd9b55c4367637077a2d..3f56add3986225e0cede5f6931e97488e3b150df 100644 --- a/lib_enc/vlpc_2st_cod_fx.c +++ b/lib_enc/vlpc_2st_cod_fx.c @@ -30,10 +30,12 @@ Word16 vlpc_2st_cod_fx( /* output: number of allocated bits Word16 nq, xq[M]; Word32 L_tmp; Word16 gap; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /* 0 bit with true weighting: save 0.5 bit */ @@ -57,7 +59,11 @@ Word16 vlpc_2st_cod_fx( /* output: number of allocated bits BASOP_SATURATE_WARNING_OFF_EVS /* Allow saturate because we only need to know if the result is smaller than 8.0f */ FOR( i = 1; i < M; i++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + L_tmp = L_mac_sat( L_tmp, x[i], x[i] ); /*10Q21*/ +#else L_tmp = L_mac_o( L_tmp, x[i], x[i], &Overflow ); /*10Q21*/ +#endif } BASOP_SATURATE_WARNING_ON_EVS diff --git a/lib_enc/voiced_enc_fx.c b/lib_enc/voiced_enc_fx.c index be1272c2a6c8f27d483c3192bb4e6cb86150a00e..ff40bce29bece5f64368f8848ca8bf5d29d8a558 100644 --- a/lib_enc/voiced_enc_fx.c +++ b/lib_enc/voiced_enc_fx.c @@ -122,9 +122,11 @@ ivas_error ppp_voiced_encoder_fx( Word32 low_band_en_fx; Word32 curr_Engy, prev_Engy; Word16 temp_Fs; +#if !defined( ISSUE_1867_replace_overflow_libenc ) #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif DTFS_STRUCTURE *CURRP_NQ_FX; DTFS_STRUCTURE *TMPDTFS_FX; @@ -563,7 +565,11 @@ ivas_error ppp_voiced_encoder_fx( /*if ( res_enratio > 5.0 && tmp < 0.65 ) */ /* 5 in Q11, 0.65 in Q15 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q31 */ test(); +#ifdef ISSUE_1867_replace_overflow_libenc + if ( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl_sat( tmp_fx, sub( 31, Qtmp ) ) ), 21299 ) ) ) +#else if ( ( GT_32( res_enratio_fx, 10240 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 31, Qtmp ), &Overflow ) ), 21299 ) ) ) +#endif { PPP_MODE_E = 'B'; move16(); @@ -574,7 +580,11 @@ ivas_error ppp_voiced_encoder_fx( /* if ( res_enratio > 3.0 && tmp < 1.2 ) */ /*3 in Q11, 1.2 in Q14 // L_shl(tmp_fx,sub(31,Qtmp)) makes tmp_fx FIXED Q14 */ test(); +#ifdef ISSUE_1867_replace_overflow_libenc + if ( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl_sat( tmp_fx, sub( 30, Qtmp ) ) ), 19661 ) ) ) +#else if ( ( GT_32( res_enratio_fx, 6144 ) ) && ( LT_16( extract_h( L_shl_o( tmp_fx, sub( 30, Qtmp ), &Overflow ) ), 19661 ) ) ) +#endif { PPP_MODE_E = 'B'; move16(); @@ -588,7 +598,12 @@ ivas_error ppp_voiced_encoder_fx( IF( LT_16( shl_sat( hSC_VBR->vadsnr_fx, 1 ), hSC_VBR->SNR_THLD_fx ) ) /*Q8 */ { /* if (res_enratio < 0.025) */ - IF( LT_32( L_shl_o( res_enratio_fx, 4, &Overflow ), 819 ) ) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ +#ifdef ISSUE_1867_replace_overflow_libenc + IF( LT_32( L_shl_sat( res_enratio_fx, 4 ), 819 ) ) + /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ +#else + IF( LT_32( L_shl_o( res_enratio_fx, 4, &Overflow ), 819 ) ) /*0x0333 = 0.025 in Q15, res_enratio_fx in Q15 after shl 4 */ +#endif { hSC_VBR->bump_up = 1; move16(); @@ -604,7 +619,11 @@ ivas_error ppp_voiced_encoder_fx( ELSE { /* if ( res_enratio < 0.092f) */ +#ifdef ISSUE_1867_replace_overflow_libenc + if ( LT_32( L_shl_sat( res_enratio_fx, 4 ), 3015 ) ) /*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ +#else if ( LT_32( L_shl_o( res_enratio_fx, 4, &Overflow ), 3015 ) ) /*3015 = 0.092 in Q15, res_enratio_fx in Q15 after shl 4 */ +#endif { hSC_VBR->bump_up = 1; move16(); @@ -613,7 +632,12 @@ ivas_error ppp_voiced_encoder_fx( /* if (min(res_enratio, sp_enratio) < 0.075 && tmp < -0.5f)) : 2458 = 0.075 in Q15 */ test(); +#ifdef ISSUE_1867_replace_overflow_libenc + if ( LT_32( L_min( L_shl_sat( res_enratio_fx, 4 ), sp_enratio_fx ), 2458 ) && LT_32( tmp_fx, shl_sat( -1, sub( Qtmp, 1 ) ) ) ) +#else + if ( LT_32( L_min( L_shl_o( res_enratio_fx, 4, &Overflow ), sp_enratio_fx ), 2458 ) && LT_32( tmp_fx, shl_sat( -1, sub( Qtmp, 1 ) ) ) ) +#endif { hSC_VBR->bump_up = 1; move16(); @@ -732,7 +756,11 @@ ivas_error ppp_voiced_encoder_fx( Ltemp1 = L_negate( Ltemp1 ); } expa = norm_l( Ltemp2 ); +#ifdef ISSUE_1867_replace_overflow_libenc + fraca = extract_h( L_shl( Ltemp2, expa ) ); +#else fraca = extract_h( L_shl_o( Ltemp2, expa, &Overflow ) ); +#endif expa = sub( 30, expa ); expb = norm_l( Ltemp1 ); @@ -745,7 +773,11 @@ ivas_error ppp_voiced_encoder_fx( tmp = div_s( fracb, fraca ); exp = sub( expb, expa ); +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp_fx = L_shl_sat( tmp, add( exp, 14 ) ); +#else Ltemp_fx = L_shl_o( tmp, add( exp, 14 ), &Overflow ); +#endif /*-------------------------------------------*/ sp_hb_enratio_fx = L_add( Ltemp_fx, 0 ); /* Q29 */ } @@ -769,7 +801,11 @@ ivas_error ppp_voiced_encoder_fx( move32(); Qadj = sub( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_NQ_FX->Q, 1 ) ); +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp_32 = L_shl_sat( Ltmp_32, Qadj ); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ +#else Ltmp_32 = L_shl_o( Ltmp_32, Qadj, &Overflow ); /* shift left required to adjust Q of CURRP_NQ_FX = Q_prev_cw_en_fx */ +#endif /* Ltmp1_32 = 0.8f * st->prev_cw_en */ Ltmp1_32 = Mult_32_16( hSC_VBR->prev_cw_en_fx, 26214 ); /* Q = (Q_prev_cw_en_fx + Q15+1)-Q16 = Q_prev_cw_en_fx */ @@ -874,7 +910,11 @@ ivas_error ppp_voiced_encoder_fx( /* compute energy of impz */ FOR( x_fx = 0; x_fx < 160; x_fx++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + energy_impz_fx = L_add_sat( energy_impz_fx, L_mult0( impzo_fx[x_fx], impzo_fx[x_fx] ) ); +#else energy_impz_fx = L_add_o( energy_impz_fx, L_mult0( impzo_fx[x_fx], impzo_fx[x_fx] ), &Overflow ); +#endif } /*energy_impz = (float)(10*log10((float)energy_impz)); */ @@ -888,7 +928,11 @@ ivas_error ppp_voiced_encoder_fx( Ltmp_32 = DTFS_getEngy_fx( CURRP_Q_E_FX ); /*Q = 2*(CURRP_Q_E_FX->Q) */ move32(); Qadj = sub( hSC_VBR->Q_prev_cw_en_fx, shl( CURRP_Q_E_FX->Q, 1 ) ); - Ltmp_32 = L_shl_o( Ltmp_32, Qadj, &Overflow ); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltmp_32 = L_shl_sat( Ltmp_32, Qadj ); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ +#else + Ltmp_32 = L_shl_o( Ltmp_32, Qadj, &Overflow ); /* shift left required to adjust Q of CURRP_Q_E_FX = Q_prev_cw_en_fx */ +#endif /* if ((DTFS_getEngy(*CURRP_Q_E) > st->prev_cw_en)&&(max(pos_q,neg_q)>3.5) && energy_impz>15.0 && tmpres>0.7) */ test(); test(); @@ -950,9 +994,13 @@ ivas_error ppp_voiced_encoder_fx( fracb = shl( fracb, scale ); expb = sub( expb, scale ); - tmp = div_s( fracb, fraca ); /* tmp in Q15 */ - exp = sub( expb, expa ); /* ans = tmp*2^(exp) */ - Ltemp_fx = L_shl_o( tmp, add( exp, 12 ), &Overflow ); /* make tmp Q27 */ + tmp = div_s( fracb, fraca ); /* tmp in Q15 */ + exp = sub( expb, expa ); /* ans = tmp*2^(exp) */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp_fx = L_shl_sat( tmp, add( exp, 12 ) ); /* make tmp Q27 */ +#else + Ltemp_fx = L_shl_o( tmp, add( exp, 12 ), &Overflow ); /* make tmp Q27 */ +#endif } test(); IF( GT_32( Ltemp_fx, 6710886 ) && ( !hSC_VBR->rate_control ) ) /* 0.05 in Q27 = 6710886 */ @@ -988,7 +1036,11 @@ ivas_error ppp_voiced_encoder_fx( tmp = div_s( fracb, fraca ); exp = sub( expb, expa ); +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp_fx = L_shl_sat( tmp, add( exp, 14 ) ); /* answer in Q29 */ +#else Ltemp_fx = L_shl_o( tmp, add( exp, 14 ), &Overflow ); /* answer in Q29 */ +#endif } /*-------------------------------------------*/ @@ -1055,8 +1107,12 @@ ivas_error ppp_voiced_encoder_fx( L_tmp = L_shl( L_tmp, expa ); exp = sub( 30, add( expa, sub( 31, exp ) ) ); frac = Log2_norm_lc( L_tmp ); - L_tmp = Mpy_32_16( exp, frac, 12330 ); /* L_tmp is always Q13 */ - Ltemp = L_shl_o( L_tmp, 10, &Overflow ); /* Ltemp is always Q23 */ + L_tmp = Mpy_32_16( exp, frac, 12330 ); /* L_tmp is always Q13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + Ltemp = L_shl_sat( L_tmp, 10 ); /* Ltemp is always Q23 */ +#else + Ltemp = L_shl_o( L_tmp, 10, &Overflow ); /* Ltemp is always Q23 */ +#endif } ELSE { @@ -1239,9 +1295,11 @@ static void synthesis_filter_fx( Word16 b[], Word16 x[], Word16 y[], Word16 buf[ { Word32 acc; Word16 i, j; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif FOR( i = 0; i < N; i++ ) { @@ -1251,17 +1309,29 @@ static void synthesis_filter_fx( Word16 b[], Word16 x[], Word16 y[], Word16 buf[ FOR( j = P - 1; j > 0; j-- ) { /* acc = L_sub(acc, L_mult(memory[j], coef[j])); */ - acc = L_msu_o( acc, buf[j], b[j], &Overflow ); /*Q13 */ +#ifdef ISSUE_1867_replace_overflow_libenc + acc = L_msu_sat( acc, buf[j], b[j] ); /*Q13 */ +#else + acc = L_msu_o( acc, buf[j], b[j], &Overflow ); /*Q13 */ +#endif buf[j] = buf[j - 1]; move16(); } /* acc = L_sub(acc, L_mult(memory[0], coef[0])); */ +#ifdef ISSUE_1867_replace_overflow_libenc + acc = L_msu_sat( acc, buf[0], b[0] ); + acc = L_shl_sat( acc, 3 ); + *y++ = round_fx_sat( acc ); + buf[0] = round_fx_sat( acc ); +#else acc = L_msu_o( acc, buf[0], b[0], &Overflow ); acc = L_shl_o( acc, 3, &Overflow ); *y++ = round_fx_o( acc, &Overflow ); - move16(); + buf[0] = round_fx_o( acc, &Overflow ); +#endif + move16(); move16(); } } @@ -1305,9 +1375,11 @@ static Word32 DTFS_freq_corr_fx( Word16 exp, tmp; Word32 L_tmp; Word16 Q_num, Q_den; +#if !defined( ISSUE_1867_replace_overflow_libenc ) #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif IF( LT_16( X1_DTFS_fx.lag_fx, X2_DTFS_fx.lag_fx ) ) { @@ -1343,8 +1415,13 @@ static Word32 DTFS_freq_corr_fx( FOR( k = lk; k < hk; k++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + corr_fx = L_mac0_sat( corr_fx, X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k] ); /* Q(1) */ + corr_fx = L_mac0_sat( corr_fx, X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k] ); /* Q(1) */ +#else corr_fx = L_mac0_o( corr_fx, X1_DTFS_fx.a_fx[k], X2_DTFS_fx.a_fx[k], &Overflow ); /* Q(1) */ corr_fx = L_mac0_o( corr_fx, X1_DTFS_fx.b_fx[k], X2_DTFS_fx.b_fx[k], &Overflow ); /* Q(1) */ +#endif } Qr = norm_l( corr_fx ); @@ -1354,8 +1431,12 @@ static Word32 DTFS_freq_corr_fx( move16(); } - E1_fx = round_fx_o( L_shl_o( corr_fx, Qr, &Overflow ), &Overflow ); /* Q(Qr-16) */ - Num = L_mult0( E1_fx, E1_fx ); /* Q(2+2*Qr-32+1) */ +#ifdef ISSUE_1867_replace_overflow_libenc + E1_fx = round_fx_sat( L_shl_sat( corr_fx, Qr ) ); /* Q(Qr-16) */ +#else + E1_fx = round_fx_o( L_shl_o( corr_fx, Qr, &Overflow ), &Overflow ); /* Q(Qr-16) */ +#endif + Num = L_mult0( E1_fx, E1_fx ); /* Q(2+2*Qr-32+1) */ Q_num = sub( shl( add( add( X1_DTFS_fx.Q, X2_DTFS_fx.Q ), Qr ), 1 ), 32 ); /* PORTING: Handling the functions with variable no. of arguments */ @@ -1368,7 +1449,11 @@ static Word32 DTFS_freq_corr_fx( move16(); } - E1_fx = round_fx_o( L_shl_o( E_fx, q1, &Overflow ), &Overflow ); /* Q(1+q1-16) */ +#ifdef ISSUE_1867_replace_overflow_libenc + E1_fx = round_fx_sat( L_shl_sat( E_fx, q1 ) ); /* Q(1+q1-16) */ +#else + E1_fx = round_fx_o( L_shl_o( E_fx, q1, &Overflow ), &Overflow ); /* Q(1+q1-16) */ +#endif /* PORTING: Handling the functions with variable no. of arguments */ E_fx = DTFS_getEngy_band_fx( X2_DTFS_fx, lband, hband ); /* Q(1) */ q2 = norm_l( E_fx ); @@ -1378,8 +1463,12 @@ static Word32 DTFS_freq_corr_fx( move16(); } - E2_fx = round_fx_o( L_shl_o( E_fx, q2, &Overflow ), &Overflow ); /* Q(1+q2-16) */ - Den = L_mult0( E1_fx, E2_fx ); /* Q(2+q1+q2-32+1) */ +#ifdef ISSUE_1867_replace_overflow_libenc + E2_fx = round_fx_sat( L_shl_sat( E_fx, q2 ) ); /* Q(1+q2-16) */ +#else + E2_fx = round_fx_o( L_shl_o( E_fx, q2, &Overflow ), &Overflow ); /* Q(1+q2-16) */ +#endif + Den = L_mult0( E1_fx, E2_fx ); /* Q(2+q1+q2-32+1) */ Q_den = sub( add( shl( add( X2_DTFS_fx.Q, X1_DTFS_fx.Q ), 1 ), add( q1, q2 ) ), 32 ); Num = L_max( Num, 1 ); @@ -1395,12 +1484,20 @@ static Word32 DTFS_freq_corr_fx( { expa = norm_l( Num ); +#ifdef ISSUE_1867_replace_overflow_libenc + fraca = extract_h( L_shl_sat( Num, expa ) ); +#else fraca = extract_h( L_shl_o( Num, expa, &Overflow ) ); +#endif expa = sub( 30, add( expa, Q_num ) ); expb = norm_l( Den ); +#ifdef ISSUE_1867_replace_overflow_libenc + fracb = round_fx_sat( L_shl( Den, expb ) ); +#else fracb = round_fx_o( L_shl_o( Den, expb, &Overflow ), &Overflow ); +#endif expb = sub( 30, add( expb, Q_den ) ); @@ -1449,9 +1546,11 @@ static Word16 DTFS_alignment_extract_td_fx( Word16 *x1, Word16 *x2, Word16 lag ) { Word16 j, k, idx, Adiff_fx; Word32 maxcorr, corr; +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif maxcorr = L_add( MIN_32, 0 ); Adiff_fx = (Word16) ( s_max( 4, shr( lag, 3 ) ) ); @@ -1463,7 +1562,11 @@ static Word16 DTFS_alignment_extract_td_fx( Word16 *x1, Word16 *x2, Word16 lag ) corr = L_deposit_l( 0 ); FOR( k = 0; k < lag; k++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + corr = L_mac_sat( corr, x1[k], x2[( k - j + lag ) % lag] ); +#else corr = L_mac_o( corr, x1[k], x2[( k - j + lag ) % lag], &Overflow ); +#endif } IF( GT_32( corr, maxcorr ) ) { @@ -1506,9 +1609,11 @@ static Word32 DTFS_getEngy_band_fx( Word32 freq_fx, L_lband, L_hband; Word32 en_fx = 0; move32(); +#ifndef ISSUE_1867_replace_overflow_libenc #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif L_lband = L_mult( lband, X_fx.lag_fx ); /* Q0 * Q0 -> Q1 */ L_hband = L_mult( hband, X_fx.lag_fx ); /* Q0 * Q0 -> Q1 */ @@ -1537,8 +1642,13 @@ static Word32 DTFS_getEngy_band_fx( FOR( k = lk; k < hk; k++ ) { +#ifdef ISSUE_1867_replace_overflow_libenc + en_fx = L_mac0_sat( en_fx, X_fx.a_fx[k], X_fx.a_fx[k] ); /* 2*X1.Q+1 */ + en_fx = L_mac0_sat( en_fx, X_fx.b_fx[k], X_fx.b_fx[k] ); +#else en_fx = L_mac0_o( en_fx, X_fx.a_fx[k], X_fx.a_fx[k], &Overflow ); /* 2*X1.Q+1 */ en_fx = L_mac0_o( en_fx, X_fx.b_fx[k], X_fx.b_fx[k], &Overflow ); +#endif } if ( lband == 0 ) @@ -1550,8 +1660,13 @@ static Word32 DTFS_getEngy_band_fx( test(); IF( ( s_and( X_fx.lag_fx, 1 ) == 0 ) && ( hband == X_fx.upper_cut_off_freq_fx ) ) { +#ifdef ISSUE_1867_replace_overflow_libenc + en_fx = L_mac0_sat( en_fx, X_fx.a_fx[k], X_fx.a_fx[k] ); + en_fx = L_mac0_sat( en_fx, X_fx.b_fx[k], X_fx.b_fx[k] ); +#else en_fx = L_mac0_o( en_fx, X_fx.a_fx[k], X_fx.a_fx[k], &Overflow ); en_fx = L_mac0_o( en_fx, X_fx.b_fx[k], X_fx.b_fx[k], &Overflow ); +#endif } return en_fx; /* 2*X1.Q */