shithub: opus

Download patch

ref: 8842fdee21772dccf2417d90aacac08c2b45ae68
parent: ec836da27cc2f36435c8dcd7ef57acb26a4d54c6
author: Gregory Maxwell <[email protected]>
date: Mon May 4 11:58:40 EDT 2009

Fixing stereo: Do not attempt to use more bits than are available.
This change breaks the bitstream.

Make the first frame out of the encoder an intra-frame. (While not required this may help
in the case that the decoder has old state laying around, and it shouldn't hurt)

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -51,11 +51,12 @@
 
 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
-#define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
+#define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Minimum 16-bit value.   */
 #define MAX16(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 32-bit value.  */
-#define MIN32(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
+#define MIN32(a,b) ((a) < (b) ? (a) : (b))   /**< Minimum 32-bit value.   */
 #define MAX32(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
+#define IMIN(a,b) ((a) < (b) ? (a) : (b))   /**< Minimum int value.   */
 #define IMAX(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum int value.   */
 #define UADD32(a,b) ((a)+(b))
 #define USUB32(a,b) ((a)-(b))
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -539,7 +539,7 @@
       if (curr_balance > 3)
          curr_balance = 3;
       curr_balance = balance / curr_balance;
-      b = pulses[i]+curr_balance;
+      b = IMIN(remaining_bits+1,pulses[i]+curr_balance);
       if (b<0)
          b = 0;
 
@@ -892,7 +892,7 @@
       if (curr_balance > 3)
          curr_balance = 3;
       curr_balance = balance / curr_balance;
-      b = pulses[i]+curr_balance;
+      b = IMIN(remaining_bits+1,pulses[i]+curr_balance);
       if (b<0)
          b = 0;
       
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -110,6 +110,7 @@
 
    st->pitch_enabled = 1;
    st->pitch_available = 1;
+   st->delayedIntra = 1;
 
    st->in_mem = celt_alloc(st->overlap*C*sizeof(celt_sig_t));
    st->out_mem = celt_alloc((MAX_PERIOD+st->overlap)*C*sizeof(celt_sig_t));