Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
SoundManager.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_SOUNDMANAGER_H
19#define INCLUDED_SOUNDMANAGER_H
20
21#include "lib/config2.h"
22
23#if CONFIG2_AUDIO
24
25#include "ISoundManager.h"
26#include "data/SoundData.h"
27#include "items/ISoundItem.h"
29
32#include "ps/CStr.h"
33#include "ps/Profiler2.h"
35
36#include <map>
37#include <mutex>
38#include <vector>
39
40#define AL_CHECK CSoundManager::al_check(__func__, __LINE__)
41
43{
44 /// Title of the column
45 ALuint ALSource;
47};
48
49typedef std::vector<VfsPath> PlayList;
50typedef std::vector<ISoundItem*> ItemsList;
51typedef std::map<entity_id_t, ISoundItem*> ItemsMap;
52typedef std::map<std::wstring, CSoundGroup*> SoundGroupMap;
53
55
56
58{
60
61protected:
62
63 ALCcontext* m_Context;
64 ALCdevice* m_Device;
69 std::mutex m_DistressMutex;
72
73 float m_Gain;
77 float m_UIGain;
83
90
94
97public:
98 CSoundManager(ALCdevice* device);
99 virtual ~CSoundManager();
100
101 void StartWorker();
102
103 ISoundItem* LoadItem(const VfsPath& itemPath);
106
107 Status ReloadChangedFiles(const VfsPath& path);
108
109 void ClearPlayListItems();
110 void StartPlayList(bool doLoop);
111 void AddPlayListItem(const VfsPath& itemPath);
112
113 static void CreateSoundManager();
114 static void SetEnabled(bool doEnable);
115 static Status ReloadChangedFileCB(void* param, const VfsPath& path);
116
117 static void CloseGame();
118
119 static void al_ReportError(ALenum err, const char* caller, int line);
120 static void al_check(const char* caller, int line);
121
122 void SetMusicEnabled(bool isEnabled);
123 void SetSoundEnabled(bool enabled);
124
125 ALuint GetALSource(ISoundItem* anItem);
126 void ReleaseALSource(ALuint theSource);
128
131
132 ISoundItem* GetSoundItem(unsigned long itemRow);
133 unsigned long Count();
134 void IdleTask();
135
136 void SetMemoryUsage(long bufferSize, int bufferCount);
137 long GetBufferCount();
138 long GetBufferSize();
139 CStr8 GetSoundCardNames() const;
140 CStr8 GetOpenALVersion() const;
141
142 void PlayAsMusic(const VfsPath& itemPath, bool looping);
143 void PlayAsAmbient(const VfsPath& itemPath, bool looping);
144 void PlayAsUI(const VfsPath& itemPath, bool looping);
145 void PlayAsGroup(const VfsPath& groupPath, const CVector3D& sourcePos, entity_id_t source, bool ownedSound);
146
147 void PlayGroupItem(ISoundItem* anItem, ALfloat groupGain);
148
149 bool InDistress();
152
153 void Pause(bool pauseIt);
154 void PauseMusic(bool pauseIt);
155 void PauseAmbient(bool pauseIt);
156 void PauseAction(bool pauseIt);
157
159
160 void SetAmbientItem(ISoundItem* anItem);
161
162 void SetMasterGain(float gain);
163 void SetMusicGain(float gain);
164 void SetAmbientGain(float gain);
165 void SetActionGain(float gain);
166 void SetUIGain(float gain);
167
168protected:
169 void InitListener();
170 Status AlcInit();
171 void SetMusicItem(ISoundItem* anItem);
172
173private:
175};
176
177#else // !CONFIG2_AUDIO
178
179#define AL_CHECK
180
181#endif // !CONFIG2_AUDIO
182
183#endif // INCLUDED_SOUNDMANAGER_H
184
New profiler (complementing the older CProfileManager)
std::map< std::wstring, CSoundGroup * > SoundGroupMap
Definition: SoundManager.h:52
std::vector< ISoundItem * > ItemsList
Definition: SoundManager.h:50
std::vector< VfsPath > PlayList
Definition: SoundManager.h:49
std::map< entity_id_t, ISoundItem * > ItemsMap
Definition: SoundManager.h:51
Definition: SoundData.h:35
Definition: SoundManager.cpp:45
Definition: SoundManager.h:58
ISoundItem * m_CurrentEnvirons
Definition: SoundManager.h:67
void SetMusicEnabled(bool isEnabled)
Definition: SoundManager.cpp:643
void SetMasterGain(float gain)
Definition: SoundManager.cpp:485
CSoundManager(CSoundManager *other)
Definition: SoundManager.h:174
void SetSoundEnabled(bool enabled)
void SetDistressThroughShortage()
Definition: SoundManager.cpp:389
ISoundItem * ItemFromWAV(VfsPath &fname)
bool m_ActionPaused
Definition: SoundManager.h:86
float m_AmbientGain
Definition: SoundManager.h:75
std::mutex m_DistressMutex
Definition: SoundManager.h:69
void ClearPlayListItems()
Definition: SoundManager.cpp:451
Status AlcInit()
Definition: SoundManager.cpp:311
ISoundItem * GetSoundItem(unsigned long itemRow)
void SetAmbientGain(float gain)
Definition: SoundManager.cpp:502
ISoundItem * ItemForData(CSoundData *itemData)
Definition: SoundManager.cpp:532
CStr8 GetOpenALVersion() const
Definition: SoundManager.cpp:857
unsigned long Count()
long m_DistressErrCount
Definition: SoundManager.h:92
void SetAmbientItem(ISoundItem *anItem)
Definition: SoundManager.cpp:799
void StartWorker()
Definition: SoundManager.cpp:305
int m_BufferCount
Definition: SoundManager.h:80
CSoundManager(ALCdevice *device)
Definition: SoundManager.cpp:237
void AddPlayListItem(const VfsPath &itemPath)
Definition: SoundManager.cpp:445
void PlayAsGroup(const VfsPath &groupPath, const CVector3D &sourcePos, entity_id_t source, bool ownedSound)
Definition: SoundManager.cpp:653
ISoundItem * ItemFromData(CSoundData *itemData)
void PlayAsUI(const VfsPath &itemPath, bool looping)
Definition: SoundManager.cpp:703
bool InDistress()
Definition: SoundManager.cpp:372
ALCdevice * m_Device
Definition: SoundManager.h:64
bool m_PlayingPlaylist
Definition: SoundManager.h:88
CSoundManagerWorker * m_Worker
Definition: SoundManager.h:68
void SetUIGain(float gain)
Definition: SoundManager.cpp:510
Status ReloadChangedFiles(const VfsPath &path)
Definition: SoundManager.cpp:226
ALSourceHolder * m_ALSourceBuffer
Definition: SoundManager.h:65
ALCcontext * m_Context
Definition: SoundManager.h:63
void Pause(bool pauseIt)
Definition: SoundManager.cpp:722
NONCOPYABLE(CSoundManager)
long GetBufferSize()
Definition: SoundManager.cpp:440
void PlayAsAmbient(const VfsPath &itemPath, bool looping)
Definition: SoundManager.cpp:691
bool m_AmbientPaused
Definition: SoundManager.h:85
void InitListener()
Definition: SoundManager.cpp:617
virtual ~CSoundManager()
Definition: SoundManager.cpp:272
bool m_MusicPaused
Definition: SoundManager.h:84
ISoundItem * LoadItem(const VfsPath &itemPath)
Definition: SoundManager.cpp:516
long m_BufferSize
Definition: SoundManager.h:79
PlayList * m_PlayListItems
Definition: SoundManager.h:70
bool m_LoopingPlaylist
Definition: SoundManager.h:89
SoundGroupMap m_SoundGroups
Definition: SoundManager.h:71
long m_PlaylistGap
Definition: SoundManager.h:91
void IdleTask()
Definition: SoundManager.cpp:560
bool m_SoundEnabled
Definition: SoundManager.h:81
void SetMusicGain(float gain)
Definition: SoundManager.cpp:495
CStr8 m_SoundCardNames
Definition: SoundManager.h:95
void StartPlayList(bool doLoop)
Definition: SoundManager.cpp:466
void PlayGroupItem(ISoundItem *anItem, ALfloat groupGain)
Definition: SoundManager.cpp:630
float m_MusicGain
Definition: SoundManager.h:74
ISoundItem * m_CurrentTune
Definition: SoundManager.h:66
bool m_RunningPlaylist
Definition: SoundManager.h:87
void ReleaseALSource(ALuint theSource)
Definition: SoundManager.cpp:424
ISoundItem * ItemFromOgg(VfsPath &fname)
void PlayAsMusic(const VfsPath &itemPath, bool looping)
Definition: SoundManager.cpp:679
bool m_MusicEnabled
Definition: SoundManager.h:82
void RunHardwareDetection()
Definition: SoundManager.cpp:824
ISoundItem * ItemForEntity(entity_id_t source, CSoundData *sndData)
Definition: SoundManager.cpp:606
static Status ReloadChangedFileCB(void *param, const VfsPath &path)
Definition: SoundManager.cpp:232
static void SetEnabled(bool doEnable)
static void CloseGame()
void SetMemoryUsage(long bufferSize, int bufferCount)
ALuint GetALSource(ISoundItem *anItem)
Definition: SoundManager.cpp:410
void PauseMusic(bool pauseIt)
Definition: SoundManager.cpp:729
float m_UIGain
Definition: SoundManager.h:77
void SetDistressThroughError()
Definition: SoundManager.cpp:398
static void al_check(const char *caller, int line)
Definition: SoundManager.cpp:219
static void CreateSoundManager()
float m_Gain
Definition: SoundManager.h:73
static void al_ReportError(ALenum err, const char *caller, int line)
Definition: SoundManager.cpp:214
CStr8 m_OpenALVersion
Definition: SoundManager.h:96
void PauseAction(bool pauseIt)
Definition: SoundManager.cpp:754
void SetActionGain(float gain)
Definition: SoundManager.cpp:506
long m_DistressTime
Definition: SoundManager.h:93
CStr8 GetSoundCardNames() const
Definition: SoundManager.cpp:862
float m_ActionGain
Definition: SoundManager.h:76
bool m_Enabled
Definition: SoundManager.h:78
long GetBufferCount()
Definition: SoundManager.cpp:436
void SetMusicItem(ISoundItem *anItem)
Definition: SoundManager.cpp:759
void PauseAmbient(bool pauseIt)
Definition: SoundManager.cpp:744
Definition: Vector3D.h:31
Definition: ISoundItem.h:30
Definition: ISoundManager.h:29
Definition: path.h:80
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
u32 entity_id_t
Entity ID type.
Definition: Entity.h:29
i64 Status
Error handling system.
Definition: status.h:173
Definition: SoundManager.h:43
ALuint ALSource
Title of the column.
Definition: SoundManager.h:45
ISoundItem * SourceItem
Definition: SoundManager.h:46