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

Method ProcessAudio

Source/GateEffect.cpp:44–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void GateEffect::ProcessAudio(double time, ChannelBuffer* buffer)
45{
46 PROFILER(GateEffect);
47
48 if (!mEnabled)
49 return;
50
51 float bufferSize = buffer->BufferSize();
52
53 ComputeSliders(0);
54
55 for (int i = 0; i < bufferSize; ++i)
56 {
57 const float decayTime = .01f;
58 float scalar = powf(0.5f, 1.0f / (decayTime * gSampleRate));
59 float input = 0;
60 for (int ch = 0; ch < buffer->NumActiveChannels(); ++ch)
61 input = MAX(input, fabsf(buffer->GetChannel(ch)[i]));
62
63 if (input >= mPeak)
64 {
65 /* When we hit a peak, ride the peak to the top. */
66 mPeak = input;
67 }
68 else
69 {
70 /* Exponential decay of output when signal is low. */
71 mPeak = mPeak * scalar;
72 if (mPeak < FLT_EPSILON)
73 mPeak = 0.0;
74 }
75
76 if (mPeak >= mThreshold && mEnvelope < 1)
77 mEnvelope = MIN(1, mEnvelope + gInvSampleRateMs / mAttackTime);
78 if (mPeak < mThreshold && mEnvelope > 0)
79 mEnvelope = MAX(0, mEnvelope - gInvSampleRateMs / mReleaseTime);
80
81 for (int ch = 0; ch < buffer->NumActiveChannels(); ++ch)
82 buffer->GetChannel(ch)[i] *= mEnvelope;
83
84 time += gInvSampleRateMs;
85 }
86}
87
88void GateEffect::DrawModule()
89{

Callers

nothing calls this directly

Calls 3

BufferSizeMethod · 0.80
NumActiveChannelsMethod · 0.80
GetChannelMethod · 0.80

Tested by

no test coverage detected