WwiseEventTracking.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "AkAudioDevice.h"
  17. #include "AkComponent.h"
  18. /** This can be used to track a Wwise event as it is triggered and stopped.
  19. * Maintains a collection of playing IDs and a collection of IDs that have scheduled stop calls.
  20. * Also maintains a collection of Vector2Ds that indicate the history of start times and durations
  21. * of event retriggers.
  22. */
  23. struct AKAUDIO_API FWwiseEventTracker
  24. {
  25. static int GetScrubTimeMs() { return 100; }
  26. /** Callback receieved at various points during lifetime Wwise event.
  27. * The FWwiseEventTracker is stored in the AkCallbackInfo as pCookie.
  28. */
  29. static void PostEventCallbackHandler(AkCallbackType in_eType, AkCallbackInfo* in_pCallbackInfo);
  30. void RemoveScheduledStop(AkPlayingID InID);
  31. void RemovePlayingID(AkPlayingID InID);
  32. void TryAddPlayingID(const AkPlayingID& PlayingID);
  33. void EmptyPlayingIDs();
  34. void EmptyScheduledStops();
  35. bool PlayingIDHasScheduledStop(AkPlayingID InID);
  36. void AddScheduledStop(AkPlayingID InID);
  37. bool IsDirty = false;
  38. bool IsPlaying() const { FScopeLock autoLock(&PlayingIDsLock); return PlayingIDs.Num() > 0; }
  39. bool HasScheduledStop() const { FScopeLock autoLock(&ScheduledStopsLock); return ScheduledStops.Num() > 0; }
  40. float GetClipDuration() const { return ClipEndTime - ClipStartTime; }
  41. TArray<AkPlayingID> PlayingIDs;
  42. TArray<AkPlayingID> ScheduledStops;
  43. FFloatRange EventDuration;
  44. FString EventName;
  45. UAkAudioEvent* Event;
  46. mutable FCriticalSection PlayingIDsLock;
  47. mutable FCriticalSection ScheduledStopsLock;
  48. float ClipStartTime = 0.0f;
  49. float ClipEndTime = 0.0f;
  50. int ScrubTailLengthMs = GetScrubTimeMs();
  51. float PreviousEventStartTime = -1.0f;
  52. float PreviousPlayingTime = -1.0f;
  53. float CurrentDurationEstimation = -1.0f;
  54. float CurrentDurationProportionRemaining = 1.0f;
  55. bool bStopAtSectionEnd = true;
  56. };
  57. /** A collection of helper functions for triggering tracked Wwise events */
  58. namespace WwiseEventTriggering
  59. {
  60. AKAUDIO_API TArray<AkPlayingID, TInlineAllocator<16>> GetPlayingIds(FWwiseEventTracker& EventTracker);
  61. AKAUDIO_API void LogDirtyPlaybackWarning();
  62. AKAUDIO_API void StopAllPlayingIDs(FAkAudioDevice* AudioDevice, FWwiseEventTracker& EventTracker);
  63. AKAUDIO_API AkPlayingID PostEventOnDummyObject(FAkAudioDevice* AudioDevice, FWwiseEventTracker& EventTracker, float CurrentTime);
  64. AKAUDIO_API AkPlayingID PostEvent(UObject* Object, FAkAudioDevice* AudioDevice, FWwiseEventTracker& EventTracker, float CurrentTime);
  65. AKAUDIO_API void StopEvent(FAkAudioDevice* AudioDevice, AkPlayingID InPlayingID, FWwiseEventTracker* EventTracker);
  66. AKAUDIO_API void TriggerStopEvent(FAkAudioDevice* AudioDevice, FWwiseEventTracker& EventTracker, AkPlayingID PlayingID);
  67. AKAUDIO_API void ScheduleStopEventsForCurrentlyPlayingIDs(FAkAudioDevice* AudioDevice, FWwiseEventTracker& EventTracker);
  68. /** Trigger and EventTracker's Wwise event and schedule an accompanying stop event. */
  69. AKAUDIO_API void TriggerScrubSnippetOnDummyObject(FAkAudioDevice* AudioDevice, FWwiseEventTracker& EventTracker);
  70. /** Trigger and EventTracker's Wwise event and schedule an accompanying stop event. */
  71. AKAUDIO_API void TriggerScrubSnippet(UObject* Object, FAkAudioDevice* AudioDevice, FWwiseEventTracker& EventTracker);
  72. AKAUDIO_API void SeekOnEvent(UObject* Object, FAkAudioDevice* AudioDevice, AkReal32 in_fPercent, FWwiseEventTracker& EventTracker, AkPlayingID InPlayingID);
  73. AKAUDIO_API void SeekOnEvent(UObject* Object, FAkAudioDevice* AudioDevice, AkReal32 in_fPercent, FWwiseEventTracker& EventTracker);
  74. AKAUDIO_API void SeekOnEventWithDummyObject(FAkAudioDevice* AudioDevice, AkReal32 ProportionalTime, FWwiseEventTracker& EventTracker, AkPlayingID InPlayingID);
  75. AKAUDIO_API void SeekOnEventWithDummyObject(FAkAudioDevice* AudioDevice, AkReal32 ProportionalTime, FWwiseEventTracker& EventTracker);
  76. }