From a5b8bfb6ac31a5f762943c09b9379ecaa2e1b91d Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 8 Dec 2019 18:11:17 +0100 Subject: [PATCH] Added a freewheeling option to the synth --- src/sfizz.h | 3 ++- src/sfizz/Synth.cpp | 3 +++ src/sfizz/Synth.h | 4 ++++ src/sfizz/sfizz_wrapper.cpp | 12 ++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/sfizz.h b/src/sfizz.h index 0f155850..869b10c9 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -324,7 +324,8 @@ int sfizz_get_num_buffers(sfizz_synth_t* synth); */ int sfizz_get_num_bytes(sfizz_synth_t* synth); - +void sfizz_enable_freewheeling(sfizz_synth_t* synth); +void sfizz_disable_freewheeling(sfizz_synth_t* synth); #ifdef __cplusplus } #endif diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 68ca29d1..401c1610 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -351,6 +351,9 @@ void sfz::Synth::renderBlock(AudioSpan buffer) noexcept resources.filePool.cleanupPromises(); + if (freeWheeling) + resources.filePool.waitForBackgroundLoading(); + AtomicGuard callbackGuard { inCallback }; if (!canEnterCallback) return; diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 2f91b189..ce181284 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -324,6 +324,9 @@ public: * @return The allocated bytes. */ int getAllocatedBytes() const noexcept { return Buffer::counter().getTotalBytes(); } + + void enableFreeWheeling() { freeWheeling = true; } + void disableFreeWheeling() { freeWheeling = true; } protected: /** * @brief The parser callback; this is called by the parent object each time @@ -419,6 +422,7 @@ private: // Atomic guards; must be used with AtomicGuard and AtomicDisabler std::atomic canEnterCallback { true }; std::atomic inCallback { false }; + bool freeWheeling { false }; // Singletons passed as references to the voices Resources resources; diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 2fccaa34..5b27a7b4 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -204,6 +204,18 @@ int sfizz_get_num_bytes(sfizz_synth_t* synth) return self->getAllocatedBytes(); } +void sfizz_enable_freewheeling(sfizz_synth_t* synth) +{ + auto self = reinterpret_cast(synth); + self->enableFreeWheeling(); +} + +void sfizz_disable_freewheeling(sfizz_synth_t* synth) +{ + auto self = reinterpret_cast(synth); + self->enableFreeWheeling(); +} + #ifdef __cplusplus } #endif