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

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



jm          03/10/08 00:53:18

  Modified:    libspeex filters.c ltp.c smallft.c
  Log:
  fixed-point: conversion of the open-loop pitch analysis

Revision  Changes    Path
1.42      +4 -4      speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- filters.c	8 Oct 2003 04:52:27 -0000	1.41
+++ filters.c	8 Oct 2003 04:53:18 -0000	1.42
@@ -60,13 +60,13 @@
    {
       spx_sig_t tmp = x[i];
       if (tmp<0)
-         tmp = -1;
+         tmp = -tmp;
       if (tmp > max_val)
          max_val = tmp;
    }
 
    sig_shift=0;
-   while (max_val>2048)
+   while (max_val>16383)
    {
       sig_shift++;
       max_val >>= 1;
@@ -84,11 +84,11 @@
       sum2 += MULT16_16(tmp,tmp);
       tmp = SHR(x[i+3],sig_shift);
       sum2 += MULT16_16(tmp,tmp);
-      sum += sum2;
+      sum += SHR(sum2,6);
    }
    
    /*FIXME: remove division*/
-   return (1<<sig_shift)*sqrt(1+sum/len)/SIG_SCALING;
+   return (1<<(sig_shift+3))*sqrt(1+sum/len)/SIG_SCALING;
 }
 
 #define MUL_16_32_R15(a,bh,bl) ((a)*(bh) + ((a)*(bl)>>15))

<p><p>1.81      +135 -1    speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- ltp.c	8 Oct 2003 04:42:59 -0000	1.80
+++ ltp.c	8 Oct 2003 04:53:18 -0000	1.81
@@ -38,6 +38,140 @@
 
 #include <stdio.h>
 
+#ifdef FIXED_POINT
+
+static spx_word32_t inner_prod2(spx_word16_t *x, spx_word16_t *y, int len)
+{
+   int i;
+   spx_word32_t sum=0;
+   for (i=0;i<len;i+=4)
+   {
+      spx_word32_t part=0;
+      part += MULT16_16(x[i],y[i]);
+      part += MULT16_16(x[i+1],y[i+1]);
+      part += MULT16_16(x[i+2],y[i+2]);
+      part += MULT16_16(x[i+3],y[i+3]);
+      sum += SHR(part,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;
+   /*float corr=0;*/
+   /*float energy;*/
+   float *best_score;
+   float e0;
+   spx_word32_t *corr, *energy;
+   float *score;
+
+   spx_word16_t *swn;
+   spx_sig_t max_sw=1;
+   int sw_shift=0;
+
+   best_score = PUSH(stack,N, float);
+   corr = PUSH(stack,end-start+1, spx_word32_t);
+   energy = PUSH(stack,end-start+2, spx_word32_t);
+   score = PUSH(stack,end-start+1, float);
+
+   swn = PUSH(stack, end+len, spx_word16_t);
+   for (i=-end;i<len;i++)
+   {
+      spx_sig_t tmp = sw[i];
+      if (tmp<0)
+         tmp = -tmp;
+      if (tmp > max_sw)
+         max_sw = tmp;
+   }
+   while (max_sw>16384)
+   {
+      sw_shift++;
+      max_sw>>=1;
+   }
+   for (i=0;i<end+len;i++)
+      swn[i] = SHR(sw[i-end],sw_shift);
+   
+   swn += end;
+
+
+   for (i=0;i<N;i++)
+   {
+        best_score[i]=-1;
+        gain[i]=0;
+   }
+
+
+   energy[0]=inner_prod2(swn-start, swn-start, len);
+   e0=inner_prod2(swn, swn, len);
+   for (i=start;i<=end;i++)
+   {
+      /* Update energy for next pitch*/
+      energy[i-start+1] = energy[i-start] + SHR(MULT16_16(swn[-i-1],swn[-i-1]) - MULT16_16(swn[-i+len-1],swn[-i+len-1]),6);
+   }
+   for (i=start;i<=end;i++)
+   {
+      corr[i-start]=0;
+      score[i-start]=0;
+   }
+
+   for (i=start;i<=end;i++)
+   {
+      /* Compute correlation*/
+      corr[i-start]=inner_prod2(swn, swn-i, len);
+      score[i-start]=1.*corr[i-start]*corr[i-start]/(energy[i-start]+1.);
+   }
+   for (i=start;i<=end;i++)
+   {
+      if (score[i-start]>best_score[N-1])
+      {
+         float g1, g;
+         g1 = corr[i-start]/(energy[i-start]+10.);
+         g = sqrt(g1*corr[i-start]/(e0+10.));
+         if (g>g1)
+            g=g1;
+         if (g<0)
+            g=0;
+         for (j=0;j<N;j++)
+         {
+            if (score[i-start] > best_score[j])
+            {
+               for (k=N-1;k>j;k--)
+               {
+                  best_score[k]=best_score[k-1];
+                  pitch[k]=pitch[k-1];
+                  gain[k] = gain[k-1];
+               }
+               best_score[j]=score[i-start];
+               pitch[j]=i;
+               gain[j]=g;
+               break;
+            }
+         }
+      }
+   }
+
+}
+
+#else
+
+
 #ifdef _USE_SSE
 #include "ltp_sse.h"
 #else
@@ -137,7 +271,7 @@
    }
 
 }
-
+#endif
 
 
 

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

Index: smallft.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/smallft.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- smallft.c	8 Oct 2003 04:52:27 -0000	1.10
+++ smallft.c	8 Oct 2003 04:53:18 -0000	1.11
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.10 2003/10/08 04:52:27 jm Exp $
+ last mod: $Id: smallft.c,v 1.11 2003/10/08 04:53:18 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