countStp

cyclic up counter with modifiable stepsize and maximum output. IMPORTANT: Counter-length is set by "max" INPUT. Output-value is wrapped between 0 and "maximum" SELECTOR. Made be used with the "gateSpreader" module, but whatever, use it for anything
Author: Remco van der Most
License: BSD
Github: sss/logic/countStp.axo

Inlets

bool32.rising trigger

bool32.rising reset

int32 max

frac32 stepsize

Outlets

int32 output

int32 max

bool32.pulse carry pulse

Parameters

int32 maximum

frac32.u.map.gain stepsize

Declaration
int ntrig;
int rtrig;
int count;
Init
count = 0;
ntrig = 0;
rtrig = 0;
Control Rate
outlet_c = 0;
int max = inlet_max;
if ((inlet_trig > 0) && !ntrig) {
  count += 1;
  if (count >= max) {
    count = 0;
    outlet_c = 1;
  }
  ntrig = 1;
} else if (!(inlet_trig > 0))
  ntrig = 0;
if ((inlet_r > 0) && !rtrig) {
  count = 0;
  rtrig = 1;
} else if (!(inlet_r > 0))
  rtrig = 0;
int cnt = count;
int32_t stepsize = param_stepsize + (inlet_stepsize << 4);
stepsize = stepsize > 0 ? stepsize : -stepsize;
cnt = count * (___SMMUL(stepsize, param_maximum) << 1);
cnt = cnt - cnt / param_maximum * param_maximum;
outlet_o = cnt;
outlet_max = param_maximum;

Privacy

© 2024 Zrna Research