diff --git a/libcelt/celt.c b/libcelt/celt.c index fb86278b..44386d6d 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -782,10 +782,10 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si { if (transient_shift) { - ec_enc_bits(&enc, transient_shift, 2); + ec_enc_uint(&enc, transient_shift, 4); ec_enc_uint(&enc, transient_time, N+st->overlap); } else { - ec_enc_bits(&enc, mdct_weight_shift, 2); + ec_enc_uint(&enc, mdct_weight_shift, 4); if (mdct_weight_shift && st->mode->nbShortMdcts!=2) ec_enc_uint(&enc, mdct_weight_pos, st->mode->nbShortMdcts-1); } @@ -833,6 +833,7 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si /* In VBR mode the frame size must not be reduced so much that it would result in the coarse energy busting its budget */ target=IMAX(coarse_needed,(target+64)/128); nbCompressedBytes=IMIN(nbCompressedBytes,target); + ec_byte_shrink(&buf, nbCompressedBytes); } ALLOC(offsets, st->mode->nbEBands, int); @@ -1328,7 +1329,7 @@ int celt_decode_float(CELTDecoder * restrict st, const unsigned char *data, int decode_flags(&dec, &intra_ener, &has_pitch, &shortBlocks, &has_fold); if (shortBlocks) { - transient_shift = ec_dec_bits(&dec, 2); + transient_shift = ec_dec_uint(&dec, 4); if (transient_shift == 3) { transient_time = ec_dec_uint(&dec, N+st->mode->overlap); diff --git a/libcelt/entcode.h b/libcelt/entcode.h index 5148242c..57107d49 100644 --- a/libcelt/entcode.h +++ b/libcelt/entcode.h @@ -63,6 +63,7 @@ struct ec_byte_buffer{ /*Encoding functions.*/ void ec_byte_writeinit_buffer(ec_byte_buffer *_b, unsigned char *_buf, long _size); +void ec_byte_shrink(ec_byte_buffer *_b, long _size); void ec_byte_writeinit(ec_byte_buffer *_b); void ec_byte_writetrunc(ec_byte_buffer *_b,long _bytes); void ec_byte_write1(ec_byte_buffer *_b,unsigned _value); diff --git a/libcelt/entenc.c b/libcelt/entenc.c index 1ff10360..095170b2 100644 --- a/libcelt/entenc.c +++ b/libcelt/entenc.c @@ -47,6 +47,12 @@ void ec_byte_writeinit_buffer(ec_byte_buffer *_b, unsigned char *_buf, long _siz _b->resizable=0; } +void ec_byte_shrink(ec_byte_buffer *_b, long _size){ + _b->end_ptr=_b->buf+_size-1; + _b->storage=_size; + _b->resizable=0; +} + void ec_byte_writeinit(ec_byte_buffer *_b){ _b->ptr=_b->buf=celt_alloc(EC_BUFFER_INCREMENT*sizeof(char)); _b->storage=EC_BUFFER_INCREMENT;