From 6156022628f484642d4276997a6879c86ce677d6 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 4 Oct 2020 17:32:44 +0200 Subject: [PATCH 1/2] this use of getSourcePosition is wrong (sourcePosition is not increased if e.g. the voice is a generator for example) To avoid this I removed the API which has really no purpose --- src/sfizz/Synth.cpp | 2 +- src/sfizz/Voice.cpp | 5 ----- src/sfizz/Voice.h | 6 ------ 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index b191d841..2d8b01d6 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -1018,7 +1018,7 @@ void sfz::Synth::checkNotePolyphony(const Region* region, int delay, const Trigg } break; case SfzSelfMask::dontMask: - if (!selfMaskCandidate || selfMaskCandidate->getSourcePosition() < voice->getSourcePosition()) + if (!selfMaskCandidate || selfMaskCandidate->getAge() < voice->getAge()) selfMaskCandidate = voice; break; } diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 4a0fc5b0..4afc7bc2 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -856,11 +856,6 @@ bool sfz::Voice::releasedOrFree() const noexcept return state != State::playing || egAmplitude.isReleased(); } -uint32_t sfz::Voice::getSourcePosition() const noexcept -{ - return sourcePosition; -} - void sfz::Voice::setMaxFiltersPerVoice(size_t numFilters) { if (numFilters == filters.size()) diff --git a/src/sfizz/Voice.h b/src/sfizz/Voice.h index 9d5bfceb..70e5fb74 100644 --- a/src/sfizz/Voice.h +++ b/src/sfizz/Voice.h @@ -248,12 +248,6 @@ public: * @return float */ float getAveragePower() const noexcept; - /** - * @brief Get the position of the voice in the source, in samples - * - * @return uint32_t - */ - uint32_t getSourcePosition() const noexcept; /** * Returns the region that is currently playing. May be null if the voice is not active! * From 0046bb69e64817ef9be9c36f4f2fb4271208252d Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 4 Oct 2020 17:32:58 +0200 Subject: [PATCH 2/2] Set the proper oversampling factor for the initial offset --- src/sfizz/Voice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 4afc7bc2..27323c6d 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -97,6 +97,7 @@ void sfz::Voice::startVoice(Region* region, int delay, const TriggerEvent& event return; } speedRatio = static_cast(currentPromise->sampleRate / this->sampleRate); + sourcePosition = region->getOffset(currentPromise->oversamplingFactor); } // do Scala retuning and reconvert the frequency into a 12TET key number @@ -123,7 +124,6 @@ void sfz::Voice::startVoice(Region* region, int delay, const TriggerEvent& event equalizers[i].setup(*region, i, triggerEvent.value); } - sourcePosition = region->getOffset(); triggerDelay = delay; initialDelay = delay + static_cast(region->getDelay() * sampleRate); baseFrequency = resources.tuning.getFrequencyOfKey(triggerEvent.number);