mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 16:48:00 +00:00
Volume Gate
This commit is contained in:
parent
ded3f1a61a
commit
d01cb52bf4
1 changed files with 69 additions and 0 deletions
69
Tone/component/Gate.js
Normal file
69
Tone/component/Gate.js
Normal 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;
|
||||
});
|
Loading…
Reference in a new issue