Tone.js/Tone/signal/Abs.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/Selector", "Tone/signal/Negate", "Tone/signal/LessThan"], function(Tone){
/**
2014-07-04 17:36:13 +00:00
* @class return the absolute value of an incoming signal
*
* @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-22 22:54:23 +00:00
* @type {Tone.LessThan}
* @private
*/
2014-07-22 22:54:23 +00:00
this._ltz = new Tone.LessThan(0);
2014-07-03 03:36:59 +00:00
/**
* @type {Tone.Selector}
2014-07-03 03:36:59 +00:00
* @private
*/
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-03 03:36:59 +00:00
Tone.extend(Tone.Abs);
/**
* 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;
};
return Tone.Abs;
});