版本

menu_open
Wwise SDK 2023.1.3
SoundBank Integration Samples

The following sections contain sample integrations of various SoundBank management strategies. These strategies are described in Strategies for Managing SoundBanks in the Wwise help.

备注: PrepareEvent 和 LoadBank 不可共用,因为两者都会将数据加载到内存中。


The All-in-one SoundBank

With this strategy, all event content, sound structure data, and media files are stored in one SoundBank. For a discussion of this strategy and its implementation in Wwise Authoring, see The All-in-one SoundBank in the Wwise Help.

Since there is only one SoundBank for this game, load it when initializing the game. As always, the sound engine must be initialized first.

...
// 在此初始化声音引擎。
...
// Load the Init bank and the all-in-one bank.
AkBankID bankID; // 此示例中未使用。
AKRESULT eResult = AK::SoundEngine::LoadBank( L"Init.bnk", bankID );
if( eResult == AK_Success )
{
eResult = AK::SoundEngine::LoadBank( L"MyAllInOneBank.bnk", bankID );
}
...

Multiple Complete SoundBanks

This strategy works well for single player games, where all possible sounds depend on the location of the player in the game. For a discussion of this strategy and its implementation in Wwise Authoring, see Multiple Complete SoundBanks in the Wwise Help.

In the game, load the correct bank at the correct time. 例如,游戏可以在开始时加载通用 SoundBank ,然后根据游戏中玩家的实际位置加载其它 SoundBank 。Note that some games will need to have enough memory to load more than one "level" at a time to allow for transitions between levels.

As an alternative to LoadBank(), you could prepare your SoundBanks using AkBankContent_All. This has the advantage of avoiding duplicating media in memory. See 对 SoundBank 做 Prepare 操作.

...
// 在此初始化声音引擎。
...
// 加载初始化 Bank 和通用 SoundBank 。
AkBankID bankID; // 此示例中未使用。
AKRESULT eResult = AK::SoundEngine::LoadBank( L"Init.bnk", bankID );
if( eResult == AK_Success )
{
eResult = AK::SoundEngine::LoadBank( L"CommonEvents.bnk", bankID );
}
...
// 在代码中多处,取决于实际需要:
eResult = AK::SoundEngine::LoadBank( L"Level_1.bnk", bankID );
...
eResult = AK::SoundEngine::LoadBank( L"Level_2.bnk", bankID );
...
eResult = AK::SoundEngine::LoadBank( L"Level_3.bnk", bankID );
...
eResult = AK::SoundEngine::UnloadBank( L"Level_1.bnk", NULL );
...
eResult = AK::SoundEngine::UnloadBank( L"Level_2.bnk", NULL );
...
eResult = AK::SoundEngine::UnloadBank( L"Level_3.bnk", NULL );

Micromanaging Media

Consider this strategy for complex games with many assets. For a discussion of this strategy and its implementation in Wwise Authoring, see Micromanaging Media in the Wwise Help.

In the game, load the common SoundBanks at the beginning of your game then load the other SoundBanks when they are required. For example, the game could load the Event SoundBank and the common footsteps SoundBank at the beginning, then load the other SoundBanks based on the player's location in the game.

// 加载初始化和事件 SoundBank
AkBankID bankID; // 此示例中未使用。
AKRESULT eResult = AK::SoundEngine::LoadBank( L"Init.bnk", bankID );
if( eResult == AK_Success )
{
eResult = AK::SoundEngine::LoadBank( L"EventBank.bnk", bankID );
}
if( eResult == AK_Success )
{
eResult = AK::SoundEngine::LoadBank( L"Common_Footstep_bank.bnk", bankID );
}
...
// 在代码中多处,可能取决于位置:
eResult = AK::SoundEngine::LoadBank( L"Winter_Footstep_bank.bnk", bankID );
...
eResult = AK::SoundEngine::LoadBank( L"Desert_Footstep_bank.bnk", bankID );
...
eResult = AK::SoundEngine::UnloadBank( L"Winter_Footstep_bank.bnk", NULL );
...
eResult = AK::SoundEngine::UnloadBank( L"Desert_Footstep_bank.bnk", NULL );

Preparing Action Events

Consider this strategy if you require a high level of media granularity to keep memory usage low and do not want to manage the structure and media related to Events. For a discussion of this strategy and its implementation in Wwise Authoring, see Preparing Action Events in the Wwise Help.

In the game, load the Events' SoundBank at the beginning of the game, then prepare the Events when they are required in game. The corresponding structures and media will be loaded automatically.

// 初始化声音引擎。
AkInitSettings initSettings;
AkPlatformInitSettings platformInitSettings;
// 设置所需的设置。
...
// 设置 PrepareEvent 相关设置。
initSettings.bEnableGameSyncPreparation = false; // 当前示例中未使用。
AKRESULT eResult = AK::SoundEngine::Init( initSettings, platformInitSettings );
if( eResult != AK_Success )
{
// Handle error.
}
// 加载初始化 SoundBank 和事件/结构 SoundBank 。
AkBankID bankID; // 此示例中未使用。
AKRESULT eResult = AK::SoundEngine::LoadBank( L"Init.bnk", bankID );
if( eResult == AK_Success )
{
eResult = AK::SoundEngine::LoadBank( L"Events.bnk", bankID );
}
...
// 然后在代码中的各个位置:
const char * pEventsNameArray[1] = { "My_Event_Name" };
// Prepare 事件:
eResult = AK::SoundEngine::PrepareEvent( Preparation_Load, pEventsNameArray, 1 ); // 1 is the array size
// 撤消 Prepare 事件:
eResult = AK::SoundEngine::PrepareEvent( Preparation_Unload, pEventsNameArray, 1 ); // 1 is the array size

Preparing Events and Game Syncs (Switches and States)

This strategy is like Preparing Action Events, but with more control over the media that gets loaded when Events are prepared. For a discussion of this strategy and its implementation in Wwise Authoring, see Preparing Events and Game Syncs (Switches and States) in the Wwise Help.

The order in which you call AK::SoundEngine::PrepareEvent and AK::SoundEngine::PrepareGameSync is not important. Each time the state changes, the media pool is updated by crossmatching the Events and the game syncs.

