Created
June 11, 2013 00:45
-
-
Save srikumarks/5753704 to your computer and use it in GitHub Desktop.
Get an AudioContext class that has "future compatible" names for methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gets the AudioContext class when in a browser environment. | |
function getAudioContext() { | |
try { | |
var AC = (window.AudioContext || window.webkitAudioContext || window.mozAudioContext); | |
function myAC() { | |
var ac = new AC(); | |
// Future compatible names. | |
ac.createGain = ac.createGainNode = (ac.createGain || ac.createGainNode); | |
ac.createDelay = ac.createDelayNode = ac.createDelay || ac.createDelayNode; | |
ac.createScriptProcessor = ac.createJavaScriptNode = (ac.createScriptProcessor || ac.createJavaScriptNode); | |
var AudioParam = ac.createGain().gain.__proto__.__proto__; | |
AudioParam.setTargetAtTime = AudioParam.setTargetValueAtTime = (AudioParam.setTargetAtTime || AudioParam.setTargetValueAtTime); | |
var BufferSource = ac.createBufferSource().__proto__; | |
BufferSource.start = BufferSource.noteOn = (BufferSource.start || BufferSource.noteOn); | |
BufferSource.stop = BufferSource.noteOff = (BufferSource.stop || BufferSource.noteOff); | |
var Oscillator = ac.createOscillator().__proto__; | |
Oscillator.start = Oscillator.noteOn = (Oscillator.start || Oscillator.noteOn); | |
Oscillator.stop = Oscillator.noteOff = (Oscillator.stop || Oscillator.noteOff); | |
return ac; | |
} | |
return myAC; | |
} catch (e) { | |
return undefined; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment