Engine
Raylib based game framework
Loading...
Searching...
No Matches
AudioSystem Class Reference

Handles playback of sounds and music with volume control and crossfading. More...

#include <AudioSystem.hpp>

Inheritance diagram for AudioSystem:
Collaboration diagram for AudioSystem:

Public Member Functions

void Update (const float deltaT) override
 Updates music stream and removes finished sounds.
void PlaySound (const Sound &sound, float volume=1)
 Plays a sound effect.
void StopSound (const Sound &sound)
 Stops a sound effect immediately.
void SetSoundVolume (const Sound &sound, float volume)
 Changes volume of a currently playing sound.
void PlayMusic (const Music &music, float volume=1, const bool loop=false, const float crossfadeS=0)
 Starts playing background music.
void StopMusic (const float fadeOutDuration=0)
 Stops the current music, optionally with a fade out.
bool IsMusicPlaying ()
 Checks if music is currently playing or fading in.
void PauseMusic ()
 Pauses the current music stream.
void ResumeMusic ()
 Resumes a paused music stream.
std::optional< float > GetMusicLengthS ()
 Gets the total length of the current music.
std::optional< float > GetMusicPlayedS ()
 Gets the current playback position.
void SeekMusic (const float timeS)
 Seeks to a specific time in the current music.
void SetMusicVolume (float volume)
 Sets the music volume (without affecting sound effects).
void SetMusicPitch (const float pitch)
 Sets the music pitch.
void SetMusicPan (float pan)
 Sets the music stereo pan.
void SetMusicLoop (const bool loop)
 Enables or disables looping for the current music.
void SetSFXVolume (float volume)
 Sets the volume multiplier for all sound effects.
Public Member Functions inherited from System
virtual void Draw () const
 Renders the system.

Static Public Member Functions

static void SetSoundPitch (const Sound &sound, const float pitch)
 Changes pitch of a playing sound.
static void SetSoundPan (const Sound &sound, const float pan)
 Changes stereo pan of a playing sound.
static void SetMasterVolume (float volume)
 Sets the master volume for the entire audio device.

Detailed Description

Handles playback of sounds and music with volume control and crossfading.

Member Function Documentation

◆ GetMusicLengthS()

std::optional< float > AudioSystem::GetMusicLengthS ( )

Gets the total length of the current music.

Returns
Length in seconds, or std::nullopt if no music is loaded.

◆ GetMusicPlayedS()

std::optional< float > AudioSystem::GetMusicPlayedS ( )

Gets the current playback position.

Returns
Position in seconds, or std::nullopt if no music is loaded.

◆ IsMusicPlaying()

bool AudioSystem::IsMusicPlaying ( )

Checks if music is currently playing or fading in.

Returns
True if music is active.

◆ PlayMusic()

void AudioSystem::PlayMusic ( const Music & music,
float volume = 1,
const bool loop = false,
const float crossfadeS = 0 )

Starts playing background music.

Parameters
musicThe music asset.
volumeVolume (0.0–1.0).
loopWhether to repeat the track.
crossfadeSCrossfade duration in seconds (if another music is playing).

◆ PlaySound()

void AudioSystem::PlaySound ( const Sound & sound,
float volume = 1 )

Plays a sound effect.

Parameters
soundThe sound asset.
volumePlayback volume (0.0–1.0), scaled by global SFX volume.

◆ SeekMusic()

void AudioSystem::SeekMusic ( const float timeS)

Seeks to a specific time in the current music.

Parameters
timeSTarget time in seconds.

◆ SetMasterVolume()

void AudioSystem::SetMasterVolume ( float volume)
static

Sets the master volume for the entire audio device.

Parameters
volume0.0–1.0.

◆ SetMusicLoop()

void AudioSystem::SetMusicLoop ( const bool loop)

Enables or disables looping for the current music.

Parameters
loopTrue to loop.

◆ SetMusicPan()

void AudioSystem::SetMusicPan ( float pan)

Sets the music stereo pan.

Parameters
pan-1.0 left … 1.0 right.

◆ SetMusicPitch()

void AudioSystem::SetMusicPitch ( const float pitch)

Sets the music pitch.

Parameters
pitchMultiplier (1.0 = original).

◆ SetMusicVolume()

void AudioSystem::SetMusicVolume ( float volume)

Sets the music volume (without affecting sound effects).

Parameters
volume0.0–1.0.

◆ SetSFXVolume()

void AudioSystem::SetSFXVolume ( float volume)

Sets the volume multiplier for all sound effects.

Parameters
volume0.0–1.0.

◆ SetSoundPan()

void AudioSystem::SetSoundPan ( const Sound & sound,
const float pan )
static

Changes stereo pan of a playing sound.

Parameters
soundThe sound asset.
pan-1.0 = left, 0.0 = center, 1.0 = right.

◆ SetSoundPitch()

void AudioSystem::SetSoundPitch ( const Sound & sound,
const float pitch )
static

Changes pitch of a playing sound.

Parameters
soundThe sound asset.
pitchPitch multiplier (1.0 = original).

◆ SetSoundVolume()

void AudioSystem::SetSoundVolume ( const Sound & sound,
float volume )

Changes volume of a currently playing sound.

Parameters
soundThe sound asset.
volumeNew volume (0.0–1.0).

◆ StopMusic()

void AudioSystem::StopMusic ( const float fadeOutDuration = 0)

Stops the current music, optionally with a fade out.

Parameters
fadeOutDurationSeconds to fade out before stopping (0 = immediate).

◆ StopSound()

void AudioSystem::StopSound ( const Sound & sound)

Stops a sound effect immediately.

Parameters
soundThe sound asset.

◆ Update()

void AudioSystem::Update ( const float deltaT)
overridevirtual

Updates music stream and removes finished sounds.

Parameters
deltaTUnused.

Implements System.


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