diff --git a/js/other/XAudioServer.js b/js/other/XAudioServer.js index 6932421d..784fbbb5 100644 --- a/js/other/XAudioServer.js +++ b/js/other/XAudioServer.js @@ -204,7 +204,29 @@ XAudioServer.prototype.initializeWebAudio = function () { XAudioJSWebAudioAudioNode = XAudioJSWebAudioContextHandle.createJavaScriptNode(XAudioJSSamplesPerCallback, 0, XAudioJSChannelsAllocated); //Create the js event node. } 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. + var gainNode = XAudioJSWebAudioContextHandle.createGain(); + XAudioJSWebAudioAudioNode.connect(gainNode); //Connect the audio processing event to a handling function so we can manipulate output + gainNode.connect(XAudioJSWebAudioContextHandle.destination); + gainNode.gain.value = 0.001; + gainNode.gain.exponentialRampToValueAtTime( + 1, + XAudioJSWebAudioContextHandle.currentTime + 0.5 + ); + + document.addEventListener("visibilitychange", function(event) { + if (document.hidden) { + gainNode.gain.exponentialRampToValueAtTime( + 0.0001, + XAudioJSWebAudioContextHandle.currentTime + 0.5 + ); + } else { + gainNode.gain.exponentialRampToValueAtTime( + 1, + XAudioJSWebAudioContextHandle.currentTime + 0.5 + ); + } + }); + this.resetCallbackAPIAudioBuffer(XAudioJSWebAudioContextHandle.sampleRate); this.audioType = 1; /*