ref: 4777f06910a16654e8091fb1ebfd9cb9308de498
parent: 283a9b606dcbbf03e651c257009e02201b8cc714
author: Timothy B. Terriberry <[email protected]>
date: Wed Dec 15 01:56:00 EST 2010
Store the total budget of compute_allocation in BITRES units. The margin of safety was supposed to be 1/8th bit, not 1 bit, and the bit we reserved to terminate skip signalling before was actually 8 bits. This patch updates the margin of safety to the correct value and accounts for the one bit (not 8) needed for skip signalling. It also fixes the remainder calculation in the skip loop to work correctly when start>0.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -1119,8 +1119,8 @@
ALLOC(pulses, st->mode->nbEBands, int);
ALLOC(fine_priority, st->mode->nbEBands, int);
- /* bits = packet size - where we are - safety */
- bits = nbCompressedBytes*8 - ec_enc_tell(enc, 0) - 1;
+ /* bits = packet size - where we are - safety - skip signalling*/
+ bits = (nbCompressedBytes*8<<BITRES) - ec_enc_tell(enc, BITRES) - 1 - (1<<BITRES);
codedBands = compute_allocation(st->mode, st->start, st->end, offsets,
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, enc, 1, st->lastCodedBands);
st->lastCodedBands = codedBands;
@@ -1856,7 +1856,7 @@
intensity = ec_dec_uint(dec, 1+st->end-st->start);
}
- bits = len*8 - ec_dec_tell(dec, 0) - 1;
+ bits = (len*8<<BITRES) - ec_dec_tell(dec, BITRES) - 1 - (1<<BITRES);
codedBands = compute_allocation(st->mode, st->start, st->end, offsets,
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, dec, 0, 0);
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -178,7 +178,7 @@
psum += alloc_floor;
}
}
- if (psum > (total<<BITRES))
+ if (psum > total)
hi = mid;
else
lo = mid;
@@ -214,10 +214,10 @@
int rem;
/*Figure out how many left-over bits we would be adding to this band.
This can include bits we've stolen back from higher, skipped bands.*/
- left = (total<<BITRES)-psum;
+ left = total-psum;
percoeff = left/(m->eBands[codedBands]-m->eBands[start]);
left -= (m->eBands[codedBands]-m->eBands[start])*percoeff;
- rem = IMAX(left-m->eBands[j],0);
+ rem = IMAX(left-(m->eBands[j]-m->eBands[start]),0);
band_width = m->eBands[codedBands]-m->eBands[j];
band_bits = bits[j] + percoeff*band_width + rem;
/*Only code a skip decision if we're above the threshold for this band.
@@ -379,7 +379,7 @@
/*printf ("%d ", bits[j]);*/
}
/*printf ("\n");*/
- if (psum > (total<<BITRES))
+ if (psum > total)
hi = mid;
else
lo = mid;