changeset 19:e90a4797e579

* Attempted fixing bug which crashes sonic visualizer.
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Fri, 15 Aug 2014 12:34:07 +0100
parents 89bc9e5199d7
children de7213b35755
files TempogramPlugin.cpp TempogramPlugin.h
diffstat 2 files changed, 33 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/TempogramPlugin.cpp	Thu Aug 14 16:43:26 2014 +0100
+++ b/TempogramPlugin.cpp	Fri Aug 15 12:34:07 2014 +0100
@@ -16,7 +16,7 @@
     Plugin(inputSampleRate),
     m_inputBlockSize(0), //host parameter
     m_inputStepSize(0), //host parameter
-    m_noveltyCurveMinDB(0), //set in initialise()
+    m_noveltyCurveMinDB(pow(10,(float)-74/20)), //set in initialise()
     m_noveltyCurveCompressionConstant(1000), //parameter
     m_tempogramLog2WindowLength(10), //parameter
     m_tempogramWindowLength(pow((float)2,m_tempogramLog2WindowLength)),
@@ -41,7 +41,7 @@
 TempogramPlugin::~TempogramPlugin()
 {
     //delete stuff
-    cleanup();
+    
 }
 
 string
@@ -290,10 +290,6 @@
     
 }
 
-void TempogramPlugin::updateBPMParameters(){
-
-}
-
 TempogramPlugin::ProgramList
 TempogramPlugin::getPrograms() const
 {
@@ -396,7 +392,8 @@
     // Real initialisation work goes here!
     m_inputBlockSize = blockSize;
     m_inputStepSize = stepSize;
-    m_noveltyCurveMinDB = pow(10,(float)-74/20);
+    
+    m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2 + 1);
     
     if (m_tempogramFftLength < m_tempogramWindowLength){
         m_tempogramFftLength = m_tempogramWindowLength;
@@ -414,23 +411,20 @@
     float cyclicTempogramMaxBPM = 480;
     if (m_tempogramMaxBPM < cyclicTempogramMaxBPM) cyclicTempogramMaxBPM = m_tempogramMaxBPM;
     
-    m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2 + 1);
-    
     m_cyclicTempogramNumberOfOctaves = floor(log2(cyclicTempogramMaxBPM/m_cyclicTempogramMinBPM));
     int numberOfBinsInFirstOctave = bpmToBin(m_cyclicTempogramMinBPM);
-    if (m_cyclicTempogramOctaveDivider < numberOfBinsInFirstOctave) m_cyclicTempogramOctaveDivider = numberOfBinsInFirstOctave;
+    if (m_cyclicTempogramOctaveDivider > numberOfBinsInFirstOctave) m_cyclicTempogramOctaveDivider = numberOfBinsInFirstOctave;
+    
+    //cout << m_cyclicTempogramOctaveDivider << endl;
     
     return true;
 }
 
-void TempogramPlugin::cleanup(){
-
-}
-
 void
 TempogramPlugin::reset()
 {
     // Clear buffers, reset stored values, etc
+    m_spectrogram.clear();
     m_spectrogram = SpectrogramTransposed(m_inputBlockSize/2 + 1);
 }
 
@@ -463,8 +457,11 @@
         int bin = bpmToBin(bpm);
         
         logBins.push_back(bin);
+        cerr << bin << endl;
     }
     
+    cerr << logBins.size() << endl;
+    
     return logBins;
 }
 
@@ -491,18 +488,17 @@
     
     FeatureSet featureSet;
     
-    //initialise m_noveltyCurve processor
+    //initialise novelty curve processor
     size_t numberOfBlocks = m_spectrogram[0].size();
     NoveltyCurveProcessor nc(m_inputSampleRate, m_inputBlockSize, numberOfBlocks, m_noveltyCurveCompressionConstant);
-    m_noveltyCurve = nc.spectrogramToNoveltyCurve(m_spectrogram); //calculate novelty curve from magnitude data
+    vector<float> noveltyCurve = nc.spectrogramToNoveltyCurve(m_spectrogram); //calculate novelty curve from magnitude data
     
     //push novelty curve data to featureset 1 and set timestamps
     for (unsigned int i = 0; i < numberOfBlocks; i++){
-        Feature feature;
-        feature.values.push_back(m_noveltyCurve[i]);
-        feature.hasTimestamp = false;
-        //feature.timestamp = ncTimestamps[i];
-        featureSet[1].push_back(feature);
+        Feature noveltyCurveFeature;
+        noveltyCurveFeature.values.push_back(noveltyCurve[i]);
+        noveltyCurveFeature.hasTimestamp = false;
+        featureSet[1].push_back(noveltyCurveFeature);
     }
     
     //window function for spectrogram
@@ -511,7 +507,7 @@
     //initialise spectrogram processor
     SpectrogramProcessor spectrogramProcessor(m_tempogramWindowLength, m_tempogramFftLength, m_tempogramHopSize);
     //compute spectrogram from novelty curve data (i.e., tempogram)
-    Tempogram tempogram = spectrogramProcessor.process(&m_noveltyCurve[0], numberOfBlocks, hannWindow);
+    Tempogram tempogram = spectrogramProcessor.process(&noveltyCurve[0], numberOfBlocks, hannWindow);
     delete []hannWindow;
     hannWindow = 0;
     
@@ -519,34 +515,34 @@
     
     //push tempogram data to featureset 0 and set timestamps.
     for (int block = 0; block < tempogramLength; block++){
-        Feature feature;
+        Feature tempogramFeature;
         
         assert(tempogram[block].size() == (m_tempogramFftLength/2 + 1));
         for(int k = m_tempogramMinBin; k < (int)m_tempogramMaxBin; k++){
-            feature.values.push_back(tempogram[block][k]);
+            tempogramFeature.values.push_back(tempogram[block][k]);
         }
-        feature.hasTimestamp = false;
-        featureSet[0].push_back(feature);
+        tempogramFeature.hasTimestamp = false;
+        featureSet[0].push_back(tempogramFeature);
     }
     
     //Calculate cyclic tempogram
     vector<unsigned int> logBins = calculateTempogramNearestNeighbourLogBins();
-    Tempogram cyclicTempogram;
     
+    assert(logBins.back() <= m_tempogramFftLength/2);
+    assert(logBins.size() == m_cyclicTempogramOctaveDivider*m_cyclicTempogramNumberOfOctaves);
     for (int block = 0; block < tempogramLength; block++){
-        Feature feature;
+        Feature cyclicTempogramFeature;
         
         for (int i = 0; i < m_cyclicTempogramOctaveDivider; i++){
             float sum = 0;
             for (int j = 0; j < m_cyclicTempogramNumberOfOctaves; j++){
                 sum += tempogram[block][logBins[i+j*m_cyclicTempogramOctaveDivider]];
             }
-            feature.values.push_back(sum/m_cyclicTempogramNumberOfOctaves);
+            cyclicTempogramFeature.values.push_back(sum/m_cyclicTempogramNumberOfOctaves);
         }
 
-        feature.hasTimestamp = false;
-        
-        featureSet[2].push_back(feature);
+        cyclicTempogramFeature.hasTimestamp = false;
+        featureSet[2].push_back(cyclicTempogramFeature);
     }
     
     return featureSet;
--- a/TempogramPlugin.h	Thu Aug 14 16:43:26 2014 +0100
+++ b/TempogramPlugin.h	Fri Aug 15 12:34:07 2014 +0100
@@ -78,16 +78,9 @@
     size_t m_inputBlockSize;
     size_t m_inputStepSize;
     SpectrogramTransposed m_spectrogram; //spectrogram data
-    vector<float> m_noveltyCurve; //novelty curve data
-    float m_noveltyCurveMinDB;
-    
-    void cleanup(); //used to release anything allocated in initialise()
-    string floatToString(float value) const;
-    vector<unsigned int> calculateTempogramNearestNeighbourLogBins() const;
-    void updateBPMParameters();
-    int bpmToBin(const float &bpm) const;
     
     //Novelty Curve specific parameters
+    float m_noveltyCurveMinDB;
     float m_noveltyCurveCompressionConstant;
     
     //Tempogram specific parameters
@@ -107,6 +100,10 @@
     float m_cyclicTempogramMinBPM;
     int m_cyclicTempogramNumberOfOctaves;
     int m_cyclicTempogramOctaveDivider;
+
+    string floatToString(float value) const;
+    vector<unsigned int> calculateTempogramNearestNeighbourLogBins() const;
+    int bpmToBin(const float &bpm) const;
 };