Commit 3b48390e authored by vaclav's avatar vaclav
Browse files

harmonize wb_bwe_enc_fx()

parent 7dcf3817
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@
#define FIX_1904_HARM_GSC_ENC                           /* VA: #1904 Harmonization of EVS and IVAS GSC code */
#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 */
#define HARM_FD_BWE                                     /* VA: harmonize core-coder FD BWE function duplications */

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

+4 −0
Original line number Diff line number Diff line
@@ -438,7 +438,11 @@ ivas_error evs_enc_fx(
    ELSE IF( EQ_16( st->extl, WB_BWE ) )
    {
        /* WB BWE encoder */
#ifdef HARM_FD_BWE
        wb_bwe_enc_fx( st, new_inp_resamp16k );
#else
        wb_bwe_enc_fx( st, new_inp_resamp16k, st->coder_type );
#endif
    }

    /*---------------------------------------------------------------------*
+4 −0
Original line number Diff line number Diff line
@@ -645,7 +645,11 @@ ivas_error ivas_core_enc_fx(
        ELSE IF( EQ_16( st->extl, WB_BWE ) && n == 0 && NE_16( st->element_mode, IVAS_CPE_MDCT ) )
        {
            /* WB BWE encoder */
#ifdef HARM_FD_BWE
            wb_bwe_enc_fx( st, new_inp_resamp16k_fx[n] );
#else
            wb_bwe_enc_ivas_fx( st, new_inp_resamp16k_fx[n] );
#endif
        }

        /*---------------------------------------------------------------------*
+2 −17
Original line number Diff line number Diff line
@@ -669,12 +669,14 @@ void vad_param_updt_fx(
);

void wb_bwe_enc_fx(
#ifndef HARM_FD_BWE
    Encoder_State *st_fx,           /* i/o: encoder state structure                  */
    const Word16 *new_wb_speech_fx, /* i  : original i   signal at 16kHz             */
    Word16 coder_type               /* i  : coding type                              */
);

void wb_bwe_enc_ivas_fx(
#endif
    Encoder_State *st_fx,          /* i/o: encoder state structure                  */
    const Word16 *new_wb_speech_fx /* i  : original i   signal at 16kHz             */
);
@@ -981,23 +983,6 @@ void set_bw_stereo_fx(
    CPE_ENC_HANDLE hCPE /* i/o: CPE encoder structures     */
);

/* o  : classification of wb signal            */
Word16 WB_BWE_encoding_fx(
    const Word16 coder_type, /* i  : coder type                             */
    const Word16 *yos_fx,    /* i  : MDCT coefficients of weighted original */
    Word16 *WB_fenv_fx,      /* i/o: energy of WB envelope                  */
    Encoder_State *st_fx,    /* i/o: Encoder structure                      */
    Word16 Q_synth,
    Word16 Q_synth_lf );

/* o  : classification of wb signal            */
Word16 WB_BWE_encoding_ivas_fx(
    Encoder_State *st_fx, /* i/o: Encoder structure                      */
    const Word32 *yos_fx, /* i  : MDCT coefficients of weighted original */
    Word16 *WB_fenv_fx,   /* i/o: energy of WB envelope                  */
    Word16 Q_synth,
    Word16 Q_synth_lf );

