[xiph-cvs] cvs commit: speex/libspeex preprocess.c speex_preprocess.h

Jean-Marc Valin jm at xiph.org
Tue Sep 16 17:15:12 PDT 2003



jm          03/09/16 20:15:12

  Modified:    libspeex preprocess.c speex_preprocess.h
  Log:
  added function to update the estimates without applying denoising

Revision  Changes    Path
1.6       +56 -12    speex/libspeex/preprocess.c

Index: preprocess.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/preprocess.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- preprocess.c	16 Sep 2003 23:44:19 -0000	1.5
+++ preprocess.c	17 Sep 2003 00:15:12 -0000	1.6
@@ -489,16 +489,12 @@
    
 }
 
-int speex_preprocess(SpeexPreprocessState *st, float *x, float *echo)
+static void preprocess_analysis(SpeexPreprocessState *st, float *x)
 {
    int i;
-   int is_speech=1;
-   float mean_post=0;
-   float mean_prior=0;
    int N = st->ps_size;
    int N3 = 2*N - st->frame_size;
    int N4 = st->frame_size - N3;
-   float scale=.5/N;
    float *ps=st->ps;
 
    /* 'Build' input frame */
@@ -518,18 +514,21 @@
    /* Perform FFT */
    drft_forward(st->fft_lookup, st->frame);
 
-   /************************************************************** 
-    *  Denoise in spectral domain using Ephraim-Malah algorithm  *
-    **************************************************************/
-
    /* Power spectrum */
    ps[0]=1;
    for (i=1;i<N;i++)
       ps[i]=1+st->frame[2*i-1]*st->frame[2*i-1] + st->frame[2*i]*st->frame[2*i];
 
-   for (i=1;i<N-1;i++)
-      st->S[i] = 100+ .8*st->S[i] + .05*ps[i-1]+.1*ps[i]+.05*ps[i+1];
+}
 
+static void update_noise_prob(SpeexPreprocessState *st)
+{
+   int i;
+   int N = st->ps_size;
+   
+   for (i=1;i<N-1;i++)
+      st->S[i] = 100+ .8*st->S[i] + .05*st->ps[i-1]+.1*st->ps[i]+.05*st->ps[i+1];
+   
    if (st->nb_preprocess<1)
    {
       for (i=1;i<N-1;i++)
@@ -558,12 +557,28 @@
       /*fprintf (stderr, "%f ", st->S[i]/st->Smin[i]);*/
       /*fprintf (stderr, "%f ", st->update_prob[i]);*/
    }
+}
 
+int speex_preprocess(SpeexPreprocessState *st, float *x, float *echo)
+{
+   int i;
+   int is_speech=1;
+   float mean_post=0;
+   float mean_prior=0;
+   int N = st->ps_size;
+   int N3 = 2*N - st->frame_size;
+   int N4 = st->frame_size - N3;
+   float scale=.5/N;
+   float *ps=st->ps;
+
+   preprocess_analysis(st, x);
+
+   update_noise_prob(st);
 
    st->nb_preprocess++;
 
    /* Noise estimation always updated for the 20 first times */
-   if (st->nb_adapt<20)
+   if (st->nb_adapt<10)
       /*if (st->nb_adapt<25 && st->nb_adapt>15)*/
    {
       update_noise(st, ps, echo);
@@ -810,6 +825,35 @@
    return is_speech;
 }
 
+void speex_preprocess_estimate_update(SpeexPreprocessState *st, float *x, float *noise)
+{
+   int i;
+   int N = st->ps_size;
+   int N3 = 2*N - st->frame_size;
+
+   float *ps=st->ps;
+
+   preprocess_analysis(st, x);
+
+   update_noise_prob(st);
+
+   st->nb_preprocess++;
+   
+   for (i=1;i<N-1;i++)
+   {
+      if (st->update_prob[i]<.5)
+         st->noise[i] = .90*st->noise[i] + .1*ps[i];
+   }
+
+   for (i=0;i<N3;i++)
+      st->outbuf[i] = x[st->frame_size-N3+i]*st->window[st->frame_size+i];
+
+   /* Save old power spectrum */
+   for (i=1;i<N;i++)
+      st->old_ps[i] = ps[i];
+
+}
+
 
 int speex_preprocess_ctl(SpeexPreprocessState *state, int request, void *ptr)
 {

<p><p>1.6       +3 -0      speex/libspeex/speex_preprocess.h

Index: speex_preprocess.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_preprocess.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- speex_preprocess.h	16 Sep 2003 23:44:19 -0000	1.5
+++ speex_preprocess.h	17 Sep 2003 00:15:12 -0000	1.6
@@ -102,6 +102,9 @@
 /** Preprocess a frame */
 int speex_preprocess(SpeexPreprocessState *st, float *x, float *noise);
 
+/** Preprocess a frame */
+void speex_preprocess_estimate_update(SpeexPreprocessState *st, float *x, float *noise);
+
 /** Used like the ioctl function to control the preprocessor parameters */
 int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);
 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list