Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Sound Class Reference

#include <Sound.h>

Inheritance diagram for Sound:

Inheritance graph
[legend]
Collaboration diagram for Sound:

Collaboration graph
[legend]
List of all members.

Static Public Methods

void init (istream &in)
 Initialze the sound system by loading settings, samples from a file.

void playRandomSound (int soundClass, float volume=s_masterSFXVol)
 plays a random sound from set of sounds specified by soundClass

void play (int sample, float volume=s_masterSFXVol)
 Play a sample.

void loop (int sample, float volume=s_masterSFXVol)
 Loop a sample at specified volume. volume ranges from 0.0 to 1.0.

void stop (int sample)
 Stop a sample from looping.

const vector< NDX_Sample * > & samples ()
 Return the list of samples.

void increaseSongVol ()
 increase the volume of the background song

void decreaseSongVol ()
 decrease the volume of the background song

void increaseSFXVol ()
 increase the volume of the sound effects

void decreaseSFXVol ()
 decrease the volume of the sound effects

float getMasterSFXVol ()
float getMasterSongVol ()
void shutdown ()
 Free any resources.

void playMusic (int sample, float volume=s_masterSongVol)
 works just like loop(sample), except that there can be only 1 music at a time. When you play a new one, the old one is automatically stopped

Sound & getObj ()

Static Public Attributes

const int CLASS_SELECT = 0
 classes of sounds played when a unit is selected

const int CLASS_ACK = 1
 played when a unit is given a command

const int CLASS_TARGET = 2
 played when a battallion aquires a target

const int CLASS_DEATH = 3
 played when a unit dies

const int CLASS_CREATE_LT = 4
 played when light tank is created

const int CLASS_CREATE_HT = 5
 played when heavy tank is created

const int CLASS_CREATE_RT = 6
 played when rocket tank is created

const int CLASS_CREATE_AR = 7
 played when artillery is created

const int CLASS_CREATE_JT = 8
 played when jet is created

const int CLASS_BATTLE_CONTACT = 9
 played during when battle units engage

const int CLASS_BATTLE_STRESS = 10
 played during when battle units are stressed

const int CLASS_BATTLE_PANICK = 11
 played during when battle units are panicked

const int CLASS_JET_INTERCEPT = 12
 played during when jets intercept jets

const int CLASS_JET_BOMBING = 13
 played during when jets bomb targets

const int CLASS_JET_DIE = 14
 played during when jets die

const int NUM_CLASSES = 15
const int SMPL_SONG_WAR_WORLDS = 0
const int SMPL_SONG_MENU = 1
const int SMPL_SONG_WIN = 2
const int SMPL_SONG_LOST = 3
const int SMPL_SFX_EXPLOSION_LARGE = 4
const int SMPL_SFX_FIRE_LIGHTTANK = 5
const int SMPL_SFX_FIRE_LAUNCHER = 4
const int SMPL_SFX_FIRE_ARTILLERY = 7
const int SMPL_SFX_FIRE_JET = 8
const int SMPL_TUTORIAL_CITIES = 9
const int SMPL_TUTORIAL_INTRO = 10
const int SMPL_TUTORIAL_OVERHEAD = 11
const int SMPL_TUTORIAL_UNITS = 12
const int SMPL_TUTORIAL_BATTLE_CIRCLE = 13
const int SMPL_TUTORIAL_OVERHEAD_WHILE_BATTLE = 14
const int SMPL_TUTORIAL_BATTLE_MODE = 15
const int SMPL_TUTORIAL_TWO_BATTLES_AT_ONCE = 16
const int MSG_ANOTHER_BATTLE_IS_HAPPENING = 17

Static Protected Methods

void releaseObj ()
 should only be called by the class that inherits the Singleton functionality after the subclasses releases all its necessary resources


Static Private Methods

NDX_Sample * sampleFromWAV (LPSTR fn, int bufCount)

Private Attributes

NDX_Sound m_sound
vector< NDX_Sample * > m_sndClass [NUM_CLASSES]
vector< NDX_Sample * > m_samples
int currentMusic
vector< int > lastRandomSelected

Static Private Attributes

Sound * s_pObj
float s_masterSongVol
float s_masterSFXVol
int s_songHandle

Member Function Documentation

void Sound::decreaseSFXVol   [static]
 

decrease the volume of the sound effects

