1 | import { Effect } from "./Effect.js";
|
2 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
3 | import { LFO } from "../source/oscillator/LFO.js";
|
4 | import { Delay } from "../core/context/Delay.js";
|
5 | import { readOnly } from "../core/util/Interface.js";
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export 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,
|
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 |
|
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 |
|
\ | No newline at end of file |