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

jm at svn.xiph.org jm at svn.xiph.org
Fri Dec 9 19:13:51 PST 2005


Author: jm
Date: 2005-12-09 19:13:48 -0800 (Fri, 09 Dec 2005)
New Revision: 10571

Modified:
   trunk/speex/libspeex/mdf.c
   trunk/speex/libspeex/pseudofloat.h
Log:
think all the main AEC loops are in fixed-point


Modified: trunk/speex/libspeex/mdf.c
===================================================================
--- trunk/speex/libspeex/mdf.c	2005-12-10 02:42:34 UTC (rev 10570)
+++ trunk/speex/libspeex/mdf.c	2005-12-10 03:13:48 UTC (rev 10571)
@@ -65,6 +65,7 @@
 #else
 #define WEIGHT_SCALING 1.f
 #define WEIGHT_SCALING_1 1.f
+#define WEIGHT_SHIFT 0
 #endif
 
 /** Speex echo cancellation state. */
@@ -432,26 +433,27 @@
 
    if (st->adapted)
    {
-      adapt_rate = 1.f/M;
+      spx_word16_t M_1;
+#ifdef FIXED_POINT
+      M_1 = DIV32_16(32767,M);
+#else
+      M_1 = 1.f/M;
+#endif
       for (i=0;i<=st->frame_size;i++)
       {
+         spx_word32_t r, e;
+         /* Compute frequency-domain adaptation mask */
+         r = leak_estimate*st->Yf[i];
+         e = st->Rf[i]+1;
 #ifdef FIXED_POINT
-         float r;
-         /* Compute frequency-domain adaptation mask */
-         r = leak_estimate*st->Yf[i] / (1.f+st->Rf[i]);
-         if (r>.5)
-            r = .5;
-         st->power_1[i] = FLOAT_DIV32(WEIGHT_SCALING*adapt_rate*r,ADD32(1,st->power[i]));
-         /*printf ("%f ", st->power_1[i]);*/
+         if (r>SHR32(e,1))
+            r = SHR32(e,1);
 #else
-         float r, e;
-         /* Compute frequency-domain adaptation mask */
-         r = leak_estimate*st->Yf[i];
-         e = 1.f+st->Rf[i];
          if (r>.5*e)
             r = .5*e;
-         st->power_1[i] = adapt_rate*r/(e*(1+st->power[i]));
 #endif
+         /*st->power_1[i] = adapt_rate*r/(e*(1+st->power[i]));*/
+         st->power_1[i] = FLOAT_SHL(FLOAT_DIV32_FLOAT(MULT16_32_Q15(M_1,r),FLOAT_MUL32U(e,st->power[i]+1)),WEIGHT_SHIFT);
       }
    } else {
       for (i=0;i<=st->frame_size;i++)

Modified: trunk/speex/libspeex/pseudofloat.h
===================================================================
--- trunk/speex/libspeex/pseudofloat.h	2005-12-10 02:42:34 UTC (rev 10570)
+++ trunk/speex/libspeex/pseudofloat.h	2005-12-10 03:13:48 UTC (rev 10571)
@@ -162,6 +162,55 @@
       return SHL32(MULT16_32_Q15(a.m, b),15+a.e);
 }
 
+static inline spx_float_t FLOAT_MUL32U(spx_word32_t a, spx_word32_t b)
+{
+   int e=0;
+   /* FIXME: Handle the sign */
+   if (a==0)
+      return (spx_float_t) {0,0};
+   while (a>32767)
+   {
+      a >>= 1;
+      e++;
+   }
+   while (a<16384)
+   {
+      a <<= 1;
+      e--;
+   }
+   while (b>32767)
+   {
+      b >>= 1;
+      e++;
+   }
+   while (b<16384)
+   {
+      b <<= 1;
+      e--;
+   }
+   return (spx_float_t) {MULT16_16_Q15(a,b),e+15};
+}
+
+static inline spx_float_t FLOAT_DIV32_FLOAT(spx_word32_t a, spx_float_t b)
+{
+   int e=0;
+   /* FIXME: Handle the sign */
+   if (a==0)
+      return (spx_float_t) {0,0};
+   while (a<SHL32(b.m,14))
+   {
+      a <<= 1;
+      e--;
+   }
+   while (a>=SHL32(b.m-1,15))
+   {
+      a >>= 1;
+      e++;
+   }
+   return (spx_float_t) {DIV32_16(a,b.m),e-b.e};
+}
+
+
 static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b)
 {
    int e=0;
@@ -196,6 +245,9 @@
 #define FLOAT_DIV32(a,b) ((a)/(b))
 #define FLOAT_ADD(a,b) ((a)+(b))
 #define REALFLOAT(x) (x)
+#define FLOAT_DIV32_FLOAT(a,b) ((a)/(b))
+#define FLOAT_MUL32U(a,b) ((a)*(b))
+#define FLOAT_SHL(a,b) (a)
 
 #endif
 



More information about the commits mailing list