Allow Tone.js to use its own prepared audio context (fix firefox cancelAndHold bug)#91
Draft
nbogie wants to merge 1 commit into
Draft
Allow Tone.js to use its own prepared audio context (fix firefox cancelAndHold bug)#91nbogie wants to merge 1 commit into
nbogie wants to merge 1 commit into
Conversation
Tone.js sets up its audio context with standardized-audio-context wrapper which polyfills for various missing functions missing from firefox and safari which Tone.js expects to be able to call unconditionally. Let Tone.js own the audio context throughout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a suggested, illustrative fix for the
cancelAndHoldAtTime is not a functionbug that we saw causing various of the examples to fail on firefox.Minimal repeatable example of the bug is here - (fails in firefox, doesn't complain in chrome), and another slightly longer, more typical example, here.
A full root-cause-analysis is here.
It is only a draft pull request because I haven't done exhaustive testing of it on all browsers or of anything more than the 22 examples in
examples/. The p5-to-tone example may show a regression (see section on testing).What it changes:
Rather than pass tone.js a new raw native audio context, let Tone.js use its own prepared audio context, and own the audio context throughout.
Why:
Tone.js creates an AudioContext when it loads and shims it for maximum browser compatibility using standardized-audio-context. This adds various missing functions missing from firefox and safari which Tone.js expects to be able to call unconditionally, one of which is cancelAndHoldAtTime.
p5.sound currently forces it to use a raw new native audio context instead of this prepared one, and in turn this causes various of our examples to fail in firefox (and likely safari, too) under certain conditions.
Testing:
Tested with the browser based tests #85 plus #90 (which fixes a couple of errors in the examples).
All local examples then pass on firefox, and continue to pass on chrome, with one exception
examples/p5-to-tone/. This looks like a newly introduced regression.AI disclosure:
Claude Code was used in the investigation and preparation of this solution.
Code review, testing, and this write-up by me, a human.