Commit f8bb73a7 authored by vaclav's avatar vaclav
Browse files

Merge branch 'voiceage/harm_gsc' into 'main'

Voiceage/harm gsc

See merge request !2645
parents 8056dfd7 e42b52a2
Loading
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -260,7 +260,8 @@ void Comp_and_apply_gain_ivas_fx(
/* _ None                                                                 */
/*========================================================================*/

static Word16 Comp_band_log_ener(                      /* o  : Band gain Q12 */
/* o  : Band gain Q12 */
static Word16 Comp_band_log_ener(
    const Word16 *pt_fx, /* i  : Dct input Q_sc */
    const Word16 Len,    /* i  : Lenght en energy accumulation */
    const Word16 Q_sc,   /* i  : scaling of input    */
@@ -269,12 +270,14 @@ static Word16 Comp_band_log_ener( /* o : Band gain Q12 */
{
    Word32 L_tmp;
    Word16 e_tmp, f_tmp, tmp16, ener_exp;

    L_tmp = Calc_Energy_Autoscaled( pt_fx, Q_sc, Len, &ener_exp );
    e_tmp = norm_l( L_tmp );
    f_tmp = Log2_norm_lc( L_shl( L_tmp, e_tmp ) );
    e_tmp = sub( sub( add( 30, E_sc ), e_tmp ), ener_exp );
    L_tmp = Mpy_32_16( e_tmp, f_tmp, 19728 ); /* Q16 */ /*log10(2) in Q17 */
    tmp16 = round_fx( L_shl( L_tmp, 12 - 2 ) );         /* Q12 -1 is to compensate Q17 */

    return tmp16;
}

@@ -283,7 +286,12 @@ 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;
@@ -311,9 +319,19 @@ void Ener_per_band_comp_fx(
        pt_fx += 32;
    }

    return;
#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*/
        move16();
        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            */
@@ -359,6 +377,7 @@ void Ener_per_band_comp_ivas_fx(

    return;
}
#endif


/*-------------------------------------------------------------------*
+13 −0
Original line number Diff line number Diff line
@@ -77,7 +77,11 @@ 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++ )
@@ -91,7 +95,11 @@ 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++ )
@@ -104,7 +112,12 @@ 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;
+27 −2
Original line number Diff line number Diff line
@@ -636,7 +636,7 @@ 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                    */
@@ -801,12 +801,19 @@ void highband_exc_dct_in_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_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++ )
@@ -1010,8 +1017,14 @@ void highband_exc_dct_in_fx(

    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              */
@@ -1168,19 +1181,29 @@ void highband_exc_dct_in_ivas_fx(
    {
        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_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 ) )
@@ -1195,9 +1218,11 @@ void highband_exc_dct_in_ivas_fx(
            }
        }
    }

    /*--------------------------------------------------------------------------------------*
     * Check potential energy excitation overshoot
     *--------------------------------------------------------------------------------------*/

    IF( bfi )
    {
        test();
+77 −33
Original line number Diff line number Diff line
@@ -56,7 +56,12 @@ void pre_echo_att_fx(
    const Word16 gsc_attack_flag_fx, /* i  : flag signalling attack encoded by AC mode (GSC)    Q0*/
    const Word16 Q_new,
    const Word16 last_coder_type, /* i  : Last coding mode        Q0*/
#ifdef FIX_1904_HARM_GSC_ENC
    const Word16 L_frame,     /* i  : Frame length            Q0*/
    const Word16 element_mode /* i  : Current IVAS element mode*/
#else
    const Word16 L_frame /* i  : Frame length            Q0*/
#endif
)
{
    Word32 etmp_fx;
@@ -68,7 +73,9 @@ void pre_echo_att_fx(
    Word16 tmp, n1, n2, exp, frac1, frac2;
    Word32 etmp1_fx;
    Word16 att_len;

#ifdef FIX_1904_HARM_GSC_ENC
    Word16 etmp_e, tmp_e;
#endif
    test();
    IF( gsc_attack_flag_fx > 0 && EQ_16( last_coder_type, AUDIO ) ) /*gsc_attack_flag_fx does not get set for all the test cases */
    {
@@ -107,6 +114,26 @@ void pre_echo_att_fx(
        IF( GT_32( etmp_fx, *Last_frame_ener_fx ) && attack_pos_fx > 0 )
        {
            /* Find the average energy before the attack */
#ifdef FIX_1904_HARM_GSC_ENC
            IF( NE_16( element_mode, EVS_MONO ) ) /* This could be harmonized with EVS, but won't be BE */
            {
                etmp_fx = sum32_fx( finc_fx, attack_pos_fx );
                etmp_e = sub( 31, add( shl( Q_new, 1 ), 1 ) );
                etmp_fx = L_add( etmp_fx, L_shr( 21474836 /*0.01 in Q31*/, etmp_e ) ); /* etmp = etmp + 0.01;   (exp = etmp_e) */
                etmp_fx = L_deposit_h( BASOP_Util_Divide3232_Scale( etmp_fx, L_mult0( attack_pos_fx, ATT_SEG_LEN ), &tmp_e ) );
                tmp_e = add( tmp_e, sub( etmp_e, 31 ) );
                etmp_e = tmp_e;
                move16();

                /* Find the correction factor and apply it before the attack */
                tmp = BASOP_Util_Divide3232_Scale( *Last_frame_ener_fx, etmp_fx, &tmp_e ); /* numerator Q = 2 * Q_new + 1;  denominator Q = 31 - tmp_e */
                tmp_e = add( tmp_e, sub( sub( 31, etmp_e ), add( shl( Q_new, 1 ), 1 ) ) ); /* tmp_e = tmp_e + (31 - tmp_e) - (2 * Q_new + 1) */
                tmp = Sqrt16( tmp, &tmp_e );
                ratio_fx = shr_sat( tmp, sub( 2, tmp_e ) ); /* Q13 */
            }
            ELSE
#endif
            {
                L_tmp = sum32_fx( finc_fx, attack_pos_fx );                  /*Q1 */
                L_tmp1 = L_shr( L_mult( attack_pos_fx, attack_pos_fx ), 1 ); /*Q0 */
                tmp = round_fx( Isqrt( L_tmp1 ) );                           /*Q15 */
@@ -133,7 +160,7 @@ void pre_echo_att_fx(

                L_tmp = Isqrt( L_tmp );
                ratio_fx = round_fx( L_shl( L_tmp, 9 ) ); /* Q13 */

            }
            /* Pre-echo atttenuation should never increase the energy */
            ratio_fx = s_min( ratio_fx, 8192 /* 1 in Q13 */ ); /* Q13 */
            FOR( i = 0; i < attack_pos_fx * ATT_SEG_LEN; i++ )
@@ -152,16 +179,32 @@ void pre_echo_att_fx(
         * In normal cases, just compute the energy of the frame
         *-------------------------------------------------------*/

#ifdef FIX_1904_HARM_GSC_ENC
        IF( NE_16( element_mode, EVS_MONO ) ) /* This could be harmonized with EVS, but won't be BE */
        {
            Word16 exp_etmp = sub( 15, Q_new );
            etmp_fx = sum2_16_exp_fx( exc_fx, L_frame, &exp_etmp, 7 ); /* Q = 31-exp_etmp */
            etmp_fx = L_shr( etmp_fx, 8 );                             /*31-exp_etmp//INV_L_FRAME = 1/256*/
            IF( EQ_16( L_frame, L_FRAME16k ) )
            {
                etmp_fx = Mpy_32_16_1( etmp_fx, 26214 /* 0.8 in Q15 */ ); /*31 - exp_etmp*/
            }
            *Last_frame_ener_fx = L_shl( etmp_fx, sub( shl( Q_new, 1 ), sub( 30 /*31-1*/, exp_etmp ) ) ); /*2*Q_new+1*/
        }
        ELSE
#endif
        {
            etmp_fx = sum2_fx( exc_fx, L_frame );                          /*2*Q_new+1 */
            etmp_fx = L_shr( etmp_fx, add( 8 + 1 - 4, shl( Q_new, 1 ) ) ); /*2*Q_new+1 //INV_L_FRAME = 1/256 -> Q4*/
            *Last_frame_ener_fx = etmp_fx;
            move32(); /*2*Q_new+1*/
        }
    }

    return;
}


#ifndef FIX_1904_HARM_GSC_ENC
void pre_echo_att_ivas_fx(
    Word32 *Last_frame_ener_fx,      /* i/o: Energy of the last frame         2*Q_new+1*/
    Word16 *exc_fx,                  /* i/o: Excitation of the current frame  Q_new*/
@@ -266,3 +309,4 @@ void pre_echo_att_ivas_fx(

    return;
}
#endif
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
#define FIX_2274_OOB_INDEXING_IN_CORRMATRIX             /* FhG: fix OOB indexing complaint */
#define FIX_2278_OOB_INDEXING_IN_CLOSED_LOOP_PIT_SEARCH /* FhG: fix oob indexing USAN complaint */
#define FIX_2287_MCT_MDCT_STEREO_DATA_MALLOC_SIZE       /* FhG: correct allocation size for STEREO_MDCT_DEC_DATA struct */
#define FIX_1904_HARM_GSC_ENC                           /* VA: #1904 Harmonization of EVS and IVAS GSC code */

/* #################### End BE switches ################################## */

Loading