-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudioFunctions.pde
46 lines (36 loc) · 905 Bytes
/
AudioFunctions.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
FFT fft;
AudioIn audio;
int bands = 256;
float[] spectrum = new float[bands];
float[][] sampledDistributions = new float[128][bands];
void audioSetup(){
fft = new FFT(this, bands);
audio = new AudioIn(this, 0);
audio.start();
fft.input(audio);
float ek, a, s, x;
for(int i = 0; i < sampledDistributions.length; i++){
s = i * 0.5 + 0.5;
ek = -1. / (2 * s * s);
a = 1. / (s * sqrt(TWO_PI));
for(int j = 0; j < bands; j++){
x = j;
sampledDistributions[i][j] = a * exp(x * x * ek);
}
}
}
float amplitude(int sd, int center){
float amp = 0;
for(int i = 0; i < bands; i++){
amp += spectrum[i] * sampledDistributions[sd][abs(i - center)];
}
return amp;
}
void audioDebugDraw(){
strokeWeight(2);
stroke(0);
//background(255);
for(int i = 0; i < bands * 2; i += 2){
line(i, height, i, height - spectrum[i / 2] * height);
}
}