2014-07-22 23:17:45 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Abs", "Tone/signal/Negate", "Tone/signal/Multiply"], function(Tone){
|
2014-06-30 15:34:52 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-22 23:17:45 +00:00
|
|
|
* @class Follow the envelope of the incoming signal
|
2014-07-23 19:22:46 +00:00
|
|
|
* Note: due to the nature of low-pass filters,
|
|
|
|
* there is some rippling which is proportional
|
|
|
|
* to the smoothTime
|
2014-07-22 23:17:45 +00:00
|
|
|
*
|
2014-06-30 15:34:52 +00:00
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
2014-07-23 19:22:46 +00:00
|
|
|
* @param {Tone.Time=} [smoothTime = 0.1]
|
2014-06-30 15:34:52 +00:00
|
|
|
*/
|
2014-07-23 19:22:46 +00:00
|
|
|
Tone.Follower = function(smoothTime){
|
2014-07-02 22:20:34 +00:00
|
|
|
Tone.call(this);
|
|
|
|
|
|
|
|
//default values
|
2014-07-23 19:22:46 +00:00
|
|
|
smoothTime = this.defaultArg(smoothTime, 0.1);
|
2014-07-02 22:20:34 +00:00
|
|
|
|
2014-06-30 15:34:52 +00:00
|
|
|
/**
|
2014-07-02 22:20:34 +00:00
|
|
|
* @type {Tone.Abs}
|
2014-06-30 15:34:52 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-07-02 22:20:34 +00:00
|
|
|
this._abs = new Tone.Abs();
|
2014-06-30 15:34:52 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-23 19:22:46 +00:00
|
|
|
* the lowpass filter which smooths the input
|
2014-06-30 15:34:52 +00:00
|
|
|
* @type {BiquadFilterNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._filter = this.context.createBiquadFilter();
|
|
|
|
this._filter.type = "lowpass";
|
2014-07-22 23:17:45 +00:00
|
|
|
this._filter.Q.value = -10;
|
2014-06-30 15:34:52 +00:00
|
|
|
|
2014-07-23 19:22:46 +00:00
|
|
|
//the connections
|
|
|
|
this.chain(this.input, this._abs, this._filter, this.output);
|
2014-07-23 19:25:46 +00:00
|
|
|
this.setSmoothTime(smoothTime);
|
2014-06-30 15:34:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.Follower);
|
2014-07-02 22:20:34 +00:00
|
|
|
|
2014-07-23 19:25:46 +00:00
|
|
|
/**
|
|
|
|
* set the amount of time it takes to reach the destination value
|
|
|
|
*
|
|
|
|
* @param {Tone.Time} smoothTime the amount of time it takes
|
|
|
|
* to reach the destination value
|
|
|
|
*/
|
|
|
|
Tone.Follower.prototype.setSmoothTime = function(smoothTime){
|
|
|
|
this._filter.frequency.value = this.secondsToFrequency(smoothTime * 2);
|
|
|
|
};
|
|
|
|
|
2014-07-02 22:20:34 +00:00
|
|
|
/**
|
|
|
|
* dispose
|
|
|
|
*/
|
|
|
|
Tone.Follower.prototype.dispose = function(){
|
|
|
|
this._filter.disconnect();
|
|
|
|
this.input.disconnect();
|
|
|
|
this.output.disconnect();
|
|
|
|
this._abs.dispose();
|
|
|
|
this._filter = null;
|
|
|
|
this.input = null;
|
|
|
|
this.output = null;
|
|
|
|
this._abs = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Follower;
|
2014-06-30 15:34:52 +00:00
|
|
|
});
|