Skip to content

Audio: device selection and stream, opt-in at init - #301

Draft
catilac wants to merge 1 commit into
audio-forksfrom
audio-devices
Draft

catilac wants to merge 1 commit into
audio-forksfrom
audio-devices

Conversation

@catilac

@catilac catilac commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #300. Adds audio device handling and the audio stream.

Audio is opt-in at init. Set ConfigKey::AudioEnabled to "true" before init(). Seedling then builds the context and graph at startup, and the stream is open by the time init() returns. Without the flag no device is opened, nothing runs per frame, and the audio functions return AudioNotEnabled (device listing still works).

Device handling (device.rs) replaces seedling's CpalPlatformPlugin:

  • One output and one optional input device, chosen by name (ConfigKey::Audio*) or index (audio_set_*_device_index). The input defaults to none, so no microphone permission prompt unless a sketch asks for an input.
  • A named output is never swapped for another device. If it disappears the stream stops, and it resumes on the same graph when the device comes back. This matters when outputs are wired to speakers or DC-coupled gear.
  • Device, sample rate and block size can change while running.
  • audio_status, audio_info and audio_events (lost/restored devices, xruns, restarts).

Review notes

  • lib.rs: the plugin, the opt-in check and the public functions.
  • device.rs: device selection, stream lifecycle and reconnection.
  • tests.rs adds a mock backend that pulls blocks without audio hardware. It's used here for startup and repeated restarts at changing block sizes; later PRs add graph tests on top of it.

Testing


Stack created with GitHub Stacks CLI • Give Feedback 💬

A sketch enables audio with ConfigKey::AudioEnabled before init(). Seedling then builds the context and graph at startup and we open the stream during init(); without the flag no device is opened and the audio functions return AudioNotEnabled.

We manage the cpal stream ourselves instead of seedling's CpalPlatformPlugin:
- one output and one optional input device (none by default, so no microphone prompt), by name or index;
- a named output is never swapped for another device: if it disappears the stream stops, and it resumes on the same graph when the device returns;
- device, sample rate and block size can change while running;
- status, info and stream events (lost/restored devices, xruns, restarts).

Tests run on a mock backend that pulls blocks without audio hardware, including restarts at changing block sizes.
@catilac
catilac added this pull request to stack #306 December 1, 2026 05:13
@catilac catilac changed the title processing_audio: audio devices and stream, opt-in at init Audio: device selection and stream, opt-in at init Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to 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.

1 participant