[JUCE API] HighPass& LowPass

SangHoon You·2025년 5월 30일
0

JUCE API

목록 보기
17/17
post-thumbnail

In this post, I'll show how to implement high-pass and low-pass filter using juce::dsp::StateVariableTPTFilter

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);
}
  • mLowCutFilter is configured as a high-pass filter
  • mHighCutFilter is configured as a low-pass filter

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;
};
  • StateVariableTPTFilter's prepare() get the structor juce::dsp::ProcessSpec as a pamrameter, which involves samplerate, buffersize and channel.
  • It have to be initialized before internal processing. Generally, it is performed in PrepareToplay().

float MyFilter::processLowCut(const int inChannel,
                              const float inSample,
                              const float inCutoff) noexcept
{
    mLowCutfilter.setCutoffFrequency(inCutoff);
    return mLowCutfilter.processSample(inChannel, inSample);
}        
  • In audio plugin, cutoff frequency should be adjustable in real time. setCutoffFrequency() allow cutoff frequency to be varied.
  • processLowCut() sets the cutoff frequency of the filter using the provided channel, sample, and cutoff value, then returns the filtered sample.
  • Since the filter must pass every sample sequentially, the filtering function should be called inside processBlock().

profile
Audio Plugin Developer

0개의 댓글