shithub: opus

Download patch

ref: 9bac8c17d57ea99192de09f8b97300b3dee0422f
parent: 115fa35a9db045aefe77686edc0468b060ec42df
author: Timothy B. Terriberry <[email protected]>
date: Wed Mar 2 11:24:32 EST 2011

Eliminate the ec_int32 and ec_uint32 typedefs.

These were used because the entropy coder originally came from
 outside libcelt, and thus did not have a common type system.
It's now undergone enough modification that it's not ever likely to
 be used as-is in another codec without some porting effort, so
 there's no real reason to maintain the typedefs separately.
Hopefully we'll replace these all again somedate with a common set
 of Opus typedefs, but for now this will do.

This fixes an issue caused by commit 6c8acbf1, which moved the
 ec_ilog() prototype from entcode.h to ecintrin.h, where the
 ec_uint32 typedef was not yet available.
Thanks to John Ridges for the report.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -1161,7 +1161,7 @@
 void quant_all_bands(int encode, const CELTMode *m, int start, int end,
       celt_norm *_X, celt_norm *_Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses,
       int shortBlocks, int spread, int dual_stereo, int intensity, int *tf_res, int resynth,
-      celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int LM, int codedBands, ec_uint32 *seed)
+      celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int LM, int codedBands, celt_uint32 *seed)
 {
    int i;
    celt_int32 remaining_bits;
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -84,7 +84,7 @@
 void quant_all_bands(int encode, const CELTMode *m, int start, int end,
       celt_norm * X, celt_norm * Y, unsigned char *collapse_masks, const celt_ener *bandE, int *pulses,
       int time_domain, int fold, int dual_stereo, int intensity, int *tf_res, int resynth,
-      celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int M, int codedBands, ec_uint32 *seed);
+      celt_int32 total_bits, celt_int32 balance, ec_ctx *ec, int M, int codedBands, celt_uint32 *seed);
 
 
 void stereo_decision(const CELTMode *m, celt_norm * restrict X, int *stereo_mode, int len, int M);
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -113,7 +113,7 @@
    /* Everything beyond this point gets cleared on a reset */
 #define ENCODER_RESET_START rng
 
-   ec_uint32 rng;
+   celt_uint32 rng;
    int spread_decision;
    int delayedIntra;
    int tonal_average;
@@ -687,8 +687,8 @@
    int tf_select_rsv;
    int tf_changed;
    int logp;
-   ec_uint32 budget;
-   ec_uint32 tell;
+   celt_uint32 budget;
+   celt_uint32 tell;
    budget = enc->storage*8;
    tell = ec_tell(enc);
    logp = isTransient ? 2 : 4;
@@ -727,8 +727,8 @@
    int tf_select_rsv;
    int tf_changed;
    int logp;
-   ec_uint32 budget;
-   ec_uint32 tell;
+   celt_uint32 budget;
+   celt_uint32 tell;
 
    budget = dec->storage*8;
    tell = ec_tell(dec);
@@ -1810,7 +1810,7 @@
    /* Everything beyond this point gets cleared on a reset */
 #define DECODER_RESET_START rng
 
-   ec_uint32 rng;
+   celt_uint32 rng;
    int last_pitch_index;
    int loss_count;
    int postfilter_period;
--- a/libcelt/cwrs.c
+++ b/libcelt/cwrs.c
@@ -42,7 +42,7 @@
    with frac bits of fractional precision.
   Tested for all possible 32-bit inputs with frac=4, where the maximum
    overestimation is 0.06254243 bits.*/
