Version
menu_open

Method 5: Preparing Events and Game Syncs (Switches and States)

This method will apply if:

  • A small level of granularity is required for media to keep the memory usage low.

  • You do not want to worry about splitting your media assets into SoundBanks.

  • You have Events in your project that play different sounds based on Switches or States.

  • Your project contains interactive music that plays music based on Switches or States.

This method is basically the same as the previous method, but with more control over the media that gets loaded when Events are prepared. With this method, only the media associated with both the Events that are prepared and the game syncs that are currently active is loaded into memory.

Let's say you have a simple project with two Events: “Play_Maincharacter_FootSteps” and “Play_Monster_Footsteps”. Each Event plays a different Switch Container that plays different random sounds based on the ground texture under the moving character. The Switch Group name is “GroundTexture” and has three possible states: “Snow”, “Concrete”, and “Sand”.

The Switch Container hierarchies in Wwise will look like the following:

In this example, we have 18 sounds (6 groups of 3 sounds) that can potentially be loaded into memory. You could use Method 4: Preparing Action Events, but you won't get a level of granularity smaller than 6 sounds loaded in memory per Event.

You could use Method 3: Micromanaging Your Media to get a better level of granularity, but you would have to create 6 different SounbBanks for this simple project (the number of SoundBanks increases quickly in a real project). Then, when a monster appears, you would have to check to see what textures are possible and then load the appropriate SoundBanks.

With the current method, all you have to do is specify which Events and game syncs are possible and then only the appropriate media will be loaded. To make things very simple, all the media can be grouped into one single SoundBank.

To set up SoundBanks when preparing Events and Game Syncs:

  1. Create a SoundBank named “Events” and load it into the SoundBank Editor.

  2. Drag the two Events to the Add tab of the SoundBank Editor.

  3. Disable the Media check box, leaving only the Events and Structures check boxes enabled. When using PrepareEvent(), the media must not reside in a SoundBank, but be loaded directly off disk as a loose file.

    [Note] Note

    For the purposes of this example, all the Events and structures are contained in one SoundBank. Although this is acceptable for small projects, you will most likely want to split up your content into several SoundBanks. It is also possible to create a separate “Structures” SoundBank that does not need to be explicitly loaded nor prepared from the SDK command because each Event includes references to the other SoundBanks that need to be loaded.

  4. Generate the SoundBanks and copy the generated SoundBank folder to the game application.

    [Note] Note

    The structure data contained within a single SoundBank can't be split at run time. Therefore, if you are using AK::SoundEngine::PrepareEvent, and the structure data from a separate SoundBank is required, all the structures within that SoundBank will be loaded at once. For this reason, you may want to split the structure content in your project into multiple SoundBanks, to minimize the amount of unnecessary information that is loaded into memory.

To prepare Events and game syncs in game:

  1. Load the “Event” SoundBank before the two Events are required by the game.

  2. Activate the Concrete texture at all times.

  3. Prepare the main character footstep Event at all times.

  4. When possible ground textures are nearby, activate the game syncs.

The following sample of code gives you an idea how to prepare game syncs in game. First off, you need to initialize the sound engine and set the required settings, including the bEnableGameSyncPreparation flag.

          
          // Initializing the sound engine. 

          AkInitSettings initSettings;
          AkPlatformInitSettings platformInitSettings;
          AK::SoundEngine::GetDefaultInitSettings( initSettings ):
          AK::SoundEngine::GetDefaultPlatformInitSettings( platformInitSettings ):

          // Set the required settings. 

          ...

          // Set PrepareEvent related settings. 

          // The flag bEnableGameSyncPreparation is set to true to activate the prepare
          // Game Sync mechanism. When set to false, the media associated with all Game
          // Syncs is loaded and there is no need to call AK::SoundEngine:PrepareGameSyncs. 
          //
          // When set to true, no media that is Game Sync dependent will be loaded unless 
          // the Game Sync is activated by calling AK::SoundEngine:PrepareGameSyncs. 
          initSettings.bEnableGameSyncPreparation = true;

          // (Optional) Allocate a memory pool into which prepared media will be loaded. 
          // If this is not done, memory will be allocated directly in the default memory pool. 
          {
            initSettings.uPrepareEventMemoryPoolID = AK.MemoryMgr.CreatePool( NULL, 4*1024*1024, 1024, AkMalloc );

            // (Optional) Give the memory pool a name. This can be very useful for profiling. 
            AK::MemoryMgr::SetPoolName( initSettings.uPrepareEventMemoryPoolID, L"PrepareEventPool" );
          }

          AKRESULT eResult = AK.SoundEngine.Init( initSettings, platformInitSettings );
          if( eResult != AK_Success )
          {
            // Handle error. 
          }
        

