2
0
Fork 0
mirror of https://github.com/Tonejs/Tone.js synced 2025-02-15 12:08:29 +00:00
Tone.js/Tone/component/channel/Split.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-08-02 21:46:36 -04: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
2019-10-22 23:39:35 -04:00
* import { Split } from "tone";
*
* const split = new Split();
* // stereoSignal.connect(split);
2019-09-16 10:15:23 -04:00
* @category Component
2019-08-02 21:46:36 -04:00
*/
export class Split extends ToneAudioNode<SplitOptions> {
2019-09-04 19:18:44 -04:00
readonly name: string = "Split";
2019-08-02 21:46:36 -04:00
/**
* The splitting node
*/
private _splitter: ChannelSplitterNode;
readonly input: ChannelSplitterNode;
readonly output: ChannelSplitterNode;
2019-08-27 10:02:31 -07:00
/**
* @param channels The number of channels to merge.
*/
2019-08-02 21:46:36 -04: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;
}
}