Fixed ring buffer (not, it's not the same as a stack!) in the new API. Some
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Tue, 18 Apr 2006 08:35:23 +0000 (08:35 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Tue, 18 Apr 2006 08:35:23 +0000 (08:35 +0000)
comments too.

git-svn-id: http://svn.xiph.org/trunk/speex@11162 0101bb08-14d6-0310-b084-bc0e0c8e3800

include/speex/speex_echo.h
libspeex/mdf.c

index f8a95c2..4813b5a 100644 (file)
@@ -63,10 +63,10 @@ void speex_echo_state_destroy(SpeexEchoState *st);
 /** Performs echo cancellation a frame */
 void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out, spx_int32_t *Yout);
 
-/** Performs echo cancellation a frame */
+/** Perform echo cancellation using internal playback buffer */
 void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out, spx_int32_t *Yout);
 
-/** Performs echo cancellation a frame */
+/** Let the echo canceller know that a frame was just played */
 void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play);
 
 /** Reset the echo canceller state */
index 1a9e951..fe96d80 100644 (file)
@@ -398,21 +398,23 @@ void speex_echo_state_destroy(SpeexEchoState *st)
 
 void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out, spx_int32_t *Yout)
 {
+   int i;
    if (st->play_buf_pos>=st->frame_size)
    {
+      speex_echo_cancel(st, rec, st->play_buf, out, Yout);
       st->play_buf_pos -= st->frame_size;
+      for (i=0;i<st->frame_size;i++)
+         st->play_buf[i] = st->play_buf[i+st->frame_size];
    } else {
-      int i;
       speex_warning("no playback frame available");
-      for (i=0;i<st->frame_size;i++)
-         st->play_buf[i] = 0;
       if (st->play_buf_pos!=0)
       {
          speex_warning("internal playback buffer corruption?");
          st->play_buf_pos = 0;
       }
+      for (i=0;i<st->frame_size;i++)
+         out[i] = rec[i];
    }
-   speex_echo_cancel(st, rec, st->play_buf+st->play_buf_pos, out, Yout);
 }
 
 void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play)