Issue when decoding at 32 kbps
in 6aad3441, there is a saturation in ivas_calc_tilt_bwe_fx() causing a crash at 32.0 kbps for the following bitstream (created with the floating point encoder)
Once unzipped, the command line is: IVAS_DEC STEREO 32 stereo_dtx_32000_32.bit syn
To get there, #712 (closed) needs to be fixed
stack: ivas_bw_switching_pre_proc_fx() -->ivas_calc_tilt_bwe_fx() Ln757 -->Madd_32_32()
The saturation happens with the L_add() within Madd_32_32(). The fix is more tricky as Madd_32_32 is used at multiple places without an issue. these function were created by Ittiam, @venkateshsa please have a look if the saturation is expected or not, if so, maybe a new Madd_32_32_sat() operator should be created.
a possible solution would be something like :
/* Divide Frame Length by 32 */
FOR(j = shr(N, 5); j > 0; j--)
{
Word32 tmp = *ptr++; /* Divide by 4 */
L_ener = Mpy_32_32( tmp, tmp );
/* With the shift by 4 and the L_mult0, no overflow possible for 32 samples */
FOR(i = 1; i < 32; i++)
{
tmp1 = *ptr++; /* Divide by 4 */
#ifdef BASOP_NOGLOB_TMP_FIX
L_ener = Madd_32_32_sat( L_ener, tmp1, tmp1 );
#else
L_ener = Madd_32_32( L_ener, tmp1, tmp1 );
#endif
}
#ifdef BASOP_NOGLOB_TMP_FIX
L_temp = L_add_sat( L_ener_tot, L_ener );
L_ener_tot = L_add_sat(L_ener_tot, L_ener);
#else
L_temp = L_add( L_ener_tot, L_ener );
L_ener_tot = L_add(L_ener_tot, L_ener);
#endif
}
On the other hand, as the function has been re-written for ivas, I guess the whole loop could be computed with the 64 operand, that would solve the issue as well
I think something like the code below could replace the whole loop above:
{
//Word64 L_ener_tot64, Ltmp64;
//L_ener_tot64 = W_deposit32_h(1);
//ptr = sp;
//FOR( j = N; j > 0; j-- )
//{
//Ltmp64 = W_mult_32_32( *ptr, *ptr);
//L_ener_tot64 = W_add( L_ener_tot64, Ltmp64 );
//ptr++;
//}
//L_ener_tot = W_extract_h( L_ener_tot64 );
}
Actually the proposal above doesn't give more headroom to prevent mid way saturation, it would be better to do as below such that the accumulation in done from the lower 32 bits:
Word64 L_ener_tot64;
Word32 Ltmp32;
L_ener_tot64 = W_deposit32_l( 1 );
ptr = sp;
FOR( j = N; j > 0; j-- )
{
Word32 tmp = *ptr++; /* Divide by 4 */
Ltmp32 = Mpy_32_32( tmp, tmp );
L_ener_tot64 = W_add( L_ener_tot64, W_deposit32_l( Ltmp32 ) );
}
L_ener_tot = W_sat_l( L_ener_tot64 );
@venkateshsa , please have a look at it, while the previous proposal solve some cases, I still had saturation for a different file (sat_tilt_stereo_24400_32.bit), with the latest proposal I don't have saturation anymore