1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078 |
- /*******************************************************************************
- The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
- Technology released in source code form as part of the game integration package.
- The content of this file may not be used without valid licenses to the
- AUDIOKINETIC Wwise Technology.
- Note that the use of the game engine is subject to the Unreal(R) Engine End User
- License Agreement at https://www.unrealengine.com/en-US/eula/unreal
-
- License Usage
-
- Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
- this file in accordance with the end user license agreement provided with the
- software or, alternatively, in accordance with the terms contained
- in a written agreement between you and Audiokinetic Inc.
- Copyright (c) 2023 Audiokinetic Inc.
- *******************************************************************************/
- /*=============================================================================
- AkAudioClasses.cpp:
- =============================================================================*/
- #include "AkGameplayStatics.h"
- #include "AkAmbientSound.h"
- #include "AkAudioDevice.h"
- #include "AkAudioEvent.h"
- #include "AkAudioType.h"
- #include "AkComponent.h"
- #include "AkEffectShareSet.h"
- #include "AkRtpc.h"
- #include "AkStateValue.h"
- #include "AkSwitchValue.h"
- #include "AkTrigger.h"
- #include "Engine/GameEngine.h"
- #include "EngineUtils.h"
- #include "AkAcousticPortal.h"
- #include "AkAuxBus.h"
- #include "Wwise/API/WwiseSoundEngineAPI.h"
- #include "Wwise/WwiseExternalSourceManager.h"
- #include "inttypes.h"
- #include "WwiseInitBankLoader/WwiseInitBankLoader.h"
- bool UAkGameplayStatics::m_bSoundEngineRecording = false;
- /*-----------------------------------------------------------------------------
- UAkGameplayStatics.
- -----------------------------------------------------------------------------*/
- UAkGameplayStatics::UAkGameplayStatics(const class FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- // Property initialization
- }
- class UAkComponent * UAkGameplayStatics::GetAkComponent( class USceneComponent* AttachToComponent, bool& ComponentCreated, FName AttachPointName, FVector Location, EAttachLocation::Type LocationType )
- {
- if ( AttachToComponent == NULL )
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::GetAkComponent: NULL AttachToComponent specified!"));
- return NULL;
- }
- FAkAudioDevice * AkAudioDevice = FAkAudioDevice::Get();
- if( AkAudioDevice )
- {
- return AkAudioDevice->GetAkComponent( AttachToComponent, AttachPointName, &Location, LocationType, ComponentCreated );
- }
- return NULL;
- }
- bool UAkGameplayStatics::IsEditor()
- {
- #if WITH_EDITOR
- return true;
- #else
- return false;
- #endif
- }
- bool UAkGameplayStatics::IsGame(UObject* WorldContextObject)
- {
- EWorldType::Type WorldType = EWorldType::None;
- if (WorldContextObject)
- {
- UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull);
- if(World)
- WorldType = World->WorldType;
- }
- return WorldType == EWorldType::Game || WorldType == EWorldType::GamePreview || WorldType == EWorldType::PIE;
- }
- int32 UAkGameplayStatics::PostEvent(UAkAudioEvent* AkEvent, AActor* Actor, int32 CallbackMask,
- const FOnAkPostEventCallback& PostEventCallback, bool bStopWhenAttachedToDestroyed,
- FString EventName)
- {
- if (LIKELY(IsValid(AkEvent)))
- {
- return AkEvent->PostOnActor(Actor, PostEventCallback, CallbackMask, bStopWhenAttachedToDestroyed);
- }
- AkDeviceAndWorld DeviceAndWorld(Actor);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- {
- return AK_INVALID_PLAYING_ID;
- }
-
- AkCallbackType AkCallbackMask = AkCallbackTypeHelpers::GetCallbackMaskFromBlueprintMask(CallbackMask);
- AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(AkEvent, EventName);
- return DeviceAndWorld.AkAudioDevice->PostEventOnActor(ShortId, Actor, PostEventCallback, AkCallbackMask, bStopWhenAttachedToDestroyed, {});
- }
- int32 UAkGameplayStatics::PostAndWaitForEndOfEvent(UAkAudioEvent* AkEvent, AActor* Actor, bool bStopWhenAttachedToDestroyed,
- FLatentActionInfo LatentInfo)
- {
- if (UNLIKELY(!IsValid(AkEvent)))
- {
- UE_LOG(LogAkAudio, Error, TEXT("Failed to post and wait invalid AkAudioEvent on actor '%s'."), IsValid(Actor) ? *Actor->GetName() : TEXT("(invalid)"));
- return AK_INVALID_PLAYING_ID;
- }
- return AkEvent->PostOnActorAndWait(Actor, bStopWhenAttachedToDestroyed, LatentInfo);
- }
- void UAkGameplayStatics::PostAndWaitForEndOfEventAsync(
- class UAkAudioEvent* AkEvent,
- class AActor* Actor,
- int32& PlayingID,
- bool bStopWhenAttachedToDestroyed,
- FLatentActionInfo LatentInfo
- )
- {
- if (!AkEvent)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::PostAndWaitForEndOfEventAsync: No Event specified!"));
- PlayingID = AK_INVALID_PLAYING_ID;
- return;
- }
- if (!Actor)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::PostAndWaitForEndOfEventAsync: NULL Actor specified!"));
- PlayingID = AK_INVALID_PLAYING_ID;
- return;
- }
- AkDeviceAndWorld DeviceAndWorld(Actor);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- {
- PlayingID = AK_INVALID_PLAYING_ID;
- }
- FLatentActionManager& LatentActionManager = DeviceAndWorld.CurrentWorld->GetLatentActionManager();
- FWaitEndOfEventAsyncAction* NewAction = LatentActionManager.FindExistingAction<FWaitEndOfEventAsyncAction>(LatentInfo.CallbackTarget, LatentInfo.UUID);
- if (!NewAction)
- {
- NewAction = new FWaitEndOfEventAsyncAction(LatentInfo, &PlayingID, AkEvent, bStopWhenAttachedToDestroyed);
- LatentActionManager.AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, NewAction);
- NewAction->FuturePlayingID = DeviceAndWorld.AkAudioDevice->PostAkAudioEventWithLatentActionOnActorAsync(AkEvent, Actor, bStopWhenAttachedToDestroyed, NewAction);
- }
- }
- void UAkGameplayStatics::PostEventByName(const FString& EventName, class AActor* Actor, bool bStopWhenAttachedToDestroyed)
- {
- AkDeviceAndWorld DeviceAndWorld(Actor);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- {
- return;
- }
- AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(nullptr, EventName);
- DeviceAndWorld.AkAudioDevice->PostEventOnActor(ShortId, Actor, 0, {}, {}, bStopWhenAttachedToDestroyed);
- }
- int32 UAkGameplayStatics::PostEventAtLocation(class UAkAudioEvent* AkEvent, FVector Location, FRotator Orientation, const FString& EventName, UObject* WorldContextObject)
- {
- if (LIKELY(IsValid(AkEvent)))
- {
- return AkEvent->PostAtLocation(Location, Orientation, {}, 0, WorldContextObject);
- }
- AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- return AK_INVALID_PLAYING_ID;
- AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(nullptr, EventName);
- return DeviceAndWorld.AkAudioDevice->PostEventAtLocation(EventName, ShortId, Location, Orientation, DeviceAndWorld.CurrentWorld);
- }
- void UAkGameplayStatics::PostEventAtLocationByName(const FString& EventName, FVector Location, FRotator Orientation, UObject* WorldContextObject)
- {
- AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- return;
- AkUInt32 ShortId = DeviceAndWorld.AkAudioDevice->GetShortID(nullptr, EventName);
- DeviceAndWorld.AkAudioDevice->PostEventAtLocation(EventName, ShortId, Location, Orientation, DeviceAndWorld.CurrentWorld);
- }
- UAkComponent* UAkGameplayStatics::SpawnAkComponentAtLocation(UObject* WorldContextObject, class UAkAudioEvent* AkEvent, FVector Location, FRotator Orientation, bool AutoPost, const FString& EventName, bool AutoDestroy /* = true*/)
- {
- AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- {
- return nullptr;
- }
- return DeviceAndWorld.AkAudioDevice->SpawnAkComponentAtLocation(AkEvent, Location, Orientation, AutoPost, EventName, AutoDestroy, DeviceAndWorld.CurrentWorld);
- }
- void UAkGameplayStatics::ExecuteActionOnEvent(class UAkAudioEvent* AkEvent, AkActionOnEventType ActionType, class AActor* Actor, int32 TransitionDuration, EAkCurveInterpolation FadeCurve, int32 PlayingID)
- {
- if (!AkEvent)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ExecuteActionOnEvent: No Event specified!"));
- return;
- }
- AkEvent->ExecuteAction(ActionType, Actor, PlayingID, TransitionDuration, FadeCurve);
-
- }
- void UAkGameplayStatics::ExecuteActionOnPlayingID(AkActionOnEventType ActionType, int32 PlayingID, int32 TransitionDuration, EAkCurveInterpolation FadeCurve)
- {
- if (PlayingID == AK_INVALID_PLAYING_ID)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ExecuteActionOnPlayingID: Invalid Playing ID!"));
- return;
- }
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- AudioDevice->ExecuteActionOnPlayingID(ActionType, PlayingID, TransitionDuration, FadeCurve);
- }
- }
- void UAkGameplayStatics::SetRTPCValue(const UAkRtpc* RTPCValue, float Value, int32 InterpolationTimeMs, AActor* Actor, FName RTPC)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- if (RTPCValue)
- {
- AudioDevice->SetRTPCValue(RTPCValue, Value, InterpolationTimeMs, Actor);
- }
- else if (RTPC.IsValid())
- {
- AudioDevice->SetRTPCValue(*RTPC.ToString(), Value, InterpolationTimeMs, Actor);
- }
- }
- }
- void UAkGameplayStatics::GetRTPCValue(const UAkRtpc* RTPCValue, int32 PlayingID, ERTPCValueType InputValueType, float& Value, ERTPCValueType& OutputValueType, AActor* Actor, FName RTPC)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- AK::SoundEngine::Query::RTPCValue_type RTPCType = (AK::SoundEngine::Query::RTPCValue_type)InputValueType;
- AkGameObjectID IdToGet = AK_INVALID_GAME_OBJECT;
- if (Actor != nullptr)
- {
- UAkComponent * ComponentToGet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
- IdToGet = ComponentToGet->GetAkGameObjectID();
- }
- if (RTPCValue)
- {
- AudioDevice->GetRTPCValue(RTPCValue, IdToGet, PlayingID, Value, RTPCType);
- }
- else if (RTPC.IsValid())
- {
- AudioDevice->GetRTPCValue(*RTPC.ToString(), IdToGet, PlayingID, Value, RTPCType);
- }
- OutputValueType = (ERTPCValueType)RTPCType;
- }
- }
- void UAkGameplayStatics::ResetRTPCValue(UAkRtpc const* RTPCValue, int32 InterpolationTimeMs, AActor* Actor, FName RTPC)
- {
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- AkGameObjectID IdToGet = AK_INVALID_GAME_OBJECT;
- if (Actor != nullptr)
- {
- UAkComponent* ComponentToGet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
- IdToGet = ComponentToGet->GetAkGameObjectID();
- }
- if (RTPCValue == NULL && RTPC.IsNone())
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: No parameter specified!"));
- return;
- }
- AKRESULT Result = AK_Success;
- if (RTPCValue)
- {
- Result = AudioDevice->ResetRTPCValue(RTPCValue, IdToGet, InterpolationTimeMs);
- }
- else if (RTPC.IsValid())
- {
- Result = AudioDevice->ResetRTPCValue(*RTPC.ToString(), IdToGet, InterpolationTimeMs);
- }
- else
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: Could not reset RTPC value, valid RTPC value not provided"));
- }
- if (Result == AK_IDNotFound)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: Could not reset RTPC value, RTPC %s not found"), *RTPC.ToString());
- }
- else if (Result != AK_Success)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ResetRTPCValue: Could not reset RTPC value!"));
- }
- }
- }
- void UAkGameplayStatics::SetState(const UAkStateValue* StateValue, FName stateGroup, FName state)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if( AudioDevice && stateGroup.IsValid() && state.IsValid() )
- {
- if (StateValue)
- {
- AudioDevice->SetState(StateValue);
- }
- else if (stateGroup.IsValid() && state.IsValid())
- {
- AudioDevice->SetState(*stateGroup.ToString(), *state.ToString());
- }
- }
- }
- void UAkGameplayStatics::PostTrigger(const UAkTrigger* TriggerValue, AActor* Actor, FName Trigger)
- {
- if ( Actor == NULL )
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::PostTrigger: NULL Actor specified!"));
- return;
- }
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if( AudioDevice)
- {
- if (TriggerValue)
- {
- AudioDevice->PostTrigger(TriggerValue, Actor);
- }
- else if (Trigger.IsValid())
- {
- AudioDevice->PostTrigger(*Trigger.ToString(), Actor);
- }
- }
- }
- void UAkGameplayStatics::SetSwitch(const UAkSwitchValue* SwitchValue, AActor* Actor, FName SwitchGroup, FName SwitchState)
- {
- if (Actor == NULL)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetSwitch: NULL Actor specified!"));
- return;
- }
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- if (SwitchValue)
- {
- AudioDevice->SetSwitch(SwitchValue, Actor);
- }
- else if (SwitchGroup.IsValid() && SwitchState.IsValid())
- {
- AudioDevice->SetSwitch(*SwitchGroup.ToString(), *SwitchState.ToString(), Actor);
- }
- }
- }
- void UAkGameplayStatics::SetMultiplePositions(UAkComponent* GameObjectAkComponent, TArray<FTransform> Positions,
- AkMultiPositionType MultiPositionType /*= AkMultiPositionType::MultiPositionType_MultiDirections*/)
- {
- if (GameObjectAkComponent == NULL)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetMultiplePositions: NULL Component specified!"));
- return;
- }
- FAkAudioDevice * pAudioDevice = FAkAudioDevice::Get();
- if (pAudioDevice)
- {
- pAudioDevice->SetMultiplePositions(GameObjectAkComponent, Positions, MultiPositionType);
- }
- }
- void UAkGameplayStatics::SetMultipleChannelEmitterPositions(UAkComponent* GameObjectAkComponent,
- TArray<AkChannelConfiguration> ChannelMasks,
- TArray<FTransform> Positions,
- AkMultiPositionType MultiPositionType
- )
- {
- if (GameObjectAkComponent == NULL)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetMultipleChannelEmitterPositions: NULL Component specified!"));
- return;
- }
- FAkAudioDevice * pAudioDevice = FAkAudioDevice::Get();
- if (pAudioDevice)
- {
- pAudioDevice->SetMultiplePositions(GameObjectAkComponent, ChannelMasks, Positions, MultiPositionType);
- }
- }
- void UAkGameplayStatics::SetMultipleChannelMaskEmitterPositions(UAkComponent* GameObjectAkComponent,
- TArray<FAkChannelMask> ChannelMasks,
- TArray<FTransform> Positions,
- AkMultiPositionType MultiPositionType
- )
- {
- if (GameObjectAkComponent == NULL)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetMultipleChannelMaskEmitterPositions: NULL Component specified!"));
- return;
- }
- FAkAudioDevice * pAudioDevice = FAkAudioDevice::Get();
- if (pAudioDevice)
- {
- pAudioDevice->SetMultiplePositions(GameObjectAkComponent, ChannelMasks, Positions, MultiPositionType);
- }
- }
- void UAkGameplayStatics::UseReverbVolumes(bool inUseReverbVolumes, class AActor* Actor )
- {
- if ( Actor == NULL )
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::UseReverbVolumes: NULL Actor specified!"));
- return;
- }
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if( AudioDevice )
- {
- UAkComponent * ComponentToSet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
- if( ComponentToSet != NULL )
- {
- ComponentToSet->UseReverbVolumes(inUseReverbVolumes);
- }
- }
- }
- void UAkGameplayStatics::UseEarlyReflections(class AActor* Actor,
- class UAkAuxBus* AuxBus,
- int Order,
- float BusSendGain,
- float MaxPathLength,
- bool SpotReflectors,
- const FString& AuxBusName)
- {
- // Deprecated
- }
- void UAkGameplayStatics::SetReflectionsOrder(int Order, bool RefreshPaths)
- {
- if (Order > 4 || Order < 0)
- {
- Order = FMath::Clamp(Order, 0, 4);
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetReflectionsOrder: The order value is invalid. It was clamped to %d"), Order);
- }
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- AudioDevice->SetReflectionsOrder(Order, RefreshPaths);
- }
- }
- void UAkGameplayStatics::SetPortalObstructionAndOcclusion(UAkPortalComponent* PortalComponent, float ObstructionValue, float OcclusionValue)
- {
- if (ObstructionValue > 1.f || ObstructionValue < 0.f)
- {
- ObstructionValue = FMath::Clamp(ObstructionValue, 0.f, 1.f);
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetPortalObstructionAndOcclusion: The obstruction value is invalid. It was clamped to %f"), ObstructionValue);
- }
- if (OcclusionValue > 1.f || OcclusionValue < 0.f)
- {
- OcclusionValue = FMath::Clamp(OcclusionValue, 0.f, 1.f);
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetPortalObstructionAndOcclusion: The occlusion value is invalid. It was clamped to %f"), OcclusionValue);
- }
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- AudioDevice->SetPortalObstructionAndOcclusion(PortalComponent, ObstructionValue, OcclusionValue);
- }
- }
- void UAkGameplayStatics::SetGameObjectToPortalObstruction(UAkComponent* GameObjectAkComponent, UAkPortalComponent* PortalComponent, float ObstructionValue)
- {
- if (ObstructionValue > 1.f || ObstructionValue < 0.f)
- {
- ObstructionValue = FMath::Clamp(ObstructionValue, 0.f, 1.f);
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetGameObjectToPortalObstruction: The obstruction value is invalid. It was clamped to %f"), ObstructionValue);
- }
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- AudioDevice->SetGameObjectToPortalObstruction(GameObjectAkComponent, PortalComponent, ObstructionValue);
- }
- }
- void UAkGameplayStatics::SetPortalToPortalObstruction(UAkPortalComponent* PortalComponent0, UAkPortalComponent* PortalComponent1, float ObstructionValue)
- {
- if (ObstructionValue > 1.f || ObstructionValue < 0.f)
- {
- ObstructionValue = FMath::Clamp(ObstructionValue, 0.f, 1.f);
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetGameObjectToPortalObstruction: The obstruction value is invalid. It was clamped to %f"), ObstructionValue);
- }
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- AudioDevice->SetPortalToPortalObstruction(PortalComponent0, PortalComponent1, ObstructionValue);
- }
- }
- void UAkGameplayStatics::SetOutputBusVolume(float BusVolume, class AActor* Actor)
- {
- if (Actor == NULL)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOutputBusVolume: NULL Actor specified!"));
- return;
- }
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- UAkComponent * ComponentToSet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
- if (ComponentToSet != NULL)
- {
- ComponentToSet->SetOutputBusVolume(BusVolume);
- }
- }
- }
- void UAkGameplayStatics::SetBusConfig(const FString& BusName, AkChannelConfiguration ChannelConfiguration)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AkChannelConfig config;
- FAkAudioDevice::GetChannelConfig(ChannelConfiguration, config);
- AudioDevice->SetBusConfig(BusName, config);
- }
- void UAkGameplayStatics::SetPanningRule(PanningRule PanRule)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AkPanningRule AkPanRule = (PanRule == PanningRule::PanningRule_Headphones) ? AkPanningRule_Headphones : AkPanningRule_Speakers;
- AudioDevice->SetPanningRule(AkPanRule);
- }
- void UAkGameplayStatics::AddOutput(const FAkOutputSettings& in_Settings, FAkOutputDeviceID& out_DeviceID, UPARAM(ref) TArray<UAkComponent*>& in_ListenerIDs)
- {
- auto* SoundEngine = IWwiseSoundEngineAPI::Get();
- if (UNLIKELY(!SoundEngine))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::AddOutput: SoundEngine not initialized, new output will not be added."));
- return;
- }
- AkUInt32 ShortID = SoundEngine->GetIDFromString(TCHAR_TO_ANSI(*in_Settings.AudioDeviceShareSetName));
- if (UNLIKELY(ShortID == AK_INVALID_UNIQUE_ID))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::AddOutput: Short ID for %s is invalid, new output will not be added."));
- return;
- }
- AkOutputSettings OutSettings;
- OutSettings.audioDeviceShareset = ShortID;
- OutSettings.idDevice = in_Settings.IdDevice;
- OutSettings.ePanningRule = (in_Settings.PanRule == PanningRule::PanningRule_Headphones) ? AkPanningRule_Headphones : AkPanningRule_Speakers;
- FAkAudioDevice::GetChannelConfig(in_Settings.ChannelConfig, OutSettings.channelConfig);
- AkOutputDeviceID outputDeviceID;
- AKRESULT result = AK_Fail;
- if (in_ListenerIDs.Num() > 0)
- {
- result = SoundEngine->AddOutput(OutSettings, &outputDeviceID);
- }
- else
- {
- TArray<AkGameObjectID> akGameObjectIDArray;
- for (int i = 0; i < in_ListenerIDs.Num(); i++)
- {
- akGameObjectIDArray.Add(in_ListenerIDs[i]->GetAkGameObjectID());
- }
- result = SoundEngine->AddOutput(OutSettings, &outputDeviceID, akGameObjectIDArray.GetData(), akGameObjectIDArray.Num());
- }
- if (result != AK_Success)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::AddOutput: AddOuput has failed, new output will not be added. AkResult: %s"), result);
- }
- out_DeviceID.UInt64Value = outputDeviceID;
- }
- void UAkGameplayStatics::RemoveOutput(FAkOutputDeviceID in_OutputDeviceId)
- {
- auto* SoundEngine = IWwiseSoundEngineAPI::Get();
- if (UNLIKELY(!SoundEngine))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::RemoveOutput: Could not fetch audio device, output will not be removed."));
- return;
- }
- SoundEngine->RemoveOutput(in_OutputDeviceId.UInt64Value);
- }
- void UAkGameplayStatics::ReplaceMainOutput(const FAkOutputSettings& MainOutputSettings)
- {
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ReplaceMainOutput: Could not fetch audio device, main output will not be replaced."));
- return;
- }
- AkUInt32 ShortID = AudioDevice->GetShortIDFromString(MainOutputSettings.AudioDeviceShareSetName);
- if (UNLIKELY(ShortID == AK_INVALID_UNIQUE_ID))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::ReplaceMainOutput: Short ID for %s is invalid, main output will not be replaced."));
- return;
- }
- AkOutputSettings OutSettings;
- OutSettings.audioDeviceShareset = ShortID;
- OutSettings.idDevice = MainOutputSettings.IdDevice;
- OutSettings.ePanningRule = (MainOutputSettings.PanRule == PanningRule::PanningRule_Headphones) ? AkPanningRule_Headphones : AkPanningRule_Speakers;
- FAkAudioDevice::GetChannelConfig(MainOutputSettings.ChannelConfig, OutSettings.channelConfig);
- AudioDevice->ReplaceMainOutput(OutSettings);
- }
- void UAkGameplayStatics::GetSpeakerAngles(TArray<float>& SpeakerAngles, float& HeightAngle, const FString& DeviceShareSet)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AkOutputDeviceID DeviceID = DeviceShareSet.IsEmpty() ? 0 : AudioDevice->GetOutputID(DeviceShareSet);
- AudioDevice->GetSpeakerAngles(SpeakerAngles, HeightAngle, DeviceID);
- }
- void UAkGameplayStatics::SetSpeakerAngles(const TArray<float>& SpeakerAngles, float HeightAngles, const FString& DeviceShareSet)
- {
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AkOutputDeviceID DeviceID = DeviceShareSet.IsEmpty() ? 0 : AudioDevice->GetOutputID(DeviceShareSet);
- AudioDevice->SetSpeakerAngles(SpeakerAngles, HeightAngles, DeviceID);
- }
- void UAkGameplayStatics::SetOcclusionRefreshInterval(float RefreshInterval, class AActor* Actor)
- {
- if (Actor == NULL)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOcclusionRefreshInterval: NULL Actor specified!"));
- return;
- }
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOcclusionRefreshInterval: Could not retrieve audio device."));
- return;
- }
- UAkComponent* ComponentToSet = AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
- if (ComponentToSet != NULL)
- {
- ComponentToSet->OcclusionRefreshInterval = RefreshInterval;
- }
- }
-
- void UAkGameplayStatics::StopActor(class AActor* Actor)
- {
- if ( Actor == NULL )
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::StopActor: NULL Actor specified!"));
- return;
- }
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::StopActor: Could not retrieve audio device."));
- return;
- }
- AudioDevice->StopGameObject(AudioDevice->GetAkComponent(Actor->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset));
- }
- void UAkGameplayStatics::StopAll()
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AudioDevice->StopAllSounds();
- }
- void UAkGameplayStatics::CancelEventCallback(const FOnAkPostEventCallback& PostEventCallback)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AudioDevice->CancelEventCallbackDelegate(PostEventCallback);
- }
- void UAkGameplayStatics::StartAllAmbientSounds(UObject* WorldContextObject)
- {
- AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- {
- return;
- }
- for (FActorIterator It(DeviceAndWorld.CurrentWorld); It; ++It)
- {
- AAkAmbientSound* pAmbientSound = Cast<AAkAmbientSound>(*It);
- if (pAmbientSound != NULL)
- {
- UAkComponent* pComponent = pAmbientSound->AkComponent;
- if (pComponent && GWorld->Scene == pComponent->GetScene())
- {
- pAmbientSound->StartPlaying();
- }
- }
- }
- }
- void UAkGameplayStatics::StopAllAmbientSounds(UObject* WorldContextObject)
- {
- AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
- if (UNLIKELY(!DeviceAndWorld.IsValid()))
- {
- return;
- }
- for (FActorIterator It(DeviceAndWorld.CurrentWorld); It; ++It)
- {
- AAkAmbientSound* pAmbientSound = Cast<AAkAmbientSound>(*It);
- if (pAmbientSound != NULL)
- {
- UAkComponent* pComponent = pAmbientSound->AkComponent;
- if (pComponent && GWorld->Scene == pComponent->GetScene())
- {
- pAmbientSound->StopPlaying();
- }
- }
- }
- }
- void UAkGameplayStatics::ClearSoundBanksAndMedia()
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AudioDevice->ClearSoundBanksAndMedia();
- }
- void UAkGameplayStatics::ClearBanks()
- {
- ClearSoundBanksAndMedia();
- }
- void UAkGameplayStatics::LoadInitBank()
- {
- auto* InitBankLoader = FWwiseInitBankLoader::Get();
- if(UNLIKELY(!InitBankLoader))
- {
- UE_LOG(LogAkAudio, Error, TEXT("LoadInitBank: WwiseInitBankLoader is not initialized."));
- return;
- }
- InitBankLoader->LoadInitBank();
- }
- void UAkGameplayStatics::UnloadInitBank()
- {
- auto* InitBankLoader = FWwiseInitBankLoader::Get();
- if(UNLIKELY(!InitBankLoader))
- {
- UE_LOG(LogAkAudio, Error, TEXT("UnloadInitBank: WwiseInitBankLoader is not initialized."));
- return;
- }
- InitBankLoader->UnloadInitBank();
- }
- void UAkGameplayStatics::LoadBankByName(const FString& BankName)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AkBankID BankId;
- AudioDevice->LoadBank(BankName, BankId);
- }
- void UAkGameplayStatics::UnloadBankByName(const FString& BankName)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- AudioDevice->UnloadBank(BankName);
- }
- void UAkGameplayStatics::StartOutputCapture(const FString& Filename)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if (UNLIKELY(!AudioDevice))
- {
- return;
- }
- FString name = Filename;
- if (!name.EndsWith(".wav"))
- {
- name += ".wav";
- }
- AudioDevice->StartOutputCapture(name);
- }
- void UAkGameplayStatics::AddOutputCaptureMarker(const FString& MarkerText)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if( AudioDevice )
- {
- AudioDevice->AddOutputCaptureMarker(MarkerText);
- }
- }
- void UAkGameplayStatics::StopOutputCapture()
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if( AudioDevice )
- {
- AudioDevice->StopOutputCapture();
- }
- }
- void UAkGameplayStatics::StartProfilerCapture(const FString& Filename)
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if( AudioDevice )
- {
- FString name = Filename;
- if( !name.EndsWith(".prof") )
- {
- name += ".prof";
- }
- AudioDevice->StartProfilerCapture(name);
- }
- }
- void UAkGameplayStatics::StopProfilerCapture()
- {
- FAkAudioDevice * AudioDevice = FAkAudioDevice::Get();
- if( AudioDevice )
- {
- AudioDevice->StopProfilerCapture();
- }
- }
- FString UAkGameplayStatics::GetCurrentAudioCulture()
- {
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- return AudioDevice->GetCurrentAudioCulture();
- }
- return FString();
- }
- TArray<FString> UAkGameplayStatics::GetAvailableAudioCultures()
- {
- FAkAudioDevice* AudioDevice = FAkAudioDevice::Get();
- if (AudioDevice)
- {
- return AudioDevice->GetAvailableAudioCultures();
- }
- return TArray<FString>();
- }
- void UAkGameplayStatics::SetCurrentAudioCulture(const FString& AudioCulture, FLatentActionInfo LatentInfo, UObject* WorldContextObject)
- {
- AkDeviceAndWorld DeviceAndWorld(WorldContextObject);
- FLatentActionManager& LatentActionManager = DeviceAndWorld.CurrentWorld->GetLatentActionManager();
- FSetCurrentAudioCultureAction* NewAction = LatentActionManager.FindExistingAction<FSetCurrentAudioCultureAction>(LatentInfo.CallbackTarget, LatentInfo.UUID);
- if (!NewAction)
- {
- NewAction = new FSetCurrentAudioCultureAction(LatentInfo);
- LatentActionManager.AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, NewAction);
- }
- if (FAkAudioDevice* AudioDevice = FAkAudioDevice::Get())
- {
- AudioDevice->SetCurrentAudioCultureAsync(AudioCulture, NewAction);
- }
- else
- {
- NewAction->ActionDone = true;
- }
- }
- void UAkGameplayStatics::SetCurrentAudioCultureAsync(const FString& AudioCulture, const FOnSetCurrentAudioCultureCallback& Completed)
- {
- if (FAkAudioDevice* AudioDevice = FAkAudioDevice::Get())
- {
- AudioDevice->SetCurrentAudioCultureAsync(AudioCulture, FOnSetCurrentAudioCultureCompleted::CreateLambda([Completed](bool Succeeded) {
- Completed.ExecuteIfBound(Succeeded);
- }));
- }
- }
- UObject* UAkGameplayStatics::GetAkAudioTypeUserData(const UAkAudioType* Instance, const UClass* Type)
- {
- for (auto entry : Instance->UserData)
- {
- if (entry && entry->GetClass()->IsChildOf(Type))
- {
- return entry;
- }
- }
- return nullptr;
- }
- void UAkGameplayStatics::SetDistanceProbe(AActor* Listener, AActor* DistanceProbe)
- {
- if (Listener == nullptr)
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetDistanceProbe: NULL Listener specified!"));
- return;
- }
- if (FAkAudioDevice* AudioDevice = FAkAudioDevice::Get())
- {
- UAkComponent * ListenerAkComponent = AudioDevice->GetAkComponent(Listener->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset);
- UAkComponent* DistanceProbeAkComponent =
- DistanceProbe != nullptr ?
- AudioDevice->GetAkComponent(DistanceProbe->GetRootComponent(), FName(), NULL, EAttachLocation::KeepRelativeOffset) :
- nullptr;
- AudioDevice->SetDistanceProbe(ListenerAkComponent, DistanceProbeAkComponent);
- }
- }
- bool UAkGameplayStatics::SetOutputDeviceEffect(const FAkOutputDeviceID InDeviceID, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
- {
- if(UNLIKELY(!InEffectShareSet))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetOutputDeviceEffect: NULL Effect ShareSet specified!"));
- return false;
- }
- auto* SoundEngine = IWwiseSoundEngineAPI::Get();
- if (UNLIKELY(!SoundEngine)) return false;
- UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetOutputDeviceEffect: DeviceID: %" PRIu64 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
- InDeviceID.UInt64Value, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
- AKRESULT Result = SoundEngine->SetOutputDeviceEffect(InDeviceID.UInt64Value, InEffectIndex, InEffectShareSet->GetShortID());
- return Result == AK_Success;
- }
- bool UAkGameplayStatics::SetBusEffectByName(const FString InBusName, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
- {
- if(UNLIKELY(!InEffectShareSet))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetBusEffectByName: NULL Effect ShareSet specified!"));
- return false;
- }
- auto* SoundEngine = IWwiseSoundEngineAPI::Get();
- if (UNLIKELY(!SoundEngine)) return false;
- UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetBusEffectByName: BusName: %s, InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
- *InBusName, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
- AKRESULT Result = SoundEngine->SetBusEffect(TCHAR_TO_AK(*InBusName), InEffectIndex, InEffectShareSet->GetShortID());
- return Result == AK_Success;
- }
- bool UAkGameplayStatics::SetBusEffectByID(const FAkUniqueID InBusID, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
- {
- if(UNLIKELY(!InEffectShareSet))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetBusEffectByID: NULL Effect ShareSet specified!"));
- return false;
- }
- auto* SoundEngine = IWwiseSoundEngineAPI::Get();
- if (UNLIKELY(!SoundEngine)) return false;
- UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetBusEffectByID: BusID: %" PRIu32 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
- InBusID.UInt32Value, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
- AKRESULT Result = SoundEngine->SetBusEffect(InBusID.UInt32Value, InEffectIndex, InEffectShareSet->GetShortID());
- return Result == AK_Success;
- }
- bool UAkGameplayStatics::SetAuxBusEffect(const UAkAuxBus* InAuxBus, const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
- {
- if(UNLIKELY(!InEffectShareSet))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetAuxBusEffect: NULL Effect ShareSet specified!"));
- return false;
- }
- if(UNLIKELY(!InAuxBus))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetAuxBusEffect: NULL Aux Bus specified!"));
- return false;
- }
- auto* SoundEngine = IWwiseSoundEngineAPI::Get();
- if (UNLIKELY(!SoundEngine)) return false;
- UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetAuxBusEffect: AuxBus Asset Name: %s, AuxBus Short ID: %" PRIu32 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
- *InAuxBus->GetName(), InAuxBus->GetShortID(), InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
- AKRESULT Result = SoundEngine->SetBusEffect(InAuxBus->GetShortID(), InEffectIndex, InEffectShareSet->GetShortID());
- return Result == AK_Success;
- }
- bool UAkGameplayStatics::SetActorMixerEffect(const FAkUniqueID InAudioNodeID,const int32 InEffectIndex, const UAkEffectShareSet* InEffectShareSet)
- {
- if(UNLIKELY(!InEffectShareSet))
- {
- UE_LOG(LogAkAudio, Warning, TEXT("UAkGameplayStatics::SetActorMixerEffect: NULL Effect ShareSet specified!"));
- return false;
- }
- auto* SoundEngine = IWwiseSoundEngineAPI::Get();
- if (UNLIKELY(!SoundEngine)) return false;
- UE_LOG(LogAkAudio, Verbose, TEXT("UAkGameplayStatics::SetActorMixerEffect: AudioNodeID: %" PRIu32 ", InEffectIndex: %d, EffectShareSet Asset Name: %s, EffectShareSet ShortID: %" PRIu32 "."),
- InAudioNodeID.UInt32Value, InEffectIndex, *InEffectShareSet->GetName(), InEffectShareSet->GetShortID());
- AKRESULT Result = SoundEngine->SetActorMixerEffect(InAudioNodeID.UInt32Value, InEffectIndex, InEffectShareSet->GetShortID());
- return Result == AK_Success;
- }
|