alemangui / pizzicato

Library to simplify the way you create and manipulate sounds with the Web Audio API.
https://alemangui.github.io/pizzicato/
MIT License
1.67k stars 132 forks source link

Safari has issues with frequency get/set #146

Open jlyman opened 3 years ago

jlyman commented 3 years ago

I've hit an issue where I can't change the frequency of a Sound after creating it in Safari. Works just fine in other browsers that I've tested so far (FF 79+ and Chrome 84+) but Safari v14 the following would result in null or no change in the sound:

const sound = new Pizzicato.Sound({
  source: "wave",
  options: {
    frequency: 400,
  },
});

console.log('Frequency: ', sound.frequency);
sound.frequency = 500;

I've created a fiddle to compare it amongst the different browsers: https://jsfiddle.net/7fgs8d0h/

As I've been writing this up it occurred to me that this may potentially be occurring on other properties like volume, though I haven't tested it.

Could I be missing something obvious here? Thanks in advance for any assistance!

jlyman commented 3 years ago

Additional information: from testing on a few different devices, it looks like this may be due to a more recent change to Safari. The macOS Safari v14 and the mobile Safari on iOS 14.0.1 both exhibit this issue, but on an older iPad I have with iOS 12.4.8 doesn't have any issue with this. I'm going to look into the release notes to see if I can spot anything.

jlyman commented 3 years ago

Ah okay, I believe I've found the issue. Looks like the name of the OscillatorNode in WebKit has been moved to a prefixed version, WebKitOscillatorNode. The issue for it notes the following:

Move non standard OscillatorNode API to new WebKitOscillatorNode interface, so that the unprefixed OscillatorNode is fully spec-compliant.

Now I'm not too familiar with the internals of the Web Audio API (okay, not familiar at all!) but in the Utils method that checks if something is an oscillator node, adding a check for the prefixed WebKit version seems to fix things for me. I'll put forward a PR with this change to see what others think.