| 42 | } |
| 43 | |
| 44 | void 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 | |
| 88 | void GateEffect::DrawModule() |
| 89 | { |
nothing calls this directly
no test coverage detected