1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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.
This commit is contained in:
Justin Ruggles 2011-09-11 12:04:46 -04:00
parent 76db17dc7d
commit 04b24cf94b

View File

@ -43,7 +43,7 @@
typedef struct DPCMContext { typedef struct DPCMContext {
int channels; int channels;
short roq_square_array[256]; 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 const int *sol_table;//for SOL_DPCM
} DPCMContext; } DPCMContext;
@ -155,7 +155,11 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
break; 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; return 0;
} }
@ -285,18 +289,17 @@ static int dpcm_decode_frame(AVCodecContext *avctx,
case CODEC_ID_SOL_DPCM: case CODEC_ID_SOL_DPCM:
in = 0; in = 0;
if (avctx->codec_tag != 3) { if (avctx->codec_tag != 3) {
uint8_t *output_samples_u8 = data;
while (in < buf_size) { while (in < buf_size) {
int n1, n2; uint8_t n = buf[in++];
n1 = (buf[in] >> 4) & 0xF;
n2 = buf[in++] & 0xF; s->sample[0] += s->sol_table[n >> 4];
s->sample[0] += s->sol_table[n1]; s->sample[0] = av_clip_uint8(s->sample[0]);
if (s->sample[0] < 0) s->sample[0] = 0; *output_samples_u8++ = s->sample[0];
if (s->sample[0] > 255) s->sample[0] = 255;
*output_samples++ = (s->sample[0] - 128) << 8; s->sample[stereo] += s->sol_table[n & 0x0F];
s->sample[stereo] += s->sol_table[n2]; s->sample[stereo] = av_clip_uint8(s->sample[stereo]);
if (s->sample[stereo] < 0) s->sample[stereo] = 0; *output_samples_u8++ = s->sample[stereo];
if (s->sample[stereo] > 255) s->sample[stereo] = 255;
*output_samples++ = (s->sample[stereo] - 128) << 8;
} }
} else { } else {
while (in < buf_size) { while (in < buf_size) {