44 #define EXPMAX ((19 + EXPVLCBITS - 1) / EXPVLCBITS)
46 #define HGAINVLCBITS 9
47 #define HGAINMAX ((13 + HGAINVLCBITS - 1) / HGAINVLCBITS)
53 int prec,
const float *
tab,
int n)
58 for (
i = 0;
i < n;
i++) {
87 flags2 =
AV_RL16(extradata + 2);
89 flags2 =
AV_RL16(extradata + 4);
91 s->use_exp_vlc = flags2 & 0x0001;
92 s->use_bit_reservoir = flags2 & 0x0002;
93 s->use_variable_block_len = flags2 & 0x0004;
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;
103 s->max_exponent[
i] = 1.0;
109 for (
i = 0;
i <
s->nb_block_sizes;
i++) {
116 if (
s->use_noise_coding) {
126 if (
s->use_exp_vlc) {
162 t.v = ((
u.v <<
LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
163 a =
s->lsp_pow_m_table1[m];
164 b =
s->lsp_pow_m_table2[m];
165 return s->lsp_pow_e_table[e] * (
a +
b * t.f);
173 wdel =
M_PI / frame_len;
174 for (
i = 0;
i < frame_len;
i++)
175 s->lsp_cos_table[
i] = 2.0f * cos(wdel *
i);
178 for (
i = 0;
i < 256;
i++) {
180 s->lsp_pow_e_table[
i] =
exp2f(e * -0.25);
190 s->lsp_pow_m_table1[
i] = 2 *
a -
b;
191 s->lsp_pow_m_table2[
i] =
b -
a;
204 float p, q,
w, v, val_max;
207 for (
i = 0;
i < n;
i++) {
210 w =
s->lsp_cos_table[
i];
223 *val_max_ptr = val_max;
235 if (
i == 0 ||
i >= 8)
243 s->block_len, lsp_coefs);
248 1.7782794100389e-04, 2.0535250264571e-04,
249 2.3713737056617e-04, 2.7384196342644e-04,
250 3.1622776601684e-04, 3.6517412725484e-04,
251 4.2169650342858e-04, 4.8696752516586e-04,
252 5.6234132519035e-04, 6.4938163157621e-04,
253 7.4989420933246e-04, 8.6596432336006e-04,
254 1.0000000000000e-03, 1.1547819846895e-03,
255 1.3335214321633e-03, 1.5399265260595e-03,
256 1.7782794100389e-03, 2.0535250264571e-03,
257 2.3713737056617e-03, 2.7384196342644e-03,
258 3.1622776601684e-03, 3.6517412725484e-03,
259 4.2169650342858e-03, 4.8696752516586e-03,
260 5.6234132519035e-03, 6.4938163157621e-03,
261 7.4989420933246e-03, 8.6596432336006e-03,
262 1.0000000000000e-02, 1.1547819846895e-02,
263 1.3335214321633e-02, 1.5399265260595e-02,
264 1.7782794100389e-02, 2.0535250264571e-02,
265 2.3713737056617e-02, 2.7384196342644e-02,
266 3.1622776601684e-02, 3.6517412725484e-02,
267 4.2169650342858e-02, 4.8696752516586e-02,
268 5.6234132519035e-02, 6.4938163157621e-02,
269 7.4989420933246e-02, 8.6596432336007e-02,
270 1.0000000000000e-01, 1.1547819846895e-01,
271 1.3335214321633e-01, 1.5399265260595e-01,
272 1.7782794100389e-01, 2.0535250264571e-01,
273 2.3713737056617e-01, 2.7384196342644e-01,
274 3.1622776601684e-01, 3.6517412725484e-01,
275 4.2169650342858e-01, 4.8696752516586e-01,
276 5.6234132519035e-01, 6.4938163157621e-01,
277 7.4989420933246e-01, 8.6596432336007e-01,
278 1.0000000000000e+00, 1.1547819846895e+00,
279 1.3335214321633e+00, 1.5399265260595e+00,
280 1.7782794100389e+00, 2.0535250264571e+00,
281 2.3713737056617e+00, 2.7384196342644e+00,
282 3.1622776601684e+00, 3.6517412725484e+00,
283 4.2169650342858e+00, 4.8696752516586e+00,
284 5.6234132519035e+00, 6.4938163157621e+00,
285 7.4989420933246e+00, 8.6596432336007e+00,
286 1.0000000000000e+01, 1.1547819846895e+01,
287 1.3335214321633e+01, 1.5399265260595e+01,
288 1.7782794100389e+01, 2.0535250264571e+01,
289 2.3713737056617e+01, 2.7384196342644e+01,
290 3.1622776601684e+01, 3.6517412725484e+01,
291 4.2169650342858e+01, 4.8696752516586e+01,
292 5.6234132519035e+01, 6.4938163157621e+01,
293 7.4989420933246e+01, 8.6596432336007e+01,
294 1.0000000000000e+02, 1.1547819846895e+02,
295 1.3335214321633e+02, 1.5399265260595e+02,
296 1.7782794100389e+02, 2.0535250264571e+02,
297 2.3713737056617e+02, 2.7384196342644e+02,
298 3.1622776601684e+02, 3.6517412725484e+02,
299 4.2169650342858e+02, 4.8696752516586e+02,
300 5.6234132519035e+02, 6.4938163157621e+02,
301 7.4989420933246e+02, 8.6596432336007e+02,
302 1.0000000000000e+03, 1.1547819846895e+03,
303 1.3335214321633e+03, 1.5399265260595e+03,
304 1.7782794100389e+03, 2.0535250264571e+03,
305 2.3713737056617e+03, 2.7384196342644e+03,
306 3.1622776601684e+03, 3.6517412725484e+03,
307 4.2169650342858e+03, 4.8696752516586e+03,
308 5.6234132519035e+03, 6.4938163157621e+03,
309 7.4989420933246e+03, 8.6596432336007e+03,
310 1.0000000000000e+04, 1.1547819846895e+04,
311 1.3335214321633e+04, 1.5399265260595e+04,
312 1.7782794100389e+04, 2.0535250264571e+04,
313 2.3713737056617e+04, 2.7384196342644e+04,
314 3.1622776601684e+04, 3.6517412725484e+04,
315 4.2169650342858e+04, 4.8696752516586e+04,
316 5.6234132519035e+04, 6.4938163157621e+04,
317 7.4989420933246e+04, 8.6596432336007e+04,
318 1.0000000000000e+05, 1.1547819846895e+05,
319 1.3335214321633e+05, 1.5399265260595e+05,
320 1.7782794100389e+05, 2.0535250264571e+05,
321 2.3713737056617e+05, 2.7384196342644e+05,
322 3.1622776601684e+05, 3.6517412725484e+05,
323 4.2169650342858e+05, 4.8696752516586e+05,
324 5.6234132519035e+05, 6.4938163157621e+05,
325 7.4989420933246e+05, 8.6596432336007e+05,
333 int last_exp, n,
code;
336 uint32_t *q, *q_end, iv;
337 const float *ptab =
pow_tab + 60;
338 const uint32_t *iptab = (
const uint32_t *) ptab;
340 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
341 q = (uint32_t *)
s->exponents[ch];
342 q_end = q +
s->block_len;
344 if (
s->version == 1) {
347 iv = iptab[last_exp];
355 }
while ((n -= 4) > 0);
362 last_exp +=
code - 60;
369 iv = iptab[last_exp];
378 }
while ((n -= 4) > 0);
380 s->max_exponent[ch] = max_scale;
392 float *in =
s->output;
393 int block_len, bsize, n;
396 if (
s->block_len_bits <=
s->prev_block_len_bits) {
397 block_len =
s->block_len;
398 bsize =
s->frame_len_bits -
s->block_len_bits;
400 s->fdsp->vector_fmul_add(
out, in,
s->windows[bsize],
403 block_len = 1 <<
s->prev_block_len_bits;
404 n = (
s->block_len - block_len) / 2;
405 bsize =
s->frame_len_bits -
s->prev_block_len_bits;
407 s->fdsp->vector_fmul_add(
out + n, in + n,
s->windows[bsize],
410 memcpy(
out + n + block_len, in + n + block_len, n *
sizeof(
float));
417 if (
s->block_len_bits <=
s->next_block_len_bits) {
418 block_len =
s->block_len;
419 bsize =
s->frame_len_bits -
s->block_len_bits;
421 s->fdsp->vector_fmul_reverse(
out, in,
s->windows[bsize], block_len);
423 block_len = 1 <<
s->next_block_len_bits;
424 n = (
s->block_len - block_len) / 2;
425 bsize =
s->frame_len_bits -
s->next_block_len_bits;
427 memcpy(
out, in, n *
sizeof(
float));
429 s->fdsp->vector_fmul_reverse(
out + n, in + n,
s->windows[bsize],
432 memset(
out + n + block_len, 0, n *
sizeof(
float));
442 int n, v,
a, ch, bsize;
443 int coef_nb_bits, total_gain;
449 ff_tlog(
s->avctx,
"***decode_block: %d:%d\n",
450 s->frame_count - 1,
s->block_num);
454 if (
s->use_variable_block_len) {
455 n =
av_log2(
s->nb_block_sizes - 1) + 1;
457 if (
s->reset_block_lengths) {
458 s->reset_block_lengths = 0;
460 if (v >=
s->nb_block_sizes) {
462 "prev_block_len_bits %d out of range\n",
463 s->frame_len_bits - v);
466 s->prev_block_len_bits =
s->frame_len_bits - v;
468 if (v >=
s->nb_block_sizes) {
470 "block_len_bits %d out of range\n",
471 s->frame_len_bits - v);
474 s->block_len_bits =
s->frame_len_bits - v;
477 s->prev_block_len_bits =
s->block_len_bits;
478 s->block_len_bits =
s->next_block_len_bits;
481 if (v >=
s->nb_block_sizes) {
483 "next_block_len_bits %d out of range\n",
484 s->frame_len_bits - v);
487 s->next_block_len_bits =
s->frame_len_bits - v;
490 s->next_block_len_bits =
s->frame_len_bits;
491 s->prev_block_len_bits =
s->frame_len_bits;
492 s->block_len_bits =
s->frame_len_bits;
495 if (
s->frame_len_bits -
s->block_len_bits >=
s->nb_block_sizes){
501 s->block_len = 1 <<
s->block_len_bits;
502 if ((
s->block_pos +
s->block_len) >
s->frame_len) {
507 if (
s->avctx->channels == 2)
510 for (ch = 0; ch <
s->avctx->channels; ch++) {
512 s->channel_coded[ch] =
a;
516 bsize =
s->frame_len_bits -
s->block_len_bits;
540 n =
s->coefs_end[bsize] -
s->coefs_start;
541 for (ch = 0; ch <
s->avctx->channels; ch++)
545 if (
s->use_noise_coding) {
546 for (ch = 0; ch <
s->avctx->channels; ch++) {
547 if (
s->channel_coded[ch]) {
549 n =
s->exponent_high_sizes[bsize];
550 for (
i = 0;
i < n;
i++) {
552 s->high_band_coded[ch][
i] =
a;
555 nb_coefs[ch] -=
s->exponent_high_bands[bsize][
i];
559 for (ch = 0; ch <
s->avctx->channels; ch++) {
560 if (
s->channel_coded[ch]) {
563 n =
s->exponent_high_sizes[bsize];
565 for (
i = 0;
i < n;
i++) {
566 if (
s->high_band_coded[ch][
i]) {
567 if (
val == (
int) 0x80000000) {
573 s->high_band_values[ch][
i] =
val;
581 if ((
s->block_len_bits ==
s->frame_len_bits) ||
get_bits1(&
s->gb)) {
582 for (ch = 0; ch <
s->avctx->channels; ch++) {
583 if (
s->channel_coded[ch]) {
584 if (
s->use_exp_vlc) {
590 s->exponents_bsize[ch] = bsize;
591 s->exponents_initialized[ch] = 1;
596 for (ch = 0; ch <
s->avctx->channels; ch++) {
597 if (
s->channel_coded[ch] && !
s->exponents_initialized[ch])
602 for (ch = 0; ch <
s->avctx->channels; ch++) {
603 if (
s->channel_coded[ch]) {
610 tindex = (ch == 1 &&
s->ms_stereo);
611 memset(ptr, 0,
s->block_len *
sizeof(
WMACoef));
613 s->level_table[tindex],
s->run_table[tindex],
615 s->block_len,
s->frame_len_bits, coef_nb_bits);
619 if (
s->version == 1 &&
s->avctx->channels >= 2)
625 int n4 =
s->block_len / 2;
626 mdct_norm = 1.0 / (float) n4;
628 mdct_norm *= sqrt(n4);
632 for (ch = 0; ch <
s->avctx->channels; ch++) {
633 if (
s->channel_coded[ch]) {
635 float *coefs, *exponents,
mult, mult1,
noise;
636 int i, j, n, n1, last_high_band, esize;
639 coefs1 =
s->coefs1[ch];
640 exponents =
s->exponents[ch];
641 esize =
s->exponents_bsize[ch];
644 coefs =
s->coefs[ch];
645 if (
s->use_noise_coding) {
648 for (
i = 0;
i <
s->coefs_start;
i++) {
649 *coefs++ =
s->noise_table[
s->noise_index] *
650 exponents[i << bsize >> esize] * mult1;
651 s->noise_index = (
s->noise_index + 1) &
655 n1 =
s->exponent_high_sizes[bsize];
658 exponents =
s->exponents[ch] +
659 (
s->high_band_start[bsize] << bsize >> esize);
661 for (j = 0; j < n1; j++) {
662 n =
s->exponent_high_bands[
s->frame_len_bits -
663 s->block_len_bits][j];
664 if (
s->high_band_coded[ch][j]) {
667 for (
i = 0;
i < n;
i++) {
668 v = exponents[i << bsize >> esize];
671 exp_power[j] = e2 / n;
673 ff_tlog(
s->avctx,
"%d: power=%f (%d)\n", j, exp_power[j], n);
675 exponents += n << bsize >> esize;
679 exponents =
s->exponents[ch] + (
s->coefs_start << bsize >> esize);
680 for (j = -1; j < n1; j++) {
682 n =
s->high_band_start[bsize] -
s->coefs_start;
684 n =
s->exponent_high_bands[
s->frame_len_bits -
685 s->block_len_bits][j];
686 if (j >= 0 &&
s->high_band_coded[ch][j]) {
688 mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
690 mult1 = mult1 *
ff_exp10(
s->high_band_values[ch][j] * 0.05);
691 mult1 = mult1 / (
s->max_exponent[ch] *
s->noise_mult);
693 for (
i = 0;
i < n;
i++) {
694 noise =
s->noise_table[
s->noise_index];
696 *coefs++ =
noise * exponents[i << bsize >> esize] * mult1;
698 exponents += n << bsize >> esize;
701 for (
i = 0;
i < n;
i++) {
702 noise =
s->noise_table[
s->noise_index];
704 *coefs++ = ((*coefs1++) +
noise) *
705 exponents[i << bsize >> esize] *
mult;
707 exponents += n << bsize >> esize;
712 n =
s->block_len -
s->coefs_end[bsize];
713 mult1 =
mult * exponents[(-(1 << bsize)) >> esize];
714 for (
i = 0;
i < n;
i++) {
715 *coefs++ =
s->noise_table[
s->noise_index] * mult1;
720 for (
i = 0;
i <
s->coefs_start;
i++)
723 for (
i = 0;
i < n;
i++)
724 *coefs++ = coefs1[
i] * exponents[
i << bsize >> esize] *
mult;
725 n =
s->block_len -
s->coefs_end[bsize];
726 for (
i = 0;
i < n;
i++)
733 for (ch = 0; ch <
s->avctx->channels; ch++) {
734 if (
s->channel_coded[ch]) {
735 dump_floats(
s,
"exponents", 3,
s->exponents[ch],
s->block_len);
736 dump_floats(
s,
"coefs", 1,
s->coefs[ch],
s->block_len);
741 if (
s->ms_stereo &&
s->channel_coded[1]) {
745 if (!
s->channel_coded[0]) {
746 ff_tlog(
s->avctx,
"rare ms-stereo case happened\n");
747 memset(
s->coefs[0], 0,
sizeof(
float) *
s->block_len);
748 s->channel_coded[0] = 1;
751 s->fdsp->butterflies_float(
s->coefs[0],
s->coefs[1],
s->block_len);
755 mdct = &
s->mdct_ctx[bsize];
757 for (ch = 0; ch <
s->avctx->channels; ch++) {
760 n4 =
s->block_len / 2;
761 if (
s->channel_coded[ch])
763 else if (!(
s->ms_stereo && ch == 1))
764 memset(
s->output, 0,
sizeof(
s->output));
767 index = (
s->frame_len / 2) +
s->block_pos - n4;
773 s->block_pos +=
s->block_len;
774 if (
s->block_pos >=
s->frame_len)
787 ff_tlog(
s->avctx,
"***decode_frame: %d size=%d\n",
788 s->frame_count++,
s->frame_len);
802 for (ch = 0; ch <
s->avctx->channels; ch++) {
804 memcpy(
samples[ch] + samples_offset,
s->frame_out[ch],
805 s->frame_len *
sizeof(*
s->frame_out[ch]));
807 memmove(&
s->frame_out[ch][0], &
s->frame_out[ch][
s->frame_len],
808 s->frame_len *
sizeof(*
s->frame_out[ch]));
811 dump_floats(
s,
"samples", 6,
samples[ch] + samples_offset,
820 int *got_frame_ptr,
AVPacket *avpkt)
823 const uint8_t *buf = avpkt->
data;
824 int buf_size = avpkt->
size;
831 ff_tlog(avctx,
"***decode_superframe:\n");
837 frame->nb_samples =
s->frame_len;
841 for (
i = 0;
i <
s->avctx->channels;
i++)
842 memcpy(
frame->extended_data[
i], &
s->frame_out[
i][0],
843 frame->nb_samples *
sizeof(
s->frame_out[
i][0]));
845 s->last_superframe_len = 0;
850 if (buf_size < avctx->block_align) {
852 "Input packet size too small (%d < %d)\n",
861 if (
s->use_bit_reservoir) {
864 nb_frames =
get_bits(&
s->gb, 4) - (
s->last_superframe_len <= 0);
865 if (nb_frames <= 0) {
868 "nb_frames is %d bits left %d\n",
873 if ((
s->last_superframe_len + buf_size - 1) >
877 q =
s->last_superframe +
s->last_superframe_len;
885 s->last_superframe_len += 8*buf_size - 8;
894 frame->nb_samples = nb_frames *
s->frame_len;
900 if (
s->use_bit_reservoir) {
901 bit_offset =
get_bits(&
s->gb,
s->byte_offset_bits + 3);
904 "Invalid last frame bit offset %d > buf size %d (%d)\n",
909 if (
s->last_superframe_len > 0) {
911 if ((
s->last_superframe_len + ((bit_offset + 7) >> 3)) >
914 q =
s->last_superframe +
s->last_superframe_len;
926 s->last_superframe_len * 8 + bit_offset);
928 if (
s->last_bitoffset > 0)
934 samples_offset +=
s->frame_len;
939 pos = bit_offset + 4 + 4 +
s->byte_offset_bits + 3;
947 s->reset_block_lengths = 1;
948 for (
i = 0;
i < nb_frames;
i++) {
951 samples_offset +=
s->frame_len;
956 ((bit_offset + 4 + 4 +
s->byte_offset_bits + 3) & ~7);
957 s->last_bitoffset =
pos & 7;
964 s->last_superframe_len =
len;
965 memcpy(
s->last_superframe, buf +
pos,
len);
970 samples_offset +=
s->frame_len;
974 s->frame_len_bits,
s->block_len_bits,
s->frame_len,
s->block_len,
983 s->last_superframe_len = 0;
992 s->last_superframe_len = 0;
998 #if CONFIG_WMAV1_DECODER
1015 #if CONFIG_WMAV2_DECODER