Add ec_enc_tellf, which can return the number of bits used to fractional precision.

git-svn-id: http://svn.xiph.org/trunk/ghost@14393 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
tterribe 2008-01-11 05:12:17 +00:00 committed by Jean-Marc Valin
parent 06390d082d
commit fad779ca56
4 changed files with 63 additions and 4 deletions

View file

@ -104,6 +104,31 @@ long ec_enc_tell(ec_enc *_this){
return nbits;
}
long ec_enc_tellf(ec_enc *_this,int _b){
ec_uint32 r;
int l;
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;
nbits<<=_b;
l=EC_ILOG(_this->rng);
r=_this->rng>>l-16;
while(_b-->0){
int b;
r=r*r>>15;
b=(int)(r>>16);
l=l<<1|b;
r>>=b;
}
return nbits-l;
}
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.