Version
menu_open
Wwise SDK 2023.1.5
Offline Rendering with Wwise

Offline Rendering

The Wwise Sound Engine offers offline rendering that allows for non-real-time, compute-intensive audio generation and the synchronization of audio processing with compute-intensive video generation.

Caution: Care must be taken when enabling offline rendering in applications that use the synchronous AK::SoundEngine::LoadBank and AK::SoundEngine::UnloadBank APIs. See Audio Rendering Thread for details.

An audio capture callback can be registered using AK::SoundEngine::RegisterCaptureCallback, which provides a mechanism for accessing the rendered audio buffers.

The following is an example that illustrates one possible implementation of offline rendering:

/// Video capture services accessible in the game code
namespace VideoCaptureServices
{
/// Possibly allocates buffers for video capture
void Initialize();
/// Possibly outputs captured video and audio as a movie file
void Finalize();
/// Possibly captures a single video frame buffer to a file.
void CaptureSingleFrame();
}
/// Audio capture services accessible in the game code
namespace AudioCaptureServices
{
/// Allocates buffers or opens files for the eventual capture of audio samples.
void Initialize(unsigned in_uSampleRate, unsigned in_uChannels);
/// Releases buffers or file handles once audio sample capture is completed.
void Finalize();
/// Adds audio samples to the allocated buffers
void CaptureInterleavedSamples(float* in_pfSamples, unsigned in_uSampleCount);
}
class GameInterface
{
// ...
public:
/// Function called once per game frame
virtual void UpdateCallback(float deltaTime //< elapsed wall clock time in real-time, inverse of the desired frame rate in offline mode
) = 0;
};
class Game : public GameInterface
{
// ...
private:
/// True when offline rendering is enabled.
bool m_bIsOfflineRendering{ false };
/// Output device ID for registration/unregistration of capture callback.
AkOutputDeviceID m_defaultOutputDeviceId{ AK_INVALID_OUTPUT_DEVICE_ID };
/// Wwise audio capture callback.
static void CaptureCallback(AkAudioBuffer& in_CaptureBuffer, AkOutputDeviceID /*in_idOutput*/, void* /*in_pCookie*/)
{
const unsigned uSampleCount = static_cast<unsigned>(in_CaptureBuffer.uValidFrames) * in_CaptureBuffer.NumChannels();
if (!uSampleCount)
return;
AudioCaptureServices::CaptureInterleavedSamples(in_CaptureBuffer.GetInterleavedData(), uSampleCount);
}
public:
/// Function called to enable/disable offline rendering
void SetOfflineRendering(bool bIsOfflineRendering //< true for offline rendering, and false for real-time rendering
)
{
const bool bWasOfflineRendering{ m_bIsOfflineRendering };
m_bIsOfflineRendering = bIsOfflineRendering;
// Posts a message on the message queue to enable/disable offline rendering
AK::SoundEngine::SetOfflineRendering(m_bIsOfflineRendering);
if (m_bIsOfflineRendering == bWasOfflineRendering)
return;
// Posts a message on the message queue to set the offline rendering frame time to zero ensuring that the subsequent call to RenderAudio() will not generate more audio samples.
// Call RenderAudio() to flush the message queue. After this call, offline rendering will be enabled/disabled.
if (m_bIsOfflineRendering)
{
VideoCaptureServices::Initialize();
// When engaging offline rendering, the output configuration will switch to Stereo output by default
// In order to render to a different output speaker layout, replace the output with an explicitly defined one.
// In this example, switch to 7.1.4
AkChannelConfig surroundConfig;
// Post a mesage to replace the output device.
AkOutputSettings newSettings;
newSettings.audioDeviceShareset = AK::AUDIO_DEVICES::SYSTEM;
newSettings.idDevice = 0;
newSettings.channelConfig = surroundConfig;
AK::SoundEngine::ReplaceOutput(newSettings, 0, &m_defaultOutputDeviceId);
// Flush the message queue again to make sure ReplaceOutput is processed, before registering the capture callback on the offline device
const AkUInt32 uSampleRate{ AK::SoundEngine::GetSampleRate() };
// Provide the sample rate and number of channels to allocate the appropriate buffers.
AudioCaptureServices::Initialize(uSampleRate, surroundConfig.uNumChannels);
AK::SoundEngine::RegisterCaptureCallback(&CaptureCallback, m_defaultOutputDeviceId, this);
}
else
{
AK::SoundEngine::UnregisterCaptureCallback(&CaptureCallback, m_defaultOutputDeviceId, this);
AudioCaptureServices::Finalize();
VideoCaptureServices::Finalize();
}
}
void UpdateCallback(float deltaTime) override
{
if (m_bIsOfflineRendering)
if (m_bIsOfflineRendering)
VideoCaptureServices::CaptureSingleFrame();
}
};
AKSOUNDENGINE_API AkUInt32 GetSampleRate()
AkPanningRule ePanningRule
AkUInt32 uNumChannels
Number of channels.
AkForceInline AkUInt32 NumChannels() const
Get the number of channels.
Definition: AkCommonDefs.h:492
Platform-independent initialization settings of output devices.
AKSOUNDENGINE_API AKRESULT SetOfflineRenderingFrameTime(AkReal32 in_fFrameTimeInSeconds)
AKSOUNDENGINE_API AKRESULT ReplaceOutput(const AkOutputSettings &in_Settings, AkOutputDeviceID in_outputDeviceId, AkOutputDeviceID *out_pOutputDeviceId=NULL)
AkUInt16 uValidFrames
Number of valid sample frames in the audio buffer.
Definition: AkCommonDefs.h:657
#define AK_SPEAKER_SETUP_DOLBY_7_1_4
Dolby 7.1.4 setup channel mask.
AKSOUNDENGINE_API AKRESULT RegisterCaptureCallback(AkCaptureCallbackFunc in_pfnCallback, AkOutputDeviceID in_idOutput=AK_INVALID_OUTPUT_DEVICE_ID, void *in_pCookie=NULL)
AKSOUNDENGINE_API AKRESULT RenderAudio(bool in_bAllowSyncRender=true)
AKSOUNDENGINE_API AKRESULT UnregisterCaptureCallback(AkCaptureCallbackFunc in_pfnCallback, AkOutputDeviceID in_idOutput=AK_INVALID_OUTPUT_DEVICE_ID, void *in_pCookie=NULL)
static const AkUInt32 AK_INVALID_OUTPUT_DEVICE_ID
Invalid Device ID.
Definition: AkTypes.h:107
@ AkPanningRule_Speakers
Left and right positioned 60 degrees apart (by default - see AK::SoundEngine::GetSpeakerAngles()).
Definition: AkTypes.h:1128
AKSOUNDENGINE_API AKRESULT SetOfflineRendering(bool in_bEnableOfflineRendering)
AkForceInline void SetStandard(AkUInt32 in_uChannelMask)
Set channel config as a standard configuration specified with given channel mask.
AkUniqueID audioDeviceShareset
uint32_t AkUInt32
Unsigned 32-bit integer.
AkChannelConfig channelConfig
AkUInt64 AkOutputDeviceID
Audio Output device ID.
Definition: AkTypes.h:85
AkForceInline void * GetInterleavedData()
Definition: AkCommonDefs.h:514

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