Created
January 26, 2013 08:54
-
-
Save srikumarks/4641156 to your computer and use it in GitHub Desktop.
(Web Audio API) A test to see if accumulating sample time drifts away from AudioContext.currentTime.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var ac = new webkitAudioContext; | |
var j = ac.createScriptProcessor(1024, 1, 1); | |
var startTime, startTimeGrabbed = false, samples = 0, sampleCountTime = 0, frames = 0; | |
j.onaudioprocess = function (event) { | |
if (!startTimeGrabbed) { | |
startTime = ac.currentTime; | |
samples = 0; | |
sampleCountTime = ac.currentTime; | |
frames = 0; | |
startTimeGrabbed = true; | |
} | |
var drift_ms = Math.round(1000 * (sampleCountTime - ac.currentTime)); | |
if ((frames++) % 100 === 0) { | |
console.log("Frame stats = " + JSON.stringify({ | |
startTime: startTime, | |
samples: samples, | |
sampleCountTime: sampleCountTime, | |
currentTime: ac.currentTime, | |
drift_ms: drift_ms | |
})); | |
} | |
if (Math.abs(sampleCountTime - ac.currentTime) > 0.1) { | |
console.log("Drift = " + drift_ms + " ms"); | |
} | |
samples += event.inputBuffer.length; | |
sampleCountTime += event.inputBuffer.duration; | |
}; | |
j.connect(ac.destination); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment