npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

synth-kit

v0.0.2

Published

Web Audio Synthesizers construction kit

Downloads

12

Readme

synth-kit

Travis CI Codecov CDNJS npm

Synthesizers construction kit for Web Audio API

Work in progress. Experimental API

synth-kit is a small (8Kb minified, 3Kb minified and gzipped) collection of ready-to-use Web Audio instruments:

import { Kick } from 'synth-kit'
const ac = new AudioContext()

// create a Kick instrument and connect it to the audio context destination
const kick = Kick(ac).connect(true)
// trigger the kick
kick.trigger()

Features

  • Sound reasonably good
  • No setup: nice defaults, no config
  • Easy and simple API
  • Extensible and flexible

SynthKit

Percussion instruments

Melodic instruments

Effects

Components

Usage

synth-kit is designed to be very easy to use: install the library, create an instrument and trigger it.

Installation

Node

With npm: npm i --save synth-kit or with yarn: yarn add --save synth-kit

ES6:

import { Clave } from "synth-kit"
const ac = new AudioContext()
const clave = Clave(ac).connect(true)
clave.trigger()

ES5:

const SynthKit = require('synth-kit')
const ac = new AudioContext()
const clave = new SynthKit.Clave(ac).connect(true)
clave.trigger()

Browser

<script src="https://oramics.github.io/synth-kit/dist/synth-kit.js"></script>
<script>
  // SynthKit is exported as global
  const ac = new AudioContext()
  const kick = SynthKit.Kick(ac).connect(true)
  kick.trigger()
</script>

Create instruments

Call the function with an audio context. The connect function is chainable and accepts true to connect to the AudioContext's destination:

import { MonoSynth } from 'synth-kit'

const mono = MonoSynth(ac).connect(true)
// trigger signature for melodic instruments: (midi, time, duration)
mono.trigger(440, ac.currentTime, 0.5)
mono.trigger(62, ac.currentTime + 1, 0.5)

Trigger

Trigger the attack/release envelope of an instrument with the trigger function:

import { Snare } from 'synth-kit'

const snare = Snare(ac).connect(true)
snare.trigger()

Perussion instruments accept time as trigger arguments:

snare.trigger(ac.currentTime + 1)

Melodic instruments accept frequency, time, duration as trigger arguments:

import { MonoSynth } from 'synth-kit'

const mono = MonoSynth(ac).connect(true)
mono.trigger(440, ac.currentTime, 0.5)

Re-triggerable

You can trigger an instrument any number of times:

mono.trigger(440, ac.currentTime, 0.5)
mono.trigger(880, ac.currentTime + 1, 0.5)

You can use Sample to get a re-triggerable buffer source:

import { Sample } from 'synth-kit'

fetch("snare.wav").then(decodeAudioData).then(buffer => {
  sample = Sample(ac, buffer)
  sample.trigger()
  sample.trigger(ac.currentTime + 1)
})

Attack/release

Using a melodic instrument, you can trigger the attack and release phases at different moments:

const triggerRelease = mono.trigger(440, ac.currentTime)
triggerRelease(ac.currentTime + 1)

Polyphony

All instruments are monophonic by default. You can create a polyphonic instrument with polyphonc function:

import { DuoSynth, polyphonic } from 'synth-kit'

const synth = polyphonic(ac, 16, DuoSynth)
const freqs = [400, 500, 600, 700]
freqs.forEach((note, i) => synth.trigger(note, ac.currentTime + i))

Update parameters

All instruments have an update function:

const duo = DuoSynth(ac)
duo.update({
  filter: {
    frequency: 800
  },
  amp: {
    gain: 0.5
  }
})
duo.trigger(440)

And an inspect function:

console.log(duo.inspect())
// console.log output:
{
  osc1: {
    frequency: 440,
    ...
  },
  osc2: {
    frequency: 880,
    ...
  },
  filter: {
    ...
  },
  amp: {
    gain: 0.6
  }
}

For fine-grained control, use the audio nodes directly:

const duo = DuoSynth(ac)
duo.filter.frequency.linearRampToValueAtTime(600, ac.currentTime + 1)

References

  • Of course, the synth secrets tutorial was the beginning of all: https://github.com/micjamking/synth-secrets (that's a easy to read version). Thanks Gordon Reid (here it is an awesome PDF version)
  • Vincent made some nice 808 drum synsthesis: https://github.com/vincentriemer/io-808
  • Percussion synthesis tutorial: http://www.cim.mcgill.ca/~clark/nordmodularbook/nm_percussion.html
  • Sound Design in Web Audio its an awesome two part blog post: http://nickwritesablog.com/sound-design-in-web-audio-neurofunk-bass-part-1/ and http://nickwritesablog.com/sound-design-in-web-audio-neurofunk-bass-part-2/
  • There are a lot of resources about synthesis, here is a nice one: https://www.gearslutz.com/board/electronic-music-instruments-electronic-music-production/460283-how-do-you-synthesize-808-ish-drums.html

License

MIT License