jipodine / web-audio-clock

https://jipodine.github.io/web-audio-clock
9 stars 3 forks source link

Output latency question #1

Open dustinkerstein opened 4 years ago

dustinkerstein commented 4 years ago

Could your code be utilized as an approximation for outputLatency? If not, do you think it's generally possible (given that only Firefox supports that API feature)? Thanks!

jipodine commented 4 years ago

With several measures, you can make guesses about the size of the audio processing block, but it is neither accurate, nor sufficient. Try plugging a bluetooth speaker, and nothing will change except the outputLatency. (You should also check the baseLatency property and the getOutputTimestamp function.)

The only accurate way is that the browser reports the value: if more people need it and ask for it, it might be there some day. We are waiting for it for years.

dustinkerstein commented 4 years ago

K, thanks for the explanation. Do you know if there are tickets filed for each browser platform to implement outputLatency?

Do you happen to have any recommendations on how to go about designing a rough estimate using the currently implemented API (excluding outputLatency)?

jipodine commented 4 years ago

Using only the API, I did not find a better way.

If you are using a synchronised time to trigger a sound, with an external microphone (knowing its latency) it would be possible.

You could also use the microphone of the device the browser is running on, and suppose a similar delay for the speaker. It might be wrong, even if you try to deactivate any processing. An other pain is that getUserMedia is not part of WebAudio, but WebRTC.

dustinkerstein commented 4 years ago

K, thanks for the suggestions.

FYI, it looks like there is a ticket for Chromium - https://bugs.chromium.org/p/chromium/issues/detail?id=785409 0 but I wasn't able to find anything for WebKit. Think it's worth adding one or is there a better way to express interest?

For the on-device microphone design, were you thinking of measuring from when the getUserMedia returns to when data starts arriving, or actually playing an audio pattern from the device speakers and measuring input from the device mic?

jipodine commented 4 years ago

For the on-device microphone design, were you thinking of measuring from when the getUserMedia returns to when data starts arriving, or actually playing an audio pattern from the device speakers and measuring input from the device mic?

I was thinking of recording a pattern (or a burst) played by device speaker, thus assuming symmetrical delay.

dustinkerstein commented 4 years ago

Got it. Makes sense. My use-case is going to be in a noisy outdoor environment... I wonder how well that would work. Only one way to find out though :) Thanks!