envelopes work again

This commit is contained in:
Gordon JC Pearce 2024-10-20 22:12:22 +01:00
parent af2968c23f
commit 1c3c6adf3c
3 changed files with 49 additions and 37 deletions

View File

@ -22,6 +22,7 @@
#include "peacock.hpp" #include "peacock.hpp"
void Assigner::printMap() { void Assigner::printMap() {
return;
printf("note memory:\n"); printf("note memory:\n");
for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", voicemap[i]); for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", voicemap[i]);
printf("\n"); printf("\n");
@ -33,7 +34,7 @@ Assigner::Assigner() {
// set up the assigner // set up the assigner
for (uint8_t i = 0; i < NUM_VOICES; i++) { for (uint8_t i = 0; i < NUM_VOICES; i++) {
voicemap[i] = 0x80 + 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; voicemap[NUM_VOICES - 1] = voice;
keymap[NUM_VOICES - 1] = note | 0x80; keymap[NUM_VOICES - 1] = note | 0x80;
_ic29->voiceOff(voice); _ic29->voiceOff(voice);
printMap();
} }
} }
} }
@ -90,6 +92,7 @@ void Assigner::noteOn(uint8_t note) {
keymap[0] = note; // show note as on keymap[0] = note; // show note as on
voicemap[0] = voice; voicemap[0] = voice;
_ic29->voiceOn(voice, note); _ic29->voiceOn(voice, note);
printMap();
return; return;
} }
} }
@ -104,6 +107,7 @@ void Assigner::noteOn(uint8_t note) {
keymap[0] = note; // show note as on keymap[0] = note; // show note as on
voicemap[0] = voice; voicemap[0] = voice;
_ic29->voiceOn(voice, note); _ic29->voiceOn(voice, note);
printMap();
return; return;
} }
} }

View File

@ -26,7 +26,6 @@
#define DEBUG #define DEBUG
Synth::Synth() { Synth::Synth() {
printf("Synth constructor\n");
} }
void Synth::buildTables(double sampleRate) { void Synth::buildTables(double sampleRate) {
@ -71,11 +70,13 @@ void Synth::run() {
// generate the voices, then // generate the voices, then
for (uint32_t i = 0; i < bufferSize; i++) { for (uint32_t i = 0; i < bufferSize; i++) {
tr21 = (tr21 * 519) + 3; 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++) { 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 // enable synth voice, start it all running
voice &= 0x7f; voice &= 0x7f;
d_debug("voiceOn %02x %02x", voice, note); d_debug("voiceOn %02x %02x", voice, note);
voices[voice].on(note); voices[voice].on(note);
} }
@ -122,40 +123,43 @@ void LFO::run() {
// printf("lfoOut=%04x\n", lfoOut); // 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() { Envelope::Envelope() {
level = 0; level = 0;
phase = ENV_RLS; phase = ENV_RLS;
} }
void Envelope::run() { void Envelope::run() {
/* uint16_t temp = stn << 7;
uint16_t tempStn = patchRam.sustain << 7;
switch (phase) { switch (phase) {
case ENV_ATK: case ENV_ATK:
level += atkTable[ic29.patchRam.attack]; level += atkTable[atk];
if (level > 0x3fff) { if (level > 0x3fff) {
level = 0x3fff; level = 0x3fff;
phase = ENV_DCY; phase = ENV_DCY;
} }
break; break;
case ENV_DCY: case ENV_DCY:
if (level > tempStn) { if (level > temp) {
level = (((level - tempStn) * dcyTable[ic29.patchRam.decay]) >> 16) + tempStn; level = (((level - temp) * dcyTable[dcy]) >> 16) + temp;
} else { } else {
level = tempStn; level = temp;
} }
break; break;
case ENV_RLS: case ENV_RLS:
level = (level * dcyTable[ic29.patchRam.release]) >> 16; level = (level * dcyTable[rls]) >> 16;
break; break;
case ENV_IDLE: case ENV_IDLE:
default: default:
break; break;
}*/ }
} }
Voice::Voice() { Voice::Voice() {
subosc = .1;
} }
void Voice::calcPitch() { void Voice::calcPitch() {
@ -196,23 +200,24 @@ void Voice::calcPitch() {
double frac = (pitch & 0xff) / 256.0f; double frac = (pitch & 0xff) / 256.0f;
omega = ((o2 - o1) * frac) + o1; 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) { void Voice::on(uint8_t key) {
d_debug("Voice on key %02x\n", key); d_debug("Voice on key %02x\n", key);
voiceState = V_ON; voiceState = V_ON;
@ -220,7 +225,7 @@ void Voice::on(uint8_t key) {
phase = 0; phase = 0;
} }
note = key; note = key;
if (env.phase == env.ENV_RLS) { if (env.inRelease()) {
env.on(); // FIXME move to synth update code env.on(); // FIXME move to synth update code
} }
} }

View File

@ -42,6 +42,7 @@ class LFO {
class Envelope { class Envelope {
public: public:
Envelope(); Envelope();
void run(); void run();
void on() { void on() {
phase = ENV_ATK; phase = ENV_ATK;
@ -55,18 +56,20 @@ class Envelope {
return phase == ENV_RLS; return phase == ENV_RLS;
} }
static uint16_t atk, dcy, stn, rls;
uint16_t level; uint16_t level;
private:
static const uint16_t atkTable[128];
static const uint16_t dcyTable[128];
enum { enum {
ENV_ATK, ENV_ATK,
ENV_DCY, ENV_DCY,
ENV_RLS, ENV_RLS,
ENV_IDLE ENV_IDLE
} phase; } phase;
private:
static const uint16_t atkTable[128];
static const uint16_t dcyTable[128];
}; };
class Voice { class Voice {
@ -80,7 +83,7 @@ class Voice {
void on(uint8_t note); void on(uint8_t note);
void off(); void off();
// private: // private:
Envelope env; // calculated envelope value Envelope env; // calculated envelope value
uint16_t pitch = 0x1818; // calculated pitch value with porta and master pitch etc uint16_t pitch = 0x1818; // calculated pitch value with porta and master pitch etc
float delay = 0; // delay slot for polyblep float delay = 0; // delay slot for polyblep
@ -95,7 +98,7 @@ class Voice {
void calcPitch(); 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 { class Synth {
@ -123,8 +126,8 @@ class Synth {
float *noise; float *noise;
// private: // private:
uint8_t vcoBend=42; uint8_t vcoBend = 42;
uint8_t vcfBend=42; uint8_t vcfBend = 42;
Voice voices[NUM_VOICES]; Voice voices[NUM_VOICES];
LFO lfo; LFO lfo;