static int atrac1_decode_frame(AVCodecContext *avctx, void *data,

                               int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    AT1Ctx *q          = avctx->priv_data;

    int ch, ret, i;

    GetBitContext gb;

    float* samples = data;





    if (buf_size < 212 * q->channels) {

        av_log(q,AV_LOG_ERROR,"Not enought data to decode!\n");

        return -1;

    }



    for (ch = 0; ch < q->channels; ch++) {

        AT1SUCtx* su = &q->SUs[ch];



        init_get_bits(&gb, &buf[212 * ch], 212 * 8);



        /* parse block_size_mode, 1st byte */

        ret = at1_parse_bsm(&gb, su->log2_block_count);

        if (ret < 0)

            return ret;



        ret = at1_unpack_dequant(&gb, su, q->spec);

        if (ret < 0)

            return ret;



        ret = at1_imdct_block(su, q);

        if (ret < 0)

            return ret;

        at1_subband_synthesis(q, su, q->out_samples[ch]);

    }



    /* interleave; FIXME, should create/use a DSP function */

    if (q->channels == 1) {

        /* mono */

        memcpy(samples, q->out_samples[0], AT1_SU_SAMPLES * 4);

    } else {

        /* stereo */

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

            samples[i * 2]     = q->out_samples[0][i];

            samples[i * 2 + 1] = q->out_samples[1][i];

        }

    }



    *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples);

    return avctx->block_align;

}

static int atrac1_decode_frame(AVCodecContext *avctx, void *data,

                               int *data_size, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    AT1Ctx *q          = avctx->priv_data;

    int ch, ret, i;

    GetBitContext gb;

    float* samples = data;





    if (buf_size < 212 * q->channels) {

        av_log(q,AV_LOG_ERROR,"Not enought data to decode!\n");

        return -1;

    }



    for (ch = 0; ch < q->channels; ch++) {

        AT1SUCtx* su = &q->SUs[ch];



        init_get_bits(&gb, &buf[212 * ch], 212 * 8);



        

        ret = at1_parse_bsm(&gb, su->log2_block_count);

        if (ret < 0)

            return ret;



        ret = at1_unpack_dequant(&gb, su, q->spec);

        if (ret < 0)

            return ret;



        ret = at1_imdct_block(su, q);

        if (ret < 0)

            return ret;

        at1_subband_synthesis(q, su, q->out_samples[ch]);

    }



    

    if (q->channels == 1) {

        

        memcpy(samples, q->out_samples[0], AT1_SU_SAMPLES * 4);

    } else {

        

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

            samples[i * 2]     = q->out_samples[0][i];

            samples[i * 2 + 1] = q->out_samples[1][i];

        }

    }



    *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples);

    return avctx->block_align;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                               int *VAR_2, AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5       = VAR_3->size;

    AT1Ctx *q          = VAR_0->priv_data;

    int VAR_6, VAR_7, VAR_8;

    GetBitContext gb;

    float* VAR_9 = VAR_1;





    if (VAR_5 < 212 * q->channels) {

        av_log(q,AV_LOG_ERROR,"Not enought VAR_1 to decode!\n");

        return -1;

    }



    for (VAR_6 = 0; VAR_6 < q->channels; VAR_6++) {

        AT1SUCtx* su = &q->SUs[VAR_6];



        init_get_bits(&gb, &VAR_4[212 * VAR_6], 212 * 8);



        

        VAR_7 = at1_parse_bsm(&gb, su->log2_block_count);

        if (VAR_7 < 0)

            return VAR_7;



        VAR_7 = at1_unpack_dequant(&gb, su, q->spec);

        if (VAR_7 < 0)

            return VAR_7;



        VAR_7 = at1_imdct_block(su, q);

        if (VAR_7 < 0)

            return VAR_7;

        at1_subband_synthesis(q, su, q->out_samples[VAR_6]);

    }



    

    if (q->channels == 1) {

        

        memcpy(VAR_9, q->out_samples[0], AT1_SU_SAMPLES * 4);

    } else {

        

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

            VAR_9[VAR_8 * 2]     = q->out_samples[0][VAR_8];

            VAR_9[VAR_8 * 2 + 1] = q->out_samples[1][VAR_8];

        }

    }



    *VAR_2 = q->channels * AT1_SU_SAMPLES * sizeof(*VAR_9);

    return VAR_0->block_align;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5       = VAR_3->size; AT1Ctx *q          = VAR_0->priv_data; int VAR_6, VAR_7, VAR_8; GetBitContext gb; float* VAR_9 = VAR_1; if (VAR_5 < 212 * q->channels) { av_log(q,AV_LOG_ERROR,"Not enought VAR_1 to decode!\n"); return -1; } for (VAR_6 = 0; VAR_6 < q->channels; VAR_6++) { AT1SUCtx* su = &q->SUs[VAR_6]; init_get_bits(&gb, &VAR_4[212 * VAR_6], 212 * 8); VAR_7 = at1_parse_bsm(&gb, su->log2_block_count); if (VAR_7 < 0)
return VAR_7; VAR_7 = at1_unpack_dequant(&gb, su, q->spec); if (VAR_7 < 0)
return VAR_7; VAR_7 = at1_imdct_block(su, q); if (VAR_7 < 0)
return VAR_7; at1_subband_synthesis(q, su, q->out_samples[VAR_6]); } if (q->channels == 1) { memcpy(VAR_9, q->out_samples[0], AT1_SU_SAMPLES * 4); } else { for (VAR_8 = 0; VAR_8 < AT1_SU_SAMPLES; VAR_8++) { VAR_9[VAR_8 * 2]     = q->out_samples[0][VAR_8]; VAR_9[VAR_8 * 2 + 1] = q->out_samples[1][VAR_8]; } } *VAR_2 = q->channels * AT1_SU_SAMPLES * sizeof(*VAR_9); return VAR_0->block_align; }