From 7b42e070a2bc67db14c87f2ea8a44b6ec5a8d93e Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Fri, 19 Mar 2021 11:24:02 +0100 Subject: [PATCH] Clamp the crossfade to the available samples before the loop starts --- src/sfizz/Voice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 34b98c8d..55bde31c 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -1540,6 +1540,8 @@ void Voice::Impl::updateLoopInformation() noexcept loop_.start = static_cast(region_->loopStart(factor)); loop_.size = loop_.end + 1 - loop_.start; loop_.xfSize = static_cast(lroundPositive(region_->loopCrossfade * rate)); + // Clamp the crossfade to the part available before the loop starts + loop_.xfSize = min(loop_.start, loop_.xfSize); loop_.xfOutStart = loop_.end + 1 - loop_.xfSize; loop_.xfInStart = loop_.start - loop_.xfSize; }