2024-10-09 21:43:52 +00:00
|
|
|
/*
|
|
|
|
Peacock-8 VA polysynth
|
|
|
|
|
|
|
|
Copyright 2024 Gordon JC Pearce <gordonjcp@gjcp.net>
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ic29.hpp"
|
|
|
|
|
2024-10-12 22:36:34 +00:00
|
|
|
|
|
|
|
Synth s;
|
|
|
|
|
2024-10-09 21:43:52 +00:00
|
|
|
|
2024-10-11 23:15:00 +00:00
|
|
|
Synth::Synth() {
|
2024-10-12 22:36:34 +00:00
|
|
|
printf("initialising synth\n");
|
|
|
|
envAtk = 0x007f;
|
|
|
|
envDcy = envRls = 0xfe90;
|
|
|
|
envStn = 0x1fff;
|
2024-10-11 23:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Synth::run() {
|
2024-10-12 22:36:34 +00:00
|
|
|
//printf("called synth::run()\n");
|
|
|
|
//printf("%d\n", voices[0].env.phase);
|
|
|
|
for (uint8_t i=0; i<NUM_VOICES; i++) {
|
|
|
|
s.voices[i].env.run();
|
|
|
|
|
|
|
|
}
|
2024-10-11 23:15:00 +00:00
|
|
|
}
|
|
|
|
|
2024-10-09 21:51:37 +00:00
|
|
|
void Synth::voiceOn(uint8_t voice, uint8_t note) {
|
|
|
|
// enable synth voice, start it all running
|
2024-10-12 22:36:34 +00:00
|
|
|
voice &= 0x7f;
|
|
|
|
s.voices[voice].env.on();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Synth::voiceOff(uint8_t voice) {
|
|
|
|
// enable synth voice, start it all running
|
|
|
|
voice &= 0x7f;
|
|
|
|
s.voices[voice].env.off();
|
2024-10-09 21:51:37 +00:00
|
|
|
}
|
2024-10-11 23:15:00 +00:00
|
|
|
|
|
|
|
Envelope::Envelope() {
|
|
|
|
level = 0;
|
|
|
|
phase = ENV_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2024-10-12 22:36:34 +00:00
|
|
|
level = (level * s.envDcy) >> 16;
|
2024-10-11 23:15:00 +00:00
|
|
|
level += s.envStn;
|
|
|
|
} else {
|
|
|
|
level = s.envStn;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ENV_RLS:
|
2024-10-12 22:36:34 +00:00
|
|
|
level = (level * s.envRls) >> 16;
|
2024-10-11 23:15:00 +00:00
|
|
|
break;
|
|
|
|
case ENV_IDLE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Voice::Voice() {
|
|
|
|
}
|
2024-10-12 22:36:34 +00:00
|
|
|
|
|
|
|
extern Synth s;
|