LMMS
Loading...
Searching...
No Matches
juce_LadderFilter.h
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
27{
28namespace dsp
29{
30
32{
33 LPF12, // low-pass 12 dB/octave
34 HPF12, // high-pass 12 dB/octave
35 BPF12, // band-pass 12 dB/octave
36 LPF24, // low-pass 24 dB/octave
37 HPF24, // high-pass 24 dB/octave
38 BPF24 // band-pass 24 dB/octave
39};
40
46template <typename SampleType>
48{
49public:
50 //==============================================================================
52
53 //==============================================================================
56
58 void setEnabled (bool isEnabled) noexcept { enabled = isEnabled; }
59
61 void setMode (Mode newMode) noexcept;
62
64 void prepare (const ProcessSpec& spec);
65
67 size_t getNumChannels() const noexcept { return state.size(); }
68
70 void reset() noexcept;
71
76 void setCutoffFrequencyHz (SampleType newCutoff) noexcept;
77
82 void setResonance (SampleType newResonance) noexcept;
83
88 void setDrive (SampleType newDrive) noexcept;
89
90 //==============================================================================
91 template <typename ProcessContext>
92 void process (const ProcessContext& context) noexcept
93 {
94 const auto& inputBlock = context.getInputBlock();
95 auto& outputBlock = context.getOutputBlock();
96 const auto numChannels = outputBlock.getNumChannels();
97 const auto numSamples = outputBlock.getNumSamples();
98
99 jassert (inputBlock.getNumChannels() <= getNumChannels());
100 jassert (inputBlock.getNumChannels() == numChannels);
101 jassert (inputBlock.getNumSamples() == numSamples);
102
103 if (! enabled || context.isBypassed)
104 {
105 outputBlock.copyFrom (inputBlock);
106 return;
107 }
108
109 for (size_t n = 0; n < numSamples; ++n)
110 {
112
113 for (size_t ch = 0; ch < numChannels; ++ch)
114 outputBlock.getChannelPointer (ch)[n] = processSample (inputBlock.getChannelPointer (ch)[n], ch);
115 }
116 }
117
118protected:
119 //==============================================================================
120 SampleType processSample (SampleType inputValue, size_t channelToUse) noexcept;
121 void updateSmoothers() noexcept;
122
123private:
124 //==============================================================================
125 void setSampleRate (SampleType newValue) noexcept;
126 void setNumChannels (size_t newValue) { state.resize (newValue); }
128 void updateResonance() noexcept { scaledResonanceSmoother.setTargetValue (jmap (resonance, SampleType (0.1), SampleType (1.0))); }
129
130 //==============================================================================
131 SampleType drive, drive2, gain, gain2, comp;
132
133 static constexpr size_t numStates = 5;
134 std::vector<std::array<SampleType, numStates>> state;
135 std::array<SampleType, numStates> A;
136
139
140 LookupTableTransform<SampleType> saturationLUT { [] (SampleType x) { return std::tanh (x); },
141 SampleType (-5), SampleType (5), 128 };
142
143 SampleType cutoffFreqHz { SampleType (200) };
144 SampleType resonance;
145
147
149 bool enabled = true;
150};
151
152} // namespace dsp
153} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_SmoothedValue.h:227
SampleType processSample(SampleType inputValue, size_t channelToUse) noexcept
Definition juce_LadderFilter.cpp:123
SampleType drive2
Definition juce_LadderFilter.h:131
SampleType drive
Definition juce_LadderFilter.h:131
SampleType gain
Definition juce_LadderFilter.h:131
LadderFilter()
Definition juce_LadderFilter.cpp:33
LookupTableTransform< SampleType > saturationLUT
Definition juce_LadderFilter.h:140
bool enabled
Definition juce_LadderFilter.h:149
static constexpr size_t numStates
Definition juce_LadderFilter.h:133
void updateSmoothers() noexcept
Definition juce_LadderFilter.cpp:151
SmoothedValue< SampleType > cutoffTransformSmoother
Definition juce_LadderFilter.h:137
Mode mode
Definition juce_LadderFilter.h:148
SampleType gain2
Definition juce_LadderFilter.h:131
void updateResonance() noexcept
Definition juce_LadderFilter.h:128
std::vector< std::array< SampleType, numStates > > state
Definition juce_LadderFilter.h:134
void setEnabled(bool isEnabled) noexcept
Definition juce_LadderFilter.h:58
SampleType resonance
Definition juce_LadderFilter.h:144
SmoothedValue< SampleType > scaledResonanceSmoother
Definition juce_LadderFilter.h:137
SampleType cutoffFreqScaler
Definition juce_LadderFilter.h:146
void setNumChannels(size_t newValue)
Definition juce_LadderFilter.h:126
SampleType cutoffTransformValue
Definition juce_LadderFilter.h:138
void updateCutoffFreq() noexcept
Definition juce_LadderFilter.h:127
SampleType scaledResonanceValue
Definition juce_LadderFilter.h:138
size_t getNumChannels() const noexcept
Definition juce_LadderFilter.h:67
void process(const ProcessContext &context) noexcept
Definition juce_LadderFilter.h:92
LadderFilterMode Mode
Definition juce_LadderFilter.h:51
SampleType comp
Definition juce_LadderFilter.h:131
SampleType cutoffFreqHz
Definition juce_LadderFilter.h:143
std::array< SampleType, numStates > A
Definition juce_LadderFilter.h:135
Definition juce_LookupTable.h:175
unsigned x[BMAX+1]
Definition inflate.c:1586
virtual ASIOError setSampleRate(ASIOSampleRate sampleRate)=0
#define jassert(expression)
Definition juce_AudioBlock.h:29
LadderFilterMode
Definition juce_LadderFilter.h:32
@ LPF24
Definition juce_LadderFilter.h:36
@ BPF24
Definition juce_LadderFilter.h:38
@ LPF12
Definition juce_LadderFilter.h:33
@ BPF12
Definition juce_LadderFilter.h:35
@ HPF24
Definition juce_LadderFilter.h:37
@ HPF12
Definition juce_LadderFilter.h:34
Definition carla_juce.cpp:31
constexpr Type jmap(Type value0To1, Type targetRangeMin, Type targetRangeMax)
Definition juce_MathsFunctions.h:120
Definition juce_ProcessContext.h:38
int n
Definition crypt.c:458
#define const
Definition zconf.h:137