Derive the VBR floor from the coded bin count - #202
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #202 +/- ##
==========================================
+ Coverage 93.10% 93.13% +0.03%
==========================================
Files 58 58
Lines 10263 10260 -3
==========================================
+ Hits 9555 9556 +1
+ Misses 500 498 -2
+ Partials 208 206 -2
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 12, 2026
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
In VBR, the encoder was only using 28–38% of the requested bitrate. At 96 kbps it was averaging around 27 kbps.
The cause was the target floor in
compute_vbr. libopus (celt_encoder.c) does:pion had:
There are two problems here. It was using effectiveBytes where libopus uses a bin count (eBands[19]<<LM = 480, not the byte budget), and it divided by 65536, which corresponds to the SHR32(..., DB_SHIFT) — an identity in the float build (arch.h:313).
Together, those made the floor several orders of magnitude too small, so IMIN(target, floor_depth) always reduced the target to target>>2: one quarter of the requested bitrate on every frame.
I also ported the transient boost, which was previously approximated as:
libopus scales it using tf_estimate and compensates for the average:
SHL32 is also an identity in the float build, so this becomes:
Measurement
Average packet size over 200 music frames, compared against the requested bitrate:
Constrained VBR was also under target at around 77–79%; it now reaches 94–95%.
The packet sizes still vary frame to frame as expected: there are 10–12 distinct sizes per bitrate, ranging from 51 to 60 bytes at 24 kbps.
What is still short
At 96 kbps, libopus averages 244 bytes, slightly above the nominal 240, while pion stops at 227.5.
That's a separate structural issue: pion currently gives CELT a budget equal to frameBytes, so unrestricted VBR can only undershoot the target, never exceed it. libopus separates the packet buffer limit from the nominal vbr_rate, allowing demanding frames to use more bits while the reservoir keeps the long-term average under control.
That also shows up in quality: VBR round-trip SNR against libopus changes by +0.19 dB at 24 kbps, −0.15 dB at 48 kbps, and −0.45 dB at 96 kbps. The direction follows the amount of bits being spent.
Separating those two budgets is a separate change, so I'm leaving it for another PR.
Tests
TestVBRTracksTargetBitrate catches the main issue: it averages 40 frames and requires the result to stay above 80% of the requested bitrate. With the old floor it was around 30%, so the test fails.
TestVBRProducesVaryingPacketSizes was still passing with the bug because the two synthetic tones happened to produce different packet sizes anyway. I rewrote it around a case where the variation actually depends on the target being correct: a silence frame versus tonal frames.
Reference issue
Part of #34.