36 #include "config_components.h"
48 #define EXPMAX ((19 + EXPVLCBITS - 1) / EXPVLCBITS)
50 #define HGAINVLCBITS 9
51 #define HGAINMAX ((13 + HGAINVLCBITS - 1) / HGAINVLCBITS)
57 int prec,
const float *
tab,
int n)
62 for (
i = 0;
i < n;
i++) {
91 flags2 =
AV_RL16(extradata + 2);
93 flags2 =
AV_RL16(extradata + 4);
95 s->use_exp_vlc = flags2 & 0x0001;
96 s->use_bit_reservoir = flags2 & 0x0002;
97 s->use_variable_block_len = flags2 & 0x0004;
100 if (
AV_RL16(extradata+4)==0xd &&
s->use_variable_block_len){
101 av_log(avctx,
AV_LOG_WARNING,
"Disabling use_variable_block_len, if this fails contact the ffmpeg developers and send us the file\n");
102 s->use_variable_block_len= 0;
107 s->max_exponent[
i] = 1.0;
113 for (
i = 0;
i <
s->nb_block_sizes;
i++) {
114 float scale = 1.0 / 32768.0;
121 if (
s->use_noise_coding) {
131 if (
s->use_exp_vlc) {
167 t.v = ((
u.v <<
LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
168 a =
s->lsp_pow_m_table1[m];
169 b =
s->lsp_pow_m_table2[m];
170 return s->lsp_pow_e_table[e] * (
a +
b * t.f);
178 wdel =
M_PI / frame_len;
179 for (
i = 0;
i < frame_len;
i++)
180 s->lsp_cos_table[
i] = 2.0f * cos(wdel *
i);
183 for (
i = 0;
i < 256;
i++) {
185 s->lsp_pow_e_table[
i] =
exp2f(e * -0.25);
195 s->lsp_pow_m_table1[
i] = 2 *
a -
b;
196 s->lsp_pow_m_table2[
i] =
b -
a;
209 float p, q,
w, v, val_max;
212 for (
i = 0;
i < n;
i++) {
215 w =
s->lsp_cos_table[
i];
228 *val_max_ptr = val_max;
240 if (
i == 0 ||
i >= 8)
248 s->block_len, lsp_coefs);
253 1.7782794100389e-04, 2.0535250264571e-04,
254 2.3713737056617e-04, 2.7384196342644e-04,
255 3.1622776601684e-04, 3.6517412725484e-04,
256 4.2169650342858e-04, 4.8696752516586e-04,
257 5.6234132519035e-04, 6.4938163157621e-04,
258 7.4989420933246e-04, 8.6596432336006e-04,
259 1.0000000000000e-03, 1.1547819846895e-03,
260 1.3335214321633e-03, 1.5399265260595e-03,
261 1.7782794100389e-03, 2.0535250264571e-03,
262 2.3713737056617e-03, 2.7384196342644e-03,
263 3.1622776601684e-03, 3.6517412725484e-03,
264 4.2169650342858e-03, 4.8696752516586e-03,
265 5.6234132519035e-03, 6.4938163157621e-03,
266 7.4989420933246e-03, 8.6596432336006e-03,
267 1.0000000000000e-02, 1.1547819846895e-02,
268 1.3335214321633e-02, 1.5399265260595e-02,
269 1.7782794100389e-02, 2.0535250264571e-02,
270 2.3713737056617e-02, 2.7384196342644e-02,
271 3.1622776601684e-02, 3.6517412725484e-02,
272 4.2169650342858e-02, 4.8696752516586e-02,
273 5.6234132519035e-02, 6.4938163157621e-02,
274 7.4989420933246e-02, 8.6596432336007e-02,
275 1.0000000000000e-01, 1.1547819846895e-01,
276 1.3335214321633e-01, 1.5399265260595e-01,
277 1.7782794100389e-01, 2.0535250264571e-01,
278 2.3713737056617e-01, 2.7384196342644e-01,
279 3.1622776601684e-01, 3.6517412725484e-01,
280 4.2169650342858e-01, 4.8696752516586e-01,
281 5.6234132519035e-01, 6.4938163157621e-01,
282 7.4989420933246e-01, 8.6596432336007e-01,
283 1.0000000000000e+00, 1.1547819846895e+00,
284 1.3335214321633e+00, 1.5399265260595e+00,
285 1.7782794100389e+00, 2.0535250264571e+00,
286 2.3713737056617e+00, 2.7384196342644e+00,
287 3.1622776601684e+00, 3.6517412725484e+00,
288 4.2169650342858e+00, 4.8696752516586e+00,
289 5.6234132519035e+00, 6.4938163157621e+00,
290 7.4989420933246e+00, 8.6596432336007e+00,
291 1.0000000000000e+01, 1.1547819846895e+01,
292 1.3335214321633e+01, 1.5399265260595e+01,
293 1.7782794100389e+01, 2.0535250264571e+01,
294 2.3713737056617e+01, 2.7384196342644e+01,
295 3.1622776601684e+01, 3.6517412725484e+01,
296 4.2169650342858e+01, 4.8696752516586e+01,
297 5.6234132519035e+01, 6.4938163157621e+01,
298 7.4989420933246e+01, 8.6596432336007e+01,
299 1.0000000000000e+02, 1.1547819846895e+02,
300 1.3335214321633e+02, 1.5399265260595e+02,
301 1.7782794100389e+02, 2.0535250264571e+02,
302 2.3713737056617e+02, 2.7384196342644e+02,
303 3.1622776601684e+02, 3.6517412725484e+02,
304 4.2169650342858e+02, 4.8696752516586e+02,
305 5.6234132519035e+02, 6.4938163157621e+02,
306 7.4989420933246e+02, 8.6596432336007e+02,
307 1.0000000000000e+03, 1.1547819846895e+03,
308 1.3335214321633e+03, 1.5399265260595e+03,
309 1.7782794100389e+03, 2.0535250264571e+03,
310 2.3713737056617e+03, 2.7384196342644e+03,
311 3.1622776601684e+03, 3.6517412725484e+03,
312 4.2169650342858e+03, 4.8696752516586e+03,
313 5.6234132519035e+03, 6.4938163157621e+03,
314 7.4989420933246e+03, 8.6596432336007e+03,
315 1.0000000000000e+04, 1.1547819846895e+04,
316 1.3335214321633e+04, 1.5399265260595e+04,
317 1.7782794100389e+04, 2.0535250264571e+04,
318 2.3713737056617e+04, 2.7384196342644e+04,
319 3.1622776601684e+04, 3.6517412725484e+04,
320 4.2169650342858e+04, 4.8696752516586e+04,
321 5.6234132519035e+04, 6.4938163157621e+04,
322 7.4989420933246e+04, 8.6596432336007e+04,
323 1.0000000000000e+05, 1.1547819846895e+05,
324 1.3335214321633e+05, 1.5399265260595e+05,
325 1.7782794100389e+05, 2.0535250264571e+05,
326 2.3713737056617e+05, 2.7384196342644e+05,
327 3.1622776601684e+05, 3.6517412725484e+05,
328 4.2169650342858e+05, 4.8696752516586e+05,
329 5.6234132519035e+05, 6.4938163157621e+05,
330 7.4989420933246e+05, 8.6596432336007e+05,
338 int last_exp, n,
code;
341 uint32_t *q, *q_end, iv;
342 const float *ptab =
pow_tab + 60;
343 const uint32_t *iptab = (
const uint32_t *) ptab;
345 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
346 q = (uint32_t *)
s->exponents[ch];
347 q_end = q +
s->block_len;
349 if (
s->version == 1) {
352 iv = iptab[last_exp];
360 }
while ((n -= 4) > 0);
367 last_exp +=
code - 60;
374 iv = iptab[last_exp];
383 }
while ((n -= 4) > 0);
385 s->max_exponent[ch] = max_scale;
397 float *in =
s->output;
398 int block_len, bsize, n;
401 if (
s->block_len_bits <=
s->prev_block_len_bits) {
402 block_len =
s->block_len;
403 bsize =
s->frame_len_bits -
s->block_len_bits;
405 s->fdsp->vector_fmul_add(
out, in,
s->windows[bsize],
408 block_len = 1 <<
s->prev_block_len_bits;
409 n = (
s->block_len - block_len) / 2;
410 bsize =
s->frame_len_bits -
s->prev_block_len_bits;
412 s->fdsp->vector_fmul_add(
out + n, in + n,
s->windows[bsize],
415 memcpy(
out + n + block_len, in + n + block_len, n *
sizeof(
float));
422 if (
s->block_len_bits <=
s->next_block_len_bits) {
423 block_len =
s->block_len;
424 bsize =
s->frame_len_bits -
s->block_len_bits;
426 s->fdsp->vector_fmul_reverse(
out, in,
s->windows[bsize], block_len);
428 block_len = 1 <<
s->next_block_len_bits;
429 n = (
s->block_len - block_len) / 2;
430 bsize =
s->frame_len_bits -
s->next_block_len_bits;
432 memcpy(
out, in, n *
sizeof(
float));
434 s->fdsp->vector_fmul_reverse(
out + n, in + n,
s->windows[bsize],
437 memset(
out + n + block_len, 0, n *
sizeof(
float));
447 int channels =
s->avctx->ch_layout.nb_channels;
448 int n, v,
a, ch, bsize;
449 int coef_nb_bits, total_gain;
456 ff_tlog(
s->avctx,
"***decode_block: %d:%d\n",
457 s->frame_count - 1,
s->block_num);
461 if (
s->use_variable_block_len) {
462 n =
av_log2(
s->nb_block_sizes - 1) + 1;
464 if (
s->reset_block_lengths) {
465 s->reset_block_lengths = 0;
467 if (v >=
s->nb_block_sizes) {
469 "prev_block_len_bits %d out of range\n",
470 s->frame_len_bits - v);
473 s->prev_block_len_bits =
s->frame_len_bits - v;
475 if (v >=
s->nb_block_sizes) {
477 "block_len_bits %d out of range\n",
478 s->frame_len_bits - v);
481 s->block_len_bits =
s->frame_len_bits - v;
484 s->prev_block_len_bits =
s->block_len_bits;
485 s->block_len_bits =
s->next_block_len_bits;
488 if (v >=
s->nb_block_sizes) {
490 "next_block_len_bits %d out of range\n",
491 s->frame_len_bits - v);
494 s->next_block_len_bits =
s->frame_len_bits - v;
497 s->next_block_len_bits =
s->frame_len_bits;
498 s->prev_block_len_bits =
s->frame_len_bits;
499 s->block_len_bits =
s->frame_len_bits;
502 if (
s->frame_len_bits -
s->block_len_bits >=
s->nb_block_sizes){
508 s->block_len = 1 <<
s->block_len_bits;
509 if ((
s->block_pos +
s->block_len) >
s->frame_len) {
519 s->channel_coded[ch] =
a;
523 bsize =
s->frame_len_bits -
s->block_len_bits;
547 n =
s->coefs_end[bsize] -
s->coefs_start;
552 if (
s->use_noise_coding) {
554 if (
s->channel_coded[ch]) {
556 n =
s->exponent_high_sizes[bsize];
557 for (
i = 0;
i < n;
i++) {
559 s->high_band_coded[ch][
i] =
a;
562 nb_coefs[ch] -=
s->exponent_high_bands[bsize][
i];
567 if (
s->channel_coded[ch]) {
570 n =
s->exponent_high_sizes[bsize];
572 for (
i = 0;
i < n;
i++) {
573 if (
s->high_band_coded[ch][
i]) {
574 if (
val == (
int) 0x80000000) {
580 s->high_band_values[ch][
i] =
val;
588 if ((
s->block_len_bits ==
s->frame_len_bits) ||
get_bits1(&
s->gb)) {
590 if (
s->channel_coded[ch]) {
591 if (
s->use_exp_vlc) {
597 s->exponents_bsize[ch] = bsize;
598 s->exponents_initialized[ch] = 1;
604 if (
s->channel_coded[ch] && !
s->exponents_initialized[ch])
610 if (
s->channel_coded[ch]) {
617 tindex = (ch == 1 &&
s->ms_stereo);
618 memset(ptr, 0,
s->block_len *
sizeof(
WMACoef));
620 s->level_table[tindex],
s->run_table[tindex],
622 s->block_len,
s->frame_len_bits, coef_nb_bits);
632 int n4 =
s->block_len / 2;
633 mdct_norm = 1.0 / (
float) n4;
635 mdct_norm *= sqrt(n4);
640 if (
s->channel_coded[ch]) {
642 float *coefs, *exponents,
mult, mult1,
noise;
643 int i, j, n, n1, last_high_band, esize;
646 coefs1 =
s->coefs1[ch];
647 exponents =
s->exponents[ch];
648 esize =
s->exponents_bsize[ch];
651 coefs =
s->coefs[ch];
652 if (
s->use_noise_coding) {
655 for (
i = 0;
i <
s->coefs_start;
i++) {
656 *coefs++ =
s->noise_table[
s->noise_index] *
657 exponents[i << bsize >> esize] * mult1;
658 s->noise_index = (
s->noise_index + 1) &
662 n1 =
s->exponent_high_sizes[bsize];
665 exponents =
s->exponents[ch] +
666 (
s->high_band_start[bsize] << bsize >> esize);
668 for (j = 0; j < n1; j++) {
669 n =
s->exponent_high_bands[
s->frame_len_bits -
670 s->block_len_bits][j];
671 if (
s->high_band_coded[ch][j]) {
674 for (
i = 0;
i < n;
i++) {
675 v = exponents[i << bsize >> esize];
678 exp_power[j] = e2 / n;
680 ff_tlog(
s->avctx,
"%d: power=%f (%d)\n", j, exp_power[j], n);
682 exponents += n << bsize >> esize;
686 exponents =
s->exponents[ch] + (
s->coefs_start << bsize >> esize);
687 for (j = -1; j < n1; j++) {
689 n =
s->high_band_start[bsize] -
s->coefs_start;
691 n =
s->exponent_high_bands[
s->frame_len_bits -
692 s->block_len_bits][j];
693 if (j >= 0 &&
s->high_band_coded[ch][j]) {
695 mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
697 mult1 = mult1 *
ff_exp10(
s->high_band_values[ch][j] * 0.05);
698 mult1 = mult1 / (
s->max_exponent[ch] *
s->noise_mult);
700 for (
i = 0;
i < n;
i++) {
701 noise =
s->noise_table[
s->noise_index];
703 *coefs++ =
noise * exponents[i << bsize >> esize] * mult1;
705 exponents += n << bsize >> esize;
708 for (
i = 0;
i < n;
i++) {
709 noise =
s->noise_table[
s->noise_index];
711 *coefs++ = ((*coefs1++) +
noise) *
712 exponents[i << bsize >> esize] *
mult;
714 exponents += n << bsize >> esize;
719 n =
s->block_len -
s->coefs_end[bsize];
720 mult1 =
mult * exponents[(-(1 << bsize)) >> esize];
721 for (
i = 0;
i < n;
i++) {
722 *coefs++ =
s->noise_table[
s->noise_index] * mult1;
727 for (
i = 0;
i <
s->coefs_start;
i++)
730 for (
i = 0;
i < n;
i++)
731 *coefs++ = coefs1[
i] * exponents[
i << bsize >> esize] *
mult;
732 n =
s->block_len -
s->coefs_end[bsize];
733 for (
i = 0;
i < n;
i++)
741 if (
s->channel_coded[ch]) {
742 dump_floats(
s,
"exponents", 3,
s->exponents[ch],
s->block_len);
743 dump_floats(
s,
"coefs", 1,
s->coefs[ch],
s->block_len);
748 if (
s->ms_stereo &&
s->channel_coded[1]) {
752 if (!
s->channel_coded[0]) {
753 ff_tlog(
s->avctx,
"rare ms-stereo case happened\n");
754 memset(
s->coefs[0], 0,
sizeof(
float) *
s->block_len);
755 s->channel_coded[0] = 1;
758 s->fdsp->butterflies_float(
s->coefs[0],
s->coefs[1],
s->block_len);
762 mdct =
s->mdct_ctx[bsize];
763 mdct_fn =
s->mdct_fn[bsize];
768 n4 =
s->block_len / 2;
769 if (
s->channel_coded[ch])
770 mdct_fn(mdct,
s->output,
s->coefs[ch],
sizeof(
float));
771 else if (!(
s->ms_stereo && ch == 1))
772 memset(
s->output, 0,
sizeof(
s->output));
775 index = (
s->frame_len / 2) +
s->block_pos - n4;
781 s->block_pos +=
s->block_len;
782 if (
s->block_pos >=
s->frame_len)
795 ff_tlog(
s->avctx,
"***decode_frame: %d size=%d\n",
796 s->frame_count++,
s->frame_len);
810 for (ch = 0; ch <
s->avctx->ch_layout.nb_channels; ch++) {
812 memcpy(
samples[ch] + samples_offset,
s->frame_out[ch],
813 s->frame_len *
sizeof(*
s->frame_out[ch]));
815 memmove(&
s->frame_out[ch][0], &
s->frame_out[ch][
s->frame_len],
816 s->frame_len *
sizeof(*
s->frame_out[ch]));
819 dump_floats(
s,
"samples", 6,
samples[ch] + samples_offset,
828 int *got_frame_ptr,
AVPacket *avpkt)
830 const uint8_t *buf = avpkt->
data;
831 int buf_size = avpkt->
size;
838 ff_tlog(avctx,
"***decode_superframe:\n");
849 for (
i = 0;
i <
s->avctx->ch_layout.nb_channels;
i++)
853 s->last_superframe_len = 0;
858 if (buf_size < avctx->block_align) {
860 "Input packet size too small (%d < %d)\n",
869 if (
s->use_bit_reservoir) {
872 nb_frames =
get_bits(&
s->gb, 4) - (
s->last_superframe_len <= 0);
873 if (nb_frames <= 0) {
876 "nb_frames is %d bits left %d\n",
881 if ((
s->last_superframe_len + buf_size - 1) >
885 q =
s->last_superframe +
s->last_superframe_len;
893 s->last_superframe_len += 8*buf_size - 8;
908 if (
s->use_bit_reservoir) {
909 bit_offset =
get_bits(&
s->gb,
s->byte_offset_bits + 3);
912 "Invalid last frame bit offset %d > buf size %d (%d)\n",
917 if (
s->last_superframe_len > 0) {
919 if ((
s->last_superframe_len + ((bit_offset + 7) >> 3)) >
922 q =
s->last_superframe +
s->last_superframe_len;
934 s->last_superframe_len * 8 + bit_offset);
936 if (
s->last_bitoffset > 0)
942 samples_offset +=
s->frame_len;
947 pos = bit_offset + 4 + 4 +
s->byte_offset_bits + 3;
955 s->reset_block_lengths = 1;
956 for (
i = 0;
i < nb_frames;
i++) {
959 samples_offset +=
s->frame_len;
964 ((bit_offset + 4 + 4 +
s->byte_offset_bits + 3) & ~7);
965 s->last_bitoffset =
pos & 7;
972 s->last_superframe_len =
len;
973 memcpy(
s->last_superframe, buf +
pos,
len);
978 samples_offset +=
s->frame_len;
981 ff_dlog(
s->avctx,
"%d %d %d %d eaten:%d\n",
982 s->frame_len_bits,
s->block_len_bits,
s->frame_len,
s->block_len,
991 s->last_superframe_len = 0;
1000 s->last_superframe_len = 0;
1006 #if CONFIG_WMAV1_DECODER
1023 #if CONFIG_WMAV2_DECODER