[xiph-cvs] cvs commit: speex/libspeex filters.c ltp.c smallft.c

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



jm          03/10/08 00:57:58

  Modified:    libspeex filters.c ltp.c smallft.c
  Log:
  fixed-point: normalization function, some work on pitch closed-loop search

Revision  Changes    Path
1.44      +28 -0     speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- filters.c	8 Oct 2003 04:56:09 -0000	1.43
+++ filters.c	8 Oct 2003 04:57:58 -0000	1.44
@@ -49,6 +49,34 @@
 
 #ifdef FIXED_POINT
 
+int normalize16(spx_sig_t *x, spx_word16_t *y, int max_scale, int len)
+{
+   int i;
+   spx_sig_t max_val=1;
+   int sig_shift;
+   
+   for (i=0;i<len;i++)
+   {
+      spx_sig_t tmp = x[i];
+      if (tmp<0)
+         tmp = -tmp;
+      if (tmp > max_val)
+         max_val = tmp;
+   }
+
+   sig_shift=0;
+   while (max_val>max_scale)
+   {
+      sig_shift++;
+      max_val >>= 1;
+   }
+
+   for (i=0;i<len;i++)
+      y[i] = SHR(x[i], sig_shift);
+   
+   return sig_shift;
+}
+
 spx_word16_t compute_rms(spx_sig_t *x, int len)
 {
    int i;

<p><p>1.83      +73 -27    speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- ltp.c	8 Oct 2003 04:56:09 -0000	1.82
+++ ltp.c	8 Oct 2003 04:57:58 -0000	1.83
@@ -40,7 +40,7 @@
 
 #ifdef FIXED_POINT
 
-static spx_word32_t inner_prod2(spx_word16_t *x, spx_word16_t *y, int len)
+static spx_word32_t inner_prod(spx_word16_t *x, spx_word16_t *y, int len)
 {
    int i;
    spx_word32_t sum=0;
@@ -56,22 +56,6 @@
    return sum;
 }
 
-
-static float inner_prod(spx_sig_t *x, spx_sig_t *y, int len)
-{
-   int i;
-   float sum1=0,sum2=0,sum3=0,sum4=0;
-   for (i=0;i<len;)
-   {
-      sum1 += x[i]*y[i];
-      sum2 += x[i+1]*y[i+1];
-      sum3 += x[i+2]*y[i+2];
-      sum4 += x[i+3]*y[i+3];
-      i+=4;
-   }
-   return sum1+sum2+sum3+sum4;
-}
-
 void open_loop_nbest_pitch(spx_sig_t *sw, int start, int end, int len, int *pitch, float *gain, int N, char *stack)
 {
    int i,j,k;
@@ -118,8 +102,8 @@
    }
 
 
-   energy[0]=inner_prod2(swn-start, swn-start, len);
-   e0=inner_prod2(swn, swn, len);
+   energy[0]=inner_prod(swn-start, swn-start, len);
+   e0=inner_prod(swn, swn, len);
    for (i=start;i<=end;i++)
    {
       /* Update energy for next pitch*/
@@ -134,7 +118,7 @@
    for (i=start;i<=end;i++)
    {
       /* Compute correlation*/
-      corr[i-start]=inner_prod2(swn, swn-i, len);
+      corr[i-start]=inner_prod(swn, swn-i, len);
       score[i-start]=1.*corr[i-start]*corr[i-start]/(energy[i-start]+1.);
    }
    for (i=start;i<=end;i++)
@@ -349,13 +333,75 @@
       }
    }
 
-   for (i=0;i<3;i++)
-      corr[i]=inner_prod(x[i],target,nsf);
-   
-   for (i=0;i<3;i++)
-      for (j=0;j<=i;j++)
-         A[i][j]=A[j][i]=inner_prod(x[i],x[j],nsf);
-   
+#ifdef FIXED_POINT
+   {
+      spx_word16_t *y[3];
+      spx_word16_t *t;
+
+      spx_sig_t max_val=1;
+      int sig_shift;
+      
+      y[0] = PUSH(stack, nsf, spx_word16_t);
+      y[1] = PUSH(stack, nsf, spx_word16_t);
+      y[2] = PUSH(stack, nsf, spx_word16_t);
+      t = PUSH(stack, nsf, spx_word16_t);
+      for (j=0;j<3;j++)
+      {
+         for (i=0;i<nsf;i++)
+         {
+            spx_sig_t tmp = x[j][i];
+            if (tmp<0)
+               tmp = -tmp;
+            if (tmp > max_val)
+               max_val = tmp;
+         }
+      }
+      for (i=0;i<nsf;i++)
+      {
+         spx_sig_t tmp = target[i];
+         if (tmp<0)
+            tmp = -tmp;
+         if (tmp > max_val)
+            max_val = tmp;
+      }
+
+      sig_shift=0;
+      while (max_val>16384)
+      {
+         sig_shift++;
+         max_val >>= 1;
+      }
+
+      for (j=0;j<3;j++)
+      {
+         for (i=0;i<nsf;i++)
+         {
+            y[j][i] = SHR(x[j][i],sig_shift);
+         }
+      }     
+      for (i=0;i<nsf;i++)
+      {
+         t[i] = SHR(target[i],sig_shift);
+      }
+
+      for (i=0;i<3;i++)
+         corr[i]=inner_prod(y[i],t,nsf);
+      
+      for (i=0;i<3;i++)
+         for (j=0;j<=i;j++)
+            A[i][j]=A[j][i]=inner_prod(y[i],y[j],nsf);
+   }
+#else
+   {
+      for (i=0;i<3;i++)
+         corr[i]=inner_prod(x[i],target,nsf);
+      
+      for (i=0;i<3;i++)
+         for (j=0;j<=i;j++)
+            A[i][j]=A[j][i]=inner_prod(x[i],x[j],nsf);
+   }
+#endif
+
    {
       float C[9];
       signed char *ptr=gain_cdbk;

<p><p>1.13      +0 -0      speex/libspeex/smallft.c

Index: smallft.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/smallft.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- smallft.c	8 Oct 2003 04:56:09 -0000	1.12
+++ smallft.c	8 Oct 2003 04:57:58 -0000	1.13
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.12 2003/10/08 04:56:09 jm Exp $
+ last mod: $Id: smallft.c,v 1.13 2003/10/08 04:57:58 jm Exp $
 
  ********************************************************************/
 

<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