feat(producer): add Rio-style residual-RMS check to regression harness
What
Adds Rio-style residual-RMS audio equivalence check to the producer regression harness. The existing envelope-correlation gate stays in place; the new check is a complementary, sample-level test of "does the rendered audio actually match the snapshot, bit-by-bit after resampling".
Why
Surfaced while validating real-AWS Lambda renders (Phase 6 stack). The existing audio comparison uses Pearson correlation over RMS envelopes (2048-sample windows). That measures shape similarity but is insensitive to level shifts, phase drift, and codec-quantization noise. Two streams with correlation > 0.95 can still differ audibly.
Rio's audio check (rio/tests/checksum.py::compare_audio_files_ffmpeg)
is sample-level instead: subtract one stream from the other via ffmpeg
amix, run astats, read the residual Overall RMS in dBFS. Identical
streams cancel to silence:
ffmpeg ... -filter_complex \
"[0:a]aresample=48000,pan=stereo|c0=c0|c1=c1[a0];
[1:a]aresample=48000,pan=stereo|c0=c0|c1=c1,volume=-1[a1];
[a0][a1]amix=inputs=2:duration=shortest,astats[out]" \
-map "[out]" -f null -
Verified on the Lambda render of many-cuts (a 5.6s composition with 4
audio elements): residual RMS = -90.36 dBFS vs the in-process
baseline. Well below Rio's -50 dBFS pass threshold.
How
Three changes:
-
packages/producer/src/utils/audioRegression.ts— newcomputeAudioResidualRmsDb(rendered, snapshot, maxResidualRmsDb=-50)that spawnsffmpegwith Rio's filter graph, parses theOverall RMS level(or per-channel max as fallback), and returns{ overallDb, ok, rmsLines }. Handles-inf(perfect cancellation), per-channel vs overall lines, and missing-audio-stream inputs. -
packages/producer/src/utils/audioRegression.test.ts— three new vitest cases covering identical sines (-inf), drifted sines (440 Hz vs 880 Hz), and missing-audio-stream input. Skips automatically when ffmpeg isn't on PATH (matches the existing harness invariant). -
packages/producer/src/regression-harness.ts— optionalmaxAudioResidualRmsDbfield inmeta.jsonvalidated alongside the existing audio knobs. When present, runs the residual check after envelope correlation and folds the result intoaudioPassed. When absent (default), skips the residual gate — legacy fixtures aren't retroactively broken. NewresidualRmsDbfield on theaudio_comparison_completeJSON event and on the pretty log line.
Test plan
- [x]
bunx vitest run packages/producer/src/utils/audioRegression.test.ts— 4 tests pass (the existing one + 3 new) - [x]
bun run --filter @hyperframes/producer typecheck— clean - [x]
bunx oxlint+bunx oxfmt --check— clean - [x] Verified end-to-end against Lambda renders:
many-cutslambda output vs Docker baseline = -90.36 dBFS residual (passes Rio's -50 dBFS gate)
Adoption path
Existing fixtures: no change. The check is opt-in.
New fixtures: add "maxAudioResidualRmsDb": -50 to meta.json. Existing
audio-bearing fixtures can adopt one at a time as their residuals are
verified.
🤖 Generated with Claude Code
- #882
👈 (View in Graphite) main
This stack of pull requests is managed by Graphite. Learn more about stacking.
remove rio mentions btw @jrusso1020