author | koda |
Sun, 11 Oct 2009 20:14:55 +0000 | |
changeset 2418 | 538a777f90c4 |
parent 2415 | 35d09cbf819a |
child 2419 | dbaaba09146d |
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" |
2418 | 20 |
|
2191 | 21 |
|
22 |
#ifdef __CPLUSPLUS |
|
23 |
extern "C" { |
|
24 |
#endif |
|
2259 | 25 |
|
26 |
/*Sources are points emitting sound*/ |
|
27 |
ALuint *Sources; |
|
28 |
/*Buffers hold sound data*/ |
|
29 |
ALuint *Buffers; |
|
30 |
/*index for Sources and Buffers*/ |
|
31 |
ALuint globalindex, globalsize, increment; |
|
32 |
||
33 |
ALboolean openalReady = AL_FALSE; |
|
34 |
||
35 |
ALboolean openal_close (void) { |
|
2418 | 36 |
/*Stop all sounds, deallocate all memory and close OpenAL */ |
37 |
ALCcontext *context; |
|
38 |
ALCdevice *device; |
|
39 |
||
40 |
if (openalReady == AL_FALSE) { |
|
41 |
errno = EPERM; |
|
42 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
43 |
return AL_FALSE; |
|
44 |
} |
|
45 |
||
2259 | 46 |
alSourceStopv (globalsize, Sources); |
47 |
alDeleteSources (globalsize, Sources); |
|
48 |
alDeleteBuffers (globalsize, Buffers); |
|
49 |
||
50 |
free(Sources); |
|
51 |
free(Buffers); |
|
52 |
||
53 |
context = alcGetCurrentContext(); |
|
54 |
device = alcGetContextsDevice(context); |
|
55 |
||
56 |
alcMakeContextCurrent(NULL); |
|
57 |
alcDestroyContext(context); |
|
58 |
alcCloseDevice(device); |
|
59 |
||
60 |
openalReady = AL_FALSE; |
|
61 |
||
62 |
return AL_TRUE; |
|
63 |
} |
|
64 |
||
65 |
ALboolean openal_ready(void) { |
|
66 |
return openalReady; |
|
67 |
} |
|
68 |
||
2418 | 69 |
ALboolean openal_init(char* programname, ALboolean usehardware, uint32_t memorysize) { |
2259 | 70 |
/*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
71 |
ALCcontext *context; |
|
72 |
ALCdevice *device; |
|
73 |
const ALCchar *default_device; |
|
2418 | 74 |
|
75 |
prog = programname; |
|
76 |
||
77 |
||
2259 | 78 |
/*Position of the listener*/ |
79 |
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; |
|
80 |
/*Velocity of the listener*/ |
|
81 |
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 }; |
|
82 |
/*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/ |
|
83 |
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; |
|
84 |
||
2418 | 85 |
if (openalReady == AL_TRUE) { |
86 |
errno = EPERM; |
|
87 |
err_ret("(%s) WARN - OpenAL already initialized", prog); |
|
88 |
return AL_FALSE; |
|
89 |
} |
|
2392
a55dbef5cf31
Smaxx's patch fixing openal sound issues with poor card drivers
koda
parents:
2326
diff
changeset
|
90 |
|
2418 | 91 |
if (usehardware) |
92 |
device = alcOpenDevice(NULL); |
|
93 |
else |
|
94 |
device = alcOpenDevice("Generic Software"); |
|
95 |
||
96 |
if (device == NULL) { |
|
97 |
errno = ENODEV; |
|
98 |
err_ret("(%s) WARN - Failed to open sound device", prog); |
|
99 |
return AL_FALSE; |
|
100 |
} |
|
101 |
err_msg("(%s) INFO - output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); |
|
102 |
||
103 |
context = alcCreateContext(device, NULL); |
|
104 |
alcMakeContextCurrent(context); |
|
105 |
alcProcessContext(context); |
|
106 |
||
107 |
if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE) |
|
2259 | 108 |
return AL_FALSE; |
109 |
||
110 |
/*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
|
111 |
if (memorysize == 0) |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
112 |
globalsize = 50; |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
113 |
else |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
114 |
globalsize = memorysize; |
0ddf641fddee
rename dpr -> pas, restores ammos on two columns, minor fixes to openalbridge
koda
parents:
2261
diff
changeset
|
115 |
increment = globalsize; |
2415 | 116 |
|
2259 | 117 |
Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
118 |
Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
|
119 |
||
120 |
/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ |
|
121 |
alListenerf (AL_GAIN, 1.0f ); |
|
122 |
alListenerfv(AL_POSITION, ListenerPos); |
|
123 |
alListenerfv(AL_VELOCITY, ListenerVel); |
|
124 |
alListenerfv(AL_ORIENTATION, ListenerOri); |
|
125 |
||
2418 | 126 |
if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE) |
2259 | 127 |
return AL_FALSE; |
128 |
||
129 |
openalReady = AL_TRUE; |
|
130 |
||
131 |
alGetError(); /* clear any AL errors beforehand */ |
|
132 |
return AL_TRUE; |
|
133 |
} |
|
134 |
||
135 |
||
136 |
ALboolean helper_realloc (void) { |
|
137 |
/*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
|
138 |
int oldsize = globalsize; |
2259 | 139 |
globalsize += increment; |
2191 | 140 |
|
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
141 |
#ifdef DEBUG |
2418 | 142 |
err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); |
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
143 |
#endif |
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
144 |
|
2259 | 145 |
Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
146 |
Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
|
147 |
||
148 |
return AL_TRUE; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
ALint openal_loadfile (const char *filename){ |
|
153 |
/*Open a file, load into memory and allocate the Source buffer for playing*/ |
|
154 |
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
|
155 |
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
|
156 |
ALenum format; |
|
157 |
ALsizei bitsize, freq; |
|
158 |
char *data; |
|
159 |
uint32_t fileformat; |
|
160 |
ALenum error; |
|
161 |
FILE *fp; |
|
162 |
||
2418 | 163 |
if (openalReady == AL_FALSE) { |
164 |
errno = EPERM; |
|
165 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
166 |
return AL_FALSE; |
|
167 |
} |
|
2259 | 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"); |
|
2418 | 175 |
|
2259 | 176 |
if (fp == NULL) |
177 |
return -1; |
|
2418 | 178 |
|
2259 | 179 |
error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
180 |
fclose (fp); |
|
181 |
||
182 |
if (error < 0) { |
|
2418 | 183 |
errno = EIO; |
184 |
err_ret("(%s) ERROR - file %s is too short", prog, filename); |
|
185 |
return -2; |
|
2259 | 186 |
} |
187 |
||
188 |
/*prepare the buffer to receive data*/ |
|
189 |
alGenBuffers(1, &Buffers[globalindex]); |
|
190 |
||
2418 | 191 |
if (AlGetError("(%s) ERROR - allocating memory for buffers") != AL_TRUE) |
2259 | 192 |
return -3; |
193 |
||
194 |
/*prepare the source to emit sound*/ |
|
195 |
alGenSources(1, &Sources[globalindex]); |
|
196 |
||
2418 | 197 |
if (AlGetError("(%s) ERROR - allocating memory for sources") != AL_TRUE) |
2259 | 198 |
return -4; |
199 |
||
200 |
||
2415 | 201 |
switch (ENDIAN_BIG_32(fileformat)) { |
202 |
case OGG_FILE_FORMAT: |
|
203 |
error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
|
204 |
break; |
|
205 |
case WAV_FILE_FORMAT: |
|
206 |
error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
|
207 |
break; |
|
208 |
default: |
|
2418 | 209 |
errno = EINVAL; |
210 |
err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); |
|
2415 | 211 |
return -5; |
212 |
break; |
|
2259 | 213 |
} |
214 |
||
2415 | 215 |
|
2259 | 216 |
/*copy pcm data in one buffer*/ |
217 |
alBufferData(Buffers[globalindex], format, data, bitsize, freq); |
|
218 |
free(data); /*deallocate data to save memory*/ |
|
219 |
||
2418 | 220 |
if (AlGetError("(%s) ERROR - writing data to buffers") != AL_TRUE) |
2259 | 221 |
return -6; |
222 |
||
223 |
/*set source properties that it will use when it's in playback*/ |
|
224 |
alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); |
|
225 |
alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); |
|
226 |
alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); |
|
227 |
alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); |
|
228 |
alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); |
|
229 |
alSourcei (Sources[globalindex], AL_LOOPING, 0 ); |
|
230 |
||
2418 | 231 |
if (AlGetError("(%s) ERROR - setting Source properties") != AL_TRUE) |
2259 | 232 |
return -7; |
233 |
||
234 |
alGetError(); /* clear any AL errors beforehand */ |
|
235 |
||
236 |
/*returns the index of the source you just loaded, increments it and exits*/ |
|
237 |
return globalindex++; |
|
238 |
} |
|
239 |
||
240 |
||
241 |
ALboolean openal_toggleloop (uint32_t index){ |
|
242 |
/*Set or unset looping mode*/ |
|
243 |
ALint loop; |
|
244 |
||
2418 | 245 |
if (openalReady == AL_FALSE) { |
246 |
errno = EPERM; |
|
247 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
248 |
return AL_FALSE; |
|
249 |
} |
|
2259 | 250 |
|
251 |
if (index >= globalsize) { |
|
2418 | 252 |
errno = EINVAL; |
253 |
err_ret("(%s) ERROR - index out of bounds (got %d, max %d)", prog, index, globalindex); |
|
254 |
return AL_FALSE; |
|
2259 | 255 |
} |
256 |
||
257 |
alGetSourcei (Sources[index], AL_LOOPING, &loop); |
|
258 |
alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
|
2418 | 259 |
if (AlGetError("(%s) ERROR - getting or setting loop property") != AL_TRUE) |
2259 | 260 |
return AL_FALSE; |
261 |
||
262 |
alGetError(); /* clear any AL errors beforehand */ |
|
263 |
||
264 |
return AL_TRUE; |
|
265 |
} |
|
266 |
||
267 |
||
268 |
ALboolean openal_setvolume (uint32_t index, uint8_t percentage) { |
|
2418 | 269 |
if (openalReady == AL_FALSE) { |
270 |
errno = EPERM; |
|
271 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
272 |
return AL_FALSE; |
|
273 |
} |
|
2259 | 274 |
|
275 |
/*Set volume for sound number index*/ |
|
276 |
if (index >= globalindex) { |
|
2415 | 277 |
fprintf(stderr, "ERROR 'openal_setvolume()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 278 |
return AL_FALSE; |
279 |
} |
|
280 |
||
281 |
if (percentage > 100) |
|
282 |
percentage = 100; |
|
283 |
alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f); |
|
2415 | 284 |
if (AlGetError2("ERROR %d in 'openal_setvolume()': setting volume for sound %d\n", index) != AL_TRUE) |
2259 | 285 |
return AL_FALSE; |
286 |
||
287 |
alGetError(); /* clear any AL errors beforehand */ |
|
288 |
||
289 |
return AL_TRUE; |
|
290 |
} |
|
291 |
||
292 |
||
293 |
ALboolean openal_setglobalvolume (uint8_t percentage) { |
|
2418 | 294 |
if (openalReady == AL_FALSE) { |
295 |
errno = EPERM; |
|
296 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
297 |
return AL_FALSE; |
|
298 |
} |
|
2259 | 299 |
|
300 |
/*Set volume for all sounds*/ |
|
301 |
if (percentage > 100) |
|
302 |
percentage = 100; |
|
303 |
alListenerf (AL_GAIN, (float) percentage/100.0f); |
|
2415 | 304 |
if (AlGetError("ERROR %d in 'openal_setglobalvolume()': Setting global volume\n") != AL_TRUE) |
2259 | 305 |
return AL_FALSE; |
306 |
||
307 |
alGetError(); /* clear any AL errors beforehand */ |
|
308 |
||
309 |
return AL_TRUE; |
|
310 |
} |
|
311 |
||
312 |
||
313 |
ALboolean openal_togglemute () { |
|
314 |
/*Mute or unmute sound*/ |
|
315 |
ALfloat mute; |
|
316 |
||
2418 | 317 |
if (openalReady == AL_FALSE) { |
318 |
errno = EPERM; |
|
319 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
320 |
return AL_FALSE; |
|
321 |
} |
|
2259 | 322 |
|
323 |
alGetListenerf (AL_GAIN, &mute); |
|
324 |
if (mute > 0) |
|
325 |
mute = 0; |
|
326 |
else |
|
327 |
mute = 1.0; |
|
328 |
alListenerf (AL_GAIN, mute); |
|
2415 | 329 |
if (AlGetError("ERROR %d in 'openal_togglemute()': Setting mute property\n") != AL_TRUE) |
2259 | 330 |
return AL_FALSE; |
331 |
||
332 |
alGetError(); /* clear any AL errors beforehand */ |
|
333 |
||
334 |
return AL_TRUE; |
|
335 |
} |
|
336 |
||
337 |
||
2261 | 338 |
ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) { |
2259 | 339 |
/*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
|
340 |
#ifndef _WIN32 |
2259 | 341 |
pthread_t thread; |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
342 |
#else |
2259 | 343 |
HANDLE Thread; |
344 |
DWORD threadID; |
|
345 |
#endif |
|
346 |
fade_t *fade; |
|
347 |
||
2418 | 348 |
if (openalReady == AL_FALSE) { |
349 |
errno = EPERM; |
|
350 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
351 |
return AL_FALSE; |
|
352 |
} |
|
2259 | 353 |
|
354 |
fade = (fade_t*) Malloc(sizeof(fade_t)); |
|
355 |
fade->index = index; |
|
356 |
fade->quantity = quantity; |
|
357 |
||
358 |
if (index >= globalindex) { |
|
2415 | 359 |
fprintf(stderr, "ERROR 'openal_fade()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 360 |
return AL_FALSE; |
361 |
} |
|
2415 | 362 |
|
363 |
switch (direction) { |
|
364 |
case FADE_IN: |
|
2259 | 365 |
#ifndef _WIN32 |
2415 | 366 |
pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
2259 | 367 |
#else |
2415 | 368 |
Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
2259 | 369 |
#endif |
2415 | 370 |
break; |
371 |
case FADE_OUT: |
|
2259 | 372 |
#ifndef _WIN32 |
2415 | 373 |
pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
2259 | 374 |
#else |
2415 | 375 |
Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
376 |
#endif |
2415 | 377 |
break; |
378 |
default: |
|
379 |
fprintf(stderr, "ERROR 'openal_fade()': unknown direction for fade (%d)\n", direction); |
|
380 |
free(fade); |
|
381 |
return AL_FALSE; |
|
382 |
break; |
|
2259 | 383 |
} |
384 |
||
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
385 |
#ifndef _WIN32 |
2259 | 386 |
pthread_detach(thread); |
2191 | 387 |
#endif |
2259 | 388 |
|
389 |
alGetError(); /* clear any AL errors beforehand */ |
|
390 |
||
391 |
return AL_TRUE; |
|
392 |
} |
|
393 |
||
394 |
||
395 |
ALboolean openal_fadeout (uint32_t index, uint16_t quantity) { |
|
396 |
/*wrapper for fadeout*/ |
|
397 |
return openal_fade(index, quantity, FADE_OUT); |
|
398 |
} |
|
399 |
||
400 |
||
401 |
ALboolean openal_fadein (uint32_t index, uint16_t quantity) { |
|
402 |
/*wrapper for fadein*/ |
|
403 |
return openal_fade(index, quantity, FADE_IN); |
|
404 |
} |
|
405 |
||
406 |
||
407 |
ALboolean openal_setposition (uint32_t index, float x, float y, float z) { |
|
2418 | 408 |
if (openalReady == AL_FALSE) { |
409 |
errno = EPERM; |
|
410 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
411 |
return AL_FALSE; |
|
412 |
} |
|
2415 | 413 |
|
2259 | 414 |
if (index >= globalindex) { |
2415 | 415 |
fprintf(stderr, "ERROR 'openal_setposition()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 416 |
return AL_FALSE; |
417 |
} |
|
418 |
||
419 |
alSource3f(Sources[index], AL_POSITION, x, y, z); |
|
2415 | 420 |
if (AlGetError2("ERROR %d in 'openal_setposition()': setting position for sound %d\n", index) != AL_TRUE) |
2259 | 421 |
return AL_FALSE; |
422 |
||
423 |
return AL_TRUE; |
|
424 |
} |
|
425 |
||
426 |
||
427 |
ALboolean openal_playsound (uint32_t index){ |
|
2418 | 428 |
if (openalReady == AL_FALSE) { |
429 |
errno = EPERM; |
|
430 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
431 |
return AL_FALSE; |
|
432 |
} |
|
2259 | 433 |
|
434 |
/*Play sound number index*/ |
|
435 |
if (index >= globalindex) { |
|
2415 | 436 |
fprintf(stderr, "ERROR 'openal_playsound()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 437 |
return AL_FALSE; |
438 |
} |
|
439 |
alSourcePlay(Sources[index]); |
|
2415 | 440 |
if (AlGetError2("ERROR %d in 'openal_playsound()': Playing sound %d\n", index) != AL_TRUE) |
2259 | 441 |
return AL_FALSE; |
442 |
||
443 |
alGetError(); /* clear any AL errors beforehand */ |
|
444 |
||
445 |
return AL_TRUE; |
|
446 |
} |
|
447 |
||
448 |
||
449 |
ALboolean openal_pausesound(uint32_t index){ |
|
2418 | 450 |
if (openalReady == AL_FALSE) { |
451 |
errno = EPERM; |
|
452 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
453 |
return AL_FALSE; |
|
454 |
} |
|
2259 | 455 |
|
456 |
/*Pause sound number index*/ |
|
457 |
if (index >= globalindex) { |
|
2415 | 458 |
fprintf(stderr, "ERROR 'openal_pausesound()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 459 |
return AL_FALSE; |
460 |
} |
|
461 |
alSourcePause(Sources[index]); |
|
2415 | 462 |
if (AlGetError2("ERROR %d in 'openal_pausesound()': Pausing sound %d\n", index) != AL_TRUE) |
2259 | 463 |
return AL_FALSE; |
464 |
||
465 |
return AL_TRUE; |
|
466 |
} |
|
467 |
||
468 |
||
469 |
ALboolean openal_stopsound(uint32_t index){ |
|
2418 | 470 |
if (openalReady == AL_FALSE) { |
471 |
errno = EPERM; |
|
472 |
err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
473 |
return AL_FALSE; |
|
474 |
} |
|
2259 | 475 |
|
476 |
/*Stop sound number index*/ |
|
477 |
if (index >= globalindex) { |
|
2415 | 478 |
fprintf(stderr, "ERROR 'openal_stopsound()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 479 |
return AL_FALSE; |
480 |
} |
|
481 |
alSourceStop(Sources[index]); |
|
2415 | 482 |
if (AlGetError2("ERROR %d in 'openal_stopsound()': Stopping sound %d\n", index) != AL_TRUE) |
2259 | 483 |
return AL_FALSE; |
484 |
||
485 |
alGetError(); /* clear any AL errors beforehand */ |
|
486 |
||
487 |
return AL_TRUE; |
|
488 |
} |
|
489 |
||
2191 | 490 |
#ifdef __CPLUSPLUS |
491 |
} |
|
492 |
#endif |