Skip to content

πŸ“¦ Audio

Ekrol34 edited this page Nov 25, 2025 · 1 revision

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.

Behaviour

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.

Methods

Add

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.

Delete

void Delete(String name)

Removes a sound from the channel.

Parameters:

  • name: Name of the sound to remove.

Play

void Play(String name)

Plays a sound.

Parameters:

  • name: Name of the sound to play.

Pause

void Pause(String name)

Pauses a sound.

Parameters:

  • name: Name of the sound to pause.

Stop

void Stop(String name)

Stops a sound completely, reseting the sound’s position to the start.

Parameters:

  • name: Name of the sound to stop.

SetAttenuation

void SetAttenuation(String name, float attenuation)

Sets how sound diminishes over distance.

Parameters:

  • name: Name of the sound.

  • attenuation: Attenuation factor (SFML standard).

SetLoop

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.

SetPitch

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).

SetRelativeToListener

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.

GetSound

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.

IsPlaying / IsPaused / IsStopped

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.

GetAttenuation / GetPitch / IsLooping / IsRelativeToListener

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.

GetVolume / SetVolume

float GetVolume()
void SetVolume(float volume)

Gets or sets the volume for all sounds in the channel.

Parameters (SetVolume):

  • volume: Desired volume level (β‰₯ 0).

IsPlaying

bool IsPlaying()

Checks if any sound in the channel is currently playing.

Returns: True if at least one sound is playing.

Clear

void Clear()

Removes all sounds from the channel.

AddChannel

void AddChannel(String name)

Adds a new audio channel to the system.

Parameters:

  • name: Unique channel identifier.

DeleteChannel

void DeleteChannel(String name)

Removes a channel.

Parameters:

  • name: Name of the channel to remove.

GetChannel

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.

Clone this wiki locally