From 5cc2a5c9caaeb810c95596d3b01f7650059e12d3 Mon Sep 17 00:00:00 2001 From: Gordon JC Pearce Date: Tue, 7 Jan 2025 14:19:50 +0000 Subject: [PATCH] renamed osc components for clarity --- plugin/alphaosc.cpp | 65 +++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/plugin/alphaosc.cpp b/plugin/alphaosc.cpp index 7bb0562..af9afed 100644 --- a/plugin/alphaosc.cpp +++ b/plugin/alphaosc.cpp @@ -56,10 +56,13 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE uint16_t i; uint32_t osc; uint8_t lfo; - float saw, sqr, sub; - float oct1, oct3, pwg; - float sub1, sub2; + // oscillator outputs + float saw, sqr, sub, pwg; + + // counter bits derived from osc + float bit4, bit5, bit6, bit7, bit8, bit9; + float out, in; // steeply "logarithmic" curve similar to the Juno 106 LFO rate curve @@ -97,76 +100,80 @@ void AlphaOsc::run(const float **, float **outputs, uint32_t frames, const MidiE // 8-bit saw scaled saw = (osc & 0xff) / 256.0f; - // square scaled to 0-1, along with one and three octaves up - sqr = (float)(osc & 0x80) != 0; - oct1 = (float)(osc & 0x40) != 0; - oct3 = (float)(osc & 0x10) != 0; - sub1 = (float)(osc & 0x40) != 0; - sub2 = (float)(osc & 0x10) != 0; - - + // various counter bits scaled from 0-1 + bit4 = (float)(osc & 0x010) != 0; // 3 octaves up + bit5 = (float)(osc & 0x020) != 0; // 2 octaves up + bit6 = (float)(osc & 0x040) != 0; // 1 octave up + bit7 = (float)(osc & 0x080) != 0; // square wave, top bit of saw counter + bit8 = (float)(osc & 0x100) != 0; // 1 octave down + bit9 = (float)(osc & 0x200) != 0; // 2 octaves down // pulse width gate // lower seven bits of the saw osc, compared with PW setting pwg = (float)((osc & 0x7f) >= pw) != 0; - - // 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) { case 0: - sub = sub1; + default: + sub = bit8; break; // one octave down case 1: - sub = sub1 * sqr; - break; // saw is fine, do nothing + sub = bit8 * bit7; // one octave down, 25% PW + break; case 2: - saw *= oct1; // pulsed + sub = bit8 * bit6; // one octave down modulated by one octave up break; case 3: - saw *= pwg; // pwm + sub = bit8 * bit5; // one octave down modulated by two octaves up break; case 4: - saw *= oct3; // oct3 pulse + sub = bit9; // two octaves down break; case 5: - saw *= oct1 * oct3; // both pulse + sub = bit9 * bit8; // two octaves down, 25% PW break; } switch (sqrmode) { case 0: case 4: + default: sqr = 0; // oscillator is off break; - case 1: // do nothing, sqr is fine + case 1: // fundamental + sqr = bit7; break; case 2: - sqr *= oct1; // 25% pulse + sqr = bit7 * bit6; // 25% pulse break; case 3: - sqr *= pwg; // pwm + sqr = bit7 * pwg; // pwm break; } switch (sawmode) { case 0: + default: saw = 0; break; // oscillator is off case 1: break; // saw is fine, do nothing case 2: - saw *= oct1; // pulsed + saw *= bit6; // pulsed break; case 3: saw *= pwg; // pwm break; case 4: - saw *= oct3; // oct3 pulse + saw *= bit4; // oct3 pulse break; case 5: - saw *= oct1 * oct3; // both pulse + saw *= bit6 * bit4; // both pulse 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 - 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 // 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; hpfy = out; - outputs[0][i] = out; + outputs[0][i] = out*0.5; } // printf("%f %f\n", sqr, saw); }