UNPKG

1.93 kBJavaScriptView Raw
1import { optionsFromArguments } from "../core/util/Defaults.js";
2import { Multiply } from "../signal/Multiply.js";
3import { ModulationSynth } from "./ModulationSynth.js";
4/**
5 * FMSynth is composed of two Tone.Synths where one Tone.Synth modulates
6 * the frequency of a second Tone.Synth. A lot of spectral content
7 * can be explored using the modulationIndex parameter. Read more about
8 * frequency modulation synthesis on Sound On Sound: [Part 1](https://web.archive.org/web/20160403123704/http://www.soundonsound.com/sos/apr00/articles/synthsecrets.htm), [Part 2](https://web.archive.org/web/20160403115835/http://www.soundonsound.com/sos/may00/articles/synth.htm).
9 *
10 * @example
11 * const fmSynth = new Tone.FMSynth().toDestination();
12 * fmSynth.triggerAttackRelease("C5", "4n");
13 *
14 * @category Instrument
15 */
16export 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 // control the two voices frequency
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//# sourceMappingURL=FMSynth.js.map
\No newline at end of file