-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_LiSaSampler.ck
68 lines (60 loc) · 1.42 KB
/
08_LiSaSampler.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
// LiSa Sampler
// sound chain
adc => LiSa mic => dac;
Hid hi;
HidMsg msg;
0 => int device;
if (!hi.openKeyboard(device)) me.exit();
<<< hi.name() + " is fully operational.", "">>>;
// const
40 => int NUM_VOICES;
// variables
8::second => dur measureTime;
dur recTime;
int recOff, playOff;
while (true) {
hi => now;
while (hi.recv(msg)) {
if (msg.isButtonDown()) {
if (msg.ascii == 96) {
0 => recOff;
spork ~ record();
}
else {
spork ~ play(msg.ascii);
}
}
}
if (msg.isButtonUp()) {
if (msg.ascii == 96) {
1 => recOff;
}
}
}
// recording function
fun void record() {
measureTime => mic.duration;
NUM_VOICES => mic.maxVoices;
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." >>>;
<<< "------------------------------", "" >>>;
}
fun void play(int rate) {
mic.getVoice() => int newVoice;
// the ascii for 1 is 49, and they increase by one
// throughout the numbers
Math.pow(1.059463, (rate - 49)) => float x;
mic.rate(newVoice, x);
mic.playPos(newVoice, 0::samp);
mic.play(newVoice, 1);
recTime * 1 / x => now;
mic.play(newVoice, 0);
}