Initial implementation of audio input ring buffer.#268
Initial implementation of audio input ring buffer.#268namark wants to merge 13 commits intovircadia:masterfrom
Conversation
It couldn't be imported in the audio worklet, cause of two various with issues with firefox and webpack. It was also an outdated distribution, that did not correspond to the v0.3.3 code in github repo.
It's faster than the asynchronous readyRead signal.
Gigabyte5671
left a comment
There was a problem hiding this comment.
Looks great apart from a few linting errors. I'll push a fix for these in a moment.
| super(options); // eslint-disable-line | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
| this._ringBufferStorage = options?.processorOptions?.ringBufferStorage as SharedArrayBuffer; |
There was a problem hiding this comment.
This line is not necessarily type safe. Do we need to account for a situation where options, processorOptions, or ringBufferStorage are undefined?
There was a problem hiding this comment.
Not really, that would be a programmer error and should fail loudly cause there is sort of a type check in the RingBuffer constructor. Ideally we would have options parameter typed to require this, but the call site is not direct in this case, It happens in the AudioInput.ts through instantiation of AudioWorkletNode with an string id that is associated with AudioInputProcessor in AudioWorklets.ts. In theory typescript should be able to handle all of that, I think I saw a feature that allows mapping string literals to a types, but it might get tricky if the browser builtin typing we're using can't accommodate something like that.
There was a problem hiding this comment.
Ow no, the "sort of type check" is for another parameter, so I'll add explicit check there with an exception.
The ring buffer uses SharedArrayBuffer which requires cross origin isolation. For local testing the client can be hosted using statikk which has a built in convenience option:
The ringbuf.js source is included since I had trouble importing the node module in the audio worklet. The module was also outdated, missing some useful features.