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

Connect output-less script processor to destination to allow processing #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hgcummings
Copy link

@hgcummings hgcummings commented May 16, 2020

As described in the code comment:

  • On browsers that do support AudioWorklet, process() will be invoked for disconnected AudioWorkletNodes as long as they are created with numberOfOutputs: 0 in the options
  • In Safari, onaudioprocess is only invoked on a ScriptProcessorNode if it is connected to an output

The use case for input-only processors is performing audio analysis (rather than audio manipulation), e.g. for visualisation.

Tested in iOS Safari 12. Note that for the polyfill to work for me at all on this platform, I also needed PR #25 .

Some things that didn't work:

  • Explicitly creating the ScriptProcessorNode with 0 outputChannels (as the third constructor argument): process still wasn't invoked unless the ScriptProcessorNode was connected to the output
  • Connect the ScriptProcessorNode to the destination via a GainNode with gain 0 (seemed like a slightly safer option than connecting directly to the destination): did cause process() to be invoked, but the input was always silent (possibly an optimisation because the AudioContext can see the output is muted?)

Connecting without going through a zero-gain node would only cause surprising behaviour if someone created a polyfill AudioWorkletNode with numberOfOutputs: 0 and then tried to output something from the node, which would suggest a programming error in any case.

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

Successfully merging this pull request may close these issues.

1 participant