shithub: opus

Download patch

ref: 949a29bf0c7305bd79021815a06123b343972743
parent: 50cf82f7abebea4f46c296e674820eb04d0551fd
author: Jean-Marc Valin <[email protected]>
date: Sat Jul 25 16:16:01 EDT 2009

Raw bits encoding/decoding functions renamed to *_raw() and re-introducing
original ec_encode_bin()/ec_decode_bin() to optimize performance when ft is
a power of two.

--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -128,13 +128,13 @@
   unsigned  ft;
   t=0;
   while(_ftb>EC_UNIT_BITS){
-    s=ec_decode_bin(_this,EC_UNIT_BITS);
+    s=ec_decode_raw(_this,EC_UNIT_BITS);
     /*ec_dec_update(_this,s,s+1,EC_UNIT_MASK+1);*/
     t=t<<EC_UNIT_BITS|s;
     _ftb-=EC_UNIT_BITS;
   }
   ft=1U<<_ftb;
-  s=ec_decode_bin(_this,_ftb);
+  s=ec_decode_raw(_this,_ftb);
   /*ec_dec_update(_this,s,s+1,ft);*/
   t=t<<_ftb|s;
   return t;
--- a/libcelt/entdec.h
+++ b/libcelt/entdec.h
@@ -78,7 +78,9 @@
            up to and including the one encoded is fh, then the returned value
            will fall in the range [fl,fh).*/
 unsigned ec_decode(ec_dec *_this,unsigned _ft);
-unsigned ec_decode_bin(ec_dec *_this,unsigned bits);
+unsigned ec_decode_bin(ec_dec *_this,unsigned _bits);
+unsigned ec_decode_raw(ec_dec *_this,unsigned bits);
+
 /*Advance the decoder past the next symbol using the frequency information the
    symbol was encoded with.
   Exactly one call to ec_decode() must have been made so that all necessary
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -131,11 +131,11 @@
   while(_ftb>EC_UNIT_BITS){
     _ftb-=EC_UNIT_BITS;
     fl=(unsigned)(_fl>>_ftb)&EC_UNIT_MASK;
-    ec_encode_bin(_this,fl,fl+1,EC_UNIT_BITS);
+    ec_encode_raw(_this,fl,fl+1,EC_UNIT_BITS);
   }
   ft=1<<_ftb;
   fl=(unsigned)_fl&ft-1;
-  ec_encode_bin(_this,fl,fl+1,_ftb);
+  ec_encode_raw(_this,fl,fl+1,_ftb);
 }
 
 void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
--- a/libcelt/entenc.h
+++ b/libcelt/entenc.h
@@ -78,7 +78,8 @@
         decoded value will fall.
   _ft: The sum of the frequencies of all the symbols*/
 void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft);
-void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits);
+void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits);
+void ec_encode_raw(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits);
 /*Encodes a sequence of raw bits in the stream.
   _fl:  The bits to encode.
   _ftb: The number of bits to encode.
--- a/libcelt/laplace.c
+++ b/libcelt/laplace.c
@@ -84,7 +84,7 @@
       fl = 0;
    if (s)
       fl += fs;
-   ec_encode(enc, fl, fl+fs, ft);
+   ec_encode_bin(enc, fl, fl+fs, 15);
 }
 
 void ec_laplace_encode(ec_enc *enc, int *value, int decay)
@@ -102,7 +102,7 @@
    fl = 0;
    ft = 32768;
    fh = fs;
-   fm = ec_decode(dec, ft);
+   fm = ec_decode_bin(dec, 15);
    while (fm >= fh && fs != 0)
    {
       fl = fh;
--- a/libcelt/rangedec.c
+++ b/libcelt/rangedec.c
@@ -154,15 +154,14 @@
   return _ft-EC_MINI(s+1,_ft);
 }
 
-unsigned ec_decode_bin(ec_dec *_this,unsigned bits){
-#if 0
+unsigned ec_decode_bin(ec_dec *_this,unsigned _bits){
    unsigned s;
-   ec_uint32 ft;
-   ft = (ec_uint32)1<<bits;
-   _this->nrm=_this->rng>>bits;
+   _this->nrm=_this->rng>>_bits;
    s=(unsigned)((_this->dif-1)/_this->nrm);
-   return ft-EC_MINI(s+1,ft);
-#else
+   return (1<<_bits)-EC_MINI(s+1,1<<_bits);
+}
+
+unsigned ec_decode_raw(ec_dec *_this,unsigned bits){
   unsigned value=0;
   int count=0;
   _this->nb_end_bits += bits;
@@ -177,7 +176,6 @@
   value |= ((_this->end_byte>>(8-_this->end_bits_left))&((1<<bits)-1))<<count;
   _this->end_bits_left -= bits;
   return value;
-#endif
 }
 
 void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
--- a/libcelt/rangeenc.c
+++ b/libcelt/rangeenc.c
@@ -127,18 +127,18 @@
   ec_enc_normalize(_this);
 }
 
-void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
-#if 0
-   ec_uint32 r, ft;
-   r=_this->rng>>bits;
-   ft = (ec_uint32)1<<bits;
+void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){
+   ec_uint32 r;
+   r=_this->rng>>_bits;
    if(_fl>0){
-     _this->low+=_this->rng-IMUL32(r,(ft-_fl));
-     _this->rng=IMUL32(r,(_fh-_fl));
+      _this->low+=_this->rng-IMUL32(r,((1<<_bits)-_fl));
+      _this->rng=IMUL32(r,(_fh-_fl));
    }
-   else _this->rng-=IMUL32(r,(ft-_fh));
+   else _this->rng-=IMUL32(r,((1<<_bits)-_fh));
    ec_enc_normalize(_this);
-#else
+}
+
+void ec_encode_raw(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned bits){
   _this->nb_end_bits += bits;
   while (bits >= _this->end_bits_left)
   {
@@ -151,7 +151,6 @@
   }
   _this->end_byte |= (_fl<<(8-_this->end_bits_left)) & 0xff;
   _this->end_bits_left -= bits;
-#endif
 }
 
 long ec_enc_tell(ec_enc *_this,int _b){