Commit ffe011f5 authored by vaclav's avatar vaclav
Browse files

harmonize swb_CNG_enc_fx()

parent 82b98c43
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -10721,12 +10721,13 @@ void writeTCXparam_fx(
    const Word16 target_bitsTCX10[2],
    const Word16 pre_past_flag );
#ifndef HARM_NON_LINEARITY
void calculate_hangover_attenuation_gain_ivas_fx(
    Encoder_State *st,          /* i  : encoder state structure         */
    Word16 *att,                /* o  : attenuation factor              */
    const Word16 vad_hover_flag /* i  : VAD hangover flag               */
);
#endif
void init_coder_ace_plus_ivas_fx(
    Encoder_State *st,             /* i  : Encoder state                          */
    const Word32 last_total_brate, /* i  : last total bitrate                     */
+5 −0
Original line number Diff line number Diff line
@@ -1266,7 +1266,12 @@ ivas_error acelp_core_enc_ivas_fx(
         *---------------------------------------------------------------*/

        calc_residu_fx( st, inp, res_fx, Aq );

#ifdef HARM_NON_LINEARITY
        calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag );
#else
        calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag );
#endif

        IF( NE_16( att_fx, 32767 /* ONE_IN_Q15 */ ) )
        {
+103 −49
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@

static void shb_CNG_encod_fx( Encoder_State *st_fx, const Word16 update_fx );
static Word16 shb_DTX_fx( Encoder_State *st_fx, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k );
#ifndef HARM_NON_LINEARITY
static Word16 shb_DTX_ivas_fx( Encoder_State *st, const Word16 *shb_speech_fx, const Word16 *syn_12k8_16k_fx );
static void shb_CNG_encod_ivas_fx( Encoder_State *st, const Word16 update );
#endif


/*---------------------------------------------------------------------*
@@ -1408,6 +1410,7 @@ void CNG_enc_fx(
            move16();
        }
    }

    /* update the pointer to circular buffer of old LSP vectors */
    hTdCngEnc->cng_hist_ptr = add( hTdCngEnc->cng_hist_ptr, 1 );
    move16();
@@ -2513,6 +2516,7 @@ void CNG_enc_fx(
    /*-----------------------------------------------------------------*
     * Updates
     *-----------------------------------------------------------------*/

    /* update the SID frames counter */
    test();
    IF( EQ_32( st_fx->core_brate, SID_2k40 ) || EQ_32( st_fx->core_brate, SID_1k75 ) )
@@ -2534,7 +2538,7 @@ void CNG_enc_fx(
    return;
}


#ifndef HARM_NON_LINEARITY
/*---------------------------------------------------------------------*
 * swb_CNG_enc()
 *
@@ -2657,6 +2661,7 @@ static void shb_CNG_encod_fx(
 *
 * Decide if encoding SHB SID or not
 *---------------------------------------------------------------------*/

static Word16 shb_DTX_fx(
    Encoder_State *st_fx,        /* i/o: State structure                                                   */
    const Word16 *shb_speech_fx, /* i  : SHB target signal (6-14kHz) at 16kHz       (Q0)                   */
@@ -2836,13 +2841,16 @@ static Word16 shb_DTX_fx(

    return ( update_fx );
}
#endif

/*---------------------------------------------------------------------*
 * calculate_hangover_attenuation_gain_fx()
 *
 *
 *---------------------------------------------------------------------*/

void calculate_hangover_attenuation_gain_fx(
#ifndef HARM_NON_LINEARITY
    Encoder_State *st,          /* i  : encoder state structure         */
    Word16 *att,                /* o  : attenuation factor            Q15  */
    const Word16 vad_hover_flag /* i  : VAD hangover flag                       */
@@ -2885,6 +2893,7 @@ void calculate_hangover_attenuation_gain_fx(
}

void calculate_hangover_attenuation_gain_ivas_fx(
#endif
    Encoder_State *st,          /* i  : encoder state structure     */
    Word16 *att,                /* o  : attenuation factor      Q15 */
    const Word16 vad_hover_flag /* i  : VAD hangover flag           */
@@ -2909,6 +2918,22 @@ void calculate_hangover_attenuation_gain_ivas_fx(
            *att = extract_h( L_shl_sat( L_tmp, result_e ) );
            move16();
        }
#ifdef HARM_NON_LINEARITY
        ELSE IF( st->element_mode == EVS_MONO )
        {
            Word16 offset = 5;
            move16();
            test();
            if ( EQ_16( st->bwidth, WB ) && st->hDtxEnc->CNG_mode >= 0 )
            {
                offset = st->hDtxEnc->CNG_mode;
                move16();
            }
            assert( st->hTdCngEnc->burst_ho_cnt > 0 );
            *att = CNG_burst_att_fx[offset][st->hTdCngEnc->burst_ho_cnt - 1]; /*Q15*/
            move16();
        }
#endif
        ELSE
        {
            test();
@@ -2938,7 +2963,18 @@ void calculate_hangover_attenuation_gain_ivas_fx(
    return;
}


#ifdef HARM_NON_LINEARITY
/*---------------------------------------------------------------------*
 * swb_CNG_enc()
 *
 * SWB DTX/CNG encoding
 *---------------------------------------------------------------------*/

void swb_CNG_enc_fx(
#else
void swb_CNG_enc_ivas_fx(
#endif
    Encoder_State *st,            /* i/o: State structure                                 */
    const Word16 *shb_speech_fx,  /* i  : SHB target signal (6-14kHz) at 16kHz         Q0 */
    const Word16 *syn_12k8_16k_fx /* i  : ACELP core synthesis at 12.8kHz or 16kHz     Q0 */
@@ -2955,10 +2991,18 @@ void swb_CNG_enc_ivas_fx(
            IF( GE_32( st->input_Fs, L_FRAME32k * FRAMES_PER_SEC ) )
            {
                /* decide if SHB SID encoding or not */
#ifdef HARM_NON_LINEARITY
                shb_SID_updt = shb_DTX_fx( st, shb_speech_fx, syn_12k8_16k_fx );
#else
                shb_SID_updt = shb_DTX_ivas_fx( st, shb_speech_fx, syn_12k8_16k_fx );
#endif

                /* SHB CNG encoding */
#ifdef HARM_NON_LINEARITY
                shb_CNG_encod_fx( st, shb_SID_updt );
#else
                shb_CNG_encod_ivas_fx( st, shb_SID_updt );
#endif
            }
            ELSE IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) && EQ_32( st->core_brate, SID_2k40 ) )
            {
@@ -2988,7 +3032,11 @@ void swb_CNG_enc_ivas_fx(
 * SID parameters encoding for SHB signal
 *---------------------------------------------------------------------*/

#ifdef HARM_NON_LINEARITY
static void shb_CNG_encod_fx(
#else
static void shb_CNG_encod_ivas_fx(
#endif
    Encoder_State *st,  /* i/o: State structure             */
    const Word16 update /* i  : SID update flag             */
)
@@ -2996,17 +3044,17 @@ static void shb_CNG_encod_ivas_fx(
    Word16 idx_ener = 0;
    move16();
    BSTR_ENC_HANDLE hBstr = st->hBstr;

    Word16 ener_mid_dec_thr_fx;

    IF( EQ_16( update, 1 ) )
    {
        IF( st->element_mode == EVS_MONO )
        {
            /* 6.0 in Q8 -> 1510 */
            /* 0.9 in Q15 29491 */
            /* ( 1 / log10(2.0) ) * 0.1 in Q15 ->10886 */
#ifdef HARM_NON_LINEARITY
            idx_ener = shr( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 9797 ), 1510 ), 8 ); /* Q0 */
#else
            idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 29491 ), 8 ); /* Q0 */
#endif
        }
        ELSE
        {
@@ -3017,7 +3065,6 @@ static void shb_CNG_encod_ivas_fx(
            idx_ener = shr( mult( add( mult( st->hTdCngEnc->mov_shb_cng_ener_fx, 10886 ), 1510 ), 22938 ), 8 ); /* Q0 */
        }


        if ( LT_16( st->bwidth, SWB ) )
        {
            idx_ener = 0;
@@ -3078,6 +3125,7 @@ static void shb_CNG_encod_ivas_fx(
        push_indice( hBstr, IND_SHB_CNG_GAIN, idx_ener, 4 );
        push_indice( hBstr, IND_SID_BW, 1, 1 );
        delete_indice( hBstr, IND_CNG_ENV1 );

        IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) )
        {
            push_indice( st->hBstr, IND_BWIDTH, st->bwidth, 2 );
@@ -3086,6 +3134,7 @@ static void shb_CNG_encod_ivas_fx(
        {
            push_indice( hBstr, IND_UNUSED, 0, 2 );
        }

        st->hTdCngEnc->ho_sid_bw = L_shl( L_and( st->hTdCngEnc->ho_sid_bw, (Word32) 0x3fffffffL ), 1 );
        st->hTdCngEnc->ho_sid_bw = L_or( st->hTdCngEnc->ho_sid_bw, 0x1L );
        move32();
@@ -3101,13 +3150,18 @@ static void shb_CNG_encod_ivas_fx(
    return;
}


/*---------------------------------------------------------------------*
 * shb_DTX()
 *
 * Decide if encoding SHB SID or not
 *---------------------------------------------------------------------*/

#ifdef HARM_NON_LINEARITY
static Word16 shb_DTX_fx(
#else
static Word16 shb_DTX_ivas_fx(
#endif
    Encoder_State *st,            /* i/o: State structure                                 */
    const Word16 *shb_speech_fx,  /* i  : SHB target signal (6-14kHz) at 16kHz         Q0 */
    const Word16 *syn_12k8_16k_fx /* i  : ACELP core synthesis at 12.8kHz or 16kHz     Q0 */
@@ -3163,7 +3217,6 @@ static Word16 shb_DTX_ivas_fx(
    exp = sub( 30 - 1, exp );
    shb_ener_fx = Mpy_32_16( exp, fra, LG10 );


    test();
    IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) )
    {
@@ -3240,7 +3293,8 @@ static Word16 shb_DTX_ivas_fx(
    move16();

    IF( EQ_32( st->core_brate, SID_2k40 ) )
    {            test();
    {
        test();
        test();
        test();
        IF( st->hDtxEnc->first_CNG == 0 )
+4 −0
Original line number Diff line number Diff line
@@ -3617,7 +3617,11 @@ void QuantizeTCXSpectrum_fx(
    test();
    IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
    {
#ifdef HARM_NON_LINEARITY
        calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag );
#else
        calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag );
#endif
        *gain_tcx_fx = mult( *gain_tcx_fx, att_fx );
        move16();
    }
+4 −0
Original line number Diff line number Diff line
@@ -337,7 +337,11 @@ void hq_hr_enc_ivas_fx(
    test();
    IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) )
    {
#ifdef HARM_NON_LINEARITY
        calculate_hangover_attenuation_gain_fx( st, &att_fx, vad_hover_flag );
#else
        calculate_hangover_attenuation_gain_ivas_fx( st, &att_fx, vad_hover_flag );
#endif
        v_multc_att32( t_audio_fx, att_fx, t_audio_fx, sfm_end[( num_sfm - 1 )] ); /* Q12 */
    }

Loading