MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / ProcessAudio

Method ProcessAudio

Source/DelayEffect.cpp:71–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71void DelayEffect::ProcessAudio(double time, ChannelBuffer* buffer)
72{
73 PROFILER(DelayEffect);
74
75 if (!mEnabled)
76 return;
77
78 float bufferSize = buffer->BufferSize();
79 mDelayBuffer.SetNumChannels(buffer->NumActiveChannels());
80
81 if (mInterval != kInterval_None)
82 {
83 mDelay = TheTransport->GetDuration(mInterval) + .1f; //+1 to avoid perfect sample collision
84 mDelayRamp.Start(time, mDelay, time + 10);
85 }
86
87 mAmountRamp.Start(time, mFeedback, time + 3);
88 for (int i = 0; i < bufferSize; ++i)
89 {
90 mFeedback = mAmountRamp.Value(time);
91
92 ComputeSliders(i);
93
94 float delay;
95 if (mDelaySlider->GetModulator() != nullptr)
96 delay = MAX(mDelay, GetMinDelayMs());
97 else
98 delay = MAX(mDelayRamp.Value(time), GetMinDelayMs());
99
100 float delaySamps = delay / gInvSampleRateMs;
101 if (mFeedbackModuleMode)
102 delaySamps -= gBufferSize;
103 delaySamps = ofClamp(delaySamps, 0.1f, DELAY_BUFFER_SIZE - 2);
104
105 int sampsAgoA = int(delaySamps);
106 int sampsAgoB = sampsAgoA + 1;
107
108 for (int ch = 0; ch < buffer->NumActiveChannels(); ++ch)
109 {
110 float sample = mDelayBuffer.GetSample(sampsAgoA, ch);
111 float nextSample = mDelayBuffer.GetSample(sampsAgoB, ch);
112 float a = delaySamps - sampsAgoA;
113 float delayedSample = (1 - a) * sample + a * nextSample; //interpolate
114
115 float in = buffer->GetChannel(ch)[i];
116
117 if (!mEcho && mAcceptInput) //single delay, no continuous feedback so do it pre
118 mDelayBuffer.Write(buffer->GetChannel(ch)[i], ch);
119
120 float delayInput = delayedSample * mFeedback * (mInvert ? -1 : 1);
121 JUCE_UNDENORMALISE(delayInput);
122 if (!std::isnan(delayInput))
123 buffer->GetChannel(ch)[i] += delayInput;
124
125 if (mEcho && mAcceptInput) //continuous feedback so do it post
126 mDelayBuffer.Write(buffer->GetChannel(ch)[i], ch);
127
128 if (!mAcceptInput)

Callers

nothing calls this directly

Calls 11

ofClampFunction · 0.85
BufferSizeMethod · 0.80
SetNumChannelsMethod · 0.80
NumActiveChannelsMethod · 0.80
GetDurationMethod · 0.80
GetModulatorMethod · 0.80
GetChannelMethod · 0.80
StartMethod · 0.45
ValueMethod · 0.45
GetSampleMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected