UNPKG

5.03 kBTypeScriptView Raw
1import { Param } from "../../core/context/Param.js";
2import { InputNode, OutputNode, ToneAudioNode } from "../../core/context/ToneAudioNode.js";
3import { Degrees, Frequency, NormalRange, Time, UnitName } from "../../core/type/Units.js";
4import { BasicPlaybackState } from "../../core/util/StateTimeline.js";
5import { Signal } from "../../signal/Signal.js";
6import { ToneOscillatorType } from "./Oscillator.js";
7import { ToneOscillatorOptions } from "./OscillatorInterface.js";
8export type LFOOptions = {
9 min: number;
10 max: number;
11 amplitude: NormalRange;
12 units: UnitName;
13} & ToneOscillatorOptions;
14/**
15 * LFO stands for low frequency oscillator. LFO produces an output signal
16 * which can be attached to an AudioParam or Tone.Signal
17 * in order to modulate that parameter with an oscillator. The LFO can
18 * also be synced to the transport to start/stop and change when the tempo changes.
19 * @example
20 * return Tone.Offline(() => {
21 * const lfo = new Tone.LFO("4n", 400, 4000).start().toDestination();
22 * }, 0.5, 1);
23 * @category Source
24 */
25export declare class LFO extends ToneAudioNode<LFOOptions> {
26 readonly name: string;
27 /**
28 * The oscillator.
29 */
30 private _oscillator;
31 /**
32 * The gain of the output
33 */
34 private _amplitudeGain;
35 /**
36 * The amplitude of the LFO, which controls the output range between
37 * the min and max output. For example if the min is -10 and the max
38 * is 10, setting the amplitude to 0.5 would make the LFO modulate
39 * between -5 and 5.
40 */
41 readonly amplitude: Param<"normalRange">;
42 /**
43 * The signal which is output when the LFO is stopped
44 */
45 private _stoppedSignal;
46 /**
47 * Just outputs zeros. This is used so that scaled signal is not
48 * optimized to silence.
49 */
50 private _zeros;
51 /**
52 * The value that the LFO outputs when it's stopped
53 */
54 private _stoppedValue;
55 /**
56 * Convert the oscillators audio range to an output between 0-1 so it can be scaled
57 */
58 private _a2g;
59 /**
60 * Scales the final output to the min and max value
61 */
62 private _scaler;
63 /**
64 * The output of the LFO
65 */
66 readonly output: OutputNode;
67 /**
68 * There is no input node
69 */
70 readonly input: undefined;
71 /**
72 * A private placeholder for the units
73 */
74 private _units;
75 /**
76 * If the input value is converted using the {@link units}
77 */
78 convert: boolean;
79 /**
80 * The frequency value of the LFO
81 */
82 readonly frequency: Signal<"frequency">;
83 /**
84 * @param frequency The frequency of the oscillation.
85 * Typically, LFOs will be in the frequency range of 0.1 to 10 hertz.
86 * @param min The minimum output value of the LFO.
87 * @param max The maximum value of the LFO.
88 */
89 constructor(frequency?: Frequency, min?: number, max?: number);
90 constructor(options?: Partial<LFOOptions>);
91 static getDefaults(): LFOOptions;
92 /**
93 * Start the LFO.
94 * @param time The time the LFO will start
95 */
96 start(time?: Time): this;
97 /**
98 * Stop the LFO.
99 * @param time The time the LFO will stop
100 */
101 stop(time?: Time): this;
102 /**
103 * Sync the start/stop/pause to the transport
104 * and the frequency to the bpm of the transport
105 * @example
106 * const lfo = new Tone.LFO("8n");
107 * lfo.sync().start(0);
108 * // the rate of the LFO will always be an eighth note, even as the tempo changes
109 */
110 sync(): this;
111 /**
112 * unsync the LFO from transport control
113 */
114 unsync(): this;
115 /**
116 * After the oscillator waveform is updated, reset the `_stoppedSignal` value to match the updated waveform
117 */
118 private _setStoppedValue;
119 /**
120 * The minimum output of the LFO.
121 */
122 get min(): number;
123 set min(min: number);
124 /**
125 * The maximum output of the LFO.
126 */
127 get max(): number;
128 set max(max: number);
129 /**
130 * The type of the oscillator.
131 * @see {@link Oscillator.type}
132 */
133 get type(): ToneOscillatorType;
134 set type(type: ToneOscillatorType);
135 /**
136 * The oscillator's partials array.
137 * @see {@link Oscillator.partials}
138 */
139 get partials(): number[];
140 set partials(partials: number[]);
141 /**
142 * The phase of the LFO.
143 */
144 get phase(): Degrees;
145 set phase(phase: Degrees);
146 /**
147 * The output units of the LFO.
148 */
149 get units(): UnitName;
150 set units(val: UnitName);
151 /**
152 * Returns the playback state of the source, either "started" or "stopped".
153 */
154 get state(): BasicPlaybackState;
155 /**
156 * @param node the destination to connect to
157 * @param outputNum the optional output number
158 * @param inputNum the input number
159 */
160 connect(node: InputNode, outputNum?: number, inputNum?: number): this;
161 /**
162 * Private methods borrowed from Param
163 */
164 private _fromType;
165 private _toType;
166 private _is;
167 private _clampValue;
168 dispose(): this;
169}