From 0450482773ef4ea1b89fc7f6aa96bebf66724520 Mon Sep 17 00:00:00 2001 From: Blitblank Date: Wed, 14 Jan 2026 21:32:50 -0600 Subject: [PATCH] add velocity effects --- src/synth/Voice.cpp | 14 ++++++++++---- src/synth/Voice.h | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/synth/Voice.cpp b/src/synth/Voice.cpp index e2bfc4b..8f3b4ed 100644 --- a/src/synth/Voice.cpp +++ b/src/synth/Voice.cpp @@ -1,6 +1,7 @@ #include "Voice.h" #include +#include Voice::Voice(SmoothedParam* params) : params_(params) { @@ -78,7 +79,11 @@ float Voice::process(float* params, bool& scopeTrigger) { float pitchOffset = 1.0f; float phaseInc = pitchOffset * 2.0f * M_PI * frequency_ / static_cast(sampleRate_); - float gain = gainEnv * getParam(ParamId::Osc1VolumeDepth); + // calculate the change that the velocity will make + // TODO: make velocity parameters configurable, probably also for filterCutoff and filterResonance + float velocityGain = std::lerp(velocityCenter, velocity_, velocitySensitivity); + + float gain = gainEnv * getParam(ParamId::Osc1VolumeDepth) * velocityGain; float sampleOut = 0.0f; // sample generation @@ -108,9 +113,10 @@ float Voice::process(float* params, bool& scopeTrigger) { } // filter sample - float cutoffFreq = cutoffEnv * pow(2.0f, getParam(ParamId::FilterCutoffDepth)) * frequency_; - filter1_.setParams(Filter::Type::BiquadLowpass, cutoffFreq, resonanceEnv * getParam(ParamId::FilterResonanceDepth)); - filter2_.setParams(Filter::Type::BiquadLowpass, cutoffFreq, resonanceEnv * getParam(ParamId::FilterResonanceDepth)); + float cutoffFreq = cutoffEnv * pow(2.0f, getParam(ParamId::FilterCutoffDepth)) * frequency_ * velocityGain; + float resonance = resonanceEnv * getParam(ParamId::FilterResonanceDepth) * velocityGain; + filter1_.setParams(Filter::Type::BiquadLowpass, cutoffFreq, resonance); + filter2_.setParams(Filter::Type::BiquadLowpass, cutoffFreq, resonance); sampleOut = filter1_.biquadProcess(sampleOut); sampleOut = filter2_.biquadProcess(sampleOut); diff --git a/src/synth/Voice.h b/src/synth/Voice.h index 991f7c3..650b612 100644 --- a/src/synth/Voice.h +++ b/src/synth/Voice.h @@ -71,4 +71,8 @@ private: // paramstore pointer SmoothedParam* params_; + // TODO: add a parameter in the paramstore for this + float velocitySensitivity = 0.7f; + float velocityCenter = 2.0f; + };