From 2c3185513750d7b2c3008b0e698d82d83de3a90b Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Fri, 2 Apr 2021 14:51:56 +0200 Subject: [PATCH] Cache ids for faster lookup --- src/sfizz/LFO.cpp | 16 ++++++++++++---- src/sfizz/modulations/ModMatrix.cpp | 7 ++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/sfizz/LFO.cpp b/src/sfizz/LFO.cpp index 334d2379..5ec9aab7 100644 --- a/src/sfizz/LFO.cpp +++ b/src/sfizz/LFO.cpp @@ -31,6 +31,9 @@ struct LFO::Impl { // control const LFODescription* desc_ = nullptr; + ModMatrix::TargetId beatsKeyId; + ModMatrix::TargetId freqKeyId; + ModMatrix::TargetId phaseKeyId; // state size_t delayFramesLeft_ = 0; @@ -57,7 +60,12 @@ void LFO::setSampleRate(double sampleRate) void LFO::configure(const LFODescription* desc) { - impl_->desc_ = desc ? desc : &LFODescription::getDefault(); + Impl& impl = *impl_; + ModMatrix& modMatrix = impl.resources_.modMatrix; + impl.desc_ = desc ? desc : &LFODescription::getDefault(); + impl.beatsKeyId = modMatrix.findTarget(desc->beatsKey); + impl.freqKeyId = modMatrix.findTarget(desc->freqKey); + impl.phaseKeyId = modMatrix.findTarget(desc->phaseKey); } void LFO::start(unsigned triggerDelay) @@ -336,9 +344,9 @@ void LFO::generatePhase(unsigned nth, absl::Span phases) const float* phaseMod = nullptr; // Note(jpc) we might switch between beats and frequency, if host // switches play state on and off; continually generate both. - beatsMod = modMatrix.getModulationByKey(desc.beatsKey); - freqMod = modMatrix.getModulationByKey(desc.freqKey); - phaseMod = modMatrix.getModulationByKey(desc.phaseKey); + beatsMod = modMatrix.getModulation(impl.beatsKeyId); + freqMod = modMatrix.getModulation(impl.freqKeyId); + phaseMod = modMatrix.getModulation(impl.phaseKeyId); if (beatClock.isPlaying() && beats > 0) { // generate using the beat clock diff --git a/src/sfizz/modulations/ModMatrix.cpp b/src/sfizz/modulations/ModMatrix.cpp index 7c64244f..35ab05f7 100644 --- a/src/sfizz/modulations/ModMatrix.cpp +++ b/src/sfizz/modulations/ModMatrix.cpp @@ -39,6 +39,7 @@ struct ModMatrix::Impl { struct ConnectionData { float sourceDepth_ {}; ModKey sourceDepthMod_ {}; + TargetId sourceDepthModId_ {}; float velToDepth_ {}; }; @@ -207,6 +208,10 @@ bool ModMatrix::connect(SourceId sourceId, TargetId targetId, float sourceDepth, Impl::ConnectionData& conn = target.connectedSources[sourceIndex]; conn.sourceDepth_ = sourceDepth; conn.sourceDepthMod_ = sourceDepthMod; + + if (sourceDepthMod) + conn.sourceDepthModId_ = registerTarget(sourceDepthMod); + conn.velToDepth_ = velToDepth; return true; @@ -414,7 +419,7 @@ float* ModMatrix::getModulation(TargetId targetId) sourceDepth += triggerValue * velToDepth; } - const float* sourceDepthMod = getModulationByKey(sourcesPos->second.sourceDepthMod_); + const float* sourceDepthMod = getModulation(sourcesPos->second.sourceDepthModId_); if (isFirstSource) { if (sourceDepth == 1 && !sourceDepthMod)