49 using Mode = LadderFilterMode;
56 void setEnabled (
bool isEnabled)
noexcept { enabled = isEnabled; }
59 void setMode (Mode newMode)
noexcept;
68 void reset() noexcept;
86 void setDrive (SampleType newDrive) noexcept;
89 template <typename ProcessContext>
90 void process (const ProcessContext& context) noexcept
92 const auto& inputBlock = context.getInputBlock();
93 auto& outputBlock = context.getOutputBlock();
94 const auto numChannels = outputBlock.getNumChannels();
95 const auto numSamples = outputBlock.getNumSamples();
98 jassert (inputBlock.getNumChannels() == numChannels);
99 jassert (inputBlock.getNumSamples() == numSamples);
101 if (! enabled || context.isBypassed)
103 outputBlock.copyFrom (inputBlock);
107 for (
size_t n = 0; n < numSamples; ++n)
111 for (
size_t ch = 0; ch < numChannels; ++ch)
112 outputBlock.getChannelPointer (ch)[n] = processSample (inputBlock.getChannelPointer (ch)[n], ch);
118 SampleType processSample (SampleType inputValue,
size_t channelToUse)
noexcept;
119 void updateSmoothers() noexcept;
123 void setSampleRate (SampleType newValue) noexcept;
124 void setNumChannels (
size_t newValue) { state.resize (newValue); }
125 void updateCutoffFreq() noexcept { cutoffTransformSmoother.
setTargetValue (std::exp (cutoffFreqHz * cutoffFreqScaler)); }
126 void updateResonance() noexcept { scaledResonanceSmoother.
setTargetValue (jmap (resonance, SampleType (0.1), SampleType (1.0))); }
129 SampleType drive, drive2, gain, gain2, comp;
131 static constexpr size_t numStates = 5;
132 std::vector<std::array<SampleType, numStates>> state;
133 std::array<SampleType, numStates> A;
135 SmoothedValue<SampleType> cutoffTransformSmoother, scaledResonanceSmoother;
136 SampleType cutoffTransformValue, scaledResonanceValue;
138 LookupTableTransform<SampleType> saturationLUT { [] (SampleType x) {
return std::tanh (x); },
139 SampleType (-5), SampleType (5), 128 };
141 SampleType cutoffFreqHz { SampleType (200) };
142 SampleType resonance;
144 SampleType cutoffFreqScaler;