Trying to be nice with 16-bit chips.

This commit is contained in:
Jean-Marc Valin 2008-02-26 10:28:20 +11:00
parent 65d79e4419
commit 508de38d22
5 changed files with 14 additions and 12 deletions

View file

@ -55,7 +55,7 @@ int ec_ilog64(ec_uint64 _v){
int ret;
int m;
ret=!!_v;
m=!!(_v&0xFFFFFFFF00000000)<<5;
m=!!(_v&((ec_uint64)0xFFFFFFFF)<<32)<<5;
v=(ec_uint32)(_v>>m);
ret|=m;
m=!!(v&0xFFFF0000)<<4;

View file

@ -7,6 +7,7 @@
typedef celt_int32_t ec_int32;
typedef celt_uint32_t ec_uint32;
typedef celt_uint64_t ec_uint64;
typedef struct ec_byte_buffer ec_byte_buffer;

View file

@ -37,12 +37,13 @@
static int ec_laplace_get_total(int decay)
{
return (1<<30)/((1<<14) - decay) - (1<<15) + 1;
return (((ec_uint32)1)<<30)/((((ec_uint32)1)<<14) - decay) - (((ec_uint32)1)<<15) + 1;
}
void ec_laplace_encode(ec_enc *enc, int value, int decay)
{
int i, fl, fs, ft;
int i;
ec_int32 fl, fs, ft;
int s = 0;
if (value < 0)
{
@ -50,8 +51,8 @@ void ec_laplace_encode(ec_enc *enc, int value, int decay)
value = -value;
}
ft = ec_laplace_get_total(decay);
fl = -(1<<15);
fs = 1<<15;
fl = -(((ec_uint32)1)<<15);
fs = ((ec_uint32)1)<<15;
for (i=0;i<value;i++)
{
int tmp_l, tmp_s;
@ -77,13 +78,13 @@ void ec_laplace_encode(ec_enc *enc, int value, int decay)
int ec_laplace_decode(ec_dec *dec, int decay)
{
int val=0;
int fl, fh, fs, ft, fm;
ec_int32 fl, fh, fs, ft, fm;
ft = ec_laplace_get_total(decay);
fm = ec_decode(dec, ft);
/*printf ("fm: %d/%d\n", fm, ft);*/
fl = 0;
fs = 1<<15;
fs = ((ec_uint32)1)<<15;
fh = fs;
while (fm >= fh && fs != 0)
{

View file

@ -13,18 +13,18 @@
/*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 (1U<<EC_CODE_BITS-1)
# define EC_CODE_TOP (((ec_uint32)1U)<<EC_CODE_BITS-1)
/*Low-order bit of the high-order range symbol.*/
# define EC_CODE_BOT (EC_CODE_TOP>>EC_SYM_BITS)
/*Code for which propagating carries are possible.*/
# define EC_CODE_CARRY (EC_SYM_MAX<<EC_CODE_SHIFT)
# define EC_CODE_CARRY (((ec_uint32)EC_SYM_MAX)<<EC_CODE_SHIFT)
/*The number of bits available for the last, partial symbol in the code field.*/
# define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1)
/*A mask for the bits available in the coding buffer.
This allows different platforms to use a variable with more bits, if it is
convenient.
We will only use EC_CODE_BITS of it.*/
# define EC_CODE_MASK ((1U<<EC_CODE_BITS-1)-1<<1|1)
# define EC_CODE_MASK ((((ec_uint32)1U)<<EC_CODE_BITS-1)-1<<1|1)
/*The non-zero symbol of the second possible reserved ending.

View file

@ -93,7 +93,7 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
int q2;
float offset = (error[i]+.5)*frac[i];
/* FIXME: Instead of giving up without warning, we should degrade everything gracefully */
if (ec_enc_tell(enc, 0) - bits +ec_ilog(frac[i])> budget)
if (ec_enc_tell(enc, 0) - bits +EC_ILOG(frac[i])> budget)
break;
q2 = (int)floor(offset);
if (q2 > frac[i]-1)
@ -145,7 +145,7 @@ static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBan
{
int q2;
float offset;
if (ec_dec_tell(dec, 0) - bits +ec_ilog(frac[i])> budget)
if (ec_dec_tell(dec, 0) - bits +EC_ILOG(frac[i])> budget)
break;
q2 = ec_dec_uint(dec, frac[i]);
offset = ((q2+.5)/frac[i])-.5;