Renamed some funciton that were likely to clash with other (non-Opus) code
[opus.git] / libcelt / bands.c
index d057c26..835d726 100644 (file)
@@ -41,7 +41,7 @@
 #include "mathops.h"
 #include "rate.h"
 
-opus_uint32 lcg_rand(opus_uint32 seed)
+opus_uint32 celt_lcg_rand(opus_uint32 seed)
 {
    return 1664525 * seed + 1013904223;
 }
@@ -68,7 +68,7 @@ static int bitexact_log2tan(int isin,int icos)
    ls=EC_ILOG(isin);
    icos<<=15-lc;
    isin<<=15-ls;
-   return (ls-lc<<11)
+   return ((ls-lc)<<11)
          +FRAC_MUL16(isin, FRAC_MUL16(isin, -2597) + 7932)
          -FRAC_MUL16(icos, FRAC_MUL16(icos, -2597) + 7932);
 }
@@ -222,7 +222,7 @@ void anti_collapse(const CELTMode *m, celt_norm *_X, unsigned char *collapse_mas
 
       N0 = m->eBands[i+1]-m->eBands[i];
       /* depth in 1/8 bits */
-      depth = (1+pulses[i])/(m->eBands[i+1]-m->eBands[i]<<LM);
+      depth = (1+pulses[i])/((m->eBands[i+1]-m->eBands[i])<<LM);
 
 #ifdef FIXED_POINT
       thresh = MULT16_32_Q15(QCONST16(0.5f, 15), MIN32(32767,SHR32(celt_exp2(-SHL16(depth, 10-BITRES)),1) ));
@@ -283,7 +283,7 @@ void anti_collapse(const CELTMode *m, celt_norm *_X, unsigned char *collapse_mas
                /* Fill with noise */
                for (j=0;j<N0;j++)
                {
-                  seed = lcg_rand(seed);
+                  seed = celt_lcg_rand(seed);
                   X[(j<<LM)+k] = (seed&0x8000 ? r : -r);
                }
                renormalize = 1;
@@ -758,7 +758,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
          split = 1;
          LM -= 1;
          if (B==1)
-            fill = fill&1|fill<<1;
+            fill = (fill&1)|(fill<<1);
          B = (B+1)>>1;
       }
    }
@@ -903,14 +903,14 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
       {
          imid = 0;
          iside = 32767;
-         fill &= (1<<B)-1<<B;
+         fill &= ((1<<B)-1)<<B;
          delta = 16384;
       } else {
          imid = bitexact_cos(itheta);
          iside = bitexact_cos(16384-itheta);
          /* This is the mid vs side allocation that minimizes squared error
             in that band. */
-         delta = FRAC_MUL16(N-1<<7,bitexact_log2tan(iside,imid));
+         delta = FRAC_MUL16((N-1)<<7,bitexact_log2tan(iside,imid));
       }
 
 #ifdef FIXED_POINT
@@ -1020,13 +1020,13 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
                folding will be done to the side. */
             cm |= quant_band(encode, m, i, Y, NULL, N, sbits, spread, B, intensity, tf_change,
                   next_lowband2, ec, remaining_bits, LM, NULL,
-                  NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<(B0>>1&stereo-1);
+                  NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<((B0>>1)&(stereo-1));
          } else {
             /* For a stereo split, the high bits of fill are always zero, so no
                folding will be done to the side. */
             cm = quant_band(encode, m, i, Y, NULL, N, sbits, spread, B, intensity, tf_change,
                   next_lowband2, ec, remaining_bits, LM, NULL,
-                  NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<(B0>>1&stereo-1);
+                  NULL, next_level, seed, MULT16_16_P15(gain,side), NULL, fill>>B)<<((B0>>1)&(stereo-1));
             rebalance = sbits - (rebalance-*remaining_bits);
             if (rebalance > 3<<BITRES && itheta!=16384)
                mbits += rebalance - (3<<BITRES);
@@ -1082,8 +1082,8 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
                   /* Noise */
                   for (j=0;j<N;j++)
                   {
-                     *seed = lcg_rand(*seed);
-                     X[j] = (opus_int32)(*seed)>>20;
+                     *seed = celt_lcg_rand(*seed);
+                     X[j] = (celt_norm)((opus_int32)*seed>>20);
                   }
                   cm = cm_mask;
                } else {
@@ -1091,7 +1091,7 @@ static unsigned quant_band(int encode, const CELTMode *m, int i, celt_norm *X, c
                   for (j=0;j<N;j++)
                   {
                      opus_val16 tmp;
-                     *seed = lcg_rand(*seed);
+                     *seed = celt_lcg_rand(*seed);
                      /* About 48 dB below the "normal" folding level */
                      tmp = QCONST16(1.0f/256, 10);
                      tmp = (*seed)&0x8000 ? tmp : -tmp;