|
Game Audio Module
A C++ audio system using miniaudio with Python bindings
|
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< AudioTrack > | Create (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, Layer > | layers_ |
| Map of layer names to layer data. | |
| AudioSystem * | system_ |
| Reference to the audio system. | |
Friends | |
| class | AudioManager |
| AudioManager is the only class that can create AudioTracks. | |
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.
|
explicitprivate |
Private constructor - use Create() instead.
| system | Pointer to the audio system |
| audio::AudioTrack::~AudioTrack | ( | ) |
Destructor.
Stops all audio playback and releases resources
|
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.
| name | Identifier for the layer |
| filepath | Path to the audio file |
| group | Optional pointer to the group this layer belongs to |
| looping | Whether the layer should loop continuously |
|
inlinestatic |
Factory method for creating AudioTrack instances.
This static factory method ensures proper initialization and encapsulation of AudioTrack objects.
| system | Pointer to the audio system |
|
private |
Sets the target volume for a layer and fades to it over time.
| name | Name of the layer |
| target_volume | Target volume (0.0 to 1.0) |
| duration | Duration of the fade in milliseconds |
|
private |
Gets current volume of a layer.
| name | Name of the layer |
|
private |
Starts playing all layers in sync.
All layers will begin playback simultaneously to ensure they remain synchronized.
|
private |
Removes a layer from the track.
| name | Name of the layer to remove |
|
private |
Sets layer volume immediately without fading.
| name | Name of the layer |
| volume | Volume level (0.0 to 1.0) |
|
private |
Stops all layers.
Stops playback of all layers in the track.
|
private |
Updates layer fading.
This method is called regularly by the audio system to update volume fading for all layers.
|
friend |
AudioManager is the only class that can create AudioTracks.
|
private |
Whether the track is currently playing.
|
private |
Map of layer names to layer data.
|
private |
Reference to the audio system.