void calculate_hangover_attenuation_gain_fx(
    Encoder_State *st,          /* i  : encoder state structure         */
    Word16 *att,                /* o  : attenuation factor              */
+114 −73
Original line number Diff line number Diff line
@@ -11,39 +11,23 @@
#include "prot_fx_enc.h" /* Function prototypes                    */

/*---------------------------------------------------------------------*
 * Local functions
 * Local functions declarations
 *---------------------------------------------------------------------*/

static Word16 SWB_BWE_encoding_fx(
    Encoder_State *st_fx,      /* i/o: encoder state structure   */
    Word16 *insig_fx,          /* i/o: delayed original input signal at 32kHz (might be rescaled)*/
    const Word16 *insig_lp_fx, /* i  : delayed original lowband input signal at 32kHz */
    const Word16 *insig_hp_fx, /* i  : delayed original highband input signal at 32kHz */
    const Word16 *synth_fx,    /* i  : delayed ACELP core synthesis at 12.8kHz */
    const Word16 *yos_fx,      /* i  : MDCT coefficients of the windowed original input signal at 32kHz */
    Word16 *SWB_fenv_fx,       /* o  : frequency-domain quantized BWE envelope */
    const Word16 tilt_nb_fx,   /* i  : SWB tilt */
    const Word16 st_offset,    /* i  : start frequency offset for BWE envelope */
    const Word16 coder_type,   /* i  : coding type                              */
    Word16 Q_insig_lp,
    Word16 Q_shb,
    Word16 Q_synth,
    Word16 Q_synth_lf );
static Word16 WB_BWE_encoding_fx( const Word16 coder_type, const Word16 *yos_fx, Word16 *WB_fenv_fx, Encoder_State *st_fx, const Word16 Q_synth, const Word16 Q_synth_lf );

static Word16 SWB_BWE_encoding_ivas_fx(
    Encoder_State *st_fx,      /* i/o: encoder state structure   */
    Word16 *insig_fx,          /* i/o: delayed original input signal at 32kHz (might be rescaled)*/
    const Word16 *insig_lp_fx, /* i  : delayed original lowband input signal at 32kHz */
    const Word16 *insig_hp_fx, /* i  : delayed original highband input signal at 32kHz */
    const Word16 *synth_fx,    /* i  : delayed ACELP core synthesis at 12.8kHz */
    const Word32 *yos_fx,      /* i  : MDCT coefficients of the windowed original input signal at 32kHz */
    Word16 *SWB_fenv_fx,       /* o  : frequency-domain quantized BWE envelope */
    const Word16 tilt_nb_fx,   /* i  : SWB tilt */
    const Word16 st_offset,    /* i  : start frequency offset for BWE envelope */
    Word16 Q_insig_lp,
    Word16 Q_shb,
    Word16 Q_synth,
    Word16 Q_synth_lf );
static Word16 WB_BWE_encoding_fx_32( Encoder_State *st_fx, const Word32 *yos_fx, Word16 *WB_fenv_fx, const Word16 Q_synth, const Word16 Q_synth_lf );

static Word16 SWB_BWE_encoding_fx( Encoder_State *st_fx, Word16 *insig_fx, const Word16 *insig_lp_fx, const Word16 *insig_hp_fx, const Word16 *synth_fx, const Word16 *yos_fx, Word16 *SWB_fenv_fx, const Word16 tilt_nb_fx, const Word16 st_offset, const Word16 coder_type, const Word16 Q_insig_lp, const Word16 Q_shb, const Word16 Q_synth, const Word16 Q_synth_lf );

static Word16 SWB_BWE_encoding_fx_32( Encoder_State *st_fx, Word16 *insig_fx, const Word16 *insig_lp_fx, const Word16 *insig_hp_fx, const Word16 *synth_fx, const Word32 *yos_fx, Word16 *SWB_fenv_fx, const Word16 tilt_nb_fx, const Word16 st_offset, const Word16 Q_insig_lp, const Word16 Q_shb, const Word16 Q_synth, const Word16 Q_synth_lf );


/*-------------------------------------------------------------------*
 * delay_input_signal_fx()
 *
 *
 *-------------------------------------------------------------------*/

static void delay_input_signal_fx(
    Word16 *old_sig,
@@ -115,6 +99,7 @@ static void delay_input_signal_fx(
    return;
}


/*-------------------------------------------------------------------*
 * wb_bwe_enc()
 *
@@ -122,6 +107,7 @@ static void delay_input_signal_fx(
 *-------------------------------------------------------------------*/

void wb_bwe_enc_fx(
#ifndef HARM_FD_BWE
    Encoder_State *st_fx,           /* i/o: encoder state structure                  */
    const Word16 *new_wb_speech_fx, /* i  : original input signal at 16kHz           */
    Word16 coder_type               /* i  : coding type                              */
@@ -201,6 +187,7 @@ void wb_bwe_enc_fx(
 *-------------------------------------------------------------------*/

void wb_bwe_enc_ivas_fx(
#endif
    Encoder_State *st_fx,          /* i/o: encoder state structure                  */
    const Word16 *new_wb_speech_fx /* i  : original input signal at 16kHz           */
)
@@ -232,12 +219,18 @@ void wb_bwe_enc_ivas_fx(

        /*---------------------------------------------------------------------*/
        /* WB BWE encoding                                                     */


        /* MDCT of the core synthesis signal                                   */
        /*---------------------------------------------------------------------*/

        new_input_fx_exp = -1;
        move16();
#ifdef HARM_FD_BWE
        if ( st_fx->element_mode == EVS_MONO )
        {
            new_input_fx_exp = 0;
            move16();
        }
#endif

        wtda_fx( old_input_fx, &new_input_fx_exp, L_wtda_synth_fx, hBWE_FD->L_old_wtda_swb_fx,
                 &st_fx->Q_old_wtda, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */
@@ -246,8 +239,37 @@ void wb_bwe_enc_ivas_fx(
        /* DCT of the ACELP core synthesis */
        direct_transform_fx( L_wtda_synth_fx, yorig_32, 0, L_FRAME16k, &new_input_fx_exp, st_fx->element_mode );

        mode = WB_BWE_encoding_ivas_fx( st_fx, yorig_32, WB_fenv_fx, new_input_fx_exp, new_input_fx_exp );
#ifdef HARM_FD_BWE
        IF( st_fx->element_mode == EVS_MONO )
        {
            Word16 scl, Q_synth;
            Word16 yorig_fx[L_FRAME16k];

            /* Convert to 16 Bits (Calc Shift Required to Stay within MAX_Q_NEW_INPUT) */
            scl = sub( 16 + 8 /*MAX_Q_NEW_INPUT*/, new_input_fx_exp );

            /* Possible to Upscale? */
            IF( scl > 0 )
            {
                /* Yes */
                /* Calc Room to Upscale */
                Q_synth = Find_Max_Norm32( yorig_32, L_FRAME16k );

                /* Stay within MAX_Q_NEW_INPUT */
                scl = s_min( Q_synth, scl );
            }
            Copy_Scale_sig32_16( yorig_32, yorig_fx, L_FRAME16k, scl );
            Q_synth = sub( add( sub( new_input_fx_exp, 16 ), scl ), 1 );

            mode = WB_BWE_encoding_fx( st_fx->coder_type, yorig_fx, WB_fenv_fx, st_fx, Q_synth, Q_synth );
        }
        ELSE
#endif
        {
            mode = WB_BWE_encoding_fx_32( st_fx, yorig_32, WB_fenv_fx, new_input_fx_exp, new_input_fx_exp );
        }
        move16();

        push_indice( st_fx->hBstr, IND_WB_CLASS, sub( mode, 2 ), 1 );
    }

@@ -559,12 +581,12 @@ void swb_bwe_enc_ivas_fx(
    /* SWB BWE encoding */
    IF( EQ_16( st_fx->L_frame, L_FRAME16k ) )
    {
        SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32,
        SWB_BWE_encoding_fx_32( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32,
                                SWB_fenv_fx, tilt_nb_fx, 80, Q_slb_speech, Q_shb, new_input_fx_q, new_input_fx_q );
    }
    ELSE
    {
        SWB_BWE_encoding_ivas_fx( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32,
        SWB_BWE_encoding_fx_32( st_fx, old_input_fx, old_input_lp_fx, new_input_hp_fx, old_syn_12k8_16k_fx, yorig_32,
                                SWB_fenv_fx, tilt_nb_fx, 6, Q_slb_speech, Q_shb, new_input_fx_q, new_input_fx_q );
    }

@@ -2048,6 +2070,7 @@ static void calculate_Tonality_fx(
    return;
}

#ifndef HARM_FD_BWE
/*-------------------------------------------------------------------*
 * calculate_Tonality_ivas_fx()
 *
@@ -2201,6 +2224,7 @@ static void calculate_Tonality_ivas_fx(

    return;
}
#endif

/*-------------------------------------------------------------------*
 * energy_control_fx()
@@ -2294,6 +2318,7 @@ static void energy_control_fx(
    return;
}

#ifndef HARM_FD_BWE
/*-------------------------------------------------------------------*
 * energy_control_ivas_fx()
 *
@@ -2386,6 +2411,7 @@ static void energy_control_ivas_fx(
    }
    return;
}
#endif

/*-------------------------------------------------------------------*
 * WB_BWE_encoding()
@@ -2393,13 +2419,14 @@ static void energy_control_ivas_fx(
 * WB BWE main encoder
 *-------------------------------------------------------------------*/

Word16 WB_BWE_encoding_fx(                          /* o  : classification of wb signal            */
/* o  : classification of wb signal  */
static Word16 WB_BWE_encoding_fx(
    const Word16 coder_type, /* i  : coder type                             */
    const Word16 *yos_fx,    /* i  : MDCT coefficients of weighted original */
    Word16 *WB_fenv_fx,      /* i/o: energy of WB envelope                  */
    Encoder_State *st_fx,    /* i/o: Encoder structure                      */
                           Word16 Q_synth,
                           Word16 Q_synth_lf )
    const Word16 Q_synth,
    const Word16 Q_synth_lf )
{
    Word16 mode;
    Word16 i, n_coeff, n_band;
@@ -2459,17 +2486,18 @@ Word16 WB_BWE_encoding_fx( /* o : classification of wb
}

/*-------------------------------------------------------------------*
 * WB_BWE_encoding_ivas()
 * WB_BWE_encoding()
 *
 * WB BWE main encoder
 * WB BWE main encoder, 32-bit variant
 *-------------------------------------------------------------------*/

Word16 WB_BWE_encoding_ivas_fx(                       /* o  : classification of wb signal            */
/* o  : classification of wb signal */
static Word16 WB_BWE_encoding_fx_32(
    Encoder_State *st_fx, /* i/o: Encoder structure                      */
    const Word32 *yos_fx, /* i  : MDCT coefficients of weighted original */
    Word16 *WB_fenv_fx,   /* i/o: energy of WB envelope                  */
                                Word16 Q_synth,
                                Word16 Q_synth_lf )
    const Word16 Q_synth,
    const Word16 Q_synth_lf )
{
    Word16 mode;
    Word16 i, n_coeff, n_band;
@@ -2484,6 +2512,7 @@ Word16 WB_BWE_encoding_ivas_fx( /* o : classification of
    Word16 q_shift, scale;
    Word16 q_WB_fenv[2];
    Word16 yos_fx_16[L_FRAME16k];

    n_band = 0;
    move16();
    FOR( i = 0; i < 2; i++ )
@@ -2510,7 +2539,11 @@ Word16 WB_BWE_encoding_ivas_fx( /* o : classification of

    mode = FD_BWE_class_fx( yos_fx_16, 0, 0, sub( add( Q_synth, scale ), Q16 ), 0, st_fx );

#ifdef HARM_FD_BWE
    energy_control_fx( st_fx, ACELP_CORE, mode, st_fx->coder_type, yos_fx_16, 0, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) );
#else
    energy_control_ivas_fx( st_fx, ACELP_CORE, mode, st_fx->coder_type, yos_fx_16, 0, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) );
#endif

    FOR( i = 0; i < 2; i++ )
    {
@@ -2545,6 +2578,7 @@ Word16 WB_BWE_encoding_ivas_fx( /* o : classification of
 *
 * SWB BWE encoder
 *-------------------------------------------------------------------*/

static Word16 SWB_BWE_encoding_fx(
    Encoder_State *st_fx,      /* i/o: encoder state structure   */
    Word16 *insig_fx,          /* i  : delayed original input signal at 32kHz */
@@ -2556,10 +2590,10 @@ static Word16 SWB_BWE_encoding_fx(
    const Word16 tilt_nb_fx,   /* i  : SWB tilt */
    const Word16 st_offset,    /* i  : start frequency offset for BWE envelope */
    const Word16 coder_type,   /* i  : coding type                              */
    Word16 Q_insig_lp,
    Word16 Q_shb,
    Word16 Q_synth,
    Word16 Q_synth_lf )
    const Word16 Q_insig_lp,
    const Word16 Q_shb,
    const Word16 Q_synth,
    const Word16 Q_synth_lf )
{
    Word16 IsTransient, mode;
    Word16 index;
@@ -2982,9 +3016,10 @@ static Word16 SWB_BWE_encoding_fx(
/*-------------------------------------------------------------------*
 * SWB_BWE_encoding()
 *
 * SWB BWE encoder
 * SWB BWE encoder, 32-bit variant
 *-------------------------------------------------------------------*/
static Word16 SWB_BWE_encoding_ivas_fx(

static Word16 SWB_BWE_encoding_fx_32(
    Encoder_State *st_fx,      /* i/o: encoder state structure   */
    Word16 *insig_fx,          /* i  : delayed original input signal at 32kHz */
    const Word16 *insig_lp_fx, /* i  : delayed original lowband input signal at 32kHz */
@@ -2994,10 +3029,10 @@ static Word16 SWB_BWE_encoding_ivas_fx(
    Word16 *SWB_fenv_fx,       /* o  : frequency-domain quantized BWE envelope */
    const Word16 tilt_nb_fx,   /* i  : SWB tilt */
    const Word16 st_offset,    /* i  : start frequency offset for BWE envelope */
    Word16 Q_insig_lp,
    Word16 Q_shb,
    Word16 Q_synth,
    Word16 Q_synth_lf )
    const Word16 Q_insig_lp,
    const Word16 Q_shb,
    const Word16 Q_synth,
    const Word16 Q_synth_lf )
{
    Word16 IsTransient, mode;
    Word16 index;
@@ -3411,7 +3446,11 @@ static Word16 SWB_BWE_encoding_ivas_fx(
        mode = FD_BWE_class_fx( yos_fx_16, global_gain_fx, tilt_nb_fx, sub( add( Q_synth, scale ), Q16 ), Q_shb, st_fx );
        push_indice( hBstr, IND_SWB_CLASS, mode, 2 );

#ifdef HARM_FD_BWE
        energy_control_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) );
#else
        energy_control_ivas_fx( st_fx, ACELP_CORE, mode, -1, yos_fx_16, st_offset, energy_factor_fx, sub( add( Q_synth_lf, scale ), Q16 ) );
#endif

        FOR( n_band = 0; n_band < SWB_FENV; n_band++ )
        {
@@ -3555,6 +3594,7 @@ static void get_normalize_spec_fx_32(
 * calculate_tonality_fx_32()
 *
 *-------------------------------------------------------------------*/

static void calculate_tonality_fx_32(
    const Word32 *org_fx, /* i  : MDCT coefficients of original         : Q12  */
    const Word32 *gen_fx, /* i  : MDCT coefficients of generated signal : Q12  */
@@ -3687,6 +3727,7 @@ static void calculate_tonality_fx_32(
 * energy_control_fx_32()
 *
 *-------------------------------------------------------------------*/

static void energy_control_fx_32(
    Encoder_State *st_fx,    /* i/o: encoder structure   */
    const Word16 core,       /* i  : core                : Q0  */
@@ -3870,6 +3911,7 @@ static Word16 decision_hq_generic_class_fx_32(
 * hq_generic_encoding_fx()
 *
 *-------------------------------------------------------------------*/

void hq_generic_encoding_fx(
    const Word32 *coefs_fx,         /* i  : MDCT coefficients of weighted original : Q12   */
    Word16 *hq_generic_fenv_fx,     /* i/o: energy of SWB envelope                 : Q3    */
@@ -3903,7 +3945,6 @@ void hq_generic_encoding_fx(
        move16();
    }


    energy_control_fx_32( st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx );

    IF( EQ_16( hHQ_core->hq_generic_speech_class, 1 ) )
@@ -4021,7 +4062,6 @@ void hq_generic_encoding_fx(
        }
    }


    /* Energy VQ */
    IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
    {
@@ -4088,6 +4128,7 @@ void hq_generic_encoding_fx(
    return;
}


/*-------------------------------------------------------------------*
 * fd_bwe_enc_init_fx()
 *
@@ -4134,10 +4175,12 @@ void fd_bwe_enc_init_fx(
    return;
}


/*-------------------------------------------------------------------*
 * hq_generic_encoding_fx()
 * hq_generic_hf_encoding_fx()
 *
 *-------------------------------------------------------------------*/

void hq_generic_hf_encoding_fx(
    const Word32 *coefs_fx,         /* i  : MDCT coefficients of weighted original : Q12   */
    Word16 *hq_generic_fenv_fx,     /* i/o: energy of SWB envelope                 : Q1    */
@@ -4172,7 +4215,6 @@ void hq_generic_hf_encoding_fx(
        move16();
    }


    energy_control_fx_32( st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx );

    IF( EQ_16( hHQ_core->hq_generic_speech_class, 1 ) )
@@ -4290,7 +4332,6 @@ void hq_generic_hf_encoding_fx(
        }
    }


    /* Energy VQ */
    IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) )
    {