In CVBR mode the rate selection was failing to add bytes which were about to fall...
authorGregory Maxwell <greg@xiph.org>
Thu, 13 Jan 2011 19:38:24 +0000 (14:38 -0500)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Thu, 13 Jan 2011 21:31:50 +0000 (16:31 -0500)
libcelt/celt.c

index 4c088e3..c623f39 100644 (file)
@@ -1163,10 +1163,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
      min_allowed = (tell+total_boost+(1<<BITRES+3)-1>>(BITRES+3)) + 2 - nbFilledBytes;
 
      nbAvailableBytes = target+(1<<(BITRES+2))>>(BITRES+3);
      min_allowed = (tell+total_boost+(1<<BITRES+3)-1>>(BITRES+3)) + 2 - nbFilledBytes;
 
      nbAvailableBytes = target+(1<<(BITRES+2))>>(BITRES+3);
-     nbAvailableBytes=IMAX(min_allowed,nbAvailableBytes);
-
-     nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes);
-     nbAvailableBytes = nbCompressedBytes - nbFilledBytes;
+     nbAvailableBytes = IMAX(min_allowed,nbAvailableBytes);
+     nbAvailableBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes) - nbFilledBytes;
 
      target=nbAvailableBytes<<(BITRES+3);
 
 
      target=nbAvailableBytes<<(BITRES+3);
 
@@ -1194,6 +1192,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
         st->vbr_reservoir = 0;
         /*printf ("+%d\n", adjust);*/
      }
         st->vbr_reservoir = 0;
         /*printf ("+%d\n", adjust);*/
      }
+     nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes);
 
      /* This moves the raw bits to take into account the new compressed size */
      ec_byte_shrink(&buf, nbCompressedBytes);
 
      /* This moves the raw bits to take into account the new compressed size */
      ec_byte_shrink(&buf, nbCompressedBytes);