hyperframes icon indicating copy to clipboard operation
hyperframes copied to clipboard

feat(producer): add Rio-style residual-RMS check to regression harness

Open jrusso1020 opened this issue 6 months ago • 2 comments

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:

  1. packages/producer/src/utils/audioRegression.ts — new computeAudioResidualRmsDb(rendered, snapshot, maxResidualRmsDb=-50) that spawns ffmpeg with Rio's filter graph, parses the Overall 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.

  2. 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).

  3. packages/producer/src/regression-harness.ts — optional maxAudioResidualRmsDb field in meta.json validated alongside the existing audio knobs. When present, runs the residual check after envelope correlation and folds the result into audioPassed. When absent (default), skips the residual gate — legacy fixtures aren't retroactively broken. New residualRmsDb field on the audio_comparison_complete JSON 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-cuts lambda 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

jrusso1020 avatar May 16 '26 02:05 jrusso1020

This stack of pull requests is managed by Graphite. Learn more about stacking.

jrusso1020 avatar May 16 '26 02:05 jrusso1020

remove rio mentions btw @jrusso1020

miguel-heygen avatar May 16 '26 02:05 miguel-heygen