envelope cleanup
This commit is contained in:
parent
ca0afc5d3d
commit
f59a142476
|
|
@ -25,24 +25,24 @@ Module::Module() {
|
||||||
|
|
||||||
void Module::run(Voice* voice) {
|
void Module::run(Voice* voice) {
|
||||||
// run updates for module board
|
// 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++) {
|
for (uint32_t i = 0; i < NUM_VOICES; i++) {
|
||||||
switch (voice[i].envPhase) {
|
switch (voice[i].envPhase) {
|
||||||
case 0:
|
case 0: // release phase FIXME use an enum I guess
|
||||||
voice[i].envTarget = 0;
|
voice[i].env *= decayTable[patchRam.env_r] / 65536.0f; // "RC" decay to zero
|
||||||
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;
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1: // attack phase
|
||||||
voice[i].envTarget = 1;
|
voice[i].env += attackTable[patchRam.env_a] / 65536.0f; // linear attack to 1
|
||||||
voice[i].env += attackTable[patchRam.env_a] / 65536.0f;
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
voice[i].envTarget = patchRam.env_s / 127.0f;
|
float t = patchRam.env_s / 127.0f;
|
||||||
voice[i].envTc = 1 - (decayTable[patchRam.env_d] / 65536.0f);
|
voice[i].env = (voice[i].env - t) * (decayTable[patchRam.env_d] / 65536.0f) + t;
|
||||||
voice[i].env = (voice[i].envTarget - voice[i].env) * voice[i].envTc + voice[i].env;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//voice[i].env = (voice[i].envTarget - voice[i].env) * voice[i].envTc + voice[i].env;
|
|
||||||
if (voice[i].env > 1.0f) {
|
if (voice[i].env > 1.0f) {
|
||||||
voice[i].env = 1.0f;
|
voice[i].env = 1.0f;
|
||||||
voice[i].envPhase = 2; // flip to decay
|
voice[i].envPhase = 2; // flip to decay
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ class Module {
|
||||||
void run(Voice* voice);
|
void run(Voice* voice);
|
||||||
// Voice voices[NUM_VOICES];
|
// Voice voices[NUM_VOICES];
|
||||||
float vcfCutoff = 0, vcfReso = 0;
|
float vcfCutoff = 0, vcfReso = 0;
|
||||||
|
float lfo = 0, lfoTheta = 0;
|
||||||
|
|
||||||
// precomputed values for all voices
|
// precomputed values for all voices
|
||||||
float pw, saw, square, sub;
|
float pw, saw, square, sub;
|
||||||
|
|
@ -65,10 +66,7 @@ class Voice {
|
||||||
void off();
|
void off();
|
||||||
void run(Module* m, float* buffer, uint32_t samples);
|
void run(Module* m, float* buffer, uint32_t samples);
|
||||||
uint8_t envPhase = 0;
|
uint8_t envPhase = 0;
|
||||||
float env = 0; // output amplitude
|
float env = 0; // output amplitude
|
||||||
float envTc = 0;
|
|
||||||
float envTarget = 0;
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float omega = 0, theta = 0; // phase increment and angle
|
float omega = 0, theta = 0; // phase increment and angle
|
||||||
|
|
@ -77,8 +75,7 @@ class Voice {
|
||||||
float subosc = 1; // sub oscillator flipflop output
|
float subosc = 1; // sub oscillator flipflop output
|
||||||
|
|
||||||
// filter
|
// filter
|
||||||
float b1=0, b2=0, b3=0, b4=0;
|
float b1 = 0, b2 = 0, b3 = 0, b4 = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue