Tone.js/Tone/signal/Abs.js
Yotam Mann a48a980861 moving signals to static defaults
invoking super constructor in prep for es6 classes
2017-04-25 23:45:37 -04:00

46 lines
No EOL
933 B
JavaScript

define(["Tone/core/Tone", "Tone/signal/WaveShaper", "Tone/signal/SignalBase"],
function(Tone){
"use strict";
/**
* @class Return the absolute value of an incoming signal.
*
* @constructor
* @extends {Tone.SignalBase}
* @example
* var signal = new Tone.Signal(-1);
* var abs = new Tone.Abs();
* signal.connect(abs);
* //the output of abs is 1.
*/
Tone.Abs = function(){
Tone.SignalBase.call(this);
/**
* @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.SignalBase.prototype.dispose.call(this);
this._abs.dispose();
this._abs = null;
return this;
};
return Tone.Abs;
});