[xiph-cvs] cvs commit: speex/libspeex mdf.c speex_echo.h

Jean-Marc Valin jm at xiph.org
Thu Aug 21 16:25:14 PDT 2003



jm          03/08/21 19:25:14

  Modified:    libspeex mdf.c speex_echo.h
  Log:
  first shot at dealing with cross-talk

Revision  Changes    Path
1.6       +31 -13    speex/libspeex/mdf.c

Index: mdf.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/mdf.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- mdf.c	21 Aug 2003 22:39:33 -0000	1.5
+++ mdf.c	21 Aug 2003 23:25:14 -0000	1.6
@@ -54,9 +54,11 @@
    drft_init(&st->fft_lookup, N);
    
    st->x = (float*)speex_alloc(N*sizeof(float));
+   st->d = (float*)speex_alloc(N*sizeof(float));
    st->y = (float*)speex_alloc(N*sizeof(float));
 
    st->X = (float*)speex_alloc(M*N*sizeof(float));
+   st->D = (float*)speex_alloc(N*sizeof(float));
    st->Y = (float*)speex_alloc(N*sizeof(float));
    st->E = (float*)speex_alloc(N*sizeof(float));
    st->W = (float*)speex_alloc(M*N*sizeof(float));
@@ -78,9 +80,11 @@
 {
    drft_clear(&st->fft_lookup);
    speex_free(st->x);
+   speex_free(st->d);
    speex_free(st->y);
 
    speex_free(st->X);
+   speex_free(st->D);
    speex_free(st->Y);
    speex_free(st->E);
    speex_free(st->W);
@@ -100,6 +104,7 @@
    int N,M;
    float scale;
    float powE=0, powY=0, powD=0;
+   float spectral_dist=0;
 
    N = st->window_size;
    M = st->M;
@@ -110,6 +115,9 @@
    {
       st->x[i] = st->x[i+st->frame_size];
       st->x[i+st->frame_size] = echo[i];
+
+      st->d[i] = st->d[i+st->frame_size];
+      st->d[i+st->frame_size] = ref[i];
    }
 
    /* Shift memory: this could be optimized eventually*/
@@ -138,18 +146,20 @@
       st->Y[N-1] += st->X[(j+1)*N-1]*st->W[(j+1)*N-1];
    }
 
-#if 1
-   if (Yout)
+   for (i=0;i<N;i++)
+      st->D[i]=st->d[i];
+   drft_forward(&st->fft_lookup, st->D);
+   for (i=1;i<N-1;i+=2)
    {
-      for (i=1,j=1;i<N-1;i+=2,j++)
-      {
-         Yout[j] =  st->X[(M-1)*N+i]*st->X[(M-1)*N+i] + st->X[(M-1)*N+i+1]*st->X[(M-1)*N+i+1];
-         Yout[j] *= .01;
-      }
-      Yout[0] = Yout[st->frame_size] = 0;
+      float Sdd, Syy, Sdy;
+      Sdd = 1e4 + st->D[i]*st->D[i] + st->D[i+1]*st->D[i+1];
+      Syy = 1e4 + st->Y[i]*st->Y[i] + st->Y[i+1]*st->Y[i+1];
+      Sdy = st->Y[i]*st->D[i] + st->Y[i+1]*st->D[i+1];
+      spectral_dist += Sdy/sqrt(Sdd*Syy);
    }
+   spectral_dist *= 2*scale;
+   /*printf ("%f\n", spectral_dist);*/
 
-#else
    if (Yout)
    {
       for (i=1,j=1;i<N-1;i+=2,j++)
@@ -158,7 +168,6 @@
       }
       Yout[0] = Yout[st->frame_size] = 0;
    }
-#endif
 
    for (i=0;i<N;i++)
       st->y[i] = st->Y[i];
@@ -273,7 +282,6 @@
       
 
 #if 0
-      /*st->PHI[0] = st->PHI[N-1] = 0;*/
       drft_backward(&st->fft_lookup, st->PHI);
       for (i=0;i<N;i++)
          st->PHI[i]*=scale;
@@ -293,8 +301,18 @@
    }
 
    if (st->cancel_count>2*M)
-      st->adapt_rate = .005;
-   else
+   {
+      if (st->cancel_count<8*M)
+      {
+         st->adapt_rate = .03;
+      } else {
+         st->adapt_rate = spectral_dist*.05;
+         if (st->adapt_rate>.03)
+            st->adapt_rate=.03;
+         if (st->adapt_rate<0)
+            st->adapt_rate=0;
+      }
+   } else
       st->adapt_rate = .0;
 
    /* Update weights */

<p><p>1.4       +2 -0      speex/libspeex/speex_echo.h

Index: speex_echo.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_echo.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- speex_echo.h	21 Aug 2003 04:25:36 -0000	1.3
+++ speex_echo.h	21 Aug 2003 23:25:14 -0000	1.4
@@ -41,6 +41,8 @@
 
    float *x;
    float *X;
+   float *d;
+   float *D;
    float *y;
    float *Y;
    float *E;

<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