adsr1

Attack/decay/sustain/release envelope with modulation inputs and build in vca. "On" button turn envelope on. When "off" input is passed through with no gate.
Author: Jaffasplaffa
License: BSD
Github: jaffa/env/adsr1.axo

Inlets

frac32buffer i

bool32.risingfalling gate

Outlets

frac32buffer o

Parameters

frac32.s.map a

frac32.s.map d

frac32.s.map r

frac32.u.map s

bool32.tgl on

Declaration
int32_t prev;
int32_t step;

int8_t stage;
int ntrig;
int32_t val;
int32_t Loopval;
Init
stage = 0;
ntrig = 0;
val = 0;
Control Rate
// vca
step = (Loopval - prev) >> 4;
int32_t i = prev;
prev = Loopval;

// env
if ((inlet_g > 0) && !ntrig) {
  stage = 1;
  ntrig = 1;
}
if (!(inlet_g > 0) && ntrig) {
  stage = 0;
  ntrig = 0;
}
if (stage == 0) {
  int32_t r1;
  int32_t r2;
  MTOF(-param_r, r1);
  r1 = 0x7FFFFFFF - (r1 >> 2);
  val = ___SMMUL(val, r1) << 1;
} else if (stage == 1) {
  int32_t a;
  MTOF(-param_a, a);
  a = a >> 2;
  val = val + a;
  if (val < 0) {
    val = 0x7FFFFFFF;
    stage = 2;
  }
} else if (stage == 2) {
  int32_t s = __USAT(param_s, 27);
  int32_t d;
  MTOF(-param_d, d);
  d = 0x7FFFFFFF - (d >> 2);
  val = (s << 4) + (___SMMUL(val - (s << 4), d) << 1);
}
Loopval = val >> 4;
Audio Rate
// Env off
outlet_o = inlet_i;

// Env on
if (param_on) {

  outlet_o = ___SMMUL(inlet_i, i) << 5;
  i += step;
}

Privacy

© 2024 Zrna Research