1 | import { Filter } from "../component/filter/Filter.js";
|
2 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
3 | import { LFOEffect } from "./LFOEffect.js";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export class AutoFilter extends LFOEffect {
|
17 | constructor() {
|
18 | const options = optionsFromArguments(AutoFilter.getDefaults(), arguments, ["frequency", "baseFrequency", "octaves"]);
|
19 | super(options);
|
20 | this.name = "AutoFilter";
|
21 | this.filter = new Filter(Object.assign(options.filter, {
|
22 | context: this.context,
|
23 | }));
|
24 |
|
25 | this.connectEffect(this.filter);
|
26 | this._lfo.connect(this.filter.frequency);
|
27 | this.octaves = options.octaves;
|
28 | this.baseFrequency = options.baseFrequency;
|
29 | }
|
30 | static getDefaults() {
|
31 | return Object.assign(LFOEffect.getDefaults(), {
|
32 | baseFrequency: 200,
|
33 | octaves: 2.6,
|
34 | filter: {
|
35 | type: "lowpass",
|
36 | rolloff: -12,
|
37 | Q: 1,
|
38 | },
|
39 | });
|
40 | }
|
41 | |
42 |
|
43 |
|
44 | get baseFrequency() {
|
45 | return this._lfo.min;
|
46 | }
|
47 | set baseFrequency(freq) {
|
48 | this._lfo.min = this.toFrequency(freq);
|
49 |
|
50 | this.octaves = this._octaves;
|
51 | }
|
52 | |
53 |
|
54 |
|
55 | get octaves() {
|
56 | return this._octaves;
|
57 | }
|
58 | set octaves(oct) {
|
59 | this._octaves = oct;
|
60 | this._lfo.max = this._lfo.min * Math.pow(2, oct);
|
61 | }
|
62 | dispose() {
|
63 | super.dispose();
|
64 | this.filter.dispose();
|
65 | return this;
|
66 | }
|
67 | }
|
68 |
|
\ | No newline at end of file |