Measure the VBR target against the nominal rate - #206
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #206 +/- ##
==========================================
+ Coverage 93.09% 93.11% +0.01%
==========================================
Files 58 58
Lines 10389 10407 +18
==========================================
+ Hits 9672 9690 +18
Misses 505 505
Partials 212 212
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
FrantaBOT
approved these changes
Aug 13, 2026
thomas-vilte
force-pushed
the
fix/vbr-equiv-rate
branch
from
August 13, 2026 16:52
83a5446 to
0e676e5
Compare
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.
Description
There were two places where the VBR path was using the frame budget while the reference uses the requested bitrate.
1.
equiv_rate. This feeds the intensity band, trim, and temporal VBR factor. libopus caps it with the nominal bitrate (celt_encoder.c:1926):In VBR, nbCompressedBytes is the output buffer size, so without that IMIN every rate-dependent decision would see a bitrate corresponding to hundreds of kb/s. pion was always deriving equiv_rate from the frame budget.
Instrumenting the reference at 24 kb/s:
VBR: equiv=24000 with nbComp=1275
CBR: equiv=23600 with nbComp=59
In CBR, st->bitrate is OPUS_BITRATE_MAX, so the cap does not apply.
pion was returning 23600 in both cases. That put VBR 24 kb/s into the previous intensity-table entry: band 9 instead of the reference's band 10.
2. vbr_rate. The base used to calculate the target comes directly from the bitrate (celt_encoder.c:1904):
This is the integer portion of the frame — 60 bytes at 24 kb/s — including the header byte that the CBR payload budget excludes. The reservoir absorbs the difference.
pion was using the 59-byte payload budget instead, one byte less per frame.
For this, the CELT layer needs to know the nominal bitrate, so I added SetBitrate alongside the existing setters.
Measurement
Intensity-band agreement against opus_demo, over 3000 frames:
The 24 kb/s VBR case was a complete mismatch: the reference selected band 10 for all 3000 frames while pion selected band 9.
This also affects the bands that are actually coded:
Packet size and SNR in VBR:
CBR remains unchanged, verified at 24, 48, and 96 kb/s: 7.0676 / 10.1179 / 15.0721 dB, identical digit for digit.
What remains
In VBR, pion is now within roughly 0.5–2% of libopus in bytes and 0.08–0.10 dB in SNR.
In CBR, it remains essentially matched: +0.014 / +0.015 / −0.002 dB at 24, 48, and 96 kb/s.
The only metric still below 99% is the number of coded bands at 24 kb/s: 95.9% in VBR and 96.9% in CBR. Since it happens in both modes, this is not a VBR-path issue and should be addressed separately.
Reference issue
Part of #34.