UNPKG

1.71 kBPlain TextView Raw
1import { AudioToGain } from "../signal/AudioToGain.js";
2import { RecursivePartial } from "../core/util/Interface.js";
3import { optionsFromArguments } from "../core/util/Defaults.js";
4import { ModulationSynth, ModulationSynthOptions } from "./ModulationSynth.js";
5
6export type AMSynthOptions = ModulationSynthOptions;
7
8/**
9 * AMSynth uses the output of one Tone.Synth to modulate the
10 * amplitude of another Tone.Synth. The harmonicity (the ratio between
11 * the two signals) affects the timbre of the output signal greatly.
12 * Read more about Amplitude Modulation Synthesis on
13 * [SoundOnSound](https://web.archive.org/web/20160404103653/http://www.soundonsound.com:80/sos/mar00/articles/synthsecrets.htm).
14 *
15 * @example
16 * const synth = new Tone.AMSynth().toDestination();
17 * synth.triggerAttackRelease("C4", "4n");
18 *
19 * @category Instrument
20 */
21export class AMSynth extends ModulationSynth<AMSynthOptions> {
22 readonly name: string = "AMSynth";
23
24 /**
25 * Scale the oscillator from -1,1 to 0-1
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}