static float quantize_band_cost(struct AACEncContext *s, const float *in,

                                const float *scaled, int size, int scale_idx,

                                int cb, const float lambda, const float uplim,

                                int *bits)

{

    const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];

    const float  Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];

    const float CLIPPED_ESCAPE = 165140.0f*IQ;

    int i, j, k;

    float cost = 0;

    const int dim = cb < FIRST_PAIR_BT ? 4 : 2;

    int resbits = 0;

#ifndef USE_REALLY_FULL_SEARCH

    const float  Q34 = sqrtf(Q * sqrtf(Q));

    const int range  = aac_cb_range[cb];

    const int maxval = aac_cb_maxval[cb];

    int offs[4];

#endif /* USE_REALLY_FULL_SEARCH */



    if (!cb) {

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

            cost += in[i]*in[i];

        if (bits)

            *bits = 0;

        return cost * lambda;

    }

#ifndef USE_REALLY_FULL_SEARCH

    offs[0] = 1;

    for (i = 1; i < dim; i++)

        offs[i] = offs[i-1]*range;

    quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval);

#endif /* USE_REALLY_FULL_SEARCH */

    for (i = 0; i < size; i += dim) {

        float mincost;

        int minidx  = 0;

        int minbits = 0;

        const float *vec;

#ifndef USE_REALLY_FULL_SEARCH

        int (*quants)[2] = &s->qcoefs[i];

        mincost = 0.0f;

        for (j = 0; j < dim; j++)

            mincost += in[i+j]*in[i+j];

        minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;

        minbits = ff_aac_spectral_bits[cb-1][minidx];

        mincost = mincost * lambda + minbits;

        for (j = 0; j < (1<<dim); j++) {

            float rd = 0.0f;

            int curbits;

            int curidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;

            int same   = 0;

            for (k = 0; k < dim; k++) {

                if ((j & (1 << k)) && quants[k][0] == quants[k][1]) {

                    same = 1;

                    break;

                }

            }

            if (same)

                continue;

            for (k = 0; k < dim; k++)

                curidx += quants[k][!!(j & (1 << k))] * offs[dim - 1 - k];

            curbits =  ff_aac_spectral_bits[cb-1][curidx];

            vec     = &ff_aac_codebook_vectors[cb-1][curidx*dim];

#else

        mincost = INFINITY;

        vec = ff_aac_codebook_vectors[cb-1];

        for (j = 0; j < ff_aac_spectral_sizes[cb-1]; j++, vec += dim) {

            float rd = 0.0f;

            int curbits = ff_aac_spectral_bits[cb-1][j];

#endif /* USE_REALLY_FULL_SEARCH */

            if (IS_CODEBOOK_UNSIGNED(cb)) {

                for (k = 0; k < dim; k++) {

                    float t = fabsf(in[i+k]);

                    float di;

                    if (vec[k] == 64.0f) { //FIXME: slow

                        //do not code with escape sequence small values

                        if (t < 39.0f*IQ) {

                            rd = INFINITY;

                            break;

                        }

                        if (t >= CLIPPED_ESCAPE) {

                            di = t - CLIPPED_ESCAPE;

                            curbits += 21;

                        } else {

                            int c = av_clip(quant(t, Q), 0, 8191);

                            di = t - c*cbrtf(c)*IQ;

                            curbits += av_log2(c)*2 - 4 + 1;

                        }

                    } else {

                        di = t - vec[k]*IQ;

                    }

                    if (vec[k] != 0.0f)

                        curbits++;

                    rd += di*di;

                }

            } else {

                for (k = 0; k < dim; k++) {

                    float di = in[i+k] - vec[k]*IQ;

                    rd += di*di;

                }

            }

            rd = rd * lambda + curbits;

            if (rd < mincost) {

                mincost = rd;

                minidx  = j;

                minbits = curbits;

            }

        }

        cost    += mincost;

        resbits += minbits;

        if (cost >= uplim)

            return uplim;

    }



    if (bits)

        *bits = resbits;

    return cost;

}

static float quantize_band_cost(struct AACEncContext *s, const float *in,

                                const float *scaled, int size, int scale_idx,

                                int cb, const float lambda, const float uplim,

                                int *bits)

{

    const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];

    const float  Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];

    const float CLIPPED_ESCAPE = 165140.0f*IQ;

    int i, j, k;

    float cost = 0;

    const int dim = cb < FIRST_PAIR_BT ? 4 : 2;

    int resbits = 0;

