void ff_aac_search_for_tns(AACEncContext *s, SingleChannelElement *sce)

{

    TemporalNoiseShaping *tns = &sce->tns;

    int w, g, order, sfb_start, sfb_len, coef_start, shift[MAX_LPC_ORDER], count = 0;

    const int is8 = sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE;

    const int tns_max_order = is8 ? 7 : s->profile == FF_PROFILE_AAC_LOW ? 12 : TNS_MAX_ORDER;

    const float freq_mult = mpeg4audio_sample_rates[s->samplerate_index]/(1024.0f/sce->ics.num_windows)/2.0f;

    float max_coef = 0.0f;



    sce->tns.present = 0;

    return;



    for (coef_start = 0; coef_start < 1024; coef_start++)

        max_coef = FFMAX(max_coef, sce->pcoeffs[coef_start]);



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

        int filters = 1, start = 0, coef_len = 0;

        int32_t conv_coeff[1024] = {0};

        int32_t coefs_t[MAX_LPC_ORDER][MAX_LPC_ORDER] = {{0}};



        /* Determine start sfb + coef - excludes anything below threshold */

        for (g = 0;  g < sce->ics.num_swb; g++) {

            if (start*freq_mult > TNS_LOW_LIMIT) {

                sfb_start = w*16+g;

                sfb_len   = (w+1)*16 + g - sfb_start;

                coef_start = sce->ics.swb_offset[sfb_start];

                coef_len  = sce->ics.swb_offset[sfb_start + sfb_len] - coef_start;

                break;

            }

            start += sce->ics.swb_sizes[g];

        }



        if (coef_len <= 0)

            continue;



        conv_to_int32(conv_coeff, &sce->pcoeffs[coef_start], coef_len, max_coef);



        /* LPC */

        order = ff_lpc_calc_coefs(&s->lpc, conv_coeff, coef_len,

                                  TNS_MIN_PRED_ORDER, tns_max_order,

                                  32, coefs_t, shift,

                                  FF_LPC_TYPE_LEVINSON, 10,

                                  ORDER_METHOD_EST, MAX_LPC_SHIFT, 0) - 1;



        /* Works surprisingly well, remember to tweak MAX_LPC_SHIFT if you want to play around with this */

        if (shift[order] > 3) {

            int direction = 0;

            float tns_coefs_raw[TNS_MAX_ORDER];

            tns->n_filt[w] = filters++;

            conv_to_float(tns_coefs_raw, coefs_t[order], order);

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

                process_tns_coeffs(tns, tns_coefs_raw, order, w, g);

                apply_tns_filter(&sce->coeffs[coef_start], sce->pcoeffs, order, direction, tns->coef[w][g],

                                 sce->ics.ltp.present, w, g, coef_start, coef_len);

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

                tns->length[w][g]    = sfb_len;

                tns->direction[w][g] = direction;

            }

            count++;

        }

    }



    sce->tns.present = !!count;

}

void ff_aac_search_for_tns(AACEncContext *s, SingleChannelElement *sce)