Definition at line 206 of file Sound.cpp.

References s_masterSFXVol, and VOL_STEP().

Referenced by HUD::processOverheadInput().

00207 {
00208   if(s_masterSFXVol > 0.0f)  
00209     s_masterSFXVol -= VOL_STEP;
00210 
00211 }

void Sound::decreaseSongVol   [static]
 

decrease the volume of the background song

Definition at line 191 of file Sound.cpp.

References currentMusic, m_samples, s_masterSongVol, s_pObj, and VOL_STEP().

Referenced by HUD::processOverheadInput().

00192 {
00193   if(s_masterSongVol > 0.0f)  
00194   {
00195     s_masterSongVol -= VOL_STEP;
00196     s_pObj->m_samples[s_pObj->currentMusic]->SetVolume(s_songHandle, NDX_CALCVOLUME(s_masterSongVol));
00197   }
00198 }

float Sound::getMasterSFXVol   [static]
 

Definition at line 213 of file Sound.cpp.

References s_masterSFXVol.

Referenced by BattleGroup::destroyUnit(), BattleGroup::fire(), BattleJets::fireAntiAirMissiles(), BattleJets::fireAntiSurfaceMissiles(), playVoiceContact(), playVoicePanick(), playVoiceStress(), and BattleJets::takeHit().

00214 {
00215         return s_masterSFXVol;
00216 }

float Sound::getMasterSongVol   [static]
 

Definition at line 218 of file Sound.cpp.

References s_masterSongVol.

00219 {
00220         return s_masterSongVol;
00221 }

Sound& Singleton< Sound >::getObj   [static, inherited]
 

Referenced by init(), and main_init().

void Sound::increaseSFXVol   [static]
 

increase the volume of the sound effects

Definition at line 200 of file Sound.cpp.

References s_masterSFXVol, and VOL_STEP().

Referenced by HUD::processOverheadInput().

00201 {
00202   if(s_masterSFXVol < 1.0f)
00203     s_masterSFXVol += VOL_STEP;
00204 }

void Sound::increaseSongVol   [static]
 

increase the volume of the background song

Definition at line 182 of file Sound.cpp.

References currentMusic, m_samples, s_masterSongVol, s_pObj, and VOL_STEP().

Referenced by HUD::processOverheadInput().

00183 {
00184   if(s_masterSongVol < 1.0f)
00185   {
00186     s_masterSongVol += VOL_STEP;
00187     s_pObj->m_samples[s_pObj->currentMusic]->SetVolume(s_songHandle, NDX_CALCVOLUME(s_masterSongVol));
00188   }
00189 }

void Sound::init istream &    in [static]
 

Initialze the sound system by loading settings, samples from a file.

Initializes the sound subsystem.

Parameters:
in the input stream that contains the names of the samples and sounds. ALL comments should be stripped from the input stream. The sound classes are surround by a BEGIN CLASSES/END CLASSES pair and each sound is listed with the class number (defined by the constants in Sound.h) it belongs to.
The order the sounds/samples are loaded is the order in which the named constants are listed so the filenames should be listed in the same order.

Definition at line 52 of file Sound.cpp.

References currentMusic, Singleton< Sound >::getObj(), lastRandomSelected, m_samples, m_sndClass, m_sound, NUM_CLASSES, s_pObj, sampleFromWAV(), samples(), TOK_BEGIN_SAMPLES(), and TOK_BEGIN_SOUND_CLASSES().

Referenced by main_init().

