2014-11-30 18:20:35 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/GreaterThanZero", "Tone/signal/WaveShaper"],
|
|
|
|
function(Tone){
|
2014-07-02 19:37:08 +00:00
|
|
|
|
2014-09-04 04:41:40 +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
|
2014-12-01 04:26:06 +00:00
|
|
|
* @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}
|
|
|
|
*/
|
2014-11-04 06:21:42 +00:00
|
|
|
this._scale = this.input = new Tone.Multiply(10000);
|
2014-10-03 17:07:53 +00:00
|
|
|
|
2014-07-02 19:37:08 +00:00
|
|
|
/**
|
2014-11-30 18:20:35 +00:00
|
|
|
* @type {Tone.WaveShaper}
|
2014-07-02 19:37:08 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-30 18:20:35 +00:00
|
|
|
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
|
|
|
|
*/
|
2014-11-04 06:21:42 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.EqualZero, Tone.SignalBase);
|
2014-08-24 17:19:49 +00:00
|
|
|
|
2014-07-02 19:47:05 +00:00
|
|
|
/**
|
|
|
|
* dispose method
|
2015-06-14 00:54:29 +00:00
|
|
|
* @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(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-10-03 17:07:53 +00:00
|
|
|
this._gtz.dispose();
|
2014-11-30 18:20:35 +00:00
|
|
|
this._gtz = null;
|
2014-10-03 17:07:53 +00:00
|
|
|
this._scale.dispose();
|
|
|
|
this._scale = null;
|
2014-11-30 18:20:35 +00:00
|
|
|
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
|
|
|
});
|