Fixing a few bugs introduced in the energy interleaving changes and due to
authorJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Thu, 18 Jun 2009 02:39:46 +0000 (22:39 -0400)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Thu, 18 Jun 2009 02:39:46 +0000 (22:39 -0400)
side effects of "continue" statements.

libcelt/quant_bands.c

index 56df3e8..93e7574 100644 (file)
@@ -151,13 +151,13 @@ void quant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *ol
    /* 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 @@ void quant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *ol
          /*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,13 +206,13 @@ void quant_energy_finalise(const CELTMode *m, celt_ener_t *eBands, celt_word16_t
             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);
       }
    }
    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 @@ void unquant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *
    /* 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 @@ void unquant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *
          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,13 +307,13 @@ void unquant_energy_finalise(const CELTMode *m, celt_ener_t *eBands, celt_word16
             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);
       }
    }
    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);
    }