b4u

A bipolar input, unipolar output k rate function defined by 4 segments.
Author: Smashed Transistors
License: LGPL
Github: tiar/kfunc/b4u.axo

Inlets

frac32.bipolar in

Outlets

frac32 out

Parameters

frac32.u.mapvsl p0

frac32.u.mapvsl p1

frac32.u.mapvsl p2

frac32.u.mapvsl p3

frac32.u.mapvsl p4

Control Rate
int32_t in = (inlet_in + (1 << 27)) >> 1;
if (in >= (1 << 27))
  outlet_out = param_p4;
else if (in <= 0)
  outlet_out = param_p0;
else {
  int32_t i = in >> (27 - 2);               // i [0 4[
  int32_t a = (in & ((1 << (27 - 2)) - 1)); // a q25
  if (i < 2) {                              // [0 2[
    if (i < 1) { // [0 1[             q27         q25   q20           q27
      outlet_out = ___SMMLA(param_p1 - param_p0, a, param_p0 >> 7) << 7;
    } else { // [1 2[
      outlet_out = ___SMMLA(param_p2 - param_p1, a, param_p1 >> 7) << 7;
    }
  } else {       // [2 4[
    if (i < 3) { // [2 3[
      outlet_out = ___SMMLA(param_p3 - param_p2, a, param_p2 >> 7) << 7;
    } else { // [3 4[
      outlet_out = ___SMMLA(param_p4 - param_p3, a, param_p3 >> 7) << 7;
    }
  }
}

Privacy

© 2024 Zrna Research