#ifndef USE_REALLY_FULL_SEARCH

    const float  Q34 = sqrtf(Q * sqrtf(Q));

    const int range  = aac_cb_range[cb];

    const int maxval = aac_cb_maxval[cb];

    int offs[4];

#endif 



    if (!cb) {

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

            cost += in[i]*in[i];

        if (bits)

            *bits = 0;

        return cost * lambda;

    }

#ifndef USE_REALLY_FULL_SEARCH

    offs[0] = 1;

    for (i = 1; i < dim; i++)

        offs[i] = offs[i-1]*range;

    quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval);

#endif 

    for (i = 0; i < size; i += dim) {

        float mincost;

        int minidx  = 0;

        int minbits = 0;

        const float *vec;

#ifndef USE_REALLY_FULL_SEARCH

        int (*quants)[2] = &s->qcoefs[i];

        mincost = 0.0f;

        for (j = 0; j < dim; j++)

            mincost += in[i+j]*in[i+j];

        minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;

        minbits = ff_aac_spectral_bits[cb-1][minidx];

        mincost = mincost * lambda + minbits;

        for (j = 0; j < (1<<dim); j++) {

            float rd = 0.0f;

            int curbits;

            int curidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;

            int same   = 0;

            for (k = 0; k < dim; k++) {

                if ((j & (1 << k)) && quants[k][0] == quants[k][1]) {

                    same = 1;

                    break;

                }

            }

            if (same)

                continue;

            for (k = 0; k < dim; k++)

                curidx += quants[k][!!(j & (1 << k))] * offs[dim - 1 - k];

            curbits =  ff_aac_spectral_bits[cb-1][curidx];

            vec     = &ff_aac_codebook_vectors[cb-1][curidx*dim];

#else

        mincost = INFINITY;

        vec = ff_aac_codebook_vectors[cb-1];

        for (j = 0; j < ff_aac_spectral_sizes[cb-1]; j++, vec += dim) {

            float rd = 0.0f;

            int curbits = ff_aac_spectral_bits[cb-1][j];

#endif 

            if (IS_CODEBOOK_UNSIGNED(cb)) {

                for (k = 0; k < dim; k++) {

                    float t = fabsf(in[i+k]);

                    float di;

                    if (vec[k] == 64.0f) { 

                        

                        if (t < 39.0f*IQ) {

                            rd = INFINITY;

                            break;

                        }

                        if (t >= CLIPPED_ESCAPE) {

                            di = t - CLIPPED_ESCAPE;

                            curbits += 21;

                        } else {

                            int c = av_clip(quant(t, Q), 0, 8191);

                            di = t - c*cbrtf(c)*IQ;

                            curbits += av_log2(c)*2 - 4 + 1;

                        }

                    } else {

                        di = t - vec[k]*IQ;

                    }

                    if (vec[k] != 0.0f)

                        curbits++;

                    rd += di*di;

                }

            } else {

                for (k = 0; k < dim; k++) {

                    float di = in[i+k] - vec[k]*IQ;

                    rd += di*di;

                }

            }

            rd = rd * lambda + curbits;

            if (rd < mincost) {

                mincost = rd;

                minidx  = j;

                minbits = curbits;

            }

        }

        cost    += mincost;

        resbits += minbits;

        if (cost >= uplim)

            return uplim;

    }



    if (bits)

        *bits = resbits;

    return cost;

}