00053 {
00054   s_pObj = &Sound::getObj();
00055 
00056   assert(s_pObj->m_sound.Create(sys_getWindowHandle()) == NDXERR_OK);
00057 
00058   // load the sound classes
00059   ostringstream dump;
00060   dump << in.rdbuf();
00061   string rawdata = dump.str();
00062 
00063   size_t start = rawdata.find(TOK_BEGIN_SOUND_CLASSES)+TOK_BEGIN_SOUND_CLASSES.size();
00064   size_t len = rawdata.find(TOK_END_SOUND_CLASSES) - start;
00065   istringstream classData(rawdata.substr(start, len));
00066 
00067   string line;
00068   while(getline(classData, line))
00069   {
00070     // format of the sound class data:
00071     // CLASS_NUM WAV_FILE_NAME NUMBER_OF_BUFFERS
00072     istringstream is(line);
00073     int classNum;
00074     string s;
00075     int bc;
00076     is >> classNum >> s >> bc;
00077     s_pObj->m_sndClass[classNum].push_back(sampleFromWAV(const_cast<LPSTR>(s.data()), bc));
00078 
00079         for( int i=0; i<NUM_CLASSES; i++ )
00080                 s_pObj->lastRandomSelected.push_back(-1);
00081   }
00082 
00083   // load the rest of the samples
00084   start = rawdata.find(TOK_BEGIN_SAMPLES)+TOK_BEGIN_SAMPLES.size();
00085   len = rawdata.find(TOK_END_SAMPLES) - start;
00086   istringstream samples(rawdata.substr(start, len));
00087 
00088   while(getline(samples, line))
00089   {
00090     // format of the sound samples data:
00091     // WAV_FILE_NAME NUMBER_OF_BUFFERS
00092     istringstream is(line);
00093     string s;
00094     int bc;
00095     is >> s >> bc;
00096     s_pObj->m_samples.push_back(sampleFromWAV(const_cast<LPSTR>(s.data()), bc));
00097   }
00098 
00099   s_pObj->currentMusic = -1;
00100 }

void Sound::loop int    sample,
float    volume = s_masterSFXVol
[static]
 

Loop a sample at specified volume. volume ranges from 0.0 to 1.0.

Definition at line 167 of file Sound.cpp.

References m_samples, and s_pObj.

00168 { 
00169   s_pObj->m_samples[sample]->Loop(NDX_CALCVOLUME(volume)); 
00170 }

void Sound::play int    sample,
float    volume = s_masterSFXVol
[static]
 

Play a sample.

Definition at line 154 of file Sound.cpp.

References m_samples, and s_pObj.

Referenced by Tutorial::battleCircle(), Tutorial::battleMode(), Tutorial::city(), BattleGroup::destroyUnit(), Overhead::doCollisionDetection(), BattleGroup::fire(), BattleJets::fireAntiAirMissiles(), BattleJets::fireAntiSurfaceMissiles(), Tutorial::intro(), Tutorial::overhead(), Tutorial::overheadWhileBattle(), BattleJets::takeHit(), Tutorial::twoBattlesAtOnce(), and Tutorial::unit().

00155 { 
00156   s_pObj-> m_samples[sample]->Play(NDX_CALCVOLUME(volume)); 
00157 }

void Sound::playMusic int    sample,
float    volume = s_masterSongVol
[static]
 

works just like loop(sample), except that there can be only 1 music at a time. When you play a new one, the old one is automatically stopped

Definition at line 160 of file Sound.cpp.

References currentMusic, m_samples, s_pObj, and stop().

Referenced by Overhead::overhead_init(), and updateSponsor().

00161 {
00162         if( s_pObj->currentMusic!=-1 ) s_pObj->stop(s_pObj->currentMusic);
00163   s_pObj->m_samples[sample]->Loop(NDX_CALCVOLUME(s_masterSongVol), &s_songHandle);
00164         s_pObj->currentMusic = sample;
00165 }

void Sound::playRandomSound int    soundClass,
float    volume = s_masterSFXVol
[static]
 

plays a random sound from set of sounds specified by soundClass

Precondition:
soundClass is in range from 0 to 3 inclusive
:

Definition at line 141 of file Sound.cpp.

References lastRandomSelected, m_sndClass, s_pObj, and sys_localRandInt().

Referenced by BattleEntry::inputIssueGroupCommand(), BattleEntry::inputIssueJetsCommand(), BattleEntry::inputSelectGroups(), BattleEntry::inputSelectJets(), playVoiceContact(), playVoicePanick(), playVoiceStress(), HUD::processMiniMapInput(), Overhead::processOverheadInput(), and City::update().

00142 {
00144         int N = (int)s_pObj->m_sndClass[soundClass].size();
00145         size_t idx = sys_localRandInt() % N;
00146 
00147         if( N>1 && idx==s_pObj->lastRandomSelected[soundClass] )                        // don't pick the same thing twice
00148                 idx = (idx+1) % N;
00149         s_pObj->lastRandomSelected[soundClass] = (int)idx;
00150                 
00151         s_pObj->m_sndClass[soundClass][idx]->Play(NDX_CALCVOLUME(volume));
00152 }

void Singleton< Sound >::releaseObj   [static, protected, inherited]
 

