2014-07-03 03:36:59 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Negate", "Tone/signal/EqualZero"], function(Tone){
|
2014-07-02 22:20:02 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-03 03:36:59 +00:00
|
|
|
* return the absolute value of an incoming signal
|
2014-07-02 22:20:02 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
* @param {number} value
|
|
|
|
*/
|
|
|
|
Tone.Abs = function(value){
|
2014-07-03 03:36:59 +00:00
|
|
|
Tone.call(this);
|
|
|
|
|
2014-07-02 22:20:02 +00:00
|
|
|
/**
|
2014-07-03 03:36:59 +00:00
|
|
|
* @type {Tone.Threshold}
|
2014-07-02 22:20:02 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-07-03 03:36:59 +00:00
|
|
|
this._thresh = new Tone.Threshold(0);
|
|
|
|
|
2014-07-02 22:20:02 +00:00
|
|
|
/**
|
2014-07-03 03:36:59 +00:00
|
|
|
* @type {Tone.Negate}
|
|
|
|
* @private
|
2014-07-02 22:20:02 +00:00
|
|
|
*/
|
2014-07-03 03:36:59 +00:00
|
|
|
this._negate = new Tone.Negate();
|
2014-07-02 22:20:02 +00:00
|
|
|
|
2014-07-03 03:36:59 +00:00
|
|
|
/**
|
|
|
|
* @type {Tone.EqualZero}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._not = new Tone.EqualZero();
|
2014-07-02 22:20:02 +00:00
|
|
|
|
2014-07-03 03:36:59 +00:00
|
|
|
/**
|
|
|
|
* @type {GainNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._positive = this.context.createGain();
|
2014-07-02 22:20:02 +00:00
|
|
|
|
2014-07-03 03:36:59 +00:00
|
|
|
/**
|
|
|
|
* @type {GainNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._negative = this.context.createGain();
|
|
|
|
|
|
|
|
this.input.connect(this._thresh);
|
|
|
|
//two routes, one positive, one negative
|
|
|
|
this.chain(this.input, this._positive, this.output);
|
|
|
|
this.chain(this.input, this._negate, this._negative, this.output);
|
|
|
|
//the switching logic
|
|
|
|
this._thresh.connect(this._positive.gain);
|
|
|
|
this._positive.gain.value = 0;
|
|
|
|
this.chain(this._thresh, this._not, this._negative.gain);
|
|
|
|
this._negative.gain.value = 0;
|
2014-07-02 22:20:02 +00:00
|
|
|
};
|
|
|
|
|
2014-07-03 03:36:59 +00:00
|
|
|
Tone.extend(Tone.Abs);
|
|
|
|
|
2014-07-02 22:20:02 +00:00
|
|
|
/**
|
|
|
|
* dispose method
|
|
|
|
*/
|
|
|
|
Tone.Abs.prototype.dispose = function(){
|
2014-07-03 03:36:59 +00:00
|
|
|
this._thresh.dispose();
|
|
|
|
this._negate.dispose();
|
|
|
|
this._not.dispose();
|
|
|
|
this._positive.disconnect();
|
|
|
|
this._negative.disconnect();
|
2014-07-04 02:57:04 +00:00
|
|
|
this.input.disconnect();
|
|
|
|
this.output.disconnect();
|
2014-07-03 03:36:59 +00:00
|
|
|
this._thresh = null;
|
|
|
|
this._negate = null;
|
|
|
|
this._not = null;
|
|
|
|
this._positive = null;
|
|
|
|
this._negative = null;
|
2014-07-04 02:57:04 +00:00
|
|
|
this.input = null;
|
|
|
|
this.output = null;
|
2014-07-02 22:20:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Abs;
|
|
|
|
});
|