1 | import { AudioToGain } from "../signal/AudioToGain.js";
|
2 | import { RecursivePartial } from "../core/util/Interface.js";
|
3 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
4 | import { ModulationSynth, ModulationSynthOptions } from "./ModulationSynth.js";
|
5 |
|
6 | export type AMSynthOptions = ModulationSynthOptions;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export class AMSynth extends ModulationSynth<AMSynthOptions> {
|
22 | readonly name: string = "AMSynth";
|
23 |
|
24 | |
25 |
|
26 |
|
27 | private _modulationScale: AudioToGain;
|
28 |
|
29 | constructor(options?: RecursivePartial<AMSynthOptions>);
|
30 | constructor() {
|
31 | super(optionsFromArguments(AMSynth.getDefaults(), arguments));
|
32 |
|
33 | this._modulationScale = new AudioToGain({
|
34 | context: this.context,
|
35 | });
|
36 |
|
37 | // control the two voices frequency
|
38 | this.frequency.connect(this._carrier.frequency);
|
39 | this.frequency.chain(this.harmonicity, this._modulator.frequency);
|
40 | this.detune.fan(this._carrier.detune, this._modulator.detune);
|
41 | this._modulator.chain(this._modulationScale, this._modulationNode.gain);
|
42 | this._carrier.chain(this._modulationNode, this.output);
|
43 | }
|
44 |
|
45 | dispose(): this {
|
46 | super.dispose();
|
47 | this._modulationScale.dispose();
|
48 | return this;
|
49 | }
|
50 | }
|