void ff_aac_update_ltp(AACEncContext *s, SingleChannelElement *sce)

{

    int i, j, lag;

    float corr, s0, s1, max_corr = 0.0f;

    float *samples = &s->planar_samples[s->cur_channel][1024];

    float *pred_signal = &sce->ltp_state[0];

    int samples_num = 2048;



    if (s->profile != FF_PROFILE_AAC_LTP)

        return;



    /* Calculate lag */

    for (i = 0; i < samples_num; i++) {

        s0 = s1 = 0.0f;

        for (j = 0; j < samples_num; j++) {

            if (j + 1024 < i)

                continue;

            s0 += samples[j]*pred_signal[j-i+1024];

            s1 += pred_signal[j-i+1024]*pred_signal[j-i+1024];

        }

        corr = s1 > 0.0f ? s0/sqrt(s1) : 0.0f;

        if (corr > max_corr) {

            max_corr = corr;

            lag = i;

        }

    }

    lag = av_clip_uintp2(lag, 11); /* 11 bits => 2^11 = 0->2047 */



    if (!lag) {

        sce->ics.ltp.lag = lag;

        return;

    }



    s0 = s1 = 0.0f;

    for (i = 0; i < lag; i++) {

        s0 += samples[i];

        s1 += pred_signal[i-lag+1024];

    }



    sce->ics.ltp.coef_idx = quant_array_idx(s0/s1, ltp_coef, 8);

    sce->ics.ltp.coef     = ltp_coef[sce->ics.ltp.coef_idx];



    /* Predict the new samples */

    if (lag < 1024)

        samples_num = lag + 1024;

    for (i = 0; i < samples_num; i++)

        pred_signal[i+1024] = sce->ics.ltp.coef*pred_signal[i-lag+1024];

    memset(&pred_signal[samples_num], 0, (2048 - samples_num)*sizeof(float));



    sce->ics.ltp.lag = lag;

}

void ff_aac_update_ltp(AACEncContext *s, SingleChannelElement *sce)

{

    int i, j, lag;

    float corr, s0, s1, max_corr = 0.0f;

    float *samples = &s->planar_samples[s->cur_channel][1024];

    float *pred_signal = &sce->ltp_state[0];

    int samples_num = 2048;



    if (s->profile != FF_PROFILE_AAC_LTP)

        return;



    

    for (i = 0; i < samples_num; i++) {

        s0 = s1 = 0.0f;

        for (j = 0; j < samples_num; j++) {

            if (j + 1024 < i)

                continue;

            s0 += samples[j]*pred_signal[j-i+1024];

            s1 += pred_signal[j-i+1024]*pred_signal[j-i+1024];

        }

        corr = s1 > 0.0f ? s0/sqrt(s1) : 0.0f;

        if (corr > max_corr) {

            max_corr = corr;

            lag = i;

        }

    }

    lag = av_clip_uintp2(lag, 11); 



    if (!lag) {

        sce->ics.ltp.lag = lag;

        return;

    }



    s0 = s1 = 0.0f;

    for (i = 0; i < lag; i++) {

        s0 += samples[i];

        s1 += pred_signal[i-lag+1024];

    }



    sce->ics.ltp.coef_idx = quant_array_idx(s0/s1, ltp_coef, 8);

    sce->ics.ltp.coef     = ltp_coef[sce->ics.ltp.coef_idx];



    

    if (lag < 1024)

        samples_num = lag + 1024;

    for (i = 0; i < samples_num; i++)

        pred_signal[i+1024] = sce->ics.ltp.coef*pred_signal[i-lag+1024];

    memset(&pred_signal[samples_num], 0, (2048 - samples_num)*sizeof(float));



    sce->ics.ltp.lag = lag;

}

void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1)

{

    int VAR_2, VAR_3, VAR_4;

    float VAR_5, VAR_6, VAR_7, VAR_8 = 0.0f;

    float *VAR_9 = &VAR_0->planar_samples[VAR_0->cur_channel][1024];

    float *VAR_10 = &VAR_1->ltp_state[0];

    int VAR_11 = 2048;



    if (VAR_0->profile != FF_PROFILE_AAC_LTP)

        return;



    

    for (VAR_2 = 0; VAR_2 < VAR_11; VAR_2++) {

        VAR_6 = VAR_7 = 0.0f;

        for (VAR_3 = 0; VAR_3 < VAR_11; VAR_3++) {

            if (VAR_3 + 1024 < VAR_2)

                continue;

            VAR_6 += VAR_9[VAR_3]*VAR_10[VAR_3-VAR_2+1024];

            VAR_7 += VAR_10[VAR_3-VAR_2+1024]*VAR_10[VAR_3-VAR_2+1024];

        }

        VAR_5 = VAR_7 > 0.0f ? VAR_6/sqrt(VAR_7) : 0.0f;

        if (VAR_5 > VAR_8) {

            VAR_8 = VAR_5;

            VAR_4 = VAR_2;

        }

    }

    VAR_4 = av_clip_uintp2(VAR_4, 11); 



    if (!VAR_4) {

        VAR_1->ics.ltp.VAR_4 = VAR_4;

        return;

    }



    VAR_6 = VAR_7 = 0.0f;

    for (VAR_2 = 0; VAR_2 < VAR_4; VAR_2++) {

        VAR_6 += VAR_9[VAR_2];

        VAR_7 += VAR_10[VAR_2-VAR_4+1024];

    }



    VAR_1->ics.ltp.coef_idx = quant_array_idx(VAR_6/VAR_7, ltp_coef, 8);

    VAR_1->ics.ltp.coef     = ltp_coef[VAR_1->ics.ltp.coef_idx];



    

    if (VAR_4 < 1024)

        VAR_11 = VAR_4 + 1024;

    for (VAR_2 = 0; VAR_2 < VAR_11; VAR_2++)

        VAR_10[VAR_2+1024] = VAR_1->ics.ltp.coef*VAR_10[VAR_2-VAR_4+1024];

    memset(&VAR_10[VAR_11], 0, (2048 - VAR_11)*sizeof(float));



    VAR_1->ics.ltp.VAR_4 = VAR_4;

}

void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1)
{ int VAR_2, VAR_3, VAR_4; float VAR_5, VAR_6, VAR_7, VAR_8 = 0.0f; float *VAR_9 = &VAR_0->planar_samples[VAR_0->cur_channel][1024]; float *VAR_10 = &VAR_1->ltp_state[0]; int VAR_11 = 2048; if (VAR_0->profile != FF_PROFILE_AAC_LTP)
return; for (VAR_2 = 0; VAR_2 < VAR_11; VAR_2++) { VAR_6 = VAR_7 = 0.0f; for (VAR_3 = 0; VAR_3 < VAR_11; VAR_3++) { if (VAR_3 + 1024 < VAR_2)
continue; VAR_6 += VAR_9[VAR_3]*VAR_10[VAR_3-VAR_2+1024]; VAR_7 += VAR_10[VAR_3-VAR_2+1024]*VAR_10[VAR_3-VAR_2+1024]; } VAR_5 = VAR_7 > 0.0f ? VAR_6/sqrt(VAR_7) : 0.0f; if (VAR_5 > VAR_8) { VAR_8 = VAR_5; VAR_4 = VAR_2; } } VAR_4 = av_clip_uintp2(VAR_4, 11); if (!VAR_4) { VAR_1->ics.ltp.VAR_4 = VAR_4; return; } VAR_6 = VAR_7 = 0.0f; for (VAR_2 = 0; VAR_2 < VAR_4; VAR_2++) { VAR_6 += VAR_9[VAR_2]; VAR_7 += VAR_10[VAR_2-VAR_4+1024]; } VAR_1->ics.ltp.coef_idx = quant_array_idx(VAR_6/VAR_7, ltp_coef, 8); VAR_1->ics.ltp.coef     = ltp_coef[VAR_1->ics.ltp.coef_idx]; if (VAR_4 < 1024)
VAR_11 = VAR_4 + 1024; for (VAR_2 = 0; VAR_2 < VAR_11; VAR_2++) VAR_10[VAR_2+1024] = VAR_1->ics.ltp.coef*VAR_10[VAR_2-VAR_4+1024]; memset(&VAR_10[VAR_11], 0, (2048 - VAR_11)*sizeof(float)); VAR_1->ics.ltp.VAR_4 = VAR_4; }