>From 87fa6232a6309466ccdd353ca62f3a1aafc501ff Mon Sep 17 00:00:00 2001 From: Timothy B. Terriberry Date: Wed, 2 Mar 2011 16:24:32 -0800 Subject: [PATCH] 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. --- libcelt/bands.c | 2 +- libcelt/bands.h | 2 +- libcelt/celt.c | 12 ++++++------ libcelt/cwrs.c | 2 +- libcelt/cwrs.h | 2 +- libcelt/ecintrin.h | 3 ++- libcelt/entcode.c | 12 ++++++------ libcelt/entcode.h | 22 ++++++++++------------ libcelt/entdec.c | 38 +++++++++++++++++++------------------- libcelt/entdec.h | 6 +++--- libcelt/entenc.c | 36 ++++++++++++++++++------------------ libcelt/entenc.h | 8 ++++---- libcelt/mfrngcod.h | 6 +++--- libcelt/quant_bands.c | 14 +++++++------- libcelt/quant_bands.h | 2 +- 15 files changed, 83 insertions(+), 84 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 1948bae..d51feee 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -1161,7 +1161,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c 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; diff --git a/libcelt/bands.h b/libcelt/bands.h index d0fcf1b..d3d3dc8 100644 --- a/libcelt/bands.h +++ b/libcelt/bands.h @@ -84,7 +84,7 @@ void haar1(celt_norm *X, int N0, int stride); 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); diff --git a/libcelt/celt.c b/libcelt/celt.c index ccab29d..47697c0 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -113,7 +113,7 @@ struct CELTEncoder { /* 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 @@ static void tf_encode(int start, int end, int isTransient, int *tf_res, int LM, 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 @@ static void tf_decode(int start, int end, int isTransient, int *tf_res, int LM, 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 @@ struct CELTDecoder { /* 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; diff --git a/libcelt/cwrs.c b/libcelt/cwrs.c index 40dcc55..21d278f 100644 --- 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); diff --git a/libcelt/cwrs.h b/libcelt/cwrs.h index 1224a26..443213f 100644 --- 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); diff --git a/libcelt/ecintrin.h b/libcelt/ecintrin.h index 9222a3c..1a7f168 100644 --- 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 #include #if !defined(_ecintrin_H) @@ -114,7 +115,7 @@ static __inline int ec_bsr(unsigned long _x){ 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 diff --git a/libcelt/entcode.c b/libcelt/entcode.c index 17d08df..0626e51 100644 --- 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 @@ int ec_ilog(ec_uint32 _v){ #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 diff --git a/libcelt/entcode.h b/libcelt/entcode.h index 56f7ffe..f24e1c4 100644 --- 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 @@ typedef struct ec_ctx ec_dec; -/*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 @@ struct ec_ctx{ /*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 @@ struct ec_ctx{ 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 @@ static inline void ec_reset(ec_ctx *_this){ _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 @@ static inline int ec_tell(ec_ctx *_this){ 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 diff --git a/libcelt/entdec.c b/libcelt/entdec.c index f5676c6..8b4d2ee 100644 --- a/libcelt/entdec.c +++ b/libcelt/entdec.c @@ -125,7 +125,7 @@ static void ec_dec_normalize(ec_dec *_this){ } } -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 @@ unsigned ec_decode_bin(ec_dec *_this,unsigned _bits){ } 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 @@ void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){ /*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_bit_logp(ec_dec *_this,unsigned _logp){ } 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 @@ int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb){ 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 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){ _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<error=1; return _ft; @@ -231,10 +231,10 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){ } } -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 @@ ec_uint32 ec_dec_bits(ec_dec *_this,unsigned _bits){ } 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; diff --git a/libcelt/entdec.h b/libcelt/entdec.h index 5119e0a..593979b 100644 --- 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 @@ int ec_dec_icdf(ec_dec *_this,const unsigned char *_icdf,unsigned _ftb); _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 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft); _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 diff --git a/libcelt/entenc.c b/libcelt/entenc.c index 9297b5f..df649a6 100644 --- a/libcelt/entenc.c +++ b/libcelt/entenc.c @@ -114,7 +114,7 @@ static void ec_enc_normalize(ec_enc *_this){ } } -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_enc_init(ec_enc *_this,unsigned char *_buf,ec_uint32 _size){ } 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(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _ft){ } 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 @@ void ec_encode_bin(ec_enc *_this,unsigned _fl,unsigned _fh,unsigned _bits){ /*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_bit_logp(ec_enc *_this,int _val,unsigned _logp){ } 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 @@ void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb){ 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 @@ void ec_enc_uint(ec_enc *_this,ec_uint32 _fl,ec_uint32 _ft){ ft=(_ft>>ftb)+1; fl=(unsigned)(_fl>>ftb); ec_encode(_this,fl,fl+1,ft); - ec_enc_bits(_this,_fl&((ec_uint32)1<end_window; @@ -231,14 +231,14 @@ void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits){ } else if(_this->rng<=EC_CODE_TOP>>shift){ /*The renormalization loop has never been run.*/ - _this->val=_this->val&~((ec_uint32)mask<val=_this->val&~((celt_uint32)mask<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_shrink(ec_enc *_this,ec_uint32 _size){ } 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); diff --git a/libcelt/entenc.h b/libcelt/entenc.h index e64e887..7e30617 100644 --- 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 @@ void ec_enc_icdf(ec_enc *_this,int _s,const unsigned char *_icdf,unsigned _ftb); _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 @@ void ec_enc_patch_initial_bits(ec_enc *_this,unsigned _val,unsigned _nbits); _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. diff --git a/libcelt/mfrngcod.h b/libcelt/mfrngcod.h index 9a065f0..5e7a5bb 100644 --- a/libcelt/mfrngcod.h +++ b/libcelt/mfrngcod.h @@ -40,17 +40,17 @@ /*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_SYM_BITS) /*Code for which propagating carries are possible.*/ -# define EC_CODE_CARRY (((ec_uint32)EC_SYM_MAX)<