shithub: opus

Download patch

ref: d85018cb54bee95570502d0b76d5af66a14ccf77
parent: 5677e34fdeca736f5894f01f0099629e823e8608
author: Gregory Maxwell <[email protected]>
date: Thu Jan 13 09:38:24 EST 2011

In CVBR mode the rate selection was failing to add bytes which were about to fall off the end of the bitres and never be reusable, causing undershoot.

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -1163,11 +1163,9 @@
      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);
+     nbAvailableBytes = IMAX(min_allowed,nbAvailableBytes);
+     nbAvailableBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes) - nbFilledBytes;
 
-     nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes);
-     nbAvailableBytes = nbCompressedBytes - nbFilledBytes;
-
      target=nbAvailableBytes<<(BITRES+3);
 
      if (st->vbr_count < 970)
@@ -1194,6 +1192,7 @@
         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);