From ecc1c82c99e5c9541efb42ad811aa894e37c5b2a Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Sun, 21 Dec 2025 23:30:16 +0000 Subject: [PATCH] chorus switching --- plugin/chorus.cpp | 42 ++++++++++++++++++++-------- plugin/chorus.hpp | 2 ++ plugin/module.cpp | 2 ++ plugin/module.hpp | 6 ++-- plugin/parameters.cpp | 65 ++++++++++++++++++++++++++++++------------- plugin/peacock.cpp | 5 ++-- plugin/svf.cpp | 1 - plugin/ui.cpp | 10 ++++--- 8 files changed, 92 insertions(+), 41 deletions(-) diff --git a/plugin/chorus.cpp b/plugin/chorus.cpp index 2acadcd..f8f4372 100644 --- a/plugin/chorus.cpp +++ b/plugin/chorus.cpp @@ -23,8 +23,7 @@ #include -Chorus::Chorus() { - +Chorus::Chorus() { lpfOut1 = new float[bufferSize]; lpfOut2 = new float[bufferSize]; ram = new float[DELAYSIZE]; // probably needs to be calculated based on sample rate @@ -39,7 +38,7 @@ Chorus::Chorus() { // lfo values taken from a rough simulation fastOmega = 6.283 * 0.7 / sampleRate; // approximate, can be adjusted - + // zero out the delay buffer memset(ram, 0, sizeof(float) * DELAYSIZE); memset(lpfOut1, 0, sizeof(float) * bufferSize); @@ -47,7 +46,6 @@ Chorus::Chorus() { } Chorus::~Chorus() { - printf("called chorus destructor\n"); delete lpfOut1; delete lpfOut2; delete ram; @@ -60,6 +58,8 @@ Chorus::~Chorus() { void Chorus::run(const float* input, float** outputs, uint32_t frames) { // actual effects here + // FIXME add highpass filter + // now run the DSP float s0 = 0, s1 = 0; float lfoMod, dly1, frac; @@ -72,11 +72,11 @@ void Chorus::run(const float* input, float** outputs, uint32_t frames) { ram[delayptr] = input[i]; -#define BASE 0.05 -#define AMT 0.003175 +#define BASE 0.005 +#define AMT 0.00175 - // 0 degree delay line - lfoMod = 0.603 * sin(fastPhase); + // FIXME make this triangle not sine, and move arithmetic out of mainloop + lfoMod = sin(fastPhase); dly1 = (BASE + (AMT * lfoMod)) * sampleRate; delay = (int)dly1; frac = dly1 - delay; @@ -95,8 +95,8 @@ void Chorus::run(const float* input, float** outputs, uint32_t frames) { s0 = ram[tap & 0x3ff]; lpfOut2[i] = ((s1 - s0) * frac) + s0; - // lpfOut1[i] = input[i] + 1.2 * out0; //(out0 + (out120 * 0.66) + (out240 * 0.33)); - // lpfOut2[i] = input[i] + 1.2 * out120; //(out0 + (out120 * 0.33) + (out240 * 0.66)); + // lpfOut1[i] = input[i] + 1.2 * out0; //(out0 + (out120 * 0.66) + (out240 * 0.33)); + // lpfOut2[i] = input[i] + 1.2 * out120; //(out0 + (out120 * 0.33) + (out240 * 0.66)); delayptr++; delayptr &= 0x3ff; @@ -112,6 +112,24 @@ void Chorus::run(const float* input, float** outputs, uint32_t frames) { outputs[0][i] = y + (gain * lpfOut1[i]); outputs[1][i] = y + (gain * lpfOut2[i]); } - - +} + +void Chorus::setHpf(uint8_t mode) { +} + +void Chorus::setChorus(uint8_t mode) { + // switch chorus mode + switch (mode) { + case 0x60: + gain = 0; + break; + case 0x40: + gain = 1.2; + fastOmega = 6.283 * 0.5 / sampleRate; + break; // approximate, can be adjusted + case 0x00: + gain = 1.2; + fastOmega = 6.283 * 0.9 / sampleRate; + break; // approximate, can be adjusted + } } diff --git a/plugin/chorus.hpp b/plugin/chorus.hpp index 3a4cdee..8dc7328 100644 --- a/plugin/chorus.hpp +++ b/plugin/chorus.hpp @@ -34,6 +34,8 @@ class Chorus { Chorus(); ~Chorus(); void run(const float* input, float** outputs, uint32_t frames); + void setHpf(uint8_t mode); + void setChorus(uint8_t mode); private: double fastPhase = 0, fastOmega = 0; diff --git a/plugin/module.cpp b/plugin/module.cpp index 3a548f0..5c8a8df 100644 --- a/plugin/module.cpp +++ b/plugin/module.cpp @@ -42,6 +42,8 @@ void Module::run(Voice* voice) { res = patchRam.vcfReso / 127.0 * 5; noise = patchRam.noise / 127.0; + chorus->setChorus(patchRam.switch1 & 0x60); + if (lfoPhase & 0x4000) lfo = 0x1fff - (lfoPhase & 0x3fff); else diff --git a/plugin/module.hpp b/plugin/module.hpp index 9b34419..91d4b50 100644 --- a/plugin/module.hpp +++ b/plugin/module.hpp @@ -22,6 +22,7 @@ #include #include "DistrhoPluginInfo.h" +#include "chorus.hpp" extern double sampleRate; @@ -61,9 +62,10 @@ class Module { uint8_t env_s = 0x30; // 0x3f80 uint8_t env_r = 0x30; uint8_t sub = 0x40; - uint8_t switch1 = 0x19; - uint8_t switch2 = 0x018; + uint8_t switch1 = 0x59; + uint8_t switch2 = 0x18; } patchRam; + Chorus* chorus; private: // controls diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp index 84e9b4e..bdc23ec 100644 --- a/plugin/parameters.cpp +++ b/plugin/parameters.cpp @@ -289,17 +289,17 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { parameter.ranges.def = 40.0f; parameter.midiCC = 26; break; -/* - case pModWheel: - parameter.hints = kParameterIsAutomatable | kParameterIsHidden; - parameter.name = "Mod wheel"; - parameter.symbol = "ch_modwheel"; - parameter.ranges.min = 0.0f; - parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; - parameter.midiCC = 1; - break; - */ + /* + case pModWheel: + parameter.hints = kParameterIsAutomatable | kParameterIsHidden; + parameter.name = "Mod wheel"; + parameter.symbol = "ch_modwheel"; + parameter.ranges.min = 0.0f; + parameter.ranges.max = 127.0f; + parameter.ranges.def = 0.0f; + parameter.midiCC = 1; + break; + */ } // chorus, porta, bend range, key mode still to do } @@ -379,8 +379,21 @@ void Peacock::setParameterValue(uint32_t index, float value) { m->patchRam.switch1 |= (value >= 0.5) << 4; break; - // missing chorus switch - + case pChorus: + m->patchRam.switch1 &= 0x9f; + + switch ((int)value) { + case 0: + m->patchRam.switch1 |= 0x60; // both off + break; + case 1: + m->patchRam.switch1 |= 0x40; // both off + break; + case 2: + default: + break; + } + break; // switch 2 params case pPWMMode: // bit 0 of switch 2 m->patchRam.switch2 &= 0xfe; @@ -400,12 +413,12 @@ void Peacock::setParameterValue(uint32_t index, float value) { // doesn't look great in Carla because of odd behaviour with small integer knobs if (value > 3) value = 3; m->patchRam.switch2 &= 0xe7; - m->patchRam.switch2 |= (3-(int)value )<< 3; + m->patchRam.switch2 |= (3 - (int)value) << 3; break; -/* - case pModWheel: - //s.ff64 = (int)value << 1; - break;*/ + /* + case pModWheel: + //s.ff64 = (int)value << 1; + break;*/ } } @@ -453,7 +466,7 @@ float Peacock::getParameterValue(uint32_t index) const { return m->patchRam.noise; break; case pHPF: - return 3-((m->patchRam.switch2 & 0x18) >> 3); + return 3 - ((m->patchRam.switch2 & 0x18) >> 3); break; case pCutoff: return m->patchRam.vcfFreq; @@ -493,6 +506,20 @@ float Peacock::getParameterValue(uint32_t index) const { case pVCALevel: return m->patchRam.vca; break; + case pChorus: + + switch (m->patchRam.switch1 & 0x60) { + case 0x60: + return 0; + case 0x40: + return 1; + case 0x00: + return 2; + default: + break; + } + + } return 0; } diff --git a/plugin/peacock.cpp b/plugin/peacock.cpp index e157b31..9d08d3d 100644 --- a/plugin/peacock.cpp +++ b/plugin/peacock.cpp @@ -28,17 +28,16 @@ Peacock::Peacock() : Plugin(parameterCount, 0, 0) { sampleRate = getSampleRate(); bufferSize = getBufferSize(); + chorus = new Chorus(); m = new Module(); ic1 = new Assigner; ic1->voice = voice; - chorus = new Chorus(); + m->chorus = chorus; } Peacock::~Peacock() { - printf("peacock destructor\n"); - } void Peacock::initAudioPort(bool input, uint32_t index, AudioPort& port) { diff --git a/plugin/svf.cpp b/plugin/svf.cpp index 14c3684..f91fca8 100644 --- a/plugin/svf.cpp +++ b/plugin/svf.cpp @@ -51,5 +51,4 @@ void SVF::runSVF(const float *input, float *output, uint32_t frames) { z1 += c1 * x; output[i] = d0 * x + z2; } - // printf("%f\n", x); } \ No newline at end of file diff --git a/plugin/ui.cpp b/plugin/ui.cpp index 07fb6b4..53819f4 100644 --- a/plugin/ui.cpp +++ b/plugin/ui.cpp @@ -182,7 +182,6 @@ DistrhoUIPeacock::DistrhoUIPeacock() : UI(Art::backgroundWidth, Art::backgroundH } DistrhoUIPeacock::~DistrhoUIPeacock() { - printf("Called destructor for UI\n"); } /* void DistrhoUIPeacock::programLoaded(uint32_t index) { @@ -325,13 +324,16 @@ void DistrhoUIPeacock::imageButtonClicked(ImageButton* imgBtn, int) { setParameterValue(pSaw, (sw1 & 0x10) ? 1.0f : 0.0f); break; case btnCh0: - sw1 = (sw1 & 0x1f) | 0x20; + sw1 = (sw1 & 0x9f) | 0x20; + setParameterValue(pChorus, 0); break; case btnCh1: - sw1 = (sw1 & 0x1f) | 0x40; + sw1 = (sw1 & 0x9f) | 0x40; + setParameterValue(pChorus, 1); break; case btnCh2: - sw1 = (sw1 & 0x1f); + sw1 = (sw1 & 0x9f); + setParameterValue(pChorus, 2); break; default: