[xiph-cvs] cvs commit: speex/libspeex filters.c lpc.c lsp.c misc.h modes.c nb_celp.c

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



jm          03/10/08 00:29:45

  Modified:    libspeex filters.c lpc.c lsp.c misc.h modes.c nb_celp.c
  Log:
  fixed-point: lpc stuff

Revision  Changes    Path
1.34      +5 -0      speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- filters.c	8 Oct 2003 04:27:51 -0000	1.33
+++ filters.c	8 Oct 2003 04:29:45 -0000	1.34
@@ -88,6 +88,11 @@
    
    for (i=0;i<11;i++)
    {
+      if (fabs(den[i])>3.999)
+      {
+         speex_warning_int("tata", den[i]*100);
+         den[i]=3.999;
+      }
       dens[i] = (int)floor(.5+8192*den[i]);
    }
 

<p><p>1.12      +89 -0     speex/libspeex/lpc.c

Index: lpc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lpc.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- lpc.c	8 Oct 2003 04:27:51 -0000	1.11
+++ lpc.c	8 Oct 2003 04:29:45 -0000	1.12
@@ -63,6 +63,90 @@
 
 #include "lpc.h"
 
+#ifdef FIXED_POINT
+#include <math.h>
+
+/* returns minimum mean square error    */
+float _spx_lpc(
+spx_coef_t       *lpc, /* out: [0...p-1] LPC coefficients      */
+const float *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 lpcq[10];
+
+   if (ac[0] == 0)
+   {
+      for (i = 0; i < p; i++)
+         lpc[i] = 0;
+      return 0;
+   }
+
+   for (i = 0; i < p; i++) {
+
+      /* Sum up this iteration's reflection coefficient */
+      int rr = -8192.*floor(ac[i + 1]);
+      for (j = 0; j < i; j++) 
+         rr -= lpcq[j] * floor(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++) 
+      {
+         spx_word16_t tmp  = lpcq[j];
+         lpcq[j]     += MULT16_16_Q13(r,lpcq[i-1-j]);
+         lpcq[i-1-j] += MULT16_16_Q13(r,tmp);
+      }
+      if (i & 1) 
+         lpcq[j] += MULT16_16_Q13(lpcq[j],r);
+
+      error -= MULT16_16_Q13(r,MULT16_16_Q13(error,r));
+   }
+   for (i = 0; i < p; i++)
+      lpc[i] = lpcq[i]/8192.;
+   return error;
+}
+
+
+/* Compute the autocorrelation
+ *                      ,--,
+ *              ac(i) = >  x(n) * x(n-i)  for all n
+ *                      `--'
+ * for lags between 0 and lag-1, and x == 0 outside 0...n-1
+ */
+void _spx_autocorr(
+const float *x,   /*  in: [0...n-1] samples x   */
+float       *ac,  /* out: [0...lag-1] ac values */
+int          lag, 
+int          n
+)
+{
+   float d;
+   int i, j;
+   for (i=0;i<lag;i++)
+   {
+      d=0;
+      for (j=i;j<n;j++)
+      {
+         d += x[j] * x[j-i];
+      }
+      if (i==0)
+         ac[i] = d+.01;
+      else
+         ac[i] = 8192.*d/ac[0];
+   }
+   ac[0] = 8192.;
+}
+
+
+#else
+
+
+
 /* returns minimum mean square error    */
 float _spx_lpc(
 spx_coef_t       *lpc, /* out: [0...p-1] LPC coefficients      */
@@ -125,4 +209,9 @@
          d += x[i] * x[i-lag];
       ac[lag] = d;
    }
+   ac[0] += 10;
 }
+
+#endif
+
+

<p><p>1.26      +2 -8      speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- lsp.c	8 Oct 2003 04:29:00 -0000	1.25
+++ lsp.c	8 Oct 2003 04:29:45 -0000	1.26
@@ -67,16 +67,10 @@
 
 \*---------------------------------------------------------------------------*/
 
+#undef FIXED_POINT
 
 #ifdef FIXED_POINT
 
-#define SCALE1 8192.
-#define SCALE2 16384.
-#define SCALE 16384.
-
-#include <stdio.h>
-
-
 static float cheb_poly_eva(float *coef,float x,int m,char *stack)
 /*  float coef[]  	coefficients of the polynomial to be evaluated 	*/
 /*  float x   		the point where polynomial is to be evaluated 	*/
@@ -299,7 +293,7 @@
 
 \*---------------------------------------------------------------------------*/
 
-#if FIXED_POINT
+#ifdef FIXED_POINT
 
 void lsp_to_lpc(float *freq,spx_coef_t *ak,int lpcrdr, char *stack)
 /*  float *freq 	array of LSP frequencies in the x domain	*/

<p><p>1.23      +3 -0      speex/libspeex/misc.h

Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- misc.h	8 Oct 2003 04:29:00 -0000	1.22
+++ misc.h	8 Oct 2003 04:29:45 -0000	1.23
@@ -63,6 +63,9 @@
 
 #define MULT16_16_P14(a,b) ((8192+((signed int)(a))*(b))>>14)
 
+
+#define DIV32_16(a,b) (((signed int)(a))/(b))
+
 #else
 
 typedef float spx_mem_t;

<p><p>1.107     +2 -2      speex/libspeex/modes.c

Index: modes.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/modes.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -r1.106 -r1.107
--- modes.c	3 Jun 2003 05:29:19 -0000	1.106
+++ modes.c	8 Oct 2003 04:29:45 -0000	1.107
@@ -350,8 +350,8 @@
    144,    /*pitchEnd*/
    0.9,    /*gamma1*/
    0.6,    /*gamma2*/
-   .01,   /*lag_factor*/
-   1.0001, /*lpc_floor*/
+   .012,   /*lag_factor*/
+   1.0002, /*lpc_floor*/
    0.0,    /*preemph*/
 #ifdef EPIC_48K
    0,

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

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -r1.122 -r1.123
--- nb_celp.c	8 Oct 2003 04:27:51 -0000	1.122
+++ nb_celp.c	8 Oct 2003 04:29:45 -0000	1.123
@@ -235,7 +235,6 @@
    /* Compute auto-correlation */
    _spx_autocorr(st->buf2, st->autocorr, st->lpcSize+1, st->windowSize);
 
-   st->autocorr[0] += 10;        /* prevents NANs */
    st->autocorr[0] *= st->lpc_floor; /* Noise floor in auto-correlation domain */
 
    /* Lag windowing: equivalent to filtering in the power-spectrum domain */

<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