____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

sound.h File Reference

The sound header file. More...

#include <vector>
#include "unit.h"
#include "unitsound.h"
#include "player.h"

Go to the source code of this file.

Classes

class  GameSound
class  CSound
struct  Origin

Defines

#define MaxSampleVolume   255
 Maximum sample volume.
#define NO_SOUND   0
 No valid sound ID.
#define ONE_SOUND   0
#define TWO_GROUPS   1
#define INFINITE_SOUND_RANGE   255
#define MAX_SOUND_RANGE   254
#define CallbackMusicOn()   CallbackMusic = true;
 Turn music stopped callback off.
#define CallbackMusicOff()   CallbackMusic = false;

Functions

void PlayUnitSound (const CUnit *unit, UnitVoiceGroup unit_voice_group)
 < Play a unit sound
void PlayUnitSound (const CUnit *unit, CSound *sound)
 Play a missile sound.
void PlayMissileSound (const Missile *missile, CSound *sound)
 Play a game sound.
void PlayGameSound (CSound *sound, unsigned char volume)
 Play a sound file.
int PlayFile (const std::string &name, LuaActionListener *listener=NULL)
 Modify the range of a given sound.
void SetSoundRange (CSound *sound, unsigned char range)
 Register a sound (can be a simple sound or a group).
CSoundRegisterSound (const char *files[], unsigned number)
 Create a special sound group with two sounds.
CSoundRegisterTwoGroups (CSound *first, CSound *second)
 Initialize client side of the sound layer.
void InitSoundClient (void)
void CheckMusicFinished (bool force=false)
 < Check if music is finished and play the next song
void InitMusic (void)
 Turn music stopped callback on.
void MapSound (const std::string &sound_name, CSound *id)
 < Map sound to identifier
CSoundSoundForName (const std::string &sound_name)
 Make a sound bound to identifier.
CSoundMakeSound (const std::string &sound_name, const char *file[], int nb)
 Make a sound group bound to identifier.
CSoundMakeSoundGroup (const std::string &name, CSound *first, CSound *second)
void SoundCclRegister (void)
 < register ccl features

Variables

GameSound GameSounds
 Game sound configuration.
bool CallbackMusic
 flag true callback ccl if stops
int DistanceSilent
 silent distance


Detailed Description

The sound header file.

Definition in file sound.h.


Define Documentation

 
#define CallbackMusicOff (  )     CallbackMusic = false;

Definition at line 184 of file sound.h.

 
#define CallbackMusicOn (  )     CallbackMusic = true;

Turn music stopped callback off.

Definition at line 179 of file sound.h.

Referenced by CreateGame(), and InitModules().

#define INFINITE_SOUND_RANGE   255

the range value that makes a sound volume distance independent

Definition at line 115 of file sound.h.

Referenced by MapUnitSounds(), and VolumeForDistance().

#define MAX_SOUND_RANGE   254

the maximum range value

Definition at line 119 of file sound.h.

Referenced by RegisterSound(), RegisterTwoGroups(), and VolumeForDistance().

#define MaxSampleVolume   255

#define NO_SOUND   0

No valid sound ID.

Definition at line 57 of file sound.h.

Referenced by ChooseUnitVoiceSound(), RegisterSound(), RegisterTwoGroups(), and SetSoundRange().

#define ONE_SOUND   0

A possible value for Number in the Sound struct: means a simple sound

Definition at line 105 of file sound.h.

Referenced by RegisterSound(), SimpleChooseSample(), and CSound::~CSound().

#define TWO_GROUPS   1

A possible value for Number in the Sound struct: means a double group (for selection/annoyed sounds)

Definition at line 110 of file sound.h.

Referenced by ChooseSample(), RegisterTwoGroups(), and CSound::~CSound().


Function Documentation

void CheckMusicFinished ( bool  force  ) 

< Check if music is finished and play the next song

Initialize music

Check if music is finished and play the next song

Definition at line 77 of file music.cpp.

References CallbackMusic, IsMusicEnabled(), Lua, LuaCall(), MusicFinished, MusicFinishedMutex, SoundEnabled(), and StopMusic().

Referenced by EditorMainLoop(), GameMainLoop(), PatchEditorMainLoop(), and UiToggleSound().

