Move skip coding into interp_bits2pulses().

This allows us to a) not pay a coding cost to avoid skipping bands that are
 stupid to skip (e.g., the first band, or bands that have so few bits that we
 wouldn't redistribute anything) and b) not reserve bits to pay that cost.
This commit is contained in:
Timothy B. Terriberry 2010-12-15 05:12:43 -08:00 committed by Jean-Marc Valin
parent 7cbf168c01
commit b2f59009f6
3 changed files with 26 additions and 41 deletions

View file

@ -752,7 +752,6 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
int intensity=0;
int dual_stereo=0;
int effectiveBytes;
int skip;
SAVE_STACK;
if (nbCompressedBytes<0 || pcm==NULL)
@ -1120,15 +1119,11 @@ 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 - ec_enc_tell(enc, 0) - 1 - (1<<BITRES);
skip=-1;
/* bits = packet size - where we are - safety */
bits = nbCompressedBytes*8 - ec_enc_tell(enc, 0) - 1;
codedBands = compute_allocation(st->mode, st->start, st->end, offsets,
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, &skip, st->lastCodedBands);
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, enc, 1, st->lastCodedBands);
st->lastCodedBands = codedBands;
for (i=0;i<skip;i++)
ec_enc_bit_prob(enc, 0, 32768);
ec_enc_bit_prob(enc, 1, 32768);
quant_fine_energy(st->mode, st->start, st->end, bandE, oldBandE, error, fine_quant, enc, C);
@ -1728,7 +1723,6 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
celt_word16 postfilter_gain;
int intensity=0;
int dual_stereo=0;
int skip;
SAVE_STACK;
if (pcm==NULL)
@ -1862,19 +1856,9 @@ 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 - ec_dec_tell(dec, 0) - 1 - (1<<BITRES);
skip=0;
while (ec_dec_bit_prob(dec, 32768)==0)
{
skip++;
if (skip>21)
{
dec->error = 1;
break;
}
}
bits = len*8 - ec_dec_tell(dec, 0) - 1;
codedBands = compute_allocation(st->mode, st->start, st->end, offsets,
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, &skip, 0);
alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, dec, 0, 0);
unquant_fine_energy(st->mode, st->start, st->end, bandE, oldBandE, fine_quant, dec, C);