Tone.js/Tone/signal/Abs.js

46 lines
941 B
JavaScript
Raw Normal View History

2017-10-21 23:02:46 +00:00
define(["Tone/core/Tone", "Tone/signal/WaveShaper", "Tone/signal/SignalBase"], function(Tone){
"use strict";
/**
2017-10-21 23:02:46 +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);
2017-10-21 23:02:46 +00:00
* //the output of abs is 1.
*/
2014-07-04 17:36:13 +00:00
Tone.Abs = function(){
Tone.SignalBase.call(this);
/**
2014-07-22 22:54:23 +00:00
* @type {Tone.LessThan}
* @private
*/
this._abs = this.input = this.output = new Tone.WaveShaper(function(val){
if (Math.abs(val) < 0.001){
return 0;
} else {
return Math.abs(val);
}
}, 1024);
};
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;
2015-02-02 03:56:33 +00:00
return this;
2017-10-21 23:02:46 +00:00
};
return Tone.Abs;
2017-10-21 23:02:46 +00:00
});