-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendOnsets.sc
56 lines (48 loc) · 1.3 KB
/
SendOnsets.sc
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
/*
Aris Bezas Mon, 12 12 2012, 20:36
Send for machine listening.
b = SendOnsets.new
b.start
b.threshold(0)
b.stop
*/
SendOnsets {
classvar default;
var <server; // the scserver that runs the listening process
var <synthListenOnsets; // the listening Onsets process
var <synthPlay; // the produce process
var <addr; // the address (p5, of ...) for sending the data for drawing
var <chan = 0; // the channel that we detect
*default {
if (default.isNil) { default = this.new }; // create default
^default;
}
*new { | server, addr, chan = 0|
^super.new.init(server, addr, chan);
}
init { | argServer, argAddr, argChan = 0|
server = argServer ?? { Server.default }; //define server
addr = argAddr ?? { NetAddr("127.0.0.1", 12345); }; //localhost, oF port
chan = argChan;
}
start {
if (not(server.serverRunning)) { server.boot };
server.doWhenBooted {
synthListenOnsets = SynthDef(\onsetSynth, { |thres = 1|
var sig, chain, onsets, pips,buf;
buf = Buffer.alloc(server, 512);
sig = SoundIn.ar(chan);
chain = FFT(buf, sig);
thres.postln;
onsets = Onsets.kr(chain, thres, \rcomplex);
SendReply.kr(onsets, \onset);
}).play(server);
};
}
stop {
synthListenOnsets.free;
}
threshold { |threshold|
synthListenOnsets.set(\thres, threshold);
}
}