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.
This commit is contained in:
parent
0668b8ea5e
commit
000973f7e2
1 changed files with 40 additions and 10 deletions
|
@ -71,6 +71,10 @@ void exp_rotation(celt_norm_t *X, int len, int dir, int stride, int iter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
/* 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)
|
void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *bank)
|
||||||
{
|
{
|
||||||
|
@ -83,19 +87,27 @@ void compute_band_energies(const CELTMode *m, const celt_sig_t *X, celt_ener_t *
|
||||||
for (i=0;i<m->nbEBands;i++)
|
for (i=0;i<m->nbEBands;i++)
|
||||||
{
|
{
|
||||||
int j;
|
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++)
|
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];
|
maxval = MAX32(maxval, ABS32(X[j*C+c]));
|
||||||
bank[i*C+c] = ENER_SCALING*sqrt(sum);
|
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]);*/
|
/*printf ("%f ", bank[i*C+c]);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*printf ("\n");*/
|
/*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. */
|
/* 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)
|
void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
|
||||||
{
|
{
|
||||||
|
@ -139,6 +151,28 @@ void renormalise_bands(const CELTMode *m, celt_norm_t *X)
|
||||||
RESTORE_STACK;
|
RESTORE_STACK;
|
||||||
}
|
}
|
||||||
#else
|
#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. */
|
/* 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)
|
void normalise_bands(const CELTMode *m, const celt_sig_t *freq, celt_norm_t *X, const celt_ener_t *bank)
|
||||||
{
|
{
|
||||||
|
@ -284,8 +318,6 @@ void quant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, celt_mask_t
|
||||||
int q;
|
int q;
|
||||||
celt_word16_t n;
|
celt_word16_t n;
|
||||||
q = pulses[i];
|
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);
|
n = SHL16(celt_sqrt(B*(eBands[i+1]-eBands[i])),11);
|
||||||
|
|
||||||
/* If pitch isn't available, use intra-frame prediction */
|
/* If pitch isn't available, use intra-frame prediction */
|
||||||
|
@ -345,8 +377,6 @@ void unquant_bands(const CELTMode *m, celt_norm_t *X, celt_norm_t *P, int total_
|
||||||
int q;
|
int q;
|
||||||
celt_word16_t n;
|
celt_word16_t n;
|
||||||
q = pulses[i];
|
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);
|
n = SHL16(celt_sqrt(B*(eBands[i+1]-eBands[i])),11);
|
||||||
|
|
||||||
/* If pitch isn't available, use intra-frame prediction */
|
/* If pitch isn't available, use intra-frame prediction */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue