rndLGC

multi logic with 4 inputs and randomisation Uses 16 stages of A/B logic, that interconnected, outputs can select any of the logic inputs or logic-calculations.
Author: Remco van der Most
License: BSD
Github: sss/logic/rndLGC.axo

Inlets

bool32 input 1

bool32 input 2

bool32 i3

bool32 i4

bool32 rnd

Outlets

bool32 o1

bool32 o2

bool32 o3

bool32 o4

Parameters

int32 f1

int32 f2

int32 f3

int32 f4

int32 f5

int32 f6

int32 f7

int32 f8

int32 1a

int32 1b

int32 2a

int32 2b

int32 3a

int32 3b

int32 4a

int32 4b

int32 5a

int32 5b

int32 6a

int32 6b

int32 7a

int32 7b

int32 8a

int32 8b

int32 o1

int32 o2

int32 o3

int32 o4

bool32.mom rnd

frac32.u.map.gain chance

Declaration
bool array[32];
bool rnd;
int i;
int in;
int prv;
int32_t func(int S, int A, int B, int I) {
  I += 4;
  switch (S) {
  case 0:
    array[I] = array[A] && array[B];
    break;
  case 1:
    array[I] = !(array[A] && array[B]);
    break;
  case 2:
    array[I] = array[A] && (!array[B]);
    break;
  case 3:
    array[I] = (!array[A]) && array[B];
    break;
  case 4:
    array[I] = array[A] || array[B];
    break;
  case 5:
    array[I] = !(array[A] || array[B]);
    break;
  case 6:
    array[I] = array[A] || (!array[B]);
    break;
  case 7:
    array[I] = (!array[A]) || array[B];
    break;
  case 8:
    array[I] = array[A] ^ array[B];
    break;
  case 9:
    array[I] = !(array[A] ^ array[B]);
    break;
  case 10:
    array[I] = array[A] ^ (!array[B]);
    break;
  case 11:
    array[I] = (!array[A]) ^ array[B];
    break;
  }
}
Control Rate
bool R = param_rnd || inlet_rnd;
if (((R) > 0) && !rnd) {
  rnd = 1;
  for (i = 0; i < 28; i++) {
    if (i < 8) {
      if ((int32_t)(GenerateRandomNumber() >> 1) < param_chance) {
        PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_f1 + i],
                           (int32_t)(GenerateRandomNumber() % 12), 0xFFFD);
      }
    }
    if (i > 7) {
      int k = i - 8;
      k = k > 15 ? 15 : k;
      if ((int32_t)(GenerateRandomNumber() >> 1) < param_chance) {
        PExParameterChange(&parent->PExch[PARAM_INDEX_attr_legal_name_f1 + i],
                           (int32_t)(GenerateRandomNumber() % (4 + (k >> 1))),
                           0xFFFD);
      }
    }
  }
} else if ((R) < 1) {
  rnd = 0;
}
in = inlet_i1 + inlet_i2 + inlet_i3 + inlet_i4;
array[0] = inlet_i1;
array[1] = inlet_i2;
array[2] = inlet_i3;
array[3] = inlet_i4;
if (!(in == prv)) {
  func(param_f1, array[param_1a], array[param_1b], 0);
  func(param_f2, array[param_2a], array[param_2b], 1);
  func(param_f3, array[param_3a], array[param_3b], 2);
  func(param_f4, array[param_4a], array[param_4b], 3);
  func(param_f5, array[param_5a], array[param_5b], 4);
  func(param_f6, array[param_6a], array[param_6b], 5);
  func(param_f7, array[param_7a], array[param_7b], 6);
  func(param_f8, array[param_8a], array[param_8b], 7);
}
outlet_o1 = array[param_o1];
outlet_o2 = array[param_o2];
outlet_o3 = array[param_o3];
outlet_o4 = array[param_o4];
prv = in;

Privacy

© 2024 Zrna Research