Index: include/mediastreamer2/msinterfaces.h
===================================================================
--- include/mediastreamer2/msinterfaces.h	(revision 1276)
+++ include/mediastreamer2/msinterfaces.h	(revision 1332)
@@ -101,9 +101,4 @@
 	MS_FILTER_METHOD(MSFilterEchoCancellerInterface,2,int)
 
-
-/** Interface definitions for video decoders */
-#define MS_VIDEO_DECODER_DECODING_ERRORS \
-		MS_FILTER_EVENT_NO_ARG(MSFilterVideoDecoderInterface,0)
-
 /** put filter in bypass mode */
 #define MS_ECHO_CANCELLER_SET_BYPASS_MODE \
@@ -112,4 +107,10 @@
 #define MS_ECHO_CANCELLER_GET_BYPASS_MODE \
 	MS_FILTER_METHOD(MSFilterEchoCancellerInterface,4,bool_t)
+
+
+
+/** Interface definitions for video decoders */
+#define MS_VIDEO_DECODER_DECODING_ERRORS \
+		MS_FILTER_EVENT_NO_ARG(MSFilterVideoDecoderInterface,0)
 #endif
 
Index: src/speexec.c
===================================================================
--- src/speexec.c	(revision 1331)
+++ src/speexec.c	(revision 1332)
@@ -33,6 +33,9 @@
 
 //#define EC_DUMP 1
-
+#ifdef ANDROID
 #define EC_DUMP_PREFIX "/sdcard"
+#else
+#define EC_DUMP_PREFIX "/dynamic/tests"
+#endif
 
 static const float smooth_factor=0.05;
@@ -55,4 +58,5 @@
 	FILE *echofile;
 	FILE *reffile;
+	FILE *cleanfile;
 #endif
 	bool_t echostarted;
@@ -84,4 +88,7 @@
 		s->reffile=fopen(fname,"w");
 		ms_free(fname);
+		fname=ms_strdup_printf("%s/msspeexec-%p-clean.raw", EC_DUMP_PREFIX,f);
+		s->cleanfile=fopen(fname,"w");
+		ms_free(fname);
 	}
 #endif
@@ -123,4 +130,5 @@
 	ms_bufferizer_put (&s->delayed_ref,m);
 	s->min_ref_samples=-1;
+	s->nominal_ref_samples=delay_samples;
 }
 
@@ -194,4 +202,8 @@
 		speex_echo_cancellation(s->ecstate,(short*)echo,(short*)ref,(short*)oecho->b_wptr);
 		speex_preprocess_run(s->den, (short*)oecho->b_wptr);
+#ifdef EC_DUMP
+		if (s->cleanfile)
+			fwrite(oecho->b_wptr,nbytes,1,s->cleanfile);
+#endif
 		oecho->b_wptr+=nbytes;
 		ms_queue_put(f->outputs[1],oecho);
@@ -202,6 +214,7 @@
 		int diff=s->min_ref_samples-s->nominal_ref_samples;
 		if (diff>nbytes){
-			ms_warning("echo canceller: we are accumulating too much reference signal, purging now %i bytes",nbytes);
-			ms_bufferizer_skip_bytes(&s->delayed_ref,nbytes);
+			int purge=diff-(nbytes/2);
+			ms_warning("echo canceller: we are accumulating too much reference signal, purging now %i bytes",purge);
+			ms_bufferizer_skip_bytes(&s->delayed_ref,purge);
 		}
 		s->min_ref_samples=-1;
@@ -262,5 +275,5 @@
 	{	MS_ECHO_CANCELLER_SET_TAIL_LENGTH	,	speex_ec_set_tail_length	},
 	{	MS_ECHO_CANCELLER_SET_DELAY		,	speex_ec_set_delay		},
-	{	MS_ECHO_CANCELLER_SET_FRAMESIZE	,	speex_ec_set_framesize		},
+	{	MS_ECHO_CANCELLER_SET_FRAMESIZE		,	speex_ec_set_framesize		},
 	{	MS_ECHO_CANCELLER_SET_BYPASS_MODE	,	speex_ec_set_bypass_mode		},
 	{	MS_ECHO_CANCELLER_GET_BYPASS_MODE	,	speex_ec_get_bypass_mode		},
