You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
libobs: correct own-clock audio drift smoothly (resampler), without the #4143 steps #4182
#4143 bounds the delay of audio on its own clock from a fast sender by taking its timing again when a packet would be placed more than 70 ms after its arrival. Each such step overwrites the audio already buffered for those ~60 ms: a short skip, a click on a steady tone. At 50 ppm that is once every 23 minutes. This issue is the smooth correction: the audio keeps pace with the system clock without steps.
A stimulus run (voice, clicks, sweep, noise and a 60 s 997 Hz sine, 135 s) through the own-clock test source, sender clock 1.01 times the system clock, program audio recorded from obs_add_raw_audio_callback:
one at each step: residual -22 to -24 dBFS over about 85 ms
Proposal
Feed the gap between a packet's placement and its arrival (data->timestamp + own_clock_timing_adjust - os_time, smoothed over seconds) to the resampler as compensation, as audio_resampler_set_compensation_error already does for samples against timestamps, so the resampler takes out the extra samples a few at a time. The #4143 step stays as the bound for jumps the resampler cannot follow.
Open points:
A source in the mix's format and rate has no resampler today. It needs one when it is on its own clock (or a simple drop or insert of single samples).
Arrival jitter (network, packet size) must not drive the compensation: a smoothed estimate over several seconds, or a minimum over a window.
A slow sender: today the late-audio path places it again; the same compensation could also cover it.
Done when
The stimulus run at 1.01 (and 0.99) shows a bounded delay and no discontinuities in the sine, and the #4143 Tier 2 case still passes.
Coordinator triage: the body lists three open design points (no resampler in the mix format, jitter filtering, the slow-sender path). Its "done when" uses the stimulus run, and that tool is not in the repo yet (#4066).
I read the own-clock path on master (libobs/obs-source-audio-output.c.h, obs-source-audio-timing.c.h, media-io/audio-resampler-drift.h, and the Rust in obs_source::audio_output). Most of what the proposal needs is already in libobs, but the error in the proposal does not settle. Findings first, then the decisions and the plan.
Findings
The resampler compensation exists.audio_resampler_set_compensation_error() drives a lag-lead loop filter (after obsproject#6351): dead band 10 ms, correction clamped to ±1000 ppm, unity gain at 1/180 Hz. A source with async_compensation on gets a resampler even in the mix format (obs_source_audio_input_resampler_needed()), which passes the audio through until the error leaves the dead band. ALSA and PulseAudio inputs turn it on; an NDI source does not.
Own-clock packets are already appended without gaps. In obs_source_audio_timing_under_lock() a packet within 70 ms of next_audio_sys_ts_min is pushed back onto the buffer, whatever its timestamp. So a packet that the resampler made shorter leaves no hole.
The gap in the proposal does not settle.data->timestamp + own_clock_timing_adjust - os_time is in the sender's time. Resampling changes how many samples are buffered, not the sender's timestamps, so this gap keeps growing at the sender's drift rate, and the loop would only run into its clamp. The quantity that resampling moves is the end of the buffered audio against the arrival time: audio_ts + buffered frames / rate - os_time. A fast sender makes it grow, and a slow one makes it shrink.
One error per packet.obs-source-audio-output.c.h:181 already writes pre.drift_error to the resampler on every packet when compensation is on. For own-clock audio, the new error must replace that write, not come after it. For own-clock audio pre.drift_error is about 0 anyway, because the sender stamps its packets from its own sample count.
Decisions
Resampler in the mix format: libobs turns compensation on by itself for audio on its own clock. The output stage knows that only after process_audio() (on_video_clock). When the first own-clock packet sets own_clock_timing_set, it also sets an internal flag. That flag is ORed into the compensation argument of obs_source_audio_input_reset_needed() and _resampler_needed(), so the next packet resets the resampler once, as a pass-through. The public obs_source_async_compensation() keeps returning what the plugin set.
Jitter: the error is buffered end - arrival - baseline, measured when each packet is appended. The baseline is the first second's minimum (the start offset, like own_clock_timing_adjust), and the error uses a sliding minimum over about 1 s. That takes out packet-size and network jitter and the 21 ms mix-tick phase. The loop's 1/180 Hz bandwidth and 10 ms dead band do the rest. This needs no new filter.
The "done when" in the body cannot pass as written. 1.01 is 10,000 ppm, ten times the clamp, and the loop locks over minutes, which a real-time Tier 2 case cannot wait for. So:
Tier 1 and Tier 3 (simulated time): a model of the sender, the mix tick and the buffered-end error, driving audio_resampler_comp_step() without real time. At ±500 ppm with 100 ms packets and ±20 ms arrival jitter, the gap stays bounded under the 70 ms step threshold, it never steps, and it settles near the baseline. The same run finds the largest drift the loop holds. Rust and the C oracle give the same corrections (obs_source::audio_output carries the same placement code).
Claim bot:@vpacher, this can't be claimed yet: it needs investigation before anyone can implement it. Comment Claiming: investigation to take the research.
The plan and the decisions are in my claim comment above: PR 1 is the buffered-end error and its filter as a pure helper with the simulated-time tests; PR 2 wires it in (C and Rust) with the Tier 2 case.
Done: #4856 (PR 1, the buffered-end error and its filter, Tier 1 and Tier 3 with simulated time) and #4864 (PR 2, the wiring in C and Rust, the Tier 2 case, the features line).
Activity
vpacher commentedon Nov 13, 2026
Coordinator triage: the body lists three open design points (no resampler in the mix format, jitter filtering, the slow-sender path). Its "done when" uses the stimulus run, and that tool is not in the repo yet (#4066).
Missing:
test_async_audio_own_clock.c(bug: libobs: audio on its own clock from a fast sender plays later and later since #4049 #4143): sender clock 1.01 and 0.99, the delay stays bounded, and there is no sample discontinuity./investigate
vpacher commentedon Nov 14, 2026
Claiming: #4182
I read the own-clock path on master (
libobs/obs-source-audio-output.c.h,obs-source-audio-timing.c.h,media-io/audio-resampler-drift.h, and the Rust inobs_source::audio_output). Most of what the proposal needs is already in libobs, but the error in the proposal does not settle. Findings first, then the decisions and the plan.Findings
audio_resampler_set_compensation_error()drives a lag-lead loop filter (after obsproject#6351): dead band 10 ms, correction clamped to ±1000 ppm, unity gain at 1/180 Hz. A source withasync_compensationon gets a resampler even in the mix format (obs_source_audio_input_resampler_needed()), which passes the audio through until the error leaves the dead band. ALSA and PulseAudio inputs turn it on; an NDI source does not.obs_source_audio_timing_under_lock()a packet within 70 ms ofnext_audio_sys_ts_minis pushed back onto the buffer, whatever its timestamp. So a packet that the resampler made shorter leaves no hole.data->timestamp + own_clock_timing_adjust - os_timeis in the sender's time. Resampling changes how many samples are buffered, not the sender's timestamps, so this gap keeps growing at the sender's drift rate, and the loop would only run into its clamp. The quantity that resampling moves is the end of the buffered audio against the arrival time:audio_ts + buffered frames / rate - os_time. A fast sender makes it grow, and a slow one makes it shrink.obs-source-audio-output.c.h:181already writespre.drift_errorto the resampler on every packet when compensation is on. For own-clock audio, the new error must replace that write, not come after it. For own-clock audiopre.drift_erroris about 0 anyway, because the sender stamps its packets from its own sample count.Decisions
process_audio()(on_video_clock). When the first own-clock packet setsown_clock_timing_set, it also sets an internal flag. That flag is ORed into the compensation argument ofobs_source_audio_input_reset_needed()and_resampler_needed(), so the next packet resets the resampler once, as a pass-through. The publicobs_source_async_compensation()keeps returning what the plugin set.buffered end - arrival - baseline, measured when each packet is appended. The baseline is the first second's minimum (the start offset, likeown_clock_timing_adjust), and the error uses a sliding minimum over about 1 s. That takes out packet-size and network jitter and the 21 ms mix-tick phase. The loop's 1/180 Hz bandwidth and 10 ms dead band do the rest. This needs no new filter.Tests
The "done when" in the body cannot pass as written. 1.01 is 10,000 ppm, ten times the clamp, and the loop locks over minutes, which a real-time Tier 2 case cannot wait for. So:
audio_resampler_comp_step()without real time. At ±500 ppm with 100 ms packets and ±20 ms arrival jitter, the gap stays bounded under the 70 ms step threshold, it never steps, and it settles near the baseline. The same run finds the largest drift the loop holds. Rust and the C oracle give the same corrections (obs_source::audio_outputcarries the same placement code).timinglock). A source on the video clock gets none. The bug: libobs: audio on its own clock from a fast sender plays later and later since #4049 #4143 case at 1.10 still passes: beyond the clamp, the step stays the bound.Plan
drift_errorfor own-clock audio, the bug: libobs: audio on its own clock from a fast sender plays later and later since #4049 #4143 check on the buffered end) in C and Rust, plus the Tier 2 case and adocs/features.mdline.github-actions commentedon Nov 14, 2026
Claim bot: @vpacher, this can't be claimed yet: it needs investigation before anyone can implement it. Comment
Claiming: investigationto take the research.vpacher commentedon Nov 14, 2026
Claiming: investigation
The findings are in my comment above (the own-clock path, the existing resampler compensation, and why the proposed error does not settle).
vpacher commentedon Nov 14, 2026
/ready
The investigation is done: the design points are answered and the acceptance tests are defined in my claim comment above.
vpacher commentedon Nov 14, 2026
Claiming: #4182
The plan and the decisions are in my claim comment above: PR 1 is the buffered-end error and its filter as a pure helper with the simulated-time tests; PR 2 wires it in (C and Rust) with the Tier 2 case.
feat(obs-source): the own-clock drift error and its filter (obs-rust#…
feat(libobs): compensate the clock drift of own-clock audio (obs-rust…
vpacher commentedon Nov 23, 2026
Done: #4856 (PR 1, the buffered-end error and its filter, Tier 1 and Tier 3 with simulated time) and #4864 (PR 2, the wiring in C and Rust, the Tier 2 case, the features line).