Tone.js/Tone/signal/EqualZero.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/GreaterThanZero", "Tone/signal/WaveShaper"],
function(Tone){
2014-07-02 19:37:08 +00:00
"use strict";
2014-10-03 17:07:53 +00:00
/**
* @class EqualZero outputs 1 when the input is strictly greater than zero
2014-07-02 19:37:08 +00:00
*
* @constructor
* @extends {Tone.SignalBase}
2015-02-27 18:40:35 +00:00
* @example
* var eq0 = new Tone.EqualZero();
* var sig = new Tone.Signal(0).connect(eq0);
* //the output of eq0 is 1.
2014-07-02 19:37:08 +00:00
*/
2014-07-02 23:18:00 +00:00
Tone.EqualZero = function(){
2014-10-03 17:07:53 +00:00
/**
* scale the incoming signal by a large factor
* @private
* @type {Tone.Multiply}
*/
this._scale = this.input = new Tone.Multiply(10000);
2014-10-03 17:07:53 +00:00
2014-07-02 19:37:08 +00:00
/**
* @type {Tone.WaveShaper}
2014-07-02 19:37:08 +00:00
* @private
*/
this._thresh = new Tone.WaveShaper(function(val){
if (val === 0){
return 1;
} else {
return 0;
}
}, 128);
2014-07-02 19:37:08 +00:00
/**
2014-10-03 17:07:53 +00:00
* threshold the output so that it's 0 or 1
* @type {Tone.GreaterThanZero}
2014-07-02 19:37:08 +00:00
* @private
*/
this._gtz = this.output = new Tone.GreaterThanZero();
2014-07-02 19:37:08 +00:00
2014-10-03 17:07:53 +00:00
//connections
2014-12-01 02:32:09 +00:00
this._scale.chain(this._thresh, this._gtz);
2014-07-02 19:37:08 +00:00
};
Tone.extend(Tone.EqualZero, Tone.SignalBase);
2014-07-02 19:47:05 +00:00
/**
* dispose method
* @returns {Tone.EqualZero} this
2014-07-02 19:47:05 +00:00
*/
2014-07-02 23:18:00 +00:00
Tone.EqualZero.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2014-10-03 17:07:53 +00:00
this._gtz.dispose();
this._gtz = null;
2014-10-03 17:07:53 +00:00
this._scale.dispose();
this._scale = null;
this._thresh.dispose();
this._thresh = null;
2015-02-02 03:56:33 +00:00
return this;
2014-07-02 19:47:05 +00:00
};
2014-07-02 23:18:00 +00:00
return Tone.EqualZero;
2014-07-02 19:37:08 +00:00
});