Tone.js/Tone/component/MultibandCompressor.js

117 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-10-20 01:55:55 +00:00
define(["Tone/core/Tone", "Tone/component/MultibandSplit", "Tone/component/Compressor"], function(Tone){
"use strict";
/**
* @class A compressor with seperate controls over low/mid/high dynamics
*
* @extends {Tone}
* @constructor
2015-06-20 23:25:49 +00:00
* @param {Object} options The low/mid/high compressor settings.
2015-02-27 21:53:10 +00:00
* @example
* var multiband = new Tone.MultibandCompressor({
* "lowFrequency" : 200,
* "highFrequency" : 1300
* "low" : {
* "threshold" : -12
* }
* })
2014-10-20 01:55:55 +00:00
*/
Tone.MultibandCompressor = function(options){
options = this.defaultArg(arguments, Tone.MultibandCompressor.defaults);
/**
* split the incoming signal into high/mid/low
* @type {Tone.MultibandSplit}
* @private
*/
2015-02-27 21:53:10 +00:00
this._splitter = this.input = new Tone.MultibandSplit({
2014-10-20 01:55:55 +00:00
"lowFrequency" : options.lowFrequency,
"highFrequency" : options.highFrequency
});
/**
2015-06-20 23:25:49 +00:00
* low/mid crossover frequency.
2015-06-13 23:50:39 +00:00
* @type {Frequency}
* @signal
2014-10-20 01:55:55 +00:00
*/
this.lowFrequency = this._splitter.lowFrequency;
/**
2015-06-20 23:25:49 +00:00
* mid/high crossover frequency.
2015-06-13 23:50:39 +00:00
* @type {Frequency}
* @signal
2014-10-20 01:55:55 +00:00
*/
this.highFrequency = this._splitter.highFrequency;
/**
* the output
* @type {GainNode}
2015-02-27 21:53:10 +00:00
* @private
2014-10-20 01:55:55 +00:00
*/
this.output = this.context.createGain();
/**
2015-06-20 23:25:49 +00:00
* The compressor applied to the low frequencies.
2014-10-20 01:55:55 +00:00
* @type {Tone.Compressor}
*/
this.low = new Tone.Compressor(options.low);
/**
2015-06-20 23:25:49 +00:00
* The compressor applied to the mid frequencies.
2014-10-20 01:55:55 +00:00
* @type {Tone.Compressor}
*/
this.mid = new Tone.Compressor(options.mid);
/**
2015-06-20 23:25:49 +00:00
* The compressor applied to the high frequencies.
2014-10-20 01:55:55 +00:00
* @type {Tone.Compressor}
*/
this.high = new Tone.Compressor(options.high);
//connect the compressor
2014-12-01 02:32:09 +00:00
this._splitter.low.chain(this.low, this.output);
this._splitter.mid.chain(this.mid, this.output);
this._splitter.high.chain(this.high, this.output);
2015-04-05 19:13:15 +00:00
this._readOnly(["high", "mid", "low", "highFrequency", "lowFrequency"]);
2014-10-20 01:55:55 +00:00
};
Tone.extend(Tone.MultibandCompressor);
/**
* @const
* @static
* @type {Object}
*/
Tone.MultibandCompressor.defaults = {
"low" : Tone.Compressor.defaults,
"mid" : Tone.Compressor.defaults,
"high" : Tone.Compressor.defaults,
"lowFrequency" : 250,
"highFrequency" : 2000
};
/**
* clean up
* @returns {Tone.MultibandCompressor} this
2014-10-20 01:55:55 +00:00
*/
Tone.MultibandCompressor.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._splitter.dispose();
2015-04-05 19:13:15 +00:00
this._writable(["high", "mid", "low", "highFrequency", "lowFrequency"]);
2014-10-20 01:55:55 +00:00
this.low.dispose();
this.mid.dispose();
this.high.dispose();
this._splitter = null;
this.low = null;
this.mid = null;
this.high = null;
this.lowFrequency = null;
this.highFrequency = null;
2015-02-02 17:49:13 +00:00
return this;
2014-10-20 01:55:55 +00:00
};
return Tone.MultibandCompressor;
});