Tone.js/Tone/signal/Abs.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-09-08 01:42:31 +00:00
define(["Tone/core/Tone", "Tone/signal/Select", "Tone/signal/Negate", "Tone/signal/LessThan", "Tone/signal/Signal"],
function(Tone){
"use strict";
/**
2014-07-04 17:36:13 +00:00
* @class return the absolute value of an incoming signal
*
* @constructor
* @extends {Tone.SignalBase}
*/
2014-07-04 17:36:13 +00:00
Tone.Abs = function(){
Tone.call(this, 1, 0);
2014-07-03 03:36:59 +00:00
/**
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
/**
2014-09-08 01:42:31 +00:00
* @type {Tone.Select}
2014-07-03 03:36:59 +00:00
* @private
*/
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);
};
Tone.extend(Tone.Abs, Tone.SignalBase);
/**
* dispose method
*/
Tone.Abs.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2014-07-22 22:54:23 +00:00
this._switch.dispose();
this._switch = null;
this._ltz.dispose();
2014-07-22 22:54:23 +00:00
this._ltz = null;
this._negate.dispose();
2014-07-03 03:36:59 +00:00
this._negate = null;
};
return Tone.Abs;
});