ref: cefc5ca26de662e7f506e41ba85413313418d5c7
parent: f8eb420a09a1c57430505f52f282c7ed5b225db3
author: Jean-Marc Valin <[email protected]>
date: Fri Mar 7 09:53:17 EST 2008
Revert "compute_band_energies() merged with normalised_bands()" This reverts commit a1bc18a38836e2b1360a26a1d7ef2571b2f3b694. I think it's easier for now to deal with two functions here, even though they could be merged.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -71,8 +71,8 @@
}
}
-/* 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)
+/* 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)
{
int i, c, B, C;
const int *eBands = m->eBands;
@@ -83,12 +83,29 @@
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*freq[j*C+c]*freq[j*C+c];
+ sum += SIG_SCALING_1*SIG_SCALING_1*X[j*C+c]*X[j*C+c];
bank[i*C+c] = ENER_SCALING*sqrt(sum);
- g = 1.f/(1e-10+ENER_SCALING_1*bank[i*C+c]*sqrt(C));
+ /*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));
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;
}
@@ -108,6 +125,7 @@
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;
}
@@ -117,6 +135,7 @@
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,6 +43,13 @@
sparse spectrum resulting from the pulse codebook */
void exp_rotation(celt_norm_t *X, int len, 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
@@ -49,7 +56,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, celt_ener_t *bands);
+void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bands);
void renormalise_bands(const CELTMode *m, celt_norm_t *X);
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -307,6 +307,7 @@
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");*/
@@ -328,6 +329,7 @@
/* 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)
@@ -612,6 +614,7 @@
{
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);
}