static av_cold int ac3_encode_init(AVCodecContext *avctx)

{

    int freq = avctx->sample_rate;

    int bitrate = avctx->bit_rate;

    AC3EncodeContext *s = avctx->priv_data;

    int i, j, ch;

    int bw_code;



    avctx->frame_size = AC3_FRAME_SIZE;



    ac3_common_init();



    if (!avctx->channel_layout) {

        av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "

                                      "encoder will guess the layout, but it "

                                      "might be incorrect.\n");

    }

    if (set_channel_info(s, avctx->channels, &avctx->channel_layout)) {

        av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

        return -1;

    }



    /* frequency */

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

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

            if ((ff_ac3_sample_rate_tab[j] >> i) == freq)

                goto found;

    }

    return -1;

 found:

    s->sample_rate        = freq;

    s->bit_alloc.sr_shift = i;

    s->bit_alloc.sr_code  = j;

    s->bitstream_id       = 8 + s->bit_alloc.sr_shift;

    s->bitstream_mode     = 0; /* complete main audio service */



    /* bitrate & frame size */

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

        if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == bitrate)

            break;

    }

    if (i == 19)

        return -1;

    s->bit_rate        = bitrate;

    s->frame_size_code = i << 1;

    s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];

    s->bits_written    = 0;

    s->samples_written = 0;

    s->frame_size      = s->frame_size_min;



    /* set bandwidth */

    if (avctx->cutoff) {

        /* calculate bandwidth based on user-specified cutoff frequency */

        int cutoff     = av_clip(avctx->cutoff, 1, s->sample_rate >> 1);

        int fbw_coeffs = cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;

        bw_code        = av_clip((fbw_coeffs - 73) / 3, 0, 60);

    } else {

        /* use default bandwidth setting */

        /* XXX: should compute the bandwidth according to the frame

           size, so that we avoid annoying high frequency artifacts */

        bw_code = 50;

    }

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

        /* bandwidth for each channel */

        s->bandwidth_code[ch] = bw_code;

        s->nb_coefs[ch]       = bw_code * 3 + 73;

    }

    if (s->lfe_on)

        s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */



    /* initial snr offset */

    s->coarse_snr_offset = 40;



    mdct_init(9);



    avctx->coded_frame= avcodec_alloc_frame();

    avctx->coded_frame->key_frame= 1;



    return 0;

}

static av_cold int ac3_encode_init(AVCodecContext *avctx)

{

    int freq = avctx->sample_rate;

    int bitrate = avctx->bit_rate;

    AC3EncodeContext *s = avctx->priv_data;

    int i, j, ch;

    int bw_code;



    avctx->frame_size = AC3_FRAME_SIZE;



    ac3_common_init();



    if (!avctx->channel_layout) {

        av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "

                                      "encoder will guess the layout, but it "

                                      "might be incorrect.\n");

    }

    if (set_channel_info(s, avctx->channels, &avctx->channel_layout)) {

        av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

        return -1;

    }



    

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

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

            if ((ff_ac3_sample_rate_tab[j] >> i) == freq)

                goto found;

    }

    return -1;

 found:

    s->sample_rate        = freq;

    s->bit_alloc.sr_shift = i;

    s->bit_alloc.sr_code  = j;

    s->bitstream_id       = 8 + s->bit_alloc.sr_shift;

    s->bitstream_mode     = 0; 



    

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

        if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == bitrate)

            break;

    }

    if (i == 19)

        return -1;

    s->bit_rate        = bitrate;

    s->frame_size_code = i << 1;

    s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];

    s->bits_written    = 0;

    s->samples_written = 0;

    s->frame_size      = s->frame_size_min;



    

    if (avctx->cutoff) {

        

        int cutoff     = av_clip(avctx->cutoff, 1, s->sample_rate >> 1);

        int fbw_coeffs = cutoff * 2 * AC3_MAX_COEFS / s->sample_rate;

        bw_code        = av_clip((fbw_coeffs - 73) / 3, 0, 60);

    } else {

        

        



        bw_code = 50;

    }

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

        

        s->bandwidth_code[ch] = bw_code;

        s->nb_coefs[ch]       = bw_code * 3 + 73;

    }

    if (s->lfe_on)

        s->nb_coefs[s->lfe_channel] = 7; 



    

    s->coarse_snr_offset = 40;



    mdct_init(9);



    avctx->coded_frame= avcodec_alloc_frame();

    avctx->coded_frame->key_frame= 1;



    return 0;

}

static av_cold int FUNC_0(AVCodecContext *avctx)

