ref: 95784cbc564b5eea3d343cdaa1e7f58ca6070c6d
parent: 5e5e7f69548486dabe553e6466f8e273a913748f
author: Jean-Marc Valin <jeanmarcv@google.com>
date: Fri Aug 2 07:54:17 EDT 2024
Fix OpusCustom encoder busting at low bitrate Was due to nbAvailableBytes not matching the real CBR budget. Also adding same tell+16<=total_bits condition that the decoder has for the comb filter just to be on the safe side. This bug doesn't appear to be possible with the regular Opus API.
--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1572,7 +1572,6 @@
/* Can't produce more than 1275 output bytes */
nbCompressedBytes = IMIN(nbCompressedBytes,1275);
- nbAvailableBytes = nbCompressedBytes - nbFilledBytes;
if (st->vbr && st->bitrate!=OPUS_BITRATE_MAX)
{
@@ -1598,6 +1597,7 @@
}
effectiveBytes = nbCompressedBytes - nbFilledBytes;
}
+ nbAvailableBytes = nbCompressedBytes - nbFilledBytes;
equiv_rate = ((opus_int32)nbCompressedBytes*8*50 << (3-LM)) - (40*C+20)*((400>>LM) - 50);
if (st->bitrate != OPUS_BITRATE_MAX)
equiv_rate = IMIN(equiv_rate, st->bitrate - (40*C+20)*((400>>LM) - 50));
@@ -1688,7 +1688,7 @@
{
int enabled;
int qg;
- enabled = ((st->lfe&&nbAvailableBytes>3) || nbAvailableBytes>12*C) && !hybrid && !silence && !st->disable_pf
+ enabled = ((st->lfe&&nbAvailableBytes>3) || nbAvailableBytes>12*C) && !hybrid && !silence && tell+16<=total_bits && !st->disable_pf
&& st->complexity >= 5;
prefilter_tapset = st->tapset_decision;
--
⑨