diff options
| author | s1nical <[email protected]> | 2019-08-15 22:26:43 -0700 |
|---|---|---|
| committer | s1nical <[email protected]> | 2019-08-15 22:26:43 -0700 |
| commit | cbbf483d4bb753df4ebea18905605efe9ccb9bca (patch) | |
| tree | 43df9aae6322569d043e6a7c7615596ef5e94d22 /wolf3d/js/webkitAudioContextMonkeyPatch.js | |
| parent | remvoed directory loader but kept code (diff) | |
| download | s1n.pw-admin-cbbf483d4bb753df4ebea18905605efe9ccb9bca.tar.xz s1n.pw-admin-cbbf483d4bb753df4ebea18905605efe9ccb9bca.zip | |
add wolfenstein 3d to games directory
Diffstat (limited to 'wolf3d/js/webkitAudioContextMonkeyPatch.js')
| -rw-r--r-- | wolf3d/js/webkitAudioContextMonkeyPatch.js | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/wolf3d/js/webkitAudioContextMonkeyPatch.js b/wolf3d/js/webkitAudioContextMonkeyPatch.js new file mode 100644 index 0000000..6ce16bd --- /dev/null +++ b/wolf3d/js/webkitAudioContextMonkeyPatch.js @@ -0,0 +1,175 @@ +/* Copyright 2013 Chris Wilson + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* + +This monkeypatch library is intended to be included in projects that use +webkitAudioContext (instead of AudioContext), and that may use the now- +deprecated bits of the Web Audio API (e.g. using BufferSourceNode.noteOn() +instead of BufferSourceNode.start(). + +This library should be harmless to include if the browser does not have +the unprefixed "AudioContext" implemented. If unprefixed AudioContext is +supported, but the deprecated method names are already implemented, this +library will have created a few shim functions on create* methods, but +will not damage or override anything else. + +Ideally, the use of this library will go to zero - it is only intended as +a way to quickly get script written to the old Web Audio methods to work +in browsers that only support the new, approved methods. + +The patches this library handles: + +AudioBufferSourceNode.noteOn() is aliased to start() +AudioBufferSourceNode.noteGrainOn() is aliased to start() +AudioBufferSourceNode.noteOff() is aliased to stop() +AudioContext.createGainNode() is aliased to createGain() +AudioContext.createDelayNode() is aliased to createDelay() +AudioContext.createJavaScriptNode() is aliased to createScriptProcessor() +OscillatorNode.noteOn() is aliased to start() +OscillatorNode.noteOff() is aliased to stop() +AudioParam.setTargetValueAtTime() is aliased to setTargetAtTime() +OscillatorNode's old enum values are aliased to the Web IDL enum values. +BiquadFilterNode's old enum values are aliased to the Web IDL enum values. +PannerNode's old enum values are aliased to the Web IDL enum values. +AudioContext.createWaveTable() is aliased to createPeriodicWave(). +OscillatorNode.setWaveTable() is aliased to setPeriodicWave(). + +*/ +(function (global, exports, perf) { + 'use strict'; + + function fixSetTarget(param) { + if (!param) // if NYI, just return + return; + if (!param.setTargetValueAtTime) + param.setTargetValueAtTime = param.setTargetAtTime; + } + + if (window.hasOwnProperty('AudioContext') /*&& !window.hasOwnProperty('webkitAudioContext') */) { + window.webkitAudioContext = AudioContext; + + AudioContext.prototype.internal_createGain = AudioContext.prototype.createGain; + AudioContext.prototype.createGain = function() { + var node = this.internal_createGain(); + fixSetTarget(node.gain); + return node; + }; + + AudioContext.prototype.internal_createDelay = AudioContext.prototype.createDelay; + AudioContext.prototype.createDelay = function() { + var node = this.internal_createDelay(); + fixSetTarget(node.delayTime); + return node; + }; + + AudioContext.prototype.internal_createBufferSource = AudioContext.prototype.createBufferSource; + AudioContext.prototype.createBufferSource = function() { + var node = this.internal_createBufferSource(); + if (!node.noteOn) + node.noteOn = node.start; + if (!node.noteGrainOn) + node.noteGrainOn = node.start; + if (!node.noteOff) + node.noteOff = node.stop; + fixSetTarget(node.playbackRate); + return node; + }; + + AudioContext.prototype.internal_createDynamicsCompressor = AudioContext.prototype.createDynamicsCompressor; + AudioContext.prototype.createDynamicsCompressor = function() { + var node = this.internal_createDynamicsCompressor(); + fixSetTarget(node.threshold); + fixSetTarget(node.knee); + fixSetTarget(node.ratio); + fixSetTarget(node.reduction); + fixSetTarget(node.attack); + fixSetTarget(node.release); + return node; + }; + + AudioContext.prototype.internal_createBiquadFilter = AudioContext.prototype.createBiquadFilter; + AudioContext.prototype.createBiquadFilter = function() { + var node = this.internal_createBiquadFilter(); + fixSetTarget(node.frequency); + fixSetTarget(node.detune); + fixSetTarget(node.Q); + fixSetTarget(node.gain); + var enumValues = ['LOWPASS', 'HIGHPASS', 'BANDPASS', 'LOWSHELF', 'HIGHSHELF', 'PEAKING', 'NOTCH', 'ALLPASS']; + for (var i = 0; i < enumValues.length; ++i) { + var enumValue = enumValues[i]; + var newEnumValue = enumValue.toLowerCase(); + if (!node.hasOwnProperty(enumValue)) { + node[enumValue] = newEnumValue; + } + } + return node; + }; + + if (AudioContext.prototype.hasOwnProperty( 'createOscillator' )) { + AudioContext.prototype.internal_createOscillator = AudioContext.prototype.createOscillator; + AudioContext.prototype.createOscillator = function() { + var node = this.internal_createOscillator(); + if (!node.noteOn) + node.noteOn = node.start; + if (!node.noteOff) + node.noteOff = node.stop; + fixSetTarget(node.frequency); + fixSetTarget(node.detune); + var enumValues = ['SINE', 'SQUARE', 'SAWTOOTH', 'TRIANGLE', 'CUSTOM']; + for (var i = 0; i < enumValues.length; ++i) { + var enumValue = enumValues[i]; + var newEnumValue = enumValue.toLowerCase(); + if (!node.hasOwnProperty(enumValue)) { + node[enumValue] = newEnumValue; + } + } + if (!node.hasOwnProperty('setWaveTable')) { + node.setWaveTable = node.setPeriodicTable; + } + return node; + }; + } + + AudioContext.prototype.internal_createPanner = AudioContext.prototype.createPanner; + AudioContext.prototype.createPanner = function() { + var node = this.internal_createPanner(); + var enumValues = { + 'EQUALPOWER': 'equalpower', + 'HRTF': 'HRTF', + 'LINEAR_DISTANCE': 'linear', + 'INVERSE_DISTANCE': 'inverse', + 'EXPONENTIAL_DISTANCE': 'exponential', + }; + for (var enumValue in enumValues) { + var newEnumValue = enumValues[enumValue]; + if (!node.hasOwnProperty(enumValue)) { + node[enumValue] = newEnumValue; + } + } + return node; + }; + + if (!AudioContext.prototype.hasOwnProperty('createGainNode')) + AudioContext.prototype.createGainNode = AudioContext.prototype.createGain; + if (!AudioContext.prototype.hasOwnProperty('createDelayNode')) + AudioContext.prototype.createDelayNode = AudioContext.prototype.createDelay; + if (!AudioContext.prototype.hasOwnProperty('createJavaScriptNode')) + AudioContext.prototype.createJavaScriptNode = AudioContext.prototype.createScriptProcessor; + if (!AudioContext.prototype.hasOwnProperty('createWaveTable')) + AudioContext.prototype.createWaveTable = AudioContext.prototype.createPeriodicWave; + } +}(window)); + |