diff --git a/plugin/module.hpp b/plugin/module.hpp index 428fe41..6ba1b3c 100644 --- a/plugin/module.hpp +++ b/plugin/module.hpp @@ -75,6 +75,10 @@ class Voice { float delay = 0, lastpw = 0; // delay slots for antialiasing uint8_t pulseStage = 1; // pulse wave phase float subosc = 1; // sub oscillator flipflop output + + // filter + float b1=0, b2=0, b3=0, b4=0; }; + #endif \ No newline at end of file diff --git a/plugin/voice.cpp b/plugin/voice.cpp index 4087063..abf1d62 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -49,8 +49,9 @@ void Voice::off() { void Voice::run(Module* m, float* buffer, uint32_t samples) { // carry out per-voice calculations for each block of samples - float out, t; + float out, t, fb, res; + float cut = 0.00513 + 0.075*env; // printf("%f ", delay); m->saw = 1; m->square = 1; @@ -92,7 +93,20 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) { delay += m->sub * subosc; // delay += (1-(m->noisegen/(float)(1<<30))) * m->noise; FIXME figure out what to do about noise - buffer[i] += 0.125 * env * out; + for (uint8_t ovs = 0; ovs < 4; ovs++) { + fb = b4; + // hard clip + if (fb > 1) fb = 1; + if (fb < -1) fb = -1; + + fb = out - (fb * 2); + b1 = ((fb - b1) * cut) + b1; + b2 = ((b1 - b2) * cut) + b2; + b3 = ((b2 - b3) * cut) + b3; + b4 = ((b3 - b4) * cut) + b4; + } + + buffer[i] += 0.125 * env * b4; lastpw = m->pw; } // buffer[0] += 1;