Skip to content

cvc::gl::playback: SDL3 audio-output sink (f32 PCM playback) - #535

Merged
transfix merged 1 commit into
masterfrom
feat/stream-audio-output
Oct 2, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/stream-audio-output

Conversation

@transfix

@transfix transfix commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Holy-grail step (b): the SDL3 audio playback sink — the output mirror of the capture source (device audio source is #534). Independent of the #532→#534 stack (needs only the merged stream substrate), so it targets master directly.

open_audio_output() / list_audio_playback_devices() wrap an SDL3 playback device as an audio_output sink that consumes interleaved f32 PCM. Where a capture source is a frame_source a stream pulls from, an audio_output is a push sink the app feeds: pull frames off a stream subscription on the app tick and hand each chunk to play(). It's deliberately untied from the stream types (takes raw bytes), so it plays a live mic stream, a replayed recording, or any f32 PCM in hand — the record/playback half of the mic demo.

Structure: new src/cvcGL/playback/ dir (cvc::gl::playback), symmetric to capture/, with its own glob. SDL-gated on CVC_ENABLE_SDL, graceful no-op without it.

API: play(data, bytes) (push model, SDL_PutAudioStreamData), queued_bytes() (pacing / "done"), flush() (drop the queue). Subsystem refcount balanced on every path; resume failure fails the open loudly; dtor closes the device then quits the subsystem.

Robustness: play() rejects a non-frame-aligned size and pushes in frame-aligned slices, so a single buffer larger than INT_MAX (~93 min of f32 stereo @ 48 kHz) queues whole instead of truncating.

Testing: device-gated cvcgl_audio_output (enumeration always; live playback behind CVC_TEST_AUDIO) plays a generated tone and verifies the device queues then drains it. Builds clean with SDL on; passes with graceful SKIP on a headless builder.

Folds an adversarial review: the size_t→int truncation fix plus a documented flush() device-buffer-tail caveat.

open_audio_output()/list_audio_playback_devices() wrap an SDL3 playback device
as an audio_output sink consuming interleaved f32 PCM — the output mirror of
cvc::gl::capture::audio_source. Where a capture source is a frame_source a stream
PULLS from, an audio_output is a push sink the app feeds: pull frames off a stream
subscription on the app tick and hand each chunk to play(). Deliberately untied
from the stream types (takes raw bytes), so it plays a live mic stream, a replayed
recording, or any f32 the app holds — the holy-grail mic record/playback path.

New src/cvcGL/playback/ dir (cvc::gl::playback), symmetric to capture/, its own
glob in the cvcGL CMakeLists. SDL-gated on CVC_ENABLE_SDL, graceful no-op without
it. Push model (SDL_PutAudioStreamData); queued_bytes() for pacing/"done";
flush() drops the queue. Subsystem refcount balanced on every path; resume failure
fails the open loudly; dtor closes device then quits the subsystem.

play() rejects a non-frame-aligned size and pushes in frame-aligned slices so a
single buffer larger than INT_MAX queues whole instead of truncating. Device-gated
test (enumeration always; live playback behind CVC_TEST_AUDIO) plays a generated
tone and verifies the device queues then drains it.

Folds an adversarial review: the size_t->int truncation fix plus the flush()
device-buffer-tail caveat.
@transfix
transfix enabled auto-merge October 2, 2026 06:31
@transfix
transfix merged commit 82b71c1 into master Oct 2, 2026
11 of 13 checks passed
@transfix
transfix deleted the feat/stream-audio-output branch October 29, 2026 20:53
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