Replace ec_{enc|dec}_bit_prob() with ec_{enc|dec}_bit_logp().

All of our usage of ec_{enc|dec}_bit_prob had the probability of a
 "one" being a power of two.
This adds a new ec_{enc|dec}_bit_logp() function that takes this
 explicitly into account.
It introduces less rounding error than the bit_prob version, does not
 require 17-bit integers to be emulated by ec_{encode|decode}_bin(),
 and does not require any multiplies or divisions at all.
It is exactly equivalent to
 ec_encode_bin(enc,_val?0:(1<<_logp)-1,(1<<_logp)-(_val?1:0),1<<_logp)

The old ec_{enc|dec}_bit_prob functions are left in place for now,
 because I am not sure if SILK is still using them or not when
 combined in Opus.
This commit is contained in:
Timothy B. Terriberry 2010-12-17 14:50:19 -08:00 committed by Jean-Marc Valin
parent 8c23a3a0fd
commit e86fb268b0
8 changed files with 61 additions and 25 deletions

View file

@ -190,8 +190,8 @@ void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
/*The probability of having a "one" is given in 1/65536.*/
int ec_dec_bit_prob(ec_dec *_this,unsigned _prob){
ec_uint32 r;
ec_uint32 s;
ec_uint32 d;
ec_uint32 s;
int val;
r=_this->rng;
d=_this->dif;
@ -203,6 +203,22 @@ int ec_dec_bit_prob(ec_dec *_this,unsigned _prob){
return val;
}
/*The probability of having a "one" is 1/(1<<_logp).*/
int ec_dec_bit_logp(ec_dec *_this,unsigned _logp){
ec_uint32 r;
ec_uint32 d;
ec_uint32 s;
int val;
r=_this->rng;
d=_this->dif;
s=r>>_logp;
val=d<s;
if(!val)_this->dif=d-s;
_this->rng=val?s:r-s;
ec_dec_normalize(_this);
return val;
}
int ec_dec_cdf(ec_dec *_this,const int *_cdf,unsigned _ftb){
ec_uint32 r;
ec_uint32 d;