forked from skooter500/OOP-2021-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Audio2.java
113 lines (88 loc) · 2.54 KB
/
Audio2.java
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package ie.tudublin;
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;
/*
The infinite number of waves make up the mind, and all minds are made up of these waves which then interact with one another to form reality via Fourier transformations
Science is not supposed to give meaning to ones life or the reason behind their existence; science only explains the testable and provable mechanisms that run the universe
*/
public class Audio2 extends PApplet
{
Minim minim;
AudioPlayer ap;
AudioInput ai;
AudioBuffer ab;
int mode = 0;
float[] lerpedBuffer;
float y = 0;
float smoothedY = 0;
float smoothedAmplitude = 0;
FFT fft;
public void keyPressed() {
if (key >= '0' && key <= '9') {
mode = key - '0';
}
if (keyCode == ' ') {
if (ap.isPlaying()) {
ap.pause();
} else {
ap.rewind();
ap.play();
}
}
}
public void settings()
{
size(1024, 1000, P3D);
//fullScreen(P3D, SPAN);
}
public void setup()
{
minim = new Minim(this);
// Uncomment this to use the microphone
ai = minim.getLineIn(Minim.MONO, width, 44100, 16);
ab = ai.mix;
//ap = minim.loadFile("heroplanet.mp3", 1024);
//ap.play();
//ab = ap.mix;
colorMode(RGB);
fft = new FFT(1024, 44100);
y = height / 2;
smoothedY = y;
lerpedBuffer = new float[width];
}
float off = 0;
public void draw()
{
background(0);
stroke(255);
float halfH = height / 2;
for(int i = 0 ; i < ab.size() ; i ++)
{
line(i, halfH, i, halfH + ab.get(i) * halfH);
}
fft.window(FFT.HAMMING);
fft.forward(ab);
stroke(0, 255, 0);
for(int i = 0 ; i < fft.specSize(); i ++)
{
line(i, 0, i,fft.getBand(i) * 10);
}
int maxIndex = 0;
for(int i = 0 ; i < fft.specSize(); i ++)
{
if (fft.getBand(i) > fft.getBand(maxIndex))
{
maxIndex = i;
}
}
// Fill out missing code!!
float freq = fft.indexToFreq(maxIndex);
textSize(20);
fill(255);
text("Freq: " + freq, 100, 200);
}
}