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

jm at svn.xiph.org jm at svn.xiph.org
Wed Nov 1 02:03:19 PST 2006


Author: jm
Date: 2006-11-01 02:03:16 -0800 (Wed, 01 Nov 2006)
New Revision: 11979

Modified:
   trunk/speex/libspeex/arch.h
   trunk/speex/libspeex/preprocess.c
Log:
a posteriori SNR now in spx_word16_t


Modified: trunk/speex/libspeex/arch.h
===================================================================
--- trunk/speex/libspeex/arch.h	2006-11-01 09:54:31 UTC (rev 11978)
+++ trunk/speex/libspeex/arch.h	2006-11-01 10:03:16 UTC (rev 11979)
@@ -39,8 +39,10 @@
 
 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
+#define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
 #define MAX16(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
 #define ABS32(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 32-bit value.  */
+#define MIN32(a,b) ((a) < (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
 #define MAX32(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
 
 #ifdef FIXED_POINT
@@ -68,6 +70,7 @@
 #define VERY_SMALL 0
 #define VERY_LARGE32 ((spx_word32_t)2147483647)
 #define VERY_LARGE16 ((spx_word16_t)32767)
+#define Q15_ONE ((spx_word16_t)32767)
 
 
 #ifdef FIXED_DEBUG
@@ -113,6 +116,7 @@
 #define VERY_SMALL 1e-15f
 #define VERY_LARGE32 1e15f
 #define VERY_LARGE16 1e15f
+#define Q15_ONE ((spx_word16_t)1.f)
 
 #define QCONST16(x,bits) (x)
 #define QCONST32(x,bits) (x)

Modified: trunk/speex/libspeex/preprocess.c
===================================================================
--- trunk/speex/libspeex/preprocess.c	2006-11-01 09:54:31 UTC (rev 11978)
+++ trunk/speex/libspeex/preprocess.c	2006-11-01 10:03:16 UTC (rev 11979)
@@ -204,7 +204,7 @@
    spx_word32_t *old_ps;     /**< Power spectrum for last frame */
    float *gain;              /**< Ephraim Malah gain */
    float *prior;             /**< A-priori SNR */
-   float *post;              /**< A-posteriori SNR */
+   spx_word16_t *post;       /**< A-posteriori SNR */
 
    spx_word32_t *S;          /**< Smoothed power spectrum */
    spx_word32_t *Smin;       /**< See Cohen paper */
@@ -359,7 +359,7 @@
    st->reverb_estimate = (spx_word32_t*)speex_alloc((N+M)*sizeof(float));
    st->old_ps = (spx_word32_t*)speex_alloc((N+M)*sizeof(float));
    st->prior = (float*)speex_alloc((N+M)*sizeof(float));
-   st->post = (float*)speex_alloc((N+M)*sizeof(float));
+   st->post = (spx_word16_t*)speex_alloc((N+M)*sizeof(float));
    st->gain = (float*)speex_alloc((N+M)*sizeof(float));
    st->gain2 = (float*)speex_alloc((N+M)*sizeof(float));
    st->gain_floor = (float*)speex_alloc((N+M)*sizeof(float));
@@ -392,7 +392,7 @@
       st->reverb_estimate[i]=0.;
       st->old_ps[i]=1.;
       st->gain[i]=1;
-      st->post[i]=1;
+      st->post[i]=Q15_ONE;
       st->prior[i]=1;
    }
 
@@ -684,13 +684,12 @@
    {
       float gamma = .1;
       spx_word32_t tot_noise = 1.f+ PSHR32(st->noise[i],NOISE_SHIFT) + st->echo_noise[i] + st->reverb_estimate[i];
-      st->post[i] = SNR_SCALING_1*SUB16(DIV32_16_Q8(ps[i],tot_noise), QCONST16(1.f,8));
-
-      if (st->post[i]>100.f)
-         st->post[i]=100.f;
+      st->post[i] = SUB16(DIV32_16_Q8(ps[i],tot_noise), QCONST16(1.f,8));
+      st->post[i]=MIN16(st->post[i], QCONST16(100.f,8));
+      
       gamma = .1+.9*FRAC_SCALING_1*SQR16_Q15(DIV32_16_Q15(st->old_ps[i],ADD32(st->old_ps[i],tot_noise)));
       /* A priori SNR update */
-      st->prior[i] = gamma*max(0.0f,st->post[i]) + (1.f-gamma)*SNR_SCALING_1*DIV32_16_Q8(st->old_ps[i],tot_noise);
+      st->prior[i] = gamma*max(0.0f,SNR_SCALING_1*st->post[i]) + (1.f-gamma)*SNR_SCALING_1*DIV32_16_Q8(st->old_ps[i],tot_noise);
 
       if (st->prior[i]>100.f)
          st->prior[i]=100.f;
@@ -729,7 +728,7 @@
       /* Compute the gain floor based on different floors for the background noise and residual echo */
       st->gain_floor[i] = 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]/(1.f+st->prior[i]);
-      theta = (1.f+st->post[i])*prior_ratio;
+      theta = (1.f+SNR_SCALING_1*st->post[i])*prior_ratio;
 
       MM = hypergeom_gain(theta);
       st->gain[i] = prior_ratio * MM;
@@ -763,7 +762,7 @@
          
          /* Wiener filter gain */
          prior_ratio = st->prior[i]/(1.f+st->prior[i]);
-         theta = (1.f+st->post[i])*prior_ratio;
+         theta = (1.f+SNR_SCALING_1*st->post[i])*prior_ratio;
          p = st->gain2[i];
          
          /* Optimal estimator for loudness domain */



More information about the commits mailing list