Tone.js/Tone/effect/StereoWidener.js

111 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-10-21 23:02:46 +00:00
define(["Tone/core/Tone", "Tone/effect/MidSideEffect", "Tone/signal/Signal",
2017-10-26 17:51:51 +00:00
"Tone/signal/Multiply", "Tone/signal/Subtract"], function(Tone){
2014-11-01 22:17:03 +00:00
"use strict";
/**
2017-10-21 23:02:46 +00:00
* @class Applies a width factor to the mid/side seperation.
2015-06-22 05:20:57 +00:00
* 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>
* <code>
2015-06-22 05:20:57 +00:00
* Mid *= 2*(1-width)<br>
* Side *= 2*width
* </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(){
2017-04-26 03:18:08 +00:00
var options = Tone.defaults(arguments, ["width"], Tone.StereoWidener);
2014-12-04 03:11:23 +00:00
Tone.MidSideEffect.call(this, options);
2014-11-01 22:17:03 +00:00
/**
2017-10-21 23:02:46 +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);
2017-10-26 17:51:51 +00:00
this._readOnly(["width"]);
/**
* Two times the (1-width) for the mid channel
* @type {Tone.Multiply}
* @private
*/
this._twoTimesWidthMid = new Tone.Multiply(2);
/**
* Two times the width for the side channel
* @type {Tone.Multiply}
* @private
*/
this._twoTimesWidthSide = new Tone.Multiply(2);
2014-11-01 22:17:03 +00:00
/**
* Mid multiplier
2017-10-26 17:51:51 +00:00
* @type {Tone.Multiply}
2014-11-01 22:17:03 +00:00
* @private
*/
2017-10-26 17:51:51 +00:00
this._midMult = new Tone.Multiply();
this._twoTimesWidthMid.connect(this._midMult, 0, 1);
this.midSend.chain(this._midMult, this.midReturn);
2014-11-01 22:17:03 +00:00
/**
2017-10-26 17:51:51 +00:00
* 1 - width
* @type {Tone}
2014-11-01 22:17:03 +00:00
*/
2017-10-26 17:51:51 +00:00
this._oneMinusWidth = new Tone.Subtract();
this._oneMinusWidth.connect(this._twoTimesWidthMid);
this.context.getConstant(1).connect(this._oneMinusWidth, 0, 0);
this.width.connect(this._oneMinusWidth, 0, 1);
2014-11-01 22:17:03 +00:00
/**
2017-10-26 17:51:51 +00:00
* Side multiplier
* @type {Tone.Multiply}
2014-11-01 22:17:03 +00:00
* @private
*/
2017-10-26 17:51:51 +00:00
this._sideMult = new Tone.Multiply();
this.width.connect(this._twoTimesWidthSide);
this._twoTimesWidthSide.connect(this._sideMult, 0, 1);
2014-12-01 02:32:09 +00:00
this.sideSend.chain(this._sideMult, this.sideReturn);
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
};
/**
2017-10-21 23:02:46 +00:00
* Clean up.
* @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;
2017-10-26 17:51:51 +00:00
this._twoTimesWidthMid.dispose();
this._twoTimesWidthMid = null;
this._twoTimesWidthSide.dispose();
this._twoTimesWidthSide = null;
this._oneMinusWidth.dispose();
this._oneMinusWidth = null;
2015-02-02 18:22:16 +00:00
return this;
2014-11-01 22:17:03 +00:00
};
return Tone.StereoWidener;
2017-10-21 23:02:46 +00:00
});