This commit is contained in:
Gordon JC Pearce 2024-10-20 01:08:50 +01:00
parent 08712969c7
commit af2968c23f
8 changed files with 93 additions and 78 deletions

View File

@ -9,6 +9,7 @@
include dpf/Makefile.base.mk
CFLAGS += -ggdb
all: plugins gen
plugins:

View File

@ -21,8 +21,6 @@
#include "voiceboard.hpp"
#include "peacock.hpp"
Assigner ic1;
void Assigner::printMap() {
printf("note memory:\n");
for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", voicemap[i]);
@ -52,14 +50,14 @@ void Assigner::handleMidi(const MidiEvent *ev) {
case 0xb0:
switch (ev->data[1]) {
case 0x01:
ic29.modWheel = ev->data[2];
_ic29->modWheel = ev->data[2];
break;
default:
break;
}
break; // nothing to do here except in special cases where we don't expect the host to pass on controls
case 0xe0: // pitch bend;
ic29.pitchBend = ev->data[2] << 7 | ev->data[1];
_ic29->pitchBend = ev->data[2] << 7 | ev->data[1];
break;
default:
d_debug("unhandled MIDI event, status %02x value %02x\n", ev->data[0], ev->data[1]);
@ -75,7 +73,7 @@ void Assigner::noteOff(uint8_t note) {
memmove(keymap + i, keymap + i + 1, NUM_VOICES - i - 1);
voicemap[NUM_VOICES - 1] = voice;
keymap[NUM_VOICES - 1] = note | 0x80;
ic29.voiceOff(voice);
_ic29->voiceOff(voice);
}
}
}
@ -91,7 +89,7 @@ void Assigner::noteOn(uint8_t note) {
memmove(keymap + 1, keymap, i);
keymap[0] = note; // show note as on
voicemap[0] = voice;
ic29.voiceOn(voice, note);
_ic29->voiceOn(voice, note);
return;
}
}
@ -105,7 +103,7 @@ void Assigner::noteOn(uint8_t note) {
memmove(keymap + 1, keymap, i);
keymap[0] = note; // show note as on
voicemap[0] = voice;
ic29.voiceOn(voice, note);
_ic29->voiceOn(voice, note);
return;
}
}

View File

@ -18,20 +18,27 @@
#pragma once
#include "peacock.hpp"
#include "DistrhoPlugin.hpp"
#define NUM_VOICES 8
#include "voiceboard.hpp"
class Assigner {
public:
Assigner();
void setVoiceBoard(Synth& s) {
_ic29 = &s;
}
void handleMidi(const MidiEvent *ev);
private:
void noteOn(uint8_t note);
void noteOff(uint8_t note);
void printMap();
Synth* _ic29;
uint8_t keymap[NUM_VOICES];
uint8_t voicemap[NUM_VOICES];
};
extern Assigner ic1;

View File

@ -68,7 +68,7 @@ void Voice::run(float *buffer, uint32_t pos, uint32_t samples) {
// the DC correction is important because the hardware synth is AC-coupled effectively high-passing
// the signal at about 10Hz or so, preventing any PWM rumble from leaking through!
delay += subosc;
delay += ic29.noise[i+pos];
//delay += ic29.noise[i+pos];
lastpw = pwrc;
buffer[i + pos] = y * 0.707;

View File

@ -25,6 +25,7 @@ START_NAMESPACE_DISTRHO
Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) {
printf("peacock constructor\n");
ic1.setVoiceBoard(ic29);
ic29.buildTables(getSampleRate());
ic29.bufferSize = getBufferSize();
}
@ -84,10 +85,10 @@ void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEv
// run every synth voice into the buffer here FIXME
for (uint8_t i = 0; i < NUM_VOICES; i++) {
ic29.voices[i].run(outputs[0], framePos, sizeThisTime);
ic29.voices[i].filter(outputs[0], framePos, sizeThisTime);
//ic29->voices[i].run(outputs[0], framePos, sizeThisTime);
//ic29->voices[i].filter(outputs[0], framePos, sizeThisTime);
for (uint8_t j=0; j<sizeThisTime; j++) {
outputs[1][framePos+j] += outputs[0][framePos+j] * ic29.voices[i].env.level/16384.0;
// outputs[1][framePos+j] += outputs[0][framePos+j] * ic29->voices[i].env.level/16384.0;
}
}

View File

