]> git.sesse.net Git - ffmpeg/blob - libavcodec/adpcm.c
Merge remote-tracking branch 'tjoppen/proper_mxf_track_linking'
[ffmpeg] / libavcodec / adpcm.c
1 /*
2  * Copyright (c) 2001-2003 The ffmpeg Project
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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     if(ch <= 0)
345         return 0;
346
347     switch (avctx->codec->id) {
348     /* constant, only check buf_size */
349     case CODEC_ID_ADPCM_EA_XAS:
350         if (buf_size < 76 * ch)
351             return 0;
352         nb_samples = 128;
353         break;
354     case CODEC_ID_ADPCM_IMA_QT:
355         if (buf_size < 34 * ch)
356             return 0;
357         nb_samples = 64;
358         break;
359     /* simple 4-bit adpcm */
360     case CODEC_ID_ADPCM_CT:
361     case CODEC_ID_ADPCM_IMA_EA_SEAD:
362     case CODEC_ID_ADPCM_IMA_WS:
363     case CODEC_ID_ADPCM_YAMAHA:
364         nb_samples = buf_size * 2 / ch;
365         break;
366     }
367     if (nb_samples)
368         return nb_samples;
369
370     /* simple 4-bit adpcm, with header */
371     header_size = 0;
372     switch (avctx->codec->id) {
373         case CODEC_ID_ADPCM_4XM:
374         case CODEC_ID_ADPCM_IMA_ISS:     header_size = 4 * ch;      break;
375         case CODEC_ID_ADPCM_IMA_AMV:     header_size = 8;           break;
376         case CODEC_ID_ADPCM_IMA_SMJPEG:  header_size = 4;           break;
377     }
378     if (header_size > 0)
379         return (buf_size - header_size) * 2 / ch;
380
381     /* more complex formats */
382     switch (avctx->codec->id) {
383     case CODEC_ID_ADPCM_EA:
384         has_coded_samples = 1;
385         if (buf_size < 4)
386             return 0;
387         *coded_samples  = AV_RL32(buf);
388         *coded_samples -= *coded_samples % 28;
389         nb_samples      = (buf_size - 12) / 30 * 28;
390         break;
391     case CODEC_ID_ADPCM_IMA_EA_EACS:
392         has_coded_samples = 1;
393         if (buf_size < 4)
394             return 0;
395         *coded_samples = AV_RL32(buf);
396         nb_samples     = (buf_size - (4 + 8 * ch)) * 2 / ch;
397         break;
398     case CODEC_ID_ADPCM_EA_MAXIS_XA:
399         nb_samples = ((buf_size - ch) / (2 * ch)) * 2 * ch;
400         break;
401     case CODEC_ID_ADPCM_EA_R1:
402     case CODEC_ID_ADPCM_EA_R2:
403     case CODEC_ID_ADPCM_EA_R3:
404         /* maximum number of samples */
405         /* has internal offsets and a per-frame switch to signal raw 16-bit */
406         has_coded_samples = 1;
407         if (buf_size < 4)
408             return 0;
409         switch (avctx->codec->id) {
410         case CODEC_ID_ADPCM_EA_R1:
411             header_size    = 4 + 9 * ch;
412             *coded_samples = AV_RL32(buf);
413             break;
414         case CODEC_ID_ADPCM_EA_R2:
415             header_size    = 4 + 5 * ch;
416             *coded_samples = AV_RL32(buf);
417             break;
418         case CODEC_ID_ADPCM_EA_R3:
419             header_size    = 4 + 5 * ch;
420             *coded_samples = AV_RB32(buf);
421             break;
422         }
423         *coded_samples -= *coded_samples % 28;
424         nb_samples      = (buf_size - header_size) * 2 / ch;
425         nb_samples     -= nb_samples % 28;
426         break;
427     case CODEC_ID_ADPCM_IMA_DK3:
428         if (avctx->block_align > 0)
429             buf_size = FFMIN(buf_size, avctx->block_align);
430         nb_samples = ((buf_size - 16) * 8 / 3) / ch;
431         break;
432     case CODEC_ID_ADPCM_IMA_DK4:
433         nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
434         break;
435     case CODEC_ID_ADPCM_IMA_WAV:
436         if (avctx->block_align > 0)
437             buf_size = FFMIN(buf_size, avctx->block_align);
438         nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8;
439         break;
440     case CODEC_ID_ADPCM_MS:
441         if (avctx->block_align > 0)
442             buf_size = FFMIN(buf_size, avctx->block_align);
443         nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
444         break;
445     case CODEC_ID_ADPCM_SBPRO_2:
446     case CODEC_ID_ADPCM_SBPRO_3:
447     case CODEC_ID_ADPCM_SBPRO_4:
448     {
449         int samples_per_byte;
450         switch (avctx->codec->id) {
451         case CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
452         case CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
453         case CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
454         }
455         if (!s->status[0].step_index) {
456             nb_samples++;
457             buf_size -= ch;
458         }
459         nb_samples += buf_size * samples_per_byte / ch;
460         break;
461     }
462     case CODEC_ID_ADPCM_SWF:
463     {
464         int buf_bits       = buf_size * 8 - 2;
465         int nbits          = (buf[0] >> 6) + 2;
466         int block_hdr_size = 22 * ch;
467         int block_size     = block_hdr_size + nbits * ch * 4095;
468         int nblocks        = buf_bits / block_size;
469         int bits_left      = buf_bits - nblocks * block_size;
470         nb_samples         = nblocks * 4096;
471         if (bits_left >= block_hdr_size)
472             nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
473         break;
474     }
475     case CODEC_ID_ADPCM_THP:
476         has_coded_samples = 1;
477         if (buf_size < 8)
478             return 0;
479         *coded_samples  = AV_RB32(&buf[4]);
480         *coded_samples -= *coded_samples % 14;
481         nb_samples      = (buf_size - 80) / (8 * ch) * 14;
482         break;
483     case CODEC_ID_ADPCM_XA:
484         nb_samples = (buf_size / 128) * 224 / ch;
485         break;
486     }
487
488     /* validate coded sample count */
489     if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
490         return AVERROR_INVALIDDATA;
491
492     return nb_samples;
493 }
494
495 /* DK3 ADPCM support macro */
496 #define DK3_GET_NEXT_NIBBLE() \
497     if (decode_top_nibble_next) \
498     { \
499         nibble = last_byte >> 4; \
500         decode_top_nibble_next = 0; \
501     } \
502     else \
503     { \
504         if (end_of_packet) \
505             break; \
506         last_byte = *src++; \
507         if (src >= buf + buf_size) \
508             end_of_packet = 1; \
509         nibble = last_byte & 0x0F; \
510         decode_top_nibble_next = 1; \
511     }
512
513 static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
514                               int *got_frame_ptr, AVPacket *avpkt)
515 {
516     const uint8_t *buf = avpkt->data;
517     int buf_size = avpkt->size;
518     ADPCMDecodeContext *c = avctx->priv_data;
519     ADPCMChannelStatus *cs;
520     int n, m, channel, i;
521     short *samples;
522     const uint8_t *src;
523     int st; /* stereo */
524     int count1, count2;
525     int nb_samples, coded_samples, ret;
526
527     nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples);
528     if (nb_samples <= 0) {
529         av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
530         return AVERROR_INVALIDDATA;
531     }
532
533     /* get output buffer */
534     c->frame.nb_samples = nb_samples;
535     if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) {
536         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
537         return ret;
538     }
539     samples = (short *)c->frame.data[0];
540
541     /* use coded_samples when applicable */
542     /* it is always <= nb_samples, so the output buffer will be large enough */
543     if (coded_samples) {
544         if (coded_samples != nb_samples)
545             av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
546         c->frame.nb_samples = nb_samples = coded_samples;
547     }
548
549     src = buf;
550
551     st = avctx->channels == 2 ? 1 : 0;
552
553     switch(avctx->codec->id) {
554     case CODEC_ID_ADPCM_IMA_QT:
555         /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
556            Channel data is interleaved per-chunk. */
557         for (channel = 0; channel < avctx->channels; channel++) {
558             int16_t predictor;
559             int step_index;
560             cs = &(c->status[channel]);
561             /* (pppppp) (piiiiiii) */
562
563             /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
564             predictor = AV_RB16(src);
565             step_index = predictor & 0x7F;
566             predictor &= 0xFF80;
567
568             src += 2;
569
570             if (cs->step_index == step_index) {
571                 int diff = (int)predictor - cs->predictor;
572                 if (diff < 0)
573                     diff = - diff;
574                 if (diff > 0x7f)
575                     goto update;
576             } else {
577             update:
578                 cs->step_index = step_index;
579                 cs->predictor = predictor;
580             }
581
582             if (cs->step_index > 88){
583                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
584                 cs->step_index = 88;
585             }
586
587             samples = (short *)c->frame.data[0] + channel;
588
589             for (m = 0; m < 32; m++) {
590                 *samples = adpcm_ima_qt_expand_nibble(cs, src[0] & 0x0F, 3);
591                 samples += avctx->channels;
592                 *samples = adpcm_ima_qt_expand_nibble(cs, src[0] >> 4  , 3);
593                 samples += avctx->channels;
594                 src ++;
595             }
596         }
597         break;
598     case CODEC_ID_ADPCM_IMA_WAV:
599         if (avctx->block_align != 0 && buf_size > avctx->block_align)
600             buf_size = avctx->block_align;
601
602         for(i=0; i<avctx->channels; i++){
603             cs = &(c->status[i]);
604             cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src);
605
606             cs->step_index = *src++;
607             if (cs->step_index > 88){
608                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
609                 cs->step_index = 88;
610             }
611             if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */
612         }
613
614         for (n = (nb_samples - 1) / 8; n > 0; n--) {
615             for (i = 0; i < avctx->channels; i++) {
616                 cs = &c->status[i];
617                 for (m = 0; m < 4; m++) {
618                     uint8_t v = *src++;
619                     *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
620                     samples += avctx->channels;
621                     *samples = adpcm_ima_expand_nibble(cs, v >> 4  , 3);
622                     samples += avctx->channels;
623                 }
624                 samples -= 8 * avctx->channels - 1;
625             }
626             samples += 7 * avctx->channels;
627         }
628         break;
629     case CODEC_ID_ADPCM_4XM:
630         for (i = 0; i < avctx->channels; i++)
631             c->status[i].predictor= (int16_t)bytestream_get_le16(&src);
632
633         for (i = 0; i < avctx->channels; i++) {
634             c->status[i].step_index= (int16_t)bytestream_get_le16(&src);
635             c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
636         }
637
638         for (i = 0; i < avctx->channels; i++) {
639             samples = (short *)c->frame.data[0] + i;
640             cs = &c->status[i];
641             for (n = nb_samples >> 1; n > 0; n--, src++) {
642                 uint8_t v = *src;
643                 *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
644                 samples += avctx->channels;
645                 *samples = adpcm_ima_expand_nibble(cs, v >> 4  , 4);
646                 samples += avctx->channels;
647             }
648         }
649         break;
650     case CODEC_ID_ADPCM_MS:
651     {
652         int block_predictor;
653
654         if (avctx->block_align != 0 && buf_size > avctx->block_align)
655             buf_size = avctx->block_align;
656
657         block_predictor = av_clip(*src++, 0, 6);
658         c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
659         c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
660         if (st) {
661             block_predictor = av_clip(*src++, 0, 6);
662             c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
663             c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
664         }
665         c->status[0].idelta = (int16_t)bytestream_get_le16(&src);
666         if (st){
667             c->status[1].idelta = (int16_t)bytestream_get_le16(&src);
668         }
669
670         c->status[0].sample1 = bytestream_get_le16(&src);
671         if (st) c->status[1].sample1 = bytestream_get_le16(&src);
672         c->status[0].sample2 = bytestream_get_le16(&src);
673         if (st) c->status[1].sample2 = bytestream_get_le16(&src);
674
675         *samples++ = c->status[0].sample2;
676         if (st) *samples++ = c->status[1].sample2;
677         *samples++ = c->status[0].sample1;
678         if (st) *samples++ = c->status[1].sample1;
679         for(n = (nb_samples - 2) >> (1 - st); n > 0; n--, src++) {
680             *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4  );
681             *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
682         }
683         break;
684     }
685     case CODEC_ID_ADPCM_IMA_DK4:
686         if (avctx->block_align != 0 && buf_size > avctx->block_align)
687             buf_size = avctx->block_align;
688
689         for (channel = 0; channel < avctx->channels; channel++) {
690             cs = &c->status[channel];
691             cs->predictor  = (int16_t)bytestream_get_le16(&src);
692             cs->step_index = *src++;
693             src++;
694             *samples++ = cs->predictor;
695         }
696         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
697             uint8_t v = *src;
698             *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4  , 3);
699             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
700         }
701         break;
702     case CODEC_ID_ADPCM_IMA_DK3:
703     {
704         unsigned char last_byte = 0;
705         unsigned char nibble;
706         int decode_top_nibble_next = 0;
707         int end_of_packet = 0;
708         int diff_channel;
709
710         if (avctx->block_align != 0 && buf_size > avctx->block_align)
711             buf_size = avctx->block_align;
712
713         c->status[0].predictor  = (int16_t)AV_RL16(src + 10);
714         c->status[1].predictor  = (int16_t)AV_RL16(src + 12);
715         c->status[0].step_index = src[14];
716         c->status[1].step_index = src[15];
717         /* sign extend the predictors */
718         src += 16;
719         diff_channel = c->status[1].predictor;
720
721         /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
722          * the buffer is consumed */
723         while (1) {
724
725             /* for this algorithm, c->status[0] is the sum channel and
726              * c->status[1] is the diff channel */
727
728             /* process the first predictor of the sum channel */
729             DK3_GET_NEXT_NIBBLE();
730             adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
731
732             /* process the diff channel predictor */
733             DK3_GET_NEXT_NIBBLE();
734             adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
735
736             /* process the first pair of stereo PCM samples */
737             diff_channel = (diff_channel + c->status[1].predictor) / 2;
738             *samples++ = c->status[0].predictor + c->status[1].predictor;
739             *samples++ = c->status[0].predictor - c->status[1].predictor;
740
741             /* process the second predictor of the sum channel */
742             DK3_GET_NEXT_NIBBLE();
743             adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
744
745             /* process the second pair of stereo PCM samples */
746             diff_channel = (diff_channel + c->status[1].predictor) / 2;
747             *samples++ = c->status[0].predictor + c->status[1].predictor;
748             *samples++ = c->status[0].predictor - c->status[1].predictor;
749         }
750         break;
751     }
752     case CODEC_ID_ADPCM_IMA_ISS:
753         for (channel = 0; channel < avctx->channels; channel++) {
754             cs = &c->status[channel];
755             cs->predictor  = (int16_t)bytestream_get_le16(&src);
756             cs->step_index = *src++;
757             src++;
758         }
759
760         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
761             uint8_t v1, v2;
762             uint8_t v = *src;
763             /* nibbles are swapped for mono */
764             if (st) {
765                 v1 = v >> 4;
766                 v2 = v & 0x0F;
767             } else {
768                 v2 = v >> 4;
769                 v1 = v & 0x0F;
770             }
771             *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
772             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
773         }
774         break;
775     case CODEC_ID_ADPCM_IMA_WS:
776         while (src < buf + buf_size) {
777             uint8_t v = *src++;
778             *samples++ = adpcm_ima_expand_nibble(&c->status[0],  v >> 4  , 3);
779             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
780         }
781         break;
782     case CODEC_ID_ADPCM_XA:
783         while (buf_size >= 128) {
784             xa_decode(samples, src, &c->status[0], &c->status[1],
785                 avctx->channels);
786             src += 128;
787             samples += 28 * 8;
788             buf_size -= 128;
789         }
790         break;
791     case CODEC_ID_ADPCM_IMA_EA_EACS:
792         src += 4; // skip sample count (already read)
793
794         for (i=0; i<=st; i++)
795             c->status[i].step_index = bytestream_get_le32(&src);
796         for (i=0; i<=st; i++)
797             c->status[i].predictor  = bytestream_get_le32(&src);
798
799         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
800             *samples++ = adpcm_ima_expand_nibble(&c->status[0],  *src>>4,   3);
801             *samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);
802         }
803         break;
804     case CODEC_ID_ADPCM_IMA_EA_SEAD:
805         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
806             *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6);
807             *samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6);
808         }
809         break;
810     case CODEC_ID_ADPCM_EA:
811     {
812         int32_t previous_left_sample, previous_right_sample;
813         int32_t current_left_sample, current_right_sample;
814         int32_t next_left_sample, next_right_sample;
815         int32_t coeff1l, coeff2l, coeff1r, coeff2r;
816         uint8_t shift_left, shift_right;
817
818         /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
819            each coding 28 stereo samples. */
820
821         src += 4; // skip sample count (already read)
822
823         current_left_sample   = (int16_t)bytestream_get_le16(&src);
824         previous_left_sample  = (int16_t)bytestream_get_le16(&src);
825         current_right_sample  = (int16_t)bytestream_get_le16(&src);
826         previous_right_sample = (int16_t)bytestream_get_le16(&src);
827
828         for (count1 = 0; count1 < nb_samples / 28; count1++) {
829             coeff1l = ea_adpcm_table[ *src >> 4       ];
830             coeff2l = ea_adpcm_table[(*src >> 4  ) + 4];
831             coeff1r = ea_adpcm_table[*src & 0x0F];
832             coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
833             src++;
834
835             shift_left  = 20 - (*src >> 4);
836             shift_right = 20 - (*src & 0x0F);
837             src++;
838
839             for (count2 = 0; count2 < 28; count2++) {
840                 next_left_sample  = sign_extend(*src >> 4, 4) << shift_left;
841                 next_right_sample = sign_extend(*src,      4) << shift_right;
842                 src++;
843
844                 next_left_sample = (next_left_sample +
845                     (current_left_sample * coeff1l) +
846                     (previous_left_sample * coeff2l) + 0x80) >> 8;
847                 next_right_sample = (next_right_sample +
848                     (current_right_sample * coeff1r) +
849                     (previous_right_sample * coeff2r) + 0x80) >> 8;
850
851                 previous_left_sample = current_left_sample;
852                 current_left_sample = av_clip_int16(next_left_sample);
853                 previous_right_sample = current_right_sample;
854                 current_right_sample = av_clip_int16(next_right_sample);
855                 *samples++ = (unsigned short)current_left_sample;
856                 *samples++ = (unsigned short)current_right_sample;
857             }
858         }
859
860         if (src - buf == buf_size - 2)
861             src += 2; // Skip terminating 0x0000
862
863         break;
864     }
865     case CODEC_ID_ADPCM_EA_MAXIS_XA:
866     {
867         int coeff[2][2], shift[2];
868
869         for(channel = 0; channel < avctx->channels; channel++) {
870             for (i=0; i<2; i++)
871                 coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i];
872             shift[channel] = 20 - (*src & 0x0F);
873             src++;
874         }
875         for (count1 = 0; count1 < nb_samples / 2; count1++) {
876             for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
877                 for(channel = 0; channel < avctx->channels; channel++) {
878                     int32_t sample = sign_extend(src[channel] >> i, 4) << shift[channel];
879                     sample = (sample +
880                              c->status[channel].sample1 * coeff[channel][0] +
881                              c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
882                     c->status[channel].sample2 = c->status[channel].sample1;
883                     c->status[channel].sample1 = av_clip_int16(sample);
884                     *samples++ = c->status[channel].sample1;
885                 }
886             }
887             src+=avctx->channels;
888         }
889         /* consume whole packet */
890         src = buf + buf_size;
891         break;
892     }
893     case CODEC_ID_ADPCM_EA_R1:
894     case CODEC_ID_ADPCM_EA_R2:
895     case CODEC_ID_ADPCM_EA_R3: {
896         /* channel numbering
897            2chan: 0=fl, 1=fr
898            4chan: 0=fl, 1=rl, 2=fr, 3=rr
899            6chan: 0=fl, 1=c,  2=fr, 3=rl,  4=rr, 5=sub */
900         const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3;
901         int32_t previous_sample, current_sample, next_sample;
902         int32_t coeff1, coeff2;
903         uint8_t shift;
904         unsigned int channel;
905         uint16_t *samplesC;
906         const uint8_t *srcC;
907         const uint8_t *src_end = buf + buf_size;
908         int count = 0;
909
910         src += 4; // skip sample count (already read)
911
912         for (channel=0; channel<avctx->channels; channel++) {
913             int32_t offset = (big_endian ? bytestream_get_be32(&src)
914                                          : bytestream_get_le32(&src))
915                            + (avctx->channels-channel-1) * 4;
916
917             if ((offset < 0) || (offset >= src_end - src - 4)) break;
918             srcC  = src + offset;
919             samplesC = samples + channel;
920
921             if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) {
922                 current_sample  = (int16_t)bytestream_get_le16(&srcC);
923                 previous_sample = (int16_t)bytestream_get_le16(&srcC);
924             } else {
925                 current_sample  = c->status[channel].predictor;
926                 previous_sample = c->status[channel].prev_sample;
927             }
928
929             for (count1 = 0; count1 < nb_samples / 28; count1++) {
930                 if (*srcC == 0xEE) {  /* only seen in R2 and R3 */
931                     srcC++;
932                     if (srcC > src_end - 30*2) break;
933                     current_sample  = (int16_t)bytestream_get_be16(&srcC);
934                     previous_sample = (int16_t)bytestream_get_be16(&srcC);
935
936                     for (count2=0; count2<28; count2++) {
937                         *samplesC = (int16_t)bytestream_get_be16(&srcC);
938                         samplesC += avctx->channels;
939                     }
940                 } else {
941                     coeff1 = ea_adpcm_table[ *srcC>>4     ];
942                     coeff2 = ea_adpcm_table[(*srcC>>4) + 4];
943                     shift = 20 - (*srcC++ & 0x0F);
944
945                     if (srcC > src_end - 14) break;
946                     for (count2=0; count2<28; count2++) {
947                         if (count2 & 1)
948                             next_sample = sign_extend(*srcC++,    4) << shift;
949                         else
950                             next_sample = sign_extend(*srcC >> 4, 4) << shift;
951
952                         next_sample += (current_sample  * coeff1) +
953                                        (previous_sample * coeff2);
954                         next_sample = av_clip_int16(next_sample >> 8);
955
956                         previous_sample = current_sample;
957                         current_sample  = next_sample;
958                         *samplesC = current_sample;
959                         samplesC += avctx->channels;
960                     }
961                 }
962             }
963             if (!count) {
964                 count = count1;
965             } else if (count != count1) {
966                 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
967                 count = FFMAX(count, count1);
968             }
969
970             if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) {
971                 c->status[channel].predictor   = current_sample;
972                 c->status[channel].prev_sample = previous_sample;
973             }
974         }
975
976         c->frame.nb_samples = count * 28;
977         src = src_end;
978         break;
979     }
980     case CODEC_ID_ADPCM_EA_XAS:
981         for (channel=0; channel<avctx->channels; channel++) {
982             int coeff[2][4], shift[4];
983             short *s2, *s = &samples[channel];
984             for (n=0; n<4; n++, s+=32*avctx->channels) {
985                 for (i=0; i<2; i++)
986                     coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i];
987                 shift[n] = 20 - (src[2] & 0x0F);
988                 for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels)
989                     s2[0] = (src[0]&0xF0) + (src[1]<<8);
990             }
991
992             for (m=2; m<32; m+=2) {
993                 s = &samples[m*avctx->channels + channel];
994                 for (n=0; n<4; n++, src++, s+=32*avctx->channels) {
995                     for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) {
996                         int level = sign_extend(*src >> (4 - i), 4) << shift[n];
997                         int pred  = s2[-1*avctx->channels] * coeff[0][n]
998                                   + s2[-2*avctx->channels] * coeff[1][n];
999                         s2[0] = av_clip_int16((level + pred + 0x80) >> 8);
1000                     }
1001                 }
1002             }
1003         }
1004         break;
1005     case CODEC_ID_ADPCM_IMA_AMV:
1006     case CODEC_ID_ADPCM_IMA_SMJPEG:
1007         c->status[0].predictor = (int16_t)bytestream_get_le16(&src);
1008         c->status[0].step_index = bytestream_get_le16(&src);
1009
1010         if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
1011             src+=4;
1012
1013         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1014             char hi, lo;
1015             lo = *src & 0x0F;
1016             hi = *src >> 4;
1017
1018             if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
1019                 FFSWAP(char, hi, lo);
1020
1021             *samples++ = adpcm_ima_expand_nibble(&c->status[0],
1022                 lo, 3);
1023             *samples++ = adpcm_ima_expand_nibble(&c->status[0],
1024                 hi, 3);
1025         }
1026         break;
1027     case CODEC_ID_ADPCM_CT:
1028         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1029             uint8_t v = *src;
1030             *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4  );
1031             *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
1032         }
1033         break;
1034     case CODEC_ID_ADPCM_SBPRO_4:
1035     case CODEC_ID_ADPCM_SBPRO_3:
1036     case CODEC_ID_ADPCM_SBPRO_2:
1037         if (!c->status[0].step_index) {
1038             /* the first byte is a raw sample */
1039             *samples++ = 128 * (*src++ - 0x80);
1040             if (st)
1041               *samples++ = 128 * (*src++ - 0x80);
1042             c->status[0].step_index = 1;
1043             nb_samples--;
1044         }
1045         if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
1046             for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1047                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1048                     src[0] >> 4, 4, 0);
1049                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1050                     src[0] & 0x0F, 4, 0);
1051             }
1052         } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
1053             for (n = nb_samples / 3; n > 0; n--, src++) {
1054                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1055                      src[0] >> 5        , 3, 0);
1056                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1057                     (src[0] >> 2) & 0x07, 3, 0);
1058                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1059                     src[0] & 0x03, 2, 0);
1060             }
1061         } else {
1062             for (n = nb_samples >> (2 - st); n > 0; n--, src++) {
1063                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1064                      src[0] >> 6        , 2, 2);
1065                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1066                     (src[0] >> 4) & 0x03, 2, 2);
1067                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1068                     (src[0] >> 2) & 0x03, 2, 2);
1069                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1070                     src[0] & 0x03, 2, 2);
1071             }
1072         }
1073         break;
1074     case CODEC_ID_ADPCM_SWF:
1075     {
1076         GetBitContext gb;
1077         const int *table;
1078         int k0, signmask, nb_bits, count;
1079         int size = buf_size*8;
1080
1081         init_get_bits(&gb, buf, size);
1082
1083         //read bits & initial values
1084         nb_bits = get_bits(&gb, 2)+2;
1085         //av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", nb_bits);
1086         table = swf_index_tables[nb_bits-2];
1087         k0 = 1 << (nb_bits-2);
1088         signmask = 1 << (nb_bits-1);
1089
1090         while (get_bits_count(&gb) <= size - 22*avctx->channels) {
1091             for (i = 0; i < avctx->channels; i++) {
1092                 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
1093                 c->status[i].step_index = get_bits(&gb, 6);
1094             }
1095
1096             for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
1097                 int i;
1098
1099                 for (i = 0; i < avctx->channels; i++) {
1100                     // similar to IMA adpcm
1101                     int delta = get_bits(&gb, nb_bits);
1102                     int step = ff_adpcm_step_table[c->status[i].step_index];
1103                     long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
1104                     int k = k0;
1105
1106                     do {
1107                         if (delta & k)
1108                             vpdiff += step;
1109                         step >>= 1;
1110                         k >>= 1;
1111                     } while(k);
1112                     vpdiff += step;
1113
1114                     if (delta & signmask)
1115                         c->status[i].predictor -= vpdiff;
1116                     else
1117                         c->status[i].predictor += vpdiff;
1118
1119                     c->status[i].step_index += table[delta & (~signmask)];
1120
1121                     c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
1122                     c->status[i].predictor = av_clip_int16(c->status[i].predictor);
1123
1124                     *samples++ = c->status[i].predictor;
1125                 }
1126             }
1127         }
1128         src += buf_size;
1129         break;
1130     }
1131     case CODEC_ID_ADPCM_YAMAHA:
1132         for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
1133             uint8_t v = *src;
1134             *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
1135             *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4  );
1136         }
1137         break;
1138     case CODEC_ID_ADPCM_THP:
1139     {
1140         int table[2][16];
1141         int prev[2][2];
1142         int ch;
1143
1144         src += 4; // skip channel size
1145         src += 4; // skip number of samples (already read)
1146
1147         for (i = 0; i < 32; i++)
1148             table[0][i] = (int16_t)bytestream_get_be16(&src);
1149
1150         /* Initialize the previous sample.  */
1151         for (i = 0; i < 4; i++)
1152             prev[0][i] = (int16_t)bytestream_get_be16(&src);
1153
1154         for (ch = 0; ch <= st; ch++) {
1155             samples = (short *)c->frame.data[0] + ch;
1156
1157             /* Read in every sample for this channel.  */
1158             for (i = 0; i < nb_samples / 14; i++) {
1159                 int index = (*src >> 4) & 7;
1160                 unsigned int exp = *src++ & 15;
1161                 int factor1 = table[ch][index * 2];
1162                 int factor2 = table[ch][index * 2 + 1];
1163
1164                 /* Decode 14 samples.  */
1165                 for (n = 0; n < 14; n++) {
1166                     int32_t sampledat;
1167                     if(n&1) sampledat = sign_extend(*src++, 4);
1168                     else    sampledat = sign_extend(*src >> 4, 4);
1169
1170                     sampledat = ((prev[ch][0]*factor1
1171                                 + prev[ch][1]*factor2) >> 11) + (sampledat << exp);
1172                     *samples = av_clip_int16(sampledat);
1173                     prev[ch][1] = prev[ch][0];
1174                     prev[ch][0] = *samples++;
1175
1176                     /* In case of stereo, skip one sample, this sample
1177                        is for the other channel.  */
1178                     samples += st;
1179                 }
1180             }
1181         }
1182         break;
1183     }
1184
1185     default:
1186         return -1;
1187     }
1188
1189     *got_frame_ptr   = 1;
1190     *(AVFrame *)data = c->frame;
1191
1192     return src - buf;
1193 }
1194
1195
1196 #define ADPCM_DECODER(id_, name_, long_name_)               \
1197 AVCodec ff_ ## name_ ## _decoder = {                        \
1198     .name           = #name_,                               \
1199     .type           = AVMEDIA_TYPE_AUDIO,                   \
1200     .id             = id_,                                  \
1201     .priv_data_size = sizeof(ADPCMDecodeContext),           \
1202     .init           = adpcm_decode_init,                    \
1203     .decode         = adpcm_decode_frame,                   \
1204     .capabilities   = CODEC_CAP_DR1,                        \
1205     .long_name      = NULL_IF_CONFIG_SMALL(long_name_),     \
1206 }
1207
1208 /* Note: Do not forget to add new entries to the Makefile as well. */
1209 ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie");
1210 ADPCM_DECODER(CODEC_ID_ADPCM_CT, adpcm_ct, "ADPCM Creative Technology");
1211 ADPCM_DECODER(CODEC_ID_ADPCM_EA, adpcm_ea, "ADPCM Electronic Arts");
1212 ADPCM_DECODER(CODEC_ID_ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
1213 ADPCM_DECODER(CODEC_ID_ADPCM_EA_R1, adpcm_ea_r1, "ADPCM Electronic Arts R1");
1214 ADPCM_DECODER(CODEC_ID_ADPCM_EA_R2, adpcm_ea_r2, "ADPCM Electronic Arts R2");
1215 ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3, "ADPCM Electronic Arts R3");
1216 ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
1217 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, "ADPCM IMA AMV");
1218 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
1219 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
1220 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
1221 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
1222 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
1223 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime");
1224 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
1225 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV");
1226 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "ADPCM IMA Westwood");
1227 ADPCM_DECODER(CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft");
1228 ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
1229 ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
1230 ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
1231 ADPCM_DECODER(CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash");
1232 ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "ADPCM Nintendo Gamecube THP");
1233 ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "ADPCM CDROM XA");
1234 ADPCM_DECODER(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha");