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

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



jm          03/10/08 00:33:37

  Modified:    libspeex filters.c lpc.c lsp.c modes.c sb_celp.c
  Log:
  fixed-point: more LPC/LSP cleanup

Revision  Changes    Path
1.36      +6 -30     speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- filters.c	8 Oct 2003 04:31:40 -0000	1.35
+++ filters.c	8 Oct 2003 04:33:36 -0000	1.36
@@ -57,13 +57,6 @@
 {
    int i,j;
    int xi,yi;
-   short nums[11], dens[11];
-   
-   for (i=0;i<ord+1;i++)
-   {
-      nums[i] = (int)floor(.5+num[i]);
-      dens[i] = (int)floor(.5+den[i]);
-   }
 
    for (i=0;i<N;i++)
    {
@@ -73,9 +66,9 @@
       xh = xi>>15; xl=xi&0x00007fff; yh = yi>>15; yl=yi&0x00007fff; 
       for (j=0;j<ord-1;j++)
       {
-         mem[j] = mem[j+1] +  MUL_16_32_R15(nums[j+1],xh,xl) - MUL_16_32_R15(dens[j+1],yh,yl);
+         mem[j] = mem[j+1] +  MUL_16_32_R15(num[j+1],xh,xl) - MUL_16_32_R15(den[j+1],yh,yl);
       }
-      mem[ord-1] = MUL_16_32_R15(nums[ord],xh,xl) - MUL_16_32_R15(dens[ord],yh,yl);
+      mem[ord-1] = MUL_16_32_R15(num[ord],xh,xl) - MUL_16_32_R15(den[ord],yh,yl);
       y[i] = yi*(1.f/16384.f);
    }
 }
@@ -84,18 +77,7 @@
 {
    int i,j;
    int xi,yi;
-   short dens[11];
    
-   for (i=0;i<11;i++)
-   {
-      if (fabs(den[i])>3.999*8192)
-      {
-         speex_warning_int("tata", den[i]*100);
-         den[i]=3.999*8192;
-      }
-      dens[i] = (int)floor(.5+den[i]);
-   }
-
    for (i=0;i<N;i++)
    {
       int yh,yl;
@@ -104,9 +86,9 @@
       yh = yi>>15; yl=yi&0x00007fff; 
       for (j=0;j<ord-1;j++)
       {
-         mem[j] = mem[j+1] - MUL_16_32_R15(dens[j+1],yh,yl);
+         mem[j] = mem[j+1] - MUL_16_32_R15(den[j+1],yh,yl);
       }
-      mem[ord-1] = - MUL_16_32_R15(dens[ord],yh,yl);
+      mem[ord-1] = - MUL_16_32_R15(den[ord],yh,yl);
       y[i] = yi*(1.f/16384.f);
    }
 }
@@ -116,12 +98,6 @@
 {
    int i,j;
    int xi,yi;
-   short nums[11];
-   
-   for (i=0;i<11;i++)
-   {
-      nums[i] = (int)floor(.5+num[i]);
-   }
 
    for (i=0;i<N;i++)
    {
@@ -131,9 +107,9 @@
       xh = xi>>15; xl=xi&0x00007fff;
       for (j=0;j<ord-1;j++)
       {
-         mem[j] = mem[j+1] +  MUL_16_32_R15(nums[j+1],xh,xl);
+         mem[j] = mem[j+1] +  MUL_16_32_R15(num[j+1],xh,xl);
       }
-      mem[ord-1] = MUL_16_32_R15(nums[ord],xh,xl);
+      mem[ord-1] = MUL_16_32_R15(num[ord],xh,xl);
       y[i] = yi*(1.f/16384.f);
    }
 

<p><p>1.15      +7 -10     speex/libspeex/lpc.c

Index: lpc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lpc.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- lpc.c	8 Oct 2003 04:31:40 -0000	1.14
+++ lpc.c	8 Oct 2003 04:33:36 -0000	1.15
@@ -76,7 +76,6 @@
    int i, j;  
    spx_word16_t r;
    spx_word16_t error = ac[0];
-   spx_word16_t lpcq[10];
 
    if (ac[0] == 0)
    {
@@ -90,24 +89,22 @@
       /* Sum up this iteration's reflection coefficient */
       int rr = -ac[i + 1]<<13;
       for (j = 0; j < i; j++) 
-         rr -= lpcq[j] * ac[i - j];
+         rr -= lpc[j] * ac[i - j];
       r = DIV32_16(rr,error+16);
 
       /*  Update LPC coefficients and total error */
-      lpcq[i] = r;
+      lpc[i] = r;
       for (j = 0; j < i>>1; 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);
+         spx_word16_t tmp  = lpc[j];
+         lpc[j]     += MULT16_16_Q13(r,lpc[i-1-j]);
+         lpc[i-1-j] += MULT16_16_Q13(r,tmp);
       }
       if (i & 1) 
-         lpcq[j] += MULT16_16_Q13(lpcq[j],r);
+         lpc[j] += MULT16_16_Q13(lpc[j],r);
 
       error -= MULT16_16_Q13(r,MULT16_16_Q13(error,r));
    }
-   for (i = 0; i < p; i++)
-      lpc[i] = lpcq[i];
    return error;
 }
 
@@ -158,7 +155,7 @@
       
       ac[i] = d >> ac_shift;
    }
-   /*ac[0] = 8192.;*/
+   /*ac[0] += 1;*/
    /*printf ("%d %d %d, %f\n", ac0, shift, ac_shift, ac[0]);*/
 }
 

<p><p>1.29      +42 -16    speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- lsp.c	8 Oct 2003 04:32:24 -0000	1.28
+++ lsp.c	8 Oct 2003 04:33:36 -0000	1.29
@@ -69,7 +69,7 @@
 
 #ifdef FIXED_POINT
 
-static float cheb_poly_eva(float *coef,float x,int m,char *stack)
+static float cheb_poly_eva(spx_word32_t *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 	*/
 /*  int m 		order of the polynomial 			*/
@@ -89,7 +89,7 @@
     
     for (i=0;i<m2+1;i++)
     {
-       coefn[i] = floor(.5+1024*coef[i]);
+       coefn[i] = coef[i];
        /*printf ("%f ", coef[i]);*/
     }
     /*printf ("\n");*/
@@ -113,7 +113,7 @@
     return sum;
 }
 #else
-static float cheb_poly_eva(float *coef,float x,int m,char *stack)
+static float cheb_poly_eva(spx_word32_t *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 	*/
 /*  int m 		order of the polynomial 			*/
@@ -169,13 +169,13 @@
     float psuml,psumr,psumm,temp_xr,xl,xr,xm=0;
     float temp_psumr/*,temp_qsumr*/;
     int i,j,m,flag,k;
-    float *Q;                 	/* ptrs for memory allocation 		*/
-    float *P;
-    float *px;                	/* ptrs of respective P'(z) & Q'(z)	*/
-    float *qx;
-    float *p;
-    float *q;
-    float *pt;                	/* ptr used for cheb_poly_eval()
+    spx_word32_t *Q;                 	/* ptrs for memory allocation 		*/
+    spx_word32_t *P;
+    spx_word32_t *px;                	/* ptrs of respective P'(z) & Q'(z)	*/
+    spx_word32_t *qx;
+    spx_word32_t *p;
+    spx_word32_t *q;
+    spx_word32_t *pt;                	/* ptr used for cheb_poly_eval()
                                 whether P' or Q' 			*/
     int roots=0;              	/* DR 8/2/94: number of roots found 	*/
     flag = 1;                	/*  program is searching for a root when,
@@ -184,8 +184,8 @@
 
 
     /* Allocate memory space for polynomials */
-    Q = PUSH(stack, (m+1), float);
-    P = PUSH(stack, (m+1), float);
+    Q = PUSH(stack, (m+1), spx_word32_t);
+    P = PUSH(stack, (m+1), spx_word32_t);
 
     /* determine P'(z)'s and Q'(z)'s coefficients where
       P'(z) = P(z)/(1 + z^(-1)) and Q'(z) = Q(z)/(1-z^(-1)) */
@@ -194,11 +194,35 @@
     qx = Q;
     p = px;
     q = qx;
-    *px++ = 1.0;
-    *qx++ = 1.0;
+
+#ifdef FIXED_POINT
+    *px++ = LPC_SCALING;
+    *qx++ = LPC_SCALING;
     for(i=1;i<=m;i++){
-	*px++ = (a[i]+a[lpcrdr+1-i])/LPC_SCALING - *p++;
-	*qx++ = (a[i]-a[lpcrdr+1-i])/LPC_SCALING + *q++;
+	*px++ = (a[i]+a[lpcrdr+1-i]) - *p++;
+	*qx++ = (a[i]-a[lpcrdr+1-i]) + *q++;
+    }
+    px = P;
+    qx = Q;
+    for(i=0;i<m;i++)
+    {
+       /*if (fabs(*px)>=32768)
+          speex_warning_int("px", *px);
+       if (fabs(*qx)>=32768)
+       speex_warning_int("qx", *qx);*/
+       *px = (2+*px)>>2;
+       *qx = (2+*qx)>>2;
+       px++;
+       qx++;
+    }
+    P[m] = (4+P[m])>>3;
+    Q[m] = (4+Q[m])>>3;
+#else
+    *px++ = LPC_SCALING;
+    *qx++ = LPC_SCALING;
+    for(i=1;i<=m;i++){
+	*px++ = (a[i]+a[lpcrdr+1-i]) - *p++;
+	*qx++ = (a[i]-a[lpcrdr+1-i]) + *q++;
     }
     px = P;
     qx = Q;
@@ -208,6 +232,8 @@
          px++;
          qx++;
     }
+#endif
+
     px = P;             	/* re-initialise ptrs 			*/
     qx = Q;
 

<p><p>1.108     +1 -1      speex/libspeex/modes.c

Index: modes.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/modes.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- modes.c	8 Oct 2003 04:29:45 -0000	1.107
+++ modes.c	8 Oct 2003 04:33:36 -0000	1.108
@@ -479,7 +479,7 @@
    640,    /*bufSize*/
    .9,    /*gamma1*/
    0.6,    /*gamma2*/
-   .002,   /*lag_factor*/
+   .001,   /*lag_factor*/
    1.0001, /*lpc_floor*/
    0.0,    /*preemph*/
    0.9,

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

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -r1.128 -r1.129
--- sb_celp.c	8 Oct 2003 04:32:24 -0000	1.128
+++ sb_celp.c	8 Oct 2003 04:33:36 -0000	1.129
@@ -282,7 +282,6 @@
    /* Compute auto-correlation */
    _spx_autocorr(st->buf, st->autocorr, st->lpcSize+1, st->windowSize);
 
-   st->autocorr[0] += 1;        /* prevents NANs */
    st->autocorr[0] *= st->lpc_floor; /* Noise floor in auto-correlation domain */
    /* Lag windowing: equivalent to filtering in the power-spectrum domain */
    for (i=0;i<st->lpcSize+1;i++)

<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