From 45f111058301102d1244a03b67110a8f0c45b89a Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 22 Oct 2009 00:12:31 -0400 Subject: [PATCH] Making sure the VBR controller never busts the number of bytes allowed --- libcelt/celt.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index cb53ff7b..6f050f0f 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -802,7 +802,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig /* 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 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig alpha = QCONST16(.001f,15); /* By how much did we "miss" the target on that frame */ - delta = (8<vbr_rate; + delta = (8<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 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig * pcm, celt_sig /* We're under the min value -- increase rate */ int adjust = 1-(st->vbr_reservoir-1)/(8<vbr_reservoir += adjust*(8<