demux12Chance

12-output demultiplexer with 2 control modes: -using "s" input (0-11) when "chance" switch is off -using weighted randomisation for randomly selecting an output with each trigger/gate at the "i" input. the parameters get automatically updated when you move one, making sure the total gets to 100% the default inputs are "or-combined" with the outputs, so these are thru-connectors for overriding the chance/s-controlled demux. Eg. force one of the outputs to generate a trigger using a button.
Author: Remco van der Most
License: BSD
Github: sss/demux/demux12Chance.axo

Inlets

bool32 input

bool32 default 0

bool32 default 1

bool32 default 2

bool32 default 3

bool32 default 4

bool32 default 5

bool32 default 6

bool32 default 7

bool32 d8

bool32 d9

bool32 d10

bool32 d11

int32.positive select

Outlets

bool32 output 0

bool32 output 1

bool32 output 2

bool32 output 3

bool32 output 4

bool32 output 5

bool32 output 6

bool32 output 7

bool32 o8

bool32 o9

bool32 o10

bool32 o11

Parameters

frac32.u.map p0

frac32.u.map p1

frac32.u.map p2

frac32.u.map p3

frac32.u.map p4

frac32.u.map p5

frac32.u.map p6

frac32.u.map p7

frac32.u.map p8

frac32.u.map p9

frac32.u.map p10

frac32.u.map p11

bool32.tgl enable chance calculation for sending the incoming trigger to a random output, when off, uses the "s" input to select output

Declaration
bool gate[12];
int i;
int32_t v27 = 1 << 27;
uint32_t prv;
int32_t val[12];
Init
for (i = 0; i < 12; i++) {
  gate[i] = 0;
}
Control Rate
for (i = 0; i < 12; i++) {
  gate[i] = 0;
}
uint32_t sum;
if (param_chance > 0) {
  sum = param_p0 + param_p1 + param_p2 + param_p3 + param_p4 + param_p5 +
        param_p6 + param_p7 + param_p8 + param_p9 + param_p10 + param_p11;
  float32_t ratio = (float32_t)v27 / sum;
  if (!(sum == prv)) {
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p0],
                       param_p0 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p1],
                       param_p1 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p2],
                       param_p2 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p3],
                       param_p3 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p4],
                       param_p4 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p5],
                       param_p5 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p6],
                       param_p6 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p7],
                       param_p7 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p8],
                       param_p8 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p9],
                       param_p9 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p10],
                       param_p10 * ratio, 0xFFFD);
    PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_p11],
                       param_p11 * ratio, 0xFFFD);
  }
  sum = param_p0 + param_p1 + param_p2 + param_p3 + param_p4 + param_p5 +
        param_p6 + param_p7 + param_p8 + param_p9 + param_p10 + param_p11;
  val[0] = param_p0;
  val[1] = param_p1 + val[0];
  val[2] = param_p2 + val[1];
  val[3] = param_p3 + val[2];
  val[4] = param_p4 + val[3];
  val[5] = param_p5 + val[4];
  val[6] = param_p6 + val[5];
  val[7] = param_p7 + val[6];
  val[8] = param_p8 + val[7];
  val[9] = param_p9 + val[8];
  val[10] = param_p10 + val[9];
  val[11] = param_p11 + val[10];
  int sel;
  int32_t rnd = (int32_t)(GenerateRandomNumber() >> 5);
  for (i = 0; i < 12; i++) {
    sel = rnd > val[i] ? i + 1 : sel;
  }
  gate[sel] = inlet_i;
} else {
  int sel = inlet_s;
  sel = sel - sel / 12 * 12;
  sel += sel < 0 ? 12 : 0;
  gate[sel] = inlet_i;
}
outlet_o0 = gate[0] || inlet_d0;
outlet_o1 = gate[1] || inlet_d1;
outlet_o2 = gate[2] || inlet_d2;
outlet_o3 = gate[3] || inlet_d3;
outlet_o4 = gate[4] || inlet_d4;
outlet_o5 = gate[5] || inlet_d5;
outlet_o6 = gate[6] || inlet_d6;
outlet_o7 = gate[7] || inlet_d7;
outlet_o8 = gate[8] || inlet_d8;
outlet_o9 = gate[9] || inlet_d9;
outlet_o10 = gate[10] || inlet_d10;
outlet_o11 = gate[11] || inlet_d11;

prv = sum;

Privacy

© 2024 Zrna Research