0.6.0 • Published 5 years ago

granular-js v0.6.0

Weekly downloads
3
License
MIT
Repository
-
Last release
5 years ago

granular-js

A simple granular synthesis library.

  • built with Web Audio API
  • no dependencies

How to use

Install via npm:

npm i granular-js

Use:

import Granular from 'granular-js';

// create instance with optional configuration
const granular = new Granular({
  envelope: {
    attack: 0,
    decay: 0.5
  },
  density: 0.9,
  spread: 0.1,
  pitch: 1
});

// listen for events
granular.on('settingBuffer', () => {
  // ...
});

granular.on('bufferSet', () => {
  // ...
});

granular.on('grainCreated', ({ gain, position }) => {
  // ...
});

// set parameters
granular.set({
  pitch: {
    0.5
  }
});

const data = await getData('example.wav');

await granular.setBuffer(data);

// start voice
const id = granular.startVoice({
  position: 10,
  volume: 0.5
});

// update voice
granular.updateVoice({
  id,
  position: 20
});

// stop voice
granular.stopVoice(id);

See example.

License

MIT

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago