UNPKG

3.05 kBTypeScriptView Raw
1import { Gain } from "../../core/context/Gain.js";
2import { ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode.js";
3import { NormalRange } from "../../core/type/Units.js";
4import { Signal } from "../../signal/Signal.js";
5interface CrossFadeOptions extends ToneAudioNodeOptions {
6 fade: NormalRange;
7}
8/**
9 * Tone.Crossfade provides equal power fading between two inputs.
10 * More on crossfading technique [here](https://en.wikipedia.org/wiki/Fade_(audio_engineering)#Crossfading).
11 * ```
12 * +---------+
13 * +> input a +>--+
14 * +-----------+ +---------------------+ | | |
15 * | 1s signal +>--> stereoPannerNode L +>----> gain | |
16 * +-----------+ | | +---------+ |
17 * +-> pan R +>-+ | +--------+
18 * | +---------------------+ | +---> output +>
19 * +------+ | | +---------+ | +--------+
20 * | fade +>----+ | +> input b +>--+
21 * +------+ | | |
22 * +--> gain |
23 * +---------+
24 * ```
25 * @example
26 * const crossFade = new Tone.CrossFade().toDestination();
27 * // connect two inputs Tone.to a/b
28 * const inputA = new Tone.Oscillator(440, "square").connect(crossFade.a).start();
29 * const inputB = new Tone.Oscillator(440, "sine").connect(crossFade.b).start();
30 * // use the fade to control the mix between the two
31 * crossFade.fade.value = 0.5;
32 * @category Component
33 */
34export declare class CrossFade extends ToneAudioNode<CrossFadeOptions> {
35 readonly name: string;
36 /**
37 * The crossfading is done by a StereoPannerNode
38 */
39 private _panner;
40 /**
41 * Split the output of the panner node into two values used to control the gains.
42 */
43 private _split;
44 /**
45 * Convert the fade value into an audio range value so it can be connected
46 * to the panner.pan AudioParam
47 */
48 private _g2a;
49 /**
50 * The input which is at full level when fade = 0
51 */
52 readonly a: Gain;
53 /**
54 * The input which is at full level when fade = 1
55 */
56 readonly b: Gain;
57 /**
58 * The output is a mix between `a` and `b` at the ratio of `fade`
59 */
60 readonly output: Gain;
61 /**
62 * CrossFade has no input, you must choose either `a` or `b`
63 */
64 readonly input: undefined;
65 /**
66 * The mix between the two inputs. A fade value of 0
67 * will output 100% crossFade.a and
68 * a value of 1 will output 100% crossFade.b.
69 */
70 readonly fade: Signal<"normalRange">;
71 protected _internalChannels: Gain<"gain">[];
72 /**
73 * @param fade The initial fade value [0, 1].
74 */
75 constructor(fade?: NormalRange);
76 constructor(options?: Partial<CrossFadeOptions>);
77 static getDefaults(): CrossFadeOptions;
78 dispose(): this;
79}
80export {};