{

    int VAR_0 = avctx->sample_rate;

    int VAR_1 = avctx->bit_rate;

    AC3EncodeContext *s = avctx->priv_data;

    int VAR_2, VAR_3, VAR_4;

    int VAR_5;



    avctx->frame_size = AC3_FRAME_SIZE;



    ac3_common_init();



    if (!avctx->channel_layout) {

        av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "

                                      "encoder will guess the layout, but it "

                                      "might be incorrect.\n");

    }

    if (set_channel_info(s, avctx->channels, &avctx->channel_layout)) {

        av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");

        return -1;

    }



    

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

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

            if ((ff_ac3_sample_rate_tab[VAR_3] >> VAR_2) == VAR_0)

                goto found;

    }

    return -1;

 found:

    s->sample_rate        = VAR_0;

    s->bit_alloc.sr_shift = VAR_2;

    s->bit_alloc.sr_code  = VAR_3;

    s->bitstream_id       = 8 + s->bit_alloc.sr_shift;

    s->bitstream_mode     = 0; 



    

    for (VAR_2 = 0; VAR_2 < 19; VAR_2++) {

        if ((ff_ac3_bitrate_tab[VAR_2] >> s->bit_alloc.sr_shift)*1000 == VAR_1)

            break;

    }

    if (VAR_2 == 19)

        return -1;

    s->bit_rate        = VAR_1;

    s->frame_size_code = VAR_2 << 1;

    s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code];

    s->bits_written    = 0;

    s->samples_written = 0;

    s->frame_size      = s->frame_size_min;



    

    if (avctx->VAR_6) {

        

        int VAR_6     = av_clip(avctx->VAR_6, 1, s->sample_rate >> 1);

        int VAR_7 = VAR_6 * 2 * AC3_MAX_COEFS / s->sample_rate;

        VAR_5        = av_clip((VAR_7 - 73) / 3, 0, 60);

    } else {

        

        



        VAR_5 = 50;

    }

    for (VAR_4 = 0; VAR_4 < s->fbw_channels; VAR_4++) {

        

        s->bandwidth_code[VAR_4] = VAR_5;

        s->nb_coefs[VAR_4]       = VAR_5 * 3 + 73;

    }

    if (s->lfe_on)

        s->nb_coefs[s->lfe_channel] = 7; 



    

    s->coarse_snr_offset = 40;



    mdct_init(9);



    avctx->coded_frame= avcodec_alloc_frame();

    avctx->coded_frame->key_frame= 1;



    return 0;

}

static av_cold int FUNC_0(AVCodecContext *avctx)
{ int VAR_0 = avctx->sample_rate; int VAR_1 = avctx->bit_rate; AC3EncodeContext *s = avctx->priv_data; int VAR_2, VAR_3, VAR_4; int VAR_5; avctx->frame_size = AC3_FRAME_SIZE; ac3_common_init(); if (!avctx->channel_layout) { av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
"encoder will guess the layout, but it "
"might be incorrect.\n"); } if (set_channel_info(s, avctx->channels, &avctx->channel_layout)) { av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n"); return -1; } for (VAR_2 = 0; VAR_2 < 3; VAR_2++) { for (VAR_3 = 0; VAR_3 < 3; VAR_3++) if ((ff_ac3_sample_rate_tab[VAR_3] >> VAR_2) == VAR_0)
goto found; } return -1; found:
s->sample_rate        = VAR_0; s->bit_alloc.sr_shift = VAR_2; s->bit_alloc.sr_code  = VAR_3; s->bitstream_id       = 8 + s->bit_alloc.sr_shift; s->bitstream_mode     = 0; for (VAR_2 = 0; VAR_2 < 19; VAR_2++) { if ((ff_ac3_bitrate_tab[VAR_2] >> s->bit_alloc.sr_shift)*1000 == VAR_1)
break; } if (VAR_2 == 19)
return -1; s->bit_rate        = VAR_1; s->frame_size_code = VAR_2 << 1; s->frame_size_min  = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; s->bits_written    = 0; s->samples_written = 0; s->frame_size      = s->frame_size_min; if (avctx->VAR_6) { int VAR_6     = av_clip(avctx->VAR_6, 1, s->sample_rate >> 1); int VAR_7 = VAR_6 * 2 * AC3_MAX_COEFS / s->sample_rate; VAR_5        = av_clip((VAR_7 - 73) / 3, 0, 60); } else { VAR_5 = 50; } for (VAR_4 = 0; VAR_4 < s->fbw_channels; VAR_4++) { s->bandwidth_code[VAR_4] = VAR_5; s->nb_coefs[VAR_4]       = VAR_5 * 3 + 73; } if (s->lfe_on)
s->nb_coefs[s->lfe_channel] = 7; s->coarse_snr_offset = 40; mdct_init(9); avctx->coded_frame= avcodec_alloc_frame(); avctx->coded_frame->key_frame= 1; return 0; }