From d70dd0cc3780cf4824d70043eba33f22e35ba889 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 26 Apr 2017 20:01:07 -0700 Subject: [PATCH] Reorder audio nodes to avoid Safari hack. --- js/media.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/js/media.js b/js/media.js index b4e6aae3..a76c3291 100644 --- a/js/media.js +++ b/js/media.js @@ -56,6 +56,10 @@ export default { // |\ // | // | + // preamp + // | + // [biquadFilters] + // | // (split using createChannelSplitter) // | // / \ @@ -72,24 +76,7 @@ export default { // | // destination - this._preamp.connect(this._chanSplit); - - // Connect split channels to left / right gains - this._chanSplit.connect(this._leftGain, 0); - this._chanSplit.connect(this._rightGain, 1); - - // Reconnect the left / right gains to the merge node - this._leftGain.connect(this._chanMerge, 0, 0); - this._rightGain.connect(this._chanMerge, 0, 1); - - // Safari, both mobile and desktop, has a bug where - // connecting a merger node to biquad filter node - // will cause it to crash. Adding this dummy node - // works around this bug. - const dummyNode = this._context.createAnalyser(); - this._chanMerge.connect(dummyNode); - - let output = dummyNode; + let output = this._preamp; this.bands = {}; BANDS.forEach((band, i) => { @@ -113,7 +100,18 @@ export default { output = filter; }); - output.connect(this._gainNode); + output.connect(this._chanSplit); + + // Connect split channels to left / right gains + this._chanSplit.connect(this._leftGain, 0); + this._chanSplit.connect(this._rightGain, 1); + + // Reconnect the left / right gains to the merge node + this._leftGain.connect(this._chanMerge, 0, 0); + this._rightGain.connect(this._chanMerge, 0, 1); + + this._chanMerge.connect(this._gainNode); + this._gainNode.connect(this._context.destination); // Kick off the animation loop