Skip to content

rust: Port source volume multiply kernels #3080

Closed

Description

@vpacher

Unit

libobs/obs-source.c.h: the two volume kernels that scale a source's audio every audio tick, once per mix the source is in:

  • multiply_output_audio(): out[i] *= vol over AUDIO_OUTPUT_FRAMES * channels samples from audio_output_buf[mix][0], from apply_audio_volume();
  • multiply_vol_data(): out[i] *= vol_data[i] for each channel, from apply_audio_actions() when a volume, mute or push-to-talk action falls inside the tick.

They move to libobs/obs-source-volume-mul.c.h and are ported to rust/obs-source (module volume_mul, next to volume_apply and audio_place).

Phase and position

Phase 2 libobs core, sources (core-source group). This is the source half of #3007 under #3009. The decisions around these kernels are already ported: obs-source-volume.c.h (skip, clear or multiply, and which mixes) and obs-source-audio-place.c.h (each action's frame and the fill of vol_data). The scene mix kernels are a separate issue. Tracking: #4.

Dependencies and existing tests

  • Depends on nothing open.
  • Existing tests that run the kernels through the real libobs: test_source_volume_mix (the volume as the mix applies it, out-of-range volumes included) and test_source_volume_apply_steps.
  • No characterization of the kernels on their own yet. test_source_volume_mul_steps (cmocka, the moved file on its own) lands first. It pins:
    • both kernels for 1, 2 and 8 channels;
    • volumes 0, 1, 0.5 and 20;
    • a vol_data ramp across the tick;
    • NaN, infinities and -0.0;
    • other mixes left alone.

Notes

  • perf: libobs: vectorize scene audio mixing and source volume multiply when ported #3007 applies:
    • a benchmark under audio_mix 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 (multiplies only, so there is no fused multiply-add question).
  • Vectorization: GCC 14 at -O2 (the Linux builds) leaves both loops scalar; clang vectorizes them.
  • Channel layout (characterized, not endorsed): multiply_output_audio() treats a mix's channel buffers as one block from channel 0. That holds because allocate_audio_output_buffer() makes one allocation for all mixes, and each mix's audio_output_buf[mix][ch] are consecutive blocks of AUDIO_OUTPUT_FRAMES in channel order. The C function on plain pointers keeps that block; the characterization pins it.
  • apply_audio_volume() and apply_audio_actions() keep the action queue and its mutex, get_source_volume(), the vol_data fill, the memset and the mix loop. 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: #3080.

    Plan (one PR, in this order):

    1. Behaviour-neutral extraction: multiply_output_audio() and multiply_vol_data() move to libobs/obs-source-volume-mul.c.h as hidden functions on plain pointers and counts; apply_audio_volume() and apply_audio_actions() keep everything else in its order.
    2. Characterization: test_source_volume_mul_steps (cmocka, the moved file on its own), with the cases listed in the issue.
    3. RED: rust/obs-source module volume_mul 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
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