radsr

Attack/decay/sustain/release envelope
Author: Johannes Taelman
License: BSD
Github: lokki/env/radsr.axo

Inlets

bool32.risingfalling gate

bool32.risingfalling resetgate

Outlets

frac32.positive envelope output

Parameters

frac32.s.map.klineartime.exp2 a

frac32.s.map.kdecaytime.exp d

frac32.s.map.kdecaytime.exp r

frac32.u.map s

Declaration
int8_t stage;
int ntrig;
int32_t val;
int ntrig2;
Init
stage = 0;
ntrig = 0;
val = 0;
ntrig2 = 0;
Control Rate
if ((inlet_gate > 0) && !ntrig) {
  stage = 1;
  ntrig = 1;
}
if ((inlet_resetgate > 0) && !ntrig2) {
  stage = 1;
  ntrig2 = 1;
  val = 0;
}
if (!(inlet_gate > 0) && ntrig) {
  stage = 0;
  ntrig = 0;
}

if ((!inlet_resetgate > 0) && ntrig2) {
  stage = 0;
  ntrig2 = 0;
}
if (stage == 0) {
  val = ___SMMUL(val, param_r) << 1;
} else if (stage == 1) {
  val = val + param_a;
  if (val < 0) {
    val = 0x7FFFFFFF;
    stage = 2;
  }
} else if (stage == 2) {
  val = (param_s << 4) + (___SMMUL(val - (param_s << 4), param_d) << 1);
}

outlet_env = val >> 4;

Privacy

© 2024 Zrna Research