Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/celt-0.7.0.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2009-10-22 08:12:31 +0400
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2009-10-22 08:13:44 +0400
commit45f111058301102d1244a03b67110a8f0c45b89a (patch)
tree3dbdc4dc4c71e2d96b63caa42f98fe99a2d0f296
parent25767d1ca7fbbb7160a1db1bc6a034903185a672 (diff)
Making sure the VBR controller never busts the number of bytes allowed
-rw-r--r--libcelt/celt.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libcelt/celt.c b/libcelt/celt.c
index cb53ff7..6f050f0 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<<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 @@ 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<<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);
}