Skip to content

Commit

Permalink
Safe delaying
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Nov 27, 2023
1 parent 8213a60 commit 14377a1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Cavern/Utilities/WaveformUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ public static unsafe void ClearChannel(float[] signal, int channel, int channels
/// Apply a delay of a given number of <paramref name="samples"/> on a <paramref name="waveform"/>.
/// </summary>
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);
}
}

/// <summary>
Expand Down

0 comments on commit 14377a1

Please sign in to comment.