author | koda |
Sun, 11 Oct 2009 16:03:56 +0000 | |
changeset 2415 | 35d09cbf819a |
parent 2392 | a55dbef5cf31 |
child 2418 | 538a777f90c4 |
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) { |
|
2415 | 85 |
fprintf(stderr, "ERROR 'openal_init()': OpenAL already initialized\n"); |
2259 | 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) { |
2415 | 92 |
fprintf(stderr, "ERROR 'openal_init()': Failed to open sound device\n"); |
2392
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) { |
2415 | 99 |
fprintf(stderr, "ERROR 'openal_init()': Failed to open sound device\n"); |
2392
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 |
||
2415 | 109 |
if (AlGetError("ERROR %d in 'openal_init()': Creating a new contex\n") != AL_TRUE) |
2259 | 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; |
2415 | 118 |
|
2259 | 119 |
Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
120 |
Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
|
121 |
||
122 |
/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ |
|
123 |
alListenerf (AL_GAIN, 1.0f ); |
|
124 |
alListenerfv(AL_POSITION, ListenerPos); |
|
125 |
alListenerfv(AL_VELOCITY, ListenerVel); |
|
126 |
alListenerfv(AL_ORIENTATION, ListenerOri); |
|
127 |
||
128 |
if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE) |
|
129 |
return AL_FALSE; |
|
130 |
||
131 |
openalReady = AL_TRUE; |
|
132 |
||
133 |
alGetError(); /* clear any AL errors beforehand */ |
|
134 |
return AL_TRUE; |
|
135 |
} |
|
136 |
||
137 |
||
138 |
ALboolean helper_realloc (void) { |
|
139 |
/*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
|
140 |
int oldsize = globalsize; |
2259 | 141 |
globalsize += increment; |
2191 | 142 |
|
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
143 |
#ifdef DEBUG |
2415 | 144 |
fprintf(stderr, "OpenALBridge: Realloc in process from %d to %d\n", oldsize, globalsize); |
2260
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
145 |
#endif |
31756e21c436
other indentation, binding and miscellaneous fixes to openalbridge
koda
parents:
2259
diff
changeset
|
146 |
|
2259 | 147 |
Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
148 |
Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
|
149 |
||
150 |
return AL_TRUE; |
|
151 |
} |
|
152 |
||
153 |
||
154 |
ALint openal_loadfile (const char *filename){ |
|
155 |
/*Open a file, load into memory and allocate the Source buffer for playing*/ |
|
156 |
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
|
157 |
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
|
158 |
ALenum format; |
|
159 |
ALsizei bitsize, freq; |
|
160 |
char *data; |
|
161 |
uint32_t fileformat; |
|
162 |
ALenum error; |
|
163 |
FILE *fp; |
|
164 |
||
165 |
if(openalReady == AL_FALSE) { |
|
2415 | 166 |
fprintf(stderr, "ERROR 'openal_loadfile()': OpenAL not initialized\n"); |
2259 | 167 |
return AL_FALSE; |
168 |
} |
|
169 |
||
170 |
/*when the buffers are all used, we can expand memory to accept new files*/ |
|
171 |
if (globalindex == globalsize) |
|
172 |
helper_realloc(); |
|
173 |
||
174 |
/*detect the file format, as written in the first 4 bytes of the header*/ |
|
175 |
fp = Fopen (filename, "rb"); |
|
176 |
if (fp == NULL) |
|
177 |
return -1; |
|
178 |
error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
|
179 |
fclose (fp); |
|
180 |
||
181 |
if (error < 0) { |
|
2415 | 182 |
fprintf(stderr, "ERROR 'openal_loadfile()': file %s is too short \n", filename); |
2259 | 183 |
return -2; |
184 |
} |
|
185 |
||
186 |
/*prepare the buffer to receive data*/ |
|
187 |
alGenBuffers(1, &Buffers[globalindex]); |
|
188 |
||
2415 | 189 |
if (AlGetError("ERROR %d in 'openal_loadfile()': Allocating memory for buffers\n") != AL_TRUE) |
2259 | 190 |
return -3; |
191 |
||
192 |
/*prepare the source to emit sound*/ |
|
193 |
alGenSources(1, &Sources[globalindex]); |
|
194 |
||
2415 | 195 |
if (AlGetError("ERROR %d in 'openal_loadfile()': Allocating memory for sources\n") != AL_TRUE) |
2259 | 196 |
return -4; |
197 |
||
198 |
||
2415 | 199 |
switch (ENDIAN_BIG_32(fileformat)) { |
200 |
case OGG_FILE_FORMAT: |
|
201 |
error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
|
202 |
break; |
|
203 |
case WAV_FILE_FORMAT: |
|
204 |
error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
|
205 |
break; |
|
206 |
default: |
|
207 |
fprintf(stderr, "ERROR 'openal_loadfile()': File format (%08X) not supported!\n", ENDIAN_BIG_32(fileformat)); |
|
208 |
return -5; |
|
209 |
break; |
|
2259 | 210 |
} |
211 |
||
2415 | 212 |
|
2259 | 213 |
/*copy pcm data in one buffer*/ |
214 |
alBufferData(Buffers[globalindex], format, data, bitsize, freq); |
|
215 |
free(data); /*deallocate data to save memory*/ |
|
216 |
||
2415 | 217 |
if (AlGetError("ERROR %d in 'openal_loadfile()': Writing data to buffer\n") != AL_TRUE) |
2259 | 218 |
return -6; |
219 |
||
220 |
/*set source properties that it will use when it's in playback*/ |
|
221 |
alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); |
|
222 |
alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); |
|
223 |
alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); |
|
224 |
alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); |
|
225 |
alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); |
|
226 |
alSourcei (Sources[globalindex], AL_LOOPING, 0 ); |
|
227 |
||
2415 | 228 |
if (AlGetError("ERROR %d in 'openal_loadfile()': Setting source properties\n") != AL_TRUE) |
2259 | 229 |
return -7; |
230 |
||
231 |
alGetError(); /* clear any AL errors beforehand */ |
|
232 |
||
233 |
/*returns the index of the source you just loaded, increments it and exits*/ |
|
234 |
return globalindex++; |
|
235 |
} |
|
236 |
||
237 |
||
238 |
ALboolean openal_toggleloop (uint32_t index){ |
|
239 |
/*Set or unset looping mode*/ |
|
240 |
ALint loop; |
|
241 |
||
242 |
if(openalReady == AL_FALSE) { |
|
2415 | 243 |
fprintf(stderr, "ERROR 'openal_toggleloop()': OpenAL not initialized\n"); |
2259 | 244 |
return AL_FALSE; |
245 |
} |
|
246 |
||
247 |
if (index >= globalsize) { |
|
2415 | 248 |
fprintf(stderr, "ERROR 'openal_toggleloop()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 249 |
return AL_FALSE; |
250 |
} |
|
251 |
||
252 |
alGetSourcei (Sources[index], AL_LOOPING, &loop); |
|
253 |
alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
|
2415 | 254 |
if (AlGetError("ERROR %d in 'openal_toggleloop()': Getting or setting loop property\n") != AL_TRUE) |
2259 | 255 |
return AL_FALSE; |
256 |
||
257 |
alGetError(); /* clear any AL errors beforehand */ |
|
258 |
||
259 |
return AL_TRUE; |
|
260 |
} |
|
261 |
||
262 |
||
263 |
ALboolean openal_setvolume (uint32_t index, uint8_t percentage) { |
|
264 |
if(openalReady == AL_FALSE) { |
|
2415 | 265 |
fprintf(stderr, "ERROR 'openal_setvolume()': OpenAL not initialized\n"); |
2259 | 266 |
return AL_FALSE; |
267 |
} |
|
268 |
||
269 |
/*Set volume for sound number index*/ |
|
270 |
if (index >= globalindex) { |
|
2415 | 271 |
fprintf(stderr, "ERROR 'openal_setvolume()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 272 |
return AL_FALSE; |
273 |
} |
|
274 |
||
275 |
if (percentage > 100) |
|
276 |
percentage = 100; |
|
277 |
alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f); |
|
2415 | 278 |
if (AlGetError2("ERROR %d in 'openal_setvolume()': setting volume for sound %d\n", index) != AL_TRUE) |
2259 | 279 |
return AL_FALSE; |
280 |
||
281 |
alGetError(); /* clear any AL errors beforehand */ |
|
282 |
||
283 |
return AL_TRUE; |
|
284 |
} |
|
285 |
||
286 |
||
287 |
ALboolean openal_setglobalvolume (uint8_t percentage) { |
|
288 |
if(openalReady == AL_FALSE) { |
|
2415 | 289 |
fprintf(stderr, "ERROR 'openal_setglobalvolume()': OpenAL not initialized\n"); |
2259 | 290 |
return AL_FALSE; |
291 |
} |
|
292 |
||
293 |
/*Set volume for all sounds*/ |
|
294 |
if (percentage > 100) |
|
295 |
percentage = 100; |
|
296 |
alListenerf (AL_GAIN, (float) percentage/100.0f); |
|
2415 | 297 |
if (AlGetError("ERROR %d in 'openal_setglobalvolume()': Setting global volume\n") != AL_TRUE) |
2259 | 298 |
return AL_FALSE; |
299 |
||
300 |
alGetError(); /* clear any AL errors beforehand */ |
|
301 |
||
302 |
return AL_TRUE; |
|
303 |
} |
|
304 |
||
305 |
||
306 |
ALboolean openal_togglemute () { |
|
307 |
/*Mute or unmute sound*/ |
|
308 |
ALfloat mute; |
|
309 |
||
310 |
if(openalReady == AL_FALSE) { |
|
2415 | 311 |
fprintf(stderr, "ERROR 'openal_togglemute()': OpenAL not initialized\n"); |
2259 | 312 |
return AL_FALSE; |
313 |
} |
|
314 |
||
315 |
alGetListenerf (AL_GAIN, &mute); |
|
316 |
if (mute > 0) |
|
317 |
mute = 0; |
|
318 |
else |
|
319 |
mute = 1.0; |
|
320 |
alListenerf (AL_GAIN, mute); |
|
2415 | 321 |
if (AlGetError("ERROR %d in 'openal_togglemute()': Setting mute property\n") != AL_TRUE) |
2259 | 322 |
return AL_FALSE; |
323 |
||
324 |
alGetError(); /* clear any AL errors beforehand */ |
|
325 |
||
326 |
return AL_TRUE; |
|
327 |
} |
|
328 |
||
329 |
||
2261 | 330 |
ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) { |
2259 | 331 |
/*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
|
332 |
#ifndef _WIN32 |
2259 | 333 |
pthread_t thread; |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
334 |
#else |
2259 | 335 |
HANDLE Thread; |
336 |
DWORD threadID; |
|
337 |
#endif |
|
338 |
fade_t *fade; |
|
339 |
||
340 |
if(openalReady == AL_FALSE) { |
|
2415 | 341 |
fprintf(stderr, "ERROR 'openal_fade()': OpenAL not initialized\n"); |
2259 | 342 |
return AL_FALSE; |
343 |
} |
|
344 |
||
345 |
fade = (fade_t*) Malloc(sizeof(fade_t)); |
|
346 |
fade->index = index; |
|
347 |
fade->quantity = quantity; |
|
348 |
||
349 |
if (index >= globalindex) { |
|
2415 | 350 |
fprintf(stderr, "ERROR 'openal_fade()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 351 |
return AL_FALSE; |
352 |
} |
|
2415 | 353 |
|
354 |
switch (direction) { |
|
355 |
case FADE_IN: |
|
2259 | 356 |
#ifndef _WIN32 |
2415 | 357 |
pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
2259 | 358 |
#else |
2415 | 359 |
Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
2259 | 360 |
#endif |
2415 | 361 |
break; |
362 |
case FADE_OUT: |
|
2259 | 363 |
#ifndef _WIN32 |
2415 | 364 |
pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
2259 | 365 |
#else |
2415 | 366 |
Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
367 |
#endif |
2415 | 368 |
break; |
369 |
default: |
|
370 |
fprintf(stderr, "ERROR 'openal_fade()': unknown direction for fade (%d)\n", direction); |
|
371 |
free(fade); |
|
372 |
return AL_FALSE; |
|
373 |
break; |
|
2259 | 374 |
} |
375 |
||
2211
288360b78f30
- fade in/out functions merged, but kept binary compatibility
koda
parents:
2210
diff
changeset
|
376 |
#ifndef _WIN32 |
2259 | 377 |
pthread_detach(thread); |
2191 | 378 |
#endif |
2259 | 379 |
|
380 |
alGetError(); /* clear any AL errors beforehand */ |
|
381 |
||
382 |
return AL_TRUE; |
|
383 |
} |
|
384 |
||
385 |
||
386 |
ALboolean openal_fadeout (uint32_t index, uint16_t quantity) { |
|
387 |
/*wrapper for fadeout*/ |
|
388 |
return openal_fade(index, quantity, FADE_OUT); |
|
389 |
} |
|
390 |
||
391 |
||
392 |
ALboolean openal_fadein (uint32_t index, uint16_t quantity) { |
|
393 |
/*wrapper for fadein*/ |
|
394 |
return openal_fade(index, quantity, FADE_IN); |
|
395 |
} |
|
396 |
||
397 |
||
398 |
ALboolean openal_setposition (uint32_t index, float x, float y, float z) { |
|
399 |
if(openalReady == AL_FALSE) { |
|
2415 | 400 |
fprintf(stderr, "ERROR 'openal_setposition()': OpenAL not initialized\n"); |
2259 | 401 |
return AL_FALSE; |
402 |
} |
|
2415 | 403 |
|
2259 | 404 |
if (index >= globalindex) { |
2415 | 405 |
fprintf(stderr, "ERROR 'openal_setposition()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 406 |
return AL_FALSE; |
407 |
} |
|
408 |
||
409 |
alSource3f(Sources[index], AL_POSITION, x, y, z); |
|
2415 | 410 |
if (AlGetError2("ERROR %d in 'openal_setposition()': setting position for sound %d\n", index) != AL_TRUE) |
2259 | 411 |
return AL_FALSE; |
412 |
||
413 |
return AL_TRUE; |
|
414 |
} |
|
415 |
||
416 |
||
417 |
ALboolean openal_playsound (uint32_t index){ |
|
418 |
if(openalReady == AL_FALSE) { |
|
2415 | 419 |
fprintf(stderr, "ERROR 'openal_playsound()': OpenAL not initialized\n"); |
2259 | 420 |
return AL_FALSE; |
421 |
} |
|
422 |
||
423 |
/*Play sound number index*/ |
|
424 |
if (index >= globalindex) { |
|
2415 | 425 |
fprintf(stderr, "ERROR 'openal_playsound()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 426 |
return AL_FALSE; |
427 |
} |
|
428 |
alSourcePlay(Sources[index]); |
|
2415 | 429 |
if (AlGetError2("ERROR %d in 'openal_playsound()': Playing sound %d\n", index) != AL_TRUE) |
2259 | 430 |
return AL_FALSE; |
431 |
||
432 |
alGetError(); /* clear any AL errors beforehand */ |
|
433 |
||
434 |
return AL_TRUE; |
|
435 |
} |
|
436 |
||
437 |
||
438 |
ALboolean openal_pausesound(uint32_t index){ |
|
439 |
if(openalReady == AL_FALSE) { |
|
2415 | 440 |
fprintf(stderr, "ERROR 'openal_pausesound()': OpenAL not initialized\n"); |
2259 | 441 |
return AL_FALSE; |
442 |
} |
|
443 |
||
444 |
/*Pause sound number index*/ |
|
445 |
if (index >= globalindex) { |
|
2415 | 446 |
fprintf(stderr, "ERROR 'openal_pausesound()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 447 |
return AL_FALSE; |
448 |
} |
|
449 |
alSourcePause(Sources[index]); |
|
2415 | 450 |
if (AlGetError2("ERROR %d in 'openal_pausesound()': Pausing sound %d\n", index) != AL_TRUE) |
2259 | 451 |
return AL_FALSE; |
452 |
||
453 |
return AL_TRUE; |
|
454 |
} |
|
455 |
||
456 |
||
457 |
ALboolean openal_stopsound(uint32_t index){ |
|
458 |
if(openalReady == AL_FALSE) { |
|
2415 | 459 |
fprintf(stderr, "ERROR 'openal_stopsound()': OpenAL not initialized\n"); |
2259 | 460 |
return AL_FALSE; |
461 |
} |
|
462 |
||
463 |
/*Stop sound number index*/ |
|
464 |
if (index >= globalindex) { |
|
2415 | 465 |
fprintf(stderr, "ERROR 'openal_stopsound()': index out of bounds (got %d, max %d)\n", index, globalindex); |
2259 | 466 |
return AL_FALSE; |
467 |
} |
|
468 |
alSourceStop(Sources[index]); |
|
2415 | 469 |
if (AlGetError2("ERROR %d in 'openal_stopsound()': Stopping sound %d\n", index) != AL_TRUE) |
2259 | 470 |
return AL_FALSE; |
471 |
||
472 |
alGetError(); /* clear any AL errors beforehand */ |
|
473 |
||
474 |
return AL_TRUE; |
|
475 |
} |
|
476 |
||
2191 | 477 |
#ifdef __CPLUSPLUS |
478 |
} |
|
479 |
#endif |