1 /* |
1 /* |
2 * OpenAL Bridge - a simple portable library for OpenAL interface |
2 * OpenAL Bridge - a simple portable library for OpenAL interface |
3 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
3 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU Lesser General Public License as published by |
6 * it under the terms of the GNU Lesser General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
9 * This program is distributed in the hope that it will be useful, |
9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU Lesser General Public License for more details. |
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * You should have received a copy of the GNU Lesser General Public License |
14 * You should have received a copy of the GNU Lesser General Public License |
15 * along with this program; if not, write to the Free Software |
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 |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 */ |
17 */ |
18 |
18 |
19 #include "openalbridge.h" |
19 #include "openalbridge.h" |
20 #include "globals.h" |
20 #include "globals.h" |
21 #include "wrappers.h" |
21 #include "wrappers.h" |
22 #include "alc.h" |
22 #include "alc.h" |
23 #include "loaders.h" |
23 #include "loaders.h" |
24 |
24 |
25 #ifdef __CPLUSPLUS |
25 |
26 extern "C" { |
26 /*Sources are points emitting sound*/ |
27 #endif |
27 ALuint *Sources; |
28 |
28 /*Buffers hold sound data*/ |
29 /*Sources are points emitting sound*/ |
29 ALuint *Buffers; |
30 ALuint *Sources; |
30 /*index for Sources and Buffers*/ |
31 /*Buffers hold sound data*/ |
31 ALuint globalindex, globalsize, increment; |
32 ALuint *Buffers; |
32 |
33 /*index for Sources and Buffers*/ |
33 ALboolean openalReady = AL_FALSE; |
34 ALuint globalindex, globalsize, increment; |
34 ALfloat old_gain; |
35 |
35 |
36 ALboolean openalReady = AL_FALSE; |
36 int openal_init(int memorysize) { |
37 ALfloat old_gain; |
37 /*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
38 |
38 ALCcontext *context; |
39 ALboolean openal_init(ALboolean usehardware, int memorysize) { |
39 ALCdevice *device; |
40 /*Initialize an OpenAL contex and allocate memory space for data and buffers*/ |
40 |
41 ALCcontext *context; |
41 // set the memory dimentsion and the increment width when reallocating |
42 ALCdevice *device; |
42 if (memorysize <= 0) |
43 |
43 globalsize = 50; |
44 prog = "OpenAL subsystem"; |
44 else |
45 |
45 globalsize = memorysize; |
46 // set the memory dimentsion and the increment width when reallocating |
46 increment = globalsize; |
47 if (memorysize <= 0) |
47 |
48 globalsize = 50; |
48 // reuse old context but keep the new value for increment |
49 else |
49 if (openalReady == AL_TRUE) { |
50 globalsize = memorysize; |
50 err_msg("(%s) WARN - already initialized", prog); |
51 increment = globalsize; |
51 return 0; |
52 |
52 } |
53 // reuse old context but keep the new value for increment |
53 |
54 if (openalReady == AL_TRUE) { |
54 // open hardware device if present |
55 err_msg("(%s) WARN - already initialized", prog); |
55 device = alcOpenDevice(NULL); |
56 return AL_FALSE; |
56 |
|
57 if (device == NULL) { |
|
58 errno = ENODEV; |
|
59 err_ret("(%s) WARN - failed to open sound device, using software renderer", prog); |
|
60 device = alcOpenDevice("Generic Software"); |
|
61 if (device == NULL) { |
|
62 err_ret("(%s) ERROR - failed to open sound software device, sound will be disabled", prog); |
|
63 return -1; |
57 } |
64 } |
58 |
65 } |
59 if (usehardware == AL_TRUE) |
66 |
60 device = alcOpenDevice(NULL); |
67 err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); |
61 else |
68 |
62 device = alcOpenDevice("Generic Software"); |
69 context = alcCreateContext(device, NULL); |
63 |
70 alcMakeContextCurrent(context); |
64 err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); |
71 alcProcessContext(context); |
65 |
72 |
66 if (device == NULL) { |
73 if (AL_NO_ERROR != alGetError()) { |
67 errno = ENODEV; |
74 err_msg("(%s) ERROR - Failed to create a new contex",prog); |
68 err_ret("(%s) WARN - failed to open sound device", prog); |
|
69 return AL_FALSE; |
|
70 } |
|
71 |
|
72 context = alcCreateContext(device, NULL); |
|
73 alcMakeContextCurrent(context); |
|
74 alcProcessContext(context); |
|
75 |
|
76 if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE) |
|
77 return AL_FALSE; |
|
78 |
|
79 // allocate memory space for buffers and sources |
|
80 Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
|
81 Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
|
82 |
|
83 // set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation |
|
84 // Position, Velocity and Orientation of the listener |
|
85 ALfloat ListenerPos[] = {0.0, 0.0, 0.0}; |
|
86 ALfloat ListenerVel[] = {0.0, 0.0, 0.0}; |
|
87 ALfloat ListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; |
|
88 |
|
89 alListenerf (AL_GAIN, 1.0f ); |
|
90 alListenerfv(AL_POSITION, ListenerPos); |
|
91 alListenerfv(AL_VELOCITY, ListenerVel); |
|
92 alListenerfv(AL_ORIENTATION, ListenerOri); |
|
93 |
|
94 if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE) |
|
95 return AL_FALSE; |
|
96 |
|
97 openalReady = AL_TRUE; |
|
98 |
|
99 alGetError(); // clear any AL errors beforehand |
|
100 return AL_TRUE; |
|
101 } |
|
102 |
|
103 void openal_close (void) { |
|
104 /*Stop all sounds, deallocate all memory and close OpenAL */ |
|
105 ALCcontext *context; |
|
106 ALCdevice *device; |
|
107 |
|
108 if (openalReady == AL_FALSE) { |
|
109 errno = EPERM; |
|
110 err_ret("(%s) WARN - OpenAL not initialized", prog); |
|
111 return; |
|
112 } |
|
113 |
|
114 alSourceStopv (globalsize, Sources); |
|
115 alDeleteSources (globalsize, Sources); |
|
116 alDeleteBuffers (globalsize, Buffers); |
|
117 |
|
118 free(Sources); |
|
119 free(Buffers); |
|
120 |
|
121 context = alcGetCurrentContext(); |
|
122 device = alcGetContextsDevice(context); |
|
123 |
|
124 alcMakeContextCurrent(NULL); |
75 alcMakeContextCurrent(NULL); |
125 alcDestroyContext(context); |
76 alcDestroyContext(context); |
126 alcCloseDevice(device); |
77 alcCloseDevice(device); |
127 |
78 return -2; |
128 openalReady = AL_FALSE; |
79 } |
129 |
80 |
130 err_msg("(%s) INFO - closed", prog); |
81 // allocate memory space for buffers and sources |
131 |
82 Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
|
83 Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); |
|
84 |
|
85 // set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation |
|
86 // Position, Velocity and Orientation of the listener |
|
87 ALfloat ListenerPos[] = {0.0, 0.0, 0.0}; |
|
88 ALfloat ListenerVel[] = {0.0, 0.0, 0.0}; |
|
89 ALfloat ListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; |
|
90 |
|
91 alListenerf (AL_GAIN, 1.0f ); |
|
92 alListenerfv(AL_POSITION, ListenerPos); |
|
93 alListenerfv(AL_VELOCITY, ListenerVel); |
|
94 alListenerfv(AL_ORIENTATION, ListenerOri); |
|
95 |
|
96 if (AL_NO_ERROR != alGetError()) { |
|
97 err_msg("(%s) ERROR - Failed to set Listener properties",prog); |
|
98 return -3; |
|
99 } |
|
100 openalReady = AL_TRUE; |
|
101 |
|
102 alGetError(); // clear any AL errors beforehand |
|
103 return AL_TRUE; |
|
104 } |
|
105 |
|
106 void openal_close (void) { |
|
107 /*Stop all sounds, deallocate all memory and close OpenAL */ |
|
108 ALCcontext *context; |
|
109 ALCdevice *device; |
|
110 |
|
111 if (openalReady == AL_FALSE) { |
|
112 errno = EPERM; |
|
113 err_ret("(%s) WARN - OpenAL not initialized", prog); |
132 return; |
114 return; |
133 } |
115 } |
134 |
116 |
135 ALboolean openal_ready(void) { |
117 alSourceStopv (globalsize, Sources); |
136 return openalReady; |
118 alDeleteSources (globalsize, Sources); |
137 } |
119 alDeleteBuffers (globalsize, Buffers); |
138 |
120 |
139 |
121 free(Sources); |
140 void helper_realloc (void) { |
122 free(Buffers); |
141 /*expands allocated memory when loading more sound files than expected*/ |
123 |
142 int oldsize = globalsize; |
124 context = alcGetCurrentContext(); |
143 globalsize += increment; |
125 device = alcGetContextsDevice(context); |
144 |
126 |
145 err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); |
127 alcMakeContextCurrent(NULL); |
146 |
128 alcDestroyContext(context); |
147 Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
129 alcCloseDevice(device); |
148 Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
130 |
149 |
131 openalReady = AL_FALSE; |
150 return; |
132 |
151 } |
133 err_msg("(%s) INFO - closed", prog); |
152 |
134 |
153 |
135 return; |
154 int openal_loadfile (const char *filename){ |
136 } |
155 /*Open a file, load into memory and allocate the Source buffer for playing*/ |
137 |
156 ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
138 ALboolean openal_ready(void) { |
157 ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
139 return openalReady; |
158 ALenum format; |
140 } |
159 ALsizei bitsize, freq; |
141 |
160 char *data; |
142 |
161 uint32_t fileformat; |
143 void helper_realloc (void) { |
162 ALenum error; |
144 /*expands allocated memory when loading more sound files than expected*/ |
163 FILE *fp; |
145 int oldsize = globalsize; |
164 |
146 globalsize += increment; |
165 if (openalReady == AL_FALSE) { |
147 |
166 err_msg("(%s) WARN - not initialized", prog); |
148 err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); |
167 return -1; |
149 |
168 } |
150 Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); |
169 |
151 Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); |
170 /*when the buffers are all used, we can expand memory to accept new files*/ |
152 |
171 if (globalindex == globalsize) |
153 return; |
172 helper_realloc(); |
154 } |
173 |
155 |
174 /*detect the file format, as written in the first 4 bytes of the header*/ |
156 |
175 fp = Fopen (filename, "rb"); |
157 int openal_loadfile (const char *filename){ |
176 |
158 /*Open a file, load into memory and allocate the Source buffer for playing*/ |
177 if (fp == NULL) |
159 ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ |
178 return -2; |
160 ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ |
179 |
161 ALenum format; |
180 error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
162 ALsizei bitsize, freq; |
181 fclose (fp); |
163 char *data; |
182 |
164 uint32_t fileformat; |
183 if (error < 0) { |
165 ALenum error; |
184 err_msg("(%s) ERROR - File %s is too short", prog, filename); |
166 FILE *fp; |
185 return -3; |
167 |
186 } |
168 if (openalReady == AL_FALSE) { |
187 |
169 err_msg("(%s) WARN - not initialized", prog); |
188 /*prepare the buffer to receive data*/ |
170 return -1; |
189 alGenBuffers(1, &Buffers[globalindex]); |
171 } |
190 |
172 |
191 if (AlGetError("(%s) ERROR - Failed to allocate memory for buffers") != AL_TRUE) |
173 /*when the buffers are all used, we can expand memory to accept new files*/ |
192 return -4; |
174 if (globalindex == globalsize) |
193 |
175 helper_realloc(); |
194 /*prepare the source to emit sound*/ |
176 |
195 alGenSources(1, &Sources[globalindex]); |
177 /*detect the file format, as written in the first 4 bytes of the header*/ |
196 |
178 fp = Fopen (filename, "rb"); |
197 if (AlGetError("(%s) ERROR - Failed to allocate memory for sources") != AL_TRUE) |
179 |
198 return -5; |
180 if (fp == NULL) |
199 |
181 return -2; |
200 |
182 |
201 switch (ENDIAN_BIG_32(fileformat)) { |
183 error = fread (&fileformat, sizeof(uint32_t), 1, fp); |
202 case OGG_FILE_FORMAT: |
184 fclose (fp); |
203 error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
185 |
204 break; |
186 if (error < 0) { |
205 case WAV_FILE_FORMAT: |
187 err_msg("(%s) ERROR - File %s is too short", prog, filename); |
206 error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
188 return -3; |
207 break; |
189 } |
208 default: |
190 |
209 err_msg ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); |
191 /*prepare the buffer to receive data*/ |
210 return -6; |
192 alGenBuffers(1, &Buffers[globalindex]); |
211 break; |
193 |
212 } |
194 if (AL_NO_ERROR != alGetError()) { |
213 |
195 err_msg("(%s) ERROR - Failed to allocate memory for buffers",prog); |
214 |
196 return -4; |
215 /*copy pcm data in one buffer*/ |
197 } |
216 alBufferData(Buffers[globalindex], format, data, bitsize, freq); |
198 |
217 free(data); /*deallocate data to save memory*/ |
199 /*prepare the source to emit sound*/ |
218 |
200 alGenSources(1, &Sources[globalindex]); |
219 if (AlGetError("(%s) ERROR - Failed to write data to buffers") != AL_TRUE) |
201 |
|
202 if (AL_NO_ERROR != alGetError()) { |
|
203 err_msg("(%s) ERROR - Failed to allocate memory for sources",prog); |
|
204 return -5; |
|
205 } |
|
206 |
|
207 switch (ENDIAN_BIG_32(fileformat)) { |
|
208 case OGG_FILE_FORMAT: |
|
209 error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); |
|
210 break; |
|
211 case WAV_FILE_FORMAT: |
|
212 error = load_wavpcm (filename, &format, &data, &bitsize, &freq); |
|
213 break; |
|
214 default: |
|
215 err_msg ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); |
220 return -6; |
216 return -6; |
221 |
217 break; |
222 /*set source properties that it will use when it's in playback*/ |
218 } |
223 alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); |
219 |
224 alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); |
220 |
225 alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); |
221 //copy pcm data in one buffer and free it |
226 alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); |
222 alBufferData(Buffers[globalindex], format, data, bitsize, freq); |
227 alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); |
223 free(data); |
228 alSourcei (Sources[globalindex], AL_LOOPING, 0 ); |
224 |
229 |
225 if (AL_NO_ERROR != alGetError()) { |
230 if (AlGetError("(%s) ERROR - Failed to set Source properties") != AL_TRUE) |
226 err_msg("(%s) ERROR - Failed to write data to buffers",prog); |
231 return -7; |
227 return -6; |
232 |
228 } |
233 alGetError(); /* clear any AL errors beforehand */ |
229 |
234 |
230 /*set source properties that it will use when it's in playback*/ |
235 /*returns the index of the source you just loaded, increments it and exits*/ |
231 alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); |
236 return globalindex++; |
232 alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); |
237 } |
233 alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); |
238 |
234 alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); |
239 |
235 alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); |
240 void openal_playsound (uint32_t index) { |
236 alSourcei (Sources[globalindex], AL_LOOPING, 0 ); |
241 openal_playsound_loop (index, 0); |
237 |
242 } |
238 if (AL_NO_ERROR != alGetError()) { |
243 |
239 err_msg("(%s) ERROR - Failed to set Source properties",prog); |
244 |
240 return -7; |
245 void openal_pausesound (uint32_t index) { |
241 } |
246 if (openalReady == AL_TRUE && index < globalsize) |
242 |
247 alSourcePause(Sources[index]); |
243 alGetError(); /* clear any AL errors beforehand */ |
248 } |
244 |
249 |
245 /*returns the index of the source you just loaded, increments it and exits*/ |
250 |
246 return globalindex++; |
251 void openal_stopsound (uint32_t index) { |
247 } |
252 openal_stopsound_free(index, 0); |
248 |
253 } |
249 |
254 |
250 void openal_playsound (uint32_t index) { |
255 |
251 openal_playsound_loop (index, 0); |
256 void openal_freesound (uint32_t index){ |
252 } |
257 if (openalReady == AL_TRUE && index < globalsize) |
253 |
258 alSourceStop(Sources[index]); |
254 |
259 // STUB |
255 void openal_pausesound (uint32_t index) { |
260 } |
256 if (openalReady == AL_TRUE && index < globalsize) |
261 |
257 alSourcePause(Sources[index]); |
262 |
258 } |
263 void openal_playsound_loop (unsigned int index, char loops) { |
259 |
264 if (openalReady == AL_TRUE && index < globalsize) { |
260 |
265 alSourcePlay(Sources[index]); |
261 void openal_stopsound (uint32_t index) { |
266 if (loops != 0) |
262 openal_stopsound_free(index, 0); |
267 openal_toggleloop(index); |
263 } |
268 } |
264 |
269 } |
265 |
270 |
266 void openal_freesound (uint32_t index){ |
271 void openal_stopsound_free (unsigned int index, char freesource) { |
267 if (openalReady == AL_TRUE && index < globalsize) |
272 if (openalReady == AL_TRUE && index < globalsize) { |
268 alSourceStop(Sources[index]); |
273 alSourceStop(Sources[index]); |
269 // STUB |
274 if (freesource != 0) |
270 } |
275 openal_freesound(index); |
271 |
276 } |
272 |
277 } |
273 void openal_playsound_loop (unsigned int index, char loops) { |
278 |
274 if (openalReady == AL_TRUE && index < globalsize) { |
279 void openal_toggleloop (uint32_t index) { |
275 alSourcePlay(Sources[index]); |
280 ALint loop; |
276 if (loops != 0) |
281 |
277 openal_toggleloop(index); |
282 if (openalReady == AL_TRUE && index < globalsize) { |
278 } |
283 alGetSourcei (Sources[index], AL_LOOPING, &loop); |
279 } |
284 alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
280 |
285 } |
281 void openal_stopsound_free (unsigned int index, char freesource) { |
286 |
282 if (openalReady == AL_TRUE && index < globalsize) { |
287 } |
283 alSourceStop(Sources[index]); |
288 |
284 if (freesource != 0) |
289 |
285 openal_freesound(index); |
290 void openal_setvolume (uint32_t index, float gain) { |
286 } |
291 if (openalReady == AL_TRUE && index < globalsize) |
287 } |
292 alSourcef (Sources[index], AL_GAIN, gain); |
288 |
293 } |
289 void openal_toggleloop (uint32_t index) { |
294 |
290 ALint loop; |
295 |
291 |
296 void openal_setglobalvolume (float gain) { |
292 if (openalReady == AL_TRUE && index < globalsize) { |
297 if (openalReady == AL_TRUE) |
293 alGetSourcei (Sources[index], AL_LOOPING, &loop); |
298 alListenerf (AL_GAIN, gain); |
294 alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); |
299 } |
295 } |
300 |
296 |
301 void openal_togglemute () { |
297 } |
302 ALfloat gain; |
298 |
303 |
299 |
304 if (openalReady == AL_TRUE) { |
300 void openal_setvolume (uint32_t index, float gain) { |
305 alGetListenerf (AL_GAIN, &gain); |
301 if (openalReady == AL_TRUE && index < globalsize) |
306 if (gain > 0) { |
302 alSourcef (Sources[index], AL_GAIN, gain); |
307 old_gain = gain; |
303 } |
308 gain = 0; |
304 |
309 } else |
305 |
310 gain = old_gain; |
306 void openal_setglobalvolume (float gain) { |
311 |
307 if (openalReady == AL_TRUE) |
312 alListenerf (AL_GAIN, gain); |
308 alListenerf (AL_GAIN, gain); |
313 } |
309 } |
314 } |
310 |
315 |
311 void openal_togglemute () { |
316 |
312 ALfloat gain; |
317 void openal_fade (uint32_t index, uint16_t quantity, char direction) { |
313 |
318 /*Fade in or out by calling a helper thread*/ |
314 if (openalReady == AL_TRUE) { |
|
315 alGetListenerf (AL_GAIN, &gain); |
|
316 if (gain > 0) { |
|
317 old_gain = gain; |
|
318 gain = 0; |
|
319 } else |
|
320 gain = old_gain; |
|
321 |
|
322 alListenerf (AL_GAIN, gain); |
|
323 } |
|
324 } |
|
325 |
|
326 // Fade in or out by calling a helper thread |
|
327 void openal_fade (uint32_t index, uint16_t quantity, al_fade_t direction) { |
319 #ifndef _WIN32 |
328 #ifndef _WIN32 |
320 pthread_t thread; |
329 pthread_t thread; |
321 #else |
330 #else |
322 HANDLE Thread; |
331 HANDLE Thread; |
323 DWORD threadID; |
|
324 #endif |
332 #endif |
325 fade_t *fade; |
333 fade_t *fade; |
326 |
334 |
327 if (openalReady == AL_TRUE && index < globalsize) { |
335 if (openalReady == AL_TRUE && index < globalsize) { |
328 |
336 fade = (fade_t*) Malloc(sizeof(fade_t)); |
329 fade = (fade_t*) Malloc(sizeof(fade_t)); |
337 fade->index = index; |
330 fade->index = index; |
338 fade->quantity = quantity; |
331 fade->quantity = quantity; |
339 fade->type = direction; |
332 |
340 |
333 if (direction > 0) { |
|
334 #ifndef _WIN32 |
341 #ifndef _WIN32 |
335 pthread_create(&thread, NULL, helper_fadein, (void*) fade); |
342 pthread_create(&thread, NULL, (void *)helper_fade, (void *)fade); |
|
343 pthread_detach(thread); |
336 #else |
344 #else |
337 Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
345 Thread = (HANDLE) _beginthread((void *)helper_fade, 0, (void *)fade); |
338 #endif |
346 #endif |
339 } else { |
347 } |
340 #ifndef _WIN32 |
348 } |
341 pthread_create(&thread, NULL, helper_fadeout, (void*) fade); |
349 |
342 #else |
350 void openal_fadein (uint32_t index, uint16_t quantity) { |
343 Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
351 openal_fade(index, quantity, AL_FADE_IN); |
344 #endif |
352 } |
345 } |
353 |
346 |
354 void openal_fadeout (uint32_t index, uint16_t quantity) { |
347 #ifndef _WIN32 |
355 openal_fade(index, quantity, AL_FADE_OUT); |
348 pthread_detach(thread); |
356 } |
349 #endif |
357 |
350 } |
358 |
351 } |
359 void openal_setposition (uint32_t index, float x, float y, float z) { |
352 |
360 if (openalReady == AL_TRUE && index < globalsize) |
353 |
361 alSource3f(Sources[index], AL_POSITION, x, y, z);; |
354 void openal_fadeout (uint32_t index, uint16_t quantity) { |
362 } |
355 openal_fade(index, quantity, AL_FADE_OUT); |
|
356 } |
|
357 |
|
358 |
|
359 void openal_fadein (uint32_t index, uint16_t quantity) { |
|
360 openal_fade(index, quantity, AL_FADE_IN); |
|
361 } |
|
362 |
|
363 |
|
364 void openal_setposition (uint32_t index, float x, float y, float z) { |
|
365 if (openalReady == AL_TRUE && index < globalsize) |
|
366 alSource3f(Sources[index], AL_POSITION, x, y, z);; |
|
367 } |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 #ifdef __CPLUSPLUS |
|
373 } |
|
374 #endif |
|