Fixed incorrect assumption about the number of bytes returned by the
authorJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Fri, 8 Feb 2008 00:50:17 +0000 (11:50 +1100)
committerJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Fri, 8 Feb 2008 00:50:17 +0000 (11:50 +1100)
entropy coder. All testcases pass again.

libcelt/celt.c
tests/ectest.c

index 804782e..bf81354 100644 (file)
@@ -343,19 +343,17 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
    {
       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);
       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);
index 41fd047..947afae 100644 (file)
@@ -118,8 +118,13 @@ int main(int _argc,char **_argv){
     }
     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;