xxxxxxxxxx
63
/*
Thunder https://freesound.org/people/Erdie/sounds/24003/
Bird Chirp https://freesound.org/people/InspectorJ/sounds/416529/
*/
let birdSnd;
let thunderSnd;
let amp;
let mic;
let fft;
function preload() {
birdSnd = loadSound("assets/bird.mp3");
thunderSnd = loadSound("assets/thunder.mp3");
}
function setup() {
createCanvas(400, 400);
colorMode(HSB, 360, 100, 100);
amp = new p5.Amplitude();
mic = new p5.AudioIn();
fft = new p5.FFT();
}
function draw() {
background(0, 10);
let analyzeArray = fft.analyze()
// console.log(analyzeArray);
for (let i = 0; i < analyzeArray.length; i++) {
let x = map(i, 0, analyzeArray.length, 0, width);
let y = map(analyzeArray[i], 0, 255, height, 0);
circle(x, y, 5)
}
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
amp.setInput(birdSnd);
birdSnd.play();
thunderSnd.stop();
mic.stop();
}
if (keyCode === RIGHT_ARROW) {
amp.setInput(thunderSnd);
thunderSnd.play();
birdSnd.stop();
mic.stop();
}
if (keyCode === ENTER) {
mic.start();
amp.setInput(mic);
thunderSnd.stop();
birdSnd.stop();
}
}