ref: 283a9b606dcbbf03e651c257009e02201b8cc714
parent: b2f59009f6a1ef5b9faba6c9e256bbee65f8f9f7
author: Timothy B. Terriberry <[email protected]>
date: Wed Dec 15 00:35:54 EST 2010
Don't stop force-skipping on the first manually skipped band. Now that manual skipping is in the same loop as forced skipping, there is no reason to do all of one, then all of the other. This ensures we won't propagate bits to bands that have almost nothing later in quant_all_bands() because we didn't have enough bits to signal them skipped.
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -152,7 +152,6 @@
int codedBands=-1;
int alloc_floor;
int left, percoeff;
- int force_skipping;
int done;
SAVE_STACK;
@@ -204,9 +203,11 @@
psum += tmp;
}
- force_skipping = 1;
+ /*Decide which bands to skip, working backwards from the end.
+ The loop condition stops before the first band, which we never skip: we'd
+ be coding a bit to signal that we're going to waste all the other bits.*/
codedBands=end;
- for (j=end;j-->start;)
+ for (j=end;--j>start;)
{
int band_width;
int band_bits;
@@ -219,20 +220,12 @@
rem = IMAX(left-m->eBands[j],0);
band_width = m->eBands[codedBands]-m->eBands[j];
band_bits = bits[j] + percoeff*band_width + rem;
- /*As long as, even after adding these bits, we're below the threshold for
- this band, it is force-skipped.*/
- force_skipping = force_skipping && band_bits < thresh[j];
- if (!force_skipping)
+ /*Only code a skip decision if we're above the threshold for this band.
+ Otherwise it is force-skipped.
+ This ensures that a) we have enough bits to code the skip flag and b)
+ there are actually some bits to redistribute.*/
+ if (band_bits >= IMAX(thresh[j], alloc_floor+(1<<BITRES)+1))
{
- /*Never skip the first band: we'd be coding a bit to signal that we're
- going to waste all of the other bits.*/
- if (j<=start)break;
- /*If we have enough for the fine energy, but not more than a full
- bit beyond that, or no more than one bit total, then don't bother
- skipping this band: there's no extra bits to redistribute.*/
- if ((band_bits>=alloc_floor && band_bits<=alloc_floor+(1<<BITRES))
- || band_bits<(1<<BITRES))
- break;
if (encode)
{
/*This if() block is the only part of the allocation function that