Tone.js/Tone/component/Compressor.js

99 lines
2 KiB
JavaScript
Raw Normal View History

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
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
*/
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 parameter
* @type {Tone.Signal}
2014-10-20 01:55:18 +00:00
*/
this.attack = new Tone.Signal(this._compressor.attack, Tone.Signal.Units.Time);
2014-10-20 01:55:18 +00:00
/**
* The release parameter
* @type {Tone.Signal}
2014-10-20 01:55:18 +00:00
*/
this.release = new Tone.Signal(this._compressor.release, Tone.Signal.Units.Time);
2014-10-20 01:55:18 +00:00
/**
* The knee parameter
2014-10-20 01:55:18 +00:00
* @type {AudioParam}
*/
this.knee = this._compressor.knee;
/**
* The ratio value
2014-10-20 01:55:18 +00:00
* @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
};
/**
* 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.dispose();
2014-10-20 01:55:18 +00:00
this.attack = null;
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;
});