Tone.js/Tone/component/Limiter.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

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.
*
* @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);
*/
Tone.Limiter = function(){
var options = this.optionsObject(arguments, ["threshold"], Tone.Limiter.defaults);
/**
* 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,
"threshold" : options.threshold
});
/**
* The threshold of of the limiter
2015-06-20 23:25:49 +00:00
* @type {Decibel}
* @signal
*/
this.threshold = this._compressor.threshold;
2015-04-05 19:13:15 +00:00
this._readOnly("threshold");
};
Tone.extend(Tone.Limiter);
/**
* The default value
* @type {Object}
* @const
* @static
*/
Tone.Limiter.defaults = {
"threshold" : -12
};
/**
2015-06-20 23:25:49 +00:00
* Clean up.
* @returns {Tone.Limiter} this
*/
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");
this.threshold = null;
2015-02-02 17:49:13 +00:00
return this;
};
return Tone.Limiter;
});