Skip to content
......@@ -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,
......@@ -783,8 +785,13 @@ static void gethar_noisegn_fx(
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 */
#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;
......
......@@ -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 */
#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*/ ) )
......@@ -2555,11 +2580,19 @@ void swb_tbe_enc_fx(
FOR( ; i < L_SHB_LAHEAD + 10; i++ )
{
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 */
#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 ) );
#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 */
#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();
}
}
......@@ -2803,7 +2844,11 @@ void swb_tbe_enc_fx(
/* 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 */
#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;
......@@ -3853,7 +3900,11 @@ 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) */
#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 )
......@@ -3871,11 +3922,19 @@ 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 */
#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 */
#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 ) );
#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 */
#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();
}
}
......@@ -4397,7 +4464,11 @@ void swb_tbe_enc_ivas_fx(
/* 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 */
#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++ )
{
#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++ )
{
#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++ )
{
#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_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++ )
{
#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++ )
{
#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_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();
......@@ -5129,25 +5276,43 @@ static void EstimateSHBGainShape_fx(
FOR( k = 0; k < length; k++ )
{
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 */
#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 */
#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_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++ )
{
#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();
}
......@@ -5210,7 +5380,11 @@ 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) */
#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();
}
}
......@@ -5219,7 +5393,11 @@ 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) */
#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,7 +7058,11 @@ static void first_VQstages_fx(
L_tmp = L_deposit_l( 0 );
FOR( j = 0; j < N; j++ )
{
#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 */
}
......@@ -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++ )
......@@ -7406,7 +7592,11 @@ void fb_tbe_enc_fx(
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 */
#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 */
#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) */
......
......@@ -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();
}
}
......
......@@ -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
......
......@@ -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 */
......
......@@ -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();
#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();
......
......@@ -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 );
......@@ -219,7 +221,12 @@ static void sign_thr_snr_acc_fx(
L_tmp = L_add( L_snr, 0 ); /* 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 ) )
{
#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 ) )
{
#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 ) )
{
#ifdef ISSUE_1867_replace_overflow_libenc
tmp = add_sat( tmp, delta3 ); /*Q13 */
#else
tmp = add_o( tmp, delta3, &Overflow ); /*Q13 */
#endif
}
ELSE
{
#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 ) )
{
#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 ) )
{
#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
{
#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 */
#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 ) )
{
#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
{
#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 */
......@@ -2415,7 +2470,11 @@ Word16 wb_vad_ivas_fx(
move16();
}
} /* 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
......
......@@ -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*/
......@@ -165,8 +167,13 @@ void vad_param_updt_fx(
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 */
#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 */
......
......@@ -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;
}
......@@ -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
......
......@@ -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) */
#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 ) );
#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();
......@@ -952,7 +996,11 @@ ivas_error ppp_voiced_encoder_fx(
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
}
/*-------------------------------------------*/
......@@ -1056,7 +1108,11 @@ ivas_error ppp_voiced_encoder_fx(
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 */
#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])); */
#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,7 +1431,11 @@ static Word32 DTFS_freq_corr_fx(
move16();
}
#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 );
......@@ -1368,7 +1449,11 @@ static Word32 DTFS_freq_corr_fx(
move16();
}
#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,7 +1463,11 @@ static Word32 DTFS_freq_corr_fx(
move16();
}
#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 );
......@@ -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 */
......