fixed-point: celt_sig_t now a 32-bit value.
authorJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Mon, 25 Feb 2008 03:55:09 +0000 (14:55 +1100)
committerJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Mon, 25 Feb 2008 03:55:09 +0000 (14:55 +1100)
libcelt/arch.h
libcelt/bands.c
libcelt/celt.c
libcelt/pitch.c

index 76ef86f..519b7f8 100644 (file)
@@ -51,7 +51,7 @@
 typedef celt_int16_t celt_word16_t;
 typedef celt_int32_t celt_word32_t;
 
-typedef float celt_sig_t;
+typedef celt_word32_t celt_sig_t;
 typedef float celt_norm_t;
 
 #define Q15ONE 32767
index dc94e3d..448abf3 100644 (file)
@@ -83,7 +83,7 @@ void compute_band_energies(const CELTMode *m, celt_sig_t *X, float *bank)
          int j;
          float sum = 1e-10;
          for (j=B*eBands[i];j<B*eBands[i+1];j++)
-            sum += X[j*C+c]*X[j*C+c];
+            sum += SIG_SCALING_1*SIG_SCALING_1*X[j*C+c]*X[j*C+c];
          bank[i*C+c] = sqrt(C*sum);
          /*printf ("%f ", bank[i*C+c]);*/
       }
@@ -105,7 +105,7 @@ void normalise_bands(const CELTMode *m, celt_sig_t *freq, celt_norm_t *X, float
          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] = freq[j*C+c]*g;
+            X[j*C+c] = 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 @@ void denormalise_bands(const CELTMode *m, celt_norm_t *X, celt_sig_t *freq, floa
          int j;
          float g = bank[i*C+c];
          for (j=B*eBands[i];j<B*eBands[i+1];j++)
-            freq[j*C+c] = X[j*C+c] * g;
+            freq[j*C+c] = SIG_SCALING*X[j*C+c] * g;
       }
    }
    for (i=B*C*eBands[m->nbEBands];i<B*C*eBands[m->nbEBands+1];i++)
index 156716c..7b8cac3 100644 (file)
@@ -177,13 +177,13 @@ static float compute_mdcts(mdct_lookup *mdct_lookup, float *window, celt_sig_t *
          int j;
          for (j=0;j<2*N;j++)
          {
-            x[j] = SIG_SCALING*window[j]*in[C*i*N+C*j+c];
+            x[j] = window[j]*in[C*i*N+C*j+c];
             E += SIG_SCALING_1*SIG_SCALING_1*x[j]*x[j];
          }
          mdct_forward(mdct_lookup, x, tmp);
          /* Interleaving the sub-frames */
          for (j=0;j<N;j++)
-            out[C*B*j+C*i+c] = SIG_SCALING_1*tmp[j];
+            out[C*B*j+C*i+c] = tmp[j];
       }
    }
    return E;
@@ -205,16 +205,16 @@ static void compute_inv_mdcts(mdct_lookup *mdct_lookup, float *window, celt_sig_
          int j;
          /* De-interleaving the sub-frames */
          for (j=0;j<N;j++)
-            tmp[j] = SIG_SCALING*X[C*B*j+C*i+c];
+            tmp[j] = X[C*B*j+C*i+c];
          mdct_backward(mdct_lookup, tmp, x);
          for (j=0;j<2*N;j++)
             x[j] = window[j]*x[j];
          for (j=0;j<overlap;j++)
-            out_mem[C*(MAX_PERIOD+(i-B)*N)+C*j+c] = 2*(SIG_SCALING_1*x[N4+j]+mdct_overlap[C*j+c]);
+            out_mem[C*(MAX_PERIOD+(i-B)*N)+C*j+c] = 2*(x[N4+j]+mdct_overlap[C*j+c]);
          for (j=0;j<2*N4;j++)
-            out_mem[C*(MAX_PERIOD+(i-B)*N)+C*(j+overlap)+c] = 2*SIG_SCALING_1*x[j+N4+overlap];
+            out_mem[C*(MAX_PERIOD+(i-B)*N)+C*(j+overlap)+c] = 2*x[j+N4+overlap];
          for (j=0;j<overlap;j++)
-            mdct_overlap[C*j+c] = SIG_SCALING_1*x[N+N4+j];
+            mdct_overlap[C*j+c] = x[N+N4+j];
       }
    }
 }
@@ -257,7 +257,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
          in[C*(i+N4)+c] = st->in_mem[C*i+c];
       for (i=0;i<B*N;i++)
       {
-         float tmp = pcm[C*i+c];
+         float tmp = SIG_SCALING*pcm[C*i+c];
          in[C*(i+st->overlap+N4)+c] = tmp - st->preemph*st->preemph_memE[c];
          st->preemph_memE[c] = tmp;
       }
@@ -384,6 +384,7 @@ int celt_encode(CELTEncoder *st, celt_int16_t *pcm, unsigned char *compressed, i
          {
             float tmp = st->out_mem[C*(MAX_PERIOD+(i-B)*N)+C*j+c] + st->preemph*st->preemph_memD[c];
             st->preemph_memD[c] = tmp;
+            tmp *= SIG_SCALING_1;
             if (tmp > 32767) tmp = 32767;
             if (tmp < -32767) tmp = -32767;
             pcm[C*i*N+C*j+c] = (short)floor(.5+tmp);
@@ -558,6 +559,7 @@ static void celt_decode_lost(CELTDecoder *st, short *pcm)
          {
             float tmp = st->out_mem[C*(MAX_PERIOD+(i-B)*N)+C*j+c] + st->preemph*st->preemph_memD[c];
             st->preemph_memD[c] = tmp;
+            tmp *= SIG_SCALING_1;
             if (tmp > 32767) tmp = 32767;
             if (tmp < -32767) tmp = -32767;
             pcm[C*i*N+C*j+c] = (short)floor(.5+tmp);
@@ -660,6 +662,7 @@ int celt_decode(CELTDecoder *st, unsigned char *data, int len, celt_int16_t *pcm
          {
             float tmp = st->out_mem[C*(MAX_PERIOD+(i-B)*N)+C*j+c] + st->preemph*st->preemph_memD[c];
             st->preemph_memD[c] = tmp;
+            tmp *= SIG_SCALING_1;
             if (tmp > 32767) tmp = 32767;
             if (tmp < -32767) tmp = -32767;
             pcm[C*i*N+C*j+c] = (short)floor(.5+tmp);
index 54e87d2..80bceb6 100644 (file)
@@ -65,9 +65,9 @@ void find_spectral_pitch(kiss_fftr_cfg fft, struct PsyDecay *decay, celt_sig_t *
    for (c=0;c<C;c++)
    {
       for (i=0;i<len;i++)
-         xx[c*lag+i] = SIG_SCALING*x[C*i+c];
+         xx[c*lag+i] = x[C*i+c];
       for (i=0;i<lag;i++)
-         yy[c*lag+i] = SIG_SCALING*y[C*i+c];
+         yy[c*lag+i] = y[C*i+c];
       
    }