Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::Audio Class Reference

Manages audio playback via SDL3_mixer. More...

#include <flint/audio/audio.h>

+ Collaboration diagram for Flint::Audio:

Public Member Functions

FLINT_API bool init ()
 Initialize the audio subsystem and open the default playback device.
 
FLINT_API void cleanup ()
 Release all audio resources and shut down SDL_mixer.
 
FLINT_API int loadSound (const void *data, const size_t size)
 Load a sound from an in-memory audio file.
 
FLINT_API bool playSound (int id, bool loop=false, float volume=1.0f, float pitch=1.0f)
 Begin playback of a previously loaded sound.
 
FLINT_API void pauseSound (int id)
 Pause playback of the given sound.
 
FLINT_API void resumeSound (int id)
 Resume a paused sound.
 
FLINT_API bool isPaused (const int id) const
 Query whether a sound is currently paused.
 
FLINT_API void stopSound (int id)
 Stop playback of a sound immediately.
 
FLINT_API void stopAllSounds ()
 Stop all currently playing sounds immediately.
 
FLINT_API void setVolume (int id, float volume)
 Set the playback volume for a specific sound.
 
FLINT_API void setPitch (int id, float pitch)
 Set the playback pitch (frequency ratio) for a specific sound.
 
FLINT_API void setLooping (int id, bool loop)
 Change the looping state of a currently playing sound.
 
FLINT_API bool isPlaying (int id) const
 Query whether a sound is currently playing (not stopped or finished).
 
FLINT_API void pauseAll () const
 Pause all tracks on the mixer device.
 
FLINT_API void resumeAll () const
 Resume all tracks on the mixer device.
 
FLINT_API void setMasterVolume (float volume) const
 Set the master output volume for the entire mixer.
 

Detailed Description

Manages audio playback via SDL3_mixer.

Wraps an SDL_mixer device along with per-sound track and audio-data lifetime management. Sounds are identified by integer IDs returned from loadSound(). The subsystem must be initialized with init() before any other method is called.

Definition at line 20 of file audio.h.

Constructor & Destructor Documentation

◆ ~Audio()

Flint::Audio::~Audio ( )
inline

Definition at line 24 of file audio.h.

Member Function Documentation

◆ cleanup()

FLINT_API void Flint::Audio::cleanup ( )

Release all audio resources and shut down SDL_mixer.

Destroys every loaded track and audio buffer, then tears down the mixer device.

◆ init()

FLINT_API bool Flint::Audio::init ( )

Initialize the audio subsystem and open the default playback device.

Returns
true on success, false if SDL_mixer could not be initialized or the playback device could not be opened.

◆ isPaused()

FLINT_API bool Flint::Audio::isPaused ( const int id) const

Query whether a sound is currently paused.

Parameters
idSound ID to query.
Returns
true if the sound is currently paused.

◆ isPlaying()

FLINT_API bool Flint::Audio::isPlaying ( int id) const

Query whether a sound is currently playing (not stopped or finished).

Parameters
idSound ID to query.
Returns
true if the sound's track is actively playing.

◆ loadSound()

FLINT_API int Flint::Audio::loadSound ( const void * data,
const size_t size )

Load a sound from an in-memory audio file.

Parameters
dataPointer to the raw audio file bytes.
sizeNumber of bytes in data.
Returns
A positive integer ID that identifies the loaded sound, or -1 on failure.

◆ pauseSound()

FLINT_API void Flint::Audio::pauseSound ( int id)

Pause playback of the given sound.

The sound can be resumed with resumeSound().

Parameters
idSound ID to pause.

◆ playSound()

FLINT_API bool Flint::Audio::playSound ( int id,
bool loop = false,
float volume = 1.0f,
float pitch = 1.0f )

Begin playback of a previously loaded sound.

Parameters
idSound ID returned by loadSound().
loopIf true the sound loops indefinitely until stopped.
volumeLinear gain in [0, 1] (1.0 = original level).
pitchFrequency ratio (1.0 = original pitch).
Returns
true if playback was started successfully, false otherwise.

◆ resumeSound()

FLINT_API void Flint::Audio::resumeSound ( int id)

Resume a paused sound.

Parameters
idSound ID to resume.

◆ setLooping()

FLINT_API void Flint::Audio::setLooping ( int id,
bool loop )

Change the looping state of a currently playing sound.

If the sound is playing, it is restarted with the new loop flag while preserving the current gain and pitch settings.

Parameters
idSound ID to modify.
looptrue to loop indefinitely, false to play once.

◆ setMasterVolume()

FLINT_API void Flint::Audio::setMasterVolume ( float volume) const

Set the master output volume for the entire mixer.

Parameters
volumeLinear gain in [0, 1] applied to all tracks combined.

◆ setPitch()

FLINT_API void Flint::Audio::setPitch ( int id,
float pitch )

Set the playback pitch (frequency ratio) for a specific sound.

Parameters
idSound ID to adjust.
pitchFrequency ratio (1.0 = original pitch).

◆ setVolume()

FLINT_API void Flint::Audio::setVolume ( int id,
float volume )

Set the playback volume for a specific sound.

Parameters
idSound ID to adjust.
volumeLinear gain in [0, 1].

◆ stopSound()

FLINT_API void Flint::Audio::stopSound ( int id)

Stop playback of a sound immediately.

Parameters
idSound ID to stop.

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