static av_cold int MPA_encode_init(AVCodecContext *avctx)

{

    MpegAudioContext *s = avctx->priv_data;

    int freq = avctx->sample_rate;

    int bitrate = avctx->bit_rate;

    int channels = avctx->channels;

    int i, v, table;

    float a;



    if (channels <= 0 || channels > 2){

        av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels);

        return AVERROR(EINVAL);

    }

    bitrate = bitrate / 1000;

    s->nb_channels = channels;

    avctx->frame_size = MPA_FRAME_SIZE;

    avctx->delay      = 512 - 32 + 1;



    /* encoding freq */

    s->lsf = 0;

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

        if (avpriv_mpa_freq_tab[i] == freq)

            break;

        if ((avpriv_mpa_freq_tab[i] / 2) == freq) {

            s->lsf = 1;

            break;

        }

    }

    if (i == 3){

        av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq);

        return AVERROR(EINVAL);

    }

    s->freq_index = i;



    /* encoding bitrate & frequency */

    for(i=0;i<15;i++) {

        if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate)

            break;

    }

    if (i == 15){

        av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate);

        return AVERROR(EINVAL);

    }

    s->bitrate_index = i;



    /* compute total header size & pad bit */



    a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0);

    s->frame_size = ((int)a) * 8;



    /* frame fractional size to compute padding */

    s->frame_frac = 0;

    s->frame_frac_incr = (int)((a - floor(a)) * 65536.0);



    /* select the right allocation table */

    table = ff_mpa_l2_select_table(bitrate, s->nb_channels, freq, s->lsf);



    /* number of used subbands */

    s->sblimit = ff_mpa_sblimit_table[table];

    s->alloc_table = ff_mpa_alloc_tables[table];



    av_dlog(avctx, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n",

            bitrate, freq, s->frame_size, table, s->frame_frac_incr);



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

        s->samples_offset[i] = 0;



    for(i=0;i<257;i++) {

        int v;

        v = ff_mpa_enwindow[i];

#if WFRAC_BITS != 16

        v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);

#endif

        s->filter_bank[i] = v;

        if ((i & 63) != 0)

            v = -v;

        if (i != 0)

            s->filter_bank[512 - i] = v;

    }



    for(i=0;i<64;i++) {

        v = (int)(exp2((3 - i) / 3.0) * (1 << 20));

        if (v <= 0)

            v = 1;

        s->scale_factor_table[i] = v;

#if USE_FLOATS

        s->scale_factor_inv_table[i] = exp2(-(3 - i) / 3.0) / (float)(1 << 20);

#else

#define P 15

        s->scale_factor_shift[i] = 21 - P - (i / 3);

        s->scale_factor_mult[i] = (1 << P) * exp2((i % 3) / 3.0);

#endif

    }

    for(i=0;i<128;i++) {

        v = i - 64;

        if (v <= -3)

            v = 0;

        else if (v < 0)

            v = 1;

        else if (v == 0)

            v = 2;

        else if (v < 3)

            v = 3;

        else

            v = 4;

        s->scale_diff_table[i] = v;

    }



    for(i=0;i<17;i++) {

        v = ff_mpa_quant_bits[i];

        if (v < 0)

            v = -v;

        else

            v = v * 3;

        s->total_quant_bits[i] = 12 * v;

    }



    return 0;

}

static av_cold int MPA_encode_init(AVCodecContext *avctx)

{

    MpegAudioContext *s = avctx->priv_data;

    int freq = avctx->sample_rate;

    int bitrate = avctx->bit_rate;

    int channels = avctx->channels;

    int i, v, table;

    float a;



    if (channels <= 0 || channels > 2){

        av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels);

        return AVERROR(EINVAL);

    }

    bitrate = bitrate / 1000;

    s->nb_channels = channels;

    avctx->frame_size = MPA_FRAME_SIZE;

    avctx->delay      = 512 - 32 + 1;



    

    s->lsf = 0;

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

        if (avpriv_mpa_freq_tab[i] == freq)

            break;

        if ((avpriv_mpa_freq_tab[i] / 2) == freq) {

            s->lsf = 1;

            break;

        }

    }

    if (i == 3){

        av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq);

        return AVERROR(EINVAL);

    }

    s->freq_index = i;



    

    for(i=0;i<15;i++) {

        if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate)

            break;

    }

    if (i == 15){

        av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate);

        return AVERROR(EINVAL);

    }

    s->bitrate_index = i;



    



    a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0);

    s->frame_size = ((int)a) * 8;



    

    s->frame_frac = 0;

    s->frame_frac_incr = (int)((a - floor(a)) * 65536.0);



    

    table = ff_mpa_l2_select_table(bitrate, s->nb_channels, freq, s->lsf);



    

    s->sblimit = ff_mpa_sblimit_table[table];

    s->alloc_table = ff_mpa_alloc_tables[table];



    av_dlog(avctx, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n",

            bitrate, freq, s->frame_size, table, s->frame_frac_incr);



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

        s->samples_offset[i] = 0;



    for(i=0;i<257;i++) {

        int v;

        v = ff_mpa_enwindow[i];

#if WFRAC_BITS != 16

        v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);

