2016-02-06 20:06:03 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/WaveShaper", "Tone/signal/SignalBase"],
|
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
|
|
|
/**
|
2015-06-19 04:52:04 +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}
|
2015-02-27 18:40:35 +00:00
|
|
|
* @example
|
2015-06-14 05:17:09 +00:00
|
|
|
* var signal = new Tone.Signal(-1);
|
|
|
|
* var abs = new Tone.Abs();
|
|
|
|
* signal.connect(abs);
|
|
|
|
* //the output of abs is 1.
|
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
|
|
|
|
*/
|
2016-02-06 20:06:03 +00:00
|
|
|
this._abs = this.input = this.output = new Tone.WaveShaper(function(val){
|
|
|
|
if (val === 0){
|
|
|
|
return 0;
|
|
|
|
} else {
|
2016-03-16 17:09:46 +00:00
|
|
|
return Math.abs(val);
|
2016-02-06 20:06:03 +00:00
|
|
|
}
|
2016-03-16 17:09:46 +00:00
|
|
|
}, 127);
|
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
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Abs} this
|
2014-07-02 22:20:02 +00:00
|
|
|
*/
|
|
|
|
Tone.Abs.prototype.dispose = function(){
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2016-02-06 20:06:03 +00:00
|
|
|
this._abs.dispose();
|
|
|
|
this._abs = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-07-02 22:20:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Abs;
|
|
|
|
});
|