{

    TemporalNoiseShaping *tns = &sce->tns;

    int w, g, order, sfb_start, sfb_len, coef_start, shift[MAX_LPC_ORDER], count = 0;

    const int is8 = sce->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE;

    const int tns_max_order = is8 ? 7 : s->profile == FF_PROFILE_AAC_LOW ? 12 : TNS_MAX_ORDER;

    const float freq_mult = mpeg4audio_sample_rates[s->samplerate_index]/(1024.0f/sce->ics.num_windows)/2.0f;

    float max_coef = 0.0f;



    sce->tns.present = 0;

    return;



    for (coef_start = 0; coef_start < 1024; coef_start++)

        max_coef = FFMAX(max_coef, sce->pcoeffs[coef_start]);



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

        int filters = 1, start = 0, coef_len = 0;

        int32_t conv_coeff[1024] = {0};

        int32_t coefs_t[MAX_LPC_ORDER][MAX_LPC_ORDER] = {{0}};



        

        for (g = 0;  g < sce->ics.num_swb; g++) {

            if (start*freq_mult > TNS_LOW_LIMIT) {

                sfb_start = w*16+g;

                sfb_len   = (w+1)*16 + g - sfb_start;

                coef_start = sce->ics.swb_offset[sfb_start];

                coef_len  = sce->ics.swb_offset[sfb_start + sfb_len] - coef_start;

                break;

            }

            start += sce->ics.swb_sizes[g];

        }



        if (coef_len <= 0)

            continue;



        conv_to_int32(conv_coeff, &sce->pcoeffs[coef_start], coef_len, max_coef);



        

        order = ff_lpc_calc_coefs(&s->lpc, conv_coeff, coef_len,

                                  TNS_MIN_PRED_ORDER, tns_max_order,

                                  32, coefs_t, shift,

                                  FF_LPC_TYPE_LEVINSON, 10,

                                  ORDER_METHOD_EST, MAX_LPC_SHIFT, 0) - 1;



        

        if (shift[order] > 3) {

            int direction = 0;

            float tns_coefs_raw[TNS_MAX_ORDER];

            tns->n_filt[w] = filters++;

            conv_to_float(tns_coefs_raw, coefs_t[order], order);

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

                process_tns_coeffs(tns, tns_coefs_raw, order, w, g);

                apply_tns_filter(&sce->coeffs[coef_start], sce->pcoeffs, order, direction, tns->coef[w][g],

                                 sce->ics.ltp.present, w, g, coef_start, coef_len);

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

                tns->length[w][g]    = sfb_len;

                tns->direction[w][g] = direction;

            }

            count++;

        }

    }



    sce->tns.present = !!count;

}

void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1)

{

    TemporalNoiseShaping *tns = &VAR_1->tns;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, shift[MAX_LPC_ORDER], count = 0;

    const int VAR_8 = VAR_1->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE;

    const int VAR_9 = VAR_8 ? 7 : VAR_0->profile == FF_PROFILE_AAC_LOW ? 12 : TNS_MAX_ORDER;

    const float VAR_10 = mpeg4audio_sample_rates[VAR_0->samplerate_index]/(1024.0f/VAR_1->ics.num_windows)/2.0f;

    float VAR_11 = 0.0f;



    VAR_1->tns.present = 0;

    return;



    for (VAR_7 = 0; VAR_7 < 1024; VAR_7++)

        VAR_11 = FFMAX(VAR_11, VAR_1->pcoeffs[VAR_7]);



    for (VAR_2 = 0; VAR_2 < VAR_1->ics.num_windows; VAR_2++) {

        int filters = 1, start = 0, coef_len = 0;

        int32_t conv_coeff[1024] = {0};

        int32_t coefs_t[MAX_LPC_ORDER][MAX_LPC_ORDER] = {{0}};



        

        for (VAR_3 = 0;  VAR_3 < VAR_1->ics.num_swb; VAR_3++) {

            if (start*VAR_10 > TNS_LOW_LIMIT) {

                VAR_5 = VAR_2*16+VAR_3;

                VAR_6   = (VAR_2+1)*16 + VAR_3 - VAR_5;

                VAR_7 = VAR_1->ics.swb_offset[VAR_5];

                coef_len  = VAR_1->ics.swb_offset[VAR_5 + VAR_6] - VAR_7;

                break;

            }

            start += VAR_1->ics.swb_sizes[VAR_3];

        }



        if (coef_len <= 0)

            continue;



        conv_to_int32(conv_coeff, &VAR_1->pcoeffs[VAR_7], coef_len, VAR_11);



        

        VAR_4 = ff_lpc_calc_coefs(&VAR_0->lpc, conv_coeff, coef_len,

                                  TNS_MIN_PRED_ORDER, VAR_9,

                                  32, coefs_t, shift,

                                  FF_LPC_TYPE_LEVINSON, 10,

                                  ORDER_METHOD_EST, MAX_LPC_SHIFT, 0) - 1;



        

        if (shift[VAR_4] > 3) {

            int direction = 0;

            float tns_coefs_raw[TNS_MAX_ORDER];

            tns->n_filt[VAR_2] = filters++;

            conv_to_float(tns_coefs_raw, coefs_t[VAR_4], VAR_4);

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

                process_tns_coeffs(tns, tns_coefs_raw, VAR_4, VAR_2, VAR_3);

                apply_tns_filter(&VAR_1->coeffs[VAR_7], VAR_1->pcoeffs, VAR_4, direction, tns->coef[VAR_2][VAR_3],

                                 VAR_1->ics.ltp.present, VAR_2, VAR_3, VAR_7, coef_len);

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

                tns->length[VAR_2][VAR_3]    = VAR_6;

                tns->direction[VAR_2][VAR_3] = direction;

            }

            count++;

        }

    }



    VAR_1->tns.present = !!count;

}

