diff --git a/libcelt/celt.c b/libcelt/celt.c index 26849ac2..94cacce5 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -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<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<mode, st->start, st->end, offsets, alloc_trim, bits, pulses, fine_quant, fine_priority, C, LM, dec, 0, 0); diff --git a/libcelt/rate.c b/libcelt/rate.c index bd228651..c711fb4f 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -141,7 +141,7 @@ void compute_pulse_cache(CELTMode *m, int LM) #define ALLOC_STEPS 6 static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int skip_start, - const int *bits1, const int *bits2, const int *thresh, int total, int *bits, + const int *bits1, const int *bits2, const int *thresh, int total, int skip_rsv,int *bits, int *ebits, int *fine_priority, int len, int _C, int LM, void *ec, int encode, int prev) { int psum; @@ -216,13 +216,18 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int left = total-psum; percoeff = left/(m->eBands[codedBands]-m->eBands[start]); left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; - /* Never skip the first band: we'd be coding a bit to signal that we're - going to waste all the other bits. - This means we won't be using the extra bit we reserved to signal the - end of manual skipping, but that will get added back in by - quant_all_bands().*/ + /* Never skip the first band, nor a band that has been boosted by + dynalloc. + In the first case, we'd be coding a bit to signal we're going to waste + all the other bits. + In the second case, we'd be coding a bit to redistribute all the bits + we just signaled should be cocentrated in this band. */ if (j<=skip_start) + { + /* Give the bit we reserved to end skipping back to this band. */ + bits[j] += skip_rsv; break; + } 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; @@ -364,6 +369,7 @@ int compute_allocation(const CELTMode *m, int start, int end, const int *offsets const int C = CHANNELS(_C); int codedBands; int skip_start; + int skip_rsv; VARDECL(int, bits1); VARDECL(int, bits2); VARDECL(int, thresh); @@ -373,6 +379,9 @@ int compute_allocation(const CELTMode *m, int start, int end, const int *offsets total = IMAX(total, 0); len = m->nbEBands; skip_start = start; + /* Reserve a bit to signal the end of manually skipped bands. */ + skip_rsv = total >= 1<