Commit de111a2c authored by vaillancour's avatar vaillancour
Browse files

proposed fix to 2380, issue with Q_exc being possibly too high when coming from CNG

parent 5324fe7c
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -70,12 +70,19 @@ static Word16 VDQ_vec_fx( Word16 *Qvec_out_fx, const Word16 *mean_dic_fx, const
/* _ None                                                                 */
/*========================================================================*/

#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
Word16 Comp_and_apply_gain_fx(
#else
void Comp_and_apply_gain_fx(
#endif
    Word16 exc_diffQ[],      /* i/o: Quantized excitation                  */
    Word16 Ener_per_bd_iQ[], /* i  : Target ener per band              Q13 */
    Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector   i->Q13/o->Q13 */
    Word16 Mbands_gn,        /* i  : number of bands                       */
    const Word16 ReUseGain,  /* i  : Reuse the gain in Ener_per_bd_yQ      */
#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
    const Word16 max_lt_ener, /* i  : max_lt_ener of lt_ener_per_band_fx   */
#endif
    Word16 Qexc_diff,
    Word16 Q_exc )
{
@@ -83,6 +90,9 @@ void Comp_and_apply_gain_fx(
    Word16 StartBin, NB_Qbins;
    Word16 y_gain;
    Word16 L16, frac, exp1, tmp_exp;
#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
    Word16 Q_adapt;
#endif
    Word32 L32;

    /* Recreate excitation for local synthesis and decoder */
@@ -92,6 +102,16 @@ void Comp_and_apply_gain_fx(
    move16();

    tmp_exp = add( 14, sub( Q_exc, Qexc_diff ) ); /* In case of reuse, it can be computed outside the loop*/
#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
    Q_adapt = 0;
    move16();
    test();
    test();
    IF( GT_16( Q_exc, 3 ) && EQ_16( ReUseGain, 0 ) && GT_16( max_lt_ener, 8192 /* 13 bits */ ) ) /* When lt_energy is high, Q_exc shouldn't be high too, addresses cases when switching from CNG */
    {
        Q_adapt = sub( 3 - 1, Q_exc ); /* add extra 1 bit headroom */
    }
#endif
    FOR( i_band = 0; i_band < Mbands_gn; i_band++ )
    {
        StartBin = add( StartBin, NB_Qbins );
@@ -126,7 +146,9 @@ void Comp_and_apply_gain_fx(
            Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) );
            move16(); /*Q1     */
            tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) );

#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
            tmp_exp = add( tmp_exp, Q_adapt );
#endif
            FOR( i = StartBin; i < NB_Qbins + StartBin; i++ )
            {
                L32 = L_mult( exc_diffQ[i], y_gain );                     /*Qexc_diff+15 */
@@ -135,8 +157,11 @@ void Comp_and_apply_gain_fx(
            }
        }
    }

#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
    return add( Q_exc, Q_adapt );
#else
    return;
#endif
}
#ifndef FIX_2338_HARM_GSC_GAIN_COMP

+33 −3
Original line number Diff line number Diff line
@@ -1081,6 +1081,9 @@ void highband_exc_dct_in_ivas_fx(
    Word16 frac, exp, tmp1;
    Word16 tmp2;
    Word16 *end, Q_hb_exc;
#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
    Word16 max_lt_ener, old_Q_exc;
#endif

    FOR( j = 10; j < MBANDS_GN; j++ )
    {
@@ -1364,10 +1367,9 @@ void highband_exc_dct_in_ivas_fx(
            move16();
        }
    }
#ifndef FIX_2338_HARM_GSC_GAIN_COMP
#if !defined FIX_2338_HARM_GSC_GAIN_COMP && !defined FIX_2380_HARM_GSC_GAIN_COMP_FX
    IF( EQ_16( element_mode, EVS_MONO ) )
    {
#endif
        Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc );

        IF( exc_wo_nf != NULL )
@@ -1375,7 +1377,6 @@ void highband_exc_dct_in_ivas_fx(
            Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc );
            Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
        }
#ifndef FIX_2338_HARM_GSC_GAIN_COMP
    }
    ELSE
    {
@@ -1406,7 +1407,36 @@ void highband_exc_dct_in_ivas_fx(
            Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, Q_old ) );
        }
    }
