You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1735 lines
63KB

  1. /*
  2. * ADPCM codecs
  3. * Copyright (c) 2001-2003 The ffmpeg Project
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avcodec.h"
  22. #include "get_bits.h"
  23. #include "put_bits.h"
  24. #include "bytestream.h"
  25. /**
  26. * @file
  27. * ADPCM codecs.
  28. * First version by Francois Revol (revol@free.fr)
  29. * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
  30. * by Mike Melanson (melanson@pcisys.net)
  31. * CD-ROM XA ADPCM codec by BERO
  32. * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
  33. * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org)
  34. * EA IMA EACS decoder by Peter Ross (pross@xvid.org)
  35. * EA IMA SEAD decoder by Peter Ross (pross@xvid.org)
  36. * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org)
  37. * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com)
  38. * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl)
  39. *
  40. * Features and limitations:
  41. *
  42. * Reference documents:
  43. * http://www.pcisys.net/~melanson/codecs/simpleaudio.html
  44. * http://www.geocities.com/SiliconValley/8682/aud3.txt
  45. * http://openquicktime.sourceforge.net/plugins.htm
  46. * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html
  47. * http://www.cs.ucla.edu/~leec/mediabench/applications.html
  48. * SoX source code http://home.sprynet.com/~cbagwell/sox.html
  49. *
  50. * CD-ROM XA:
  51. * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html
  52. * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html
  53. * readstr http://www.geocities.co.jp/Playtown/2004/
  54. */
  55. #define BLKSIZE 1024
  56. /* step_table[] and index_table[] are from the ADPCM reference source */
  57. /* This is the index table: */
  58. static const int index_table[16] = {
  59. -1, -1, -1, -1, 2, 4, 6, 8,
  60. -1, -1, -1, -1, 2, 4, 6, 8,
  61. };
  62. /**
  63. * This is the step table. Note that many programs use slight deviations from
  64. * this table, but such deviations are negligible:
  65. */
  66. static const int step_table[89] = {
  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. /* These are for MS-ADPCM */
  78. /* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */
  79. static const int AdaptationTable[] = {
  80. 230, 230, 230, 230, 307, 409, 512, 614,
  81. 768, 614, 512, 409, 307, 230, 230, 230
  82. };
  83. /** Divided by 4 to fit in 8-bit integers */
  84. static const uint8_t AdaptCoeff1[] = {
  85. 64, 128, 0, 48, 60, 115, 98
  86. };
  87. /** Divided by 4 to fit in 8-bit integers */
  88. static const int8_t AdaptCoeff2[] = {
  89. 0, -64, 0, 16, 0, -52, -58
  90. };
  91. /* These are for CD-ROM XA ADPCM */
  92. static const int xa_adpcm_table[5][2] = {
  93. { 0, 0 },
  94. { 60, 0 },
  95. { 115, -52 },
  96. { 98, -55 },
  97. { 122, -60 }
  98. };
  99. static const int ea_adpcm_table[] = {
  100. 0, 240, 460, 392, 0, 0, -208, -220, 0, 1,
  101. 3, 4, 7, 8, 10, 11, 0, -1, -3, -4
  102. };
  103. // padded to zero where table size is less then 16
  104. static const int swf_index_tables[4][16] = {
  105. /*2*/ { -1, 2 },
  106. /*3*/ { -1, -1, 2, 4 },
  107. /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
  108. /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
  109. };
  110. static const int yamaha_indexscale[] = {
  111. 230, 230, 230, 230, 307, 409, 512, 614,
  112. 230, 230, 230, 230, 307, 409, 512, 614
  113. };
  114. static const int yamaha_difflookup[] = {
  115. 1, 3, 5, 7, 9, 11, 13, 15,
  116. -1, -3, -5, -7, -9, -11, -13, -15
  117. };
  118. /* end of tables */
  119. typedef struct ADPCMChannelStatus {
  120. int predictor;
  121. short int step_index;
  122. int step;
  123. /* for encoding */
  124. int prev_sample;
  125. /* MS version */
  126. short sample1;
  127. short sample2;
  128. int coeff1;
  129. int coeff2;
  130. int idelta;
  131. } ADPCMChannelStatus;
  132. typedef struct TrellisPath {
  133. int nibble;
  134. int prev;
  135. } TrellisPath;
  136. typedef struct TrellisNode {
  137. uint32_t ssd;
  138. int path;
  139. int sample1;
  140. int sample2;
  141. int step;
  142. } TrellisNode;
  143. typedef struct ADPCMContext {
  144. ADPCMChannelStatus status[6];
  145. TrellisPath *paths;
  146. TrellisNode *node_buf;
  147. TrellisNode **nodep_buf;
  148. } ADPCMContext;
  149. #define FREEZE_INTERVAL 128
  150. /* XXX: implement encoding */
  151. #if CONFIG_ENCODERS
  152. static av_cold int adpcm_encode_init(AVCodecContext *avctx)
  153. {
  154. ADPCMContext *s = avctx->priv_data;
  155. uint8_t *extradata;
  156. int i;
  157. if (avctx->channels > 2)
  158. return -1; /* only stereo or mono =) */
  159. if(avctx->trellis && (unsigned)avctx->trellis > 16U){
  160. av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n");
  161. return -1;
  162. }
  163. if (avctx->trellis) {
  164. int frontier = 1 << avctx->trellis;
  165. int max_paths = frontier * FREEZE_INTERVAL;
  166. FF_ALLOC_OR_GOTO(avctx, s->paths, max_paths * sizeof(*s->paths), error);
  167. FF_ALLOC_OR_GOTO(avctx, s->node_buf, 2 * frontier * sizeof(*s->node_buf), error);
  168. FF_ALLOC_OR_GOTO(avctx, s->nodep_buf, 2 * frontier * sizeof(*s->nodep_buf), error);
  169. }
  170. switch(avctx->codec->id) {
  171. case CODEC_ID_ADPCM_IMA_WAV:
  172. avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */
  173. /* and we have 4 bytes per channel overhead */
  174. avctx->block_align = BLKSIZE;
  175. /* seems frame_size isn't taken into account... have to buffer the samples :-( */
  176. break;
  177. case CODEC_ID_ADPCM_IMA_QT:
  178. avctx->frame_size = 64;
  179. avctx->block_align = 34 * avctx->channels;
  180. break;
  181. case CODEC_ID_ADPCM_MS:
  182. avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
  183. /* and we have 7 bytes per channel overhead */
  184. avctx->block_align = BLKSIZE;
  185. avctx->extradata_size = 32;
  186. extradata = avctx->extradata = av_malloc(avctx->extradata_size);
  187. if (!extradata)
  188. return AVERROR(ENOMEM);
  189. bytestream_put_le16(&extradata, avctx->frame_size);
  190. bytestream_put_le16(&extradata, 7); /* wNumCoef */
  191. for (i = 0; i < 7; i++) {
  192. bytestream_put_le16(&extradata, AdaptCoeff1[i] * 4);
  193. bytestream_put_le16(&extradata, AdaptCoeff2[i] * 4);
  194. }
  195. break;
  196. case CODEC_ID_ADPCM_YAMAHA:
  197. avctx->frame_size = BLKSIZE * avctx->channels;
  198. avctx->block_align = BLKSIZE;
  199. break;
  200. case CODEC_ID_ADPCM_SWF:
  201. if (avctx->sample_rate != 11025 &&
  202. avctx->sample_rate != 22050 &&
  203. avctx->sample_rate != 44100) {
  204. av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, 22050 or 44100\n");
  205. goto error;
  206. }
  207. avctx->frame_size = 512 * (avctx->sample_rate / 11025);
  208. break;
  209. default:
  210. goto error;
  211. }
  212. avctx->coded_frame= avcodec_alloc_frame();
  213. avctx->coded_frame->key_frame= 1;
  214. return 0;
  215. error:
  216. av_freep(&s->paths);
  217. av_freep(&s->node_buf);
  218. av_freep(&s->nodep_buf);
  219. return -1;
  220. }
  221. static av_cold int adpcm_encode_close(AVCodecContext *avctx)
  222. {
  223. ADPCMContext *s = avctx->priv_data;
  224. av_freep(&avctx->coded_frame);
  225. av_freep(&s->paths);
  226. av_freep(&s->node_buf);
  227. av_freep(&s->nodep_buf);
  228. return 0;
  229. }
  230. static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample)
  231. {
  232. int delta = sample - c->prev_sample;
  233. int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8;
  234. c->prev_sample += ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8);
  235. c->prev_sample = av_clip_int16(c->prev_sample);
  236. c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88);
  237. return nibble;
  238. }
  239. static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample)
  240. {
  241. int predictor, nibble, bias;
  242. predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
  243. nibble= sample - predictor;
  244. if(nibble>=0) bias= c->idelta/2;
  245. else bias=-c->idelta/2;
  246. nibble= (nibble + bias) / c->idelta;
  247. nibble= av_clip(nibble, -8, 7)&0x0F;
  248. predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
  249. c->sample2 = c->sample1;
  250. c->sample1 = av_clip_int16(predictor);
  251. c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
  252. if (c->idelta < 16) c->idelta = 16;
  253. return nibble;
  254. }
  255. static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample)
  256. {
  257. int nibble, delta;
  258. if(!c->step) {
  259. c->predictor = 0;
  260. c->step = 127;
  261. }
  262. delta = sample - c->predictor;
  263. nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8;
  264. c->predictor += ((c->step * yamaha_difflookup[nibble]) / 8);
  265. c->predictor = av_clip_int16(c->predictor);
  266. c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
  267. c->step = av_clip(c->step, 127, 24567);
  268. return nibble;
  269. }
  270. static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
  271. uint8_t *dst, ADPCMChannelStatus *c, int n)
  272. {
  273. //FIXME 6% faster if frontier is a compile-time constant
  274. ADPCMContext *s = avctx->priv_data;
  275. const int frontier = 1 << avctx->trellis;
  276. const int stride = avctx->channels;
  277. const int version = avctx->codec->id;
  278. TrellisPath *paths = s->paths, *p;
  279. TrellisNode *node_buf = s->node_buf;
  280. TrellisNode **nodep_buf = s->nodep_buf;
  281. TrellisNode **nodes = nodep_buf; // nodes[] is always sorted by .ssd
  282. TrellisNode **nodes_next = nodep_buf + frontier;
  283. int pathn = 0, froze = -1, i, j, k;
  284. memset(nodep_buf, 0, 2 * frontier * sizeof(*nodep_buf));
  285. nodes[0] = node_buf + frontier;
  286. nodes[0]->ssd = 0;
  287. nodes[0]->path = 0;
  288. nodes[0]->step = c->step_index;
  289. nodes[0]->sample1 = c->sample1;
  290. nodes[0]->sample2 = c->sample2;
  291. if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_IMA_QT) || (version == CODEC_ID_ADPCM_SWF))
  292. nodes[0]->sample1 = c->prev_sample;
  293. if(version == CODEC_ID_ADPCM_MS)
  294. nodes[0]->step = c->idelta;
  295. if(version == CODEC_ID_ADPCM_YAMAHA) {
  296. if(c->step == 0) {
  297. nodes[0]->step = 127;
  298. nodes[0]->sample1 = 0;
  299. } else {
  300. nodes[0]->step = c->step;
  301. nodes[0]->sample1 = c->predictor;
  302. }
  303. }
  304. for(i=0; i<n; i++) {
  305. TrellisNode *t = node_buf + frontier*(i&1);
  306. TrellisNode **u;
  307. int sample = samples[i*stride];
  308. memset(nodes_next, 0, frontier*sizeof(TrellisNode*));
  309. for(j=0; j<frontier && nodes[j]; j++) {
  310. // higher j have higher ssd already, so they're unlikely to use a suboptimal next sample too
  311. const int range = (j < frontier/2) ? 1 : 0;
  312. const int step = nodes[j]->step;
  313. int nidx;
  314. if(version == CODEC_ID_ADPCM_MS) {
  315. const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 64;
  316. const int div = (sample - predictor) / step;
  317. const int nmin = av_clip(div-range, -8, 6);
  318. const int nmax = av_clip(div+range, -7, 7);
  319. for(nidx=nmin; nidx<=nmax; nidx++) {
  320. const int nibble = nidx & 0xf;
  321. int dec_sample = predictor + nidx * step;
  322. #define STORE_NODE(NAME, STEP_INDEX)\
  323. int d;\
  324. uint32_t ssd;\
  325. dec_sample = av_clip_int16(dec_sample);\
  326. d = sample - dec_sample;\
  327. ssd = nodes[j]->ssd + d*d;\
  328. if(nodes_next[frontier-1] && ssd >= nodes_next[frontier-1]->ssd)\
  329. continue;\
  330. /* Collapse any two states with the same previous sample value. \
  331. * One could also distinguish states by step and by 2nd to last
  332. * sample, but the effects of that are negligible. */\
  333. for(k=0; k<frontier && nodes_next[k]; k++) {\
  334. if(dec_sample == nodes_next[k]->sample1) {\
  335. assert(ssd >= nodes_next[k]->ssd);\
  336. goto next_##NAME;\
  337. }\
  338. }\
  339. for(k=0; k<frontier; k++) {\
  340. if(!nodes_next[k] || ssd < nodes_next[k]->ssd) {\
  341. TrellisNode *u = nodes_next[frontier-1];\
  342. if(!u) {\
  343. assert(pathn < FREEZE_INTERVAL<<avctx->trellis);\
  344. u = t++;\
  345. u->path = pathn++;\
  346. }\
  347. u->ssd = ssd;\
  348. u->step = STEP_INDEX;\
  349. u->sample2 = nodes[j]->sample1;\
  350. u->sample1 = dec_sample;\
  351. paths[u->path].nibble = nibble;\
  352. paths[u->path].prev = nodes[j]->path;\
  353. memmove(&nodes_next[k+1], &nodes_next[k], (frontier-k-1)*sizeof(TrellisNode*));\
  354. nodes_next[k] = u;\
  355. break;\
  356. }\
  357. }\
  358. next_##NAME:;
  359. STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8));
  360. }
  361. } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_IMA_QT)|| (version == CODEC_ID_ADPCM_SWF)) {
  362. #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
  363. const int predictor = nodes[j]->sample1;\
  364. const int div = (sample - predictor) * 4 / STEP_TABLE;\
  365. int nmin = av_clip(div-range, -7, 6);\
  366. int nmax = av_clip(div+range, -6, 7);\
  367. if(nmin<=0) nmin--; /* distinguish -0 from +0 */\
  368. if(nmax<0) nmax--;\
  369. for(nidx=nmin; nidx<=nmax; nidx++) {\
  370. const int nibble = nidx<0 ? 7-nidx : nidx;\
  371. int dec_sample = predictor + (STEP_TABLE * yamaha_difflookup[nibble]) / 8;\
  372. STORE_NODE(NAME, STEP_INDEX);\
  373. }
  374. LOOP_NODES(ima, step_table[step], av_clip(step + index_table[nibble], 0, 88));
  375. } else { //CODEC_ID_ADPCM_YAMAHA
  376. LOOP_NODES(yamaha, step, av_clip((step * yamaha_indexscale[nibble]) >> 8, 127, 24567));
  377. #undef LOOP_NODES
  378. #undef STORE_NODE
  379. }
  380. }
  381. u = nodes;
  382. nodes = nodes_next;
  383. nodes_next = u;
  384. // prevent overflow
  385. if(nodes[0]->ssd > (1<<28)) {
  386. for(j=1; j<frontier && nodes[j]; j++)
  387. nodes[j]->ssd -= nodes[0]->ssd;
  388. nodes[0]->ssd = 0;
  389. }
  390. // merge old paths to save memory
  391. if(i == froze + FREEZE_INTERVAL) {
  392. p = &paths[nodes[0]->path];
  393. for(k=i; k>froze; k--) {
  394. dst[k] = p->nibble;
  395. p = &paths[p->prev];
  396. }
  397. froze = i;
  398. pathn = 0;
  399. // other nodes might use paths that don't coincide with the frozen one.
  400. // checking which nodes do so is too slow, so just kill them all.
  401. // this also slightly improves quality, but I don't know why.
  402. memset(nodes+1, 0, (frontier-1)*sizeof(TrellisNode*));
  403. }
  404. }
  405. p = &paths[nodes[0]->path];
  406. for(i=n-1; i>froze; i--) {
  407. dst[i] = p->nibble;
  408. p = &paths[p->prev];
  409. }
  410. c->predictor = nodes[0]->sample1;
  411. c->sample1 = nodes[0]->sample1;
  412. c->sample2 = nodes[0]->sample2;
  413. c->step_index = nodes[0]->step;
  414. c->step = nodes[0]->step;
  415. c->idelta = nodes[0]->step;
  416. }
  417. static int adpcm_encode_frame(AVCodecContext *avctx,
  418. unsigned char *frame, int buf_size, void *data)
  419. {
  420. int n, i, st;
  421. short *samples;
  422. unsigned char *dst;
  423. ADPCMContext *c = avctx->priv_data;
  424. uint8_t *buf;
  425. dst = frame;
  426. samples = (short *)data;
  427. st= avctx->channels == 2;
  428. /* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
  429. switch(avctx->codec->id) {
  430. case CODEC_ID_ADPCM_IMA_WAV:
  431. n = avctx->frame_size / 8;
  432. c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
  433. /* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
  434. bytestream_put_le16(&dst, c->status[0].prev_sample);
  435. *dst++ = (unsigned char)c->status[0].step_index;
  436. *dst++ = 0; /* unknown */
  437. samples++;
  438. if (avctx->channels == 2) {
  439. c->status[1].prev_sample = (signed short)samples[0];
  440. /* c->status[1].step_index = 0; */
  441. bytestream_put_le16(&dst, c->status[1].prev_sample);
  442. *dst++ = (unsigned char)c->status[1].step_index;
  443. *dst++ = 0;
  444. samples++;
  445. }
  446. /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
  447. if(avctx->trellis > 0) {
  448. FF_ALLOC_OR_GOTO(avctx, buf, 2*n*8, error);
  449. adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n*8);
  450. if(avctx->channels == 2)
  451. adpcm_compress_trellis(avctx, samples+1, buf + n*8, &c->status[1], n*8);
  452. for(i=0; i<n; i++) {
  453. *dst++ = buf[8*i+0] | (buf[8*i+1] << 4);
  454. *dst++ = buf[8*i+2] | (buf[8*i+3] << 4);
  455. *dst++ = buf[8*i+4] | (buf[8*i+5] << 4);
  456. *dst++ = buf[8*i+6] | (buf[8*i+7] << 4);
  457. if (avctx->channels == 2) {
  458. uint8_t *buf1 = buf + n*8;
  459. *dst++ = buf1[8*i+0] | (buf1[8*i+1] << 4);
  460. *dst++ = buf1[8*i+2] | (buf1[8*i+3] << 4);
  461. *dst++ = buf1[8*i+4] | (buf1[8*i+5] << 4);
  462. *dst++ = buf1[8*i+6] | (buf1[8*i+7] << 4);
  463. }
  464. }
  465. av_free(buf);
  466. } else
  467. for (; n>0; n--) {
  468. *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]);
  469. *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4;
  470. dst++;
  471. *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]);
  472. *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4;
  473. dst++;
  474. *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]);
  475. *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4;
  476. dst++;
  477. *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]);
  478. *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4;
  479. dst++;
  480. /* right channel */
  481. if (avctx->channels == 2) {
  482. *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
  483. *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
  484. dst++;
  485. *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
  486. *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
  487. dst++;
  488. *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
  489. *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
  490. dst++;
  491. *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
  492. *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
  493. dst++;
  494. }
  495. samples += 8 * avctx->channels;
  496. }
  497. break;
  498. case CODEC_ID_ADPCM_IMA_QT:
  499. {
  500. int ch, i;
  501. PutBitContext pb;
  502. init_put_bits(&pb, dst, buf_size*8);
  503. for(ch=0; ch<avctx->channels; ch++){
  504. put_bits(&pb, 9, (c->status[ch].prev_sample + 0x10000) >> 7);
  505. put_bits(&pb, 7, c->status[ch].step_index);
  506. if(avctx->trellis > 0) {
  507. uint8_t buf[64];
  508. adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64);
  509. for(i=0; i<64; i++)
  510. put_bits(&pb, 4, buf[i^1]);
  511. c->status[ch].prev_sample = c->status[ch].predictor & ~0x7F;
  512. } else {
  513. for (i=0; i<64; i+=2){
  514. int t1, t2;
  515. t1 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]);
  516. t2 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]);
  517. put_bits(&pb, 4, t2);
  518. put_bits(&pb, 4, t1);
  519. }
  520. c->status[ch].prev_sample &= ~0x7F;
  521. }
  522. }
  523. flush_put_bits(&pb);
  524. dst += put_bits_count(&pb)>>3;
  525. break;
  526. }
  527. case CODEC_ID_ADPCM_SWF:
  528. {
  529. int i;
  530. PutBitContext pb;
  531. init_put_bits(&pb, dst, buf_size*8);
  532. n = avctx->frame_size-1;
  533. //Store AdpcmCodeSize
  534. put_bits(&pb, 2, 2); //Set 4bits flash adpcm format
  535. //Init the encoder state
  536. for(i=0; i<avctx->channels; i++){
  537. c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); // clip step so it fits 6 bits
  538. put_sbits(&pb, 16, samples[i]);
  539. put_bits(&pb, 6, c->status[i].step_index);
  540. c->status[i].prev_sample = (signed short)samples[i];
  541. }
  542. if(avctx->trellis > 0) {
  543. FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error);
  544. adpcm_compress_trellis(avctx, samples+2, buf, &c->status[0], n);
  545. if (avctx->channels == 2)
  546. adpcm_compress_trellis(avctx, samples+3, buf+n, &c->status[1], n);
  547. for(i=0; i<n; i++) {
  548. put_bits(&pb, 4, buf[i]);
  549. if (avctx->channels == 2)
  550. put_bits(&pb, 4, buf[n+i]);
  551. }
  552. av_free(buf);
  553. } else {
  554. for (i=1; i<avctx->frame_size; i++) {
  555. put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i]));
  556. if (avctx->channels == 2)
  557. put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1]));
  558. }
  559. }
  560. flush_put_bits(&pb);
  561. dst += put_bits_count(&pb)>>3;
  562. break;
  563. }
  564. case CODEC_ID_ADPCM_MS:
  565. for(i=0; i<avctx->channels; i++){
  566. int predictor=0;
  567. *dst++ = predictor;
  568. c->status[i].coeff1 = AdaptCoeff1[predictor];
  569. c->status[i].coeff2 = AdaptCoeff2[predictor];
  570. }
  571. for(i=0; i<avctx->channels; i++){
  572. if (c->status[i].idelta < 16)
  573. c->status[i].idelta = 16;
  574. bytestream_put_le16(&dst, c->status[i].idelta);
  575. }
  576. for(i=0; i<avctx->channels; i++){
  577. c->status[i].sample2= *samples++;
  578. }
  579. for(i=0; i<avctx->channels; i++){
  580. c->status[i].sample1= *samples++;
  581. bytestream_put_le16(&dst, c->status[i].sample1);
  582. }
  583. for(i=0; i<avctx->channels; i++)
  584. bytestream_put_le16(&dst, c->status[i].sample2);
  585. if(avctx->trellis > 0) {
  586. int n = avctx->block_align - 7*avctx->channels;
  587. FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error);
  588. if(avctx->channels == 1) {
  589. adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
  590. for(i=0; i<n; i+=2)
  591. *dst++ = (buf[i] << 4) | buf[i+1];
  592. } else {
  593. adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
  594. adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n);
  595. for(i=0; i<n; i++)
  596. *dst++ = (buf[i] << 4) | buf[n+i];
  597. }
  598. av_free(buf);
  599. } else
  600. for(i=7*avctx->channels; i<avctx->block_align; i++) {
  601. int nibble;
  602. nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4;
  603. nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++);
  604. *dst++ = nibble;
  605. }
  606. break;
  607. case CODEC_ID_ADPCM_YAMAHA:
  608. n = avctx->frame_size / 2;
  609. if(avctx->trellis > 0) {
  610. FF_ALLOC_OR_GOTO(avctx, buf, 2*n*2, error);
  611. n *= 2;
  612. if(avctx->channels == 1) {
  613. adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
  614. for(i=0; i<n; i+=2)
  615. *dst++ = buf[i] | (buf[i+1] << 4);
  616. } else {
  617. adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n);
  618. adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n);
  619. for(i=0; i<n; i++)
  620. *dst++ = buf[i] | (buf[n+i] << 4);
  621. }
  622. av_free(buf);
  623. } else
  624. for (n *= avctx->channels; n>0; n--) {
  625. int nibble;
  626. nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++);
  627. nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4;
  628. *dst++ = nibble;
  629. }
  630. break;
  631. default:
  632. error:
  633. return -1;
  634. }
  635. return dst - frame;
  636. }
  637. #endif //CONFIG_ENCODERS
  638. static av_cold int adpcm_decode_init(AVCodecContext * avctx)
  639. {
  640. ADPCMContext *c = avctx->priv_data;
  641. unsigned int max_channels = 2;
  642. switch(avctx->codec->id) {
  643. case CODEC_ID_ADPCM_EA_R1:
  644. case CODEC_ID_ADPCM_EA_R2:
  645. case CODEC_ID_ADPCM_EA_R3:
  646. max_channels = 6;
  647. break;
  648. }
  649. if(avctx->channels > max_channels){
  650. return -1;
  651. }
  652. switch(avctx->codec->id) {
  653. case CODEC_ID_ADPCM_CT:
  654. c->status[0].step = c->status[1].step = 511;
  655. break;
  656. case CODEC_ID_ADPCM_IMA_WAV:
  657. if (avctx->bits_per_coded_sample != 4) {
  658. av_log(avctx, AV_LOG_ERROR, "Only 4-bit ADPCM IMA WAV files are supported\n");
  659. return -1;
  660. }
  661. break;
  662. case CODEC_ID_ADPCM_IMA_WS:
  663. if (avctx->extradata && avctx->extradata_size == 2 * 4) {
  664. c->status[0].predictor = AV_RL32(avctx->extradata);
  665. c->status[1].predictor = AV_RL32(avctx->extradata + 4);
  666. }
  667. break;
  668. default:
  669. break;
  670. }
  671. avctx->sample_fmt = SAMPLE_FMT_S16;
  672. return 0;
  673. }
  674. static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
  675. {
  676. int step_index;
  677. int predictor;
  678. int sign, delta, diff, step;
  679. step = step_table[c->step_index];
  680. step_index = c->step_index + index_table[(unsigned)nibble];
  681. if (step_index < 0) step_index = 0;
  682. else if (step_index > 88) step_index = 88;
  683. sign = nibble & 8;
  684. delta = nibble & 7;
  685. /* perform direct multiplication instead of series of jumps proposed by
  686. * the reference ADPCM implementation since modern CPUs can do the mults
  687. * quickly enough */
  688. diff = ((2 * delta + 1) * step) >> shift;
  689. predictor = c->predictor;
  690. if (sign) predictor -= diff;
  691. else predictor += diff;
  692. c->predictor = av_clip_int16(predictor);
  693. c->step_index = step_index;
  694. return (short)c->predictor;
  695. }
  696. static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
  697. {
  698. int predictor;
  699. predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
  700. predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
  701. c->sample2 = c->sample1;
  702. c->sample1 = av_clip_int16(predictor);
  703. c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8;
  704. if (c->idelta < 16) c->idelta = 16;
  705. return c->sample1;
  706. }
  707. static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
  708. {
  709. int sign, delta, diff;
  710. int new_step;
  711. sign = nibble & 8;
  712. delta = nibble & 7;
  713. /* perform direct multiplication instead of series of jumps proposed by
  714. * the reference ADPCM implementation since modern CPUs can do the mults
  715. * quickly enough */
  716. diff = ((2 * delta + 1) * c->step) >> 3;
  717. /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
  718. c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
  719. c->predictor = av_clip_int16(c->predictor);
  720. /* calculate new step and clamp it to range 511..32767 */
  721. new_step = (AdaptationTable[nibble & 7] * c->step) >> 8;
  722. c->step = av_clip(new_step, 511, 32767);
  723. return (short)c->predictor;
  724. }
  725. static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
  726. {
  727. int sign, delta, diff;
  728. sign = nibble & (1<<(size-1));
  729. delta = nibble & ((1<<(size-1))-1);
  730. diff = delta << (7 + c->step + shift);
  731. /* clamp result */
  732. c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
  733. /* calculate new step */
  734. if (delta >= (2*size - 3) && c->step < 3)
  735. c->step++;
  736. else if (delta == 0 && c->step > 0)
  737. c->step--;
  738. return (short) c->predictor;
  739. }
  740. static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
  741. {
  742. if(!c->step) {
  743. c->predictor = 0;
  744. c->step = 127;
  745. }
  746. c->predictor += (c->step * yamaha_difflookup[nibble]) / 8;
  747. c->predictor = av_clip_int16(c->predictor);
  748. c->step = (c->step * yamaha_indexscale[nibble]) >> 8;
  749. c->step = av_clip(c->step, 127, 24567);
  750. return c->predictor;
  751. }
  752. static void xa_decode(short *out, const unsigned char *in,
  753. ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc)
  754. {
  755. int i, j;
  756. int shift,filter,f0,f1;
  757. int s_1,s_2;
  758. int d,s,t;
  759. for(i=0;i<4;i++) {
  760. shift = 12 - (in[4+i*2] & 15);
  761. filter = in[4+i*2] >> 4;
  762. f0 = xa_adpcm_table[filter][0];
  763. f1 = xa_adpcm_table[filter][1];
  764. s_1 = left->sample1;
  765. s_2 = left->sample2;
  766. for(j=0;j<28;j++) {
  767. d = in[16+i+j*4];
  768. t = (signed char)(d<<4)>>4;
  769. s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
  770. s_2 = s_1;
  771. s_1 = av_clip_int16(s);
  772. *out = s_1;
  773. out += inc;
  774. }
  775. if (inc==2) { /* stereo */
  776. left->sample1 = s_1;
  777. left->sample2 = s_2;
  778. s_1 = right->sample1;
  779. s_2 = right->sample2;
  780. out = out + 1 - 28*2;
  781. }
  782. shift = 12 - (in[5+i*2] & 15);
  783. filter = in[5+i*2] >> 4;
  784. f0 = xa_adpcm_table[filter][0];
  785. f1 = xa_adpcm_table[filter][1];
  786. for(j=0;j<28;j++) {
  787. d = in[16+i+j*4];
  788. t = (signed char)d >> 4;
  789. s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
  790. s_2 = s_1;
  791. s_1 = av_clip_int16(s);
  792. *out = s_1;
  793. out += inc;
  794. }
  795. if (inc==2) { /* stereo */
  796. right->sample1 = s_1;
  797. right->sample2 = s_2;
  798. out -= 1;
  799. } else {
  800. left->sample1 = s_1;
  801. left->sample2 = s_2;
  802. }
  803. }
  804. }
  805. /* DK3 ADPCM support macro */
  806. #define DK3_GET_NEXT_NIBBLE() \
  807. if (decode_top_nibble_next) \
  808. { \
  809. nibble = last_byte >> 4; \
  810. decode_top_nibble_next = 0; \
  811. } \
  812. else \
  813. { \
  814. last_byte = *src++; \
  815. if (src >= buf + buf_size) break; \
  816. nibble = last_byte & 0x0F; \
  817. decode_top_nibble_next = 1; \
  818. }
  819. static int adpcm_decode_frame(AVCodecContext *avctx,
  820. void *data, int *data_size,
  821. AVPacket *avpkt)
  822. {
  823. const uint8_t *buf = avpkt->data;
  824. int buf_size = avpkt->size;
  825. ADPCMContext *c = avctx->priv_data;
  826. ADPCMChannelStatus *cs;
  827. int n, m, channel, i;
  828. int block_predictor[2];
  829. short *samples;
  830. short *samples_end;
  831. const uint8_t *src;
  832. int st; /* stereo */
  833. /* DK3 ADPCM accounting variables */
  834. unsigned char last_byte = 0;
  835. unsigned char nibble;
  836. int decode_top_nibble_next = 0;
  837. int diff_channel;
  838. /* EA ADPCM state variables */
  839. uint32_t samples_in_chunk;
  840. int32_t previous_left_sample, previous_right_sample;
  841. int32_t current_left_sample, current_right_sample;
  842. int32_t next_left_sample, next_right_sample;
  843. int32_t coeff1l, coeff2l, coeff1r, coeff2r;
  844. uint8_t shift_left, shift_right;
  845. int count1, count2;
  846. int coeff[2][2], shift[2];//used in EA MAXIS ADPCM
  847. if (!buf_size)
  848. return 0;
  849. //should protect all 4bit ADPCM variants
  850. //8 is needed for CODEC_ID_ADPCM_IMA_WAV with 2 channels
  851. //
  852. if(*data_size/4 < buf_size + 8)
  853. return -1;
  854. samples = data;
  855. samples_end= samples + *data_size/2;
  856. *data_size= 0;
  857. src = buf;
  858. st = avctx->channels == 2 ? 1 : 0;
  859. switch(avctx->codec->id) {
  860. case CODEC_ID_ADPCM_IMA_QT:
  861. n = buf_size - 2*avctx->channels;
  862. for (channel = 0; channel < avctx->channels; channel++) {
  863. cs = &(c->status[channel]);
  864. /* (pppppp) (piiiiiii) */
  865. /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
  866. cs->predictor = (*src++) << 8;
  867. cs->predictor |= (*src & 0x80);
  868. cs->predictor &= 0xFF80;
  869. /* sign extension */
  870. if(cs->predictor & 0x8000)
  871. cs->predictor -= 0x10000;
  872. cs->predictor = av_clip_int16(cs->predictor);
  873. cs->step_index = (*src++) & 0x7F;
  874. if (cs->step_index > 88){
  875. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
  876. cs->step_index = 88;
  877. }
  878. cs->step = step_table[cs->step_index];
  879. samples = (short*)data + channel;
  880. for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
  881. *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3);
  882. samples += avctx->channels;
  883. *samples = adpcm_ima_expand_nibble(cs, src[0] >> 4 , 3);
  884. samples += avctx->channels;
  885. src ++;
  886. }
  887. }
  888. if (st)
  889. samples--;
  890. break;
  891. case CODEC_ID_ADPCM_IMA_WAV:
  892. if (avctx->block_align != 0 && buf_size > avctx->block_align)
  893. buf_size = avctx->block_align;
  894. // samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1;
  895. for(i=0; i<avctx->channels; i++){
  896. cs = &(c->status[i]);
  897. cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src);
  898. cs->step_index = *src++;
  899. if (cs->step_index > 88){
  900. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
  901. cs->step_index = 88;
  902. }
  903. if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */
  904. }
  905. while(src < buf + buf_size){
  906. for(m=0; m<4; m++){
  907. for(i=0; i<=st; i++)
  908. *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3);
  909. for(i=0; i<=st; i++)
  910. *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3);
  911. src++;
  912. }
  913. src += 4*st;
  914. }
  915. break;
  916. case CODEC_ID_ADPCM_4XM:
  917. cs = &(c->status[0]);
  918. c->status[0].predictor= (int16_t)bytestream_get_le16(&src);
  919. if(st){
  920. c->status[1].predictor= (int16_t)bytestream_get_le16(&src);
  921. }
  922. c->status[0].step_index= (int16_t)bytestream_get_le16(&src);
  923. if(st){
  924. c->status[1].step_index= (int16_t)bytestream_get_le16(&src);
  925. }
  926. if (cs->step_index < 0) cs->step_index = 0;
  927. if (cs->step_index > 88) cs->step_index = 88;
  928. m= (buf_size - (src - buf))>>st;
  929. for(i=0; i<m; i++) {
  930. *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] & 0x0F, 4);
  931. if (st)
  932. *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4);
  933. *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4);
  934. if (st)
  935. *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4);
  936. }
  937. src += m<<st;
  938. break;
  939. case CODEC_ID_ADPCM_MS:
  940. if (avctx->block_align != 0 && buf_size > avctx->block_align)
  941. buf_size = avctx->block_align;
  942. n = buf_size - 7 * avctx->channels;
  943. if (n < 0)
  944. return -1;
  945. block_predictor[0] = av_clip(*src++, 0, 6);
  946. block_predictor[1] = 0;
  947. if (st)
  948. block_predictor[1] = av_clip(*src++, 0, 6);
  949. c->status[0].idelta = (int16_t)bytestream_get_le16(&src);
  950. if (st){
  951. c->status[1].idelta = (int16_t)bytestream_get_le16(&src);
  952. }
  953. c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
  954. c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
  955. c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
  956. c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
  957. c->status[0].sample1 = bytestream_get_le16(&src);
  958. if (st) c->status[1].sample1 = bytestream_get_le16(&src);
  959. c->status[0].sample2 = bytestream_get_le16(&src);
  960. if (st) c->status[1].sample2 = bytestream_get_le16(&src);
  961. *samples++ = c->status[0].sample2;
  962. if (st) *samples++ = c->status[1].sample2;
  963. *samples++ = c->status[0].sample1;
  964. if (st) *samples++ = c->status[1].sample1;
  965. for(;n>0;n--) {
  966. *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4 );
  967. *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
  968. src ++;
  969. }
  970. break;
  971. case CODEC_ID_ADPCM_IMA_DK4:
  972. if (avctx->block_align != 0 && buf_size > avctx->block_align)
  973. buf_size = avctx->block_align;
  974. c->status[0].predictor = (int16_t)bytestream_get_le16(&src);
  975. c->status[0].step_index = *src++;
  976. src++;
  977. *samples++ = c->status[0].predictor;
  978. if (st) {
  979. c->status[1].predictor = (int16_t)bytestream_get_le16(&src);
  980. c->status[1].step_index = *src++;
  981. src++;
  982. *samples++ = c->status[1].predictor;
  983. }
  984. while (src < buf + buf_size) {
  985. /* take care of the top nibble (always left or mono channel) */
  986. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  987. src[0] >> 4, 3);
  988. /* take care of the bottom nibble, which is right sample for
  989. * stereo, or another mono sample */
  990. if (st)
  991. *samples++ = adpcm_ima_expand_nibble(&c->status[1],
  992. src[0] & 0x0F, 3);
  993. else
  994. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  995. src[0] & 0x0F, 3);
  996. src++;
  997. }
  998. break;
  999. case CODEC_ID_ADPCM_IMA_DK3:
  1000. if (avctx->block_align != 0 && buf_size > avctx->block_align)
  1001. buf_size = avctx->block_align;
  1002. if(buf_size + 16 > (samples_end - samples)*3/8)
  1003. return -1;
  1004. c->status[0].predictor = (int16_t)AV_RL16(src + 10);
  1005. c->status[1].predictor = (int16_t)AV_RL16(src + 12);
  1006. c->status[0].step_index = src[14];
  1007. c->status[1].step_index = src[15];
  1008. /* sign extend the predictors */
  1009. src += 16;
  1010. diff_channel = c->status[1].predictor;
  1011. /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
  1012. * the buffer is consumed */
  1013. while (1) {
  1014. /* for this algorithm, c->status[0] is the sum channel and
  1015. * c->status[1] is the diff channel */
  1016. /* process the first predictor of the sum channel */
  1017. DK3_GET_NEXT_NIBBLE();
  1018. adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
  1019. /* process the diff channel predictor */
  1020. DK3_GET_NEXT_NIBBLE();
  1021. adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
  1022. /* process the first pair of stereo PCM samples */
  1023. diff_channel = (diff_channel + c->status[1].predictor) / 2;
  1024. *samples++ = c->status[0].predictor + c->status[1].predictor;
  1025. *samples++ = c->status[0].predictor - c->status[1].predictor;
  1026. /* process the second predictor of the sum channel */
  1027. DK3_GET_NEXT_NIBBLE();
  1028. adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
  1029. /* process the second pair of stereo PCM samples */
  1030. diff_channel = (diff_channel + c->status[1].predictor) / 2;
  1031. *samples++ = c->status[0].predictor + c->status[1].predictor;
  1032. *samples++ = c->status[0].predictor - c->status[1].predictor;
  1033. }
  1034. break;
  1035. case CODEC_ID_ADPCM_IMA_ISS:
  1036. c->status[0].predictor = (int16_t)AV_RL16(src + 0);
  1037. c->status[0].step_index = src[2];
  1038. src += 4;
  1039. if(st) {
  1040. c->status[1].predictor = (int16_t)AV_RL16(src + 0);
  1041. c->status[1].step_index = src[2];
  1042. src += 4;
  1043. }
  1044. while (src < buf + buf_size) {
  1045. if (st) {
  1046. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1047. src[0] >> 4 , 3);
  1048. *samples++ = adpcm_ima_expand_nibble(&c->status[1],
  1049. src[0] & 0x0F, 3);
  1050. } else {
  1051. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1052. src[0] & 0x0F, 3);
  1053. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1054. src[0] >> 4 , 3);
  1055. }
  1056. src++;
  1057. }
  1058. break;
  1059. case CODEC_ID_ADPCM_IMA_WS:
  1060. /* no per-block initialization; just start decoding the data */
  1061. while (src < buf + buf_size) {
  1062. if (st) {
  1063. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1064. src[0] >> 4 , 3);
  1065. *samples++ = adpcm_ima_expand_nibble(&c->status[1],
  1066. src[0] & 0x0F, 3);
  1067. } else {
  1068. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1069. src[0] >> 4 , 3);
  1070. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1071. src[0] & 0x0F, 3);
  1072. }
  1073. src++;
  1074. }
  1075. break;
  1076. case CODEC_ID_ADPCM_XA:
  1077. while (buf_size >= 128) {
  1078. xa_decode(samples, src, &c->status[0], &c->status[1],
  1079. avctx->channels);
  1080. src += 128;
  1081. samples += 28 * 8;
  1082. buf_size -= 128;
  1083. }
  1084. break;
  1085. case CODEC_ID_ADPCM_IMA_EA_EACS:
  1086. samples_in_chunk = bytestream_get_le32(&src) >> (1-st);
  1087. if (samples_in_chunk > buf_size-4-(8<<st)) {
  1088. src += buf_size - 4;
  1089. break;
  1090. }
  1091. for (i=0; i<=st; i++)
  1092. c->status[i].step_index = bytestream_get_le32(&src);
  1093. for (i=0; i<=st; i++)
  1094. c->status[i].predictor = bytestream_get_le32(&src);
  1095. for (; samples_in_chunk; samples_in_chunk--, src++) {
  1096. *samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3);
  1097. *samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);
  1098. }
  1099. break;
  1100. case CODEC_ID_ADPCM_IMA_EA_SEAD:
  1101. for (; src < buf+buf_size; src++) {
  1102. *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6);
  1103. *samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6);
  1104. }
  1105. break;
  1106. case CODEC_ID_ADPCM_EA:
  1107. if (buf_size < 4 || AV_RL32(src) >= ((buf_size - 12) * 2)) {
  1108. src += buf_size;
  1109. break;
  1110. }
  1111. samples_in_chunk = AV_RL32(src);
  1112. src += 4;
  1113. current_left_sample = (int16_t)bytestream_get_le16(&src);
  1114. previous_left_sample = (int16_t)bytestream_get_le16(&src);
  1115. current_right_sample = (int16_t)bytestream_get_le16(&src);
  1116. previous_right_sample = (int16_t)bytestream_get_le16(&src);
  1117. for (count1 = 0; count1 < samples_in_chunk/28;count1++) {
  1118. coeff1l = ea_adpcm_table[ *src >> 4 ];
  1119. coeff2l = ea_adpcm_table[(*src >> 4 ) + 4];
  1120. coeff1r = ea_adpcm_table[*src & 0x0F];
  1121. coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
  1122. src++;
  1123. shift_left = (*src >> 4 ) + 8;
  1124. shift_right = (*src & 0x0F) + 8;
  1125. src++;
  1126. for (count2 = 0; count2 < 28; count2++) {
  1127. next_left_sample = (int32_t)((*src & 0xF0) << 24) >> shift_left;
  1128. next_right_sample = (int32_t)((*src & 0x0F) << 28) >> shift_right;
  1129. src++;
  1130. next_left_sample = (next_left_sample +
  1131. (current_left_sample * coeff1l) +
  1132. (previous_left_sample * coeff2l) + 0x80) >> 8;
  1133. next_right_sample = (next_right_sample +
  1134. (current_right_sample * coeff1r) +
  1135. (previous_right_sample * coeff2r) + 0x80) >> 8;
  1136. previous_left_sample = current_left_sample;
  1137. current_left_sample = av_clip_int16(next_left_sample);
  1138. previous_right_sample = current_right_sample;
  1139. current_right_sample = av_clip_int16(next_right_sample);
  1140. *samples++ = (unsigned short)current_left_sample;
  1141. *samples++ = (unsigned short)current_right_sample;
  1142. }
  1143. }
  1144. if (src - buf == buf_size - 2)
  1145. src += 2; // Skip terminating 0x0000
  1146. break;
  1147. case CODEC_ID_ADPCM_EA_MAXIS_XA:
  1148. for(channel = 0; channel < avctx->channels; channel++) {
  1149. for (i=0; i<2; i++)
  1150. coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i];
  1151. shift[channel] = (*src & 0x0F) + 8;
  1152. src++;
  1153. }
  1154. for (count1 = 0; count1 < (buf_size - avctx->channels) / avctx->channels; count1++) {
  1155. for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
  1156. for(channel = 0; channel < avctx->channels; channel++) {
  1157. int32_t sample = (int32_t)(((*(src+channel) >> i) & 0x0F) << 0x1C) >> shift[channel];
  1158. sample = (sample +
  1159. c->status[channel].sample1 * coeff[channel][0] +
  1160. c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
  1161. c->status[channel].sample2 = c->status[channel].sample1;
  1162. c->status[channel].sample1 = av_clip_int16(sample);
  1163. *samples++ = c->status[channel].sample1;
  1164. }
  1165. }
  1166. src+=avctx->channels;
  1167. }
  1168. break;
  1169. case CODEC_ID_ADPCM_EA_R1:
  1170. case CODEC_ID_ADPCM_EA_R2:
  1171. case CODEC_ID_ADPCM_EA_R3: {
  1172. /* channel numbering
  1173. 2chan: 0=fl, 1=fr
  1174. 4chan: 0=fl, 1=rl, 2=fr, 3=rr
  1175. 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
  1176. const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3;
  1177. int32_t previous_sample, current_sample, next_sample;
  1178. int32_t coeff1, coeff2;
  1179. uint8_t shift;
  1180. unsigned int channel;
  1181. uint16_t *samplesC;
  1182. const uint8_t *srcC;
  1183. const uint8_t *src_end = buf + buf_size;
  1184. samples_in_chunk = (big_endian ? bytestream_get_be32(&src)
  1185. : bytestream_get_le32(&src)) / 28;
  1186. if (samples_in_chunk > UINT32_MAX/(28*avctx->channels) ||
  1187. 28*samples_in_chunk*avctx->channels > samples_end-samples) {
  1188. src += buf_size - 4;
  1189. break;
  1190. }
  1191. for (channel=0; channel<avctx->channels; channel++) {
  1192. int32_t offset = (big_endian ? bytestream_get_be32(&src)
  1193. : bytestream_get_le32(&src))
  1194. + (avctx->channels-channel-1) * 4;
  1195. if ((offset < 0) || (offset >= src_end - src - 4)) break;
  1196. srcC = src + offset;
  1197. samplesC = samples + channel;
  1198. if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) {
  1199. current_sample = (int16_t)bytestream_get_le16(&srcC);
  1200. previous_sample = (int16_t)bytestream_get_le16(&srcC);
  1201. } else {
  1202. current_sample = c->status[channel].predictor;
  1203. previous_sample = c->status[channel].prev_sample;
  1204. }
  1205. for (count1=0; count1<samples_in_chunk; count1++) {
  1206. if (*srcC == 0xEE) { /* only seen in R2 and R3 */
  1207. srcC++;
  1208. if (srcC > src_end - 30*2) break;
  1209. current_sample = (int16_t)bytestream_get_be16(&srcC);
  1210. previous_sample = (int16_t)bytestream_get_be16(&srcC);
  1211. for (count2=0; count2<28; count2++) {
  1212. *samplesC = (int16_t)bytestream_get_be16(&srcC);
  1213. samplesC += avctx->channels;
  1214. }
  1215. } else {
  1216. coeff1 = ea_adpcm_table[ *srcC>>4 ];
  1217. coeff2 = ea_adpcm_table[(*srcC>>4) + 4];
  1218. shift = (*srcC++ & 0x0F) + 8;
  1219. if (srcC > src_end - 14) break;
  1220. for (count2=0; count2<28; count2++) {
  1221. if (count2 & 1)
  1222. next_sample = (int32_t)((*srcC++ & 0x0F) << 28) >> shift;
  1223. else
  1224. next_sample = (int32_t)((*srcC & 0xF0) << 24) >> shift;
  1225. next_sample += (current_sample * coeff1) +
  1226. (previous_sample * coeff2);
  1227. next_sample = av_clip_int16(next_sample >> 8);
  1228. previous_sample = current_sample;
  1229. current_sample = next_sample;
  1230. *samplesC = current_sample;
  1231. samplesC += avctx->channels;
  1232. }
  1233. }
  1234. }
  1235. if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) {
  1236. c->status[channel].predictor = current_sample;
  1237. c->status[channel].prev_sample = previous_sample;
  1238. }
  1239. }
  1240. src = src + buf_size - (4 + 4*avctx->channels);
  1241. samples += 28 * samples_in_chunk * avctx->channels;
  1242. break;
  1243. }
  1244. case CODEC_ID_ADPCM_EA_XAS:
  1245. if (samples_end-samples < 32*4*avctx->channels
  1246. || buf_size < (4+15)*4*avctx->channels) {
  1247. src += buf_size;
  1248. break;
  1249. }
  1250. for (channel=0; channel<avctx->channels; channel++) {
  1251. int coeff[2][4], shift[4];
  1252. short *s2, *s = &samples[channel];
  1253. for (n=0; n<4; n++, s+=32*avctx->channels) {
  1254. for (i=0; i<2; i++)
  1255. coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i];
  1256. shift[n] = (src[2]&0x0F) + 8;
  1257. for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels)
  1258. s2[0] = (src[0]&0xF0) + (src[1]<<8);
  1259. }
  1260. for (m=2; m<32; m+=2) {
  1261. s = &samples[m*avctx->channels + channel];
  1262. for (n=0; n<4; n++, src++, s+=32*avctx->channels) {
  1263. for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) {
  1264. int level = (int32_t)((*src & (0xF0>>i)) << (24+i)) >> shift[n];
  1265. int pred = s2[-1*avctx->channels] * coeff[0][n]
  1266. + s2[-2*avctx->channels] * coeff[1][n];
  1267. s2[0] = av_clip_int16((level + pred + 0x80) >> 8);
  1268. }
  1269. }
  1270. }
  1271. }
  1272. samples += 32*4*avctx->channels;
  1273. break;
  1274. case CODEC_ID_ADPCM_IMA_AMV:
  1275. case CODEC_ID_ADPCM_IMA_SMJPEG:
  1276. c->status[0].predictor = (int16_t)bytestream_get_le16(&src);
  1277. c->status[0].step_index = bytestream_get_le16(&src);
  1278. if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
  1279. src+=4;
  1280. while (src < buf + buf_size) {
  1281. char hi, lo;
  1282. lo = *src & 0x0F;
  1283. hi = *src >> 4;
  1284. if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
  1285. FFSWAP(char, hi, lo);
  1286. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1287. lo, 3);
  1288. *samples++ = adpcm_ima_expand_nibble(&c->status[0],
  1289. hi, 3);
  1290. src++;
  1291. }
  1292. break;
  1293. case CODEC_ID_ADPCM_CT:
  1294. while (src < buf + buf_size) {
  1295. if (st) {
  1296. *samples++ = adpcm_ct_expand_nibble(&c->status[0],
  1297. src[0] >> 4);
  1298. *samples++ = adpcm_ct_expand_nibble(&c->status[1],
  1299. src[0] & 0x0F);
  1300. } else {
  1301. *samples++ = adpcm_ct_expand_nibble(&c->status[0],
  1302. src[0] >> 4);
  1303. *samples++ = adpcm_ct_expand_nibble(&c->status[0],
  1304. src[0] & 0x0F);
  1305. }
  1306. src++;
  1307. }
  1308. break;
  1309. case CODEC_ID_ADPCM_SBPRO_4:
  1310. case CODEC_ID_ADPCM_SBPRO_3:
  1311. case CODEC_ID_ADPCM_SBPRO_2:
  1312. if (!c->status[0].step_index) {
  1313. /* the first byte is a raw sample */
  1314. *samples++ = 128 * (*src++ - 0x80);
  1315. if (st)
  1316. *samples++ = 128 * (*src++ - 0x80);
  1317. c->status[0].step_index = 1;
  1318. }
  1319. if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
  1320. while (src < buf + buf_size) {
  1321. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1322. src[0] >> 4, 4, 0);
  1323. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1324. src[0] & 0x0F, 4, 0);
  1325. src++;
  1326. }
  1327. } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
  1328. while (src < buf + buf_size && samples + 2 < samples_end) {
  1329. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1330. src[0] >> 5 , 3, 0);
  1331. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1332. (src[0] >> 2) & 0x07, 3, 0);
  1333. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1334. src[0] & 0x03, 2, 0);
  1335. src++;
  1336. }
  1337. } else {
  1338. while (src < buf + buf_size && samples + 3 < samples_end) {
  1339. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1340. src[0] >> 6 , 2, 2);
  1341. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1342. (src[0] >> 4) & 0x03, 2, 2);
  1343. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1344. (src[0] >> 2) & 0x03, 2, 2);
  1345. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1346. src[0] & 0x03, 2, 2);
  1347. src++;
  1348. }
  1349. }
  1350. break;
  1351. case CODEC_ID_ADPCM_SWF:
  1352. {
  1353. GetBitContext gb;
  1354. const int *table;
  1355. int k0, signmask, nb_bits, count;
  1356. int size = buf_size*8;
  1357. init_get_bits(&gb, buf, size);
  1358. //read bits & initial values
  1359. nb_bits = get_bits(&gb, 2)+2;
  1360. //av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", nb_bits);
  1361. table = swf_index_tables[nb_bits-2];
  1362. k0 = 1 << (nb_bits-2);
  1363. signmask = 1 << (nb_bits-1);
  1364. while (get_bits_count(&gb) <= size - 22*avctx->channels) {
  1365. for (i = 0; i < avctx->channels; i++) {
  1366. *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
  1367. c->status[i].step_index = get_bits(&gb, 6);
  1368. }
  1369. for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
  1370. int i;
  1371. for (i = 0; i < avctx->channels; i++) {
  1372. // similar to IMA adpcm
  1373. int delta = get_bits(&gb, nb_bits);
  1374. int step = step_table[c->status[i].step_index];
  1375. long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
  1376. int k = k0;
  1377. do {
  1378. if (delta & k)
  1379. vpdiff += step;
  1380. step >>= 1;
  1381. k >>= 1;
  1382. } while(k);
  1383. vpdiff += step;
  1384. if (delta & signmask)
  1385. c->status[i].predictor -= vpdiff;
  1386. else
  1387. c->status[i].predictor += vpdiff;
  1388. c->status[i].step_index += table[delta & (~signmask)];
  1389. c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
  1390. c->status[i].predictor = av_clip_int16(c->status[i].predictor);
  1391. *samples++ = c->status[i].predictor;
  1392. if (samples >= samples_end) {
  1393. av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
  1394. return -1;
  1395. }
  1396. }
  1397. }
  1398. }
  1399. src += buf_size;
  1400. break;
  1401. }
  1402. case CODEC_ID_ADPCM_YAMAHA:
  1403. while (src < buf + buf_size) {
  1404. if (st) {
  1405. *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
  1406. src[0] & 0x0F);
  1407. *samples++ = adpcm_yamaha_expand_nibble(&c->status[1],
  1408. src[0] >> 4 );
  1409. } else {
  1410. *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
  1411. src[0] & 0x0F);
  1412. *samples++ = adpcm_yamaha_expand_nibble(&c->status[0],
  1413. src[0] >> 4 );
  1414. }
  1415. src++;
  1416. }
  1417. break;
  1418. case CODEC_ID_ADPCM_THP:
  1419. {
  1420. int table[2][16];
  1421. unsigned int samplecnt;
  1422. int prev[2][2];
  1423. int ch;
  1424. if (buf_size < 80) {
  1425. av_log(avctx, AV_LOG_ERROR, "frame too small\n");
  1426. return -1;
  1427. }
  1428. src+=4;
  1429. samplecnt = bytestream_get_be32(&src);
  1430. for (i = 0; i < 32; i++)
  1431. table[0][i] = (int16_t)bytestream_get_be16(&src);
  1432. /* Initialize the previous sample. */
  1433. for (i = 0; i < 4; i++)
  1434. prev[0][i] = (int16_t)bytestream_get_be16(&src);
  1435. if (samplecnt >= (samples_end - samples) / (st + 1)) {
  1436. av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
  1437. return -1;
  1438. }
  1439. for (ch = 0; ch <= st; ch++) {
  1440. samples = (unsigned short *) data + ch;
  1441. /* Read in every sample for this channel. */
  1442. for (i = 0; i < samplecnt / 14; i++) {
  1443. int index = (*src >> 4) & 7;
  1444. unsigned int exp = 28 - (*src++ & 15);
  1445. int factor1 = table[ch][index * 2];
  1446. int factor2 = table[ch][index * 2 + 1];
  1447. /* Decode 14 samples. */
  1448. for (n = 0; n < 14; n++) {
  1449. int32_t sampledat;
  1450. if(n&1) sampledat= *src++ <<28;
  1451. else sampledat= (*src&0xF0)<<24;
  1452. sampledat = ((prev[ch][0]*factor1
  1453. + prev[ch][1]*factor2) >> 11) + (sampledat>>exp);
  1454. *samples = av_clip_int16(sampledat);
  1455. prev[ch][1] = prev[ch][0];
  1456. prev[ch][0] = *samples++;
  1457. /* In case of stereo, skip one sample, this sample
  1458. is for the other channel. */
  1459. samples += st;
  1460. }
  1461. }
  1462. }
  1463. /* In the previous loop, in case stereo is used, samples is
  1464. increased exactly one time too often. */
  1465. samples -= st;
  1466. break;
  1467. }
  1468. default:
  1469. return -1;
  1470. }
  1471. *data_size = (uint8_t *)samples - (uint8_t *)data;
  1472. return src - buf;
  1473. }
  1474. #if CONFIG_ENCODERS
  1475. #define ADPCM_ENCODER(id,name,long_name_) \
  1476. AVCodec name ## _encoder = { \
  1477. #name, \
  1478. AVMEDIA_TYPE_AUDIO, \
  1479. id, \
  1480. sizeof(ADPCMContext), \
  1481. adpcm_encode_init, \
  1482. adpcm_encode_frame, \
  1483. adpcm_encode_close, \
  1484. NULL, \
  1485. .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, \
  1486. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  1487. };
  1488. #else
  1489. #define ADPCM_ENCODER(id,name,long_name_)
  1490. #endif
  1491. #if CONFIG_DECODERS
  1492. #define ADPCM_DECODER(id,name,long_name_) \
  1493. AVCodec name ## _decoder = { \
  1494. #name, \
  1495. AVMEDIA_TYPE_AUDIO, \
  1496. id, \
  1497. sizeof(ADPCMContext), \
  1498. adpcm_decode_init, \
  1499. NULL, \
  1500. NULL, \
  1501. adpcm_decode_frame, \
  1502. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  1503. };
  1504. #else
  1505. #define ADPCM_DECODER(id,name,long_name_)
  1506. #endif
  1507. #define ADPCM_CODEC(id,name,long_name_) \
  1508. ADPCM_ENCODER(id,name,long_name_) ADPCM_DECODER(id,name,long_name_)
  1509. /* Note: Do not forget to add new entries to the Makefile as well. */
  1510. ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie");
  1511. ADPCM_DECODER(CODEC_ID_ADPCM_CT, adpcm_ct, "ADPCM Creative Technology");
  1512. ADPCM_DECODER(CODEC_ID_ADPCM_EA, adpcm_ea, "ADPCM Electronic Arts");
  1513. ADPCM_DECODER(CODEC_ID_ADPCM_EA_MAXIS_XA, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
  1514. ADPCM_DECODER(CODEC_ID_ADPCM_EA_R1, adpcm_ea_r1, "ADPCM Electronic Arts R1");
  1515. ADPCM_DECODER(CODEC_ID_ADPCM_EA_R2, adpcm_ea_r2, "ADPCM Electronic Arts R2");
  1516. ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3, "ADPCM Electronic Arts R3");
  1517. ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
  1518. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, "ADPCM IMA AMV");
  1519. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
  1520. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
  1521. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
  1522. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
  1523. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
  1524. ADPCM_CODEC (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime");
  1525. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
  1526. ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV");
  1527. ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "ADPCM IMA Westwood");
  1528. ADPCM_CODEC (CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft");
  1529. ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
  1530. ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
  1531. ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
  1532. ADPCM_CODEC (CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash");
  1533. ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "ADPCM Nintendo Gamecube THP");
  1534. ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "ADPCM CDROM XA");
  1535. ADPCM_CODEC (CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha");