Commit 1e35574b authored by Justin Ruggles's avatar Justin Ruggles

adpcm_ima_wav: simplify encoding

parent cfc0a80a
...@@ -499,70 +499,51 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ...@@ -499,70 +499,51 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
switch(avctx->codec->id) { switch(avctx->codec->id) {
case AV_CODEC_ID_ADPCM_IMA_WAV: case AV_CODEC_ID_ADPCM_IMA_WAV:
n = frame->nb_samples / 8; {
c->status[0].prev_sample = samples[0]; int blocks, j, ch;
/* c->status[0].step_index = 0;
XXX: not sure how to init the state machine */ blocks = (frame->nb_samples - 1) / 8;
bytestream_put_le16(&dst, c->status[0].prev_sample);
*dst++ = c->status[0].step_index; for (ch = 0; ch < avctx->channels; ch++) {
*dst++ = 0; /* unknown */ ADPCMChannelStatus *status = &c->status[ch];
samples++; status->prev_sample = samples[ch];
if (avctx->channels == 2) { /* status->step_index = 0;
c->status[1].prev_sample = samples[0]; XXX: not sure how to init the state machine */
/* c->status[1].step_index = 0; */ bytestream_put_le16(&dst, status->prev_sample);
bytestream_put_le16(&dst, c->status[1].prev_sample); *dst++ = status->step_index;
*dst++ = c->status[1].step_index; *dst++ = 0; /* unknown */
*dst++ = 0;
samples++;
} }
/* stereo: 4 bytes (8 samples) for left, /* stereo: 4 bytes (8 samples) for left, 4 bytes for right */
4 bytes for right, 4 bytes left, ... */
if (avctx->trellis > 0) { if (avctx->trellis > 0) {
FF_ALLOC_OR_GOTO(avctx, buf, 2 * n * 8, error); FF_ALLOC_OR_GOTO(avctx, buf, avctx->channels * blocks * 8, error);
adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n * 8); for (ch = 0; ch < avctx->channels; ch++) {
if (avctx->channels == 2) adpcm_compress_trellis(avctx, &samples[avctx->channels + ch],
adpcm_compress_trellis(avctx, samples + 1, buf + n * 8, buf + ch * blocks * 8, &c->status[ch],
&c->status[1], n * 8); blocks * 8);
for (i = 0; i < n; i++) { }
*dst++ = buf[8 * i + 0] | (buf[8 * i + 1] << 4); for (i = 0; i < blocks; i++) {
*dst++ = buf[8 * i + 2] | (buf[8 * i + 3] << 4); for (ch = 0; ch < avctx->channels; ch++) {
*dst++ = buf[8 * i + 4] | (buf[8 * i + 5] << 4); uint8_t *buf1 = buf + ch * blocks * 8 + i * 8;
*dst++ = buf[8 * i + 6] | (buf[8 * i + 7] << 4); for (j = 0; j < 8; j += 2)
if (avctx->channels == 2) { *dst++ = buf1[j] | (buf1[j + 1] << 4);
uint8_t *buf1 = buf + n * 8;
*dst++ = buf1[8 * i + 0] | (buf1[8 * i + 1] << 4);
*dst++ = buf1[8 * i + 2] | (buf1[8 * i + 3] << 4);
*dst++ = buf1[8 * i + 4] | (buf1[8 * i + 5] << 4);
*dst++ = buf1[8 * i + 6] | (buf1[8 * i + 7] << 4);
} }
} }
av_free(buf); av_free(buf);
} else { } else {
for (; n > 0; n--) { for (i = 0; i < blocks; i++) {
*dst = adpcm_ima_compress_sample(&c->status[0], samples[0]); for (ch = 0; ch < avctx->channels; ch++) {
*dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels ]) << 4; ADPCMChannelStatus *status = &c->status[ch];
*dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]); const int16_t *smp = &samples[avctx->channels * (1 + i * 8) + ch];
*dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4; for (j = 0; j < 8; j += 2) {
*dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]); *dst++ = adpcm_ima_compress_sample(status, smp[avctx->channels * j ]) |
*dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4; (adpcm_ima_compress_sample(status, smp[avctx->channels * (j + 1)]) << 4);
*dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]); }
*dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4;
/* right channel */
if (avctx->channels == 2) {
*dst = adpcm_ima_compress_sample(&c->status[1], samples[1 ]);
*dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[3 ]) << 4;
*dst = adpcm_ima_compress_sample(&c->status[1], samples[5 ]);
*dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[7 ]) << 4;
*dst = adpcm_ima_compress_sample(&c->status[1], samples[9 ]);
*dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
*dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
*dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
} }
samples += 8 * avctx->channels;
} }
} }
break; break;
}
case AV_CODEC_ID_ADPCM_IMA_QT: case AV_CODEC_ID_ADPCM_IMA_QT:
{ {
int ch, i; int ch, i;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment