Commit b46163d3 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Fixes the overflow issue for file with 10dB gain.

[x] Fixes the overflow issue by using 64-bit operations
in for loop and then using the MSB for further calculations.
parent 2a322ddf
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -589,7 +589,7 @@ int16_t res_bpf_adapt(
Word16 res_bpf_adapt_fx(
    STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT stereo decoder handle */
    const Word32 *bpf_error_signal_8k,     /* i  : BPF modification signal   */
    Word32 res_buf[STEREO_DFT_N_8k]        /* i  : residual buffer           */
    Word32 res_buf[STEREO_DFT_N_8k]        /* i  : residual buffer Q12       */
)
{
    Word32 error_nrg;
@@ -601,6 +601,8 @@ Word16 res_bpf_adapt_fx(
    Word16 i_start;
    Word16 i_end;
    Word16 bw_inv;
    Word16 shift;
    Word64 W_tmp;

    IF( EQ_16( hStereoDft->res_cod_band_max, 6 ) )
    {
@@ -617,11 +619,20 @@ Word16 res_bpf_adapt_fx(

    /* Measure energy of high frequency band in MDCT domain */
    res_hb_nrg = L_deposit_l( 0 );
    W_tmp = W_deposit32_l( 0 );
    FOR( i = i_start; i < i_end; i++ )
    {
        res_hb_nrg = Madd_32_32_r( res_hb_nrg, res_buf[i], res_buf[i] );
        W_tmp = W_add_nosat( W_tmp, W_mult0_32_32( res_buf[i], res_buf[i] ) );
    }
    res_hb_nrg = L_shl( (Word32) res_hb_nrg, Q7 ); // Q0

    shift = W_norm( W_tmp );
    W_tmp = W_shl( W_tmp, shift );
    res_hb_nrg = W_extract_h( W_tmp );
    IF( GT_16( add( Q24, shift ), 32 ) )
    {
        res_hb_nrg = L_shr( res_hb_nrg, sub( add( Q24, shift ), 32 ) ); // Q0
    }

    res_hb_nrg = Mpy_32_16_1( res_hb_nrg, bw_inv );
    res_hb_nrg = L_add( Mpy_32_16_1( res_hb_nrg, STEREO_DFT_BPF_ADAPT_ALPHA_FX ), Mpy_32_16_1( hStereoDft->res_hb_nrg_mem_fx, sub( MAX_16, STEREO_DFT_BPF_ADAPT_ALPHA_FX ) ) );
    hStereoDft->res_hb_nrg_mem_fx = res_hb_nrg;