baseRatios

Module to calculate only ratio's of the input signal based on the selected base-values. You can either just include a single base value, like 3, to only have "power of two" multiplications/divisions of 3 as output values: 1,3,6,12,etc divided by 1,3,6,12etc Or use 3 bases, like 2,3 and 5 and their "power of two" multiplications, for more complex ratios. The whole list is created at start-up and sorted out from lowest to highest value automatically. The "total" control sets how many values will be created for the M and D selecting inputs. The M input selects a value from the created list to use as a multiplier for the time input. The D input selects a value from the created list to use as a divider for the time input. Both inputs expect a fractioal control value between 0 and 64. (like a normal control module)
Author: Remco van der Most
License: BSD
Github: sss/math/baseRatios.axo

Inlets

frac32 time

frac32 M

frac32 D

bool32 mGate

bool32 dGate

Outlets

frac32 time

bool32 gate

Attributes

combo base1

combo base2

combo base3

combo bases

combo total

Declaration
int M[attr_total];
int i;
int32_t m;
int32_t d;
int32_t Time;
int mtrig;
int dtrig;
int32_t temp1;
int32_t temp2;
int gate;
Init
if (attr_bases == 1) {
  for (i = 0; i < attr_total; i++) {
    M[i] = attr_base1 << i;
  }
}
if (attr_bases == 2) {
  for (i = 0; i < attr_total; i++) {
    M[i] = ((attr_base1 * ((i + 1) & 1)) + attr_base2 * ((i)&1)) << (i / 2);
  }
}

if (attr_bases == 3) {
  for (i = 0; i < attr_total; i++) {
    int j = i - (i / 3) * 3;
    M[i] =
        (attr_base1 * (j == 0) + attr_base2 * (j == 1) + attr_base3 * (j == 2))
        << (i / 3);
  }
}

int update = 1;
while (update > 0) {
  update = 0;
  for (i = 0; i < attr_total - 1; i++) {
    if (M[i] > M[i + 1]) {
      update = 1;
      temp1 = M[i];
      M[i] = M[i + 1];
      M[i + 1] = temp1;
    }
  }
}
m = 1;
d = 1;
temp1 = 1;
temp2 = 1;
Control Rate
if (inlet_mGate > 0) {
  m = ((inlet_M >> 21) * (attr_total - 1)) >> 6;
}
if (inlet_dGate > 0) {
  d = ((inlet_D >> 21) * (attr_total - 1)) >> 6;
}

if ((inlet_mGate > 0) && !mtrig) {
  mtrig = 1;
  temp1 = m;
  Time = inlet_time;
} else if (inlet_mGate == 0) {
  mtrig = 0;
  m = temp1;
}

if ((inlet_dGate > 0) && !dtrig) {
  dtrig = 1;
  temp2 = d;
  Time = inlet_time;
} else if (inlet_dGate == 0) {
  dtrig = 0;
  d = temp2;
}

if (!(inlet_mGate || inlet_dGate)) {
  gate = 0;
} else {
  gate = 1;
}
outlet_time = Time / M[d] * M[m] >> 1;
outlet_gate = gate;

Privacy

© 2024 Zrna Research