版本
menu
Wwise Unreal Integration Documentation
|
External Sources are a type of source that developers can associate with Wwise sound objects to provide sound data at runtime. You can use External Sources to load media dynamically, especially if there are many different media files associated with an Event, such as multiple lines of dialogue.
You can use the External Source Manager to implement your own system that determines which media to load, as well as when and how to load it. The External Source Manager provides a highly extensible base class that contains a basic implementation to track states of External Sources and their media, but you must extend it to define the actual loading behavior.
In the Wwise Unreal Integration, the External Source system consists of three parts:
To use External Sources, you must first set the generation path in Wwise Authoring, in the External Sources tab in the Project Settings dialog. See Specifying the Input/Output Locations for External Sources for more information.
External Source 是个空的容器。The game has to fill it in and inform the sound engine about its contents.
An External Source uses a Cookie as an identifier, similar to a ShortId. 若要获取 Cookie,请对在源的 Contents Editor 中为 External Source 插件指定的名称进行哈希处理。See Contents Editor: Wwise External Source for more information.
When an Event that uses External Sources is posted to the sound engine, an array of AkExternalSourceInfo structures that identify the media to use for each Cookie must be passed with it. This media can be in memory or streamed, and the game must ensure that these resources are ready when the Event is posted.
For more information about External Sources, see the following topics:
External Source 具有以下几个显著特性:
To manage the relationship between Events, External Sources, and media, the External Source Manager:
AkExternalSourceInfo
structures for calls to PostEvent
.The default implementation of the Wwise External Source Manager attempts to answer PostEvent
calls (PrepareExternalSourceInfos
, BindPlayingIdToExternalSources
, and OnEndOfEvent
) as quickly as possible. It requests PrepareExternalSourceInfos
in order to "use" the specified media until OnEndOfEvent
indicates that the playing media is no longer needed. The Simple External Source Manager provides the cookies that identify the media to load. You can override the default implementation if desired.
To implement a custom Wwise External Source Manager, you must first create an Unreal module. 该模块至少要包含两个类:
FWwiseExternalSourceManager
,负责履行上节中所列的职责。FWwiseExternalSourceManager
包含定义 External Source 所需的纯虚拟接口。在特殊情况下,工程可将此定义为其继承点,并完全控制 External Source 管线。FWwiseExternalSourceManagerImpl
具有在运行时加载和卸载 External Source 所用媒体所需的各种函数。它包含由 External Source Cookie 到媒体 ID 的映射,可处理 I/O 操作并追踪媒体的生命周期。通过继承该类,可简化自定义追踪操作和打包的实现。FWwiseExternalSourceManagerImpl
类可自行处理复杂的 I/O 详细信息。FWwiseSimpleExtSrcModule
用作父类,因为它是可扩展的。FWwiseFileHandlerModule
,负责覆盖 InstantiateExternalSourceManager
以返回第一个类的实例。在此之后,若要启用模块,可将 WwiseFileHandlerModuleName
设为 DefaultEngine.ini
文件的 [Audio]
部分中的新模块的名称。有关详细信息,请参阅 启用 Simple External Source Manager 章节。
Wwise External Source Manager 是 WwiseFileHandler
模块中的接口。When Wwise Event assets that use External Sources are loaded, the WwiseResourceLoader
module passes the External Source information in the Event's CookedData
(see Wwise Unreal 素材) to the WwiseFileHandler
, which then delegates resource loading to the Wwise External Source Manager Implementation. Subsequent behavior depends on the implementation.
在默认实现中,External Source Manager 会创建 FWwiseExternalSourceState 结构以供追踪 External Source。基于具体的实现和可用信息,会加载媒体或准备进行流传输。同样,在加载 Event 素材时,会告知 External Source Manager 并相应地更新 External Source 的状态。此行为履行 External Source Manager 的第一项职责(追踪 External Source 的状态),其在以下函数中实现:
AkExternalSourceInfo
以便播放 External Source。LoadExternalSourceImpl
的调用。UnloadExternalSourceImpl
的调用。LoadExternalSourceMedia
。UnloadExternalSourceMedia
is called.The default implementation answers PostEvent
calls (Prepare
, Bind
) as quickly as possible.
第二项职责(填充 AkExternalSourceInfo 结构)由 PrepareExternalSourceInfos
履行。对此,将返回 PostEvent
External Source 参数。它会检索 CookieToMedia
中的数据,使用该信息来定义不同的文件状态,并提供所需的 AkExternalSourceInfo
以便发送 Event。若要使用更为复杂的选择算法,可将其覆盖。
在 Wwise Simple External Source Manager 扩展中,有个固定的 MediaInfo
DataTable,其用于识别工程中的所有 External Source 媒体及相关元数据。您可以采用更为高级的系统来动态更新已知媒体列表。因为有很多不同的方式来实现此类系统,所以所有操作都可以虚拟化。您可以创建相应的代码来让 Random Container 更改每一 PostEvent,或者根据外部状态(如语言变化)来更改结构。
The FWwiseExternalSourceManagerImpl
class tracks known External Source media and the information necessary to load them. 这种状态追踪通过 ExternalSourceStatesById
映射在内部完成。
在实现前面所说的系统和结构后,建议实现以下虚函数:
FWwiseFileHandlerBase
继承的方法来追踪媒体加载状态,并使用 FWwiseExternalSourceFileState 结构来管理媒体资源。SetExternalSourceMedia
函数假定各个 External Source 媒体具有唯一的 ID。对于 SetExternalSourceMediaByName
,则可通过名称来检索媒体 ID。建议将 Wwise Simple External Source Manager 作为这些函数的参考,因为实现很可能仅在如何存储、更新和检索由 External Source 到媒体的映射上有所不同。记住,External Source 和媒体文件之间映射关系的动态变化可能会导致资源被加载和卸载。
The current implementation treats these as blocking functions, which potentially run through the game thread. 不过,这并不是必需的。
![]() | 警告: Forcibly unloading External Source media while it is playing causes the sound engine to crash. The FWwiseExternalSourceFileState can handle this automatically through the BindPlayingIdToExternalSources and OnEndOfEvent methods to increment and decrement their play counts. |
After you implement the desired functions, the most complex part of External Source manager development is complete. 倘若一切正常,可通过加载 Event 素材或采用系统对 External Source 的准备方式,来将 External Source 所用的媒体加载到内存中或准备进行流传输。
最后,必须对 External Source 媒体进行打包。简单来说,可在 Unreal 工程中生成 External Source 媒体,并将其保存到被设为始终烘焙的目录。To implement more complex packaging logic, override the External Source Manager's Cook method, which the Wwise Resource Cooker calls for each External Source contained in cooked Wwise Assets.
The following functions, which you can override, are also available:
在默认情况下,会在 WwiseExternalSourceStatics 中暴露三个 Blueprint 函数。
These functions call the corresponding functions defined in the Simple External Source Manager extension. 有关详细信息,请参阅 External Source Manager Blueprint 函数 章节。
默认在 WwiseExternalSourceManagerImpl
中使用该结构来获取所加载 External Source 的引用计数。
Wwise Simple External Source Manager 使用该结构来处理媒体资源。状态可追踪引用计数以及其当前是否正在播放。Unloading External Source media while it is playing causes the sound engine to crash. 您可以通过两个子类来处理加载到内存中或进行流传输的媒体。
FWwiseFileHandlerBase
基类对自身进行注册。在将要对媒体进行流传输的请求传给 External Source Manager 时,会检索注册的 FileState 并由其处理后续 I/O 请求。