Tone.js/Tone/core/Gain.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-10-21 14:02:23 +00:00
define(["Tone/core/Tone", "Tone/core/Param", "Tone/core/Type"], function (Tone) {
2015-08-15 23:30:43 +00:00
/**
* @class A thin wrapper around the Native Web Audio GainNode.
* The GainNode is a basic building block of the Web Audio
* API and is useful for routing audio and adjusting gains.
* @extends {Tone}
2015-10-21 14:02:23 +00:00
* @param {Number=} value The initial gain of the GainNode
* @param {Tone.Type=} units The units of the gain parameter.
2015-08-15 23:30:43 +00:00
*/
2015-10-21 14:02:23 +00:00
Tone.Gain = function(){
2015-08-15 23:30:43 +00:00
2015-10-21 14:02:23 +00:00
var options = this.optionsObject(arguments, ["value", "units"], Tone.Gain.defaults);
2015-08-16 18:23:01 +00:00
2015-08-15 23:30:43 +00:00
/**
* The GainNode
* @type {GainNode}
* @private
*/
2015-10-21 14:02:23 +00:00
this._gainNode = this.context.createGain();
options.param = this._gainNode.gain;
Tone.Param.call(this, options);
this.input = this.output = this._gainNode;
2015-08-15 23:30:43 +00:00
/**
2015-10-21 14:02:23 +00:00
* The gain parameter of the gain node.
* @type {AudioParam}
2015-08-15 23:30:43 +00:00
* @signal
*/
2015-10-21 14:02:23 +00:00
this.gain = this._param;
2015-08-15 23:30:43 +00:00
this._readOnly("gain");
};
2015-10-21 14:02:23 +00:00
Tone.extend(Tone.Gain, Tone.Param);
2015-08-15 23:30:43 +00:00
/**
* The defaults
* @const
* @type {Object}
*/
Tone.Gain.defaults = {
2015-10-21 14:02:23 +00:00
"value" : 1,
"units" : Tone.Type.Gain,
"convert" : true
2015-08-15 23:30:43 +00:00
};
/**
* Clean up.
* @return {Tone.Gain} this
*/
Tone.Gain.prototype.dispose = function(){
2015-10-21 14:02:23 +00:00
Tone.Param.prototype.dispose.call(this);
2015-08-15 23:30:43 +00:00
this._gainNode.disconnect();
this._gainNode = null;
this._writable("gain");
this.gain = null;
};
return Tone.Gain;
});