renamed osc components for clarity

This commit is contained in:
Gordon JC Pearce 2025-01-07 14:19:50 +00:00
parent a06266892e
commit 5cc2a5c9ca

View File

@ -56,9 +56,12 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE
uint16_t i; uint16_t i;
uint32_t osc; uint32_t osc;
uint8_t lfo; uint8_t lfo;
float saw, sqr, sub;
float oct1, oct3, pwg; // oscillator outputs
float sub1, sub2; float saw, sqr, sub, pwg;
// counter bits derived from osc
float bit4, bit5, bit6, bit7, bit8, bit9;
float out, in; float out, in;
@ -97,76 +100,80 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE
// 8-bit saw scaled // 8-bit saw scaled
saw = (osc & 0xff) / 256.0f; saw = (osc & 0xff) / 256.0f;
// square scaled to 0-1, along with one and three octaves up // various counter bits scaled from 0-1
sqr = (float)(osc & 0x80) != 0; bit4 = (float)(osc & 0x010) != 0; // 3 octaves up
oct1 = (float)(osc & 0x40) != 0; bit5 = (float)(osc & 0x020) != 0; // 2 octaves up
oct3 = (float)(osc & 0x10) != 0; bit6 = (float)(osc & 0x040) != 0; // 1 octave up
sub1 = (float)(osc & 0x40) != 0; bit7 = (float)(osc & 0x080) != 0; // square wave, top bit of saw counter
sub2 = (float)(osc & 0x10) != 0; bit8 = (float)(osc & 0x100) != 0; // 1 octave down
bit9 = (float)(osc & 0x200) != 0; // 2 octaves down
// pulse width gate // pulse width gate
// lower seven bits of the saw osc, compared with PW setting // lower seven bits of the saw osc, compared with PW setting
pwg = (float)((osc & 0x7f) >= pw) != 0; pwg = (float)((osc & 0x7f) >= pw) != 0;
// calculate the oscillator output // calculate the oscillator output
// because all the "bits" are scaled to floats from 0 to 1
// we can just multiply them
// in the real chip it probably uses AND gates to control outputs
// including an AND gate driving the DAC latch pin
switch (submode) { switch (submode) {
case 0: case 0:
sub = sub1; default:
sub = bit8;
break; // one octave down break; // one octave down
case 1: case 1:
sub = sub1 * sqr; sub = bit8 * bit7; // one octave down, 25% PW
break; // saw is fine, do nothing break;
case 2: case 2:
saw *= oct1; // pulsed sub = bit8 * bit6; // one octave down modulated by one octave up
break; break;
case 3: case 3:
saw *= pwg; // pwm sub = bit8 * bit5; // one octave down modulated by two octaves up
break; break;
case 4: case 4:
saw *= oct3; // oct3 pulse sub = bit9; // two octaves down
break; break;
case 5: case 5:
saw *= oct1 * oct3; // both pulse sub = bit9 * bit8; // two octaves down, 25% PW
break; break;
} }
switch (sqrmode) { switch (sqrmode) {
case 0: case 0:
case 4: case 4:
default:
sqr = 0; // oscillator is off sqr = 0; // oscillator is off
break; break;
case 1: // do nothing, sqr is fine case 1: // fundamental
sqr = bit7;
break; break;
case 2: case 2:
sqr *= oct1; // 25% pulse sqr = bit7 * bit6; // 25% pulse
break; break;
case 3: case 3:
sqr *= pwg; // pwm sqr = bit7 * pwg; // pwm
break; break;
} }
switch (sawmode) { switch (sawmode) {
case 0: case 0:
default:
saw = 0; saw = 0;
break; // oscillator is off break; // oscillator is off
case 1: case 1:
break; // saw is fine, do nothing break; // saw is fine, do nothing
case 2: case 2:
saw *= oct1; // pulsed saw *= bit6; // pulsed
break; break;
case 3: case 3:
saw *= pwg; // pwm saw *= pwg; // pwm
break; break;
case 4: case 4:
saw *= oct3; // oct3 pulse saw *= bit4; // oct3 pulse
break; break;
case 5: case 5:
saw *= oct1 * oct3; // both pulse saw *= bit6 * bit4; // both pulse
break; break;
} }
@ -174,7 +181,7 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE
// mix the signals, probably done with some resistors in the chip // mix the signals, probably done with some resistors in the chip
in = (saw * 0.8) + (sqr * 0.63); // scaled similarly to Juno 106 in = (sub * sublevel) + (saw * 0.8) + (sqr * 0.63); // scaled similarly to Juno 106
// DC removal highpass filter // DC removal highpass filter
// this is very approximately 6Hz at 44.1kHz and 48kHz // this is very approximately 6Hz at 44.1kHz and 48kHz
@ -183,7 +190,7 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE
hpfx = in; hpfx = in;
hpfy = out; hpfy = out;
outputs[0][i] = out; outputs[0][i] = out*0.5;
} }
// printf("%f %f\n", sqr, saw); // printf("%f %f\n", sqr, saw);
} }