author | koda |
Sat, 10 Oct 2009 14:26:50 +0000 | |
changeset 2413 | d921d13a8546 |
parent 2392 | a55dbef5cf31 |
child 2415 | 35d09cbf819a |
permissions | -rw-r--r-- |
2191 | 1 |
/* |
2 |
* OpenAL Bridge - a simple portable library for OpenAL interface |
|
3 |
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2220
diff
changeset
|
6 |
* it under the terms of the GNU Lesser General Public License as published by |
2191 | 7 |
* the Free Software Foundation; version 2 of the License |
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2220
diff
changeset
|
12 |
* GNU Lesser General Public License for more details. |
2191 | 13 |
* |
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2220
diff
changeset
|
14 |
* You should have received a copy of the GNU Lesser General Public License |
2191 | 15 |
* along with this program; if not, write to the Free Software |
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
2326
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
19 |
#include "openalbridge.h" |
2213 | 20 |
#include "wrappers.h" |
21 |
#include "alc.h" |
|
22 |
#include "loaders.h" |
|
23 |
#include "endianness.h" |
|
2191 | 24 |
|
25 |
#ifdef __CPLUSPLUS |
|
26 |
extern "C" { |
|
27 |
#endif |
|
2259 | 28 |
|
29 |
/*Sources are points emitting sound*/ |
|
30 |
ALuint *Sources; |
|
31 |
/*Buffers hold sound data*/ |
|
32 |
ALuint *Buffers; |
|
33 |
/*index for Sources and Buffers*/ |
|
34 |
ALuint globalindex, globalsize, increment; |
|
35 |
||
36 |
ALboolean openalReady = AL_FALSE; |
|
37 |
||
38 |
ALboolean openal_close (void) { |
|
39 |
/*Stop all sounds, deallocate all memory and close OpenAL */ |
|
40 |
ALCcontext *context; |
|
41 |
ALCdevice *device; |
|
42 |
||
43 |
if(openalReady == AL_FALSE) { |
|
44 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
45 |
return AL_FALSE; |
|
46 |
} |
|
47 |
||
48 |
alSourceStopv (globalsize, Sources); |
|
49 |
alDeleteSources (globalsize, Sources); |
|
50 |
alDeleteBuffers (globalsize, Buffers); |
|
51 |
||
52 |
free(Sources); |
|
53 |
free(Buffers); |
|
54 |
||
55 |
context = alcGetCurrentContext(); |
|
56 |
device = alcGetContextsDevice(context); |
|
57 |
||
58 |
alcMakeContextCurrent(NULL); |
|
59 |
alcDestroyContext(context); |
|
60 |
alcCloseDevice(device); |
|
61 |
||
62 |
openalReady = AL_FALSE; |
|
63 |
||
64 |
return AL_TRUE; |
|
65 |
} |
|
66 |
||
67 |
ALboolean openal_ready(void) { |
|
68 |
return openalReady; |
|
69 |
} |
|
70 |
||
2392
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
71 |
ALboolean openal_init(uint32_t usehardware, uint32_t memorysize) { |
2259 | 72 |
/*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
73 |
ALCcontext *context; |
|
74 |
ALCdevice *device; |
|
75 |
const ALCchar *default_device; |
|
76 |
||
77 |
/*Position of the listener*/ |
|
78 |
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; |
|
79 |
/*Velocity of the listener*/ |
|
80 |
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 }; |
|
81 |
/*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/ |
|
82 |
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; |
|
83 |
||
84 |
if(openalReady == AL_TRUE) { |
|
85 |
fprintf(stderr, "ERROR: OpenAL already initialized\n"); |
|
86 |
return AL_FALSE; |
|
87 |
} |
|
2392
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
88 |
|
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
89 |
if(usehardware) |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
90 |
{ |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
91 |
if ((device = alcOpenDevice(NULL)) == NULL) { |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
92 |
fprintf(stderr, "ERROR: Failed to open sound device\n"); |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
93 |
return AL_FALSE; |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
94 |
} |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
95 |
} |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
96 |
else |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
97 |
{ |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
98 |
if ((device = alcOpenDevice("Generic Software")) == NULL) { |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
99 |
fprintf(stderr, "ERROR: Failed to open sound device\n"); |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
100 |
return AL_FALSE; |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
101 |
} |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
102 |
} |
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
103 |
fprintf(stderr, "Using default device: %s\n", alcGetString(device, ALC_DEVICE_SPECIFIER)); |
2259 | 104 |
|
105 |
context = alcCreateContext(device, NULL); |
|
106 |
alcMakeContextCurrent(context); |
|
107 |
alcProcessContext(context); |
|
108 |
||
109 |
if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE) |
|
110 |
return AL_FALSE; |
|
111 |
||
112 |
/*allocate memory space for buffers and sources*/ |
|
2326
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
113 |
if (memorysize == 0) |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
114 |
globalsize = 50; |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
115 |
else |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
116 |
globalsize = memorysize; |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
117 |
increment = globalsize; |
2259 | 118 |
Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
119 |
Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
|
120 |
||
121 |
/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ |
|
122 |
alListenerf (AL_GAIN, 1.0f ); |
|
123 |
alListenerfv(AL_POSITION, ListenerPos); |
|
124 |
alListenerfv(AL_VELOCITY, ListenerVel); |
|
125 |
alListenerfv(AL_ORIENTATION, ListenerOri); |
|
126 |
||
127 |
if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE) |
|
128 |
return AL_FALSE; |
|
129 |
||
130 |
openalReady = AL_TRUE; |
|
131 |
||
132 |
alGetError(); /* clear any AL errors beforehand */ |
|
133 |
return AL_TRUE; |
|
134 |
} |
|
135 |
||
136 |
||
137 |
ALboolean helper_realloc (void) { |
|
138 |
/*expands allocated memory when loading more sound files than expected*/ |
|
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
139 |
int oldsize = globalsize; |
2259 | 140 |
globalsize += increment; |
2191 | 141 |
|
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
142 |
#ifdef DEBUG |
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
143 |
fprintf(stderr, "OpenAL: Realloc in process from %d to %d\n", oldsize, globalsize); |
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
144 |
#endif |
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
145 |
|
2259 | 146 |
Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
147 |
Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
|
148 |
||
149 |
return AL_TRUE; |
|
150 |
} |
|
151 |
||
152 |
||
153 |
ALint openal_loadfile (const char *filename){ |
|
154 |
/*Open a file, load into memory and allocate the Source buffer for playing*/ |
|
155 |
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
|
156 |
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
|
157 |
ALenum format; |
|
158 |
ALsizei bitsize, freq; |
|
159 |
char *data; |
|
160 |
uint32_t fileformat; |
|
161 |
ALenum error; |
|
162 |
FILE *fp; |
|
163 |
||
164 |
if(openalReady == AL_FALSE) { |
|
165 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
166 |
return AL_FALSE; |
|
167 |
} |
|
168 |
||
169 |
/*when the buffers are all used, we can expand memory to accept new files*/ |
|
170 |
if (globalindex == globalsize) |
|
171 |
helper_realloc(); |
|
172 |
||
173 |
/*detect the file format, as written in the first 4 bytes of the header*/ |
|
174 |
fp = Fopen (filename, "rb"); |
|
175 |
if (fp == NULL) |
|
176 |
return -1; |
|
177 |
error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
|
178 |
fclose (fp); |
|
179 |
||
180 |
if (error < 0) { |
|
181 |
fprintf(stderr, "ERROR: file %s is too short \n", filename); |
|
182 |
return -2; |
|
183 |
} |
|
184 |
||
185 |
/*prepare the buffer to receive data*/ |
|
186 |
alGenBuffers(1, &Buffers[globalindex]); |
|
187 |
||
188 |
if (AlGetError("ERROR %d: Allocating memory for buffers\n") != AL_TRUE) |
|
189 |
return -3; |
|
190 |
||
191 |
/*prepare the source to emit sound*/ |
|
192 |
alGenSources(1, &Sources[globalindex]); |
|
193 |
||
194 |
if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE) |
|
195 |
return -4; |
|
196 |
||
197 |
||
198 |
if (fileformat == 0x5367674F) /*check if ogg*/ |
|
199 |
error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
|
200 |
else { |
|
201 |
if (fileformat == 0x46464952) /*check if wav*/ |
|
202 |
error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
|
203 |
else { |
|
204 |
fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat)); |
|
205 |
return -5; |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
/*copy pcm data in one buffer*/ |
|
210 |
alBufferData(Buffers[globalindex], format, data, bitsize, freq); |
|
211 |
free(data); /*deallocate data to save memory*/ |
|
212 |
||
213 |
if (AlGetError("ERROR %d: Writing data to buffer\n") != AL_TRUE) |
|
214 |
return -6; |
|
215 |
||
216 |
/*set source properties that it will use when it's in playback*/ |
|
217 |
alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); |
|
218 |
alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); |
|
219 |
alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); |
|
220 |
alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); |
|
221 |
alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); |
|
222 |
alSourcei (Sources[globalindex], AL_LOOPING, 0 ); |
|
223 |
||
224 |
if (AlGetError("ERROR %d: Setting source properties\n") != AL_TRUE) |
|
225 |
return -7; |
|
226 |
||
227 |
alGetError(); /* clear any AL errors beforehand */ |
|
228 |
||
229 |
/*returns the index of the source you just loaded, increments it and exits*/ |
|
230 |
return globalindex++; |
|
231 |
} |
|
232 |
||
233 |
||
234 |
ALboolean openal_toggleloop (uint32_t index){ |
|
235 |
/*Set or unset looping mode*/ |
|
236 |
ALint loop; |
|
237 |
||
238 |
if(openalReady == AL_FALSE) { |
|
239 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
240 |
return AL_FALSE; |
|
241 |
} |
|
242 |
||
243 |
if (index >= globalsize) { |
|
244 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
|
245 |
return AL_FALSE; |
|
246 |
} |
|
247 |
||
248 |
alGetSourcei (Sources[index], AL_LOOPING, &loop); |
|
249 |
alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
|
250 |
if (AlGetError("ERROR %d: Getting or setting loop property\n") != AL_TRUE) |
|
251 |
return AL_FALSE; |
|
252 |
||
253 |
alGetError(); /* clear any AL errors beforehand */ |
|
254 |
||
255 |
return AL_TRUE; |
|
256 |
} |
|
257 |
||
258 |
||
259 |
ALboolean openal_setvolume (uint32_t index, uint8_t percentage) { |
|
260 |
if(openalReady == AL_FALSE) { |
|
261 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
262 |
return AL_FALSE; |
|
263 |
} |
|
264 |
||
265 |
/*Set volume for sound number index*/ |
|
266 |
if (index >= globalindex) { |
|
267 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
|
268 |
return AL_FALSE; |
|
269 |
} |
|
270 |
||
271 |
if (percentage > 100) |
|
272 |
percentage = 100; |
|
273 |
alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f); |
|
274 |
if (AlGetError2("ERROR %d: setting volume for sound %d\n", index) != AL_TRUE) |
|
275 |
return AL_FALSE; |
|
276 |
||
277 |
alGetError(); /* clear any AL errors beforehand */ |
|
278 |
||
279 |
return AL_TRUE; |
|
280 |
} |
|
281 |
||
282 |
||
283 |
ALboolean openal_setglobalvolume (uint8_t percentage) { |
|
284 |
if(openalReady == AL_FALSE) { |
|
285 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
286 |
return AL_FALSE; |
|
287 |
} |
|
288 |
||
289 |
/*Set volume for all sounds*/ |
|
290 |
if (percentage > 100) |
|
291 |
percentage = 100; |
|
292 |
alListenerf (AL_GAIN, (float) percentage/100.0f); |
|
293 |
if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE) |
|
294 |
return AL_FALSE; |
|
295 |
||
296 |
alGetError(); /* clear any AL errors beforehand */ |
|
297 |
||
298 |
return AL_TRUE; |
|
299 |
} |
|
300 |
||
301 |
||
302 |
ALboolean openal_togglemute () { |
|
303 |
/*Mute or unmute sound*/ |
|
304 |
ALfloat mute; |
|
305 |
||
306 |
if(openalReady == AL_FALSE) { |
|
307 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
308 |
return AL_FALSE; |
|
309 |
} |
|
310 |
||
311 |
alGetListenerf (AL_GAIN, &mute); |
|
312 |
if (mute > 0) |
|
313 |
mute = 0; |
|
314 |
else |
|
315 |
mute = 1.0; |
|
316 |
alListenerf (AL_GAIN, mute); |
|
317 |
if (AlGetError("ERROR %d: Setting mute property\n") != AL_TRUE) |
|
318 |
return AL_FALSE; |
|
319 |
||
320 |
alGetError(); /* clear any AL errors beforehand */ |
|
321 |
||
322 |
return AL_TRUE; |
|
323 |
} |
|
324 |
||
325 |
||
2261 | 326 |
ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) { |
2259 | 327 |
/*Fade in or out by calling a helper thread*/ |
2194
1597710c6118
koda adds threading for fadein/out. Untested under windows, but works beautifully under Linux (and presumably OSX, right koda?)
nemo
parents:
2191
diff
changeset
|
328 |
#ifndef _WIN32 |
2259 | 329 |
pthread_t thread; |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
330 |
#else |
2259 | 331 |
HANDLE Thread; |
332 |
DWORD threadID; |
|
333 |
#endif |
|
334 |
fade_t *fade; |
|
335 |
||
336 |
if(openalReady == AL_FALSE) { |
|
337 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
338 |
return AL_FALSE; |
|
339 |
} |
|
340 |
||
341 |
fade = (fade_t*) Malloc(sizeof(fade_t)); |
|
342 |
fade->index = index; |
|
343 |
fade->quantity = quantity; |
|
344 |
||
345 |
if (index >= globalindex) { |
|
346 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
|
347 |
return AL_FALSE; |
|
348 |
} |
|
349 |
||
350 |
if (direction == FADE_IN) |
|
351 |
#ifndef _WIN32 |
|
352 |
pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
|
353 |
#else |
|
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
354 |
Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
2259 | 355 |
#endif |
356 |
else { |
|
357 |
if (direction == FADE_OUT) |
|
358 |
#ifndef _WIN32 |
|
359 |
pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
|
360 |
#else |
|
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
361 |
Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
362 |
#endif |
2259 | 363 |
else { |
364 |
fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction); |
|
365 |
free(fade); |
|
366 |
return AL_FALSE; |
|
367 |
} |
|
368 |
} |
|
369 |
||
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
370 |
#ifndef _WIN32 |
2259 | 371 |
pthread_detach(thread); |
2191 | 372 |
#endif |
2259 | 373 |
|
374 |
alGetError(); /* clear any AL errors beforehand */ |
|
375 |
||
376 |
return AL_TRUE; |
|
377 |
} |
|
378 |
||
379 |
||
380 |
ALboolean openal_fadeout (uint32_t index, uint16_t quantity) { |
|
381 |
/*wrapper for fadeout*/ |
|
382 |
return openal_fade(index, quantity, FADE_OUT); |
|
383 |
} |
|
384 |
||
385 |
||
386 |
ALboolean openal_fadein (uint32_t index, uint16_t quantity) { |
|
387 |
/*wrapper for fadein*/ |
|
388 |
return openal_fade(index, quantity, FADE_IN); |
|
389 |
} |
|
390 |
||
391 |
||
392 |
ALboolean openal_setposition (uint32_t index, float x, float y, float z) { |
|
393 |
if(openalReady == AL_FALSE) { |
|
394 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
395 |
return AL_FALSE; |
|
396 |
} |
|
397 |
if (index >= globalindex) { |
|
398 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
|
399 |
return AL_FALSE; |
|
400 |
} |
|
401 |
||
402 |
alSource3f(Sources[index], AL_POSITION, x, y, z); |
|
403 |
if (AlGetError2("ERROR %d: setting position for sound %d\n", index) != AL_TRUE) |
|
404 |
return AL_FALSE; |
|
405 |
||
406 |
return AL_TRUE; |
|
407 |
} |
|
408 |
||
409 |
||
410 |
ALboolean openal_playsound (uint32_t index){ |
|
411 |
if(openalReady == AL_FALSE) { |
|
412 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
413 |
return AL_FALSE; |
|
414 |
} |
|
415 |
||
416 |
/*Play sound number index*/ |
|
417 |
if (index >= globalindex) { |
|
418 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
|
419 |
return AL_FALSE; |
|
420 |
} |
|
421 |
alSourcePlay(Sources[index]); |
|
422 |
if (AlGetError2("ERROR %d: Playing sound %d\n", index) != AL_TRUE) |
|
423 |
return AL_FALSE; |
|
424 |
||
425 |
alGetError(); /* clear any AL errors beforehand */ |
|
426 |
||
427 |
return AL_TRUE; |
|
428 |
} |
|
429 |
||
430 |
||
431 |
ALboolean openal_pausesound(uint32_t index){ |
|
432 |
if(openalReady == AL_FALSE) { |
|
433 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
434 |
return AL_FALSE; |
|
435 |
} |
|
436 |
||
437 |
/*Pause sound number index*/ |
|
438 |
if (index >= globalindex) { |
|
439 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
|
440 |
return AL_FALSE; |
|
441 |
} |
|
442 |
alSourcePause(Sources[index]); |
|
443 |
if (AlGetError2("ERROR %d: Pausing sound %d\n", index) != AL_TRUE) |
|
444 |
return AL_FALSE; |
|
445 |
||
446 |
return AL_TRUE; |
|
447 |
} |
|
448 |
||
449 |
||
450 |
ALboolean openal_stopsound(uint32_t index){ |
|
451 |
if(openalReady == AL_FALSE) { |
|
452 |
fprintf(stderr, "ERROR: OpenAL not initialized\n"); |
|
453 |
return AL_FALSE; |
|
454 |
} |
|
455 |
||
456 |
/*Stop sound number index*/ |
|
457 |
if (index >= globalindex) { |
|
458 |
fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex); |
|
459 |
return AL_FALSE; |
|
460 |
} |
|
461 |
alSourceStop(Sources[index]); |
|
462 |
if (AlGetError2("ERROR %d: Stopping sound %d\n", index) != AL_TRUE) |
|
463 |
return AL_FALSE; |
|
464 |
||
465 |
alGetError(); /* clear any AL errors beforehand */ |
|
466 |
||
467 |
return AL_TRUE; |
|
468 |
} |
|
469 |
||
2191 | 470 |
#ifdef __CPLUSPLUS |
471 |
} |
|
472 |
#endif |