#endif

        s->filter_bank[i] = v;

        if ((i & 63) != 0)

            v = -v;

        if (i != 0)

            s->filter_bank[512 - i] = v;

    }



    for(i=0;i<64;i++) {

        v = (int)(exp2((3 - i) / 3.0) * (1 << 20));

        if (v <= 0)

            v = 1;

        s->scale_factor_table[i] = v;

#if USE_FLOATS

        s->scale_factor_inv_table[i] = exp2(-(3 - i) / 3.0) / (float)(1 << 20);

#else

#define P 15

        s->scale_factor_shift[i] = 21 - P - (i / 3);

        s->scale_factor_mult[i] = (1 << P) * exp2((i % 3) / 3.0);

#endif

    }

    for(i=0;i<128;i++) {

        v = i - 64;

        if (v <= -3)

            v = 0;

        else if (v < 0)

            v = 1;

        else if (v == 0)

            v = 2;

        else if (v < 3)

            v = 3;

        else

            v = 4;

        s->scale_diff_table[i] = v;

    }



    for(i=0;i<17;i++) {

        v = ff_mpa_quant_bits[i];

        if (v < 0)

            v = -v;

        else

            v = v * 3;

        s->total_quant_bits[i] = 12 * v;

    }



    return 0;

}

    for(i=0;i<15;i++) {
static av_cold int FUNC_0(AVCodecContext *avctx)

{

    MpegAudioContext *s = avctx->priv_data;

    int VAR_0 = avctx->sample_rate;

    int VAR_1 = avctx->bit_rate;

    int VAR_2 = avctx->VAR_2;

    int VAR_3, VAR_7, VAR_5;

    float VAR_6;



    if (VAR_2 <= 0 || VAR_2 > 2){

        av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", VAR_2);

        return AVERROR(EINVAL);

    }

    VAR_1 = VAR_1 / 1000;

    s->nb_channels = VAR_2;

    avctx->frame_size = MPA_FRAME_SIZE;

    avctx->delay      = 512 - 32 + 1;



    

    s->lsf = 0;

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

        if (avpriv_mpa_freq_tab[VAR_3] == VAR_0)

            break;

        if ((avpriv_mpa_freq_tab[VAR_3] / 2) == VAR_0) {

            s->lsf = 1;

            break;

        }

    }

    if (VAR_3 == 3){

        av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", VAR_0);

        return AVERROR(EINVAL);

    }

    s->freq_index = VAR_3;



    

    for(VAR_3=0;VAR_3<15;VAR_3++) {

        if (avpriv_mpa_bitrate_tab[s->lsf][1][VAR_3] == VAR_1)

            break;

    }

    if (VAR_3 == 15){

        av_log(avctx, AV_LOG_ERROR, "VAR_1 %d is not allowed in mp2\n", VAR_1);

        return AVERROR(EINVAL);

    }

    s->bitrate_index = VAR_3;



    



    VAR_6 = (float)(VAR_1 * 1000 * MPA_FRAME_SIZE) / (VAR_0 * 8.0);

    s->frame_size = ((int)VAR_6) * 8;



    

    s->frame_frac = 0;

    s->frame_frac_incr = (int)((VAR_6 - floor(VAR_6)) * 65536.0);



    

    VAR_5 = ff_mpa_l2_select_table(VAR_1, s->nb_channels, VAR_0, s->lsf);



    

    s->sblimit = ff_mpa_sblimit_table[VAR_5];

    s->alloc_table = ff_mpa_alloc_tables[VAR_5];



    av_dlog(avctx, "%d kb/s, %d Hz, frame_size=%d bits, VAR_5=%d, padincr=%x\n",

            VAR_1, VAR_0, s->frame_size, VAR_5, s->frame_frac_incr);



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

        s->samples_offset[VAR_3] = 0;



    for(VAR_3=0;VAR_3<257;VAR_3++) {

        int VAR_7;

        VAR_7 = ff_mpa_enwindow[VAR_3];

#if WFRAC_BITS != 16

        VAR_7 = (VAR_7 + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);

#endif

        s->filter_bank[VAR_3] = VAR_7;

        if ((VAR_3 & 63) != 0)

            VAR_7 = -VAR_7;

        if (VAR_3 != 0)

            s->filter_bank[512 - VAR_3] = VAR_7;

    }



    for(VAR_3=0;VAR_3<64;VAR_3++) {

        VAR_7 = (int)(exp2((3 - VAR_3) / 3.0) * (1 << 20));

        if (VAR_7 <= 0)

            VAR_7 = 1;

        s->scale_factor_table[VAR_3] = VAR_7;

#if USE_FLOATS

        s->scale_factor_inv_table[VAR_3] = exp2(-(3 - VAR_3) / 3.0) / (float)(1 << 20);

#else

#define P 15

        s->scale_factor_shift[VAR_3] = 21 - P - (VAR_3 / 3);

        s->scale_factor_mult[VAR_3] = (1 << P) * exp2((VAR_3 % 3) / 3.0);

#endif

    }

    for(VAR_3=0;VAR_3<128;VAR_3++) {

        VAR_7 = VAR_3 - 64;

        if (VAR_7 <= -3)

            VAR_7 = 0;

        else if (VAR_7 < 0)

            VAR_7 = 1;

        else if (VAR_7 == 0)

            VAR_7 = 2;

        else if (VAR_7 < 3)

            VAR_7 = 3;

        else

            VAR_7 = 4;

        s->scale_diff_table[VAR_3] = VAR_7;

    }



    for(VAR_3=0;VAR_3<17;VAR_3++) {

        VAR_7 = ff_mpa_quant_bits[VAR_3];

        if (VAR_7 < 0)

            VAR_7 = -VAR_7;

        else

            VAR_7 = VAR_7 * 3;

        s->total_quant_bits[VAR_3] = 12 * VAR_7;

    }



    return 0;

}

