forked from skooter500/OOP-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio2.java
More file actions
91 lines (71 loc) · 2.14 KB
/
Audio2.java
File metadata and controls
91 lines (71 loc) · 2.14 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package ie.tudublin;
import ddf.minim.AudioBuffer;
// import ddf.minim.AudioBuffer;
import ddf.minim.AudioInput;
import ddf.minim.AudioPlayer;
import ddf.minim.Minim;
import ddf.minim.analysis.FFT;
import processing.core.PApplet;
public class Audio2 extends PApplet{
Minim m;
AudioInput ai;
AudioPlayer ap;
AudioBuffer ab;
FFT fft;
public void settings()
{
size(1024, 1024);
}
public void setup()
{
m = new Minim(this);
ai = m.getLineIn(Minim.MONO, width, 44100, 16);
ab = ai.mix;
lerpedBuffer = new float[width];
fft = new FFT(width, 44100);
}
float[] lerpedBuffer;
public void draw()
{
background(0);
colorMode(HSB);
stroke(255);
float half = height / 2;
for(int i = 0 ; i < ab.size() ; i ++)
{
stroke(map(i, 0, ab.size(), 0, 255), 255, 255);
lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.05f);
float f = abs(lerpedBuffer[i] * half * 2.0f);
line(i, half + f, i, half - f);
}
fft.forward(ab);
stroke(255);
int highestIndex = 0;
for(int i = 0 ;i < fft.specSize() / 2 ; i ++)
{
line(i * 2.0f, height, i * 2.0f, height - fft.getBand(i) * 5.0f);
if (fft.getBand(i) > fft.getBand(highestIndex))
{
highestIndex = i;
}
}
float freq = fft.indexToFreq(highestIndex);
fill(255);
textSize(20);
text("Freq: " + freq, 100, 100);
float y = map(freq, 1000.0f, 2500.0f, height, 0);
lerpedY = lerp(lerpedY, y, 0.1f);
circle(200, y, 50);
circle(300, lerpedY, 50);
//println(map(5, 2, 10, 1000, 2000));
//println(map1(5, 2, 10, 1000, 2000));
}
float lerpedY = 0;
float map1(float a, float b, float c, float d, float e)
{
float range1 = c - b;
float range2 = e - d;
float howFar = a - b;
return d + (howFar / range1) * range2;
}
}