shithub: opus

Download patch

ref: a1bc18a38836e2b1360a26a1d7ef2571b2f3b694
parent: 069c3de65f8c3bfcb0c488fbb8aa7ab11a3eba78
author: Jean-Marc Valin <[email protected]>
date: Tue Mar 4 17:52:52 EST 2008

compute_band_energies() merged with normalised_bands()

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -70,8 +70,8 @@
    }
 }
 
-/* Compute the amplitude (sqrt energy) in each of the bands */
-void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bank)
+/* Normalise each band such that the energy is one. */
+void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bank)
 {
    int i, c, B, C;
    const int *eBands = m->eBands;
@@ -82,29 +82,12 @@
       for (i=0;i<m->nbEBands;i++)
       {
          int j;
+         float g;
          float sum = 1e-10;
          for (j=B*eBands[i];j<B*eBands[i+1];j++)
-            sum += SIG_SCALING_1*SIG_SCALING_1*X[j*C+c]*X[j*C+c];
+            sum += SIG_SCALING_1*SIG_SCALING_1*freq[j*C+c]*freq[j*C+c];
          bank[i*C+c] = ENER_SCALING*sqrt(sum);
-         /*printf ("%f ", bank[i*C+c]);*/
-      }
-   }
-   /*printf ("\n");*/
-}
-
-/* Normalise each band such that the energy is one. */
-void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
-{
-   int i, c, B, C;
-   const int *eBands = m->eBands;
-   B = m->nbMdctBlocks;
-   C = m->nbChannels;
-   for (c=0;c<C;c++)
-   {
-      for (i=0;i<m->nbEBands;i++)
-      {
-         int j;
-         float g = 1.f/(1e-10+ENER_SCALING_1*bank[i*C+c]*sqrt(C));
+         g = 1.f/(1e-10+ENER_SCALING_1*bank[i*C+c]*sqrt(C));
          for (j=B*eBands[i];j<B*eBands[i+1];j++)
             X[j*C+c] = NORM_SCALING*SIG_SCALING_1*freq[j*C+c]*g;
       }
@@ -124,7 +107,6 @@
    ALLOC(freq, m->nbMdctBlocks*m->nbChannels*m->eBands[m->nbEBands+1], celt_sig_t);
    for (i=0;i<m->nbMdctBlocks*m->nbChannels*m->eBands[m->nbEBands+1];i++)
       freq[i] = SHL32(EXTEND32(X[i]), 10);
-   compute_band_energies(m, freq, tmpE);
    normalise_bands(m, freq, X, tmpE);
    RESTORE_STACK;
 }
@@ -134,7 +116,6 @@
    VARDECL(celt_ener_t *tmpE);
    SAVE_STACK;
    ALLOC(tmpE, m->nbEBands*m->nbChannels, celt_ener_t);
-   compute_band_energies(m, X, tmpE);
    normalise_bands(m, X, X, tmpE);
    RESTORE_STACK;
 }
--- a/libcelt/bands.h
+++ b/libcelt/bands.h
@@ -43,13 +43,6 @@
 sparse spectrum resulting from the pulse codebook */
 void exp_rotation(celt_norm_t *X, int len, celt_word16_t theta, int dir, int stride, int iter);
 
-/** Compute the amplitude (sqrt energy) in each of the bands 
- * @param m Mode data 
- * @param X Spectrum
- * @param bands Square root of the energy for each band (returned)
- */
-void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bands);
-
 /** Normalise each band of X such that the energy in each band is 
     equal to 1
  * @param m Mode data 
@@ -56,7 +49,7 @@
  * @param X Spectrum (returned normalised)
  * @param bands Square root of the energy for each band
  */
-void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bands);
+void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, celt_ener_t *bands);
 
 void renormalise_bands(const CELTMode *m, celt_norm_t *X);
 
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -307,7 +307,6 @@
    printf ("\n");*/
 
    /* Band normalisation */
-   compute_band_energies(st->mode, freq, bandE);
    normalise_bands(st->mode, freq, X, bandE);
    /*for (i=0;i<st->mode->nbEBands;i++)printf("%f ", bandE[i]);printf("\n");*/
    /*for (i=0;i<N*B*C;i++)printf("%f ", X[i]);printf("\n");*/
@@ -329,7 +328,6 @@
       /* Normalise the pitch vector as well (discard the energies) */
       VARDECL(celt_ener_t *bandEp);
       ALLOC(bandEp, st->mode->nbEBands*st->mode->nbChannels, celt_ener_t);
-      compute_band_energies(st->mode, freq, bandEp);
       normalise_bands(st->mode, freq, P, bandEp);
 
       if (C==2)
@@ -615,7 +613,6 @@
    {
       VARDECL(celt_ener_t *bandEp);
       ALLOC(bandEp, st->mode->nbEBands*C, celt_ener_t);
-      compute_band_energies(st->mode, freq, bandEp);
       normalise_bands(st->mode, freq, P, bandEp);
    }