Audio

Handles audio output for the game through a high level interface. More...


Files

file  audio.c
 Audio output code.
file  audio.h
 Interface to audio output.

Defines

#define DistSq(p1, p2)
 Computes the square of the distance between two players.
#define MAX_SQ_DIST   (27500<<2)
 The maximum squared distance that can be heard by the player.
#define PlayLocalTankMove()   PlaySound(SND_MOVE, SND_CH_TANK, -1)
 Plays the sound of the local player's tank moving.
#define PlayTankIdle()   PlaySound(SND_IDLE, SND_CH_TANK, -1)
 Plays the sound of the local player's tank idling.
#define PlayTankKilled(distsq)   PlaySoundDist(SND_DEATH, -1, distsq, 0)
 Plays the sound of the destruction of a tank other than the local player's tank.
#define PlayTankMove(distsq)   PlaySoundDist(SND_MOVE, SND_CH_TANK, distsq, -1)
 Plays the sound of a tank, other than the local player's tank, moving.
#define PlayTankShoot(distsq)   PlaySoundDist(SND_SHOOT, -1, distsq, 0)
 Plays the sound of a tank, other than the local player's tank, shooting.

Enumerations

enum  SND_CHANNEL { SND_CH_LOCALSHOOT, SND_CH_TANK, SND_CH_RESERVE, SND_CH_MAX = 8 }
 The audio channels that are mixed together to produce the final output. More...
enum  SND_SOUND {
  SND_IDLE, SND_MOVE, SND_SHOOT, SND_DEATH,
  SND_MAX
}
 The available sounds. More...

Functions

Bool InitAudio ()
 Prepares for auido output by requesting output resources and loading in the game sounds.
void PauseSound (int chan)
 Pauses the sound on a specific mixing channel.
Bool PlayLocalDeath ()
 Stops all sounds and plays the sound of the local player's tank being destroyed.
Bool PlaySound (int snd, int chan, int count)
 Plays a sound; intended to play sounds caused by actions taken by the local player.
Bool PlaySoundDist (int snd, int chan, int distsq, int count)
 Plays a sound with its volume attenuated according to its distance from the local player.
void StopAllSounds ()
 Halts all playing sounds on all channels.
void UninitAudio ()
 Stops all sounds and frees all resources needed for audio output.

Detailed Description

Handles audio output for the game through a high level interface.

The sound setup is intentionally simple because I haven't found much motiviation for this part of the project, but the game does need sound.

SDL_mixer is used for the sound output. Several of SDL_mixer's channels are used to easily support several independent sounds that can play simultaneously. Sound volume drops linearly with distance such that a tank 212 units distant (just off-screen at initial window size) produces sound at half the volumne of something 0 units away.

The audio functions are not critical to gameplay, so if InitAudio() fails, the game will continue. All other audio functions will correctly do nothing if called when audio is not initialized.


Define Documentation

#define DistSq ( p1,
p2   ) 

Value:

((int)(((p1)->x - (p2)->x) >> 8) * (int)(((p1)->x - (p2)->x) >> 8) +  \
     (int)(((p1)->y - (p2)->y) >> 8) * (int)(((p1)->y - (p2)->y) >> 8))
Computes the square of the distance between two players.

Parameters:
p1 A pointer to a Player.
p2 A pointer to another Player.
Returns:
An int with the square of the distance.
Author:
Jeff Jackowski

Definition at line 200 of file audio.h.

Referenced by ReadPlayer().

#define MAX_SQ_DIST   (27500<<2)

The maximum squared distance that can be heard by the player.

The value was selected from what seemed to work well during trials.

Definition at line 107 of file audio.h.

Referenced by ReadPlayer().

 
#define PlayLocalTankMove (  )     PlaySound(SND_MOVE, SND_CH_TANK, -1)

Plays the sound of the local player's tank moving.

Returns:
True on success, false on failure.
Author:
Jeff Jackowski

Definition at line 165 of file audio.h.

 
#define PlayTankIdle (  )     PlaySound(SND_IDLE, SND_CH_TANK, -1)

Plays the sound of the local player's tank idling.

Returns:
True on success, false on failure.
Author:
Jeff Jackowski

Definition at line 172 of file audio.h.

#define PlayTankKilled ( distsq   )     PlaySoundDist(SND_DEATH, -1, distsq, 0)

Plays the sound of the destruction of a tank other than the local player's tank.

Parameters:
distsq The square of the distance from the player's tank to the source of the sound.
Returns:
True on success, false on failure.
Author:
Jeff Jackowski

