Commit e610864c authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

This fixes a VBR bug introduced by raw bits. We should not write any raw

bit before the rate is decided (otherwise they'll end up at the wrong place)
and we have to shrink the byte buffer before writing raw bits.
parent 91f07dc1
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment