Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SoundManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 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 
26 
27 
28 #include "lib/file/vfs/vfs_path.h"
35 #include "ps/Profiler2.h"
36 
37 #include <vector>
38 #include <map>
39 
40 #define AL_CHECK CSoundManager::al_check(__func__, __LINE__);
41 
43 {
44  /// Title of the column
45  ALuint ALSource;
47 };
48 
49 typedef std::vector<VfsPath> PlayList;
50 typedef std::vector<ISoundItem*> ItemsList;
51 typedef std::map<entity_id_t, ISoundItem*> ItemsMap;
52 typedef std::map<std::wstring, CSoundGroup*> SoundGroupMap;
53 
55 
56 
58 {
60 
61 protected:
62 
64  ALCcontext* m_Context;
65  ALCdevice* m_Device;
72 
73  float m_Gain;
74  float m_MusicGain;
76  float m_ActionGain;
77  float m_UIGain;
78  bool m_Enabled;
83 
90 
94 
96 
97 public:
98  CSoundManager();
99  virtual ~CSoundManager();
100 
101  ISoundItem* LoadItem(const VfsPath& itemPath);
102  ISoundItem* ItemForData(CSoundData* itemData);
103  ISoundItem* ItemForEntity( entity_id_t source, CSoundData* sndData);
104 
105  Status ReloadChangedFiles(const VfsPath& path);
106 
107  void ClearPlayListItems();
108  void StartPlayList( bool doLoop );
109  void AddPlayListItem(const VfsPath& itemPath);
110 
111  static void ScriptingInit();
112  static void CreateSoundManager();
113  static void SetEnabled(bool doEnable);
114  static Status ReloadChangedFileCB(void* param, const VfsPath& path);
115 
116  static void CloseGame();
117 
118  static void al_ReportError(ALenum err, const char* caller, int line);
119  static void al_check(const char* caller, int line);
120 
121  void SetMusicEnabled (bool isEnabled);
122  void setSoundEnabled( bool enabled );
123 
124  ALuint GetALSource(ISoundItem* anItem);
125  void ReleaseALSource(ALuint theSource);
126  ISoundItem* ItemFromData(CSoundData* itemData);
127 
128  ISoundItem* ItemFromWAV(VfsPath& fname);
129  ISoundItem* ItemFromOgg(VfsPath& fname);
130 
131  ISoundItem* GetSoundItem(unsigned long itemRow);
132  unsigned long Count();
133  void IdleTask();
134 
135  void SetMemoryUsage(long bufferSize, int bufferCount);
136  long GetBufferCount();
137  long GetBufferSize();
138 
139  void PlayAsMusic( const VfsPath& itemPath, bool looping );
140  void PlayAsAmbient( const VfsPath& itemPath, bool looping );
141  void PlayAsUI(const VfsPath& itemPath, bool looping);
142  void PlayAsGroup(const VfsPath& groupPath, CVector3D sourcePos, entity_id_t source, bool ownedSound);
143 
144  void PlayGroupItem(ISoundItem* anItem, ALfloat groupGain);
145 
146  bool InDistress();
149 
150  void Pause(bool pauseIt);
151  void PauseMusic (bool pauseIt);
152  void PauseAmbient (bool pauseIt);
153  void PauseAction (bool pauseIt);
154  void SetAmbientItem(ISoundItem* anItem);
155 
156 protected:
157  void InitListener();
158  Status AlcInit();
159  void SetMusicItem(ISoundItem* anItem);
160  void SetMasterGain(float gain);
161  void SetMusicGain(float gain);
162  void SetAmbientGain(float gain);
163  void SetActionGain(float gain);
164  void SetUIGain(float gain);
165 
166 private:
168 };
169 
170 #else // !CONFIG2_AUDIO
171 
172 #define AL_CHECK
173 
174 #endif // !CONFIG2_AUDIO
175 
176 #endif // INCLUDED_SOUNDMANAGER_H
177 
ISoundItem * ItemForData(CSoundData *itemData)
static void ScriptingInit()
void PlayGroupItem(ISoundItem *anItem, ALfloat groupGain)
ALuint ALSource
Title of the column.
Definition: SoundManager.h:45
bool m_LoopingPlaylist
Definition: SoundManager.h:89
void Pause(bool pauseIt)
Status AlcInit()
void SetDistressThroughShortage()
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
float m_AmbientGain
Definition: SoundManager.h:75
SoundGroupMap m_SoundGroups
Definition: SoundManager.h:71
std::vector< ISoundItem * > ItemsList
Definition: SoundManager.h:50
bool m_SoundEnabled
Definition: SoundManager.h:82
static void SetEnabled(bool doEnable)
bool m_MusicPaused
Definition: SoundManager.h:84
ISoundItem * ItemFromOgg(VfsPath &fname)
long GetBufferSize()
ALCdevice * m_Device
Definition: SoundManager.h:65
ALCcontext * m_Context
Definition: SoundManager.h:64
void ClearPlayListItems()
PlayList * m_PlayListItems
Definition: SoundManager.h:70
void SetMusicGain(float gain)
void setSoundEnabled(bool enabled)
CMutex m_DistressMutex
Definition: SoundManager.h:69
std::map< entity_id_t, ISoundItem * > ItemsMap
Definition: SoundManager.h:51
void PlayAsUI(const VfsPath &itemPath, bool looping)
ALuint GetALSource(ISoundItem *anItem)
long m_DistressErrCount
Definition: SoundManager.h:92
ISoundItem * m_CurrentEnvirons
Definition: SoundManager.h:67
void SetAmbientGain(float gain)
A non-recursive mutual exclusion lock.
Definition: ThreadUtil.h:45
unsigned long Count()
CSoundManager(CSoundManager *other)
Definition: SoundManager.h:167
virtual ~CSoundManager()
void SetMusicEnabled(bool isEnabled)
void PauseMusic(bool pauseIt)
CSoundManagerWorker * m_Worker
Definition: SoundManager.h:68
static Status ReloadChangedFileCB(void *param, const VfsPath &path)
void SetDistressThroughError()
bool m_RunningPlaylist
Definition: SoundManager.h:87
void PlayAsGroup(const VfsPath &groupPath, CVector3D sourcePos, entity_id_t source, bool ownedSound)
Definition: path.h:75
New profiler (complementing the older CProfileManager)
void SetAmbientItem(ISoundItem *anItem)
void SetMusicItem(ISoundItem *anItem)
ISoundItem * SourceItem
Definition: SoundManager.h:46
std::vector< VfsPath > PlayList
Definition: SoundManager.h:49
void SetMemoryUsage(long bufferSize, int bufferCount)
ALuint m_ALEnvironment
Definition: SoundManager.h:63
bool m_MusicEnabled
Definition: SoundManager.h:81
long m_DistressTime
Definition: SoundManager.h:93
i64 Status
Error handling system.
Definition: status.h:171
void StartPlayList(bool doLoop)
static void al_check(const char *caller, int line)
void SetMasterGain(float gain)
static void CloseGame()
void PauseAction(bool pauseIt)
ISoundItem * ItemForEntity(entity_id_t source, CSoundData *sndData)
void PauseAmbient(bool pauseIt)
void PlayAsMusic(const VfsPath &itemPath, bool looping)
static void al_ReportError(ALenum err, const char *caller, int line)
ISoundItem * m_CurrentTune
Definition: SoundManager.h:66
ISoundItem * ItemFromWAV(VfsPath &fname)
void PlayAsAmbient(const VfsPath &itemPath, bool looping)
static void CreateSoundManager()
float m_MusicGain
Definition: SoundManager.h:74
long m_PlaylistGap
Definition: SoundManager.h:91
bool m_PlayingPlaylist
Definition: SoundManager.h:88
ISoundItem * LoadItem(const VfsPath &itemPath)
std::map< std::wstring, CSoundGroup * > SoundGroupMap
Definition: SoundManager.h:52
void AddPlayListItem(const VfsPath &itemPath)
float m_ActionGain
Definition: SoundManager.h:76
void ReleaseALSource(ALuint theSource)
long GetBufferCount()
NONCOPYABLE(CSoundManager)
ISoundItem * GetSoundItem(unsigned long itemRow)
void SetUIGain(float gain)
Status ReloadChangedFiles(const VfsPath &path)
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
bool m_ActionPaused
Definition: SoundManager.h:86
ISoundItem * ItemFromData(CSoundData *itemData)
bool m_AmbientPaused
Definition: SoundManager.h:85
ALSourceHolder * m_ALSourceBuffer
Definition: SoundManager.h:95
void SetActionGain(float gain)