Make B-frame reduction sensitivity by b_strategy/vb_strategy = 1
[libav.git] / libavcodec / adpcm.c
CommitLineData
0147f198
FR
1/*
2 * ADPCM codecs
9937e686 3 * Copyright (c) 2001-2003 The ffmpeg Project
0147f198
FR
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
5509bffa 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0147f198
FR
18 */
19#include "avcodec.h"
659c3692 20#include "bitstream.h"
0147f198 21
983e3246
MN
22/**
23 * @file adpcm.c
24 * ADPCM codecs.
fc384777 25 * First version by Francois Revol (revol@free.fr)
2fdf638b 26 * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
9937e686 27 * by Mike Melanson (melanson@pcisys.net)
fc384777 28 * CD-ROM XA ADPCM codec by BERO
7d8379f2 29 * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
0147f198
FR
30 *
31 * Features and limitations:
32 *
33 * Reference documents:
9937e686 34 * http://www.pcisys.net/~melanson/codecs/simpleaudio.html
0147f198
FR
35 * http://www.geocities.com/SiliconValley/8682/aud3.txt
36 * http://openquicktime.sourceforge.net/plugins.htm
37 * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html
889c5224
FR
38 * http://www.cs.ucla.edu/~leec/mediabench/applications.html
39 * SoX source code http://home.sprynet.com/~cbagwell/sox.html
fc384777
MM
40 *
41 * CD-ROM XA:
42 * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html
43 * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html
44 * readstr http://www.geocities.co.jp/Playtown/2004/
0147f198
FR
45 */
46
47#define BLKSIZE 1024
48
49#define CLAMP_TO_SHORT(value) \
50if (value > 32767) \
51 value = 32767; \
52else if (value < -32768) \
53 value = -32768; \
54
55/* step_table[] and index_table[] are from the ADPCM reference source */
56/* This is the index table: */
135ee03a 57static const int index_table[16] = {
0147f198
FR
58 -1, -1, -1, -1, 2, 4, 6, 8,
59 -1, -1, -1, -1, 2, 4, 6, 8,
60};
61
115329f1 62/**
983e3246 63 * This is the step table. Note that many programs use slight deviations from
0147f198
FR
64 * this table, but such deviations are negligible:
65 */
135ee03a 66static const int step_table[89] = {
0147f198
FR
67 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
68 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
69 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
70 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
71 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
72 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
73 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
74 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
75 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
76};
77
fc384777 78/* These are for MS-ADPCM */
0147f198 79/* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */
135ee03a 80static const int AdaptationTable[] = {
0147f198
FR
81 230, 230, 230, 230, 307, 409, 512, 614,
82 768, 614, 512, 409, 307, 230, 230, 230
83};
84
135ee03a 85static const int AdaptCoeff1[] = {
0147f198
FR
86 256, 512, 0, 192, 240, 460, 392
87};
88
135ee03a 89static const int AdaptCoeff2[] = {
0147f198
FR
90 0, -256, 0, 64, 0, -208, -232
91};
92
fc384777 93/* These are for CD-ROM XA ADPCM */
1ffb0091 94static const int xa_adpcm_table[5][2] = {
fc384777
MM
95 { 0, 0 },
96 { 60, 0 },
97 { 115, -52 },
98 { 98, -55 },
99 { 122, -60 }
100};
101
c26ae41d 102static const int ea_adpcm_table[] = {
7d8379f2
MM
103 0, 240, 460, 392, 0, 0, -208, -220, 0, 1,
104 3, 4, 7, 8, 10, 11, 0, -1, -3, -4
105};
106
c26ae41d 107static const int ct_adpcm_table[8] = {
b3bfb299
MM
108 0x00E6, 0x00E6, 0x00E6, 0x00E6,
109 0x0133, 0x0199, 0x0200, 0x0266
110};
111
659c3692 112// padded to zero where table size is less then 16
c26ae41d 113static const int swf_index_tables[4][16] = {
659c3692
AB
114 /*2*/ { -1, 2 },
115 /*3*/ { -1, -1, 2, 4 },
116 /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
117 /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
118};
119
2ff4524e
VM
120static const int yamaha_indexscale[] = {
121 230, 230, 230, 230, 307, 409, 512, 614,
122 230, 230, 230, 230, 307, 409, 512, 614
123};
124
125static const int yamaha_difflookup[] = {
126 1, 3, 5, 7, 9, 11, 13, 15,
127 -1, -3, -5, -7, -9, -11, -13, -15
128};
129
0147f198
FR
130/* end of tables */
131
132typedef struct ADPCMChannelStatus {
133 int predictor;
134 short int step_index;
135 int step;
889c5224
FR
136 /* for encoding */
137 int prev_sample;
0147f198
FR
138
139 /* MS version */
140 short sample1;
141 short sample2;
142 int coeff1;
143 int coeff2;
144 int idelta;
145} ADPCMChannelStatus;
146
147typedef struct ADPCMContext {
148 int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */
149 ADPCMChannelStatus status[2];
150 short sample_buffer[32]; /* hold left samples while waiting for right samples */
659c3692
AB
151
152 /* SWF only */
153 int nb_bits;
154 int nb_samples;
0147f198
FR
155} ADPCMContext;
156
157/* XXX: implement encoding */
158
764ef400 159#ifdef CONFIG_ENCODERS
0147f198
FR
160static int adpcm_encode_init(AVCodecContext *avctx)
161{
889c5224
FR
162 if (avctx->channels > 2)
163 return -1; /* only stereo or mono =) */
0147f198
FR
164 switch(avctx->codec->id) {
165 case CODEC_ID_ADPCM_IMA_QT:
8dbcc9f2 166 av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ima_qt unsupported for encoding !\n");
889c5224
FR
167 avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */
168 return -1;
0147f198
FR
169 break;
170 case CODEC_ID_ADPCM_IMA_WAV:
889c5224
FR
171 avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */
172 /* and we have 4 bytes per channel overhead */
173 avctx->block_align = BLKSIZE;
174 /* seems frame_size isn't taken into account... have to buffer the samples :-( */
175 break;
176 case CODEC_ID_ADPCM_MS:
6cf9d5eb
MN
177 avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
178 /* and we have 7 bytes per channel overhead */
179 avctx->block_align = BLKSIZE;
0147f198 180 break;
2ff4524e
VM
181 case CODEC_ID_ADPCM_YAMAHA:
182 avctx->frame_size = BLKSIZE * avctx->channels;
183 avctx->block_align = BLKSIZE;
184 break;
0147f198 185 default:
889c5224 186 return -1;
0147f198
FR
187 break;
188 }
492cd3a9
MN
189
190 avctx->coded_frame= avcodec_alloc_frame();
191 avctx->coded_frame->key_frame= 1;
192
0147f198
FR
193 return 0;
194}
195
196static int adpcm_encode_close(AVCodecContext *avctx)
197{
492cd3a9
MN
198 av_freep(&avctx->coded_frame);
199
0147f198
FR
200 return 0;
201}
202
889c5224
FR
203
204static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample)
205{
7e537051
LM
206 int delta = sample - c->prev_sample;
207 int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8;
208 c->prev_sample = c->prev_sample + ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8);
889c5224 209 CLAMP_TO_SHORT(c->prev_sample);
7e537051 210 c->step_index = clip(c->step_index + index_table[nibble], 0, 88);
889c5224
FR
211 return nibble;
212}
213
6cf9d5eb
MN
214static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
215{
216 int predictor, nibble, bias;
217
218 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
115329f1 219
6cf9d5eb
MN
220 nibble= sample - predictor;
221 if(nibble>=0) bias= c->idelta/2;
222 else bias=-c->idelta/2;
115329f1 223
6cf9d5eb
MN
224 nibble= (nibble + bias) / c->idelta;
225 nibble= clip(nibble, -8, 7)&0x0F;
115329f1 226
6cf9d5eb
MN
227 predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
228 CLAMP_TO_SHORT(predictor);
229
230 c->sample2 = c->sample1;
231 c->sample1 = predictor;
232
233 c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
234 if (c->idelta < 16) c->idelta = 16;
235
236 return nibble;
237}
238
2ff4524e
VM
239static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample)
240{
7e537051 241 int nibble, delta;
2ff4524e
VM
242
243 if(!c->step) {
244 c->predictor = 0;
245 c->step = 127;
246 }
2ff4524e 247
7e537051 248 delta = sample - c->predictor;
2ff4524e 249
7e537051
LM
250 nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8;
251
252 c->predictor = c->predictor + ((c->step * yamaha_difflookup[nibble]) / 8);
2ff4524e 253 CLAMP_TO_SHORT(c->predictor);
7e537051 254 c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
2ff4524e
VM
255 c->step = clip(c->step, 127, 24567);
256
7e537051 257 return nibble;
2ff4524e
VM
258}
259
0147f198 260static int adpcm_encode_frame(AVCodecContext *avctx,
bb270c08 261 unsigned char *frame, int buf_size, void *data)
0147f198 262{
6cf9d5eb 263 int n, i, st;
0147f198
FR
264 short *samples;
265 unsigned char *dst;
889c5224
FR
266 ADPCMContext *c = avctx->priv_data;
267
268 dst = frame;
269 samples = (short *)data;
6cf9d5eb 270 st= avctx->channels == 2;
889c5224 271/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
0147f198
FR
272
273 switch(avctx->codec->id) {
889c5224
FR
274 case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */
275 break;
276 case CODEC_ID_ADPCM_IMA_WAV:
277 n = avctx->frame_size / 8;
278 c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
279/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
280 *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */
281 *dst++ = (c->status[0].prev_sample >> 8) & 0xFF;
282 *dst++ = (unsigned char)c->status[0].step_index;
283 *dst++ = 0; /* unknown */
284 samples++;
285 if (avctx->channels == 2) {
1ffb0091 286 c->status[1].prev_sample = (signed short)samples[1];
889c5224
FR
287/* c->status[1].step_index = 0; */
288 *dst++ = (c->status[1].prev_sample) & 0xFF;
289 *dst++ = (c->status[1].prev_sample >> 8) & 0xFF;
290 *dst++ = (unsigned char)c->status[1].step_index;
291 *dst++ = 0;
292 samples++;
293 }
115329f1 294
889c5224
FR
295 /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
296 for (; n>0; n--) {
297 *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F;
298 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0;
299 dst++;
300 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F;
301 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0;
302 dst++;
303 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F;
304 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0;
305 dst++;
306 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F;
307 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0;
308 dst++;
309 /* right channel */
310 if (avctx->channels == 2) {
311 *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
312 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
313 dst++;
314 *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
315 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
316 dst++;
317 *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
318 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
319 dst++;
320 *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
321 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
322 dst++;
323 }
324 samples += 8 * avctx->channels;
325 }
326 break;
6cf9d5eb
MN
327 case CODEC_ID_ADPCM_MS:
328 for(i=0; i<avctx->channels; i++){
329 int predictor=0;
330
331 *dst++ = predictor;
332 c->status[i].coeff1 = AdaptCoeff1[predictor];
333 c->status[i].coeff2 = AdaptCoeff2[predictor];
334 }
335 for(i=0; i<avctx->channels; i++){
115329f1 336 if (c->status[i].idelta < 16)
6cf9d5eb 337 c->status[i].idelta = 16;
115329f1 338
6cf9d5eb
MN
339 *dst++ = c->status[i].idelta & 0xFF;
340 *dst++ = c->status[i].idelta >> 8;
341 }
342 for(i=0; i<avctx->channels; i++){
343 c->status[i].sample1= *samples++;
344
345 *dst++ = c->status[i].sample1 & 0xFF;
346 *dst++ = c->status[i].sample1 >> 8;
347 }
348 for(i=0; i<avctx->channels; i++){
349 c->status[i].sample2= *samples++;
350
351 *dst++ = c->status[i].sample2 & 0xFF;
352 *dst++ = c->status[i].sample2 >> 8;
353 }
354
355 for(i=7*avctx->channels; i<avctx->block_align; i++) {
356 int nibble;
357 nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4;
358 nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++);
359 *dst++ = nibble;
360 }
361 break;
2ff4524e
VM
362 case CODEC_ID_ADPCM_YAMAHA:
363 n = avctx->frame_size / 2;
364 for (; n>0; n--) {
365 for(i = 0; i < avctx->channels; i++) {
366 int nibble;
b194c327
MN
367 nibble = adpcm_yamaha_compress_sample(&c->status[i], samples[i]);
368 nibble |= adpcm_yamaha_compress_sample(&c->status[i], samples[i+avctx->channels]) << 4;
2ff4524e
VM
369 *dst++ = nibble;
370 }
371 samples += 2 * avctx->channels;
372 }
373 break;
0147f198
FR
374 default:
375 return -1;
376 }
0147f198
FR
377 return dst - frame;
378}
764ef400 379#endif //CONFIG_ENCODERS
0147f198
FR
380
381static int adpcm_decode_init(AVCodecContext * avctx)
382{
383 ADPCMContext *c = avctx->priv_data;
384
385 c->channel = 0;
386 c->status[0].predictor = c->status[1].predictor = 0;
387 c->status[0].step_index = c->status[1].step_index = 0;
388 c->status[0].step = c->status[1].step = 0;
389
390 switch(avctx->codec->id) {
b3bfb299 391 case CODEC_ID_ADPCM_CT:
bb270c08
DB
392 c->status[0].step = c->status[1].step = 511;
393 break;
0147f198
FR
394 default:
395 break;
396 }
397 return 0;
398}
399
d94728c3 400static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
0147f198
FR
401{
402 int step_index;
403 int predictor;
404 int sign, delta, diff, step;
405
135ee03a 406 step = step_table[c->step_index];
0147f198
FR
407 step_index = c->step_index + index_table[(unsigned)nibble];
408 if (step_index < 0) step_index = 0;
135ee03a 409 else if (step_index > 88) step_index = 88;
0147f198 410
0147f198
FR
411 sign = nibble & 8;
412 delta = nibble & 7;
9937e686
MM
413 /* perform direct multiplication instead of series of jumps proposed by
414 * the reference ADPCM implementation since modern CPUs can do the mults
415 * quickly enough */
d94728c3 416 diff = ((2 * delta + 1) * step) >> shift;
4b465299
MN
417 predictor = c->predictor;
418 if (sign) predictor -= diff;
419 else predictor += diff;
420
421 CLAMP_TO_SHORT(predictor);
422 c->predictor = predictor;
423 c->step_index = step_index;
424
425 return (short)predictor;
426}
427
0147f198
FR
428static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
429{
430 int predictor;
431
432 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
433 predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
434 CLAMP_TO_SHORT(predictor);
435
436 c->sample2 = c->sample1;
437 c->sample1 = predictor;
6cf9d5eb 438 c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
0147f198
FR
439 if (c->idelta < 16) c->idelta = 16;
440
441 return (short)predictor;
442}
443
b3bfb299
MM
444static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
445{
446 int predictor;
447 int sign, delta, diff;
448 int new_step;
449
450 sign = nibble & 8;
451 delta = nibble & 7;
452 /* perform direct multiplication instead of series of jumps proposed by
453 * the reference ADPCM implementation since modern CPUs can do the mults
454 * quickly enough */
455 diff = ((2 * delta + 1) * c->step) >> 3;
456 predictor = c->predictor;
457 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
458 if(sign)
bb270c08 459 predictor = ((predictor * 254) >> 8) - diff;
b3bfb299 460 else
bb270c08 461 predictor = ((predictor * 254) >> 8) + diff;
b3bfb299
MM
462 /* calculate new step and clamp it to range 511..32767 */
463 new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8;
464 c->step = new_step;
465 if(c->step < 511)
bb270c08 466 c->step = 511;
b3bfb299 467 if(c->step > 32767)
bb270c08 468 c->step = 32767;
b3bfb299
MM
469
470 CLAMP_TO_SHORT(predictor);
471 c->predictor = predictor;
472 return (short)predictor;
473}
474
2433f24f
AJ
475static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
476{
477 int sign, delta, diff;
478
479 sign = nibble & (1<<(size-1));
480 delta = nibble & ((1<<(size-1))-1);
481 diff = delta << (7 + c->step + shift);
482
483 if (sign)
484 c->predictor -= diff;
485 else
486 c->predictor += diff;
487
488 /* clamp result */
489 if (c->predictor > 16256)
490 c->predictor = 16256;
491 else if (c->predictor < -16384)
492 c->predictor = -16384;
493
494 /* calculate new step */
495 if (delta >= (2*size - 3) && c->step < 3)
496 c->step++;
497 else if (delta == 0 && c->step > 0)
498 c->step--;
499
500 return (short) c->predictor;
501}
502
2ff4524e
VM
503static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
504{
505 if(!c->step) {
506 c->predictor = 0;
507 c->step = 127;
508 }
509
510 c->predictor += (c->step * yamaha_difflookup[nibble]) / 8;
511 CLAMP_TO_SHORT(c->predictor);
512 c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
513 c->step = clip(c->step, 127, 24567);
514 return c->predictor;
515}
516
115329f1 517static void xa_decode(short *out, const unsigned char *in,
fc384777
MM
518 ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
519{
520 int i, j;
521 int shift,filter,f0,f1;
522 int s_1,s_2;
523 int d,s,t;
524
525 for(i=0;i<4;i++) {
526
527 shift = 12 - (in[4+i*2] & 15);
528 filter = in[4+i*2] >> 4;
529 f0 = xa_adpcm_table[filter][0];
530 f1 = xa_adpcm_table[filter][1];
531
532 s_1 = left->sample1;
533 s_2 = left->sample2;
534
535 for(j=0;j<28;j++) {
536 d = in[16+i+j*4];
537
538 t = (signed char)(d<<4)>>4;
539 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
540 CLAMP_TO_SHORT(s);
541 *out = s;
542 out += inc;
543 s_2 = s_1;
544 s_1 = s;
545 }
546
547 if (inc==2) { /* stereo */
548 left->sample1 = s_1;
549 left->sample2 = s_2;
550 s_1 = right->sample1;
551 s_2 = right->sample2;
552 out = out + 1 - 28*2;
553 }
554
555 shift = 12 - (in[5+i*2] & 15);
556 filter = in[5+i*2] >> 4;
557
558 f0 = xa_adpcm_table[filter][0];
559 f1 = xa_adpcm_table[filter][1];
560
561 for(j=0;j<28;j++) {
562 d = in[16+i+j*4];
563
564 t = (signed char)d >> 4;
565 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
566 CLAMP_TO_SHORT(s);
567 *out = s;
568 out += inc;
569 s_2 = s_1;
570 s_1 = s;
571 }
572
573 if (inc==2) { /* stereo */
574 right->sample1 = s_1;
575 right->sample2 = s_2;
576 out -= 1;
577 } else {
578 left->sample1 = s_1;
579 left->sample2 = s_2;
580 }
581 }
582}
583
584
9937e686
MM
585/* DK3 ADPCM support macro */
586#define DK3_GET_NEXT_NIBBLE() \
587 if (decode_top_nibble_next) \
588 { \
589 nibble = (last_byte >> 4) & 0x0F; \
590 decode_top_nibble_next = 0; \
591 } \
592 else \
593 { \
594 last_byte = *src++; \
595 if (src >= buf + buf_size) break; \
596 nibble = last_byte & 0x0F; \
597 decode_top_nibble_next = 1; \
598 }
599
0147f198 600static int adpcm_decode_frame(AVCodecContext *avctx,
bb270c08
DB
601 void *data, int *data_size,
602 uint8_t *buf, int buf_size)
0147f198
FR
603{
604 ADPCMContext *c = avctx->priv_data;
605 ADPCMChannelStatus *cs;
4b465299 606 int n, m, channel, i;
0147f198
FR
607 int block_predictor[2];
608 short *samples;
0c1a9eda 609 uint8_t *src;
0147f198
FR
610 int st; /* stereo */
611
9937e686
MM
612 /* DK3 ADPCM accounting variables */
613 unsigned char last_byte = 0;
614 unsigned char nibble;
615 int decode_top_nibble_next = 0;
616 int diff_channel;
617
7d8379f2
MM
618 /* EA ADPCM state variables */
619 uint32_t samples_in_chunk;
620 int32_t previous_left_sample, previous_right_sample;
621 int32_t current_left_sample, current_right_sample;
622 int32_t next_left_sample, next_right_sample;
623 int32_t coeff1l, coeff2l, coeff1r, coeff2r;
624 uint8_t shift_left, shift_right;
625 int count1, count2;
626
df72754d
MM
627 if (!buf_size)
628 return 0;
629
0147f198
FR
630 samples = data;
631 src = buf;
632
2433f24f 633 st = avctx->channels == 2 ? 1 : 0;
0147f198
FR
634
635 switch(avctx->codec->id) {
636 case CODEC_ID_ADPCM_IMA_QT:
637 n = (buf_size - 2);/* >> 2*avctx->channels;*/
638 channel = c->channel;
639 cs = &(c->status[channel]);
640 /* (pppppp) (piiiiiii) */
641
642 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
643 cs->predictor = (*src++) << 8;
644 cs->predictor |= (*src & 0x80);
645 cs->predictor &= 0xFF80;
646
647 /* sign extension */
648 if(cs->predictor & 0x8000)
649 cs->predictor -= 0x10000;
650
651 CLAMP_TO_SHORT(cs->predictor);
652
653 cs->step_index = (*src++) & 0x7F;
654
8d359bba
MN
655 if (cs->step_index > 88){
656 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
657 cs->step_index = 88;
658 }
0147f198
FR
659
660 cs->step = step_table[cs->step_index];
661
662 if (st && channel)
663 samples++;
664
665 for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
d94728c3 666 *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3);
0147f198 667 samples += avctx->channels;
d94728c3 668 *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F, 3);
0147f198
FR
669 samples += avctx->channels;
670 src ++;
671 }
672
673 if(st) { /* handle stereo interlacing */
674 c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */
ac3d5cac 675 if(channel == 1) { /* wait for the other packet before outputing anything */
0147f198
FR
676 return src - buf;
677 }
678 }
679 break;
680 case CODEC_ID_ADPCM_IMA_WAV:
ca1d62f4
AY
681 if (avctx->block_align != 0 && buf_size > avctx->block_align)
682 buf_size = avctx->block_align;
683
8d359bba
MN
684// samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1;
685
d94728c3
MN
686 for(i=0; i<avctx->channels; i++){
687 cs = &(c->status[i]);
8d359bba
MN
688 cs->predictor = (int16_t)(src[0] + (src[1]<<8));
689 src+=2;
0147f198 690
bb270c08 691 // XXX: is this correct ??: *samples++ = cs->predictor;
889c5224 692
d94728c3 693 cs->step_index = *src++;
8d359bba
MN
694 if (cs->step_index > 88){
695 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
696 cs->step_index = 88;
697 }
698 if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */
0147f198 699 }
0147f198 700
8d359bba
MN
701 while(src < buf + buf_size){
702 for(m=0; m<4; m++){
703 for(i=0; i<=st; i++)
704 *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3);
705 for(i=0; i<=st; i++)
706 *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3);
707 src++;
bb270c08 708 }
8d359bba 709 src += 4*st;
bb270c08 710 }
0147f198 711 break;
4b465299
MN
712 case CODEC_ID_ADPCM_4XM:
713 cs = &(c->status[0]);
714 c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
715 if(st){
716 c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
717 }
718 c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
719 if(st){
720 c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
721 }
ac3d5cac
MM
722 if (cs->step_index < 0) cs->step_index = 0;
723 if (cs->step_index > 88) cs->step_index = 88;
4b465299
MN
724
725 m= (buf_size - (src - buf))>>st;
4b465299 726 for(i=0; i<m; i++) {
bb270c08 727 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
4b465299 728 if (st)
d94728c3
MN
729 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
730 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
bb270c08 731 if (st)
d94728c3 732 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
bb270c08 733 }
4b465299
MN
734
735 src += m<<st;
736
737 break;
0147f198 738 case CODEC_ID_ADPCM_MS:
ca1d62f4
AY
739 if (avctx->block_align != 0 && buf_size > avctx->block_align)
740 buf_size = avctx->block_align;
0147f198
FR
741 n = buf_size - 7 * avctx->channels;
742 if (n < 0)
743 return -1;
6cf9d5eb 744 block_predictor[0] = clip(*src++, 0, 7);
0147f198
FR
745 block_predictor[1] = 0;
746 if (st)
6cf9d5eb
MN
747 block_predictor[1] = clip(*src++, 0, 7);
748 c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
0147f198 749 src+=2;
6cf9d5eb
MN
750 if (st){
751 c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
0147f198 752 src+=2;
6cf9d5eb 753 }
0147f198
FR
754 c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
755 c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
756 c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
757 c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
115329f1 758
0147f198
FR
759 c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
760 src+=2;
761 if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
762 if (st) src+=2;
763 c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
764 src+=2;
765 if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
766 if (st) src+=2;
767
768 *samples++ = c->status[0].sample1;
769 if (st) *samples++ = c->status[1].sample1;
770 *samples++ = c->status[0].sample2;
771 if (st) *samples++ = c->status[1].sample2;
772 for(;n>0;n--) {
773 *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F);
774 *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
775 src ++;
776 }
777 break;
9937e686 778 case CODEC_ID_ADPCM_IMA_DK4:
5c69a4fd
MN
779 if (avctx->block_align != 0 && buf_size > avctx->block_align)
780 buf_size = avctx->block_align;
781
6cf9d5eb 782 c->status[0].predictor = (int16_t)(src[0] | (src[1] << 8));
9937e686
MM
783 c->status[0].step_index = src[2];
784 src += 4;
9937e686
MM
785 *samples++ = c->status[0].predictor;
786 if (st) {
6cf9d5eb 787 c->status[1].predictor = (int16_t)(src[0] | (src[1] << 8));
9937e686
MM
788 c->status[1].step_index = src[2];
789 src += 4;
9937e686
MM
790 *samples++ = c->status[1].predictor;
791 }
792 while (src < buf + buf_size) {
793
794 /* take care of the top nibble (always left or mono channel) */
115329f1 795 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 796 (src[0] >> 4) & 0x0F, 3);
9937e686
MM
797
798 /* take care of the bottom nibble, which is right sample for
799 * stereo, or another mono sample */
800 if (st)
115329f1 801 *samples++ = adpcm_ima_expand_nibble(&c->status[1],
d94728c3 802 src[0] & 0x0F, 3);
9937e686 803 else
115329f1 804 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 805 src[0] & 0x0F, 3);
9937e686
MM
806
807 src++;
808 }
809 break;
810 case CODEC_ID_ADPCM_IMA_DK3:
5c69a4fd
MN
811 if (avctx->block_align != 0 && buf_size > avctx->block_align)
812 buf_size = avctx->block_align;
813
6cf9d5eb
MN
814 c->status[0].predictor = (int16_t)(src[10] | (src[11] << 8));
815 c->status[1].predictor = (int16_t)(src[12] | (src[13] << 8));
9937e686
MM
816 c->status[0].step_index = src[14];
817 c->status[1].step_index = src[15];
818 /* sign extend the predictors */
9937e686
MM
819 src += 16;
820 diff_channel = c->status[1].predictor;
821
822 /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
823 * the buffer is consumed */
824 while (1) {
825
826 /* for this algorithm, c->status[0] is the sum channel and
827 * c->status[1] is the diff channel */
828
829 /* process the first predictor of the sum channel */
830 DK3_GET_NEXT_NIBBLE();
d94728c3 831 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
9937e686
MM
832
833 /* process the diff channel predictor */
834 DK3_GET_NEXT_NIBBLE();
d94728c3 835 adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
9937e686
MM
836
837 /* process the first pair of stereo PCM samples */
838 diff_channel = (diff_channel + c->status[1].predictor) / 2;
839 *samples++ = c->status[0].predictor + c->status[1].predictor;
840 *samples++ = c->status[0].predictor - c->status[1].predictor;
841
842 /* process the second predictor of the sum channel */
843 DK3_GET_NEXT_NIBBLE();
d94728c3 844 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
9937e686
MM
845
846 /* process the second pair of stereo PCM samples */
847 diff_channel = (diff_channel + c->status[1].predictor) / 2;
848 *samples++ = c->status[0].predictor + c->status[1].predictor;
849 *samples++ = c->status[0].predictor - c->status[1].predictor;
850 }
851 break;
2fdf638b
MM
852 case CODEC_ID_ADPCM_IMA_WS:
853 /* no per-block initialization; just start decoding the data */
854 while (src < buf + buf_size) {
855
856 if (st) {
115329f1 857 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 858 (src[0] >> 4) & 0x0F, 3);
115329f1 859 *samples++ = adpcm_ima_expand_nibble(&c->status[1],
d94728c3 860 src[0] & 0x0F, 3);
2fdf638b 861 } else {
115329f1 862 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 863 (src[0] >> 4) & 0x0F, 3);
115329f1 864 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 865 src[0] & 0x0F, 3);
2fdf638b
MM
866 }
867
868 src++;
869 }
870 break;
fc384777 871 case CODEC_ID_ADPCM_XA:
115329f1 872 c->status[0].sample1 = c->status[0].sample2 =
fc384777
MM
873 c->status[1].sample1 = c->status[1].sample2 = 0;
874 while (buf_size >= 128) {
115329f1 875 xa_decode(samples, src, &c->status[0], &c->status[1],
fc384777
MM
876 avctx->channels);
877 src += 128;
878 samples += 28 * 8;
879 buf_size -= 128;
880 }
881 break;
7d8379f2
MM
882 case CODEC_ID_ADPCM_EA:
883 samples_in_chunk = LE_32(src);
884 if (samples_in_chunk >= ((buf_size - 12) * 2)) {
885 src += buf_size;
886 break;
887 }
888 src += 4;
889 current_left_sample = (int16_t)LE_16(src);
890 src += 2;
891 previous_left_sample = (int16_t)LE_16(src);
892 src += 2;
893 current_right_sample = (int16_t)LE_16(src);
894 src += 2;
895 previous_right_sample = (int16_t)LE_16(src);
896 src += 2;
897
898 for (count1 = 0; count1 < samples_in_chunk/28;count1++) {
899 coeff1l = ea_adpcm_table[(*src >> 4) & 0x0F];
900 coeff2l = ea_adpcm_table[((*src >> 4) & 0x0F) + 4];
901 coeff1r = ea_adpcm_table[*src & 0x0F];
902 coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
903 src++;
904
905 shift_left = ((*src >> 4) & 0x0F) + 8;
906 shift_right = (*src & 0x0F) + 8;
907 src++;
908
909 for (count2 = 0; count2 < 28; count2++) {
910 next_left_sample = (((*src & 0xF0) << 24) >> shift_left);
911 next_right_sample = (((*src & 0x0F) << 28) >> shift_right);
912 src++;
913
115329f1
DB
914 next_left_sample = (next_left_sample +
915 (current_left_sample * coeff1l) +
7d8379f2 916 (previous_left_sample * coeff2l) + 0x80) >> 8;
115329f1
DB
917 next_right_sample = (next_right_sample +
918 (current_right_sample * coeff1r) +
7d8379f2
MM
919 (previous_right_sample * coeff2r) + 0x80) >> 8;
920 CLAMP_TO_SHORT(next_left_sample);
921 CLAMP_TO_SHORT(next_right_sample);
922
923 previous_left_sample = current_left_sample;
924 current_left_sample = next_left_sample;
925 previous_right_sample = current_right_sample;
926 current_right_sample = next_right_sample;
927 *samples++ = (unsigned short)current_left_sample;
928 *samples++ = (unsigned short)current_right_sample;
929 }
930 }
931 break;
932 case CODEC_ID_ADPCM_IMA_SMJPEG:
933 c->status[0].predictor = *src;
934 src += 2;
935 c->status[0].step_index = *src++;
936 src++; /* skip another byte before getting to the meat */
937 while (src < buf + buf_size) {
938 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
939 *src & 0x0F, 3);
940 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
941 (*src >> 4) & 0x0F, 3);
942 src++;
943 }
944 break;
b3bfb299 945 case CODEC_ID_ADPCM_CT:
bb270c08 946 while (src < buf + buf_size) {
b3bfb299 947 if (st) {
115329f1 948 *samples++ = adpcm_ct_expand_nibble(&c->status[0],
b3bfb299 949 (src[0] >> 4) & 0x0F);
115329f1 950 *samples++ = adpcm_ct_expand_nibble(&c->status[1],
b3bfb299
MM
951 src[0] & 0x0F);
952 } else {
115329f1 953 *samples++ = adpcm_ct_expand_nibble(&c->status[0],
b3bfb299 954 (src[0] >> 4) & 0x0F);
115329f1 955 *samples++ = adpcm_ct_expand_nibble(&c->status[0],
b3bfb299
MM
956 src[0] & 0x0F);
957 }
bb270c08 958 src++;
b3bfb299
MM
959 }
960 break;
2433f24f
AJ
961 case CODEC_ID_ADPCM_SBPRO_4:
962 case CODEC_ID_ADPCM_SBPRO_3:
963 case CODEC_ID_ADPCM_SBPRO_2:
964 if (!c->status[0].step_index) {
965 /* the first byte is a raw sample */
966 *samples++ = 128 * (*src++ - 0x80);
967 if (st)
968 *samples++ = 128 * (*src++ - 0x80);
969 c->status[0].step_index = 1;
970 }
971 if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
972 while (src < buf + buf_size) {
973 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
974 (src[0] >> 4) & 0x0F, 4, 0);
975 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
976 src[0] & 0x0F, 4, 0);
977 src++;
978 }
979 } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
980 while (src < buf + buf_size) {
981 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
982 (src[0] >> 5) & 0x07, 3, 0);
983 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
984 (src[0] >> 2) & 0x07, 3, 0);
985 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
986 src[0] & 0x03, 2, 0);
987 src++;
988 }
989 } else {
990 while (src < buf + buf_size) {
991 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
992 (src[0] >> 6) & 0x03, 2, 2);
993 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
994 (src[0] >> 4) & 0x03, 2, 2);
995 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
996 (src[0] >> 2) & 0x03, 2, 2);
997 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
998 src[0] & 0x03, 2, 2);
999 src++;
1000 }
1001 }
1002 break;
659c3692
AB
1003 case CODEC_ID_ADPCM_SWF:
1004 {
bb270c08
DB
1005 GetBitContext gb;
1006 const int *table;
1007 int k0, signmask;
1008 int size = buf_size*8;
1009
1010 init_get_bits(&gb, buf, size);
1011
1012 // first frame, read bits & inital values
1013 if (!c->nb_bits)
1014 {
1015 c->nb_bits = get_bits(&gb, 2)+2;
1016// av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", c->nb_bits);
1017 }
1018
1019 table = swf_index_tables[c->nb_bits-2];
1020 k0 = 1 << (c->nb_bits-2);
1021 signmask = 1 << (c->nb_bits-1);
1022
1023 while (get_bits_count(&gb) <= size)
1024 {
1025 int i;
1026
1027 c->nb_samples++;
1028 // wrap around at every 4096 samples...
1029 if ((c->nb_samples & 0xfff) == 1)
1030 {
1031 for (i = 0; i <= st; i++)
1032 {
1033 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
1034 c->status[i].step_index = get_bits(&gb, 6);
1035 }
1036 }
1037
1038 // similar to IMA adpcm
1039 for (i = 0; i <= st; i++)
1040 {
1041 int delta = get_bits(&gb, c->nb_bits);
1042 int step = step_table[c->status[i].step_index];
1043 long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
1044 int k = k0;
1045
1046 do {
1047 if (delta & k)
1048 vpdiff += step;
1049 step >>= 1;
1050 k >>= 1;
1051 } while(k);
1052 vpdiff += step;
1053
1054 if (delta & signmask)
1055 c->status[i].predictor -= vpdiff;
1056 else
1057 c->status[i].predictor += vpdiff;
1058
1059 c->status[i].step_index += table[delta & (~signmask)];
1060
1061 c->status[i].step_index = clip(c->status[i].step_index, 0, 88);
1062 c->status[i].predictor = clip(c->status[i].predictor, -32768, 32767);
1063
1064 *samples++ = c->status[i].predictor;
1065 }
1066 }
1067
1068// src += get_bits_count(&gb)*8;
1069 src += size;
1070
1071 break;
659c3692 1072 }
2ff4524e
VM
1073 case CODEC_ID_ADPCM_YAMAHA:
1074 while (src < buf + buf_size) {
1075 if (st) {
1076 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
2ff4524e 1077 src[0] & 0x0F);
b194c327 1078 *samples++ = adpcm_yamaha_expand_nibble(&c->status[1],
2ff4524e 1079 (src[0] >> 4) & 0x0F);
b194c327 1080 } else {
2ff4524e
VM
1081 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
1082 src[0] & 0x0F);
b194c327
MN
1083 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
1084 (src[0] >> 4) & 0x0F);
2ff4524e
VM
1085 }
1086 src++;
1087 }
1088 break;
0147f198 1089 default:
0147f198
FR
1090 return -1;
1091 }
0c1a9eda 1092 *data_size = (uint8_t *)samples - (uint8_t *)data;
0147f198
FR
1093 return src - buf;
1094}
1095
764ef400
MM
1096
1097
1098#ifdef CONFIG_ENCODERS
1099#define ADPCM_ENCODER(id,name) \
0147f198
FR
1100AVCodec name ## _encoder = { \
1101 #name, \
1102 CODEC_TYPE_AUDIO, \
1103 id, \
1104 sizeof(ADPCMContext), \
1105 adpcm_encode_init, \
1106 adpcm_encode_frame, \
1107 adpcm_encode_close, \
1108 NULL, \
764ef400
MM
1109};
1110#else
1111#define ADPCM_ENCODER(id,name)
1112#endif
1113
1114#ifdef CONFIG_DECODERS
1115#define ADPCM_DECODER(id,name) \
0147f198
FR
1116AVCodec name ## _decoder = { \
1117 #name, \
1118 CODEC_TYPE_AUDIO, \
1119 id, \
1120 sizeof(ADPCMContext), \
1121 adpcm_decode_init, \
1122 NULL, \
1123 NULL, \
1124 adpcm_decode_frame, \
1125};
764ef400
MM
1126#else
1127#define ADPCM_DECODER(id,name)
1128#endif
1129
1130#define ADPCM_CODEC(id, name) \
1131ADPCM_ENCODER(id,name) ADPCM_DECODER(id,name)
0147f198
FR
1132
1133ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
1134ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
9937e686
MM
1135ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
1136ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
2fdf638b 1137ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
7d8379f2 1138ADPCM_CODEC(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
0147f198 1139ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
4b465299 1140ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
fc384777
MM
1141ADPCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa);
1142ADPCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx);
7d8379f2 1143ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
b3bfb299 1144ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
659c3692 1145ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
2ff4524e 1146ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
2433f24f
AJ
1147ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
1148ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
1149ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
0147f198
FR
1150
1151#undef ADPCM_CODEC