UNPKG

2.06 kBJavaScriptView Raw
1import { Effect } from "./Effect.js";
2import { optionsFromArguments } from "../core/util/Defaults.js";
3import { LFO } from "../source/oscillator/LFO.js";
4import { Delay } from "../core/context/Delay.js";
5import { readOnly } from "../core/util/Interface.js";
6/**
7 * A Vibrato effect composed of a Tone.Delay and a Tone.LFO. The LFO
8 * modulates the delayTime of the delay, causing the pitch to rise and fall.
9 * @category Effect
10 */
11export class Vibrato extends Effect {
12 constructor() {
13 const options = optionsFromArguments(Vibrato.getDefaults(), arguments, [
14 "frequency",
15 "depth",
16 ]);
17 super(options);
18 this.name = "Vibrato";
19 this._delayNode = new Delay({
20 context: this.context,
21 delayTime: 0,
22 maxDelay: options.maxDelay,
23 });
24 this._lfo = new LFO({
25 context: this.context,
26 type: options.type,
27 min: 0,
28 max: options.maxDelay,
29 frequency: options.frequency,
30 phase: -90, // offse the phase so the resting position is in the center
31 })
32 .start()
33 .connect(this._delayNode.delayTime);
34 this.frequency = this._lfo.frequency;
35 this.depth = this._lfo.amplitude;
36 this.depth.value = options.depth;
37 readOnly(this, ["frequency", "depth"]);
38 this.effectSend.chain(this._delayNode, this.effectReturn);
39 }
40 static getDefaults() {
41 return Object.assign(Effect.getDefaults(), {
42 maxDelay: 0.005,
43 frequency: 5,
44 depth: 0.1,
45 type: "sine",
46 });
47 }
48 /**
49 * Type of oscillator attached to the Vibrato.
50 */
51 get type() {
52 return this._lfo.type;
53 }
54 set type(type) {
55 this._lfo.type = type;
56 }
57 dispose() {
58 super.dispose();
59 this._delayNode.dispose();
60 this._lfo.dispose();
61 this.frequency.dispose();
62 this.depth.dispose();
63 return this;
64 }
65}
66//# sourceMappingURL=Vibrato.js.map
\No newline at end of file