ref: 285bc372cadfc6876b7f4942318e312665729156
parent: b570f1a91053c3633fff047134279719d9039c0b
author: Timothy B. Terriberry <[email protected]>
date: Sun Feb 6 08:29:00 EST 2011
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.
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -872,7 +872,7 @@
{
#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 @@
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 @@
#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 @@
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,
--- a/libcelt/entcode.h
+++ b/libcelt/entcode.h
@@ -41,7 +41,7 @@
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;
@@ -48,7 +48,8 @@
-/*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.*/
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -222,7 +222,7 @@
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;
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -252,11 +252,11 @@
#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 @@
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 @@
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 @@
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 @@
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;
}
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -105,7 +105,7 @@
@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