should only be called by the class that inherits the Singleton functionality after the subclasses releases all its necessary resources

Referenced by shutdown().

NDX_Sample * Sound::sampleFromWAV LPSTR    fn,
int    bufCount
[static, private]
 

Loads a sample from wav file.

Parameters:
fn name of file (starting at project root).
bufCount number of buffers we have for this sound.

Definition at line 108 of file Sound.cpp.

References m_sound, and s_pObj.

Referenced by init().

00109 {
00110   NDX_Sample *s = new NDX_Sample();
00111   if( (s->LoadWAV(&s_pObj->m_sound, fn, bufCount)) != NDXERR_OK )
00112     throw Error(string("Sound::Unable to load: ")+string(fn));
00113   return s;
00114 }

const vector< NDX_Sample * > & Sound::samples   [static]
 

Return the list of samples.

Definition at line 177 of file Sound.cpp.

References m_samples, and s_pObj.

Referenced by init().

00178 { 
00179   return s_pObj->m_samples; 
00180 }

void Sound::shutdown   [static]
 

Free any resources.

Frees all the resources

Definition at line 119 of file Sound.cpp.

References m_samples, m_sndClass, NUM_CLASSES, Singleton< Sound >::releaseObj(), and s_pObj.

Referenced by Overhead::overhead_shutdown().

00120 {
00121   vector<NDX_Sample*>::iterator iter;
00122   for(int i=0; i<NUM_CLASSES; ++i)
00123   {
00124     for(iter = s_pObj->m_sndClass[i].begin(); iter != s_pObj->m_sndClass[i].end(); ++iter)
00125     {
00126       (*iter)->StopAll();
00127       delete *iter;
00128     }
00129   }
00130   for(iter = s_pObj->m_samples.begin(); iter != s_pObj->m_samples.end(); ++iter)
00131   {
00132     (*iter)->StopAll();
00133     delete *iter;
00134   }
00135   s_pObj->releaseObj();
00136 }

void Sound::stop int    sample [static]
 

Stop a sample from looping.

Definition at line 172 of file Sound.cpp.

References m_samples, and s_pObj.

Referenced by playMusic(), and Tutorial::stopTutorial().

00173 { 
00174   s_pObj->m_samples[sample]->StopAll(); 
00175 }


Member Data Documentation

const int Sound::CLASS_ACK = 1 [static]
 

played when a unit is given a command

Definition at line 36 of file Sound.h.

const int Sound::CLASS_BATTLE_CONTACT = 9 [static]
 

played during when battle units engage

Definition at line 52 of file Sound.h.

const int Sound::CLASS_BATTLE_PANICK = 11 [static]
 

played during when battle units are panicked

Definition at line 56 of file Sound.h.

const int Sound::CLASS_BATTLE_STRESS = 10 [static]
 

played during when battle units are stressed

Definition at line 54 of file Sound.h.

const int Sound::CLASS_CREATE_AR = 7 [static]
 

played when artillery is created

Definition at line 48 of file Sound.h.

const int Sound::CLASS_CREATE_HT = 5 [static]
 

played when heavy tank is created

Definition at line 44 of file Sound.h.

const int Sound::CLASS_CREATE_JT = 8 [static]
 

played when jet is created

Definition at line 50 of file Sound.h.

const int Sound::CLASS_CREATE_LT = 4 [static]
 

played when light tank is created

Definition at line 42 of file Sound.h.

const int Sound::CLASS_CREATE_RT = 6 [static]
 

played when rocket tank is created

Definition at line 46 of file Sound.h.

const int Sound::CLASS_DEATH = 3 [static]
 

played when a unit dies

Definition at line 40 of file Sound.h.

const int Sound::CLASS_JET_BOMBING = 13 [static]
 

played during when jets bomb targets

Definition at line 60 of file Sound.h.

const int Sound::CLASS_JET_DIE = 14 [static]
 

played during when jets die

Definition at line 62 of file Sound.h.

const int Sound::CLASS_JET_INTERCEPT = 12 [static]
 

played during when jets intercept jets

Definition at line 58 of file Sound.h.

const int Sound::CLASS_SELECT = 0 [static]
 

classes of sounds played when a unit is selected

Definition at line 34 of file Sound.h.

const int Sound::CLASS_TARGET = 2 [static]
 

played when a battallion aquires a target