static float quantize_band_cost(struct AACEncContext *s, const float *in,                 minidx  = j;     if (bits)         *bits = resbits;     return cost;     const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];     const float  Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];     const float CLIPPED_ESCAPE = 165140.0f*IQ;     int i, j, k; #ifndef USE_REALLY_FULL_SEARCH     const float  Q34 = sqrtf(Q * sqrtf(Q));     const int range  = aac_cb_range[cb];     const int maxval = aac_cb_maxval[cb];     int offs[4]; #ifndef USE_REALLY_FULL_SEARCH     offs[0] = 1;     for (i = 1; i < dim; i++)         offs[i] = offs[i-1]*range;     quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval);     for (i = 0; i < size; i += dim) {         float mincost;         int minidx  = 0;         int minbits = 0;         const float *vec; #ifndef USE_REALLY_FULL_SEARCH         int (*quants)[2] = &s->qcoefs[i];         mincost = 0.0f;         for (j = 0; j < dim; j++)             mincost += in[i+j]*in[i+j];         minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;         minbits = ff_aac_spectral_bits[cb-1][minidx];         mincost = mincost * lambda + minbits;         for (j = 0; j < (1<<dim); j++) {             float rd = 0.0f;             int curbits;             int curidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40;             int same   = 0;             for (k = 0; k < dim; k++) {                 if ((j & (1 << k)) && quants[k][0] == quants[k][1]) {                     same = 1;                     break;             if (same)                 continue;             for (k = 0; k < dim; k++)                 curidx += quants[k][!!(j & (1 << k))] * offs[dim - 1 - k];             curbits =  ff_aac_spectral_bits[cb-1][curidx];             vec     = &ff_aac_codebook_vectors[cb-1][curidx*dim]; #else         vec = ff_aac_codebook_vectors[cb-1];         mincost = INFINITY;         for (j = 0; j < ff_aac_spectral_sizes[cb-1]; j++, vec += dim) {             float rd = 0.0f;             int curbits = ff_aac_spectral_bits[cb-1][j];             if (IS_CODEBOOK_UNSIGNED(cb)) {                 for (k = 0; k < dim; k++) {                     float t = fabsf(in[i+k]);                     float di;                         if (t < 39.0f*IQ) {                             rd = INFINITY;                             break;                         if (t >= CLIPPED_ESCAPE) {                             di = t - CLIPPED_ESCAPE;                             curbits += 21;                         } else {                             int c = av_clip(quant(t, Q), 0, 8191);                             di = t - c*cbrtf(c)*IQ;                             curbits += av_log2(c)*2 - 4 + 1;                     } else {                         di = t - vec[k]*IQ;                     if (vec[k] != 0.0f)                         curbits++;                     rd += di*di;             } else {                 for (k = 0; k < dim; k++) {                     float di = in[i+k] - vec[k]*IQ;                     rd += di*di;             rd = rd * lambda + curbits;             if (rd < mincost) {                 mincost = rd;                 minbits = curbits;
static float FUNC_0(struct AACEncContext *VAR_0, const float *VAR_1,

                                const float *VAR_2, int VAR_3, int VAR_4,

                                int VAR_5, const float VAR_6, const float VAR_7,

                                int *VAR_8)

