square medium

square wave oscillator Non-bandwith limited, medium quality
Author: Johannes Taelman
License: BSD
Github: osc/square medium.axo

Inlets

frac32.bipolar pitch

Outlets

frac32buffer.bipolar square wave

Parameters

frac32.s.map.pitch pitch

Declaration
int32_t osc_p;
Init
osc_p = 0;
Control Rate
uint32_t freq;
MTOFEXTENDED(param_pitch + inlet_pitch, freq);
int j;
int32_t f0i = 0x7fffffff / (1 + (freq) >> 11);
for (j = 0; j < BUFSIZE; j++) {
  int32_t p1 = osc_p;
  int32_t p2 = p1 + freq;
  osc_p = p2;
  if ((p2 < 0) && (p1 > 0))
    outlet_wave[j] = ___SMMLS(f0i, (-p1) << 1, 0x400) << 16;
  else if ((p1 < 0) && (p2 > 0))
    outlet_wave[j] = ___SMMLS(f0i, (p1) << 1, -0x400) << 16;
  else
    outlet_wave[j] = (p2 > 0) ? -(1 << 26) : ((1 << 26));
}

Privacy

© 2024 Zrna Research