Commit bdda6081 authored by vaclav's avatar vaclav
Browse files

Merge branch 'basop-2339-remove-duplicated-code-core-coder-dtx' into 'main'

Remove duplicated code: core-coder front pre-procesing

See merge request !2709
parents 2997f3e6 9f78f55e
Loading
Loading
Loading
Loading
Loading
+59 −63
Original line number Diff line number Diff line
@@ -5968,14 +5968,14 @@ ivas_error pre_proc_front_ivas_fx(
    const Word16 nb_bits_metadata,                                 /* i  : number of metadata bits                                  Q0*/
    const Word16 input_frame,                                      /* i  : frame length                                             Q0*/
    const Word16 n,                                                /* i  : channel number                                           Q0*/
    Word16 old_inp_12k8_fx[],                                   /* o  : buffer of old input signal                Q_new-1*/
    Word16 old_inp_12k8_fx[],                                      /* o  : buffer of old input signal (st->Q_inp until preemph, then Q_new, then Q_new-1 towards the end)*/
    Word16 old_inp_16k_fx[],                                       /* o  : buffer of old input signal @16kHz                        Q_new-1*/
    Word32 *ener_fx,                                               /* o  : residual energy from Levinson-Durbin                     epsP_fx_q*/
    Word16 *relE_fx,                                               /* o  : frame relative energy                                    Q8*/
    Word16 A_fx[NB_SUBFR16k * ( M + 1 )],                          /* o  : A(z) unquantized for the 4 subframes                     Q12*/
    Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )],                         /* o  : weighted A(z) unquantized for subframes                  Q12*/
    Word32 epsP_fx[M + 1],                                         /* o  : LP prediction errors                                     epsP_fx_q*/
    Word16 *epsP_fx_q,
    Word16 *epsP_fx_q,                                             /* o  : Q factor of LP prediction errors                         */
    Word16 lsp_new_fx[M],                                          /* o  : LSPs at the end of the frame                             Q15*/
    Word16 lsp_mid_fx[M],                                          /* o  : LSPs in the middle of the frame                          Q15*/
    Word16 *vad_hover_flag,                                        /* o  : VAD hangover flag                                        Q0*/
