--- audioecho.c.old	2012-10-25 18:55:46.000000000 +0800
+++ audioecho.c	2013-07-10 21:32:38.982105938 +0800
@@ -187,10 +187,12 @@
   switch (prop_id) {
     case PROP_DELAY:{
       guint64 max_delay, delay;
-
+      guint rate, bpf, new_size;
+      
       g_mutex_lock (&self->lock);
       delay = g_value_get_uint64 (value);
       max_delay = self->max_delay;
+      rate = GST_AUDIO_FILTER_RATE (self);
 
       if (delay > max_delay && GST_STATE (self) > GST_STATE_READY) {
         GST_WARNING_OBJECT (self, "New delay (%" GST_TIME_FORMAT ") "
@@ -200,7 +202,22 @@
       } else {
         self->delay = delay;
         self->max_delay = MAX (delay, max_delay);
+        if(self->max_delay>max_delay) {
+          bpf = GST_AUDIO_FILTER_BPF (self);
+          self->buffer_size_frames = MAX (gst_util_uint64_scale (self->max_delay, rate, GST_SECOND), 1);
+          new_size = self->buffer_size_frames * bpf;
+          self->buffer = g_realloc (self->buffer, new_size);
+          
+          if(new_size > self->buffer_size) {
+            memset (self->buffer + self->buffer_size, 0, new_size - self->buffer_size);
+          }
+          
+          self->buffer_size = new_size;
+        }
       }
+      
+      self->delay_frames = MAX (gst_util_uint64_scale (self->delay, rate, GST_SECOND), 1);
+            
       g_mutex_unlock (&self->lock);
       break;
     }
