Cache ids for faster lookup

This commit is contained in:
Paul Fd 2021-04-02 14:51:56 +02:00
parent 646ca14164
commit 2c31855137
2 changed files with 18 additions and 5 deletions

View file

@ -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<float> 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

View file

@ -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)