Compare commits

...

16 Commits

Author SHA1 Message Date
Gordon JC Pearce bad4e6b018 tune lfo speeds a bit 2025-12-30 01:02:55 +00:00
Gordon JC Pearce 4317f15f4e updated with gui fixes 2025-12-30 00:42:34 +00:00
Gordon JC Pearce 4982d27019 chorus buttons 2025-12-29 23:45:20 +00:00
Gordon JC Pearce ad7b7f4405 formatting cleanup 2025-12-28 12:08:42 +00:00
Gordon JC Pearce 36c27f14d8 mystran filter 2025-12-26 22:08:52 +00:00
Gordon JC Pearce 2d53d3c5da parameter MIDI value 2025-12-26 00:28:58 +00:00
Gordon JC Pearce fd392ecf56 proper parameter for chorus 2025-12-25 23:21:12 +00:00
Gordon JC Pearce 13ff93a0a5 LFO delay, basically feature-complete 2025-12-24 01:46:37 +00:00
Gordon JC Pearce d6e5f21e5b vcf lfo 2025-12-24 00:34:52 +00:00
Gordon JC Pearce 7a4ebded58 grr, argh, peacock.xcf.final.final.reallythistime.xcf.gz how many times will I cock this up? 2025-12-23 23:53:41 +00:00
Gordon JC Pearce 80c8f409f5 are you kidding, how often will I forget to put the 'off' LEDs back in? 2025-12-23 23:46:10 +00:00
Gordon JC Pearce cef0957d6e lfo fix, chorus fix 2025-12-23 23:36:58 +00:00
Gordon JC Pearce e38cf3da59 fixed some blemishes 2025-12-23 23:11:53 +00:00
Gordon JC Pearce 5c5f8f2229 filter and oscillator tuning 2025-12-23 22:54:08 +00:00
Gordon JC Pearce 8ce34e6b3a replaced background image with fixed one 2025-12-23 11:09:43 +00:00
Gordon JC Pearce 9d64247598 declick things, now just needs parameter tuning 2025-12-23 00:20:00 +00:00
12 changed files with 16291 additions and 16002 deletions

View File

@ -63,7 +63,7 @@
pSustain, pSustain,
pRelease, pRelease,
pChorus, pChorusMode,
parameterCount parameterCount
}; };

File diff suppressed because it is too large Load Diff

View File

@ -110,6 +110,10 @@ void Assigner::noteOn(uint8_t note) {
return; return;
} }
if ((noteTbl[voiceTbl[0]] & 0x80)) {
m->lfoRampOn();
}
// loop around the voices // loop around the voices
for (i = NUM_VOICES - 1; i >= 0; i--) { for (i = NUM_VOICES - 1; i >= 0; i--) {
v = voiceTbl[i]; v = voiceTbl[i];
@ -137,6 +141,6 @@ void Assigner::noteOn(uint8_t note) {
// printf("at end, l=%d e=%d\n", l,e); // printf("at end, l=%d e=%d\n", l,e);
noteTbl[v] = note; noteTbl[v] = note;
d_debug("send voice on %3d to voice %d", note, v); d_debug("send voice on %3d to voice %d", note, i);
voice[v].on(note); voice[v].on(note);
} }

View File

@ -27,6 +27,7 @@ class Assigner {
Assigner(); Assigner();
void handleMidi(MidiEvent* ev); void handleMidi(MidiEvent* ev);
Voice* voice; Voice* voice;
Module *m;
private: private:
void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0) void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0)

View File

@ -21,6 +21,7 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <stdio.h>
Chorus::Chorus() { Chorus::Chorus() {
lpfOut1 = new float[bufferSize]; lpfOut1 = new float[bufferSize];
lpfOut2 = new float[bufferSize]; lpfOut2 = new float[bufferSize];
@ -29,6 +30,8 @@ Chorus::Chorus() {
lfoPhase = 1; lfoPhase = 1;
lfoSpeed = 6.283 * 10.7 / sampleRate; // plainly silly value to show if it hasn't been set lfoSpeed = 6.283 * 10.7 / sampleRate; // plainly silly value to show if it hasn't been set
gainTC = 1 - exp(-6.283 * 10 / sampleRate);
// not quite Butterworth but you'd never hear the difference // not quite Butterworth but you'd never hear the difference
// these are calculated from the real-world component values // these are calculated from the real-world component values
postFilter1l = new SVF(9688, .549); postFilter1l = new SVF(9688, .549);
@ -100,6 +103,7 @@ void Chorus::run(float* input, float** outputs, uint32_t frames) {
delayptr++; delayptr++;
delayptr &= 0x3ff; delayptr &= 0x3ff;
} }
//printf("dly1 = %f\n", dly1);
postFilter1l->runSVF(lpfOut1, lpfOut1, frames); postFilter1l->runSVF(lpfOut1, lpfOut1, frames);
postFilter2l->runSVF(lpfOut1, lpfOut1, frames); postFilter2l->runSVF(lpfOut1, lpfOut1, frames);
@ -108,8 +112,10 @@ void Chorus::run(float* input, float** outputs, uint32_t frames) {
for (uint32_t i = 0; i < frames; i++) { for (uint32_t i = 0; i < frames; i++) {
float y = input[i]; float y = input[i];
outputs[0][i] = y + (gain * lpfOut1[i]); gainRC = (gain - gainRC) * gainTC + gainRC;
outputs[1][i] = y + (gain * lpfOut2[i]);
outputs[0][i] = y + (gainRC * lpfOut1[i]);
outputs[1][i] = y + (gainRC * lpfOut2[i]);
} }
} }
@ -143,15 +149,16 @@ void Chorus::setChorus(uint8_t mode) {
// switch chorus mode // switch chorus mode
switch (mode) { switch (mode) {
case 0x60: case 0x60:
case 0x20:
gain = 0; gain = 0;
break; break;
case 0x40: case 0x40:
gain = 1.2; gain = 1.2;
lfoSpeed = 6.283 * 0.5 / sampleRate; lfoSpeed = 6.283 * 0.3 / sampleRate;
break; break;
case 0x00: case 0x00:
gain = 1.2; gain = 1.2;
lfoSpeed = 6.283 * 0.9 / sampleRate; lfoSpeed = 6.283 * 0.5 / sampleRate;
break; break;
} }
} }

