cpal icon indicating copy to clipboard operation
cpal copied to clipboard

ALSA or JACK

Open wiiznokes opened this issue 1 year ago • 4 comments

Should i use ALSA or JACK ? Looking at the documentation, ALSA doesn't have a dedicated thread. JACK is not mentioned. And ALSA is the default backend.

Note: Creating and running a stream will not block the thread. On modern platforms, the given callback is called by a dedicated, high-priority thread responsible for delivering audio data to the system’s audio device in a timely manner. On older platforms that only provide a blocking API (e.g. ALSA), CPAL will create a thread in order to consistently provide non-blocking behaviour (currently this is a thread per stream, but this may change to use a single thread for all streams).

wiiznokes avatar Nov 26 '24 13:11 wiiznokes

Unrelated but why there is no jack feature declared in Cargo.toml ?

wiiznokes avatar Nov 26 '24 13:11 wiiznokes

If you only need to target systems with pipewire or Linux users who care about audio latency, I would go with the JACK backend. Pipewire being the default sound system in some linux distros is pretty new, while ALSA will work almost anywhere. (There may be other benefits of ALSA that I'm not aware of.)

An implicit jack feature is inserted because the jack dependency is optional. This should probably be documented somewhere.

ErikNatanael avatar Dec 18 '24 09:12 ErikNatanael

can we disable alsa if we don't want to use it at all? that way it saves having to download the dev dependencies...

technobaboo avatar Jan 15 '25 20:01 technobaboo

No, ALSA isn't an optional dependency on Linux, but you could use rust-jack directly on Linux, it's very little extra code: https://github.com/RustAudio/rust-jack/blob/main/examples/sine.rs

ErikNatanael avatar Jan 15 '25 20:01 ErikNatanael