Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
SoundEngine Class Reference

The wrapper around SDL_Mixer that plays sounds ingame. More...

#include <sound.h>

Public Member Functions

void clear_sound ()
 Shuts down sound system.
 
void preloadsound (int n)
 Loads the approriate sound file at the given index.
 
void preloadmapsounds ()
 Loads the sounds for every element in the map sounds vector.
 
int playsound (int n, const vec *loc=nullptr, extentity *ent=nullptr, int flags=0, int loops=0, int fade=0, int chanid=-1, int radius=0, int expire=-1)
 Plays a sound with the given attributes.
 
bool stopsound (int n, int chanid, int fade)
 Stops playing a sound of index n in the specificied channel.
 
void stopsounds ()
 Immediately kills all active sounds.
 
void updatesounds ()
 Restarts and updates all sound indices.
 
int playsoundname (const char *s, const vec *loc, int vol, int flags, int loops, int fade, int chanid, int radius, int expire)
 Plays a sound with the given attributes.
 
void initsound ()
 Starts SDL_Mixer and initializes startup sound channels.
 
void startmusic (char *name, char *cmd)
 Starts a nonpositional music track.
 
void resetsound ()
 Resets the sound subsystem.
 
void setstereo (const int *const on)
 Sets whether stereo audio is enabled.
 
int getstereo ()
 Returns whether stereo or mono is enabled.
 
void setmaxradius (const int *const dist)
 Sets the maximum radius to play sounds from.
 
int getmaxradius ()
 Returns the maximum sound play radius.
 
void setsoundchans (const int *const val)
 Sets the number of sound channels to use.
 
int getsoundchans ()
 Returns the number of sound channels in use.
 
void setsoundvol (const int *const vol)
 Sets the map sound volume.
 
int getsoundvol ()
 Returns the current sound volume.
 
void setmusicvol (const int *const musicvol)
 Sets the music sound volume.
 
int getmusicvol ()
 Returns the current music volume.
 
void setaudiodriver (char *f)
 Sends a list of audio subsystems for SDL to bind to.
 
void setsound (const int *const on)
 Sets whether the sound engine is enabled.
 
int getsound ()
 Returns whether sound is on.
 
void registersound (char *name, int *vol)
 Adds a sound to the sound list at a given volume.
 
void mapsound (char *name, int *vol, int *maxuses)
 Adds a sound to the list of map sounds.
 
void altsound (char *name, int *vol)
 Adds an alternative game sound.
 
void altmapsound (char *name, int *vol)
 Adds an alternative map sound.
 
void numsounds ()
 Returns to the console the number of game sounds loaded.
 
void nummapsounds ()
 Returns to the console the number of map sounds loaded.
 
void soundreset ()
 Resets the loaded game sounds.
 
void mapsoundreset ()
 Resets the loaded map sounds.
 

Detailed Description

The wrapper around SDL_Mixer that plays sounds ingame.

This class stores and plays sounds on command into either positionally (as a point in the world) or nonpositionally (such as background music).

Member Function Documentation

◆ altmapsound()

void SoundEngine::altmapsound ( char * name,
int * vol )

Adds an alternative map sound.

Parameters
thename of the sound to add
volthe volume of the sound (0..255)

◆ altsound()

void SoundEngine::altsound ( char * name,
int * vol )

Adds an alternative game sound.

Parameters
thename of the sound to add
volthe volume of the sound (0..255)

◆ clear_sound()

void SoundEngine::clear_sound ( )

Shuts down sound system.

Stops playing any active music, cleans up game and map sound vectors, and shuts down SDL_Mixer.

◆ getmaxradius()

int SoundEngine::getmaxradius ( )

Returns the maximum sound play radius.

The distance is in cube units ( =12.5cm).

Returns
the maximum distance at which sounds will be played

◆ getmusicvol()

int SoundEngine::getmusicvol ( )

Returns the current music volume.

Returns
the current volume for music (0..255)

◆ getsound()

int SoundEngine::getsound ( )

Returns whether sound is on.

Returns
1 if sound is on, 0 otherwise

◆ getsoundchans()

int SoundEngine::getsoundchans ( )

Returns the number of sound channels in use.

Returns
the number of sound channels in use (1..128)

◆ getsoundvol()

int SoundEngine::getsoundvol ( )

Returns the current sound volume.

Returns
the current volume for map sounds (0..255)

◆ getstereo()

int SoundEngine::getstereo ( )

Returns whether stereo or mono is enabled.

The return is in CubeScript friendly int form.

Returns
1 if stereo enabled, 0 if mono enabled

◆ initsound()

void SoundEngine::initsound ( )

Starts SDL_Mixer and initializes startup sound channels.

Fails and disables sound output if SDL is v2.0.6.

◆ mapsound()

void SoundEngine::mapsound ( char * name,
int * vol,
int * maxuses )

