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

jm at svn.xiph.org jm at svn.xiph.org
Sat Aug 25 04:13:36 PDT 2007


Author: jm
Date: 2007-08-25 04:13:36 -0700 (Sat, 25 Aug 2007)
New Revision: 13620

Modified:
   trunk/ghost/libghost/pitch.c
   trunk/ghost/libghost/pitch.h
Log:
Pitch estimation from an FFT instead (needs improvement)


Modified: trunk/ghost/libghost/pitch.c
===================================================================
--- trunk/ghost/libghost/pitch.c	2007-08-25 11:13:28 UTC (rev 13619)
+++ trunk/ghost/libghost/pitch.c	2007-08-25 11:13:36 UTC (rev 13620)
@@ -23,6 +23,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include "fftwrap.h"
 
 float inner_prod(float *x, float *y, int len)
 {
@@ -66,4 +67,50 @@
 }
 
 
-
+void find_spectral_pitch(float *x, float *y, int lag, int len, int *pitch)
+{
+   //FIXME: Yuck!!!
+   static void *fft;
+   
+   if (!fft)
+      fft = spx_fft_init(lag);
+   
+   float xx[lag];
+   float X[lag];
+   float Y[lag];
+   int i;
+   
+   for (i=0;i<lag;i++)
+      xx[i] = 0;
+   for (i=0;i<len;i++)
+      xx[i] = x[i];
+   
+   spx_fft(fft, xx, X);
+   spx_fft(fft, y, Y);
+   X[0] = X[0]*Y[0];
+   for (i=1;i<lag/2;i++)
+   {
+      float n = 1.f/(1e3+sqrt((X[2*i-1]*X[2*i-1] + X[2*i  ]*X[2*i  ])*(Y[2*i-1]*Y[2*i-1] + Y[2*i  ]*Y[2*i  ])));
+      //n = 1;
+      float tmp = X[2*i-1];
+      X[2*i-1] = (X[2*i-1]*Y[2*i-1] + X[2*i  ]*Y[2*i  ])*n;
+      X[2*i  ] = (- X[2*i  ]*Y[2*i-1] + tmp*Y[2*i  ])*n;
+   }
+   X[len-1] = X[len-1]*Y[len-1];
+   X[0] = X[len-1] = 0;
+   spx_ifft(fft, X, xx);
+   
+   float max_corr=-1;
+   //int pitch;
+   *pitch = -1;
+   for (i=0;i<lag-len;i++)
+   {
+      //printf ("%f ", xx[i]);
+      if (xx[i] > max_corr)
+      {
+         *pitch = i;
+         max_corr = xx[i];
+      }
+   }
+   //printf ("%d\n", *pitch);
+}

Modified: trunk/ghost/libghost/pitch.h
===================================================================
--- trunk/ghost/libghost/pitch.h	2007-08-25 11:13:28 UTC (rev 13619)
+++ trunk/ghost/libghost/pitch.h	2007-08-25 11:13:36 UTC (rev 13620)
@@ -27,5 +27,6 @@
 
 void find_pitch(float *x, float *gain, float *pitch, int start, int end, int len);
 
+void find_spectral_pitch(float *x, float *y, int lag, int len, int *pitch);
 
 #endif



More information about the commits mailing list