ADorADSR

Auto-switching attack/decay or attack/decay/sustain/release envelope trigger=1->AD envelope trigger=2->ADSR envelope
Author: Remco van der Most
License: BSD
Github: sss/env/ADorADSR.axo

Inlets

int32 gate

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 mode;
int32_t R;
int32_t S;
int pv;
Init
stage = 0;
ntrig = 0;
val = 0;
Control Rate
if ((pv == 2) && (inlet_gate == 1)) {
  ntrig = 0;
}

if ((inlet_gate > 0) && !ntrig) {
  mode = inlet_gate;
  if (mode == 1) {
    R = param_d;
    S = 0;
  }
  if (mode == 2) {
    R = param_r;
    S = param_s;
  }
  stage = 1;

  ntrig = 1;
}
if (!(inlet_gate > 0) && ntrig) {
  stage = 0;
  ntrig = 0;
}
if (stage == 0) {
  val = ___SMMUL(val, R) << 1;
} else if (stage == 1) {
  val = val + param_a;
  if (val < 0) {
    val = 0x7FFFFFFF;
    stage = 2;
  }
} else if (stage == 2) {
  val = (S << 4) + (___SMMUL(val - (S << 4), param_d) << 1);
}

outlet_env = val >> 4;

pv = inlet_gate;

Privacy

© 2024 Zrna Research