2.1.0 - MIDI Playback Issues (Wrong Notes)

Windows SDK 2.1.0

MIDI Playback Issue.zip (437.8 KB)

I have a short MIDI file with two tracks which is loaded in a project and played back. I expect it to play back the notes as written and confirmed with various external MIDI utilities, but under certain conditions, specific notes are cut very short (notes are silenced almost immediately after playing).


I've attached a project which demonstrates the behavior. It will automatically play 5 variations of "Pop Goes the Weasel" to test different inputs:

  1. The original MIDI file, which I rendered from an external utility. Sequence is played using Playdate synth (square waves). No apparent issues with playback

  2. A modified version of the MIDI file used in (1), where I have moved all notes closer to the start of the song (intent was to make the notes start playing sooner). I did not try to snap the notes to a particular step. Sequence is played using Playdate synth. The song plays, but several of the notes are unexpectedly cut short

  3. A modified version of the MIDI file used in (1), where I have lengthened all notes to intentionally make them overlap. The results are similar to (2)

  4. Same as (2), but using a piano sample as the instrument. Same results as (2)

  5. Same as (3), but using a piano sample as the instrument. Same results as (2)


I'm out of ideas for what could be causing this. Is there something about timing/polyphony in MIDI files that I don't understand that could lead to this behavior?

All modifications of the MIDI files used can be played without issues in external tools like MIDIEditor and FL.

I took a closer look at the MIDI files, and discovered that there actually were unexpected artifacts in them after editing, saving, then reopening them in the editor that I'm using. But the odd thing is that the errors in the file don't seem to match the errors that I actually hear when running my Playdate project.

For example, when viewing "testscore2.mid" in the attachment above, very short notes can be seen at several locations in one of the tracks (I have no idea how they were introduced, but that's not a Playdate problem). But the notes that are cut off while playing the song in the Playdate project are not the notes that are short.

I'm seriously mystified by this whole thing. Thinking of submitting a bug report for this... if anyone has any thoughts, I'd be glad to hear them.

Okay, I see the problem. The .mid file format is a list of note-on and note-off events, and our loader converts that to a note+length list by matching each note-off with the most recent note-on for that note. In other words, it's expecting that after each note-on, there will be an off event for that note before the next on occurs. That's true for the first midi file but not for the other two: In the second some of the notes are butting up against each other, stopping and starting on the same tick, and for some reason it has the on event before the off; In the third they overlap, with the on of the second note occurring well before the off of the first. In those cases the note-offs for the overlapping notes get matched to the second note event, and the first event keeps its default length value of 1, which is why you get the little blip of a note.

I'll file it, though it seems like a pretty obscure bug without a simple fix. I might come up with something in the future, but until then if you make sure there's a space between note events on the same pitch everything should work.

1 Like