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.

1320 lines
41KB

  1. /*
  2. * WMA compatible decoder
  3. * Copyright (c) 2002 The FFmpeg Project.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. /**
  20. * @file wmadec.c
  21. * WMA compatible decoder.
  22. */
  23. #include "avcodec.h"
  24. #include "dsputil.h"
  25. /* size of blocks */
  26. #define BLOCK_MIN_BITS 7
  27. #define BLOCK_MAX_BITS 11
  28. #define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
  29. #define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
  30. /* XXX: find exact max size */
  31. #define HIGH_BAND_MAX_SIZE 16
  32. #define NB_LSP_COEFS 10
  33. /* XXX: is it a suitable value ? */
  34. #define MAX_CODED_SUPERFRAME_SIZE 4096
  35. #define MAX_CHANNELS 2
  36. #define NOISE_TAB_SIZE 8192
  37. #define LSP_POW_BITS 7
  38. typedef struct WMADecodeContext {
  39. GetBitContext gb;
  40. int sample_rate;
  41. int nb_channels;
  42. int bit_rate;
  43. int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
  44. int block_align;
  45. int use_bit_reservoir;
  46. int use_variable_block_len;
  47. int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
  48. int use_noise_coding; /* true if perceptual noise is added */
  49. int byte_offset_bits;
  50. VLC exp_vlc;
  51. int exponent_sizes[BLOCK_NB_SIZES];
  52. uint16_t exponent_bands[BLOCK_NB_SIZES][25];
  53. int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
  54. int coefs_start; /* first coded coef */
  55. int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
  56. int exponent_high_sizes[BLOCK_NB_SIZES];
  57. int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
  58. VLC hgain_vlc;
  59. /* coded values in high bands */
  60. int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
  61. int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
  62. /* there are two possible tables for spectral coefficients */
  63. VLC coef_vlc[2];
  64. uint16_t *run_table[2];
  65. uint16_t *level_table[2];
  66. /* frame info */
  67. int frame_len; /* frame length in samples */
  68. int frame_len_bits; /* frame_len = 1 << frame_len_bits */
  69. int nb_block_sizes; /* number of block sizes */
  70. /* block info */
  71. int reset_block_lengths;
  72. int block_len_bits; /* log2 of current block length */
  73. int next_block_len_bits; /* log2 of next block length */
  74. int prev_block_len_bits; /* log2 of prev block length */
  75. int block_len; /* block length in samples */
  76. int block_num; /* block number in current frame */
  77. int block_pos; /* current position in frame */
  78. uint8_t ms_stereo; /* true if mid/side stereo mode */
  79. uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
  80. float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE] __attribute__((aligned(16)));
  81. float max_exponent[MAX_CHANNELS];
  82. int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
  83. float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE] __attribute__((aligned(16)));
  84. MDCTContext mdct_ctx[BLOCK_NB_SIZES];
  85. float *windows[BLOCK_NB_SIZES];
  86. FFTSample mdct_tmp[BLOCK_MAX_SIZE] __attribute__((aligned(16))); /* temporary storage for imdct */
  87. /* output buffer for one frame and the last for IMDCT windowing */
  88. float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2] __attribute__((aligned(16)));
  89. /* last frame info */
  90. uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
  91. int last_bitoffset;
  92. int last_superframe_len;
  93. float noise_table[NOISE_TAB_SIZE];
  94. int noise_index;
  95. float noise_mult; /* XXX: suppress that and integrate it in the noise array */
  96. /* lsp_to_curve tables */
  97. float lsp_cos_table[BLOCK_MAX_SIZE];
  98. float lsp_pow_e_table[256];
  99. float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
  100. float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
  101. #ifdef TRACE
  102. int frame_count;
  103. #endif
  104. } WMADecodeContext;
  105. typedef struct CoefVLCTable {
  106. int n; /* total number of codes */
  107. const uint32_t *huffcodes; /* VLC bit values */
  108. const uint8_t *huffbits; /* VLC bit size */
  109. const uint16_t *levels; /* table to build run/level tables */
  110. } CoefVLCTable;
  111. static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len);
  112. #include "wmadata.h"
  113. #ifdef TRACE
  114. static void dump_shorts(const char *name, const short *tab, int n)
  115. {
  116. int i;
  117. tprintf("%s[%d]:\n", name, n);
  118. for(i=0;i<n;i++) {
  119. if ((i & 7) == 0)
  120. tprintf("%4d: ", i);
  121. tprintf(" %5d.0", tab[i]);
  122. if ((i & 7) == 7)
  123. tprintf("\n");
  124. }
  125. }
  126. static void dump_floats(const char *name, int prec, const float *tab, int n)
  127. {
  128. int i;
  129. tprintf("%s[%d]:\n", name, n);
  130. for(i=0;i<n;i++) {
  131. if ((i & 7) == 0)
  132. tprintf("%4d: ", i);
  133. tprintf(" %8.*f", prec, tab[i]);
  134. if ((i & 7) == 7)
  135. tprintf("\n");
  136. }
  137. if ((i & 7) != 0)
  138. tprintf("\n");
  139. }
  140. #endif
  141. /* XXX: use same run/length optimization as mpeg decoders */
  142. static void init_coef_vlc(VLC *vlc,
  143. uint16_t **prun_table, uint16_t **plevel_table,
  144. const CoefVLCTable *vlc_table)
  145. {
  146. int n = vlc_table->n;
  147. const uint8_t *table_bits = vlc_table->huffbits;
  148. const uint32_t *table_codes = vlc_table->huffcodes;
  149. const uint16_t *levels_table = vlc_table->levels;
  150. uint16_t *run_table, *level_table;
  151. const uint16_t *p;
  152. int i, l, j, level;
  153. init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4);
  154. run_table = av_malloc(n * sizeof(uint16_t));
  155. level_table = av_malloc(n * sizeof(uint16_t));
  156. p = levels_table;
  157. i = 2;
  158. level = 1;
  159. while (i < n) {
  160. l = *p++;
  161. for(j=0;j<l;j++) {
  162. run_table[i] = j;
  163. level_table[i] = level;
  164. i++;
  165. }
  166. level++;
  167. }
  168. *prun_table = run_table;
  169. *plevel_table = level_table;
  170. }
  171. static int wma_decode_init(AVCodecContext * avctx)
  172. {
  173. WMADecodeContext *s = avctx->priv_data;
  174. int i, flags1, flags2;
  175. float *window;
  176. uint8_t *extradata;
  177. float bps1, high_freq, bps;
  178. int sample_rate1;
  179. int coef_vlc_table;
  180. s->sample_rate = avctx->sample_rate;
  181. s->nb_channels = avctx->channels;
  182. s->bit_rate = avctx->bit_rate;
  183. s->block_align = avctx->block_align;
  184. if (avctx->codec->id == CODEC_ID_WMAV1) {
  185. s->version = 1;
  186. } else {
  187. s->version = 2;
  188. }
  189. /* extract flag infos */
  190. flags1 = 0;
  191. flags2 = 0;
  192. extradata = avctx->extradata;
  193. if (s->version == 1 && avctx->extradata_size >= 4) {
  194. flags1 = extradata[0] | (extradata[1] << 8);
  195. flags2 = extradata[2] | (extradata[3] << 8);
  196. } else if (s->version == 2 && avctx->extradata_size >= 6) {
  197. flags1 = extradata[0] | (extradata[1] << 8) |
  198. (extradata[2] << 16) | (extradata[3] << 24);
  199. flags2 = extradata[4] | (extradata[5] << 8);
  200. }
  201. s->use_exp_vlc = flags2 & 0x0001;
  202. s->use_bit_reservoir = flags2 & 0x0002;
  203. s->use_variable_block_len = flags2 & 0x0004;
  204. /* compute MDCT block size */
  205. if (s->sample_rate <= 16000) {
  206. s->frame_len_bits = 9;
  207. } else if (s->sample_rate <= 22050 ||
  208. (s->sample_rate <= 32000 && s->version == 1)) {
  209. s->frame_len_bits = 10;
  210. } else {
  211. s->frame_len_bits = 11;
  212. }
  213. s->frame_len = 1 << s->frame_len_bits;
  214. if (s->use_variable_block_len) {
  215. int nb_max, nb;
  216. nb = ((flags2 >> 3) & 3) + 1;
  217. if ((s->bit_rate / s->nb_channels) >= 32000)
  218. nb += 2;
  219. nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
  220. if (nb > nb_max)
  221. nb = nb_max;
  222. s->nb_block_sizes = nb + 1;
  223. } else {
  224. s->nb_block_sizes = 1;
  225. }
  226. /* init rate dependant parameters */
  227. s->use_noise_coding = 1;
  228. high_freq = s->sample_rate * 0.5;
  229. /* if version 2, then the rates are normalized */
  230. sample_rate1 = s->sample_rate;
  231. if (s->version == 2) {
  232. if (sample_rate1 >= 44100)
  233. sample_rate1 = 44100;
  234. else if (sample_rate1 >= 22050)
  235. sample_rate1 = 22050;
  236. else if (sample_rate1 >= 16000)
  237. sample_rate1 = 16000;
  238. else if (sample_rate1 >= 11025)
  239. sample_rate1 = 11025;
  240. else if (sample_rate1 >= 8000)
  241. sample_rate1 = 8000;
  242. }
  243. bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
  244. s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0)) + 2;
  245. /* compute high frequency value and choose if noise coding should
  246. be activated */
  247. bps1 = bps;
  248. if (s->nb_channels == 2)
  249. bps1 = bps * 1.6;
  250. if (sample_rate1 == 44100) {
  251. if (bps1 >= 0.61)
  252. s->use_noise_coding = 0;
  253. else
  254. high_freq = high_freq * 0.4;
  255. } else if (sample_rate1 == 22050) {
  256. if (bps1 >= 1.16)
  257. s->use_noise_coding = 0;
  258. else if (bps1 >= 0.72)
  259. high_freq = high_freq * 0.7;
  260. else
  261. high_freq = high_freq * 0.6;
  262. } else if (sample_rate1 == 16000) {
  263. if (bps > 0.5)
  264. high_freq = high_freq * 0.5;
  265. else
  266. high_freq = high_freq * 0.3;
  267. } else if (sample_rate1 == 11025) {
  268. high_freq = high_freq * 0.7;
  269. } else if (sample_rate1 == 8000) {
  270. if (bps <= 0.625) {
  271. high_freq = high_freq * 0.5;
  272. } else if (bps > 0.75) {
  273. s->use_noise_coding = 0;
  274. } else {
  275. high_freq = high_freq * 0.65;
  276. }
  277. } else {
  278. if (bps >= 0.8) {
  279. high_freq = high_freq * 0.75;
  280. } else if (bps >= 0.6) {
  281. high_freq = high_freq * 0.6;
  282. } else {
  283. high_freq = high_freq * 0.5;
  284. }
  285. }
  286. dprintf("flags1=0x%x flags2=0x%x\n", flags1, flags2);
  287. dprintf("version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
  288. s->version, s->nb_channels, s->sample_rate, s->bit_rate,
  289. s->block_align);
  290. dprintf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
  291. bps, bps1, high_freq, s->byte_offset_bits);
  292. dprintf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
  293. s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
  294. /* compute the scale factor band sizes for each MDCT block size */
  295. {
  296. int a, b, pos, lpos, k, block_len, i, j, n;
  297. const uint8_t *table;
  298. if (s->version == 1) {
  299. s->coefs_start = 3;
  300. } else {
  301. s->coefs_start = 0;
  302. }
  303. for(k = 0; k < s->nb_block_sizes; k++) {
  304. block_len = s->frame_len >> k;
  305. if (s->version == 1) {
  306. lpos = 0;
  307. for(i=0;i<25;i++) {
  308. a = wma_critical_freqs[i];
  309. b = s->sample_rate;
  310. pos = ((block_len * 2 * a) + (b >> 1)) / b;
  311. if (pos > block_len)
  312. pos = block_len;
  313. s->exponent_bands[0][i] = pos - lpos;
  314. if (pos >= block_len) {
  315. i++;
  316. break;
  317. }
  318. lpos = pos;
  319. }
  320. s->exponent_sizes[0] = i;
  321. } else {
  322. /* hardcoded tables */
  323. table = NULL;
  324. a = s->frame_len_bits - BLOCK_MIN_BITS - k;
  325. if (a < 3) {
  326. if (s->sample_rate >= 44100)
  327. table = exponent_band_44100[a];
  328. else if (s->sample_rate >= 32000)
  329. table = exponent_band_32000[a];
  330. else if (s->sample_rate >= 22050)
  331. table = exponent_band_22050[a];
  332. }
  333. if (table) {
  334. n = *table++;
  335. for(i=0;i<n;i++)
  336. s->exponent_bands[k][i] = table[i];
  337. s->exponent_sizes[k] = n;
  338. } else {
  339. j = 0;
  340. lpos = 0;
  341. for(i=0;i<25;i++) {
  342. a = wma_critical_freqs[i];
  343. b = s->sample_rate;
  344. pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
  345. pos <<= 2;
  346. if (pos > block_len)
  347. pos = block_len;
  348. if (pos > lpos)
  349. s->exponent_bands[k][j++] = pos - lpos;
  350. if (pos >= block_len)
  351. break;
  352. lpos = pos;
  353. }
  354. s->exponent_sizes[k] = j;
  355. }
  356. }
  357. /* max number of coefs */
  358. s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
  359. /* high freq computation */
  360. s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
  361. s->sample_rate + 0.5);
  362. n = s->exponent_sizes[k];
  363. j = 0;
  364. pos = 0;
  365. for(i=0;i<n;i++) {
  366. int start, end;
  367. start = pos;
  368. pos += s->exponent_bands[k][i];
  369. end = pos;
  370. if (start < s->high_band_start[k])
  371. start = s->high_band_start[k];
  372. if (end > s->coefs_end[k])
  373. end = s->coefs_end[k];
  374. if (end > start)
  375. s->exponent_high_bands[k][j++] = end - start;
  376. }
  377. s->exponent_high_sizes[k] = j;
  378. #if 0
  379. tprintf("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
  380. s->frame_len >> k,
  381. s->coefs_end[k],
  382. s->high_band_start[k],
  383. s->exponent_high_sizes[k]);
  384. for(j=0;j<s->exponent_high_sizes[k];j++)
  385. tprintf(" %d", s->exponent_high_bands[k][j]);
  386. tprintf("\n");
  387. #endif
  388. }
  389. }
  390. #ifdef TRACE
  391. {
  392. int i, j;
  393. for(i = 0; i < s->nb_block_sizes; i++) {
  394. tprintf("%5d: n=%2d:",
  395. s->frame_len >> i,
  396. s->exponent_sizes[i]);
  397. for(j=0;j<s->exponent_sizes[i];j++)
  398. tprintf(" %d", s->exponent_bands[i][j]);
  399. tprintf("\n");
  400. }
  401. }
  402. #endif
  403. /* init MDCT */
  404. for(i = 0; i < s->nb_block_sizes; i++)
  405. ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1);
  406. /* init MDCT windows : simple sinus window */
  407. for(i = 0; i < s->nb_block_sizes; i++) {
  408. int n, j;
  409. float alpha;
  410. n = 1 << (s->frame_len_bits - i);
  411. window = av_malloc(sizeof(float) * n);
  412. alpha = M_PI / (2.0 * n);
  413. for(j=0;j<n;j++) {
  414. window[n - j - 1] = sin((j + 0.5) * alpha);
  415. }
  416. s->windows[i] = window;
  417. }
  418. s->reset_block_lengths = 1;
  419. if (s->use_noise_coding) {
  420. /* init the noise generator */
  421. if (s->use_exp_vlc)
  422. s->noise_mult = 0.02;
  423. else
  424. s->noise_mult = 0.04;
  425. #ifdef TRACE
  426. for(i=0;i<NOISE_TAB_SIZE;i++)
  427. s->noise_table[i] = 1.0 * s->noise_mult;
  428. #else
  429. {
  430. unsigned int seed;
  431. float norm;
  432. seed = 1;
  433. norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
  434. for(i=0;i<NOISE_TAB_SIZE;i++) {
  435. seed = seed * 314159 + 1;
  436. s->noise_table[i] = (float)((int)seed) * norm;
  437. }
  438. }
  439. #endif
  440. init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits),
  441. hgain_huffbits, 1, 1,
  442. hgain_huffcodes, 2, 2);
  443. }
  444. if (s->use_exp_vlc) {
  445. init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits),
  446. scale_huffbits, 1, 1,
  447. scale_huffcodes, 4, 4);
  448. } else {
  449. wma_lsp_to_curve_init(s, s->frame_len);
  450. }
  451. /* choose the VLC tables for the coefficients */
  452. coef_vlc_table = 2;
  453. if (s->sample_rate >= 32000) {
  454. if (bps1 < 0.72)
  455. coef_vlc_table = 0;
  456. else if (bps1 < 1.16)
  457. coef_vlc_table = 1;
  458. }
  459. init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
  460. &coef_vlcs[coef_vlc_table * 2]);
  461. init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
  462. &coef_vlcs[coef_vlc_table * 2 + 1]);
  463. return 0;
  464. }
  465. /* interpolate values for a bigger or smaller block. The block must
  466. have multiple sizes */
  467. static void interpolate_array(float *scale, int old_size, int new_size)
  468. {
  469. int i, j, jincr, k;
  470. float v;
  471. if (new_size > old_size) {
  472. jincr = new_size / old_size;
  473. j = new_size;
  474. for(i = old_size - 1; i >=0; i--) {
  475. v = scale[i];
  476. k = jincr;
  477. do {
  478. scale[--j] = v;
  479. } while (--k);
  480. }
  481. } else if (new_size < old_size) {
  482. j = 0;
  483. jincr = old_size / new_size;
  484. for(i = 0; i < new_size; i++) {
  485. scale[i] = scale[j];
  486. j += jincr;
  487. }
  488. }
  489. }
  490. /* compute x^-0.25 with an exponent and mantissa table. We use linear
  491. interpolation to reduce the mantissa table size at a small speed
  492. expense (linear interpolation approximately doubles the number of
  493. bits of precision). */
  494. static inline float pow_m1_4(WMADecodeContext *s, float x)
  495. {
  496. union {
  497. float f;
  498. unsigned int v;
  499. } u, t;
  500. unsigned int e, m;
  501. float a, b;
  502. u.f = x;
  503. e = u.v >> 23;
  504. m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
  505. /* build interpolation scale: 1 <= t < 2. */
  506. t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
  507. a = s->lsp_pow_m_table1[m];
  508. b = s->lsp_pow_m_table2[m];
  509. return s->lsp_pow_e_table[e] * (a + b * t.f);
  510. }
  511. static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len)
  512. {
  513. float wdel, a, b;
  514. int i, e, m;
  515. wdel = M_PI / frame_len;
  516. for(i=0;i<frame_len;i++)
  517. s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
  518. /* tables for x^-0.25 computation */
  519. for(i=0;i<256;i++) {
  520. e = i - 126;
  521. s->lsp_pow_e_table[i] = pow(2.0, e * -0.25);
  522. }
  523. /* NOTE: these two tables are needed to avoid two operations in
  524. pow_m1_4 */
  525. b = 1.0;
  526. for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) {
  527. m = (1 << LSP_POW_BITS) + i;
  528. a = (float)m * (0.5 / (1 << LSP_POW_BITS));
  529. a = pow(a, -0.25);
  530. s->lsp_pow_m_table1[i] = 2 * a - b;
  531. s->lsp_pow_m_table2[i] = b - a;
  532. b = a;
  533. }
  534. #if 0
  535. for(i=1;i<20;i++) {
  536. float v, r1, r2;
  537. v = 5.0 / i;
  538. r1 = pow_m1_4(s, v);
  539. r2 = pow(v,-0.25);
  540. printf("%f^-0.25=%f e=%f\n", v, r1, r2 - r1);
  541. }
  542. #endif
  543. }
  544. /* NOTE: We use the same code as Vorbis here */
  545. /* XXX: optimize it further with SSE/3Dnow */
  546. static void wma_lsp_to_curve(WMADecodeContext *s,
  547. float *out, float *val_max_ptr,
  548. int n, float *lsp)
  549. {
  550. int i, j;
  551. float p, q, w, v, val_max;
  552. val_max = 0;
  553. for(i=0;i<n;i++) {
  554. p = 0.5f;
  555. q = 0.5f;
  556. w = s->lsp_cos_table[i];
  557. for(j=1;j<NB_LSP_COEFS;j+=2){
  558. q *= w - lsp[j - 1];
  559. p *= w - lsp[j];
  560. }
  561. p *= p * (2.0f - w);
  562. q *= q * (2.0f + w);
  563. v = p + q;
  564. v = pow_m1_4(s, v);
  565. if (v > val_max)
  566. val_max = v;
  567. out[i] = v;
  568. }
  569. *val_max_ptr = val_max;
  570. }
  571. /* decode exponents coded with LSP coefficients (same idea as Vorbis) */
  572. static void decode_exp_lsp(WMADecodeContext *s, int ch)
  573. {
  574. float lsp_coefs[NB_LSP_COEFS];
  575. int val, i;
  576. for(i = 0; i < NB_LSP_COEFS; i++) {
  577. if (i == 0 || i >= 8)
  578. val = get_bits(&s->gb, 3);
  579. else
  580. val = get_bits(&s->gb, 4);
  581. lsp_coefs[i] = lsp_codebook[i][val];
  582. }
  583. wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
  584. s->block_len, lsp_coefs);
  585. }
  586. /* decode exponents coded with VLC codes */
  587. static int decode_exp_vlc(WMADecodeContext *s, int ch)
  588. {
  589. int last_exp, n, code;
  590. const uint16_t *ptr, *band_ptr;
  591. float v, *q, max_scale, *q_end;
  592. band_ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
  593. ptr = band_ptr;
  594. q = s->exponents[ch];
  595. q_end = q + s->block_len;
  596. max_scale = 0;
  597. if (s->version == 1) {
  598. last_exp = get_bits(&s->gb, 5) + 10;
  599. /* XXX: use a table */
  600. v = pow(10, last_exp * (1.0 / 16.0));
  601. max_scale = v;
  602. n = *ptr++;
  603. do {
  604. *q++ = v;
  605. } while (--n);
  606. }
  607. last_exp = 36;
  608. while (q < q_end) {
  609. code = get_vlc(&s->gb, &s->exp_vlc);
  610. if (code < 0)
  611. return -1;
  612. /* NOTE: this offset is the same as MPEG4 AAC ! */
  613. last_exp += code - 60;
  614. /* XXX: use a table */
  615. v = pow(10, last_exp * (1.0 / 16.0));
  616. if (v > max_scale)
  617. max_scale = v;
  618. n = *ptr++;
  619. do {
  620. *q++ = v;
  621. } while (--n);
  622. }
  623. s->max_exponent[ch] = max_scale;
  624. return 0;
  625. }
  626. /* return 0 if OK. return 1 if last block of frame. return -1 if
  627. unrecorrable error. */
  628. static int wma_decode_block(WMADecodeContext *s)
  629. {
  630. int n, v, a, ch, code, bsize;
  631. int coef_nb_bits, total_gain, parse_exponents;
  632. float window[BLOCK_MAX_SIZE * 2];
  633. int nb_coefs[MAX_CHANNELS];
  634. float mdct_norm;
  635. #ifdef TRACE
  636. tprintf("***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);
  637. #endif
  638. /* compute current block length */
  639. if (s->use_variable_block_len) {
  640. n = av_log2(s->nb_block_sizes - 1) + 1;
  641. if (s->reset_block_lengths) {
  642. s->reset_block_lengths = 0;
  643. v = get_bits(&s->gb, n);
  644. if (v >= s->nb_block_sizes)
  645. return -1;
  646. s->prev_block_len_bits = s->frame_len_bits - v;
  647. v = get_bits(&s->gb, n);
  648. if (v >= s->nb_block_sizes)
  649. return -1;
  650. s->block_len_bits = s->frame_len_bits - v;
  651. } else {
  652. /* update block lengths */
  653. s->prev_block_len_bits = s->block_len_bits;
  654. s->block_len_bits = s->next_block_len_bits;
  655. }
  656. v = get_bits(&s->gb, n);
  657. if (v >= s->nb_block_sizes)
  658. return -1;
  659. s->next_block_len_bits = s->frame_len_bits - v;
  660. } else {
  661. /* fixed block len */
  662. s->next_block_len_bits = s->frame_len_bits;
  663. s->prev_block_len_bits = s->frame_len_bits;
  664. s->block_len_bits = s->frame_len_bits;
  665. }
  666. /* now check if the block length is coherent with the frame length */
  667. s->block_len = 1 << s->block_len_bits;
  668. if ((s->block_pos + s->block_len) > s->frame_len)
  669. return -1;
  670. if (s->nb_channels == 2) {
  671. s->ms_stereo = get_bits(&s->gb, 1);
  672. }
  673. v = 0;
  674. for(ch = 0; ch < s->nb_channels; ch++) {
  675. a = get_bits(&s->gb, 1);
  676. s->channel_coded[ch] = a;
  677. v |= a;
  678. }
  679. /* if no channel coded, no need to go further */
  680. /* XXX: fix potential framing problems */
  681. if (!v)
  682. goto next;
  683. bsize = s->frame_len_bits - s->block_len_bits;
  684. /* read total gain and extract corresponding number of bits for
  685. coef escape coding */
  686. total_gain = 1;
  687. for(;;) {
  688. a = get_bits(&s->gb, 7);
  689. total_gain += a;
  690. if (a != 127)
  691. break;
  692. }
  693. if (total_gain < 15)
  694. coef_nb_bits = 13;
  695. else if (total_gain < 32)
  696. coef_nb_bits = 12;
  697. else if (total_gain < 40)
  698. coef_nb_bits = 11;
  699. else if (total_gain < 45)
  700. coef_nb_bits = 10;
  701. else
  702. coef_nb_bits = 9;
  703. /* compute number of coefficients */
  704. n = s->coefs_end[bsize] - s->coefs_start;
  705. for(ch = 0; ch < s->nb_channels; ch++)
  706. nb_coefs[ch] = n;
  707. /* complex coding */
  708. if (s->use_noise_coding) {
  709. for(ch = 0; ch < s->nb_channels; ch++) {
  710. if (s->channel_coded[ch]) {
  711. int i, n, a;
  712. n = s->exponent_high_sizes[bsize];
  713. for(i=0;i<n;i++) {
  714. a = get_bits(&s->gb, 1);
  715. s->high_band_coded[ch][i] = a;
  716. /* if noise coding, the coefficients are not transmitted */
  717. if (a)
  718. nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
  719. }
  720. }
  721. }
  722. for(ch = 0; ch < s->nb_channels; ch++) {
  723. if (s->channel_coded[ch]) {
  724. int i, n, val, code;
  725. n = s->exponent_high_sizes[bsize];
  726. val = (int)0x80000000;
  727. for(i=0;i<n;i++) {
  728. if (s->high_band_coded[ch][i]) {
  729. if (val == (int)0x80000000) {
  730. val = get_bits(&s->gb, 7) - 19;
  731. } else {
  732. code = get_vlc(&s->gb, &s->hgain_vlc);
  733. if (code < 0)
  734. return -1;
  735. val += code - 18;
  736. }
  737. s->high_band_values[ch][i] = val;
  738. }
  739. }
  740. }
  741. }
  742. }
  743. /* exposant can be interpolated in short blocks. */
  744. parse_exponents = 1;
  745. if (s->block_len_bits != s->frame_len_bits) {
  746. parse_exponents = get_bits(&s->gb, 1);
  747. }
  748. if (parse_exponents) {
  749. for(ch = 0; ch < s->nb_channels; ch++) {
  750. if (s->channel_coded[ch]) {
  751. if (s->use_exp_vlc) {
  752. if (decode_exp_vlc(s, ch) < 0)
  753. return -1;
  754. } else {
  755. decode_exp_lsp(s, ch);
  756. }
  757. }
  758. }
  759. } else {
  760. for(ch = 0; ch < s->nb_channels; ch++) {
  761. if (s->channel_coded[ch]) {
  762. interpolate_array(s->exponents[ch], 1 << s->prev_block_len_bits,
  763. s->block_len);
  764. }
  765. }
  766. }
  767. /* parse spectral coefficients : just RLE encoding */
  768. for(ch = 0; ch < s->nb_channels; ch++) {
  769. if (s->channel_coded[ch]) {
  770. VLC *coef_vlc;
  771. int level, run, sign, tindex;
  772. int16_t *ptr, *eptr;
  773. const int16_t *level_table, *run_table;
  774. /* special VLC tables are used for ms stereo because
  775. there is potentially less energy there */
  776. tindex = (ch == 1 && s->ms_stereo);
  777. coef_vlc = &s->coef_vlc[tindex];
  778. run_table = s->run_table[tindex];
  779. level_table = s->level_table[tindex];
  780. /* XXX: optimize */
  781. ptr = &s->coefs1[ch][0];
  782. eptr = ptr + nb_coefs[ch];
  783. memset(ptr, 0, s->block_len * sizeof(int16_t));
  784. for(;;) {
  785. code = get_vlc(&s->gb, coef_vlc);
  786. if (code < 0)
  787. return -1;
  788. if (code == 1) {
  789. /* EOB */
  790. break;
  791. } else if (code == 0) {
  792. /* escape */
  793. level = get_bits(&s->gb, coef_nb_bits);
  794. /* NOTE: this is rather suboptimal. reading
  795. block_len_bits would be better */
  796. run = get_bits(&s->gb, s->frame_len_bits);
  797. } else {
  798. /* normal code */
  799. run = run_table[code];
  800. level = level_table[code];
  801. }
  802. sign = get_bits(&s->gb, 1);
  803. if (!sign)
  804. level = -level;
  805. ptr += run;
  806. if (ptr >= eptr)
  807. return -1;
  808. *ptr++ = level;
  809. /* NOTE: EOB can be omitted */
  810. if (ptr >= eptr)
  811. break;
  812. }
  813. }
  814. if (s->version == 1 && s->nb_channels >= 2) {
  815. align_get_bits(&s->gb);
  816. }
  817. }
  818. /* normalize */
  819. {
  820. int n4 = s->block_len / 2;
  821. mdct_norm = 1.0 / (float)n4;
  822. if (s->version == 1) {
  823. mdct_norm *= sqrt(n4);
  824. }
  825. }
  826. /* finally compute the MDCT coefficients */
  827. for(ch = 0; ch < s->nb_channels; ch++) {
  828. if (s->channel_coded[ch]) {
  829. int16_t *coefs1;
  830. float *coefs, *exponents, mult, mult1, noise, *exp_ptr;
  831. int i, j, n, n1, last_high_band;
  832. float exp_power[HIGH_BAND_MAX_SIZE];
  833. coefs1 = s->coefs1[ch];
  834. exponents = s->exponents[ch];
  835. mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
  836. mult *= mdct_norm;
  837. coefs = s->coefs[ch];
  838. if (s->use_noise_coding) {
  839. mult1 = mult;
  840. /* very low freqs : noise */
  841. for(i = 0;i < s->coefs_start; i++) {
  842. *coefs++ = s->noise_table[s->noise_index] * (*exponents++) * mult1;
  843. s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
  844. }
  845. n1 = s->exponent_high_sizes[bsize];
  846. /* compute power of high bands */
  847. exp_ptr = exponents +
  848. s->high_band_start[bsize] -
  849. s->coefs_start;
  850. last_high_band = 0; /* avoid warning */
  851. for(j=0;j<n1;j++) {
  852. n = s->exponent_high_bands[s->frame_len_bits -
  853. s->block_len_bits][j];
  854. if (s->high_band_coded[ch][j]) {
  855. float e2, v;
  856. e2 = 0;
  857. for(i = 0;i < n; i++) {
  858. v = exp_ptr[i];
  859. e2 += v * v;
  860. }
  861. exp_power[j] = e2 / n;
  862. last_high_band = j;
  863. tprintf("%d: power=%f (%d)\n", j, exp_power[j], n);
  864. }
  865. exp_ptr += n;
  866. }
  867. /* main freqs and high freqs */
  868. for(j=-1;j<n1;j++) {
  869. if (j < 0) {
  870. n = s->high_band_start[bsize] -
  871. s->coefs_start;
  872. } else {
  873. n = s->exponent_high_bands[s->frame_len_bits -
  874. s->block_len_bits][j];
  875. }
  876. if (j >= 0 && s->high_band_coded[ch][j]) {
  877. /* use noise with specified power */
  878. mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
  879. /* XXX: use a table */
  880. mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);
  881. mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
  882. mult1 *= mdct_norm;
  883. for(i = 0;i < n; i++) {
  884. noise = s->noise_table[s->noise_index];
  885. s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
  886. *coefs++ = (*exponents++) * noise * mult1;
  887. }
  888. } else {
  889. /* coded values + small noise */
  890. for(i = 0;i < n; i++) {
  891. noise = s->noise_table[s->noise_index];
  892. s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
  893. *coefs++ = ((*coefs1++) + noise) * (*exponents++) * mult;
  894. }
  895. }
  896. }
  897. /* very high freqs : noise */
  898. n = s->block_len - s->coefs_end[bsize];
  899. mult1 = mult * exponents[-1];
  900. for(i = 0; i < n; i++) {
  901. *coefs++ = s->noise_table[s->noise_index] * mult1;
  902. s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
  903. }
  904. } else {
  905. /* XXX: optimize more */
  906. for(i = 0;i < s->coefs_start; i++)
  907. *coefs++ = 0.0;
  908. n = nb_coefs[ch];
  909. for(i = 0;i < n; i++) {
  910. *coefs++ = coefs1[i] * exponents[i] * mult;
  911. }
  912. n = s->block_len - s->coefs_end[bsize];
  913. for(i = 0;i < n; i++)
  914. *coefs++ = 0.0;
  915. }
  916. }
  917. }
  918. #ifdef TRACE
  919. for(ch = 0; ch < s->nb_channels; ch++) {
  920. if (s->channel_coded[ch]) {
  921. dump_floats("exponents", 3, s->exponents[ch], s->block_len);
  922. dump_floats("coefs", 1, s->coefs[ch], s->block_len);
  923. }
  924. }
  925. #endif
  926. if (s->ms_stereo && s->channel_coded[1]) {
  927. float a, b;
  928. int i;
  929. /* nominal case for ms stereo: we do it before mdct */
  930. /* no need to optimize this case because it should almost
  931. never happen */
  932. if (!s->channel_coded[0]) {
  933. tprintf("rare ms-stereo case happened\n");
  934. memset(s->coefs[0], 0, sizeof(float) * s->block_len);
  935. s->channel_coded[0] = 1;
  936. }
  937. for(i = 0; i < s->block_len; i++) {
  938. a = s->coefs[0][i];
  939. b = s->coefs[1][i];
  940. s->coefs[0][i] = a + b;
  941. s->coefs[1][i] = a - b;
  942. }
  943. }
  944. /* build the window : we ensure that when the windows overlap
  945. their squared sum is always 1 (MDCT reconstruction rule) */
  946. /* XXX: merge with output */
  947. {
  948. int i, next_block_len, block_len, prev_block_len, n;
  949. float *wptr;
  950. block_len = s->block_len;
  951. prev_block_len = 1 << s->prev_block_len_bits;
  952. next_block_len = 1 << s->next_block_len_bits;
  953. /* right part */
  954. wptr = window + block_len;
  955. if (block_len <= next_block_len) {
  956. for(i=0;i<block_len;i++)
  957. *wptr++ = s->windows[bsize][i];
  958. } else {
  959. /* overlap */
  960. n = (block_len / 2) - (next_block_len / 2);
  961. for(i=0;i<n;i++)
  962. *wptr++ = 1.0;
  963. for(i=0;i<next_block_len;i++)
  964. *wptr++ = s->windows[s->frame_len_bits - s->next_block_len_bits][i];
  965. for(i=0;i<n;i++)
  966. *wptr++ = 0.0;
  967. }
  968. /* left part */
  969. wptr = window + block_len;
  970. if (block_len <= prev_block_len) {
  971. for(i=0;i<block_len;i++)
  972. *--wptr = s->windows[bsize][i];
  973. } else {
  974. /* overlap */
  975. n = (block_len / 2) - (prev_block_len / 2);
  976. for(i=0;i<n;i++)
  977. *--wptr = 1.0;
  978. for(i=0;i<prev_block_len;i++)
  979. *--wptr = s->windows[s->frame_len_bits - s->prev_block_len_bits][i];
  980. for(i=0;i<n;i++)
  981. *--wptr = 0.0;
  982. }
  983. }
  984. for(ch = 0; ch < s->nb_channels; ch++) {
  985. if (s->channel_coded[ch]) {
  986. FFTSample output[BLOCK_MAX_SIZE * 2] __attribute__((aligned(16)));
  987. float *ptr;
  988. int i, n4, index, n;
  989. n = s->block_len;
  990. n4 = s->block_len / 2;
  991. ff_imdct_calc(&s->mdct_ctx[bsize],
  992. output, s->coefs[ch], s->mdct_tmp);
  993. /* XXX: optimize all that by build the window and
  994. multipying/adding at the same time */
  995. /* multiply by the window */
  996. for(i=0;i<n * 2;i++) {
  997. output[i] *= window[i];
  998. }
  999. /* add in the frame */
  1000. index = (s->frame_len / 2) + s->block_pos - n4;
  1001. ptr = &s->frame_out[ch][index];
  1002. for(i=0;i<n * 2;i++) {
  1003. *ptr += output[i];
  1004. ptr++;
  1005. }
  1006. /* specific fast case for ms-stereo : add to second
  1007. channel if it is not coded */
  1008. if (s->ms_stereo && !s->channel_coded[1]) {
  1009. ptr = &s->frame_out[1][index];
  1010. for(i=0;i<n * 2;i++) {
  1011. *ptr += output[i];
  1012. ptr++;
  1013. }
  1014. }
  1015. }
  1016. }
  1017. next:
  1018. /* update block number */
  1019. s->block_num++;
  1020. s->block_pos += s->block_len;
  1021. if (s->block_pos >= s->frame_len)
  1022. return 1;
  1023. else
  1024. return 0;
  1025. }
  1026. /* decode a frame of frame_len samples */
  1027. static int wma_decode_frame(WMADecodeContext *s, int16_t *samples)
  1028. {
  1029. int ret, i, n, a, ch, incr;
  1030. int16_t *ptr;
  1031. float *iptr;
  1032. #ifdef TRACE
  1033. tprintf("***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len);
  1034. #endif
  1035. /* read each block */
  1036. s->block_num = 0;
  1037. s->block_pos = 0;
  1038. for(;;) {
  1039. ret = wma_decode_block(s);
  1040. if (ret < 0)
  1041. return -1;
  1042. if (ret)
  1043. break;
  1044. }
  1045. /* convert frame to integer */
  1046. n = s->frame_len;
  1047. incr = s->nb_channels;
  1048. for(ch = 0; ch < s->nb_channels; ch++) {
  1049. ptr = samples + ch;
  1050. iptr = s->frame_out[ch];
  1051. for(i=0;i<n;i++) {
  1052. a = lrintf(*iptr++);
  1053. if (a > 32767)
  1054. a = 32767;
  1055. else if (a < -32768)
  1056. a = -32768;
  1057. *ptr = a;
  1058. ptr += incr;
  1059. }
  1060. /* prepare for next block */
  1061. memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
  1062. s->frame_len * sizeof(float));
  1063. /* XXX: suppress this */
  1064. memset(&s->frame_out[ch][s->frame_len], 0,
  1065. s->frame_len * sizeof(float));
  1066. }
  1067. #ifdef TRACE
  1068. dump_shorts("samples", samples, n * s->nb_channels);
  1069. #endif
  1070. return 0;
  1071. }
  1072. static int wma_decode_superframe(AVCodecContext *avctx,
  1073. void *data, int *data_size,
  1074. uint8_t *buf, int buf_size)
  1075. {
  1076. WMADecodeContext *s = avctx->priv_data;
  1077. int nb_frames, bit_offset, i, pos, len;
  1078. uint8_t *q;
  1079. int16_t *samples;
  1080. tprintf("***decode_superframe:\n");
  1081. if(buf_size==0){
  1082. s->last_superframe_len = 0;
  1083. return 0;
  1084. }
  1085. samples = data;
  1086. init_get_bits(&s->gb, buf, buf_size*8);
  1087. if (s->use_bit_reservoir) {
  1088. /* read super frame header */
  1089. get_bits(&s->gb, 4); /* super frame index */
  1090. nb_frames = get_bits(&s->gb, 4) - 1;
  1091. bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
  1092. if (s->last_superframe_len > 0) {
  1093. // printf("skip=%d\n", s->last_bitoffset);
  1094. /* add bit_offset bits to last frame */
  1095. if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
  1096. MAX_CODED_SUPERFRAME_SIZE)
  1097. goto fail;
  1098. q = s->last_superframe + s->last_superframe_len;
  1099. len = bit_offset;
  1100. while (len > 0) {
  1101. *q++ = (get_bits)(&s->gb, 8);
  1102. len -= 8;
  1103. }
  1104. if (len > 0) {
  1105. *q++ = (get_bits)(&s->gb, len) << (8 - len);
  1106. }
  1107. /* XXX: bit_offset bits into last frame */
  1108. init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
  1109. /* skip unused bits */
  1110. if (s->last_bitoffset > 0)
  1111. skip_bits(&s->gb, s->last_bitoffset);
  1112. /* this frame is stored in the last superframe and in the
  1113. current one */
  1114. if (wma_decode_frame(s, samples) < 0)
  1115. goto fail;
  1116. samples += s->nb_channels * s->frame_len;
  1117. }
  1118. /* read each frame starting from bit_offset */
  1119. pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
  1120. init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
  1121. len = pos & 7;
  1122. if (len > 0)
  1123. skip_bits(&s->gb, len);
  1124. s->reset_block_lengths = 1;
  1125. for(i=0;i<nb_frames;i++) {
  1126. if (wma_decode_frame(s, samples) < 0)
  1127. goto fail;
  1128. samples += s->nb_channels * s->frame_len;
  1129. }
  1130. /* we copy the end of the frame in the last frame buffer */
  1131. pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
  1132. s->last_bitoffset = pos & 7;
  1133. pos >>= 3;
  1134. len = buf_size - pos;
  1135. if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
  1136. goto fail;
  1137. }
  1138. s->last_superframe_len = len;
  1139. memcpy(s->last_superframe, buf + pos, len);
  1140. } else {
  1141. /* single frame decode */
  1142. if (wma_decode_frame(s, samples) < 0)
  1143. goto fail;
  1144. samples += s->nb_channels * s->frame_len;
  1145. }
  1146. *data_size = (int8_t *)samples - (int8_t *)data;
  1147. return s->block_align;
  1148. fail:
  1149. /* when error, we reset the bit reservoir */
  1150. s->last_superframe_len = 0;
  1151. return -1;
  1152. }
  1153. static int wma_decode_end(AVCodecContext *avctx)
  1154. {
  1155. WMADecodeContext *s = avctx->priv_data;
  1156. int i;
  1157. for(i = 0; i < s->nb_block_sizes; i++)
  1158. ff_mdct_end(&s->mdct_ctx[i]);
  1159. for(i = 0; i < s->nb_block_sizes; i++)
  1160. av_free(s->windows[i]);
  1161. if (s->use_exp_vlc) {
  1162. free_vlc(&s->exp_vlc);
  1163. }
  1164. if (s->use_noise_coding) {
  1165. free_vlc(&s->hgain_vlc);
  1166. }
  1167. for(i = 0;i < 2; i++) {
  1168. free_vlc(&s->coef_vlc[i]);
  1169. av_free(s->run_table[i]);
  1170. av_free(s->level_table[i]);
  1171. }
  1172. return 0;
  1173. }
  1174. AVCodec wmav1_decoder =
  1175. {
  1176. "wmav1",
  1177. CODEC_TYPE_AUDIO,
  1178. CODEC_ID_WMAV1,
  1179. sizeof(WMADecodeContext),
  1180. wma_decode_init,
  1181. NULL,
  1182. wma_decode_end,
  1183. wma_decode_superframe,
  1184. };
  1185. AVCodec wmav2_decoder =
  1186. {
  1187. "wmav2",
  1188. CODEC_TYPE_AUDIO,
  1189. CODEC_ID_WMAV2,
  1190. sizeof(WMADecodeContext),
  1191. wma_decode_init,
  1192. NULL,
  1193. wma_decode_end,
  1194. wma_decode_superframe,
  1195. };