Commit 6ec556d2 authored by Anjaneyulu Sana's avatar Anjaneyulu Sana
Browse files

Fix for 3GPP issue 1478: Encoder crash (assert) in ISM1, GSC encoder

parent 4f234b04
Loading
Loading
Loading
Loading
Loading
+15 −27
Original line number Diff line number Diff line
@@ -177,9 +177,10 @@ void pre_echo_att_ivas_fx(
    move16();
    Word16 ratio_fx;
    Word16 attack_pos_fx, i;
    Word32 L_tmp, L_tmp1;
    Word16 tmp, n1, n2, exp, frac1, frac2;
    Word32 L_tmp;
    Word16 tmp, tmp_e;
    Word32 etmp1_fx;
    Word16 etmp_e;
    Word16 att_len;

    test();
@@ -220,32 +221,19 @@ void pre_echo_att_ivas_fx(
        IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 )
        {
            /* Find the average energy before the attack */
            L_tmp = sum32_fx( finc_fx, attack_pos_fx );                  /*Q1 */
            L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */
            tmp = round_fx( Isqrt( L_tmp1 ) );                           /*Q15 */
            L_tmp = L_shr( L_tmp, 2 );                                   /*Q1 ; ATT_SEG_LEN=4 */
            etmp_fx = Mult_32_16( L_tmp, tmp );                          /*Q1 */
            etmp_fx = sum32_fx( finc_fx, attack_pos_fx );
            etmp_e = sub( 31, add( shl( Q_new, 1 ), 1 ) );
            etmp_fx = L_add( etmp_fx, L_shr( 21474836 /*0.01 in Q31*/, etmp_e ) ); /* etmp = etmp + 0.01;   (exp = etmp_e) */
            etmp_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( etmp_fx, L_mult0( attack_pos_fx, ATT_SEG_LEN ), &tmp_e ) );
            tmp_e = add( tmp_e, sub( etmp_e, 31 ) );
            etmp_e = tmp_e;
            move16();

            etmp_fx = L_shr( etmp_fx, add( 1 - 4, shl( Q_new, 1 ) ) ); /* makes etmp i nQ4 as *Last_frame_ener_fx */
            /* Find the correction factor and apply it before the attack */
                                                                       /*   ratio = (float)sqrt(*Last_frame_ener/etmp);*/
                                                                       /*         = isqrt(etmp/(*Last_frame_ener))			*/
            etmp_fx = L_max( etmp_fx, 1 );
            *Last_frame_ener_fx = L_max( *Last_frame_ener_fx, 1 );
            move32();
            n1 = norm_l( etmp_fx );
            n2 = norm_l( *Last_frame_ener_fx );

            n1 = sub( n1, 1 );
            exp = sub( n1, n2 );

            frac1 = round_fx( L_shl( etmp_fx, n1 ) );
            frac2 = round_fx_sat( L_shl_sat( *Last_frame_ener_fx, n2 ) );
            L_tmp = L_mult0( 128, div_s( frac1, frac2 ) ); /* s = gain_out / gain_in */
            L_tmp = L_shr( L_tmp, exp );                   /* add exponent */

            L_tmp = Isqrt( L_tmp );
            ratio_fx = round_fx( L_shl( L_tmp, 9 ) );
            tmp = BASOP_Util_Divide3232_Scale( *Last_frame_ener_fx, etmp_fx, &tmp_e ); /* numerator Q = 2 * Q_new + 1;  denominator Q = 31 - tmp_e */
            tmp_e = add( tmp_e, sub( sub( 31, etmp_e ), add( shl( Q_new, 1 ), 1 ) ) ); /* tmp_e = tmp_e + (31 - tmp_e) - (2 * Q_new + 1) */
            tmp = Sqrt16( tmp, &tmp_e );
            ratio_fx = shr( tmp, sub( 2, tmp_e ) ); /* Q13 */

            /* Pre-echo atttenuation should never increase the energy */
            ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */