AkGameplayStatics.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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. /*=============================================================================
  16. AkAudioClasses.cpp:
  17. =============================================================================*/
  18. #include "AkGameplayStatics.h"
  19. #include "AkAmbientSound.h"
  20. #include "AkAudioDevice.h"
  21. #include "AkAudioEvent.h"
  22. #include "AkAudioType.h"
  23. #include "AkComponent.h"
  24. #include "AkEffectShareSet.h"
  25. #include "AkRtpc.h"
  26. #include "AkStateValue.h"
  27. #include "AkSwitchValue.h"
  28. #include "AkTrigger.h"
  29. #include "Engine/GameEngine.h"
  30. #include "EngineUtils.h"
  31. #include "AkAcousticPortal.h"
  32. #include "AkAuxBus.h"
  33. #include "Wwise/API/WwiseSoundEngineAPI.h"
  34. #include "Wwise/WwiseExternalSourceManager.h"
  35. #include "inttypes.h"
  36. #include "WwiseInitBankLoader/WwiseInitBankLoader.h"
  37. bool UAkGameplayStatics::m_bSoundEngineRecording = false;
  38. /*-----------------------------------------------------------------------------
  39. UAkGameplayStatics.
  40. -----------------------------------------------------------------------------*/
  41. UAkGameplayStatics::UAkGameplayStatics(const class FObjectInitializer& ObjectInitializer)
  42. : Super(ObjectInitializer)
  43. {
  44. // Property initialization
  45. }
  46. class UAkComponent * UAkGameplayStatics::GetAkComponent( class USceneComponent* AttachToComponent, bool& ComponentCreated, FName AttachPointName, FVector Location, EAttachLocation::Type LocationType )
  47. {
  48. if ( AttachToComponent == NULL )
  49. {
  50. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::GetAkComponent: NULL AttachToComponent specified!"));
  51. return NULL;
  52. }
  53. FAkAudioDevice * AkAudioDevice = FAkAudioDevice::Get();
  54. if( AkAudioDevice )
  55. {
  56. return AkAudioDevice->GetAkComponent( AttachToComponent, AttachPointName, &Location, LocationType, ComponentCreated );
  57. }
  58. return NULL;
  59. }
  60. bool UAkGameplayStatics::IsEditor()
  61. {
  62. #if WITH_EDITOR
  63. return true;
  64. #else
  65. return false;
  66. #endif
  67. }
  68. bool UAkGameplayStatics::IsGame(UObject* WorldContextObject)
  69. {
  70. EWorldType::Type WorldType = EWorldType::None;
  71. if (WorldContextObject)
  72. {
  73. UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull);
  74. if(World)
  75. WorldType = World->WorldType;
  76. }
  77. return WorldType == EWorldType::Game || WorldType == EWorldType::GamePreview || WorldType == EWorldType::PIE;
  78. }
  79. int32 UAkGameplayStatics::PostEvent(UAkAudioEvent* AkEvent, AActor* Actor, int32 CallbackMask,
  80. const FOnAkPostEventCallback& PostEventCallback, bool bStopWhenAttachedToDestroyed,
  81. FString EventName)
  82. {
  83. if (LIKELY(IsValid(AkEvent)))
  84. {
  85. return AkEvent->PostOnActor(Actor, PostEventCallback, CallbackMask, bStopWhenAttachedToDestroyed);
  86. }
  87. AkDeviceAndWorld DeviceAndWorld(Actor);
  88. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  89. {
  90. return AK_INVALID_PLAYING_ID;
  91. }
  92. AkCallbackType AkCallbackMask = AkCallbackTypeHelpers::GetCallbackMaskFromBlueprintMask(CallbackMask);
  93. AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(AkEvent, EventName);
  94. return DeviceAndWorld.AkAudioDevice->PostEventOnActor(ShortId, Actor, PostEventCallback, AkCallbackMask, bStopWhenAttachedToDestroyed, {});
  95. }
  96. int32 UAkGameplayStatics::PostAndWaitForEndOfEvent(UAkAudioEvent* AkEvent, AActor* Actor, bool bStopWhenAttachedToDestroyed,
  97. FLatentActionInfo LatentInfo)
  98. {
  99. if (UNLIKELY(!IsValid(AkEvent)))
  100. {
  101. UE_LOG(LogAkAudio, Error, TEXT("Failed to post and wait invalid AkAudioEvent on actor '%s'."), IsValid(Actor) ? *Actor->GetName() : TEXT("(invalid)"));
  102. return AK_INVALID_PLAYING_ID;
  103. }
  104. return AkEvent->PostOnActorAndWait(Actor, bStopWhenAttachedToDestroyed, LatentInfo);
  105. }
  106. void UAkGameplayStatics::PostAndWaitForEndOfEventAsync(
  107. class UAkAudioEvent* AkEvent,
  108. class AActor* Actor,
  109. int32& PlayingID,
  110. bool bStopWhenAttachedToDestroyed,
  111. FLatentActionInfo LatentInfo
  112. )
  113. {
  114. if (!AkEvent)
  115. {
  116. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::PostAndWaitForEndOfEventAsync: No Event specified!"));
  117. PlayingID = AK_INVALID_PLAYING_ID;
  118. return;
  119. }
  120. if (!Actor)
  121. {
  122. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::PostAndWaitForEndOfEventAsync: NULL Actor specified!"));
  123. PlayingID = AK_INVALID_PLAYING_ID;
  124. return;
  125. }
  126. AkDeviceAndWorld DeviceAndWorld(Actor);
  127. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  128. {
  129. PlayingID = AK_INVALID_PLAYING_ID;
  130. }
  131. FLatentActionManager& LatentActionManager = DeviceAndWorld.CurrentWorld->GetLatentActionManager();
  132. FWaitEndOfEventAsyncAction* NewAction = LatentActionManager.FindExistingAction<FWaitEndOfEventAsyncAction>(LatentInfo.CallbackTarget, LatentInfo.UUID);
  133. if (!NewAction)
  134. {
  135. NewAction = new FWaitEndOfEventAsyncAction(LatentInfo, &PlayingID, AkEvent, bStopWhenAttachedToDestroyed);
  136. LatentActionManager.AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, NewAction);
  137. NewAction->FuturePlayingID = DeviceAndWorld.AkAudioDevice->PostAkAudioEventWithLatentActionOnActorAsync(AkEvent, Actor, bStopWhenAttachedToDestroyed, NewAction);
  138. }
  139. }
  140. void UAkGameplayStatics::PostEventByName(const FString& EventName, class AActor* Actor, bool bStopWhenAttachedToDestroyed)
  141. {
  142. AkDeviceAndWorld DeviceAndWorld(Actor);
  143. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  144. {
  145. return;
  146. }
  147. AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(nullptr, EventName);
  148. DeviceAndWorld.AkAudioDevice->PostEventOnActor(ShortId, Actor, 0, {}, {}, bStopWhenAttachedToDestroyed);
  149. }
  150. int32 UAkGameplayStatics::PostEventAtLocation(class UAkAudioEvent* AkEvent, FVector Location, FRotator Orientation, const FString& EventName, UObject* WorldContextObject)
  151. {
  152. if (LIKELY(IsValid(AkEvent)))
  153. {
  154. return AkEvent->PostAtLocation(Location, Orientation, {}, 0, WorldContextObject);
  155. }
  156. AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
  157. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  158. return AK_INVALID_PLAYING_ID;
  159. AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(nullptr, EventName);
  160. return DeviceAndWorld.AkAudioDevice->PostEventAtLocation(EventName, ShortId, Location, Orientation, DeviceAndWorld.CurrentWorld);
  161. }
  162. void UAkGameplayStatics::PostEventAtLocationByName(const FString& EventName, FVector Location, FRotator Orientation, UObject* WorldContextObject)
  163. {
  164. AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
  165. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  166. return;
  167. AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(nullptr, EventName);
  168. DeviceAndWorld.AkAudioDevice->PostEventAtLocation(EventName, ShortId, Location, Orientation, DeviceAndWorld.CurrentWorld);
  169. }
  170. UAkComponent* UAkGameplayStatics::SpawnAkComponentAtLocation(UObject* WorldContextObject, class UAkAudioEvent* AkEvent, FVector Location, FRotator Orientation, bool AutoPost, const FString& EventName, bool AutoDestroy /* = true*/)
  171. {
  172. AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
  173. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  174. {
  175. return nullptr;
  176. }
  177. return DeviceAndWorld.AkAudioDevice->SpawnAkComponentAtLocation(AkEvent, Location, Orientation, AutoPost, EventName, AutoDestroy, DeviceAndWorld.CurrentWorld);
  178. }
  179. void UAkGameplayStatics::ExecuteActionOnEvent(class UAkAudioEvent* AkEvent, AkActionOnEventType ActionType, class AActor* Actor, int32 TransitionDuration, EAkCurveInterpolation FadeCurve, int32 PlayingID)
  180. {
  181. if (!AkEvent)
  182. {
  183. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ExecuteActionOnEvent: No Event specified!"));
  184. return;
  185. }
  186. AkEvent->ExecuteAction(ActionType, Actor, PlayingID, TransitionDuration, FadeCurve);
  187. }
  188. void UAkGameplayStatics::ExecuteActionOnPlayingID(AkActionOnEventType ActionType, int32 PlayingID, int32 TransitionDuration, EAkCurveInterpolation FadeCurve)
  189. {
  190. if (PlayingID == AK_INVALID_PLAYING_ID)
  191. {
  192. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ExecuteActionOnPlayingID: Invalid Playing ID!"));
  193. return;
  194. }
  195. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  196. if (AudioDevice)
  197. {
  198. AudioDevice->ExecuteActionOnPlayingID(ActionType, PlayingID, TransitionDuration, FadeCurve);
  199. }
  200. }
  201. void UAkGameplayStatics::SetRTPCValue(const UAkRtpc* RTPCValue, float Value, int32 InterpolationTimeMs, AActor* Actor, FName RTPC)
  202. {
  203. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  204. if (AudioDevice)
  205. {
  206. if (RTPCValue)
  207. {
  208. AudioDevice->SetRTPCValue(RTPCValue, Value, InterpolationTimeMs, Actor);
  209. }
  210. else if (RTPC.IsValid())
  211. {
  212. AudioDevice->SetRTPCValue(*RTPC.ToString(), Value, InterpolationTimeMs, Actor);
  213. }
  214. }
  215. }
  216. void UAkGameplayStatics::GetRTPCValue(const UAkRtpc* RTPCValue, int32 PlayingID, ERTPCValueType InputValueType, float& Value, ERTPCValueType& OutputValueType, AActor* Actor, FName RTPC)
  217. {
  218. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  219. if (AudioDevice)
  220. {
  221. AK::SoundEngine::Query::RTPCValue_type RTPCType = (AK::SoundEngine::Query::RTPCValue_type)InputValueType;
  222. AkGameObjectID IdToGet = AK_INVALID_GAME_OBJECT;
  223. if (Actor != nullptr)
  224. {
  225. UAkComponent * ComponentToGet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
  226. IdToGet = ComponentToGet->GetAkGameObjectID();
  227. }
  228. if (RTPCValue)
  229. {
  230. AudioDevice->GetRTPCValue(RTPCValue, IdToGet, PlayingID, Value, RTPCType);
  231. }
  232. else if (RTPC.IsValid())
  233. {
  234. AudioDevice->GetRTPCValue(*RTPC.ToString(), IdToGet, PlayingID, Value, RTPCType);
  235. }
  236. OutputValueType = (ERTPCValueType)RTPCType;
  237. }
  238. }
  239. void UAkGameplayStatics::ResetRTPCValue(UAkRtpc const* RTPCValue, int32 InterpolationTimeMs, AActor* Actor, FName RTPC)
  240. {
  241. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  242. if (AudioDevice)
  243. {
  244. AkGameObjectID IdToGet = AK_INVALID_GAME_OBJECT;
  245. if (Actor != nullptr)
  246. {
  247. UAkComponent* ComponentToGet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
  248. IdToGet = ComponentToGet->GetAkGameObjectID();
  249. }
  250. if (RTPCValue == NULL && RTPC.IsNone())
  251. {
  252. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: No parameter specified!"));
  253. return;
  254. }
  255. AKRESULT Result = AK_Success;
  256. if (RTPCValue)
  257. {
  258. Result = AudioDevice->ResetRTPCValue(RTPCValue, IdToGet, InterpolationTimeMs);
  259. }
  260. else if (RTPC.IsValid())
  261. {
  262. Result = AudioDevice->ResetRTPCValue(*RTPC.ToString(), IdToGet, InterpolationTimeMs);
  263. }
  264. else
  265. {
  266. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: Could not reset RTPC value, valid RTPC value not provided"));
  267. }
  268. if (Result == AK_IDNotFound)
  269. {
  270. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: Could not reset RTPC value, RTPC %s not found"), *RTPC.ToString());
  271. }
  272. else if (Result != AK_Success)
  273. {
  274. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: Could not reset RTPC value!"));
  275. }
  276. }
  277. }
  278. void UAkGameplayStatics::SetState(const UAkStateValue* StateValue, FName stateGroup, FName state)
  279. {
  280. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  281. if( AudioDevice && stateGroup.IsValid() && state.IsValid() )
  282. {
  283. if (StateValue)
  284. {
  285. AudioDevice->SetState(StateValue);
  286. }
  287. else if (stateGroup.IsValid() && state.IsValid())
  288. {
  289. AudioDevice->SetState(*stateGroup.ToString(), *state.ToString());
  290. }
  291. }
  292. }
  293. void UAkGameplayStatics::PostTrigger(const UAkTrigger* TriggerValue, AActor* Actor, FName Trigger)
  294. {
  295. if ( Actor == NULL )
  296. {
  297. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::PostTrigger: NULL Actor specified!"));
  298. return;
  299. }
  300. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  301. if( AudioDevice)
  302. {
  303. if (TriggerValue)
  304. {
  305. AudioDevice->PostTrigger(TriggerValue, Actor);
  306. }
  307. else if (Trigger.IsValid())
  308. {
  309. AudioDevice->PostTrigger(*Trigger.ToString(), Actor);
  310. }
  311. }
  312. }
  313. void UAkGameplayStatics::SetSwitch(const UAkSwitchValue* SwitchValue, AActor* Actor, FName SwitchGroup, FName SwitchState)
  314. {
  315. if (Actor == NULL)
  316. {
  317. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetSwitch: NULL Actor specified!"));
  318. return;
  319. }
  320. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  321. if (AudioDevice)
  322. {
  323. if (SwitchValue)
  324. {
  325. AudioDevice->SetSwitch(SwitchValue, Actor);
  326. }
  327. else if (SwitchGroup.IsValid() && SwitchState.IsValid())
  328. {
  329. AudioDevice->SetSwitch(*SwitchGroup.ToString(), *SwitchState.ToString(), Actor);
  330. }
  331. }
  332. }
  333. void UAkGameplayStatics::SetMultiplePositions(UAkComponent* GameObjectAkComponent, TArray<FTransform> Positions,
  334. AkMultiPositionType MultiPositionType /*= AkMultiPositionType::MultiPositionType_MultiDirections*/)
  335. {
  336. if (GameObjectAkComponent == NULL)
  337. {
  338. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetMultiplePositions: NULL Component specified!"));
  339. return;
  340. }
  341. FAkAudioDevice * pAudioDevice = FAkAudioDevice::Get();
  342. if (pAudioDevice)
  343. {
  344. pAudioDevice->SetMultiplePositions(GameObjectAkComponent, Positions, MultiPositionType);
  345. }
  346. }
  347. void UAkGameplayStatics::SetMultipleChannelEmitterPositions(UAkComponent* GameObjectAkComponent,
  348. TArray<AkChannelConfiguration> ChannelMasks,
  349. TArray<FTransform> Positions,
  350. AkMultiPositionType MultiPositionType
  351. )
  352. {
  353. if (GameObjectAkComponent == NULL)
  354. {
  355. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetMultipleChannelEmitterPositions: NULL Component specified!"));
  356. return;
  357. }
  358. FAkAudioDevice * pAudioDevice = FAkAudioDevice::Get();
  359. if (pAudioDevice)
  360. {
  361. pAudioDevice->SetMultiplePositions(GameObjectAkComponent, ChannelMasks, Positions, MultiPositionType);
  362. }
  363. }
  364. void UAkGameplayStatics::SetMultipleChannelMaskEmitterPositions(UAkComponent* GameObjectAkComponent,
  365. TArray<FAkChannelMask> ChannelMasks,
  366. TArray<FTransform> Positions,
  367. AkMultiPositionType MultiPositionType
  368. )
  369. {
  370. if (GameObjectAkComponent == NULL)
  371. {
  372. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetMultipleChannelMaskEmitterPositions: NULL Component specified!"));
  373. return;
  374. }
  375. FAkAudioDevice * pAudioDevice = FAkAudioDevice::Get();
  376. if (pAudioDevice)
  377. {
  378. pAudioDevice->SetMultiplePositions(GameObjectAkComponent, ChannelMasks, Positions, MultiPositionType);
  379. }
  380. }
  381. void UAkGameplayStatics::UseReverbVolumes(bool inUseReverbVolumes, class AActor* Actor )
  382. {
  383. if ( Actor == NULL )
  384. {
  385. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::UseReverbVolumes: NULL Actor specified!"));
  386. return;
  387. }
  388. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  389. if( AudioDevice )
  390. {
  391. UAkComponent * ComponentToSet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
  392. if( ComponentToSet != NULL )
  393. {
  394. ComponentToSet->UseReverbVolumes(inUseReverbVolumes);
  395. }
  396. }
  397. }
  398. void UAkGameplayStatics::UseEarlyReflections(class AActor* Actor,
  399. class UAkAuxBus* AuxBus,
  400. int Order,
  401. float BusSendGain,
  402. float MaxPathLength,
  403. bool SpotReflectors,
  404. const FString& AuxBusName)
  405. {
  406. // Deprecated
  407. }
  408. void UAkGameplayStatics::SetReflectionsOrder(int Order, bool RefreshPaths)
  409. {
  410. if (Order > 4 || Order < 0)
  411. {
  412. Order = FMath::Clamp(Order, 0, 4);
  413. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetReflectionsOrder: The order value is invalid. It was clamped to %d"), Order);
  414. }
  415. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  416. if (AudioDevice)
  417. {
  418. AudioDevice->SetReflectionsOrder(Order, RefreshPaths);
  419. }
  420. }
  421. void UAkGameplayStatics::SetPortalObstructionAndOcclusion(UAkPortalComponent* PortalComponent, float ObstructionValue, float OcclusionValue)
  422. {
  423. if (ObstructionValue > 1.f || ObstructionValue < 0.f)
  424. {
  425. ObstructionValue = FMath::Clamp(ObstructionValue, 0.f, 1.f);
  426. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetPortalObstructionAndOcclusion: The obstruction value is invalid. It was clamped to %f"), ObstructionValue);
  427. }
  428. if (OcclusionValue > 1.f || OcclusionValue < 0.f)
  429. {
  430. OcclusionValue = FMath::Clamp(OcclusionValue, 0.f, 1.f);
  431. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetPortalObstructionAndOcclusion: The occlusion value is invalid. It was clamped to %f"), OcclusionValue);
  432. }
  433. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  434. if (AudioDevice)
  435. {
  436. AudioDevice->SetPortalObstructionAndOcclusion(PortalComponent, ObstructionValue, OcclusionValue);
  437. }
  438. }
  439. void UAkGameplayStatics::SetGameObjectToPortalObstruction(UAkComponent* GameObjectAkComponent, UAkPortalComponent* PortalComponent, float ObstructionValue)
  440. {
  441. if (ObstructionValue > 1.f || ObstructionValue < 0.f)
  442. {
  443. ObstructionValue = FMath::Clamp(ObstructionValue, 0.f, 1.f);
  444. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetGameObjectToPortalObstruction: The obstruction value is invalid. It was clamped to %f"), ObstructionValue);
  445. }
  446. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  447. if (AudioDevice)
  448. {
  449. AudioDevice->SetGameObjectToPortalObstruction(GameObjectAkComponent, PortalComponent, ObstructionValue);
  450. }
  451. }
  452. void UAkGameplayStatics::SetPortalToPortalObstruction(UAkPortalComponent* PortalComponent0, UAkPortalComponent* PortalComponent1, float ObstructionValue)
  453. {
  454. if (ObstructionValue > 1.f || ObstructionValue < 0.f)
  455. {
  456. ObstructionValue = FMath::Clamp(ObstructionValue, 0.f, 1.f);
  457. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetGameObjectToPortalObstruction: The obstruction value is invalid. It was clamped to %f"), ObstructionValue);
  458. }
  459. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  460. if (AudioDevice)
  461. {
  462. AudioDevice->SetPortalToPortalObstruction(PortalComponent0, PortalComponent1, ObstructionValue);
  463. }
  464. }
  465. void UAkGameplayStatics::SetOutputBusVolume(float BusVolume, class AActor* Actor)
  466. {
  467. if (Actor == NULL)
  468. {
  469. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOutputBusVolume: NULL Actor specified!"));
  470. return;
  471. }
  472. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  473. if (AudioDevice)
  474. {
  475. UAkComponent * ComponentToSet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
  476. if (ComponentToSet != NULL)
  477. {
  478. ComponentToSet->SetOutputBusVolume(BusVolume);
  479. }
  480. }
  481. }
  482. void UAkGameplayStatics::SetBusConfig(const FString& BusName, AkChannelConfiguration ChannelConfiguration)
  483. {
  484. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  485. if (UNLIKELY(!AudioDevice))
  486. {
  487. return;
  488. }
  489. AkChannelConfig config;
  490. FAkAudioDevice::GetChannelConfig(ChannelConfiguration, config);
  491. AudioDevice->SetBusConfig(BusName, config);
  492. }
  493. void UAkGameplayStatics::SetPanningRule(PanningRule PanRule)
  494. {
  495. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  496. if (UNLIKELY(!AudioDevice))
  497. {
  498. return;
  499. }
  500. AkPanningRule AkPanRule = (PanRule == PanningRule::PanningRule_Headphones) ? AkPanningRule_Headphones : AkPanningRule_Speakers;
  501. AudioDevice->SetPanningRule(AkPanRule);
  502. }
  503. void UAkGameplayStatics::AddOutput(const FAkOutputSettings& in_Settings, FAkOutputDeviceID& out_DeviceID, UPARAM(ref) TArray<UAkComponent*>& in_ListenerIDs)
  504. {
  505. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  506. if (UNLIKELY(!SoundEngine))
  507. {
  508. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::AddOutput: SoundEngine not initialized, new output will not be added."));
  509. return;
  510. }
  511. AkUInt32 ShortID = SoundEngine->GetIDFromString(TCHAR_TO_ANSI(*in_Settings.AudioDeviceShareSetName));
  512. if (UNLIKELY(ShortID == AK_INVALID_UNIQUE_ID))
  513. {
  514. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::AddOutput: Short ID for %s is invalid, new output will not be added."));
  515. return;
  516. }
  517. AkOutputSettings OutSettings;
  518. OutSettings.audioDeviceShareset = ShortID;
  519. OutSettings.idDevice = in_Settings.IdDevice;
  520. OutSettings.ePanningRule = (in_Settings.PanRule == PanningRule::PanningRule_Headphones) ? AkPanningRule_Headphones : AkPanningRule_Speakers;
  521. FAkAudioDevice::GetChannelConfig(in_Settings.ChannelConfig, OutSettings.channelConfig);
  522. AkOutputDeviceID outputDeviceID;
  523. AKRESULT result = AK_Fail;
  524. if (in_ListenerIDs.Num() > 0)
  525. {
  526. result = SoundEngine->AddOutput(OutSettings, &outputDeviceID);
  527. }
  528. else
  529. {
  530. TArray<AkGameObjectID> akGameObjectIDArray;
  531. for (int i = 0; i < in_ListenerIDs.Num(); i++)
  532. {
  533. akGameObjectIDArray.Add(in_ListenerIDs[i]->GetAkGameObjectID());
  534. }
  535. result = SoundEngine->AddOutput(OutSettings, &outputDeviceID, akGameObjectIDArray.GetData(), akGameObjectIDArray.Num());
  536. }
  537. if (result != AK_Success)
  538. {
  539. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::AddOutput: AddOuput has failed, new output will not be added. AkResult: %s"), result);
  540. }
  541. out_DeviceID.UInt64Value = outputDeviceID;
  542. }
  543. void UAkGameplayStatics::RemoveOutput(FAkOutputDeviceID in_OutputDeviceId)
  544. {
  545. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  546. if (UNLIKELY(!SoundEngine))
  547. {
  548. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::RemoveOutput: Could not fetch audio device, output will not be removed."));
  549. return;
  550. }
  551. SoundEngine->RemoveOutput(in_OutputDeviceId.UInt64Value);
  552. }
  553. void UAkGameplayStatics::ReplaceMainOutput(const FAkOutputSettings& MainOutputSettings)
  554. {
  555. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  556. if (UNLIKELY(!AudioDevice))
  557. {
  558. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ReplaceMainOutput: Could not fetch audio device, main output will not be replaced."));
  559. return;
  560. }
  561. AkUInt32 ShortID = AudioDevice->GetShortIDFromString(MainOutputSettings.AudioDeviceShareSetName);
  562. if (UNLIKELY(ShortID == AK_INVALID_UNIQUE_ID))
  563. {
  564. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ReplaceMainOutput: Short ID for %s is invalid, main output will not be replaced."));
  565. return;
  566. }
  567. AkOutputSettings OutSettings;
  568. OutSettings.audioDeviceShareset = ShortID;
  569. OutSettings.idDevice = MainOutputSettings.IdDevice;
  570. OutSettings.ePanningRule = (MainOutputSettings.PanRule == PanningRule::PanningRule_Headphones) ? AkPanningRule_Headphones : AkPanningRule_Speakers;
  571. FAkAudioDevice::GetChannelConfig(MainOutputSettings.ChannelConfig, OutSettings.channelConfig);
  572. AudioDevice->ReplaceMainOutput(OutSettings);
  573. }
  574. void UAkGameplayStatics::GetSpeakerAngles(TArray<float>& SpeakerAngles, float& HeightAngle, const FString& DeviceShareSet)
  575. {
  576. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  577. if (UNLIKELY(!AudioDevice))
  578. {
  579. return;
  580. }
  581. AkOutputDeviceID DeviceID = DeviceShareSet.IsEmpty() ? 0 : AudioDevice->GetOutputID(DeviceShareSet);
  582. AudioDevice->GetSpeakerAngles(SpeakerAngles, HeightAngle, DeviceID);
  583. }
  584. void UAkGameplayStatics::SetSpeakerAngles(const TArray<float>& SpeakerAngles, float HeightAngles, const FString& DeviceShareSet)
  585. {
  586. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  587. if (UNLIKELY(!AudioDevice))
  588. {
  589. return;
  590. }
  591. AkOutputDeviceID DeviceID = DeviceShareSet.IsEmpty() ? 0 : AudioDevice->GetOutputID(DeviceShareSet);
  592. AudioDevice->SetSpeakerAngles(SpeakerAngles, HeightAngles, DeviceID);
  593. }
  594. void UAkGameplayStatics::SetOcclusionRefreshInterval(float RefreshInterval, class AActor* Actor)
  595. {
  596. if (Actor == NULL)
  597. {
  598. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOcclusionRefreshInterval: NULL Actor specified!"));
  599. return;
  600. }
  601. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  602. if (UNLIKELY(!AudioDevice))
  603. {
  604. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOcclusionRefreshInterval: Could not retrieve audio device."));
  605. return;
  606. }
  607. UAkComponent* ComponentToSet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
  608. if (ComponentToSet != NULL)
  609. {
  610. ComponentToSet->OcclusionRefreshInterval = RefreshInterval;
  611. }
  612. }
  613. void UAkGameplayStatics::StopActor(class AActor* Actor)
  614. {
  615. if ( Actor == NULL )
  616. {
  617. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::StopActor: NULL Actor specified!"));
  618. return;
  619. }
  620. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  621. if (UNLIKELY(!AudioDevice))
  622. {
  623. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::StopActor: Could not retrieve audio device."));
  624. return;
  625. }
  626. AudioDevice->StopGameObject(AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset));
  627. }
  628. void UAkGameplayStatics::StopAll()
  629. {
  630. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  631. if (UNLIKELY(!AudioDevice))
  632. {
  633. return;
  634. }
  635. AudioDevice->StopAllSounds();
  636. }
  637. void UAkGameplayStatics::CancelEventCallback(const FOnAkPostEventCallback& PostEventCallback)
  638. {
  639. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  640. if (UNLIKELY(!AudioDevice))
  641. {
  642. return;
  643. }
  644. AudioDevice->CancelEventCallbackDelegate(PostEventCallback);
  645. }
  646. void UAkGameplayStatics::StartAllAmbientSounds(UObject* WorldContextObject)
  647. {
  648. AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
  649. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  650. {
  651. return;
  652. }
  653. for (FActorIterator It(DeviceAndWorld.CurrentWorld); It; ++It)
  654. {
  655. AAkAmbientSound* pAmbientSound = Cast<AAkAmbientSound>(*It);
  656. if (pAmbientSound != NULL)
  657. {
  658. UAkComponent* pComponent = pAmbientSound->AkComponent;
  659. if (pComponent && GWorld->Scene == pComponent->GetScene())
  660. {
  661. pAmbientSound->StartPlaying();
  662. }
  663. }
  664. }
  665. }
  666. void UAkGameplayStatics::StopAllAmbientSounds(UObject* WorldContextObject)
  667. {
  668. AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
  669. if (UNLIKELY(!DeviceAndWorld.IsValid()))
  670. {
  671. return;
  672. }
  673. for (FActorIterator It(DeviceAndWorld.CurrentWorld); It; ++It)
  674. {
  675. AAkAmbientSound* pAmbientSound = Cast<AAkAmbientSound>(*It);
  676. if (pAmbientSound != NULL)
  677. {
  678. UAkComponent* pComponent = pAmbientSound->AkComponent;
  679. if (pComponent && GWorld->Scene == pComponent->GetScene())
  680. {
  681. pAmbientSound->StopPlaying();
  682. }
  683. }
  684. }
  685. }
  686. void UAkGameplayStatics::ClearSoundBanksAndMedia()
  687. {
  688. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  689. if (UNLIKELY(!AudioDevice))
  690. {
  691. return;
  692. }
  693. AudioDevice->ClearSoundBanksAndMedia();
  694. }
  695. void UAkGameplayStatics::ClearBanks()
  696. {
  697. ClearSoundBanksAndMedia();
  698. }
  699. void UAkGameplayStatics::LoadInitBank()
  700. {
  701. auto* InitBankLoader = FWwiseInitBankLoader::Get();
  702. if(UNLIKELY(!InitBankLoader))
  703. {
  704. UE_LOG(LogAkAudio, Error, TEXT("LoadInitBank: WwiseInitBankLoader is not initialized."));
  705. return;
  706. }
  707. InitBankLoader->LoadInitBank();
  708. }
  709. void UAkGameplayStatics::UnloadInitBank()
  710. {
  711. auto* InitBankLoader = FWwiseInitBankLoader::Get();
  712. if(UNLIKELY(!InitBankLoader))
  713. {
  714. UE_LOG(LogAkAudio, Error, TEXT("UnloadInitBank: WwiseInitBankLoader is not initialized."));
  715. return;
  716. }
  717. InitBankLoader->UnloadInitBank();
  718. }
  719. void UAkGameplayStatics::LoadBankByName(const FString& BankName)
  720. {
  721. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  722. if (UNLIKELY(!AudioDevice))
  723. {
  724. return;
  725. }
  726. AkBankID BankId;
  727. AudioDevice->LoadBank(BankName, BankId);
  728. }
  729. void UAkGameplayStatics::UnloadBankByName(const FString& BankName)
  730. {
  731. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  732. if (UNLIKELY(!AudioDevice))
  733. {
  734. return;
  735. }
  736. AudioDevice->UnloadBank(BankName);
  737. }
  738. void UAkGameplayStatics::StartOutputCapture(const FString& Filename)
  739. {
  740. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  741. if (UNLIKELY(!AudioDevice))
  742. {
  743. return;
  744. }
  745. FString name = Filename;
  746. if (!name.EndsWith(".wav"))
  747. {
  748. name += ".wav";
  749. }
  750. AudioDevice->StartOutputCapture(name);
  751. }
  752. void UAkGameplayStatics::AddOutputCaptureMarker(const FString& MarkerText)
  753. {
  754. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  755. if( AudioDevice )
  756. {
  757. AudioDevice->AddOutputCaptureMarker(MarkerText);
  758. }
  759. }
  760. void UAkGameplayStatics::StopOutputCapture()
  761. {
  762. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  763. if( AudioDevice )
  764. {
  765. AudioDevice->StopOutputCapture();
  766. }
  767. }
  768. void UAkGameplayStatics::StartProfilerCapture(const FString& Filename)
  769. {
  770. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  771. if( AudioDevice )
  772. {
  773. FString name = Filename;
  774. if( !name.EndsWith(".prof") )
  775. {
  776. name += ".prof";
  777. }
  778. AudioDevice->StartProfilerCapture(name);
  779. }
  780. }
  781. void UAkGameplayStatics::StopProfilerCapture()
  782. {
  783. FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
  784. if( AudioDevice )
  785. {
  786. AudioDevice->StopProfilerCapture();
  787. }
  788. }
  789. FString UAkGameplayStatics::GetCurrentAudioCulture()
  790. {
  791. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  792. if (AudioDevice)
  793. {
  794. return AudioDevice->GetCurrentAudioCulture();
  795. }
  796. return FString();
  797. }
  798. TArray<FString> UAkGameplayStatics::GetAvailableAudioCultures()
  799. {
  800. FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
  801. if (AudioDevice)
  802. {
  803. return AudioDevice->GetAvailableAudioCultures();
  804. }
  805. return TArray<FString>();
  806. }
  807. void UAkGameplayStatics::SetCurrentAudioCulture(const FString& AudioCulture, FLatentActionInfo LatentInfo, UObject* WorldContextObject)
  808. {
  809. AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
  810. FLatentActionManager& LatentActionManager = DeviceAndWorld.CurrentWorld->GetLatentActionManager();
  811. FSetCurrentAudioCultureAction* NewAction = LatentActionManager.FindExistingAction<FSetCurrentAudioCultureAction>(LatentInfo.CallbackTarget, LatentInfo.UUID);
  812. if (!NewAction)
  813. {
  814. NewAction = new FSetCurrentAudioCultureAction(LatentInfo);
  815. LatentActionManager.AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, NewAction);
  816. }
  817. if (FAkAudioDevice* AudioDevice = FAkAudioDevice::Get())
  818. {
  819. AudioDevice->SetCurrentAudioCultureAsync(AudioCulture, NewAction);
  820. }
  821. else
  822. {
  823. NewAction->ActionDone = true;
  824. }
  825. }
  826. void UAkGameplayStatics::SetCurrentAudioCultureAsync(const FString& AudioCulture, const FOnSetCurrentAudioCultureCallback& Completed)
  827. {
  828. if (FAkAudioDevice* AudioDevice = FAkAudioDevice::Get())
  829. {
  830. AudioDevice->SetCurrentAudioCultureAsync(AudioCulture, FOnSetCurrentAudioCultureCompleted::CreateLambda([Completed](bool Succeeded) {
  831. Completed.ExecuteIfBound(Succeeded);
  832. }));
  833. }
  834. }
  835. UObject* UAkGameplayStatics::GetAkAudioTypeUserData(const UAkAudioType* Instance, const UClass* Type)
  836. {
  837. for (auto entry : Instance->UserData)
  838. {
  839. if (entry && entry->GetClass()->IsChildOf(Type))
  840. {
  841. return entry;
  842. }
  843. }
  844. return nullptr;
  845. }
  846. void UAkGameplayStatics::SetDistanceProbe(AActor* Listener, AActor* DistanceProbe)
  847. {
  848. if (Listener == nullptr)
  849. {
  850. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetDistanceProbe: NULL Listener specified!"));
  851. return;
  852. }
  853. if (FAkAudioDevice* AudioDevice = FAkAudioDevice::Get())
  854. {
  855. UAkComponent * ListenerAkComponent = AudioDevice->GetAkComponent(Listener->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
  856. UAkComponent* DistanceProbeAkComponent =
  857. DistanceProbe != nullptr ?
  858. AudioDevice->GetAkComponent(DistanceProbe->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset) :
  859. nullptr;
  860. AudioDevice->SetDistanceProbe(ListenerAkComponent, DistanceProbeAkComponent);
  861. }
  862. }
  863. bool UAkGameplayStatics::SetOutputDeviceEffect(const FAkOutputDeviceID InDeviceID, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
  864. {
  865. if(UNLIKELY(!InEffectShareSet))
  866. {
  867. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOutputDeviceEffect: NULL Effect ShareSet specified!"));
  868. return false;
  869. }
  870. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  871. if (UNLIKELY(!SoundEngine)) return false;
  872. UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetOutputDeviceEffect: DeviceID: %" PRIu64 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
  873. InDeviceID.UInt64Value, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
  874. AKRESULT Result = SoundEngine->SetOutputDeviceEffect(InDeviceID.UInt64Value, InEffectIndex, InEffectShareSet->GetShortID());
  875. return Result == AK_Success;
  876. }
  877. bool UAkGameplayStatics::SetBusEffectByName(const FString InBusName, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
  878. {
  879. if(UNLIKELY(!InEffectShareSet))
  880. {
  881. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetBusEffectByName: NULL Effect ShareSet specified!"));
  882. return false;
  883. }
  884. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  885. if (UNLIKELY(!SoundEngine)) return false;
  886. UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetBusEffectByName: BusName: %s, InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
  887. *InBusName, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
  888. AKRESULT Result = SoundEngine->SetBusEffect(TCHAR_TO_AK(*InBusName), InEffectIndex, InEffectShareSet->GetShortID());
  889. return Result == AK_Success;
  890. }
  891. bool UAkGameplayStatics::SetBusEffectByID(const FAkUniqueID InBusID, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
  892. {
  893. if(UNLIKELY(!InEffectShareSet))
  894. {
  895. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetBusEffectByID: NULL Effect ShareSet specified!"));
  896. return false;
  897. }
  898. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  899. if (UNLIKELY(!SoundEngine)) return false;
  900. UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetBusEffectByID: BusID: %" PRIu32 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
  901. InBusID.UInt32Value, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
  902. AKRESULT Result = SoundEngine->SetBusEffect(InBusID.UInt32Value, InEffectIndex, InEffectShareSet->GetShortID());
  903. return Result == AK_Success;
  904. }
  905. bool UAkGameplayStatics::SetAuxBusEffect(const UAkAuxBus* InAuxBus, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
  906. {
  907. if(UNLIKELY(!InEffectShareSet))
  908. {
  909. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetAuxBusEffect: NULL Effect ShareSet specified!"));
  910. return false;
  911. }
  912. if(UNLIKELY(!InAuxBus))
  913. {
  914. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetAuxBusEffect: NULL Aux Bus specified!"));
  915. return false;
  916. }
  917. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  918. if (UNLIKELY(!SoundEngine)) return false;
  919. UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetAuxBusEffect: AuxBus Asset Name: %s, AuxBus Short ID: %" PRIu32 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
  920. *InAuxBus->GetName(), InAuxBus->GetShortID(), InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
  921. AKRESULT Result = SoundEngine->SetBusEffect(InAuxBus->GetShortID(), InEffectIndex, InEffectShareSet->GetShortID());
  922. return Result == AK_Success;
  923. }
  924. bool UAkGameplayStatics::SetActorMixerEffect(const FAkUniqueID InAudioNodeID,const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
  925. {
  926. if(UNLIKELY(!InEffectShareSet))
  927. {
  928. UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetActorMixerEffect: NULL Effect ShareSet specified!"));
  929. return false;
  930. }
  931. auto* SoundEngine = IWwiseSoundEngineAPI::Get();
  932. if (UNLIKELY(!SoundEngine)) return false;
  933. UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetActorMixerEffect: AudioNodeID: %" PRIu32 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
  934. InAudioNodeID.UInt32Value, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
  935. AKRESULT Result = SoundEngine->SetActorMixerEffect(InAudioNodeID.UInt32Value, InEffectIndex, InEffectShareSet->GetShortID());
  936. return Result == AK_Success;
  937. }