void ff_aac_apply_tns(SingleChannelElement *sce)

{

    const int mmm = FFMIN(sce->ics.tns_max_bands, sce->ics.max_sfb);

    float *coef = sce->pcoeffs;

    TemporalNoiseShaping *tns = &sce->tns;

    int w, filt, m, i;

    int bottom, top, order, start, end, size, inc;

    float *lpc, tmp[TNS_MAX_ORDER+1];



    for (w = 0; w < sce->ics.num_windows; w++) {

        bottom = sce->ics.num_swb;

        for (filt = 0; filt < tns->n_filt[w]; filt++) {

            top    = bottom;

            bottom = FFMAX(0, top - tns->length[w][filt]);

            order  = tns->order[w][filt];

            lpc    = tns->coef[w][filt];

            if (!order)

                continue;



            start = sce->ics.swb_offset[FFMIN(bottom, mmm)];

            end   = sce->ics.swb_offset[FFMIN(   top, mmm)];

            if ((size = end - start) <= 0)

                continue;

            if (tns->direction[w][filt]) {

                inc = -1;

                start = end - 1;

            } else {

                inc = 1;

            }

            start += w * 128;



            if (!sce->ics.ltp.present) {

                // ar filter

                for (m = 0; m < size; m++, start += inc)

                    for (i = 1; i <= FFMIN(m, order); i++)

                        coef[start] += coef[start - i * inc]*lpc[i - 1];

            } else {

                // ma filter

                for (m = 0; m < size; m++, start += inc) {

                    tmp[0] = coef[start];

                    for (i = 1; i <= FFMIN(m, order); i++)

                        coef[start] += tmp[i]*lpc[i - 1];

                    for (i = order; i > 0; i--)

                        tmp[i] = tmp[i - 1];

                }

            }

        }

    }

}

void ff_aac_apply_tns(SingleChannelElement *sce)

{

    const int mmm = FFMIN(sce->ics.tns_max_bands, sce->ics.max_sfb);

    float *coef = sce->pcoeffs;

    TemporalNoiseShaping *tns = &sce->tns;

    int w, filt, m, i;

    int bottom, top, order, start, end, size, inc;

    float *lpc, tmp[TNS_MAX_ORDER+1];



    for (w = 0; w < sce->ics.num_windows; w++) {

        bottom = sce->ics.num_swb;

        for (filt = 0; filt < tns->n_filt[w]; filt++) {

            top    = bottom;

            bottom = FFMAX(0, top - tns->length[w][filt]);

            order  = tns->order[w][filt];

            lpc    = tns->coef[w][filt];

            if (!order)

                continue;



            start = sce->ics.swb_offset[FFMIN(bottom, mmm)];

            end   = sce->ics.swb_offset[FFMIN(   top, mmm)];

            if ((size = end - start) <= 0)

                continue;

            if (tns->direction[w][filt]) {

                inc = -1;

                start = end - 1;

            } else {

                inc = 1;

            }

            start += w * 128;



            if (!sce->ics.ltp.present) {

                

                for (m = 0; m < size; m++, start += inc)

                    for (i = 1; i <= FFMIN(m, order); i++)

                        coef[start] += coef[start - i * inc]*lpc[i - 1];

            } else {

                

                for (m = 0; m < size; m++, start += inc) {

                    tmp[0] = coef[start];

                    for (i = 1; i <= FFMIN(m, order); i++)

                        coef[start] += tmp[i]*lpc[i - 1];

                    for (i = order; i > 0; i--)

                        tmp[i] = tmp[i - 1];

                }

            }

        }

    }

}

void FUNC_0(SingleChannelElement *VAR_0)

