OpenShot Audio Library | OpenShotAudio: juce_LinkwitzRileyFilter.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_LinkwitzRileyFilter.h
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
29enum class LinkwitzRileyFilterType
30{
31 lowpass,
32 highpass,
33 allpass
34};
35
47template <typename SampleType>
48 class LinkwitzRileyFilter
49{
50public:
51 //==============================================================================
52 using Type = LinkwitzRileyFilterType;
53
54 //==============================================================================
56 LinkwitzRileyFilter();
57
58 //==============================================================================
60 void setType (Type newType);
61
63 void setCutoffFrequency (SampleType newCutoffFrequencyHz);
64
65 //==============================================================================
67 Type getType() const noexcept { return filterType; }
68
70 SampleType getCutoffFrequency() const noexcept { return cutoffFrequency; }
71
72 //==============================================================================
74 void prepare (const ProcessSpec& spec);
75
77 void reset();
78
79 //==============================================================================
81 template <typename ProcessContext>
82 void process (const ProcessContext& context) noexcept
83 {
84 const auto& inputBlock = context.getInputBlock();
85 auto& outputBlock = context.getOutputBlock();
86 const auto numChannels = outputBlock.getNumChannels();
87 const auto numSamples = outputBlock.getNumSamples();
88
89 jassert (inputBlock.getNumChannels() <= s1.size());
90 jassert (inputBlock.getNumChannels() == numChannels);
91 jassert (inputBlock.getNumSamples() == numSamples);
92
93 if (context.isBypassed)
94 {
95 outputBlock.copyFrom (inputBlock);
96 return;
97 }
98
99 for (size_t channel = 0; channel < numChannels; ++channel)
100 {
101 auto* inputSamples = inputBlock.getChannelPointer (channel);
102 auto* outputSamples = outputBlock.getChannelPointer (channel);
103
104 for (size_t i = 0; i < numSamples; ++i)
105 outputSamples[i] = processSample ((int) channel, inputSamples[i]);
106 }
107
108 #if JUCE_DSP_ENABLE_SNAP_TO_ZERO
109 snapToZero();
110 #endif
111 }
112
114 SampleType processSample (int channel, SampleType inputValue);
115
119 void processSample (int channel, SampleType inputValue, SampleType &outputLow, SampleType &outputHigh);
120
125 void snapToZero() noexcept;
126
127private:
128 //==============================================================================
129 void update();
130
131 //==============================================================================
132 SampleType g, R2, h;
133 std::vector<SampleType> s1, s2, s3, s4;
134
135 double sampleRate = 44100.0;
136 SampleType cutoffFrequency = 2000.0;
137 Type filterType = Type::lowpass;
138};
139
140} // namespace juce::dsp
juce::dsp::LinkwitzRileyFilter
Definition juce_LinkwitzRileyFilter.h:49
juce::dsp::LinkwitzRileyFilter::prepare
void prepare(const ProcessSpec &spec)
Definition juce_LinkwitzRileyFilter.cpp:54
juce::dsp::LinkwitzRileyFilter::setType
void setType(Type newType)
Definition juce_LinkwitzRileyFilter.cpp:38
juce::dsp::LinkwitzRileyFilter::process
void process(const ProcessContext &context) noexcept
Definition juce_LinkwitzRileyFilter.h:82
juce::dsp::LinkwitzRileyFilter::reset
void reset()
Definition juce_LinkwitzRileyFilter.cpp:71
juce::dsp::LinkwitzRileyFilter::LinkwitzRileyFilter
LinkwitzRileyFilter()
Definition juce_LinkwitzRileyFilter.cpp:31
juce::dsp::LinkwitzRileyFilter::getCutoffFrequency
SampleType getCutoffFrequency() const noexcept
Definition juce_LinkwitzRileyFilter.h:70
juce::dsp::LinkwitzRileyFilter::processSample
SampleType processSample(int channel, SampleType inputValue)
Definition juce_LinkwitzRileyFilter.cpp:87
juce::dsp::LinkwitzRileyFilter::setCutoffFrequency
void setCutoffFrequency(SampleType newCutoffFrequencyHz)
Definition juce_LinkwitzRileyFilter.cpp:44
juce::dsp::LinkwitzRileyFilter::getType
Type getType() const noexcept
Definition juce_LinkwitzRileyFilter.h:67
juce::dsp::LinkwitzRileyFilter::snapToZero
void snapToZero() noexcept
Definition juce_LinkwitzRileyFilter.cpp:78
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36