[xiph-commits] r13758 - trunk/ghost/libghost

jm at svn.xiph.org jm at svn.xiph.org
Wed Sep 5 07:45:33 PDT 2007


Author: jm
Date: 2007-09-05 07:45:32 -0700 (Wed, 05 Sep 2007)
New Revision: 13758

Modified:
   trunk/ghost/libghost/ceft.c
Log:
Improved search a bit by considering the N-best at each stage (instead of the
1-best).


Modified: trunk/ghost/libghost/ceft.c
===================================================================
--- trunk/ghost/libghost/ceft.c	2007-09-05 07:40:25 UTC (rev 13757)
+++ trunk/ghost/libghost/ceft.c	2007-09-05 14:45:32 UTC (rev 13758)
@@ -41,25 +41,10 @@
 //int qpulses[] = {4, 4, 3, 3, 3,  3,  3,  2,  2,  3,  2,  2,  0,  0,  0};
 //int qpulses[] = {5, 5, 5, 5, 5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5};
 
-//#define NBANDS 19
-//int qbank[] =   {1, 2, 3, 4, 5, 6, 8, 10, 12, 14, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
-//int qpulses[] = {3, 2, 2, 2, 2, 2, 2,  2,  2,  2,  2,  2,  2,  2,  2,  0,  0,  0,  0};
-//int qpulses[] = {3, 2, 2, 2, 2, 2, 2,  2,  2,  1,  1,  1,  1,  2,  2,  0,  0,  0,  0};
 
-//int qpulses[] = {3, 3, 2, 2, 2, 2, 2,  2,  2,  2,  3,  2,  2,  2,  3,  0,  0,  0,  0};
-
-//int qpulses[] = {5, 5, 5, 5, 5, 5, 5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5,  5};
-//int qpulses[] = {1, 1, 1, 1, 1, 2, 2,  2,  2,  2,  2,  2,  2,  2,  2,  1,  1,  1,  1};
-
-//#define PBANDS 5
-//int pbank[] = {1, 4, 10, 16, 28, 44};
-
 #define PBANDS 5
 int pbank[] = {1, 4, 8, 12, 20, 44};
 
-//#define PBANDS NBANDS
-//#define pbank qbank
-
 void alg_quant(float *x, int N, int K, float *p)
 {
    float y[N];
@@ -73,39 +58,7 @@
       Rpp += p[j]*p[j];
    for (i=0;i<N;i++)
       y[i] = 0;
-   
-   float boost[N];
-   for (i=0;i<N;i++)
-      boost[i] = 0;
-   if (0&&K==1)
-   {
-      float centre;
-      float Sxw = 0, Sw = 1e-10;
-      for (i=0;i<N/2;i++)
-      {
-         float weight = x[2*i]*x[2*i] + x[2*i+1]*x[2*i+1];
-         Sxw += i*weight;
-         Sw  += weight;
-      }
-      centre = Sxw/Sw;
-      centre = floor(centre)+(rand()&1);
-      //printf ("%d ", (int)centre);
-      for (i=0;i<N/2;i++)
-         boost[2*i] = boost[2*i+1] = (1.f/N)*(N-fabs(i-centre));
-   }
-   
-   if (0)
-   {
-      int tmp = N;
-      int b=0;
-      while (tmp>1)
-      {
-         b++;
-         tmp >>= 1;
-      }
-      printf ("%d\n", 1+K*b);
-   }
-   
+      
    for (i=0;i<K;i++)
    {
       int best_id=0;
@@ -123,9 +76,7 @@
          else
             tmp_yp = yp - p[j];
          g = (sqrt(tmp_yp*tmp_yp + tmp_yy - tmp_yy*Rpp) - tmp_yp)/tmp_yy;
-         //g = 1/sqrt(tmp_yy);
-         score = 2*g*tmp_xy - g*g*tmp_yy + boost[j];
-         //score = tmp_xy*tmp_xy/tmp_yy;
+         score = 2*g*tmp_xy - g*g*tmp_yy;
          if (score>max_val)
          {
             max_val = score;
@@ -135,24 +86,8 @@
             best_yp = tmp_yp;
             gain = g;
          }
-         if (0) {
-            float ny[N];
-            int k;
-            for (k=0;k<N;k++)
-               ny[k] = y[k];
-            if (x[j]>0)
-               ny[j] += 1;
-            else
-               ny[j] -= 1;
-            float E = 0;
-            for (k=0;k<N;k++)
-               E += (p[k]+g*ny[k])*(p[k]+g*ny[k]);
-            printf ("(%f %f %f) ", g, tmp_yp, E);
-         }
       }
-      
-      //if (K==1)
-      //   printf ("%d\n", best_id/2);
+
       xy = best_xy;
       yy = best_yy;
       yp = best_yp;
@@ -161,21 +96,120 @@
       else
          y[best_id] -= 1;
    }
-   if (0) {
-      int k;
-      float E = 0, Ex=0;
-      for (k=0;k<N;k++)
-         E += (p[k]+gain*y[k])*(p[k]+gain*y[k]);
-      for (k=0;k<N;k++)
-         Ex += (x[k]*x[k]);
-      printf ("** %f %f %f ", E, Ex, Rpp);
-   }
-   //printf ("\n");
+   
    for (i=0;i<N;i++)
       x[i] = p[i]+gain*y[i];
    
 }
 
+void alg_quant2(float *x, int N, int K, float *p)
+{
+   int L = 5;
+   float tata[200];
+   float y[L][N];
+   float tata2[200];
+   float ny[L][N];
+   int i, j, m;
+   float xy[L], nxy[L];
+   float yy[L], nyy[L];
+   float yp[L], nyp[L];
+   float best_scores[L];
+   float Rpp=0;
+   float gain[L];
+   int maxL = 1;
+   for (j=0;j<N;j++)
+      Rpp += p[j]*p[j];
+   for (m=0;m<L;m++)
+      for (i=0;i<N;i++)
+         y[m][i] = 0;
+      
+   for (m=0;m<L;m++)
+      for (i=0;i<N;i++)
+         ny[m][i] = 0;
+
+   for (m=0;m<L;m++)
+      xy[m] = yy[m] = yp[m] = gain[m] = 0;
+   
+   for (i=0;i<K;i++)
+   {
+      int L2 = L;
+      if (L>maxL)
+      {
+         L2 = maxL;
+         maxL *= N;
+      }
+      for (m=0;m<L;m++)
+         best_scores[m] = -1e10;
+
+      for (m=0;m<L2;m++)
+      {
+         for (j=0;j<N;j++)
+         {
+            //fprintf (stderr, "%d/%d %d/%d %d/%d\n", i, K, m, L2, j, N);
+            float tmp_xy, tmp_yy, tmp_yp;
+            float score;
+            float g;
+            tmp_xy = xy[m] + fabs(x[j]);
+            tmp_yy = yy[m] + 2*fabs(y[m][j]) + 1;
+            if (x[j]>0)
+               tmp_yp = yp[m] + p[j];
+            else
+               tmp_yp = yp[m] - p[j];
+            g = (sqrt(tmp_yp*tmp_yp + tmp_yy - tmp_yy*Rpp) - tmp_yp)/tmp_yy;
+            score = 2*g*tmp_xy - g*g*tmp_yy;
+
+            if (score>best_scores[L-1])
+            {
+               int k, n;
+               int id = L-1;
+               while (id > 0 && score > best_scores[id-1])
+                  id--;
+               
+               for (k=L-1;k>id;k--)
+               {
+                  nxy[k] = nxy[k-1];
+                  nyy[k] = nyy[k-1];
+                  nyp[k] = nyp[k-1];
+                  //fprintf(stderr, "%d %d \n", N, k);
+                  for (n=0;n<N;n++)
+                     ny[k][n] = ny[k-1][n];
+                  gain[k] = gain[k-1];
+                  best_scores[k] = best_scores[k-1];
+               }
+
+               nxy[id] = tmp_xy;
+               nyy[id] = tmp_yy;
+               nyp[id] = tmp_yp;
+               gain[id] = g;
+               for (n=0;n<N;n++)
+                  ny[id][n] = y[m][n];
+               if (x[j]>0)
+                  ny[id][j] += 1;
+               else
+                  ny[id][j] -= 1;
+               best_scores[id] = score;
+            }
+            
+         }
+         
+      }
+      int k,n;
+      for (k=0;k<L;k++)
+      {
+         xy[k] = nxy[k];
+         yy[k] = nyy[k];
+         yp[k] = nyp[k];
+         for (n=0;n<N;n++)
+            y[k][n] = ny[k][n];
+      }
+
+   }
+   
+   for (i=0;i<N;i++)
+      x[i] = p[i]+gain[0]*y[0][i];
+   
+}
+
 void noise_quant(float *x, int N, int K, float *p)
 {
    int i;
@@ -419,7 +453,7 @@
          q =qpulses[i];*/
       q =qpulses[i];
       if (q)
-         alg_quant(X+qbank[i]*2-1, 2*(qbank[i+1]-qbank[i]), q, P+qbank[i]*2-1);
+         alg_quant2(X+qbank[i]*2-1, 2*(qbank[i+1]-qbank[i]), q, P+qbank[i]*2-1);
       else
          noise_quant(X+qbank[i]*2-1, 2*(qbank[i+1]-qbank[i]), q, P+qbank[i]*2-1);
    }



More information about the commits mailing list