Debian Codegraph @

examples/effects/PowerADSR.ck

raw
1 // PowerADSR is a power based ADSR envelope that
2 // allows separate power curves for each envelope phase.
3 // In general, curves under 1.0 are sharp, while curves over 1.0 are soft.
4
5 // ~ linearEnvelope^curveValue ~
6
7 // ~options
8 //
9 // set (duration a, duration d, float s, duration r), default (0.0, 0.0, 1.0, 0.0)
10 // sets duration for attack, decay, and release phase; sets sustain level
11 //
12 // attack or attackTime (duration a), default 1.0::second
13 // sets length for the attack phase
14 //
15 // decay or decayTime (duration d), default 1.0::second
16 // sets length for the decay phase
17 //
18 // release or releasetTime (duration r), default 1:0::second
19 //
20 // sustainLevel (float s), default 0.5
21 // sets level for the sustain phase
22 //
23 // setCurves (float ac, float dc, float rc), default (1.0, 1.0, 1.0) (all linear)
24 // sets power curve for attack, decay, and release phase
25 //
26 // attackCurve (float ac), default 1.0 (linear)
27 // sets power curve for the attack phase
28 //
29 // decayCurve (float dc), default 1.0 (linear)
30 // sets power curve for the decay phase
31 //
32 // releaseCurve(float rc), default 1.0 (linear)
33 // sets power curve for the release phase
34
35 Noise nois;
36 PowerADSR env;
37
38 // sound chain
39 nois => env => dac;
40
41 // you can set the envelope on paramter at a time
42 env.attackTime(1::second);
43 env.releaseTime(1::second);
44
45 // defaults to a 1.0 curve, you have to set
46 // the curves for the power functionality
47
48 // curves under 1.0 are sharper
49 env.attackCurve(0.5);
50
51 // curves over 1.0 are softer
52 env.releaseCurve(2.0);
53
54 env.keyOn();
55 1::second => now;
56 env.keyOff();
57 1::second => now;
58
59 // you can also set all the durations and sustain at once
60 env.set(2::second, 1::second, 0.8, 0.5::second);
61
62 // and all the curves can be set at once, without the sustain
63 env.setCurves(1.75, 1.25, 1.5);
64
65 env.keyOn();
66 3::second => now;
67 env.keyOff();
68 1.0::second => now;
69
70 env.set(1::second, 1::second, 0.5, 1::second);
71
72 // and you can retrieve the state and value of the envelope
73 <<< "Done\t", env.state(), env.value(), "" >>>;
74
75 env.keyOn();
76 <<< "Attack\t", env.state(), env.value(), "" >>>;
77 1::second => now;
78
79 <<< "Decay\t", env.state(), env.value(), "" >>>;
80 1::second => now;
81
82 <<< "Sustain\t", env.state(), env.value(), "" >>>;
83 1::second => now;
84
85 env.keyOff();
86 <<< "Release\t", env.state(), env.value(), "" >>>;
87 1::second => now;
88
89 <<< "Done\t", env.state(), env.value(), "" >>>;