shithub: opus

Download patch

ref: e2b7616e8a404ce78e2de14354c3bb36f5e6f550
parent: b0b23a3579f2c42e236cba9dfd88b250b59a2aca
author: Jean-Marc Valin <[email protected]>
date: Wed Jun 17 18:39:46 EDT 2009

Fixing a few bugs introduced in the energy interleaving changes and due to
side effects of "continue" statements.

--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -151,13 +151,13 @@
    /* Encode finer resolution */
    for (i=0;i<m->nbEBands;i++)
    {
+      celt_int16_t frac = 1<<fine_quant[i];
+      if (fine_quant[i] <= 0)
+         continue;
       c=0;
       do {
          int q2;
-         celt_int16_t frac = 1<<fine_quant[i];
          celt_word16_t offset;
-         if (fine_quant[i] <= 0)
-            continue;
 #ifdef FIXED_POINT
          /* Has to be without rounding */
          q2 = (error[i+c*m->nbEBands]+QCONST16(.5f,8))>>(8-fine_quant[i]);
@@ -178,6 +178,8 @@
          /*printf ("%f ", error[i] - offset);*/
       } while (++c < C);
    }
+   for (i=0;i<C*m->nbEBands;i++)
+      eBands[i] = log2Amp(oldEBands[i]);
 }
 
 void quant_energy_finalise(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, celt_word16_t *error, int *fine_quant, int *fine_priority, int bits_left, ec_enc *enc)
@@ -204,7 +206,6 @@
             offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384);
 #endif
             oldEBands[i+c*m->nbEBands] += offset;
-            eBands[i+c*m->nbEBands] = log2Amp(oldEBands[i+c*m->nbEBands]);
             bits_left--;
          } while (++c < C);
       }
@@ -211,6 +212,7 @@
    }
    for (i=0;i<C*m->nbEBands;i++)
    {
+      eBands[i] = log2Amp(oldEBands[i]);
       if (oldEBands[i] < -QCONST16(7.f,8))
          oldEBands[i] = -QCONST16(7.f,8);
    }
@@ -263,12 +265,12 @@
    /* Decode finer resolution */
    for (i=0;i<m->nbEBands;i++)
    {
+      if (fine_quant[i] <= 0)
+         continue;
       c=0; 
       do {
          int q2;
          celt_word16_t offset;
-         if (fine_quant[i] <= 0)
-            continue;
          q2 = ec_dec_bits(dec, fine_quant[i]);
 #ifdef FIXED_POINT
          offset = SUB16(SHR16(SHL16(q2,8)+QCONST16(.5,8),fine_quant[i]),QCONST16(.5f,8));
@@ -276,9 +278,10 @@
          offset = (q2+.5f)*(1<<(14-fine_quant[i]))*(1.f/16384) - .5f;
 #endif
          oldEBands[i+c*m->nbEBands] += offset;
-         eBands[i+c*m->nbEBands] = log2Amp(oldEBands[i+c*m->nbEBands]);
       } while (++c < C);
    }
+   for (i=0;i<C*m->nbEBands;i++)
+      eBands[i] = log2Amp(oldEBands[i]);
 }
 
 void unquant_energy_finalise(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *oldEBands, int *fine_quant,  int *fine_priority, int bits_left, ec_dec *dec)
@@ -304,7 +307,6 @@
             offset = (q2-.5f)*(1<<(14-fine_quant[i]-1))*(1.f/16384);
 #endif
             oldEBands[i+c*m->nbEBands] += offset;
-            eBands[i+c*m->nbEBands] = log2Amp(oldEBands[i+c*m->nbEBands]);
             bits_left--;
          } while (++c < C);
       }
@@ -311,6 +313,7 @@
    }
    for (i=0;i<C*m->nbEBands;i++)
    {
+      eBands[i] = log2Amp(oldEBands[i]);
       if (oldEBands[i] < -QCONST16(7.f,8))
          oldEBands[i] = -QCONST16(7.f,8);
    }