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