AkAudioDevice.h 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  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. AkAudioDevice.h: Audiokinetic audio interface object.
  17. =============================================================================*/
  18. #pragma once
  19. /*------------------------------------------------------------------------------------
  20. AkAudioDevice system headers
  21. ------------------------------------------------------------------------------------*/
  22. #include "AkEnvironmentIndex.h"
  23. #include "AkGameplayTypes.h"
  24. #include "AkGroupValue.h"
  25. #include "AkInclude.h"
  26. #include "WwiseUnrealDefines.h"
  27. #include "AkJobWorkerScheduler.h"
  28. #include "Wwise/WwiseSharedLanguageId.h"
  29. #include "Engine/EngineTypes.h"
  30. #include "Wwise/Stats/AkAudio.h"
  31. #include "Wwise/AkPortalObstructionAndOcclusionService.h"
  32. #include "Wwise/WwiseSoundEngineUtils.h"
  33. #if WITH_EDITORONLY_DATA
  34. #include "EditorViewportClient.h"
  35. #endif
  36. #define GET_AK_EVENT_NAME(AkEvent, EventName) ((AkEvent) ? ((AkEvent)->GetName()) : (EventName))
  37. DECLARE_EVENT(FAkAudioDevice, SoundbanksLoaded);
  38. DECLARE_EVENT(FAkAudioDevice, FOnWwiseProjectModification);
  39. DECLARE_EVENT_OneParam(FAkAudioDevice, FOnSwitchValueLoaded, UAkGroupValue*);
  40. DECLARE_DELEGATE_OneParam(FOnSetCurrentAudioCultureCompleted, bool);
  41. /*------------------------------------------------------------------------------------
  42. Dependencies, helpers & forward declarations.
  43. ------------------------------------------------------------------------------------*/
  44. class UAkPortalComponent;
  45. class AkCallbackInfoPool;
  46. class AkLegacyFileCustomParamPolicy;
  47. class CAkDiskPackage;
  48. class FAkComponentCallbackManager;
  49. class FWwiseIOHook;
  50. class UAkComponent;
  51. class UAkGameObject;
  52. class UAkGroupValue;
  53. class UAkLateReverbComponent;
  54. class UAkRoomComponent;
  55. class UAkStateValue;
  56. class UAkSwitchValue;
  57. class UAkAudioType;
  58. class UAkAudioEvent;
  59. class UAkEffectShareSet;
  60. class AkXMLErrorMessageTranslator;
  61. class AkWAAPIErrorMessageTranslator;
  62. class AkUnrealErrorTranslator;
  63. typedef TSet<UAkComponent*> UAkComponentSet;
  64. #define DUMMY_GAMEOBJ ((AkGameObjectID)0x2)
  65. #define SOUNDATLOCATION_GAMEOBJ ((AkGameObjectID)0x3)
  66. struct AKAUDIO_API FAkAudioDeviceDelegates
  67. {
  68. DECLARE_MULTICAST_DELEGATE_TwoParams(FOnAkGlobalCallback, AK::IAkGlobalPluginContext*, AkGlobalCallbackLocation);
  69. };
  70. /*------------------------------------------------------------------------------------
  71. Audiokinetic audio device.
  72. ------------------------------------------------------------------------------------*/
  73. class AKAUDIO_API FAkAudioDevice final
  74. {
  75. public:
  76. UE_NONCOPYABLE(FAkAudioDevice);
  77. FAkAudioDevice() {}
  78. /**
  79. * Initializes the audio device and creates sources.
  80. *
  81. * @return true if initialization was successful, false otherwise
  82. */
  83. bool Init( void );
  84. /**
  85. * Update the audio device and calculates the cached inverse transform later
  86. * on used for spatialization.
  87. */
  88. bool Update( float DeltaTime );
  89. /**
  90. * Tears down audio device by stopping all sounds, removing all buffers,
  91. * destroying all sources, ... Called by both Destroy and ShutdownAfterError
  92. * to perform the actual tear down.
  93. */
  94. void Teardown();
  95. /**
  96. * Stops all game sounds (and possibly UI) sounds
  97. *
  98. * @param bShouldStopUISounds If true, this function will stop UI sounds as well
  99. */
  100. void StopAllSounds( bool bShouldStopUISounds = false );
  101. /**
  102. * Stops all game sounds (and possibly UI) sounds
  103. *
  104. * @param AudioContext Stop sounds associated with this Context only
  105. */
  106. void StopAllSounds(EAkAudioContext AudioContext);
  107. /**
  108. * Stop all audio associated with a scene
  109. *
  110. * @param WorldToFlush Interface of the scene to flush
  111. */
  112. void Flush(UWorld* WorldToFlush);
  113. /**
  114. * Determine if any rooms or reverb volumes have been added to World during the current frame
  115. */
  116. bool WorldSpatialAudioVolumesUpdated(UWorld* World);
  117. /**
  118. * Clears all loaded SoundBanks and associated media
  119. */
  120. void ClearSoundBanksAndMedia();
  121. /**
  122. * Load a soundbank by name
  123. *
  124. * @param in_BankName The name of the bank to load
  125. * @param out_bankID Returned bank ID
  126. * @return Result from ak sound engine
  127. */
  128. AKRESULT LoadBank(
  129. const FString& in_BankName,
  130. AkBankID & out_bankID
  131. );
  132. /**
  133. * Load a soundbank asynchronously
  134. *
  135. * @param in_BankName The bank to load
  136. * @param in_pfnBankCallback Callback function
  137. * @param in_pCookie Callback cookie (reserved to user, passed to the callback function)
  138. * @param out_bankID Returned bank ID
  139. * @return Result from ak sound engine
  140. */
  141. AKRESULT LoadBank(
  142. const FString& in_BankName,
  143. AkBankCallbackFunc in_pfnBankCallback,
  144. void * in_pCookie,
  145. AkBankID & out_bankID
  146. );
  147. /**
  148. * Load a soundbank asynchronously, flagging completion in the latent action
  149. *
  150. * @param in_BankName The bank to load
  151. * @param LoadBankLatentAction Blueprint Latent action to flag completion
  152. * @param out_bankID Returned bank ID
  153. * @return Result from ak sound engine
  154. */
  155. AKRESULT LoadBank(
  156. const FString& in_BankName,
  157. FWaitEndBankAction* LoadBankLatentAction
  158. );
  159. /**
  160. * Load a sound bank from a memory pointer
  161. *
  162. * @param in_MemoryPtr Pointer to the bank data
  163. * @param in_MemorySize Size of the bank data
  164. * @param out_banKID Returned bank ID
  165. */
  166. AKRESULT LoadBankFromMemory(
  167. const void* MemoryPtr,
  168. uint32 MemorySize,
  169. AkBankType BankType,
  170. AkBankID& OutBankID
  171. );
  172. /**
  173. * Load a soundbank asynchronously, using a Blueprint Delegate for completion
  174. *
  175. * @param in_BankName The bank to load
  176. * @param BankLoadedCallback Blueprint Delegate called upon completion
  177. * @param out_bankID Returned bank ID
  178. * @return Result from ak sound engine
  179. */
  180. AKRESULT LoadBankAsync(
  181. const FString& in_BankName,
  182. const FOnAkBankCallback& BankLoadedCallback,
  183. AkBankID & out_bankID
  184. );
  185. /**
  186. * Unload a soundbank by its name
  187. *
  188. * @param in_BankName The name of the bank to unload
  189. * @return Result from ak sound engine
  190. */
  191. AKRESULT UnloadBank(
  192. const FString& in_BankName
  193. );
  194. /**
  195. * Unload a soundbank asynchronously
  196. *
  197. * @param in_BankName The bank to unload
  198. * @param in_pfnBankCallback Callback function
  199. * @param in_pCookie Callback cookie (reserved to user, passed to the callback function)
  200. * @return Result from ak sound engine
  201. */
  202. AKRESULT UnloadBank(
  203. const FString& in_BankName,
  204. AkBankCallbackFunc in_pfnBankCallback,
  205. void * in_pCookie
  206. );
  207. /**
  208. * Unload a soundbank asynchronously, flagging completion in the latent action
  209. *
  210. * @param in_BankName The bank to unload
  211. * @param UnloadBankLatentAction Blueprint Latent action to flag completion
  212. * @return Result from ak sound engine
  213. */
  214. AKRESULT UnloadBank(
  215. const FString& in_BankName,
  216. FWaitEndBankAction* UnloadBankLatentAction
  217. );
  218. /**
  219. * Unload bank with bank data pointer
  220. *
  221. * @param in_bankID The BankID returned by the LoadBankFromMemory call.
  222. * @param in_memoryPtr The same bank data pointer used with th LoadBankFromMemory call.
  223. */
  224. AKRESULT UnloadBankFromMemory(
  225. AkBankID in_bankID,
  226. const void* in_memoryPtr
  227. );
  228. /**
  229. * Unload bank with bank data pointer
  230. *
  231. * @param in_bankID The BankID returned by the LoadBankFromMemory call.
  232. * @param in_memoryPtr The same bank data pointer used with th LoadBankFromMemory call.
  233. */
  234. AKRESULT UnloadBankFromMemoryAsync(
  235. AkBankID in_bankID,
  236. const void* in_memoryPtr,
  237. AkBankCallbackFunc in_pfnBankCallback,
  238. void* in_pCookie,
  239. uint32 BankType
  240. );
  241. /**
  242. * Unload a soundbank asynchronously, using a Blueprint Delegate for completion
  243. *
  244. * @param in_BankName The bank to load
  245. * @param BankUnloadedCallback Blueprint Delegate called upon completion
  246. * @param out_bankID Returned bank ID
  247. * @return Result from ak sound engine
  248. */
  249. AKRESULT UnloadBankAsync(
  250. const FString& in_BankName,
  251. const FOnAkBankCallback& BankUnloadedCallback
  252. );
  253. /**
  254. * FString-friendly GetIDFromString
  255. */
  256. static AkUInt32 GetShortIDFromString(const FString& InString);
  257. /**
  258. * NUll-check asset and if invalid return ID based on BackupName
  259. */
  260. static AkUInt32 GetShortID(UAkAudioType* AudioAsset, const FString& BackupName);
  261. /**
  262. * Indicates the location of a specific Media ID in memory.
  263. *
  264. * @param in_pSourceSettings Array of Source Settings
  265. * @param in_uNumSourceSettings Number of Source Settings in the array
  266. */
  267. AKRESULT SetMedia(AkSourceSettings* in_pSourceSettings, uint32 in_uNumSourceSettings);
  268. /**
  269. * Removes the specified source from the list of loaded media, even if this media is already in use.
  270. *
  271. * @param in_pSourceSettings Array of Source Settings
  272. * @param in_uNumSourceSettings Number of Source Settings in the array
  273. * @param out_pUnsetResults Array of AKRESULT results per Source Settings
  274. */
  275. AKRESULT TryUnsetMedia(AkSourceSettings* in_pSourceSettings, uint32 in_uNumSourceSettings, AKRESULT* out_pUnsetResults = nullptr);
  276. /**
  277. * Removes the specified source from the list of loaded media.
  278. *
  279. * @param in_pSourceSettings Array of Source Settings
  280. * @param un_uNumSourceSettings Number of Source Settings in the array
  281. */
  282. AKRESULT UnsetMedia(AkSourceSettings* in_pSourceSettings, uint32 in_uNumSourceSettings);
  283. /**
  284. * Get the currently selected audio culture
  285. */
  286. FString GetCurrentAudioCulture() const;
  287. /**
  288. * Get the default language set in the Wwise project
  289. */
  290. FString GetDefaultLanguage();
  291. /**
  292. * Get the list of available audio cultures
  293. */
  294. TArray<FString> GetAvailableAudioCultures() const;
  295. /**
  296. * Get a FWwiseSharedLanguageId from the name as set in Wwise
  297. */
  298. FWwiseLanguageCookedData GetLanguageCookedDataFromString(const FString& WwiseLanguage);
  299. /**
  300. * Change the audio culture
  301. */
  302. void SetCurrentAudioCulture(const FString& AudioCulture);
  303. /**
  304. * Change the audio culture asynchronously and signal the latent action when done
  305. */
  306. void SetCurrentAudioCultureAsync(const FString& AudioCulture, FSetCurrentAudioCultureAction* LatentAction);
  307. /**
  308. * Change the audio culture asynchronous and call the callback when done
  309. */
  310. void SetCurrentAudioCultureAsync(const FString& AudioCulture, const FOnSetCurrentAudioCultureCompleted& CompletedCallback);
  311. /** Spawn an AkComponent at a location. Allows, for example, to set a switch on a fire and forget sound.
  312. * @param AkEvent - Wwise Event to post.
  313. * @param Location - Location from which to post the Wwise Event.
  314. * @param Orientation - Orientation of the event.
  315. * @param AutoPost - Automatically post the event once the AkComponent is created.
  316. * @param EarlyReflectionsBusName - Use the provided auxiliary bus to process early reflections. If empty, no early reflections will be processed.
  317. * @param AutoDestroy - Automatically destroy the AkComponent once the event is finished.
  318. */
  319. class UAkComponent* SpawnAkComponentAtLocation( class UAkAudioEvent* AkEvent, FVector Location, FRotator Orientation, bool AutoPost, const FString& EventName, bool AutoDestroy, class UWorld* in_World );
  320. /** Seek on an event in the ak soundengine.
  321. * @param EventShortID ID of the event on which to seek.
  322. * @param Component The associated Actor.
  323. * @param Position Desired percent where playback should restart.
  324. * @param bSeekToNearestMarker If true, the final seeking position will be made equal to the nearest marker.
  325. *
  326. * @return Success or failure.
  327. */
  328. AKRESULT SeekOnEvent(
  329. const AkUInt32 EventShortID,
  330. AActor* Actor,
  331. AkReal32 Percent,
  332. bool bSeekToNearestMarker = false,
  333. AkPlayingID PlayingID = AK_INVALID_PLAYING_ID
  334. );
  335. /** Seek on an event in the ak soundengine.
  336. * @param EventShortID ID of the event on which to seek.
  337. * @param Component The associated AkComponent.
  338. * @param Percent Desired percent where playback should restart.
  339. * @param bSeekToNearestMarker If true, the final seeking position will be made equal to the nearest marker.
  340. *
  341. * @return Success or failure.
  342. */
  343. AKRESULT SeekOnEvent(
  344. const AkUInt32 EventShortID,
  345. UAkComponent* Component,
  346. AkReal32 Percent,
  347. bool bSeekToNearestMarker = false,
  348. AkPlayingID PlayingID = AK_INVALID_PLAYING_ID
  349. );
  350. /**
  351. * Post a trigger to ak soundengine
  352. *
  353. * @param in_pszTrigger Name of the trigger
  354. * @param in_pAkComponent AkComponent on which to post the trigger
  355. * @return Result from ak sound engine
  356. */
  357. AKRESULT PostTrigger(
  358. const TCHAR * in_pszTrigger,
  359. AActor * in_pActor
  360. );
  361. /**
  362. * Post a trigger to ak soundengine
  363. *
  364. * @param in_TriggerValue Trigger value
  365. * @param in_pAkComponent AkComponent on which to post the trigger
  366. * @return Result from ak sound engine
  367. */
  368. AKRESULT PostTrigger(
  369. class UAkTrigger const* in_TriggerValue,
  370. AActor * in_pActor
  371. );
  372. /**
  373. * Set a RTPC in ak soundengine
  374. *
  375. * @param in_pszRtpcName Name of the RTPC
  376. * @param in_value Value to set
  377. * @param in_interpolationTimeMs - Duration during which the RTPC is interpolated towards in_value (in ms)
  378. * @param in_pActor AActor on which to set the RTPC
  379. * @return Result from ak sound engine
  380. */
  381. AKRESULT SetRTPCValue(
  382. const TCHAR * in_pszRtpcName,
  383. AkRtpcValue in_value,
  384. int32 in_interpolationTimeMs,
  385. AActor * in_pActor
  386. );
  387. /**
  388. * Set a RTPC in ak soundengine
  389. *
  390. * @param in_Rtpc RTPC Short ID
  391. * @param in_value Value to set
  392. * @param in_interpolationTimeMs - Duration during which the RTPC is interpolated towards in_value (in ms)
  393. * @param in_pActor AActor on which to set the RTPC
  394. * @return Result from ak sound engine
  395. */
  396. AKRESULT SetRTPCValue(
  397. AkRtpcID in_Rtpc,
  398. AkRtpcValue in_value,
  399. int32 in_interpolationTimeMs,
  400. AActor * in_pActor
  401. );
  402. /**
  403. * Set a RTPC in ak soundengine
  404. *
  405. * @param in_RtpcValue RTPC Value
  406. * @param in_value Value to set
  407. * @param in_interpolationTimeMs - Duration during which the RTPC is interpolated towards in_value (in ms)
  408. * @param in_pActor AActor on which to set the RTPC
  409. * @return Result from ak sound engine
  410. */
  411. AKRESULT SetRTPCValue(
  412. class UAkRtpc const* in_RtpcValue,
  413. AkRtpcValue in_value,
  414. int32 in_interpolationTimeMs,
  415. AActor * in_pActor
  416. );
  417. /**
  418. * Set a RTPC in ak soundengine by PlayingID
  419. *
  420. * @param in_Rtpc RTPC Short ID
  421. * @param in_value Value to set
  422. * @param in_playingID PlayingID on which to set the value
  423. * @param in_interpolationTimeMs - Duration during which the RTPC is interpolated towards in_value (in ms)
  424. * @return Result from ak sound engine
  425. */
  426. AKRESULT SetRTPCValueByPlayingID(
  427. AkRtpcID in_Rtpc,
  428. AkRtpcValue in_value,
  429. AkPlayingID in_playingID,
  430. int32 in_interpolationTimeMs
  431. );
  432. /**
  433. * Get the value of a real-time parameter control (by ID)
  434. * An RTPC can have a any combination of a global value, a unique value for each game object, or a unique value for each playing ID.
  435. * The value requested is determined by RTPCValue_type, in_gameObjectID and in_playingID.
  436. * If a value at the requested scope (determined by RTPCValue_type) is not found, the value that is available at the the next broadest scope will be returned, and io_rValueType will be changed to indicate this.
  437. * @note
  438. * When looking up RTPC values via playing ID (ie. io_rValueType is RTPC_PlayingID), in_gameObjectID can be set to a specific game object (if it is available to the caller) to use as a fall back value.
  439. * If the game object is unknown or unavailable, AK_INVALID_GAME_OBJECT can be passed in in_gameObjectID, and the game object will be looked up via in_playingID.
  440. * However in this case, it is not possible to retrieve a game object value as a fall back value if the playing id does not exist. It is best to pass in the game object if possible.
  441. *
  442. * @return AK_Success if succeeded, AK_IDNotFound if the game object was not registered, or AK_Fail if the RTPC value could not be obtained
  443. */
  444. AKRESULT GetRTPCValue(
  445. const TCHAR * in_pszRtpcName,
  446. AkGameObjectID in_gameObjectID, ///< Associated game object ID, ignored if io_rValueType is RTPCValue_Global.
  447. AkPlayingID in_playingID, ///< Associated playing ID, ignored if io_rValueType is not RTPC_PlayingID.
  448. AkRtpcValue& out_rValue, ///< Value returned
  449. AK::SoundEngine::Query::RTPCValue_type& io_rValueType ///< In/Out value, the user must specify the requested type. The function will return in this variable the type of the returned value. );
  450. );
  451. /**
  452. * Get the value of a real-time parameter control (by ID)
  453. * An RTPC can have a any combination of a global value, a unique value for each game object, or a unique value for each playing ID.
  454. * The value requested is determined by RTPCValue_type, in_gameObjectID and in_playingID.
  455. * If a value at the requested scope (determined by RTPCValue_type) is not found, the value that is available at the the next broadest scope will be returned, and io_rValueType will be changed to indicate this.
  456. * @note
  457. * When looking up RTPC values via playing ID (ie. io_rValueType is RTPC_PlayingID), in_gameObjectID can be set to a specific game object (if it is available to the caller) to use as a fall back value.
  458. * If the game object is unknown or unavailable, AK_INVALID_GAME_OBJECT can be passed in in_gameObjectID, and the game object will be looked up via in_playingID.
  459. * However in this case, it is not possible to retrieve a game object value as a fall back value if the playing id does not exist. It is best to pass in the game object if possible.
  460. *
  461. * @return AK_Success if succeeded, AK_IDNotFound if the game object was not registered, or AK_Fail if the RTPC value could not be obtained
  462. */
  463. AKRESULT GetRTPCValue(
  464. AkRtpcID in_Rtpc,
  465. AkGameObjectID in_gameObjectID, ///< Associated game object ID, ignored if io_rValueType is RTPCValue_Global.
  466. AkPlayingID in_playingID, ///< Associated playing ID, ignored if io_rValueType is not RTPC_PlayingID.
  467. AkRtpcValue& out_rValue, ///< Value returned
  468. AK::SoundEngine::Query::RTPCValue_type& io_rValueType ///< In/Out value, the user must specify the requested type. The function will return in this variable the type of the returned value. );
  469. );
  470. /**
  471. * Get the value of a real-time parameter control (by ID)
  472. * An RTPC can have a any combination of a global value, a unique value for each game object, or a unique value for each playing ID.
  473. * The value requested is determined by RTPCValue_type, in_gameObjectID and in_playingID.
  474. * If a value at the requested scope (determined by RTPCValue_type) is not found, the value that is available at the the next broadest scope will be returned, and io_rValueType will be changed to indicate this.
  475. * @note
  476. * When looking up RTPC values via playing ID (ie. io_rValueType is RTPC_PlayingID), in_gameObjectID can be set to a specific game object (if it is available to the caller) to use as a fall back value.
  477. * If the game object is unknown or unavailable, AK_INVALID_GAME_OBJECT can be passed in in_gameObjectID, and the game object will be looked up via in_playingID.
  478. * However in this case, it is not possible to retrieve a game object value as a fall back value if the playing id does not exist. It is best to pass in the game object if possible.
  479. *
  480. * @return AK_Success if succeeded, AK_IDNotFound if the game object was not registered, or AK_Fail if the RTPC value could not be obtained
  481. */
  482. AKRESULT GetRTPCValue(
  483. class UAkRtpc const* in_RtpcValue,
  484. AkGameObjectID in_gameObjectID, ///< Associated game object ID, ignored if io_rValueType is RTPCValue_Global.
  485. AkPlayingID in_playingID, ///< Associated playing ID, ignored if io_rValueType is not RTPC_PlayingID.
  486. AkRtpcValue& out_rValue, ///< Value returned
  487. AK::SoundEngine::Query::RTPCValue_type& io_rValueType ///< In/Out value, the user must specify the requested type. The function will return in this variable the type of the returned value. );
  488. );
  489. /// Resets the value of the game parameter to its default value, as specified in the Wwise project.
  490. /// With this function, you may reset a game parameter to its default value with global scope or with game object scope.
  491. /// Game object scope supersedes global scope. Game parameter values reset with global scope are applied to all
  492. /// game objects that were not overridden with a value with game object scope.
  493. /// To reset a game parameter value with global scope, pass AK_INVALID_GAME_OBJECT as the game object.
  494. /// With this function, you may also reset the value of a game parameter over time. To do so, specify a non-zero
  495. /// value for in_interpolationTimeMs. At each audio frame, the game parameter value will be updated internally
  496. /// according to the interpolation curve. If you call SetRTPCValue() or ResetRTPCValue() with in_interpolationTimeMs = 0 in the
  497. /// middle of an interpolation, the interpolation stops and the new value is set directly.
  498. AKRESULT ResetRTPCValue(
  499. const UAkRtpc* in_RtpcValue,
  500. AkGameObjectID in_gameObjectID,
  501. int32 in_interpolationTimeMs
  502. );
  503. /// Resets the value of the game parameter to its default value, as specified in the Wwise project.
  504. /// With this function, you may reset a game parameter to its default value with global scope or with game object scope.
  505. /// Game object scope supersedes global scope. Game parameter values reset with global scope are applied to all
  506. /// game objects that were not overridden with a value with game object scope.
  507. /// To reset a game parameter value with global scope, pass AK_INVALID_GAME_OBJECT as the game object.
  508. /// With this function, you may also reset the value of a game parameter over time. To do so, specify a non-zero
  509. /// value for in_interpolationTimeMs. At each audio frame, the game parameter value will be updated internally
  510. /// according to the interpolation curve. If you call SetRTPCValue() or ResetRTPCValue() with in_interpolationTimeMs = 0 in the
  511. /// middle of an interpolation, the interpolation stops and the new value is set directly.
  512. AKRESULT ResetRTPCValue(
  513. AkRtpcID in_rtpcID, ///< ID of the game parameter
  514. AkGameObjectID in_gameObjectID, ///< Associated game object ID
  515. int32 in_interpolationTimeMs ///< Duration during which the game parameter is interpolated towards its default value
  516. );
  517. /// Resets the value of the game parameter to its default value, as specified in the Wwise project.
  518. /// With this function, you may reset a game parameter to its default value with global scope or with game object scope.
  519. /// Game object scope supersedes global scope. Game parameter values reset with global scope are applied to all
  520. /// game objects that were not overridden with a value with game object scope.
  521. /// To reset a game parameter value with global scope, pass AK_INVALID_GAME_OBJECT as the game object.
  522. /// With this function, you may also reset the value of a game parameter over time. To do so, specify a non-zero
  523. /// value for in_interpolationTimeMs. At each audio frame, the game parameter value will be updated internally
  524. /// according to the interpolation curve. If you call SetRTPCValue() or ResetRTPCValue() with in_interpolationTimeMs = 0 in the
  525. /// middle of an interpolation, the interpolation stops and the new value is set directly.
  526. AKRESULT ResetRTPCValue(
  527. const TCHAR * in_pszRtpcName, ///< Name of the game parameter
  528. AkGameObjectID in_gameObjectID, ///< Associated game object ID
  529. int32 in_interpolationTimeMs ///< Duration during which the game parameter is interpolated towards its default value
  530. );
  531. /**
  532. * Set a state in ak soundengine
  533. *
  534. * @param in_pszStateGroup Name of the state group
  535. * @param in_pszState Name of the state
  536. * @return Result from ak sound engine
  537. */
  538. AKRESULT SetState(
  539. const TCHAR* in_pszStateGroup,
  540. const TCHAR* in_pszState
  541. );
  542. /**
  543. * Set a state in ak soundengine
  544. *
  545. * @param in_StateGroup State group short ID
  546. * @param in_State State short ID
  547. * @return Result from ak sound engine
  548. */
  549. AKRESULT SetState(
  550. AkStateGroupID in_StateGroup,
  551. AkStateID in_State
  552. );
  553. /**
  554. * Set a state in ak soundengine
  555. *
  556. * @param in_stateValue State to set
  557. * @return Result from ak sound engine
  558. */
  559. AKRESULT SetState(
  560. const UAkStateValue* in_stateValue
  561. );
  562. /**
  563. * Set a switch in ak soundengine
  564. *
  565. * @param in_pszSwitchGroup Name of the switch group
  566. * @param in_pszSwitchState Name of the switch
  567. * @param in_pComponent AkComponent on which to set the switch
  568. * @return Result from ak sound engine
  569. */
  570. AKRESULT SetSwitch(
  571. const TCHAR * in_pszSwitchGroup,
  572. const TCHAR * in_pszSwitchState,
  573. AActor * in_pActor
  574. );
  575. /**
  576. * Set a switch in ak soundengine
  577. *
  578. * @param in_SwitchGroup Short ID of the switch group
  579. * @param in_SwitchState Short ID of the switch
  580. * @param in_pComponent AkComponent on which to set the switch
  581. * @return Result from ak sound engine
  582. */
  583. AKRESULT SetSwitch(
  584. AkSwitchGroupID in_SwitchGroup,
  585. AkSwitchStateID in_SwitchState,
  586. AActor* in_pActor
  587. );
  588. /**
  589. * Set a switch in ak soundengine
  590. *
  591. * @param in_switchValue Switch to set
  592. * @param in_pActor AkActor on which to set the switch
  593. * @return Result from ak sound engine
  594. */
  595. AKRESULT SetSwitch(
  596. const UAkSwitchValue* in_switchValue,
  597. AActor * in_pActor
  598. );
  599. /** Sets multiple positions to a single game object.
  600. * Setting multiple positions on a single game object is a way to simulate multiple emission sources while using the resources of only one voice.
  601. * This can be used to simulate wall openings, area sounds, or multiple objects emitting the same sound in the same area.
  602. * Note: Calling AK::SoundEngine::SetMultiplePositions() with only one position is the same as calling AK::SoundEngine::SetPosition()
  603. * @param in_pGameObjectAkComponent UAkComponent of the game object.
  604. * @param in_aPositions Array of positions to apply.
  605. * @param in_eMultiPositionType Position type
  606. * @return AK_Success when successful, AK_InvalidParameter if parameters are not valid.
  607. */
  608. AKRESULT SetMultiplePositions(
  609. UAkComponent* in_pGameObjectAkComponent,
  610. TArray<FTransform> in_aPositions,
  611. AkMultiPositionType in_eMultiPositionType = AkMultiPositionType::MultiDirections
  612. );
  613. /** Sets multiple positions to a single game object, with flexible assignment of input channels.
  614. * Setting multiple positions on a single game object is a way to simulate multiple emission sources while using the resources of only one voice.
  615. * This can be used to simulate wall openings, area sounds, or multiple objects emitting the same sound in the same area.
  616. * Note: Calling AK::SoundEngine::SetMultiplePositions() with only one position is the same as calling AK::SoundEngine::SetPosition()
  617. * @param in_pGameObjectAkComponent Game Object AkComponent.
  618. * @param in_aChannelConfigurations Array of channel configurations for each position.
  619. * @param in_pPositions Array of positions to apply.
  620. * @param in_eMultiPositionType Position type
  621. * @return AK_Success when successful, AK_InvalidParameter if parameters are not valid.
  622. */
  623. AKRESULT SetMultiplePositions(
  624. UAkComponent* in_pGameObjectAkComponent,
  625. const TArray<AkChannelConfiguration>& in_aChannelConfigurations,
  626. const TArray<FTransform>& in_aPositions,
  627. AkMultiPositionType in_eMultiPositionType = AkMultiPositionType::MultiDirections
  628. );
  629. /** Sets multiple positions to a single game object, with flexible assignment of input channels.
  630. * Setting multiple positions on a single game object is a way to simulate multiple emission sources while using the resources of only one voice.
  631. * This can be used to simulate wall openings, area sounds, or multiple objects emitting the same sound in the same area.
  632. * Note: Calling AK::SoundEngine::SetMultiplePositions() with only one position is the same as calling AK::SoundEngine::SetPosition()
  633. * @param in_pGameObjectAkComponent Game Object AkComponent.
  634. * @param in_channelMasks Array of channel mask for each position.
  635. * @param in_pPositions Array of positions to apply.
  636. * @param in_eMultiPositionType Position type
  637. * @return AK_Success when successful, AK_InvalidParameter if parameters are not valid.
  638. */
  639. AKRESULT SetMultiplePositions(
  640. UAkComponent* in_pGameObjectAkComponent,
  641. const TArray<FAkChannelMask>& in_channelMasks,
  642. const TArray<FTransform>& in_aPositions,
  643. AkMultiPositionType in_eMultiPositionType = AkMultiPositionType::MultiDirections
  644. );
  645. /** Sets multiple positions to a single game object.
  646. * Setting multiple positions on a single game object is a way to simulate multiple emission sources while using the resources of only one voice.
  647. * This can be used to simulate wall openings, area sounds, or multiple objects emitting the same sound in the same area.
  648. * Note: Calling AK::SoundEngine::SetMultiplePositions() with only one position is the same as calling AK::SoundEngine::SetPosition()
  649. * @param in_GameObjectID Game Object identifier.
  650. * @param in_pPositions Array of positions to apply.
  651. * @param in_NumPositions Number of positions specified in the provided array.
  652. * @param in_eMultiPositionType Position type
  653. * @return AK_Success when successful, AK_InvalidParameter if parameters are not valid.
  654. *
  655. */
  656. AKRESULT SetMultiplePositions(
  657. AkGameObjectID in_GameObjectID,
  658. const AkSoundPosition * in_pPositions,
  659. AkUInt16 in_NumPositions,
  660. AK::SoundEngine::MultiPositionType in_eMultiPositionType = AK::SoundEngine::MultiPositionType_MultiDirections
  661. );
  662. /** Sets multiple positions to a single game object, with flexible assignment of input channels.
  663. * Setting multiple positions on a single game object is a way to simulate multiple emission sources while using the resources of only one voice.
  664. * This can be used to simulate wall openings, area sounds, or multiple objects emitting the same sound in the same area.
  665. * Note: Calling AK::SoundEngine::SetMultiplePositions() with only one position is the same as calling AK::SoundEngine::SetPosition()
  666. * @param in_GameObjectID Game Object identifier.
  667. * @param in_pPositions Array of positions to apply.
  668. * @param in_NumPositions Number of positions specified in the provided array.
  669. * @param in_eMultiPositionType Position type
  670. * @return AK_Success when successful, AK_InvalidParameter if parameters are not valid.
  671. */
  672. AKRESULT SetMultiplePositions(
  673. AkGameObjectID in_GameObjectID,
  674. const AkChannelEmitter * in_pPositions,
  675. AkUInt16 in_NumPositions,
  676. AK::SoundEngine::MultiPositionType in_eMultiPositionType = AK::SoundEngine::MultiPositionType_MultiDirections
  677. );
  678. /**
  679. * Set auxiliary sends
  680. *
  681. * @param in_GameObjId Wwise Game Object ID
  682. * @param in_AuxSendValues Array of AkAuxSendValue, containing all Aux Sends to set on the game object
  683. * @return Result from ak sound engine
  684. */
  685. AKRESULT SetAuxSends(
  686. const UAkComponent* in_akComponent,
  687. TArray<AkAuxSendValue>& in_AuxSendValues
  688. );
  689. /**
  690. * Set spatial audio room
  691. *
  692. * @param in_GameObjId Wwise Game Object ID
  693. * @param in_RoomID ID of the room that the game object is inside.
  694. * @return Result from ak sound engine
  695. */
  696. AKRESULT SetInSpatialAudioRoom(
  697. const AkGameObjectID in_GameObjId,
  698. AkRoomID in_RoomID
  699. );
  700. /**
  701. * Force channel configuration for the specified bus.
  702. * This function has unspecified behavior when changing the configuration of a bus that
  703. * is currently playing.
  704. * You cannot change the configuration of the master bus.
  705. *
  706. * @param in_BusName Bus Name
  707. * @param in_Config Desired channel configuration. An invalid configuration (from default constructor) means "as parent".
  708. * @return Always returns AK_Success
  709. */
  710. AKRESULT SetBusConfig(
  711. const FString& in_BusName,
  712. AkChannelConfig in_Config
  713. );
  714. /**
  715. * Set the panning rule of the specified output.
  716. * This may be changed anytime once the sound engine is initialized.
  717. * \warning This function posts a message through the sound engine's internal message queue, whereas GetPanningRule() queries the current panning rule directly.
  718. */
  719. AKRESULT SetPanningRule(
  720. AkPanningRule in_ePanningRule ///< Panning rule.
  721. );
  722. /**
  723. * Gets the compounded output ID from ShareSet and device id.
  724. * Outputs are defined by their type (Audio Device ShareSet) and their specific system ID.
  725. * A system ID could be reused for other device types on some OS or platforms, hence the compounded ID.
  726. *
  727. * @param in_szShareSet Audio Device ShareSet Name, as defined in the Wwise Project. If Null, will select the Default Output ShareSet (always available)
  728. * @param in_idDevice Device specific identifier, when multiple devices of the same type are possible. If only one device is possible, leave to 0.
  729. * @return The id of the output
  730. */
  731. AkOutputDeviceID GetOutputID(
  732. const FString& in_szShareSet,
  733. AkUInt32 in_idDevice = 0
  734. );
  735. /**
  736. * Replaces the main output device previously created during engine initialization with a new output device.
  737. * In addition to simply removing one output device and adding a new one, the new output device will also be used on all of the master busses
  738. * that the old output device was associated with, and preserve all listeners that were attached to the old output device.
  739. *
  740. * @param MainOutputSettings Creation parameters for this output
  741. *
  742. * @return
  743. * - AK_InvalidID: The audioDeviceShareSet on in_settings was not valid.
  744. * - AK_IDNotFound: The audioDeviceShareSet on in_settings doesn't exist. Possibly, the Init bank isn't loaded yet or was not updated with latest changes.
  745. * - AK_DeviceNotReady: The idDevice on in_settings doesn't match with a valid hardware device. Either the device doesn't exist or is disabled. Disconnected devices (headphones) are not considered "not ready" therefore won't cause this error.
  746. * - AK_DeviceNotFound: The in_outputDeviceId provided does not match with any of the output devices that the sound engine is currently using.
  747. * - AK_InvalidParameter: Out of range parameters or unsupported parameter combinations on in_settings
  748. * - AK_Success: parameters were valid, and the remove and add will occur.
  749. */
  750. AKRESULT ReplaceMainOutput(const AkOutputSettings& MainOutputSettings);
  751. /**
  752. * Gets speaker angles of the specified device. Speaker angles are used for 3D positioning of sounds over standard configurations.
  753. * Note that the current version of Wwise only supports positioning on the plane.
  754. * The speaker angles are expressed as an array of loudspeaker pairs, in degrees, relative to azimuth ]0,180].
  755. * Supported loudspeaker setups are always symmetric; the center speaker is always in the middle and thus not specified by angles.
  756. * Angles must be set in ascending order.
  757. * Typical usage:
  758. * - AkReal32 heightAngle;
  759. * - TArray<AkReal32> speakerAngles;
  760. * - GetSpeakerAngles(speakerAngles, heightAngle, AkOutput_Main );
  761. * \aknote
  762. * On most platforms, the angle set on the plane consists of 3 angles, to account for 7.1.
  763. * - When panning to stereo (speaker mode, see <tt>AK::SoundEngine::SetPanningRule()</tt>), only angle[0] is used, and 3D sounds in the back of the listener are mirrored to the front.
  764. * - When panning to 5.1, the front speakers use angle[0], and the surround speakers use (angle[2] - angle[1]) / 2.
  765. * \endaknote
  766. * \warning Call this function only after the sound engine has been properly initialized.
  767. *
  768. * @param io_pfSpeakerAngles Returned array of loudspeaker pair angles, in degrees relative to azimuth [0,180]. Pass NULL to get the required size of the array.
  769. * @param out_fHeightAngle Elevation of the height layer, in degrees relative to the plane [-90,90].
  770. * @param in_idOutput Output ID to set the bus on. As returned from AddOutput or GetOutputID. You can pass 0 for the main (default) output
  771. * @return AK_Success if device exists
  772. *
  773. */
  774. AKRESULT GetSpeakerAngles(
  775. TArray<AkReal32>& io_pfSpeakerAngles,
  776. AkReal32& out_fHeightAngle,
  777. AkOutputDeviceID in_idOutput = 0
  778. );
  779. /**
  780. * Sets speaker angles of the specified device. Speaker angles are used for 3D positioning of sounds over standard configurations.
  781. * Note that the current version of Wwise only supports positioning on the plane.
  782. * The speaker angles are expressed as an array of loudspeaker pairs, in degrees, relative to azimuth ]0,180].
  783. * Supported loudspeaker setups are always symmetric; the center speaker is always in the middle and thus not specified by angles.
  784. * Angles must be set in ascending order.
  785. * Typical usage:
  786. * - Initialize the sound engine and/or add secondary output(s).
  787. * - Get number of speaker angles and their value into an array using GetSpeakerAngles().
  788. * - Modify the angles and call SetSpeakerAngles().
  789. * This function posts a message to the audio thread through the command queue, so it is thread safe. However the result may not be immediately read with GetSpeakerAngles().
  790. * \warning This function only applies to configurations (or subset of these configurations) that are standard and whose speakers are on the plane (2D).
  791. * \sa GetSpeakerAngles()
  792. *
  793. * @param in_pfSpeakerAngles Array of loudspeaker pair angles, in degrees relative to azimuth [0,180]
  794. * @param in_fHeightAngle Elevation of the height layer, in degrees relative to the plane [-90,90]
  795. * @param in_idOutput Output ID to set the bus on. As returned from AddOutput or GetOutputID. You can pass 0 for the main (default) output
  796. * @return AK_Success if successful (device exists and angles are valid), AK_NotCompatible if the channel configuration of the device is not standard (AK_ChannelConfigType_Standard), AK_Fail otherwise.
  797. *
  798. */
  799. AKRESULT SetSpeakerAngles(
  800. const TArray<AkReal32>& in_pfSpeakerAngles,
  801. AkReal32 in_fHeightAngle,
  802. AkOutputDeviceID in_idOutput = 0
  803. );
  804. /**
  805. * Set the output bus volume (direct) to be used for the specified game object.
  806. * The control value is a number ranging from 0.0f to 1.0f.
  807. *
  808. * @param in_GameObjId Wwise Game Object ID
  809. * @param in_fControlValue Control value to set
  810. * @return Always returns Ak_Success
  811. */
  812. AKRESULT SetGameObjectOutputBusVolume(
  813. const UAkComponent* in_pEmitter,
  814. const UAkComponent* in_pListener,
  815. float in_fControlValue
  816. );
  817. /**
  818. * Registers a callback that can run within the global callback at a specific AkGlobalCallbackLocation.
  819. *
  820. * @param Callback The callback that will be called.
  821. * @param Location The location in the sound engine processing loop
  822. * @return Returns the handle of the delegate that must be used to unregister the callback.
  823. */
  824. FDelegateHandle RegisterGlobalCallback(FAkAudioDeviceDelegates::FOnAkGlobalCallback::FDelegate Callback, AkGlobalCallbackLocation Location);
  825. /**
  826. * Unregisters a callback that can run within the global callback at a specific AkGlobalCallbackLocation.
  827. *
  828. * @param Handle The handle of the registered callback
  829. * @param Location The location in the sound engine processing loop
  830. */
  831. void UnregisterGlobalCallback(FDelegateHandle Handle, AkGlobalCallbackLocation Location);
  832. /**
  833. * Registers a callback to be called to allow the game to access metering data from any output device.
  834. * @param OutputID Output ID, as returned from AddOutput or GetOutputID. You can pass 0 for the main (default) output
  835. * @param Callback Callback function
  836. * @param MeteringFlags Metering flags
  837. * @param Cookie User cookie
  838. * @return AK_Success if callback has been registered
  839. */
  840. AKRESULT RegisterOutputDeviceMeteringCallback(AkOutputDeviceID OutputID,
  841. AkOutputDeviceMeteringCallbackFunc Callback,
  842. AkMeteringFlags MeteringFlags,
  843. void* Cookie);
  844. /**
  845. * Unregisters the output device's metering callback
  846. * @param OutputID
  847. * @return AK_Success if callback has been unregistered
  848. */
  849. AKRESULT UnregisterOutputDeviceMeteringCallback(AkOutputDeviceID OutputID);
  850. /**
  851. * Obtain a pointer to the singleton instance of FAkAudioDevice
  852. *
  853. * @return Pointer to the singleton instance of FAkAudioDevice
  854. */
  855. static FAkAudioDevice* Get();
  856. /**
  857. * Is the Wwise SoundEngine initialized?
  858. */
  859. static bool IsInitialized() { return m_bSoundEngineInitialized; }
  860. /**
  861. * Gets the system sample rate
  862. *
  863. * @return Sample rate
  864. */
  865. AkUInt32 GetSampleRate();
  866. /**
  867. * Enables/disables offline rendering
  868. *
  869. * @param bEnable Set to true to enable offline rendering
  870. */
  871. AKRESULT SetOfflineRendering(bool bEnable);
  872. /**
  873. * Sets the offline rendering frame time in seconds.
  874. *
  875. * @param FrameTimeInSeconds Frame time in seconds used during offline rendering
  876. */
  877. AKRESULT SetOfflineRenderingFrameTime(AkReal32 FrameTimeInSeconds);
  878. /**
  879. * Registers a callback used for retrieving audio samples.
  880. *
  881. * @param Callback Capture callback function to register
  882. * @param OutputId The audio device specific id, return by AK::SoundEngine::AddOutput or AK::SoundEngine::GetOutputID
  883. * @param Cookie Callback cookie that will be sent to the callback function along with additional information
  884. */
  885. AKRESULT RegisterCaptureCallback(AkCaptureCallbackFunc Callback, AkOutputDeviceID OutputId = AK_INVALID_OUTPUT_DEVICE_ID, void* Cookie = nullptr);
  886. /**
  887. * Unregisters a callback used for retrieving audio samples.
  888. *
  889. * @param Callback Capture callback function to register
  890. * @param OutputId The audio device specific id, return by AK::SoundEngine::AddOutput or AK::SoundEngine::GetOutputID
  891. * @param Cookie Callback cookie that will be sent to the callback function along with additional information
  892. */
  893. AKRESULT UnregisterCaptureCallback(AkCaptureCallbackFunc Callback, AkOutputDeviceID OutputId = AK_INVALID_OUTPUT_DEVICE_ID, void* Cookie = nullptr);
  894. /**
  895. * Stop all audio associated with a game object
  896. *
  897. * @param in_pComponent AkComponent which should be stopped
  898. */
  899. void StopGameObject(UAkComponent * in_pComponent);
  900. /**
  901. * Stop all audio associated with a playing ID
  902. *
  903. * @param in_playingID AkPlayingID which should be stopped
  904. */
  905. void StopPlayingID( AkPlayingID in_playingID,
  906. AkTimeMs in_uTransitionDuration = 0,
  907. AkCurveInterpolation in_eFadeCurve = AkCurveInterpolation_Linear);
  908. /**
  909. * Register an ak audio component with ak sound engine
  910. *
  911. * @param in_pComponent Pointer to the component to register
  912. */
  913. void RegisterComponent(UAkComponent * in_pComponent);
  914. /**
  915. * Register a game object with ak sound engine
  916. *
  917. * @param GameObjectID ID of the game object to register
  918. */
  919. void RegisterComponent(AkGameObjectID GameObjectID);
  920. /**
  921. * Unregister an ak audio component with ak sound engine
  922. *
  923. * @param in_pComponent Pointer to the component to unregister
  924. */
  925. void UnregisterComponent(UAkComponent * in_pComponent);
  926. /**
  927. * Unregister an ak game object with ak sound engine
  928. *
  929. * @param GameObjectID ID of the game object to unregister
  930. */
  931. void UnregisterComponent(AkGameObjectID GameObjectID);
  932. /**
  933. * Send a set of triangles to the Spatial Audio Engine
  934. */
  935. AKRESULT SetGeometry(AkGeometrySetID GeometrySetID, const AkGeometryParams& Params);
  936. /**
  937. * Create a geometry instance in Spatial Audio
  938. */
  939. AKRESULT SetGeometryInstance(AkGeometryInstanceID GeometryInstanceID, const AkGeometryInstanceParams& Params);
  940. /**
  941. * Remove a set of triangles from the Spatial Audio Engine
  942. */
  943. AKRESULT RemoveGeometrySet(AkGeometrySetID GeometrySetID);
  944. /**
  945. * Remove a geometry instance from Spatial Audio
  946. */
  947. AKRESULT RemoveGeometryInstance(AkGeometryInstanceID GeometryInstanceID);
  948. /**
  949. * Set the early reflections aux bus for an AK Component
  950. */
  951. AKRESULT SetEarlyReflectionsAuxBus(UAkComponent* in_pComponent, const AkUInt32 AuxBusID);
  952. /**
  953. * Set the early reflections send volume for an AK Component
  954. */
  955. AKRESULT SetEarlyReflectionsVolume(UAkComponent* in_pComponent, float in_fSendVolume);
  956. /**
  957. * Set the reflections order for the project
  958. */
  959. AKRESULT SetReflectionsOrder(int Order, bool RefreshPaths);
  960. /**
  961. * Sets a game object's obstruction and occlusion levels.
  962. */
  963. AKRESULT SetObjectObstructionAndOcclusion(AkGameObjectID in_Object, AkGameObjectID in_listener, AkReal32 Obstruction, AkReal32 Occlusion);
  964. /**
  965. * Sets a game object's obstruction and occlusion levels for each position defined by SetMultiplePositions.
  966. */
  967. AKRESULT SetMultipleObstructionAndOcclusion(AkGameObjectID in_Object, AkGameObjectID in_listener, AkObstructionOcclusionValues* ObstructionAndOcclusionValues, AkUInt32 in_uNumObstructionAndOcclusion);
  968. /**
  969. * Set obstruction and occlusion on sounds going through this portal
  970. */
  971. AKRESULT SetPortalObstructionAndOcclusion(const UAkPortalComponent* in_pPortal, float in_fObstructionValue, float in_fOcclusionValue);
  972. /**
  973. * Set obstruction on sounds from this game object going through this portal
  974. */
  975. AKRESULT SetGameObjectToPortalObstruction(const UAkComponent* in_pComponent, const UAkPortalComponent* in_pPortal, float in_fObstructionValue);
  976. /**
  977. * Set obstruction on sounds from a first portal going through the next portal
  978. */
  979. AKRESULT SetPortalToPortalObstruction(const UAkPortalComponent* in_pPortal0, const UAkPortalComponent* in_pPortal1, float in_fObstructionValue);
  980. /** @brief Sets an effect ShareSet on an output device
  981. *
  982. * Make sure the new effect ShareSet is included in a soundbank, and that sound bank is loaded. Otherwise you will see errors in the Capture Log.
  983. * This function will replace existing effects of the audio device ShareSet.
  984. * Audio device effects support is limited to one ShareSet per plug-in type at any time.
  985. * Errors are reported in the Wwise Capture Log if the effect cannot be set on the output device.
  986. * ShareSet must be in a loaded bank.
  987. *
  988. * @param InDeviceID Output ID, as returned from AddOutput or GetOutputID. You can pass 0 for the main (default) output
  989. * @param InFXIndex Effect slot index (0-3)
  990. * @param InFXShareSetID Effect ShareSet ID; pass AK_INVALID_UNIQUE_ID to use the effect from the Audio Device ShareSet.
  991. * @return Always returns AK_Success
  992. */
  993. AKRESULT SetOutputDeviceEffect(AkOutputDeviceID InDeviceID, AkUInt32 InFXIndex, AkUniqueID InFXShareSetID);
  994. /** @brief Sets an Effect ShareSet at the specified Bus and Effect slot index.
  995. *
  996. * The Bus can either be an Audio Bus or an Auxiliary Bus.
  997. * This adds a reference on the audio node to an existing ShareSet.
  998. * This function has unspecified behavior when adding an Effect to a currently playing
  999. * Bus which does not have any effects, or removing the last Effect on a currently playing bus.
  1000. * Make sure the new effect ShareSet is included in a soundbank, and that sound bank is loaded. Otherwise you will see errors in the Capture Log.
  1001. * This function will replace existing Effects on the node. If the target node is not at
  1002. * the top of the hierarchy and is in the Actor-Mixer Hierarchy, the option "Override Parent" in
  1003. * the Effect section in Wwise must be enabled for this node, otherwise the parent's Effect will
  1004. * still be the one in use and the call to SetBusEffect will have no impact.
  1005. * ShareSet must be in a loaded bank.
  1006. *
  1007. * @param InBusName Bus name
  1008. * @param InFXIndex Effect slot index (0-3)
  1009. * @param InFXShareSetID Effect ShareSet ID; pass AK_INVALID_UNIQUE_ID to clear the Effect slot
  1010. * @return - AK_Success when successfully posted, AK_IDNotFound if the Bus name doesn't point to a valid bus, AK_InvalidParameter if in_uFXIndex isn't in range.
  1011. */
  1012. AKRESULT SetBusEffect(const FString& InBusName, AkUInt32 InFXIndex, AkUniqueID InFXShareSetID);
  1013. /** @briefSets an Effect ShareSet at the specified Bus and Effect slot index.
  1014. *
  1015. * The Bus can either be an Audio Bus or an Auxiliary Bus.
  1016. * This adds a reference on the audio node to an existing ShareSet.
  1017. * This function has unspecified behavior when adding an Effect to a currently playing
  1018. * Bus which does not have any effects, or removing the last Effect on a currently playing bus.
  1019. * Make sure the new effect ShareSet is included in a soundbank, and that sound bank is loaded. Otherwise you will see errors in the Capture Log.
  1020. * This function will replace existing Effects on the node. If the target node is not at
  1021. * the top of the hierarchy and is in the Actor-Mixer Hierarchy, the option "Override Parent" in
  1022. * the Effect section in Wwise must be enabled for this node, otherwise the parent's Effect will
  1023. * still be the one in use and the call to SetBusEffect will have no impact.
  1024. * ShareSet must be in a loaded bank.
  1025. *
  1026. * @param InBusID Bus Short ID.
  1027. * @param InFXIndex Effect slot index (0-3)
  1028. * @param InFXShareSetID Effect ShareSet ID; pass AK_INVALID_UNIQUE_ID to clear the Effect slot
  1029. * @return AK_Success when successfully posted, AK_IDNotFound if the Bus name doesn't point to a valid bus, AK_InvalidParameter if in_uFXIndex isn't in range.
  1030. */
  1031. AKRESULT SetBusEffect(AkUniqueID InBusID, AkUInt32 InFXIndex, AkUniqueID InFXShareSetID);
  1032. /** @brief Sets an Effect ShareSet at the specified audio node and Effect slot index.
  1033. *
  1034. * The target node cannot be a Bus, to set effects on a bus, use SetBusEffect() instead.
  1035. * The option "Override Parent" in the Effect section in Wwise must be enabled for this node, otherwise the parent's effect will
  1036. * still be the one in use and the call to SetActorMixerEffect will have no impact.
  1037. * ShareSet must be in a loaded bank.
  1038. *
  1039. * @param InAudioNodeID Can be a member of the Actor-Mixer or Interactive Music Hierarchy (not a bus).
  1040. * @param InFXIndex Effect slot index (0-3)
  1041. * @param InShareSetID ShareSets ID; pass AK_INVALID_UNIQUE_ID to clear the effect slot
  1042. * @return Always returns AK_Success
  1043. */
  1044. AKRESULT SetActorMixerEffect(AkUniqueID InAudioNodeID, AkUInt32 InFXIndex, AkUniqueID InShareSetID);
  1045. AKRESULT SetActorMixerEffect(const FString& InBusName, AkUInt32 InFXIndex, AkUniqueID InFXShareSetID);
  1046. /**
  1047. * Get an ak audio component, or create it if none exists that fit the attachment criteria.
  1048. */
  1049. static class UAkComponent* GetAkComponent(
  1050. class USceneComponent* AttachToComponent, FName AttachPointName, const FVector * Location, EAttachLocation::Type LocationType);
  1051. static class UAkComponent* GetAkComponent(
  1052. class USceneComponent* AttachToComponent, FName AttachPointName, const FVector * Location, EAttachLocation::Type LocationType, bool& ComponentCreated);
  1053. /**
  1054. * Cancel the callback cookie for a dispatched event
  1055. *
  1056. * @param in_cookie The cookie to cancel
  1057. */
  1058. void CancelEventCallbackCookie(void* in_cookie);
  1059. void CancelEventCallbackDelegate(const FOnAkPostEventCallback& in_Delegate);
  1060. /**
  1061. * Set the scaling factor of a game object.
  1062. * Modify the attenuation computations on this game object to simulate sounds with a a larger or smaller area of effect.
  1063. */
  1064. AKRESULT SetAttenuationScalingFactor(AActor* Actor, float ScalingFactor);
  1065. /**
  1066. * Set the scaling factor of a AkComponent.
  1067. * Modify the attenuation computations on this game object to simulate sounds with a a larger or smaller area of effect.
  1068. */
  1069. AKRESULT SetAttenuationScalingFactor(UAkComponent* AkComponent, float ScalingFactor);
  1070. /**
  1071. * Use the position of a separate AkComponent for distance calculations for a specified listener.
  1072. * When <tt>SetDistanceProbe()</tt> is called, Wwise calculates distance attenuation and filtering
  1073. * based on the distance between the distance probe AkComponent and the sound source.
  1074. * In third-person perspective applications, the distance probe may be set to the player character's position,
  1075. * and the listener position to that of the camera. In this scenario, attenuation is based on
  1076. * the distance between the character and the sound, whereas panning, spatialization, and spread and focus calculations are base on the camera.
  1077. */
  1078. AKRESULT SetDistanceProbe(UAkComponent* Listener, UAkComponent* DistanceProbe);
  1079. /**
  1080. * Starts a Wwise output capture. The output file will be located in the same folder as the SoundBanks.
  1081. * @param Filename - The name to give to the output file.
  1082. */
  1083. void StartOutputCapture(const FString& Filename);
  1084. /**
  1085. * Add text marker in output capture file.
  1086. * @param MarkerText - The name text to put in the marker.
  1087. */
  1088. void AddOutputCaptureMarker(const FString& MarkerText);
  1089. /**
  1090. * Stops a Wwise output capture. The output file will be located in the same folder as the SoundBanks.
  1091. */
  1092. void StopOutputCapture();
  1093. /**
  1094. * Starts a Wwise profiler capture. The output file will be located in the same folder as the SoundBanks.
  1095. * @param Filename - The name to give to the output file.
  1096. */
  1097. void StartProfilerCapture(const FString& Filename);
  1098. /**
  1099. * Stops a Wwise profiler capture. The output file will be located in the same folder as the SoundBanks.
  1100. */
  1101. void StopProfilerCapture();
  1102. /**
  1103. * Allows to register a Wwise plugin from a DLL name and path
  1104. */
  1105. AKRESULT RegisterPluginDLL(const FString& in_DllName, const FString& in_DllPath);
  1106. /**
  1107. * Gets the path where the SoundBanks are located on disk
  1108. */
  1109. FString GetBasePath();
  1110. /**
  1111. * Suspends the SoundEngine
  1112. * @param in_bRenderAnyway If set to true, audio processing will still occur, but not outputted. When set to false, no audio will be processed at all, even upon reception of RenderAudio().
  1113. */
  1114. void Suspend(bool in_bRenderAnyway = false);
  1115. /**
  1116. * Return from a suspended state
  1117. */
  1118. void WakeupFromSuspend();
  1119. /**
  1120. * Event called when the Wwise project is modified
  1121. */
  1122. FOnWwiseProjectModification OnWwiseProjectModification;
  1123. static inline void FVectorToAKVector( const FVector & in_vect, AkVector & out_vect )
  1124. {
  1125. #if UE_5_0_OR_LATER
  1126. checkf(in_vect.X <= FLT_MAX && in_vect.Y <= FLT_MAX && in_vect.Z <= FLT_MAX, TEXT("FVectorToAKVector: Data truncation when converting from FVector to AkVector."));
  1127. #endif
  1128. out_vect.X = in_vect.X;
  1129. out_vect.Y = in_vect.Y;
  1130. out_vect.Z = in_vect.Z;
  1131. }
  1132. static inline AkVector FVectorToAKVector(const FVector& in_vect)
  1133. {
  1134. #if UE_5_0_OR_LATER
  1135. checkf(in_vect.X <= FLT_MAX && in_vect.Y <= FLT_MAX && in_vect.Z <= FLT_MAX, TEXT("FVectorToAKVector: Data truncation when converting from FVector to AkVector."));
  1136. #endif
  1137. return AkVector{ (float)in_vect.X, (float)in_vect.Y, (float)in_vect.Z };
  1138. }
  1139. static inline void FVectorToAKVector64( const FVector & in_vect, AkVector64 & out_vect )
  1140. {
  1141. out_vect.X = in_vect.X;
  1142. out_vect.Y = in_vect.Y;
  1143. out_vect.Z = in_vect.Z;
  1144. }
  1145. static inline AkVector64 FVectorToAKVector64(const FVector& in_vect)
  1146. {
  1147. return AkVector64{ in_vect.X, in_vect.Y, in_vect.Z };
  1148. }
  1149. static inline AkExtent FVectorToAkExtent(const FVector& in_vect)
  1150. {
  1151. #if UE_5_0_OR_LATER
  1152. checkf(in_vect.X <= FLT_MAX && in_vect.Y <= FLT_MAX && in_vect.Z <= FLT_MAX, TEXT("FVectorToAkExtent: Data truncation when converting from FVector to AkExtent."));
  1153. #endif
  1154. /* Unreal: right=y, up=z, front=x */
  1155. return AkExtent{ (float)in_vect.Y, (float)in_vect.Z, (float)in_vect.X };
  1156. }
  1157. static inline void FVectorsToAKWorldTransform(const FVector& in_Position, const FVector& in_Front, const FVector& in_Up, AkWorldTransform& out_AkTransform)
  1158. {
  1159. // Convert from the UE axis system to the Wwise axis system
  1160. out_AkTransform.Set(FVectorToAKVector64(in_Position), FVectorToAKVector(in_Front), FVectorToAKVector(in_Up));
  1161. }
  1162. static inline void AKVectorToFVector(const AkVector & in_vect, FVector & out_vect)
  1163. {
  1164. out_vect.X = in_vect.X;
  1165. out_vect.Y = in_vect.Y;
  1166. out_vect.Z = in_vect.Z;
  1167. }
  1168. static inline FVector AKVectorToFVector(const AkVector& in_vect)
  1169. {
  1170. return FVector(in_vect.X, in_vect.Y, in_vect.Z);
  1171. }
  1172. // Note that this is a loss of precision due to conversion from 64-bit to 32-bit
  1173. static inline void AKVector64ToFVector(const AkVector64 & in_vect, FVector & out_vect)
  1174. {
  1175. out_vect.X = (float)in_vect.X;
  1176. out_vect.Y = (float)in_vect.Y;
  1177. out_vect.Z = (float)in_vect.Z;
  1178. }
  1179. // Note that this is a loss of precision due to conversion from 64-bit to 32-bit
  1180. static inline FVector AKVector64ToFVector(const AkVector64& in_vect)
  1181. {
  1182. return FVector((float)in_vect.X, (float)in_vect.Y, (float)in_vect.Z);
  1183. }
  1184. FAkJobWorkerScheduler* GetAkJobWorkerScheduler() { return &AkJobWorkerScheduler; }
  1185. uint8 GetMaxAuxBus() const { return MaxAuxBus; }
  1186. AkCallbackInfoPool* GetAkCallbackInfoPool()
  1187. {
  1188. return CallbackInfoPool;
  1189. }
  1190. #if WITH_EDITOR
  1191. void SetMaxAuxBus(uint8 ValToSet) { MaxAuxBus = ValToSet; }
  1192. #endif
  1193. static const int32 FIND_COMPONENTS_DEPTH_INFINITE = -1;
  1194. /** Find UAkLateReverbComponents at a given location. */
  1195. TArray<class UAkLateReverbComponent*> FindLateReverbComponentsAtLocation(const FVector& Loc, const UWorld* in_World);
  1196. /** Add a UAkLateReverbComponent to the spatial index data structure. */
  1197. void IndexLateReverb(class UAkLateReverbComponent* ComponentToAdd);
  1198. /** Remove a UAkLateReverbComponent from the spatial index data structure. */
  1199. void UnindexLateReverb(class UAkLateReverbComponent* ComponentToRemove);
  1200. /** Update the bounds of a UAkLateReverbComponent in the spatial index data structure. Must be called if the component's transform changes.*/
  1201. void ReindexLateReverb(class UAkLateReverbComponent* ComponentToAdd);
  1202. /** Get whether the given world has room registered in it. */
  1203. bool WorldHasActiveRooms(UWorld* World);
  1204. /** Find UAkRoomComponents at a given location. */
  1205. TArray<class UAkRoomComponent*> FindRoomComponentsAtLocation(const FVector& Loc, const UWorld* World);
  1206. /** Return true if any UAkRoomComponents have been added to the prioritized list of rooms for the in_World**/
  1207. bool UsingSpatialAudioRooms(const UWorld* World);
  1208. /** Get the aux send values corresponding to a point in the world.**/
  1209. void GetAuxSendValuesAtLocation(FVector Loc, TArray<AkAuxSendValue>& AkAuxSendValues, const UWorld* in_World);
  1210. /** Update all portals. */
  1211. void UpdateAllSpatialAudioPortals(UWorld* InWorld);
  1212. /** Queue an update for all portals in a world to reconnect to their front and back rooms */
  1213. void PortalsNeedRoomUpdate(UWorld* World) { WorldsInNeedOfPortalRoomsUpdate.Add(World); }
  1214. /** Register a Portal in AK Spatial Audio. Can be called again to update the portal parameters. */
  1215. void SetSpatialAudioPortal(UAkPortalComponent* in_Portal);
  1216. /** Remove a Portal from AK Spatial Audio */
  1217. void RemoveSpatialAudioPortal(UAkPortalComponent* in_Portal);
  1218. void OnActorSpawned(AActor* SpawnedActor);
  1219. UAkComponentSet& GetDefaultListeners() { return m_defaultListeners; }
  1220. void SetListeners(UAkComponent* in_pEmitter, const TArray<UAkComponent*>& in_listenerSet);
  1221. void AddDefaultListener(UAkComponent* in_pListener);
  1222. void RemoveDefaultListener(UAkComponent* in_pListener);
  1223. void UpdateDefaultActiveListeners();
  1224. #if WITH_EDITORONLY_DATA
  1225. FTransform GetEditorListenerPosition(int32 ViewIndex) const;
  1226. #endif
  1227. /** Specifies which listener is used for Wwise Spatial Audio**/
  1228. bool SetSpatialAudioListener(UAkComponent* in_pListener);
  1229. /** Get the listener that has been choosen to be used for Wwise Spatial Audio**/
  1230. UAkComponent* GetSpatialAudioListener() const;
  1231. AKRESULT SetPosition(UAkComponent* in_akComponent, const AkSoundPosition& in_SoundPosition);
  1232. /** Add a UAkRoomComponent to the spatial index data structure. */
  1233. void IndexRoom(class UAkRoomComponent* ComponentToAdd);
  1234. /** Remove a UAkRoomComponent from the spatial index data structure. */
  1235. void UnindexRoom(class UAkRoomComponent* ComponentToRemove);
  1236. /** Update the bounds of a UAkRoomComponent in the spatial index data structure. Must be called if the component's transform changes.*/
  1237. void ReindexRoom(class UAkRoomComponent* ComponentToAdd);
  1238. AKRESULT AddRoom(UAkRoomComponent* in_pRoom, const AkRoomParams& in_RoomParams);
  1239. AKRESULT UpdateRoom(UAkRoomComponent* in_pRoom, const AkRoomParams& in_RoomParams);
  1240. AKRESULT RemoveRoom(UAkRoomComponent* in_pRoom);
  1241. AKRESULT SetGameObjectRadius(UAkComponent* in_akComponent, float in_outerRadius, float in_innerRadius);
  1242. AKRESULT SetImageSource(class AAkSpotReflector* in_pSpotReflector, const AkImageSourceSettings& in_ImageSourceInfo, AkUniqueID in_AuxBusID, UAkComponent* in_AkComponent);
  1243. AKRESULT RemoveImageSource(class AAkSpotReflector* in_pSpotReflector, AkUniqueID in_AuxBusID, UAkComponent* in_AkComponent);
  1244. AKRESULT ClearImageSources(AkUniqueID in_AuxBusID = AK_INVALID_AUX_ID, UAkComponent* in_AkComponent = NULL);
  1245. static void GetChannelConfig(AkChannelConfiguration ChannelConfiguration, AkChannelConfig& config);
  1246. static void GetChannelConfig(FAkChannelMask SpeakerConfiguration, AkChannelConfig& config);
  1247. FAkEnvironmentIndex& GetRoomIndex() { return RoomIndex; }
  1248. void AddPortalConnectionToOutdoors(const UWorld* in_world, UAkPortalComponent* in_pPortal);
  1249. void RemovePortalConnectionToOutdoors(const UWorld* in_world, AkPortalID in_portalID);
  1250. void GetObsOccServicePortalMap(const UAkRoomComponent* InRoom, const UWorld* InWorld, AkObstructionAndOcclusionService::PortalMap& OutPortalMap) const;
  1251. struct SetCurrentAudioCultureAsyncTask
  1252. {
  1253. enum CompletionType
  1254. {
  1255. LatentAction,
  1256. Callback
  1257. };
  1258. FWwiseLanguageCookedData Language;
  1259. FThreadSafeBool IsDone = false;
  1260. FThreadSafeBool Succeeded = false;
  1261. SetCurrentAudioCultureAsyncTask(FWwiseLanguageCookedData NewLanguage, FSetCurrentAudioCultureAction* LatentAction);
  1262. SetCurrentAudioCultureAsyncTask(FWwiseLanguageCookedData NewLanguage, const FOnSetCurrentAudioCultureCompleted& CompletedCallback);
  1263. bool Start();
  1264. void Update();
  1265. private:
  1266. TSharedPtr<FPendingLatentActionValidityToken, ESPMode::ThreadSafe> LatentActionValidityToken;
  1267. CompletionType CompletionActionType;
  1268. FSetCurrentAudioCultureAction* SetAudioCultureLatentAction;
  1269. FOnSetCurrentAudioCultureCompleted SetAudioCultureCompletedCallback;
  1270. };
  1271. void AddPlayingID(uint32 EventID, uint32 PlayingID, EAkAudioContext AudioContext);
  1272. bool IsPlayingIDActive(uint32 EventID, uint32 PlayingID);
  1273. bool IsEventIDActive(uint32 EventID);
  1274. void RemovePlayingID(uint32 EventID, uint32 PlayingID);
  1275. void StopEventID(uint32 EventID);
  1276. FOnSwitchValueLoaded& GetOnSwitchValueLoaded(uint32 SwitchID);
  1277. void BroadcastOnSwitchValueLoaded(UAkGroupValue* GroupValue);
  1278. void SetLocalOutput();
  1279. FAkComponentCallbackManager* GetCallbackManager() { return CallbackManager; }
  1280. AKRESULT RegisterGameObject(AkGameObjectID GameObjectID, const FString& Name);
  1281. /** Determine whether the Wwise sound engine should be updated for the given world type */
  1282. static bool ShouldNotifySoundEngine(EWorldType::Type WorldType);
  1283. static void LoadAudioObjectsAfterInitialization(TWeakObjectPtr<UAkAudioType>&& InAudioType);
  1284. void LoadDelayedObjects();
  1285. private:
  1286. bool EnsureInitialized();
  1287. void* AllocatePermanentMemory( int32 Size, /*OUT*/ bool& AllocatedInPool );
  1288. AKRESULT GetGameObjectID(AActor * in_pActor, AkGameObjectID& io_GameObject );
  1289. template<typename FCreateCallbackPackage>
  1290. AkPlayingID PostEventWithCallbackPackageOnAkGameObject(
  1291. const AkUInt32 EventShortID,
  1292. UAkGameObject* GameObject,
  1293. const TArray<AkExternalSourceInfo>& ExternalSources,
  1294. FCreateCallbackPackage CreateCallbackPackage,
  1295. EAkAudioContext AudioContext
  1296. );
  1297. template<typename ChannelConfig>
  1298. AKRESULT SetMultiplePositions(
  1299. UAkComponent* in_pGameObjectAkComponent,
  1300. const TArray<ChannelConfig>& in_aChannelConfigurations,
  1301. const TArray<FTransform>& in_aPositions,
  1302. AkMultiPositionType in_eMultiPositionType
  1303. );
  1304. // Overload allowing to modify StopWhenOwnerDestroyed after getting the AkComponent
  1305. AKRESULT GetGameObjectID(AActor * in_pActor, AkGameObjectID& io_GameObject, bool in_bStopWhenOwnerDestroyed );
  1306. /** Update the room connections for all portals */
  1307. void UpdateRoomsForPortals();
  1308. #if WITH_EDITORONLY_DATA
  1309. UAkComponent* CreateListener(UWorld* World, FEditorViewportClient* ViewportClient = nullptr);
  1310. TArray<FTransform> ListenerTransforms;
  1311. UAkComponent* EditorListener = nullptr;
  1312. /**
  1313. * Update Default Listeners when going in and out of Play mode in editor
  1314. */
  1315. void EndPIE(const bool bIsSimulating);
  1316. void BeginPIE(const bool bIsSimulating);
  1317. void PausePIE(const bool bIsSimulating);
  1318. void ResumePie(const bool bIsSimulating);
  1319. void OnSwitchBeginPIEAndSIE(const bool bIsSimulating);
  1320. #endif
  1321. /** Map to track whether new reverbs or rooms have been added to worlds in the previous frame.
  1322. * AkComponent checks this in its TickComponent function and updates its assigned room and/or reverb volumes.
  1323. */
  1324. TMap<UWorld*, bool> WorldVolumesUpdatedMap;
  1325. void SAComponentAddedRemoved(UWorld* World);
  1326. /** We keep a spatial index of UAkLateReverbComponents sorted by priority for faster finding of reverb volumes at a specific location.
  1327. */
  1328. FAkEnvironmentIndex LateReverbIndex;
  1329. /** We keep a spatial index of Spatial audio Rooms for faster finding of reverb volumes at a specific location.
  1330. */
  1331. FAkEnvironmentIndex RoomIndex;
  1332. /** We keep track of the portals in each world so their rooms can be updated when room and portal parameters change.
  1333. */
  1334. TMap<UWorld*, TArray<TWeakObjectPtr<UAkPortalComponent>>> WorldPortalsMap;
  1335. typedef WwiseUnrealHelper::AkSpatialAudioIDKeyFuncs<UAkPortalComponent*, false> PortalComponentSpatialAudioIDKeyFuncs;
  1336. typedef TMap<AkPortalID, UAkPortalComponent*, FDefaultSetAllocator, PortalComponentSpatialAudioIDKeyFuncs> PortalComponentMap;
  1337. TMap<const UWorld*, PortalComponentMap> OutdoorsConnectedPortals;
  1338. void CleanupComponentMapsForWorld(UWorld* World);
  1339. bool FindWwiseLanguage(const FString& NewAudioCulture, FString& FoundWwiseLanguage);
  1340. void UpdateSetCurrentAudioCultureAsyncTasks();
  1341. static bool m_bSoundEngineInitialized;
  1342. UAkComponentSet m_defaultListeners;
  1343. UAkComponent* m_SpatialAudioListener;
  1344. bool m_isSuspended = false;
  1345. uint8 MaxAuxBus;
  1346. FAkComponentCallbackManager* CallbackManager;
  1347. AkCallbackInfoPool* CallbackInfoPool;
  1348. FAkJobWorkerScheduler AkJobWorkerScheduler;
  1349. FWwiseIOHook* IOHook = nullptr;
  1350. static bool m_EngineExiting;
  1351. /* WAAPI Callback handles. */
  1352. FDelegateHandle ProjectLoadedHandle;
  1353. FDelegateHandle ConnectionLostHandle;
  1354. FDelegateHandle ClientBeginDestroyHandle;
  1355. struct FWaapiSubscriptionIds
  1356. {
  1357. uint64 Renamed = 0;
  1358. uint64 PreDeleted = 0;
  1359. uint64 ChildRemoved = 0;
  1360. uint64 ChildAdded = 0;
  1361. uint64 Created = 0;
  1362. } WaapiSubscriptionIds;
  1363. TArray<SetCurrentAudioCultureAsyncTask*> AudioCultureAsyncTasks;
  1364. TSet<UWorld*> WorldsInNeedOfPortalRoomsUpdate;
  1365. #if !WITH_EDITOR
  1366. TMap<FCulturePtr, FString> CachedUnrealToWwiseCulture;
  1367. #endif
  1368. static FCriticalSection EventToPlayingIDMapCriticalSection;
  1369. static TMap<uint32, TArray<uint32>> EventToPlayingIDMap;
  1370. static TMap<uint32, EAkAudioContext> PlayingIDToAudioContextMap;
  1371. static void PostEventAtLocationEndOfEventCallback(AkCallbackType in_eType, AkCallbackInfo* in_pCallbackInfo);
  1372. static TMap<uint32, FOnSwitchValueLoaded> OnSwitchValueLoadedMap;
  1373. static TArray<TWeakObjectPtr<UAkAudioType>> AudioObjectsToLoadAfterInitialization;
  1374. #if WITH_EDITORONLY_DATA
  1375. #ifndef AK_OPTIMIZED
  1376. static AkErrorMessageTranslator* m_UnrealErrorTranslator;
  1377. #if AK_SUPPORT_WAAPI
  1378. static AkWAAPIErrorMessageTranslator m_waapiErrorMessageTranslator;
  1379. #endif //AK_SUPPORT_WAAPI
  1380. #endif //AK_OPTIMIZED
  1381. #endif //WITH_EDITORONLY_DATA
  1382. };