Commit 918cfac6 authored by pross's avatar pross

Simplify PCM codec; change 'n' in pcm_decode_frame() to equal "total number of samples".


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@14659 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent e04b4fd9
...@@ -339,7 +339,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, ...@@ -339,7 +339,7 @@ static int pcm_decode_frame(AVCodecContext *avctx,
const uint8_t *buf, int buf_size) const uint8_t *buf, int buf_size)
{ {
PCMDecode *s = avctx->priv_data; PCMDecode *s = avctx->priv_data;
int c, n; int sample_size, c, n;
short *samples; short *samples;
const uint8_t *src, *src2[MAX_CHANNELS]; const uint8_t *src, *src2[MAX_CHANNELS];
...@@ -351,7 +351,9 @@ static int pcm_decode_frame(AVCodecContext *avctx, ...@@ -351,7 +351,9 @@ static int pcm_decode_frame(AVCodecContext *avctx,
return -1; return -1;
} }
n = avctx->channels * av_get_bits_per_sample(avctx->codec_id)/8; sample_size = av_get_bits_per_sample(avctx->codec_id)/8;
n = avctx->channels * sample_size;
/* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */ /* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */
if (CODEC_ID_PCM_DVD == avctx->codec_id) if (CODEC_ID_PCM_DVD == avctx->codec_id)
/* 2 samples are interleaved per block in PCM_DVD */ /* 2 samples are interleaved per block in PCM_DVD */
...@@ -365,15 +367,12 @@ static int pcm_decode_frame(AVCodecContext *avctx, ...@@ -365,15 +367,12 @@ static int pcm_decode_frame(AVCodecContext *avctx,
buf_size= FFMIN(buf_size, *data_size/2); buf_size= FFMIN(buf_size, *data_size/2);
*data_size=0; *data_size=0;
n = buf_size/avctx->channels; n = buf_size/sample_size;
for(c=0;c<avctx->channels;c++)
src2[c] = &src[c*n];
switch(avctx->codec->id) { switch(avctx->codec->id) {
case CODEC_ID_PCM_F32BE: case CODEC_ID_PCM_F32BE:
{ {
float *fsamples = data; float *fsamples = data;
n = buf_size >> 2;
for(;n>0;n--) for(;n>0;n--)
*fsamples++ = av_int2flt(bytestream_get_be32(&src)); *fsamples++ = av_int2flt(bytestream_get_be32(&src));
samples = (void*)fsamples; samples = (void*)fsamples;
...@@ -404,7 +403,6 @@ static int pcm_decode_frame(AVCodecContext *avctx, ...@@ -404,7 +403,6 @@ static int pcm_decode_frame(AVCodecContext *avctx,
decode_to16(3, 0, 1, &src, &samples, buf_size); decode_to16(3, 0, 1, &src, &samples, buf_size);
break; break;
case CODEC_ID_PCM_S24DAUD: case CODEC_ID_PCM_S24DAUD:
n = buf_size / 3;
for(;n>0;n--) { for(;n>0;n--) {
uint32_t v = bytestream_get_be24(&src); uint32_t v = bytestream_get_be24(&src);
v >>= 4; // sync flags are here v >>= 4; // sync flags are here
...@@ -413,49 +411,45 @@ static int pcm_decode_frame(AVCodecContext *avctx, ...@@ -413,49 +411,45 @@ static int pcm_decode_frame(AVCodecContext *avctx,
} }
break; break;
case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16LE:
n = buf_size >> 1;
for(;n>0;n--) { for(;n>0;n--) {
*samples++ = bytestream_get_le16(&src); *samples++ = bytestream_get_le16(&src);
} }
break; break;
case CODEC_ID_PCM_S16LE_PLANAR: case CODEC_ID_PCM_S16LE_PLANAR:
n /= avctx->channels;
for(c=0;c<avctx->channels;c++)
src2[c] = &src[c*n];
for(n>>=1;n>0;n--) for(n>>=1;n>0;n--)
for(c=0;c<avctx->channels;c++) for(c=0;c<avctx->channels;c++)
*samples++ = bytestream_get_le16(&src2[c]); *samples++ = bytestream_get_le16(&src2[c]);
src = src2[avctx->channels-1]; src = src2[avctx->channels-1];
break; break;
case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_S16BE:
n = buf_size >> 1;
for(;n>0;n--) { for(;n>0;n--) {
*samples++ = bytestream_get_be16(&src); *samples++ = bytestream_get_be16(&src);
} }
break; break;
case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_U16LE:
n = buf_size >> 1;
for(;n>0;n--) { for(;n>0;n--) {
*samples++ = bytestream_get_le16(&src) - 0x8000; *samples++ = bytestream_get_le16(&src) - 0x8000;
} }
break; break;
case CODEC_ID_PCM_U16BE: case CODEC_ID_PCM_U16BE:
n = buf_size >> 1;
for(;n>0;n--) { for(;n>0;n--) {
*samples++ = bytestream_get_be16(&src) - 0x8000; *samples++ = bytestream_get_be16(&src) - 0x8000;
} }
break; break;
case CODEC_ID_PCM_S8: case CODEC_ID_PCM_S8:
n = buf_size;
for(;n>0;n--) { for(;n>0;n--) {
*samples++ = *src++ << 8; *samples++ = *src++ << 8;
} }
break; break;
case CODEC_ID_PCM_U8: case CODEC_ID_PCM_U8:
n = buf_size;
for(;n>0;n--) { for(;n>0;n--) {
*samples++ = ((int)*src++ - 128) << 8; *samples++ = ((int)*src++ - 128) << 8;
} }
break; break;
case CODEC_ID_PCM_ZORK: case CODEC_ID_PCM_ZORK:
n = buf_size;
for(;n>0;n--) { for(;n>0;n--) {
int x= *src++; int x= *src++;
if(x&128) x-= 128; if(x&128) x-= 128;
...@@ -465,7 +459,6 @@ static int pcm_decode_frame(AVCodecContext *avctx, ...@@ -465,7 +459,6 @@ static int pcm_decode_frame(AVCodecContext *avctx,
break; break;
case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_ALAW:
case CODEC_ID_PCM_MULAW: case CODEC_ID_PCM_MULAW:
n = buf_size;
for(;n>0;n--) { for(;n>0;n--) {
*samples++ = s->table[*src++]; *samples++ = s->table[*src++];
} }
......
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