Compare commits
No commits in common. "e3c54e3ef19e1b0e784ef553f60aaf93dbe61e3f" and "8c2263c129cd63c08442d7071dd5b5be1c69a15f" have entirely different histories.
e3c54e3ef1
...
8c2263c129
|
|
@ -140,7 +140,7 @@ void Chorus::setHpf(uint8_t mode) {
|
||||||
break;
|
break;
|
||||||
case 0x18:
|
case 0x18:
|
||||||
hpCut = 1 - exp(-6.283 * 85 / sampleRate);
|
hpCut = 1 - exp(-6.283 * 85 / sampleRate);
|
||||||
hpGain = 1.0;
|
hpGain = 1.707;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ void Module::genNoise() {
|
||||||
for (uint32_t i = 0; i < bufferSize; i++) {
|
for (uint32_t i = 0; i < bufferSize; i++) {
|
||||||
noiseRNG *= 0x8088405;
|
noiseRNG *= 0x8088405;
|
||||||
noiseRNG++;
|
noiseRNG++;
|
||||||
noiseBuf[i] = 1 - (noiseRNG & 0xffff) / 32768.0f;
|
noiseBuf[i] = 2 - (noiseRNG & 0xffff) / 16384.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,41 +58,32 @@ void Module::lfoRampOn() {
|
||||||
|
|
||||||
void Module::runLFO() {
|
void Module::runLFO() {
|
||||||
if (lfoDelayState == 1) {
|
if (lfoDelayState == 1) {
|
||||||
lfoDelayTimer += attackTable[patchRam.lfoDelay];
|
lfoDelayTimer += lfoDelayTable[patchRam.lfoDelay >> 4];
|
||||||
if (lfoDelayTimer > 0x3fff) lfoDelayState = 2;
|
if (lfoDelayTimer & 0xc000) lfoDelayState = 2;
|
||||||
}
|
}
|
||||||
if ((lfoDelayState == 2)) {
|
if ((lfoDelayState == 2)) {
|
||||||
lfoDelay += lfoDelayTable[patchRam.lfoDelay >> 4];
|
lfoDelay += attackTable[patchRam.lfoDelay];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lfoDelay > 0xff) {
|
if (lfoDelay & 0xc000) {
|
||||||
lfoDelayState = 0;
|
lfoDelayState = 0;
|
||||||
lfoDelay = 0xff;
|
lfoDelay = 0x3fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
lfoRate = lfoRateTable[patchRam.lfoRate]; // FIXME move to parameters
|
lfoPhase += lfoRateTable[patchRam.lfoRate];
|
||||||
|
if (lfoPhase & 0x4000)
|
||||||
|
lfo = 0x1fff - (lfoPhase & 0x3fff);
|
||||||
|
else
|
||||||
|
lfo = (lfoPhase & 0x3fff) - 0x1fff;
|
||||||
|
|
||||||
lfoPhase += (lfoState & 0x01) ? -lfoRate : lfoRate;
|
pw = 0x3fff - (((0x2000 + lfo) * patchRam.pwmLfo) >> 7);
|
||||||
if (lfoPhase > 0x1fff) {
|
pw = (patchRam.switch2 & 0x01) ? 0x3fff - (patchRam.pwmLfo << 7) : pw;
|
||||||
lfoPhase = 0x1fff;
|
lfo = (lfo * lfoDelay) >> 14;
|
||||||
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
|
||||||
|
|
@ -117,11 +108,10 @@ void Module::run(Voice* voices, uint32_t blockSize) {
|
||||||
|
|
||||||
runLFO();
|
runLFO();
|
||||||
|
|
||||||
// calculate "smoothed" parameters
|
float pwf = pw / 32768.0f;
|
||||||
// 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 = ((pw / 32768.0f) - pwmRC) * pwmTC + pwmRC;
|
pwmRC = (pwf - pwmRC) * pwmTC + pwmRC;
|
||||||
subRC = (sub - subRC) * vcaTC + subRC;
|
subRC = (sub - subRC) * vcaTC + subRC;
|
||||||
|
|
||||||
vcaBuf[i] = vcaRC;
|
vcaBuf[i] = vcaRC;
|
||||||
|
|
@ -131,27 +121,13 @@ void Module::run(Voice* voices, uint32_t blockSize) {
|
||||||
if (bufPtr < bufferSize) bufPtr++;
|
if (bufPtr < bufferSize) bufPtr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
lfoToVco = (lfoDepthTable[patchRam.vcoLfo] * lfoDelay) >> 8; // lookup table is 0-255
|
int16_t vcf = (patchRam.vcfEnv << 7) * ((patchRam.switch2 & 0x02) ? -1 : 1);
|
||||||
lfoToVco += /* lfo from modwheel FIXME */ 0;
|
|
||||||
if (lfoToVco > 0xff) lfoToVco = 0xff;
|
|
||||||
lfoToVco = (lfo * lfoToVco) >> 11; // 8 for normalisation plus three additional DSLR EA
|
|
||||||
|
|
||||||
lfoToVcf = (patchRam.vcfLfo * lfoDelay) >> 7; // value is 0-127
|
int16_t pitchBase = 0x1818;
|
||||||
lfoToVcf = (lfo * lfoToVcf) >> 9; // 8 for normalisation plus one additional DSLR EA
|
pitchBase += (lfo * lfoDepthTable[patchRam.vcoLfo]) >> 11;
|
||||||
|
|
||||||
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++) {
|
||||||
// run one step of the envelope
|
// maybe move all this into voice.cpp FIXME
|
||||||
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
|
||||||
|
|
@ -170,20 +146,21 @@ void Module::run(Voice* voices, uint32_t blockSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pitch
|
// pitch
|
||||||
uint16_t pitch = pitchBase + (v->note << 8);
|
// FIXME clean this all up a bit
|
||||||
uint8_t semi = pitch >> 8;
|
int16_t pitch = pitchBase + (v->note << 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); // interpolated pitch from table
|
int16_t px = ((p2 - p1) * frac + p1);
|
||||||
|
|
||||||
// octave divider
|
|
||||||
px *= (patchRam.switch1 & 0x07);
|
px *= (patchRam.switch1 & 0x07);
|
||||||
|
|
||||||
v->omega = px / (sampleRate * 8.0f); // FIXME recalculate table using 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 = vcfBase + (((v->env * patchRam.vcfEnv)>>7) * ((patchRam.switch1 & 0x02) ? -1 : 1));
|
v->vcfCut = (patchRam.vcfFreq << 7) + ((vcf * v->env) >> 14);
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,9 +130,7 @@ class Module {
|
||||||
float pwmRC = 0, subRC = 0, vcaRC = 0;
|
float pwmRC = 0, subRC = 0, vcaRC = 0;
|
||||||
|
|
||||||
int16_t lfo, pw;
|
int16_t lfo, pw;
|
||||||
int16_t lfoPhase;
|
uint32_t lfoPhase;
|
||||||
uint8_t lfoState = 0;
|
|
||||||
uint16_t lfoRate;
|
|
||||||
|
|
||||||
uint32_t noiseRNG = 1;
|
uint32_t noiseRNG = 1;
|
||||||
|
|
||||||
|
|
@ -156,11 +154,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; // current running state of envelope
|
uint8_t envPhase = 0;
|
||||||
int16_t env = 0; // calculated envelope amount
|
int16_t env = 0; // output amplitude
|
||||||
int16_t vcfCut; // calculated cutoff to filter
|
uint16_t vcfCut;
|
||||||
int16_t vcaEnv; // calculated level to VCA (env/gate)
|
int16_t vcaEnv;
|
||||||
float vcaRC = 0, vcfRC = 0; // RC circuit state values
|
float vcaRC = 0, vcfRC = 0;
|
||||||
|
|
||||||
uint8_t note = 0;
|
uint8_t note = 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue