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

jm at svn.xiph.org jm at svn.xiph.org
Sat Aug 25 07:37:22 PDT 2007


Author: jm
Date: 2007-08-25 07:37:22 -0700 (Sat, 25 Aug 2007)
New Revision: 13625

Modified:
   trunk/ghost/libghost/ceft.c
   trunk/ghost/libghost/ghost.c
Log:
Think I've got the pitch right now.


Modified: trunk/ghost/libghost/ceft.c
===================================================================
--- trunk/ghost/libghost/ceft.c	2007-08-25 14:16:07 UTC (rev 13624)
+++ trunk/ghost/libghost/ceft.c	2007-08-25 14:37:22 UTC (rev 13625)
@@ -242,28 +242,21 @@
 
 #define NBANDS 23 /*or 22 if we discard the small last band*/
 int qbank[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
-#if 0
+
+
+#if 1
 #define PBANDS 6
 int pbank[] = {1, 5, 9, 20, 44, 84, 128};
+//#define PBANDS 22 /*or 22 if we discard the small last band*/
+//int pbank[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 20, 24, 28, 36, 44, 52, 68, 84, 116, 128};
+
 #else
+
 #define PBANDS 1
 int pbank[] = {1, 128};
+
 #endif
 
-#if 0
-void compute_bank(float *ps, float *bank)
-{
-   int i;
-   for (i=0;i<NBANDS;i++)
-   {
-      int j;
-      bank[i]=0;
-      for (j=qbank[i];j<qbank[i+1];j++)
-         bank[i] += ps[j];
-      bank[i] = sqrt(bank[i]/(qbank[i+1]-qbank[i]));
-   }
-}
-#else
 void compute_bank(float *X, float *bank)
 {
    int i;
@@ -282,7 +275,6 @@
    //FIXME: Kludge
    X[255] = 1;
 }
-#endif
 
 void normalise_bank(float *X, float *bank)
 {
@@ -375,6 +367,10 @@
          Sxy += X[j*2]*P[j*2];
       }
       gain = Sxy/(2*(pbank[i+1]-pbank[i]));
+      //if (i<3)
+      //gain *= 1+.02*gain;
+      if (gain > .95)
+         gain = .95;
       for (j=pbank[i];j<pbank[i+1];j++)
       {
          P[j*2-1] *= gain;
@@ -409,6 +405,9 @@
       Rxp *= .5/(qbank[i+1]-qbank[i]);
       Rpp *= .5/(qbank[i+1]-qbank[i]);
       gain1 = sqrt(Rxp*Rxp + 1 - Rpp)-Rxp;
+      if (Rpp>.9999)
+         Rpp = .9999;
+      gain1 = sqrt(1.-Rpp);
       //gain2 = -sqrt(Rxp*Rxp + 1 - Rpp)-Rxp;
       //if (fabs(gain2)<fabs(gain1))
       //   gain1 = gain2;
@@ -422,7 +421,7 @@
          Rxx += X[j*2-1]*X[j*2-1];
          Rxx += X[j*2  ]*X[j*2  ];
       }
-      //printf ("%f ", gain1);
+      //printf ("%f %f ", gain1, Rxx);
    }
    //printf ("\n");
    //FIXME: Kludge
