diff --git a/plugin/assigner.cpp b/plugin/assigner.cpp index 264bc72..28d2b98 100644 --- a/plugin/assigner.cpp +++ b/plugin/assigner.cpp @@ -22,6 +22,7 @@ #include "peacock.hpp" void Assigner::printMap() { + return; printf("note memory:\n"); for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", voicemap[i]); printf("\n"); @@ -33,7 +34,7 @@ Assigner::Assigner() { // set up the assigner for (uint8_t i = 0; i < NUM_VOICES; i++) { voicemap[i] = 0x80 + i; - keymap[i] = 0x3c | 0x80; + keymap[i] = 0xff; } } @@ -74,6 +75,7 @@ void Assigner::noteOff(uint8_t note) { voicemap[NUM_VOICES - 1] = voice; keymap[NUM_VOICES - 1] = note | 0x80; _ic29->voiceOff(voice); + printMap(); } } } @@ -90,6 +92,7 @@ void Assigner::noteOn(uint8_t note) { keymap[0] = note; // show note as on voicemap[0] = voice; _ic29->voiceOn(voice, note); + printMap(); return; } } @@ -104,6 +107,7 @@ void Assigner::noteOn(uint8_t note) { keymap[0] = note; // show note as on voicemap[0] = voice; _ic29->voiceOn(voice, note); + printMap(); return; } } diff --git a/plugin/voiceboard.cpp b/plugin/voiceboard.cpp index 205a55b..3b351ad 100644 --- a/plugin/voiceboard.cpp +++ b/plugin/voiceboard.cpp @@ -26,7 +26,6 @@ #define DEBUG Synth::Synth() { - printf("Synth constructor\n"); } void Synth::buildTables(double sampleRate) { @@ -71,11 +70,13 @@ void Synth::run() { // generate the voices, then for (uint32_t i = 0; i < bufferSize; i++) { tr21 = (tr21 * 519) + 3; - noise[i] = (1 - (tr21 & 0x00ffffff) / 8388608.0f) * (patchRam.noiseLevel * 0.0063); + // noise[i] = (1 - (tr21 & 0x00ffffff) / 8388608.0f) * (patchRam.noiseLevel * 0.0063); } + //printf("updating\n"); + for (uint8_t i = 0; i < NUM_VOICES; i++) { - //voices[i].update(); + voices[i].update(); } } @@ -83,7 +84,7 @@ void Synth::voiceOn(uint8_t voice, uint8_t note) { // enable synth voice, start it all running voice &= 0x7f; - d_debug("voiceOn %02x %02x", voice, note); + d_debug("voiceOn %02x %02x", voice, note); voices[voice].on(note); } @@ -122,40 +123,43 @@ void LFO::run() { // printf("lfoOut=%04x\n", lfoOut); } +uint16_t Envelope::atk = 0x10; +uint16_t Envelope::dcy = 0x3f; +uint16_t Envelope::stn = 0x3f; +uint16_t Envelope::rls = 0x1f; + Envelope::Envelope() { level = 0; phase = ENV_RLS; } void Envelope::run() { - /* - uint16_t tempStn = patchRam.sustain << 7; + uint16_t temp = stn << 7; switch (phase) { case ENV_ATK: - level += atkTable[ic29.patchRam.attack]; + level += atkTable[atk]; if (level > 0x3fff) { level = 0x3fff; phase = ENV_DCY; } break; case ENV_DCY: - if (level > tempStn) { - level = (((level - tempStn) * dcyTable[ic29.patchRam.decay]) >> 16) + tempStn; + if (level > temp) { + level = (((level - temp) * dcyTable[dcy]) >> 16) + temp; } else { - level = tempStn; + level = temp; } break; case ENV_RLS: - level = (level * dcyTable[ic29.patchRam.release]) >> 16; + level = (level * dcyTable[rls]) >> 16; break; case ENV_IDLE: default: break; - }*/ + } } Voice::Voice() { - subosc = .1; } void Voice::calcPitch() { @@ -196,23 +200,24 @@ void Voice::calcPitch() { double frac = (pitch & 0xff) / 256.0f; omega = ((o2 - o1) * frac) + o1; - } - - void Voice::update() { - // calculate the once-per-block values - env.run(); - calcPitch(); - - pw = (ic29.patchRam.switch1 & 0x08) ? ic29.pwm : 0.0f; - saw = (ic29.patchRam.switch1 & 0x10) ? 1.0f : 0.0f; - sub = ic29.patchRam.subLevel / 128.0f; - - ic29.lfo.rate = ic29.patchRam.lfoRate; - - // do filter values */ } +void Voice::update() { + // calculate the once-per-block values + env.run(); + calcPitch(); + //printf("env=%04x\n", env.level); + /* + pw = (patchRam.switch1 & 0x08) ? ic29.pwm : 0.0f; + saw = (ic29.patchRam.switch1 & 0x10) ? 1.0f : 0.0f; + sub = ic29.patchRam.subLevel / 128.0f; + + ic29.lfo.rate = ic29.patchRam.lfoRate; + */ + // do filter values +} + void Voice::on(uint8_t key) { d_debug("Voice on key %02x\n", key); voiceState = V_ON; @@ -220,7 +225,7 @@ void Voice::on(uint8_t key) { phase = 0; } note = key; - if (env.phase == env.ENV_RLS) { + if (env.inRelease()) { env.on(); // FIXME move to synth update code } } diff --git a/plugin/voiceboard.hpp b/plugin/voiceboard.hpp index e0fa4f5..a0b3328 100644 --- a/plugin/voiceboard.hpp +++ b/plugin/voiceboard.hpp @@ -42,6 +42,7 @@ class LFO { class Envelope { public: Envelope(); + void run(); void on() { phase = ENV_ATK; @@ -55,18 +56,20 @@ class Envelope { return phase == ENV_RLS; } + static uint16_t atk, dcy, stn, rls; + uint16_t level; + private: + static const uint16_t atkTable[128]; + static const uint16_t dcyTable[128]; + enum { ENV_ATK, ENV_DCY, ENV_RLS, ENV_IDLE } phase; - - private: - static const uint16_t atkTable[128]; - static const uint16_t dcyTable[128]; }; class Voice { @@ -80,7 +83,7 @@ class Voice { void on(uint8_t note); void off(); - // private: + // private: Envelope env; // calculated envelope value uint16_t pitch = 0x1818; // calculated pitch value with porta and master pitch etc float delay = 0; // delay slot for polyblep @@ -95,7 +98,7 @@ class Voice { void calcPitch(); - float fb=0, b1=0, b2=0, b3=0, b4=0, cut=0.1, reso=4; + float fb = 0, b1 = 0, b2 = 0, b3 = 0, b4 = 0, cut = 0.1, reso = 4; }; class Synth { @@ -123,8 +126,8 @@ class Synth { float *noise; // private: - uint8_t vcoBend=42; - uint8_t vcfBend=42; + uint8_t vcoBend = 42; + uint8_t vcfBend = 42; Voice voices[NUM_VOICES]; LFO lfo;