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

                              int *got_frame_ptr, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    ADPCMDecodeContext *c = avctx->priv_data;

    ADPCMChannelStatus *cs;

    int n, m, channel, i;

    short *samples;

    int16_t **samples_p;

    int st; /* stereo */

    int count1, count2;

    int nb_samples, coded_samples, ret;

    GetByteContext gb;



    bytestream2_init(&gb, buf, buf_size);

    nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples);

    if (nb_samples <= 0) {

        av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");

        return AVERROR_INVALIDDATA;

    }



    /* get output buffer */

    c->frame.nb_samples = nb_samples;

    if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

        return ret;

    }

    samples = (short *)c->frame.data[0];

    samples_p = (int16_t **)c->frame.extended_data;



    /* use coded_samples when applicable */

    /* it is always <= nb_samples, so the output buffer will be large enough */

    if (coded_samples) {

        if (coded_samples != nb_samples)

            av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");

        c->frame.nb_samples = nb_samples = coded_samples;

    }



    st = avctx->channels == 2 ? 1 : 0;



    switch(avctx->codec->id) {

    case AV_CODEC_ID_ADPCM_IMA_QT:

        /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).

           Channel data is interleaved per-chunk. */

        for (channel = 0; channel < avctx->channels; channel++) {

            int predictor;

            int step_index;

            cs = &(c->status[channel]);

            /* (pppppp) (piiiiiii) */



            /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */

            predictor = sign_extend(bytestream2_get_be16u(&gb), 16);

            step_index = predictor & 0x7F;

            predictor &= ~0x7F;



            if (cs->step_index == step_index) {

                int diff = predictor - cs->predictor;

                if (diff < 0)

                    diff = - diff;

                if (diff > 0x7f)

                    goto update;

            } else {

            update:

                cs->step_index = step_index;

                cs->predictor = predictor;

            }



            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       channel, cs->step_index);

                return AVERROR_INVALIDDATA;

            }



            samples = samples_p[channel];



            for (m = 0; m < 64; m += 2) {

                int byte = bytestream2_get_byteu(&gb);

                samples[m    ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);

                samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4  , 3);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_WAV:

        for(i=0; i<avctx->channels; i++){

            cs = &(c->status[i]);

            cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);



            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       i, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (n = 0; n < (nb_samples - 1) / 8; n++) {

            for (i = 0; i < avctx->channels; i++) {

                cs = &c->status[i];

                samples = &samples_p[i][1 + n * 8];

                for (m = 0; m < 8; m += 2) {

                    int v = bytestream2_get_byteu(&gb);

                    samples[m    ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);

                    samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4  , 3);

                }

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_4XM:

        for (i = 0; i < avctx->channels; i++)

            c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);



        for (i = 0; i < avctx->channels; i++) {

            c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (c->status[i].step_index > 88u) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       i, c->status[i].step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (i = 0; i < avctx->channels; i++) {

            samples = (int16_t *)c->frame.data[i];

            cs = &c->status[i];

            for (n = nb_samples >> 1; n > 0; n--) {

                int v = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);

                *samples++ = adpcm_ima_expand_nibble(cs, v >> 4  , 4);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_MS:

    {

        int block_predictor;



        block_predictor = bytestream2_get_byteu(&gb);

        if (block_predictor > 6) {

            av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",

                   block_predictor);

            return AVERROR_INVALIDDATA;

        }

        c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];

        c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];

        if (st) {

            block_predictor = bytestream2_get_byteu(&gb);

            if (block_predictor > 6) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",

                       block_predictor);

                return AVERROR_INVALIDDATA;

            }

            c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];

            c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];

        }

        c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (st){

            c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);

        }



        c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);



        *samples++ = c->status[0].sample2;

        if (st) *samples++ = c->status[1].sample2;

        *samples++ = c->status[0].sample1;

        if (st) *samples++ = c->status[1].sample1;

        for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {

            int byte = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4  );

            *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_DK4:

        for (channel = 0; channel < avctx->channels; channel++) {

            cs = &c->status[channel];

            cs->predictor  = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);

            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       channel, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4  , 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_DK3:

    {

        int last_byte = 0;

        int nibble;

        int decode_top_nibble_next = 0;

        int diff_channel;

        const int16_t *samples_end = samples + avctx->channels * nb_samples;



        bytestream2_skipu(&gb, 10);

        c->status[0].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[1].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].step_index = bytestream2_get_byteu(&gb);

        c->status[1].step_index = bytestream2_get_byteu(&gb);

        if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){

            av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",

                   c->status[0].step_index, c->status[1].step_index);

            return AVERROR_INVALIDDATA;

        }

        /* sign extend the predictors */

        diff_channel = c->status[1].predictor;



        /* DK3 ADPCM support macro */

