Brunot
Loading...
Searching...
No Matches
AudioSystem.h
Go to the documentation of this file.
1// File: AudioSystem.h
2// Description: Initialilze FMOD and holds messages for audio playback
3// Author(s): Marcelo Escamilla (marcelo.escamilla@digipen.edu) worked on the audio playback parts and system initialization
4// Ori Balashov (ori.balashov@digipen.edu) Helped with message implementation
5// 2025 / 10 / 20
6// (C) Digipen 2025
7// newSystemStub.h
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15#pragma once
16
17#include "Framework/System.h"
18#include <FMOD/fmod.h>
19#include <FMOD/fmod.hpp>
20
21struct Message;
22
23namespace sys
24{
25class AudioSystem : public System
26{
27public:
28#pragma region static_functions
29
33 static auto getEnum() -> Type
34 {
35 return Type::AudioSystem;
36 }
37
38#pragma endregion
39
40 // this constructor will initialize FMOD init stuff should only be called once
42 // Shutdown code
43 ~AudioSystem() override;
44 AudioSystem(const AudioSystem& other);
45 AudioSystem(AudioSystem&& other) noexcept;
46 auto operator=(const AudioSystem& other) -> AudioSystem&;
47 auto operator=(AudioSystem&& other) noexcept -> AudioSystem&;
48
49
50#pragma region overridden_functions
51
52 auto clone() const -> std::unique_ptr<GameObject> override
53 {
54 return std::make_unique<AudioSystem>(*this);
55 }
56
57 auto systemShowMenu() -> void override;
58
59 auto onUpdate(float dt) -> void override;
60
61 auto endWindow() -> void override
62 {
63 }; // for debug ImGUI
64 auto onRender() -> void override;
65 auto load(Stream& stream) -> void override;
66 auto save(Stream& stream) const -> void override;
67
68#pragma endregion
69
70#pragma region AudioSystem_Functions
71
76 auto stopAll() -> void;
77
83 auto getFMODSystem() -> FMOD::System*
84 {
85 return this->member;
86 }
87
93 auto getOverrideChannelGroup() -> FMOD::ChannelGroup*
94 {
95 return this->overrideGroup;
96 }
97
103 auto getMasterChannelGroup() -> FMOD::ChannelGroup*
104 {
105 return this->masterGroup;
106 }
107
113 auto getMusicChannelGroup() -> FMOD::ChannelGroup*
114 {
115 return this->musicGroup;
116 }
117
122 auto setMusicPitch(float gain) -> void
123 {
124 if (musicGroup)
125 {
126 musicGroup->setPitch(gain);
127 }
128 }
129
135 auto getSFXChannelGroup() -> FMOD::ChannelGroup*
136 {
137 return this->sfxGroup;
138 }
139
144 auto setSFXPitch(float gain) -> void
145 {
146 if (sfxGroup)
147 {
148 sfxGroup->setPitch(gain);
149 }
150 }
151
157 auto getUIChannelGroup() -> FMOD::ChannelGroup*
158 {
159 return this->uiGroup;
160 }
161
166 auto setUIPitch(float gain) -> void
167 {
168 if (uiGroup)
169 {
170 uiGroup->setPitch(gain);
171 }
172 }
173
178 auto setMasterPitch(float gain) -> void
179 {
180 if (masterGroup)
181 {
182 masterGroup->setPitch(gain);
183 }
184 }
185
190 auto setOverridePitch(float gain) -> void
191 {
192 if (overrideGroup)
193 {
194 overrideGroup->setPitch(gain);
195 }
196 }
197
203 auto setOverrideVolume(float volume) -> void
204 {
205 if (overrideGroup)
206 {
207 overrideGroup->setVolume(volume);
208 }
209 }
210
216 auto getOverrideVolume() const -> float
217 {
218 auto volume = 0.0f;
219 if (overrideGroup)
220 {
221 overrideGroup->getVolume(&volume);
222 }
223 return volume;
224 }
225
231 auto setMasterVolume(float volume) -> void
232 {
233 if (masterGroup)
234 {
235 masterGroup->setVolume(volume);
236 }
237 }
238
244 auto getMasterVolume() const -> float
245 {
246 auto volume = 0.0f;
247 if (masterGroup)
248 {
249 masterGroup->getVolume(&volume);
250 }
251 return volume;
252 }
253
260 auto setMusicVolume(float volume) -> void
261 {
262 if (musicGroup)
263 {
264 musicGroup->setVolume(volume);
265 }
266 }
267
274 auto getMusicVolume() const -> float
275 {
276 auto volume = 0.0f;
277 if (musicGroup)
278 {
279 musicGroup->getVolume(&volume);
280 }
281 return volume;
282 }
283
289 auto setSFXVolume(float volume) -> void
290 {
291 if (sfxGroup)
292 {
293 sfxGroup->setVolume(volume);
294 }
295 }
296
302 auto getSFXVolume() -> float
303 {
304 auto volume = 0.0f;
305 if (sfxGroup)
306 {
307 sfxGroup->getVolume(&volume);
308 }
309 return volume;
310 }
311
317 auto setUIVolume(float volume) -> void
318 {
319 if (uiGroup)
320 {
321 uiGroup->setVolume(volume);
322 }
323 }
324
330 auto getUIVolume() const -> float
331 {
332 auto volume = 0.0f;
333 if (uiGroup)
334 {
335 uiGroup->getVolume(&volume);
336 }
337 return volume;
338 }
339
340#pragma endregion
341
342private:
343#pragma region member_variables
344 FMOD::System* member;
345 FMOD::ChannelGroup* masterGroup;
346 FMOD::ChannelGroup* musicGroup;
347 FMOD::ChannelGroup* sfxGroup;
348 FMOD::ChannelGroup* uiGroup;
349 FMOD::ChannelGroup* overrideGroup; // exists soley for the purpose of allowing temporary overrides of pitch for all
350
351#pragma endregion
352
353#pragma region helper_functions
354
355#pragma endregion
356
357#pragma region AudioSystem_Messages
358
359 auto linkMessages() -> void;
360
361 auto receivePlayAudioMessage(const Message* message) -> Message;
362 auto receivePlayModulatedMessage(const Message* message) -> Message;
364 auto receiveIncreaseVolume(const Message* message) -> Message;
366 auto receiveDecreaseVolume(const Message* message) -> Message;
367
368#pragma endregion
369
370#pragma region static_variables
371
372#pragma endregion
373
374
375};
376}
sys::Json Stream
Definition AudioObject.h:20
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
Type
Definition System.h:20
@ AudioSystem
Definition System.h:29
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
Definition AudioSystem.h:26
auto setMasterVolume(float volume) -> void
Sets the master volume for all audio, this will affect all channel groups and sounds that are playing...
Definition AudioSystem.h:231
auto operator=(const AudioSystem &other) -> AudioSystem &
Definition AudioSystem.cpp:166
auto setOverridePitch(float gain) -> void
Set the gain of the low pass filter 0 for full quiet and 1 for full volume.
Definition AudioSystem.h:190
auto linkMessages() -> void
Definition AudioSystem.cpp:268
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition AudioSystem.h:61
auto getMusicVolume() const -> float
Returns the music volume for all audio in the music channel group, this will affect all sounds that a...
Definition AudioSystem.h:274
auto getUIVolume() const -> float
Definition AudioSystem.h:330
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition AudioSystem.cpp:215
FMOD::ChannelGroup * uiGroup
Definition AudioSystem.h:348
auto receivePlayAudioMessage(const Message *message) -> Message
Definition AudioSystem.cpp:292
FMOD::ChannelGroup * overrideGroup
Definition AudioSystem.h:349
auto setUIPitch(float gain) -> void
Set the gain of the low pass filter 0 for full quiet and 1 for full volume.
Definition AudioSystem.h:166
FMOD::ChannelGroup * musicGroup
Definition AudioSystem.h:346
AudioSystem()
Definition AudioSystem.cpp:53
auto onUpdate(float dt) -> void override
called once every frame.
Definition AudioSystem.cpp:194
auto setMusicPitch(float gain) -> void
Set the gain of the low pass filter 0 for full quiet and 1 for full volume.
Definition AudioSystem.h:122
auto getOverrideVolume() const -> float
Returns the master volume for all audio, this will affect all channel groups and sounds that are play...
Definition AudioSystem.h:216
auto receiveIncreaseVolume(const Message *message) -> Message
Increase in volume using the '=' key (meant to be plus).
Definition AudioSystem.cpp:329
auto getUIChannelGroup() -> FMOD::ChannelGroup *
Returns the ui channel group.
Definition AudioSystem.h:157
auto getMasterChannelGroup() -> FMOD::ChannelGroup *
Returns the master channel group.
Definition AudioSystem.h:103
auto getSFXVolume() -> float
Sets the sfx volume for all audio in the sfx channel group, this will affect all sounds that are play...
Definition AudioSystem.h:302
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition AudioSystem.cpp:262
auto stopAll() -> void
Stops all current tracks playing.
Definition AudioSystem.cpp:360
auto setSFXVolume(float volume) -> void
Sets the sfx volume for all audio in the sfx channel group, this will affect all sounds that are play...
Definition AudioSystem.h:289
auto getSFXChannelGroup() -> FMOD::ChannelGroup *
Returns the sfx channel group.
Definition AudioSystem.h:135
FMOD::ChannelGroup * sfxGroup
Definition AudioSystem.h:347
FMOD::System * member
Definition AudioSystem.h:344
auto getMasterVolume() const -> float
Returns the master volume for all audio, this will affect all channel groups and sounds that are play...
Definition AudioSystem.h:244
auto setOverrideVolume(float volume) -> void
Sets the master volume for all audio, this will affect all channel groups and sounds that are playing...
Definition AudioSystem.h:203
auto getMusicChannelGroup() -> FMOD::ChannelGroup *
Returns the music channel group.
Definition AudioSystem.h:113
auto setUIVolume(float volume) -> void
Definition AudioSystem.h:317
auto load(Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition AudioSystem.cpp:258
auto receiveDecreaseVolume(const Message *message) -> Message
Decrease in volume using the '-' key.
Definition AudioSystem.cpp:345
static auto getEnum() -> Type
function required by all systems
Definition AudioSystem.h:33
auto receivePlayModulatedMessage(const Message *message) -> Message
Definition AudioSystem.cpp:307
~AudioSystem() override
Definition AudioSystem.cpp:136
auto getFMODSystem() -> FMOD::System *
Returns the FMOD system.
Definition AudioSystem.h:83
FMOD::ChannelGroup * masterGroup
Definition AudioSystem.h:345
auto onRender() -> void override
called every frame after update has been called for every object.
Definition AudioSystem.cpp:254
auto getOverrideChannelGroup() -> FMOD::ChannelGroup *
Returns the override channel group.
Definition AudioSystem.h:93
auto setMusicVolume(float volume) -> void
Sets the music volume for all audio in the music channel group, this will affect all sounds that are ...
Definition AudioSystem.h:260
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition AudioSystem.h:52
auto setSFXPitch(float gain) -> void
Set the gain of the low pass filter 0 for full quiet and 1 for full volume.
Definition AudioSystem.h:144
auto setMasterPitch(float gain) -> void
Set the gain of the low pass filter 0 for full quiet and 1 for full volume.
Definition AudioSystem.h:178
the type of elements in a basic_json container
Definition GameObject.h:32
Definition Message.h:34