AkInitializationSettings.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "InitializationSettings/AkInitializationSettings.h"
  16. #include "Platforms/AkUEPlatform.h"
  17. #include "HAL/PlatformMemory.h"
  18. #include "Misc/App.h"
  19. #include "ProfilingDebugging/CpuProfilerTrace.h"
  20. #include "ProfilingDebugging/MiscTrace.h"
  21. #include "AkAudioDevice.h"
  22. #include "Wwise/WwiseAssertHook.h"
  23. #include "Wwise/WwiseIOHook.h"
  24. #include "Wwise/API/WwiseCommAPI.h"
  25. #include "Wwise/API/WwiseMemoryMgrAPI.h"
  26. #include "Wwise/API/WwiseMonitorAPI.h"
  27. #include "Wwise/API/WwiseMusicEngineAPI.h"
  28. #include "Wwise/API/WwiseSoundEngineAPI.h"
  29. #include "Wwise/API/WwiseSpatialAudioAPI.h"
  30. #include "Wwise/API/WwiseStreamMgrAPI.h"
  31. #include "Wwise/Stats/AkAudioMemory.h"
  32. #include "Wwise/Stats/AsyncStats.h"
  33. #include "Wwise/WwiseGlobalCallbacks.h"
  34. #include "WwiseDefines.h"
  35. namespace AkInitializationSettings_Helpers
  36. {
  37. enum { IsLoggingInitialization = true };
  38. FAkInitializationStructure::MemoryAllocFunction AllocFunction = nullptr;
  39. FAkInitializationStructure::MemoryFreeFunction FreeFunction = nullptr;
  40. void* AkMemAllocVM(size_t size, size_t* /*extra*/)
  41. {
  42. ASYNC_INC_MEMORY_STAT_BY(STAT_WwiseMemorySoundEngineVM, size);
  43. return AllocFunction(size);
  44. }
  45. void AkMemFreeVM(void* address, size_t /*size*/, size_t /*extra*/, size_t release)
  46. {
  47. if (release)
  48. {
  49. FreeFunction(address, release);
  50. ASYNC_DEC_MEMORY_STAT_BY(STAT_WwiseMemorySoundEngineVM, release);
  51. }
  52. }
  53. #if AK_SUPPORT_DEVICE_MEMORY
  54. void* AkMemAllocDevice(size_t size, size_t* extra)
  55. {
  56. ASYNC_INC_MEMORY_STAT_BY(STAT_WwiseMemorySoundEngineDevice, size);
  57. return AKPLATFORM::AllocDevice(size, extra);
  58. }
  59. void AkMemFreeDevice(void* address, size_t size, size_t extra, size_t release)
  60. {
  61. AKPLATFORM::FreeDevice(address, size, extra, release);
  62. if (release)
  63. {
  64. ASYNC_DEC_MEMORY_STAT_BY(STAT_WwiseMemorySoundEngineDevice, release);
  65. }
  66. }
  67. #endif
  68. void AkProfilerPushTimer(AkPluginID in_uPluginID, const char* in_pszZoneName)
  69. {
  70. if (!in_pszZoneName)
  71. {
  72. in_pszZoneName = "(Unknown)";
  73. }
  74. #if CPUPROFILERTRACE_ENABLED
  75. FCpuProfilerTrace::OutputBeginDynamicEvent(in_pszZoneName);
  76. #endif
  77. #if PLATFORM_IMPLEMENTS_BeginNamedEventStatic
  78. FPlatformMisc::BeginNamedEventStatic(WwiseNamedEvents::Color1, in_pszZoneName);
  79. #else
  80. FPlatformMisc::BeginNamedEvent(WwiseNamedEvents::Color1, in_pszZoneName);
  81. #endif
  82. }
  83. void AkProfilerPopTimer()
  84. {
  85. FPlatformMisc::EndNamedEvent();
  86. #if CPUPROFILERTRACE_ENABLED
  87. FCpuProfilerTrace::OutputEndEvent();
  88. #endif
  89. }
  90. void AkProfilerPostMarker(AkPluginID in_uPluginID, const char* in_pszMarkerName)
  91. {
  92. // Filter out audioFrameBoundary bookmarks, because those occur too frequently
  93. if (in_uPluginID != AKMAKECLASSID(AkPluginTypeNone, AKCOMPANYID_AUDIOKINETIC, AK::ProfilingID::AudioFrameBoundary))
  94. {
  95. TRACE_BOOKMARK(TEXT("AK Marker: %s"), in_pszMarkerName);
  96. }
  97. }
  98. }
  99. //////////////////////////////////////////////////////////////////////////
  100. // FAkInitializationStructure
  101. FAkInitializationStructure::FAkInitializationStructure()
  102. {
  103. auto* Comm = IWwiseCommAPI::Get();
  104. auto* MemoryMgr = IWwiseMemoryMgrAPI::Get();
  105. auto* MusicEngine = IWwiseMusicEngineAPI::Get();
  106. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  107. auto* StreamMgr = IWwiseStreamMgrAPI::Get();
  108. if (UNLIKELY(!Comm || !MemoryMgr || !MusicEngine || !SoundEngine || !StreamMgr)) return;
  109. MemoryMgr->GetDefaultSettings(MemSettings);
  110. StreamMgr->GetDefaultSettings(StreamManagerSettings);
  111. StreamMgr->GetDefaultDeviceSettings(DeviceSettings);
  112. #if !WWISE_2023_1_OR_LATER
  113. DeviceSettings.uSchedulerTypeFlags = AK_SCHEDULER_DEFERRED_LINED_UP;
  114. #endif
  115. DeviceSettings.uMaxConcurrentIO = AK_UNREAL_MAX_CONCURRENT_IO;
  116. SoundEngine->GetDefaultInitSettings(InitSettings);
  117. #ifdef AK_ENABLE_ASSERTS
  118. InitSettings.pfnAssertHook = WwiseAssertHook;
  119. #endif
  120. InitSettings.eFloorPlane = AkFloorPlane_XY;
  121. InitSettings.fGameUnitsToMeters = 100.f;
  122. InitSettings.fnProfilerPushTimer = AkInitializationSettings_Helpers::AkProfilerPushTimer;
  123. InitSettings.fnProfilerPopTimer = AkInitializationSettings_Helpers::AkProfilerPopTimer;
  124. InitSettings.fnProfilerPostMarker = AkInitializationSettings_Helpers::AkProfilerPostMarker;
  125. SoundEngine->GetDefaultPlatformInitSettings(PlatformInitSettings);
  126. MusicEngine->GetDefaultInitSettings(MusicSettings);
  127. #if AK_ENABLE_COMMUNICATION
  128. Comm->GetDefaultInitSettings(CommSettings);
  129. #endif
  130. }
  131. FAkInitializationStructure::~FAkInitializationStructure()
  132. {
  133. delete[] InitSettings.szPluginDLLPath;
  134. }
  135. void FAkInitializationStructure::SetPluginDllPath(const FString& PlatformArchitecture)
  136. {
  137. if (PlatformArchitecture.IsEmpty())
  138. {
  139. InitSettings.szPluginDLLPath = nullptr;
  140. return;
  141. }
  142. auto Path = FAkPlatform::GetDSPPluginsDirectory(PlatformArchitecture);
  143. auto Length = Path.Len() + 1;
  144. AkOSChar* PluginDllPath = new AkOSChar[Length];
  145. AKPLATFORM::SafeStrCpy(PluginDllPath, TCHAR_TO_AK(*Path), Length);
  146. InitSettings.szPluginDLLPath = PluginDllPath;
  147. }
  148. void FAkInitializationStructure::SetupLLMAllocFunctions(MemoryAllocFunction alloc, MemoryFreeFunction free, bool UseMemTracker)
  149. {
  150. ensure(alloc == nullptr && free == nullptr || alloc != nullptr && free != nullptr);
  151. AkInitializationSettings_Helpers::AllocFunction = alloc;
  152. AkInitializationSettings_Helpers::FreeFunction = free;
  153. #if ENABLE_LOW_LEVEL_MEM_TRACKER
  154. if (UseMemTracker)
  155. {
  156. int32 OutAlignment = 0;
  157. FPlatformMemory::GetLLMAllocFunctions(AkInitializationSettings_Helpers::AllocFunction, AkInitializationSettings_Helpers::FreeFunction, OutAlignment);
  158. }
  159. #endif
  160. if (!AkInitializationSettings_Helpers::AllocFunction || !AkInitializationSettings_Helpers::FreeFunction)
  161. return;
  162. MemSettings.pfAllocVM = AkInitializationSettings_Helpers::AkMemAllocVM;
  163. MemSettings.pfFreeVM = AkInitializationSettings_Helpers::AkMemFreeVM;
  164. #if AK_SUPPORT_DEVICE_MEMORY
  165. MemSettings.pfAllocDevice = AkInitializationSettings_Helpers::AkMemAllocDevice;
  166. MemSettings.pfFreeDevice = AkInitializationSettings_Helpers::AkMemFreeDevice;
  167. #endif
  168. }
  169. //////////////////////////////////////////////////////////////////////////
  170. // FAkMainOutputSettings
  171. void FAkMainOutputSettings::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  172. {
  173. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  174. if (UNLIKELY(!SoundEngine)) return;
  175. auto& OutputSettings = InitializationStructure.InitSettings.settingsMainOutput;
  176. auto ShareSetID = !AudioDeviceShareSet.IsEmpty() ? SoundEngine->GetIDFromString(TCHAR_TO_ANSI(*AudioDeviceShareSet)) : AK_INVALID_UNIQUE_ID;
  177. OutputSettings.audioDeviceShareset = ShareSetID;
  178. switch (ChannelConfigType)
  179. {
  180. case EAkChannelConfigType::Anonymous:
  181. OutputSettings.channelConfig.SetAnonymous(NumberOfChannels);
  182. break;
  183. case EAkChannelConfigType::Standard:
  184. OutputSettings.channelConfig.SetStandard(ChannelMask);
  185. break;
  186. case EAkChannelConfigType::Ambisonic:
  187. OutputSettings.channelConfig.SetAmbisonic(NumberOfChannels);
  188. break;
  189. }
  190. OutputSettings.ePanningRule = (AkPanningRule)PanningRule;
  191. OutputSettings.idDevice = DeviceID;
  192. }
  193. //////////////////////////////////////////////////////////////////////////
  194. // FAkSpatialAudioSettings
  195. void FAkSpatialAudioSettings::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  196. {
  197. auto& SpatialAudioInitSettings = InitializationStructure.SpatialAudioInitSettings;
  198. SpatialAudioInitSettings.uMaxSoundPropagationDepth = MaxSoundPropagationDepth;
  199. SpatialAudioInitSettings.fMovementThreshold = MovementThreshold;
  200. SpatialAudioInitSettings.uNumberOfPrimaryRays = NumberOfPrimaryRays;
  201. SpatialAudioInitSettings.uMaxReflectionOrder = ReflectionOrder;
  202. SpatialAudioInitSettings.uMaxDiffractionOrder = DiffractionOrder;
  203. #if WWISE_2023_1_OR_LATER
  204. SpatialAudioInitSettings.uMaxEmitterRoomAuxSends = MaxEmitterRoomAuxSends;
  205. #endif
  206. SpatialAudioInitSettings.uDiffractionOnReflectionsOrder = DiffractionOnReflectionsOrder;
  207. SpatialAudioInitSettings.fMaxPathLength = MaximumPathLength;
  208. SpatialAudioInitSettings.fCPULimitPercentage = CPULimitPercentage;
  209. SpatialAudioInitSettings.uLoadBalancingSpread = LoadBalancingSpread;
  210. SpatialAudioInitSettings.bEnableGeometricDiffractionAndTransmission = EnableGeometricDiffractionAndTransmission;
  211. SpatialAudioInitSettings.bCalcEmitterVirtualPosition = CalcEmitterVirtualPosition;
  212. }
  213. //////////////////////////////////////////////////////////////////////////
  214. // FAkCommunicationSettings
  215. void FAkCommunicationSettings::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  216. {
  217. #if AK_ENABLE_COMMUNICATION
  218. auto& CommSettings = InitializationStructure.CommSettings;
  219. CommSettings.ports.uDiscoveryBroadcast = DiscoveryBroadcastPort;
  220. CommSettings.ports.uCommand = CommandPort;
  221. const FString GameName = GetCommsNetworkName();
  222. FCStringAnsi::Strcpy(CommSettings.szAppNetworkName, AK_COMM_SETTINGS_MAX_STRING_SIZE, TCHAR_TO_ANSI(*GameName));
  223. #endif
  224. }
  225. FString FAkCommunicationSettings::GetCommsNetworkName() const
  226. {
  227. FString CommsNetworkName = NetworkName;
  228. if (CommsNetworkName.IsEmpty() && FApp::HasProjectName())
  229. {
  230. CommsNetworkName = FApp::GetProjectName();
  231. }
  232. #if WITH_EDITORONLY_DATA
  233. if (!CommsNetworkName.IsEmpty() && !IsRunningGame())
  234. {
  235. CommsNetworkName += TEXT(" (Editor)");
  236. }
  237. #endif
  238. return CommsNetworkName;
  239. }
  240. //////////////////////////////////////////////////////////////////////////
  241. // FAkCommunicationSettingsWithSystemInitialization
  242. void FAkCommunicationSettingsWithSystemInitialization::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  243. {
  244. Super::FillInitializationStructure(InitializationStructure);
  245. #if AK_ENABLE_COMMUNICATION
  246. InitializationStructure.CommSettings.bInitSystemLib = InitializeSystemComms;
  247. #endif
  248. }
  249. void FAkCommunicationSettingsWithCommSelection::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  250. {
  251. Super::FillInitializationStructure(InitializationStructure);
  252. #if AK_ENABLE_COMMUNICATION
  253. InitializationStructure.CommSettings.commSystem = (AkCommSettings::AkCommSystem)CommunicationSystem;
  254. #endif
  255. }
  256. //////////////////////////////////////////////////////////////////////////
  257. // FAkCommonInitializationSettings
  258. void FAkCommonInitializationSettings::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  259. {
  260. auto& InitSettings = InitializationStructure.InitSettings;
  261. InitSettings.uMaxNumPaths = MaximumNumberOfPositioningPaths;
  262. InitSettings.uCommandQueueSize = CommandQueueSize;
  263. InitSettings.uNumSamplesPerFrame = SamplesPerFrame;
  264. MainOutputSettings.FillInitializationStructure(InitializationStructure);
  265. auto& PlatformInitSettings = InitializationStructure.PlatformInitSettings;
  266. PlatformInitSettings.uNumRefillsInVoice = NumberOfRefillsInVoice;
  267. SpatialAudioSettings.FillInitializationStructure(InitializationStructure);
  268. InitializationStructure.MusicSettings.fStreamingLookAheadRatio = StreamingLookAheadRatio;
  269. }
  270. //////////////////////////////////////////////////////////////////////////
  271. // FAkAdvancedInitializationSettings
  272. void FAkAdvancedInitializationSettings::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  273. {
  274. auto& DeviceSettings = InitializationStructure.DeviceSettings;
  275. DeviceSettings.uIOMemorySize = IO_MemorySize;
  276. DeviceSettings.uGranularity = IO_Granularity == 0 ? (32 * 1024) : IO_Granularity;
  277. DeviceSettings.fTargetAutoStmBufferLength = TargetAutoStreamBufferLength;
  278. DeviceSettings.bUseStreamCache = UseStreamCache;
  279. DeviceSettings.uMaxCachePinnedBytes = MaximumPinnedBytesInCache;
  280. auto& InitSettings = InitializationStructure.InitSettings;
  281. InitSettings.bEnableGameSyncPreparation = EnableGameSyncPreparation;
  282. InitSettings.uContinuousPlaybackLookAhead = ContinuousPlaybackLookAhead;
  283. InitSettings.uMonitorQueuePoolSize = MonitorQueuePoolSize;
  284. InitSettings.uMaxHardwareTimeoutMs = MaximumHardwareTimeoutMs;
  285. InitSettings.bDebugOutOfRangeCheckEnabled = DebugOutOfRangeCheckEnabled;
  286. InitSettings.fDebugOutOfRangeLimit = DebugOutOfRangeLimit;
  287. }
  288. //////////////////////////////////////////////////////////////////////////
  289. // FAkAdvancedInitializationSettingsWithMultiCoreRendering
  290. void FAkAdvancedInitializationSettingsWithMultiCoreRendering::FillInitializationStructure(FAkInitializationStructure& InitializationStructure) const
  291. {
  292. Super::FillInitializationStructure(InitializationStructure);
  293. if (EnableMultiCoreRendering)
  294. {
  295. FAkAudioDevice* pDevice = FAkAudioDevice::Get();
  296. check(pDevice != nullptr);
  297. FAkJobWorkerScheduler* pScheduler = pDevice->GetAkJobWorkerScheduler();
  298. check(pScheduler != nullptr);
  299. auto& InitSettings = InitializationStructure.InitSettings;
  300. pScheduler->InstallJobWorkerScheduler(JobWorkerMaxExecutionTimeUSec, MaxNumJobWorkers, InitSettings.settingsJobManager);
  301. }
  302. }
  303. static void UELocalOutputFunc(
  304. AK::Monitor::ErrorCode in_eErrorCode,
  305. const AkOSChar* in_pszError,
  306. AK::Monitor::ErrorLevel in_eErrorLevel,
  307. AkPlayingID in_playingID,
  308. AkGameObjectID in_gameObjID)
  309. {
  310. if (!IsRunningCommandlet())
  311. {
  312. FString AkError(in_pszError);
  313. if (in_eErrorLevel == AK::Monitor::ErrorLevel_Message)
  314. {
  315. UE_LOG(LogWwiseMonitor, Log, TEXT("%s"), *AkError);
  316. }
  317. #if !UE_BUILD_SHIPPING
  318. else if (FPlatformMisc::IsDebuggerPresent() && AkError == TEXT("Voice Starvation"))
  319. {
  320. UE_LOG(LogWwiseMonitor, Log, TEXT("%s [Debugger])"), *AkError);
  321. }
  322. #endif
  323. else
  324. {
  325. #if UE_EDITOR
  326. UE_LOG(LogWwiseMonitor, Warning, TEXT("%s"), *AkError);
  327. #else
  328. UE_LOG(LogWwiseMonitor, Error, TEXT("%s"), *AkError);
  329. #endif
  330. }
  331. }
  332. }
  333. namespace FAkSoundEngineInitialization
  334. {
  335. bool Initialize(FWwiseIOHook* IOHook)
  336. {
  337. if (!IOHook)
  338. {
  339. UE_LOG(LogAkAudio, Error, TEXT("IOHook is null."));
  340. return false;
  341. }
  342. const UAkInitializationSettings* InitializationSettings = FAkPlatform::GetInitializationSettings();
  343. if (InitializationSettings == nullptr)
  344. {
  345. UE_LOG(LogAkAudio, Error, TEXT("InitializationSettings could not be found."));
  346. return false;
  347. }
  348. FAkInitializationStructure InitializationStructure;
  349. InitializationSettings->FillInitializationStructure(InitializationStructure);
  350. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Platform"));
  351. FAkPlatform::PreInitialize(InitializationStructure);
  352. auto* Comm = IWwiseCommAPI::Get();
  353. auto* MemoryMgr = IWwiseMemoryMgrAPI::Get();
  354. auto* Monitor = IWwiseMonitorAPI::Get();
  355. auto* MusicEngine = IWwiseMusicEngineAPI::Get();
  356. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  357. auto* SpatialAudio = IWwiseSpatialAudioAPI::Get();
  358. auto* StreamMgr = IWwiseStreamMgrAPI::Get();
  359. // Enable AK error redirection to UE log.
  360. if (LIKELY(Monitor))
  361. {
  362. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Monitor's Output"));
  363. Monitor->SetLocalOutput(AK::Monitor::ErrorLevel_All, UELocalOutputFunc);
  364. }
  365. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Memory Manager"));
  366. if (UNLIKELY(!MemoryMgr) || MemoryMgr->Init(&InitializationStructure.MemSettings) != AK_Success)
  367. {
  368. UE_LOG(LogAkAudio, Error, TEXT("Failed to initialize AK::MemoryMgr."));
  369. return false;
  370. }
  371. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Global Callbacks"));
  372. auto* GlobalCallbacks = FWwiseGlobalCallbacks::Get();
  373. if (UNLIKELY(!GlobalCallbacks) || !GlobalCallbacks->Initialize())
  374. {
  375. UE_LOG(LogAkAudio, Error, TEXT("Failed to initialize Global Callbacks."));
  376. return false;
  377. }
  378. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Stream Manager"));
  379. if (UNLIKELY(!StreamMgr) || !StreamMgr->Create(InitializationStructure.StreamManagerSettings))
  380. {
  381. UE_LOG(LogAkAudio, Error, TEXT("Failed to initialize AK::StreamMgr."));
  382. return false;
  383. }
  384. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing IOHook"));
  385. if (!IOHook->Init(InitializationStructure.DeviceSettings))
  386. {
  387. UE_LOG(LogAkAudio, Error, TEXT("Failed to initialize IOHook."));
  388. return false;
  389. }
  390. if (AkInitializationSettings_Helpers::IsLoggingInitialization && InitializationStructure.InitSettings.szPluginDLLPath)
  391. {
  392. FString DllPath(InitializationStructure.InitSettings.szPluginDLLPath);
  393. UE_LOG(LogAkAudio, Log, TEXT("Wwise plug-in DLL path: %s"), *DllPath);
  394. }
  395. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Sound Engine"));
  396. if (UNLIKELY(!SoundEngine) || SoundEngine->Init(&InitializationStructure.InitSettings, &InitializationStructure.PlatformInitSettings) != AK_Success)
  397. {
  398. UE_LOG(LogAkAudio, Error, TEXT("Failed to initialize AK::SoundEngine."));
  399. return false;
  400. }
  401. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Music Engine"));
  402. if (UNLIKELY(!MusicEngine) || MusicEngine->Init(&InitializationStructure.MusicSettings) != AK_Success)
  403. {
  404. UE_LOG(LogAkAudio, Error, TEXT("Failed to initialize AK::MusicEngine."));
  405. return false;
  406. }
  407. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Spatial Audio"));
  408. if (UNLIKELY(!SpatialAudio) || SpatialAudio->Init(InitializationStructure.SpatialAudioInitSettings) != AK_Success)
  409. {
  410. UE_LOG(LogAkAudio, Error, TEXT("Failed to initialize AK::SpatialAudio."));
  411. return false;
  412. }
  413. #if AK_ENABLE_COMMUNICATION
  414. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Initializing Communication"));
  415. if (UNLIKELY(!Comm) || Comm->Init(InitializationStructure.CommSettings) != AK_Success)
  416. {
  417. UE_LOG(LogAkAudio, Warning, TEXT("Could not initialize Wwise communication."));
  418. }
  419. else
  420. {
  421. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Log, TEXT("Wwise remote connection application name: %s"), ANSI_TO_TCHAR(InitializationStructure.CommSettings.szAppNetworkName));
  422. }
  423. #endif
  424. return true;
  425. }
  426. void Finalize(FWwiseIOHook* IOHook)
  427. {
  428. auto* Comm = IWwiseCommAPI::Get();
  429. auto* MemoryMgr = IWwiseMemoryMgrAPI::Get();
  430. auto* Monitor = IWwiseMonitorAPI::Get();
  431. auto* MusicEngine = IWwiseMusicEngineAPI::Get();
  432. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  433. auto* StreamMgr = IWwiseStreamMgrAPI::GetAkStreamMgr();
  434. #if AK_ENABLE_COMMUNICATION
  435. if (LIKELY(Comm))
  436. {
  437. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Terminating Communication"));
  438. Comm->Term();
  439. }
  440. #endif
  441. // Note: No Spatial Audio Term
  442. if (LIKELY(MusicEngine))
  443. {
  444. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Terminating Music Engine"));
  445. MusicEngine->Term();
  446. }
  447. if (LIKELY(SoundEngine && SoundEngine->IsInitialized()))
  448. {
  449. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Terminating Sound Engine"));
  450. SoundEngine->Term();
  451. }
  452. if (LIKELY(IOHook))
  453. {
  454. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Terminating IOHook"));
  455. IOHook->Term();
  456. }
  457. if (LIKELY(StreamMgr))
  458. {
  459. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Terminating Stream Manager"));
  460. StreamMgr->Destroy();
  461. }
  462. if (LIKELY(MemoryMgr && MemoryMgr->IsInitialized()))
  463. {
  464. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Terminating Memory Manager"));
  465. MemoryMgr->Term();
  466. }
  467. if (LIKELY(Monitor))
  468. {
  469. UE_CLOG(AkInitializationSettings_Helpers::IsLoggingInitialization, LogAkAudio, Verbose, TEXT("Resetting Monitor's Output"));
  470. Monitor->SetLocalOutput(0, nullptr);
  471. }
  472. }
  473. }