From 285bc372cadfc6876b7f4942318e312665729156 Mon Sep 17 00:00:00 2001 From: "Timothy B. Terriberry" Date: Sun, 6 Feb 2011 13:29:00 -0800 Subject: 16-bit int fixes. This fixes a number of issues for platforms with a 16-bit int, but by no means all of them. The type change for ec_window (for platforms where sizeof(size_t)==2) will break ABI (but not API) compatibility with libsilk and libopus, and reduce speed on x86-64, but allows the code to work in real-mode DOS without using the huge memory model, which is useful for testing 16-bit int compliance. --- libcelt/celt.c | 10 +++++----- libcelt/entcode.h | 5 +++-- libcelt/entdec.c | 2 +- libcelt/rate.c | 14 +++++++------- libcelt/rate.h | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libcelt/celt.c b/libcelt/celt.c index 6fefd01..ef89730 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -872,7 +872,7 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i { #endif int i, c, N; - int bits; + celt_int32 bits; ec_enc _enc; VARDECL(celt_sig, in); VARDECL(celt_sig, freq); @@ -1439,8 +1439,8 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i ALLOC(pulses, st->mode->nbEBands, int); ALLOC(fine_priority, st->mode->nbEBands, int); - /* bits = packet size - where we are - safety*/ - bits = (nbCompressedBytes*8<=2&&bits>=(LM+2<mode, st->start, st->end, offsets, cap, @@ -2151,7 +2151,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da #endif int c, i, N; int spread_decision; - int bits; + celt_int32 bits; ec_dec _dec; VARDECL(celt_sig, freq); VARDECL(celt_norm, X); @@ -2367,7 +2367,7 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da alloc_trim = tell+(6<=2&&bits>=(LM+2<mode, st->start, st->end, offsets, cap, diff --git a/libcelt/entcode.h b/libcelt/entcode.h index e62a78e..a498d4c 100644 --- a/libcelt/entcode.h +++ b/libcelt/entcode.h @@ -41,14 +41,15 @@ typedef celt_int32 ec_int32; typedef celt_uint32 ec_uint32; -typedef size_t ec_window; +typedef celt_uint32 ec_window; typedef struct ec_ctx ec_ctx; typedef struct ec_ctx ec_enc; typedef struct ec_ctx ec_dec; -/*This must be at least 32 bits.*/ +/*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.*/ diff --git a/libcelt/entdec.c b/libcelt/entdec.c index 6170155..a7d177f 100644 --- a/libcelt/entdec.c +++ b/libcelt/entdec.c @@ -222,7 +222,7 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){ ft=(unsigned)(_ft>>ftb)+1; s=ec_decode(_this,ft); ec_dec_update(_this,s,s+1,ft); - t=s<error=1; return _ft; diff --git a/libcelt/rate.c b/libcelt/rate.c index 22fee42..b03754c 100644 --- a/libcelt/rate.c +++ b/libcelt/rate.c @@ -252,11 +252,11 @@ void compute_pulse_cache(CELTMode *m, int LM) #define ALLOC_STEPS 6 static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int skip_start, - const int *bits1, const int *bits2, const int *thresh, const int *cap, int total, celt_int32 *_balance, + const int *bits1, const int *bits2, const int *thresh, const int *cap, celt_int32 total, celt_int32 *_balance, int skip_rsv, int *intensity, int intensity_rsv, int *dual_stereo, int dual_stereo_rsv, int *bits, int *ebits, int *fine_priority, int _C, int LM, ec_ctx *ec, int encode, int prev) { - int psum; + celt_int32 psum; int lo, hi; int i, j; int logM; @@ -264,7 +264,7 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int int stereo; int codedBands=-1; int alloc_floor; - int left, percoeff; + celt_int32 left, percoeff; int done; int balance; SAVE_STACK; @@ -282,7 +282,7 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int done = 0; for (j=end;j-->start;) { - int tmp = bits1[j] + (mid*bits2[j]>>ALLOC_STEPS); + int tmp = bits1[j] + (mid*(celt_int32)bits2[j]>>ALLOC_STEPS); if (tmp >= thresh[j] || done) { done = 1; @@ -344,7 +344,7 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; rem = IMAX(left-(m->eBands[j]-m->eBands[start]),0); band_width = m->eBands[codedBands]-m->eBands[j]; - band_bits = bits[j] + percoeff*band_width + rem; + band_bits = (int)(bits[j] + percoeff*band_width + rem); /*Only code a skip decision if we're above the threshold for this band. Otherwise it is force-skipped. This ensures that we have enough bits to code the skip flag.*/ @@ -420,10 +420,10 @@ static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int percoeff = left/(m->eBands[codedBands]-m->eBands[start]); left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; for (j=start;jeBands[j+1]-m->eBands[j]); + bits[j] += (int)(percoeff*(m->eBands[j+1]-m->eBands[j])); for (j=start;jeBands[j+1]-m->eBands[j]); + int tmp = (int)IMIN(left, m->eBands[j+1]-m->eBands[j]); bits[j] += tmp; left -= tmp; } diff --git a/libcelt/rate.h b/libcelt/rate.h index 86f114b..342fa4d 100644 --- a/libcelt/rate.h +++ b/libcelt/rate.h @@ -105,7 +105,7 @@ celt_int16 **compute_alloc_cache(CELTMode *m, int M); @return Total number of bits allocated */ int compute_allocation(const CELTMode *m, int start, int end, const int *offsets, const int *cap, int alloc_trim, int *intensity, int *dual_stero, - int total, celt_int32 *balance, int *pulses, int *ebits, int *fine_priority, int _C, int LM, ec_ctx *ec, int encode, int prev); + celt_int32 total, celt_int32 *balance, int *pulses, int *ebits, int *fine_priority, int _C, int LM, ec_ctx *ec, int encode, int prev); #endif -- cgit v1.2.3