Advertisement
Guest User

wwise.cpp

a guest
Aug 6th, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.65 KB | None | 0 0
  1. #include <AK/SoundEngine/Common/AkMemoryMgr.h>                      // memory manager interface
  2. #include <AK/SoundEngine/Common/AkModule.h>                         // default memory manager
  3.  
  4. #include <AK/SoundEngine/Common/IAkStreamMgr.h>                     // streaming manager interface
  5. #include <AK/Tools/Common/AkPlatformFuncs.h>                        // thread definitions
  6. #include <AK/SoundEngine/Win32/AkFilePackageLowLevelIOBlocking.h>   // sample low-level I/O implementation
  7.  
  8. #include <AK/SoundEngine/Common/AkSoundEngine.h>                    // actual sound engine header
  9.  
  10. #include <AK/MusicEngine/Common/AkMusicEngine.h>                    // music engine
  11.  
  12. #include <AK/SpatialAudio/Common/AkSpatialAudio.h>                  // spatial audio
  13.  
  14. #ifndef AK_OPTIMIZED                                                // AK_OPTIMIZED is only used in Release configuration
  15.  
  16. //#include <AK/Comm/AkCommunication.h>                                
  17.  
  18. #endif
  19.  
  20. #include "util.h"
  21. #include "wwise.h"
  22. #include "Wwise_IDs.h"
  23. #include <Windows.h>
  24.  
  25. namespace AdventureEngine {
  26.    
  27.     WwiseManager::WwiseManager() {
  28. #define AK_WIN
  29.     }
  30.  
  31.     WwiseManager::~WwiseManager() {
  32.         // terminate in reverse order of initialization
  33. #ifndef AK_OPTIMIZED
  34.         /*
  35.         AK::Comm::Term();
  36.         */
  37. #endif
  38.  
  39.         //AK::SpatialAudio::Term();
  40.         AK::MusicEngine::Term();
  41.         AK::SoundEngine::Term();
  42.         g_lowLevelIO.Term();
  43.         if (AK::IAkStreamMgr::Get()) {
  44.             AK::IAkStreamMgr::Get()->Destroy();
  45.         }
  46.         AK::MemoryMgr::Term();
  47.     }
  48.  
  49.     bool WwiseManager::InitMemoryManager() {
  50.         AkMemSettings memSettings;
  51.         AK::MemoryMgr::GetDefaultSettings(memSettings);
  52.         if (AK::MemoryMgr::Init(&memSettings) != AK_Success) {
  53.             Util::Print("[WwiseManager::InitMemoryManager] Could not create the memory manager :(");
  54.             return false;
  55.         }
  56.  
  57.         return true;
  58.     }
  59.    
  60.     bool WwiseManager::InitStreamingManager() {
  61.         AkStreamMgrSettings streamSettings;                 // create & init instance of default streaming manager
  62.         AK::StreamMgr::GetDefaultSettings(streamSettings);  // Note this can be overwritten
  63.  
  64.         // customnized stream manager settings go here
  65.  
  66.         AK::IAkStreamMgr * pStreamMgr = AK::StreamMgr::Create(streamSettings);
  67.         AKASSERT(pStreamMgr);
  68.  
  69.         // create streaming device with low-level I/O handshaking
  70.         // note this can be overwritten
  71.  
  72.         AkDeviceSettings deviceSettings;
  73.         AK::StreamMgr::GetDefaultDeviceSettings(deviceSettings);
  74.  
  75.         // creates a streaming device in stream manager,
  76.         // and registers itself as the File Location Resolver
  77.         AKRESULT ioResult = g_lowLevelIO.Init(deviceSettings);
  78.         AKASSERT(AK_Success == ioResult);
  79.  
  80.         return true;
  81.     }
  82.    
  83.     bool WwiseManager::CreateSoundEngine() {
  84.         // using default init parameters
  85.         AkInitSettings initSettings;
  86.         AkPlatformInitSettings platformInitSettings;
  87.         AK::SoundEngine::GetDefaultInitSettings(initSettings);
  88.         AK::SoundEngine::GetDefaultPlatformInitSettings(platformInitSettings);
  89.  
  90.         AKRESULT engineResult = AK::SoundEngine::Init(&initSettings, &platformInitSettings);
  91.         AKASSERT(AK_Success == engineResult);
  92.  
  93.         return true;
  94.     }
  95.    
  96.     bool WwiseManager::InitMusicEngine() {
  97.         // initialize music engine using default parameters
  98.         AkMusicSettings musicSettings;
  99.         AK::MusicEngine::GetDefaultInitSettings(musicSettings);
  100.  
  101.         AKRESULT musicResult = AK::MusicEngine::Init(&musicSettings);
  102.         AKASSERT(AK_Success == musicResult);
  103.  
  104.         return true;
  105.     }
  106.  
  107.     bool WwiseManager::InitSpatialAudio() {
  108.         // using default parameters
  109.  
  110.             //constructor fills AkSpatialAudioInitSettings w/ recommended defaults
  111.         AkSpatialAudioInitSettings spatialSettings;
  112.  
  113.         AKRESULT spatialResult = AK::SpatialAudio::Init(spatialSettings);
  114.         AKASSERT(AK_Success == spatialResult);
  115.  
  116.         return true;
  117.     }
  118.  
  119.     bool WwiseManager::LoadBanks() {
  120.         // setup bank path
  121.         g_lowLevelIO.SetBasePath(AKTEXT("../Wwise_Adventure/GeneratedSoundBanks/Windows/"));
  122.         AK::StreamMgr::SetCurrentLanguage(AKTEXT("English(US)"));
  123.  
  124.         // load banks synchronously
  125.         AKRESULT initResult = AK::SoundEngine::LoadBank(AK::BANKS::INIT);
  126.         if (initResult != AK_Success) {
  127.             Util::Print("[WwiseManager::LoadBanks] Failed to load Init bank");
  128.             Util::Print("initResult is " + std::to_string(initResult));
  129.             return false;
  130.         }
  131.  
  132.         AKRESULT musicResult = AK::SoundEngine::LoadBank(AK::BANKS::MUSIC);
  133.         if (musicResult != AK_Success) {
  134.             Util::Print("[WwiseManager::LoadBanks] Failed to load Music bank");
  135.             return false;
  136.         }
  137.  
  138.         return true;
  139.     }
  140.  
  141.     bool WwiseManager::RegisterObjects() {
  142.         AKRESULT listenerResult = AK::SoundEngine::RegisterGameObj(Listener, "Default Listener");
  143.         AKRESULT regListenerResult = AK::SoundEngine::SetDefaultListeners(&Listener, 1);
  144.         if (listenerResult != AK_Success) {
  145.             Util::Print("[WwiseManager::RegisterObjects] Failed to register Default Listener object.");
  146.             Util::Print("listenerResult is " + std::to_string(listenerResult));
  147.             return false;
  148.         }
  149.  
  150.         AKRESULT regMusicResult = AK::SoundEngine::RegisterGameObj(MusController, "MusicController");
  151.         if (regMusicResult != AK_Success) {
  152.             Util::Print("[WwiseManager::RegisterObjects] Failed to register MusicController.");
  153.             Util::Print("regMusicResult is " + std::to_string(regMusicResult));
  154.             return false;
  155.         }
  156.  
  157.         return true;
  158.     }
  159.  
  160.     bool WwiseManager::UnregisterObjects() {
  161.         AKRESULT unregResult = AK::SoundEngine::UnregisterAllGameObj();
  162.         if (unregResult != AK_Success) {
  163.             Util::Print("[WwiseManager::UnregisterObjects] Failed to unregister all gameObjects");
  164.             return false;
  165.         }
  166.  
  167.         return true;
  168.     }
  169.  
  170.     /*
  171. #ifndef AK_OPTIMIZED
  172.    
  173.     bool WwiseManager::InitComms() {
  174.         // method should not be called in release build;
  175.             // only called when not using AK_OPTIMIZED
  176.         AkCommSettings commSettings;
  177.         AK::Comm::GetDefaultInitSettings(commSettings);
  178.         if (AK::Comm::Init(commSettings) != AK_Success) {
  179.             Util::Print("[WwiseManager::InitComms] Could not initialize comms :(");
  180.             return false;
  181.         }
  182.  
  183.         return true;
  184.     }
  185.    
  186. #endif
  187. */
  188.     bool WwiseManager::InitSoundEngine() {
  189.         if (!InitMemoryManager()) {
  190.             return false;
  191.         }
  192.        
  193.         if (!InitStreamingManager()) {
  194.             return false;
  195.         }
  196.        
  197.         if (!CreateSoundEngine()) {
  198.             return false;
  199.         }
  200.        
  201.         if (!InitMusicEngine()) {
  202.             return false;
  203.         }
  204.  
  205.         if (!InitSpatialAudio()) {
  206.             return false;
  207.         }
  208.  
  209.         if (!LoadBanks()) {
  210.             return false;
  211.         }
  212.  
  213.         if (!RegisterObjects()) {
  214.             return false;
  215.         }
  216.  
  217.         //init comms
  218.         /*
  219. #ifndef AK_OPTIMIZED
  220.        
  221.         if (!InitComms()) {
  222.             return false;
  223.         }
  224.        
  225. #endif
  226. */
  227.         return true;
  228.     }
  229.  
  230.     void WwiseManager::Post(AkUniqueID eventId, AkGameObjectID gameObjectId, AkCallbackFunc callback) {
  231.         AK::SoundEngine::PostEvent(eventId, gameObjectId, 0U, callback);
  232.  
  233.         // Process bank requests, events, positions, RTPCs, etc.
  234.         AK::SoundEngine::RenderAudio(false);
  235.     }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement