Jitter in MIDI scheduling


I’m noticing that with a high buffer size, fast MIDI notes are played back unevenly. Logging from applyToBuffer for my synth plugin, it seems like metadata.samplePosition is zero for all notes (and therefore all notes are quantized to the audio buffer size).

What am I doing wrong?


I’ve been thinking about this and if you’re using a large buffer, it’s what I would expect to happen “I think”.

For example:
• Live MIDI notes come in on a separate thread, they have a timestamp from the driver or if this doesn’t exist get a timestamp from the OS
• They can’t get injected in to the current buffer because it’s already playing so they’ll need to go in to the next audio callback
• In order for them to be played as close to the arrival time as possible they’ll be at the start of the buffer. Otherwise there will be a larger latency

I guess this is a question of trading latency for jitter. What would be the most natural way to do this?

I’m sorry, I wasn’t being clear: I wasn’t talking about live MIDI but of (pre-scheduled) MidiClip playback!

For live MIDI, I agree that the most reasonable approach probably is to minimize the latency.

Ah ok. If that is the case that does sound like a bug.
Can I just check that you’re on the tip of develop (or the midi branch I created yesterday)?

I was on a snapshot of develop from May 18th but I just tried it in feature/midi_list and I do get the same result there.

I’m sorry, it was indeed my own mistake! In applyToBuffer, i thought that the timestamps in PluginRenderContext.bufferForMidiMessages are in samples where they are actually in seconds. The values were then truncated to integers by my code, that’s why I only got zeros in the log.

Multiplying the timestamps with the current sample rate now give perfect jitter-free playback! :slight_smile:

Again, sorry for the noise!

Great, glad you got it sorted!