OpenShot Audio Library | OpenShotAudio: juce_StateVariableTPTFilter.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_StateVariableTPTFilter.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::dsp
27{
28
29enum class StateVariableTPTFilterType
30{
31 lowpass,
32 bandpass,
33 highpass
34};
35
36//==============================================================================
56template <typename SampleType>
57 class StateVariableTPTFilter
58{
59public:
60 //==============================================================================
61 using Type = StateVariableTPTFilterType;
62
63 //==============================================================================
65 StateVariableTPTFilter();
66
67 //==============================================================================
69 void setType (Type newType);
70
75 void setCutoffFrequency (SampleType newFrequencyHz);
76
83 void setResonance (SampleType newResonance);
84
85 //==============================================================================
87 Type getType() const noexcept { return filterType; }
88
90 SampleType getCutoffFrequency() const noexcept { return cutoffFrequency; }
91
93 SampleType getResonance() const noexcept { return resonance; }
94
95 //==============================================================================
97 void prepare (const ProcessSpec& spec);
98
100 void reset();
101
103 void reset (SampleType newValue);
104
109 void snapToZero() noexcept;
110
111 //==============================================================================
113 template <typename ProcessContext>
114 void process (const ProcessContext& context) noexcept
115 {
116 const auto& inputBlock = context.getInputBlock();
117 auto& outputBlock = context.getOutputBlock();
118 const auto numChannels = outputBlock.getNumChannels();
119 const auto numSamples = outputBlock.getNumSamples();
120
121 jassert (inputBlock.getNumChannels() <= s1.size());
122 jassert (inputBlock.getNumChannels() == numChannels);
123 jassert (inputBlock.getNumSamples() == numSamples);
124
125 if (context.isBypassed)
126 {
127 outputBlock.copyFrom (inputBlock);
128 return;
129 }
130
131 for (size_t channel = 0; channel < numChannels; ++channel)
132 {
133 auto* inputSamples = inputBlock .getChannelPointer (channel);
134 auto* outputSamples = outputBlock.getChannelPointer (channel);
135
136 for (size_t i = 0; i < numSamples; ++i)
137 outputSamples[i] = processSample ((int) channel, inputSamples[i]);
138 }
139
140 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
141 snapToZero();
142 #endif
143 }
144
145 //==============================================================================
147 SampleType processSample (int channel, SampleType inputValue);
148
149private:
150 //==============================================================================
151 void update();
152
153 //==============================================================================
154 SampleType g, h, R2;
155 std::vector<SampleType> s1 { 2 }, s2 { 2 };
156
157 double sampleRate = 44100.0;
158 Type filterType = Type::lowpass;
159 SampleType cutoffFrequency = static_cast<SampleType> (1000.0),
160 resonance = static_cast<SampleType> (1.0 / std::sqrt (2.0));
161};
162
163} // namespace juce::dsp
juce::dsp::StateVariableTPTFilter
Definition juce_StateVariableTPTFilter.h:58
juce::dsp::StateVariableTPTFilter::StateVariableTPTFilter
StateVariableTPTFilter()
Definition juce_StateVariableTPTFilter.cpp:31
juce::dsp::StateVariableTPTFilter::getResonance
SampleType getResonance() const noexcept
Definition juce_StateVariableTPTFilter.h:93
juce::dsp::StateVariableTPTFilter::snapToZero
void snapToZero() noexcept
Definition juce_StateVariableTPTFilter.cpp:90
juce::dsp::StateVariableTPTFilter::process
void process(const ProcessContext &context) noexcept
Definition juce_StateVariableTPTFilter.h:114
juce::dsp::StateVariableTPTFilter::setType
void setType(Type newType)
Definition juce_StateVariableTPTFilter.cpp:37
juce::dsp::StateVariableTPTFilter::prepare
void prepare(const ProcessSpec &spec)
Definition juce_StateVariableTPTFilter.cpp:62
juce::dsp::StateVariableTPTFilter::getCutoffFrequency
SampleType getCutoffFrequency() const noexcept
Definition juce_StateVariableTPTFilter.h:90
juce::dsp::StateVariableTPTFilter::setResonance
void setResonance(SampleType newResonance)
Definition juce_StateVariableTPTFilter.cpp:52
juce::dsp::StateVariableTPTFilter::reset
void reset()
Definition juce_StateVariableTPTFilter.cpp:77
juce::dsp::StateVariableTPTFilter::processSample
SampleType processSample(int channel, SampleType inputValue)
Definition juce_StateVariableTPTFilter.cpp:99
juce::dsp::StateVariableTPTFilter::setCutoffFrequency
void setCutoffFrequency(SampleType newFrequencyHz)
Definition juce_StateVariableTPTFilter.cpp:43
juce::dsp::StateVariableTPTFilter::getType
Type getType() const noexcept
Definition juce_StateVariableTPTFilter.h:87
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36