working modwheel and pitchbend

This commit is contained in:
Gordon JC Pearce 2024-10-18 23:57:14 +01:00
parent 3cfe118acc
commit 5d80fe5870
6 changed files with 65 additions and 51 deletions

View File

@ -16,8 +16,8 @@
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "peacock.hpp"
#include "ic29.hpp" #include "ic29.hpp"
#include "peacock.hpp"
void Peacock::initParameter(uint32_t index, Parameter& parameter) { void Peacock::initParameter(uint32_t index, Parameter& parameter) {
switch (index) { switch (index) {
@ -291,23 +291,21 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
parameter.midiCC = 26; parameter.midiCC = 26;
break; break;
case p_modWheel: case p_vcoBend:
parameter.hints = kParameterIsAutomatable | kParameterIsHidden; parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "Mod wheel"; parameter.name = "VCO Bend";
parameter.symbol = "pfau_modwheel"; parameter.symbol = "pfau_vcobend";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f; parameter.ranges.def = 43.0f;
parameter.midiCC = 1;
break; break;
case p_holdPedal: case p_vcfBend:
parameter.hints = kParameterIsAutomatable | kParameterIsHidden; parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "Hold Pedal"; parameter.name = "VCF Bend";
parameter.symbol = "pfau_holdpedal"; parameter.symbol = "pfau_vcfbend";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 0.0f; parameter.ranges.def = 43.0f;
parameter.midiCC = 64;
break; break;
} }
// chorus, porta, bend range, key mode still to do // chorus, porta, bend range, key mode still to do
@ -318,7 +316,6 @@ void Peacock::setParameterValue(uint32_t index, float value) {
if (value < 0.0f) value = 0.0f; if (value < 0.0f) value = 0.0f;
if (value > 127.0f) value = 127.0f; if (value > 127.0f) value = 127.0f;
switch (index) { switch (index) {
case p_lfoRate: case p_lfoRate:
ic29.patchRam.lfoRate = value; ic29.patchRam.lfoRate = value;
@ -375,7 +372,7 @@ void Peacock::setParameterValue(uint32_t index, float value) {
case p_vcoRange: // bits 0-2 of switch 1 case p_vcoRange: // bits 0-2 of switch 1
// doesn't look great in Carla because of odd behaviour with small integer knobs // doesn't look great in Carla because of odd behaviour with small integer knobs
ic29.patchRam.switch1 &= 0xf8; ic29.patchRam.switch1 &= 0xf8;
ic29.patchRam.switch1 |= (1 << (int)(value - 1)); ic29.patchRam.switch1 |= (1 << (uint8_t)(value - 1));
break; break;
case p_sqrOn: // bit 3 of switch 1 case p_sqrOn: // bit 3 of switch 1
ic29.patchRam.switch1 &= 0xf7; ic29.patchRam.switch1 &= 0xf7;
@ -408,11 +405,10 @@ void Peacock::setParameterValue(uint32_t index, float value) {
// doesn't look great in Carla because of odd behaviour with small integer knobs // doesn't look great in Carla because of odd behaviour with small integer knobs
if (value > 3) value = 3; if (value > 3) value = 3;
ic29.patchRam.switch2 &= 0xf3; ic29.patchRam.switch2 &= 0xf3;
ic29.patchRam.switch2 |= (int)value << 3; ic29.patchRam.switch2 |= (uint8_t)value << 3;
break; break;
case p_vcoBend:
case p_modWheel: ic29.vcoBend = (uint8_t)value;
//s.ff64 = (int)value << 1;
break; break;
} }
} }

View File

@ -50,7 +50,17 @@ void Assigner::handleMidi(const MidiEvent *ev) {
noteOn(ev->data[1]); noteOn(ev->data[1]);
break; break;
case 0xb0: case 0xb0:
switch (ev->data[1]) {
case 0x01:
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 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];
break;
default: default:
d_debug("unhandled MIDI event, status %02x value %02x\n", ev->data[0], ev->data[1]); d_debug("unhandled MIDI event, status %02x value %02x\n", ev->data[0], ev->data[1]);
break; break;

View File

@ -43,9 +43,14 @@ void Synth::run() {
ic29.lfo.run(); ic29.lfo.run();
masterPitch = 0x1818; masterPitch = 0x1818;
uint16_t vcoLfoDepth = ic29.lfoDepthTable[ic29.patchRam.vcoLfoMod] + ic29.modWheel;
vcoLfoDepth = (vcoLfoDepth < 0xff) ? vcoLfoDepth : 0xff;
masterPitch += (lfo.lfoOut * vcoLfoDepth) >> 11;
if (pitchBend < 0x0100) pitchBend = 0x0100;
masterPitch += (((pitchBend >> 8) - 0x20) * vcoBend) / 1.281;
// need to calculate VCF "base" setting // need to calculate VCF "base" setting
// need to calculate PWM
// various on/off switches // various on/off switches
// PWM is bit 0 sw2, 0 = fixed 1 = lfo // PWM is bit 0 sw2, 0 = fixed 1 = lfo
@ -179,7 +184,7 @@ void Voice::update() {
// calculate the once-per-block values // calculate the once-per-block values
env.run(); env.run();
calcPitch(); calcPitch();
pw = (ic29.patchRam.switch1 & 0x08) ? ic29.pwm : 0.0f; pw = (ic29.patchRam.switch1 & 0x08) ? ic29.pwm : 0.0f;
saw = (ic29.patchRam.switch1 & 0x10) ? 1.0f : 0.0f; saw = (ic29.patchRam.switch1 & 0x10) ? 1.0f : 0.0f;
sub = ic29.patchRam.subLevel / 128.0f; sub = ic29.patchRam.subLevel / 128.0f;
@ -198,7 +203,6 @@ void Voice::on(uint8_t key) {
if (env.phase == env.ENV_RLS) { if (env.phase == env.ENV_RLS) {
env.on(); // FIXME move to synth update code env.on(); // FIXME move to synth update code
} }
} }
void Voice::off() { void Voice::off() {

View File

@ -63,7 +63,7 @@ class Envelope {
ENV_IDLE ENV_IDLE
} phase; } phase;
private: private:
static const uint16_t atkTable[128]; static const uint16_t atkTable[128];
static const uint16_t dcyTable[128]; static const uint16_t dcyTable[128];
}; };
@ -103,8 +103,6 @@ class Synth {
void voiceOn(uint8_t voice, uint8_t note); void voiceOn(uint8_t voice, uint8_t note);
void voiceOff(uint8_t voice); void voiceOff(uint8_t voice);
void sustainSwitch(uint8_t val); void sustainSwitch(uint8_t val);
void pitchBend(int16_t bend);
void modWheel(uint8_t wheel);
void buildTables(double sampleRate); void buildTables(double sampleRate);
double sampleRate; double sampleRate;
@ -116,10 +114,13 @@ class Synth {
double pitchTable[104]; double pitchTable[104];
// private: // private:
int16_t lfoPitch; uint8_t vcoBend=42;
int16_t bendPitch; uint8_t vcfBend=42;
Voice voices[NUM_VOICES]; Voice voices[NUM_VOICES];
LFO lfo; LFO lfo;
uint16_t pitchBend = 0x2000;
uint8_t modWheel = 0x00;
float pwm; float pwm;
@ -143,6 +144,9 @@ class Synth {
uint8_t switch1 = 0x1a; uint8_t switch1 = 0x1a;
uint8_t switch2 = 0x10; uint8_t switch2 = 0x10;
} patchRam; } patchRam;
const static uint16_t lfoDelayTable[8];
const static uint8_t lfoDepthTable[128];
const static uint8_t portaTable[128];
}; };
// global // global

View File

@ -54,7 +54,7 @@ const uint16_t Envelope::dcyTable[128] = {
0xffd8, 0xffdc, 0xffe0, 0xffe4, 0xffe8, 0xffec, 0xfff0, 0xfff1, 0xfff2, 0xffd8, 0xffdc, 0xffe0, 0xffe4, 0xffe8, 0xffec, 0xfff0, 0xfff1, 0xfff2,
0xfff3, 0xfff4}; 0xfff3, 0xfff4};
extern const uint8_t lfoDepthTable[128] = { const uint8_t Synth::lfoDepthTable[128] = {
0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
@ -67,6 +67,27 @@ extern const uint8_t lfoDepthTable[128] = {
0xb0, 0xb4, 0xb8, 0xbc, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4, 0xd8, 0xdc, 0xb0, 0xb4, 0xb8, 0xbc, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4, 0xd8, 0xdc,
0xe0, 0xe4, 0xe8, 0xec, 0xf0, 0xf8, 0xff, 0xff}; 0xe0, 0xe4, 0xe8, 0xec, 0xf0, 0xf8, 0xff, 0xff};
const uint16_t Synth::lfoDelayTable[8] = {
0xffff, 0x0419, 0x020c, 0x015e, 0x0100, 0x0100, 0x0100, 0x0100};
const uint8_t Synth::portaTable[128] = {
0x00, 0xff, 0xf7, 0xef, 0xe7, 0xdf, 0xd7, 0xcf,
0xc7, 0xbf, 0xb7, 0xaf, 0xa7, 0x9f, 0x97, 0x8f,
0x87, 0x7f, 0x77, 0x6f, 0x67, 0x5f, 0x57, 0x4f,
0x47, 0x3f, 0x3d, 0x3b, 0x39, 0x37, 0x35, 0x33,
0x31, 0x2f, 0x2d, 0x2b, 0x29, 0x27, 0x25, 0x23,
0x21, 0x1f, 0x1d, 0x1b, 0x19, 0x17, 0x15, 0x13,
0x12, 0x11, 0x10, 0x10, 0x10, 0x10, 0x0f, 0x0f,
0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d,
0x0d, 0x0d, 0x0d, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a,
0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x08,
0x08, 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07,
0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x05,
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04,
0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02,
0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
const uint16_t LFO::lfoRateTable[128] = { const uint16_t LFO::lfoRateTable[128] = {
0x0005, 0x000f, 0x0019, 0x0028, 0x0037, 0x0046, 0x0050, 0x005a, 0x0064, 0x0005, 0x000f, 0x0019, 0x0028, 0x0037, 0x0046, 0x0050, 0x005a, 0x0064,
0x006e, 0x0078, 0x0082, 0x008c, 0x0096, 0x00a0, 0x00aa, 0x00b4, 0x00be, 0x006e, 0x0078, 0x0082, 0x008c, 0x0096, 0x00a0, 0x00aa, 0x00b4, 0x00be,
@ -83,24 +104,3 @@ const uint16_t LFO::lfoRateTable[128] = {
0x07a8, 0x07f8, 0x085c, 0x08c0, 0x0924, 0x0988, 0x09ec, 0x0a50, 0x0ab4, 0x07a8, 0x07f8, 0x085c, 0x08c0, 0x0924, 0x0988, 0x09ec, 0x0a50, 0x0ab4,
0x0b18, 0x0b7c, 0x0be0, 0x0c58, 0x0cd0, 0x0d48, 0x0dde, 0x0e74, 0x0f0a, 0x0b18, 0x0b7c, 0x0be0, 0x0c58, 0x0cd0, 0x0d48, 0x0dde, 0x0e74, 0x0f0a,
0x0fa0, 0x1000}; 0x0fa0, 0x1000};
extern const uint16_t lfoDelayTable[8] = {
0xffff, 0x0419, 0x020c, 0x015e, 0x0100, 0x0100, 0x0100, 0x0100};
extern const uint8_t portaTable[128] = {
0x00, 0xff, 0xf7, 0xef, 0xe7, 0xdf, 0xd7, 0xcf,
0xc7, 0xbf, 0xb7, 0xaf, 0xa7, 0x9f, 0x97, 0x8f,
0x87, 0x7f, 0x77, 0x6f, 0x67, 0x5f, 0x57, 0x4f,
0x47, 0x3f, 0x3d, 0x3b, 0x39, 0x37, 0x35, 0x33,
0x31, 0x2f, 0x2d, 0x2b, 0x29, 0x27, 0x25, 0x23,
0x21, 0x1f, 0x1d, 0x1b, 0x19, 0x17, 0x15, 0x13,
0x12, 0x11, 0x10, 0x10, 0x10, 0x10, 0x0f, 0x0f,
0x0f, 0x0f, 0x0e, 0x0e, 0x0e, 0x0e, 0x0d, 0x0d,
0x0d, 0x0d, 0x0d, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a,
0x0a, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x08,
0x08, 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07,
0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x05,
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04,
0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02,
0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};

View File

@ -52,8 +52,8 @@ class Peacock : public Plugin {
p_sustain, p_sustain,
p_release, p_release,
p_chorus, // 0, 1, 2 p_chorus, // 0, 1, 2
p_modWheel, p_vcoBend,
p_holdPedal, p_vcfBend,
paramCount paramCount
}; };