
class MyFilter
{
public:
void reset() noexcept;
void prepare(const juce::dsp::ProcessSpec& inSpec) noexcept;
float processLowCut(const int inChannel,
const float inSample,
const float inCutoff) noexcept;
float processHighCut(const int inChannel,
const float inSample,
const float inCutoff) noexcept;
private:
juce::dsp::StateVariableTPTFilter<float> mLowCutfilter;
juce::dsp::StateVariableTPTFilter<float> mHighCutfilter;
};
MyFilter::MyFilter()
{
mLowCutfilter.setType(juce::dsp::StateVariableTPTFilterType::highpass);
mHighCutfilter.setType(juce::dsp::StateVariableTPTFilterType::lowpass);
}
void MyFilter::reset() noexcept
{
mLowCutfilter.reset();
mHighCutfilter.reset();
}
juce::dsp::StateVariableTPTFilter's reset() initializes the data in filter. It is recommended it is located in PrepareToplay() and reset() in PiuginProcessor.
void MyFilter::prepare(const juce::dsp::ProcessSpec& inSpec) noexcept
{
mLowCutfilter.prepare(inSpec);
mHighCutfilter.prepare(inSpec);
}
struct ProcessSpec
{
/** The sample rate that will be used for the data that is sent to the processor. */
double sampleRate;
/** The maximum number of samples that will be in the blocks sent to process() method. */
uint32 maximumBlockSize;
/** The number of channels that the process() method will be expected to handle. */
uint32 numChannels;
};
float MyFilter::processLowCut(const int inChannel,
const float inSample,
const float inCutoff) noexcept
{
mLowCutfilter.setCutoffFrequency(inCutoff);
return mLowCutfilter.processSample(inChannel, inSample);
}