Skip to content

Commit d771729

Browse files
committed
dispose methods
1 parent 0e2e870 commit d771729

File tree

11 files changed

+101
-10
lines changed

11 files changed

+101
-10
lines changed

src/amplitude.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,16 @@ define(function (require) {
298298
}
299299
};
300300

301+
p5.Amplitude.prototype.dispose = function() {
302+
// remove reference from soundArray
303+
var index = p5sound.soundArray.indexOf(this);
304+
p5sound.soundArray.splice(index, 1);
305+
306+
this.input.disconnect();
307+
this.output.disconnect();
308+
309+
this.input = this.processor = undefined;
310+
this.output = undefined;
311+
};
312+
301313
});

src/audioin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ define(function (require) {
317317

318318
// private method
319319
p5.AudioIn.prototype.dispose = function(){
320+
// remove reference from soundArray
321+
var index = p5sound.soundArray.indexOf(this);
322+
p5sound.soundArray.splice(index, 1);
323+
320324
this.stop();
321325
if (this.output) {
322326
this.output.disconnect();

src/delay.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ define(function (require) {
8787
this._leftFilter.disconnect();
8888
this._rightFilter.disconnect();
8989

90-
/**
91-
* Internal filter. Set to lowPass by default, but can be accessed directly.
92-
* See p5.Filter for methods. Or use the p5.Delay.filter() method to change
93-
* frequency and q.
94-
*
95-
* @property lowPass
96-
* @type {p5.Filter}
97-
*/
98-
this.lowPass = this._leftFilter;
99-
10090
this._leftFilter.biquad.frequency.setValueAtTime(1200, this.ac.currentTime);
10191
this._rightFilter.biquad.frequency.setValueAtTime(1200, this.ac.currentTime);
10292
this._leftFilter.biquad.Q.setValueAtTime(0.3, this.ac.currentTime);
@@ -298,4 +288,32 @@ define(function (require) {
298288
this.output.disconnect();
299289
};
300290

291+
p5.Delay.prototype.dispose = function() {
292+
// remove reference from soundArray
293+
var index = p5sound.soundArray.indexOf(this);
294+
p5sound.soundArray.splice(index, 1);
295+
296+
this.input.disconnect();
297+
this.output.disconnect();
298+
this._split.disconnect();
299+
this._leftFilter.disconnect();
300+
this._rightFilter.disconnect();
301+
this._merge.disconnect();
302+
this._leftGain.disconnect();
303+
this._rightGain.disconnect();
304+
this.leftDelay.disconnect();
305+
this.rightDelay.disconnect();
306+
307+
this.input = undefined;
308+
this.output = undefined;
309+
this._split = undefined;
310+
this._leftFilter = undefined;
311+
this._rightFilter = undefined;
312+
this._merge = undefined;
313+
this._leftGain = undefined;
314+
this._rightGain = undefined;
315+
this.leftDelay = undefined;
316+
this.rightDelay = undefined;
317+
}
318+
301319
});

src/env.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,10 @@ define(function (require) {
419419

420420
// get rid of the oscillator
421421
p5.Env.prototype.dispose = function() {
422+
// remove reference from soundArray
423+
var index = p5sound.soundArray.indexOf(this);
424+
p5sound.soundArray.splice(index, 1);
425+
422426
var now = p5sound.audiocontext.currentTime;
423427
this.disconnect();
424428
try{

src/fft.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,15 @@ define(function (require) {
383383
this.analyser.smoothingTimeConstant = s;
384384
};
385385

386+
p5.FFT.prototype.dispose = function() {
387+
// remove reference from soundArray
388+
var index = p5sound.soundArray.indexOf(this);
389+
p5sound.soundArray.splice(index, 1);
390+
391+
this.analyser.disconnect();
392+
this.analyser = undefined;
393+
}
394+
386395
// helper methods to convert type from float (dB) to int (0-255)
387396
var freqToFloat = function (fft) {
388397
if (fft.freqDomain instanceof Float32Array === false) {

src/filter.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ define(function (require) {
234234
this.output.disconnect();
235235
};
236236

237+
p5.Filter.prototype.dispose = function() {
238+
// remove reference from soundArray
239+
var index = p5sound.soundArray.indexOf(this);
240+
p5sound.soundArray.splice(index, 1);
241+
242+
this.input.disconnect();
243+
this.input = undefined;
244+
245+
246+
this.output.disconnect();
247+
this.output = undefined;
248+
249+
this.biquad.disconnect();
250+
this.biquad = undefined;
251+
}
252+
237253
/**
238254
* Constructor: <code>new p5.LowPass()</code> Filter.
239255
* This is the same as creating a p5.Filter and then calling

src/gain.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ define(function (require) {
134134
this.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime);
135135
};
136136

137+
p5.Gain.prototype.dispose = function() {
138+
// remove reference from soundArray
139+
var index = p5sound.soundArray.indexOf(this);
140+
p5sound.soundArray.splice(index, 1);
141+
this.output.disconnect();
142+
this.input.disconnect();
143+
this.output = undefined;
144+
this.input = undefined;
145+
}
146+
137147
});
138148

139149

src/noise.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ define(function (require) {
170170

171171
p5.Noise.prototype.dispose = function(){
172172
var now = p5sound.audiocontext.currentTime;
173+
174+
// remove reference from soundArray
175+
var index = p5sound.soundArray.indexOf(this);
176+
p5sound.soundArray.splice(index, 1);
177+
173178
if (this.noise) {
174179
this.noise.disconnect();
175180
this.stop(now);

src/oscillator.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ define(function (require) {
335335

336336
// get rid of the oscillator
337337
p5.Oscillator.prototype.dispose = function() {
338+
// remove reference from soundArray
339+
var index = p5sound.soundArray.indexOf(this);
340+
p5sound.soundArray.splice(index, 1);
341+
338342
if (this.oscillator){
339343
var now = p5sound.audiocontext.currentTime;
340344
this.stop(now);

src/reverb.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ define(function (require) {
180180
};
181181

182182
p5.Reverb.prototype.dispose = function() {
183+
// remove reference from soundArray
184+
var index = p5sound.soundArray.indexOf(this);
185+
p5sound.soundArray.splice(index, 1);
186+
183187
if (this.convolverNode) {
184188
this.convolverNode.buffer = null;
185189
this.convolverNode = null;

0 commit comments

Comments
 (0)