Tone.js/Tone/signal/Pow.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
2014-10-31 01:34:11 +00:00
"use strict";
/**
2014-11-02 01:53:14 +00:00
* @class Pow applies an exponent to the incoming signal. The incoming signal
* must be in the range -1,1
2014-10-31 01:34:11 +00:00
*
* @extends {Tone}
* @constructor
* @param {number} exp the exponent to apply to the incoming signal, must be at least 2.
*/
Tone.Pow = function(exp){
exp = this.defaultArg(exp, 1);
2014-11-02 01:53:14 +00:00
/**
* @type {WaveShaperNode}
* @private
*/
2014-11-30 22:42:02 +00:00
this._expScaler = this.input = this.output = new Tone.WaveShaper(this._expFunc(exp), 8192);
2014-10-31 01:34:11 +00:00
};
Tone.extend(Tone.Pow);
2014-11-02 01:53:14 +00:00
/**
* set the exponential scaling curve
* @param {number} exp the exponent to raise the incoming signal to
*/
Tone.Pow.prototype.setExponent = function(exp){
this._expScaler.setMap(this._expFunc(exp));
};
/**
* the function which maps the waveshaper
* @param {number} exp
* @return {function}
* @private
*/
Tone.Pow.prototype._expFunc = function(exp){
return function(val){
return Math.pow(Math.abs(val), exp);
};
2014-11-02 01:53:14 +00:00
};
2014-10-31 01:34:11 +00:00
/**
* clean up
*/
Tone.Pow.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._expScaler.dispose();
2014-11-02 01:53:14 +00:00
this._expScaler = null;
2014-10-31 01:34:11 +00:00
};
return Tone.Pow;
});