AudioWorklet Usage
The current repository uses AudioWorklet in docs/demos/vgm.html when available.
The player logic still runs on the main thread, but audio output timing is handled by the worklet path.
Current Model
- The main thread owns
VgmPlayer. - The main thread renders float chunks with
player.process(...). - Those chunks are posted to an
AudioWorkletNode. - The worklet queues chunks and writes them to the audio output.
Why This Exists
- Audio output timing is steadier than a pure ScriptProcessorNode path.
- It reduces the browser-demo gap between "it works" and "it is usable".
- It is a better stepping stone toward game-oriented browser playback.
Important Limitation
This is not yet a full "all audio logic is inside the worklet" design. The current implementation still computes VGM playback chunks on the main thread and streams them into the worklet queue.
Minimal Idea
await audioContext.audioWorklet.addModule("../js/vgm-output-worklet.js");
const node = new AudioWorkletNode(audioContext, "vgm-output-processor", {
numberOfInputs: 0,
numberOfOutputs: 1,
outputChannelCount: [2],
});
node.port.postMessage({
type: "enqueue",
left: left.buffer,
right: right.buffer,
}, [left.buffer, right.buffer]);