From 04b24cf94b3582f94a94e28506368d3ee54daad7 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 11 Sep 2011 12:04:46 -0400 Subject: [PATCH] dpcm: output AV_SAMPLE_FMT_U8 for Sol DPCM subcodecs 1 and 2. Uses the native sample format for the codec instead of left-shifting all samples by 8. --- libavcodec/dpcm.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c index 3f3b422d96..ef90ab30e1 100644 --- a/libavcodec/dpcm.c +++ b/libavcodec/dpcm.c @@ -43,7 +43,7 @@ typedef struct DPCMContext { int channels; short roq_square_array[256]; - long sample[2];//for SOL_DPCM + int sample[2]; ///< previous sample (for SOL_DPCM) const int *sol_table;//for SOL_DPCM } DPCMContext; @@ -155,7 +155,11 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx) break; } - avctx->sample_fmt = AV_SAMPLE_FMT_S16; + if (avctx->codec->id == CODEC_ID_SOL_DPCM && avctx->codec_tag != 3) + avctx->sample_fmt = AV_SAMPLE_FMT_U8; + else + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + return 0; } @@ -285,18 +289,17 @@ static int dpcm_decode_frame(AVCodecContext *avctx, case CODEC_ID_SOL_DPCM: in = 0; if (avctx->codec_tag != 3) { + uint8_t *output_samples_u8 = data; 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++ = (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++ = (s->sample[stereo] - 128) << 8; + uint8_t n = buf[in++]; + + s->sample[0] += s->sol_table[n >> 4]; + s->sample[0] = av_clip_uint8(s->sample[0]); + *output_samples_u8++ = s->sample[0]; + + s->sample[stereo] += s->sol_table[n & 0x0F]; + s->sample[stereo] = av_clip_uint8(s->sample[stereo]); + *output_samples_u8++ = s->sample[stereo]; } } else { while (in < buf_size) {