Wwise SDK 2025.1.0
|
Android音频延迟一直都是所有应用的问题之一。虽然通常延迟低于100ms,但有些设备的延迟高达150ms。
Over the years, Google introduced the several "paths" through which audio can flow from an app to the device's audio hardware:
When supported, these paths bypass various levels of internal processing to reduce the latency between the app and the hardware. 总体延迟可以减少到几十毫秒。It is important to note that it is not mandatory for the hardware manufacturers to implement these paths; many do not. Furthermore, some devices can report a fast path without it actually being implemented. Therefore, a game cannot rely on the existence of fast audio paths on the end-user's devices. 如果您的游戏是针对广泛目标市场,则在设计游戏音频时不应该使用该功能。
一般来说,更低的延迟会引发更高的CPU消耗。RTPC更新的处理、游戏对象位置、以及其他游戏输入都是每帧进行的。因此,帧越小,处理进行得就越频繁。延迟和CPU占用之间的平衡点可以通过实验找到。没有什么死规矩。
有些设置会在Wwise SDK中控制音频延迟:
AkPlatformInitSettings::uSampleRate
:使用的采样率。When set to 0 (the default), the hardware preferred rate is selected, allowing use of the fast audio path.AkPlatformInitSettings::uNumRefillsInVoice
:预处理缓冲区数目。这是针对CPU可用性问题或中断的保护。AkInitSettings::uNumSamplesPerFrame
:每缓冲区采样数。AkPlatformInitSettings::eAudioPath
: Which audio path to prefer based on device capabilities.由 AK::SoundEngine::GetDefaultSettings()
和 AK::SoundEngine::GetDefaultPlatformInitSettings()
返回的默认设置在大部分情况下对大部分设备来说是“安全的”设置。使用这些会将:
uSampleRate
设置成硬件偏好数值。这一般是48 kHz或44.1 kHz.uNumSamplesPerFrame
to 512.uNumRefillsInVoice
设置成4
。AkPlatformInitSettings::eAudioPath
to AkAudioPath_LowLatency
.Advantages: This setup will select an appropriately low-latency audio path on devices that support it. 对于音频设计的CPU占用限制也少得多。
劣势: 为了给 CPU 用量变化留出一些空间,需要预处理四帧的音频,可能会导致不需要设置余量的设备产生更高的延迟。
To initialize Wwise with the lowest latency, call AK::SoundEngine::GetDefaultSettings()
and AK::SoundEngine::GetDefaultPlatformSettings()
, then apply the following changes:
AkPlatformInitSettings::uNumRefillsInVoice
to 2.AkPlatformInitSettings::eAudioAPI
to AkAudioAPI_AAudio
.AkPlatformInitSettings::eAudioPath
to AkAudioPath_Exclusive
.优势: 可将延迟降到最低。
劣势: 可用CPU受限。分配给渲染音频的时间非常短,而且很容易被其他系统上的事件打断。音频设计的CPU开销(比如RTPCs、切换开关、定位、以及容器)会是一个问题,需要仔细监控。Also, device compatibility is reduced. Only devices running Android 8.1 and above will have audio.
在音频帧所需处理时间短到 CPU 无法及时完成处理时,会出现音频匮乏。此时,假如游戏不是在输出无声音频,用户可能会听到可辨的噼啪和毛刺噪声。
若无法接受这种毛刺现象,可通过如下方式禁用此行为:确保将 uNumRefillsInVoice
设成一个大到绝对不会导致匮乏的初始值。在大部分游戏中 uNumRefillsInVoice
需要至少设置成3,通常为4,这样能为CPU占用变化留出余量。
Many Bluetooth devices cannot be low latency or use a fast audio path. In fact, to have glitchless audio with a Bluetooth device, the buffering must be a lot higher. Wwise will detect the usage of a high-latency Bluetooth headset and automatically override AkPlatformInitSettings::uNumRefillsInVoice
to reach a latency of 170 ms.