2014-08-25 14:23:37 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/effect/Effect", "Tone/signal/Signal", "Tone/signal/Multiply"], function(Tone){
|
2014-09-04 04:41:40 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2014-09-05 15:32:33 +00:00
|
|
|
* @class Feedback Effect (a sound loop between an audio source and its own output)
|
2014-06-21 21:34:31 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone.Effect}
|
2014-12-03 22:20:23 +00:00
|
|
|
* @param {number|Object} [initialFeedback=0.125] the initial feedback value
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-08-24 23:28:42 +00:00
|
|
|
Tone.FeedbackEffect = function(){
|
|
|
|
|
|
|
|
var options = this.optionsObject(arguments, ["feedback"]);
|
2014-08-25 14:23:37 +00:00
|
|
|
options = this.defaultArg(options, Tone.FeedbackEffect.defaults);
|
2014-08-24 23:28:42 +00:00
|
|
|
|
|
|
|
Tone.Effect.call(this, options);
|
2014-06-21 21:34:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* controls the amount of feedback
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
2015-05-24 13:45:15 +00:00
|
|
|
this.feedback = new Tone.Signal(options.feedback, Tone.Type.NormalRange);
|
2014-08-23 18:24:54 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* the gain which controls the feedback
|
|
|
|
* @type {GainNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._feedbackGain = this.context.createGain();
|
|
|
|
|
|
|
|
//the feedback loop
|
2014-12-01 02:32:09 +00:00
|
|
|
this.effectReturn.chain(this._feedbackGain, this.effectSend);
|
2014-11-30 22:17:50 +00:00
|
|
|
this.feedback.connect(this._feedbackGain.gain);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._readOnly(["feedback"]);
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.FeedbackEffect, Tone.Effect);
|
|
|
|
|
2014-08-24 23:28:42 +00:00
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2014-08-25 14:23:37 +00:00
|
|
|
Tone.FeedbackEffect.defaults = {
|
2014-11-30 22:17:50 +00:00
|
|
|
"feedback" : 0.125
|
2014-08-24 23:28:42 +00:00
|
|
|
};
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 18:22:16 +00:00
|
|
|
* @returns {Tone.FeedbackEffect} `this`
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.FeedbackEffect.prototype.dispose = function(){
|
2014-08-23 19:51:21 +00:00
|
|
|
Tone.Effect.prototype.dispose.call(this);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._writable(["feedback"]);
|
2014-06-21 21:34:31 +00:00
|
|
|
this.feedback.dispose();
|
|
|
|
this.feedback = null;
|
2014-11-30 22:17:50 +00:00
|
|
|
this._feedbackGain.disconnect();
|
2014-06-21 21:34:31 +00:00
|
|
|
this._feedbackGain = null;
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.FeedbackEffect;
|
|
|
|
});
|