JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_FirstOrderTPTFilter.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::dsp
27{
28
29//==============================================================================
30template <typename SampleType>
35
36//==============================================================================
37template <typename SampleType>
39{
40 filterType = newValue;
41}
42
43template <typename SampleType>
45{
46 jassert (isPositiveAndBelow (newValue, static_cast<SampleType> (sampleRate * 0.5)));
47
48 cutoffFrequency = newValue;
49 update();
50}
51
52//==============================================================================
53template <typename SampleType>
55{
56 jassert (spec.sampleRate > 0);
57 jassert (spec.numChannels > 0);
58
59 sampleRate = spec.sampleRate;
60 s1.resize (spec.numChannels);
61
62 update();
63 reset();
64}
65
66template <typename SampleType>
68{
69 reset (static_cast<SampleType> (0));
70}
71
72template <typename SampleType>
74{
75 std::fill (s1.begin(), s1.end(), newValue);
76}
77
78//==============================================================================
79template <typename SampleType>
81{
82 auto& s = s1[(size_t) channel];
83
84 auto v = G * (inputValue - s);
85 auto y = v + s;
86 s = y + v;
87
88 switch (filterType)
89 {
90 case Type::lowpass: return y;
91 case Type::highpass: return inputValue - y;
92 case Type::allpass: return 2 * y - inputValue;
93 default: break;
94 }
95
97 return y;
98}
99
100template <typename SampleType>
102{
103 for (auto& s : s1)
104 util::snapToZero (s);
105}
106
107//==============================================================================
108template <typename SampleType>
110{
111 auto g = SampleType (std::tan (juce::MathConstants<double>::pi * cutoffFrequency / sampleRate));
112 G = g / (1 + g);
113}
114
115//==============================================================================
116template class FirstOrderTPTFilter<float>;
117template class FirstOrderTPTFilter<double>;
118
119} // namespace juce::dsp
A first order filter class using the TPT (Topology-Preserving Transform) structure.
void prepare(const ProcessSpec &spec)
Initialises the filter.
void snapToZero() noexcept
Ensure that the state variables are rounded to zero if the state variables are denormals.
SampleType processSample(int channel, SampleType inputValue)
Processes one sample at a time on a given channel.
void setType(Type newType)
Sets the filter type.
void setCutoffFrequency(SampleType newFrequencyHz)
Sets the cutoff frequency of the filter.
void reset()
Resets the internal state variables of the filter.
T fill(T... args)
#define jassert(expression)
Platform-independent assertion macro.
#define jassertfalse
This will always cause an assertion failure.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
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...
typedef size_t
T tan(T... args)