static int dpcm_decode_frame(AVCodecContext *avctx,

                             void *data, int *data_size,

                             AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    DPCMContext *s = avctx->priv_data;

    int in, out = 0;

    int predictor[2];

    int ch = 0;

    int stereo = s->channels - 1;

    short *output_samples = data;

    int shift[2];

    unsigned char byte;

    short diff;



    if (!buf_size)

        return 0;



    // almost every DPCM variant expands one byte of data into two

    if(*data_size/2 < buf_size)

        return -1;



    switch(avctx->codec->id) {



    case CODEC_ID_ROQ_DPCM:

        if (stereo) {

            predictor[0] = buf[7] << 8;

            predictor[1] = buf[6] << 8;

        } else {

            predictor[0] = AV_RL16(&buf[6]);

        }

        SE_16BIT(predictor[0]);

        SE_16BIT(predictor[1]);



        /* decode the samples */

        for (in = 8, out = 0; in < buf_size; in++, out++) {

            predictor[ch] += s->roq_square_array[buf[in]];

            predictor[ch] = av_clip_int16(predictor[ch]);

            output_samples[out] = predictor[ch];



            /* toggle channel */

            ch ^= stereo;

        }

        break;



    case CODEC_ID_INTERPLAY_DPCM:

        in = 6;  /* skip over the stream mask and stream length */

        predictor[0] = AV_RL16(&buf[in]);

        in += 2;

        SE_16BIT(predictor[0])

        output_samples[out++] = predictor[0];

        if (stereo) {

            predictor[1] = AV_RL16(&buf[in]);

            in += 2;

            SE_16BIT(predictor[1])

            output_samples[out++] = predictor[1];

        }



        while (in < buf_size) {

            predictor[ch] += interplay_delta_table[buf[in++]];

            predictor[ch] = av_clip_int16(predictor[ch]);

            output_samples[out++] = predictor[ch];



            /* toggle channel */

            ch ^= stereo;

        }



        break;



    case CODEC_ID_XAN_DPCM:

        in = 0;

        shift[0] = shift[1] = 4;

        predictor[0] = AV_RL16(&buf[in]);

        in += 2;

        SE_16BIT(predictor[0]);

        if (stereo) {

            predictor[1] = AV_RL16(&buf[in]);

            in += 2;

            SE_16BIT(predictor[1]);

        }



        while (in < buf_size) {

            byte = buf[in++];

            diff = (byte & 0xFC) << 8;

            if ((byte & 0x03) == 3)

                shift[ch]++;

            else

                shift[ch] -= (2 * (byte & 3));

            /* saturate the shifter to a lower limit of 0 */

            if (shift[ch] < 0)

                shift[ch] = 0;



            diff >>= shift[ch];

            predictor[ch] += diff;



            predictor[ch] = av_clip_int16(predictor[ch]);

            output_samples[out++] = predictor[ch];



            /* toggle channel */

            ch ^= stereo;

        }

        break;

    case CODEC_ID_SOL_DPCM:

        in = 0;

        if (avctx->codec_tag != 3) {

            if(*data_size/4 < buf_size)

                return -1;

            while (in < buf_size) {

                int n1, n2;

                n1 = (buf[in] >> 4) & 0xF;

                n2 = buf[in++] & 0xF;

                s->sample[0] += s->sol_table[n1];

                if (s->sample[0] < 0)   s->sample[0] = 0;

                if (s->sample[0] > 255) s->sample[0] = 255;

                output_samples[out++] = (s->sample[0] - 128) << 8;

                s->sample[stereo] += s->sol_table[n2];

                if (s->sample[stereo] < 0)   s->sample[stereo] = 0;

                if (s->sample[stereo] > 255) s->sample[stereo] = 255;

                output_samples[out++] = (s->sample[stereo] - 128) << 8;

            }

        } else {

            while (in < buf_size) {

                int n;

                n = buf[in++];

                if (n & 0x80) s->sample[ch] -= s->sol_table[n & 0x7F];

                else s->sample[ch] += s->sol_table[n & 0x7F];

                s->sample[ch] = av_clip_int16(s->sample[ch]);

                output_samples[out++] = s->sample[ch];

                /* toggle channel */

                ch ^= stereo;

            }

        }

        break;

    }



    *data_size = out * sizeof(short);

    return buf_size;

}