Adds a sound to the list of map sounds.

Parameters
namethe path to the sound
volthe volume of the sound (0..255)
maxusesthe number of uses before the sound won't play

◆ mapsoundreset()

void SoundEngine::mapsoundreset ( )

Resets the loaded map sounds.

This clears the list of map environment sounds loaded into the sound engine.

◆ nummapsounds()

void SoundEngine::nummapsounds ( )

Returns to the console the number of map sounds loaded.

Returns
(to console) the number of map sounds

◆ numsounds()

void SoundEngine::numsounds ( )

Returns to the console the number of game sounds loaded.

Returns
(to console) the number of game sounds

◆ playsound()

int SoundEngine::playsound ( int n,
const vec * loc = nullptr,
extentity * ent = nullptr,
int flags = 0,
int loops = 0,
int fade = 0,
int chanid = -1,
int radius = 0,
int expire = -1 )

Plays a sound with the given attributes.

Parameters
nindex of the sound to play
locworld location to play at
ententity to associate with (overwrites location)
flagsmusic option flags
loopsnumber of times to loop
fadems to fade in over
chanidmusic channel index to use
radiusdistance over which sound is audible (in size 0 cubes)
expiremaximum time before the sound stops playing

◆ playsoundname()

int SoundEngine::playsoundname ( const char * s,
const vec * loc,
int vol,
int flags,
int loops,
int fade,
int chanid,
int radius,
int expire )

Plays a sound with the given attributes.

Parameters
sname of the sound to play
locworld location to play at
ententity to associate with (overwrites location)
flagsmusic option flags
loopsnumber of times to loop
fadems to fade in over
chanidmusic channel index to use
radiusdistance over which sound is audible (in size 0 cubes)
expiremaximum time before the sound stops playing

◆ preloadmapsounds()

void SoundEngine::preloadmapsounds ( )

Loads the sounds for every element in the map sounds vector.

Loads the related sound file for every valid map sound index (map entity sounds).

◆ preloadsound()

void SoundEngine::preloadsound ( int n)

Loads the approriate sound file at the given index.

Fails silently if index is invalid.

Parameters
nthe sound index to use

◆ registersound()

void SoundEngine::registersound ( char * name,
int * vol )

Adds a sound to the sound list at a given volume.

Parameters
namethe path to the sound
volthe volume of the sound (0..255)

◆ setaudiodriver()

void SoundEngine::setaudiodriver ( char * f)

Sends a list of audio subsystems for SDL to bind to.

By default, the standard Linux and Windows audio systems are set.

Parameters
fa list of space-separated names for SDL to attempt to bind

◆ setmaxradius()

void SoundEngine::setmaxradius ( const int *const dist)

Sets the maximum radius to play sounds from.

The distance is in cube units ( =12.5cm).

Parameters
distthe distance to render from

◆ setmusicvol()

void SoundEngine::setmusicvol ( const int *const musicvol)

Sets the music sound volume.

Bounds limited to 0..255.

Parameters
volthe volume level for music tracks

◆ setsound()

void SoundEngine::setsound ( const int *const on)

Sets whether the sound engine is enabled.

Parameters
onwhether sound is enabled or not

◆ setsoundchans()

void SoundEngine::setsoundchans ( const int *const val)

Sets the number of sound channels to use.

Default value is 32; bounds limited to 1..128.

Parameters
valthe number of channels to use

◆ setsoundvol()

void SoundEngine::setsoundvol ( const int *const vol)

Sets the map sound volume.

Bounds limited to 0..255.

Parameters
volthe volume level for map sounds

◆ setstereo()

void SoundEngine::setstereo ( const int *const on)

Sets whether stereo audio is enabled.

Parameters
onif true, enables stereo; if false, disables it

◆ soundreset()

void SoundEngine::soundreset ( )

Resets the loaded game sounds.

This clears the list of game (e.g. hud weapon) sounds loaded into the sound engine.

◆ startmusic()

void SoundEngine::startmusic ( char * name,
char * cmd )

Starts a nonpositional music track.

Parameters
name(inc. path) of the track to play
cmdthe command to run (in CubeScript) at the end of the track

◆ stopsound()

bool SoundEngine::stopsound ( int n,
int chanid,
int fade )

Stops playing a sound of index n in the specificied channel.

Parameters
nthe sound index to stop playing
chanidthe channel id to use
fademilliseconds to spend fading out the sound

◆ stopsounds()

void SoundEngine::stopsounds ( )

Immediately kills all active sounds.

Halts all sound channels in use and frees them.

◆ updatesounds()

void SoundEngine::updatesounds ( )

Restarts and updates all sound indices.

Pauses, reloads, and resumes playback of all active sounds. Does not play sounds if on the main menu.


The documentation for this class was generated from the following file: