Significant latency in examples
I'm not sure if this is representative of fundsp as whole, or if there is some kind of issue with my OS config, but the keys example has an unusable amount of latency (probably like 200ms?) between key presses and notes sounding. The latency is present on both my MacBook and desktop Linux machine. I have already done some linux configuration for real-time audio that was good enough to eliminate most latency from VSTs running in Reaper.
Is this a known issue?
EDIT: See Resolution
have you ran it in release? (reverb is known to be too slow in debug) i can't think of anything else, it has no latency for me
fresh clone test
https://github.com/user-attachments/assets/28e06ae4-ed15-4023-b0bf-0cce3f0541a3
Yea I'm running in release.
what happens if you go to https://tomara-x.github.io/lapis/ and execute
set_out_device(0, 0);
"keys" = true;
let seq = Sequencer::new(false, 1);
let be = seq.backend();
let filter = (pass() | dc(1729) | dc(1)) >> lowpass();
let verb = (pass() | pass()) & reverb_stereo(40, 3, 0.4);
let limit = limiter(0.1, 0.1);
let g = be >> filter >> limit >> pan(0) >> verb;
g.play();
"a" = "seq.push_relative(0, 0.5, Fade::Smooth, 0.01, 0.01, sine_hz(440));"
and give the a key a press?
Long latency between pressing a and hearing a sound
but do you see the text printed immediately? or is there latency between pressing the key and seeing the text?
No latency for seeing the text.
https://github.com/user-attachments/assets/6b4de0c6-21ed-4bb8-9028-3127e0663ab4
how about this?
set_out_device(0, 0);
"keys" = true;
let seq = Sequencer::new(false, 1);
let be = seq.backend();
let filter = (pass() | dc(1729) | dc(1)) >> lowpass();
let verb = (pass() | pass()) & reverb_stereo(40, 3, 0.4);
let g = be >> filter >> pan(0) >> verb;
g.play();
"a" = "seq.push_relative(0, 0.5, Fade::Smooth, 0, 0, impulse::<U1>() >> pluck(440, 0.5, 1));"
Better, but still there.
https://github.com/user-attachments/assets/45c874e8-46b1-4904-bdad-a2c452aa510b
i put your video in audacity and i can measure 100ms between the sound of you pressing the key and the sound of the pluck.
can you do one more test with the same setup? run this and press a
i'm thinking it's an input thing, because there's nothing in fundsp that would cause that much latency
Much better
https://github.com/user-attachments/assets/776fc84b-7657-4cb5-8e18-dfe95c91b9f3
that's around 90ms tho? i'm thinking also this being native, while the other tests were in web, might be the reason for that difference oh and there's also an egui version difference, this used 0.31.0, while fundsp's example used 0.29.1
Ah, yea 90ms isn't great. It felt better though, subjectively.
hehe without measuring i can't perceive any of that
I also just modified examples/input to just do a passthrough without any effects. I'm playing my synth into it, and there is still a lot of latency.
I thought maybe I could reduce the latency by shrinking the buffer size of the cpal devices. My Reaper audio config looks like this:
However, changing the cpal::BufferSize from Default to Fixed(256) seems to totally break the audio; no sound comes out anymore.
OK I finally figured it out! Here's what I needed to get low latency:
- Upgrade
cpalto version 0.16.0. - Enable the
audio_thread_priorityfeature ofcpal. - Manually override the
cpal::BufferSizeto beFixed(256).
I think it would be a good idea to apply these changes to the fundsp examples.
@bonsairobo , thanks, that fixes my latency issue too.