30template <
typename SampleType>
37template <
typename SampleType>
43template <
typename SampleType>
48 cutoffFrequency = newCutoffFrequencyHz;
53template <
typename SampleType>
70template <
typename SampleType>
73 for (
auto s : { &s1, &s2, &s3, &s4 })
74 std::fill (s->begin(), s->end(),
static_cast<SampleType
> (0));
77template <
typename SampleType>
80 for (
auto s : { &s1, &s2, &s3, &s4 })
81 for (
auto& element : *s)
82 util::snapToZero (element);
86template <
typename SampleType>
89 auto yH = (inputValue - (R2 + g) * s1[(
size_t) channel] - s2[(
size_t) channel]) * h;
91 auto yB = g * yH + s1[(
size_t) channel];
92 s1[(
size_t) channel] = g * yH + yB;
94 auto yL = g * yB + s2[(
size_t) channel];
95 s2[(
size_t) channel] = g * yB + yL;
97 if (filterType == Type::allpass)
98 return yL - R2 * yB + yH;
100 auto yH2 = ((filterType == Type::lowpass ? yL : yH) - (R2 + g) * s3[(
size_t) channel] - s4[(
size_t) channel]) * h;
102 auto yB2 = g * yH2 + s3[(
size_t) channel];
103 s3[(
size_t) channel] = g * yH2 + yB2;
105 auto yL2 = g * yB2 + s4[(
size_t) channel];
106 s4[(
size_t) channel] = g * yB2 + yL2;
108 return filterType == Type::lowpass ? yL2 : yH2;
111template <
typename SampleType>
114 auto yH = (inputValue - (R2 + g) * s1[(
size_t) channel] - s2[(
size_t) channel]) * h;
116 auto yB = g * yH + s1[(
size_t) channel];
117 s1[(
size_t) channel] = g * yH + yB;
119 auto yL = g * yB + s2[(
size_t) channel];
120 s2[(
size_t) channel] = g * yB + yL;
122 auto yH2 = (yL - (R2 + g) * s3[(
size_t) channel] - s4[(
size_t) channel]) * h;
124 auto yB2 = g * yH2 + s3[(
size_t) channel];
125 s3[(
size_t) channel] = g * yH2 + yB2;
127 auto yL2 = g * yB2 + s4[(
size_t) channel];
128 s4[(
size_t) channel] = g * yB2 + yL2;
131 outputHigh = yL - R2 * yB + yH - yL2;
134template <
typename SampleType>
139 h = (SampleType) (1.0 / (1.0 + R2 * g + g * g));
143template class LinkwitzRileyFilter<float>;
144template class LinkwitzRileyFilter<double>;
A filter class designed to perform multi-band separation using the TPT (Topology-Preserving Transform...
void prepare(const ProcessSpec &spec)
Initialises the filter.
void setType(Type newType)
Sets the filter type.
void reset()
Resets the internal state variables of the filter.
LinkwitzRileyFilter()
Constructor.
SampleType processSample(int channel, SampleType inputValue)
Performs the filter operation on a single sample at a time.
void setCutoffFrequency(SampleType newCutoffFrequencyHz)
Sets the cutoff frequency of the filter in Hz.
void snapToZero() noexcept
Ensure that the state variables are rounded to zero if the state variables are denormals.
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.