2014-12-04 03:11:23 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/effect/MidSideEffect", "Tone/signal/Signal",
|
2014-11-01 22:17:03 +00:00
|
|
|
"Tone/signal/Multiply", "Tone/signal/Expr"],
|
|
|
|
function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
2015-06-22 05:20:57 +00:00
|
|
|
* @class Applies a width factor to the mid/side seperation.
|
|
|
|
* 0 is all mid and 1 is all side.
|
2015-07-04 19:25:37 +00:00
|
|
|
* Algorithm found in [kvraudio forums](http://www.kvraudio.com/forum/viewtopic.php?t=212587).
|
2015-06-22 05:20:57 +00:00
|
|
|
* <br><br>
|
2015-07-04 16:40:33 +00:00
|
|
|
* <code>
|
2015-06-22 05:20:57 +00:00
|
|
|
* Mid *= 2*(1-width)<br>
|
|
|
|
* Side *= 2*width
|
2015-07-04 16:40:33 +00:00
|
|
|
* </code>
|
2014-11-01 22:17:03 +00:00
|
|
|
*
|
2014-12-04 03:11:23 +00:00
|
|
|
* @extends {Tone.MidSideEffect}
|
2014-11-01 22:17:03 +00:00
|
|
|
* @constructor
|
2015-06-22 05:20:57 +00:00
|
|
|
* @param {NormalRange|Object} [width] The stereo width. A width of 0 is mono and 1 is stereo. 0.5 is no change.
|
2014-11-01 22:17:03 +00:00
|
|
|
*/
|
|
|
|
Tone.StereoWidener = function(){
|
|
|
|
|
|
|
|
var options = this.optionsObject(arguments, ["width"], Tone.StereoWidener.defaults);
|
2014-12-04 03:11:23 +00:00
|
|
|
Tone.MidSideEffect.call(this, options);
|
2014-11-01 22:17:03 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-22 05:20:57 +00:00
|
|
|
* The width control. 0 = 100% mid. 1 = 100% side. 0.5 = no change.
|
2015-06-13 23:50:39 +00:00
|
|
|
* @type {NormalRange}
|
|
|
|
* @signal
|
2014-11-01 22:17:03 +00:00
|
|
|
*/
|
2015-08-26 13:59:11 +00:00
|
|
|
this.width = new Tone.Signal(options.width, Tone.Type.NormalRange);
|
2014-11-01 22:17:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mid multiplier
|
|
|
|
* @type {Tone.Expr}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._midMult = new Tone.Expr("$0 * ($1 * (1 - $2))");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Side multiplier
|
|
|
|
* @type {Tone.Expr}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._sideMult = new Tone.Expr("$0 * ($1 * $2)");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* constant output of 2
|
|
|
|
* @type {Tone}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._two = new Tone.Signal(2);
|
|
|
|
|
|
|
|
//the mid chain
|
|
|
|
this._two.connect(this._midMult, 0, 1);
|
|
|
|
this.width.connect(this._midMult, 0, 2);
|
|
|
|
//the side chain
|
|
|
|
this._two.connect(this._sideMult, 0, 1);
|
|
|
|
this.width.connect(this._sideMult, 0, 2);
|
|
|
|
//connect it to the effect send/return
|
2014-12-01 02:32:09 +00:00
|
|
|
this.midSend.chain(this._midMult, this.midReturn);
|
|
|
|
this.sideSend.chain(this._sideMult, this.sideReturn);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._readOnly(["width"]);
|
2014-11-01 22:17:03 +00:00
|
|
|
};
|
|
|
|
|
2014-12-04 03:11:23 +00:00
|
|
|
Tone.extend(Tone.StereoWidener, Tone.MidSideEffect);
|
2014-11-01 22:17:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the default values
|
|
|
|
* @static
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
Tone.StereoWidener.defaults = {
|
|
|
|
"width" : 0.5
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-06-22 05:20:57 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.StereoWidener} this
|
2014-11-01 22:17:03 +00:00
|
|
|
*/
|
|
|
|
Tone.StereoWidener.prototype.dispose = function(){
|
2014-12-04 03:11:23 +00:00
|
|
|
Tone.MidSideEffect.prototype.dispose.call(this);
|
2015-04-18 14:54:08 +00:00
|
|
|
this._writable(["width"]);
|
2014-11-01 22:17:03 +00:00
|
|
|
this.width.dispose();
|
|
|
|
this.width = null;
|
|
|
|
this._midMult.dispose();
|
|
|
|
this._midMult = null;
|
|
|
|
this._sideMult.dispose();
|
|
|
|
this._sideMult = null;
|
|
|
|
this._two.dispose();
|
|
|
|
this._two = null;
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-11-01 22:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.StereoWidener;
|
|
|
|
});
|