changeset 228:b7f01ab7045e

* Give the chromagram an alternative entry point passing in frequency domain data * Centre the Hamming windows and do an fftshift when calculating sparse kernel
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 15 May 2006 15:07:27 +0000
parents f06672e8db10
children 0e42bf10f29a
files dsp/chromagram/Chromagram.cpp dsp/chromagram/Chromagram.h dsp/chromagram/ConstantQ.cpp
diffstat 3 files changed, 36 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/dsp/chromagram/Chromagram.cpp	Mon May 15 11:21:47 2006 +0000
+++ b/dsp/chromagram/Chromagram.cpp	Mon May 15 15:07:27 2006 +0000
@@ -113,25 +113,29 @@
 
 double* Chromagram::process( double *data )
 {
-    //initialise chromadata to 0
-    for (unsigned i=0; i<m_BPO; i++) 
-	m_chromadata[i]=0;
+    // FFT of current frame
+    m_FFT->process( m_frameSize, 0, data, NULL, m_FFTRe, m_FFTIm ); 
+
+    return process(m_FFTRe, m_FFTIm);
+}
+
+double* Chromagram::process( double *real, double *imag )
+{
+    // initialise chromadata to 0
+    for (unsigned i = 0; i < m_BPO; i++) m_chromadata[i] = 0;
 
     double cmax = 0.0;
     double cval = 0;
 
-    // FFT of current frame
-    m_FFT->process( m_frameSize, 0, data, NULL, m_FFTRe, m_FFTIm ); 
-
     // Calculate ConstantQ frame
-    m_ConstantQ->process( m_FFTRe, m_FFTIm, m_CQRe, m_CQIm );
+    m_ConstantQ->process( real, imag, m_CQRe, m_CQIm );
 	
     // add each octave of cq data into Chromagram
     const unsigned octaves = (int)floor(double( m_uK/m_BPO))-1;
-    for (unsigned octave=0; octave<=octaves; octave++) 
+    for (unsigned octave = 0; octave <= octaves; octave++) 
     {
 	unsigned firstBin = octave*m_BPO;
-	for (unsigned i=0; i<m_BPO; i++) 
+	for (unsigned i = 0; i < m_BPO; i++) 
 	{
 	    m_chromadata[i] += kabs( m_CQRe[ firstBin + i ], m_CQIm[ firstBin + i ]);
 	}
--- a/dsp/chromagram/Chromagram.h	Mon May 15 11:21:47 2006 +0000
+++ b/dsp/chromagram/Chromagram.h	Mon May 15 15:07:27 2006 +0000
@@ -30,7 +30,8 @@
     Chromagram( ChromaConfig Config );
     ~Chromagram();
 	
-    double* process( double *data );
+    double* process( double *data ); // time domain
+    double* process( double *real, double *imag ); // frequency domain
     void unityNormalise( double* src );
 
     // Complex arithmetic
@@ -56,7 +57,7 @@
     unsigned int m_frameSize;
     unsigned int m_hopSize;
 
-    FFT*	 m_FFT;
+    FFT* m_FFT;
     ConstantQ* m_ConstantQ;
 
     double* m_FFTRe;
--- a/dsp/chromagram/ConstantQ.cpp	Mon May 15 11:21:47 2006 +0000
+++ b/dsp/chromagram/ConstantQ.cpp	Mon May 15 15:07:27 2006 +0000
@@ -68,18 +68,36 @@
 	
     for (unsigned k = m_uK; k--; ) 
     {
+        for (unsigned u=0; u < m_FFTLength; u++) 
+        {
+            hammingWindowRe[u] = 0;
+            hammingWindowIm[u] = 0;
+        }
+        
 	// Computing a hamming window
 	const unsigned hammingLength = (int) ceil( m_dQ * m_FS / ( m_FMin * pow(2,((double)(k))/(double)m_BPO)));
+
+        unsigned origin = m_FFTLength/2 - hammingLength/2;
+
 	for (unsigned i=0; i<hammingLength; i++) 
 	{
 	    const double angle = 2*PI*m_dQ*i/hammingLength;
 	    const double real = cos(angle);
 	    const double imag = sin(angle);
 	    const double absol = hamming(hammingLength, i)/hammingLength;
-	    hammingWindowRe[ i ] = absol*real;
-	    hammingWindowIm[ i ] = absol*imag;
+	    hammingWindowRe[ origin + i ] = absol*real;
+	    hammingWindowIm[ origin + i ] = absol*imag;
 	}
 
+        for (unsigned i = 0; i < m_FFTLength/2; ++i) {
+            double temp = hammingWindowRe[i];
+            hammingWindowRe[i] = hammingWindowRe[i + m_FFTLength/2];
+            hammingWindowRe[i + m_FFTLength/2] = temp;
+            temp = hammingWindowIm[i];
+            hammingWindowIm[i] = hammingWindowIm[i + m_FFTLength/2];
+            hammingWindowIm[i + m_FFTLength/2] = temp;
+        }
+    
 	//do fft of hammingWindow
 	m_FFT.process( m_FFTLength, 0, hammingWindowRe, hammingWindowIm, transfHammingWindowRe, transfHammingWindowIm );