Repository navigation
voice_mixer: a late underrun grows the target by how late the audio was - #1416
Merged
Merged
Conversation
A late underrun grew a peer's jitter-buffer target a fixed 20 ms, so a sender whose main thread stalls 150 ms took a gap per step to catch up (9 late underruns, 80 to 260 ms, in headless Chrome). Now it grows by how late the audio was to the device: the audio the device asked for from running dry to the audio's return and did not get, at least a step, rounded up to whole steps, capped at max_delay_s. For a device pulling at its own pace that is the time since; a receiver whose own main thread stalled pulls a stall's worth at once after it, or nothing during it, and the time alone reads those wrong (measured in headless Chrome under SwiftShader: 90 ms by the clock against 1 ms short, and 3 ms against 56). After a late underrun the voice plays again once what it waited for before is buffered, not the grown target. The audio that comes back brings the delay the stall needed; waiting for the rest was a gap of its own (up to 580 ms in one, in headless Chrome). The grown target keeps that audio from being trimmed, and the next talk spurt starts at it. A voice that runs dry on quiet audio (below quiet_rms, 0.008) is not late: a conference sender sends nothing through a silence after 0.8 s of its mic below 0.004, and the next talk spurt can come within late_window_s. Counted late, a pause grew the target 20 ms, and by its length would take it to the most. Relaxing stays one step per relax_after_s, so a stall that recurs still finds the buffer big enough; the delay a one-off stall added lingers longer. The tests: OnlyLateUnderrunsGrowTheTarget expects three steps for a device that went 60 ms short; new tests for one large late arrival, a device that pulls a stall's worth at once, one that pulled nothing while dry, a late voice playing again at its old target, whole steps up to max_delay_s, a pause in speech, and two minutes of speech sent with the uplink's silence rule; the simulation gains sender and receiver main-thread stalls, and a test where both stall.
transfix
enabled auto-merge (squash)
November 21, 2026 05:16
This was referenced Nov 21, 2026
Merged
transfix
added a commit
that referenced
this pull request
Nov 21, 2026
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.
What this changes
cvc::voice_mixer(inc/cvc/media/voice_mixer.h,src/cvc/media/voice_mixer.cpp): a late underrun used to grow a peer's jitter-buffer target by a fixed 20 ms. A sender whose main thread stalls 150 ms therefore got one audible gap per step while the target caught up: in #1412's headless-Chrome busy case that was 9 late underruns, from 80 to 260 ms.Now a late underrun grows the target by how late the audio was, as the device saw it. The proposal in the workstream was
max(step_s, now - underrun_at)rounded up to a step. This PR differs from it in three ways, each for a reason I measured:In detail:
The growth is
max(short_by, step_s), rounded up to wholestep_ssteps and capped atmax_delay_s.short_bycounts the samples the device asked for and didn't get, from the dry pull until the audio came back.step_s = 0still turns growth off.Why not
now - underrun_at. A device that pulls at its own pace (SDL's audio thread, natively) asks for audio continuously, so there the shortfall equals the time since running dry. A browser is different: its main thread pulls for the AudioWorklet ring (Conference audio in a browser: the mic and the speaker on AudioWorklets, off the main thread #1412), on each ticktarget - ahead. When that main thread stalls, it pulls a stall's worth at once afterwards, or nothing during the stall, and the clock misreads both. I added a temporary log line in headless Chrome under SwiftShader, and the clock and the shortfall disagreed both ways:In a first browser run, using
max(time, shortfall), the clock's overestimates grew targets to 300-400 ms under SwiftShader.After a late underrun the voice plays again once its old target is buffered, not the grown one (new
peer::restart_s). The audio that comes back brings the delay the stall needed with it, so waiting for the rest is a gap of its own: with the shortfall alone, a second browser run had single gaps of 580 and 235 ms under SwiftShader busy. The grown target still keeps that audio from being trimmed away, and the next talk spurt starts at it. Master's 9-step ramp came from exactly that trimming: a stall's burst larger than twice the target was cut back to the target.A voice that runs dry on quiet audio is not late (new
params::quiet_rms, 0.008, against a 20 ms average of the peer's played level). Growth by lateness needs this. The uplink (forward_frame, the same in Conference audio: a native client's audio is off the frame loop #1408 and Conference audio in a browser: the mic and the speaker on AudioWorklets, off the main thread #1412) sends a mic chunk while its RMS is above 0.004 or within 0.8 s of one that was, then sends nothing. So a quiet stretch of 0.8 + x s reaches the receiver as a gap of x, and any x up to 300 ms (late_window_s) used to count as a late underrun. Master grew the target 20 ms for each such pause. Growing by lateness would have grown it by the whole pause.Relaxing: kept at one step per
relax_after_sI compared three ways back down: one step per 10 s (as now), undoing the last jump after 10 s, and shrinking to the buffer's low-water mark. Simulated with 20 ms blocks and a 20 ms device and the final growth rule; dry spells, silence and mean buffered audio, mean of 5 seeds:
The latency trade-off. A jump sized to the stall means the buffer holds that much more audio until it relaxes. After a one-off 250 ms stall, the target goes from 80 to 240 ms and comes back at 20 ms per 10 s: 220, 180, 140, 80 and 40 ms at 20, 40, 60, 90 and 120 s. Relaxing faster gives that latency back within 10 s, but every stall that comes back after the probe is another full gap: in the recurring cases above, undoing the jump ran dry 1.6-3.0 times as often as relaxing a step at a time. Stalls that size do come back in practice (slow frames, GC, a busy tab), so I kept the slow relax. The cap stays at
max_delay_s(400 ms).Pauses in speech
A simulated speaker (talk U(0.5, 3) s, pauses lognormal with a 0.6 s median), sent with the uplink's silence rule over a clean link; 5 minutes, mean of 8:
With 150 ms sender stalls during speech that has quiet dips between words: master had 26.6 late underruns and a 279 ms mean target; this PR has 9.0 and 296 ms.
Tests
src/cvc/tests/voice_mixer_test.cpp: 20 tests, all passing natively.OnlyLateUnderrunsGrowTheTarget: the audio comes back 50 ms late, with the device 60 ms short, and the target now grows three steps (0.04 to 0.10 s); it was one step (0.06).OneLargeLateArrival: a 200 ms sender stall gives one late underrun and a 0.22 s target, and the next stall like it plays through.ADeviceThatPullsAStallAtOnce.TimeTheDeviceDidNotPullIsNotLate.ALateVoicePlaysOnceItsOldTargetIsBack.LateGrowthIsWholeStepsUpToTheMost.APauseInSpeechIsNotLate.PausesInSpeechDoNotGrowTheTarget: 2 minutes of speech under the uplink's silence rule.StallingMainThreadsGrowTheTargetAtOnce. For this one,simulate()now models sender and receiver main-thread stalls.max(time, shortfall), without the quiet check or the restart, fails 4. This PR without the restart fails 1.Browser measurement (
src/arigl/web/test/arigl_web_audio.mjs)Headless Chrome 152 on prettyhatemachine, worklet mode, 30 s a case. I built #1412's head (09e86e0) twice: "before" as it is, and "after" with this commit applied. The two builds alternated, with the order flipped on trial 2, over 3 trials (2026-11-20, 19:32-20:06, 1-minute load 3-15). I ran it with
--gpu(ANGLE on the GTX 1650) and without (SwiftShader, where each arigl frame is a ~100 ms long task). Each cell lists the three trials:Latency. The test measures no mouth-to-ear delay. What I report is the receiver's own log: the jitter buffer's target at its last 10 s line, and what the playback ring plays ahead.
Caveats.
Run-to-run spread is large. Over today's seven "before" runs of busy SwiftShader, heard ranged from 95.3% to 99.8%. Three trials cannot resolve differences under about half a percent; on the GPU, where everything is at 99.3-100%, the change is within that noise.
Two earlier versions of this change ran the same matrix with 2 trials each; their logs are not in the repo:
max(time, shortfall)without the restart: SwiftShader targets reached 300-400 ms, and single gaps reached 300 ms.Those two runs led to the shortfall-only rule and the restart at the old target.
Not verified: real mics and ears, other browsers, and the native client's end to end with this change. Its unit tests and simulations cover it, with SDL's pull pace, where the shortfall equals the time.
Docs
docs/roadmap/ARIADNE_CONFERENCE_ROADMAP.md§5j: the "Jitter buffers" bullet, rewritten for the new rule.The "Measured" bullet under "Browser audio off the main thread" comes with #1412, so it is not on master yet. It ends by saying that growing the target by how late the audio was "would take one or two" late underruns. Once #1412 lands, I'll rebase this branch, replace that sentence with the measurement above, and resolve any §5j conflict.
Merge order
This should merge after #1412. The code doesn't depend on it, since it touches only
voice_mixer.{h,cpp}, its test and the roadmap. But the measurement is against #1412's AudioWorklet path, and the "Measured" edit above needs #1412's text. #1408 doesn't touch these files either.