Volume Gate

This commit is contained in:
Yotam Mann 2014-07-23 15:50:45 -04:00
parent ded3f1a61a
commit d01cb52bf4

69
Tone/component/Gate.js Normal file
View file

@ -0,0 +1,69 @@
define(["Tone/core/Tone", "Tone/component/Follower", "Tone/signal/GreaterThan"], function(Tone){
/**
* @class Only pass signal through when it's signal exceeds the
* specified threshold.
*
* @constructor
* @extends {Tone}
* @param {number=} [thresh = -40] the threshold in Decibels
*/
Tone.Gate = function(thresh){
Tone.call(this);
//default values
thresh = this.defaultArg(thresh, -40);
/**
* @type {Tone.Follower}
* @private
*/
this._follower = new Tone.Follower(0.1);
/**
* @type {Tone.GreaterThan}
* @private
*/
this._gt = new Tone.GreaterThan(this.dbToGain(thresh));
//the connections
this.chain(this.input, this.output);
//the control signal
this.chain(this.input, this._follower, this._gt, this.output.gain);
this.output.gain.value = 0;
};
Tone.extend(Tone.Gate);
/**
* set the gating threshold
* @param {number} thresh the gating threshold
*/
Tone.Gate.prototype.setThreshold = function(thresh){
this._gt.setValue(this.dbToGain(thresh));
};
/**
* set the amount of smoothing applied to the incoming signal
* @param {Tone.Time} smoothTime
*/
Tone.Gate.prototype.setSmoothTime = function(smoothTime){
this._follower.setSmoothTime(smoothTime);
};
/**
* dispose
*/
Tone.Gate.prototype.dispose = function(){
this._follower.dispose();
this._gt.dispose();
this.input.disconnect();
this.output.disconnect();
this._follower = null;
this._gt = null;
this.input = null;
this.output = null;
};
return Tone.Gate;
});