Version
menu_open
Wwise SDK 2021.1.14
Custom Scheduling of Audio Rendering

Audio Rendering Thread

By default, the Wwise Sound Engine does all its command processing and audio rendering in a dedicated thread named AK::EventManager, controlled by the AkPlatformInitSettings::threadLEngine parameters. Calling AK::SoundEngine::RenderAudio signals the end of a game frame and allows the thread to consume all API commands received since the previous call to RenderAudio.

Setting AkInitSettings::bUseLEngineThread to false disables this thread and causes RenderAudio to run synchronously: processing commands and, if needed, rendering audio. The actual rate of audio output remains controlled by the audio endpoint. If the RenderAudio call interval is shorter than the buffer period determined by AkInitSettings::uNumSamplesPerFrame and the output sample rate, some calls to RenderAudio will skip the audio rendering portion. Conversely, if the RenderAudio call interval is longer than the output buffer period, RenderAudio may process more than one buffer at a time, causing a CPU usage spike, and may eventually cause the audio to stutter.

Enabling offline rendering disables asynchronous command processing and audio rendering from the audio thread. The amount of audio rendered per call to RenderAudio is determined by a positive non-zero value sent to AK::SoundEngine::SetOfflineRenderingFrameTime. A zero or negative value will force RenderAudio to process precisely one audio buffer.

Caution: With the audio rendering thread disabled or with offline rendering enabled, synchronous AK::SoundEngine::LoadBank and AK::SoundEngine::UnloadBank API calls must not be made from the same thread as the caller of RenderAudio. This is because these calls may block until an audio buffer is rendered to complete Stop operations and free SoundBank media, which won't happen without a concurrent call to RenderAudio.

On Microsoft platforms, due to the use of a single-threaded apartment (STA) concurrency model, CoInitializeEx() must be called from the same thread that calls AK::SoundEngine::RenderAudio when setting AkInitSettings::bUseLEngineThread to false.

Using Query API Functions

Certain AK::SoundEngine::Query functions can cause CPU spikes. To minimize wasted CPU time and ensure optimal performance, we recommend that you follow these guidelines:

  • Use the Query functions in development builds and avoid using them in production builds.
  • If it is necessary to use Query functions, use them inside SoundEngine global callbacks (see AkGlobalCallbackLocation). For example, if you have to read RTPC values, put the code in AkGlobalCallbackLocation_BeginRender or AkGlobalCallbackLocation_EndRender.

Parallel Execution of Audio Rendering Tasks

By default, the Wwise Sound Engine executes Bus and Voice processing on the audio rendering thread.

Parallel execution of individual Bus and Voice tasks can be enabled via AkInitSettings::taskSchedulerDesc. Wwise will call the AkTaskSchedulerDesc::fcnParallelFor callback for any group of tasks that can be safely executed concurrently. This request can be passed along to a game-side task scheduler, which can divide the range for execution across worker threads.

Note: When enabling parallel execution, some AK::SoundEngine callbacks will be generated from concurrent task scheduler threads.
Note: Some plug-ins may not be compatible with parallel execution.

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise