Plasma Engine  2.0
Loading...
Searching...
No Matches
AudioSystem.h
1#pragma once
2
3#include <AudioSystemPlugin/AudioSystemPluginDLL.h>
4
5#include <AudioSystemPlugin/ATL/AudioTranslationLayer.h>
6#include <AudioSystemPlugin/Core/AudioSystemData.h>
7#include <AudioSystemPlugin/Core/AudioThread.h>
8
9#include <Core/GameApplication/GameApplicationBase.h>
10#include <Core/Interfaces/SoundInterface.h>
11
12#include <Foundation/Configuration/Singleton.h>
13#include <Foundation/Threading/Semaphore.h>
14
16
22class PL_AUDIOSYSTEMPLUGIN_DLL plAudioSystem final : public plSoundInterface
23{
24 PL_DECLARE_SINGLETON_OF_INTERFACE(plAudioSystem, plSoundInterface);
25
26 // ----- plSoundInterface
27
28public:
31 void LoadConfiguration(plStringView sFile) override;
32
35 void SetOverridePlatform(plStringView sPlatform) override;
36
38 void UpdateSound() override;
39
41 void SetMasterChannelVolume(float fVolume) override;
42
44 float GetMasterChannelVolume() const override;
45
47 void SetMasterChannelMute(bool bMute) override;
48
50 bool GetMasterChannelMute() const override;
51
53 void SetMasterChannelPaused(bool bPaused) override;
54
56 bool GetMasterChannelPaused() const override;
57
59 void SetSoundGroupVolume(plStringView sVcaGroupGuid, float fVolume) override;
60
62 float GetSoundGroupVolume(plStringView sVcaGroupGuid) const override;
63
65 void SetNumListeners(plUInt8 uiNumListeners) override {}
66
68 plUInt8 GetNumListeners() override;
69
72 void SetListenerOverrideMode(bool bEnabled) override;
73
76 void SetListener(plInt32 iIndex, const plVec3& vPosition, const plVec3& vForward, const plVec3& vUp, const plVec3& vVelocity) override;
77
79 plResult OneShotSound(plStringView sResourceID, const plTransform& globalPosition, float fPitch = 1.0f, float fVolume = 1.0f, bool bBlockIfNotLoaded = true) override;
80
81 // ----- plAudioSystem
82
83public:
85 virtual ~plAudioSystem();
86
87 bool Startup();
88 void Shutdown();
89
90 [[nodiscard]] bool IsInitialized() const;
91
92 void SendRequest(plVariant&& request);
93 void SendRequests(plAudioSystemRequestsQueue& requests);
94
95 void SendRequestSync(plVariant&& request);
96
97 plAudioSystemDataID GetTriggerId(plStringView sTriggerName) const;
98
99 plAudioSystemDataID GetRtpcId(plStringView sRtpcName) const;
100
101 plAudioSystemDataID GetSwitchStateId(plStringView sSwitchStateName) const;
102
103 plAudioSystemDataID GetEnvironmentId(plStringView sEnvironmentName) const;
104
105 plAudioSystemDataID GetBankId(plStringView sBankName) const;
106
107 void RegisterTrigger(plAudioSystemDataID uiId, plAudioSystemTriggerData* pTriggerData);
108 void RegisterRtpc(plAudioSystemDataID uiId, plAudioSystemRtpcData* pRtpcData);
109 void RegisterSwitchState(plAudioSystemDataID uiId, plAudioSystemSwitchStateData* pSwitchStateData);
110 void RegisterEnvironment(plAudioSystemDataID uiId, plAudioSystemEnvironmentData* pEnvironmentData);
111 void RegisterSoundBank(plAudioSystemDataID uiId, plAudioSystemBankData* pSoundBankData);
112
113 void UnregisterEntity(plAudioSystemDataID uiId);
114 void UnregisterListener(plAudioSystemDataID uiId);
115 void UnregisterTrigger(plAudioSystemDataID uiId);
116 void UnregisterRtpc(plAudioSystemDataID uiId);
117 void UnregisterSwitchState(plAudioSystemDataID uiId);
118 void UnregisterEnvironment(plAudioSystemDataID uiId);
119 void UnregisterSoundBank(plAudioSystemDataID uiId);
120
121private:
122 PL_MAKE_SUBSYSTEM_STARTUP_FRIEND(AudioSystem, AudioSystemPlugin);
123
124 friend class plAudioThread;
125 friend class plAudioTranslationLayer;
126
127 static void GameApplicationEventHandler(const plGameApplicationExecutionEvent& e);
128
129 void UpdateInternal();
130
131 void StartAudioThread();
132 void StopAudioThread();
133
134 void QueueRequestCallback(plVariant&& request, bool bSync);
135
136 plAudioThread* m_pAudioThread = nullptr;
137 plAudioTranslationLayer m_AudioTranslationLayer;
138
139 plAudioSystemRequestsQueue m_RequestsQueue;
140 plAudioSystemRequestsQueue m_PendingRequestsQueue;
141 plAudioSystemRequestsQueue m_BlockingRequestsQueue;
142 plAudioSystemRequestsQueue m_PendingRequestCallbacksQueue;
143 plAudioSystemRequestsQueue m_BlockingRequestCallbacksQueue;
144
145 mutable plMutex m_RequestsMutex;
146 mutable plMutex m_PendingRequestsMutex;
147 mutable plMutex m_BlockingRequestsMutex;
148 mutable plMutex m_PendingRequestCallbacksMutex;
149 mutable plMutex m_BlockingRequestCallbacksMutex;
150
151 plSemaphore m_MainEvent;
152 plSemaphore m_ProcessingEvent;
153
154 bool m_bInitialized;
155
156 bool m_bListenerOverrideMode;
157};
Base class for an audio middleware bank file.
Definition AudioSystemData.h:224
Base class for an audio middleware environment.
Definition AudioSystemData.h:198
The AudioSystem.
Definition AudioSystem.h:23
void SetNumListeners(plUInt8 uiNumListeners) override
Asks the audio middleware to set the required number of listeners.
Definition AudioSystem.h:65
Base class for an audio middleware RTPC.
Definition AudioSystemData.h:180
Base class for an audio middleware switch state.
Definition AudioSystemData.h:189
Base class for an audio middleware trigger.
Definition AudioSystemData.h:171
The audio thread. Responsible to process asynchronous audio requests.
Definition AudioThread.h:9
The Audio Translation Layer.
Definition AudioTranslationLayer.h:17
Definition Deque.h:270
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
A semaphore is used to synchronize threads, similar to a mutex (see plMutex).
Definition Semaphore.h:17
Definition SoundInterface.h:7
virtual void SetMasterChannelMute(bool bMute)=0
Allows to mute all sounds. Useful for when the application goes to a background state.
virtual void SetSoundGroupVolume(plStringView sVcaGroupGuid, float fVolume)=0
Specifies the volume for a VCA ('Voltage Control Amplifier').
virtual void SetOverridePlatform(plStringView sPlatform)=0
By default the integration should auto-detect the platform (and thus the config) to use....
virtual void SetListenerOverrideMode(bool bEnabled)=0
The editor activates this to ignore the listener positions from the listener components,...
virtual void SetMasterChannelVolume(float fVolume)=0
Adjusts the master volume. This affects all sounds, with no exception. Value must be between 0....
virtual void UpdateSound()=0
Has to be called once per frame to update all sounds.
virtual void LoadConfiguration(plStringView sFile)=0
Can be called before startup to load the configs from a different file. Otherwise will automatically ...
virtual void SetMasterChannelPaused(bool bPaused)=0
Allows to pause all sounds. Useful for when the application goes to a background state and you want t...
virtual void SetListener(plInt32 iIndex, const plVec3 &vPosition, const plVec3 &vForward, const plVec3 &vUp, const plVec3 &vVelocity)=0
Sets the position for listener N. Index -1 is used for the override mode listener.
virtual plResult OneShotSound(plStringView sResourceID, const plTransform &globalPosition, float fPitch=1.0f, float fVolume=1.0f, bool bBlockIfNotLoaded=true)=0
Plays a sound once. Callced by plSoundInterface::PlaySound().
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
Definition GameApplicationBase.h:32
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54