changeset 28:723af5b3303a

* Fixed tempogram via ACT bin names etc
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Thu, 21 Aug 2014 11:07:20 +0100
parents a3a37c8dcee7
children 1ad47a9afc2e
files AutocorrelationProcessor.cpp AutocorrelationProcessor.h TempogramPlugin.cpp TempogramPlugin.h
diffstat 4 files changed, 45 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/AutocorrelationProcessor.cpp	Wed Aug 20 16:48:54 2014 +0100
+++ b/AutocorrelationProcessor.cpp	Thu Aug 21 11:07:20 2014 +0100
@@ -8,18 +8,17 @@
 
 #include "AutocorrelationProcessor.h"
 using namespace std;
+#include <iostream>
 
 AutocorrelationProcessor::AutocorrelationProcessor(const size_t &windowLength, const unsigned int &hopSize) :
     m_windowLength(windowLength),
-    m_hopSize(hopSize),
-    m_blockInput(0)
+    m_hopSize(hopSize)
 {
-    m_blockInput = new float [m_windowLength];
+
 }
 
 AutocorrelationProcessor::~AutocorrelationProcessor(){
-    delete []m_blockInput;
-    m_blockInput = 0;
+
 }
 
 AutoCorrelation AutocorrelationProcessor::process(float * input, const size_t &inputLength) const
@@ -28,36 +27,27 @@
     AutoCorrelation autocorrelation;
     
     while(readBlockPointerIndex <= (int)inputLength) {
-        int readPointer = readBlockPointerIndex - m_windowLength/2; //read window centered at readBlockPointerIndex
         
-        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];
+        vector<float> autocorrelationBlock;
+        
+        for (int lag = 0; lag < (int)m_windowLength; lag++){
+            float sum = 0;
+            int readPointer = readBlockPointerIndex - m_windowLength/2;
             
-            readPointer++;
+            for (int n = 0; n < (int)m_windowLength; n++){
+                if (readPointer+lag >= (int)inputLength) break;
+                else if (readPointer >= 0) sum += input[readPointer]*input[readPointer+lag];
+                //else cout << readPointer << " : "<< lag << "/" << m_windowLength << endl;
+                
+                readPointer++;
+            }
+            autocorrelationBlock.push_back(sum/(2*m_windowLength + 1 - lag));
         }
         
-        autocorrelation.push_back(processBlock());
+        //autocorrelation.push_back(processBlock());
+        autocorrelation.push_back(autocorrelationBlock);
         readBlockPointerIndex += m_hopSize;
     }
     
     return autocorrelation;
 }
-
-vector<float> AutocorrelationProcessor::processBlock() const
-{
-    vector<float> autocorrelation;
-    
-    int N = m_windowLength;
-    
-    for (int lag = 0; lag < N; lag++){
-        float sum = 0;
-
-        for (int n = 0; n < N-lag; n++){
-            sum += m_blockInput[n]*m_blockInput[n+lag];
-        }
-        autocorrelation.push_back(sum/(2*N + 1 - lag));
-    }
-    
-    return autocorrelation;
-}
\ No newline at end of file
--- a/AutocorrelationProcessor.h	Wed Aug 20 16:48:54 2014 +0100
+++ b/AutocorrelationProcessor.h	Thu Aug 21 11:07:20 2014 +0100
@@ -22,9 +22,6 @@
 private:
     size_t m_windowLength;
     unsigned int m_hopSize;
-    float * m_blockInput;
-    
-    std::vector<float> processBlock() const;
 };
 
 #endif /* defined(__Tempogram__Autocorrelation__) */
--- a/TempogramPlugin.cpp	Wed Aug 20 16:48:54 2014 +0100
+++ b/TempogramPlugin.cpp	Thu Aug 21 11:07:20 2014 +0100
@@ -27,6 +27,8 @@
     m_tempogramMaxBPM(480), //parameter
     m_tempogramMinBin(0), //set in initialise()
     m_tempogramMaxBin(0), //set in initialise()
+    m_tempogramMinLag(0),
+    m_tempogramMaxLag(0),
     m_cyclicTempogramMinBPM(30), //reset in initialise()
     m_cyclicTempogramNumberOfOctaves(0), //set in initialise()
     m_cyclicTempogramOctaveDivider(30) //parameter
@@ -362,15 +364,14 @@
     d3.description = "Tempogram via ACT";
     d3.unit = "BPM";
     d3.hasFixedBinCount = true;
