MIDI Sequencing jitter


#1

Hi, I’m getting some jitter when doing some MIDI sequencing on OSX and iOS. General operation is ok, but there is some jitter. Gets much worse when moving windows around on OSX or sending app to background/foreground in OSX.

The general architecture of the sequencer is as follows:
hires timer that fires periodically
generate a MidiBuffer containing the data to be sent to the device
output the buffer via a sendBlockOfMessages() call to the MIDI device

Anything obviously wrong with this approach? thx


#2

How are you generating the MidiBuffer to send to the hires timer? on the gui thread or a background thread? any locks shared with gui thread?


#3

Hi, the MidiBuffer is created in the callback from the hirestimer, so will be created on its thread.

Cheers


#4

I would avoid using MidiOutput::sendBlockOfMessagesNow(), internally it uses a normal thread and Thread::sleep() for timing, which isn’t as good as the hires timer you are already using (but not using the accuracy of)

Set your hires timer to 1000 hz, and have it check a buffer and if there is a message with a timestamp <= current time, send it with MidiOutput::sendMessageNow()

Then use another thread to generate the midi messages and fill the buffer. My apps usually generate audio and midi, so I use the audio thread to generate a block of audio and midi. If your app is Midi only, you could make another thread that runs at 200 hz or so to fill the buffer.


#5

Hi, funnily enough I’d just made my app generate 1 bar of data at a time and send that to see if that’s where the issue lay and I came to the same conclusion.

Thx for the suggestion - seems like the right way to go.

thx