shithub: opus

Download patch

ref: fa50d3ac349ea62db082898febd0a0fbe90dc1dc
parent: dcacb73c33bd0b9c4be2b88d6449b0f5543c7f7d
author: Jean-Marc Valin <[email protected]>
date: Tue Dec 14 10:02:21 EST 2010

More negative bits prevention

--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -207,11 +207,17 @@
    }
    for (i=0;i<*skip;i++)
    {
-      if (bits[codedBands-1] >= C<<BITRES)
+      int alloc_floor;
+      if (C==2)
+         alloc_floor = 4<<BITRES; /* Fine energy plus intensity stereo */
+      else
+         alloc_floor = 1<<BITRES;
+      if (bits[codedBands-1] >= alloc_floor)
       {
-         psum = psum - bits[codedBands-1] + ((C+1)<<BITRES);
-         bits[codedBands-1] = C<<BITRES;
-      } else {
+         psum = psum - bits[codedBands-1] + alloc_floor;
+         bits[codedBands-1] = alloc_floor;
+      } else if (bits[codedBands-1] < C<<BITRES)
+      {
          psum = psum - bits[codedBands-1];
          bits[codedBands-1] = 0;
       }