diff audio/AudioGenerator.cpp @ 615:755fc02a1565

Associate a note-on time with each pending note-off as well, so we can check whether a rewind action (or looping) has caused us to jump to before the note began. Also improve implementation of note-off structure comparator
author Chris Cannam
date Mon, 13 Aug 2018 14:13:38 +0100
parents 88f9266e0417
children 7d3a6357ce64
line wrap: on
line diff
--- a/audio/AudioGenerator.cpp	Mon Aug 13 11:44:33 2018 +0100
+++ b/audio/AudioGenerator.cpp	Mon Aug 13 14:13:38 2018 +0100
@@ -568,6 +568,24 @@
         std::vector<ClipMixer::NoteStart> starts;
         std::vector<ClipMixer::NoteEnd> ends;
 
+        while (noteOffs.begin() != noteOffs.end() &&
+               noteOffs.begin()->onFrame > reqStart) {
+
+            // We must have jumped back in time, as there is a
+            // note-off pending for a note that hasn't begun yet. Emit
+            // the note-off now and discard
+
+            off.frameOffset = 0;
+            off.frequency = noteOffs.begin()->frequency;
+
+#ifdef DEBUG_AUDIO_GENERATOR
+            cerr << "mixModel [clip]: adding rewind-caused note-off at frame offset 0 frequency " << off.frequency << endl;
+#endif
+
+            ends.push_back(off);
+            noteOffs.erase(noteOffs.begin());
+        }
+        
         for (NoteList::const_iterator ni = notes.begin();
              ni != notes.end(); ++ni) {
 
@@ -595,9 +613,9 @@
             }
 
             while (noteOffs.begin() != noteOffs.end() &&
-                   noteOffs.begin()->frame <= noteFrame) {
+                   noteOffs.begin()->offFrame <= noteFrame) {
 
-                sv_frame_t eventFrame = noteOffs.begin()->frame;
+                sv_frame_t eventFrame = noteOffs.begin()->offFrame;
                 if (eventFrame < reqStart) eventFrame = reqStart;
 
                 off.frameOffset = eventFrame - reqStart;
@@ -622,13 +640,14 @@
             
             starts.push_back(on);
             noteOffs.insert
-                (NoteOff(on.frequency, noteFrame + noteDuration));
+                (NoteOff(on.frequency, noteFrame + noteDuration, noteFrame));
         }
 
         while (noteOffs.begin() != noteOffs.end() &&
-               noteOffs.begin()->frame <= reqStart + m_processingBlockSize) {
+               noteOffs.begin()->offFrame <=
+               reqStart + m_processingBlockSize) {
 
-            sv_frame_t eventFrame = noteOffs.begin()->frame;
+            sv_frame_t eventFrame = noteOffs.begin()->offFrame;
             if (eventFrame < reqStart) eventFrame = reqStart;
 
             off.frameOffset = eventFrame - reqStart;