70 |
70 |
71 ALint openal_init(int memorysize) { |
71 ALint openal_init(int memorysize) { |
72 /* This function initializes an OpenAL contex, allocates memory space for data and prepares OpenAL buffers*/ |
72 /* This function initializes an OpenAL contex, allocates memory space for data and prepares OpenAL buffers*/ |
73 ALCcontext *context; |
73 ALCcontext *context; |
74 ALCdevice *device; |
74 ALCdevice *device; |
75 ALenum error; |
|
76 |
75 |
77 const ALCchar *default_device; |
76 const ALCchar *default_device; |
78 // Position of the listener. |
77 // Position of the listener. |
79 ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; |
78 ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; |
80 // Velocity of the listener. |
79 // Velocity of the listener. |
85 default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); |
84 default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); |
86 |
85 |
87 fprintf(stderr, "Using default device: %s\n", default_device); |
86 fprintf(stderr, "Using default device: %s\n", default_device); |
88 |
87 |
89 if ((device = alcOpenDevice(default_device)) == NULL) { |
88 if ((device = alcOpenDevice(default_device)) == NULL) { |
90 fprintf(stderr, "ERROR %d: Failed to open sound device\n", error); |
89 fprintf(stderr, "ERROR: Failed to open sound device\n"); |
91 return AL_FALSE; |
90 return AL_FALSE; |
92 } |
91 } |
93 context = alcCreateContext(device, NULL); |
92 context = alcCreateContext(device, NULL); |
94 alcMakeContextCurrent(context); |
93 alcMakeContextCurrent(context); |
95 alcProcessContext(context); |
94 alcProcessContext(context); |
303 alSourcef (Sources[index], AL_GAIN, 1.0f); |
302 alSourcef (Sources[index], AL_GAIN, 1.0f); |
304 |
303 |
305 #ifndef _WIN32 |
304 #ifndef _WIN32 |
306 pthread_exit(NULL); |
305 pthread_exit(NULL); |
307 #else |
306 #else |
308 ThreadExit(); |
307 free(fade); |
|
308 _endthread(); |
309 #endif |
309 #endif |
310 } |
310 } |
311 |
311 |
312 ALint openal_fadeout(int index, unsigned int quantity) { |
312 ALint openal_fadeout(int index, unsigned int quantity) { |
313 #ifndef _WIN32 |
313 #ifndef _WIN32 |
314 pthread_t thread; |
314 pthread_t thread; |
|
315 fade_t fade; |
|
316 fade.index = index; |
|
317 fade.quantity = quantity; |
315 #else |
318 #else |
316 HANDLE Thread; |
319 HANDLE Thread; |
317 DWORD threadID; |
320 DWORD threadID; |
318 #endif |
321 fade_t *fade = malloc(sizeof(fade_t)); |
319 fade_t fade; |
322 fade->index = index; |
320 |
323 fade->quantity = quantity; |
321 if (index >= globalindex) { |
324 #endif |
322 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex); |
325 |
323 return AL_FALSE; |
326 if (index >= globalindex) { |
324 } |
327 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex); |
325 |
328 return AL_FALSE; |
326 fade.index = index; |
329 } |
327 fade.quantity = quantity; |
330 |
328 |
331 |
329 #ifndef _WIN32 |
332 #ifndef _WIN32 |
330 pthread_create(&thread, NULL, helper_fadeout, (void*) &fade); |
333 pthread_create(&thread, NULL, helper_fadeout, (void*) &fade); |
331 pthread_detach(thread); |
334 pthread_detach(thread); |
332 #else |
335 #else |
333 Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) helper_fadeout, (void*) &fade, 0, threadID); |
336 Thread = _beginthread(&helper_fadeout, 0, (void*) fade); |
334 CloseHandle(Thread); |
337 #endif |
335 #endif |
338 |
336 |
339 alGetError(); /* clear any AL errors beforehand */ |
337 alGetError(); /* clear any AL errors beforehand */ |
340 |
338 |
341 return AL_TRUE; |
339 return AL_TRUE; |
342 } |
340 } |
343 |
341 |
344 #ifndef _WIN32 |
342 #ifndef _WIN32 |
345 void *helper_fadein(void *tmp) |
343 void *helper_fadein(void* tmp) |
346 #else |
344 #else |
347 void WINAPI helper_fadein(void *tmp) |
345 VOID WINAPI helper_fadein(LPVOID tmp) |
|
346 #endif |
348 #endif |
347 { |
349 { |
348 ALfloat gain; |
350 ALfloat gain; |
349 fade_t *fade; |
351 fade_t *fade; |
350 int index; |
352 int index; |
370 return AL_FALSE; |
372 return AL_FALSE; |
371 |
373 |
372 #ifndef _WIN32 |
374 #ifndef _WIN32 |
373 pthread_exit(NULL); |
375 pthread_exit(NULL); |
374 #else |
376 #else |
375 ThreadExit(); |
377 free(fade); |
|
378 _endthread(); |
376 #endif |
379 #endif |
377 } |
380 } |
378 |
381 |
379 |
382 |
380 ALint openal_fadein(int index, unsigned int quantity) { |
383 ALint openal_fadein(int index, unsigned int quantity) { |
381 #ifndef _WIN32 |
384 #ifndef _WIN32 |
382 pthread_t thread; |
385 pthread_t thread; |
|
386 fade_t fade; |
|
387 fade.index = index; |
|
388 fade.quantity = quantity; |
383 #else |
389 #else |
384 HANDLE Thread; |
390 HANDLE Thread; |
385 DWORD threadID; |
391 DWORD threadID; |
386 #endif |
392 fade_t *fade = malloc(sizeof(fade_t)); |
387 fade_t fade; |
393 fade->index = index; |
388 |
394 fade->quantity = quantity; |
389 if (index >= globalindex) { |
395 #endif |
390 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex); |
396 |
391 return AL_FALSE; |
397 if (index >= globalindex) { |
392 } |
398 fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)", index, globalindex); |
393 |
399 return AL_FALSE; |
394 fade.index = index; |
400 } |
395 fade.quantity = quantity; |
401 |
396 |
|
397 #ifndef _WIN32 |
402 #ifndef _WIN32 |
398 pthread_create(&thread, NULL, helper_fadein, (void*) &fade); |
403 pthread_create(&thread, NULL, helper_fadein, (void*) &fade); |
399 pthread_detach(thread); |
404 pthread_detach(thread); |
400 #else |
405 #else |
401 Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) helper_fadein, (void*) &fade, 0, threadID); |
406 Thread = _beginthread(&helper_fadein, 0, (void*) fade); |
402 CloseHandle(Thread); |
|
403 #endif |
407 #endif |
404 |
408 |
405 alGetError(); /* clear any AL errors beforehand */ |
409 alGetError(); /* clear any AL errors beforehand */ |
406 |
410 |
407 return AL_TRUE; |
411 return AL_TRUE; |