Skip to content

feat(lambda-rs): Add audio device enumeration & playback - #165

Merged
vmarcella merged 17 commits into
mainfrom
vmarcella/audio-devices
Jan 31, 2026
Merged

feat(lambda-rs): Add audio device enumeration & playback#165
vmarcella merged 17 commits into
mainfrom
vmarcella/audio-devices

Conversation

@vmarcella

Copy link
Copy Markdown
Member

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 in lambda-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

  • Add cpal (v0.17.1) as a dependency in lambda-rs-platform for cross-platform audio support
  • Implement platform-level audio device enumeration and stream creation in lambda-rs-platform::cpal
  • Add application-facing audio module to lambda-rs with:
    • AudioOutputDevice handle for managing audio playback
    • AudioOutputDeviceBuilder for configuring and creating output devices
    • enumerate_output_devices() function for discovering available audio endpoints
    • AudioOutputWriter for writing samples in output callbacks
    • AudioCallbackInfo for providing stream configuration to callbacks
    • AudioError for actionable error reporting
  • Add audio_sine_wave example demonstrating audio playback with a 440 Hz tone
  • Add comprehensive specification document (docs/specs/audio-devices.md)
  • Update docs/features.md with audio-related Cargo feature documentation

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • 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)
  • Test (adding or updating tests)
  • Build/CI (changes to build process or CI configuration)

Affected Crates

  • lambda-rs
  • lambda-rs-platform
  • lambda-rs-args
  • lambda-rs-logging
  • Other:

Checklist

  • Code follows the repository style guidelines (cargo +nightly fmt --all)
  • Code passes clippy (cargo clippy --workspace --all-targets -- -D warnings)
  • Tests pass (cargo test --workspace)
  • New code includes appropriate documentation
  • Public API changes are documented
  • Breaking changes are noted in this PR description

Testing

Commands run:

cargo build --workspace
cargo test --workspace
cargo run -p lambda-rs --example audio_sine_wave --features audio-output-device

Manual verification steps (if applicable):

  1. Run the audio_sine_wave example to verify that an audible tone plays for 2 seconds
  2. Verify device enumeration lists available system audio outputs with correct default marking

Screenshots/Recordings

N/A - Audio feature, verified by audible output.

Platform Testing

  • macOS
  • Windows
  • Linux

Additional Notes

New Cargo Features

This PR introduces the following Cargo features:

FeatureCrateDefaultDescription
audio-output-devicelambda-rsYesEnables audio output device enumeration and playback
audio-cpallambda-rs-platformNoInternal cpal backend (activated by audio-output-device)

API Overview

// Enumerate available output deviceslet devices = enumerate_output_devices()?;// Build and play audio through the default devicelet device = AudioOutputDeviceBuilder::new().with_label("my_app").with_sample_rate(48000).with_channels(2).build_with_output_callback(|writer, info| {// Write audio samples here})?;

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::audio facade API (device enumeration + callback-based playback) behind new audio features.
  • Implements lambda_platform::cpal backend (device discovery, stream config selection, stream creation).
  • Adds specs/docs and an audio_sine_wave example; 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
FileDescription
docs/specs/audio-devices.mdNew spec defining the audio device abstraction, API surface, rules, and requirements.
docs/features.mdDocuments new audio-related Cargo features and defaults.
crates/lambda-rs/src/lib.rsExposes audio module behind audio-output-device feature.
crates/lambda-rs/src/audio.rsNew public audio facade types + builder + enumeration function mapping to platform layer.
crates/lambda-rs/examples/audio_sine_wave.rsExample demonstrating enumeration + 440 Hz tone playback via callback.
crates/lambda-rs/Cargo.tomlAdds audio features and enables audio by default via default = ["with-wgpu", "audio"].
crates/lambda-rs-platform/src/lib.rsExposes internal cpal module behind audio-device feature.
crates/lambda-rs-platform/src/cpal/mod.rsNew module re-exporting internal audio backend surface.
crates/lambda-rs-platform/src/cpal/device.rsCore cpal-backed implementation: config selection, stream creation, enumeration, writer semantics, tests.
crates/lambda-rs-platform/Cargo.tomlAdds optional cpal = "=0.17.1" dep and feature gates (audio-device, audio).
Cargo.lockLocks new transitive dependencies introduced by cpal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +465 to +468
|_error| {
return;
},
None,

CopilotAIJan 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment threadcrates/lambda-rs/Cargo.toml Outdated
Comment threaddocs/features.md
Comment threadcrates/lambda-rs-platform/src/cpal/device.rs Outdated
Comment threadcrates/lambda-rs-platform/src/cpal/device.rs Outdated
… for testing audio out (Will make a headless/game feature set to group certain features together in the future)
@vmarcella
vmarcella merged commit 928d6e3 into mainJan 31, 2026
8 checks passed
@vmarcella
vmarcella deleted the vmarcella/audio-devices branch January 31, 2026 03:27
@vmarcellavmarcella linked an issue Jan 31, 2026 that may be closed by this pull request
5 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Audio device initialization and enumeration

2 participants

@vmarcella