Commit 285bc372 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry Committed by Jean-Marc Valin
Browse files

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.
parent b570f1a9
......@@ -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,
......
......@@ -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.*/
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment