Repository navigation
Check that audio survives the round trip, approximately and exactly - #6
Merged
Merged
Conversation
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>
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.
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.
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
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.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.
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.shneeded no change — verified:--- linux-aarch64 OKwith valgrind clean and its control still detected.🤖 Generated with Claude Code