2014-11-30 02:47:28 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/Compressor"], function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
2015-07-02 00:19:58 +00:00
|
|
|
* @class Tone.Limiter will limit the loudness of an incoming signal.
|
|
|
|
* It is composed of a Tone.Compressor with a fast attack
|
|
|
|
* and release. Limiters are commonly used to safeguard against
|
|
|
|
* signal clipping. Unlike a compressor, limiters do not provide
|
|
|
|
* smooth gain reduction and almost completely prevent
|
|
|
|
* additional gain above the threshold.
|
2014-11-30 02:47:28 +00:00
|
|
|
*
|
|
|
|
* @extends {Tone}
|
|
|
|
* @constructor
|
2015-06-20 23:25:49 +00:00
|
|
|
* @param {number} threshold The theshold above which the limiting is applied.
|
2015-02-27 21:53:10 +00:00
|
|
|
* @example
|
|
|
|
* var limiter = new Tone.Limiter(-6);
|
2014-11-30 02:47:28 +00:00
|
|
|
*/
|
2015-08-28 03:08:58 +00:00
|
|
|
Tone.Limiter = function(){
|
|
|
|
|
|
|
|
var options = this.optionsObject(arguments, ["threshold"], Tone.Limiter.defaults);
|
2014-11-30 02:47:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the compressor
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Compressor}
|
|
|
|
*/
|
|
|
|
this._compressor = this.input = this.output = new Tone.Compressor({
|
2015-06-20 23:25:49 +00:00
|
|
|
"attack" : 0.001,
|
|
|
|
"decay" : 0.001,
|
2015-08-28 03:08:58 +00:00
|
|
|
"threshold" : options.threshold
|
2014-11-30 02:47:28 +00:00
|
|
|
});
|
2015-02-06 22:49:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The threshold of of the limiter
|
2015-06-20 23:25:49 +00:00
|
|
|
* @type {Decibel}
|
|
|
|
* @signal
|
2015-02-06 22:49:04 +00:00
|
|
|
*/
|
|
|
|
this.threshold = this._compressor.threshold;
|
2015-04-05 19:13:15 +00:00
|
|
|
|
|
|
|
this._readOnly("threshold");
|
2014-11-30 02:47:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.Limiter);
|
|
|
|
|
2015-08-28 03:08:58 +00:00
|
|
|
/**
|
|
|
|
* The default value
|
|
|
|
* @type {Object}
|
|
|
|
* @const
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
Tone.Limiter.defaults = {
|
|
|
|
"threshold" : -12
|
|
|
|
};
|
|
|
|
|
2014-11-30 02:47:28 +00:00
|
|
|
/**
|
2015-06-20 23:25:49 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Limiter} this
|
2014-11-30 02:47:28 +00:00
|
|
|
*/
|
|
|
|
Tone.Limiter.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
|
|
|
this._compressor.dispose();
|
|
|
|
this._compressor = null;
|
2015-04-05 19:13:15 +00:00
|
|
|
this._writable("threshold");
|
2015-02-06 22:49:04 +00:00
|
|
|
this.threshold = null;
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-11-30 02:47:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Limiter;
|
|
|
|
});
|