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
38
42
44 #define EXPMAX ((19 + EXPVLCBITS - 1) / EXPVLCBITS)
45
46 #define HGAINVLCBITS 9
47 #define HGAINMAX ((13 + HGAINVLCBITS - 1) / HGAINVLCBITS)
48
50
51 #ifdef TRACE
53 int prec,
const float *
tab,
int n)
54 {
55 int i;
56
58 for (i = 0; i <
n; i++) {
59 if ((i & 7) == 0)
62 if ((i & 7) == 7)
64 }
65 if ((i & 7) != 0)
67 }
68 #endif /* TRACE */
69
71 {
73 int i, flags2;
75
79 }
80
82
83 /* extract flag info */
84 flags2 = 0;
87 flags2 =
AV_RL16(extradata + 2);
89 flags2 =
AV_RL16(extradata + 4);
90
94
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");
99 }
100 }
101
104
106 return -1;
107
108 /* init MDCT */
111
116 }
117
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 */
137 {
138 union {
139 float f;
140 unsigned int v;
142 unsigned int e, m;
144
148 /* build interpolation scale: 1 <= t < 2. */
149 t.v = ((
u.v <<
LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
153 }
154
156 {
158 int i, e, m;
159
160 wdel =
M_PI / frame_len;
161 for (i = 0; i < frame_len; i++)
163
164 /* tables for x^-0.25 computation */
165 for (i = 0; i < 256; i++) {
166 e = i - 126;
168 }
169
170 /* NOTE: these two tables are needed to avoid two operations in
171 * pow_m1_4 */
172 b = 1.0;
176 a = 1/sqrt(sqrt(a));
180 }
181 }
182
183 /**
184 * NOTE: We use the same code as Vorbis here
185 * @todo optimize it further with SSE/3Dnow
186 */
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;
199 q *= w - lsp[j - 1];
200 p *= w - lsp[j];
201 }
204 v = p + q;
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 */
217 {
220
222 if (i == 0 || i >= 8)
224 else
227 }
228
231 }
232
233 /** pow(10, i / 16.0) for i in -60..95 */
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 */
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
330 max_scale = 0;
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) {
348 if (code < 0) {
350 return -1;
351 }
352 /* NOTE: this offset is the same as MPEG-4 AAC! */
353 last_exp += code - 60;
356 last_exp);
357 return -1;
358 }
359 v = ptab[last_exp];
360 iv = iptab[last_exp];
361 if (v > max_scale)
362 max_scale = v;
363 n = *ptr++;
364 switch (n & 3) do {
365 case 0: *q++ = iv;
366 case 3: *q++ = iv;
367 case 2: *q++ = iv;
368 case 1: *q++ = iv;
369 } while ((n -= 4) > 0);
370 }
372 return 0;
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 */
382 {
384 int block_len, bsize,
n;
385
386 /* left part */
390
392 out, block_len);
393 } else {
397
399 out + n, block_len);
400
401 memcpy(out + n + block_len, in + n + block_len, n * sizeof(float));
402 }
403
406
407 /* right part */
411
413 } else {
417
418 memcpy(out, in, n * sizeof(float));
419
421 block_len);
422
423 memset(out + n + block_len, 0, n * sizeof(float));
424 }
425 }
426
427 /**
428 * @return 0 if OK. 1 if last block of frame. return -1 if
429 * unrecoverable error.
430 */
432 {
433 int n, v,
a,
ch, bsize;
434 int coef_nb_bits, total_gain;
436 float mdct_norm;
438
439 #ifdef TRACE
442 #endif /* TRACE */
443
444 /* compute current block length */
447
453 "prev_block_len_bits %d out of range\n",
455 return -1;
456 }
461 "block_len_bits %d out of range\n",
463 return -1;
464 }
466 } else {
467 /* update block lengths */
470 }
474 "next_block_len_bits %d out of range\n",
476 return -1;
477 }
479 } else {
480 /* fixed block len */
484 }
485
488 return -1;
489 }
490
491 /* now check if the block length is coherent with the frame length */
495 return -1;
496 }
497
500 v = 0;
505 }
506
508
509 /* if no channel coded, no need to go further */
510 /* XXX: fix potential framing problems */
511 if (!v)
512 goto next;
513
514 /* read total gain and extract corresponding number of bits for
515 * coef escape coding */
516 total_gain = 1;
517 for (;;) {
521 }
524 if (a != 127)
525 break;
526 }
527
529
530 /* compute number of coefficients */
533 nb_coefs[ch] = n;
534
535 /* complex coding */
541 for (i = 0; i <
n; i++) {
544 /* if noise coding, the coefficients are not transmitted */
545 if (a)
547 }
548 }
549 }
553
555 val = (
int) 0x80000000;
556 for (i = 0; i <
n; i++) {
558 if (val == (int) 0x80000000) {
560 } else {
563 if (code < 0) {
565 "hgain vlc invalid\n");
566 return -1;
567 }
568 val += code - 18;
569 }
571 }
572 }
573 }
574 }
575 }
576
577 /* exponents can be reused in short blocks. */
583 return -1;
584 } else {
586 }
588 }
589 }
590 }
591
592 /* parse spectral coefficients : just RLE encoding */
595 int tindex;
597
598 /* special VLC tables are used for ms stereo because
599 * there is potentially less energy there */
604 0, ptr, 0, nb_coefs[ch],
606 }
609 }
610
611 /* normalize */
612 {
614 mdct_norm = 1.0 / (float) n4;
616 mdct_norm *= sqrt(n4);
617 }
618
619 /* finally compute the MDCT coefficients */
623 float *coefs, *exponents,
mult, mult1,
noise;
624 int i, j,
n, n1, last_high_band, esize;
626
631 mult *= mdct_norm;
635 /* very low freqs : noise */
638 exponents[i << bsize >> esize] * mult1;
641 }
642
644
645 /* compute power of high bands */
648 last_high_band = 0; /* avoid warning */
649 for (j = 0; j < n1; j++) {
653 float e2, v;
654 e2 = 0;
655 for (i = 0; i <
n; i++) {
656 v = exponents[i << bsize >> esize];
657 e2 += v * v;
658 }
659 exp_power[j] = e2 /
n;
660 last_high_band = j;
661 ff_tlog(s->
avctx,
"%d: power=%f (%d)\n", j, exp_power[j], n);
662 }
663 exponents += n << bsize >> esize;
664 }
665
666 /* main freqs and high freqs */
668 for (j = -1; j < n1; j++) {
669 if (j < 0)
671 else
675 /* use noise with specified power */
676 mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
677 /* XXX: use a table */
680 mult1 *= mdct_norm;
681 for (i = 0; i <
n; i++) {
684 *coefs++ = noise * exponents[i << bsize >> esize] * mult1;
685 }
686 exponents += n << bsize >> esize;
687 } else {
688 /* coded values + small noise */
689 for (i = 0; i <
n; i++) {
692 *coefs++ = ((*coefs1++) + noise) *
693 exponents[i << bsize >> esize] *
mult;
694 }
695 exponents += n << bsize >> esize;
696 }
697 }
698
699 /* very high freqs : noise */
701 mult1 = mult * exponents[(-(1 << bsize)) >> esize];
702 for (i = 0; i <
n; i++) {
705 }
706 } else {
707 /* XXX: optimize more */
709 *coefs++ = 0.0;
711 for (i = 0; i <
n; i++)
712 *coefs++ = coefs1[i] * exponents[i << bsize >> esize] * mult;
714 for (i = 0; i <
n; i++)
715 *coefs++ = 0.0;
716 }
717 }
718 }
719
720 #ifdef TRACE
725 }
726 }
727 #endif /* TRACE */
728
730 /* nominal case for ms stereo: we do it before mdct */
731 /* no need to optimize this case because it should almost
732 * never happen */
737 }
738
740 }
741
742 next:
744
747
753
754 /* multiply by the window and add in the frame */
757 }
758
759 /* update block number */
763 return 1;
764 else
765 return 0;
766 }
767
768 /* decode a frame of frame_len samples */
770 int samples_offset)
771 {
773
774 #ifdef TRACE
777 #endif /* TRACE */
778
779 /* read each block */
782 for (;;) {
784 if (ret < 0)
785 return -1;
786 if (ret)
787 break;
788 }
789
791 /* copy current block to output */
792 memcpy(samples[ch] + samples_offset, s->
frame_out[ch],
794 /* prepare for next block */
797
798 #ifdef TRACE
799 dump_floats(s, "samples", 6, samples[ch] + samples_offset,
801 #endif /* TRACE */
802 }
803
804 return 0;
805 }
806
808 int *got_frame_ptr,
AVPacket *avpkt)
809 {
812 int buf_size = avpkt->
size;
814 int nb_frames, bit_offset, i, pos,
len, ret;
816 float **samples;
817 int samples_offset;
818
819 ff_tlog(avctx,
"***decode_superframe:\n");
820
821 if (buf_size == 0) {
823 return 0;
824 }
825 if (buf_size < avctx->block_align) {
827 "Input packet size too small (%d < %d)\n",
830 }
833
835
837 /* read super frame header */
840 if (nb_frames <= 0) {
843 "nb_frames is %d bits left %d\n",
845 if (is_error)
847
851
853 len = buf_size - 1;
854 while (len > 0) {
856 len --;
857 }
859
861 // s->reset_block_lengths = 1; //XXX is this needed ?
862 *got_frame_ptr = 0;
863 return buf_size;
864 }
865 } else
866 nb_frames = 1;
867
868 /* get output buffer */
871 return ret;
873 samples_offset = 0;
874
879 "Invalid last frame bit offset %d > buf size %d (%d)\n",
882 }
883
885 /* add bit_offset bits to last frame */
890 len = bit_offset;
891 while (len > 7) {
893 len -= 8;
894 }
895 if (len > 0)
898
899 /* XXX: bit_offset bits into last frame */
902 /* skip unused bits */
905 /* this frame is stored in the last superframe and in the
906 * current one */
910 nb_frames--;
911 }
912
913 /* read each frame starting from bit_offset */
918 len = pos & 7;
919 if (len > 0)
921
923 for (i = 0; i < nb_frames; i++) {
927 }
928
929 /* we copy the end of the frame in the last frame buffer */
933 pos >>= 3;
934 len = buf_size - pos;
938 }
941 } else {
942 /* single frame decode */
946 }
947
950 (int8_t *) samples - (int8_t *) data, avctx->
block_align);
951
952 *got_frame_ptr = 1;
953
954 return buf_size;
955
957 /* when error, we reset the bit reservoir */
959 return -1;
960 }
961
963 {
965
968 }
969
970 #if CONFIG_WMAV1_DECODER
984 };
985 #endif
986 #if CONFIG_WMAV2_DECODER
1000 };
1001 #endif
const struct AVCodec * codec
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
int next_block_len_bits
log2 of next block length
static av_cold int init(AVCodecContext *avctx)
static const float pow_tab[]
pow(10, i / 16.0) for i in -60..95
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.
int block_len
block length in samples
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...
float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]
static void wma_window(WMACodecContext *s, float *out)
Apply MDCT window and add into output.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
float lsp_pow_m_table2[(1<< LSP_POW_BITS)]
Macro definitions for various function/variable attributes.
static int wma_decode_block(WMACodecContext *s)
float lsp_cos_table[BLOCK_MAX_SIZE]
int high_band_start[BLOCK_NB_SIZES]
index of first coef in high band
enum AVSampleFormat sample_fmt
audio sample format
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
const uint8_t ff_aac_scalefactor_bits[121]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int block_pos
current position in frame
#define u(width, name, range_min, range_max)
static int decode_exp_vlc(WMACodecContext *s, int ch)
decode exponents coded with VLC codes
static int get_bits_count(const GetBitContext *s)
float lsp_pow_m_table1[(1<< LSP_POW_BITS)]
int nb_block_sizes
number of block sizes
int ff_wma_total_gain_to_bits(int total_gain)
static int get_bits_left(GetBitContext *gb)
static float pow_m1_4(WMACodecContext *s, float x)
compute x^-0.25 with an exponent and mantissa table.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define PTRDIFF_SPECIFIER
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
uint16_t exponent_bands[BLOCK_NB_SIZES][25]
uint8_t channel_coded[MAX_CHANNELS]
true if channel is coded
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void(* butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len)
Calculate the sum and difference of two vectors of floats.
uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE+AV_INPUT_BUFFER_PADDING_SIZE]
const char * name
Name of the codec implementation.
static int wma_decode_superframe(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
FFTSample output[BLOCK_MAX_SIZE *2]
const uint8_t ff_wma_hgain_huffbits[37]
static av_cold int wma_decode_init(AVCodecContext *avctx)
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE]
int ff_wma_end(AVCodecContext *avctx)
int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
static int16_t mult(Float11 *f1, Float11 *f2)
#define MAX_CODED_SUPERFRAME_SIZE
av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
const uint16_t ff_wma_hgain_huffcodes[37]
int version
1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
int frame_len
frame length in samples
#define FF_ARRAY_ELEMS(a)
static av_cold void flush(AVCodecContext *avctx)
int frame_len_bits
frame_len = 1 << frame_len_bits
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
static int wma_decode_frame(WMACodecContext *s, float **samples, int samples_offset)
#define HIGH_BAND_MAX_SIZE
int use_exp_vlc
exponent coding: 0 = lsp, 1 = vlc + delta
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE *2]
int exponent_high_sizes[BLOCK_NB_SIZES]
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...
static void decode_exp_lsp(WMACodecContext *s, int ch)
decode exponents coded with LSP coefficients (same idea as Vorbis)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
int block_num
block number in current frame
int use_noise_coding
true if perceptual noise is added
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int use_variable_block_len
uint8_t ms_stereo
true if mid/side stereo mode
FFTContext mdct_ctx[BLOCK_NB_SIZES]
const uint32_t ff_aac_scalefactor_code[121]
int exponents_bsize[MAX_CHANNELS]
log2 ratio frame/exp. length
static int noise(AVBSFContext *ctx, AVPacket *pkt)
float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]
int prev_block_len_bits
log2 of prev block length
int coefs_end[BLOCK_NB_SIZES]
max number of coded coefficients
internal math functions header
float lsp_pow_e_table[256]
const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]
common internal api header.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int channels
number of audio channels
VLC_TYPE(* table)[2]
code, bits
WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]
static const uint8_t * align_get_bits(GetBitContext *s)
static const struct twinvq_data tab
static enum AVSampleFormat sample_fmts[]
float max_exponent[MAX_CHANNELS]
int coefs_start
first coded coef
int block_len_bits
log2 of current block length
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE]
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
float noise_table[NOISE_TAB_SIZE]
const float * windows[BLOCK_NB_SIZES]