formatting cleanup
This commit is contained in:
parent
36c27f14d8
commit
ad7b7f4405
|
|
@ -48,6 +48,7 @@ class Module {
|
|||
|
||||
float saw = 0, square = 0, sub = 0, noise = 0;
|
||||
|
||||
/*
|
||||
#if 0
|
||||
struct {
|
||||
uint8_t lfoRate = 0x58;
|
||||
|
|
@ -92,6 +93,29 @@ class Module {
|
|||
uint8_t switch2 = 0x1d;
|
||||
} patchRam;
|
||||
#endif
|
||||
*/
|
||||
|
||||
struct {
|
||||
uint8_t lfoRate = 0x58;
|
||||
uint8_t lfoDelay = 0x00;
|
||||
uint8_t vcoLfo = 0x00;
|
||||
uint8_t pwmLfo = 0x00;
|
||||
uint8_t noise = 0x00;
|
||||
uint8_t vcfFreq = 0x00; // 1c; // 0x3f80
|
||||
uint8_t vcfReso = 0x7f;
|
||||
uint8_t vcfEnv = 0x7f; // 4e;
|
||||
uint8_t vcfLfo = 0x00;
|
||||
uint8_t vcfKey = 0x00; // 47;
|
||||
uint8_t vca = 0x20;
|
||||
uint8_t env_a = 0x00;
|
||||
uint8_t env_d = 0x5c;
|
||||
uint8_t env_s = 0x00; // 0x3f80
|
||||
uint8_t env_r = 0x3c;
|
||||
uint8_t sub = 0x7f;
|
||||
uint8_t switch1 = 0x3a;
|
||||
uint8_t switch2 = 0x19;
|
||||
} patchRam;
|
||||
|
||||
Chorus* chorus;
|
||||
|
||||
float vcaTC;
|
||||
|
|
@ -128,7 +152,7 @@ class Voice {
|
|||
|
||||
uint8_t envPhase = 0;
|
||||
int16_t env = 0; // output amplitude
|
||||
int16_t vcfCut;
|
||||
uint16_t vcfCut;
|
||||
int16_t vcaEnv;
|
||||
float vcaRC = 0, vcfRC = 0;
|
||||
|
||||
|
|
@ -137,6 +161,7 @@ class Voice {
|
|||
// filter
|
||||
float y0 = 0, y1 = 0, y2 = 0, y3 = 0;
|
||||
double s[4] = {0, 0, 0, 0};
|
||||
float zi = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -50,45 +50,26 @@ void Voice::off() {
|
|||
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);
|
||||
|
||||
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) {
|
||||
// carry out per-voice calculations for each block of samples
|
||||
float out, t, fb;
|
||||
|
||||
double zi;
|
||||
|
||||
|
||||
// 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 = cut / (1 + cut); // correct tuning warp
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
// if (cut > 0.7) cut = 0.7;
|
||||
double r = 5 * m->res;
|
||||
|
||||
float amp = vcaEnv / 4096.0f;
|
||||
|
||||
|
|
@ -128,7 +109,7 @@ double zi;
|
|||
delay += m->subBuf[i] * subosc;
|
||||
|
||||
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
|
||||
vcfRC = (cut - vcfRC) * m->vcaTC + vcfRC;
|
||||
|
|
@ -157,8 +138,11 @@ double zi;
|
|||
//------------------------------------------------------------------------------ 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 = 0.5 * (out + zi);
|
||||
zi = out;
|
||||
|
||||
// double ih = out;
|
||||
|
||||
|
|
@ -196,14 +180,17 @@ double zi;
|
|||
|
||||
// out[n] = y3;
|
||||
// }
|
||||
// out *= 0.1;
|
||||
|
||||
out = y3;
|
||||
|
||||
#else
|
||||
|
||||
for (uint8_t ovs = 0; ovs < 4; ovs++) {
|
||||
out *= 0.5;
|
||||
for (uint8_t ovs = 0; ovs < 2; ovs++) {
|
||||
fb = y3;
|
||||
// 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;
|
||||
// fb = 1.5 * fb - 0.5 * fb * fb * fb;
|
||||
|
|
@ -216,7 +203,7 @@ double zi;
|
|||
}
|
||||
#endif
|
||||
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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue