Repository navigation
Conference audio in a browser: the mic and the speaker on AudioWorklets, off the main thread - #1412
Merged
Merged
Conversation
transfix
force-pushed
the
feat/conference-audio-worklet
branch
from
November 21, 2026 00:04
09e86e0 to
900a53c
Compare
transfix
added a commit
to cy-pca/cyprty
that referenced
this pull request
Nov 21, 2026
…n A/B (#4) An arigl-web from transfix/libcvc#1412 on runs the browser's mic and speaker on AudioWorklets and installs their processors as share/arigl-web/cvc-audio-worklet.js. stage.sh copies the file when the package has it. An older package has neither the file nor the code that loads it, so the file is optional; a package whose arigl.js loads it but which lacks it stages with a warning (the page falls back to the copy in arigl.wasm, from a blob: URL, after a 404). Both page configs gain url_env "audio" -> CVC_WEB_AUDIO, ^(sdl|worklet)$, so ?audio=sdl puts the mic and speaker back on SDL's ScriptProcessorNode. verify.py already checks every staged file; it now also checks that each script is served as JavaScript, since an AudioWorklet module loads only as one. ci stages two fake packages, with and without the file.
SDL 3.4.12's Web Audio backend plays and captures through a ScriptProcessorNode in 43 ms blocks, and its callback runs on the main thread between arigl's frames. A long frame plays a gap and loses capture. In a hidden tab the mic is not captured at all, and the speaker barely plays. - cvcMedia's web_audio (cvc/media/web_audio.h) has two AudioWorklet processors (src/cvcMedia/web/cvc-audio-worklet.js). cvc-capture posts the mic in 20 ms blocks. cvc-playback plays a ring the main thread keeps filled. They hold no wasm and share no memory with it: every block goes over a MessagePort, so the single-threaded build and a page without COOP/COEP both work. - Each block's message ticks an audio clock. The conference sends the mic and fills the jitter buffers there (ConferenceSession::audio_tick), not only once a frame. The browser delivers those messages between frames, and at full rate in a hidden tab. - Capture: a FIFO frame_source. Each block wakes the stream's producer at once (frame_source::set_ready_callback, producer_thread::run_now), where it used to wait for a timer that a hidden tab slows to 1 Hz. - Playback: the ring stays 60 ms ahead of the speaker. When it runs dry it grows by the silence played and a block, up to 400 ms. After 10 s without that it shrinks a block, cross-faded. The jitter buffers stay in voice_mixer. A/V sync counts what the ring holds. - SDL is the fallback: no AudioWorklet, not a secure context, a rate other than the context's 48 kHz, more than two channels, a device other than the default, push-mode outputs, or CVC_WEB_AUDIO=sdl. A device opened while the worklets load gets its node once they have loaded. - The page loads cvc-audio-worklet.js from beside itself (arigl-web and ariglx-web ship it), else the copy compiled in, from a blob: URL. - Tests: cvc_audio_worklet_test.js (the processors in node, in run-js-tests.sh) and arigl_web_audio.mjs (a local arisrv and two headless Chromes with fake media: a 440 Hz tone sent, the receiver's playback recorded and checked for gaps and clicks; idle, busy main threads, sender hidden, receiver hidden; worklet against ?audio=sdl).
transfix
force-pushed
the
feat/conference-audio-worklet
branch
from
November 21, 2026 05:46
900a53c to
0f9bb25
Compare
transfix
enabled auto-merge (squash)
November 21, 2026 05:57
This was referenced Nov 21, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Browser audio for the conference client, off the main thread. This is the follow-up #1398 named (roadmap §5j, "Browser audio off the main thread").
Why
SDL 3.4.12's Web Audio backend plays and captures through a ScriptProcessorNode, in 43 ms blocks, and its callback runs on the main thread between arigl's frames. A long frame plays a gap and loses capture. In a hidden tab it is worse: measured below, a hidden sender sends nothing, and a hidden receiver hears 13-19% of the audio.
What
src/cvcMedia/web/cvc-audio-worklet.js).cvc-captureposts the mic in 20 ms blocks.cvc-playbackplays from a ring that the main thread keeps filled.web_audio::audio_clock). Each block's message is a tick. On each one the conference sends the mic and fills the jitter buffers (ConferenceSession::audio_tick), so neither waits for a frame. The browser delivers those messages between frames, and at full rate in a hidden tab.frame_source, behindopen_audio_capture. Each block wakes the stream's producer at once (frame_source::set_ready_callback,producer_thread::run_now), where it used to wait for a timer that a hidden tab slows to 1 Hz.open_audio_output_pull. The ring stays 60 ms ahead of the speaker. When it runs dry it grows by the silence it played and a block, up to 400 ms. After 10 s without running dry it shrinks a block, cross-faded. The jitter buffers stay invoice_mixer, and A/V sync counts what the ring holds.CVC_WEB_AUDIO=sdlforces it for an A/B. A device opened while the worklets load gets its node once they have loaded.cvc-audio-worklet.jsfrom beside itself (arigl-web and ariglx-web now ship it), else the copy compiled in, from ablob:URL. A page with a strict CSP needs the file.docs/roadmap/ARIADNE_CONFERENCE_ROADMAP.md§5j.Tests
src/cvcMedia/test/cvc_audio_worklet_test.jstests the processors in node: blocks, the ring, ticks, running dry, the cross-faded drop, and overflow. It runs fromrun-js-tests.shin the "cvcGL wasm JS tests" job.src/arigl/web/test/arigl_web_audio.mjsruns a local arisrv and two headless Chromes with fake media. The sender's mic is a steady 440 Hz tone (voice processing off for the test). The receiver's playback is recorded on its own audio thread and checked for how much of the time the tone is heard, for gaps, and for clicks. It runs four cases in both modes. It is not in CI yet: it needs a native arisrv. To run it:node src/arigl/web/test/arigl_web_audio.mjs --web <share/arigl-web> --doc examples/ariadne/documents/conference_roster.ari --arisrv <arisrv> --chrome <chrome> [--gpu] [--expect]Measured locally (headless Chrome 152, 30 s a case, on this branch before its rebase onto master, which changed nothing in these files). On the GPU, where frames are short:
?audio=sdl)In SwiftShader each frame is a long task of about 100 ms. There the worklets kept the tone 97.9-99.3% of the time. SDL kept it 89.9% busy, 0% with the sender hidden, and 18.7% with the receiver hidden, with hundreds of clicks. What the worklets still lose comes in the first seconds, while the ring and the jitter buffers grow.
voice_mixergrows 20 ms per late underrun, which took 9 against a stalling sender. That is a follow-up.The existing
arigl_web_smoke.mjspasses 14/14 against the new package. The worklets also load under its strict CSP, and fromblob:when the page lacks the file.Not verified
stage.shcopies a fixed file list withoutcvc-audio-worklet.js, so a cyprty built from this would load the compiled-in copy, which works there (no CSP).ConferenceSession. Whichever merges second needs a rebase.