From 620914b5002f164f2593f2d8f9d2cb53fffca774 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Wed, 11 Sep 2024 21:40:11 +0100 Subject: [PATCH] saneish looking parameters --- plugin/chassis.cpp | 19 ++++++---- plugin/parameters.cpp | 83 +++++++++++++++++++++++-------------------- plugin/voice.cpp | 18 +++++----- plugin/voice.hpp | 34 +++++++++--------- 4 files changed, 85 insertions(+), 69 deletions(-) diff --git a/plugin/chassis.cpp b/plugin/chassis.cpp index e0b3fa4..7e805c5 100644 --- a/plugin/chassis.cpp +++ b/plugin/chassis.cpp @@ -40,6 +40,7 @@ void Chassis::initProgramName(uint32_t index, String &programName) { } void Chassis::loadProgram(uint32_t index) { + uint8_t paramOrder[16] = { paramLFORate, paramLFODelay, @@ -60,14 +61,20 @@ void Chassis::loadProgram(uint32_t index) { for (uint i = 0; i < 16; i++) { setParameterValue(paramOrder[i], (float)patchData[index][i]); } - setParameterValue(paramVCORange, patchData[index][16] & 0x07); - setParameterValue(paramSaw, (patchData[index][16] & 0x10) ? 127.0f : 0.0f); - setParameterValue(paramSqr, (patchData[index][16] & 0x08) ? 127.0f : 0.0f); + + switch (patchData[index][16] & 0x07) { + case 1: setParameterValue(paramVCORange, 0); break; + case 4: setParameterValue(paramVCORange, 2); break; + default: setParameterValue(paramVCORange, 1); break; + } + + setParameterValue(paramSaw, (patchData[index][16] & 0x10) ? 1.0f : 0.0f); + setParameterValue(paramSqr, (patchData[index][16] & 0x08) ? 1.0f : 0.0f); // FIXME chorus switch settings - setParameterValue(paramPWMMode, (patchData[index][17] & 0x01) ? 127.0f : 0.0f); - setParameterValue(paramVCFMode, (patchData[index][17] & 0x02) ? 127.0f : 0.0f); - setParameterValue(paramEnvGate, (patchData[index][17] & 0x04) ? 127.0f : 0.0f); + setParameterValue(paramPWMMode, (patchData[index][17] & 0x01) ? 0.0f : 1.0f); + setParameterValue(paramVCFMode, (patchData[index][17] & 0x02) ? 0.0f : 1.0f); + setParameterValue(paramEnvGate, (patchData[index][17] & 0x04) ? 0.0f : 1.0f); setParameterValue(paramHPF, (patchData[index][17] & 0x18) >> 3); } diff --git a/plugin/parameters.cpp b/plugin/parameters.cpp index 4fc05f6..5ff5367 100644 --- a/plugin/parameters.cpp +++ b/plugin/parameters.cpp @@ -26,7 +26,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_lforate"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 57.0f; + parameter.ranges.def = 48.0f; parameter.midiCC = 3; break; @@ -36,7 +36,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_lfodelay"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 45.0f; + parameter.ranges.def = 0.0f; parameter.midiCC = 9; break; @@ -45,8 +45,8 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.name = "Range"; parameter.symbol = "ch_vcorange"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 4.0f; - parameter.ranges.def = 2.0f; + parameter.ranges.max = 2.0f; + parameter.ranges.def = 1.0f; parameter.midiCC = 12; break; @@ -56,7 +56,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_lfo"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; + parameter.ranges.def = 10.0f; parameter.midiCC = 13; break; @@ -66,7 +66,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_pwm"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 55.0f; + parameter.ranges.def = 48.0f; parameter.midiCC = 14; break; @@ -75,8 +75,8 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.name = "PWM Mode"; parameter.symbol = "ch_pwmmode"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; + parameter.ranges.max = 1.0f; + parameter.ranges.def = 1.0f; parameter.midiCC = 15; break; @@ -85,8 +85,8 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.name = "Saw"; parameter.symbol = "ch_saw"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 127.0f; - parameter.ranges.def = 127.0f; + parameter.ranges.max = 1.0f; + parameter.ranges.def = 1.0f; parameter.midiCC = 17; break; @@ -95,8 +95,8 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.name = "Square"; parameter.symbol = "ch_sqr"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 127.0f; - parameter.ranges.def = 127.0f; + parameter.ranges.max = 1.0f; + parameter.ranges.def = 1.0f; parameter.midiCC = 16; break; @@ -125,7 +125,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.name = "HPF"; parameter.symbol = "ch_hpf"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 4.0f; + parameter.ranges.max = 3.0f; parameter.ranges.def = 0.0f; parameter.midiCC = 20; break; @@ -136,7 +136,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_freq"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; + parameter.ranges.def = 60.0f; parameter.midiCC = 74; break; case paramVCFReso: @@ -153,8 +153,8 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.name = "Polarity"; parameter.symbol = "ch_vcfmode"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; + parameter.ranges.max = 1.0f; + parameter.ranges.def = 1.0f; parameter.midiCC = 21; break; case paramVCFEnv: @@ -163,7 +163,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_vcfenv"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; + parameter.ranges.def = 46.0f; parameter.midiCC = 22; break; case paramVCFLFO: @@ -181,7 +181,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_vcfkey"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; + parameter.ranges.def = 71.0f; parameter.midiCC = 24; break; @@ -191,7 +191,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_attack"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 59.0f; + parameter.ranges.def = 27.0f; parameter.midiCC = 73; break; @@ -201,7 +201,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_decay"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 32.0f; + parameter.ranges.def = 57.0f; parameter.midiCC = 75; break; @@ -211,7 +211,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_sustain"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 86.0f; + parameter.ranges.def = 57.0f; parameter.midiCC = 27; break; @@ -221,7 +221,7 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.symbol = "ch_release"; parameter.ranges.min = 0.0f; parameter.ranges.max = 127.0f; - parameter.ranges.def = 40.0f; + parameter.ranges.def = 48.0f; parameter.midiCC = 72; break; @@ -230,8 +230,8 @@ void Chassis::initParameter(uint32_t index, Parameter ¶meter) { parameter.name = "Env-Gate"; parameter.symbol = "ch_envgate"; parameter.ranges.min = 0.0f; - parameter.ranges.max = 127.0f; - parameter.ranges.def = 0.0f; + parameter.ranges.max = 1.0f; + parameter.ranges.def = 1.0f; parameter.midiCC = 25; break; @@ -263,6 +263,8 @@ void Chassis::setParameterValue(uint32_t index, float value) { if (value < 0.0f) value = 0.0f; if (value > 127.0f) value = 127.0f; + //printf("setparam %d %f\n", index, value); + switch (index) { case paramLFORate: s.patchRam.lfoRate = value; @@ -321,16 +323,16 @@ void Chassis::setParameterValue(uint32_t index, float value) { case paramVCORange: // bits 0-2 of switch 1 // doesn't look great in Carla because of odd behaviour with small integer knobs s.patchRam.switch1 &= 0xf8; - s.patchRam.switch1 |= (1 << (int)value); + s.patchRam.switch1 |= (1 << (int)(value-1)); break; case paramSqr: // bit 3 of switch 1 s.patchRam.switch1 &= 0xf7; - s.patchRam.switch1 |= (value > 63) << 3; + s.patchRam.switch1 |= (value >= 0.5 ) << 3; break; case paramSaw: // bit 4 of switch 1 s.patchRam.switch1 &= 0xef; - s.patchRam.switch1 |= (value > 63) << 4; + s.patchRam.switch1 |= (value >= 0.5) << 4; break; // missing chorus switch @@ -338,16 +340,16 @@ void Chassis::setParameterValue(uint32_t index, float value) { // switch 2 params case paramPWMMode: // bit 0 of switch 2 s.patchRam.switch2 &= 0xfe; - s.patchRam.switch2 |= (value > 63); + s.patchRam.switch2 |= (value < 0.5); break; case paramVCFMode: // bit 1 of switch 2 s.patchRam.switch2 &= 0xfd; - s.patchRam.switch2 |= (value > 63) << 1; + s.patchRam.switch2 |= (value < 0.5) << 1; break; case paramEnvGate: s.patchRam.switch2 &= 0xfb; - s.patchRam.switch2 |= (value > 63) << 2; + s.patchRam.switch2 |= (value < 0.5) << 2; break; case paramHPF: // bits 3-4 of switch 2 @@ -364,7 +366,7 @@ void Chassis::setParameterValue(uint32_t index, float value) { } float Chassis::getParameterValue(uint32_t index) const { - // printf("getparametervalue %d\n", index); + //printf("getparametervalue %d\n", index); switch (index) { case paramLFORate: return s.patchRam.lfoRate; @@ -374,7 +376,11 @@ float Chassis::getParameterValue(uint32_t index) const { break; case paramVCORange: // FIXME this needs to be better generally - return (s.patchRam.switch1 & 0x07) << 1; + switch (s.patchRam.switch1 & 0x07) { + case 1: return 0; break; + case 4: return 2; break; + default: return 1; + } break; case paramVCOLFO: return s.patchRam.vcoLfo; @@ -382,15 +388,16 @@ float Chassis::getParameterValue(uint32_t index) const { case paramPWMLFO: return s.patchRam.pwmLfo * 1.27f; break; + + // the "slide switches" appear inverted because up is on case paramPWMMode: - return (s.patchRam.switch2 & 0x01) ? 127.0f : 0.0f; + return (s.patchRam.switch2 & 0x01) ? 0.0f : 1.0f; break; - case paramSaw: - return (s.patchRam.switch1 & 0x10) ? 127.0f : 0.0f; + return (s.patchRam.switch1 & 0x10) ? 1.0f : 0.0f; break; case paramSqr: - return (s.patchRam.switch1 & 0x08) ? 127.0f : 0.0f; + return (s.patchRam.switch1 & 0x08) ? 1.0f : 0.0f; break; case paramSub: @@ -418,7 +425,7 @@ float Chassis::getParameterValue(uint32_t index) const { return s.patchRam.vcfKey; break; case paramVCFMode: - return (s.patchRam.switch2 & 0x02) ? 127.0f : 0.0f; + return (s.patchRam.switch2 & 0x02) ? 0.0f : 1.0f; break; case paramAttack: @@ -435,7 +442,7 @@ float Chassis::getParameterValue(uint32_t index) const { break; case paramEnvGate: - return (s.patchRam.switch2 & 0x04) ? 127.0f : 0.0f; + return (s.patchRam.switch2 & 0x04) ? 0.0f : 1.0f; break; case paramVCALevel: diff --git a/plugin/voice.cpp b/plugin/voice.cpp index 4bad19f..859ef30 100644 --- a/plugin/voice.cpp +++ b/plugin/voice.cpp @@ -42,14 +42,14 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) { float pw = s.ff4f / 32768.0f; float fb, res = s.patchRam.vcfReso / 28.0f; // guess - //float cut = s.patchRam.vcfFreq / 400.0f; // guess + // float cut = s.patchRam.vcfFreq / 400.0f; // guess - float cut = 248.0f * (powf(2,(vcfenv-0x1880)/1143.0f)); + float cut = 248.0f * (powf(2, (vcfenv - 0x1880) / 1143.0f)); // now radians cut = 0.25 * 6.2832 * cut / 48000.0f; // now correct - cut = cut/(1+cut); + cut = cut / (1 + cut); float sqr = (s.patchRam.switch1 & 0x08) ? 0.63 : 0; //? 0.175 : 0; float saw = (s.patchRam.switch1 & 0x10) ? 0.8 : 0; //? 0.220 : 0; @@ -57,7 +57,9 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) { float gain = 0.5 * powf(2, (s.patchRam.vca / 64.0f) - 1); - float vcaEnv = (s.patchRam.switch2 & 0x04) ? (float)ff11 : (env / 16384.0f); + //printf("patchram.switches= %3d %3d\n", s.patchRam.switch1, s.patchRam.switch2); + + float vcaEnv = (s.patchRam.switch2 & 0x04) ? (float)ff11:(env / 16384.0f); for (uint32_t i = 0; i < samples; i++) { y = delay; @@ -103,7 +105,7 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) { out = y; // widthDelay = pw; - //out *= 0.5; + out *= 0.707; for (uint8_t ovs = 0; ovs < 4; ovs++) { fb = b4; @@ -118,11 +120,11 @@ void Voice::run(Synth &s, float *buffer, uint32_t samples) { b4 = ((b3 - b4) * cut) + b4; } - vr58c106 += ((vcaEnv - vr58c106) * 0.0075); + vr58c106 += ((vcaEnv - vr58c106) * 0.005); lastpw = pw; - out = b4 * (0.2); + out = b4 * (0.5); - buffer[i] += (gain * b4 * vr58c106); + buffer[i] += (gain * out * vr58c106); } } diff --git a/plugin/voice.hpp b/plugin/voice.hpp index 8775a25..43f19b0 100644 --- a/plugin/voice.hpp +++ b/plugin/voice.hpp @@ -112,24 +112,24 @@ class Synth { // the comments indicate what the defaults are set to // in the routine at 02c2h, in case they're important struct { - uint8_t lfoRate = 57; // lookup value defaults to 0x0200 - uint8_t lfoDelay = 45; - uint8_t vcoLfo = 0; - uint8_t pwmLfo = 55; - uint8_t noise = 0; - uint8_t vcfFreq = 85; // 0x3f80 - uint8_t vcfReso = 0; - uint8_t vcfEnv = 0; + uint8_t lfoRate = 0x30; // lookup value defaults to 0x0200 + uint8_t lfoDelay = 0x00; + uint8_t vcoLfo = 0x0a; + uint8_t pwmLfo = 0x30; + uint8_t noise = 0x00; + uint8_t vcfFreq = 0x3c; // 0x3f80 + uint8_t vcfReso = 0x00; + uint8_t vcfEnv = 0x2e; uint8_t vcfLfo = 0; - uint8_t vcfKey = 108; - uint8_t vca = 52; - uint8_t env_a = 59; - uint8_t env_d = 32; - uint8_t env_s = 86; // 0x3f80 - uint8_t env_r = 40; - uint8_t sub = 0; - uint8_t switch1 = 26; - uint8_t switch2 = 24; + uint8_t vcfKey = 0x47; + uint8_t vca = 0x28; + uint8_t env_a = 0x1b; + uint8_t env_d = 0x39; + uint8_t env_s = 0x39; // 0x3f80 + uint8_t env_r = 0x30; + uint8_t sub = 0x00; + uint8_t switch1 = 0x1a; + uint8_t switch2 = 0x18; } patchRam; float pitchCV[104];