Repository navigation
rust: Port media-io/audio-math.h to obs-media-io - #179
Merged
Merged
Conversation
Pins mul_to_db and db_to_mul from media-io/audio-math.h before the Rust port. log10f and powf come from the platform libm, and glibc, the UCRT and libSystem can differ in the last bit, so only results every libm gets exactly are compared exactly: 0 and -0 -> -inf, 1 -> 0 and +inf -> +inf for mul_to_db; 0 -> 1, non-finite input -> 0 (+inf included), and finite input past float range -> inf or 0 for db_to_mul. A negative multiplier or NaN gives NaN. Everything else, including the float extremes, is compared with a relative tolerance of about 8 ULPs. Characterized, not endorsed. The header calls log10f/powf, so the test links libm outside MSVC, like the graphics math tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 1 and Tier 3 tests for mul_to_db and db_to_mul against todo!() cores in obs_media_io::audio_math. audio-math.h is header-inline and defines no struct, so there is no shim, no layout test and no symbol swap; Tier 2 is the unchanged characterization test passing OFF/ON. The oracle wraps the header in non-inline oracle_mul_to_db and oracle_db_to_mul (oracle/audio_math.c, bindings in src/audio_math.rs). Tier 1 ports test_audio_math.c case for case, with its exact cases and relative tolerance, and adds the sign of the exact zero results, NaNs of either sign and any payload giving 0 from db_to_mul, and the largest in-range dB values. The C is scalar, so per the Phase 5 rule parity is exact bit equality (any NaN equals any NaN), with no ULP tolerance: both sides call the same platform log10f/powf. It covers special values (zeros, infinities, NaNs, subnormals, the float extremes, the cmocka values, each with both signs), every 4096th bit pattern, and proptest over arbitrary bits and the audio range (multipliers 0..4, -200..40 dB). Co-Authored-By: Claude Opus 5.5 <[email protected]>
mul_to_db and db_to_mul get Rust equivalents in obs_media_io::audio_math, for Rust ports of the audio code that converts between faders and gain. The header is static inline, so nothing is swapped or exported. No intentional differences. The cores are the header's expressions: -inf for a zero multiplier, else 20 * log10(mul); 10^(db / 20) via powf for finite dB, else 0. f32::log10 and f32::powf lower to the platform log10f/powf, the same calls the C makes, so parity is bit-exact on each platform, also in release builds (no pow(10, x) -> exp10 rewrite on either side). Mutation check: computing powf as exp(x * ln 10) or log10 as ln(x) / ln 10 fails every parity test; keeping +inf dB (checking !is_nan instead of is_finite) fails the special-value and bit-pattern sweeps. Making the zero check sign-sensitive passes, as expected: log10f(-0) is -inf as well, so that mutant is equivalent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=3900f919177dac1fb933c78a8e8e1d7b400e92ae secs=164 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791680975,"gate":"rust/all/fmt","host":"linux-x86_64","key":"5987b139be6f71709ce8b1e5468e0beaadfcd29d1efcd0fa45a0c90dfb1b3310","lane":"lint","parents":["6d23f0ccfa214ad6144f0b4da6b7187c329dbf33"],"secs":54,"stamp":"856dffc539a0d984d0c682c8eb4289f8","tree":"3900f919177dac1fb933c78a8e8e1d7b400e92ae","v":1,"via":"run"} Ci-Attestation: {"at":1791680975,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"5987b139be6f71709ce8b1e5468e0beaadfcd29d1efcd0fa45a0c90dfb1b3310","lane":"lint","parents":["6d23f0ccfa214ad6144f0b4da6b7187c329dbf33"],"secs":54,"stamp":"102162225499cd7dd23d4d6b3bcd3b61","tree":"3900f919177dac1fb933c78a8e8e1d7b400e92ae","v":1,"via":"run"} Ci-Attestation: {"at":1791680975,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"72aa51d98402d5ac64565e50f9ada5e540cc12f73963586798e351cd46ba9145","lane":"rust-test","parents":["6d23f0ccfa214ad6144f0b4da6b7187c329dbf33"],"secs":46,"stamp":"e90f0df1f369bed465076d970be04f55","tree":"3900f919177dac1fb933c78a8e8e1d7b400e92ae","v":1,"via":"run"} Ci-Attestation: {"at":1791680975,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"0e9dd62c5b41dfeb23ffdb9f275282bb2ffe294e7c4cf05331c0db242a684c87","lane":"tier2-linux","parents":["6d23f0ccfa214ad6144f0b4da6b7187c329dbf33"],"secs":63,"stamp":"c9c4908a0161afcf39f97745686f17eb","tree":"3900f919177dac1fb933c78a8e8e1d7b400e92ae","v":1,"via":"run"}
Member
|
Verified (soldr cache disabled) and rebased onto current master with no conflicts (old head 4e0a6c0, replaced with --force-with-lease). Thanks for using the new per-unit layout: a
The local gate passes and is stamped. I'll merge once CI is green. |
zackees
force-pushed
the
port/audio-math
branch
from
October 11, 2026 01:09
4e0a6c0 to
d3e9f96
Compare
10 of 22 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #45
What and why
Ports
mul_to_dbanddb_to_mulfromlibobs/media-io/audio-math.htoobs-media-io(obs_media_io::audio_math). This is item 4 of the media-io part 2 order on #45 (#45 (comment)), kept separate from #129. No intentional differences.Header-inline exemption. Both functions are
static inline, so nothing is swapped or exported. There is noENABLE_RUST_LIBOBSguard and norust-exports.dfragment, and the header is unmodified. The header defines no struct, so Tier 2 is just the unchanged cmocka test passing OFF and ON. Tier 1 and Tier 3 run against the non-inlineoracle_mul_to_db/oracle_db_to_mulwrappers (oracle/audio_math.c, bindings insrc/audio_math.rs).Exactness, as set on #45.
db_to_mul(0)→ 1, non-finite dB → 0, out-of-range dB → inf or 0, negative or NaN multiplier → NaN). Everything else uses a relative tolerance of about 8 ULPs, because glibc, UCRT and libSystem differ in the last bit.log10f/powf. The core keeps10.0f32.powf(db / 20.0)as written.pow(10, x)→exp10: Apple clang rewrites the oracle'spowf(10, x)into__exp10fat -O1 and above. In release builds the C side therefore calls__exp10fwhile Rust callspowf. libSystem'spowf(10, x)and__exp10f(x)agree bit for bit (checked over all 2,166,358,017 floats with x in [-10, 2], i.e. -200..+40 dB), and parity passes in debug and release on macOS. On Linux and with MSVC, parity passes in both profiles as well.RED → GREEN
3ed35cb31addstest/cmocka/test_audio_math.cand registers it astests.d/test_audio_math.cmake(links libm outside MSVC, like the graphics math tests). It passes OFF and ON before any Rust.54a7c41ca. Against thetodo!()cores,audio_mathfails 10/10 andaudio_math_parityfails 4/4. Checked with soldr's cache disabled and a fresh target dir.4e0a6c051.audio_math10/10 andaudio_math_parity4/4 pass. Tier 2 Linux: 51/51 with ENABLE_RUST_LIBOBS OFF and ON,test_audio_mathincluded, and libobs exports are identical (1752 symbols).How has this been tested?
tests/audio_math.rs: portstest_audio_math.ccase for case, with the same exact cases and tolerance. Edge cases: the exact zero results are +0, NaNs of either sign and any payload give 0 fromdb_to_mul, and the largest in-range dB values.tests/audio_math_parity.rs: special values (zeros, infinities, NaNs, subnormals, the float extremes, the cmocka values, each with both signs), every 4096th bit pattern (about 1M floats), and proptest (20,000 cases each) over arbitrary bits and the audio range (multipliers 0..4, -200..40 dB).powfasexp(x * ln 10), orlog10asln(x) / ln 10, fails every parity test. Treating +inf dB as finite (checking!is_naninstead ofis_finite) fails the special-value and bit-pattern sweeps. Making the zero check sign-sensitive is an equivalent mutant, sincelog10f(-0)is -inf too../lint,./unittest, and the stamped head. Parity also passes with--release.audio_math10/10,audio_math_parity4/4. The oracle there is built with clang-cl, and cmocka Tier 2 wasn't run locally.rust/tools/tier2-validate/validate.shpasses OFF and ON with identical exports (1863 symbols).Checklist
master🤖 Generated with Claude Code