diff songparts/plugins/SongParts.cpp @ 4:fa8450e6f5a9

In this version the corrections at the function beatQuantizer by Matthias has been integrated: the problem about the adding of extra beats is solved
author maxzanoni76 <max.zanoni@eecs.qmul.ac.uk>
date Wed, 11 Apr 2012 12:53:57 +0100
parents f44aa6d29642
children 79b343f3e4b8
line wrap: on
line diff
--- a/songparts/plugins/SongParts.cpp	Wed Apr 11 09:58:31 2012 +0100
+++ b/songparts/plugins/SongParts.cpp	Wed Apr 11 12:53:57 2012 +0100
@@ -1073,15 +1073,16 @@
 
 /* ------ Beat Quantizer ------ */
 
-std::vector<Vamp::Plugin::FeatureList> SongPartitioner::BeatQuantiser(Vamp::Plugin::FeatureList chromagram, Vamp::Plugin::FeatureList beats)
+std::vector<Vamp::Plugin::FeatureList>
+SongPartitioner::BeatQuantiser(Vamp::Plugin::FeatureList chromagram, Vamp::Plugin::FeatureList beats)
 {
     std::vector<FeatureList> returnVector;
     
     FeatureList fwQchromagram; // frame-wise beat-quantised chroma
     FeatureList bwQchromagram; // beat-wise beat-quantised chroma
     
-    size_t nChromaFrame = chromagram.size();
-    size_t nBeat = beats.size();
+    int nChromaFrame = (int) chromagram.size();
+    int nBeat = (int) beats.size();
     
     if (nBeat == 0 && nChromaFrame == 0) return returnVector;
     
@@ -1093,15 +1094,23 @@
     int currBeatCount = -1; // start before first beat
     int framesInBeat = 0;
     
-    for (size_t iChroma = 0; iChroma < nChromaFrame; ++iChroma)
+    for (int iChroma = 0; iChroma < nChromaFrame; ++iChroma)
     {
-        Vamp::RealTime chromaTimestamp = chromagram[iChroma].timestamp;
-        if (chromaTimestamp > beats[currBeatCount+1].timestamp ||
+        Vamp::RealTime frameTimestamp = chromagram[iChroma].timestamp;
+		Vamp::RealTime tempBeatTimestamp;
+		
+		if (currBeatCount != beats.size()-1) tempBeatTimestamp = beats[currBeatCount+1].timestamp;
+		else tempBeatTimestamp = chromagram[nChromaFrame-1].timestamp;
+		
+        if (frameTimestamp > tempBeatTimestamp ||
             iChroma == nChromaFrame-1)
         {
             // new beat (or last chroma frame)
             // 1. finish all the old beat processing
-            for (size_t i = 0; i < nBin; ++i) tempChroma[i] /= framesInBeat; // average
+			if (framesInBeat > 0)
+			{
+            	for (int i = 0; i < nBin; ++i) tempChroma[i] /= framesInBeat; // average
+			}
             
             Feature bwQchromaFrame;
             bwQchromaFrame.hasTimestamp = true;
@@ -1132,8 +1141,6 @@
     returnVector.push_back(bwQchromagram);
 }
 
-
-
 /* -------------------------------- */
 /* ------ Support Functions  ------ */
 /* -------------------------------- */
@@ -1331,12 +1338,6 @@
     int nBeat = quatisedChromagram.size();                      // Number of feature vector
     int nFeatValues = quatisedChromagram[0].values.size();      // Number of values for each feature vector
     
-    // ----- TEMP ------
-    /*if (nBeat > 255)
-        nBeat = 255;
-    std::cout << "CUT THE ERROR BEAT -> " << nBeat << std::endl;*/
-    // -----------------
-    
     arma::irowvec timeStamp = arma::zeros<arma::imat>(1,nBeat);       // Vector of Time Stamps
     
 	// Save time stamp as a Vector