shithub: opus

Download patch

ref: ac1e03d78ed89eb0bbe03d1f4f35911c8ed2a3dc
parent: 636f5c86abfc06184dc7027daa76d5f288c63a42
author: Jean-Marc Valin <[email protected]>
date: Tue Feb 12 18:00:18 EST 2008

minor optimisation+tuning of vq search

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -237,7 +237,8 @@
    float norm[B*eBands[m->nbEBands+1]];
    int pulses[m->nbEBands];
    int offsets[m->nbEBands];
-   
+   float alpha = .7;
+
    for (i=0;i<m->nbEBands;i++)
       offsets[i] = 0;
    /* Use a single-bit margin to guard against overrunning (make sure it's enough) */
@@ -262,10 +263,13 @@
       if (eBands[i] >= m->pitchEnd || q<=0)
       {
          q -= 1;
+         alpha = 0;
          if (q<0)
             intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i]);
          else
             intra_prediction(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i], enc);
+      } else {
+         alpha = .7;
       }
       
       if (q > 0)
@@ -272,7 +276,7 @@
       {
          exp_rotation(P+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, -1, B, 8);
          exp_rotation(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, -1, B, 8);
-         alg_quant(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], 0.7, enc);
+         alg_quant(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], alpha, enc);
          exp_rotation(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, 1, B, 8);
       }
       for (j=B*eBands[i];j<B*eBands[i+1];j++)
@@ -294,7 +298,8 @@
    float norm[B*eBands[m->nbEBands+1]];
    int pulses[m->nbEBands];
    int offsets[m->nbEBands];
-   
+   float alpha = .7;
+
    for (i=0;i<m->nbEBands;i++)
       offsets[i] = 0;
    /* Use a single-bit margin to guard against overrunning (make sure it's enough) */
@@ -314,16 +319,19 @@
       if (eBands[i] >= m->pitchEnd || q<=0)
       {
          q -= 1;
+         alpha = 0;
          if (q<0)
             intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i]);
          else
             intra_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i], dec);
+      } else {
+         alpha = .7;
       }
       
       if (q > 0)
       {
          exp_rotation(P+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, -1, B, 8);
-         alg_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], 0.7, dec);
+         alg_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, P+B*eBands[i], alpha, dec);
          exp_rotation(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), theta, 1, B, 8);
       }
       for (j=B*eBands[i];j<B*eBands[i+1];j++)
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -115,10 +115,11 @@
          for (j=0;j<N;j++)
          {
             int sign;
+            //if (x[j]>0) sign=1; else sign=-1;
             for (sign=-1;sign<=1;sign+=2)
             {
                /* All pulses at one location must have the same size */
-               if (iy[m][j]*sign < 0)
+               if (iy[m][j]*sign < 0 || (x[j]*sign<0 && pulsesLeft>((K+1)>>1)))
                   continue;
                //fprintf (stderr, "%d/%d %d/%d %d/%d\n", i, K, m, L2, j, N);
                float tmp_xy, tmp_yy, tmp_yp;
@@ -200,6 +201,13 @@
       pulsesLeft -= pulsesAtOnce;
    }
    
+   if (0) {
+      float err=0;
+      for (i=0;i<N;i++)
+         err += (x[i]-gain[0]*y[0][i])*(x[i]-gain[0]*y[0][i]);
+      //if (N<=10)
+      //printf ("%f %d %d\n", err, K, N);
+   }
    for (i=0;i<N;i++)
       x[i] = p[i]+gain[0]*y[0][i];
    if (0) {