62#include "AudioBuffer.h"
63#include "DenormalGuard.h"
64#include "detail/TptSvf.h"
135 if (!(spec.sampleRate > 0.0))
return;
137 updateCoefficients();
148 const int nCh = std::min(buffer.getNumChannels(),
kMaxChannels);
149 const int nS = buffer.getNumSamples();
153 for (
int ch = 0; ch < nCh; ++ch)
155 T* data = buffer.getChannel(ch);
156 for (
int i = 0; i < nS; ++i)
157 data[i] = processOne(data[i], ch);
179 if (channel < 0 || channel >=
kMaxChannels)
return input;
180 return processOne(input, channel);
197 if (channel < 0 || channel >=
kMaxChannels)
return { input, T(0), T(0) };
198 return processCore(input, channel);
226 if (!std::isfinite(hz))
return;
228 updateCoefficients();
240 if (!std::isfinite(resonance))
return;
241 resonance_ = std::clamp(resonance, T(0), T(1));
244 R_ = T(1) / (T(2) * Q);
246 updateDerivedCoeffs();
260 if (!std::isfinite(q))
return;
261 q = std::max(q, T(0.01));
262 R_ = T(1) / (T(2) * q);
263 resonance_ = std::clamp((q - T(0.5)) / T(49.5), T(0), T(1));
265 updateDerivedCoeffs();
272 updateDerivedCoeffs();
281 if (!std::isfinite(dB))
return;
283 A_ = std::pow(T(10), std::abs(dB) / T(40));
285 updateDerivedCoeffs();
292 [[nodiscard]] T
getQ() const noexcept {
return T(1) / (T(2) *
R_); }
301 std::array<ChannelState, kMaxChannels>
state_ {};
325 void updateCoefficients() noexcept
331 g_ =
static_cast<T
>(std::tan(pi<double> *
static_cast<double>(
cutoff_)
335 updateDerivedCoeffs();
339 void updateBellR() noexcept
362 void updateDerivedCoeffs() noexcept
369 const T sqrtAs = std::sqrt((
gainDb_ >= T(0)) ?
A_ : T(1) /
A_);
374 a1_ = T(1) / (T(1) + T(2) *
effR_ * gEff + gEff * gEff);
380 [[nodiscard]] T processOne(T input,
int channel)
noexcept
382 const MultiOutput m = processCore(input, channel);
383 return selectOutput(input, m.lowpass, m.highpass, m.bandpass);
399 [[nodiscard]] MultiOutput processCore(T input,
int channel)
noexcept
402 return { output.lowpass, input - T(2) *
effR_ * output.bandpass - output.lowpass,
406 [[nodiscard]] T selectOutput(T input, T lp, T hp, T bp)
const noexcept
426 const T k = T(2) *
Rbell_;
428 ? input + (
A_ *
A_ - T(1)) * k * bp
429 : input + (T(1) / (
A_ *
A_) - T(1)) * k * bp;
440 const T twoR = T(2) *
R_;
441 return As * As * lp + As * twoR * bp + hp;
448 const T twoR = T(2) *
R_;
449 return lp + As * twoR * bp + As * As * hp;
Non-owning view over audio channel data.
RAII scope guard to disable denormalised (subnormal) floating-point numbers.
TPT State Variable Filter with simultaneous multi-output.
void setResonance(T resonance) noexcept
Sets the resonance amount.
void setCutoff(T hz) noexcept
Sets the cutoff/center frequency.
std::array< ChannelState, kMaxChannels > state_
void setQ(T q) noexcept
Sets the Q factor directly.
Mode getMode() const noexcept
T getGain() const noexcept
void reset() noexcept
Resets internal state.
~StateVariableFilter()=default
void setGain(T dB) noexcept
Sets gain for Bell/Shelf modes (in dB).
static constexpr int kMaxChannels
void setMode(Mode mode) noexcept
Sets the output mode.
MultiOutput processMultiOutput(T input, int channel) noexcept
Processes a single sample returning LP, HP, BP simultaneously.
void processBlock(AudioBufferView< T > buffer) noexcept
Processes an audio buffer in-place using the selected Mode.
Mode
Filter output mode for processBlock/processSample.
@ LowShelf
Low shelf (boost/cut below frequency).
@ BandPass
Bandpass (constant skirt gain).
@ AllPass
Allpass (phase shift, unity gain).
@ LowPass
2nd-order lowpass (12 dB/oct).
@ Bell
Parametric bell (boost/cut at frequency).
@ Notch
Band-reject (notch).
@ HighShelf
High shelf (boost/cut above frequency).
@ HighPass
2nd-order highpass (12 dB/oct).
T processSample(T input, int channel) noexcept
Processes a single sample (selected Mode output).
void prepare(const AudioSpec &spec) noexcept
Prepares the filter.
T getCutoff() const noexcept
T getResonance() const noexcept
TptSvfOutput< T > tptSvfStep(T input, TptSvfState< T > &state, T a1, T a2, T a3) noexcept
Advances the expanded Simper TPT recurrence by one sample.
Main namespace for the DSPark framework.
Describes the audio environment for a DSP processor.
double sampleRate
Sample rate in Hz.
Result struct for simultaneous multi-output processing.
Equivalent-current memories of the two trapezoidal integrators.