Fix iOS Safari audio silence by unlocking Web Audio during power button gesture #2
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.
Problem
The clarinet synthesizer was silent on iOS Safari and Chrome (WebKit), even though the UI appeared to work correctly. This is a common issue with Web Audio API on iOS, which requires audio contexts to be "unlocked" during a user gesture.
Root Cause
While the codebase had an iOS unlock mechanism (
_installIOSUnlock()), it only attached event listeners for future interactions. The unlock happened like this:initialize()called_installIOSUnlock()calledThe first user gesture (power button click) was being wasted because the unlock listeners were attached after the click event had already propagated.
Solution
Modified the iOS unlock mechanism to trigger immediately during initialization:
experiments/clarinet-synth/src/audio/ClarinetProcessor.js:This ensures that when the power button is clicked:
Changes
_installIOSUnlock()async to allow awaiting the unlock operationawait unlock()call at the end of_installIOSUnlock()initialize()to properly await the iOS unlock setupvite.config.jsby removingwatch: {}which caused builds to hangTesting
The fix has been built and deployed to
www/clarinet-synth/for GitHub Pages. On iOS devices:Screenshots
Clarinet Synthesizer Interface:
The synthesizer provides a physical modeling clarinet with real-time parameter controls (breath, reed stiffness, damping, etc.) and a visual keyboard interface. With this fix, iOS users can now hear audio output when playing notes.
Files Changed
experiments/clarinet-synth/src/audio/ClarinetProcessor.js- iOS unlock fix (7 lines)experiments/clarinet-synth/vite.config.js- Removed hanging watch mode (3 lines)www/clarinet-synth/- Rebuilt and deployed filesFixes #[issue_number]
Original prompt
Fixes #1
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.