Use the pepare() function to initialize filters
This commit is contained in:
parent
2d94810af2
commit
0173aa1e96
2 changed files with 27 additions and 38 deletions
|
|
@ -18,14 +18,22 @@ void sfz::EQHolder::reset()
|
||||||
|
|
||||||
void sfz::EQHolder::setup(const EQDescription& description, unsigned numChannels, uint8_t velocity)
|
void sfz::EQHolder::setup(const EQDescription& description, unsigned numChannels, uint8_t velocity)
|
||||||
{
|
{
|
||||||
reset();
|
|
||||||
eq.setChannels(numChannels);
|
eq.setChannels(numChannels);
|
||||||
this->description = &description;
|
this->description = &description;
|
||||||
const auto normalizedVelocity = normalizeVelocity(velocity);
|
const auto normalizedVelocity = normalizeVelocity(velocity);
|
||||||
|
|
||||||
|
// Setup the base values
|
||||||
|
baseFrequency = description.frequency + normalizedVelocity * description.vel2frequency;
|
||||||
baseBandwidth = description.bandwidth;
|
baseBandwidth = description.bandwidth;
|
||||||
baseGain = Default::eqGainRange.clamp(description.gain + normalizedVelocity * description.vel2gain);
|
baseGain = description.gain + normalizedVelocity * description.vel2gain;
|
||||||
baseFrequency = Default::eqFrequencyRange.clamp(description.frequency + normalizedVelocity * description.vel2frequency);
|
|
||||||
|
// Setup the modulated values
|
||||||
|
lastFrequency = midiState.modulate(baseFrequency, description.frequencyCC, Default::eqFrequencyRange);
|
||||||
|
lastBandwidth = midiState.modulate(baseBandwidth, description.bandwidthCC, Default::eqBandwidthRange);
|
||||||
|
lastGain = midiState.modulate(baseGain, description.gainCC, Default::eqGainRange);
|
||||||
|
|
||||||
|
// Initialize the EQ
|
||||||
|
eq.prepare(lastFrequency, lastBandwidth, lastGain);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::EQHolder::process(const float** inputs, float** outputs, unsigned numFrames)
|
void sfz::EQHolder::process(const float** inputs, float** outputs, unsigned numFrames)
|
||||||
|
|
@ -42,23 +50,9 @@ void sfz::EQHolder::process(const float** inputs, float** outputs, unsigned numF
|
||||||
|
|
||||||
// TODO: Once the midistate envelopes are done, add modulation in there!
|
// TODO: Once the midistate envelopes are done, add modulation in there!
|
||||||
// For now we take the last value
|
// For now we take the last value
|
||||||
lastFrequency = baseFrequency;
|
lastFrequency = midiState.modulate(baseFrequency, description->frequencyCC, Default::eqFrequencyRange);
|
||||||
for (auto& mod: description->frequencyCC) {
|
lastBandwidth = midiState.modulate(baseBandwidth, description->bandwidthCC, Default::eqBandwidthRange);
|
||||||
lastFrequency += midiState.getCCValue(mod.first) * mod.second;
|
lastGain = midiState.modulate(baseGain, description->gainCC, Default::eqGainRange);
|
||||||
}
|
|
||||||
lastFrequency = Default::eqFrequencyRange.clamp(lastFrequency);
|
|
||||||
|
|
||||||
lastBandwidth = baseBandwidth;
|
|
||||||
for (auto& mod: description->bandwidthCC) {
|
|
||||||
lastBandwidth += midiState.getCCValue(mod.first) * mod.second;
|
|
||||||
}
|
|
||||||
lastBandwidth = Default::eqBandwidthRange.clamp(lastBandwidth);
|
|
||||||
|
|
||||||
lastGain = baseGain;
|
|
||||||
for (auto& mod: description->gainCC) {
|
|
||||||
lastGain += midiState.getCCValue(mod.first) * mod.second;
|
|
||||||
}
|
|
||||||
lastGain = Default::eqGainRange.clamp(lastGain);
|
|
||||||
|
|
||||||
if (lastGain == 0.0f) {
|
if (lastGain == 0.0f) {
|
||||||
justCopy();
|
justCopy();
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ void sfz::FilterHolder::reset()
|
||||||
|
|
||||||
void sfz::FilterHolder::setup(const FilterDescription& description, unsigned numChannels, int noteNumber, uint8_t velocity)
|
void sfz::FilterHolder::setup(const FilterDescription& description, unsigned numChannels, int noteNumber, uint8_t velocity)
|
||||||
{
|
{
|
||||||
reset();
|
|
||||||
this->description = &description;
|
this->description = &description;
|
||||||
filter.setType(description.type);
|
filter.setType(description.type);
|
||||||
filter.setChannels(numChannels);
|
filter.setChannels(numChannels);
|
||||||
|
|
||||||
|
// Setup the base values
|
||||||
baseCutoff = description.cutoff;
|
baseCutoff = description.cutoff;
|
||||||
if (description.random != 0) {
|
if (description.random != 0) {
|
||||||
dist.param(filterRandomDist::param_type(0, description.random));
|
dist.param(filterRandomDist::param_type(0, description.random));
|
||||||
|
|
@ -37,6 +37,14 @@ void sfz::FilterHolder::setup(const FilterDescription& description, unsigned num
|
||||||
|
|
||||||
baseGain = description.gain;
|
baseGain = description.gain;
|
||||||
baseResonance = description.resonance;
|
baseResonance = description.resonance;
|
||||||
|
|
||||||
|
// Setup the modulated values
|
||||||
|
lastCutoff = midiState.modulate<float, int>(baseCutoff, description.cutoffCC, Default::filterCutoffRange, multiplyByCents);
|
||||||
|
lastResonance = midiState.modulate(baseResonance, description.resonanceCC, Default::filterResonanceRange);
|
||||||
|
baseGain = midiState.modulate(baseGain, description.gainCC, Default::filterGainRange);
|
||||||
|
|
||||||
|
// Initialize the filter
|
||||||
|
filter.prepare(lastCutoff, lastResonance, lastGain);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::FilterHolder::process(const float** inputs, float** outputs, unsigned numFrames)
|
void sfz::FilterHolder::process(const float** inputs, float** outputs, unsigned numFrames)
|
||||||
|
|
@ -49,23 +57,10 @@ void sfz::FilterHolder::process(const float** inputs, float** outputs, unsigned
|
||||||
|
|
||||||
// TODO: Once the midistate envelopes are done, add modulation in there!
|
// TODO: Once the midistate envelopes are done, add modulation in there!
|
||||||
// For now we take the last value
|
// For now we take the last value
|
||||||
lastCutoff = baseCutoff;
|
// TODO: the template deduction could be automatic here?
|
||||||
for (auto& mod: description->cutoffCC) {
|
lastCutoff = midiState.modulate<float, int>(baseCutoff, description->cutoffCC, Default::filterCutoffRange, multiplyByCents);
|
||||||
lastCutoff *= centsFactor(midiState.getCCValue(mod.first) * mod.second);
|
lastResonance = midiState.modulate(baseResonance, description->resonanceCC, Default::filterResonanceRange);
|
||||||
}
|
baseGain = midiState.modulate(baseGain, description->gainCC, Default::filterGainRange);
|
||||||
lastCutoff = Default::filterCutoffRange.clamp(lastCutoff);
|
|
||||||
|
|
||||||
lastResonance = baseResonance;
|
|
||||||
for (auto& mod: description->resonanceCC) {
|
|
||||||
lastResonance += midiState.getCCValue(mod.first) * mod.second;
|
|
||||||
}
|
|
||||||
lastResonance = Default::filterResonanceRange.clamp(lastResonance);
|
|
||||||
|
|
||||||
lastGain = baseGain;
|
|
||||||
for (auto& mod: description->gainCC) {
|
|
||||||
lastGain += midiState.getCCValue(mod.first) * mod.second;
|
|
||||||
}
|
|
||||||
lastGain = Default::filterGainRange.clamp(lastGain);
|
|
||||||
|
|
||||||
filter.process(inputs, outputs, lastCutoff, lastResonance, lastGain, numFrames);
|
filter.process(inputs, outputs, lastCutoff, lastResonance, lastGain, numFrames);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue