ahdsr2v

2 voice Attack/hold/decay/sustain/release envelope, linear attack, exponential decay and release. The main out gives the highest envelope (max of 1/2), this is how it would be if just a single envelope was used (monophonic). Use this, for example, for a filter or if you're using only a single oscillator. Envelope 1 and 2 are used together with 2 oscillators and vca's to produce a dual-voice. With every new gate, the next envelope goes into attack stage and the other is forced into release state, fading out the voice.
Author: Remco van der Most
License: BSD
Github: sss/env/ahdsr2v.axo

Inlets

bool32.rising trigger

Outlets

frac32.positive main

frac32.positive envelope output

frac32.positive env2

bool32 trg1

bool32 trg2

bool32 n1

bool32 n2

bool32 mn

int32 s1

int32 s2

int32 ms

Parameters

frac32.s.map.klineartime.exp a

frac32.s.map.klineartime.exp h

frac32.s.map.kdecaytime.exp d

frac32.s.map.kdecaytime.exp r

frac32.u.map.gain s

Declaration
int8_t stage;
int ntrig;
int32_t val;
int32_t vol;
bool sel;
int32_t hold;
uint32_t v30 = 1 << 30;
int prv;
Init
ntrig = 0;
val = 0;
Control Rate
outlet_trg1 = 0;
outlet_trg2 = 0;
if ((inlet_trig > 0) && !ntrig) {
  sel = (sel + 1) & 1;
  if (sel == 0) {
    outlet_trg1 = 1;
  } else {
    outlet_trg2 = 1;
  }
  hold = 0;
  uint32_t tmp = vol;
  vol = val;
  val = tmp;
  ntrig = 1;
  stage = 1;
} else if (!(inlet_trig > 0)) {
  ntrig = 0;
  stage = 0;
}
vol = ___SMMUL(vol, param_r) << 1;
if (stage == 0) {
  val = ___SMMUL(val, param_r) << 1;
} else if (stage == 3) {
  val = param_s + (___SMMUL(val - param_s, param_d) << 1);
} else if (stage == 2) {
  int32_t t;
  MTOF(-param_h, t);
  hold = hold + (t >> 3);
  if (hold < 0) {
    hold = 0x7FFFFFFF;
    stage = 3;
  }
} else if (stage == 1) {
  int32_t t;
  MTOF(-param_a, t);
  val = val + (t >> 3);
  if (val < 0) {
    val = 0x7FFFFFFF;
    stage = 2;
  }
}

if (sel == 0) {
  outlet_env1 = val >> 4;
  outlet_env2 = vol >> 4;
  outlet_s1 = stage;
  outlet_s2 = 0;
  outlet_n2 = 0;
  outlet_n1 = !(stage == prv) ? 1 : 0;
} else if (sel == 1) {
  outlet_env1 = vol >> 4;
  outlet_env2 = val >> 4;
  outlet_s2 = stage;
  outlet_s1 = 0;
  outlet_n1 = 0;
  outlet_n2 = !(stage == prv);
}
outlet_ms = stage;
outlet_mn = !(stage == prv);
outlet_main = (val > vol ? val : vol) >> 4;
prv = stage;

Privacy

© 2024 Zrna Research