Mercurial > hg > vamp-tempogram
changeset 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 |
files | FIRFilter.cpp FIRFilter.h Spectrogram.cpp Tempogram.cpp |
diffstat | 4 files changed, 29 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/FIRFilter.cpp Thu Aug 07 16:21:21 2014 +0100 +++ b/FIRFilter.cpp Thu Aug 07 17:25:24 2014 +0100 @@ -12,8 +12,8 @@ using Vamp::FFT; FIRFilter::FIRFilter(const unsigned int lengthInput, const unsigned int numberOfCoefficients) : - _lengthInput(lengthInput), - _numberOfCoefficients(numberOfCoefficients), + m_lengthInput(lengthInput), + m_numberOfCoefficients(numberOfCoefficients), fftInput(NULL), fftCoefficients(NULL), fftReal1(NULL), @@ -36,20 +36,20 @@ void FIRFilter::initialise() { - _lengthFIRFFT = pow(2,(ceil(log2(_lengthInput+_numberOfCoefficients-1)))); + m_lengthFIRFFT = pow(2,(ceil(log2(m_lengthInput+m_numberOfCoefficients-1)))); - fftInput = new double[_lengthFIRFFT]; - fftCoefficients = new double[_lengthFIRFFT]; - fftReal1 = new double[_lengthFIRFFT]; - fftImag1 = new double[_lengthFIRFFT]; - fftReal2 = new double[_lengthFIRFFT]; - fftImag2 = new double[_lengthFIRFFT]; - fftFilteredReal = new double[_lengthFIRFFT]; - fftFilteredImag = new double[_lengthFIRFFT]; - fftOutputReal = new double[_lengthFIRFFT]; - fftOutputImag = new double[_lengthFIRFFT]; + fftInput = new double[m_lengthFIRFFT]; + fftCoefficients = new double[m_lengthFIRFFT]; + fftReal1 = new double[m_lengthFIRFFT]; + fftImag1 = new double[m_lengthFIRFFT]; + fftReal2 = new double[m_lengthFIRFFT]; + fftImag2 = new double[m_lengthFIRFFT]; + fftFilteredReal = new double[m_lengthFIRFFT]; + fftFilteredImag = new double[m_lengthFIRFFT]; + fftOutputReal = new double[m_lengthFIRFFT]; + fftOutputImag = new double[m_lengthFIRFFT]; - for(int i = 0; i < _lengthFIRFFT; i++){ + for(int i = 0; i < m_lengthFIRFFT; i++){ fftInput[i] = fftCoefficients[i] = fftReal1[i] = fftImag1[i] = fftReal2[i] = fftImag2[i] = fftFilteredReal[i] = fftFilteredImag[i] = fftOutputReal[i] = fftOutputImag[i] = 0.0; } } @@ -57,21 +57,21 @@ void FIRFilter::process(const float* input, const float* coefficients, float* output) { - for(int i = 0; i < _lengthFIRFFT; i++){ - fftInput[i] = i < _lengthInput ? input[i] : 0.0; - fftCoefficients[i] = i < _numberOfCoefficients ? coefficients[i] : 0.0; + for(int i = 0; i < m_lengthFIRFFT; i++){ + fftInput[i] = i < m_lengthInput ? input[i] : 0.0; + fftCoefficients[i] = i < m_numberOfCoefficients ? coefficients[i] : 0.0; } - FFT::forward(_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); - FFT::forward(_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); + FFT::forward(m_lengthFIRFFT, fftInput, NULL, fftReal1, fftImag1); + FFT::forward(m_lengthFIRFFT, fftCoefficients, NULL, fftReal2, fftImag2); - for (int i = 0; i < _lengthFIRFFT; i++){ + for (int i = 0; i < m_lengthFIRFFT; i++){ fftFilteredReal[i] = (fftReal1[i] * fftReal2[i]) - (fftImag1[i] * fftImag2[i]); fftFilteredImag[i] = (fftReal1[i] * fftImag2[i]) + (fftReal2[i] * fftImag1[i]); } - FFT::inverse(_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); + FFT::inverse(m_lengthFIRFFT, fftFilteredReal, fftFilteredImag, fftOutputReal, fftOutputImag); - for (int i = 0; i < _lengthInput; i++){ + for (int i = 0; i < m_lengthInput; i++){ output[i] = fftOutputReal[i]; } }
--- a/FIRFilter.h Thu Aug 07 16:21:21 2014 +0100 +++ b/FIRFilter.h Thu Aug 07 17:25:24 2014 +0100 @@ -20,9 +20,9 @@ ~FIRFilter(); void process(const float *input, const float *coefficients, float *output); private: - unsigned int _lengthInput; - unsigned int _numberOfCoefficients; - unsigned int _lengthFIRFFT; + unsigned int m_lengthInput; + unsigned int m_numberOfCoefficients; + unsigned int m_lengthFIRFFT; double *fftInput; double *fftCoefficients;
--- 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;
--- a/Tempogram.cpp Thu Aug 07 16:21:21 2014 +0100 +++ b/Tempogram.cpp Thu Aug 07 17:25:24 2014 +0100 @@ -269,12 +269,12 @@ cleanupForGRF(); ncTimestamps.clear(); specData.clear(); + specData = vector< vector<float> >(m_blockSize/2 + 1); } Tempogram::FeatureSet Tempogram::process(const float *const *inputBuffers, Vamp::RealTime timestamp) { - size_t n = m_blockSize/2 + 1; FeatureSet featureSet; @@ -337,10 +337,7 @@ WindowFunction::hanning(hannWindowtN, tN); Spectrogram * spectrogramProcessor = new Spectrogram(numberOfBlocks, tN, thopSize); vector< vector<float> > tempogram = spectrogramProcessor->audioToMagnitudeSpectrogram(&noveltyCurve[0], hannWindowtN); - - cout << "About to delete..." << endl; delete spectrogramProcessor; - cout << "Deleted!" << endl; spectrogramProcessor = NULL; int timePointer = thopSize-tN/2; @@ -351,8 +348,6 @@ int timeMS = floor(1000*(m_stepSize*timePointer)/m_inputSampleRate + 0.5); - cout << timeMS << endl; - for(int k = 0; k < tN/2 + 1; k++){ feature.values.push_back(tempogram[k][block]); }