static void encode_frame(MpegAudioContext *s,

                         unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],

                         int padding)

{

    int i, j, k, l, bit_alloc_bits, b, ch;

    unsigned char *sf;

    int q[3];

    PutBitContext *p = &s->pb;



    /* header */



    put_bits(p, 12, 0xfff);

    put_bits(p, 1, 1 - s->lsf); /* 1 = mpeg1 ID, 0 = mpeg2 lsf ID */

    put_bits(p, 2, 4-2);  /* layer 2 */

    put_bits(p, 1, 1); /* no error protection */

    put_bits(p, 4, s->bitrate_index);

    put_bits(p, 2, s->freq_index);

    put_bits(p, 1, s->do_padding); /* use padding */

    put_bits(p, 1, 0);             /* private_bit */

    put_bits(p, 2, s->nb_channels == 2 ? MPA_STEREO : MPA_MONO);

    put_bits(p, 2, 0); /* mode_ext */

    put_bits(p, 1, 0); /* no copyright */

    put_bits(p, 1, 1); /* original */

    put_bits(p, 2, 0); /* no emphasis */



    /* bit allocation */

    j = 0;

    for(i=0;i<s->sblimit;i++) {

        bit_alloc_bits = s->alloc_table[j];

        for(ch=0;ch<s->nb_channels;ch++) {

            put_bits(p, bit_alloc_bits, bit_alloc[ch][i]);

        }

        j += 1 << bit_alloc_bits;

    }



    /* scale codes */

    for(i=0;i<s->sblimit;i++) {

        for(ch=0;ch<s->nb_channels;ch++) {

            if (bit_alloc[ch][i])

                put_bits(p, 2, s->scale_code[ch][i]);

        }

    }



    /* scale factors */

    for(i=0;i<s->sblimit;i++) {

        for(ch=0;ch<s->nb_channels;ch++) {

            if (bit_alloc[ch][i]) {

                sf = &s->scale_factors[ch][i][0];

                switch(s->scale_code[ch][i]) {

                case 0:

                    put_bits(p, 6, sf[0]);

                    put_bits(p, 6, sf[1]);

                    put_bits(p, 6, sf[2]);

                    break;

                case 3:

                case 1:

                    put_bits(p, 6, sf[0]);

                    put_bits(p, 6, sf[2]);

                    break;

                case 2:

                    put_bits(p, 6, sf[0]);

                    break;

                }

            }

        }

    }



    /* quantization & write sub band samples */



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

        for(l=0;l<12;l+=3) {

            j = 0;

            for(i=0;i<s->sblimit;i++) {

                bit_alloc_bits = s->alloc_table[j];

                for(ch=0;ch<s->nb_channels;ch++) {

                    b = bit_alloc[ch][i];

                    if (b) {

                        int qindex, steps, m, sample, bits;

                        /* we encode 3 sub band samples of the same sub band at a time */

                        qindex = s->alloc_table[j+b];

                        steps = ff_mpa_quant_steps[qindex];

                        for(m=0;m<3;m++) {

                            sample = s->sb_samples[ch][k][l + m][i];

                            /* divide by scale factor */

#if USE_FLOATS

                            {

                                float a;

                                a = (float)sample * s->scale_factor_inv_table[s->scale_factors[ch][i][k]];

                                q[m] = (int)((a + 1.0) * steps * 0.5);

                            }

#else

                            {

                                int q1, e, shift, mult;

                                e = s->scale_factors[ch][i][k];

                                shift = s->scale_factor_shift[e];

                                mult = s->scale_factor_mult[e];



                                /* normalize to P bits */

                                if (shift < 0)

                                    q1 = sample << (-shift);

                                else

                                    q1 = sample >> shift;

                                q1 = (q1 * mult) >> P;

                                q1 += 1 << P;

                                if (q1 < 0)

                                    q1 = 0;

                                q[m] = (unsigned)(q1 * steps) >> (P + 1);

                            }

#endif

                            if (q[m] >= steps)

                                q[m] = steps - 1;

                            av_assert2(q[m] >= 0 && q[m] < steps);

                        }

                        bits = ff_mpa_quant_bits[qindex];

                        if (bits < 0) {

                            /* group the 3 values to save bits */

                            put_bits(p, -bits,

                                     q[0] + steps * (q[1] + steps * q[2]));

                        } else {

                            put_bits(p, bits, q[0]);

                            put_bits(p, bits, q[1]);

                            put_bits(p, bits, q[2]);

                        }

                    }

                }

                /* next subband in alloc table */

                j += 1 << bit_alloc_bits;

            }

        }

    }



    /* padding */

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

        put_bits(p, 1, 0);



    /* flush */

    flush_put_bits(p);

}

static void encode_frame(MpegAudioContext *s,

                         unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],

                         int padding)

{

    int i, j, k, l, bit_alloc_bits, b, ch;

    unsigned char *sf;

    int q[3];

    PutBitContext *p = &s->pb;



    



    put_bits(p, 12, 0xfff);

    put_bits(p, 1, 1 - s->lsf); 

    put_bits(p, 2, 4-2);  

    put_bits(p, 1, 1); 

    put_bits(p, 4, s->bitrate_index);

    put_bits(p, 2, s->freq_index);

    put_bits(p, 1, s->do_padding); 

    put_bits(p, 1, 0);             

    put_bits(p, 2, s->nb_channels == 2 ? MPA_STEREO : MPA_MONO);

    put_bits(p, 2, 0); 

    put_bits(p, 1, 0); 

    put_bits(p, 1, 1); 

    put_bits(p, 2, 0); 



    

    j = 0;

    for(i=0;i<s->sblimit;i++) {

        bit_alloc_bits = s->alloc_table[j];

        for(ch=0;ch<s->nb_channels;ch++) {

            put_bits(p, bit_alloc_bits, bit_alloc[ch][i]);

        }

        j += 1 << bit_alloc_bits;

    }



    

    for(i=0;i<s->sblimit;i++) {

        for(ch=0;ch<s->nb_channels;ch++) {

            if (bit_alloc[ch][i])

                put_bits(p, 2, s->scale_code[ch][i]);

        }

    }



    

    for(i=0;i<s->sblimit;i++) {

        for(ch=0;ch<s->nb_channels;ch++) {

            if (bit_alloc[ch][i]) {

                sf = &s->scale_factors[ch][i][0];

                switch(s->scale_code[ch][i]) {

                case 0:

                    put_bits(p, 6, sf[0]);

                    put_bits(p, 6, sf[1]);

                    put_bits(p, 6, sf[2]);

                    break;

                case 3:

                case 1:

                    put_bits(p, 6, sf[0]);

                    put_bits(p, 6, sf[2]);

                    break;

                case 2:

                    put_bits(p, 6, sf[0]);

                    break;

                }

            }

        }

    }



    



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

        for(l=0;l<12;l+=3) {

            j = 0;

            for(i=0;i<s->sblimit;i++) {

                bit_alloc_bits = s->alloc_table[j];

                for(ch=0;ch<s->nb_channels;ch++) {

                    b = bit_alloc[ch][i];

                    if (b) {

                        int qindex, steps, m, sample, bits;

                        

                        qindex = s->alloc_table[j+b];

                        steps = ff_mpa_quant_steps[qindex];

                        for(m=0;m<3;m++) {

                            sample = s->sb_samples[ch][k][l + m][i];

                            

#if USE_FLOATS

                            {

                                float a;

                                a = (float)sample * s->scale_factor_inv_table[s->scale_factors[ch][i][k]];

                                q[m] = (int)((a + 1.0) * steps * 0.5);

                            }

#else

                            {

                                int q1, e, shift, mult;

                                e = s->scale_factors[ch][i][k];

                                shift = s->scale_factor_shift[e];

                                mult = s->scale_factor_mult[e];



                                

                                if (shift < 0)

                                    q1 = sample << (-shift);

                                else

                                    q1 = sample >> shift;

                                q1 = (q1 * mult) >> P;

                                q1 += 1 << P;

                                if (q1 < 0)

                                    q1 = 0;

                                q[m] = (unsigned)(q1 * steps) >> (P + 1);

                            }

#endif

                            if (q[m] >= steps)

                                q[m] = steps - 1;

                            av_assert2(q[m] >= 0 && q[m] < steps);

                        }

                        bits = ff_mpa_quant_bits[qindex];

                        if (bits < 0) {

                            

                            put_bits(p, -bits,

                                     q[0] + steps * (q[1] + steps * q[2]));

                        } else {

                            put_bits(p, bits, q[0]);

                            put_bits(p, bits, q[1]);

                            put_bits(p, bits, q[2]);

                        }

                    }

                }

                

                j += 1 << bit_alloc_bits;

            }

        }

    }



    

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

        put_bits(p, 1, 0);



    

    flush_put_bits(p);

}

                                q[m] = (unsigned)(q1 * steps) >> (P + 1);
static void FUNC_0(MpegAudioContext *VAR_0,

                         unsigned char VAR_1[MPA_MAX_CHANNELS][SBLIMIT],

                         int VAR_2)

{

    int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9;

    unsigned char *VAR_10;

    int VAR_11[3];

    PutBitContext *p = &VAR_0->pb;



    



    put_bits(p, 12, 0xfff);

    put_bits(p, 1, 1 - VAR_0->lsf); 

    put_bits(p, 2, 4-2);  

    put_bits(p, 1, 1); 

    put_bits(p, 4, VAR_0->bitrate_index);

    put_bits(p, 2, VAR_0->freq_index);

    put_bits(p, 1, VAR_0->do_padding); 

    put_bits(p, 1, 0);             

    put_bits(p, 2, VAR_0->nb_channels == 2 ? MPA_STEREO : MPA_MONO);

    put_bits(p, 2, 0); 

    put_bits(p, 1, 0); 

    put_bits(p, 1, 1); 

    put_bits(p, 2, 0); 



    

    VAR_4 = 0;

    for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) {

        VAR_7 = VAR_0->alloc_table[VAR_4];

        for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) {

            put_bits(p, VAR_7, VAR_1[VAR_9][VAR_3]);

        }

        VAR_4 += 1 << VAR_7;

    }



    

    for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) {

        for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) {

            if (VAR_1[VAR_9][VAR_3])

                put_bits(p, 2, VAR_0->scale_code[VAR_9][VAR_3]);

        }

    }



    

    for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) {

        for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) {

            if (VAR_1[VAR_9][VAR_3]) {

                VAR_10 = &VAR_0->scale_factors[VAR_9][VAR_3][0];

                switch(VAR_0->scale_code[VAR_9][VAR_3]) {

                case 0:

                    put_bits(p, 6, VAR_10[0]);

                    put_bits(p, 6, VAR_10[1]);

                    put_bits(p, 6, VAR_10[2]);

                    break;

                case 3:

                case 1:

                    put_bits(p, 6, VAR_10[0]);

                    put_bits(p, 6, VAR_10[2]);

                    break;

                case 2:

                    put_bits(p, 6, VAR_10[0]);

                    break;

                }

            }

        }

    }



    



    for(VAR_5=0;VAR_5<3;VAR_5++) {

        for(VAR_6=0;VAR_6<12;VAR_6+=3) {

            VAR_4 = 0;

            for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) {

                VAR_7 = VAR_0->alloc_table[VAR_4];

                for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) {

                    VAR_8 = VAR_1[VAR_9][VAR_3];

                    if (VAR_8) {

                        int qindex, steps, m, sample, bits;

                        

                        qindex = VAR_0->alloc_table[VAR_4+VAR_8];

                        steps = ff_mpa_quant_steps[qindex];

                        for(m=0;m<3;m++) {

                            sample = VAR_0->sb_samples[VAR_9][VAR_5][VAR_6 + m][VAR_3];

                            

#if USE_FLOATS

                            {

                                float a;

                                a = (float)sample * VAR_0->scale_factor_inv_table[VAR_0->scale_factors[VAR_9][VAR_3][VAR_5]];

                                VAR_11[m] = (int)((a + 1.0) * steps * 0.5);

                            }

#else

                            {

                                int q1, e, shift, mult;

                                e = VAR_0->scale_factors[VAR_9][VAR_3][VAR_5];

                                shift = VAR_0->scale_factor_shift[e];

                                mult = VAR_0->scale_factor_mult[e];



                                

                                if (shift < 0)

                                    q1 = sample << (-shift);

                                else

                                    q1 = sample >> shift;

                                q1 = (q1 * mult) >> P;

                                q1 += 1 << P;

                                if (q1 < 0)

                                    q1 = 0;

                                VAR_11[m] = (unsigned)(q1 * steps) >> (P + 1);

                            }

#endif

                            if (VAR_11[m] >= steps)

                                VAR_11[m] = steps - 1;

                            av_assert2(VAR_11[m] >= 0 && VAR_11[m] < steps);

                        }

                        bits = ff_mpa_quant_bits[qindex];

                        if (bits < 0) {

                            

                            put_bits(p, -bits,

                                     VAR_11[0] + steps * (VAR_11[1] + steps * VAR_11[2]));

                        } else {

                            put_bits(p, bits, VAR_11[0]);

                            put_bits(p, bits, VAR_11[1]);

                            put_bits(p, bits, VAR_11[2]);

                        }

                    }

                }

                

                VAR_4 += 1 << VAR_7;

            }

        }

    }



    

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

        put_bits(p, 1, 0);



    

    flush_put_bits(p);

}

