-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,47 +2,54 @@ | |
* Patch to port old implementation of `webkitAudioContext` | ||
* to standards based `audioContext`. | ||
* | ||
* Props to Lajos György Mészáros <[email protected]> for this patch. | ||
* Props to Lajos György Mészáros <[email protected]> for this patch, | ||
* although some edits were needed to make it work. | ||
* @see https://github.com/meszaros-lajos-gyorgy/meszaros-lajos-gyorgy.github.io/blob/master/microtonal/monochord/js/webkit-audio-context-patch.js | ||
*/ | ||
|
||
/* globals OscillatorNode */ | ||
|
||
"use strict"; | ||
|
||
module.exports = function(){ | ||
var AudioContext, | ||
OscillatorNode, | ||
oldStart, | ||
oldStop; | ||
|
||
if( !window.hasOwnProperty("AudioContext") && | ||
window.hasOwnProperty("webkitAudioContext") ){ | ||
var a = window.AudioContext = window.webkitAudioContext; | ||
AudioContext = window.AudioContext = window.webkitAudioContext; | ||
OscillatorNode = window.OscillatorNode; | ||
|
||
if(!a.prototype.hasOwnProperty("createGain")){ | ||
a.prototype.createGain = a.prototype.createGainNode; | ||
if(!AudioContext.prototype.hasOwnProperty("createGain")){ | ||
AudioContext.prototype.createGain = AudioContext.prototype.createGainNode; | ||
} | ||
|
||
if(!OscillatorNode.prototype.hasOwnProperty("start")){ | ||
OscillatorNode.prototype.start = OscillatorNode.prototype.noteOn; | ||
} | ||
|
||
// make the first parameter optional for firefox <30 | ||
var oldStart = OscillatorNode.prototype.start; | ||
OscillatorNode.prototype.start = function(t){ | ||
oldStart(t || 0); | ||
oldStart = OscillatorNode.prototype.start; | ||
OscillatorNode.prototype.start = function(t = 0){ | ||
oldStart.call(this, t); | ||
}; | ||
|
||
if(!OscillatorNode.prototype.hasOwnProperty("stop")){ | ||
OscillatorNode.prototype.stop = OscillatorNode.prototype.noteOff; | ||
} | ||
|
||
// make the first parameter optional for firefox <30 | ||
var oldStop = OscillatorNode.prototype.stop; | ||
OscillatorNode.prototype.stop = function(t){ | ||
oldStop(t || 0); | ||
oldStop = OscillatorNode.prototype.stop; | ||
OscillatorNode.prototype.stop = function(t = 0){ | ||
oldStop.call(this, t); | ||
}; | ||
|
||
Object.defineProperty(OscillatorNode.prototype, "type", { | ||
get : function(){ | ||
get: function() { | ||
return ["sine", "square", "sawtooth", "triangle", "custom"][this.type]; | ||
}, | ||
set : function(type){ | ||
this.type = OscillatorNode.prototype[type.toUpperCase()]; | ||
set: function(type) { | ||
this.type = OscillatorNode.prototype[type.toUpperCase()] || type; | ||
} | ||
}); | ||
} | ||
|
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