From 66d2cec2c91d9c9916123d9c253fc608866774ed Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Thu, 17 Oct 2024 23:57:28 +0100 Subject: [PATCH] now pulls some patch params from patchram --- plugin/ic29.cpp | 23 ++++++++++++----------- plugin/ic29.hpp | 29 +++++++++++++++++++++++++---- plugin/oscillator.cpp | 2 +- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/plugin/ic29.cpp b/plugin/ic29.cpp index 966232e..7552521 100644 --- a/plugin/ic29.cpp +++ b/plugin/ic29.cpp @@ -24,10 +24,6 @@ Synth ic29; Synth::Synth() { d_debug("initialising synth\n"); - envAtk = 0x00; - envDcy = 0x1f; - envStn = 0x00; - envRls = 0x1f; portaCoeff = 0x0; lfo.speed = 0x06; } @@ -56,9 +52,9 @@ void Synth::run() { // PWM is bit 0 sw2, 0 = fixed 1 = lfo // 0 sets EA to 0x3fff, 1 adds uint16_t pwmVal = 0x2000 - ic29.lfo.lfoOut; - if (0) pwmVal = 0x3fff; + if (ic29.patchRam.switch2 & 0x01) pwmVal = 0x3fff; - ic29.pwm = pwmVal / 40960.0f * (1); // 0.5 is knob val + ic29.pwm = 0.5 - pwmVal / 40960.0f * (ic29.patchRam.pwmLfoMod/128.0f); for (uint8_t i = 0; i < NUM_VOICES; i++) { ic29.voices[i].update(); @@ -111,10 +107,10 @@ Envelope::Envelope() { } void Envelope::run() { - uint16_t tempStn = ic29.envStn << 7; + uint16_t tempStn = ic29.patchRam.sustain << 7; switch (phase) { case ENV_ATK: - level += atkTable[ic29.envAtk]; + level += atkTable[ic29.patchRam.attack]; if (level > 0x3fff) { level = 0x3fff; phase = ENV_DCY; @@ -122,13 +118,13 @@ void Envelope::run() { break; case ENV_DCY: if (level > tempStn) { - level = (((level - tempStn) * dcyTable[ic29.envDcy]) >> 16) + tempStn; + level = (((level - tempStn) * dcyTable[ic29.patchRam.decay]) >> 16) + tempStn; } else { level = tempStn; } break; case ENV_RLS: - level = (level * dcyTable[ic29.envRls]) >> 16; + level = (level * dcyTable[ic29.patchRam.release]) >> 16; break; case ENV_IDLE: default: @@ -184,7 +180,12 @@ void Voice::update() { // calculate the once-per-block values env.run(); calcPitch(); - pw = 0.5 - ic29.pwm; + if (ic29.patchRam.switch1 & 0x08) pw = ic29.pwm; + else pw = 0; + + saw = (float)((ic29.patchRam.switch1 & 0x10) == true); + sub = ic29.patchRam.subLevel / 128.0f; + // do filter values } diff --git a/plugin/ic29.hpp b/plugin/ic29.hpp index 569cd29..0a13888 100644 --- a/plugin/ic29.hpp +++ b/plugin/ic29.hpp @@ -29,7 +29,7 @@ class LFO { private: uint8_t - phase; + phase; uint16_t holdoff; uint16_t envelope; enum { LFO_RUN, @@ -79,10 +79,11 @@ class Voice { private: Envelope env; // calculated envelope value uint16_t pitch = 0x1818; // calculated pitch value with porta and master pitch etc - float delay; // delay slot for polyblep - bool pulseStage; - float pw, lastpw, pwrc; + float delay = 0; // delay slot for polyblep + bool pulseStage = 0; + float pw = 0, lastpw = 0, pwrc = 0; float subosc = -1; + float sub = 0, saw = 0; float phase = 0, omega = 0; enum { V_DONE, V_OFF, @@ -121,6 +122,26 @@ class Synth { float pwm; + struct { + uint8_t lfoRate = 0x3f; + uint8_t lfoDelay = 0x00; + uint8_t vcoLfoMod = 0x00; + uint8_t pwmLfoMod = 0x27; + uint8_t noiseLevel = 0x00; + uint8_t vcfCutoff = 0x4d; + uint8_t vcfReso = 0x14; + uint8_t vcfEnvMod = 0x04; + uint8_t vcfLfoMod = 0x00; + uint8_t vcfKeyTrk = 0x6f; + uint8_t vcaLevel = 0x22; + uint8_t attack = 0x0d; + uint8_t decay = 0x57; + uint8_t sustain = 0x58; + uint8_t release = 0x23; + uint8_t subLevel = 0x0e; + uint8_t switch1 = 0x1a; + uint8_t switch2 = 0x10; + } patchRam; }; // global diff --git a/plugin/oscillator.cpp b/plugin/oscillator.cpp index 6357c14..733ab3e 100644 --- a/plugin/oscillator.cpp +++ b/plugin/oscillator.cpp @@ -31,9 +31,9 @@ void Voice::run(float *buffer, uint32_t samples) { // generate a full block of samples for the oscillator float y, out, t; - float saw = 0; float gain = env.level / 16384.0; + if (subosc > 0) subosc = sub; else subosc = -sub; // this uses an adaptation of Mystran's Polyblep oscillator