void InitMusic ( void   ) 

Turn music stopped callback on.

Init music

Definition at line 101 of file music.cpp.

References MusicFinished, MusicFinishedCallback(), MusicFinishedMutex, and SetMusicFinishedCallback().

Referenced by main1().

void InitSoundClient ( void   ) 

CSound* MakeSound ( const std::string &  name,
const char *  file[],
int  nb 
)

Make a sound group bound to identifier.

Ask the sound server to register a sound and store the mapping between its name and its id. Register a sound group (or an unique sound if nb==1) and get the corresponding sound id.

Parameters:
name name of this sound group (Freed by caller).
file list of sound file names
nb number of sounds
Returns:
the sound id of the created group

Definition at line 99 of file sound_id.cpp.

References _C_, Assert, DebugPrint, MapSound(), RegisterSound(), and SoundMap.

Referenced by CclMakeSound().

CSound* MakeSoundGroup ( const std::string &  name,
CSound first,
CSound second 
)

Ask the sound server to build a special sound group.

Register two sound groups together to make a special sound (for selection). Return the corresponding id after registering it under a given name.

Parameters:
name the name of the group (handled by caller).
first id of the first group
second id of the second group
Returns:
Registered sound identifier.

Definition at line 129 of file sound_id.cpp.

References _C_, DebugPrint, MapSound(), RegisterTwoGroups(), and SoundMap.

Referenced by CclMakeSoundGroup().

void MapSound ( const std::string &  name,
CSound id 
)

< Map sound to identifier

Get the sound id bound to an identifier

Add a new mapping (sound name to sound id) in the hash table Create a new mapping between a name and an already valid sound id.

Parameters:
name Name of the sound (now freed by caller!).
id Sound identifier.

Definition at line 64 of file sound_id.cpp.

References SoundMap.

Referenced by CclMapSound(), MakeSound(), and MakeSoundGroup().

int PlayFile ( const std::string &  name,
LuaActionListener listener 
)

Modify the range of a given sound.

Play a sound file

Parameters:
name Filename of a sound to play
listener Optional lua callback
Returns:
Channel number the sound is playing on, -1 for error

Definition at line 386 of file sound.cpp.

References ChannelMap, LoadSample(), MaxVolume, PlaySample(), PlaySoundFileCallback(), SetChannelFinishedCallback(), and SetChannelVolume().

Referenced by tolua_stratagus_PlayFile00().

void PlayGameSound ( CSound sound,
unsigned char  volume 
)

Play a sound file.

Play a game sound

Parameters:
sound Sound to play
volume Volume level to play the sound

Definition at line 352 of file sound.cpp.

References CalculateVolume(), ChooseSample(), PlaySample(), CSound::Range, and SetChannelVolume().

Referenced by CclPlaySound(), CButtonPanel::DoClicked(), EditorCallbackButtonDown(), ParseNetworkCommand(), RescueUnits(), SpellCast(), UIHandleButtonDown(), and UIHandleButtonUp().

void PlayMissileSound ( const Missile missile,
CSound sound 
)

Play a game sound.

Ask the sound server to play a sound for a missile.

Parameters:
missile Sound initiator, missile exploding
sound Sound to be generated

Definition at line 323 of file sound.cpp.

References CalculateVolume(), ChooseSample(), MissileType::G, CViewport::MapWidth, CViewport::MapX, PlaySample(), CSound::Range, CUserInterface::SelectedViewport, SetChannelStereo(), SetChannelVolume(), TileSizeX, Missile::Type, UI, ViewPointDistanceToMissile(), CGraphic::Width, and Missile::X.

Referenced by MissileHit().

void PlayUnitSound ( const CUnit unit,
CSound sound 
)

Play a missile sound.

Ask to the sound server to play a sound attached to a unit. The sound server may discard the sound if needed (e.g., when the same unit is already speaking).

Parameters:
unit Sound initiator, unit speaking
sound Sound to be generated

Definition at line 306 of file sound.cpp.

References CalculateStereo(), CalculateVolume(), ChooseSample(), PlaySample(), CSound::Range, SetChannelStereo(), SetChannelVolume(), CUnit::Slot, and ViewPointDistanceToUnit().

