Now storing the band energies in de-interleaved format when doing stereo
authorJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Sun, 14 Jun 2009 13:19:51 +0000 (09:19 -0400)
committerJean-Marc Valin <jean-marc.valin@usherbrooke.ca>
Sun, 14 Jun 2009 13:19:51 +0000 (09:19 -0400)
libcelt/bands.c
libcelt/celt.c
libcelt/quant_bands.c

index f564be7..9ddfb03 100644 (file)
@@ -74,11 +74,11 @@ void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *
             } while (++j<eBands[i+1]);
             /* We're adding one here to make damn sure we never end up with a pitch vector that's
                larger than unity norm */
-            bank[i*C+c] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-shift);
+            bank[i+c*m->nbEBands] = EPSILON+VSHR32(EXTEND32(celt_sqrt(sum)),-shift);
          } else {
-            bank[i*C+c] = EPSILON;
+            bank[i+c*m->nbEBands] = EPSILON;
          }
-         /*printf ("%f ", bank[i*C+c]);*/
+         /*printf ("%f ", bank[i+c*m->nbEBands]);*/
       }
    }
    /*printf ("\n");*/
@@ -96,8 +96,8 @@ void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_n
          celt_word16_t g;
          int j,shift;
          celt_word16_t E;
-         shift = celt_zlog2(bank[i*C+c])-13;
-         E = VSHR32(bank[i*C+c], shift);
+         shift = celt_zlog2(bank[i+c*m->nbEBands])-13;
+         E = VSHR32(bank[i+c*m->nbEBands], shift);
          g = EXTRACT16(celt_rcp(SHL32(E,3)));
          j=eBands[i]; do {
             X[j*C+c] = MULT16_16_Q15(VSHR32(freq[j*C+c],shift-1),g);
@@ -121,8 +121,8 @@ void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *
          celt_word32_t sum = 1e-10;
          for (j=eBands[i];j<eBands[i+1];j++)
             sum += X[j*C+c]*X[j*C+c];
-         bank[i*C+c] = sqrt(sum);
-         /*printf ("%f ", bank[i*C+c]);*/
+         bank[i+c*m->nbEBands] = sqrt(sum);
+         /*printf ("%f ", bank[i+c*m->nbEBands]);*/
       }
    }
    /*printf ("\n");*/
@@ -142,8 +142,8 @@ void compute_noise_energies(const CELTMode *m, const celt_sig_t *X, const celt_w
          celt_word32_t sum = 1e-10;
          for (j=eBands[i];j<eBands[i+1];j++)
             sum += X[j*C+c]*X[j*C+c]*tonality[j];
-         bank[i*C+c] = sqrt(sum);
-         /*printf ("%f ", bank[i*C+c]);*/
+         bank[i+c*m->nbEBands] = sqrt(sum);
+         /*printf ("%f ", bank[i+c*m->nbEBands]);*/
       }
    }
    /*printf ("\n");*/
@@ -161,7 +161,7 @@ void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_n
       for (i=0;i<m->nbEBands;i++)
       {
          int j;
-         celt_word16_t g = 1.f/(1e-10+bank[i*C+c]);
+         celt_word16_t g = 1.f/(1e-10+bank[i+c*m->nbEBands]);
          for (j=eBands[i];j<eBands[i+1];j++)
             X[j*C+c] = freq[j*C+c]*g;
       }
@@ -198,7 +198,7 @@ void denormalise_bands(const CELTMode *m, const celt_norm_t * restrict X, celt_s
       for (i=0;i<m->nbEBands;i++)
       {
          int j;
-         celt_word32_t g = SHR32(bank[i*C+c],1);
+         celt_word32_t g = SHR32(bank[i+c*m->nbEBands],1);
          j=eBands[i]; do {
             freq[j*C+c] = SHL32(MULT16_32_Q15(X[j*C+c], g),2);
          } while (++j<eBands[i+1]);
@@ -305,10 +305,10 @@ static void stereo_band_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t
             celt_word16_t left, right;
             celt_word16_t norm;
 #ifdef FIXED_POINT
-            int shift = celt_zlog2(MAX32(bank[i*C], bank[i*C+1]))-13;
+            int shift = celt_zlog2(MAX32(bank[i], bank[i+m->nbEBands]))-13;
 #endif
-            left = VSHR32(bank[i*C],shift);
-            right = VSHR32(bank[i*C+1],shift);
+            left = VSHR32(bank[i],shift);
+            right = VSHR32(bank[i+m->nbEBands],shift);
             norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right));
             a1 = DIV32_16(SHL32(EXTEND32(left),14),norm);
             a2 = dir*DIV32_16(SHL32(EXTEND32(right),14),norm);