{

    const float VAR_9 = ff_aac_pow2sf_tab[200 + VAR_4 - SCALE_ONE_POS + SCALE_DIV_512];

    const float  VAR_10 = ff_aac_pow2sf_tab[200 - VAR_4 + SCALE_ONE_POS - SCALE_DIV_512];

    const float VAR_11 = 165140.0f*VAR_9;

    int VAR_12, VAR_13, VAR_14;

    float VAR_15 = 0;

    const int VAR_16 = VAR_5 < FIRST_PAIR_BT ? 4 : 2;

    int VAR_17 = 0;

#ifndef USE_REALLY_FULL_SEARCH

    const float  VAR_18 = sqrtf(VAR_10 * sqrtf(VAR_10));

    const int VAR_19  = aac_cb_range[VAR_5];

    const int VAR_20 = aac_cb_maxval[VAR_5];

    int VAR_21[4];

#endif 



    if (!VAR_5) {

        for (VAR_12 = 0; VAR_12 < VAR_3; VAR_12++)

            VAR_15 += VAR_1[VAR_12]*VAR_1[VAR_12];

        if (VAR_8)

            *VAR_8 = 0;

        return VAR_15 * VAR_6;

    }

#ifndef USE_REALLY_FULL_SEARCH

    VAR_21[0] = 1;

    for (VAR_12 = 1; VAR_12 < VAR_16; VAR_12++)

        VAR_21[VAR_12] = VAR_21[VAR_12-1]*VAR_19;

    quantize_bands(VAR_0->qcoefs, VAR_1, VAR_2, VAR_3, VAR_18, !IS_CODEBOOK_UNSIGNED(VAR_5), VAR_20);

#endif 

    for (VAR_12 = 0; VAR_12 < VAR_3; VAR_12 += VAR_16) {

        float VAR_22;

        int VAR_23  = 0;

        int VAR_24 = 0;

        const float *VAR_25;

#ifndef USE_REALLY_FULL_SEARCH

        int (*VAR_26)[2] = &VAR_0->qcoefs[VAR_12];

        VAR_22 = 0.0f;

        for (VAR_13 = 0; VAR_13 < VAR_16; VAR_13++)

            VAR_22 += VAR_1[VAR_12+VAR_13]*VAR_1[VAR_12+VAR_13];

        VAR_23 = IS_CODEBOOK_UNSIGNED(VAR_5) ? 0 : 40;

        VAR_24 = ff_aac_spectral_bits[VAR_5-1][VAR_23];

        VAR_22 = VAR_22 * VAR_6 + VAR_24;

        for (VAR_13 = 0; VAR_13 < (1<<VAR_16); VAR_13++) {

            float VAR_27 = 0.0f;

            int VAR_28;

            int VAR_29 = IS_CODEBOOK_UNSIGNED(VAR_5) ? 0 : 40;

            int VAR_30   = 0;

            for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++) {

                if ((VAR_13 & (1 << VAR_14)) && VAR_26[VAR_14][0] == VAR_26[VAR_14][1]) {

                    VAR_30 = 1;

                    break;

                }

            }

            if (VAR_30)

                continue;

            for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++)

                VAR_29 += VAR_26[VAR_14][!!(VAR_13 & (1 << VAR_14))] * VAR_21[VAR_16 - 1 - VAR_14];

            VAR_28 =  ff_aac_spectral_bits[VAR_5-1][VAR_29];

            VAR_25     = &ff_aac_codebook_vectors[VAR_5-1][VAR_29*VAR_16];

#else

        VAR_22 = INFINITY;

        VAR_25 = ff_aac_codebook_vectors[VAR_5-1];

        for (VAR_13 = 0; VAR_13 < ff_aac_spectral_sizes[VAR_5-1]; VAR_13++, VAR_25 += VAR_16) {

            float VAR_27 = 0.0f;

            int VAR_28 = ff_aac_spectral_bits[VAR_5-1][VAR_13];

#endif 

            if (IS_CODEBOOK_UNSIGNED(VAR_5)) {

                for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++) {

                    float VAR_31 = fabsf(VAR_1[VAR_12+VAR_14]);

                    float VAR_34;

                    if (VAR_25[VAR_14] == 64.0f) { 

                        

                        if (VAR_31 < 39.0f*VAR_9) {

                            VAR_27 = INFINITY;

                            break;

                        }

                        if (VAR_31 >= VAR_11) {

                            VAR_34 = VAR_31 - VAR_11;

                            VAR_28 += 21;

                        } else {

                            int VAR_33 = av_clip(quant(VAR_31, VAR_10), 0, 8191);

                            VAR_34 = VAR_31 - VAR_33*cbrtf(VAR_33)*VAR_9;

                            VAR_28 += av_log2(VAR_33)*2 - 4 + 1;

                        }

                    } else {

                        VAR_34 = VAR_31 - VAR_25[VAR_14]*VAR_9;

                    }

                    if (VAR_25[VAR_14] != 0.0f)

                        VAR_28++;

                    VAR_27 += VAR_34*VAR_34;

                }

            } else {

                for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++) {

                    float VAR_34 = VAR_1[VAR_12+VAR_14] - VAR_25[VAR_14]*VAR_9;

                    VAR_27 += VAR_34*VAR_34;

                }

            }

            VAR_27 = VAR_27 * VAR_6 + VAR_28;

            if (VAR_27 < VAR_22) {

                VAR_22 = VAR_27;

                VAR_23  = VAR_13;

                VAR_24 = VAR_28;

            }

        }

        VAR_15    += VAR_22;

        VAR_17 += VAR_24;

        if (VAR_15 >= VAR_7)

            return VAR_7;

    }



    if (VAR_8)

        *VAR_8 = VAR_17;

    return VAR_15;

}

