/**************************************************************************
Copyright (C) 2019 Arnaud Champenois arthelion@free.fr
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#pragma once
#include "TimeVariant.h"
class TVF : public TimeVariant {
public:
TVF(const TVFParameters&tvfParam) :
TimeVariant(tvfParam), mTVFParam(tvfParam) {}
virtual ~TVF() override;
virtual void init(double sampleRate) override;
double next(double value) {
if (mLowCutFrequency > TVFLowestCutoffFrequency)
value = mLowCutFilter.processSample(value);
if (!isActive() && isLFOBypassed() && mCutoffCtrlOffset == 0.0f) {
moveLFO(1.0);
value = mFilter.processSample(value);
}
else {
double cutoff = (nextFreqADSR(false)*mCutoffValue+mCutoffCtrlOffset)*nextLFO();
if (cutoff < TVFLowestCutoffFrequency)
return 0.0;
if (cutoff > mMaxCutoff)
cutoff = mMaxCutoff;
mFilter.parameters->setCutOffFrequency(mSampleRate, cutoff, mResonanceValue);
value = mFilter.processSample(value);
}
if (mMidGain != 0.0f) {
value = mBandFilter.processSample(value);
}
return value;
}
void updateInternalValues(int controller = 0) override;
private:
juce::dsp::StateVariableFilter::Filter<double> mFilter;
juce::dsp::StateVariableFilter::Filter<double> mLowCutFilter;
juce::dsp::IIR::Filter<double> mBandFilter;
//Parameters
const TVFParameters& mTVFParam;
// Current values
double mLowCutFrequency = 0.0;
double mCutoffValue = TVFHighestCutoffFrequency;
double mMaxCutoff = TVFHighestCutoffFrequency;
double mResonanceValue = TVFDefaultResonance;
float mMidFreq = 0.0f, mMidGain = 0.0f, mMidQ = 0.0f;
float mCutoffCtrlOffset = 0.0f;
};