chrisguttandin / standardized-audio-context

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

AudioBufferSourceNode.detune #965

Closed furudean closed 3 years ago

furudean commented 3 years ago

From the README,

:warning: The detune AudioParam is not implemented so far.

What is the rationale behind at least not implementing it for supported browsers and throwing if its not? It's a no-go for me to use standardized-audio-context due to the lack of this feature, since even on supported browsers I can't use detune.

Is there a way around this?

chrisguttandin commented 3 years ago

The goal of this library is to provide a unified API surface in all browsers. It should not be necessary to do any feature detection in your own code. That's why in general a feature is only available in standardized-audio-context if it can be used in every browser.

No rule without exceptions. There are some things which throw a NotSupportedError when used in a browser which doesn't have this feature.

But in this case I would rather not like to introduce an exception since as far as I know everything that can be done with the detune AudioParam can also be done with the playbackRate AudioParam. Please let me know if you have a use case which can't be implemented with the playbackRate AudioParam.

furudean commented 3 years ago

After looking into it more, I figured out that this was indeed possible to solve using playbackRate.

function detuneWithPlaybackRate(cents) {
  const semitones = cents / 100;
  return 2 ** (semitones / 12)
}
source.playbackRate.value = detuneWithPlaybackRate(600);

Thanks!