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>
106 void process (
const ProcessContext& context)
noexcept
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)
112 processInternal<true, ProcessContext> (context);
114 processInternal<false, ProcessContext> (context);
126 default: jassertfalse;
129 return SampleType{0};
134 template <bool isBypassed, typename Parameters<NumericType>::Type type>
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)];
148 template <bool isBypassed, typename Parameters<NumericType>::Type type>
149 void processBlock (
const SampleType* input, SampleType* output,
size_t n)
noexcept
153 for (
size_t i = 0 ; i < n; ++i)
154 output[i] = processLoop<isBypassed, type> (input[i], state);
156 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
163 template <
bool isBypassed,
typename ProcessContext>
164 void processInternal (
const ProcessContext& context)
noexcept
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);
180 case Parameters<NumericType>::Type::lowPass: processBlock<isBypassed, Parameters<NumericType>::Type::lowPass> (src, dst, n);
break;
181 case Parameters<NumericType>::Type::bandPass: processBlock<isBypassed, Parameters<NumericType>::Type::bandPass> (src, dst, n);
break;
182 case Parameters<NumericType>::Type::highPass: processBlock<isBypassed, Parameters<NumericType>::Type::highPass> (src, dst, n);
break;
183 default: jassertfalse;
188 std::array<SampleType, 3> y;
192 JUCE_LEAK_DETECTOR (
Filter)