-    d3.binCount = m_tempogramMaxBin - m_tempogramMinBin + 1;
+    d3.binCount = m_tempogramMaxLag - m_tempogramMinLag + 1;
     d3.hasKnownExtents = false;
     d3.isQuantized = false;
     d3.sampleType = OutputDescriptor::FixedSampleRate;
     d_sampleRate = tempogramInputSampleRate/m_tempogramHopSize;
     d3.sampleRate = d_sampleRate > 0.0 && !isnan(d_sampleRate) ? d_sampleRate : 0.0;
-    for(int i = m_tempogramMinBin; i <= (int)m_tempogramMaxBin; i++){
-        float w = ((float)i/m_tempogramFftLength)*(tempogramInputSampleRate);
-        d3.binNames.push_back(floatToString(w*60));
+    for(int lag = m_tempogramMaxLag; lag >= (int)m_tempogramMinLag; lag--){
+        d3.binNames.push_back(floatToString(60/(m_inputStepSize*(lag/m_inputSampleRate))));
     }
     d3.hasDuration = false;
     list.push_back(d3);
@@ -474,24 +475,30 @@
     delete []hannWindow;
     hannWindow = 0;
     
-    AutocorrelationProcessor autocorrelationProcessor(m_tempogramWindowLength, m_tempogramHopSize);
-    Tempogram tempogramACT = autocorrelationProcessor.process(&noveltyCurve[0], numberOfBlocks);
-    
     int tempogramLength = tempogramDFT.size();
     
     //push tempogram data to featureset 0 and set timestamps.
     for (int block = 0; block < tempogramLength; block++){
         Feature tempogramDFTFeature;
+        
+        assert(tempogramDFT[block].size() == (m_tempogramFftLength/2 + 1));
+        for(int k = m_tempogramMinBin; k <= (int)m_tempogramMaxBin; k++){
+            tempogramDFTFeature.values.push_back(tempogramDFT[block][k]);
+        }
+        tempogramDFTFeature.hasTimestamp = false;
+        featureSet[1].push_back(tempogramDFTFeature);
+    }
+    
+    AutocorrelationProcessor autocorrelationProcessor(m_tempogramWindowLength, m_tempogramHopSize);
+    Tempogram tempogramACT = autocorrelationProcessor.process(&noveltyCurve[0], numberOfBlocks);
+    
+    for (int block = 0; block < tempogramLength; block++){
         Feature tempogramACTFeature;
         
-        assert(tempogramDFT[block].size() == (m_tempogramFftLength/2 + 1));
-        for(int k = m_tempogramMinBin; k < (int)m_tempogramMaxBin; k++){
-            tempogramDFTFeature.values.push_back(tempogramDFT[block][k]);
+        for(int k = m_tempogramMaxLag; k >= (int)m_tempogramMinLag; k--){
             tempogramACTFeature.values.push_back(tempogramACT[block][k]);
         }
-        tempogramDFTFeature.hasTimestamp = false;
         tempogramACTFeature.hasTimestamp = false;
-        featureSet[1].push_back(tempogramDFTFeature);
         featureSet[2].push_back(tempogramACTFeature);
     }
     
@@ -572,8 +579,11 @@
     }
     
     float tempogramInputSampleRate = (float)m_inputSampleRate/m_inputStepSize;
-    m_tempogramMinBin = (max(floor(((m_tempogramMinBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (float)0.0));
-    m_tempogramMaxBin = (min(ceil(((m_tempogramMaxBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (float)m_tempogramFftLength/2));
+    m_tempogramMinBin = (max((int)floor(((m_tempogramMinBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), 0));
+    m_tempogramMaxBin = (min((int)ceil(((m_tempogramMaxBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (int)(m_tempogramFftLength/2)));
+    
+    m_tempogramMinLag = max((int)ceil((60/(m_inputStepSize * m_tempogramMaxBPM))*m_inputSampleRate), 0);
+    m_tempogramMaxLag = min((int)floor((60/(m_inputStepSize * m_tempogramMinBPM))*m_inputSampleRate), (int)m_tempogramWindowLength);
     
     if (m_tempogramMinBPM > m_cyclicTempogramMinBPM) m_cyclicTempogramMinBPM = m_tempogramMinBPM; //m_cyclicTempogram can't be less than default = 30
     float cyclicTempogramMaxBPM = 480;
--- a/TempogramPlugin.h	Wed Aug 20 16:48:54 2014 +0100
+++ b/TempogramPlugin.h	Thu Aug 21 11:07:20 2014 +0100
@@ -98,6 +98,8 @@
     float m_tempogramMaxBPM; // tempogram output bin range max
     unsigned int m_tempogramMinBin;
     unsigned int m_tempogramMaxBin;
+    unsigned int m_tempogramMinLag;
+    unsigned int m_tempogramMaxLag;
     
     //Cyclic tempogram parameters
     float m_cyclicTempogramMinBPM;