void FUNC_0(AACEncContext *VAR_0, SingleChannelElement *VAR_1)
{ TemporalNoiseShaping *tns = &VAR_1->tns; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, shift[MAX_LPC_ORDER], count = 0; const int VAR_8 = VAR_1->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE; const int VAR_9 = VAR_8 ? 7 : VAR_0->profile == FF_PROFILE_AAC_LOW ? 12 : TNS_MAX_ORDER; const float VAR_10 = mpeg4audio_sample_rates[VAR_0->samplerate_index]/(1024.0f/VAR_1->ics.num_windows)/2.0f; float VAR_11 = 0.0f; VAR_1->tns.present = 0; return; for (VAR_7 = 0; VAR_7 < 1024; VAR_7++) VAR_11 = FFMAX(VAR_11, VAR_1->pcoeffs[VAR_7]); for (VAR_2 = 0; VAR_2 < VAR_1->ics.num_windows; VAR_2++) { int filters = 1, start = 0, coef_len = 0; int32_t conv_coeff[1024] = {0}; int32_t coefs_t[MAX_LPC_ORDER][MAX_LPC_ORDER] = {{0}}; for (VAR_3 = 0;  VAR_3 < VAR_1->ics.num_swb; VAR_3++) { if (start*VAR_10 > TNS_LOW_LIMIT) { VAR_5 = VAR_2*16+VAR_3; VAR_6   = (VAR_2+1)*16 + VAR_3 - VAR_5; VAR_7 = VAR_1->ics.swb_offset[VAR_5]; coef_len  = VAR_1->ics.swb_offset[VAR_5 + VAR_6] - VAR_7; break; } start += VAR_1->ics.swb_sizes[VAR_3]; } if (coef_len <= 0)
continue; conv_to_int32(conv_coeff, &VAR_1->pcoeffs[VAR_7], coef_len, VAR_11); VAR_4 = ff_lpc_calc_coefs(&VAR_0->lpc, conv_coeff, coef_len,
TNS_MIN_PRED_ORDER, VAR_9,
32, coefs_t, shift,
FF_LPC_TYPE_LEVINSON, 10,
ORDER_METHOD_EST, MAX_LPC_SHIFT, 0) - 1; if (shift[VAR_4] > 3) { int direction = 0; float tns_coefs_raw[TNS_MAX_ORDER]; tns->n_filt[VAR_2] = filters++; conv_to_float(tns_coefs_raw, coefs_t[VAR_4], VAR_4); for (VAR_3 = 0; VAR_3 < tns->n_filt[VAR_2]; VAR_3++) { process_tns_coeffs(tns, tns_coefs_raw, VAR_4, VAR_2, VAR_3); apply_tns_filter(&VAR_1->coeffs[VAR_7], VAR_1->pcoeffs, VAR_4, direction, tns->coef[VAR_2][VAR_3],
VAR_1->ics.ltp.present, VAR_2, VAR_3, VAR_7, coef_len); tns->VAR_4[VAR_2][VAR_3]     = VAR_4; tns->length[VAR_2][VAR_3]    = VAR_6; tns->direction[VAR_2][VAR_3] = direction; } count++; } } VAR_1->tns.present = !!count; }