diff --git a/src/AudioPlayer.js b/src/AudioPlayer.js index 9f3a3db..868282e 100644 --- a/src/AudioPlayer.js +++ b/src/AudioPlayer.js @@ -142,6 +142,7 @@ class AudioPlayer { * @param {object} target - target whose node to should be connected */ connect (target) { + this.outputNode.disconnect(); this.outputNode.connect(target.getInputNode()); } diff --git a/src/effects/Effect.js b/src/effects/Effect.js index a607128..66bcd39 100644 --- a/src/effects/Effect.js +++ b/src/effects/Effect.js @@ -38,7 +38,7 @@ class Effect { * @return {boolean} is the effect affecting the graph? */ get _isPatch () { - return this.initialized; + return this.initialized && this.value !== this.DEFAULT_VALUE; } /** @@ -46,7 +46,7 @@ class Effect { * @return {AudioNode} - audio node that is the input for this effect */ getInputNode () { - if (this.initialized) { + if (this._isPatch) { return this.inputNode; } return this.target.getInputNode(); @@ -117,6 +117,10 @@ class Effect { return; } + if (this.outputNode !== null) { + this.outputNode.disconnect(); + } + let nextTarget = target; if (this._isPatch) { nextTarget = this; diff --git a/src/effects/PanEffect.js b/src/effects/PanEffect.js index 58ccf10..340dcf0 100644 --- a/src/effects/PanEffect.js +++ b/src/effects/PanEffect.js @@ -20,14 +20,6 @@ class PanEffect extends Effect { this.channelMerger = null; } - /** - * Should the effect be connected to the audio graph? - * @return {boolean} is the effect affecting the graph? - */ - get _isPatch () { - return this.initialized && this.value !== 0; - } - /** * Initialize the Effect. * Effects start out uninitialized. Then initialize when they are first set