xxxxxxxxxx
29
const cities = ['Dhaka', 'Moreadabad', 'Islamabad', 'Rajshahi', 'Ho Chi Minh City', 'Ibadan', 'Kupondole', 'Algiers', 'Bangkok', 'New York City', 'Damascus', 'Manila', 'Hong Kong', 'Kolkata', 'Asansol'];
const dBa = [119, 114, 105, 103, 101, 100, 99, 95, 94, 92, 89];
let mic;
function todB(vol) {
return log(vol) * 8.686;
}
function setup() {
createCanvas(400, 400);
mic = new p5.AudioIn();
mic.start();
frameRate(1);
}
function draw() {
let vol = mic.getLevel();
let drawText = 'New York City';
background(220);
for (let i = 0; i < dBa.length; i++) {
if (dBa[i] > todB(vol) + 60 + 89) {
drawText = cities[i];
}
}
textAlign(CENTER);
text(drawText, 200, 200);
}