[xiph-commits] r11937 - in trunk/speex: include/speex libspeex

jm at svn.xiph.org jm at svn.xiph.org
Sat Oct 21 20:24:45 PDT 2006


Author: jm
Date: 2006-10-21 20:24:40 -0700 (Sat, 21 Oct 2006)
New Revision: 11937

Modified:
   trunk/speex/include/speex/speex_preprocess.h
   trunk/speex/libspeex/filterbank.c
   trunk/speex/libspeex/filterbank.h
   trunk/speex/libspeex/preprocess.c
Log:
Now possible to control the amount of noise and echo suppression through the
_ctl() interface.


Modified: trunk/speex/include/speex/speex_preprocess.h
===================================================================
--- trunk/speex/include/speex/speex_preprocess.h	2006-10-21 07:13:35 UTC (rev 11936)
+++ trunk/speex/include/speex/speex_preprocess.h	2006-10-22 03:24:40 UTC (rev 11937)
@@ -104,6 +104,15 @@
 #define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16
 #define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17
 
+#define SPEEX_PREPROCESS_SET_NOISE_SUPPRESS 18
+#define SPEEX_PREPROCESS_GET_NOISE_SUPPRESS 19
+
+#define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS 20
+#define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS 21
+
+#define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE 22
+#define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE 23
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/speex/libspeex/filterbank.c
===================================================================
--- trunk/speex/libspeex/filterbank.c	2006-10-21 07:13:35 UTC (rev 11936)
+++ trunk/speex/libspeex/filterbank.c	2006-10-22 03:24:40 UTC (rev 11937)
@@ -42,13 +42,13 @@
 #define toBARK(n)   (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
 #define toMEL(n)    (2595.f*log10(1.f+(n)/700.f))
 
-FilterBank *filterbank_new(int banks, float max_freq, float sampling, int len, int type)
+FilterBank *filterbank_new(int banks, float sampling, int len, int type)
 {
    FilterBank *bank;
    float df, max_mel, mel_interval;
    int i;
    df = .5*sampling/len;
-   max_mel = toBARK(max_freq);
+   max_mel = toBARK(.5*sampling);
    mel_interval = max_mel/(banks-1);
    
    bank = speex_alloc(sizeof(FilterBank));

Modified: trunk/speex/libspeex/filterbank.h
===================================================================
--- trunk/speex/libspeex/filterbank.h	2006-10-21 07:13:35 UTC (rev 11936)
+++ trunk/speex/libspeex/filterbank.h	2006-10-22 03:24:40 UTC (rev 11937)
@@ -47,7 +47,7 @@
 } FilterBank;
 
 
-FilterBank *filterbank_new(int banks, float max_freq, float sampling, int len, int type);
+FilterBank *filterbank_new(int banks, float sampling, int len, int type);
 
 void filterbank_destroy(FilterBank *bank);
 

Modified: trunk/speex/libspeex/preprocess.c
===================================================================
--- trunk/speex/libspeex/preprocess.c	2006-10-21 07:13:35 UTC (rev 11936)
+++ trunk/speex/libspeex/preprocess.c	2006-10-22 03:24:40 UTC (rev 11937)
@@ -76,16 +76,22 @@
 
 #define NB_BANDS 24
 
-#define SPEEX_PROB_START_DEFAULT    0.35f
-#define SPEEX_PROB_CONTINUE_DEFAULT 0.20f
+#define SPEEX_PROB_START_DEFAULT       0.35f
+#define SPEEX_PROB_CONTINUE_DEFAULT    0.20f
+#define NOISE_SUPPRESS_DEFAULT       -25
+#define ECHO_SUPPRESS_DEFAULT        -45
+#define ECHO_SUPPRESS_ACTIVE_DEFAULT -15
 
 /** Speex pre-processor state. */
 struct SpeexPreprocessState_ {
+   /* Basic info */
    int    frame_size;        /**< Number of samples processed each time */
    int    ps_size;           /**< Number of points in the power spectrum */
    int    sampling_rate;     /**< Sampling rate of the input/output */
+   int    nbands;
+   FilterBank *bank;
    
-   /* parameters */
+   /* Parameters */
    int    denoise_enabled;
    int    agc_enabled;
    float  agc_level;
@@ -95,10 +101,11 @@
    float  reverb_level;
    float  speech_prob_start;
    float  speech_prob_continue;
+   int    noise_suppress;
+   int    echo_suppress;
+   int    echo_suppress_active;
    
-   int    nbands;
-   FilterBank *bank;
-   
+   /* DSP-related arrays */
    float *frame;             /**< Processing frame (2*ps_size) */
    float *ft;                /**< Processing frame in freq domain (2*ps_size) */
    float *ps;                /**< Current power spectrum */
@@ -122,6 +129,7 @@
 
    float *echo_noise;
 
+   /* Misc */
    float *inbuf;             /**< Input buffer (overlapped analysis) */
    float *outbuf;            /**< Output buffer (for overlap and add) */
 
@@ -130,7 +138,7 @@
    int    nb_adapt;          /**< Number of frames used for adaptation so far */
    int    nb_loudness_adapt; /**< Number of frames used for loudness adaptation so far */
    int    min_count;         /**< Number of frames processed so far */
-   void *fft_lookup;   /**< Lookup table for the FFT */
+   void  *fft_lookup;        /**< Lookup table for the FFT */
 
 };
 
