function successCallback(stream) {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var audioContext = new AudioContext();
var analyser = audioContext.createAnalyser();
analyser.fftSize = Math.pow(2, 13);
var sampleRate = audioContext.sampleRate;
var data = new Float32Array(analyser.fftSize);
function step() {
requestAnimationFrame(step);
analyser.getFloatTimeDomainData(data);
var frequency = window.yin(data, sampleRate, 0.1);
frequencies.push(frequency);
if (frequencies.length > maxValuesToKeep) {
frequencies.shift();
}
const midi = freqToApproxMidiNr(lastFreq);
offsets.push(Math.round((midi - Math.round(midi)) * 100));
if (offsets.length > 20) {
offsets.shift();
}
}
var mediaStreamSource = audioContext.createMediaStreamSource(stream);
mediaStreamSource.connect(analyser);
requestAnimationFrame(step);
}