# HG changeset patch # User Carl Bussey # Date 1408548772 -3600 # Node ID ff6110f1144b9fa6ee083fb0a9c5c0a50f9cd556 # Parent fe23998968b4b85c6a2e108daf138d482f573c96 * Added an additional buffer in AutocorrelationProcessor::process() - possibly a little bit slower, but much easier to debug! diff -r fe23998968b4 -r ff6110f1144b AutocorrelationProcessor.cpp --- a/AutocorrelationProcessor.cpp Wed Aug 20 16:00:37 2014 +0100 +++ b/AutocorrelationProcessor.cpp Wed Aug 20 16:32:52 2014 +0100 @@ -9,12 +9,17 @@ #include "AutocorrelationProcessor.h" using namespace std; -AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize, const unsigned int &lagIncrement) : +AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) : m_windowLength(windowLength), m_hopSize(hopSize), - m_lagIncrement(lagIncrement) + m_blockInput(0) { - //Nothing to do here + m_blockInput = new float [m_windowLength]; +} + +AutocorrelationProcessor::~AutocorrelationProcessor(){ + delete []m_blockInput; + m_blockInput = 0; } AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const @@ -23,16 +28,23 @@ AutoCorrelation autocorrelation; while(readBlockPointerIndex <= (int)inputLength) { - int readPointer = readBlockPointerIndex - m_windowLength/2; + int readPointer = readBlockPointerIndex - m_windowLength/2; //read window centered at readBlockPointerIndex - autocorrelation.push_back(processBlock(&input[readPointer], min(inputLength-readPointer, m_windowLength))); + for (int n = 0; n < (int)m_windowLength; n++){ + if (readPointer < 0 || readPointer >= (int)inputLength) m_blockInput[n] = 0.0f; + else m_blockInput[n] = input[readPointer]; + + readPointer++; + } + + autocorrelation.push_back(processBlock()); readBlockPointerIndex += m_hopSize; } return autocorrelation; } -vector AutocorrelationProcessor::processBlock(float * blockInput, const size_t &blockLength) const +vector AutocorrelationProcessor::processBlock() const { vector autocorrelation; @@ -40,10 +52,9 @@ for (int lag = 0; lag < N; lag++){ float sum = 0; - int sampleLag = m_lagIncrement*lag; - - for (int n = sampleLag; n < (int)blockLength; n++){ - sum += blockInput[n-sampleLag]*blockInput[n]; + + for (int n = 0; n < (int)m_windowLength-lag; n++){ + sum += m_blockInput[lag]*m_blockInput[n+lag]; } autocorrelation.push_back(sum/(2*N + 1 - lag)); } diff -r fe23998968b4 -r ff6110f1144b AutocorrelationProcessor.h --- a/AutocorrelationProcessor.h Wed Aug 20 16:00:37 2014 +0100 +++ b/AutocorrelationProcessor.h Wed Aug 20 16:32:52 2014 +0100 @@ -16,14 +16,16 @@ class AutocorrelationProcessor{ public: - AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize, const unsigned int &lagIncrement); + AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize); + ~AutocorrelationProcessor(); AutoCorrelation process(float * input, const size_t &inputLength) const; - std::vector processBlock(float * input, const size_t &inputLength) const; private: size_t m_windowLength; unsigned int m_hopSize; unsigned int m_lagIncrement; + float * m_blockInput; + std::vector processBlock() const; }; #endif /* defined(__Tempogram__Autocorrelation__) */ diff -r fe23998968b4 -r ff6110f1144b TempogramPlugin.cpp --- a/TempogramPlugin.cpp Wed Aug 20 16:00:37 2014 +0100 +++ b/TempogramPlugin.cpp Wed Aug 20 16:32:52 2014 +0100 @@ -474,8 +474,7 @@ delete []hannWindow; hannWindow = 0; - int tempogramLag = 1; - AutocorrelationProcessor autocorrelationProcessor(m_tempogramWindowLength, m_tempogramHopSize, tempogramLag); + AutocorrelationProcessor autocorrelationProcessor(m_tempogramWindowLength, m_tempogramHopSize); Tempogram tempogramACT = autocorrelationProcessor.process(&noveltyCurve[0], numberOfBlocks); int tempogramLength = tempogramDFT.size();