Skip to content

Releases: RustAudio/cpal

cpal 0.18.1

07 Jun 14:53
94ecb6e

Choose a tag to compare

A quick follow-up to 0.18.0 primarily to fix the docs.rs build failure.

  • docs.rs: Excluded pipewire, whose system dependency isn't available in that sandboxed build environment.
  • WASM: Fixed the audioworklet feature failing to compile on wasm32-wasip1 and other non-browser wasm32 targets.

No API or behavioral changes.

Links

cpal 0.18.0

06 Jun 21:07
45fe976

Choose a tag to compare

Hey everyone! cpal 0.18.0 is out, bringing two long-requested native Linux backends, a unified error API, and accurate timestamps across every platform.

What's New

Native PipeWire and PulseAudio

Two new first-class backends join the Linux and BSD lineup:

  • PipeWire
  • PulseAudio

Enable them with the pipewire and pulseaudio Cargo features. When multiple backends are compiled in, cpal selects the best available one at runtime: PipeWire > PulseAudio > ALSA.

Unified Error API

All per-operation error enums (DevicesError, BuildStreamError, StreamError, etc.) are replaced by a single cpal::Error with a kind() getter:

match device.default_output_config() {
    Err(e) => match e.kind() {
        cpal::ErrorKind::DeviceNotAvailable => { /* ... */ }
        cpal::ErrorKind::DeviceBusy => { /* retry */ }
        _ => { /* ... */ }
    }
}

Two new error kinds make previously indistinguishable cases actionable: DeviceBusy (EBUSY/EAGAIN is retryable) and PermissionDenied for OS-level access denials. See the upgrading guide for the mapping table.

Accurate Timestamps and A/V Sync

Timestamps previously reflected when the callback fired rather than when audio would actually reach hardware. This release corrects that across every backend:

  • AAudio: pipeline buffer depth accounted for; fallback to zero on error fixed
  • ALSA: LinkSynchronized hardware cross-timestamps for reduced jitter on supported devices
  • ASIO: driver-reported hardware latency included; re-queried on kAsioLatenciesChanged
  • CoreAudio: device latency and safety offset included
  • JACK: precise hardware cycle deadline; input capture timestamps were previously using callback execution time
  • WASAPI: hardware pipeline latency included
  • WebAudio: base and output latency included

A new StreamTrait::now() method lets you query the stream's clock from outside the callback for A/V sync: read the audio clock at any point and correlate it with your video timeline.

48 kHz is the New Default

default_input_config() and default_output_config() now prefer 48 kHz, then 44.1 kHz, on all backends. Defaulting to 44.1 kHz meant cpal's chosen rate often didn't match the hardware's preferred rate. Pin it explicitly if you need 44.1 kHz.

New API

  • StreamTrait::buffer_size() queries the stream's current buffer size
  • SupportedStreamConfigRange::try_with_standard_sample_rate() / with_standard_sample_rate() snaps to 48 kHz or 44.1 kHz from a supported range

Platform Improvements

  • ALSA: device_by_id() now accepts PCM shorthand names like hw:0,0 and plughw:foo; streams attempt to recover after system suspend; capture streams no longer hang on overruns; backward-stepping timestamps during startup and xrun recovery are fixed.

  • ASIO: collect() on the device iterator no longer stops after the first device; device enumeration and stream creation now work correctly when called from spawned threads; distortion from drivers that fire the buffer callback multiple times per cycle is fixed.

  • CoreAudio: the physical stream format is now set directly on the hardware device rather than relying on the HAL mixer; user-specified timeouts are now respected when building a stream.

  • JACK: buffer size changes no longer fire an error callback but resizes internal buffers, avoiding unnecessary stream rebuilds; server shutdown now surfaces as ErrorKind::DeviceNotAvailable.

  • WASAPI: device names now prefer FriendlyName over DeviceDesc, so you see the readable name from system settings; default streams automatically reroute when the system default device changes.

...and a lot more. The changelog has the full picture.

