chrisguttandin / standardized-audio-context

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

Add iOS Safari workaround hint to readme #969

Closed homerjam closed 3 years ago

homerjam commented 3 years ago

Hello!

I came across this bug via Tone.js. Obviously it's a Safari issue (surprise, surprise) but this seems like a good place to provide some help as I'd imagine this project is widely depended on.

Thanks!

chrisguttandin commented 3 years ago

Hi @homerjam, thanks for your contribution.

Do you know which nodes trigger that error? Could that be related to Tonejs/Tone.js#813?

homerjam commented 3 years ago

This was the error - on closer inspection createStereoPanner was called via new PitchShift(). It could be related to Tonejs I suppose but similar issues I found when googling suggested it would be more likely "fixed" here..

Screenshot 2021-01-07 at 21 58 33

chrisguttandin commented 3 years ago

I'm not sure if I can follow along. When setting the destination to a fixed channelCount of 1, wouldn't that make a StereoPanner unusable as well? It might not throw an error anymore but it will output mono, right?

homerjam commented 3 years ago

Yes, that's right. As far as I can tell that's simply a limitation of iOS's implementation of AudioContext. Maybe it'd be worth pointing that out too though.

homerjam commented 3 years ago

Ah maybe this explains it better https://stackoverflow.com/questions/52809552/how-to-pan-audio-in-ios-web-audio-implementation

Where do you think this polyfill would be best placed?

chrisguttandin commented 3 years ago

There is already a polyfill in this library for the missing StereoPannerNode.

Do the latest changes released as v25.1.8 make any difference for you? Is there a chance that you enabled what Safari calls the "Modern WebAudio API"?

homerjam commented 3 years ago

Thanks for helping out here.

Unfortunately I seem to have a new issue with v25.1.8. This effects Chrome and iOS (the error is the same in both) which may indicate that the the original issue has gone away.

Screenshot 2021-01-09 at 18 41 08 Screenshot 2021-01-09 at 18 16 16

chrisguttandin commented 3 years ago

This error is caused by a check within Tone.js. I think it's most likely a side effect of having two different versions of standardized-audio-context running on the same page. Is that possible?

homerjam commented 3 years ago

Ah yes, that was the case - I was importing standardized-audio-context explicitly as well as Tone.js. However in the codepen below this seems to be a requirement to make iOS work (with the explicit channelCount workaround).

Since removing that I still face the original issue but now there's another problem even when trying to suppress the issue with the workaround.

I've created a codepen which shows the problem. Check the console to see the new error in Safari.

Also note the original createStereoPanner problem if you comment out lines 17 + 18.

Screenshot 2021-01-11 at 18 57 58

chrisguttandin commented 3 years ago

It seems to work with Tone v14.7.76 which is the latest dev version. I created a little example based on yours: https://stackblitz.com/edit/typescript-jtgkme

homerjam commented 3 years ago

That's done it! I'm not sure whether it's the new version or if it's seeing how I should have been using Tone in my example - but either way thanks so much for your help on this!