%sw1_2 hold

probabiltiy switch 1-2 i with hold aka filters 0 to save sequencer zeros i1 adds 1, while on the outputs 1 is substracted again.
Author: Philoop
License: GPL
Github: phi/prob/%sw1_2 hold.axo

Inlets

bool32 trig

int32 i1

Outlets

int32 o

int32 a

Parameters

frac32.s.map prob

Declaration
int32_t val;
int ntrig;
int mtrig;
int otrig;
int prob1;
int prob2;
int latch1;
int latch2;
Init
val = (int32_t)(GenerateRandomNumber()) >> 4;
ntrig = 0;
mtrig = 0;
otrig = 0;
prob1 = 0;
prob2 = 0;
latch1 = 0;
latch2 = 0;
Control Rate
if ((inlet_trig > 0) && !ntrig) {
  val = (int32_t)(GenerateRandomNumber()) >> 4;
  ntrig = 1;
} else if (!(inlet_trig > 0))
  ntrig = 0;

prob1 = ((val >= param_prob)) ? inlet_i1 : 0;
prob2 = ((val < param_prob)) ? inlet_i1 : 0;

if ((prob1 != 0) && !mtrig) {
  latch1 = prob1;
  mtrig = 1;
} else
  mtrig = 0;
outlet_o = latch1 - 1;
if ((prob2 != 0) && !otrig) {
  latch2 = prob2;
  otrig = 1;
} else
  otrig = 0;
outlet_a = latch2 - 1;

Privacy

© 2024 Zrna Research