shithub: opus

Download patch

ref: 6f1cbca519ad1daa59093135da13d9de575e65eb
parent: 663c0492bb9a978c2c91f9f46afd84455f450742
author: Jean-Marc Valin <[email protected]>
date: Sat Jul 24 18:06:29 EDT 2010

More cleanup

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -363,7 +363,7 @@
    }
 }
 
-
+/* Decide whether we should spread the pulses in the current frame */
 int folding_decision(const CELTMode *m, celt_norm *X, celt_word16 *average, int *last_decision, int end, int _C, int M)
 {
    int i, c, N0;
@@ -803,6 +803,7 @@
          if (lowband && !stereo)
             next_lowband2 = lowband+N; /* >32-bit split case */
 
+         /* Only stereo needs to pass on lowband_out. Otherwise, it's handled at the end */
          if (stereo)
             next_lowband_out1 = lowband_out;
          else
@@ -829,9 +830,9 @@
 
       /* Finally do the actual quantization */
       if (encode)
-         alg_quant(X, N, q, spread ? B : 0, lowband, resynth, (ec_enc*)ec, seed);
+         alg_quant(X, N, q, spread, B, lowband, resynth, (ec_enc*)ec, seed);
       else
-         alg_unquant(X, N, q, spread ? B : 0, lowband, (ec_dec*)ec, seed);
+         alg_unquant(X, N, q, spread, B, lowband, (ec_dec*)ec, seed);
    }
 
    /* This code is used by the decoder and by the resynthesis-enabled encoder */
@@ -898,6 +899,8 @@
       if (stereo)
       {
          stereo_band_mix(m, X, Y, bandE, 0, i, -1, N);
+         /* We only need to renormalize because quantization may not
+            have preserved orthogonality of mid and side */
          renormalise_vector(X, Q15ONE, N, 1);
          renormalise_vector(Y, Q15ONE, N, 1);
       }
@@ -953,6 +956,7 @@
       else
          tell = ec_dec_tell((ec_dec*)ec, BITRES);
 
+      /* Compute how many bits we want to allocate to this band */
       if (i != start)
          balance -= tell;
       remaining_bits = (total_bits<<BITRES)-tell-1;
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -154,7 +154,7 @@
    while (++i < N);
 }
 
-void alg_quant(celt_norm *X, int N, int K, int spread, celt_norm *lowband, int resynth, ec_enc *enc, celt_int32 *seed)
+void alg_quant(celt_norm *X, int N, int K, int spread, int B, celt_norm *lowband, int resynth, ec_enc *enc, celt_int32 *seed)
 {
    VARDECL(celt_norm, y);
    VARDECL(int, iy);
@@ -198,7 +198,7 @@
    N_1 = 512/N;
    
    if (spread)
-      exp_rotation(X, N, 1, spread, K);
+      exp_rotation(X, N, 1, B, K);
 
    sum = 0;
    j=0; do {
@@ -332,7 +332,7 @@
    {
       normalise_residual(iy, X, N, K, EXTRACT16(SHR32(yy,2*yshift)));
       if (spread)
-         exp_rotation(X, N, -1, spread, K);
+         exp_rotation(X, N, -1, B, K);
    }
    RESTORE_STACK;
 }
@@ -340,12 +340,13 @@
 
 /** Decode pulse vector and combine the result with the pitch vector to produce
     the final normalised signal in the current band. */
-void alg_unquant(celt_norm *X, int N, int K, int spread, celt_norm *lowband, ec_dec *dec, celt_int32 *seed)
+void alg_unquant(celt_norm *X, int N, int K, int spread, int B, celt_norm *lowband, ec_dec *dec, celt_int32 *seed)
 {
    int i;
    celt_word32 Ryy;
    VARDECL(int, iy);
    SAVE_STACK;
+
    if (K==0)
    {
       if (lowband != NULL)
@@ -373,7 +374,7 @@
    } while (++i < N);
    normalise_residual(iy, X, N, K, Ryy);
    if (spread)
-      exp_rotation(X, N, -1, spread, K);
+      exp_rotation(X, N, -1, B, K);
    RESTORE_STACK;
 }
 
--- a/libcelt/vq.h
+++ b/libcelt/vq.h
@@ -51,7 +51,7 @@
  * @param p Pitch vector (it is assumed that p+x is a unit vector)
  * @param enc Entropy encoder state
 */
-void alg_quant(celt_norm *X, int N, int K, int spread, celt_norm *lowband, int resynth, ec_enc *enc, celt_int32 *seed);
+void alg_quant(celt_norm *X, int N, int K, int spread, int B, celt_norm *lowband, int resynth, ec_enc *enc, celt_int32 *seed);
 
 /** Algebraic pulse decoder
  * @param x Decoded normalised spectrum (returned)
@@ -60,7 +60,7 @@
  * @param p Pitch vector (automatically added to x)
  * @param dec Entropy decoder state
  */
-void alg_unquant(celt_norm *X, int N, int K, int spread, celt_norm *lowband, ec_dec *dec, celt_int32 *seed);
+void alg_unquant(celt_norm *X, int N, int K, int spread, int B, celt_norm *lowband, ec_dec *dec, celt_int32 *seed);
 
 celt_word16 renormalise_vector(celt_norm *X, celt_word16 value, int N, int stride);