diff Spectrogram.cpp @ 8:4e429b9f2b4d

* Fixed memory leak bug. Issue with calculating size of spectrogram array. * Fixed bug in Tempogram::reset() where specData wasn't reinitialised.
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Thu, 07 Aug 2014 17:25:24 +0100
parents 21147df9cb2d
children be59b4a73f49
line wrap: on
line diff
--- a/Spectrogram.cpp	Thu Aug 07 16:21:21 2014 +0100
+++ b/Spectrogram.cpp	Thu Aug 07 17:25:24 2014 +0100
@@ -15,7 +15,7 @@
     m_inputLength(inputLength),
     m_fftLength(fftLength),
     m_hopSize(hopSize),
-    m_numberOfOutputBins(floor(fftLength/2 + 0.5) + 1),
+    m_numberOfOutputBins(ceil(fftLength/2) + 1),
     fftInput(NULL),
     fftOutputReal(NULL),
     fftOutputImag(NULL)
@@ -32,7 +32,7 @@
     fftOutputReal = new double [m_fftLength];
     fftOutputImag = new double [m_fftLength];
     
-    int numberOfBlocks = ceil(m_inputLength/m_hopSize) + m_fftLength/m_hopSize-1;
+    int numberOfBlocks = ceil(m_inputLength/m_hopSize) + 2*(ceil(m_fftLength/m_hopSize)-1); //The last term corresponds to overlaps at the beginning and end with padded zeros. I.e., if m_hopSize = m_fftLength/2, there'll be 1 overlap at each end. If m_hopSize = m_fftLength/4, there'll be 3 overlaps at each end, etc...
     spectrogramOutput = vector< vector<float> >(m_numberOfOutputBins, vector<float>(numberOfBlocks));
 }
 
@@ -42,8 +42,6 @@
     delete []fftOutputImag;
     
     fftInput = fftOutputReal = fftOutputImag = NULL;
-    
-    cerr << "Spectrogram" << endl;
 }
 
 vector< vector<float> > Spectrogram::audioToMagnitudeSpectrogram(const float * const input, const float * window){
@@ -69,6 +67,7 @@
         //@todo: sample at logarithmic spacing? Leave for host?
         for(int k = 0; k < m_numberOfOutputBins; k++){
             spectrogramOutput[k][writeBlockPointer] = (fftOutputReal[k]*fftOutputReal[k] + fftOutputImag[k]*fftOutputImag[k]); //Magnitude or power?
+            cerr << writeBlockPointer << " : " << spectrogramOutput[k].size() << endl;
         }
         
         readPointerBeginIndex += m_hopSize;