2014-10-20 01:55:18 +00:00
|
|
|
define(["Tone/core/Tone"], function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class A thin wrapper around the DynamicsCompressorNode
|
|
|
|
*
|
|
|
|
* @extends {Tone}
|
|
|
|
* @constructor
|
|
|
|
* @param {number} [threshold=-24] threshold in decibels
|
|
|
|
* @param {number} [ratio=12] gain reduction ratio
|
|
|
|
*/
|
|
|
|
Tone.Compressor = function(){
|
|
|
|
|
|
|
|
var options = this.optionsObject(arguments, ["threshold", "ratio"], Tone.Compressor.defaults);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the compressor node
|
|
|
|
* @type {DynamicsCompressorNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._compressor = this.context.createDynamicsCompressor();
|
|
|
|
|
|
|
|
/**
|
2015-02-02 17:49:13 +00:00
|
|
|
* the input and output
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
2015-02-02 17:49:13 +00:00
|
|
|
this.input = this.output = this._compressor;
|
2014-10-20 01:55:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the threshold vaue
|
|
|
|
* @type {AudioParam}
|
|
|
|
*/
|
|
|
|
this.threshold = this._compressor.threshold;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the attack vaue
|
|
|
|
* @type {AudioParam}
|
|
|
|
*/
|
|
|
|
this.attack = this._compressor.attack;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the release vaue
|
|
|
|
* @type {AudioParam}
|
|
|
|
*/
|
|
|
|
this.release = this._compressor.release;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the knee vaue
|
|
|
|
* @type {AudioParam}
|
|
|
|
*/
|
|
|
|
this.knee = this._compressor.knee;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the ratio vaue
|
|
|
|
* @type {AudioParam}
|
|
|
|
*/
|
|
|
|
this.ratio = this._compressor.ratio;
|
|
|
|
|
|
|
|
//set the defaults
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the attack time
|
|
|
|
* @param {Tone.Time} time the attack time
|
2015-02-02 17:49:13 +00:00
|
|
|
* @returns {Tone.Compressor} `this`
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor.prototype.setAttack = function(time) {
|
|
|
|
this._compressor.attack.value = this.toSeconds(time);
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-10-20 01:55:18 +00:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* set the release time
|
|
|
|
* @param {Tone.Time} time the release time
|
2015-02-02 17:49:13 +00:00
|
|
|
* @returns {Tone.Compressor} `this`
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor.prototype.setRelease = function(time) {
|
|
|
|
this._compressor.release.value = this.toSeconds(time);
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-10-20 01:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the threshold value
|
|
|
|
* @param {number} value the threshold in decibels
|
2015-02-02 17:49:13 +00:00
|
|
|
* @returns {Tone.Compressor} `this`
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor.prototype.setThreshold = function(value) {
|
|
|
|
this._compressor.threshold.value = value;
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-10-20 01:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the knee value
|
|
|
|
* @param {number} knee
|
2015-02-02 17:49:13 +00:00
|
|
|
* @returns {Tone.Compressor} `this`
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor.prototype.setKnee = function(knee) {
|
|
|
|
this._compressor.knee.value = knee;
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-10-20 01:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the ratio value
|
|
|
|
* @param {number} ratio
|
2015-02-02 17:49:13 +00:00
|
|
|
* @returns {Tone.Compressor} `this`
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor.prototype.setRatio = function(ratio) {
|
|
|
|
this._compressor.ratio.value = ratio;
|
2015-02-02 17:49:13 +00:00
|
|
|
return this;
|
2014-10-20 01:55:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 17:49:13 +00:00
|
|
|
* @returns {Tone.Compressor} `this`
|
2014-10-20 01:55:18 +00:00
|
|
|
*/
|
|
|
|
Tone.Compressor.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
|
|
|
this._compressor.disconnect();
|
|
|
|
this._compressor = null;
|
|
|
|
this.attack = null;
|
|
|
|
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;
|
|
|
|
});
|