Skip to content

Commit 53da932

Browse files
author
Lanny McNie
committed
WebAudio and HTMLAudio - change to suppress errors in old browsers that do not support object.defineProperty
Signed-off-by: Lanny McNie <[email protected]>
1 parent 9a9577c commit 53da932

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

VERSIONS.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Version NEXT
22
************************************************************************************************************************
33
- suppressing errors in WebAudioPlugin and HTMLAudioPlugin in old browsers that do not properly support object.defineProperty
4+
- changes to WebAudioPlugin to allow it to work with lasted working draft of Web Audio API
5+
- WebAudioPlugin changed SoundInstance node order to SourceNode -> PanNode -> GainNode --> context.destination to get
6+
around firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=933304
47

58
Version 0.5.0 [September 25, 2013]
69
************************************************************************************************************************

src/soundjs/WebAudioPlugin.js

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ this.createjs = this.createjs || {};
160160
return null;
161161
}
162162

163-
// this handles if only deprecated calls are supported
163+
// this handles if only deprecated Web Audio API calls are supported
164164
s.compatibilitySetUp();
165165

166166
// playing this inside of a touch event will enable audio on iOS, which starts muted
@@ -699,31 +699,31 @@ this.createjs = this.createjs || {};
699699

700700
/**
701701
* NOTE this only exists as a {{#crossLink "WebAudioPlugin"}}{{/crossLink}} property and is only intended for use by advanced users.
702-
* A panNode allowing left and right audio channel panning only. Connected to our WebAudioPlugin {{#crossLink "WebAudioPlugin/gainNode:property"}}{{/crossLink}}
702+
* GainNode for controlling <code>SoundInstance</code> volume. Connected to the WebAudioPlugin {{#crossLink "WebAudioPlugin/gainNode:property"}}{{/crossLink}}
703703
* that sequences to <code>context.destination</code>.
704-
* @property panNode
705-
* @type {AudioPannerNode}
704+
* @property gainNode
705+
* @type {AudioGainNode}
706706
* @default null
707707
* @since 0.4.0
708+
*
708709
*/
709-
p.panNode = null;
710+
p.gainNode = null;
710711

711712
/**
712713
* NOTE this only exists as a {{#crossLink "WebAudioPlugin"}}{{/crossLink}} property and is only intended for use by advanced users.
713-
* GainNode for controlling <code>SoundInstance</code> volume. Connected to {{#crossLink "SoundInstance/panNode:property"}}{{/crossLink}}.
714-
* @property gainNode
715-
* @type {AudioGainNode}
714+
* A panNode allowing left and right audio channel panning only. Connected to SoundInstance {{#crossLink "SoundInstance/gainNode:property"}}{{/crossLink}}.
715+
* @property panNode
716+
* @type {AudioPannerNode}
716717
* @default null
717718
* @since 0.4.0
718-
*
719719
*/
720-
p.gainNode = null;
720+
p.panNode = null;
721721

