feat(lambda-rs): Add audio device enumeration & playback#165
feat(lambda-rs): Add audio device enumeration & playback#165
Conversation
…h level implemenation for audio playback.
…n + audio streams.
There was a problem hiding this comment.
Pull request overview
Adds an initial, backend-agnostic audio output device API to lambda-rs (with a cpal-backed implementation in lambda-rs-platform), plus documentation and an example to validate audible playback.
Changes:
- Introduces
lambda::audiofacade API (device enumeration + callback-based playback) behind new audio features. - Implements
lambda_platform::cpalbackend (device discovery, stream config selection, stream creation). - Adds specs/docs and an
audio_sine_waveexample; updates feature documentation and locks new deps.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/specs/audio-devices.md | New spec defining the audio device abstraction, API surface, rules, and requirements. |
| docs/features.md | Documents new audio-related Cargo features and defaults. |
| crates/lambda-rs/src/lib.rs | Exposes audio module behind audio-output-device feature. |
| crates/lambda-rs/src/audio.rs | New public audio facade types + builder + enumeration function mapping to platform layer. |
| crates/lambda-rs/examples/audio_sine_wave.rs | Example demonstrating enumeration + 440 Hz tone playback via callback. |
| crates/lambda-rs/Cargo.toml | Adds audio features and enables audio by default via default = ["with-wgpu", "audio"]. |
| crates/lambda-rs-platform/src/lib.rs | Exposes internal cpal module behind audio-device feature. |
| crates/lambda-rs-platform/src/cpal/mod.rs | New module re-exporting internal audio backend surface. |
| crates/lambda-rs-platform/src/cpal/device.rs | Core cpal-backed implementation: config selection, stream creation, enumeration, writer semantics, tests. |
| crates/lambda-rs-platform/Cargo.toml | Adds optional cpal = "=0.17.1" dep and feature gates (audio-device, audio). |
| Cargo.lock | Locks new transitive dependencies introduced by cpal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| |_error| { | ||
| return; | ||
| }, | ||
| None, |
There was a problem hiding this comment.
The stream error callback passed to build_output_stream currently ignores all runtime stream errors (|_error| { return; }), which drops potentially important diagnostics (underruns, device disconnects, etc.). Please log these errors (e.g., via logging::error!) and consider incorporating the builder label to identify the stream/device in the message. Apply this consistently to all build_output_stream invocations in this module.
…ion to specify the requirement for it.
… for testing audio out (Will make a headless/game feature set to group certain features together in the future)
Summary
This PR introduces a new audio output device API to
lambda-rs, enabling applications to enumerate audio output devices and play audio through callbacks. All backend-specific code is encapsulated inlambda-rs-platform. This API is still in very early phases but will be used as the foundation to build out other audio capabilities in lambda.Related Issues
Changes
cpal(v0.17.1) as a dependency inlambda-rs-platformfor cross-platform audio supportlambda-rs-platform::cpalaudiomodule tolambda-rswith:AudioOutputDevicehandle for managing audio playbackAudioOutputDeviceBuilderfor configuring and creating output devicesenumerate_output_devices()function for discovering available audio endpointsAudioOutputWriterfor writing samples in output callbacksAudioCallbackInfofor providing stream configuration to callbacksAudioErrorfor actionable error reportingaudio_sine_waveexample demonstrating audio playback with a 440 Hz tonedocs/specs/audio-devices.md)docs/features.mdwith audio-related Cargo feature documentationType of Change
Affected Crates
lambda-rslambda-rs-platformlambda-rs-argslambda-rs-loggingChecklist
cargo +nightly fmt --all)cargo clippy --workspace --all-targets -- -D warnings)cargo test --workspace)Testing
Commands run:
cargo build --workspace cargo test --workspace cargo run -p lambda-rs --example audio_sine_wave --features audio-output-deviceManual verification steps (if applicable):
audio_sine_waveexample to verify that an audible tone plays for 2 secondsScreenshots/Recordings
N/A - Audio feature, verified by audible output.
Platform Testing
Additional Notes
New Cargo Features
This PR introduces the following Cargo features:
audio-output-devicelambda-rsaudio-cpallambda-rs-platformaudio-output-device)API Overview