2 * Copyright (c) 2001-2003 The FFmpeg project
4 * first version by Francois Revol (revol@free.fr)
5 * fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
6 * by Mike Melanson (melanson@pcisys.net)
7 * CD-ROM XA ADPCM codec by BERO
8 * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
9 * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org)
10 * EA IMA EACS decoder by Peter Ross (pross@xvid.org)
11 * EA IMA SEAD decoder by Peter Ross (pross@xvid.org)
12 * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org)
13 * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com)
14 * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl)
15 * Argonaut Games ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
16 * Simon & Schuster Interactive ADPCM decoder by Zane van Iperen (zane@zanevaniperen.com)
18 * This file is part of FFmpeg.
20 * FFmpeg is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
25 * FFmpeg is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with FFmpeg; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36 #include "bytestream.h"
38 #include "adpcm_data.h"
44 * Features and limitations:
46 * Reference documents:
47 * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs
48 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead]
49 * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead]
50 * http://openquicktime.sourceforge.net/
51 * XAnim sources (xa_codec.c) http://xanim.polter.net/
52 * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead]
53 * SoX source code http://sox.sourceforge.net/
56 * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead]
57 * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead]
58 * readstr http://www.geocities.co.jp/Playtown/2004/
61 /* These are for CD-ROM XA ADPCM */
62 static const int8_t xa_adpcm_table[5][2] = {
70 static const int16_t ea_adpcm_table[] = {
78 // padded to zero where table size is less then 16
79 static const int8_t swf_index_tables[4][16] = {
81 /*3*/ { -1, -1, 2, 4 },
82 /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
83 /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
88 typedef struct ADPCMDecodeContext {
89 ADPCMChannelStatus status[14];
90 int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */
94 static av_cold int adpcm_decode_init(AVCodecContext * avctx)
96 ADPCMDecodeContext *c = avctx->priv_data;
97 unsigned int min_channels = 1;
98 unsigned int max_channels = 2;
100 switch(avctx->codec->id) {
101 case AV_CODEC_ID_ADPCM_DTK:
102 case AV_CODEC_ID_ADPCM_EA:
105 case AV_CODEC_ID_ADPCM_AFC:
106 case AV_CODEC_ID_ADPCM_EA_R1:
107 case AV_CODEC_ID_ADPCM_EA_R2:
108 case AV_CODEC_ID_ADPCM_EA_R3:
109 case AV_CODEC_ID_ADPCM_EA_XAS:
110 case AV_CODEC_ID_ADPCM_MS:
113 case AV_CODEC_ID_ADPCM_MTAF:
116 if (avctx->channels & 1) {
117 avpriv_request_sample(avctx, "channel count %d\n", avctx->channels);
118 return AVERROR_PATCHWELCOME;
121 case AV_CODEC_ID_ADPCM_PSX:
124 case AV_CODEC_ID_ADPCM_IMA_DAT4:
125 case AV_CODEC_ID_ADPCM_THP:
126 case AV_CODEC_ID_ADPCM_THP_LE:
130 if (avctx->channels < min_channels || avctx->channels > max_channels) {
131 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
132 return AVERROR(EINVAL);
135 switch(avctx->codec->id) {
136 case AV_CODEC_ID_ADPCM_CT:
137 c->status[0].step = c->status[1].step = 511;
139 case AV_CODEC_ID_ADPCM_IMA_WAV:
140 if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5)
141 return AVERROR_INVALIDDATA;
143 case AV_CODEC_ID_ADPCM_IMA_APC:
144 if (avctx->extradata && avctx->extradata_size >= 8) {
145 c->status[0].predictor = av_clip_intp2(AV_RL32(avctx->extradata ), 18);
146 c->status[1].predictor = av_clip_intp2(AV_RL32(avctx->extradata + 4), 18);
149 case AV_CODEC_ID_ADPCM_IMA_WS:
150 if (avctx->extradata && avctx->extradata_size >= 2)
151 c->vqa_version = AV_RL16(avctx->extradata);
153 case AV_CODEC_ID_ADPCM_ARGO:
154 if (avctx->bits_per_coded_sample != 4)
155 return AVERROR_INVALIDDATA;
161 switch(avctx->codec->id) {
162 case AV_CODEC_ID_ADPCM_AICA:
163 case AV_CODEC_ID_ADPCM_IMA_DAT4:
164 case AV_CODEC_ID_ADPCM_IMA_QT:
165 case AV_CODEC_ID_ADPCM_IMA_WAV:
166 case AV_CODEC_ID_ADPCM_4XM:
167 case AV_CODEC_ID_ADPCM_XA:
168 case AV_CODEC_ID_ADPCM_EA_R1:
169 case AV_CODEC_ID_ADPCM_EA_R2:
170 case AV_CODEC_ID_ADPCM_EA_R3:
171 case AV_CODEC_ID_ADPCM_EA_XAS:
172 case AV_CODEC_ID_ADPCM_THP:
173 case AV_CODEC_ID_ADPCM_THP_LE:
174 case AV_CODEC_ID_ADPCM_AFC:
175 case AV_CODEC_ID_ADPCM_DTK:
176 case AV_CODEC_ID_ADPCM_PSX:
177 case AV_CODEC_ID_ADPCM_MTAF:
178 case AV_CODEC_ID_ADPCM_ARGO:
179 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
181 case AV_CODEC_ID_ADPCM_IMA_WS:
182 avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P :
185 case AV_CODEC_ID_ADPCM_MS:
186 avctx->sample_fmt = avctx->channels > 2 ? AV_SAMPLE_FMT_S16P :
190 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
196 static inline int16_t adpcm_agm_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
198 int delta, pred, step, add;
203 add = (delta * 2 + 1) * step;
207 if ((nibble & 8) == 0)
208 pred = av_clip(pred + (add >> 3), -32767, 32767);
210 pred = av_clip(pred - (add >> 3), -32767, 32767);
217 c->step = av_clip(c->step * 2, 127, 24576);
235 c->step = av_clip(c->step, 127, 24576);
240 static inline int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
244 int sign, delta, diff, step;
246 step = ff_adpcm_step_table[c->step_index];
247 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
248 step_index = av_clip(step_index, 0, 88);
252 /* perform direct multiplication instead of series of jumps proposed by
253 * the reference ADPCM implementation since modern CPUs can do the mults
255 diff = ((2 * delta + 1) * step) >> shift;
256 predictor = c->predictor;
257 if (sign) predictor -= diff;
258 else predictor += diff;
260 c->predictor = av_clip_int16(predictor);
261 c->step_index = step_index;
263 return (int16_t)c->predictor;
266 static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
268 int nibble, step_index, predictor, sign, delta, diff, step, shift;
271 nibble = get_bits_le(gb, bps),
272 step = ff_adpcm_step_table[c->step_index];
273 step_index = c->step_index + ff_adpcm_index_tables[bps - 2][nibble];
274 step_index = av_clip(step_index, 0, 88);
276 sign = nibble & (1 << shift);
277 delta = av_mod_uintp2(nibble, shift);
278 diff = ((2 * delta + 1) * step) >> shift;
279 predictor = c->predictor;
280 if (sign) predictor -= diff;
281 else predictor += diff;
283 c->predictor = av_clip_int16(predictor);
284 c->step_index = step_index;
286 return (int16_t)c->predictor;
289 static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
295 step = ff_adpcm_step_table[c->step_index];
296 step_index = c->step_index + ff_adpcm_index_table[nibble];
297 step_index = av_clip(step_index, 0, 88);
300 if (nibble & 4) diff += step;
301 if (nibble & 2) diff += step >> 1;
302 if (nibble & 1) diff += step >> 2;
305 predictor = c->predictor - diff;
307 predictor = c->predictor + diff;
309 c->predictor = av_clip_int16(predictor);
310 c->step_index = step_index;
315 static inline int16_t adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
319 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
320 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
322 c->sample2 = c->sample1;
323 c->sample1 = av_clip_int16(predictor);
324 c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
325 if (c->idelta < 16) c->idelta = 16;
326 if (c->idelta > INT_MAX/768) {
327 av_log(NULL, AV_LOG_WARNING, "idelta overflow\n");
328 c->idelta = INT_MAX/768;
334 static inline int16_t adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
336 int step_index, predictor, sign, delta, diff, step;
338 step = ff_adpcm_oki_step_table[c->step_index];
339 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
340 step_index = av_clip(step_index, 0, 48);
344 diff = ((2 * delta + 1) * step) >> 3;
345 predictor = c->predictor;
346 if (sign) predictor -= diff;
347 else predictor += diff;
349 c->predictor = av_clip_intp2(predictor, 11);
350 c->step_index = step_index;
352 return c->predictor * 16;
355 static inline int16_t adpcm_ct_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
357 int sign, delta, diff;
362 /* perform direct multiplication instead of series of jumps proposed by
363 * the reference ADPCM implementation since modern CPUs can do the mults
365 diff = ((2 * delta + 1) * c->step) >> 3;
366 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
367 c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
368 c->predictor = av_clip_int16(c->predictor);
369 /* calculate new step and clamp it to range 511..32767 */
370 new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
371 c->step = av_clip(new_step, 511, 32767);
373 return (int16_t)c->predictor;
376 static inline int16_t adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int size, int shift)
378 int sign, delta, diff;
380 sign = nibble & (1<<(size-1));
381 delta = nibble & ((1<<(size-1))-1);
382 diff = delta << (7 + c->step + shift);
385 c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
387 /* calculate new step */
388 if (delta >= (2*size - 3) && c->step < 3)
390 else if (delta == 0 && c->step > 0)
393 return (int16_t) c->predictor;
396 static inline int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
403 c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
404 c->predictor = av_clip_int16(c->predictor);
405 c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
406 c->step = av_clip(c->step, 127, 24576);
410 static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
412 c->predictor += ff_adpcm_mtaf_stepsize[c->step][nibble];
413 c->predictor = av_clip_int16(c->predictor);
414 c->step += ff_adpcm_index_table[nibble];
415 c->step = av_clip_uintp2(c->step, 5);
419 static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1,
420 const uint8_t *in, ADPCMChannelStatus *left,
421 ADPCMChannelStatus *right, int channels, int sample_offset)
424 int shift,filter,f0,f1;
428 out0 += sample_offset;
432 out1 += sample_offset;
435 shift = 12 - (in[4+i*2] & 15);
436 filter = in[4+i*2] >> 4;
437 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
438 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
441 f0 = xa_adpcm_table[filter][0];
442 f1 = xa_adpcm_table[filter][1];
450 t = sign_extend(d, 4);
451 s = t*(1<<shift) + ((s_1*f0 + s_2*f1+32)>>6);
453 s_1 = av_clip_int16(s);
460 s_1 = right->sample1;
461 s_2 = right->sample2;
464 shift = 12 - (in[5+i*2] & 15);
465 filter = in[5+i*2] >> 4;
466 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
467 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
471 f0 = xa_adpcm_table[filter][0];
472 f1 = xa_adpcm_table[filter][1];
477 t = sign_extend(d >> 4, 4);
478 s = t*(1<<shift) + ((s_1*f0 + s_2*f1+32)>>6);
480 s_1 = av_clip_int16(s);
485 right->sample1 = s_1;
486 right->sample2 = s_2;
492 out0 += 28 * (3 - channels);
493 out1 += 28 * (3 - channels);
499 static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
501 ADPCMDecodeContext *c = avctx->priv_data;
504 int k0, signmask, nb_bits, count;
505 int size = buf_size*8;
508 init_get_bits(&gb, buf, size);
510 //read bits & initial values
511 nb_bits = get_bits(&gb, 2)+2;
512 table = swf_index_tables[nb_bits-2];
513 k0 = 1 << (nb_bits-2);
514 signmask = 1 << (nb_bits-1);
516 while (get_bits_count(&gb) <= size - 22*avctx->channels) {
517 for (i = 0; i < avctx->channels; i++) {
518 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
519 c->status[i].step_index = get_bits(&gb, 6);
522 for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
525 for (i = 0; i < avctx->channels; i++) {
526 // similar to IMA adpcm
527 int delta = get_bits(&gb, nb_bits);
528 int step = ff_adpcm_step_table[c->status[i].step_index];
529 int vpdiff = 0; // vpdiff = (delta+0.5)*step/4
540 if (delta & signmask)
541 c->status[i].predictor -= vpdiff;
543 c->status[i].predictor += vpdiff;
545 c->status[i].step_index += table[delta & (~signmask)];
547 c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
548 c->status[i].predictor = av_clip_int16(c->status[i].predictor);
550 *samples++ = c->status[i].predictor;
556 static inline int16_t adpcm_argo_expand_nibble(ADPCMChannelStatus *cs, int nibble, int control, int shift)
558 int sample = nibble * (1 << shift);
561 sample += (8 * cs->sample1) - (4 * cs->sample2);
563 sample += 4 * cs->sample1;
565 sample = av_clip_int16(sample >> 2);
567 cs->sample2 = cs->sample1;
568 cs->sample1 = sample;
574 * Get the number of samples that will be decoded from the packet.
575 * In one case, this is actually the maximum number of samples possible to
576 * decode with the given buf_size.
578 * @param[out] coded_samples set to the number of samples as coded in the
579 * packet, or 0 if the codec does not encode the
580 * number of samples in each frame.
581 * @param[out] approx_nb_samples set to non-zero if the number of samples
582 * returned is an approximation.
584 static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
585 int buf_size, int *coded_samples, int *approx_nb_samples)
587 ADPCMDecodeContext *s = avctx->priv_data;
589 int ch = avctx->channels;
590 int has_coded_samples = 0;
594 *approx_nb_samples = 0;
599 switch (avctx->codec->id) {
600 /* constant, only check buf_size */
601 case AV_CODEC_ID_ADPCM_EA_XAS:
602 if (buf_size < 76 * ch)
606 case AV_CODEC_ID_ADPCM_IMA_QT:
607 if (buf_size < 34 * ch)
611 case AV_CODEC_ID_ADPCM_ARGO:
612 if (buf_size < 17 * ch)
616 /* simple 4-bit adpcm */
617 case AV_CODEC_ID_ADPCM_CT:
618 case AV_CODEC_ID_ADPCM_IMA_APC:
619 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
620 case AV_CODEC_ID_ADPCM_IMA_OKI:
621 case AV_CODEC_ID_ADPCM_IMA_WS:
622 case AV_CODEC_ID_ADPCM_YAMAHA:
623 case AV_CODEC_ID_ADPCM_AICA:
624 case AV_CODEC_ID_ADPCM_IMA_SSI:
625 nb_samples = buf_size * 2 / ch;
631 /* simple 4-bit adpcm, with header */
633 switch (avctx->codec->id) {
634 case AV_CODEC_ID_ADPCM_4XM:
635 case AV_CODEC_ID_ADPCM_AGM:
636 case AV_CODEC_ID_ADPCM_IMA_DAT4:
637 case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
638 case AV_CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break;
639 case AV_CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4 * ch; break;
642 return (buf_size - header_size) * 2 / ch;
644 /* more complex formats */
645 switch (avctx->codec->id) {
646 case AV_CODEC_ID_ADPCM_EA:
647 has_coded_samples = 1;
648 *coded_samples = bytestream2_get_le32(gb);
649 *coded_samples -= *coded_samples % 28;
650 nb_samples = (buf_size - 12) / 30 * 28;
652 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
653 has_coded_samples = 1;
654 *coded_samples = bytestream2_get_le32(gb);
655 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
657 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
658 nb_samples = (buf_size - ch) / ch * 2;
660 case AV_CODEC_ID_ADPCM_EA_R1:
661 case AV_CODEC_ID_ADPCM_EA_R2:
662 case AV_CODEC_ID_ADPCM_EA_R3:
663 /* maximum number of samples */
664 /* has internal offsets and a per-frame switch to signal raw 16-bit */
665 has_coded_samples = 1;
666 switch (avctx->codec->id) {
667 case AV_CODEC_ID_ADPCM_EA_R1:
668 header_size = 4 + 9 * ch;
669 *coded_samples = bytestream2_get_le32(gb);
671 case AV_CODEC_ID_ADPCM_EA_R2:
672 header_size = 4 + 5 * ch;
673 *coded_samples = bytestream2_get_le32(gb);
675 case AV_CODEC_ID_ADPCM_EA_R3:
676 header_size = 4 + 5 * ch;
677 *coded_samples = bytestream2_get_be32(gb);
680 *coded_samples -= *coded_samples % 28;
681 nb_samples = (buf_size - header_size) * 2 / ch;
682 nb_samples -= nb_samples % 28;
683 *approx_nb_samples = 1;
685 case AV_CODEC_ID_ADPCM_IMA_DK3:
686 if (avctx->block_align > 0)
687 buf_size = FFMIN(buf_size, avctx->block_align);
688 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
690 case AV_CODEC_ID_ADPCM_IMA_DK4:
691 if (avctx->block_align > 0)
692 buf_size = FFMIN(buf_size, avctx->block_align);
693 if (buf_size < 4 * ch)
694 return AVERROR_INVALIDDATA;
695 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
697 case AV_CODEC_ID_ADPCM_IMA_RAD:
698 if (avctx->block_align > 0)
699 buf_size = FFMIN(buf_size, avctx->block_align);
700 nb_samples = (buf_size - 4 * ch) * 2 / ch;
702 case AV_CODEC_ID_ADPCM_IMA_WAV:
704 int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
705 int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
706 if (avctx->block_align > 0)
707 buf_size = FFMIN(buf_size, avctx->block_align);
708 if (buf_size < 4 * ch)
709 return AVERROR_INVALIDDATA;
710 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
713 case AV_CODEC_ID_ADPCM_MS:
714 if (avctx->block_align > 0)
715 buf_size = FFMIN(buf_size, avctx->block_align);
716 nb_samples = (buf_size - 6 * ch) * 2 / ch;
718 case AV_CODEC_ID_ADPCM_MTAF:
719 if (avctx->block_align > 0)
720 buf_size = FFMIN(buf_size, avctx->block_align);
721 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
723 case AV_CODEC_ID_ADPCM_SBPRO_2:
724 case AV_CODEC_ID_ADPCM_SBPRO_3:
725 case AV_CODEC_ID_ADPCM_SBPRO_4:
727 int samples_per_byte;
728 switch (avctx->codec->id) {
729 case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
730 case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
731 case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
733 if (!s->status[0].step_index) {
735 return AVERROR_INVALIDDATA;
739 nb_samples += buf_size * samples_per_byte / ch;
742 case AV_CODEC_ID_ADPCM_SWF:
744 int buf_bits = buf_size * 8 - 2;
745 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
746 int block_hdr_size = 22 * ch;
747 int block_size = block_hdr_size + nbits * ch * 4095;
748 int nblocks = buf_bits / block_size;
749 int bits_left = buf_bits - nblocks * block_size;
750 nb_samples = nblocks * 4096;
751 if (bits_left >= block_hdr_size)
752 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
755 case AV_CODEC_ID_ADPCM_THP:
756 case AV_CODEC_ID_ADPCM_THP_LE:
757 if (avctx->extradata) {
758 nb_samples = buf_size * 14 / (8 * ch);
761 has_coded_samples = 1;
762 bytestream2_skip(gb, 4); // channel size
763 *coded_samples = (avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE) ?
764 bytestream2_get_le32(gb) :
765 bytestream2_get_be32(gb);
766 buf_size -= 8 + 36 * ch;
768 nb_samples = buf_size / 8 * 14;
769 if (buf_size % 8 > 1)
770 nb_samples += (buf_size % 8 - 1) * 2;
771 *approx_nb_samples = 1;
773 case AV_CODEC_ID_ADPCM_AFC:
774 nb_samples = buf_size / (9 * ch) * 16;
776 case AV_CODEC_ID_ADPCM_XA:
777 nb_samples = (buf_size / 128) * 224 / ch;
779 case AV_CODEC_ID_ADPCM_DTK:
780 case AV_CODEC_ID_ADPCM_PSX:
781 nb_samples = buf_size / (16 * ch) * 28;
785 /* validate coded sample count */
786 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
787 return AVERROR_INVALIDDATA;
792 static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
793 int *got_frame_ptr, AVPacket *avpkt)
795 AVFrame *frame = data;
796 const uint8_t *buf = avpkt->data;
797 int buf_size = avpkt->size;
798 ADPCMDecodeContext *c = avctx->priv_data;
799 ADPCMChannelStatus *cs;
800 int n, m, channel, i;
805 int nb_samples, coded_samples, approx_nb_samples, ret;
808 bytestream2_init(&gb, buf, buf_size);
809 nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
810 if (nb_samples <= 0) {
811 av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
812 return AVERROR_INVALIDDATA;
815 /* get output buffer */
816 frame->nb_samples = nb_samples;
817 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
819 samples = (int16_t *)frame->data[0];
820 samples_p = (int16_t **)frame->extended_data;
822 /* use coded_samples when applicable */
823 /* it is always <= nb_samples, so the output buffer will be large enough */
825 if (!approx_nb_samples && coded_samples != nb_samples)
826 av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
827 frame->nb_samples = nb_samples = coded_samples;
830 st = avctx->channels == 2 ? 1 : 0;
832 switch(avctx->codec->id) {
833 case AV_CODEC_ID_ADPCM_IMA_QT:
834 /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
835 Channel data is interleaved per-chunk. */
836 for (channel = 0; channel < avctx->channels; channel++) {
839 cs = &(c->status[channel]);
840 /* (pppppp) (piiiiiii) */
842 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
843 predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
844 step_index = predictor & 0x7F;
847 if (cs->step_index == step_index) {
848 int diff = predictor - cs->predictor;
855 cs->step_index = step_index;
856 cs->predictor = predictor;
859 if (cs->step_index > 88u){
860 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
861 channel, cs->step_index);
862 return AVERROR_INVALIDDATA;
865 samples = samples_p[channel];
867 for (m = 0; m < 64; m += 2) {
868 int byte = bytestream2_get_byteu(&gb);
869 samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);
870 samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 , 3);
874 case AV_CODEC_ID_ADPCM_IMA_WAV:
875 for(i=0; i<avctx->channels; i++){
876 cs = &(c->status[i]);
877 cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
879 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
880 if (cs->step_index > 88u){
881 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
883 return AVERROR_INVALIDDATA;
887 if (avctx->bits_per_coded_sample != 4) {
888 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
889 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
890 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
893 for (n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
894 for (i = 0; i < avctx->channels; i++) {
898 samples = &samples_p[i][1 + n * samples_per_block];
899 for (j = 0; j < block_size; j++) {
900 temp[j] = buf[4 * avctx->channels + block_size * n * avctx->channels +
901 (j % 4) + (j / 4) * (avctx->channels * 4) + i * 4];
903 ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size);
906 for (m = 0; m < samples_per_block; m++) {
907 samples[m] = adpcm_ima_wav_expand_nibble(cs, &g,
908 avctx->bits_per_coded_sample);
912 bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4);
914 for (n = 0; n < (nb_samples - 1) / 8; n++) {
915 for (i = 0; i < avctx->channels; i++) {
917 samples = &samples_p[i][1 + n * 8];
918 for (m = 0; m < 8; m += 2) {
919 int v = bytestream2_get_byteu(&gb);
920 samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
921 samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
927 case AV_CODEC_ID_ADPCM_4XM:
928 for (i = 0; i < avctx->channels; i++)
929 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
931 for (i = 0; i < avctx->channels; i++) {
932 c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
933 if (c->status[i].step_index > 88u) {
934 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
935 i, c->status[i].step_index);
936 return AVERROR_INVALIDDATA;
940 for (i = 0; i < avctx->channels; i++) {
941 samples = (int16_t *)frame->data[i];
943 for (n = nb_samples >> 1; n > 0; n--) {
944 int v = bytestream2_get_byteu(&gb);
945 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
946 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
950 case AV_CODEC_ID_ADPCM_AGM:
951 for (i = 0; i < avctx->channels; i++)
952 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
953 for (i = 0; i < avctx->channels; i++)
954 c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16);
956 for (n = 0; n < nb_samples >> (1 - st); n++) {
957 int v = bytestream2_get_byteu(&gb);
958 *samples++ = adpcm_agm_expand_nibble(&c->status[0], v & 0xF);
959 *samples++ = adpcm_agm_expand_nibble(&c->status[st], v >> 4 );
962 case AV_CODEC_ID_ADPCM_MS:
966 if (avctx->channels > 2) {
967 for (channel = 0; channel < avctx->channels; channel++) {
968 samples = samples_p[channel];
969 block_predictor = bytestream2_get_byteu(&gb);
970 if (block_predictor > 6) {
971 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[%d] = %d\n",
972 channel, block_predictor);
973 return AVERROR_INVALIDDATA;
975 c->status[channel].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
976 c->status[channel].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
977 c->status[channel].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
978 c->status[channel].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
979 c->status[channel].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
980 *samples++ = c->status[channel].sample2;
981 *samples++ = c->status[channel].sample1;
982 for(n = (nb_samples - 2) >> 1; n > 0; n--) {
983 int byte = bytestream2_get_byteu(&gb);
984 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte >> 4 );
985 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte & 0x0F);
989 block_predictor = bytestream2_get_byteu(&gb);
990 if (block_predictor > 6) {
991 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
993 return AVERROR_INVALIDDATA;
995 c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
996 c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
998 block_predictor = bytestream2_get_byteu(&gb);
999 if (block_predictor > 6) {
1000 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
1002 return AVERROR_INVALIDDATA;
1004 c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
1005 c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
1007 c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1009 c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
1012 c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1013 if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
1014 c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1015 if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
1017 *samples++ = c->status[0].sample2;
1018 if (st) *samples++ = c->status[1].sample2;
1019 *samples++ = c->status[0].sample1;
1020 if (st) *samples++ = c->status[1].sample1;
1021 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
1022 int byte = bytestream2_get_byteu(&gb);
1023 *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
1024 *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
1029 case AV_CODEC_ID_ADPCM_MTAF:
1030 for (channel = 0; channel < avctx->channels; channel+=2) {
1031 bytestream2_skipu(&gb, 4);
1032 c->status[channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
1033 c->status[channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1034 c->status[channel ].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1035 bytestream2_skipu(&gb, 2);
1036 c->status[channel + 1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1037 bytestream2_skipu(&gb, 2);
1038 for (n = 0; n < nb_samples; n+=2) {
1039 int v = bytestream2_get_byteu(&gb);
1040 samples_p[channel][n ] = adpcm_mtaf_expand_nibble(&c->status[channel], v & 0x0F);
1041 samples_p[channel][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel], v >> 4 );
1043 for (n = 0; n < nb_samples; n+=2) {
1044 int v = bytestream2_get_byteu(&gb);
1045 samples_p[channel + 1][n ] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v & 0x0F);
1046 samples_p[channel + 1][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v >> 4 );
1050 case AV_CODEC_ID_ADPCM_IMA_DK4:
1051 for (channel = 0; channel < avctx->channels; channel++) {
1052 cs = &c->status[channel];
1053 cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
1054 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1055 if (cs->step_index > 88u){
1056 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1057 channel, cs->step_index);
1058 return AVERROR_INVALIDDATA;
1061 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1062 int v = bytestream2_get_byteu(&gb);
1063 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
1064 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1067 case AV_CODEC_ID_ADPCM_IMA_DK3:
1071 int decode_top_nibble_next = 0;
1073 const int16_t *samples_end = samples + avctx->channels * nb_samples;
1075 bytestream2_skipu(&gb, 10);
1076 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1077 c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1078 c->status[0].step_index = bytestream2_get_byteu(&gb);
1079 c->status[1].step_index = bytestream2_get_byteu(&gb);
1080 if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
1081 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
1082 c->status[0].step_index, c->status[1].step_index);
1083 return AVERROR_INVALIDDATA;
1085 /* sign extend the predictors */
1086 diff_channel = c->status[1].predictor;
1088 /* DK3 ADPCM support macro */
1089 #define DK3_GET_NEXT_NIBBLE() \
1090 if (decode_top_nibble_next) { \
1091 nibble = last_byte >> 4; \
1092 decode_top_nibble_next = 0; \
1094 last_byte = bytestream2_get_byteu(&gb); \
1095 nibble = last_byte & 0x0F; \
1096 decode_top_nibble_next = 1; \
1099 while (samples < samples_end) {
1101 /* for this algorithm, c->status[0] is the sum channel and
1102 * c->status[1] is the diff channel */
1104 /* process the first predictor of the sum channel */
1105 DK3_GET_NEXT_NIBBLE();
1106 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1108 /* process the diff channel predictor */
1109 DK3_GET_NEXT_NIBBLE();
1110 adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
1112 /* process the first pair of stereo PCM samples */
1113 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1114 *samples++ = c->status[0].predictor + c->status[1].predictor;
1115 *samples++ = c->status[0].predictor - c->status[1].predictor;
1117 /* process the second predictor of the sum channel */
1118 DK3_GET_NEXT_NIBBLE();
1119 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1121 /* process the second pair of stereo PCM samples */
1122 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1123 *samples++ = c->status[0].predictor + c->status[1].predictor;
1124 *samples++ = c->status[0].predictor - c->status[1].predictor;
1127 if ((bytestream2_tell(&gb) & 1))
1128 bytestream2_skip(&gb, 1);
1131 case AV_CODEC_ID_ADPCM_IMA_ISS:
1132 for (channel = 0; channel < avctx->channels; channel++) {
1133 cs = &c->status[channel];
1134 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1135 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1136 if (cs->step_index > 88u){
1137 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1138 channel, cs->step_index);
1139 return AVERROR_INVALIDDATA;
1143 for (n = nb_samples >> (1 - st); n > 0; n--) {
1145 int v = bytestream2_get_byteu(&gb);
1146 /* nibbles are swapped for mono */
1154 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
1155 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
1158 case AV_CODEC_ID_ADPCM_IMA_DAT4:
1159 for (channel = 0; channel < avctx->channels; channel++) {
1160 cs = &c->status[channel];
1161 samples = samples_p[channel];
1162 bytestream2_skip(&gb, 4);
1163 for (n = 0; n < nb_samples; n += 2) {
1164 int v = bytestream2_get_byteu(&gb);
1165 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1166 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1170 case AV_CODEC_ID_ADPCM_IMA_APC:
1171 while (bytestream2_get_bytes_left(&gb) > 0) {
1172 int v = bytestream2_get_byteu(&gb);
1173 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
1174 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1177 case AV_CODEC_ID_ADPCM_IMA_SSI:
1178 while (bytestream2_get_bytes_left(&gb) > 0) {
1179 int v = bytestream2_get_byteu(&gb);
1180 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0], v >> 4 , 3);
1181 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0x0F, 3);
1184 case AV_CODEC_ID_ADPCM_IMA_OKI:
1185 while (bytestream2_get_bytes_left(&gb) > 0) {
1186 int v = bytestream2_get_byteu(&gb);
1187 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0], v >> 4 );
1188 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);
1191 case AV_CODEC_ID_ADPCM_IMA_RAD:
1192 for (channel = 0; channel < avctx->channels; channel++) {
1193 cs = &c->status[channel];
1194 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1195 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1196 if (cs->step_index > 88u){
1197 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1198 channel, cs->step_index);
1199 return AVERROR_INVALIDDATA;
1202 for (n = 0; n < nb_samples / 2; n++) {
1205 byte[0] = bytestream2_get_byteu(&gb);
1207 byte[1] = bytestream2_get_byteu(&gb);
1208 for(channel = 0; channel < avctx->channels; channel++) {
1209 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
1211 for(channel = 0; channel < avctx->channels; channel++) {
1212 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3);
1216 case AV_CODEC_ID_ADPCM_IMA_WS:
1217 if (c->vqa_version == 3) {
1218 for (channel = 0; channel < avctx->channels; channel++) {
1219 int16_t *smp = samples_p[channel];
1221 for (n = nb_samples / 2; n > 0; n--) {
1222 int v = bytestream2_get_byteu(&gb);
1223 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1224 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1228 for (n = nb_samples / 2; n > 0; n--) {
1229 for (channel = 0; channel < avctx->channels; channel++) {
1230 int v = bytestream2_get_byteu(&gb);
1231 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1232 samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1234 samples += avctx->channels;
1237 bytestream2_seek(&gb, 0, SEEK_END);
1239 case AV_CODEC_ID_ADPCM_XA:
1241 int16_t *out0 = samples_p[0];
1242 int16_t *out1 = samples_p[1];
1243 int samples_per_block = 28 * (3 - avctx->channels) * 4;
1244 int sample_offset = 0;
1245 int bytes_remaining;
1246 while (bytestream2_get_bytes_left(&gb) >= 128) {
1247 if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
1248 &c->status[0], &c->status[1],
1249 avctx->channels, sample_offset)) < 0)
1251 bytestream2_skipu(&gb, 128);
1252 sample_offset += samples_per_block;
1254 /* Less than a full block of data left, e.g. when reading from
1255 * 2324 byte per sector XA; the remainder is padding */
1256 bytes_remaining = bytestream2_get_bytes_left(&gb);
1257 if (bytes_remaining > 0) {
1258 bytestream2_skip(&gb, bytes_remaining);
1262 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1263 for (i=0; i<=st; i++) {
1264 c->status[i].step_index = bytestream2_get_le32u(&gb);
1265 if (c->status[i].step_index > 88u) {
1266 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1267 i, c->status[i].step_index);
1268 return AVERROR_INVALIDDATA;
1271 for (i=0; i<=st; i++) {
1272 c->status[i].predictor = bytestream2_get_le32u(&gb);
1273 if (FFABS((int64_t)c->status[i].predictor) > (1<<16))
1274 return AVERROR_INVALIDDATA;
1277 for (n = nb_samples >> (1 - st); n > 0; n--) {
1278 int byte = bytestream2_get_byteu(&gb);
1279 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
1280 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
1283 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1284 for (n = nb_samples >> (1 - st); n > 0; n--) {
1285 int byte = bytestream2_get_byteu(&gb);
1286 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6);
1287 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
1290 case AV_CODEC_ID_ADPCM_EA:
1292 int previous_left_sample, previous_right_sample;
1293 int current_left_sample, current_right_sample;
1294 int next_left_sample, next_right_sample;
1295 int coeff1l, coeff2l, coeff1r, coeff2r;
1296 int shift_left, shift_right;
1298 /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
1299 each coding 28 stereo samples. */
1301 if(avctx->channels != 2)
1302 return AVERROR_INVALIDDATA;
1304 current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1305 previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1306 current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1307 previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1309 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1310 int byte = bytestream2_get_byteu(&gb);
1311 coeff1l = ea_adpcm_table[ byte >> 4 ];
1312 coeff2l = ea_adpcm_table[(byte >> 4 ) + 4];
1313 coeff1r = ea_adpcm_table[ byte & 0x0F];
1314 coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
1316 byte = bytestream2_get_byteu(&gb);
1317 shift_left = 20 - (byte >> 4);
1318 shift_right = 20 - (byte & 0x0F);
1320 for (count2 = 0; count2 < 28; count2++) {
1321 byte = bytestream2_get_byteu(&gb);
1322 next_left_sample = sign_extend(byte >> 4, 4) * (1 << shift_left);
1323 next_right_sample = sign_extend(byte, 4) * (1 << shift_right);
1325 next_left_sample = (next_left_sample +
1326 (current_left_sample * coeff1l) +
1327 (previous_left_sample * coeff2l) + 0x80) >> 8;
1328 next_right_sample = (next_right_sample +
1329 (current_right_sample * coeff1r) +
1330 (previous_right_sample * coeff2r) + 0x80) >> 8;
1332 previous_left_sample = current_left_sample;
1333 current_left_sample = av_clip_int16(next_left_sample);
1334 previous_right_sample = current_right_sample;
1335 current_right_sample = av_clip_int16(next_right_sample);
1336 *samples++ = current_left_sample;
1337 *samples++ = current_right_sample;
1341 bytestream2_skip(&gb, 2); // Skip terminating 0x0000
1345 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1347 int coeff[2][2], shift[2];
1349 for(channel = 0; channel < avctx->channels; channel++) {
1350 int byte = bytestream2_get_byteu(&gb);
1352 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
1353 shift[channel] = 20 - (byte & 0x0F);
1355 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1358 byte[0] = bytestream2_get_byteu(&gb);
1359 if (st) byte[1] = bytestream2_get_byteu(&gb);
1360 for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
1361 for(channel = 0; channel < avctx->channels; channel++) {
1362 int sample = sign_extend(byte[channel] >> i, 4) * (1 << shift[channel]);
1364 c->status[channel].sample1 * coeff[channel][0] +
1365 c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
1366 c->status[channel].sample2 = c->status[channel].sample1;
1367 c->status[channel].sample1 = av_clip_int16(sample);
1368 *samples++ = c->status[channel].sample1;
1372 bytestream2_seek(&gb, 0, SEEK_END);
1375 case AV_CODEC_ID_ADPCM_EA_R1:
1376 case AV_CODEC_ID_ADPCM_EA_R2:
1377 case AV_CODEC_ID_ADPCM_EA_R3: {
1378 /* channel numbering
1380 4chan: 0=fl, 1=rl, 2=fr, 3=rr
1381 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
1382 const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
1383 int previous_sample, current_sample, next_sample;
1386 unsigned int channel;
1391 for (channel=0; channel<avctx->channels; channel++)
1392 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1393 bytestream2_get_le32(&gb)) +
1394 (avctx->channels + 1) * 4;
1396 for (channel=0; channel<avctx->channels; channel++) {
1397 bytestream2_seek(&gb, offsets[channel], SEEK_SET);
1398 samplesC = samples_p[channel];
1400 if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
1401 current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1402 previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1404 current_sample = c->status[channel].predictor;
1405 previous_sample = c->status[channel].prev_sample;
1408 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1409 int byte = bytestream2_get_byte(&gb);
1410 if (byte == 0xEE) { /* only seen in R2 and R3 */
1411 current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
1412 previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
1414 for (count2=0; count2<28; count2++)
1415 *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);
1417 coeff1 = ea_adpcm_table[ byte >> 4 ];
1418 coeff2 = ea_adpcm_table[(byte >> 4) + 4];
1419 shift = 20 - (byte & 0x0F);
1421 for (count2=0; count2<28; count2++) {
1423 next_sample = (unsigned)sign_extend(byte, 4) << shift;
1425 byte = bytestream2_get_byte(&gb);
1426 next_sample = (unsigned)sign_extend(byte >> 4, 4) << shift;
1429 next_sample += (current_sample * coeff1) +
1430 (previous_sample * coeff2);
1431 next_sample = av_clip_int16(next_sample >> 8);
1433 previous_sample = current_sample;
1434 current_sample = next_sample;
1435 *samplesC++ = current_sample;
1441 } else if (count != count1) {
1442 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
1443 count = FFMAX(count, count1);
1446 if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
1447 c->status[channel].predictor = current_sample;
1448 c->status[channel].prev_sample = previous_sample;
1452 frame->nb_samples = count * 28;
1453 bytestream2_seek(&gb, 0, SEEK_END);
1456 case AV_CODEC_ID_ADPCM_EA_XAS:
1457 for (channel=0; channel<avctx->channels; channel++) {
1458 int coeff[2][4], shift[4];
1459 int16_t *s = samples_p[channel];
1460 for (n = 0; n < 4; n++, s += 32) {
1461 int val = sign_extend(bytestream2_get_le16u(&gb), 16);
1463 coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
1466 val = sign_extend(bytestream2_get_le16u(&gb), 16);
1467 shift[n] = 20 - (val & 0x0F);
1471 for (m=2; m<32; m+=2) {
1472 s = &samples_p[channel][m];
1473 for (n = 0; n < 4; n++, s += 32) {
1475 int byte = bytestream2_get_byteu(&gb);
1477 level = sign_extend(byte >> 4, 4) * (1 << shift[n]);
1478 pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
1479 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1481 level = sign_extend(byte, 4) * (1 << shift[n]);
1482 pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
1483 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1488 case AV_CODEC_ID_ADPCM_IMA_AMV:
1489 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1490 c->status[0].step_index = bytestream2_get_byteu(&gb);
1491 bytestream2_skipu(&gb, 5);
1492 if (c->status[0].step_index > 88u) {
1493 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
1494 c->status[0].step_index);
1495 return AVERROR_INVALIDDATA;
1498 for (n = nb_samples >> (1 - st); n > 0; n--) {
1499 int v = bytestream2_get_byteu(&gb);
1501 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
1502 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);
1505 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1506 for (i = 0; i < avctx->channels; i++) {
1507 c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
1508 c->status[i].step_index = bytestream2_get_byteu(&gb);
1509 bytestream2_skipu(&gb, 1);
1510 if (c->status[i].step_index > 88u) {
1511 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
1512 c->status[i].step_index);
1513 return AVERROR_INVALIDDATA;
1517 for (n = nb_samples >> (1 - st); n > 0; n--) {
1518 int v = bytestream2_get_byteu(&gb);
1520 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3);
1521 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3);
1524 case AV_CODEC_ID_ADPCM_CT:
1525 for (n = nb_samples >> (1 - st); n > 0; n--) {
1526 int v = bytestream2_get_byteu(&gb);
1527 *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
1528 *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
1531 case AV_CODEC_ID_ADPCM_SBPRO_4:
1532 case AV_CODEC_ID_ADPCM_SBPRO_3:
1533 case AV_CODEC_ID_ADPCM_SBPRO_2:
1534 if (!c->status[0].step_index) {
1535 /* the first byte is a raw sample */
1536 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1538 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1539 c->status[0].step_index = 1;
1542 if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
1543 for (n = nb_samples >> (1 - st); n > 0; n--) {
1544 int byte = bytestream2_get_byteu(&gb);
1545 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1547 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1550 } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
1551 for (n = (nb_samples<<st) / 3; n > 0; n--) {
1552 int byte = bytestream2_get_byteu(&gb);
1553 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1555 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1556 (byte >> 2) & 0x07, 3, 0);
1557 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1561 for (n = nb_samples >> (2 - st); n > 0; n--) {
1562 int byte = bytestream2_get_byteu(&gb);
1563 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1565 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1566 (byte >> 4) & 0x03, 2, 2);
1567 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1568 (byte >> 2) & 0x03, 2, 2);
1569 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1574 case AV_CODEC_ID_ADPCM_SWF:
1575 adpcm_swf_decode(avctx, buf, buf_size, samples);
1576 bytestream2_seek(&gb, 0, SEEK_END);
1578 case AV_CODEC_ID_ADPCM_YAMAHA:
1579 for (n = nb_samples >> (1 - st); n > 0; n--) {
1580 int v = bytestream2_get_byteu(&gb);
1581 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
1582 *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
1585 case AV_CODEC_ID_ADPCM_AICA:
1586 if (!c->has_status) {
1587 for (channel = 0; channel < avctx->channels; channel++)
1588 c->status[channel].step = 0;
1591 for (channel = 0; channel < avctx->channels; channel++) {
1592 samples = samples_p[channel];
1593 for (n = nb_samples >> 1; n > 0; n--) {
1594 int v = bytestream2_get_byteu(&gb);
1595 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v & 0x0F);
1596 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v >> 4 );
1600 case AV_CODEC_ID_ADPCM_AFC:
1602 int samples_per_block;
1605 if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
1606 samples_per_block = avctx->extradata[0] / 16;
1607 blocks = nb_samples / avctx->extradata[0];
1609 samples_per_block = nb_samples / 16;
1613 for (m = 0; m < blocks; m++) {
1614 for (channel = 0; channel < avctx->channels; channel++) {
1615 int prev1 = c->status[channel].sample1;
1616 int prev2 = c->status[channel].sample2;
1618 samples = samples_p[channel] + m * 16;
1619 /* Read in every sample for this channel. */
1620 for (i = 0; i < samples_per_block; i++) {
1621 int byte = bytestream2_get_byteu(&gb);
1622 int scale = 1 << (byte >> 4);
1623 int index = byte & 0xf;
1624 int factor1 = ff_adpcm_afc_coeffs[0][index];
1625 int factor2 = ff_adpcm_afc_coeffs[1][index];
1627 /* Decode 16 samples. */
1628 for (n = 0; n < 16; n++) {
1632 sampledat = sign_extend(byte, 4);
1634 byte = bytestream2_get_byteu(&gb);
1635 sampledat = sign_extend(byte >> 4, 4);
1638 sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) +
1640 *samples = av_clip_int16(sampledat);
1646 c->status[channel].sample1 = prev1;
1647 c->status[channel].sample2 = prev2;
1650 bytestream2_seek(&gb, 0, SEEK_END);
1653 case AV_CODEC_ID_ADPCM_THP:
1654 case AV_CODEC_ID_ADPCM_THP_LE:
1659 #define THP_GET16(g) \
1661 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
1662 bytestream2_get_le16u(&(g)) : \
1663 bytestream2_get_be16u(&(g)), 16)
1665 if (avctx->extradata) {
1667 if (avctx->extradata_size < 32 * avctx->channels) {
1668 av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
1669 return AVERROR_INVALIDDATA;
1672 bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
1673 for (i = 0; i < avctx->channels; i++)
1674 for (n = 0; n < 16; n++)
1675 table[i][n] = THP_GET16(tb);
1677 for (i = 0; i < avctx->channels; i++)
1678 for (n = 0; n < 16; n++)
1679 table[i][n] = THP_GET16(gb);
1681 if (!c->has_status) {
1682 /* Initialize the previous sample. */
1683 for (i = 0; i < avctx->channels; i++) {
1684 c->status[i].sample1 = THP_GET16(gb);
1685 c->status[i].sample2 = THP_GET16(gb);
1689 bytestream2_skip(&gb, avctx->channels * 4);
1693 for (ch = 0; ch < avctx->channels; ch++) {
1694 samples = samples_p[ch];
1696 /* Read in every sample for this channel. */
1697 for (i = 0; i < (nb_samples + 13) / 14; i++) {
1698 int byte = bytestream2_get_byteu(&gb);
1699 int index = (byte >> 4) & 7;
1700 unsigned int exp = byte & 0x0F;
1701 int factor1 = table[ch][index * 2];
1702 int factor2 = table[ch][index * 2 + 1];
1704 /* Decode 14 samples. */
1705 for (n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
1709 sampledat = sign_extend(byte, 4);
1711 byte = bytestream2_get_byteu(&gb);
1712 sampledat = sign_extend(byte >> 4, 4);
1715 sampledat = ((c->status[ch].sample1 * factor1
1716 + c->status[ch].sample2 * factor2) >> 11) + sampledat * (1 << exp);
1717 *samples = av_clip_int16(sampledat);
1718 c->status[ch].sample2 = c->status[ch].sample1;
1719 c->status[ch].sample1 = *samples++;
1725 case AV_CODEC_ID_ADPCM_DTK:
1726 for (channel = 0; channel < avctx->channels; channel++) {
1727 samples = samples_p[channel];
1729 /* Read in every sample for this channel. */
1730 for (i = 0; i < nb_samples / 28; i++) {
1733 bytestream2_skipu(&gb, 1);
1734 header = bytestream2_get_byteu(&gb);
1735 bytestream2_skipu(&gb, 3 - channel);
1737 /* Decode 28 samples. */
1738 for (n = 0; n < 28; n++) {
1739 int32_t sampledat, prev;
1741 switch (header >> 4) {
1743 prev = (c->status[channel].sample1 * 0x3c);
1746 prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
1749 prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
1755 prev = av_clip_intp2((prev + 0x20) >> 6, 21);
1757 byte = bytestream2_get_byteu(&gb);
1759 sampledat = sign_extend(byte, 4);
1761 sampledat = sign_extend(byte >> 4, 4);
1763 sampledat = ((sampledat * (1 << 12)) >> (header & 0xf)) * (1 << 6) + prev;
1764 *samples++ = av_clip_int16(sampledat >> 6);
1765 c->status[channel].sample2 = c->status[channel].sample1;
1766 c->status[channel].sample1 = sampledat;
1770 bytestream2_seek(&gb, 0, SEEK_SET);
1773 case AV_CODEC_ID_ADPCM_PSX:
1774 for (channel = 0; channel < avctx->channels; channel++) {
1775 samples = samples_p[channel];
1777 /* Read in every sample for this channel. */
1778 for (i = 0; i < nb_samples / 28; i++) {
1779 int filter, shift, flag, byte;
1781 filter = bytestream2_get_byteu(&gb);
1782 shift = filter & 0xf;
1783 filter = filter >> 4;
1784 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table))
1785 return AVERROR_INVALIDDATA;
1786 flag = bytestream2_get_byteu(&gb);
1788 /* Decode 28 samples. */
1789 for (n = 0; n < 28; n++) {
1790 int sample = 0, scale;
1794 scale = sign_extend(byte >> 4, 4);
1796 byte = bytestream2_get_byteu(&gb);
1797 scale = sign_extend(byte, 4);
1800 scale = scale << 12;
1801 sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64);
1803 *samples++ = av_clip_int16(sample);
1804 c->status[channel].sample2 = c->status[channel].sample1;
1805 c->status[channel].sample1 = sample;
1810 case AV_CODEC_ID_ADPCM_ARGO:
1812 * The format of each block:
1813 * uint8_t left_control;
1814 * uint4_t left_samples[nb_samples];
1815 * ---- and if stereo ----
1816 * uint8_t right_control;
1817 * uint4_t right_samples[nb_samples];
1819 * Format of the control byte:
1820 * MSB [SSSSDRRR] LSB
1821 * S = (Shift Amount - 2)
1825 * Each block relies on the previous two samples of each channel.
1826 * They should be 0 initially.
1828 for (channel = 0; channel < avctx->channels; channel++) {
1831 samples = samples_p[channel];
1832 cs = c->status + channel;
1834 /* Get the control byte and decode the samples, 2 at a time. */
1835 control = bytestream2_get_byteu(&gb);
1836 shift = (control >> 4) + 2;
1838 for (n = 0; n < nb_samples / 2; n++) {
1839 int sample = bytestream2_get_byteu(&gb);
1840 *samples++ = adpcm_argo_expand_nibble(cs, sign_extend(sample >> 4, 4), control, shift);
1841 *samples++ = adpcm_argo_expand_nibble(cs, sign_extend(sample >> 0, 4), control, shift);
1846 av_assert0(0); // unsupported codec_id should not happen
1849 if (avpkt->size && bytestream2_tell(&gb) == 0) {
1850 av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");
1851 return AVERROR_INVALIDDATA;
1856 if (avpkt->size < bytestream2_tell(&gb)) {
1857 av_log(avctx, AV_LOG_ERROR, "Overread of %d < %d\n", avpkt->size, bytestream2_tell(&gb));
1861 return bytestream2_tell(&gb);
1864 static void adpcm_flush(AVCodecContext *avctx)
1866 ADPCMDecodeContext *c = avctx->priv_data;
1871 static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
1872 AV_SAMPLE_FMT_NONE };
1873 static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16P,
1874 AV_SAMPLE_FMT_NONE };
1875 static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16,
1877 AV_SAMPLE_FMT_NONE };
1879 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
1880 AVCodec ff_ ## name_ ## _decoder = { \
1882 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
1883 .type = AVMEDIA_TYPE_AUDIO, \
1885 .priv_data_size = sizeof(ADPCMDecodeContext), \
1886 .init = adpcm_decode_init, \
1887 .decode = adpcm_decode_frame, \
1888 .flush = adpcm_flush, \
1889 .capabilities = AV_CODEC_CAP_DR1, \
1890 .sample_fmts = sample_fmts_, \
1893 /* Note: Do not forget to add new entries to the Makefile as well. */
1894 ADPCM_DECODER(AV_CODEC_ID_ADPCM_4XM, sample_fmts_s16p, adpcm_4xm, "ADPCM 4X Movie");
1895 ADPCM_DECODER(AV_CODEC_ID_ADPCM_AFC, sample_fmts_s16p, adpcm_afc, "ADPCM Nintendo Gamecube AFC");
1896 ADPCM_DECODER(AV_CODEC_ID_ADPCM_AGM, sample_fmts_s16, adpcm_agm, "ADPCM AmuseGraphics Movie");
1897 ADPCM_DECODER(AV_CODEC_ID_ADPCM_AICA, sample_fmts_s16p, adpcm_aica, "ADPCM Yamaha AICA");
1898 ADPCM_DECODER(AV_CODEC_ID_ADPCM_ARGO, sample_fmts_s16p, adpcm_argo, "ADPCM Argonaut Games");
1899 ADPCM_DECODER(AV_CODEC_ID_ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology");
1900 ADPCM_DECODER(AV_CODEC_ID_ADPCM_DTK, sample_fmts_s16p, adpcm_dtk, "ADPCM Nintendo Gamecube DTK");
1901 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts");
1902 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
1903 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1, "ADPCM Electronic Arts R1");
1904 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2, "ADPCM Electronic Arts R2");
1905 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3, "ADPCM Electronic Arts R3");
1906 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
1907 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV");
1908 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC");
1909 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DAT4, sample_fmts_s16, adpcm_ima_dat4, "ADPCM IMA Eurocom DAT4");
1910 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
1911 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
1912 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
1913 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
1914 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
1915 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_OKI, sample_fmts_s16, adpcm_ima_oki, "ADPCM IMA Dialogic OKI");
1916 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, "ADPCM IMA QuickTime");
1917 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad, "ADPCM IMA Radical");
1918 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SSI, sample_fmts_s16, adpcm_ima_ssi, "ADPCM IMA Simon & Schuster Interactive");
1919 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
1920 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV");
1921 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood");
1922 ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Microsoft");
1923 ADPCM_DECODER(AV_CODEC_ID_ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF");
1924 ADPCM_DECODER(AV_CODEC_ID_ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation");
1925 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
1926 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
1927 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
1928 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash");
1929 ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le, "ADPCM Nintendo THP (little-endian)");
1930 ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo THP");
1931 ADPCM_DECODER(AV_CODEC_ID_ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA");
1932 ADPCM_DECODER(AV_CODEC_ID_ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha");