shithub: opus

Download patch

ref: 420c325875686e2f45e00878cba21b4dcc5e1bfe
parent: 09213de91c1da66be193ad27a61f08eb43f2302d
author: Gregory Maxwell <[email protected]>
date: Thu Jan 27 17:35:50 EST 2011

Prevent VBR from shooting up to the maximum rate if set to very low target rates, and prevent the encoder VBR from producing 1 byte frames (which are no longer allowed).

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -869,10 +869,10 @@
          celt_int32 max_allowed;
          /* We could use any multiple of vbr_rate as bound (depending on the
              delay).
-            This is clamped to ensure we use at least one byte if the encoder
+            This is clamped to ensure we use at least two bytes if the encoder
              was entirely empty, but to allow 0 in hybrid mode. */
          vbr_bound = vbr_rate;
-         max_allowed = IMIN(IMAX((tell+7>>3)-nbFilledBytes,
+         max_allowed = IMIN(IMAX(tell==1?2:0,
                vbr_rate+vbr_bound-st->vbr_reservoir>>(BITRES+3)),
                nbAvailableBytes);
          if(max_allowed < nbAvailableBytes)
@@ -1596,7 +1596,7 @@
          if (value>3072000)
             value = 3072000;
          frame_rate = ((st->mode->Fs<<3)+(N>>1))/N;
-         st->vbr_rate_norm = ((value<<(BITRES+3))+(frame_rate>>1))/frame_rate;
+         st->vbr_rate_norm = value>0?IMAX(1,((value<<(BITRES+3))+(frame_rate>>1))/frame_rate):0;
       }
       break;
       case CELT_RESET_STATE: