diff dsp/chromagram/Chromagram.cpp @ 467:1db23b9a8da4

Fix mismatch between time- and frequency-domain versions of the chromagram process method - the frequency-domain one expects fftshifted input and the kernel is set up for that, but the time-domain one wasn't doing it
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 29 May 2019 15:56:30 +0100
parents 46375e6d1b54
children a72d98f8baa3
line wrap: on
line diff
--- a/dsp/chromagram/Chromagram.cpp	Wed May 29 14:08:43 2019 +0100
+++ b/dsp/chromagram/Chromagram.cpp	Wed May 29 15:56:30 2019 +0100
@@ -121,7 +121,7 @@
 }
 
 
-double* Chromagram::process( const double *data )
+double *Chromagram::process(const double *data)
 {
     if (!m_skGenerated) {
         // Generate CQ Kernel 
@@ -139,12 +139,20 @@
     }
     m_window->cut(m_windowbuf);
 
+    // The frequency-domain version expects pre-fftshifted input - so
+    // we must do the same here
+    for (int i = 0; i < m_frameSize/2; ++i) {
+        double tmp = m_windowbuf[i];
+        m_windowbuf[i] = m_windowbuf[i + m_frameSize/2];
+        m_windowbuf[i + m_frameSize/2] = tmp;
+    }
+
     m_FFT->forward(m_windowbuf, m_FFTRe, m_FFTIm);
 
     return process(m_FFTRe, m_FFTIm);
 }
 
-double* Chromagram::process( const double *real, const double *imag )
+double *Chromagram::process(const double *real, const double *imag)
 {
     if (!m_skGenerated) {
         // Generate CQ Kernel