31 template <
typename NumericType>
54 template <
typename SampleType>
62 using NumericType =
typename SampleTypeHelpers::ElementType<SampleType>::Type;
70 [[
deprecated (
"The classes in the StateVariableFilter namespace are deprecated. you should "
71 "use the equivalent functionality in the StateVariableTPTFilter class.")]]
75 [[
deprecated (
"The classes in the StateVariableFilter namespace are deprecated. you should "
76 "use the equivalent functionality in the StateVariableTPTFilter class.")]]
91 void reset() noexcept { s1 = s2 = SampleType {0}; }
97 void snapToZero() noexcept { util::snapToZero (s1); util::snapToZero (s2); }
105 template <
typename ProcessContext>
108 static_assert (std::is_same_v<typename ProcessContext::SampleType, SampleType>,
109 "The sample-type of the filter must match the sample-type supplied to this process callback");
111 if (context.isBypassed)
129 return SampleType{0};
137 y[2] = (sample - s1 * state.R2 - s1 * state.g - s2) * state.h;
139 y[1] = y[2] * state.g + s1;
140 s1 = y[2] * state.g + y[1];
142 y[0] = y[1] * state.g + s2;
143 s2 = y[1] * state.g + y[0];
145 return isBypassed ? sample : y[
static_cast<size_t> (type)];
149 void processBlock (
const SampleType* input, SampleType* output,
size_t n)
noexcept
153 for (
size_t i = 0 ; i < n; ++i)
156 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
163 template <
bool isBypassed,
typename ProcessContext>
166 auto&& inputBlock = context.getInputBlock();
167 auto&& outputBlock = context.getOutputBlock();
171 jassert (inputBlock.getNumChannels() == 1);
172 jassert (outputBlock.getNumChannels() == 1);
174 auto n = inputBlock.getNumSamples();
175 auto* src = inputBlock .getChannelPointer (0);
176 auto*
dst = outputBlock.getChannelPointer (0);
195 enum class StateVariableFilterType
208 template <
typename NumericType>
212 using Type = StateVariableFilterType;
233 h =
static_cast<NumericType> (1.0 / (1.0 + R2 * g + g * g));
A smart-pointer class which points to a reference-counted object.
An IIR filter that can perform low, band and high-pass filtering on an audio signal,...
Parameters< NumericType >::Ptr parameters
The parameters of the state variable filter.
typename Parameters< NumericType >::Ptr ParametersPtr
A typedef for a ref-counted pointer to the coefficients object.
void prepare(const ProcessSpec &) noexcept
Initialization of the filter.
void reset() noexcept
Resets the filter's processing pipeline.
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType sample) noexcept
Processes a single sample, without any locking or checking.
Filter(const Filter &)=default
Creates a copy of another filter.
void snapToZero() noexcept
Ensure that the state variables are rounded to zero if the state variables are denormals.
typename SampleTypeHelpers::ElementType< SampleType >::Type NumericType
The NumericType is the underlying primitive type used by the SampleType (which could be either a prim...
Filter(Filter &&)=default
Move constructor.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
bool isBypassed(const ProcessorChain< Processors... > &chain) noexcept
Non-member equivalent of ProcessorChain::isBypassed which avoids awkward member template syntax.
Classes for state variable filter processing.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Commonly used mathematical constants.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
This is a handy base class for the state of a processor (such as parameter values) which is typically...
Structure used for the state variable filter parameters.
void setCutOffFrequency(double sampleRate, NumericType frequency, NumericType resonance=static_cast< NumericType >(1.0/MathConstants< double >::sqrt2)) noexcept
Sets the cutoff frequency and resonance of the IIR filter.
Type type
The type of the IIR filter.