Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/celt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy B. Terriberry <tterribe@xiph.org>2011-02-07 00:29:00 +0300
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>2011-02-07 01:32:58 +0300
commit285bc372cadfc6876b7f4942318e312665729156 (patch)
tree79c41cdfb75ddc856ac6609cc9ad4d86980f2160 /libcelt
parentb570f1a91053c3633fff047134279719d9039c0b (diff)
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.
Diffstat (limited to 'libcelt')
-rw-r--r--libcelt/celt.c10
-rw-r--r--libcelt/entcode.h5
-rw-r--r--libcelt/entdec.c2
-rw-r--r--libcelt/rate.c14
-rw-r--r--libcelt/rate.h2
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<<BITRES) - ec_tell_frac(enc) - 1;
+ /* bits = packet size - where we are - safety*/
+ bits = ((celt_int32)nbCompressedBytes*8<<BITRES) - ec_tell_frac(enc) - 1;
anti_collapse_rsv = isTransient&&LM>=2&&bits>=(LM+2<<BITRES) ? (1<<BITRES) : 0;
bits -= anti_collapse_rsv;
codedBands = compute_allocation(st->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<<BITRES) <= total_bits ?
ec_dec_icdf(dec, trim_icdf, 7) : 5;
- bits = (len*8<<BITRES) - ec_tell_frac(dec) - 1;
+ bits = ((celt_int32)len*8<<BITRES) - ec_tell_frac(dec) - 1;
anti_collapse_rsv = isTransient&&LM>=2&&bits>=(LM+2<<BITRES) ? (1<<BITRES) : 0;
bits -= anti_collapse_rsv;
codedBands = compute_allocation(st->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<<ftb|ec_dec_bits(_this,ftb);
+ t=(ec_uint32)s<<ftb|ec_dec_bits(_this,ftb);
if(t<=_ft)return t;
_this->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;j<codedBands;j++)
- bits[j] += percoeff*(m->eBands[j+1]-m->eBands[j]);
+ bits[j] += (int)(percoeff*(m->eBands[j+1]-m->eBands[j]));
for (j=start;j<codedBands;j++)
{
- int tmp = IMIN(left, m->eBands[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