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

Merge branch 'fix_10dBgain_file_crash_issue' into 'main'

Fixes the overflow issue for file with 10dB gain.

See merge request !38
parents 2a322ddf 97479730
Loading
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -57,7 +57,8 @@ void sns_compute_scf_fx(
    Word32 *scf )
{
    Word16 i, n, k;
    Word32 x[FDNS_NPTS], xs[FDNS_NPTS], sum, mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS];
    Word32 x[FDNS_NPTS], xs[FDNS_NPTS], mean, xl4[SNS_NPTS], nf, xl[FDNS_NPTS];
    Word64 sum;
    Word32 L_tmp;
    const Word16 *pow_tilt;
    const UWord8 nBands = pPsychParams->nBands;
@@ -139,8 +140,11 @@ void sns_compute_scf_fx(
    }

    /* Noise floor at -40dB */
    sum = sum32_fx( xs, FDNS_NPTS );
    mean = L_shr( sum, 6 );
    sum = 0;
    for (Word16 ind = 0; ind < FDNS_NPTS; ind++) {
        sum += (Word64)xs[i];
    }
    mean = (Word32)(sum >> 6);

    nf = Mpy_32_16_1( mean, 3 ); // 3 => powf( 10.0f, -4.0f ) in Q15
    nf = L_max( nf, 0 );         // 0 => powf( 2.0f, -32.0f ) in Q15
@@ -198,8 +202,11 @@ void sns_compute_scf_fx(
    xl4[SNS_NPTS - 1] = L_tmp;

    /* Remove mean and scaling */
    sum = sum32_fx( xl4, SNS_NPTS );
    mean = L_shr( sum, 4 );
    sum = 0;
    for (Word16 ind = 0; ind < SNS_NPTS; ind++) {
        sum += (Word64)xl4[i];
    }
    mean = (Word32)(sum >> 4);

    FOR( i = 0; i < SNS_NPTS; i++ )
    {
+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;
+11 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
#include "wmc_auto.h"
#ifdef IVAS_FLOAT_FIXED
#include "ivas_prot_fx.h"
#include "prot_fx2.h"
#endif // IVAS_FLOAT_FIXED


@@ -1214,9 +1215,18 @@ void TonalMdctConceal_whiten_noise_shape_ivas(
        Word32 whitenend_noise_shape_fx[L_FRAME16k];
        Word32 scfs_int_fx[FDNS_NPTS], scfs_bg_fx[FDNS_NPTS];

        Word16 q = 31;
        FOR( Word16 k = 0; k < L_FRAME16k; k++ )
        {
            whitenend_noise_shape_fx[k] = (Word32) ( whitenend_noise_shape[k] * ONE_IN_Q7 );
            if(abs((Word32)whitenend_noise_shape[k])!=0) q = s_min(q, norm_l( whitenend_noise_shape[k] ));
        }

        q -= find_guarded_bits_fx(L_frame) + 2;
        //q -= 1;

        FOR( Word16 k = 0; k < L_FRAME16k; k++ )
        {
            whitenend_noise_shape_fx[k] = q>=0 ? ((Word32) ( whitenend_noise_shape[k] *(1<< q) )):((Word32) ( whitenend_noise_shape[k] / (1<< q) ));
        }

        sns_compute_scf_fx( whitenend_noise_shape_fx, psychParams, L_frame, scf_fx );