Setup the filters and EQ from the region
This commit is contained in:
parent
dc4f59107b
commit
bebd398e39
5 changed files with 41 additions and 39 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include "SfzFilter.h"
|
||||
#include "EQDescription.h"
|
||||
#include "Region.h"
|
||||
#include "Resources.h"
|
||||
#include "utility/SpinMutex.h"
|
||||
#include <vector>
|
||||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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<float>(description.veltrack) * velocity;
|
||||
const auto veltrack = static_cast<float>(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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<int>(Default::filterKeycenter), float velocity = 0);
|
||||
void setup(const Region& region, unsigned filterId, int noteNumber = static_cast<int>(Default::filterKeycenter), float velocity = 0);
|
||||
/**
|
||||
* @brief Process a block of stereo inputs
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue