Skip to content

danigb/synthlet

Repository files navigation

Synthlet

npm version

Collection of synth modules implemented as AudioWorklets.

import {
  registerAllWorklets,
  AdsrAmp,
  Svf,
  SvfType,
  PolyblepOscillator
} from "synthlet";

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

// Simplest synth: Oscillator -> Filter -> Amplifier
const osc = PolyblepOscillator(ac, { frequency: 440 });
const filter = Svf(ac, {
  type: SvfType.LowPass
  frequency: 4000,
});
const amp = AdsrAmp(ac, { attack: 0.1, release: 0.5 });
osc.connect(filter).connect(amp).connect(ac.destination);

// Change parameters
osc.frequency.value = 1200;

// Start sound
amp.gate.value = 1;

// Stop sound
vca.gate.value = 0;

Install

Install synthlet to install all modules:

npm i synthlet

Or each module individually:

npm i @synthlet/adsr

Documentation

Documentation and examples are here

Why?

Mostly, because I want to learn dsp.

Is it a good idea to write dsp in Typescript?

Probably not, but I've seen a talk at WAC 2022 about it that made me think it is possible (thanks to JS engine optimizations).

Should I use it?

Just for fun and curiosity. If you want to make music, Tone.js is probably the way to go.

If you want to deploy dsp modules to web in production, currently Faust and Cmajor or Elementary Audio are better alternatives.

References

This library wouldn't be possible with all the people writing books, blog posts and awesome libraries... and making music! Thanks to all 💚

Books

Blogs and papers

Synthesis open source repositories

Other

License

MIT License