Definition at line 191 of file audio.h.

Referenced by ReadPlayer().

#define PlayTankMove ( distsq   )     PlaySoundDist(SND_MOVE, SND_CH_TANK, distsq, -1)

Plays the sound of a tank, other than the local player's tank, moving.

Parameters:
distsq The square of the distance from the player's tank to the source of the sound.
Returns:
True on success, false on failure.
Author:
Jeff Jackowski

Definition at line 158 of file audio.h.

#define PlayTankShoot ( distsq   )     PlaySoundDist(SND_SHOOT, -1, distsq, 0)

Plays the sound of a tank, other than the local player's tank, shooting.

Parameters:
distsq The square of the distance from the player's tank to the source of the sound.
Returns:
True on success, false on failure.
Author:
Jeff Jackowski

Definition at line 181 of file audio.h.

Referenced by ReadPlayer().


Enumeration Type Documentation

enum SND_CHANNEL

The audio channels that are mixed together to produce the final output.

Enumerator:
SND_CH_LOCALSHOOT  This channel plays the local player's shooting sound.
SND_CH_TANK  A channel for the movement sound of tanks in the game.

The local player is moving, the sound will be SND_SOUND::SND_MOVE at full volumne. If not, and another tank close by is moving, the sound will be SND_SOUND::SND_MOVE attenuated according to distance. Otherwise, the sound will be SND_SOUND::SND_IDLE.

SND_CH_RESERVE  The number of reserved channels.
SND_CH_MAX  The total number of mixing channels.

The additional channels used beyond the reservered channels play the sounds of shots and kills of tanks other than the local player.

Definition at line 78 of file audio.h.

enum SND_SOUND

The available sounds.

Enumerator:
SND_IDLE  The sound of a tank's engine idling.
SND_MOVE  The sound of a tank moving forward.
SND_SHOOT  The sound of a tank shooting its cannon.
SND_DEATH  The sound of a tank being destroyed.
SND_MAX 

Definition at line 55 of file audio.h.


Function Documentation

Bool InitAudio (  ) 

Prepares for auido output by requesting output resources and loading in the game sounds.

Returns:
True on success, false on failure. Failure can be caused by lack of available sound hardware or inability to load any sounds. Failure to load some but not all sounds is not considered an error.

Referenced by main().

void PauseSound ( int  chan  ) 

Pauses the sound on a specific mixing channel.

Intended to pause the sound of tanks moving in the SND_CHANNEL::SND_CH_TANK channel.

Author:
Jeff Jackowski

Bool PlayLocalDeath (  ) 

Stops all sounds and plays the sound of the local player's tank being destroyed.

Returns:
True on success, false on failure. Failure can be caused by lack of availble channels or an inability to load the requested sound (error during InitAudio()).
Author:
Jeff Jackowski

Referenced by ReadPlayer().

Bool PlaySound ( int  snd,
int  chan,
int  count 
)

Plays a sound; intended to play sounds caused by actions taken by the local player.

Parameters:
snd The sound from the SND_SOUND enum to play.
chan The channel on which to play the sound, from the SND_CHANNEL enum. A specific channel must be specified; -1 is not accepted.
count The number of times to repeat the sound, or -1 to loop forever.
Returns:
True on success, false on failure. Failure can be caused by lack of availble channels or an inability to load the requested sound (error during InitAudio()).
Author:
Jeff Jackowski

Referenced by HandleInput().

Bool PlaySoundDist ( int  snd,
int  chan,
int  distsq,
int  count 
)

Plays a sound with its volume attenuated according to its distance from the local player.

This should not be used for sounds corresponding to the local player.

Parameters:
snd The sound from the SND_SOUND enum to play.
chan The channel on which to play the sound, from the SND_CHANNEL enum, or -1 to select a free channel.
distsq The square of the distance from the player's tank to the source of the sound.
count The number of times to repeat the sound, or -1 to loop forever. If -1, then the specific channel must be specified; chan must not be -1.
Returns:
True on success, false on failure. Failure can be caused by lack of availble channels or an inability to load the requested sound (error during InitAudio()).
Author:
Jeff Jackowski

void StopAllSounds (  ) 

Halts all playing sounds on all channels.

Author:
Jeff Jackowski

Referenced by GameUninit().

void UninitAudio (  ) 

Stops all sounds and frees all resources needed for audio output.

Author:
Jeff Jackowski

Referenced by main().


Generated on Mon May 28 04:41:41 2007 for Retro Tank Super Attack by  doxygen 1.5.2