shithub: opus

Download patch

ref: b6a3b0c4646256a9ad158102214b0075d80af571
parent: 60d0837ea00964d76926719afcb0849b2bf32906
author: Gregory Maxwell <[email protected]>
date: Fri Oct 3 13:12:44 EDT 2008

Fix stereo support; correctly deallocate bits_stereo.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -355,9 +355,15 @@
       int tell;
       int q;
       celt_word16_t n;
+      celt_int16_t * const *BPbits;
       
       int curr_balance, curr_bits;
       
+      if (C>1 && stereo_mode[i]==0)
+         BPbits = m->bits_stereo;
+      else
+         BPbits = m->bits;
+
       tell = ec_enc_tell(enc, 4);
       if (i != 0)
          balance -= tell;
@@ -366,14 +372,14 @@
       if (curr_balance > 3)
          curr_balance = 3;
       curr_balance = balance / curr_balance;
-      q = bits2pulses(m, m->bits[i], pulses[i]+curr_balance);
-      curr_bits = m->bits[i][q];
+      q = bits2pulses(m, BPbits[i], pulses[i]+curr_balance);
+      curr_bits = BPbits[i][q];
       remaining_bits -= curr_bits;
       if (remaining_bits < 0)
       {
          q--;
          remaining_bits += curr_bits;
-         curr_bits = m->bits[i][q];
+         curr_bits = BPbits[i][q];
          remaining_bits -= curr_bits;
       }
       balance += pulses[i] + tell;
@@ -434,9 +440,15 @@
       int tell;
       int q;
       celt_word16_t n;
+      celt_int16_t * const *BPbits;
       
       int curr_balance, curr_bits;
       
+      if (C>1 && stereo_mode[i]==0)
+         BPbits = m->bits_stereo;
+      else
+         BPbits = m->bits;
+
       tell = ec_dec_tell(dec, 4);
       if (i != 0)
          balance -= tell;
@@ -445,14 +457,14 @@
       if (curr_balance > 3)
          curr_balance = 3;
       curr_balance = balance / curr_balance;
-      q = bits2pulses(m, m->bits[i], pulses[i]+curr_balance);
-      curr_bits = m->bits[i][q];
+      q = bits2pulses(m, BPbits[i], pulses[i]+curr_balance);
+      curr_bits = BPbits[i][q];
       remaining_bits -= curr_bits;
       if (remaining_bits < 0)
       {
          q--;
          remaining_bits += curr_bits;
-         curr_bits = m->bits[i][q];
+         curr_bits = BPbits[i][q];
          remaining_bits -= curr_bits;
       }
       balance += pulses[i] + tell;
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -394,7 +394,6 @@
    if (mode->nbChannels>=2)
       mode->bits_stereo = (const celt_int16_t **)compute_alloc_cache(mode, mode->nbChannels);
 
-   mode->bits_stereo = NULL;
 #ifndef SHORTCUTS
    psydecay_init(&mode->psy, MAX_PERIOD/2, mode->Fs);
 #endif
@@ -430,6 +429,18 @@
       }
    }
    celt_free((int**)mode->bits);
+   if (mode->bits_stereo != NULL)
+   {
+      for (i=0;i<mode->nbEBands;i++)
+      {
+         if (mode->bits_stereo[i] != prevPtr)
+         {
+            prevPtr = mode->bits_stereo[i];
+            celt_free((int*)mode->bits_stereo[i]);
+         }
+      }
+      celt_free((int**)mode->bits_stereo);
+   }
    if (check_mode(mode) != CELT_OK)
       return;
    celt_free((int*)mode->eBands);