mirror of
https://github.com/Tonejs/Tone.js
synced 2024-12-27 12:03:12 +00:00
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import { AudioToGain } from "../signal/AudioToGain";
|
|
import { RecursivePartial } from "../core/util/Interface";
|
|
import { optionsFromArguments } from "../core/util/Defaults";
|
|
import { ModulationSynth, ModulationSynthOptions } from "./ModulationSynth";
|
|
|
|
export type AMSynthOptions = ModulationSynthOptions;
|
|
|
|
/**
|
|
* AMSynth uses the output of one Tone.Synth to modulate the
|
|
* amplitude of another Tone.Synth. The harmonicity (the ratio between
|
|
* the two signals) affects the timbre of the output signal greatly.
|
|
* Read more about Amplitude Modulation Synthesis on
|
|
* [SoundOnSound](https://web.archive.org/web/20160404103653/http://www.soundonsound.com:80/sos/mar00/articles/synthsecrets.htm).
|
|
*
|
|
* @example
|
|
* import { AMSynth } from "tone";
|
|
* const synth = new AMSynth().toMaster();
|
|
* synth.triggerAttackRelease("C4", "4n");
|
|
*
|
|
* @category Instrument
|
|
*/
|
|
export class AMSynth extends ModulationSynth<AMSynthOptions> {
|
|
|
|
readonly name: string = "AMSynth";
|
|
|
|
/**
|
|
* Scale the oscillator from -1,1 to 0-1
|
|
*/
|
|
private _modulationScale: AudioToGain;
|
|
|
|
constructor(options?: RecursivePartial<AMSynthOptions>);
|
|
constructor() {
|
|
super(optionsFromArguments(AMSynth.getDefaults(), arguments));
|
|
const options = optionsFromArguments(AMSynth.getDefaults(), arguments);
|
|
|
|
this._modulationScale = new AudioToGain({
|
|
context: this.context,
|
|
});
|
|
|
|
// control the two voices frequency
|
|
this.frequency.connect(this._carrier.frequency);
|
|
this.frequency.chain(this.harmonicity, this._modulator.frequency);
|
|
this.detune.fan(this._carrier.detune, this._modulator.detune);
|
|
this._modulator.chain(this._modulationScale, this._modulationNode.gain);
|
|
this._carrier.chain(this._modulationNode, this.output);
|
|
}
|
|
|
|
dispose(): this {
|
|
super.dispose();
|
|
this._modulationScale.dispose();
|
|
return this;
|
|
}
|
|
}
|