#define DK3_GET_NEXT_NIBBLE() \

    if (decode_top_nibble_next) { \

        nibble = last_byte >> 4; \

        decode_top_nibble_next = 0; \

    } else { \

        last_byte = bytestream2_get_byteu(&gb); \

        nibble = last_byte & 0x0F; \

        decode_top_nibble_next = 1; \

    }



        while (samples < samples_end) {



            /* for this algorithm, c->status[0] is the sum channel and

             * c->status[1] is the diff channel */



            /* process the first predictor of the sum channel */

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[0], nibble, 3);



            /* process the diff channel predictor */

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[1], nibble, 3);



            /* process the first pair of stereo PCM samples */

            diff_channel = (diff_channel + c->status[1].predictor) / 2;

            *samples++ = c->status[0].predictor + c->status[1].predictor;

            *samples++ = c->status[0].predictor - c->status[1].predictor;



            /* process the second predictor of the sum channel */

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[0], nibble, 3);



            /* process the second pair of stereo PCM samples */

            diff_channel = (diff_channel + c->status[1].predictor) / 2;

            *samples++ = c->status[0].predictor + c->status[1].predictor;

            *samples++ = c->status[0].predictor - c->status[1].predictor;

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_ISS:

        for (channel = 0; channel < avctx->channels; channel++) {

            cs = &c->status[channel];

            cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       channel, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v1, v2;

            int v = bytestream2_get_byteu(&gb);

            /* nibbles are swapped for mono */

            if (st) {

                v1 = v >> 4;

                v2 = v & 0x0F;

            } else {

                v2 = v >> 4;

                v1 = v & 0x0F;

            }

            *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_APC:

        while (bytestream2_get_bytes_left(&gb) > 0) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  v >> 4  , 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_OKI:

        while (bytestream2_get_bytes_left(&gb) > 0) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0],  v >> 4  );

            *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_WS:

        if (c->vqa_version == 3) {

            for (channel = 0; channel < avctx->channels; channel++) {

                int16_t *smp = samples_p[channel];



                for (n = nb_samples / 2; n > 0; n--) {

                    int v = bytestream2_get_byteu(&gb);

                    *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);

                    *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);

                }

            }

        } else {

            for (n = nb_samples / 2; n > 0; n--) {

                for (channel = 0; channel < avctx->channels; channel++) {

                    int v = bytestream2_get_byteu(&gb);

                    *samples++  = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);

                    samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);

                }

                samples += avctx->channels;

            }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    case AV_CODEC_ID_ADPCM_XA:

    {

        int16_t *out0 = samples_p[0];

        int16_t *out1 = samples_p[1];

        int samples_per_block = 28 * (3 - avctx->channels) * 4;

        int sample_offset = 0;

        while (bytestream2_get_bytes_left(&gb) >= 128) {

            if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),

                                 &c->status[0], &c->status[1],

                                 avctx->channels, sample_offset)) < 0)

                return ret;

            bytestream2_skipu(&gb, 128);

            sample_offset += samples_per_block;

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_EA_EACS:

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

            c->status[i].step_index = bytestream2_get_le32u(&gb);

            if (c->status[i].step_index > 88u) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       i, c->status[i].step_index);

                return AVERROR_INVALIDDATA;

            }

        }

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

            c->status[i].predictor  = bytestream2_get_le32u(&gb);



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int byte   = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int byte = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   6);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);

        }

        break;

    case AV_CODEC_ID_ADPCM_EA:

    {

        int previous_left_sample, previous_right_sample;

        int current_left_sample, current_right_sample;

        int next_left_sample, next_right_sample;

        int coeff1l, coeff2l, coeff1r, coeff2r;

        int shift_left, shift_right;



        /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,

           each coding 28 stereo samples. */



        if(avctx->channels != 2)

            return AVERROR_INVALIDDATA;



        current_left_sample   = sign_extend(bytestream2_get_le16u(&gb), 16);

        previous_left_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);

        current_right_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);

        previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);



        for (count1 = 0; count1 < nb_samples / 28; count1++) {

            int byte = bytestream2_get_byteu(&gb);

            coeff1l = ea_adpcm_table[ byte >> 4       ];

            coeff2l = ea_adpcm_table[(byte >> 4  ) + 4];

            coeff1r = ea_adpcm_table[ byte & 0x0F];

            coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];



            byte = bytestream2_get_byteu(&gb);

            shift_left  = 20 - (byte >> 4);

            shift_right = 20 - (byte & 0x0F);



            for (count2 = 0; count2 < 28; count2++) {

                byte = bytestream2_get_byteu(&gb);

                next_left_sample  = sign_extend(byte >> 4, 4) << shift_left;

                next_right_sample = sign_extend(byte,      4) << shift_right;



                next_left_sample = (next_left_sample +

                    (current_left_sample * coeff1l) +

                    (previous_left_sample * coeff2l) + 0x80) >> 8;

                next_right_sample = (next_right_sample +

                    (current_right_sample * coeff1r) +

                    (previous_right_sample * coeff2r) + 0x80) >> 8;



                previous_left_sample = current_left_sample;

                current_left_sample = av_clip_int16(next_left_sample);

                previous_right_sample = current_right_sample;

                current_right_sample = av_clip_int16(next_right_sample);

                *samples++ = current_left_sample;

                *samples++ = current_right_sample;

            }

        }



        bytestream2_skip(&gb, 2); // Skip terminating 0x0000



        break;

    }

    case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:

    {

        int coeff[2][2], shift[2];



        for(channel = 0; channel < avctx->channels; channel++) {

            int byte = bytestream2_get_byteu(&gb);

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

                coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];

            shift[channel] = 20 - (byte & 0x0F);

        }

        for (count1 = 0; count1 < nb_samples / 2; count1++) {

            int byte[2];



            byte[0] = bytestream2_get_byteu(&gb);

            if (st) byte[1] = bytestream2_get_byteu(&gb);

            for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */

                for(channel = 0; channel < avctx->channels; channel++) {

                    int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];

                    sample = (sample +

                             c->status[channel].sample1 * coeff[channel][0] +

                             c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;

                    c->status[channel].sample2 = c->status[channel].sample1;

                    c->status[channel].sample1 = av_clip_int16(sample);

                    *samples++ = c->status[channel].sample1;

                }

            }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_EA_R1:

    case AV_CODEC_ID_ADPCM_EA_R2:

    case AV_CODEC_ID_ADPCM_EA_R3: {

        /* channel numbering

           2chan: 0=fl, 1=fr

           4chan: 0=fl, 1=rl, 2=fr, 3=rr

           6chan: 0=fl, 1=c,  2=fr, 3=rl,  4=rr, 5=sub */

        const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;

        int previous_sample, current_sample, next_sample;

        int coeff1, coeff2;

        int shift;

        unsigned int channel;

        uint16_t *samplesC;

        int count = 0;

        int offsets[6];



        for (channel=0; channel<avctx->channels; channel++)

            offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :

                                             bytestream2_get_le32(&gb)) +

                               (avctx->channels + 1) * 4;



        for (channel=0; channel<avctx->channels; channel++) {

            bytestream2_seek(&gb, offsets[channel], SEEK_SET);

            samplesC = samples_p[channel];



            if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {

                current_sample  = sign_extend(bytestream2_get_le16(&gb), 16);

                previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);

            } else {

                current_sample  = c->status[channel].predictor;

                previous_sample = c->status[channel].prev_sample;

            }



            for (count1 = 0; count1 < nb_samples / 28; count1++) {

                int byte = bytestream2_get_byte(&gb);

                if (byte == 0xEE) {  /* only seen in R2 and R3 */

                    current_sample  = sign_extend(bytestream2_get_be16(&gb), 16);

                    previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);



                    for (count2=0; count2<28; count2++)

                        *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);

                } else {

                    coeff1 = ea_adpcm_table[ byte >> 4     ];

                    coeff2 = ea_adpcm_table[(byte >> 4) + 4];

                    shift = 20 - (byte & 0x0F);



                    for (count2=0; count2<28; count2++) {

                        if (count2 & 1)

                            next_sample = sign_extend(byte,    4) << shift;

                        else {

                            byte = bytestream2_get_byte(&gb);

                            next_sample = sign_extend(byte >> 4, 4) << shift;

                        }



                        next_sample += (current_sample  * coeff1) +

                                       (previous_sample * coeff2);

                        next_sample = av_clip_int16(next_sample >> 8);



                        previous_sample = current_sample;

                        current_sample  = next_sample;

                        *samplesC++ = current_sample;

                    }

                }

            }

            if (!count) {

                count = count1;

            } else if (count != count1) {

                av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");

                count = FFMAX(count, count1);

            }



            if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {

                c->status[channel].predictor   = current_sample;

                c->status[channel].prev_sample = previous_sample;

            }

        }



        c->frame.nb_samples = count * 28;

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_EA_XAS:

        for (channel=0; channel<avctx->channels; channel++) {

            int coeff[2][4], shift[4];

            int16_t *s = samples_p[channel];

            for (n = 0; n < 4; n++, s += 32) {

                int val = sign_extend(bytestream2_get_le16u(&gb), 16);

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

                    coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];

                s[0] = val & ~0x0F;



                val = sign_extend(bytestream2_get_le16u(&gb), 16);

                shift[n] = 20 - (val & 0x0F);

                s[1] = val & ~0x0F;

            }



            for (m=2; m<32; m+=2) {

                s = &samples_p[channel][m];

                for (n = 0; n < 4; n++, s += 32) {

                    int level, pred;

                    int byte = bytestream2_get_byteu(&gb);



                    level = sign_extend(byte >> 4, 4) << shift[n];

                    pred  = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];

                    s[0]  = av_clip_int16((level + pred + 0x80) >> 8);



                    level = sign_extend(byte, 4) << shift[n];

                    pred  = s[0] * coeff[0][n] + s[-1] * coeff[1][n];

                    s[1]  = av_clip_int16((level + pred + 0x80) >> 8);

                }

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_AMV:

        c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].step_index = bytestream2_get_le16u(&gb);

        bytestream2_skipu(&gb, 4);

        if (c->status[0].step_index > 88u) {

            av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",

                   c->status[0].step_index);

            return AVERROR_INVALIDDATA;

        }



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);



            *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_SMJPEG:

        for (i = 0; i < avctx->channels; i++) {

            c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);

            c->status[i].step_index = bytestream2_get_byteu(&gb);

            bytestream2_skipu(&gb, 1);

            if (c->status[i].step_index > 88u) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",

                       c->status[i].step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);



            *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3);

            *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_CT:

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4  );

            *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);

        }

        break;

    case AV_CODEC_ID_ADPCM_SBPRO_4:

    case AV_CODEC_ID_ADPCM_SBPRO_3:

    case AV_CODEC_ID_ADPCM_SBPRO_2:

        if (!c->status[0].step_index) {

            /* the first byte is a raw sample */

            *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);

            if (st)

                *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);

            c->status[0].step_index = 1;

            nb_samples--;

        }

        if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {

            for (n = nb_samples >> (1 - st); n > 0; n--) {

                int byte = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       byte >> 4,   4, 0);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],

                                                       byte & 0x0F, 4, 0);

            }

        } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {

            for (n = nb_samples / 3; n > 0; n--) {

                int byte = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        byte >> 5        , 3, 0);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       (byte >> 2) & 0x07, 3, 0);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        byte & 0x03,       2, 0);

            }

        } else {

            for (n = nb_samples >> (2 - st); n > 0; n--) {

                int byte = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        byte >> 6        , 2, 2);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],

                                                       (byte >> 4) & 0x03, 2, 2);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       (byte >> 2) & 0x03, 2, 2);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],

                                                        byte & 0x03,       2, 2);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_SWF:

        adpcm_swf_decode(avctx, buf, buf_size, samples);

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    case AV_CODEC_ID_ADPCM_YAMAHA:

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);

            *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4  );

        }

        break;

    case AV_CODEC_ID_ADPCM_AFC:

    {

        int samples_per_block;

        int blocks;



        if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {

            samples_per_block = avctx->extradata[0] / 16;

            blocks = nb_samples / avctx->extradata[0];

        } else {

            samples_per_block = nb_samples / 16;

            blocks = 1;

        }



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

        for (channel = 0; channel < avctx->channels; channel++) {

            int prev1 = c->status[channel].sample1;

            int prev2 = c->status[channel].sample2;



            samples = samples_p[channel] + m * 16;

            /* Read in every sample for this channel.  */

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

                int byte = bytestream2_get_byteu(&gb);

                int scale = 1 << (byte >> 4);

                int index = byte & 0xf;

                int factor1 = ff_adpcm_afc_coeffs[0][index];

                int factor2 = ff_adpcm_afc_coeffs[1][index];



                /* Decode 16 samples.  */

                for (n = 0; n < 16; n++) {

                    int32_t sampledat;



                    if (n & 1) {

                        sampledat = sign_extend(byte, 4);

                    } else {

                        byte = bytestream2_get_byteu(&gb);

                        sampledat = sign_extend(byte >> 4, 4);

                    }



                    sampledat = ((prev1 * factor1 + prev2 * factor2) +

                                 ((sampledat * scale) << 11)) >> 11;

                    *samples = av_clip_int16(sampledat);

                    prev2 = prev1;

                    prev1 = *samples++;

                }

            }



            c->status[channel].sample1 = prev1;

            c->status[channel].sample2 = prev2;

        }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_THP:

    {

        int table[6][16];

        int ch;



        for (i = 0; i < avctx->channels; i++)

            for (n = 0; n < 16; n++)

                table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);



        /* Initialize the previous sample.  */

        for (i = 0; i < avctx->channels; i++) {

            c->status[i].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16);

            c->status[i].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16);

        }



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

            samples = samples_p[ch];



            /* Read in every sample for this channel.  */

            for (i = 0; i < nb_samples / 14; i++) {

                int byte = bytestream2_get_byteu(&gb);

                int index = (byte >> 4) & 7;

                unsigned int exp = byte & 0x0F;

                int factor1 = table[ch][index * 2];

                int factor2 = table[ch][index * 2 + 1];



                /* Decode 14 samples.  */

                for (n = 0; n < 14; n++) {

                    int32_t sampledat;



                    if (n & 1) {

                        sampledat = sign_extend(byte, 4);

                    } else {

                        byte = bytestream2_get_byteu(&gb);

                        sampledat = sign_extend(byte >> 4, 4);

                    }



                    sampledat = ((c->status[ch].sample1 * factor1

                                + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp);

                    *samples = av_clip_int16(sampledat);

                    c->status[ch].sample2 = c->status[ch].sample1;

                    c->status[ch].sample1 = *samples++;

                }

            }

        }

        break;

    }



    default:

        return -1;

    }



    if (avpkt->size && bytestream2_tell(&gb) == 0) {

        av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");

        return AVERROR_INVALIDDATA;

    }



    *got_frame_ptr   = 1;

    *(AVFrame *)data = c->frame;



    return bytestream2_tell(&gb);

}

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

                              int *got_frame_ptr, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    ADPCMDecodeContext *c = avctx->priv_data;

    ADPCMChannelStatus *cs;

    int n, m, channel, i;

    short *samples;

    int16_t **samples_p;

    int st; 

    int count1, count2;

    int nb_samples, coded_samples, ret;

    GetByteContext gb;



    bytestream2_init(&gb, buf, buf_size);

    nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples);

    if (nb_samples <= 0) {

        av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");

        return AVERROR_INVALIDDATA;

    }



    

    c->frame.nb_samples = nb_samples;

    if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

        return ret;

    }

    samples = (short *)c->frame.data[0];

    samples_p = (int16_t **)c->frame.extended_data;



    

    

    if (coded_samples) {

        if (coded_samples != nb_samples)

            av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");

        c->frame.nb_samples = nb_samples = coded_samples;

    }



    st = avctx->channels == 2 ? 1 : 0;



    switch(avctx->codec->id) {

    case AV_CODEC_ID_ADPCM_IMA_QT:

        



        for (channel = 0; channel < avctx->channels; channel++) {

            int predictor;

            int step_index;

            cs = &(c->status[channel]);

            



            

            predictor = sign_extend(bytestream2_get_be16u(&gb), 16);

            step_index = predictor & 0x7F;

            predictor &= ~0x7F;



            if (cs->step_index == step_index) {

                int diff = predictor - cs->predictor;

                if (diff < 0)

                    diff = - diff;

                if (diff > 0x7f)

                    goto update;

            } else {

            update:

                cs->step_index = step_index;

                cs->predictor = predictor;

            }



            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       channel, cs->step_index);

                return AVERROR_INVALIDDATA;

            }



            samples = samples_p[channel];



            for (m = 0; m < 64; m += 2) {

                int byte = bytestream2_get_byteu(&gb);

                samples[m    ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);

                samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4  , 3);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_WAV:

        for(i=0; i<avctx->channels; i++){

            cs = &(c->status[i]);

            cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);



            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       i, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (n = 0; n < (nb_samples - 1) / 8; n++) {

            for (i = 0; i < avctx->channels; i++) {

                cs = &c->status[i];

                samples = &samples_p[i][1 + n * 8];

                for (m = 0; m < 8; m += 2) {

                    int v = bytestream2_get_byteu(&gb);

                    samples[m    ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);

                    samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4  , 3);

                }

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_4XM:

        for (i = 0; i < avctx->channels; i++)

            c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);



        for (i = 0; i < avctx->channels; i++) {

            c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (c->status[i].step_index > 88u) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       i, c->status[i].step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (i = 0; i < avctx->channels; i++) {

            samples = (int16_t *)c->frame.data[i];

            cs = &c->status[i];

            for (n = nb_samples >> 1; n > 0; n--) {

                int v = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);

                *samples++ = adpcm_ima_expand_nibble(cs, v >> 4  , 4);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_MS:

    {

        int block_predictor;



        block_predictor = bytestream2_get_byteu(&gb);

        if (block_predictor > 6) {

            av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",

                   block_predictor);

            return AVERROR_INVALIDDATA;

        }

        c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];

        c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];

        if (st) {

            block_predictor = bytestream2_get_byteu(&gb);

            if (block_predictor > 6) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",

                       block_predictor);

                return AVERROR_INVALIDDATA;

            }

            c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];

            c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];

        }

        c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (st){

            c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);

        }



        c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);



        *samples++ = c->status[0].sample2;

        if (st) *samples++ = c->status[1].sample2;

        *samples++ = c->status[0].sample1;

        if (st) *samples++ = c->status[1].sample1;

        for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {

            int byte = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4  );

            *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_DK4:

        for (channel = 0; channel < avctx->channels; channel++) {

            cs = &c->status[channel];

            cs->predictor  = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);

            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       channel, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4  , 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_DK3:

    {

        int last_byte = 0;

        int nibble;

        int decode_top_nibble_next = 0;

        int diff_channel;

        const int16_t *samples_end = samples + avctx->channels * nb_samples;



        bytestream2_skipu(&gb, 10);

        c->status[0].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[1].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].step_index = bytestream2_get_byteu(&gb);

        c->status[1].step_index = bytestream2_get_byteu(&gb);

        if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){

            av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",

                   c->status[0].step_index, c->status[1].step_index);

            return AVERROR_INVALIDDATA;

        }

        

        diff_channel = c->status[1].predictor;



        

#define DK3_GET_NEXT_NIBBLE() \

    if (decode_top_nibble_next) { \

        nibble = last_byte >> 4; \

        decode_top_nibble_next = 0; \

    } else { \

        last_byte = bytestream2_get_byteu(&gb); \

        nibble = last_byte & 0x0F; \

        decode_top_nibble_next = 1; \

    }



        while (samples < samples_end) {



            





            

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[0], nibble, 3);



            

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[1], nibble, 3);



            

            diff_channel = (diff_channel + c->status[1].predictor) / 2;

            *samples++ = c->status[0].predictor + c->status[1].predictor;

            *samples++ = c->status[0].predictor - c->status[1].predictor;



            

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[0], nibble, 3);



            

            diff_channel = (diff_channel + c->status[1].predictor) / 2;

            *samples++ = c->status[0].predictor + c->status[1].predictor;

            *samples++ = c->status[0].predictor - c->status[1].predictor;

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_ISS:

        for (channel = 0; channel < avctx->channels; channel++) {

            cs = &c->status[channel];

            cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       channel, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v1, v2;

            int v = bytestream2_get_byteu(&gb);

            

            if (st) {

                v1 = v >> 4;

                v2 = v & 0x0F;

            } else {

                v2 = v >> 4;

                v1 = v & 0x0F;

            }

            *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_APC:

        while (bytestream2_get_bytes_left(&gb) > 0) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  v >> 4  , 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_OKI:

        while (bytestream2_get_bytes_left(&gb) > 0) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0],  v >> 4  );

            *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_WS:

        if (c->vqa_version == 3) {

            for (channel = 0; channel < avctx->channels; channel++) {

                int16_t *smp = samples_p[channel];



                for (n = nb_samples / 2; n > 0; n--) {

                    int v = bytestream2_get_byteu(&gb);

                    *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);

                    *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);

                }

            }

        } else {

            for (n = nb_samples / 2; n > 0; n--) {

                for (channel = 0; channel < avctx->channels; channel++) {

                    int v = bytestream2_get_byteu(&gb);

                    *samples++  = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);

                    samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);

                }

                samples += avctx->channels;

            }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    case AV_CODEC_ID_ADPCM_XA:

    {

        int16_t *out0 = samples_p[0];

        int16_t *out1 = samples_p[1];

        int samples_per_block = 28 * (3 - avctx->channels) * 4;

        int sample_offset = 0;

        while (bytestream2_get_bytes_left(&gb) >= 128) {

            if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),

                                 &c->status[0], &c->status[1],

                                 avctx->channels, sample_offset)) < 0)

                return ret;

            bytestream2_skipu(&gb, 128);

            sample_offset += samples_per_block;

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_EA_EACS:

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

            c->status[i].step_index = bytestream2_get_le32u(&gb);

            if (c->status[i].step_index > 88u) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",

                       i, c->status[i].step_index);

                return AVERROR_INVALIDDATA;

            }

        }

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

            c->status[i].predictor  = bytestream2_get_le32u(&gb);



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int byte   = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int byte = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   6);

            *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);

        }

        break;

    case AV_CODEC_ID_ADPCM_EA:

    {

        int previous_left_sample, previous_right_sample;

        int current_left_sample, current_right_sample;

        int next_left_sample, next_right_sample;

        int coeff1l, coeff2l, coeff1r, coeff2r;

        int shift_left, shift_right;



        





        if(avctx->channels != 2)

            return AVERROR_INVALIDDATA;



        current_left_sample   = sign_extend(bytestream2_get_le16u(&gb), 16);

        previous_left_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);

        current_right_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);

        previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);



        for (count1 = 0; count1 < nb_samples / 28; count1++) {

            int byte = bytestream2_get_byteu(&gb);

            coeff1l = ea_adpcm_table[ byte >> 4       ];

            coeff2l = ea_adpcm_table[(byte >> 4  ) + 4];

            coeff1r = ea_adpcm_table[ byte & 0x0F];

            coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];



            byte = bytestream2_get_byteu(&gb);

            shift_left  = 20 - (byte >> 4);

            shift_right = 20 - (byte & 0x0F);



            for (count2 = 0; count2 < 28; count2++) {

                byte = bytestream2_get_byteu(&gb);

                next_left_sample  = sign_extend(byte >> 4, 4) << shift_left;

                next_right_sample = sign_extend(byte,      4) << shift_right;



                next_left_sample = (next_left_sample +

                    (current_left_sample * coeff1l) +

                    (previous_left_sample * coeff2l) + 0x80) >> 8;

                next_right_sample = (next_right_sample +

                    (current_right_sample * coeff1r) +

                    (previous_right_sample * coeff2r) + 0x80) >> 8;



                previous_left_sample = current_left_sample;

                current_left_sample = av_clip_int16(next_left_sample);

                previous_right_sample = current_right_sample;

                current_right_sample = av_clip_int16(next_right_sample);

                *samples++ = current_left_sample;

                *samples++ = current_right_sample;

            }

        }



        bytestream2_skip(&gb, 2); 



        break;

    }

    case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:

    {

        int coeff[2][2], shift[2];



        for(channel = 0; channel < avctx->channels; channel++) {

            int byte = bytestream2_get_byteu(&gb);

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

                coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];

            shift[channel] = 20 - (byte & 0x0F);

        }

        for (count1 = 0; count1 < nb_samples / 2; count1++) {

            int byte[2];



            byte[0] = bytestream2_get_byteu(&gb);

            if (st) byte[1] = bytestream2_get_byteu(&gb);

            for(i = 4; i >= 0; i-=4) { 

                for(channel = 0; channel < avctx->channels; channel++) {

                    int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];

                    sample = (sample +

                             c->status[channel].sample1 * coeff[channel][0] +

                             c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;

                    c->status[channel].sample2 = c->status[channel].sample1;

                    c->status[channel].sample1 = av_clip_int16(sample);

                    *samples++ = c->status[channel].sample1;

                }

            }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_EA_R1:

    case AV_CODEC_ID_ADPCM_EA_R2:

    case AV_CODEC_ID_ADPCM_EA_R3: {

        







        const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;

        int previous_sample, current_sample, next_sample;

        int coeff1, coeff2;

        int shift;

        unsigned int channel;

        uint16_t *samplesC;

        int count = 0;

        int offsets[6];



        for (channel=0; channel<avctx->channels; channel++)

            offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :

                                             bytestream2_get_le32(&gb)) +

                               (avctx->channels + 1) * 4;



        for (channel=0; channel<avctx->channels; channel++) {

            bytestream2_seek(&gb, offsets[channel], SEEK_SET);

            samplesC = samples_p[channel];



            if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {

                current_sample  = sign_extend(bytestream2_get_le16(&gb), 16);

                previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);

            } else {

                current_sample  = c->status[channel].predictor;

                previous_sample = c->status[channel].prev_sample;

            }



            for (count1 = 0; count1 < nb_samples / 28; count1++) {

                int byte = bytestream2_get_byte(&gb);

                if (byte == 0xEE) {  

                    current_sample  = sign_extend(bytestream2_get_be16(&gb), 16);

                    previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);



                    for (count2=0; count2<28; count2++)

                        *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);

                } else {

                    coeff1 = ea_adpcm_table[ byte >> 4     ];

                    coeff2 = ea_adpcm_table[(byte >> 4) + 4];

                    shift = 20 - (byte & 0x0F);



                    for (count2=0; count2<28; count2++) {

                        if (count2 & 1)

                            next_sample = sign_extend(byte,    4) << shift;

                        else {

                            byte = bytestream2_get_byte(&gb);

                            next_sample = sign_extend(byte >> 4, 4) << shift;

                        }



                        next_sample += (current_sample  * coeff1) +

                                       (previous_sample * coeff2);

                        next_sample = av_clip_int16(next_sample >> 8);



                        previous_sample = current_sample;

                        current_sample  = next_sample;

                        *samplesC++ = current_sample;

                    }

                }

            }

            if (!count) {

                count = count1;

            } else if (count != count1) {

                av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");

                count = FFMAX(count, count1);

            }



            if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {

                c->status[channel].predictor   = current_sample;

                c->status[channel].prev_sample = previous_sample;

            }

        }



        c->frame.nb_samples = count * 28;

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_EA_XAS:

        for (channel=0; channel<avctx->channels; channel++) {

            int coeff[2][4], shift[4];

            int16_t *s = samples_p[channel];

            for (n = 0; n < 4; n++, s += 32) {

                int val = sign_extend(bytestream2_get_le16u(&gb), 16);

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

                    coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];

                s[0] = val & ~0x0F;



                val = sign_extend(bytestream2_get_le16u(&gb), 16);

                shift[n] = 20 - (val & 0x0F);

                s[1] = val & ~0x0F;

            }



            for (m=2; m<32; m+=2) {

                s = &samples_p[channel][m];

                for (n = 0; n < 4; n++, s += 32) {

                    int level, pred;

                    int byte = bytestream2_get_byteu(&gb);



                    level = sign_extend(byte >> 4, 4) << shift[n];

                    pred  = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];

                    s[0]  = av_clip_int16((level + pred + 0x80) >> 8);



                    level = sign_extend(byte, 4) << shift[n];

                    pred  = s[0] * coeff[0][n] + s[-1] * coeff[1][n];

                    s[1]  = av_clip_int16((level + pred + 0x80) >> 8);

                }

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_AMV:

        c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].step_index = bytestream2_get_le16u(&gb);

        bytestream2_skipu(&gb, 4);

        if (c->status[0].step_index > 88u) {

            av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",

                   c->status[0].step_index);

            return AVERROR_INVALIDDATA;

        }



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);



            *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);

            *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_SMJPEG:

        for (i = 0; i < avctx->channels; i++) {

            c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);

            c->status[i].step_index = bytestream2_get_byteu(&gb);

            bytestream2_skipu(&gb, 1);

            if (c->status[i].step_index > 88u) {

                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",

                       c->status[i].step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);



            *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3);

            *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_CT:

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4  );

            *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);

        }

        break;

    case AV_CODEC_ID_ADPCM_SBPRO_4:

    case AV_CODEC_ID_ADPCM_SBPRO_3:

    case AV_CODEC_ID_ADPCM_SBPRO_2:

        if (!c->status[0].step_index) {

            

            *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);

            if (st)

                *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);

            c->status[0].step_index = 1;

            nb_samples--;

        }

        if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {

            for (n = nb_samples >> (1 - st); n > 0; n--) {

                int byte = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       byte >> 4,   4, 0);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],

                                                       byte & 0x0F, 4, 0);

            }

        } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {

            for (n = nb_samples / 3; n > 0; n--) {

                int byte = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        byte >> 5        , 3, 0);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       (byte >> 2) & 0x07, 3, 0);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        byte & 0x03,       2, 0);

            }

        } else {

            for (n = nb_samples >> (2 - st); n > 0; n--) {

                int byte = bytestream2_get_byteu(&gb);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        byte >> 6        , 2, 2);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],

                                                       (byte >> 4) & 0x03, 2, 2);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       (byte >> 2) & 0x03, 2, 2);

                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],

                                                        byte & 0x03,       2, 2);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_SWF:

        adpcm_swf_decode(avctx, buf, buf_size, samples);

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    case AV_CODEC_ID_ADPCM_YAMAHA:

        for (n = nb_samples >> (1 - st); n > 0; n--) {

            int v = bytestream2_get_byteu(&gb);

            *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);

            *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4  );

        }

        break;

    case AV_CODEC_ID_ADPCM_AFC:

    {

        int samples_per_block;

        int blocks;



        if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {

            samples_per_block = avctx->extradata[0] / 16;

            blocks = nb_samples / avctx->extradata[0];

        } else {

            samples_per_block = nb_samples / 16;

            blocks = 1;

        }



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

        for (channel = 0; channel < avctx->channels; channel++) {

            int prev1 = c->status[channel].sample1;

            int prev2 = c->status[channel].sample2;



            samples = samples_p[channel] + m * 16;

            

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

                int byte = bytestream2_get_byteu(&gb);

                int scale = 1 << (byte >> 4);

                int index = byte & 0xf;

                int factor1 = ff_adpcm_afc_coeffs[0][index];

                int factor2 = ff_adpcm_afc_coeffs[1][index];



                

                for (n = 0; n < 16; n++) {

                    int32_t sampledat;



                    if (n & 1) {

                        sampledat = sign_extend(byte, 4);

                    } else {

                        byte = bytestream2_get_byteu(&gb);

                        sampledat = sign_extend(byte >> 4, 4);

                    }



                    sampledat = ((prev1 * factor1 + prev2 * factor2) +

                                 ((sampledat * scale) << 11)) >> 11;

                    *samples = av_clip_int16(sampledat);

                    prev2 = prev1;

                    prev1 = *samples++;

                }

            }



            c->status[channel].sample1 = prev1;

            c->status[channel].sample2 = prev2;

        }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_THP:

    {

        int table[6][16];

        int ch;



        for (i = 0; i < avctx->channels; i++)

            for (n = 0; n < 16; n++)

                table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);



        

        for (i = 0; i < avctx->channels; i++) {

            c->status[i].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16);

            c->status[i].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16);

        }



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

            samples = samples_p[ch];



            

            for (i = 0; i < nb_samples / 14; i++) {

                int byte = bytestream2_get_byteu(&gb);

                int index = (byte >> 4) & 7;

                unsigned int exp = byte & 0x0F;

                int factor1 = table[ch][index * 2];

                int factor2 = table[ch][index * 2 + 1];



                

                for (n = 0; n < 14; n++) {

                    int32_t sampledat;



                    if (n & 1) {

                        sampledat = sign_extend(byte, 4);

                    } else {

                        byte = bytestream2_get_byteu(&gb);

                        sampledat = sign_extend(byte >> 4, 4);

                    }



                    sampledat = ((c->status[ch].sample1 * factor1

                                + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp);

                    *samples = av_clip_int16(sampledat);

                    c->status[ch].sample2 = c->status[ch].sample1;

                    c->status[ch].sample1 = *samples++;

                }

            }

        }

        break;

    }



    default:

        return -1;

    }



    if (avpkt->size && bytestream2_tell(&gb) == 0) {

        av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");

        return AVERROR_INVALIDDATA;

    }



    *got_frame_ptr   = 1;

    *(AVFrame *)data = c->frame;



    return bytestream2_tell(&gb);

}

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;

    ADPCMDecodeContext *c = VAR_0->priv_data;

    ADPCMChannelStatus *cs;

    int VAR_6, VAR_7, VAR_49, VAR_9;

    short *VAR_10;

    int16_t **samples_p;

    int VAR_11; 

    int VAR_12, VAR_13;

    int VAR_14, VAR_15, VAR_16;

    GetByteContext gb;



    bytestream2_init(&gb, VAR_4, VAR_5);

    VAR_14 = get_nb_samples(VAR_0, &gb, VAR_5, &VAR_15);

    if (VAR_14 <= 0) {

        av_log(VAR_0, AV_LOG_ERROR, "invalid number of VAR_10 in packet\VAR_6");

        return AVERROR_INVALIDDATA;

    }



    

    c->frame.VAR_14 = VAR_14;

    if ((VAR_16 = ff_get_buffer(VAR_0, &c->frame)) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\VAR_6");

        return VAR_16;

    }

    VAR_10 = (short *)c->frame.VAR_1[0];

    samples_p = (int16_t **)c->frame.extended_data;



    

    

    if (VAR_15) {

        if (VAR_15 != VAR_14)

            av_log(VAR_0, AV_LOG_WARNING, "mismatch in coded sample VAR_49\VAR_6");

        c->frame.VAR_14 = VAR_14 = VAR_15;

    }



    VAR_11 = VAR_0->channels == 2 ? 1 : 0;



    switch(VAR_0->codec->id) {

    case AV_CODEC_ID_ADPCM_IMA_QT:

        



        for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

            int predictor;

            int step_index;

            cs = &(c->status[VAR_49]);

            



            

            predictor = sign_extend(bytestream2_get_be16u(&gb), 16);

            step_index = predictor & 0x7F;

            predictor &= ~0x7F;



            if (cs->step_index == step_index) {

                int diff = predictor - cs->predictor;

                if (diff < 0)

                    diff = - diff;

                if (diff > 0x7f)

                    goto update;

            } else {

            update:

                cs->step_index = step_index;

                cs->predictor = predictor;

            }



            if (cs->step_index > 88u){

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",

                       VAR_49, cs->step_index);

                return AVERROR_INVALIDDATA;

            }



            VAR_10 = samples_p[VAR_49];



            for (VAR_7 = 0; VAR_7 < 64; VAR_7 += 2) {

                int VAR_51 = bytestream2_get_byteu(&gb);

                VAR_10[VAR_7    ] = adpcm_ima_qt_expand_nibble(cs, VAR_51 & 0x0F, 3);

                VAR_10[VAR_7 + 1] = adpcm_ima_qt_expand_nibble(cs, VAR_51 >> 4  , 3);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_WAV:

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

            cs = &(c->status[VAR_9]);

            cs->predictor = samples_p[VAR_9][0] = sign_extend(bytestream2_get_le16u(&gb), 16);



            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",

                       VAR_9, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (VAR_6 = 0; VAR_6 < (VAR_14 - 1) / 8; VAR_6++) {

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

                cs = &c->status[VAR_9];

                VAR_10 = &samples_p[VAR_9][1 + VAR_6 * 8];

                for (VAR_7 = 0; VAR_7 < 8; VAR_7 += 2) {

                    int VAR_51 = bytestream2_get_byteu(&gb);

                    VAR_10[VAR_7    ] = adpcm_ima_expand_nibble(cs, VAR_51 & 0x0F, 3);

                    VAR_10[VAR_7 + 1] = adpcm_ima_expand_nibble(cs, VAR_51 >> 4  , 3);

                }

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_4XM:

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

            c->status[VAR_9].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);



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

            c->status[VAR_9].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (c->status[VAR_9].step_index > 88u) {

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",

                       VAR_9, c->status[VAR_9].step_index);

                return AVERROR_INVALIDDATA;

            }

        }



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

            VAR_10 = (int16_t *)c->frame.VAR_1[VAR_9];

            cs = &c->status[VAR_9];

            for (VAR_6 = VAR_14 >> 1; VAR_6 > 0; VAR_6--) {

                int VAR_51 = bytestream2_get_byteu(&gb);

                *VAR_10++ = adpcm_ima_expand_nibble(cs, VAR_51 & 0x0F, 4);

                *VAR_10++ = adpcm_ima_expand_nibble(cs, VAR_51 >> 4  , 4);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_MS:

    {

        int VAR_17;



        VAR_17 = bytestream2_get_byteu(&gb);

        if (VAR_17 > 6) {

            av_log(VAR_0, AV_LOG_ERROR, "ERROR: VAR_17[0] = %d\VAR_6",

                   VAR_17);

            return AVERROR_INVALIDDATA;

        }

        c->status[0].VAR_47 = ff_adpcm_AdaptCoeff1[VAR_17];

        c->status[0].VAR_48 = ff_adpcm_AdaptCoeff2[VAR_17];

        if (VAR_11) {

            VAR_17 = bytestream2_get_byteu(&gb);

            if (VAR_17 > 6) {

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: VAR_17[1] = %d\VAR_6",

                       VAR_17);

                return AVERROR_INVALIDDATA;

            }

            c->status[1].VAR_47 = ff_adpcm_AdaptCoeff1[VAR_17];

            c->status[1].VAR_48 = ff_adpcm_AdaptCoeff2[VAR_17];

        }

        c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (VAR_11){

            c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);

        }



        c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (VAR_11) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);

        if (VAR_11) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);



        *VAR_10++ = c->status[0].sample2;

        if (VAR_11) *VAR_10++ = c->status[1].sample2;

        *VAR_10++ = c->status[0].sample1;

        if (VAR_11) *VAR_10++ = c->status[1].sample1;

        for(VAR_6 = (VAR_14 - 2) >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_ms_expand_nibble(&c->status[0 ], VAR_51 >> 4  );

            *VAR_10++ = adpcm_ms_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F);

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_DK4:

        for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

            cs = &c->status[VAR_49];

            cs->predictor  = *VAR_10++ = sign_extend(bytestream2_get_le16u(&gb), 16);

            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",

                       VAR_49, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }

        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0 ], VAR_51 >> 4  , 3);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_DK3:

    {

        int VAR_20 = 0;

        int VAR_21;

        int VAR_22 = 0;

        int VAR_23;

        const int16_t *VAR_24 = VAR_10 + VAR_0->channels * VAR_14;



        bytestream2_skipu(&gb, 10);

        c->status[0].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[1].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].step_index = bytestream2_get_byteu(&gb);

        c->status[1].step_index = bytestream2_get_byteu(&gb);

        if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){

            av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index = %VAR_9/%VAR_9\VAR_6",

                   c->status[0].step_index, c->status[1].step_index);

            return AVERROR_INVALIDDATA;

        }

        

        VAR_23 = c->status[1].predictor;



        

