Go to the documentation of this file.
22 #define BITSTREAM_WRITER_LE
36 #define UPDATE_WEIGHT(weight, delta, source, result) \
37 if ((source) && (result)) { \
38 int32_t s = (int32_t) ((source) ^ (result)) >> 31; \
39 weight = ((delta) ^ s) + ((weight) - s); \
42 #define APPLY_WEIGHT_F(weight, sample) ((((((sample) & 0xffff) * (weight)) >> 9) + \
43 ((((sample) & ~0xffff) >> 9) * (weight)) + 1) >> 1)
45 #define APPLY_WEIGHT_I(weight, sample) (((weight) * (sample) + 512) >> 10)
47 #define APPLY_WEIGHT(weight, sample) ((sample) != (short) (sample) ? \
48 APPLY_WEIGHT_F(weight, sample) : APPLY_WEIGHT_I (weight, sample))
50 #define CLEAR(destin) memset(&destin, 0, sizeof(destin));
53 #define SHIFT_MASK (0x1FU << SHIFT_LSB)
56 #define MAG_MASK (0x1FU << MAG_LSB)
59 #define SRATE_MASK (0xFU << SRATE_LSB)
61 #define EXTRA_TRY_DELTAS 1
62 #define EXTRA_ADJUST_DELTAS 2
63 #define EXTRA_SORT_FIRST 4
64 #define EXTRA_BRANCHES 8
65 #define EXTRA_SORT_LAST 16
161 s->decorr_filter = 3;
180 s->decorr_filter = 2;
183 s->decorr_filter = 1;
186 s->decorr_filter = 0;
194 s->delta_decay = 2.0;
202 for (
i = 0;
i < nb_samples;
i++)
207 int nb_samples,
int shift)
210 for (
i = 0;
i < nb_samples;
i++) {
216 #define FLOAT_SHIFT_ONES 1
217 #define FLOAT_SHIFT_SAME 2
218 #define FLOAT_SHIFT_SENT 4
219 #define FLOAT_ZEROS_SENT 8
220 #define FLOAT_NEG_ZEROS 0x10
221 #define FLOAT_EXCEPTIONS 0x20
223 #define get_mantissa(f) ((f) & 0x7fffff)
224 #define get_exponent(f) (((f) >> 23) & 0xff)
225 #define get_sign(f) (((f) >> 31) & 0x1)
239 shift_count =
s->max_exp ?
s->max_exp - 1 : 0;
243 if (shift_count < 25)
244 value >>= shift_count;
253 }
else if (shift_count) {
272 uint32_t crc = 0xffffffff
u;
275 s->shifted_ones =
s->shifted_zeros =
s->shifted_both =
s->ordata = 0;
276 s->float_shift =
s->float_flags = 0;
277 s->false_zeros =
s->neg_zeros = 0;
281 for (
i = 0;
i < nb_samples;
i++) {
289 for (
i = 0;
i < nb_samples;
i++) {
308 for (
i = 0;
i < nb_samples;
i++)
311 for (
i = 0;
i < nb_samples;
i++) {
317 s->float_max_exp =
s->max_exp;
321 else if (
s->shifted_ones && !
s->shifted_zeros)
323 else if (
s->shifted_ones &&
s->shifted_zeros)
325 else if (
s->ordata && !(
s->ordata & 1)) {
329 }
while (!(
s->ordata & 1));
334 shift_stereo(samples_l, samples_r, nb_samples,
s->float_shift);
344 if (
s->false_zeros ||
s->neg_zeros)
358 uint32_t magdata = 0, ordata = 0, xordata = 0, anddata = ~0;
359 int i, total_shift = 0;
361 s->int32_sent_bits =
s->int32_zeros =
s->int32_ones =
s->int32_dups = 0;
364 for (
i = 0;
i < nb_samples;
i++) {
367 magdata |= (
M < 0) ? ~
M :
M;
368 xordata |=
M ^ -(
M & 1);
372 if ((ordata & 1) && !(anddata & 1) && (xordata & 2))
376 for (
i = 0;
i < nb_samples;
i++) {
380 magdata |= (
L < 0) ? ~
L :
L;
381 magdata |= (
R < 0) ? ~
R :
R;
382 xordata |=
L ^ -(
L & 1);
383 xordata |=
R ^ -(
R & 1);
387 if ((ordata & 1) && !(anddata & 1) && (xordata & 2))
408 }
while (!(ordata & 1));
409 }
else if (anddata & 1) {
415 }
while (anddata & 1);
416 }
else if (!(xordata & 2)) {
422 }
while (!(xordata & 2));
429 shift_mono(samples_l, nb_samples, total_shift);
431 shift_stereo(samples_l, samples_r, nb_samples, total_shift);
439 uint32_t magdata = 0, ordata = 0, xordata = 0, anddata = ~0;
440 uint32_t crc = 0xffffffff
u;
441 int i, total_shift = 0;
443 s->int32_sent_bits =
s->int32_zeros =
s->int32_ones =
s->int32_dups = 0;
446 for (
i = 0;
i < nb_samples;
i++) {
449 crc = crc * 9 + (
M & 0xffff) * 3 + ((
M >> 16) & 0xffff);
450 magdata |= (
M < 0) ? ~
M :
M;
451 xordata |=
M ^ -(
M & 1);
456 for (
i = 0;
i < nb_samples;
i++) {
460 crc = crc * 9 + (
L & 0xffff) * 3 + ((
L >> 16) & 0xffff);
461 crc = crc * 9 + (
R & 0xffff) * 3 + ((
R >> 16) & 0xffff);
462 magdata |= (
L < 0) ? ~
L :
L;
463 magdata |= (
R < 0) ? ~
R :
R;
464 xordata |=
L ^ -(
L & 1);
465 xordata |=
R ^ -(
R & 1);
490 }
while (!(ordata & 1));
491 else if (anddata & 1)
497 }
while (anddata & 1);
498 else if (!(xordata & 2))
504 }
while (!(xordata & 2));
508 total_shift +=
s->int32_sent_bits;
517 shift_mono(samples_l, nb_samples, total_shift);
519 shift_stereo(samples_l, samples_r, nb_samples, total_shift);
522 return s->int32_sent_bits;
550 int nb_samples,
struct Decorr *dpp,
int dir)
557 out_samples += (nb_samples - 1);
558 in_samples += (nb_samples - 1);
567 while (nb_samples--) {
578 out_samples[0] =
left;
582 }
else if (dpp->
value > 0) {
583 while (nb_samples--) {
594 out_samples[0] =
left;
631 }
else if (dpp->
value > 1) {
634 for (
i = 0, j = dpp->
value - 1, k = 0; k < dpp->
value / 2;
i++, j--, k++) {
644 #define count_bits(av) ((av) ? 32 - ff_clz(av) : 0)
650 if ((v += v >> 9) < (1 << 8)) {
665 while (nb_samples--) {
673 int nb_samples,
int limit)
676 while (nb_samples--) {
685 int nb_samples,
struct Decorr *dpp,
688 struct Decorr dp, *dppi = dpp + tindex;
696 pre_delta =
delta + 1;
700 dp.
delta = pre_delta;
724 int depth,
int delta, uint32_t input_bits)
726 int term, branches =
s->num_branches - depth;
728 uint32_t term_bits[22],
bits;
730 if (branches < 1 || depth + 1 == info->nterms)
735 outsamples =
s->sampleptrs[depth + 1][0];
737 for (term = 1; term <= 18; term++) {
738 if (term == 17 && branches == 1 && depth + 1 <
info->nterms)
741 if (term > 8 && term < 17)
744 if (!
s->extra_flags && (term > 4 && term < 17))
747 info->dps[depth].value = term;
752 if (bits < info->best_bits) {
755 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) * (depth + 1));
756 memcpy(
s->sampleptrs[
info->nterms + 1][0],
757 s->sampleptrs[depth + 1][0],
s->block_samples * 4);
760 term_bits[term + 3] =
bits;
763 while (depth + 1 <
info->nterms && branches--) {
764 uint32_t local_best_bits = input_bits;
765 int best_term = 0,
i;
767 for (
i = 0;
i < 22;
i++)
768 if (term_bits[
i] && term_bits[
i] < local_best_bits) {
769 local_best_bits = term_bits[
i];
776 term_bits[best_term + 3] = 0;
778 info->dps[depth].value = best_term;
794 memcpy(
info->dps,
s->decorr_passes,
sizeof(
s->decorr_passes));
797 for (ri = 0; ri <
info->nterms &&
s->decorr_passes[ri].value; ri++) {
799 if (ri + 1 >=
info->nterms || !
s->decorr_passes[ri+1].value)
802 if (
s->decorr_passes[ri].value ==
s->decorr_passes[ri+1].value) {
804 s->block_samples,
info->dps, ri);
808 info->dps[ri ] =
s->decorr_passes[ri+1];
809 info->dps[ri+1] =
s->decorr_passes[ri ];
811 for (
i = ri;
i <
info->nterms &&
s->decorr_passes[
i].value;
i++)
813 s->block_samples,
info->dps,
i);
816 if (bits < info->best_bits) {
820 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) *
i);
821 memcpy(
s->sampleptrs[
info->nterms + 1][0],
s->sampleptrs[
i][0],
822 s->block_samples * 4);
824 info->dps[ri ] =
s->decorr_passes[ri];
825 info->dps[ri+1] =
s->decorr_passes[ri+1];
827 s->block_samples,
info->dps, ri);
835 int lower = 0,
delta, d;
838 if (!
s->decorr_passes[0].value)
840 delta =
s->decorr_passes[0].delta;
842 for (d =
delta - 1; d >= 0; d--) {
845 for (
i = 0;
i <
info->nterms &&
s->decorr_passes[
i].value;
i++) {
846 info->dps[
i].value =
s->decorr_passes[
i].value;
847 info->dps[
i].delta = d;
849 s->block_samples,
info->dps,
i);
859 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) *
i);
860 memcpy(
s->sampleptrs[
info->nterms + 1][0],
s->sampleptrs[
i][0],
861 s->block_samples * 4);
864 for (d =
delta + 1; !lower && d <= 7; d++) {
867 for (
i = 0;
i <
info->nterms &&
s->decorr_passes[
i].value;
i++) {
868 info->dps[
i].value =
s->decorr_passes[
i].value;
869 info->dps[
i].delta = d;
871 s->block_samples,
info->dps,
i);
880 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) *
i);
881 memcpy(
s->sampleptrs[
info->nterms + 1][0],
s->sampleptrs[
i][0],
882 s->block_samples * 4);
890 for (
i = 0;
i < nterms + 2;
i++) {
892 s->block_samples * 4);
893 if (!
s->sampleptrs[
i][0])
897 s->block_samples * 4);
898 if (!
s->sampleptrs[
i][1])
910 for (
i = 0;
i < 2;
i++) {
912 s->block_samples * 4);
913 if (!
s->best_buffer[0])
917 s->block_samples * 4);
918 if (!
s->temp_buffer[
i][0])
922 s->block_samples * 4);
923 if (!
s->best_buffer[1])
927 s->block_samples * 4);
928 if (!
s->temp_buffer[
i][1])
944 info.nterms =
s->num_terms;
949 memcpy(
info.dps,
s->decorr_passes,
sizeof(
info.dps));
950 memcpy(
s->sampleptrs[0][0],
samples,
s->block_samples * 4);
954 s->block_samples,
info.dps +
i, 1);
957 memcpy(
s->sampleptrs[
info.nterms + 1][0],
s->sampleptrs[
i][0],
s->block_samples * 4);
961 log2mono(
s->sampleptrs[0][0],
s->block_samples, 0));
970 s->delta_decay = (
float)((
s->delta_decay * 2.0 +
s->decorr_passes[0].delta) / 3.0);
972 s->delta_decay = 2.0;
979 memcpy(
samples,
s->sampleptrs[
info.nterms + 1][0],
s->block_samples * 4);
981 for (
i = 0;
i <
info.nterms;
i++)
982 if (!
s->decorr_passes[
i].value)
994 while (nb_samples--) {
1021 int no_history,
int do_samples)
1023 struct Decorr temp_decorr_pass, save_decorr_passes[
MAX_TERMS] = {{0}};
1024 int nb_samples =
s->block_samples;
1025 int buf_size =
sizeof(
int32_t) * nb_samples;
1026 uint32_t best_size = UINT32_MAX,
size;
1027 int log_limit, pi,
i,
ret;
1029 for (
i = 0;
i < nb_samples;
i++)
1033 if (
i == nb_samples) {
1041 log_limit =
FFMIN(6912, log_limit);
1046 if (no_history ||
s->num_passes >= 7)
1047 s->best_decorr =
s->mask_decorr = 0;
1049 for (pi = 0; pi <
s->num_passes;) {
1056 if (
s->mask_decorr == 0)
1059 c = (
s->best_decorr & (
s->mask_decorr - 1)) |
s->mask_decorr;
1061 if (
c ==
s->best_decorr) {
1062 s->mask_decorr =
s->mask_decorr ? ((
s->mask_decorr << 1) & (
s->num_decorrs - 1)) : 1;
1067 wpds = &
s->decorr_specs[
c];
1071 memcpy(
s->temp_buffer[0][0],
samples, buf_size);
1072 CLEAR(save_decorr_passes);
1074 for (j = 0; j < nterms; j++) {
1075 CLEAR(temp_decorr_pass);
1079 if (temp_decorr_pass.
value < 0)
1080 temp_decorr_pass.
value = 1;
1082 decorr_mono(
s->temp_buffer[j&1][0],
s->temp_buffer[~j&1][0],
1083 FFMIN(nb_samples, 2048), &temp_decorr_pass, -1);
1091 memcpy(save_decorr_passes + j, &temp_decorr_pass,
sizeof(
struct Decorr));
1092 decorr_mono(
s->temp_buffer[j&1][0],
s->temp_buffer[~j&1][0],
1093 nb_samples, &temp_decorr_pass, 1);
1096 size =
log2mono(
s->temp_buffer[j&1][0], nb_samples, log_limit);
1097 if (
size != UINT32_MAX || !nterms)
1102 if (
size < best_size) {
1103 memcpy(
s->best_buffer[0],
s->temp_buffer[j&1][0], buf_size);
1104 memcpy(
s->decorr_passes, save_decorr_passes,
sizeof(
struct Decorr) *
MAX_TERMS);
1105 s->num_terms = nterms;
1111 s->mask_decorr =
s->mask_decorr ? ((
s->mask_decorr << 1) & (
s->num_decorrs - 1)) : 1;
1116 else if (do_samples)
1117 memcpy(
samples,
s->best_buffer[0], buf_size);
1119 if (no_history ||
s->extra_flags) {
1121 scan_word(
s, &
s->w.c[0],
s->best_buffer[0], nb_samples, -1);
1128 int nb_samples,
struct Decorr *dpp,
int dir)
1135 out_left += nb_samples - 1;
1136 out_right += nb_samples - 1;
1137 in_left += nb_samples - 1;
1138 in_right += nb_samples - 1;
1149 switch (dpp->
value) {
1151 while (nb_samples--) {
1173 while (nb_samples--) {
1195 while (nb_samples--) {
1219 while (nb_samples--) {
1256 while (nb_samples--) {
1275 while (nb_samples--) {
1294 while (nb_samples--) {
1324 if (dpp->
value & 1) {
1337 if (dpp->
value & 1) {
1347 }
else if (dpp->
value > 1) {
1350 for (
i = 0, j = dpp->
value - 1, k = 0; k < dpp->
value / 2;
i++, j--, k++) {
1365 int nb_samples,
struct Decorr *dpp)
1377 switch (dpp->
value) {
1379 for (
i = 0;
i < nb_samples;
i++) {
1394 for (
i = 0;
i < nb_samples;
i++) {
1409 for (
i = 0;
i < nb_samples;
i++) {
1426 for (
i = 0;
i < nb_samples;
i++) {
1457 for (
i = 0;
i < nb_samples;
i++) {
1469 for (
i = 0;
i < nb_samples;
i++) {
1481 for (
i = 0;
i < nb_samples;
i++) {
1502 int nb_samples,
int tindex)
1504 struct Decorr dp = {0}, *dppi =
info->dps + tindex;
1505 int delta = dppi->delta, pre_delta;
1506 int term = dppi->value;
1513 pre_delta =
delta + 1;
1516 dp.
delta = pre_delta;
1518 FFMIN(2048, nb_samples), &dp, -1);
1535 decorr_stereo(in_left, in_right, out_left, out_right, nb_samples, &dp, 1);
1539 dppi->weightA = dp.
weightA = dp.
sumA / nb_samples;
1540 dppi->weightB = dp.
weightB = dp.
sumB / nb_samples;
1545 nb_samples, &dp, 1);
1559 memcpy(
info->dps,
s->decorr_passes,
sizeof(
s->decorr_passes));
1562 for (ri = 0; ri <
info->nterms &&
s->decorr_passes[ri].value; ri++) {
1564 if (ri + 1 >=
info->nterms || !
s->decorr_passes[ri+1].value)
1567 if (
s->decorr_passes[ri].value ==
s->decorr_passes[ri+1].value) {
1569 s->sampleptrs[ri ][0],
s->sampleptrs[ri ][1],
1570 s->sampleptrs[ri+1][0],
s->sampleptrs[ri+1][1],
1571 s->block_samples, ri);
1575 info->dps[ri ] =
s->decorr_passes[ri+1];
1576 info->dps[ri+1] =
s->decorr_passes[ri ];
1578 for (
i = ri;
i <
info->nterms &&
s->decorr_passes[
i].value;
i++)
1580 s->sampleptrs[
i ][0],
s->sampleptrs[
i ][1],
1581 s->sampleptrs[
i+1][0],
s->sampleptrs[
i+1][1],
1582 s->block_samples,
i);
1585 s->block_samples,
info->log_limit);
1587 if (bits < info->best_bits) {
1591 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) *
i);
1592 memcpy(
s->sampleptrs[
info->nterms + 1][0],
1593 s->sampleptrs[
i][0],
s->block_samples * 4);
1594 memcpy(
s->sampleptrs[
info->nterms + 1][1],
1595 s->sampleptrs[
i][1],
s->block_samples * 4);
1597 info->dps[ri ] =
s->decorr_passes[ri ];
1598 info->dps[ri+1] =
s->decorr_passes[ri+1];
1600 s->sampleptrs[ri ][0],
s->sampleptrs[ri ][1],
1601 s->sampleptrs[ri+1][0],
s->sampleptrs[ri+1][1],
1602 s->block_samples, ri);
1610 int lower = 0,
delta, d,
i;
1613 if (!
s->decorr_passes[0].value)
1615 delta =
s->decorr_passes[0].delta;
1617 for (d =
delta - 1; d >= 0; d--) {
1618 for (
i = 0;
i <
info->nterms &&
s->decorr_passes[
i].value;
i++) {
1619 info->dps[
i].value =
s->decorr_passes[
i].value;
1620 info->dps[
i].delta = d;
1622 s->sampleptrs[
i ][0],
s->sampleptrs[
i ][1],
1623 s->sampleptrs[
i+1][0],
s->sampleptrs[
i+1][1],
1624 s->block_samples,
i);
1628 s->block_samples,
info->log_limit);
1634 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) *
i);
1635 memcpy(
s->sampleptrs[
info->nterms + 1][0],
s->sampleptrs[
i][0],
1636 s->block_samples * 4);
1637 memcpy(
s->sampleptrs[
info->nterms + 1][1],
s->sampleptrs[
i][1],
1638 s->block_samples * 4);
1641 for (d =
delta + 1; !lower && d <= 7; d++) {
1642 for (
i = 0;
i <
info->nterms &&
s->decorr_passes[
i].value;
i++) {
1643 info->dps[
i].value =
s->decorr_passes[
i].value;
1644 info->dps[
i].delta = d;
1646 s->sampleptrs[
i ][0],
s->sampleptrs[
i ][1],
1647 s->sampleptrs[
i+1][0],
s->sampleptrs[
i+1][1],
1648 s->block_samples,
i);
1652 s->block_samples,
info->log_limit);
1654 if (bits < info->best_bits) {
1657 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) *
i);
1658 memcpy(
s->sampleptrs[
info->nterms + 1][0],
1659 s->sampleptrs[
i][0],
s->block_samples * 4);
1660 memcpy(
s->sampleptrs[
info->nterms + 1][1],
1661 s->sampleptrs[
i][1],
s->block_samples * 4);
1669 int depth,
int delta, uint32_t input_bits)
1671 int term, branches =
s->num_branches - depth;
1672 int32_t *in_left, *in_right, *out_left, *out_right;
1673 uint32_t term_bits[22],
bits;
1675 if (branches < 1 || depth + 1 == info->nterms)
1679 in_left =
s->sampleptrs[depth ][0];
1680 in_right =
s->sampleptrs[depth ][1];
1681 out_left =
s->sampleptrs[depth + 1][0];
1682 out_right =
s->sampleptrs[depth + 1][1];
1684 for (term = -3; term <= 18; term++) {
1685 if (!term || (term > 8 && term < 17))
1688 if (term == 17 && branches == 1 && depth + 1 <
info->nterms)
1691 if (term == -1 || term == -2)
1695 if (!
s->extra_flags && (term > 4 && term < 17))
1698 info->dps[depth].value = term;
1701 s->block_samples, depth);
1704 if (bits < info->best_bits) {
1707 memcpy(
s->decorr_passes,
info->dps,
sizeof(
info->dps[0]) * (depth + 1));
1708 memcpy(
s->sampleptrs[
info->nterms + 1][0],
s->sampleptrs[depth + 1][0],
1709 s->block_samples * 4);
1710 memcpy(
s->sampleptrs[
info->nterms + 1][1],
s->sampleptrs[depth + 1][1],
1711 s->block_samples * 4);
1714 term_bits[term + 3] =
bits;
1717 while (depth + 1 <
info->nterms && branches--) {
1718 uint32_t local_best_bits = input_bits;
1719 int best_term = 0,
i;
1721 for (
i = 0;
i < 22;
i++)
1722 if (term_bits[
i] && term_bits[
i] < local_best_bits) {
1723 local_best_bits = term_bits[
i];
1730 term_bits[best_term + 3] = 0;
1732 info->dps[depth].value = best_term;
1735 s->block_samples, depth);
1753 info.nterms =
s->num_terms;
1758 memcpy(
info.dps,
s->decorr_passes,
sizeof(
info.dps));
1759 memcpy(
s->sampleptrs[0][0], in_left,
s->block_samples * 4);
1760 memcpy(
s->sampleptrs[0][1], in_right,
s->block_samples * 4);
1765 s->sampleptrs[
i + 1][0],
s->sampleptrs[
i + 1][1],
1766 s->block_samples,
info.dps +
i, 1);
1769 s->sampleptrs[
i + 1][0],
s->sampleptrs[
i + 1][1],
1770 s->block_samples,
info.dps +
i);
1773 s->block_samples, 0);
1775 memcpy(
s->sampleptrs[
info.nterms + 1][0],
s->sampleptrs[
i][0],
s->block_samples * 4);
1776 memcpy(
s->sampleptrs[
info.nterms + 1][1],
s->sampleptrs[
i][1],
s->block_samples * 4);
1781 s->block_samples, 0));
1790 s->delta_decay = (
float)((
s->delta_decay * 2.0 +
s->decorr_passes[0].delta) / 3.0);
1792 s->delta_decay = 2.0;
1799 memcpy(in_left,
s->sampleptrs[
info.nterms + 1][0],
s->block_samples * 4);
1800 memcpy(in_right,
s->sampleptrs[
info.nterms + 1][1],
s->block_samples * 4);
1803 for (
i = 0;
i <
info.nterms;
i++)
1804 if (!
s->decorr_passes[
i].value)
1812 int no_history,
int do_samples)
1814 struct Decorr temp_decorr_pass, save_decorr_passes[
MAX_TERMS] = {{0}};
1815 int nb_samples =
s->block_samples,
ret;
1816 int buf_size =
sizeof(
int32_t) * nb_samples;
1817 int log_limit, force_js = 0, force_ts = 0, got_js = 0, pi,
i;
1818 uint32_t best_size = UINT32_MAX,
size;
1820 for (
i = 0;
i < nb_samples;
i++)
1821 if (samples_l[
i] || samples_r[
i])
1824 if (
i == nb_samples) {
1833 log_limit =
FFMIN(6912, log_limit);
1835 if (
s->joint != -1) {
1836 force_js =
s->joint;
1837 force_ts = !
s->joint;
1843 if (no_history ||
s->num_passes >= 7)
1844 s->best_decorr =
s->mask_decorr = 0;
1846 for (pi = 0; pi <
s->num_passes;) {
1853 if (
s->mask_decorr == 0)
1856 c = (
s->best_decorr & (
s->mask_decorr - 1)) |
s->mask_decorr;
1858 if (
c ==
s->best_decorr) {
1859 s->mask_decorr =
s->mask_decorr ? ((
s->mask_decorr << 1) & (
s->num_decorrs - 1)) : 1;
1864 wpds = &
s->decorr_specs[
c];
1872 memcpy(
s->js_left, samples_l, buf_size);
1873 memcpy(
s->js_right, samples_r, buf_size);
1875 for (
i = 0;
i < nb_samples;
i++)
1876 s->js_right[
i] += ((
s->js_left[
i] -=
s->js_right[
i]) >> 1);
1880 memcpy(
s->temp_buffer[0][0],
s->js_left, buf_size);
1881 memcpy(
s->temp_buffer[0][1],
s->js_right, buf_size);
1883 memcpy(
s->temp_buffer[0][0], samples_l, buf_size);
1884 memcpy(
s->temp_buffer[0][1], samples_r, buf_size);
1887 CLEAR(save_decorr_passes);
1889 for (j = 0; j < nterms; j++) {
1890 CLEAR(temp_decorr_pass);
1895 temp_decorr_pass.
value = -3;
1898 s->temp_buffer[~j&1][0],
s->temp_buffer[~j&1][1],
1899 FFMIN(2048, nb_samples), &temp_decorr_pass, -1);
1908 memcpy(save_decorr_passes + j, &temp_decorr_pass,
sizeof(
struct Decorr));
1912 s->temp_buffer[~j&1][0],
s->temp_buffer[~j&1][1],
1913 nb_samples, &temp_decorr_pass, 1);
1916 s->temp_buffer[~j&1][0],
s->temp_buffer[~j&1][1],
1917 nb_samples, &temp_decorr_pass);
1921 nb_samples, log_limit);
1922 if (
size != UINT32_MAX || !nterms)
1927 if (
size < best_size) {
1928 memcpy(
s->best_buffer[0],
s->temp_buffer[j&1][0], buf_size);
1929 memcpy(
s->best_buffer[1],
s->temp_buffer[j&1][1], buf_size);
1930 memcpy(
s->decorr_passes, save_decorr_passes,
sizeof(
struct Decorr) *
MAX_TERMS);
1931 s->num_terms = nterms;
1937 s->mask_decorr =
s->mask_decorr ? ((
s->mask_decorr << 1) & (
s->num_decorrs - 1)) : 1;
1940 if (force_js || (
s->decorr_specs[
s->best_decorr].joint_stereo && !force_ts))
1945 if (
s->extra_flags) {
1950 memcpy(samples_l,
s->js_left, buf_size);
1951 memcpy(samples_r,
s->js_right, buf_size);
1955 }
else if (do_samples) {
1956 memcpy(samples_l,
s->best_buffer[0], buf_size);
1957 memcpy(samples_r,
s->best_buffer[1], buf_size);
1960 if (
s->extra_flags || no_history ||
1961 s->joint_stereo !=
s->decorr_specs[
s->best_decorr].joint_stereo) {
1962 s->joint_stereo =
s->decorr_specs[
s->best_decorr].joint_stereo;
1964 scan_word(
s, &
s->w.c[0],
s->best_buffer[0], nb_samples, -1);
1965 scan_word(
s, &
s->w.c[1],
s->best_buffer[1], nb_samples, -1);
1990 while (
w->zeros_acc > 1) {
1998 if (
w->holding_one) {
1999 if (
w->holding_one >= 16) {
2004 w->holding_one -= 16;
2019 while (
w->holding_one > 1) {
2021 w->holding_one >>= 1;
2024 w->holding_zero = 0;
2026 put_bits(pb,
w->holding_one, (1 <<
w->holding_one) - 1);
2032 if (
w->holding_zero) {
2034 w->holding_zero = 0;
2037 if (
w->pend_count) {
2039 w->pend_data =
w->pend_count = 0;
2046 uint32_t ones_count, low,
high;
2049 if (
s->w.c[0].median[0] < 2 && !
s->w.holding_zero &&
s->w.c[1].median[0] < 2) {
2071 ones_count = low = 0;
2092 low += (ones_count - 2) *
GET_MED(2);
2099 if (
w->holding_zero) {
2106 w->holding_zero = 1;
2109 w->holding_zero = 0;
2111 w->holding_zero = 1;
2113 w->holding_one = ones_count * 2;
2118 uint32_t extras = (1 << bitcount) - maxcode - 1;
2120 if (
code < extras) {
2121 w->pend_data |=
code <<
w->pend_count;
2122 w->pend_count += bitcount - 1;
2124 w->pend_data |= ((
code + extras) >> 1) <<
w->pend_count;
2125 w->pend_count += bitcount - 1;
2126 w->pend_data |= ((
code + extras) & 1) <<
w->pend_count++;
2130 w->pend_data |= ((
int32_t) sign <<
w->pend_count++);
2132 if (!
w->holding_zero)
2140 const int sent_bits =
s->int32_sent_bits;
2144 pre_shift =
s->int32_zeros +
s->int32_ones +
s->int32_dups;
2150 for (
i = 0;
i < nb_samples;
i++) {
2151 put_sbits(pb, sent_bits, samples_l[
i] >> pre_shift);
2154 for (
i = 0;
i < nb_samples;
i++) {
2155 put_sbits(pb, sent_bits, samples_l[
i] >> pre_shift);
2156 put_sbits(pb, sent_bits, samples_r[
i] >> pre_shift);
2163 const int max_exp =
s->float_max_exp;
2181 shift_count = max_exp ? max_exp - 1 : 0;
2185 if (shift_count < 25)
2186 value >>= shift_count;
2207 }
else if (shift_count) {
2223 for (
i = 0;
i < nb_samples;
i++)
2226 for (
i = 0;
i < nb_samples;
i++) {
2239 switch (dpp->
value) {
2241 for (
i = 0;
i < nb_samples;
i++) {
2256 for (
i = 0;
i < nb_samples;
i++) {
2299 for (
i = 0;
i < nb_samples;
i++) {
2311 for (
i = 0;
i < nb_samples;
i++) {
2323 for (
i = 0;
i < nb_samples;
i++) {
2341 #define update_weight_d2(weight, delta, source, result) \
2342 if (source && result) \
2343 weight -= (((source ^ result) >> 29) & 4) - 2;
2345 #define update_weight_clip_d2(weight, delta, source, result) \
2346 if (source && result) { \
2347 const int32_t s = (source ^ result) >> 31; \
2348 if ((weight = (weight ^ s) + (2 - s)) > 1024) weight = 1024; \
2349 weight = (weight ^ s) - s; \
2358 switch (dpp->
value) {
2360 for (
i = 0;
i < nb_samples;
i++) {
2375 for (
i = 0;
i < nb_samples;
i++) {
2419 for (
i = 0;
i < nb_samples;
i++) {
2431 for (
i = 0;
i < nb_samples;
i++) {
2443 for (
i = 0;
i < nb_samples;
i++) {
2466 bytestream2_put_byte(pb,
flags);
2467 bytestream2_put_byte(pb, (
size + 1) >> 1);
2474 int block_size, start, end, data_size, tcount,
temp, m = 0;
2475 int i, j,
ret = 0, got_extra = 0, nb_samples =
s->block_samples;
2476 uint32_t crc = 0xffffffff
u;
2483 if (!(
s->flags &
WV_MONO) &&
s->optimize_mono) {
2486 for (
i = 0;
i < nb_samples;
i++) {
2487 lor |= samples_l[
i] | samples_r[
i];
2488 diff |= samples_l[
i] - samples_r[
i];
2494 if (
i == nb_samples && lor && !
diff) {
2498 if (!
s->false_stereo) {
2499 s->false_stereo = 1;
2503 }
else if (
s->false_stereo) {
2504 s->false_stereo = 0;
2519 if ((mag -=
shift) < 0)
2527 memcpy(
s->orig_l, samples_l,
sizeof(
int32_t) * nb_samples);
2530 memcpy(
s->orig_r, samples_r,
sizeof(
int32_t) * nb_samples);
2534 got_extra =
scan_float(
s, samples_l, samples_r, nb_samples);
2536 got_extra =
scan_int32(
s, samples_l, samples_r, nb_samples);
2540 if (
s->shift !=
s->int32_zeros +
s->int32_ones +
s->int32_dups) {
2541 s->shift =
s->int32_zeros +
s->int32_ones +
s->int32_dups;
2546 if (!
s->num_passes && !
s->num_terms) {
2557 for (
i = 0;
i < nb_samples;
i++)
2558 crc += (crc << 1) + samples_l[
i];
2563 for (
i = 0;
i < nb_samples;
i++)
2564 crc += (crc << 3) + ((uint32_t)samples_l[
i] << 1) + samples_l[
i] + samples_r[
i];
2575 s->ch_offset += 1 + !(
s->flags &
WV_MONO);
2577 if (
s->ch_offset ==
s->avctx->ch_layout.nb_channels)
2581 bytestream2_put_le32(&pb,
MKTAG(
'w',
'v',
'p',
'k'));
2582 bytestream2_put_le32(&pb, 0);
2583 bytestream2_put_le16(&pb, 0x410);
2584 bytestream2_put_le16(&pb, 0);
2585 bytestream2_put_le32(&pb, 0);
2586 bytestream2_put_le32(&pb,
s->sample_index);
2587 bytestream2_put_le32(&pb, nb_samples);
2588 bytestream2_put_le32(&pb,
s->flags);
2589 bytestream2_put_le32(&pb, crc);
2596 bytestream2_put_byte(&pb,
s->avctx->ch_layout.nb_channels);
2597 if (
s->avctx->ch_layout.u.mask >> 32)
2598 bytestream2_put_le32(&pb, 0);
2600 bytestream2_put_le32(&pb,
s->avctx->ch_layout.u.mask);
2601 bytestream2_put_byte(&pb, 0);
2605 bytestream2_put_byte(&pb,
s->avctx->ch_layout.nb_channels);
2606 bytestream2_put_le32(&pb, 0);
2607 bytestream2_put_byte(&pb, 0);
2612 bytestream2_put_le24(&pb,
s->avctx->sample_rate);
2613 bytestream2_put_byte(&pb, 0);
2617 for (
i = 0;
i <
s->num_terms;
i++) {
2618 struct Decorr *dpp = &
s->decorr_passes[
i];
2619 bytestream2_put_byte(&pb, ((dpp->
value + 5) & 0x1f) | ((dpp->
delta << 5) & 0xe0));
2621 if (
s->num_terms & 1)
2622 bytestream2_put_byte(&pb, 0);
2624 #define WRITE_DECWEIGHT(type) do { \
2625 temp = store_weight(type); \
2626 bytestream2_put_byte(&pb, temp); \
2627 type = restore_weight(temp); \
2631 bytestream2_put_byte(&pb, 0);
2633 for (
i =
s->num_terms - 1;
i >= 0; --
i) {
2634 struct Decorr *dpp = &
s->decorr_passes[
i];
2641 for (
i = 0;
i <
s->num_terms;
i++) {
2642 struct Decorr *dpp = &
s->decorr_passes[
i];
2653 out[start - 1] = (end - start + 1) >> 1;
2654 if ((end - start) & 1)
2655 bytestream2_put_byte(&pb, 0);
2657 #define WRITE_DECSAMPLE(type) do { \
2658 temp = log2s(type); \
2659 type = wp_exp2(temp); \
2660 bytestream2_put_le16(&pb, temp); \
2664 bytestream2_put_byte(&pb, 0);
2666 for (
i = 0;
i <
s->num_terms;
i++) {
2667 struct Decorr *dpp = &
s->decorr_passes[
i];
2676 }
else if (dpp->
value < 0) {
2680 for (j = 0; j < dpp->
value; j++) {
2692 out[start - 1] = (end - start) >> 1;
2694 #define WRITE_CHAN_ENTROPY(chan) do { \
2695 for (i = 0; i < 3; i++) { \
2696 temp = wp_log2(s->w.c[chan].median[i]); \
2697 bytestream2_put_le16(&pb, temp); \
2698 s->w.c[chan].median[i] = wp_exp2(temp); \
2709 bytestream2_put_byte(&pb,
s->float_flags);
2710 bytestream2_put_byte(&pb,
s->float_shift);
2711 bytestream2_put_byte(&pb,
s->float_max_exp);
2712 bytestream2_put_byte(&pb, 127);
2717 bytestream2_put_byte(&pb,
s->int32_sent_bits);
2718 bytestream2_put_byte(&pb,
s->int32_zeros);
2719 bytestream2_put_byte(&pb,
s->int32_ones);
2720 bytestream2_put_byte(&pb,
s->int32_dups);
2724 for (
i = 0;
i < nb_samples;
i++) {
2727 for (tcount =
s->num_terms, dpp =
s->decorr_passes; tcount--; dpp++) {
2748 samples_l[
i] =
code;
2751 for (tcount =
s->num_terms, dpp =
s->decorr_passes; tcount--; dpp++)
2766 }
else if (!
s->num_passes) {
2768 for (
i = 0;
i < nb_samples;
i++)
2769 samples_r[
i] += ((samples_l[
i] -= samples_r[
i]) >> 1);
2772 for (
i = 0;
i <
s->num_terms;
i++) {
2773 struct Decorr *dpp = &
s->decorr_passes[
i];
2784 for (
i = 0;
i < nb_samples;
i++)
2787 for (
i = 0;
i < nb_samples;
i++) {
2795 bytestream2_put_le24(&pb, (data_size + 1) >> 1);
2798 bytestream2_put_byte(&pb, 0);
2809 bytestream2_put_le24(&pb, (data_size + 5) >> 1);
2810 bytestream2_put_le32(&pb,
s->crc_x);
2813 bytestream2_put_byte(&pb, 0);
2830 #define COPY_SAMPLES(type, offset, shift) do { \
2831 const type *sptr = (const type *)src; \
2832 for (i = 0; i < nb_samples; i++) \
2833 dst[i] = (sptr[i] - offset) >> shift; \
2836 switch (
s->avctx->sample_fmt) {
2844 if (
s->avctx->bits_per_raw_sample <= 24) {
2850 memcpy(
dst,
src, nb_samples * 4);
2858 for (
i = 0;
i < 15;
i++) {
2873 s->block_samples =
frame->nb_samples;
2875 sizeof(
int32_t) *
s->block_samples);
2880 sizeof(
int32_t) *
s->block_samples);
2894 switch (
s->avctx->sample_fmt) {
2908 s->flags += (1 <<
MAG_LSB) * ((
s->flags & 3) * 8 + 7);
2911 buf, buf_size)) < 0)
2917 s->sample_index +=
frame->nb_samples;
2920 *got_packet_ptr = 1;
2932 s->sampleptrs_size[
i][0] =
s->sampleptrs_size[
i][1] = 0;
2935 for (
i = 0;
i < 2;
i++) {
2937 s->samples_size[
i] = 0;
2940 s->best_buffer_size[
i] = 0;
2944 s->temp_buffer_size[
i][0] =
s->temp_buffer_size[
i][1] = 0;
2949 s->js_left_size =
s->js_right_size = 0;
2953 s->orig_l_size =
s->orig_r_size = 0;
2958 #define OFFSET(x) offsetof(WavPackEncodeContext, x)
2959 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
2974 .
p.
name =
"wavpack",
int frame_size
Number of samples per channel in an audio frame.
int32_t * temp_buffer[2][2]
@ AV_SAMPLE_FMT_FLTP
float, planar
static const WavPackDecorrSpec *const decorr_filters[]
const FFCodec ff_wavpack_encoder
static void shift_mono(int32_t *samples, int nb_samples, int shift)
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
struct Decorr decorr_passes[MAX_TERMS]
#define update_weight_clip_d2(weight, delta, source, result)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int restore_weight(int8_t weight)
static uint32_t log2sample(uint32_t v, int limit, uint32_t *result)
static void encode_flush(WavPackEncodeContext *s)
static int put_bytes_output(const PutBitContext *s)
int sample_rate
samples per second
#define WRITE_DECWEIGHT(type)
static void scan_int23(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
#define AV_CH_LAYOUT_MONO
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int scan_float(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define u(width, name, range_min, range_max)
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
static const AVClass wavpack_encoder_class
#define WRITE_CHAN_ENTROPY(chan)
static int wavpack_encode_block(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, uint8_t *out, int out_size)
#define COPY_SAMPLES(type, offset, shift)
int nb_channels
Number of channels in this layout.
#define FF_COMPRESSION_DEFAULT
#define update_weight_d2(weight, delta, source, result)
static void set_samplerate(WavPackEncodeContext *s)
static void decorr_stereo_buffer(WavPackExtraInfo *info, int32_t *in_left, int32_t *in_right, int32_t *out_left, int32_t *out_right, int nb_samples, int tindex)
int8_t terms[MAX_TERMS+1]
static void decorr_mono_buffer(int32_t *samples, int32_t *outsamples, int nb_samples, struct Decorr *dpp, int tindex)
AVCodec p
The public AVCodec.
static void recurse_mono(WavPackEncodeContext *s, WavPackExtraInfo *info, int depth, int delta, uint32_t input_bits)
AVChannelLayout ch_layout
Audio channel layout.
static av_cold int wavpack_encode_close(AVCodecContext *avctx)
const h264_weight_func weight
#define FF_CODEC_ENCODE_CB(func)
int temp_buffer_size[2][2]
#define AV_CH_LAYOUT_STEREO
static av_always_inline int wp_log2(uint32_t val)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int sampleptrs_size[MAX_TERMS+2][2]
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static const uint8_t decorr_filter_nterms[]
static int wv_stereo(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int no_history, int do_samples)
static __device__ float floor(float a)
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
static const int wv_rates[16]
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_always_inline int wp_exp2(int16_t val)
static int8_t store_weight(int weight)
static int log2s(int32_t value)
static void delta_mono(WavPackEncodeContext *s, WavPackExtraInfo *info)
const WavPackDecorrSpec * decorr_specs
#define CODEC_LONG_NAME(str)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
static av_always_inline int bytestream2_get_bytes_left_p(const PutByteContext *p)
static void sort_stereo(WavPackEncodeContext *s, WavPackExtraInfo *info)
const char * av_default_item_name(void *ptr)
Return the context name.
static void decorr_stereo_pass_id2(struct Decorr *dpp, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static void reverse_mono_decorr(struct Decorr *dpp)
static int scan_int32(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static void analyze_stereo(WavPackEncodeContext *s, int32_t *in_left, int32_t *in_right, int do_samples)
static void pack_int32(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static av_cold int wavpack_encode_init(AVCodecContext *avctx)
static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
int32_t * sampleptrs[MAX_TERMS+2][2]
static int shift(int a, int b)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define i(width, name, range_min, range_max)
static void process_float(WavPackEncodeContext *s, int32_t *sample)
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
static const uint16_t decorr_filter_sizes[]
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
#define CODEC_SAMPLEFMTS(...)
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
static void pack_float_sample(WavPackEncodeContext *s, int32_t *sample)
static void decorr_stereo(int32_t *in_left, int32_t *in_right, int32_t *out_left, int32_t *out_right, int nb_samples, struct Decorr *dpp, int dir)
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
static void put_metadata_block(PutByteContext *pb, int flags, int size)
const char * name
Name of the codec implementation.
#define EXTRA_ADJUST_DELTAS
static double limit(double x)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define APPLY_WEIGHT(weight, sample)
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
main external API structure.
#define APPLY_WEIGHT_I(weight, sample)
static int allocate_buffers(WavPackEncodeContext *s)
#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in)
static uint32_t log2mono(int32_t *samples, int nb_samples, int limit)
static void sort_mono(WavPackEncodeContext *s, WavPackExtraInfo *info)
static void reverse_decorr(struct Decorr *dpp)
static void decorr_stereo_quick(int32_t *in_left, int32_t *in_right, int32_t *out_left, int32_t *out_right, int nb_samples, struct Decorr *dpp)
Filter the word “frame” indicates either a video frame or a group of audio samples
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
#define UPDATE_WEIGHT(weight, delta, source, result)
#define WRITE_DECSAMPLE(type)
static void decorr_mono(int32_t *in_samples, int32_t *out_samples, int nb_samples, struct Decorr *dpp, int dir)
static void recurse_stereo(WavPackEncodeContext *s, WavPackExtraInfo *info, int depth, int delta, uint32_t input_bits)
static void scan_word(WavPackEncodeContext *s, WvChannel *c, int32_t *samples, int nb_samples, int dir)
static uint32_t log2stereo(int32_t *samples_l, int32_t *samples_r, int nb_samples, int limit)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void fill_buffer(WavPackEncodeContext *s, const int8_t *src, int32_t *dst, int nb_samples)
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static void analyze_mono(WavPackEncodeContext *s, int32_t *samples, int do_samples)
static void delta_stereo(WavPackEncodeContext *s, WavPackExtraInfo *info)
static void shift_stereo(int32_t *left, int32_t *right, int nb_samples, int shift)
const uint8_t ff_wp_log2_table[256]
static void wavpack_encode_sample(WavPackEncodeContext *s, WvChannel *c, int32_t sample)
#define MKTAG(a, b, c, d)
static void decorr_stereo_pass2(struct Decorr *dpp, int32_t *samples_l, int32_t *samples_r, int nb_samples)
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
static int allocate_buffers2(WavPackEncodeContext *s, int nterms)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
static void pack_float(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static int wv_mono(WavPackEncodeContext *s, int32_t *samples, int no_history, int do_samples)
static const AVOption options[]