-
Notifications
You must be signed in to change notification settings - Fork 1
/
microphone.pde
60 lines (49 loc) · 1.25 KB
/
microphone.pde
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
Minim minim;
AudioInput microphoneInput;
class Microphone extends SensorReading {
AudioInput microphoneInput;
float amplitude;
public Microphone(AudioInput micro) {
super("microphone");
microphoneInput = micro;
}
void init() {
amplitude = 0.0f;
}
void execute() {
amplitude = getAmplitude();
readingDone = true;
send();
}
void send() {
OscMessage m = createMessage("/data");
oscP5.send(m, serverLocation);
}
SensorReading createFromMessage(OscMessage msg) {
Microphone microphone = new Microphone(microphoneInput);
microphone.amplitude = msg.get(1).floatValue();
return microphone;
}
OscMessage createMessage(String adrPattern) {
OscMessage m = new OscMessage(adrPattern);
m.add(name);
m.add(amplitude);
return m;
}
float getAmplitude() {
float amplitude = 0.0f;
if (microphoneInput != null) {
for (int i = 0; i < microphoneInput.bufferSize() - 1; i++) {
amplitude += microphoneInput.mix.get(i);
}
amplitude /= microphoneInput.bufferSize();
} else {
println("Error: no lin-in present: ");
}
println(" - " + amplitude);
return amplitude;
}
void print() {
println(name + " amplitude: " + amplitude);
}
}