2019-07-25 17:32:34 +00:00
|
|
|
import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
|
2019-07-30 19:35:27 +00:00
|
|
|
import { Positive } from "../../core/type/Units";
|
2019-07-25 17:32:34 +00:00
|
|
|
import { optionsFromArguments } from "../../core/util/Defaults";
|
2019-07-25 14:45:27 +00:00
|
|
|
|
|
|
|
interface MergeOptions extends ToneAudioNodeOptions {
|
|
|
|
channels: Positive;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge brings multiple mono input channels into a single multichannel output channel.
|
|
|
|
*
|
|
|
|
* @example
|
2019-07-25 15:32:56 +00:00
|
|
|
* var merge = new Merge().toDestination();
|
2019-07-25 14:45:27 +00:00
|
|
|
* //routing a sine tone in the left channel
|
|
|
|
* //and noise in the right channel
|
|
|
|
* var osc = new Tone.Oscillator().connect(merge.left);
|
|
|
|
* var noise = new Tone.Noise().connect(merge.right);
|
|
|
|
* //starting our oscillators
|
|
|
|
* noise.start();
|
|
|
|
* osc.start();
|
|
|
|
*/
|
|
|
|
export class Merge extends ToneAudioNode<MergeOptions> {
|
|
|
|
|
2019-09-04 22:38:04 +00:00
|
|
|
readonly name: string = "Merge";
|
2019-07-25 14:45:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The merger node for the two channels.
|
|
|
|
*/
|
|
|
|
private _merger: ChannelMergerNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The output is the input channels combined into a sigle (multichannel) output
|
|
|
|
*/
|
2019-08-03 01:47:57 +00:00
|
|
|
readonly output: ChannelMergerNode;
|
2019-07-25 14:45:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiple input connections combine into a single output.
|
|
|
|
*/
|
2019-08-03 01:47:57 +00:00
|
|
|
readonly input: ChannelMergerNode;
|
2019-07-25 14:45:27 +00:00
|
|
|
|
2019-08-27 17:02:31 +00:00
|
|
|
/**
|
|
|
|
* @param channels The number of channels to merge.
|
|
|
|
*/
|
2019-07-25 14:45:27 +00:00
|
|
|
constructor(channels?: Positive);
|
|
|
|
// tslint:disable-next-line: unified-signatures
|
|
|
|
constructor(options?: Partial<MergeOptions>);
|
|
|
|
constructor() {
|
|
|
|
super(optionsFromArguments(Merge.getDefaults(), arguments, ["channels"]));
|
|
|
|
const options = optionsFromArguments(Merge.getDefaults(), arguments, ["channels"]);
|
|
|
|
|
|
|
|
this._merger = this.output = this.input = this.context.createChannelMerger(options.channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getDefaults(): MergeOptions {
|
|
|
|
return Object.assign(ToneAudioNode.getDefaults(), {
|
|
|
|
channels: 2,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose(): this {
|
|
|
|
super.dispose();
|
|
|
|
this._merger.disconnect();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|