-int log2_frac(ec_uint32 val, int frac)
+int log2_frac(celt_uint32 val, int frac)
 {
   int l;
   l=EC_ILOG(val);
--- a/libcelt/cwrs.h
+++ b/libcelt/cwrs.h
@@ -35,7 +35,7 @@
 #include "entenc.h"
 #include "entdec.h"
 
-int log2_frac(ec_uint32 val, int frac);
+int log2_frac(celt_uint32 val, int frac);
 
 void get_required_bits(celt_int16 *bits, int N, int K, int frac);
 
--- a/libcelt/ecintrin.h
+++ b/libcelt/ecintrin.h
@@ -26,6 +26,7 @@
 */
 
 /*Some common macros for potential platform-specific optimization.*/
+#include "celt_types.h"
 #include <math.h>
 #include <limits.h>
 #if !defined(_ecintrin_H)
@@ -114,7 +115,7 @@
   When we need to, it can be special cased.*/
 # define EC_ILOG(_x) (EC_CLZ0-EC_CLZ(_x))
 #else
-int ec_ilog(ec_uint32 _v);
+int ec_ilog(celt_uint32 _v);
 
 # define EC_ILOG(_x) (ec_ilog(_x))
 #endif
--- a/libcelt/entcode.c
+++ b/libcelt/entcode.c
@@ -34,7 +34,7 @@
 
 
 #if !defined(EC_CLZ)
-int ec_ilog(ec_uint32 _v){
+int ec_ilog(celt_uint32 _v){
   /*On a Pentium M, this branchless version tested as the fastest on
      1,000,000,000 random 32-bit integers, edging out a similar version with
      branches, and a 256-entry LUT version.*/
@@ -59,11 +59,11 @@
 #endif
 
 
-ec_uint32 ec_tell_frac(ec_ctx *_this){
-  ec_uint32 nbits;
-  ec_uint32 r;
-  int       l;
-  int       i;
+celt_uint32 ec_tell_frac(ec_ctx *_this){
+  celt_uint32 nbits;
+  celt_uint32 r;
+  int         l;
+  int         i;
   /*To handle the non-integral number of bits still left in the encoder/decoder
      state, we compute the worst-case number of bits of val that must be
      encoded to ensure that the value is inside the range for any possible
--- a/libcelt/entcode.h
+++ b/libcelt/entcode.h
@@ -35,8 +35,8 @@
 
 
 
-typedef celt_int32            ec_int32;
-typedef celt_uint32           ec_uint32;
+/*OPT: ec_window must be at least 32 bits, but if you have fast arithmetic on a
+   larger type, you can speed up the decoder by using it here.*/
 typedef celt_uint32           ec_window;
 typedef struct ec_ctx         ec_ctx;
 typedef struct ec_ctx         ec_enc;
@@ -44,8 +44,6 @@
 
 
 
-/*OPT: This must be at least 32 bits, but if you have fast arithmetic on a
-   larger type, you can speed up the decoder by using it for ec_window.*/
 # define EC_WINDOW_SIZE ((int)sizeof(ec_window)*CHAR_BIT)
 
 /*The number of bits to use for the range-coded part of unsigned integers.*/
@@ -64,9 +62,9 @@
    /*Buffered input/output.*/
    unsigned char *buf;
    /*The size of the buffer.*/
-   ec_uint32      storage;
+   celt_uint32    storage;
    /*The offset at which the last byte containing raw bits was read/written.*/
-   ec_uint32      end_offs;
+   celt_uint32    end_offs;
    /*Bits that will be read from/written at the end.*/
    ec_window      end_window;
    /*Number of valid bits in end_window.*/
@@ -75,16 +73,16 @@
      This does not include partial bits currently in the range coder.*/
    int            nbits_total;
    /*The offset at which the next range coder byte will be read/written.*/
-   ec_uint32      offs;
+   celt_uint32    offs;
    /*The number of values in the current range.*/
-   ec_uint32      rng;
+   celt_uint32    rng;
    /*In the decoder: the difference between the top of the current range and
       the input value, minus one.
      In the encoder: the low end of the current range.*/
-   ec_uint32      val;
+   celt_uint32    val;
    /*In the decoder: the saved normalization factor from ec_decode().
      In the encoder: the number of oustanding carry propagating symbols.*/
-   ec_uint32      ext;
+   celt_uint32    ext;
    /*A buffered input/output symbol, awaiting carry propagation.*/
    int            rem;
    /*Nonzero if an error occurred.*/
@@ -97,7 +95,7 @@
   _this->offs=_this->end_offs=0;
 }
 
-static inline ec_uint32 ec_range_bytes(ec_ctx *_this){
+static inline celt_uint32 ec_range_bytes(ec_ctx *_this){
   return _this->offs;
 }
 
@@ -125,6 +123,6 @@
   Return: The number of bits scaled by 2**BITRES.
           This will always be slightly larger than the exact value (e.g., all
            rounding error is in the positive direction).*/
-ec_uint32 ec_tell_frac(ec_ctx *_this);
+celt_uint32 ec_tell_frac(ec_ctx *_this);
 
 #endif
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -125,7 +125,7 @@
   }
 }
 
-void ec_dec_init(ec_dec *_this,unsigned char *_buf,ec_uint32 _storage){
+void ec_dec_init(ec_dec *_this,unsigned char *_buf,celt_uint32 _storage){
   _this->buf=_buf;
   _this->storage=_storage;
   _this->end_offs=0;
@@ -160,7 +160,7 @@
 }
 
 void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
-  ec_uint32 s;
+  celt_uint32 s;
   s=IMUL32(_this->ext,_ft-_fh);
   _this->val-=s;
   _this->rng=_fl>0?IMUL32(_this->ext,_fh-_fl):_this->rng-s;
@@ -169,10 +169,10 @@
 
 /*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       ret;
+  celt_uint32 r;
+  celt_uint32 d;
+  celt_uint32 s;
+  int         ret;
   r=_this->rng;
   d=_this->val;
   s=r>>_logp;
@@ -184,11 +184,11 @@
 }
 
 int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb){
-  ec_uint32 r;
-  ec_uint32 d;
-  ec_uint32 s;
-  ec_uint32 t;
-  int       ret;
+  celt_uint32 r;
+  celt_uint32 d;
+  celt_uint32 s;
+  celt_uint32 t;
+  int         ret;
   s=_this->rng;
   d=_this->val;
   r=s>>_ftb;
@@ -204,7 +204,7 @@
   return ret;
 }
 
-ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){
+celt_uint32 ec_dec_uint(ec_dec *_this,celt_uint32 _ft){
   unsigned ft;
   unsigned s;
   int      ftb;
@@ -213,12 +213,12 @@
   _ft--;
   ftb=EC_ILOG(_ft);
   if(ftb>EC_UINT_BITS){
-    ec_uint32 t;
+    celt_uint32 t;
     ftb-=EC_UINT_BITS;
     ft=(unsigned)(_ft>>ftb)+1;
     s=ec_decode(_this,ft);
     ec_dec_update(_this,s,s+1,ft);
-    t=(ec_uint32)s<<ftb|ec_dec_bits(_this,ftb);
+    t=(celt_uint32)s<<ftb|ec_dec_bits(_this,ftb);
     if(t<=_ft)return t;
     _this->error=1;
     return _ft;
@@ -231,10 +231,10 @@
   }
 }
 
-ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){
-  ec_window window;
-  int       available;
-  ec_uint32 ret;
+celt_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){
+  ec_window   window;
+  int         available;
+  celt_uint32 ret;
   window=_this->end_window;
   available=_this->nend_bits;
   if(available<_bits){
@@ -244,7 +244,7 @@
     }
     while(available<=EC_WINDOW_SIZE-EC_SYM_BITS);
   }
-  ret=(ec_uint32)window&((ec_uint32)1<<_bits)-1;
+  ret=(celt_uint32)window&((celt_uint32)1<<_bits)-1;
   window>>=_bits;
   available-=_bits;
   _this->end_window=window;
--- a/libcelt/entdec.h
+++ b/libcelt/entdec.h
@@ -35,7 +35,7 @@
 /*Initializes the decoder.
   _buf: The input buffer to use.
   Return: 0 on success, or a negative value on error.*/
-void ec_dec_init(ec_dec *_this,unsigned char *_buf,ec_uint32 _storage);
+void ec_dec_init(ec_dec *_this,unsigned char *_buf,celt_uint32 _storage);
 
 /*Calculates the cumulative frequency for the next symbol.
   This can then be fed into the probability model to determine what that
@@ -89,7 +89,7 @@
   _ft: The number of integers that can be decoded (one more than the max).
        This must be at least one, and no more than 2**32-1.
   Return: The decoded bits.*/
-ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft);
+celt_uint32 ec_dec_uint(ec_dec *_this,celt_uint32 _ft);
 
 /*Extracts a sequence of raw bits from the stream.
   The bits must have been encoded with ec_enc_bits().
@@ -97,6 +97,6 @@
   _ftb: The number of bits to extract.
         This must be between 0 and 25, inclusive.
   Return: The decoded bits.*/
-ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb);
+celt_uint32 ec_dec_bits(ec_dec *_this,unsigned _ftb);
 
 #endif
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -114,7 +114,7 @@
   }
 }
 
-void ec_enc_init(ec_enc *_this,unsigned char *_buf,ec_uint32 _size){
+void ec_enc_init(ec_enc *_this,unsigned char *_buf,celt_uint32 _size){
   _this->buf=_buf;
   _this->end_offs=0;
   _this->end_window=0;
@@ -131,7 +131,7 @@
 }
 
 void ec_encode(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft){
-  ec_uint32 r;
+  celt_uint32 r;
   r=_this->rng/_ft;
   if(_fl>0){
     _this->val+=_this->rng-IMUL32(r,(_ft-_fl));
@@ -142,7 +142,7 @@
 }
 
 void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){
-  ec_uint32 r;
+  celt_uint32 r;
   r=_this->rng>>_bits;
   if(_fl>0){
     _this->val+=_this->rng-IMUL32(r,((1<<_bits)-_fl));
@@ -154,9 +154,9 @@
 
 /*The probability of having a "one" is 1/(1<<_logp).*/
 void ec_enc_bit_logp(ec_enc *_this,int _val,unsigned _logp){
-  ec_uint32 r;
-  ec_uint32 s;
-  ec_uint32 l;
+  celt_uint32 r;
+  celt_uint32 s;
+  celt_uint32 l;
   r=_this->rng;
   l=_this->val;
   s=r>>_logp;
@@ -167,7 +167,7 @@
 }
 
 void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb){
-  ec_uint32 r;
+  celt_uint32 r;
   r=_this->rng>>_ftb;
   if(_s>0){
     _this->val+=_this->rng-IMUL32(r,_icdf[_s-1]);
@@ -177,7 +177,7 @@
   ec_enc_normalize(_this);
 }
 
-void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){
+void ec_enc_uint(ec_enc *_this,celt_uint32 _fl,celt_uint32 _ft){
   unsigned  ft;
   unsigned  fl;
   int       ftb;
@@ -190,12 +190,12 @@
     ft=(_ft>>ftb)+1;
     fl=(unsigned)(_fl>>ftb);
     ec_encode(_this,fl,fl+1,ft);
-    ec_enc_bits(_this,_fl&((ec_uint32)1<<ftb)-1,ftb);
+    ec_enc_bits(_this,_fl&((celt_uint32)1<<ftb)-1,ftb);
   }
   else ec_encode(_this,_fl,_fl+1,_ft+1);
 }
 
-void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _bits){
+void ec_enc_bits(ec_enc *_this,celt_uint32 _fl,unsigned _bits){
   ec_window window;
   int       used;
   window=_this->end_window;
@@ -231,14 +231,14 @@
   }
   else if(_this->rng<=EC_CODE_TOP>>shift){
     /*The renormalization loop has never been run.*/
-    _this->val=_this->val&~((ec_uint32)mask<<EC_CODE_SHIFT)|
-     (ec_uint32)_val<<EC_CODE_SHIFT+shift;
+    _this->val=_this->val&~((celt_uint32)mask<<EC_CODE_SHIFT)|
+     (celt_uint32)_val<<EC_CODE_SHIFT+shift;
   }
   /*The encoder hasn't even encoded _nbits of data yet.*/
   else _this->error=-1;
 }
 
-void ec_enc_shrink(ec_enc *_this,ec_uint32 _size){
+void ec_enc_shrink(ec_enc *_this,celt_uint32 _size){
   celt_assert(_this->offs+_this->end_offs<=_size);
   CELT_MOVE(_this->buf+_size-_this->end_offs,
    _this->buf+_this->storage-_this->end_offs,_this->end_offs);
@@ -246,11 +246,11 @@
 }
 
 void ec_enc_done(ec_enc *_this){
-  ec_window window;
-  int       used;
-  ec_uint32 msk;
-  ec_uint32 end;
-  int       l;
+  ec_window   window;
+  int         used;
+  celt_uint32 msk;
+  celt_uint32 end;
+  int         l;
   /*We output the minimum number of bits that ensures that the symbols encoded
      thus far will be decoded correctly regardless of the bits that follow.*/
   l=EC_CODE_BITS-EC_ILOG(_this->rng);
--- a/libcelt/entenc.h
+++ b/libcelt/entenc.h
@@ -35,7 +35,7 @@
 /*Initializes the encoder.
   _buf:  The buffer to store output bytes in.
   _size: The size of the buffer, in chars.*/
-void ec_enc_init(ec_enc *_this,unsigned char *_buf,ec_uint32 _size);
+void ec_enc_init(ec_enc *_this,unsigned char *_buf,celt_uint32 _size);
 /*Encodes a symbol given its frequency information.
   The frequency information must be discernable by the decoder, assuming it
    has read only the previous symbols from the stream.
@@ -70,13 +70,13 @@
   _fl: The integer to encode.
   _ft: The number of integers that can be encoded (one more than the max).
        This must be at least one, and no more than 2**32-1.*/
-void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft);
+void ec_enc_uint(ec_enc *_this,celt_uint32 _fl,celt_uint32 _ft);
 
 /*Encodes a sequence of raw bits in the stream.
   _fl:  The bits to encode.
   _ftb: The number of bits to encode.
         This must be between 0 and 25, inclusive.*/
-void ec_enc_bits(ec_enc *_this,ec_uint32 _fl,unsigned _ftb);
+void ec_enc_bits(ec_enc *_this,celt_uint32 _fl,unsigned _ftb);
 
 /*Overwrites a few bits at the very start of an existing stream, after they
    have already been encoded.
@@ -102,7 +102,7 @@
   _size: The number of bytes in the new buffer.
          This must be large enough to contain the bits already written, and
           must be no larger than the existing size.*/
-void ec_enc_shrink(ec_enc *_this,ec_uint32 _size);
+void ec_enc_shrink(ec_enc *_this,celt_uint32 _size);
 
 /*Indicates that there are no more symbols to encode.
   All reamining output bytes are flushed to the output buffer.
--- a/libcelt/mfrngcod.h
+++ b/libcelt/mfrngcod.h
@@ -40,11 +40,11 @@
 /*Bits to shift by to move a symbol into the high-order position.*/
 # define EC_CODE_SHIFT (EC_CODE_BITS-EC_SYM_BITS-1)
 /*Carry bit of the high-order range symbol.*/
-# define EC_CODE_TOP   (((ec_uint32)1U)<<EC_CODE_BITS-1)
+# define EC_CODE_TOP   (((celt_uint32)1U)<<EC_CODE_BITS-1)
 /*Low-order bit of the high-order range symbol.*/
 # define EC_CODE_BOT   (EC_CODE_TOP>>EC_SYM_BITS)
 /*Code for which propagating carries are possible.*/
-# define EC_CODE_CARRY (((ec_uint32)EC_SYM_MAX)<<EC_CODE_SHIFT)
+# define EC_CODE_CARRY (((celt_uint32)EC_SYM_MAX)<<EC_CODE_SHIFT)
 /*The number of bits available for the last, partial symbol in the code field.*/
 # define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1)
 /*A mask for the bits available in the coding buffer.
@@ -51,6 +51,6 @@
   This allows different platforms to use a variable with more bits, if it is
    convenient.
   We will only use EC_CODE_BITS of it.*/
-# define EC_CODE_MASK  ((((ec_uint32)1U)<<EC_CODE_BITS-1)-1<<1|1)
+# define EC_CODE_MASK  ((((celt_uint32)1U)<<EC_CODE_BITS-1)-1<<1|1)
 
 #endif
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -155,7 +155,7 @@
 
 static int quant_coarse_energy_impl(const CELTMode *m, int start, int end,
       const celt_word16 *eBands, celt_word16 *oldEBands,
-      ec_int32 budget, ec_int32 tell,
+      celt_int32 budget, celt_int32 tell,
       const unsigned char *prob_model, celt_word16 *error, ec_enc *enc,
       int _C, int LM, int intra, celt_word16 max_decay)
 {
@@ -258,7 +258,7 @@
 }
 
 void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
-      const celt_word16 *eBands, celt_word16 *oldEBands, ec_uint32 budget,
+      const celt_word16 *eBands, celt_word16 *oldEBands, celt_uint32 budget,
       celt_word16 *error, ec_enc *enc, int _C, int LM, int nbAvailableBytes,
       int force_intra, int *delayedIntra, int two_pass)
 {
@@ -268,7 +268,7 @@
    VARDECL(celt_word16, oldEBands_intra);
    VARDECL(celt_word16, error_intra);
    ec_enc enc_start_state;
-   ec_uint32 tell;
+   celt_uint32 tell;
    int badness1=0;
    SAVE_STACK;
 
@@ -307,8 +307,8 @@
    {
       ec_enc enc_intra_state;
       int tell_intra;
-      ec_uint32 nstart_bytes;
-      ec_uint32 nintra_bytes;
+      celt_uint32 nstart_bytes;
+      celt_uint32 nintra_bytes;
       int badness2;
       VARDECL(unsigned char, intra_bits);
 
@@ -421,8 +421,8 @@
    celt_word16 coef;
    celt_word16 beta;
    const int C = CHANNELS(_C);
-   ec_int32 budget;
-   ec_int32 tell;
+   celt_int32 budget;
+   celt_int32 tell;
 
 
    if (intra)
--- a/libcelt/quant_bands.h
+++ b/libcelt/quant_bands.h
@@ -45,7 +45,7 @@
 void quant_prob_free(const celt_int16 *freq);
 
 void quant_coarse_energy(const CELTMode *m, int start, int end, int effEnd,
-      const celt_word16 *eBands, celt_word16 *oldEBands, ec_uint32 budget,
+      const celt_word16 *eBands, celt_word16 *oldEBands, celt_uint32 budget,
       celt_word16 *error, ec_enc *enc, int _C, int LM,
       int nbAvailableBytes, int force_intra, int *delayedIntra, int two_pass);