[xiph-commits] r11137 - in trunk/speex: include/speex libspeex

jm at svn.xiph.org jm at svn.xiph.org
Thu Apr 13 21:46:36 PDT 2006


Author: jm
Date: 2006-04-13 21:46:33 -0700 (Thu, 13 Apr 2006)
New Revision: 11137

Modified:
   trunk/speex/include/speex/speex_echo.h
   trunk/speex/libspeex/mdf.c
Log:
added speex_echo_capture() and speex_echo_playback() so the app doesn't need
to buffer playback audio.


Modified: trunk/speex/include/speex/speex_echo.h
===================================================================
--- trunk/speex/include/speex/speex_echo.h	2006-04-14 03:53:48 UTC (rev 11136)
+++ trunk/speex/include/speex/speex_echo.h	2006-04-14 04:46:33 UTC (rev 11137)
@@ -61,8 +61,14 @@
 void speex_echo_state_destroy(SpeexEchoState *st);
 
 /** Performs echo cancellation a frame */
-void speex_echo_cancel(SpeexEchoState *st, spx_int16_t *ref, spx_int16_t *echo, spx_int16_t *out, spx_int32_t *Y);
+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 */
+void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out, spx_int32_t *Yout);
+
+/** Performs echo cancellation a frame */
+void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play);
+
 /** Reset the echo canceller state */
 void speex_echo_state_reset(SpeexEchoState *st);
 

Modified: trunk/speex/libspeex/mdf.c
===================================================================
--- trunk/speex/libspeex/mdf.c	2006-04-14 03:53:48 UTC (rev 11136)
+++ trunk/speex/libspeex/mdf.c	2006-04-14 04:46:33 UTC (rev 11137)
@@ -140,9 +140,13 @@
    spx_word16_t preemph;
    spx_word16_t notch_radius;
    spx_mem_t notch_mem[2];
+
+   /* NOTE: If you only use speex_echo_cancel() and want to save some memory, remove this */
+   spx_int16_t *play_buf;
+   int play_buf_pos;
 };
 
-static inline void filter_dc_notch16(spx_int16_t *in, spx_word16_t radius, spx_word16_t *out, int len, spx_mem_t *mem)
+static inline void filter_dc_notch16(const spx_int16_t *in, spx_word16_t radius, spx_word16_t *out, int len, spx_mem_t *mem)
 {
    int i;
    spx_word16_t den2;
@@ -332,6 +336,10 @@
    st->notch_mem[0] = st->notch_mem[1] = 0;
    st->adapted = 0;
    st->Pey = st->Pyy = FLOAT_ONE;
+   
+   st->play_buf = (spx_int16_t*)speex_alloc(2*st->frame_size*sizeof(spx_int16_t));
+   st->play_buf_pos = 0;
+
    return st;
 }
 
@@ -388,9 +396,40 @@
    speex_free(st);
 }
 
-extern int fixed_point;
+void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out, spx_int32_t *Yout)
+{
+   if (st->play_buf_pos>=st->frame_size)
+   {
+      st->play_buf_pos -= 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;
+      }
+   }
+   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)
+{
+   if (st->play_buf_pos<=st->frame_size)
+   {
+      int i;
+      for (i=0;i<st->frame_size;i++)
+         st->play_buf[st->play_buf_pos+i] = play[i];
+      st->play_buf_pos += st->frame_size;
+   } else {
+      speex_warning("had to discard a playback frame");
+   }
+}
+
 /** Performs echo cancellation on a frame */
-void speex_echo_cancel(SpeexEchoState *st, spx_int16_t *ref, spx_int16_t *echo, spx_int16_t *out, spx_int32_t *Yout)
+void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *ref, const spx_int16_t *echo, spx_int16_t *out, spx_int32_t *Yout)
 {
    int i,j;
    int N,M;



More information about the commits mailing list