Commit cccf2d0b authored by Fabian Bauer's avatar Fabian Bauer
Browse files

added real harmonized function

parent 0a678182
Loading
Loading
Loading
Loading
+1004 −615
Original line number Diff line number Diff line
@@ -1116,6 +1116,13 @@ void open_decoder_LPD_ivas_fx(
hTcxLtpDec = st->hTcxLtpDec;
hTcxDec = st->hTcxDec;

#ifdef HARMONIZATION_2583_open_decoder_LPD
if ( EQ_16( st->element_mode, EVS_MONO ) )
{
    st->total_brate = total_brate;
    move32();
}
#endif
if ( NE_16( st->codec_mode, MODE1 ) ) /*already updated in MODE1*/
{
    st->fscale_old = st->fscale; /* Q0 */
@@ -1123,16 +1130,16 @@ void open_decoder_LPD_ivas_fx(
}

st->sr_core = getCoreSamplerateMode2( st->element_mode, total_brate, bwidth, st->flag_ACELP16k, st->rf_flag, st->is_ism_format );
    move16();
move32();

st->fscale = sr2fscale_fx( st->sr_core );
move16();
fscaleFB = sr2fscale_fx( st->output_Fs );
    move16();

/* initializing variables for frame lengths etc. right in the beginning */
st->L_frame = extract_l( Mult_32_16( st->sr_core, INV_FRAME_PER_SEC_Q15 ) );
move16();
    if ( st->ini_frame == 0 )
IF( st->ini_frame == 0 )
{
    st->last_L_frame = st->L_frame_past = st->L_frame; /* Q0 */
    move16();
@@ -1178,6 +1185,14 @@ void open_decoder_LPD_ivas_fx(
                                                                                             // assert(st->fscale == 2 * st->L_frame); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */
                                                                                             // assert(st->bits_frame == (int16_t)(((float)st->L_frame / (float)st->fscale) * (float)FSCALE_DENOM / 128.0f * (float)total_brate / 100.0f + 0.49f));
move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( EQ_16( st->element_mode, EVS_MONO ) )
{
    assert( FSCALE_DENOM == 512 );
    assert( st->fscale == 2 * st->L_frame ); /* this assumption is true if operated in 20ms frames with FSCALE_DENOM == 512, which is the current default */
    assert( st->bits_frame == (int) ( (float) st->L_frame / (float) st->fscale * (float) FSCALE_DENOM / 128.0f * (float) st->total_brate / 100.0f + 0.49f ) );
}
#endif
st->TcxBandwidth = getTcxBandwidth( bwidth );
move16();
st->narrowBand = 0;
@@ -1241,6 +1256,21 @@ void open_decoder_LPD_ivas_fx(
st->inv_gamma = GAMMA1_INV;
move16();
test();

#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( EQ_32( st->sr_core, INT_FS_16k ) )
{
    st->gamma = GAMMA16k;
    move16();
    st->inv_gamma = GAMMA16k_INV;
    move16();
}
ELSE
{
    st->gamma = GAMMA1;
    move16();
}
#else
    IF( EQ_32( st->sr_core, INT_FS_16k ) )
    {
        st->gamma = GAMMA16k;
@@ -1260,6 +1290,7 @@ void open_decoder_LPD_ivas_fx(
        st->gamma = GAMMA1;
        move16();
    }
#endif

/* LPC quantization */
test();
@@ -1341,8 +1372,19 @@ void open_decoder_LPD_ivas_fx(
    move16();

    IF( st->hTcxDec != NULL )
    {
#ifdef HARMONIZATION_2583_open_decoder_LPD
        IF( EQ_16( st->element_mode, EVS_MONO ) )
        {
            set16_fx( hTcxDec->old_syn_Overl, 0, shr( L_FRAME32k, 1 ) );     /* hTcxDec->Q_syn_Overl_TDACFB */
            set16_fx( hTcxDec->syn_Overl_TDAC, 0, shr( L_FRAME32k, 1 ) );    /* hTcxDec->Q_syn_Overl_TDAC */
            set16_fx( hTcxDec->syn_Overl_TDACFB, 0, shr( L_FRAME_MAX, 1 ) ); /* hTcxDec->Q_syn_Overl_TDACFB */
            set16_fx( hTcxDec->syn_Overl, 0, shr( L_FRAME32k, 1 ) );         /* hTcxDec->Q_syn_Overl */
        }
        ELSE
        {
            reset_tcx_overl_buf_fx( st->hTcxDec );
        }
        set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 );      /* Qx */
        set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
        hTcxDec->q_old_synth = 0;
@@ -1350,6 +1392,16 @@ void open_decoder_LPD_ivas_fx(
        set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); /* hTcxDec->q_synth_history_fx */
        hTcxDec->q_synth_history_fx = 0;
        move16();
#else
            reset_tcx_overl_buf_fx( st->hTcxDec );
            set16_fx( hTcxDec->syn_OverlFB, 0, L_FRAME_MAX / 2 );      /* Qx */
            set16_fx( hTcxDec->old_synth, 0, OLD_SYNTH_INTERNAL_DEC ); /* hTcxDec->q_old_synth */
            hTcxDec->q_old_synth = 0;
            move16();
            set16_fx( hTcxDec->synth_history_fx, 0, L_PROT48k + L_FRAME_MAX ); /* hTcxDec->q_synth_history_fx */
            hTcxDec->q_synth_history_fx = 0;
            move16();
#endif
    }
    set16_fx( st->syn, 0, M + 1 );           /* Q_syn */
    set16_fx( st->mem_syn_r, 0, L_SYN_MEM ); /* Qx */
@@ -1417,6 +1469,73 @@ void open_decoder_LPD_ivas_fx(
    test();
    test();
    test();
#ifdef HARMONIZATION_2583_open_decoder_LPD
    IF( EQ_16( st->element_mode, EVS_MONO ) )
    {
        IF( ( NE_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->prev_bfi ) ) && EQ_16( st->last_codec_mode, MODE1 ) && ( st->last_core == ACELP_CORE ) )
        {
            st->last_core_bfi = ACELP_CORE;
            move16();

            /*PLC*/
            IF( st->prev_bfi != 0 )
            {
                PWord16 const *w;
                Word16 W1, W2, nz, delay_comp;

                W1 = st->hTcxCfg->tcx_mdct_window_lengthFB; /* Q0 */
                move16();
                W2 = shr( st->hTcxCfg->tcx_mdct_window_lengthFB, 1 );
                w = st->hTcxCfg->tcx_mdct_windowFB; /*pointer - no need to instrument*/

                nz = NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS );
                move16();
                delay_comp = NS2SA_FX2( st->output_Fs, DELAY_CLDFB_NS ); /*CLDFB delay*/
                move16();

                Copy( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_OverlFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* hHQ_core->Q_fer_samples*/
                hTcxDec->Q_syn_OverlFB = hHQ_core->Q_fer_samples;
                move16();
                lerp( hHQ_core->fer_samples_fx + delay_comp, hTcxDec->syn_Overl, shr( st->L_frame, 1 ), shr( hTcxDec->L_frameTCX, 1 ) ); /*Q0: ACELP(bfi)->TCX(rect)*/
                hTcxDec->Q_syn_Overl = hHQ_core->Q_fer_samples;
                move16();

                /*old_out needed for MODE1 routine and syn_Overl_TDAC for MODE2 routine*/
                hHQ_core->Q_old_wtda = -1;
                move16();
                set16_fx( hHQ_core->old_out_fx, 0, nz );                                                                      /* exp(exp_old_out) */
                Copy_Scale_sig( hHQ_core->fer_samples_fx + delay_comp, hHQ_core->old_out_fx + nz, W1, hHQ_core->Q_old_wtda ); /*Q-1*/

                FOR( i = 0; i < W2; i++ )
                {
                    hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[i].v.re, w[i].v.re ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */
                    move16();
                }
                FOR( ; i < W1; i++ )
                {
                    hHQ_core->old_out_fx[i + nz] = round_fx( Mpy_32_16_1( L_mult( w[W2 - ( 1 + ( i - W2 ) )].v.im, w[W2 - ( 1 + ( i - W2 ) )].v.im ), hHQ_core->old_out_fx[i + nz] ) ); /* exp(exp_old_out) */
                    move16();
                }
                set16_fx( &hHQ_core->old_out_fx[W1 + nz], 0, nz );

                lerp( hHQ_core->old_out_fx, hHQ_core->old_out_LB_fx, st->L_frame, hTcxDec->L_frameTCX );

                Copy( hHQ_core->old_out_fx + nz, hTcxDec->syn_Overl_TDACFB, shr( hTcxDec->L_frameTCX, 1 ) ); /* exp(exp_old_out) */
                hTcxDec->Q_syn_Overl_TDACFB = hHQ_core->Q_old_wtda;
                move16();
                nz = NS2SA_FX2( st->sr_core, N_ZERO_MDCT_NS );
                move16();
                Copy( hHQ_core->old_out_LB_fx + nz, hTcxDec->syn_Overl_TDAC, shr( st->L_frame, 1 ) ); /* hHQ_core->q_old_outLB_fx */
                hHQ_core->Q_old_wtda_LB = hHQ_core->Q_old_wtda;
                move16();
                hTcxDec->Q_syn_Overl_TDAC = hHQ_core->Q_old_wtda_LB;
                move16();
            }
        }
    }
    ELSE
    {
#endif
        IF( ( NE_16( st->element_mode, IVAS_CPE_DFT ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && st->prev_bfi ) ) && EQ_16( st->last_codec_mode, MODE1 ) && ( st->last_core == ACELP_CORE ) )
        {
            /* Switching from Mode 1 ACELP */
@@ -1440,6 +1559,9 @@ void open_decoder_LPD_ivas_fx(
                move16();
            }
        }
#ifdef HARMONIZATION_2583_open_decoder_LPD
    }
#endif
    test();
    test();
    test();
@@ -1474,13 +1596,34 @@ void open_decoder_LPD_ivas_fx(
        /*OLA -> zero */
        IF( st->hTcxDec != NULL )
        {
#ifdef HARMONIZATION_2583_open_decoder_LPD
            IF( EQ_16( st->element_mode, EVS_MONO ) )
            {
                set16_fx( hTcxDec->old_syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/     /* Q_old_syn_Overl */
                set16_fx( hTcxDec->syn_Overl_TDAC, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/    /* Q_syn_Overl_TDAC */
                set16_fx( hTcxDec->syn_Overl_TDACFB, 0, L_FRAME_MAX / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/ /* Q_syn_Overl_TDACFB */
                set16_fx( hTcxDec->syn_Overl, 0, L_FRAME32k / 2 ); /*HQ-CORE(bfi)->TCX don't need it*/         /* Q_syn_Overl */
            }
            ELSE
            {
#endif
                reset_tcx_overl_buf_fx( st->hTcxDec );
#ifdef HARMONIZATION_2583_open_decoder_LPD
            }
#endif
        }

        IF( st->hTcxCfg != NULL )
        {
            Copy_Scale_sig( hHQ_core->old_out_fx + NS2SA_FX2( st->output_Fs, N_ZERO_MDCT_NS ), hTcxDec->syn_OverlFB, st->hTcxCfg->tcx_mdct_window_lengthFB, negate( add( hHQ_core->Q_old_wtda, TCX_IMDCT_HEADROOM ) ) ); /* Q_old_out */
#ifdef HARMONIZATION_2583_open_decoder_LPD
            IF( GT_16( st->element_mode, EVS_MONO ) )
            {
#endif
                *Q_syn_OverlFB = *Q_old_out;
#ifdef HARMONIZATION_2583_open_decoder_LPD
            }
#endif
            move16();
            st->hTcxCfg->last_aldo = 1; /*It was previously ALDO*/
            move16();
@@ -1497,13 +1640,23 @@ void open_decoder_LPD_ivas_fx(
        st->last_core_bfi = TCX_20_CORE;
        move16();

            IF( st->hPFstat != NULL )
        if ( st->hPFstat != NULL )
        {
            st->hPFstat->on = 0;
            move16();
        }

        /* reset CLDFB memories */
#ifdef HARMONIZATION_2583_open_decoder_LPD
        IF( EQ_16( st->element_mode, EVS_MONO ) )
        {
            cldfb_reset_memory( st->cldfbAna );
            cldfb_reset_memory( st->cldfbBPF );
            cldfb_reset_memory( st->cldfbSyn );
        }
        ELSE
        {
#endif
            cldfb_reset_memory_fx( st->cldfbAna );
            cldfb_reset_memory_fx( st->cldfbBPF );
            cldfb_reset_memory_fx( st->cldfbSyn );
@@ -1511,6 +1664,9 @@ void open_decoder_LPD_ivas_fx(
            {
                cldfb_reset_memory_fx( st->cldfbSynHB );
            }
#ifdef HARMONIZATION_2583_open_decoder_LPD
        }
#endif
    }
    ELSE IF( ( NE_16( st->L_frame, st->last_L_frame ) ) && ( LE_16( st->L_frame, L_FRAME16k ) ) && ( LE_16( st->last_L_frame, L_FRAME16k ) ) ) /* Rate switching between 12.8 and 16 kHz*/
    {
@@ -1530,8 +1686,15 @@ void open_decoder_LPD_ivas_fx(
        E_LPC_f_lsp_a_conversion( st->lsp_old_fx, st->old_Aq_12_8_fx, M );
        Copy( st->lsp_old_fx, st->lspold_uw, M ); /* Q15 */
        Copy( st->lsf_old_fx, st->lsfold_uw, M ); /* Q2.56 */
#ifdef HARMONIZATION_2583_open_decoder_LPD
        IF( GT_16( st->element_mode, EVS_MONO ) )
        {
#endif
            *Q_old_Aq_12_8 = 14;
            move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
        }
#endif
        IF( !st->last_con_tcx )
        {
            synth_mem_updt2_fx( st->L_frame, st->last_L_frame, st->old_exc_fx, st->mem_syn_r, st->mem_syn2_fx, NULL, DEC );
@@ -1559,11 +1722,12 @@ void open_decoder_LPD_ivas_fx(
        lerp( st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_old ), st->mem_syn_r + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
        Copy( st->mem_syn_r + L_SYN_MEM - M, st->mem_syn2_fx, M ); /* Qx */
    }
        /* update of lsf_old only needed in BASOP */
        /* ELSE IF( !st->tcxonly && (st->L_frame == L_FRAME16k) && (st->last_total_brate > ACELP_32k) ) */
        /* { */
        /*     lsp2lsf( st->lsp_old, st->lsf_old, M, st->sr_core ); */
        /* } */
#ifdef HARMONIZATION_2583_open_decoder_LPD
    ELSE IF( EQ_16( st->element_mode, EVS_MONO ) && ( !st->tcxonly && EQ_16( st->L_frame, L_FRAME16k ) && GT_32( st->last_total_brate, ACELP_32k ) ) )
    {
        lsp2lsf_fx( st->lsp_old_fx, st->lsf_old_fx, M, st->sr_core );
    }
#endif
}
test();
test();
@@ -1624,7 +1788,7 @@ void open_decoder_LPD_ivas_fx(
    /*codec mode switching*/

    /*reset post-filter except for Narrowband*/
        IF( NE_32( st->output_Fs, i_mult( L_FRAME8k, FRAMES_PER_SEC ) ) )
    IF( NE_32( st->output_Fs, L_FRAME8k * FRAMES_PER_SEC ) )
    {
        IF( st->hPFstat != NULL )
        {
@@ -1634,10 +1798,13 @@ void open_decoder_LPD_ivas_fx(
            {
                st->hPFstat->reset = 0;
                move16();
                    //-------------Present in EVS
                    // Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn)); /* WB post_filter mem */
                    // Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn));   /* WB post_filter mem */
                    //--------------
#ifdef HARMONIZATION_2583_open_decoder_LPD
                IF( EQ_16( st->element_mode, EVS_MONO ) )
                {
                    Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */ /* q_mem - st->Q_syn */
                    Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* WB post_filter mem */   /* q_mem - st->Q_syn */
                }
#endif
                lerp( st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_stp + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
                lerp( st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_old ), st->hPFstat->mem_pf_in + sub( L_SYN_MEM, mem_syn_r_size_new ), mem_syn_r_size_new, mem_syn_r_size_old );
            }
@@ -1645,14 +1812,17 @@ void open_decoder_LPD_ivas_fx(
    }
    ELSE
    {
            //----------------Present in EVS
            // IF(st->hPFstat != NULL)
            //{
            // Scale_sig(st->hPFstat->mem_pf_in, L_SUBFR, negate(st->Q_syn));    /* NB post_filter mem */
            // Scale_sig(st->hPFstat->mem_res2, DECMEM_RES2, negate(st->Q_syn)); /* NB post_filter mem */
            // Scale_sig(st->hPFstat->mem_stp, L_SUBFR, negate(st->Q_syn));      /* NB post_filter mem */
            //}
            //------------------
#ifdef HARMONIZATION_2583_open_decoder_LPD
        test();

        IF( ( st->hPFstat != NULL ) && ( st->hPFstat != NULL ) )
        {
            Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */    /* q_mem - st->Q_syn */
            Scale_sig( st->hPFstat->mem_res2, DECMEM_RES2, negate( st->Q_syn ) ); /* NB post_filter mem */ /* q_mem - st->Q_syn */
            Scale_sig( st->hPFstat->mem_stp, L_SUBFR, negate( st->Q_syn ) ); /* NB post_filter mem */      /* q_mem - st->Q_syn */
        }

#endif
        /*feed last value old_synth as it is used for pre-emphasis mem*/
        if ( st->hTcxDec != NULL )
        {
@@ -1696,6 +1866,13 @@ void open_decoder_LPD_ivas_fx(
st->last_gain_syn_deemph = 32768 / 2; /* 1.f Q14*/
move16();

#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( EQ_16( st->element_mode, EVS_MONO ) )
{
    st->last_gain_syn_deemph_e = 1;
    move16();
}
#endif
test();
IF( EQ_16( st->last_codec_mode, MODE1 ) || ( st->ini_frame == 0 ) )
{
@@ -1707,11 +1884,22 @@ void open_decoder_LPD_ivas_fx(
    move16();
    if ( hTcxDec != NULL )
    {
#ifdef HARMONIZATION_2583_open_decoder_LPD
        IF( EQ_16( st->element_mode, EVS_MONO ) )
        {
            hTcxDec->conceal_eof_gain = 32768 / 2; /*Q14*/
            move16();
        }
        ELSE
        {
#endif
            hTcxDec->conceal_eof_gain32 = ONE_IN_Q30; /*Q30*/
            hTcxDec->conceal_eof_gain_e = 1;
            move16();
            move32();
            move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
        }
#endif
    }
}
/* Post processing */
@@ -1725,15 +1913,26 @@ void open_decoder_LPD_ivas_fx(
    move16();
    st->last_core_bfi = -1;
    move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
    IF( GT_16( st->element_mode, EVS_MONO ) )
    {
#endif
        if ( st->hTcxDec != NULL )
        {
            hTcxDec->tcxConceal_recalc_exc = 0;
            move16();
        }
#ifdef HARMONIZATION_2583_open_decoder_LPD
    }
#endif
}
st->prev_old_bfi = 0;
move16();

#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( GT_16( st->element_mode, EVS_MONO ) )
{
#endif
    IF( st->hTcxDec != NULL )
    {
        st->hTcxDec->noise_filling_index[0] = st->hTcxDec->noise_filling_index[1] = 0;
@@ -1744,6 +1943,9 @@ void open_decoder_LPD_ivas_fx(
        move16();
        set16_fx( st->hTcxDec->ltpGainMemory_fx, 0, N_LTP_GAIN_MEMS ); /* Q15 */
    }
#ifdef HARMONIZATION_2583_open_decoder_LPD
}
#endif

Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M ); /* Q2.56 */
Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M );        /* Q2.56 */
@@ -1778,13 +1980,49 @@ void open_decoder_LPD_ivas_fx(
move32();
st->Mode2_lp_gainp = L_deposit_l( 0 );
move32();
#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( EQ_16( st->element_mode, EVS_MONO ) )
{
    st->hTcxDec->prev_widow_left_rect = 0;
    move16();
}
ELSE
{
#endif
    st->lp_gainc_fx = 0; /* Q3 */
    move16();
    st->lp_gainp_fx = 0; /* Q14 */
    move16();

#ifdef HARMONIZATION_2583_open_decoder_LPD
}
#endif
IF( st->hTcxDec != NULL )
{
#ifdef HARMONIZATION_2583_open_decoder_LPD
    IF( EQ_16( st->element_mode, EVS_MONO ) )
    {
        hTcxDec->conCngLevelBackgroundTrace = PLC_MIN_CNG_LEV_Q21; /*Q21*/
        move16();
        hTcxDec->conNoiseLevelIndex = PLC_MIN_STAT_BUFF_SIZE - 1; /* Q0 */
        move16();
        hTcxDec->conCurrLevelIndex = 0; /* Q0 */
        move16();
        hTcxDec->conLastFrameLevel = PLC_MIN_CNG_LEV; /*Q15*/
        move16();
        set16_fx( hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); /*Q15*/
        set16_fx( hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE );
        hTcxDec->conLastFrameLevel_e = 0; /* Q15 */
        move16();
        hTcxDec->conCngLevelBackgroundTrace_e = -6;
        move16();

        hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
        move16();
    }
    ELSE
    {
#endif
        st->hTcxDec->prev_widow_left_rect = 0;
        move16();
        test();
@@ -1821,6 +2059,9 @@ void open_decoder_LPD_ivas_fx(
            hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/;
            move16();
        }
#ifdef HARMONIZATION_2583_open_decoder_LPD
    }
#endif
}
st->cummulative_damping = 32767 /*1.0f Q15*/;
move16();
@@ -1838,6 +2079,13 @@ void open_decoder_LPD_ivas_fx(
}
st->old_fpitch = L_deposit_h( st->pit_min );
move32();
#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( EQ_16( st->element_mode, EVS_MONO ) )
{
    st->old_fpitchFB = L_deposit_h( hTcxDec->pit_min_TCX );
    move32();
}
#endif
st->rate_switching_init = 1;
move16();

@@ -1853,6 +2101,49 @@ void open_decoder_LPD_ivas_fx(
st->voice_fac = -1;
move16();

#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( EQ_16( st->element_mode, EVS_MONO ) )
{
    /* TCX-LTP */
    IF( hTcxLtpDec != NULL )
    {
        hTcxLtpDec->tcxltp = getTcxLtp( st->sr_core );
        move16();
    }
    move16();

    test();
    test();
    test();
    IF( hTcxLtpDec != NULL && ( EQ_16( st->ini_frame, 0 ) || ( EQ_16( st->last_codec_mode, MODE1 ) && st->element_mode == EVS_MONO ) ) )
    {
        hTcxLtpDec->tcxltp_pitch_int = st->pit_max; /* Q0 */
        move16();
        hTcxLtpDec->tcxltp_pitch_fr = 0; /* Q0 */
        move16();
        if ( hTcxDec != NULL )
        {
            hTcxDec->tcxltp_last_gain_unmodified = 0; /* Q15 */
            move16();
        }
        IF( st->ini_frame == 0 )
        {
            set16_fx( hTcxLtpDec->tcxltp_mem_in, 0, TCXLTP_MAX_DELAY ); /* hTcxLtpDec->exp_tcxltp_mem_out */
            set16_fx( hTcxLtpDec->tcxltp_mem_out, 0, L_FRAME48k );      /* hTcxLtpDec->exp_tcxltp_mem_out */
            hTcxLtpDec->tcxltp_pitch_int_post_prev = 0;
            move16();
            hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0;
            move16();
            hTcxLtpDec->tcxltp_gain_post_prev = 0;
            move16();
            hTcxLtpDec->tcxltp_filt_idx_prev = -1;
            move16();
        }
    }
}
ELSE
{
  #endif
    /* TCX-LTP */
    IF( hTcxLtpDec != NULL )
    {
@@ -1878,13 +2169,22 @@ void open_decoder_LPD_ivas_fx(
        hTcxDec->envWeighted = 0;
        move16();
    }

#ifdef HARMONIZATION_2583_open_decoder_LPD
}
#endif
IF( st->hBPF != NULL )
{
    st->lp_error_ener = Mpy_32_16_1( L_shl( hBPF->pst_lp_ener_fx, 8 ), 0x2a86 ); /* convert from 7Q8 10*log10 -> 15Q16, log2 */
    move32();
#ifdef HARMONIZATION_2583_open_decoder_LPD
    IF( GT_16( st->element_mode, EVS_MONO ) )
    {
#endif
        hBPF->pst_mem_deemp_err_fx = 0; /* Q_syn2 - 1 */
        move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
    }
#endif
}
ELSE
{
@@ -1893,17 +2193,53 @@ void open_decoder_LPD_ivas_fx(
}
st->mem_error = L_deposit_l( 0 );
move32();
#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( EQ_16( st->element_mode, EVS_MONO ) )
{
    st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, total_brate, st->rf_flag );
    move16();
    st->last_ctx_hm_enabled = 0; /* Q0 */
    move16();

    st->hTcxCfg->resq = getResq( total_brate ); /* Q0 */
    move16();

    st->hTcxCfg->sq_rounding = 12288 /*0.375f Q15*/; /*deadzone of 1.25->rounding=1-1.25/2 (No deadzone=0.5)*/
    move16();
    IF( hTcxDec != NULL )
    {
        hTcxDec->tcx_lpc_shaped_ari = getTcxLpcShapedAri( total_brate, st->rf_flag, st->element_mode );
        move16();
        hTcxDec->envWeighted = 0;
        move16();
    }
}
#endif
IF( st->tcxonly )
{
    st->p_bpf_noise_buf = NULL;
#ifdef HARMONIZATION_2583_open_decoder_LPD
    IF( GT_16( st->element_mode, EVS_MONO ) )
    {
#endif
        st->p_bpf_noise_buf_32 = NULL;
#ifdef HARMONIZATION_2583_open_decoder_LPD
    }
#endif
}
ELSE
{
    st->p_bpf_noise_buf = st->bpf_noise_buf;
    move32();
#ifdef HARMONIZATION_2583_open_decoder_LPD
    IF( GT_16( st->element_mode, EVS_MONO ) )
    {
#endif
        st->p_bpf_noise_buf_32 = st->bpf_noise_buf_32;
        move32();
#ifdef HARMONIZATION_2583_open_decoder_LPD
    }
#endif
}
test();
test();
@@ -1930,8 +2266,15 @@ void open_decoder_LPD_ivas_fx(

st->flagGuidedAcelp = 0;
move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
IF( GT_16( st->element_mode, EVS_MONO ) )
{
#endif
    st->tonal_mdct_plc_active = 0;
    move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
}
#endif
st->T0_4th = L_SUBFR;
move16();
st->guidedT0 = st->T0_4th;
@@ -1972,7 +2315,23 @@ void open_decoder_LPD_ivas_fx(
    move16();
    st->hTonalMDCTConc->lastBlockData.nSamples = 0;
    move16();
#ifdef HARMONIZE_2553_TonalConceal_Init
    TonalMDCTConceal_Init_fx( st->element_mode, st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
#else

#ifdef HARMONIZATION_2583_open_decoder_LPD
        IF( EQ_16( st->element_mode, EVS_MONO ) )
        {
            TonalMDCTConceal_Init_fx( st->hTonalMDCTConc, hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
        }
        ELSE
        {
#endif
            TonalMDCTConceal_Init_ivas_fx( st->hTonalMDCTConc, st->hTcxDec->L_frameTCX, st->L_frame, FDNS_NPTS, st->hTcxCfg );
#ifdef HARMONIZATION_2583_open_decoder_LPD
        }
#endif
#endif /*HARMONIZE_2553_TonalConceal_Init*/
}

st->last_tns_active = 0;
@@ -2009,8 +2368,28 @@ void open_decoder_LPD_ivas_fx(
test();
IF( ( EQ_32( total_brate, ACELP_9k60 ) || EQ_32( total_brate, ACELP_16k40 ) || EQ_32( total_brate, ACELP_24k40 ) ) && st->element_mode == EVS_MONO )
{
#ifdef HARMONIZATION_2583_open_decoder_LPD
    IF( EQ_16( st->element_mode, EVS_MONO ) )
    {
        test();
        test();
        test();
        IF( ( ( EQ_32( st->total_brate, 9600 ) ) || ( EQ_32( st->total_brate, 16400 ) ) ||
              ( EQ_32( st->total_brate, 24400 ) ) ) &&
            st->element_mode == EVS_MONO )
        {
            move16();
            st->dec_glr = 1;
        }
    }
    ELSE
    {
#endif
        st->dec_glr = 1;
        move16();
#ifdef HARMONIZATION_2583_open_decoder_LPD
    }
#endif
}
ELSE
{
@@ -2042,6 +2421,16 @@ void open_decoder_LPD_ivas_fx(
    move16();
}

#ifdef HARMONIZATION_2583_open_decoder_LPD
if ( EQ_16( st->element_mode, EVS_MONO ) )
{
    if ( hTcxLtpDec != NULL )
    {
        hTcxLtpDec->tcxltp_gain = 0; /* Q15 */
        move16();
    }
}
#endif
return;
}