_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Classes
sound.h File Reference
#include "unitsound.h"
#include "SDL.h"
#include "SDL_mixer.h"

Go to the source code of this file.

Classes

class  GameSound
 
class  CSound
 
struct  Origin
 

sound.h - The sound header file.

#define MaxSampleVolume   255
 
#define NO_SOUND   0
 
#define ONE_SOUND   0
 
#define TWO_GROUPS   1
 
#define INFINITE_SOUND_RANGE   255
 
#define MAX_SOUND_RANGE   254
 
enum  UnitVoiceGroup {
  VoiceSelected, VoiceAcknowledging, VoiceReady, VoiceHelpMe,
  VoiceDying, VoiceWorkCompleted, VoiceBuilding, VoiceDocking,
  VoiceRepairing, VoiceHarvesting, VoiceAttack, VoiceBuild
}
 
GameSound GameSounds
 
int DistanceSilent
 Game sound configuration. More...
 
unsigned char CalculateVolume (bool isVolume, int power, unsigned char range)
 Calculates volume level. More...
 
void PlayUnitSound (const CUnit &unit, UnitVoiceGroup unit_voice_group, bool sampleUnique=false)
 Play a unit sound. More...
 
void PlayUnitSound (const CUnit &unit, CSound *sound)
 Play a unit sound. More...
 
void PlayMissileSound (const Missile &missile, CSound *sound)
 Play a missile sound. More...
 
void PlayGameSound (CSound *sound, unsigned char volume, bool always=false)
 Play a game sound. More...
 
int PlayFile (const std::string &name, LuaActionListener *listener=NULL)
 Play a sound file. More...
 
void SetSoundRange (CSound *sound, unsigned char range)
 Modify the range of a given sound. More...
 
CSoundRegisterSound (const std::vector< std::string > &files)
 Register a sound (can be a simple sound or a group) More...
 
CSoundRegisterTwoGroups (CSound *first, CSound *second)
 Create a special sound group with two sounds. More...
 
void InitSoundClient ()
 Initialize client side of the sound layer. More...
 
void InitMusic ()
 Initialize music. More...
 
void CallbackMusicEnable ()
 Turn music stopped callback on. More...
 
void CallbackMusicDisable ()
 Skip the next music stopped callback invocation. More...
 
void CallbackMusicTrigger ()
 Turn music stopped callback on and trigger it immediately. More...
 
void MapSound (const std::string &sound_name, CSound *id)
 Map sound to identifier. More...
 
CSoundSoundForName (const std::string &sound_name)
 Get the sound id bound to an identifier. More...
 
CSoundMakeSound (const std::string &sound_name, const std::vector< std::string > &files)
 Make a sound bound to identifier. More...
 
CSoundMakeSoundGroup (const std::string &name, CSound *first, CSound *second)
 Make a sound group bound to identifier. More...
 
void FreeSounds ()
 
void SoundCclRegister ()
 register ccl features More...
 

Macro Definition Documentation

◆ INFINITE_SOUND_RANGE

#define INFINITE_SOUND_RANGE   255

the range value that makes a sound volume distance independent

◆ MAX_SOUND_RANGE

#define MAX_SOUND_RANGE   254

the maximum range value

◆ MaxSampleVolume

#define MaxSampleVolume   255

◆ NO_SOUND

#define NO_SOUND   0

◆ ONE_SOUND

#define ONE_SOUND   0

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

◆ TWO_GROUPS

#define TWO_GROUPS   1

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

Enumeration Type Documentation

◆ UnitVoiceGroup

Voice groups for a unit

Enumerator
VoiceSelected 
VoiceAcknowledging 

If selected.

VoiceReady 

Acknowledge command.

VoiceHelpMe 

Command completed.

VoiceDying 

If attacked.

VoiceWorkCompleted 

If killed.

VoiceBuilding 

only worker, work completed

VoiceDocking 

only for building under construction

VoiceRepairing 

only for transport reaching coast

VoiceHarvesting 

repairing

VoiceAttack 

harvesting

VoiceBuild 

Attack command.

worker goes to build a building

Function Documentation

◆ CalculateVolume()

unsigned char CalculateVolume ( bool  isVolume,
int  power,
unsigned char  range 
)

Calculates volume level.

Calculate the volume associated with a request, either by clipping the range parameter of this request, or by mapping this range to a volume.

◆ CallbackMusicDisable()

void CallbackMusicDisable ( )

Skip the next music stopped callback invocation.

◆ CallbackMusicEnable()

void CallbackMusicEnable ( )

Turn music stopped callback on.

◆ CallbackMusicTrigger()

void CallbackMusicTrigger ( )

Turn music stopped callback on and trigger it immediately.

◆ FreeSounds()

void FreeSounds ( )

◆ InitMusic()

void InitMusic ( )

Initialize music.

Init music

◆ InitSoundClient()

void InitSoundClient ( )

Initialize client side of the sound layer.

Lookup the sound id's for the game sounds.

◆ MakeSound()

CSound* MakeSound ( const std::string &  name,
const std::vector< std::string > &  files 
)

Make a sound 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
namename of this sound group (Freed by caller).
filelist of sound file names
nbnumber of sounds
Returns
the sound id of the created group

◆ MakeSoundGroup()

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

Make a sound group bound to identifier.

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
namethe name of the group (handled by caller).
firstid of the first group
secondid of the second group
Returns
Registered sound identifier.

◆ MapSound()

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

Map sound to 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
nameName of the sound (now freed by caller!).
idSound identifier.

◆ PlayFile()

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

Play a sound file.

Play a sound file

Parameters
nameFilename of a sound to play
listenerOptional lua callback
Returns
Channel number the sound is playing on, -1 for error

◆ PlayGameSound()

void PlayGameSound ( CSound sound,
unsigned char  volume,
bool  always 
)

Play a game sound.

Play a game sound

Parameters
soundSound to play
volumeVolume level to play the sound

◆ PlayMissileSound()

void PlayMissileSound ( const Missile missile,
CSound sound 
)

Play a missile sound.

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

Parameters
missileSound initiator, missile exploding
soundSound to be generated

◆ PlayUnitSound() [1/2]

void PlayUnitSound ( const CUnit unit,
CSound 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
unitSound initiator, unit speaking
soundSound to be generated

◆ PlayUnitSound() [2/2]

void PlayUnitSound ( const CUnit unit,
UnitVoiceGroup  voice,
bool  sampleUnique 
)

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
unitSound initiator, unit speaking
voiceType of sound wanted (Ready,Die,Yes,...)

◆ RegisterSound()

CSound* RegisterSound ( const std::vector< std::string > &  files)

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

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
filesAn array of wav files.
numberNumber of files belonging together.
Returns
the sound unique identifier
Todo:
FIXME: Must handle the errors better.

◆ RegisterTwoGroups()

CSound* RegisterTwoGroups ( CSound first,
CSound second 
)

Create a special sound group with two sounds.

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

Parameters
firstfirst part of the group
secondsecond part of the group
Returns
the special sound unique identifier

◆ SetSoundRange()

void SetSoundRange ( CSound sound,
unsigned char  range 
)

Modify the range of a given sound.

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

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

◆ SoundCclRegister()

void SoundCclRegister ( )

register ccl features

Register CCL features for sound.

◆ SoundForName()

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

Get the sound id bound to an identifier.

Maps a sound name to its id

Parameters
nameSound name.
Returns
Sound identifier for this name.

Variable Documentation

◆ DistanceSilent

int DistanceSilent

Game sound configuration.

global range control (max cut off distance for sound)

Game sound configuration.

◆ GameSounds

GameSound GameSounds

Various sounds used in game.

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.