22 #define BITSTREAM_READER_LE
73 #define WV_MAX_FRAME_DECODERS 14
86 #define LEVEL_DECAY(a) (((a) + 0x80) >> 8)
95 e = (1 << (p + 1)) - k - 1;
112 int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
113 if (balance > br[0]) {
116 }
else if (-balance > br[0]) {
120 br[1] = br[0] + balance;
121 br[0] = br[0] - balance;
126 if (sl[i] - br[i] > -0x100)
137 int channel,
int *last)
140 int sign, base, add,
ret;
158 t =
get_bits(gb, t - 1) | (1 << (t - 1));
189 t +=
get_bits(gb, t2 - 1) | (1 << (t2 - 1));
203 if (ctx->
hybrid && !channel)
229 if (add >= 0x2000000U) {
237 int mid = (base * 2 + add + 1) >> 1;
245 add = mid - base - 1;
246 mid = (base * 2 + add + 1) >> 1;
253 return sign ? ~ret :
ret;
275 *crc = *crc * 9 + (S & 0xffff) * 3 + ((
unsigned)S >> 16);
279 bit = (S & s->
and) | s->
or;
280 bit = ((S + bit) << s->
shift) - bit;
299 const int max_bits = 1 + 23 + 8 + 1;
311 if (S >= 0x1000000) {
330 S |= (1 <<
shift) - 1;
356 *crc = *crc * 27 + S * 9 + exp * 3 + sign;
358 value.u = (sign << 31) | (exp << 23) |
S;
369 uint32_t crc_extra_bits)
384 void *dst_l,
void *dst_r,
const int type)
390 uint32_t crc = s->
sc.
crc;
392 int16_t *dst16_l = dst_l;
393 int16_t *dst16_r = dst_r;
396 float *dstfl_l = dst_l;
397 float *dstfl_r = dst_r;
407 for (i = 0; i < s->
terms; i++) {
439 }
else if (t == -1) {
477 L += (R -= (L >> 1));
478 crc = (crc * 3 +
L) * 3 + R;
509 void *dst,
const int type)
515 uint32_t crc = s->
sc.
crc;
517 int16_t *dst16 = dst;
527 for (i = 0; i < s->
terms; i++) {
629 void *samples_l = NULL, *samples_r = NULL;
631 int got_terms = 0, got_weights = 0, got_samples = 0,
632 got_entropy = 0, got_bs = 0, got_float = 0, got_hybrid = 0;
633 int i, j,
id,
size, ssize, weights, t;
634 int bpp, chan = 0, chmask = 0, orig_bpp,
sample_rate = 0;
642 s = wc->
fdec[block_no];
650 memset(s->
ch, 0,
sizeof(s->
ch));
657 s->
samples = bytestream2_get_le32(&gb);
676 s->
CRC = bytestream2_get_le32(&gb);
680 id = bytestream2_get_byte(&gb);
681 size = bytestream2_get_byte(&gb);
683 size |= (bytestream2_get_byte(&gb)) << 8;
684 size |= (bytestream2_get_byte(&gb)) << 16;
692 "Got incorrect block %02X with size %i\n",
id, size);
697 "Block size %i is out of bounds\n", size);
709 for (i = 0; i < s->
terms; i++) {
727 for (i = 0; i < weights; i++) {
728 t = (int8_t)bytestream2_get_byte(&gb);
734 t = (int8_t)bytestream2_get_byte(&gb);
749 for (i = s->
terms - 1; (i >= 0) && (t < size); i--) {
752 wp_exp2(bytestream2_get_le16(&gb));
754 wp_exp2(bytestream2_get_le16(&gb));
758 wp_exp2(bytestream2_get_le16(&gb));
760 wp_exp2(bytestream2_get_le16(&gb));
766 wp_exp2(bytestream2_get_le16(&gb));
768 wp_exp2(bytestream2_get_le16(&gb));
773 wp_exp2(bytestream2_get_le16(&gb));
776 wp_exp2(bytestream2_get_le16(&gb));
787 "Entropy vars size should be %i, got %i.\n",
793 for (i = 0; i < 3; i++) {
805 for (i = 0; i < (s->
stereo_in + 1); i++) {
810 for (i = 0; i < (s->
stereo_in + 1); i++) {
812 wp_exp2((int16_t)bytestream2_get_le16(&gb));
824 "Invalid INT32INFO, size = %i\n",
854 "Invalid FLOATINFO, size = %i\n", size);
891 "Insufficient channel information\n");
894 chan = bytestream2_get_byte(&gb);
897 chmask = bytestream2_get_byte(&gb);
900 chmask = bytestream2_get_le16(&gb);
903 chmask = bytestream2_get_le24(&gb);
906 chmask = bytestream2_get_le32(&gb);
909 size = bytestream2_get_byte(&gb);
912 " instead of %i.\n", size, avctx->
channels);
913 chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
914 chmask = bytestream2_get_le16(&gb);
928 sample_rate = bytestream2_get_le24(&gb);
953 if (s->
hybrid && !got_hybrid) {
1024 memcpy(samples_r, samples_l, bpp * s->
samples);
1040 int *got_frame_ptr,
AVPacket *avpkt)
1044 int buf_size = avpkt->
size;
1056 frame_flags =
AV_RL32(buf + 24);
1063 if (frame_flags & 0x80) {
1065 }
else if ((frame_flags & 0x03) <= 1) {
1072 while (buf_size > 0) {
1075 frame_size =
AV_RL32(buf + 4) - 12;
1078 if (frame_size <= 0 || frame_size > buf_size) {
1080 "Block %d has invalid size (size %d vs. %d bytes left)\n",
1081 s->
block, frame_size, buf_size);
1086 frame, buf, frame_size)) < 0) {