13template <
typename T =
float>
58template <
typename T =
float>
73 this->lambda = 1 / tau;
93template <
typename T =
float>
107 this->lambda = 1 / tau;
132template <
typename T =
float>
159template <
typename T =
float>
174 this->riseLambda = 1 / riseTau;
175 this->fallLambda = 1 / fallTau;
179 T y =
out + (in -
out) * lambda * deltaTime;
195template <
int B_ORDER,
int A_ORDER,
typename T =
float>
203 T
a[A_ORDER - 1] = {};
218 for (
int i = 1; i < B_ORDER; i++) {
221 for (
int i = 1; i < A_ORDER; i++) {
227 for (
int i = 0; i < B_ORDER; i++) {
230 for (
int i = 1; i < A_ORDER; i++) {
231 this->a[i - 1] =
a[i - 1];
241 for (
int i = 1; i < B_ORDER; i++) {
242 out +=
b[i] *
x[i - 1];
245 for (
int i = 1; i < A_ORDER; i++) {
246 out -=
a[i - 1] *
y[i - 1];
249 for (
int i = B_ORDER - 1; i >= 2; i--) {
254 for (
int i = A_ORDER - 1; i >= 2; i--) {
266 std::complex<T> bSum(
b[0], 0);
267 std::complex<T> aSum(1, 0);
268 for (
int i = 1; i < std::max(B_ORDER, A_ORDER); i++) {
270 std::complex<T> z(simd::cos(p), simd::sin(p));
274 aSum +=
a[i - 1] * z;
292template <
typename T =
float>
317 float K = std::tan(M_PI * f);
320 this->
a[0] = -std::exp(-2.f * M_PI * f);
322 this->
b[0] = 1.f + this->
a[0];
328 this->
a[0] = std::exp(-2.f * M_PI * (0.5f - f));
330 this->
b[0] = 1.f - this->
a[0];
336 float norm = 1.f / (1.f + K / Q + K * K);
337 this->
b[0] = K * K * norm;
338 this->
b[1] = 2.f * this->
b[0];
339 this->
b[2] = this->
b[0];
340 this->
a[0] = 2.f * (K * K - 1.f) * norm;
341 this->
a[1] = (1.f - K / Q + K * K) * norm;
345 float norm = 1.f / (1.f + K / Q + K * K);
347 this->
b[1] = -2.f * this->
b[0];
348 this->
b[2] = this->
b[0];
349 this->
a[0] = 2.f * (K * K - 1.f) * norm;
350 this->
a[1] = (1.f - K / Q + K * K) * norm;
355 float sqrtV = std::sqrt(V);
357 float norm = 1.f / (1.f + M_SQRT2 * K + K * K);
358 this->
b[0] = (1.f + M_SQRT2 * sqrtV * K + V * K * K) * norm;
359 this->
b[1] = 2.f * (V * K * K - 1.f) * norm;
360 this->
b[2] = (1.f - M_SQRT2 * sqrtV * K + V * K * K) * norm;
361 this->
a[0] = 2.f * (K * K - 1.f) * norm;
362 this->
a[1] = (1.f - M_SQRT2 * K + K * K) * norm;
365 float norm = 1.f / (1.f + M_SQRT2 / sqrtV * K + K * K / V);
366 this->
b[0] = (1.f + M_SQRT2 * K + K * K) * norm;
367 this->
b[1] = 2.f * (K * K - 1) * norm;
368 this->
b[2] = (1.f - M_SQRT2 * K + K * K) * norm;
369 this->
a[0] = 2.f * (K * K / V - 1.f) * norm;
370 this->
a[1] = (1.f - M_SQRT2 / sqrtV * K + K * K / V) * norm;
375 float sqrtV = std::sqrt(V);
377 float norm = 1.f / (1.f + M_SQRT2 * K + K * K);
378 this->
b[0] = (V + M_SQRT2 * sqrtV * K + K * K) * norm;
379 this->
b[1] = 2.f * (K * K - V) * norm;
380 this->
b[2] = (V - M_SQRT2 * sqrtV * K + K * K) * norm;
381 this->
a[0] = 2.f * (K * K - 1.f) * norm;
382 this->
a[1] = (1.f - M_SQRT2 * K + K * K) * norm;
385 float norm = 1.f / (1.f / V + M_SQRT2 / sqrtV * K + K * K);
386 this->
b[0] = (1.f + M_SQRT2 * K + K * K) * norm;
387 this->
b[1] = 2.f * (K * K - 1.f) * norm;
388 this->
b[2] = (1.f - M_SQRT2 * K + K * K) * norm;
389 this->
a[0] = 2.f * (K * K - 1.f / V) * norm;
390 this->
a[1] = (1.f / V - M_SQRT2 / sqrtV * K + K * K) * norm;
395 float norm = 1.f / (1.f + K / Q + K * K);
396 this->
b[0] = K / Q * norm;
398 this->
b[2] = -this->
b[0];
399 this->
a[0] = 2.f * (K * K - 1.f) * norm;
400 this->
a[1] = (1.f - K / Q + K * K) * norm;
405 float norm = 1.f / (1.f + K / Q + K * K);
406 this->
b[0] = (1.f + K / Q * V + K * K) * norm;
407 this->
b[1] = 2.f * (K * K - 1.f) * norm;
408 this->
b[2] = (1.f - K / Q * V + K * K) * norm;
409 this->
a[0] = this->
b[1];
410 this->
a[1] = (1.f - K / Q + K * K) * norm;
413 float norm = 1.f / (1.f + K / Q / V + K * K);
414 this->
b[0] = (1.f + K / Q + K * K) * norm;
415 this->
b[1] = 2.f * (K * K - 1.f) * norm;
416 this->
b[2] = (1.f - K / Q + K * K) * norm;
417 this->
a[0] = this->
b[1];
418 this->
a[1] = (1.f - K / Q / V + K * K) * norm;
423 float norm = 1.f / (1.f + K / Q + K * K);
424 this->
b[0] = (1.f + K * K) * norm;
425 this->
b[1] = 2.f * (K * K - 1.f) * norm;
426 this->
b[2] = this->
b[0];
427 this->
a[0] = this->
b[1];
428 this->
a[1] = (1.f - K / Q + K * K) * norm;
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:26
TBiquadFilter BiquadFilter
Definition filter.hpp:436
TSlewLimiter SlewLimiter
Definition filter.hpp:155
TExponentialSlewLimiter ExponentialSlewLimiter
Definition filter.hpp:189
TRCFilter RCFilter
Definition filter.hpp:52
TPeakFilter PeakFilter
Definition filter.hpp:128
TExponentialFilter ExponentialFilter
Definition filter.hpp:88
float_4 arg(std::complex< float_4 > a)
Definition functions.hpp:221
float_4 abs(float_4 a)
Definition functions.hpp:211
float_4 fmax(float_4 x, float_4 b)
Definition functions.hpp:90
float_4 clamp(float_4 x, float_4 a=0.f, float_4 b=1.f)
Definition functions.hpp:251
float ifelse(bool cond, float a, float b)
Definition functions.hpp:49
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Digital IIR filter processor.
Definition filter.hpp:196
IIRFilter()
Definition filter.hpp:213
T x[B_ORDER - 1]
input state x[0] = x_{n-1} x[1] = x_{n-2} etc.
Definition filter.hpp:209
T process(T in)
Definition filter.hpp:235
T getFrequencyPhase(T f)
Definition filter.hpp:286
T y[A_ORDER - 1]
output state
Definition filter.hpp:211
std::complex< T > getTransferFunction(T s)
Computes the complex transfer function $H(s)$ at a particular frequency s: normalized angular frequen...
Definition filter.hpp:264
T getFrequencyResponse(T f)
Definition filter.hpp:279
T b[B_ORDER]
transfer function numerator coefficients: b_0, b_1, etc.
Definition filter.hpp:199
T a[A_ORDER - 1]
transfer function denominator coefficients: a_1, a_2, etc.
Definition filter.hpp:203
void setCoefficients(const T *b, const T *a)
Definition filter.hpp:226
void reset()
Definition filter.hpp:217
Definition filter.hpp:293
TBiquadFilter()
Definition filter.hpp:307
Type
Definition filter.hpp:294
@ HIGHSHELF
Definition filter.hpp:300
@ NUM_TYPES
Definition filter.hpp:304
@ NOTCH
Definition filter.hpp:303
@ LOWPASS
Definition filter.hpp:297
@ BANDPASS
Definition filter.hpp:301
@ HIGHPASS
Definition filter.hpp:298
@ PEAK
Definition filter.hpp:302
@ LOWSHELF
Definition filter.hpp:299
@ HIGHPASS_1POLE
Definition filter.hpp:296
@ LOWPASS_1POLE
Definition filter.hpp:295
void setParameters(Type type, float f, float Q, float V)
Calculates and sets the biquad transfer function coefficients.
Definition filter.hpp:316
Applies exponential smoothing to a signal with the ODE .
Definition filter.hpp:59
T lambda
Definition filter.hpp:61
T process(T deltaTime, T in)
Definition filter.hpp:76
void setLambda(T lambda)
Definition filter.hpp:67
DEPRECATED T process(T in)
Definition filter.hpp:83
void setTau(T tau)
Sets .
Definition filter.hpp:72
void reset()
Definition filter.hpp:63
T out
Definition filter.hpp:60
Behaves like ExponentialFilter but with different lambas when the RHS of the ODE is positive or negat...
Definition filter.hpp:160
T out
Definition filter.hpp:161
T fallLambda
Definition filter.hpp:163
void reset()
Definition filter.hpp:165
void setRiseFall(T riseLambda, T fallLambda)
Definition filter.hpp:169
void setRiseFallTau(T riseTau, T fallTau)
Definition filter.hpp:173
DEPRECATED T process(T in)
Definition filter.hpp:184
T riseLambda
Definition filter.hpp:162
T process(T deltaTime, T in)
Definition filter.hpp:177
Like ExponentialFilter but jumps immediately to higher values.
Definition filter.hpp:94
DEPRECATED T process(T x)
Definition filter.hpp:123
T out
Definition filter.hpp:95
DEPRECATED T peak()
Use the return value of process() instead.
Definition filter.hpp:116
T lambda
Definition filter.hpp:96
void setTau(T tau)
Definition filter.hpp:106
void setLambda(T lambda)
Definition filter.hpp:102
T process(T deltaTime, T in)
Definition filter.hpp:110
void reset()
Definition filter.hpp:98
DEPRECATED void setRate(T r)
Use setLambda() instead.
Definition filter.hpp:120
The simplest possible analog filter using an Euler solver.
Definition filter.hpp:14
T ystate[1]
Definition filter.hpp:17
T xstate[1]
Definition filter.hpp:16
T c
Definition filter.hpp:15
void reset()
Definition filter.hpp:23
T lowpass()
Definition filter.hpp:44
void setCutoff(T r)
Sets the cutoff angular frequency in radians.
Definition filter.hpp:30
void process(T x)
Definition filter.hpp:39
TRCFilter()
Definition filter.hpp:19
void setCutoffFreq(T f)
Sets the cutoff frequency.
Definition filter.hpp:36
T highpass()
Definition filter.hpp:47
Limits the derivative of the output by a rise and fall speed, in units/s.
Definition filter.hpp:133
void setRiseFall(T rise, T fall)
Definition filter.hpp:142
DEPRECATED T process(T in)
Definition filter.hpp:150
T out
Definition filter.hpp:134
T fall
Definition filter.hpp:136
void reset()
Definition filter.hpp:138
T rise
Definition filter.hpp:135
T process(T deltaTime, T in)
Definition filter.hpp:146