The Table Engine
|
Encapsulates sound management functionality using SDL_mixer. More...
#include <sound.h>
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... | |
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.
Sound::Sound | ( | std::string | path | ) |
Constructor that initializes the SDL_mixer and loads sound from a specified path.
path | Path 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 | ( | ) |
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.
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.
void Sound::play | ( | int | loops | ) |
Plays the loaded sound.
loops | Number 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.
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.
void Sound::setVolume | ( | int | volume | ) |
Sets the volume for the channel used by this sound.
volume | Desired volume level (0 to 128). |
This method adjusts the volume of the sound channel. The volume range is from 0 (mute) to 128 (maximum).
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.
Mix_Chunk* Sound::m_sound |