@@ -450,6 +449,7 @@
 {
    //float bark[BARK_BANDS];
    float X[st->length];
+   float Xbak[st->length];
    float Xp[st->length];
    int i;
    float bank[NBANDS];
@@ -459,6 +459,14 @@
    for (i=0;i<st->length;i++)
       p[i] = pitch[i]*window[i];
    
+#if 0
+   for (i=0;i<st->length;i++)
+      printf ("%f ", p[i]);
+   for (i=0;i<st->length;i++)
+      printf ("%f ", in[i]);
+   printf ("\n");
+#endif
+                    
    spx_fft_float(st->frame_fft, in, X);
    spx_fft_float(st->frame_fft, p, Xp);
    
@@ -470,6 +478,9 @@
    compute_bank(Xp, pitch_bank);
    normalise_bank(Xp, pitch_bank);
    
+   
+   for(i=0;i<st->length;i++)
+      Xbak[i] = X[i];
    /*for(i=0;i<st->length;i++)
       printf ("%f ", X[i]);
    printf ("\n");
@@ -477,6 +488,23 @@
    pitch_quant_bank(X, Xp);
    
    if (1) {
+#if 0
+      for (i=0;i<st->length;i++)
+         printf ("%f ", X[i]);
+      for (i=0;i<st->length;i++)
+         printf ("%f ", Xp[i]);
+      printf ("\n");
+#endif
+#if 0
+      float err1=0, err2=0, err0=0;
+      for (i=0;i<19;i++)
+      {
+         err0 += (X[i])*(X[i]);
+         err1 += (X[i]-Xp[i])*(X[i]-Xp[i]);
+         err2 += (X[i]-.7*Xp[i])*(X[i]-.7*Xp[i]);
+      }
+      printf ("%f %f %f ", err0, err1, err2);
+#endif
       for (i=1;i<st->length;i++)
          X[i] -= Xp[i];
       float tmp[NBANDS];
@@ -495,6 +523,15 @@
    if (1) {
       pitch_renormalise_bank(X, Xp);
    }
+   compute_bank(X, bank2);
+   normalise_bank(X, bank2);
+
+#if 0
+   float err = 0;
+   for(i=1;i<19;i++)
+      err += (Xbak[i] - X[i])*(Xbak[i] - X[i]);
+   printf ("%f\n", err);
+#endif
    
    /* Denormalise back to real power */
    denormalise_bank(X, bank);

Modified: trunk/ghost/libghost/ghost.c
===================================================================
--- trunk/ghost/libghost/ghost.c	2007-08-25 14:16:07 UTC (rev 13624)
+++ trunk/ghost/libghost/ghost.c	2007-08-25 14:37:22 UTC (rev 13625)
@@ -114,9 +114,12 @@
    }
    for (i=0;i<st->overlap;i++)
    {
-      st->synthesis_window[i] = st->analysis_window[i] = sqrt(.5-.5*cos(M_PI*(i+.5)/st->overlap));
-      st->synthesis_window[st->length-i-1] = st->analysis_window[st->length-i-1] = sqrt(.5-.5*cos(M_PI*(i+.5)/st->overlap));
+      //st->synthesis_window[i] = st->analysis_window[i] = sqrt(.5-.5*cos(M_PI*(i+.5)/st->overlap));
+      //st->synthesis_window[st->length-i-1] = st->analysis_window[st->length-i-1] = sqrt(.5-.5*cos(M_PI*(i+.5)/st->overlap));
       
+      st->synthesis_window[i] = st->analysis_window[i] =
+      st->synthesis_window[st->length-i-1] = st->analysis_window[st->length-i-1] = sin(.5*M_PI* sin(.5*M_PI*(i+.5)/st->overlap) * sin(.5*M_PI*(i+.5)/st->overlap));
+
       //st->analysis_window[i] = .5-.5*cos(M_PI*(i+.5)/st->overlap);
       //st->analysis_window[st->length-i-1] = .5-.5*cos(M_PI*(i+.5)/st->overlap);
             
@@ -245,7 +248,15 @@
          }
          //printf ("\n");
       }
-      //printf ("%f %d ", max_score, pitch_index);
+      int fpitch = -2;
+      float curve2[512];
+      for (i=0;i<512;i++)
+         curve2[i] = curve[(PCM_BUF_SIZE>>1)*i/512];
+
+      find_spectral_pitch(x, st->pitch_buf, 1024, st->length, &fpitch, curve2);
+      //printf ("%f %d %d\n", max_score, pitch_index, fpitch);
+      pitch_index = fpitch;
+      
       float z[st->length];
       for (i=0;i<st->length;i++)
          z[i] = x[i]-y[i];
@@ -274,6 +285,12 @@
       for (i=0;i<st->advance;i++)
          st->pitch_buf[PITCH_BUF_SIZE+i-st->advance] = st->current_frame[i]-st->new_noise[i];
                
+      //for (i=0;i<1024;i++)
+      //   printf ("%f ", st->pitch_buf[i]);
+      //for (i=0;i<st->length;i++)
+      //   printf ("%f ", x[i]);
+      //printf ("\n");
+
       /*for (i=0;i<st->overlap;i++)
          pcm[i] = st->syn_memory[i]+y[i];
       for (i=st->overlap;i<st->advance;i++)



More information about the commits mailing list