PTRSaw

Low CPU Anti Aliased Sawtooth using third order Polynomial Transition Region algoiritm.
Author: Ricard Wanderlof
License: LGPL
Github: ricard/osc/PTRSaw.axo

Inlets

frac32.bipolar pitch

Outlets

frac32buffer.bipolar sawtooth wave

Parameters

frac32.s.map.pitch default pitch

Declaration
float p, dp, dp2, y, D;
Init
p = 0;
Control Rate
int32_t idp;
MTOFEXTENDED(param_pitch + inlet_pitch, idp);
dp = idp * (0.25f / (1 << 30));
dp2 = dp + dp; // 2*dp
Audio Rate
p += dp;
p -= (p > 1);
if (p < dp) {
  D = p / dp;
  y = (dp2 - D) * D + 1;
} // D0
else if (p < dp2) {
  D = p / dp;
  y = (D + dp2 - 4) * D + 3;
} // D1
else
  y = 2 * p - 1; // trivial waveform for all but the first two points
y -= dp2;        // frequency dependent DC offset needed for algorithm
outlet_saw = (int32_t)(y * (1 << 27));

Privacy

© 2024 Zrna Research