elementary
Search…
WebAudio
Rendering Elementary applications via WebAudio is extremely simple. In general, you'll just need to import the ElementaryWebAudioRenderer from the top level package, establish a callback for the "load" event, initialize the renderer by passing in an AudioContext and an optional configuration object, then connect the resulting AudioWorkletNode to your desired destination.
1
import {ElementaryWebAudioRenderer as core, el} from '@nick-thompson/elementary';
2
3
core.on('load', function() {
4
core.render(el.cycle(440), el.cycle(441));
5
});
6
7
(async function main() {
8
let node = await core.initialize(ctx, {
9
numberOfInputs: 0,
10
numberOfOutputs: 1,
11
outputChannelCount: [2],
12
});
13
14
node.connect(ctx.destination);
15
})();
Copied!
Here, the ElementaryWebAudioRenderer.initialize function expects at least argument, an AudioContext, and an optional second argument which will be passed on to the construction of the underlying AudioWorkletNode. See the documentation for the AudioWorkletNode options object here.
Finally, ElementaryWebAudioRenderer.initialize is an async function (or, returns a promise) which resolves to the resulting AudioWorkletNode. You may connect inputs to and outputs from the returned node to insert the Elementary node into your WebAudio graph.
Last modified 1mo ago
Copy link