diff --git a/delay.c b/delay.c
index 91236c9..f9a6ea8 100644
--- a/delay.c
+++ b/delay.c
@@ -30,7 +30,9 @@ void delay_set_time(
     }
 
     delay->duration = new_duration;
-    delay->buf_idx %= new_duration;
+    if( new_duration > 0 ) {
+        delay->buf_idx %= new_duration;
+    }
 }
 
 void delay_process(