xxxxxxxxxx
34
let drums = []; //create an array for drums
let mic; // mic variable
//same as images, to load audio files
function preload(){
//follow directory of where the sound sits
//drums[0] = loadSound('drums/0.mp3')
//loop for running through the entire sound files
for(let d = 0; d<7; d++){
drums[d] = loadSound('drums/' + d + '.mp3'); //cancanate
}
mic = mic new p5.AudioIn(); //use p5 audio
mic.start() //start recording
}
function setup() {
createCanvas(400, 400);
console.log(drums) //to check drums in chrome console 'cmd' 'opt' 'J'
}
function draw() {
background(220);
let level = mic.getLevel();
}
//press 1 to 5 to play drum samples
function keyPressed(){
drums[key].play(); //play the drums with any keys played
}