Definition at line 38 of file Sound.h.

int Sound::currentMusic [private]
 

Definition at line 122 of file Sound.h.

Referenced by decreaseSongVol(), increaseSongVol(), init(), and playMusic().

vector<int> Sound::lastRandomSelected [private]
 

Definition at line 123 of file Sound.h.

Referenced by init(), and playRandomSound().

vector<NDX_Sample*> Sound::m_samples [private]
 

Definition at line 119 of file Sound.h.

Referenced by decreaseSongVol(), increaseSongVol(), init(), loop(), play(), playMusic(), samples(), shutdown(), and stop().

vector<NDX_Sample*> Sound::m_sndClass[NUM_CLASSES] [private]
 

Definition at line 118 of file Sound.h.

Referenced by init(), playRandomSound(), and shutdown().

NDX_Sound Sound::m_sound [private]
 

Definition at line 117 of file Sound.h.

Referenced by init(), and sampleFromWAV().

const int Sound::MSG_ANOTHER_BATTLE_IS_HAPPENING = 17 [static]
 

Definition at line 82 of file Sound.h.

const int Sound::NUM_CLASSES = 15 [static]
 

Definition at line 63 of file Sound.h.

Referenced by init(), and shutdown().

float Sound::s_masterSFXVol [static, private]
 

Referenced by decreaseSFXVol(), getMasterSFXVol(), and increaseSFXVol().

float Sound::s_masterSongVol [static, private]
 

Referenced by decreaseSongVol(), getMasterSongVol(), and increaseSongVol().

Sound * Sound::s_pObj [static, private]
 

Definition at line 35 of file Sound.cpp.

Referenced by decreaseSongVol(), increaseSongVol(), init(), loop(), play(), playMusic(), playRandomSound(), sampleFromWAV(), samples(), shutdown(), and stop().

int Sound::s_songHandle [static, private]
 

Definition at line 38 of file Sound.cpp.

const int Sound::SMPL_SFX_EXPLOSION_LARGE = 4 [static]
 

Definition at line 69 of file Sound.h.

const int Sound::SMPL_SFX_FIRE_ARTILLERY = 7 [static]
 

Definition at line 72 of file Sound.h.

const int Sound::SMPL_SFX_FIRE_JET = 8 [static]
 

Definition at line 73 of file Sound.h.

const int Sound::SMPL_SFX_FIRE_LAUNCHER = 4 [static]
 

Definition at line 71 of file Sound.h.

const int Sound::SMPL_SFX_FIRE_LIGHTTANK = 5 [static]
 

Definition at line 70 of file Sound.h.

const int Sound::SMPL_SONG_LOST = 3 [static]
 

Definition at line 68 of file Sound.h.

const int Sound::SMPL_SONG_MENU = 1 [static]
 

Definition at line 66 of file Sound.h.

const int Sound::SMPL_SONG_WAR_WORLDS = 0 [static]
 

Definition at line 65 of file Sound.h.

const int Sound::SMPL_SONG_WIN = 2 [static]
 

Definition at line 67 of file Sound.h.

const int Sound::SMPL_TUTORIAL_BATTLE_CIRCLE = 13 [static]
 

Definition at line 78 of file Sound.h.

const int Sound::SMPL_TUTORIAL_BATTLE_MODE = 15 [static]
 

Definition at line 80 of file Sound.h.

const int Sound::SMPL_TUTORIAL_CITIES = 9 [static]
 

Definition at line 74 of file Sound.h.

const int Sound::SMPL_TUTORIAL_INTRO = 10 [static]
 

Definition at line 75 of file Sound.h.

const int Sound::SMPL_TUTORIAL_OVERHEAD = 11 [static]
 

Definition at line 76 of file Sound.h.

const int Sound::SMPL_TUTORIAL_OVERHEAD_WHILE_BATTLE = 14 [static]
 

Definition at line 79 of file Sound.h.

const int Sound::SMPL_TUTORIAL_TWO_BATTLES_AT_ONCE = 16 [static]
 

Definition at line 81 of file Sound.h.

Referenced by Tutorial::stopTutorial().

const int Sound::SMPL_TUTORIAL_UNITS = 12 [static]
 

Definition at line 77 of file Sound.h.


The documentation for this class was generated from the following files:
Generated on Wed Apr 23 05:52:15 2003 for Modern Warfare by doxygen1.3-rc2