-
Notifications
You must be signed in to change notification settings - Fork 172
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
investigate AudioWorklet #111
Comments
I would love to support audio worklet. I didn't know any browser had a working implementation yet. :) |
@mreinstein I just took a look at the AudioWorklet feature and it seems it's main use case is for developers to create their own audio node for inclusion in an audio graph which is latency sensitive. Since this doesn't output PCM audio to a buffer, and we don't have any latency requirements, I don't think it actually fits this use case. Thoughts? |
I'm under the impression that |
Thanks @mreinstein for bringing up this opportunity & @chris-rudmin for looking into it back in December. Our startup, SquadCast.fm, is dependent on the recorder & encoder. ~10% of the files recorded on our platform are negatively affected by the known issues with If you see this opportunity as being in scope, I'm happy to contribute. |
All of the nodes in a webaudio graph essentially operate on pcm data (even the fancy new audioworklet.) opus-recorder takes pcm as input and produces opus encoded binary data as output. Maybe it's possible to use audio worklet as a node that just receives audio data and does not send it anywhere, because an audio worklet is intended to produce pcm as output, and this module doesnt do that. |
Sorry for jumping in here -
AudioWorklet can be configured as a "sink" node, which suitable for use cases like analysis and recording. It also comes with MessagePort, so you can capture/encode the audio stream and transfer it to the main scope. If the encoding is too expensive, the load can be distributed to Worker as well. |
@ZachMoreno The existing code for the encoder should port itself pretty easily to an AudioWorklet. I would probably start a new repo for such a project as a proof of concept, and when there is more mainstream support for AudioWorklets, we could release a new version of opus-recorder. |
Please, allow me to clarify. I'm not suggesting that we refactor the encoder from a It should also be possible to utelize |
My suspicion right now is that won't have a huge impact on performance. here is the script processor currently: https://github.com/chris-rudmin/opus-recorder/blob/master/src/recorder.js#L64-L76 It basically just reads data from the stream and posts it to a worker running in another thread. There doesn't seem to be much cpu load being introduced in here, it's mostly i/o but then again, I haven't tested this, just gut feeling! If you're feeling ambitious and want to move that to an audio worklet, give it a try. would be interesting to get some real numbers on the perf impact. |
ooh a UML diagram. How luxurious! :) Yes this looks like an accurate representation of the data flow and the sequence. My previous point still stands; my 5$ gut reaction is that Again, I don't want to discourage us from trying this. I just don't expect to see big performance gains. |
I generally agree with @mreinstein from a practical view point, but I have seen many problematic cases. If the main thread suffers from some intensive processing (which is quite common), @ZachMoreno I also recommend to use the internal buffering inside of Worklet instead of sending message for every 3ms. Here's a ring buffer example for AudioWorklet. (It's WIP so use at your own risk...) |
@mreinstein Thanks kindly for reopening! We agree on net equal perf. I'm seeking reliability on capture. |
Okay, so the tl;dr is not much a net perf improvement but there stands to be some gain in terms of reduced latency and it's related side effects. Cool! Sounds worthwhile then. |
I believe buffering is sort of prerequisite for the stability, the latency might not be a big win here. However, the worklet version will survive when the main thread is hammered. FireFox is also implementing it at the moment, so hopefully at least 2 browsers will support it soon. |
something that might be nice to consider; chrome and ff actually support recording opus natively. That would enable bypassing all of this userland encoding entirely (on supported platforms) This works for me: https://jsbin.com/hedujihuqo/edit?js,console |
@mreinstein I had created the |
@ZachMoreno I would love it if you would like to make a pull request to add AudioWorklet support. To support such a feature I would definitely like it to fallback to ScriptProcessorNode when worklets are not available. |
Chrome is about to land AudioWorklet and finally deprecate ScriptProcessorNode.
It would be awesome if Recorderjs could be used a normal WebAudio node!
https://www.chromestatus.com/features/4588498229133312
The text was updated successfully, but these errors were encountered: