Compare commits

..

6 Commits

Author SHA1 Message Date
Gordon JC Pearce d2e8e6126d adjustments to timing 2026-01-07 12:25:46 +00:00
Gordon JC Pearce e452e282f4 fixed button update bug in Windows 2026-01-07 11:38:04 +00:00
Gordon JC Pearce a3a2e0dd04 fix lfo and pitch calculation 2026-01-06 22:16:39 +00:00
Gordon JC Pearce 7ff0bf0659 better LFO and PW 2026-01-06 20:20:30 +00:00
Gordon JC Pearce 8c2263c129 chorus a bit more like the real thing 2026-01-05 23:08:50 +00:00
Gordon JC Pearce ffe4026b18 fix module being updated at the wrong time causing incorrect LFO speed 2026-01-05 21:34:30 +00:00
8 changed files with 94 additions and 62 deletions

View File

@ -34,7 +34,8 @@ include ../dpf/Makefile.plugins.mk
SKIP_NATIVE_AUDIO_FALLBACK = true SKIP_NATIVE_AUDIO_FALLBACK = true
TARGETS += jack lv2_sep vst3 clap # omitting LV2 for the moment until I figure out cross-compiling
TARGETS += jack vst2 vst3 clap
all: $(TARGETS) all: $(TARGETS)

View File

@ -19,9 +19,8 @@
#include "chorus.hpp" #include "chorus.hpp"
#include <math.h> #include <math.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
Chorus::Chorus() { Chorus::Chorus() {
lpfOut1 = new float[bufferSize]; lpfOut1 = new float[bufferSize];
lpfOut2 = new float[bufferSize]; lpfOut2 = new float[bufferSize];
@ -30,7 +29,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); gainTC = 1 - exp(-M_PI * 10 / sampleRate); // 1/10th of a second declick
bbdTC = 1 - exp(-M_PI * 60 / sampleRate); // hpf into BBD
// 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
@ -76,11 +76,14 @@ void Chorus::run(float* input, float** outputs, uint32_t frames) {
hpDelay = flt; hpDelay = flt;
input[i] += (flt * hpGain); input[i] += (flt * hpGain);
ram[delayptr] = input[i]; flt = ((input[i] - bbdRC) * bbdTC) + bbdRC;
bbdRC = flt;
ram[delayptr] = input[i] - flt;
// delays in milliseconds // delays in milliseconds
#define BASE 0.005 #define BASE 0.0035
#define AMT 0.00175 #define AMT 0.002
dly1 = (BASE + (AMT * lfoPhase)) * sampleRate; dly1 = (BASE + (AMT * lfoPhase)) * sampleRate;
delay = (int)dly1; delay = (int)dly1;
@ -103,8 +106,6 @@ 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);
postFilter1r->runSVF(lpfOut2, lpfOut2, frames); postFilter1r->runSVF(lpfOut2, lpfOut2, frames);
@ -113,7 +114,6 @@ 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];
gainRC = (gain - gainRC) * gainTC + gainRC; gainRC = (gain - gainRC) * gainTC + gainRC;
outputs[0][i] = y + (gainRC * lpfOut1[i]); outputs[0][i] = y + (gainRC * lpfOut1[i]);
outputs[1][i] = y + (gainRC * lpfOut2[i]); outputs[1][i] = y + (gainRC * lpfOut2[i]);
} }
@ -127,11 +127,11 @@ void Chorus::setHpf(uint8_t mode) {
// k = 1-exp(-2pi * Fc * sampleRate) // k = 1-exp(-2pi * Fc * sampleRate)
switch (mode) { switch (mode) {
case 0x00: case 0x00:
hpCut = 1 - exp(-6.283 * 720 / sampleRate); hpCut = 1 - exp(-M_PI * 720 / sampleRate);
hpGain = -1; hpGain = -1;
break; break;
case 0x08: case 0x08:
hpCut = 1 - exp(-6.283 * 225 / sampleRate); hpCut = 1 - exp(-M_PI * 225 / sampleRate);
hpGain = -1; hpGain = -1;
break; break;
case 0x10: case 0x10:
@ -139,7 +139,7 @@ void Chorus::setHpf(uint8_t mode) {
hpGain = 0; hpGain = 0;
break; break;
case 0x18: case 0x18:
hpCut = 1 - exp(-6.283 * 85 / sampleRate); hpCut = 1 - exp(-M_PI * 85 / sampleRate);
hpGain = 1.707; hpGain = 1.707;
break; break;
} }
@ -154,11 +154,11 @@ void Chorus::setChorus(uint8_t mode) {
break; break;
case 0x40: case 0x40:
gain = 1.2; gain = 1.2;
lfoSpeed = 6.283 * 0.3 / sampleRate; lfoSpeed = M_PI * 0.525 / sampleRate;
break; break;
case 0x00: case 0x00:
gain = 1.2; gain = 1.2;
lfoSpeed = 6.283 * 0.5 / sampleRate; lfoSpeed = M_PI * 0.85 / sampleRate;
break; break;
} }
} }

View File

@ -46,6 +46,8 @@ class Chorus {
float gainRC = 0; float gainRC = 0;
float gainTC = 0; float gainTC = 0;
float bbdRC=0, bbdTC=0;
uint16_t delayptr = 0; uint16_t delayptr = 0;

View File

@ -25,9 +25,9 @@
Module::Module() { Module::Module() {
// cutoff frequencies for various RC networks // cutoff frequencies for various RC networks
vcaTC = 1 - exp(-6.283 * 159 / sampleRate); // VCA and VCF 10k/0.1u time constant vcaTC = 1 - exp(-M_PI * 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 subTC = 1 - exp(-M_PI * 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 pwmTC = 1 - exp(-M_PI * 40 / sampleRate); // integrator with 100k/0.047u time constant
vcaBuf = new float[bufferSize]; vcaBuf = new float[bufferSize];
subBuf = new float[bufferSize]; subBuf = new float[bufferSize];
@ -58,32 +58,41 @@ void Module::lfoRampOn() {
void Module::runLFO() { void Module::runLFO() {
if (lfoDelayState == 1) { if (lfoDelayState == 1) {
lfoDelayTimer += lfoDelayTable[patchRam.lfoDelay >> 4]; lfoDelayTimer += attackTable[patchRam.lfoDelay];
if (lfoDelayTimer & 0xc000) lfoDelayState = 2; if (lfoDelayTimer > 0x3fff) lfoDelayState = 2;
} }
if ((lfoDelayState == 2)) { if ((lfoDelayState == 2)) {
lfoDelay += attackTable[patchRam.lfoDelay]; lfoDelay += lfoDelayTable[patchRam.lfoDelay >> 4];
} }
if (lfoDelay & 0xc000) { if (lfoDelay > 0xff) {
lfoDelayState = 0; lfoDelayState = 0;
lfoDelay = 0x3fff; lfoDelay = 0xff;
} }
lfoPhase += lfoRateTable[patchRam.lfoRate]; lfoRate = lfoRateTable[patchRam.lfoRate]; // FIXME move to parameters
if (lfoPhase & 0x4000)
lfo = 0x1fff - (lfoPhase & 0x3fff);
else
lfo = (lfoPhase & 0x3fff) - 0x1fff;
pw = 0x3fff-(((0x2000 + lfo) * patchRam.pwmLfo) >> 7); lfoPhase += (lfoState & 0x01) ? -lfoRate : lfoRate;
pw = (patchRam.switch2 & 0x01) ? 0x3fff - (patchRam.pwmLfo << 7 ) : pw; if (lfoPhase > 0x1fff) {
lfo = (lfo * lfoDelay) >> 14; lfoPhase = 0x1fff;
lfoState++;
}
if (lfoPhase < 0x0000) {
lfoPhase = 0x0000;
lfoState++;
}
lfo = (lfoState & 0x02) ? -lfoPhase : lfoPhase;
pw = (lfoState & 0x02) ? lfoPhase + 0x2000 : 0x2000 - lfoPhase; // PW LFO is unipolar
pw = (patchRam.switch2 & 0x01) ? 0x3fff : pw; // either LFO or "all on"
pw = 0x3fff - ((pw * patchRam.pwmLfo) >> 7); // scaled by PWM pot
} }
void Module::run(Voice* voices, uint32_t blockSize) { void Module::run(Voice* voices, uint32_t blockSize) {
// run updates for module board // run updates for module board
int16_t lfoToVco = 0, lfoToVcf = 0;
// 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
@ -95,12 +104,12 @@ void Module::run(Voice* voices, uint32_t blockSize) {
// originally I had 0.28, 0.36, 0.4 // originally I had 0.28, 0.36, 0.4
// measurement suggests that saw and square are around 100mV each with sub 160mV // measurement suggests that saw and square are around 100mV each with sub 160mV
square = (patchRam.switch1 & 0x08) ? 0.3 : 0; square = (patchRam.switch1 & 0x08) ? 1 : 0;
saw = (patchRam.switch1 & 0x10) ? .3 : 0; saw = (patchRam.switch1 & 0x10) ? 1 : 0;
sub = (patchRam.sub / 127.0f) * 0.48; sub = (patchRam.sub / 127.0f) * 1.6;
res = patchRam.vcfReso / 127.0; res = patchRam.vcfReso / 127.0;
noise = (patchRam.noise / 127.0) * 0.4; noise = (patchRam.noise / 127.0);
// FIXME the exp in these is expensive, don't call it all the time // FIXME the exp in these is expensive, don't call it all the time
chorus->setChorus(patchRam.switch1 & 0x60); chorus->setChorus(patchRam.switch1 & 0x60);
@ -108,10 +117,11 @@ void Module::run(Voice* voices, uint32_t blockSize) {
runLFO(); runLFO();
float pwf = pw / 32768.0f; // calculate "smoothed" parameters
// these are single outputs with heavy RC smoothing
for (uint32_t i = 0; i < blockSize; i++) { for (uint32_t i = 0; i < blockSize; i++) {
vcaRC = (master - vcaRC) * subTC + vcaRC; vcaRC = (master - vcaRC) * subTC + vcaRC;
pwmRC = (pwf - pwmRC) * pwmTC + pwmRC; pwmRC = ((pw / 32768.0f) - pwmRC) * pwmTC + pwmRC;
subRC = (sub - subRC) * vcaTC + subRC; subRC = (sub - subRC) * vcaTC + subRC;
vcaBuf[i] = vcaRC; vcaBuf[i] = vcaRC;
@ -121,13 +131,27 @@ void Module::run(Voice* voices, uint32_t blockSize) {
if (bufPtr < bufferSize) bufPtr++; if (bufPtr < bufferSize) bufPtr++;
} }
int16_t vcf = (patchRam.vcfEnv << 7) * ((patchRam.switch2 & 0x02) ? -1 : 1); lfoToVco = (lfoDepthTable[patchRam.vcoLfo] * lfoDelay) >> 8; // lookup table is 0-255
lfoToVco += /* lfo from modwheel FIXME */ 0;
if (lfoToVco > 0xff) lfoToVco = 0xff;
lfoToVco = (lfo * lfoToVco) >> 11; // 8 for normalisation plus three additional DSLR EA
int16_t pitchBase = 0x1818; lfoToVcf = (patchRam.vcfLfo * lfoDelay) >> 7; // value is 0-127
pitchBase += (lfo * lfoDepthTable[patchRam.vcoLfo]) >> 11; lfoToVcf = (lfo * lfoToVcf) >> 9; // 8 for normalisation plus one additional DSLR EA
int16_t pitchBase = 0x1818, vcfBase = 0;
pitchBase += lfoToVco;
pitchBase += /* pitch bend FIXME */ 0;
// int16_t vcf = (patchRam.vcfEnv << 7) * ((patchRam.switch2 & 0x02) ? -1 : 1);
vcfBase = (patchRam.vcfFreq << 7) + /* vcf bend FIXME */ 0;
vcfBase += lfoToVcf;
if (vcfBase > 0x3fff) vcfBase = 0x3fff;
if (vcfBase < 0x0000) vcfBase = 0x0000;
// per-voice calculations
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 // run one step of the envelope
Voice* v = &voices[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
@ -146,21 +170,20 @@ void Module::run(Voice* voices, uint32_t blockSize) {
} }
// pitch // pitch
// FIXME clean this all up a bit uint16_t pitch = pitchBase + (v->note << 8);
int16_t pitch = pitchBase + (v->note << 8); uint8_t semi = pitch >> 8;
int16_t semi = pitch >> 8;
float frac = (pitch & 0xff) / 256.0; float frac = (pitch & 0xff) / 256.0;
float p1 = pitchTable[semi], p2 = pitchTable[semi + 1]; float p1 = pitchTable[semi], p2 = pitchTable[semi + 1];
int16_t px = ((p2 - p1) * frac + p1); int16_t px = ((p2 - p1) * frac + p1); // interpolated pitch from table
// octave divider
px *= (patchRam.switch1 & 0x07); px *= (patchRam.switch1 & 0x07);
v->omega = px / (sampleRate * 8.0f); // fixme use proper scaler v->omega = px / (sampleRate * 8.0f); // FIXME recalculate table using 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) >> 14); v->vcfCut = vcfBase + (((v->env * patchRam.vcfEnv)>>7) * ((patchRam.switch2 & 0x02) ? -1 : 1));
v->vcfCut += (lfo * patchRam.vcfLfo) >> 9;
v->vcfCut += (int)((v->note - 36) * (patchRam.vcfKey << 1) * 0.375); v->vcfCut += (int)((v->note - 36) * (patchRam.vcfKey << 1) * 0.375);

View File

@ -92,7 +92,7 @@ class Module {
*/ */
struct { struct {
uint8_t lfoRate = 0x00; uint8_t lfoRate = 0x1f;
uint8_t lfoDelay = 0x00; uint8_t lfoDelay = 0x00;
uint8_t vcoLfo = 0x00; uint8_t vcoLfo = 0x00;
uint8_t pwmLfo = 0x3c; uint8_t pwmLfo = 0x3c;
@ -124,12 +124,15 @@ class Module {
private: private:
void runLFO(); void runLFO();
// precalculated coefficients for RC networks // precalculated coefficients for RC networks
float pwmTC = 0, subTC = 0, mVcaTC = 0; float pwmTC = 0, subTC = 0, mVcaTC = 0;
float pwmRC = 0, subRC = 0, vcaRC = 0; float pwmRC = 0, subRC = 0, vcaRC = 0;
int16_t lfo, pw; int16_t lfo, pw;
uint32_t lfoPhase; int16_t lfoPhase;
uint8_t lfoState = 0;
uint16_t lfoRate;
uint32_t noiseRNG = 1; uint32_t noiseRNG = 1;
@ -153,11 +156,11 @@ class Voice {
uint8_t pulseStage = 1; // pulse wave phase uint8_t pulseStage = 1; // pulse wave phase
float subosc = 1; // sub oscillator flipflop output float subosc = 1; // sub oscillator flipflop output
uint8_t envPhase = 0; uint8_t envPhase = 0; // current running state of envelope
int16_t env = 0; // output amplitude int16_t env = 0; // calculated envelope amount
uint16_t vcfCut; int16_t vcfCut; // calculated cutoff to filter
int16_t vcaEnv; int16_t vcaEnv; // calculated level to VCA (env/gate)
float vcaRC = 0, vcfRC = 0; float vcaRC = 0, vcfRC = 0; // RC circuit state values
uint8_t note = 0; uint8_t note = 0;

View File

@ -80,16 +80,14 @@ void Peacock::run(const float**, float** outputs, uint32_t frames, const MidiEve
while (framePos < frames) { while (framePos < frames) {
if (blockLeft == 0) { if (blockLeft == 0) {
// no more samples to calculate in this update period // no more samples to calculate in this update period
blockLeft = sampleRate / 238; // update rate in Hz blockLeft = sampleRate / 233.5; // update rate in Hz, measured
runMidi(midiEvents, midiEventCount, framePos + blockLeft); runMidi(midiEvents, midiEventCount, framePos + blockLeft);
m->run(voice, blockLeft);
} }
// 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;
// update the module board for this block
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++) {
voice[i].run(m, outputs[0], framePos, sizeThisTime); voice[i].run(m, outputs[0], framePos, sizeThisTime);

View File

@ -258,15 +258,17 @@ 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 repaint();
break; break;
case pSqr: case pSqr:
sw1 &= 0xf7; sw1 &= 0xf7;
sw1 |= ((value >= 0.5)) << 3; sw1 |= ((value >= 0.5)) << 3;
repaint();
break; break;
case pSaw: case pSaw:
sw1 &= 0xef; sw1 &= 0xef;
sw1 |= (value > 0.5) << 4; sw1 |= (value > 0.5) << 4;
repaint();
break; break;
case pChorusMode: case pChorusMode:
@ -283,6 +285,8 @@ void DistrhoUIPeacock::parameterChanged(uint32_t index, float value) {
sw1 |= 0x00; sw1 |= 0x00;
break; break;
} }
repaint();
break;
} }
} }
@ -340,6 +344,7 @@ void DistrhoUIPeacock::imageButtonClicked(ImageButton* imgBtn, int) {
default: default:
break; break;
} }
repaint();
} }
void DistrhoUIPeacock::onDisplay() { void DistrhoUIPeacock::onDisplay() {

View File

@ -72,7 +72,7 @@ void Voice::run(Module* m, float* buffer, uint32_t framePos, uint32_t samples) {
float r = 5 * m->res; float r = 5 * m->res;
float amp = vcaEnv / 4096.0f; float amp = vcaEnv / 16384.0f;
for (uint32_t i = 0; i < samples; i++) { for (uint32_t i = 0; i < samples; i++) {
out = delay; out = delay;