%latch

probabilty latch
Author: Philoop
License: BSD
Github: phi/prob/%latch.axo

Inlets

int32 i

Outlets

int32 o

Parameters

frac32.s.map prob

Declaration
int32_t val;
int ntrig;
int latch;
int mtrig;
int ptrig;
int pval;
Init
val = (int32_t)(GenerateRandomNumber()) >> 4;
ntrig = 0;

latch = 0;
ptrig = 0;
pval = 0;
mtrig = 0;
Control Rate
// change
if ((pval != inlet_i) & (!ptrig)) {
  pval = inlet_i;
  ptrig = 1;
} else {
  ptrig = 0;
}
// prob
if ((ptrig > 0) && !ntrig) {
  val = (int32_t)(GenerateRandomNumber()) >> 4;
  ntrig = 1;
} else if (!(ptrig > 0))
  ntrig = 0;

// latch
if (((param_prob > val) > 0) && !mtrig) {
  latch = inlet_i;
  mtrig = 1;
}
if (!((param_prob > val) > 0))
  mtrig = 0;
outlet_o = ((param_prob > val) > 0) ? latch : inlet_i;

Privacy

© 2024 Zrna Research