前言
一般來說在游戲開發的過程中,聲音這一模塊是相對獨立的。因此會有一些編輯器用於輔助sound designer進行設計,這些編輯器再提供一些API方便集成到引擎中。目前在我所有所接觸過的一些游戲中,大部分使用的是Wwise以及FMod。由於最近的項目里面使用的是Wwise和UE4,所以這篇文章我將就Wwise在UE4中是如何使用展開,當作一個記錄,畢竟以后可能還會再用到。
將Wwise集成到UE4中
Wwise以插件的方式集成在UE4中,從WwiseLauncher中下載下來的Wwise integration具有UE4插件的一貫結構:
所以將這個文件夾copy到plugins目錄下。
還沒完,Wwise所依賴的SDK的源代碼以及靜態庫放在哪里呢?
在和*.uplugin同一級的目錄的目錄下新建文件夾ThirdParty,以Win64下VS2017為例,ThirdParty下應具有結構:
---- ThirdParty
|-- include
|-- x64_vc150
其中的子文件夾include和x64_vc150來自..\Wwise 2019.1.0.6947\SDK\
更詳細的可以參照plugin中的AkAudio.Build.cs文件和文檔Wwise_UE4_Integration中的Installation一節,這里不再贅述。
隨后重新生成工程、編譯。然后運行UE4Editor時,打開Project Setting拉到下面就應該能看到Wwise相關的設置了:
在對應的平台里可以設置平台默認的初始值,這里是Windows下的默認值:

這里有一點需要注意,那就是這里的預設應視情況而定。在官方文檔平台上的音頻輸出一節中對各個常用平台的輸出的采樣率、通道數有所介紹。
可以看到在console平台中有其標准化的輸出,即采樣率固定為48000Hz。不同的平台設定描述不同,具體的可以參考...\Wwise 2019.1.0.6947\SDK\include\AK\SoundEngine\Platforms\ 下的sound engine頭文件,比如這是Windows的:
struct AkPlatformInitSettings { // Direct sound. HWND hWnd; ///< Handle to the window associated to the audio. ///< Each game must specify the HWND that will be passed to DirectSound initialization. ///< The value returned by GetDefaultPlatformInitSettings is the foreground HWND at ///< the moment of the initialization of the sound engine and may not be the correct one for your game. ///< It is required that each game provides the correct HWND to be used. // Threading model. AkThreadProperties threadLEngine; ///< Lower engine threading properties AkThreadProperties threadOutputMgr; ///< Ouput thread threading properties AkThreadProperties threadBankManager; ///< Bank manager threading properties (its default priority is AK_THREAD_PRIORITY_NORMAL) AkThreadProperties threadMonitor; ///< Monitor threading properties (its default priority is AK_THREAD_PRIORITY_ABOVENORMAL). This parameter is not used in Release build. // Memory. AkUInt32 uLEngineDefaultPoolSize;///< Lower Engine default memory pool size AkReal32 fLEngineDefaultPoolRatioThreshold; ///< 0.0f to 1.0f value: The percentage of occupied memory where the sound engine should enter in Low memory mode. \ref soundengine_initialization_advanced_soundengine_using_memory_threshold // Voices. AkUInt16 uNumRefillsInVoice; ///< Number of refill buffers in voice buffer. 2 == double-buffered, defaults to 4. AkUInt32 uSampleRate; ///< Sampling Rate. Default is 48000 Hz. Use 24000hz for low quality. Any positive reasonable sample rate is supported. However be careful setting a custom value. Using an odd or really low sample rate may result in malfunctionning sound engine. AkAudioAPI eAudioAPI; ///< Main audio API to use. Leave to AkAPI_Default for the default sink (default value). ///< If a valid audioDeviceShareset plug-in is provided, the AkAudioAPI will be Ignored. ///< \ref AkAudioAPI bool bGlobalFocus; ///< Corresponding to DSBCAPS_GLOBALFOCUS. If using the AkAPI_DirectSound AkAudioAPI type, sounds will be muted if set to false when the game loses the focus. ///< This setting is ignored when using other AkAudioAPI types. IXAudio2* pXAudio2; ///< XAudio2 instance to use for the Wwise sound engine. If NULL (default) Wwise will initialize its own instance. Used only if the sink type is XAudio2 in AkInitSettings.outputType. };
Wwise在UE4中的使用
根據文檔中的說明,UE4中使用Wwise的Workflow分為以下幾個步驟:
1)創建Wwise工程
創建完Wwise工程后,需要在UE4的項目設置中Wwise - Integration Settings下配置項目路徑。
2)在UE4中添加AkAudioEvent
在Content Browser里右鍵就能創建Wwise對象了,此外還有一些其他的Actor:AkAousticPortal, AkReverbVolume, AkSpatialAudioVolume, AkSpotReflector, AkAmbientSound.

需要注意的一件事是,在UE4中引用的Wwise Event的名稱必須與Wwise工程中的名稱一致。
3)在關卡中引用對象AkAudioEvent
在上一步中創建的Event可以直接拖動到關卡中,默認是以AkAmbientSound的類型存在於關卡之中。

在生成完SoundBank后,通過PostEvent即可完成聲音的播放。
4)添加AkAudioBank
與 2)中的步驟類似,但與Event不同,這里創建的SoundBank的名稱可以與Wwise工程中的SoundBank的名稱不同。
5)為AkAudioEvent設置引用的SoundBank
在Event選項卡中為Event指定引用的SoundBank。

6)生成SoundBank
在Build菜單下生成SoundBank,生成的SoundBank的默認路徑是在Content/WwiseAudio/{PLATFORM}下,這個路徑可以在ProjectSetting-> Wwise -> Integration Settings下指定。


這里的Platforms來自UE4的項目設置,Available Banks是來自Content中的UE4的Assets,與Wwise工程中的SoundBank不同,所以在Wwise中生成的SoundBank和在UE4中利用插件生成的SoundBank的數量以及名稱也許會不同。
Note
Wwise幫助我們將音頻的設計和游戲的設計分離開來。在游戲這部分,我們在意的是什么時候播放聲音,播放什么聲音。而在音頻設計,也就是Wwise這里,更着重的是音頻的一些具體參數如聲道、采樣率以及編碼格式等,當然在Wwise中也可以通過Switch,GameObject等涉及更多游戲相關的聲音設計。
所以假如游戲中的聲音沒有改變,即Event和SoundBank等UE4資源對象uasset沒有改變時,但是改變了原始聲音的采樣率等設置時。

在Cook數據時請不要打開Iterative Cook選項,否則在最后打包后的游戲中的聲音數據將不會有所修改。
