2014-11-30 18:20:35 +00:00
|
|
|
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
|
|
|
*
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2014-10-31 01:34:11 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {number} exp the exponent to apply to the incoming signal, must be at least 2.
|
|
|
|
*/
|
|
|
|
Tone.Pow = function(exp){
|
|
|
|
|
2014-11-30 18:20:35 +00:00
|
|
|
exp = this.defaultArg(exp, 1);
|
2014-11-02 01:53:14 +00:00
|
|
|
|
2014-11-04 00:22:17 +00:00
|
|
|
/**
|
2014-11-30 18:20:35 +00:00
|
|
|
* @type {WaveShaperNode}
|
2014-11-04 00:22:17 +00:00
|
|
|
* @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
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.Pow, Tone.SignalBase);
|
2014-10-31 01:34:11 +00:00
|
|
|
|
2014-11-02 01:53:14 +00:00
|
|
|
/**
|
|
|
|
* set the exponential scaling curve
|
|
|
|
* @param {number} exp the exponent to raise the incoming signal to
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Pow} `this`
|
2014-11-02 01:53:14 +00:00
|
|
|
*/
|
|
|
|
Tone.Pow.prototype.setExponent = function(exp){
|
2014-11-30 18:20:35 +00:00
|
|
|
this._expScaler.setMap(this._expFunc(exp));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-11-30 18:20:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Pow} `this`
|
2014-10-31 01:34:11 +00:00
|
|
|
*/
|
|
|
|
Tone.Pow.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
2014-11-30 18:20:35 +00:00
|
|
|
this._expScaler.dispose();
|
2014-11-02 01:53:14 +00:00
|
|
|
this._expScaler = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-10-31 01:34:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Pow;
|
|
|
|
});
|