# HG changeset patch # User koda # Date 1255292724 0 # Node ID dbaaba09146d634ac25adacf9e12c1a1c708ff14 # Parent 538a777f90c4b7a21c13df9e8841816518c4859b really fix build and completes transition to errlib diff -r 538a777f90c4 -r dbaaba09146d openalbridge/globals.h --- a/openalbridge/globals.h Sun Oct 11 20:14:55 2009 +0000 +++ b/openalbridge/globals.h Sun Oct 11 20:25:24 2009 +0000 @@ -67,11 +67,12 @@ #endif #endif /* _SLEEP_H */ - +#ifdef __APPLE__ /* check compiler requirements */ #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) #error Do not know the endianess of this architecture #endif +#endif /* use byteswap macros from the host system, hopefully optimized ones ;-) * or define our own version, simple, stupid, straight-forward... */ @@ -101,7 +102,7 @@ extern "C" { #endif -/*data type for WAV header*/ + /*data type for WAV header*/ #pragma pack(1) typedef struct _WAV_header_t { uint32_t ChunkID; @@ -120,25 +121,25 @@ } WAV_header_t; #pragma pack() -/*data type for passing data between threads*/ + /*data type for passing data between threads*/ #pragma pack(1) typedef struct _fade_t { uint32_t index; uint16_t quantity; } fade_t; #pragma pack() - + -/*file format defines*/ + /*file format defines*/ #define OGG_FILE_FORMAT 0x4F676753 #define WAV_FILE_FORMAT 0x52494646 #define WAV_HEADER_SUBCHUNK2ID 0x64617461 - - -/*other defines*/ + + + /*other defines*/ #define FADE_IN 0 #define FADE_OUT 1 - + char *prog; #ifdef __CPLUSPLUS diff -r 538a777f90c4 -r dbaaba09146d openalbridge/openalbridge.c --- a/openalbridge/openalbridge.c Sun Oct 11 20:14:55 2009 +0000 +++ b/openalbridge/openalbridge.c Sun Oct 11 20:25:24 2009 +0000 @@ -22,471 +22,477 @@ #ifdef __CPLUSPLUS extern "C" { #endif - - /*Sources are points emitting sound*/ - ALuint *Sources; - /*Buffers hold sound data*/ - ALuint *Buffers; - /*index for Sources and Buffers*/ - ALuint globalindex, globalsize, increment; - - ALboolean openalReady = AL_FALSE; - - ALboolean openal_close (void) { - /*Stop all sounds, deallocate all memory and close OpenAL */ - ALCcontext *context; - ALCdevice *device; - - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - - alSourceStopv (globalsize, Sources); - alDeleteSources (globalsize, Sources); - alDeleteBuffers (globalsize, Buffers); - - free(Sources); - free(Buffers); - context = alcGetCurrentContext(); - device = alcGetContextsDevice(context); - - alcMakeContextCurrent(NULL); - alcDestroyContext(context); - alcCloseDevice(device); - - openalReady = AL_FALSE; + /*Sources are points emitting sound*/ + ALuint *Sources; + /*Buffers hold sound data*/ + ALuint *Buffers; + /*index for Sources and Buffers*/ + ALuint globalindex, globalsize, increment; - return AL_TRUE; - } - - ALboolean openal_ready(void) { - return openalReady; - } - - ALboolean openal_init(char* programname, ALboolean usehardware, uint32_t memorysize) { - /*Initialize an OpenAL contex and allocate memory space for data and buffers*/ - ALCcontext *context; - ALCdevice *device; - const ALCchar *default_device; - - prog = programname; - - - /*Position of the listener*/ - ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; - /*Velocity of the listener*/ - ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 }; - /*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/ - ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; + ALboolean openalReady = AL_FALSE; - if (openalReady == AL_TRUE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL already initialized", prog); - return AL_FALSE; - } - - if (usehardware) - device = alcOpenDevice(NULL); - else - device = alcOpenDevice("Generic Software"); - - if (device == NULL) { - errno = ENODEV; - err_ret("(%s) WARN - Failed to open sound device", prog); - return AL_FALSE; - } - err_msg("(%s) INFO - output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); - - context = alcCreateContext(device, NULL); - alcMakeContextCurrent(context); - alcProcessContext(context); - - if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE) - return AL_FALSE; - - /*allocate memory space for buffers and sources*/ - if (memorysize == 0) - globalsize = 50; - else - globalsize = memorysize; - increment = globalsize; - - Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); - Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); - - /*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ - alListenerf (AL_GAIN, 1.0f ); - alListenerfv(AL_POSITION, ListenerPos); - alListenerfv(AL_VELOCITY, ListenerVel); - alListenerfv(AL_ORIENTATION, ListenerOri); - - if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE) - return AL_FALSE; - - openalReady = AL_TRUE; + ALboolean openal_close (void) { + /*Stop all sounds, deallocate all memory and close OpenAL */ + ALCcontext *context; + ALCdevice *device; + + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + alSourceStopv (globalsize, Sources); + alDeleteSources (globalsize, Sources); + alDeleteBuffers (globalsize, Buffers); + + free(Sources); + free(Buffers); + + context = alcGetCurrentContext(); + device = alcGetContextsDevice(context); + + alcMakeContextCurrent(NULL); + alcDestroyContext(context); + alcCloseDevice(device); + + openalReady = AL_FALSE; + + return AL_TRUE; + } - alGetError(); /* clear any AL errors beforehand */ - return AL_TRUE; - } - - - ALboolean helper_realloc (void) { - /*expands allocated memory when loading more sound files than expected*/ - int oldsize = globalsize; - globalsize += increment; - -#ifdef DEBUG - err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); -#endif - - Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); - Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); - - return AL_TRUE; - } - - - ALint openal_loadfile (const char *filename){ - /*Open a file, load into memory and allocate the Source buffer for playing*/ - ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ - ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ - ALenum format; - ALsizei bitsize, freq; - char *data; - uint32_t fileformat; - ALenum error; - FILE *fp; - - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - - /*when the buffers are all used, we can expand memory to accept new files*/ - if (globalindex == globalsize) - helper_realloc(); - - /*detect the file format, as written in the first 4 bytes of the header*/ - fp = Fopen (filename, "rb"); - - if (fp == NULL) - return -1; - - error = fread (&fileformat, sizeof(uint32_t), 1, fp); - fclose (fp); - - if (error < 0) { - errno = EIO; - err_ret("(%s) ERROR - file %s is too short", prog, filename); - return -2; + ALboolean openal_ready(void) { + return openalReady; } - /*prepare the buffer to receive data*/ - alGenBuffers(1, &Buffers[globalindex]); - - if (AlGetError("(%s) ERROR - allocating memory for buffers") != AL_TRUE) - return -3; - - /*prepare the source to emit sound*/ - alGenSources(1, &Sources[globalindex]); - - if (AlGetError("(%s) ERROR - allocating memory for sources") != AL_TRUE) - return -4; + ALboolean openal_init(char* programname, ALboolean usehardware, uint32_t memorysize) { + /*Initialize an OpenAL contex and allocate memory space for data and buffers*/ + ALCcontext *context; + ALCdevice *device; + const ALCchar *default_device; + + prog = programname; + + + /*Position of the listener*/ + ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; + /*Velocity of the listener*/ + ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 }; + /*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/ + ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; + + if (openalReady == AL_TRUE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL already initialized", prog); + return AL_FALSE; + } + + if (usehardware) + device = alcOpenDevice(NULL); + else + device = alcOpenDevice("Generic Software"); + + if (device == NULL) { + errno = ENODEV; + err_ret("(%s) WARN - Failed to open sound device", prog); + return AL_FALSE; + } + err_msg("(%s) INFO - Output device: %s", prog, alcGetString(device, ALC_DEVICE_SPECIFIER)); + + context = alcCreateContext(device, NULL); + alcMakeContextCurrent(context); + alcProcessContext(context); + + if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE) + return AL_FALSE; + + /*allocate memory space for buffers and sources*/ + if (memorysize == 0) + globalsize = 50; + else + globalsize = memorysize; + increment = globalsize; + + Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize); + Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize); + + /*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/ + alListenerf (AL_GAIN, 1.0f ); + alListenerfv(AL_POSITION, ListenerPos); + alListenerfv(AL_VELOCITY, ListenerVel); + alListenerfv(AL_ORIENTATION, ListenerOri); + + if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE) + return AL_FALSE; + + openalReady = AL_TRUE; + + alGetError(); /* clear any AL errors beforehand */ + return AL_TRUE; + } - switch (ENDIAN_BIG_32(fileformat)) { - case OGG_FILE_FORMAT: - error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); - break; - case WAV_FILE_FORMAT: - error = load_wavpcm (filename, &format, &data, &bitsize, &freq); - break; - default: - errno = EINVAL; - err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); - return -5; - break; + ALboolean helper_realloc (void) { + /*expands allocated memory when loading more sound files than expected*/ + int oldsize = globalsize; + globalsize += increment; + +#ifdef DEBUG + err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize); +#endif + + Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize); + Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize); + + return AL_TRUE; } - - /*copy pcm data in one buffer*/ - alBufferData(Buffers[globalindex], format, data, bitsize, freq); - free(data); /*deallocate data to save memory*/ - if (AlGetError("(%s) ERROR - writing data to buffers") != AL_TRUE) - return -6; - - /*set source properties that it will use when it's in playback*/ - alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); - alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); - alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); - alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); - alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); - alSourcei (Sources[globalindex], AL_LOOPING, 0 ); - - if (AlGetError("(%s) ERROR - setting Source properties") != AL_TRUE) - return -7; - - alGetError(); /* clear any AL errors beforehand */ - - /*returns the index of the source you just loaded, increments it and exits*/ - return globalindex++; - } - - - ALboolean openal_toggleloop (uint32_t index){ - /*Set or unset looping mode*/ - ALint loop; - - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - - if (index >= globalsize) { - errno = EINVAL; - err_ret("(%s) ERROR - index out of bounds (got %d, max %d)", prog, index, globalindex); - return AL_FALSE; + ALint openal_loadfile (const char *filename){ + /*Open a file, load into memory and allocate the Source buffer for playing*/ + ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/ + ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/ + ALenum format; + ALsizei bitsize, freq; + char *data; + uint32_t fileformat; + ALenum error; + FILE *fp; + + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + /*when the buffers are all used, we can expand memory to accept new files*/ + if (globalindex == globalsize) + helper_realloc(); + + /*detect the file format, as written in the first 4 bytes of the header*/ + fp = Fopen (filename, "rb"); + + if (fp == NULL) + return -1; + + error = fread (&fileformat, sizeof(uint32_t), 1, fp); + fclose (fp); + + if (error < 0) { + errno = EIO; + err_ret("(%s) ERROR - File %s is too short", prog, filename); + return -2; + } + + /*prepare the buffer to receive data*/ + alGenBuffers(1, &Buffers[globalindex]); + + if (AlGetError("(%s) ERROR - Failed to allocate memory for buffers") != AL_TRUE) + return -3; + + /*prepare the source to emit sound*/ + alGenSources(1, &Sources[globalindex]); + + if (AlGetError("(%s) ERROR - Failed to allocate memory for sources") != AL_TRUE) + return -4; + + + switch (ENDIAN_BIG_32(fileformat)) { + case OGG_FILE_FORMAT: + error = load_oggvorbis (filename, &format, &data, &bitsize, &freq); + break; + case WAV_FILE_FORMAT: + error = load_wavpcm (filename, &format, &data, &bitsize, &freq); + break; + default: + errno = EINVAL; + err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat)); + return -5; + break; + } + + + /*copy pcm data in one buffer*/ + alBufferData(Buffers[globalindex], format, data, bitsize, freq); + free(data); /*deallocate data to save memory*/ + + if (AlGetError("(%s) ERROR - Failed to write data to buffers") != AL_TRUE) + return -6; + + /*set source properties that it will use when it's in playback*/ + alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] ); + alSourcef (Sources[globalindex], AL_PITCH, 1.0f ); + alSourcef (Sources[globalindex], AL_GAIN, 1.0f ); + alSourcefv(Sources[globalindex], AL_POSITION, SourcePos ); + alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel ); + alSourcei (Sources[globalindex], AL_LOOPING, 0 ); + + if (AlGetError("(%s) ERROR - Failed to set Source properties") != AL_TRUE) + return -7; + + alGetError(); /* clear any AL errors beforehand */ + + /*returns the index of the source you just loaded, increments it and exits*/ + return globalindex++; } - alGetSourcei (Sources[index], AL_LOOPING, &loop); - alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); - if (AlGetError("(%s) ERROR - getting or setting loop property") != AL_TRUE) - return AL_FALSE; - alGetError(); /* clear any AL errors beforehand */ + ALboolean openal_toggleloop (uint32_t index){ + /*Set or unset looping mode*/ + ALint loop; + + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + if (index >= globalsize) { + errno = EINVAL; + err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); + return AL_FALSE; + } + + alGetSourcei (Sources[index], AL_LOOPING, &loop); + alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001); + if (AlGetError("(%s) ERROR - Failed to get or set loop property") != AL_TRUE) + return AL_FALSE; + + alGetError(); /* clear any AL errors beforehand */ + + return AL_TRUE; + } + - return AL_TRUE; - } - - - ALboolean openal_setvolume (uint32_t index, uint8_t percentage) { - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } + ALboolean openal_setvolume (uint32_t index, uint8_t percentage) { + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + /*Set volume for sound number index*/ + if (index >= globalindex) { + fprintf(stderr, "ERROR 'openal_setvolume()': index out of bounds (got %d, max %d)\n", index, globalindex); + return AL_FALSE; + } + + if (percentage > 100) + percentage = 100; + alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f); + if (AlGetError2("(%s) ERROR - Failed to set volume for sound %d\n", index) != AL_TRUE) + return AL_FALSE; + + alGetError(); /* clear any AL errors beforehand */ + + return AL_TRUE; + } + - /*Set volume for sound number index*/ - if (index >= globalindex) { - fprintf(stderr, "ERROR 'openal_setvolume()': index out of bounds (got %d, max %d)\n", index, globalindex); - return AL_FALSE; + ALboolean openal_setglobalvolume (uint8_t percentage) { + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + /*Set volume for all sounds*/ + if (percentage > 100) + percentage = 100; + alListenerf (AL_GAIN, (float) percentage/100.0f); + if (AlGetError("(%s) ERROR - Failed to set global volume") != AL_TRUE) + return AL_FALSE; + + alGetError(); /* clear any AL errors beforehand */ + + return AL_TRUE; + } + + + ALboolean openal_togglemute () { + /*Mute or unmute sound*/ + ALfloat mute; + + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + alGetListenerf (AL_GAIN, &mute); + if (mute > 0) + mute = 0; + else + mute = 1.0; + alListenerf (AL_GAIN, mute); + if (AlGetError("(%s) ERROR - Failed to set mute property") != AL_TRUE) + return AL_FALSE; + + alGetError(); /* clear any AL errors beforehand */ + + return AL_TRUE; } - if (percentage > 100) - percentage = 100; - alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f); - if (AlGetError2("ERROR %d in 'openal_setvolume()': setting volume for sound %d\n", index) != AL_TRUE) - return AL_FALSE; - - alGetError(); /* clear any AL errors beforehand */ - - return AL_TRUE; - } - - - ALboolean openal_setglobalvolume (uint8_t percentage) { - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - - /*Set volume for all sounds*/ - if (percentage > 100) - percentage = 100; - alListenerf (AL_GAIN, (float) percentage/100.0f); - if (AlGetError("ERROR %d in 'openal_setglobalvolume()': Setting global volume\n") != AL_TRUE) - return AL_FALSE; - - alGetError(); /* clear any AL errors beforehand */ - - return AL_TRUE; - } - - - ALboolean openal_togglemute () { - /*Mute or unmute sound*/ - ALfloat mute; - - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - - alGetListenerf (AL_GAIN, &mute); - if (mute > 0) - mute = 0; - else - mute = 1.0; - alListenerf (AL_GAIN, mute); - if (AlGetError("ERROR %d in 'openal_togglemute()': Setting mute property\n") != AL_TRUE) - return AL_FALSE; - - alGetError(); /* clear any AL errors beforehand */ - - return AL_TRUE; - } - - - ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) { - /*Fade in or out by calling a helper thread*/ -#ifndef _WIN32 - pthread_t thread; -#else - HANDLE Thread; - DWORD threadID; -#endif - fade_t *fade; - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - - fade = (fade_t*) Malloc(sizeof(fade_t)); - fade->index = index; - fade->quantity = quantity; - - if (index >= globalindex) { - fprintf(stderr, "ERROR 'openal_fade()': index out of bounds (got %d, max %d)\n", index, globalindex); - return AL_FALSE; - } - - switch (direction) { - case FADE_IN: + ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) { + /*Fade in or out by calling a helper thread*/ #ifndef _WIN32 - pthread_create(&thread, NULL, helper_fadein, (void*) fade); + pthread_t thread; #else - Thread = _beginthread(&helper_fadein, 0, (void*) fade); + HANDLE Thread; + DWORD threadID; #endif - break; - case FADE_OUT: + fade_t *fade; + + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + fade = (fade_t*) Malloc(sizeof(fade_t)); + fade->index = index; + fade->quantity = quantity; + + if (index >= globalsize) { + errno = EINVAL; + err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); + return AL_FALSE; + } + + switch (direction) { + case FADE_IN: #ifndef _WIN32 - pthread_create(&thread, NULL, helper_fadeout, (void*) fade); + pthread_create(&thread, NULL, helper_fadein, (void*) fade); #else - Thread = _beginthread(&helper_fadeout, 0, (void*) fade); + Thread = _beginthread(&helper_fadein, 0, (void*) fade); +#endif + break; + case FADE_OUT: +#ifndef _WIN32 + pthread_create(&thread, NULL, helper_fadeout, (void*) fade); +#else + Thread = _beginthread(&helper_fadeout, 0, (void*) fade); #endif - break; - default: - fprintf(stderr, "ERROR 'openal_fade()': unknown direction for fade (%d)\n", direction); - free(fade); - return AL_FALSE; - break; - } - + break; + default: + errno = EINVAL; + err_ret("(%s) ERROR - Unknown direction for fading", prog, index, globalindex); + free(fade); + return AL_FALSE; + break; + } + #ifndef _WIN32 - pthread_detach(thread); + pthread_detach(thread); #endif - - alGetError(); /* clear any AL errors beforehand */ + + alGetError(); /* clear any AL errors beforehand */ + + return AL_TRUE; + } - return AL_TRUE; - } - - - ALboolean openal_fadeout (uint32_t index, uint16_t quantity) { - /*wrapper for fadeout*/ - return openal_fade(index, quantity, FADE_OUT); - } - - - ALboolean openal_fadein (uint32_t index, uint16_t quantity) { - /*wrapper for fadein*/ - return openal_fade(index, quantity, FADE_IN); - } - - - ALboolean openal_setposition (uint32_t index, float x, float y, float z) { - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - if (index >= globalindex) { - fprintf(stderr, "ERROR 'openal_setposition()': index out of bounds (got %d, max %d)\n", index, globalindex); - return AL_FALSE; + ALboolean openal_fadeout (uint32_t index, uint16_t quantity) { + /*wrapper for fadeout*/ + return openal_fade(index, quantity, FADE_OUT); + } + + + ALboolean openal_fadein (uint32_t index, uint16_t quantity) { + /*wrapper for fadein*/ + return openal_fade(index, quantity, FADE_IN); } - alSource3f(Sources[index], AL_POSITION, x, y, z); - if (AlGetError2("ERROR %d in 'openal_setposition()': setting position for sound %d\n", index) != AL_TRUE) - return AL_FALSE; + + ALboolean openal_setposition (uint32_t index, float x, float y, float z) { + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + if (index >= globalsize) { + errno = EINVAL; + err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); + return AL_FALSE; + } + + alSource3f(Sources[index], AL_POSITION, x, y, z); + if (AlGetError2("(%s) ERROR - Failed to set position for sound %d)", index) != AL_TRUE) + return AL_FALSE; + + return AL_TRUE; + } + - return AL_TRUE; - } - - - ALboolean openal_playsound (uint32_t index){ - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - - /*Play sound number index*/ - if (index >= globalindex) { - fprintf(stderr, "ERROR 'openal_playsound()': index out of bounds (got %d, max %d)\n", index, globalindex); - return AL_FALSE; + ALboolean openal_playsound (uint32_t index){ + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + /*Play sound number index*/ + if (index >= globalsize) { + errno = EINVAL; + err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); + return AL_FALSE; + } + alSourcePlay(Sources[index]); + if (AlGetError2("(%s) ERROR - Failed to play sound %d)", index) != AL_TRUE) + return AL_FALSE; + + alGetError(); /* clear any AL errors beforehand */ + + return AL_TRUE; } - alSourcePlay(Sources[index]); - if (AlGetError2("ERROR %d in 'openal_playsound()': Playing sound %d\n", index) != AL_TRUE) - return AL_FALSE; - - alGetError(); /* clear any AL errors beforehand */ - return AL_TRUE; - } - - - ALboolean openal_pausesound(uint32_t index){ - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } - /*Pause sound number index*/ - if (index >= globalindex) { - fprintf(stderr, "ERROR 'openal_pausesound()': index out of bounds (got %d, max %d)\n", index, globalindex); - return AL_FALSE; + ALboolean openal_pausesound(uint32_t index){ + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + /*Pause sound number index*/ + if (index >= globalsize) { + errno = EINVAL; + err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); + return AL_FALSE; + } + alSourcePause(Sources[index]); + if (AlGetError2("(%s) ERROR - Failed to pause sound %d)", index) != AL_TRUE) + return AL_FALSE; + + return AL_TRUE; } - alSourcePause(Sources[index]); - if (AlGetError2("ERROR %d in 'openal_pausesound()': Pausing sound %d\n", index) != AL_TRUE) - return AL_FALSE; + - return AL_TRUE; - } - - - ALboolean openal_stopsound(uint32_t index){ - if (openalReady == AL_FALSE) { - errno = EPERM; - err_ret("(%s) WARN - OpenAL not initialized", prog); - return AL_FALSE; - } + ALboolean openal_stopsound(uint32_t index){ + if (openalReady == AL_FALSE) { + errno = EPERM; + err_ret("(%s) WARN - OpenAL not initialized", prog); + return AL_FALSE; + } + + /*Stop sound number index*/ + if (index >= globalsize) { + errno = EINVAL; + err_ret("(%s) ERROR - Index out of bounds (got %d, max %d)", prog, index, globalindex); + return AL_FALSE; + } + alSourceStop(Sources[index]); + if (AlGetError2("(%s) ERROR - Failed to stop sound %d)", index) != AL_TRUE) + return AL_FALSE; + + alGetError(); /* clear any AL errors beforehand */ + + return AL_TRUE; + } - /*Stop sound number index*/ - if (index >= globalindex) { - fprintf(stderr, "ERROR 'openal_stopsound()': index out of bounds (got %d, max %d)\n", index, globalindex); - return AL_FALSE; - } - alSourceStop(Sources[index]); - if (AlGetError2("ERROR %d in 'openal_stopsound()': Stopping sound %d\n", index) != AL_TRUE) - return AL_FALSE; - - alGetError(); /* clear any AL errors beforehand */ - - return AL_TRUE; - } - #ifdef __CPLUSPLUS } #endif diff -r 538a777f90c4 -r dbaaba09146d openalbridge/wrappers.c --- a/openalbridge/wrappers.c Sun Oct 11 20:14:55 2009 +0000 +++ b/openalbridge/wrappers.c Sun Oct 11 20:25:24 2009 +0000 @@ -51,6 +51,7 @@ fp = fopen(fname,mode); if (fp == NULL) err_ret("(%s) ERROR - can't open file %s in mode '%s'", prog, fname, mode); + return fp; } @@ -71,8 +72,8 @@ error = alGetError(); if (error != AL_NO_ERROR) { - fprintf(stderr, str, error, num); - return -2; + err_msg(str, prog, num); + return error; } else return AL_TRUE; }