Tone.js/Tone/component/MidSideSplit.js

86 lines
2.2 KiB
JavaScript
Raw Normal View History

define(["../core/Tone", "../signal/Add", "../signal/Subtract", "../signal/Signal",
"../component/Split", "../core/AudioNode"], function(Tone){
2015-04-20 19:41:30 +00:00
"use strict";
/**
* @class Mid/Side processing separates the the 'mid' signal
* (which comes out of both the left and the right channel)
2015-06-20 23:25:49 +00:00
* 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.AudioNode}
2015-04-20 19:41:30 +00:00
* @constructor
*/
Tone.MidSideSplit = function(){
Tone.AudioNode.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>
2017-10-21 22:29:50 +00:00
* @type {Tone.Add}
2015-04-20 19:41:30 +00:00
*/
2017-10-21 22:29:50 +00:00
this._midAdd = new Tone.Add();
2015-04-20 19:41:30 +00:00
/**
2017-10-21 22:29:50 +00:00
* Multiply the _midAdd by sqrt(1/2)
* @type {Tone.Multiply}
2015-04-20 19:41:30 +00:00
*/
2017-10-21 22:29:50 +00:00
this.mid = this.output[0] = new Tone.Multiply(Math.SQRT1_2);
2015-04-20 19:41:30 +00:00
2017-10-21 22:29:50 +00:00
/**
* The side output. Connect to side processing. Also Output 1
* @type {Tone.Subtract}
*/
this._sideSubtract = new Tone.Subtract();
/**
* Multiply the _midAdd by sqrt(1/2)
* @type {Tone.Multiply}
*/
this.side = this.output[1] = new Tone.Multiply(Math.SQRT1_2);
this._split.connect(this._midAdd, 0, 0);
this._split.connect(this._midAdd, 1, 1);
this._split.connect(this._sideSubtract, 0, 0);
this._split.connect(this._sideSubtract, 1, 1);
this._midAdd.connect(this.mid);
this._sideSubtract.connect(this.side);
2015-04-20 19:41:30 +00:00
};
Tone.extend(Tone.MidSideSplit, Tone.AudioNode);
2015-04-20 19:41:30 +00:00
/**
* clean up
* @returns {Tone.MidSideSplit} this
2015-04-20 19:41:30 +00:00
*/
Tone.MidSideSplit.prototype.dispose = function(){
Tone.AudioNode.prototype.dispose.call(this);
2015-04-20 19:41:30 +00:00
this.mid.dispose();
this.mid = null;
this.side.dispose();
this.side = null;
2017-10-21 22:29:50 +00:00
this._midAdd.dispose();
this._midAdd = null;
this._sideSubtract.dispose();
this._sideSubtract = null;
2015-04-20 19:41:30 +00:00
this._split.dispose();
this._split = null;
return this;
};
return Tone.MidSideSplit;
});