#define DK3_GET_NEXT_NIBBLE() \

    if (VAR_22) { \

        VAR_21 = VAR_20 >> 4; \

        VAR_22 = 0; \

    } else { \

        VAR_20 = bytestream2_get_byteu(&gb); \

        VAR_21 = VAR_20 & 0x0F; \

        VAR_22 = 1; \

    }



        while (VAR_10 < VAR_24) {



            





            

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[0], VAR_21, 3);



            

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[1], VAR_21, 3);



            

            VAR_23 = (VAR_23 + c->status[1].predictor) / 2;

            *VAR_10++ = c->status[0].predictor + c->status[1].predictor;

            *VAR_10++ = c->status[0].predictor - c->status[1].predictor;



            

            DK3_GET_NEXT_NIBBLE();

            adpcm_ima_expand_nibble(&c->status[0], VAR_21, 3);



            

            VAR_23 = (VAR_23 + c->status[1].predictor) / 2;

            *VAR_10++ = c->status[0].predictor + c->status[1].predictor;

            *VAR_10++ = c->status[0].predictor - c->status[1].predictor;

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_ISS:

        for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

            cs = &c->status[VAR_49];

            cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);

            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);

            if (cs->step_index > 88u){

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",

                       VAR_49, cs->step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_25, VAR_26;

            int VAR_51 = bytestream2_get_byteu(&gb);

            

            if (VAR_11) {

                VAR_25 = VAR_51 >> 4;

                VAR_26 = VAR_51 & 0x0F;

            } else {

                VAR_26 = VAR_51 >> 4;

                VAR_25 = VAR_51 & 0x0F;

            }

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0 ], VAR_25, 3);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_26, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_APC:

        while (bytestream2_get_bytes_left(&gb) > 0) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0],  VAR_51 >> 4  , 3);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_OKI:

        while (bytestream2_get_bytes_left(&gb) > 0) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_ima_oki_expand_nibble(&c->status[0],  VAR_51 >> 4  );

            *VAR_10++ = adpcm_ima_oki_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_WS:

        if (c->vqa_version == 3) {

            for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

                int16_t *smp = samples_p[VAR_49];



                for (VAR_6 = VAR_14 / 2; VAR_6 > 0; VAR_6--) {

                    int VAR_51 = bytestream2_get_byteu(&gb);

                    *smp++ = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 >> 4  , 3);

                    *smp++ = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 & 0x0F, 3);

                }

            }

        } else {

            for (VAR_6 = VAR_14 / 2; VAR_6 > 0; VAR_6--) {

                for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

                    int VAR_51 = bytestream2_get_byteu(&gb);

                    *VAR_10++  = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 >> 4  , 3);

                    VAR_10[VAR_11] = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 & 0x0F, 3);

                }

                VAR_10 += VAR_0->channels;

            }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    case AV_CODEC_ID_ADPCM_XA:

    {

        int16_t *out0 = samples_p[0];

        int16_t *out1 = samples_p[1];

        int VAR_51 = 28 * (3 - VAR_0->channels) * 4;

        int VAR_28 = 0;

        while (bytestream2_get_bytes_left(&gb) >= 128) {

            if ((VAR_16 = xa_decode(VAR_0, out0, out1, VAR_4 + bytestream2_tell(&gb),

                                 &c->status[0], &c->status[1],

                                 VAR_0->channels, VAR_28)) < 0)

                return VAR_16;

            bytestream2_skipu(&gb, 128);

            VAR_28 += VAR_51;

        }

        break;

    }

    case AV_CODEC_ID_ADPCM_IMA_EA_EACS:

        for (VAR_9=0; VAR_9<=VAR_11; VAR_9++) {

            c->status[VAR_9].step_index = bytestream2_get_le32u(&gb);

            if (c->status[VAR_9].step_index > 88u) {

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",

                       VAR_9, c->status[VAR_9].step_index);

                return AVERROR_INVALIDDATA;

            }

        }

        for (VAR_9=0; VAR_9<=VAR_11; VAR_9++)

            c->status[VAR_9].predictor  = bytestream2_get_le32u(&gb);



        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51   = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0],  VAR_51 >> 4,   3);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:

        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0],  VAR_51 >> 4,   6);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 6);

        }

        break;

    case AV_CODEC_ID_ADPCM_EA:

    {

        int VAR_29, VAR_30;

        int VAR_31, VAR_32;

        int VAR_33, VAR_34;

        int VAR_35, VAR_36, VAR_37, VAR_38;

        int VAR_39, VAR_40;



        





        if(VAR_0->channels != 2)

            return AVERROR_INVALIDDATA;



        VAR_31   = sign_extend(bytestream2_get_le16u(&gb), 16);

        VAR_29  = sign_extend(bytestream2_get_le16u(&gb), 16);

        VAR_32  = sign_extend(bytestream2_get_le16u(&gb), 16);

        VAR_30 = sign_extend(bytestream2_get_le16u(&gb), 16);



        for (VAR_12 = 0; VAR_12 < VAR_14 / 28; VAR_12++) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            VAR_35 = ea_adpcm_table[ VAR_51 >> 4       ];

            VAR_36 = ea_adpcm_table[(VAR_51 >> 4  ) + 4];

            VAR_37 = ea_adpcm_table[ VAR_51 & 0x0F];

            VAR_38 = ea_adpcm_table[(VAR_51 & 0x0F) + 4];



            VAR_51 = bytestream2_get_byteu(&gb);

            VAR_39  = 20 - (VAR_51 >> 4);

            VAR_40 = 20 - (VAR_51 & 0x0F);



            for (VAR_13 = 0; VAR_13 < 28; VAR_13++) {

                VAR_51 = bytestream2_get_byteu(&gb);

                VAR_33  = sign_extend(VAR_51 >> 4, 4) << VAR_39;

                VAR_34 = sign_extend(VAR_51,      4) << VAR_40;



                VAR_33 = (VAR_33 +

                    (VAR_31 * VAR_35) +

                    (VAR_29 * VAR_36) + 0x80) >> 8;

                VAR_34 = (VAR_34 +

                    (VAR_32 * VAR_37) +

                    (VAR_30 * VAR_38) + 0x80) >> 8;



                VAR_29 = VAR_31;

                VAR_31 = av_clip_int16(VAR_33);

                VAR_30 = VAR_32;

                VAR_32 = av_clip_int16(VAR_34);

                *VAR_10++ = VAR_31;

                *VAR_10++ = VAR_32;

            }

        }



        bytestream2_skip(&gb, 2); 



        break;

    }

    case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:

    {

        int VAR_41[2][2], VAR_49[2];



        for(VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            for (VAR_9=0; VAR_9<2; VAR_9++)

                VAR_41[VAR_49][VAR_9] = ea_adpcm_table[(VAR_51 >> 4) + 4*VAR_9];

            VAR_49[VAR_49] = 20 - (VAR_51 & 0x0F);

        }

        for (VAR_12 = 0; VAR_12 < VAR_14 / 2; VAR_12++) {

            int VAR_51[2];



            VAR_51[0] = bytestream2_get_byteu(&gb);

            if (VAR_11) VAR_51[1] = bytestream2_get_byteu(&gb);

            for(VAR_9 = 4; VAR_9 >= 0; VAR_9-=4) { 

                for(VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

                    int sample = sign_extend(VAR_51[VAR_49] >> VAR_9, 4) << VAR_49[VAR_49];

                    sample = (sample +

                             c->status[VAR_49].sample1 * VAR_41[VAR_49][0] +

                             c->status[VAR_49].sample2 * VAR_41[VAR_49][1] + 0x80) >> 8;

                    c->status[VAR_49].sample2 = c->status[VAR_49].sample1;

                    c->status[VAR_49].sample1 = av_clip_int16(sample);

                    *VAR_10++ = c->status[VAR_49].sample1;

                }

            }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_EA_R1:

    case AV_CODEC_ID_ADPCM_EA_R2:

    case AV_CODEC_ID_ADPCM_EA_R3: {

        







        const int VAR_43 = VAR_0->codec->id == AV_CODEC_ID_ADPCM_EA_R3;

        int VAR_44, VAR_45, VAR_46;

        int VAR_47, VAR_48;

        int VAR_49;

        unsigned int VAR_49;

        uint16_t *samplesC;

        int VAR_49 = 0;

        int VAR_50[6];



        for (VAR_49=0; VAR_49<VAR_0->channels; VAR_49++)

            VAR_50[VAR_49] = (VAR_43 ? bytestream2_get_be32(&gb) :

                                             bytestream2_get_le32(&gb)) +

                               (VAR_0->channels + 1) * 4;



        for (VAR_49=0; VAR_49<VAR_0->channels; VAR_49++) {

            bytestream2_seek(&gb, VAR_50[VAR_49], SEEK_SET);

            samplesC = samples_p[VAR_49];



            if (VAR_0->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {

                VAR_45  = sign_extend(bytestream2_get_le16(&gb), 16);

                VAR_44 = sign_extend(bytestream2_get_le16(&gb), 16);

            } else {

                VAR_45  = c->status[VAR_49].predictor;

                VAR_44 = c->status[VAR_49].prev_sample;

            }



            for (VAR_12 = 0; VAR_12 < VAR_14 / 28; VAR_12++) {

                int VAR_51 = bytestream2_get_byte(&gb);

                if (VAR_51 == 0xEE) {  

                    VAR_45  = sign_extend(bytestream2_get_be16(&gb), 16);

                    VAR_44 = sign_extend(bytestream2_get_be16(&gb), 16);



                    for (VAR_13=0; VAR_13<28; VAR_13++)

                        *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);

                } else {

                    VAR_47 = ea_adpcm_table[ VAR_51 >> 4     ];

                    VAR_48 = ea_adpcm_table[(VAR_51 >> 4) + 4];

                    VAR_49 = 20 - (VAR_51 & 0x0F);



                    for (VAR_13=0; VAR_13<28; VAR_13++) {

                        if (VAR_13 & 1)

                            VAR_46 = sign_extend(VAR_51,    4) << VAR_49;

                        else {

                            VAR_51 = bytestream2_get_byte(&gb);

                            VAR_46 = sign_extend(VAR_51 >> 4, 4) << VAR_49;

                        }



                        VAR_46 += (VAR_45  * VAR_47) +

                                       (VAR_44 * VAR_48);

                        VAR_46 = av_clip_int16(VAR_46 >> 8);



                        VAR_44 = VAR_45;

                        VAR_45  = VAR_46;

                        *samplesC++ = VAR_45;

                    }

                }

            }

            if (!VAR_49) {

                VAR_49 = VAR_12;

            } else if (VAR_49 != VAR_12) {

                av_log(VAR_0, AV_LOG_WARNING, "per-VAR_49 sample VAR_49 mismatch\VAR_6");

                VAR_49 = FFMAX(VAR_49, VAR_12);

            }



            if (VAR_0->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {

                c->status[VAR_49].predictor   = VAR_45;

                c->status[VAR_49].prev_sample = VAR_44;

            }

        }



        c->frame.VAR_14 = VAR_49 * 28;

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_EA_XAS:

        for (VAR_49=0; VAR_49<VAR_0->channels; VAR_49++) {

            int VAR_41[2][4], VAR_49[4];

            int16_t *s = samples_p[VAR_49];

            for (VAR_6 = 0; VAR_6 < 4; VAR_6++, s += 32) {

                int val = sign_extend(bytestream2_get_le16u(&gb), 16);

                for (VAR_9=0; VAR_9<2; VAR_9++)

                    VAR_41[VAR_9][VAR_6] = ea_adpcm_table[(val&0x0F)+4*VAR_9];

                s[0] = val & ~0x0F;



                val = sign_extend(bytestream2_get_le16u(&gb), 16);

                VAR_49[VAR_6] = 20 - (val & 0x0F);

                s[1] = val & ~0x0F;

            }



            for (VAR_7=2; VAR_7<32; VAR_7+=2) {

                s = &samples_p[VAR_49][VAR_7];

                for (VAR_6 = 0; VAR_6 < 4; VAR_6++, s += 32) {

                    int level, pred;

                    int VAR_51 = bytestream2_get_byteu(&gb);



                    level = sign_extend(VAR_51 >> 4, 4) << VAR_49[VAR_6];

                    pred  = s[-1] * VAR_41[0][VAR_6] + s[-2] * VAR_41[1][VAR_6];

                    s[0]  = av_clip_int16((level + pred + 0x80) >> 8);



                    level = sign_extend(VAR_51, 4) << VAR_49[VAR_6];

                    pred  = s[0] * VAR_41[0][VAR_6] + s[-1] * VAR_41[1][VAR_6];

                    s[1]  = av_clip_int16((level + pred + 0x80) >> 8);

                }

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_AMV:

        c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);

        c->status[0].step_index = bytestream2_get_le16u(&gb);

        bytestream2_skipu(&gb, 4);

        if (c->status[0].step_index > 88u) {

            av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index = %VAR_9\VAR_6",

                   c->status[0].step_index);

            return AVERROR_INVALIDDATA;

        }



        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51 = bytestream2_get_byteu(&gb);



            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0], VAR_51 >> 4, 3);

            *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0], VAR_51 & 0xf, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_IMA_SMJPEG:

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

            c->status[VAR_9].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);

            c->status[VAR_9].step_index = bytestream2_get_byteu(&gb);

            bytestream2_skipu(&gb, 1);

            if (c->status[VAR_9].step_index > 88u) {

                av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index = %VAR_9\VAR_6",

                       c->status[VAR_9].step_index);

                return AVERROR_INVALIDDATA;

            }

        }



        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51 = bytestream2_get_byteu(&gb);



            *VAR_10++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], VAR_51 >> 4, 3);

            *VAR_10++ = adpcm_ima_qt_expand_nibble(&c->status[VAR_11], VAR_51 & 0xf, 3);

        }

        break;

    case AV_CODEC_ID_ADPCM_CT:

        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_ct_expand_nibble(&c->status[0 ], VAR_51 >> 4  );

            *VAR_10++ = adpcm_ct_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F);

        }

        break;

    case AV_CODEC_ID_ADPCM_SBPRO_4:

    case AV_CODEC_ID_ADPCM_SBPRO_3:

    case AV_CODEC_ID_ADPCM_SBPRO_2:

        if (!c->status[0].step_index) {

            

            *VAR_10++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);

            if (VAR_11)

                *VAR_10++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);

            c->status[0].step_index = 1;

            VAR_14--;

        }

        if (VAR_0->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {

            for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

                int VAR_51 = bytestream2_get_byteu(&gb);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       VAR_51 >> 4,   4, 0);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[VAR_11],

                                                       VAR_51 & 0x0F, 4, 0);

            }

        } else if (VAR_0->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {

            for (VAR_6 = VAR_14 / 3; VAR_6 > 0; VAR_6--) {

                int VAR_51 = bytestream2_get_byteu(&gb);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        VAR_51 >> 5        , 3, 0);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       (VAR_51 >> 2) & 0x07, 3, 0);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        VAR_51 & 0x03,       2, 0);

            }

        } else {

            for (VAR_6 = VAR_14 >> (2 - VAR_11); VAR_6 > 0; VAR_6--) {

                int VAR_51 = bytestream2_get_byteu(&gb);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                        VAR_51 >> 6        , 2, 2);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[VAR_11],

                                                       (VAR_51 >> 4) & 0x03, 2, 2);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],

                                                       (VAR_51 >> 2) & 0x03, 2, 2);

                *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[VAR_11],

                                                        VAR_51 & 0x03,       2, 2);

            }

        }

        break;

    case AV_CODEC_ID_ADPCM_SWF:

        adpcm_swf_decode(VAR_0, VAR_4, VAR_5, VAR_10);

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    case AV_CODEC_ID_ADPCM_YAMAHA:

        for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) {

            int VAR_51 = bytestream2_get_byteu(&gb);

            *VAR_10++ = adpcm_yamaha_expand_nibble(&c->status[0 ], VAR_51 & 0x0F);

            *VAR_10++ = adpcm_yamaha_expand_nibble(&c->status[VAR_11], VAR_51 >> 4  );

        }

        break;

    case AV_CODEC_ID_ADPCM_AFC:

    {

        int VAR_51;

        int VAR_51;



        if (VAR_0->extradata && VAR_0->extradata_size == 1 && VAR_0->extradata[0]) {

            VAR_51 = VAR_0->extradata[0] / 16;

            VAR_51 = VAR_14 / VAR_0->extradata[0];

        } else {

            VAR_51 = VAR_14 / 16;

            VAR_51 = 1;

        }



        for (VAR_7 = 0; VAR_7 < VAR_51; VAR_7++) {

        for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) {

            int prev1 = c->status[VAR_49].sample1;

            int prev2 = c->status[VAR_49].sample2;



            VAR_10 = samples_p[VAR_49] + VAR_7 * 16;

            

            for (VAR_9 = 0; VAR_9 < VAR_51; VAR_9++) {

                int VAR_51 = bytestream2_get_byteu(&gb);

                int scale = 1 << (VAR_51 >> 4);

                int index = VAR_51 & 0xf;

                int factor1 = ff_adpcm_afc_coeffs[0][index];

                int factor2 = ff_adpcm_afc_coeffs[1][index];



                

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

                    int32_t sampledat;



                    if (VAR_6 & 1) {

                        sampledat = sign_extend(VAR_51, 4);

                    } else {

                        VAR_51 = bytestream2_get_byteu(&gb);

                        sampledat = sign_extend(VAR_51 >> 4, 4);

                    }



                    sampledat = ((prev1 * factor1 + prev2 * factor2) +

                                 ((sampledat * scale) << 11)) >> 11;

                    *VAR_10 = av_clip_int16(sampledat);

                    prev2 = prev1;

                    prev1 = *VAR_10++;

                }

            }



            c->status[VAR_49].sample1 = prev1;

            c->status[VAR_49].sample2 = prev2;

        }

        }

        bytestream2_seek(&gb, 0, SEEK_END);

        break;

    }

    case AV_CODEC_ID_ADPCM_THP:

    {

        int VAR_52[6][16];

        int VAR_53;



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

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

                VAR_52[VAR_9][VAR_6] = sign_extend(bytestream2_get_be16u(&gb), 16);



        

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

            c->status[VAR_9].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16);

            c->status[VAR_9].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16);

        }



        for (VAR_53 = 0; VAR_53 < VAR_0->channels; VAR_53++) {

            VAR_10 = samples_p[VAR_53];



            

            for (VAR_9 = 0; VAR_9 < VAR_14 / 14; VAR_9++) {

                int VAR_51 = bytestream2_get_byteu(&gb);

                int index = (VAR_51 >> 4) & 7;

                unsigned int exp = VAR_51 & 0x0F;

                int factor1 = VAR_52[VAR_53][index * 2];

                int factor2 = VAR_52[VAR_53][index * 2 + 1];



                

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

                    int32_t sampledat;



                    if (VAR_6 & 1) {

                        sampledat = sign_extend(VAR_51, 4);

                    } else {

                        VAR_51 = bytestream2_get_byteu(&gb);

                        sampledat = sign_extend(VAR_51 >> 4, 4);

                    }



                    sampledat = ((c->status[VAR_53].sample1 * factor1

                                + c->status[VAR_53].sample2 * factor2) >> 11) + (sampledat << exp);

                    *VAR_10 = av_clip_int16(sampledat);

                    c->status[VAR_53].sample2 = c->status[VAR_53].sample1;

                    c->status[VAR_53].sample1 = *VAR_10++;

                }

            }

        }

        break;

    }



    default:

        return -1;

    }



    if (VAR_3->size && bytestream2_tell(&gb) == 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Nothing consumed\VAR_6");

        return AVERROR_INVALIDDATA;

    }



    *VAR_2   = 1;

    *(AVFrame *)VAR_1 = c->frame;



    return bytestream2_tell(&gb);

}

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; ADPCMDecodeContext *c = VAR_0->priv_data; ADPCMChannelStatus *cs; int VAR_6, VAR_7, VAR_49, VAR_9; short *VAR_10; int16_t **samples_p; int VAR_11; int VAR_12, VAR_13; int VAR_14, VAR_15, VAR_16; GetByteContext gb; bytestream2_init(&gb, VAR_4, VAR_5); VAR_14 = get_nb_samples(VAR_0, &gb, VAR_5, &VAR_15); if (VAR_14 <= 0) { av_log(VAR_0, AV_LOG_ERROR, "invalid number of VAR_10 in packet\VAR_6"); return AVERROR_INVALIDDATA; } c->frame.VAR_14 = VAR_14; if ((VAR_16 = ff_get_buffer(VAR_0, &c->frame)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\VAR_6"); return VAR_16; } VAR_10 = (short *)c->frame.VAR_1[0]; samples_p = (int16_t **)c->frame.extended_data; if (VAR_15) { if (VAR_15 != VAR_14)
av_log(VAR_0, AV_LOG_WARNING, "mismatch in coded sample VAR_49\VAR_6"); c->frame.VAR_14 = VAR_14 = VAR_15; } VAR_11 = VAR_0->channels == 2 ? 1 : 0; switch(VAR_0->codec->id) { case AV_CODEC_ID_ADPCM_IMA_QT:
for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { int predictor; int step_index; cs = &(c->status[VAR_49]); predictor = sign_extend(bytestream2_get_be16u(&gb), 16); step_index = predictor & 0x7F; predictor &= ~0x7F; if (cs->step_index == step_index) { int diff = predictor - cs->predictor; if (diff < 0)
diff = - diff; if (diff > 0x7f)
goto update; } else { update:
cs->step_index = step_index; cs->predictor = predictor; } if (cs->step_index > 88u){ av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",
VAR_49, cs->step_index); return AVERROR_INVALIDDATA; } VAR_10 = samples_p[VAR_49]; for (VAR_7 = 0; VAR_7 < 64; VAR_7 += 2) { int VAR_51 = bytestream2_get_byteu(&gb); VAR_10[VAR_7    ] = adpcm_ima_qt_expand_nibble(cs, VAR_51 & 0x0F, 3); VAR_10[VAR_7 + 1] = adpcm_ima_qt_expand_nibble(cs, VAR_51 >> 4  , 3); } } break; case AV_CODEC_ID_ADPCM_IMA_WAV:
for(VAR_9=0; VAR_9<VAR_0->channels; VAR_9++){ cs = &(c->status[VAR_9]); cs->predictor = samples_p[VAR_9][0] = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (cs->step_index > 88u){ av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",
VAR_9, cs->step_index); return AVERROR_INVALIDDATA; } } for (VAR_6 = 0; VAR_6 < (VAR_14 - 1) / 8; VAR_6++) { for (VAR_9 = 0; VAR_9 < VAR_0->channels; VAR_9++) { cs = &c->status[VAR_9]; VAR_10 = &samples_p[VAR_9][1 + VAR_6 * 8]; for (VAR_7 = 0; VAR_7 < 8; VAR_7 += 2) { int VAR_51 = bytestream2_get_byteu(&gb); VAR_10[VAR_7    ] = adpcm_ima_expand_nibble(cs, VAR_51 & 0x0F, 3); VAR_10[VAR_7 + 1] = adpcm_ima_expand_nibble(cs, VAR_51 >> 4  , 3); } } } break; case AV_CODEC_ID_ADPCM_4XM:
for (VAR_9 = 0; VAR_9 < VAR_0->channels; VAR_9++) c->status[VAR_9].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); for (VAR_9 = 0; VAR_9 < VAR_0->channels; VAR_9++) { c->status[VAR_9].step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (c->status[VAR_9].step_index > 88u) { av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",
VAR_9, c->status[VAR_9].step_index); return AVERROR_INVALIDDATA; } } for (VAR_9 = 0; VAR_9 < VAR_0->channels; VAR_9++) { VAR_10 = (int16_t *)c->frame.VAR_1[VAR_9]; cs = &c->status[VAR_9]; for (VAR_6 = VAR_14 >> 1; VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_expand_nibble(cs, VAR_51 & 0x0F, 4); *VAR_10++ = adpcm_ima_expand_nibble(cs, VAR_51 >> 4  , 4); } } break; case AV_CODEC_ID_ADPCM_MS:
{ int VAR_17; VAR_17 = bytestream2_get_byteu(&gb); if (VAR_17 > 6) { av_log(VAR_0, AV_LOG_ERROR, "ERROR: VAR_17[0] = %d\VAR_6",
VAR_17); return AVERROR_INVALIDDATA; } c->status[0].VAR_47 = ff_adpcm_AdaptCoeff1[VAR_17]; c->status[0].VAR_48 = ff_adpcm_AdaptCoeff2[VAR_17]; if (VAR_11) { VAR_17 = bytestream2_get_byteu(&gb); if (VAR_17 > 6) { av_log(VAR_0, AV_LOG_ERROR, "ERROR: VAR_17[1] = %d\VAR_6",
VAR_17); return AVERROR_INVALIDDATA; } c->status[1].VAR_47 = ff_adpcm_AdaptCoeff1[VAR_17]; c->status[1].VAR_48 = ff_adpcm_AdaptCoeff2[VAR_17]; } c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16); if (VAR_11){ c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16); } c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16); if (VAR_11) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16); if (VAR_11) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16); *VAR_10++ = c->status[0].sample2; if (VAR_11) *VAR_10++ = c->status[1].sample2; *VAR_10++ = c->status[0].sample1; if (VAR_11) *VAR_10++ = c->status[1].sample1; for(VAR_6 = (VAR_14 - 2) >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ms_expand_nibble(&c->status[0 ], VAR_51 >> 4  ); *VAR_10++ = adpcm_ms_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F); } break; } case AV_CODEC_ID_ADPCM_IMA_DK4:
for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { cs = &c->status[VAR_49]; cs->predictor  = *VAR_10++ = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (cs->step_index > 88u){ av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",
VAR_49, cs->step_index); return AVERROR_INVALIDDATA; } } for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0 ], VAR_51 >> 4  , 3); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 3); } break; case AV_CODEC_ID_ADPCM_IMA_DK3:
{ int VAR_20 = 0; int VAR_21; int VAR_22 = 0; int VAR_23; const int16_t *VAR_24 = VAR_10 + VAR_0->channels * VAR_14; bytestream2_skipu(&gb, 10); c->status[0].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[1].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[0].step_index = bytestream2_get_byteu(&gb); c->status[1].step_index = bytestream2_get_byteu(&gb); if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){ av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index = %VAR_9/%VAR_9\VAR_6",
c->status[0].step_index, c->status[1].step_index); return AVERROR_INVALIDDATA; } VAR_23 = c->status[1].predictor; #define DK3_GET_NEXT_NIBBLE() \
if (VAR_22) { \ VAR_21 = VAR_20 >> 4; \ VAR_22 = 0; \ } else { \ VAR_20 = bytestream2_get_byteu(&gb); \ VAR_21 = VAR_20 & 0x0F; \ VAR_22 = 1; \ } while (VAR_10 < VAR_24) { DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[0], VAR_21, 3); DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[1], VAR_21, 3); VAR_23 = (VAR_23 + c->status[1].predictor) / 2; *VAR_10++ = c->status[0].predictor + c->status[1].predictor; *VAR_10++ = c->status[0].predictor - c->status[1].predictor; DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[0], VAR_21, 3); VAR_23 = (VAR_23 + c->status[1].predictor) / 2; *VAR_10++ = c->status[0].predictor + c->status[1].predictor; *VAR_10++ = c->status[0].predictor - c->status[1].predictor; } break; } case AV_CODEC_ID_ADPCM_IMA_ISS:
for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { cs = &c->status[VAR_49]; cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (cs->step_index > 88u){ av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",
VAR_49, cs->step_index); return AVERROR_INVALIDDATA; } } for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_25, VAR_26; int VAR_51 = bytestream2_get_byteu(&gb); if (VAR_11) { VAR_25 = VAR_51 >> 4; VAR_26 = VAR_51 & 0x0F; } else { VAR_26 = VAR_51 >> 4; VAR_25 = VAR_51 & 0x0F; } *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0 ], VAR_25, 3); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_26, 3); } break; case AV_CODEC_ID_ADPCM_IMA_APC:
while (bytestream2_get_bytes_left(&gb) > 0) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0],  VAR_51 >> 4  , 3); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 3); } break; case AV_CODEC_ID_ADPCM_IMA_OKI:
while (bytestream2_get_bytes_left(&gb) > 0) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_oki_expand_nibble(&c->status[0],  VAR_51 >> 4  ); *VAR_10++ = adpcm_ima_oki_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F); } break; case AV_CODEC_ID_ADPCM_IMA_WS:
if (c->vqa_version == 3) { for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { int16_t *smp = samples_p[VAR_49]; for (VAR_6 = VAR_14 / 2; VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *smp++ = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 >> 4  , 3); *smp++ = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 & 0x0F, 3); } } } else { for (VAR_6 = VAR_14 / 2; VAR_6 > 0; VAR_6--) { for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++  = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 >> 4  , 3); VAR_10[VAR_11] = adpcm_ima_expand_nibble(&c->status[VAR_49], VAR_51 & 0x0F, 3); } VAR_10 += VAR_0->channels; } } bytestream2_seek(&gb, 0, SEEK_END); break; case AV_CODEC_ID_ADPCM_XA:
{ int16_t *out0 = samples_p[0]; int16_t *out1 = samples_p[1]; int VAR_51 = 28 * (3 - VAR_0->channels) * 4; int VAR_28 = 0; while (bytestream2_get_bytes_left(&gb) >= 128) { if ((VAR_16 = xa_decode(VAR_0, out0, out1, VAR_4 + bytestream2_tell(&gb),
&c->status[0], &c->status[1],
VAR_0->channels, VAR_28)) < 0)
return VAR_16; bytestream2_skipu(&gb, 128); VAR_28 += VAR_51; } break; } case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
for (VAR_9=0; VAR_9<=VAR_11; VAR_9++) { c->status[VAR_9].step_index = bytestream2_get_le32u(&gb); if (c->status[VAR_9].step_index > 88u) { av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index[%d] = %VAR_9\VAR_6",
VAR_9, c->status[VAR_9].step_index); return AVERROR_INVALIDDATA; } } for (VAR_9=0; VAR_9<=VAR_11; VAR_9++) c->status[VAR_9].predictor  = bytestream2_get_le32u(&gb); for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51   = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0],  VAR_51 >> 4,   3); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 3); } break; case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0],  VAR_51 >> 4,   6); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F, 6); } break; case AV_CODEC_ID_ADPCM_EA:
{ int VAR_29, VAR_30; int VAR_31, VAR_32; int VAR_33, VAR_34; int VAR_35, VAR_36, VAR_37, VAR_38; int VAR_39, VAR_40; if(VAR_0->channels != 2)
return AVERROR_INVALIDDATA; VAR_31   = sign_extend(bytestream2_get_le16u(&gb), 16); VAR_29  = sign_extend(bytestream2_get_le16u(&gb), 16); VAR_32  = sign_extend(bytestream2_get_le16u(&gb), 16); VAR_30 = sign_extend(bytestream2_get_le16u(&gb), 16); for (VAR_12 = 0; VAR_12 < VAR_14 / 28; VAR_12++) { int VAR_51 = bytestream2_get_byteu(&gb); VAR_35 = ea_adpcm_table[ VAR_51 >> 4       ]; VAR_36 = ea_adpcm_table[(VAR_51 >> 4  ) + 4]; VAR_37 = ea_adpcm_table[ VAR_51 & 0x0F]; VAR_38 = ea_adpcm_table[(VAR_51 & 0x0F) + 4]; VAR_51 = bytestream2_get_byteu(&gb); VAR_39  = 20 - (VAR_51 >> 4); VAR_40 = 20 - (VAR_51 & 0x0F); for (VAR_13 = 0; VAR_13 < 28; VAR_13++) { VAR_51 = bytestream2_get_byteu(&gb); VAR_33  = sign_extend(VAR_51 >> 4, 4) << VAR_39; VAR_34 = sign_extend(VAR_51,      4) << VAR_40; VAR_33 = (VAR_33 +
(VAR_31 * VAR_35) +
(VAR_29 * VAR_36) + 0x80) >> 8; VAR_34 = (VAR_34 +
(VAR_32 * VAR_37) +
(VAR_30 * VAR_38) + 0x80) >> 8; VAR_29 = VAR_31; VAR_31 = av_clip_int16(VAR_33); VAR_30 = VAR_32; VAR_32 = av_clip_int16(VAR_34); *VAR_10++ = VAR_31; *VAR_10++ = VAR_32; } } bytestream2_skip(&gb, 2); break; } case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
{ int VAR_41[2][2], VAR_49[2]; for(VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { int VAR_51 = bytestream2_get_byteu(&gb); for (VAR_9=0; VAR_9<2; VAR_9++) VAR_41[VAR_49][VAR_9] = ea_adpcm_table[(VAR_51 >> 4) + 4*VAR_9]; VAR_49[VAR_49] = 20 - (VAR_51 & 0x0F); } for (VAR_12 = 0; VAR_12 < VAR_14 / 2; VAR_12++) { int VAR_51[2]; VAR_51[0] = bytestream2_get_byteu(&gb); if (VAR_11) VAR_51[1] = bytestream2_get_byteu(&gb); for(VAR_9 = 4; VAR_9 >= 0; VAR_9-=4) { for(VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { int sample = sign_extend(VAR_51[VAR_49] >> VAR_9, 4) << VAR_49[VAR_49]; sample = (sample +
c->status[VAR_49].sample1 * VAR_41[VAR_49][0] +
c->status[VAR_49].sample2 * VAR_41[VAR_49][1] + 0x80) >> 8; c->status[VAR_49].sample2 = c->status[VAR_49].sample1; c->status[VAR_49].sample1 = av_clip_int16(sample); *VAR_10++ = c->status[VAR_49].sample1; } } } bytestream2_seek(&gb, 0, SEEK_END); break; } case AV_CODEC_ID_ADPCM_EA_R1:
case AV_CODEC_ID_ADPCM_EA_R2:
case AV_CODEC_ID_ADPCM_EA_R3: { const int VAR_43 = VAR_0->codec->id == AV_CODEC_ID_ADPCM_EA_R3; int VAR_44, VAR_45, VAR_46; int VAR_47, VAR_48; int VAR_49; unsigned int VAR_49; uint16_t *samplesC; int VAR_49 = 0; int VAR_50[6]; for (VAR_49=0; VAR_49<VAR_0->channels; VAR_49++) VAR_50[VAR_49] = (VAR_43 ? bytestream2_get_be32(&gb) :
bytestream2_get_le32(&gb)) +
(VAR_0->channels + 1) * 4; for (VAR_49=0; VAR_49<VAR_0->channels; VAR_49++) { bytestream2_seek(&gb, VAR_50[VAR_49], SEEK_SET); samplesC = samples_p[VAR_49]; if (VAR_0->codec->id == AV_CODEC_ID_ADPCM_EA_R1) { VAR_45  = sign_extend(bytestream2_get_le16(&gb), 16); VAR_44 = sign_extend(bytestream2_get_le16(&gb), 16); } else { VAR_45  = c->status[VAR_49].predictor; VAR_44 = c->status[VAR_49].prev_sample; } for (VAR_12 = 0; VAR_12 < VAR_14 / 28; VAR_12++) { int VAR_51 = bytestream2_get_byte(&gb); if (VAR_51 == 0xEE) { VAR_45  = sign_extend(bytestream2_get_be16(&gb), 16); VAR_44 = sign_extend(bytestream2_get_be16(&gb), 16); for (VAR_13=0; VAR_13<28; VAR_13++) *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16); } else { VAR_47 = ea_adpcm_table[ VAR_51 >> 4     ]; VAR_48 = ea_adpcm_table[(VAR_51 >> 4) + 4]; VAR_49 = 20 - (VAR_51 & 0x0F); for (VAR_13=0; VAR_13<28; VAR_13++) { if (VAR_13 & 1)
VAR_46 = sign_extend(VAR_51,    4) << VAR_49; else { VAR_51 = bytestream2_get_byte(&gb); VAR_46 = sign_extend(VAR_51 >> 4, 4) << VAR_49; } VAR_46 += (VAR_45  * VAR_47) +
(VAR_44 * VAR_48); VAR_46 = av_clip_int16(VAR_46 >> 8); VAR_44 = VAR_45; VAR_45  = VAR_46; *samplesC++ = VAR_45; } } } if (!VAR_49) { VAR_49 = VAR_12; } else if (VAR_49 != VAR_12) { av_log(VAR_0, AV_LOG_WARNING, "per-VAR_49 sample VAR_49 mismatch\VAR_6"); VAR_49 = FFMAX(VAR_49, VAR_12); } if (VAR_0->codec->id != AV_CODEC_ID_ADPCM_EA_R1) { c->status[VAR_49].predictor   = VAR_45; c->status[VAR_49].prev_sample = VAR_44; } } c->frame.VAR_14 = VAR_49 * 28; bytestream2_seek(&gb, 0, SEEK_END); break; } case AV_CODEC_ID_ADPCM_EA_XAS:
for (VAR_49=0; VAR_49<VAR_0->channels; VAR_49++) { int VAR_41[2][4], VAR_49[4]; int16_t *s = samples_p[VAR_49]; for (VAR_6 = 0; VAR_6 < 4; VAR_6++, s += 32) { int val = sign_extend(bytestream2_get_le16u(&gb), 16); for (VAR_9=0; VAR_9<2; VAR_9++) VAR_41[VAR_9][VAR_6] = ea_adpcm_table[(val&0x0F)+4*VAR_9]; s[0] = val & ~0x0F; val = sign_extend(bytestream2_get_le16u(&gb), 16); VAR_49[VAR_6] = 20 - (val & 0x0F); s[1] = val & ~0x0F; } for (VAR_7=2; VAR_7<32; VAR_7+=2) { s = &samples_p[VAR_49][VAR_7]; for (VAR_6 = 0; VAR_6 < 4; VAR_6++, s += 32) { int level, pred; int VAR_51 = bytestream2_get_byteu(&gb); level = sign_extend(VAR_51 >> 4, 4) << VAR_49[VAR_6]; pred  = s[-1] * VAR_41[0][VAR_6] + s[-2] * VAR_41[1][VAR_6]; s[0]  = av_clip_int16((level + pred + 0x80) >> 8); level = sign_extend(VAR_51, 4) << VAR_49[VAR_6]; pred  = s[0] * VAR_41[0][VAR_6] + s[-1] * VAR_41[1][VAR_6]; s[1]  = av_clip_int16((level + pred + 0x80) >> 8); } } } break; case AV_CODEC_ID_ADPCM_IMA_AMV:
c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[0].step_index = bytestream2_get_le16u(&gb); bytestream2_skipu(&gb, 4); if (c->status[0].step_index > 88u) { av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index = %VAR_9\VAR_6",
c->status[0].step_index); return AVERROR_INVALIDDATA; } for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0], VAR_51 >> 4, 3); *VAR_10++ = adpcm_ima_expand_nibble(&c->status[0], VAR_51 & 0xf, 3); } break; case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
for (VAR_9 = 0; VAR_9 < VAR_0->channels; VAR_9++) { c->status[VAR_9].predictor = sign_extend(bytestream2_get_be16u(&gb), 16); c->status[VAR_9].step_index = bytestream2_get_byteu(&gb); bytestream2_skipu(&gb, 1); if (c->status[VAR_9].step_index > 88u) { av_log(VAR_0, AV_LOG_ERROR, "ERROR: step_index = %VAR_9\VAR_6",
c->status[VAR_9].step_index); return AVERROR_INVALIDDATA; } } for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], VAR_51 >> 4, 3); *VAR_10++ = adpcm_ima_qt_expand_nibble(&c->status[VAR_11], VAR_51 & 0xf, 3); } break; case AV_CODEC_ID_ADPCM_CT:
for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_ct_expand_nibble(&c->status[0 ], VAR_51 >> 4  ); *VAR_10++ = adpcm_ct_expand_nibble(&c->status[VAR_11], VAR_51 & 0x0F); } break; case AV_CODEC_ID_ADPCM_SBPRO_4:
case AV_CODEC_ID_ADPCM_SBPRO_3:
case AV_CODEC_ID_ADPCM_SBPRO_2:
if (!c->status[0].step_index) { *VAR_10++ = 128 * (bytestream2_get_byteu(&gb) - 0x80); if (VAR_11)
*VAR_10++ = 128 * (bytestream2_get_byteu(&gb) - 0x80); c->status[0].step_index = 1; VAR_14--; } if (VAR_0->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) { for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],
VAR_51 >> 4,   4, 0); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[VAR_11],
VAR_51 & 0x0F, 4, 0); } } else if (VAR_0->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) { for (VAR_6 = VAR_14 / 3; VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],
VAR_51 >> 5        , 3, 0); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],
(VAR_51 >> 2) & 0x07, 3, 0); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],
VAR_51 & 0x03,       2, 0); } } else { for (VAR_6 = VAR_14 >> (2 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],
VAR_51 >> 6        , 2, 2); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[VAR_11],
(VAR_51 >> 4) & 0x03, 2, 2); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[0],
(VAR_51 >> 2) & 0x03, 2, 2); *VAR_10++ = adpcm_sbpro_expand_nibble(&c->status[VAR_11],
VAR_51 & 0x03,       2, 2); } } break; case AV_CODEC_ID_ADPCM_SWF:
adpcm_swf_decode(VAR_0, VAR_4, VAR_5, VAR_10); bytestream2_seek(&gb, 0, SEEK_END); break; case AV_CODEC_ID_ADPCM_YAMAHA:
for (VAR_6 = VAR_14 >> (1 - VAR_11); VAR_6 > 0; VAR_6--) { int VAR_51 = bytestream2_get_byteu(&gb); *VAR_10++ = adpcm_yamaha_expand_nibble(&c->status[0 ], VAR_51 & 0x0F); *VAR_10++ = adpcm_yamaha_expand_nibble(&c->status[VAR_11], VAR_51 >> 4  ); } break; case AV_CODEC_ID_ADPCM_AFC:
{ int VAR_51; int VAR_51; if (VAR_0->extradata && VAR_0->extradata_size == 1 && VAR_0->extradata[0]) { VAR_51 = VAR_0->extradata[0] / 16; VAR_51 = VAR_14 / VAR_0->extradata[0]; } else { VAR_51 = VAR_14 / 16; VAR_51 = 1; } for (VAR_7 = 0; VAR_7 < VAR_51; VAR_7++) { for (VAR_49 = 0; VAR_49 < VAR_0->channels; VAR_49++) { int prev1 = c->status[VAR_49].sample1; int prev2 = c->status[VAR_49].sample2; VAR_10 = samples_p[VAR_49] + VAR_7 * 16; for (VAR_9 = 0; VAR_9 < VAR_51; VAR_9++) { int VAR_51 = bytestream2_get_byteu(&gb); int scale = 1 << (VAR_51 >> 4); int index = VAR_51 & 0xf; int factor1 = ff_adpcm_afc_coeffs[0][index]; int factor2 = ff_adpcm_afc_coeffs[1][index]; for (VAR_6 = 0; VAR_6 < 16; VAR_6++) { int32_t sampledat; if (VAR_6 & 1) { sampledat = sign_extend(VAR_51, 4); } else { VAR_51 = bytestream2_get_byteu(&gb); sampledat = sign_extend(VAR_51 >> 4, 4); } sampledat = ((prev1 * factor1 + prev2 * factor2) +
((sampledat * scale) << 11)) >> 11; *VAR_10 = av_clip_int16(sampledat); prev2 = prev1; prev1 = *VAR_10++; } } c->status[VAR_49].sample1 = prev1; c->status[VAR_49].sample2 = prev2; } } bytestream2_seek(&gb, 0, SEEK_END); break; } case AV_CODEC_ID_ADPCM_THP:
{ int VAR_52[6][16]; int VAR_53; for (VAR_9 = 0; VAR_9 < VAR_0->channels; VAR_9++) for (VAR_6 = 0; VAR_6 < 16; VAR_6++) VAR_52[VAR_9][VAR_6] = sign_extend(bytestream2_get_be16u(&gb), 16); for (VAR_9 = 0; VAR_9 < VAR_0->channels; VAR_9++) { c->status[VAR_9].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16); c->status[VAR_9].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16); } for (VAR_53 = 0; VAR_53 < VAR_0->channels; VAR_53++) { VAR_10 = samples_p[VAR_53]; for (VAR_9 = 0; VAR_9 < VAR_14 / 14; VAR_9++) { int VAR_51 = bytestream2_get_byteu(&gb); int index = (VAR_51 >> 4) & 7; unsigned int exp = VAR_51 & 0x0F; int factor1 = VAR_52[VAR_53][index * 2]; int factor2 = VAR_52[VAR_53][index * 2 + 1]; for (VAR_6 = 0; VAR_6 < 14; VAR_6++) { int32_t sampledat; if (VAR_6 & 1) { sampledat = sign_extend(VAR_51, 4); } else { VAR_51 = bytestream2_get_byteu(&gb); sampledat = sign_extend(VAR_51 >> 4, 4); } sampledat = ((c->status[VAR_53].sample1 * factor1
+ c->status[VAR_53].sample2 * factor2) >> 11) + (sampledat << exp); *VAR_10 = av_clip_int16(sampledat); c->status[VAR_53].sample2 = c->status[VAR_53].sample1; c->status[VAR_53].sample1 = *VAR_10++; } } } break; } default:
return -1; } if (VAR_3->size && bytestream2_tell(&gb) == 0) { av_log(VAR_0, AV_LOG_ERROR, "Nothing consumed\VAR_6"); return AVERROR_INVALIDDATA; } *VAR_2   = 1; *(AVFrame *)VAR_1 = c->frame; return bytestream2_tell(&gb); }