2015-05-05 20:40:58 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
|
2014-10-20 01:55:18 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
2015-06-14 05:09:06 +00:00
|
|
|
* @class A thin wrapper around the DynamicsCompressorNode. Compression reduces the
|
|
|
|
* volume of loud sounds or amplifies quiet sounds by narrowing or "compressing"
|
|
|
|
* an audio signal's dynamic range. [<a href="https://en.wikipedia.org/wiki/Dynamic_range_compression">Wikipedia</a>]
|
2014-10-20 01:55:18 +00:00
|
|
|
*
|
|
|
|
* @extends {Tone}
|
|
|
|
* @constructor
|
2015-06-13 23:29:25 +00:00
|
|
|
* @param {Decibels=} threshold The value above which the compression starts to be applied.
|
|
|
|
* @param {Positive=} ratio The gain reduction ratio.
|
2015-02-27 21:53:10 +00:00
|
|
|
* @example
|
|
|
|
* var comp = new Tone.Compressor(-30, 3);
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor = function(){
|
|
|
|
|
|
|
|
var options = this.optionsObject(arguments, ["threshold", "ratio"], Tone.Compressor.defaults);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the compressor node
|
|
|
|
* @type {DynamicsCompressorNode}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-04-24 17:13:20 +00:00
|
|
|
this._compressor = this.input = this.output = this.context.createDynamicsCompressor();
|
2014-10-20 01:55:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the threshold vaue
|
2015-06-13 23:29:25 +00:00
|
|
|
* @type {Decibels}
|
|
|
|
* @signal
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
this.threshold = this._compressor.threshold;
|
|
|
|
|
|
|
|
/**
|
2015-02-06 22:49:04 +00:00
|
|
|
* The attack parameter
|
2015-06-13 23:29:25 +00:00
|
|
|
* @type {Time}
|
|
|
|
* @signal
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
2015-05-23 22:57:05 +00:00
|
|
|
this.attack = new Tone.Signal(this._compressor.attack, Tone.Type.Time);
|
2014-10-20 01:55:18 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-06 22:49:04 +00:00
|
|
|
* The release parameter
|
2015-06-13 23:29:25 +00:00
|
|
|
* @type {Time}
|
|
|
|
* @signal
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
2015-05-23 22:57:05 +00:00
|
|
|
this.release = new Tone.Signal(this._compressor.release, Tone.Type.Time);
|
2014-10-20 01:55:18 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-06 22:49:04 +00:00
|
|
|
* The knee parameter
|
2015-06-13 23:29:25 +00:00
|
|
|
* @type {Decibels}
|
|
|
|
* @signal
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
this.knee = this._compressor.knee;
|
|
|
|
|
|
|
|
/**
|
2015-02-06 22:49:04 +00:00
|
|
|
* The ratio value
|
2015-06-13 23:29:25 +00:00
|
|
|
* @type {Number}
|
|
|
|
* @signal
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
this.ratio = this._compressor.ratio;
|
|
|
|
|
|
|
|
//set the defaults
|
2015-04-05 19:13:15 +00:00
|
|
|
this._readOnly(["knee", "release", "attack", "ratio", "threshold"]);
|
2014-10-20 01:55:18 +00:00
|
|
|
this.set(options);
|
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.Compressor);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @const
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
Tone.Compressor.defaults = {
|
|
|
|
"ratio" : 12,
|
|
|
|
"threshold" : -24,
|
|
|
|
"release" : 0.25,
|
|
|
|
"attack" : 0.003,
|
|
|
|
"knee" : 30
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Compressor} this
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
2015-04-05 19:13:15 +00:00
|
|
|
this._writable(["knee", "release", "attack", "ratio", "threshold"]);
|
2014-10-20 01:55:18 +00:00
|
|
|
this._compressor.disconnect();
|
|
|
|
this._compressor = null;
|
2015-02-06 22:49:04 +00:00
|
|
|
this.attack.dispose();
|
2014-10-20 01:55:18 +00:00
|
|
|
this.attack = null;
|
2015-02-06 22:49:04 +00:00
|
|
|
this.release.dispose();
|
2014-10-20 01:55:18 +00:00
|
|
|
this.release = null;
|
|
|
|
this.threshold = null;
|
|
|
|
this.ratio = null;
|
|
|
|
this.knee = null;
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-10-20 01:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Compressor;
|
|
|
|
});
|