Skip to content

rust: Port scene audio mix kernels #3079

Closed

Description

@vpacher

Unit

libobs/obs-scene.c.h: the two mix kernels of scene_audio_render(), which add each audible scene item's audio into the scene's mixes every audio tick:

  • mix_audio_with_buf(): out[pos + i] += in[i] * buf[i], for an item whose visibility change falls in the tick (the 0/1 gain buffer of apply_scene_item_volume());
  • scene_mix_audio(): out[pos + i] += in[i], for every other item.

They move to libobs/obs-scene-audio-mix.c.h and are ported to rust/obs-scene (module audio_mix, next to audio_window and audio_actions).

Phase and position

Phase 2 libobs core, scenes (core-scene group). This is the scene half of #3007 under #3009. The decisions around these kernels are already ported: obs-scene-audio-window.c.h (the window and whether an item mixes) and obs-scene-audio-actions.c.h (the gain buffer). The source volume kernels are a separate issue. Tracking: #4.

Dependencies and existing tests

  • Depends on nothing open.
  • Existing test that runs the kernels through the real libobs: test_scene_audio_actions (the visibility ramp, sample by sample, over a second audible item).
  • No characterization of the kernels on their own yet. test_scene_audio_mix_steps (cmocka, the moved file on its own) lands first. It pins:
    • both kernels at pos 0 and inside the tick, count 0, 1 and 1024;
    • the gain buffer at 0, 1 and other values;
    • NaN, infinities and -0.0 in each operand;
    • output samples outside pos .. pos + count left alone.

Notes

  • perf: libobs: vectorize scene audio mixing and source volume multiply when ported #3007 applies:
    • a benchmark under audio_mix in port_comparison first, with before and after numbers on a named x86_64 and a named aarch64 machine;
    • an assembly check that the kernels vectorize;
    • a scalar fallback;
    • bit-exact Tier 3.
  • Vectorization: GCC 14 at -O2 (the Linux builds) leaves both loops scalar, because it cannot rule out that out and in overlap. Clang vectorizes them. Rust slices cannot overlap, so plain Rust loops should vectorize with no std::arch.
  • Fused multiply-add: on aarch64, clang's default -ffp-contract=on fuses out += in * buf into one fmla, and GCC does the same for x86-64-v3. The C oracle is pinned to -ffp-contract=off (rust/obs-c-oracle/build.rs), as for every port, so the port keeps a separate multiply and add. It matches the oracle bit for bit; the shipped aarch64 C can differ in the last bit.
  • scene_audio_render() keeps the item loop, the mix and channel loops, obs_source_get_audio_mix(), the locks and every read of the item and source. Only the two kernels move, as functions on plain pointers and counts, hidden in libobs.

Activity

  1. vpacher commented on Oct 30, 2026

    @vpacher
    MemberAuthor

    Claiming: #3079.

    Plan (one PR, in this order):

    1. Behaviour-neutral extraction: mix_audio_with_buf() and scene_mix_audio() move to libobs/obs-scene-audio-mix.c.h as hidden functions on plain pointers and counts; scene_audio_render() keeps everything else in its order.
    2. Characterization: test_scene_audio_mix_steps (cmocka, the moved file on its own), with the cases listed in the issue.
    3. RED: rust/obs-scene module audio_mix with stubs and Tier 1 tests.
    4. GREEN: the port, swapped into the hybrid libobs, plus the audio_mix benchmark against the C and the assembly check (perf: libobs: vectorize scene audio mixing and source volume multiply when ported #3007).
    5. Tier 3 parity against the oracle build of the moved file, bit for bit.

    Draft PR within 48 h.

  2. added
    ready
    on Oct 30, 2026
  3. moved this from In merge queue to Done in obs-rust Multiviewon Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions