From 7d98349e1606190344a03a97e98d540ef433b544 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 13 May 2020 15:17:03 +0200 Subject: [PATCH] Internally check that a change is needed or not --- lv2/sfizz.c | 11 ----------- src/sfizz/Synth.cpp | 13 +++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lv2/sfizz.c b/lv2/sfizz.c index c5d0c3c3..59f5b1a8 100644 --- a/lv2/sfizz.c +++ b/lv2/sfizz.c @@ -950,10 +950,6 @@ work(LV2_Handle instance, else if (atom->type == self->sfizz_num_voices_uri) { const int num_voices = *(const int *)LV2_ATOM_BODY_CONST(atom); - if (sfizz_get_num_voices(self->synth) == num_voices) { - return LV2_WORKER_SUCCESS; // Nothing to do - } - sfizz_set_num_voices(self->synth, num_voices); if (sfizz_get_num_voices(self->synth) == num_voices) { lv2_log_note(&self->logger, "[sfizz] Number of voices changed to: %d\n", num_voices); @@ -964,9 +960,6 @@ work(LV2_Handle instance, else if (atom->type == self->sfizz_preload_size_uri) { const unsigned int preload_size = *(const unsigned int *)LV2_ATOM_BODY_CONST(atom); - if (sfizz_get_preload_size(self->synth) == preload_size) - return LV2_WORKER_SUCCESS; // Nothing to do - sfizz_set_preload_size(self->synth, preload_size); if (sfizz_get_preload_size(self->synth) == preload_size) { lv2_log_note(&self->logger, "[sfizz] Preload size changed to: %d\n", preload_size); @@ -978,10 +971,6 @@ work(LV2_Handle instance, { const sfizz_oversampling_factor_t oversampling = *(const sfizz_oversampling_factor_t *)LV2_ATOM_BODY_CONST(atom); - if (sfizz_get_oversampling_factor(self->synth) == oversampling) { - return LV2_WORKER_SUCCESS; // Nothing to do - } - sfizz_set_oversampling_factor(self->synth, oversampling); if (sfizz_get_oversampling_factor(self->synth) == oversampling) { lv2_log_note(&self->logger, "[sfizz] Oversampling changed to: %d\n", oversampling); diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index f3c9e2cf..7267a1c1 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -1054,6 +1054,11 @@ void sfz::Synth::setNumVoices(int numVoices) noexcept { ASSERT(numVoices > 0); const std::lock_guard disableCallback { callbackGuard }; + + // fast path + if (numVoices == this->numVoices) + return; + resetVoices(numVoices); } @@ -1077,6 +1082,10 @@ void sfz::Synth::setOversamplingFactor(sfz::Oversampling factor) noexcept { const std::lock_guard disableCallback { callbackGuard }; + // fast path + if (factor == oversamplingFactor) + return; + for (auto& voice : voices) voice->reset(); @@ -1094,6 +1103,10 @@ void sfz::Synth::setPreloadSize(uint32_t preloadSize) noexcept { const std::lock_guard disableCallback { callbackGuard }; + // fast path + if (preloadSize == resources.filePool.getPreloadSize()) + return; + resources.filePool.setPreloadSize(preloadSize); }