Skip to content

ALSA duplex bridge example (hardware testing Setup 1)#20

Merged
tap merged 1 commit into
mainfrom
claude/alsa-bridge
Jun 12, 2026
Merged

ALSA duplex bridge example (hardware testing Setup 1)#20
tap merged 1 commit into
mainfrom
claude/alsa-bridge

Conversation

@tap

@tap tap commented Jun 12, 2026

Copy link
Copy Markdown
Owner

The Setup 1 deliverable from docs/HARDWARE_TESTING.md: a real-clock test harness bridging two independent ALSA devices through the converter — the canonical two-USB-dongle Raspberry Pi soak test.

What's in here

  • examples/alsa_bridge.cpp: capture thread (blocking snd_pcm_readipush()) and playback thread (pull()snd_pcm_writei); CLI for devices/rate/channels/period/latency; once-per-second status line plus optional --csv telemetry log (time_s,state,ppm,fill,underruns,overruns,resyncs) and --dump of the post-ASRC float stream for offline analysis with the notebook tooling; --tone mode keeps the read cadence on the input device's real crystal but pushes a synthetic sine (clean-signal soak without trusting dongle analog); SIGINT-clean shutdown.
  • Format negotiation tries FLOAT_LE, falls back to S16_LE with conversion; ALSA buffer = 4× period; xruns go through snd_pcm_recover, fatal only if recovery fails; non-exact set_rate_near is a hard error (both domains must be nominally equal for a near-unity ASRC).
  • examples/CMakeLists.txt: built only when find_package(ALSA) succeeds — macOS/Windows/no-ALSA configures verified unaffected (including with -DCMAKE_DISABLE_FIND_PACKAGE_ALSA=ON).

Verified

Warning-clean under the project flags; --help/bad-args/no-device paths exit gracefully. Not verified: actual audio I/O — no hardware here. This is the piece you point at a Pi with two dongles; the README's hardware-testing doc now references the workflow.

https://claude.ai/code/session_01HuAFfoeD5a5Xe5aGNA16M9


Generated by Claude Code

examples/alsa_bridge.cpp implements the two-device real-clock harness from
docs/HARDWARE_TESTING.md Setup 1: a capture thread blocks on snd_pcm_readi
(paced by the input device's crystal) and feeds asrc.push(), a playback
thread feeds snd_pcm_writei from asrc.pull() (paced by the output device's
crystal). Per-second status line on stdout, optional --csv telemetry log,
optional --dump of the post-ASRC float stream for offline analysis, and
--tone <hz> to push a synthetic sine still paced by the input device's
real clock. Negotiates FLOAT_LE with S16_LE fallback, recovers from
xruns via snd_pcm_recover, clean SIGINT shutdown.

examples/CMakeLists.txt guards the new srt_alsa_bridge target behind
find_package(ALSA QUIET) so non-Linux CI configures unchanged; verified
with -DCMAKE_DISABLE_FIND_PACKAGE_ALSA=ON. Built warning-clean under the
srt_warnings flags (-Wall -Wextra -Wpedantic -Wconversion -Wshadow);
smoke-tested --help, bad-option handling, and graceful failure when no
audio device exists.

https://claude.ai/code/session_01HuAFfoeD5a5Xe5aGNA16M9
@tap tap merged commit ddd2c47 into main Jun 12, 2026
24 checks passed
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.

2 participants