static av_always_inline float quantize_and_encode_band_cost_template(

                                struct AACEncContext *s,

                                PutBitContext *pb, const float *in,

                                const float *scaled, int size, int scale_idx,

                                int cb, const float lambda, const float uplim,

                                int *bits, int BT_ZERO, int BT_UNSIGNED,

                                int BT_PAIR, int BT_ESC)

{

    const int q_idx = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512;

    const float Q   = ff_aac_pow2sf_tab [q_idx];

    const float Q34 = ff_aac_pow34sf_tab[q_idx];

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

    const float CLIPPED_ESCAPE = 165140.0f*IQ;

    int i, j;

    float cost = 0;

    const int dim = BT_PAIR ? 2 : 4;

    int resbits = 0;

    const int range  = aac_cb_range[cb];

    const int maxval = aac_cb_maxval[cb];

    int off;



    if (BT_ZERO) {

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

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

        if (bits)

            *bits = 0;

        return cost * lambda;

    }

    if (!scaled) {

        abs_pow34_v(s->scoefs, in, size);

        scaled = s->scoefs;

    }

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

    if (BT_UNSIGNED) {

        off = 0;

    } else {

        off = maxval;

    }

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

        const float *vec;

        int *quants = s->qcoefs + i;

        int curidx = 0;

        int curbits;

        float rd = 0.0f;

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

            curidx *= range;

            curidx += quants[j] + off;

        }

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

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

        if (BT_UNSIGNED) {

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

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

                float di;

                if (BT_ESC && vec[j] == 64.0f) { //FIXME: slow

                    if (t >= CLIPPED_ESCAPE) {

                        di = t - CLIPPED_ESCAPE;

                        curbits += 21;

                    } else {

                        int c = av_clip_uintp2(quant(t, Q), 13);

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

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

                    }

                } else {

                    di = t - vec[j]*IQ;

                }

                if (vec[j] != 0.0f)

                    curbits++;

                rd += di*di;

            }

        } else {

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

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

                rd += di*di;

            }

        }

        cost    += rd * lambda + curbits;

        resbits += curbits;

        if (cost >= uplim)

            return uplim;

        if (pb) {

            put_bits(pb, ff_aac_spectral_bits[cb-1][curidx], ff_aac_spectral_codes[cb-1][curidx]);

            if (BT_UNSIGNED)

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

                    if (ff_aac_codebook_vectors[cb-1][curidx*dim+j] != 0.0f)

                        put_bits(pb, 1, in[i+j] < 0.0f);

            if (BT_ESC) {

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

                    if (ff_aac_codebook_vectors[cb-1][curidx*2+j] == 64.0f) {

                        int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q), 13);

                        int len = av_log2(coef);



                        put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);

                        put_bits(pb, len, coef & ((1 << len) - 1));

                    }

                }

            }

        }

    }



    if (bits)

        *bits = resbits;

    return cost;

}

static av_always_inline float quantize_and_encode_band_cost_template(

                                struct AACEncContext *s,

                                PutBitContext *pb, const float *in,

                                const float *scaled, int size, int scale_idx,

                                int cb, const float lambda, const float uplim,

                                int *bits, int BT_ZERO, int BT_UNSIGNED,

                                int BT_PAIR, int BT_ESC)

{

    const int q_idx = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512;

    const float Q   = ff_aac_pow2sf_tab [q_idx];

    const float Q34 = ff_aac_pow34sf_tab[q_idx];

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

    const float CLIPPED_ESCAPE = 165140.0f*IQ;

    int i, j;

    float cost = 0;

    const int dim = BT_PAIR ? 2 : 4;

    int resbits = 0;

    const int range  = aac_cb_range[cb];

    const int maxval = aac_cb_maxval[cb];

    int off;



    if (BT_ZERO) {

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

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

        if (bits)

            *bits = 0;

        return cost * lambda;

    }

    if (!scaled) {

        abs_pow34_v(s->scoefs, in, size);

        scaled = s->scoefs;

    }

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

    if (BT_UNSIGNED) {

        off = 0;

    } else {

        off = maxval;

    }

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

        const float *vec;

        int *quants = s->qcoefs + i;

        int curidx = 0;

        int curbits;

        float rd = 0.0f;

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

            curidx *= range;

            curidx += quants[j] + off;

        }

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

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

        if (BT_UNSIGNED) {

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

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

                float di;

                if (BT_ESC && vec[j] == 64.0f) { 

                    if (t >= CLIPPED_ESCAPE) {

                        di = t - CLIPPED_ESCAPE;

                        curbits += 21;

                    } else {

                        int c = av_clip_uintp2(quant(t, Q), 13);

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

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

                    }

                } else {

                    di = t - vec[j]*IQ;

                }

                if (vec[j] != 0.0f)

                    curbits++;

                rd += di*di;

            }

        } else {

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

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

                rd += di*di;

            }

        }

        cost    += rd * lambda + curbits;

        resbits += curbits;

        if (cost >= uplim)

            return uplim;

        if (pb) {

            put_bits(pb, ff_aac_spectral_bits[cb-1][curidx], ff_aac_spectral_codes[cb-1][curidx]);

            if (BT_UNSIGNED)

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

                    if (ff_aac_codebook_vectors[cb-1][curidx*dim+j] != 0.0f)

                        put_bits(pb, 1, in[i+j] < 0.0f);

            if (BT_ESC) {

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

                    if (ff_aac_codebook_vectors[cb-1][curidx*2+j] == 64.0f) {

                        int coef = av_clip_uintp2(quant(fabsf(in[i+j]), Q), 13);

                        int len = av_log2(coef);



                        put_bits(pb, len - 4 + 1, (1 << (len - 4 + 1)) - 2);

                        put_bits(pb, len, coef & ((1 << len) - 1));

                    }

                }

            }

        }

    }



    if (bits)

        *bits = resbits;

    return cost;

}

                                int BT_PAIR, int BT_ESC)     const int range  = aac_cb_range[cb];     const int maxval = aac_cb_maxval[cb];     quantize_bands(s->qcoefs, in, scaled, size, Q34, !BT_UNSIGNED, maxval);         off = maxval;             curidx *= range;
static av_always_inline float FUNC_0(

                                struct AACEncContext *s,

                                PutBitContext *pb, const float *in,

                                const float *scaled, int size, int scale_idx,

                                int cb, const float lambda, const float uplim,

                                int *bits, int BT_ZERO, int BT_UNSIGNED,

                                int BT_PAIR, int BT_ESC)

{

    const int VAR_0 = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512;

    const float VAR_1   = ff_aac_pow2sf_tab [VAR_0];

    const float VAR_2 = ff_aac_pow34sf_tab[VAR_0];

    const float VAR_3  = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];

    const float VAR_4 = 165140.0f*VAR_3;

    int VAR_5, VAR_6;

    float VAR_7 = 0;

    const int VAR_8 = BT_PAIR ? 2 : 4;

    int VAR_9 = 0;

    const int VAR_10  = aac_cb_range[cb];

    const int VAR_11 = aac_cb_maxval[cb];

    int VAR_12;



    if (BT_ZERO) {

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

            VAR_7 += in[VAR_5]*in[VAR_5];

        if (bits)

            *bits = 0;

        return VAR_7 * lambda;

    }

    if (!scaled) {

        abs_pow34_v(s->scoefs, in, size);

        scaled = s->scoefs;

    }

    quantize_bands(s->qcoefs, in, scaled, size, VAR_2, !BT_UNSIGNED, VAR_11);

    if (BT_UNSIGNED) {

        VAR_12 = 0;

    } else {

        VAR_12 = VAR_11;

    }

    for (VAR_5 = 0; VAR_5 < size; VAR_5 += VAR_8) {

        const float *VAR_13;

        int *VAR_14 = s->qcoefs + VAR_5;

        int VAR_15 = 0;

        int VAR_16;

        float VAR_17 = 0.0f;

        for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) {

            VAR_15 *= VAR_10;

            VAR_15 += VAR_14[VAR_6] + VAR_12;

        }

        VAR_16 =  ff_aac_spectral_bits[cb-1][VAR_15];

        VAR_13     = &ff_aac_codebook_vectors[cb-1][VAR_15*VAR_8];

        if (BT_UNSIGNED) {

            for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) {

                float VAR_18 = fabsf(in[VAR_5+VAR_6]);

                float VAR_21;

                if (BT_ESC && VAR_13[VAR_6] == 64.0f) { 

                    if (VAR_18 >= VAR_4) {

                        VAR_21 = VAR_18 - VAR_4;

                        VAR_16 += 21;

                    } else {

                        int VAR_20 = av_clip_uintp2(quant(VAR_18, VAR_1), 13);

                        VAR_21 = VAR_18 - VAR_20*cbrtf(VAR_20)*VAR_3;

                        VAR_16 += av_log2(VAR_20)*2 - 4 + 1;

                    }

                } else {

                    VAR_21 = VAR_18 - VAR_13[VAR_6]*VAR_3;

                }

                if (VAR_13[VAR_6] != 0.0f)

                    VAR_16++;

                VAR_17 += VAR_21*VAR_21;

            }

        } else {

            for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) {

                float VAR_21 = in[VAR_5+VAR_6] - VAR_13[VAR_6]*VAR_3;

                VAR_17 += VAR_21*VAR_21;

            }

        }

        VAR_7    += VAR_17 * lambda + VAR_16;

        VAR_9 += VAR_16;

        if (VAR_7 >= uplim)

            return uplim;

        if (pb) {

            put_bits(pb, ff_aac_spectral_bits[cb-1][VAR_15], ff_aac_spectral_codes[cb-1][VAR_15]);

            if (BT_UNSIGNED)

                for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++)

                    if (ff_aac_codebook_vectors[cb-1][VAR_15*VAR_8+VAR_6] != 0.0f)

                        put_bits(pb, 1, in[VAR_5+VAR_6] < 0.0f);

            if (BT_ESC) {

                for (VAR_6 = 0; VAR_6 < 2; VAR_6++) {

                    if (ff_aac_codebook_vectors[cb-1][VAR_15*2+VAR_6] == 64.0f) {

                        int VAR_21 = av_clip_uintp2(quant(fabsf(in[VAR_5+VAR_6]), VAR_1), 13);

                        int VAR_22 = av_log2(VAR_21);



                        put_bits(pb, VAR_22 - 4 + 1, (1 << (VAR_22 - 4 + 1)) - 2);

                        put_bits(pb, VAR_22, VAR_21 & ((1 << VAR_22) - 1));

                    }

                }

            }

        }

    }



    if (bits)

        *bits = VAR_9;

    return VAR_7;

}

