Commit 244c59e
authored
feat(lambda-rs): Pitch and Volume control (#186)
## Summary
Add per-sound-instance volume (gain) and pitch (playback speed) controls
plus an `AudioContext` master 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
- Resolves #113
## Changes
- `lambda-rs`:
- Add `AudioContext::{set_master_volume, master_volume}`.
- Add `SoundInstance::{set_volume, volume}`.
- Add `SoundInstance::{set_pitch, pitch}` implemented via fractional
cursor + linear interpolation resampling.
- Apply transport ramp * master volume * instance volume in the
callback.
- Add clipping awareness (bounded output), with soft-knee limiting when
amplification is in effect.
- Add unit tests covering normalization behavior and output
scaling/bounding.
- `docs`:
- Add draft spec: `docs/specs/audio/sound-instance-gain-and-pitch.md`.
- Update specs index and cross-reference from `sound-playback`
non-goals.
- `lambda-demos-audio`:
- Add demo: `sound_instance_gain_pitch`.
- Add CLI modes (subcommands) using `lambda-rs-args`: `script`, `play`,
`repl`.
- Default behavior prints usage when invoked with no args.
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] Feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation (updates to docs, specs, tutorials, or comments)
- [ ] Refactor (code change that neither fixes a bug nor adds a feature)
- [ ] Performance (change that improves performance)
- [x] Test (adding or updating tests)
- [ ] Build/CI (changes to build process or CI configuration)
## Affected Crates
- [x] `lambda-rs`
- [ ] `lambda-rs-platform`
- [x] `lambda-rs-args` (used by demo for CLI parsing)
- [ ] `lambda-rs-logging`
- [x] Other: `lambda-demos-audio`
## Checklist
- [ ] Code follows the repository style guidelines (`cargo +nightly fmt
--all`)
- [ ] Code passes clippy (`cargo clippy --workspace --all-targets -- -D
warnings`)
- [x] Tests pass (see Testing section)
- [x] New code includes appropriate documentation
- [x] Public API changes are documented (spec + rustdoc)
- [ ] Breaking changes are noted in this PR description
## Testing
**Commands run:**
```bash
# Unit tests for audio playback (focused)
cargo test -p lambda-rs --no-default-features --features audio-playback
# Demo build
cargo build -p lambda-demos-audio --bin sound_instance_gain_pitch
```
**Manual verification steps (if applicable):**
1. `cargo run -p lambda-demos-audio --bin sound_instance_gain_pitch --
--help`
2. `cargo run -p lambda-demos-audio --bin sound_instance_gain_pitch --
script`
3. `cargo run -p lambda-demos-audio --bin sound_instance_gain_pitch --
repl`
- Try: `volume 0`, `volume 2`, `pitch 0.5`, `pitch 2`, `master 0.05`,
`master 0.25`
## Screenshots/Recordings
N/A
## Platform Testing
- [x] macOS
- [ ] Windows
- [ ] Linux
## Additional Notes
- Pitch is implemented as resampling (rate change), so it changes both
speed and perceived frequency (no time-stretch).
- Playback remains “single active sound” as per the existing
transport/playback design; volume/pitch are stored for the active slot.File tree
9 files changed
+1473
-53
lines changed- crates/lambda-rs/src/audio/playback
- demos/audio
- src/bin
- docs/specs
- audio
9 files changed
+1473
-53
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments