21 #define BITSTREAM_WRITER_LE
32 #define UPDATE_WEIGHT(weight, delta, source, result) \
33 if ((source) && (result)) { \
34 int32_t s = (int32_t) ((source) ^ (result)) >> 31; \
35 weight = ((delta) ^ s) + ((weight) - s); \
38 #define APPLY_WEIGHT_F(weight, sample) ((((((sample) & 0xffff) * (weight)) >> 9) + \
39 ((((sample) & ~0xffff) >> 9) * (weight)) + 1) >> 1)
41 #define APPLY_WEIGHT_I(weight, sample) (((weight) * (sample) + 512) >> 10)
43 #define APPLY_WEIGHT(weight, sample) ((sample) != (short) (sample) ? \
44 APPLY_WEIGHT_F(weight, sample) : APPLY_WEIGHT_I (weight, sample))
46 #define CLEAR(destin) memset(&destin, 0, sizeof(destin));
49 #define SHIFT_MASK (0x1FU << SHIFT_LSB)
52 #define MAG_MASK (0x1FU << MAG_LSB)
55 #define SRATE_MASK (0xFU << SRATE_LSB)
57 #define EXTRA_TRY_DELTAS 1
58 #define EXTRA_ADJUST_DELTAS 2
59 #define EXTRA_SORT_FIRST 4
60 #define EXTRA_BRANCHES 8
61 #define EXTRA_SORT_LAST 16
141 while (block_samples * avctx->
channels < 40000)
193 for (i = 0; i < nb_samples; i++)
194 samples[i] >>= shift;
198 int nb_samples,
int shift)
201 for (i = 0; i < nb_samples; i++) {
207 #define FLOAT_SHIFT_ONES 1
208 #define FLOAT_SHIFT_SAME 2
209 #define FLOAT_SHIFT_SENT 4
210 #define FLOAT_ZEROS_SENT 8
211 #define FLOAT_NEG_ZEROS 0x10
212 #define FLOAT_EXCEPTIONS 0x20
214 #define get_mantissa(f) ((f) & 0x7fffff)
215 #define get_exponent(f) (((f) >> 23) & 0xff)
216 #define get_sign(f) (((f) >> 31) & 0x1)
234 if (shift_count < 25)
235 value >>= shift_count;
244 }
else if (shift_count) {
263 uint32_t crc = 0xffffffff
u;
272 for (i = 0; i < nb_samples; i++) {
280 for (i = 0; i < nb_samples; i++) {
299 for (i = 0; i < nb_samples; i++)
302 for (i = 0; i < nb_samples; i++) {
320 }
while (!(s->
ordata & 1));
349 uint32_t magdata = 0, ordata = 0, xordata = 0, anddata = ~0;
350 int i, total_shift = 0;
355 for (i = 0; i < nb_samples; i++) {
358 magdata |= (M < 0) ? ~M : M;
359 xordata |= M ^ -(M & 1);
363 if ((ordata & 1) && !(anddata & 1) && (xordata & 2))
367 for (i = 0; i < nb_samples; i++) {
371 magdata |= (L < 0) ? ~L : L;
372 magdata |= (R < 0) ? ~R : R;
373 xordata |= L ^ -(L & 1);
374 xordata |= R ^ -(R & 1);
378 if ((ordata & 1) && !(anddata & 1) && (xordata & 2))
399 }
while (!(ordata & 1));
400 }
else if (anddata & 1) {
406 }
while (anddata & 1);
407 }
else if (!(xordata & 2)) {
413 }
while (!(xordata & 2));
420 shift_mono(samples_l, nb_samples, total_shift);
422 shift_stereo(samples_l, samples_r, nb_samples, total_shift);
430 uint32_t magdata = 0, ordata = 0, xordata = 0, anddata = ~0;
431 uint32_t crc = 0xffffffff
u;
432 int i, total_shift = 0;
437 for (i = 0; i < nb_samples; i++) {
440 crc = crc * 9 + (M & 0xffff) * 3 + ((M >> 16) & 0xffff);
441 magdata |= (M < 0) ? ~M : M;
442 xordata |= M ^ -(M & 1);
447 for (i = 0; i < nb_samples; i++) {
451 crc = crc * 9 + (L & 0xffff) * 3 + ((L >> 16) & 0xffff);
452 crc = crc * 9 + (R & 0xffff) * 3 + ((R >> 16) & 0xffff);
453 magdata |= (L < 0) ? ~L : L;
454 magdata |= (R < 0) ? ~R : R;
455 xordata |= L ^ -(L & 1);
456 xordata |= R ^ -(R & 1);
481 }
while (!(ordata & 1));
482 else if (anddata & 1)
488 }
while (anddata & 1);
489 else if (!(xordata & 2))
495 }
while (!(xordata & 2));
508 shift_mono(samples_l, nb_samples, total_shift);
510 shift_stereo(samples_l, samples_r, nb_samples, total_shift);
518 weight = av_clip(weight, -1024, 1024);
520 weight -= (weight + 64) >> 7;
522 return (weight + 4) >> 3;
529 if ((result = (
int) weight << 3) > 0)
530 result += (result + 64) >> 7;
541 int nb_samples,
struct Decorr *dpp,
int dir)
548 out_samples += (nb_samples - 1);
549 in_samples += (nb_samples - 1);
557 if (dpp->
value > MAX_TERM) {
558 while (nb_samples--) {
564 dpp->
samplesA[0] = left = in_samples[0];
569 out_samples[0] = left;
573 }
else if (dpp->
value > 0) {
574 while (nb_samples--) {
575 int k = (m + dpp->
value) & (MAX_TERM - 1);
579 dpp->
samplesA[k] = left = in_samples[0];
580 m = (m + 1) & (MAX_TERM - 1);
585 out_samples[0] = left;
591 if (m && dpp->
value > 0 && dpp->
value <= MAX_TERM) {
598 m = (m + 1) & (MAX_TERM - 1);
622 }
else if (dpp->
value > 1) {
625 for (i = 0, j = dpp->
value - 1, k = 0; k < dpp->
value / 2; i++, j--, k++) {
635 static uint32_t
log2sample(uint32_t
v,
int limit, uint32_t *result)
639 if ((v += v >> 9) < (1 << 8)) {
641 *result += (dbits << 8) +
wp_log2_table[(v << (9 - dbits)) & 0xff];
645 else if (v < (1 << 24))
650 *result += dbits = (dbits << 8) + wp_log2_table[(v >> (dbits - 9)) & 0xff];
652 if (limit && dbits >= limit)
662 while (nb_samples--) {
663 if (
log2sample(abs(*samples++), limit, &result))
670 int nb_samples,
int limit)
673 while (nb_samples--) {
674 if (
log2sample(abs(*samples_l++), limit, &result) ||
675 log2sample(abs(*samples_r++), limit, &result))
682 int nb_samples,
struct Decorr *dpp,
685 struct Decorr dp, *dppi = dpp + tindex;
693 pre_delta = delta + 1;
697 dp.
delta = pre_delta;
711 decorr_mono(samples, outsamples, nb_samples, &dp, 1);
717 decorr_mono(samples, outsamples, nb_samples, &dp, 1);
725 uint32_t term_bits[22],
bits;
727 if (branches < 1 || depth + 1 == info->nterms)
734 for (term = 1; term <= 18; term++) {
735 if (term == 17 && branches == 1 && depth + 1 < info->
nterms)
738 if (term > 8 && term < 17)
749 if (bits < info->best_bits) {
757 term_bits[term + 3] =
bits;
760 while (depth + 1 < info->
nterms && branches--) {
761 uint32_t local_best_bits = input_bits;
762 int best_term = 0, i;
764 for (i = 0; i < 22; i++)
765 if (term_bits[i] && term_bits[i] < local_best_bits) {
766 local_best_bits = term_bits[i];
773 term_bits[best_term + 3] = 0;
779 recurse_mono(s, info, depth + 1, delta, local_best_bits);
813 if (bits < info->best_bits) {
832 int lower = 0,
delta, d;
839 for (d =
delta - 1; d >= 0; d--) {
861 for (d =
delta + 1; !lower && d <= 7; d++) {
887 for (i = 0; i < nterms + 2; i++) {
907 for (i = 0; i < 2; i++) {
978 for (i = 0; i < info.
nterms; i++)
986 int32_t *samples,
int nb_samples,
int dir)
989 samples += nb_samples - 1;
991 while (nb_samples--) {
992 uint32_t low,
value = labs(samples[0]);
1000 if (value - low <
GET_MED(1)) {
1006 if (value - low <
GET_MED(2)) {
1018 int no_history,
int do_samples)
1020 struct Decorr temp_decorr_pass, save_decorr_passes[MAX_TERMS] = {{0}};
1022 int buf_size =
sizeof(
int32_t) * nb_samples;
1023 uint32_t best_size = UINT32_MAX,
size;
1024 int log_limit, pi, i,
ret;
1026 for (i = 0; i < nb_samples; i++)
1030 if (i == nb_samples) {
1038 log_limit =
FFMIN(6912, log_limit);
1069 CLEAR(save_decorr_passes);
1071 for (j = 0; j < nterms; j++) {
1072 CLEAR(temp_decorr_pass);
1076 if (temp_decorr_pass.
value < 0)
1077 temp_decorr_pass.
value = 1;
1080 FFMIN(nb_samples, 2048), &temp_decorr_pass, -1);
1088 memcpy(save_decorr_passes + j, &temp_decorr_pass,
sizeof(
struct Decorr));
1090 nb_samples, &temp_decorr_pass, 1);
1094 if (size != UINT32_MAX || !nterms)
1099 if (size < best_size) {
1113 else if (do_samples)
1125 int nb_samples,
struct Decorr *dpp,
int dir)
1132 out_left += nb_samples - 1;
1133 out_right += nb_samples - 1;
1134 in_left += nb_samples - 1;
1135 in_right += nb_samples - 1;
1146 switch (dpp->
value) {
1148 while (nb_samples--) {
1170 while (nb_samples--) {
1192 while (nb_samples--) {
1214 int k = dpp->
value & (MAX_TERM - 1);
1216 while (nb_samples--) {
1233 m = (m + 1) & (MAX_TERM - 1);
1234 k = (k + 1) & (MAX_TERM - 1);
1247 m = (m + 1) & (MAX_TERM - 1);
1253 while (nb_samples--) {
1272 while (nb_samples--) {
1291 while (nb_samples--) {
1297 dpp->
samplesA[0] = tmp = in_right[0];
1302 dpp->
samplesB[0] = tmp = in_left[0];
1321 if (dpp->
value & 1) {
1334 if (dpp->
value & 1) {
1344 }
else if (dpp->
value > 1) {
1347 for (i = 0, j = dpp->
value - 1, k = 0; k < dpp->
value / 2; i++, j--, k++) {
1362 int nb_samples,
struct Decorr *dpp)
1374 switch (dpp->
value) {
1376 for (i = 0; i < nb_samples; i++) {
1391 for (i = 0; i < nb_samples; i++) {
1406 for (i = 0; i < nb_samples; i++) {
1421 int k = dpp->
value & (MAX_TERM - 1);
1423 for (i = 0; i < nb_samples; i++) {
1434 m = (m + 1) & (MAX_TERM - 1);
1435 k = (k + 1) & (MAX_TERM - 1);
1448 m = (m + 1) & (MAX_TERM - 1);
1454 for (i = 0; i < nb_samples; i++) {
1466 for (i = 0; i < nb_samples; i++) {
1478 for (i = 0; i < nb_samples; i++) {
1484 dpp->
samplesA[0] = tmp = in_right[i];
1488 dpp->
samplesB[0] = tmp = in_left[i];
1499 int nb_samples,
int tindex)
1501 struct Decorr dp = {0}, *dppi = info->
dps + tindex;
1502 int delta = dppi->delta, pre_delta;
1503 int term = dppi->value;
1510 pre_delta = delta + 1;
1513 dp.
delta = pre_delta;
1515 FFMIN(2048, nb_samples), &dp, -1);
1532 decorr_stereo(in_left, in_right, out_left, out_right, nb_samples, &dp, 1);
1536 dppi->weightA = dp.
weightA = dp.
sumA / nb_samples;
1537 dppi->weightB = dp.
weightB = dp.
sumB / nb_samples;
1542 nb_samples, &dp, 1);
1584 if (bits < info->best_bits) {
1607 int lower = 0,
delta, d, i;
1614 for (d =
delta - 1; d >= 0; d--) {
1638 for (d =
delta + 1; !lower && d <= 7; d++) {
1651 if (bits < info->best_bits) {
1669 int32_t *in_left, *in_right, *out_left, *out_right;
1670 uint32_t term_bits[22],
bits;
1672 if (branches < 1 || depth + 1 == info->nterms)
1681 for (term = -3; term <= 18; term++) {
1682 if (!term || (term > 8 && term < 17))
1685 if (term == 17 && branches == 1 && depth + 1 < info->
nterms)
1688 if (term == -1 || term == -2)
1701 if (bits < info->best_bits) {
1711 term_bits[term + 3] =
bits;
1714 while (depth + 1 < info->
nterms && branches--) {
1715 uint32_t local_best_bits = input_bits;
1716 int best_term = 0, i;
1718 for (i = 0; i < 22; i++)
1719 if (term_bits[i] && term_bits[i] < local_best_bits) {
1720 local_best_bits = term_bits[i];
1727 term_bits[best_term + 3] = 0;
1800 for (i = 0; i < info.
nterms; i++)
1809 int no_history,
int do_samples)
1811 struct Decorr temp_decorr_pass, save_decorr_passes[MAX_TERMS] = {{0}};
1813 int buf_size =
sizeof(
int32_t) * nb_samples;
1814 int log_limit, force_js = 0, force_ts = 0, got_js = 0, pi, i;
1815 uint32_t best_size = UINT32_MAX,
size;
1817 for (i = 0; i < nb_samples; i++)
1818 if (samples_l[i] || samples_r[i])
1821 if (i == nb_samples) {
1830 log_limit =
FFMIN(6912, log_limit);
1833 force_js = s->
joint > 0;
1834 force_ts = s->
joint < 0;
1869 memcpy(s->
js_left, samples_l, buf_size);
1870 memcpy(s->
js_right, samples_r, buf_size);
1872 for (i = 0; i < nb_samples; i++)
1880 memcpy(s->
temp_buffer[0][0], samples_l, buf_size);
1881 memcpy(s->
temp_buffer[0][1], samples_r, buf_size);
1884 CLEAR(save_decorr_passes);
1886 for (j = 0; j < nterms; j++) {
1887 CLEAR(temp_decorr_pass);
1892 temp_decorr_pass.
value = -3;
1896 FFMIN(2048, nb_samples), &temp_decorr_pass, -1);
1905 memcpy(save_decorr_passes + j, &temp_decorr_pass,
sizeof(
struct Decorr));
1910 nb_samples, &temp_decorr_pass, 1);
1914 nb_samples, &temp_decorr_pass);
1918 nb_samples, log_limit);
1919 if (size != UINT32_MAX || !nterms)
1924 if (size < best_size) {
1947 memcpy(samples_l, s->
js_left, buf_size);
1948 memcpy(samples_r, s->
js_right, buf_size);
1952 }
else if (do_samples) {
1967 #define count_bits(av) ( \
1968 (av) < (1 << 8) ? nbits_table[av] : \
1970 (av) < (1 << 16) ? nbits_table[(av) >> 8] + 8 : \
1971 ((av) < (1 << 24) ? nbits_table[(av) >> 16] + 16 : nbits_table[(av) >> 24] + 24) \
1988 put_bits(pb, cbits, (1 << cbits) - 1);
2017 put_bits(pb, cbits, (1 << cbits) - 1);
2051 uint32_t ones_count, low, high;
2052 int sign = sample < 0;
2062 }
else if (sample) {
2076 ones_count = low = 0;
2083 if (sample - low <
GET_MED(1)) {
2091 if (sample - low <
GET_MED(2)) {
2096 ones_count = 2 + (sample - low) /
GET_MED(2);
2097 low += (ones_count - 2) *
GET_MED(2);
2121 uint32_t maxcode = high - low, code = sample - low;
2123 uint32_t extras = (1 << bitcount) - maxcode - 1;
2125 if (code < extras) {
2155 for (i = 0; i < nb_samples; i++) {
2156 put_sbits(pb, sent_bits, samples_l[i] >> pre_shift);
2159 for (i = 0; i < nb_samples; i++) {
2160 put_sbits(pb, sent_bits, samples_l[i] >> pre_shift);
2161 put_sbits(pb, sent_bits, samples_r[i] >> pre_shift);
2186 shift_count = max_exp ? max_exp - 1 : 0;
2190 if (shift_count < 25)
2191 value >>= shift_count;
2212 }
else if (shift_count) {
2229 for (i = 0; i < nb_samples; i++)
2232 for (i = 0; i < nb_samples; i++) {
2245 switch (dpp->
value) {
2247 for (i = 0; i < nb_samples; i++) {
2262 for (i = 0; i < nb_samples; i++) {
2277 for (m = 0, k = dpp->
value & (
MAX_TERM - 1), i = 0; i < nb_samples; i++) {
2300 m = (m + 1) & (MAX_TERM - 1);
2305 for (i = 0; i < nb_samples; i++) {
2317 for (i = 0; i < nb_samples; i++) {
2329 for (i = 0; i < nb_samples; i++) {
2335 dpp->
samplesA[0] = tmp = samples_r[i];
2339 dpp->
samplesB[0] = tmp = samples_l[i];
2347 #define update_weight_d2(weight, delta, source, result) \
2348 if (source && result) \
2349 weight -= (((source ^ result) >> 29) & 4) - 2;
2351 #define update_weight_clip_d2(weight, delta, source, result) \
2352 if (source && result) { \
2353 const int32_t s = (source ^ result) >> 31; \
2354 if ((weight = (weight ^ s) + (2 - s)) > 1024) weight = 1024; \
2355 weight = (weight ^ s) - s; \
2364 switch (dpp->
value) {
2366 for (i = 0; i < nb_samples; i++) {
2381 for (i = 0; i < nb_samples; i++) {
2396 for (m = 0, k = dpp->
value & (
MAX_TERM - 1), i = 0; i < nb_samples; i++) {
2420 m = (m + 1) & (MAX_TERM - 1);
2425 for (i = 0; i < nb_samples; i++) {
2437 for (i = 0; i < nb_samples; i++) {
2449 for (i = 0; i < nb_samples; i++) {
2455 dpp->
samplesA[0] = tmp = samples_r[i];
2459 dpp->
samplesB[0] = tmp = samples_l[i];
2472 bytestream2_put_byte(pb, flags);
2473 bytestream2_put_byte(pb, (size + 1) >> 1);
2482 uint32_t crc = 0xffffffff
u;
2492 for (i = 0; i < nb_samples; i++) {
2493 lor |= samples_l[i] | samples_r[i];
2494 diff |= samples_l[i] - samples_r[i];
2500 if (i == nb_samples && lor && !
diff) {
2525 if ((mag -= shift) < 0)
2540 got_extra =
scan_float(s, samples_l, samples_r, nb_samples);
2542 got_extra =
scan_int32(s, samples_l, samples_r, nb_samples);
2545 scan_int23(s, samples_l, samples_r, nb_samples);
2556 ret =
wv_mono(s, samples_l, 1, 0);
2558 ret =
wv_stereo(s, samples_l, samples_r, 1, 0);
2563 for (i = 0; i < nb_samples; i++)
2564 crc += (crc << 1) + samples_l[i];
2569 for (i = 0; i < nb_samples; i++)
2570 crc += (crc << 3) + (samples_l[i] << 1) + samples_l[i] + samples_r[i];
2587 bytestream2_put_le32(&pb,
MKTAG(
'w',
'v',
'p',
'k'));
2588 bytestream2_put_le32(&pb, 0);
2589 bytestream2_put_le16(&pb, 0x410);
2590 bytestream2_put_le16(&pb, 0);
2591 bytestream2_put_le32(&pb, 0);
2593 bytestream2_put_le32(&pb, nb_samples);
2594 bytestream2_put_le32(&pb, s->
flags);
2595 bytestream2_put_le32(&pb, crc);
2603 bytestream2_put_byte(&pb, 0);
2609 bytestream2_put_byte(&pb, 0);
2615 bytestream2_put_byte(&pb, ((dpp->
value + 5) & 0x1f) | ((dpp->
delta << 5) & 0xe0));
2618 bytestream2_put_byte(&pb, 0);
2620 #define WRITE_DECWEIGHT(type) do { \
2621 temp = store_weight(type); \
2622 bytestream2_put_byte(&pb, temp); \
2623 type = restore_weight(temp); \
2627 bytestream2_put_byte(&pb, 0);
2629 for (i = s->
num_terms - 1; i >= 0; --i) {
2649 out[start - 1] = (end - start + 1) >> 1;
2650 if ((end - start) & 1)
2651 bytestream2_put_byte(&pb, 0);
2653 #define WRITE_DECSAMPLE(type) do { \
2654 temp = log2s(type); \
2655 type = wp_exp2(temp); \
2656 bytestream2_put_le16(&pb, temp); \
2660 bytestream2_put_byte(&pb, 0);
2672 }
else if (dpp->
value < 0) {
2676 for (j = 0; j < dpp->
value; j++) {
2688 out[start - 1] = (end -
start) >> 1;
2690 #define WRITE_CHAN_ENTROPY(chan) do { \
2691 for (i = 0; i < 3; i++) { \
2692 temp = wp_log2(s->w.c[chan].median[i]); \
2693 bytestream2_put_le16(&pb, temp); \
2694 s->w.c[chan].median[i] = wp_exp2(temp); \
2708 bytestream2_put_byte(&pb, 127);
2720 for (i = 0; i < nb_samples; i++) {
2744 samples_l[i] = code;
2758 m = (m + 1) & (MAX_TERM - 1);
2764 for (i = 0; i < nb_samples; i++)
2765 samples_r[i] += ((samples_l[i] -= samples_r[i]) >> 1);
2780 for (i = 0; i < nb_samples; i++)
2783 for (i = 0; i < nb_samples; i++) {
2791 bytestream2_put_le24(&pb, (data_size + 1) >> 1);
2794 bytestream2_put_byte(&pb, 0);
2805 bytestream2_put_le24(&pb, (data_size + 5) >> 1);
2806 bytestream2_put_le32(&pb, s->
crc_x);
2809 bytestream2_put_byte(&pb, 0);
2813 AV_WL32(out + 4, block_size - 8);
2826 #define COPY_SAMPLES(type, offset, shift) do { \
2827 const type *sptr = (const type *)src; \
2828 for (i = 0; i < nb_samples; i++) \
2829 dst[i] = (sptr[i] - offset) >> shift; \
2845 memcpy(dst, src, nb_samples * 4);
2853 for (i = 0; i < 15; i++) {
2906 buf, buf_size)) < 0)
2917 *got_packet_ptr = 1;
2932 for (i = 0; i < 2; i++) {
2955 #define OFFSET(x) offsetof(WavPackEncodeContext, x)
2956 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
2981 .priv_class = &wavpack_encoder_class,
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
#define WRITE_DECWEIGHT(type)
#define FF_COMPRESSION_DEFAULT
static int shift(int a, int b)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static av_cold int wavpack_encode_close(AVCodecContext *avctx)
static void shift_stereo(int32_t *left, int32_t *right, int nb_samples, int shift)
static int scan_float(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static int wv_stereo(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int no_history, int do_samples)
static int wavpack_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
#define LIBAVUTIL_VERSION_INT
static void process_float(WavPackEncodeContext *s, int32_t *sample)
static av_cold int init(AVCodecContext *avctx)
static void shift_mono(int32_t *samples, int nb_samples, int shift)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static void delta_mono(WavPackEncodeContext *s, WavPackExtraInfo *info)
static int allocate_buffers2(WavPackEncodeContext *s, int nterms)
static void sort_stereo(WavPackEncodeContext *s, WavPackExtraInfo *info)
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end w...
static void pack_float_sample(WavPackEncodeContext *s, int32_t *sample)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_CH_LAYOUT_STEREO
static void put_metadata_block(PutByteContext *pb, int flags, int size)
static void wavpack_encode_sample(WavPackEncodeContext *s, WvChannel *c, int32_t sample)
static uint32_t log2mono(int32_t *samples, int nb_samples, int limit)
static av_cold int wavpack_encode_init(AVCodecContext *avctx)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
enum AVSampleFormat sample_fmt
audio sample format
#define UPDATE_WEIGHT(weight, delta, source, result)
static void pack_int32(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
const WavPackDecorrSpec * decorr_specs
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)
#define APPLY_WEIGHT_I(weight, sample)
static av_cold int end(AVCodecContext *avctx)
AVCodec ff_wavpack_encoder
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static void delta_stereo(WavPackEncodeContext *s, WavPackExtraInfo *info)
#define WRITE_CHAN_ENTROPY(chan)
static void fill_buffer(WavPackEncodeContext *s, const int8_t *src, int32_t *dst, int nb_samples)
static void decorr_mono_buffer(int32_t *samples, int32_t *outsamples, int nb_samples, struct Decorr *dpp, int tindex)
struct Decorr decorr_passes[MAX_TERMS]
#define APPLY_WEIGHT(weight, sample)
static void analyze_stereo(WavPackEncodeContext *s, int32_t *in_left, int32_t *in_right, int do_samples)
static const AVOption options[]
static void reverse_mono_decorr(struct Decorr *dpp)
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int32_t * sampleptrs[MAX_TERMS+2][2]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p)
static const uint16_t mask[17]
#define EXTRA_ADJUST_DELTAS
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void set_samplerate(WavPackEncodeContext *s)
static av_always_inline int wp_exp2(int16_t val)
static void recurse_stereo(WavPackEncodeContext *s, WavPackExtraInfo *info, int depth, int delta, uint32_t input_bits)
const char * name
Name of the codec implementation.
static void decorr_stereo_pass_id2(struct Decorr *dpp, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static av_always_inline int bytestream2_tell_p(PutByteContext *p)
Libavcodec external API header.
int8_t terms[MAX_TERMS+1]
static int log2s(int32_t value)
uint64_t channel_layout
Audio channel layout.
static int put_bits_count(PutBitContext *s)
static const WavPackDecorrSpec *const decorr_filters[]
static av_always_inline void bytestream2_skip_p(PutByteContext *p, unsigned int size)
static void decorr_stereo_pass2(struct Decorr *dpp, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static void scan_word(WavPackEncodeContext *s, WvChannel *c, int32_t *samples, int nb_samples, int dir)
static const int wv_rates[16]
GLsizei GLboolean const GLfloat * value
static void pack_float(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static uint32_t log2sample(uint32_t v, int limit, uint32_t *result)
#define update_weight_d2(weight, delta, source, result)
int frame_size
Number of samples per channel in an audio frame.
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)
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
static int allocate_buffers(WavPackEncodeContext *s)
static void analyze_mono(WavPackEncodeContext *s, int32_t *samples, int do_samples)
main external API structure.
static int scan_int32(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
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)
#define WRITE_DECSAMPLE(type)
Describe the class of an AVClass context structure.
static int8_t store_weight(int weight)
int32_t * temp_buffer[2][2]
static void scan_int23(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, int nb_samples)
static int weight(int i, int blen, int offset)
#define update_weight_clip_d2(weight, delta, source, result)
#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in)
static int restore_weight(int8_t weight)
static uint32_t log2stereo(int32_t *samples_l, int32_t *samples_r, int nb_samples, int limit)
static const AVClass wavpack_encoder_class
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int wavpack_encode_block(WavPackEncodeContext *s, int32_t *samples_l, int32_t *samples_r, uint8_t *out, int out_size)
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
static const uint8_t decorr_filter_nterms[]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static av_always_inline int wp_log2(int32_t val)
static void encode_flush(WavPackEncodeContext *s)
static void recurse_mono(WavPackEncodeContext *s, WavPackExtraInfo *info, int depth, int delta, uint32_t input_bits)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static int wv_mono(WavPackEncodeContext *s, int32_t *samples, int no_history, int do_samples)
#define COPY_SAMPLES(type, offset, shift)
int channels
number of audio channels
static void decorr_mono(int32_t *in_samples, int32_t *out_samples, int nb_samples, struct Decorr *dpp, int dir)
static void reverse_decorr(struct Decorr *dpp)
int sampleptrs_size[MAX_TERMS+2][2]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static const uint8_t wp_log2_table[]
static const uint16_t decorr_filter_sizes[]
static enum AVSampleFormat sample_fmts[]
int temp_buffer_size[2][2]
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
static void sort_mono(WavPackEncodeContext *s, WavPackExtraInfo *info)
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_LAYOUT_MONO
#define MKTAG(a, b, c, d)
static const int8_t nbits_table[]
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...