-
Notifications
You must be signed in to change notification settings - Fork 0
/
09_LiSaGrain.ck
77 lines (70 loc) · 1.67 KB
/
09_LiSaGrain.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
68
69
70
71
72
73
74
75
76
77
// LiSa HID
// sound chain
adc => LiSa mic => dac;
Hid hi;
HidMsg msg;
0 => int device;
if (!hi.openKeyboard(device)) me.exit();
<<< hi.name() + " is fully operational.", "">>>;
// variables
8::second => dur measureTime;
dur recTime;
float s;
int recOff, playOff, samples, grain, end;
100 => int steps;
while (true) {
hi => now;
while (hi.recv(msg)) {
if (msg.isButtonDown()) {
if (msg.ascii == 96) {
0 => recOff;
1 => playOff;
spork ~ record();
}
if (msg.ascii == 49) {
0 => playOff;
spork ~ play();
}
}
}
if (msg.isButtonUp()) {
if (msg.ascii == 96) {
1 => recOff;
}
if (msg.ascii == 49) {
1 => playOff;
}
}
}
// recording function
fun void record() {
measureTime => mic.duration;
1 => mic.record;
<<< "Recording", "" >>>;
now => time past;
while (recOff == 0) {
1::samp => now;
}
now => time present;
present - past => recTime;
0 => mic.record;
<<< "Recorded for", recTime/second, "seconds." >>>;
<<< "------------------------------", "" >>>;
recTime/samp => s;
s $ int => int samples;
samples/steps => grain;
samples - grain => end;
}
fun void play() {
<<< "Playing", "" >>>;
<<< "------------------------------", "" >>>;
mic.play(1);
while (playOff == 0) {
mic.playPos((Math.random2(0,steps) * grain)::samp);
mic.rampUp((grain*0.5)::samp);
(grain*0.5)::samp => now;
mic.rampDown((grain*0.5)::samp);
(grain*0.5)::samp => now;
}
mic.play(0);
}