mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-16 17:30:27 +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() {
|
var MasterAudio = function() {
|
||||||
this.master = new MasterChannel();
|
this.master = new MasterChannel();
|
||||||
|
this.looper = new AudioLooper(512);
|
||||||
this.start = function() {
|
this.start = function() {
|
||||||
this.looper = new AudioLooper(512);
|
|
||||||
this.looper.setChannel(this.master);
|
this.looper.setChannel(this.master);
|
||||||
this.looper.activate();
|
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 AnimationTimer = function(frequencyHz, callback) {
|
||||||
var intervalMsec = 1000.0 / frequencyHz;
|
var intervalMsec = 1000.0 / frequencyHz;
|
||||||
var running;
|
var running;
|
||||||
var useReqAnimFrame = false; // TODO: enable?
|
var lastts = 0;
|
||||||
|
var useReqAnimFrame = true;
|
||||||
|
|
||||||
function scheduleFrame() {
|
function scheduleFrame() {
|
||||||
if (useReqAnimFrame)
|
if (useReqAnimFrame)
|
||||||
@ -210,7 +211,14 @@ var AnimationTimer = function(frequencyHz, callback) {
|
|||||||
setTimeout(nextFrame, intervalMsec);
|
setTimeout(nextFrame, intervalMsec);
|
||||||
}
|
}
|
||||||
var nextFrame = function(ts) {
|
var nextFrame = function(ts) {
|
||||||
callback();
|
if (!useReqAnimFrame || ts - lastts > intervalMsec/2) {
|
||||||
|
if (ts - lastts < intervalMsec*30) {
|
||||||
|
lastts += intervalMsec;
|
||||||
|
} else {
|
||||||
|
lastts = ts;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
if (running) {
|
if (running) {
|
||||||
scheduleFrame();
|
scheduleFrame();
|
||||||
}
|
}
|
||||||
@ -221,6 +229,7 @@ var AnimationTimer = function(frequencyHz, callback) {
|
|||||||
this.start = function() {
|
this.start = function() {
|
||||||
if (!running) {
|
if (!running) {
|
||||||
running = true;
|
running = true;
|
||||||
|
lastts = 0;
|
||||||
scheduleFrame();
|
scheduleFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user