2014-09-08 01:42:31 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Negate", "Tone/signal/LessThan", "Tone/signal/Signal"],
|
2014-08-24 17:19:49 +00:00
|
|
|
function(Tone){
|
2014-07-02 22:20:02 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
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
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2014-07-02 22:20:02 +00:00
|
|
|
*/
|
2014-07-04 17:36:13 +00:00
|
|
|
Tone.Abs = function(){
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.call(this, 1, 0);
|
2014-07-03 03:36:59 +00:00
|
|
|
|
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-09-08 01:42:31 +00:00
|
|
|
* @type {Tone.Select}
|
2014-07-03 03:36:59 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-04 06:21:42 +00:00
|
|
|
this._switch = this.output = new Tone.Select(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);
|
|
|
|
|
|
|
|
//the control signal
|
2014-12-01 02:32:09 +00:00
|
|
|
this.input.chain(this._ltz, this._switch.gate);
|
2014-07-02 22:20:02 +00:00
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.Abs, Tone.SignalBase);
|
2014-08-24 17:19:49 +00:00
|
|
|
|
2014-07-02 22:20:02 +00:00
|
|
|
/**
|
|
|
|
* dispose method
|
|
|
|
*/
|
|
|
|
Tone.Abs.prototype.dispose = function(){
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-07-22 22:54:23 +00:00
|
|
|
this._switch.dispose();
|
|
|
|
this._switch = null;
|
2014-11-04 06:21:42 +00:00
|
|
|
this._ltz.dispose();
|
2014-07-22 22:54:23 +00:00
|
|
|
this._ltz = null;
|
2014-11-04 06:21:42 +00:00
|
|
|
this._negate.dispose();
|
2014-07-03 03:36:59 +00:00
|
|
|
this._negate = null;
|
2014-07-02 22:20:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Abs;
|
|
|
|
});
|