Skip to content

Commit 332db54

Browse files
committed
move shims to new shims module
1 parent 80c3d54 commit 332db54

File tree

4 files changed

+207
-197
lines changed

4 files changed

+207
-197
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = function(grunt) {
6565
'Tone' : 'node_modules/tone/Tone',
6666
'automation-timeline': 'node_modules/web-audio-automation-timeline/build/automation-timeline-amd',
6767
'panner' : 'src/panner',
68+
'shims': 'src/shims',
6869
'audiocontext': 'src/audiocontext',
6970
'master': 'src/master',
7071
'helpers': 'src/helpers',

src/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
define(function (require) {
44

5+
require('shims');
56
require('audiocontext');
67
var p5SOUND = require('master');
78
require('helpers');

src/audiocontext.js

Lines changed: 1 addition & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,6 @@
11
'use strict';
22

33
define(function () {
4-
5-
/* AudioContext Monkeypatch
6-
Copyright 2013 Chris Wilson
7-
Licensed under the Apache License, Version 2.0 (the "License");
8-
you may not use this file except in compliance with the License.
9-
You may obtain a copy of the License at
10-
http://www.apache.org/licenses/LICENSE-2.0
11-
Unless required by applicable law or agreed to in writing, software
12-
distributed under the License is distributed on an "AS IS" BASIS,
13-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
See the License for the specific language governing permissions and
15-
limitations under the License.
16-
*/
17-
(function () {
18-
function fixSetTarget(param) {
19-
if (!param) // if NYI, just return
20-
return;
21-
if (!param.setTargetAtTime)
22-
param.setTargetAtTime = param.setTargetValueAtTime;
23-
}
24-
25-
if (window.hasOwnProperty('webkitAudioContext') &&
26-
!window.hasOwnProperty('AudioContext')) {
27-
window.AudioContext = window.webkitAudioContext;
28-
29-
if (typeof AudioContext.prototype.createGain !== 'function')
30-
AudioContext.prototype.createGain = AudioContext.prototype.createGainNode;
31-
if (typeof AudioContext.prototype.createDelay !== 'function')
32-
AudioContext.prototype.createDelay = AudioContext.prototype.createDelayNode;
33-
if (typeof AudioContext.prototype.createScriptProcessor !== 'function')
34-
AudioContext.prototype.createScriptProcessor = AudioContext.prototype.createJavaScriptNode;
35-
if (typeof AudioContext.prototype.createPeriodicWave !== 'function')
36-
AudioContext.prototype.createPeriodicWave = AudioContext.prototype.createWaveTable;
37-
38-
39-
AudioContext.prototype.internal_createGain = AudioContext.prototype.createGain;
40-
AudioContext.prototype.createGain = function() {
41-
var node = this.internal_createGain();
42-
fixSetTarget(node.gain);
43-
return node;
44-
};
45-
46-
AudioContext.prototype.internal_createDelay = AudioContext.prototype.createDelay;
47-
AudioContext.prototype.createDelay = function(maxDelayTime) {
48-
var node = maxDelayTime ? this.internal_createDelay(maxDelayTime) : this.internal_createDelay();
49-
fixSetTarget(node.delayTime);
50-
return node;
51-
};
52-
53-
AudioContext.prototype.internal_createBufferSource = AudioContext.prototype.createBufferSource;
54-
AudioContext.prototype.createBufferSource = function() {
55-
var node = this.internal_createBufferSource();
56-
if (!node.start) {
57-
node.start = function ( when, offset, duration ) {
58-
if ( offset || duration )
59-
this.noteGrainOn( when || 0, offset, duration );
60-
else
61-
this.noteOn( when || 0 );
62-
};
63-
} else {
64-
node.internal_start = node.start;
65-
node.start = function( when, offset, duration ) {
66-
if( typeof duration !== 'undefined' )
67-
node.internal_start( when || 0, offset, duration );
68-
else
69-
node.internal_start( when || 0, offset || 0 );
70-
};
71-
}
72-
if (!node.stop) {
73-
node.stop = function ( when ) {
74-
this.noteOff( when || 0 );
75-
};
76-
} else {
77-
node.internal_stop = node.stop;
78-
node.stop = function( when ) {
79-
node.internal_stop( when || 0 );
80-
};
81-
}
82-
fixSetTarget(node.playbackRate);
83-
return node;
84-
};
85-
86-
AudioContext.prototype.internal_createDynamicsCompressor = AudioContext.prototype.createDynamicsCompressor;
87-
AudioContext.prototype.createDynamicsCompressor = function() {
88-
var node = this.internal_createDynamicsCompressor();
89-
fixSetTarget(node.threshold);
90-
fixSetTarget(node.knee);
91-
fixSetTarget(node.ratio);
92-
fixSetTarget(node.reduction);
93-
fixSetTarget(node.attack);
94-
fixSetTarget(node.release);
95-
return node;
96-
};
97-
98-
AudioContext.prototype.internal_createBiquadFilter = AudioContext.prototype.createBiquadFilter;
99-
AudioContext.prototype.createBiquadFilter = function() {
100-
var node = this.internal_createBiquadFilter();
101-
fixSetTarget(node.frequency);
102-
fixSetTarget(node.detune);
103-
fixSetTarget(node.Q);
104-
fixSetTarget(node.gain);
105-
return node;
106-
};
107-
108-
if (typeof AudioContext.prototype.createOscillator !== 'function') {
109-
AudioContext.prototype.internal_createOscillator = AudioContext.prototype.createOscillator;
110-
AudioContext.prototype.createOscillator = function() {
111-
var node = this.internal_createOscillator();
112-
if (!node.start) {
113-
node.start = function ( when ) {
114-
this.noteOn( when || 0 );
115-
};
116-
} else {
117-
node.internal_start = node.start;
118-
node.start = function ( when ) {
119-
node.internal_start( when || 0);
120-
};
121-
}
122-
if (!node.stop) {
123-
node.stop = function ( when ) {
124-
this.noteOff( when || 0 );
125-
};
126-
} else {
127-
node.internal_stop = node.stop;
128-
node.stop = function( when ) {
129-
node.internal_stop( when || 0 );
130-
};
131-
}
132-
if (!node.setPeriodicWave)
133-
node.setPeriodicWave = node.setWaveTable;
134-
fixSetTarget(node.frequency);
135-
fixSetTarget(node.detune);
136-
return node;
137-
};
138-
}
139-
}
140-
141-
if (window.hasOwnProperty('webkitOfflineAudioContext') &&
142-
!window.hasOwnProperty('OfflineAudioContext')) {
143-
window.OfflineAudioContext = window.webkitOfflineAudioContext;
144-
}
145-
146-
})(window);
147-
// <-- end MonkeyPatch.
148-
1494
// Create the Audio Context
1505
var audiocontext = new window.AudioContext();
1516

@@ -162,58 +17,6 @@ define(function () {
16217
return audiocontext;
16318
};
16419

165-
// Polyfill for AudioIn, also handled by p5.dom createCapture
166-
navigator.getUserMedia = navigator.getUserMedia ||
167-
navigator.webkitGetUserMedia ||
168-
navigator.mozGetUserMedia ||
169-
navigator.msGetUserMedia;
170-
171-
172-
/**
173-
* Determine which filetypes are supported (inspired by buzz.js)
174-
* The audio element (el) will only be used to test browser support for various audio formats
175-
*/
176-
var el = document.createElement('audio');
177-
178-
p5.prototype.isSupported = function() {
179-
return !!el.canPlayType;
180-
};
181-
var isOGGSupported = function() {
182-
return !!el.canPlayType && el.canPlayType('audio/ogg; codecs="vorbis"');
183-
};
184-
var isMP3Supported = function() {
185-
return !!el.canPlayType && el.canPlayType('audio/mpeg;');
186-
};
187-
var isWAVSupported = function() {
188-
return !!el.canPlayType && el.canPlayType('audio/wav; codecs="1"');
189-
};
190-
var isAACSupported = function() {
191-
return !!el.canPlayType && (el.canPlayType('audio/x-m4a;') || el.canPlayType('audio/aac;'));
192-
};
193-
var isAIFSupported = function() {
194-
return !!el.canPlayType && el.canPlayType('audio/x-aiff;');
195-
};
196-
p5.prototype.isFileSupported = function(extension) {
197-
switch(extension.toLowerCase())
198-
{
199-
case 'mp3':
200-
return isMP3Supported();
201-
case 'wav':
202-
return isWAVSupported();
203-
case 'ogg':
204-
return isOGGSupported();
205-
case 'aac':
206-
case 'm4a':
207-
case 'mp4':
208-
return isAACSupported();
209-
case 'aif':
210-
case 'aiff':
211-
return isAIFSupported();
212-
default:
213-
return false;
214-
}
215-
};
216-
21720
// if it is iOS, we have to have a user interaction to start Web Audio
21821
// http://paulbakaus.com/tutorials/html5/web-audio-on-ios/
21922
var iOS = navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false ;
@@ -243,4 +46,5 @@ define(function () {
24346
// TO DO: fake touch event so that audio will just start
24447
}
24548

49+
return audiocontext;
24650
});

0 commit comments

Comments
 (0)