static int dpcm_decode_frame(AVCodecContext *avctx,

                             void *data, int *data_size,

                             AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    DPCMContext *s = avctx->priv_data;

    int in, out = 0;

    int predictor[2];

    int ch = 0;

    int stereo = s->channels - 1;

    short *output_samples = data;

    int shift[2];

    unsigned char byte;

    short diff;



    if (!buf_size)

        return 0;



    

    if(*data_size/2 < buf_size)

        return -1;



    switch(avctx->codec->id) {



    case CODEC_ID_ROQ_DPCM:

        if (stereo) {

            predictor[0] = buf[7] << 8;

            predictor[1] = buf[6] << 8;

        } else {

            predictor[0] = AV_RL16(&buf[6]);

        }

        SE_16BIT(predictor[0]);

        SE_16BIT(predictor[1]);



        

        for (in = 8, out = 0; in < buf_size; in++, out++) {

            predictor[ch] += s->roq_square_array[buf[in]];

            predictor[ch] = av_clip_int16(predictor[ch]);

            output_samples[out] = predictor[ch];



            

            ch ^= stereo;

        }

        break;



    case CODEC_ID_INTERPLAY_DPCM:

        in = 6;  

        predictor[0] = AV_RL16(&buf[in]);

        in += 2;

        SE_16BIT(predictor[0])

        output_samples[out++] = predictor[0];

        if (stereo) {

            predictor[1] = AV_RL16(&buf[in]);

            in += 2;

            SE_16BIT(predictor[1])

            output_samples[out++] = predictor[1];

        }



        while (in < buf_size) {

            predictor[ch] += interplay_delta_table[buf[in++]];

            predictor[ch] = av_clip_int16(predictor[ch]);

            output_samples[out++] = predictor[ch];



            

            ch ^= stereo;

        }



        break;



    case CODEC_ID_XAN_DPCM:

        in = 0;

        shift[0] = shift[1] = 4;

        predictor[0] = AV_RL16(&buf[in]);

        in += 2;

        SE_16BIT(predictor[0]);

        if (stereo) {

            predictor[1] = AV_RL16(&buf[in]);

            in += 2;

            SE_16BIT(predictor[1]);

        }



        while (in < buf_size) {

            byte = buf[in++];

            diff = (byte & 0xFC) << 8;

            if ((byte & 0x03) == 3)

                shift[ch]++;

            else

                shift[ch] -= (2 * (byte & 3));

            

            if (shift[ch] < 0)

                shift[ch] = 0;



            diff >>= shift[ch];

            predictor[ch] += diff;



            predictor[ch] = av_clip_int16(predictor[ch]);

            output_samples[out++] = predictor[ch];



            

            ch ^= stereo;

        }

        break;

    case CODEC_ID_SOL_DPCM:

        in = 0;

        if (avctx->codec_tag != 3) {

            if(*data_size/4 < buf_size)

                return -1;

            while (in < buf_size) {

                int n1, n2;

                n1 = (buf[in] >> 4) & 0xF;

                n2 = buf[in++] & 0xF;

                s->sample[0] += s->sol_table[n1];

                if (s->sample[0] < 0)   s->sample[0] = 0;

                if (s->sample[0] > 255) s->sample[0] = 255;

                output_samples[out++] = (s->sample[0] - 128) << 8;

                s->sample[stereo] += s->sol_table[n2];

                if (s->sample[stereo] < 0)   s->sample[stereo] = 0;

                if (s->sample[stereo] > 255) s->sample[stereo] = 255;

                output_samples[out++] = (s->sample[stereo] - 128) << 8;

            }

        } else {

            while (in < buf_size) {

                int n;

                n = buf[in++];

                if (n & 0x80) s->sample[ch] -= s->sol_table[n & 0x7F];

                else s->sample[ch] += s->sol_table[n & 0x7F];

                s->sample[ch] = av_clip_int16(s->sample[ch]);

                output_samples[out++] = s->sample[ch];

                

                ch ^= stereo;

            }

        }

        break;

    }



    *data_size = out * sizeof(short);

    return buf_size;

}

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;

    DPCMContext *s = VAR_0->priv_data;

    int VAR_6, VAR_7 = 0;

    int VAR_8[2];

    int VAR_9 = 0;

    int VAR_10 = s->channels - 1;

    short *VAR_11 = VAR_1;

    int VAR_12[2];

    unsigned char VAR_13;

    short VAR_14;



    if (!VAR_5)

        return 0;



    

    if(*VAR_2/2 < VAR_5)

        return -1;



    switch(VAR_0->codec->id) {



    case CODEC_ID_ROQ_DPCM:

        if (VAR_10) {

            VAR_8[0] = VAR_4[7] << 8;

            VAR_8[1] = VAR_4[6] << 8;

        } else {

            VAR_8[0] = AV_RL16(&VAR_4[6]);

        }

        SE_16BIT(VAR_8[0]);

        SE_16BIT(VAR_8[1]);



        

        for (VAR_6 = 8, VAR_7 = 0; VAR_6 < VAR_5; VAR_6++, VAR_7++) {

            VAR_8[VAR_9] += s->roq_square_array[VAR_4[VAR_6]];

            VAR_8[VAR_9] = av_clip_int16(VAR_8[VAR_9]);

            VAR_11[VAR_7] = VAR_8[VAR_9];



            

            VAR_9 ^= VAR_10;

        }

        break;



    case CODEC_ID_INTERPLAY_DPCM:

        VAR_6 = 6;  

        VAR_8[0] = AV_RL16(&VAR_4[VAR_6]);

        VAR_6 += 2;

        SE_16BIT(VAR_8[0])

        VAR_11[VAR_7++] = VAR_8[0];

        if (VAR_10) {

            VAR_8[1] = AV_RL16(&VAR_4[VAR_6]);

            VAR_6 += 2;

            SE_16BIT(VAR_8[1])

            VAR_11[VAR_7++] = VAR_8[1];

        }



        while (VAR_6 < VAR_5) {

            VAR_8[VAR_9] += interplay_delta_table[VAR_4[VAR_6++]];

            VAR_8[VAR_9] = av_clip_int16(VAR_8[VAR_9]);

            VAR_11[VAR_7++] = VAR_8[VAR_9];



            

            VAR_9 ^= VAR_10;

        }



        break;



    case CODEC_ID_XAN_DPCM:

        VAR_6 = 0;

        VAR_12[0] = VAR_12[1] = 4;

        VAR_8[0] = AV_RL16(&VAR_4[VAR_6]);

        VAR_6 += 2;

        SE_16BIT(VAR_8[0]);

        if (VAR_10) {

            VAR_8[1] = AV_RL16(&VAR_4[VAR_6]);

            VAR_6 += 2;

            SE_16BIT(VAR_8[1]);

        }



        while (VAR_6 < VAR_5) {

            VAR_13 = VAR_4[VAR_6++];

            VAR_14 = (VAR_13 & 0xFC) << 8;

            if ((VAR_13 & 0x03) == 3)

                VAR_12[VAR_9]++;

            else

                VAR_12[VAR_9] -= (2 * (VAR_13 & 3));

            

            if (VAR_12[VAR_9] < 0)

                VAR_12[VAR_9] = 0;



            VAR_14 >>= VAR_12[VAR_9];

            VAR_8[VAR_9] += VAR_14;



            VAR_8[VAR_9] = av_clip_int16(VAR_8[VAR_9]);

            VAR_11[VAR_7++] = VAR_8[VAR_9];



            

            VAR_9 ^= VAR_10;

        }

        break;

    case CODEC_ID_SOL_DPCM:

        VAR_6 = 0;

        if (VAR_0->codec_tag != 3) {

            if(*VAR_2/4 < VAR_5)

                return -1;

            while (VAR_6 < VAR_5) {

                int VAR_15, VAR_16;

                VAR_15 = (VAR_4[VAR_6] >> 4) & 0xF;

                VAR_16 = VAR_4[VAR_6++] & 0xF;

                s->sample[0] += s->sol_table[VAR_15];

                if (s->sample[0] < 0)   s->sample[0] = 0;

                if (s->sample[0] > 255) s->sample[0] = 255;

                VAR_11[VAR_7++] = (s->sample[0] - 128) << 8;

                s->sample[VAR_10] += s->sol_table[VAR_16];

                if (s->sample[VAR_10] < 0)   s->sample[VAR_10] = 0;

                if (s->sample[VAR_10] > 255) s->sample[VAR_10] = 255;

                VAR_11[VAR_7++] = (s->sample[VAR_10] - 128) << 8;

            }

        } else {

            while (VAR_6 < VAR_5) {

                int VAR_17;

                VAR_17 = VAR_4[VAR_6++];

                if (VAR_17 & 0x80) s->sample[VAR_9] -= s->sol_table[VAR_17 & 0x7F];

                else s->sample[VAR_9] += s->sol_table[VAR_17 & 0x7F];

                s->sample[VAR_9] = av_clip_int16(s->sample[VAR_9]);

                VAR_11[VAR_7++] = s->sample[VAR_9];

                

                VAR_9 ^= VAR_10;

            }

        }

        break;

    }



    *VAR_2 = VAR_7 * sizeof(short);

    return VAR_5;

}

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; DPCMContext *s = VAR_0->priv_data; int VAR_6, VAR_7 = 0; int VAR_8[2]; int VAR_9 = 0; int VAR_10 = s->channels - 1; short *VAR_11 = VAR_1; int VAR_12[2]; unsigned char VAR_13; short VAR_14; if (!VAR_5)
return 0; if(*VAR_2/2 < VAR_5)
return -1; switch(VAR_0->codec->id) { case CODEC_ID_ROQ_DPCM:
if (VAR_10) { VAR_8[0] = VAR_4[7] << 8; VAR_8[1] = VAR_4[6] << 8; } else { VAR_8[0] = AV_RL16(&VAR_4[6]); } SE_16BIT(VAR_8[0]); SE_16BIT(VAR_8[1]); for (VAR_6 = 8, VAR_7 = 0; VAR_6 < VAR_5; VAR_6++, VAR_7++) { VAR_8[VAR_9] += s->roq_square_array[VAR_4[VAR_6]]; VAR_8[VAR_9] = av_clip_int16(VAR_8[VAR_9]); VAR_11[VAR_7] = VAR_8[VAR_9]; VAR_9 ^= VAR_10; } break; case CODEC_ID_INTERPLAY_DPCM:
VAR_6 = 6; VAR_8[0] = AV_RL16(&VAR_4[VAR_6]); VAR_6 += 2; SE_16BIT(VAR_8[0])
VAR_11[VAR_7++] = VAR_8[0]; if (VAR_10) { VAR_8[1] = AV_RL16(&VAR_4[VAR_6]); VAR_6 += 2; SE_16BIT(VAR_8[1])
VAR_11[VAR_7++] = VAR_8[1]; } while (VAR_6 < VAR_5) { VAR_8[VAR_9] += interplay_delta_table[VAR_4[VAR_6++]]; VAR_8[VAR_9] = av_clip_int16(VAR_8[VAR_9]); VAR_11[VAR_7++] = VAR_8[VAR_9]; VAR_9 ^= VAR_10; } break; case CODEC_ID_XAN_DPCM:
VAR_6 = 0; VAR_12[0] = VAR_12[1] = 4; VAR_8[0] = AV_RL16(&VAR_4[VAR_6]); VAR_6 += 2; SE_16BIT(VAR_8[0]); if (VAR_10) { VAR_8[1] = AV_RL16(&VAR_4[VAR_6]); VAR_6 += 2; SE_16BIT(VAR_8[1]); } while (VAR_6 < VAR_5) { VAR_13 = VAR_4[VAR_6++]; VAR_14 = (VAR_13 & 0xFC) << 8; if ((VAR_13 & 0x03) == 3)
VAR_12[VAR_9]++; else
VAR_12[VAR_9] -= (2 * (VAR_13 & 3)); if (VAR_12[VAR_9] < 0)
VAR_12[VAR_9] = 0; VAR_14 >>= VAR_12[VAR_9]; VAR_8[VAR_9] += VAR_14; VAR_8[VAR_9] = av_clip_int16(VAR_8[VAR_9]); VAR_11[VAR_7++] = VAR_8[VAR_9]; VAR_9 ^= VAR_10; } break; case CODEC_ID_SOL_DPCM:
VAR_6 = 0; if (VAR_0->codec_tag != 3) { if(*VAR_2/4 < VAR_5)
return -1; while (VAR_6 < VAR_5) { int VAR_15, VAR_16; VAR_15 = (VAR_4[VAR_6] >> 4) & 0xF; VAR_16 = VAR_4[VAR_6++] & 0xF; s->sample[0] += s->sol_table[VAR_15]; if (s->sample[0] < 0)   s->sample[0] = 0; if (s->sample[0] > 255) s->sample[0] = 255; VAR_11[VAR_7++] = (s->sample[0] - 128) << 8; s->sample[VAR_10] += s->sol_table[VAR_16]; if (s->sample[VAR_10] < 0)   s->sample[VAR_10] = 0; if (s->sample[VAR_10] > 255) s->sample[VAR_10] = 255; VAR_11[VAR_7++] = (s->sample[VAR_10] - 128) << 8; } } else { while (VAR_6 < VAR_5) { int VAR_17; VAR_17 = VAR_4[VAR_6++]; if (VAR_17 & 0x80) s->sample[VAR_9] -= s->sol_table[VAR_17 & 0x7F]; else s->sample[VAR_9] += s->sol_table[VAR_17 & 0x7F]; s->sample[VAR_9] = av_clip_int16(s->sample[VAR_9]); VAR_11[VAR_7++] = s->sample[VAR_9]; VAR_9 ^= VAR_10; } } break; } *VAR_2 = VAR_7 * sizeof(short); return VAR_5; }