1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

adpcm: convert adpcm_ea_r1/2/3 to bytestream2.

This commit is contained in:
Ronald S. Bultje 2012-03-17 15:07:03 -07:00
parent e60d09918c
commit edd9555537

View File

@ -421,20 +421,18 @@ static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf,
/* maximum number of samples */ /* maximum number of samples */
/* has internal offsets and a per-frame switch to signal raw 16-bit */ /* has internal offsets and a per-frame switch to signal raw 16-bit */
has_coded_samples = 1; has_coded_samples = 1;
if (buf_size < 4)
return 0;
switch (avctx->codec->id) { switch (avctx->codec->id) {
case CODEC_ID_ADPCM_EA_R1: case CODEC_ID_ADPCM_EA_R1:
header_size = 4 + 9 * ch; header_size = 4 + 9 * ch;
*coded_samples = AV_RL32(buf); *coded_samples = bytestream2_get_le32(gb);
break; break;
case CODEC_ID_ADPCM_EA_R2: case CODEC_ID_ADPCM_EA_R2:
header_size = 4 + 5 * ch; header_size = 4 + 5 * ch;
*coded_samples = AV_RL32(buf); *coded_samples = bytestream2_get_le32(gb);
break; break;
case CODEC_ID_ADPCM_EA_R3: case CODEC_ID_ADPCM_EA_R3:
header_size = 4 + 5 * ch; header_size = 4 + 5 * ch;
*coded_samples = AV_RB32(buf); *coded_samples = bytestream2_get_be32(gb);
break; break;
} }
*coded_samples -= *coded_samples % 28; *coded_samples -= *coded_samples % 28;
@ -954,56 +952,53 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
4chan: 0=fl, 1=rl, 2=fr, 3=rr 4chan: 0=fl, 1=rl, 2=fr, 3=rr
6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */ 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3; const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3;
int32_t previous_sample, current_sample, next_sample; int previous_sample, current_sample, next_sample;
int32_t coeff1, coeff2; int coeff1, coeff2;
uint8_t shift; int shift;
unsigned int channel; unsigned int channel;
uint16_t *samplesC; uint16_t *samplesC;
const uint8_t *srcC;
const uint8_t *src_end = buf + buf_size;
int count = 0; int count = 0;
int offsets[6];
src += 4; // skip sample count (already read) for (channel=0; channel<avctx->channels; channel++)
offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
bytestream2_get_le32(&gb)) +
(avctx->channels + 1) * 4;
for (channel=0; channel<avctx->channels; channel++) { for (channel=0; channel<avctx->channels; channel++) {
int32_t offset = (big_endian ? bytestream_get_be32(&src) bytestream2_seek(&gb, offsets[channel], SEEK_SET);
: bytestream_get_le32(&src))
+ (avctx->channels-channel-1) * 4;
if ((offset < 0) || (offset >= src_end - src - 4)) break;
srcC = src + offset;
samplesC = samples + channel; samplesC = samples + channel;
if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) { if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) {
current_sample = (int16_t)bytestream_get_le16(&srcC); current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
previous_sample = (int16_t)bytestream_get_le16(&srcC); previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
} else { } else {
current_sample = c->status[channel].predictor; current_sample = c->status[channel].predictor;
previous_sample = c->status[channel].prev_sample; previous_sample = c->status[channel].prev_sample;
} }
for (count1 = 0; count1 < nb_samples / 28; count1++) { for (count1 = 0; count1 < nb_samples / 28; count1++) {
if (*srcC == 0xEE) { /* only seen in R2 and R3 */ int byte = bytestream2_get_byte(&gb);
srcC++; if (byte == 0xEE) { /* only seen in R2 and R3 */
if (srcC > src_end - 30*2) break; current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
current_sample = (int16_t)bytestream_get_be16(&srcC); previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
previous_sample = (int16_t)bytestream_get_be16(&srcC);
for (count2=0; count2<28; count2++) { for (count2=0; count2<28; count2++) {
*samplesC = (int16_t)bytestream_get_be16(&srcC); *samplesC = sign_extend(bytestream2_get_be16(&gb), 16);
samplesC += avctx->channels; samplesC += avctx->channels;
} }
} else { } else {
coeff1 = ea_adpcm_table[ *srcC>>4 ]; coeff1 = ea_adpcm_table[ byte >> 4 ];
coeff2 = ea_adpcm_table[(*srcC>>4) + 4]; coeff2 = ea_adpcm_table[(byte >> 4) + 4];
shift = 20 - (*srcC++ & 0x0F); shift = 20 - (byte & 0x0F);
if (srcC > src_end - 14) break;
for (count2=0; count2<28; count2++) { for (count2=0; count2<28; count2++) {
if (count2 & 1) if (count2 & 1)
next_sample = sign_extend(*srcC++, 4) << shift; next_sample = sign_extend(byte, 4) << shift;
else else {
next_sample = sign_extend(*srcC >> 4, 4) << shift; byte = bytestream2_get_byte(&gb);
next_sample = sign_extend(byte >> 4, 4) << shift;
}
next_sample += (current_sample * coeff1) + next_sample += (current_sample * coeff1) +
(previous_sample * coeff2); (previous_sample * coeff2);
@ -1030,7 +1025,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
} }
c->frame.nb_samples = count * 28; c->frame.nb_samples = count * 28;
src = src_end; bytestream2_seek(&gb, 0, SEEK_END);
break; break;
} }
case CODEC_ID_ADPCM_EA_XAS: case CODEC_ID_ADPCM_EA_XAS: