Tone.js/Tone/component/Split.js

72 lines
1.6 KiB
JavaScript
Raw Normal View History

define(["../core/Tone", "../core/Gain", "../core/AudioNode"], function(Tone){
"use strict";
2014-06-17 15:48:17 +00:00
/**
2015-07-02 00:19:58 +00:00
* @class Tone.Split splits an incoming signal into left and right channels.
*
2014-06-17 15:48:17 +00:00
* @constructor
* @extends {Tone.AudioNode}
* @param {number} [channels=2] The number of channels to merge.
2015-02-27 21:53:10 +00:00
* @example
2015-06-14 05:09:06 +00:00
* var split = new Tone.Split();
* stereoSignal.connect(split);
2014-06-17 15:48:17 +00:00
*/
Tone.Split = function(channels){
//defaults to 2 channels
channels = Tone.defaultArg(channels, 2);
Tone.AudioNode.call(this);
this.createInsOuts(0, channels);
/**
2014-06-22 16:33:21 +00:00
* @type {ChannelSplitterNode}
2014-08-24 21:48:28 +00:00
* @private
2014-06-22 16:33:21 +00:00
*/
this._splitter = this.input = this.context.createChannelSplitter(channels);
//connections
for (var i = 0; i < channels; i++){
this.output[i] = new Tone.Gain();
this._splitter.connect(this.output[i], i, 0);
this.output[i].channelCount = 1;
this.output[i].channelCountMode = "explicit";
}
/**
* Left channel output.
2015-06-20 23:25:49 +00:00
* Alias for <code>output[0]</code>
* @type {Tone.Gain}
2014-06-17 15:48:17 +00:00
*/
this.left = this.output[0];
2014-06-17 15:48:17 +00:00
/**
2015-06-20 23:25:49 +00:00
* Right channel output.
* Alias for <code>output[1]</code>
* @type {Tone.Gain}
2014-06-17 15:48:17 +00:00
*/
this.right = this.output[1];
2014-06-17 15:48:17 +00:00
};
Tone.extend(Tone.Split, Tone.AudioNode);
2014-06-20 04:38:14 +00:00
/**
* Clean up.
* @returns {Tone.Split} this
2014-06-20 04:38:14 +00:00
*/
2014-06-21 17:09:46 +00:00
Tone.Split.prototype.dispose = function(){
this.output.forEach(function(output){
output.dispose();
});
Tone.AudioNode.prototype.dispose.call(this);
2014-08-24 21:48:28 +00:00
this._splitter.disconnect();
this.left = null;
this.right = null;
2014-08-24 21:48:28 +00:00
this._splitter = null;
2015-02-02 17:49:13 +00:00
return this;
};
2014-06-20 04:38:14 +00:00
return Tone.Split;
});