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.

1577 lines
60KB

  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. */
  403. static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
  404. int buf_size, int *coded_samples)
  405. {
  406. ADPCMDecodeContext *s = avctx->priv_data;
  407. int nb_samples = 0;
  408. int ch = avctx->channels;
  409. int has_coded_samples = 0;
  410. int header_size;
  411. *coded_samples = 0;
  412. if(ch <= 0)
  413. return 0;
  414. switch (avctx->codec->id) {
  415. /* constant, only check buf_size */
  416. case AV_CODEC_ID_ADPCM_EA_XAS:
  417. if (buf_size < 76 * ch)
  418. return 0;
  419. nb_samples = 128;
  420. break;
  421. case AV_CODEC_ID_ADPCM_IMA_QT:
  422. if (buf_size < 34 * ch)
  423. return 0;
  424. nb_samples = 64;
  425. break;
  426. /* simple 4-bit adpcm */
  427. case AV_CODEC_ID_ADPCM_CT:
  428. case AV_CODEC_ID_ADPCM_IMA_APC:
  429. case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
  430. case AV_CODEC_ID_ADPCM_IMA_OKI:
  431. case AV_CODEC_ID_ADPCM_IMA_WS:
  432. case AV_CODEC_ID_ADPCM_YAMAHA:
  433. nb_samples = buf_size * 2 / ch;
  434. break;
  435. }
  436. if (nb_samples)
  437. return nb_samples;
  438. /* simple 4-bit adpcm, with header */
  439. header_size = 0;
  440. switch (avctx->codec->id) {
  441. case AV_CODEC_ID_ADPCM_4XM:
  442. case AV_CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break;
  443. case AV_CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break;
  444. case AV_CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4 * ch; break;
  445. }
  446. if (header_size > 0)
  447. return (buf_size - header_size) * 2 / ch;
  448. /* more complex formats */
  449. switch (avctx->codec->id) {
  450. case AV_CODEC_ID_ADPCM_EA:
  451. has_coded_samples = 1;
  452. *coded_samples = bytestream2_get_le32(gb);
  453. *coded_samples -= *coded_samples % 28;
  454. nb_samples = (buf_size - 12) / 30 * 28;
  455. break;
  456. case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
  457. has_coded_samples = 1;
  458. *coded_samples = bytestream2_get_le32(gb);
  459. nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch;
  460. break;
  461. case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
  462. nb_samples = (buf_size - ch) / ch * 2;
  463. break;
  464. case AV_CODEC_ID_ADPCM_EA_R1:
  465. case AV_CODEC_ID_ADPCM_EA_R2:
  466. case AV_CODEC_ID_ADPCM_EA_R3:
  467. /* maximum number of samples */
  468. /* has internal offsets and a per-frame switch to signal raw 16-bit */
  469. has_coded_samples = 1;
  470. switch (avctx->codec->id) {
  471. case AV_CODEC_ID_ADPCM_EA_R1:
  472. header_size = 4 + 9 * ch;
  473. *coded_samples = bytestream2_get_le32(gb);
  474. break;
  475. case AV_CODEC_ID_ADPCM_EA_R2:
  476. header_size = 4 + 5 * ch;
  477. *coded_samples = bytestream2_get_le32(gb);
  478. break;
  479. case AV_CODEC_ID_ADPCM_EA_R3:
  480. header_size = 4 + 5 * ch;
  481. *coded_samples = bytestream2_get_be32(gb);
  482. break;
  483. }
  484. *coded_samples -= *coded_samples % 28;
  485. nb_samples = (buf_size - header_size) * 2 / ch;
  486. nb_samples -= nb_samples % 28;
  487. break;
  488. case AV_CODEC_ID_ADPCM_IMA_DK3:
  489. if (avctx->block_align > 0)
  490. buf_size = FFMIN(buf_size, avctx->block_align);
  491. nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
  492. break;
  493. case AV_CODEC_ID_ADPCM_IMA_DK4:
  494. if (avctx->block_align > 0)
  495. buf_size = FFMIN(buf_size, avctx->block_align);
  496. nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
  497. break;
  498. case AV_CODEC_ID_ADPCM_IMA_RAD:
  499. if (avctx->block_align > 0)
  500. buf_size = FFMIN(buf_size, avctx->block_align);
  501. nb_samples = (buf_size - 4 * ch) * 2 / ch;
  502. break;
  503. case AV_CODEC_ID_ADPCM_IMA_WAV:
  504. {
  505. int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
  506. int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
  507. if (avctx->block_align > 0)
  508. buf_size = FFMIN(buf_size, avctx->block_align);
  509. nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
  510. break;
  511. }
  512. case AV_CODEC_ID_ADPCM_MS:
  513. if (avctx->block_align > 0)
  514. buf_size = FFMIN(buf_size, avctx->block_align);
  515. nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch;
  516. break;
  517. case AV_CODEC_ID_ADPCM_SBPRO_2:
  518. case AV_CODEC_ID_ADPCM_SBPRO_3:
  519. case AV_CODEC_ID_ADPCM_SBPRO_4:
  520. {
  521. int samples_per_byte;
  522. switch (avctx->codec->id) {
  523. case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
  524. case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
  525. case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
  526. }
  527. if (!s->status[0].step_index) {
  528. nb_samples++;
  529. buf_size -= ch;
  530. }
  531. nb_samples += buf_size * samples_per_byte / ch;
  532. break;
  533. }
  534. case AV_CODEC_ID_ADPCM_SWF:
  535. {
  536. int buf_bits = buf_size * 8 - 2;
  537. int nbits = (bytestream2_get_byte(gb) >> 6) + 2;
  538. int block_hdr_size = 22 * ch;
  539. int block_size = block_hdr_size + nbits * ch * 4095;
  540. int nblocks = buf_bits / block_size;
  541. int bits_left = buf_bits - nblocks * block_size;
  542. nb_samples = nblocks * 4096;
  543. if (bits_left >= block_hdr_size)
  544. nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
  545. break;
  546. }
  547. case AV_CODEC_ID_ADPCM_THP:
  548. if (avctx->extradata) {
  549. nb_samples = buf_size / (8 * ch) * 14;
  550. break;
  551. }
  552. has_coded_samples = 1;
  553. bytestream2_skip(gb, 4); // channel size
  554. *coded_samples = bytestream2_get_be32(gb);
  555. *coded_samples -= *coded_samples % 14;
  556. nb_samples = (buf_size - (8 + 36 * ch)) / (8 * ch) * 14;
  557. break;
  558. case AV_CODEC_ID_ADPCM_AFC:
  559. nb_samples = buf_size / (9 * ch) * 16;
  560. break;
  561. case AV_CODEC_ID_ADPCM_XA:
  562. nb_samples = (buf_size / 128) * 224 / ch;
  563. break;
  564. case AV_CODEC_ID_ADPCM_DTK:
  565. nb_samples = buf_size / (16 * ch) * 28;
  566. break;
  567. }
  568. /* validate coded sample count */
  569. if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
  570. return AVERROR_INVALIDDATA;
  571. return nb_samples;
  572. }
  573. static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
  574. int *got_frame_ptr, AVPacket *avpkt)
  575. {
  576. AVFrame *frame = data;
  577. const uint8_t *buf = avpkt->data;
  578. int buf_size = avpkt->size;
  579. ADPCMDecodeContext *c = avctx->priv_data;
  580. ADPCMChannelStatus *cs;
  581. int n, m, channel, i;
  582. short *samples;
  583. int16_t **samples_p;
  584. int st; /* stereo */
  585. int count1, count2;
  586. int nb_samples, coded_samples, ret;
  587. GetByteContext gb;
  588. bytestream2_init(&gb, buf, buf_size);
  589. nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples);
  590. if (nb_samples <= 0) {
  591. av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
  592. return AVERROR_INVALIDDATA;
  593. }
  594. /* get output buffer */
  595. frame->nb_samples = nb_samples;
  596. if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
  597. return ret;
  598. samples = (short *)frame->data[0];
  599. samples_p = (int16_t **)frame->extended_data;
  600. /* use coded_samples when applicable */
  601. /* it is always <= nb_samples, so the output buffer will be large enough */
  602. if (coded_samples) {
  603. if (coded_samples != nb_samples)
  604. av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
  605. frame->nb_samples = nb_samples = coded_samples;
  606. }
  607. st = avctx->channels == 2 ? 1 : 0;
  608. switch(avctx->codec->id) {
  609. case AV_CODEC_ID_ADPCM_IMA_QT:
  610. /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
  611. Channel data is interleaved per-chunk. */
  612. for (channel = 0; channel < avctx->channels; channel++) {
  613. int predictor;
  614. int step_index;
  615. cs = &(c->status[channel]);
  616. /* (pppppp) (piiiiiii) */
  617. /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
  618. predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
  619. step_index = predictor & 0x7F;
  620. predictor &= ~0x7F;
  621. if (cs->step_index == step_index) {
  622. int diff = predictor - cs->predictor;
  623. if (diff < 0)
  624. diff = - diff;
  625. if (diff > 0x7f)
  626. goto update;
  627. } else {
  628. update:
  629. cs->step_index = step_index;
  630. cs->predictor = predictor;
  631. }
  632. if (cs->step_index > 88u){
  633. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  634. channel, cs->step_index);
  635. return AVERROR_INVALIDDATA;
  636. }
  637. samples = samples_p[channel];
  638. for (m = 0; m < 64; m += 2) {
  639. int byte = bytestream2_get_byteu(&gb);
  640. samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);
  641. samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 , 3);
  642. }
  643. }
  644. break;
  645. case AV_CODEC_ID_ADPCM_IMA_WAV:
  646. for(i=0; i<avctx->channels; i++){
  647. cs = &(c->status[i]);
  648. cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
  649. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  650. if (cs->step_index > 88u){
  651. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  652. i, cs->step_index);
  653. return AVERROR_INVALIDDATA;
  654. }
  655. }
  656. if (avctx->bits_per_coded_sample != 4) {
  657. int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
  658. GetBitContext g;
  659. init_get_bits8(&g, gb.buffer, bytestream2_get_bytes_left(&gb));
  660. for (n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
  661. for (i = 0; i < avctx->channels; i++) {
  662. cs = &c->status[i];
  663. samples = &samples_p[i][1 + n * samples_per_block];
  664. for (m = 0; m < samples_per_block; m++) {
  665. samples[m] = adpcm_ima_wav_expand_nibble(cs, &g,
  666. avctx->bits_per_coded_sample);
  667. }
  668. }
  669. }
  670. bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4);
  671. } else {
  672. for (n = 0; n < (nb_samples - 1) / 8; n++) {
  673. for (i = 0; i < avctx->channels; i++) {
  674. cs = &c->status[i];
  675. samples = &samples_p[i][1 + n * 8];
  676. for (m = 0; m < 8; m += 2) {
  677. int v = bytestream2_get_byteu(&gb);
  678. samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
  679. samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
  680. }
  681. }
  682. }
  683. }
  684. break;
  685. case AV_CODEC_ID_ADPCM_4XM:
  686. for (i = 0; i < avctx->channels; i++)
  687. c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  688. for (i = 0; i < avctx->channels; i++) {
  689. c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  690. if (c->status[i].step_index > 88u) {
  691. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  692. i, c->status[i].step_index);
  693. return AVERROR_INVALIDDATA;
  694. }
  695. }
  696. for (i = 0; i < avctx->channels; i++) {
  697. samples = (int16_t *)frame->data[i];
  698. cs = &c->status[i];
  699. for (n = nb_samples >> 1; n > 0; n--) {
  700. int v = bytestream2_get_byteu(&gb);
  701. *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
  702. *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
  703. }
  704. }
  705. break;
  706. case AV_CODEC_ID_ADPCM_MS:
  707. {
  708. int block_predictor;
  709. block_predictor = bytestream2_get_byteu(&gb);
  710. if (block_predictor > 6) {
  711. av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
  712. block_predictor);
  713. return AVERROR_INVALIDDATA;
  714. }
  715. c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
  716. c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
  717. if (st) {
  718. block_predictor = bytestream2_get_byteu(&gb);
  719. if (block_predictor > 6) {
  720. av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
  721. block_predictor);
  722. return AVERROR_INVALIDDATA;
  723. }
  724. c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
  725. c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
  726. }
  727. c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
  728. if (st){
  729. c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
  730. }
  731. c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
  732. if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
  733. c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
  734. if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
  735. *samples++ = c->status[0].sample2;
  736. if (st) *samples++ = c->status[1].sample2;
  737. *samples++ = c->status[0].sample1;
  738. if (st) *samples++ = c->status[1].sample1;
  739. for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
  740. int byte = bytestream2_get_byteu(&gb);
  741. *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 );
  742. *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
  743. }
  744. break;
  745. }
  746. case AV_CODEC_ID_ADPCM_IMA_DK4:
  747. for (channel = 0; channel < avctx->channels; channel++) {
  748. cs = &c->status[channel];
  749. cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
  750. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  751. if (cs->step_index > 88u){
  752. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  753. channel, cs->step_index);
  754. return AVERROR_INVALIDDATA;
  755. }
  756. }
  757. for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
  758. int v = bytestream2_get_byteu(&gb);
  759. *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
  760. *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
  761. }
  762. break;
  763. case AV_CODEC_ID_ADPCM_IMA_DK3:
  764. {
  765. int last_byte = 0;
  766. int nibble;
  767. int decode_top_nibble_next = 0;
  768. int diff_channel;
  769. const int16_t *samples_end = samples + avctx->channels * nb_samples;
  770. bytestream2_skipu(&gb, 10);
  771. c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  772. c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  773. c->status[0].step_index = bytestream2_get_byteu(&gb);
  774. c->status[1].step_index = bytestream2_get_byteu(&gb);
  775. if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
  776. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
  777. c->status[0].step_index, c->status[1].step_index);
  778. return AVERROR_INVALIDDATA;
  779. }
  780. /* sign extend the predictors */
  781. diff_channel = c->status[1].predictor;
  782. /* DK3 ADPCM support macro */
  783. #define DK3_GET_NEXT_NIBBLE() \
  784. if (decode_top_nibble_next) { \
  785. nibble = last_byte >> 4; \
  786. decode_top_nibble_next = 0; \
  787. } else { \
  788. last_byte = bytestream2_get_byteu(&gb); \
  789. nibble = last_byte & 0x0F; \
  790. decode_top_nibble_next = 1; \
  791. }
  792. while (samples < samples_end) {
  793. /* for this algorithm, c->status[0] is the sum channel and
  794. * c->status[1] is the diff channel */
  795. /* process the first predictor of the sum channel */
  796. DK3_GET_NEXT_NIBBLE();
  797. adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
  798. /* process the diff channel predictor */
  799. DK3_GET_NEXT_NIBBLE();
  800. adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
  801. /* process the first pair of stereo PCM samples */
  802. diff_channel = (diff_channel + c->status[1].predictor) / 2;
  803. *samples++ = c->status[0].predictor + c->status[1].predictor;
  804. *samples++ = c->status[0].predictor - c->status[1].predictor;
  805. /* process the second predictor of the sum channel */
  806. DK3_GET_NEXT_NIBBLE();
  807. adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
  808. /* process the second pair of stereo PCM samples */
  809. diff_channel = (diff_channel + c->status[1].predictor) / 2;
  810. *samples++ = c->status[0].predictor + c->status[1].predictor;
  811. *samples++ = c->status[0].predictor - c->status[1].predictor;
  812. }
  813. break;
  814. }
  815. case AV_CODEC_ID_ADPCM_IMA_ISS:
  816. for (channel = 0; channel < avctx->channels; channel++) {
  817. cs = &c->status[channel];
  818. cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  819. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  820. if (cs->step_index > 88u){
  821. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  822. channel, cs->step_index);
  823. return AVERROR_INVALIDDATA;
  824. }
  825. }
  826. for (n = nb_samples >> (1 - st); n > 0; n--) {
  827. int v1, v2;
  828. int v = bytestream2_get_byteu(&gb);
  829. /* nibbles are swapped for mono */
  830. if (st) {
  831. v1 = v >> 4;
  832. v2 = v & 0x0F;
  833. } else {
  834. v2 = v >> 4;
  835. v1 = v & 0x0F;
  836. }
  837. *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
  838. *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
  839. }
  840. break;
  841. case AV_CODEC_ID_ADPCM_IMA_APC:
  842. while (bytestream2_get_bytes_left(&gb) > 0) {
  843. int v = bytestream2_get_byteu(&gb);
  844. *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
  845. *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
  846. }
  847. break;
  848. case AV_CODEC_ID_ADPCM_IMA_OKI:
  849. while (bytestream2_get_bytes_left(&gb) > 0) {
  850. int v = bytestream2_get_byteu(&gb);
  851. *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0], v >> 4 );
  852. *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);
  853. }
  854. break;
  855. case AV_CODEC_ID_ADPCM_IMA_RAD:
  856. for (channel = 0; channel < avctx->channels; channel++) {
  857. cs = &c->status[channel];
  858. cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
  859. cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  860. if (cs->step_index > 88u){
  861. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  862. channel, cs->step_index);
  863. return AVERROR_INVALIDDATA;
  864. }
  865. }
  866. for (n = 0; n < nb_samples / 2; n++) {
  867. int byte[2];
  868. byte[0] = bytestream2_get_byteu(&gb);
  869. if (st)
  870. byte[1] = bytestream2_get_byteu(&gb);
  871. for(channel = 0; channel < avctx->channels; channel++) {
  872. *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
  873. }
  874. for(channel = 0; channel < avctx->channels; channel++) {
  875. *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3);
  876. }
  877. }
  878. break;
  879. case AV_CODEC_ID_ADPCM_IMA_WS:
  880. if (c->vqa_version == 3) {
  881. for (channel = 0; channel < avctx->channels; channel++) {
  882. int16_t *smp = samples_p[channel];
  883. for (n = nb_samples / 2; n > 0; n--) {
  884. int v = bytestream2_get_byteu(&gb);
  885. *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
  886. *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
  887. }
  888. }
  889. } else {
  890. for (n = nb_samples / 2; n > 0; n--) {
  891. for (channel = 0; channel < avctx->channels; channel++) {
  892. int v = bytestream2_get_byteu(&gb);
  893. *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
  894. samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
  895. }
  896. samples += avctx->channels;
  897. }
  898. }
  899. bytestream2_seek(&gb, 0, SEEK_END);
  900. break;
  901. case AV_CODEC_ID_ADPCM_XA:
  902. {
  903. int16_t *out0 = samples_p[0];
  904. int16_t *out1 = samples_p[1];
  905. int samples_per_block = 28 * (3 - avctx->channels) * 4;
  906. int sample_offset = 0;
  907. while (bytestream2_get_bytes_left(&gb) >= 128) {
  908. if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
  909. &c->status[0], &c->status[1],
  910. avctx->channels, sample_offset)) < 0)
  911. return ret;
  912. bytestream2_skipu(&gb, 128);
  913. sample_offset += samples_per_block;
  914. }
  915. break;
  916. }
  917. case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
  918. for (i=0; i<=st; i++) {
  919. c->status[i].step_index = bytestream2_get_le32u(&gb);
  920. if (c->status[i].step_index > 88u) {
  921. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
  922. i, c->status[i].step_index);
  923. return AVERROR_INVALIDDATA;
  924. }
  925. }
  926. for (i=0; i<=st; i++)
  927. c->status[i].predictor = bytestream2_get_le32u(&gb);
  928. for (n = nb_samples >> (1 - st); n > 0; n--) {
  929. int byte = bytestream2_get_byteu(&gb);
  930. *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3);
  931. *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
  932. }
  933. break;
  934. case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
  935. for (n = nb_samples >> (1 - st); n > 0; n--) {
  936. int byte = bytestream2_get_byteu(&gb);
  937. *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6);
  938. *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
  939. }
  940. break;
  941. case AV_CODEC_ID_ADPCM_EA:
  942. {
  943. int previous_left_sample, previous_right_sample;
  944. int current_left_sample, current_right_sample;
  945. int next_left_sample, next_right_sample;
  946. int coeff1l, coeff2l, coeff1r, coeff2r;
  947. int shift_left, shift_right;
  948. /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
  949. each coding 28 stereo samples. */
  950. if(avctx->channels != 2)
  951. return AVERROR_INVALIDDATA;
  952. current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  953. previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  954. current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  955. previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
  956. for (count1 = 0; count1 < nb_samples / 28; count1++) {
  957. int byte = bytestream2_get_byteu(&gb);
  958. coeff1l = ea_adpcm_table[ byte >> 4 ];
  959. coeff2l = ea_adpcm_table[(byte >> 4 ) + 4];
  960. coeff1r = ea_adpcm_table[ byte & 0x0F];
  961. coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
  962. byte = bytestream2_get_byteu(&gb);
  963. shift_left = 20 - (byte >> 4);
  964. shift_right = 20 - (byte & 0x0F);
  965. for (count2 = 0; count2 < 28; count2++) {
  966. byte = bytestream2_get_byteu(&gb);
  967. next_left_sample = sign_extend(byte >> 4, 4) << shift_left;
  968. next_right_sample = sign_extend(byte, 4) << shift_right;
  969. next_left_sample = (next_left_sample +
  970. (current_left_sample * coeff1l) +
  971. (previous_left_sample * coeff2l) + 0x80) >> 8;
  972. next_right_sample = (next_right_sample +
  973. (current_right_sample * coeff1r) +
  974. (previous_right_sample * coeff2r) + 0x80) >> 8;
  975. previous_left_sample = current_left_sample;
  976. current_left_sample = av_clip_int16(next_left_sample);
  977. previous_right_sample = current_right_sample;
  978. current_right_sample = av_clip_int16(next_right_sample);
  979. *samples++ = current_left_sample;
  980. *samples++ = current_right_sample;
  981. }
  982. }
  983. bytestream2_skip(&gb, 2); // Skip terminating 0x0000
  984. break;
  985. }
  986. case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
  987. {
  988. int coeff[2][2], shift[2];
  989. for(channel = 0; channel < avctx->channels; channel++) {
  990. int byte = bytestream2_get_byteu(&gb);
  991. for (i=0; i<2; i++)
  992. coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
  993. shift[channel] = 20 - (byte & 0x0F);
  994. }
  995. for (count1 = 0; count1 < nb_samples / 2; count1++) {
  996. int byte[2];
  997. byte[0] = bytestream2_get_byteu(&gb);
  998. if (st) byte[1] = bytestream2_get_byteu(&gb);
  999. for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
  1000. for(channel = 0; channel < avctx->channels; channel++) {
  1001. int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];
  1002. sample = (sample +
  1003. c->status[channel].sample1 * coeff[channel][0] +
  1004. c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
  1005. c->status[channel].sample2 = c->status[channel].sample1;
  1006. c->status[channel].sample1 = av_clip_int16(sample);
  1007. *samples++ = c->status[channel].sample1;
  1008. }
  1009. }
  1010. }
  1011. bytestream2_seek(&gb, 0, SEEK_END);
  1012. break;
  1013. }
  1014. case AV_CODEC_ID_ADPCM_EA_R1:
  1015. case AV_CODEC_ID_ADPCM_EA_R2:
  1016. case AV_CODEC_ID_ADPCM_EA_R3: {
  1017. /* channel numbering
  1018. 2chan: 0=fl, 1=fr
  1019. 4chan: 0=fl, 1=rl, 2=fr, 3=rr
  1020. 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */
  1021. const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
  1022. int previous_sample, current_sample, next_sample;
  1023. int coeff1, coeff2;
  1024. int shift;
  1025. unsigned int channel;
  1026. uint16_t *samplesC;
  1027. int count = 0;
  1028. int offsets[6];
  1029. for (channel=0; channel<avctx->channels; channel++)
  1030. offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
  1031. bytestream2_get_le32(&gb)) +
  1032. (avctx->channels + 1) * 4;
  1033. for (channel=0; channel<avctx->channels; channel++) {
  1034. bytestream2_seek(&gb, offsets[channel], SEEK_SET);
  1035. samplesC = samples_p[channel];
  1036. if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
  1037. current_sample = sign_extend(bytestream2_get_le16(&gb), 16);
  1038. previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
  1039. } else {
  1040. current_sample = c->status[channel].predictor;
  1041. previous_sample = c->status[channel].prev_sample;
  1042. }
  1043. for (count1 = 0; count1 < nb_samples / 28; count1++) {
  1044. int byte = bytestream2_get_byte(&gb);
  1045. if (byte == 0xEE) { /* only seen in R2 and R3 */
  1046. current_sample = sign_extend(bytestream2_get_be16(&gb), 16);
  1047. previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
  1048. for (count2=0; count2<28; count2++)
  1049. *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);
  1050. } else {
  1051. coeff1 = ea_adpcm_table[ byte >> 4 ];
  1052. coeff2 = ea_adpcm_table[(byte >> 4) + 4];
  1053. shift = 20 - (byte & 0x0F);
  1054. for (count2=0; count2<28; count2++) {
  1055. if (count2 & 1)
  1056. next_sample = sign_extend(byte, 4) << shift;
  1057. else {
  1058. byte = bytestream2_get_byte(&gb);
  1059. next_sample = sign_extend(byte >> 4, 4) << shift;
  1060. }
  1061. next_sample += (current_sample * coeff1) +
  1062. (previous_sample * coeff2);
  1063. next_sample = av_clip_int16(next_sample >> 8);
  1064. previous_sample = current_sample;
  1065. current_sample = next_sample;
  1066. *samplesC++ = current_sample;
  1067. }
  1068. }
  1069. }
  1070. if (!count) {
  1071. count = count1;
  1072. } else if (count != count1) {
  1073. av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
  1074. count = FFMAX(count, count1);
  1075. }
  1076. if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
  1077. c->status[channel].predictor = current_sample;
  1078. c->status[channel].prev_sample = previous_sample;
  1079. }
  1080. }
  1081. frame->nb_samples = count * 28;
  1082. bytestream2_seek(&gb, 0, SEEK_END);
  1083. break;
  1084. }
  1085. case AV_CODEC_ID_ADPCM_EA_XAS:
  1086. for (channel=0; channel<avctx->channels; channel++) {
  1087. int coeff[2][4], shift[4];
  1088. int16_t *s = samples_p[channel];
  1089. for (n = 0; n < 4; n++, s += 32) {
  1090. int val = sign_extend(bytestream2_get_le16u(&gb), 16);
  1091. for (i=0; i<2; i++)
  1092. coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
  1093. s[0] = val & ~0x0F;
  1094. val = sign_extend(bytestream2_get_le16u(&gb), 16);
  1095. shift[n] = 20 - (val & 0x0F);
  1096. s[1] = val & ~0x0F;
  1097. }
  1098. for (m=2; m<32; m+=2) {
  1099. s = &samples_p[channel][m];
  1100. for (n = 0; n < 4; n++, s += 32) {
  1101. int level, pred;
  1102. int byte = bytestream2_get_byteu(&gb);
  1103. level = sign_extend(byte >> 4, 4) << shift[n];
  1104. pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
  1105. s[0] = av_clip_int16((level + pred + 0x80) >> 8);
  1106. level = sign_extend(byte, 4) << shift[n];
  1107. pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
  1108. s[1] = av_clip_int16((level + pred + 0x80) >> 8);
  1109. }
  1110. }
  1111. }
  1112. break;
  1113. case AV_CODEC_ID_ADPCM_IMA_AMV:
  1114. c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
  1115. c->status[0].step_index = bytestream2_get_le16u(&gb);
  1116. bytestream2_skipu(&gb, 4);
  1117. if (c->status[0].step_index > 88u) {
  1118. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
  1119. c->status[0].step_index);
  1120. return AVERROR_INVALIDDATA;
  1121. }
  1122. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1123. int v = bytestream2_get_byteu(&gb);
  1124. *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
  1125. *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);
  1126. }
  1127. break;
  1128. case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
  1129. for (i = 0; i < avctx->channels; i++) {
  1130. c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
  1131. c->status[i].step_index = bytestream2_get_byteu(&gb);
  1132. bytestream2_skipu(&gb, 1);
  1133. if (c->status[i].step_index > 88u) {
  1134. av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
  1135. c->status[i].step_index);
  1136. return AVERROR_INVALIDDATA;
  1137. }
  1138. }
  1139. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1140. int v = bytestream2_get_byteu(&gb);
  1141. *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3);
  1142. *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3);
  1143. }
  1144. break;
  1145. case AV_CODEC_ID_ADPCM_CT:
  1146. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1147. int v = bytestream2_get_byteu(&gb);
  1148. *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
  1149. *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
  1150. }
  1151. break;
  1152. case AV_CODEC_ID_ADPCM_SBPRO_4:
  1153. case AV_CODEC_ID_ADPCM_SBPRO_3:
  1154. case AV_CODEC_ID_ADPCM_SBPRO_2:
  1155. if (!c->status[0].step_index) {
  1156. /* the first byte is a raw sample */
  1157. *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
  1158. if (st)
  1159. *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
  1160. c->status[0].step_index = 1;
  1161. nb_samples--;
  1162. }
  1163. if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
  1164. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1165. int byte = bytestream2_get_byteu(&gb);
  1166. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1167. byte >> 4, 4, 0);
  1168. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1169. byte & 0x0F, 4, 0);
  1170. }
  1171. } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
  1172. for (n = nb_samples / 3; n > 0; n--) {
  1173. int byte = bytestream2_get_byteu(&gb);
  1174. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1175. byte >> 5 , 3, 0);
  1176. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1177. (byte >> 2) & 0x07, 3, 0);
  1178. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1179. byte & 0x03, 2, 0);
  1180. }
  1181. } else {
  1182. for (n = nb_samples >> (2 - st); n > 0; n--) {
  1183. int byte = bytestream2_get_byteu(&gb);
  1184. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1185. byte >> 6 , 2, 2);
  1186. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1187. (byte >> 4) & 0x03, 2, 2);
  1188. *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
  1189. (byte >> 2) & 0x03, 2, 2);
  1190. *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
  1191. byte & 0x03, 2, 2);
  1192. }
  1193. }
  1194. break;
  1195. case AV_CODEC_ID_ADPCM_SWF:
  1196. adpcm_swf_decode(avctx, buf, buf_size, samples);
  1197. bytestream2_seek(&gb, 0, SEEK_END);
  1198. break;
  1199. case AV_CODEC_ID_ADPCM_YAMAHA:
  1200. for (n = nb_samples >> (1 - st); n > 0; n--) {
  1201. int v = bytestream2_get_byteu(&gb);
  1202. *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
  1203. *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
  1204. }
  1205. break;
  1206. case AV_CODEC_ID_ADPCM_AFC:
  1207. {
  1208. int samples_per_block;
  1209. int blocks;
  1210. if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
  1211. samples_per_block = avctx->extradata[0] / 16;
  1212. blocks = nb_samples / avctx->extradata[0];
  1213. } else {
  1214. samples_per_block = nb_samples / 16;
  1215. blocks = 1;
  1216. }
  1217. for (m = 0; m < blocks; m++) {
  1218. for (channel = 0; channel < avctx->channels; channel++) {
  1219. int prev1 = c->status[channel].sample1;
  1220. int prev2 = c->status[channel].sample2;
  1221. samples = samples_p[channel] + m * 16;
  1222. /* Read in every sample for this channel. */
  1223. for (i = 0; i < samples_per_block; i++) {
  1224. int byte = bytestream2_get_byteu(&gb);
  1225. int scale = 1 << (byte >> 4);
  1226. int index = byte & 0xf;
  1227. int factor1 = ff_adpcm_afc_coeffs[0][index];
  1228. int factor2 = ff_adpcm_afc_coeffs[1][index];
  1229. /* Decode 16 samples. */
  1230. for (n = 0; n < 16; n++) {
  1231. int32_t sampledat;
  1232. if (n & 1) {
  1233. sampledat = sign_extend(byte, 4);
  1234. } else {
  1235. byte = bytestream2_get_byteu(&gb);
  1236. sampledat = sign_extend(byte >> 4, 4);
  1237. }
  1238. sampledat = ((prev1 * factor1 + prev2 * factor2) +
  1239. ((sampledat * scale) << 11)) >> 11;
  1240. *samples = av_clip_int16(sampledat);
  1241. prev2 = prev1;
  1242. prev1 = *samples++;
  1243. }
  1244. }
  1245. c->status[channel].sample1 = prev1;
  1246. c->status[channel].sample2 = prev2;
  1247. }
  1248. }
  1249. bytestream2_seek(&gb, 0, SEEK_END);
  1250. break;
  1251. }
  1252. case AV_CODEC_ID_ADPCM_THP:
  1253. {
  1254. int table[6][16];
  1255. int ch;
  1256. if (avctx->extradata) {
  1257. GetByteContext tb;
  1258. if (avctx->extradata_size < 32 * avctx->channels) {
  1259. av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
  1260. return AVERROR_INVALIDDATA;
  1261. }
  1262. bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
  1263. for (i = 0; i < avctx->channels; i++)
  1264. for (n = 0; n < 16; n++)
  1265. table[i][n] = sign_extend(bytestream2_get_be16u(&tb), 16);
  1266. } else {
  1267. for (i = 0; i < avctx->channels; i++)
  1268. for (n = 0; n < 16; n++)
  1269. table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16);
  1270. /* Initialize the previous sample. */
  1271. for (i = 0; i < avctx->channels; i++) {
  1272. c->status[i].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16);
  1273. c->status[i].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16);
  1274. }
  1275. }
  1276. for (ch = 0; ch < avctx->channels; ch++) {
  1277. samples = samples_p[ch];
  1278. /* Read in every sample for this channel. */
  1279. for (i = 0; i < nb_samples / 14; i++) {
  1280. int byte = bytestream2_get_byteu(&gb);
  1281. int index = (byte >> 4) & 7;
  1282. unsigned int exp = byte & 0x0F;
  1283. int factor1 = table[ch][index * 2];
  1284. int factor2 = table[ch][index * 2 + 1];
  1285. /* Decode 14 samples. */
  1286. for (n = 0; n < 14; n++) {
  1287. int32_t sampledat;
  1288. if (n & 1) {
  1289. sampledat = sign_extend(byte, 4);
  1290. } else {
  1291. byte = bytestream2_get_byteu(&gb);
  1292. sampledat = sign_extend(byte >> 4, 4);
  1293. }
  1294. sampledat = ((c->status[ch].sample1 * factor1
  1295. + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp);
  1296. *samples = av_clip_int16(sampledat);
  1297. c->status[ch].sample2 = c->status[ch].sample1;
  1298. c->status[ch].sample1 = *samples++;
  1299. }
  1300. }
  1301. }
  1302. break;
  1303. }
  1304. case AV_CODEC_ID_ADPCM_DTK:
  1305. for (channel = 0; channel < avctx->channels; channel++) {
  1306. samples = samples_p[channel];
  1307. /* Read in every sample for this channel. */
  1308. for (i = 0; i < nb_samples / 28; i++) {
  1309. int byte, header;
  1310. if (channel)
  1311. bytestream2_skipu(&gb, 1);
  1312. header = bytestream2_get_byteu(&gb);
  1313. bytestream2_skipu(&gb, 3 - channel);
  1314. /* Decode 28 samples. */
  1315. for (n = 0; n < 28; n++) {
  1316. int32_t sampledat, prev;
  1317. switch (header >> 4) {
  1318. case 1:
  1319. prev = (c->status[channel].sample1 * 0x3c);
  1320. break;
  1321. case 2:
  1322. prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
  1323. break;
  1324. case 3:
  1325. prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
  1326. break;
  1327. default:
  1328. prev = 0;
  1329. }
  1330. prev = av_clip((prev + 0x20) >> 6, -0x200000, 0x1fffff);
  1331. byte = bytestream2_get_byteu(&gb);
  1332. if (!channel)
  1333. sampledat = sign_extend(byte, 4);
  1334. else
  1335. sampledat = sign_extend(byte >> 4, 4);
  1336. sampledat = (((sampledat << 12) >> (header & 0xf)) << 6) + prev;
  1337. *samples++ = av_clip_int16(sampledat >> 6);
  1338. c->status[channel].sample2 = c->status[channel].sample1;
  1339. c->status[channel].sample1 = sampledat;
  1340. }
  1341. }
  1342. if (!channel)
  1343. bytestream2_seek(&gb, 0, SEEK_SET);
  1344. }
  1345. break;
  1346. default:
  1347. return -1;
  1348. }
  1349. if (avpkt->size && bytestream2_tell(&gb) == 0) {
  1350. av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");
  1351. return AVERROR_INVALIDDATA;
  1352. }
  1353. *got_frame_ptr = 1;
  1354. return bytestream2_tell(&gb);
  1355. }
  1356. static const enum AVSampleFormat sample_fmts_s16[] = { AV_SAMPLE_FMT_S16,
  1357. AV_SAMPLE_FMT_NONE };
  1358. static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16,
  1359. AV_SAMPLE_FMT_NONE };
  1360. static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16,
  1361. AV_SAMPLE_FMT_S16P,
  1362. AV_SAMPLE_FMT_NONE };
  1363. #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
  1364. AVCodec ff_ ## name_ ## _decoder = { \
  1365. .name = #name_, \
  1366. .long_name = NULL_IF_CONFIG_SMALL(long_name_), \
  1367. .type = AVMEDIA_TYPE_AUDIO, \
  1368. .id = id_, \
  1369. .priv_data_size = sizeof(ADPCMDecodeContext), \
  1370. .init = adpcm_decode_init, \
  1371. .decode = adpcm_decode_frame, \
  1372. .capabilities = CODEC_CAP_DR1, \
  1373. .sample_fmts = sample_fmts_, \
  1374. }
  1375. /* Note: Do not forget to add new entries to the Makefile as well. */
  1376. ADPCM_DECODER(AV_CODEC_ID_ADPCM_4XM, sample_fmts_s16p, adpcm_4xm, "ADPCM 4X Movie");
  1377. ADPCM_DECODER(AV_CODEC_ID_ADPCM_AFC, sample_fmts_s16p, adpcm_afc, "ADPCM Nintendo Gamecube AFC");
  1378. ADPCM_DECODER(AV_CODEC_ID_ADPCM_CT, sample_fmts_s16, adpcm_ct, "ADPCM Creative Technology");
  1379. ADPCM_DECODER(AV_CODEC_ID_ADPCM_DTK, sample_fmts_s16p, adpcm_dtk, "ADPCM Nintendo Gamecube DTK");
  1380. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA, sample_fmts_s16, adpcm_ea, "ADPCM Electronic Arts");
  1381. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16, adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
  1382. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1, sample_fmts_s16p, adpcm_ea_r1, "ADPCM Electronic Arts R1");
  1383. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2, sample_fmts_s16p, adpcm_ea_r2, "ADPCM Electronic Arts R2");
  1384. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3, sample_fmts_s16p, adpcm_ea_r3, "ADPCM Electronic Arts R3");
  1385. ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS, sample_fmts_s16p, adpcm_ea_xas, "ADPCM Electronic Arts XAS");
  1386. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV, sample_fmts_s16, adpcm_ima_amv, "ADPCM IMA AMV");
  1387. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC, sample_fmts_s16, adpcm_ima_apc, "ADPCM IMA CRYO APC");
  1388. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3, sample_fmts_s16, adpcm_ima_dk3, "ADPCM IMA Duck DK3");
  1389. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4, sample_fmts_s16, adpcm_ima_dk4, "ADPCM IMA Duck DK4");
  1390. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_EACS, sample_fmts_s16, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
  1391. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_SEAD, sample_fmts_s16, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
  1392. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ISS, sample_fmts_s16, adpcm_ima_iss, "ADPCM IMA Funcom ISS");
  1393. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_OKI, sample_fmts_s16, adpcm_ima_oki, "ADPCM IMA Dialogic OKI");
  1394. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_QT, sample_fmts_s16p, adpcm_ima_qt, "ADPCM IMA QuickTime");
  1395. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_RAD, sample_fmts_s16, adpcm_ima_rad, "ADPCM IMA Radical");
  1396. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG, sample_fmts_s16, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG");
  1397. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV, sample_fmts_s16p, adpcm_ima_wav, "ADPCM IMA WAV");
  1398. ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS, sample_fmts_both, adpcm_ima_ws, "ADPCM IMA Westwood");
  1399. ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS, sample_fmts_s16, adpcm_ms, "ADPCM Microsoft");
  1400. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2, sample_fmts_s16, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit");
  1401. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3, sample_fmts_s16, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit");
  1402. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4, sample_fmts_s16, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit");
  1403. ADPCM_DECODER(AV_CODEC_ID_ADPCM_SWF, sample_fmts_s16, adpcm_swf, "ADPCM Shockwave Flash");
  1404. ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP, sample_fmts_s16p, adpcm_thp, "ADPCM Nintendo Gamecube THP");
  1405. ADPCM_DECODER(AV_CODEC_ID_ADPCM_XA, sample_fmts_s16p, adpcm_xa, "ADPCM CDROM XA");
  1406. ADPCM_DECODER(AV_CODEC_ID_ADPCM_YAMAHA, sample_fmts_s16, adpcm_yamaha, "ADPCM Yamaha");