2014-07-02 19:37:08 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Threshold"], function(Tone){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output 1 if the signal is equal to 0, otherwise outputs 0
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
*/
|
2014-07-02 23:18:00 +00:00
|
|
|
Tone.EqualZero = function(){
|
2014-07-02 19:37:08 +00:00
|
|
|
/**
|
|
|
|
* @type {WaveShaperNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._equals = this.context.createWaveShaper();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {WaveShaperNode}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-07-02 21:08:03 +00:00
|
|
|
this._thresh = new Tone.Threshold(1);
|
2014-07-02 19:37:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {WaveShaperNode}
|
|
|
|
*/
|
|
|
|
this.input = this._equals;
|
|
|
|
|
|
|
|
this._equals.connect(this._thresh);
|
|
|
|
|
|
|
|
this.output = this._thresh;
|
|
|
|
|
|
|
|
|
|
|
|
this._setEquals();
|
|
|
|
};
|
|
|
|
|
2014-07-02 23:18:00 +00:00
|
|
|
Tone.extend(Tone.EqualZero);
|
2014-07-02 19:37:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2014-07-02 23:18:00 +00:00
|
|
|
Tone.EqualZero.prototype._setEquals = function(){
|
2014-07-02 19:37:08 +00:00
|
|
|
var curveLength = 1024;
|
|
|
|
var curve = new Float32Array(curveLength);
|
|
|
|
for (var i = 0; i < curveLength; i++){
|
2014-07-03 03:38:20 +00:00
|
|
|
var normalized = (i / (curveLength)) * 2 - 1;
|
|
|
|
if (normalized === 0){
|
|
|
|
curve[i] = 1;
|
2014-07-02 19:37:08 +00:00
|
|
|
} else {
|
2014-07-03 03:38:20 +00:00
|
|
|
curve[i] = 0;
|
2014-07-02 19:37:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this._equals.curve = curve;
|
|
|
|
};
|
|
|
|
|
2014-07-02 19:47:05 +00:00
|
|
|
/**
|
|
|
|
* dispose method
|
|
|
|
*/
|
2014-07-02 23:18:00 +00:00
|
|
|
Tone.EqualZero.prototype.dispose = function(){
|
2014-07-02 19:47:05 +00:00
|
|
|
this._equals.disconnect();
|
|
|
|
this._thresh.dispose();
|
|
|
|
this._equals = null;
|
|
|
|
this._thresh = null;
|
|
|
|
};
|
|
|
|
|
2014-07-02 23:18:00 +00:00
|
|
|
return Tone.EqualZero;
|
2014-07-02 19:37:08 +00:00
|
|
|
});
|