Skip to content

Conversation

Copy link

Copilot AI commented Oct 13, 2025

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:

  1. User taps power button → initialize() called
  2. AudioContext created → _installIOSUnlock() called
  3. Event listeners attached for unlock
  4. Power button gesture completes ❌
  5. User would need a second interaction to trigger unlock

The 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:

async _installIOSUnlock(ctx) {
    // ... setup listeners for future interactions ...
    
    // NEW: Try to unlock immediately if we're in a user gesture
    await unlock();
}

This ensures that when the power button is clicked:

  1. AudioContext is created
  2. iOS unlock listeners are attached for future needs
  3. Unlock is immediately attempted during the same gesture
  4. A 1-frame silent buffer is created and played, satisfying iOS requirements
  5. AudioContext is fully unlocked and ready for audio

Changes

  • Made _installIOSUnlock() async to allow awaiting the unlock operation
  • Added immediate await unlock() call at the end of _installIOSUnlock()
  • Updated initialize() to properly await the iOS unlock setup
  • Fixed vite.config.js by removing watch: {} which caused builds to hang

Testing

The fix has been built and deployed to www/clarinet-synth/ for GitHub Pages. On iOS devices:

  • Tap the power button (PWR) to initialize audio
  • The AudioContext will unlock during this first tap
  • Subsequent keyboard presses will produce audio normally

Screenshots

Clarinet Synthesizer Interface:

Clarinet Synth UI

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 files

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>No audio in ios</issue_title>
<issue_description>Tested in ios safari and (webkit)chrome, looks ok but silent</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@danbri
Copy link
Collaborator

danbri commented Oct 13, 2025

Consider what a failing test might look like for complex browser feature like this, @copilot

Co-authored-by: danbri <170265+danbri@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix no audio issue in iOS browsers Fix iOS Safari audio silence by unlocking Web Audio during power button gesture Oct 13, 2025
Copilot AI requested a review from danbri October 13, 2025 18:54
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.

No audio in ios

2 participants