Tone.js/Tone/component/channel/Split.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-08-03 01:46:36 +00:00
import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
import { optionsFromArguments } from "../../core/util/Defaults";
interface SplitOptions extends ToneAudioNodeOptions {
channels: number;
}
/**
* Split splits an incoming signal into the number of given channels.
*
* @example
* var split = new Split();
* stereoSignal.connect(split);
2019-09-16 14:15:23 +00:00
* @category Component
2019-08-03 01:46:36 +00:00
*/
export class Split extends ToneAudioNode<SplitOptions> {
2019-09-04 23:18:44 +00:00
readonly name: string = "Split";
2019-08-03 01:46:36 +00:00
/**
* The splitting node
*/
private _splitter: ChannelSplitterNode;
readonly input: ChannelSplitterNode;
readonly output: ChannelSplitterNode;
2019-08-27 17:02:31 +00:00
/**
* @param channels The number of channels to merge.
*/
2019-08-03 01:46:36 +00:00
constructor(channels?: number);
constructor(options?: Partial<SplitOptions>);
constructor() {
super(optionsFromArguments(Split.getDefaults(), arguments, ["channels"]));
const options = optionsFromArguments(Split.getDefaults(), arguments, ["channels"]);
this._splitter = this.input = this.output = this.context.createChannelSplitter(options.channels);
this._internalChannels = [this._splitter];
}
static getDefaults(): SplitOptions {
return Object.assign(ToneAudioNode.getDefaults(), {
channels: 2,
});
}
dispose(): this {
super.dispose();
this._splitter.disconnect();
return this;
}
}