ATL.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <ATLEntities.h>
  10. #include <ATLComponents.h>
  11. #include <FileCacheManager.h>
  12. #include <ISystem.h>
  13. #if !defined(AUDIO_RELEASE)
  14. namespace AzFramework
  15. {
  16. class DebugDisplayRequests;
  17. }
  18. #endif
  19. namespace Audio
  20. {
  21. ///////////////////////////////////////////////////////////////////////////////////////////////////
  22. class CAudioTranslationLayer
  23. : public ISystemEventListener
  24. {
  25. public:
  26. CAudioTranslationLayer();
  27. ~CAudioTranslationLayer() override;
  28. CAudioTranslationLayer(const CAudioTranslationLayer& rOther) = delete; //copy protection
  29. CAudioTranslationLayer& operator=(const CAudioTranslationLayer& rOther) = delete; //copy protection
  30. // ISystemEventListener
  31. void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam) override;
  32. // ~ISystemEventListener
  33. bool Initialize();
  34. bool ShutDown();
  35. void Update();
  36. void ProcessRequest(AudioRequestVariant&& request);
  37. TAudioControlID GetAudioTriggerID(const char* const sAudioTriggerName) const;
  38. TAudioControlID GetAudioRtpcID(const char* const sAudioRtpcName) const;
  39. TAudioControlID GetAudioSwitchID(const char* const sAudioSwitchName) const;
  40. TAudioSwitchStateID GetAudioSwitchStateID(const TAudioControlID nSwitchID, const char* const sAudioSwitchStateName) const;
  41. TAudioPreloadRequestID GetAudioPreloadRequestID(const char* const sAudioPreloadRequestName) const;
  42. TAudioEnvironmentID GetAudioEnvironmentID(const char* const sAudioEnvironmentName) const;
  43. bool ReserveAudioObjectID(TAudioObjectID& rAudioObjectID, const char* const sAudioObjectName);
  44. bool ReleaseAudioObjectID(const TAudioObjectID nAudioObjectID);
  45. bool ReserveAudioListenerID(TAudioObjectID& rAudioObjectID);
  46. bool ReleaseAudioListenerID(const TAudioObjectID nAudioObjectID);
  47. bool SetAudioListenerOverrideID(const TAudioObjectID nAudioObjectID);
  48. bool CanProcessRequests() const { return (m_nFlags & eAIS_AUDIO_MIDDLEWARE_SHUTTING_DOWN) == 0; }
  49. EAudioRequestStatus ParseControlsData(const char* const pFolderPath, const EATLDataScope eDataScope);
  50. EAudioRequestStatus ClearControlsData(const EATLDataScope eDataScope);
  51. const AZStd::string& GetControlsImplSubPath() const;
  52. TAudioSourceId CreateAudioSource(const SAudioInputConfig& sourceConfig);
  53. void DestroyAudioSource(TAudioSourceId sourceId);
  54. private:
  55. EAudioRequestStatus InitializeImplComponent();
  56. void ReleaseImplComponent();
  57. EAudioRequestStatus PrepUnprepTriggerAsync(
  58. CATLAudioObjectBase* const pAudioObject,
  59. const CATLTrigger* const pTrigger,
  60. const bool bPrepare);
  61. EAudioRequestStatus ActivateTrigger(
  62. CATLAudioObjectBase* const pAudioObject,
  63. const CATLTrigger* const pTrigger,
  64. void* const pOwner = nullptr,
  65. const SATLSourceData* pSourceData = nullptr);
  66. EAudioRequestStatus StopTrigger(
  67. CATLAudioObjectBase* const pAudioObject,
  68. const CATLTrigger* const pTrigger);
  69. EAudioRequestStatus StopAllTriggers(CATLAudioObjectBase* const pAudioObject, void* const pOwner = nullptr);
  70. EAudioRequestStatus SetSwitchState(
  71. CATLAudioObjectBase* const pAudioObject,
  72. const CATLSwitchState* const pState);
  73. EAudioRequestStatus SetRtpc(
  74. CATLAudioObjectBase* const pAudioObject,
  75. const CATLRtpc* const pRtpc,
  76. const float fValue);
  77. EAudioRequestStatus ResetRtpcs(CATLAudioObjectBase* const pAudioObject);
  78. EAudioRequestStatus SetEnvironment(
  79. CATLAudioObjectBase* const pAudioObject,
  80. const CATLAudioEnvironment* const pEnvironment,
  81. const float fAmount);
  82. EAudioRequestStatus ResetEnvironments(CATLAudioObjectBase* const pAudioObject);
  83. EAudioRequestStatus ActivateInternalTrigger(
  84. CATLAudioObjectBase* const pAudioObject,
  85. const IATLTriggerImplData* const pTriggerData,
  86. IATLEventData* const pEventData);
  87. EAudioRequestStatus StopInternalEvent(
  88. CATLAudioObjectBase* const pAudioObject,
  89. const IATLEventData* const pEventData);
  90. EAudioRequestStatus StopAllInternalEvents(CATLAudioObjectBase* const pAudioObject);
  91. EAudioRequestStatus SetInternalRtpc(
  92. CATLAudioObjectBase* const pAudioObject,
  93. const IATLRtpcImplData* const pRtpcData,
  94. const float fValue);
  95. EAudioRequestStatus SetInternalSwitchState(
  96. CATLAudioObjectBase* const pAudioObject,
  97. const IATLSwitchStateImplData* const pSwitchStateData);
  98. EAudioRequestStatus SetInternalEnvironment(
  99. CATLAudioObjectBase* const pAudioObject,
  100. const IATLEnvironmentImplData* const pEnvironmentImplData,
  101. const float fAmount);
  102. EAudioRequestStatus RefreshAudioSystem(
  103. const char* const controlsPath, const char* const levelName, TAudioPreloadRequestID levelPreloadId);
  104. EAudioRequestStatus MuteAll();
  105. EAudioRequestStatus UnmuteAll();
  106. EAudioRequestStatus LoseFocus();
  107. EAudioRequestStatus GetFocus();
  108. void UpdateSharedData();
  109. void SetImplLanguage();
  110. CATLAudioObjectBase* GetRequestObject(TAudioObjectID objectId);
  111. enum EATLInternalStates : TATLEnumFlagsType
  112. {
  113. eAIS_NONE = 0,
  114. eAIS_IS_MUTED = AUDIO_BIT(0),
  115. eAIS_AUDIO_MIDDLEWARE_SHUTTING_DOWN = AUDIO_BIT(1),
  116. };
  117. // Regularly updated common data to be referenced by all components.
  118. SATLSharedData m_oSharedData;
  119. // ATLObject containers
  120. TATLTriggerLookup m_cTriggers;
  121. TATLRtpcLookup m_cRtpcs;
  122. TATLSwitchLookup m_cSwitches;
  123. TATLPreloadRequestLookup m_cPreloadRequests;
  124. TATLEnvironmentLookup m_cEnvironments;
  125. CATLGlobalAudioObject* m_pGlobalAudioObject;
  126. const TAudioObjectID m_nGlobalAudioObjectID;
  127. TAudioTriggerInstanceID m_nTriggerInstanceIDCounter;
  128. TAudioSourceId m_nextSourceId;
  129. // Components
  130. CAudioEventManager m_oAudioEventMgr;
  131. CAudioObjectManager m_oAudioObjectMgr;
  132. CAudioListenerManager m_oAudioListenerMgr;
  133. CFileCacheManager m_oFileCacheMgr;
  134. CATLXmlProcessor m_oXmlProcessor;
  135. // Utility members
  136. TATLEnumFlagsType m_nFlags;
  137. AZStd::string m_implSubPath;
  138. using duration_ms = AZStd::chrono::duration<float, AZStd::milli>;
  139. AZStd::chrono::steady_clock::time_point m_lastUpdateTime;
  140. duration_ms m_elapsedTime;
  141. #if !defined(AUDIO_RELEASE)
  142. public:
  143. void DrawAudioSystemDebugInfo();
  144. const CATLDebugNameStore& GetDebugStore() const { return m_oDebugNameStore; }
  145. private:
  146. void DrawAudioObjectDebugInfo(AzFramework::DebugDisplayRequests& debugDisplay);
  147. void DrawATLComponentDebugInfo(AzFramework::DebugDisplayRequests& debugDisplay, float posX, float posY);
  148. void DrawImplMemoryPoolDebugInfo(AzFramework::DebugDisplayRequests& debugDisplay, float posX, float posY);
  149. CATLDebugNameStore m_oDebugNameStore;
  150. AZStd::string m_implementationName;
  151. #endif // !AUDIO_RELEASE
  152. };
  153. } // namespace Audio