shithub: opus

Download patch

ref: c4711e4e11b0672e2b6466ae5df2209938d7aca3
parent: bbc010c4f3e63661442d35af8877ff5a5cce3903
author: Jean-Marc Valin <[email protected]>
date: Fri Oct 15 19:31:06 EDT 2010

More VQ search simplifications

--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -171,8 +171,8 @@
    celt_word16 s;
    int pulsesLeft;
    celt_word32 sum;
-   celt_word32 xy, yy;
-   int N_1; /* Inverse of N, in Q14 format (even for float) */
+   celt_word32 xy;
+   celt_word16 yy;
    SAVE_STACK;
 
    /* When there's no pulse, fill with noise or folded spectrum */
@@ -204,7 +204,6 @@
    ALLOC(y, N, celt_norm);
    ALLOC(iy, N, int);
    ALLOC(signx, N, celt_word16);
-   N_1 = 512/N;
    
    exp_rotation(X, N, 1, B, K, spread);
 
@@ -290,21 +289,18 @@
 #ifdef FIXED_POINT
       rshift = 1+celt_ilog2(K-pulsesLeft+i+1);
 #endif
-
       best_id = 0;
       /* The squared magnitude term gets added anyway, so we might as well 
          add it outside the loop */
-      yy = MAC16_16(yy, s,s);
-      /* Choose between fast and accurate strategy depending on where we are in the search */
-         /* This should ensure that anything we can process will have a better score */
+      yy = ADD32(yy, 1);
       j=0;
       do {
          celt_word16 Rxy, Ryy;
          /* Temporary sums of the new pulse(s) */
-         Rxy = EXTRACT16(SHR32(MAC16_16(xy, s,X[j]),rshift));
+         Rxy = EXTRACT16(SHR32(ADD32(xy, EXTEND32(X[j])),rshift));
          /* We're multiplying y[j] by two so we don't have to do it here */
-         Ryy = MAC16_16(yy, s,y[j]);
-            
+         Ryy = ADD16(yy, y[j]);
+
          /* Approximate score: we maximise Rxy/sqrt(Ryy) (we're guaranteed that
             Rxy is positive because the sign is pre-computed) */
          Rxy = MULT16_16_Q15(Rxy,Rxy);
@@ -319,17 +315,15 @@
          }
       } while (++j<N);
       
-      j = best_id;
-
       /* Updating the sums of the new pulse(s) */
-      xy = xy + MULT16_16(s,X[j]);
+      xy = ADD32(xy, EXTEND32(X[best_id]));
       /* We're multiplying y[j] by two so we don't have to do it here */
-      yy = yy + MULT16_16(s,y[j]);
+      yy = ADD16(yy, y[best_id]);
 
       /* Only now that we've made the final choice, update y/iy */
       /* Multiplying y[j] by 2 so we don't have to do it everywhere else */
-      y[j] += 2*s;
-      iy[j]++;
+      y[best_id] += 2*s;
+      iy[best_id]++;
    }
 
    /* Put the original sign back */