@@ -234,14 +242,17 @@
    st->dereverb_enabled = 0;
    st->reverb_decay = .0;
    st->reverb_level = .0;
+   st->noise_suppress = NOISE_SUPPRESS_DEFAULT;
+   st->echo_suppress = ECHO_SUPPRESS_DEFAULT;
+   st->echo_suppress_active = ECHO_SUPPRESS_ACTIVE_DEFAULT;
 
    st->speech_prob_start = SPEEX_PROB_START_DEFAULT;
    st->speech_prob_continue = SPEEX_PROB_CONTINUE_DEFAULT;
 
    st->nbands = NB_BANDS;
    M = st->nbands;
-   st->bank = filterbank_new(M, 4000, 8000, N, 1);
-         
+   st->bank = filterbank_new(M, sampling_rate, N, 1);
+   
    st->frame = (float*)speex_alloc(2*N*sizeof(float));
    st->window = (float*)speex_alloc(2*N*sizeof(float));
    st->ft = (float*)speex_alloc(2*N*sizeof(float));
@@ -501,6 +512,8 @@
    float *ps=st->ps;
    float Zframe=0, Pframe;
    float beta, beta_1;
+   float echo_floor;
+   float noise_floor;
    
    st->nb_adapt++;
    st->min_count++;
@@ -577,6 +590,8 @@
    Zframe /= st->nbands;
    Pframe = .1+.9*qcurve(Zframe);
    
+   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]);
@@ -618,10 +633,10 @@
       MM = hypergeom_gain(theta);
 
       g = prior_ratio * MM;
-      if (g > 1.5*st->gain[i])
-         g = 1.5*st->gain[i];
-      if (g < .66*st->gain[i])
-         g = .66*st->gain[i];
+      if (g > 2*st->gain[i])
+         g = 2*st->gain[i];
+      if (g < .5*st->gain[i])
+         g = .5*st->gain[i];
       st->gain[i] = g;
       /* Limit on the gain */
       if (st->gain[i]>1.f)
@@ -631,7 +646,7 @@
       if (st->denoise_enabled)
       {
          /* Compute the gain floor based on different floors for the background noise and residual echo */
-         float gain_floor = (.003f*st->noise[i] + .00003*st->echo_noise[i])/(1+st->noise[i] + st->echo_noise[i]);
+         float gain_floor = (noise_floor*st->noise[i] + echo_floor*st->echo_noise[i])/(1+st->noise[i] + st->echo_noise[i]);
          gain_floor = sqrt(gain_floor);
 
          /* Take into account speech probability of presence (what's the best rule to use?) */
@@ -816,7 +831,26 @@
       (*(int*)ptr) = st->speech_prob_continue * 100;
       break;
 
-      default:
+   case SPEEX_PREPROCESS_SET_NOISE_SUPPRESS:
+      st->noise_suppress = -ABS(*(spx_int32_t*)ptr);
+      break;
+   case SPEEX_PREPROCESS_GET_NOISE_SUPPRESS:
+      (*(spx_int32_t*)ptr) = st->noise_suppress;
+      break;
+   case SPEEX_PREPROCESS_SET_ECHO_SUPPRESS:
+      st->echo_suppress = -ABS(*(spx_int32_t*)ptr);
+      break;
+   case SPEEX_PREPROCESS_GET_ECHO_SUPPRESS:
+      (*(spx_int32_t*)ptr) = st->echo_suppress;
+      break;
+   case SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE:
+      st->echo_suppress_active = -ABS(*(spx_int32_t*)ptr);
+      break;
+   case SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE:
+      (*(spx_int32_t*)ptr) = st->echo_suppress_active;
+      break;
+
+   default:
       speex_warning_int("Unknown speex_preprocess_ctl request: ", request);
       return -1;
    }



More information about the commits mailing list