Skip to content

rust: Port the source audio input steps in obs-source.c to obs-source #1994

Closed

Description

@rdoupe

Unit

Port the audio input decisions in libobs/obs-source.c.h to rust/obs-source, as a new module audio_input:

  • in process_audio:
  • in reset_resampler: the "no resampler needed" rule from the clock drift fix;
  • process_audio_balancing (the sine, square and linear laws over two planes) and downmix_to_mono_planar.

These stay C:

  • the computation of next_resample_in_ts, which C stores and passes in;
  • the resampler calls, copy_audio_data and its allocation;
  • audio_resampler_set_compensation_error and the drift filter. Rust only reads the compensation flag.

Plan (one PR, separate commits)

  1. Behaviour-neutral move into libobs/obs-source-audio-input.c.h, as hidden functions. The loops take plain float ** and counts. process_audio keeps its order.

  2. Characterization in test_source_audio_input_steps:

    • the discontinuity at the threshold −1, equal and +1, in both directions, and with a zero start;
    • each reset trigger on its own;
    • the balance gate at 0.49, 0.50, 0.51 and just outside, NaN, and out-of-range balances;
    • each law on known samples, bit-exact, and an unknown law;
    • mono with 2, 6 and 8 channels, and 0 frames.

    Plus one real-libobs case for the balance and mono gates, read back through an audio capture callback.

  3. RED, then GREEN: the safe Rust core plus shims, in a libobs.ported-source-audio-input group. Exported symbols are unchanged. If libm sinf and Rust's f32::sin differ by an ulp on any platform, C computes the two gains and Rust ports only the loop.

  4. Tier 3 parity against the original C, plus a deliberate-break check and port_comparison numbers:

    • exhaustive over the gate flags;
    • full-range timestamps;
    • bit-equal f32 planes for random samples and balances.

These real-libobs tests must stay green on every lane: test_audio_restart_resampler_tail, test_audio_clock_drift, test_media_sync_offset_restart and test_async_delay_audio.

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions