diff src/Silvet.cpp @ 334:806b2ea65416 livemode

Detect repeated notes
author Chris Cannam
date Thu, 25 Jun 2015 14:18:44 +0100
parents 19c17cd0c7d8
children d861f86f2b17
line wrap: on
line diff
--- a/src/Silvet.cpp	Thu Jun 25 12:21:02 2015 +0100
+++ b/src/Silvet.cpp	Thu Jun 25 14:18:44 2015 +0100
@@ -1011,8 +1011,6 @@
         return { noteFeatures, onsetFeatures };
     }
     
-    //!!! try: repeated note detection? (look for change in first derivative of the pitch matrix)
-
     for (map<int, double>::const_iterator ni = m_pianoRoll[width-1].begin();
          ni != m_pianoRoll[width-1].end(); ++ni) {
 
@@ -1041,6 +1039,20 @@
             // the note was playing but just ended
             m_current.erase(note);
             emitNote(start, end, note, shiftCount, noteFeatures);
+        } else { // still playing
+            // repeated note detection: if level is greater than this
+            // multiple of its previous value, then we end the note and
+            // restart it with the same pitch
+            double restartFactor = 1.5;
+            if (duration >= durationThreshold * 2 &&
+                (active.find(note)->second >
+                 restartFactor * m_pianoRoll[width-1][note])) {
+                m_current.erase(note);
+                emitNote(start, end-1, note, shiftCount, noteFeatures);
+                // and remove this so that we start counting the new
+                // note's duration from the current position
+                m_pianoRoll[width-1].erase(note);
+            }
         }
     }