changeset 26:ff6110f1144b

* Added an additional buffer in AutocorrelationProcessor::process() - possibly a little bit slower, but much easier to debug!
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Wed, 20 Aug 2014 16:32:52 +0100
parents fe23998968b4
children a3a37c8dcee7
files AutocorrelationProcessor.cpp AutocorrelationProcessor.h TempogramPlugin.cpp
diffstat 3 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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<float> AutocorrelationProcessor::processBlock(float * blockInput, const size_t &blockLength) const
+vector<float> AutocorrelationProcessor::processBlock() const
 {
     vector<float> 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));
     }
--- 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<float> 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<float> processBlock() const;
 };
 
 #endif /* defined(__Tempogram__Autocorrelation__) */
--- 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();