ARTICLE AD BOX
I'm working on a Javascript browser application that requires very precise timing of audio playback via the AudioBufferSourceNode.start() method. I'm unsure on how I should treat 'baseLatency' and 'outputLatency' to achieve my goal. I'll first describe my goal and then attempt to answer my question with my current understanding of these two latencies. However, I'm looking for validation / correction to my interpretation.
I'm generating an audio "beep" signal using an AudioBufferSourceNode in Javascript. I want this signal to be "heard" by a human listener at precisely N seconds in units of AudioContext.currentTime. Note that I'm not saying "played" but rather "heard". Thus I want to account for latencies such that the outputted audio lines up at exactly N seconds per human interpretation.
My current interpretations of 'baseLatency' and 'outputLatency' are as follows:
'baseLatency' is the amount of time required to pass an audio signal from Javascript to the OS audio buffer. So essentially if I were to issue an audio command in Javascript at time "now", it would be received by my OS sound buffer at "now + baseLatency". BUT - if I were to call AudioBufferSrcNode.start(future time), the fact that I'm scheduling audio to play at sufficient future time, this baseLatency is essentially neglected. 'outputLatency' is the amount of time for the OS sound buffer to be heard by the listener. That is, assuming the OS already has my signal and decided to play it - it will take 'outputLatency' until the sound comes through the speakers.So here's my current strategy to achieve my goal using my interpretations: My JavaScript function should 'schedule' my audio to play at some point in the future to offset 'baseLatency' using the .start(when) method. Essentially if I were to schedule well in advance, the audio would get to the OS regardless of baseLatency. However, I would still need to adjust my 'when' time to account for outputLatency. Thus I should schedule my audio: .start(N - outputLatency).
In summary, I'm treating my baseLatency as a measurement of how early I need to issue my .start() method relative to N, and then I need to use outputLatency to adjust the value at which it is played (i.e. N - outputLatency)
5,00816 gold badges55 silver badges104 bronze badges
Explore related questions
See similar questions with these tags.
