DPtrisaw

aliased limited triangle - sawtooth osc
Author: Smashed Transistors
License: LGPL
Github: tiar/osc/DPtrisaw.axo

Inlets

frac32.bipolar pitch

frac32.bipolar sym

Outlets

frac32buffer.bipolar sine wave

Parameters

frac32.s.map.pitch pitch

frac32.s.map sym

Attributes

combo update

Declaration
int32_t I(int32_t p) { return ___SMMLS(p, ___SMMUL(p, p), p >> 2); }

int32_t p, x1;
#if attr_update == 1
int32_t c_m, c_dp;
float c_g;
#endif
Init
p = x1 = 0;
#if attr_update == 1
c_g = 0.0f;
c_m = 0x40000000;
c_dp = 1 << 29;
#endif
Control Rate
int32_t dp;
MTOFEXTENDED(inlet_pitch + param_pitch, dp);
int32_t m = 0x7FFFFFFF - (__USAT(abs(inlet_sym + param_sym), 27) << 4);
if (m < (1 << 20))
  m = 1 << 20; // min ratio 1/128

float g =
    (0.5f + arm::q_to_float(m, 32)) / arm::q_to_float(___SMMUL(m, dp), 25);

if (inlet_sym + param_sym < 0)
  m = -m;
m >>= 1;
#if attr_update == 0
x1 = I(p - m) - I(p + m);
#endif
Audio Rate
#if attr_update == 0
p += dp;
int32_t x0 = I(p - m) - I(p + m);
outlet_wave = (int32_t)((x0 - x1) * g);
x1 = x0;
#else
int32_t x0 = I(p - c_m) - I(p + c_m);
outlet_wave = (int32_t)((x0 - x1) * c_g);
p += c_dp;
x1 = x0;
if (((uint32_t)p) < c_dp) {
  c_m = m;
  c_g = g;
  c_dp = dp;
  x1 = I(p - c_dp - c_m) - I(p - c_dp + c_m);
}
#endif

Privacy

© 2024 Zrna Research