libavcodec/adpcm.c:1124: error: Uninitialized Value
  The value read from shift[_] was never initialized.

libavcodec/adpcm.c:1124:21: 
1122.                     int byte = bytestream2_get_byteu(&gb);
1123. 
1124.                     level = sign_extend(byte >> 4, 4) << shift[n];
                          ^
1125.                     pred  = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
1126.                     s[0]  = av_clip_int16((level + pred + 0x80) >> 8);

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 = avctx->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_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;
        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:
    case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
        if (avctx->codec->id == 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);
        } else {
            c->status[0].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
            c->status[0].step_index = bytestream2_get_byteu(&gb);
            bytestream2_skipu(&gb, 1);
        }
        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 hi, lo, v = bytestream2_get_byteu(&gb);
            if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_AMV) {
                hi = v & 0x0F;
                lo = v >> 4;
            } else {
                lo = v & 0x0F;
                hi = v >> 4;
            }
            *samples++ = adpcm_ima_expand_nibble(&c->status[0], lo, 3);
            *samples++ = adpcm_ima_expand_nibble(&c->status[0], hi, 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_THP:
    {
        int table[2][16];
        int prev[2][2];
        int ch;
        for (i = 0; i < 2; i++)
            for (n = 0; n < 16; n++)
                table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);
        for (i = 0; i < 2; i++)
            for (n = 0; n < 2; n++)
                prev[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);
        for (ch = 0; ch <= st; 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 = ((prev[ch][0]*factor1
                                + prev[ch][1]*factor2) >> 11) + (sampledat << exp);
                    *samples = av_clip_int16(sampledat);
                    prev[ch][1] = prev[ch][0];
                    prev[ch][0] = *samples++;
                }
            }
        }
        break;
    }
    default:
        return -1;
    }
    *got_frame_ptr   = 1;
    *(AVFrame *)data = c->frame;
    return bytestream2_tell(&gb);
}
['static int adpcm_decode_frame(AVCodecContext *avctx, void *data,\n                              int *got_frame_ptr, AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size = avpkt->size;\n    ADPCMDecodeContext *c = avctx->priv_data;\n    ADPCMChannelStatus *cs;\n    int n, m, channel, i;\n    short *samples;\n    int16_t **samples_p;\n    int st;\n    int count1, count2;\n    int nb_samples, coded_samples, ret;\n    GetByteContext gb;\n    bytestream2_init(&gb, buf, buf_size);\n    nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples);\n    if (nb_samples <= 0) {\n        av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    c->frame.nb_samples = nb_samples;\n    if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n        return ret;\n    }\n    samples = (short *)c->frame.data[0];\n    samples_p = (int16_t **)c->frame.extended_data;\n    if (coded_samples) {\n        if (coded_samples != nb_samples)\n            av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\\n");\n        c->frame.nb_samples = nb_samples = coded_samples;\n    }\n    st = avctx->channels == 2 ? 1 : 0;\n    switch(avctx->codec->id) {\n    case AV_CODEC_ID_ADPCM_IMA_QT:\n        for (channel = 0; channel < avctx->channels; channel++) {\n            int predictor;\n            int step_index;\n            cs = &(c->status[channel]);\n            predictor = sign_extend(bytestream2_get_be16u(&gb), 16);\n            step_index = predictor & 0x7F;\n            predictor &= ~0x7F;\n            if (cs->step_index == step_index) {\n                int diff = predictor - cs->predictor;\n                if (diff < 0)\n                    diff = - diff;\n                if (diff > 0x7f)\n                    goto update;\n            } else {\n            update:\n                cs->step_index = step_index;\n                cs->predictor = predictor;\n            }\n            if (cs->step_index > 88u){\n                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\\n",\n                       channel, cs->step_index);\n                return AVERROR_INVALIDDATA;\n            }\n            samples = samples_p[channel];\n            for (m = 0; m < 64; m += 2) {\n                int byte = bytestream2_get_byteu(&gb);\n                samples[m    ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);\n                samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4  , 3);\n            }\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_IMA_WAV:\n        for(i=0; i<avctx->channels; i++){\n            cs = &(c->status[i]);\n            cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);\n            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);\n            if (cs->step_index > 88u){\n                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\\n",\n                       i, cs->step_index);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n        for (n = 0; n < (nb_samples - 1) / 8; n++) {\n            for (i = 0; i < avctx->channels; i++) {\n                cs = &c->status[i];\n                samples = &samples_p[i][1 + n * 8];\n                for (m = 0; m < 8; m += 2) {\n                    int v = bytestream2_get_byteu(&gb);\n                    samples[m    ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);\n                    samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4  , 3);\n                }\n            }\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_4XM:\n        for (i = 0; i < avctx->channels; i++)\n            c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);\n        for (i = 0; i < avctx->channels; i++) {\n            c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);\n            if (c->status[i].step_index > 88u) {\n                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\\n",\n                       i, c->status[i].step_index);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n        for (i = 0; i < avctx->channels; i++) {\n            samples = (int16_t *)c->frame.data[i];\n            cs = &c->status[i];\n            for (n = nb_samples >> 1; n > 0; n--) {\n                int v = bytestream2_get_byteu(&gb);\n                *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);\n                *samples++ = adpcm_ima_expand_nibble(cs, v >> 4  , 4);\n            }\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_MS:\n    {\n        int block_predictor;\n        block_predictor = bytestream2_get_byteu(&gb);\n        if (block_predictor > 6) {\n            av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\\n",\n                   block_predictor);\n            return AVERROR_INVALIDDATA;\n        }\n        c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];\n        c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];\n        if (st) {\n            block_predictor = bytestream2_get_byteu(&gb);\n            if (block_predictor > 6) {\n                av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\\n",\n                       block_predictor);\n                return AVERROR_INVALIDDATA;\n            }\n            c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];\n            c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];\n        }\n        c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);\n        if (st){\n            c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);\n        }\n        c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);\n        if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);\n        c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);\n        if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);\n        *samples++ = c->status[0].sample2;\n        if (st) *samples++ = c->status[1].sample2;\n        *samples++ = c->status[0].sample1;\n        if (st) *samples++ = c->status[1].sample1;\n        for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {\n            int byte = bytestream2_get_byteu(&gb);\n            *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4  );\n            *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);\n        }\n        break;\n    }\n    case AV_CODEC_ID_ADPCM_IMA_DK4:\n        for (channel = 0; channel < avctx->channels; channel++) {\n            cs = &c->status[channel];\n            cs->predictor  = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);\n            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);\n            if (cs->step_index > 88u){\n                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\\n",\n                       channel, cs->step_index);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n        for (n = nb_samples >> (1 - st); n > 0; n--) {\n            int v = bytestream2_get_byteu(&gb);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4  , 3);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_IMA_DK3:\n    {\n        int last_byte = 0;\n        int nibble;\n        int decode_top_nibble_next = 0;\n        int diff_channel;\n        const int16_t *samples_end = samples + avctx->channels * nb_samples;\n        bytestream2_skipu(&gb, 10);\n        c->status[0].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);\n        c->status[1].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);\n        c->status[0].step_index = bytestream2_get_byteu(&gb);\n        c->status[1].step_index = bytestream2_get_byteu(&gb);\n        if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){\n            av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\\n",\n                   c->status[0].step_index, c->status[1].step_index);\n            return AVERROR_INVALIDDATA;\n        }\n        diff_channel = c->status[1].predictor;\n#define DK3_GET_NEXT_NIBBLE() \\\n    if (decode_top_nibble_next) { \\\n        nibble = last_byte >> 4; \\\n        decode_top_nibble_next = 0; \\\n    } else { \\\n        last_byte = bytestream2_get_byteu(&gb); \\\n        nibble = last_byte & 0x0F; \\\n        decode_top_nibble_next = 1; \\\n    }\n        while (samples < samples_end) {\n            DK3_GET_NEXT_NIBBLE();\n            adpcm_ima_expand_nibble(&c->status[0], nibble, 3);\n            DK3_GET_NEXT_NIBBLE();\n            adpcm_ima_expand_nibble(&c->status[1], nibble, 3);\n            diff_channel = (diff_channel + c->status[1].predictor) / 2;\n            *samples++ = c->status[0].predictor + c->status[1].predictor;\n            *samples++ = c->status[0].predictor - c->status[1].predictor;\n            DK3_GET_NEXT_NIBBLE();\n            adpcm_ima_expand_nibble(&c->status[0], nibble, 3);\n            diff_channel = (diff_channel + c->status[1].predictor) / 2;\n            *samples++ = c->status[0].predictor + c->status[1].predictor;\n            *samples++ = c->status[0].predictor - c->status[1].predictor;\n        }\n        break;\n    }\n    case AV_CODEC_ID_ADPCM_IMA_ISS:\n        for (channel = 0; channel < avctx->channels; channel++) {\n            cs = &c->status[channel];\n            cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);\n            cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);\n            if (cs->step_index > 88u){\n                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\\n",\n                       channel, cs->step_index);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n        for (n = nb_samples >> (1 - st); n > 0; n--) {\n            int v1, v2;\n            int v = bytestream2_get_byteu(&gb);\n            if (st) {\n                v1 = v >> 4;\n                v2 = v & 0x0F;\n            } else {\n                v2 = v >> 4;\n                v1 = v & 0x0F;\n            }\n            *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_IMA_APC:\n        while (bytestream2_get_bytes_left(&gb) > 0) {\n            int v = bytestream2_get_byteu(&gb);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  v >> 4  , 3);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_IMA_WS:\n        if (c->vqa_version == 3) {\n            for (channel = 0; channel < avctx->channels; channel++) {\n                int16_t *smp = samples_p[channel];\n                for (n = nb_samples / 2; n > 0; n--) {\n                    int v = bytestream2_get_byteu(&gb);\n                    *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);\n                    *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);\n                }\n            }\n        } else {\n            for (n = nb_samples / 2; n > 0; n--) {\n                for (channel = 0; channel < avctx->channels; channel++) {\n                    int v = bytestream2_get_byteu(&gb);\n                    *samples++  = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);\n                    samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);\n                }\n                samples += avctx->channels;\n            }\n        }\n        bytestream2_seek(&gb, 0, SEEK_END);\n        break;\n    case AV_CODEC_ID_ADPCM_XA:\n    {\n        int16_t *out0 = samples_p[0];\n        int16_t *out1 = samples_p[1];\n        int samples_per_block = 28 * (3 - avctx->channels) * 4;\n        int sample_offset = 0;\n        while (bytestream2_get_bytes_left(&gb) >= 128) {\n            if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),\n                                 &c->status[0], &c->status[1],\n                                 avctx->channels, sample_offset)) < 0)\n                return ret;\n            bytestream2_skipu(&gb, 128);\n            sample_offset += samples_per_block;\n        }\n        break;\n    }\n    case AV_CODEC_ID_ADPCM_IMA_EA_EACS:\n        for (i=0; i<=st; i++) {\n            c->status[i].step_index = bytestream2_get_le32u(&gb);\n            if (c->status[i].step_index > 88u) {\n                av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\\n",\n                       i, c->status[i].step_index);\n                return AVERROR_INVALIDDATA;\n            }\n        }\n        for (i=0; i<=st; i++)\n            c->status[i].predictor  = bytestream2_get_le32u(&gb);\n        for (n = nb_samples >> (1 - st); n > 0; n--) {\n            int byte   = bytestream2_get_byteu(&gb);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   3);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:\n        for (n = nb_samples >> (1 - st); n > 0; n--) {\n            int byte = bytestream2_get_byteu(&gb);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   6);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_EA:\n    {\n        int previous_left_sample, previous_right_sample;\n        int current_left_sample, current_right_sample;\n        int next_left_sample, next_right_sample;\n        int coeff1l, coeff2l, coeff1r, coeff2r;\n        int shift_left, shift_right;\n        current_left_sample   = sign_extend(bytestream2_get_le16u(&gb), 16);\n        previous_left_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);\n        current_right_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);\n        previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);\n        for (count1 = 0; count1 < nb_samples / 28; count1++) {\n            int byte = bytestream2_get_byteu(&gb);\n            coeff1l = ea_adpcm_table[ byte >> 4       ];\n            coeff2l = ea_adpcm_table[(byte >> 4  ) + 4];\n            coeff1r = ea_adpcm_table[ byte & 0x0F];\n            coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];\n            byte = bytestream2_get_byteu(&gb);\n            shift_left  = 20 - (byte >> 4);\n            shift_right = 20 - (byte & 0x0F);\n            for (count2 = 0; count2 < 28; count2++) {\n                byte = bytestream2_get_byteu(&gb);\n                next_left_sample  = sign_extend(byte >> 4, 4) << shift_left;\n                next_right_sample = sign_extend(byte,      4) << shift_right;\n                next_left_sample = (next_left_sample +\n                    (current_left_sample * coeff1l) +\n                    (previous_left_sample * coeff2l) + 0x80) >> 8;\n                next_right_sample = (next_right_sample +\n                    (current_right_sample * coeff1r) +\n                    (previous_right_sample * coeff2r) + 0x80) >> 8;\n                previous_left_sample = current_left_sample;\n                current_left_sample = av_clip_int16(next_left_sample);\n                previous_right_sample = current_right_sample;\n                current_right_sample = av_clip_int16(next_right_sample);\n                *samples++ = current_left_sample;\n                *samples++ = current_right_sample;\n            }\n        }\n        bytestream2_skip(&gb, 2);\n        break;\n    }\n    case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:\n    {\n        int coeff[2][2], shift[2];\n        for(channel = 0; channel < avctx->channels; channel++) {\n            int byte = bytestream2_get_byteu(&gb);\n            for (i=0; i<2; i++)\n                coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];\n            shift[channel] = 20 - (byte & 0x0F);\n        }\n        for (count1 = 0; count1 < nb_samples / 2; count1++) {\n            int byte[2];\n            byte[0] = bytestream2_get_byteu(&gb);\n            if (st) byte[1] = bytestream2_get_byteu(&gb);\n            for(i = 4; i >= 0; i-=4) {\n                for(channel = 0; channel < avctx->channels; channel++) {\n                    int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];\n                    sample = (sample +\n                             c->status[channel].sample1 * coeff[channel][0] +\n                             c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;\n                    c->status[channel].sample2 = c->status[channel].sample1;\n                    c->status[channel].sample1 = av_clip_int16(sample);\n                    *samples++ = c->status[channel].sample1;\n                }\n            }\n        }\n        bytestream2_seek(&gb, 0, SEEK_END);\n        break;\n    }\n    case AV_CODEC_ID_ADPCM_EA_R1:\n    case AV_CODEC_ID_ADPCM_EA_R2:\n    case AV_CODEC_ID_ADPCM_EA_R3: {\n        const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;\n        int previous_sample, current_sample, next_sample;\n        int coeff1, coeff2;\n        int shift;\n        unsigned int channel;\n        uint16_t *samplesC;\n        int count = 0;\n        int offsets[6];\n        for (channel=0; channel<avctx->channels; channel++)\n            offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :\n                                             bytestream2_get_le32(&gb)) +\n                               (avctx->channels + 1) * 4;\n        for (channel=0; channel<avctx->channels; channel++) {\n            bytestream2_seek(&gb, offsets[channel], SEEK_SET);\n            samplesC = samples_p[channel];\n            if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {\n                current_sample  = sign_extend(bytestream2_get_le16(&gb), 16);\n                previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);\n            } else {\n                current_sample  = c->status[channel].predictor;\n                previous_sample = c->status[channel].prev_sample;\n            }\n            for (count1 = 0; count1 < nb_samples / 28; count1++) {\n                int byte = bytestream2_get_byte(&gb);\n                if (byte == 0xEE) {\n                    current_sample  = sign_extend(bytestream2_get_be16(&gb), 16);\n                    previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);\n                    for (count2=0; count2<28; count2++)\n                        *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);\n                } else {\n                    coeff1 = ea_adpcm_table[ byte >> 4     ];\n                    coeff2 = ea_adpcm_table[(byte >> 4) + 4];\n                    shift = 20 - (byte & 0x0F);\n                    for (count2=0; count2<28; count2++) {\n                        if (count2 & 1)\n                            next_sample = sign_extend(byte,    4) << shift;\n                        else {\n                            byte = bytestream2_get_byte(&gb);\n                            next_sample = sign_extend(byte >> 4, 4) << shift;\n                        }\n                        next_sample += (current_sample  * coeff1) +\n                                       (previous_sample * coeff2);\n                        next_sample = av_clip_int16(next_sample >> 8);\n                        previous_sample = current_sample;\n                        current_sample  = next_sample;\n                        *samplesC++ = current_sample;\n                    }\n                }\n            }\n            if (!count) {\n                count = count1;\n            } else if (count != count1) {\n                av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\\n");\n                count = FFMAX(count, count1);\n            }\n            if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {\n                c->status[channel].predictor   = current_sample;\n                c->status[channel].prev_sample = previous_sample;\n            }\n        }\n        c->frame.nb_samples = count * 28;\n        bytestream2_seek(&gb, 0, SEEK_END);\n        break;\n    }\n    case AV_CODEC_ID_ADPCM_EA_XAS:\n        for (channel=0; channel<avctx->channels; channel++) {\n            int coeff[2][4], shift[4];\n            int16_t *s = samples_p[channel];\n            for (n = 0; n < 4; n++, s += 32) {\n                int val = sign_extend(bytestream2_get_le16u(&gb), 16);\n                for (i=0; i<2; i++)\n                    coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];\n                s[0] = val & ~0x0F;\n                val = sign_extend(bytestream2_get_le16u(&gb), 16);\n                shift[n] = 20 - (val & 0x0F);\n                s[1] = val & ~0x0F;\n            }\n            for (m=2; m<32; m+=2) {\n                s = &samples_p[channel][m];\n                for (n = 0; n < 4; n++, s += 32) {\n                    int level, pred;\n                    int byte = bytestream2_get_byteu(&gb);\n                    level = sign_extend(byte >> 4, 4) << shift[n];\n                    pred  = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];\n                    s[0]  = av_clip_int16((level + pred + 0x80) >> 8);\n                    level = sign_extend(byte, 4) << shift[n];\n                    pred  = s[0] * coeff[0][n] + s[-1] * coeff[1][n];\n                    s[1]  = av_clip_int16((level + pred + 0x80) >> 8);\n                }\n            }\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_IMA_AMV:\n    case AV_CODEC_ID_ADPCM_IMA_SMJPEG:\n        if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_AMV) {\n            c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);\n            c->status[0].step_index = bytestream2_get_le16u(&gb);\n            bytestream2_skipu(&gb, 4);\n        } else {\n            c->status[0].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);\n            c->status[0].step_index = bytestream2_get_byteu(&gb);\n            bytestream2_skipu(&gb, 1);\n        }\n        if (c->status[0].step_index > 88u) {\n            av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\\n",\n                   c->status[0].step_index);\n            return AVERROR_INVALIDDATA;\n        }\n        for (n = nb_samples >> (1 - st); n > 0; n--) {\n            int hi, lo, v = bytestream2_get_byteu(&gb);\n            if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_AMV) {\n                hi = v & 0x0F;\n                lo = v >> 4;\n            } else {\n                lo = v & 0x0F;\n                hi = v >> 4;\n            }\n            *samples++ = adpcm_ima_expand_nibble(&c->status[0], lo, 3);\n            *samples++ = adpcm_ima_expand_nibble(&c->status[0], hi, 3);\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_CT:\n        for (n = nb_samples >> (1 - st); n > 0; n--) {\n            int v = bytestream2_get_byteu(&gb);\n            *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4  );\n            *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_SBPRO_4:\n    case AV_CODEC_ID_ADPCM_SBPRO_3:\n    case AV_CODEC_ID_ADPCM_SBPRO_2:\n        if (!c->status[0].step_index) {\n            *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);\n            if (st)\n                *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);\n            c->status[0].step_index = 1;\n            nb_samples--;\n        }\n        if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {\n            for (n = nb_samples >> (1 - st); n > 0; n--) {\n                int byte = bytestream2_get_byteu(&gb);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n                                                       byte >> 4,   4, 0);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],\n                                                       byte & 0x0F, 4, 0);\n            }\n        } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {\n            for (n = nb_samples / 3; n > 0; n--) {\n                int byte = bytestream2_get_byteu(&gb);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n                                                        byte >> 5        , 3, 0);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n                                                       (byte >> 2) & 0x07, 3, 0);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n                                                        byte & 0x03,       2, 0);\n            }\n        } else {\n            for (n = nb_samples >> (2 - st); n > 0; n--) {\n                int byte = bytestream2_get_byteu(&gb);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n                                                        byte >> 6        , 2, 2);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],\n                                                       (byte >> 4) & 0x03, 2, 2);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n                                                       (byte >> 2) & 0x03, 2, 2);\n                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],\n                                                        byte & 0x03,       2, 2);\n            }\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_SWF:\n        adpcm_swf_decode(avctx, buf, buf_size, samples);\n        bytestream2_seek(&gb, 0, SEEK_END);\n        break;\n    case AV_CODEC_ID_ADPCM_YAMAHA:\n        for (n = nb_samples >> (1 - st); n > 0; n--) {\n            int v = bytestream2_get_byteu(&gb);\n            *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);\n            *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4  );\n        }\n        break;\n    case AV_CODEC_ID_ADPCM_THP:\n    {\n        int table[2][16];\n        int prev[2][2];\n        int ch;\n        for (i = 0; i < 2; i++)\n            for (n = 0; n < 16; n++)\n                table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);\n        for (i = 0; i < 2; i++)\n            for (n = 0; n < 2; n++)\n                prev[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);\n        for (ch = 0; ch <= st; ch++) {\n            samples = samples_p[ch];\n            for (i = 0; i < nb_samples / 14; i++) {\n                int byte = bytestream2_get_byteu(&gb);\n                int index = (byte >> 4) & 7;\n                unsigned int exp = byte & 0x0F;\n                int factor1 = table[ch][index * 2];\n                int factor2 = table[ch][index * 2 + 1];\n                for (n = 0; n < 14; n++) {\n                    int32_t sampledat;\n                    if (n & 1) {\n                        sampledat = sign_extend(byte, 4);\n                    } else {\n                        byte = bytestream2_get_byteu(&gb);\n                        sampledat = sign_extend(byte >> 4, 4);\n                    }\n                    sampledat = ((prev[ch][0]*factor1\n                                + prev[ch][1]*factor2) >> 11) + (sampledat << exp);\n                    *samples = av_clip_int16(sampledat);\n                    prev[ch][1] = prev[ch][0];\n                    prev[ch][0] = *samples++;\n                }\n            }\n        }\n        break;\n    }\n    default:\n        return -1;\n    }\n    *got_frame_ptr   = 1;\n    *(AVFrame *)data = c->frame;\n    return bytestream2_tell(&gb);\n}']