// 初始化声音引擎。
AkInitSettings initSettings;
AkPlatformInitSettings platformInitSettings;
// 设置所需的设置。
...
// 设置 PrepareEvent 相关设置。
////////////////////////////////////////////////////////////////
// bEnableGameSyncPreparation 标志设为 true,以激活
// 准备游戏同步器机制。当设置为 false 时,与所有游戏
// 同步器相关的媒体将加载,并且无需
// 调用 AK::SoundEngine:PrepareGameSyncs。
//
// 当设置为 true 时,不会加载与游戏同步器相关的媒体,
// 除非游戏同步器已通过调用 AK::SoundEngine:PrepareGameSyncs 被激活
////////////////////////////////////////////////////////////////
initSettings.bEnableGameSyncPreparation = true;
AKRESULT eResult = AK.SoundEngine.Init( initSettings, platformInitSettings );
if( eResult != AK_Success )
{
// 处理错误。
}
// 加载初始化 Bank 和事件/结构 SoundBank 。
AkBankID bankID; // 此示例中未使用。
AKRESULT eResult = AK::SoundEngine::LoadBank( L"Init.bnk", bankID );
if( eResult == AK_Success )
{
eResult = AK::SoundEngine::LoadBank( L"Events.bnk", bankID );
}
// ... 在此时,
// 两个事件已加载但尚未 Prepare。当前没有加载媒体。
const char * pNameArray[1];
// Prepare 主人公脚步事件。
pNameArray[0] = "Play_Maincharacter_FootSteps";
eResult = AK::SoundEngine::PrepareEvent( Preparation_Load, pNameArray, 1 ); // 1 是数组大小
// ... 在此时,
// 已 Prepare 一个事件,但尚未加载任何媒体。
// 从现在起,游戏中始终可用 concrete。
pNameArray[0] = "Concrete";
eResult = AK::SoundEngine::PrepareGameSyncs( Preparation_Load, in_eType, "GroundTexture", pNameArray, 1 );
// ... 在此时,
// 已加载 3 个声音:Sound_Concrete_main_1、Sound_Concrete_main_2 和 Sound_Concrete_main_3。
// 现在,假设主人公进入一片雪地。
pNameArray[0] = "Snow";
eResult = AK::SoundEngine::PrepareGameSyncs( Preparation_Load, in_eType, "GroundTexture", pNameArray, 1 );
// ... 在此时,
// 又加载了 3 个声音:Sound_Snow_main_1、Sound_Snow_main_2 和 Sound_Snow_main_3
// 然后假设怪兽突然在此时出现。
pNameArray[0] = "Play_Monster_Footsteps";
eResult = AK::SoundEngine::PrepareEvent( Preparation_Load, pEventsNameArray, 1 ); // 1 是数组大小
// ... 在此时,
// 又加载了 6 个声音( Sound_Concrete_Monster_1.2.3 和 Sound_Snow_Monster_1.2.3)
// 现在我们的玩家决定逃离怪兽,而怪兽在玩家身后紧追不舍。
// 怪兽和玩家一直奔跑,来到没有积雪的地方。
pNameArray[0] = "Snow";
eResult = AK::SoundEngine::PrepareGameSyncs( Preparation_Unload, in_eType, "GroundTexture", pNameArray, 1 );
// ... 在此时,
// 与积雪相关的 6 个声音(Sound_Snow_Monster_1.2.3 和 Sound_Snow_main_1.2.3)已从内存中卸载。
...
参见
AKSOUNDENGINE_API AKRESULT PrepareEvent(PreparationType in_PreparationType, const char **in_ppszString, AkUInt32 in_uNumEvent)
Audiokinetic namespace
AKSOUNDENGINE_API AKRESULT PrepareGameSyncs(PreparationType in_PreparationType, AkGroupType in_eGameSyncType, const char *in_pszGroupName, const char **in_ppszGameSyncName, AkUInt32 in_uNumGameSyncs)
AKSOUNDENGINE_API AKRESULT Init(AkInitSettings *in_pSettings, AkPlatformInitSettings *in_pPlatformSettings)
AkUInt32 AkBankID
Run time bank ID
Definition: AkTypes.h:157
AKRESULT
Standard function call result.
Definition: AkTypes.h:213
AKSOUNDENGINE_API AKRESULT LoadBank(const char *in_pszString, AkBankID &out_bankID, AkBankType in_bankType=AkBankType_User)
@ Preparation_Unload
PrepareEvent() will unload required information to play the specified event.
#define NULL
Definition: AkTypes.h:46
@ AK_Success
The operation was successful.
Definition: AkTypes.h:215
AKSOUNDENGINE_API void GetDefaultInitSettings(AkInitSettings &out_settings)
@ Preparation_Load
PrepareEvent() will load required information to play the specified event.
AKSOUNDENGINE_API AKRESULT UnloadBank(const char *in_pszString, const void *in_pInMemoryBankPtr, AkBankType in_bankType=AkBankType_User)
AKSOUNDENGINE_API void GetDefaultPlatformInitSettings(AkPlatformInitSettings &out_platformSettings)

此页面对您是否有帮助?

需要技术支持?

仍有疑问?或者问题?需要更多信息?欢迎联系我们,我们可以提供帮助!

查看我们的“技术支持”页面

介绍一下自己的项目。我们会竭力为您提供帮助。

来注册自己的项目,我们帮您快速入门,不带任何附加条件!

开始 Wwise 之旅