shithub: opus

Download patch

ref: 8852563a2ece33b2e17c03ba508d3ede96e4b9a9
parent: 8200b2d16cde223df0b18c26b9ca82d733c4ee45
author: Jean-Marc Valin <[email protected]>
date: Fri Oct 15 06:24:53 EDT 2010

Unb0rked the VBR code: several units issues that made VBR completely useless

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -940,7 +940,7 @@
      target=target+st->vbr_offset-(50<<BITRES)+ec_enc_tell(enc, BITRES);
 
      /* In VBR mode the frame size must not be reduced so much that it would result in the coarse energy busting its budget */
-     target=IMIN(nbAvailableBytes,target);
+     target=IMIN(nbAvailableBytes<<(BITRES+3),target);
      /* Make the adaptation coef (alpha) higher at the beginning */
      if (st->vbr_count < 990)
      {
@@ -951,7 +951,7 @@
         alpha = QCONST16(.001f,15);
 
      /* By how much did we "miss" the target on that frame */
-     delta = (8<<BITRES)*(celt_int32)target - vbr_rate;
+     delta = (celt_int32)target - vbr_rate;
      /* How many bits have we used in excess of what we're allowed */
      st->vbr_reservoir += delta;
      /*printf ("%d\n", st->vbr_reservoir);*/
@@ -970,8 +970,8 @@
         target += adjust;
         /*printf ("+%d\n", adjust);*/
      }
-     if (target < nbAvailableBytes)
-        nbAvailableBytes = target;
+     if (nbAvailableBytes > target>>(BITRES+3))
+        nbAvailableBytes = target>>(BITRES+3);
      nbCompressedBytes = nbAvailableBytes + nbFilledBytes;
 
      /* This moves the raw bits to take into account the new compressed size */