3 layered architecture for sound programming in JavaScript
All components in the main thread. This architecture works on the browser and the Node.js
$ npm install triolet.bundle
in the main thread
const triolet = require("triolet.bundle")();
const Driver = require("pico.driver.webaudio");
const API = require("./api");
const DSP = require("./dsp");
let audioContext = new AudioContext();
triolet.compose({ api: new API(), dsp: new DSP(), driver: new Driver() });
triolet.setup({ context: audioContext, bufferLength: 1024 });
triolet.start();
DRIVER
and API
in the main thread; DSP
in the worker thread. This architecture works on the browser.
$ npm install triolet.client
in the main thread
const triolet = require("triolet.client/client")();
const Driver = require("pico.driver.webaudio");
const API = require("./api");
let audioContext = new AudioContext();
triolet.compose({ api: new API(), driver: new Driver(), workerPath: "/path/to/worker" });
triolet.setup({ context: audioContext, bufferLength: 1024 });
triolet.start();
in the worker thread
const triolet = require("triolet.client/worker")(self);
const DSP = require("./dsp");
triolet.compose({ dsp: new DSP() });
DRIVER
in the main thread; API
and DSP
in the worker thread. This architecture works on the browser.
$ npm install triolet.worker
in the main thread
const triolet = require("triolet.worker/client")();
const Driver = require("pico.driver.webaudio");
let audioContext = new AudioContext();
triolet.compose({ driver: new Driver(), workerPath: "/path/to/worker" });
triolet.setup({ context: audioContext, bufferLength: 1024 });
triolet.sendToWorker({ type: "start" });
in the worker thread
const triolet = require("triolet.worker/worker")(self);
const API = require("./api");
const DSP = require("./dsp");
triolet.compose({ api: new API(), dsp: new DSP() });
triolet.recvFromClient = (e) => {
if (e.type === "start") {
triolet.start();
}
};
interface TrioletAPI {
optional setup(opts: object) => void;
optional start() => void;
optional stop() => void;
process(inNumSamples: number) => void;
}
interface TrioletDSP {
optional setup(opts: object) => void;
optional start() => void;
optional stop() => void;
process(bufL: Float32Array, bufR: Float32Array) => void;
}
MIT