CorsixTH engine (the C++ part)
Open source implementation of Theme Hospital
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
sound_player Class Reference

#include <th_sound.h>

Public Types

enum class  toggle_pause_result { error , paused , resumed }
 

Public Member Functions

 sound_player ()
 
 sound_player (const sound_player &)=delete
 
sound_playeroperator= (const sound_player &)=delete
 
 ~sound_player ()
 
void populate_from (sound_archive *pArchive)
 
uint32_t play (size_t iIndex, double dVolume, int loops)
 
uint32_t play_at (size_t iIndex, int iX, int iY, int loops)
 
uint32_t play_at (size_t iIndex, double dVolume, int iX, int iY, int loops)
 
toggle_pause_result toggle_pause (uint32_t handle)
 
void stop (uint32_t handle)
 
bool is_playing (uint32_t handle)
 Returns whether the sound matching the given handle is playing.
 
void set_sound_effect_volume (double dVolume)
 Sets the default volume for sound effects.
 
void set_sound_effects_enabled (bool bOn)
 
void set_camera (int iX, int iY, int iRadius)
 Sets the position of the camera for play_at calculations.
 
int reserve_channel ()
 
void release_channel (int iChannel)
 Releases a previously reserved SDL_mixer channel.
 

Static Public Member Functions

static sound_playerget_singleton ()
 

Static Public Attributes

static constexpr uint32_t null_handle = 0u
 
static constexpr int number_of_channels = 32
 

Member Enumeration Documentation

◆ toggle_pause_result

Enumerator
error 
paused 
resumed 

Constructor & Destructor Documentation

◆ sound_player() [1/2]

sound_player::sound_player ( )

◆ sound_player() [2/2]

sound_player::sound_player ( const sound_player )
delete

◆ ~sound_player()

sound_player::~sound_player ( )

Member Function Documentation

◆ get_singleton()

sound_player * sound_player::get_singleton ( )
static

◆ is_playing()

bool sound_player::is_playing ( uint32_t  handle)

Returns whether the sound matching the given handle is playing.

◆ operator=()

sound_player & sound_player::operator= ( const sound_player )
delete

◆ play()

uint32_t sound_player::play ( size_t  iIndex,
double  dVolume,
int  loops 
)

Plays the sound effect in the sound_archive with the given index.

Parameters
iIndexIndex of the sound effect to play.
dVolumeVolume to play the sound effect at, in the range 0.0 to 1.0.
loopsThe number of times to play the sound, -1 for 'practically' infinite.
Returns
The sound handle
See also
Mix_PlayChannel

◆ play_at() [1/2]

uint32_t sound_player::play_at ( size_t  iIndex,
double  dVolume,
int  iX,
int  iY,
int  loops 
)

Plays the sound effect in the sound_archive with the given index with volume attenuation based on the distance from the given position to the camera.

Parameters
iIndexIndex of the sound effect to play.
dVolumeVolume to play the sound effect at before attenuation, in the range 0.0 to 1.0.
iXX coordinate of the sound effect.
iYY coordinate of the sound effect.
loopsThe number of times to play the sound, -1 for 'practically' infinite.
Returns
The sound handle or 0 on error

◆ play_at() [2/2]

uint32_t sound_player::play_at ( size_t  iIndex,
int  iX,
int  iY,
int  loops 
)

Plays the sound effect in the sound_archive with the given index with volume attenuation based on the distance from the given position to the camera.

Parameters
iIndexIndex of the sound effect to play.
iXX coordinate of the sound effect.
iYY coordinate of the sound effect.
loopsThe number of times to play the sound, -1 for 'practically' infinite.
Returns
The sound handle or 0 on error

◆ populate_from()

void sound_player::populate_from ( sound_archive pArchive)

◆ release_channel()

void sound_player::release_channel ( int  iChannel)

Releases a previously reserved SDL_mixer channel.

◆ reserve_channel()

int sound_player::reserve_channel ( )

Reserves an SDL_mixer channel for exclusive use.

Not necessary to use in conjunction with play() or play_at(), as these methods will automatically reserve and release channels.

Returns
The reserved channel index, or -1 if no channels are available.

◆ set_camera()

void sound_player::set_camera ( int  iX,
int  iY,
int  iRadius 
)

Sets the position of the camera for play_at calculations.

◆ set_sound_effect_volume()

void sound_player::set_sound_effect_volume ( double  dVolume)

Sets the default volume for sound effects.

◆ set_sound_effects_enabled()

void sound_player::set_sound_effects_enabled ( bool  bOn)

Enables or disables sound effects. Note: Only affects sounds played via play_at(int, int, int).

◆ stop()

void sound_player::stop ( uint32_t  handle)

Stops playback on a given channel.

Parameters
handleThe sound to stop.

◆ toggle_pause()

sound_player::toggle_pause_result sound_player::toggle_pause ( uint32_t  handle)

Pause playback on a given channel if playing, or resume if paused.

Parameters
handleThe sound to toggle pause on.
Returns
The result of the toggle: paused, resumed, or error.

Member Data Documentation

◆ null_handle

constexpr uint32_t sound_player::null_handle = 0u
staticconstexpr

◆ number_of_channels

constexpr int sound_player::number_of_channels = 32
staticconstexpr

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