Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SoundGroup.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 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 /**
19 * =========================================================================
20 * File : SoundGroup.h
21 * Project : 0 A.D.
22 * Description : Loads up a group of sound files with shared properties,
23 * and provides a simple interface for playing them.
24 * =========================================================================
25 */
26 
27 /*
28 Example usage:
29 
30 
31 Example SoundGroup.xml
32  <?xml version="1.0" encoding="utf-8"?>
33  <SoundGroup>
34  <Gain>1.0</Gain>
35  <Looping>0</Looping>
36  <Pitch>1.0</Pitch>
37  <Priority>100</Priority>
38  <RandOrder>0</RandOrder>
39  <RandGain>0</RandGain>
40  <RandPitch>0</RandPitch>
41  <ConeGain>1.0</ConeGain>
42  <ConeInner>360</ConeInner>
43  <ConeOuter>360</ConeOuter>
44  <Sound>audio/voice/hellenes/soldier/Attack_Attackx.ogg</Sound>
45  <Sound>audio/voice/hellenes/soldier/Attack_Chargex.ogg</Sound>
46  <Sound>audio/voice/hellenes/soldier/Attack_Engagex.ogg</Sound>
47  <Sound>audio/voice/hellenes/soldier/Attack_ForMyFamily.ogg</Sound>
48  </SoundGroup>
49 
50 */
51 
52 #ifndef INCLUDED_SOUNDGROUP_H
53 #define INCLUDED_SOUNDGROUP_H
54 
55 #include "lib/config2.h"
56 #include "lib/file/vfs/vfs_path.h"
59 
60 #include <vector>
61 
62 class CVector3D;
63 class ISoundItem;
64 
66 {
67  eRandOrder = 0x01,
68  eRandGain = 0x02,
69  eRandPitch = 0x04,
70  eLoop = 0x08,
71  eOmnipresent = 0x10,
72  eDistanceless = 0x20,
73  eOwnerOnly = 0x40
74 };
75 
76 
78 {
80 public:
81  CSoundGroup(const VfsPath& pathnameXML);
82  CSoundGroup();
83  ~CSoundGroup();
84 
85  // Play next sound in group
86  // @param position world position of the entity generating the sound
87  // (ignored if the eOmnipresent flag is set)
88  void PlayNext(const CVector3D& position, entity_id_t source);
89 
90  float RadiansOffCenter(const CVector3D& position, bool& onScreen, float& itemRollOff);
91 
92  // Load a group
93  bool LoadSoundGroup(const VfsPath& pathnameXML);
94 
95  void Reload();
96 
97  // Release all remaining loaded handles
98  void ReleaseGroup();
99 
100  // Update SoundGroup, remove dead sounds from intensity count
101  void Update(float TimeSinceLastFrame);
102 
103  // Set a flag using a value from eSndGrpFlags
104  inline void SetFlag(int flag) { m_Flags = (unsigned char)(m_Flags | flag); }
105 
106  // Test flag, returns true if flag is set.
107  inline bool TestFlag(int flag) { return (m_Flags & flag) != 0; }
108 
109 private:
110  void SetGain(float gain);
111 
112  void UploadPropertiesAndPlay(size_t theIndex, const CVector3D& position, entity_id_t source);
113 
114  void SetDefaultValues();
115 
116  size_t m_index; // index of the next sound to play
117 
118 #if CONFIG2_AUDIO
119  std::vector<CSoundData*> snd_group; // we store the handles so we can load now and play later
120 #endif
121  std::vector<std::wstring> filenames; // we need the filenames so we can reload when necessary.
122 
123  VfsPath m_filepath; // the file path for the list of sound file resources
124 
125  float m_CurTime; // Time elapsed since soundgroup was created
126  float m_TimeWindow; // The Intensity Threshold Window
127  size_t m_IntensityThreshold; // the allowable intensity before a sound switch
128  size_t m_Intensity; // our current intensity(number of sounds played since m_CurTime - m_TimeWindow)
129  float m_Decay; //
130  unsigned char m_Flags; // up to eight individual parameters, use with eSndGrpFlags.
131 
132  float m_Gain;
133  float m_Pitch;
134  float m_Priority;
138  float m_GainUpper;
139  float m_GainLower;
142 };
143 
144 #endif //#ifndef INCLUDED_SOUNDGROUP_H
145 
float m_Gain
Definition: SoundGroup.h:132
float m_Pitch
Definition: SoundGroup.h:133
VfsPath m_filepath
Definition: SoundGroup.h:123
float m_GainUpper
Definition: SoundGroup.h:138
void SetDefaultValues()
Definition: SoundGroup.cpp:58
size_t m_IntensityThreshold
Definition: SoundGroup.h:127
void UploadPropertiesAndPlay(size_t theIndex, const CVector3D &position, entity_id_t source)
Definition: SoundGroup.cpp:156
std::vector< std::wstring > filenames
Definition: SoundGroup.h:121
void SetFlag(int flag)
Definition: SoundGroup.h:104
size_t m_Intensity
Definition: SoundGroup.h:128
void Update(float TimeSinceLastFrame)
Definition: SoundGroup.cpp:279
float RadiansOffCenter(const CVector3D &position, bool &onScreen, float &itemRollOff)
Definition: SoundGroup.cpp:105
bool LoadSoundGroup(const VfsPath &pathnameXML)
Definition: SoundGroup.cpp:283
float m_Priority
Definition: SoundGroup.h:134
float m_ConeInnerAngle
Definition: SoundGroup.h:140
float m_CurTime
Definition: SoundGroup.h:125
float m_TimeWindow
Definition: SoundGroup.h:126
Definition: path.h:75
float m_Decay
Definition: SoundGroup.h:129
float m_ConeOuterGain
Definition: SoundGroup.h:135
float m_ConeOuterAngle
Definition: SoundGroup.h:141
void Reload()
Definition: SoundGroup.cpp:243
float m_PitchUpper
Definition: SoundGroup.h:136
eSndGrpFlags
Definition: SoundGroup.h:65
std::vector< CSoundData * > snd_group
Definition: SoundGroup.h:119
void ReleaseGroup()
Definition: SoundGroup.cpp:268
float m_GainLower
Definition: SoundGroup.h:139
NONCOPYABLE(CSoundGroup)
size_t m_index
Definition: SoundGroup.h:116
void SetGain(float gain)
Definition: SoundGroup.cpp:52
unsigned char m_Flags
Definition: SoundGroup.h:130
float m_PitchLower
Definition: SoundGroup.h:137
u32 entity_id_t
Entity ID type.
Definition: Entity.h:24
bool TestFlag(int flag)
Definition: SoundGroup.h:107
void PlayNext(const CVector3D &position, entity_id_t source)
Definition: SoundGroup.cpp:233