Libav
wmadec.c
Go to the documentation of this file.
1 /*
2  * WMA compatible decoder
3  * Copyright (c) 2002 The Libav Project
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
36 #include "libavutil/attributes.h"
37 #include "avcodec.h"
38 #include "internal.h"
39 #include "wma.h"
40 
41 #undef NDEBUG
42 #include <assert.h>
43 
44 #define EXPVLCBITS 8
45 #define EXPMAX ((19+EXPVLCBITS-1)/EXPVLCBITS)
46 
47 #define HGAINVLCBITS 9
48 #define HGAINMAX ((13+HGAINVLCBITS-1)/HGAINVLCBITS)
49 
50 static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len);
51 
52 #ifdef TRACE
53 static void dump_floats(WMACodecContext *s, const char *name, int prec, const float *tab, int n)
54 {
55  int i;
56 
57  tprintf(s->avctx, "%s[%d]:\n", name, n);
58  for(i=0;i<n;i++) {
59  if ((i & 7) == 0)
60  tprintf(s->avctx, "%4d: ", i);
61  tprintf(s->avctx, " %8.*f", prec, tab[i]);
62  if ((i & 7) == 7)
63  tprintf(s->avctx, "\n");
64  }
65  if ((i & 7) != 0)
66  tprintf(s->avctx, "\n");
67 }
68 #endif
69 
71 {
72  WMACodecContext *s = avctx->priv_data;
73  int i, flags2;
74  uint8_t *extradata;
75 
76  if (!avctx->block_align) {
77  av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
78  return AVERROR(EINVAL);
79  }
80 
81  s->avctx = avctx;
82 
83  /* extract flag infos */
84  flags2 = 0;
85  extradata = avctx->extradata;
86  if (avctx->codec->id == AV_CODEC_ID_WMAV1 && avctx->extradata_size >= 4) {
87  flags2 = AV_RL16(extradata+2);
88  } else if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 6) {
89  flags2 = AV_RL16(extradata+4);
90  }
91 
92  s->use_exp_vlc = flags2 & 0x0001;
93  s->use_bit_reservoir = flags2 & 0x0002;
94  s->use_variable_block_len = flags2 & 0x0004;
95 
96  if(ff_wma_init(avctx, flags2)<0)
97  return -1;
98 
99  /* init MDCT */
100  for(i = 0; i < s->nb_block_sizes; i++)
101  ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1, 1.0 / 32768.0);
102 
103  if (s->use_noise_coding) {
105  ff_wma_hgain_huffbits, 1, 1,
106  ff_wma_hgain_huffcodes, 2, 2, 0);
107  }
108 
109  if (s->use_exp_vlc) {
110  init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits), //FIXME move out of context
112  ff_aac_scalefactor_code, 4, 4, 0);
113  } else {
115  }
116 
118 
119  return 0;
120 }
121 
128 static inline float pow_m1_4(WMACodecContext *s, float x)
129 {
130  union {
131  float f;
132  unsigned int v;
133  } u, t;
134  unsigned int e, m;
135  float a, b;
136 
137  u.f = x;
138  e = u.v >> 23;
139  m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
140  /* build interpolation scale: 1 <= t < 2. */
141  t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
142  a = s->lsp_pow_m_table1[m];
143  b = s->lsp_pow_m_table2[m];
144  return s->lsp_pow_e_table[e] * (a + b * t.f);
145 }
146 
147 static av_cold void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
148 {
149  float wdel, a, b;
150  int i, e, m;
151 
152  wdel = M_PI / frame_len;
153  for(i=0;i<frame_len;i++)
154  s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
155 
156  /* tables for x^-0.25 computation */
157  for(i=0;i<256;i++) {
158  e = i - 126;
159  s->lsp_pow_e_table[i] = pow(2.0, e * -0.25);
160  }
161 
162  /* NOTE: these two tables are needed to avoid two operations in
163  pow_m1_4 */
164  b = 1.0;
165  for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) {
166  m = (1 << LSP_POW_BITS) + i;
167  a = (float)m * (0.5 / (1 << LSP_POW_BITS));
168  a = pow(a, -0.25);
169  s->lsp_pow_m_table1[i] = 2 * a - b;
170  s->lsp_pow_m_table2[i] = b - a;
171  b = a;
172  }
173 }
174 
180  float *out, float *val_max_ptr,
181  int n, float *lsp)
182 {
183  int i, j;
184  float p, q, w, v, val_max;
185 
186  val_max = 0;
187  for(i=0;i<n;i++) {
188  p = 0.5f;
189  q = 0.5f;
190  w = s->lsp_cos_table[i];
191  for(j=1;j<NB_LSP_COEFS;j+=2){
192  q *= w - lsp[j - 1];
193  p *= w - lsp[j];
194  }
195  p *= p * (2.0f - w);
196  q *= q * (2.0f + w);
197  v = p + q;
198  v = pow_m1_4(s, v);
199  if (v > val_max)
200  val_max = v;
201  out[i] = v;
202  }
203  *val_max_ptr = val_max;
204 }
205 
209 static void decode_exp_lsp(WMACodecContext *s, int ch)
210 {
211  float lsp_coefs[NB_LSP_COEFS];
212  int val, i;
213 
214  for(i = 0; i < NB_LSP_COEFS; i++) {
215  if (i == 0 || i >= 8)
216  val = get_bits(&s->gb, 3);
217  else
218  val = get_bits(&s->gb, 4);
219  lsp_coefs[i] = ff_wma_lsp_codebook[i][val];
220  }
221 
222  wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
223  s->block_len, lsp_coefs);
224 }
225 
227 static const float pow_tab[] = {
228  1.7782794100389e-04, 2.0535250264571e-04,
229  2.3713737056617e-04, 2.7384196342644e-04,
230  3.1622776601684e-04, 3.6517412725484e-04,
231  4.2169650342858e-04, 4.8696752516586e-04,
232  5.6234132519035e-04, 6.4938163157621e-04,
233  7.4989420933246e-04, 8.6596432336006e-04,
234  1.0000000000000e-03, 1.1547819846895e-03,
235  1.3335214321633e-03, 1.5399265260595e-03,
236  1.7782794100389e-03, 2.0535250264571e-03,
237  2.3713737056617e-03, 2.7384196342644e-03,
238  3.1622776601684e-03, 3.6517412725484e-03,
239  4.2169650342858e-03, 4.8696752516586e-03,
240  5.6234132519035e-03, 6.4938163157621e-03,
241  7.4989420933246e-03, 8.6596432336006e-03,
242  1.0000000000000e-02, 1.1547819846895e-02,
243  1.3335214321633e-02, 1.5399265260595e-02,
244  1.7782794100389e-02, 2.0535250264571e-02,
245  2.3713737056617e-02, 2.7384196342644e-02,
246  3.1622776601684e-02, 3.6517412725484e-02,
247  4.2169650342858e-02, 4.8696752516586e-02,
248  5.6234132519035e-02, 6.4938163157621e-02,
249  7.4989420933246e-02, 8.6596432336007e-02,
250  1.0000000000000e-01, 1.1547819846895e-01,
251  1.3335214321633e-01, 1.5399265260595e-01,
252  1.7782794100389e-01, 2.0535250264571e-01,
253  2.3713737056617e-01, 2.7384196342644e-01,
254  3.1622776601684e-01, 3.6517412725484e-01,
255  4.2169650342858e-01, 4.8696752516586e-01,
256  5.6234132519035e-01, 6.4938163157621e-01,
257  7.4989420933246e-01, 8.6596432336007e-01,
258  1.0000000000000e+00, 1.1547819846895e+00,
259  1.3335214321633e+00, 1.5399265260595e+00,
260  1.7782794100389e+00, 2.0535250264571e+00,
261  2.3713737056617e+00, 2.7384196342644e+00,
262  3.1622776601684e+00, 3.6517412725484e+00,
263  4.2169650342858e+00, 4.8696752516586e+00,
264  5.6234132519035e+00, 6.4938163157621e+00,
265  7.4989420933246e+00, 8.6596432336007e+00,
266  1.0000000000000e+01, 1.1547819846895e+01,
267  1.3335214321633e+01, 1.5399265260595e+01,
268  1.7782794100389e+01, 2.0535250264571e+01,
269  2.3713737056617e+01, 2.7384196342644e+01,
270  3.1622776601684e+01, 3.6517412725484e+01,
271  4.2169650342858e+01, 4.8696752516586e+01,
272  5.6234132519035e+01, 6.4938163157621e+01,
273  7.4989420933246e+01, 8.6596432336007e+01,
274  1.0000000000000e+02, 1.1547819846895e+02,
275  1.3335214321633e+02, 1.5399265260595e+02,
276  1.7782794100389e+02, 2.0535250264571e+02,
277  2.3713737056617e+02, 2.7384196342644e+02,
278  3.1622776601684e+02, 3.6517412725484e+02,
279  4.2169650342858e+02, 4.8696752516586e+02,
280  5.6234132519035e+02, 6.4938163157621e+02,
281  7.4989420933246e+02, 8.6596432336007e+02,
282  1.0000000000000e+03, 1.1547819846895e+03,
283  1.3335214321633e+03, 1.5399265260595e+03,
284  1.7782794100389e+03, 2.0535250264571e+03,
285  2.3713737056617e+03, 2.7384196342644e+03,
286  3.1622776601684e+03, 3.6517412725484e+03,
287  4.2169650342858e+03, 4.8696752516586e+03,
288  5.6234132519035e+03, 6.4938163157621e+03,
289  7.4989420933246e+03, 8.6596432336007e+03,
290  1.0000000000000e+04, 1.1547819846895e+04,
291  1.3335214321633e+04, 1.5399265260595e+04,
292  1.7782794100389e+04, 2.0535250264571e+04,
293  2.3713737056617e+04, 2.7384196342644e+04,
294  3.1622776601684e+04, 3.6517412725484e+04,
295  4.2169650342858e+04, 4.8696752516586e+04,
296  5.6234132519035e+04, 6.4938163157621e+04,
297  7.4989420933246e+04, 8.6596432336007e+04,
298  1.0000000000000e+05, 1.1547819846895e+05,
299  1.3335214321633e+05, 1.5399265260595e+05,
300  1.7782794100389e+05, 2.0535250264571e+05,
301  2.3713737056617e+05, 2.7384196342644e+05,
302  3.1622776601684e+05, 3.6517412725484e+05,
303  4.2169650342858e+05, 4.8696752516586e+05,
304  5.6234132519035e+05, 6.4938163157621e+05,
305  7.4989420933246e+05, 8.6596432336007e+05,
306 };
307 
311 static int decode_exp_vlc(WMACodecContext *s, int ch)
312 {
313  int last_exp, n, code;
314  const uint16_t *ptr;
315  float v, max_scale;
316  uint32_t *q, *q_end, iv;
317  const float *ptab = pow_tab + 60;
318  const uint32_t *iptab = (const uint32_t*)ptab;
319 
320  ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
321  q = (uint32_t *)s->exponents[ch];
322  q_end = q + s->block_len;
323  max_scale = 0;
324  if (s->version == 1) {
325  last_exp = get_bits(&s->gb, 5) + 10;
326  v = ptab[last_exp];
327  iv = iptab[last_exp];
328  max_scale = v;
329  n = *ptr++;
330  switch (n & 3) do {
331  case 0: *q++ = iv;
332  case 3: *q++ = iv;
333  case 2: *q++ = iv;
334  case 1: *q++ = iv;
335  } while ((n -= 4) > 0);
336  }else
337  last_exp = 36;
338 
339  while (q < q_end) {
340  code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
341  if (code < 0){
342  av_log(s->avctx, AV_LOG_ERROR, "Exponent vlc invalid\n");
343  return -1;
344  }
345  /* NOTE: this offset is the same as MPEG4 AAC ! */
346  last_exp += code - 60;
347  if ((unsigned)last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {
348  av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
349  last_exp);
350  return -1;
351  }
352  v = ptab[last_exp];
353  iv = iptab[last_exp];
354  if (v > max_scale)
355  max_scale = v;
356  n = *ptr++;
357  switch (n & 3) do {
358  case 0: *q++ = iv;
359  case 3: *q++ = iv;
360  case 2: *q++ = iv;
361  case 1: *q++ = iv;
362  } while ((n -= 4) > 0);
363  }
364  s->max_exponent[ch] = max_scale;
365  return 0;
366 }
367 
368 
375 static void wma_window(WMACodecContext *s, float *out)
376 {
377  float *in = s->output;
378  int block_len, bsize, n;
379 
380  /* left part */
381  if (s->block_len_bits <= s->prev_block_len_bits) {
382  block_len = s->block_len;
383  bsize = s->frame_len_bits - s->block_len_bits;
384 
385  s->fdsp.vector_fmul_add(out, in, s->windows[bsize],
386  out, block_len);
387 
388  } else {
389  block_len = 1 << s->prev_block_len_bits;
390  n = (s->block_len - block_len) / 2;
391  bsize = s->frame_len_bits - s->prev_block_len_bits;
392 
393  s->fdsp.vector_fmul_add(out+n, in+n, s->windows[bsize],
394  out+n, block_len);
395 
396  memcpy(out+n+block_len, in+n+block_len, n*sizeof(float));
397  }
398 
399  out += s->block_len;
400  in += s->block_len;
401 
402  /* right part */
403  if (s->block_len_bits <= s->next_block_len_bits) {
404  block_len = s->block_len;
405  bsize = s->frame_len_bits - s->block_len_bits;
406 
407  s->fdsp.vector_fmul_reverse(out, in, s->windows[bsize], block_len);
408 
409  } else {
410  block_len = 1 << s->next_block_len_bits;
411  n = (s->block_len - block_len) / 2;
412  bsize = s->frame_len_bits - s->next_block_len_bits;
413 
414  memcpy(out, in, n*sizeof(float));
415 
416  s->fdsp.vector_fmul_reverse(out+n, in+n, s->windows[bsize], block_len);
417 
418  memset(out+n+block_len, 0, n*sizeof(float));
419  }
420 }
421 
422 
428 {
429  int n, v, a, ch, bsize;
430  int coef_nb_bits, total_gain;
431  int nb_coefs[MAX_CHANNELS];
432  float mdct_norm;
433  FFTContext *mdct;
434 
435 #ifdef TRACE
436  tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);
437 #endif
438 
439  /* compute current block length */
440  if (s->use_variable_block_len) {
441  n = av_log2(s->nb_block_sizes - 1) + 1;
442 
443  if (s->reset_block_lengths) {
444  s->reset_block_lengths = 0;
445  v = get_bits(&s->gb, n);
446  if (v >= s->nb_block_sizes){
447  av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v);
448  return -1;
449  }
451  v = get_bits(&s->gb, n);
452  if (v >= s->nb_block_sizes){
453  av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v);
454  return -1;
455  }
456  s->block_len_bits = s->frame_len_bits - v;
457  } else {
458  /* update block lengths */
461  }
462  v = get_bits(&s->gb, n);
463  if (v >= s->nb_block_sizes){
464  av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v);
465  return -1;
466  }
468  } else {
469  /* fixed block len */
473  }
474 
475  /* now check if the block length is coherent with the frame length */
476  s->block_len = 1 << s->block_len_bits;
477  if ((s->block_pos + s->block_len) > s->frame_len){
478  av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
479  return -1;
480  }
481 
482  if (s->avctx->channels == 2) {
483  s->ms_stereo = get_bits1(&s->gb);
484  }
485  v = 0;
486  for(ch = 0; ch < s->avctx->channels; ch++) {
487  a = get_bits1(&s->gb);
488  s->channel_coded[ch] = a;
489  v |= a;
490  }
491 
492  bsize = s->frame_len_bits - s->block_len_bits;
493 
494  /* if no channel coded, no need to go further */
495  /* XXX: fix potential framing problems */
496  if (!v)
497  goto next;
498 
499  /* read total gain and extract corresponding number of bits for
500  coef escape coding */
501  total_gain = 1;
502  for(;;) {
503  a = get_bits(&s->gb, 7);
504  total_gain += a;
505  if (a != 127)
506  break;
507  }
508 
509  coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);
510 
511  /* compute number of coefficients */
512  n = s->coefs_end[bsize] - s->coefs_start;
513  for(ch = 0; ch < s->avctx->channels; ch++)
514  nb_coefs[ch] = n;
515 
516  /* complex coding */
517  if (s->use_noise_coding) {
518 
519  for(ch = 0; ch < s->avctx->channels; ch++) {
520  if (s->channel_coded[ch]) {
521  int i, n, a;
522  n = s->exponent_high_sizes[bsize];
523  for(i=0;i<n;i++) {
524  a = get_bits1(&s->gb);
525  s->high_band_coded[ch][i] = a;
526  /* if noise coding, the coefficients are not transmitted */
527  if (a)
528  nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
529  }
530  }
531  }
532  for(ch = 0; ch < s->avctx->channels; ch++) {
533  if (s->channel_coded[ch]) {
534  int i, n, val, code;
535 
536  n = s->exponent_high_sizes[bsize];
537  val = (int)0x80000000;
538  for(i=0;i<n;i++) {
539  if (s->high_band_coded[ch][i]) {
540  if (val == (int)0x80000000) {
541  val = get_bits(&s->gb, 7) - 19;
542  } else {
543  code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
544  if (code < 0){
545  av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n");
546  return -1;
547  }
548  val += code - 18;
549  }
550  s->high_band_values[ch][i] = val;
551  }
552  }
553  }
554  }
555  }
556 
557  /* exponents can be reused in short blocks. */
558  if ((s->block_len_bits == s->frame_len_bits) ||
559  get_bits1(&s->gb)) {
560  for(ch = 0; ch < s->avctx->channels; ch++) {
561  if (s->channel_coded[ch]) {
562  if (s->use_exp_vlc) {
563  if (decode_exp_vlc(s, ch) < 0)
564  return -1;
565  } else {
566  decode_exp_lsp(s, ch);
567  }
568  s->exponents_bsize[ch] = bsize;
569  }
570  }
571  }
572 
573  /* parse spectral coefficients : just RLE encoding */
574  for (ch = 0; ch < s->avctx->channels; ch++) {
575  if (s->channel_coded[ch]) {
576  int tindex;
577  WMACoef* ptr = &s->coefs1[ch][0];
578 
579  /* special VLC tables are used for ms stereo because
580  there is potentially less energy there */
581  tindex = (ch == 1 && s->ms_stereo);
582  memset(ptr, 0, s->block_len * sizeof(WMACoef));
583  ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex],
584  s->level_table[tindex], s->run_table[tindex],
585  0, ptr, 0, nb_coefs[ch],
586  s->block_len, s->frame_len_bits, coef_nb_bits);
587  }
588  if (s->version == 1 && s->avctx->channels >= 2) {
589  align_get_bits(&s->gb);
590  }
591  }
592 
593  /* normalize */
594  {
595  int n4 = s->block_len / 2;
596  mdct_norm = 1.0 / (float)n4;
597  if (s->version == 1) {
598  mdct_norm *= sqrt(n4);
599  }
600  }
601 
602  /* finally compute the MDCT coefficients */
603  for (ch = 0; ch < s->avctx->channels; ch++) {
604  if (s->channel_coded[ch]) {
605  WMACoef *coefs1;
606  float *coefs, *exponents, mult, mult1, noise;
607  int i, j, n, n1, last_high_band, esize;
608  float exp_power[HIGH_BAND_MAX_SIZE];
609 
610  coefs1 = s->coefs1[ch];
611  exponents = s->exponents[ch];
612  esize = s->exponents_bsize[ch];
613  mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
614  mult *= mdct_norm;
615  coefs = s->coefs[ch];
616  if (s->use_noise_coding) {
617  mult1 = mult;
618  /* very low freqs : noise */
619  for(i = 0;i < s->coefs_start; i++) {
620  *coefs++ = s->noise_table[s->noise_index] *
621  exponents[i<<bsize>>esize] * mult1;
622  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
623  }
624 
625  n1 = s->exponent_high_sizes[bsize];
626 
627  /* compute power of high bands */
628  exponents = s->exponents[ch] +
629  (s->high_band_start[bsize]<<bsize>>esize);
630  last_high_band = 0; /* avoid warning */
631  for(j=0;j<n1;j++) {
633  s->block_len_bits][j];
634  if (s->high_band_coded[ch][j]) {
635  float e2, v;
636  e2 = 0;
637  for(i = 0;i < n; i++) {
638  v = exponents[i<<bsize>>esize];
639  e2 += v * v;
640  }
641  exp_power[j] = e2 / n;
642  last_high_band = j;
643  tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
644  }
645  exponents += n<<bsize>>esize;
646  }
647 
648  /* main freqs and high freqs */
649  exponents = s->exponents[ch] + (s->coefs_start<<bsize>>esize);
650  for(j=-1;j<n1;j++) {
651  if (j < 0) {
652  n = s->high_band_start[bsize] -
653  s->coefs_start;
654  } else {
656  s->block_len_bits][j];
657  }
658  if (j >= 0 && s->high_band_coded[ch][j]) {
659  /* use noise with specified power */
660  mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
661  /* XXX: use a table */
662  mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);
663  mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
664  mult1 *= mdct_norm;
665  for(i = 0;i < n; i++) {
666  noise = s->noise_table[s->noise_index];
667  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
668  *coefs++ = noise *
669  exponents[i<<bsize>>esize] * mult1;
670  }
671  exponents += n<<bsize>>esize;
672  } else {
673  /* coded values + small noise */
674  for(i = 0;i < n; i++) {
675  noise = s->noise_table[s->noise_index];
676  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
677  *coefs++ = ((*coefs1++) + noise) *
678  exponents[i<<bsize>>esize] * mult;
679  }
680  exponents += n<<bsize>>esize;
681  }
682  }
683 
684  /* very high freqs : noise */
685  n = s->block_len - s->coefs_end[bsize];
686  mult1 = mult * exponents[((-1<<bsize))>>esize];
687  for(i = 0; i < n; i++) {
688  *coefs++ = s->noise_table[s->noise_index] * mult1;
689  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
690  }
691  } else {
692  /* XXX: optimize more */
693  for(i = 0;i < s->coefs_start; i++)
694  *coefs++ = 0.0;
695  n = nb_coefs[ch];
696  for(i = 0;i < n; i++) {
697  *coefs++ = coefs1[i] * exponents[i<<bsize>>esize] * mult;
698  }
699  n = s->block_len - s->coefs_end[bsize];
700  for(i = 0;i < n; i++)
701  *coefs++ = 0.0;
702  }
703  }
704  }
705 
706 #ifdef TRACE
707  for (ch = 0; ch < s->avctx->channels; ch++) {
708  if (s->channel_coded[ch]) {
709  dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
710  dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
711  }
712  }
713 #endif
714 
715  if (s->ms_stereo && s->channel_coded[1]) {
716  /* nominal case for ms stereo: we do it before mdct */
717  /* no need to optimize this case because it should almost
718  never happen */
719  if (!s->channel_coded[0]) {
720  tprintf(s->avctx, "rare ms-stereo case happened\n");
721  memset(s->coefs[0], 0, sizeof(float) * s->block_len);
722  s->channel_coded[0] = 1;
723  }
724 
725  s->fdsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len);
726  }
727 
728 next:
729  mdct = &s->mdct_ctx[bsize];
730 
731  for (ch = 0; ch < s->avctx->channels; ch++) {
732  int n4, index;
733 
734  n4 = s->block_len / 2;
735  if(s->channel_coded[ch]){
736  mdct->imdct_calc(mdct, s->output, s->coefs[ch]);
737  }else if(!(s->ms_stereo && ch==1))
738  memset(s->output, 0, sizeof(s->output));
739 
740  /* multiply by the window and add in the frame */
741  index = (s->frame_len / 2) + s->block_pos - n4;
742  wma_window(s, &s->frame_out[ch][index]);
743  }
744 
745  /* update block number */
746  s->block_num++;
747  s->block_pos += s->block_len;
748  if (s->block_pos >= s->frame_len)
749  return 1;
750  else
751  return 0;
752 }
753 
754 /* decode a frame of frame_len samples */
755 static int wma_decode_frame(WMACodecContext *s, float **samples,
756  int samples_offset)
757 {
758  int ret, ch;
759 
760 #ifdef TRACE
761  tprintf(s->avctx, "***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len);
762 #endif
763 
764  /* read each block */
765  s->block_num = 0;
766  s->block_pos = 0;
767  for(;;) {
768  ret = wma_decode_block(s);
769  if (ret < 0)
770  return -1;
771  if (ret)
772  break;
773  }
774 
775  for (ch = 0; ch < s->avctx->channels; ch++) {
776  /* copy current block to output */
777  memcpy(samples[ch] + samples_offset, s->frame_out[ch],
778  s->frame_len * sizeof(*s->frame_out[ch]));
779  /* prepare for next block */
780  memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
781  s->frame_len * sizeof(*s->frame_out[ch]));
782 
783 #ifdef TRACE
784  dump_floats(s, "samples", 6, samples[ch] + samples_offset, s->frame_len);
785 #endif
786  }
787 
788  return 0;
789 }
790 
791 static int wma_decode_superframe(AVCodecContext *avctx, void *data,
792  int *got_frame_ptr, AVPacket *avpkt)
793 {
794  AVFrame *frame = data;
795  const uint8_t *buf = avpkt->data;
796  int buf_size = avpkt->size;
797  WMACodecContext *s = avctx->priv_data;
798  int nb_frames, bit_offset, i, pos, len, ret;
799  uint8_t *q;
800  float **samples;
801  int samples_offset;
802 
803  tprintf(avctx, "***decode_superframe:\n");
804 
805  if(buf_size==0){
806  s->last_superframe_len = 0;
807  return 0;
808  }
809  if (buf_size < avctx->block_align) {
810  av_log(avctx, AV_LOG_ERROR,
811  "Input packet size too small (%d < %d)\n",
812  buf_size, avctx->block_align);
813  return AVERROR_INVALIDDATA;
814  }
815  buf_size = avctx->block_align;
816 
817  init_get_bits(&s->gb, buf, buf_size*8);
818 
819  if (s->use_bit_reservoir) {
820  /* read super frame header */
821  skip_bits(&s->gb, 4); /* super frame index */
822  nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0);
823  } else {
824  nb_frames = 1;
825  }
826 
827  /* get output buffer */
828  frame->nb_samples = nb_frames * s->frame_len;
829  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
830  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
831  return ret;
832  }
833  samples = (float **)frame->extended_data;
834  samples_offset = 0;
835 
836  if (s->use_bit_reservoir) {
837  bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
838  if (bit_offset > get_bits_left(&s->gb)) {
839  av_log(avctx, AV_LOG_ERROR,
840  "Invalid last frame bit offset %d > buf size %d (%d)\n",
841  bit_offset, get_bits_left(&s->gb), buf_size);
842  goto fail;
843  }
844 
845  if (s->last_superframe_len > 0) {
846  /* add bit_offset bits to last frame */
847  if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
849  goto fail;
851  len = bit_offset;
852  while (len > 7) {
853  *q++ = (get_bits)(&s->gb, 8);
854  len -= 8;
855  }
856  if (len > 0) {
857  *q++ = (get_bits)(&s->gb, len) << (8 - len);
858  }
859  memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE);
860 
861  /* XXX: bit_offset bits into last frame */
862  init_get_bits(&s->gb, s->last_superframe, s->last_superframe_len * 8 + bit_offset);
863  /* skip unused bits */
864  if (s->last_bitoffset > 0)
865  skip_bits(&s->gb, s->last_bitoffset);
866  /* this frame is stored in the last superframe and in the
867  current one */
868  if (wma_decode_frame(s, samples, samples_offset) < 0)
869  goto fail;
870  samples_offset += s->frame_len;
871  nb_frames--;
872  }
873 
874  /* read each frame starting from bit_offset */
875  pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
876  if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8 || pos > buf_size * 8)
877  return AVERROR_INVALIDDATA;
878  init_get_bits(&s->gb, buf + (pos >> 3), (buf_size - (pos >> 3))*8);
879  len = pos & 7;
880  if (len > 0)
881  skip_bits(&s->gb, len);
882 
883  s->reset_block_lengths = 1;
884  for(i=0;i<nb_frames;i++) {
885  if (wma_decode_frame(s, samples, samples_offset) < 0)
886  goto fail;
887  samples_offset += s->frame_len;
888  }
889 
890  /* we copy the end of the frame in the last frame buffer */
891  pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
892  s->last_bitoffset = pos & 7;
893  pos >>= 3;
894  len = buf_size - pos;
895  if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
896  av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len);
897  goto fail;
898  }
900  memcpy(s->last_superframe, buf + pos, len);
901  } else {
902  /* single frame decode */
903  if (wma_decode_frame(s, samples, samples_offset) < 0)
904  goto fail;
905  samples_offset += s->frame_len;
906  }
907 
908  av_dlog(s->avctx, "%d %d %d %d outbytes:%td eaten:%d\n",
910  (int8_t *)samples - (int8_t *)data, avctx->block_align);
911 
912  *got_frame_ptr = 1;
913 
914  return avctx->block_align;
915  fail:
916  /* when error, we reset the bit reservoir */
917  s->last_superframe_len = 0;
918  return -1;
919 }
920 
921 static av_cold void flush(AVCodecContext *avctx)
922 {
923  WMACodecContext *s = avctx->priv_data;
924 
925  s->last_bitoffset=
926  s->last_superframe_len= 0;
927 }
928 
930  .name = "wmav1",
931  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
932  .type = AVMEDIA_TYPE_AUDIO,
933  .id = AV_CODEC_ID_WMAV1,
934  .priv_data_size = sizeof(WMACodecContext),
936  .close = ff_wma_end,
938  .flush = flush,
939  .capabilities = CODEC_CAP_DR1,
940  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
942 };
943 
945  .name = "wmav2",
946  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
947  .type = AVMEDIA_TYPE_AUDIO,
948  .id = AV_CODEC_ID_WMAV2,
949  .priv_data_size = sizeof(WMACodecContext),
951  .close = ff_wma_end,
953  .flush = flush,
954  .capabilities = CODEC_CAP_DR1,
955  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
957 };
float, planar
Definition: samplefmt.h:72
const struct AVCodec * codec
Definition: avcodec.h:1059
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
static void wma_lsp_to_curve(WMACodecContext *s, float *out, float *val_max_ptr, int n, float *lsp)
NOTE: We use the same code as Vorbis here.
Definition: wmadec.c:179
uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE+FF_INPUT_BUFFER_PADDING_SIZE]
Definition: wma.h:122
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
int next_block_len_bits
log2 of next block length
Definition: wma.h:104
static const float pow_tab[]
pow(10, i / 16.0) for i in -60..95
Definition: wmadec.c:227
int size
Definition: avcodec.h:974
GetBitContext gb
Definition: wma.h:68
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, VLC *vlc, const float *level_table, const uint16_t *run_table, int version, WMACoef *ptr, int offset, int num_coefs, int block_len, int frame_len_bits, int coef_nb_bits)
Decode run level compressed coefficients.
Definition: wma.c:431
int block_len
block length in samples
Definition: wma.h:106
#define AV_RL16
Definition: intreadwrite.h:42
#define FF_ARRAY_ELEMS(a)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
AVCodec ff_wmav1_decoder
Definition: wmadec.c:929
float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:112
AVCodec.
Definition: avcodec.h:2796
static void wma_window(WMACodecContext *s, float *out)
Apply MDCT window and add into output.
Definition: wmadec.c:375
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1828
#define NOISE_TAB_SIZE
Definition: wma.h:48
float lsp_pow_m_table2[(1<< LSP_POW_BITS)]
Definition: wma.h:132
Macro definitions for various function/variable attributes.
static int wma_decode_block(WMACodecContext *s)
Definition: wmadec.c:427
float lsp_cos_table[BLOCK_MAX_SIZE]
Definition: wma.h:129
int high_band_start[BLOCK_NB_SIZES]
index of first coef in high band
Definition: wma.h:79
#define HGAINVLCBITS
Definition: wmadec.c:47
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1799
uint8_t
#define av_cold
Definition: attributes.h:66
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
Definition: wma.h:56
#define b
Definition: input.c:52
const uint8_t ff_aac_scalefactor_bits[121]
Definition: aactab.c:74
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1164
const char * name
int block_pos
current position in frame
Definition: wma.h:108
static int decode_exp_vlc(WMACodecContext *s, int ch)
decode exponents coded with VLC codes
Definition: wmadec.c:311
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:973
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:194
float lsp_pow_m_table1[(1<< LSP_POW_BITS)]
Definition: wma.h:131
#define EXPMAX
Definition: wmadec.c:45
int reset_block_lengths
Definition: wma.h:102
int nb_block_sizes
number of block sizes
Definition: wma.h:100
int ff_wma_total_gain_to_bits(int total_gain)
Definition: wma.c:360
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:555
enum AVCodecID id
Definition: avcodec.h:2810
static float pow_m1_4(WMACodecContext *s, float x)
compute x^-0.25 with an exponent and mantissa table.
Definition: wmadec.c:128
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
#define AVERROR(e)
Definition: error.h:43
sample_fmts
Definition: avconv_filter.c:68
uint16_t exponent_bands[BLOCK_NB_SIZES][25]
Definition: wma.h:78
uint8_t channel_coded[MAX_CHANNELS]
true if channel is coded
Definition: wma.h:110
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
AVFloatDSPContext fdsp
Definition: wma.h:134
int last_superframe_len
Definition: wma.h:124
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2803
static int wma_decode_superframe(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: wmadec.c:791
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:92
FFTSample output[BLOCK_MAX_SIZE *2]
Definition: wma.h:116
#define ff_mdct_init
Definition: fft.h:151
const uint8_t ff_wma_hgain_huffbits[37]
Definition: wmadata.h:67
int noise_index
Definition: wma.h:126
static av_cold int wma_decode_init(AVCodecContext *avctx)
Definition: wmadec.c:70
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:531
int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]
Definition: wma.h:83
int ff_wma_end(AVCodecContext *avctx)
Definition: wma.c:369
int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:88
Definition: fft.h:73
int use_bit_reservoir
Definition: wma.h:71
float * windows[BLOCK_NB_SIZES]
Definition: wma.h:118
#define MAX_CODED_SUPERFRAME_SIZE
Definition: wma.h:44
av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
Definition: wma.c:72
uint16_t * run_table[2]
Definition: wma.h:93
const uint16_t ff_wma_hgain_huffcodes[37]
Definition: wmadata.h:59
int version
1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
Definition: wma.h:70
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:522
int frame_len
frame length in samples
Definition: wma.h:98
if(ac->has_optimized_func)
int last_bitoffset
Definition: wma.h:123
static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
Definition: noise_bsf.c:28
static av_cold void flush(AVCodecContext *avctx)
Definition: wmadec.c:921
int frame_len_bits
frame_len = 1 << frame_len_bits
Definition: wma.h:99
Libavcodec external API header.
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:61
static int wma_decode_frame(WMACodecContext *s, float **samples, int samples_offset)
Definition: wmadec.c:755
AV_SAMPLE_FMT_NONE
Definition: avconv_filter.c:68
#define HIGH_BAND_MAX_SIZE
Definition: wma.h:39
int use_exp_vlc
exponent coding: 0 = lsp, 1 = vlc + delta
Definition: wma.h:73
VLC coef_vlc[2]
Definition: wma.h:92
#define NB_LSP_COEFS
Definition: wma.h:41
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:612
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: get_bits.h:424
static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
Definition: wmadec.c:147
AVCodecContext * avctx
Definition: wma.h:67
float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE *2]
Definition: wma.h:120
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:56
int extradata_size
Definition: avcodec.h:1165
int exponent_high_sizes[BLOCK_NB_SIZES]
Definition: wma.h:82
static void decode_exp_lsp(WMACodecContext *s, int ch)
decode exponents coded with LSP coefficients (same idea as Vorbis)
Definition: wmadec.c:209
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:263
int index
Definition: gxfenc.c:72
int block_num
block number in current frame
Definition: wma.h:107
int use_noise_coding
true if perceptual noise is added
Definition: wma.h:74
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:375
float * level_table[2]
Definition: wma.h:94
#define LSP_POW_BITS
Definition: wma.h:50
#define MAX_CHANNELS
Definition: aac.h:42
int use_variable_block_len
Definition: wma.h:72
uint8_t ms_stereo
true if mid/side stereo mode
Definition: wma.h:109
VLC exp_vlc
Definition: wma.h:76
FFTContext mdct_ctx[BLOCK_NB_SIZES]
Definition: wma.h:117
const uint32_t ff_aac_scalefactor_code[121]
Definition: aactab.c:55
int exponents_bsize[MAX_CHANNELS]
log2 ratio frame/exp. length
Definition: wma.h:111
float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:115
int prev_block_len_bits
log2 of prev block length
Definition: wma.h:105
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int coefs_end[BLOCK_NB_SIZES]
max number of coded coefficients
Definition: wma.h:81
float lsp_pow_e_table[256]
Definition: wma.h:130
#define tprintf(p,...)
Definition: get_bits.h:626
const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]
Definition: wmadata.h:75
common internal api header.
void(* vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len)
Calculate the product of two vectors of floats, add a third vector of floats and store the result in ...
Definition: float_dsp.h:121
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
void * priv_data
Definition: avcodec.h:1092
int len
int channels
number of audio channels
Definition: avcodec.h:1792
#define av_log2
Definition: intmath.h:85
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
#define EXPVLCBITS
Definition: wmadec.c:44
WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:114
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:416
AVCodec ff_wmav2_decoder
Definition: wmadec.c:944
#define HGAINMAX
Definition: wmadec.c:48
static const struct twinvq_data tab
float max_exponent[MAX_CHANNELS]
Definition: wma.h:113
void(* butterflies_float)(float *restrict v1, float *restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
Definition: float_dsp.h:148
VLC hgain_vlc
Definition: wma.h:84
int coefs_start
first coded coef
Definition: wma.h:80
int block_len_bits
log2 of current block length
Definition: wma.h:103
int byte_offset_bits
Definition: wma.h:75
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:169
This structure stores compressed data.
Definition: avcodec.h:950
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:179
int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:87
float noise_table[NOISE_TAB_SIZE]
Definition: wma.h:125
float noise_mult
Definition: wma.h:127
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the product of two vectors of floats, and store the result in a vector of floats...
Definition: float_dsp.h:138