static av_cold int FUNC_0(AVCodecContext *avctx)
{ MpegAudioContext *s = avctx->priv_data; int VAR_0 = avctx->sample_rate; int VAR_1 = avctx->bit_rate; int VAR_2 = avctx->VAR_2; int VAR_3, VAR_7, VAR_5; float VAR_6; if (VAR_2 <= 0 || VAR_2 > 2){ av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", VAR_2); return AVERROR(EINVAL); } VAR_1 = VAR_1 / 1000; s->nb_channels = VAR_2; avctx->frame_size = MPA_FRAME_SIZE; avctx->delay      = 512 - 32 + 1; s->lsf = 0; for(VAR_3=0;VAR_3<3;VAR_3++) { if (avpriv_mpa_freq_tab[VAR_3] == VAR_0)
break; if ((avpriv_mpa_freq_tab[VAR_3] / 2) == VAR_0) { s->lsf = 1; break; } } if (VAR_3 == 3){ av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", VAR_0); return AVERROR(EINVAL); } s->freq_index = VAR_3; for(VAR_3=0;VAR_3<15;VAR_3++) { if (avpriv_mpa_bitrate_tab[s->lsf][1][VAR_3] == VAR_1)
break; } if (VAR_3 == 15){ av_log(avctx, AV_LOG_ERROR, "VAR_1 %d is not allowed in mp2\n", VAR_1); return AVERROR(EINVAL); } s->bitrate_index = VAR_3; VAR_6 = (float)(VAR_1 * 1000 * MPA_FRAME_SIZE) / (VAR_0 * 8.0); s->frame_size = ((int)VAR_6) * 8; s->frame_frac = 0; s->frame_frac_incr = (int)((VAR_6 - floor(VAR_6)) * 65536.0); VAR_5 = ff_mpa_l2_select_table(VAR_1, s->nb_channels, VAR_0, s->lsf); s->sblimit = ff_mpa_sblimit_table[VAR_5]; s->alloc_table = ff_mpa_alloc_tables[VAR_5]; av_dlog(avctx, "%d kb/s, %d Hz, frame_size=%d bits, VAR_5=%d, padincr=%x\n",
VAR_1, VAR_0, s->frame_size, VAR_5, s->frame_frac_incr); for(VAR_3=0;VAR_3<s->nb_channels;VAR_3++) s->samples_offset[VAR_3] = 0; for(VAR_3=0;VAR_3<257;VAR_3++) { int VAR_7; VAR_7 = ff_mpa_enwindow[VAR_3]; #if WFRAC_BITS != 16
VAR_7 = (VAR_7 + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); #endif
s->filter_bank[VAR_3] = VAR_7; if ((VAR_3 & 63) != 0)
VAR_7 = -VAR_7; if (VAR_3 != 0)
s->filter_bank[512 - VAR_3] = VAR_7; } for(VAR_3=0;VAR_3<64;VAR_3++) { VAR_7 = (int)(exp2((3 - VAR_3) / 3.0) * (1 << 20)); if (VAR_7 <= 0)
VAR_7 = 1; s->scale_factor_table[VAR_3] = VAR_7; #if USE_FLOATS
s->scale_factor_inv_table[VAR_3] = exp2(-(3 - VAR_3) / 3.0) / (float)(1 << 20); #else
#define P 15
s->scale_factor_shift[VAR_3] = 21 - P - (VAR_3 / 3); s->scale_factor_mult[VAR_3] = (1 << P) * exp2((VAR_3 % 3) / 3.0); #endif
} for(VAR_3=0;VAR_3<128;VAR_3++) { VAR_7 = VAR_3 - 64; if (VAR_7 <= -3)
VAR_7 = 0; else if (VAR_7 < 0)
VAR_7 = 1; else if (VAR_7 == 0)
VAR_7 = 2; else if (VAR_7 < 3)
VAR_7 = 3; else
VAR_7 = 4; s->scale_diff_table[VAR_3] = VAR_7; } for(VAR_3=0;VAR_3<17;VAR_3++) { VAR_7 = ff_mpa_quant_bits[VAR_3]; if (VAR_7 < 0)
VAR_7 = -VAR_7; else
VAR_7 = VAR_7 * 3; s->total_quant_bits[VAR_3] = 12 * VAR_7; } return 0; }