ref: 000973f7e2ecc621d16761e65cd20e6a1e5055e9
parent: 0668b8ea5e6608101d6faeb28fa3a483c4a52475
author: Jean-Marc Valin <[email protected]>
date: Fri Mar 7 11:42:31 EST 2008
fixed-point: compute_band_energies() converted. Had to add some tiny bias to make sure never to end up with a pitch vector with >1 norm.
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -71,6 +71,10 @@
}
}
+
+const celt_word16_t sqrtC_1[2] = {QCONST16(1.f, 14), QCONST16(1.414214f, 14)};
+
+#ifdef FIXED_POINT
/* 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)
{
@@ -83,10 +87,21 @@
for (i=0;i<m->nbEBands;i++)
{
int j;
- float sum = 1e-10;
+ celt_word32_t maxval=0;
+ celt_word32_t sum = 0;
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];
- bank[i*C+c] = ENER_SCALING*sqrt(sum);
+ maxval = MAX32(maxval, ABS32(X[j*C+c]));
+ if (maxval > 0)
+ {
+ int shift = celt_ilog2(maxval)-10;
+ for (j=B*eBands[i];j<B*eBands[i+1];j++)
+ sum += VSHR32(X[j*C+c],shift)*VSHR32(X[j*C+c],shift);
+ /* 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] = 1+VSHR32(EXTEND32(celt_sqrt(sum)),-shift);
+ } else {
+ bank[i*C+c] = 0;
+ }
/*printf ("%f ", bank[i*C+c]);*/
}
}
@@ -93,9 +108,6 @@
/*printf ("\n");*/
}
-const celt_word16_t sqrtC_1[2] = {QCONST16(1.f, 14), QCONST16(1.414214f, 14)};
-
-#ifdef FIXED_POINT
/* 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)
{
@@ -139,6 +151,28 @@
RESTORE_STACK;
}
#else
+/* 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;
+ B = m->nbMdctBlocks;
+ C = m->nbChannels;
+ for (c=0;c<C;c++)
+ {
+ for (i=0;i<m->nbEBands;i++)
+ {
+ int j;
+ 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];
+ 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)
{
@@ -284,8 +318,6 @@
int q;
celt_word16_t n;
q = pulses[i];
- /*Scale factor of .0625f is just there to prevent overflows in fixed-point
- (has no effect on float)*/
n = SHL16(celt_sqrt(B*(eBands[i+1]-eBands[i])),11);
/* If pitch isn't available, use intra-frame prediction */
@@ -345,8 +377,6 @@
int q;
celt_word16_t n;
q = pulses[i];
- /*Scale factor of .0625f is just there to prevent overflows in fixed-point
- (has no effect on float)*/
n = SHL16(celt_sqrt(B*(eBands[i+1]-eBands[i])),11);
/* If pitch isn't available, use intra-frame prediction */