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
// require https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.js
// require https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/addons/p5.sound.js
let mySound;
let fft;
function preload() {
mySound = loadSound("/sound/sketches/hack-comp.wav");
}
function setup() {
createCanvas(500, 200);
fft = new p5.FFT(0.8, 128);
fft.setInput(mySound);
startButton = createButton("start");
startButton.mousePressed(start);
stopButton = createButton("stop");
stopButton.mousePressed(stop);
}
function start() {
mySound.loop(0, 1, 1, 0, 4);
}
function stop() {
mySound.pause();
}
function draw() {
background(50);
fill(255);
noStroke();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
⌥⌘j Open Console | ⌘s/ctrl-s Update Preview |