2019-07-25 13:32:34 -04:00
|
|
|
import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
|
2019-07-30 15:35:27 -04:00
|
|
|
import { Positive } from "../../core/type/Units";
|
2019-07-25 13:32:34 -04:00
|
|
|
import { optionsFromArguments } from "../../core/util/Defaults";
|
2019-07-25 10:45:27 -04:00
|
|
|
|
|
|
|
interface MergeOptions extends ToneAudioNodeOptions {
|
|
|
|
channels: Positive;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merge brings multiple mono input channels into a single multichannel output channel.
|
|
|
|
*
|
|
|
|
* @example
|
2019-10-22 23:39:35 -04:00
|
|
|
* import { Merge, Noise, Oscillator } from "tone";
|
2019-10-22 23:04:52 -04:00
|
|
|
* const merge = new Merge().toDestination();
|
|
|
|
* // routing a sine tone in the left channel
|
|
|
|
* const osc = new Oscillator().connect(merge, 0, 0).start();
|
|
|
|
* // and noise in the right channel
|
|
|
|
* const noise = new Noise().connect(merge, 0, 1).start();;
|
2019-09-16 10:15:23 -04:00
|
|
|
* @category Component
|
2019-07-25 10:45:27 -04:00
|
|
|
*/
|
|
|
|
export class Merge extends ToneAudioNode<MergeOptions> {
|
|
|
|
|
2019-09-04 19:18:44 -04:00
|
|
|
readonly name: string = "Merge";
|
2019-07-25 10:45:27 -04:00
|
|
|
|
|
|
|
/**
|
2019-09-14 16:39:18 -04:00
|
|
|
* The merger node for the two channels.
|
2019-07-25 10:45:27 -04:00
|
|
|
*/
|
|
|
|
private _merger: ChannelMergerNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The output is the input channels combined into a sigle (multichannel) output
|
|
|
|
*/
|
2019-08-02 21:47:57 -04:00
|
|
|
readonly output: ChannelMergerNode;
|
2019-07-25 10:45:27 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiple input connections combine into a single output.
|
|
|
|
*/
|
2019-08-02 21:47:57 -04:00
|
|
|
readonly input: ChannelMergerNode;
|
2019-07-25 10:45:27 -04:00
|
|
|
|
2019-08-27 10:02:31 -07:00
|
|
|
/**
|
|
|
|
* @param channels The number of channels to merge.
|
|
|
|
*/
|
2019-07-25 10:45:27 -04:00
|
|
|
constructor(channels?: Positive);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|