Tone.js/Tone/component/MidSideSplit.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-04-20 19:41:30 +00:00
define(["Tone/core/Tone", "Tone/signal/Expr", "Tone/signal/Signal", "Tone/component/Split"],
function(Tone){
"use strict";
/**
2015-06-20 23:25:49 +00:00
* @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). <br><br>
* <code>
2015-06-20 23:25:49 +00:00
* Mid = (Left+Right)/sqrt(2); // obtain mid-signal from left and right<br>
* Side = (Left-Right)/sqrt(2); // obtain side-signal from left and righ<br>
* </code>
2015-04-20 19:41:30 +00:00
*
* @extends {Tone}
* @constructor
*/
Tone.MidSideSplit = function(){
Tone.call(this);
2016-09-20 03:02:42 +00:00
this.createInsOuts(0, 2);
2015-04-20 19:41:30 +00:00
/**
* split the incoming signal into left and right channels
* @type {Tone.Split}
* @private
*/
this._split = this.input = new Tone.Split();
/**
2015-06-20 23:25:49 +00:00
* The mid send. Connect to mid processing. Alias for
* <code>output[0]</code>
2015-04-20 19:41:30 +00:00
* @type {Tone.Expr}
*/
this.mid = this.output[0] = new Tone.Expr("($0 + $1) * $2");
/**
2015-06-20 23:25:49 +00:00
* The side output. Connect to side processing. Alias for
* <code>output[1]</code>
2015-04-20 19:41:30 +00:00
* @type {Tone.Expr}
*/
this.side = this.output[1] = new Tone.Expr("($0 - $1) * $2");
this._split.connect(this.mid, 0, 0);
this._split.connect(this.mid, 1, 1);
this._split.connect(this.side, 0, 0);
this._split.connect(this.side, 1, 1);
this.context.getConstant(Math.SQRT1_2).connect(this.mid, 0, 2);
this.context.getConstant(Math.SQRT1_2).connect(this.side, 0, 2);
2015-04-20 19:41:30 +00:00
};
Tone.extend(Tone.MidSideSplit);
/**
* clean up
* @returns {Tone.MidSideSplit} this
2015-04-20 19:41:30 +00:00
*/
Tone.MidSideSplit.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this.mid.dispose();
this.mid = null;
this.side.dispose();
this.side = null;
this._split.dispose();
this._split = null;
return this;
};
return Tone.MidSideSplit;
});