Repository navigation
Description
Unit
The arithmetic of the audio tick in libobs/obs-audio.c.h (746 lines), into rust/obs-core as obs_core::audio_mix. Unit 10 of #1846, slice 1. It moves first to libobs/obs-audio-mix.c.h.
convert_time_to_frames: ns to frames at the sample rate (util_mul_div64).mix_audio, the part that does not read the source: the start point and the frame count of a source's audio in the tick window (ts_info), the early returns (audio outside the window, start point equal toAUDIO_OUTPUT_FRAMES), and the add loop overMAX_AUDIO_MIXESmixes and the channels.set_fixed_audio_bufferingandadd_audio_buffering, the arithmetic: the number of ticks to add (rounded up from the frame offset, capped atmax_buffering_ticks), the new totals, the millisecond values for the log lines, and the sequence ofts_infovalues that go to the front ofbuffered_timestamps.
These stay C in obs-audio.c.h: the source tree walk (push_audio_tree*), audio_callback, the locks, ignore_audio, discard_if_stopped, discard_audio, the min-timestamp search, the monitoring checks, the blog lines and the deque calls. The C passes the values in and takes the results back.
Correction to the meta: obs-audio.c.h does not clamp. Clamping happens in media-io/audio-io, after the mix.
Phase and position
Phase 6 (#444), first slice of a large file, as the meta says for unit 10. Crate obs-core (it exists; video_plan from #1713 has the same "C gives the values, Rust computes" shape). The precedent for an extracted libobs core helper is #1814 / #1842 (obs-scene-audio-actions.c.h): helpers declared in a header without EXPORT, hidden shims, and a test that compiles the C core into itself for Tier 3.
Seam: none needed
The extracted functions take plain values (timestamps, sample rate, channel count, float pointers, and the four buffering fields of struct obs_core_audio: buffered_ts, buffering_wait_ticks, total_buffering_ticks, max_buffering_ticks). The C reads source->audio_ts and source->audio_output_buf and passes them. No obs-internal.h layout goes to Rust, and no public header changes.
audio_frames_to_ns and ns_to_audio_frames are already in obs-media-io::audio_io.
Existing tests
test_audio_buffering_subsample(Flaky: real-time audio cmocka tests lose audio under machine load (test_vlc_playlist_gap, test_group_hide_transition_audio) #838) compileslibobs/obs-audio.c.hinto itself. It tests the C buffering, not the swap, and says so. After the extraction it also needsobs-audio-mix.c.h: one#includeline in the extraction commit, no change to its cases.test_audio_clock_drift,test_audio_sync_offset_changeandtest_audio_capture_mix_racerun the real mixer throughOBS::libobs. They see the swap and are the Tier 2 for this slice.- No test pins the mix window edges. New cases go into
test_audio_buffering_subsample(no new executable): audio before and at the window start, at and after the window end, a start point that rounds toAUDIO_OUTPUT_FRAMES, and a partial window. Also the buffering edge cases: a sub-sample offset (no ticks), an offset that reaches the cap ("Max audio buffering reached!"), and fixed buffering when it is already at the maximum.
Plan
One PR, in this order:
- Extraction commit, behaviour-neutral, no Rust: move the arithmetic into
libobs/obs-audio-mix.c.hwith plain-value signatures, declared inlibobs/obs-audio-mix.hwithoutEXPORT, included fromlibobs/build/libobs.core-output+.h.c. The callers inobs-audio.c.hpass the fields. The unchanged C tests pass. - Characterization commit: the new cases above, against the C reference and the hybrid libobs.
- RED: the safe core in
obs-corewithtodo!(), Tier 1 tests inobs-tests-core(the cmocka cases 1:1, plus window and tick properties), failing. - GREEN: the core, a thin hidden
#[no_mangle]shim, the include moved to alibobs.ported-audio-mixgroup inlibobs/build/source-sets.json, Tier 3 proptest againstrust/obs-c-oracle/legacy/(the extracted C), andport_comparisonnumbers for the add loop and the buffering step. - Tier 2: the real-mixer tests above with Rust off and on. Tier 4: n/a.
The add loop runs on every audio tick for every root source, mix and channel. Besides port_comparison, I measure it on a real OBS host (CT104, NDI/ALSA audio) before and after, and put the numbers in the PR.
Next slices (filed here when this one closes)
ignore_audio, discard_if_stopped and discard_audio (the deque arithmetic over audio_input_buf), then the min-timestamp search. They read more source fields, so each needs its own check for a seam.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Oct 23, 2026
Claiming: #1903 (#1846 unit 10, slice 1, the audio mix and buffering math in
obs-audio.c.h). First PR: the extraction and characterization commits, then RED and GREEN in the same PR, as in the plan above.libobs: Move the audio tick arithmetic into obs-audio-mix.c (obs-rust…
obs-core: Port the audio tick arithmetic (obs-rust#1903) (obs-rust#1909)
zackees commentedon Oct 25, 2026
Closing as done. Both steps of the plan merged: #1905 moved the audio tick arithmetic into
libobs/obs-audio-mix.c.hwith characterization, and #1909 ported it toobs_core::audio_mixbehind the seam with Tier 1 and Tier 3 tests (mutation check: 20 of 21 killed, and the survivor is equivalent). #1909 usedRefs, so this didn't close by itself. The next slices of #1846 unit 10 go in their own issues. Thanks @vpacher.obs-core: Port the per-source decisions of the audio render step (obs…
perf(bench): Record the SIMD candidates and repair the benchmark reco…