Skip to content
...@@ -64,9 +64,11 @@ void encod_amr_wb_fx( ...@@ -64,9 +64,11 @@ void encod_amr_wb_fx(
AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO; AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO;
BSTR_ENC_HANDLE hBstr = st->hBstr; BSTR_ENC_HANDLE hBstr = st->hBstr;
LPD_state_HANDLE hLPDmem = st->hLPDmem; LPD_state_HANDLE hLPDmem = st->hLPDmem;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*------------------------------------------------------------------* /*------------------------------------------------------------------*
...@@ -190,14 +192,23 @@ void encod_amr_wb_fx( ...@@ -190,14 +192,23 @@ void encod_amr_wb_fx(
&gain_inov, &norm_gain_code, g_corr, clip_gain, hAmrwb_IO->past_qua_en_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 ); gp_clip_test_gain_pit_fx( st->element_mode, st->core_brate, gain_pit, st->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 ); /*Q0*/
#else
Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/ Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/
#endif
hLPDmem->tilt_code = Est_tilt2( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); /*Q15*/ hLPDmem->tilt_code = Est_tilt2( exc + i_subfr, gain_pit, code, Lgcode, &voice_fac, shift ); /*Q15*/
FOR( i = 0; i < L_SUBFR; i++ ) 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*/ 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(); move16();
} }
...@@ -224,8 +235,13 @@ void encod_amr_wb_fx( ...@@ -224,8 +235,13 @@ void encod_amr_wb_fx(
L_tmp = L_mult( gcode16, code[i] ); /*Q10*/ L_tmp = L_mult( gcode16, code[i] ); /*Q10*/
L_tmp = L_shl_sat( L_tmp, 5 ); /*Q15*/ 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_mac_sat( L_tmp, exc[i + i_subfr], gain_pit ); /* Q_new+15 */
#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*/ 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*/ exc[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /*Q_new*/
#endif
move16(); move16();
} }
......
...@@ -144,9 +144,11 @@ void encod_gen_voic_fx( ...@@ -144,9 +144,11 @@ void encod_gen_voic_fx(
Word16 shift_wsp; Word16 shift_wsp;
Word16 harm_flag_acelp; Word16 harm_flag_acelp;
Word16 lp_select, lp_flag, L_frame; Word16 lp_select, lp_flag, L_frame;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr; BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
...@@ -281,7 +283,11 @@ void encod_gen_voic_fx( ...@@ -281,7 +283,11 @@ void encod_gen_voic_fx(
} }
/*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit_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*/ 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 * Transform domain contribution encoding - active frames
...@@ -333,8 +339,13 @@ void encod_gen_voic_fx( ...@@ -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 ); gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
#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*/ Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
gcode16 = round_fx_o( Lgcode, &Overflow ); /*Q0*/ 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 */ hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr_fx], gain_pit_fx, code_fx, Lgcode, &voice_fac_fx, shift ); /* Q15 */
move16(); move16();
...@@ -370,20 +381,35 @@ void encod_gen_voic_fx( ...@@ -370,20 +381,35 @@ void encod_gen_voic_fx(
FOR( i = 0; i < L_SUBFR; i++ ) FOR( i = 0; i < L_SUBFR; i++ )
{ {
/* Contribution from AVQ layer */ /* Contribution from AVQ layer */
#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_mult_o( gain_preQ_fx, code_preQ_fx[i], &Overflow ); /* Q2 + Q6 -> Q9*/
Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */ Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); /* Q16 + Q_exc */
#endif
/* Compute exc2 */ /* Compute exc2 */
#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 */ 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 */ exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */
#endif
move16(); move16();
/* code in Q9, gain_pit in Q14 */ /* code in Q9, gain_pit in Q14 */
Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */
Ltmp = L_shl( Ltmp, 5 ); /* Q15 */ Ltmp = L_shl( Ltmp, 5 ); /* Q15 */
Ltmp = L_mac( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx ); /* 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*/ 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 */ exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow ); /* Q0 */
#endif
} }
} }
ELSE ELSE
...@@ -397,10 +423,17 @@ void encod_gen_voic_fx( ...@@ -397,10 +423,17 @@ void encod_gen_voic_fx(
{ {
/* code in Q9, gain_pit in Q14 */ /* code in Q9, gain_pit in Q14 */
Ltmp = L_mult( gcode16, code_fx[i] ); /* Q10 */ 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_shl_o( Ltmp, 5, &Overflow ); /* Q15 */
Ltmp = L_mac_o( Ltmp, exc_fx[i + i_subfr_fx], gain_pit_fx, &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*/ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /* saturation can occur here Q16*/
exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */ exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); /* Q0 */
#endif
} }
} }
...@@ -509,9 +542,11 @@ void encod_gen_voic_ivas_fx( ...@@ -509,9 +542,11 @@ void encod_gen_voic_ivas_fx(
Word16 harm_flag_acelp; Word16 harm_flag_acelp;
Word16 lp_select, lp_flag, L_frame; Word16 lp_select, lp_flag, L_frame;
Word16 q_h1; Word16 q_h1;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr; BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
...@@ -706,8 +741,13 @@ void encod_gen_voic_ivas_fx( ...@@ -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 ); gp_clip_test_gain_pit_fx( st_fx->element_mode, st_fx->core_brate, gain_pit_fx, st_fx->clip_var_fx );
#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*/ Lgcode = L_shl_o( gain_code_fx, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
gcode16 = round_fx_o( Lgcode, &Overflow ); 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 */ 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(); move16();
...@@ -758,20 +798,35 @@ void encod_gen_voic_ivas_fx( ...@@ -758,20 +798,35 @@ void encod_gen_voic_ivas_fx(
FOR( i = 0; i < L_SUBFR; i++ ) FOR( i = 0; i < L_SUBFR; i++ )
{ {
/* Contribution from AVQ layer */ /* 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_mult_o( gain_preQ_fx, code_preQ_fx[i], &Overflow );
Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow ); Ltmp1 = L_shl_o( Ltmp1, tmp1_fx, &Overflow );
#endif
/* Compute exc2 */ /* 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 ); 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 ); exc2_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow );
#endif
move16(); move16();
/* code in Q9, gain_pit in Q14 */ /* code in Q9, gain_pit in Q14 */
Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */ Ltmp = L_mult( gcode16, code_fx[i] ); /*Qnew + 9 + 1 */
Ltmp = L_shl( Ltmp, 5 ); /*Qnew + 9+ 1+5 */ 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_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*/ 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 ); exc_fx[i + i_subfr_fx] = round_fx_o( L_add_o( Ltmp, Ltmp1, &Overflow ), &Overflow );
#endif
move16(); move16();
} }
} }
...@@ -787,10 +842,17 @@ void encod_gen_voic_ivas_fx( ...@@ -787,10 +842,17 @@ void encod_gen_voic_ivas_fx(
/* code in Q9, gain_pit in Q14 */ /* code in Q9, gain_pit in Q14 */
/*gcode16 in Qnew*/ /*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_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_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 */ Ltmp = L_shl_o( Ltmp, 1, &Overflow ); /*Qnew + 14 + 1 +1 */
exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow ); exc_fx[i + i_subfr_fx] = round_fx_o( Ltmp, &Overflow );
#endif
} }
} }
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
......
...@@ -165,9 +165,11 @@ void coder_acelp_rf_fx( ...@@ -165,9 +165,11 @@ void coder_acelp_rf_fx(
Word16 prev_gain_pit; Word16 prev_gain_pit;
Word16 rf_coder_type; Word16 rf_coder_type;
Word16 lp_select; Word16 lp_select;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
RF_ENC_HANDLE hRF = st->hRF; RF_ENC_HANDLE hRF = st->hRF;
...@@ -441,6 +443,15 @@ void coder_acelp_rf_fx( ...@@ -441,6 +443,15 @@ void coder_acelp_rf_fx(
*-----------------------------------------------------------------*/ *-----------------------------------------------------------------*/
/* st_fx->_rf_mem_w0 = xn[L_SUBFR-1] - (gain_pit*y1[L_SUBFR-1]) - (gain_code*y2[L_SUBFR-1]); */ /* 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_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 */ Ltmp = L_mac_o( Ltmp, y1[L_SUBFR - 1], gain_pit, &Overflow ); /* Q15 + Q_xn */
/* Add Gaussian contribution*/ /* Add Gaussian contribution*/
...@@ -448,6 +459,7 @@ void coder_acelp_rf_fx( ...@@ -448,6 +459,7 @@ void coder_acelp_rf_fx(
Ltmp2 = L_shl_o( Ltmp2, add( 5, Q_xn ), &Overflow ); /* Q15 + Q_xn */ Ltmp2 = L_shl_o( Ltmp2, add( 5, Q_xn ), &Overflow ); /* Q15 + Q_xn */
Ltmp = L_add_o( Ltmp, Ltmp2, &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 */ 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(); move16();
hRF->rf_mem_w0 = shr_sat( hRF->rf_mem_w0, shift ); /*Qnew-1*/ hRF->rf_mem_w0 = shr_sat( hRF->rf_mem_w0, shift ); /*Qnew-1*/
...@@ -463,6 +475,17 @@ void coder_acelp_rf_fx( ...@@ -463,6 +475,17 @@ void coder_acelp_rf_fx(
{ {
/* code in Q9, gain_pit in Q14; exc Q_new */ /* code in Q9, gain_pit in Q14; exc Q_new */
Ltmp = Mpy_32_16_1( gain_code2, code2[i] ); /* Q10 */ 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_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 */ 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 */ exc2[i] = round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ); /* Q_new */
...@@ -472,6 +495,7 @@ void coder_acelp_rf_fx( ...@@ -472,6 +495,7 @@ void coder_acelp_rf_fx(
Ltmp = L_add_o( Ltmp, Ltmp2, &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*/ 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 */ exc_rf[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */
#endif
move16(); move16();
} }
tmp2 = L_SUBFR; tmp2 = L_SUBFR;
......
...@@ -85,7 +85,11 @@ void transf_cdbk_enc_fx( ...@@ -85,7 +85,11 @@ void transf_cdbk_enc_fx(
*--------------------------------------------------------------*/ *--------------------------------------------------------------*/
IF( EQ_16( st_fx->coder_type, INACTIVE ) ) 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 ); gcode16 = round_fx_o( L_shl_o( gain_code, Q_new, &Overflow ), &Overflow );
#endif
FOR( i = 0; i < L_SUBFR; i++ ) FOR( i = 0; i < L_SUBFR; i++ )
{ {
/*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/ /*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/
...@@ -180,7 +184,11 @@ void transf_cdbk_enc_fx( ...@@ -180,7 +184,11 @@ void transf_cdbk_enc_fx(
m_corr = div_s( 16384, m_den ); m_corr = div_s( 16384, m_den );
e_corr = sub( 14 + 4, e_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 */ stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12 */
#endif
} }
ELSE ELSE
{ {
...@@ -435,7 +443,11 @@ void transf_cdbk_enc_ivas_fx( ...@@ -435,7 +443,11 @@ void transf_cdbk_enc_ivas_fx(
*--------------------------------------------------------------*/ *--------------------------------------------------------------*/
IF( EQ_16( st_fx->coder_type, INACTIVE ) ) 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 ); gcode16 = round_fx_o( L_shl_o( gain_code, Q_new, &Overflow ), &Overflow );
#endif
FOR( i = 0; i < L_SUBFR; i++ ) FOR( i = 0; i < L_SUBFR; i++ )
{ {
/*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/ /*x_tran[i] = xn[i] - *gain_pit * y1[i] - gain_code * y2[i];*/
...@@ -529,7 +541,11 @@ void transf_cdbk_enc_ivas_fx( ...@@ -529,7 +541,11 @@ void transf_cdbk_enc_ivas_fx(
m_corr = div_s( 16384, m_den ); m_corr = div_s( 16384, m_den );
e_corr = sub( 14 + 4, e_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 */ stmp = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12 */
#endif
} }
ELSE ELSE
{ {
......
...@@ -104,9 +104,11 @@ void enc_pit_exc_fx( ...@@ -104,9 +104,11 @@ void enc_pit_exc_fx(
BSTR_ENC_HANDLE hBstr = st_fx->hBstr; BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*------------------------------------------------------------------* /*------------------------------------------------------------------*
...@@ -295,7 +297,11 @@ void enc_pit_exc_fx( ...@@ -295,7 +297,11 @@ void enc_pit_exc_fx(
} }
/*st_fx->lowrate_pitchGain = 0.9f * st_fx->lowrate_pitchGain + 0.1f * gain_pit;*/ /*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*/ 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; gpit_tmp = gain_pit;
move16(); /*Q14*/ move16(); /*Q14*/
...@@ -374,12 +380,21 @@ void enc_pit_exc_fx( ...@@ -374,12 +380,21 @@ void enc_pit_exc_fx(
IF( use_fcb != 0 ) IF( use_fcb != 0 )
{ {
Ltmp = L_mult( gcode16, y2[L_subfr - 1] ); /* Q10 + Q_new */ 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_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_shl_o( Ltmp, add( 5, shift ), &Overflow ); /* Q15 + Q_new + shift */
Ltmp = L_negate( Ltmp ); Ltmp = L_negate( Ltmp );
Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); /* Q_new + Q15 + shift */ 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_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 */ Ltmp = L_shl_o( Ltmp, sub( 1, shift ), &Overflow ); /* Q_new + 15 */
hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */ hLPDmem->mem_w0 = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */
#endif
move16(); move16();
} }
ELSE ELSE
...@@ -402,10 +417,17 @@ void enc_pit_exc_fx( ...@@ -402,10 +417,17 @@ void enc_pit_exc_fx(
{ {
/* code in Q9, gain_pit in Q14 */ /* 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_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_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*/ 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 */ exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */
#endif
move16(); move16();
} }
} }
...@@ -591,9 +613,11 @@ void enc_pit_exc_ivas_fx( ...@@ -591,9 +613,11 @@ void enc_pit_exc_ivas_fx(
BSTR_ENC_HANDLE hBstr = st_fx->hBstr; BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc; GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
LPD_state_HANDLE hLPDmem = st_fx->hLPDmem; LPD_state_HANDLE hLPDmem = st_fx->hLPDmem;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*------------------------------------------------------------------* /*------------------------------------------------------------------*
...@@ -860,12 +884,21 @@ void enc_pit_exc_ivas_fx( ...@@ -860,12 +884,21 @@ void enc_pit_exc_ivas_fx(
IF( use_fcb != 0 ) IF( use_fcb != 0 )
{ {
Ltmp = L_mult0( gcode16, y2[L_subfr - 1] ); Ltmp = L_mult0( gcode16, y2[L_subfr - 1] );
#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_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_shl_o( Ltmp, add( 5, shift ), &Overflow ); // Q_new+14+shift
Ltmp = L_negate( Ltmp ); Ltmp = L_negate( Ltmp );
Ltmp = L_mac_o( Ltmp, xn[L_subfr - 1], 16384, &Overflow ); // Q_new-1+15+shift 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_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 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 */ hGSCEnc->mem_w0_tmp_fx = round_fx_o( Ltmp, &Overflow ); /*Q_new-1 */
#endif
} }
ELSE ELSE
{ {
...@@ -886,10 +919,17 @@ void enc_pit_exc_ivas_fx( ...@@ -886,10 +919,17 @@ void enc_pit_exc_ivas_fx(
{ {
/* code in Q9, gain_pit in Q14 */ /* 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_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_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 */ 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 */ exc[i + i_subfr] = round_fx_o( Ltmp, &Overflow ); /* Q_new */
#endif
move16(); move16();
} }
} }
......
...@@ -93,9 +93,11 @@ Word16 encod_tran_fx( ...@@ -93,9 +93,11 @@ Word16 encod_tran_fx(
Word16 L_frame_fx; Word16 L_frame_fx;
Word16 shift_wsp; Word16 shift_wsp;
Word32 L_tmp; Word32 L_tmp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
BSTR_ENC_HANDLE hBstr = st_fx->hBstr; BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
...@@ -228,8 +230,13 @@ Word16 encod_tran_fx( ...@@ -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 ); 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*/ Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
gcode16 = round_fx_o( Lgcode, &Overflow ); gcode16 = round_fx_o( Lgcode, &Overflow );
#endif
hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */ hLPDmem->tilt_code = Est_tilt2( &exc_fx[i_subfr], gain_pit, code, Lgcode, &voice_fac, shift ); /* Q15 */
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
* Update memory of the weighting filter * Update memory of the weighting filter
...@@ -278,10 +285,17 @@ Word16 encod_tran_fx( ...@@ -278,10 +285,17 @@ Word16 encod_tran_fx(
{ {
/* code in Q9, gain_pit in Q14 */ /* 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_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_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 */ 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 */ exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /* Q_new */
#endif
} }
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
...@@ -294,13 +308,21 @@ Word16 encod_tran_fx( ...@@ -294,13 +308,21 @@ Word16 encod_tran_fx(
FOR( i = 0; i < L_SUBFR; i++ ) FOR( i = 0; i < L_SUBFR; i++ )
{ {
L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ 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 */ L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */
tmp_fx = round_fx_o( L_tmp, &Overflow ); 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 */ exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
move16(); move16();
exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */ exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
move16(); move16();
#endif
} }
} }
...@@ -467,9 +489,11 @@ Word16 encod_tran_ivas_fx( ...@@ -467,9 +489,11 @@ Word16 encod_tran_ivas_fx(
Word16 shift_wsp; Word16 shift_wsp;
Word32 L_tmp; Word32 L_tmp;
Word16 q_h1; Word16 q_h1;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
BSTR_ENC_HANDLE hBstr = st_fx->hBstr; BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
...@@ -610,8 +634,13 @@ Word16 encod_tran_ivas_fx( ...@@ -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 ); 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*/ Lgcode = L_shl_o( gain_code, Q_new, &Overflow ); /* scaled gain_code with Qnew -> Q16*/
gcode16 = round_fx_o( Lgcode, &Overflow ); 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 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 * Update memory of the weighting filter
...@@ -660,10 +689,17 @@ Word16 encod_tran_ivas_fx( ...@@ -660,10 +689,17 @@ Word16 encod_tran_ivas_fx(
{ {
/* code in Q9, gain_pit in Q14 */ /* 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_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_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 */ 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 */ exc_fx[i + i_subfr] = round_fx_o( L_tmp, &Overflow ); /* Q_new */
#endif
} }
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
...@@ -676,12 +712,21 @@ Word16 encod_tran_ivas_fx( ...@@ -676,12 +712,21 @@ Word16 encod_tran_ivas_fx(
FOR( i = 0; i < L_SUBFR; i++ ) FOR( i = 0; i < L_SUBFR; i++ )
{ {
L_tmp = L_mult( gain_preQ, code_preQ[i] ); /* Q2 + Q10 -> Q13*/ 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 */ L_tmp = L_shl_o( L_tmp, tmp1_fx, &Overflow ); /* Q16 + Q_exc */
tmp_fx = round_fx_o( L_tmp, &Overflow ); 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 */ exc2_fx[i + i_subfr] = add_o( exc2_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
move16(); move16();
exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */ exc_fx[i + i_subfr] = add_o( exc_fx[i + i_subfr], tmp_fx, &Overflow ); /* Q_exc */
#endif
move16(); move16();
} }
} }
......
...@@ -134,7 +134,11 @@ void find_targets_fx( ...@@ -134,7 +134,11 @@ void find_targets_fx(
{ {
Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */ Ltmp = L_msu( Ltmp, Aqs[j], h1[i - j] ); /* Q27 */
} }
#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 */ h1[i] = round_fx( L_shl_o( Ltmp, s, &Overflow ) ); /* Q11 + s */
#endif
} }
Ltmp = L_mult( Ap[i], s2 ); /* Q27 */ Ltmp = L_mult( Ap[i], s2 ); /* Q27 */
FOR( j = 1; j <= M; j++ ) FOR( j = 1; j <= M; j++ )
...@@ -181,9 +185,11 @@ void find_targets_ivas_fx( ...@@ -181,9 +185,11 @@ void find_targets_ivas_fx(
Word32 h1_32[6 * L_SUBFR]; Word32 h1_32[6 * L_SUBFR];
Word16 sf; Word16 sf;
Word64 Ltmp64; Word64 Ltmp64;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move16(); move16();
#endif
#endif #endif
/*------------------------------------------------------------------------* /*------------------------------------------------------------------------*
* Find the target vector for excitation search: * Find the target vector for excitation search:
...@@ -250,14 +256,20 @@ void find_targets_ivas_fx( ...@@ -250,14 +256,20 @@ void find_targets_ivas_fx(
} }
set32_fx( h1_32, 0, L_subfr ); set32_fx( h1_32, 0, L_subfr );
#ifndef ISSUE_1867_replace_overflow_libenc
Overflow = 0; Overflow = 0;
move16(); move16();
#endif
FOR( i = 0; i < M; i++ ) FOR( i = 0; i < M; i++ )
{ {
Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */
FOR( j = 1; j <= i; j++ ) 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 */ 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 */ h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */
move32(); move32();
...@@ -266,17 +278,29 @@ void find_targets_ivas_fx( ...@@ -266,17 +278,29 @@ void find_targets_ivas_fx(
Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */ Ltmp64 = W_mult_16_16( Ap[i], s2 ); /* Q27 */
FOR( j = 1; j <= M; j++ ) FOR( j = 1; 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 */ 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 */ h1_32[M] = W_extract_l( Ltmp64 ); /* Q27 */
move32(); move32();
FOR( i = M + 1; i < L_subfr; i++ ) FOR( i = M + 1; i < L_subfr; i++ )
{ {
#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 */ 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++ ) 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 */ 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 */ h1_32[i] = W_extract_l( Ltmp64 ); /* Q27 */
move32(); move32();
......
...@@ -44,9 +44,11 @@ void find_tilt_fx( ...@@ -44,9 +44,11 @@ void find_tilt_fx(
Word16 scaling; Word16 scaling;
move32(); move32();
move32(); move32();
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
* Initializations * Initializations
...@@ -108,8 +110,13 @@ void find_tilt_fx( ...@@ -108,8 +110,13 @@ void find_tilt_fx(
/*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/
Ltmp = L_mult( voicing[1], 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 */ 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 ); /* Q31 */
mean_voi = round_fx_sat( Ltmp ); /* Q15 */
#else
Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); /* Q31 */ Ltmp = L_mac_o( Ltmp, corr_shift, 32767, &Overflow ); /* Q31 */
mean_voi = round_fx_o( Ltmp, &Overflow ); /* Q15 */ mean_voi = round_fx_o( Ltmp, &Overflow ); /* Q15 */
#endif
/*f0 = INT_FS_FX / pitch[2];*/ /*f0 = INT_FS_FX / pitch[2];*/
e_tmp = norm_s( pitch[2] ); e_tmp = norm_s( pitch[2] );
...@@ -155,13 +162,22 @@ void find_tilt_fx( ...@@ -155,13 +162,22 @@ void find_tilt_fx(
tmp = sub( freq, f2 ); tmp = sub( freq, f2 );
IF( L_mac0( -(Word32) TH_D_FX * TH_D_FX, tmp, tmp ) < 0 ) 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 */ lp_E = L_add_o( *pt_E, lp_E, &Overflow ); /* Q_new + QSCALE - 2 */
#endif
m_cnt = add( m_cnt, 1 ); /* Q0 */ m_cnt = add( m_cnt, 1 ); /* Q0 */
} }
pt_E++; 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 ); f1 = add_o( f1, f0, &Overflow );
f2 = add_o( f2, f0, &Overflow ); f2 = add_o( f2, f0, &Overflow );
#endif
} }
/*lp_E = lp_E / (float)cnt - lp_bckr;*/ /*lp_E = lp_E / (float)cnt - lp_bckr;*/
e_tmp = sub( norm_l( lp_E ), 1 ); e_tmp = sub( norm_l( lp_E ), 1 );
...@@ -175,7 +191,11 @@ void find_tilt_fx( ...@@ -175,7 +191,11 @@ void find_tilt_fx(
m_tmp = div_s( m_tmp, m_cnt ); /* exp(e_tmp + e_cnt) */ m_tmp = div_s( m_tmp, m_cnt ); /* exp(e_tmp + e_cnt) */
e_tmp = sub( 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 */ 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 */ pt_E = tmp_E + VOIC_BINS; /* Update for next half-frame */
} }
...@@ -216,7 +236,11 @@ void find_tilt_fx( ...@@ -216,7 +236,11 @@ void find_tilt_fx(
IF( EQ_16( bwidth, NB ) ) /* For NB input, compensate for the missing bands */ 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 ); Ltmp = L_shl_o( ee[i], 3, &Overflow );
#endif
IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ 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*/ Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/
...@@ -271,9 +295,11 @@ void find_tilt_ivas_fx( ...@@ -271,9 +295,11 @@ void find_tilt_ivas_fx(
Word64 sum; Word64 sum;
Word16 inv_bands, q_lp_E; Word16 inv_bands, q_lp_E;
Word32 Le_min_scaled, Ltmp2; Word32 Le_min_scaled, Ltmp2;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
move32(); move32();
move32(); move32();
...@@ -346,8 +372,13 @@ void find_tilt_ivas_fx( ...@@ -346,8 +372,13 @@ void find_tilt_ivas_fx(
/*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/ /*mean_voi = 0.5f * (voicing[1] + voicing[2]) + corr_shift;*/
Ltmp = L_mult( voicing[1], 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 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 Ltmp = L_mac_o( Ltmp, corr_shift, 32767 /* 1.0f in Q15 */, &Overflow ); // Q31
mean_voi = round_fx_o( Ltmp, &Overflow ); // Q15 mean_voi = round_fx_o( Ltmp, &Overflow ); // Q15
#endif
/*f0 = INT_FS_FX / pitch[2];*/ /*f0 = INT_FS_FX / pitch[2];*/
e_tmp = norm_s( pitch[2] ); e_tmp = norm_s( pitch[2] );
...@@ -399,8 +430,13 @@ void find_tilt_ivas_fx( ...@@ -399,8 +430,13 @@ void find_tilt_ivas_fx(
} }
pt_E++; 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 ); f1 = add_o( f1, f0, &Overflow );
f2 = add_o( f2, f0, &Overflow ); f2 = add_o( f2, f0, &Overflow );
#endif
} }
/*lp_E = lp_E / (float)cnt - lp_bckr;*/ /*lp_E = lp_E / (float)cnt - lp_bckr;*/
e_tmp = sub( W_norm( sum ), 1 ); e_tmp = sub( W_norm( sum ), 1 );
...@@ -468,7 +504,11 @@ void find_tilt_ivas_fx( ...@@ -468,7 +504,11 @@ void find_tilt_ivas_fx(
IF( bwidth == NB ) /* For NB input, compensate for the missing bands */ 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 */ Ltmp = L_shl_o( ee[i], 3, &Overflow ); /* Q6 */
#endif
IF( EQ_32( Ltmp, MAX_32 ) ) /* if Overflow: Compute with less precision */ 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*/ Ltmp = Mult_32_16( ee[i], 24576 /* 0.75 in Q15 */ ); /* 6/8 Q6*/
......
...@@ -115,9 +115,11 @@ Word16 find_uv_fx( /* o : coding type */ ...@@ -115,9 +115,11 @@ Word16 find_uv_fx( /* o : coding type */
Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE; Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE;
NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
Word16 Last_Resort; Word16 Last_Resort;
...@@ -198,7 +200,11 @@ Word16 find_uv_fx( /* o : coding type */ ...@@ -198,7 +200,11 @@ Word16 find_uv_fx( /* o : coding type */
*-----------------------------------------------------------------*/ *-----------------------------------------------------------------*/
/*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ /*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 */ 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_ee = Mult_32_16( mean_ee, 10923 /* 1/3 in Q15 */ ); /*Q6*/
/* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/
...@@ -224,7 +230,11 @@ Word16 find_uv_fx( /* o : coding type */ ...@@ -224,7 +230,11 @@ Word16 find_uv_fx( /* o : coding type */
{ {
dE2_th = 21 << 10; dE2_th = 21 << 10;
move32(); move32();
#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*/ 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; nb_cond = 0;
move16(); move16();
...@@ -303,7 +313,11 @@ Word16 find_uv_fx( /* o : coding type */ ...@@ -303,7 +313,11 @@ Word16 find_uv_fx( /* o : coding type */
test(); test();
if ( ( EQ_16( st_fx->last_coder_type_raw, UNVOICED ) ) || /* previous frame was unvoiced */ 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_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 */
#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 */ ( LT_16( add_o( st_fx->voicing_fx[0], corr_shift, &Overflow ), voi_th ) ) ) ) /* normalized correlation is low */
#endif
{ {
tmp_offset_flag = 0; tmp_offset_flag = 0;
move16(); move16();
...@@ -379,8 +393,13 @@ Word16 find_uv_fx( /* o : coding type */ ...@@ -379,8 +393,13 @@ Word16 find_uv_fx( /* o : coding type */
test(); test();
test(); test();
test(); test();
#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 */ 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_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[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 */ ( 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 */ ( tmp_offset_flag == 0 ) && /* Take care of voiced offsets */
...@@ -408,7 +427,11 @@ Word16 find_uv_fx( /* o : coding type */ ...@@ -408,7 +427,11 @@ Word16 find_uv_fx( /* o : coding type */
test(); test();
test(); 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 */ if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */
#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_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[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 */ ( LT_32( ee[1], 397 /* 6.2f in Q6 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
...@@ -610,9 +633,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ ...@@ -610,9 +633,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ
Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE; Word16 ee0_th, ee1_th, voi_th, nb_cond, flag_low_relE;
NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst; NOISE_EST_HANDLE hNoiseEst = st_fx->hNoiseEst;
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR; SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
Word16 Last_Resort; Word16 Last_Resort;
Word16 vadnoise; Word16 vadnoise;
...@@ -714,7 +739,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ ...@@ -714,7 +739,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ
*-----------------------------------------------------------------*/ *-----------------------------------------------------------------*/
/*mean_ee = 1.0f/3.0f * (st->ee_old + ee[0] + ee[1]); */ /* coefficients take into account the position of the window */ /*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 */ 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_ee = Mult_32_16( mean_ee, 10923 ); /*Q6*/
/* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/ /* mean_voi3 = 1.0f/3.0f * (voicing[0] + voicing[1] + voicing[2]);*/
...@@ -740,7 +769,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ ...@@ -740,7 +769,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ
{ {
dE2_th = 21 << 10; dE2_th = 21 << 10;
move32(); move32();
#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*/ if ( GE_16( add_o( mean_voi3, corr_shift, &Overflow ), 22282 ) ) /*( mean_voi3 + corr_shift ) >= 0.68f*/
#endif
{ {
nb_cond = 0; nb_cond = 0;
move16(); move16();
...@@ -819,9 +852,16 @@ Word16 find_uv_ivas_fx( /* o : coding typ ...@@ -819,9 +852,16 @@ Word16 find_uv_ivas_fx( /* o : coding typ
test(); test();
test(); test();
test(); test();
#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 */ 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_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 */ ( LT_16( add_o( st_fx->voicing_fx[0], corr_shift, &Overflow ), voi_th ) ) ) ) /* normalized correlation is low */
#endif
{ {
tmp_offset_flag = 0; tmp_offset_flag = 0;
move16(); move16();
...@@ -897,6 +937,18 @@ Word16 find_uv_ivas_fx( /* o : coding typ ...@@ -897,6 +937,18 @@ Word16 find_uv_ivas_fx( /* o : coding typ
test(); test();
test(); test();
test(); test();
#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 */ 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_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[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... */
...@@ -906,7 +958,9 @@ Word16 find_uv_ivas_fx( /* o : coding typ ...@@ -906,7 +958,9 @@ Word16 find_uv_ivas_fx( /* o : coding typ
( LE_32( dE1, 237568 /* 29.0f in Q13 */ ) ) && /* Avoid on sharp energy spikes */ ( 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 */ ( 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) */ ( 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) */ flag_low_relE )
#endif
/* low relative frame energy (only for SC-VBR) */
{ {
coder_type = UNVOICED; coder_type = UNVOICED;
move16(); move16();
...@@ -923,7 +977,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ ...@@ -923,7 +977,11 @@ Word16 find_uv_ivas_fx( /* o : coding typ
test(); test();
test(); 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 */ if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774 /* 0.695f in Q15 */, mean_voi3_offset ) ) ) && /* normalized correlation low */
#endif
/*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */ /* normalized correlation low on look-ahead - onset detection */ /*( 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[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 */ ( LT_32( ee[1], 397 /* 6.2f in Q16 */ ) ) && ( GT_32( hp_E[1], E_min_th ) ) && /* ... biased towards look-ahead to detect onsets */
......
...@@ -64,9 +64,11 @@ void Es_pred_enc_fx( ...@@ -64,9 +64,11 @@ void Es_pred_enc_fx(
Word16 s0, s1, ener_dB, mean_ener_code16; Word16 s0, s1, ener_dB, mean_ener_code16;
const Word16 *qua_table; const Word16 *qua_table;
Word32 ener_fx, Lmean_ener_code, Ltmp; Word32 ener_fx, Lmean_ener_code, Ltmp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
Lmean_ener_code = L_deposit_l( 0 ); Lmean_ener_code = L_deposit_l( 0 );
...@@ -95,7 +97,11 @@ void Es_pred_enc_fx( ...@@ -95,7 +97,11 @@ void Es_pred_enc_fx(
FOR( i = 1; i < L_SUBFR; i++ ) FOR( i = 1; i < L_SUBFR; i++ )
{ {
tmp16 = mult_r( res[i_subfr + i], 8192 /* 1 in Q13 */ ); /* remove 2bits Q_new - 2*/ 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 ); ener_fx = L_mac_o( ener_fx, tmp16, tmp16, &Overflow );
#endif
} }
/* ener = 10 * (float)log10(ener / (float)L_SUBFR) */ /* ener = 10 * (float)log10(ener / (float)L_SUBFR) */
...@@ -177,7 +183,11 @@ void Es_pred_enc_fx( ...@@ -177,7 +183,11 @@ void Es_pred_enc_fx(
FOR( i = 1; i < size; i++ ) 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 ) ); tmp16_2 = abs_s( sub_o( mean_ener_code16, qua_table[i], &Overflow ) );
#endif
IF( LT_16( tmp16_2, tmp16 ) ) IF( LT_16( tmp16_2, tmp16 ) )
{ {
tmp16 = tmp16_2; tmp16 = tmp16_2;
...@@ -233,9 +243,11 @@ void gain_enc_mless_fx( ...@@ -233,9 +243,11 @@ void gain_enc_mless_fx(
Word16 exp1, exp2; Word16 exp1, exp2;
Word16 exp_num, exp_den, exp_div, frac_den; Word16 exp_num, exp_den, exp_div, frac_den;
Word32 L_frac_num, L_frac_den, L_div; Word32 L_frac_num, L_frac_den, L_div;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
...@@ -399,7 +411,11 @@ void gain_enc_mless_fx( ...@@ -399,7 +411,11 @@ void gain_enc_mless_fx(
L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/
exp_div = sub( exp_num, exp_den ); 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*/ *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*/ L_tmp1 = L_shr( L_mult( coeff[1], coeff[4] ), 2 ); /*Q31*/
exp1 = add( exp_coeff[1], exp_coeff[4] ); exp1 = add( exp_coeff[1], exp_coeff[4] );
...@@ -424,7 +440,11 @@ void gain_enc_mless_fx( ...@@ -424,7 +440,11 @@ void gain_enc_mless_fx(
L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/ L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/
exp_div = sub( exp_num, exp_den ); 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 ); *gain_code = L_shl_o( L_div, sub( add( exp, exp_div ), 14 ), &Overflow );
#endif
move32(); /*Q16*/ move32(); /*Q16*/
*gain_pit = s_max( G_PITCH_MIN_TC192_Q14, s_min( *gain_pit, G_PITCH_MAX_TC192_Q14 ) ); *gain_pit = s_max( G_PITCH_MIN_TC192_Q14, s_min( *gain_pit, G_PITCH_MAX_TC192_Q14 ) );
...@@ -454,7 +474,11 @@ void gain_enc_mless_fx( ...@@ -454,7 +474,11 @@ 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 ); 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 ); push_indice( hBstr, IND_GAIN_CODE, index, nBits2 );
L_tmp = L_mult( gain_code16, gcode0 ); /*Q0*Q0 -> Q1*/ 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*/ *gain_code = L_shl_o( L_tmp, add( add( expg, exp_gcode0 ), 15 ), &Overflow ); /*Q16*/
#endif
} }
ELSE ELSE
{ {
...@@ -572,9 +596,11 @@ void gain_enc_SQ_fx( ...@@ -572,9 +596,11 @@ void gain_enc_SQ_fx(
Word16 exp1, exp2; Word16 exp1, exp2;
Word16 exp_num, exp_den, exp_div, frac_den; Word16 exp_num, exp_den, exp_div, frac_den;
Word32 L_frac_num, L_frac_den, L_div; Word32 L_frac_num, L_frac_den, L_div;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*-----------------------------------------------------------------* /*-----------------------------------------------------------------*
...@@ -679,7 +705,11 @@ void gain_enc_SQ_fx( ...@@ -679,7 +705,11 @@ void gain_enc_SQ_fx(
L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/ L_tmp1 = L_mult( coeff[0], coeff[2] ); /*Q31*/
exp1 = add( exp_coeff[0], exp_coeff[2] ); exp1 = add( exp_coeff[0], exp_coeff[2] );
#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*/ L_tmp2 = L_mult_o( coeff[4], coeff[4], &Overflow ); /*Q31*/
#endif
exp2 = add( exp_coeff[4], exp_coeff[4] ); exp2 = add( exp_coeff[4], exp_coeff[4] );
IF( GT_16( exp1, exp2 ) ) IF( GT_16( exp1, exp2 ) )
...@@ -721,12 +751,20 @@ void gain_enc_SQ_fx( ...@@ -721,12 +751,20 @@ void gain_enc_SQ_fx(
exp_num = exp2; exp_num = exp2;
move16(); move16();
} }
#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*/ 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)*/ L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/
exp_div = sub( exp_num, exp_den ); 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*/ *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 #ifdef FIX_1978_SAT_MISSING_IN_GAIN_ENC
L_tmp1 = L_mult_sat( coeff[1], coeff[4] ); /*Q31*/ L_tmp1 = L_mult_sat( coeff[1], coeff[4] ); /*Q31*/
...@@ -754,7 +792,11 @@ void gain_enc_SQ_fx( ...@@ -754,7 +792,11 @@ void gain_enc_SQ_fx(
exp_num = exp2; exp_num = exp2;
move16(); move16();
} }
#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*/ 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)*/ L_div = Mult_32_16( L_frac_num, tmp ); /*Q(30-exp)*/
exp_div = sub( exp_num, exp_den ); exp_div = sub( exp_num, exp_den );
...@@ -841,9 +883,11 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quant ...@@ -841,9 +883,11 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quant
Word16 index, exp_gain, frac_gain, wtmp; Word16 index, exp_gain, frac_gain, wtmp;
Word16 enr_q, wenr; Word16 enr_q, wenr;
Word32 Ltmp, enr; Word32 Ltmp, enr;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*enr = 20.0 * log10(*gain + 0.001) codebook gain in dB */ /*enr = 20.0 * log10(*gain + 0.001) codebook gain in dB */
exp_gain = norm_l( *gain ); exp_gain = norm_l( *gain );
...@@ -875,7 +919,11 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quant ...@@ -875,7 +919,11 @@ Word16 gain_enc_gaus_fx( /* o : Return index of quant
Ltmp = Pow2( 14, frac_gain ); /* Put 14 as exponent */ Ltmp = Pow2( 14, frac_gain ); /* Put 14 as exponent */
exp_gain = sub( exp_gain, 14 ); /* Retreive exponent of wtmp */ 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 ); *gain = L_shl_o( Ltmp, add( 16, exp_gain ), &Overflow );
#endif
move32(); /*Q16*/ move32(); /*Q16*/
return index; return index;
...@@ -1094,10 +1142,12 @@ static Word16 Find_Opt_gainQ_fx( ...@@ -1094,10 +1142,12 @@ static Word16 Find_Opt_gainQ_fx(
Word16 exp_max[5]; Word16 exp_max[5];
Word16 exp_code, e_max; Word16 exp_code, e_max;
Word32 L_tmp, L_tmp1; Word32 L_tmp, L_tmp1;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif #endif
#endif
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
...@@ -1192,7 +1242,11 @@ static Word16 Find_Opt_gainQ_fx( ...@@ -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[3], g_code ); /* 15 - coeff_exp + 13 - 1 */
L_tmp = L_mac( L_tmp, coeff[4], g_pit_cod ); /* 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 ); L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow );
#endif
if ( L_tmp1 < 0 ) if ( L_tmp1 < 0 )
{ {
index = i; index = i;
...@@ -1725,9 +1779,11 @@ void gain_enc_amr_wb_fx( ...@@ -1725,9 +1779,11 @@ void gain_enc_amr_wb_fx(
Word16 exp_max[5], tmp, nBits; Word16 exp_max[5], tmp, nBits;
Word32 L_tmp, dist_min, L_inov, L_tmp1; Word32 L_tmp, dist_min, L_inov, L_tmp1;
const Word16 *t_qua_gain, *p; const Word16 *t_qua_gain, *p;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
...@@ -1960,7 +2016,11 @@ void gain_enc_amr_wb_fx( ...@@ -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[3], g_code ); /* 15 - coeff_exp + 13 - 1 */
L_tmp = L_mac( L_tmp, coeff[4], g_pit_cod ); /* 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 ); L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow );
#endif
/* splitting the if cost half the complexity of using IF macro */ /* splitting the if cost half the complexity of using IF macro */
if ( L_tmp1 < 0 ) if ( L_tmp1 < 0 )
{ {
...@@ -1983,7 +2043,11 @@ void gain_enc_amr_wb_fx( ...@@ -1983,7 +2043,11 @@ void gain_enc_amr_wb_fx(
move16(); 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 */ L_tmp = L_shl_o( L_tmp, add( exp_gcode0, 4 ), &Overflow ); /* Q12 -> Q16 */
#endif
*gain_code = L_tmp; /* gain of code in Q16 */ *gain_code = L_tmp; /* gain of code in Q16 */
move16(); move16();
......
...@@ -60,9 +60,11 @@ Word16 gaus_encode_fx( ...@@ -60,9 +60,11 @@ Word16 gaus_encode_fx(
Word32 Ltmp; Word32 Ltmp;
Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */ Word16 dn[L_SUBFR], exp_code, gcode; /* Correlation between xn and h1 */
Word16 exp, tmp, tmp_idx; Word16 exp, tmp, tmp_idx;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
...@@ -98,7 +100,11 @@ Word16 gaus_encode_fx( ...@@ -98,7 +100,11 @@ Word16 gaus_encode_fx(
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
* Total excitation for Unvoiced coders * 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 */ 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++ ) FOR( i = 0; i < L_SUBFR; i++ )
{ {
exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); /* Q_new */ exc[i + i_subfr] = round_fx( L_shl( L_mult( gcode, code[i] ), 15 - 9 ) ); /* Q_new */
...@@ -191,9 +197,11 @@ void gauss2v_fx( ...@@ -191,9 +197,11 @@ void gauss2v_fx(
Word16 gxx, gcc, index_delta, delta, m_sign, inv_delta; Word16 gxx, gcc, index_delta, delta, m_sign, inv_delta;
Word16 hg[190], Gaus_dico2[190]; Word16 hg[190], Gaus_dico2[190];
Word16 shiftP3; Word16 shiftP3;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/*----------------------------------------------------------------* /*----------------------------------------------------------------*
...@@ -424,8 +432,13 @@ void gauss2v_fx( ...@@ -424,8 +432,13 @@ void gauss2v_fx(
cor2_norm = norm_l( cor2 ); cor2_norm = norm_l( cor2 );
eneri_norm = norm_l( eneri ); 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 ); 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 ); 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 ) ); difference_norm = sub( add( cor2_norm, enerw_norm ), add( cor2w_norm, eneri_norm ) );
update_best = 0; update_best = 0;
...@@ -594,7 +607,11 @@ void gauss2v_fx( ...@@ -594,7 +607,11 @@ void gauss2v_fx(
/* Gain must be output in a 32-bit variable as a Q16 */ /* Gain must be output in a 32-bit variable as a Q16 */
/* Compensate for Q_new */ /* 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 */ *gain = L_shl_o( Portion, sub( 13, Q_new ), &Overflow ); /* Q16 */
#endif
move32(); move32();
return; return;
......
...@@ -114,9 +114,11 @@ Word16 gp_clip_fx( ...@@ -114,9 +114,11 @@ Word16 gp_clip_fx(
Word32 ener; Word32 ener;
Word32 L_tmp; Word32 L_tmp;
Word16 thres; Word16 thres;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
clip = 0; clip = 0;
...@@ -142,10 +144,18 @@ Word16 gp_clip_fx( ...@@ -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 ); ener = L_mac_o( 1L, xn[0], xn[0], &Overflow );
#endif
FOR( i = 1; i < L_SUBFR; i++ ) 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 ); ener = L_mac_o( ener, xn[i], xn[i], &Overflow );
#endif
} }
/* ener = 10.0f*(float)log10(ener) */ /* ener = 10.0f*(float)log10(ener) */
...@@ -334,9 +344,11 @@ Word16 Mode2_gp_clip_fx( ...@@ -334,9 +344,11 @@ Word16 Mode2_gp_clip_fx(
Word16 clip, tmp, exp_xn; Word16 clip, tmp, exp_xn;
Word16 i; Word16 i;
Word32 wener, Ltmp; Word32 wener, Ltmp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
move16(); move16();
clip = 0; clip = 0;
...@@ -355,7 +367,11 @@ Word16 Mode2_gp_clip_fx( ...@@ -355,7 +367,11 @@ Word16 Mode2_gp_clip_fx(
FOR( i = 0; i < L_subfr; i++ ) 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 ); wener = L_mac0_o( wener, xn[i], xn[i], &Overflow );
#endif
} }
/*wener = 10.0f*(float)log10(wener);*/ /*wener = 10.0f*(float)log10(wener);*/
......
...@@ -1329,9 +1329,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ ...@@ -1329,9 +1329,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */
Word32 L_tmp, ener_max, ener_mean; Word32 L_tmp, ener_max, ener_mean;
Word16 tmp, exp2, tmp2, tmp1, exp1, exp3; Word16 tmp, exp2, tmp2, tmp1, exp1, exp3;
Word16 scale; Word16 scale;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
ener_mean = L_shl( 1, shl( Qnew, 1 ) ); /*2*Qnew*/ ener_mean = L_shl( 1, shl( Qnew, 1 ) ); /*2*Qnew*/
...@@ -1341,7 +1343,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */ ...@@ -1341,7 +1343,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */
{ {
L_tmp = L_mult0( vec[j], vec[j] ); /*2*Qnew*/ L_tmp = L_mult0( vec[j], vec[j] ); /*2*Qnew*/
ener_max = L_max( ener_max, L_tmp ); 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 ); ener_mean = L_add_o( ener_mean, L_tmp, &Overflow );
#endif
} }
/*dyn = 10.0f * (ener_max / ener_mean);*/ /*dyn = 10.0f * (ener_max / ener_mean);*/
ener_mean = Mult_32_16( ener_mean, div_s( 1, lvec ) ); /*2*Qnew*/ 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 */ ...@@ -1349,7 +1355,11 @@ static Word16 edyn_fx( /* o : ratio of max to mean */
IF( ener_mean > 0 ) IF( ener_mean > 0 )
{ {
exp1 = norm_l( ener_mean ); 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 ); tmp1 = round_fx_o( L_shl( ener_mean, exp1 ), &Overflow );
#endif
exp1 = sub( 30, exp1 ); exp1 = sub( 30, exp1 );
exp2 = norm_l( ener_max ); exp2 = norm_l( ener_max );
......
...@@ -43,10 +43,12 @@ static void coderLookAheadInnovation( ...@@ -43,10 +43,12 @@ static void coderLookAheadInnovation(
move32(); move32();
move16(); move16();
move16(); move16();
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif #endif
#endif
/* Debug init (not instrumented) */ /* Debug init (not instrumented) */
...@@ -165,7 +167,11 @@ static void coderLookAheadInnovation( ...@@ -165,7 +167,11 @@ static void coderLookAheadInnovation(
ps_e = add( alp_e, ps_e ); ps_e = add( alp_e, ps_e );
BASOP_SATURATE_WARNING_OFF_EVS 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 ); max_ps_tmp = L_shl_o( max_ps, sub( max_ps_e, ps_e ), &Overflow );
#endif
BASOP_SATURATE_WARNING_ON_EVS BASOP_SATURATE_WARNING_ON_EVS
...@@ -442,10 +448,12 @@ void updateSpecPowDiffuseIdx_fx( ...@@ -442,10 +448,12 @@ void updateSpecPowDiffuseIdx_fx(
{ {
Word16 min_gp; Word16 min_gp;
Word16 k; Word16 k;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif #endif
#endif
move32(); move32();
...@@ -455,14 +463,22 @@ void updateSpecPowDiffuseIdx_fx( ...@@ -455,14 +463,22 @@ void updateSpecPowDiffuseIdx_fx(
FOR( k = 1; k < 4; k++ ) 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 ); st->mean_gc[1] = L_add_o( st->mean_gc[1], st->gain_code[k], &Overflow );
#endif
move32(); move32();
min_gp = s_min( min_gp, st->bpf_gainT[k] ); min_gp = s_min( min_gp, st->bpf_gainT[k] );
} }
/* Suppress saturation warning in threshold comparison. */ /* Suppress saturation warning in threshold comparison. */
test(); 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*/ ) ) 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(); move16();
st->glr_idx[0] = 0; st->glr_idx[0] = 0;
......
...@@ -86,8 +86,10 @@ void hf_cod_fx( ...@@ -86,8 +86,10 @@ void hf_cod_fx(
Word32 L_tmp; Word32 L_tmp;
Word16 *pt1; Word16 *pt1;
const Word16 *pt2; const Word16 *pt2;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
#endif
#endif #endif
/* Original speech signal as reference for high band gain quantisation */ /* Original speech signal as reference for high band gain quantisation */
...@@ -110,7 +112,11 @@ void hf_cod_fx( ...@@ -110,7 +112,11 @@ void hf_cod_fx(
scale_fx = div_s( shl( 1, 14 ), ener_exc_fx ); /*Q(29-q1) */ 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 */ L_tmp = L_mult( ener_hf_fx, scale_fx ); /*30-q1+q2 */
q2 = sub( q1, q2 ); /*30-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 */ scale_fx = round_fx( Isqrt( L_shl_o( L_tmp, sub( q2, 26 ), &Overflow ) ) ); /*Q13 */
#endif
pt1 = HF_fx; pt1 = HF_fx;
...@@ -186,7 +192,11 @@ void hf_cod_fx( ...@@ -186,7 +192,11 @@ void hf_cod_fx(
HF_calc_gain_fx = div_s( shl( 1, 14 ), ener_input_fx ); /*Q(29-q1) */ 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 */ L_tmp = L_mult( ener_hf_fx, HF_calc_gain_fx ); /*30-q1+q2 */
q2 = sub( q1, q2 ); /*30-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 */ 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: /* set energy of HF synthesis to energy of original HF:
......
...@@ -652,9 +652,11 @@ void hvq_classifier_ivas_fx( ...@@ -652,9 +652,11 @@ void hvq_classifier_ivas_fx(
Word16 num_peak_cands, high, low; Word16 num_peak_cands, high, low;
Word16 sharp[HVQ_NSUB_32k]; Word16 sharp[HVQ_NSUB_32k];
Word16 peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[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 #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move16(); move16();
#endif
#endif #endif
Word16 temp_e = 0; Word16 temp_e = 0;
move16(); move16();
...@@ -808,7 +810,11 @@ void hvq_classifier_ivas_fx( ...@@ -808,7 +810,11 @@ void hvq_classifier_ivas_fx(
sharp[i] = extract_h( L_shl( L_tmp, shift ) ); /* 30-s+s-8-16 -> Q6 */ sharp[i] = extract_h( L_shl( L_tmp, shift ) ); /* 30-s+s-8-16 -> Q6 */
move16(); move16();
/*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ /*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 */ 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 ) ) if ( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) )
{ {
num_sharp_bands = add( num_sharp_bands, 1 ); num_sharp_bands = add( num_sharp_bands, 1 );
...@@ -1085,9 +1091,11 @@ void hvq_classifier_fx( ...@@ -1085,9 +1091,11 @@ void hvq_classifier_fx(
Word16 num_peak_cands, high, low; Word16 num_peak_cands, high, low;
Word16 sharp[HVQ_NSUB_32k]; Word16 sharp[HVQ_NSUB_32k];
Word16 peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[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 #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
L_input_max = L_deposit_l( 0 ); L_input_max = L_deposit_l( 0 );
set32_fx( L_thr, 0, L_FRAME16k ); set32_fx( L_thr, 0, L_FRAME16k );
...@@ -1240,7 +1248,11 @@ void hvq_classifier_fx( ...@@ -1240,7 +1248,11 @@ void hvq_classifier_fx(
move16(); move16();
/*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ /*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 ); sharp_dist = add_o( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ), &Overflow );
#endif
IF( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) ) IF( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) )
{ {
num_sharp_bands = add( num_sharp_bands, 1 ); num_sharp_bands = add( num_sharp_bands, 1 );
......
...@@ -272,10 +272,12 @@ void hq_lr_enc_fx( ...@@ -272,10 +272,12 @@ void hq_lr_enc_fx(
Word16 beta_fx; /*Q14 1.05f; */ Word16 beta_fx; /*Q14 1.05f; */
HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr; BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif #endif
#endif
set32_fx( L_y2, 0x0L, L_FRAME48k ); set32_fx( L_y2, 0x0L, L_FRAME48k );
...@@ -607,7 +609,11 @@ void hq_lr_enc_fx( ...@@ -607,7 +609,11 @@ void hq_lr_enc_fx(
move16(); move16();
} }
L_tmp = Mult_32_16( Ep_vari_fx, 3277 ); /*13+15-15=13 */ 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) */ 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 */ tmp2 = extract_h( Ep_avrg_fx ); /*Q13-16=-3 */
IF( tmp2 != 0 ) IF( tmp2 != 0 )
{ {
...@@ -624,7 +630,11 @@ void hq_lr_enc_fx( ...@@ -624,7 +630,11 @@ void hq_lr_enc_fx(
move16(); move16();
} }
L_tmp2 = Mult_32_16( Ep_vari_fx, 6554 ); /*13+15-15=13 */ 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) */ 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 */ L_tmp = L_min( L_tmp, L_tmp2 ); /*Q14 */
tmp = extract_l( L_min( L_tmp, 13107 ) ); /*Q14 */ tmp = extract_l( L_min( L_tmp, 13107 ) ); /*Q14 */
alpha_fx = add( 16384, tmp ); alpha_fx = add( 16384, tmp );
...@@ -647,7 +657,11 @@ void hq_lr_enc_fx( ...@@ -647,7 +657,11 @@ void hq_lr_enc_fx(
exp = 0; exp = 0;
move16(); move16();
} }
#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) */ 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 */ L_tmp = L_max( L_tmp, 16384 ); /*Q14 */
tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*Q14 */ tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*Q14 */
alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=Q14 */ alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=Q14 */
...@@ -670,7 +684,11 @@ void hq_lr_enc_fx( ...@@ -670,7 +684,11 @@ void hq_lr_enc_fx(
exp = 0; exp = 0;
move16(); move16();
} }
#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) */ 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 = Mult_32_16( L_tmp, shl( sub( bands_fx, lowband ), 9 ) ); /*20 +9 -15 =Q14 */
L_tmp = L_max( L_tmp, 13926 ); /*Q14 */ L_tmp = L_max( L_tmp, 13926 ); /*Q14 */
tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*Q14 */ tmp2 = extract_l( L_min( L_tmp, 16384 ) ); /*Q14 */
...@@ -749,7 +767,11 @@ void hq_lr_enc_fx( ...@@ -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*/ 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++ ) FOR( i = 0; i < bands_fx; i++ )
{ {
#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 */ Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */
#endif
move32(); move32();
} }
IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) ) IF( EQ_32( st_fx->core_brate, ACELP_13k20 ) )
...@@ -781,7 +803,11 @@ void hq_lr_enc_fx( ...@@ -781,7 +803,11 @@ void hq_lr_enc_fx(
IF( GE_16( i, lowband ) && add( sub( i, bands_fx ), p2a_bands_fx ) < 0 ) 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_vari_fx = L_add_sat( Ep_vari_fx, L_abs( L_sub_sat( Ep_tmp_fx[i], Ep_tmp_fx[( i - 1 )] ) ) ); /*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 */ Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */
#endif
} }
IF( GE_16( i, highband ) ) IF( GE_16( i, highband ) )
...@@ -850,7 +876,11 @@ void hq_lr_enc_fx( ...@@ -850,7 +876,11 @@ void hq_lr_enc_fx(
{ {
tmp = sub( tmp, lowband ); tmp = sub( tmp, lowband );
L_tmp = Mult_32_16( Ep_tmp_fx[i], tmp ); /*Q(15+0-15 = 0) */ 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 */ tmp = extract_h( L_shl_o( L_tmp, 16, &Overflow ) ); /*Q0 */
#endif
IF( tmp != 0 ) IF( tmp != 0 )
{ {
exp = norm_s( tmp ); exp = norm_s( tmp );
...@@ -911,11 +941,19 @@ void hq_lr_enc_fx( ...@@ -911,11 +941,19 @@ void hq_lr_enc_fx(
{ {
IF( GE_16( i, lowband ) ) IF( GE_16( i, lowband ) )
{ {
#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 */ Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */
#endif
} }
ELSE ELSE
{ {
#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 */ 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 ) ) IF( GT_32( Ep_tmp_fx[i], Ep_peak_fx ) )
{ {
Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */ Ep_peak_fx = L_add( Ep_tmp_fx[i], 0 ); /*Q15 */
...@@ -1179,8 +1217,10 @@ void hq_lr_enc_ivas_fx( ...@@ -1179,8 +1217,10 @@ void hq_lr_enc_ivas_fx(
Word32 L_band_energy_tmp[BANDS_MAX]; Word32 L_band_energy_tmp[BANDS_MAX];
UWord16 lo; UWord16 lo;
Word16 Q_band_energy; Word16 Q_band_energy;
#ifndef ISSUE_1867_replace_overflow_libenc
Flag Overflow; Flag Overflow;
move32(); move32();
#endif
BSTR_ENC_HANDLE hBstr = st->hBstr; BSTR_ENC_HANDLE hBstr = st->hBstr;
HQ_ENC_HANDLE hHQ_core = st->hHQ_core; HQ_ENC_HANDLE hHQ_core = st->hHQ_core;
...@@ -1448,7 +1488,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1448,7 +1488,11 @@ void hq_lr_enc_ivas_fx(
} }
ELSE ELSE
{ {
#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 */ 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 ) IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 )
{ {
Ep_peak_fx = Ep_tmp_fx[i]; /*Q15 */ Ep_peak_fx = Ep_tmp_fx[i]; /*Q15 */
...@@ -1572,7 +1616,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1572,7 +1616,11 @@ void hq_lr_enc_ivas_fx(
move16(); move16();
} }
Mpy_32_16_ss( Ep_avrg_fx, tmp, &L_tmp, &lo ); Mpy_32_16_ss( Ep_avrg_fx, tmp, &L_tmp, &lo );
#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) */ 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 */ L_tmp = L_max( L_tmp, 16384 ); /*14 */
tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */ tmp = extract_l( L_min( L_tmp, beta_fx ) ); /*14 */
alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */ alpha_fx = shl( mult( alpha_fx, tmp ), 1 ); /*14+14-15 +1=14 */
...@@ -1619,7 +1667,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1619,7 +1667,11 @@ void hq_lr_enc_ivas_fx(
{ {
IF( sub( i, lowband ) >= 0 ) IF( sub( i, lowband ) >= 0 )
{ {
#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 */ Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */
#endif
} }
ELSE ELSE
{ {
...@@ -1661,7 +1713,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1661,7 +1713,11 @@ void hq_lr_enc_ivas_fx(
Mpy_32_16_ss( Ep_peak_fx, tmp, &L_tmp, &lo ); 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, lowband, &L_tmp, &lo );
Mpy_32_16_ss( L_tmp, 18842, &L_tmp, &lo ); Mpy_32_16_ss( L_tmp, 18842, &L_tmp, &lo );
#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 */ L_tmp = L_shl_o( L_tmp, sub( 27, exp ), &Overflow ); /*Q14 0.5 */
#endif
tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */ tmp2 = extract_l( L_min( L_tmp, 19661 ) ); /*14 */
Mpy_32_16_ss( L_band_energy_tmp[i], tmp2, &L_tmp, &lo ); 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 */ L_band_energy_tmp[i] = L_shl( L_tmp, 1 ); /*Q_band_energy */
...@@ -1685,7 +1741,11 @@ void hq_lr_enc_ivas_fx( ...@@ -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 */ 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++ ) FOR( i = 0; i < bands; i++ )
{ {
#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 */ Ep_tmp_fx[i] = L_shl_o( Ep_tmp_fx[i], 2, &Overflow ); /* Q15 */
#endif
move32(); move32();
} }
IF( EQ_32( st->core_brate, ACELP_13k20 ) ) IF( EQ_32( st->core_brate, ACELP_13k20 ) )
...@@ -1721,7 +1781,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1721,7 +1781,11 @@ void hq_lr_enc_ivas_fx(
IF( sub( i, lowband ) >= 0 && add( sub( i, bands ), p2a_bands ) < 0 ) 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_vari_fx = L_add( Ep_vari_fx, L_abs( L_sub( Ep_tmp_fx[i], Ep_tmp_fx[sub( i, 1 )] ) ) ); /*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 */ Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */
#endif
} }
IF( sub( i, highband ) >= 0 ) IF( sub( i, highband ) >= 0 )
...@@ -1754,7 +1818,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1754,7 +1818,11 @@ void hq_lr_enc_ivas_fx(
tmp = sub( bands, p2a_bands ); tmp = sub( bands, p2a_bands );
tmp = sub( tmp, lowband ); /*Q0 */ tmp = sub( tmp, lowband ); /*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 */ tmp1 = extract_h( L_shl_o( Ep_avrg_fx, 1, &Overflow ) ); /*Q0 */
#endif
IF( tmp1 != 0 ) IF( tmp1 != 0 )
{ {
exp = norm_s( tmp1 ); exp = norm_s( tmp1 );
...@@ -1793,7 +1861,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1793,7 +1861,11 @@ void hq_lr_enc_ivas_fx(
{ {
tmp = sub( tmp, lowband ); tmp = sub( tmp, lowband );
Mpy_32_16_ss( Ep_tmp_fx[i], tmp, &L_tmp, &lo ); Mpy_32_16_ss( Ep_tmp_fx[i], tmp, &L_tmp, &lo );
#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 */ tmp = extract_h( L_shl_o( L_tmp, 16, &Overflow ) ); /*Q0 */
#endif
IF( tmp != 0 ) IF( tmp != 0 )
{ {
exp = norm_s( tmp ); exp = norm_s( tmp );
...@@ -1818,7 +1890,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1818,7 +1890,11 @@ void hq_lr_enc_ivas_fx(
{ {
tmp = sub( tmp, lowband ); tmp = sub( tmp, lowband );
#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 */ tmp1 = extract_h( L_shl_o( Ep_avrg_fx, 1, &Overflow ) ); /*Q0 */
#endif
IF( tmp1 != 0 ) IF( tmp1 != 0 )
{ {
exp = norm_s( tmp1 ); exp = norm_s( tmp1 );
...@@ -1857,11 +1933,19 @@ void hq_lr_enc_ivas_fx( ...@@ -1857,11 +1933,19 @@ void hq_lr_enc_ivas_fx(
{ {
IF( sub( i, lowband ) >= 0 ) IF( sub( i, lowband ) >= 0 )
{ {
#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 */ Ep_avrg_fx = L_add_o( Ep_avrg_fx, Ep_tmp_fx[i], &Overflow ); /*Q15 */
#endif
} }
ELSE ELSE
{ {
#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 */ 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 ) IF( L_sub( Ep_tmp_fx[i], Ep_peak_fx ) > 0 )
{ {
Ep_peak_fx = Ep_tmp_fx[i]; /* Q15 */ Ep_peak_fx = Ep_tmp_fx[i]; /* Q15 */
...@@ -1886,7 +1970,11 @@ void hq_lr_enc_ivas_fx( ...@@ -1886,7 +1970,11 @@ void hq_lr_enc_ivas_fx(
move16(); move16();
FOR( i = 0; i < lowband; i++ ) FOR( i = 0; i < lowband; i++ )
{ {
#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 */ tmp = extract_h( L_shl_o( Ep_avrgL_fx, 1, &Overflow ) ); /*Q0 */
#endif
IF( tmp != 0 ) IF( tmp != 0 )
{ {
exp = norm_s( tmp ); exp = norm_s( tmp );
...@@ -3394,9 +3482,11 @@ static Word16 p2a_threshold_quant_fx( ...@@ -3394,9 +3482,11 @@ static Word16 p2a_threshold_quant_fx(
Word32 L_p2a; Word32 L_p2a;
Word16 p2a_fx; Word16 p2a_fx;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
exp_safe = 4; /* never happen overflow. */ exp_safe = 4; /* never happen overflow. */
...@@ -3464,7 +3554,11 @@ static Word16 p2a_threshold_quant_fx( ...@@ -3464,7 +3554,11 @@ static Word16 p2a_threshold_quant_fx(
/* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */ /* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */
L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */ L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */
#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 */ 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 ) ) IF( LE_16( p2a_fx, p2a_th_fx ) )
...@@ -3514,9 +3608,11 @@ static Word16 p2a_threshold_quant_ivas_fx( ...@@ -3514,9 +3608,11 @@ static Word16 p2a_threshold_quant_ivas_fx(
Word32 L_p2a; Word32 L_p2a;
Word16 p2a_fx; Word16 p2a_fx;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
exp_safe = 4; /* never happen overflow. */ exp_safe = 4; /* never happen overflow. */
...@@ -3583,7 +3679,11 @@ static Word16 p2a_threshold_quant_ivas_fx( ...@@ -3583,7 +3679,11 @@ static Word16 p2a_threshold_quant_ivas_fx(
/* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */ /* 10/( log(10)/log(2) ) = 3.01029995663981195211 24660(Q13) */
L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */ L_p2a = Mpy_32_16_1( L_tmp, 24660 ); /* 16+13-15 -> Q14 */
#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 */ 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 ) ) IF( LE_16( p2a_fx, p2a_th_fx ) )
...@@ -3650,9 +3750,11 @@ static void mdct_spectrum_fine_gain_enc_fx( ...@@ -3650,9 +3750,11 @@ static void mdct_spectrum_fine_gain_enc_fx(
Word16 d_fx; Word16 d_fx;
Word16 dmin_fx; Word16 dmin_fx;
Word16 imin_fx; Word16 imin_fx;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/* Fine gain quantization on only the most significant energy bands */ /* Fine gain quantization on only the most significant energy bands */
...@@ -3723,7 +3825,11 @@ static void mdct_spectrum_fine_gain_enc_fx( ...@@ -3723,7 +3825,11 @@ static void mdct_spectrum_fine_gain_enc_fx(
exp_normn = norm_l( L_Exy ); exp_normn = norm_l( L_Exy );
exp_normn = sub( exp_normn, 1 ); exp_normn = sub( exp_normn, 1 );
exp_normd = norm_l( L_Eyy ); 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 */ 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 */
#endif
Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */
gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */
...@@ -3812,9 +3918,11 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( ...@@ -3812,9 +3918,11 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx(
Word16 d_fx; Word16 d_fx;
Word16 dmin_fx; Word16 dmin_fx;
Word16 imin_fx; Word16 imin_fx;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/* Fine gain quantization on only the most significant energy bands */ /* Fine gain quantization on only the most significant energy bands */
...@@ -3885,7 +3993,11 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx( ...@@ -3885,7 +3993,11 @@ static void mdct_spectrum_fine_gain_enc_ivas_fx(
exp_normn = norm_l( L_Exy ); exp_normn = norm_l( L_Exy );
exp_normn = sub( exp_normn, 1 ); exp_normn = sub( exp_normn, 1 );
exp_normd = norm_l( L_Eyy ); 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 */ 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 */
#endif
Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */ Qgamma = add( sub( exp_normn, exp_normd ), 15 ); /* exp_normn - (exp_normd-16) - 1; */
gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */ gamma_fx = shl( gamma_fx, sub( 14, Qgamma ) ); /* Qgamma -> Q14 */
......
...@@ -49,9 +49,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits ...@@ -49,9 +49,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits
Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3; Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3;
Word16 manPeMean, manNfMean, manNfpe, man; Word16 manPeMean, manNfMean, manNfpe, man;
Word16 tmp16, adjust; Word16 tmp16, adjust;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
bits_used = 0; bits_used = 0;
move16(); move16();
...@@ -118,7 +120,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits ...@@ -118,7 +120,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits
nf_cnt = add( nf_cnt, 1 ); /* Q0 */ nf_cnt = add( nf_cnt, 1 ); /* Q0 */
} }
#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 */ pe_mean = L_add_o( pe_mean, pe, &Overflow ); /* in Q12 and always positive */
#endif
} }
IF( pe_mean > 0 ) IF( pe_mean > 0 )
...@@ -146,7 +152,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits ...@@ -146,7 +152,11 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits
expNfpe3 = extract_l( L_mult0( expNfpe, 3 ) ); /* Cube operation */ expNfpe3 = extract_l( L_mult0( expNfpe, 3 ) ); /* Cube operation */
/* Number of bits required to adjust to Q15 */ /* 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 */ noise_level[i] = extract_h( L_shr_sat( acc, adjust ) ); /* noise_level[] in Q15 */
#endif
move16(); move16();
q_noise_level_idx[i] = quant_lc_fx( noise_level[i], &q_noise_level[i] ); q_noise_level_idx[i] = quant_lc_fx( noise_level[i], &q_noise_level[i] );
move16(); move16();
...@@ -226,9 +236,11 @@ Word16 hvq_enc_fx( /*o : Consumed bits ...@@ -226,9 +236,11 @@ Word16 hvq_enc_fx( /*o : Consumed bits
Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3; Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3;
Word16 manPeMean, manNfMean, manNfpe, man; Word16 manPeMean, manNfMean, manNfpe, man;
Word16 tmp16, adjust; Word16 tmp16, adjust;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
bits_used = 0; bits_used = 0;
move16(); move16();
...@@ -295,7 +307,11 @@ Word16 hvq_enc_fx( /*o : Consumed bits ...@@ -295,7 +307,11 @@ Word16 hvq_enc_fx( /*o : Consumed bits
nf_cnt = add( nf_cnt, 1 ); /* Q0 */ nf_cnt = add( nf_cnt, 1 ); /* Q0 */
} }
#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 */ pe_mean = L_add_o( pe_mean, pe, &Overflow ); /* in Q12 and always positive */
#endif
} }
IF( pe_mean > 0 ) IF( pe_mean > 0 )
......
...@@ -93,9 +93,11 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< ...@@ -93,9 +93,11 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**<
Word16 tmp_exp; Word16 tmp_exp;
Word32 L_tmp; Word32 L_tmp;
Word16 shift; Word16 shift;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL #ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0; Flag Overflow = 0;
move32(); move32();
#endif
#endif #endif
/* initialize variables */ /* initialize variables */
...@@ -218,8 +220,13 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< ...@@ -218,8 +220,13 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**<
move16(); 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( 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 ); 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 ); L_tmp = L_mult( gain, tmp );
gain_exp = add( gain_exp, tmp_exp ); gain_exp = add( gain_exp, tmp_exp );
} }
...@@ -247,7 +254,11 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**< ...@@ -247,7 +254,11 @@ static void IGF_CalculateEnvelope( const IGF_ENC_INSTANCE_HANDLE hInstance, /**<
L_tmp = BASOP_Util_Log2( L_tmp ); L_tmp = BASOP_Util_Log2( L_tmp );
L_tmp = L_add( L_tmp, L_deposit_h( shl( gain_exp, 15 - 6 ) ) ); L_tmp = L_add( L_tmp, L_deposit_h( shl( gain_exp, 15 - 6 ) ) );
shift = norm_l( L_tmp ); 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 ); gain = round_fx_o( L_shl_o( L_tmp, shift, &Overflow ), &Overflow );
#endif
gain_exp = sub( 7, shift ); 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, 32767 /*16 Q11*/, 4, &gain );
gain_exp = BASOP_Util_Add_MantExp( gain, gain_exp, 0x4000, 0, &gain ); gain_exp = BASOP_Util_Add_MantExp( gain, gain_exp, 0x4000, 0, &gain );
...@@ -442,8 +453,13 @@ void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< ou ...@@ -442,8 +453,13 @@ void IGF_ErodeSpectrum( Word16 *highPassEner_exp, /**< ou
/* May overflow - just for threshold comparison */ /* May overflow - just for threshold comparison */
/* negate because the negated may be 1 larger in abs, */ /* 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 */ /* 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 ); 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 ); L_tmp = L_add_o( pPowerSpectrum[i - 1], highPassEner_Ovfl, &Overflow );
#endif
if ( L_tmp >= 0 ) if ( L_tmp >= 0 )
{ {
......
...@@ -753,7 +753,9 @@ Word16 ivas_acelp_tcx20_switching_fx( ...@@ -753,7 +753,9 @@ Word16 ivas_acelp_tcx20_switching_fx(
Word32 offset_tcx, target; Word32 offset_tcx, target;
Word32 y_fx[N_MAX]; Word32 y_fx[N_MAX];
Word32 tcx_snr; Word32 tcx_snr;
#ifndef ISSUE_1867_replace_overflow_libenc
Flag Overflow; Flag Overflow;
#endif
Word32 gain, noise; Word32 gain, noise;
Word16 noise_e = 0; Word16 noise_e = 0;
move16(); move16();
...@@ -1241,7 +1243,11 @@ Word16 ivas_acelp_tcx20_switching_fx( ...@@ -1241,7 +1243,11 @@ Word16 ivas_acelp_tcx20_switching_fx(
test(); test();
if ( ( GT_32( snr_acelp, tcx_snr ) ) && if ( ( GT_32( snr_acelp, tcx_snr ) ) &&
( LT_32( snr_acelp, L_add( tcx_snr, 131072 /*2.0f Q16*/ ) ) ) && ( 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 ) || ( 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*/ ) ) ) && ( !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 ) ) ) ( LE_16( st->Nb_ACELP_frames, 6 ) ) )
{ {
......