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