@ -23,6 +23,9 @@
#include "DistrhoPlugin.hpp"
#include "assigner.hpp"
#include "voiceboard.hpp"
START_NAMESPACE_DISTRHO
class Peacock : public Plugin {
@ -87,6 +90,9 @@ class Peacock : public Plugin {
uint32_t blockLeft = 0;
uint32_t lastEvent = 0;
Assigner ic1;
Synth ic29;
void runMidi(const MidiEvent *ev, uint32_t count, uint32_t timeLimit);
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Peacock);

View File

@ -18,14 +18,15 @@
#include "voiceboard.hpp"
#include <math.h>
#include "DistrhoPlugin.hpp"
#include "ic29tables.hpp"
Synth ic29;
#define DEBUG
Synth::Synth() {
d_debug("initialising synth\n");
portaCoeff = 0x0;
noise = new float [4096];
printf("Synth constructor\n");
}
void Synth::buildTables(double sampleRate) {
@ -40,9 +41,7 @@ void Synth::buildTables(double sampleRate) {
// the ROM preset for adjusting the VCF scale and centre presets cutoff to $31
// and key scale to $7f, which corresponds to C4 = 248Hz and C6 = 992Hz, B3 and B5
for (uint16_t i = 0; i< 256; i++) {
for (uint16_t i = 0; i < 256; i++) {
}
}
@ -50,10 +49,10 @@ void Synth::run() {
// handle a "loop" worth of envelopes, pitch calculations, etc
// callled once every 4.3ms block of samples
ic29.lfo.run();
lfo.run();
masterPitch = 0x1818;
uint16_t vcoLfoDepth = ic29.lfoDepthTable[ic29.patchRam.vcoLfoMod] + ic29.modWheel;
uint16_t vcoLfoDepth = lfoDepthTable[patchRam.vcoLfoMod] + modWheel;
vcoLfoDepth = (vcoLfoDepth < 0xff) ? vcoLfoDepth : 0xff;
masterPitch += (lfo.lfoOut * vcoLfoDepth) >> 11;
@ -65,31 +64,34 @@ 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 (ic29.patchRam.switch2 & 0x01) pwmVal = 0x3fff;
ic29.pwm = 0.5 - pwmVal / 32768.0f * (ic29.patchRam.pwmLfoMod / 106.0f);
uint16_t pwmVal = 0x2000 - lfo.lfoOut;
if (patchRam.switch2 & 0x01) pwmVal = 0x3fff;
pwm = 0.5 - pwmVal / 32768.0f * (patchRam.pwmLfoMod / 106.0f);
// generate the voices, then
for (uint32_t i=0; i<bufferSize; i++) {
tr21 = (tr21*519) + 3;
noise[i] = (1-(tr21 & 0x00ffffff) / 8388608.0f) * (ic29.patchRam.noiseLevel * 0.0063);
for (uint32_t i = 0; i < bufferSize; i++) {
tr21 = (tr21 * 519) + 3;
noise[i] = (1 - (tr21 & 0x00ffffff) / 8388608.0f) * (patchRam.noiseLevel * 0.0063);
}
for (uint8_t i = 0; i < NUM_VOICES; i++) {
ic29.voices[i].update();
//voices[i].update();
}
}
void Synth::voiceOn(uint8_t voice, uint8_t note) {
// enable synth voice, start it all running
voice &= 0x7f;
ic29.voices[voice].on(note);
d_debug("voiceOn %02x %02x", voice, note);
voices[voice].on(note);
}
void Synth::voiceOff(uint8_t voice) {
// enable synth voice, start it all running
voice &= 0x7f;
ic29.voices[voice].off();
voices[voice].off();
}
LFO::LFO() {
@ -126,7 +128,8 @@ Envelope::Envelope() {
}
void Envelope::run() {
uint16_t tempStn = ic29.patchRam.sustain << 7;
/*
uint16_t tempStn = patchRam.sustain << 7;
switch (phase) {
case ENV_ATK:
level += atkTable[ic29.patchRam.attack];
@ -148,7 +151,7 @@ void Envelope::run() {
case ENV_IDLE:
default:
break;
}
}*/
}
Voice::Voice() {
@ -164,7 +167,7 @@ void Voice::calcPitch() {
// This is implemented here by adding on a step value until you pass
// the desired final pitch. Once that happens the value is clamped to the
// desired pitch.
/*
if (ic29.portaCoeff != 0) {
// portamento up
if (pitch < target) {
@ -193,9 +196,9 @@ void Voice::calcPitch() {
double frac = (pitch & 0xff) / 256.0f;
omega = ((o2 - o1) * frac) + o1;
}
}
void Voice::update() {
void Voice::update() {
// calculate the once-per-block values
env.run();
calcPitch();
@ -207,9 +210,11 @@ void Voice::update() {
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;
if (note != key) {
phase = 0;
@ -221,9 +226,8 @@ void Voice::on(uint8_t key) {
}
void Voice::off() {
d_debug("Voice off\n");
// sustain - I need to rethink this bit FIXME
voiceState = V_OFF;
if (!ic29.sustained) {
env.off();
}
}

View File

@ -18,8 +18,9 @@
#pragma once
#include "peacock.hpp"
#include <cstdint>
#define NUM_VOICES 8
class LFO {
public:
LFO();
@ -157,6 +158,3 @@ class Synth {
const static uint8_t lfoDepthTable[128];
const static uint8_t portaTable[128];
};
// global
extern Synth ic29;