static float FUNC_0(struct AACEncContext *VAR_0, const float *VAR_1,
const float *VAR_2, int VAR_3, int VAR_4,
int VAR_5, const float VAR_6, const float VAR_7,
int *VAR_8)
{ const float VAR_9 = ff_aac_pow2sf_tab[200 + VAR_4 - SCALE_ONE_POS + SCALE_DIV_512]; const float  VAR_10 = ff_aac_pow2sf_tab[200 - VAR_4 + SCALE_ONE_POS - SCALE_DIV_512]; const float VAR_11 = 165140.0f*VAR_9; int VAR_12, VAR_13, VAR_14; float VAR_15 = 0; const int VAR_16 = VAR_5 < FIRST_PAIR_BT ? 4 : 2; int VAR_17 = 0; #ifndef USE_REALLY_FULL_SEARCH
const float  VAR_18 = sqrtf(VAR_10 * sqrtf(VAR_10)); const int VAR_19  = aac_cb_range[VAR_5]; const int VAR_20 = aac_cb_maxval[VAR_5]; int VAR_21[4]; #endif
if (!VAR_5) { for (VAR_12 = 0; VAR_12 < VAR_3; VAR_12++) VAR_15 += VAR_1[VAR_12]*VAR_1[VAR_12]; if (VAR_8)
*VAR_8 = 0; return VAR_15 * VAR_6; } #ifndef USE_REALLY_FULL_SEARCH
VAR_21[0] = 1; for (VAR_12 = 1; VAR_12 < VAR_16; VAR_12++) VAR_21[VAR_12] = VAR_21[VAR_12-1]*VAR_19; quantize_bands(VAR_0->qcoefs, VAR_1, VAR_2, VAR_3, VAR_18, !IS_CODEBOOK_UNSIGNED(VAR_5), VAR_20); #endif
for (VAR_12 = 0; VAR_12 < VAR_3; VAR_12 += VAR_16) { float VAR_22; int VAR_23  = 0; int VAR_24 = 0; const float *VAR_25; #ifndef USE_REALLY_FULL_SEARCH
int (*VAR_26)[2] = &VAR_0->qcoefs[VAR_12]; VAR_22 = 0.0f; for (VAR_13 = 0; VAR_13 < VAR_16; VAR_13++) VAR_22 += VAR_1[VAR_12+VAR_13]*VAR_1[VAR_12+VAR_13]; VAR_23 = IS_CODEBOOK_UNSIGNED(VAR_5) ? 0 : 40; VAR_24 = ff_aac_spectral_bits[VAR_5-1][VAR_23]; VAR_22 = VAR_22 * VAR_6 + VAR_24; for (VAR_13 = 0; VAR_13 < (1<<VAR_16); VAR_13++) { float VAR_27 = 0.0f; int VAR_28; int VAR_29 = IS_CODEBOOK_UNSIGNED(VAR_5) ? 0 : 40; int VAR_30   = 0; for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++) { if ((VAR_13 & (1 << VAR_14)) && VAR_26[VAR_14][0] == VAR_26[VAR_14][1]) { VAR_30 = 1; break; } } if (VAR_30)
continue; for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++) VAR_29 += VAR_26[VAR_14][!!(VAR_13 & (1 << VAR_14))] * VAR_21[VAR_16 - 1 - VAR_14]; VAR_28 =  ff_aac_spectral_bits[VAR_5-1][VAR_29]; VAR_25     = &ff_aac_codebook_vectors[VAR_5-1][VAR_29*VAR_16]; #else
VAR_22 = INFINITY; VAR_25 = ff_aac_codebook_vectors[VAR_5-1]; for (VAR_13 = 0; VAR_13 < ff_aac_spectral_sizes[VAR_5-1]; VAR_13++, VAR_25 += VAR_16) { float VAR_27 = 0.0f; int VAR_28 = ff_aac_spectral_bits[VAR_5-1][VAR_13]; #endif
if (IS_CODEBOOK_UNSIGNED(VAR_5)) { for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++) { float VAR_31 = fabsf(VAR_1[VAR_12+VAR_14]); float VAR_34; if (VAR_25[VAR_14] == 64.0f) { if (VAR_31 < 39.0f*VAR_9) { VAR_27 = INFINITY; break; } if (VAR_31 >= VAR_11) { VAR_34 = VAR_31 - VAR_11; VAR_28 += 21; } else { int VAR_33 = av_clip(quant(VAR_31, VAR_10), 0, 8191); VAR_34 = VAR_31 - VAR_33*cbrtf(VAR_33)*VAR_9; VAR_28 += av_log2(VAR_33)*2 - 4 + 1; } } else { VAR_34 = VAR_31 - VAR_25[VAR_14]*VAR_9; } if (VAR_25[VAR_14] != 0.0f)
VAR_28++; VAR_27 += VAR_34*VAR_34; } } else { for (VAR_14 = 0; VAR_14 < VAR_16; VAR_14++) { float VAR_34 = VAR_1[VAR_12+VAR_14] - VAR_25[VAR_14]*VAR_9; VAR_27 += VAR_34*VAR_34; } } VAR_27 = VAR_27 * VAR_6 + VAR_28; if (VAR_27 < VAR_22) { VAR_22 = VAR_27; VAR_23  = VAR_13; VAR_24 = VAR_28; } } VAR_15    += VAR_22; VAR_17 += VAR_24; if (VAR_15 >= VAR_7)
return VAR_7; } if (VAR_8)
*VAR_8 = VAR_17; return VAR_15; }