Give the bit we reserved to end skipping back when we don't use it.

Commit 8e447678 increased the number of cases where we end skipping
 without explicit signaling.
Before, this would cause the bit we reserved for this purpose to
 either a) get grabbed by some N=1 band to code its sign bits or
 b) wind up as part of the fine energy at the end.
This patch gives it back to the band where we stopped skipping,
 which is either the first band, or a band that was boosted by
 dynalloc.
This allows the bit to be used for shape coding in that band, and
 allows the better computation of the fine offset, since the band
 knows it will get that bit in advance.

With this change, we now guarantee that the number of bits allocated
 by compute_allocation() is exactly equal to the input total, less
 the bits consumed by skip flags during allocation itself (assuming
 total was non-negative; for negative total, no bits are emitted,
 and no bits are allocated).
This commit is contained in:
Timothy B. Terriberry 2010-12-16 14:39:58 -08:00 committed by Jean-Marc Valin
parent 8e31ab3def
commit 76ea41e17f
2 changed files with 19 additions and 10 deletions

View file

@ -1119,8 +1119,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
ALLOC(pulses, st->mode->nbEBands, int);
ALLOC(fine_priority, st->mode->nbEBands, int);
/* bits = packet size - where we are - safety - skip signalling*/
bits = (nbCompressedBytes*8<<BITRES) - ec_enc_tell(enc, BITRES) - 1 - (1<<BITRES);
/* bits = packet size - where we are - safety */
bits = (nbCompressedBytes*8<<BITRES) - ec_enc_tell(enc, BITRES) - 1;
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 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
intensity = ec_dec_uint(dec, 1+st->end-st->start);
}
bits = (len*8<<BITRES) - ec_dec_tell(dec, BITRES) - 1 - (1<<BITRES);
bits = (len*8<<BITRES) - ec_dec_tell(dec, BITRES) - 1;
codedBands = compute_allocation(st->mode, st->start, st->end, offsets,
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, dec, 0, 0);