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

Jean-Marc Valin jm at xiph.org
Mon Sep 15 18:51:20 PDT 2003



jm          03/09/15 21:51:20

  Modified:    libspeex denoise.c
  Log:
  prevented the AGC from causing clipping

Revision  Changes    Path
1.23      +28 -4     speex/libspeex/denoise.c

Index: denoise.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/denoise.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- denoise.c	22 Aug 2003 21:30:58 -0000	1.22
+++ denoise.c	16 Sep 2003 01:51:20 -0000	1.23
@@ -441,6 +441,7 @@
    int i;
    int N = st->ps_size;
    float scale=.5/N;
+   float agc_gain;
 
    /** BEGIN AGC */
    if ((mean_prior>3&&mean_prior>3))
@@ -449,8 +450,12 @@
       float rate;
       st->nb_loudness_adapt++;
       rate=2.0/(1+st->nb_loudness_adapt);
-      if (rate < .01)
-         rate = .01;
+      if (rate < .005)
+         rate = .005;
+      if (rate < .1 && pow(loudness, LOUDNESS_EXP) > st->loudness)
+         rate = .1;
+      if (rate < .5 && pow(loudness, LOUDNESS_EXP) > 5*st->loudness)
+         rate = .5;
 
       for (i=2;i<N;i++)
       {
@@ -467,8 +472,11 @@
 
       /*fprintf (stderr, "%f %f %f\n", loudness, st->loudness2, rate);*/
    }
+   
+   agc_gain = 6000.0/st->loudness2;
+
    for (i=0;i<N;i++)
-      st->gain2[i] *= 6000.0/st->loudness2;
+      st->gain2[i] *= agc_gain;
    
 
    /** END AGC */
@@ -745,7 +753,23 @@
    drft_backward(&st->fft_lookup, st->frame);
 
    for (i=0;i<2*N;i++)
-      st->frame[i] *= scale*st->window[i];
+      st->frame[i] *= scale;
+
+   {
+      float max_sample=0;
+      for (i=0;i<2*N;i++)
+         if (fabs(st->frame[i])>max_sample)
+            max_sample = fabs(st->frame[i]);
+      if (max_sample>30000)
+      {
+         float damp = 30000./max_sample;
+         for (i=0;i<2*N;i++)
+            st->frame[i] *= damp;
+      }
+   }
+
+   for (i=0;i<2*N;i++)
+      st->frame[i] *= st->window[i];
 
    /* Perform overlap and add */
    for (i=0;i<N3;i++)

<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