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

       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.cpp File Reference

The sound. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include "SDL.h"
#include "sound.h"
#include "video.h"
#include "unitsound.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
#include "sound_server.h"
#include "missile.h"
#include "map.h"
#include "ui.h"
#include "widgets.h"

Go to the source code of this file.

Classes

struct  SelectionHandling

Functions

static CSampleSimpleChooseSample (const CSound *sound)
static CSampleChooseSample (CSound *sound, bool selection, Origin &source)
static CSoundChooseUnitVoiceSound (const CUnit *unit, UnitVoiceGroup voice)
static unsigned char VolumeForDistance (unsigned short d, unsigned char range)
static unsigned char CalculateVolume (bool isVolume, int power, unsigned char range)
static char CalculateStereo (const CUnit *unit)
void PlayUnitSound (const CUnit *unit, UnitVoiceGroup voice)
 < 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.
static void PlaySoundFileCallback (int channel)
int PlayFile (const std::string &name, LuaActionListener *listener)
 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)

Variables

GameSound GameSounds
 Game sound configuration.
SelectionHandling SelectionHandler
static int ViewPointOffset
 Distance to Volume Mapping.
int DistanceSilent
 silent distance
static std::map< int,
LuaActionListener * > 
ChannelMap


Detailed Description

The sound.

Definition in file sound.cpp.


Function Documentation

static char CalculateStereo ( const CUnit unit  )  [static]

Calculate the stereo value for a unit

Definition at line 256 of file sound.cpp.

References CUnit::IX, CViewport::MapWidth, CViewport::MapX, CUserInterface::SelectedViewport, TileSizeX, CUnitType::TileWidth, CUnit::Type, UI, and CUnit::X.

Referenced by PlayUnitSound().

static unsigned char CalculateVolume ( bool  isVolume,
int  power,
unsigned char  range 
) [static]

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

Definition at line 238 of file sound.cpp.

References MaxVolume, and VolumeForDistance().

Referenced by PlayGameSound(), PlayMissileSound(), and PlayUnitSound().

static CSample* ChooseSample ( CSound sound,
bool  selection,
Origin source 
) [static]

static CSound* ChooseUnitVoiceSound ( const CUnit unit,
UnitVoiceGroup  voice 
) [static]

void InitSoundClient ( void   ) 

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().

static void PlaySoundFileCallback ( int  channel  )  [static]

Callback for PlaySoundFile

Definition at line 368 of file sound.cpp.

References LuaActionListener::action(), ChannelMap, and GetChannelSample().

Referenced by PlayFile().

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

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().

static CSample* SimpleChooseSample ( const CSound sound  )  [static]

"Randomly" choose a sample from a sound group.

Definition at line 101 of file sound.cpp.

References FrameCounter, CSound::Number, ONE_SOUND, CSound::OneGroup, CSound::OneSound, and CSound::Sound.

Referenced by ChooseSample().

static unsigned char VolumeForDistance ( unsigned short  d,
unsigned char  range 
) [static]

Compute a suitable volume for something taking place at a given distance from the current view point.

Parameters:
d distance
range range
Returns:
volume for given distance (0..??)

Definition at line 209 of file sound.cpp.

References DistanceSilent, INFINITE_SOUND_RANGE, MAX_SOUND_RANGE, MaxVolume, and ViewPointOffset.

Referenced by CalculateVolume().


Variable Documentation

std::map<int, LuaActionListener *> ChannelMap [static]

Definition at line 363 of file sound.cpp.

Referenced by PlayFile(), and PlaySoundFileCallback().

silent distance

Definition at line 92 of file sound.cpp.

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

Initial value:

{
    SoundConfig("placement error"),
    SoundConfig("placement success"),
    SoundConfig("click"),
    SoundConfig("transport docking"),
    SoundConfig("building construction"),
    SoundConfig("basic human voices work complete"),
    SoundConfig("rescue (human) UNUSED"),
}
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().

Definition at line 89 of file sound.cpp.

int ViewPointOffset [static]

Distance to Volume Mapping.

Definition at line 91 of file sound.cpp.

Referenced by InitSoundClient(), and VolumeForDistance().


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