Tone.js/Tone/component/EQ3.js

149 lines
3.4 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/component/MultibandSplit", "Tone/core/Gain", "Tone/core/AudioNode"], function(Tone){
"use strict";
/**
2015-07-02 19:45:40 +00:00
* @class Tone.EQ3 is a three band EQ with control over low, mid, and high gain as
2015-07-02 00:19:58 +00:00
* well as the low and high crossover frequencies.
*
* @constructor
* @extends {Tone.AudioNode}
*
2015-06-20 23:25:49 +00:00
* @param {Decibels|Object} [lowLevel] The gain applied to the lows.
* @param {Decibels} [midLevel] The gain applied to the mid.
* @param {Decibels} [highLevel] The gain applied to the high.
2015-02-27 21:53:10 +00:00
* @example
2015-06-20 23:25:49 +00:00
* var eq = new Tone.EQ3(-10, 3, -20);
*/
2015-04-20 14:41:55 +00:00
Tone.EQ3 = function(){
var options = Tone.defaults(arguments, ["low", "mid", "high"], Tone.EQ3);
Tone.AudioNode.call(this);
/**
2014-10-13 19:58:06 +00:00
* the output node
* @type {GainNode}
2015-02-27 21:53:10 +00:00
* @private
*/
this.output = new Tone.Gain();
/**
2014-10-13 19:58:06 +00:00
* the multiband split
* @type {Tone.MultibandSplit}
* @private
*/
2015-02-27 21:53:10 +00:00
this._multibandSplit = this.input = new Tone.MultibandSplit({
2014-10-13 19:58:06 +00:00
"lowFrequency" : options.lowFrequency,
"highFrequency" : options.highFrequency
});
2015-11-01 22:49:53 +00:00
/**
* The gain for the lower signals
* @type {Tone.Gain}
* @private
*/
this._lowGain = new Tone.Gain(options.low, Tone.Type.Decibels);
/**
* The gain for the mid signals
* @type {Tone.Gain}
* @private
*/
this._midGain = new Tone.Gain(options.mid, Tone.Type.Decibels);
/**
* The gain in decibels of the high part
* @type {Tone.Gain}
* @private
*/
this._highGain = new Tone.Gain(options.high, Tone.Type.Decibels);
2015-02-24 00:46:28 +00:00
/**
* The gain in decibels of the low part
2015-06-13 23:29:25 +00:00
* @type {Decibels}
* @signal
2015-02-24 00:46:28 +00:00
*/
2015-11-01 22:49:53 +00:00
this.low = this._lowGain.gain;
2015-02-24 00:46:28 +00:00
/**
* The gain in decibels of the mid part
2015-06-13 23:29:25 +00:00
* @type {Decibels}
* @signal
2015-02-24 00:46:28 +00:00
*/
2015-11-01 22:49:53 +00:00
this.mid = this._midGain.gain;
2015-02-24 00:46:28 +00:00
/**
* The gain in decibels of the high part
2015-06-13 23:29:25 +00:00
* @type {Decibels}
* @signal
2015-02-24 00:46:28 +00:00
*/
2015-11-01 22:49:53 +00:00
this.high = this._highGain.gain;
2015-02-24 00:46:28 +00:00
2015-05-22 14:12:50 +00:00
/**
* The Q value for all of the filters.
2015-06-13 23:29:25 +00:00
* @type {Positive}
* @signal
2015-05-22 14:12:50 +00:00
*/
this.Q = this._multibandSplit.Q;
2014-10-13 19:58:06 +00:00
/**
* The low/mid crossover frequency.
2015-06-13 23:29:25 +00:00
* @type {Frequency}
* @signal
2014-10-13 19:58:06 +00:00
*/
this.lowFrequency = this._multibandSplit.lowFrequency;
/**
* The mid/high crossover frequency.
2015-06-13 23:29:25 +00:00
* @type {Frequency}
* @signal
2014-10-13 19:58:06 +00:00
*/
this.highFrequency = this._multibandSplit.highFrequency;
//the frequency bands
2015-11-01 22:49:53 +00:00
this._multibandSplit.low.chain(this._lowGain, this.output);
this._multibandSplit.mid.chain(this._midGain, this.output);
this._multibandSplit.high.chain(this._highGain, this.output);
2015-04-05 19:13:15 +00:00
this._readOnly(["low", "mid", "high", "lowFrequency", "highFrequency"]);
};
Tone.extend(Tone.EQ3, Tone.AudioNode);
/**
* the default values
*/
2015-04-20 14:41:55 +00:00
Tone.EQ3.defaults = {
2015-01-06 04:33:05 +00:00
"low" : 0,
"mid" : 0,
"high" : 0,
"lowFrequency" : 400,
"highFrequency" : 2500
};
/**
* clean up
* @returns {Tone.EQ3} this
*/
2015-04-20 14:41:55 +00:00
Tone.EQ3.prototype.dispose = function(){
Tone.AudioNode.prototype.dispose.call(this);
2015-04-05 19:13:15 +00:00
this._writable(["low", "mid", "high", "lowFrequency", "highFrequency"]);
2014-10-13 19:58:06 +00:00
this._multibandSplit.dispose();
this._multibandSplit = null;
this.lowFrequency = null;
this.highFrequency = null;
2015-11-01 22:49:53 +00:00
this._lowGain.dispose();
this._lowGain = null;
this._midGain.dispose();
this._midGain = null;
this._highGain.dispose();
this._highGain = null;
2015-02-24 00:46:28 +00:00
this.low = null;
this.mid = null;
this.high = null;
2015-05-22 14:12:50 +00:00
this.Q = null;
2015-02-02 17:49:13 +00:00
return this;
};
2015-04-20 14:41:55 +00:00
return Tone.EQ3;
});