-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path6. Introducing Functions.ck
69 lines (38 loc) · 1.31 KB
/
6. Introducing Functions.ck
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
64
65
66
67
// Sync to a period of 1::second
1::second => dur T;
T - (now % T) => now;
// Band limited Saw Wave connected to an ADSR Envelope connected to Reverb connected an audio out
BlitSaw s => ADSR adsr => NRev r => dac;
// Connect another Osc to the same adsr
BlitSquare sqr => adsr;
// Use the Chuck Operator (=>) to set the harmonic levels for both oscillators
Math.random2(5,25) => s.harmonics => sqr.harmonics;
// set the gain for both oscillators
0.8 => s.gain => sqr.gain;
// Set the adsr envelope (attack, decay, sustain, and release)
adsr.set(10::ms, 200::ms, 0.0, 0::ms);
// set the reverb mix
r.mix(0.0);
function void sequencer(int octave,int seq[],float duration, float detune) {
while(true) {
<<<duration>>>;
for(int i; i < seq.cap(); i++) {
// Store the note to a frequency variable
Std.mtof(seq[i] + octave) => float freq;
// Pass to both oscillators. Detune the second oscillator for a wider sound
freq + detune => sqr.freq;
freq => s.freq;
// Trigger ADSR envelope with a key on message
adsr.keyOn();
T * duration => now;
}
}
}
[4,7,4,2] @=> int seq1[];
[4,2,7,0] @=> int seq2[];
// Play seq1 2 * T (2 measures)
spork ~sequencer(24,seq1, 0.25, 0);
T * 2 => now;
// Play seq2 2 * T (2 measures)
spork ~sequencer(24,seq2, 0.25, 0);
T * 2 => now;