Provide direct implementations ec_{enc|dec}_bit_prob() that do not require a division instead of using the normal entropy coder path. This should be exactly equivalent to the existing code.

This commit is contained in:
Timothy B. Terriberry 2010-05-29 22:47:37 -04:00 committed by Jean-Marc Valin
parent 8cc945c53a
commit 299747ee24
5 changed files with 31 additions and 32 deletions

View file

@ -186,6 +186,22 @@ void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
ec_dec_normalize(_this);
}
/*The probability of having a "one" is given in 1/256.*/
int ec_dec_bit_prob(ec_dec *_this,int _prob){
ec_uint32 r;
ec_uint32 s;
ec_uint32 d;
int val;
r=_this->rng;
d=_this->dif;
s=IMUL32(r>>8,_prob);
val=d<=s;
if(!val)_this->dif=d-s;
_this->rng=val?s:r-s;
ec_dec_normalize(_this);
return val;
}
long ec_dec_tell(ec_dec *_this,int _b){
ec_uint32 r;
int l;