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