From d85018cb54bee95570502d0b76d5af66a14ccf77 Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Thu, 13 Jan 2011 14:38:24 -0500 Subject: [PATCH] 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. --- libcelt/celt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index 4c088e3a..c623f39f 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -1163,10 +1163,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i min_allowed = (tell+total_boost+(1<>(BITRES+3)) + 2 - nbFilledBytes; nbAvailableBytes = target+(1<<(BITRES+2))>>(BITRES+3); - nbAvailableBytes=IMAX(min_allowed,nbAvailableBytes); - - nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes); - nbAvailableBytes = nbCompressedBytes - nbFilledBytes; + nbAvailableBytes = IMAX(min_allowed,nbAvailableBytes); + nbAvailableBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes) - nbFilledBytes; target=nbAvailableBytes<<(BITRES+3); @@ -1194,6 +1192,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i 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);