static av_always_inline float FUNC_0(
struct AACEncContext *s,
PutBitContext *pb, const float *in,
const float *scaled, int size, int scale_idx,
int cb, const float lambda, const float uplim,
int *bits, int BT_ZERO, int BT_UNSIGNED,
int BT_PAIR, int BT_ESC)
{ const int VAR_0 = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512; const float VAR_1   = ff_aac_pow2sf_tab [VAR_0]; const float VAR_2 = ff_aac_pow34sf_tab[VAR_0]; const float VAR_3  = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; const float VAR_4 = 165140.0f*VAR_3; int VAR_5, VAR_6; float VAR_7 = 0; const int VAR_8 = BT_PAIR ? 2 : 4; int VAR_9 = 0; const int VAR_10  = aac_cb_range[cb]; const int VAR_11 = aac_cb_maxval[cb]; int VAR_12; if (BT_ZERO) { for (VAR_5 = 0; VAR_5 < size; VAR_5++) VAR_7 += in[VAR_5]*in[VAR_5]; if (bits)
*bits = 0; return VAR_7 * lambda; } if (!scaled) { abs_pow34_v(s->scoefs, in, size); scaled = s->scoefs; } quantize_bands(s->qcoefs, in, scaled, size, VAR_2, !BT_UNSIGNED, VAR_11); if (BT_UNSIGNED) { VAR_12 = 0; } else { VAR_12 = VAR_11; } for (VAR_5 = 0; VAR_5 < size; VAR_5 += VAR_8) { const float *VAR_13; int *VAR_14 = s->qcoefs + VAR_5; int VAR_15 = 0; int VAR_16; float VAR_17 = 0.0f; for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) { VAR_15 *= VAR_10; VAR_15 += VAR_14[VAR_6] + VAR_12; } VAR_16 =  ff_aac_spectral_bits[cb-1][VAR_15]; VAR_13     = &ff_aac_codebook_vectors[cb-1][VAR_15*VAR_8]; if (BT_UNSIGNED) { for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) { float VAR_18 = fabsf(in[VAR_5+VAR_6]); float VAR_21; if (BT_ESC && VAR_13[VAR_6] == 64.0f) { if (VAR_18 >= VAR_4) { VAR_21 = VAR_18 - VAR_4; VAR_16 += 21; } else { int VAR_20 = av_clip_uintp2(quant(VAR_18, VAR_1), 13); VAR_21 = VAR_18 - VAR_20*cbrtf(VAR_20)*VAR_3; VAR_16 += av_log2(VAR_20)*2 - 4 + 1; } } else { VAR_21 = VAR_18 - VAR_13[VAR_6]*VAR_3; } if (VAR_13[VAR_6] != 0.0f)
VAR_16++; VAR_17 += VAR_21*VAR_21; } } else { for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) { float VAR_21 = in[VAR_5+VAR_6] - VAR_13[VAR_6]*VAR_3; VAR_17 += VAR_21*VAR_21; } } VAR_7    += VAR_17 * lambda + VAR_16; VAR_9 += VAR_16; if (VAR_7 >= uplim)
return uplim; if (pb) { put_bits(pb, ff_aac_spectral_bits[cb-1][VAR_15], ff_aac_spectral_codes[cb-1][VAR_15]); if (BT_UNSIGNED)
for (VAR_6 = 0; VAR_6 < VAR_8; VAR_6++) if (ff_aac_codebook_vectors[cb-1][VAR_15*VAR_8+VAR_6] != 0.0f)
put_bits(pb, 1, in[VAR_5+VAR_6] < 0.0f); if (BT_ESC) { for (VAR_6 = 0; VAR_6 < 2; VAR_6++) { if (ff_aac_codebook_vectors[cb-1][VAR_15*2+VAR_6] == 64.0f) { int VAR_21 = av_clip_uintp2(quant(fabsf(in[VAR_5+VAR_6]), VAR_1), 13); int VAR_22 = av_log2(VAR_21); put_bits(pb, VAR_22 - 4 + 1, (1 << (VAR_22 - 4 + 1)) - 2); put_bits(pb, VAR_22, VAR_21 & ((1 << VAR_22) - 1)); } } } } } if (bits)
*bits = VAR_9; return VAR_7; }