ref: b3756709ad18f2da42a7cbc97daca012256eb542
parent: e6586d21fad18d4cd4b72c8ff0f870db8ccbcbe6
author: Jean-Marc Valin <[email protected]>
date: Fri Feb 8 06:50:17 EST 2008
Fixed incorrect assumption about the number of bytes returned by the entropy coder. All testcases pass again.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -343,13 +343,9 @@
{
unsigned char *data;
int nbBytes = ec_byte_bytes(&st->buf);
- if (nbBytes != nbCompressedBytes)
+ if (nbBytes > nbCompressedBytes)
{
- if (nbBytes > nbCompressedBytes)
- celt_warning("got too many bytes");
- else
- celt_warning("not enough bytes");
- celt_warning_int ("output bytes:", nbBytes);
+ celt_warning_int ("got too many bytes:", nbBytes);
return CELT_INTERNAL_ERROR;
}
//printf ("%d\n", *nbBytes);
@@ -356,6 +352,8 @@
data = ec_byte_get_buffer(&st->buf);
for (i=0;i<nbBytes;i++)
compressed[i] = data[i];
+ for (;i<nbCompressedBytes;i++)
+ compressed[i] = 0;
}
/* Reset the packing for the next encoding */
ec_byte_reset(&st->buf);
--- a/tests/ectest.c
+++ b/tests/ectest.c
@@ -118,8 +118,13 @@
}
tell_bits = ec_enc_tell(&enc, 0);
ec_enc_done(&enc);
+ if ((tell_bits+7)/8 < ec_byte_bytes(&buf))
+ {
+ fprintf (stderr, "tell() lied, there's %d bytes instead of %d\n",
+ ec_byte_bytes(&buf), (tell_bits+7)/8);
+ }
tell_bits -= 8*ec_byte_bytes(&buf);
- if (tell_bits > 0 || tell_bits < -7)
+ if (tell_bits > 8)
{
printf ("tell() failed with %d bit offset\n", tell_bits);
return -1;