envelope cleanup
This commit is contained in:
parent
ca0afc5d3d
commit
f59a142476
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -66,9 +67,6 @@ class Voice {
|
|||
void run(Module* m, float* buffer, uint32_t samples);
|
||||
uint8_t envPhase = 0;
|
||||
float env = 0; // output amplitude
|
||||
float envTc = 0;
|
||||
float envTarget = 0;
|
||||
|
||||
|
||||
private:
|
||||
float omega = 0, theta = 0; // phase increment and angle
|
||||
|
|
@ -80,5 +78,4 @@ class Voice {
|
|||
float b1 = 0, b2 = 0, b3 = 0, b4 = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue