pure-data / pure-data

Pure Data - a free real-time computer music system
Other
1.57k stars 245 forks source link

Gem + Jack, with dsp off, shows weird midi latency #1339

Open abreubacelar opened 3 years ago

abreubacelar commented 3 years ago

i'm on Ubuntu 20.04.2 LTS, using pd version 0.51.4 and Gem 0.94

with jack running, a gemwin created and with dsp off (i didn't test with dsp on, to be honest), i noticed that i get a strange midi latency. Each new gemhead structure adds latency to midi, and this only happens with jack chosen in the media settings.

if i change to alsa (and dsp still off), the midi latency drops...

i'm unsure if this is a Gem or pd bug, but since the jack option on pd menu is that trigger the latency addition by gemheads trees, i decided to report it here...

a patch that shows the problem:

midiGemJackTest.zip

and a video of that patch with the latency growing when using jack, but drops when choose alsa:

https://user-images.githubusercontent.com/16086370/121548467-6984c480-c9e3-11eb-95fd-4ea1754eed6f.mp4

umlaeute commented 3 years ago

could you try disabling "Sync to VBlank" for your gfx-card?

in general it is better to keep the audio and Gem in separate Pd instances (so start Pd/Gem with -nosound - but of course this is not very nice as you then need to have control about how Pd is started...)

umlaeute commented 3 years ago

also: could you rule out a problem with [pix_snap]? it's rather inefficient. in a use-case like yours, [pix_snap2tex] would be much faster.

your problem might be related to synching between monitor&framebuffers and CPU-memory&GPU-memory.

abreubacelar commented 3 years ago

starting pd with -nosound works,

to be honest, this patch was a test to just create something that gives the problem to show it here, my actual patch doesn't use pix_snap at all, but since you mentioned about pix_snap being inefficient i decided to drop Gem and make a test really dumb to see if these latency differences still happens when pd is running some "cpu intensive" code... and aha, it happened, -nosound and alsa showed the lowest midi latencies, jack have more latency and portaudio give way more (oss doesn't work, but yeah, i don't have it here, just clicked to see what happens, no midi output, even with alsa-midi selected together with oss)

my very dumb test: [metro 17] making until generate 60000 bangs connected to f + 1 and numberbox, useless, but with this in my system i can notice differences in midi latency when alsa or jack is selected

midilatencyDumbUntil.zip

if i make until generate more bangs, latency grows for alsa too, but i think this is expected since pd is working "hard" and midi get delayed, the whole point is just for some reason jack option gives more latency than alsa even with dsp off

but in other words, my original patch is inefficient, but i'm happy to know that it works with -nosound or alsa, i just need to avoid jack with it, and rethink to how to make it more efficient

and i don't know how to disable "Sync to VBlank" here... i need help to test it, if needed (i don't have a dedicated graphic card, it is the intel hd graphic something, in my case my processor is an intel i5-2410M)