Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.39k stars 976 forks source link

Audio crackling using bluetooth devices when switching out of the browser app on Android devices. #1104

Closed andrewsrichardson closed 2 years ago

andrewsrichardson commented 2 years ago

Hey 👋

Describe the bug

When playing audio on Android Chrome and listening via a connected bluetooth device, switching apps or locking the phone will cause crackling in the audio. The crackling is constant, rather than pops or clicks. After around 30s, the audio will stop, presumably from some sort of crash, but there is no audible change to prove this.

This happens with even the simplest synth implementation.

Oddly, with no bluetooth device connected, this does not seem to happen.

To Reproduce

A reproducable sandbox is here. Connect to a bluetooth device. Press play on the sound, the switch apps from Chrome to anything other app, or lock the phone.

Phones tested are Pixel 2XL and Samsung Note 10. It doesnt seem specific to any bluetooth device.

Expected behavior Switching apps does not degrade the performance while using bluetooth devices.

What I've tried Doesn't seem to be a regular performance issue as this never happes while staying in the chrome app. Similarly, without a connected bluetooth device, I seem to be able to run this without issue.

I have tried using a Tone Context with a latencyHint of 'playback', to no avail.

Additional context While I only named 2 devices, this seems like it could be fairly widespread, as I have had a couple of reports of the same bug.

chrisguttandin commented 2 years ago

Hi @andrewsrichardson, I vaguely remember that there were a couple of issues with certain Chrome / Bluetooth speakers combinations in the past. Could you try to play some audio with the Web Audio API to see if the problem persists? I guess a single Oscillator should be enough to trigger the bug.

Does your example work as expected in Firefox?

andrewsrichardson commented 2 years ago

hey Chris

I tried the Web Audio API with Chrome (updated the sandbox) and the issue does indeed persist.

Oddly, I checked Firefox, and the issue does not persist using either Tone.js or the Web Audio API.

So I decided to also test Opera and Brave browser, both of which also produce the crackling issue for both Tone.js and the Web Audio API.

chrisguttandin commented 2 years ago

Thanks for checking this. I think it makes sense that Chrome, Opera and Brave have the same bug since they are all based on Chromium these days. Firefox has its own browser engine.

Maybe it's better to report this on Chromium's bug tracker. https://new.crbug.com/

andrewsrichardson commented 2 years ago

Thanks for the direction Chris - I have opened a bug in the Chromium bug tracker here.

Happy to close this ticket!