|
@@ -28,6 +28,7 @@
|
28
|
28
|
|
29
|
29
|
Sound::Sound() {
|
30
|
30
|
mInit = false;
|
|
31
|
+ mVolume = 1.0f;
|
31
|
32
|
}
|
32
|
33
|
|
33
|
34
|
Sound::~Sound() {
|
|
@@ -36,6 +37,8 @@ Sound::~Sound() {
|
36
|
37
|
}
|
37
|
38
|
|
38
|
39
|
int Sound::init() {
|
|
40
|
+ assert(mInit == false);
|
|
41
|
+
|
39
|
42
|
#ifndef __APPLE__
|
40
|
43
|
int fd;
|
41
|
44
|
|
|
@@ -71,6 +74,32 @@ int Sound::registeredSources() {
|
71
|
74
|
return mSource.size();
|
72
|
75
|
}
|
73
|
76
|
|
|
77
|
+void Sound::clear() {
|
|
78
|
+ assert(mInit == true);
|
|
79
|
+ assert(mSource.size() == mBuffer.size());
|
|
80
|
+
|
|
81
|
+ for (size_t i = 0; i < mSource.size(); i++) {
|
|
82
|
+ alDeleteSources(1, &mSource[i]);
|
|
83
|
+ alDeleteBuffers(1, &mBuffer[i]);
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ mSource.clear();
|
|
87
|
+ mBuffer.clear();
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+void Sound::setVolume(float vol) {
|
|
91
|
+ assert(mInit == true);
|
|
92
|
+ assert(mSource.size() == mBuffer.size());
|
|
93
|
+
|
|
94
|
+ if ((mSource.size() > 0) && (mVolume != vol)) {
|
|
95
|
+ // Apply new volume to old sources if needed
|
|
96
|
+ for (size_t i = 0; i < mSource.size(); i++)
|
|
97
|
+ alSourcef(mSource[i], AL_GAIN, vol);
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ mVolume = vol;
|
|
101
|
+}
|
|
102
|
+
|
74
|
103
|
void Sound::listenAt(float pos[3], float angle[3]) {
|
75
|
104
|
assert(mInit == true);
|
76
|
105
|
assert(mSource.size() == mBuffer.size());
|
|
@@ -138,6 +167,8 @@ int Sound::addFile(const char *filename, int *source, unsigned int flags)
|
138
|
167
|
alSourcei(mSource[id], AL_LOOPING, 1);
|
139
|
168
|
}
|
140
|
169
|
|
|
170
|
+ alSourcef(mSource[id], AL_GAIN, mVolume);
|
|
171
|
+
|
141
|
172
|
*source = id;
|
142
|
173
|
|
143
|
174
|
return 0;
|
|
@@ -194,6 +225,8 @@ int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigne
|
194
|
225
|
alSourcei(mSource[id], AL_LOOPING, 1);
|
195
|
226
|
}
|
196
|
227
|
|
|
228
|
+ alSourcef(mSource[id], AL_GAIN, mVolume);
|
|
229
|
+
|
197
|
230
|
*source = id;
|
198
|
231
|
|
199
|
232
|
//! \fixme Should free alut buffer?
|
|
@@ -201,19 +234,6 @@ int Sound::addWave(unsigned char *wav, unsigned int length, int *source, unsigne
|
201
|
234
|
return 0;
|
202
|
235
|
}
|
203
|
236
|
|
204
|
|
-void Sound::clear() {
|
205
|
|
- assert(mInit == true);
|
206
|
|
- assert(mSource.size() == mBuffer.size());
|
207
|
|
-
|
208
|
|
- for (size_t i = 0; i < mSource.size(); i++) {
|
209
|
|
- alDeleteSources(1, &mSource[i]);
|
210
|
|
- alDeleteBuffers(1, &mBuffer[i]);
|
211
|
|
- }
|
212
|
|
-
|
213
|
|
- mSource.clear();
|
214
|
|
- mBuffer.clear();
|
215
|
|
-}
|
216
|
|
-
|
217
|
237
|
void Sound::play(int source) {
|
218
|
238
|
assert(mInit == true);
|
219
|
239
|
assert(mSource.size() == mBuffer.size());
|