mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-17 00:58:09 +00:00
ecd15808c2
now only accepts signals in the range [-1,1]
47 lines
No EOL
904 B
JavaScript
47 lines
No EOL
904 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.call(this, 1, 0);
|
|
|
|
/**
|
|
* @type {Tone.LessThan}
|
|
* @private
|
|
*/
|
|
this._abs = this.input = this.output = new Tone.WaveShaper(function(val){
|
|
if (val === 0){
|
|
return 0;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}, 3);
|
|
};
|
|
|
|
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;
|
|
return this;
|
|
};
|
|
|
|
return Tone.Abs;
|
|
}); |