cpal

Low-level, cross-platform audio I/O library for Rust with a unified API over ALSA, WASAPI, CoreAudio, JACK, and more.

Library
Cargo
v0.18.2
3,901stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
91/100Excellent
Development Activity96
Maintenance96
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture85
Code Quality80
Innovation72
Learning Curve62

cpal is a low-level cross-platform audio input/output library for Rust, providing a single Host/Device/Stream API that abstracts over each platform’s native audio backend: ALSA, PulseAudio, PipeWire, and JACK on Linux; WASAPI and ASIO on Windows; CoreAudio on macOS/iOS; AAudio on Android; and the Web Audio API/AudioWorklet in WebAssembly. Applications enumerate available devices and their supported stream configurations, then open an input or output stream with a callback invoked on each buffer of audio samples.

As part of the RustAudio organization, cpal is the foundational audio I/O layer underneath much of the Rust audio ecosystem — used directly by synthesizers, DAWs, voice-processing tools, and games, and as the device-access layer beneath higher-level crates like rodio. With 16+ million cumulative downloads and a very active maintenance cadence, it is the standard choice whenever a Rust project needs to capture or play raw audio samples without depending on a single OS’s native API.

What You Get

  • A Host/Device/Stream trait hierarchy that abstracts over platform-specific audio backends behind one API
  • Device enumeration and supported stream configuration querying (sample rate, channel count, sample format)
  • Callback-based input and output streams that deliver/consume buffers of audio samples in real time
  • Optional backends behind Cargo features: ASIO (low-latency Windows), JACK, PipeWire, and an AudioWorklet backend for WebAssembly
  • A realtime feature for platform-specific real-time thread scheduling to reduce audio glitches/underruns
  • A custom feature for plugging in user-defined hosts, devices, and streams for testing or non-standard backends

Common Use Cases

  • Capturing microphone input for a voice-processing, transcription, or voice-chat application
  • Building a software synthesizer, DAW, or audio effect processor that needs low-latency playback
  • Recording audio to disk (e.g. WAV) from the system’s default or a specifically selected input device
  • Cross-compiling one audio codebase to Linux, Windows, macOS, Android, iOS, and WebAssembly targets

Under The Hood

Architecture — cpal’s public API (src/traits.rs, src/lib.rs) defines Host, Device, and Stream traits, with src/host/ containing one backend implementation per platform (alsa, pulseaudio, pipewire, jack, wasapi, asio, coreaudio, aaudio, webaudio, audioworklet, plus a null backend for headless/CI use), and src/platform/mod.rs selecting the appropriate backend set at compile time via cfg attributes. This lets application code write against the trait interface once while the correct OS-specific implementation is compiled in per target. Tech Stack — Rust 2021 edition (rust-version 1.85+); most backends bind to system libraries directly (ALSA via alsa-sys, ASIO via the companion asio-sys workspace crate, WASAPI/CoreAudio via OS-provided COM/Core Foundation bindings), with an audioworklet feature adding wasm-bindgen/web-sys for WebAssembly targets and a realtime feature adding audio_thread_priority for real-time thread scheduling. Code Quality — The crate maintains an examples/ directory covering desktop, Android, iOS, and WASM builds (beep.rs, record_wav.rs, feedback.rs, synth_tones.rs), a documented UPGRADING.md for breaking changes, and a maintenance = actively-developed badge backed by a very active commit and release cadence (health-score development-activity and maintenance-consistency both near maximum). API Design — The Host/Device/Stream/callback model is intentionally minimal and close to the underlying OS APIs it wraps, so switching between backends (e.g. ALSA to JACK) requires no application code changes beyond host selection, though understanding platform-specific audio concepts (buffer sizes, sample formats, real-time scheduling) is still necessary to use it effectively.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search