diff --git a/plugin/module.cpp b/plugin/module.cpp index 72a2066..bcad0f4 100644 --- a/plugin/module.cpp +++ b/plugin/module.cpp @@ -25,24 +25,24 @@ Module::Module() { void Module::run(Voice* voice) { // run updates for module board + + // work out the "master" cutoff + vcfCutoff = patchRam.vcfFreq / 127.0f; + vcfCutoff += lfo * (patchRam.vcfLfo/127.0f); + for (uint32_t i = 0; i < NUM_VOICES; i++) { switch (voice[i].envPhase) { - case 0: - voice[i].envTarget = 0; - voice[i].envTc = 1-(decayTable[patchRam.env_r] / 65536.0f); - voice[i].env = (voice[i].envTarget - voice[i].env) * voice[i].envTc + voice[i].env; + case 0: // release phase FIXME use an enum I guess + voice[i].env *= decayTable[patchRam.env_r] / 65536.0f; // "RC" decay to zero break; - case 1: - voice[i].envTarget = 1; - voice[i].env += attackTable[patchRam.env_a] / 65536.0f; + case 1: // attack phase + voice[i].env += attackTable[patchRam.env_a] / 65536.0f; // linear attack to 1 break; case 2: - voice[i].envTarget = patchRam.env_s / 127.0f; - voice[i].envTc = 1 - (decayTable[patchRam.env_d] / 65536.0f); - voice[i].env = (voice[i].envTarget - voice[i].env) * voice[i].envTc + voice[i].env; + float t = patchRam.env_s / 127.0f; + voice[i].env = (voice[i].env - t) * (decayTable[patchRam.env_d] / 65536.0f) + t; break; } - //voice[i].env = (voice[i].envTarget - voice[i].env) * voice[i].envTc + voice[i].env; if (voice[i].env > 1.0f) { voice[i].env = 1.0f; voice[i].envPhase = 2; // flip to decay diff --git a/plugin/module.hpp b/plugin/module.hpp index 6ba1b3c..22d4492 100644 --- a/plugin/module.hpp +++ b/plugin/module.hpp @@ -32,6 +32,7 @@ class Module { void run(Voice* voice); // Voice voices[NUM_VOICES]; float vcfCutoff = 0, vcfReso = 0; + float lfo = 0, lfoTheta = 0; // precomputed values for all voices float pw, saw, square, sub; @@ -65,10 +66,7 @@ class Voice { void off(); void run(Module* m, float* buffer, uint32_t samples); uint8_t envPhase = 0; - float env = 0; // output amplitude - float envTc = 0; - float envTarget = 0; - + float env = 0; // output amplitude private: float omega = 0, theta = 0; // phase increment and angle @@ -77,8 +75,7 @@ class Voice { float subosc = 1; // sub oscillator flipflop output // filter - float b1=0, b2=0, b3=0, b4=0; + float b1 = 0, b2 = 0, b3 = 0, b4 = 0; }; - #endif \ No newline at end of file