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

Jean-Marc Valin jm at xiph.org
Sun May 11 18:23:51 PDT 2003



jm          03/05/11 21:23:51

  Modified:    libspeex denoise.c smallft.h speex_denoise.h
  Log:
  made the code OK for inclusion with C++ files. Merge some early AGC work.

Revision  Changes    Path
1.4       +20 -1     speex/libspeex/denoise.c

Index: denoise.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/denoise.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- denoise.c	12 May 2003 01:02:19 -0000	1.3
+++ denoise.c	12 May 2003 01:23:51 -0000	1.4
@@ -114,7 +114,7 @@
    st->min_ps = (float*)speex_alloc(N*sizeof(float));
    st->last_energy = (float*)speex_alloc(STABILITY_TIME*sizeof(float));
    st->last_ps = (float*)speex_alloc(NB_LAST_PS*N*sizeof(float));
-
+   st->loudness_weight = (float*)speex_alloc(N*sizeof(float));
    st->inbuf = (float*)speex_alloc(N3*sizeof(float));
    st->outbuf = (float*)speex_alloc(N3*sizeof(float));
 
@@ -140,6 +140,13 @@
       st->outbuf[i]=0;
    }
 
+   for (i=0;i<N;i++)
+   {
+      float ff=((float)i)*128.0/4000.0;
+      st->loudness_weight[i] = .35-.35*ff/16000+.73*exp(-.5*(ff-3800)*(ff-3800)/9e5);
+      st->loudness_weight[i] *= st->loudness_weight[i];
+   }
+
    drft_init(&st->fft_lookup,2*N);
 
 
@@ -166,6 +173,7 @@
    speex_free(st->min_ps);
    speex_free(st->last_energy);
    speex_free(st->last_ps);
+   speex_free(st->loudness_weight);
 
    speex_free(st->inbuf);
    speex_free(st->outbuf);
@@ -403,6 +411,17 @@
          st->gain2[i]=.1;
    }
    st->gain2[N-1]=0;
+
+   {
+      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);
+      //if (st->consec_noise==0)
+      fprintf (stderr, "%f\n", loudness);
+   }
 
    /* Apply computed gain */
    for (i=1;i<N;i++)

<p><p>1.2       +9 -1      speex/libspeex/smallft.h

Index: smallft.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/smallft.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- smallft.h	8 May 2003 04:04:49 -0000	1.1
+++ smallft.h	12 May 2003 01:23:51 -0000	1.2
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: fft transform
- last mod: $Id: smallft.h,v 1.1 2003/05/08 04:04:49 jm Exp $
+ last mod: $Id: smallft.h,v 1.2 2003/05/12 01:23:51 jm Exp $
 
  ********************************************************************/
 
@@ -20,6 +20,10 @@
 
 /*#include "vorbis/codec.h"*/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct {
   int n;
   float *trigcache;
@@ -30,5 +34,9 @@
 extern void drft_backward(drft_lookup *l,float *data);
 extern void drft_init(drft_lookup *l,int n);
 extern void drft_clear(drft_lookup *l);
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif

<p><p>1.2       +9 -0      speex/libspeex/speex_denoise.h

Index: speex_denoise.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_denoise.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- speex_denoise.h	12 May 2003 01:02:19 -0000	1.1
+++ speex_denoise.h	12 May 2003 01:23:51 -0000	1.2
@@ -34,6 +34,10 @@
 
 #include "smallft.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct DenoiseState {
    int frame_size;           /**< Number of samples processed each time */
    int ps_size;              /**< Number of points in the power spectrum */
@@ -50,6 +54,7 @@
    float *min_ps;            /**< */
    float *last_energy;       /**< Energy of the previous frames */
    float *last_ps;           /**< Power spectrum of the past frames */
+   float *loudness_weight;   /**< */
    int   last_id;            /**< */
 
    float *inbuf;             /**< Input buffer (overlapped analysis) */
@@ -73,3 +78,7 @@
 
 /** Denoise a frame */
 int denoise(DenoiseState *st, float *x);
+
+#ifdef __cplusplus
+}
+#endif

<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