mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-24 11:49:48 +00: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,
|
||||
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--;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user