shithub: opus

Download patch

ref: 6b565268fb9ade18f3ec4dc365a2e31ed6f76ee7
parent: 44203907995199447d8a0052e6b1eb0189ae6385
author: Jean-Marc Valin <[email protected]>
date: Wed Jan 12 06:27:03 EST 2011

Fixes constrained VBR

Also removes the 8 byte/packet lower bound

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -1164,7 +1164,10 @@
 
      nbAvailableBytes = target+(1<<(BITRES+2))>>(BITRES+3);
      nbAvailableBytes=IMAX(min_allowed,nbAvailableBytes);
-     /* TODO: if we're busting, this will increase the reservoir by too much */
+
+     nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes);
+     nbAvailableBytes = nbCompressedBytes - nbFilledBytes;
+
      target=nbAvailableBytes<<(BITRES+3);
 
      if (st->vbr_count < 970)
@@ -1191,7 +1194,6 @@
         st->vbr_reservoir = 0;
         /*printf ("+%d\n", adjust);*/
      }
-     nbCompressedBytes = IMIN(nbCompressedBytes,nbAvailableBytes+nbFilledBytes);
 
      /* This moves the raw bits to take into account the new compressed size */
      ec_byte_shrink(&buf, nbCompressedBytes);
--- a/tools/celtdec.c
+++ b/tools/celtdec.c
@@ -533,9 +533,9 @@
          /*printf ("page granulepos: %d %d %d\n", skip_samples, page_nb_packets, (int)page_granule);*/
          last_granule = page_granule;
          /*Extract all available packets*/
-         while (!eos && ogg_stream_packetout(&os, &op) == 1 && op.bytes>=8)
+         while (!eos && ogg_stream_packetout(&os, &op) == 1)
          {
-	    if (!memcmp(op.packet, "CELT    ", 8)) {
+	    if (op.bytes>=8 && !memcmp(op.packet, "CELT    ", 8)) {
 	       celt_serialno = os.serialno;
 	    }
 	    if (celt_serialno == -1 || os.serialno != celt_serialno)
--- a/tools/celtenc.c
+++ b/tools/celtenc.c
@@ -484,10 +484,7 @@
      
    bytes_per_packet = (bitrate*1000*frame_size/rate+4)/8;
    
-   if (bytes_per_packet < 8) {
-      bytes_per_packet=8;
-      fprintf (stderr, "Warning: Requested bitrate (%0.3fkbit/sec) is too low. Setting CELT to 8 bytes/frame.\n",bitrate);
-   } else if (bytes_per_packet > MAX_FRAME_BYTES) {
+   if (bytes_per_packet > MAX_FRAME_BYTES) {
       bytes_per_packet=MAX_FRAME_BYTES;
       fprintf (stderr, "Warning: Requested bitrate (%0.3fkbit/sec) is too high. Setting CELT to %d bytes/frame.\n",bitrate,MAX_FRAME_BYTES);      
    }