I am trying to create a function that measures the average of a microphone input level over five minutes, then stores the sum of calculations in a variable.
At the moment, an interval is set to run the function every five minutes but only calculates the average of the single last input value, instead of the values over time.
function measureLevel() {
average = 0;
for (counter = 0; counter < 75000; counter++) {
average += absoluteLevel / 75000;
}
averageAbsoluteLevel = Math.abs(average);
averageDbLevel = Tone.gainToDb(averageAbsoluteLevel) * scale + offset;
console.log('Counter reached. Average level is: ' + averageDbLevel);
}
window.setInterval(measureLevel, 300000);
Thanks in advance.