Skip to content

Check that audio survives the round trip, approximately and exactly - #6

Merged
andrewchen5678 merged 1 commit into
mainfrom
fidelity-checks
Jul 31, 2026
Merged

andrewchen5678 merged 1 commit into
mainfrom
fidelity-checks

Conversation

@andrewchen5678

Copy link
Copy Markdown
Contributor

Two questions, and only one has an exact answer.

The exact one

OPUS_GET_FINAL_RANGE. If the decoder's entropy coder ends in the same state as the encoder's, the decoder walked an identical path through that packet's range coder — libopus's own test suite uses it the same way. Unlike a digest of the bitstream it is valid across platforms, since the AVX2 and NEON archives take different float paths and would produce different bytes for reasons that are not bugs. Asserted for all 800 packets.

The approximate one

Four signal classes — tone, chord, band-limited noise, speech-like — across 48 kHz stereo and mono, 16 kHz and 8 kHz.

measure asserted why
per-band energy error ≤ 6 dB phase-blind, survives what the other two trip over. The gate.
correlation per signal class catches waveform damage band energy would miss
SNR reported only collapses on noise by design — a working encoder scores 2.9 dB

The correlation floor cannot be one number: noise round-trips at 0.70 at 8 kHz on a healthy encoder, so anything strict enough to mean something for a chord fails every clean build. 0.99 tone, 0.95 chord and speech, 0.60 noise.

Two bugs found by measuring, both in the test

  • Alignment cannot be a fixed offset. get_lookahead() is exact — the aperiodic noise signal locks onto it off-by-zero at every rate, now asserted — but periodic content aligns equally well a whole period late, and the speech-like signal genuinely lands 16 samples early at 16 kHz. Forcing the reported value dropped its correlation to 0.7180 and failed six checks against an encoder that was working perfectly.
  • A search window must leave room for the largest lag it tries. At 8 kHz a one-second signal is 8000 samples, so a fixed 8192-sample window left room for exactly one candidate — delay 0. Every metric downstream then compared signals 52 samples apart and reported a broken codec.

Margins, and cross-platform stability

Worst band error is 4.1 dB against the 6 dB gate. Tightest correlation margin is 0.977 vs 0.95.

macOS arm64 Linux aarch64
48k stereo noise corr 0.9429 0.9430
16k noise corr 0.8150 0.8166
16k noise band 4.1 dB 3.8 dB
8k noise corr 0.7029 0.7027

Agreement to within 0.002 correlation and 0.3 dB across two architectures is the property that makes an approximate check work where a digest could not.

Cost

74 checks, up from 37. About 0.4 s added to the binary, and quick enough under valgrind that test-docker.sh needed no change — verified: --- linux-aarch64 OK with valgrind clean and its control still detected.

🤖 Generated with Claude Code

Two questions, and only one has an exact answer.

The exact one is OPUS_GET_FINAL_RANGE. If the decoder's entropy coder
ends in the same state as the encoder's, the decoder walked an identical
path through that packet's range coder; libopus's own test suite uses it
the same way. Unlike a digest of the bitstream it is valid across
platforms, because the AVX2 and NEON archives take different float paths
and would produce different bytes for reasons that are not bugs. Asserted
for all 800 packets.

The approximate one is whether the audio survived, which cannot be exact
because the codec is lossy on purpose. Four signal classes - tone, chord,
band-limited noise, speech-like - across 48 kHz stereo and mono, 16 kHz
and 8 kHz. Per-band energy error is the gate at 6 dB; correlation is
asserted against a floor that travels with the signal; SNR is reported
and not asserted, because CELT preserves band energy for noise rather
than the waveform and a working encoder scores 2.9 dB there.

The correlation floor cannot be one number. Noise round-trips at 0.70 at
8 kHz on a healthy encoder, so anything strict enough to mean something
for a chord fails every clean build. 0.99 tone, 0.95 chord and speech,
0.60 noise.

Two bugs found by measuring rather than reasoning, both in the test:

  - Alignment cannot be a fixed offset. get_lookahead() is exact - the
    aperiodic noise signal locks onto it off-by-zero at every rate, which
    is now itself a check - but periodic content aligns equally well a
    whole period late, and the speech-like signal genuinely lands 16
    samples early at 16 kHz. Forcing the reported value dropped its
    correlation to 0.7180 and failed six checks against an encoder that
    was working perfectly.
  - A search window has to leave room for the largest lag it tries. At
    8 kHz a one second signal is 8000 samples, so a fixed 8192-sample
    window left room for exactly one candidate, delay 0. Every metric
    downstream then compared signals 52 samples apart and reported a
    broken codec.

Thresholds have margin and are stable across architectures. Worst band
error is 4.1 dB against the 6 dB gate. macOS arm64 and Linux aarch64
agree to within 0.002 correlation and 0.3 dB of band energy, which is the
property that makes an approximate check work where a digest could not.

74 checks now, from 37. Adds about 0.4s to the binary, and it stays quick
enough under valgrind that test-docker.sh is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@andrewchen5678
andrewchen5678 merged commit 74aab76 into main Jul 31, 2026
16 checks passed
@andrewchen5678
andrewchen5678 deleted the fidelity-checks branch July 31, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant