Reduce MIDI latency?

Hi,
MIDI data passing MIDI In > PureData > MIDI out gets delayed by about 35ms. Where does the latency get introduced, and is it possible to reduce this somehow?

Hey, how did you meassure the latency?

I used Roland Studio Capture connected to my laptop to measure the latency. When this interface’s MIDI IN is looped directly to OUT, I get 3ms latency.

With Pisound added to the loop, and it’s MIDI ports connected to each other in software (aconnect 16:0 16:0), I get 5ms total latency, that means 2ms was spent within RPi / Pisound.

With a simple patch on Pure Data which imitates what aconnect above did:

[midiin]
|      \
[midiout]

I get 10ms total latency, so PD itself seems to add about 5ms…

I’m not sure whether there’s any settings available to improve this on PD. Launching PD with no GUI does not improve it.

i think pd links ‘control rate’ processing to audio processing, so perhaps if you reduce the audio buf size?

Ok, I tried agin using only objects midiin > midiout, and got a similar result to you, 2.5ms latency within RPi/Pisound, and 7.5ms within Pure Data, total 10ms. However if i change my patch to

ctlin > ctlout
or
notein > noteout

I get a latency within pure data of 29ms, So it seems if i use those objects rather that midiin and midiout the latency of puredata is quadrupled…

1 Like

So it looks like i can eliminate this extra latency in some midi objects by setting audio delay to 0ms in audio settings. Not sure why…

1 Like

Was just noticing the midi latency today too and went to the forum for help and found your comment.

Thanks!

Will try changing the delay too and see what happens :slight_smile:

1 Like

Hey guys :slight_smile:

I am playing a bit around with the Pisound this evening and I am looking into the latency issue, I am experiencing.

I wanted to try changing the delay setting of PD settings. Put since we are using Jack for audio, the delay setting in PD is overwritten by an Jack settings:
https://archive.flossmanuals.net/pure-data/getting-started/configuring

In Jack settings I can only set sample rate, buffer size and Jack service settings, there is no access to the delay setting. They are set to:
SR: 48000
Buffer: 128
Jack Service Setting: 2

I tried opening pd manually and changing the delay setting and save, then close pd anf launch PD from the Pisound app. It seems like the latency is still there. Maybe the delay setting is overwritten when loading a patch in nogui mode from the Pisound app?

I also tried changing the buffer to 64, but then Jack won’t work at all, only 128 and above is allowed, it seems.

I guess I could try a higher sample rate, but not sure the PI3 will be able to run the patch then. Is changing the sample rate the only option I have here?

Or are there any other ways I can impact latency, to make it shorter?

Thanks in advance.

Hey, changing the sample rate to a higher one does reduce the latency, but of course the patch must be able to run stable enough at a higher rate for this to work.

You may edit the whole command line for the Jack server in /etc/jackdrc file. Check out the ‘-S’ flag here: Latency Measurment with jack_iodelay, it may be able to reduce the latency a bit, but might turn out to be a less stable in case overruns occur, so experiment with it.

1 Like

@Giedrius

Thank you for the suggestion, I will take a look at it :slight_smile: