From 14377a1230ec6ef83cf9cebb2aa58ad4d60733d9 Mon Sep 17 00:00:00 2001 From: VoidX Date: Mon, 27 Nov 2023 18:05:16 +0100 Subject: [PATCH] Safe delaying --- Cavern/Utilities/WaveformUtils.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Cavern/Utilities/WaveformUtils.cs b/Cavern/Utilities/WaveformUtils.cs index 41a7d277..09d518a3 100644 --- a/Cavern/Utilities/WaveformUtils.cs +++ b/Cavern/Utilities/WaveformUtils.cs @@ -28,8 +28,13 @@ public static unsafe void ClearChannel(float[] signal, int channel, int channels /// Apply a delay of a given number of on a . /// public static void Delay(float[] waveform, int samples) { - Array.Copy(waveform, 0, waveform, samples, waveform.Length - samples); - Array.Clear(waveform, 0, samples); + int count = waveform.Length - samples; + if (count > 0) { + Array.Copy(waveform, 0, waveform, samples, count); + Array.Clear(waveform, 0, samples); + } else { + Array.Clear(waveform, 0, waveform.Length); + } } ///