Commit 5425fce1 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

ASAN and MSAN error fixes, float structure clean up changes in encoder

parent 474bc689
Loading
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ void bands_and_bit_alloc_ivas_fx(
    Word32 sum_bit /*Q0*/, bit_fracf /*Q18*/;
    Word16 etmp;
    Word16 tmp;
    Word16 Ener_per_bd_iQ_tmp[MBANDS_GN_BITALLOC16k]; // Q13
    Word16 pos, band;
    Word32 SWB_bit_budget;                        // Q0 -> Q18
    Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; // Q18
@@ -126,7 +125,6 @@ void bands_and_bit_alloc_ivas_fx(
        nb_tot_bands = MBANDS_GN_BITALLOC16k;
        move16();
    }
    Copy( Ener_per_bd_iQ, Ener_per_bd_iQ_tmp, nb_tot_bands );

    set32_fx( bits_per_bands, 0, MBANDS_GN_BITALLOC16k );
    set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k );
@@ -138,7 +136,7 @@ void bands_and_bit_alloc_ivas_fx(
    ener_vec[0] = add( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1] ); /*Q12 */
#endif
    move16();
    Copy( Ener_per_bd_iQ_tmp + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */
    Copy( Ener_per_bd_iQ + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */
    ener_vec[MBANDS_GN - 1] = ener_vec[MBANDS_GN - 2];
    move16();
    IF( EQ_16( L_frame, L_FRAME16k ) )
+11 −9
Original line number Diff line number Diff line
@@ -322,20 +322,19 @@ static void house_refl_fx(
        Word32 rcp_fx = L_deposit_h( tmp ); // rcp_q
        Word16 rcp_q = sub( Q31, exp );

        rcp_fx = L_shr( rcp_fx, sub( rcp_q, Q31 ) ); // making rcp_fx in Q31
        FOR( i = 0; i < sizex; i++ )
        {
            norm = norm_l( pu_fx[i] );
            L_tmp = L_shl( pu_fx[i], norm );
            pu_fx[i] = Mpy_32_32( L_tmp, rcp_fx ); // px_q + Q31 - Q31 -> px_q
            pu_e[i] = sub( 31, add( px_q, norm ) );
            pu_fx[i] = Mpy_32_32( L_tmp, rcp_fx ); // ( px_q + norm ) + rcp_q - 31  -> exp: 31 + 31 - (px_q + norm + rcp_q)
            pu_e[i] = sub( 62, add( add( px_q, norm ), rcp_q ) );
            move32();
            move16();
        }

        IF( pu_fx[0] >= 0 )
        {
            pu_fx[0] = L_add( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) );
            pu_fx[0] = BASOP_Util_Add_Mant32Exp( pu_fx[0], pu_e[0], ONE_IN_Q30, 1, &pu_e[0] );
            ( *normu_fx ) = L_negate( *normu_fx );

            move32();
@@ -343,7 +342,7 @@ static void house_refl_fx(
        }
        ELSE
        {
            pu_fx[0] = L_sub( pu_fx[0], L_shl( 1, sub( 31, pu_e[0] ) ) );
            pu_fx[0] = BASOP_Util_Add_Mant32Exp( pu_fx[0], pu_e[0], -ONE_IN_Q30, 1, &pu_e[0] );
            move32();
        }

@@ -357,8 +356,8 @@ static void house_refl_fx(
        FOR( i = 0; i < sizex; i++ )
        {
            pu_fx[i] = Mpy_32_32( pu_fx[i], rcp_fx ); // pu_e[i] + exp2
            pu_fx[i] = L_shl( pu_fx[i], exp2 );       // pu_e[i] + exp2
            move32();
            pu_e[i] = add( pu_e[i], exp2 );
            move32();
        }

@@ -489,6 +488,7 @@ static void house_qr_fx(
    Word32 U_fx[FOA_CHANNELS * FOA_CHANNELS];
    Word16 U_e[FOA_CHANNELS * FOA_CHANNELS];
    Word32 pu_fx[FOA_CHANNELS];
    Word16 tmp_pu_e[FOA_CHANNELS];
    Word16 pv_exp[FOA_CHANNELS];
    Word32 pa_fx[FOA_CHANNELS];
    Word16 tmp_e;
@@ -573,8 +573,10 @@ static void house_qr_fx(
    {
        FOR( i = 0; i < n_rows; i++ )
        {
            pu_fx[i] = L_shr( U_fx[i * n + k], sub( sub( 31, U_e[i * n + k] ), pu_fx_q ) ); // pu_fx_q
            pu_fx[i] = U_fx[i * n + k];
            move32();
            tmp_pu_e[i] = U_e[i * n + k];
            move16();
        }

        FOR( s = k; s < n_rows; s++ )
@@ -586,8 +588,8 @@ static void house_qr_fx(
            }


            pv_fx[s - k] = dotp_fixed( &pu_fx[k], &pa_fx[k], sub( n_rows, k ) ); // pu_fx_q + Q31 - Q31
            pv_exp[s - k] = sub( 31, pu_fx_q );
            pv_fx[s - k] = dotp_fixed( &pu_fx[k], &pa_fx[k], sub( n_rows, k ) ); // exp: tmp_pu_e[i]
            pv_exp[s - k] = tmp_pu_e[i];
            move32();
            move16();
        }
+9 −1
Original line number Diff line number Diff line
@@ -481,7 +481,7 @@ ivas_error acelp_core_enc(
        Copy( hLPDmem->mem_syn3, hLPDmem->mem_syn, M );

        /* update old synthesis buffer - needed for ACELP internal sampling rate switching */
        Copy( syn1_fx + add( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM );
        Copy( syn1_fx + sub( st->L_frame, L_SYN_MEM ), hLPDmem->mem_syn_r, L_SYN_MEM );

        /* save and delay synthesis to be used by SWB BWE */
        IF( st->hBWE_FD != NULL )
@@ -785,7 +785,11 @@ ivas_error acelp_core_enc(
        IF( st->element_mode > EVS_MONO && st->hTcxEnc != NULL )
        {
            Copy( syn1_fx + shr( st->L_frame, 1 ), st->hTcxEnc->Txnq, shr( st->L_frame, 1 ) );
#ifdef MSAN_FIX
            Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 1 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) );
#else
            Scale_sig( st->hTcxEnc->Txnq + shr( st->L_frame, 1 ), sub( L_FRAME32k / 2 + 64, shr( st->L_frame, 2 ) ), sub( st->Q_syn, st->hTcxEnc->q_Txnq ) );
#endif
            st->hTcxEnc->q_Txnq = st->Q_syn;
            move16();
        }
@@ -810,7 +814,11 @@ ivas_error acelp_core_enc(
         *-----------------------------------------------------------------*/

        Scale_sig( syn_fx, L_FRAME, sub( s_min( st->Q_syn, Q_new ), st->Q_syn ) );
#ifdef MSAN_FIX
        Scale_sig( res_fx, st->L_frame, sub( s_min( st->Q_syn, Q_new ), Q_new ) );
#else
        Scale_sig( res_fx, L_FRAME16k, sub( s_min( st->Q_syn, Q_new ), Q_new ) );
#endif
        FEC_encode_ivas_fx( hBstr, st->acelp_cfg, syn_fx, st->coder_type, st->clas, pitch_buf, res_fx, &st->Last_pulse_pos, st->L_frame, st->total_brate, s_min( st->Q_syn, Q_new ) );
        IF( st->hBWE_TD != NULL )
        {
+6 −3
Original line number Diff line number Diff line
@@ -310,7 +310,8 @@ static void find_enr_dft_fx(
            move32();
            BinE_fx[bin_cnt] = L_shl( BinE_fx[bin_cnt], sub( *Qout, sub( sub( add( add( shl( Q_inp_dmx, 1 ), te_exp ), ngmult_exp ), 34 ), guarded_bits ) ) );
            move32();
            band_fx[i] = L_add( BinE_fx[bin_cnt], band_fx[i] );
            // To Be Checked
            band_fx[i] = L_add_sat( BinE_fx[bin_cnt], band_fx[i] );
            move32();
            ptR_fx += 2;
            ptI_fx += 2;
@@ -409,8 +410,10 @@ static void find_enr_dft_fx(
    }
    *Etot_fx = tmp_fx;

    scale_sig32( band_fx, NB_BANDS, 2 );
    scale_sig32( band_ener_fx, NB_BANDS, 2 );
    // To Be Checked
    Scale_sig32( band_fx, NB_BANDS, 2 );
    // To Be Checked
    Scale_sig32( band_ener_fx, NB_BANDS, 2 );
    move32();
    return;
}
+80 −0
Original line number Diff line number Diff line
@@ -76,7 +76,87 @@ void gauss_L2_fx(
    }

    tmp16 = norm_l( tmp32 );
#ifdef BASOP_NOGLOB
    g_corr->y1y1 = round_fx_sat( L_shl( tmp32, tmp16 ) );
#else
    g_corr->y1y1 = round_fx( L_shl( tmp32, tmp16 ) );
#endif
    g_corr->y1y1_e = sub( 31 - 18, tmp16 );
    move16();

    tmp16 = norm_l( tmp32_2 );
#ifdef BASOP_NOGLOB
    g_corr->y1y2 = round_fx_sat( L_shl( tmp32_2, tmp16 ) );
#else
    g_corr->y1y2 = round_fx( L_shl( tmp32_2, tmp16 ) );
#endif
    g_corr->y1y2_e = sub( 31 - 18, tmp16 );
    move16();
}

void gauss_L2_ivas_fx(
    const Word16 h[],             /* i  : weighted LP filter impulse response   Q14+s */
    Word16 code[],                /* o  : gaussian excitation                     Q9  */
    const Word16 y2[],            /* i  : zero-memory filtered code. excitation   Q9  */
    Word16 y11[],                 /* o  : zero-memory filtered gauss. excitation  Q9  */
    Word32 *gain,                 /* o  : excitation gain                         Q16 */
    ACELP_CbkCorr *g_corr,        /*i/o : correlation structure for gain coding       */
    const Word16 gain_pit,        /* i  : unquantized gain of code                Q14 */
    const Word16 tilt_code,       /* i  : tilt of code                            Q15 */
    const Word16 *Aq,             /* i  : quantized LPCs                          Q12 */
    const Word16 formant_enh_num, /* i  : formant enhancement numerator factor              Q15 */
    Word16 *seed_acelp,           /*i/o : random seed                             Q0  */
    const Word16 shift )
{
    Word16 i, tmp16;
    Word32 tmp32, tmp32_2;


    assert( gain_pit == 0 );

    /*-----------------------------------------------------------------*
     * Find new target for the Gaussian codebook
     *-----------------------------------------------------------------*/

    /*Generate white gaussian noise using central limit theorem method (N only 4 as E_util_random is not purely uniform)*/
    FOR( i = 0; i < L_SUBFR; i++ )
    {
        Random( seed_acelp );
        tmp32 = L_mac( 0, *seed_acelp, 1 << 9 );

        Random( seed_acelp );
        tmp32 = L_mac( tmp32, *seed_acelp, 1 << 9 );

        Random( seed_acelp );
        code[i] = mac_r( tmp32, *seed_acelp, 1 << 9 );
        move16();
    }

    /*Shape the gaussian excitation*/
    cb_shape_fx( 1, 0, 0, 1, 0, formant_enh_num, FORMANT_SHARPENING_G2, Aq, code, tilt_code, 0, 1, L_SUBFR );

    /*compute 0s memory weighted synthesis contribution and find gain*/
    E_UTIL_f_convolve( code, h, y11, L_SUBFR ); /* y11: Q8+shift */
    Scale_sig( y11, L_SUBFR, sub( 1, shift ) ); /* Q9 */
    *gain = L_deposit_l( 0 );

    /*Update correlations for gains coding */
    tmp32 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 );   /* Q18 */
    tmp32_2 = L_shr( 21474836l /*0.01f Q31*/, 31 - 18 ); /* Q18 */

    FOR( i = 0; i < L_SUBFR; i++ )
    {
        tmp32 = L_mac0( tmp32, y11[i], y11[i] );    /* Q18 */
        tmp32_2 = L_mac0( tmp32_2, y11[i], y2[i] ); /* Q18 */
    }

    tmp16 = norm_l( tmp32 );
    // To be checked
#ifdef BASOP_NOGLOB
    g_corr->y1y1 = round_fx_sat( L_shl( tmp32, tmp16 ) );
#else
    g_corr->y1y1 = round_fx( L_shl( tmp32, tmp16 ) );
#endif
    g_corr->y1y1_e = sub( 31 - 18, tmp16 );
    move16();

Loading