shithub: opus

Download patch

ref: dfe3bf9650617ff09eb6598e8296e4631ca85887
parent: d683c76b882224cb331268438c001ac46fe8e3ab
author: Jean-Marc Valin <[email protected]>
date: Wed Dec 19 02:19:54 EST 2012

First step in quant_band() cleanup: N=1 case.

--- a/celt/bands.c
+++ b/celt/bands.c
@@ -648,6 +648,41 @@
    return qn;
 }
 
+static unsigned quant_band_n1(int encode, celt_norm *X, celt_norm *Y, int b,
+      opus_int32 *remaining_bits, ec_ctx *ec, celt_norm *lowband_out)
+{
+#ifdef RESYNTH
+   int resynth = 1;
+#else
+   int resynth = !encode;
+#endif
+   int c;
+   int stereo;
+   celt_norm *x = X;
+   stereo = Y != NULL;
+   c=0; do {
+      int sign=0;
+      if (*remaining_bits>=1<<BITRES)
+      {
+         if (encode)
+         {
+            sign = x[0]<0;
+            ec_enc_bits(ec, sign, 1);
+         } else {
+            sign = ec_dec_bits(ec, 1);
+         }
+         *remaining_bits -= 1<<BITRES;
+         b-=1<<BITRES;
+      }
+      if (resynth)
+         x[0] = sign ? -NORM_SCALING : NORM_SCALING;
+      x = Y;
+   } while (++c<1+stereo);
+   if (lowband_out)
+      lowband_out[0] = SHR16(X[0],4);
+   return 1;
+}
+
 /* This function is responsible for encoding and decoding a band for both
    the mono and stereo case. Even in the mono case, it can split the band
    in two and transmit the energy difference with the two half-bands. It
@@ -688,29 +723,7 @@
    /* Special case for one sample */
    if (N==1)
    {
-      int c;
-      celt_norm *x = X;
-      c=0; do {
-         int sign=0;
-         if (*remaining_bits>=1<<BITRES)
-         {
-            if (encode)
-            {
-               sign = x[0]<0;
-               ec_enc_bits(ec, sign, 1);
-            } else {
-               sign = ec_dec_bits(ec, 1);
-            }
-            *remaining_bits -= 1<<BITRES;
-            b-=1<<BITRES;
-         }
-         if (resynth)
-            x[0] = sign ? -NORM_SCALING : NORM_SCALING;
-         x = Y;
-      } while (++c<1+stereo);
-      if (lowband_out)
-         lowband_out[0] = SHR16(X[0],4);
-      return 1;
+      return quant_band_n1(encode, X, Y, b, remaining_bits, ec, lowband_out);
    }
 
    if (!stereo && level == 0)