[xiph-cvs] cvs commit: speex/libspeex speex_denoise.h denoise.c testdenoise.c mdf.c
Jean-Marc Valin
jm at xiph.org
Thu Aug 21 22:10:47 PDT 2003
jm 03/08/22 01:10:47
Modified: libspeex speex_denoise.h denoise.c testdenoise.c mdf.c
Log:
Coupling between the echo canceller and the denoiser so that residual
echo can be removed.
Revision Changes Path
1.7 +4 -1 speex/libspeex/speex_denoise.h
Index: speex_denoise.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_denoise.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- speex_denoise.h 22 May 2003 16:25:33 -0000 1.6
+++ speex_denoise.h 22 Aug 2003 05:10:47 -0000 1.7
@@ -55,6 +55,9 @@
float *last_energy; /**< Energy of the previous frames */
float *last_ps; /**< Power spectrum of the past frames */
float *loudness_weight; /**< */
+
+ float *echo_noise;
+
int last_id; /**< */
float *noise_bands;
@@ -89,7 +92,7 @@
void speex_denoise_state_destroy(SpeexDenoiseState *st);
/** Denoise a frame */
-int speex_denoise(SpeexDenoiseState *st, float *x);
+int speex_denoise(SpeexDenoiseState *st, float *x, float *noise);
#ifdef __cplusplus
}
<p><p>1.21 +33 -12 speex/libspeex/denoise.c
Index: denoise.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/denoise.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- denoise.c 19 Aug 2003 06:07:44 -0000 1.20
+++ denoise.c 22 Aug 2003 05:10:47 -0000 1.21
@@ -128,6 +128,7 @@
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));
+ st->echo_noise = (float*)speex_alloc(N*sizeof(float));
st->noise_bands = (float*)speex_alloc(NB_BANDS*sizeof(float));
st->noise_bands2 = (float*)speex_alloc(NB_BANDS*sizeof(float));
@@ -201,6 +202,12 @@
speex_free(st->last_energy);
speex_free(st->last_ps);
speex_free(st->loudness_weight);
+ speex_free(st->echo_noise);
+
+ speex_free(st->noise_bands);
+ speex_free(st->noise_bands2);
+ speex_free(st->speech_bands);
+ speex_free(st->speech_bands2);
speex_free(st->inbuf);
speex_free(st->outbuf);
@@ -210,7 +217,7 @@
speex_free(st);
}
-static void update_noise(SpeexDenoiseState *st, float *ps)
+static void update_noise(SpeexDenoiseState *st, float *ps, float *echo)
{
int i;
float beta;
@@ -219,11 +226,21 @@
if (beta < .05)
beta=.05;
- for (i=0;i<st->ps_size;i++)
- st->noise[i] = (1-beta)*st->noise[i] + beta*ps[i];
+ if (!echo)
+ {
+ for (i=0;i<st->ps_size;i++)
+ st->noise[i] = (1-beta)*st->noise[i] + beta*ps[i];
+ } else {
+ for (i=0;i<st->ps_size;i++)
+ st->noise[i] = (1-beta)*st->noise[i] + beta*max(0,ps[i]-echo[i]);
+#if 0
+ for (i=0;i<st->ps_size;i++)
+ st->noise[i] = 0;
+#endif
+ }
}
-int speex_denoise(SpeexDenoiseState *st, float *x)
+int speex_denoise(SpeexDenoiseState *st, float *x, float *echo)
{
int i;
int is_speech=0;
@@ -282,7 +299,7 @@
std = sqrt(E2-E*E);
if (std<.15 && st->last_update>20)
{
- update_noise(st, &st->last_ps[st->last_id*N]);
+ update_noise(st, &st->last_ps[st->last_id*N], echo);
}
/*fprintf (stderr, "%f\n", std);*/
}
@@ -327,14 +344,18 @@
if (st->nb_adapt<15)
/*if (st->nb_adapt<25 && st->nb_adapt>15)*/
{
- update_noise(st, ps);
+ update_noise(st, ps, echo);
st->last_update=0;
}
+ if (echo)
+ for (i=1;i<N;i++)
+ st->echo_noise[i] = (.7*st->echo_noise[i] + .3* 2*echo[i]);
+
/* Compute a posteriori SNR */
for (i=1;i<N;i++)
{
- st->post[i] = ps[i]/(1+st->noise[i]) - 1;
+ st->post[i] = ps[i]/(1+st->noise[i]+st->echo_noise[i]) - 1;
if (st->post[i]>100)
st->post[i]=100;
/*if (st->post[i]<0)
@@ -370,17 +391,17 @@
if (min_gamma<.01)
min_gamma = .01;
#endif
- /*min_gamma = .2;*/
+ min_gamma = .6;
if (gamma<min_gamma)
gamma=min_gamma;
-
+
for (i=1;i<N;i++)
{
/* A priori SNR update */
st->prior[i] = gamma*max(0.0,st->post[i]) +
- (1-gamma)*st->gain[i]*st->gain[i]*st->old_ps[i]/st->noise[i];
+ (1-gamma)*st->gain[i]*st->gain[i]*st->old_ps[i]/(1+st->noise[i]+st->echo_noise[i]);
if (st->prior[i]>100)
st->prior[i]=100;
@@ -612,7 +633,7 @@
if (st->consec_noise>=3)
{
- update_noise(st, st->old_ps);
+ update_noise(st, st->old_ps, echo);
st->last_update=0;
} else {
st->last_update++;
@@ -694,7 +715,7 @@
}
for (i=0;i<N;i++)
st->gain2[i] *= 6000.0/st->loudness2;
-
+
#if 0
if (!is_speech)
{
<p><p>1.6 +2 -2 speex/libspeex/testdenoise.c
Index: testdenoise.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testdenoise.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- testdenoise.c 21 May 2003 21:20:25 -0000 1.5
+++ testdenoise.c 22 Aug 2003 05:10:47 -0000 1.6
@@ -1,7 +1,7 @@
#include "speex_denoise.h"
#include <stdio.h>
-#define NN 240
+#define NN 160
int main()
{
@@ -21,7 +21,7 @@
for (i=0;i<NN;i++)
x[i]=in[i];
- vad = speex_denoise(st, x);
+ vad = speex_denoise(st, x, NULL);
for (i=0;i<NN;i++)
out[i]=x[i];
fprintf (stderr, "%d\n", vad);
<p><p>1.7 +6 -4 speex/libspeex/mdf.c
Index: mdf.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/mdf.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- mdf.c 21 Aug 2003 23:25:14 -0000 1.6
+++ mdf.c 22 Aug 2003 05:10:47 -0000 1.7
@@ -167,6 +167,8 @@
Yout[j] = st->Y[i]*st->Y[i] + st->Y[i+1]*st->Y[i+1];
}
Yout[0] = Yout[st->frame_size] = 0;
+ for (i=0;i<=st->frame_size;i++)
+ Yout[i] *= .08;
}
for (i=0;i<N;i++)
@@ -304,11 +306,11 @@
{
if (st->cancel_count<8*M)
{
- st->adapt_rate = .03;
+ st->adapt_rate = .5/M;
} else {
- st->adapt_rate = spectral_dist*.05;
- if (st->adapt_rate>.03)
- st->adapt_rate=.03;
+ st->adapt_rate = spectral_dist*(1.0/M);
+ if (st->adapt_rate>.5/M)
+ st->adapt_rate=.5/M;
if (st->adapt_rate<0)
st->adapt_rate=0;
}
<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