36 #include "config_components.h"
47 #define EXPMAX ((19 + EXPVLCBITS - 1) / EXPVLCBITS)
49 #define HGAINVLCBITS 9
50 #define HGAINMAX ((13 + HGAINVLCBITS - 1) / HGAINVLCBITS)
56 int prec,
const float *
tab,
int n)
61 for (
i = 0;
i < n;
i++) {
90 flags2 =
AV_RL16(extradata + 2);
92 flags2 =
AV_RL16(extradata + 4);
94 s->use_exp_vlc = flags2 & 0x0001;
95 s->use_bit_reservoir = flags2 & 0x0002;
96 s->use_variable_block_len = flags2 & 0x0004;
99 if (
AV_RL16(extradata+4)==0xd &&
s->use_variable_block_len){
100 av_log(avctx,
AV_LOG_WARNING,
"Disabling use_variable_block_len, if this fails contact the ffmpeg developers and send us the file\n");
101 s->use_variable_block_len= 0;
106 s->max_exponent[
i] = 1.0;
112 for (
i = 0;
i <
s->nb_block_sizes;
i++) {
119 if (
s->use_noise_coding) {
129 if (
s->use_exp_vlc) {
165 t.v = ((
u.v <<
LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
166 a =
s->lsp_pow_m_table1[m];
167 b =
s->lsp_pow_m_table2[m];
168 return s->lsp_pow_e_table[e] * (
a +
b * t.f);
176 wdel =
M_PI / frame_len;
177 for (
i = 0;
i < frame_len;
i++)
178 s->lsp_cos_table[
i] = 2.0f * cos(wdel *
i);
181 for (
i = 0;
i < 256;
i++) {
183 s->lsp_pow_e_table[
i] =
exp2f(e * -0.25);
193 s->lsp_pow_m_table1[
i] = 2 *
a -
b;
194 s->lsp_pow_m_table2[
i] =
b -
a;
207 float p, q,
w, v, val_max;
210 for (
i = 0;
i < n;
i++) {
213 w =
s->lsp_cos_table[
i];
226 *val_max_ptr = val_max;
238 if (
i == 0 ||
i >= 8)
246 s->block_len, lsp_coefs);
251 1.7782794100389e-04, 2.0535250264571e-04,
252 2.3713737056617e-04, 2.7384196342644e-04,
253 3.1622776601684e-04, 3.6517412725484e-04,
254 4.2169650342858e-04, 4.8696752516586e-04,
255 5.6234132519035e-04, 6.4938163157621e-04,
256 7.4989420933246e-04, 8.6596432336006e-04,
257 1.0000000000000e-03, 1.1547819846895e-03,
258 1.3335214321633e-03, 1.5399265260595e-03,
259 1.7782794100389e-03, 2.0535250264571e-03,
260 2.3713737056617e-03, 2.7384196342644e-03,
261 3.1622776601684e-03, 3.6517412725484e-03,
262 4.2169650342858e-03, 4.8696752516586e-03,
263 5.6234132519035e-03, 6.4938163157621e-03,
264 7.4989420933246e-03, 8.6596432336006e-03,
265 1.0000000000000e-02, 1.1547819846895e-02,
266 1.3335214321633e-02, 1.5399265260595e-02,
267 1.7782794100389e-02, 2.0535250264571e-02,
268 2.3713737056617e-02, 2.7384196342644e-02,
269 3.1622776601684e-02, 3.6517412725484e-02,
270 4.2169650342858e-02, 4.8696752516586e-02,
271 5.6234132519035e-02, 6.4938163157621e-02,
272 7.4989420933246e-02, 8.6596432336007e-02,
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+00, 1.1547819846895e+00,
282 1.3335214321633e+00, 1.5399265260595e+00,
283 1.7782794100389e+00, 2.0535250264571e+00,
284 2.3713737056617e+00, 2.7384196342644e+00,
285 3.1622776601684e+00, 3.6517412725484e+00,
286 4.2169650342858e+00, 4.8696752516586e+00,
287 5.6234132519035e+00, 6.4938163157621e+00,
288 7.4989420933246e+00, 8.6596432336007e+00,
289 1.0000000000000e+01, 1.1547819846895e+01,
290 1.3335214321633e+01, 1.5399265260595e+01,
291 1.7782794100389e+01, 2.0535250264571e+01,
292 2.3713737056617e+01, 2.7384196342644e+01,
293 3.1622776601684e+01, 3.6517412725484e+01,
294 4.2169650342858e+01, 4.8696752516586e+01,
295 5.6234132519035e+01, 6.4938163157621e+01,
296 7.4989420933246e+01, 8.6596432336007e+01,
297 1.0000000000000e+02, 1.1547819846895e+02,
298 1.3335214321633e+02, 1.5399265260595e+02,
299 1.7782794100389e+02, 2.0535250264571e+02,
300 2.3713737056617e+02, 2.7384196342644e+02,
301 3.1622776601684e+02, 3.6517412725484e+02,
302 4.2169650342858e+02, 4.8696752516586e+02,
303 5.6234132519035e+02, 6.4938163157621e+02,
304 7.4989420933246e+02, 8.6596432336007e+02,
305 1.0000000000000e+03, 1.1547819846895e+03,
306 1.3335214321633e+03, 1.5399265260595e+03,
307 1.7782794100389e+03, 2.0535250264571e+03,
308 2.3713737056617e+03, 2.7384196342644e+03,
309 3.1622776601684e+03, 3.6517412725484e+03,
310 4.2169650342858e+03, 4.8696752516586e+03,
311 5.6234132519035e+03, 6.4938163157621e+03,
312 7.4989420933246e+03, 8.6596432336007e+03,
313 1.0000000000000e+04, 1.1547819846895e+04,
314 1.3335214321633e+04, 1.5399265260595e+04,
315 1.7782794100389e+04, 2.0535250264571e+04,
316 2.3713737056617e+04, 2.7384196342644e+04,
317 3.1622776601684e+04, 3.6517412725484e+04,
318 4.2169650342858e+04, 4.8696752516586e+04,
319 5.6234132519035e+04, 6.4938163157621e+04,
320 7.4989420933246e+04, 8.6596432336007e+04,
321 1.0000000000000e+05, 1.1547819846895e+05,
322 1.3335214321633e+05, 1.5399265260595e+05,
323 1.7782794100389e+05, 2.0535250264571e+05,
324 2.3713737056617e+05, 2.7384196342644e+05,
325 3.1622776601684e+05, 3.6517412725484e+05,
326 4.2169650342858e+05, 4.8696752516586e+05,
327 5.6234132519035e+05, 6.4938163157621e+05,
328 7.4989420933246e+05, 8.6596432336007e+05,
336 int last_exp, n,
code;
339 uint32_t *q, *q_end, iv;
340 const float *ptab =
pow_tab + 60;
341 const uint32_t *iptab = (
const uint32_t *) ptab;
343 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
344 q = (uint32_t *)
s->exponents[ch];
345 q_end = q +
s->block_len;
347 if (
s->version == 1) {
350 iv = iptab[last_exp];
358 }
while ((n -= 4) > 0);
365 last_exp +=
code - 60;
372 iv = iptab[last_exp];
381 }
while ((n -= 4) > 0);
383 s->max_exponent[ch] = max_scale;
395 float *in =
s->output;
396 int block_len, bsize, n;
399 if (
s->block_len_bits <=
s->prev_block_len_bits) {
400 block_len =
s->block_len;
401 bsize =
s->frame_len_bits -
s->block_len_bits;
403 s->fdsp->vector_fmul_add(
out, in,
s->windows[bsize],
406 block_len = 1 <<
s->prev_block_len_bits;
407 n = (
s->block_len - block_len) / 2;
408 bsize =
s->frame_len_bits -
s->prev_block_len_bits;
410 s->fdsp->vector_fmul_add(
out + n, in + n,
s->windows[bsize],
413 memcpy(
out + n + block_len, in + n + block_len, n *
sizeof(
float));
420 if (
s->block_len_bits <=
s->next_block_len_bits) {
421 block_len =
s->block_len;
422 bsize =
s->frame_len_bits -
s->block_len_bits;
424 s->fdsp->vector_fmul_reverse(
out, in,
s->windows[bsize], block_len);
426 block_len = 1 <<
s->next_block_len_bits;
427 n = (
s->block_len - block_len) / 2;
428 bsize =
s->frame_len_bits -
s->next_block_len_bits;
430 memcpy(
out, in, n *
sizeof(
float));
432 s->fdsp->vector_fmul_reverse(
out + n, in + n,
s->windows[bsize],
435 memset(
out + n + block_len, 0, n *
sizeof(
float));
445 int channels =
s->avctx->ch_layout.nb_channels;
446 int n, v,
a, ch, bsize;
447 int coef_nb_bits, total_gain;
453 ff_tlog(
s->avctx,
"***decode_block: %d:%d\n",
454 s->frame_count - 1,
s->block_num);
458 if (
s->use_variable_block_len) {
459 n =
av_log2(
s->nb_block_sizes - 1) + 1;
461 if (
s->reset_block_lengths) {
462 s->reset_block_lengths = 0;
464 if (v >=
s->nb_block_sizes) {
466 "prev_block_len_bits %d out of range\n",
467 s->frame_len_bits - v);
470 s->prev_block_len_bits =
s->frame_len_bits - v;
472 if (v >=
s->nb_block_sizes) {
474 "block_len_bits %d out of range\n",
475 s->frame_len_bits - v);
478 s->block_len_bits =
s->frame_len_bits - v;
481 s->prev_block_len_bits =
s->block_len_bits;
482 s->block_len_bits =
s->next_block_len_bits;
485 if (v >=
s->nb_block_sizes) {
487 "next_block_len_bits %d out of range\n",
488 s->frame_len_bits - v);
491 s->next_block_len_bits =
s->frame_len_bits - v;
494 s->next_block_len_bits =
s->frame_len_bits;
495 s->prev_block_len_bits =
s->frame_len_bits;
496 s->block_len_bits =
s->frame_len_bits;
499 if (
s->frame_len_bits -
s->block_len_bits >=
s->nb_block_sizes){
505 s->block_len = 1 <<
s->block_len_bits;
506 if ((
s->block_pos +
s->block_len) >
s->frame_len) {
516 s->channel_coded[ch] =
a;
520 bsize =
s->frame_len_bits -
s->block_len_bits;
544 n =
s->coefs_end[bsize] -
s->coefs_start;
549 if (
s->use_noise_coding) {
551 if (
s->channel_coded[ch]) {
553 n =
s->exponent_high_sizes[bsize];
554 for (
i = 0;
i < n;
i++) {
556 s->high_band_coded[ch][
i] =
a;
559 nb_coefs[ch] -=
s->exponent_high_bands[bsize][
i];
564 if (
s->channel_coded[ch]) {
567 n =
s->exponent_high_sizes[bsize];
569 for (
i = 0;
i < n;
i++) {
570 if (
s->high_band_coded[ch][
i]) {
571 if (
val == (
int) 0x80000000) {
577 s->high_band_values[ch][
i] =
val;
585 if ((
s->block_len_bits ==
s->frame_len_bits) ||
get_bits1(&
s->gb)) {
587 if (
s->channel_coded[ch]) {
588 if (
s->use_exp_vlc) {
594 s->exponents_bsize[ch] = bsize;
595 s->exponents_initialized[ch] = 1;
601 if (
s->channel_coded[ch] && !
s->exponents_initialized[ch])
607 if (
s->channel_coded[ch]) {
614 tindex = (ch == 1 &&
s->ms_stereo);
615 memset(ptr, 0,
s->block_len *
sizeof(
WMACoef));
617 s->level_table[tindex],
s->run_table[tindex],
619 s->block_len,
s->frame_len_bits, coef_nb_bits);
629 int n4 =
s->block_len / 2;
630 mdct_norm = 1.0 / (
float) n4;
632 mdct_norm *= sqrt(n4);
637 if (
s->channel_coded[ch]) {
639 float *coefs, *exponents,
mult, mult1,
noise;
640 int i, j, n, n1, last_high_band, esize;
643 coefs1 =
s->coefs1[ch];
644 exponents =
s->exponents[ch];
645 esize =
s->exponents_bsize[ch];
648 coefs =
s->coefs[ch];
649 if (
s->use_noise_coding) {
652 for (
i = 0;
i <
s->coefs_start;
i++) {
653 *coefs++ =
s->noise_table[
s->noise_index] *
654 exponents[i << bsize >> esize] * mult1;
655 s->noise_index = (
s->noise_index + 1) &
659 n1 =
s->exponent_high_sizes[bsize];
662 exponents =
s->exponents[ch] +
663 (
s->high_band_start[bsize] << bsize >> esize);
665 for (j = 0; j < n1; j++) {
666 n =
s->exponent_high_bands[
s->frame_len_bits -
667 s->block_len_bits][j];
668 if (
s->high_band_coded[ch][j]) {
671 for (
i = 0;
i < n;
i++) {
672 v = exponents[i << bsize >> esize];
675 exp_power[j] = e2 / n;
677 ff_tlog(
s->avctx,
"%d: power=%f (%d)\n", j, exp_power[j], n);
679 exponents += n << bsize >> esize;
683 exponents =
s->exponents[ch] + (
s->coefs_start << bsize >> esize);
684 for (j = -1; j < n1; j++) {
686 n =
s->high_band_start[bsize] -
s->coefs_start;
688 n =
s->exponent_high_bands[
s->frame_len_bits -
689 s->block_len_bits][j];
690 if (j >= 0 &&
s->high_band_coded[ch][j]) {
692 mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
694 mult1 = mult1 *
ff_exp10(
s->high_band_values[ch][j] * 0.05);
695 mult1 = mult1 / (
s->max_exponent[ch] *
s->noise_mult);
697 for (
i = 0;
i < n;
i++) {
698 noise =
s->noise_table[
s->noise_index];
700 *coefs++ =
noise * exponents[i << bsize >> esize] * mult1;
702 exponents += n << bsize >> esize;
705 for (
i = 0;
i < n;
i++) {
706 noise =
s->noise_table[
s->noise_index];
708 *coefs++ = ((*coefs1++) +
noise) *
709 exponents[i << bsize >> esize] *
mult;
711 exponents += n << bsize >> esize;
716 n =
s->block_len -
s->coefs_end[bsize];
717 mult1 =
mult * exponents[(-(1 << bsize)) >> esize];
718 for (
i = 0;
i < n;
i++) {
719 *coefs++ =
s->noise_table[
s->noise_index] * mult1;
724 for (
i = 0;
i <
s->coefs_start;
i++)
727 for (
i = 0;
i < n;
i++)
728 *coefs++ = coefs1[
i] * exponents[
i << bsize >> esize] *
mult;
729 n =
s->block_len -
s->coefs_end[bsize];
730 for (
i = 0;
i < n;
i++)
738 if (
s->channel_coded[ch]) {
739 dump_floats(
s,
"exponents", 3,
s->exponents[ch],
s->block_len);
740 dump_floats(
s,
"coefs", 1,
s->coefs[ch],
s->block_len);
745 if (
s->ms_stereo &&
s->channel_coded[1]) {
749 if (!
s->channel_coded[0]) {
750 ff_tlog(
s->avctx,
"rare ms-stereo case happened\n");
751 memset(
s->coefs[0], 0,
sizeof(
float) *
s->block_len);
752 s->channel_coded[0] = 1;
755 s->fdsp->butterflies_float(
s->coefs[0],
s->coefs[1],
s->block_len);
759 mdct = &
s->mdct_ctx[bsize];
764 n4 =
s->block_len / 2;
765 if (
s->channel_coded[ch])
767 else if (!(
s->ms_stereo && ch == 1))
768 memset(
s->output, 0,
sizeof(
s->output));
771 index = (
s->frame_len / 2) +
s->block_pos - n4;
777 s->block_pos +=
s->block_len;
778 if (
s->block_pos >=
s->frame_len)
791 ff_tlog(
s->avctx,
"***decode_frame: %d size=%d\n",
792 s->frame_count++,
s->frame_len);
806 for (ch = 0; ch <
s->avctx->ch_layout.nb_channels; ch++) {
808 memcpy(
samples[ch] + samples_offset,
s->frame_out[ch],
809 s->frame_len *
sizeof(*
s->frame_out[ch]));
811 memmove(&
s->frame_out[ch][0], &
s->frame_out[ch][
s->frame_len],
812 s->frame_len *
sizeof(*
s->frame_out[ch]));
815 dump_floats(
s,
"samples", 6,
samples[ch] + samples_offset,
824 int *got_frame_ptr,
AVPacket *avpkt)
826 const uint8_t *buf = avpkt->
data;
827 int buf_size = avpkt->
size;
834 ff_tlog(avctx,
"***decode_superframe:\n");
840 frame->nb_samples =
s->frame_len;
844 for (
i = 0;
i <
s->avctx->ch_layout.nb_channels;
i++)
845 memcpy(
frame->extended_data[
i], &
s->frame_out[
i][0],
846 frame->nb_samples *
sizeof(
s->frame_out[
i][0]));
848 s->last_superframe_len = 0;
853 if (buf_size < avctx->block_align) {
855 "Input packet size too small (%d < %d)\n",
864 if (
s->use_bit_reservoir) {
867 nb_frames =
get_bits(&
s->gb, 4) - (
s->last_superframe_len <= 0);
868 if (nb_frames <= 0) {
871 "nb_frames is %d bits left %d\n",
876 if ((
s->last_superframe_len + buf_size - 1) >
880 q =
s->last_superframe +
s->last_superframe_len;
888 s->last_superframe_len += 8*buf_size - 8;
897 frame->nb_samples = nb_frames *
s->frame_len;
903 if (
s->use_bit_reservoir) {
904 bit_offset =
get_bits(&
s->gb,
s->byte_offset_bits + 3);
907 "Invalid last frame bit offset %d > buf size %d (%d)\n",
912 if (
s->last_superframe_len > 0) {
914 if ((
s->last_superframe_len + ((bit_offset + 7) >> 3)) >
917 q =
s->last_superframe +
s->last_superframe_len;
929 s->last_superframe_len * 8 + bit_offset);
931 if (
s->last_bitoffset > 0)
937 samples_offset +=
s->frame_len;
942 pos = bit_offset + 4 + 4 +
s->byte_offset_bits + 3;
950 s->reset_block_lengths = 1;
951 for (
i = 0;
i < nb_frames;
i++) {
954 samples_offset +=
s->frame_len;
959 ((bit_offset + 4 + 4 +
s->byte_offset_bits + 3) & ~7);
960 s->last_bitoffset =
pos & 7;
967 s->last_superframe_len =
len;
968 memcpy(
s->last_superframe, buf +
pos,
len);
973 samples_offset +=
s->frame_len;
976 ff_dlog(
s->avctx,
"%d %d %d %d eaten:%d\n",
977 s->frame_len_bits,
s->block_len_bits,
s->frame_len,
s->block_len,
986 s->last_superframe_len = 0;
995 s->last_superframe_len = 0;
1001 #if CONFIG_WMAV1_DECODER
1018 #if CONFIG_WMAV2_DECODER