Breaking Changes

  • Streams now require an explicit play() call: ALSA, CoreAudio, and JACK previously auto-started streams on creation. If you never called play(), your callback will never fire after upgrading.
  • Error types unified: match on e.kind() instead of per-operation error enums.
  • StreamConfig passed by value: StreamConfig now implements Copy; drop the & at build_*_stream call sites.
  • StreamInstant API overhauled: aligns with std::time::Instant. Change add/sub to checked_add/checked_sub (or +/-); duration_since returns Duration (saturating), secs/nanos are now u64.
  • Default sample rate is now 48 kHz: pin explicitly if you need 44.1 kHz.
  • Default sample format heuristics now fully ranked: floats before integers, higher bit-depth before lower; pin F32 explicitly if you were relying on it as the default.
  • Emscripten host removed: migrate to wasm32-unknown-unknown with the wasm-bindgen feature.

Full details and migration examples in the upgrading guide.

Looking Ahead to v0.19

The design goals are tracked in #1220. Highlights:

  • Extension traits: clean access to platform-specific functionality like RAW mode on WASAPI, control panel on ASIO, identifying stream properties on PipeWire, etc.
  • Exclusive mode on CoreAudio and WASAPI
  • Duplex stream API
  • Input streams on WASM: microphone access from the browser
  • Stream lifecycle normalization: play/pause to start/pause/stop with a draining stop
  • Native DSD on WASAPI
  • BufferSize refactor with range support

The feature set may change.

Thanks to Our Contributors

16 people contributed to this release, 13 of them for the first time: Access (@Decodetalkers), atlv (@atlv24), Chandler Newman (@csnewman), Colin Marc (@colinmarc), Edwin Löffler (@edwloef), Jerry.Wang (@wangjia184), Mat Silverstein (@silverstein), Mike Hilgendorf (@m-hilgendorf), osoftware (@osoftware), Raphael Poss (@knz), Seto Elkahfi (@setoelkahfi), Sintel (@Sin-tel), thewh1teagle (@thewh1teagle), Umer Haider (@umerhd), and Worik Stanton (@worikgh). Welcome aboard, and thank you all!

Support the Project

If you find value in cpal, sponsorships are a heartfelt token of appreciation and help cover the costs of building it: music service subscriptions, hardware for cross-platform compatibility, and tooling. Every contribution helps: sponsor me at GitHub.

Links

Huge thanks to everyone who contributed to this release!

asio-sys 0.3.0

06 Jun 20:41
baa3678

Choose a tag to compare

Added

  • Added Driver::latencies() to query input and output stream latencies
  • Added BufferPreference enum with the driver's preferred buffer size and valid-size constraints

Changed

  • Driver::add_message_callback and Driver::remove_message_callback replaced by Driver::add_event_callback and Driver::remove_event_callback
  • MessageCallback renamed to DriverEventCallback, and MessageCallbackId renamed to DriverEventCallbackId. DriverEventCallback wraps Fn(AsioDriverEvent) -> bool whereAsioDriverEvent is a new enum covering both asioMessage selector events and sampleRateDidChange notifications
  • CallbackId renamed to BufferCallbackId
  • Public-facing c_long fields and return types replaced with i32
  • Public-facing c_double parameters and return types replaced with f64
  • CallbackInfo::system_time is now u64 nanoseconds
  • AsioError::ASE_NoMemory renamed to AsioError::NoMemory
  • Extended BufferSizeRange with a preferred: BufferPreference field
  • AsioTime::reserved, AsioTimeInfo::reserved, AsioTimeCode::future fields made private.
  • asio_import module is now pub(crate); raw bindgen types are no longer public API
  • asio_message now dispatches kAsioResyncRequest and kAsioLatenciesChanged to callbacks
  • asio_message delegates kAsioSelectorSupported for unknown selectors to registered callbacks, so each host decides which capabilities it opts into
  • sample_rate_did_change now dispatches AsioDriverEvent::SampleRateChanged to registered callbacks when the reported rate differs from the last known rate