{

    const int VAR_1 = FFMIN(VAR_0->ics.tns_max_bands, VAR_0->ics.max_sfb);

    float *VAR_2 = VAR_0->pcoeffs;

    TemporalNoiseShaping *tns = &VAR_0->tns;

    int VAR_3, VAR_4, VAR_5, VAR_6;

    int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;

    float *VAR_14, tmp[TNS_MAX_ORDER+1];



    for (VAR_3 = 0; VAR_3 < VAR_0->ics.num_windows; VAR_3++) {

        VAR_7 = VAR_0->ics.num_swb;

        for (VAR_4 = 0; VAR_4 < tns->n_filt[VAR_3]; VAR_4++) {

            VAR_8    = VAR_7;

            VAR_7 = FFMAX(0, VAR_8 - tns->length[VAR_3][VAR_4]);

            VAR_9  = tns->VAR_9[VAR_3][VAR_4];

            VAR_14    = tns->VAR_2[VAR_3][VAR_4];

            if (!VAR_9)

                continue;



            VAR_10 = VAR_0->ics.swb_offset[FFMIN(VAR_7, VAR_1)];

            VAR_11   = VAR_0->ics.swb_offset[FFMIN(   VAR_8, VAR_1)];

            if ((VAR_12 = VAR_11 - VAR_10) <= 0)

                continue;

            if (tns->direction[VAR_3][VAR_4]) {

                VAR_13 = -1;

                VAR_10 = VAR_11 - 1;

            } else {

                VAR_13 = 1;

            }

            VAR_10 += VAR_3 * 128;



            if (!VAR_0->ics.ltp.present) {

                

                for (VAR_5 = 0; VAR_5 < VAR_12; VAR_5++, VAR_10 += VAR_13)

                    for (VAR_6 = 1; VAR_6 <= FFMIN(VAR_5, VAR_9); VAR_6++)

                        VAR_2[VAR_10] += VAR_2[VAR_10 - VAR_6 * VAR_13]*VAR_14[VAR_6 - 1];

            } else {

                

                for (VAR_5 = 0; VAR_5 < VAR_12; VAR_5++, VAR_10 += VAR_13) {

                    tmp[0] = VAR_2[VAR_10];

                    for (VAR_6 = 1; VAR_6 <= FFMIN(VAR_5, VAR_9); VAR_6++)

                        VAR_2[VAR_10] += tmp[VAR_6]*VAR_14[VAR_6 - 1];

                    for (VAR_6 = VAR_9; VAR_6 > 0; VAR_6--)

                        tmp[VAR_6] = tmp[VAR_6 - 1];

                }

            }

        }

    }

}

void FUNC_0(SingleChannelElement *VAR_0)
{ const int VAR_1 = FFMIN(VAR_0->ics.tns_max_bands, VAR_0->ics.max_sfb); float *VAR_2 = VAR_0->pcoeffs; TemporalNoiseShaping *tns = &VAR_0->tns; int VAR_3, VAR_4, VAR_5, VAR_6; int VAR_7, VAR_8, VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; float *VAR_14, tmp[TNS_MAX_ORDER+1]; for (VAR_3 = 0; VAR_3 < VAR_0->ics.num_windows; VAR_3++) { VAR_7 = VAR_0->ics.num_swb; for (VAR_4 = 0; VAR_4 < tns->n_filt[VAR_3]; VAR_4++) { VAR_8    = VAR_7; VAR_7 = FFMAX(0, VAR_8 - tns->length[VAR_3][VAR_4]); VAR_9  = tns->VAR_9[VAR_3][VAR_4]; VAR_14    = tns->VAR_2[VAR_3][VAR_4]; if (!VAR_9)
continue; VAR_10 = VAR_0->ics.swb_offset[FFMIN(VAR_7, VAR_1)]; VAR_11   = VAR_0->ics.swb_offset[FFMIN(   VAR_8, VAR_1)]; if ((VAR_12 = VAR_11 - VAR_10) <= 0)
continue; if (tns->direction[VAR_3][VAR_4]) { VAR_13 = -1; VAR_10 = VAR_11 - 1; } else { VAR_13 = 1; } VAR_10 += VAR_3 * 128; if (!VAR_0->ics.ltp.present) { for (VAR_5 = 0; VAR_5 < VAR_12; VAR_5++, VAR_10 += VAR_13) for (VAR_6 = 1; VAR_6 <= FFMIN(VAR_5, VAR_9); VAR_6++) VAR_2[VAR_10] += VAR_2[VAR_10 - VAR_6 * VAR_13]*VAR_14[VAR_6 - 1]; } else { for (VAR_5 = 0; VAR_5 < VAR_12; VAR_5++, VAR_10 += VAR_13) { tmp[0] = VAR_2[VAR_10]; for (VAR_6 = 1; VAR_6 <= FFMIN(VAR_5, VAR_9); VAR_6++) VAR_2[VAR_10] += tmp[VAR_6]*VAR_14[VAR_6 - 1]; for (VAR_6 = VAR_9; VAR_6 > 0; VAR_6--) tmp[VAR_6] = tmp[VAR_6 - 1]; } } } } }