xxxxxxxxxx
57
/*
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;
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();
}
function draw() {
background(0, 10);
// amp.setInput(birdSnd);
// birdSnd.play();
// console.log(amp.getLevel());
let level = amp.getLevel();
let mapLevel = map(level, 0, 1, 0, width);
ellipse(width / 2, height / 2, mapLevel);
}
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();
}
}