shithub: opus

Download patch

ref: 8e4476789c3fbd5b56dbb15c6445193ba215a753
parent: 034172baa6880895050b7fcb65bbf7485680b8cf
author: Gregory Maxwell <[email protected]>
date: Thu Dec 16 09:22:51 EST 2010

Terminate the coding of skip bits at the last dynalloc boosted band. Otherwise the bitstream allows non-sensible behavior by the encoder (dynallocing bits into a band and then skipping it). This reduces skip bit overhead by about 2-3% at moderate bitrates with the current encoder.

--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -140,7 +140,7 @@
 
 #define ALLOC_STEPS 6
 
-static inline int interp_bits2pulses(const CELTMode *m, int start, int end,
+static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int skip_start,
       const int *bits1, const int *bits2, const int *thresh, int total, int *bits,
       int *ebits, int *fine_priority, int len, int _C, int LM, void *ec, int encode, int prev)
 {
@@ -221,7 +221,7 @@
          This means we won't be using the extra bit we reserved to signal the
           end of manual skipping, but that will get added back in by
           quant_all_bands().*/
-      if (j<=start)
+      if (j<=skip_start)
          break;
       rem = IMAX(left-(m->eBands[j]-m->eBands[start]),0);
       band_width = m->eBands[codedBands]-m->eBands[j];
@@ -363,6 +363,7 @@
    int lo, hi, len, j;
    const int C = CHANNELS(_C);
    int codedBands;
+   int skip_start;
    VARDECL(int, bits1);
    VARDECL(int, bits2);
    VARDECL(int, thresh);
@@ -371,6 +372,7 @@
    
    total = IMAX(total, 0);
    len = m->nbEBands;
+   skip_start = start;
    ALLOC(bits1, len, int);
    ALLOC(bits2, len, int);
    ALLOC(thresh, len, int);
@@ -424,8 +426,10 @@
       if (bits1[j] < 0)
          bits1[j] = 0;
       bits1[j] += offsets[j];
+      if (offsets[j]>0)
+         skip_start = j;
    }
-   codedBands = interp_bits2pulses(m, start, end, bits1, bits2, thresh,
+   codedBands = interp_bits2pulses(m, start, end, skip_start, bits1, bits2, thresh,
          total, pulses, ebits, fine_priority, len, C, LM, ec, encode, prev);
    RESTORE_STACK;
    return codedBands;