From bebd398e3976e2e1763a0f29736d98fa63d0e4fa Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 16 Sep 2020 13:56:37 +0200 Subject: [PATCH] Setup the filters and EQ from the region --- src/sfizz/EQPool.cpp | 22 ++++++++++++---------- src/sfizz/EQPool.h | 12 ++++++------ src/sfizz/FilterPool.cpp | 29 +++++++++++++++-------------- src/sfizz/FilterPool.h | 12 ++++++------ src/sfizz/Voice.cpp | 5 ++--- 5 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/sfizz/EQPool.cpp b/src/sfizz/EQPool.cpp index 7e42546b..20267647 100644 --- a/src/sfizz/EQPool.cpp +++ b/src/sfizz/EQPool.cpp @@ -16,31 +16,33 @@ void sfz::EQHolder::reset() eq->clear(); } -void sfz::EQHolder::setup(const EQDescription& description, unsigned numChannels, float velocity) +void sfz::EQHolder::setup(const Region& region, unsigned eqId, float velocity) { ASSERT(velocity >= 0.0f && velocity <= 1.0f); - eq->setType(description.type); - eq->setChannels(numChannels); - this->description = &description; + ASSERT(eqId < region.equalizers.size()); + + this->description = ®ion.equalizers[eqId]; + eq->setType(description->type); + eq->setChannels(region.isStereo() ? 2 : 1); // Setup the base values - baseFrequency = description.frequency + velocity * description.vel2frequency; - baseBandwidth = description.bandwidth; - baseGain = description.gain + velocity * description.vel2gain; + baseFrequency = description->frequency + velocity * description->vel2frequency; + baseBandwidth = description->bandwidth; + baseGain = description->gain + velocity * description->vel2gain; // Setup the modulated values float lastFrequency = baseFrequency; - for (const auto& mod : description.frequencyCC) + for (const auto& mod : description->frequencyCC) lastFrequency += resources.midiState.getCCValue(mod.cc) * mod.data; lastFrequency = Default::eqFrequencyRange.clamp(lastFrequency); float lastBandwidth = baseBandwidth; - for (const auto& mod : description.bandwidthCC) + for (const auto& mod : description->bandwidthCC) lastBandwidth += resources.midiState.getCCValue(mod.cc) * mod.data; lastBandwidth = Default::eqBandwidthRange.clamp(lastBandwidth); float lastGain = baseGain; - for (const auto& mod : description.gainCC) + for (const auto& mod : description->gainCC) lastGain += resources.midiState.getCCValue(mod.cc) * mod.data; lastGain = Default::filterGainRange.clamp(lastGain); diff --git a/src/sfizz/EQPool.h b/src/sfizz/EQPool.h index 5b61c096..dc4b65fa 100644 --- a/src/sfizz/EQPool.h +++ b/src/sfizz/EQPool.h @@ -1,6 +1,6 @@ #pragma once #include "SfzFilter.h" -#include "EQDescription.h" +#include "Region.h" #include "Resources.h" #include "utility/SpinMutex.h" #include @@ -16,13 +16,13 @@ public: EQHolder() = delete; EQHolder(const Resources& resources); /** - * @brief Setup a new EQ based on an EQ description. + * @brief Setup a new EQ from a region and an index * - * @param description the EQ description - * @param numChannels the number of channels for the EQ - * @param description the triggering velocity/value + * @param description the region from which we take the EQ + * @param eqId the EQ index in the region + * @param description the triggering velocity/value */ - void setup(const EQDescription& description, unsigned numChannels, float velocity); + void setup(const Region& region, unsigned eqId, float velocity); /** * @brief Process a block of stereo inputs * diff --git a/src/sfizz/FilterPool.cpp b/src/sfizz/FilterPool.cpp index de271a06..5362e8a3 100644 --- a/src/sfizz/FilterPool.cpp +++ b/src/sfizz/FilterPool.cpp @@ -17,42 +17,43 @@ void sfz::FilterHolder::reset() filter->clear(); } -void sfz::FilterHolder::setup(const FilterDescription& description, unsigned numChannels, int noteNumber, float velocity) +void sfz::FilterHolder::setup(const Region& region, unsigned filterId, int noteNumber, float velocity) { ASSERT(velocity >= 0.0f && velocity <= 1.0f); + ASSERT(filterId < region.filters.size()); - this->description = &description; - filter->setType(description.type); - filter->setChannels(numChannels); + this->description = ®ion.filters[filterId]; + filter->setType(description->type); + filter->setChannels(region.isStereo() ? 2 : 1); // Setup the base values - baseCutoff = description.cutoff; - if (description.random != 0) { - dist.param(filterRandomDist::param_type(0, description.random)); + baseCutoff = description->cutoff; + if (description->random != 0) { + dist.param(filterRandomDist::param_type(0, description->random)); baseCutoff *= centsFactor(dist(Random::randomGenerator)); } - const auto keytrack = description.keytrack * (noteNumber - description.keycenter); + const auto keytrack = description->keytrack * (noteNumber - description->keycenter); baseCutoff *= centsFactor(keytrack); - const auto veltrack = static_cast(description.veltrack) * velocity; + const auto veltrack = static_cast(description->veltrack) * velocity; baseCutoff *= centsFactor(veltrack); baseCutoff = Default::filterCutoffRange.clamp(baseCutoff); - baseGain = description.gain; - baseResonance = description.resonance; + baseGain = description->gain; + baseResonance = description->resonance; // Setup the modulated values float lastCutoff = baseCutoff; - for (const auto& mod : description.cutoffCC) + for (const auto& mod : description->cutoffCC) lastCutoff *= centsFactor(resources.midiState.getCCValue(mod.cc) * mod.data); lastCutoff = Default::filterCutoffRange.clamp(lastCutoff); float lastResonance = baseResonance; - for (const auto& mod : description.resonanceCC) + for (const auto& mod : description->resonanceCC) lastResonance += resources.midiState.getCCValue(mod.cc) * mod.data; lastResonance = Default::filterResonanceRange.clamp(lastResonance); float lastGain = baseGain; - for (const auto& mod : description.gainCC) + for (const auto& mod : description->gainCC) lastGain += resources.midiState.getCCValue(mod.cc) * mod.data; lastGain = Default::filterGainRange.clamp(lastGain); diff --git a/src/sfizz/FilterPool.h b/src/sfizz/FilterPool.h index c926f196..b3709cea 100644 --- a/src/sfizz/FilterPool.h +++ b/src/sfizz/FilterPool.h @@ -1,6 +1,6 @@ #pragma once #include "SfzFilter.h" -#include "FilterDescription.h" +#include "Region.h" #include "Resources.h" #include "Defaults.h" #include "utility/SpinMutex.h" @@ -19,12 +19,12 @@ public: /** * @brief Setup a new filter based on a filter description, and a triggering note parameters. * - * @param description the filter description - * @param numChannels the number of channels - * @param noteNumber the triggering note number - * @param velocity the triggering note velocity/value + * @param description the region from which we take the filter + * @param filterId the filter index in the region + * @param noteNumber the triggering note number + * @param velocity the triggering note velocity/value */ - void setup(const FilterDescription& description, unsigned numChannels, int noteNumber = static_cast(Default::filterKeycenter), float velocity = 0); + void setup(const Region& region, unsigned filterId, int noteNumber = static_cast(Default::filterKeycenter), float velocity = 0); /** * @brief Process a block of stereo inputs * diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 6cc473d0..d080db37 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -121,13 +121,12 @@ void sfz::Voice::startVoice(Region* region, int delay, const TriggerEvent& event gainSmoother.reset(); resetCrossfades(); - const unsigned numChannels = region->isStereo() ? 2 : 1; for (unsigned i = 0; i < region->filters.size(); ++i) { - filters[i].setup(region->filters[i], numChannels, triggerEvent.number, triggerEvent.value); + filters[i].setup(*region, i, triggerEvent.number, triggerEvent.value); } for (unsigned i = 0; i < region->equalizers.size(); ++i) { - equalizers[i].setup(region->equalizers[i], numChannels, triggerEvent.value); + equalizers[i].setup(*region, i, triggerEvent.value); } sourcePosition = region->getOffset();