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

jm at svn.xiph.org jm at svn.xiph.org
Sat Nov 11 23:00:23 PST 2006


Author: jm
Date: 2006-11-11 23:00:19 -0800 (Sat, 11 Nov 2006)
New Revision: 12088

Modified:
   trunk/speex/libspeex/filterbank.c
   trunk/speex/libspeex/math_approx.c
   trunk/speex/libspeex/math_approx.h
Log:
Implemented atan in fixed-point and used it for toBARK. Also fixed a bug
in the float version of filterbank_new(). This was the last part of the 
fixed-point convertion for the echo canceller+nonlinear processor (including
initialisation).


Modified: trunk/speex/libspeex/filterbank.c
===================================================================
--- trunk/speex/libspeex/filterbank.c	2006-11-12 01:28:13 UTC (rev 12087)
+++ trunk/speex/libspeex/filterbank.c	2006-11-12 07:00:19 UTC (rev 12088)
@@ -38,10 +38,18 @@
 #include "filterbank.h"
 #include "misc.h"
 #include <math.h>
+#include "math_approx.h"
       
-#define toBARK(n)   (1000.f*32768.f*(13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n)))
+#ifdef FIXED_POINT
+
+#define toBARK(n)   (MULT16_16(26829,spx_atan(SHR32(MULT16_16(97,n),2))) + MULT16_16(4588,spx_atan(MULT16_32_Q15(20,MULT16_16(n,n)))) + MULT16_16(3355,n))
+      
+#else
+#define toBARK(n)   (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
+#endif
+       
 #define toMEL(n)    (2595.f*log10(1.f+(n)/700.f))
-      
+
 FilterBank *filterbank_new(int banks, spx_word32_t sampling, int len, int type)
 {
    FilterBank *bank;
@@ -51,7 +59,7 @@
    int id1;
    int id2;
    df = DIV32(SHL32(sampling,15),MULT16_16(2,len));
-   max_mel = toBARK(.5*sampling);
+   max_mel = toBARK(EXTRACT16(MULT16_16_Q15(QCONST16(.5f,15),sampling)));
    mel_interval = PDIV32(max_mel,banks-1);
    
    bank = (FilterBank*)speex_alloc(sizeof(FilterBank));
@@ -67,10 +75,10 @@
 #endif
    for (i=0;i<len;i++)
    {
-      spx_word32_t curr_freq;
+      spx_word16_t curr_freq;
       spx_word32_t mel;
       spx_word16_t val;
-      curr_freq = MULT16_32_P15(i,df);
+      curr_freq = EXTRACT16(MULT16_32_P15(i,df));
       mel = toBARK(curr_freq);
       if (mel > max_mel)
          break;
@@ -84,7 +92,7 @@
          id1 = banks-2;
          val = Q15_ONE;
       } else {
-         val = DIV32_16(mel - id1*mel_interval,EXTRACT16(PSHR32((int)(.5+mel_interval),15)));
+         val = DIV32_16(mel - id1*mel_interval,EXTRACT16(PSHR32(mel_interval,15)));
       }
       id2 = id1+1;
       bank->bank_left[i] = id1;

Modified: trunk/speex/libspeex/math_approx.c
===================================================================
--- trunk/speex/libspeex/math_approx.c	2006-11-12 01:28:13 UTC (rev 12087)
+++ trunk/speex/libspeex/math_approx.c	2006-11-12 07:00:19 UTC (rev 12088)
@@ -238,8 +238,30 @@
    else
       return spx_exp2(MULT16_16_P14(23637,x));
 }
+#define M1 32767
+#define M2 -21
+#define M3 -11943
+#define M4 4936
 
+static inline spx_word16_t spx_atan01(spx_word16_t x)
+{
+   return MULT16_16_P15(x, ADD32(M1, MULT16_16_P15(x, ADD32(M2, MULT16_16_P15(x, ADD32(M3, MULT16_16_P15(M4, x)))))));
+}
 
+/* Input in Q15, output in Q14 */
+spx_word16_t spx_atan(spx_word32_t x)
+{
+   if (x <= 32767)
+   {
+      return SHR16(spx_atan01(x),1);
+   } else {
+      int e = spx_ilog2(x);
+      if (e>=29)
+         return 25736;
+      x = DIV32_16(SHL32(EXTEND32(32767),29-e), EXTRACT16(SHR32(x, e-14)));
+      return SUB16(25736, SHR16(spx_atan01(x),1));
+   }
+}
 #else
 
 #ifndef M_PI

Modified: trunk/speex/libspeex/math_approx.h
===================================================================
--- trunk/speex/libspeex/math_approx.h	2006-11-12 01:28:13 UTC (rev 12087)
+++ trunk/speex/libspeex/math_approx.h	2006-11-12 07:00:19 UTC (rev 12088)
@@ -46,12 +46,16 @@
 spx_word32_t spx_exp(spx_word16_t x);
 spx_word16_t spx_cos_norm(spx_word32_t x);
 
+/* Input in Q15, output in Q14 */
+spx_word16_t spx_atan(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)))
+#define spx_atan atan
 
 #endif
 



More information about the commits mailing list