void PlayUnitSound ( const CUnit unit,
UnitVoiceGroup  voice 
)

< Play a unit sound

Play a unit sound

Ask to the sound server to play a sound attached to a unit. The sound server may discard the sound if needed (e.g., when the same unit is already speaking).

Parameters:
unit Sound initiator, unit speaking
voice Type of sound wanted (Ready,Die,Yes,...)

Definition at line 280 of file sound.cpp.

References CalculateStereo(), CalculateVolume(), ChooseSample(), ChooseUnitVoiceSound(), PlaySample(), CSound::Range, SetChannelStereo(), SetChannelVolume(), CUnit::Slot, ViewPointDistanceToUnit(), VoiceBuilding, and VoiceSelected.

Referenced by DoActionMove(), DoRightButton(), HandleActionBuilt(), HandleActionTrain(), HitUnit(), LetUnitDie(), SendCommand(), UiFindIdleWorker(), UIHandleButtonUp(), and UnitShowAnimationScaled().

CSound* RegisterSound ( const char *  files[],
unsigned  number 
)

Create a special sound group with two sounds.

Ask the sound server to register a sound (and currently to load it) and to return an unique identifier for it. The unique identifier is memory pointer of the server.

Parameters:
files An array of wav files.
number Number of files belonging together.
Returns:
the sound unique identifier

Definition at line 427 of file sound.cpp.

References LoadSample(), MAX_SOUND_RANGE, NO_SOUND, ONE_SOUND, CSound::OneGroup, CSound::OneSound, and CSound::Sound.

Referenced by MakeSound().

CSound* RegisterTwoGroups ( CSound first,
CSound second 
)

Initialize client side of the sound layer.

Ask the sound server to put together two sounds to form a special sound.

Parameters:
first first part of the group
second second part of the group
Returns:
the special sound unique identifier

Definition at line 463 of file sound.cpp.

References MAX_SOUND_RANGE, NO_SOUND, CSound::Range, CSound::Sound, TWO_GROUPS, and CSound::TwoGroups.

Referenced by MakeSoundGroup().

void SetSoundRange ( CSound sound,
unsigned char  range 
)

Register a sound (can be a simple sound or a group).

Ask the sound server to change the range of a sound.

Parameters:
sound the id of the sound to modify.
range the new range for this sound.

Definition at line 410 of file sound.cpp.

References NO_SOUND, and CSound::Range.

Referenced by CclSetSoundRange(), and MapUnitSounds().

void SoundCclRegister ( void   ) 

< register ccl features

Register CCL features for sound.

Definition at line 334 of file script_sound.cpp.

References CclDefineGameSounds(), CclMakeSound(), CclMakeSoundGroup(), CclMapSound(), CclPlaySound(), CclSetGlobalSoundRange(), CclSetSoundRange(), CclSoundForName(), and Lua.

Referenced by InitCcl().

CSound* SoundForName ( const std::string &  name  ) 

Make a sound bound to identifier.

Maps a sound name to its id

Parameters:
name Sound name.
Returns:
Sound identifier for this name.

Definition at line 76 of file sound_id.cpp.

References _C_, Assert, DebugPrint, and SoundMap.

Referenced by CclDefineSpell(), CclSoundForName(), MissileType::Init(), InitSoundClient(), MapAnimSounds2(), MapUnitSounds(), and UIHandleButtonUp().


Variable Documentation

flag true callback ccl if stops

global range control (max cut off distance for sound)

Definition at line 57 of file music.cpp.

Referenced by CheckMusicFinished().

silent distance

Definition at line 92 of file sound.cpp.

Referenced by CclSetGlobalSoundRange(), InitSoundClient(), and VolumeForDistance().

Game sound configuration.

Various sounds used in game.

FIXME:

Todo:
Must remove static config.

Definition at line 68 of file sound.cpp.

Referenced by CclDefineGameSounds(), ChooseUnitVoiceSound(), CButtonPanel::DoClicked(), EditorCallbackButtonDown(), InitSoundClient(), ParseNetworkCommand(), RescueUnits(), UIHandleButtonDown(), and UIHandleButtonUp().


Generated on Sat Feb 21 00:28:19 2009 for Bos Wars by  doxygen 1.5.6