ADloopR

Attack/decay/sustain/release envelope with modulation inputs
Author: Johannes Taelman (edited by Remco van der Most)
License: BSD
Github: sss/env/ADloopR.axo

Inlets

frac32.bipolar attack time modulation

frac32.bipolar decay time modulation

frac32.bipolar sustail level1 modulation

frac32.bipolar ds1

frac32.bipolar sustail level2 modulation

frac32.bipolar ds2

frac32.bipolar release time modulation

bool32.risingfalling gate

Outlets

frac32.positive envelope output

int32 stage

Parameters

frac32.s.map a

frac32.s.map d

frac32.s.map ds1

frac32.s.map ds2

frac32.s.map r

frac32.u.map s1

frac32.u.map s2

Declaration
int8_t stage;
int ntrig;
int32_t val;
Init
stage = 0;
ntrig = 0;
val = 0;
Control Rate
if ((inlet_gate > 0) && !ntrig) {
  stage = 1;
  ntrig = 1;
}
if (!(inlet_gate > 0) && ntrig) {
  stage = 0;
  ntrig = 0;
}
if (stage == 0) {
  int32_t r1;
  int32_t r2;
  MTOF(-param_r - inlet_r, r1);
  r1 = 0x7FFFFFFF - (r1 >> 2);
  val = ___SMMUL(val, r1) << 1;
} else if (stage == 1) {
  int32_t a;
  MTOF(-param_a - inlet_a, a);
  a = a >> 2;
  val = val + a;
  if (val < 0) {
    val = 0x7FFFFFFF;
    stage = 2;
  }
} else if (stage == 2) {
  int64_t s1 = __USAT(param_s1 + inlet_s1, 27);
  int32_t de;
  MTOF(-param_d - inlet_d, de);
  de = 0x7FFFFFFF - (de >> 2);
  val = (s1 << 4) + (___SMMUL(val - (s1 << 4), de) << 1);
  if ((val >= ((s1 << 4) - 10000000)) && (val <= ((s1 << 4) + 10000000))) {
    stage = 3;
  }
} else if (stage == 3) {
  int64_t s2 = __USAT(param_s2 + inlet_s2, 27);
  int32_t ds1;
  MTOF(-param_ds1 - inlet_ds1, ds1);
  ds1 = 0x7FFFFFFF - (ds1 >> 2);
  val = (s2 << 4) + (___SMMUL(val - (s2 << 4), ds1) << 1);
  if ((val >= ((s2 << 4) - 10000000)) && (val <= ((s2 << 4) + 10000000))) {
    stage = 4;
  }
} else if (stage == 4) {
  int64_t s1 = __USAT(param_s1 + inlet_s1, 27);
  int32_t ds2;
  MTOF(-param_ds2 - inlet_ds2, ds2);
  ds2 = 0x7FFFFFFF - (ds2 >> 2);
  val = (s1 << 4) + (___SMMUL(val - (s1 << 4), ds2) << 1);
  if ((val >= ((s1 << 4) - 10000000)) && (val <= ((s1 << 4) + 10000000))) {
    stage = 3;
  }
}

outlet_env = val >> 4;
outlet_stage = stage;

Privacy

© 2024 Zrna Research