#elif defined FIX_2380_HARM_GSC_GAIN_COMP_FX
    max_lt_ener = 0;
    move16();
    IF( NE_16( element_mode, EVS_MONO ) ) /* to keep EVS BE */
    {
        FOR( i = 0; i < MBANDS_GN; i++ )
        {
            max_lt_ener = s_max( max_lt_ener, lt_ener_per_band_fx[i] );
        }
    }
    old_Q_exc = *Q_exc;
    move16();
    *Q_exc = Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, max_lt_ener, Qexc_diffQ, *Q_exc );
    Scale_sig( exc_dct_in, L_frame, sub( *Q_exc, old_Q_exc ) );

    IF( exc_wo_nf != NULL )
    {
        Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, max_lt_ener, Qexc_diffQ, *Q_exc );
        Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
    }
#else /* #if defined FIX_2338_HARM_GSC_GAIN_COMP */
    Comp_and_apply_gain_fx( exc_diffQ, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 0, Qexc_diffQ, *Q_exc );

    IF( exc_wo_nf != NULL )
    {
        Comp_and_apply_gain_fx( exc_wo_nf, Ener_per_bd_iQ, Ener_per_bd_yQ, last_bin, 1, Qexc_diffQ, *Q_exc );
        Vr_add( exc_dct_in, exc_wo_nf, exc_wo_nf, L_frame );
    }
#endif

    /*--------------------------------------------------------------------------------------*
     * add the correction layer to the LF bins,
     * and add the quantized pulses or the noise for the higher part of the spectrum
+1 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@

#define FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT  /* Dolby: Issue 2250:  random vector generation in GenShapedSHBExcitation() */
#define FIX_2338_HARM_GSC_GAIN_COMP                     /* VA: basop issue 2338: harmonization of band gain computation for both EVS and IVAS */
#define FIX_2380_HARM_GSC_GAIN_COMP_FX                  /* VA: basop issue 2380 & 2381: Fix issue when switching from CNG low energy to active content with high energy */
#define FIX_BASOP_2317_UNINIT_VALUE_IN_STEREO_CNG       /* Eri: Basop issue 2317: Uninitialized value read in case of DTX and BW switching   */

/* ##################### End NON-BE switches ########################### */
+11 −3
Original line number Diff line number Diff line
@@ -1703,14 +1703,22 @@ void Ener_per_band_comp_ivas_fx(
    const Word16 L_frame        /* i  : frame length                      */
);
#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
Word16 Comp_and_apply_gain_fx(
#else
void Comp_and_apply_gain_fx(
#endif
    Word16 exc_diffQ[],      /* i/o: Quantized excitation                  */
    Word16 Ener_per_bd_iQ[], /* i  : Target ener per band              Q13 */
    Word16 Ener_per_bd_yQ[], /* i/o: Ener per band for norm vector   i->Q13/o->Q13 */
    Word16 Mbands_gn,        /* i  : number of bands                       */
    const Word16 ReUseGain,  /* i  : Reuse the gain in Ener_per_bd_yQ      */
#ifdef FIX_2380_HARM_GSC_GAIN_COMP_FX
    const Word16 max_lt_ener, /* i  : max_lt_ener of lt_ener_per_band_fx   */
#endif
    Word16 Qexc_diff,
    Word16 Q_exc );
#ifndef FIX_2338_HARM_GSC_GAIN_COMP
void Comp_and_apply_gain_ivas_fx(
    Word16 exc_diffQ[],      /* i/o: Quantized excitation                  */