Tone.js/Tone/signal/Abs.js

47 lines
918 B
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/WaveShaper", "Tone/signal/SignalBase"],
function(Tone){
"use strict";
/**
2015-06-19 04:52:04 +00:00
* @class Return the absolute value of an incoming signal.
*
* @constructor
* @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-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
*/
this._abs = this.input = this.output = new Tone.WaveShaper(function(val){
if (val === 0){
return 0;
} else {
return Math.abs(val);
}
}, 127);
};
Tone.extend(Tone.Abs, Tone.SignalBase);
/**
* dispose method
* @returns {Tone.Abs} this
*/
Tone.Abs.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._abs.dispose();
this._abs = null;
2015-02-02 03:56:33 +00:00
return this;
};
return Tone.Abs;
});