-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoundEngine.h
121 lines (88 loc) · 2.65 KB
/
SoundEngine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
namespace sfx
{
const unsigned int ChannelsMax = 32;
// 0-31
enum class Sound : unsigned int
{
ButtonPress = 0,
ButtonRelease,
SOUND_MAX = sfx::ChannelsMax - 1u
};
// 0-31
enum class Music : unsigned int
{
MainMenu = 0,
Ambient,
MUSIC_MAX = sfx::ChannelsMax - 1u
};
class SoundEngine
{
private:
// System:
FMOD::System* soundSystem;
// Sounds:
// SFX
FMOD::Sound* sounds[sfx::ChannelsMax];
// Music
FMOD::Sound* music[sfx::ChannelsMax];
// Channels:
// SFX
FMOD::Channel* soundChannels[sfx::ChannelsMax];
FMOD::ChannelGroup* sfxGroup;
// Music
FMOD::Channel* musicChannels[sfx::ChannelsMax];
FMOD::ChannelGroup* musicGroup;
// Master channel group
FMOD::ChannelGroup* masterGroup;
// Variables:
// SFX
float sfxVolume;
// Music
float musicVolume;
float fadeStep;
float fadeRate;
std::map<const sfx::Music, const char*> musicFiles;
// private: Functions:
void initVariables();
void initSoundSystem();
public:
// Constructors and Destructor:
SoundEngine();
virtual ~SoundEngine();
// Accessors:
const float& getSfxVolume() const;
const float& getMusicVolume() const;
const float& getFadeRate() const;
const bool isPlaying(const sfx::Music name) const;
const bool isMusicPlaying() const;
const bool isPaused(const sfx::Music name) const;
const bool isMusicPaused() const;
// Modifiers:
void increaseSfxVolume(const float& value);
void increaseMusicVolume(const float& value);
void fade(const float& fade_step);
// Functions:
// Should use '\\' instead of '/' in the file path and put this file to the .exe location,
// to be able to play the game without Visual Studio.
// @param const unsigned int& index Index associated with sound file.
// @param const char* file_path Actual file path, 256 symbols maximum.
void initSound(const sfx::Sound name, const char* file_path);
void playSound(const sfx::Sound name);
// Should use '\\' instead of '/' in the file path and put this file to the .exe location,
// to be able to play the game without Visual Studio.
// @param const unsigned int& index Index associated with music file.
// @param const char* file_path Actual file path.
void initMusic(const sfx::Music name, const char* file_path);
void playMusic(const sfx::Music name, const bool looped, const bool paused);
void pause(const sfx::Music name);
void unpause(const sfx::Music name);
void stop(const sfx::Music name);
void setPosition(const sfx::Music name, const unsigned int milliseconds);
void fadeIn();
void fadeOut();
void updateSfxVolume();
void updateMusicVolume();
void update(const float& dt);
};
};