2016-09-20 03:53:07 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Expr", "Tone/component/Merge", "Tone/core/Gain"],
|
2015-04-20 19:41:30 +00:00
|
|
|
function(Tone){
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class Mid/Side processing separates the the 'mid' signal
|
|
|
|
* (which comes out of both the left and the right channel)
|
|
|
|
* and the 'side' (which only comes out of the the side channels).
|
|
|
|
* MidSideMerge merges the mid and side signal after they've been seperated
|
2015-06-20 23:25:49 +00:00
|
|
|
* by Tone.MidSideSplit.<br><br>
|
2015-07-04 16:32:18 +00:00
|
|
|
* <code>
|
2015-06-20 23:25:49 +00:00
|
|
|
* Left = (Mid+Side)/sqrt(2); // obtain left signal from mid and side<br>
|
|
|
|
* Right = (Mid-Side)/sqrt(2); // obtain right signal from mid and side<br>
|
2015-07-04 16:32:18 +00:00
|
|
|
* </code>
|
2015-04-20 19:41:30 +00:00
|
|
|
*
|
|
|
|
* @extends {Tone.StereoEffect}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
Tone.MidSideMerge = function(){
|
2017-04-26 03:08:23 +00:00
|
|
|
|
|
|
|
Tone.call(this);
|
2016-09-20 03:02:42 +00:00
|
|
|
this.createInsOuts(2, 0);
|
2015-04-20 19:41:30 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-20 23:25:49 +00:00
|
|
|
* The mid signal input. Alias for
|
|
|
|
* <code>input[0]</code>
|
2016-09-20 03:53:07 +00:00
|
|
|
* @type {Tone.Gain}
|
2015-04-20 19:41:30 +00:00
|
|
|
*/
|
2016-09-20 03:53:07 +00:00
|
|
|
this.mid = this.input[0] = new Tone.Gain();
|
2015-04-20 19:41:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* recombine the mid/side into Left
|
|
|
|
* @type {Tone.Expr}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._left = new Tone.Expr("($0 + $1) * $2");
|
|
|
|
|
|
|
|
/**
|
2015-06-20 23:25:49 +00:00
|
|
|
* The side signal input. Alias for
|
|
|
|
* <code>input[1]</code>
|
2016-09-20 03:53:07 +00:00
|
|
|
* @type {Tone.Gain}
|
2015-04-20 19:41:30 +00:00
|
|
|
*/
|
2016-09-20 03:53:07 +00:00
|
|
|
this.side = this.input[1] = new Tone.Gain();
|
2015-04-20 19:41:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* recombine the mid/side into Right
|
|
|
|
* @type {Tone.Expr}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._right = new Tone.Expr("($0 - $1) * $2");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge the left/right signal back into a stereo signal.
|
|
|
|
* @type {Tone.Merge}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._merge = this.output = new Tone.Merge();
|
|
|
|
|
|
|
|
this.mid.connect(this._left, 0, 0);
|
|
|
|
this.side.connect(this._left, 0, 1);
|
|
|
|
this.mid.connect(this._right, 0, 0);
|
|
|
|
this.side.connect(this._right, 0, 1);
|
|
|
|
this._left.connect(this._merge, 0, 0);
|
|
|
|
this._right.connect(this._merge, 0, 1);
|
2017-03-22 19:21:21 +00:00
|
|
|
this.context.getConstant(Math.SQRT1_2).connect(this._left, 0, 2);
|
|
|
|
this.context.getConstant(Math.SQRT1_2).connect(this._right, 0, 2);
|
2015-04-20 19:41:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.MidSideMerge);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.MidSideMerge} this
|
2015-04-20 19:41:30 +00:00
|
|
|
*/
|
|
|
|
Tone.MidSideMerge.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
2016-09-20 03:53:07 +00:00
|
|
|
this.mid.dispose();
|
2015-04-20 19:41:30 +00:00
|
|
|
this.mid = null;
|
2016-09-20 03:53:07 +00:00
|
|
|
this.side.dispose();
|
2015-04-20 19:41:30 +00:00
|
|
|
this.side = null;
|
|
|
|
this._left.dispose();
|
|
|
|
this._left = null;
|
|
|
|
this._right.dispose();
|
|
|
|
this._right = null;
|
|
|
|
this._merge.dispose();
|
|
|
|
this._merge = null;
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.MidSideMerge;
|
|
|
|
});
|