From 32f981b1f65e2067cbbe50960fd041236a86a556 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 2 Feb 2023 16:27:43 +0100 Subject: [PATCH] Fix Buffr Glitch for crossfade lengths of 1 sample --- plugins/buffr_glitch/src/buffer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/buffr_glitch/src/buffer.rs b/plugins/buffr_glitch/src/buffer.rs index 7c668419..7ba82c88 100644 --- a/plugins/buffr_glitch/src/buffer.rs +++ b/plugins/buffr_glitch/src/buffer.rs @@ -121,8 +121,10 @@ impl RingBuffer { } BufferStatus::Crossfading if self.next_sample_pos < self.crossfade_length => { // This is an equal power fade between the part of the input after the first loop - // and the buffer's existing contents. - let crossfade_t = self.next_sample_pos as f32 / (self.crossfade_length - 1) as f32; + // and the buffer's existing contents. The `.max(1)` is needed to avoid NaNs with + // crossfade lengths of 1 sample. + let crossfade_t = + self.next_sample_pos as f32 / (self.crossfade_length - 1).max(1) as f32; let new_t = (1.0 - crossfade_t).sqrt(); let existing_t = crossfade_t.sqrt();