feat(fx): add effect rack and effect units
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#include "Phaser.h"
|
||||
|
||||
namespace serum
|
||||
{
|
||||
|
||||
void PhaserUnit::prepare (double sampleRate, int)
|
||||
{
|
||||
sr = sampleRate;
|
||||
reset();
|
||||
}
|
||||
|
||||
void PhaserUnit::reset()
|
||||
{
|
||||
lfoPhase = 0.0;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
xL[i] = xR[i] = yL[i] = yR[i] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void PhaserUnit::process (float* l, float* r, int numSamples, const float p[4])
|
||||
{
|
||||
const double rate = 0.05 + p[0] * 2.0;
|
||||
const float depth = 0.3f + p[1] * 0.6f;
|
||||
const float feedback = p[2] * 0.7f;
|
||||
const int stages = juce::jlimit (2, 6, 2 + (int) (p[3] * 4.0f + 0.5f));
|
||||
|
||||
for (int i = 0; i < numSamples; ++i)
|
||||
{
|
||||
lfoPhase += 6.28318530717958647692 * rate / sr;
|
||||
if (lfoPhase > 6.28318530717958647692) lfoPhase -= 6.28318530717958647692;
|
||||
|
||||
const float sweep = (float) (0.5 + 0.5 * std::sin (lfoPhase));
|
||||
const float a = 0.3f + depth * sweep; // allpass coefficient
|
||||
|
||||
float outL = l[i] + yL[5] * feedback;
|
||||
float outR = r[i] + yR[5] * feedback;
|
||||
|
||||
for (int s = 0; s < stages; ++s)
|
||||
{
|
||||
// y = a*x + x_prev - a*y_prev
|
||||
const float inL = outL, inR = outR;
|
||||
outL = a * inL + xL[s] - a * yL[s];
|
||||
outR = a * inR + xR[s] - a * yR[s];
|
||||
xL[s] = inL; xR[s] = inR;
|
||||
yL[s] = outL; yR[s] = outR;
|
||||
}
|
||||
|
||||
l[i] = outL;
|
||||
r[i] = outR;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace serum
|
||||
Reference in New Issue
Block a user