rndPattF16

16 channel random pattern generator with lots of goodies
Author: Remco van der Most
License: BSD
Github: sss/patt/rndPattF16.axo

Inlets

int32 count

int32 max

bool32 rnd

Outlets

frac32 o1

frac32 o2

frac32 o3

frac32 o4

frac32 o5

frac32 o6

frac32 o7

frac32 o8

frac32 o9

frac32 o10

frac32 o11

frac32 o12

frac32 o13

frac32 o14

frac32 o15

frac32 o16

Parameters

frac32.u.map repeat

frac32.u.map chance

frac32.u.map change

frac32.u.map nonMemChance

frac32.u.map nonMemChange

frac32.u.map freeze

frac32.u.map maxFreeze

frac32.u.map difference

frac32.u.map errorChance

frac32.u.map errorSize

frac32.u.map glidechance

frac32.u.map gliderate

Attributes

combo maxlength

combo start

Declaration
static const uint32_t LENGTH = 1 << attr_maxlength;
static const uint32_t LENGTHPOW = attr_maxlength + 4;
static const uint32_t LENGTHMASK = LENGTH - 1;
static const uint32_t GAIN = 0;
int32_t ofs[16], C[16], cnt[16], repeat[16], R[16], tcnt[16], i, error, E[16],
    val[16], rate[16], RT[16];

bool trg, rnd, glide[16];
int32_t *array;
int32_t v27 = 1 << 27;
Init
static int32_t _array[LENGTH << 4] __attribute__((section(".sdram")));
array = &_array[0];

for (i = 0; i < (LENGTH << 4); i++) {
  if (attr_start > 0) {
    array[i] = (int32_t)(GenerateRandomNumber() >> 5);
  } else {
    array[i] = 0;
  }
}
for (i = 0; i < 16; i++) {
  C[i] = 0;
  R[i] = (int32_t)(GenerateRandomNumber());
  RT[i] = (int32_t)(GenerateRandomNumber());
}
Control Rate
for (i = 0; i < 16; i++) {
  MTOF((param_gliderate << 1) - v27 + ___SMMUL(param_difference << 1, RT[i]),
       rate[i])
  rate[i] = rate[i] >> 2;
  repeat[i] =
      ___SMMUL(inlet_max << 5,
               __USAT(param_repeat + ___SMMUL(R[i], param_difference), 27)) +
      1;
  tcnt[i] = inlet_count;
  tcnt[i] = tcnt[i] - tcnt[i] / repeat[i] * repeat[i];
  tcnt[i] += tcnt[i] < 0 ? repeat[i] : 0;
  tcnt[i] = tcnt[i] & LENGTHMASK;
}
int32_t tmp;
if ((inlet_rnd > 0) && !rnd) {
  rnd = 1;
  for (i = 0; i < (LENGTH << 4); i++) {
    array[i] = (int32_t)(GenerateRandomNumber() >> 5);
  }
  for (i = 0; i < 16; i++) {
    R[i] = (int32_t)(GenerateRandomNumber());
    RT[i] = (int32_t)(GenerateRandomNumber());
  }
} else if (inlet_rnd < 1) {
  rnd = 0;
}
for (i = 0; i < 16; i++) {
  if (!(tcnt[i] == cnt[i])) {
    if (((int32_t)(GenerateRandomNumber() >> 5)) < param_glidechance) {
      glide[i] = 1;
    } else {
      glide[i] = 0;
    }
    if (((int32_t)(GenerateRandomNumber() >> 5)) < param_errorChance) {
      E[i] = ___SMMUL((int32_t)(GenerateRandomNumber()),
                      ___SMMUL(param_errorSize, inlet_max << 6));
    } else {
      E[i] = 0;
    }
    if (((int32_t)(GenerateRandomNumber() >> 5)) <
        param_chance) { // R[i]=(int32_t)(GenerateRandomNumber());
      tmp = array[(i << 4) + tcnt[i]];
      tmp += ___SMMUL(param_change << 1, (int32_t)GenerateRandomNumber());
      array[(i << 4) + tcnt[i]] = __USAT(tmp, 27) - (tmp - __USAT(tmp, 27));
    }
    C[i] -= C[i] > 0 ? 1 : 0;
    if ((((int32_t)(GenerateRandomNumber() >> 5)) < param_freeze) &&
        (C[i] == 0)) {
      C[i] = ___SMMUL(param_maxFreeze, (int32_t)(GenerateRandomNumber() >> 21));
    }
    if (C[i] == 0) {
      ofs[i] = 0;
      if (((int32_t)(GenerateRandomNumber() >> 5)) < param_nonMemChance) {
        ofs[i] =
            ___SMMUL(param_nonMemChange << 1, (int32_t)GenerateRandomNumber());
      }
      tmp = ofs[i] + array[(i << 4) + ((tcnt[i] + E[i]) & LENGTHMASK)];
      ofs[i] = __USAT(tmp, 27) - (tmp - __USAT(tmp, 27));
    }
  }
}

for (i = 0; i < 16; i++) {
  if (glide[i] > 0) {
    val[i] = ___SMMLA((ofs[i] - val[i]) << 1, rate[i], val[i]);
  } else {
    val[i] = ofs[i];
  }
}

outlet_o1 = val[0];
outlet_o2 = val[1];
outlet_o3 = val[2];
outlet_o4 = val[3];
outlet_o5 = val[4];
outlet_o6 = val[5];
outlet_o7 = val[6];
outlet_o8 = val[7];
outlet_o9 = val[8];
outlet_o10 = val[9];
outlet_o11 = val[10];
outlet_o12 = val[11];
outlet_o13 = val[12];
outlet_o14 = val[13];
outlet_o15 = val[14];
outlet_o16 = val[15];
for (i = 0; i < 16; i++) {
  cnt[i] = tcnt[i];
}

Privacy

© 2024 Zrna Research