Game Audio Module
A C++ audio system using miniaudio with Python bindings
Loading...
Searching...
No Matches
audio_group.h
Go to the documentation of this file.
1#pragma once
2
3#include "miniaudio/miniaudio.h"
4#include <chrono>
5#include <memory>
6
12namespace audio {
13
28 friend class AudioManager;
29
33 friend class AudioSystem;
34
38 friend class Sound;
39
40 public:
50 static std::unique_ptr<AudioGroup> Create(ma_engine* engine) {
51 return std::unique_ptr<AudioGroup>(new AudioGroup(engine));
52 }
53
54 private:
60 explicit AudioGroup(ma_engine* engine);
61
62 public:
69
70 private:
71
77 void SetVolume(float volume);
78
84 float GetVolume() const { return volume_; }
85
92 void FadeVolume(float targetVolume, std::chrono::milliseconds duration);
93
99 ma_sound_group* GetHandle() { return sound_group_; }
100
106 std::chrono::steady_clock::time_point GetFadeEndTime() const { return fade_end_time_; }
107
113 float GetTargetVolume() const { return target_volume_; }
114
120 float GetStartVolume() const { return start_volume_; }
121
127 bool IsFading() const { return is_fading_; }
128
134 std::chrono::milliseconds GetFadeDuration() const { return fade_duration_; }
135
141 void SetFadingState(bool fading) { is_fading_ = fading; }
142
143 private:
146 float target_volume_{0.0f};
147 float start_volume_{0.0f};
148 bool is_fading_{false};
149 std::chrono::steady_clock::time_point fade_end_time_;
150 std::chrono::milliseconds fade_duration_{0};
152
155 ma_sound_group* sound_group_;
156 ma_engine* engine_;
158
159 float volume_;
160};
161
162} // namespace audio
Controls multiple sounds as a single unit.
Definition audio_group.h:24
~AudioGroup()
Destructor.
Definition audio_group.cpp:19
void SetFadingState(bool fading)
Allows AudioManager to set fading state directly.
Definition audio_group.h:141
bool IsFading() const
Checks if the group is currently fading.
Definition audio_group.h:127
void SetVolume(float volume)
Sets the volume for this group.
Definition audio_group.cpp:27
void FadeVolume(float targetVolume, std::chrono::milliseconds duration)
Fades the group volume to a target over duration.
Definition audio_group.cpp:36
ma_engine * engine_
Reference to miniaudio engine.
Definition audio_group.h:156
float target_volume_
Target volume for fade.
Definition audio_group.h:146
bool is_fading_
Whether currently fading.
Definition audio_group.h:148
std::chrono::steady_clock::time_point GetFadeEndTime() const
Gets the end time of the current fade.
Definition audio_group.h:106
std::chrono::milliseconds GetFadeDuration() const
Gets the duration of the current fade.
Definition audio_group.h:134
ma_sound_group * GetHandle()
Gets the underlying miniaudio sound group handle.
Definition audio_group.h:99
float GetStartVolume() const
Gets the starting volume for the current fade.
Definition audio_group.h:120
float GetTargetVolume() const
Gets the target volume for the current fade.
Definition audio_group.h:113
float start_volume_
Starting volume for fade.
Definition audio_group.h:147
std::chrono::milliseconds fade_duration_
Duration of the fade.
Definition audio_group.h:150
std::chrono::steady_clock::time_point fade_end_time_
When the fade will end.
Definition audio_group.h:149
static std::unique_ptr< AudioGroup > Create(ma_engine *engine)
Factory method for creating AudioGroup instances.
Definition audio_group.h:50
float GetVolume() const
Gets the current volume for this group.
Definition audio_group.h:84
ma_sound_group * sound_group_
miniaudio sound group handle
Definition audio_group.h:155
float volume_
Current volume level.
Definition audio_group.h:159
Central manager for all audio functionality.
Definition audio_manager.h:179
Low-level audio system that interfaces directly with miniaudio.
Definition audio_system.h:32
Represents an audio file that can be played multiple times simultaneously.
Definition sound.h:51
Definition audio_group.cpp:7