AHDSR

Attack/hold/decay/sustain/release envelope with modulation inputs
Author: Johannes Taelman edit by Remco van der Most
License: BSD
Github: sss/env/AHDSR.axo

Inlets

frac32.bipolar attack time modulation

frac32.bipolar decay time modulation

frac32.bipolar sustail level modulation

frac32.bipolar release time modulation

frac32.positive hold time modulation

bool32.risingfalling gate

Outlets

frac32.positive envelope output

Parameters

frac32.s.map a

frac32.s.map d

frac32.s.map r

frac32.u.map h

frac32.u.map s

Declaration
int8_t stage;
int ntrig;
int32_t val;
int32_t count;
Init
stage = 0;
ntrig = 0;
val = 0;
Control Rate
if ((inlet_gate > 0) && !ntrig) {
  stage = 1;
  ntrig = 1;
  count = 0;
}
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) {
  int32_t hold = (param_h + inlet_h) >> 17;

  count += 1;

  if (count > hold) {
    stage = 3;
  }

} else if (stage == 3) {
  int32_t s = __USAT(param_s + inlet_s, 27);
  int32_t d;
  MTOF(-param_d - inlet_d, d);
  d = 0x7FFFFFFF - (d >> 2);
  val = (s << 4) + (___SMMUL(val - (s << 4), d) << 1);
}
outlet_env = val >> 4;

Privacy

© 2024 Zrna Research