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)
16 * This file is part of FFmpeg.
18 * FFmpeg is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
23 * FFmpeg is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with FFmpeg; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "bytestream.h"
36 #include "adpcm_data.h"
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 int8_t xa_adpcm_table[5][2] = {
68 static const int16_t ea_adpcm_table[] = {
76 // padded to zero where table size is less then 16
77 static const int8_t 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 {
87 ADPCMChannelStatus status[14];
88 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_DTK:
100 case AV_CODEC_ID_ADPCM_EA:
103 case AV_CODEC_ID_ADPCM_AFC:
104 case AV_CODEC_ID_ADPCM_EA_R1:
105 case AV_CODEC_ID_ADPCM_EA_R2:
106 case AV_CODEC_ID_ADPCM_EA_R3:
107 case AV_CODEC_ID_ADPCM_EA_XAS:
108 case AV_CODEC_ID_ADPCM_MS:
111 case AV_CODEC_ID_ADPCM_MTAF:
115 case AV_CODEC_ID_ADPCM_PSX:
118 case AV_CODEC_ID_ADPCM_IMA_DAT4:
119 case AV_CODEC_ID_ADPCM_THP:
120 case AV_CODEC_ID_ADPCM_THP_LE:
124 if (avctx->channels < min_channels || avctx->channels > max_channels) {
125 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
126 return AVERROR(EINVAL);
129 switch(avctx->codec->id) {
130 case AV_CODEC_ID_ADPCM_CT:
131 c->status[0].step = c->status[1].step = 511;
133 case AV_CODEC_ID_ADPCM_IMA_WAV:
134 if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5)
135 return AVERROR_INVALIDDATA;
137 case AV_CODEC_ID_ADPCM_IMA_APC:
138 if (avctx->extradata && avctx->extradata_size >= 8) {
139 c->status[0].predictor = AV_RL32(avctx->extradata);
140 c->status[1].predictor = AV_RL32(avctx->extradata + 4);
143 case AV_CODEC_ID_ADPCM_IMA_WS:
144 if (avctx->extradata && avctx->extradata_size >= 2)
145 c->vqa_version = AV_RL16(avctx->extradata);
151 switch(avctx->codec->id) {
152 case AV_CODEC_ID_ADPCM_AICA:
153 case AV_CODEC_ID_ADPCM_IMA_DAT4:
154 case AV_CODEC_ID_ADPCM_IMA_QT:
155 case AV_CODEC_ID_ADPCM_IMA_WAV:
156 case AV_CODEC_ID_ADPCM_4XM:
157 case AV_CODEC_ID_ADPCM_XA:
158 case AV_CODEC_ID_ADPCM_EA_R1:
159 case AV_CODEC_ID_ADPCM_EA_R2:
160 case AV_CODEC_ID_ADPCM_EA_R3:
161 case AV_CODEC_ID_ADPCM_EA_XAS:
162 case AV_CODEC_ID_ADPCM_THP:
163 case AV_CODEC_ID_ADPCM_THP_LE:
164 case AV_CODEC_ID_ADPCM_AFC:
165 case AV_CODEC_ID_ADPCM_DTK:
166 case AV_CODEC_ID_ADPCM_PSX:
167 case AV_CODEC_ID_ADPCM_MTAF:
168 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
170 case AV_CODEC_ID_ADPCM_IMA_WS:
171 avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P :
174 case AV_CODEC_ID_ADPCM_MS:
175 avctx->sample_fmt = avctx->channels > 2 ? AV_SAMPLE_FMT_S16P :
179 avctx->sample_fmt = AV_SAMPLE_FMT_S16;
185 static inline int16_t adpcm_agm_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
187 int delta, pred, step, add;
192 add = (delta * 2 + 1) * step;
196 if ((nibble & 8) == 0)
197 pred = av_clip(pred + (add >> 3), -32767, 32767);
199 pred = av_clip(pred - (add >> 3), -32767, 32767);
206 c->step = av_clip(c->step * 2, 127, 24576);
224 c->step = av_clip(c->step, 127, 24576);
229 static inline int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
233 int sign, delta, diff, step;
235 step = ff_adpcm_step_table[c->step_index];
236 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
237 step_index = av_clip(step_index, 0, 88);
241 /* perform direct multiplication instead of series of jumps proposed by
242 * the reference ADPCM implementation since modern CPUs can do the mults
244 diff = ((2 * delta + 1) * step) >> shift;
245 predictor = c->predictor;
246 if (sign) predictor -= diff;
247 else predictor += diff;
249 c->predictor = av_clip_int16(predictor);
250 c->step_index = step_index;
252 return (int16_t)c->predictor;
255 static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
257 int nibble, step_index, predictor, sign, delta, diff, step, shift;
260 nibble = get_bits_le(gb, bps),
261 step = ff_adpcm_step_table[c->step_index];
262 step_index = c->step_index + ff_adpcm_index_tables[bps - 2][nibble];
263 step_index = av_clip(step_index, 0, 88);
265 sign = nibble & (1 << shift);
266 delta = av_mod_uintp2(nibble, shift);
267 diff = ((2 * delta + 1) * step) >> shift;
268 predictor = c->predictor;
269 if (sign) predictor -= diff;
270 else predictor += diff;
272 c->predictor = av_clip_int16(predictor);
273 c->step_index = step_index;
275 return (int16_t)c->predictor;
278 static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
284 step = ff_adpcm_step_table[c->step_index];
285 step_index = c->step_index + ff_adpcm_index_table[nibble];
286 step_index = av_clip(step_index, 0, 88);
289 if (nibble & 4) diff += step;
290 if (nibble & 2) diff += step >> 1;
291 if (nibble & 1) diff += step >> 2;
294 predictor = c->predictor - diff;
296 predictor = c->predictor + diff;
298 c->predictor = av_clip_int16(predictor);
299 c->step_index = step_index;
304 static inline int16_t adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
308 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
309 predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
311 c->sample2 = c->sample1;
312 c->sample1 = av_clip_int16(predictor);
313 c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
314 if (c->idelta < 16) c->idelta = 16;
315 if (c->idelta > INT_MAX/768) {
316 av_log(NULL, AV_LOG_WARNING, "idelta overflow\n");
317 c->idelta = INT_MAX/768;
323 static inline int16_t adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
325 int step_index, predictor, sign, delta, diff, step;
327 step = ff_adpcm_oki_step_table[c->step_index];
328 step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
329 step_index = av_clip(step_index, 0, 48);
333 diff = ((2 * delta + 1) * step) >> 3;
334 predictor = c->predictor;
335 if (sign) predictor -= diff;
336 else predictor += diff;
338 c->predictor = av_clip_intp2(predictor, 11);
339 c->step_index = step_index;
341 return c->predictor << 4;
344 static inline int16_t adpcm_ct_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
346 int sign, delta, diff;
351 /* perform direct multiplication instead of series of jumps proposed by
352 * the reference ADPCM implementation since modern CPUs can do the mults
354 diff = ((2 * delta + 1) * c->step) >> 3;
355 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
356 c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
357 c->predictor = av_clip_int16(c->predictor);
358 /* calculate new step and clamp it to range 511..32767 */
359 new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
360 c->step = av_clip(new_step, 511, 32767);
362 return (int16_t)c->predictor;
365 static inline int16_t adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int size, int shift)
367 int sign, delta, diff;
369 sign = nibble & (1<<(size-1));
370 delta = nibble & ((1<<(size-1))-1);
371 diff = delta << (7 + c->step + shift);
374 c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
376 /* calculate new step */
377 if (delta >= (2*size - 3) && c->step < 3)
379 else if (delta == 0 && c->step > 0)
382 return (int16_t) c->predictor;
385 static inline int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
392 c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
393 c->predictor = av_clip_int16(c->predictor);
394 c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
395 c->step = av_clip(c->step, 127, 24576);
399 static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
401 c->predictor += ff_adpcm_mtaf_stepsize[c->step][nibble];
402 c->predictor = av_clip_int16(c->predictor);
403 c->step += ff_adpcm_index_table[nibble];
404 c->step = av_clip_uintp2(c->step, 5);
408 static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1,
409 const uint8_t *in, ADPCMChannelStatus *left,
410 ADPCMChannelStatus *right, int channels, int sample_offset)
413 int shift,filter,f0,f1;
417 out0 += sample_offset;
421 out1 += sample_offset;
424 shift = 12 - (in[4+i*2] & 15);
425 filter = in[4+i*2] >> 4;
426 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
427 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
430 f0 = xa_adpcm_table[filter][0];
431 f1 = xa_adpcm_table[filter][1];
439 t = sign_extend(d, 4);
440 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
442 s_1 = av_clip_int16(s);
449 s_1 = right->sample1;
450 s_2 = right->sample2;
453 shift = 12 - (in[5+i*2] & 15);
454 filter = in[5+i*2] >> 4;
455 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
456 avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
460 f0 = xa_adpcm_table[filter][0];
461 f1 = xa_adpcm_table[filter][1];
466 t = sign_extend(d >> 4, 4);
467 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
469 s_1 = av_clip_int16(s);
474 right->sample1 = s_1;
475 right->sample2 = s_2;
481 out0 += 28 * (3 - channels);
482 out1 += 28 * (3 - channels);
488 static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
490 ADPCMDecodeContext *c = avctx->priv_data;
493 int k0, signmask, nb_bits, count;
494 int size = buf_size*8;
497 init_get_bits(&gb, buf, size);
499 //read bits & initial values
500 nb_bits = get_bits(&gb, 2)+2;
501 table = swf_index_tables[nb_bits-2];
502 k0 = 1 << (nb_bits-2);
503 signmask = 1 << (nb_bits-1);
505 while (get_bits_count(&gb) <= size - 22*avctx->channels) {
506 for (i = 0; i < avctx->channels; i++) {
507 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
508 c->status[i].step_index = get_bits(&gb, 6);
511 for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
514 for (i = 0; i < avctx->channels; i++) {
515 // similar to IMA adpcm
516 int delta = get_bits(&gb, nb_bits);
517 int step = ff_adpcm_step_table[c->status[i].step_index];
518 int vpdiff = 0; // vpdiff = (delta+0.5)*step/4
529 if (delta & signmask)
530 c->status[i].predictor -= vpdiff;
532 c->status[i].predictor += vpdiff;
534 c->status[i].step_index += table[delta & (~signmask)];
536 c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
537 c->status[i].predictor = av_clip_int16(c->status[i].predictor);
539 *samples++ = c->status[i].predictor;
546 * Get the number of samples that will be decoded from the packet.
547 * In one case, this is actually the maximum number of samples possible to
548 * decode with the given buf_size.
550 * @param[out] coded_samples set to the number of samples as coded in the
551 * packet, or 0 if the codec does not encode the
552 * number of samples in each frame.
553 * @param[out] approx_nb_samples set to non-zero if the number of samples
554 * returned is an approximation.
556 static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
557 int buf_size, int *coded_samples, int *approx_nb_samples)
559 ADPCMDecodeContext *s = avctx->priv_data;
561 int ch = avctx->channels;
562 int has_coded_samples = 0;
566 *approx_nb_samples = 0;
571 switch (avctx->codec->id) {
572 /* constant, only check buf_size */
573 case AV_CODEC_ID_ADPCM_EA_XAS:
574 if (buf_size < 76 * ch)
578 case AV_CODEC_ID_ADPCM_IMA_QT:
579 if (buf_size < 34 * ch)
583 /* simple 4-bit adpcm */
584 case AV_CODEC_ID_ADPCM_CT:
585 case AV_CODEC_ID_ADPCM_IMA_APC:
586 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
587 case AV_CODEC_ID_ADPCM_IMA_OKI:
588 case AV_CODEC_ID_ADPCM_IMA_WS:
589 case AV_CODEC_ID_ADPCM_YAMAHA:
590 case AV_CODEC_ID_ADPCM_AICA:
591 nb_samples = buf_size * 2 / ch;
597 /* simple 4-bit adpcm, with header */
599 switch (avctx->codec->id) {
600 case AV_CODEC_ID_ADPCM_4XM:
601 case AV_CODEC_ID_ADPCM_AGM:
602 case AV_CODEC_ID_ADPCM_IMA_DAT4:
603 case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
604 case AV_CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break;
605 case AV_CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4 * ch; break;
608 return (buf_size - header_size) * 2 / ch;
610 /* more complex formats */
611 switch (avctx->codec->id) {
612 case AV_CODEC_ID_ADPCM_EA:
613 has_coded_samples = 1;
614 *coded_samples = bytestream2_get_le32(gb);
615 *coded_samples -= *coded_samples % 28;
616 nb_samples = (buf_size - 12) / 30 * 28;
618 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
619 has_coded_samples = 1;
620 *coded_samples = bytestream2_get_le32(gb);
621 nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
623 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
624 nb_samples = (buf_size - ch) / ch * 2;
626 case AV_CODEC_ID_ADPCM_EA_R1:
627 case AV_CODEC_ID_ADPCM_EA_R2:
628 case AV_CODEC_ID_ADPCM_EA_R3:
629 /* maximum number of samples */
630 /* has internal offsets and a per-frame switch to signal raw 16-bit */
631 has_coded_samples = 1;
632 switch (avctx->codec->id) {
633 case AV_CODEC_ID_ADPCM_EA_R1:
634 header_size = 4 + 9 * ch;
635 *coded_samples = bytestream2_get_le32(gb);
637 case AV_CODEC_ID_ADPCM_EA_R2:
638 header_size = 4 + 5 * ch;
639 *coded_samples = bytestream2_get_le32(gb);
641 case AV_CODEC_ID_ADPCM_EA_R3:
642 header_size = 4 + 5 * ch;
643 *coded_samples = bytestream2_get_be32(gb);
646 *coded_samples -= *coded_samples % 28;
647 nb_samples = (buf_size - header_size) * 2 / ch;
648 nb_samples -= nb_samples % 28;
649 *approx_nb_samples = 1;
651 case AV_CODEC_ID_ADPCM_IMA_DK3:
652 if (avctx->block_align > 0)
653 buf_size = FFMIN(buf_size, avctx->block_align);
654 nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
656 case AV_CODEC_ID_ADPCM_IMA_DK4:
657 if (avctx->block_align > 0)
658 buf_size = FFMIN(buf_size, avctx->block_align);
659 if (buf_size < 4 * ch)
660 return AVERROR_INVALIDDATA;
661 nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
663 case AV_CODEC_ID_ADPCM_IMA_RAD:
664 if (avctx->block_align > 0)
665 buf_size = FFMIN(buf_size, avctx->block_align);
666 nb_samples = (buf_size - 4 * ch) * 2 / ch;
668 case AV_CODEC_ID_ADPCM_IMA_WAV:
670 int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
671 int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
672 if (avctx->block_align > 0)
673 buf_size = FFMIN(buf_size, avctx->block_align);
674 if (buf_size < 4 * ch)
675 return AVERROR_INVALIDDATA;
676 nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
679 case AV_CODEC_ID_ADPCM_MS:
680 if (avctx->block_align > 0)
681 buf_size = FFMIN(buf_size, avctx->block_align);
682 nb_samples = (buf_size - 6 * ch) * 2 / ch;
684 case AV_CODEC_ID_ADPCM_MTAF:
685 if (avctx->block_align > 0)
686 buf_size = FFMIN(buf_size, avctx->block_align);
687 nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
689 case AV_CODEC_ID_ADPCM_SBPRO_2:
690 case AV_CODEC_ID_ADPCM_SBPRO_3:
691 case AV_CODEC_ID_ADPCM_SBPRO_4:
693 int samples_per_byte;
694 switch (avctx->codec->id) {
695 case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
696 case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
697 case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
699 if (!s->status[0].step_index) {
701 return AVERROR_INVALIDDATA;
705 nb_samples += buf_size * samples_per_byte / ch;
708 case AV_CODEC_ID_ADPCM_SWF:
710 int buf_bits = buf_size * 8 - 2;
711 int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
712 int block_hdr_size = 22 * ch;
713 int block_size = block_hdr_size + nbits * ch * 4095;
714 int nblocks = buf_bits / block_size;
715 int bits_left = buf_bits - nblocks * block_size;
716 nb_samples = nblocks * 4096;
717 if (bits_left >= block_hdr_size)
718 nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
721 case AV_CODEC_ID_ADPCM_THP:
722 case AV_CODEC_ID_ADPCM_THP_LE:
723 if (avctx->extradata) {
724 nb_samples = buf_size * 14 / (8 * ch);
727 has_coded_samples = 1;
728 bytestream2_skip(gb, 4); // channel size
729 *coded_samples = (avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE) ?
730 bytestream2_get_le32(gb) :
731 bytestream2_get_be32(gb);
732 buf_size -= 8 + 36 * ch;
734 nb_samples = buf_size / 8 * 14;
735 if (buf_size % 8 > 1)
736 nb_samples += (buf_size % 8 - 1) * 2;
737 *approx_nb_samples = 1;
739 case AV_CODEC_ID_ADPCM_AFC:
740 nb_samples = buf_size / (9 * ch) * 16;
742 case AV_CODEC_ID_ADPCM_XA:
743 nb_samples = (buf_size / 128) * 224 / ch;
745 case AV_CODEC_ID_ADPCM_DTK:
746 case AV_CODEC_ID_ADPCM_PSX:
747 nb_samples = buf_size / (16 * ch) * 28;
751 /* validate coded sample count */
752 if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
753 return AVERROR_INVALIDDATA;
758 static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
759 int *got_frame_ptr, AVPacket *avpkt)
761 AVFrame *frame = data;
762 const uint8_t *buf = avpkt->data;
763 int buf_size = avpkt->size;
764 ADPCMDecodeContext *c = avctx->priv_data;
765 ADPCMChannelStatus *cs;
766 int n, m, channel, i;
771 int nb_samples, coded_samples, approx_nb_samples, ret;
774 bytestream2_init(&gb, buf, buf_size);
775 nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
776 if (nb_samples <= 0) {
777 av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
778 return AVERROR_INVALIDDATA;
781 /* get output buffer */
782 frame->nb_samples = nb_samples;
783 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
785 samples = (int16_t *)frame->data[0];
786 samples_p = (int16_t **)frame->extended_data;
788 /* use coded_samples when applicable */
789 /* it is always <= nb_samples, so the output buffer will be large enough */
791 if (!approx_nb_samples && coded_samples != nb_samples)
792 av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
793 frame->nb_samples = nb_samples = coded_samples;
796 st = avctx->channels == 2 ? 1 : 0;
798 switch(avctx->codec->id) {
799 case AV_CODEC_ID_ADPCM_IMA_QT:
800 /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
801 Channel data is interleaved per-chunk. */
802 for (channel = 0; channel < avctx->channels; channel++) {
805 cs = &(c->status[channel]);
806 /* (pppppp) (piiiiiii) */
808 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
809 predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
810 step_index = predictor & 0x7F;
813 if (cs->step_index == step_index) {
814 int diff = predictor - cs->predictor;
821 cs->step_index = step_index;
822 cs->predictor = predictor;
825 if (cs->step_index > 88u){
826 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
827 channel, cs->step_index);
828 return AVERROR_INVALIDDATA;
831 samples = samples_p[channel];
833 for (m = 0; m < 64; m += 2) {
834 int byte = bytestream2_get_byteu(&gb);
835 samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);
836 samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 , 3);
840 case AV_CODEC_ID_ADPCM_IMA_WAV:
841 for(i=0; i<avctx->channels; i++){
842 cs = &(c->status[i]);
843 cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
845 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
846 if (cs->step_index > 88u){
847 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
849 return AVERROR_INVALIDDATA;
853 if (avctx->bits_per_coded_sample != 4) {
854 int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
855 int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
856 uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
859 for (n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
860 for (i = 0; i < avctx->channels; i++) {
864 samples = &samples_p[i][1 + n * samples_per_block];
865 for (j = 0; j < block_size; j++) {
866 temp[j] = buf[4 * avctx->channels + block_size * n * avctx->channels +
867 (j % 4) + (j / 4) * (avctx->channels * 4) + i * 4];
869 ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size);
872 for (m = 0; m < samples_per_block; m++) {
873 samples[m] = adpcm_ima_wav_expand_nibble(cs, &g,
874 avctx->bits_per_coded_sample);
878 bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4);
880 for (n = 0; n < (nb_samples - 1) / 8; n++) {
881 for (i = 0; i < avctx->channels; i++) {
883 samples = &samples_p[i][1 + n * 8];
884 for (m = 0; m < 8; m += 2) {
885 int v = bytestream2_get_byteu(&gb);
886 samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
887 samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
893 case AV_CODEC_ID_ADPCM_4XM:
894 for (i = 0; i < avctx->channels; i++)
895 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
897 for (i = 0; i < avctx->channels; i++) {
898 c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
899 if (c->status[i].step_index > 88u) {
900 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
901 i, c->status[i].step_index);
902 return AVERROR_INVALIDDATA;
906 for (i = 0; i < avctx->channels; i++) {
907 samples = (int16_t *)frame->data[i];
909 for (n = nb_samples >> 1; n > 0; n--) {
910 int v = bytestream2_get_byteu(&gb);
911 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
912 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
916 case AV_CODEC_ID_ADPCM_AGM:
917 for (i = 0; i < avctx->channels; i++)
918 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
919 for (i = 0; i < avctx->channels; i++)
920 c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16);
922 for (n = 0; n < nb_samples >> (1 - st); n++) {
923 int v = bytestream2_get_byteu(&gb);
924 *samples++ = adpcm_agm_expand_nibble(&c->status[0], v & 0xF);
925 *samples++ = adpcm_agm_expand_nibble(&c->status[st], v >> 4 );
928 case AV_CODEC_ID_ADPCM_MS:
932 if (avctx->channels > 2) {
933 for (channel = 0; channel < avctx->channels; channel++) {
934 samples = samples_p[channel];
935 block_predictor = bytestream2_get_byteu(&gb);
936 if (block_predictor > 6) {
937 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[%d] = %d\n",
938 channel, block_predictor);
939 return AVERROR_INVALIDDATA;
941 c->status[channel].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
942 c->status[channel].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
943 c->status[channel].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
944 c->status[channel].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
945 c->status[channel].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
946 *samples++ = c->status[channel].sample2;
947 *samples++ = c->status[channel].sample1;
948 for(n = (nb_samples - 2) >> 1; n > 0; n--) {
949 int byte = bytestream2_get_byteu(&gb);
950 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte >> 4 );
951 *samples++ = adpcm_ms_expand_nibble(&c->status[channel], byte & 0x0F);
955 block_predictor = bytestream2_get_byteu(&gb);
956 if (block_predictor > 6) {
957 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
959 return AVERROR_INVALIDDATA;
961 c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
962 c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
964 block_predictor = bytestream2_get_byteu(&gb);
965 if (block_predictor > 6) {
966 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
968 return AVERROR_INVALIDDATA;
970 c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
971 c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
973 c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
975 c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
978 c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
979 if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
980 c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
981 if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
983 *samples++ = c->status[0].sample2;
984 if (st) *samples++ = c->status[1].sample2;
985 *samples++ = c->status[0].sample1;
986 if (st) *samples++ = c->status[1].sample1;
987 for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
988 int byte = bytestream2_get_byteu(&gb);
989 *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
990 *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
995 case AV_CODEC_ID_ADPCM_MTAF:
996 for (channel = 0; channel < avctx->channels; channel+=2) {
997 bytestream2_skipu(&gb, 4);
998 c->status[channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
999 c->status[channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
1000 c->status[channel ].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1001 bytestream2_skipu(&gb, 2);
1002 c->status[channel + 1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1003 bytestream2_skipu(&gb, 2);
1004 for (n = 0; n < nb_samples; n+=2) {
1005 int v = bytestream2_get_byteu(&gb);
1006 samples_p[channel][n ] = adpcm_mtaf_expand_nibble(&c->status[channel], v & 0x0F);
1007 samples_p[channel][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel], v >> 4 );
1009 for (n = 0; n < nb_samples; n+=2) {
1010 int v = bytestream2_get_byteu(&gb);
1011 samples_p[channel + 1][n ] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v & 0x0F);
1012 samples_p[channel + 1][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v >> 4 );
1016 case AV_CODEC_ID_ADPCM_IMA_DK4:
1017 for (channel = 0; channel < avctx->channels; channel++) {
1018 cs = &c->status[channel];
1019 cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
1020 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1021 if (cs->step_index > 88u){
1022 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1023 channel, cs->step_index);
1024 return AVERROR_INVALIDDATA;
1027 for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
1028 int v = bytestream2_get_byteu(&gb);
1029 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
1030 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1033 case AV_CODEC_ID_ADPCM_IMA_DK3:
1037 int decode_top_nibble_next = 0;
1039 const int16_t *samples_end = samples + avctx->channels * nb_samples;
1041 bytestream2_skipu(&gb, 10);
1042 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1043 c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1044 c->status[0].step_index = bytestream2_get_byteu(&gb);
1045 c->status[1].step_index = bytestream2_get_byteu(&gb);
1046 if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
1047 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
1048 c->status[0].step_index, c->status[1].step_index);
1049 return AVERROR_INVALIDDATA;
1051 /* sign extend the predictors */
1052 diff_channel = c->status[1].predictor;
1054 /* DK3 ADPCM support macro */
1055 #define DK3_GET_NEXT_NIBBLE() \
1056 if (decode_top_nibble_next) { \
1057 nibble = last_byte >> 4; \
1058 decode_top_nibble_next = 0; \
1060 last_byte = bytestream2_get_byteu(&gb); \
1061 nibble = last_byte & 0x0F; \
1062 decode_top_nibble_next = 1; \
1065 while (samples < samples_end) {
1067 /* for this algorithm, c->status[0] is the sum channel and
1068 * c->status[1] is the diff channel */
1070 /* process the first predictor of the sum channel */
1071 DK3_GET_NEXT_NIBBLE();
1072 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1074 /* process the diff channel predictor */
1075 DK3_GET_NEXT_NIBBLE();
1076 adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
1078 /* process the first pair of stereo PCM samples */
1079 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1080 *samples++ = c->status[0].predictor + c->status[1].predictor;
1081 *samples++ = c->status[0].predictor - c->status[1].predictor;
1083 /* process the second predictor of the sum channel */
1084 DK3_GET_NEXT_NIBBLE();
1085 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
1087 /* process the second pair of stereo PCM samples */
1088 diff_channel = (diff_channel + c->status[1].predictor) / 2;
1089 *samples++ = c->status[0].predictor + c->status[1].predictor;
1090 *samples++ = c->status[0].predictor - c->status[1].predictor;
1093 if ((bytestream2_tell(&gb) & 1))
1094 bytestream2_skip(&gb, 1);
1097 case AV_CODEC_ID_ADPCM_IMA_ISS:
1098 for (channel = 0; channel < avctx->channels; channel++) {
1099 cs = &c->status[channel];
1100 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1101 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1102 if (cs->step_index > 88u){
1103 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1104 channel, cs->step_index);
1105 return AVERROR_INVALIDDATA;
1109 for (n = nb_samples >> (1 - st); n > 0; n--) {
1111 int v = bytestream2_get_byteu(&gb);
1112 /* nibbles are swapped for mono */
1120 *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
1121 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
1124 case AV_CODEC_ID_ADPCM_IMA_DAT4:
1125 for (channel = 0; channel < avctx->channels; channel++) {
1126 cs = &c->status[channel];
1127 samples = samples_p[channel];
1128 bytestream2_skip(&gb, 4);
1129 for (n = 0; n < nb_samples; n += 2) {
1130 int v = bytestream2_get_byteu(&gb);
1131 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
1132 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
1136 case AV_CODEC_ID_ADPCM_IMA_APC:
1137 while (bytestream2_get_bytes_left(&gb) > 0) {
1138 int v = bytestream2_get_byteu(&gb);
1139 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
1140 *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
1143 case AV_CODEC_ID_ADPCM_IMA_OKI:
1144 while (bytestream2_get_bytes_left(&gb) > 0) {
1145 int v = bytestream2_get_byteu(&gb);
1146 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0], v >> 4 );
1147 *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);
1150 case AV_CODEC_ID_ADPCM_IMA_RAD:
1151 for (channel = 0; channel < avctx->channels; channel++) {
1152 cs = &c->status[channel];
1153 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
1154 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1155 if (cs->step_index > 88u){
1156 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1157 channel, cs->step_index);
1158 return AVERROR_INVALIDDATA;
1161 for (n = 0; n < nb_samples / 2; n++) {
1164 byte[0] = bytestream2_get_byteu(&gb);
1166 byte[1] = bytestream2_get_byteu(&gb);
1167 for(channel = 0; channel < avctx->channels; channel++) {
1168 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
1170 for(channel = 0; channel < avctx->channels; channel++) {
1171 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3);
1175 case AV_CODEC_ID_ADPCM_IMA_WS:
1176 if (c->vqa_version == 3) {
1177 for (channel = 0; channel < avctx->channels; channel++) {
1178 int16_t *smp = samples_p[channel];
1180 for (n = nb_samples / 2; n > 0; n--) {
1181 int v = bytestream2_get_byteu(&gb);
1182 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1183 *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1187 for (n = nb_samples / 2; n > 0; n--) {
1188 for (channel = 0; channel < avctx->channels; channel++) {
1189 int v = bytestream2_get_byteu(&gb);
1190 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
1191 samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
1193 samples += avctx->channels;
1196 bytestream2_seek(&gb, 0, SEEK_END);
1198 case AV_CODEC_ID_ADPCM_XA:
1200 int16_t *out0 = samples_p[0];
1201 int16_t *out1 = samples_p[1];
1202 int samples_per_block = 28 * (3 - avctx->channels) * 4;
1203 int sample_offset = 0;
1204 int bytes_remaining;
1205 while (bytestream2_get_bytes_left(&gb) >= 128) {
1206 if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
1207 &c->status[0], &c->status[1],
1208 avctx->channels, sample_offset)) < 0)
1210 bytestream2_skipu(&gb, 128);
1211 sample_offset += samples_per_block;
1213 /* Less than a full block of data left, e.g. when reading from
1214 * 2324 byte per sector XA; the remainder is padding */
1215 bytes_remaining = bytestream2_get_bytes_left(&gb);
1216 if (bytes_remaining > 0) {
1217 bytestream2_skip(&gb, bytes_remaining);
1221 case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
1222 for (i=0; i<=st; i++) {
1223 c->status[i].step_index = bytestream2_get_le32u(&gb);
1224 if (c->status[i].step_index > 88u) {
1225 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
1226 i, c->status[i].step_index);
1227 return AVERROR_INVALIDDATA;
1230 for (i=0; i<=st; i++)
1231 c->status[i].predictor = bytestream2_get_le32u(&gb);
1233 for (n = nb_samples >> (1 - st); n > 0; n--) {
1234 int byte = bytestream2_get_byteu(&gb);
1235 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
1236 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
1239 case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
1240 for (n = nb_samples >> (1 - st); n > 0; n--) {
1241 int byte = bytestream2_get_byteu(&gb);
1242 *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6);
1243 *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
1246 case AV_CODEC_ID_ADPCM_EA:
1248 int previous_left_sample, previous_right_sample;
1249 int current_left_sample, current_right_sample;
1250 int next_left_sample, next_right_sample;
1251 int coeff1l, coeff2l, coeff1r, coeff2r;
1252 int shift_left, shift_right;
1254 /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
1255 each coding 28 stereo samples. */
1257 if(avctx->channels != 2)
1258 return AVERROR_INVALIDDATA;
1260 current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1261 previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1262 current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1263 previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
1265 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1266 int byte = bytestream2_get_byteu(&gb);
1267 coeff1l = ea_adpcm_table[ byte >> 4 ];
1268 coeff2l = ea_adpcm_table[(byte >> 4 ) + 4];
1269 coeff1r = ea_adpcm_table[ byte & 0x0F];
1270 coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
1272 byte = bytestream2_get_byteu(&gb);
1273 shift_left = 20 - (byte >> 4);
1274 shift_right = 20 - (byte & 0x0F);
1276 for (count2 = 0; count2 < 28; count2++) {
1277 byte = bytestream2_get_byteu(&gb);
1278 next_left_sample = sign_extend(byte >> 4, 4) << shift_left;
1279 next_right_sample = sign_extend(byte, 4) << shift_right;
1281 next_left_sample = (next_left_sample +
1282 (current_left_sample * coeff1l) +
1283 (previous_left_sample * coeff2l) + 0x80) >> 8;
1284 next_right_sample = (next_right_sample +
1285 (current_right_sample * coeff1r) +
1286 (previous_right_sample * coeff2r) + 0x80) >> 8;
1288 previous_left_sample = current_left_sample;
1289 current_left_sample = av_clip_int16(next_left_sample);
1290 previous_right_sample = current_right_sample;
1291 current_right_sample = av_clip_int16(next_right_sample);
1292 *samples++ = current_left_sample;
1293 *samples++ = current_right_sample;
1297 bytestream2_skip(&gb, 2); // Skip terminating 0x0000
1301 case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
1303 int coeff[2][2], shift[2];
1305 for(channel = 0; channel < avctx->channels; channel++) {
1306 int byte = bytestream2_get_byteu(&gb);
1308 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
1309 shift[channel] = 20 - (byte & 0x0F);
1311 for (count1 = 0; count1 < nb_samples / 2; count1++) {
1314 byte[0] = bytestream2_get_byteu(&gb);
1315 if (st) byte[1] = bytestream2_get_byteu(&gb);
1316 for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
1317 for(channel = 0; channel < avctx->channels; channel++) {
1318 int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];
1320 c->status[channel].sample1 * coeff[channel][0] +
1321 c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
1322 c->status[channel].sample2 = c->status[channel].sample1;
1323 c->status[channel].sample1 = av_clip_int16(sample);
1324 *samples++ = c->status[channel].sample1;
1328 bytestream2_seek(&gb, 0, SEEK_END);
1331 case AV_CODEC_ID_ADPCM_EA_R1:
1332 case AV_CODEC_ID_ADPCM_EA_R2:
1333 case AV_CODEC_ID_ADPCM_EA_R3: {
1334 /* channel numbering
1336 4chan: 0=fl, 1=rl, 2=fr, 3=rr
1337 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
1338 const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
1339 int previous_sample, current_sample, next_sample;
1342 unsigned int channel;
1347 for (channel=0; channel<avctx->channels; channel++)
1348 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
1349 bytestream2_get_le32(&gb)) +
1350 (avctx->channels + 1) * 4;
1352 for (channel=0; channel<avctx->channels; channel++) {
1353 bytestream2_seek(&gb, offsets[channel], SEEK_SET);
1354 samplesC = samples_p[channel];
1356 if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
1357 current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1358 previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
1360 current_sample = c->status[channel].predictor;
1361 previous_sample = c->status[channel].prev_sample;
1364 for (count1 = 0; count1 < nb_samples / 28; count1++) {
1365 int byte = bytestream2_get_byte(&gb);
1366 if (byte == 0xEE) { /* only seen in R2 and R3 */
1367 current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
1368 previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
1370 for (count2=0; count2<28; count2++)
1371 *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);
1373 coeff1 = ea_adpcm_table[ byte >> 4 ];
1374 coeff2 = ea_adpcm_table[(byte >> 4) + 4];
1375 shift = 20 - (byte & 0x0F);
1377 for (count2=0; count2<28; count2++) {
1379 next_sample = sign_extend(byte, 4) << shift;
1381 byte = bytestream2_get_byte(&gb);
1382 next_sample = sign_extend(byte >> 4, 4) << shift;
1385 next_sample += (current_sample * coeff1) +
1386 (previous_sample * coeff2);
1387 next_sample = av_clip_int16(next_sample >> 8);
1389 previous_sample = current_sample;
1390 current_sample = next_sample;
1391 *samplesC++ = current_sample;
1397 } else if (count != count1) {
1398 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
1399 count = FFMAX(count, count1);
1402 if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
1403 c->status[channel].predictor = current_sample;
1404 c->status[channel].prev_sample = previous_sample;
1408 frame->nb_samples = count * 28;
1409 bytestream2_seek(&gb, 0, SEEK_END);
1412 case AV_CODEC_ID_ADPCM_EA_XAS:
1413 for (channel=0; channel<avctx->channels; channel++) {
1414 int coeff[2][4], shift[4];
1415 int16_t *s = samples_p[channel];
1416 for (n = 0; n < 4; n++, s += 32) {
1417 int val = sign_extend(bytestream2_get_le16u(&gb), 16);
1419 coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
1422 val = sign_extend(bytestream2_get_le16u(&gb), 16);
1423 shift[n] = 20 - (val & 0x0F);
1427 for (m=2; m<32; m+=2) {
1428 s = &samples_p[channel][m];
1429 for (n = 0; n < 4; n++, s += 32) {
1431 int byte = bytestream2_get_byteu(&gb);
1433 level = sign_extend(byte >> 4, 4) << shift[n];
1434 pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
1435 s[0] = av_clip_int16((level + pred + 0x80) >> 8);
1437 level = sign_extend(byte, 4) << shift[n];
1438 pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
1439 s[1] = av_clip_int16((level + pred + 0x80) >> 8);
1444 case AV_CODEC_ID_ADPCM_IMA_AMV:
1445 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1446 c->status[0].step_index = bytestream2_get_byteu(&gb);
1447 bytestream2_skipu(&gb, 5);
1448 if (c->status[0].step_index > 88u) {
1449 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
1450 c->status[0].step_index);
1451 return AVERROR_INVALIDDATA;
1454 for (n = nb_samples >> (1 - st); n > 0; n--) {
1455 int v = bytestream2_get_byteu(&gb);
1457 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
1458 *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);
1461 case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
1462 for (i = 0; i < avctx->channels; i++) {
1463 c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
1464 c->status[i].step_index = bytestream2_get_byteu(&gb);
1465 bytestream2_skipu(&gb, 1);
1466 if (c->status[i].step_index > 88u) {
1467 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
1468 c->status[i].step_index);
1469 return AVERROR_INVALIDDATA;
1473 for (n = nb_samples >> (1 - st); n > 0; n--) {
1474 int v = bytestream2_get_byteu(&gb);
1476 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3);
1477 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3);
1480 case AV_CODEC_ID_ADPCM_CT:
1481 for (n = nb_samples >> (1 - st); n > 0; n--) {
1482 int v = bytestream2_get_byteu(&gb);
1483 *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
1484 *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
1487 case AV_CODEC_ID_ADPCM_SBPRO_4:
1488 case AV_CODEC_ID_ADPCM_SBPRO_3:
1489 case AV_CODEC_ID_ADPCM_SBPRO_2:
1490 if (!c->status[0].step_index) {
1491 /* the first byte is a raw sample */
1492 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1494 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
1495 c->status[0].step_index = 1;
1498 if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
1499 for (n = nb_samples >> (1 - st); n > 0; n--) {
1500 int byte = bytestream2_get_byteu(&gb);
1501 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1503 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1506 } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
1507 for (n = (nb_samples<<st) / 3; n > 0; n--) {
1508 int byte = bytestream2_get_byteu(&gb);
1509 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1511 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1512 (byte >> 2) & 0x07, 3, 0);
1513 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1517 for (n = nb_samples >> (2 - st); n > 0; n--) {
1518 int byte = bytestream2_get_byteu(&gb);
1519 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1521 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1522 (byte >> 4) & 0x03, 2, 2);
1523 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1524 (byte >> 2) & 0x03, 2, 2);
1525 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1530 case AV_CODEC_ID_ADPCM_SWF:
1531 adpcm_swf_decode(avctx, buf, buf_size, samples);
1532 bytestream2_seek(&gb, 0, SEEK_END);
1534 case AV_CODEC_ID_ADPCM_YAMAHA:
1535 for (n = nb_samples >> (1 - st); n > 0; n--) {
1536 int v = bytestream2_get_byteu(&gb);
1537 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
1538 *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
1541 case AV_CODEC_ID_ADPCM_AICA:
1542 if (!c->has_status) {
1543 for (channel = 0; channel < avctx->channels; channel++)
1544 c->status[channel].step = 0;
1547 for (channel = 0; channel < avctx->channels; channel++) {
1548 samples = samples_p[channel];
1549 for (n = nb_samples >> 1; n > 0; n--) {
1550 int v = bytestream2_get_byteu(&gb);
1551 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v & 0x0F);
1552 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v >> 4 );
1556 case AV_CODEC_ID_ADPCM_AFC:
1558 int samples_per_block;
1561 if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
1562 samples_per_block = avctx->extradata[0] / 16;
1563 blocks = nb_samples / avctx->extradata[0];
1565 samples_per_block = nb_samples / 16;
1569 for (m = 0; m < blocks; m++) {
1570 for (channel = 0; channel < avctx->channels; channel++) {
1571 int prev1 = c->status[channel].sample1;
1572 int prev2 = c->status[channel].sample2;
1574 samples = samples_p[channel] + m * 16;
1575 /* Read in every sample for this channel. */
1576 for (i = 0; i < samples_per_block; i++) {
1577 int byte = bytestream2_get_byteu(&gb);
1578 int scale = 1 << (byte >> 4);
1579 int index = byte & 0xf;
1580 int factor1 = ff_adpcm_afc_coeffs[0][index];
1581 int factor2 = ff_adpcm_afc_coeffs[1][index];
1583 /* Decode 16 samples. */
1584 for (n = 0; n < 16; n++) {
1588 sampledat = sign_extend(byte, 4);
1590 byte = bytestream2_get_byteu(&gb);
1591 sampledat = sign_extend(byte >> 4, 4);
1594 sampledat = ((prev1 * factor1 + prev2 * factor2) +
1595 ((sampledat * scale) << 11)) >> 11;
1596 *samples = av_clip_int16(sampledat);
1602 c->status[channel].sample1 = prev1;
1603 c->status[channel].sample2 = prev2;
1606 bytestream2_seek(&gb, 0, SEEK_END);
1609 case AV_CODEC_ID_ADPCM_THP:
1610 case AV_CODEC_ID_ADPCM_THP_LE:
1615 #define THP_GET16(g) \
1617 avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
1618 bytestream2_get_le16u(&(g)) : \
1619 bytestream2_get_be16u(&(g)), 16)
1621 if (avctx->extradata) {
1623 if (avctx->extradata_size < 32 * avctx->channels) {
1624 av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
1625 return AVERROR_INVALIDDATA;
1628 bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
1629 for (i = 0; i < avctx->channels; i++)
1630 for (n = 0; n < 16; n++)
1631 table[i][n] = THP_GET16(tb);
1633 for (i = 0; i < avctx->channels; i++)
1634 for (n = 0; n < 16; n++)
1635 table[i][n] = THP_GET16(gb);
1637 if (!c->has_status) {
1638 /* Initialize the previous sample. */
1639 for (i = 0; i < avctx->channels; i++) {
1640 c->status[i].sample1 = THP_GET16(gb);
1641 c->status[i].sample2 = THP_GET16(gb);
1645 bytestream2_skip(&gb, avctx->channels * 4);
1649 for (ch = 0; ch < avctx->channels; ch++) {
1650 samples = samples_p[ch];
1652 /* Read in every sample for this channel. */
1653 for (i = 0; i < (nb_samples + 13) / 14; i++) {
1654 int byte = bytestream2_get_byteu(&gb);
1655 int index = (byte >> 4) & 7;
1656 unsigned int exp = byte & 0x0F;
1657 int factor1 = table[ch][index * 2];
1658 int factor2 = table[ch][index * 2 + 1];
1660 /* Decode 14 samples. */
1661 for (n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
1665 sampledat = sign_extend(byte, 4);
1667 byte = bytestream2_get_byteu(&gb);
1668 sampledat = sign_extend(byte >> 4, 4);
1671 sampledat = ((c->status[ch].sample1 * factor1
1672 + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp);
1673 *samples = av_clip_int16(sampledat);
1674 c->status[ch].sample2 = c->status[ch].sample1;
1675 c->status[ch].sample1 = *samples++;
1681 case AV_CODEC_ID_ADPCM_DTK:
1682 for (channel = 0; channel < avctx->channels; channel++) {
1683 samples = samples_p[channel];
1685 /* Read in every sample for this channel. */
1686 for (i = 0; i < nb_samples / 28; i++) {
1689 bytestream2_skipu(&gb, 1);
1690 header = bytestream2_get_byteu(&gb);
1691 bytestream2_skipu(&gb, 3 - channel);
1693 /* Decode 28 samples. */
1694 for (n = 0; n < 28; n++) {
1695 int32_t sampledat, prev;
1697 switch (header >> 4) {
1699 prev = (c->status[channel].sample1 * 0x3c);
1702 prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
1705 prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
1711 prev = av_clip_intp2((prev + 0x20) >> 6, 21);
1713 byte = bytestream2_get_byteu(&gb);
1715 sampledat = sign_extend(byte, 4);
1717 sampledat = sign_extend(byte >> 4, 4);
1719 sampledat = (((sampledat << 12) >> (header & 0xf)) << 6) + prev;
1720 *samples++ = av_clip_int16(sampledat >> 6);
1721 c->status[channel].sample2 = c->status[channel].sample1;
1722 c->status[channel].sample1 = sampledat;
1726 bytestream2_seek(&gb, 0, SEEK_SET);
1729 case AV_CODEC_ID_ADPCM_PSX:
1730 for (channel = 0; channel < avctx->channels; channel++) {
1731 samples = samples_p[channel];
1733 /* Read in every sample for this channel. */
1734 for (i = 0; i < nb_samples / 28; i++) {
1735 int filter, shift, flag, byte;
1737 filter = bytestream2_get_byteu(&gb);
1738 shift = filter & 0xf;
1739 filter = filter >> 4;
1740 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table))
1741 return AVERROR_INVALIDDATA;
1742 flag = bytestream2_get_byteu(&gb);
1744 /* Decode 28 samples. */
1745 for (n = 0; n < 28; n++) {
1746 int sample = 0, scale;
1750 scale = sign_extend(byte >> 4, 4);
1752 byte = bytestream2_get_byteu(&gb);
1753 scale = sign_extend(byte, 4);
1756 scale = scale << 12;
1757 sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64);
1759 *samples++ = av_clip_int16(sample);
1760 c->status[channel].sample2 = c->status[channel].sample1;
1761 c->status[channel].sample1 = sample;
1768 av_assert0(0); // unsupported codec_id should not happen
1771 if (avpkt->size && bytestream2_tell(&gb) == 0) {
1772 av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");
1773 return AVERROR_INVALIDDATA;
1778 if (avpkt->size < bytestream2_tell(&gb)) {
1779 av_log(avctx, AV_LOG_ERROR, "Overread of %d < %d\n", avpkt->size, bytestream2_tell(&gb));
1783 return bytestream2_tell(&gb);
1786 static void adpcm_flush(AVCodecContext *avctx)
1788 ADPCMDecodeContext *c = avctx->priv_data;
1793 static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
1794 AV_SAMPLE_FMT_NONE };
1795 static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16P,
1796 AV_SAMPLE_FMT_NONE };
1797 static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16,
1799 AV_SAMPLE_FMT_NONE };
1801 #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
1802 AVCodec ff_ ## name_ ## _decoder = { \
1804 .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
1805 .type = AVMEDIA_TYPE_AUDIO, \
1807 .priv_data_size = sizeof(ADPCMDecodeContext), \
1808 .init = adpcm_decode_init, \
1809 .decode = adpcm_decode_frame, \
1810 .flush = adpcm_flush, \
1811 .capabilities = AV_CODEC_CAP_DR1, \
1812 .sample_fmts = sample_fmts_, \
1815 /* Note: Do not forget to add new entries to the Makefile as well. */
1816 ADPCM_DECODER(AV_CODEC_ID_ADPCM_4XM, sample_fmts_s16p, adpcm_4xm, "ADPCM 4X Movie");
1817 ADPCM_DECODER(AV_CODEC_ID_ADPCM_AFC, sample_fmts_s16p, adpcm_afc, "ADPCM Nintendo Gamecube AFC");
1818 ADPCM_DECODER(AV_CODEC_ID_ADPCM_AGM, sample_fmts_s16, adpcm_agm, "ADPCM AmuseGraphics Movie");
1819 ADPCM_DECODER(AV_CODEC_ID_ADPCM_AICA, sample_fmts_s16p, adpcm_aica, "ADPCM Yamaha AICA");
1820 ADPCM_DECODER(AV_CODEC_ID_ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology");
1821 ADPCM_DECODER(AV_CODEC_ID_ADPCM_DTK, sample_fmts_s16p, adpcm_dtk, "ADPCM Nintendo Gamecube DTK");
1822 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts");
1823 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
1824 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1, "ADPCM Electronic Arts R1");
1825 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2, "ADPCM Electronic Arts R2");
1826 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3, "ADPCM Electronic Arts R3");
1827 ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
1828 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV");
1829 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC");
1830 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DAT4, sample_fmts_s16, adpcm_ima_dat4, "ADPCM IMA Eurocom DAT4");
1831 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
1832 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
1833 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
1834 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
1835 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
1836 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_OKI, sample_fmts_s16, adpcm_ima_oki, "ADPCM IMA Dialogic OKI");
1837 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, "ADPCM IMA QuickTime");
1838 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad, "ADPCM IMA Radical");
1839 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
1840 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV");
1841 ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood");
1842 ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_both, adpcm_ms, "ADPCM Microsoft");
1843 ADPCM_DECODER(AV_CODEC_ID_ADPCM_MTAF, sample_fmts_s16p, adpcm_mtaf, "ADPCM MTAF");
1844 ADPCM_DECODER(AV_CODEC_ID_ADPCM_PSX, sample_fmts_s16p, adpcm_psx, "ADPCM Playstation");
1845 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
1846 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
1847 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
1848 ADPCM_DECODER(AV_CODEC_ID_ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash");
1849 ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP_LE, sample_fmts_s16p, adpcm_thp_le, "ADPCM Nintendo THP (little-endian)");
1850 ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo THP");
1851 ADPCM_DECODER(AV_CODEC_ID_ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA");
1852 ADPCM_DECODER(AV_CODEC_ID_ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha");