Skip to content

Add AudioNode hooks to support additional AudioContext cases#67

Open
mikejhill wants to merge 5 commits intorain-fighters:mainfrom
mikejhill:bugfix/add-audiocontext-createbuffersource-support
Open

Add AudioNode hooks to support additional AudioContext cases#67
mikejhill wants to merge 5 commits intorain-fighters:mainfrom
mikejhill:bugfix/add-audiocontext-createbuffersource-support

Conversation

@mikejhill
Copy link

@mikejhill mikejhill commented May 4, 2025

This PR replaces the AudioContext factory-based hooks with AudioNode#connect hooks. This supports additional cases, including constructor-based AudioNode creation (rather than factory-based) and after-page-load extension functionality through AudioContext#resume.

Factory methods are not deprecated, but their constructor alternatives are recommended. Per commentary in MDN (https://developer.mozilla.org/en-US/docs/Web/API/AudioNode#creating_an_audionode):

You are free to use either constructors or factory methods, or mix both, however there are advantages to using the constructors:

  • All parameters can be set during construction time and don't need to be set individually.
  • You can sub-class an audio node. While the actual processing is done internally by the browser and cannot be altered, you could write a wrapper around an audio node to provide custom properties and methods.
  • Slightly better performance: In both Chrome and Firefox, the factory methods call the constructors internally.

Brief history: The first version of the Web Audio spec only defined the factory methods. After a design review in October 2013, it was decided to add constructors because they have numerous benefits over factory methods. The constructors were added to the spec from August to October 2016. Factory methods continue to be included in the spec and are not deprecated.

The original PR intent was to support BaseAudioContext.createBufferSource (MDN), such as on myNoise.net. However, diving in after seeing MDN's constructor recommendation, it seems that AudioNode#connect to connect to an AudioContext#destination is a hard requirement of the Web Audio API (reference: https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API), and thus this change should hopefully cover all remaining AudioContext cases not supported by the current implementation.

Tested sites so far appear to all be working as expected:

  • app.pluralsight.com
  • deezer.com
  • music.youtube.com
  • mynoise.net (fixed by this PR)
  • pandora.com
  • soundcloud.com
  • spotify.com
  • www.youtube.com

I'm not aware of other AudioContext cases in the wild, but would love to validate on more if we have other samples.

@necropola
Copy link
Member

I just wanted to let you know that I have seen your PR. I just hadn't the time yet to test your patch and -- assuming it works -- merge it into main and make a new release.

Thanks!

@necropola necropola self-assigned this May 10, 2025
@mikejhill
Copy link
Author

I just wanted to let you know that I have seen your PR. I just hadn't the time yet to test your patch and -- assuming it works -- merge it into main and make a new release.

Thanks!

No worries! Let me know if there is anything I can do to support.

@necropola necropola mentioned this pull request Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants