Synthlet

Get started

How to get started with Synthlet

Synthlet is a collection of audio modules implemented as AudioWorkletNodes that you can use to create synthesizers and audio effects in the browser.

Install

You can installl all modules using the synthlet package:

npm install synthlet

Register worklet processors

Before you can create any module, you need to register the worklet processors. You can do this by calling the registerAllWorklets to register all modules at once:

import { registerAllWorklets } from "synthlet";
 
const audioContext = new AudioContext();
await registerAllWorklets(audioContext);

Register is async

registerAllWorklets (and all register functions) are async, so ensure you await for the result before creating any modules.

By convenience, registerAllWorklets returns the AudioContext so you can write it more concise:

const audioContext = await registerAllWorklets(new AudioContext());

Create the first synth

You can create a synth by creating nodes and connect them.

A simple archetipical monophonic synthesizer consist of an oscillator connected to a filter connected to an amplifier with an envelope.

Here's the full gist:

import {
  registerAllWorklets
  PolyblepOscillator,
  VirtualAnalogFilter,
  AdsrAmp,
} from "synthlet";
 
const ac = await registerAllWorklets(new AudioContext());
 
const osc = PolyblepOscillator(ac, {frequency: 440 });
const filter = VirtualAnalogFilter(ac, {
  type: VirtualAnalogFilter.MOOG_LADDER,
  frequency: 1500,
});
const vca = AdsrAmp(ac, {
  attack: 0.01,
  decay: 0.1,
  sustain: 0.7,
  release: 0.3,
});
 
osc.connect(filter).connect(vca).connect(ac.destination);
 
// Trigger the envelope
vca.gate.value = 1;

At this point you should able to hear some sound. If you don't hear anything, check the browser console for any errors.

No new required

Unlike the standard WebAudio API, Synthlet modules are functions, not classes. So no new is required to create a module.

No start required

Unlike the standard WebAudio API, Synthlet modules start automatically. No need to call the start method on the module to start it.

Read more about how to use the modules in the guide.

On this page