在UE4中整合Wwise及其使用

◇◆丶佛笑我妖孽 提交于 2020-05-04 02:34:07

前言

  一般来说在游戏开发的过程中,声音这一模块是相对独立的。因此会有一些编辑器用于辅助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 

  其中的子文件夹includex64_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选项,否则在最后打包后的游戏中的声音数据将不会有所修改。

  

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!