Tone.js/Tone/signal/Abs.js
2014-11-30 23:26:06 -05:00

58 lines
No EOL
1.2 KiB
JavaScript

define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Negate", "Tone/signal/LessThan", "Tone/signal/Signal"],
function(Tone){
"use strict";
/**
* @class return the absolute value of an incoming signal
*
* @constructor
* @extends {Tone.SignalBase}
*/
Tone.Abs = function(){
Tone.call(this, 1, 0);
/**
* @type {Tone.LessThan}
* @private
*/
this._ltz = new Tone.LessThan(0);
/**
* @type {Tone.Select}
* @private
*/
this._switch = this.output = new Tone.Select(2);
/**
* @type {Tone.Negate}
* @private
*/
this._negate = new Tone.Negate();
//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
this.input.chain(this._ltz, this._switch.gate);
};
Tone.extend(Tone.Abs, Tone.SignalBase);
/**
* dispose method
*/
Tone.Abs.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._switch.dispose();
this._switch = null;
this._ltz.dispose();
this._ltz = null;
this._negate.dispose();
this._negate = null;
};
return Tone.Abs;
});