static int dpcm_decode_frame(AVCodecContext *avctx,

                             void *data, int *data_size,

                             uint8_t *buf, int buf_size)

{

    DPCMContext *s = avctx->priv_data;

    int in, out = 0;

    int predictor[2];

    int channel_number = 0;

    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)




    switch(avctx->codec->id) {



    case CODEC_ID_ROQ_DPCM:

        if (s->channels == 1)

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

        else {

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

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

        }

        SE_16BIT(predictor[0]);

        SE_16BIT(predictor[1]);



        /* decode the samples */

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

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

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

            output_samples[out] = predictor[channel_number];



            /* toggle channel */

            channel_number ^= s->channels - 1;

        }

        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 (s->channels == 2) {

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

            in += 2;

            SE_16BIT(predictor[1])

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

        }



        while (in < buf_size) {

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

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

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



            /* toggle channel */

            channel_number ^= s->channels - 1;

        }



        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 (s->channels == 2) {

            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[channel_number]++;

            else

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

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

            if (shift[channel_number] < 0)

                shift[channel_number] = 0;



            diff >>= shift[channel_number];

            predictor[channel_number] += diff;



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

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



            /* toggle channel */

            channel_number ^= s->channels - 1;

        }

        break;

    case CODEC_ID_SOL_DPCM:

        in = 0;

        if (avctx->codec_tag != 3) {



            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[s->channels - 1] += s->sol_table[n2];

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

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

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

            }

        } else {

            while (in < buf_size) {

                int n;

                n = buf[in++];

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

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

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

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

                /* toggle channel */

                channel_number ^= s->channels - 1;

            }

        }

        break;

    }



    *data_size = out * sizeof(short);

    return buf_size;

}
static int dpcm_decode_frame(AVCodecContext *avctx,

                             void *data, int *data_size,

                             uint8_t *buf, int buf_size)

{

    DPCMContext *s = avctx->priv_data;

    int in, out = 0;

    int predictor[2];

    int channel_number = 0;

    short *output_samples = data;

    int shift[2];

    unsigned char byte;

    short diff;



    if (!buf_size)

        return 0;



    

    if(*data_size/2 < buf_size)




    switch(avctx->codec->id) {



    case CODEC_ID_ROQ_DPCM:

        if (s->channels == 1)

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

        else {

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

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

        }

        SE_16BIT(predictor[0]);

        SE_16BIT(predictor[1]);



        

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

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

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

            output_samples[out] = predictor[channel_number];



            

            channel_number ^= s->channels - 1;

        }

        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 (s->channels == 2) {

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

            in += 2;

            SE_16BIT(predictor[1])

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

        }



        while (in < buf_size) {

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

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

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



            

            channel_number ^= s->channels - 1;

        }



        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 (s->channels == 2) {

            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[channel_number]++;

            else

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

            

            if (shift[channel_number] < 0)

                shift[channel_number] = 0;



            diff >>= shift[channel_number];

            predictor[channel_number] += diff;



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

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



            

            channel_number ^= s->channels - 1;

        }

        break;

    case CODEC_ID_SOL_DPCM:

        in = 0;

        if (avctx->codec_tag != 3) {



            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[s->channels - 1] += s->sol_table[n2];

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

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

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

            }

        } else {

            while (in < buf_size) {

                int n;

                n = buf[in++];

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

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

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

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

                

                channel_number ^= s->channels - 1;

            }

        }

        break;

    }



    *data_size = out * sizeof(short);

    return buf_size;

}
static int FUNC_0(AVCodecContext *VAR_0,

                             void *VAR_1, int *VAR_2,

                             uint8_t *VAR_3, int VAR_4)

{

    DPCMContext *s = VAR_0->priv_data;

    int VAR_5, VAR_6 = 0;

    int VAR_7[2];

    int VAR_8 = 0;

    short *VAR_9 = VAR_1;

    int VAR_10[2];

    unsigned char VAR_11;

    short VAR_12;



    if (!VAR_4)

        return 0;



    

    if(*VAR_2/2 < VAR_4)




    switch(VAR_0->codec->id) {



    case CODEC_ID_ROQ_DPCM:

        if (s->channels == 1)

            VAR_7[0] = AV_RL16(&VAR_3[6]);

        else {

            VAR_7[0] = VAR_3[7] << 8;

            VAR_7[1] = VAR_3[6] << 8;

        }

        SE_16BIT(VAR_7[0]);

        SE_16BIT(VAR_7[1]);



        

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

            VAR_7[VAR_8] += s->roq_square_array[VAR_3[VAR_5]];

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

            VAR_9[VAR_6] = VAR_7[VAR_8];



            

            VAR_8 ^= s->channels - 1;

        }

        break;



    case CODEC_ID_INTERPLAY_DPCM:

        VAR_5 = 6;  

        VAR_7[0] = AV_RL16(&VAR_3[VAR_5]);

        VAR_5 += 2;

        SE_16BIT(VAR_7[0])

        VAR_9[VAR_6++] = VAR_7[0];

        if (s->channels == 2) {

            VAR_7[1] = AV_RL16(&VAR_3[VAR_5]);

            VAR_5 += 2;

            SE_16BIT(VAR_7[1])

            VAR_9[VAR_6++] = VAR_7[1];

        }



        while (VAR_5 < VAR_4) {

            VAR_7[VAR_8] += interplay_delta_table[VAR_3[VAR_5++]];

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

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



            

            VAR_8 ^= s->channels - 1;

        }



        break;



    case CODEC_ID_XAN_DPCM:

        VAR_5 = 0;

        VAR_10[0] = VAR_10[1] = 4;

        VAR_7[0] = AV_RL16(&VAR_3[VAR_5]);

        VAR_5 += 2;

        SE_16BIT(VAR_7[0]);

        if (s->channels == 2) {

            VAR_7[1] = AV_RL16(&VAR_3[VAR_5]);

            VAR_5 += 2;

            SE_16BIT(VAR_7[1]);

        }



        while (VAR_5 < VAR_4) {

            VAR_11 = VAR_3[VAR_5++];

            VAR_12 = (VAR_11 & 0xFC) << 8;

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

                VAR_10[VAR_8]++;

            else

                VAR_10[VAR_8] -= (2 * (VAR_11 & 3));

            

            if (VAR_10[VAR_8] < 0)

                VAR_10[VAR_8] = 0;



            VAR_12 >>= VAR_10[VAR_8];

            VAR_7[VAR_8] += VAR_12;



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

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



            

            VAR_8 ^= s->channels - 1;

        }

        break;

    case CODEC_ID_SOL_DPCM:

        VAR_5 = 0;

        if (VAR_0->codec_tag != 3) {



            while (VAR_5 < VAR_4) {

                int VAR_13, VAR_14;

                VAR_13 = (VAR_3[VAR_5] >> 4) & 0xF;

                VAR_14 = VAR_3[VAR_5++] & 0xF;

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

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

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

                VAR_9[VAR_6++] = (s->sample[0] - 128) << 8;

                s->sample[s->channels - 1] += s->sol_table[VAR_14];

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

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

                VAR_9[VAR_6++] = (s->sample[s->channels - 1] - 128) << 8;

            }

        } else {

            while (VAR_5 < VAR_4) {

                int VAR_15;

                VAR_15 = VAR_3[VAR_5++];

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

                else s->sample[VAR_8] += s->sol_table[VAR_15 & 0x7F];

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

                VAR_9[VAR_6++] = s->sample[VAR_8];

                

                VAR_8 ^= s->channels - 1;

            }

        }

        break;

    }



    *VAR_2 = VAR_6 * sizeof(short);

    return VAR_4;

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