Commit 76bda7b2 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh Committed by Fabian Bauer
Browse files

Fix for 3GPP issue 1092: BASOP asserts in stereo fx encoder for selection test inputs

Link #1092
parent d976c7b5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -106,4 +106,5 @@
#define FIX_1133_IMPROVE_MC_MLD                 /* Ittiam: Correcting wrong updation of exponents in ivas_mc_paramupmix_param_est_enc_fx() */
#define FIX_ISSUE_1122                          /* Ittiam: Fix issue 1122: corrected incorrect scaling of a buffer leading to incorrect metadata bits */
#define FIX_1132_STACK_CORRUPTION               /* Stack corruption issue due of extending index access*/
#define FIX_ISSUE_1092                          /* Ittiam: Fix for Issue 1092: BASOP asserts in stereo fx encoder for selection test inputs*/
#endif
+13 −6
Original line number Diff line number Diff line
@@ -905,9 +905,13 @@ static uint16_t enc_ste_pre_mdct(
        absMagnR_fx = Sqrt32( L_add( Mpy_32_32( sigR1_fx[s], sigR1_fx[s] ), Mpy_32_32( sigI1_fx[s], sigI1_fx[s] ) ), &absMagnR_e );

        corr_fx = L_add( corr_fx, L_add( Mpy_32_32( sigR0_fx[s], sigR1_fx[s] ), Mpy_32_32( sigI0_fx[s], sigI1_fx[s] ) ) ); // q_com*2 - 31
#ifdef FIX_ISSUE_1092
        sumL_fx = L_add( sumL_fx, L_add( L_shr( sigR0_fx[s], 1 ), L_shr( sigI0_fx[s], 1 ) ) ); // q_com -1
        sumR_fx = L_add( sumR_fx, L_add( L_shr( sigR1_fx[s], 1 ), L_shr( sigI1_fx[s], 1 ) ) ); // q_com - 1
#else
        sumL_fx = L_add( sumL_fx, L_add( sigR0_fx[s], sigI0_fx[s] ) ); // q_com
        sumR_fx = L_add( sumR_fx, L_add( sigR1_fx[s], sigI1_fx[s] ) ); // q_com

#endif
        sumMagnL_fx = BASOP_Util_Add_Mant32Exp( sumMagnL_fx, sumMagnL_e, absMagnL_fx, absMagnL_e, &sumMagnL_e );
        sumMagnR_fx = BASOP_Util_Add_Mant32Exp( sumMagnR_fx, sumMagnR_e, absMagnR_fx, absMagnR_e, &sumMagnR_e );
        sumPrdLR_fx = BASOP_Util_Add_Mant32Exp( sumPrdLR_fx, sumPrdLR_e, Mpy_32_32( absMagnL_fx, absMagnR_fx ), add( absMagnL_e, absMagnR_e ), &sumPrdLR_e );
@@ -919,8 +923,11 @@ static uint16_t enc_ste_pre_mdct(
    temp1 = L_shl( preproLen, x1 );
    corr_fx = Mpy_32_32( corr_fx, temp1 );
    x1 = sub( 62, add( shl( *q_com, 1 ), x1 ) );
#ifdef FIX_ISSUE_1092
    corr_fx = BASOP_Util_Add_Mant32Exp( corr_fx, x1, Mpy_32_32( sumL_fx, sumR_fx ), sub( 62, shl( sub( *q_com, 1 ), 1 ) ), &x1 );
#else
    corr_fx = BASOP_Util_Add_Mant32Exp( corr_fx, x1, Mpy_32_32( sumL_fx, sumR_fx ), sub( 62, shl( *q_com, 1 ) ), &x1 );

#endif

    IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( corr_fx, x1, -maxSqrValue_fx, 52 ), -1 ) )
    {
+5 −0
Original line number Diff line number Diff line
@@ -85,7 +85,12 @@ typedef struct stereo_itd_data_struct
    Word16 prev_sum_nrg_L_lb_fx_e;
    Word32 prev_xcorr_lb_fx[STEREO_DFT_XCORR_LB_MAX];
    Word16 prev_xcorr_lb_fx_e;
#ifdef FIX_ISSUE_1092
    Word32 E_band_n_fx[STEREO_DFT_ITD_VAD_BAND_NUM]; /*E_band_n_exp*/
    Word16 E_band_n_exp[STEREO_DFT_ITD_VAD_BAND_NUM];
#else
    Word32 E_band_n_fx[STEREO_DFT_ITD_VAD_BAND_NUM]; /*Q0*/
#endif
    Word32 xcorr_smooth_fx[STEREO_DFT_N_32k_ENC];
    Word16 xcorr_smooth_fx_e[STEREO_DFT_N_32k_ENC];
    Word32 lp_phat_peak_fx; /* low-pass GCC PHAT peak value */ // Q31
+3 −0
Original line number Diff line number Diff line
@@ -752,6 +752,9 @@ void stereo_enc_itd_init_fx(
    hItd->prev_xcorr_lb_fx_e = 0;
    move16();
    set32_fx( hItd->E_band_n_fx, ITD_VAD_E_BAND_N_INIT, STEREO_DFT_ITD_VAD_BAND_NUM );
#ifdef FIX_ISSUE_1092
    set16_fx( hItd->E_band_n_exp, Q31, STEREO_DFT_ITD_VAD_BAND_NUM );
#endif
    hItd->vad_frm_cnt = 0;
    move16();
    hItd->pre_vad = 0;
+52 −23
Original line number Diff line number Diff line
@@ -205,7 +205,12 @@ static void stereo_dft_quantize_itd_fx(
 *-------------------------------------------------------------------------*/

static Word32 itd_vad_ms_snr_calc_fx(
#ifdef FIX_ISSUE_1092
    Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // E_band_n_exp
    Word16 E_band_n_exp[STEREO_DFT_ITD_VAD_BAND_NUM],
#else
    Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // Q0
#endif
    Word32 *Spd,
    Word16 *Spd_e,
    Word32 *E_band,
@@ -248,7 +253,11 @@ static Word32 itd_vad_ms_snr_calc_fx(
        // snr[i] = E_band[i] / E_band_n[i];
        snr[i] = BASOP_Util_Divide3232_Scale_cadence( E_band[i], E_band_n[i], &snr_e[i] );
        move32();
#ifdef FIX_ISSUE_1092
        snr_e[i] = add( snr_e[i], sub( E_band_e[i], E_band_n_exp[i] ) );
#else
        snr_e[i] = add( snr_e[i], sub( E_band_e[i], 31 ) );
#endif
        move16();
        // if ( snr[i] < 1 )
        IF( BASOP_Util_Cmp_Mant32Exp( snr[i], snr_e[i], 1, 31 ) < 0 )
@@ -284,7 +293,12 @@ static Word32 itd_vad_ms_snr_calc_fx(
 *
 *-------------------------------------------------------------------------*/
static void itd_vad_background_update_fx(
#ifdef FIX_ISSUE_1092
    Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // E_band_n_exp
    Word16 E_band_n_exp[STEREO_DFT_ITD_VAD_BAND_NUM],
#else
    Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // Q0
#endif
    Word16 *vad_frm_cnt,
    const Word32 ms_snr,
    const Word16 ms_snr_e,
@@ -326,23 +340,21 @@ static void itd_vad_background_update_fx(
            Word16 q_temp = norm_l( *vad_frm_cnt );
            L_temp = L_shl( *vad_frm_cnt, q_temp );
            L_temp_e = sub( 31, q_temp );
#ifdef FIX_ISSUE_1092
            L_temp = BASOP_Util_Add_Mant32Exp( Mpy_32_32( E_band_n[i], L_temp ), add( E_band_n_exp[i], L_temp_e ), E_band[i], E_band_e[i], &L_temp_e );
#else
            L_temp = BASOP_Util_Add_Mant32Exp( Mpy_32_32( E_band_n[i], L_temp ), add( 31, L_temp_e ), E_band[i], E_band_e[i], &L_temp_e );
#endif
            E_band_n[i] = BASOP_Util_Divide3232_Scale_cadence( L_temp, L_add( *vad_frm_cnt, 1 ), &E_band_n_e_tmp );
            move32();
#ifdef FIX_ISSUE_1092
            E_band_n_exp[i] = add( E_band_n_e_tmp, sub( L_temp_e, 31 ) );
#else
            E_band_n_e_tmp = add( E_band_n_e_tmp, sub( L_temp_e, 31 ) );
            E_band_n[i] = L_shr_r( E_band_n[i], sub( 31, E_band_n_e_tmp ) ); // Q31
#endif
            move16();
        }
        /*Word16 max_exp = E_band_n_e_tmp[0];
        for ( i = 1; i < STEREO_DFT_ITD_VAD_BAND_NUM; i++ )
        {
            max_exp = s_max( max_exp, E_band_n_e_tmp[i] );
        }
        *E_band_n_e = max_exp;
        for ( i = 0; i < STEREO_DFT_ITD_VAD_BAND_NUM; i++ )
        {
            E_band_n[i] = L_shr_r( E_band_n[i], sub( *E_band_n_e, E_band_n_e_tmp[i] ) );
        }*/
    }
    ELSE
    {
@@ -352,6 +364,20 @@ static void itd_vad_background_update_fx(
            FOR( i = 0; i < STEREO_DFT_ITD_VAD_BAND_NUM; i++ )
            {
                // E_band_n[i] = 0.96f * E_band_n[i] + 0.04f * E_band[i];
#ifdef FIX_ISSUE_1092
                E_band_n[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( 2061584302 /*0.96 in Q31*/, E_band_n[i] ), E_band_n_exp[i], Mpy_32_32( 85899346 /*0.04 in Q31*/, E_band[i] ), E_band_e[i], &E_band_n_e_tmp );
                move32();
                E_band_n_exp[i] = E_band_n_e_tmp;
                move16();
                // if ( E_band_n[i] < 1.0f )
                IF( BASOP_Util_Cmp_Mant32Exp( E_band_n[i], E_band_n_exp[i], MAX_32, 0 ) < 0 )
                {
                    E_band_n[i] = MAX_32;
                    move32();
                    E_band_n_exp[i] = 0;
                    move16();
                }
#else
                E_band_n[i] = BASOP_Util_Add_Mant32Exp( Mpy_32_32( 2061584302, E_band_n[i] ), 31, Mpy_32_32( 85899346, E_band[i] ), E_band_e[i], &E_band_n_e_tmp );
                move32();
                // if ( E_band_n[i] < 1.0f )
@@ -364,17 +390,8 @@ static void itd_vad_background_update_fx(
                }
                E_band_n[i] = L_shr_r( E_band_n[i], sub( 31, E_band_n_e_tmp ) ); // Q31
                move32();
#endif
            }
            /*Word16 max_exp = E_band_n_e_tmp[0];
            for ( i = 1; i < STEREO_DFT_ITD_VAD_BAND_NUM; i++ )
            {
                max_exp = s_max( max_exp, E_band_n_e_tmp[i] );
            }
            *E_band_n_e = max_exp;
            for ( i = 0; i < STEREO_DFT_ITD_VAD_BAND_NUM; i++ )
            {
                E_band_n[i] = L_shr_r( E_band_n[i], sub( *E_band_n_e, E_band_n_e_tmp[i] ) );
            }*/
        }
    }

@@ -387,7 +404,12 @@ static void itd_vad_background_update_fx(
 *-------------------------------------------------------------------------*/

static Word16 stereo_dft_enc_itd_vad_fx(
#ifdef FIX_ISSUE_1092
    Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // E_band_n_exp
    Word16 E_band_n_exp[STEREO_DFT_ITD_VAD_BAND_NUM],
#else
    Word32 E_band_n[STEREO_DFT_ITD_VAD_BAND_NUM], // Q0
#endif
    Word16 *vad_frm_cnt,
    Word32 *Spd_L,
    Word16 *Spd_L_e,
@@ -414,12 +436,17 @@ static Word16 stereo_dft_enc_itd_vad_fx(
        Spd_e[i] = sub( Spd_e[i], 1 );
        move16();
    }
#ifdef FIX_ISSUE_1092
    *mssnr = itd_vad_ms_snr_calc_fx( E_band_n, E_band_n_exp, Spd, Spd_e, E_band, E_band_e, mssnr_e );
    move32();

    itd_vad_background_update_fx( E_band_n, E_band_n_exp, vad_frm_cnt, *mssnr, *mssnr_e, E_band, E_band_e );
#else
    *mssnr = itd_vad_ms_snr_calc_fx( E_band_n, Spd, Spd_e, E_band, E_band_e, mssnr_e );
    move32();

    itd_vad_background_update_fx( E_band_n, vad_frm_cnt, *mssnr, *mssnr_e, E_band, E_band_e );

#endif
    // if ( *mssnr < ITD_VAD_THRSHOLD )
    IF( BASOP_Util_Cmp_Mant32Exp( *mssnr, *mssnr_e, ITD_VAD_THRSHOLD_Q31, 0 ) < 0 )
    {
@@ -1447,9 +1474,11 @@ void stereo_dft_enc_compute_itd_fx(
    }
    // L_temp = sum2_32_fx( &Spd_L[1], 11, &L_temp_e );
    sum_nrg_L_lb = BASOP_Util_Add_Mant32Exp( sum_nrg_L_lb, sum_nrg_L_lb_e, L_temp, L_temp_e, &sum_nrg_L_lb_e );

#ifdef FIX_ISSUE_1092
    vad_flag_itd = stereo_dft_enc_itd_vad_fx( hItd->E_band_n_fx, hItd->E_band_n_exp, &( hItd->vad_frm_cnt ), Spd_L, Spd_L_e, Spd_R, Spd_R_e, &mssnr, &mssnr_e );
#else
    vad_flag_itd = stereo_dft_enc_itd_vad_fx( hItd->E_band_n_fx, &( hItd->vad_frm_cnt ), Spd_L, Spd_L_e, Spd_R, Spd_R_e, &mssnr, &mssnr_e );

#endif
    vad_flag_itd = vad_flag_itd && vad_flag_dtx[0];

    // if ( sum_nrg_L < EPSILON )