-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.hpp
executable file
·145 lines (116 loc) · 2.55 KB
/
audio.hpp
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef AUDIO_HPP
#define AUDIO_HPP
#include "fmod.h"
class Audio;
class Sound;
class Music;
extern Audio audio;
//wrapper for a sound effect file
class Sound
{
public:
Sound()
{
soundFlag = FSOUND_HW2D;
soundData = 0;
};
~Sound(){};
typedef FSOUND_SAMPLE* SoundData;
void load(const char *fileName, bool is3D = true)
{
if (is3D)
soundFlag = FSOUND_HW3D;
soundData = FSOUND_Sample_Load(
FSOUND_FREE,
fileName,
soundFlag,
0,
0);
}
inline SoundData getSoundData() const
{
return soundData;
}
inline bool is3D() const
{
return soundFlag == FSOUND_HW3D;
}
private:
SoundData soundData;
int soundFlag;
};
//wrapper for a music file
class Music
{
public:
Music()
{
musicData = 0;
};
~Music(){};
typedef FSOUND_STREAM* MusicData;
void load(const char *fileName, bool repeat = true)
{
int musicFlags = FSOUND_2D;
if (repeat)
musicFlags |= FSOUND_LOOP_NORMAL;
musicData = FSOUND_Stream_Open(
fileName,
musicFlags,
0,
0);
}
inline MusicData getMusicData() const
{
return musicData;
}
private:
MusicData musicData;
};
//manages all sound/music playback
class Audio
{
public:
Audio();
~Audio();
void initialize();
void shutdown();
void update();
void playSound(const Sound &sound);
void playSoundEx(
const Sound &sound,
float x,
float y,
float z = 0.0f,
bool repeat = false);
void stopAllSounds();
void playMusic(const Music &music, bool repeat = false);
void stopMusic(const Music &music);
void setVolume(int volume);
void setMusicVolume(int volume);
const int getMusicChannel() const
{
return musicChannel;
}
enum speaker_mode
{
speaker_headphones = FSOUND_SPEAKERMODE_HEADPHONES,
speaker_mono = FSOUND_SPEAKERMODE_MONO,
speaker_quad = FSOUND_SPEAKERMODE_QUAD,
speaker_stereo = FSOUND_SPEAKERMODE_STEREO
};
void setSpeakerMode(speaker_mode speakerMode);
const speaker_mode getSpeakerModeByName(
const std::string &speakerModeName) const;
static const int maxVolume;
static const int minVolume;
private:
int currentVolume;
int currentMusicVolume;
int musicChannel;
speaker_mode currentSpeakerMode;
};
void setSoundtrack(const char *filename, bool repeat);
void stopMusic(void);
void resumeMusic(bool repeat);
#endif //AUDIO_HPP