forked from skooter500/OOP-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio3.java
More file actions
123 lines (99 loc) · 2.78 KB
/
Audio3.java
File metadata and controls
123 lines (99 loc) · 2.78 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package ie.tudublin;
import java.util.ArrayList;
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 Audio3 extends PApplet{
Minim m;
AudioInput ai;
AudioPlayer ap;
AudioBuffer ab;
FFT fft;
ArrayList<Cube> cubes = new ArrayList<Cube>();
public void keyPressed()
{
if (key == ' ')
{
if (ap.isPlaying())
{
ap.pause();
}
else
{
ap.play();
}
}
if (key >= '0' && key <= '9')
{
createCubes(key - '0');
}
}
public void settings()
{
fullScreen(P3D, SPAN);
// size(1024, 1024, P3D);
}
public void setup()
{
m = new Minim(this);
// ap = m.loadFile("tomp3.cc - 08 PsychNerD and Marco G More Cowbell.mp3", 1024);
ai = m.getLineIn(Minim.MONO, width, 44100, 16);
ab = ai.mix;
lerpedBuffer = new float[width];
// fft = new FFT(width, 44100);
createCubes(2);
}
public void createCubes(int numCubes)
{
cubes.clear();
float theta = TWO_PI / (float) numCubes;
for(int i = 0; i < numCubes ; i ++)
{
float x = (width / 2) + sin(i * theta) * 300;
float y = (height / 2) - cos(i * theta) * 300;
Cube c = new Cube();
c.x = x;
c.y = y;
cubes.add(c);
}
}
float[] lerpedBuffer;
float rot = 0;
float lerpedAverage = 0;
public void draw()
{
float total = 0;
for (int i = 0 ; i < ab.size() ; i ++)
{
total += abs(ab.get(i));
}
float average = total / (float) ab.size();
lerpedAverage = lerp(lerpedAverage, average, 0.1f);
background(0);
lights();
colorMode(HSB);
float c = map(lerpedAverage, 0, 0.5f, 0, 255);
rot += map(lerpedAverage, 0, 1.0f, 0, 0.2f);
float boxSize = map(lerpedAverage, 0, 0.5f, 100, 500);
for(int i = 0; i < cubes.size() ; i ++)
{
Cube cube = cubes.get(i);
cube.c = c;
cube.rot = rot;
cube.size = boxSize;
cube.render(this);
}
}
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;
}
}