mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-28 20:53:54 +02:00
ws_snd: decode to AV_SAMPLE_FMT_U8 instead of S16.
8-bit unsigned is the native sample format.
This commit is contained in:
parent
4c5e7b27d5
commit
2322ced8da
@ -37,13 +37,11 @@ static const int8_t ws_adpcm_4bit[] = {
|
|||||||
-9, -8, -6, -5, -4, -3, -2, -1,
|
-9, -8, -6, -5, -4, -3, -2, -1,
|
||||||
0, 1, 2, 3, 4, 5, 6, 8 };
|
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)
|
static av_cold int ws_snd_decode_init(AVCodecContext * avctx)
|
||||||
{
|
{
|
||||||
// WSSNDContext *c = avctx->priv_data;
|
// WSSNDContext *c = avctx->priv_data;
|
||||||
|
|
||||||
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
|
avctx->sample_fmt = AV_SAMPLE_FMT_U8;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,15 +54,14 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
|
|||||||
// WSSNDContext *c = avctx->priv_data;
|
// WSSNDContext *c = avctx->priv_data;
|
||||||
|
|
||||||
int in_size, out_size;
|
int in_size, out_size;
|
||||||
int sample = 0;
|
int sample = 128;
|
||||||
int i;
|
int i;
|
||||||
short *samples = data;
|
uint8_t *samples = data;
|
||||||
|
|
||||||
if (!buf_size)
|
if (!buf_size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_size = AV_RL16(&buf[0]);
|
out_size = AV_RL16(&buf[0]);
|
||||||
*data_size = out_size * 2;
|
|
||||||
in_size = AV_RL16(&buf[2]);
|
in_size = AV_RL16(&buf[2]);
|
||||||
buf += 4;
|
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");
|
av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*data_size = out_size;
|
||||||
|
|
||||||
if (in_size == out_size) {
|
if (in_size == out_size) {
|
||||||
for (i = 0; i < out_size; i++)
|
for (i = 0; i < out_size; i++)
|
||||||
*samples++ = (*buf++ - 0x80) << 8;
|
*samples++ = *buf++;
|
||||||
return buf_size;
|
return buf_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,17 +93,17 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
|
|||||||
for (count++; count > 0; count--) {
|
for (count++; count > 0; count--) {
|
||||||
code = *buf++;
|
code = *buf++;
|
||||||
sample += ws_adpcm_2bit[code & 0x3];
|
sample += ws_adpcm_2bit[code & 0x3];
|
||||||
CLIP8(sample);
|
sample = av_clip_uint8(sample);
|
||||||
*samples++ = sample << 8;
|
*samples++ = sample;
|
||||||
sample += ws_adpcm_2bit[(code >> 2) & 0x3];
|
sample += ws_adpcm_2bit[(code >> 2) & 0x3];
|
||||||
CLIP8(sample);
|
sample = av_clip_uint8(sample);
|
||||||
*samples++ = sample << 8;
|
*samples++ = sample;
|
||||||
sample += ws_adpcm_2bit[(code >> 4) & 0x3];
|
sample += ws_adpcm_2bit[(code >> 4) & 0x3];
|
||||||
CLIP8(sample);
|
sample = av_clip_uint8(sample);
|
||||||
*samples++ = sample << 8;
|
*samples++ = sample;
|
||||||
sample += ws_adpcm_2bit[(code >> 6) & 0x3];
|
sample += ws_adpcm_2bit[(code >> 6) & 0x3];
|
||||||
CLIP8(sample);
|
sample = av_clip_uint8(sample);
|
||||||
*samples++ = sample << 8;
|
*samples++ = sample;
|
||||||
out_size -= 4;
|
out_size -= 4;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -111,11 +111,11 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
|
|||||||
for (count++; count > 0; count--) {
|
for (count++; count > 0; count--) {
|
||||||
code = *buf++;
|
code = *buf++;
|
||||||
sample += ws_adpcm_4bit[code & 0xF];
|
sample += ws_adpcm_4bit[code & 0xF];
|
||||||
CLIP8(sample);
|
sample = av_clip_uint8(sample);
|
||||||
*samples++ = sample << 8;
|
*samples++ = sample;
|
||||||
sample += ws_adpcm_4bit[code >> 4];
|
sample += ws_adpcm_4bit[code >> 4];
|
||||||
CLIP8(sample);
|
sample = av_clip_uint8(sample);
|
||||||
*samples++ = sample << 8;
|
*samples++ = sample;
|
||||||
out_size -= 2;
|
out_size -= 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -125,19 +125,20 @@ static int ws_snd_decode_frame(AVCodecContext *avctx,
|
|||||||
t = count;
|
t = count;
|
||||||
t <<= 3;
|
t <<= 3;
|
||||||
sample += t >> 3;
|
sample += t >> 3;
|
||||||
*samples++ = sample << 8;
|
sample = av_clip_uint8(sample);
|
||||||
|
*samples++ = sample;
|
||||||
out_size--;
|
out_size--;
|
||||||
} else { /* copy */
|
} else { /* copy */
|
||||||
for (count++; count > 0; count--) {
|
for (count++; count > 0; count--) {
|
||||||
*samples++ = (*buf++ - 0x80) << 8;
|
*samples++ = *buf++;
|
||||||
out_size--;
|
out_size--;
|
||||||
}
|
}
|
||||||
sample = buf[-1] - 0x80;
|
sample = buf[-1];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: /* run */
|
default: /* run */
|
||||||
for(count++; count > 0; count--) {
|
for(count++; count > 0; count--) {
|
||||||
*samples++ = sample << 8;
|
*samples++ = sample;
|
||||||
out_size--;
|
out_size--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user