diff --git a/libs/sst/sst-basic-blocks b/libs/sst/sst-basic-blocks index 011c7fdb..e911cc27 160000 --- a/libs/sst/sst-basic-blocks +++ b/libs/sst/sst-basic-blocks @@ -1 +1 @@ -Subproject commit 011c7fdbbcf23edc7112da23fd6417fe09380e5f +Subproject commit e911cc275b8e140220ca4383d0ac43c3389fae3c diff --git a/src/engine/group.cpp b/src/engine/group.cpp index 14e90ce4..430b5d40 100644 --- a/src/engine/group.cpp +++ b/src/engine/group.cpp @@ -474,6 +474,8 @@ void Group::onSampleRateChanged() for (auto &z : zones) z->setSampleRate(getSampleRate(), getSampleRateInv()); + + this->setHasModulatorsSampleRate(getSampleRate(), getSampleRateInv()); } void Group::onProcessorTypeChanged(int w, dsp::processor::ProcessorType t) diff --git a/src/modulation/has_modulators.h b/src/modulation/has_modulators.h index e259b59b..e35c4325 100644 --- a/src/modulation/has_modulators.h +++ b/src/modulation/has_modulators.h @@ -45,7 +45,19 @@ static_assert(egsPerGroup == egsPerZone, "If this is false you need to template out the count below"); template struct HasModulators { - HasModulators(T *that) : eg{that, that}, egOS{that, that} {} + struct DoubleRate + { + double sampleRate, sampleRateInv; + T *that{nullptr}; + DoubleRate(T *that) : that(that) { resetRates(); } + void resetRates() + { + sampleRate = that->sampleRate * 2; + sampleRateInv = that->sampleRateInv / 2; + } + } doubleRate; + + HasModulators(T *that) : eg{that, that}, doubleRate{that}, egOS{&doubleRate, &doubleRate} {} static constexpr uint16_t lfosPerObject{lfosPerZone}; static constexpr uint16_t egsPerObject{egsPerZone}; @@ -66,7 +78,7 @@ template struct HasModulators ahdsrenv_t; typedef sst::basic_blocks::modulators::AHDSRShapedSC< - T, blockSize << 1, sst::basic_blocks::modulators::TwentyFiveSecondExp> + DoubleRate, (blockSize << 1), sst::basic_blocks::modulators::TwentyFiveSecondExp> ahdsrenvOS_t; ahdsrenv_t eg[egsPerObject]; @@ -74,6 +86,8 @@ template struct HasModulators std::array lfosActive{}; std::array egsActive{}; + + void setHasModulatorsSampleRate(double sr, double sri) { doubleRate.resetRates(); } }; } // namespace scxt::modulation::shared #endif // SHORTCIRCUITXT_HAS_MODULATORS_H diff --git a/src/voice/voice.cpp b/src/voice/voice.cpp index 7844b49a..631a43a3 100644 --- a/src/voice/voice.cpp +++ b/src/voice/voice.cpp @@ -794,4 +794,7 @@ void Voice::updateTransportPhasors() mul = mul / 2; } } + +void Voice::onSampleRateChanged() { setHasModulatorsSampleRate(samplerate, samplerate_inv); } + } // namespace scxt::voice diff --git a/src/voice/voice.h b/src/voice/voice.h index 5b2a486c..572ffc49 100644 --- a/src/voice/voice.h +++ b/src/voice/voice.h @@ -199,6 +199,8 @@ struct alignas(16) Voice : MoveableOnly, } void release() { isGated = false; } void cleanupVoice(); + + void onSampleRateChanged() override; }; } // namespace scxt::voice