1 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
2 | import { Multiply } from "../signal/Multiply.js";
|
3 | import { ModulationSynth } from "./ModulationSynth.js";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export class FMSynth extends ModulationSynth {
|
17 | constructor() {
|
18 | const options = optionsFromArguments(FMSynth.getDefaults(), arguments);
|
19 | super(options);
|
20 | this.name = "FMSynth";
|
21 | this.modulationIndex = new Multiply({
|
22 | context: this.context,
|
23 | value: options.modulationIndex,
|
24 | });
|
25 |
|
26 | this.frequency.connect(this._carrier.frequency);
|
27 | this.frequency.chain(this.harmonicity, this._modulator.frequency);
|
28 | this.frequency.chain(this.modulationIndex, this._modulationNode);
|
29 | this.detune.fan(this._carrier.detune, this._modulator.detune);
|
30 | this._modulator.connect(this._modulationNode.gain);
|
31 | this._modulationNode.connect(this._carrier.frequency);
|
32 | this._carrier.connect(this.output);
|
33 | }
|
34 | static getDefaults() {
|
35 | return Object.assign(ModulationSynth.getDefaults(), {
|
36 | modulationIndex: 10,
|
37 | });
|
38 | }
|
39 | dispose() {
|
40 | super.dispose();
|
41 | this.modulationIndex.dispose();
|
42 | return this;
|
43 | }
|
44 | }
|
45 |
|
\ | No newline at end of file |