39template <
typename SampleType>
51 void setRate (SampleType newRateHz);
70 void setMix (SampleType newMix);
81 template <
typename ProcessContext>
82 void process (
const ProcessContext& context)
noexcept
84 const auto& inputBlock = context.getInputBlock();
85 auto& outputBlock = context.getOutputBlock();
86 const auto numChannels = outputBlock.getNumChannels();
87 const auto numSamples = outputBlock.getNumSamples();
89 jassert (inputBlock.getNumChannels() == numChannels);
90 jassert (inputBlock.getNumChannels() == lastOutput.size());
91 jassert (inputBlock.getNumSamples() == numSamples);
93 if (context.isBypassed)
95 outputBlock.copyFrom (inputBlock);
99 int numSamplesDown = 0;
100 auto counter = updateCounter;
102 for (
size_t i = 0; i < numSamples; ++i)
109 if (counter == maxUpdateCounter)
113 if (numSamplesDown > 0)
119 osc.process (contextFreq);
120 freqBlock.multiplyBy (oscVolume);
125 for (
int i = 0; i < numSamplesDown; ++i)
127 auto lfo = jlimit (
static_cast<SampleType
> (0.0),
128 static_cast<SampleType
> (1.0),
129 freqSamples[i] + normCentreFrequency);
131 freqSamples[i] = mapToLog10 (lfo,
static_cast<SampleType
> (20.0),
132 static_cast<SampleType
> (jmin (20000.0, 0.49 * sampleRate)));
135 auto currentFrequency = filters[0]->getCutoffFrequency();
136 dryWet.pushDrySamples (inputBlock);
138 for (
size_t channel = 0; channel < numChannels; ++channel)
140 counter = updateCounter;
143 auto* inputSamples = inputBlock .getChannelPointer (channel);
144 auto* outputSamples = outputBlock.getChannelPointer (channel);
146 for (
size_t i = 0; i < numSamples; ++i)
148 auto input = inputSamples[i];
149 auto output = input - lastOutput[channel];
151 if (i == 0 && counter != 0)
152 for (
int n = 0; n < numStages; ++n)
153 filters[n]->setCutoffFrequency (currentFrequency);
157 for (
int n = 0; n < numStages; ++n)
158 filters[n]->setCutoffFrequency (freqSamples[k]);
163 for (
int n = 0; n < numStages; ++n)
164 output = filters[n]->processSample ((
int) channel, output);
166 outputSamples[i] = output;
167 lastOutput[channel] = output * feedbackVolume[channel].getNextValue();
171 if (counter == maxUpdateCounter)
176 dryWet.mixWetSamples (outputBlock);
177 updateCounter = (updateCounter + (int) numSamples) % maxUpdateCounter;
188 std::vector<SmoothedValue<SampleType, ValueSmoothingTypes::Linear>> feedbackVolume { 2 };
189 DryWetMixer<SampleType> dryWet;
190 std::vector<SampleType> lastOutput { 2 };
191 AudioBuffer<SampleType> bufferFrequency;
192 SampleType normCentreFrequency = 0.5;
193 double sampleRate = 44100.0;
195 int updateCounter = 0;
196 static constexpr int maxUpdateCounter = 4;
198 SampleType rate = 1.0, depth = 0.5, feedback = 0.0, mix = 0.5;
199 SampleType centreFrequency = 1300.0;
200 static constexpr int numStages = 6;
Type * getWritePointer(int channelNumber) noexcept
AudioBlock getSubBlock(size_t newOffset, size_t newLength) const noexcept
void prepare(const ProcessSpec &spec)
void process(const ProcessContext &context) noexcept
void setDepth(SampleType newDepth)
void setFeedback(SampleType newFeedback)
void setMix(SampleType newMix)
void setRate(SampleType newRateHz)
void setCentreFrequency(SampleType newCentreHz)