static void FUNC_0(MpegAudioContext *VAR_0,
unsigned char VAR_1[MPA_MAX_CHANNELS][SBLIMIT],
int VAR_2)
{ int VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9; unsigned char *VAR_10; int VAR_11[3]; PutBitContext *p = &VAR_0->pb; put_bits(p, 12, 0xfff); put_bits(p, 1, 1 - VAR_0->lsf); put_bits(p, 2, 4-2); put_bits(p, 1, 1); put_bits(p, 4, VAR_0->bitrate_index); put_bits(p, 2, VAR_0->freq_index); put_bits(p, 1, VAR_0->do_padding); put_bits(p, 1, 0); put_bits(p, 2, VAR_0->nb_channels == 2 ? MPA_STEREO : MPA_MONO); put_bits(p, 2, 0); put_bits(p, 1, 0); put_bits(p, 1, 1); put_bits(p, 2, 0); VAR_4 = 0; for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) { VAR_7 = VAR_0->alloc_table[VAR_4]; for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) { put_bits(p, VAR_7, VAR_1[VAR_9][VAR_3]); } VAR_4 += 1 << VAR_7; } for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) { for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) { if (VAR_1[VAR_9][VAR_3])
put_bits(p, 2, VAR_0->scale_code[VAR_9][VAR_3]); } } for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) { for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) { if (VAR_1[VAR_9][VAR_3]) { VAR_10 = &VAR_0->scale_factors[VAR_9][VAR_3][0]; switch(VAR_0->scale_code[VAR_9][VAR_3]) { case 0:
put_bits(p, 6, VAR_10[0]); put_bits(p, 6, VAR_10[1]); put_bits(p, 6, VAR_10[2]); break; case 3:
case 1:
put_bits(p, 6, VAR_10[0]); put_bits(p, 6, VAR_10[2]); break; case 2:
put_bits(p, 6, VAR_10[0]); break; } } } } for(VAR_5=0;VAR_5<3;VAR_5++) { for(VAR_6=0;VAR_6<12;VAR_6+=3) { VAR_4 = 0; for(VAR_3=0;VAR_3<VAR_0->sblimit;VAR_3++) { VAR_7 = VAR_0->alloc_table[VAR_4]; for(VAR_9=0;VAR_9<VAR_0->nb_channels;VAR_9++) { VAR_8 = VAR_1[VAR_9][VAR_3]; if (VAR_8) { int qindex, steps, m, sample, bits; qindex = VAR_0->alloc_table[VAR_4+VAR_8]; steps = ff_mpa_quant_steps[qindex]; for(m=0;m<3;m++) { sample = VAR_0->sb_samples[VAR_9][VAR_5][VAR_6 + m][VAR_3]; #if USE_FLOATS
{ float a; a = (float)sample * VAR_0->scale_factor_inv_table[VAR_0->scale_factors[VAR_9][VAR_3][VAR_5]]; VAR_11[m] = (int)((a + 1.0) * steps * 0.5); } #else
{ int q1, e, shift, mult; e = VAR_0->scale_factors[VAR_9][VAR_3][VAR_5]; shift = VAR_0->scale_factor_shift[e]; mult = VAR_0->scale_factor_mult[e]; if (shift < 0)
q1 = sample << (-shift); else
q1 = sample >> shift; q1 = (q1 * mult) >> P; q1 += 1 << P; if (q1 < 0)
q1 = 0; VAR_11[m] = (unsigned)(q1 * steps) >> (P + 1); } #endif
if (VAR_11[m] >= steps)
VAR_11[m] = steps - 1; av_assert2(VAR_11[m] >= 0 && VAR_11[m] < steps); } bits = ff_mpa_quant_bits[qindex]; if (bits < 0) { put_bits(p, -bits,
VAR_11[0] + steps * (VAR_11[1] + steps * VAR_11[2])); } else { put_bits(p, bits, VAR_11[0]); put_bits(p, bits, VAR_11[1]); put_bits(p, bits, VAR_11[2]); } } } VAR_4 += 1 << VAR_7; } } } for(VAR_3=0;VAR_3<VAR_2;VAR_3++) put_bits(p, 1, 0); flush_put_bits(p); }