Practical Tools for Simple Design
Loading...
Searching...
No Matches
Util::SFX Class Reference

Class for handling sound effects. More...

#include <SFX.hpp>

Public Member Functions

 SFX (const std::string &path)
 Constructor that initializes the SFX object and loads the sound effect from the specified file path. More...
 
 SFX (const SFX &)=delete
 Deleted copy constructor to prevent copying of SFX objects.
 
SFXoperator= (const SFX &)=delete
 Deleted copy assignment operator to prevent copying of SFX objects.
 
int GetVolume () const
 Retrieves the current volume of the sound effect. More...
 
void SetVolume (int volume)
 Sets the volume of the background music. More...
 
void LoadMedia (const std::string &path)
 Loads the sound effect from the specified file path. More...
 
void VolumeUp (int step=1)
 Increases the volume of the sound effect by one. More...
 
void VolumeDown (int step=1)
 Decreases the volume of the sound effect by one. More...
 
void Play (int loop=0, int duration=-1)
 Plays the sound effect. More...
 
void FadeIn (unsigned int tick, int oop=-1, unsigned int duration=-1)
 Fades in the sound effect gradually. More...
 

Detailed Description

Class for handling sound effects.

See also
One should use Util::BGM for long audio files since it loads audio from disk instead of memory. (https://wiki.libsdl.org/SDL2_mixer/Mix_LoadMUS#remarks)

Constructor & Destructor Documentation

◆ SFX()

Util::SFX::SFX ( const std::string &  path)
explicit

Constructor that initializes the SFX object and loads the sound effect from the specified file path.

Parameters
pathThe file path of the sound effect to be loaded.

Member Function Documentation

◆ FadeIn()

void Util::SFX::FadeIn ( unsigned int  tick,
int  oop = -1,
unsigned int  duration = -1 
)

Fades in the sound effect gradually.

Parameters
tickThe duration of the fade-in effect, in milliseconds.
loopThe number of times the sound effect will loop after the fade-in is complete.
A value of -1 means it will loop indefinitely.
durationThe duration of the sound effect in milliseconds.
A value of -1 means it will play the entire sound effect.

◆ GetVolume()

int Util::SFX::GetVolume ( ) const

Retrieves the current volume of the sound effect.

Returns
The current volume of the sound effect.

◆ LoadMedia()

void Util::SFX::LoadMedia ( const std::string &  path)

Loads the sound effect from the specified file path.

Parameters
pathThe file path of the sound effect to be loaded.

◆ Play()

void Util::SFX::Play ( int  loop = 0,
int  duration = -1 
)

Plays the sound effect.

Parameters
loopThe number of times the sound effect will loop.
A value of 0 means it will play once (no looping).
durationThe duration of the sound effect in milliseconds.
A value of -1 means it will play the entire sound effect.

◆ SetVolume()

void Util::SFX::SetVolume ( int  volume)

Sets the volume of the background music.

Parameters
volumeThe desired volume level for the background music. The valid range is [0, 128].
A value of 0 mutes the music, and a value of 128 sets the maximum volume.

◆ VolumeDown()

void Util::SFX::VolumeDown ( int  step = 1)

Decreases the volume of the sound effect by one.

Parameters
stepThe amount to decrease the volume by.

◆ VolumeUp()

void Util::SFX::VolumeUp ( int  step = 1)

Increases the volume of the sound effect by one.

Parameters
stepThe amount to increase the volume by.

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