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

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



jm          03/09/17 00:12:14

  Modified:    libspeex preprocess.c speex_preprocess.h
  Log:
  based the AGC adaptation decision on the MCRA stuff.

Revision  Changes    Path
1.7       +27 -11    speex/libspeex/preprocess.c

Index: preprocess.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/preprocess.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- preprocess.c	17 Sep 2003 00:15:12 -0000	1.6
+++ preprocess.c	17 Sep 2003 04:12:13 -0000	1.7
@@ -110,7 +110,8 @@
    N = st->ps_size;
    N3 = 2*N - st->frame_size;
    N4 = st->frame_size - N3;
-
+   
+   st->sampling_rate = sampling_rate;
    st->denoise_enabled = 1;
    st->agc_enabled = 0;
    st->agc_level = 8000;
@@ -452,19 +453,33 @@
    int N = st->ps_size;
    float scale=.5/N;
    float agc_gain;
+   int freq_start, freq_end;
+   float active_bands = 0;
+
+   freq_start = (int)(300.0*2*N/st->sampling_rate);
+   freq_end   = (int)(2000.0*2*N/st->sampling_rate);
+   for (i=freq_start;i<freq_end;i++)
+   {
+      if (st->S[i] > 20*st->Smin[i]+1000)
+         active_bands+=1;
+   }
+   active_bands /= (freq_end-freq_start+1);
+   /*fprintf (stderr, "%f\n", active_bands);*/
 
-   if ((mean_prior>3&&mean_prior>3))
+   if (active_bands > .3)
    {
       float loudness=0;
-      float rate;
+      float rate, rate2=.03;
       st->nb_loudness_adapt++;
       rate=2.0/(1+st->nb_loudness_adapt);
-      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;
+      if (rate < .02)
+         rate = .02;
+      if (rate < .07 && pow(loudness, LOUDNESS_EXP) > st->loudness)
+         rate = .07;
+      if (rate < .15 && pow(loudness, LOUDNESS_EXP) > 3*st->loudness)
+         rate = .15;
+      if (rate < .3 && pow(loudness, LOUDNESS_EXP) > 10*st->loudness)
+         rate = .3;
 
       for (i=2;i<N;i++)
       {
@@ -475,7 +490,7 @@
         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);
+      st->loudness2 = (1-rate2)*st->loudness2 + rate2*pow(st->loudness, 1.0/LOUDNESS_EXP);
 
       loudness = pow(st->loudness, 1.0/LOUDNESS_EXP);
 
@@ -525,7 +540,7 @@
 {
    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];
    
@@ -557,6 +572,7 @@
       /*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)

<p><p>1.7       +1 -0      speex/libspeex/speex_preprocess.h

Index: speex_preprocess.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_preprocess.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- speex_preprocess.h	17 Sep 2003 00:15:12 -0000	1.6
+++ speex_preprocess.h	17 Sep 2003 04:12:13 -0000	1.7
@@ -41,6 +41,7 @@
 typedef struct SpeexPreprocessState {
    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 */
    
    /* parameters */
    int    denoise_enabled;

<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