pulseEnv

Attack/hold/decay envelope with treshold, linear attack, exponential decay to enable square shaped envelopes. Added a hold stage by amplifying the envelope and clipping it. The treshold also amplifies the envelope, but also lowers it with the treshold level, while clipping it below zero. Enabling quick stops as if the exponential decay is partly linear. With hold and treshold all the way up, the envelope is almost squareshaped. In this case, the decay sets the pulse length.
Author: Remco van der Most
License: BSD
Github: sss/env/pulseEnv.axo

Inlets

bool32.rising trigger

Outlets

frac32.positive envelope output

Parameters

frac32.s.map.klineartime.exp a

frac32.u.map h

frac32.u.map t

frac32.s.map.kdecaytime.exp d

Declaration
int8_t stage;
int ntrig;
int32_t val;
Init
ntrig = 0;
val = 0;
Control Rate
if ((inlet_trig > 0) && !ntrig) {
  ntrig = 1;
  stage = 1;
} else if (!(inlet_trig > 0)) {
  ntrig = 0;
}
if (stage == 0) {
  val = ___SMMUL(val, param_d) << 1;
} else {
  if (val < param_t) {
    val = param_t;
  };
  int32_t t;
  MTOF(-param_a, t);
  val = val + (t >> 3);
  if (val < 0) {
    val = 0x7FFFFFFF;
    stage = 0;
  }
}
int32_t env = val >> 4;
env += ___SMMUL(param_t << 3, env << 4);
env -= param_t << 2;
env = __USAT(env, 27);
env = __USAT(env + ___SMMUL(param_h << 4, env << 4), 27);
outlet_env = env;

Privacy

© 2024 Zrna Research