cFXselector

Combination module based on permutation: Creates a full list of 4-number-combinations from the available options. No repetition, no importance of order. eg: 1,2,3,4 1,2,3,5 or 3,6,8,11 (any increasing order) BUT NOT: 1,1,3,3,6 (no repetition of numbers) AND NOT: 3,1,6,5 (not smaller then any value left of itself) "select" knob is scaled to the amount of possible combinations "fine" knob can be used when using a high option count->otherwise the stepsize would be to big to select all possible combinations. The 4 outputs give you the selected indices. This module could be used for selecting 4 out of 16 functions which may not be selected twice.
Author: Remco van der Most
License: BSD
Github: sss/fx/chainer/cFXselector.axo

Inlets

frac32 select

frac32 fine

bool32 rnd

Outlets

int32 o1

int32 o2

int32 o3

int32 o4

Parameters

frac32.u.map select

frac32.s.map fine

bool32.tgl rnd

Attributes

combo options

Declaration
int i;
int T[13] = {1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820};
int32_t C[4];
int options;
int32_t q = attr_options;
uint8_t *c;
// int c[attr_options<<2];
bool rnd;
Init
static uint8_t _array[attr_options << 2] __attribute__((section(".sdram")));
c = &_array[0];

for (i = 0; i < 13; i++) {
  if (T[i] == attr_options) {
    options = i + 4;
  }
}
rnd = 1;

for (i = 0; i < 4; i++) {
  c[i] = i;
}
int j;
for (i = 1; i < q; i++) {
  int k = i << 2;
  for (j = 0; j < 4; j++) {
    c[k + j] = c[k + j - 4];
  }
  c[k + 3] += 1;

  while ((c[k + 3] >= options) || (c[k + 2] >= options - 1) ||
         (c[k + 1] >= options - 2)) {
    if (c[k + 3] >= options) {
      c[k + 2] += 1;
      c[k + 3] = c[k + 2] + 1;
    }
    if (c[k + 2] >= (options - 1)) {
      c[k + 1] += 1;
      c[k + 2] = c[k + 1] + 1;
      c[k + 3] = c[k + 2] + 1;
    }
    if (c[k + 1] >= (options - 2)) {
      c[k] += 1;
      c[k + 1] = c[k + 0] + 1;
      c[k + 2] = c[k + 1] + 1;
      c[k + 3] = c[k + 2] + 1;
    }
  }
}
Control Rate
int RND = param_rnd || inlet_rnd;
if (RND < 1) {
  int32_t set = ((param_fine + inlet_fine >> 8) + param_select + inlet_select) &
                ((1 << 27) - 1);
  int pst = ___SMMUL(((q) << 1), set << 4) << 2;
  outlet_o1 = c[pst];
  outlet_o2 = c[pst + 1];
  outlet_o3 = c[pst + 2];
  outlet_o4 = c[pst + 3];
  rnd = 1;
} else if (RND > 0) {
  if (rnd > 0) {
    rnd = 0;
    for (i = 0; i < 4; i++) {
      C[i] = -1;
    }
    bool tmp;
    for (i = 0; i < 4; i++) {
      tmp = 0;
      while (tmp == 0) {
        C[i] = (int32_t)(GenerateRandomNumber() % options);
        tmp = ((C[i] == C[(i + 1) & 3]) || (C[i] == C[(i + 2) & 3]) ||
               (C[i] == C[(i + 3) & 3])) > 0
                  ? 0
                  : 1;
      }
    }
    // int T[4];
    // T[0]=
  }
  outlet_o1 = C[0];
  outlet_o2 = C[1];
  outlet_o3 = C[2];
  outlet_o4 = C[3];
}

Privacy

© 2024 Zrna Research