2019-01-27 18:05:20 +00:00
|
|
|
import Tone from "../core/Tone";
|
|
|
|
import "../signal/WaveShaper";
|
2014-11-30 01:32:33 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
/**
|
|
|
|
* @class Convert an incoming signal between 0, 1 to an equal power gain scale.
|
|
|
|
*
|
|
|
|
* @extends {Tone.SignalBase}
|
|
|
|
* @constructor
|
|
|
|
* @example
|
|
|
|
* var eqPowGain = new Tone.EqualPowerGain();
|
|
|
|
*/
|
|
|
|
Tone.EqualPowerGain = function(){
|
2014-11-30 01:32:33 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
Tone.SignalBase.call(this);
|
2014-11-30 01:32:33 +00:00
|
|
|
/**
|
2019-01-27 18:05:20 +00:00
|
|
|
* @type {Tone.WaveShaper}
|
|
|
|
* @private
|
2014-11-30 01:32:33 +00:00
|
|
|
*/
|
2019-01-27 18:05:20 +00:00
|
|
|
this._eqPower = this.input = this.output = new Tone.WaveShaper(function(val){
|
|
|
|
if (Math.abs(val) < 0.001){
|
|
|
|
//should output 0 when input is 0
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return Tone.equalPowerScale(val);
|
|
|
|
}
|
|
|
|
}.bind(this), 4096);
|
|
|
|
};
|
2014-11-30 01:32:33 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
Tone.extend(Tone.EqualPowerGain, Tone.SignalBase);
|
2014-11-30 01:32:33 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
|
|
|
* @returns {Tone.EqualPowerGain} this
|
|
|
|
*/
|
|
|
|
Tone.EqualPowerGain.prototype.dispose = function(){
|
|
|
|
Tone.SignalBase.prototype.dispose.call(this);
|
|
|
|
this._eqPower.dispose();
|
|
|
|
this._eqPower = null;
|
|
|
|
return this;
|
|
|
|
};
|
2014-11-30 01:32:33 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
export default Tone.EqualPowerGain;
|
2014-11-30 01:32:33 +00:00
|
|
|
|