Skip to content

danigb/synthlet

Repository files navigation

Synthlet

npm version

Collection of synth modules implemented as AudioWorklets.

import {
  // Modules
  Amp, // Amplifier with an envelope
  Output, // Output with gain control
  Polyblep, // Polyblep oscillator
  Svf, // State Variable Filter

  // Connections
  Patch, // Create a patch
  Serial, // Serial connection

  // Utils
  registerWorklets, // Register worklets
} from "synthlet";

// Initialize AudioContext
const ac = new AudioContext();
await registerWorklets(ac);

// Create modules
const osc = Polybleb.saw(ac, { frequency: 440 });
const filter = Svf.lp(ac, { frequency: 1000 });
const amp = Amp.adsr(ac, { trigger, attack: 0.01, release: 0.3 });
const out = Output(ac, { db: -3 });

// Make connections
Serial([osc, filter, amp, out]);

// Create a patch
const patch = Patch(out, { osc, filter, amp });

// Use the patch
patch.connect(ctx.destination);
patch.osc.frequency.value = 300;
patch.amp.gate.value = 1; // start sound
patch.amp.gate.value = 0; // stop sound

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