Commit 3db8db40 authored by Justin Ruggles's avatar Justin Ruggles

dpcm: factor out the stereo flag calculation

parent b09c7eef
......@@ -169,6 +169,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
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;
......@@ -184,11 +185,11 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
switch(avctx->codec->id) {
case CODEC_ID_ROQ_DPCM:
if (s->channels == 1)
predictor[0] = AV_RL16(&buf[6]);
else {
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]);
......@@ -200,7 +201,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
output_samples[out] = predictor[ch];
/* toggle channel */
ch ^= s->channels - 1;
ch ^= stereo;
}
break;
......@@ -210,7 +211,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
in += 2;
SE_16BIT(predictor[0])
output_samples[out++] = predictor[0];
if (s->channels == 2) {
if (stereo) {
predictor[1] = AV_RL16(&buf[in]);
in += 2;
SE_16BIT(predictor[1])
......@@ -223,7 +224,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
output_samples[out++] = predictor[ch];
/* toggle channel */
ch ^= s->channels - 1;
ch ^= stereo;
}
break;
......@@ -234,7 +235,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
predictor[0] = AV_RL16(&buf[in]);
in += 2;
SE_16BIT(predictor[0]);
if (s->channels == 2) {
if (stereo) {
predictor[1] = AV_RL16(&buf[in]);
in += 2;
SE_16BIT(predictor[1]);
......@@ -258,7 +259,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
output_samples[out++] = predictor[ch];
/* toggle channel */
ch ^= s->channels - 1;
ch ^= stereo;
}
break;
case CODEC_ID_SOL_DPCM:
......@@ -274,10 +275,10 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
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;
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) {
......@@ -288,7 +289,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
s->sample[ch] = av_clip_int16(s->sample[ch]);
output_samples[out++] = s->sample[ch];
/* toggle channel */
ch ^= s->channels - 1;
ch ^= stereo;
}
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment