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 "avcodec.h"
37 #include "internal.h"
38 #include "wma.h"
39 
40 #undef NDEBUG
41 #include <assert.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, int prec, const float *tab, int n)
53 {
54  int i;
55 
56  tprintf(s->avctx, "%s[%d]:\n", name, n);
57  for(i=0;i<n;i++) {
58  if ((i & 7) == 0)
59  tprintf(s->avctx, "%4d: ", i);
60  tprintf(s->avctx, " %8.*f", prec, tab[i]);
61  if ((i & 7) == 7)
62  tprintf(s->avctx, "\n");
63  }
64  if ((i & 7) != 0)
65  tprintf(s->avctx, "\n");
66 }
67 #endif
68 
69 static int wma_decode_init(AVCodecContext * avctx)
70 {
71  WMACodecContext *s = avctx->priv_data;
72  int i, flags2;
73  uint8_t *extradata;
74 
75  if (!avctx->block_align) {
76  av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
77  return AVERROR(EINVAL);
78  }
79 
80  s->avctx = avctx;
81 
82  /* extract flag infos */
83  flags2 = 0;
84  extradata = avctx->extradata;
85  if (avctx->codec->id == AV_CODEC_ID_WMAV1 && avctx->extradata_size >= 4) {
86  flags2 = AV_RL16(extradata+2);
87  } else if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 6) {
88  flags2 = AV_RL16(extradata+4);
89  }
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  if(ff_wma_init(avctx, flags2)<0)
103  return -1;
104 
105  /* init MDCT */
106  for(i = 0; i < s->nb_block_sizes; i++)
107  ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1, 1.0 / 32768.0);
108 
109  if (s->use_noise_coding) {
111  ff_wma_hgain_huffbits, 1, 1,
112  ff_wma_hgain_huffcodes, 2, 2, 0);
113  }
114 
115  if (s->use_exp_vlc) {
116  init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits), //FIXME move out of context
118  ff_aac_scalefactor_code, 4, 4, 0);
119  } else {
121  }
122 
124 
125  return 0;
126 }
127 
128 /**
129  * compute x^-0.25 with an exponent and mantissa table. We use linear
130  * interpolation to reduce the mantissa table size at a small speed
131  * expense (linear interpolation approximately doubles the number of
132  * bits of precision).
133  */
134 static inline float pow_m1_4(WMACodecContext *s, float x)
135 {
136  union {
137  float f;
138  unsigned int v;
139  } u, t;
140  unsigned int e, m;
141  float a, b;
142 
143  u.f = x;
144  e = u.v >> 23;
145  m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
146  /* build interpolation scale: 1 <= t < 2. */
147  t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
148  a = s->lsp_pow_m_table1[m];
149  b = s->lsp_pow_m_table2[m];
150  return s->lsp_pow_e_table[e] * (a + b * t.f);
151 }
152 
153 static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
154 {
155  float wdel, a, b;
156  int i, e, m;
157 
158  wdel = M_PI / frame_len;
159  for(i=0;i<frame_len;i++)
160  s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
161 
162  /* tables for x^-0.25 computation */
163  for(i=0;i<256;i++) {
164  e = i - 126;
165  s->lsp_pow_e_table[i] = pow(2.0, e * -0.25);
166  }
167 
168  /* NOTE: these two tables are needed to avoid two operations in
169  pow_m1_4 */
170  b = 1.0;
171  for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) {
172  m = (1 << LSP_POW_BITS) + i;
173  a = (float)m * (0.5 / (1 << LSP_POW_BITS));
174  a = pow(a, -0.25);
175  s->lsp_pow_m_table1[i] = 2 * a - b;
176  s->lsp_pow_m_table2[i] = b - a;
177  b = a;
178  }
179 }
180 
181 /**
182  * NOTE: We use the same code as Vorbis here
183  * @todo optimize it further with SSE/3Dnow
184  */
186  float *out, float *val_max_ptr,
187  int n, float *lsp)
188 {
189  int i, j;
190  float p, q, w, v, val_max;
191 
192  val_max = 0;
193  for(i=0;i<n;i++) {
194  p = 0.5f;
195  q = 0.5f;
196  w = s->lsp_cos_table[i];
197  for(j=1;j<NB_LSP_COEFS;j+=2){
198  q *= w - lsp[j - 1];
199  p *= w - lsp[j];
200  }
201  p *= p * (2.0f - w);
202  q *= q * (2.0f + w);
203  v = p + q;
204  v = pow_m1_4(s, v);
205  if (v > val_max)
206  val_max = v;
207  out[i] = v;
208  }
209  *val_max_ptr = val_max;
210 }
211 
212 /**
213  * decode exponents coded with LSP coefficients (same idea as Vorbis)
214  */
215 static void decode_exp_lsp(WMACodecContext *s, int ch)
216 {
217  float lsp_coefs[NB_LSP_COEFS];
218  int val, i;
219 
220  for(i = 0; i < NB_LSP_COEFS; i++) {
221  if (i == 0 || i >= 8)
222  val = get_bits(&s->gb, 3);
223  else
224  val = get_bits(&s->gb, 4);
225  lsp_coefs[i] = ff_wma_lsp_codebook[i][val];
226  }
227 
228  wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
229  s->block_len, lsp_coefs);
230 }
231 
232 /** pow(10, i / 16.0) for i in -60..95 */
233 static const float pow_tab[] = {
234  1.7782794100389e-04, 2.0535250264571e-04,
235  2.3713737056617e-04, 2.7384196342644e-04,
236  3.1622776601684e-04, 3.6517412725484e-04,
237  4.2169650342858e-04, 4.8696752516586e-04,
238  5.6234132519035e-04, 6.4938163157621e-04,
239  7.4989420933246e-04, 8.6596432336006e-04,
240  1.0000000000000e-03, 1.1547819846895e-03,
241  1.3335214321633e-03, 1.5399265260595e-03,
242  1.7782794100389e-03, 2.0535250264571e-03,
243  2.3713737056617e-03, 2.7384196342644e-03,
244  3.1622776601684e-03, 3.6517412725484e-03,
245  4.2169650342858e-03, 4.8696752516586e-03,
246  5.6234132519035e-03, 6.4938163157621e-03,
247  7.4989420933246e-03, 8.6596432336006e-03,
248  1.0000000000000e-02, 1.1547819846895e-02,
249  1.3335214321633e-02, 1.5399265260595e-02,
250  1.7782794100389e-02, 2.0535250264571e-02,
251  2.3713737056617e-02, 2.7384196342644e-02,
252  3.1622776601684e-02, 3.6517412725484e-02,
253  4.2169650342858e-02, 4.8696752516586e-02,
254  5.6234132519035e-02, 6.4938163157621e-02,
255  7.4989420933246e-02, 8.6596432336007e-02,
256  1.0000000000000e-01, 1.1547819846895e-01,
257  1.3335214321633e-01, 1.5399265260595e-01,
258  1.7782794100389e-01, 2.0535250264571e-01,
259  2.3713737056617e-01, 2.7384196342644e-01,
260  3.1622776601684e-01, 3.6517412725484e-01,
261  4.2169650342858e-01, 4.8696752516586e-01,
262  5.6234132519035e-01, 6.4938163157621e-01,
263  7.4989420933246e-01, 8.6596432336007e-01,
264  1.0000000000000e+00, 1.1547819846895e+00,
265  1.3335214321633e+00, 1.5399265260595e+00,
266  1.7782794100389e+00, 2.0535250264571e+00,
267  2.3713737056617e+00, 2.7384196342644e+00,
268  3.1622776601684e+00, 3.6517412725484e+00,
269  4.2169650342858e+00, 4.8696752516586e+00,
270  5.6234132519035e+00, 6.4938163157621e+00,
271  7.4989420933246e+00, 8.6596432336007e+00,
272  1.0000000000000e+01, 1.1547819846895e+01,
273  1.3335214321633e+01, 1.5399265260595e+01,
274  1.7782794100389e+01, 2.0535250264571e+01,
275  2.3713737056617e+01, 2.7384196342644e+01,
276  3.1622776601684e+01, 3.6517412725484e+01,
277  4.2169650342858e+01, 4.8696752516586e+01,
278  5.6234132519035e+01, 6.4938163157621e+01,
279  7.4989420933246e+01, 8.6596432336007e+01,
280  1.0000000000000e+02, 1.1547819846895e+02,
281  1.3335214321633e+02, 1.5399265260595e+02,
282  1.7782794100389e+02, 2.0535250264571e+02,
283  2.3713737056617e+02, 2.7384196342644e+02,
284  3.1622776601684e+02, 3.6517412725484e+02,
285  4.2169650342858e+02, 4.8696752516586e+02,
286  5.6234132519035e+02, 6.4938163157621e+02,
287  7.4989420933246e+02, 8.6596432336007e+02,
288  1.0000000000000e+03, 1.1547819846895e+03,
289  1.3335214321633e+03, 1.5399265260595e+03,
290  1.7782794100389e+03, 2.0535250264571e+03,
291  2.3713737056617e+03, 2.7384196342644e+03,
292  3.1622776601684e+03, 3.6517412725484e+03,
293  4.2169650342858e+03, 4.8696752516586e+03,
294  5.6234132519035e+03, 6.4938163157621e+03,
295  7.4989420933246e+03, 8.6596432336007e+03,
296  1.0000000000000e+04, 1.1547819846895e+04,
297  1.3335214321633e+04, 1.5399265260595e+04,
298  1.7782794100389e+04, 2.0535250264571e+04,
299  2.3713737056617e+04, 2.7384196342644e+04,
300  3.1622776601684e+04, 3.6517412725484e+04,
301  4.2169650342858e+04, 4.8696752516586e+04,
302  5.6234132519035e+04, 6.4938163157621e+04,
303  7.4989420933246e+04, 8.6596432336007e+04,
304  1.0000000000000e+05, 1.1547819846895e+05,
305  1.3335214321633e+05, 1.5399265260595e+05,
306  1.7782794100389e+05, 2.0535250264571e+05,
307  2.3713737056617e+05, 2.7384196342644e+05,
308  3.1622776601684e+05, 3.6517412725484e+05,
309  4.2169650342858e+05, 4.8696752516586e+05,
310  5.6234132519035e+05, 6.4938163157621e+05,
311  7.4989420933246e+05, 8.6596432336007e+05,
312 };
313 
314 /**
315  * decode exponents coded with VLC codes
316  */
317 static int decode_exp_vlc(WMACodecContext *s, int ch)
318 {
319  int last_exp, n, code;
320  const uint16_t *ptr;
321  float v, max_scale;
322  uint32_t *q, *q_end, iv;
323  const float *ptab = pow_tab + 60;
324  const uint32_t *iptab = (const uint32_t*)ptab;
325 
326  ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
327  q = (uint32_t *)s->exponents[ch];
328  q_end = q + s->block_len;
329  max_scale = 0;
330  if (s->version == 1) {
331  last_exp = get_bits(&s->gb, 5) + 10;
332  v = ptab[last_exp];
333  iv = iptab[last_exp];
334  max_scale = v;
335  n = *ptr++;
336  switch (n & 3) do {
337  case 0: *q++ = iv;
338  case 3: *q++ = iv;
339  case 2: *q++ = iv;
340  case 1: *q++ = iv;
341  } while ((n -= 4) > 0);
342  }else
343  last_exp = 36;
344 
345  while (q < q_end) {
346  code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
347  if (code < 0){
348  av_log(s->avctx, AV_LOG_ERROR, "Exponent vlc invalid\n");
349  return -1;
350  }
351  /* NOTE: this offset is the same as MPEG4 AAC ! */
352  last_exp += code - 60;
353  if ((unsigned)last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {
354  av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
355  last_exp);
356  return -1;
357  }
358  v = ptab[last_exp];
359  iv = iptab[last_exp];
360  if (v > max_scale)
361  max_scale = v;
362  n = *ptr++;
363  switch (n & 3) do {
364  case 0: *q++ = iv;
365  case 3: *q++ = iv;
366  case 2: *q++ = iv;
367  case 1: *q++ = iv;
368  } while ((n -= 4) > 0);
369  }
370  s->max_exponent[ch] = max_scale;
371  return 0;
372 }
373 
374 
375 /**
376  * Apply MDCT window and add into output.
377  *
378  * We ensure that when the windows overlap their squared sum
379  * is always 1 (MDCT reconstruction rule).
380  */
381 static void wma_window(WMACodecContext *s, float *out)
382 {
383  float *in = s->output;
384  int block_len, bsize, n;
385 
386  /* left part */
387  if (s->block_len_bits <= s->prev_block_len_bits) {
388  block_len = s->block_len;
389  bsize = s->frame_len_bits - s->block_len_bits;
390 
391  s->fdsp.vector_fmul_add(out, in, s->windows[bsize],
392  out, block_len);
393 
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 
415  } else {
416  block_len = 1 << s->next_block_len_bits;
417  n = (s->block_len - block_len) / 2;
418  bsize = s->frame_len_bits - s->next_block_len_bits;
419 
420  memcpy(out, in, n*sizeof(float));
421 
422  s->fdsp.vector_fmul_reverse(out+n, in+n, s->windows[bsize], block_len);
423 
424  memset(out+n+block_len, 0, n*sizeof(float));
425  }
426 }
427 
428 
429 /**
430  * @return 0 if OK. 1 if last block of frame. return -1 if
431  * unrecorrable error.
432  */
434 {
435  int n, v, a, ch, bsize;
436  int coef_nb_bits, total_gain;
437  int nb_coefs[MAX_CHANNELS];
438  float mdct_norm;
439  FFTContext *mdct;
440 
441 #ifdef TRACE
442  tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);
443 #endif
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){
453  av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v);
454  return -1;
455  }
457  v = get_bits(&s->gb, n);
458  if (v >= s->nb_block_sizes){
459  av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v);
460  return -1;
461  }
462  s->block_len_bits = s->frame_len_bits - v;
463  } else {
464  /* update block lengths */
467  }
468  v = get_bits(&s->gb, n);
469  if (v >= s->nb_block_sizes){
470  av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v);
471  return -1;
472  }
474  } else {
475  /* fixed block len */
479  }
480 
481  if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){
482  av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");
483  return -1;
484  }
485 
486  /* now check if the block length is coherent with the frame length */
487  s->block_len = 1 << s->block_len_bits;
488  if ((s->block_pos + s->block_len) > s->frame_len){
489  av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
490  return -1;
491  }
492 
493  if (s->avctx->channels == 2) {
494  s->ms_stereo = get_bits1(&s->gb);
495  }
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  a = get_bits(&s->gb, 7);
515  total_gain += a;
516  if (a != 127)
517  break;
518  }
519 
520  coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);
521 
522  /* compute number of coefficients */
523  n = s->coefs_end[bsize] - s->coefs_start;
524  for(ch = 0; ch < s->avctx->channels; ch++)
525  nb_coefs[ch] = n;
526 
527  /* complex coding */
528  if (s->use_noise_coding) {
529 
530  for(ch = 0; ch < s->avctx->channels; ch++) {
531  if (s->channel_coded[ch]) {
532  int i, n, a;
533  n = s->exponent_high_sizes[bsize];
534  for(i=0;i<n;i++) {
535  a = get_bits1(&s->gb);
536  s->high_band_coded[ch][i] = a;
537  /* if noise coding, the coefficients are not transmitted */
538  if (a)
539  nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
540  }
541  }
542  }
543  for(ch = 0; ch < s->avctx->channels; ch++) {
544  if (s->channel_coded[ch]) {
545  int i, n, val, code;
546 
547  n = s->exponent_high_sizes[bsize];
548  val = (int)0x80000000;
549  for(i=0;i<n;i++) {
550  if (s->high_band_coded[ch][i]) {
551  if (val == (int)0x80000000) {
552  val = get_bits(&s->gb, 7) - 19;
553  } else {
554  code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
555  if (code < 0){
556  av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n");
557  return -1;
558  }
559  val += code - 18;
560  }
561  s->high_band_values[ch][i] = val;
562  }
563  }
564  }
565  }
566  }
567 
568  /* exponents can be reused in short blocks. */
569  if ((s->block_len_bits == s->frame_len_bits) ||
570  get_bits1(&s->gb)) {
571  for(ch = 0; ch < s->avctx->channels; ch++) {
572  if (s->channel_coded[ch]) {
573  if (s->use_exp_vlc) {
574  if (decode_exp_vlc(s, ch) < 0)
575  return -1;
576  } else {
577  decode_exp_lsp(s, ch);
578  }
579  s->exponents_bsize[ch] = bsize;
580  }
581  }
582  }
583 
584  /* parse spectral coefficients : just RLE encoding */
585  for (ch = 0; ch < s->avctx->channels; ch++) {
586  if (s->channel_coded[ch]) {
587  int tindex;
588  WMACoef* ptr = &s->coefs1[ch][0];
589 
590  /* special VLC tables are used for ms stereo because
591  there is potentially less energy there */
592  tindex = (ch == 1 && s->ms_stereo);
593  memset(ptr, 0, s->block_len * sizeof(WMACoef));
594  ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex],
595  s->level_table[tindex], s->run_table[tindex],
596  0, ptr, 0, nb_coefs[ch],
597  s->block_len, s->frame_len_bits, coef_nb_bits);
598  }
599  if (s->version == 1 && s->avctx->channels >= 2) {
600  align_get_bits(&s->gb);
601  }
602  }
603 
604  /* normalize */
605  {
606  int n4 = s->block_len / 2;
607  mdct_norm = 1.0 / (float)n4;
608  if (s->version == 1) {
609  mdct_norm *= sqrt(n4);
610  }
611  }
612 
613  /* finally compute the MDCT coefficients */
614  for (ch = 0; ch < s->avctx->channels; ch++) {
615  if (s->channel_coded[ch]) {
616  WMACoef *coefs1;
617  float *coefs, *exponents, mult, mult1, noise;
618  int i, j, n, n1, last_high_band, esize;
619  float exp_power[HIGH_BAND_MAX_SIZE];
620 
621  coefs1 = s->coefs1[ch];
622  exponents = s->exponents[ch];
623  esize = s->exponents_bsize[ch];
624  mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
625  mult *= mdct_norm;
626  coefs = s->coefs[ch];
627  if (s->use_noise_coding) {
628  mult1 = mult;
629  /* very low freqs : noise */
630  for(i = 0;i < s->coefs_start; i++) {
631  *coefs++ = s->noise_table[s->noise_index] *
632  exponents[i<<bsize>>esize] * mult1;
633  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
634  }
635 
636  n1 = s->exponent_high_sizes[bsize];
637 
638  /* compute power of high bands */
639  exponents = s->exponents[ch] +
640  (s->high_band_start[bsize]<<bsize>>esize);
641  last_high_band = 0; /* avoid warning */
642  for(j=0;j<n1;j++) {
644  s->block_len_bits][j];
645  if (s->high_band_coded[ch][j]) {
646  float e2, v;
647  e2 = 0;
648  for(i = 0;i < n; i++) {
649  v = exponents[i<<bsize>>esize];
650  e2 += v * v;
651  }
652  exp_power[j] = e2 / n;
653  last_high_band = j;
654  tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
655  }
656  exponents += n<<bsize>>esize;
657  }
658 
659  /* main freqs and high freqs */
660  exponents = s->exponents[ch] + (s->coefs_start<<bsize>>esize);
661  for(j=-1;j<n1;j++) {
662  if (j < 0) {
663  n = s->high_band_start[bsize] -
664  s->coefs_start;
665  } else {
667  s->block_len_bits][j];
668  }
669  if (j >= 0 && s->high_band_coded[ch][j]) {
670  /* use noise with specified power */
671  mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
672  /* XXX: use a table */
673  mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);
674  mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
675  mult1 *= mdct_norm;
676  for(i = 0;i < n; i++) {
677  noise = s->noise_table[s->noise_index];
678  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
679  *coefs++ = noise *
680  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  }
710  n = s->block_len - s->coefs_end[bsize];
711  for(i = 0;i < n; i++)
712  *coefs++ = 0.0;
713  }
714  }
715  }
716 
717 #ifdef TRACE
718  for (ch = 0; ch < s->avctx->channels; ch++) {
719  if (s->channel_coded[ch]) {
720  dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
721  dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
722  }
723  }
724 #endif
725 
726  if (s->ms_stereo && s->channel_coded[1]) {
727  /* nominal case for ms stereo: we do it before mdct */
728  /* no need to optimize this case because it should almost
729  never happen */
730  if (!s->channel_coded[0]) {
731  tprintf(s->avctx, "rare ms-stereo case happened\n");
732  memset(s->coefs[0], 0, sizeof(float) * s->block_len);
733  s->channel_coded[0] = 1;
734  }
735 
736  s->fdsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len);
737  }
738 
739 next:
740  mdct = &s->mdct_ctx[bsize];
741 
742  for (ch = 0; ch < s->avctx->channels; ch++) {
743  int n4, index;
744 
745  n4 = s->block_len / 2;
746  if(s->channel_coded[ch]){
747  mdct->imdct_calc(mdct, s->output, s->coefs[ch]);
748  }else if(!(s->ms_stereo && ch==1))
749  memset(s->output, 0, sizeof(s->output));
750 
751  /* multiply by the window and add in the frame */
752  index = (s->frame_len / 2) + s->block_pos - n4;
753  wma_window(s, &s->frame_out[ch][index]);
754  }
755 
756  /* update block number */
757  s->block_num++;
758  s->block_pos += s->block_len;
759  if (s->block_pos >= s->frame_len)
760  return 1;
761  else
762  return 0;
763 }
764 
765 /* decode a frame of frame_len samples */
766 static int wma_decode_frame(WMACodecContext *s, float **samples,
767  int samples_offset)
768 {
769  int ret, ch;
770 
771 #ifdef TRACE
772  tprintf(s->avctx, "***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len);
773 #endif
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, s->frame_len);
796 #endif
797  }
798 
799  return 0;
800 }
801 
802 static int wma_decode_superframe(AVCodecContext *avctx, void *data,
803  int *got_frame_ptr, AVPacket *avpkt)
804 {
805  AVFrame *frame = data;
806  const uint8_t *buf = avpkt->data;
807  int buf_size = avpkt->size;
808  WMACodecContext *s = avctx->priv_data;
809  int nb_frames, bit_offset, i, pos, len, ret;
810  uint8_t *q;
811  float **samples;
812  int samples_offset;
813 
814  tprintf(avctx, "***decode_superframe:\n");
815 
816  if(buf_size==0){
817  s->last_superframe_len = 0;
818  return 0;
819  }
820  if (buf_size < avctx->block_align) {
821  av_log(avctx, AV_LOG_ERROR,
822  "Input packet size too small (%d < %d)\n",
823  buf_size, avctx->block_align);
824  return AVERROR_INVALIDDATA;
825  }
826  if(avctx->block_align)
827  buf_size = avctx->block_align;
828 
829  init_get_bits(&s->gb, buf, buf_size*8);
830 
831  if (s->use_bit_reservoir) {
832  /* read super frame header */
833  skip_bits(&s->gb, 4); /* super frame index */
834  nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0);
835  if (nb_frames <= 0) {
836  av_log(avctx, AV_LOG_ERROR, "nb_frames is %d\n", nb_frames);
837  return AVERROR_INVALIDDATA;
838  }
839  } else {
840  nb_frames = 1;
841  }
842 
843  /* get output buffer */
844  frame->nb_samples = nb_frames * s->frame_len;
845  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
846  return ret;
847  samples = (float **)frame->extended_data;
848  samples_offset = 0;
849 
850  if (s->use_bit_reservoir) {
851  bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
852  if (bit_offset > get_bits_left(&s->gb)) {
853  av_log(avctx, AV_LOG_ERROR,
854  "Invalid last frame bit offset %d > buf size %d (%d)\n",
855  bit_offset, get_bits_left(&s->gb), buf_size);
856  goto fail;
857  }
858 
859  if (s->last_superframe_len > 0) {
860  /* add bit_offset bits to last frame */
861  if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
863  goto fail;
865  len = bit_offset;
866  while (len > 7) {
867  *q++ = (get_bits)(&s->gb, 8);
868  len -= 8;
869  }
870  if (len > 0) {
871  *q++ = (get_bits)(&s->gb, len) << (8 - len);
872  }
873  memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE);
874 
875  /* XXX: bit_offset bits into last frame */
876  init_get_bits(&s->gb, s->last_superframe, s->last_superframe_len * 8 + bit_offset);
877  /* skip unused bits */
878  if (s->last_bitoffset > 0)
879  skip_bits(&s->gb, s->last_bitoffset);
880  /* this frame is stored in the last superframe and in the
881  current one */
882  if (wma_decode_frame(s, samples, samples_offset) < 0)
883  goto fail;
884  samples_offset += s->frame_len;
885  nb_frames--;
886  }
887 
888  /* read each frame starting from bit_offset */
889  pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
890  if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8 || pos > buf_size * 8)
891  return AVERROR_INVALIDDATA;
892  init_get_bits(&s->gb, buf + (pos >> 3), (buf_size - (pos >> 3))*8);
893  len = pos & 7;
894  if (len > 0)
895  skip_bits(&s->gb, len);
896 
897  s->reset_block_lengths = 1;
898  for(i=0;i<nb_frames;i++) {
899  if (wma_decode_frame(s, samples, samples_offset) < 0)
900  goto fail;
901  samples_offset += s->frame_len;
902  }
903 
904  /* we copy the end of the frame in the last frame buffer */
905  pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
906  s->last_bitoffset = pos & 7;
907  pos >>= 3;
908  len = buf_size - pos;
909  if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
910  av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len);
911  goto fail;
912  }
914  memcpy(s->last_superframe, buf + pos, len);
915  } else {
916  /* single frame decode */
917  if (wma_decode_frame(s, samples, samples_offset) < 0)
918  goto fail;
919  samples_offset += s->frame_len;
920  }
921 
922  av_dlog(s->avctx, "%d %d %d %d outbytes:%td eaten:%d\n",
924  (int8_t *)samples - (int8_t *)data, avctx->block_align);
925 
926  *got_frame_ptr = 1;
927 
928  return buf_size;
929  fail:
930  /* when error, we reset the bit reservoir */
931  s->last_superframe_len = 0;
932  return -1;
933 }
934 
935 static av_cold void flush(AVCodecContext *avctx)
936 {
937  WMACodecContext *s = avctx->priv_data;
938 
939  s->last_bitoffset=
940  s->last_superframe_len= 0;
941 }
942 
943 #if CONFIG_WMAV1_DECODER
944 AVCodec ff_wmav1_decoder = {
945  .name = "wmav1",
946  .type = AVMEDIA_TYPE_AUDIO,
947  .id = AV_CODEC_ID_WMAV1,
948  .priv_data_size = sizeof(WMACodecContext),
950  .close = ff_wma_end,
952  .flush = flush,
953  .capabilities = CODEC_CAP_DR1,
954  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
955  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
957 };
958 #endif
959 #if CONFIG_WMAV2_DECODER
960 AVCodec ff_wmav2_decoder = {
961  .name = "wmav2",
962  .type = AVMEDIA_TYPE_AUDIO,
963  .id = AV_CODEC_ID_WMAV2,
964  .priv_data_size = sizeof(WMACodecContext),
966  .close = ff_wma_end,
968  .flush = flush,
969  .capabilities = CODEC_CAP_DR1,
970  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
971  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
973 };
974 #endif
const char * name
Definition: avisynth_c.h:675
const struct AVCodec * codec
float v
const char * s
Definition: avisynth_c.h:668
#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:185
uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE+FF_INPUT_BUFFER_PADDING_SIZE]
Definition: wma.h:122
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
int next_block_len_bits
log2 of next block length
Definition: wma.h:104
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
static const float pow_tab[]
pow(10, i / 16.0) for i in -60..95
Definition: wmadec.c:233
GetBitContext gb
Definition: wma.h:68
Sinusoidal phase f
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
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:434
int block_len
block length in samples
Definition: wma.h:106
#define AV_RL16
#define FF_ARRAY_ELEMS(a)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static void wma_window(WMACodecContext *s, float *out)
Apply MDCT window and add into output.
Definition: wmadec.c:381
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
#define NOISE_TAB_SIZE
Definition: wma.h:48
output residual component w
float lsp_pow_m_table2[(1<< LSP_POW_BITS)]
Definition: wma.h:132
static int wma_decode_block(WMACodecContext *s)
Definition: wmadec.c:433
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
float lsp_cos_table[BLOCK_MAX_SIZE]
Definition: wma.h:129
int high_band_start[BLOCK_NB_SIZES]
index of first coef in high band
Definition: wma.h:79
#define HGAINVLCBITS
Definition: wmadec.c:46
enum AVSampleFormat sample_fmt
audio sample format
uint8_t
#define av_cold
Definition: attributes.h:78
window constants for m
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
Definition: wma.h:56
#define b
Definition: input.c:42
const uint8_t ff_aac_scalefactor_bits[121]
Definition: aactab.c:70
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int block_pos
current position in frame
Definition: wma.h:108
static int decode_exp_vlc(WMACodecContext *s, int ch)
decode exponents coded with VLC codes
Definition: wmadec.c:317
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t * data
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:193
integer sqrt
Definition: avutil.txt:2
float lsp_pow_m_table1[(1<< LSP_POW_BITS)]
Definition: wma.h:131
#define EXPMAX
Definition: wmadec.c:44
float, planar
Definition: samplefmt.h:60
frame
Definition: stft.m:14
int reset_block_lengths
Definition: wma.h:102
int nb_block_sizes
number of block sizes
Definition: wma.h:100
int ff_wma_total_gain_to_bits(int total_gain)
Definition: wma.c:363
Discrete Time axis x
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:557
enum AVCodecID id
static float pow_m1_4(WMACodecContext *s, float x)
compute x^-0.25 with an exponent and mantissa table.
Definition: wmadec.c:134
uint16_t exponent_bands[BLOCK_NB_SIZES][25]
Definition: wma.h:78
uint8_t channel_coded[MAX_CHANNELS]
true if channel is coded
Definition: wma.h:110
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
Definition: wmadec.c:153
Spectrum Plot time data
AVFloatDSPContext fdsp
Definition: wma.h:134
int last_superframe_len
Definition: wma.h:124
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
static int wma_decode_superframe(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: wmadec.c:802
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:81
#define ff_mdct_init
Definition: fft.h:147
const uint8_t ff_wma_hgain_huffbits[37]
Definition: wmadata.h:67
static int wma_decode_init(AVCodecContext *avctx)
Definition: wmadec.c:69
int noise_index
Definition: wma.h:126
external API header
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]
Definition: wma.h:83
int ff_wma_end(AVCodecContext *avctx)
Definition: wma.c:372
int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:88
Definition: fft.h:62
int use_bit_reservoir
Definition: wma.h:71
float * windows[BLOCK_NB_SIZES]
Definition: wma.h:118
ret
Definition: avfilter.c:821
#define MAX_CODED_SUPERFRAME_SIZE
Definition: wma.h:44
t
Definition: genspecsines3.m:6
uint16_t * run_table[2]
Definition: wma.h:93
const uint16_t ff_wma_hgain_huffcodes[37]
Definition: wmadata.h:59
int version
1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
Definition: wma.h:70
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:524
float u
int frame_len
frame length in samples
Definition: wma.h:98
int last_bitoffset
Definition: wma.h:123
or the Software in violation of any applicable export control laws in any jurisdiction Except as provided by mandatorily applicable UPF has no obligation to provide you with source code to the Software In the event Software contains any source code
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:935
int frame_len_bits
frame_len = 1 << frame_len_bits
Definition: wma.h:99
static int wma_decode_frame(WMACodecContext *s, float **samples, int samples_offset)
Definition: wmadec.c:766
#define HIGH_BAND_MAX_SIZE
Definition: wma.h:39
int use_exp_vlc
exponent coding: 0 = lsp, 1 = vlc + delta
Definition: wma.h:73
VLC coef_vlc[2]
Definition: wma.h:92
#define NB_LSP_COEFS
Definition: wma.h:41
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
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:150
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: get_bits.h:426
AVCodecContext * avctx
Definition: wma.h:67
void * buf
Definition: avisynth_c.h:594
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:56
int exponent_high_sizes[BLOCK_NB_SIZES]
Definition: wma.h:82
static void decode_exp_lsp(WMACodecContext *s, int ch)
decode exponents coded with LSP coefficients (same idea as Vorbis)
Definition: wmadec.c:215
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:273
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:265
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
int block_num
block number in current frame
Definition: wma.h:107
int use_noise_coding
true if perceptual noise is added
Definition: wma.h:74
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:379
float * level_table[2]
Definition: wma.h:94
#define LSP_POW_BITS
Definition: wma.h:50
#define MAX_CHANNELS
Definition: aac.h:42
int use_variable_block_len
Definition: wma.h:72
uint8_t ms_stereo
true if mid/side stereo mode
Definition: wma.h:109
VLC exp_vlc
Definition: wma.h:76
FFTContext mdct_ctx[BLOCK_NB_SIZES]
Definition: wma.h:117
const uint32_t ff_aac_scalefactor_code[121]
Definition: aactab.c:51
int exponents_bsize[MAX_CHANNELS]
log2 ratio frame/exp. length
Definition: wma.h:111
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
int prev_block_len_bits
log2 of prev block length
Definition: wma.h:105
int coefs_end[BLOCK_NB_SIZES]
max number of coded coefficients
Definition: wma.h:81
struct WMACodecContext WMACodecContext
float lsp_pow_e_table[256]
Definition: wma.h:130
#define tprintf(p,...)
Definition: get_bits.h:628
const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]
Definition: wmadata.h:75
common internal api header.
void(* vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len)
Calculate the product of two vectors of floats, add a third vector of floats and store the result in ...
Definition: float_dsp.h:121
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
int len
int channels
number of audio channels
#define av_log2
Definition: intmath.h:89
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:65
#define EXPVLCBITS
Definition: wmadec.c:43
WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]
Definition: wma.h:114
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:418
#define HGAINMAX
Definition: wmadec.c:47
static const struct twinvq_data tab
float max_exponent[MAX_CHANNELS]
Definition: wma.h:113
Filter the word “frame” indicates either a video frame or a group of audio samples
VLC hgain_vlc
Definition: wma.h:84
int coefs_start
first coded coef
Definition: wma.h:80
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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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_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_dlog(ac->avr,"%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-> out
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
#define M_PI
Definition: mathematics.h:46
int block_len_bits
log2 of current block length
Definition: wma.h:103
int byte_offset_bits
Definition: wma.h:75
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:117
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
Definition: wma.h:87
int ff_wma_init(AVCodecContext *avctx, int flags2)
Definition: wma.c:71
float noise_table[NOISE_TAB_SIZE]
Definition: wma.h:125
float noise_mult
Definition: wma.h:127
void(* vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len)
Calculate the product of two vectors of floats, and store the result in a vector of floats...
Definition: float_dsp.h:140