%step

probabiltiy switch inlet i or rnd number i
Author: Philoop
License: BSD
Github: phi/prob/%step.axo

Inlets

int32 i1

Outlets

int32 o

Parameters

frac32.s.map prob

int32 max

Declaration
int ptrig;
int32_t pval;
int32_t val;
int ntrig;

int32_t vali;
int itrig;
Init
val = (int32_t)(GenerateRandomNumber()) >> 4;
ntrig = 0;
ptrig = 0;
pval = 0;
Control Rate
if ((pval != inlet_i1) & (!ptrig)) {
  pval = inlet_i1;
  ptrig = 1;
} else {
  ptrig = 0;
}

if ((ptrig > 0) && !ntrig) {
  val = (int32_t)(GenerateRandomNumber()) >> 4;
  ntrig = 1;
} else if (!(ptrig > 0))
  ntrig = 0;

outlet_o = (param_prob > val) ? vali : inlet_i1;

if ((ptrig > 0) && !itrig) {
  if (param_max)
    vali = (int32_t)(GenerateRandomNumber() % (param_max));
  else
    vali = 0;
}

Privacy

© 2024 Zrna Research