Brunot
Loading...
Searching...
No Matches
AudioObject.h
Go to the documentation of this file.
1// File: AudioObject.h
2// Description: Audio system using FMOD with all declarations needed for basic audio playback
3// Author(s): Marcelo Escamilla (marcelo.escamilla@digipen.edu)
4// 2025 / 09 / 29
5// (C) Digipen 2025
6// ____ __ __ __
7// /\__ _\/\ \ /\ \/\ \
8// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
9// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
10// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
11// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
12// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
13
14#pragma once
15
16#include <FMOD/fmod.h>
17#include <FMOD/fmod.hpp>
18#include "Framework/Component.h"
19
20using Stream = sys::Json; // replace with whatever stream we are using
21
26enum class AudioType
27{
32};
33
38{
39
40public:
46
54 AudioObject(const char* name, bool loopable, AudioType _channelType);
55
56
57 // The rule of five is needed to make this work properly so these are needed here
58 // Keisha mentioned that the rule of five is having the copy, assignment, move, move assignment, and destructor
59 // Copy constructor changed a bit to properly copy the sound object
60 AudioObject(const AudioObject& other);
61 // Copy assignment operator implemented properly
62 auto operator=(const AudioObject& other) -> AudioObject&;
63 // Move constructor is needing to be implemented properly
64 AudioObject(AudioObject&& other) noexcept;
65 // Move assignment operator needing to be implemented properly
66 auto operator=(AudioObject&& other) noexcept -> AudioObject&;
67
73
78 auto play() -> void;
79
85 auto pause(bool pause) -> void;
86
91 auto stop() -> void;
92
98 auto setVolume(float vol) -> void;
99
106 auto setPitch(float pit) -> void;
107
113 auto getIsPlaying() const -> bool;
114
120 auto getIsPaused() const -> bool;
121
127 auto getVolume() const -> float;
128
134 auto getPitch() const -> float;
135
141 auto getAudioHandler() -> AudioObject*;
142
148 auto name() const -> const std::string&;
149
156 auto loadFile(const std::string& fileName, bool loopable) -> void;
157
158 auto load(Stream& stream) -> void;
159 auto save(Stream& stream) const -> void;
160
161 friend auto to_json(json& j, const AudioObject& a) -> void;
162 friend auto from_json(const json& j, AudioObject& a) -> void;
163
164private:
165 FMOD::Sound* sound;
166 FMOD::Channel* channel;
169 float volume;
170 float pitch;
171 std::string filePath;
173 std::string _name;
175};
AudioType
AudioType is an enum that represents the type of audio, it is used to determine which channel group t...
Definition AudioObject.h:27
@ Music
Definition AudioObject.h:29
@ None
Definition AudioObject.h:28
@ UI
Definition AudioObject.h:31
@ SFX
Definition AudioObject.h:30
sys::Json Stream
Definition AudioObject.h:20
The base class for components, holding all of their shared All components should inherit from this.
nlohmann::json json
Definition Json.cpp:19
auto getIsPaused() const -> bool
Definition AudioObject.cpp:309
friend auto to_json(json &j, const AudioObject &a) -> void
Definition AudioObject.cpp:376
bool isPlaying
Definition AudioObject.h:167
bool isPaused
Definition AudioObject.h:168
auto getPitch() const -> float
Definition AudioObject.cpp:343
friend auto from_json(const json &j, AudioObject &a) -> void
Definition AudioObject.cpp:387
auto setVolume(float vol) -> void
Definition AudioObject.cpp:271
auto getIsPlaying() const -> bool
Definition AudioObject.cpp:292
auto setPitch(float pit) -> void
Definition AudioObject.cpp:281
FMOD::Sound * sound
Definition AudioObject.h:165
~AudioObject()
Definition AudioObject.cpp:101
auto getAudioHandler() -> AudioObject *
Definition AudioObject.cpp:362
FMOD::Channel * channel
Definition AudioObject.h:166
auto load(Stream &stream) -> void
Definition AudioObject.cpp:367
auto save(Stream &stream) const -> void
Definition AudioObject.cpp:372
AudioObject()
Definition AudioObject.cpp:45
auto operator=(const AudioObject &other) -> AudioObject &
Definition AudioObject.cpp:75
auto loadFile(const std::string &fileName, bool loopable) -> void
Definition AudioObject.cpp:401
auto pause(bool pause) -> void
Definition AudioObject.cpp:245
AudioType channelType
Definition AudioObject.h:174
std::string filePath
Definition AudioObject.h:171
bool isLoopable
Definition AudioObject.h:172
float pitch
Definition AudioObject.h:170
std::string _name
Definition AudioObject.h:173
auto stop() -> void
Definition AudioObject.cpp:260
auto getVolume() const -> float
Definition AudioObject.cpp:324
float volume
Definition AudioObject.h:169
auto play() -> void
Definition AudioObject.cpp:146
auto name() const -> const std::string &
Definition AudioObject.cpp:396
Definition Json.h:32