[xiph-cvs] cvs commit: speex/libspeex lpc.c lpc.h nb_celp.c nb_celp.h sb_celp.c sb_celp.h

Jean-Marc Valin jm at xiph.org
Tue Oct 7 21:30:25 PDT 2003



jm          03/10/08 00:30:25

  Modified:    libspeex lpc.c lpc.h nb_celp.c nb_celp.h sb_celp.c sb_celp.h
  Log:
  fixed-point: more lpc stuff

Revision  Changes    Path
1.13      +35 -15    speex/libspeex/lpc.c

Index: lpc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lpc.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- lpc.c	8 Oct 2003 04:29:45 -0000	1.12
+++ lpc.c	8 Oct 2003 04:30:25 -0000	1.13
@@ -67,15 +67,15 @@
 #include <math.h>
 
 /* returns minimum mean square error    */
-float _spx_lpc(
+spx_word32_t _spx_lpc(
 spx_coef_t       *lpc, /* out: [0...p-1] LPC coefficients      */
-const float *ac,  /* in:  [0...p] autocorrelation values  */
+const spx_word16_t *ac,  /* in:  [0...p] autocorrelation values  */
 int          p
 )
 {
    int i, j;  
    spx_word16_t r;
-   spx_word16_t error = floor(ac[0]);
+   spx_word16_t error = ac[0];
    spx_word16_t lpcq[10];
 
    if (ac[0] == 0)
@@ -88,14 +88,14 @@
    for (i = 0; i < p; i++) {
 
       /* Sum up this iteration's reflection coefficient */
-      int rr = -8192.*floor(ac[i + 1]);
+      int rr = -ac[i + 1]<<13;
       for (j = 0; j < i; j++) 
-         rr -= lpcq[j] * floor(ac[i - j]);
+         rr -= lpcq[j] * ac[i - j];
       r = DIV32_16(rr,error+16);
 
       /*  Update LPC coefficients and total error */
       lpcq[i] = r;
-      for (j = 0; j < i/2; j++) 
+      for (j = 0; j < i>>1; j++) 
       {
          spx_word16_t tmp  = lpcq[j];
          lpcq[j]     += MULT16_16_Q13(r,lpcq[i-1-j]);
@@ -118,28 +118,48 @@
  *                      `--'
  * for lags between 0 and lag-1, and x == 0 outside 0...n-1
  */
+#include <stdio.h>
 void _spx_autocorr(
 const float *x,   /*  in: [0...n-1] samples x   */
-float       *ac,  /* out: [0...lag-1] ac values */
+spx_word16_t       *ac,  /* out: [0...lag-1] ac values */
 int          lag, 
 int          n
 )
 {
-   float d;
+   spx_word32_t d;
    int i, j;
+   spx_word32_t ac0=1;
+   int shift, ac_shift;
+   
+   for (j=0;j<n;j++)
+      ac0 += floor(x[j]*x[j])/256;
+   ac0 += n;
+   shift = 8;
+   while (shift && ac0<0x40000000)
+   {
+      shift--;
+      ac0 <<= 1;
+   }
+   ac_shift = 18;
+   while (ac_shift && ac0<0x40000000)
+   {
+      ac_shift--;
+      ac0 <<= 1;
+   }
+   
+   
    for (i=0;i<lag;i++)
    {
       d=0;
       for (j=i;j<n;j++)
       {
-         d += x[j] * x[j-i];
+         d += ((int)(floor(x[j]) * floor(x[j-i]))) >> shift;
       }
-      if (i==0)
-         ac[i] = d+.01;
-      else
-         ac[i] = 8192.*d/ac[0];
+      
+      ac[i] = d >> ac_shift;
    }
-   ac[0] = 8192.;
+   /*ac[0] = 8192.;*/
+   /*printf ("%d %d %d, %f\n", ac0, shift, ac_shift, ac[0]);*/
 }
 
 
@@ -148,7 +168,7 @@
 
 
 /* returns minimum mean square error    */
-float _spx_lpc(
+spx_word32_t _spx_lpc(
 spx_coef_t       *lpc, /* out: [0...p-1] LPC coefficients      */
 const float *ac,  /* in:  [0...p] autocorrelation values  */
 int          p

<p><p>1.7       +3 -3      speex/libspeex/lpc.h

Index: lpc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lpc.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- lpc.h	8 Oct 2003 04:27:51 -0000	1.6
+++ lpc.h	8 Oct 2003 04:30:25 -0000	1.7
@@ -37,13 +37,13 @@
 
 void _spx_autocorr(
               const float * x,   /*  in: [0...n-1] samples x   */
-              float *ac,   /* out: [0...lag-1] ac values */
+              spx_word16_t *ac,   /* out: [0...lag-1] ac values */
               int lag, int   n);
 
-float                      /* returns minimum mean square error    */
+spx_word32_t                      /* returns minimum mean square error    */
 _spx_lpc(
     spx_coef_t       * lpc, /*      [0...p-1] LPC coefficients      */
-    const float * ac,  /*  in: [0...p] autocorrelation values  */
+    const spx_word16_t * ac,  /*  in: [0...p] autocorrelation values  */
     int p
     );
 

<p><p>1.124     +1 -1      speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -r1.123 -r1.124
--- nb_celp.c	8 Oct 2003 04:29:45 -0000	1.123
+++ nb_celp.c	8 Oct 2003 04:30:25 -0000	1.124
@@ -135,7 +135,7 @@
    for (i=0;i<st->lpcSize+1;i++)
       st->lagWindow[i]=exp(-.5*sqr(2*M_PI*st->lag_factor*i));
 
-   st->autocorr = PUSH(st->stack, st->lpcSize+1, float);
+   st->autocorr = PUSH(st->stack, st->lpcSize+1, spx_word16_t);
 
    st->buf2 = PUSH(st->stack, st->windowSize, float);
 

<p><p>1.53      +1 -1      speex/libspeex/nb_celp.h

Index: nb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- nb_celp.h	8 Oct 2003 04:27:51 -0000	1.52
+++ nb_celp.h	8 Oct 2003 04:30:25 -0000	1.53
@@ -84,7 +84,7 @@
    float *innov;          /**< Innovation for the frame */
    float *window;         /**< Temporary (Hanning) window */
    float *buf2;           /**< 2nd temporary buffer */
-   float *autocorr;       /**< auto-correlation */
+   spx_word16_t *autocorr;       /**< auto-correlation */
    float *lagWindow;      /**< Window applied to auto-correlation */
    spx_coef_t *lpc;            /**< LPCs for current frame */
    float *lsp;            /**< LSPs for current frame */

<p><p>1.127     +1 -1      speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -r1.126 -r1.127
--- sb_celp.c	8 Oct 2003 04:27:51 -0000	1.126
+++ sb_celp.c	8 Oct 2003 04:30:25 -0000	1.127
@@ -190,7 +190,7 @@
    for (i=0;i<st->lpcSize+1;i++)
       st->lagWindow[i]=exp(-.5*sqr(2*M_PI*st->lag_factor*i));
 
-   st->autocorr = PUSH(st->stack, st->lpcSize+1, float);
+   st->autocorr = PUSH(st->stack, st->lpcSize+1, spx_word16_t);
    st->lpc = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
    st->bw_lpc1 = PUSH(st->stack, st->lpcSize+1, spx_coef_t);
    st->bw_lpc2 = PUSH(st->stack, st->lpcSize+1, spx_coef_t);

<p><p>1.42      +1 -1      speex/libspeex/sb_celp.h

Index: sb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- sb_celp.h	8 Oct 2003 04:27:51 -0000	1.41
+++ sb_celp.h	8 Oct 2003 04:30:25 -0000	1.42
@@ -71,7 +71,7 @@
    float *target;              /**< Weighted target signal (analysis by synthesis) */
    float *window;              /**< LPC analysis window */
    float *lagWindow;           /**< Auto-correlation window */
-   float *autocorr;            /**< Auto-correlation (for LPC analysis) */
+   spx_word16_t *autocorr;            /**< Auto-correlation (for LPC analysis) */
    spx_coef_t *lpc;                 /**< LPC coefficients */
    float *lsp;                 /**< LSP coefficients */
    float *qlsp;                /**< Quantized LSPs */

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list