chrisguttandin / standardized-audio-context

A cross-browser wrapper for the Web Audio API which aims to closely follow the standard.
MIT License
680 stars 33 forks source link

[Bug] `standardized-audio-context` is off beat and glitching #993

Closed ghost closed 2 years ago

ghost commented 2 years ago

I am having a potential issue with this library, which links to Tone.js, particularly with Tonejs/Tone.js#1096. In that issue, I pinpointed the bug to either be in Tone.js or this library; that is why I'm here to see if this package is what is making Tone.js sound glitchy and off beat.

chrisguttandin commented 2 years ago

Hi @IRod22, I tried to reproduce the issues with your example on StackBlitz but it worked as expected for me.

Can you please double check if it is a problem with standardized-audio-context or with Tone.js by setting the AudioContext used by Tone.js to the native AudioContext?

https://tonejs.github.io/docs/14.7.33/fn/setContext

I think the following should work:

Tone.setContext(window.AudioContext);
ghost commented 2 years ago

I just tried that on my Windows machine, and the browser gave me the following error:

TypeError: Ii.resume is not a function

I'll have to get you the call stack later (currently offline), but I can tell you that it happend in the following snippet (pretty-printed as I was using the min.js version):

function Pi() {
    return Ii.resume()
}

I will report this to Tone.js as well.

chrisguttandin commented 2 years ago

The snippet that I posted above is wrong. Sorry for that. It should be an instance of an AudioContext and not the constructor.

Tone.setContext(new window.AudioContext());
ghost commented 2 years ago

Got a new error: 20220721_165127 that is much deeper in the call stack. I'll get a "dev" version of Tone.js once I get back online to comb through the call stack.

chrisguttandin commented 2 years ago

I updated your example on StackBlitz. It works without throwing any errors for me in Chrome.

https://stackblitz.com/edit/tonejs-issue-playing-and-timing-cqqyoj

It fails in Firefox and for sure in Safari. That's why Tone.js uses this library. :-) But I thought the bug that you are reporting only happens in Chrome.

ghost commented 2 years ago

It happens in Firefox (desktop and Android), Chrome for Android, and Samsung Internet. This is why I created this issue here to see if this library is the root of the bug. See the original issue thread for details.

chrisguttandin commented 2 years ago

Yes, I looked at the other issue that's how I got to know that it's a Chrome only issue. The original bug says it happens in Firefox but later one you wrote:

This testing allows me to conclude that this is either with the Tone.js API, or with the Web Audio API on Chromium-based browsers.

Sadly I have no way to reproduce the issue. It works as expected for me in Firefox, too.

ghost commented 2 years ago

Wow. We may need to have the community chime in to reproduce the bug on their machines. What's strange to me is that I tested this out on two different devices, one relatively old and one relatively new, and the issue still cropped up on different browsers.

chrisguttandin commented 2 years ago

I'm going to close the issue over here. The problem isn't solved yet but I think it's confusing to have the same conversation twice.

tonejs/Tone.js#1096