UNPKG

1.52 kBJavaScriptView Raw
1import { AudioToGain } from "../signal/AudioToGain.js";
2import { optionsFromArguments } from "../core/util/Defaults.js";
3import { ModulationSynth } from "./ModulationSynth.js";
4/**
5 * AMSynth uses the output of one Tone.Synth to modulate the
6 * amplitude of another Tone.Synth. The harmonicity (the ratio between
7 * the two signals) affects the timbre of the output signal greatly.
8 * Read more about Amplitude Modulation Synthesis on
9 * [SoundOnSound](https://web.archive.org/web/20160404103653/http://www.soundonsound.com:80/sos/mar00/articles/synthsecrets.htm).
10 *
11 * @example
12 * const synth = new Tone.AMSynth().toDestination();
13 * synth.triggerAttackRelease("C4", "4n");
14 *
15 * @category Instrument
16 */
17export class AMSynth extends ModulationSynth {
18 constructor() {
19 super(optionsFromArguments(AMSynth.getDefaults(), arguments));
20 this.name = "AMSynth";
21 this._modulationScale = new AudioToGain({
22 context: this.context,
23 });
24 // control the two voices frequency
25 this.frequency.connect(this._carrier.frequency);
26 this.frequency.chain(this.harmonicity, this._modulator.frequency);
27 this.detune.fan(this._carrier.detune, this._modulator.detune);
28 this._modulator.chain(this._modulationScale, this._modulationNode.gain);
29 this._carrier.chain(this._modulationNode, this.output);
30 }
31 dispose() {
32 super.dispose();
33 this._modulationScale.dispose();
34 return this;
35 }
36}
37//# sourceMappingURL=AMSynth.js.map
\No newline at end of file