Here's how we can estimate the latency between the time an event is posted and the time audio data starts being played back by the console.
From the game thread, you call the SDK function PostEvent(). Posting an event will post a request to play something. This request will not be processed until the game call the function RenderAudio().
The function "RenderAudio()" does not actually render the audio, it simply sets a notification to process the request that were posted since the last call to RenderAudio().
Normally, RenderAudio() is called by the game once per game frame, but this is not a restriction, it can be called anytime to force execution of recently posted events asap.
Once RenderAudio() is called, the audio (EventManager) thread will be granted the permission to consume the events/commands that were posted previously. However, note that this thread is synchronized with the consumption rate of the platform's audio. An "audio refill" pass is only executed when the audio output module has consumed a buffer and therefore made a section of its ring buffer available for writing.
Finally, there is the output module's ring buffer size consider. When initializing the sound engine under Windows, in the platform specific parameters, you may specify the ring buffer's size using this parameter:
AkPlatformInitSettings::uNumRefillsInVoice
Number of "refill buffers" in voice buffer. 2 is double-buffered, default is 4.
Picking this number is a balance between reducing the latency and making the system more resistant to starvation.
A "refill buffer" is called an audio frame, and it typically is 21.3 ms under windows in high quality mode. It is the double in low quality. You will find links to each platform's audio frame size below.
So the "total sound engine's latency" is something like:
1-
The time between the call to PostEvent and the call to RenderAudio (this is up to the game), that is, 16 ms in a 60 frame per second game which calls RenderAudio() once per frame.
2-
The time between the call to RenderAudio() and an audio frame boundary:
0 to 21 ms depending on whether RenderAudio() was called at the end or at the beginning of the current audio frame.
3-
The output stage buffering. With a double-buffered output stage:
2 * 21 ms = 42 ms latency
Total, in a 60 frames per second update system:
53 ms latency /- 10.7 ms because of the audio frame granularity.
...Of course, if the sound is 100% streamed, you need to add the inherent I/O latency...
Refer to these articles for details on audio frame size for each platforms:
- Windows and Mac
- PS3
- Xbox 360
- Wii