From fd392ecf56c8a625d8339b954ba1c801a03cb105 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Thu, 25 Dec 2025 23:21:12 +0000 Subject: [PATCH 1/5] proper parameter for chorus --- plugin/DistrhoPluginInfo.h | 2 +- plugin/parameters.cpp | 80 ++++++++++++++++++++++++-------------- plugin/ui.cpp | 8 ++-- 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/plugin/DistrhoPluginInfo.h b/plugin/DistrhoPluginInfo.h index 6370ea0..85daadc 100644 --- a/plugin/DistrhoPluginInfo.h +++ b/plugin/DistrhoPluginInfo.h @@ -63,7 +63,7 @@ pSustain, pRelease, - pChorus, + pChorusMode, parameterCount }; diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp index bdc23ec..a73b9a3 100644 --- a/plugin/parameters.cpp +++ b/plugin/parameters.cpp @@ -23,7 +23,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pLFORate: parameter.hints = kParameterIsAutomatable; parameter.name = "LFO Rate"; - parameter.symbol = "ch_lforate"; + parameter.symbol = "pfau_lforate"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 48.0f; @@ -33,7 +33,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pLFODelay: parameter.hints = kParameterIsAutomatable; parameter.name = "LFO Delay"; - parameter.symbol = "ch_lfodelay"; + parameter.symbol = "pfau_lfodelay"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 0.0f; @@ -43,7 +43,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pVCORange: parameter.hints = kParameterIsAutomatable | kParameterIsInteger; parameter.name = "Range"; - parameter.symbol = "ch_vcorange"; + parameter.symbol = "pfau_vcorange"; parameter.ranges.min = 0.0f; parameter.ranges.max = 2.0f; parameter.ranges.def = 1.0f; @@ -66,7 +66,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pLFODepth: parameter.hints = kParameterIsAutomatable; parameter.name = "LFO"; - parameter.symbol = "ch_lfo"; + parameter.symbol = "pfau_lfo"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 10.0f; @@ -76,7 +76,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pPWMDepth: parameter.hints = kParameterIsAutomatable; parameter.name = "PWM"; - parameter.symbol = "ch_pwm"; + parameter.symbol = "pfau_pwm"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 48.0f; @@ -86,7 +86,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pPWMMode: parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; parameter.name = "PWM Mode"; - parameter.symbol = "ch_pwmmode"; + parameter.symbol = "pfau_pwmmode"; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; parameter.ranges.def = 1.0f; @@ -107,7 +107,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pSaw: parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; parameter.name = "Saw"; - parameter.symbol = "ch_saw"; + parameter.symbol = "pfau_saw"; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; parameter.ranges.def = 1.0f; @@ -117,7 +117,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pSqr: parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; parameter.name = "Square"; - parameter.symbol = "ch_sqr"; + parameter.symbol = "pfau_sqr"; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; parameter.ranges.def = 1.0f; @@ -127,7 +127,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pSubLevel: parameter.hints = kParameterIsAutomatable; parameter.name = "Sub Osc"; - parameter.symbol = "ch_sub"; + parameter.symbol = "pfau_sub"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 0.0f; @@ -137,7 +137,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pNoiseLevel: parameter.hints = kParameterIsAutomatable; parameter.name = "Noise"; - parameter.symbol = "ch_noise"; + parameter.symbol = "pfau_noise"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 0.0f; @@ -147,7 +147,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pHPF: parameter.hints = kParameterIsAutomatable | kParameterIsInteger; parameter.name = "HPF"; - parameter.symbol = "ch_hpf"; + parameter.symbol = "pfau_hpf"; parameter.ranges.min = 0.0f; parameter.ranges.max = 3.9f; parameter.ranges.def = 0.0f; @@ -157,7 +157,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pCutoff: parameter.hints = kParameterIsAutomatable; parameter.name = "Freq"; - parameter.symbol = "ch_freq"; + parameter.symbol = "pfau_freq"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 60.0f; @@ -166,7 +166,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pRes: parameter.hints = kParameterIsAutomatable; parameter.name = "Res"; - parameter.symbol = "ch_reso"; + parameter.symbol = "pfau_reso"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 0.0f; @@ -175,7 +175,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pVCFPol: parameter.hints = kParameterIsAutomatable | kParameterIsInteger; parameter.name = "Polarity"; - parameter.symbol = "ch_vcfmode"; + parameter.symbol = "pfau_vcfmode"; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; parameter.ranges.def = 0.0f; @@ -195,7 +195,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pEnv: parameter.hints = kParameterIsAutomatable; parameter.name = "Env"; - parameter.symbol = "ch_vcfenv"; + parameter.symbol = "pfau_vcfenv"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 46.0f; @@ -204,7 +204,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pLfo: parameter.hints = kParameterIsAutomatable; parameter.name = "LFO"; - parameter.symbol = "ch_vcflfo"; + parameter.symbol = "pfau_vcflfo"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 0.0f; @@ -213,7 +213,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pKyb: parameter.hints = kParameterIsAutomatable; parameter.name = "Kybd"; - parameter.symbol = "ch_vcfkey"; + parameter.symbol = "pfau_vcfkey"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 71.0f; @@ -223,7 +223,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pAttack: parameter.hints = kParameterIsAutomatable; parameter.name = "Attack"; - parameter.symbol = "ch_attack"; + parameter.symbol = "pfau_attack"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 27.0f; @@ -233,7 +233,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pDecay: parameter.hints = kParameterIsAutomatable; parameter.name = "Decay"; - parameter.symbol = "ch_decay"; + parameter.symbol = "pfau_decay"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 57.0f; @@ -243,7 +243,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pSustain: parameter.hints = kParameterIsAutomatable; parameter.name = "Sustain"; - parameter.symbol = "ch_sustain"; + parameter.symbol = "pfau_sustain"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 57.0f; @@ -253,7 +253,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pRelease: parameter.hints = kParameterIsAutomatable; parameter.name = "Release"; - parameter.symbol = "ch_release"; + parameter.symbol = "pfau_release"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 48.0f; @@ -263,7 +263,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pEnvGate: parameter.hints = kParameterIsAutomatable | kParameterIsInteger; // | kParameterIsBoolean; parameter.name = "Env-Gate"; - parameter.symbol = "ch_envgate"; + parameter.symbol = "pfau_envgate"; parameter.ranges.min = 0.0f; parameter.ranges.max = 1.0f; parameter.ranges.def = 0.0f; @@ -283,17 +283,39 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { case pVCALevel: parameter.hints = kParameterIsAutomatable; parameter.name = "VCA Level"; - parameter.symbol = "ch_vcalevel"; + parameter.symbol = "pfau_vcalevel"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 40.0f; parameter.midiCC = 26; break; + + case pChorusMode: + parameter.hints = kParameterIsAutomatable | kParameterIsInteger; + parameter.name = "Chorus"; + parameter.symbol = "pfau_chorus"; + parameter.ranges.min = 0.0f; + parameter.ranges.max = 2.0f; + parameter.ranges.def = 1.0f; + parameter.midiCC = 12; + parameter.enumValues.count = 3; + parameter.enumValues.restrictedMode = true; + { + ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[3]; + enumValues[0].value = 0.0f; + enumValues[0].label = "Off"; + enumValues[1].value = 1.0f; + enumValues[1].label = "Slow"; + enumValues[2].value = 2.0f; + enumValues[2].label = "Fast"; + parameter.enumValues.values = enumValues; + } + /* case pModWheel: parameter.hints = kParameterIsAutomatable | kParameterIsHidden; parameter.name = "Mod wheel"; - parameter.symbol = "ch_modwheel"; + parameter.symbol = "pfau_modwheel"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; parameter.ranges.def = 0.0f; @@ -379,9 +401,9 @@ void Peacock::setParameterValue(uint32_t index, float value) { m->patchRam.switch1 |= (value >= 0.5) << 4; break; - case pChorus: + case pChorusMode: m->patchRam.switch1 &= 0x9f; - + switch ((int)value) { case 0: m->patchRam.switch1 |= 0x60; // both off @@ -506,8 +528,8 @@ float Peacock::getParameterValue(uint32_t index) const { case pVCALevel: return m->patchRam.vca; break; - case pChorus: - + case pChorusMode: + switch (m->patchRam.switch1 & 0x60) { case 0x60: return 0; @@ -518,8 +540,6 @@ float Peacock::getParameterValue(uint32_t index) const { default: break; } - - } return 0; } diff --git a/plugin/ui.cpp b/plugin/ui.cpp index 53819f4..c15ad38 100644 --- a/plugin/ui.cpp +++ b/plugin/ui.cpp @@ -268,7 +268,7 @@ void DistrhoUIPeacock::parameterChanged(uint32_t index, float value) { sw1 |= (value > 0.5) << 4; break; - case pChorus: + case pChorusMode: sw1 &= 0x9f; // 60, 40, 00 switch ((int)value) { @@ -325,15 +325,15 @@ void DistrhoUIPeacock::imageButtonClicked(ImageButton* imgBtn, int) { break; case btnCh0: sw1 = (sw1 & 0x9f) | 0x20; - setParameterValue(pChorus, 0); + setParameterValue(pChorusMode, 0); break; case btnCh1: sw1 = (sw1 & 0x9f) | 0x40; - setParameterValue(pChorus, 1); + setParameterValue(pChorusMode, 1); break; case btnCh2: sw1 = (sw1 & 0x9f); - setParameterValue(pChorus, 2); + setParameterValue(pChorusMode, 2); break; default: From 2d53d3c5da7ed385f6dbb6f0c6d311eef4aed567 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Fri, 26 Dec 2025 00:28:58 +0000 Subject: [PATCH 2/5] parameter MIDI value --- plugin/parameters.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp index a73b9a3..7677e94 100644 --- a/plugin/parameters.cpp +++ b/plugin/parameters.cpp @@ -296,8 +296,8 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) { parameter.symbol = "pfau_chorus"; parameter.ranges.min = 0.0f; parameter.ranges.max = 2.0f; - parameter.ranges.def = 1.0f; - parameter.midiCC = 12; + parameter.ranges.def = 0.0f; + parameter.midiCC = 93; parameter.enumValues.count = 3; parameter.enumValues.restrictedMode = true; { From 36c27f14d8fd07aed9541c1eeb5112edefc282e5 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Fri, 26 Dec 2025 22:08:52 +0000 Subject: [PATCH 3/5] mystran filter --- plugin/module.cpp | 2 +- plugin/module.hpp | 27 ++++++++++- plugin/voice.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 134 insertions(+), 12 deletions(-) diff --git a/plugin/module.cpp b/plugin/module.cpp index 99b5d51..aff551c 100644 --- a/plugin/module.cpp +++ b/plugin/module.cpp @@ -74,7 +74,7 @@ void Module::run(Voice* voices, uint32_t blockSize) { sub = patchRam.sub / 127.0f; lfoPhase += lfoRateTable[patchRam.lfoRate]; - res = patchRam.vcfReso / 127.0 * 5; + res = patchRam.vcfReso / 127.0; noise = patchRam.noise / 127.0; // FIXME the exp in these is expensive, don't call it all the time diff --git a/plugin/module.hpp b/plugin/module.hpp index a28902f..0b451e6 100644 --- a/plugin/module.hpp +++ b/plugin/module.hpp @@ -48,6 +48,7 @@ class Module { float saw = 0, square = 0, sub = 0, noise = 0; +#if 0 struct { uint8_t lfoRate = 0x58; uint8_t lfoDelay = 0x00; @@ -68,6 +69,29 @@ class Module { uint8_t switch1 = 0x4a; uint8_t switch2 = 0x18; } patchRam; + +#else + struct { + uint8_t lfoRate = 0x40; + uint8_t lfoDelay = 0x00; + uint8_t vcoLfo = 0x00; + uint8_t pwmLfo = 0x00; + uint8_t noise = 0x01; + uint8_t vcfFreq = 0x31; + uint8_t vcfReso = 0x7f; + uint8_t vcfEnv = 0x00; + uint8_t vcfLfo = 0x00; + uint8_t vcfKey = 0x7f; + uint8_t vca = 0x40; + uint8_t env_a = 0x00; + uint8_t env_d = 0x00; + uint8_t env_s = 0x00; // 0x3f80 + uint8_t env_r = 0x00; + uint8_t sub = 0x00; + uint8_t switch1 = 0x22; + uint8_t switch2 = 0x1d; + } patchRam; +#endif Chorus* chorus; float vcaTC; @@ -111,7 +135,8 @@ class Voice { uint8_t note = 0; // filter - float b1 = 0, b2 = 0, b3 = 0, b4 = 0; + float y0 = 0, y1 = 0, y2 = 0, y3 = 0; + double s[4] = {0, 0, 0, 0}; }; #endif diff --git a/plugin/voice.cpp b/plugin/voice.cpp index ec81b15..1b4d1ac 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -50,16 +50,46 @@ void Voice::off() { envPhase = 0; } + +// tanh(x)/x approximation, flatline at very high inputs +// so might not be safe for very large feedback gains +// [limit is 1/15 so very large means ~15 or +23dB] + + +double tanhXdX(double x) { + + return 1-0.1*abs(x); + double a = x*x; + // IIRC I got this as Pade-approx for tanh(sqrt(x))/sqrt(x) + return ((a + 105)*a + 945) / ((15*a + 420)*a + 945); +} + + void Voice::run(Module* m, float* buffer, uint32_t samples) { // carry out per-voice calculations for each block of samples float out, t, fb; - // FIXME incorrect +double zi; + + // calculate cutoff frequency float cut = 248.0f * (powf(2, (vcfCut - 0x1880) / 1143.0f)); - cut = 0.25 * 6.2832 * cut / 48000.0f; // FIXME hardcoded values + cut = M_PI * cut / sampleRate; cut = cut / (1 + cut); // correct tuning warp + + // printf("%f\n", cut); + + //if (cut > 0.5) cut = 0.5; + + // double f = tan(cut); + + + //printf("cut = %4f f = %4f\n", cut, f); + + double r = (40.0/9.0) * m->res; + + float amp = vcaEnv / 4096.0f; for (uint32_t i = 0; i < samples; i++) { @@ -98,13 +128,80 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) { delay += m->subBuf[i] * subosc ; out += m->noise * (0.8 - 1.6 * (rand() & 0xffff) / 65536.0); - out *= 0.5; + out *= 0.01; // same time constant for both VCF and VCF RC circuits vcfRC = (cut - vcfRC) * m->vcaTC + vcfRC; +#if 1 + +//// LICENSE TERMS: Copyright 2012 Teemu Voipio +// +// You can use this however you like for pretty much any purpose, +// as long as you don't claim you wrote it. There is no warranty. +// +// Distribution of substantial portions of this code in source form +// must include this copyright notice and list of conditions. +// + +// input delay and state for member variables + +// cutoff as normalized frequency (eg 0.5 = Nyquist) +// resonance from 0 to 1, self-oscillates at settings over 0.9 +//void transistorLadder( +// double cutoff, double resonance, +// double * in, double * out, unsigned nsamples) +//{ + // tuning and feedback + + //------------------------------------------------------------------------------ sample loop + //for(unsigned n = 0; n < nsamples; ++n) + //{ + // input with half delay, for non-linearities + double ih = 0.5 * (out + zi); zi = out; + + //double ih = out; + + // evaluate the non-linear gains + double t0 = tanhXdX((ih * (r+1))- r * s[3]); + + double t1 = tanhXdX(s[0]); + double t2 = tanhXdX(s[1]); + double t3 = tanhXdX(s[2]); + double t4 = tanhXdX(s[3]); + + double f = vcfRC; + + // g# the denominators for solutions of individual stages + double g0 = 1 / (1 + f*t1), g1 = 1 / (1 + f*t2); + double g2 = 1 / (1 + f*t3), g3 = 1 / (1 + f*t4); + + // f# are just factored out of the feedback solution + double f3 = f*t3*g3, f2 = f*t2*g2*f3, f1 = f*t1*g1*f2, f0 = f*t0*g0*f1; + + // solve feedback + double y3 = (g3*s[3] + f3*g2*s[2] + f2*g1*s[1] + f1*g0*s[0] + f0*out) / (1 + r*f0); + + // then solve the remaining outputs (with the non-linear gains here) + double xx = t0*((out * (r+1)) - r*y3); + double y0 = t1*g0*(s[0] + f*xx); + double y1 = t2*g1*(s[1] + f*y0); + double y2 = t3*g2*(s[2] + f*y1); + + // update state + s[0] += 2*f * (xx - y0); + s[1] += 2*f * (y0 - y1); + s[2] += 2*f * (y1 - y2); + s[3] += 2*f * (y2 - t4*y3); + + //out[n] = y3; + // } + + +#else + for (uint8_t ovs = 0; ovs < 4; ovs++) { - fb = b4; + fb = y3; // hard clip fb = ((out * 0.5) - fb) * m->res; if (fb > 4) fb = 4; @@ -112,14 +209,14 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) { // fb = 1.5 * fb - 0.5 * fb * fb * fb; // - b1 = ((out + fb - b1) * vcfRC) + b1; - b2 = ((b1 - b2) * vcfRC) + b2; - b3 = ((b2 - b3) * vcfRC) + b3; - b4 = ((b3 - b4) * vcfRC) + b4; + y0 = ((out + fb - y0) * vcfRC) + y0; + y1 = ((y0 - y1) * vcfRC) + y1; + y2 = ((y1 - y2) * vcfRC) + y2; + y3 = ((y2 - y3) * vcfRC) + y3; } - +#endif vcaRC = (amp - vcaRC) * m->vcaTC + vcaRC; - buffer[i] += 0.09367 * m->vcaBuf[i] * vcaRC * b4; + buffer[i] += 1 * m->vcaBuf[i] * vcaRC * y3; lastpw = m->pwmBuf[i]; } From ad7b7f440561c3eee4cc8ec0b44373b320a0f56e Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Sun, 28 Dec 2025 12:08:42 +0000 Subject: [PATCH 4/5] formatting cleanup --- plugin/module.hpp | 95 +++++++++++++++++++++------------ plugin/voice.cpp | 133 +++++++++++++++++++++------------------------- 2 files changed, 120 insertions(+), 108 deletions(-) diff --git a/plugin/module.hpp b/plugin/module.hpp index 0b451e6..642dffd 100644 --- a/plugin/module.hpp +++ b/plugin/module.hpp @@ -48,50 +48,74 @@ class Module { float saw = 0, square = 0, sub = 0, noise = 0; -#if 0 - struct { - uint8_t lfoRate = 0x58; - uint8_t lfoDelay = 0x00; - uint8_t vcoLfo = 0x00; - uint8_t pwmLfo = 0x3b; - uint8_t noise = 0x00; - uint8_t vcfFreq = 0x25; // 1c; // 0x3f80 - uint8_t vcfReso = 0x6a; - uint8_t vcfEnv = 0x25; // 4e; - uint8_t vcfLfo = 0x00; - uint8_t vcfKey = 0x00; // 47; - uint8_t vca = 0x35; - uint8_t env_a = 0x00; - uint8_t env_d = 0x3c; - uint8_t env_s = 0x00; // 0x3f80 - uint8_t env_r = 0x3c; - uint8_t sub = 0x7f; - uint8_t switch1 = 0x4a; - uint8_t switch2 = 0x18; - } patchRam; + /* + #if 0 + struct { + uint8_t lfoRate = 0x58; + uint8_t lfoDelay = 0x00; + uint8_t vcoLfo = 0x00; + uint8_t pwmLfo = 0x3b; + uint8_t noise = 0x00; + uint8_t vcfFreq = 0x25; // 1c; // 0x3f80 + uint8_t vcfReso = 0x6a; + uint8_t vcfEnv = 0x25; // 4e; + uint8_t vcfLfo = 0x00; + uint8_t vcfKey = 0x00; // 47; + uint8_t vca = 0x35; + uint8_t env_a = 0x00; + uint8_t env_d = 0x3c; + uint8_t env_s = 0x00; // 0x3f80 + uint8_t env_r = 0x3c; + uint8_t sub = 0x7f; + uint8_t switch1 = 0x4a; + uint8_t switch2 = 0x18; + } patchRam; + + #else + struct { + uint8_t lfoRate = 0x40; + uint8_t lfoDelay = 0x00; + uint8_t vcoLfo = 0x00; + uint8_t pwmLfo = 0x00; + uint8_t noise = 0x01; + uint8_t vcfFreq = 0x31; + uint8_t vcfReso = 0x7f; + uint8_t vcfEnv = 0x00; + uint8_t vcfLfo = 0x00; + uint8_t vcfKey = 0x7f; + uint8_t vca = 0x40; + uint8_t env_a = 0x00; + uint8_t env_d = 0x00; + uint8_t env_s = 0x00; // 0x3f80 + uint8_t env_r = 0x00; + uint8_t sub = 0x00; + uint8_t switch1 = 0x22; + uint8_t switch2 = 0x1d; + } patchRam; + #endif + */ -#else struct { - uint8_t lfoRate = 0x40; + uint8_t lfoRate = 0x58; uint8_t lfoDelay = 0x00; uint8_t vcoLfo = 0x00; uint8_t pwmLfo = 0x00; - uint8_t noise = 0x01; - uint8_t vcfFreq = 0x31; + uint8_t noise = 0x00; + uint8_t vcfFreq = 0x00; // 1c; // 0x3f80 uint8_t vcfReso = 0x7f; - uint8_t vcfEnv = 0x00; + uint8_t vcfEnv = 0x7f; // 4e; uint8_t vcfLfo = 0x00; - uint8_t vcfKey = 0x7f; - uint8_t vca = 0x40; + uint8_t vcfKey = 0x00; // 47; + uint8_t vca = 0x20; uint8_t env_a = 0x00; - uint8_t env_d = 0x00; + uint8_t env_d = 0x5c; uint8_t env_s = 0x00; // 0x3f80 - uint8_t env_r = 0x00; - uint8_t sub = 0x00; - uint8_t switch1 = 0x22; - uint8_t switch2 = 0x1d; + uint8_t env_r = 0x3c; + uint8_t sub = 0x7f; + uint8_t switch1 = 0x3a; + uint8_t switch2 = 0x19; } patchRam; -#endif + Chorus* chorus; float vcaTC; @@ -128,7 +152,7 @@ class Voice { uint8_t envPhase = 0; int16_t env = 0; // output amplitude - int16_t vcfCut; + uint16_t vcfCut; int16_t vcaEnv; float vcaRC = 0, vcfRC = 0; @@ -137,6 +161,7 @@ class Voice { // filter float y0 = 0, y1 = 0, y2 = 0, y3 = 0; double s[4] = {0, 0, 0, 0}; + float zi = 0; }; #endif diff --git a/plugin/voice.cpp b/plugin/voice.cpp index 1b4d1ac..9b268c2 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -41,7 +41,7 @@ Voice::Voice() { void Voice::on(uint8_t midiNote) { while (midiNote < 24) midiNote += 12; - while (midiNote > 108) midiNote -=12; + while (midiNote > 108) midiNote -= 12; note = midiNote - 24; envPhase = 1; } @@ -50,45 +50,26 @@ void Voice::off() { envPhase = 0; } - // tanh(x)/x approximation, flatline at very high inputs // so might not be safe for very large feedback gains // [limit is 1/15 so very large means ~15 or +23dB] - double tanhXdX(double x) { + float s = 0.0333, d = 30.0; + return 1.0f - s * (d + 1.0f) * x * x / (d + x * x); - return 1-0.1*abs(x); - double a = x*x; - // IIRC I got this as Pade-approx for tanh(sqrt(x))/sqrt(x) - return ((a + 105)*a + 945) / ((15*a + 420)*a + 945); } - void Voice::run(Module* m, float* buffer, uint32_t samples) { // carry out per-voice calculations for each block of samples float out, t, fb; -double zi; - - // calculate cutoff frequency - float cut = 248.0f * (powf(2, (vcfCut - 0x1880) / 1143.0f)); + float cut = 261.0f * (powf(2, (vcfCut - 0x1880) / 1143.0f)); cut = M_PI * cut / sampleRate; - cut = cut / (1 + cut); // correct tuning warp - - - // printf("%f\n", cut); - - //if (cut > 0.5) cut = 0.5; - - // double f = tan(cut); - - - //printf("cut = %4f f = %4f\n", cut, f); - - double r = (40.0/9.0) * m->res; - + cut = cut / (1 + cut); // correct tuning warp + // if (cut > 0.7) cut = 0.7; + double r = 5 * m->res; float amp = vcaEnv / 4096.0f; @@ -125,46 +106,49 @@ double zi; // FIXME DC offset removal delay += m->saw * (1 - (2 * theta)); delay += m->square * ((pulseStage ? -1.f : 1.f) - m->pwmBuf[i] + 0.5); - delay += m->subBuf[i] * subosc ; - + delay += m->subBuf[i] * subosc; + out += m->noise * (0.8 - 1.6 * (rand() & 0xffff) / 65536.0); - out *= 0.01; + // out *= 0.1; // same time constant for both VCF and VCF RC circuits vcfRC = (cut - vcfRC) * m->vcaTC + vcfRC; #if 1 -//// LICENSE TERMS: Copyright 2012 Teemu Voipio -// -// You can use this however you like for pretty much any purpose, -// as long as you don't claim you wrote it. There is no warranty. -// -// Distribution of substantial portions of this code in source form -// must include this copyright notice and list of conditions. -// + //// LICENSE TERMS: Copyright 2012 Teemu Voipio + // + // You can use this however you like for pretty much any purpose, + // as long as you don't claim you wrote it. There is no warranty. + // + // Distribution of substantial portions of this code in source form + // must include this copyright notice and list of conditions. + // -// input delay and state for member variables + // input delay and state for member variables -// cutoff as normalized frequency (eg 0.5 = Nyquist) -// resonance from 0 to 1, self-oscillates at settings over 0.9 -//void transistorLadder( -// double cutoff, double resonance, -// double * in, double * out, unsigned nsamples) -//{ - // tuning and feedback + // cutoff as normalized frequency (eg 0.5 = Nyquist) + // resonance from 0 to 1, self-oscillates at settings over 0.9 + // void transistorLadder( + // double cutoff, double resonance, + // double * in, double * out, unsigned nsamples) + //{ + // tuning and feedback - //------------------------------------------------------------------------------ sample loop - //for(unsigned n = 0; n < nsamples; ++n) - //{ + //------------------------------------------------------------------------------ sample loop + // for(unsigned n = 0; n < nsamples; ++n) + //{ + + out *= 0.025; // input with half delay, for non-linearities - double ih = 0.5 * (out + zi); zi = out; + double ih = 0.5 * (out + zi); + zi = out; - //double ih = out; + // double ih = out; // evaluate the non-linear gains - double t0 = tanhXdX((ih * (r+1))- r * s[3]); - + double t0 = tanhXdX((ih * (r + 1)) - r * s[3]); + double t1 = tanhXdX(s[0]); double t2 = tanhXdX(s[1]); double t3 = tanhXdX(s[2]); @@ -173,37 +157,40 @@ double zi; double f = vcfRC; // g# the denominators for solutions of individual stages - double g0 = 1 / (1 + f*t1), g1 = 1 / (1 + f*t2); - double g2 = 1 / (1 + f*t3), g3 = 1 / (1 + f*t4); - - // f# are just factored out of the feedback solution - double f3 = f*t3*g3, f2 = f*t2*g2*f3, f1 = f*t1*g1*f2, f0 = f*t0*g0*f1; + double g0 = 1 / (1 + f * t1), g1 = 1 / (1 + f * t2); + double g2 = 1 / (1 + f * t3), g3 = 1 / (1 + f * t4); - // solve feedback - double y3 = (g3*s[3] + f3*g2*s[2] + f2*g1*s[1] + f1*g0*s[0] + f0*out) / (1 + r*f0); + // f# are just factored out of the feedback solution + double f3 = f * t3 * g3, f2 = f * t2 * g2 * f3, f1 = f * t1 * g1 * f2, f0 = f * t0 * g0 * f1; + + // solve feedback + double y3 = (g3 * s[3] + f3 * g2 * s[2] + f2 * g1 * s[1] + f1 * g0 * s[0] + f0 * out) / (1 + r * f0); // then solve the remaining outputs (with the non-linear gains here) - double xx = t0*((out * (r+1)) - r*y3); - double y0 = t1*g0*(s[0] + f*xx); - double y1 = t2*g1*(s[1] + f*y0); - double y2 = t3*g2*(s[2] + f*y1); + double xx = t0 * ((out * (r + 1)) - r * y3); + double y0 = t1 * g0 * (s[0] + f * xx); + double y1 = t2 * g1 * (s[1] + f * y0); + double y2 = t3 * g2 * (s[2] + f * y1); // update state - s[0] += 2*f * (xx - y0); - s[1] += 2*f * (y0 - y1); - s[2] += 2*f * (y1 - y2); - s[3] += 2*f * (y2 - t4*y3); + s[0] += 2 * f * (xx - y0); + s[1] += 2 * f * (y0 - y1); + s[2] += 2 * f * (y1 - y2); + s[3] += 2 * f * (y2 - t4 * y3); - //out[n] = y3; - // } + // out[n] = y3; + // } + // out *= 0.1; + out = y3; #else - for (uint8_t ovs = 0; ovs < 4; ovs++) { + out *= 0.5; + for (uint8_t ovs = 0; ovs < 2; ovs++) { fb = y3; // hard clip - fb = ((out * 0.5) - fb) * m->res; + fb = ((out * 0.5) - fb) * r; if (fb > 4) fb = 4; if (fb < -4) fb = -4; // fb = 1.5 * fb - 0.5 * fb * fb * fb; @@ -216,8 +203,8 @@ double zi; } #endif vcaRC = (amp - vcaRC) * m->vcaTC + vcaRC; - buffer[i] += 1 * m->vcaBuf[i] * vcaRC * y3; - + buffer[i] += m->vcaBuf[i] * vcaRC * out; + lastpw = m->pwmBuf[i]; } // buffer[0] += 1; From bad4e6b0189099f4ef555f4d63129eabc7f3ce0e Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Tue, 30 Dec 2025 01:02:55 +0000 Subject: [PATCH 5/5] tune lfo speeds a bit --- plugin/chorus.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin/chorus.cpp b/plugin/chorus.cpp index d6a8431..1a16739 100644 --- a/plugin/chorus.cpp +++ b/plugin/chorus.cpp @@ -21,6 +21,7 @@ #include #include +#include Chorus::Chorus() { lpfOut1 = new float[bufferSize]; lpfOut2 = new float[bufferSize]; @@ -102,6 +103,7 @@ void Chorus::run(float* input, float** outputs, uint32_t frames) { delayptr++; delayptr &= 0x3ff; } + //printf("dly1 = %f\n", dly1); postFilter1l->runSVF(lpfOut1, lpfOut1, frames); postFilter2l->runSVF(lpfOut1, lpfOut1, frames); @@ -152,11 +154,11 @@ void Chorus::setChorus(uint8_t mode) { break; case 0x40: gain = 1.2; - lfoSpeed = 6.283 * 0.5 / sampleRate; + lfoSpeed = 6.283 * 0.3 / sampleRate; break; case 0x00: gain = 1.2; - lfoSpeed = 6.283 * 0.9 / sampleRate; + lfoSpeed = 6.283 * 0.5 / sampleRate; break; } }