ref: b4dfce46658ca9847b3f7b93efeba37ebbcd0cf1
parent: 5c032a4cb4620d5a1dad7eadb5e3d90a962a5256
author: Jean-Marc Valin <[email protected]>
date: Mon Feb 25 12:41:30 EST 2008
fixed-point: Using a NORM_SCALING of 16384, sig_norm_t is still a float though.
--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -59,6 +59,8 @@
#define LPC_SCALING 8192
#define SIG_SCALING 16384.f
#define SIG_SCALING_1 0.000061035
+#define NORM_SCALING 16384.f
+#define NORM_SCALING_1 0.000061035
#define LSP_SCALING 8192.
#define GAMMA_SCALING 32768.
@@ -105,6 +107,9 @@
#define LPC_SCALING 1.f
#define SIG_SCALING 1.f
#define SIG_SCALING_1 1.f
+#define NORM_SCALING 1.f
+#define NORM_SCALING_1 1.f
+
#define LSP_SCALING 1.f
#define GAMMA_SCALING 1.f
#define GAIN_SCALING 1.f
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -105,7 +105,7 @@
int j;
float g = 1.f/(1e-10+bank[i*C+c]);
for (j=B*eBands[i];j<B*eBands[i+1];j++)
- X[j*C+c] = SIG_SCALING_1*freq[j*C+c]*g;
+ X[j*C+c] = NORM_SCALING*SIG_SCALING_1*freq[j*C+c]*g;
}
}
for (i=B*C*eBands[m->nbEBands];i<B*C*eBands[m->nbEBands+1];i++)
@@ -135,7 +135,7 @@
int j;
float g = bank[i*C+c];
for (j=B*eBands[i];j<B*eBands[i+1];j++)
- freq[j*C+c] = SIG_SCALING*X[j*C+c] * g;
+ freq[j*C+c] = NORM_SCALING_1*SIG_SCALING*X[j*C+c] * g;
}
}
for (i=B*C*eBands[m->nbEBands];i<B*C*eBands[m->nbEBands+1];i++)
@@ -168,10 +168,10 @@
float gain;
for (j=B*pBands[i];j<B*pBands[i+1];j++)
{
- Sxy += X[j]*P[j]*w[j];
- Sxx += X[j]*X[j]*w[j];
+ Sxy += 1.f*X[j]*P[j]*w[j];
+ Sxx += 1.f*X[j]*X[j]*w[j];
}
- gain = Sxy/(1e-10+Sxx);
+ gain = Sxy/(1e-10*NORM_SCALING*NORM_SCALING+Sxx);
if (gain > 1.f)
gain = 1.f;
if (gain < 0.0f)
--- a/libcelt/mdct.c
+++ b/libcelt/mdct.c
@@ -64,7 +64,7 @@
N2 = N/2;
N4 = N/4;
l->kfft = kiss_fft_alloc(N4, NULL, NULL);
- l->trig = celt_alloc(N2*sizeof(float));
+ l->trig = (kiss_twiddle_scalar*)celt_alloc(N2*sizeof(kiss_twiddle_scalar));
/* We have enough points that sine isn't necessary */
#if defined(FIXED_POINT)
#if defined(DOUBLE_PRECISION) & !defined(MIXED_PRECISION)
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -106,6 +106,12 @@
ALLOC(_nbest, L, struct NBest);
ALLOC(nbest, L, struct NBest *);
+ for (j=0;j<N;j++)
+ {
+ x[j] *= NORM_SCALING_1;
+ p[j] *= NORM_SCALING_1;
+ }
+
for (m=0;m<L;m++)
nbest[m] = &_nbest[m];
@@ -301,6 +307,11 @@
x[i] = p[i] + g*y[0][i];
}
+ for (j=0;j<N;j++)
+ {
+ x[j] *= NORM_SCALING;
+ p[j] *= NORM_SCALING;
+ }
}
@@ -318,6 +329,11 @@
ALLOC(y, N, float);
decode_pulses(iy, N, K, dec);
+ for (i=0;i<N;i++)
+ {
+ x[i] *= NORM_SCALING_1;
+ p[i] *= NORM_SCALING_1;
+ }
/*for (i=0;i<N;i++)
printf ("%d ", iy[i]);*/
@@ -342,6 +358,12 @@
for (i=0;i<N;i++)
x[i] = p[i] + g*y[i];
+ for (i=0;i<N;i++)
+ {
+ x[i] *= NORM_SCALING;
+ p[i] *= NORM_SCALING;
+ }
+
}
@@ -367,8 +389,8 @@
float score;
for (j=0;j<N;j++)
{
- xy += x[j]*Y[i+N-j-1];
- yy += Y[i+N-j-1]*Y[i+N-j-1];
+ xy += 1.f*x[j]*Y[i+N-j-1];
+ yy += 1.f*Y[i+N-j-1]*Y[i+N-j-1];
}
score = xy*xy/(.001+yy);
if (score > best_score)
@@ -398,7 +420,7 @@
for (j=0;j<N;j++)
{
P[j] = s*Y[best+N-j-1];
- E += P[j]*P[j];
+ E += NORM_SCALING_1*NORM_SCALING_1*P[j]*P[j];
}
E = pred_gain/sqrt(E);
for (j=0;j<N;j++)
@@ -445,7 +467,7 @@
for (j=0;j<N;j++)
{
P[j] = s*Y[best+N-j-1];
- E += P[j]*P[j];
+ E += NORM_SCALING_1*NORM_SCALING_1*P[j]*P[j];
}
E = pred_gain/sqrt(E);
for (j=0;j<N;j++)
@@ -470,7 +492,7 @@
for (j=0;j<N/B;j++)
{
P[j*B+i] = Y[(Nmax-N0-j-1)*B+i];
- E += P[j*B+i]*P[j*B+i];
+ E += NORM_SCALING_1*NORM_SCALING_1*P[j*B+i]*P[j*B+i];
}
}
} else {
@@ -477,7 +499,7 @@
for (j=0;j<N;j++)
{
P[j] = Y[j];
- E += P[j]*P[j];
+ E += NORM_SCALING_1*NORM_SCALING_1*P[j]*P[j];
}
}
E = 1.f/sqrt(E);