summaryrefslogtreecommitdiff
path: root/objects/env/ad m.axo
blob: fd12bf99294e1df9de4201e4269cb8405a389c85 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<objdefs>
   <obj.normal id="ad m" uuid="9045d727a260ba66aa68c68f684eea2148aaf338" sha="b5f72335c41e5dec8763a23bed395833a6694bab">
      <sDescription>attack decay envelope with modulation inputs</sDescription>
      <author>Ricardo Wurmus</author>
      <license>GPL</license>
      <helpPatch>env.axh</helpPatch>
      <inlets>
         <frac32 name="a" description="attack time"/>
         <frac32 name="d" description="decay time"/>
         <bool32.rising name="trig" description="trigger"/>
      </inlets>
      <outlets>
         <frac32.positive name="env" description="envelope output"/>
      </outlets>
      <displays/>
      <params>
         <frac32.s.map name="a"/>
         <frac32.u.map.kdecaytime name="d"/>
      </params>
      <attribs/>
      <code.declaration><![CDATA[
// upper nibble: "triggered", lower nibble: stage (0x00 for decay, 0x0F for attack)
int8_t stage;
int32_t val;
]]></code.declaration>
      <code.init><![CDATA[
stage = 0x00;
val = 0;
]]></code.init>
      <code.krate><![CDATA[

// If trigger and not yet triggered
if ((inlet_trig>0) && !((stage & 0xF0)>>4)) {
   // set "triggered" and "attack"
   stage = 0xFF;
} else if (!(inlet_trig>0)) {
   // set "not triggered"
   stage &= 0x0F;
}

// decay
if ((stage & 0x0F) == 0) {
   val = ___SMMLA(val,(-1<<26)+(param_d>>1)+(inlet_d>>1),val);

// attack
} else {
   int32_t a;
   MTOF(- param_a - inlet_a,a);

   // shift to let val rise more slowly
   a = a >> 4;
   val = val + a;

   // switch to decay phase at max
   if (val > 0x07FFFFFF) {
      val = 0x07FFFFFF;
      stage &= 0xF0;
   }
}
outlet_env = val;
]]></code.krate>
   </obj.normal>
</objdefs>