32 ALuint *Buffers; |
32 ALuint *Buffers; |
33 /*index for Sources and Buffers*/ |
33 /*index for Sources and Buffers*/ |
34 ALuint globalindex, globalsize, increment; |
34 ALuint globalindex, globalsize, increment; |
35 |
35 |
36 ALboolean openalReady = AL_FALSE; |
36 ALboolean openalReady = AL_FALSE; |
37 |
37 ALfloat old_gain; |
38 ALboolean openal_close (void) { |
38 |
39 /*Stop all sounds, deallocate all memory and close OpenAL */ |
39 ALboolean openal_init(ALboolean usehardware, int memorysize) { |
40 ALCcontext *context; |
|
41 ALCdevice *device; |
|
42 |
|
43 if (openalReady == AL_FALSE) { |
|
44 errno = EPERM; |
|
45 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
46 return AL_FALSE; |
|
47 } |
|
48 |
|
49 alSourceStopv (globalsize, Sources); |
|
50 alDeleteSources (globalsize, Sources); |
|
51 alDeleteBuffers (globalsize, Buffers); |
|
52 |
|
53 free(Sources); |
|
54 free(Buffers); |
|
55 |
|
56 context = alcGetCurrentContext(); |
|
57 device = alcGetContextsDevice(context); |
|
58 |
|
59 alcMakeContextCurrent(NULL); |
|
60 alcDestroyContext(context); |
|
61 alcCloseDevice(device); |
|
62 |
|
63 openalReady = AL_FALSE; |
|
64 |
|
65 err_msg("(%s) INFO - OpenAL closed", prog); |
|
66 |
|
67 return AL_TRUE; |
|
68 } |
|
69 |
|
70 ALboolean openal_ready(void) { |
|
71 return openalReady; |
|
72 } |
|
73 |
|
74 ALboolean openal_init(char* programname, ALboolean usehardware, uint32_t memorysize) { |
|
75 /*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
40 /*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
76 ALCcontext *context; |
41 ALCcontext *context; |
77 ALCdevice *device; |
42 ALCdevice *device; |
78 const ALCchar *default_device; |
43 const ALCchar *default_device; |
79 |
44 |
80 prog = programname; |
45 prog = "OpenAL subsystem"; |
81 |
46 |
82 /*Position of the listener*/ |
47 // set the memory dimentsion and the increment width when reallocating |
83 ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; |
48 if (memorysize <= 0) |
84 /*Velocity of the listener*/ |
49 globalsize = 50; |
85 ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 }; |
50 else |
86 /*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/ |
51 globalsize = memorysize; |
87 ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; |
52 increment = globalsize; |
88 |
53 |
|
54 // reuse old context but keep the new value for increment |
89 if (openalReady == AL_TRUE) { |
55 if (openalReady == AL_TRUE) { |
90 errno = EPERM; |
56 err_msg("(%s) WARN - already initialized", prog); |
91 err_ret("(%s) WARN - OpenAL already initialized", prog); |
|
92 return AL_FALSE; |
57 return AL_FALSE; |
93 } |
58 } |
94 |
59 |
95 if (usehardware == AL_TRUE) { |
60 if (usehardware == AL_TRUE) |
96 default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); |
61 device = alcOpenDevice(NULL); |
97 device = alcOpenDevice(default_device); |
62 else |
98 } else |
|
99 device = alcOpenDevice("Generic Software"); |
63 device = alcOpenDevice("Generic Software"); |
100 |
64 |
101 if (device == NULL) { |
65 err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); |
|
66 |
|
67 if (device == NULL) { |
102 errno = ENODEV; |
68 errno = ENODEV; |
103 err_ret("(%s) WARN - Failed to open sound device", prog); |
69 err_ret("(%s) WARN - failed to open sound device", prog); |
104 return AL_FALSE; |
70 return AL_FALSE; |
105 } |
71 } |
106 err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); |
72 |
107 |
|
108 context = alcCreateContext(device, NULL); |
73 context = alcCreateContext(device, NULL); |
109 alcMakeContextCurrent(context); |
74 alcMakeContextCurrent(context); |
110 alcProcessContext(context); |
75 alcProcessContext(context); |
111 |
76 |
112 if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE) |
77 if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE) |
113 return AL_FALSE; |
78 return AL_FALSE; |
114 |
79 |
115 /*allocate memory space for buffers and sources*/ |
80 // allocate memory space for buffers and sources |
116 if (memorysize == 0) |
|
117 globalsize = 50; |
|
118 else |
|
119 globalsize = memorysize; |
|
120 increment = globalsize; |
|
121 |
|
122 Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
81 Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
123 Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
82 Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
124 |
83 |
125 /*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ |
84 // set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation |
|
85 // Position, Velocity and Orientation of the listener |
|
86 ALfloat ListenerPos[] = {0.0, 0.0, 0.0}; |
|
87 ALfloat ListenerVel[] = {0.0, 0.0, 0.0}; |
|
88 ALfloat ListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; |
|
89 |
126 alListenerf (AL_GAIN, 1.0f ); |
90 alListenerf (AL_GAIN, 1.0f ); |
127 alListenerfv(AL_POSITION, ListenerPos); |
91 alListenerfv(AL_POSITION, ListenerPos); |
128 alListenerfv(AL_VELOCITY, ListenerVel); |
92 alListenerfv(AL_VELOCITY, ListenerVel); |
129 alListenerfv(AL_ORIENTATION, ListenerOri); |
93 alListenerfv(AL_ORIENTATION, ListenerOri); |
130 |
94 |
131 if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE) |
95 if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE) |
132 return AL_FALSE; |
96 return AL_FALSE; |
133 |
97 |
134 openalReady = AL_TRUE; |
98 openalReady = AL_TRUE; |
135 |
99 |
136 alGetError(); /* clear any AL errors beforehand */ |
100 alGetError(); // clear any AL errors beforehand |
137 return AL_TRUE; |
101 return AL_TRUE; |
138 } |
102 } |
139 |
103 |
140 |
104 void openal_close (void) { |
141 ALboolean helper_realloc (void) { |
105 /*Stop all sounds, deallocate all memory and close OpenAL */ |
|
106 ALCcontext *context; |
|
107 ALCdevice *device; |
|
108 |
|
109 if (openalReady == AL_FALSE) { |
|
110 errno = EPERM; |
|
111 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
112 return; |
|
113 } |
|
114 |
|
115 alSourceStopv (globalsize, Sources); |
|
116 alDeleteSources (globalsize, Sources); |
|
117 alDeleteBuffers (globalsize, Buffers); |
|
118 |
|
119 free(Sources); |
|
120 free(Buffers); |
|
121 |
|
122 context = alcGetCurrentContext(); |
|
123 device = alcGetContextsDevice(context); |
|
124 |
|
125 alcMakeContextCurrent(NULL); |
|
126 alcDestroyContext(context); |
|
127 alcCloseDevice(device); |
|
128 |
|
129 openalReady = AL_FALSE; |
|
130 |
|
131 err_msg("(%s) INFO - closed", prog); |
|
132 |
|
133 return AL_TRUE; |
|
134 } |
|
135 |
|
136 ALboolean openal_ready(void) { |
|
137 return openalReady; |
|
138 } |
|
139 |
|
140 |
|
141 void helper_realloc (void) { |
142 /*expands allocated memory when loading more sound files than expected*/ |
142 /*expands allocated memory when loading more sound files than expected*/ |
143 int oldsize = globalsize; |
143 int oldsize = globalsize; |
144 globalsize += increment; |
144 globalsize += increment; |
145 |
145 |
146 err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); |
146 err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); |
147 |
147 |
148 Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
148 Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
149 Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
149 Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
150 |
150 |
151 return AL_TRUE; |
151 return; |
152 } |
152 } |
153 |
153 |
154 |
154 |
155 ALint openal_loadfile (const char *filename){ |
155 int openal_loadfile (const char *filename){ |
156 /*Open a file, load into memory and allocate the Source buffer for playing*/ |
156 /*Open a file, load into memory and allocate the Source buffer for playing*/ |
157 ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
157 ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
158 ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
158 ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
159 ALenum format; |
159 ALenum format; |
160 ALsizei bitsize, freq; |
160 ALsizei bitsize, freq; |
162 uint32_t fileformat; |
162 uint32_t fileformat; |
163 ALenum error; |
163 ALenum error; |
164 FILE *fp; |
164 FILE *fp; |
165 |
165 |
166 if (openalReady == AL_FALSE) { |
166 if (openalReady == AL_FALSE) { |
167 errno = EPERM; |
167 err_msg("(%s) WARN - not initialized", prog); |
168 err_ret("(%s) WARN - OpenAL not initialized", prog); |
168 return -1; |
169 return AL_FALSE; |
|
170 } |
169 } |
171 |
170 |
172 /*when the buffers are all used, we can expand memory to accept new files*/ |
171 /*when the buffers are all used, we can expand memory to accept new files*/ |
173 if (globalindex == globalsize) |
172 if (globalindex == globalsize) |
174 helper_realloc(); |
173 helper_realloc(); |
175 |
174 |
176 /*detect the file format, as written in the first 4 bytes of the header*/ |
175 /*detect the file format, as written in the first 4 bytes of the header*/ |
177 fp = Fopen (filename, "rb"); |
176 fp = Fopen (filename, "rb"); |
178 |
177 |
179 if (fp == NULL) |
178 if (fp == NULL) |
180 return -1; |
179 return -2; |
181 |
180 |
182 error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
181 error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
183 fclose (fp); |
182 fclose (fp); |
184 |
183 |
185 if (error < 0) { |
184 if (error < 0) { |
186 errno = EIO; |
185 err_msg("(%s) ERROR - File %s is too short", prog, filename); |
187 err_ret("(%s) ERROR - File %s is too short", prog, filename); |
186 return -3; |
188 return -2; |
|
189 } |
187 } |
190 |
188 |
191 /*prepare the buffer to receive data*/ |
189 /*prepare the buffer to receive data*/ |
192 alGenBuffers(1, &Buffers[globalindex]); |
190 alGenBuffers(1, &Buffers[globalindex]); |
193 |
191 |
194 if (AlGetError("(%s) ERROR - Failed to allocate memory for buffers") != AL_TRUE) |
192 if (AlGetError("(%s) ERROR - Failed to allocate memory for buffers") != AL_TRUE) |
195 return -3; |
193 return -4; |
196 |
194 |
197 /*prepare the source to emit sound*/ |
195 /*prepare the source to emit sound*/ |
198 alGenSources(1, &Sources[globalindex]); |
196 alGenSources(1, &Sources[globalindex]); |
199 |
197 |
200 if (AlGetError("(%s) ERROR - Failed to allocate memory for sources") != AL_TRUE) |
198 if (AlGetError("(%s) ERROR - Failed to allocate memory for sources") != AL_TRUE) |
201 return -4; |
199 return -5; |
202 |
200 |
203 |
201 |
204 switch (ENDIAN_BIG_32(fileformat)) { |
202 switch (ENDIAN_BIG_32(fileformat)) { |
205 case OGG_FILE_FORMAT: |
203 case OGG_FILE_FORMAT: |
206 error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
204 error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
207 break; |
205 break; |
208 case WAV_FILE_FORMAT: |
206 case WAV_FILE_FORMAT: |
209 error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
207 error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
210 break; |
208 break; |
211 default: |
209 default: |
212 errno = EINVAL; |
210 err_msg ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); |
213 err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); |
211 return -6; |
214 return -5; |
|
215 break; |
212 break; |
216 } |
213 } |
217 |
214 |
218 |
215 |
219 /*copy pcm data in one buffer*/ |
216 /*copy pcm data in one buffer*/ |
239 /*returns the index of the source you just loaded, increments it and exits*/ |
236 /*returns the index of the source you just loaded, increments it and exits*/ |
240 return globalindex++; |
237 return globalindex++; |
241 } |
238 } |
242 |
239 |
243 |
240 |
244 ALboolean openal_toggleloop (uint32_t index){ |
241 void openal_playsound (uint32_t index) { |
245 /*Set or unset looping mode*/ |
242 openal_playsound_loop (index, 0); |
|
243 } |
|
244 |
|
245 |
|
246 void openal_pausesound (uint32_t index) { |
|
247 if (openalReady == AL_TRUE && index < globalsize) |
|
248 alSourcePause(Sources[index]); |
|
249 } |
|
250 |
|
251 |
|
252 void openal_stopsound (uint32_t index) { |
|
253 openal_stopsound_free(index, 0); |
|
254 } |
|
255 |
|
256 |
|
257 void openal_freesound (uint32_t index){ |
|
258 if (openalReady == AL_TRUE && index < globalsize) |
|
259 alSourceStop(Sources[index]); |
|
260 // STUB |
|
261 } |
|
262 |
|
263 |
|
264 void openal_playsound_loop (unsigned int index, char loops) { |
|
265 if (openalReady == AL_TRUE && index < globalsize) { |
|
266 alSourcePlay(Sources[index]); |
|
267 if (loops != 0) |
|
268 openal_toggleloop(index); |
|
269 } |
|
270 } |
|
271 |
|
272 void openal_stopsound_free (unsigned int index, char freesource) { |
|
273 if (openalReady == AL_TRUE && index < globalsize) { |
|
274 alSourceStop(Sources[index]); |
|
275 if (freesource != 0) |
|
276 openal_freesound(index); |
|
277 } |
|
278 } |
|
279 |
|
280 void openal_toggleloop (uint32_t index) { |
246 ALint loop; |
281 ALint loop; |
247 |
282 |
248 if (openalReady == AL_FALSE) { |
283 if (openalReady == AL_TRUE && index < globalsize) { |
249 errno = EPERM; |
284 alGetSourcei (Sources[index], AL_LOOPING, &loop); |
250 err_ret("(%s) WARN - OpenAL not initialized", prog); |
285 alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
251 return AL_FALSE; |
286 } |
252 } |
287 |
253 |
288 } |
254 if (index >= globalsize) { |
289 |
255 errno = EINVAL; |
290 |
256 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
291 void openal_setvolume (uint32_t index, float gain) { |
257 return AL_FALSE; |
292 if (openalReady == AL_TRUE && index < globalsize) |
258 } |
293 alSourcef (Sources[index], AL_GAIN, gain); |
259 |
294 } |
260 alGetSourcei (Sources[index], AL_LOOPING, &loop); |
295 |
261 alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
296 |
262 if (AlGetError("(%s) ERROR - Failed to get or set loop property") != AL_TRUE) |
297 void openal_setglobalvolume (float gain) { |
263 return AL_FALSE; |
298 if (openalReady == AL_TRUE) |
264 |
299 alListenerf (AL_GAIN, gain); |
265 alGetError(); /* clear any AL errors beforehand */ |
300 } |
266 |
301 |
267 return AL_TRUE; |
302 void openal_togglemute () { |
268 } |
303 ALfloat gain; |
269 |
304 |
270 |
305 if (openalReady == AL_TRUE) { |
271 ALboolean openal_setvolume (uint32_t index, uint8_t percentage) { |
306 alGetListenerf (AL_GAIN, &gain); |
272 if (openalReady == AL_FALSE) { |
307 if (gain > 0) { |
273 errno = EPERM; |
308 old_gain = gain; |
274 err_ret("(%s) WARN - OpenAL not initialized", prog); |
309 gain = 0; |
275 return AL_FALSE; |
310 } else |
276 } |
311 gain = old_gain; |
277 |
312 |
278 /*Set volume for sound number index*/ |
313 alListenerf (AL_GAIN, gain); |
279 if (index >= globalsize) { |
314 } |
280 errno = EINVAL; |
315 } |
281 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
316 |
282 return AL_FALSE; |
317 |
283 } |
318 void openal_fade (uint32_t index, uint16_t quantity, char direction) { |
284 |
|
285 if (percentage > 100) |
|
286 percentage = 100; |
|
287 alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f); |
|
288 if (AlGetError2("(%s) ERROR - Failed to set volume for sound %d\n", index) != AL_TRUE) |
|
289 return AL_FALSE; |
|
290 |
|
291 alGetError(); /* clear any AL errors beforehand */ |
|
292 |
|
293 return AL_TRUE; |
|
294 } |
|
295 |
|
296 |
|
297 ALboolean openal_setglobalvolume (uint8_t percentage) { |
|
298 if (openalReady == AL_FALSE) { |
|
299 errno = EPERM; |
|
300 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
301 return AL_FALSE; |
|
302 } |
|
303 |
|
304 /*Set volume for all sounds*/ |
|
305 if (percentage > 100) |
|
306 percentage = 100; |
|
307 alListenerf (AL_GAIN, (float) percentage/100.0f); |
|
308 if (AlGetError("(%s) ERROR - Failed to set global volume") != AL_TRUE) |
|
309 return AL_FALSE; |
|
310 |
|
311 alGetError(); /* clear any AL errors beforehand */ |
|
312 |
|
313 return AL_TRUE; |
|
314 } |
|
315 |
|
316 |
|
317 ALboolean openal_togglemute () { |
|
318 /*Mute or unmute sound*/ |
|
319 ALfloat mute; |
|
320 |
|
321 if (openalReady == AL_FALSE) { |
|
322 errno = EPERM; |
|
323 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
324 return AL_FALSE; |
|
325 } |
|
326 |
|
327 alGetListenerf (AL_GAIN, &mute); |
|
328 if (mute > 0) |
|
329 mute = 0; |
|
330 else |
|
331 mute = 1.0; |
|
332 alListenerf (AL_GAIN, mute); |
|
333 if (AlGetError("(%s) ERROR - Failed to set mute property") != AL_TRUE) |
|
334 return AL_FALSE; |
|
335 |
|
336 alGetError(); /* clear any AL errors beforehand */ |
|
337 |
|
338 return AL_TRUE; |
|
339 } |
|
340 |
|
341 |
|
342 ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) { |
|
343 /*Fade in or out by calling a helper thread*/ |
319 /*Fade in or out by calling a helper thread*/ |
344 #ifndef _WIN32 |
320 #ifndef _WIN32 |
345 pthread_t thread; |
321 pthread_t thread; |
346 #else |
322 #else |
347 HANDLE Thread; |
323 HANDLE Thread; |
348 DWORD threadID; |
324 DWORD threadID; |
349 #endif |
325 #endif |
350 fade_t *fade; |
326 fade_t *fade; |
351 |
327 |
352 if (openalReady == AL_FALSE) { |
328 if (openalReady == AL_TRUE && index < globalsize) { |
353 errno = EPERM; |
329 |
354 err_ret("(%s) WARN - OpenAL not initialized", prog); |
330 fade = (fade_t*) Malloc(sizeof(fade_t)); |
355 return AL_FALSE; |
331 fade->index = index; |
356 } |
332 fade->quantity = quantity; |
357 |
333 |
358 fade = (fade_t*) Malloc(sizeof(fade_t)); |
334 if (direction > 0) { |
359 fade->index = index; |
|
360 fade->quantity = quantity; |
|
361 |
|
362 if (index >= globalsize) { |
|
363 errno = EINVAL; |
|
364 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
|
365 return AL_FALSE; |
|
366 } |
|
367 |
|
368 switch (direction) { |
|
369 case FADE_IN: |
|
370 #ifndef _WIN32 |
335 #ifndef _WIN32 |
371 pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
336 pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
372 #else |
337 #else |
373 Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
338 Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
374 #endif |
339 #endif |
375 break; |
340 } else { |
376 case FADE_OUT: |
|
377 #ifndef _WIN32 |
341 #ifndef _WIN32 |
378 pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
342 pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
379 #else |
343 #else |
380 Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
344 Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
381 #endif |
345 #endif |
382 break; |
346 } |
383 default: |
|
384 errno = EINVAL; |
|
385 err_ret("(%s) ERROR - Unknown direction for fading", prog, index, globalindex); |
|
386 free(fade); |
|
387 return AL_FALSE; |
|
388 break; |
|
389 } |
|
390 |
347 |
391 #ifndef _WIN32 |
348 #ifndef _WIN32 |
392 pthread_detach(thread); |
349 pthread_detach(thread); |
393 #endif |
350 #endif |
394 |
351 } |
395 alGetError(); /* clear any AL errors beforehand */ |
352 } |
396 |
353 |
397 return AL_TRUE; |
354 |
398 } |
355 void openal_fadeout (uint32_t index, uint16_t quantity) { |
399 |
356 openal_fade(index, quantity, AL_FADE_OUT); |
400 |
357 } |
401 ALboolean openal_fadeout (uint32_t index, uint16_t quantity) { |
358 |
402 /*wrapper for fadeout*/ |
359 |
403 return openal_fade(index, quantity, FADE_OUT); |
360 void openal_fadein (uint32_t index, uint16_t quantity) { |
404 } |
361 openal_fade(index, quantity, AL_FADE_IN); |
405 |
362 } |
406 |
363 |
407 ALboolean openal_fadein (uint32_t index, uint16_t quantity) { |
364 |
408 /*wrapper for fadein*/ |
365 void openal_setposition (uint32_t index, float x, float y, float z) { |
409 return openal_fade(index, quantity, FADE_IN); |
366 if (openalReady == AL_TRUE && index < globalsize) |
410 } |
367 alSource3f(Sources[index], AL_POSITION, x, y, z);; |
411 |
368 } |
412 |
369 |
413 ALboolean openal_setposition (uint32_t index, float x, float y, float z) { |
370 |
414 if (openalReady == AL_FALSE) { |
371 |
415 errno = EPERM; |
|
416 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
417 return AL_FALSE; |
|
418 } |
|
419 |
|
420 if (index >= globalsize) { |
|
421 errno = EINVAL; |
|
422 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
|
423 return AL_FALSE; |
|
424 } |
|
425 |
|
426 alSource3f(Sources[index], AL_POSITION, x, y, z); |
|
427 if (AlGetError2("(%s) ERROR - Failed to set position for sound %d)", index) != AL_TRUE) |
|
428 return AL_FALSE; |
|
429 |
|
430 return AL_TRUE; |
|
431 } |
|
432 |
|
433 |
|
434 ALboolean openal_playsound (uint32_t index){ |
|
435 if (openalReady == AL_FALSE) { |
|
436 errno = EPERM; |
|
437 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
438 return AL_FALSE; |
|
439 } |
|
440 |
|
441 /*Play sound number index*/ |
|
442 if (index >= globalsize) { |
|
443 errno = EINVAL; |
|
444 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
|
445 return AL_FALSE; |
|
446 } |
|
447 alSourcePlay(Sources[index]); |
|
448 if (AlGetError2("(%s) ERROR - Failed to play sound %d)", index) != AL_TRUE) |
|
449 return AL_FALSE; |
|
450 |
|
451 alGetError(); /* clear any AL errors beforehand */ |
|
452 |
|
453 return AL_TRUE; |
|
454 } |
|
455 |
|
456 |
|
457 ALboolean openal_pausesound(uint32_t index){ |
|
458 if (openalReady == AL_FALSE) { |
|
459 errno = EPERM; |
|
460 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
461 return AL_FALSE; |
|
462 } |
|
463 |
|
464 /*Pause sound number index*/ |
|
465 if (index >= globalsize) { |
|
466 errno = EINVAL; |
|
467 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
|
468 return AL_FALSE; |
|
469 } |
|
470 alSourcePause(Sources[index]); |
|
471 if (AlGetError2("(%s) ERROR - Failed to pause sound %d)", index) != AL_TRUE) |
|
472 return AL_FALSE; |
|
473 |
|
474 return AL_TRUE; |
|
475 } |
|
476 |
|
477 |
|
478 ALboolean openal_stopsound(uint32_t index){ |
|
479 if (openalReady == AL_FALSE) { |
|
480 errno = EPERM; |
|
481 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
482 return AL_FALSE; |
|
483 } |
|
484 |
|
485 /*Stop sound number index*/ |
|
486 if (index >= globalsize) { |
|
487 errno = EINVAL; |
|
488 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
|
489 return AL_FALSE; |
|
490 } |
|
491 alSourceStop(Sources[index]); |
|
492 if (AlGetError2("(%s) ERROR - Failed to stop sound %d)", index) != AL_TRUE) |
|
493 return AL_FALSE; |
|
494 |
|
495 alGetError(); /* clear any AL errors beforehand */ |
|
496 |
|
497 return AL_TRUE; |
|
498 } |
|
499 |
|
500 |
|
501 ALboolean openal_freesound(uint32_t index){ |
|
502 if (openalReady == AL_FALSE) { |
|
503 errno = EPERM; |
|
504 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
505 return AL_FALSE; |
|
506 } |
|
507 |
|
508 /*Stop sound number index*/ |
|
509 if (index >= globalsize) { |
|
510 errno = EINVAL; |
|
511 err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); |
|
512 return AL_FALSE; |
|
513 } |
|
514 globalindex--; |
|
515 // most likely should do other stuff |
|
516 |
|
517 alGetError(); /* clear any AL errors beforehand */ |
|
518 |
|
519 return AL_TRUE; |
|
520 } |
|
521 |
372 |
522 #ifdef __CPLUSPLUS |
373 #ifdef __CPLUSPLUS |
523 } |
374 } |
524 #endif |
375 #endif |