feat(lambda-rs): Add sound playback devices#184
Conversation
… implementations.
…dd play sound implementation.
✅ Coverage Report📊 View Full HTML Report (download artifact) Overall Coverage
Changed Files in This PR
PR Files Coverage: 76.28% (3207/4204 lines) Generated by cargo-llvm-cov · Latest main coverage Last updated: 2026-02-12 22:41:50 UTC · Commit: |
There was a problem hiding this comment.
Pull request overview
This pull request implements single-sound playback for the lambda-rs audio system, enabling basic transport controls (play, pause, stop) with looping support and click-free transitions. The implementation adds an AudioContext API with SoundInstance handles for controlling playback, backed by a lock-free command queue for thread-safe communication between the main thread and the real-time audio callback.
Changes:
- Adds
audio-playbackfeature flag and public APIs (AudioContext,AudioContextBuilder,SoundInstance,PlaybackState) - Implements lock-free SPSC command queue for real-time-safe communication with audio callback thread
- Implements single-voice playback scheduler with linear gain ramps for click-free transport transitions
- Updates
SoundBufferinternal storage fromVec<f32>toArc<[f32]>for efficient sharing with audio thread - Adds comprehensive unit tests covering command queue, scheduler, and controller behavior
- Includes runnable demo and updates documentation (spec, features guide, index)
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/specs/audio/sound-playback.md | New specification document detailing playback API surface, behavior requirements, and implementation constraints |
| docs/specs/README.md | Updated index to include sound playback specification |
| docs/features.md | Documents audio-playback feature flag and its composition with other audio features |
| demos/audio/src/bin/sound_playback_transport.rs | Demo application exercising transport controls and looping |
| demos/audio/Cargo.toml | Adds audio-playback feature to demo package |
| crates/lambda-rs/src/audio/playback.rs | Core implementation: CommandQueue, GainRamp, PlaybackScheduler, PlaybackController, and public API |
| crates/lambda-rs/src/audio/mod.rs | Feature-gates and re-exports playback module |
| crates/lambda-rs/src/audio/buffer.rs | Changes sample storage to Arc<[f32]> and adds test helper for creating buffers |
| crates/lambda-rs/Cargo.toml | Defines audio-playback feature and updates audio umbrella |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// This type is a placeholder API surface used while sound playback is under | ||
| /// active development. It is expected to become fully functional in a | ||
| /// subsequent change set. |
There was a problem hiding this comment.
The comment states "This type is a placeholder API surface used while sound playback is under active development. It is expected to become fully functional in a subsequent change set," but this PR implements the full functionality. This comment should be updated or removed to accurately reflect that AudioContext is now fully functional.
| /// This type is a placeholder API surface used while sound playback is under | |
| /// active development. It is expected to become fully functional in a | |
| /// subsequent change set. | |
| /// This type is the main entry point for single-sound playback and transport | |
| /// control. It manages the audio output device, queues playback commands, and | |
| /// exposes shared playback state such as sample rate and channel configuration. |
| let _result = self.command_queue.push(PlaybackCommand::StopCurrent); | ||
|
|
There was a problem hiding this comment.
The result of pushing the StopCurrent command is silently discarded. If the queue is full and this push fails, but subsequent pushes succeed, this could lead to unexpected behavior. Consider either: (1) checking if the push failed and handling it appropriately, (2) documenting why it's safe to ignore this failure, or (3) removing the StopCurrent command if the SetBuffer command handler already stops playback (which it does on line 619).
| let _result = self.command_queue.push(PlaybackCommand::StopCurrent); |
Summary
Add single-sound playback for
SoundBufferthrough anAudioContextwith basictransport controls (play, pause, stop), looping, and playback state queries.
Related Issues
Changes
audio-playbackfeature inlambda-rs.AudioContextBuilder/AudioContextandSoundInstancetransportcontrols with
PlaybackStatequeries.main thread to the audio callback thread.
SoundBuffersample storage toArc<[f32]>to avoid large copies whensharing with the audio callback.
sound_playback_transport(play/pause/stop + looping).audio-playbackin docs/features.md.Type of Change
Affected Crates
lambda-rslambda-rs-platformlambda-rs-argslambda-rs-logginglambda-demos-audioChecklist
cargo +nightly fmt --all)cargo clippy --workspace --all-targets -- -D warnings)cargo test --workspace)Testing
Commands run:
cargo +nightly fmt --all cargo clippy --workspace --all-targets -- -D warnings cargo clippy -p lambda-rs --all-targets --features audio-playback -- -D warnings cargo test -p lambda-rs --features audio-playbackManual verification steps (if applicable):
cargo run -p lambda-demos-audio --features audio-playback --bin sound_playback_transport.Screenshots/Recordings
N/A
Platform Testing
Additional Notes
sounds).