About this project
CPAL (Cross-Platform Audio Library) is a low-level Rust library for audio input and output. It is intended as a foundation layer; the README points users wanting higher-level playback and capture toward Rodio or similar libraries.
Capabilities described in the README:
- Enumerate audio hosts, devices and their supported stream configurations.
- Look up devices by stable ID or by default input/output role.
- Inspect device metadata: name, manufacturer, type and bus type.
- Build input and output streams with compile-time or runtime sample formats.
- Play, pause, and query the buffer size and clock of a stream.
Platforms and default backends:
- Android: AAudio
- BSD: ALSA (optional JACK, PipeWire, PulseAudio)
- iOS, macOS, tvOS, visionOS: CoreAudio (macOS optionally JACK)
- Linux: ALSA (optional JACK, PipeWire, PulseAudio)
- WebAssembly: Web Audio API (optional Audio Worklet)
- Windows: WASAPI (optional ASIO, JACK)
Optional features include asio, audioworklet, custom, jack, pipewire, pulseaudio, realtime, realtime-dbus and wasm-bindgen. The README documents build dependencies (for example libasound2-dev on Debian/Ubuntu for ALSA, which is required even when using JACK, PipeWire or PulseAudio), minimum supported Rust and OS/runtime versions per backend, and setup steps for Android (cargo-apk, JNI context initialization), ASIO (CPAL_ASIO_DIR, LLVM/Clang, LIBCLANG_PATH, Visual Studio, MinGW-w64 cross-compilation) and WebAssembly.
Troubleshooting guidance covers missing default devices, ALSA/PipeWire/PulseAudio device contention (DeviceBusy when a sound server holds the ALSA default device), buffer size configuration and its latency trade-offs, PipeWire resampling glitches, ALSA real-time priority promotion (SCHED_FIFO, CAP_SYS_NICE, rtprio limits, rtkit via D-Bus), and build errors. Duplex devices are discussed: CPAL does not compose devices itself and requires a device that already claims both capture and playback, with ALSA asym plugin or JACK client ports as options.
The repository ships examples under examples/ (for instance beep), runnable with cargo run --example beep and feature flags for platform-specific backends. Licensing is Apache-2.0.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.