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 92 int temp_buffer_size[2][2];
95 int best_buffer_size[2];
118 int num_terms,
shift, joint_stereo, false_stereo;
146 while (block_samples * avctx->
channels < 40000)
198 for (i = 0; i < nb_samples; i++)
199 samples[i] >>= shift;
203 int nb_samples,
int shift)
206 for (i = 0; i < nb_samples; i++) {
212 #define FLOAT_SHIFT_ONES 1 213 #define FLOAT_SHIFT_SAME 2 214 #define FLOAT_SHIFT_SENT 4 215 #define FLOAT_ZEROS_SENT 8 216 #define FLOAT_NEG_ZEROS 0x10 217 #define FLOAT_EXCEPTIONS 0x20 219 #define get_mantissa(f) ((f) & 0x7fffff) 220 #define get_exponent(f) (((f) >> 23) & 0xff) 221 #define get_sign(f) (((f) >> 31) & 0x1) 239 if (shift_count < 25)
240 value >>= shift_count;
249 }
else if (shift_count) {
268 uint32_t crc = 0xffffffff
u;
277 for (i = 0; i < nb_samples; i++) {
285 for (i = 0; i < nb_samples; i++) {
304 for (i = 0; i < nb_samples; i++)
307 for (i = 0; i < nb_samples; i++) {
325 }
while (!(s->
ordata & 1));
354 uint32_t magdata = 0, ordata = 0, xordata = 0, anddata = ~0;
355 int i, total_shift = 0;
360 for (i = 0; i < nb_samples; i++) {
363 magdata |= (M < 0) ? ~M : M;
364 xordata |= M ^ -(M & 1);
368 if ((ordata & 1) && !(anddata & 1) && (xordata & 2))
372 for (i = 0; i < nb_samples; i++) {
376 magdata |= (L < 0) ? ~L : L;
377 magdata |= (R < 0) ? ~R : R;
378 xordata |= L ^ -(L & 1);
379 xordata |= R ^ -(R & 1);
383 if ((ordata & 1) && !(anddata & 1) && (xordata & 2))
404 }
while (!(ordata & 1));
405 }
else if (anddata & 1) {
411 }
while (anddata & 1);
412 }
else if (!(xordata & 2)) {
418 }
while (!(xordata & 2));
425 shift_mono(samples_l, nb_samples, total_shift);
427 shift_stereo(samples_l, samples_r, nb_samples, total_shift);
435 uint32_t magdata = 0, ordata = 0, xordata = 0, anddata = ~0;
436 uint32_t crc = 0xffffffff
u;
437 int i, total_shift = 0;
442 for (i = 0; i < nb_samples; i++) {
445 crc = crc * 9 + (M & 0xffff) * 3 + ((M >> 16) & 0xffff);
446 magdata |= (M < 0) ? ~M : M;
447 xordata |= M ^ -(M & 1);
452 for (i = 0; i < nb_samples; i++) {
456 crc = crc * 9 + (L & 0xffff) * 3 + ((L >> 16) & 0xffff);
457 crc = crc * 9 + (R & 0xffff) * 3 + ((R >> 16) & 0xffff);
458 magdata |= (L < 0) ? ~L : L;
459 magdata |= (R < 0) ? ~R : R;
460 xordata |= L ^ -(L & 1);
461 xordata |= R ^ -(R & 1);
486 }
while (!(ordata & 1));
487 else if (anddata & 1)
493 }
while (anddata & 1);
494 else if (!(xordata & 2))
500 }
while (!(xordata & 2));
513 shift_mono(samples_l, nb_samples, total_shift);
515 shift_stereo(samples_l, samples_r, nb_samples, total_shift);
523 weight = av_clip(weight, -1024, 1024);
525 weight -= (weight + 64) >> 7;
527 return (weight + 4) >> 3;
535 result += (result + 64) >> 7;
546 int nb_samples,
struct Decorr *dpp,
int dir)
553 out_samples += (nb_samples - 1);
554 in_samples += (nb_samples - 1);
562 if (dpp->
value > MAX_TERM) {
563 while (nb_samples--) {
569 dpp->
samplesA[0] = left = in_samples[0];
574 out_samples[0] = left;
578 }
else if (dpp->
value > 0) {
579 while (nb_samples--) {
580 int k = (m + dpp->
value) & (MAX_TERM - 1);
584 dpp->
samplesA[k] = left = in_samples[0];
585 m = (m + 1) & (MAX_TERM - 1);
590 out_samples[0] = left;
596 if (m && dpp->
value > 0 && dpp->
value <= MAX_TERM) {
603 m = (m + 1) & (MAX_TERM - 1);
627 }
else if (dpp->
value > 1) {
630 for (i = 0, j = dpp->
value - 1, k = 0; k < dpp->
value / 2; i++, j--, k++) {
640 #define count_bits(av) ((av) ? 32 - ff_clz(av) : 0) 642 static uint32_t
log2sample(uint32_t v,
int limit, uint32_t *result)
646 if ((v += v >> 9) < (1 << 8)) {
647 *result += (dbits << 8) +
wp_log2_table[(v << (9 - dbits)) & 0xff];
649 *result += dbits = (dbits << 8) + wp_log2_table[(v >> (dbits - 9)) & 0xff];
651 if (limit && dbits >= limit)
661 while (nb_samples--) {
669 int nb_samples,
int limit)
672 while (nb_samples--) {
681 int nb_samples,
struct Decorr *dpp,
684 struct Decorr dp, *dppi = dpp + tindex;
692 pre_delta = delta + 1;
696 dp.
delta = pre_delta;
710 decorr_mono(samples, outsamples, nb_samples, &dp, 1);
716 decorr_mono(samples, outsamples, nb_samples, &dp, 1);
720 int depth,
int delta, uint32_t input_bits)
724 uint32_t term_bits[22],
bits;
726 if (branches < 1 || depth + 1 == info->
nterms)
733 for (term = 1; term <= 18; term++) {
734 if (term == 17 && branches == 1 && depth + 1 < info->
nterms)
737 if (term > 8 && term < 17)
756 term_bits[term + 3] =
bits;
759 while (depth + 1 < info->
nterms && branches--) {
760 uint32_t local_best_bits = input_bits;
761 int best_term = 0,
i;
763 for (
i = 0;
i < 22;
i++)
764 if (term_bits[
i] && term_bits[
i] < local_best_bits) {
765 local_best_bits = term_bits[
i];
772 term_bits[best_term + 3] = 0;
778 recurse_mono(s, info, depth + 1, delta, local_best_bits);
831 int lower = 0,
delta, d;
838 for (d =
delta - 1; d >= 0; d--) {
860 for (d =
delta + 1; !lower && d <= 7; d++) {
886 for (i = 0; i < nterms + 2; i++) {
906 for (i = 0; i < 2; i++) {
977 for (i = 0; i < info.
nterms; i++)
985 int32_t *samples,
int nb_samples,
int dir)
988 samples += nb_samples - 1;
990 while (nb_samples--) {
991 uint32_t low,
value = labs(samples[0]);
999 if (value - low <
GET_MED(1)) {
1005 if (value - low <
GET_MED(2)) {
1017 int no_history,
int do_samples)
1019 struct Decorr temp_decorr_pass, save_decorr_passes[MAX_TERMS] = {{0}};
1021 int buf_size =
sizeof(
int32_t) * nb_samples;
1022 uint32_t best_size = UINT32_MAX,
size;
1025 for (i = 0; i < nb_samples; i++)
1029 if (i == nb_samples) {
1037 log_limit =
FFMIN(6912, log_limit);
1068 CLEAR(save_decorr_passes);
1070 for (j = 0; j <
nterms; j++) {
1071 CLEAR(temp_decorr_pass);
1075 if (temp_decorr_pass.
value < 0)
1076 temp_decorr_pass.
value = 1;
1079 FFMIN(nb_samples, 2048), &temp_decorr_pass, -1);
1087 memcpy(save_decorr_passes + j, &temp_decorr_pass,
sizeof(
struct Decorr));
1089 nb_samples, &temp_decorr_pass, 1);
1093 if (size != UINT32_MAX || !nterms)
1098 if (size < best_size) {
1112 else if (do_samples)
1124 int nb_samples,
struct Decorr *dpp,
int dir)
1131 out_left += nb_samples - 1;
1132 out_right += nb_samples - 1;
1133 in_left += nb_samples - 1;
1134 in_right += nb_samples - 1;
1145 switch (dpp->
value) {
1147 while (nb_samples--) {
1169 while (nb_samples--) {
1191 while (nb_samples--) {
1213 int k = dpp->
value & (MAX_TERM - 1);
1215 while (nb_samples--) {
1232 m = (m + 1) & (MAX_TERM - 1);
1233 k = (k + 1) & (MAX_TERM - 1);
1246 m = (m + 1) & (MAX_TERM - 1);
1252 while (nb_samples--) {
1271 while (nb_samples--) {
1290 while (nb_samples--) {
1296 dpp->
samplesA[0] = tmp = in_right[0];
1301 dpp->
samplesB[0] = tmp = in_left[0];
1320 if (dpp->
value & 1) {
1333 if (dpp->
value & 1) {
1343 }
else if (dpp->
value > 1) {
1346 for (i = 0, j = dpp->
value - 1, k = 0; k < dpp->
value / 2; i++, j--, k++) {
1361 int nb_samples,
struct Decorr *dpp)
1373 switch (dpp->
value) {
1375 for (
i = 0;
i < nb_samples;
i++) {
1390 for (
i = 0;
i < nb_samples;
i++) {
1405 for (
i = 0;
i < nb_samples;
i++) {
1420 int k = dpp->
value & (MAX_TERM - 1);
1422 for (
i = 0;
i < nb_samples;
i++) {
1433 m = (m + 1) & (MAX_TERM - 1);
1434 k = (k + 1) & (MAX_TERM - 1);
1447 m = (m + 1) & (MAX_TERM - 1);
1453 for (
i = 0;
i < nb_samples;
i++) {
1465 for (
i = 0;
i < nb_samples;
i++) {
1477 for (
i = 0;
i < nb_samples;
i++) {
1498 int nb_samples,
int tindex)
1500 struct Decorr dp = {0}, *dppi = info->
dps + tindex;
1501 int delta = dppi->delta, pre_delta;
1502 int term = dppi->value;
1509 pre_delta = delta + 1;
1512 dp.
delta = pre_delta;
1514 FFMIN(2048, nb_samples), &dp, -1);
1531 decorr_stereo(in_left, in_right, out_left, out_right, nb_samples, &dp, 1);
1535 dppi->weightA = dp.
weightA = dp.
sumA / nb_samples;
1536 dppi->weightB = dp.
weightB = dp.
sumB / nb_samples;
1541 nb_samples, &dp, 1);
1606 int lower = 0,
delta, d,
i;
1613 for (d =
delta - 1; d >= 0; d--) {
1637 for (d =
delta + 1; !lower && d <= 7; d++) {
1665 int depth,
int delta, uint32_t input_bits)
1668 int32_t *in_left, *in_right, *out_left, *out_right;
1669 uint32_t term_bits[22],
bits;
1671 if (branches < 1 || depth + 1 == info->
nterms)
1680 for (term = -3; term <= 18; term++) {
1681 if (!term || (term > 8 && term < 17))
1684 if (term == 17 && branches == 1 && depth + 1 < info->
nterms)
1687 if (term == -1 || term == -2)
1710 term_bits[term + 3] =
bits;
1713 while (depth + 1 < info->
nterms && branches--) {
1714 uint32_t local_best_bits = input_bits;
1715 int best_term = 0,
i;
1717 for (
i = 0;
i < 22;
i++)
1718 if (term_bits[
i] && term_bits[
i] < local_best_bits) {
1719 local_best_bits = term_bits[
i];
1726 term_bits[best_term + 3] = 0;
1728 info->
dps[depth].
value = best_term;
1799 for (i = 0; i < info.
nterms; i++)
1808 int no_history,
int do_samples)
1810 struct Decorr temp_decorr_pass, save_decorr_passes[MAX_TERMS] = {{0}};
1812 int buf_size =
sizeof(
int32_t) * nb_samples;
1813 int log_limit, force_js = 0, force_ts = 0, got_js = 0, pi,
i;
1814 uint32_t best_size = UINT32_MAX,
size;
1816 for (i = 0; i < nb_samples; i++)
1817 if (samples_l[i] || samples_r[i])
1820 if (i == nb_samples) {
1829 log_limit =
FFMIN(6912, log_limit);
1831 if (s->
joint != -1) {
1832 force_js = s->
joint;
1833 force_ts = !s->
joint;
1868 memcpy(s->
js_left, samples_l, buf_size);
1869 memcpy(s->
js_right, samples_r, buf_size);
1871 for (i = 0; i < nb_samples; i++)
1879 memcpy(s->
temp_buffer[0][0], samples_l, buf_size);
1880 memcpy(s->
temp_buffer[0][1], samples_r, buf_size);
1883 CLEAR(save_decorr_passes);
1885 for (j = 0; j <
nterms; j++) {
1886 CLEAR(temp_decorr_pass);
1891 temp_decorr_pass.
value = -3;
1895 FFMIN(2048, nb_samples), &temp_decorr_pass, -1);
1904 memcpy(save_decorr_passes + j, &temp_decorr_pass,
sizeof(
struct Decorr));
1909 nb_samples, &temp_decorr_pass, 1);
1913 nb_samples, &temp_decorr_pass);
1917 nb_samples, log_limit);
1918 if (size != UINT32_MAX || !nterms)
1923 if (size < best_size) {
1946 memcpy(samples_l, s->
js_left, buf_size);
1947 memcpy(samples_r, s->
js_right, buf_size);
1951 }
else if (do_samples) {
2042 uint32_t ones_count, low, high;
2043 int sign = sample < 0;
2053 }
else if (sample) {
2067 ones_count = low = 0;
2074 if (sample - low <
GET_MED(1)) {
2082 if (sample - low <
GET_MED(2)) {
2087 ones_count = 2 + (sample - low) /
GET_MED(2);
2088 low += (ones_count - 2) *
GET_MED(2);
2112 uint32_t maxcode = high - low,
code = sample - low;
2114 uint32_t extras = (1 << bitcount) - maxcode - 1;
2116 if (code < extras) {
2146 for (i = 0; i < nb_samples; i++) {
2147 put_sbits(pb, sent_bits, samples_l[i] >> pre_shift);
2150 for (i = 0; i < nb_samples; i++) {
2151 put_sbits(pb, sent_bits, samples_l[i] >> pre_shift);
2152 put_sbits(pb, sent_bits, samples_r[i] >> pre_shift);
2177 shift_count = max_exp ? max_exp - 1 : 0;
2181 if (shift_count < 25)
2182 value >>= shift_count;
2203 }
else if (shift_count) {
2219 for (i = 0; i < nb_samples; i++)
2222 for (i = 0; i < nb_samples; i++) {
2235 switch (dpp->
value) {
2237 for (i = 0; i < nb_samples; i++) {
2252 for (i = 0; i < nb_samples; i++) {
2267 for (m = 0, k = dpp->
value & (
MAX_TERM - 1), i = 0; i < nb_samples; i++) {
2290 m = (m + 1) & (MAX_TERM - 1);
2295 for (i = 0; i < nb_samples; i++) {
2307 for (i = 0; i < nb_samples; i++) {
2319 for (i = 0; i < nb_samples; i++) {
2337 #define update_weight_d2(weight, delta, source, result) \ 2338 if (source && result) \ 2339 weight -= (((source ^ result) >> 29) & 4) - 2; 2341 #define update_weight_clip_d2(weight, delta, source, result) \ 2342 if (source && result) { \ 2343 const int32_t s = (source ^ result) >> 31; \ 2344 if ((weight = (weight ^ s) + (2 - s)) > 1024) weight = 1024; \ 2345 weight = (weight ^ s) - s; \ 2354 switch (dpp->
value) {
2356 for (i = 0; i < nb_samples; i++) {
2371 for (i = 0; i < nb_samples; i++) {
2386 for (m = 0, k = dpp->
value & (
MAX_TERM - 1), i = 0; i < nb_samples; i++) {
2410 m = (m + 1) & (MAX_TERM - 1);
2415 for (i = 0; i < nb_samples; i++) {
2427 for (i = 0; i < nb_samples; i++) {
2439 for (i = 0; i < nb_samples; i++) {
2462 bytestream2_put_byte(pb, flags);
2463 bytestream2_put_byte(pb, (size + 1) >> 1);
2470 int block_size, start,
end, data_size, tcount,
temp, m = 0;
2472 uint32_t crc = 0xffffffff
u;
2482 for (i = 0; i < nb_samples; i++) {
2483 lor |= samples_l[
i] | samples_r[
i];
2484 diff |= samples_l[
i] - samples_r[
i];
2490 if (i == nb_samples && lor && !
diff) {
2515 if ((mag -= shift) < 0)
2530 got_extra =
scan_float(s, samples_l, samples_r, nb_samples);
2532 got_extra =
scan_int32(s, samples_l, samples_r, nb_samples);
2535 scan_int23(s, samples_l, samples_r, nb_samples);
2546 ret =
wv_mono(s, samples_l, 1, 0);
2548 ret =
wv_stereo(s, samples_l, samples_r, 1, 0);
2553 for (i = 0; i < nb_samples; i++)
2554 crc += (crc << 1) + samples_l[
i];
2559 for (i = 0; i < nb_samples; i++)
2560 crc += (crc << 3) + ((uint32_t)samples_l[i] << 1) + samples_l[
i] + samples_r[
i];
2577 bytestream2_put_le32(&pb,
MKTAG(
'w',
'v',
'p',
'k'));
2578 bytestream2_put_le32(&pb, 0);
2579 bytestream2_put_le16(&pb, 0x410);
2580 bytestream2_put_le16(&pb, 0);
2581 bytestream2_put_le32(&pb, 0);
2583 bytestream2_put_le32(&pb, nb_samples);
2584 bytestream2_put_le32(&pb, s->
flags);
2585 bytestream2_put_le32(&pb, crc);
2593 bytestream2_put_byte(&pb, 0);
2599 bytestream2_put_byte(&pb, 0);
2605 bytestream2_put_byte(&pb, ((dpp->
value + 5) & 0x1f) | ((dpp->
delta << 5) & 0xe0));
2608 bytestream2_put_byte(&pb, 0);
2610 #define WRITE_DECWEIGHT(type) do { \ 2611 temp = store_weight(type); \ 2612 bytestream2_put_byte(&pb, temp); \ 2613 type = restore_weight(temp); \ 2617 bytestream2_put_byte(&pb, 0);
2619 for (i = s->
num_terms - 1; i >= 0; --i) {
2639 out[start - 1] = (end - start + 1) >> 1;
2640 if ((end - start) & 1)
2641 bytestream2_put_byte(&pb, 0);
2643 #define WRITE_DECSAMPLE(type) do { \ 2644 temp = log2s(type); \ 2645 type = wp_exp2(temp); \ 2646 bytestream2_put_le16(&pb, temp); \ 2650 bytestream2_put_byte(&pb, 0);
2662 }
else if (dpp->
value < 0) {
2666 for (j = 0; j < dpp->
value; j++) {
2678 out[start - 1] = (end - start) >> 1;
2680 #define WRITE_CHAN_ENTROPY(chan) do { \ 2681 for (i = 0; i < 3; i++) { \ 2682 temp = wp_log2(s->w.c[chan].median[i]); \ 2683 bytestream2_put_le16(&pb, temp); \ 2684 s->w.c[chan].median[i] = wp_exp2(temp); \ 2698 bytestream2_put_byte(&pb, 127);
2710 for (i = 0; i < nb_samples; i++) {
2734 samples_l[
i] =
code;
2748 m = (m + 1) & (MAX_TERM - 1);
2754 for (i = 0; i < nb_samples; i++)
2755 samples_r[i] += ((samples_l[i] -= samples_r[i]) >> 1);
2770 for (i = 0; i < nb_samples; i++)
2773 for (i = 0; i < nb_samples; i++) {
2781 bytestream2_put_le24(&pb, (data_size + 1) >> 1);
2784 bytestream2_put_byte(&pb, 0);
2795 bytestream2_put_le24(&pb, (data_size + 5) >> 1);
2796 bytestream2_put_le32(&pb, s->
crc_x);
2799 bytestream2_put_byte(&pb, 0);
2803 AV_WL32(out + 4, block_size - 8);
2816 #define COPY_SAMPLES(type, offset, shift) do { \ 2817 const type *sptr = (const type *)src; \ 2818 for (i = 0; i < nb_samples; i++) \ 2819 dst[i] = (sptr[i] - offset) >> shift; \ 2835 memcpy(dst, src, nb_samples * 4);
2843 for (i = 0; i < 15; i++) {
2896 buf, buf_size)) < 0)
2907 *got_packet_ptr = 1;
2922 for (i = 0; i < 2; i++) {
2945 #define OFFSET(x) offsetof(WavPackEncodeContext, x) 2946 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM 2966 .priv_class = &wavpack_encoder_class,
#define WRITE_DECWEIGHT(type)
#define FF_COMPRESSION_DEFAULT
static int shift(int a, int b)
This structure describes decoded (raw) audio or video 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)
const char * av_default_item_name(void *ptr)
Return the context name.
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 AV_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.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
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)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
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 u(width, name, range_min, range_max)
#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 av_always_inline int wp_log2(uint32_t val)
static const AVOption options[]
static void reverse_mono_decorr(struct Decorr *dpp)
int32_t * sampleptrs[MAX_TERMS+2][2]
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
#define EXTRA_ADJUST_DELTAS
static av_always_inline int bytestream2_get_bytes_left_p(PutByteContext *p)
#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)
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)
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller 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]
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)
Libavcodec external API header.
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 flags(name, subs,...)
#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 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]
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)
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...