-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-mp3.js
44 lines (37 loc) · 1.03 KB
/
test-mp3.js
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
let song, buttton, fft, space_between_lines;
function toggleSong() {
if(song.isPlaying()) {
song.pause();
} else {
song.play();
}
}
function preload() {
song = loadSound('assets/Ima Boss.mp3');
}
function setup() {
createCanvas(600, 600);
angleMode(DEGREES); // Change the mode to DEGREES
colorMode(HSB);
buttton = createButton('Toggle Play');
buttton.mousePressed(toggleSong);
song.play();
fft = new p5.FFT(0.9, 128);
space_between_lines = width / 128;
}
//Switch to branch symmetric-spectrum using "git checkout symmetric-spectrum" if you want symmetric spectrum.
function draw() {
background(0);
let spectrum = fft.analyze();
for (let i = 0; i < spectrum.length; i++) {
fill(i,255,255);
let amp = spectrum[i];
let y = map(amp, 0, 256, height, 0);
rect(i * space_between_lines, y, space_between_lines, height - y);
}
}
// Chrome 70 will require user gestures to enable web audio api
// Click on the web page to start audio
function touchStarted() {
getAudioContext().resume();
}