Tone.js/Tone/component/MultibandCompressor.js

115 lines
2.6 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
* @param {Object} options the low/mid/high compressor settings in a single object
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
});
/**
* low/mid crossover frequency
* @type {Tone.Signal}
*/
this.lowFrequency = this._splitter.lowFrequency;
/**
* mid/high crossover frequency
* @type {Tone.Signal}
*/
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();
/**
* the low compressor
* @type {Tone.Compressor}
*/
this.low = new Tone.Compressor(options.low);
/**
* the mid compressor
* @type {Tone.Compressor}
*/
this.mid = new Tone.Compressor(options.mid);
/**
* the high compressor
* @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
2015-02-02 17:49:13 +00:00
* @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;
});