Fixed

  • Fixed TOCTOU race condition when creating streams concurrently
  • Fixed data race where channels, latencies, sample_rate, and related query methods could call ASIO concurrently during set_sample_rate's teardown/reload
  • Fixed Asio::load_driver to return LoadDriverError::LoadDriverFailed instead of panicking when the driver name contains a null byte
  • Fixed Driver::set_sample_rate to perform a dummy buffer cycle and driver reload when the driver does not apply the rate change immediately, as required by some drivers (e.g. Steinberg)
  • Fixed asio_message not advertising kAsioSelectorSupported itself as a supported selector
  • Fixed rust-analyzer errors on non-Windows targets by using stub instead of ASIO bindings

Removed

  • Removed unused SampleRate struct
  • Removed DriverState from the public API

cpal 0.17.3

18 Feb 20:57
fd3b945

Choose a tag to compare

Changed

  • Reverted SemVer-breaking DeviceBusy error variant addition.

Fixed

  • ASIO: Fix linker errors.

asio-sys 0.2.6

18 Feb 20:49
fd3b945

Choose a tag to compare

Fixed

  • Link advapi32 to resolve Windows Registry API symbols.

cpal 0.17.2

08 Feb 21:59

Choose a tag to compare

This release was yanked.

Added

  • DeviceBusy error variant for retriable device access errors (EBUSY, EAGAIN).
  • ALSA: Debug implementations for Host, Device, Stream, and internal types.
  • ALSA: Example demonstrating ALSA error suppression during enumeration.
  • WASAPI: Enable as-necessary resampling in the WASAPI server process.

Changed

  • Bump overall MSRV to 1.78.
  • ALSA: Update alsa dependency to 0.11.
  • ALSA: Bump MSRV to 1.82.
  • CoreAudio: Update core-audio-rs dependency to 0.14.

Fixed

  • ALSA: Enumerating input and output devices no longer interferes with each other.
  • ALSA: Device handles are no longer exclusively held between operations.
  • ALSA: Reduce Valgrind memory leak reports from ALSA global configuration cache.
  • ALSA: Fix possible race condition on drop.
  • ALSA: Fix audio callback stalling when start threshold is not met.

cpal 0.17.1

04 Jan 14:45
ddad8bc

Choose a tag to compare

Added

  • ALSA: Default implementation for Device (returns the ALSA "default" device).
  • CI: Checks default/no-default/all feature sets with platform-dependent MSRV for JACK.

Fixed

  • ALSA: Device enumeration now includes both hints and physical cards.
  • JACK: No longer builds on iOS.
  • WASM: WasmBindgen no longer crashes (regression from 0.17.0).

Changed

  • ALSA: Devices now report direction from hint metadata and physical hardware probing.

asio-sys 0.2.5

04 Jan 14:32
ddad8bc

Choose a tag to compare

Fixed

  • Fixed ASIO SDK discovery on case sensitive filesystems.

cpal 0.17.0

20 Dec 19:18
4b8c6c3

Choose a tag to compare

