[xiph-cvs] cvs commit: speex/libspeex denoise.c speex_denoise.h

Jean-Marc Valin jm at xiph.org
Tue May 13 21:37:01 PDT 2003



jm          03/05/14 00:37:01

  Modified:    libspeex denoise.c speex_denoise.h
  Log:
  Basic adaptive gain control working

Revision  Changes    Path
1.6       +23 -1     speex/libspeex/denoise.c

Index: denoise.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/denoise.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- denoise.c	13 May 2003 20:57:31 -0000	1.5
+++ denoise.c	14 May 2003 04:37:00 -0000	1.6
@@ -47,6 +47,7 @@
 #endif
 
 #define SQRT_M_PI_2 0.88623
+#define LOUDNESS_EXP 3.5
 
 static void conj_window(float *w, int len)
 {
@@ -147,6 +148,10 @@
       st->loudness_weight[i] *= st->loudness_weight[i];
    }
 
+   st->loudness = pow(6000,LOUDNESS_EXP);
+   st->loudness2 = 6000;
+   st->nb_loudness_adapt = 0;
+
    drft_init(&st->fft_lookup,2*N);
 
 
@@ -365,6 +370,7 @@
    if (mean_prior<.23 && mean_post < .5 && st->nb_adapt>=20)
    {
       st->consec_noise++;
+      /*fprintf (stderr, "noise\n");*/
    } else {
       st->consec_noise=0;
    }
@@ -412,15 +418,31 @@
    }
    st->gain2[N-1]=0;
 
+   if ((mean_prior>3&&mean_prior>3))
    {
+      st->nb_loudness_adapt++;
+      float rate=2.0/(1+st->nb_loudness_adapt);
+      if (rate < .01)
+         rate = .01;
+
       float loudness=0;
       for (i=2;i<N;i++)
       {
          loudness += scale*st->ps[i] * st->gain2[i] * st->gain2[i] * st->loudness_weight[i];
       }
       loudness=sqrt(loudness);
-      fprintf (stderr, "%f\n", loudness);
+      /*if (loudness < 2*pow(st->loudness, 1.0/LOUDNESS_EXP) &&
+        loudness*2 > pow(st->loudness, 1.0/LOUDNESS_EXP))*/
+      st->loudness = (1-rate)*st->loudness + (rate)*pow(loudness, LOUDNESS_EXP);
+      
+      st->loudness2 = (1-rate)*st->loudness2 + rate*pow(st->loudness, 1.0/LOUDNESS_EXP);
+
+      loudness = pow(st->loudness, 1.0/LOUDNESS_EXP);
+
+      /*fprintf (stderr, "%f %f %f\n", loudness, st->loudness2, rate);*/
    }
+   for (i=0;i<N;i++)
+      st->gain2[i] *= 6000.0/st->loudness2;
 
    /* Apply computed gain */
    for (i=1;i<N;i++)

<p><p>1.3       +10 -7     speex/libspeex/speex_denoise.h

Index: speex_denoise.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_denoise.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- speex_denoise.h	12 May 2003 01:23:51 -0000	1.2
+++ speex_denoise.h	14 May 2003 04:37:00 -0000	1.3
@@ -55,17 +55,20 @@
    float *last_energy;       /**< Energy of the previous frames */
    float *last_ps;           /**< Power spectrum of the past frames */
    float *loudness_weight;   /**< */
-   int   last_id;            /**< */
+   int    last_id;           /**< */
 
    float *inbuf;             /**< Input buffer (overlapped analysis) */
    float *outbuf;            /**< Output buffer (for overlap and add) */
 
-   int nb_adapt;             /**< Number of frames used for adaptation so far */
-   int consec_noise;         /**< */
-   int nb_denoise;           /**< Number of frames processed so far */
-   int nb_min_estimate;      /**< */
-   int last_update;          /**< */
-   float min_ener;           /**< */
+   float  loudness;          /**< loudness estimate */
+   float  loudness2;          /**< loudness estimate */
+   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    consec_noise;      /**< Number of consecutive noise frames */
+   int    nb_denoise;        /**< Number of frames processed so far */
+   int    nb_min_estimate;   /**< */
+   int    last_update;       /**< */
+   float  min_ener;          /**< */
    drft_lookup fft_lookup;   /**< */
 
 } DenoiseState;

<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