@@ -5984,7 +5984,7 @@ ivas_error pre_proc_front_ivas_fx(
    Word32 imagBuffer_fx[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX], /* i/o: imag buffer                                              Q(q_re_im_buf)*/
    Word16 *q_re_im_buf,                                           /* i/o: Q-factor of real and imag buffer                         */
    Word16 old_wsp_fx[],                                           /* o  : weighted input signal buffer                             q_old_wsp*/
    Word16 *q_old_wsp,
    Word16 *q_old_wsp,                                             /* o  : Q factor of weighted input signal buffer                 */
    Word16 pitch_fr_fx[NB_SUBFR],                                  /* o  : fractional pitch values                                  Q6*/
    Word16 voicing_fr_fx[NB_SUBFR],                                /* o  : fractional pitch gains                                   Q15*/
    Word16 *loc_harm,                                              /* o  : harmonicity flag                                         Q0*/
@@ -5998,14 +5998,14 @@ ivas_error pre_proc_front_ivas_fx(
    const Word16 tdm_lsp_new_PCh_fx[M],                            /* i  : unq. LSPs of primary channel                             Q15*/
    const Word32 currFlatness_fx,                                  /* i  : flatness parameter                                       Q21*/
    const Word16 tdm_ratio_idx,                                    /* i  : Current Ratio_L index                                    Q0*/
    Word32 fr_bands_LR_fx[][2 * NB_BANDS],                      /* i  : energy in frequency bands (fr_bands_LR_fx_q)    fr_bands_LR_fx_q*/
    Word16 fr_bands_LR_fx_q[CPE_CHANNELS],
    Word32 fr_bands_LR_fx[][2 * NB_BANDS],                         /* i  : energy in frequency bands                                fr_bands_LR_fx_q*/
    Word16 fr_bands_LR_fx_q[CPE_CHANNELS],                         /* i  : Q factors of energy in frequency bands                   */
    const Word16 Etot_LR_fx[],                                     /* i  : total energy Left & Right channel                        Q8*/
    Word32 lf_E_LR_fx[][2 * VOIC_BINS],                         /* i  : per bin spectrum energy in lf, LR channels                (lf_E_LR_fx_q)*/
    Word16 lf_E_LR_fx_q,
    Word32 lf_E_LR_fx[][2 * VOIC_BINS],                            /* i  : per bin spectrum energy in lf, LR channels               lf_E_LR_fx_q*/
    const Word16 lf_E_LR_fx_q,                                     /* i  : Q factor of per bin spectrum energy in lf, LR channels   */
    const Word16 localVAD_HE_SAD_LR[],                             /* i  : HE-SAD flag without hangover, LR channels                Q0*/
    Word32 band_energies_LR_fx[2 * NB_BANDS],                   /* o  : energy in critical bands without minimum noise floor E_MIN    (band_energies_LR_fx_q)*/
    Word16 band_energies_LR_fx_q,
    Word32 band_energies_LR_fx[2 * NB_BANDS],                      /* o  : energy in critical bands without minimum noise floor E_MIN    band_energies_LR_fx_q*/
    const Word16 band_energies_LR_fx_q,                            /* o  : Q factors of energy in critical bands without minimum noise floor */
    const Word16 flag_16k_smc,                                     /* i  : flag to indicate if the OL SMC is run at 16 kHz          Q0*/
    const Word16 front_vad_flag,                                   /* i  : front-VAD flag to overwrite VAD decision                 Q0*/
    const Word16 force_front_vad,                                  /* i  : flag to force VAD decision                               Q0*/
@@ -6014,11 +6014,7 @@ ivas_error pre_proc_front_ivas_fx(
    const Word16 MCT_flag,                                         /* i  : hMCT handle allocated (1) or not (0)                     Q0*/
    const Word32 last_ivas_total_brate,                            /* i  : last IVAS total bitrate                                  Q0*/
    const Word32 ivas_total_brate,                                 /* i  : IVAS total bitrate - for setting the DTX                 Q0*/
    Word16 *Q_new
#ifdef DEBUG_MODE_INFO
    ,
    const Word16 ch_idx
#endif
    Word16 *Q_new                                                  /* i/o : Q factor of speech buffers                              */
);

ivas_error pre_proc_ivas_fx(
@@ -6040,17 +6036,17 @@ ivas_error pre_proc_ivas_fx(
    Word16 *new_inp_resamp16k_fx,                               /* o  : new input signal @16kHz, non pre-emphasised, used by the WB TBE/BWE    Q_new-1*/
    Word16 *Voicing_flag,                                       /* o  : voicing flag for HQ FEC                              Q0*/
    Word16 old_wsp_fx[],                                        /* i  : weighted input signal buffer                  e_old_wsp*/
    Word16 e_old_wsp,
    const Word16 e_old_wsp,                                     /* i  : Q value of weighted input signal buffer                */
    const Word16 loc_harm,                                      /* i  : harmonicity flag                                     Q0*/
    const Word16 vad_flag_dtx,                                  /* i  : HE-SAD flag with additional DTX HO                   Q0*/
    const Word16 MCT_flag,                                      /* i  : hMCT handle allocated (1) or not (0)                 Q0*/
    const Word16 vad_hover_flag,                                /* i  : VAD hangover flag                                    Q0*/
    const Word16 flag_16k_smc,                                  /* i  : flag to indicate if the OL SMC is run at 16 kHz      Q0*/
    Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX],                /* e_enerBuffer */
    Word16 e_enerBuffer,
    Word16 fft_buff_fx[2 * L_FFT],                              /* Qx */
    Word16 cor_map_sum_fx,                                      /* Q8 */
    Word16 *Q_new
    Word32 enerBuffer_fx[CLDFB_NO_CHANNELS_MAX],                /* i  : energy buffer                             e_enerBuffer */
    const Word16 e_enerBuffer,                                  /* i  : Q value of energy buffer                               */
    Word16 fft_buff_fx[2 * L_FFT],                              /* i  : FFT buffer                                           Qx*/
    const Word16 cor_map_sum_fx,                                /* i  : speech/music clasif. parameter                       Q8*/
    Word16 *Q_new                                               /* i/o : Q factor of speech buffers                            */
);

void ivas_initialize_handles_enc_fx(
+1 −0
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@
#define OPT_BE_2311_HARM_GSC_GAIN                       /* VA: issue 2311: BE part of the GSC gain harmonization pipeline #70380 shows the BE */
#define HARM_CORECODER_UPDT                             /* VA: basop issue 2342: Remove duplicated code in core-coder common update functions */
#define HARM_CORE_SW                                    /* VA: basop issue 2314: Remove duplicated code in the core switching */
#define HARM_PREPROC                                    /* VA: basop issue 2339: Remove duplicated code in the core-coder DTX  */

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

+8 −0
Original line number Diff line number Diff line
@@ -314,7 +314,11 @@ void amr_wb_enc_fx(
    }

    /* apply DTX hangover for CNG analysis */
#ifdef HARM_PREPROC
    vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, &vad_hover_flag, NULL, NULL, NULL );
#else
    vad_flag_dtx = dtx_hangover_addition_fx( st, st->vad_flag, sub( st->lp_speech_fx, st->lp_noise_fx ), 0, &vad_hover_flag, NULL, NULL );
#endif

    /*-----------------------------------------------------------------*
     * Select SID or FRAME_NO_DATA frame if DTX enabled
@@ -336,7 +340,11 @@ void amr_wb_enc_fx(
        move16();
    }

#ifdef HARM_PREPROC
    dtx_fx( st, -1, -1, vad_flag_dtx, inp, Q_new );
#else
    dtx_fx( st, vad_flag_dtx, inp, Q_new );
#endif

    /*----------------------------------------------------------------*
     * Noise energy down-ward update and total noise energy estimation
+68 −12
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate,


/*==================================================================================*/
/* FUNCTION : dtx_ivas_fx()                                                              */
/* FUNCTION : dtx_fx()                                                              */
/*----------------------------------------------------------------------------------*/
/* PURPOSE :  Discontinuous transmission operation                                  */
/*----------------------------------------------------------------------------------*/
@@ -58,27 +58,45 @@ static void update_SID_cnt_fx( DTX_ENC_HANDLE hDtxEnc, const Word32 core_brate,
/* _ (Word16*)  qener         : frame_ener/lt_ener_voiced/lt_ener_noise buf qformat */
/* _ (Encoder_State_Fx) st_fx : encoder state structure                             */
/*----------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------*/
/* RETURN ARGUMENTS :                                                               */
/* _ None                                                                           */
/*==================================================================================*/

#ifdef HARM_PREPROC
void dtx_fx(
#else
void dtx_ivas_fx(
#endif
    Encoder_State *st_fx,               /* i/o: encoder state structure                  */
    const Word32 last_ivas_total_brate, /* i  : last IVAS total bitrate                  Q0*/
    const Word32 ivas_total_brate,      /* i  : IVAS total bitrate                       Q0*/
    const Word16 vad,                   /* i  : vad flag for DTX                         Q0*/
    const Word16 speech[],              /* i  : Pointer to the speech frame              Q_speech*/
    Word16 Q_speech                     /* i  : Q factor for speech                      */
    const Word16 Q_speech               /* i  : Q factor for speech                      */
)
{
    Word16 alpha, i, j, Q_speech2;
    Word32 L_tmp;
    DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
    TD_CNG_ENC_HANDLE hTdCngEnc = st_fx->hTdCngEnc;

    Word16 last_br_cng_flag, last_br_flag, br_dtx_flag;
    Word32 total_brate_ref;
#ifdef HARM_PREPROC
    Word16 flag_lp_noise;

    flag_lp_noise = 0;
    move16();
    test();
    test();
    test();
    IF( ( st_fx->element_mode == EVS_MONO && LT_16( st_fx->lp_noise_fx, DTX_THR * 256 ) ) ||
        ( st_fx->element_mode != EVS_MONO && LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ) ) )
    {
        flag_lp_noise = 1;
        move16();
    }
#endif

    total_brate_ref = st_fx->total_brate;
    move32();
@@ -95,15 +113,23 @@ void dtx_ivas_fx(
        test();
        test();
        test();
#ifdef HARM_PREPROC
        last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || flag_lp_noise || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) );
#else
        last_br_cng_flag = LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_EVS ) || LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 ) || ( EQ_16( st_fx->element_mode, IVAS_SCE ) && LE_32( st_fx->last_total_brate_cng, MAX_BRATE_DTX_IVAS ) );
#endif

        test();
        test();
        test();

        test();
        last_br_flag = ( st_fx->element_mode == EVS_MONO && LE_32( st_fx->last_total_brate, MAX_BRATE_DTX_EVS ) ) ||
                       ( st_fx->element_mode != EVS_MONO && LE_32( last_ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) ||
#ifdef HARM_PREPROC
                       flag_lp_noise;
#else
                       LT_32( ( st_fx->lp_noise_32fx ), DTX_THR * 16777216 );
#endif
    }

    /* Initialization */
@@ -114,6 +140,7 @@ void dtx_ivas_fx(

        st_fx->cng_type = FD_CNG;
        move16();

        test();
        test();
        test();
@@ -123,6 +150,7 @@ void dtx_ivas_fx(
            move16();
        }
    }

    test();
    test();
    test();
@@ -142,12 +170,14 @@ void dtx_ivas_fx(
        {
            st_fx->total_brate = st_fx->last_total_brate_cng;
            move32();

            test();
            if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) )
            {
                st_fx->Opt_SC_VBR = 0;
                move16();
            }

            st_fx->rf_mode = st_fx->last_rf_mode_cng;
            move16();
            st_fx->bwidth = st_fx->last_bwidth_cng;
@@ -155,13 +185,14 @@ void dtx_ivas_fx(
            st_fx->codec_mode = st_fx->last_codec_mode_cng;
            move16();
        }

        test();
        test();
        IF( LE_32( st_fx->last_core_brate, SID_2k40 ) && NE_32( st_fx->last_total_brate, st_fx->total_brate ) && last_br_flag )

        {
            st_fx->total_brate = st_fx->last_total_brate;
            move32();

            test();
            if ( !( EQ_32( st_fx->total_brate, ACELP_7k20 ) && st_fx->Opt_SC_VBR ) )
            {
@@ -179,10 +210,12 @@ void dtx_ivas_fx(
                st_fx->Opt_RF_ON = 1;
                move16();
            }

            st_fx->rf_mode = st_fx->Opt_RF_ON;
            move16();
            st_fx->bwidth = st_fx->last_bwidth;
            move32();

            IF( st_fx->element_mode > EVS_MONO )
            {
                st_fx->codec_mode = MODE1;
@@ -211,8 +244,13 @@ void dtx_ivas_fx(
        test();
        br_dtx_flag = ( ( st_fx->element_mode == EVS_MONO ) && LE_32( st_fx->total_brate, MAX_BRATE_DTX_EVS ) ) ||
                      ( ( st_fx->element_mode != EVS_MONO ) && LE_32( ivas_total_brate, MAX_BRATE_DTX_IVAS ) ) ||
#ifdef HARM_PREPROC
                      flag_lp_noise;
#else
                      LT_16( extract_h( st_fx->lp_noise_32fx ), DTX_THR * 256 );
#endif
    }

    test();
    test();
    test();
@@ -272,12 +310,14 @@ void dtx_ivas_fx(
            st_fx->core_brate = SID_2k40;
            move32();
        }

        test();
        test();
        IF( ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->cng_type, FD_CNG ) ) && EQ_16( st_fx->dtx_sce_sba, 1 ) )
        {
            st_fx->cng_type = FD_CNG;
            move16();

            test();
            test();
            test();
@@ -320,6 +360,7 @@ void dtx_ivas_fx(
                move16();
            }
        }

        /* reset the bitstream (IVAS format signalling was already written) */
        test();
        IF( NE_16( st_fx->element_mode, IVAS_CPE_MDCT ) && st_fx->hBstr != NULL )
@@ -337,7 +378,7 @@ void dtx_ivas_fx(
    /*------------------------------------------------------------------------*
     * Reset counters when in active frame (not in SID or FRAME_NO_DATA frame)
     *------------------------------------------------------------------------*/
    /* NB core bit rate can be "-1"  at startup , so one can not use   core_brate_fx <=2400 */

    test();
    test();
    IF( ( NE_32( st_fx->core_brate, SID_2k40 ) ) && ( NE_32( st_fx->core_brate, SID_1k75 ) ) && ( st_fx->core_brate != FRAME_NO_DATA ) )
@@ -428,6 +469,7 @@ void dtx_ivas_fx(
                    move16();
                }
            }

            st_fx->last_total_brate_cng = -1;
            move16();
        }
@@ -436,6 +478,7 @@ void dtx_ivas_fx(
            st_fx->cng_type = LP_CNG;
            move16();
        }

        st_fx->active_cnt = add( st_fx->active_cnt, 1 );
        move16();
        st_fx->active_cnt = s_min( st_fx->active_cnt, 200 );
@@ -445,6 +488,7 @@ void dtx_ivas_fx(
    /*------------------------------------------------------------------------*
     * Update speech and background noise long-term energy
     *------------------------------------------------------------------------*/

    IF( hDtxEnc != NULL )
    {
        hDtxEnc->frame_ener_fx = L_deposit_l( 0 );
@@ -467,7 +511,6 @@ void dtx_ivas_fx(
            }

            /* Active speech (voiced) */

            IF( EQ_16( st_fx->clas, VOICED_CLAS ) )
            {
                alpha = ALPHA_ENER_SLOW_FX; /*Q15 */
@@ -524,7 +567,6 @@ void dtx_ivas_fx(
    test();
    IF( st_fx->Opt_DTX_ON && ( EQ_32( st_fx->core_brate, SID_2k40 ) || ( st_fx->core_brate == FRAME_NO_DATA ) ) )
    {

        st_fx->bwidth = st_fx->last_bwidth;
        move16();
        test();
@@ -561,7 +603,6 @@ void dtx_ivas_fx(
        IF( EQ_16( st_fx->codec_mode, MODE2 ) )
        {
            Word16 n, bits_frame_nominal;

            UWord16 lsb;
            Word16 tmpbandwidthMin;

@@ -575,17 +616,20 @@ void dtx_ivas_fx(
                    BREAK;
                }
            }
            IF( EQ_16( n, FRAME_SIZE_NB ) )
            if ( n == FRAME_SIZE_NB )
            {
                assert( !"Bitrate not supported: not part of EVS" );
            }

            tmpbandwidthMin = FrameSizeConfig[n].bandwidth_min;
            move16();

            if ( EQ_16( st_fx->rf_mode, 1 ) )
            {
                tmpbandwidthMin = WB;
                move16();
            }

            st_fx->bwidth = s_max( s_min( st_fx->bwidth, FrameSizeConfig[n].bandwidth_max ), tmpbandwidthMin );
            move16();
        }
@@ -594,6 +638,7 @@ void dtx_ivas_fx(
    return;
}

#ifndef HARM_PREPROC
/*==================================================================================*/
/* FUNCTION : dtx_fx()                                                              */
/*----------------------------------------------------------------------------------*/
@@ -1052,6 +1097,7 @@ void dtx_fx(

    return;
}
#endif

/*---------------------------------------------------------------------*
 * update_SID_cnt()
@@ -1201,6 +1247,12 @@ static void update_SID_cnt_fx(
}


/*-------------------------------------------------------------------*
 * dtx_hangover_control()
 *
 *
 *-------------------------------------------------------------------*/

void dtx_hangover_control_fx(
    Encoder_State *st_fx,      /* i/o: encoder state structure                  */
    const Word16 lsp_new_fx[M] /* i  : current frame LSPs                       Q15*/
@@ -1480,6 +1532,7 @@ void dtx_hangover_control_fx(
    return;
}


/*-------------------------------------------------------------------*
 * td_cng_enc_init_fx()
 *
@@ -1491,6 +1544,7 @@ void td_cng_enc_init_fx(
    const Word16 Opt_DTX_ON,     /* i  : flag indicating DTX operation       Q0*/
    const Word16 max_bwidth      /* i  : maximum encoded bandwidth           Q0*/
)
#ifndef HARM_PREPROC
{

    hTdCngEnc->cng_seed = RANDOM_INITSEED;
@@ -1580,8 +1634,8 @@ void td_cng_enc_init_ivas_fx(
    const Word16 Opt_DTX_ON,     /* i  : flag indicating DTX operation       Q0*/
    const Word16 max_bwidth      /* i  : maximum encoded bandwidth           Q0*/
)
#endif
{

    hTdCngEnc->cng_seed = RANDOM_INITSEED;
    move16();
    hTdCngEnc->cng_ener_seed = RANDOM_INITSEED;
@@ -1672,6 +1726,7 @@ void td_cng_enc_init_ivas_fx(
    return;
}


/*-------------------------------------------------------------------*
 * dtx_enc_init_fx()
 *
@@ -1734,5 +1789,6 @@ void dtx_enc_init_fx(
            move16();
        }
    }

    return;
}
+4 −0
Original line number Diff line number Diff line
@@ -686,6 +686,9 @@ ivas_error init_encoder_fx(
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DTX/TD CNG\n" ) );
        }

#ifdef HARM_PREPROC
        td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth );
#else
        IF( st->element_mode == EVS_MONO )
        {
            td_cng_enc_init_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth );
@@ -694,6 +697,7 @@ ivas_error init_encoder_fx(
        {
            td_cng_enc_init_ivas_fx( st->hTdCngEnc, st->Opt_DTX_ON, st->max_bwidth );
        }
#endif
    }
    ELSE
    {
Loading