hahdEnv

delay/Attack/hold/decay envelope, linear attack, exponential decay triggered, not gated
Author: Remco van der Most
License: BSD
Github: sss/env/hahdEnv.axo

Inlets

bool32.rising trigger

Outlets

frac32.positive envelope output

Parameters

frac32.s.map.kdecaytime.exp decay

frac32.s.map.klineartime.exp delay

frac32.s.map.klineartime.exp attack

frac32.s.map.klineartime.exp hold

Declaration
int8_t stage;
int ntrig;
int32_t val;
uint32_t count1;
uint32_t count2;
int rtrig;
Init
ntrig = 0;
val = 0;
Control Rate
int32_t hold1;
if (param_delay > (-1 << 27) + 1) {
  MTOF(param_delay, hold1)
} else {
  hold1 = 0;
}

hold1 = hold1 >> 18;

int32_t hold2;
if (param_hold > (-1 << 27) + 1) {
  MTOF(param_hold, hold2)
  hold2 = hold2 >> 18;
} else {
  hold2 = 0;
}

if ((inlet_trig > 0) && !ntrig) {
  count1 = 0;
  ntrig = 1;
} else if (!(inlet_trig > 0)) {
  ntrig = 0;
}

if ((count1 > hold1) && !rtrig) {
  rtrig = 1;
  stage = 1;
} else if (!(count1 > hold1)) {
  rtrig = 0;
}

if (stage == 2) {
  if (count2 > hold2) {
    stage = 0;
  }
}

if (stage == 0) {
  val = ___SMMUL(val, param_decay) << 1;
} else {
  int32_t t;
  MTOF(-param_attack, t);
  val = val + (t >> 3);
  if (val < 0) {
    val = 0x7FFFFFFF;
    if (stage == 1) {
      count2 = 0;
    }
    stage = 2;
  }
}
outlet_env = val >> 4;
count1 = count1 > (1 << 31) ? (1 << 31) : count1 + 1;
count2 = count2 > (1 << 31) ? (1 << 31) : count2 + 1;

Privacy

© 2024 Zrna Research