UNPKG

1.93 kBJavaScriptView Raw
1import { Effect } from "../effect/Effect.js";
2import { LFO } from "../source/oscillator/LFO.js";
3import { readOnly } from "../core/util/Interface.js";
4/**
5 * Base class for LFO-based effects.
6 */
7export class LFOEffect extends Effect {
8 constructor(options) {
9 super(options);
10 this.name = "LFOEffect";
11 this._lfo = new LFO({
12 context: this.context,
13 frequency: options.frequency,
14 amplitude: options.depth,
15 });
16 this.depth = this._lfo.amplitude;
17 this.frequency = this._lfo.frequency;
18 this.type = options.type;
19 readOnly(this, ["frequency", "depth"]);
20 }
21 static getDefaults() {
22 return Object.assign(Effect.getDefaults(), {
23 frequency: 1,
24 type: "sine",
25 depth: 1,
26 });
27 }
28 /**
29 * Start the effect.
30 */
31 start(time) {
32 this._lfo.start(time);
33 return this;
34 }
35 /**
36 * Stop the lfo
37 */
38 stop(time) {
39 this._lfo.stop(time);
40 return this;
41 }
42 /**
43 * Sync the filter to the transport.
44 * @see {@link LFO.sync}
45 */
46 sync() {
47 this._lfo.sync();
48 return this;
49 }
50 /**
51 * Unsync the filter from the transport.
52 */
53 unsync() {
54 this._lfo.unsync();
55 return this;
56 }
57 /**
58 * The type of the LFO's oscillator.
59 * @see {@link Oscillator.type}
60 * @example
61 * const autoFilter = new Tone.AutoFilter().start().toDestination();
62 * const noise = new Tone.Noise().start().connect(autoFilter);
63 * autoFilter.type = "square";
64 */
65 get type() {
66 return this._lfo.type;
67 }
68 set type(type) {
69 this._lfo.type = type;
70 }
71 dispose() {
72 super.dispose();
73 this._lfo.dispose();
74 this.frequency.dispose();
75 this.depth.dispose();
76 return this;
77 }
78}
79//# sourceMappingURL=LFOEffect.js.map
\No newline at end of file