2014-11-30 18:20:35 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Multiply", "Tone/signal/WaveShaper"],
|
|
|
|
function(Tone){
|
2014-10-03 17:06:26 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class GreaterThanZero outputs 1 when the input is strictly greater than zero
|
|
|
|
*
|
|
|
|
* @constructor
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2014-10-03 17:06:26 +00:00
|
|
|
*/
|
|
|
|
Tone.GreaterThanZero = function(){
|
|
|
|
|
|
|
|
/**
|
2014-11-30 18:20:35 +00:00
|
|
|
* @type {Tone.WaveShaper}
|
2014-10-03 17:06:26 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-30 18:20:35 +00:00
|
|
|
this._thresh = this.output = new Tone.WaveShaper(function(val){
|
|
|
|
if (val <= 0){
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
});
|
2014-10-03 17:06:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scale the first thresholded signal by a large value.
|
|
|
|
* this will help with values which are very close to 0
|
|
|
|
* @type {Tone.Multiply}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-11-30 18:20:35 +00:00
|
|
|
this._scale = this.input = new Tone.Multiply(10000);
|
2014-10-03 17:06:26 +00:00
|
|
|
|
|
|
|
//connections
|
|
|
|
this._scale.connect(this._thresh);
|
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.GreaterThanZero, Tone.SignalBase);
|
2014-10-03 17:06:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dispose method
|
|
|
|
*/
|
|
|
|
Tone.GreaterThanZero.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
|
|
|
this._scale.dispose();
|
|
|
|
this._scale = null;
|
2014-11-30 18:20:35 +00:00
|
|
|
this._thresh.dispose();
|
|
|
|
this._thresh = null;
|
2014-10-03 17:06:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.GreaterThanZero;
|
|
|
|
});
|