Skip to content

Lightweight sound synthesizer designed for real-time user interaction using the Web Audio API

License

Notifications You must be signed in to change notification settings

xenharmonic-devs/sw-synth

Repository files navigation

sw-synth

Lightweight sound synthesizer designed for real-time user interaction using the Web Audio API

Example

const context = new AudioContext({latencyHint: 'interactive'});

const synth = new Synth(context, context.destination);
synth.maxPolyphony = 6;
synth.voiceParams = defaultParams();

const noteOffs = new Map<string, () => void>();
window.addEventListener('keydown', (event: KeyboardEvent) => {
  const pitch = parseInt(event.key, 36) % 24;
  const frequency = 440 * 2 ** (pitch / 12);
  const velocity = 0.2;
  noteOffs.set(event.key, synth.noteOn(frequency, velocity));
});
window.addEventListener('keyup', (event: KeyboardEvent) => {
  if (noteOffs.has(event.key)) {
    noteOffs.get(event.key)!();
  }
});

Installation

npm i

Documentation

Documentation is hosted at the project Github pages.

To generate documentation locally run:

npm run doc

About

Lightweight sound synthesizer designed for real-time user interaction using the Web Audio API

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published