shithub: opus

Download patch

ref: 508de38d228e3412e3cafb7f2890384f8bb424bd
parent: 65d79e44190d9e3391b9e94e6b206d06ebfade9c
author: Jean-Marc Valin <[email protected]>
date: Tue Feb 26 05:28:20 EST 2008

Trying to be nice with 16-bit chips.

--- a/libcelt/entcode.c
+++ b/libcelt/entcode.c
@@ -55,7 +55,7 @@
   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;
--- a/libcelt/entcode.h
+++ b/libcelt/entcode.h
@@ -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;
--- a/libcelt/laplace.c
+++ b/libcelt/laplace.c
@@ -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 @@
       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 @@
 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)
    {
--- a/libcelt/mfrngcod.h
+++ b/libcelt/mfrngcod.h
@@ -13,11 +13,11 @@
 /*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.
@@ -24,7 +24,7 @@
   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.
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -93,7 +93,7 @@
       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 @@
    {
       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;