[FFmpeg-cvslog] ws_snd: decode to AV_SAMPLE_FMT_U8 instead of S16.
Justin Ruggles
git at videolan.org
Mon Apr 2 01:45:30 CEST 2012
ffmpeg | branch: release/0.8 | Justin Ruggles <justin.ruggles at gmail.com> | Mon Sep 12 08:55:43 2011 -0400| [137007b5bfbee8992ac088732c39cc1301bb7a3a] | committer: Reinhard Tartler
ws_snd: decode to AV_SAMPLE_FMT_U8 instead of S16.
8-bit unsigned is the native sample format.
(cherry picked from commit 2322ced8da990835717a176b8d2c32961cfecd3e)
Signed-off-by: Reinhard Tartler <siretart at tauware.de>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=137007b5bfbee8992ac088732c39cc1301bb7a3a
---
libavcodec/ws-snd1.c | 47 ++++++++++++++++++++++++-----------------------
1 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/libavcodec/ws-snd1.c b/libavcodec/ws-snd1.c
index 534be56..959c7bb 100644
--- a/libavcodec/ws-snd1.c
+++ b/libavcodec/ws-snd1.c
@@ -37,13 +37,11 @@ static const int8_t ws_adpcm_4bit[] = {
-9, -8, -6, -5, -4, -3, -2, -1,
0, 1, 2, 3, 4, 5, 6, 8 };
-#define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128;
-
static av_cold int ws_snd_decode_init(AVCodecContext * avctx)
{
// WSSNDContext *c = avctx->priv_data;
- avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avctx->sample_fmt = AV_SAMPLE_FMT_U8;
return 0;
}
@@ -56,15 +54,14 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
// WSSNDContext *c = avctx->priv_data;
int in_size, out_size;
- int sample = 0;
+ int sample = 128;
int i;
- short *samples = data;
+ uint8_t *samples = data;
if (!buf_size)
return 0;
out_size = AV_RL16(&buf[0]);
- *data_size = out_size * 2;
in_size = AV_RL16(&buf[2]);
buf += 4;
@@ -76,9 +73,12 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n");
return -1;
}
+
+ *data_size = out_size;
+
if (in_size == out_size) {
for (i = 0; i < out_size; i++)
- *samples++ = (*buf++ - 0x80) << 8;
+ *samples++ = *buf++;
return buf_size;
}
@@ -93,17 +93,17 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
for (count++; count > 0; count--) {
code = *buf++;
sample += ws_adpcm_2bit[code & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
sample += ws_adpcm_2bit[(code >> 2) & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
sample += ws_adpcm_2bit[(code >> 4) & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
sample += ws_adpcm_2bit[(code >> 6) & 0x3];
- CLIP8(sample);
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
out_size -= 4;
}
break;
@@ -111,11 +111,11 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
for (count++; count > 0; count--) {
code = *buf++;
sample += ws_adpcm_4bit[code & 0xF];
- CLIP8(sample);
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
sample += ws_adpcm_4bit[code >> 4];
- CLIP8(sample);
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
out_size -= 2;
}
break;
@@ -125,19 +125,20 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
t = count;
t <<= 3;
sample += t >> 3;
- *samples++ = sample << 8;
+ sample = av_clip_uint8(sample);
+ *samples++ = sample;
out_size--;
} else { /* copy */
for (count++; count > 0; count--) {
- *samples++ = (*buf++ - 0x80) << 8;
+ *samples++ = *buf++;
out_size--;
}
- sample = buf[-1] - 0x80;
+ sample = buf[-1];
}
break;
default: /* run */
for(count++; count > 0; count--) {
- *samples++ = sample << 8;
+ *samples++ = sample;
out_size--;
}
}
More information about the ffmpeg-cvslog
mailing list