Skip to content

Instantly share code, notes, and snippets.

@ToadKing
Created August 25, 2013 17:25
Show Gist options
  • Select an option

  • Save ToadKing/6335130 to your computer and use it in GitHub Desktop.

Select an option

Save ToadKing/6335130 to your computer and use it in GitHub Desktop.
diff --git a/src/library_openal.js b/src/library_openal.js
index 7f5d5df..9477694 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -7,11 +7,18 @@ var LibraryOpenAL = {
currentContext: null,
QUEUE_INTERVAL: 25,
QUEUE_LOOKAHEAD: 100,
+
+ updateStartTime: function(context) {
+ context.startTime = window['performance']['now']() - context.ctx.currentTime * 1000.0
+ },
getCurrentTime: function(context) {
// currentTime is frozen during execution, use performance timers to
// emulate the current time at call time
- return (window['performance']['now']() - context.startTime) / 1000.0;
+ if (!context.startTime)
+ return 0;
+ else
+ return (window['performance']['now']() - context.startTime) / 1000.0;
},
updateSources: function(context) {
@@ -212,10 +219,10 @@ var LibraryOpenAL = {
err: 0,
src: [],
buf: [],
- interval: setInterval(function() { AL.updateSources(context); }, AL.QUEUE_INTERVAL),
- startTime: window['performance']['now']()
+ interval: setInterval(function() { AL.updateSources(context); }, AL.QUEUE_INTERVAL)
};
AL.contexts.push(context);
+ setTimeout(AL.updateStartTime, 0, context);
return AL.contexts.length;
} else {
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment