Instruments
Instruments are sound sources that can be triggered with notes. All instruments share a common interface for triggering attacks and releases.
Synth
A basic synthesizer with an oscillator and an ADSR envelope.
1let synth = Synth.make()2let synth2 = Synth.makeWithOptions({3 oscillator: {"type": "square"},4 envelope: {attack: 0.1, decay: 0.2, sustain: 0.5, release: 0.8},5 volume: -6.0,6})78synth->Synth.asAudioNode->AudioNode.toDestination910// Trigger a note11synth->Synth.triggerAttack("C4")12synth->Synth.triggerRelease()1314// Trigger attack and release in one call15synth->Synth.triggerAttackRelease("C4", "8n")1617// With time and velocity18synth->Synth.triggerAttackReleaseAtVel("E4", "4n", ~velocity=0.8)1920// Properties21synth->Synth.volume // Param.t22synth->Synth.frequency // Param.t23synth->Synth.detune // Param.t2425// Lifecycle26synth->Synth.dispose()27synth->Synth.sync()28synth->Synth.unsync()FMSynth
A frequency modulation synthesizer. Same trigger interface as Synth, plus modulation controls.
1let fm = FMSynth.make()2let fm2 = FMSynth.makeWithOptions({3 modulationIndex: 10.0,4 harmonicity: 3.0,5})67fm->FMSynth.asAudioNode->AudioNode.toDestination8fm->FMSynth.triggerAttackRelease("A3", "2n")910// FM-specific properties11fm->FMSynth.harmonicity // Param.t12fm->FMSynth.modulationIndex // Param.tAMSynth
An amplitude modulation synthesizer.
1let am = AMSynth.make()2am->AMSynth.asAudioNode->AudioNode.toDestination3am->AMSynth.triggerAttackRelease("G3", "4n")45am->AMSynth.harmonicity // Param.tMonoSynth
A monophonic synthesizer with one oscillator, a filter, and two envelopes.
1let mono = MonoSynth.make()2let mono2 = MonoSynth.makeWithOptions({3 oscillator: {"type": "sawtooth"},4 filterEnvelope: {5 attack: 0.01,6 decay: 0.3,7 sustain: 0.2,8 release: 0.5,9 baseFrequency: 200.0,10 octaves: 4.0,11 },12})1314mono->MonoSynth.asAudioNode->AudioNode.toDestination15mono->MonoSynth.triggerAttackRelease("D3", "8n")PolySynth
A polyphonic synthesizer that can play multiple notes simultaneously.
1let poly = PolySynth.make()2poly->PolySynth.asAudioNode->AudioNode.toDestination34// Play a chord5poly->PolySynth.triggerAttack(["C4", "E4", "G4"])6poly->PolySynth.triggerRelease(["C4", "E4", "G4"])78poly->PolySynth.triggerAttackRelease(["C4", "E4", "G4"], "2n")910// Set max polyphony11poly->PolySynth.maxPolyphony // int12poly->PolySynth.releaseAll()