Tone.js/Tone/signal/GreaterThanZero.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-10-21 23:02:46 +00:00
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Multiply", "Tone/signal/WaveShaper"], function(Tone){
"use strict";
/**
* @class GreaterThanZero outputs 1 when the input is strictly greater than zero
2017-10-21 23:02:46 +00:00
*
* @constructor
* @extends {Tone.SignalBase}
2015-02-27 18:40:35 +00:00
* @example
2015-06-14 05:17:09 +00:00
* var gt0 = new Tone.GreaterThanZero();
* var sig = new Tone.Signal(0.01).connect(gt0);
2017-10-21 23:02:46 +00:00
* //the output of gt0 is 1.
2015-06-14 05:17:09 +00:00
* sig.value = 0;
2017-10-21 23:02:46 +00:00
* //the output of gt0 is 0.
*/
Tone.GreaterThanZero = function(){
2017-10-21 23:02:46 +00:00
Tone.SignalBase.call(this);
2017-10-21 23:02:46 +00:00
/**
* @type {Tone.WaveShaper}
* @private
*/
this._thresh = this.output = new Tone.WaveShaper(function(val){
if (val <= 0){
return 0;
} else {
return 1;
}
2016-02-27 16:18:59 +00:00
}, 127);
/**
* scale the first thresholded signal by a large value.
* this will help with values which are very close to 0
* @type {Tone.Multiply}
* @private
*/
this._scale = this.input = new Tone.Multiply(10000);
//connections
this._scale.connect(this._thresh);
};
Tone.extend(Tone.GreaterThanZero, Tone.SignalBase);
/**
* dispose method
* @returns {Tone.GreaterThanZero} this
*/
Tone.GreaterThanZero.prototype.dispose = function(){
Tone.SignalBase.prototype.dispose.call(this);
this._scale.dispose();
this._scale = null;
this._thresh.dispose();
this._thresh = null;
2015-02-02 03:56:33 +00:00
return this;
};
return Tone.GreaterThanZero;
2017-10-21 23:02:46 +00:00
});