Then you can load the Init bank and the Events' SoundBank.

          
          // Load Init bank and the Event/structure bank. 
          AkBankID    bankID;  // Not used in the sample. 
          AKRESULT eResult = AK::SoundEngine::LoadBank( L"Init.bnk", AK_DEFAULT_POOL_ID, bankID );
          if( eResult == AK_Success )
          {
              eResult = AK::SoundEngine::LoadBank( L"Events.bnk", AK_DEFAULT_POOL_ID, bankID );
          }

          // ... At this point, the two Events are loaded, but not prepared. 
          // No media is currently loaded. 
        

Now you can prepare the required Events and Game Syncs.

          
          const AkOSChar** pNameArray = new const AkOSChar*[1];

          // Prepare the main character footstep event. 
          pNameArray[0] = L"Play_Maincharacter_FootSteps";
          eResult = AK::SoundEngine::PrepareEvent(AK::SoundEngine::Preparation_Load, pNameArray, 1); // 1 is the array size. 

          // ... At this point, one Event has been prepared, but no media has been loaded. 

          // Now, since concrete is always available in the game. 
          pNameArray[0] = L"Concrete";
          eResult = AK::SoundEngine::PrepareGameSyncs(AK::SoundEngine::Preparation_Load, AkGroupType::AkGroupType_Switch, L"GroundTexture", pNameArray, 1 );
          
          
            // ... At this point, the 3 sounds (Sound_Concrete_main_1, Sound_Concrete_main_2, and Sound_Concrete_main_3)
            // are loaded.
          

          // Now, let's say that the main character enters a land where there is snow. 
          pNameArray[0] = L"Snow";
          eResult = AK::SoundEngine::PrepareGameSyncs(AK::SoundEngine::Preparation_Load, AkGroupType::AkGroupType_Switch, L"GroundTexture", pNameArray, 1 );

          // ... At this point, the 3 sounds (Sound_Snow_main_1, Sound_Snow_main_2, and Sound_Snow_main_3)
          // just got loaded. 

          // Then let's say that a monster suddenly appears. 
          pNameArray[0] = L"Play_Monster_Footsteps";
          eResult = AK::SoundEngine::PrepareEvent( AK::SoundEngine::Preparation_Load, pNameArray, 1 ); // 1 is the array size. 

          // ... At this point, 6 more sounds ( Sound_Concreate_Monster_1.2.3 and Sound_Snow_Monster_1.2.3 ). 

          // And now our player decides to run away from the monster, which goes after him. 
          // They run so far that they arrive at a place where there no longer is no snow. 

          pNameArray[0] = L"Snow";
          eResult = AK::SoundEngine::PrepareGameSyncs( AK::SoundEngine::Preparation_Unload, AkGroupType::AkGroupType_Switch, L"GroundTexture", pNameArray, 1 );
          // ... At this point,the 6 snow-related sounds (Sound_Snow_Monster_1.2.3 and Sound_Snow_main_1.2.3 )
          // are unloaded from memory. 

          ...
        

Additional Notes on this Method

The following table lists the pros and cons of preparing game syncs.

Pros

Cons

Bank generation process is simple.

Level of granularity for media is very small.

Maintain a low overall memory usage.

Easy to automate the process.

Only useful media gets loaded.

Potentially increases the number of reads and seeks on the disk as the media assets will be loaded one by one.

Less control over the total amount of memory used.

Activating a game sync can cause high streaming bandwidth when a lot of Events are prepared that require new data to be loaded.


Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise