[xiph-commits] r12054 - trunk/speex/libspeex

jm at svn.xiph.org jm at svn.xiph.org
Tue Nov 7 05:25:38 PST 2006


Author: jm
Date: 2006-11-07 05:25:33 -0800 (Tue, 07 Nov 2006)
New Revision: 12054

Modified:
   trunk/speex/libspeex/math_approx.c
   trunk/speex/libspeex/math_approx.h
   trunk/speex/libspeex/preprocess.c
Log:
Added a higher precision cosine approximation and used it for the
WOLA window. Zero float operations left in preprocess.c.


Modified: trunk/speex/libspeex/math_approx.c
===================================================================
--- trunk/speex/libspeex/math_approx.c	2006-11-07 09:41:02 UTC (rev 12053)
+++ trunk/speex/libspeex/math_approx.c	2006-11-07 13:25:33 UTC (rev 12054)
@@ -173,7 +173,42 @@
    }
 }
 
-#include <stdio.h>
+#define L1 32767
+#define L2 -7651
+#define L3 8277
+#define L4 -626
+
+static inline spx_word16_t _spx_cos_pi_2(spx_word16_t x)
+{
+   spx_word16_t x2;
+   
+   x2 = MULT16_16_P15(x,x);
+   return ADD16(1,MIN16(32766,ADD32(SUB16(L1,x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2))))))));
+}
+
+spx_word16_t spx_cos_norm(spx_word32_t x)
+{
+   x = x&0x0001ffff;
+   if (x>SHL32(EXTEND32(1), 16))
+      x = SUB32(SHL32(EXTEND32(1), 17),x);
+   if (x&0x00007fff)
+   {
+      if (x<SHL32(EXTEND32(1), 15))
+      {
+         return _spx_cos_pi_2(EXTRACT16(x));
+      } else {
+         return NEG32(_spx_cos_pi_2(EXTRACT16(65536-x)));
+      }
+   } else {
+      if (x&0x0000ffff)
+         return 0;
+      else if (x&0x0001ffff)
+         return -32767;
+      else
+         return 32767;
+   }
+}
+
 /*
  K0 = 1
  K1 = log(2)

Modified: trunk/speex/libspeex/math_approx.h
===================================================================
--- trunk/speex/libspeex/math_approx.h	2006-11-07 09:41:02 UTC (rev 12053)
+++ trunk/speex/libspeex/math_approx.h	2006-11-07 13:25:33 UTC (rev 12054)
@@ -40,15 +40,19 @@
 spx_word16_t spx_cos(spx_word16_t x);
 spx_int16_t spx_ilog2(spx_uint32_t x);
 spx_int16_t spx_ilog4(spx_uint32_t x);
-
 #ifdef FIXED_POINT
 spx_word16_t spx_sqrt(spx_word32_t x);
 spx_word16_t spx_acos(spx_word16_t x);
 spx_word32_t spx_exp(spx_word16_t x);
+spx_word16_t spx_cos_norm(spx_word32_t x);
+
 #else
+
 #define spx_sqrt sqrt
 #define spx_acos acos
 #define spx_exp exp
+#define spx_cos_norm(x) (cos((.5f*M_PI)*(x)))
+
 #endif
 
 #endif

Modified: trunk/speex/libspeex/preprocess.c
===================================================================
--- trunk/speex/libspeex/preprocess.c	2006-11-07 09:41:02 UTC (rev 12053)
+++ trunk/speex/libspeex/preprocess.c	2006-11-07 13:25:33 UTC (rev 12054)
@@ -246,27 +246,27 @@
    int i;
    for (i=0;i<len;i++)
    {
-      float tmp;
-      float x=4*((float)i)/len;
+      spx_word16_t tmp;
+      spx_word16_t x = DIV32_16(MULT16_16(QCONST16(4.f,13),i),len);
       int inv=0;
-      if (x<1)
+      if (x<QCONST16(1.f,13))
       {
-      } else if (x<2)
+      } else if (x<QCONST16(2.f,13))
       {
-         x=2-x;
+         x=QCONST16(2.f,13)-x;
          inv=1;
-      } else if (x<3)
+      } else if (x<QCONST16(3.f,13))
       {
-         x=x-2;
+         x=x-QCONST16(2.f,13);
          inv=1;
       } else {
-         x=4-x;
+         x=QCONST16(2.f,13)-x+QCONST16(2.f,13); /* 4 - x */
       }
-      x*=1.9979;
-      tmp=(.5-.5*cos(x))*(.5-.5*cos(x));
+      x = MULT16_16_Q14(QCONST16(1.271903f,14), x);
+      tmp = SQR16_Q15(QCONST16(.5f,15)-MULT16_16_P15(QCONST16(.5f,15),spx_cos_norm(QCONST32(x,2))));
       if (inv)
-         tmp=1-tmp;
-      w[i]=Q15_ONE*sqrt(tmp);
+         tmp=SUB16(Q15_ONE,tmp);
+      w[i]=spx_sqrt(SHL32(EXTEND32(tmp),15));
    }
 }
 



More information about the commits mailing list