From 2923b8b4bb04b21fe716b223038ab8c786748c10 Mon Sep 17 00:00:00 2001 From: paulfd Date: Sun, 29 Sep 2019 02:54:33 +0200 Subject: [PATCH] Cleaned up the delay calculation and actaully take it into account in the rendering step --- sfizz/Voice.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/sfizz/Voice.cpp b/sfizz/Voice.cpp index 86b75a6e..fff07961 100644 --- a/sfizz/Voice.cpp +++ b/sfizz/Voice.cpp @@ -96,10 +96,10 @@ void sfz::Voice::startVoice(Region* region, int delay, int channel, int number, // DBG("Base width: " << baseWidth << " - with modifier: " << width); sourcePosition = region->getOffset(); - // DBG("Offset: " << sourcePosition); - initialDelay = delay + static_cast(region->getDelay() / sampleRate); + DBG("Offset: " << sourcePosition); + initialDelay = delay + static_cast(region->getDelay() * sampleRate); baseFrequency = midiNoteFrequency(number) * pitchRatio; - prepareEGEnvelope(delay, value); + prepareEGEnvelope(initialDelay, value); } void sfz::Voice::prepareEGEnvelope(int delay, uint8_t velocity) noexcept @@ -236,15 +236,21 @@ void sfz::Voice::renderBlock(AudioSpan buffer) noexcept return; } + auto delay = min(static_cast(initialDelay), buffer.getNumFrames()); + auto delayed_buffer = buffer.subspan(delay); + initialDelay -= delay; + if (delayed_buffer.getNumFrames() == 0) + return; + if (region->isGenerator()) - fillWithGenerator(buffer); + fillWithGenerator(delayed_buffer); else - fillWithData(buffer); + fillWithData(delayed_buffer); if (region->isStereo()) - processStereo(buffer); + processStereo(delayed_buffer); else - processMono(buffer); + processMono(delayed_buffer); if (!egEnvelope.isSmoothing()) reset();