-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Achieving lowest possible latency on both Linux and Windows #13
Comments
Hey, the alsa default output device on many linux distros is a virtual device that feeds back into the pulseaudio soundserver which in turn rewires the audio back to alsa to an actual hardware device. Try selecting one of the hw:x,y devices instead, on my dev box i can get easily below 6ms using plain alsa. Beware of the plughw: devices, these may add additional latency. Also keep in mind that pulseaudio "hijacks" the would-be-default-output-device (i.e. actual hardware device) to make its virtual device the default output device. Look for pasuspender module or if you have the luxury, set up a machine with PA completely removed from it if low latency is your primary concern. |
Ah, that makes sense! How can I get the default ALSA hardware device, i.e. hw:0,0 using XtAudio? Currently I've looped through all available devices and there are some hw: devices listed but all in the following forms:
|
You can't. Xt-Audio searches for the first device called "default", otherwise selects index 0. That's whats get reported by XtService.GetDefaultDevice. So in your case that might just be the PulseAudio device. You'll have to manually select the desired device based on the output of XtDeviceList.GetName, in your case i'd say you want the "PCH" device, hdmi is probably your monitor. If XtDeviceList.GetName doesnt provide enough info, you can match its output against the "aplay -l" command which provides a bit more details. Heres some example output from my dev box: XT-Audio: aplay -l (also check aplay -L): In this case PCH is the on-board audio device. |
That makes more sense, thanks a lot for the clarification! |
In my program, I'm currently attempting to set up the XtService in order of lowest->highest latency.
This code shows what I've tried to do: https://github.com/jameshball/osci-render/blob/06b0fdf6dfa8f21bfac2d26b1349d2e5c4a8d61b/src/main/java/sh/ball/audio/engine/XtAudioEngine.java#L98
Essentially, I'm doing the following, using the Core docs to guide my reasonings:
This achieves the intended result on Windows, where the latency from WASAPI is significantly lower than with DirectSound, however, when trying this on multiple Linux machines, if ALSA is used (SYSTEM_AUDIO) there is a very significant delay. I would estimate delays from ALSA to be more than a second. If I instead switch to PulseAudio (CONSUMER_AUDIO) then the latency is massively improved and is nearer the latency DirectSound on Windows (approx. 0.2 seconds?).
I am confused as to why this is the case, as I believe PulseAudio is simply a wrapper around ALSA? I have tried my program on three different Linux machines on different distros with the same result.
Do you have any advice or clarity on what APIs you think I should be using and when, or why you think the latency for ALSA is so large?
Thank you so much!
The text was updated successfully, but these errors were encountered: