Game Audio Module
A C++ audio system using miniaudio with Python bindings
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
audio::AudioTrack Class Reference

Manages a collection of synchronized audio layers. More...

#include <audio_track.h>

Classes

struct  Layer
 Represents a single audio layer within a track. More...
 

Public Member Functions

 ~AudioTrack ()
 Destructor.
 

Static Public Member Functions

static std::unique_ptr< AudioTrackCreate (AudioSystem *system)
 Factory method for creating AudioTrack instances.
 

Private Member Functions

 AudioTrack (AudioSystem *system)
 Private constructor - use Create() instead.
 
void AddLayer (const std::string &name, const std::string &filepath, AudioGroup *group=nullptr, bool looping=true)
 Adds a new layer to the track.
 
void FadeLayer (const std::string &name, float target_volume, std::chrono::milliseconds duration)
 Sets the target volume for a layer and fades to it over time.
 
float GetLayerVolume (const std::string &name) const
 Gets current volume of a layer.
 
void Play ()
 Starts playing all layers in sync.
 
void RemoveLayer (const std::string &name)
 Removes a layer from the track.
 
void SetLayerVolume (const std::string &name, float volume)
 Sets layer volume immediately without fading.
 
void Stop ()
 Stops all layers.
 
void Update ()
 Updates layer fading.
 

Private Attributes

bool is_playing_
 Whether the track is currently playing.
 
std::unordered_map< std::string, Layerlayers_
 Map of layer names to layer data.
 
AudioSystemsystem_
 Reference to the audio system.
 

Friends

class AudioManager
 AudioManager is the only class that can create AudioTracks.
 

Detailed Description

Manages a collection of synchronized audio layers.

The AudioTrack class provides functionality for layered music playback where multiple audio tracks can play simultaneously and be independently controlled. Each layer can be faded in or out independently, allowing for dynamic music transitions based on gameplay.

Layers within a track are kept in sync, making them ideal for musical stems that need to play together.

Constructor & Destructor Documentation

◆ AudioTrack()

audio::AudioTrack::AudioTrack ( AudioSystem system)
explicitprivate

Private constructor - use Create() instead.

Parameters
systemPointer to the audio system

◆ ~AudioTrack()

audio::AudioTrack::~AudioTrack ( )

Destructor.

Stops all audio playback and releases resources

Member Function Documentation

◆ AddLayer()

void audio::AudioTrack::AddLayer ( const std::string &  name,
const std::string &  filepath,
AudioGroup group = nullptr,
bool  looping = true 
)
private

Adds a new layer to the track.

Each layer is a separate audio file that will play simultaneously with other layers in the track. Layers are kept in sync.

Parameters
nameIdentifier for the layer
filepathPath to the audio file
groupOptional pointer to the group this layer belongs to
loopingWhether the layer should loop continuously

◆ Create()

static std::unique_ptr< AudioTrack > audio::AudioTrack::Create ( AudioSystem system)
inlinestatic

Factory method for creating AudioTrack instances.

This static factory method ensures proper initialization and encapsulation of AudioTrack objects.

Parameters
systemPointer to the audio system
Returns
std::unique_ptr<AudioTrack> Unique pointer to a new AudioTrack

◆ FadeLayer()

void audio::AudioTrack::FadeLayer ( const std::string &  name,
float  target_volume,
std::chrono::milliseconds  duration 
)
private

Sets the target volume for a layer and fades to it over time.

Parameters
nameName of the layer
target_volumeTarget volume (0.0 to 1.0)
durationDuration of the fade in milliseconds

◆ GetLayerVolume()

float audio::AudioTrack::GetLayerVolume ( const std::string &  name) const
private

Gets current volume of a layer.

Parameters
nameName of the layer
Returns
float Current volume level (0.0 to 1.0)

◆ Play()

void audio::AudioTrack::Play ( )
private

Starts playing all layers in sync.

All layers will begin playback simultaneously to ensure they remain synchronized.

◆ RemoveLayer()

void audio::AudioTrack::RemoveLayer ( const std::string &  name)
private

Removes a layer from the track.

Parameters
nameName of the layer to remove

◆ SetLayerVolume()

void audio::AudioTrack::SetLayerVolume ( const std::string &  name,
float  volume 
)
private

Sets layer volume immediately without fading.

Parameters
nameName of the layer
volumeVolume level (0.0 to 1.0)

◆ Stop()

void audio::AudioTrack::Stop ( )
private

Stops all layers.

Stops playback of all layers in the track.

◆ Update()

void audio::AudioTrack::Update ( )
private

Updates layer fading.

This method is called regularly by the audio system to update volume fading for all layers.

Friends And Related Symbol Documentation

◆ AudioManager

friend class AudioManager
friend

AudioManager is the only class that can create AudioTracks.

Member Data Documentation

◆ is_playing_

bool audio::AudioTrack::is_playing_
private

Whether the track is currently playing.

◆ layers_

std::unordered_map<std::string, Layer> audio::AudioTrack::layers_
private

Map of layer names to layer data.

◆ system_

AudioSystem* audio::AudioTrack::system_
private

Reference to the audio system.


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