mirror of
https://github.com/DPS2004/gba.git
synced 2025-01-22 20:40:32 -03:00
Update XAudioServer.js
This commit is contained in:
parent
b24d7c6fca
commit
6c15b6a834
1 changed files with 48 additions and 50 deletions
|
@ -165,61 +165,29 @@ XAudioServer.prototype.initializeMozAudio = function () {
|
||||||
this.initializeResampler(XAudioJSMozAudioSampleRate);
|
this.initializeResampler(XAudioJSMozAudioSampleRate);
|
||||||
}
|
}
|
||||||
XAudioServer.prototype.initializeWebAudio = function () {
|
XAudioServer.prototype.initializeWebAudio = function () {
|
||||||
if (!this.userEventLatch) {
|
if (typeof AudioContext == "undefined" || typeof XAudioJSWebAudioContextHandle == "undefined") {
|
||||||
this.setupWebAudio();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//TODO: Restructure API to not have to potentially lie to end client about
|
|
||||||
//the samples in buffer before user driven event callback that actually starts WA.
|
|
||||||
this.resetCallbackAPIAudioBuffer(44100);
|
|
||||||
}
|
|
||||||
if (typeof AudioContext != "undefined" || typeof XAudioJSWebAudioContextHandle != "undefined") {
|
|
||||||
throw null;
|
throw null;
|
||||||
}
|
}
|
||||||
this.audioType = 1;
|
else {
|
||||||
/*
|
if (!this.userEventLatch) {
|
||||||
Firefox has a bug in its web audio implementation...
|
this.setupWebAudio();
|
||||||
The node may randomly stop playing on Mac OS X for no
|
}
|
||||||
good reason. Keep a watchdog timer to restart the failed
|
else {
|
||||||
node if it glitches. Google Chrome never had this issue.
|
var parentObj = this;
|
||||||
*/
|
var lazyEnableWA = function () {
|
||||||
XAudioJSWebAudioWatchDogLast = (new Date()).getTime();
|
|
||||||
if (navigator.userAgent.indexOf('Gecko/') > -1) {
|
|
||||||
if (XAudioJSWebAudioWatchDogTimer) {
|
|
||||||
clearInterval(XAudioJSWebAudioWatchDogTimer);
|
|
||||||
}
|
|
||||||
var parentObj = this;
|
|
||||||
XAudioJSWebAudioWatchDogTimer = setInterval(function () {
|
|
||||||
if(typeof XAudioJSWebAudioContextHandle.state != "undefined") {
|
|
||||||
if (XAudioJSWebAudioContextHandle.state === 'suspended') {
|
|
||||||
XAudioJSWebAudioWatchDogLast = (new Date()).getTime();
|
|
||||||
try {
|
|
||||||
XAudioJSWebAudioContextHandle.resume();
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var timeDiff = (new Date()).getTime() - XAudioJSWebAudioWatchDogLast;
|
|
||||||
if (timeDiff > 500) {
|
|
||||||
parentObj.setupWebAudio();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
if (this.userEventLatch && typeof XAudioJSWebAudioContextHandle.state != "undefined") {
|
|
||||||
var parentObj = this;
|
|
||||||
var lazyEnableWA = function () {
|
|
||||||
if(XAudioJSWebAudioContextHandle.state === 'suspended') {
|
|
||||||
parentObj.setupWebAudio();
|
parentObj.setupWebAudio();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
this.userEventLatch.addEventListener("click", lazyEnableWA, false);
|
||||||
|
this.userEventLatch.addEventListener("touchstart", lazyEnableWA, false);
|
||||||
|
this.userEventLatch.addEventListener("touchend", lazyEnableWA, false);
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
//TODO: Restructure API to not have to potentially lie to end client about
|
||||||
|
//the samples in buffer before user driven event callback that actually starts WA.
|
||||||
|
this.resetCallbackAPIAudioBuffer(44100);
|
||||||
}
|
}
|
||||||
try {
|
this.audioType = 1;
|
||||||
this.userEventLatch.addEventListener("click", lazyEnableWA, false);
|
|
||||||
this.userEventLatch.addEventListener("touchstart", lazyEnableWA, false);
|
|
||||||
this.userEventLatch.addEventListener("touchend", lazyEnableWA, false);
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XAudioServer.prototype.setupWebAudio = function () {
|
XAudioServer.prototype.setupWebAudio = function () {
|
||||||
|
@ -247,6 +215,36 @@ XAudioServer.prototype.setupWebAudio = function () {
|
||||||
XAudioJSWebAudioAudioNode.onaudioprocess = XAudioJSWebAudioEvent; //Connect the audio processing event to a handling function so we can manipulate output
|
XAudioJSWebAudioAudioNode.onaudioprocess = XAudioJSWebAudioEvent; //Connect the audio processing event to a handling function so we can manipulate output
|
||||||
XAudioJSWebAudioAudioNode.connect(XAudioJSWebAudioContextHandle.destination); //Send and chain the output of the audio manipulation to the system audio output.
|
XAudioJSWebAudioAudioNode.connect(XAudioJSWebAudioContextHandle.destination); //Send and chain the output of the audio manipulation to the system audio output.
|
||||||
this.resetCallbackAPIAudioBuffer(XAudioJSWebAudioContextHandle.sampleRate);
|
this.resetCallbackAPIAudioBuffer(XAudioJSWebAudioContextHandle.sampleRate);
|
||||||
|
/*
|
||||||
|
Firefox has a bug in its web audio implementation...
|
||||||
|
The node may randomly stop playing on Mac OS X for no
|
||||||
|
good reason. Keep a watchdog timer to restart the failed
|
||||||
|
node if it glitches. Google Chrome never had this issue.
|
||||||
|
*/
|
||||||
|
XAudioJSWebAudioWatchDogLast = (new Date()).getTime();
|
||||||
|
if (!XAudioJSWebAudioWatchDogTimer && navigator.userAgent.indexOf('Gecko/') > -1) {
|
||||||
|
if (XAudioJSWebAudioWatchDogTimer) {
|
||||||
|
clearInterval(XAudioJSWebAudioWatchDogTimer);
|
||||||
|
}
|
||||||
|
var parentObj = this;
|
||||||
|
XAudioJSWebAudioWatchDogTimer = setInterval(function () {
|
||||||
|
if(typeof XAudioJSWebAudioContextHandle.state != "undefined") {
|
||||||
|
if (XAudioJSWebAudioContextHandle.state === 'suspended') {
|
||||||
|
XAudioJSWebAudioWatchDogLast = (new Date()).getTime();
|
||||||
|
try {
|
||||||
|
XAudioJSWebAudioContextHandle.resume();
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var timeDiff = (new Date()).getTime() - XAudioJSWebAudioWatchDogLast;
|
||||||
|
if (timeDiff > 500) {
|
||||||
|
parentObj.setupWebAudio();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
XAudioServer.prototype.initializeFlashAudio = function () {
|
XAudioServer.prototype.initializeFlashAudio = function () {
|
||||||
var existingFlashload = document.getElementById("XAudioJS");
|
var existingFlashload = document.getElementById("XAudioJS");
|
||||||
|
|
Loading…
Add table
Reference in a new issue