@@ -339,10 +339,10 @@ static void point_stereo_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_
    celt_word16_t a1, a2;
    int j;
 #ifdef FIXED_POINT
-   int shift = celt_zlog2(MAX32(bank[i*C], bank[i*C+1]))-13;
+   int shift = celt_zlog2(MAX32(bank[i], bank[i+m->nbEBands]))-13;
 #endif
-   left = VSHR32(bank[i*C],shift);
-   right = VSHR32(bank[i*C+1],shift);
+   left = VSHR32(bank[i],shift);
+   right = VSHR32(bank[i+m->nbEBands],shift);
    norm = EPSILON + celt_sqrt(EPSILON+MULT16_16(left,left)+MULT16_16(right,right));
    a1 = DIV32_16(SHL32(EXTEND32(left),14),norm);
    a2 = dir*DIV32_16(SHL32(EXTEND32(right),14),norm);
index 9052040..0863374 100644 (file)
@@ -763,9 +763,14 @@ int celt_encode_float(CELTEncoder * restrict st, const celt_sig_t * pcm, celt_si
       compute_band_energies(st->mode, freq, bandEp);
       normalise_bands(st->mode, freq, P, bandEp);
       pitch_power = bandEp[0]+bandEp[1]+bandEp[2];
-      /* Check if we can safely use the pitch (i.e. effective gain 
-         isn't too high) */
       curr_power = bandE[0]+bandE[1]+bandE[2];
+      if (C>1)
+      {
+         pitch_power += bandEp[0+st->mode->nbEBands]+bandEp[1+st->mode->nbEBands]+bandEp[2+st->mode->nbEBands];
+         curr_power += bandE[0+st->mode->nbEBands]+bandE[1+st->mode->nbEBands]+bandE[2+st->mode->nbEBands];
+      }
+      /* Check if we can safely use the pitch (i.e. effective gain 
+      isn't too high) */
       if ((MULT16_32_Q15(QCONST16(.1f, 15),curr_power) + QCONST32(10.f,ENER_SHIFT) < pitch_power))
       {
          /* Pitch prediction */
index 75b555b..dd3d9e3 100644 (file)
@@ -311,7 +311,7 @@ unsigned quant_coarse_energy(const CELTMode *m, celt_word16_t *eBands, celt_word
          SAVE_STACK;
          ALLOC(E, m->nbEBands, celt_word16_t);
          for (i=0;i<m->nbEBands;i++)
-            E[i] = eBands[C*i+c];
+            E[i] = eBands[i+c*m->nbEBands];
          coarse_needed=quant_coarse_energy_mono(m, E, oldEBands+c*m->nbEBands, budget/C, intra, prob, error+c*m->nbEBands, enc);
          maxBudget=IMAX(maxBudget,coarse_needed);
          RESTORE_STACK;
@@ -339,7 +339,7 @@ void quant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *ol
          SAVE_STACK;
          quant_fine_energy_mono(m, E, oldEBands+c*m->nbEBands, error+c*m->nbEBands, fine_quant, enc);
          for (i=0;i<m->nbEBands;i++)
-            eBands[C*i+c] = E[i];
+            eBands[i+c*m->nbEBands] = E[i];
          RESTORE_STACK;
       }
    }
@@ -364,7 +364,7 @@ void quant_energy_finalise(const CELTMode *m, celt_ener_t *eBands, celt_word16_t
          SAVE_STACK;
          quant_energy_finalise_mono(m, E, oldEBands+c*m->nbEBands, error+c*m->nbEBands, fine_quant, fine_priority, bits_left/C, enc);
          for (i=0;i<m->nbEBands;i++)
-            eBands[C*i+c] = E[i];
+            eBands[i+c*m->nbEBands] = E[i];
          RESTORE_STACK;
       }
    }
@@ -412,7 +412,7 @@ void unquant_fine_energy(const CELTMode *m, celt_ener_t *eBands, celt_word16_t *
          int i;
          unquant_fine_energy_mono(m, E, oldEBands+c*m->nbEBands, fine_quant, dec);
          for (i=0;i<m->nbEBands;i++)
-            eBands[C*i+c] = E[i];
+            eBands[i+c*m->nbEBands] = E[i];
       }
       RESTORE_STACK;
    }
@@ -438,7 +438,7 @@ void unquant_energy_finalise(const CELTMode *m, celt_ener_t *eBands, celt_word16
          int i;
          unquant_energy_finalise_mono(m, E, oldEBands+c*m->nbEBands, fine_quant, fine_priority, bits_left/C, dec);
          for (i=0;i<m->nbEBands;i++)
-            eBands[C*i+c] = E[i];
+            eBands[i+c*m->nbEBands] = E[i];
       }
       RESTORE_STACK;
    }