]> git.sesse.net Git - ffmpeg/blob - libavcodec/adpcm.c
libavcodec: Define a side data type for new extradata
[ffmpeg] / libavcodec / adpcm.c
1 /*
2  * Copyright (c) 2001-2003 The ffmpeg Project
3  *
4  * This file is part of Libav.
5  *
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.
10  *
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.
15  *
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
19  */
20 #include "avcodec.h"
21 #include "get_bits.h"
22 #include "put_bits.h"
23 #include "bytestream.h"
24 #include "adpcm.h"
25 #include "adpcm_data.h"
26
27 /**
28  * @file
29  * ADPCM decoders
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)
41  *
42  * Features and limitations:
43  *
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/
52  *
53  * CD-ROM XA:
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/
57  */
58
59 /* These are for CD-ROM XA ADPCM */
60 static const int xa_adpcm_table[5][2] = {
61     {   0,   0 },
62     {  60,   0 },
63     { 115, -52 },
64     {  98, -55 },
65     { 122, -60 }
66 };
67
68 static const int ea_adpcm_table[] = {
69     0,  240,  460,  392,
70     0,    0, -208, -220,
71     0,    1,    3,    4,
72     7,    8,   10,   11,
73     0,   -1,   -3,   -4
74 };
75
76 // padded to zero where table size is less then 16
77 static const int swf_index_tables[4][16] = {
78     /*2*/ { -1, 2 },
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 }
82 };
83
84 /* end of tables */
85
86 typedef struct ADPCMDecodeContext {
87     AVFrame frame;
88     ADPCMChannelStatus status[6];
89 } ADPCMDecodeContext;
90
91 static av_cold int adpcm_decode_init(AVCodecContext * avctx)
92 {
93     ADPCMDecodeContext *c = avctx->priv_data;
94     unsigned int max_channels = 2;
95
96     switch(avctx->codec->id) {
97     case CODEC_ID_ADPCM_EA_R1:
98     case CODEC_ID_ADPCM_EA_R2:
99     case CODEC_ID_ADPCM_EA_R3:
100     case CODEC_ID_ADPCM_EA_XAS:
101         max_channels = 6;
102         break;
103     }
104     if (avctx->channels <= 0 || avctx->channels > max_channels) {
105         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
106         return AVERROR(EINVAL);
107     }
108
109     switch(avctx->codec->id) {
110     case CODEC_ID_ADPCM_CT:
111         c->status[0].step = c->status[1].step = 511;
112         break;
113     case CODEC_ID_ADPCM_IMA_WAV:
114         if (avctx->bits_per_coded_sample != 4) {
115             av_log(avctx, AV_LOG_ERROR, "Only 4-bit ADPCM IMA WAV files are supported\n");
116             return -1;
117         }
118         break;
119     case CODEC_ID_ADPCM_IMA_WS:
120         if (avctx->extradata && avctx->extradata_size == 2 * 4) {
121             c->status[0].predictor = AV_RL32(avctx->extradata);
122             c->status[1].predictor = AV_RL32(avctx->extradata + 4);
123         }
124         break;
125     default:
126         break;
127     }
128     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
129
130     avcodec_get_frame_defaults(&c->frame);
131     avctx->coded_frame = &c->frame;
132
133     return 0;
134 }
135
136 static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
137 {
138     int step_index;
139     int predictor;
140     int sign, delta, diff, step;
141
142     step = ff_adpcm_step_table[c->step_index];
143     step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
144     if (step_index < 0) step_index = 0;
145     else if (step_index > 88) step_index = 88;
146
147     sign = nibble & 8;
148     delta = nibble & 7;
149     /* perform direct multiplication instead of series of jumps proposed by
150      * the reference ADPCM implementation since modern CPUs can do the mults
151      * quickly enough */
152     diff = ((2 * delta + 1) * step) >> shift;
153     predictor = c->predictor;
154     if (sign) predictor -= diff;
155     else predictor += diff;
156
157     c->predictor = av_clip_int16(predictor);
158     c->step_index = step_index;
159
160     return (short)c->predictor;
161 }
162
163 static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
164 {
165     int step_index;
166     int predictor;
167     int diff, step;
168
169     step = ff_adpcm_step_table[c->step_index];
170     step_index = c->step_index + ff_adpcm_index_table[nibble];
171     step_index = av_clip(step_index, 0, 88);
172
173     diff = step >> 3;
174     if (nibble & 4) diff += step;
175     if (nibble & 2) diff += step >> 1;
176     if (nibble & 1) diff += step >> 2;
177
178     if (nibble & 8)
179         predictor = c->predictor - diff;
180     else
181         predictor = c->predictor + diff;
182
183     c->predictor = av_clip_int16(predictor);
184     c->step_index = step_index;
185
186     return c->predictor;
187 }
188
189 static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
190 {
191     int predictor;
192
193     predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
194     predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
195
196     c->sample2 = c->sample1;
197     c->sample1 = av_clip_int16(predictor);
198     c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
199     if (c->idelta < 16) c->idelta = 16;
200
201     return c->sample1;
202 }
203
204 static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
205 {
206     int sign, delta, diff;
207     int new_step;
208
209     sign = nibble & 8;
210     delta = nibble & 7;
211     /* perform direct multiplication instead of series of jumps proposed by
212      * the reference ADPCM implementation since modern CPUs can do the mults
213      * quickly enough */
214     diff = ((2 * delta + 1) * c->step) >> 3;
215     /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
216     c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
217     c->predictor = av_clip_int16(c->predictor);
218     /* calculate new step and clamp it to range 511..32767 */
219     new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
220     c->step = av_clip(new_step, 511, 32767);
221
222     return (short)c->predictor;
223 }
224
225 static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
226 {
227     int sign, delta, diff;
228
229     sign = nibble & (1<<(size-1));
230     delta = nibble & ((1<<(size-1))-1);
231     diff = delta << (7 + c->step + shift);
232
233     /* clamp result */
234     c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
235
236     /* calculate new step */
237     if (delta >= (2*size - 3) && c->step < 3)
238         c->step++;
239     else if (delta == 0 && c->step > 0)
240         c->step--;
241
242     return (short) c->predictor;
243 }
244
245 static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
246 {
247     if(!c->step) {
248         c->predictor = 0;
249         c->step = 127;
250     }
251
252     c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
253     c->predictor = av_clip_int16(c->predictor);
254     c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
255     c->step = av_clip(c->step, 127, 24567);
256     return c->predictor;
257 }
258
259 static void xa_decode(short *out, const unsigned char *in,
260     ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
261 {
262     int i, j;
263     int shift,filter,f0,f1;
264     int s_1,s_2;
265     int d,s,t;
266
267     for(i=0;i<4;i++) {
268
269         shift  = 12 - (in[4+i*2] & 15);
270         filter = in[4+i*2] >> 4;
271         f0 = xa_adpcm_table[filter][0];
272         f1 = xa_adpcm_table[filter][1];
273
274         s_1 = left->sample1;
275         s_2 = left->sample2;
276
277         for(j=0;j<28;j++) {
278             d = in[16+i+j*4];
279
280             t = (signed char)(d<<4)>>4;
281             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
282             s_2 = s_1;
283             s_1 = av_clip_int16(s);
284             *out = s_1;
285             out += inc;
286         }
287
288         if (inc==2) { /* stereo */
289             left->sample1 = s_1;
290             left->sample2 = s_2;
291             s_1 = right->sample1;
292             s_2 = right->sample2;
293             out = out + 1 - 28*2;
294         }
295
296         shift  = 12 - (in[5+i*2] & 15);
297         filter = in[5+i*2] >> 4;
298
299         f0 = xa_adpcm_table[filter][0];
300         f1 = xa_adpcm_table[filter][1];
301
302         for(j=0;j<28;j++) {
303             d = in[16+i+j*4];
304
305             t = (signed char)d >> 4;
306             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
307             s_2 = s_1;
308             s_1 = av_clip_int16(s);
309             *out = s_1;
310             out += inc;
311         }
312
313         if (inc==2) { /* stereo */
314             right->sample1 = s_1;
315             right->sample2 = s_2;
316             out -= 1;
317         } else {
318             left->sample1 = s_1;
319             left->sample2 = s_2;
320         }
321     }
322 }
323
324 /**
325  * Get the number of samples that will be decoded from the packet.
326  * In one case, this is actually the maximum number of samples possible to
327  * decode with the given buf_size.
328  *
329  * @param[out] coded_samples set to the number of samples as coded in the
330  *                           packet, or 0 if the codec does not encode the
331  *                           number of samples in each frame.
332  */
333 static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf,
334                           int buf_size, int *coded_samples)
335 {
336     ADPCMDecodeContext *s = avctx->priv_data;
337     int nb_samples        = 0;
338     int ch                = avctx->channels;
339     int has_coded_samples = 0;
340     int header_size;
341
342     *coded_samples = 0;
343
344     switch (avctx->codec->id) {
345     /* constant, only check buf_size */
346     case CODEC_ID_ADPCM_EA_XAS:
347         if (buf_size < 76 * ch)
348             return 0;
349         nb_samples = 128;
350         break;
351     case CODEC_ID_ADPCM_IMA_QT:
352         if (buf_size < 34 * ch)
353             return 0;
354         nb_samples = 64;
355         break;
356     /* simple 4-bit adpcm */
357     case CODEC_ID_ADPCM_CT:
358     case CODEC_ID_ADPCM_IMA_EA_SEAD:
359     case CODEC_ID_ADPCM_IMA_WS:
360     case CODEC_ID_ADPCM_YAMAHA:
361         nb_samples = buf_size * 2 / ch;
362         break;
363     }
364     if (nb_samples)
365         return nb_samples;
366
367     /* simple 4-bit adpcm, with header */
368     header_size = 0;
369     switch (avctx->codec->id) {
370         case CODEC_ID_ADPCM_4XM:
371         case CODEC_ID_ADPCM_IMA_ISS:     header_size = 4 * ch;      break;
372         case CODEC_ID_ADPCM_IMA_AMV:     header_size = 8;           break;
373         case CODEC_ID_ADPCM_IMA_SMJPEG:  header_size = 4;           break;
374     }
375     if (header_size > 0)
376         return (buf_size - header_size) * 2 / ch;
377
378     /* more complex formats */
379     switch (avctx->codec->id) {
380     case CODEC_ID_ADPCM_EA:
381         has_coded_samples = 1;
382         if (buf_size < 4)
383             return 0;
384         *coded_samples  = AV_RL32(buf);
385         *coded_samples -= *coded_samples % 28;
386         nb_samples      = (buf_size - 12) / 30 * 28;
387         break;
388     case CODEC_ID_ADPCM_IMA_EA_EACS:
389         has_coded_samples = 1;
390         if (buf_size < 4)
391             return 0;
392         *coded_samples = AV_RL32(buf);
393         nb_samples     = (buf_size - (4 + 8 * ch)) * 2 / ch;
394         break;
395     case CODEC_ID_ADPCM_EA_MAXIS_XA:
396         nb_samples = ((buf_size - ch) / (2 * ch)) * 2 * ch;
397         break;
398     case CODEC_ID_ADPCM_EA_R1:
399     case CODEC_ID_ADPCM_EA_R2:
400     case CODEC_ID_ADPCM_EA_R3:
401         /* maximum number of samples */
402         /* has internal offsets and a per-frame switch to signal raw 16-bit */
403         has_coded_samples = 1;
404         if (buf_size < 4)
405             return 0;
406         switch (avctx->codec->id) {
407         case CODEC_ID_ADPCM_EA_R1:
408             header_size    = 4 + 9 * ch;
409             *coded_samples = AV_RL32(buf);
410             break;
411         case CODEC_ID_ADPCM_EA_R2:
412             header_size    = 4 + 5 * ch;
413             *coded_samples = AV_RL32(buf);
414             break;
415         case CODEC_ID_ADPCM_EA_R3:
416             header_size    = 4 + 5 * ch;
417             *coded_samples = AV_RB32(buf);
418             break;
419         }
420         *coded_samples -= *coded_samples % 28;
421         nb_samples      = (buf_size - header_size) * 2 / ch;
422         nb_samples     -= nb_samples % 28;
423         break;
424     case CODEC_ID_ADPCM_IMA_DK3:
425         if (avctx->block_align > 0)
426             buf_size = FFMIN(buf_size, avctx->block_align);
427         nb_samples = ((buf_size - 16) * 8 / 3) / ch;
428         break;
429     case CODEC_ID_ADPCM_IMA_DK4:
430         nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
431         break;
432     case CODEC_ID_ADPCM_IMA_WAV:
433         if (avctx->block_align > 0)
434             buf_size = FFMIN(buf_size, avctx->block_align);
435         nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8;
436         break;
437     case CODEC_ID_ADPCM_MS:
438         if (avctx->block_align > 0)
439             buf_size = FFMIN(buf_size, avctx->block_align);
440         nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
441         break;
442     case CODEC_ID_ADPCM_SBPRO_2:
443     case CODEC_ID_ADPCM_SBPRO_3:
444     case CODEC_ID_ADPCM_SBPRO_4:
445     {
446         int samples_per_byte;
447         switch (avctx->codec->id) {
448         case CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
449         case CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
450         case CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
451         }
452         if (!s->status[0].step_index) {
453             nb_samples++;
454             buf_size -= ch;
455         }
456         nb_samples += buf_size * samples_per_byte / ch;
457         break;
458     }
459     case CODEC_ID_ADPCM_SWF:
460     {
461         int buf_bits       = buf_size * 8 - 2;
462         int nbits          = (buf[0] >> 6) + 2;
463         int block_hdr_size = 22 * ch;
464         int block_size     = block_hdr_size + nbits * ch * 4095;
465         int nblocks        = buf_bits / block_size;
466         int bits_left      = buf_bits - nblocks * block_size;
467         nb_samples         = nblocks * 4096;
468         if (bits_left >= block_hdr_size)
469             nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
470         break;
471     }
472     case CODEC_ID_ADPCM_THP:
473         has_coded_samples = 1;
474         if (buf_size < 8)
475             return 0;
476         *coded_samples  = AV_RB32(&buf[4]);
477         *coded_samples -= *coded_samples % 14;
478         nb_samples      = (buf_size - 80) / (8 * ch) * 14;
479         break;
480     case CODEC_ID_ADPCM_XA:
481         nb_samples = (buf_size / 128) * 224 / ch;
482         break;
483     }
484
485     /* validate coded sample count */
486     if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
487         return AVERROR_INVALIDDATA;
488
489     return nb_samples;
490 }
491
492 /* DK3 ADPCM support macro */
493 #define DK3_GET_NEXT_NIBBLE() \
494     if (decode_top_nibble_next) \
495     { \
496         nibble = last_byte >> 4; \
497         decode_top_nibble_next = 0; \
498     } \
499     else \
500     { \
501         if (end_of_packet) \
502             break; \
503         last_byte = *src++; \
504         if (src >= buf + buf_size) \
505             end_of_packet = 1; \
506         nibble = last_byte & 0x0F; \
507         decode_top_nibble_next = 1; \
508     }
509
510 static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
511                               int *got_frame_ptr, AVPacket *avpkt)
512 {
513     const uint8_t *buf = avpkt->data;
514     int buf_size = avpkt->size;
515     ADPCMDecodeContext *c = avctx->priv_data;
516     ADPCMChannelStatus *cs;
517     int n, m, channel, i;
518     short *samples;
519     const uint8_t *src;
520     int st; /* stereo */
521     int count1, count2;
522     int nb_samples, coded_samples, ret;
523
524     nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples);
525     if (nb_samples <= 0) {
526         av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
527         return AVERROR_INVALIDDATA;
528     }
529
530     /* get output buffer */
531     c->frame.nb_samples = nb_samples;
532     if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) {
533         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
534         return ret;
535     }
536     samples = (short *)c->frame.data[0];
537
538     /* use coded_samples when applicable */
539     /* it is always <= nb_samples, so the output buffer will be large enough */
540     if (coded_samples) {
541         if (coded_samples != nb_samples)
542             av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
543         c->frame.nb_samples = nb_samples = coded_samples;
544     }
545
546     src = buf;
547
548     st = avctx->channels == 2 ? 1 : 0;
549
550     switch(avctx->codec->id) {
551     case CODEC_ID_ADPCM_IMA_QT:
552         /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
553            Channel data is interleaved per-chunk. */
554         for (channel = 0; channel < avctx->channels; channel++) {
555             int16_t predictor;
556             int step_index;
557             cs = &(c->status[channel]);
558             /* (pppppp) (piiiiiii) */
559
560             /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
561             predictor = AV_RB16(src);
562             step_index = predictor & 0x7F;
563             predictor &= 0xFF80;
564
565             src += 2;
566
567             if (cs->step_index == step_index) {
568                 int diff = (int)predictor - cs->predictor;
569                 if (diff < 0)
570                     diff = - diff;
571                 if (diff > 0x7f)
572                     goto update;
573             } else {
574             update:
575                 cs->step_index = step_index;
576                 cs->predictor = predictor;
577             }
578
579             if (cs->step_index > 88){
580                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
581                 cs->step_index = 88;
582             }
583
584             samples = (short *)c->frame.data[0] + channel;
585
586             for (m = 0; m < 32; m++) {
587                 *samples = adpcm_ima_qt_expand_nibble(cs, src[0] & 0x0F, 3);
588                 samples += avctx->channels;
589                 *samples = adpcm_ima_qt_expand_nibble(cs, src[0] >> 4  , 3);
590                 samples += avctx->channels;
591                 src ++;
592             }
593         }
594         break;
595     case CODEC_ID_ADPCM_IMA_WAV:
596         if (avctx->block_align != 0 && buf_size > avctx->block_align)
597             buf_size = avctx->block_align;
598
599         for(i=0; i<avctx->channels; i++){
600             cs = &(c->status[i]);
601             cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src);
602
603             cs->step_index = *src++;
604             if (cs->step_index > 88){
605                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
606                 cs->step_index = 88;
607             }
608             if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */
609         }
610
611         for (n = (nb_samples - 1) / 8; n > 0; n--) {
612             for (i = 0; i < avctx->channels; i++) {
613                 cs = &c->status[i];
614                 for (m = 0; m < 4; m++) {
615                     uint8_t v = *src++;
616                     *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
617                     samples += avctx->channels;
618                     *samples = adpcm_ima_expand_nibble(cs, v >> 4  , 3);
619                     samples += avctx->channels;
620                 }
621                 samples -= 8 * avctx->channels - 1;
622             }
623             samples += 7 * avctx->channels;
624         }
625         break;
626     case CODEC_ID_ADPCM_4XM:
627         for (i = 0; i < avctx->channels; i++)
628             c->status[i].predictor= (int16_t)bytestream_get_le16(&src);
629
630         for (i = 0; i < avctx->channels; i++) {
631             c->status[i].step_index= (int16_t)bytestream_get_le16(&src);
632             c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
633         }
634
635         for (i = 0; i < avctx->channels; i++) {
636             samples = (short *)c->frame.data[0] + i;
637             cs = &c->status[i];
638             for (n = nb_samples >> 1; n > 0; n--, src++) {
639                 uint8_t v = *src;
640                 *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
641                 samples += avctx->channels;
642                 *samples = adpcm_ima_expand_nibble(cs, v >> 4  , 4);
643                 samples += avctx->channels;
644             }
645         }
646         break;
647     case CODEC_ID_ADPCM_MS:
648     {
649         int block_predictor;
650
651         if (avctx->block_align != 0 && buf_size > avctx->block_align)
652             buf_size = avctx->block_align;
653
654         block_predictor = av_clip(*src++, 0, 6);
655         c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
656         c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
657         if (st) {
658             block_predictor = av_clip(*src++, 0, 6);
659             c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
660             c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
661         }
662         c->status[0].idelta = (int16_t)bytestream_get_le16(&src);
663         if (st){
664             c->status[1].idelta = (int16_t)bytestream_get_le16(&src);
665         }
666
667         c->status[0].sample1 = bytestream_get_le16(&src);
668         if (st) c->status[1].sample1 = bytestream_get_le16(&src);
669         c->status[0].sample2 = bytestream_get_le16(&src);
670         if (st) c->status[1].sample2 = bytestream_get_le16(&src);
671
672         *samples++ = c->status[0].sample2;
673         if (st) *samples++ = c->status[1].sample2;
674         *samples++ = c->status[0].sample1;
675         if (st) *samples++ = c->status[1].sample1;
676         for(n = (nb_samples - 2) >> (1 - st); n > 0; n--, src++) {
677             *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4  );
678             *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
679         }
680         break;
681     }
682     case CODEC_ID_ADPCM_IMA_DK4:
683         if (avctx->block_align != 0 && buf_size > avctx->block_align)
684             buf_size = avctx->block_align;
685
686         for (channel = 0; channel < avctx->channels; channel++) {
687             cs = &c->status[channel];
688             cs->predictor  = (int16_t)bytestream_get_le16(&src);
689             cs->step_index = *src++;
690             src++;
691             *samples++ = cs->predictor;
692         }
693         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
694             uint8_t v = *src;
695             *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4  , 3);
696             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
697         }
698         break;
699     case CODEC_ID_ADPCM_IMA_DK3:
700     {
701         unsigned char last_byte = 0;
702         unsigned char nibble;
703         int decode_top_nibble_next = 0;
704         int end_of_packet = 0;
705         int diff_channel;
706
707         if (avctx->block_align != 0 && buf_size > avctx->block_align)
708             buf_size = avctx->block_align;
709
710         c->status[0].predictor  = (int16_t)AV_RL16(src + 10);
711         c->status[1].predictor  = (int16_t)AV_RL16(src + 12);
712         c->status[0].step_index = src[14];
713         c->status[1].step_index = src[15];
714         /* sign extend the predictors */
715         src += 16;
716         diff_channel = c->status[1].predictor;
717
718         /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
719          * the buffer is consumed */
720         while (1) {
721
722             /* for this algorithm, c->status[0] is the sum channel and
723              * c->status[1] is the diff channel */
724
725             /* process the first predictor of the sum channel */
726             DK3_GET_NEXT_NIBBLE();
727             adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
728
729             /* process the diff channel predictor */
730             DK3_GET_NEXT_NIBBLE();
731             adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
732
733             /* process the first pair of stereo PCM samples */
734             diff_channel = (diff_channel + c->status[1].predictor) / 2;
735             *samples++ = c->status[0].predictor + c->status[1].predictor;
736             *samples++ = c->status[0].predictor - c->status[1].predictor;
737
738             /* process the second predictor of the sum channel */
739             DK3_GET_NEXT_NIBBLE();
740             adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
741
742             /* process the second pair of stereo PCM samples */
743             diff_channel = (diff_channel + c->status[1].predictor) / 2;
744             *samples++ = c->status[0].predictor + c->status[1].predictor;
745             *samples++ = c->status[0].predictor - c->status[1].predictor;
746         }
747         break;
748     }
749     case CODEC_ID_ADPCM_IMA_ISS:
750         for (channel = 0; channel < avctx->channels; channel++) {
751             cs = &c->status[channel];
752             cs->predictor  = (int16_t)bytestream_get_le16(&src);
753             cs->step_index = *src++;
754             src++;
755         }
756
757         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
758             uint8_t v1, v2;
759             uint8_t v = *src;
760             /* nibbles are swapped for mono */
761             if (st) {
762                 v1 = v >> 4;
763                 v2 = v & 0x0F;
764             } else {
765                 v2 = v >> 4;
766                 v1 = v & 0x0F;
767             }
768             *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
769             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
770         }
771         break;
772     case CODEC_ID_ADPCM_IMA_WS:
773         while (src < buf + buf_size) {
774             uint8_t v = *src++;
775             *samples++ = adpcm_ima_expand_nibble(&c->status[0],  v >> 4  , 3);
776             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
777         }
778         break;
779     case CODEC_ID_ADPCM_XA:
780         while (buf_size >= 128) {
781             xa_decode(samples, src, &c->status[0], &c->status[1],
782                 avctx->channels);
783             src += 128;
784             samples += 28 * 8;
785             buf_size -= 128;
786         }
787         break;
788     case CODEC_ID_ADPCM_IMA_EA_EACS:
789         src += 4; // skip sample count (already read)
790
791         for (i=0; i<=st; i++)
792             c->status[i].step_index = bytestream_get_le32(&src);
793         for (i=0; i<=st; i++)
794             c->status[i].predictor  = bytestream_get_le32(&src);
795
796         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
797             *samples++ = adpcm_ima_expand_nibble(&c->status[0],  *src>>4,   3);
798             *samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);
799         }
800         break;
801     case CODEC_ID_ADPCM_IMA_EA_SEAD:
802         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
803             *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6);
804             *samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6);
805         }
806         break;
807     case CODEC_ID_ADPCM_EA:
808     {
809         int32_t previous_left_sample, previous_right_sample;
810         int32_t current_left_sample, current_right_sample;
811         int32_t next_left_sample, next_right_sample;
812         int32_t coeff1l, coeff2l, coeff1r, coeff2r;
813         uint8_t shift_left, shift_right;
814
815         /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
816            each coding 28 stereo samples. */
817
818         src += 4; // skip sample count (already read)
819
820         current_left_sample   = (int16_t)bytestream_get_le16(&src);
821         previous_left_sample  = (int16_t)bytestream_get_le16(&src);
822         current_right_sample  = (int16_t)bytestream_get_le16(&src);
823         previous_right_sample = (int16_t)bytestream_get_le16(&src);
824
825         for (count1 = 0; count1 < nb_samples / 28; count1++) {
826             coeff1l = ea_adpcm_table[ *src >> 4       ];
827             coeff2l = ea_adpcm_table[(*src >> 4  ) + 4];
828             coeff1r = ea_adpcm_table[*src & 0x0F];
829             coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
830             src++;
831
832             shift_left  = 20 - (*src >> 4);
833             shift_right = 20 - (*src & 0x0F);
834             src++;
835
836             for (count2 = 0; count2 < 28; count2++) {
837                 next_left_sample  = sign_extend(*src >> 4, 4) << shift_left;
838                 next_right_sample = sign_extend(*src,      4) << shift_right;
839                 src++;
840
841                 next_left_sample = (next_left_sample +
842                     (current_left_sample * coeff1l) +
843                     (previous_left_sample * coeff2l) + 0x80) >> 8;
844                 next_right_sample = (next_right_sample +
845                     (current_right_sample * coeff1r) +
846                     (previous_right_sample * coeff2r) + 0x80) >> 8;
847
848                 previous_left_sample = current_left_sample;
849                 current_left_sample = av_clip_int16(next_left_sample);
850                 previous_right_sample = current_right_sample;
851                 current_right_sample = av_clip_int16(next_right_sample);
852                 *samples++ = (unsigned short)current_left_sample;
853                 *samples++ = (unsigned short)current_right_sample;
854             }
855         }
856
857         if (src - buf == buf_size - 2)
858             src += 2; // Skip terminating 0x0000
859
860         break;
861     }
862     case CODEC_ID_ADPCM_EA_MAXIS_XA:
863     {
864         int coeff[2][2], shift[2];
865
866         for(channel = 0; channel < avctx->channels; channel++) {
867             for (i=0; i<2; i++)
868                 coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i];
869             shift[channel] = 20 - (*src & 0x0F);
870             src++;
871         }
872         for (count1 = 0; count1 < nb_samples / 2; count1++) {
873             for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
874                 for(channel = 0; channel < avctx->channels; channel++) {
875                     int32_t sample = sign_extend(src[channel] >> i, 4) << shift[channel];
876                     sample = (sample +
877                              c->status[channel].sample1 * coeff[channel][0] +
878                              c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
879                     c->status[channel].sample2 = c->status[channel].sample1;
880                     c->status[channel].sample1 = av_clip_int16(sample);
881                     *samples++ = c->status[channel].sample1;
882                 }
883             }
884             src+=avctx->channels;
885         }
886         /* consume whole packet */
887         src = buf + buf_size;
888         break;
889     }
890     case CODEC_ID_ADPCM_EA_R1:
891     case CODEC_ID_ADPCM_EA_R2:
892     case CODEC_ID_ADPCM_EA_R3: {
893         /* channel numbering
894            2chan: 0=fl, 1=fr
895            4chan: 0=fl, 1=rl, 2=fr, 3=rr
896            6chan: 0=fl, 1=c,  2=fr, 3=rl,  4=rr, 5=sub */
897         const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3;
898         int32_t previous_sample, current_sample, next_sample;
899         int32_t coeff1, coeff2;
900         uint8_t shift;
901         unsigned int channel;
902         uint16_t *samplesC;
903         const uint8_t *srcC;
904         const uint8_t *src_end = buf + buf_size;
905         int count = 0;
906
907         src += 4; // skip sample count (already read)
908
909         for (channel=0; channel<avctx->channels; channel++) {
910             int32_t offset = (big_endian ? bytestream_get_be32(&src)
911                                          : bytestream_get_le32(&src))
912                            + (avctx->channels-channel-1) * 4;
913
914             if ((offset < 0) || (offset >= src_end - src - 4)) break;
915             srcC  = src + offset;
916             samplesC = samples + channel;
917
918             if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) {
919                 current_sample  = (int16_t)bytestream_get_le16(&srcC);
920                 previous_sample = (int16_t)bytestream_get_le16(&srcC);
921             } else {
922                 current_sample  = c->status[channel].predictor;
923                 previous_sample = c->status[channel].prev_sample;
924             }
925
926             for (count1 = 0; count1 < nb_samples / 28; count1++) {
927                 if (*srcC == 0xEE) {  /* only seen in R2 and R3 */
928                     srcC++;
929                     if (srcC > src_end - 30*2) break;
930                     current_sample  = (int16_t)bytestream_get_be16(&srcC);
931                     previous_sample = (int16_t)bytestream_get_be16(&srcC);
932
933                     for (count2=0; count2<28; count2++) {
934                         *samplesC = (int16_t)bytestream_get_be16(&srcC);
935                         samplesC += avctx->channels;
936                     }
937                 } else {
938                     coeff1 = ea_adpcm_table[ *srcC>>4     ];
939                     coeff2 = ea_adpcm_table[(*srcC>>4) + 4];
940                     shift = 20 - (*srcC++ & 0x0F);
941
942                     if (srcC > src_end - 14) break;
943                     for (count2=0; count2<28; count2++) {
944                         if (count2 & 1)
945                             next_sample = sign_extend(*srcC++,    4) << shift;
946                         else
947                             next_sample = sign_extend(*srcC >> 4, 4) << shift;
948
949                         next_sample += (current_sample  * coeff1) +
950                                        (previous_sample * coeff2);
951                         next_sample = av_clip_int16(next_sample >> 8);
952
953                         previous_sample = current_sample;
954                         current_sample  = next_sample;
955                         *samplesC = current_sample;
956                         samplesC += avctx->channels;
957                     }
958                 }
959             }
960             if (!count) {
961                 count = count1;
962             } else if (count != count1) {
963                 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
964                 count = FFMAX(count, count1);
965             }
966
967             if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) {
968                 c->status[channel].predictor   = current_sample;
969                 c->status[channel].prev_sample = previous_sample;
970             }
971         }
972
973         c->frame.nb_samples = count * 28;
974         src = src_end;
975         break;
976     }
977     case CODEC_ID_ADPCM_EA_XAS:
978         for (channel=0; channel<avctx->channels; channel++) {
979             int coeff[2][4], shift[4];
980             short *s2, *s = &samples[channel];
981             for (n=0; n<4; n++, s+=32*avctx->channels) {
982                 for (i=0; i<2; i++)
983                     coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i];
984                 shift[n] = 20 - (src[2] & 0x0F);
985                 for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels)
986                     s2[0] = (src[0]&0xF0) + (src[1]<<8);
987             }
988
989             for (m=2; m<32; m+=2) {
990                 s = &samples[m*avctx->channels + channel];
991                 for (n=0; n<4; n++, src++, s+=32*avctx->channels) {
992                     for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) {
993                         int level = sign_extend(*src >> (4 - i), 4) << shift[n];
994                         int pred  = s2[-1*avctx->channels] * coeff[0][n]
995                                   + s2[-2*avctx->channels] * coeff[1][n];
996                         s2[0] = av_clip_int16((level + pred + 0x80) >> 8);
997                     }
998                 }
999             }
1000         }
1001         break;
1002     case CODEC_ID_ADPCM_IMA_AMV:
1003     case CODEC_ID_ADPCM_IMA_SMJPEG:
1004         c->status[0].predictor = (int16_t)bytestream_get_le16(&src);
1005         c->status[0].step_index = bytestream_get_le16(&src);
1006
1007         if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
1008             src+=4;
1009
1010         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1011             char hi, lo;
1012             lo = *src & 0x0F;
1013             hi = *src >> 4;
1014
1015             if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
1016                 FFSWAP(char, hi, lo);
1017
1018             *samples++ = adpcm_ima_expand_nibble(&c->status[0],
1019                 lo, 3);
1020             *samples++ = adpcm_ima_expand_nibble(&c->status[0],
1021                 hi, 3);
1022         }
1023         break;
1024     case CODEC_ID_ADPCM_CT:
1025         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1026             uint8_t v = *src;
1027             *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4  );
1028             *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
1029         }
1030         break;
1031     case CODEC_ID_ADPCM_SBPRO_4:
1032     case CODEC_ID_ADPCM_SBPRO_3:
1033     case CODEC_ID_ADPCM_SBPRO_2:
1034         if (!c->status[0].step_index) {
1035             /* the first byte is a raw sample */
1036             *samples++ = 128 * (*src++ - 0x80);
1037             if (st)
1038               *samples++ = 128 * (*src++ - 0x80);
1039             c->status[0].step_index = 1;
1040             nb_samples--;
1041         }
1042         if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
1043             for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1044                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1045                     src[0] >> 4, 4, 0);
1046                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1047                     src[0] & 0x0F, 4, 0);
1048             }
1049         } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
1050             for (n = nb_samples / 3; n > 0; n--, src++) {
1051                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1052                      src[0] >> 5        , 3, 0);
1053                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1054                     (src[0] >> 2) & 0x07, 3, 0);
1055                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1056                     src[0] & 0x03, 2, 0);
1057             }
1058         } else {
1059             for (n = nb_samples >> (2 - st); n > 0; n--, src++) {
1060                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1061                      src[0] >> 6        , 2, 2);
1062                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1063                     (src[0] >> 4) & 0x03, 2, 2);
1064                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1065                     (src[0] >> 2) & 0x03, 2, 2);
1066                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1067                     src[0] & 0x03, 2, 2);
1068             }
1069         }
1070         break;
1071     case CODEC_ID_ADPCM_SWF:
1072     {
1073         GetBitContext gb;
1074         const int *table;
1075         int k0, signmask, nb_bits, count;
1076         int size = buf_size*8;
1077
1078         init_get_bits(&gb, buf, size);
1079
1080         //read bits & initial values
1081         nb_bits = get_bits(&gb, 2)+2;
1082         //av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", nb_bits);
1083         table = swf_index_tables[nb_bits-2];
1084         k0 = 1 << (nb_bits-2);
1085         signmask = 1 << (nb_bits-1);
1086
1087         while (get_bits_count(&gb) <= size - 22*avctx->channels) {
1088             for (i = 0; i < avctx->channels; i++) {
1089                 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
1090                 c->status[i].step_index = get_bits(&gb, 6);
1091             }
1092
1093             for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
1094                 int i;
1095
1096                 for (i = 0; i < avctx->channels; i++) {
1097                     // similar to IMA adpcm
1098                     int delta = get_bits(&gb, nb_bits);
1099                     int step = ff_adpcm_step_table[c->status[i].step_index];
1100                     long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
1101                     int k = k0;
1102
1103                     do {
1104                         if (delta & k)
1105                             vpdiff += step;
1106                         step >>= 1;
1107                         k >>= 1;
1108                     } while(k);
1109                     vpdiff += step;
1110
1111                     if (delta & signmask)
1112                         c->status[i].predictor -= vpdiff;
1113                     else
1114                         c->status[i].predictor += vpdiff;
1115
1116                     c->status[i].step_index += table[delta & (~signmask)];
1117
1118                     c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
1119                     c->status[i].predictor = av_clip_int16(c->status[i].predictor);
1120
1121                     *samples++ = c->status[i].predictor;
1122                 }
1123             }
1124         }
1125         src += buf_size;
1126         break;
1127     }
1128     case CODEC_ID_ADPCM_YAMAHA:
1129         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1130             uint8_t v = *src;
1131             *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
1132             *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4  );
1133         }
1134         break;
1135     case CODEC_ID_ADPCM_THP:
1136     {
1137         int table[2][16];
1138         int prev[2][2];
1139         int ch;
1140
1141         src += 4; // skip channel size
1142         src += 4; // skip number of samples (already read)
1143
1144         for (i = 0; i < 32; i++)
1145             table[0][i] = (int16_t)bytestream_get_be16(&src);
1146
1147         /* Initialize the previous sample.  */
1148         for (i = 0; i < 4; i++)
1149             prev[0][i] = (int16_t)bytestream_get_be16(&src);
1150
1151         for (ch = 0; ch <= st; ch++) {
1152             samples = (short *)c->frame.data[0] + ch;
1153
1154             /* Read in every sample for this channel.  */
1155             for (i = 0; i < nb_samples / 14; i++) {
1156                 int index = (*src >> 4) & 7;
1157                 unsigned int exp = *src++ & 15;
1158                 int factor1 = table[ch][index * 2];
1159                 int factor2 = table[ch][index * 2 + 1];
1160
1161                 /* Decode 14 samples.  */
1162                 for (n = 0; n < 14; n++) {
1163                     int32_t sampledat;
1164                     if(n&1) sampledat = sign_extend(*src++, 4);
1165                     else    sampledat = sign_extend(*src >> 4, 4);
1166
1167                     sampledat = ((prev[ch][0]*factor1
1168                                 + prev[ch][1]*factor2) >> 11) + (sampledat << exp);
1169                     *samples = av_clip_int16(sampledat);
1170                     prev[ch][1] = prev[ch][0];
1171                     prev[ch][0] = *samples++;
1172
1173                     /* In case of stereo, skip one sample, this sample
1174                        is for the other channel.  */
1175                     samples += st;
1176                 }
1177             }
1178         }
1179         break;
1180     }
1181
1182     default:
1183         return -1;
1184     }
1185
1186     *got_frame_ptr   = 1;
1187     *(AVFrame *)data = c->frame;
1188
1189     return src - buf;
1190 }
1191
1192
1193 #define ADPCM_DECODER(id_, name_, long_name_)               \
1194 AVCodec ff_ ## name_ ## _decoder = {                        \
1195     .name           = #name_,                               \
1196     .type           = AVMEDIA_TYPE_AUDIO,                   \
1197     .id             = id_,                                  \
1198     .priv_data_size = sizeof(ADPCMDecodeContext),           \
1199     .init           = adpcm_decode_init,                    \
1200     .decode         = adpcm_decode_frame,                   \
1201     .capabilities   = CODEC_CAP_DR1,                        \
1202     .long_name      = NULL_IF_CONFIG_SMALL(long_name_),     \
1203 }
1204
1205 /* Note: Do not forget to add new entries to the Makefile as well. */
1206 ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie");
1207 ADPCM_DECODER(CODEC_ID_ADPCM_CT, adpcm_ct, "ADPCM Creative Technology");
1208 ADPCM_DECODER(CODEC_ID_ADPCM_EA, adpcm_ea, "ADPCM Electronic Arts");
1209 ADPCM_DECODER(CODEC_ID_ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
1210 ADPCM_DECODER(CODEC_ID_ADPCM_EA_R1, adpcm_ea_r1, "ADPCM Electronic Arts R1");
1211 ADPCM_DECODER(CODEC_ID_ADPCM_EA_R2, adpcm_ea_r2, "ADPCM Electronic Arts R2");
1212 ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3, "ADPCM Electronic Arts R3");
1213 ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
1214 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, "ADPCM IMA AMV");
1215 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
1216 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
1217 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
1218 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
1219 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
1220 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime");
1221 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
1222 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV");
1223 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "ADPCM IMA Westwood");
1224 ADPCM_DECODER(CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft");
1225 ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
1226 ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
1227 ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
1228 ADPCM_DECODER(CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash");
1229 ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "ADPCM Nintendo Gamecube THP");
1230 ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "ADPCM CDROM XA");
1231 ADPCM_DECODER(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha");