mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-11-26 10:49:17 +00:00
use requestAnimationFrame(); fixed too many audio contexts
This commit is contained in:
parent
59cd5f78fa
commit
8df7102b69
@ -2,8 +2,8 @@
|
||||
|
||||
var MasterAudio = function() {
|
||||
this.master = new MasterChannel();
|
||||
this.looper = new AudioLooper(512);
|
||||
this.start = function() {
|
||||
this.looper = new AudioLooper(512);
|
||||
this.looper.setChannel(this.master);
|
||||
this.looper.activate();
|
||||
}
|
||||
|
13
src/emu.js
13
src/emu.js
@ -201,7 +201,8 @@ var RAM = function(size) {
|
||||
var AnimationTimer = function(frequencyHz, callback) {
|
||||
var intervalMsec = 1000.0 / frequencyHz;
|
||||
var running;
|
||||
var useReqAnimFrame = false; // TODO: enable?
|
||||
var lastts = 0;
|
||||
var useReqAnimFrame = true;
|
||||
|
||||
function scheduleFrame() {
|
||||
if (useReqAnimFrame)
|
||||
@ -210,7 +211,14 @@ var AnimationTimer = function(frequencyHz, callback) {
|
||||
setTimeout(nextFrame, intervalMsec);
|
||||
}
|
||||
var nextFrame = function(ts) {
|
||||
callback();
|
||||
if (!useReqAnimFrame || ts - lastts > intervalMsec/2) {
|
||||
if (ts - lastts < intervalMsec*30) {
|
||||
lastts += intervalMsec;
|
||||
} else {
|
||||
lastts = ts;
|
||||
}
|
||||
callback();
|
||||
}
|
||||
if (running) {
|
||||
scheduleFrame();
|
||||
}
|
||||
@ -221,6 +229,7 @@ var AnimationTimer = function(frequencyHz, callback) {
|
||||
this.start = function() {
|
||||
if (!running) {
|
||||
running = true;
|
||||
lastts = 0;
|
||||
scheduleFrame();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user