diff --git a/plugin/Makefile b/plugin/Makefile index 742693b..e08c45b 100644 --- a/plugin/Makefile +++ b/plugin/Makefile @@ -10,7 +10,8 @@ NAME = chassis FILES_DSP = \ - chassis.cpp + chassis.cpp \ + voice.cpp include ../dpf/Makefile.plugins.mk diff --git a/plugin/voice.cpp b/plugin/voice.cpp index 046c6c3..29499ef 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -20,7 +20,25 @@ #include "voice.hpp" -inline bool Voice::isFree() { + +static float blep(float phase, float theta) { + float t; + + if (phase < theta) { + t = phase / theta; + return (2 * t) - (t * t) - 1; + } + if (phase > (1 - theta)) { + t = (phase - 1) / theta; + return (2 * t) + (t * t) + 1; + } + + return 0; +} + + + +bool Voice::isFree() { return keyState == K_OFF; } @@ -40,10 +58,14 @@ void Voice::off() { } void Voice::run(float *buffer, uint32_t samples) { + float y; env = ((target - env) * 0.01) + env; for (uint32_t i = 0; i < samples; i++) { phase += omega; if (phase > 1) phase -= 1; - buffer[i] += (0.5 - phase) * env; + y = (2*phase)-1; + y-=blep(phase,omega); + + buffer[i] += y * env; } } diff --git a/plugin/voice.hpp b/plugin/voice.hpp index 69e9532..415946b 100644 --- a/plugin/voice.hpp +++ b/plugin/voice.hpp @@ -29,7 +29,7 @@ class Voice { void off(); - inline bool isFree(); + bool isFree(); void run(float *buffer, uint32_t samples);