DP2PWM

Low CPU Anti Aliased Pulse Width Modulated Osc (Second order differentiated polynomial).
Author: Smashed Transistors
License: LGPL
Github: tiar/osc/DP2PWM.axo

Inlets

frac32.bipolar pitch

frac32.bipolar pw

Outlets

frac32buffer.bipolar selfPM wave

Parameters

frac32.s.map.pitch pitch

frac32.u.map Pulse Width

Declaration
float pa, pb, dp, _dp2, y0, y1, y2;
float I2(float p) { return p * (1 / 6.0f + p * (-0.5f + p * (1 / 3.0f))); }
Init
pa = pb = y0 = y1 = y2 = 0.0f;
Control Rate
int32_t idp;
MTOFEXTENDED(param_pitch + inlet_pitch, idp);
dp = idp * (0.25f / (1 << 30));
_dp2 = (1 << 27) / (dp * dp);

float pw = param_pw * (1.0f / (1 << 27)) + inlet_pw * (1.0f / (1 << 27));
if (pw < 0.05f) {
  pw = 0.05f;
}
if (pw > 0.95f) {
  pw = 0.95f;
}
pb = pa + pw;
pb -= (pb > 1);
// change of dp => update state variables y1 y2
pa -= dp;
pa += (pa < 0);
pb -= dp;
pb += (pb < 0);
y2 = I2(pa) - I2(pb);

pa += dp;
pa -= (pa > 1);
pb += dp;
pb -= (pb > 1);
y1 = I2(pa) - I2(pb);
Audio Rate
pa += dp;
pa -= (pa > 1);
pb += dp;
pb -= (pb > 1);
y0 = I2(pa) - I2(pb);
outlet_wave = (int32_t)((y0 + y2 - 2 * y1) * _dp2);
y2 = y1;
y1 = y0;

Privacy

© 2024 Zrna Research