Class: AudioWriter

AudioWriter

Send interleaved audio frames to another thread, wait-free. These classes allow communicating between a non-real time thread (browser main thread or worker) and a real-time thread (in an AudioWorkletProcessor). Write and Reader cannot change role after setup, unless externally synchronized. GC _can_ happen during the initial construction of this object when hopefully no audio is being output. This depends on how implementations schedule GC passes. After the setup phase no GC is triggered on either side of the queue.

new AudioWriter()

From a RingBuffer, build an object that can enqueue enqueue audio in a ring buffer.

Classes

AudioWriter

Methods

available_write()

Returns:
The free space in the ring buffer. This is the amount of samples that can be queued, with a guarantee of success.

enqueue(buf)

Enqueue a buffer of interleaved audio into the ring buffer. Care should be taken to enqueue a number of samples that is a multiple of the channel count of the audio stream.
Name Type Description
buf Float32Array An array of interleaved audio frames.
Returns:
The number of samples that have been successfuly written to the queue. `buf` is not written to during this call, so the samples that haven't been written to the queue are still available.