AkSettings.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. #pragma once
  16. #include "AkAcousticTexture.h"
  17. #include "Engine/EngineTypes.h"
  18. #include "PhysicalMaterials/PhysicalMaterial.h"
  19. #include "AssetRegistry/AssetRegistryModule.h"
  20. #include "WwiseDefines.h"
  21. #include "AkRtpc.h"
  22. #include "AkSettings.generated.h"
  23. class UAkInitBank;
  24. class UAkAcousticTexture;
  25. DECLARE_MULTICAST_DELEGATE(FOnSoundBanksPathChangedDelegate);
  26. /** Custom Collision Channel enum with an option to take the value from the Wwise Integration Settings (this follows a similar approach to that of EActorUpdateOverlapsMethod in Actor.h). */
  27. UENUM(BlueprintType)
  28. enum EAkCollisionChannel
  29. {
  30. EAKCC_WorldStatic UMETA(DisplayName = "WorldStatic"),
  31. EAKCC_WorldDynamic UMETA(DisplayName = "WorldDynamic"),
  32. EAKCC_Pawn UMETA(DisplayName = "Pawn"),
  33. EAKCC_Visibility UMETA(DisplayName = "Visibility", TraceQuery = "1"),
  34. EAKCC_Camera UMETA(DisplayName = "Camera", TraceQuery = "1"),
  35. EAKCC_PhysicsBody UMETA(DisplayName = "PhysicsBody"),
  36. EAKCC_Vehicle UMETA(DisplayName = "Vehicle"),
  37. EAKCC_Destructible UMETA(DisplayName = "Destructible"),
  38. EAKCC_UseIntegrationSettingsDefault UMETA(DisplayName = "Use Integration Settings Default"), // Use the default value specified by Wwise Integration Settings.
  39. };
  40. UENUM()
  41. enum class EAkUnrealAudioRouting
  42. {
  43. Custom UMETA(DisplayName = "Default", ToolTip = "Custom Unreal audio settings set up by the developer"),
  44. Separate UMETA(DisplayName = "Both Wwise and Unreal audio", ToolTip = "Use default Unreal audio at the same time than Wwise SoundEngine (might be incompatible with some platforms)"),
  45. AudioLink UMETA(DisplayName = "Route through AudioLink [UE5.1]", ToolTip = "Use WwiseAudioLink to route all Unreal audio sources to Wwise SoundEngine Inputs (requires Unreal Engine 5.1)"),
  46. AudioMixer UMETA(DisplayName = "Route through AkAudioMixer", ToolTip = "Use AkAudioMixer to route Unreal submixes to a Wwise SoundEngine Input"),
  47. EnableWwiseOnly UMETA(DisplayName = "Enable Wwise SoundEngine only", ToolTip = "Only use Wwise SoundEngine, and disable Unreal audio"),
  48. EnableUnrealOnly UMETA(DisplayName = "Enable Unreal Audio only", ToolTip = "Only use Unreal audio, and disable Wwise SoundEngine")
  49. };
  50. USTRUCT()
  51. struct FAkGeometrySurfacePropertiesToMap
  52. {
  53. GENERATED_BODY()
  54. UPROPERTY(EditAnywhere, Category = "AkGeometry Surface Properties Map")
  55. TSoftObjectPtr<class UAkAcousticTexture> AcousticTexture = nullptr;
  56. UPROPERTY(EditAnywhere, DisplayName = "Transmission Loss", Category = "AkGeometry Surface Properties Map", meta = (ClampMin = "0.0", ClampMax = "1.0"))
  57. float OcclusionValue = 1.f;
  58. bool operator==(const FAkGeometrySurfacePropertiesToMap& Rhs) const
  59. {
  60. if (OcclusionValue != Rhs.OcclusionValue)
  61. {
  62. return false;
  63. }
  64. if (!AcousticTexture.IsValid() != !Rhs.AcousticTexture.IsValid())
  65. {
  66. return false;
  67. }
  68. if (!AcousticTexture.IsValid())
  69. {
  70. return true;
  71. }
  72. return AcousticTexture->GetFName() == Rhs.AcousticTexture->GetFName();
  73. }
  74. };
  75. struct AkGeometrySurfaceProperties
  76. {
  77. UAkAcousticTexture* AcousticTexture = nullptr;
  78. float OcclusionValue = 1.f;
  79. };
  80. USTRUCT()
  81. struct FAkAcousticTextureParams
  82. {
  83. GENERATED_BODY()
  84. UPROPERTY()
  85. FVector4 AbsorptionValues = FVector4(FVector::ZeroVector, 0.0f);
  86. uint32 shortID = 0;
  87. float AbsorptionLow() const { return AbsorptionValues[0]; }
  88. float AbsorptionMidLow() const { return AbsorptionValues[1]; }
  89. float AbsorptionMidHigh() const { return AbsorptionValues[2]; }
  90. float AbsorptionHigh() const { return AbsorptionValues[3]; }
  91. TArray<float> AsTArray() const { return { AbsorptionLow(), AbsorptionMidLow(), AbsorptionMidHigh(), AbsorptionHigh() }; }
  92. };
  93. #define AK_MAX_AUX_PER_OBJ 4
  94. DECLARE_EVENT(UAkSettings, ActivatedNewAssetManagement);
  95. DECLARE_EVENT(UAkSettings, ShowRoomsPortalsChanged);
  96. DECLARE_EVENT(UAkSettings, ShowReverbInfoChanged)
  97. DECLARE_EVENT(UAkSettings, AuxBusAssignmentMapChanged);
  98. DECLARE_EVENT(UAkSettings, ReverbRTPCChanged);
  99. DECLARE_EVENT_TwoParams(UAkSettings, SoundDataFolderChanged, const FString&, const FString&);
  100. DECLARE_EVENT_OneParam(UAkSettings, AcousticTextureParamsChanged, const FGuid&)
  101. UCLASS(config = Game, defaultconfig)
  102. class AKAUDIO_API UAkSettings : public UObject
  103. {
  104. GENERATED_BODY()
  105. public:
  106. UAkSettings(const FObjectInitializer& ObjectInitializer);
  107. ~UAkSettings();
  108. /**
  109. Converts between EAkCollisionChannel and ECollisionChannel. Returns Wwise Integration Settings default if CollisionChannel == UseIntegrationSettingsDefault. Otherwise, casts CollisionChannel to ECollisionChannel.
  110. */
  111. static ECollisionChannel ConvertFitToGeomCollisionChannel(EAkCollisionChannel CollisionChannel);
  112. /**
  113. Converts between EAkCollisionChannel and ECollisionChannel. Returns Wwise Integration Settings default if CollisionChannel == UseIntegrationSettingsDefault. Otherwise, casts CollisionChannel to ECollisionChannel.
  114. */
  115. static ECollisionChannel ConvertOcclusionCollisionChannel(EAkCollisionChannel CollisionChannel);
  116. // The maximum number of reverb auxiliary sends that will be simultaneously applied to a sound source
  117. // Reverbs from a Spatial Audio room will be active even if this maximum is reached.
  118. UPROPERTY(Config, EditAnywhere, DisplayName = "Max Simultaneous Reverb", Category="Reverb")
  119. uint8 MaxSimultaneousReverbVolumes = AK_MAX_AUX_PER_OBJ;
  120. // Wwise Project Path
  121. UPROPERTY(Config, EditAnywhere, Category="Installation", meta=(FilePathFilter="wproj", AbsolutePath))
  122. FFilePath WwiseProjectPath;
  123. // Where the Sound Data will be generated in the Content Folder
  124. UPROPERTY()
  125. FDirectoryPath WwiseSoundDataFolder;
  126. UPROPERTY(Config, EditAnywhere, Category="Installation", meta=( AbsolutePath))
  127. FDirectoryPath GeneratedSoundBanksFolder;
  128. //Where wwise .bnk and .wem files will be copied to when staging files during cooking
  129. UPROPERTY(Config, EditAnywhere, Category = "Cooking", meta=(RelativeToGameContentDir))
  130. FDirectoryPath WwiseStagingDirectory = {TEXT("WwiseAudio")};
  131. //Used to track whether SoundBanks have been transferred to Wwise after migration to 2022.1 (or later)
  132. UPROPERTY(Config)
  133. bool bSoundBanksTransfered = false;
  134. //Used after migration to track whether assets have been re-serialized after migration to 2022.1 (or later)
  135. UPROPERTY(Config)
  136. bool bAssetsMigrated = false;
  137. //Used after migration to track whether project settings have been updated after migration to 2022.1 (or later)
  138. UPROPERTY(Config)
  139. bool bProjectMigrated = false;
  140. UPROPERTY(Config)
  141. bool bAutoConnectToWAAPI_DEPRECATED = false;
  142. // Default value for Occlusion Collision Channel when creating a new Ak Component.
  143. UPROPERTY(Config, EditAnywhere, Category = "Occlusion")
  144. TEnumAsByte<ECollisionChannel> DefaultOcclusionCollisionChannel = ECollisionChannel::ECC_Visibility;
  145. // Default value for Collision Channel when fitting Ak Acoustic Portals and Ak Spatial Audio Volumes to surrounding geometry.
  146. UPROPERTY(Config, EditAnywhere, Category = "Fit To Geometry")
  147. TEnumAsByte<ECollisionChannel> DefaultFitToGeometryCollisionChannel = ECollisionChannel::ECC_WorldStatic;
  148. // PhysicalMaterial to AcousticTexture and Occlusion Value Map
  149. UPROPERTY(Config, EditAnywhere, EditFixedSize, Category = "AkGeometry Surface Properties Map")
  150. TMap<TSoftObjectPtr<UPhysicalMaterial>, FAkGeometrySurfacePropertiesToMap> AkGeometryMap;
  151. // Global surface absorption value to use when estimating environment decay value. Acts as a global scale factor for the decay estimations. Defaults to 0.5.
  152. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map", meta = (ClampMin = 0.1f, ClampMax = 1.0f, UIMin = 0.1f, UIMax = 1.0f))
  153. float GlobalDecayAbsorption = .5f;
  154. // Default reverb aux bus to apply to rooms
  155. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map")
  156. TSoftObjectPtr<class UAkAuxBus> DefaultReverbAuxBus = nullptr;
  157. // RoomDecay to AuxBusID Map. Used to automatically assign aux bus ids to rooms depending on their volume and surface area.
  158. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map")
  159. TMap<float, TSoftObjectPtr<class UAkAuxBus>> EnvironmentDecayAuxBusMap;
  160. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map|RTPCs")
  161. FString HFDampingName = "";
  162. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map|RTPCs")
  163. FString DecayEstimateName = "";
  164. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map|RTPCs")
  165. FString TimeToFirstReflectionName = "";
  166. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map|RTPCs")
  167. TSoftObjectPtr<UAkRtpc> HFDampingRTPC = nullptr;
  168. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map|RTPCs")
  169. TSoftObjectPtr<UAkRtpc> DecayEstimateRTPC = nullptr;
  170. UPROPERTY(Config, EditAnywhere, Category = "Reverb Assignment Map|RTPCs")
  171. TSoftObjectPtr<UAkRtpc> TimeToFirstReflectionRTPC = nullptr;
  172. // Input event associated with the Wwise Audio Input
  173. UPROPERTY(Config, EditAnywhere, Category = "Initialization")
  174. TSoftObjectPtr<class UAkAudioEvent> AudioInputEvent = nullptr;
  175. UPROPERTY(Config)
  176. TMap<FGuid, FAkAcousticTextureParams> AcousticTextureParamsMap;
  177. // When generating the event data, the media contained in switch containers will be split by state/switch value
  178. // and only loaded if the state/switch value are currently loaded
  179. UPROPERTY(Config, meta = (Deprecated, DeprecationMessage="Setting now exists for each AK Audio Event"))
  180. bool SplitSwitchContainerMedia = false;
  181. //Deprecated in 2022.1
  182. //Used in migration from previous versions
  183. UPROPERTY(Config)
  184. bool SplitMediaPerFolder= false;
  185. // Deprecated in 2022.1
  186. //Used in migration from previous versions
  187. UPROPERTY(Config)
  188. bool UseEventBasedPackaging= false;
  189. // Commit message that GenerateSoundBanksCommandlet will use
  190. UPROPERTY()
  191. FString CommandletCommitMessage = TEXT("Unreal Wwise Sound Data auto-generation");
  192. UPROPERTY(Config, EditAnywhere, Category = "Localization")
  193. TMap<FString, FString> UnrealCultureToWwiseCulture;
  194. // When an asset is dragged from the Wwise Browser, assets are created by default in this path.
  195. UPROPERTY(Config, EditAnywhere, Category = "Asset Creation")
  196. FString DefaultAssetCreationPath = "/Game/WwiseAudio";
  197. // The unique Init Bank for the Wwise project. This contains the basic information necessary for properly setting up the SoundEngine.
  198. UPROPERTY(Config, EditAnywhere, Category = "Initialization")
  199. TSoftObjectPtr<UAkInitBank> InitBank;
  200. // Routing Audio from Unreal Audio to Wwise Sound Engine
  201. UPROPERTY(Config, EditAnywhere, Category = "Initialization", DisplayName = "Unreal Audio Routing (Experimental)", meta=(ConfigRestartRequired=true))
  202. EAkUnrealAudioRouting AudioRouting = EAkUnrealAudioRouting::Custom;
  203. UPROPERTY(Config, EditAnywhere, Category = "Initialization", DisplayName = "Wwise SoundEngine Enabled (Experimental)", meta=(ConfigRestartRequired=true, EditCondition="AudioRouting == EAkUnrealAudioRouting::Custom"))
  204. bool bWwiseSoundEngineEnabled = true;
  205. UPROPERTY(Config, EditAnywhere, Category = "Initialization", DisplayName = "Wwise AudioLink Enabled (Experimental)", meta=(ConfigRestartRequired=true, EditCondition="AudioRouting == EAkUnrealAudioRouting::Custom"))
  206. bool bWwiseAudioLinkEnabled = false;
  207. UPROPERTY(Config, EditAnywhere, Category = "Initialization", DisplayName = "AkAudioMixer Enabled (Experimental)", meta=(ConfigRestartRequired=true, EditCondition="AudioRouting == EAkUnrealAudioRouting::Custom"))
  208. bool bAkAudioMixerEnabled = false;
  209. UPROPERTY(Config)
  210. bool AskedToUseNewAssetManagement_DEPRECATED = false;
  211. UPROPERTY(Config)
  212. bool bEnableMultiCoreRendering_DEPRECATED = false;
  213. UPROPERTY(Config)
  214. bool MigratedEnableMultiCoreRendering = false;
  215. UPROPERTY(Config)
  216. bool FixupRedirectorsDuringMigration = false;
  217. UPROPERTY(Config)
  218. FDirectoryPath WwiseWindowsInstallationPath_DEPRECATED;
  219. UPROPERTY(Config)
  220. FFilePath WwiseMacInstallationPath_DEPRECATED;
  221. static FString DefaultSoundDataFolder;
  222. virtual void PostInitProperties() override;
  223. bool ReverbRTPCsInUse() const;
  224. bool DecayRTPCInUse() const;
  225. bool DampingRTPCInUse() const;
  226. bool PredelayRTPCInUse() const;
  227. bool GetAssociatedAcousticTexture(const UPhysicalMaterial* physMaterial, UAkAcousticTexture*& acousticTexture) const;
  228. bool GetAssociatedOcclusionValue(const UPhysicalMaterial* physMaterial, float& occlusionValue) const;
  229. #if WITH_EDITOR
  230. bool UpdateGeneratedSoundBanksPath();
  231. bool UpdateGeneratedSoundBanksPath(FString Path);
  232. bool GeneratedSoundBanksPathExists() const;
  233. bool AreSoundBanksGenerated() const;
  234. void RefreshAcousticTextureParams() const;
  235. #if AK_SUPPORT_WAAPI
  236. /** This needs to be called after the waapi client has been initialized, which happens after AkSettings is constructed. */
  237. void InitWaapiSync();
  238. /** Set the color of a UAkAcousticTexture asset using a color from the UnrealWwiseObjectColorPalette (this is the same as the 'dark theme' in Wwise Authoring). Send a colorIndex of -1 to use the 'unset' color. */
  239. void SetTextureColor(FGuid textureID, int colorIndex);
  240. #endif
  241. void RemoveSoundDataFromAlwaysStageAsUFS(const FString& SoundDataPath);
  242. void RemoveSoundDataFromAlwaysCook(const FString& SoundDataPath);
  243. void EnsurePluginContentIsInAlwaysCook() const;
  244. void InitAkGeometryMap();
  245. void DecayAuxBusMapChanged();
  246. void SortDecayKeys();
  247. static float MinimumDecayKeyDistance;
  248. #endif
  249. protected:
  250. #if WITH_EDITOR
  251. virtual void PostEditChangeProperty( struct FPropertyChangedEvent& PropertyChangedEvent ) override;
  252. virtual void PreEditChange(FProperty* PropertyAboutToChange) override;
  253. #endif
  254. private:
  255. #if WITH_EDITOR
  256. FString PreviousWwiseProjectPath;
  257. FString PreviousWwiseGeneratedSoundBankFolder;
  258. bool bTextureMapInitialized = false;
  259. TMap< UPhysicalMaterial*, UAkAcousticTexture* > TextureMapInternal;
  260. FAssetRegistryModule* AssetRegistryModule;
  261. void OnAssetAdded(const FAssetData& NewAssetData);
  262. void OnAssetRemoved(const struct FAssetData& AssetData);
  263. void FillAkGeometryMap(const TArray<FAssetData>& PhysicalMaterials, const TArray<FAssetData>& AcousticTextureAssets);
  264. void UpdateAkGeometryMap();
  265. void SanitizeProjectPath(FString& Path, const FString& PreviousPath, const FText& DialogMessage);
  266. void OnAudioRoutingUpdate();
  267. bool bAkGeometryMapInitialized = false;
  268. TMap< UPhysicalMaterial*, UAkAcousticTexture* > PhysicalMaterialAcousticTextureMap;
  269. TMap< UPhysicalMaterial*, float > PhysicalMaterialOcclusionMap;
  270. // This is used to track which key has changed and restrict its value between the two neighbouring keys
  271. TMap<float, TSoftObjectPtr<class UAkAuxBus>> PreviousDecayAuxBusMap;
  272. #if AK_SUPPORT_WAAPI
  273. TMap<FGuid, TArray<uint64>> WaapiTextureSubscriptions;
  274. TMap<FGuid, uint64> WaapiTextureColorSubscriptions;
  275. TMap<FGuid, uint64> WaapiTextureColorOverrideSubscriptions;
  276. FDelegateHandle WaapiProjectLoadedHandle;
  277. FDelegateHandle WaapiConnectionLostHandle;
  278. #endif
  279. #endif
  280. public:
  281. bool bRequestRefresh = false;
  282. const FAkAcousticTextureParams* GetTextureParams(const uint32& shortID) const;
  283. #if WITH_EDITOR
  284. void ClearAkRoomDecayAuxBusMap();
  285. void InsertDecayKeyValue(const float& decayKey);
  286. void SetAcousticTextureParams(const FGuid& textureID, const FAkAcousticTextureParams& params);
  287. void ClearTextureParamsMap();
  288. #if AK_SUPPORT_WAAPI
  289. void WaapiProjectLoaded();
  290. void WaapiDisconnected();
  291. void RegisterWaapiTextureCallback(const FGuid& textureID);
  292. void UnregisterWaapiTextureCallback(const FGuid& textureID);
  293. void ClearWaapiTextureCallbacks();
  294. /** Use WAAPI to query the absorption params for a given texture and store them in the texture params map. */
  295. void UpdateTextureParams(const FGuid& textureID);
  296. /** Use WAAPI to query the color for a given texture and Update the corresponding UAkAcousticTexture asset. */
  297. void UpdateTextureColor(const FGuid& textureID);
  298. #endif // AK_SUPPORT_WAAPI
  299. mutable AcousticTextureParamsChanged OnTextureParamsChanged;
  300. #endif // WITH_EDITOR
  301. #if WITH_EDITORONLY_DATA
  302. // Visualize rooms and portals in the viewport. This requires 'realtime' to be enabled in the viewport.
  303. UPROPERTY(Config, EditAnywhere, Category = "Viewports")
  304. bool VisualizeRoomsAndPortals = false;
  305. // Flips the state of VisualizeRoomsAndPortals. Used for the viewport menu options. (See FAudiokineticToolsModule in AudiokineticTooslModule.cpp).
  306. void ToggleVisualizeRoomsAndPortals();
  307. // When enabled, information about AkReverbComponents will be displayed in viewports, above the component's UPrimitiveComponent parent. This requires 'realtime' to be enabled in the viewport.
  308. UPROPERTY(Config, EditAnywhere, Category = "Viewports")
  309. bool bShowReverbInfo = true;
  310. // Flips the state of bShowReverbInfo. Used for the viewport menu options. (See FAudiokineticToolsModule in AudiokineticTooslModule.cpp).
  311. void ToggleShowReverbInfo();
  312. ShowRoomsPortalsChanged OnShowRoomsPortalsChanged;
  313. ShowReverbInfoChanged OnShowReverbInfoChanged;
  314. AuxBusAssignmentMapChanged OnAuxBusAssignmentMapChanged;
  315. ReverbRTPCChanged OnReverbRTPCChanged;
  316. FOnSoundBanksPathChangedDelegate OnGeneratedSoundBanksPathChanged;
  317. #endif
  318. /** Get the associated AuxBus for the given environment decay value.
  319. * Return the AuxBus associated to the next highest decay value in the EnvironmentDecayAuxBusMap, after the given value.
  320. */
  321. void GetAuxBusForDecayValue(float decay, class UAkAuxBus*& auxBus);
  322. void GetAudioInputEvent(class UAkAudioEvent*& OutInputEvent);
  323. };