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);
|
|
|
|
*/
|
|
|
|
export class Split extends ToneAudioNode<SplitOptions> {
|
2019-09-04 22:38:04 +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);
|
|
|
|
// tslint:disable-next-line: unified-signatures
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|