changeset 21:12b952286959

* Debugging 1Hz freeze using vamp-plugin-tester
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Mon, 18 Aug 2014 15:22:44 +0100
parents de7213b35755
children 99380ba63be6
files Makefile SpectrogramProcessor.cpp TempogramPlugin.cpp TempogramPlugin.h
diffstat 4 files changed, 49 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Aug 15 15:17:28 2014 +0100
+++ b/Makefile	Mon Aug 18 15:22:44 2014 +0100
@@ -40,7 +40,7 @@
 
 CXX := g++
 #-mmacosx-version-min=10.6
-CXXFLAGS := -mmacosx-version-min=10.6 -arch x86_64 -I$(VAMP_SDK_DIR) -Wall -Wextra -fPIC 
+CXXFLAGS := -g -mmacosx-version-min=10.6 -arch x86_64 -I$(VAMP_SDK_DIR) -Wall -Wextra -fPIC 
 PLUGIN_EXT := .dylib
 LDFLAGS := $(CXXFLAGS) -dynamiclib -install_name $(PLUGIN_LIBRARY_NAME)$(PLUGIN_EXT) /usr/local/lib/libvamp-sdk.a -exported_symbols_list vamp-plugin.list
 
--- a/SpectrogramProcessor.cpp	Fri Aug 15 15:17:28 2014 +0100
+++ b/SpectrogramProcessor.cpp	Mon Aug 18 15:22:44 2014 +0100
@@ -81,6 +81,7 @@
             m_pFftInput[n] = 0.0;
         }
         
+        //cerr << m_fftLength << endl;
         FFT::forward(m_fftLength, m_pFftInput, 0, m_pFftOutputReal, m_pFftOutputImag);
         
         vector<float> binValues;
--- a/TempogramPlugin.cpp	Fri Aug 15 15:17:28 2014 +0100
+++ b/TempogramPlugin.cpp	Mon Aug 18 15:22:44 2014 +0100
@@ -328,10 +328,25 @@
     // See OutputDescriptor documentation for the possibilities here.
     // Every plugin must have at least one output.
     
-    OutputDescriptor d1;
     float d_sampleRate;
     float tempogramInputSampleRate = (float)m_inputSampleRate/m_inputStepSize;
     
+    OutputDescriptor d3;
+    d3.identifier = "cyclicTempogram";
+    d3.name = "Cyclic Tempogram";
+    d3.description = "Cyclic Tempogram";
+    d3.unit = "";
+    d3.hasFixedBinCount = true;
+    d3.binCount = m_cyclicTempogramOctaveDivider > 0 && !isnan(m_cyclicTempogramOctaveDivider) ? m_cyclicTempogramOctaveDivider : 0;
+    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;
+    d3.hasDuration = false;
+    list.push_back(d3);
+    
+    OutputDescriptor d1;
     d1.identifier = "tempogram";
     d1.name = "Tempogram";
     d1.description = "Tempogram";
@@ -365,25 +380,13 @@
     d2.hasDuration = false;
     list.push_back(d2);
     
-    OutputDescriptor d3;
-    d3.identifier = "cyclicTempogram";
-    d3.name = "Cyclic Tempogram";
-    d3.description = "Cyclic Tempogram";
-    d3.unit = "";
-    d3.hasFixedBinCount = true;
-    d3.binCount = m_cyclicTempogramOctaveDivider > 0 && !isnan(m_cyclicTempogramOctaveDivider) ? m_cyclicTempogramOctaveDivider : 0;
-    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;
-    d3.hasDuration = false;
-    list.push_back(d3);
-    
     return list;
 }
 
-void TempogramPlugin::checkParameterValues(){
+bool TempogramPlugin::handleParameterValues(){
+    
+    if (m_tempogramHopSize <= 0) return false;
+    if (m_tempogramLog2FftLength <= 0) return false;
     
     if (m_tempogramFftLength < m_tempogramWindowLength){
         m_tempogramFftLength = m_tempogramWindowLength;
@@ -394,8 +397,8 @@
     }
     
     float tempogramInputSampleRate = (float)m_inputSampleRate/m_inputStepSize;
-    m_tempogramMinBin = (unsigned int)(max(floor(((m_tempogramMinBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (float)0.0));
-    m_tempogramMaxBin = (unsigned int)(min(ceil(((m_tempogramMaxBPM/60)/tempogramInputSampleRate)*m_tempogramFftLength), (float)m_tempogramFftLength/2));
+    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));
     
     if (m_tempogramMinBPM > m_cyclicTempogramMinBPM) m_cyclicTempogramMinBPM = m_tempogramMinBPM;
     float cyclicTempogramMaxBPM = 480;
@@ -405,6 +408,7 @@
     int numberOfBinsInFirstOctave = bpmToBin(m_cyclicTempogramMinBPM);
     if (m_cyclicTempogramOctaveDivider > numberOfBinsInFirstOctave) m_cyclicTempogramOctaveDivider = numberOfBinsInFirstOctave;
     
+    return true;
 }
 
 bool
@@ -418,7 +422,7 @@
     m_inputStepSize = stepSize;
     
     m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2.0f + 1);
-    checkParameterValues();
+    if (!handleParameterValues()) return false;
     //cout << m_cyclicTempogramOctaveDivider << endl;
     
     return true;
@@ -430,12 +434,14 @@
     // Clear buffers, reset stored values, etc
     m_spectrogram.clear();
     m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2.0f + 1);
