guitarDualOscV

this is the module to use with the guitarTable module in a polyphonic synthesizer. The guitarTable module will create a complex waveform and this module is able to play that waveform. This was needed, otherwise, in a polyphonic setting, each module would create it's own table, filling up the available memory really quickly. -features pulsewidth, start-shift (start) and pick-up (mod) modulation, all extern controllable. (though these are all only approximations to the changes made by the "fixed settings", reshaping the wavetable)
Author: Remco van der Most
License: BSD
Github: sss/osc/guitarDualOscV.axo

Inlets

frac32.bipolar pitch

frac32 pwm

frac32 mod

frac32 start

frac32 sync

frac32 volEnv

int32 rateM

int32 rateD

int32 preset1

int32 preset2

Outlets

frac32buffer.bipolar sine wave

Parameters

bool32.tgl link

frac32.s.map.pitch pitch

int32 harm2nd

int32 rateM

int32 rateD

int32 preset1

int32 preset2

frac32.u.map pwm

frac32.u.map mod

frac32.u.map start

Attributes

objref table

Declaration
uint32_t phase;
int i;
uint32_t LFO;
int32_t rate;
float32_t A;
float32_t B;
uint32_t PM;
uint32_t Pm;
int32_t prev1;
int32_t prev2;
int32_t prev3;
float32_t prev4;
float32_t prev5;
int32_t step1;
int32_t step2;
int32_t step3;
float32_t step4;
float32_t step5;
int strig;
uint32_t count;
uint32_t timer;
int32_t wave;
int32_t Prev;
int32_t Step;
int32_t val;
int32_t Freq;
Init
phase = 0;
Control Rate
int32_t freq;
MTOFEXTENDED(param_pitch + inlet_pitch, freq)
PM = param_pwm + inlet_pwm;
PM = PM > 0 ? PM : -PM;
PM = PM & ((1 << 28) - 1);
PM = PM > (1 << 27) ? (2 << 27) - PM : PM;
PM = __USAT(PM + 1, 27) << 4;
A = ((float32_t)(1 << 31)) / ((float32_t)(PM << 1));
B = ((float32_t)(1 << 31)) / ((float32_t)(((1 << 31) - PM) << 1));
PM = PM << 1;
int32_t mod1 = param_mod + inlet_mod;
mod1 = mod1 > 0 ? mod1 : -mod1;
mod1 = mod1 & ((1 << 28) - 1);
mod1 = mod1 > (1 << 27) ? (2 << 27) - mod1 : mod1;
mod1 = mod1 << 4;
int32_t mod2;
mod2 = mod1 * 3;

int32_t Start = param_start + inlet_start;
Start = Start > 0 ? Start : -Start;
Start = Start & ((1 << 28) - 1);
Start = Start > (1 << 27) ? (2 << 27) - Start : Start;

step1 = ((((int32_t)(PM)) + (1 << 31)) - prev1) >> 4;
int32_t i1 = prev1;
prev1 = ((int32_t)(PM)) + (1 << 31);

step2 = (mod1 - prev2) >> 4;
int32_t i2 = prev2;
prev2 = mod1;

step3 = (Start - prev3) >> 4;
int32_t i3 = prev3;
prev3 = Start;

step4 = (A - prev4) / (float32_t)16;
float32_t i4 = prev4;
prev4 = A;

step5 = (B - prev5) / (float32_t)16;
float32_t i5 = prev5;
prev5 = B;

int rateM = param_rateM + inlet_rateM;
int rateD = param_rateD + inlet_rateD;
int preset1 = param_preset1 + inlet_preset1;

int preset2 = param_preset2 + inlet_preset2 + preset1 * param_link;
preset2 = preset2 - (preset2 / attr_table.presets) * attr_table.presets;
preset2 = preset2 < 0 ? preset2 + attr_table.presets : preset2;
preset2 = preset2 * attr_table.LENGTH;

preset1 = preset1 - (preset1 / attr_table.presets) * attr_table.presets;
preset1 = preset1 < 0 ? preset1 + attr_table.presets : preset1;
preset1 = preset1 * attr_table.LENGTH;

Step = (inlet_volEnv - Prev) >> 4;
int32_t I = Prev;
Prev = inlet_volEnv;
Audio Rate
if ((inlet_sync > 0) && !strig) {
  timer = ((1 << 31) / count) << 1;
  count = 0;
  strig = 1;
} else if (inlet_sync <= 0) {
  strig = 0;
}
count += 1;

uint32_t Phase;
phase += freq;
LFO += timer * rateM / rateD;
uint32_t PHase = phase;
if (phase < (1 << 31)) {
  PHase = ___SMMUL(phase, i3 << 4) << 2;
} else {
  PHase = (___SMMUL(phase, ((1 << 27) - i3) << 4) << 2);
}

if (PHase < Pm) {
  Phase = (1 << 31) + ((int32_t)(PHase * i4)) + i2;
}
if (PHase >= Pm) {
  Phase = ((uint32_t)((PHase - Pm) * i5 - (1 << 31))) + i2 + (1 << 31);
}

wave =
    attr_table
        .array[((Phase >> 32 - attr_table.LENGTHPOW) & attr_table.LENGTHMASK) +
               preset1];
wave +=
    attr_table
        .array[((((Phase * param_harm2nd) + LFO) >> 32 - attr_table.LENGTHPOW) &
                attr_table.LENGTHMASK) +
               preset2] /
    (1 + (param_harm2nd - 1) / 2);
int32_t sine;
SINE2TINTERP(phase, sine)
sine = sine >> 4;

MTOF(I - (1 << 26) << 1, Freq)

int32_t out = ___SMMUL(I << 3, wave - sine << 2) + sine;
val = ___SMMLA((out - val) << 1, Freq, val);
outlet_wave = ___SMMUL(val << 3, I << 2);
I += Step;

i1 += step1;
i2 += step2;
i3 += step3;
i4 += step4;
i5 += step5;

Pm = (uint32_t)(i1) + (1 << 31);

Privacy

© 2024 Zrna Research