-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaudio_input.pde
64 lines (53 loc) · 1.15 KB
/
audio_input.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
60
61
62
63
64
// give necessary permissions for runtime in android
// choose necessary permissions from sketch -> permissions
import ketai.sensors.*;
KetaiAudioInput mic;
short[] data;
void setup()
{
fullScreen();
orientation(LANDSCAPE);
mic = new KetaiAudioInput(this);
fill(255,0,0);
textSize(displayDensity * 24);
fill(255, 0, 0);
textSize(48);
requestPermission("android.permission.RECORD_AUDIO", "initAudio");
}
void initAudio(boolean granted)
{
if (granted)
{
mic = new KetaiAudioInput(this);
println("Audio recording permission granted");
} else {
println("Audio recording permission denied");
}
}
void draw()
{
background(128);
if (data != null)
{
for (int i = 0; i < data.length; i++)
{
if (i != data.length-1)
line(i, map(data[i], -32768, 32767, height, 0), i+1, map(data[i+1], -32768, 32767, height, 0));
}
}
if (mic != null && mic.isActive())
text("READING MIC", width/2, height/2);
else
text("NOT READING MIC", width/2, height/2);
}
void onAudioEvent(short[] _data)
{
data= _data;
}
void mousePressed()
{
if (mic != null && mic.isActive())
mic.stop();
else
mic.start();
}