722722
/**
723723
* NOTE this only exists as a {{#crossLink "WebAudioPlugin"}}{{/crossLink}} property and is only intended for use by advanced users.
724724
* sourceNode is the audio source. Connected to {{#crossLink "SoundInstance/gainNode:property"}}{{/crossLink}}.
725725
* @property sourceNode
726-
* @type {AudioSourceNode}
726+
* @type {AudioNode}
727727
* @default null
728728
* @since 0.4.0
729729
*
@@ -735,7 +735,7 @@ this.createjs = this.createjs || {};
735735
* sourceNodeNext is the audio source for the next loop, inserted in a look ahead approach to allow for smooth
736736
* looping. Connected to {{#crossLink "SoundInstance/gainNode:property"}}{{/crossLink}}.
737737
* @property sourceNodeNext
738-
* @type {AudioSourceNode}
738+
* @type {AudioNode}
739739
* @default null
740740
* @protected
741741
* @since 0.4.1
@@ -908,11 +908,11 @@ this.createjs = this.createjs || {};
908908
this.owner = owner;
909909
this.src = src;
910910

911-
this.panNode = this.owner.context.createPanner(); // TODO test how this affects when we have mono audio
912-
this.panNode.panningModel = this.owner.panningModel;
913-
914911
this.gainNode = this.owner.context.createGain();
915-
this.gainNode.connect(this.panNode);
912+
913+
this.panNode = this.owner.context.createPanner(); //TODO test how this affects when we have mono audio
914+
this.panNode.panningModel = this.owner.panningModel;
915+
this.panNode.connect(this.gainNode);
916916

917917
if (this.owner.isPreloadComplete(this.src)) {
918918
this.duration = this.owner.arrayBuffers[this.src].duration * 1000;
@@ -929,14 +929,13 @@ this.createjs = this.createjs || {};
929929
* @protected
930930
*/
931931
p.cleanUp = function () {
932-
// if playbackState is UNSCHEDULED_STATE, then play has not been called so calling stop would throw an error
933-
if (this.sourceNode && this.sourceNode.playbackState != this.sourceNode.UNSCHEDULED_STATE) {
932+
if (this.sourceNode && this.playState == createjs.Sound.PLAY_SUCCEEDED) {
934933
this.sourceNode = this.cleanUpAudioNode(this.sourceNode);
935934
this.sourceNodeNext = this.cleanUpAudioNode(this.sourceNodeNext);
936935
}
937936

938-
if (this.panNode.numberOfOutputs != 0) {
939-
this.panNode.disconnect(0);
937+
if (this.gainNode.numberOfOutputs != 0) {
938+
this.gainNode.disconnect(0);
940939
} // this works because we only have one connection, and it returns 0 if we've already disconnected it.
941940
// OJR there appears to be a bug that this doesn't always work in webkit (Chrome and Safari). According to the documentation, this should work.
942941

@@ -961,7 +960,7 @@ this.createjs = this.createjs || {};
961960
p.cleanUpAudioNode = function(audioNode) {
962961
if(audioNode) {
963962
audioNode.stop(0);
964-
audioNode.disconnect(this.gainNode);
963+
audioNode.disconnect(this.panNode);
965964
audioNode = null; // release reference so Web Audio can handle removing references and garbage collection
966965
}
967966
return audioNode;
@@ -973,8 +972,8 @@ this.createjs = this.createjs || {};
973972
* @protected
974973
*/
975974
p.interrupt = function () {
976-
this.playState = createjs.Sound.PLAY_INTERRUPTED;
977975
this.cleanUp();
976+
this.playState = createjs.Sound.PLAY_INTERRUPTED;
978977
this.paused = false;
979978
this.sendEvent("interrupted");
980979
};
@@ -1000,7 +999,7 @@ this.createjs = this.createjs || {};
1000999
this.playState = createjs.Sound.PLAY_SUCCEEDED;
10011000
this.paused = false;
10021001

1003-
this.panNode.connect(this.owner.gainNode); // this line can cause a memory leak. Nodes need to be disconnected from the audioDestination or any sequence that leads to it.
1002+
this.gainNode.connect(this.owner.gainNode); // this line can cause a memory leak. Nodes need to be disconnected from the audioDestination or any sequence that leads to it.
10041003

10051004
var dur = this.owner.arrayBuffers[this.src].duration;
10061005
this.sourceNode = this.createAndPlayAudioNode((this.owner.context.currentTime - dur), this.offset);
@@ -1029,10 +1028,10 @@ this.createjs = this.createjs || {};
10291028
// The same is assumed for MediaStreamSource, although it may share the same commands as MediaElementSource.
10301029
var audioNode = this.owner.context.createBufferSource();
10311030
audioNode.buffer = this.owner.arrayBuffers[this.src];
1032-
audioNode.connect(this.gainNode);
1031+
audioNode.connect(this.panNode);
10331032
var currentTime = this.owner.context.currentTime;
10341033
audioNode.startTime = startTime + audioNode.buffer.duration; //currentTime + audioNode.buffer.duration - (currentTime - startTime);
1035-
audioNode.start(audioNode.startTime, offset, audioNode.buffer.duration - offset); // OJR deprecated in favor of start()
1034+
audioNode.start(audioNode.startTime, offset, audioNode.buffer.duration - offset);
10361035
return audioNode;
10371036
};
10381037

@@ -1119,8 +1118,8 @@ this.createjs = this.createjs || {};
11191118
this.cleanUpAudioNode(this.sourceNode);
11201119
this.cleanUpAudioNode(this.sourceNodeNext);
11211120

1122-
if (this.panNode.numberOfOutputs != 0) {
1123-
this.panNode.disconnect();
1121+
if (this.gainNode.numberOfOutputs != 0) {
1122+
this.gainNode.disconnect();
11241123
} // this works because we only have one connection, and it returns 0 if we've already disconnected it.
11251124

11261125
clearTimeout(this.delayTimeoutId); // clear timeout that plays delayed sound
@@ -1163,8 +1162,8 @@ this.createjs = this.createjs || {};
11631162
* @return {Boolean} If the stop call succeeds.
11641163
*/
11651164
p.stop = function () {
1166-
this.playState = createjs.Sound.PLAY_FINISHED;
11671165
this.cleanUp();
1166+
this.playState = createjs.Sound.PLAY_FINISHED;
11681167
this.offset = 0; // set audio to start at the beginning
11691168
return true;
11701169
};
@@ -1335,7 +1334,7 @@ this.createjs = this.createjs || {};
13351334
p.setPosition = function (value) {
13361335
this.offset = value / 1000; // convert milliseconds to seconds
13371336

1338-
if (this.sourceNode && this.sourceNode.playbackState != this.sourceNode.UNSCHEDULED_STATE) { // if playbackState is UNSCHEDULED_STATE, then play has not been called so calling stop would throw an error
1337+
if (this.sourceNode && this.playState == createjs.Sound.PLAY_SUCCEEDED) {
13391338
// we need to stop this sound from continuing to play, as we need to recreate the sourceNode to change position
13401339
this.cleanUpAudioNode(this.sourceNode);
13411340
this.cleanUpAudioNode(this.sourceNodeNext);
@@ -1396,8 +1395,8 @@ this.createjs = this.createjs || {};
13961395
if (window.createjs == null) {
13971396
return;
13981397
}
1399-
this.playState = createjs.Sound.PLAY_FINISHED;
14001398
this.cleanUp();
1399+
this.playState = createjs.Sound.PLAY_FINISHED;
14011400
this.sendEvent("complete");
14021401
};
14031402

@@ -1406,8 +1405,8 @@ this.createjs = this.createjs || {};
14061405
if (window.createjs == null) {
14071406
return;
14081407
}
1409-
this.playState = createjs.Sound.PLAY_FAILED;
14101408
this.cleanUp();
1409+
this.playState = createjs.Sound.PLAY_FAILED;
14111410
this.sendEvent("failed");
14121411
};
14131412

0 commit comments

Comments
 (0)