2 * Copyright (c) 2001-2003 The ffmpeg Project
4 * This file is part of Libav.
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "bytestream.h"
25 #include "adpcm_data.h"
30 * First version by Francois Revol (revol@free.fr)
31 * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
32 * by Mike Melanson (melanson@pcisys.net)
33 * CD-ROM XA ADPCM codec by BERO
34 * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
35 * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org)
36 * EA IMA EACS decoder by Peter Ross (pross@xvid.org)
37 * EA IMA SEAD decoder by Peter Ross (pross@xvid.org)
38 * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org)
39 * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com)
40 * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl)
42 * Features and limitations:
44 * Reference documents:
45 * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs
46 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead]
47 * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead]
48 * http://openquicktime.sourceforge.net/
49 * XAnim sources (xa_codec.c) http://xanim.polter.net/
50 * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead]
51 * SoX source code http://sox.sourceforge.net/
54 * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead]
55 * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead]
56 * readstr http://www.geocities.co.jp/Playtown/2004/
59 /* These are for CD-ROM XA ADPCM */
60 static const int xa_adpcm_table[5][2] = {
68 static const int ea_adpcm_table[] = {
76 // padded to zero where table size is less then 16
77 static const int swf_index_tables[4][16] = {
79 /*3*/ { -1, -1, 2, 4 },
80 /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
81 /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
86 typedef struct ADPCMDecodeContext {
88 ADPCMChannelStatus status[6];
89 int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */
92 static av_cold int adpcm_decode_init(AVCodecContext * avctx)
94 ADPCMDecodeContext *c = avctx->priv_data;
95 unsigned int min_channels = 1;
96 unsigned int max_channels = 2;
98 switch(avctx->codec->id) {
99 case AV_CODEC_ID_ADPCM_EA:
102 case AV_CODEC_ID_ADPCM_EA_R1:
103 case AV_CODEC_ID_ADPCM_EA_R2:
104 case AV_CODEC_ID_ADPCM_EA_R3:
105 case AV_CODEC_ID_ADPCM_EA_XAS:
109 if (avctx->channels < min_channels || avctx->channels > max_channels) {
110 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
111 return AVERROR(EINVAL);
114 switch(avctx->codec->id) {
115 case AV_CODEC_ID_ADPCM_CT:
116 c->status[0].step = c->status[1].step = 511;
118 case AV_CODEC_ID_ADPCM_IMA_WAV:
119 if (avctx->bits_per_coded_sample != 4) {
120 av_log(avctx, AV_LOG_ERROR, "Only 4-bit ADPCM IMA WAV files are supported\n");
124 case AV_CODEC_ID_ADPCM_IMA_APC:
125 if (avctx->extradata && avctx->extradata_size >= 8) {
126 c->status[0].predictor = AV_RL32(avctx->extradata);
127 c->status[1].predictor = AV_RL32(avctx->extradata + 4);
130 case AV_CODEC_ID_ADPCM_IMA_WS:
131 if (avctx->extradata && avctx->extradata_size >= 2)
132 c->vqa_version = AV_RL16(avctx->extradata);
138 switch(avctx->codec->id) {
139 case AV_CODEC_ID_ADPCM_IMA_QT:
140 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
143 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
146 avcodec_get_frame_defaults(&c->frame);
147 avctx->coded_frame = &c->frame;
152 static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
156 int sign, delta, diff, step;
158 step = ff_adpcm_step_table[c->step_index];
159 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
160 step_index = av_clip(step_index, 0, 88);
164 /* perform direct multiplication instead of series of jumps proposed by
165 * the reference ADPCM implementation since modern CPUs can do the mults
167 diff = ((2 * delta + 1) * step) >> shift;
168 predictor = c->predictor;
169 if (sign) predictor -= diff;
170 else predictor += diff;
172 c->predictor = av_clip_int16(predictor);
173 c->step_index = step_index;
175 return (short)c->predictor;
178 static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
184 step = ff_adpcm_step_table[c->step_index];
185 step_index = c->step_index + ff_adpcm_index_table[nibble];
186 step_index = av_clip(step_index, 0, 88);
189 if (nibble & 4) diff += step;
190 if (nibble & 2) diff += step >> 1;
191 if (nibble & 1) diff += step >> 2;
194 predictor = c->predictor - diff;
196 predictor = c->predictor + diff;
198 c->predictor = av_clip_int16(predictor);
199 c->step_index = step_index;
204 static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
208 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
209 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
211 c->sample2 = c->sample1;
212 c->sample1 = av_clip_int16(predictor);
213 c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
214 if (c->idelta < 16) c->idelta = 16;
219 static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
221 int sign, delta, diff;
226 /* perform direct multiplication instead of series of jumps proposed by
227 * the reference ADPCM implementation since modern CPUs can do the mults
229 diff = ((2 * delta + 1) * c->step) >> 3;
230 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
231 c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
232 c->predictor = av_clip_int16(c->predictor);
233 /* calculate new step and clamp it to range 511..32767 */
234 new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
235 c->step = av_clip(new_step, 511, 32767);
237 return (short)c->predictor;
240 static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
242 int sign, delta, diff;
244 sign = nibble & (1<<(size-1));
245 delta = nibble & ((1<<(size-1))-1);
246 diff = delta << (7 + c->step + shift);
249 c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
251 /* calculate new step */
252 if (delta >= (2*size - 3) && c->step < 3)
254 else if (delta == 0 && c->step > 0)
257 return (short) c->predictor;
260 static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
267 c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
268 c->predictor = av_clip_int16(c->predictor);
269 c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
270 c->step = av_clip(c->step, 127, 24567);
274 static int xa_decode(AVCodecContext *avctx,
275 short *out, const unsigned char *in,
276 ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
279 int shift,filter,f0,f1;
285 shift = 12 - (in[4+i*2] & 15);
286 filter = in[4+i*2] >> 4;
288 av_log(avctx, AV_LOG_ERROR,
289 "Invalid XA-ADPCM filter %d (max. allowed is 4)\n",
291 return AVERROR_INVALIDDATA;
293 f0 = xa_adpcm_table[filter][0];
294 f1 = xa_adpcm_table[filter][1];
302 t = sign_extend(d, 4);
303 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
305 s_1 = av_clip_int16(s);
310 if (inc==2) { /* stereo */
313 s_1 = right->sample1;
314 s_2 = right->sample2;
315 out = out + 1 - 28*2;
318 shift = 12 - (in[5+i*2] & 15);
319 filter = in[5+i*2] >> 4;
321 av_log(avctx, AV_LOG_ERROR,
322 "Invalid XA-ADPCM filter %d (max. allowed is 4)\n",
324 return AVERROR_INVALIDDATA;
326 f0 = xa_adpcm_table[filter][0];
327 f1 = xa_adpcm_table[filter][1];
332 t = sign_extend(d >> 4, 4);
333 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
335 s_1 = av_clip_int16(s);
340 if (inc==2) { /* stereo */
341 right->sample1 = s_1;
342 right->sample2 = s_2;
353 static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
355 ADPCMDecodeContext *c = avctx->priv_data;
358 int k0, signmask, nb_bits, count;
359 int size = buf_size*8;
362 init_get_bits(&gb, buf, size);
364 //read bits & initial values
365 nb_bits = get_bits(&gb, 2)+2;
366 table = swf_index_tables[nb_bits-2];
367 k0 = 1 << (nb_bits-2);
368 signmask = 1 << (nb_bits-1);
370 while (get_bits_count(&gb) <= size - 22*avctx->channels) {
371 for (i = 0; i < avctx->channels; i++) {
372 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
373 c->status[i].step_index = get_bits(&gb, 6);
376 for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
379 for (i = 0; i < avctx->channels; i++) {
380 // similar to IMA adpcm
381 int delta = get_bits(&gb, nb_bits);
382 int step = ff_adpcm_step_table[c->status[i].step_index];
383 long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
394 if (delta & signmask)
395 c->status[i].predictor -= vpdiff;
397 c->status[i].predictor += vpdiff;
399 c->status[i].step_index += table[delta & (~signmask)];
401 c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
402 c->status[i].predictor = av_clip_int16(c->status[i].predictor);
404 *samples++ = c->status[i].predictor;
411 * Get the number of samples that will be decoded from the packet.
412 * In one case, this is actually the maximum number of samples possible to
413 * decode with the given buf_size.
415 * @param[out] coded_samples set to the number of samples as coded in the
416 * packet, or 0 if the codec does not encode the
417 * number of samples in each frame.
419 static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
420 int buf_size, int *coded_samples)
422 ADPCMDecodeContext *s = avctx->priv_data;
424 int ch = avctx->channels;
425 int has_coded_samples = 0;
430 switch (avctx->codec->id) {
431 /* constant, only check buf_size */
432 case AV_CODEC_ID_ADPCM_EA_XAS:
433 if (buf_size < 76 * ch)
437 case AV_CODEC_ID_ADPCM_IMA_QT:
438 if (buf_size < 34 * ch)
442 /* simple 4-bit adpcm */
443 case AV_CODEC_ID_ADPCM_CT:
444 case AV_CODEC_ID_ADPCM_IMA_APC:
445 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
446 case AV_CODEC_ID_ADPCM_IMA_WS:
447 case AV_CODEC_ID_ADPCM_YAMAHA:
448 nb_samples = buf_size * 2 / ch;
454 /* simple 4-bit adpcm, with header */
456 switch (avctx->codec->id) {
457 case AV_CODEC_ID_ADPCM_4XM:
458 case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
459 case AV_CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break;
460 case AV_CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4; break;
463 return (buf_size - header_size) * 2 / ch;
465 /* more complex formats */
466 switch (avctx->codec->id) {
467 case AV_CODEC_ID_ADPCM_EA:
468 has_coded_samples = 1;
469 *coded_samples = bytestream2_get_le32(gb);
470 *coded_samples -= *coded_samples % 28;
471 nb_samples = (buf_size - 12) / 30 * 28;
473 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
474 has_coded_samples = 1;
475 *coded_samples = bytestream2_get_le32(gb);
476 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
478 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
479 nb_samples = (buf_size - ch) / ch * 2;
481 case AV_CODEC_ID_ADPCM_EA_R1:
482 case AV_CODEC_ID_ADPCM_EA_R2:
483 case AV_CODEC_ID_ADPCM_EA_R3:
484 /* maximum number of samples */
485 /* has internal offsets and a per-frame switch to signal raw 16-bit */
486 has_coded_samples = 1;
487 switch (avctx->codec->id) {
488 case AV_CODEC_ID_ADPCM_EA_R1:
489 header_size = 4 + 9 * ch;
490 *coded_samples = bytestream2_get_le32(gb);
492 case AV_CODEC_ID_ADPCM_EA_R2:
493 header_size = 4 + 5 * ch;
494 *coded_samples = bytestream2_get_le32(gb);
496 case AV_CODEC_ID_ADPCM_EA_R3:
497 header_size = 4 + 5 * ch;
498 *coded_samples = bytestream2_get_be32(gb);
501 *coded_samples -= *coded_samples % 28;
502 nb_samples = (buf_size - header_size) * 2 / ch;
503 nb_samples -= nb_samples % 28;
505 case AV_CODEC_ID_ADPCM_IMA_DK3:
506 if (avctx->block_align > 0)
507 buf_size = FFMIN(buf_size, avctx->block_align);
508 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
510 case AV_CODEC_ID_ADPCM_IMA_DK4:
511 if (avctx->block_align > 0)
512 buf_size = FFMIN(buf_size, avctx->block_align);
513 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
515 case AV_CODEC_ID_ADPCM_IMA_WAV:
516 if (avctx->block_align > 0)
517 buf_size = FFMIN(buf_size, avctx->block_align);
518 nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8;
520 case AV_CODEC_ID_ADPCM_MS:
521 if (avctx->block_align > 0)
522 buf_size = FFMIN(buf_size, avctx->block_align);
523 nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
525 case AV_CODEC_ID_ADPCM_SBPRO_2:
526 case AV_CODEC_ID_ADPCM_SBPRO_3:
527 case AV_CODEC_ID_ADPCM_SBPRO_4:
529 int samples_per_byte;
530 switch (avctx->codec->id) {
531 case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
532 case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
533 case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
535 if (!s->status[0].step_index) {
539 nb_samples += buf_size * samples_per_byte / ch;
542 case AV_CODEC_ID_ADPCM_SWF:
544 int buf_bits = buf_size * 8 - 2;
545 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
546 int block_hdr_size = 22 * ch;
547 int block_size = block_hdr_size + nbits * ch * 4095;
548 int nblocks = buf_bits / block_size;
549 int bits_left = buf_bits - nblocks * block_size;
550 nb_samples = nblocks * 4096;
551 if (bits_left >= block_hdr_size)
552 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
555 case AV_CODEC_ID_ADPCM_THP:
556 has_coded_samples = 1;
557 bytestream2_skip(gb, 4); // channel size
558 *coded_samples = bytestream2_get_be32(gb);
559 *coded_samples -= *coded_samples % 14;
560 nb_samples = (buf_size - 80) / (8 * ch) * 14;
562 case AV_CODEC_ID_ADPCM_XA:
563 nb_samples = (buf_size / 128) * 224 / ch;
567 /* validate coded sample count */
568 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
569 return AVERROR_INVALIDDATA;
574 static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
575 int *got_frame_ptr, AVPacket *avpkt)
577 const uint8_t *buf = avpkt->data;
578 int buf_size = avpkt->size;
579 ADPCMDecodeContext *c = avctx->priv_data;
580 ADPCMChannelStatus *cs;
581 int n, m, channel, i;
586 int nb_samples, coded_samples, ret;
589 bytestream2_init(&gb, buf, buf_size);
590 nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples);
591 if (nb_samples <= 0) {
592 av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
593 return AVERROR_INVALIDDATA;
596 /* get output buffer */
597 c->frame.nb_samples = nb_samples;
598 if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) {
599 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
602 samples = (short *)c->frame.data[0];
603 samples_p = (int16_t **)c->frame.extended_data;
605 /* use coded_samples when applicable */
606 /* it is always <= nb_samples, so the output buffer will be large enough */
608 if (coded_samples != nb_samples)
609 av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
610 c->frame.nb_samples = nb_samples = coded_samples;
613 st = avctx->channels == 2 ? 1 : 0;
615 switch(avctx->codec->id) {
616 case AV_CODEC_ID_ADPCM_IMA_QT:
617 /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
618 Channel data is interleaved per-chunk. */
619 for (channel = 0; channel < avctx->channels; channel++) {
622 cs = &(c->status[channel]);
623 /* (pppppp) (piiiiiii) */
625 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
626 predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
627 step_index = predictor & 0x7F;
630 if (cs->step_index == step_index) {
631 int diff = predictor - cs->predictor;
638 cs->step_index = step_index;
639 cs->predictor = predictor;
642 if (cs->step_index > 88u){
643 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
644 channel, cs->step_index);
645 return AVERROR_INVALIDDATA;
648 samples = samples_p[channel];
650 for (m = 0; m < 64; m += 2) {
651 int byte = bytestream2_get_byteu(&gb);
652 samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);
653 samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 , 3);
657 case AV_CODEC_ID_ADPCM_IMA_WAV:
658 for(i=0; i<avctx->channels; i++){
659 cs = &(c->status[i]);
660 cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
662 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
663 if (cs->step_index > 88u){
664 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
666 return AVERROR_INVALIDDATA;
670 for (n = (nb_samples - 1) / 8; n > 0; n--) {
671 for (i = 0; i < avctx->channels; i++) {
673 for (m = 0; m < 4; m++) {
674 int v = bytestream2_get_byteu(&gb);
675 *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
676 samples += avctx->channels;
677 *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
678 samples += avctx->channels;
680 samples -= 8 * avctx->channels - 1;
682 samples += 7 * avctx->channels;
685 case AV_CODEC_ID_ADPCM_4XM:
686 for (i = 0; i < avctx->channels; i++)
687 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
689 for (i = 0; i < avctx->channels; i++) {
690 c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
691 if (c->status[i].step_index > 88u) {
692 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
693 i, c->status[i].step_index);
694 return AVERROR_INVALIDDATA;
698 for (i = 0; i < avctx->channels; i++) {
699 samples = (short *)c->frame.data[0] + i;
701 for (n = nb_samples >> 1; n > 0; n--) {
702 int v = bytestream2_get_byteu(&gb);
703 *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
704 samples += avctx->channels;
705 *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
706 samples += avctx->channels;
710 case AV_CODEC_ID_ADPCM_MS:
714 block_predictor = bytestream2_get_byteu(&gb);
715 if (block_predictor > 6) {
716 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
718 return AVERROR_INVALIDDATA;
720 c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
721 c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
723 block_predictor = bytestream2_get_byteu(&gb);
724 if (block_predictor > 6) {
725 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
727 return AVERROR_INVALIDDATA;
729 c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
730 c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
732 c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
734 c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
737 c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
738 if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
739 c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
740 if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
742 *samples++ = c->status[0].sample2;
743 if (st) *samples++ = c->status[1].sample2;
744 *samples++ = c->status[0].sample1;
745 if (st) *samples++ = c->status[1].sample1;
746 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
747 int byte = bytestream2_get_byteu(&gb);
748 *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
749 *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
753 case AV_CODEC_ID_ADPCM_IMA_DK4:
754 for (channel = 0; channel < avctx->channels; channel++) {
755 cs = &c->status[channel];
756 cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
757 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
758 if (cs->step_index > 88u){
759 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
760 channel, cs->step_index);
761 return AVERROR_INVALIDDATA;
764 for (n = nb_samples >> (1 - st); n > 0; n--) {
765 int v = bytestream2_get_byteu(&gb);
766 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
767 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
770 case AV_CODEC_ID_ADPCM_IMA_DK3:
774 int decode_top_nibble_next = 0;
776 const int16_t *samples_end = samples + avctx->channels * nb_samples;
778 bytestream2_skipu(&gb, 10);
779 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
780 c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
781 c->status[0].step_index = bytestream2_get_byteu(&gb);
782 c->status[1].step_index = bytestream2_get_byteu(&gb);
783 if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
784 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
785 c->status[0].step_index, c->status[1].step_index);
786 return AVERROR_INVALIDDATA;
788 /* sign extend the predictors */
789 diff_channel = c->status[1].predictor;
791 /* DK3 ADPCM support macro */
792 #define DK3_GET_NEXT_NIBBLE() \
793 if (decode_top_nibble_next) { \
794 nibble = last_byte >> 4; \
795 decode_top_nibble_next = 0; \
797 last_byte = bytestream2_get_byteu(&gb); \
798 nibble = last_byte & 0x0F; \
799 decode_top_nibble_next = 1; \
802 while (samples < samples_end) {
804 /* for this algorithm, c->status[0] is the sum channel and
805 * c->status[1] is the diff channel */
807 /* process the first predictor of the sum channel */
808 DK3_GET_NEXT_NIBBLE();
809 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
811 /* process the diff channel predictor */
812 DK3_GET_NEXT_NIBBLE();
813 adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
815 /* process the first pair of stereo PCM samples */
816 diff_channel = (diff_channel + c->status[1].predictor) / 2;
817 *samples++ = c->status[0].predictor + c->status[1].predictor;
818 *samples++ = c->status[0].predictor - c->status[1].predictor;
820 /* process the second predictor of the sum channel */
821 DK3_GET_NEXT_NIBBLE();
822 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
824 /* process the second pair of stereo PCM samples */
825 diff_channel = (diff_channel + c->status[1].predictor) / 2;
826 *samples++ = c->status[0].predictor + c->status[1].predictor;
827 *samples++ = c->status[0].predictor - c->status[1].predictor;
831 case AV_CODEC_ID_ADPCM_IMA_ISS:
832 for (channel = 0; channel < avctx->channels; channel++) {
833 cs = &c->status[channel];
834 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
835 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
836 if (cs->step_index > 88u){
837 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
838 channel, cs->step_index);
839 return AVERROR_INVALIDDATA;
843 for (n = nb_samples >> (1 - st); n > 0; n--) {
845 int v = bytestream2_get_byteu(&gb);
846 /* nibbles are swapped for mono */
854 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
855 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
858 case AV_CODEC_ID_ADPCM_IMA_APC:
859 while (bytestream2_get_bytes_left(&gb) > 0) {
860 int v = bytestream2_get_byteu(&gb);
861 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
862 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
865 case AV_CODEC_ID_ADPCM_IMA_WS:
866 if (c->vqa_version == 3) {
867 for (channel = 0; channel < avctx->channels; channel++) {
868 int16_t *smp = samples + channel;
870 for (n = nb_samples / 2; n > 0; n--) {
871 int v = bytestream2_get_byteu(&gb);
872 *smp = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
873 smp += avctx->channels;
874 *smp = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
875 smp += avctx->channels;
879 for (n = nb_samples / 2; n > 0; n--) {
880 for (channel = 0; channel < avctx->channels; channel++) {
881 int v = bytestream2_get_byteu(&gb);
882 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
883 samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
885 samples += avctx->channels;
888 bytestream2_seek(&gb, 0, SEEK_END);
890 case AV_CODEC_ID_ADPCM_XA:
891 while (bytestream2_get_bytes_left(&gb) >= 128) {
892 if ((ret = xa_decode(avctx, samples, buf + bytestream2_tell(&gb), &c->status[0],
893 &c->status[1], avctx->channels)) < 0)
895 bytestream2_skipu(&gb, 128);
899 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
900 for (i=0; i<=st; i++) {
901 c->status[i].step_index = bytestream2_get_le32u(&gb);
902 if (c->status[i].step_index > 88u) {
903 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
904 i, c->status[i].step_index);
905 return AVERROR_INVALIDDATA;
908 for (i=0; i<=st; i++)
909 c->status[i].predictor = bytestream2_get_le32u(&gb);
911 for (n = nb_samples >> (1 - st); n > 0; n--) {
912 int byte = bytestream2_get_byteu(&gb);
913 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
914 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
917 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
918 for (n = nb_samples >> (1 - st); n > 0; n--) {
919 int byte = bytestream2_get_byteu(&gb);
920 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6);
921 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
924 case AV_CODEC_ID_ADPCM_EA:
926 int previous_left_sample, previous_right_sample;
927 int current_left_sample, current_right_sample;
928 int next_left_sample, next_right_sample;
929 int coeff1l, coeff2l, coeff1r, coeff2r;
930 int shift_left, shift_right;
932 /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
933 each coding 28 stereo samples. */
935 current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
936 previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
937 current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
938 previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
940 for (count1 = 0; count1 < nb_samples / 28; count1++) {
941 int byte = bytestream2_get_byteu(&gb);
942 coeff1l = ea_adpcm_table[ byte >> 4 ];
943 coeff2l = ea_adpcm_table[(byte >> 4 ) + 4];
944 coeff1r = ea_adpcm_table[ byte & 0x0F];
945 coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
947 byte = bytestream2_get_byteu(&gb);
948 shift_left = 20 - (byte >> 4);
949 shift_right = 20 - (byte & 0x0F);
951 for (count2 = 0; count2 < 28; count2++) {
952 byte = bytestream2_get_byteu(&gb);
953 next_left_sample = sign_extend(byte >> 4, 4) << shift_left;
954 next_right_sample = sign_extend(byte, 4) << shift_right;
956 next_left_sample = (next_left_sample +
957 (current_left_sample * coeff1l) +
958 (previous_left_sample * coeff2l) + 0x80) >> 8;
959 next_right_sample = (next_right_sample +
960 (current_right_sample * coeff1r) +
961 (previous_right_sample * coeff2r) + 0x80) >> 8;
963 previous_left_sample = current_left_sample;
964 current_left_sample = av_clip_int16(next_left_sample);
965 previous_right_sample = current_right_sample;
966 current_right_sample = av_clip_int16(next_right_sample);
967 *samples++ = current_left_sample;
968 *samples++ = current_right_sample;
972 bytestream2_skip(&gb, 2); // Skip terminating 0x0000
976 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
978 int coeff[2][2], shift[2];
980 for(channel = 0; channel < avctx->channels; channel++) {
981 int byte = bytestream2_get_byteu(&gb);
983 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
984 shift[channel] = 20 - (byte & 0x0F);
986 for (count1 = 0; count1 < nb_samples / 2; count1++) {
989 byte[0] = bytestream2_get_byteu(&gb);
990 if (st) byte[1] = bytestream2_get_byteu(&gb);
991 for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
992 for(channel = 0; channel < avctx->channels; channel++) {
993 int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];
995 c->status[channel].sample1 * coeff[channel][0] +
996 c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
997 c->status[channel].sample2 = c->status[channel].sample1;
998 c->status[channel].sample1 = av_clip_int16(sample);
999 *samples++ = c->status[channel].sample1;
1003 bytestream2_seek(&gb, 0, SEEK_END);
1006 case AV_CODEC_ID_ADPCM_EA_R1:
1007 case AV_CODEC_ID_ADPCM_EA_R2:
1008 case AV_CODEC_ID_ADPCM_EA_R3: {
1009 /* channel numbering
1011 4chan: 0=fl, 1=rl, 2=fr, 3=rr
1012 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
1013 const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
1014 int previous_sample, current_sample, next_sample;
1017 unsigned int channel;
1022 for (channel=0; channel<avctx->channels; channel++)
1023 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1024 bytestream2_get_le32(&gb)) +
1025 (avctx->channels + 1) * 4;
1027 for (channel=0; channel<avctx->channels; channel++) {
1028 bytestream2_seek(&gb, offsets[channel], SEEK_SET);
1029 samplesC = samples + channel;
1031 if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
1032 current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1033 previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1035 current_sample = c->status[channel].predictor;
1036 previous_sample = c->status[channel].prev_sample;
1039 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1040 int byte = bytestream2_get_byte(&gb);
1041 if (byte == 0xEE) { /* only seen in R2 and R3 */
1042 current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
1043 previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
1045 for (count2=0; count2<28; count2++) {
1046 *samplesC = sign_extend(bytestream2_get_be16(&gb), 16);
1047 samplesC += avctx->channels;
1050 coeff1 = ea_adpcm_table[ byte >> 4 ];
1051 coeff2 = ea_adpcm_table[(byte >> 4) + 4];
1052 shift = 20 - (byte & 0x0F);
1054 for (count2=0; count2<28; count2++) {
1056 next_sample = sign_extend(byte, 4) << shift;
1058 byte = bytestream2_get_byte(&gb);
1059 next_sample = sign_extend(byte >> 4, 4) << shift;
1062 next_sample += (current_sample * coeff1) +
1063 (previous_sample * coeff2);
1064 next_sample = av_clip_int16(next_sample >> 8);
1066 previous_sample = current_sample;
1067 current_sample = next_sample;
1068 *samplesC = current_sample;
1069 samplesC += avctx->channels;
1075 } else if (count != count1) {
1076 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
1077 count = FFMAX(count, count1);
1080 if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
1081 c->status[channel].predictor = current_sample;
1082 c->status[channel].prev_sample = previous_sample;
1086 c->frame.nb_samples = count * 28;
1087 bytestream2_seek(&gb, 0, SEEK_END);
1090 case AV_CODEC_ID_ADPCM_EA_XAS:
1091 for (channel=0; channel<avctx->channels; channel++) {
1092 int coeff[2][4], shift[4];
1093 short *s2, *s = &samples[channel];
1094 for (n=0; n<4; n++, s+=32*avctx->channels) {
1095 int val = sign_extend(bytestream2_get_le16u(&gb), 16);
1097 coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
1100 val = sign_extend(bytestream2_get_le16u(&gb), 16);
1101 shift[n] = 20 - (val & 0x0F);
1102 s[avctx->channels] = val & ~0x0F;
1105 for (m=2; m<32; m+=2) {
1106 s = &samples[m*avctx->channels + channel];
1107 for (n=0; n<4; n++, s+=32*avctx->channels) {
1108 int byte = bytestream2_get_byteu(&gb);
1109 for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) {
1110 int level = sign_extend(byte >> (4 - i), 4) << shift[n];
1111 int pred = s2[-1*avctx->channels] * coeff[0][n]
1112 + s2[-2*avctx->channels] * coeff[1][n];
1113 s2[0] = av_clip_int16((level + pred + 0x80) >> 8);
1119 case AV_CODEC_ID_ADPCM_IMA_AMV:
1120 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1121 if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_AMV) {
1122 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1123 c->status[0].step_index = bytestream2_get_le16u(&gb);
1124 bytestream2_skipu(&gb, 4);
1126 c->status[0].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
1127 c->status[0].step_index = bytestream2_get_byteu(&gb);
1128 bytestream2_skipu(&gb, 1);
1130 if (c->status[0].step_index > 88u) {
1131 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
1132 c->status[0].step_index);
1133 return AVERROR_INVALIDDATA;
1136 for (n = nb_samples >> (1 - st); n > 0; n--) {
1137 int hi, lo, v = bytestream2_get_byteu(&gb);
1139 if (avctx->codec->id == AV_CODEC_ID_ADPCM_IMA_AMV) {
1147 *samples++ = adpcm_ima_expand_nibble(&c->status[0], lo, 3);
1148 *samples++ = adpcm_ima_expand_nibble(&c->status[0], hi, 3);
1151 case AV_CODEC_ID_ADPCM_CT:
1152 for (n = nb_samples >> (1 - st); n > 0; n--) {
1153 int v = bytestream2_get_byteu(&gb);
1154 *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
1155 *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
1158 case AV_CODEC_ID_ADPCM_SBPRO_4:
1159 case AV_CODEC_ID_ADPCM_SBPRO_3:
1160 case AV_CODEC_ID_ADPCM_SBPRO_2:
1161 if (!c->status[0].step_index) {
1162 /* the first byte is a raw sample */
1163 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1165 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1166 c->status[0].step_index = 1;
1169 if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
1170 for (n = nb_samples >> (1 - st); n > 0; n--) {
1171 int byte = bytestream2_get_byteu(&gb);
1172 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1174 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1177 } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
1178 for (n = nb_samples / 3; n > 0; n--) {
1179 int byte = bytestream2_get_byteu(&gb);
1180 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1182 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1183 (byte >> 2) & 0x07, 3, 0);
1184 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1188 for (n = nb_samples >> (2 - st); n > 0; n--) {
1189 int byte = bytestream2_get_byteu(&gb);
1190 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1192 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1193 (byte >> 4) & 0x03, 2, 2);
1194 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1195 (byte >> 2) & 0x03, 2, 2);
1196 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1201 case AV_CODEC_ID_ADPCM_SWF:
1202 adpcm_swf_decode(avctx, buf, buf_size, samples);
1203 bytestream2_seek(&gb, 0, SEEK_END);
1205 case AV_CODEC_ID_ADPCM_YAMAHA:
1206 for (n = nb_samples >> (1 - st); n > 0; n--) {
1207 int v = bytestream2_get_byteu(&gb);
1208 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
1209 *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
1212 case AV_CODEC_ID_ADPCM_THP:
1218 for (i = 0; i < 2; i++)
1219 for (n = 0; n < 16; n++)
1220 table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);
1222 /* Initialize the previous sample. */
1223 for (i = 0; i < 2; i++)
1224 for (n = 0; n < 2; n++)
1225 prev[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);
1227 for (ch = 0; ch <= st; ch++) {
1228 samples = (short *)c->frame.data[0] + ch;
1230 /* Read in every sample for this channel. */
1231 for (i = 0; i < nb_samples / 14; i++) {
1232 int byte = bytestream2_get_byteu(&gb);
1233 int index = (byte >> 4) & 7;
1234 unsigned int exp = byte & 0x0F;
1235 int factor1 = table[ch][index * 2];
1236 int factor2 = table[ch][index * 2 + 1];
1238 /* Decode 14 samples. */
1239 for (n = 0; n < 14; n++) {
1243 sampledat = sign_extend(byte, 4);
1245 byte = bytestream2_get_byteu(&gb);
1246 sampledat = sign_extend(byte >> 4, 4);
1249 sampledat = ((prev[ch][0]*factor1
1250 + prev[ch][1]*factor2) >> 11) + (sampledat << exp);
1251 *samples = av_clip_int16(sampledat);
1252 prev[ch][1] = prev[ch][0];
1253 prev[ch][0] = *samples++;
1255 /* In case of stereo, skip one sample, this sample
1256 is for the other channel. */
1269 *(AVFrame *)data = c->frame;
1271 return bytestream2_tell(&gb);
1275 static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
1276 AV_SAMPLE_FMT_NONE };
1277 static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16,
1278 AV_SAMPLE_FMT_NONE };
1280 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
1281 AVCodec ff_ ## name_ ## _decoder = { \
1283 .type = AVMEDIA_TYPE_AUDIO, \
1285 .priv_data_size = sizeof(ADPCMDecodeContext), \
1286 .init = adpcm_decode_init, \
1287 .decode = adpcm_decode_frame, \
1288 .capabilities = CODEC_CAP_DR1, \
1289 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
1290 .sample_fmts = sample_fmts_, \
1293 /* Note: Do not forget to add new entries to the Makefile as well. */
1294 ADPCM_DECODER(AV_CODEC_ID_ADPCM_4XM, sample_fmts_s16, adpcm_4xm, "ADPCM 4X Movie");
1295 ADPCM_DECODER(AV_CODEC_ID_ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology");
1296 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts");
1297 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
1298 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1, sample_fmts_s16, adpcm_ea_r1, "ADPCM Electronic Arts R1");
1299 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2, sample_fmts_s16, adpcm_ea_r2, "ADPCM Electronic Arts R2");
1300 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3, sample_fmts_s16, adpcm_ea_r3, "ADPCM Electronic Arts R3");
1301 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
1302 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV");
1303 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC");
1304 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
1305 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
1306 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
1307 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
1308 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
1309 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, "ADPCM IMA QuickTime");
1310 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
1311 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16, adpcm_ima_wav, "ADPCM IMA WAV");
1312 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_s16, adpcm_ima_ws, "ADPCM IMA Westwood");
1313 ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_s16, adpcm_ms, "ADPCM Microsoft");
1314 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
1315 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
1316 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
1317 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash");
1318 ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP, sample_fmts_s16, adpcm_thp, "ADPCM Nintendo Gamecube THP");
1319 ADPCM_DECODER(AV_CODEC_ID_ADPCM_XA, sample_fmts_s16, adpcm_xa, "ADPCM CDROM XA");
1320 ADPCM_DECODER(AV_CODEC_ID_ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha");