shithub: opus

Download patch

ref: 6619a736376221f2782cecff55d051c3ecfc2ff7
parent: 92c896e8806ec34c826e638512f7e33f1c9edcd0
author: Timothy B. Terriberry <[email protected]>
date: Tue Nov 29 03:03:03 EST 2011

Move nbits_total initialize before renormalization.

The range decoder used to initialize nbits_total after the
 renormalization loop, even though the renormalization loop
 modifies it.
This was presumably safe, because nothing actually used the value
 before it was initialized, but I'm tired of it triggering the
 integer overflow checking.

--- a/celt/entdec.c
+++ b/celt/entdec.c
@@ -126,6 +126,11 @@
   _this->end_offs=0;
   _this->end_window=0;
   _this->nend_bits=0;
+  /*This is the offset from which ec_tell() will subtract partial bits.
+    The final value after the ec_dec_normalize() call will be the same as in
+     the encoder, but we have to compensate for the bits that are added there.*/
+  _this->nbits_total=EC_CODE_BITS+1
+   -((EC_CODE_BITS-EC_CODE_EXTRA)/EC_SYM_BITS)*EC_SYM_BITS;
   _this->offs=0;
   _this->rng=1U<<EC_CODE_EXTRA;
   _this->rem=ec_read_byte(_this);
@@ -133,10 +138,6 @@
   _this->error=0;
   /*Normalize the interval.*/
   ec_dec_normalize(_this);
-  /*This is the offset from which ec_tell() will subtract partial bits.
-    This must be after the initial ec_dec_normalize(), or you will have to
-     compensate for the bits that are read there.*/
-  _this->nbits_total=EC_CODE_BITS+1;
 }
 
 unsigned ec_decode(ec_dec *_this,unsigned _ft){
--- a/doc/draft-ietf-codec-opus.xml
+++ b/doc/draft-ietf-codec-opus.xml
@@ -1344,8 +1344,8 @@
  have been processed by the decoder so far in the variable nbits_total,
  including the (possibly fractional) number of bits that are currently
  buffered, but not consumed, inside the range coder.
-nbits_total is initialized to 33 just after the initial range renormalization
- process completes (or equivalently, it can be initialized to 9 before the
+nbits_total is initialized to 9 just before the initial range renormalization
+ process completes (or equivalently, it can be initialized to 33 after the
  first renormalization).
 The extra two bits over the actual amount buffered by the range coder
  guarantees that it is an upper bound and that there is enough room for the