Skip to content
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

Can players share a ScriptProcessorNode? #93

Closed
mmontag opened this issue Sep 17, 2021 · 2 comments
Closed

Can players share a ScriptProcessorNode? #93

mmontag opened this issue Sep 17, 2021 · 2 comments

Comments

@mmontag
Copy link
Owner

mmontag commented Sep 17, 2021

This might be irrelevant once the player is converted to AudioWorkers, but:

  • Each Player implementation currently has its own ScriptProcessorNode (i.e., see call to createScriptProcessor() in Player base constructor).
  • In the beginning, these nodes would be added and removed from the audio graph based on playback.
  • That caused audible lags/audio glitches, so the solution was to leave the nodes attached to the graph once created.
  • This has a slight performance overhead (made more obvious with ?debug=true param) - eventually 6 audioProcess callbacks are being called at once (one for each Player implementation).
  • The players are all "paused" but they still have to fill the buffer with zeros on every audioProcess callback.
  • This seems dumb; why not create one master ScriptProcessorNode and have the audioProcess method delegate to the implementations ("do you want to write any audio")? At least this way, there is only ever one buffer being filled with zeros, and for stopped players, the audioProcess is a no-op.
@mmontag
Copy link
Owner Author

mmontag commented Sep 20, 2021

Turns out this will be a necessary step for converting to AudioWorklets.

mmontag added a commit that referenced this issue May 22, 2023
Instead of leaving this up to each player and creating a stack of script processor nodes, this should save idle CPU cycles when all players have been loaded. Previously, they would each have their own processor node continuously filling a buffer with silence.

Required slight adjustment to audio graph. Previously, gainNode was same as playerNode. Each player would connect its output to the provided playerNode. Now, players don't know about audio graph at all, but just fill the channel buffers passed to the processAudio() method.
@mmontag
Copy link
Owner Author

mmontag commented May 22, 2023

💥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant