-
Notifications
You must be signed in to change notification settings - Fork 1
π¦ Audio
The Audio module provides a simple system to manage and play sounds within an application. It allows you to organize sounds into channels, control playback, volume, pitch, looping, and other properties, all in a structured and easy-to-use manner.
The module is built around two main classes: Audio and AudioChannel.
Audio is a singleton that manages multiple AudioChannel instances. Each AudioChannel holds a collection of sounds, represented by sf::Sound objects from the SFML library, stored in a dictionary keyed by their name. The module handles loading, playing, pausing, stopping, and adjusting sound properties such as attenuation, pitch, volume, and whether the sound is relative to the listener.
void Add(String name, String file)Adds a new sound to the channel.
Parameters:
-
name: Unique identifier for the sound. -
file: Path to the sound file to load.
void Delete(String name)Removes a sound from the channel.
Parameters:
-
name: Name of the sound to remove.
void Play(String name)Plays a sound.
Parameters:
-
name: Name of the sound to play.
void Pause(String name)Pauses a sound.
Parameters:
-
name: Name of the sound to pause.
void Stop(String name)Stops a sound completely, reseting the soundβs position to the start.
Parameters:
-
name: Name of the sound to stop.
void SetAttenuation(String name, float attenuation)Sets how sound diminishes over distance.
Parameters:
-
name: Name of the sound. -
attenuation: Attenuation factor (SFML standard).
void SetLoop(String name, bool flag = true)Enables or disables looping of a sound.
Parameters:
-
name: Name of the sound. -
flag: True to loop, false to play once.
void SetPitch(String name, float pitch)Adjusts the pitch of the sound.
Parameters:
-
name: Name of the sound. -
pitch: Pitch multiplier (1.0 is normal).
void SetRelativeToListener(String name, bool flag = true)Determines if the soundβs position is relative to the listener.
Parameters:
-
name: Name of the sound. -
flag: True if relative to listener, false otherwise.
SoundPtr GetSound(String name)Retrieves the sound object.
Parameters:
-
name: Name of the sound.
__ Returns:__ Shared pointer to the sf::Sound object or nullptr if not found.
bool IsPlaying(String name)
bool IsPaused(String name)
bool IsStopped(String name)Checks the status of a sound.
Parameters:
-
name: Name of the sound.
Returns: True if the sound is in the corresponding state.
float GetAttenuation(String name)
float GetPitch(String name)
bool IsLooping(String name)
bool IsRelativeToListener(String name)Retrieves sound properties.
Parameters:
-
name: Name of the sound.
Returns: Corresponding value or default if the sound does not exist.
float GetVolume()
void SetVolume(float volume)Gets or sets the volume for all sounds in the channel.
Parameters (SetVolume):
-
volume: Desired volume level (β₯ 0).
bool IsPlaying()Checks if any sound in the channel is currently playing.
Returns: True if at least one sound is playing.
void Clear()Removes all sounds from the channel.
void AddChannel(String name)Adds a new audio channel to the system.
Parameters:
-
name: Unique channel identifier.
void DeleteChannel(String name)Removes a channel.
Parameters:
-
name: Name of the channel to remove.
AudioChannelPtr GetChannel(String name)Retrieves a channel object.
Parameters:
-
name: Name of the channel.
Returns: Shared pointer to the AudioChannel or nullptr if not found.