The Table Engine
Sound Struct Reference

Encapsulates sound management functionality using SDL_mixer. More...

#include <sound.h>

+ Collaboration diagram for Sound:

Public Member Functions

 Sound (std::string path)
 Constructor that initializes the SDL_mixer and loads sound from a specified path. More...
 
void play (int loops)
 Plays the loaded sound. More...
 
void stop ()
 Stops all sound on the channel used by this sound. More...
 
void pause ()
 Pauses all sound on the channel used by this sound. More...
 
void resume ()
 Resumes all paused sound on the channel used by this sound. More...
 
void setVolume (int volume)
 Sets the volume for the channel used by this sound. More...
 
 ~Sound ()
 Destructor that frees the loaded sound. More...
 

Public Attributes

Mix_Chunk * m_sound
 Pointer to the sound data loaded from a file. More...
 

Detailed Description

Encapsulates sound management functionality using SDL_mixer.

Sound structure provides methods to load, play, stop, pause, and resume sound effects, as well as to adjust their volume. It automatically initializes the SDL_mixer library on construction and cleans up on destruction.

Definition at line 25 of file sound.h.

Constructor & Destructor Documentation

◆ Sound()

Sound::Sound ( std::string  path)

Constructor that initializes the SDL_mixer and loads sound from a specified path.

Parameters
pathPath to the sound file.

The constructor initializes the SDL_mixer with default settings and attempts to load a sound file from the given path. It reports errors if SDL_mixer cannot initialize or the sound file cannot be loaded.

◆ ~Sound()

Sound::~Sound ( )

Destructor that frees the loaded sound.

The destructor frees the memory allocated for the sound chunk and closes the SDL_mixer to clean up resources.

Member Function Documentation

◆ pause()

void Sound::pause ( )

Pauses all sound on the channel used by this sound.

Pauses the playback of the sound by pausing the channel it is playing on.

◆ play()

void Sound::play ( int  loops)

Plays the loaded sound.

Parameters
loopsNumber of times the sound should loop; -1 for infinite looping.

This method plays the sound using SDL_mixer. The sound can loop multiple times or play indefinitely if specified.

◆ resume()

void Sound::resume ( )

Resumes all paused sound on the channel used by this sound.

Resumes the playback of the sound by resuming the paused channel it is playing on.

◆ setVolume()

void Sound::setVolume ( int  volume)

Sets the volume for the channel used by this sound.

Parameters
volumeDesired volume level (0 to 128).

This method adjusts the volume of the sound channel. The volume range is from 0 (mute) to 128 (maximum).

◆ stop()

void Sound::stop ( )

Stops all sound on the channel used by this sound.

Stops the playback of the sound by halting the channel it is playing on.

Member Data Documentation

◆ m_sound

Mix_Chunk* Sound::m_sound

Pointer to the sound data loaded from a file.

Definition at line 26 of file sound.h.


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