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

jm at svn.xiph.org jm at svn.xiph.org
Wed Nov 1 06:13:02 PST 2006


Author: jm
Date: 2006-11-01 06:12:57 -0800 (Wed, 01 Nov 2006)
New Revision: 11984

Modified:
   trunk/speex/libspeex/arch.h
   trunk/speex/libspeex/fixed_generic.h
   trunk/speex/libspeex/math_approx.c
   trunk/speex/libspeex/math_approx.h
   trunk/speex/libspeex/preprocess.c
Log:
converted theta and prior_ratio to fixed-point.


Modified: trunk/speex/libspeex/arch.h
===================================================================
--- trunk/speex/libspeex/arch.h	2006-11-01 12:58:16 UTC (rev 11983)
+++ trunk/speex/libspeex/arch.h	2006-11-01 14:12:57 UTC (rev 11984)
@@ -151,6 +151,7 @@
 #define MULT16_32_Q13(a,b)     ((a)*(b))
 #define MULT16_32_Q14(a,b)     ((a)*(b))
 #define MULT16_32_Q15(a,b)     ((a)*(b))
+#define MULT16_32_P15(a,b)     ((a)*(b))
 
 #define MAC16_32_Q11(c,a,b)     ((c)+(a)*(b))
 #define MAC16_32_Q15(c,a,b)     ((c)+(a)*(b))

Modified: trunk/speex/libspeex/fixed_generic.h
===================================================================
--- trunk/speex/libspeex/fixed_generic.h	2006-11-01 12:58:16 UTC (rev 11983)
+++ trunk/speex/libspeex/fixed_generic.h	2006-11-01 14:12:57 UTC (rev 11984)
@@ -77,6 +77,7 @@
 #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
 #define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))
 
+#define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
 #define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
 #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
 

Modified: trunk/speex/libspeex/math_approx.c
===================================================================
--- trunk/speex/libspeex/math_approx.c	2006-11-01 12:58:16 UTC (rev 11983)
+++ trunk/speex/libspeex/math_approx.c	2006-11-01 14:12:57 UTC (rev 11984)
@@ -235,6 +235,7 @@
       return SHR32(EXTEND32(frac), -integer-2);
 }
 
+/* Input in Q11 format, output in Q16 */
 spx_word32_t spx_exp(spx_word16_t x)
 {
    if (x>21290)

Modified: trunk/speex/libspeex/math_approx.h
===================================================================
--- trunk/speex/libspeex/math_approx.h	2006-11-01 12:58:16 UTC (rev 11983)
+++ trunk/speex/libspeex/math_approx.h	2006-11-01 14:12:57 UTC (rev 11984)
@@ -44,9 +44,11 @@
 #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);
 #else
 #define spx_sqrt sqrt
 #define spx_acos acos
+#define spx_exp exp
 #endif
 
 #endif

Modified: trunk/speex/libspeex/preprocess.c
===================================================================
--- trunk/speex/libspeex/preprocess.c	2006-11-01 12:58:16 UTC (rev 11983)
+++ trunk/speex/libspeex/preprocess.c	2006-11-01 14:12:57 UTC (rev 11984)
@@ -151,6 +151,11 @@
 #define FRAC_SCALING_1 3.0518e-05
 #define FRAC_SHIFT 1
 
+#define EXPIN_SCALING 2048.f
+#define EXPIN_SCALING_1 0.00048828f
+#define EXPIN_SHIFT 11
+#define EXPOUT_SCALING_1 1.5259e-05
+
 #define NOISE_SHIFT 7
 
 #else
@@ -165,6 +170,10 @@
 #define FRAC_SHIFT 0
 #define NOISE_SHIFT 0
 
+#define EXPIN_SCALING 1.f
+#define EXPIN_SCALING_1 1.f
+#define EXPOUT_SCALING_1 1.f
+
 #endif
 
 /** Speex pre-processor state. */
@@ -717,33 +726,36 @@
    
    noise_floor = exp(.2302585f*st->noise_suppress);
    echo_floor = exp(.2302585f* (st->echo_suppress*(1-Pframe) + st->echo_suppress_active*Pframe));
-   /*print_vec(&Pframe, 1, "");*/
-   /*for (i=N;i<N+M;i++)
-      st->gain2[i] = qcurve (st->zeta[i]);
-   filterbank_compute_psd(st->bank,st->gain2+N, st->gain2);*/
    
+   /* Compute Ephraim & Malah gain speech probability of presence for each critical band (Bark scale) 
+      Technically this is actually wrong because the EM gaim assumes a slightly different probability 
+      distribution */
    for (i=N;i<N+M;i++)
    {
-      float theta, MM;
-      float prior_ratio;
+      spx_word32_t theta;
+      float MM;
+      spx_word16_t prior_ratio;
       float q;
       float P1;
 
       /* Compute the gain floor based on different floors for the background noise and residual echo */
       st->gain_floor[i] = FRAC_SCALING*sqrt((noise_floor*PSHR32(st->noise[i],NOISE_SHIFT) + echo_floor*st->echo_noise[i])/(1+PSHR32(st->noise[i],NOISE_SHIFT) + st->echo_noise[i]));
-      prior_ratio = st->prior[i]/(SNR_SCALING+st->prior[i]);
-      theta = (1.f+SNR_SCALING_1*st->post[i])*prior_ratio;
+      prior_ratio = FRAC_SCALING*st->prior[i]/(SNR_SCALING+st->prior[i]);
+      theta = MULT16_32_P15(prior_ratio, QCONST32(1.f,EXPIN_SHIFT)+SHL32(EXTEND32(st->post[i]),EXPIN_SHIFT-SNR_SHIFT));
 
-      MM = hypergeom_gain(theta);
+      MM = hypergeom_gain(EXPIN_SCALING_1*theta);
       /* Gain with bound */
-      st->gain[i] = MIN16(FRAC_SCALING, FRAC_SCALING*prior_ratio * MM);
+      st->gain[i] = MIN16(FRAC_SCALING, prior_ratio * MM);
       
       /* Save old Bark power spectrum */
       st->old_ps[i] = .2*st->old_ps[i] + .8*FRAC_SCALING_1*FRAC_SCALING_1*st->gain[i]*st->gain[i]*ps[i];
 
       P1 = .2+.8*qcurve (st->zeta[i]);
       q = 1-Pframe*P1;
-      st->gain2[i]=FRAC_SCALING/(1.f + (q/(1.f-q))*(1.f+SNR_SCALING_1*st->prior[i])*exp(-theta));
+#ifdef FIXED_POINT
+      theta = MIN32(theta, 32767);
+#endif
+      st->gain2[i]=FRAC_SCALING/(1.f + (q/(1.f-q))*(1.f+SNR_SCALING_1*st->prior[i])*EXPOUT_SCALING_1*spx_exp(-EXTRACT16(theta)));
    }
    filterbank_compute_psd16(st->bank,st->gain2+N, st->gain2);
    filterbank_compute_psd16(st->bank,st->gain+N, st->gain);



More information about the commits mailing list