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++)
112 if (
s->use_noise_coding) {
149 t.v = ((
u.v <<
LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
150 a =
s->lsp_pow_m_table1[m];
151 b =
s->lsp_pow_m_table2[m];
152 return s->lsp_pow_e_table[e] * (
a +
b * t.f);
160 wdel =
M_PI / frame_len;
161 for (
i = 0;
i < frame_len;
i++)
162 s->lsp_cos_table[
i] = 2.0f * cos(wdel *
i);
165 for (
i = 0;
i < 256;
i++) {
167 s->lsp_pow_e_table[
i] =
exp2f(e * -0.25);
177 s->lsp_pow_m_table1[
i] = 2 *
a -
b;
178 s->lsp_pow_m_table2[
i] =
b -
a;
191 float p, q,
w, v, val_max;
194 for (
i = 0;
i < n;
i++) {
197 w =
s->lsp_cos_table[
i];
210 *val_max_ptr = val_max;
222 if (
i == 0 ||
i >= 8)
230 s->block_len, lsp_coefs);
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,
320 int last_exp, n,
code;
323 uint32_t *q, *q_end, iv;
324 const float *ptab =
pow_tab + 60;
325 const uint32_t *iptab = (
const uint32_t *) ptab;
327 ptr =
s->exponent_bands[
s->frame_len_bits -
s->block_len_bits];
328 q = (uint32_t *)
s->exponents[ch];
329 q_end = q +
s->block_len;
331 if (
s->version == 1) {
334 iv = iptab[last_exp];
342 }
while ((n -= 4) > 0);
349 last_exp +=
code - 60;
356 iv = iptab[last_exp];
365 }
while ((n -= 4) > 0);
367 s->max_exponent[ch] = max_scale;
379 float *
in =
s->output;
380 int block_len, bsize, n;
383 if (
s->block_len_bits <=
s->prev_block_len_bits) {
384 block_len =
s->block_len;
385 bsize =
s->frame_len_bits -
s->block_len_bits;
387 s->fdsp->vector_fmul_add(
out,
in,
s->windows[bsize],
390 block_len = 1 <<
s->prev_block_len_bits;
391 n = (
s->block_len - block_len) / 2;
392 bsize =
s->frame_len_bits -
s->prev_block_len_bits;
394 s->fdsp->vector_fmul_add(
out + n,
in + n,
s->windows[bsize],
397 memcpy(
out + n + block_len,
in + n + block_len, n *
sizeof(
float));
404 if (
s->block_len_bits <=
s->next_block_len_bits) {
405 block_len =
s->block_len;
406 bsize =
s->frame_len_bits -
s->block_len_bits;
408 s->fdsp->vector_fmul_reverse(
out,
in,
s->windows[bsize], block_len);
410 block_len = 1 <<
s->next_block_len_bits;
411 n = (
s->block_len - block_len) / 2;
412 bsize =
s->frame_len_bits -
s->next_block_len_bits;
414 memcpy(
out,
in, n *
sizeof(
float));
416 s->fdsp->vector_fmul_reverse(
out + n,
in + n,
s->windows[bsize],
419 memset(
out + n + block_len, 0, n *
sizeof(
float));
429 int n, v,
a, ch, bsize;
430 int coef_nb_bits, total_gain;
436 ff_tlog(
s->avctx,
"***decode_block: %d:%d\n",
437 s->frame_count - 1,
s->block_num);
441 if (
s->use_variable_block_len) {
442 n =
av_log2(
s->nb_block_sizes - 1) + 1;
444 if (
s->reset_block_lengths) {
445 s->reset_block_lengths = 0;
447 if (v >=
s->nb_block_sizes) {
449 "prev_block_len_bits %d out of range\n",
450 s->frame_len_bits - v);
453 s->prev_block_len_bits =
s->frame_len_bits - v;
455 if (v >=
s->nb_block_sizes) {
457 "block_len_bits %d out of range\n",
458 s->frame_len_bits - v);
461 s->block_len_bits =
s->frame_len_bits - v;
464 s->prev_block_len_bits =
s->block_len_bits;
465 s->block_len_bits =
s->next_block_len_bits;
468 if (v >=
s->nb_block_sizes) {
470 "next_block_len_bits %d out of range\n",
471 s->frame_len_bits - v);
474 s->next_block_len_bits =
s->frame_len_bits - v;
477 s->next_block_len_bits =
s->frame_len_bits;
478 s->prev_block_len_bits =
s->frame_len_bits;
479 s->block_len_bits =
s->frame_len_bits;
482 if (
s->frame_len_bits -
s->block_len_bits >=
s->nb_block_sizes){
488 s->block_len = 1 <<
s->block_len_bits;
489 if ((
s->block_pos +
s->block_len) >
s->frame_len) {
494 if (
s->avctx->channels == 2)
497 for (ch = 0; ch <
s->avctx->channels; ch++) {
499 s->channel_coded[ch] =
a;
503 bsize =
s->frame_len_bits -
s->block_len_bits;
527 n =
s->coefs_end[bsize] -
s->coefs_start;
528 for (ch = 0; ch <
s->avctx->channels; ch++)
532 if (
s->use_noise_coding) {
533 for (ch = 0; ch <
s->avctx->channels; ch++) {
534 if (
s->channel_coded[ch]) {
536 n =
s->exponent_high_sizes[bsize];
537 for (
i = 0;
i < n;
i++) {
539 s->high_band_coded[ch][
i] =
a;
542 nb_coefs[ch] -=
s->exponent_high_bands[bsize][
i];
546 for (ch = 0; ch <
s->avctx->channels; ch++) {
547 if (
s->channel_coded[ch]) {
550 n =
s->exponent_high_sizes[bsize];
552 for (
i = 0;
i < n;
i++) {
553 if (
s->high_band_coded[ch][
i]) {
554 if (
val == (
int) 0x80000000) {
560 s->high_band_values[ch][
i] =
val;
568 if ((
s->block_len_bits ==
s->frame_len_bits) ||
get_bits1(&
s->gb)) {
569 for (ch = 0; ch <
s->avctx->channels; ch++) {
570 if (
s->channel_coded[ch]) {
571 if (
s->use_exp_vlc) {
577 s->exponents_bsize[ch] = bsize;
578 s->exponents_initialized[ch] = 1;
583 for (ch = 0; ch <
s->avctx->channels; ch++) {
584 if (
s->channel_coded[ch] && !
s->exponents_initialized[ch])
589 for (ch = 0; ch <
s->avctx->channels; ch++) {
590 if (
s->channel_coded[ch]) {
597 tindex = (ch == 1 &&
s->ms_stereo);
598 memset(ptr, 0,
s->block_len *
sizeof(
WMACoef));
600 s->level_table[tindex],
s->run_table[tindex],
601 0, ptr, 0, nb_coefs[ch],
602 s->block_len,
s->frame_len_bits, coef_nb_bits);
606 if (
s->version == 1 &&
s->avctx->channels >= 2)
612 int n4 =
s->block_len / 2;
613 mdct_norm = 1.0 / (float) n4;
615 mdct_norm *= sqrt(n4);
619 for (ch = 0; ch <
s->avctx->channels; ch++) {
620 if (
s->channel_coded[ch]) {
622 float *coefs, *exponents,
mult, mult1,
noise;
623 int i, j, n, n1, last_high_band, esize;
626 coefs1 =
s->coefs1[ch];
627 exponents =
s->exponents[ch];
628 esize =
s->exponents_bsize[ch];
631 coefs =
s->coefs[ch];
632 if (
s->use_noise_coding) {
635 for (
i = 0;
i <
s->coefs_start;
i++) {
636 *coefs++ =
s->noise_table[
s->noise_index] *
637 exponents[i << bsize >> esize] * mult1;
638 s->noise_index = (
s->noise_index + 1) &
642 n1 =
s->exponent_high_sizes[bsize];
645 exponents =
s->exponents[ch] +
646 (
s->high_band_start[bsize] << bsize >> esize);
648 for (j = 0; j < n1; j++) {
649 n =
s->exponent_high_bands[
s->frame_len_bits -
650 s->block_len_bits][j];
651 if (
s->high_band_coded[ch][j]) {
654 for (
i = 0;
i < n;
i++) {
655 v = exponents[i << bsize >> esize];
658 exp_power[j] = e2 / n;
660 ff_tlog(
s->avctx,
"%d: power=%f (%d)\n", j, exp_power[j], n);
662 exponents += n << bsize >> esize;
666 exponents =
s->exponents[ch] + (
s->coefs_start << bsize >> esize);
667 for (j = -1; j < n1; j++) {
669 n =
s->high_band_start[bsize] -
s->coefs_start;
671 n =
s->exponent_high_bands[
s->frame_len_bits -
672 s->block_len_bits][j];
673 if (j >= 0 &&
s->high_band_coded[ch][j]) {
675 mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
677 mult1 = mult1 *
ff_exp10(
s->high_band_values[ch][j] * 0.05);
678 mult1 = mult1 / (
s->max_exponent[ch] *
s->noise_mult);
680 for (
i = 0;
i < n;
i++) {
681 noise =
s->noise_table[
s->noise_index];
683 *coefs++ =
noise * exponents[i << bsize >> esize] * mult1;
685 exponents += n << bsize >> esize;
688 for (
i = 0;
i < n;
i++) {
689 noise =
s->noise_table[
s->noise_index];
691 *coefs++ = ((*coefs1++) +
noise) *
692 exponents[i << bsize >> esize] *
mult;
694 exponents += n << bsize >> esize;
699 n =
s->block_len -
s->coefs_end[bsize];
700 mult1 =
mult * exponents[(-(1 << bsize)) >> esize];
701 for (
i = 0;
i < n;
i++) {
702 *coefs++ =
s->noise_table[
s->noise_index] * mult1;
707 for (
i = 0;
i <
s->coefs_start;
i++)
710 for (
i = 0;
i < n;
i++)
711 *coefs++ = coefs1[
i] * exponents[
i << bsize >> esize] *
mult;
712 n =
s->block_len -
s->coefs_end[bsize];
713 for (
i = 0;
i < n;
i++)
720 for (ch = 0; ch <
s->avctx->channels; ch++) {
721 if (
s->channel_coded[ch]) {
722 dump_floats(
s,
"exponents", 3,
s->exponents[ch],
s->block_len);
723 dump_floats(
s,
"coefs", 1,
s->coefs[ch],
s->block_len);
728 if (
s->ms_stereo &&
s->channel_coded[1]) {
732 if (!
s->channel_coded[0]) {
733 ff_tlog(
s->avctx,
"rare ms-stereo case happened\n");
734 memset(
s->coefs[0], 0,
sizeof(
float) *
s->block_len);
735 s->channel_coded[0] = 1;
738 s->fdsp->butterflies_float(
s->coefs[0],
s->coefs[1],
s->block_len);
742 mdct = &
s->mdct_ctx[bsize];
744 for (ch = 0; ch <
s->avctx->channels; ch++) {
747 n4 =
s->block_len / 2;
748 if (
s->channel_coded[ch])
750 else if (!(
s->ms_stereo && ch == 1))
751 memset(
s->output, 0,
sizeof(
s->output));
754 index = (
s->frame_len / 2) +
s->block_pos - n4;
760 s->block_pos +=
s->block_len;
761 if (
s->block_pos >=
s->frame_len)
774 ff_tlog(
s->avctx,
"***decode_frame: %d size=%d\n",
775 s->frame_count++,
s->frame_len);
789 for (ch = 0; ch <
s->avctx->channels; ch++) {
791 memcpy(
samples[ch] + samples_offset,
s->frame_out[ch],
792 s->frame_len *
sizeof(*
s->frame_out[ch]));
794 memmove(&
s->frame_out[ch][0], &
s->frame_out[ch][
s->frame_len],
795 s->frame_len *
sizeof(*
s->frame_out[ch]));
798 dump_floats(
s,
"samples", 6,
samples[ch] + samples_offset,
807 int *got_frame_ptr,
AVPacket *avpkt)
811 int buf_size = avpkt->
size;
818 ff_tlog(avctx,
"***decode_superframe:\n");
821 s->last_superframe_len = 0;
824 if (buf_size < avctx->block_align) {
826 "Input packet size too small (%d < %d)\n",
835 if (
s->use_bit_reservoir) {
838 nb_frames =
get_bits(&
s->gb, 4) - (
s->last_superframe_len <= 0);
839 if (nb_frames <= 0) {
842 "nb_frames is %d bits left %d\n",
847 if ((
s->last_superframe_len + buf_size - 1) >
851 q =
s->last_superframe +
s->last_superframe_len;
859 s->last_superframe_len += 8*buf_size - 8;
868 frame->nb_samples = nb_frames *
s->frame_len;
874 if (
s->use_bit_reservoir) {
875 bit_offset =
get_bits(&
s->gb,
s->byte_offset_bits + 3);
878 "Invalid last frame bit offset %d > buf size %d (%d)\n",
883 if (
s->last_superframe_len > 0) {
885 if ((
s->last_superframe_len + ((bit_offset + 7) >> 3)) >
888 q =
s->last_superframe +
s->last_superframe_len;
900 s->last_superframe_len * 8 + bit_offset);
902 if (
s->last_bitoffset > 0)
908 samples_offset +=
s->frame_len;
913 pos = bit_offset + 4 + 4 +
s->byte_offset_bits + 3;
921 s->reset_block_lengths = 1;
922 for (
i = 0;
i < nb_frames;
i++) {
925 samples_offset +=
s->frame_len;
930 ((bit_offset + 4 + 4 +
s->byte_offset_bits + 3) & ~7);
931 s->last_bitoffset =
pos & 7;
938 s->last_superframe_len =
len;
939 memcpy(
s->last_superframe, buf +
pos,
len);
944 samples_offset +=
s->frame_len;
948 s->frame_len_bits,
s->block_len_bits,
s->frame_len,
s->block_len,
957 s->last_superframe_len = 0;
966 s->last_superframe_len = 0;
969 #if CONFIG_WMAV1_DECODER
986 #if CONFIG_WMAV2_DECODER