FF32Bit

Stream a WAV from the network into an AudioWorklet without handing the bytes to the main thread.

Tap to play

Source on GitHub

Zero-copy

“Zero-copy” here means the file bytes change owner instead of being cloned through the main thread. postMessage normally structured-clones data. A transfer list moves the object: the sender loses it, the receiver gets it.

The worker fetches Range slices of the WAV. It then does one of two transfers into the worklet’s MessagePort:

Decoding is not free. The worklet turns integer PCM into floats and writes those into the Float32Arrays Web Audio already allocated for process(). The network hop is the part that does not copy.

Three threads

Main thread

The tap creates the AudioContext, calls resume(), and wires a worker to an AudioWorkletNode. It never reads the file.

src/ffplayer.ts

transfer MessagePort → worker

Worker

  1. fetch with Range: bytes=start-end
  2. Own the response body
  3. Transfer the stream, or each ArrayBuffer

src/worker.ts

transfer bytes → audio thread

Audio worklet

  1. Parse the RIFF header once
  2. Decode PCM and resample if the device rate differs
  3. process() fills ~128 frames per callback

src/playback-processor.ts

in-place write → speakers