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(const 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
202 auto setMuted(bool muted) -> void
203 {
204 if (overrideGroup)
205 {
206 overrideGroup->setMute(muted);
207 }
208 }
209
215 auto setOverrideVolume(float volume) -> void
216 {
217 if (overrideGroup)
218 {
219 overrideGroup->setVolume(volume);
220 }
221 }
222
228 auto getOverrideVolume() const -> float
229 {
230 auto volume = 0.0f;
231 if (overrideGroup)
232 {
233 overrideGroup->getVolume(&volume);
234 }
235 return volume;
236 }
237
243 auto setMasterVolume(float volume) -> void
244 {
245 if (masterGroup)
246 {
247 masterGroup->setVolume(volume);
248 }
249 }
250
256 auto getMasterVolume() const -> float
257 {
258 auto volume = 0.0f;
259 if (masterGroup)
260 {
261 masterGroup->getVolume(&volume);
262 }
263 return volume;
264 }
265
272 auto setMusicVolume(float volume) -> void
273 {
274 if (musicGroup)
275 {
276 musicGroup->setVolume(volume);
277 }
278 }
279
286 auto getMusicVolume() const -> float
287 {
288 auto volume = 0.0f;
289 if (musicGroup)
290 {
291 musicGroup->getVolume(&volume);
292 }
293 return volume;
294 }
295
301 auto setSFXVolume(float volume) -> void
302 {
303 if (sfxGroup)
304 {
305 sfxGroup->setVolume(volume);
306 }
307 }
308
314 auto getSFXVolume() -> float
315 {
316 auto volume = 0.0f;
317 if (sfxGroup)
318 {
319 sfxGroup->getVolume(&volume);
320 }
321 return volume;
322 }
323
329 auto setUIVolume(float volume) -> void
330 {
331 if (uiGroup)
332 {
333 uiGroup->setVolume(volume);
334 }
335 }
336
342 auto getUIVolume() const -> float
343 {
344 auto volume = 0.0f;
345 if (uiGroup)
346 {
347 uiGroup->getVolume(&volume);
348 }
349 return volume;
350 }
351
352 auto playAudio(const std::string& soundEffect) const -> void;
353 auto playModulatedAudio(const std::string& soundEffect) const -> void;
354 auto playPitchedAudio(const std::string& soundEffect, float pitch) const -> void;
355 auto playVolumedAudio(const std::string& soundEffect, float volume) const -> void;
356
357#pragma endregion
358
359private:
360#pragma region member_variables
361 FMOD::System* member;
362 FMOD::ChannelGroup* masterGroup;
363 FMOD::ChannelGroup* musicGroup;
364 FMOD::ChannelGroup* sfxGroup;
365 FMOD::ChannelGroup* uiGroup;
366 FMOD::ChannelGroup* overrideGroup; // exists solely for the purpose of allowing temporary overrides of pitch for all
367
368#pragma endregion
369
370#pragma region helper_functions
371
372#pragma endregion
373
374#pragma region AudioSystem_Messages
375
376 auto linkMessages() -> void;
377
378 auto receivePlayAudioMessage(const Message* message) -> Message;
379 auto receivePlayModulatedMessage(const Message* message) -> Message;
381 auto receiveIncreaseVolume(const Message* message) -> Message;
383 auto receiveDecreaseVolume(const Message* message) -> Message;
384
385#pragma endregion
386
387#pragma region static_variables
388
389#pragma endregion
390
391
392};
393}
sys::Json Stream
Definition AudioObject.h:20
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
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:243
auto operator=(const AudioSystem &other) -> AudioSystem &
Definition AudioSystem.cpp:172
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:332
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:286
auto getUIVolume() const -> float
Definition AudioSystem.h:342
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition AudioSystem.cpp:221
auto playPitchedAudio(const std::string &soundEffect, float pitch) const -> void
Definition AudioSystem.cpp:307
FMOD::ChannelGroup * uiGroup
Definition AudioSystem.h:365
auto receivePlayAudioMessage(const Message *message) -> Message
Definition AudioSystem.cpp:356
FMOD::ChannelGroup * overrideGroup
Definition AudioSystem.h:366
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:363
AudioSystem()
Definition AudioSystem.cpp:56
auto onUpdate(float dt) -> void override
called once every frame.
Definition AudioSystem.cpp:200
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:228
auto receiveIncreaseVolume(const Message *message) -> Message
Increase in volume using the '=' key (meant to be plus).
Definition AudioSystem.cpp:393
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:314
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition AudioSystem.cpp:273
auto stopAll() -> void
Stops all current tracks playing.
Definition AudioSystem.cpp:421
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:301
auto getSFXChannelGroup() -> FMOD::ChannelGroup *
Returns the sfx channel group.
Definition AudioSystem.h:135
FMOD::ChannelGroup * sfxGroup
Definition AudioSystem.h:364
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition AudioSystem.cpp:269
FMOD::System * member
Definition AudioSystem.h:361
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:256
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:215
auto getMusicChannelGroup() -> FMOD::ChannelGroup *
Returns the music channel group.
Definition AudioSystem.h:113
auto setUIVolume(float volume) -> void
Definition AudioSystem.h:329
auto playVolumedAudio(const std::string &soundEffect, float volume) const -> void
Definition AudioSystem.cpp:319
auto receiveDecreaseVolume(const Message *message) -> Message
Decrease in volume using the '-' key.
Definition AudioSystem.cpp:409
static auto getEnum() -> Type
function required by all systems
Definition AudioSystem.h:33
auto receivePlayModulatedMessage(const Message *message) -> Message
Definition AudioSystem.cpp:371
~AudioSystem() override
Definition AudioSystem.cpp:142
auto getFMODSystem() -> FMOD::System *
Returns the FMOD system.
Definition AudioSystem.h:83
FMOD::ChannelGroup * masterGroup
Definition AudioSystem.h:362
auto playAudio(const std::string &soundEffect) const -> void
Definition AudioSystem.cpp:279
auto onRender() -> void override
called every frame after update has been called for every object.
Definition AudioSystem.cpp:265
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:272
auto playModulatedAudio(const std::string &soundEffect) const -> void
Definition AudioSystem.cpp:289
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition AudioSystem.h:52
auto setMuted(bool muted) -> void
mute or unmute all audio
Definition AudioSystem.h:202
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:37
Definition Message.h:35