0.0.1 • Published 1 year ago
squavy-modular-synthesizer v0.0.1
A modular synthesizer engine written in Typescript and usable standalone in the browser.
Installation
In the root directory of the project, run the following commands:
npm install
npm run build
npm link
Usage
In the root directory of the target project that will use the synthesizer, run the following commands:
npm link squavy-modular-synthesizer
Then, in the code of the target project, import the synthesizer:
import { Oscillator, Envelope, Gain, SAMPLE_RATE, requestAudioBuffer, Note } from 'squavy-modular-synthesizer';
window.addEventListener("click", () => {
const osc = new Oscillator("Triangle", 1, 0.5, 0, 0);
const env = new Envelope(osc, 0.1, 0, 1, 0.5);
const gain = new Gain(env, 0.3);
const [bufferLeft, bufferRight] = requestAudioBuffer(gain, [
new Note(220, 0, 0.5, 1),
], 0, SAMPLE_RATE, SAMPLE_RATE);
const audioContext = new AudioContext({
sampleRate: SAMPLE_RATE,
});
const source = audioContext.createBufferSource();
const buffer = audioContext.createBuffer(2, SAMPLE_RATE, SAMPLE_RATE);
buffer.copyToChannel(bufferLeft, 0)
buffer.copyToChannel(bufferRight, 1)
source.buffer = buffer;
source.connect(audioContext.destination);
source.start();
});
0.0.1
1 year ago