Menu

#131 Frame drift can cause cut-off notes for LV2 MIDI plugins

git_head
closed
nobody
lv2 (4) midi (2)
2015-03-23
2014-09-30
No

When playing using LV2 instrument plugins, "frame drift" can randomly cause note off events to be queued after the next note on event. This can cause a subsequent note of the same pitch to be cut off.

This can be reproduced with the attached MIDI file, which has tight note on/off durations. When playing this MIDI file with qtractor (after having attached a LV2 output plugin to the bus), randomly notes fall out due to the aforementioned issue.

The following patch is not meant as a fix, but illustrates the issue:

Index: src/qtractorMidiEngine.cpp
===================================================================
--- src/qtractorMidiEngine.cpp  (revision 4067)
+++ src/qtractorMidiEngine.cpp  (working copy)
@@ -1953,7 +1953,8 @@
    qtractorTimeScale::Node *pNode = cursor.seekTick(iTime);
    const long f0 = m_iFrameStart - m_iFrameDrift;
    const unsigned long t0 = pNode->frameFromTick(iTime);
-   const unsigned long t1 = (long(t0) < f0 ? t0 : t0 - f0);
+   const unsigned long t1 = t0;
+   //const unsigned long t1 = (long(t0) < f0 ? t0 : t0 - f0);
    unsigned long t2 = t1;

    if (ev.type == SND_SEQ_EVENT_NOTE && ev.data.note.duration > 0) {

After applying this the problem goes away (probably at the expense of breaking something else).

The same problem does not occur when using ALSA output.

It took me quite some effort to figure out what exactly went wrong, so if you need any more details let me know.

1 Attachments

Discussion

  • Rui Nuno Capela

    Rui Nuno Capela - 2014-09-30

    After applying this the problem goes away (probably at the expense of breaking something else).

    yes, it breaks a lot of something else i guess, namely live/realtime MIDI input playing or monitoring--it might introduce random lags in event timing and delivery, especially for instrument plugins (any type, not just LV2).

    in a perfect world and tight kernel, the audio vs. midi drift correction (exposed by the frame-drift value) wouldn't be an issue; but we all know that isn't always true, all the time, for everyone at least.

    cheers

    ps. see if you can get the midi timer with enough resolution; that should improve things a bit.

     

    Last edit: Rui Nuno Capela 2014-09-30
  • Wladimir van der Laan

    Indeed! I realize this is always a difficult issue with music software.
    It would be impossible for the human brain to notice the difference if this just resulted in the notes being a few microseconds longer or shorter.

    The only problem here is if the events end up out of order, ie

    (before)
    t=1 Start C
    t=250 Stop C
    t=254 Start C
    t=500 Stop C

    (after)
    t=1 Start C
    t=249 Start C
    t=252 Stop C ^^oops^^
    t=500 Stop C

    In this case a beat will appear to be skipped, which is audible.

     
  • Rui Nuno Capela

    Rui Nuno Capela - 2015-03-23
    • status: open --> closed
     

Log in to post a comment.