envelope cleanup

This commit is contained in:
Gordon JC Pearce 2025-12-18 10:34:49 +00:00
parent ca0afc5d3d
commit f59a142476
2 changed files with 14 additions and 17 deletions

View File

@ -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

View File

@ -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
@ -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