Uh oh!
There was an error while loading. Please reload this page.
feat(lambda-rs): Pitch and Volume control - #186
Conversation
✅ Coverage Report📊 View Full HTML Report (download artifact) Overall Coverage
Changed Files in This PR
PR Files Coverage: 94.76% (1339/1413 lines) Generated by cargo-llvm-cov · Latest main coverage Last updated: 2026-02-17 22:58:33 UTC · Commit: |
There was a problem hiding this comment.
Pull request overview
This PR adds per-sound-instance volume and pitch controls, plus a global master volume on AudioContext. The implementation uses atomic storage for lock-free access from the audio callback thread, with pitch implemented via fractional cursor advancement and linear interpolation resampling. A comprehensive CLI demo exercises all transport, gain, and pitch controls through script, play, and REPL modes.
Changes:
- Added
SoundInstance::{set_volume, volume, set_pitch, pitch}andAudioContext::{set_master_volume, master_volume}APIs with infallible normalization for invalid inputs - Implemented pitch control via fractional frame cursor (f32) with linear interpolation resampling between adjacent samples
- Added soft-knee limiter for amplified output when combined gains exceed 1.0, with non-finite sample handling
- Created
sound_instance_gain_pitchdemo with three modes (script, play, repl) for interactive testing - Added comprehensive unit tests for normalization, pitch resampling, volume scaling, and clipping behavior
- Documented the feature in new spec
sound-instance-gain-and-pitch.mdwith API surface, behavior, and validation rules
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/specs/audio/sound-instance-gain-and-pitch.md | New spec documenting API surface, behavior, validation rules, and acceptance criteria for volume/pitch controls |
| docs/specs/audio/sound-playback.md | Updated non-goals section to reference new gain/pitch spec instead of listing as out-of-scope |
| docs/specs/README.md | Added index entry for new sound-instance-gain-and-pitch spec |
| crates/lambda-rs/src/audio/playback/transport.rs | Added AtomicU32 storage for master_volume, instance_volume, instance_pitch with normalization helpers |
| crates/lambda-rs/src/audio/playback/context.rs | Added public API methods on AudioContext and SoundInstance with unit tests for defaults, clamping, and reset behavior |
| crates/lambda-rs/src/audio/playback/callback.rs | Changed cursor to f32 for fractional advancement, added linear interpolation resampling, soft-clip limiter, and comprehensive tests |
| demos/audio/src/bin/sound_instance_gain_pitch.rs | New interactive demo with CLI argument parsing and three modes for exercising volume/pitch/master controls |
| demos/audio/Cargo.toml | Added lambda-rs-args dependency for CLI parsing in demo |
| Cargo.lock | Dependency lockfile update for lambda-rs-args |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
Add per-sound-instance volume (gain) and pitch (playback speed) controls plus an
AudioContextmaster volume, implemented in the audio callback scheduler (single active sound). Includes a demo for interactively exercising transport/gain/pitch/master controls and updated audio specs.Related Issues
Changes
lambda-rs:AudioContext::{set_master_volume, master_volume}.SoundInstance::{set_volume, volume}.SoundInstance::{set_pitch, pitch}implemented via fractional cursor + linear interpolation resampling.docs:docs/specs/audio/sound-instance-gain-and-pitch.md.sound-playbacknon-goals.lambda-demos-audio:sound_instance_gain_pitch.lambda-rs-args:script,play,repl.Type of Change
Affected Crates
lambda-rslambda-rs-platformlambda-rs-args(used by demo for CLI parsing)lambda-rs-logginglambda-demos-audioChecklist
cargo +nightly fmt --all)cargo clippy --workspace --all-targets -- -D warnings)Testing
Commands run:
Manual verification steps (if applicable):
cargo run -p lambda-demos-audio --bin sound_instance_gain_pitch -- --helpcargo run -p lambda-demos-audio --bin sound_instance_gain_pitch -- scriptcargo run -p lambda-demos-audio --bin sound_instance_gain_pitch -- replvolume 0,volume 2,pitch 0.5,pitch 2,master 0.05,master 0.25Screenshots/Recordings
N/A
Platform Testing
Additional Notes