From 357cbbac9a567c2d74824389fb62a281d5a4331e Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Mon, 9 Sep 2024 16:31:43 +0100 Subject: [PATCH] filter of sorts --- plugin/chassis.cpp | 3 +++ plugin/parameters.cpp | 2 +- plugin/voice.cpp | 32 ++++++++++++++++++++++++++++---- plugin/voice.hpp | 5 +++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index 1425df8..c04e84c 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -115,6 +115,8 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv // flatten the left channel to use as temporary storage, since // the synth engine only generates a mono channel bzero(outputs[0], sizeof(float) * frames); + bzero(outputs[1], sizeof(float) * frames); + // get any of the last block's worth of MIDI out of the way lastEvent = 0; @@ -157,6 +159,7 @@ void Chassis::run(const float **, float **outputs, uint32_t frames, const MidiEv s.voice[i].run(s, outputs[0] + framePos, sizeThisTime); } + framePos += sizeThisTime; s.framesLeft -= sizeThisTime; s.blockLeft -= sizeThisTime; diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp index 59abe2d..f0a00c7 100644 --- a/plugin/parameters.cpp +++ b/plugin/parameters.cpp @@ -146,7 +146,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 0.0f; - parameter.midiCC = 74; + parameter.midiCC = 71; break; case paramVCFMode: parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; diff --git a/plugin/voice.cpp b/plugin/voice.cpp index 82151fb..793766f 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -41,9 +41,12 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) { // there's a resistor on the panel board to sprag the range float pw = s.ff4f / 32768.0f; - float sqr = (s.patchRam.switch1 & 0x08) ? 0.175 : 0; - float saw = (s.patchRam.switch1 & 0x10) ? 0.220 : 0; - float sub = (s.patchRam.sub / 127.0f) * 0.275; + float fb, res = s.patchRam.vcfReso / 24.0f; // guess + float cut = s.patchRam.vcfFreq / 400.0f; // guess + + float sqr = (s.patchRam.switch1 & 0x08) ? 0.63 : 0; //? 0.175 : 0; + float saw = (s.patchRam.switch1 & 0x10) ? 0.8 : 0; //? 0.220 : 0; + float sub = (s.patchRam.sub / 127.0f); // * 0.275; float gain = 0.5 * powf(2, (s.patchRam.vca / 64.0f) - 1); @@ -97,8 +100,29 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) { out = y; // widthDelay = pw; + //out *= 0.5; + + 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 * res); + b1 = ((fb - b1) * cut) + b1; + b2 = ((b1 - b2) * cut) + b2; + b3 = ((b2 - b3) * cut) + b3; + b4 = ((b3 - b4) * cut) + b4; + } + vr58c106 += ((vcaEnv - vr58c106) * 0.0075); lastpw = pw; - buffer[i] += (gain * out * vr58c106); + + out = b4 * (0.275); + + buffer[i] += (gain * b4 * vr58c106); } } + +void Voice::filter(Synth &s, float *buffer, uint32_t samples) { +} \ No newline at end of file diff --git a/plugin/voice.hpp b/plugin/voice.hpp index 270a1db..696b321 100644 --- a/plugin/voice.hpp +++ b/plugin/voice.hpp @@ -34,6 +34,8 @@ class Voice { void run(Synth &s, float *buffer, uint32_t samples); void gate(Synth &s); void calcPitch(Synth &s); + void filter(Synth &s, float *buffer, uint32_t samples); + uint16_t ff71 = 0; // stores pitch + fraction float omega; @@ -64,6 +66,9 @@ class Voice { float lastpw = 0; float vr58c106 = 0; + + float b1, b2, b3, b4; + uint16_t attack_table[128] = { 0x4000, 0x2000, 0x1000, 0x0aaa, 0x0800, 0x0666, 0x0555, 0x0492, 0x0400, 0x038e, 0x0333, 0x02e9, 0x02ab, 0x0276, 0x0249, 0x0222, 0x0200, 0x01e2,