11namespace tracktion {
inline namespace engine
14ChorusPlugin::ChorusPlugin (PluginCreationInfo info) : Plugin (info)
16 auto um = getUndoManager();
18 depthMs.referTo (state, IDs::depthMs, um, 3.0f);
19 speedHz.referTo (state, IDs::speedHz, um, 1.0f);
20 width.referTo (state, IDs::width, um, 0.5f);
21 mixProportion.referTo (state, IDs::mixProportion, um, 0.5f);
24ChorusPlugin::~ChorusPlugin()
26 notifyListenersOfDeletion();
29const char* ChorusPlugin::xmlTypeName =
"chorus";
33 const float delayMs = 20.0f;
35 auto bufferSizeSamples =
juce::roundToInt ((maxLengthMs * info.sampleRate) / 1000.0);
36 delayBuffer.ensureMaxBufferSize (bufferSizeSamples);
37 delayBuffer.clearBuffer();
41void ChorusPlugin::deinitialise()
43 delayBuffer.releaseBuffer();
56 const float delayMs = 20.0f;
57 const float minSweepSamples = (
float) ((delayMs * sampleRate) / 1000.0);
58 const float maxSweepSamples = (
float) (((delayMs + depthMs) * sampleRate) / 1000.0);
61 const int lengthInSamples =
juce::roundToInt ((maxLengthMs * sampleRate) / 1000.0);
63 delayBuffer.ensureMaxBufferSize (lengthInSamples);
65 const float feedbackGain = 0.0f;
66 const float lfoFactor = 0.5f * (maxSweepSamples - minSweepSamples);
67 const float lfoOffset = minSweepSamples + lfoFactor;
76 float*
const buf = (
float*) delayBuffer.buffers[chan].getData();
82 bufPos = delayBuffer.bufferPos;
86 const float in = d[i];
88 const float sweep = lfoOffset + lfoFactor *
sinf (ph);
92 const float interp = sweep - intSweepPos;
93 intSweepPos = bufPos + lengthInSamples - intSweepPos;
95 const float out = buf[(intSweepPos - 1) % lengthInSamples] * interp
96 + buf[intSweepPos % lengthInSamples] * (1.0f - interp);
98 float n = in + out * feedbackGain;
104 d[i] = out * wetDry.gain1 + in * wetDry.gain2;
106 bufPos = (bufPos + 1) % lengthInSamples;
110 jassert (! hasFloatingPointDenormaliseOccurred());
111 zeroDenormalisedValuesIfNeeded (*fc.
destBuffer);
117 delayBuffer.bufferPos = bufPos;
120void ChorusPlugin::restorePluginStateFromValueTree (
const juce::ValueTree& v)
122 copyPropertiesToCachedValues (v, depthMs, width, mixProportion, speedHz);
124 for (
auto p : getAutomatableParameters())
125 p->updateFromAttachedValue();
Type * getWritePointer(int channelNumber) noexcept
int getNumChannels() const noexcept
#define JUCE_UNDENORMALISE(x)
int roundToInt(const FloatType value) noexcept
Passed into Plugins when they are being initialised, to give them useful contextual information that ...
Calculates the two gain multipliers to use for mixing between two sources, given a position alpha fro...
The context passed to plugin render methods to provide it with buffers to fill.
int bufferNumSamples
The number of samples to write into the audio buffer.
juce::AudioBuffer< float > * destBuffer
The target audio buffer which needs to be filled.
int bufferStartSample
The index of the start point in the audio buffer from which data must be written.