garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/container-audio.md

raw


topic: container-audio triggers: [audio, voice, microphone, cpal, ALSA, asoundrc, snd-aloop, opus, AEC, echo cancellation, platform::audio, "fake audio device", "no sound device", "can we test audio"] updated: 2026-08-10

The agent container can build an audio stack but cannot hear one

Voice work (issue #32 and its client half) keeps raising the same question, so here is the measured answer rather than a fresh investigation each time.

What is present

Measured 2026-08-10 in cartopolis-agent:

What is absent, and cannot be added from inside

The measurement that decides how useful null is

Writing pcm.!default { type null } into ~/.asoundrc makes default open cleanly for both playback and capture at 48 kHz / S16_LE / mono. That is enough for cpal to enumerate a device and for a stream to start.

But it does not clock. A C probe (snd_pcm_set_params at 48 kHz mono, then 100 × 480-frame writes = exactly 1.000 s of audio) returned in 0.000 s of wall time, in both directions — thousands of times realtime, in a free run.

So pcm.null answers "does the code path open, negotiate a format and not panic?" and nothing else. Anything whose correctness is a function of time — jitter buffer behaviour, underrun and overrun recovery, clock drift between capture and playback, callback pacing — will pass instantly against null while proving nothing. That is worse than having no test, because it reports green.

The three tiers, and what each actually buys

TierCostBuys
pcm.null via ~/.asoundrctwo lines, no install, works todaystream opens, format negotiation, no panic. No timing.
PulseAudio module-null-sink + a virtual sourcepulseaudio in the agent image (Dockerfile change; no host change, no kernel module)properly clocked virtual devices — capture→encode→decode→playback end to end
snd-aloopmodprobe on the VPS + /dev/snd mapped in — a host kernel change, so ask firsttrue loopback: what is played on one subdevice is captured verbatim on another, so tests can assert on the samples themselves

None of the three buys acoustic echo cancellation quality. AEC is judged acoustically and a null sink has no acoustics; on web getUserMedia supplies it, on native it is ours to solve and to judge on a real machine with a real headset.

Consequence for how voice gets tested

The highest-value tests need no device at all: codec framing, sequence handling, resampling, the distance-attenuation curve, jitter-buffer bounds. These are pure functions over buffers and run here today — write them first regardless of which tier is chosen.

Done, 2026-08-16. They live in crates/cartopolis/src/systems/net/voice.rs, and one of them goes further than this note expected: voice::loopback starts a real simulator on a loopback socket and asserts that an encoded frame survives the round trip as a waveform. No device is involved at either end — the "microphone" is a generated tone and the "speaker" is the jitter ring — so it needs none of the three tiers below and still covers the join between the client codec and the server's fan-out, which is where voice was actually broken (it did not exist).

What remains device-shaped and therefore still untestable here: that a microphone opens, that Android's permission dialog appears, and that anything is audible. docs/notes/voice-chat.md states that plainly rather than letting a green suite imply otherwise.

Reach for tier 2 only when a bug is suspected at the device boundary itself, and tier 3 only when a test needs to assert on samples that made a full round trip.