View File

@ -40,8 +40,12 @@ class Chorus {
private: private:
double lfoPhase = 0, lfoSpeed = 0; double lfoPhase = 0, lfoSpeed = 0;
uint8_t lfoState=0; uint8_t lfoState=0;
float gain = 1.2; float gain = 1.2;
float gainRC = 0;
float gainTC = 0;
uint16_t delayptr = 0; uint16_t delayptr = 0;

View File

@ -18,16 +18,51 @@
#include "module.hpp" #include "module.hpp"
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include "tables.hpp" #include "tables.hpp"
Module::Module() { Module::Module() {
// cutoff frequencies for various RC networks
vcaTC = 1 - exp(-6.283 * 159 / sampleRate); // VCA and VCF 10k/0.1u time constant
subTC = 1 - exp(-6.283 * 15 / sampleRate); // Main VCA and Sub Level 1k + 10u time constant
pwmTC = 1 - exp(-6.283 * 40 / sampleRate); // integrator with 100k/0.047u time constant
vcaBuf = new float[bufferSize];
subBuf = new float[bufferSize];
pwmBuf = new float[bufferSize];
} }
void Module::run(Voice* voice) { Module::~Module() {
printf("module destructor\n");
delete vcaBuf;
delete subBuf;
delete pwmBuf;
}
void Module::lfoRampOn() {
lfoDelayState = 1;
lfoDelayTimer = 0;
lfoDelay = 0;
}
void Module::run(Voice* voices, uint32_t blockSize) {
// run updates for module board // run updates for module board
if (lfoDelayState == 1) {
lfoDelayTimer += lfoDelayTable[patchRam.lfoDelay >> 4];
if (lfoDelayTimer & 0xc000) lfoDelayState = 2;
}
if ((lfoDelayState == 2)) {
lfoDelay += attackTable[patchRam.lfoDelay];
}
if (lfoDelay & 0xc000) {
lfoDelayState = 0;
lfoDelay = 0x3fff;
}
// FIXME break these out to the patch setter // FIXME break these out to the patch setter
a = attackTable[patchRam.env_a]; // attack time coeff looked up in table a = attackTable[patchRam.env_a]; // attack time coeff looked up in table
d = decayTable[patchRam.env_d]; // decay time coeff looked up in table d = decayTable[patchRam.env_d]; // decay time coeff looked up in table
@ -39,9 +74,10 @@ void Module::run(Voice* voice) {
sub = patchRam.sub / 127.0f; sub = patchRam.sub / 127.0f;
lfoPhase += lfoRateTable[patchRam.lfoRate]; lfoPhase += lfoRateTable[patchRam.lfoRate];
res = patchRam.vcfReso / 127.0 * 5; res = patchRam.vcfReso / 127.0;
noise = patchRam.noise / 127.0; noise = patchRam.noise / 127.0;
// FIXME the exp in these is expensive, don't call it all the time
chorus->setChorus(patchRam.switch1 & 0x60); chorus->setChorus(patchRam.switch1 & 0x60);
chorus->setHpf(patchRam.switch2 & 0x18); chorus->setHpf(patchRam.switch2 & 0x18);
@ -50,17 +86,35 @@ void Module::run(Voice* voice) {
else else
lfo = (lfoPhase & 0x3fff) - 0x1fff; lfo = (lfoPhase & 0x3fff) - 0x1fff;
// FIXME represent PW as int until we calculate the block?
pw = 0.5 - ((0x2000 + lfo) * patchRam.pwmLfo) / (32768.0f * 128); pw = 0.5 - ((0x2000 + lfo) * patchRam.pwmLfo) / (32768.0f * 128);
pw = (patchRam.switch2 & 0x01) ? 0.5 - (patchRam.pwmLfo / 256.0f) : pw; pw = (patchRam.switch2 & 0x01) ? 0.5 - (patchRam.pwmLfo / 256.0f) : pw;
lfo = (lfo * lfoDelay) >> 14;
float master = powf(2, (patchRam.vca / 31.75 - 4.0f));
float sub = patchRam.sub / 127.0f;
for (uint32_t i = 0; i < blockSize; i++) {
vcaRC = (master - vcaRC) * subTC + vcaRC;
pwmRC = (pw - pwmRC) * pwmTC + pwmRC;
subRC = (sub - subRC) * vcaTC + subRC;
vcaBuf[i] = vcaRC;
pwmBuf[i] = pwmRC;
subBuf[i] = subRC;
if (bufPtr < bufferSize) bufPtr++;
}
int16_t vcf = (patchRam.vcfEnv << 7) * ((patchRam.switch2 & 0x02) ? -1 : 1); int16_t vcf = (patchRam.vcfEnv << 7) * ((patchRam.switch2 & 0x02) ? -1 : 1);
int16_t pitchBase = 0x1818; int16_t pitchBase = 0x1818;
pitchBase += (lfo * lfoDepthTable[patchRam.vcoLfo]) >> 9; pitchBase += (lfo * lfoDepthTable[patchRam.vcoLfo]) >> 11;
for (uint32_t i = 0; i < NUM_VOICES; i++) { for (uint32_t i = 0; i < NUM_VOICES; i++) {
// maybe move all this into voice.cpp FIXME // maybe move all this into voice.cpp FIXME
Voice* v = &voice[i]; Voice* v = &voices[i];
switch (v->envPhase) { switch (v->envPhase) {
case 0: // release phase FIXME use an enum I guess case 0: // release phase FIXME use an enum I guess
v->env = (v->env * r) >> 16; // "RC" decay to zero v->env = (v->env * r) >> 16; // "RC" decay to zero
@ -78,6 +132,7 @@ void Module::run(Voice* voice) {
} }
// pitch // pitch
// FIXME clean this all up a bit
int16_t pitch = pitchBase + (v->note << 8); int16_t pitch = pitchBase + (v->note << 8);
int16_t semi = pitch >> 8; int16_t semi = pitch >> 8;
float frac = (pitch & 0xff) / 256.0; float frac = (pitch & 0xff) / 256.0;
@ -87,14 +142,17 @@ void Module::run(Voice* voice) {
px *= (patchRam.switch1 & 0x07); px *= (patchRam.switch1 & 0x07);
v->omega = px / (sampleRate * 4.0f); // fixme use proper scaler v->omega = px / (sampleRate * 8.0f); // fixme use proper scaler
// per voice we need to calculate the key follow amount and envelope amount // per voice we need to calculate the key follow amount and envelope amount
v->vcfCut = (patchRam.vcfFreq << 7) + ((vcf * v->env) >> 16); v->vcfCut = (patchRam.vcfFreq << 7) + ((vcf * v->env) >> 14);
v->vcfCut += (int)(v->note * (patchRam.vcfKey << 1) * 0.375); v->vcfCut += (lfo * patchRam.vcfLfo) >> 9;
v->vcfCut += (int)((v->note - 36) * (patchRam.vcfKey << 1) * 0.375);
if (v->vcfCut > 0x3fff) v->vcfCut = 0x3fff; if (v->vcfCut > 0x3fff) v->vcfCut = 0x3fff;
if (v->vcfCut < 0) v->vcfCut = 0; if (v->vcfCut < 0) v->vcfCut = 0;
v->vcaEnv = (patchRam.switch2 & 0x04) ? (v->envPhase ? 0x3fff : 0) : v->env; v->vcaEnv = (patchRam.switch2 & 0x04) ? (v->envPhase ? 0x3fff : 0) : v->env;
} }
} }

View File

@ -31,8 +31,11 @@ class Voice;
class Module { class Module {
public: public:
Module(); Module();
~Module();
void run(Voice* voice); void lfoRampOn();
void run(Voice* voices, uint32_t blockLeft);
float res = 0; float res = 0;
// precomputed values for all voices // precomputed values for all voices
@ -45,30 +48,91 @@ class Module {
float saw = 0, square = 0, sub = 0, noise = 0; float saw = 0, square = 0, sub = 0, noise = 0;
/*
#if 0
struct {
uint8_t lfoRate = 0x58;
uint8_t lfoDelay = 0x00;
uint8_t vcoLfo = 0x00;
uint8_t pwmLfo = 0x3b;
uint8_t noise = 0x00;
uint8_t vcfFreq = 0x25; // 1c; // 0x3f80
uint8_t vcfReso = 0x6a;
uint8_t vcfEnv = 0x25; // 4e;
uint8_t vcfLfo = 0x00;
uint8_t vcfKey = 0x00; // 47;
uint8_t vca = 0x35;
uint8_t env_a = 0x00;
uint8_t env_d = 0x3c;
uint8_t env_s = 0x00; // 0x3f80
uint8_t env_r = 0x3c;
uint8_t sub = 0x7f;
uint8_t switch1 = 0x4a;
uint8_t switch2 = 0x18;
} patchRam;
#else
struct {
uint8_t lfoRate = 0x40;
uint8_t lfoDelay = 0x00;
uint8_t vcoLfo = 0x00;
uint8_t pwmLfo = 0x00;
uint8_t noise = 0x01;
uint8_t vcfFreq = 0x31;
uint8_t vcfReso = 0x7f;
uint8_t vcfEnv = 0x00;
uint8_t vcfLfo = 0x00;
uint8_t vcfKey = 0x7f;
uint8_t vca = 0x40;
uint8_t env_a = 0x00;
uint8_t env_d = 0x00;
uint8_t env_s = 0x00; // 0x3f80
uint8_t env_r = 0x00;
uint8_t sub = 0x00;
uint8_t switch1 = 0x22;
uint8_t switch2 = 0x1d;
} patchRam;
#endif
*/
struct { struct {
uint8_t lfoRate = 0x18; uint8_t lfoRate = 0x58;
uint8_t lfoDelay = 0x00; uint8_t lfoDelay = 0x00;
uint8_t vcoLfo = 0x00; uint8_t vcoLfo = 0x00;
uint8_t pwmLfo = 0x60; uint8_t pwmLfo = 0x00;
uint8_t noise = 0x00; uint8_t noise = 0x00;
uint8_t vcfFreq = 0x30; // 1c; // 0x3f80 uint8_t vcfFreq = 0x00; // 1c; // 0x3f80
uint8_t vcfReso = 0x00; uint8_t vcfReso = 0x7f;
uint8_t vcfEnv = 0x40; // 4e; uint8_t vcfEnv = 0x7f; // 4e;
uint8_t vcfLfo = 0; uint8_t vcfLfo = 0x00;
uint8_t vcfKey = 0x7f; // 47; uint8_t vcfKey = 0x00; // 47;
uint8_t vca = 0x28; uint8_t vca = 0x20;
uint8_t env_a = 0x00; uint8_t env_a = 0x00;
uint8_t env_d = 0x39; uint8_t env_d = 0x5c;
uint8_t env_s = 0x30; // 0x3f80 uint8_t env_s = 0x00; // 0x3f80
uint8_t env_r = 0x30; uint8_t env_r = 0x3c;
uint8_t sub = 0x40; uint8_t sub = 0x7f;
uint8_t switch1 = 0x59; uint8_t switch1 = 0x3a;
uint8_t switch2 = 0x18; uint8_t switch2 = 0x19;
} patchRam; } patchRam;
Chorus* chorus; Chorus* chorus;
float vcaTC;
uint32_t bufPtr = 0;
float* vcaBuf;
float* subBuf;
float* pwmBuf;
private: private:
// controls // precalculated coefficients for RC networks
float pwmTC = 0, subTC = 0, mVcaTC = 0;
float pwmRC = 0, subRC = 0, vcaRC = 0;
uint16_t lfoDelay = 0;
uint8_t lfoDelayState = 0;
uint16_t lfoDelayTimer = 0;
}; };
class Voice { class Voice {
@ -81,9 +145,6 @@ class Voice {
void run(Module* m, float* buffer, uint32_t samples); void run(Module* m, float* buffer, uint32_t samples);
private: private:
// control
float vcaRC = 0, vcfRC = 0;
float omega = 0, theta = 0; // phase increment and angle FIXME better names float omega = 0, theta = 0; // phase increment and angle FIXME better names
float delay = 0, lastpw = 0; // delay slots for antialiasing float delay = 0, lastpw = 0; // delay slots for antialiasing
uint8_t pulseStage = 1; // pulse wave phase uint8_t pulseStage = 1; // pulse wave phase
@ -91,13 +152,16 @@ class Voice {
uint8_t envPhase = 0; uint8_t envPhase = 0;
int16_t env = 0; // output amplitude int16_t env = 0; // output amplitude
int16_t vcfCut; uint16_t vcfCut;
int16_t vcaEnv; int16_t vcaEnv;
float vcaEnvRC = 0; float vcaRC = 0, vcfRC = 0;
uint8_t note = 0; uint8_t note = 0;
// filter // filter
float b1 = 0, b2 = 0, b3 = 0, b4 = 0; float y0 = 0, y1 = 0, y2 = 0, y3 = 0;
double s[4] = {0, 0, 0, 0};
float zi = 0;
}; };
#endif #endif

View File

@ -23,7 +23,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pLFORate: case pLFORate:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO Rate"; parameter.name = "LFO Rate";
parameter.symbol = "ch_lforate"; parameter.symbol = "pfau_lforate";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 48.0f; parameter.ranges.def = 48.0f;
@ -33,7 +33,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pLFODelay: case pLFODelay:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO Delay"; parameter.name = "LFO Delay";
parameter.symbol = "ch_lfodelay"; parameter.symbol = "pfau_lfodelay";
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 = 0.0f;
@ -43,7 +43,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pVCORange: case pVCORange:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger; parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "Range"; parameter.name = "Range";
parameter.symbol = "ch_vcorange"; parameter.symbol = "pfau_vcorange";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 2.0f; parameter.ranges.max = 2.0f;
parameter.ranges.def = 1.0f; parameter.ranges.def = 1.0f;
@ -60,13 +60,12 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
enumValues[2].label = "4'"; enumValues[2].label = "4'";
parameter.enumValues.values = enumValues; parameter.enumValues.values = enumValues;
} }
break; break;
case pLFODepth: case pLFODepth:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO"; parameter.name = "LFO";
parameter.symbol = "ch_lfo"; parameter.symbol = "pfau_lfo";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 10.0f; parameter.ranges.def = 10.0f;
@ -76,7 +75,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pPWMDepth: case pPWMDepth:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "PWM"; parameter.name = "PWM";
parameter.symbol = "ch_pwm"; parameter.symbol = "pfau_pwm";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 48.0f; parameter.ranges.def = 48.0f;
@ -86,7 +85,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pPWMMode: case pPWMMode:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "PWM Mode"; parameter.name = "PWM Mode";
parameter.symbol = "ch_pwmmode"; parameter.symbol = "pfau_pwmmode";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
parameter.ranges.def = 1.0f; parameter.ranges.def = 1.0f;
@ -107,7 +106,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pSaw: case pSaw:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Saw"; parameter.name = "Saw";
parameter.symbol = "ch_saw"; parameter.symbol = "pfau_saw";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
parameter.ranges.def = 1.0f; parameter.ranges.def = 1.0f;
@ -117,7 +116,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pSqr: case pSqr:
parameter.hints = kParameterIsAutomatable | kParameterIsBoolean; parameter.hints = kParameterIsAutomatable | kParameterIsBoolean;
parameter.name = "Square"; parameter.name = "Square";
parameter.symbol = "ch_sqr"; parameter.symbol = "pfau_sqr";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
parameter.ranges.def = 1.0f; parameter.ranges.def = 1.0f;
@ -127,7 +126,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pSubLevel: case pSubLevel:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Sub Osc"; parameter.name = "Sub Osc";
parameter.symbol = "ch_sub"; parameter.symbol = "pfau_sub";
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 = 0.0f;
@ -137,7 +136,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pNoiseLevel: case pNoiseLevel:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Noise"; parameter.name = "Noise";
parameter.symbol = "ch_noise"; parameter.symbol = "pfau_noise";
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 = 0.0f;
@ -147,7 +146,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pHPF: case pHPF:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger; parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "HPF"; parameter.name = "HPF";
parameter.symbol = "ch_hpf"; parameter.symbol = "pfau_hpf";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 3.9f; parameter.ranges.max = 3.9f;
parameter.ranges.def = 0.0f; parameter.ranges.def = 0.0f;
@ -157,7 +156,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pCutoff: case pCutoff:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Freq"; parameter.name = "Freq";
parameter.symbol = "ch_freq"; parameter.symbol = "pfau_freq";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 60.0f; parameter.ranges.def = 60.0f;
@ -166,7 +165,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pRes: case pRes:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Res"; parameter.name = "Res";
parameter.symbol = "ch_reso"; parameter.symbol = "pfau_reso";
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 = 0.0f;
@ -175,7 +174,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pVCFPol: case pVCFPol:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger; parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "Polarity"; parameter.name = "Polarity";
parameter.symbol = "ch_vcfmode"; parameter.symbol = "pfau_vcfmode";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
parameter.ranges.def = 0.0f; parameter.ranges.def = 0.0f;
@ -195,7 +194,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pEnv: case pEnv:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Env"; parameter.name = "Env";
parameter.symbol = "ch_vcfenv"; parameter.symbol = "pfau_vcfenv";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 46.0f; parameter.ranges.def = 46.0f;
@ -204,7 +203,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pLfo: case pLfo:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "LFO"; parameter.name = "LFO";
parameter.symbol = "ch_vcflfo"; parameter.symbol = "pfau_vcflfo";
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 = 0.0f;
@ -213,7 +212,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pKyb: case pKyb:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Kybd"; parameter.name = "Kybd";
parameter.symbol = "ch_vcfkey"; parameter.symbol = "pfau_vcfkey";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 71.0f; parameter.ranges.def = 71.0f;
@ -223,7 +222,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pAttack: case pAttack:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Attack"; parameter.name = "Attack";
parameter.symbol = "ch_attack"; parameter.symbol = "pfau_attack";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 27.0f; parameter.ranges.def = 27.0f;
@ -233,7 +232,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pDecay: case pDecay:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Decay"; parameter.name = "Decay";
parameter.symbol = "ch_decay"; parameter.symbol = "pfau_decay";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 57.0f; parameter.ranges.def = 57.0f;
@ -243,7 +242,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pSustain: case pSustain:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Sustain"; parameter.name = "Sustain";
parameter.symbol = "ch_sustain"; parameter.symbol = "pfau_sustain";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 57.0f; parameter.ranges.def = 57.0f;
@ -253,7 +252,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pRelease: case pRelease:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "Release"; parameter.name = "Release";
parameter.symbol = "ch_release"; parameter.symbol = "pfau_release";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 48.0f; parameter.ranges.def = 48.0f;
@ -263,7 +262,7 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pEnvGate: case pEnvGate:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger; // | kParameterIsBoolean; parameter.hints = kParameterIsAutomatable | kParameterIsInteger; // | kParameterIsBoolean;
parameter.name = "Env-Gate"; parameter.name = "Env-Gate";
parameter.symbol = "ch_envgate"; parameter.symbol = "pfau_envgate";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 1.0f; parameter.ranges.max = 1.0f;
parameter.ranges.def = 0.0f; parameter.ranges.def = 0.0f;
@ -283,17 +282,38 @@ void Peacock::initParameter(uint32_t index, Parameter& parameter) {
case pVCALevel: case pVCALevel:
parameter.hints = kParameterIsAutomatable; parameter.hints = kParameterIsAutomatable;
parameter.name = "VCA Level"; parameter.name = "VCA Level";
parameter.symbol = "ch_vcalevel"; parameter.symbol = "pfau_vcalevel";
parameter.ranges.min = 0.0f; parameter.ranges.min = 0.0f;
parameter.ranges.max = 127.0f; parameter.ranges.max = 127.0f;
parameter.ranges.def = 40.0f; parameter.ranges.def = 40.0f;
parameter.midiCC = 26; parameter.midiCC = 26;
break; break;
case pChorusMode:
parameter.hints = kParameterIsAutomatable | kParameterIsInteger;
parameter.name = "Chorus";
parameter.symbol = "pfau_chorus";
parameter.ranges.min = 0.0f;
parameter.ranges.max = 2.0f;
parameter.ranges.def = 0.0f;
parameter.midiCC = 93;
parameter.enumValues.count = 3;
parameter.enumValues.restrictedMode = true;
{
ParameterEnumerationValue* const enumValues = new ParameterEnumerationValue[3];
enumValues[0].value = 0.0f;
enumValues[0].label = "Off";
enumValues[1].value = 1.0f;
enumValues[1].label = "Slow";
enumValues[2].value = 2.0f;
enumValues[2].label = "Fast";
parameter.enumValues.values = enumValues;
}
/* /*
case pModWheel: case pModWheel:
parameter.hints = kParameterIsAutomatable | kParameterIsHidden; parameter.hints = kParameterIsAutomatable | kParameterIsHidden;
parameter.name = "Mod wheel"; parameter.name = "Mod wheel";
parameter.symbol = "ch_modwheel"; parameter.symbol = "pfau_modwheel";
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 = 0.0f;
@ -379,9 +399,8 @@ void Peacock::setParameterValue(uint32_t index, float value) {
m->patchRam.switch1 |= (value >= 0.5) << 4; m->patchRam.switch1 |= (value >= 0.5) << 4;
break; break;
case pChorus: case pChorusMode:
m->patchRam.switch1 &= 0x9f; m->patchRam.switch1 &= 0x9f;
switch ((int)value) { switch ((int)value) {
case 0: case 0:
m->patchRam.switch1 |= 0x60; // both off m->patchRam.switch1 |= 0x60; // both off
@ -506,8 +525,7 @@ float Peacock::getParameterValue(uint32_t index) const {
case pVCALevel: case pVCALevel:
return m->patchRam.vca; return m->patchRam.vca;
break; break;
case pChorus: case pChorusMode:
switch (m->patchRam.switch1 & 0x60) { switch (m->patchRam.switch1 & 0x60) {
case 0x60: case 0x60:
return 0; return 0;
@ -518,8 +536,6 @@ float Peacock::getParameterValue(uint32_t index) const {
default: default:
break; break;
} }
} }
return 0; return 0;
} }

View File

@ -32,9 +32,8 @@ Peacock::Peacock() : Plugin(parameterCount, 0, 0) {
m = new Module(); m = new Module();
ic1 = new Assigner; ic1 = new Assigner;
ic1->voice = voice; ic1->voice = voice;
ic1->m = m;
m->chorus = chorus; m->chorus = chorus;
} }
Peacock::~Peacock() { Peacock::~Peacock() {
@ -73,6 +72,7 @@ void Peacock::run(const float**, float** outputs, uint32_t frames, const MidiEve
// if there were any events that happen between now and the end of this block, process them // if there were any events that happen between now and the end of this block, process them
lastEvent = 0; lastEvent = 0;
m->bufPtr = 0;
runMidi(midiEvents, midiEventCount, blockLeft); runMidi(midiEvents, midiEventCount, blockLeft);
while (framePos < frames) { while (framePos < frames) {
@ -81,11 +81,12 @@ void Peacock::run(const float**, float** outputs, uint32_t frames, const MidiEve
blockLeft = sampleRate / 238; // update rate in Hz blockLeft = sampleRate / 238; // update rate in Hz
runMidi(midiEvents, midiEventCount, framePos + blockLeft); runMidi(midiEvents, midiEventCount, framePos + blockLeft);
m->run(voice);
} }
// how many frames to do? Are we about to run off an update block // how many frames to do? Are we about to run off an update block
sizeThisTime = (framesLeft < blockLeft) ? framesLeft : blockLeft; sizeThisTime = (framesLeft < blockLeft) ? framesLeft : blockLeft;
m->run(voice, sizeThisTime);
// now run all the voices for this chunk of samples // now run all the voices for this chunk of samples
for (uint32_t i = 0; i < NUM_VOICES; i++) { for (uint32_t i = 0; i < NUM_VOICES; i++) {
@ -98,8 +99,8 @@ void Peacock::run(const float**, float** outputs, uint32_t frames, const MidiEve
} }
// now we've assembled a full chunk of audio // now we've assembled a full chunk of audio
//memcpy(outputs[0], m->vcaBuf, sizeof(float)* frames);
chorus->run(outputs[0], outputs, frames); chorus->run(outputs[0], outputs, frames);
} }
Plugin* createPlugin() { return new Peacock(); } Plugin* createPlugin() { return new Peacock(); }

View File

@ -258,6 +258,7 @@ void DistrhoUIPeacock::parameterChanged(uint32_t index, float value) {
sw1 &= 0xf8; // mask sw1 &= 0xf8; // mask
if (value > 2) value = 2; if (value > 2) value = 2;
sw1 |= (1 << (int)value); sw1 |= (1 << (int)value);
xBtn16ft->repaint(); // will repaint all the panel
break; break;
case pSqr: case pSqr:
sw1 &= 0xf7; sw1 &= 0xf7;
@ -268,7 +269,7 @@ void DistrhoUIPeacock::parameterChanged(uint32_t index, float value) {
sw1 |= (value > 0.5) << 4; sw1 |= (value > 0.5) << 4;
break; break;
case pChorus: case pChorusMode:
sw1 &= 0x9f; sw1 &= 0x9f;
// 60, 40, 00 // 60, 40, 00
switch ((int)value) { switch ((int)value) {
@ -325,15 +326,15 @@ void DistrhoUIPeacock::imageButtonClicked(ImageButton* imgBtn, int) {
break; break;
case btnCh0: case btnCh0:
sw1 = (sw1 & 0x9f) | 0x20; sw1 = (sw1 & 0x9f) | 0x20;
setParameterValue(pChorus, 0); setParameterValue(pChorusMode, 0);
break; break;
case btnCh1: case btnCh1:
sw1 = (sw1 & 0x9f) | 0x40; sw1 = (sw1 & 0x9f) | 0x40;
setParameterValue(pChorus, 1); setParameterValue(pChorusMode, 1);
break; break;
case btnCh2: case btnCh2:
sw1 = (sw1 & 0x9f); sw1 = (sw1 & 0x9f);
setParameterValue(pChorus, 2); setParameterValue(pChorusMode, 2);
break; break;
default: default:

View File

@ -40,9 +40,9 @@ Voice::Voice() {
} }
void Voice::on(uint8_t midiNote) { void Voice::on(uint8_t midiNote) {
//omega = 261.63 * powf(2, (note - 60) / 12.0f) / 48000.0f; while (midiNote < 24) midiNote += 12;
if (midiNote>24) note = midiNote-24; while (midiNote > 108) midiNote -= 12;
else note = 24; note = midiNote - 24;
envPhase = 1; envPhase = 1;
} }
@ -50,16 +50,26 @@ void Voice::off() {
envPhase = 0; envPhase = 0;
} }
// tanh(x)/x approximation, flatline at very high inputs
// so might not be safe for very large feedback gains
// [limit is 1/15 so very large means ~15 or +23dB]
double tanhXdX(double x) {
float s = 0.0333, d = 30.0;
return 1.0f - s * (d + 1.0f) * x * x / (d + x * x);
}
void Voice::run(Module* m, float* buffer, uint32_t samples) { void Voice::run(Module* m, float* buffer, uint32_t samples) {
// carry out per-voice calculations for each block of samples // carry out per-voice calculations for each block of samples
float out, t, fb; float out, t, fb;
//float cut = 0.00513 + 0.0000075*env;
// calculate cutoff frequency // calculate cutoff frequency
float cut = 248.0f * (powf(2, (vcfCut - 0x1880) / 1143.0f)); float cut = 261.0f * (powf(2, (vcfCut - 0x1880) / 1143.0f));
cut = 0.25 * 6.2832 * cut / 48000.0f; // FIXME hardcoded values cut = M_PI * cut / sampleRate;
cut = cut/(1+cut); // correct tuning warp cut = cut / (1 + cut); // correct tuning warp
// if (cut > 0.7) cut = 0.7;
double r = 5 * m->res;
float amp = vcaEnv / 4096.0f; float amp = vcaEnv / 4096.0f;
@ -71,8 +81,8 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) {
while (true) { while (true) {
if (pulseStage == 0) { if (pulseStage == 0) {
if (theta < m->pw) break; if (theta < m->pwmBuf[i]) break;
t = (theta - m->pw) / (lastpw - m->pw + omega); t = (theta - m->pwmBuf[i]) / (lastpw - m->pwmBuf[i] + omega);
out -= poly3blep0(t) * m->square; out -= poly3blep0(t) * m->square;
delay -= poly3blep1(t) * m->square; delay -= poly3blep1(t) * m->square;
pulseStage = 1; pulseStage = 1;
@ -84,8 +94,8 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) {
out += poly3blep0(t) * (m->saw + m->square); out += poly3blep0(t) * (m->saw + m->square);
delay += poly3blep1(t) * (m->saw + m->square); delay += poly3blep1(t) * (m->saw + m->square);
out -= poly3blep0(t) * (m->sub * subosc); out -= poly3blep0(t) * (m->subBuf[i] * subosc);
delay -= poly3blep1(t) * (m->sub * subosc); delay -= poly3blep1(t) * (m->subBuf[i] * subosc);
pulseStage = 0; pulseStage = 0;
subosc = -subosc; subosc = -subosc;
@ -93,33 +103,109 @@ void Voice::run(Module* m, float* buffer, uint32_t samples) {
} }
} }
// FIXME DC offset removal
delay += m->saw * (1 - (2 * theta)); delay += m->saw * (1 - (2 * theta));
delay += m->square * (pulseStage ? -1.f : 1.f); delay += m->square * ((pulseStage ? -1.f : 1.f) - m->pwmBuf[i] + 0.5);
delay += m->sub * subosc; delay += m->subBuf[i] * subosc;
// delay += (1-(m->noisegen/(float)(1<<30))) * m->noise; FIXME figure out what to do about noise
out += m->noise * (0.8 - 1.6 * (rand() & 0xffff) / 65536.0);
// out *= 0.1;
// same time constant for both VCF and VCF RC circuits
vcfRC = (cut - vcfRC) * m->vcaTC + vcfRC;
#if 1
//// LICENSE TERMS: Copyright 2012 Teemu Voipio
//
// You can use this however you like for pretty much any purpose,
// as long as you don't claim you wrote it. There is no warranty.
//
// Distribution of substantial portions of this code in source form
// must include this copyright notice and list of conditions.
//
// input delay and state for member variables
// cutoff as normalized frequency (eg 0.5 = Nyquist)
// resonance from 0 to 1, self-oscillates at settings over 0.9
// void transistorLadder(
// double cutoff, double resonance,
// double * in, double * out, unsigned nsamples)
//{
// tuning and feedback
//------------------------------------------------------------------------------ sample loop
// for(unsigned n = 0; n < nsamples; ++n)
//{
out *= 0.025;
// input with half delay, for non-linearities
double ih = 0.5 * (out + zi);
zi = out;
// double ih = out;
// evaluate the non-linear gains
double t0 = tanhXdX((ih * (r + 1)) - r * s[3]);
double t1 = tanhXdX(s[0]);
double t2 = tanhXdX(s[1]);
double t3 = tanhXdX(s[2]);
double t4 = tanhXdX(s[3]);
double f = vcfRC;
// g# the denominators for solutions of individual stages
double g0 = 1 / (1 + f * t1), g1 = 1 / (1 + f * t2);
double g2 = 1 / (1 + f * t3), g3 = 1 / (1 + f * t4);
// f# are just factored out of the feedback solution
double f3 = f * t3 * g3, f2 = f * t2 * g2 * f3, f1 = f * t1 * g1 * f2, f0 = f * t0 * g0 * f1;
// solve feedback
double y3 = (g3 * s[3] + f3 * g2 * s[2] + f2 * g1 * s[1] + f1 * g0 * s[0] + f0 * out) / (1 + r * f0);
// then solve the remaining outputs (with the non-linear gains here)
double xx = t0 * ((out * (r + 1)) - r * y3);
double y0 = t1 * g0 * (s[0] + f * xx);
double y1 = t2 * g1 * (s[1] + f * y0);
double y2 = t3 * g2 * (s[2] + f * y1);
// update state
s[0] += 2 * f * (xx - y0);
s[1] += 2 * f * (y0 - y1);
s[2] += 2 * f * (y1 - y2);
s[3] += 2 * f * (y2 - t4 * y3);
// out[n] = y3;
// }
// out *= 0.1;
out = y3;
#else
out += m->noise * (0.8-1.6 *(rand() & 0xffff) / 65536.0);
out *= 0.5; out *= 0.5;
for (uint8_t ovs = 0; ovs < 2; ovs++) {
for (uint8_t ovs = 0; ovs < 4; ovs++) { fb = y3;
fb = b4;
// hard clip // hard clip
fb = ((out*0.5) - fb) * m->res; fb = ((out * 0.5) - fb) * r;
if (fb > 4) fb = 4; if (fb > 4) fb = 4;
if (fb < -4) fb = -4; if (fb < -4) fb = -4;
// fb = 1.5 * fb - 0.5 * fb * fb * fb; // fb = 1.5 * fb - 0.5 * fb * fb * fb;
// //
b1 = ((out + fb - b1) * cut) + b1; y0 = ((out + fb - y0) * vcfRC) + y0;
b2 = ((b1 - b2) * cut) + b2; y1 = ((y0 - y1) * vcfRC) + y1;
b3 = ((b2 - b3) * cut) + b3; y2 = ((y1 - y2) * vcfRC) + y2;
b4 = ((b3 - b4) * cut) + b4; y3 = ((y2 - y3) * vcfRC) + y3;
} }
#endif
vcaRC = (amp - vcaRC) * m->vcaTC + vcaRC;
buffer[i] += m->vcaBuf[i] * vcaRC * out;
vcaEnvRC = (amp - vcaEnvRC) * 0.0203 + vcaEnvRC; lastpw = m->pwmBuf[i];
buffer[i] += 0.0367 * vcaEnvRC * b4;
lastpw = m->pw;
} }
// buffer[0] += 1; // buffer[0] += 1;
} }