Skip to content
Snippets Groups Projects
Commit cefc5ca2 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Revert "compute_band_energies() merged with normalised_bands()"

This reverts commit a1bc18a3.
I think it's easier for now to deal with two functions here, even though they
could be merged.
parent f8eb420a
No related branches found
No related tags found
No related merge requests found
......@@ -71,8 +71,8 @@ void exp_rotation(celt_norm_t *X, int len, int dir, int stride, int iter)
}
}
/* 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 @@ void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X,
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 @@ void renormalise_bands(const CELTMode *m, celt_norm_t *X)
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 @@ void renormalise_bands(const CELTMode *m, celt_norm_t *X)
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;
}
......
......@@ -43,13 +43,20 @@ exponential. The effect of this is to reduce the tonal noise created by the
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
* @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);
......
......@@ -307,6 +307,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
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 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
/* 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 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
{
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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment