Tone.js/Tone/effect/FeedbackEffect.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/effect/Effect", "Tone/signal/Signal", "Tone/signal/Multiply"], function(Tone){
"use strict";
/**
2014-09-05 15:32:33 +00:00
* @class Feedback Effect (a sound loop between an audio source and its own output)
*
* @constructor
* @extends {Tone.Effect}
2014-12-03 22:20:23 +00:00
* @param {number|Object} [initialFeedback=0.125] the initial feedback value
*/
Tone.FeedbackEffect = function(){
var options = this.optionsObject(arguments, ["feedback"]);
options = this.defaultArg(options, Tone.FeedbackEffect.defaults);
Tone.Effect.call(this, options);
/**
* 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
/**
* 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"]);
};
Tone.extend(Tone.FeedbackEffect, Tone.Effect);
/**
* @static
* @type {Object}
*/
Tone.FeedbackEffect.defaults = {
2014-11-30 22:17:50 +00:00
"feedback" : 0.125
};
/**
* clean up
2015-02-02 18:22:16 +00:00
* @returns {Tone.FeedbackEffect} `this`
*/
Tone.FeedbackEffect.prototype.dispose = function(){
Tone.Effect.prototype.dispose.call(this);
2015-04-18 14:54:08 +00:00
this._writable(["feedback"]);
this.feedback.dispose();
this.feedback = null;
2014-11-30 22:17:50 +00:00
this._feedbackGain.disconnect();
this._feedbackGain = null;
2015-02-02 18:22:16 +00:00
return this;
};
return Tone.FeedbackEffect;
});