-    checkParameterValues();
+    handleParameterValues();
 }
 
 TempogramPlugin::FeatureSet
 TempogramPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
 {
+    //cerr << "Here" << endl;
+
     size_t n = m_inputBlockSize/2 + 1;
     
     FeatureSet featureSet;
@@ -449,7 +455,7 @@
         magnitude = magnitude > m_noveltyCurveMinDB ? magnitude : m_noveltyCurveMinDB;
         m_spectrogram[i].push_back(magnitude);
     }
-
+    
     return featureSet;
 }
 
@@ -482,6 +488,13 @@
     return bin;
 }
 
+float TempogramPlugin::binToBPM(const int &bin) const
+{
+    float sampleRate = m_inputSampleRate/m_inputStepSize;
+    
+    return (bin*sampleRate/m_tempogramFftLength)*60;
+}
+
 TempogramPlugin::FeatureSet
 TempogramPlugin::getRemainingFeatures()
 {
@@ -497,7 +510,7 @@
     size_t numberOfBlocks = m_spectrogram[0].size();
     //cerr << numberOfBlocks << endl;
     NoveltyCurveProcessor nc(m_inputSampleRate, m_inputBlockSize, numberOfBlocks, m_noveltyCurveCompressionConstant);
-    vector<float> noveltyCurve = nc.spectrogramToNoveltyCurve(m_spectrogram); //calculate novelty curve from magnitude data
+    vector<float> noveltyCurve = nc.spectrogramToNoveltyCurve(m_spectrogram); //calculate novelty curvefrom magnitude data
     //if(noveltyCurve.size() > 50) for (int i = 0; i < 50; i++) cerr << noveltyCurve[i] << endl;
     
     //push novelty curve data to featureset 1 and set timestamps
@@ -505,7 +518,8 @@
         Feature noveltyCurveFeature;
         noveltyCurveFeature.values.push_back(noveltyCurve[i]);
         noveltyCurveFeature.hasTimestamp = false;
-        featureSet[1].push_back(noveltyCurveFeature);
+        featureSet[2].push_back(noveltyCurveFeature);
+        assert(!isnan(noveltyCurveFeature.values.back()));
     }
     
     //window function for spectrogram
@@ -527,9 +541,10 @@
         assert(tempogram[block].size() == (m_tempogramFftLength/2 + 1));
         for(int k = m_tempogramMinBin; k < (int)m_tempogramMaxBin; k++){
             tempogramFeature.values.push_back(tempogram[block][k]);
+            assert(!isnan(tempogramFeature.values.back()));
         }
         tempogramFeature.hasTimestamp = false;
-        featureSet[0].push_back(tempogramFeature);
+        featureSet[1].push_back(tempogramFeature);
     }
     
     //Calculate cyclic tempogram
@@ -542,14 +557,18 @@
         
         for (int i = 0; i < (int)m_cyclicTempogramOctaveDivider; i++){
             float sum = 0;
+            
+            //mcerr << floor(binToBPM(logBins[i]) + 0.5) << " " << floor(binToBPM(logBins[i + m_cyclicTempogramOctaveDivider]) + 0.5) << endl;
+            
             for (int j = 0; j < (int)m_cyclicTempogramNumberOfOctaves; j++){
                 sum += tempogram[block][logBins[i+j*m_cyclicTempogramOctaveDivider]];
             }
             cyclicTempogramFeature.values.push_back(sum/m_cyclicTempogramNumberOfOctaves);
+            assert(!isnan(cyclicTempogramFeature.values.back()));
         }
 
         cyclicTempogramFeature.hasTimestamp = false;
-        featureSet[2].push_back(cyclicTempogramFeature);
+        featureSet[0].push_back(cyclicTempogramFeature);
     }
     
     return featureSet;
--- a/TempogramPlugin.h	Fri Aug 15 15:17:28 2014 +0100
+++ b/TempogramPlugin.h	Mon Aug 18 15:22:44 2014 +0100
@@ -104,7 +104,8 @@
     string floatToString(float value) const;
     vector<unsigned int> calculateTempogramNearestNeighbourLogBins() const;
     int bpmToBin(const float &bpm) const;
-    void checkParameterValues();
+    float binToBPM (const int &bin) const;
+    bool handleParameterValues();
 };