padenot / ringbuf.js

Wait-free thread-safe single-consumer single-producer ring buffer using SharedArrayBuffer
https://ringbuf-js.netlify.app/
Mozilla Public License 2.0
201 stars 18 forks source link

Fix `this._param_reader is undefined` in Firefox #11

Closed LucasThompson closed 3 years ago

LucasThompson commented 3 years ago

In Firefox it seems audio starts processing without an explicit user action, which breaks some assumptions elsewhere in the app:

  1. the SharedArrayBuffers used for the parameter and audio queues are currently passed to the Processor asynchronously over the message port, which means it isn't valid on construction. So, there is a race - if audio starts before these messages are received, the ring buffers are not initialised when process is called
  2. the "start" button expects to toggle the running state on and off, so if the AudioContext is already running, clicking "Start" doesn't update the text of the button to "Stop"

This PR suspends the AudioContext immediately after construction, which is all that is really needed to fix this, but also uses the AudioWorkletNodeOptions to pass the SharedArrayBuffers to the Processor on construction.

padenot commented 3 years ago

In Firefox it seems audio starts processing without an explicit user action, which breaks some assumptions elsewhere in the app:

Interesting, I only tested in Firefox Nightly, that blocks auto-play for Web Audio by default, classic Mozilla developer problem :-).

Thanks a lot for the patch!