formatting cleanup
This commit is contained in:
parent
36c27f14d8
commit
ad7b7f4405
|
|
@ -48,50 +48,74 @@ class Module {
|
||||||
|
|
||||||
float saw = 0, square = 0, sub = 0, noise = 0;
|
float saw = 0, square = 0, sub = 0, noise = 0;
|
||||||
|
|
||||||
#if 0
|
/*
|
||||||
struct {
|
#if 0
|
||||||
uint8_t lfoRate = 0x58;
|
struct {
|
||||||
uint8_t lfoDelay = 0x00;
|
uint8_t lfoRate = 0x58;
|
||||||
uint8_t vcoLfo = 0x00;
|
uint8_t lfoDelay = 0x00;
|
||||||
uint8_t pwmLfo = 0x3b;
|
uint8_t vcoLfo = 0x00;
|
||||||
uint8_t noise = 0x00;
|
uint8_t pwmLfo = 0x3b;
|
||||||
uint8_t vcfFreq = 0x25; // 1c; // 0x3f80
|
uint8_t noise = 0x00;
|
||||||
uint8_t vcfReso = 0x6a;
|
uint8_t vcfFreq = 0x25; // 1c; // 0x3f80
|
||||||
uint8_t vcfEnv = 0x25; // 4e;
|
uint8_t vcfReso = 0x6a;
|
||||||
uint8_t vcfLfo = 0x00;
|
uint8_t vcfEnv = 0x25; // 4e;
|
||||||
uint8_t vcfKey = 0x00; // 47;
|
uint8_t vcfLfo = 0x00;
|
||||||
uint8_t vca = 0x35;
|
uint8_t vcfKey = 0x00; // 47;
|
||||||
uint8_t env_a = 0x00;
|
uint8_t vca = 0x35;
|
||||||
uint8_t env_d = 0x3c;
|
uint8_t env_a = 0x00;
|
||||||
uint8_t env_s = 0x00; // 0x3f80
|
uint8_t env_d = 0x3c;
|
||||||
uint8_t env_r = 0x3c;
|
uint8_t env_s = 0x00; // 0x3f80
|
||||||
uint8_t sub = 0x7f;
|
uint8_t env_r = 0x3c;
|
||||||
uint8_t switch1 = 0x4a;
|
uint8_t sub = 0x7f;
|
||||||
uint8_t switch2 = 0x18;
|
uint8_t switch1 = 0x4a;
|
||||||
} patchRam;
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
#else
|
|
||||||
struct {
|
struct {
|
||||||
uint8_t lfoRate = 0x40;
|
uint8_t lfoRate = 0x58;
|
||||||
uint8_t lfoDelay = 0x00;
|
uint8_t lfoDelay = 0x00;
|
||||||
uint8_t vcoLfo = 0x00;
|
uint8_t vcoLfo = 0x00;
|
||||||
uint8_t pwmLfo = 0x00;
|
uint8_t pwmLfo = 0x00;
|
||||||
uint8_t noise = 0x01;
|
uint8_t noise = 0x00;
|
||||||
uint8_t vcfFreq = 0x31;
|
uint8_t vcfFreq = 0x00; // 1c; // 0x3f80
|
||||||
uint8_t vcfReso = 0x7f;
|
uint8_t vcfReso = 0x7f;
|
||||||
uint8_t vcfEnv = 0x00;
|
uint8_t vcfEnv = 0x7f; // 4e;
|
||||||
uint8_t vcfLfo = 0x00;
|
uint8_t vcfLfo = 0x00;
|
||||||
uint8_t vcfKey = 0x7f;
|
uint8_t vcfKey = 0x00; // 47;
|
||||||
uint8_t vca = 0x40;
|
uint8_t vca = 0x20;
|
||||||
uint8_t env_a = 0x00;
|
uint8_t env_a = 0x00;
|
||||||
uint8_t env_d = 0x00;
|
uint8_t env_d = 0x5c;
|
||||||
uint8_t env_s = 0x00; // 0x3f80
|
uint8_t env_s = 0x00; // 0x3f80
|
||||||
uint8_t env_r = 0x00;
|
uint8_t env_r = 0x3c;
|
||||||
uint8_t sub = 0x00;
|
uint8_t sub = 0x7f;
|
||||||
uint8_t switch1 = 0x22;
|
uint8_t switch1 = 0x3a;
|
||||||
uint8_t switch2 = 0x1d;
|
uint8_t switch2 = 0x19;
|
||||||
} patchRam;
|
} patchRam;
|
||||||
#endif
|
|
||||||
Chorus* chorus;
|
Chorus* chorus;
|
||||||
|
|
||||||
float vcaTC;
|
float vcaTC;
|
||||||
|
|
@ -128,7 +152,7 @@ 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 vcaRC = 0, vcfRC = 0;
|
float vcaRC = 0, vcfRC = 0;
|
||||||
|
|
||||||
|
|
@ -137,6 +161,7 @@ class Voice {
|
||||||
// filter
|
// filter
|
||||||
float y0 = 0, y1 = 0, y2 = 0, y3 = 0;
|
float y0 = 0, y1 = 0, y2 = 0, y3 = 0;
|
||||||
double s[4] = {0, 0, 0, 0};
|
double s[4] = {0, 0, 0, 0};
|
||||||
|
float zi = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
121
plugin/voice.cpp
121
plugin/voice.cpp
|
|
@ -41,7 +41,7 @@ Voice::Voice() {
|
||||||
|
|
||||||
void Voice::on(uint8_t midiNote) {
|
void Voice::on(uint8_t midiNote) {
|
||||||
while (midiNote < 24) midiNote += 12;
|
while (midiNote < 24) midiNote += 12;
|
||||||
while (midiNote > 108) midiNote -=12;
|
while (midiNote > 108) midiNote -= 12;
|
||||||
note = midiNote - 24;
|
note = midiNote - 24;
|
||||||
envPhase = 1;
|
envPhase = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -50,45 +50,26 @@ void Voice::off() {
|
||||||
envPhase = 0;
|
envPhase = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// tanh(x)/x approximation, flatline at very high inputs
|
// tanh(x)/x approximation, flatline at very high inputs
|
||||||
// so might not be safe for very large feedback gains
|
// so might not be safe for very large feedback gains
|
||||||
// [limit is 1/15 so very large means ~15 or +23dB]
|
// [limit is 1/15 so very large means ~15 or +23dB]
|
||||||
|
|
||||||
|
|
||||||
double tanhXdX(double x) {
|
double tanhXdX(double x) {
|
||||||
|
float s = 0.0333, d = 30.0;
|
||||||
|
return 1.0f - s * (d + 1.0f) * x * x / (d + x * x);
|
||||||
|
|
||||||
return 1-0.1*abs(x);
|
|
||||||
double a = x*x;
|
|
||||||
// IIRC I got this as Pade-approx for tanh(sqrt(x))/sqrt(x)
|
|
||||||
return ((a + 105)*a + 945) / ((15*a + 420)*a + 945);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
double zi;
|
|
||||||
|
|
||||||
|
|
||||||
// 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 = M_PI * cut / sampleRate;
|
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;
|
||||||
// printf("%f\n", cut);
|
|
||||||
|
|
||||||
//if (cut > 0.5) cut = 0.5;
|
|
||||||
|
|
||||||
// double f = tan(cut);
|
|
||||||
|
|
||||||
|
|
||||||
//printf("cut = %4f f = %4f\n", cut, f);
|
|
||||||
|
|
||||||
double r = (40.0/9.0) * m->res;
|
|
||||||
|
|
||||||
|
|
||||||
float amp = vcaEnv / 4096.0f;
|
float amp = vcaEnv / 4096.0f;
|
||||||
|
|
||||||
|
|
@ -125,45 +106,48 @@ double zi;
|
||||||
// FIXME DC offset removal
|
// FIXME DC offset removal
|
||||||
delay += m->saw * (1 - (2 * theta));
|
delay += m->saw * (1 - (2 * theta));
|
||||||
delay += m->square * ((pulseStage ? -1.f : 1.f) - m->pwmBuf[i] + 0.5);
|
delay += m->square * ((pulseStage ? -1.f : 1.f) - m->pwmBuf[i] + 0.5);
|
||||||
delay += m->subBuf[i] * subosc ;
|
delay += m->subBuf[i] * subosc;
|
||||||
|
|
||||||
out += m->noise * (0.8 - 1.6 * (rand() & 0xffff) / 65536.0);
|
out += m->noise * (0.8 - 1.6 * (rand() & 0xffff) / 65536.0);
|
||||||
out *= 0.01;
|
// out *= 0.1;
|
||||||
|
|
||||||
// same time constant for both VCF and VCF RC circuits
|
// same time constant for both VCF and VCF RC circuits
|
||||||
vcfRC = (cut - vcfRC) * m->vcaTC + vcfRC;
|
vcfRC = (cut - vcfRC) * m->vcaTC + vcfRC;
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
//// LICENSE TERMS: Copyright 2012 Teemu Voipio
|
//// LICENSE TERMS: Copyright 2012 Teemu Voipio
|
||||||
//
|
//
|
||||||
// You can use this however you like for pretty much any purpose,
|
// 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.
|
// as long as you don't claim you wrote it. There is no warranty.
|
||||||
//
|
//
|
||||||
// Distribution of substantial portions of this code in source form
|
// Distribution of substantial portions of this code in source form
|
||||||
// must include this copyright notice and list of conditions.
|
// must include this copyright notice and list of conditions.
|
||||||
//
|
//
|
||||||
|
|
||||||
// input delay and state for member variables
|
// input delay and state for member variables
|
||||||
|
|
||||||
// cutoff as normalized frequency (eg 0.5 = Nyquist)
|
// cutoff as normalized frequency (eg 0.5 = Nyquist)
|
||||||
// resonance from 0 to 1, self-oscillates at settings over 0.9
|
// resonance from 0 to 1, self-oscillates at settings over 0.9
|
||||||
//void transistorLadder(
|
// void transistorLadder(
|
||||||
// double cutoff, double resonance,
|
// double cutoff, double resonance,
|
||||||
// double * in, double * out, unsigned nsamples)
|
// double * in, double * out, unsigned nsamples)
|
||||||
//{
|
//{
|
||||||
// tuning and feedback
|
// tuning and feedback
|
||||||
|
|
||||||
//------------------------------------------------------------------------------ sample loop
|
//------------------------------------------------------------------------------ sample loop
|
||||||
//for(unsigned n = 0; n < nsamples; ++n)
|
// for(unsigned n = 0; n < nsamples; ++n)
|
||||||
//{
|
//{
|
||||||
|
|
||||||
|
out *= 0.025;
|
||||||
// input with half delay, for non-linearities
|
// input with half delay, for non-linearities
|
||||||
double ih = 0.5 * (out + zi); zi = out;
|
double ih = 0.5 * (out + zi);
|
||||||
|
zi = out;
|
||||||
|
|
||||||
//double ih = out;
|
// double ih = out;
|
||||||
|
|
||||||
// evaluate the non-linear gains
|
// evaluate the non-linear gains
|
||||||
double t0 = tanhXdX((ih * (r+1))- r * s[3]);
|
double t0 = tanhXdX((ih * (r + 1)) - r * s[3]);
|
||||||
|
|
||||||
double t1 = tanhXdX(s[0]);
|
double t1 = tanhXdX(s[0]);
|
||||||
double t2 = tanhXdX(s[1]);
|
double t2 = tanhXdX(s[1]);
|
||||||
|
|
@ -173,37 +157,40 @@ double zi;
|
||||||
double f = vcfRC;
|
double f = vcfRC;
|
||||||
|
|
||||||
// g# the denominators for solutions of individual stages
|
// g# the denominators for solutions of individual stages
|
||||||
double g0 = 1 / (1 + f*t1), g1 = 1 / (1 + f*t2);
|
double g0 = 1 / (1 + f * t1), g1 = 1 / (1 + f * t2);
|
||||||
double g2 = 1 / (1 + f*t3), g3 = 1 / (1 + f*t4);
|
double g2 = 1 / (1 + f * t3), g3 = 1 / (1 + f * t4);
|
||||||
|
|
||||||
// f# are just factored out of the feedback solution
|
// 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;
|
double f3 = f * t3 * g3, f2 = f * t2 * g2 * f3, f1 = f * t1 * g1 * f2, f0 = f * t0 * g0 * f1;
|
||||||
|
|
||||||
// solve feedback
|
// solve feedback
|
||||||
double y3 = (g3*s[3] + f3*g2*s[2] + f2*g1*s[1] + f1*g0*s[0] + f0*out) / (1 + r*f0);
|
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)
|
// then solve the remaining outputs (with the non-linear gains here)
|
||||||
double xx = t0*((out * (r+1)) - r*y3);
|
double xx = t0 * ((out * (r + 1)) - r * y3);
|
||||||
double y0 = t1*g0*(s[0] + f*xx);
|
double y0 = t1 * g0 * (s[0] + f * xx);
|
||||||
double y1 = t2*g1*(s[1] + f*y0);
|
double y1 = t2 * g1 * (s[1] + f * y0);
|
||||||
double y2 = t3*g2*(s[2] + f*y1);
|
double y2 = t3 * g2 * (s[2] + f * y1);
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
s[0] += 2*f * (xx - y0);
|
s[0] += 2 * f * (xx - y0);
|
||||||
s[1] += 2*f * (y0 - y1);
|
s[1] += 2 * f * (y0 - y1);
|
||||||
s[2] += 2*f * (y1 - y2);
|
s[2] += 2 * f * (y1 - y2);
|
||||||
s[3] += 2*f * (y2 - t4*y3);
|
s[3] += 2 * f * (y2 - t4 * y3);
|
||||||
|
|
||||||
//out[n] = y3;
|
// out[n] = y3;
|
||||||
// }
|
// }
|
||||||
|
// out *= 0.1;
|
||||||
|
|
||||||
|
out = y3;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
for (uint8_t ovs = 0; ovs < 4; ovs++) {
|
out *= 0.5;
|
||||||
|
for (uint8_t ovs = 0; ovs < 2; ovs++) {
|
||||||
fb = y3;
|
fb = y3;
|
||||||
// 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;
|
||||||
|
|
@ -216,7 +203,7 @@ double zi;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
vcaRC = (amp - vcaRC) * m->vcaTC + vcaRC;
|
vcaRC = (amp - vcaRC) * m->vcaTC + vcaRC;
|
||||||
buffer[i] += 1 * m->vcaBuf[i] * vcaRC * y3;
|
buffer[i] += m->vcaBuf[i] * vcaRC * out;
|
||||||
|
|
||||||
lastpw = m->pwmBuf[i];
|
lastpw = m->pwmBuf[i];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue