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