global synth, envelope might even work

This commit is contained in:
Gordon JC Pearce 2024-10-12 00:15:00 +01:00
parent 454051d10c
commit cbae975760
3 changed files with 92 additions and 8 deletions

View File

@ -20,6 +20,53 @@
#include "peacock.hpp"
Synth::Synth() {
}
void Synth::run() {
printf("called synth::run()\n");
printf("%d\n", voices[0].env.phase);
}
void Synth::voiceOn(uint8_t voice, uint8_t note) {
// enable synth voice, start it all running
}
Envelope::Envelope() {
level = 0;
phase = ENV_IDLE;
printf("initialising envelope\n");
}
void Envelope::run() {
switch (phase) {
case ENV_ATK:
level += s.envAtk;
if (level > 0x3fff) {
level = 0x3fff;
phase = ENV_DCY;
}
break;
case ENV_DCY:
if (level > s.envStn) {
level -= s.envStn;
level *= s.envDcy;
level += s.envStn;
} else {
level = s.envStn;
}
break;
case ENV_RLS:
level *= s.envRls;
break;
case ENV_IDLE:
default:
break;
}
}
void Envelope::gate(uint8_t gate) {
}
Voice::Voice() {
}

View File

@ -20,23 +20,57 @@
#include "peacock.hpp"
class Synth {
class Envelope {
public:
Synth();
void voiceOn(uint8_t voice, uint8_t note);
void voiceOff(uint8_t voice);
void sustainSwitch(uint8_t val);
void pitchBend(int16_t bend);
void modWheel(uint8_t wheel);
uint16_t masterPitch; // sum of bend and LFO, plus any other pitch-setting value
private:
Envelope();
void run();
void gate(uint8_t gate);
uint16_t level;
//private:
enum {
ENV_ATK,
ENV_DCY,
ENV_RLS,
ENV_IDLE
} phase;
};
class Voice {
public:
Voice();
void run();
private:
uint8_t note;
//private:
Envelope env; // calculated envelope value
uint16_t pitch; // calculated pitch value with porta and master pitch etc
enum { V_DONE,
V_OFF,
V_ON } voiceState;
};
class Synth {
friend Envelope;
friend Peacock;
public:
Synth();
void run();
void voiceOn(uint8_t voice, uint8_t note);
void voiceOff(uint8_t voice);
void sustainSwitch(uint8_t val);
void pitchBend(int16_t bend);
void modWheel(uint8_t wheel);
uint16_t masterPitch; // sum of bend and LFO, plus any other pitch-setting value
protected:
uint16_t envAtk, envDcy, envStn, envRls;
private:
Voice voices[NUM_VOICES];
void runLfo();
void runEnvelope(Voice voice);
};
// global
extern Synth s;

View File

@ -18,12 +18,15 @@
#include "peacock.hpp"
#include "ic1.hpp"
#include "ic29.hpp"
START_NAMESPACE_DISTRHO
Assigner ic1;
Synth s;
Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) {
s.run();
}
void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount) {