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.

1582 lines
61KB

  1. /*
  2. * Copyright (c) 2001-2003 The ffmpeg Project
  3. *
  4. * first version by Francois Revol (revol@free.fr)
  5. * fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
  6. * by Mike Melanson (melanson@pcisys.net)
  7. * CD-ROM XA ADPCM codec by BERO
  8. * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
  9. * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org)
  10. * EA IMA EACS decoder by Peter Ross (pross@xvid.org)
  11. * EA IMA SEAD decoder by Peter Ross (pross@xvid.org)
  12. * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org)
  13. * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com)
  14. * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl)
  15. *
  16. * This file is part of FFmpeg.
  17. *
  18. * FFmpeg is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU Lesser General Public
  20. * License as published by the Free Software Foundation; either
  21. * version 2.1 of the License, or (at your option) any later version.
  22. *
  23. * FFmpeg is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. * Lesser General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Lesser General Public
  29. * License along with FFmpeg; if not, write to the Free Software
  30. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  31. */
  32. #include "avcodec.h"
  33. #include "get_bits.h"
  34. #include "bytestream.h"
  35. #include "adpcm.h"
  36. #include "adpcm_data.h"
  37. #include "internal.h"
  38. /**
  39. * @file
  40. * ADPCM decoders
  41. * Features and limitations:
  42. *
  43. * Reference documents:
  44. * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs
  45. * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead]
  46. * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead]
  47. * http://openquicktime.sourceforge.net/
  48. * XAnim sources (xa_codec.c) http://xanim.polter.net/
  49. * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead]
  50. * SoX source code http://sox.sourceforge.net/
  51. *
  52. * CD-ROM XA:
  53. * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead]
  54. * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead]
  55. * readstr http://www.geocities.co.jp/Playtown/2004/
  56. */
  57. /* These are for CD-ROM XA ADPCM */
  58. static const int xa_adpcm_table[5][2] = {
  59. { 0, 0 },
  60. { 60, 0 },
  61. { 115, -52 },
  62. { 98, -55 },
  63. { 122, -60 }
  64. };
  65. static const int ea_adpcm_table[] = {
  66. 0, 240, 460, 392,
  67. 0, 0, -208, -220,
  68. 0, 1, 3, 4,
  69. 7, 8, 10, 11,
  70. 0, -1, -3, -4
  71. };
  72. // padded to zero where table size is less then 16
  73. static const int swf_index_tables[4][16] = {
  74. /*2*/ { -1, 2 },
  75. /*3*/ { -1, -1, 2, 4 },
  76. /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
  77. /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
  78. };
  79. /* end of tables */
  80. typedef struct ADPCMDecodeContext {
  81. ADPCMChannelStatus status[6];
  82. int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */
  83. } ADPCMDecodeContext;
  84. static av_cold int adpcm_decode_init(AVCodecContext * avctx)
  85. {
  86. ADPCMDecodeContext *c = avctx->priv_data;
  87. unsigned int min_channels = 1;
  88. unsigned int max_channels = 2;
  89. switch(avctx->codec->id) {
  90. case AV_CODEC_ID_ADPCM_DTK:
  91. case AV_CODEC_ID_ADPCM_EA:
  92. min_channels = 2;
  93. break;
  94. case AV_CODEC_ID_ADPCM_AFC:
  95. case AV_CODEC_ID_ADPCM_EA_R1:
  96. case AV_CODEC_ID_ADPCM_EA_R2:
  97. case AV_CODEC_ID_ADPCM_EA_R3:
  98. case AV_CODEC_ID_ADPCM_EA_XAS:
  99. case AV_CODEC_ID_ADPCM_THP:
  100. max_channels = 6;
  101. break;
  102. }
  103. if (avctx->channels < min_channels || avctx->channels > max_channels) {
  104. av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
  105. return AVERROR(EINVAL);
  106. }
  107. switch(avctx->codec->id) {
  108. case AV_CODEC_ID_ADPCM_CT:
  109. c->status[0].step = c->status[1].step = 511;
  110. break;
  111. case AV_CODEC_ID_ADPCM_IMA_WAV:
  112. if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5)
  113. return AVERROR_INVALIDDATA;
  114. break;
  115. case AV_CODEC_ID_ADPCM_IMA_APC:
  116. if (avctx->extradata && avctx->extradata_size >= 8) {
  117. c->status[0].predictor = AV_RL32(avctx->extradata);
  118. c->status[1].predictor = AV_RL32(avctx->extradata + 4);
  119. }
  120. break;
  121. case AV_CODEC_ID_ADPCM_IMA_WS:
  122. if (avctx->extradata && avctx->extradata_size >= 2)
  123. c->vqa_version = AV_RL16(avctx->extradata);
  124. break;
  125. default:
  126. break;
  127. }
  128. switch(avctx->codec->id) {
  129. case AV_CODEC_ID_ADPCM_IMA_QT:
  130. case AV_CODEC_ID_ADPCM_IMA_WAV:
  131. case AV_CODEC_ID_ADPCM_4XM:
  132. case AV_CODEC_ID_ADPCM_XA:
  133. case AV_CODEC_ID_ADPCM_EA_R1:
  134. case AV_CODEC_ID_ADPCM_EA_R2:
  135. case AV_CODEC_ID_ADPCM_EA_R3:
  136. case AV_CODEC_ID_ADPCM_EA_XAS:
  137. case AV_CODEC_ID_ADPCM_THP:
  138. case AV_CODEC_ID_ADPCM_AFC:
  139. case AV_CODEC_ID_ADPCM_DTK:
  140. avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
  141. break;
  142. case AV_CODEC_ID_ADPCM_IMA_WS:
  143. avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P :
  144. AV_SAMPLE_FMT_S16;
  145. break;
  146. default:
  147. avctx->sample_fmt = AV_SAMPLE_FMT_S16;
  148. }
  149. return 0;
  150. }
  151. static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, int shift)
  152. {
  153. int step_index;
  154. int predictor;
  155. int sign, delta, diff, step;
  156. step = ff_adpcm_step_table[c->step_index];
  157. step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
  158. step_index = av_clip(step_index, 0, 88);
  159. sign = nibble & 8;
  160. delta = nibble & 7;
  161. /* perform direct multiplication instead of series of jumps proposed by
  162. * the reference ADPCM implementation since modern CPUs can do the mults
  163. * quickly enough */
  164. diff = ((2 * delta + 1) * step) >> shift;
  165. predictor = c->predictor;
  166. if (sign) predictor -= diff;
  167. else predictor += diff;
  168. c->predictor = av_clip_int16(predictor);
  169. c->step_index = step_index;
  170. return (short)c->predictor;
  171. }
  172. static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
  173. {
  174. int nibble, step_index, predictor, sign, delta, diff, step, shift;
  175. shift = bps - 1;
  176. nibble = get_bits_le(gb, bps),
  177. step = ff_adpcm_step_table[c->step_index];
  178. step_index = c->step_index + ff_adpcm_index_tables[bps - 2][nibble];
  179. step_index = av_clip(step_index, 0, 88);
  180. sign = nibble & (1 << shift);
  181. delta = nibble & ((1 << shift) - 1);
  182. diff = ((2 * delta + 1) * step) >> shift;
  183. predictor = c->predictor;
  184. if (sign) predictor -= diff;
  185. else predictor += diff;
  186. c->predictor = av_clip_int16(predictor);
  187. c->step_index = step_index;
  188. return (int16_t)c->predictor;
  189. }
  190. static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
  191. {
  192. int step_index;
  193. int predictor;
  194. int diff, step;
  195. step = ff_adpcm_step_table[c->step_index];
  196. step_index = c->step_index + ff_adpcm_index_table[nibble];
  197. step_index = av_clip(step_index, 0, 88);
  198. diff = step >> 3;
  199. if (nibble & 4) diff += step;
  200. if (nibble & 2) diff += step >> 1;
  201. if (nibble & 1) diff += step >> 2;
  202. if (nibble & 8)
  203. predictor = c->predictor - diff;
  204. else
  205. predictor = c->predictor + diff;
  206. c->predictor = av_clip_int16(predictor);
  207. c->step_index = step_index;
  208. return c->predictor;
  209. }
  210. static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
  211. {
  212. int predictor;
  213. predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
  214. predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
  215. c->sample2 = c->sample1;
  216. c->sample1 = av_clip_int16(predictor);
  217. c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
  218. if (c->idelta < 16) c->idelta = 16;
  219. return c->sample1;
  220. }
  221. static inline short adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
  222. {
  223. int step_index, predictor, sign, delta, diff, step;
  224. step = ff_adpcm_oki_step_table[c->step_index];
  225. step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
  226. step_index = av_clip(step_index, 0, 48);
  227. sign = nibble & 8;
  228. delta = nibble & 7;
  229. diff = ((2 * delta + 1) * step) >> 3;
  230. predictor = c->predictor;
  231. if (sign) predictor -= diff;
  232. else predictor += diff;
  233. c->predictor = av_clip(predictor, -2048, 2047);
  234. c->step_index = step_index;
  235. return c->predictor << 4;
  236. }
  237. static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
  238. {
  239. int sign, delta, diff;
  240. int new_step;
  241. sign = nibble & 8;
  242. delta = nibble & 7;
  243. /* perform direct multiplication instead of series of jumps proposed by
  244. * the reference ADPCM implementation since modern CPUs can do the mults
  245. * quickly enough */
  246. diff = ((2 * delta + 1) * c->step) >> 3;
  247. /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
  248. c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
  249. c->predictor = av_clip_int16(c->predictor);
  250. /* calculate new step and clamp it to range 511..32767 */
  251. new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
  252. c->step = av_clip(new_step, 511, 32767);
  253. return (short)c->predictor;
  254. }
  255. static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
  256. {
  257. int sign, delta, diff;
  258. sign = nibble & (1<<(size-1));
  259. delta = nibble & ((1<<(size-1))-1);
  260. diff = delta << (7 + c->step + shift);
  261. /* clamp result */
  262. c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
  263. /* calculate new step */
  264. if (delta >= (2*size - 3) && c->step < 3)
  265. c->step++;
  266. else if (delta == 0 && c->step > 0)
  267. c->step--;
  268. return (short) c->predictor;
  269. }
  270. static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
  271. {
  272. if(!c->step) {
  273. c->predictor = 0;
  274. c->step = 127;
  275. }
  276. c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
  277. c->predictor = av_clip_int16(c->predictor);
  278. c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
  279. c->step = av_clip(c->step, 127, 24567);
  280. return c->predictor;
  281. }
  282. static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1,
  283. const uint8_t *in, ADPCMChannelStatus *left,
  284. ADPCMChannelStatus *right, int channels, int sample_offset)
  285. {
  286. int i, j;
  287. int shift,filter,f0,f1;
  288. int s_1,s_2;
  289. int d,s,t;
  290. out0 += sample_offset;
  291. if (channels == 1)
  292. out1 = out0 + 28;
  293. else
  294. out1 += sample_offset;
  295. for(i=0;i<4;i++) {
  296. shift = 12 - (in[4+i*2] & 15);
  297. filter = in[4+i*2] >> 4;
  298. if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
  299. avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
  300. filter=0;
  301. }
  302. f0 = xa_adpcm_table[filter][0];
  303. f1 = xa_adpcm_table[filter][1];
  304. s_1 = left->sample1;
  305. s_2 = left->sample2;
  306. for(j=0;j<28;j++) {
  307. d = in[16+i+j*4];
  308. t = sign_extend(d, 4);
  309. s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
  310. s_2 = s_1;
  311. s_1 = av_clip_int16(s);
  312. out0[j] = s_1;
  313. }
  314. if (channels == 2) {
  315. left->sample1 = s_1;
  316. left->sample2 = s_2;
  317. s_1 = right->sample1;
  318. s_2 = right->sample2;
  319. }
  320. shift = 12 - (in[5+i*2] & 15);
  321. filter = in[5+i*2] >> 4;
  322. if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
  323. avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
  324. filter=0;
  325. }
  326. f0 = xa_adpcm_table[filter][0];
  327. f1 = xa_adpcm_table[filter][1];
  328. for(j=0;j<28;j++) {
  329. d = in[16+i+j*4];
  330. t = sign_extend(d >> 4, 4);
  331. s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
  332. s_2 = s_1;
  333. s_1 = av_clip_int16(s);
  334. out1[j] = s_1;
  335. }
  336. if (channels == 2) {
  337. right->sample1 = s_1;
  338. right->sample2 = s_2;
  339. } else {
  340. left->sample1 = s_1;
  341. left->sample2 = s_2;
  342. }
  343. out0 += 28 * (3 - channels);
  344. out1 += 28 * (3 - channels);
  345. }
  346. return 0;
  347. }
  348. static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
  349. {
  350. ADPCMDecodeContext *c = avctx->priv_data;
  351. GetBitContext gb;
  352. const int *table;
  353. int k0, signmask, nb_bits, count;
  354. int size = buf_size*8;
  355. int i;
  356. init_get_bits(&gb, buf, size);
  357. //read bits & initial values
  358. nb_bits = get_bits(&gb, 2)+2;
  359. table = swf_index_tables[nb_bits-2];
  360. k0 = 1 << (nb_bits-2);
  361. signmask = 1 << (nb_bits-1);
  362. while (get_bits_count(&gb) <= size - 22*avctx->channels) {
  363. for (i = 0; i < avctx->channels; i++) {
  364. *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
  365. c->status[i].step_index = get_bits(&gb, 6);
  366. }
  367. for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
  368. int i;
  369. for (i = 0; i < avctx->channels; i++) {
  370. // similar to IMA adpcm
  371. int delta = get_bits(&gb, nb_bits);
  372. int step = ff_adpcm_step_table[c->status[i].step_index];
  373. long vpdiff = 0; // vpdiff = (delta+0.5)*step/4
  374. int k = k0;
  375. do {
  376. if (delta & k)
  377. vpdiff += step;
  378. step >>= 1;
  379. k >>= 1;
  380. } while(k);
  381. vpdiff += step;
  382. if (delta & signmask)
  383. c->status[i].predictor -= vpdiff;
  384. else
  385. c->status[i].predictor += vpdiff;
  386. c->status[i].step_index += table[delta & (~signmask)];
  387. c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
  388. c->status[i].predictor = av_clip_int16(c->status[i].predictor);
  389. *samples++ = c->status[i].predictor;
  390. }
  391. }
  392. }
  393. }
  394. /**
  395. * Get the number of samples that will be decoded from the packet.
  396. * In one case, this is actually the maximum number of samples possible to
  397. * decode with the given buf_size.
  398. *
  399. * @param[out] coded_samples set to the number of samples as coded in the
  400. * packet, or 0 if the codec does not encode the
  401. * number of samples in each frame.
  402. * @param[out] approx_nb_samples set to non-zero if the number of samples
  403. * returned is an approximation.
  404. */
  405. static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
  406. int buf_size, int *coded_samples, int *approx_nb_samples)
  407. {
  408. ADPCMDecodeContext *s = avctx->priv_data;
  409. int nb_samples = 0;
  410. int ch = avctx->channels;
  411. int has_coded_samples = 0;
  412. int header_size;
  413. *coded_samples = 0;
  414. *approx_nb_samples = 0;
  415. if(ch <= 0)
  416. return 0;
  417. switch (avctx->codec->id) {
  418. /* constant, only check buf_size */
  419. case AV_CODEC_ID_ADPCM_EA_XAS:
  420. if (buf_size < 76 * ch)
  421. return 0;
  422. nb_samples = 128;
  423. break;
  424. case AV_CODEC_ID_ADPCM_IMA_QT:
  425. if (buf_size < 34 * ch)
  426. return 0;
  427. nb_samples = 64;
  428. break;
  429. /* simple 4-bit adpcm */
  430. case AV_CODEC_ID_ADPCM_CT:
  431. case AV_CODEC_ID_ADPCM_IMA_APC:
  432. case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
  433. case AV_CODEC_ID_ADPCM_IMA_OKI:
  434. case AV_CODEC_ID_ADPCM_IMA_WS:
  435. case AV_CODEC_ID_ADPCM_YAMAHA:
  436. nb_samples = buf_size * 2 / ch;
  437. break;
  438. }
  439. if (nb_samples)
  440. return nb_samples;
  441. /* simple 4-bit adpcm, with header */
  442. header_size = 0;
  443. switch (avctx->codec->id) {
  444. case AV_CODEC_ID_ADPCM_4XM:
  445. case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
  446. case AV_CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break;
  447. case AV_CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4 * ch; break;
  448. }
  449. if (header_size > 0)
  450. return (buf_size - header_size) * 2 / ch;
  451. /* more complex formats */
  452. switch (avctx->codec->id) {
  453. case AV_CODEC_ID_ADPCM_EA:
  454. has_coded_samples = 1;
  455. *coded_samples = bytestream2_get_le32(gb);
  456. *coded_samples -= *coded_samples % 28;
  457. nb_samples = (buf_size - 12) / 30 * 28;
  458. break;
  459. case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
  460. has_coded_samples = 1;
  461. *coded_samples = bytestream2_get_le32(gb);
  462. nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
  463. break;
  464. case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
  465. nb_samples = (buf_size - ch) / ch * 2;
  466. break;
  467. case AV_CODEC_ID_ADPCM_EA_R1:
  468. case AV_CODEC_ID_ADPCM_EA_R2:
  469. case AV_CODEC_ID_ADPCM_EA_R3:
  470. /* maximum number of samples */
  471. /* has internal offsets and a per-frame switch to signal raw 16-bit */
  472. has_coded_samples = 1;
  473. switch (avctx->codec->id) {
  474. case AV_CODEC_ID_ADPCM_EA_R1:
  475. header_size = 4 + 9 * ch;
  476. *coded_samples = bytestream2_get_le32(gb);
  477. break;
  478. case AV_CODEC_ID_ADPCM_EA_R2:
  479. header_size = 4 + 5 * ch;
  480. *coded_samples = bytestream2_get_le32(gb);
  481. *approx_nb_samples = 1;
  482. break;
  483. case AV_CODEC_ID_ADPCM_EA_R3:
  484. header_size = 4 + 5 * ch;
  485. *coded_samples = bytestream2_get_be32(gb);
  486. *approx_nb_samples = 1;
  487. break;
  488. }
  489. *coded_samples -= *coded_samples % 28;
  490. nb_samples = (buf_size - header_size) * 2 / ch;
  491. nb_samples -= nb_samples % 28;
  492. break;
  493. case AV_CODEC_ID_ADPCM_IMA_DK3:
  494. if (avctx->block_align > 0)
  495. buf_size = FFMIN(buf_size, avctx->block_align);
  496. nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
  497. break;
  498. case AV_CODEC_ID_ADPCM_IMA_DK4:
  499. if (avctx->block_align > 0)
  500. buf_size = FFMIN(buf_size, avctx->block_align);
  501. nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
  502. break;
  503. case AV_CODEC_ID_ADPCM_IMA_RAD:
  504. if (avctx->block_align > 0)
  505. buf_size = FFMIN(buf_size, avctx->block_align);
  506. nb_samples = (buf_size - 4 * ch) * 2 / ch;
  507. break;
  508. case AV_CODEC_ID_ADPCM_IMA_WAV:
  509. {
  510. int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
  511. int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
  512. if (avctx->block_align > 0)
  513. buf_size = FFMIN(buf_size, avctx->block_align);
  514. nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
  515. break;
  516. }
  517. case AV_CODEC_ID_ADPCM_MS:
  518. if (avctx->block_align > 0)
  519. buf_size = FFMIN(buf_size, avctx->block_align);
  520. nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
  521. break;
  522. case AV_CODEC_ID_ADPCM_SBPRO_2:
  523. case AV_CODEC_ID_ADPCM_SBPRO_3:
  524. case AV_CODEC_ID_ADPCM_SBPRO_4:
  525. {
  526. int samples_per_byte;
  527. switch (avctx->codec->id) {
  528. case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
  529. case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
  530. case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
  531. }
  532. if (!s->status[0].step_index) {
  533. nb_samples++;
  534. buf_size -= ch;
  535. }
  536. nb_samples += buf_size * samples_per_byte / ch;
  537. break;
  538. }
  539. case AV_CODEC_ID_ADPCM_SWF:
  540. {
  541. int buf_bits = buf_size * 8 - 2;
  542. int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
  543. int block_hdr_size = 22 * ch;
  544. int block_size = block_hdr_size + nbits * ch * 4095;
  545. int nblocks = buf_bits / block_size;
  546. int bits_left = buf_bits - nblocks * block_size;
  547. nb_samples = nblocks * 4096;
  548. if (bits_left >= block_hdr_size)
  549. nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
  550. break;
  551. }
  552. case AV_CODEC_ID_ADPCM_THP:
  553. if (avctx->extradata) {
  554. nb_samples = buf_size / (8 * ch) * 14;
  555. break;
  556. }
  557. has_coded_samples = 1;
  558. bytestream2_skip(gb, 4); // channel size
  559. *coded_samples = bytestream2_get_be32(gb);
  560. *coded_samples -= *coded_samples % 14;
  561. nb_samples = (buf_size - (8 + 36 * ch)) / (8 * ch) * 14;
  562. break;
  563. case AV_CODEC_ID_ADPCM_AFC:
  564. nb_samples = buf_size / (9 * ch) * 16;
  565. break;
  566. case AV_CODEC_ID_ADPCM_XA:
  567. nb_samples = (buf_size / 128) * 224 / ch;
  568. break;
  569. case AV_CODEC_ID_ADPCM_DTK:
  570. nb_samples = buf_size / (16 * ch) * 28;
  571. break;
  572. }
  573. /* validate coded sample count */
  574. if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
  575. return AVERROR_INVALIDDATA;
  576. return nb_samples;
  577. }
  578. static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
  579. int *got_frame_ptr, AVPacket *avpkt)
  580. {
  581. AVFrame *frame = data;
  582. const uint8_t *buf = avpkt->data;
  583. int buf_size = avpkt->size;
  584. ADPCMDecodeContext *c = avctx->priv_data;
  585. ADPCMChannelStatus *cs;
  586. int n, m, channel, i;
  587. short *samples;
  588. int16_t **samples_p;
  589. int st; /* stereo */
  590. int count1, count2;
  591. int nb_samples, coded_samples, approx_nb_samples, ret;
  592. GetByteContext gb;
  593. bytestream2_init(&gb, buf, buf_size);
  594. nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
  595. if (nb_samples <= 0) {
  596. av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
  597. return AVERROR_INVALIDDATA;
  598. }
  599. /* get output buffer */
  600. frame->nb_samples = nb_samples;
  601. if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
  602. return ret;
  603. samples = (short *)frame->data[0];
  604. samples_p = (int16_t **)frame->extended_data;
  605. /* use coded_samples when applicable */
  606. /* it is always <= nb_samples, so the output buffer will be large enough */
  607. if (coded_samples) {
  608. if (!approx_nb_samples && coded_samples != nb_samples)
  609. av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
  610. frame->nb_samples = nb_samples = coded_samples;
  611. }
  612. st = avctx->channels == 2 ? 1 : 0;
  613. switch(avctx->codec->id) {
  614. case AV_CODEC_ID_ADPCM_IMA_QT:
  615. /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
  616. Channel data is interleaved per-chunk. */
  617. for (channel = 0; channel < avctx->channels; channel++) {
  618. int predictor;
  619. int step_index;
  620. cs = &(c->status[channel]);
  621. /* (pppppp) (piiiiiii) */
  622. /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
  623. predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
  624. step_index = predictor & 0x7F;
  625. predictor &= ~0x7F;
  626. if (cs->step_index == step_index) {
  627. int diff = predictor - cs->predictor;
  628. if (diff < 0)
  629. diff = - diff;
  630. if (diff > 0x7f)
  631. goto update;
  632. } else {
  633. update:
  634. cs->step_index = step_index;
  635. cs->predictor = predictor;
  636. }
  637. if (cs->step_index > 88u){
  638. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  639. channel, cs->step_index);
  640. return AVERROR_INVALIDDATA;
  641. }
  642. samples = samples_p[channel];
  643. for (m = 0; m < 64; m += 2) {
  644. int byte = bytestream2_get_byteu(&gb);
  645. samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);
  646. samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 , 3);
  647. }
  648. }
  649. break;
  650. case AV_CODEC_ID_ADPCM_IMA_WAV:
  651. for(i=0; i<avctx->channels; i++){
  652. cs = &(c->status[i]);
  653. cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
  654. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  655. if (cs->step_index > 88u){
  656. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  657. i, cs->step_index);
  658. return AVERROR_INVALIDDATA;
  659. }
  660. }
  661. if (avctx->bits_per_coded_sample != 4) {
  662. int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
  663. GetBitContext g;
  664. init_get_bits8(&g, gb.buffer, bytestream2_get_bytes_left(&gb));
  665. for (n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
  666. for (i = 0; i < avctx->channels; i++) {
  667. cs = &c->status[i];
  668. samples = &samples_p[i][1 + n * samples_per_block];
  669. for (m = 0; m < samples_per_block; m++) {
  670. samples[m] = adpcm_ima_wav_expand_nibble(cs, &g,
  671. avctx->bits_per_coded_sample);
  672. }
  673. }
  674. }
  675. bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4);
  676. } else {
  677. for (n = 0; n < (nb_samples - 1) / 8; n++) {
  678. for (i = 0; i < avctx->channels; i++) {
  679. cs = &c->status[i];
  680. samples = &samples_p[i][1 + n * 8];
  681. for (m = 0; m < 8; m += 2) {
  682. int v = bytestream2_get_byteu(&gb);
  683. samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
  684. samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
  685. }
  686. }
  687. }
  688. }
  689. break;
  690. case AV_CODEC_ID_ADPCM_4XM:
  691. for (i = 0; i < avctx->channels; i++)
  692. c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  693. for (i = 0; i < avctx->channels; i++) {
  694. c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  695. if (c->status[i].step_index > 88u) {
  696. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  697. i, c->status[i].step_index);
  698. return AVERROR_INVALIDDATA;
  699. }
  700. }
  701. for (i = 0; i < avctx->channels; i++) {
  702. samples = (int16_t *)frame->data[i];
  703. cs = &c->status[i];
  704. for (n = nb_samples >> 1; n > 0; n--) {
  705. int v = bytestream2_get_byteu(&gb);
  706. *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
  707. *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
  708. }
  709. }
  710. break;
  711. case AV_CODEC_ID_ADPCM_MS:
  712. {
  713. int block_predictor;
  714. block_predictor = bytestream2_get_byteu(&gb);
  715. if (block_predictor > 6) {
  716. av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
  717. block_predictor);
  718. return AVERROR_INVALIDDATA;
  719. }
  720. c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
  721. c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
  722. if (st) {
  723. block_predictor = bytestream2_get_byteu(&gb);
  724. if (block_predictor > 6) {
  725. av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
  726. block_predictor);
  727. return AVERROR_INVALIDDATA;
  728. }
  729. c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
  730. c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
  731. }
  732. c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
  733. if (st){
  734. c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
  735. }
  736. c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
  737. if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
  738. c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
  739. if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
  740. *samples++ = c->status[0].sample2;
  741. if (st) *samples++ = c->status[1].sample2;
  742. *samples++ = c->status[0].sample1;
  743. if (st) *samples++ = c->status[1].sample1;
  744. for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
  745. int byte = bytestream2_get_byteu(&gb);
  746. *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
  747. *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
  748. }
  749. break;
  750. }
  751. case AV_CODEC_ID_ADPCM_IMA_DK4:
  752. for (channel = 0; channel < avctx->channels; channel++) {
  753. cs = &c->status[channel];
  754. cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
  755. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  756. if (cs->step_index > 88u){
  757. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  758. channel, cs->step_index);
  759. return AVERROR_INVALIDDATA;
  760. }
  761. }
  762. for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
  763. int v = bytestream2_get_byteu(&gb);
  764. *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
  765. *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
  766. }
  767. break;
  768. case AV_CODEC_ID_ADPCM_IMA_DK3:
  769. {
  770. int last_byte = 0;
  771. int nibble;
  772. int decode_top_nibble_next = 0;
  773. int diff_channel;
  774. const int16_t *samples_end = samples + avctx->channels * nb_samples;
  775. bytestream2_skipu(&gb, 10);
  776. c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  777. c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  778. c->status[0].step_index = bytestream2_get_byteu(&gb);
  779. c->status[1].step_index = bytestream2_get_byteu(&gb);
  780. if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
  781. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
  782. c->status[0].step_index, c->status[1].step_index);
  783. return AVERROR_INVALIDDATA;
  784. }
  785. /* sign extend the predictors */
  786. diff_channel = c->status[1].predictor;
  787. /* DK3 ADPCM support macro */
  788. #define DK3_GET_NEXT_NIBBLE() \
  789. if (decode_top_nibble_next) { \
  790. nibble = last_byte >> 4; \
  791. decode_top_nibble_next = 0; \
  792. } else { \
  793. last_byte = bytestream2_get_byteu(&gb); \
  794. nibble = last_byte & 0x0F; \
  795. decode_top_nibble_next = 1; \
  796. }
  797. while (samples < samples_end) {
  798. /* for this algorithm, c->status[0] is the sum channel and
  799. * c->status[1] is the diff channel */
  800. /* process the first predictor of the sum channel */
  801. DK3_GET_NEXT_NIBBLE();
  802. adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
  803. /* process the diff channel predictor */
  804. DK3_GET_NEXT_NIBBLE();
  805. adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
  806. /* process the first pair of stereo PCM samples */
  807. diff_channel = (diff_channel + c->status[1].predictor) / 2;
  808. *samples++ = c->status[0].predictor + c->status[1].predictor;
  809. *samples++ = c->status[0].predictor - c->status[1].predictor;
  810. /* process the second predictor of the sum channel */
  811. DK3_GET_NEXT_NIBBLE();
  812. adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
  813. /* process the second pair of stereo PCM samples */
  814. diff_channel = (diff_channel + c->status[1].predictor) / 2;
  815. *samples++ = c->status[0].predictor + c->status[1].predictor;
  816. *samples++ = c->status[0].predictor - c->status[1].predictor;
  817. }
  818. break;
  819. }
  820. case AV_CODEC_ID_ADPCM_IMA_ISS:
  821. for (channel = 0; channel < avctx->channels; channel++) {
  822. cs = &c->status[channel];
  823. cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  824. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  825. if (cs->step_index > 88u){
  826. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  827. channel, cs->step_index);
  828. return AVERROR_INVALIDDATA;
  829. }
  830. }
  831. for (n = nb_samples >> (1 - st); n > 0; n--) {
  832. int v1, v2;
  833. int v = bytestream2_get_byteu(&gb);
  834. /* nibbles are swapped for mono */
  835. if (st) {
  836. v1 = v >> 4;
  837. v2 = v & 0x0F;
  838. } else {
  839. v2 = v >> 4;
  840. v1 = v & 0x0F;
  841. }
  842. *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
  843. *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
  844. }
  845. break;
  846. case AV_CODEC_ID_ADPCM_IMA_APC:
  847. while (bytestream2_get_bytes_left(&gb) > 0) {
  848. int v = bytestream2_get_byteu(&gb);
  849. *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
  850. *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
  851. }
  852. break;
  853. case AV_CODEC_ID_ADPCM_IMA_OKI:
  854. while (bytestream2_get_bytes_left(&gb) > 0) {
  855. int v = bytestream2_get_byteu(&gb);
  856. *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0], v >> 4 );
  857. *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);
  858. }
  859. break;
  860. case AV_CODEC_ID_ADPCM_IMA_RAD:
  861. for (channel = 0; channel < avctx->channels; channel++) {
  862. cs = &c->status[channel];
  863. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  864. cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  865. if (cs->step_index > 88u){
  866. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  867. channel, cs->step_index);
  868. return AVERROR_INVALIDDATA;
  869. }
  870. }
  871. for (n = 0; n < nb_samples / 2; n++) {
  872. int byte[2];
  873. byte[0] = bytestream2_get_byteu(&gb);
  874. if (st)
  875. byte[1] = bytestream2_get_byteu(&gb);
  876. for(channel = 0; channel < avctx->channels; channel++) {
  877. *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
  878. }
  879. for(channel = 0; channel < avctx->channels; channel++) {
  880. *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3);
  881. }
  882. }
  883. break;
  884. case AV_CODEC_ID_ADPCM_IMA_WS:
  885. if (c->vqa_version == 3) {
  886. for (channel = 0; channel < avctx->channels; channel++) {
  887. int16_t *smp = samples_p[channel];
  888. for (n = nb_samples / 2; n > 0; n--) {
  889. int v = bytestream2_get_byteu(&gb);
  890. *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
  891. *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
  892. }
  893. }
  894. } else {
  895. for (n = nb_samples / 2; n > 0; n--) {
  896. for (channel = 0; channel < avctx->channels; channel++) {
  897. int v = bytestream2_get_byteu(&gb);
  898. *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
  899. samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
  900. }
  901. samples += avctx->channels;
  902. }
  903. }
  904. bytestream2_seek(&gb, 0, SEEK_END);
  905. break;
  906. case AV_CODEC_ID_ADPCM_XA:
  907. {
  908. int16_t *out0 = samples_p[0];
  909. int16_t *out1 = samples_p[1];
  910. int samples_per_block = 28 * (3 - avctx->channels) * 4;
  911. int sample_offset = 0;
  912. while (bytestream2_get_bytes_left(&gb) >= 128) {
  913. if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
  914. &c->status[0], &c->status[1],
  915. avctx->channels, sample_offset)) < 0)
  916. return ret;
  917. bytestream2_skipu(&gb, 128);
  918. sample_offset += samples_per_block;
  919. }
  920. break;
  921. }
  922. case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
  923. for (i=0; i<=st; i++) {
  924. c->status[i].step_index = bytestream2_get_le32u(&gb);
  925. if (c->status[i].step_index > 88u) {
  926. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  927. i, c->status[i].step_index);
  928. return AVERROR_INVALIDDATA;
  929. }
  930. }
  931. for (i=0; i<=st; i++)
  932. c->status[i].predictor = bytestream2_get_le32u(&gb);
  933. for (n = nb_samples >> (1 - st); n > 0; n--) {
  934. int byte = bytestream2_get_byteu(&gb);
  935. *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
  936. *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
  937. }
  938. break;
  939. case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
  940. for (n = nb_samples >> (1 - st); n > 0; n--) {
  941. int byte = bytestream2_get_byteu(&gb);
  942. *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6);
  943. *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
  944. }
  945. break;
  946. case AV_CODEC_ID_ADPCM_EA:
  947. {
  948. int previous_left_sample, previous_right_sample;
  949. int current_left_sample, current_right_sample;
  950. int next_left_sample, next_right_sample;
  951. int coeff1l, coeff2l, coeff1r, coeff2r;
  952. int shift_left, shift_right;
  953. /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
  954. each coding 28 stereo samples. */
  955. if(avctx->channels != 2)
  956. return AVERROR_INVALIDDATA;
  957. current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  958. previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  959. current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  960. previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  961. for (count1 = 0; count1 < nb_samples / 28; count1++) {
  962. int byte = bytestream2_get_byteu(&gb);
  963. coeff1l = ea_adpcm_table[ byte >> 4 ];
  964. coeff2l = ea_adpcm_table[(byte >> 4 ) + 4];
  965. coeff1r = ea_adpcm_table[ byte & 0x0F];
  966. coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
  967. byte = bytestream2_get_byteu(&gb);
  968. shift_left = 20 - (byte >> 4);
  969. shift_right = 20 - (byte & 0x0F);
  970. for (count2 = 0; count2 < 28; count2++) {
  971. byte = bytestream2_get_byteu(&gb);
  972. next_left_sample = sign_extend(byte >> 4, 4) << shift_left;
  973. next_right_sample = sign_extend(byte, 4) << shift_right;
  974. next_left_sample = (next_left_sample +
  975. (current_left_sample * coeff1l) +
  976. (previous_left_sample * coeff2l) + 0x80) >> 8;
  977. next_right_sample = (next_right_sample +
  978. (current_right_sample * coeff1r) +
  979. (previous_right_sample * coeff2r) + 0x80) >> 8;
  980. previous_left_sample = current_left_sample;
  981. current_left_sample = av_clip_int16(next_left_sample);
  982. previous_right_sample = current_right_sample;
  983. current_right_sample = av_clip_int16(next_right_sample);
  984. *samples++ = current_left_sample;
  985. *samples++ = current_right_sample;
  986. }
  987. }
  988. bytestream2_skip(&gb, 2); // Skip terminating 0x0000
  989. break;
  990. }
  991. case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
  992. {
  993. int coeff[2][2], shift[2];
  994. for(channel = 0; channel < avctx->channels; channel++) {
  995. int byte = bytestream2_get_byteu(&gb);
  996. for (i=0; i<2; i++)
  997. coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
  998. shift[channel] = 20 - (byte & 0x0F);
  999. }
  1000. for (count1 = 0; count1 < nb_samples / 2; count1++) {
  1001. int byte[2];
  1002. byte[0] = bytestream2_get_byteu(&gb);
  1003. if (st) byte[1] = bytestream2_get_byteu(&gb);
  1004. for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
  1005. for(channel = 0; channel < avctx->channels; channel++) {
  1006. int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];
  1007. sample = (sample +
  1008. c->status[channel].sample1 * coeff[channel][0] +
  1009. c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
  1010. c->status[channel].sample2 = c->status[channel].sample1;
  1011. c->status[channel].sample1 = av_clip_int16(sample);
  1012. *samples++ = c->status[channel].sample1;
  1013. }
  1014. }
  1015. }
  1016. bytestream2_seek(&gb, 0, SEEK_END);
  1017. break;
  1018. }
  1019. case AV_CODEC_ID_ADPCM_EA_R1:
  1020. case AV_CODEC_ID_ADPCM_EA_R2:
  1021. case AV_CODEC_ID_ADPCM_EA_R3: {
  1022. /* channel numbering
  1023. 2chan: 0=fl, 1=fr
  1024. 4chan: 0=fl, 1=rl, 2=fr, 3=rr
  1025. 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
  1026. const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
  1027. int previous_sample, current_sample, next_sample;
  1028. int coeff1, coeff2;
  1029. int shift;
  1030. unsigned int channel;
  1031. uint16_t *samplesC;
  1032. int count = 0;
  1033. int offsets[6];
  1034. for (channel=0; channel<avctx->channels; channel++)
  1035. offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
  1036. bytestream2_get_le32(&gb)) +
  1037. (avctx->channels + 1) * 4;
  1038. for (channel=0; channel<avctx->channels; channel++) {
  1039. bytestream2_seek(&gb, offsets[channel], SEEK_SET);
  1040. samplesC = samples_p[channel];
  1041. if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
  1042. current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
  1043. previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
  1044. } else {
  1045. current_sample = c->status[channel].predictor;
  1046. previous_sample = c->status[channel].prev_sample;
  1047. }
  1048. for (count1 = 0; count1 < nb_samples / 28; count1++) {
  1049. int byte = bytestream2_get_byte(&gb);
  1050. if (byte == 0xEE) { /* only seen in R2 and R3 */
  1051. current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
  1052. previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
  1053. for (count2=0; count2<28; count2++)
  1054. *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);
  1055. } else {
  1056. coeff1 = ea_adpcm_table[ byte >> 4 ];
  1057. coeff2 = ea_adpcm_table[(byte >> 4) + 4];
  1058. shift = 20 - (byte & 0x0F);
  1059. for (count2=0; count2<28; count2++) {
  1060. if (count2 & 1)
  1061. next_sample = sign_extend(byte, 4) << shift;
  1062. else {
  1063. byte = bytestream2_get_byte(&gb);
  1064. next_sample = sign_extend(byte >> 4, 4) << shift;
  1065. }
  1066. next_sample += (current_sample * coeff1) +
  1067. (previous_sample * coeff2);
  1068. next_sample = av_clip_int16(next_sample >> 8);
  1069. previous_sample = current_sample;
  1070. current_sample = next_sample;
  1071. *samplesC++ = current_sample;
  1072. }
  1073. }
  1074. }
  1075. if (!count) {
  1076. count = count1;
  1077. } else if (count != count1) {
  1078. av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
  1079. count = FFMAX(count, count1);
  1080. }
  1081. if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
  1082. c->status[channel].predictor = current_sample;
  1083. c->status[channel].prev_sample = previous_sample;
  1084. }
  1085. }
  1086. frame->nb_samples = count * 28;
  1087. bytestream2_seek(&gb, 0, SEEK_END);
  1088. break;
  1089. }
  1090. case AV_CODEC_ID_ADPCM_EA_XAS:
  1091. for (channel=0; channel<avctx->channels; channel++) {
  1092. int coeff[2][4], shift[4];
  1093. int16_t *s = samples_p[channel];
  1094. for (n = 0; n < 4; n++, s += 32) {
  1095. int val = sign_extend(bytestream2_get_le16u(&gb), 16);
  1096. for (i=0; i<2; i++)
  1097. coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
  1098. s[0] = val & ~0x0F;
  1099. val = sign_extend(bytestream2_get_le16u(&gb), 16);
  1100. shift[n] = 20 - (val & 0x0F);
  1101. s[1] = val & ~0x0F;
  1102. }
  1103. for (m=2; m<32; m+=2) {
  1104. s = &samples_p[channel][m];
  1105. for (n = 0; n < 4; n++, s += 32) {
  1106. int level, pred;
  1107. int byte = bytestream2_get_byteu(&gb);
  1108. level = sign_extend(byte >> 4, 4) << shift[n];
  1109. pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
  1110. s[0] = av_clip_int16((level + pred + 0x80) >> 8);
  1111. level = sign_extend(byte, 4) << shift[n];
  1112. pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
  1113. s[1] = av_clip_int16((level + pred + 0x80) >> 8);
  1114. }
  1115. }
  1116. }
  1117. break;
  1118. case AV_CODEC_ID_ADPCM_IMA_AMV:
  1119. c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  1120. c->status[0].step_index = bytestream2_get_le16u(&gb);
  1121. bytestream2_skipu(&gb, 4);
  1122. if (c->status[0].step_index > 88u) {
  1123. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
  1124. c->status[0].step_index);
  1125. return AVERROR_INVALIDDATA;
  1126. }
  1127. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1128. int v = bytestream2_get_byteu(&gb);
  1129. *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
  1130. *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);
  1131. }
  1132. break;
  1133. case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
  1134. for (i = 0; i < avctx->channels; i++) {
  1135. c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
  1136. c->status[i].step_index = bytestream2_get_byteu(&gb);
  1137. bytestream2_skipu(&gb, 1);
  1138. if (c->status[i].step_index > 88u) {
  1139. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
  1140. c->status[i].step_index);
  1141. return AVERROR_INVALIDDATA;
  1142. }
  1143. }
  1144. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1145. int v = bytestream2_get_byteu(&gb);
  1146. *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3);
  1147. *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3);
  1148. }
  1149. break;
  1150. case AV_CODEC_ID_ADPCM_CT:
  1151. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1152. int v = bytestream2_get_byteu(&gb);
  1153. *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
  1154. *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
  1155. }
  1156. break;
  1157. case AV_CODEC_ID_ADPCM_SBPRO_4:
  1158. case AV_CODEC_ID_ADPCM_SBPRO_3:
  1159. case AV_CODEC_ID_ADPCM_SBPRO_2:
  1160. if (!c->status[0].step_index) {
  1161. /* the first byte is a raw sample */
  1162. *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
  1163. if (st)
  1164. *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
  1165. c->status[0].step_index = 1;
  1166. nb_samples--;
  1167. }
  1168. if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
  1169. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1170. int byte = bytestream2_get_byteu(&gb);
  1171. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1172. byte >> 4, 4, 0);
  1173. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1174. byte & 0x0F, 4, 0);
  1175. }
  1176. } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
  1177. for (n = (nb_samples<<st) / 3; n > 0; n--) {
  1178. int byte = bytestream2_get_byteu(&gb);
  1179. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1180. byte >> 5 , 3, 0);
  1181. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1182. (byte >> 2) & 0x07, 3, 0);
  1183. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1184. byte & 0x03, 2, 0);
  1185. }
  1186. } else {
  1187. for (n = nb_samples >> (2 - st); n > 0; n--) {
  1188. int byte = bytestream2_get_byteu(&gb);
  1189. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1190. byte >> 6 , 2, 2);
  1191. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1192. (byte >> 4) & 0x03, 2, 2);
  1193. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1194. (byte >> 2) & 0x03, 2, 2);
  1195. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1196. byte & 0x03, 2, 2);
  1197. }
  1198. }
  1199. break;
  1200. case AV_CODEC_ID_ADPCM_SWF:
  1201. adpcm_swf_decode(avctx, buf, buf_size, samples);
  1202. bytestream2_seek(&gb, 0, SEEK_END);
  1203. break;
  1204. case AV_CODEC_ID_ADPCM_YAMAHA:
  1205. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1206. int v = bytestream2_get_byteu(&gb);
  1207. *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
  1208. *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
  1209. }
  1210. break;
  1211. case AV_CODEC_ID_ADPCM_AFC:
  1212. {
  1213. int samples_per_block;
  1214. int blocks;
  1215. if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
  1216. samples_per_block = avctx->extradata[0] / 16;
  1217. blocks = nb_samples / avctx->extradata[0];
  1218. } else {
  1219. samples_per_block = nb_samples / 16;
  1220. blocks = 1;
  1221. }
  1222. for (m = 0; m < blocks; m++) {
  1223. for (channel = 0; channel < avctx->channels; channel++) {
  1224. int prev1 = c->status[channel].sample1;
  1225. int prev2 = c->status[channel].sample2;
  1226. samples = samples_p[channel] + m * 16;
  1227. /* Read in every sample for this channel. */
  1228. for (i = 0; i < samples_per_block; i++) {
  1229. int byte = bytestream2_get_byteu(&gb);
  1230. int scale = 1 << (byte >> 4);
  1231. int index = byte & 0xf;
  1232. int factor1 = ff_adpcm_afc_coeffs[0][index];
  1233. int factor2 = ff_adpcm_afc_coeffs[1][index];
  1234. /* Decode 16 samples. */
  1235. for (n = 0; n < 16; n++) {
  1236. int32_t sampledat;
  1237. if (n & 1) {
  1238. sampledat = sign_extend(byte, 4);
  1239. } else {
  1240. byte = bytestream2_get_byteu(&gb);
  1241. sampledat = sign_extend(byte >> 4, 4);
  1242. }
  1243. sampledat = ((prev1 * factor1 + prev2 * factor2) +
  1244. ((sampledat * scale) << 11)) >> 11;
  1245. *samples = av_clip_int16(sampledat);
  1246. prev2 = prev1;
  1247. prev1 = *samples++;
  1248. }
  1249. }
  1250. c->status[channel].sample1 = prev1;
  1251. c->status[channel].sample2 = prev2;
  1252. }
  1253. }
  1254. bytestream2_seek(&gb, 0, SEEK_END);
  1255. break;
  1256. }
  1257. case AV_CODEC_ID_ADPCM_THP:
  1258. {
  1259. int table[6][16];
  1260. int ch;
  1261. if (avctx->extradata) {
  1262. GetByteContext tb;
  1263. if (avctx->extradata_size < 32 * avctx->channels) {
  1264. av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
  1265. return AVERROR_INVALIDDATA;
  1266. }
  1267. bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
  1268. for (i = 0; i < avctx->channels; i++)
  1269. for (n = 0; n < 16; n++)
  1270. table[i][n] = sign_extend(bytestream2_get_be16u(&tb), 16);
  1271. } else {
  1272. for (i = 0; i < avctx->channels; i++)
  1273. for (n = 0; n < 16; n++)
  1274. table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);
  1275. /* Initialize the previous sample. */
  1276. for (i = 0; i < avctx->channels; i++) {
  1277. c->status[i].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16);
  1278. c->status[i].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16);
  1279. }
  1280. }
  1281. for (ch = 0; ch < avctx->channels; ch++) {
  1282. samples = samples_p[ch];
  1283. /* Read in every sample for this channel. */
  1284. for (i = 0; i < nb_samples / 14; i++) {
  1285. int byte = bytestream2_get_byteu(&gb);
  1286. int index = (byte >> 4) & 7;
  1287. unsigned int exp = byte & 0x0F;
  1288. int factor1 = table[ch][index * 2];
  1289. int factor2 = table[ch][index * 2 + 1];
  1290. /* Decode 14 samples. */
  1291. for (n = 0; n < 14; n++) {
  1292. int32_t sampledat;
  1293. if (n & 1) {
  1294. sampledat = sign_extend(byte, 4);
  1295. } else {
  1296. byte = bytestream2_get_byteu(&gb);
  1297. sampledat = sign_extend(byte >> 4, 4);
  1298. }
  1299. sampledat = ((c->status[ch].sample1 * factor1
  1300. + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp);
  1301. *samples = av_clip_int16(sampledat);
  1302. c->status[ch].sample2 = c->status[ch].sample1;
  1303. c->status[ch].sample1 = *samples++;
  1304. }
  1305. }
  1306. }
  1307. break;
  1308. }
  1309. case AV_CODEC_ID_ADPCM_DTK:
  1310. for (channel = 0; channel < avctx->channels; channel++) {
  1311. samples = samples_p[channel];
  1312. /* Read in every sample for this channel. */
  1313. for (i = 0; i < nb_samples / 28; i++) {
  1314. int byte, header;
  1315. if (channel)
  1316. bytestream2_skipu(&gb, 1);
  1317. header = bytestream2_get_byteu(&gb);
  1318. bytestream2_skipu(&gb, 3 - channel);
  1319. /* Decode 28 samples. */
  1320. for (n = 0; n < 28; n++) {
  1321. int32_t sampledat, prev;
  1322. switch (header >> 4) {
  1323. case 1:
  1324. prev = (c->status[channel].sample1 * 0x3c);
  1325. break;
  1326. case 2:
  1327. prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
  1328. break;
  1329. case 3:
  1330. prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
  1331. break;
  1332. default:
  1333. prev = 0;
  1334. }
  1335. prev = av_clip((prev + 0x20) >> 6, -0x200000, 0x1fffff);
  1336. byte = bytestream2_get_byteu(&gb);
  1337. if (!channel)
  1338. sampledat = sign_extend(byte, 4);
  1339. else
  1340. sampledat = sign_extend(byte >> 4, 4);
  1341. sampledat = (((sampledat << 12) >> (header & 0xf)) << 6) + prev;
  1342. *samples++ = av_clip_int16(sampledat >> 6);
  1343. c->status[channel].sample2 = c->status[channel].sample1;
  1344. c->status[channel].sample1 = sampledat;
  1345. }
  1346. }
  1347. if (!channel)
  1348. bytestream2_seek(&gb, 0, SEEK_SET);
  1349. }
  1350. break;
  1351. default:
  1352. return -1;
  1353. }
  1354. if (avpkt->size && bytestream2_tell(&gb) == 0) {
  1355. av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");
  1356. return AVERROR_INVALIDDATA;
  1357. }
  1358. *got_frame_ptr = 1;
  1359. return bytestream2_tell(&gb);
  1360. }
  1361. static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
  1362. AV_SAMPLE_FMT_NONE };
  1363. static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16,
  1364. AV_SAMPLE_FMT_NONE };
  1365. static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16,
  1366. AV_SAMPLE_FMT_S16P,
  1367. AV_SAMPLE_FMT_NONE };
  1368. #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
  1369. AVCodec ff_ ## name_ ## _decoder = { \
  1370. .name = #name_, \
  1371. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  1372. .type = AVMEDIA_TYPE_AUDIO, \
  1373. .id = id_, \
  1374. .priv_data_size = sizeof(ADPCMDecodeContext), \
  1375. .init = adpcm_decode_init, \
  1376. .decode = adpcm_decode_frame, \
  1377. .capabilities = CODEC_CAP_DR1, \
  1378. .sample_fmts = sample_fmts_, \
  1379. }
  1380. /* Note: Do not forget to add new entries to the Makefile as well. */
  1381. ADPCM_DECODER(AV_CODEC_ID_ADPCM_4XM, sample_fmts_s16p, adpcm_4xm, "ADPCM 4X Movie");
  1382. ADPCM_DECODER(AV_CODEC_ID_ADPCM_AFC, sample_fmts_s16p, adpcm_afc, "ADPCM Nintendo Gamecube AFC");
  1383. ADPCM_DECODER(AV_CODEC_ID_ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology");
  1384. ADPCM_DECODER(AV_CODEC_ID_ADPCM_DTK, sample_fmts_s16p, adpcm_dtk, "ADPCM Nintendo Gamecube DTK");
  1385. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts");
  1386. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
  1387. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1, "ADPCM Electronic Arts R1");
  1388. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2, "ADPCM Electronic Arts R2");
  1389. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3, "ADPCM Electronic Arts R3");
  1390. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
  1391. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV");
  1392. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC");
  1393. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
  1394. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
  1395. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
  1396. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
  1397. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
  1398. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_OKI, sample_fmts_s16, adpcm_ima_oki, "ADPCM IMA Dialogic OKI");
  1399. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, "ADPCM IMA QuickTime");
  1400. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad, "ADPCM IMA Radical");
  1401. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
  1402. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV");
  1403. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood");
  1404. ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_s16, adpcm_ms, "ADPCM Microsoft");
  1405. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
  1406. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
  1407. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
  1408. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash");
  1409. ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo Gamecube THP");
  1410. ADPCM_DECODER(AV_CODEC_ID_ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA");
  1411. ADPCM_DECODER(AV_CODEC_ID_ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha");