2014-07-23 19:47:00 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Selector", "Tone/signal/Negate", "Tone/signal/LessThan"], function(Tone){
|
2014-07-02 22:20:02 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-04 17:36:13 +00:00
|
|
|
* @class return the absolute value of an incoming signal
|
2014-07-02 22:20:02 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
*/
|
2014-07-04 17:36:13 +00:00
|
|
|
Tone.Abs = function(){
|
2014-07-03 03:36:59 +00:00
|
|
|
Tone.call(this);
|
|
|
|
|
2014-07-02 22:20:02 +00:00
|
|
|
/**
|
2014-07-22 22:54:23 +00:00
|
|
|
* @type {Tone.LessThan}
|
2014-07-02 22:20:02 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-07-22 22:54:23 +00:00
|
|
|
this._ltz = new Tone.LessThan(0);
|
2014-07-02 22:20:02 +00:00
|
|
|
|
2014-07-03 03:36:59 +00:00
|
|
|
/**
|
2014-07-23 19:47:00 +00:00
|
|
|
* @type {Tone.Selector}
|
2014-07-03 03:36:59 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-07-23 19:47:00 +00:00
|
|
|
this._switch = new Tone.Selector(2);
|
2014-07-22 22:54:23 +00:00
|
|
|
|
2014-07-03 03:36:59 +00:00
|
|
|
/**
|
2014-07-22 22:54:23 +00:00
|
|
|
* @type {Tone.Negate}
|
2014-07-03 03:36:59 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-07-22 22:54:23 +00:00
|
|
|
this._negate = new Tone.Negate();
|
2014-07-03 03:36:59 +00:00
|
|
|
|
2014-07-22 22:54:23 +00:00
|
|
|
//two signal paths, positive and negative
|
|
|
|
this.input.connect(this._switch, 0, 0);
|
|
|
|
this.input.connect(this._negate);
|
|
|
|
this._negate.connect(this._switch, 0, 1);
|
|
|
|
this._switch.connect(this.output);
|
|
|
|
|
|
|
|
//the control signal
|
|
|
|
this.chain(this.input, this._ltz, this._switch.gate);
|
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-22 22:54:23 +00:00
|
|
|
this._switch.dispose();
|
|
|
|
this._ltz.dispose();
|
2014-07-03 03:36:59 +00:00
|
|
|
this._negate.dispose();
|
2014-07-04 02:57:04 +00:00
|
|
|
this.input.disconnect();
|
|
|
|
this.output.disconnect();
|
2014-07-22 22:54:23 +00:00
|
|
|
this._switch = null;
|
|
|
|
this._ltz = null;
|
2014-07-03 03:36:59 +00:00
|
|
|
this._negate = 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;
|
|
|
|
});
|