Skip to content

Return the constrained VBR reservoir underflow - #210

Merged
thomas-vilte merged 1 commit into
pion:mainfrom
thomas-vilte:fix/cvbr-reservoir
Aug 13, 2026
Merged

Return the constrained VBR reservoir underflow#210
thomas-vilte merged 1 commit into
pion:mainfrom
thomas-vilte:fix/cvbr-reservoir

Conversation

@thomas-vilte

Copy link
Copy Markdown
Member

Description

When the constrained VBR reservoir becomes negative, the reference returns those bits to the current frame (celt_encoder.c):

if (st->constrained_vbr && st->vbr_reservoir < 0)
{
/* We're under the min value -- increase rate */
int adjust = (-st->vbr_reservoir)/(8<<BITRES);

nbAvailableBytes += silence?0:adjust;

st->vbr_reservoir = 0;

}

pion would simply clamp to zero and lose them. A negative reservoir means that previous frames spent less than the target rate, so this loop is precisely what keeps the average at the target; without it, the mode falls short and never recovers.

Measurement

Constrained VBR over 60 seconds of music, against opus_demo restricted-celt -cvbr:

bitrate SNR before SNR after bytes pion before after libopus
24000 −0.208 +0.017 57.50 61.00 61.0
48000 −0.101 +0.007 115.88 121.01 121.0
96000 −0.224 +0.007 235.06 241.02 241.1

The other modes remain unchanged, verified: CBR 7.0676 and 15.0721 dB, unrestricted VBR 6.3886 and 15.0756, identical to before the change.

Mode Status

With this, all four paths are now on par with the reference on the same material:

mode 24 kb/s 48 kb/s 96 kb/s
CBR +0.014 +0.015 −0.002
VBR +0.012 +0.003 −0.005
CVBR +0.017 +0.007 +0.007
mono VBR +0.001 −0.005 −0.044

Reference issue

Part of #34.

@thomas-vilte
thomas-vilte requested a review from FrantaBOT August 13, 2026 17:55
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.10%. Comparing base (9bfb54d) to head (533509a).

Files with missing lines Patch % Lines
internal/celt/encoder.go 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #210      +/-   ##
==========================================
- Coverage   93.11%   93.10%   -0.01%     
==========================================
  Files          58       58              
  Lines       10408    10411       +3     
==========================================
+ Hits         9691     9693       +2     
- Misses        505      506       +1     
  Partials      212      212              
Flag Coverage Δ
go 93.10% <75.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thomas-vilte
thomas-vilte merged commit d371ab7 into pion:main Aug 13, 2026
20 checks passed
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.

2 participants