From 43e940620151128e0cea9f05ee9ec58d1d64c93f Mon Sep 17 00:00:00 2001 From: "Timothy B. Terriberry" Date: Sat, 29 May 2010 23:02:33 -0400 Subject: [PATCH] Change ec_{enc|dec}_bit_prob to take probabilities in units of 1/65536 instead of 1/256. This allows them to use a single 16x16->32 multiply instead of a 24x8->32 multiply. Also change the time-frequency resolution flag coding to ensure that "0" is always the most-probable symbol (i.e., that prob("1")<50%), as that's where all the rounding error accumulates. --- libcelt/celt.c | 8 ++++---- libcelt/entdec.h | 4 ++-- libcelt/entenc.h | 4 ++-- libcelt/rangedec.c | 6 +++--- libcelt/rangeenc.c | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index 2613b5af..559720bf 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -615,11 +615,11 @@ static void tf_encode(celt_word16 *bandLogE, celt_word16 *oldBandE, int len, int else tf_res[i] = path0[i+1]; } - ec_enc_bit_prob(enc, tf_res[0], isTransient ? 64 : 16); + ec_enc_bit_prob(enc, tf_res[0], isTransient ? 16384 : 4096); curr = tf_res[0]; for (i=1;irng; d=_this->dif; - s=IMUL32(r>>8,_prob); + s=(r>>16)*_prob; val=d<=s; if(!val)_this->dif=d-s; _this->rng=val?s:r-s; diff --git a/libcelt/rangeenc.c b/libcelt/rangeenc.c index f7f171ba..68ff6c4a 100644 --- a/libcelt/rangeenc.c +++ b/libcelt/rangeenc.c @@ -138,14 +138,14 @@ void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){ ec_enc_normalize(_this); } -/*The probability of having a "one" is given in 1/256.*/ -void ec_enc_bit_prob(ec_enc *_this,int _val,int _prob){ +/*The probability of having a "one" is given in 1/65536.*/ +void ec_enc_bit_prob(ec_enc *_this,int _val,unsigned _prob){ ec_uint32 r; ec_uint32 s; ec_uint32 l; r=_this->rng; l=_this->low; - s=IMUL32(r>>8,_prob); + s=(r>>16)*_prob; r-=s; if(_val)_this->low=l+r; _this->rng=_val?s:r;