gateSpreaderExp

Expanded gate spreader This module generates an x-amount of steps within the given max-count (input). Use my "countExt" or "polyCount" module to connect the "max" input/output. After hitting "generate" it will generate new gates one by one, each time checking which distance between gates is the longest and then randomly divides this distance into 2 gates. The maximum amount of gates being generated is set by the "gates" selector and their timing can be quantised with the "qnt" selector (powers of 2!). The amount of gates ACTUALLY TO BE PLAYED depends on the "gates" input which is scaled to the "gates" selector (which just sets the maximum amount of gates to be generated in the array). When the "gate" input is 0, no gate will be generated. When "gate" input goes higher, it adds the gates in the order they were created, making smaller and smaller sections by adding gates in the longest "pauzes". Up to the amount of gates set by the "gate" selector.
Author: Remco van der Most
License: BSD
Github: sss/patt/gateSpreaderExp.axo

Inlets

int32 count

int32 max

int32 qnt

bool32 generate

frac32 gates

Outlets

bool32 gate

bool32 o1

bool32 o2

bool32 o3

bool32 o4

bool32 o5

bool32 skipped

int32 gates

int32 number

Parameters

frac32.u.map.gain random

bool32.mom generate

int32 gates

int32 qnt

int32 start

int32 div

int32 repeat

frac32.u.map p0

frac32.u.map p1

frac32.u.map p2

frac32.u.map p3

frac32.u.map p4

frac32.s.map swing

frac32.s.map mod

bool32.tgl toggle

Declaration
//     number & start/length
int16_t data[64][2];
int i;
int j;
bool gen;
int prv;
bool GEN = 1;
int gates;
int number;
int32_t val[5];
int32_t v27 = 1 << 27;
int32_t PRV;
int32_t vi30 = (1 << 30) - 1;
Control Rate
uint32_t sum;
sum = param_p0 + param_p1 + param_p2 + param_p3 + param_p4;
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);
}
sum = param_p0 + param_p1 + param_p2 + param_p3 + param_p4;
int32_t Gat = ___SMMUL(gates << 5, inlet_gates << 2);
val[0] = ___SMMUL(param_p0 << 3, Gat);
val[1] = ___SMMUL(param_p1 << 3, Gat) + val[0];
val[2] = ___SMMUL(param_p2 << 3, Gat) + val[1];
val[3] = ___SMMUL(param_p3 << 3, Gat) + val[2];
val[4] = ___SMMUL(param_p4 << 3, Gat) + val[3];

if ((GEN > 0) && !gen) {
  gen = 1;
  gates = param_gates; //___SMMUL(param_gates<<3,inlet_gates<<2);
  for (i = 0; i < 64; i++) {
    data[i][0] = 0;
    data[i][0] = 0;
  }
  data[0][1] = inlet_max;
  for (i = 0; i < (gates - 1); i++) {
    int16_t max = 0;
    int pos = 0;
    for (j = 0; j < (i + 1); j++) {
      if (data[j][1] > max) {
        max = data[j][1];
        pos = j;
      }
    }
    int32_t TMP = (int32_t)(GenerateRandomNumber()) & (vi30);
    int32_t swing =
        ((i & 1) > (1 - param_toggle) ? -param_swing : param_swing) + v27 << 2;
    int k = i - i / param_repeat * param_repeat;
    swing = (swing + (k * param_mod * 8)) & vi30;
    TMP = swing + (___SMMUL(param_random, TMP - swing) << 1);
    int16_t tmp = ___SMMUL((int32_t)(data[pos][1] - 1) << 2, TMP) + 1;
    // int16_t
    // tmp=___SMMUL((int32_t)(data[pos][1]-1)<<2,(int32_t)(GenerateRandomNumber()&((1<<30)-1)))+1;
    data[i + 1][1] = data[pos][1] - tmp;
    data[i + 1][0] = data[pos][0] + tmp;
    data[pos][1] = tmp;
  }
} else if (GEN == 0) {
  gen = 0;
}

outlet_gate = 0;
outlet_o1 = 0;
outlet_o2 = 0;
outlet_o3 = 0;
outlet_o4 = 0;
outlet_o5 = 0;
outlet_skipped = 0;
if (!(inlet_count == prv)) {
  for (i = 0; i < ___SMMUL(gates << 3, inlet_gates << 2); i++) {
    int qnt = __USAT(param_start - i / param_div, 8) + param_qnt + inlet_qnt;
    int pos = (data[i][0] >> qnt) << qnt;
    if (inlet_count == pos) {
      outlet_gate = 1;
      number = i;
      if (i < val[0]) {
        outlet_o1 = 1;
      } else if (i < val[1]) {
        outlet_o2 = 1;
      } else if (i < val[2]) {
        outlet_o3 = 1;
      } else if (i < val[3]) {
        outlet_o4 = 1;
      } else if (i < val[4]) {
        outlet_o5 = 1;
      }
    }
  }
  if (outlet_gate == 0) {
    outlet_skipped = 1;
  }
}
prv = inlet_count;
outlet_number = number;
outlet_gates = gates;
GEN = param_generate + inlet_generate;

Privacy

© 2024 Zrna Research