2006-09-30 22:13:11 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : SoundGroup.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : Loads up a group of sound files with shared properties,
|
|
|
|
* and provides a simple interface for playing them.
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
2007-01-13 17:00:52 +01:00
|
|
|
|
2007-05-08 17:11:53 +02:00
|
|
|
// license: GPL; see sound/license.txt
|
2007-01-13 17:00:52 +01:00
|
|
|
|
2006-09-30 22:13:11 +02:00
|
|
|
/*
|
2007-01-13 17:00:52 +01:00
|
|
|
Example usage: (SEE SOUNDGROUPMGR.H)
|
2006-09-30 22:13:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
Example SoundGroup.xml
|
|
|
|
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
|
|
|
|
<SoundGroup>
|
|
|
|
<Gain>1.0</Gain>
|
|
|
|
<Looping>0</Looping>
|
|
|
|
<Pitch>1.0</Pitch>
|
|
|
|
<Priority>100</Priority>
|
|
|
|
<RandOrder>0</RandOrder>
|
|
|
|
<RandGain>0</RandGain>
|
|
|
|
<RandPitch>0</RandPitch>
|
|
|
|
<ConeGain>1.0</ConeGain>
|
|
|
|
<ConeInner>360</ConeInner>
|
|
|
|
<ConeOuter>360</ConeOuter>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_Attackx.ogg</Sound>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_Chargex.ogg</Sound>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_Engagex.ogg</Sound>
|
|
|
|
<Sound>audio/voice/hellenes/soldier/Attack_ForMyFamily.ogg</Sound>
|
|
|
|
</SoundGroup>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_SOUNDGROUP
|
|
|
|
#define INCLUDED_SOUNDGROUP
|
2006-09-30 22:13:11 +02:00
|
|
|
|
|
|
|
#include "lib/res/handle.h"
|
2006-10-20 03:06:43 +02:00
|
|
|
#include "ps/CStr.h"
|
2006-09-30 22:13:11 +02:00
|
|
|
#include "lib/res/sound/snd_mgr.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
|
2006-11-12 05:02:36 +01:00
|
|
|
enum eSndGrpFlags
|
|
|
|
{
|
|
|
|
eRandOrder = 0x01,
|
|
|
|
eRandGain = 0x02,
|
|
|
|
eRandPitch = 0x04,
|
|
|
|
eLoop = 0x08
|
|
|
|
};
|
2006-09-30 22:13:11 +02:00
|
|
|
|
2007-01-13 17:00:52 +01:00
|
|
|
|
2006-09-30 22:13:11 +02:00
|
|
|
class CSoundGroup
|
|
|
|
{
|
2006-10-17 09:55:35 +02:00
|
|
|
size_t m_index; // index of the next sound to play
|
2006-09-30 22:13:11 +02:00
|
|
|
|
2007-01-13 17:00:52 +01:00
|
|
|
Handle m_hReplacement;
|
|
|
|
|
2006-09-30 22:13:11 +02:00
|
|
|
vector<Handle> snd_group; // we store the handles so we can load now and play later
|
|
|
|
vector<CStr> filenames; // we need the filenames so we can reload when necessary.
|
2007-01-13 17:00:52 +01:00
|
|
|
vector<float> playtimes; // it would be better to store this in with the Handles perhaps?
|
2006-10-17 09:55:35 +02:00
|
|
|
CStr m_filepath; // the file path for the list of sound file resources
|
2007-01-13 17:00:52 +01:00
|
|
|
CStr m_intensity_file; // the replacement aggregate 'intense' sound
|
2006-09-30 22:13:11 +02:00
|
|
|
|
2007-01-13 17:00:52 +01:00
|
|
|
float m_CurTime; // Time elapsed since soundgroup was created
|
|
|
|
float m_TimeWindow; // The Intensity Threshold Window
|
|
|
|
size_t m_IntensityThreshold; // the allowable intensity before a sound switch
|
|
|
|
size_t m_Intensity; // our current intensity(number of sounds played since m_CurTime - m_TimeWindow)
|
|
|
|
float m_Decay; //
|
2006-09-30 22:13:11 +02:00
|
|
|
unsigned char m_Flags; // up to eight individual parameters, use with eSndGrpFlags.
|
2007-01-13 17:00:52 +01:00
|
|
|
|
2006-09-30 22:13:11 +02:00
|
|
|
float m_Gain;
|
|
|
|
float m_Pitch;
|
|
|
|
float m_Priority;
|
|
|
|
float m_ConeOuterGain;
|
|
|
|
float m_PitchUpper;
|
|
|
|
float m_PitchLower;
|
|
|
|
float m_GainUpper;
|
|
|
|
float m_GainLower;
|
2006-10-17 09:55:35 +02:00
|
|
|
float m_ConeInnerAngle;
|
|
|
|
float m_ConeOuterAngle;
|
2006-09-30 22:13:11 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
CSoundGroup(const char *XMLfile);
|
|
|
|
CSoundGroup(void);
|
|
|
|
~CSoundGroup(void);
|
|
|
|
|
|
|
|
// Play next sound in group
|
|
|
|
void PlayNext();
|
|
|
|
|
|
|
|
// Load a group
|
|
|
|
bool LoadSoundGroup(const char *XMLfile);
|
|
|
|
|
|
|
|
void Reload();
|
|
|
|
|
|
|
|
// Release all remaining loaded handles
|
|
|
|
void ReleaseGroup();
|
2007-01-13 17:00:52 +01:00
|
|
|
|
|
|
|
// Update SoundGroup, remove dead sounds from intensity count
|
|
|
|
void Update(float TimeSinceLastFrame);
|
2006-09-30 22:13:11 +02:00
|
|
|
|
|
|
|
// Set a flag using a value from eSndGrpFlags
|
|
|
|
inline void SetFlag(int flag){ m_Flags |= flag; }
|
|
|
|
|
|
|
|
// Test flag, returns true if flag is set.
|
|
|
|
inline bool TestFlag(int flag) { return (m_Flags & flag) == flag;}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif //#ifndef INCLUDED_SOUNDGROUP
|