Trying to be nice with 16-bit chips.
This commit is contained in:
parent
65d79e4419
commit
508de38d22
5 changed files with 14 additions and 12 deletions
|
@ -55,7 +55,7 @@ int ec_ilog64(ec_uint64 _v){
|
||||||
int ret;
|
int ret;
|
||||||
int m;
|
int m;
|
||||||
ret=!!_v;
|
ret=!!_v;
|
||||||
m=!!(_v&0xFFFFFFFF00000000)<<5;
|
m=!!(_v&((ec_uint64)0xFFFFFFFF)<<32)<<5;
|
||||||
v=(ec_uint32)(_v>>m);
|
v=(ec_uint32)(_v>>m);
|
||||||
ret|=m;
|
ret|=m;
|
||||||
m=!!(v&0xFFFF0000)<<4;
|
m=!!(v&0xFFFF0000)<<4;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef celt_int32_t ec_int32;
|
||||||
typedef celt_uint32_t ec_uint32;
|
typedef celt_uint32_t ec_uint32;
|
||||||
typedef celt_uint64_t ec_uint64;
|
typedef celt_uint64_t ec_uint64;
|
||||||
typedef struct ec_byte_buffer ec_byte_buffer;
|
typedef struct ec_byte_buffer ec_byte_buffer;
|
||||||
|
|
|
@ -37,12 +37,13 @@
|
||||||
|
|
||||||
static int ec_laplace_get_total(int decay)
|
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)
|
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;
|
int s = 0;
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
{
|
||||||
|
@ -50,8 +51,8 @@ void ec_laplace_encode(ec_enc *enc, int value, int decay)
|
||||||
value = -value;
|
value = -value;
|
||||||
}
|
}
|
||||||
ft = ec_laplace_get_total(decay);
|
ft = ec_laplace_get_total(decay);
|
||||||
fl = -(1<<15);
|
fl = -(((ec_uint32)1)<<15);
|
||||||
fs = 1<<15;
|
fs = ((ec_uint32)1)<<15;
|
||||||
for (i=0;i<value;i++)
|
for (i=0;i<value;i++)
|
||||||
{
|
{
|
||||||
int tmp_l, tmp_s;
|
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 ec_laplace_decode(ec_dec *dec, int decay)
|
||||||
{
|
{
|
||||||
int val=0;
|
int val=0;
|
||||||
int fl, fh, fs, ft, fm;
|
ec_int32 fl, fh, fs, ft, fm;
|
||||||
ft = ec_laplace_get_total(decay);
|
ft = ec_laplace_get_total(decay);
|
||||||
|
|
||||||
fm = ec_decode(dec, ft);
|
fm = ec_decode(dec, ft);
|
||||||
/*printf ("fm: %d/%d\n", fm, ft);*/
|
/*printf ("fm: %d/%d\n", fm, ft);*/
|
||||||
fl = 0;
|
fl = 0;
|
||||||
fs = 1<<15;
|
fs = ((ec_uint32)1)<<15;
|
||||||
fh = fs;
|
fh = fs;
|
||||||
while (fm >= fh && fs != 0)
|
while (fm >= fh && fs != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,18 +13,18 @@
|
||||||
/*Bits to shift by to move a symbol into the high-order position.*/
|
/*Bits to shift by to move a symbol into the high-order position.*/
|
||||||
# define EC_CODE_SHIFT (EC_CODE_BITS-EC_SYM_BITS-1)
|
# define EC_CODE_SHIFT (EC_CODE_BITS-EC_SYM_BITS-1)
|
||||||
/*Carry bit of the high-order range symbol.*/
|
/*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.*/
|
/*Low-order bit of the high-order range symbol.*/
|
||||||
# define EC_CODE_BOT (EC_CODE_TOP>>EC_SYM_BITS)
|
# define EC_CODE_BOT (EC_CODE_TOP>>EC_SYM_BITS)
|
||||||
/*Code for which propagating carries are possible.*/
|
/*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.*/
|
/*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)
|
# define EC_CODE_EXTRA ((EC_CODE_BITS-2)%EC_SYM_BITS+1)
|
||||||
/*A mask for the bits available in the coding buffer.
|
/*A mask for the bits available in the coding buffer.
|
||||||
This allows different platforms to use a variable with more bits, if it is
|
This allows different platforms to use a variable with more bits, if it is
|
||||||
convenient.
|
convenient.
|
||||||
We will only use EC_CODE_BITS of it.*/
|
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.
|
/*The non-zero symbol of the second possible reserved ending.
|
||||||
|
|
|
@ -93,7 +93,7 @@ static void quant_energy_mono(const CELTMode *m, float *eBands, float *oldEBands
|
||||||
int q2;
|
int q2;
|
||||||
float offset = (error[i]+.5)*frac[i];
|
float offset = (error[i]+.5)*frac[i];
|
||||||
/* FIXME: Instead of giving up without warning, we should degrade everything gracefully */
|
/* 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;
|
break;
|
||||||
q2 = (int)floor(offset);
|
q2 = (int)floor(offset);
|
||||||
if (q2 > frac[i]-1)
|
if (q2 > frac[i]-1)
|
||||||
|
@ -145,7 +145,7 @@ static void unquant_energy_mono(const CELTMode *m, float *eBands, float *oldEBan
|
||||||
{
|
{
|
||||||
int q2;
|
int q2;
|
||||||
float offset;
|
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;
|
break;
|
||||||
q2 = ec_dec_uint(dec, frac[i]);
|
q2 = ec_dec_uint(dec, frac[i]);
|
||||||
offset = ((q2+.5)/frac[i])-.5;
|
offset = ((q2+.5)/frac[i])-.5;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue