From cdca13f412ec840013aedd798d85591d9a4a57eb Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Thu, 12 Sep 2024 15:10:16 +0100 Subject: [PATCH] workingish highpass filter --- plugin/chassis.cpp | 21 +++++++++++++++++++++ plugin/parameters.cpp | 9 +++++---- plugin/voice.hpp | 1 + 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index 80ee5e1..ef92e13 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -159,6 +159,27 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv s.blockLeft -= sizeThisTime; } + // highpass filter + + float tmp = s.hptmp; + float smp, flt=0; + float cut_tbl[4] = {0.91245, 0.97097, 1, 0.99088}; + float cut = cut_tbl[(s.patchRam.switch2 & 0x18) >> 3]; + float gain_tbl[4] = {-1, -1, 0, 4}; + float gain = gain_tbl[(s.patchRam.switch2 & 0x18) >> 3]; + + // printf("hp= %02x\n", (s.patchRam.switch2 & 0x18)>>3); + + for (uint32_t i = 0; i < frames; i++) { + smp = outputs[0][i]; + + flt = ((tmp - smp) * cut) + smp; + tmp = flt; + outputs[0][i] = ((flt * gain) + smp); + } + s.hptmp = flt; + + // copy left to right memmove(outputs[1], outputs[0], sizeof(float) * frames); // outputs[1][1]=1; diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp index 2552df6..012adf1 100644 --- a/plugin/parameters.cpp +++ b/plugin/parameters.cpp @@ -149,7 +149,7 @@ void Chassis::initParameter(uint32_t index, Parameter& parameter) { parameter.name = "HPF"; parameter.symbol = "ch_hpf"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 3.0f; + parameter.ranges.max = 3.9f; parameter.ranges.def = 0.0f; parameter.midiCC = 20; break; @@ -397,9 +397,10 @@ void Chassis::setParameterValue(uint32_t index, float value) { case paramHPF: // bits 3-4 of switch 2 // doesn't look great in Carla because of odd behaviour with small integer knobs + printf("setPV %d %f\n", index, value); if (value > 3) value = 3; - s.patchRam.switch2 &= 0xf3; - s.patchRam.switch2 |= (int)value << 3; + s.patchRam.switch2 &= 0xe7; + s.patchRam.switch2 |= (3-(int)value )<< 3; break; case paramModWheel: @@ -452,7 +453,7 @@ float Chassis::getParameterValue(uint32_t index) const { return s.patchRam.noise; break; case paramHPF: - return (s.patchRam.switch2 & 0x18) >> 3; + return 3-((s.patchRam.switch2 & 0x18) >> 3); break; case paramVCFFreq: return s.patchRam.vcfFreq; diff --git a/plugin/voice.hpp b/plugin/voice.hpp index 43f19b0..dce2768 100644 --- a/plugin/voice.hpp +++ b/plugin/voice.hpp @@ -133,6 +133,7 @@ class Synth { } patchRam; float pitchCV[104]; + float hptmp; void runLFO(); void lfoDelay();