shithub: opus

Download patch

ref: 17a29c256749fa7f44930ce3648339ace9fd2506
parent: 927488b29248f60ef65875866ed7d5fe081936a8
author: Gregory Maxwell <[email protected]>
date: Tue Aug 30 14:35:06 EDT 2011

Fix up various mixed unsigned/signed comparisons.
This silences MSVC warning C4018 and fixes a bug with the intra
decision and improves portability to 16 bit platforms.

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -45,13 +45,6 @@
 #  endif
 # endif
 
-# if defined(_MSC_VER)
-#  pragma warning(disable:4554)
-# endif
-# if __GNUC_PREREQ(4,2)
-#  pragma GCC diagnostic ignored "-Wparentheses"
-# endif
-
 #define CELT_SIG_SCALE 32768.f
 
 #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -150,7 +150,7 @@
    unsigned s;
    _this->ext=_this->rng>>_bits;
    s=(unsigned)(_this->val/_this->ext);
-   return (1<<_bits)-EC_MINI(s+1,1<<_bits);
+   return (1U<<_bits)-EC_MINI(s+1U,1U<<_bits);
 }
 
 void ec_dec_update(ec_dec *_this,unsigned _fl,unsigned _fh,unsigned _ft){
@@ -231,7 +231,7 @@
   opus_uint32 ret;
   window=_this->end_window;
   available=_this->nend_bits;
-  if(available<_bits){
+  if((unsigned)available<_bits){
     do{
       window|=(ec_window)ec_read_byte_from_end(_this)<<available;
       available+=EC_SYM_BITS;
@@ -238,7 +238,7 @@
     }
     while(available<=EC_WINDOW_SIZE-EC_SYM_BITS);
   }
-  ret=(opus_uint32)window&((opus_uint32)1<<_bits)-1;
+  ret=(opus_uint32)window&((opus_uint32)1<<_bits)-1U;
   window>>=_bits;
   available-=_bits;
   _this->end_window=window;
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -140,10 +140,10 @@
   opus_uint32 r;
   r=_this->rng>>_bits;
   if(_fl>0){
-    _this->val+=_this->rng-IMUL32(r,((1<<_bits)-_fl));
+    _this->val+=_this->rng-IMUL32(r,((1U<<_bits)-_fl));
     _this->rng=IMUL32(r,(_fh-_fl));
   }
-  else _this->rng-=IMUL32(r,((1<<_bits)-_fh));
+  else _this->rng-=IMUL32(r,((1U<<_bits)-_fh));
   ec_enc_normalize(_this);
 }
 
--- a/libcelt/kiss_fft.c
+++ b/libcelt/kiss_fft.c
@@ -262,12 +262,12 @@
                      kiss_fft_cpx * Fout,
                      const size_t fstride,
                      const kiss_fft_state *st,
-                     size_t m,
+                     int m,
                      int N,
                      int mm
                     )
 {
-   size_t i, k;
+   int i, k;
    const size_t m2 = 2*m;
    const kiss_twiddle_cpx *tw1,*tw2;
    kiss_fft_cpx scratch[5];
--- a/libcelt/laplace.c
+++ b/libcelt/laplace.c
@@ -40,14 +40,14 @@
     direction). */
 #define LAPLACE_NMIN (16)
 
-static int ec_laplace_get_freq1(int fs0, int decay)
+static unsigned ec_laplace_get_freq1(unsigned fs0, int decay)
 {
-   opus_int32 ft;
+   unsigned ft;
    ft = 32768 - LAPLACE_MINP*(2*LAPLACE_NMIN) - fs0;
    return ft*(16384-decay)>>15;
 }
 
-void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay)
+void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay)
 {
    unsigned fl;
    int val = *value;
@@ -57,7 +57,7 @@
       int s;
       int i;
       s = -(val<0);
-      val = val+s^s;
+      val = (val+s)^s;
       fl = fs;
       fs = ec_laplace_get_freq1(fs, decay);
       /* Search the decaying part of the PDF.*/
@@ -77,7 +77,7 @@
          di = IMIN(val - i, ndi_max - 1);
          fl += (2*di+1+s)*LAPLACE_MINP;
          fs = IMIN(LAPLACE_MINP, 32768-fl);
-         *value = i+di+s^s;
+         *value = (i+di+s)^s;
       }
       else
       {
@@ -90,11 +90,11 @@
    ec_encode_bin(enc, fl, fl+fs, 15);
 }
 
-int ec_laplace_decode(ec_dec *dec, int fs, int decay)
+int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay)
 {
    int val=0;
    unsigned fl;
-   int fm;
+   unsigned fm;
    fm = ec_decode_bin(dec, 15);
    fl = 0;
    if (fm >= fs)
--- a/libcelt/laplace.h
+++ b/libcelt/laplace.h
@@ -36,7 +36,7 @@
  @param fs Probability of 0, multiplied by 32768
  @param decay Probability of the value +/- 1, multiplied by 16384
 */
-void ec_laplace_encode(ec_enc *enc, int *value, int fs, int decay);
+void ec_laplace_encode(ec_enc *enc, int *value, unsigned fs, int decay);
 
 /** Decode a value that is assumed to be the realisation of a
     Laplace-distributed random process
@@ -45,4 +45,4 @@
  @param decay Probability of the value +/- 1, multiplied by 16384
  @return Value decoded
  */
-int ec_laplace_decode(ec_dec *dec, int fs, int decay);
+int ec_laplace_decode(ec_dec *dec, unsigned fs, int decay);
--- a/libcelt/mathops.h
+++ b/libcelt/mathops.h
@@ -148,7 +148,7 @@
    opus_val16 n, frac;
    /* -0.41509302963303146, 0.9609890551383969, -0.31836011537636605,
        0.15530808010959576, -0.08556153059057618 */
-   static const opus_val16 C[5] = {-6801+(1<<13-DB_SHIFT), 15746, -5217, 2545, -1401};
+   static const opus_val16 C[5] = {-6801+(1<<(13-DB_SHIFT)), 15746, -5217, 2545, -1401};
    if (x==0)
       return -32767;
    i = celt_ilog2(x);
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -306,7 +306,7 @@
    if (!intra)
    {
       ec_enc enc_intra_state;
-      int tell_intra;
+      opus_int32 tell_intra;
       opus_uint32 nstart_bytes;
       opus_uint32 nintra_bytes;
       int badness2;
@@ -329,7 +329,7 @@
       badness2 = quant_coarse_energy_impl(m, start, end, eBands, oldEBands, budget,
             tell, e_prob_model[LM][intra], error, enc, C, LM, 0, max_decay);
 
-      if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ec_tell_frac(enc)+intra_bias > tell_intra)))
+      if (two_pass && (badness1 < badness2 || (badness1 == badness2 && ((opus_int32)ec_tell_frac(enc))+intra_bias > tell_intra)))
       {
          *enc = enc_intra_state;
          /* Copy intra bits to bit-stream */