4% faster h264_qpel_mc
[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{
206 int step_index;
207 unsigned char nibble;
115329f1 208
889c5224
FR
209 int sign = 0; /* sign bit of the nibble (MSB) */
210 int delta, predicted_delta;
211
212 delta = sample - c->prev_sample;
213
214 if (delta < 0) {
215 sign = 1;
216 delta = -delta;
217 }
218
219 step_index = c->step_index;
220
221 /* nibble = 4 * delta / step_table[step_index]; */
222 nibble = (delta << 2) / step_table[step_index];
223
224 if (nibble > 7)
225 nibble = 7;
226
227 step_index += index_table[nibble];
228 if (step_index < 0)
229 step_index = 0;
230 if (step_index > 88)
231 step_index = 88;
232
233 /* what the decoder will find */
234 predicted_delta = ((step_table[step_index] * nibble) / 4) + (step_table[step_index] / 8);
235
236 if (sign)
237 c->prev_sample -= predicted_delta;
238 else
239 c->prev_sample += predicted_delta;
240
241 CLAMP_TO_SHORT(c->prev_sample);
242
243
115329f1 244 nibble += sign << 3; /* sign * 8 */
889c5224
FR
245
246 /* save back */
247 c->step_index = step_index;
248
249 return nibble;
250}
251
6cf9d5eb
MN
252static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
253{
254 int predictor, nibble, bias;
255
256 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
115329f1 257
6cf9d5eb
MN
258 nibble= sample - predictor;
259 if(nibble>=0) bias= c->idelta/2;
260 else bias=-c->idelta/2;
115329f1 261
6cf9d5eb
MN
262 nibble= (nibble + bias) / c->idelta;
263 nibble= clip(nibble, -8, 7)&0x0F;
115329f1 264
6cf9d5eb
MN
265 predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
266 CLAMP_TO_SHORT(predictor);
267
268 c->sample2 = c->sample1;
269 c->sample1 = predictor;
270
271 c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
272 if (c->idelta < 16) c->idelta = 16;
273
274 return nibble;
275}
276
2ff4524e
VM
277static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample)
278{
279 int i1 = 0, j1;
280
281 if(!c->step) {
282 c->predictor = 0;
283 c->step = 127;
284 }
285 j1 = sample - c->predictor;
286
287 j1 = (j1 * 8) / c->step;
288 i1 = abs(j1) / 2;
289 if (i1 > 7)
290 i1 = 7;
291 if (j1 < 0)
292 i1 += 8;
293
294 c->predictor = c->predictor + ((c->step * yamaha_difflookup[i1]) / 8);
295 CLAMP_TO_SHORT(c->predictor);
296 c->step = (c->step * yamaha_indexscale[i1]) >> 8;
297 c->step = clip(c->step, 127, 24567);
298
299 return i1;
300}
301
0147f198 302static int adpcm_encode_frame(AVCodecContext *avctx,
bb270c08 303 unsigned char *frame, int buf_size, void *data)
0147f198 304{
6cf9d5eb 305 int n, i, st;
0147f198
FR
306 short *samples;
307 unsigned char *dst;
889c5224
FR
308 ADPCMContext *c = avctx->priv_data;
309
310 dst = frame;
311 samples = (short *)data;
6cf9d5eb 312 st= avctx->channels == 2;
889c5224 313/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
0147f198
FR
314
315 switch(avctx->codec->id) {
889c5224
FR
316 case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */
317 break;
318 case CODEC_ID_ADPCM_IMA_WAV:
319 n = avctx->frame_size / 8;
320 c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
321/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
322 *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */
323 *dst++ = (c->status[0].prev_sample >> 8) & 0xFF;
324 *dst++ = (unsigned char)c->status[0].step_index;
325 *dst++ = 0; /* unknown */
326 samples++;
327 if (avctx->channels == 2) {
1ffb0091 328 c->status[1].prev_sample = (signed short)samples[1];
889c5224
FR
329/* c->status[1].step_index = 0; */
330 *dst++ = (c->status[1].prev_sample) & 0xFF;
331 *dst++ = (c->status[1].prev_sample >> 8) & 0xFF;
332 *dst++ = (unsigned char)c->status[1].step_index;
333 *dst++ = 0;
334 samples++;
335 }
115329f1 336
889c5224
FR
337 /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
338 for (; n>0; n--) {
339 *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F;
340 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0;
341 dst++;
342 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F;
343 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0;
344 dst++;
345 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F;
346 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0;
347 dst++;
348 *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F;
349 *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0;
350 dst++;
351 /* right channel */
352 if (avctx->channels == 2) {
353 *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
354 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
355 dst++;
356 *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
357 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
358 dst++;
359 *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
360 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
361 dst++;
362 *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
363 *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
364 dst++;
365 }
366 samples += 8 * avctx->channels;
367 }
368 break;
6cf9d5eb
MN
369 case CODEC_ID_ADPCM_MS:
370 for(i=0; i<avctx->channels; i++){
371 int predictor=0;
372
373 *dst++ = predictor;
374 c->status[i].coeff1 = AdaptCoeff1[predictor];
375 c->status[i].coeff2 = AdaptCoeff2[predictor];
376 }
377 for(i=0; i<avctx->channels; i++){
115329f1 378 if (c->status[i].idelta < 16)
6cf9d5eb 379 c->status[i].idelta = 16;
115329f1 380
6cf9d5eb
MN
381 *dst++ = c->status[i].idelta & 0xFF;
382 *dst++ = c->status[i].idelta >> 8;
383 }
384 for(i=0; i<avctx->channels; i++){
385 c->status[i].sample1= *samples++;
386
387 *dst++ = c->status[i].sample1 & 0xFF;
388 *dst++ = c->status[i].sample1 >> 8;
389 }
390 for(i=0; i<avctx->channels; i++){
391 c->status[i].sample2= *samples++;
392
393 *dst++ = c->status[i].sample2 & 0xFF;
394 *dst++ = c->status[i].sample2 >> 8;
395 }
396
397 for(i=7*avctx->channels; i<avctx->block_align; i++) {
398 int nibble;
399 nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4;
400 nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++);
401 *dst++ = nibble;
402 }
403 break;
2ff4524e
VM
404 case CODEC_ID_ADPCM_YAMAHA:
405 n = avctx->frame_size / 2;
406 for (; n>0; n--) {
407 for(i = 0; i < avctx->channels; i++) {
408 int nibble;
b194c327
MN
409 nibble = adpcm_yamaha_compress_sample(&c->status[i], samples[i]);
410 nibble |= adpcm_yamaha_compress_sample(&c->status[i], samples[i+avctx->channels]) << 4;
2ff4524e
VM
411 *dst++ = nibble;
412 }
413 samples += 2 * avctx->channels;
414 }
415 break;
0147f198
FR
416 default:
417 return -1;
418 }
0147f198
FR
419 return dst - frame;
420}
764ef400 421#endif //CONFIG_ENCODERS
0147f198
FR
422
423static int adpcm_decode_init(AVCodecContext * avctx)
424{
425 ADPCMContext *c = avctx->priv_data;
426
427 c->channel = 0;
428 c->status[0].predictor = c->status[1].predictor = 0;
429 c->status[0].step_index = c->status[1].step_index = 0;
430 c->status[0].step = c->status[1].step = 0;
431
432 switch(avctx->codec->id) {
b3bfb299 433 case CODEC_ID_ADPCM_CT:
bb270c08
DB
434 c->status[0].step = c->status[1].step = 511;
435 break;
0147f198
FR
436 default:
437 break;
438 }
439 return 0;
440}
441
d94728c3 442static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
0147f198
FR
443{
444 int step_index;
445 int predictor;
446 int sign, delta, diff, step;
447
135ee03a 448 step = step_table[c->step_index];
0147f198
FR
449 step_index = c->step_index + index_table[(unsigned)nibble];
450 if (step_index < 0) step_index = 0;
135ee03a 451 else if (step_index > 88) step_index = 88;
0147f198 452
0147f198
FR
453 sign = nibble & 8;
454 delta = nibble & 7;
9937e686
MM
455 /* perform direct multiplication instead of series of jumps proposed by
456 * the reference ADPCM implementation since modern CPUs can do the mults
457 * quickly enough */
d94728c3 458 diff = ((2 * delta + 1) * step) >> shift;
4b465299
MN
459 predictor = c->predictor;
460 if (sign) predictor -= diff;
461 else predictor += diff;
462
463 CLAMP_TO_SHORT(predictor);
464 c->predictor = predictor;
465 c->step_index = step_index;
466
467 return (short)predictor;
468}
469
0147f198
FR
470static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
471{
472 int predictor;
473
474 predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
475 predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
476 CLAMP_TO_SHORT(predictor);
477
478 c->sample2 = c->sample1;
479 c->sample1 = predictor;
6cf9d5eb 480 c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
0147f198
FR
481 if (c->idelta < 16) c->idelta = 16;
482
483 return (short)predictor;
484}
485
b3bfb299
MM
486static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
487{
488 int predictor;
489 int sign, delta, diff;
490 int new_step;
491
492 sign = nibble & 8;
493 delta = nibble & 7;
494 /* perform direct multiplication instead of series of jumps proposed by
495 * the reference ADPCM implementation since modern CPUs can do the mults
496 * quickly enough */
497 diff = ((2 * delta + 1) * c->step) >> 3;
498 predictor = c->predictor;
499 /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
500 if(sign)
bb270c08 501 predictor = ((predictor * 254) >> 8) - diff;
b3bfb299 502 else
bb270c08 503 predictor = ((predictor * 254) >> 8) + diff;
b3bfb299
MM
504 /* calculate new step and clamp it to range 511..32767 */
505 new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8;
506 c->step = new_step;
507 if(c->step < 511)
bb270c08 508 c->step = 511;
b3bfb299 509 if(c->step > 32767)
bb270c08 510 c->step = 32767;
b3bfb299
MM
511
512 CLAMP_TO_SHORT(predictor);
513 c->predictor = predictor;
514 return (short)predictor;
515}
516
2433f24f
AJ
517static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
518{
519 int sign, delta, diff;
520
521 sign = nibble & (1<<(size-1));
522 delta = nibble & ((1<<(size-1))-1);
523 diff = delta << (7 + c->step + shift);
524
525 if (sign)
526 c->predictor -= diff;
527 else
528 c->predictor += diff;
529
530 /* clamp result */
531 if (c->predictor > 16256)
532 c->predictor = 16256;
533 else if (c->predictor < -16384)
534 c->predictor = -16384;
535
536 /* calculate new step */
537 if (delta >= (2*size - 3) && c->step < 3)
538 c->step++;
539 else if (delta == 0 && c->step > 0)
540 c->step--;
541
542 return (short) c->predictor;
543}
544
2ff4524e
VM
545static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
546{
547 if(!c->step) {
548 c->predictor = 0;
549 c->step = 127;
550 }
551
552 c->predictor += (c->step * yamaha_difflookup[nibble]) / 8;
553 CLAMP_TO_SHORT(c->predictor);
554 c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
555 c->step = clip(c->step, 127, 24567);
556 return c->predictor;
557}
558
115329f1 559static void xa_decode(short *out, const unsigned char *in,
fc384777
MM
560 ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
561{
562 int i, j;
563 int shift,filter,f0,f1;
564 int s_1,s_2;
565 int d,s,t;
566
567 for(i=0;i<4;i++) {
568
569 shift = 12 - (in[4+i*2] & 15);
570 filter = in[4+i*2] >> 4;
571 f0 = xa_adpcm_table[filter][0];
572 f1 = xa_adpcm_table[filter][1];
573
574 s_1 = left->sample1;
575 s_2 = left->sample2;
576
577 for(j=0;j<28;j++) {
578 d = in[16+i+j*4];
579
580 t = (signed char)(d<<4)>>4;
581 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
582 CLAMP_TO_SHORT(s);
583 *out = s;
584 out += inc;
585 s_2 = s_1;
586 s_1 = s;
587 }
588
589 if (inc==2) { /* stereo */
590 left->sample1 = s_1;
591 left->sample2 = s_2;
592 s_1 = right->sample1;
593 s_2 = right->sample2;
594 out = out + 1 - 28*2;
595 }
596
597 shift = 12 - (in[5+i*2] & 15);
598 filter = in[5+i*2] >> 4;
599
600 f0 = xa_adpcm_table[filter][0];
601 f1 = xa_adpcm_table[filter][1];
602
603 for(j=0;j<28;j++) {
604 d = in[16+i+j*4];
605
606 t = (signed char)d >> 4;
607 s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
608 CLAMP_TO_SHORT(s);
609 *out = s;
610 out += inc;
611 s_2 = s_1;
612 s_1 = s;
613 }
614
615 if (inc==2) { /* stereo */
616 right->sample1 = s_1;
617 right->sample2 = s_2;
618 out -= 1;
619 } else {
620 left->sample1 = s_1;
621 left->sample2 = s_2;
622 }
623 }
624}
625
626
9937e686
MM
627/* DK3 ADPCM support macro */
628#define DK3_GET_NEXT_NIBBLE() \
629 if (decode_top_nibble_next) \
630 { \
631 nibble = (last_byte >> 4) & 0x0F; \
632 decode_top_nibble_next = 0; \
633 } \
634 else \
635 { \
636 last_byte = *src++; \
637 if (src >= buf + buf_size) break; \
638 nibble = last_byte & 0x0F; \
639 decode_top_nibble_next = 1; \
640 }
641
0147f198 642static int adpcm_decode_frame(AVCodecContext *avctx,
bb270c08
DB
643 void *data, int *data_size,
644 uint8_t *buf, int buf_size)
0147f198
FR
645{
646 ADPCMContext *c = avctx->priv_data;
647 ADPCMChannelStatus *cs;
4b465299 648 int n, m, channel, i;
0147f198
FR
649 int block_predictor[2];
650 short *samples;
0c1a9eda 651 uint8_t *src;
0147f198
FR
652 int st; /* stereo */
653
9937e686
MM
654 /* DK3 ADPCM accounting variables */
655 unsigned char last_byte = 0;
656 unsigned char nibble;
657 int decode_top_nibble_next = 0;
658 int diff_channel;
659
7d8379f2
MM
660 /* EA ADPCM state variables */
661 uint32_t samples_in_chunk;
662 int32_t previous_left_sample, previous_right_sample;
663 int32_t current_left_sample, current_right_sample;
664 int32_t next_left_sample, next_right_sample;
665 int32_t coeff1l, coeff2l, coeff1r, coeff2r;
666 uint8_t shift_left, shift_right;
667 int count1, count2;
668
df72754d
MM
669 if (!buf_size)
670 return 0;
671
0147f198
FR
672 samples = data;
673 src = buf;
674
2433f24f 675 st = avctx->channels == 2 ? 1 : 0;
0147f198
FR
676
677 switch(avctx->codec->id) {
678 case CODEC_ID_ADPCM_IMA_QT:
679 n = (buf_size - 2);/* >> 2*avctx->channels;*/
680 channel = c->channel;
681 cs = &(c->status[channel]);
682 /* (pppppp) (piiiiiii) */
683
684 /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
685 cs->predictor = (*src++) << 8;
686 cs->predictor |= (*src & 0x80);
687 cs->predictor &= 0xFF80;
688
689 /* sign extension */
690 if(cs->predictor & 0x8000)
691 cs->predictor -= 0x10000;
692
693 CLAMP_TO_SHORT(cs->predictor);
694
695 cs->step_index = (*src++) & 0x7F;
696
9b879566 697 if (cs->step_index > 88) av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
0147f198
FR
698 if (cs->step_index > 88) cs->step_index = 88;
699
700 cs->step = step_table[cs->step_index];
701
702 if (st && channel)
703 samples++;
704
705 for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
d94728c3 706 *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3);
0147f198 707 samples += avctx->channels;
d94728c3 708 *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F, 3);
0147f198
FR
709 samples += avctx->channels;
710 src ++;
711 }
712
713 if(st) { /* handle stereo interlacing */
714 c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */
ac3d5cac 715 if(channel == 1) { /* wait for the other packet before outputing anything */
0147f198
FR
716 return src - buf;
717 }
718 }
719 break;
720 case CODEC_ID_ADPCM_IMA_WAV:
ca1d62f4
AY
721 if (avctx->block_align != 0 && buf_size > avctx->block_align)
722 buf_size = avctx->block_align;
723
d94728c3
MN
724 for(i=0; i<avctx->channels; i++){
725 cs = &(c->status[i]);
726 cs->predictor = *src++;
727 cs->predictor |= (*src++) << 8;
0147f198
FR
728 if(cs->predictor & 0x8000)
729 cs->predictor -= 0x10000;
730 CLAMP_TO_SHORT(cs->predictor);
731
bb270c08 732 // XXX: is this correct ??: *samples++ = cs->predictor;
889c5224 733
d94728c3 734 cs->step_index = *src++;
0147f198
FR
735 if (cs->step_index < 0) cs->step_index = 0;
736 if (cs->step_index > 88) cs->step_index = 88;
d94728c3 737 if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null !!\n"); /* unused */
0147f198 738 }
0147f198 739
6b9b85c1 740 for(m=4; src < (buf + buf_size);) {
bb270c08 741 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F, 3);
0147f198 742 if (st)
d94728c3
MN
743 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[4] & 0x0F, 3);
744 *samples++ = adpcm_ima_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F, 3);
bb270c08 745 if (st) {
d94728c3 746 *samples++ = adpcm_ima_expand_nibble(&c->status[1], (src[4] >> 4) & 0x0F, 3);
bb270c08
DB
747 if (!--m) {
748 m=4;
749 src+=4;
750 }
751 }
752 src++;
753 }
0147f198 754 break;
4b465299
MN
755 case CODEC_ID_ADPCM_4XM:
756 cs = &(c->status[0]);
757 c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
758 if(st){
759 c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
760 }
761 c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
762 if(st){
763 c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
764 }
ac3d5cac
MM
765 if (cs->step_index < 0) cs->step_index = 0;
766 if (cs->step_index > 88) cs->step_index = 88;
4b465299
MN
767
768 m= (buf_size - (src - buf))>>st;
4b465299 769 for(i=0; i<m; i++) {
bb270c08 770 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
4b465299 771 if (st)
d94728c3
MN
772 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
773 *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
bb270c08 774 if (st)
d94728c3 775 *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
bb270c08 776 }
4b465299
MN
777
778 src += m<<st;
779
780 break;
0147f198 781 case CODEC_ID_ADPCM_MS:
ca1d62f4
AY
782 if (avctx->block_align != 0 && buf_size > avctx->block_align)
783 buf_size = avctx->block_align;
0147f198
FR
784 n = buf_size - 7 * avctx->channels;
785 if (n < 0)
786 return -1;
6cf9d5eb 787 block_predictor[0] = clip(*src++, 0, 7);
0147f198
FR
788 block_predictor[1] = 0;
789 if (st)
6cf9d5eb
MN
790 block_predictor[1] = clip(*src++, 0, 7);
791 c->status[0].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
0147f198 792 src+=2;
6cf9d5eb
MN
793 if (st){
794 c->status[1].idelta = (int16_t)((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
0147f198 795 src+=2;
6cf9d5eb 796 }
0147f198
FR
797 c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
798 c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
799 c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
800 c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
115329f1 801
0147f198
FR
802 c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
803 src+=2;
804 if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
805 if (st) src+=2;
806 c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
807 src+=2;
808 if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
809 if (st) src+=2;
810
811 *samples++ = c->status[0].sample1;
812 if (st) *samples++ = c->status[1].sample1;
813 *samples++ = c->status[0].sample2;
814 if (st) *samples++ = c->status[1].sample2;
815 for(;n>0;n--) {
816 *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F);
817 *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
818 src ++;
819 }
820 break;
9937e686 821 case CODEC_ID_ADPCM_IMA_DK4:
5c69a4fd
MN
822 if (avctx->block_align != 0 && buf_size > avctx->block_align)
823 buf_size = avctx->block_align;
824
6cf9d5eb 825 c->status[0].predictor = (int16_t)(src[0] | (src[1] << 8));
9937e686
MM
826 c->status[0].step_index = src[2];
827 src += 4;
9937e686
MM
828 *samples++ = c->status[0].predictor;
829 if (st) {
6cf9d5eb 830 c->status[1].predictor = (int16_t)(src[0] | (src[1] << 8));
9937e686
MM
831 c->status[1].step_index = src[2];
832 src += 4;
9937e686
MM
833 *samples++ = c->status[1].predictor;
834 }
835 while (src < buf + buf_size) {
836
837 /* take care of the top nibble (always left or mono channel) */
115329f1 838 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 839 (src[0] >> 4) & 0x0F, 3);
9937e686
MM
840
841 /* take care of the bottom nibble, which is right sample for
842 * stereo, or another mono sample */
843 if (st)
115329f1 844 *samples++ = adpcm_ima_expand_nibble(&c->status[1],
d94728c3 845 src[0] & 0x0F, 3);
9937e686 846 else
115329f1 847 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 848 src[0] & 0x0F, 3);
9937e686
MM
849
850 src++;
851 }
852 break;
853 case CODEC_ID_ADPCM_IMA_DK3:
5c69a4fd
MN
854 if (avctx->block_align != 0 && buf_size > avctx->block_align)
855 buf_size = avctx->block_align;
856
6cf9d5eb
MN
857 c->status[0].predictor = (int16_t)(src[10] | (src[11] << 8));
858 c->status[1].predictor = (int16_t)(src[12] | (src[13] << 8));
9937e686
MM
859 c->status[0].step_index = src[14];
860 c->status[1].step_index = src[15];
861 /* sign extend the predictors */
9937e686
MM
862 src += 16;
863 diff_channel = c->status[1].predictor;
864
865 /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
866 * the buffer is consumed */
867 while (1) {
868
869 /* for this algorithm, c->status[0] is the sum channel and
870 * c->status[1] is the diff channel */
871
872 /* process the first predictor of the sum channel */
873 DK3_GET_NEXT_NIBBLE();
d94728c3 874 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
9937e686
MM
875
876 /* process the diff channel predictor */
877 DK3_GET_NEXT_NIBBLE();
d94728c3 878 adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
9937e686
MM
879
880 /* process the first pair of stereo PCM samples */
881 diff_channel = (diff_channel + c->status[1].predictor) / 2;
882 *samples++ = c->status[0].predictor + c->status[1].predictor;
883 *samples++ = c->status[0].predictor - c->status[1].predictor;
884
885 /* process the second predictor of the sum channel */
886 DK3_GET_NEXT_NIBBLE();
d94728c3 887 adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
9937e686
MM
888
889 /* process the second pair of stereo PCM samples */
890 diff_channel = (diff_channel + c->status[1].predictor) / 2;
891 *samples++ = c->status[0].predictor + c->status[1].predictor;
892 *samples++ = c->status[0].predictor - c->status[1].predictor;
893 }
894 break;
2fdf638b
MM
895 case CODEC_ID_ADPCM_IMA_WS:
896 /* no per-block initialization; just start decoding the data */
897 while (src < buf + buf_size) {
898
899 if (st) {
115329f1 900 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 901 (src[0] >> 4) & 0x0F, 3);
115329f1 902 *samples++ = adpcm_ima_expand_nibble(&c->status[1],
d94728c3 903 src[0] & 0x0F, 3);
2fdf638b 904 } else {
115329f1 905 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 906 (src[0] >> 4) & 0x0F, 3);
115329f1 907 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
d94728c3 908 src[0] & 0x0F, 3);
2fdf638b
MM
909 }
910
911 src++;
912 }
913 break;
fc384777 914 case CODEC_ID_ADPCM_XA:
115329f1 915 c->status[0].sample1 = c->status[0].sample2 =
fc384777
MM
916 c->status[1].sample1 = c->status[1].sample2 = 0;
917 while (buf_size >= 128) {
115329f1 918 xa_decode(samples, src, &c->status[0], &c->status[1],
fc384777
MM
919 avctx->channels);
920 src += 128;
921 samples += 28 * 8;
922 buf_size -= 128;
923 }
924 break;
7d8379f2
MM
925 case CODEC_ID_ADPCM_EA:
926 samples_in_chunk = LE_32(src);
927 if (samples_in_chunk >= ((buf_size - 12) * 2)) {
928 src += buf_size;
929 break;
930 }
931 src += 4;
932 current_left_sample = (int16_t)LE_16(src);
933 src += 2;
934 previous_left_sample = (int16_t)LE_16(src);
935 src += 2;
936 current_right_sample = (int16_t)LE_16(src);
937 src += 2;
938 previous_right_sample = (int16_t)LE_16(src);
939 src += 2;
940
941 for (count1 = 0; count1 < samples_in_chunk/28;count1++) {
942 coeff1l = ea_adpcm_table[(*src >> 4) & 0x0F];
943 coeff2l = ea_adpcm_table[((*src >> 4) & 0x0F) + 4];
944 coeff1r = ea_adpcm_table[*src & 0x0F];
945 coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
946 src++;
947
948 shift_left = ((*src >> 4) & 0x0F) + 8;
949 shift_right = (*src & 0x0F) + 8;
950 src++;
951
952 for (count2 = 0; count2 < 28; count2++) {
953 next_left_sample = (((*src & 0xF0) << 24) >> shift_left);
954 next_right_sample = (((*src & 0x0F) << 28) >> shift_right);
955 src++;
956
115329f1
DB
957 next_left_sample = (next_left_sample +
958 (current_left_sample * coeff1l) +
7d8379f2 959 (previous_left_sample * coeff2l) + 0x80) >> 8;
115329f1
DB
960 next_right_sample = (next_right_sample +
961 (current_right_sample * coeff1r) +
7d8379f2
MM
962 (previous_right_sample * coeff2r) + 0x80) >> 8;
963 CLAMP_TO_SHORT(next_left_sample);
964 CLAMP_TO_SHORT(next_right_sample);
965
966 previous_left_sample = current_left_sample;
967 current_left_sample = next_left_sample;
968 previous_right_sample = current_right_sample;
969 current_right_sample = next_right_sample;
970 *samples++ = (unsigned short)current_left_sample;
971 *samples++ = (unsigned short)current_right_sample;
972 }
973 }
974 break;
975 case CODEC_ID_ADPCM_IMA_SMJPEG:
976 c->status[0].predictor = *src;
977 src += 2;
978 c->status[0].step_index = *src++;
979 src++; /* skip another byte before getting to the meat */
980 while (src < buf + buf_size) {
981 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
982 *src & 0x0F, 3);
983 *samples++ = adpcm_ima_expand_nibble(&c->status[0],
984 (*src >> 4) & 0x0F, 3);
985 src++;
986 }
987 break;
b3bfb299 988 case CODEC_ID_ADPCM_CT:
bb270c08 989 while (src < buf + buf_size) {
b3bfb299 990 if (st) {
115329f1 991 *samples++ = adpcm_ct_expand_nibble(&c->status[0],
b3bfb299 992 (src[0] >> 4) & 0x0F);
115329f1 993 *samples++ = adpcm_ct_expand_nibble(&c->status[1],
b3bfb299
MM
994 src[0] & 0x0F);
995 } else {
115329f1 996 *samples++ = adpcm_ct_expand_nibble(&c->status[0],
b3bfb299 997 (src[0] >> 4) & 0x0F);
115329f1 998 *samples++ = adpcm_ct_expand_nibble(&c->status[0],
b3bfb299
MM
999 src[0] & 0x0F);
1000 }
bb270c08 1001 src++;
b3bfb299
MM
1002 }
1003 break;
2433f24f
AJ
1004 case CODEC_ID_ADPCM_SBPRO_4:
1005 case CODEC_ID_ADPCM_SBPRO_3:
1006 case CODEC_ID_ADPCM_SBPRO_2:
1007 if (!c->status[0].step_index) {
1008 /* the first byte is a raw sample */
1009 *samples++ = 128 * (*src++ - 0x80);
1010 if (st)
1011 *samples++ = 128 * (*src++ - 0x80);
1012 c->status[0].step_index = 1;
1013 }
1014 if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
1015 while (src < buf + buf_size) {
1016 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1017 (src[0] >> 4) & 0x0F, 4, 0);
1018 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1019 src[0] & 0x0F, 4, 0);
1020 src++;
1021 }
1022 } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
1023 while (src < buf + buf_size) {
1024 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1025 (src[0] >> 5) & 0x07, 3, 0);
1026 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1027 (src[0] >> 2) & 0x07, 3, 0);
1028 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1029 src[0] & 0x03, 2, 0);
1030 src++;
1031 }
1032 } else {
1033 while (src < buf + buf_size) {
1034 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1035 (src[0] >> 6) & 0x03, 2, 2);
1036 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1037 (src[0] >> 4) & 0x03, 2, 2);
1038 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
1039 (src[0] >> 2) & 0x03, 2, 2);
1040 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
1041 src[0] & 0x03, 2, 2);
1042 src++;
1043 }
1044 }
1045 break;
659c3692
AB
1046 case CODEC_ID_ADPCM_SWF:
1047 {
bb270c08
DB
1048 GetBitContext gb;
1049 const int *table;
1050 int k0, signmask;
1051 int size = buf_size*8;
1052
1053 init_get_bits(&gb, buf, size);
1054
1055 // first frame, read bits & inital values
1056 if (!c->nb_bits)
1057 {
1058 c->nb_bits = get_bits(&gb, 2)+2;
1059// av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", c->nb_bits);
1060 }
1061
1062 table = swf_index_tables[c->nb_bits-2];
1063 k0 = 1 << (c->nb_bits-2);
1064 signmask = 1 << (c->nb_bits-1);
1065
1066 while (get_bits_count(&gb) <= size)
1067 {
1068 int i;
1069
1070 c->nb_samples++;
1071 // wrap around at every 4096 samples...
1072 if ((c->nb_samples & 0xfff) == 1)
1073 {
1074 for (i = 0; i <= st; i++)
1075 {
1076 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
1077 c->status[i].step_index = get_bits(&gb, 6);
1078 }
1079 }
1080
1081 // similar to IMA adpcm
1082 for (i = 0; i <= st; i++)
1083 {
1084 int delta = get_bits(&gb, c->nb_bits);
1085 int step = step_table[c->status[i].step_index];
1086 long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
1087 int k = k0;
1088
1089 do {
1090 if (delta & k)
1091 vpdiff += step;
1092 step >>= 1;
1093 k >>= 1;
1094 } while(k);
1095 vpdiff += step;
1096
1097 if (delta & signmask)
1098 c->status[i].predictor -= vpdiff;
1099 else
1100 c->status[i].predictor += vpdiff;
1101
1102 c->status[i].step_index += table[delta & (~signmask)];
1103
1104 c->status[i].step_index = clip(c->status[i].step_index, 0, 88);
1105 c->status[i].predictor = clip(c->status[i].predictor, -32768, 32767);
1106
1107 *samples++ = c->status[i].predictor;
1108 }
1109 }
1110
1111// src += get_bits_count(&gb)*8;
1112 src += size;
1113
1114 break;
659c3692 1115 }
2ff4524e
VM
1116 case CODEC_ID_ADPCM_YAMAHA:
1117 while (src < buf + buf_size) {
1118 if (st) {
1119 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
2ff4524e 1120 src[0] & 0x0F);
b194c327 1121 *samples++ = adpcm_yamaha_expand_nibble(&c->status[1],
2ff4524e 1122 (src[0] >> 4) & 0x0F);
b194c327 1123 } else {
2ff4524e
VM
1124 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
1125 src[0] & 0x0F);
b194c327
MN
1126 *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
1127 (src[0] >> 4) & 0x0F);
2ff4524e
VM
1128 }
1129 src++;
1130 }
1131 break;
0147f198 1132 default:
0147f198
FR
1133 return -1;
1134 }
0c1a9eda 1135 *data_size = (uint8_t *)samples - (uint8_t *)data;
0147f198
FR
1136 return src - buf;
1137}
1138
764ef400
MM
1139
1140
1141#ifdef CONFIG_ENCODERS
1142#define ADPCM_ENCODER(id,name) \
0147f198
FR
1143AVCodec name ## _encoder = { \
1144 #name, \
1145 CODEC_TYPE_AUDIO, \
1146 id, \
1147 sizeof(ADPCMContext), \
1148 adpcm_encode_init, \
1149 adpcm_encode_frame, \
1150 adpcm_encode_close, \
1151 NULL, \
764ef400
MM
1152};
1153#else
1154#define ADPCM_ENCODER(id,name)
1155#endif
1156
1157#ifdef CONFIG_DECODERS
1158#define ADPCM_DECODER(id,name) \
0147f198
FR
1159AVCodec name ## _decoder = { \
1160 #name, \
1161 CODEC_TYPE_AUDIO, \
1162 id, \
1163 sizeof(ADPCMContext), \
1164 adpcm_decode_init, \
1165 NULL, \
1166 NULL, \
1167 adpcm_decode_frame, \
1168};
764ef400
MM
1169#else
1170#define ADPCM_DECODER(id,name)
1171#endif
1172
1173#define ADPCM_CODEC(id, name) \
1174ADPCM_ENCODER(id,name) ADPCM_DECODER(id,name)
0147f198
FR
1175
1176ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
1177ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
9937e686
MM
1178ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
1179ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
2fdf638b 1180ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
7d8379f2 1181ADPCM_CODEC(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
0147f198 1182ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
4b465299 1183ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
fc384777
MM
1184ADPCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa);
1185ADPCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx);
7d8379f2 1186ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
b3bfb299 1187ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
659c3692 1188ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
2ff4524e 1189ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
2433f24f
AJ
1190ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
1191ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
1192ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
0147f198
FR
1193
1194#undef ADPCM_CODEC