Commit 1dda7b9e authored by multrus's avatar multrus
Browse files

[cleanup] accept FIX_1904_HARM_GSC_ENC

parent 702b9316
Loading
Loading
Loading
Loading
+0 −53
Original line number Diff line number Diff line
@@ -343,12 +343,8 @@ void Ener_per_band_comp_fx(
    Word16 y_gain4_fx[],        /* o  : Energy per band to quantize       Q12            */
    const Word16 Q_exc,         /* i  : frame length                      */
    const Word16 Mband,         /* i  : Max band                          */
#ifdef FIX_1904_HARM_GSC_ENC
    const Word16 Eflag,  /* i  : flag of highest band              */
    const Word16 L_frame /* i  : frame length                      */
#else
    const Word16 Eflag /* i  : flag of highest band              */
#endif
)
{
    const Word16 *pt_fx;
@@ -376,7 +372,6 @@ void Ener_per_band_comp_fx(
        pt_fx += 32;
    }

#ifdef FIX_1904_HARM_GSC_ENC
    IF( EQ_16( L_frame, L_FRAME16k ) )
    {
        y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/
@@ -384,57 +379,9 @@ void Ener_per_band_comp_fx(
        y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/
        move16();
    }
#endif

    return;
}
#ifndef FIX_1904_HARM_GSC_ENC
void Ener_per_band_comp_ivas_fx(
    const Word16 exc_diff_fx[], /* i  : target signal                     Q_exc_diff     */
    Word16 y_gain4_fx[],        /* o  : Energy per band to quantize       Q12            */
    const Word16 Q_exc,         /* i  : frame length                      */
    const Word16 Mband,         /* i  : Max band                          */
    const Word16 Eflag,         /* i  : flag of highest band              */
    const Word16 L_frame        /* i  : frame length                */
)
{
    const Word16 *pt_fx;
    Word16 j;

    pt_fx = exc_diff_fx;
    FOR( j = 0; j < 2; j++ )
    {
        y_gain4_fx[j] = Comp_band_log_ener( pt_fx, 8, Q_exc, 1 ); /*Q12*/
        move16();
        pt_fx += 8;
    }

    FOR( j = 1; j < Mband - 2; j++ )
    {
        y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 16, Q_exc, 0 ); /*Q12*/
        move16();
        pt_fx += 16;
    }

    IF( EQ_16( Eflag, 1 ) )
    {
        y_gain4_fx[j + 1] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/
        move16();
        pt_fx += 32;
    }

    IF( EQ_16( L_frame, L_FRAME16k ) )
    {
        y_gain4_fx[j + 2] = Comp_band_log_ener( pt_fx, 32, Q_exc, -1 ); /*Q12*/
        move16();
        y_gain4_fx[j + 3] = Comp_band_log_ener( pt_fx, 64, Q_exc, -1 ); /*Q12*/
        move16();
        pt_fx += 64;
    }

    return;
}
#endif


/*-------------------------------------------------------------------*
+0 −12
Original line number Diff line number Diff line
@@ -77,11 +77,7 @@ void Inac_switch_ematch_fx(
    test();
    IF( ( EQ_16( coder_type, AUDIO ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( tdm_low_rate_mode, 1 ) ) ) && bfi == 0 )
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#endif

        /* reset long-term energy per band */
        FOR( i = 0; i < MBANDS_GN; i++ )
@@ -95,11 +91,7 @@ void Inac_switch_ematch_fx(
        /* Find spectrum and energy per band for GC and VC frames */
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );

#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#endif

        /* reset long-term energy per band */
        FOR( i = 0; i < MBANDS_GN; i++ )
@@ -113,11 +105,7 @@ void Inac_switch_ematch_fx(
        /* Find spectrum and energy per band for inactive frames */
        edct_16fx( exc2, dct_exc_tmp, L_frame, 5, element_mode );

#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( dct_exc_tmp, Ener_per_bd, Q_exc, MBANDS_GN, 1, L_frame );
#endif

        /* More agressive smoothing in the first 50 frames */
        pt_exc = dct_exc_tmp;
+0 −394
Original line number Diff line number Diff line
@@ -636,395 +636,9 @@ static void envelop_modify_fx(

    return;
}
#ifndef FIX_1904_HARM_GSC_ENC
void highband_exc_dct_in_fx(
    const Word32 core_brate,         /* i  : core bitrate                            */
    const Word16 *mfreq_bindiv,      /* i  : bin per bands tables                    */
    Word16 last_bin,                 /* i  : last bin of bit allocation              */
    Word16 Diff_len,                 /* i  : number of bin before cut-off frequency  */
    Word16 noise_lev,                /* i  : pulses dynamic                          */
    Word16 pit_band_idx,             /* i  : bin position of the cut-off frequency   */
    Word16 *exc_diffQ,               /* i  : frequency coefficients of per band      */
    Word16 *seed_tcx,                /* i  : Seed for noise                          */
    Word16 *Ener_per_bd_iQ,          /* i  : Quantized energy of targeted vector     */
    Word16 nb_subfr,                 /* i  : Number of subframe considered           */
    Word16 *exc_dct_in,              /* o  : dct of residual signal                  */
    Word16 last_coder_type,          /* i  : coding type of last frame               */
    Word16 *bitallocation_band,      /* i  : bit allocation flag of each band        */
    const Word16 *lsf_new,           /* i  : LSFs at the end of the frame            */
    Word16 *last_exc_dct_in,         /* i  : dct of residual signal of last frame    */
    Word16 *last_ener,               /* i  : frequency energy  of last frame         */
    Word16 *last_bitallocation_band, /* i  : bit allocation flag of each band  of last frame   */
    Word16 *bitallocation_exc,       /* i  : flag of decoded coefficients            */
    Word16 bfi,                      /* i  : bad frame indicator                     */
    const Word16 coder_type,         /* i  : coder type                              */
    Word16 bwidth,
    Word16 *exc_wo_nf, /* o  : temporal excitation (in f domain) without noisefill   */
    Word16 Qexc_diffQ,
    Word16 Q_exc,
    const Word16 GSC_noisy_speech,
    Word16 *lt_ener_per_band_fx, /* i/o: Average per band energy                 */
    const Word16 L_frame,        /* i  : frame length                            */
    const Word16 element_mode,   /* i  : IVAS element mode                       */
    const Word16 GSC_IVAS_mode   /* i  : GSC IVAS mode                           */
)
{
    Word16 i, j, k;
    Word16 MAX_Bin = 0;
    Word16 last_bin_tmp, ener = 0;
    move16();
    Word16 noisepb[MBANDS_GN16k];
    Word16 Ener_per_bd_yQ[MBANDS_GN16k];
    Word16 *src, *dst;
    Word32 L_tmp;
    Word16 length_bin, bwe_flag = 0, tmp;
    move16();
    Word16 frac, exp, tmp1;
    Word16 tmp2;
    Word16 *end, Q_hb_exc;

    FOR( j = 10; j < MBANDS_GN; j++ )
    {
        /*  ener += (float)pow(10, Ener_per_bd_iQ[j]);
            ener += (float)pow(2, 3.321928*Ener_per_bd_iQ[j]); */

        L_tmp = L_mult( Ener_per_bd_iQ[j], 27213 ); /* 3.321928 in Q13 -> Q27 */
        L_tmp = L_shr( L_tmp, 10 );                 /* From Q27 to Q16 */

        frac = L_Extract_lc( L_tmp, &exp );  /* Extract exponent of L_tmp */
        tmp = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */
        /* output of Pow2() will be: */
        /* 16384 < Pow2() <= 32767 */
        exp = sub( exp, 14 );
        tmp1 = shl_sat( tmp, exp );
        move16();
        ener = add_sat( tmp1, ener ); /*Q0 */
    }

    test();
    IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
    {
        if ( NE_16( last_coder_type, AUDIO ) )
        {
            *last_ener = ener;
            move16();
        }
        test();
        test();
        IF( ( GT_16( last_bin, 8 ) || Diff_len != 0 ) && EQ_16( last_coder_type, AUDIO ) )
        {
            MAX_Bin = 10;
            move16();
            bwe_flag = 1;
            move16();
        }
        ELSE
        {
            MAX_Bin = 15;
            move16();
        }

        last_bin_tmp = last_bin;
        move16();
        last_bin = s_max( last_bin, MAX_Bin );
        last_bin = add( last_bin, 1 );
    }
    ELSE
    {
        IF( EQ_16( L_frame, L_FRAME16k ) )
        {
            last_bin = MBANDS_GN16k;
            move16();
        }
        ELSE
        {
            last_bin = MBANDS_GN;
            move16();
        }
        last_bin_tmp = last_bin;
        move16();
    }

    test();
    test();
    test();
    test();
    IF( bfi || LT_32( core_brate, 6000 ) || ( LT_32( core_brate, 8600 ) && EQ_16( coder_type, UNVOICED ) ) )
    {
        set16_fx( noisepb, 13107, last_bin ); /*0.4 in Q15 */
    }
    ELSE IF( EQ_16( GSC_IVAS_mode, 3 ) || ( GSC_IVAS_mode > 0 && EQ_16( GSC_noisy_speech, 1 ) ) )
    {
        set16_fx( noisepb, 13107 /*0.4f*/, last_bin );
    }
    ELSE
    {
        EstimateNoiseLevel_fx( noisepb, core_brate, Diff_len, last_bin, coder_type, noise_lev, pit_band_idx, last_bin_tmp, bwidth, L_frame );
    }

    IF( exc_wo_nf != NULL )
    {
        Copy( exc_diffQ, exc_wo_nf, L_frame );
    }

    test();
    test();
    test();
    IF( GSC_IVAS_mode == 0 && GSC_noisy_speech && !bfi && LE_16( element_mode, IVAS_SCE ) )
    {
        set16_fx( noisepb, 3277, last_bin );
    }
    test();
    IF( LT_32( core_brate, 6000 ) && LE_16( coder_type, UNVOICED ) )
    {
        FOR( i = 0; i < L_frame; i++ )
        {
            IF( exc_diffQ[i] == 0 )
            {
                /* exc_diffQ[i] += 2.0f * noisepb[0] * ((float)own_random(seed_tcx) / PCM16_TO_FLT_FAC);*/
                tmp = mult( shl( noisepb[0], 1 ), Random( seed_tcx ) ); /*Q15 */
                tmp = shr( tmp, sub( 15, Qexc_diffQ ) );                /*qNoise_fac */
                exc_diffQ[i] = add( exc_diffQ[i], tmp );
                move16(); /*Q */
            }
        }
    }
    ELSE
    {
        Apply_NoiseFill_fx( exc_diffQ, seed_tcx, noisepb, Diff_len, last_bin, coder_type, mfreq_bindiv, Qexc_diffQ );
    }
    /*--------------------------------------------------------------------------------------*
     * Quantize average gain
     * Subtract Q averaged gain
     * VQ of remaining gain per band
     *--------------------------------------------------------------------------------------*/
    test();
    IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
#else
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0 );
#endif
    }
    ELSE
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1 );
#endif
        IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
        {
            FOR( i = L_FRAME - 16; i < L_FRAME; i++ )
            {
                /*exc_diffQ[i] *= 0.067f * i - 15.0f; = -15 - (-0.067f * i) */
                tmp = msu_r( -7680 * 65536, -17564, shl( i, 6 ) );  /*-15 in Q9; -0.067 in Q18 and i in Q6= Q9 */
                L_tmp = L_mult( exc_diffQ[i], tmp );                /*Q(Qexc_diffQ+10) */
                exc_diffQ[i] = round_fx( L_shl( L_tmp, 16 - 10 ) ); /*Qexc_diffQ */
                move16();
            }
        }
    }
    /*--------------------------------------------------------------------------------------*
     * Check potential energy excitation overshoot
     *--------------------------------------------------------------------------------------*/
    IF( bfi )
    {
        test();
        IF( GSC_noisy_speech == 0 && GT_16( coder_type, UNVOICED ) ) /* Here coder_type == last_coder_type because of the bfi */
        {
            FOR( i = 0; i < last_bin; i++ )
            {
                Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( sub( lt_ener_per_band_fx[i], 154 ), Ener_per_bd_yQ[i] ) );
                move16();
                lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
                move16();
            }
            FOR( ; i < MBANDS_GN; i++ )
            {
                Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( lt_ener_per_band_fx[i], 154 ) );
                move16();
                lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
                move16();
            }
        }
        ELSE
        {
            FOR( i = 0; i < last_bin; i++ )
            {
                Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], sub( add( lt_ener_per_band_fx[i], 1229 ), Ener_per_bd_yQ[i] ) );
                move16();
                lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
                move16();
            }
            FOR( ; i < MBANDS_GN; i++ )
            {
                Ener_per_bd_iQ[i] = s_min( Ener_per_bd_iQ[i], add( lt_ener_per_band_fx[i], 1229 ) );
                move16();
                lt_ener_per_band_fx[i] = sub( lt_ener_per_band_fx[i], 77 );
                move16();
            }
        }
    }
    /*--------------------------------------------------------------------------------------*
     * Apply decoded gain onto the difference signal
     *--------------------------------------------------------------------------------------*/

    IF( GSC_noisy_speech )
    {
        FOR( i = 0; i < L_frame; i++ )
        {
            exc_diffQ[i] = mult_r( exc_diffQ[i], 29491 );
            move16();
        }
    }

    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 );
    }
    /*--------------------------------------------------------------------------------------*
     * add the correction layer to the LF bins,
     * and add the quantized pulses or the noise for the higher part of the spectrum
     * (non valuable temporal content already zeroed)
     * DC is Zeroed
     *--------------------------------------------------------------------------------------*/

    Vr_add( exc_dct_in, exc_diffQ, exc_dct_in, L_frame );
    test();
    IF( core_brate == ACELP_8k00 && bwidth != NB )
    {
        IF( EQ_16( bwe_flag, 1 ) )
        {
            last_bin = sub( last_bin, 1 );
            tmp = i_mult( MAX_Bin, 16 );
            tmp1 = i_mult( last_bin, 16 );
            src = &exc_diffQ[L_FRAME - 1];
            move16();
            dst = &exc_dct_in[( tmp - 1 )];
            move16();
            end = &exc_diffQ[( tmp1 - 1 )];
            move16();

            WHILE( src > end )
            {
                *src-- = *dst--;
                move16();
            }
            test();
            test();
            if ( ( bitallocation_exc[0] != 0 || bitallocation_exc[1] != 0 ) && EQ_32( core_brate, ACELP_8k00 ) )
            {
                exc_diffQ[160] = 0;
                move16();
            }

            Q_hb_exc = 0;
            move16();
            envelop_modify_fx( exc_diffQ, seed_tcx, last_bin, Ener_per_bd_iQ, Q_exc, &Q_hb_exc );
            Copy_Scale_sig( &exc_diffQ[tmp1], &exc_dct_in[tmp1], sub( L_FRAME, tmp1 ), sub( Q_exc, Q_hb_exc ) ); /* from Q_hb_exc -> Q_exc as expected */
        }

        IF( LT_16( nb_subfr, 4 ) )
        {
            FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ )
            {
                /*exc_dct_in[i] *= (0.067f*i-15.f); */
                tmp = mult_r( 17564, shl( i, 6 ) );                    /*0.067 in Q18 and i in Q6= Q9 */
                tmp = sub( tmp, 7680 );                                /*15 in Q9 = Q9 */
                L_tmp = L_mult( exc_dct_in[i], tmp );                  /*Q(Q_exc+10) */
                exc_dct_in[i] = round_fx_sat( L_shl_sat( L_tmp, 6 ) ); /*Q_exc */
            }
        }

        tmp1 = mult_r( ener, 16384 );
        tmp1 = sub( *last_ener, tmp1 );
        tmp = mult_r( *last_ener, 16384 );
        tmp = sub( ener, tmp );
        test();
        IF( tmp > 0 && tmp1 > 0 )
        {
            length_bin = 6;
            move16();
            IF( last_coder_type != AUDIO )
            {
                set16_fx( last_bitallocation_band, 0, 6 );
                Copy( &exc_dct_in[( 4 + length_bin ) * 16], &last_exc_dct_in[( 4 + length_bin ) * 16], length_bin * 16 );
            }

            FOR( i = 4; i < ( 4 + length_bin ); i++ )
            {
                test();
                IF( !( bitallocation_band[i] == 0 && last_bitallocation_band[i - 4] == 0 ) )
                {
                    k = shl( add( i, length_bin ), 4 );
                    src = &exc_dct_in[k]; /*(i+length_bin)*16*/
                    dst = &last_exc_dct_in[k];
                    FOR( j = 0; j < 16; j++ )
                    {
                        tmp = mult_r( 10923, abs_s( *src ) );
                        tmp1 = mult_r( 10923, abs_s( *dst ) );

                        IF( GT_16( tmp, abs_s( *dst ) ) )
                        {
                            tmp2 = *src;
                            *src = mult_r( 16384, sub_sat( *src, abs_s( *dst ) ) ); /*Q_exc */
                            move16();
                            tmp = mult_r( 16384, add_sat( tmp2, abs_s( *dst ) ) ); /*Q_exc */
                            if ( tmp2 > 0 )
                            {
                                *src = tmp;
                                move16();
                            }
                        }
                        ELSE IF( GT_16( tmp1, abs_s( *src ) ) )
                        {
                            tmp = mult_r( *src, 22938 );
                            tmp1 = mult_r( 9830, abs_s( *dst ) );
                            tmp2 = *src;
                            *src = sub( tmp, tmp1 ); /*Q_exc */
                            move16();
                            if ( tmp2 > 0 )
                            {
                                *src = add( tmp, tmp1 ); /*Q_exc */
                                move16();
                            }
                        }
                        src++;
                        dst++;
                    }
                }
            }
        }
        IF( EQ_16( bwe_flag, 1 ) )
        {
            Decreas_freqPeak_fx( lsf_new, exc_dct_in, 9830 );
        }
        ELSE
        {
            Decreas_freqPeak_fx( lsf_new, exc_dct_in, 16384 );
        }
    }

    Copy( &exc_dct_in[64], &last_exc_dct_in[64], L_frame - 64 );
    Copy( &bitallocation_band[4], last_bitallocation_band, 6 );
    *last_ener = ener;
    move16();

    return;
}
#endif


#ifdef FIX_1904_HARM_GSC_ENC
void highband_exc_dct_in_fx(
#else
void highband_exc_dct_in_ivas_fx(
#endif
    const Word32 core_brate,         /* i  : core bitrate                            */
    const Word16 *mfreq_bindiv,      /* i  : bin per bands tables                    */
    Word16 last_bin,                 /* i  : last bin of bit allocation              */
@@ -1194,19 +808,11 @@ void highband_exc_dct_in_ivas_fx(
    test();
    IF( EQ_32( core_brate, ACELP_8k00 ) && NE_16( bwidth, NB ) )
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
#else
        Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, add( last_bin, 1 ), 0, L_frame );
#endif
    }
    ELSE
    {
#ifdef FIX_1904_HARM_GSC_ENC
        Ener_per_band_comp_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
#else
        Ener_per_band_comp_ivas_fx( exc_diffQ, Ener_per_bd_yQ, Qexc_diffQ, MBANDS_GN, 1, L_frame );
#endif

        test();
        IF( LT_16( nb_subfr, 4 ) && LT_16( L_frame, L_FRAME16k ) )
+0 −116

File changed.

Preview size limit exceeded, changes collapsed.

+0 −1
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@
#define FIX_1990_SANITIZER_IN_REVERB_LOAD               /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */
#define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR      /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */
#define NONBE_1122_KEEP_EVS_MODE_UNCHANGED              /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR.  */
#define FIX_1904_HARM_GSC_ENC                           /* VA: #1904 Harmonization of EVS and IVAS GSC code */
#define FIX_2388_INITTNSCONFIGURATION                   /* FhG: issue 2388 : harmonizing InitTnsConfiguration() function */
#define FIX_2397_COPY_AQ_MDCT_CORE_BFI                  /* FhG: prevent copying of uninit memory in MDCT stereo core if bfi is set */
#define HARMONIZE_TBE                                   /* VA: harmonize core-coder TBE function duplications */
Loading