WebWorkletAudio

The page's half of the sound of a player that runs in a Web Worker (#100): the AudioContext and the AudioWorklet, which only a page may own, and the port a worker writes the sound to.

An application uses KitePlayerWorker in kiteplayer, which builds this itself. The worker writes blocks to workerPort and the worklet reports back on it, so the page's thread is not in the path of the sound at all.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The channels the destination carries, which may be fewer than were asked for.

Link copied to clipboard

Seconds between handing a frame over and hearing it, or null when the browser gives no figure.

Link copied to clipboard

The rate of the page's audio device, which the worker's sink resamples to.

Link copied to clipboard

The worker's end of the channel to the worklet. Transfer it to the worker, once.

Functions

Link copied to clipboard
fun close()

Disconnects the worklet and closes the context.

Link copied to clipboard
fun resume()

Starts the device. A browser starts audio only inside a user gesture, so call this from the gesture's own handler, not after an await.

Link copied to clipboard
fun suspend()

Stops the device without closing it, as a pause does.