Add oc_enc_tell to report an estimate of the number of bits used so far.

Remove the special case for 0 in EC_ILOG, as we never pass it 0 and this
 generates slightly better code.

Update ec_enc_bits64 to split the encoded values along word boundaries...
 this should generate slightly better code, as well as fix a subtle bug (the
 proper bits were not being masked out of the low part).
However, this will render previous streams that used this function undecodable
 (to my knowledge, no one is actually using it yet).

git-svn-id: http://svn.xiph.org/trunk/ghost@14391 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
tterribe 2008-01-11 03:13:50 +00:00 committed by Jean-Marc Valin
parent 45018cbfa2
commit 06390d082d
7 changed files with 81 additions and 16 deletions

View file

@ -91,6 +91,19 @@ void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft){
ec_enc_normalize(_this);
}
long ec_enc_tell(ec_enc *_this){
long nbits;
nbits=ec_byte_bytes(_this->buf)+(_this->rem>=0)+_this->ext<<3;
/*To handle the non-integral number of bits still left in the encoder state,
we compute the number of bits of low that must be encoded to ensure that
the value is inside the range for any possible subsequent bits.
Note that this is subtly different than the actual value we would end the
stream with, which tries to make as many of the trailing bits zeros as
possible.*/
nbits+=EC_CODE_BITS-EC_ILOG(_this->rng);
return nbits;
}
void ec_enc_done(ec_enc *_this){
/*We compute the integer in the current interval that has the largest number
of trailing zeros, and write that to the stream.
@ -120,6 +133,7 @@ void ec_enc_done(ec_enc *_this){
unsigned char *buf;
/*Flush it into the output buffer.*/
ec_enc_carry_out(_this,0);
_this->rem=-1;
/*We may be able to drop some redundant bytes from the end.*/
buf=ec_byte_get_buffer(_this->buf);
p=buf+ec_byte_bytes(_this->buf)-1;