ref: 45f111058301102d1244a03b67110a8f0c45b89a
parent: 25767d1ca7fbbb7160a1db1bc6a034903185a672
author: Jean-Marc Valin <[email protected]>
date: Wed Oct 21 20:12:31 EDT 2009
Making sure the VBR controller never busts the number of bytes allowed
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -802,7 +802,7 @@
/* In VBR mode the frame size must not be reduced so much that it would result in the coarse energy busting its budget */
target=IMAX(coarse_needed,(target+64)/128);
- nbCompressedBytes=IMIN(nbCompressedBytes,target);
+ target=IMIN(nbCompressedBytes,target);
/* Make the adaptation coef (alpha) higher at the beginning */
if (st->vbr_count < 990)
{
@@ -813,7 +813,7 @@
alpha = QCONST16(.001f,15);
/* By how much did we "miss" the target on that frame */
- delta = (8<<BITRES)*(celt_int32)nbCompressedBytes - st->vbr_rate;
+ delta = (8<<BITRES)*(celt_int32)target - st->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);*/
@@ -829,10 +829,11 @@
/* We're under the min value -- increase rate */
int adjust = 1-(st->vbr_reservoir-1)/(8<<BITRES);
st->vbr_reservoir += adjust*(8<<BITRES);
- nbCompressedBytes += adjust;
+ target += adjust;
/*printf ("+%d\n", adjust);*/
}
-
+ if (target < nbCompressedBytes)
+ nbCompressedBytes = target;
/* This moves the raw bits to take into account the new compressed size */
ec_byte_shrink(&buf, nbCompressedBytes);
}