30template <
typename SampleType>
36template <
typename SampleType>
39 filterType = newValue;
42template <
typename SampleType>
47 cutoffFrequency = newCutoffFrequencyHz;
51template <
typename SampleType>
54 jassert (newResonance >
static_cast<SampleType
> (0));
56 resonance = newResonance;
61template <
typename SampleType>
76template <
typename SampleType>
79 reset (
static_cast<SampleType
> (0));
82template <
typename SampleType>
85 for (
auto v : { &s1, &s2 })
86 std::fill (v->begin(), v->end(), newValue);
89template <
typename SampleType>
92 for (
auto v : { &s1, &s2 })
93 for (
auto& element : *v)
94 util::snapToZero (element);
98template <
typename SampleType>
101 auto& ls1 = s1[(
size_t) channel];
102 auto& ls2 = s2[(
size_t) channel];
104 auto yHP = h * (inputValue - ls1 * (g + R2) - ls2);
106 auto yBP = yHP * g + ls1;
109 auto yLP = yBP * g + ls2;
114 case Type::lowpass:
return yLP;
115 case Type::bandpass:
return yBP;
116 case Type::highpass:
return yHP;
122template <
typename SampleType>
126 R2 =
static_cast<SampleType
> (1.0 / resonance);
127 h =
static_cast<SampleType
> (1.0 / (1.0 + R2 * g + g * g));
131template class StateVariableTPTFilter<float>;
132template class StateVariableTPTFilter<double>;
An IIR filter that can perform low, band and high-pass filtering on an audio signal,...
StateVariableTPTFilter()
Constructor.
void snapToZero() noexcept
Ensure that the state variables are rounded to zero if the state variables are denormals.
void setType(Type newType)
Sets the filter type.
void prepare(const ProcessSpec &spec)
Initialises the filter.
void setResonance(SampleType newResonance)
Sets the resonance of the filter.
void reset()
Resets the internal state variables of the filter.
SampleType processSample(int channel, SampleType inputValue)
Processes one sample at a time on a given channel.
void setCutoffFrequency(SampleType newFrequencyHz)
Sets the cutoff frequency of the filter.
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
Commonly used mathematical constants.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
uint32 numChannels
The number of channels that the process() method will be expected to handle.
double sampleRate
The sample rate that will be used for the data that is sent to the processor.