-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCellestial.pde
189 lines (158 loc) · 3.8 KB
/
Cellestial.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import ddf.minim.analysis.*;
import ddf.minim.*;
Constellation cons;
Lissajous lis;
Spirit spirit;
Minim minim;
AudioPlayer bassWave;
AudioPlayer wave;
AudioPlayer kick;
AudioPlayer snarz;
AudioPlayer hatz;
AudioPlayer voice;
AudioPlayer mallets;
FFT fft;
SmoothSignal bassSig = new SmoothSignal(0, 0.25);
SmoothSignal waveSig = new SmoothSignal(0, 0.25);
SmoothSignal kickSig = new SmoothSignal(0, 0.25);
SmoothSignal snarzSig = new SmoothSignal(0, 0.25);
SmoothSignal hatzSig = new SmoothSignal(0, 0.25);
SmoothSignal voiceSig = new SmoothSignal(0, 0.25);
SmoothSignal malletsSig = new SmoothSignal(0, 0.25);
void settings() {
size(700, 700, P3D);
smooth(4);
randomSeed(0);
minim = new Minim(this);
bassWave = minim.loadFile("basswave.wav", 1024);
wave = minim.loadFile("wave.wav", 1024);
kick = minim.loadFile("kik.wav", 1024);
snarz = minim.loadFile("snarz.wav", 1024);
hatz = minim.loadFile("hats.wav", 1024);
voice = minim.loadFile("voice.wav", 1024);
mallets = minim.loadFile("mallets.wav", 1024);
fft = new FFT(1024, bassWave.sampleRate());
voice.loop();
mallets.loop();
bassWave.loop();
wave.loop();
kick.loop();
snarz.loop();
hatz.loop();
}
void setup() {
cons = new Constellation(floor(width * .7), 5);
lis = new Lissajous(width * 2, new PVector(width/2, height/2), width/3);
spirit = new Spirit(new PVector(width/2, height/2), .5);
}
void draw() {
background(255);
updateSignals();
cons.awaken(bassSig.value() * .1);
lis.rapture(bassSig.value());
if (kickSig.value() > 0.5) {
cons.expand();
}
if (snarzSig.value() > 0.5) {
cons.contract();
}
cons.speedUp(hatzSig.value());
lis.voice(voiceSig.value());
println(waveSig.value());
if (waveSig.value() > .8) {
spirit.expand();
}
spirit.update();
cons.update();
lis.update();
if (keyPressed) {
keyPressed();
}
spirit.draw();
cons.draw();
lis.draw();
}
void updateSignals() {
updateSignal(bassWave, bassSig);
updateSignal(wave, waveSig);
updateSignal(kick, kickSig);
updateSignal(snarz, snarzSig);
updateSignal(hatz, hatzSig);
updateSignal(voice, voiceSig);
updateSignal(mallets, malletsSig);
}
void updateSignal(AudioPlayer player, SmoothSignal signal) {
fft.forward(player.mix);
signal.update(fft.calcAvg(20, 44100));
}
void keyPressed() {
if (key == 'w') {
cons.awaken(0.2);
}
if (key == CODED) {
if (keyCode == UP) {
cons.expand();
}
if (keyCode == DOWN) {
cons.contract();
}
if (keyCode == RIGHT) {
cons.speedUp(1);
}
}
}
class SmoothSignal {
private float value;
private final float smoothFactor;
SmoothSignal(float value, float smoothFactor) {
this.value = value;
this.smoothFactor = smoothFactor;
}
public float update(float newValue) {
value += (newValue - value) * smoothFactor;
return value;
}
public float value() {
return value;
}
}
class Spirit {
PVector position;
float expansionAcc;
boolean expanding;
float expansionVelocity;
float expansion;
Spirit(PVector position, float expansionAcc) {
this.position = position;
this.expansionAcc = expansionAcc;
this.expanding = false;
this.expansionVelocity = 0;
this.expansion = 0;
}
void update() {
if (expanding) {
expansionVelocity += expansionAcc;
expansion += expansionVelocity;
if (expansion > width * 2) {
expanding = false;
expansionVelocity = 0;
expansion = 0;
}
}
}
void expand() {
if (!expanding) {
expanding = true;
}
}
void draw() {
if (expanding) {
pushMatrix();
translate(position.x, position.y);
noStroke();
fill(246, 232, 44, map(expansion, 0, width * 2, 50, 0));
ellipse(0, 0, expansion, expansion);
popMatrix();
}
}
}