Tone.js/Tone/component/EQ.js

191 lines
4 KiB
JavaScript
Raw Normal View History

2014-10-13 19:58:06 +00:00
define(["Tone/core/Tone", "Tone/component/MultibandSplit"], function(Tone){
"use strict";
/**
* @class A 3 band EQ with control over low, mid, and high gain as
* well as the low and high crossover frequencies.
*
* @constructor
* @extends {Tone}
*
2014-09-12 00:31:37 +00:00
* @param {number|object} [lowLevel=0] the gain applied to the lows (in db)
* @param {number} [midLevel=0] the gain applied to the mid (in db)
* @param {number} [highLevel=0] the gain applied to the high (in db)
*/
Tone.EQ = function(){
var options = this.optionsObject(arguments, ["low", "mid", "high"], Tone.EQ.defaults);
/**
2014-10-13 19:58:06 +00:00
* the output node
* @type {GainNode}
*/
2014-10-13 19:58:06 +00:00
this.output = this.context.createGain();
/**
2014-10-13 19:58:06 +00:00
* the multiband split
* @type {Tone.MultibandSplit}
* @private
*/
2014-10-13 19:58:06 +00:00
this._multibandSplit = new Tone.MultibandSplit({
"lowFrequency" : options.lowFrequency,
"highFrequency" : options.highFrequency
});
/**
2014-10-13 19:58:06 +00:00
* input node
*/
2014-10-13 19:58:06 +00:00
this.input = this._multibandSplit;
/**
* the low gain
* @type {GainNode}
*/
this.lowGain = this.context.createGain();
/**
* the mid gain
* @type {GainNode}
*/
this.midGain = this.context.createGain();
/**
* the high gain
* @type {GainNode}
*/
this.highGain = this.context.createGain();
2014-10-13 19:58:06 +00:00
/**
* the low/mid crossover frequency
* @type {Tone.Signal}
*/
this.lowFrequency = this._multibandSplit.lowFrequency;
/**
* the mid/high crossover frequency
* @type {Tone.Signal}
*/
this.highFrequency = this._multibandSplit.highFrequency;
//the frequency bands
2014-12-01 02:32:09 +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);
2014-09-12 00:31:37 +00:00
//set the gains
this.setLow(options.low);
this.setMid(options.mid);
this.setHigh(options.high);
};
Tone.extend(Tone.EQ);
/**
* the default values
* @type {Object}
* @static
*/
Tone.EQ.defaults = {
2015-01-06 04:33:05 +00:00
"low" : 0,
"mid" : 0,
"high" : 0,
"lowFrequency" : 400,
"highFrequency" : 2500
};
/**
* set the mid range
2015-01-06 04:33:05 +00:00
* @param {number} db the db of the mids
2015-02-02 17:49:13 +00:00
* @returns {Tone.EQ} `this`
*/
2015-01-06 04:33:05 +00:00
Tone.EQ.prototype.setMid = function(db){
this.midGain.gain.value = this.dbToGain(db);
};
/**
* set the high range
2015-01-06 04:33:05 +00:00
* @param {number} db the db of the highs
2015-02-02 17:49:13 +00:00
* @returns {Tone.EQ} `this`
*/
2015-01-06 04:33:05 +00:00
Tone.EQ.prototype.setHigh = function(db){
this.highGain.gain.value = this.dbToGain(db);
};
/**
* set the low range
2015-01-06 04:33:05 +00:00
* @param {number} db the db of the lows
2015-02-02 17:49:13 +00:00
* @returns {Tone.EQ} `this`
*/
2015-01-06 04:33:05 +00:00
Tone.EQ.prototype.setLow = function(db){
this.lowGain.gain.value = this.dbToGain(db);
};
2015-02-02 17:49:13 +00:00
/**
* get the mid range
* @return {number} the db of the mids
*/
Tone.EQ.prototype.getMid = function(){
return this.gainToDb(this.midGain.gain.value);
};
/**
* get the high range
* @return {number} the db of the highs
*/
Tone.EQ.prototype.getHigh = function(){
return this.gainToDb(this.highGain.gain.value);
};
/**
* get the low range
* @return {number} the db of the lows
*/
Tone.EQ.prototype.getLow = function(){
return this.gainToDb(this.lowGain.gain.value);
};
/**
* the gain in decibels of the low
* @memberOf Tone.EQ#
* @type {number}
* @name low
*/
Tone._defineGetterSetter(Tone.EQ, "low");
/**
* the gain in decibels of the mid
* @memberOf Tone.EQ#
* @type {number}
* @name mid
*/
Tone._defineGetterSetter(Tone.EQ, "mid");
/**
* the gain in decibels of the high
* @memberOf Tone.EQ#
* @type {number}
* @name high
*/
Tone._defineGetterSetter(Tone.EQ, "high");
/**
* clean up
2015-02-02 17:49:13 +00:00
* @returns {Tone.EQ} `this`
*/
Tone.EQ.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2014-10-13 19:58:06 +00:00
this._multibandSplit.dispose();
this.lowGain.disconnect();
this.midGain.disconnect();
this.highGain.disconnect();
2014-10-13 19:58:06 +00:00
this._multibandSplit = null;
this.lowFrequency = null;
this.highFrequency = null;
this.lowGain = null;
this.midGain = null;
this.highGain = null;
2015-02-02 17:49:13 +00:00
return this;
};
return Tone.EQ;
});