Added

  • DeviceTrait::id method that returns a stable audio device ID.
  • HostTrait::device_by_id to select a device by its stable ID.
  • Display and FromStr implementations for HostId.
  • Support for custom Hosts, Devices, and Streams.
  • Sample::bits_per_sample method.
  • Copy implementation to InputCallbackInfo and OutputCallbackInfo.
  • StreamError::StreamInvalidated variant for when stream must be rebuilt.
  • StreamError::BufferUnderrun variant for buffer underrun/overrun notifications.
  • Hash implementation to Device for all backends.
  • AAudio: Send and Sync implementations to Stream.
  • AAudio: Support for 12 and 24 kHz sample rates.
  • ALSA: I24 and U24 sample format support (24-bit samples stored in 4 bytes).
  • ALSA: Support for 12, 24, 352.8, 384, 705.6, and 768 kHz sample rates.
  • ALSA: Eq and PartialEq implementations to Device.
  • CI: Native ARM64 Linux support in GitHub Actions.
  • CoreAudio: i8, i32 and I24 sample format support (24-bit samples stored in 4 bytes).
  • CoreAudio: Support for loopback recording (recording system audio output) on macOS > 14.6.
  • CoreAudio: Send implementation to Stream.
  • Emscripten: BufferSize::Fixed validation against supported range.
  • iOS: Complete AVAudioSession integration for device enumeration and buffer size control.
  • JACK: Support for macOS and Windows platforms.
  • JACK: BufferSize::Fixed validation to reject requests that don't match server buffer size.
  • WASAPI: Expose IMMDevice from WASAPI host Device.
  • WASAPI: I24 and U24 sample format support (24-bit samples stored in 4 bytes).
  • WASAPI: Send and Sync implementations to Stream.
  • WebAudio: Send and Sync implementations to Stream.
  • WebAudio: BufferSize::Fixed validation against supported range.

Changed

  • MSRV depends on the platform and at minimum 1.77.
  • Set examples to Rust 2021.
  • SampleRate from struct to u32 type alias.
  • Update audio_thread_priority to 0.34.
  • Migrate CHANGELOG to Keep a Changelog format.
  • AAudio: Configure buffer to ensure consistent callback buffer sizes.
  • AAudio: Buffer size range detection to query the AudioService property correctly.
  • ALSA: Improve BufferSize::Fixed precision and audio callback performance.
  • ALSA: BufferSize::Default to use the device defaults.
  • ALSA: Card enumeration to work like aplay -L does.
  • ALSA: Update alsa to 0.10.
  • ALSA: Pass silent=true to PCM.try_recover, so it doesn't write to stderr.
  • ALSA: Report buffer underruns/overruns via StreamError::BufferUnderrun.
  • ASIO: Share sys::Asio instance across all Host instances.
  • CI: Fix cargo publish to trigger on GitHub releases instead of every master commit.
  • CI: Replace cargo install commands with cached tool installation for faster builds.
  • CI: Update actions to latest versions (checkout@v5, rust-cache@v2).
  • CI: Verify compatibility with windows crates since v0.59.
  • CI: Test platforms on appropriate MSRV per backend.
  • CI: Fix cargo update syntax for compatibility with Cargo 1.70 (use -p flag instead of positional argument).
  • CoreAudio: Device::supported_configs to return a single element containing the available sample rate range when all elements have the same mMinimum and mMaximum values.
  • CoreAudio: Default audio device detection to be lazy when building a stream, instead of during device enumeration.
  • CoreAudio: Configure device buffer to ensure predictable callback buffer sizes.
  • CoreAudio: Remove Clone implementation from Stream.
  • JACK: Use StreamError::StreamInvalidated for JACK server sample rate changes.
  • JACK: Report buffer underruns/overruns via StreamError::BufferUnderrun.
  • WASAPI: Update windows to >= 0.59, <= 0.62.

Fixed

  • ALSA: Format selection to probe hardware endianness instead of assuming native byte order.
  • ALSA: Data race in stream shutdown.
  • ASIO: Handling for kAsioResetRequest message to prevent driver UI becoming unresponsive.
  • ASIO: Buffer silencing logic to work with non-conformant drivers (e.g., FL Studio ASIO).
  • CoreAudio: Timestamp accuracy.
  • CoreAudio: Segfaults when enumerating devices.
  • CoreAudio: Undefined behavior related to null pointers and aligned reads.
  • CoreAudio: Unnecessary microphone permission requests when using output devices only.
  • iOS: Example by properly activating audio session.

Removed

  • WebAudio: Optional wee-alloc feature for security reasons.

asio-sys 0.2.4

20 Dec 19:01
e394d6c

Choose a tag to compare

Fixed

  • Fixed docs.rs documentation build by generating stub bindings when building for docs.rs
  • Fixed buffer switch detection to work correctly with non-conformant ASIO drivers