-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of audio input ring buffer. #268
base: master
Are you sure you want to change the base?
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great apart from a few linting errors. I'll push a fix for these in a moment.
|
||
constructor(options?: AudioWorkletNodeOptions) { | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.