Skip to content

Commit 4016d11

Browse files
committed
rebuild lib
1 parent ac65fcf commit 4016d11

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

lib/p5.sound.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9648,18 +9648,32 @@ reverb = function () {
96489648
*/
96499649
p5.Reverb = function () {
96509650
Effect.call(this);
9651-
this.convolverNode = this.ac.createConvolver();
9651+
this._initConvolverNode();
96529652
// otherwise, Safari distorts
96539653
this.input.gain.value = 0.5;
9654-
this.input.connect(this.convolverNode);
9655-
this.convolverNode.connect(this.wet);
96569654
// default params
96579655
this._seconds = 3;
96589656
this._decay = 2;
96599657
this._reverse = false;
96609658
this._buildImpulse();
96619659
};
96629660
p5.Reverb.prototype = Object.create(Effect.prototype);
9661+
p5.Reverb.prototype._initConvolverNode = function () {
9662+
this.convolverNode = this.ac.createConvolver();
9663+
this.input.connect(this.convolverNode);
9664+
this.convolverNode.connect(this.wet);
9665+
};
9666+
p5.Reverb.prototype._teardownConvolverNode = function () {
9667+
if (this.convolverNode) {
9668+
this.convolverNode.disconnect();
9669+
delete this.convolverNode;
9670+
}
9671+
};
9672+
p5.Reverb.prototype._setBuffer = function (audioBuffer) {
9673+
this._teardownConvolverNode();
9674+
this._initConvolverNode();
9675+
this.convolverNode.buffer = audioBuffer;
9676+
};
96639677
/**
96649678
* Connect a source to the reverb, and assign reverb parameters.
96659679
*
@@ -9759,14 +9773,11 @@ reverb = function () {
97599773
impulseL[i] = (Math.random() * 2 - 1) * Math.pow(1 - n / length, decay);
97609774
impulseR[i] = (Math.random() * 2 - 1) * Math.pow(1 - n / length, decay);
97619775
}
9762-
this.convolverNode.buffer = impulse;
9776+
this._setBuffer(impulse);
97639777
};
97649778
p5.Reverb.prototype.dispose = function () {
97659779
Effect.prototype.dispose.apply(this);
9766-
if (this.convolverNode) {
9767-
this.convolverNode.buffer = null;
9768-
this.convolverNode = null;
9769-
}
9780+
this._teardownConvolverNode();
97709781
};
97719782
// =======================================================================
97729783
// *** p5.Convolver ***
@@ -9825,19 +9836,17 @@ reverb = function () {
98259836
* </code></div>
98269837
*/
98279838
p5.Convolver = function (path, callback, errorCallback) {
9828-
Effect.call(this);
9839+
p5.Reverb.call(this);
98299840
/**
98309841
* Internally, the p5.Convolver uses the a
98319842
* <a href="http://www.w3.org/TR/webaudio/#ConvolverNode">
98329843
* Web Audio Convolver Node</a>.
98339844
*
9834-
* @property {ConvolverNode} convolverNod
9845+
* @property {ConvolverNode} convolverNode
98359846
*/
9836-
this.convolverNode = this.ac.createConvolver();
9847+
this._initConvolverNode();
98379848
// otherwise, Safari distorts
98389849
this.input.gain.value = 0.5;
9839-
this.input.connect(this.convolverNode);
9840-
this.convolverNode.connect(this.wet);
98419850
if (path) {
98429851
this.impulses = [];
98439852
this._loadBuffer(path, callback, errorCallback);
@@ -9935,7 +9944,7 @@ reverb = function () {
99359944
buffer.name = chunks[chunks.length - 1];
99369945
buffer.audioBuffer = buff;
99379946
self.impulses.push(buffer);
9938-
self.convolverNode.buffer = buffer.audioBuffer;
9947+
self._setBuffer(buffer.audioBuffer);
99399948
if (callback) {
99409949
callback(buffer);
99419950
}
@@ -10072,29 +10081,25 @@ reverb = function () {
1007210081
*/
1007310082
p5.Convolver.prototype.toggleImpulse = function (id) {
1007410083
if (typeof id === 'number' && id < this.impulses.length) {
10075-
this.convolverNode.buffer = this.impulses[id].audioBuffer;
10084+
this._setBuffer(this.impulses[id].audioBuffer);
1007610085
}
1007710086
if (typeof id === 'string') {
1007810087
for (var i = 0; i < this.impulses.length; i++) {
1007910088
if (this.impulses[i].name === id) {
10080-
this.convolverNode.buffer = this.impulses[i].audioBuffer;
10089+
this._setBuffer(this.impulses[i].audioBuffer);
1008110090
break;
1008210091
}
1008310092
}
1008410093
}
1008510094
};
1008610095
p5.Convolver.prototype.dispose = function () {
10087-
Effect.prototype.dispose.apply(this);
10096+
p5.Reverb.prototype.dispose.apply(this);
1008810097
// remove all the Impulse Response buffers
1008910098
for (var i in this.impulses) {
1009010099
if (this.impulses[i]) {
1009110100
this.impulses[i] = null;
1009210101
}
1009310102
}
10094-
if (this.convolverNode) {
10095-
this.convolverNode.disconnect();
10096-
this.concolverNode = null;
10097-
}
1009810103
};
1009910104
}(errorHandler, effect);
1010010105
/** Tone.js module by Yotam Mann, MIT License 2016 http://opensource.org/licenses/MIT **/

0 commit comments

Comments
 (0)