bool32.rising clock in
bool32 trig
frac32 note
frac32.u.map random
uint8_t ntrig;
int8_t pc; // pulse counter [0..7]
uint8_t gm; // gate mode [0..3] 0 : silence, 1 : one trig, 2 : multiple trig, 3
// : long trig
uint32_t note;
uint8_t trig;
uint8_t ft; // first trig
uint8_t buf;
uint8_t newbit;
uint8_t noiseGen(uint8_t in) {
return (((((in >> 7) ^ (in >> 5)) ^ (in >> 4)) ^ in) & 1) | (in << 1);
}
ntrig = 0;
pc = 0;
gm = 0;
note = 0;
trig = 0;
ft = 0;
buf = 0;
newbit = 0;
trig = 0;
if ((gm == 3) || (gm == 2) || ((gm == 1) && (ft == 1)))
trig = 1;
if ((inlet_trig > 0) && !ntrig) {
ntrig = 1;
if (pc < 1) {
if ((GenerateRandomNumber() % 255) < (param_random >> 19)) {
newbit = ~buf & 0x1;
} else {
newbit = buf & 0x1;
}
buf = (buf >> 1) | (newbit << 7);
if (buf & 128)
note = -((buf & 0x7F) << 20);
else
note = (buf << 20);
pc = noiseGen(buf) >> 5;
gm = noiseGen(noiseGen(buf)) >> 6;
trig = 0;
ft = 1;
// LogTextMessage("buf(%x)\tpc(%d)\tgm(%d)\n", buf, pc, gm);
} else {
ft = 0;
}
if (gm == 2)
trig = 0; // multiple trig
pc--;
}
if (!(inlet_trig > 0))
ntrig = 0;
outlet_trig = trig;
outlet_note = note;