--- a/openalbridge/globals.h Sun Jul 12 13:57:20 2009 +0000
+++ b/openalbridge/globals.h Sun Jul 12 15:42:54 2009 +0000
@@ -22,6 +22,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
#ifndef _WIN32
#include <pthread.h>
@@ -102,8 +104,8 @@
#pragma pack()
/*other defines*/
-#define FADE_IN 11
-#define FADE_OUT 12
+#define FADE_IN true
+#define FADE_OUT false
#ifdef __CPLUSPLUS
}
--- a/openalbridge/loaders.c Sun Jul 12 13:57:20 2009 +0000
+++ b/openalbridge/loaders.c Sun Jul 12 15:42:54 2009 +0000
@@ -21,185 +21,185 @@
#ifdef __CPLUSPLUS
extern "C" {
#endif
-
- int load_wavpcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) {
- WAV_header_t WAVHeader;
- FILE *wavfile;
- int32_t t;
- uint32_t n = 0;
-
- wavfile = Fopen(filename, "rb");
-
- fread(&WAVHeader.ChunkID, sizeof(uint32_t), 1, wavfile);
- fread(&WAVHeader.ChunkSize, sizeof(uint32_t), 1, wavfile);
- fread(&WAVHeader.Format, sizeof(uint32_t), 1, wavfile);
-
+
+ int load_wavpcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) {
+ WAV_header_t WAVHeader;
+ FILE *wavfile;
+ int32_t t;
+ uint32_t n = 0;
+
+ wavfile = Fopen(filename, "rb");
+
+ fread(&WAVHeader.ChunkID, sizeof(uint32_t), 1, wavfile);
+ fread(&WAVHeader.ChunkSize, sizeof(uint32_t), 1, wavfile);
+ fread(&WAVHeader.Format, sizeof(uint32_t), 1, wavfile);
+
#ifdef DEBUG
- fprintf(stderr, "ChunkID: %X\n", invert_endianness(WAVHeader.ChunkID));
- fprintf(stderr, "ChunkSize: %d\n", WAVHeader.ChunkSize);
- fprintf(stderr, "Format: %X\n", invert_endianness(WAVHeader.Format));
+ fprintf(stderr, "ChunkID: %X\n", invert_endianness(WAVHeader.ChunkID));
+ fprintf(stderr, "ChunkSize: %d\n", WAVHeader.ChunkSize);
+ fprintf(stderr, "Format: %X\n", invert_endianness(WAVHeader.Format));
#endif
-
- fread(&WAVHeader.Subchunk1ID, sizeof(uint32_t), 1, wavfile);
- fread(&WAVHeader.Subchunk1Size, sizeof(uint32_t), 1, wavfile);
- fread(&WAVHeader.AudioFormat, sizeof(uint16_t), 1, wavfile);
- fread(&WAVHeader.NumChannels, sizeof(uint16_t), 1, wavfile);
- fread(&WAVHeader.SampleRate, sizeof(uint32_t), 1, wavfile);
- fread(&WAVHeader.ByteRate, sizeof(uint32_t), 1, wavfile);
- fread(&WAVHeader.BlockAlign, sizeof(uint16_t), 1, wavfile);
- fread(&WAVHeader.BitsPerSample, sizeof(uint16_t), 1, wavfile);
-
+
+ fread(&WAVHeader.Subchunk1ID, sizeof(uint32_t), 1, wavfile);
+ fread(&WAVHeader.Subchunk1Size, sizeof(uint32_t), 1, wavfile);
+ fread(&WAVHeader.AudioFormat, sizeof(uint16_t), 1, wavfile);
+ fread(&WAVHeader.NumChannels, sizeof(uint16_t), 1, wavfile);
+ fread(&WAVHeader.SampleRate, sizeof(uint32_t), 1, wavfile);
+ fread(&WAVHeader.ByteRate, sizeof(uint32_t), 1, wavfile);
+ fread(&WAVHeader.BlockAlign, sizeof(uint16_t), 1, wavfile);
+ fread(&WAVHeader.BitsPerSample, sizeof(uint16_t), 1, wavfile);
+
#ifdef DEBUG
- fprintf(stderr, "Subchunk1ID: %X\n", invert_endianness(WAVHeader.Subchunk1ID));
- fprintf(stderr, "Subchunk1Size: %d\n", WAVHeader.Subchunk1Size);
- fprintf(stderr, "AudioFormat: %d\n", WAVHeader.AudioFormat);
- fprintf(stderr, "NumChannels: %d\n", WAVHeader.NumChannels);
- fprintf(stderr, "SampleRate: %d\n", WAVHeader.SampleRate);
- fprintf(stderr, "ByteRate: %d\n", WAVHeader.ByteRate);
- fprintf(stderr, "BlockAlign: %d\n", WAVHeader.BlockAlign);
- fprintf(stderr, "BitsPerSample: %d\n", WAVHeader.BitsPerSample);
+ fprintf(stderr, "Subchunk1ID: %X\n", invert_endianness(WAVHeader.Subchunk1ID));
+ fprintf(stderr, "Subchunk1Size: %d\n", WAVHeader.Subchunk1Size);
+ fprintf(stderr, "AudioFormat: %d\n", WAVHeader.AudioFormat);
+ fprintf(stderr, "NumChannels: %d\n", WAVHeader.NumChannels);
+ fprintf(stderr, "SampleRate: %d\n", WAVHeader.SampleRate);
+ fprintf(stderr, "ByteRate: %d\n", WAVHeader.ByteRate);
+ fprintf(stderr, "BlockAlign: %d\n", WAVHeader.BlockAlign);
+ fprintf(stderr, "BitsPerSample: %d\n", WAVHeader.BitsPerSample);
#endif
-
- do { /*remove useless header chunks (plenty room for improvements)*/
- t = fread(&WAVHeader.Subchunk2ID, sizeof(uint32_t), 1, wavfile);
- if (invert_endianness(WAVHeader.Subchunk2ID) == 0x64617461)
- break;
- if (t <= 0) { /*eof*/
- fprintf(stderr, "ERROR: wrong WAV header\n");
- return AL_FALSE;
- }
- } while (1);
- fread(&WAVHeader.Subchunk2Size, sizeof(uint32_t), 1, wavfile);
-
+
+ do { /*remove useless header chunks (plenty room for improvements)*/
+ t = fread(&WAVHeader.Subchunk2ID, sizeof(uint32_t), 1, wavfile);
+ if (invert_endianness(WAVHeader.Subchunk2ID) == 0x64617461)
+ break;
+ if (t <= 0) { /*eof*/
+ fprintf(stderr, "ERROR: wrong WAV header\n");
+ return AL_FALSE;
+ }
+ } while (1);
+ fread(&WAVHeader.Subchunk2Size, sizeof(uint32_t), 1, wavfile);
+
#ifdef DEBUG
- fprintf(stderr, "Subchunk2ID: %X\n", invert_endianness(WAVHeader.Subchunk2ID));
- fprintf(stderr, "Subchunk2Size: %d\n", WAVHeader.Subchunk2Size);
+ fprintf(stderr, "Subchunk2ID: %X\n", invert_endianness(WAVHeader.Subchunk2ID));
+ fprintf(stderr, "Subchunk2Size: %d\n", WAVHeader.Subchunk2Size);
#endif
-
- *data = (char*) Malloc (sizeof(char) * WAVHeader.Subchunk2Size);
-
- /*this could be improved*/
- do {
- n += fread(&((*data)[n]), sizeof(uint8_t), 1, wavfile);
- } while (n < WAVHeader.Subchunk2Size);
-
- fclose(wavfile);
-
+
+ *data = (char*) Malloc (sizeof(char) * WAVHeader.Subchunk2Size);
+
+ /*this could be improved*/
+ do {
+ n += fread(&((*data)[n]), sizeof(uint8_t), 1, wavfile);
+ } while (n < WAVHeader.Subchunk2Size);
+
+ fclose(wavfile);
+
#ifdef DEBUG
- fprintf(stderr, "Last two bytes of data: %X%X\n", (*data)[n-2], (*data)[n-1]);
+ fprintf(stderr, "Last two bytes of data: %X%X\n", (*data)[n-2], (*data)[n-1]);
#endif
-
- /*remaining parameters*/
- /*Valid formats are AL_FORMAT_MONO8, AL_FORMAT_MONO16, AL_FORMAT_STEREO8, and AL_FORMAT_STEREO16*/
- if (WAVHeader.NumChannels == 1) {
- if (WAVHeader.BitsPerSample == 8)
- *format = AL_FORMAT_MONO8;
- else {
- if (WAVHeader.BitsPerSample == 16)
- *format = AL_FORMAT_MONO16;
- else {
- fprintf(stderr, "ERROR: wrong WAV header - bitsample value\n");
- return AL_FALSE;
- }
- }
- } else {
- if (WAVHeader.NumChannels == 2) {
- if (WAVHeader.BitsPerSample == 8)
- *format = AL_FORMAT_STEREO8;
- else {
- if (WAVHeader.BitsPerSample == 16)
- *format = AL_FORMAT_STEREO16;
- else {
- fprintf(stderr, "ERROR: wrong WAV header - bitsample value\n");
- return AL_FALSE;
- }
- }
- } else {
- fprintf(stderr, "ERROR: wrong WAV header - format value\n");
- return AL_FALSE;
- }
- }
-
- *bitsize = WAVHeader.Subchunk2Size;
- *freq = WAVHeader.SampleRate;
- return AL_TRUE;
- }
-
+
+ /*remaining parameters*/
+ /*Valid formats are AL_FORMAT_MONO8, AL_FORMAT_MONO16, AL_FORMAT_STEREO8, and AL_FORMAT_STEREO16*/
+ if (WAVHeader.NumChannels == 1) {
+ if (WAVHeader.BitsPerSample == 8)
+ *format = AL_FORMAT_MONO8;
+ else {
+ if (WAVHeader.BitsPerSample == 16)
+ *format = AL_FORMAT_MONO16;
+ else {
+ fprintf(stderr, "ERROR: wrong WAV header - bitsample value\n");
+ return AL_FALSE;
+ }
+ }
+ } else {
+ if (WAVHeader.NumChannels == 2) {
+ if (WAVHeader.BitsPerSample == 8)
+ *format = AL_FORMAT_STEREO8;
+ else {
+ if (WAVHeader.BitsPerSample == 16)
+ *format = AL_FORMAT_STEREO16;
+ else {
+ fprintf(stderr, "ERROR: wrong WAV header - bitsample value\n");
+ return AL_FALSE;
+ }
+ }
+ } else {
+ fprintf(stderr, "ERROR: wrong WAV header - format value\n");
+ return AL_FALSE;
+ }
+ }
+
+ *bitsize = WAVHeader.Subchunk2Size;
+ *freq = WAVHeader.SampleRate;
+ return AL_TRUE;
+ }
- int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) {
- /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */
- FILE *oggFile; /*ogg handle*/
- OggVorbis_File oggStream; /*stream handle*/
- vorbis_info *vorbisInfo; /*some formatting data*/
- int64_t pcm_length; /*length of the decoded data*/
- int size = 0;
- int section, result;
+
+ int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) {
+ /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */
+ FILE *oggFile; /*ogg handle*/
+ OggVorbis_File oggStream; /*stream handle*/
+ vorbis_info *vorbisInfo; /*some formatting data*/
+ int64_t pcm_length; /*length of the decoded data*/
+ int size = 0;
+ int section, result;
#ifdef DEBUG
- int i;
- vorbis_comment *vorbisComment; /*other less useful data*/
+ int i;
+ vorbis_comment *vorbisComment; /*other less useful data*/
#endif
-
- oggFile = Fopen(filename, "rb");
- result = ov_open(oggFile, &oggStream, NULL, 0); /*TODO: check returning value of result*/
- fclose(oggFile);
-
- vorbisInfo = ov_info(&oggStream, -1);
- pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels;
-
+
+ oggFile = Fopen(filename, "rb");
+ result = ov_open(oggFile, &oggStream, NULL, 0); /*TODO: check returning value of result*/
+ fclose(oggFile);
+
+ vorbisInfo = ov_info(&oggStream, -1);
+ pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels;
+
#ifdef DEBUG
- vorbisComment = ov_comment(&oggStream, -1);
- fprintf(stderr, "Version: %d\n", vorbisInfo->version);
- fprintf(stderr, "Channels: %d\n", vorbisInfo->channels);
- fprintf(stderr, "Rate (Hz): %ld\n", vorbisInfo->rate);
- fprintf(stderr, "Bitrate Upper: %ld\n", vorbisInfo->bitrate_upper);
- fprintf(stderr, "Bitrate Nominal: %ld\n", vorbisInfo->bitrate_nominal);
- fprintf(stderr, "Bitrate Lower: %ld\n", vorbisInfo->bitrate_lower);
- fprintf(stderr, "Bitrate Windows: %ld\n", vorbisInfo->bitrate_window);
- fprintf(stderr, "Vendor: %s\n", vorbisComment->vendor);
- fprintf(stderr, "PCM data size: %lld\n", pcm_length);
- fprintf(stderr, "# comment: %d\n", vorbisComment->comments);
- for (i = 0; i < vorbisComment->comments; i++)
- fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]);
+ vorbisComment = ov_comment(&oggStream, -1);
+ fprintf(stderr, "Version: %d\n", vorbisInfo->version);
+ fprintf(stderr, "Channels: %d\n", vorbisInfo->channels);
+ fprintf(stderr, "Rate (Hz): %ld\n", vorbisInfo->rate);
+ fprintf(stderr, "Bitrate Upper: %ld\n", vorbisInfo->bitrate_upper);
+ fprintf(stderr, "Bitrate Nominal: %ld\n", vorbisInfo->bitrate_nominal);
+ fprintf(stderr, "Bitrate Lower: %ld\n", vorbisInfo->bitrate_lower);
+ fprintf(stderr, "Bitrate Windows: %ld\n", vorbisInfo->bitrate_window);
+ fprintf(stderr, "Vendor: %s\n", vorbisComment->vendor);
+ fprintf(stderr, "PCM data size: %lld\n", pcm_length);
+ fprintf(stderr, "# comment: %d\n", vorbisComment->comments);
+ for (i = 0; i < vorbisComment->comments; i++)
+ fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]);
#endif
-
- /*allocates enough room for the decoded data*/
- *data = (char*) Malloc (sizeof(char) * pcm_length);
-
- /*there *should* not be ogg at 8 bits*/
- if (vorbisInfo->channels == 1)
- *format = AL_FORMAT_MONO16;
- else {
- if (vorbisInfo->channels == 2)
- *format = AL_FORMAT_STEREO16;
- else {
- fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels);
- return AL_FALSE;
- }
- }
-
- while(size < pcm_length) {
- /*ov_read decodes the ogg stream and storse the pcm in data*/
- result = ov_read (&oggStream, *data + size, pcm_length - size, 0, 2, 1, §ion);
- if(result > 0) {
- size += result;
- } else {
- if (result == 0)
- break;
- else {
- fprintf(stderr, "ERROR: end of file from OGG stream\n");
- return AL_FALSE;
- }
- }
- }
-
- /*records the last fields*/
- *bitsize = size;
- *freq = vorbisInfo->rate;
-
- ov_clear (&oggStream);
- return AL_TRUE;
- }
-
+
+ /*allocates enough room for the decoded data*/
+ *data = (char*) Malloc (sizeof(char) * pcm_length);
+
+ /*there *should* not be ogg at 8 bits*/
+ if (vorbisInfo->channels == 1)
+ *format = AL_FORMAT_MONO16;
+ else {
+ if (vorbisInfo->channels == 2)
+ *format = AL_FORMAT_STEREO16;
+ else {
+ fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels);
+ return AL_FALSE;
+ }
+ }
+
+ while(size < pcm_length) {
+ /*ov_read decodes the ogg stream and storse the pcm in data*/
+ result = ov_read (&oggStream, *data + size, pcm_length - size, 0, 2, 1, §ion);
+ if(result > 0) {
+ size += result;
+ } else {
+ if (result == 0)
+ break;
+ else {
+ fprintf(stderr, "ERROR: end of file from OGG stream\n");
+ return AL_FALSE;
+ }
+ }
+ }
+
+ /*records the last fields*/
+ *bitsize = size;
+ *freq = vorbisInfo->rate;
+
+ ov_clear (&oggStream);
+ return AL_TRUE;
+ }
+
#ifdef __CPLUSPLUS
}
#endif
--- a/openalbridge/openalwrap.c Sun Jul 12 13:57:20 2009 +0000
+++ b/openalbridge/openalwrap.c Sun Jul 12 15:42:54 2009 +0000
@@ -25,443 +25,435 @@
#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;
-
- ALint openalReady = AL_FALSE;
-
- ALint openal_close(void) {
- /*Stop all sounds, deallocate all memory and close OpenAL */
- ALCcontext *context;
- ALCdevice *device;
-
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- 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;
- }
-
- ALint openal_ready(void) {
- return openalReady;
- }
-
- ALint openal_init(uint32_t memorysize) {
- /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
- ALCcontext *context;
- ALCdevice *device;
- const ALCchar *default_device;
-
- /*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)
- {
- fprintf(stderr, "ERROR: OpenAL already initialized\n");
- return AL_FALSE;
- }
-
- default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
- fprintf(stderr, "Using default device: %s\n", default_device);
-
- if ((device = alcOpenDevice(default_device)) == NULL) {
- fprintf(stderr, "ERROR: Failed to open sound device\n");
- return AL_FALSE;
- }
-
- context = alcCreateContext(device, NULL);
- alcMakeContextCurrent(context);
- alcProcessContext(context);
-
- if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE)
- return AL_FALSE;
-
- /*allocate memory space for buffers and sources*/
- globalsize = memorysize;
- increment = memorysize;
- 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("ERROR %d: Setting Listener properties\n") != AL_TRUE)
- return AL_FALSE;
-
- openalReady = AL_TRUE;
-
- alGetError(); /* clear any AL errors beforehand */
- return AL_TRUE;
- }
-
-
- uint8_t helper_realloc (void) {
- /*expands allocated memory when loading more sound files than expected*/
- globalsize += increment;
+
+ /*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) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ 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;
+ }
+
+ ALboolean openal_ready(void) {
+ return openalReady;
+ }
+
+ ALboolean openal_init(uint32_t memorysize) {
+ /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
+ ALCcontext *context;
+ ALCdevice *device;
+ const ALCchar *default_device;
+
+ /*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) {
+ fprintf(stderr, "ERROR: OpenAL already initialized\n");
+ return AL_FALSE;
+ }
+
+ default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
+ fprintf(stderr, "Using default device: %s\n", default_device);
+
+ if ((device = alcOpenDevice(default_device)) == NULL) {
+ fprintf(stderr, "ERROR: Failed to open sound device\n");
+ return AL_FALSE;
+ }
+
+ context = alcCreateContext(device, NULL);
+ alcMakeContextCurrent(context);
+ alcProcessContext(context);
+
+ if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE)
+ return AL_FALSE;
+
+ /*allocate memory space for buffers and sources*/
+ globalsize = memorysize;
+ increment = memorysize;
+ 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("ERROR %d: Setting Listener properties\n") != AL_TRUE)
+ return AL_FALSE;
+
+ openalReady = 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*/
#ifdef DEBUG
- fprintf(stderr, "OpenAL: Realloc in process %d\n", globalsize);
+ fprintf(stderr, "OpenAL: Realloc in process %d\n", globalsize);
#endif
- Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
- Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
-
- return 0;
- }
-
-
- int 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;
- ALsizei freq;
- char *data;
- uint32_t fileformat;
- ALenum error;
- FILE *fp;
-
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- 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) {
- fprintf(stderr, "ERROR: file %s is too short \n", filename);
- return -2;
- }
-
- /*prepare the buffer to receive data*/
- alGenBuffers(1, &Buffers[globalindex]);
-
- if (AlGetError("ERROR %d: Allocating memory for buffers\n") != AL_TRUE)
- return -3;
-
- /*prepare the source to emit sound*/
- alGenSources(1, &Sources[globalindex]);
-
- if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE)
- return -4;
-
-
- if (fileformat == 0x5367674F) /*check if ogg*/
- error = load_oggvorbis (filename, &format, &data, &bitsize, &freq);
- else {
- if (fileformat == 0x46464952) /*check if wav*/
- error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
- else {
- fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat));
- return -5;
- }
- }
-
- /*copy pcm data in one buffer*/
- alBufferData(Buffers[globalindex], format, data, bitsize, freq);
- free(data); /*deallocate data to save memory*/
-
- if (AlGetError("ERROR %d: Writing data to buffer\n") != 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("ERROR %d: Setting source properties\n") != 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++;
- }
-
-
- ALint openal_toggleloop (uint32_t index){
- /*Set or unset looping mode*/
- ALint loop;
-
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- if (index >= globalsize) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
-
- alGetSourcei (Sources[index], AL_LOOPING, &loop);
- alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001);
- if (AlGetError("ERROR %d: Getting or setting loop property\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
+ globalsize += increment;
- return AL_TRUE;
- }
-
-
- ALint openal_setvolume (uint32_t index, uint8_t percentage) {
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Set volume for sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: 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 (AlGetError("ERROR %d: Setting volume for last sound\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALint openal_setglobalvolume (uint8_t percentage) {
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Set volume for all sounds*/
- if (percentage > 100)
- percentage = 100;
- alListenerf (AL_GAIN, (float) percentage/100.0f);
- if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALint openal_togglemute () {
- /*Mute or unmute sound*/
- ALfloat mute;
-
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- alGetListenerf (AL_GAIN, &mute);
- if (mute > 0)
- mute = 0;
- else
- mute = 1.0;
- alListenerf (AL_GAIN, mute);
- if (AlGetError("ERROR %d: Setting mute property\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALint openal_fade(uint32_t index, uint16_t quantity, uint8_t direction) {
- /*Fade in or out by calling a helper thread*/
+ 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) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ 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) {
+ fprintf(stderr, "ERROR: file %s is too short \n", filename);
+ return -2;
+ }
+
+ /*prepare the buffer to receive data*/
+ alGenBuffers(1, &Buffers[globalindex]);
+
+ if (AlGetError("ERROR %d: Allocating memory for buffers\n") != AL_TRUE)
+ return -3;
+
+ /*prepare the source to emit sound*/
+ alGenSources(1, &Sources[globalindex]);
+
+ if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE)
+ return -4;
+
+
+ if (fileformat == 0x5367674F) /*check if ogg*/
+ error = load_oggvorbis (filename, &format, &data, &bitsize, &freq);
+ else {
+ if (fileformat == 0x46464952) /*check if wav*/
+ error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
+ else {
+ fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat));
+ return -5;
+ }
+ }
+
+ /*copy pcm data in one buffer*/
+ alBufferData(Buffers[globalindex], format, data, bitsize, freq);
+ free(data); /*deallocate data to save memory*/
+
+ if (AlGetError("ERROR %d: Writing data to buffer\n") != 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("ERROR %d: Setting source properties\n") != 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) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ if (index >= globalsize) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+
+ alGetSourcei (Sources[index], AL_LOOPING, &loop);
+ alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001);
+ if (AlGetError("ERROR %d: Getting or setting loop property\n") != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_setvolume (uint32_t index, uint8_t percentage) {
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Set volume for sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: 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("ERROR %d: 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) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Set volume for all sounds*/
+ if (percentage > 100)
+ percentage = 100;
+ alListenerf (AL_GAIN, (float) percentage/100.0f);
+ if (AlGetError("ERROR %d: 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) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ alGetListenerf (AL_GAIN, &mute);
+ if (mute > 0)
+ mute = 0;
+ else
+ mute = 1.0;
+ alListenerf (AL_GAIN, mute);
+ if (AlGetError("ERROR %d: 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, bool 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)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- fade = (fade_t*) Malloc(sizeof(fade_t));
- fade->index = index;
- fade->quantity = quantity;
-
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
-
- if (direction == FADE_IN)
-#ifndef _WIN32
- pthread_create(&thread, NULL, helper_fadein, (void*) fade);
-#else
- Thread = _beginthread(&helper_fadein, 0, (void*) fade);
-#endif
- else {
- if (direction == FADE_OUT)
-#ifndef _WIN32
- pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
+ pthread_t thread;
#else
- Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
+ HANDLE Thread;
+ DWORD threadID;
+#endif
+ fade_t *fade;
+
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ fade = (fade_t*) Malloc(sizeof(fade_t));
+ fade->index = index;
+ fade->quantity = quantity;
+
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+
+ if (direction == FADE_IN)
+#ifndef _WIN32
+ pthread_create(&thread, NULL, helper_fadein, (void*) fade);
+#else
+ Thread = _beginthread(&helper_fadein, 0, (void*) fade);
+#endif
+ else {
+ if (direction == FADE_OUT)
+#ifndef _WIN32
+ pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
+#else
+ Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
#endif
- else {
- fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction);
- free(fade);
- return AL_FALSE;
- }
- }
-
+ else {
+ fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction);
+ free(fade);
+ return AL_FALSE;
+ }
+ }
+
#ifndef _WIN32
- pthread_detach(thread);
+ pthread_detach(thread);
#endif
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALint openal_fadeout(uint32_t index, uint16_t quantity) {
- /*wrapper for fadeout*/
- return openal_fade(index, quantity, FADE_OUT);
- }
-
-
- ALint openal_fadein(uint32_t index, uint16_t quantity) {
- /*wrapper for fadein*/
- return openal_fade(index, quantity, FADE_IN);
- }
-
-
- ALint openal_setposition(uint32_t index, float x, float y, float z) {
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
-
- alSource3f(Sources[index], AL_POSITION, x, y, z);
- if (AlGetError("ERROR %d: setting position for last sound\n") != AL_TRUE)
- return AL_FALSE;
-
- return AL_TRUE;
- }
- ALint openal_playsound(uint32_t index){
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Play sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
- alSourcePlay(Sources[index]);
- if (AlGetError("ERROR %d: Playing last sound\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALint openal_pausesound(uint32_t index){
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Pause sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
- alSourcePause(Sources[index]);
- if (AlGetError("ERROR %d: Pausing last sound\n") != AL_TRUE)
- return AL_FALSE;
-
- return AL_TRUE;
- }
-
-
- ALint openal_stopsound(uint32_t index){
- if(openalReady == AL_FALSE)
- {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Stop sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
- alSourceStop(Sources[index]);
- if (AlGetError("ERROR %d: Stopping last sound\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ 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) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+
+ alSource3f(Sources[index], AL_POSITION, x, y, z);
+ if (AlGetError2("ERROR %d: setting position for sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_playsound (uint32_t index){
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Play sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+ alSourcePlay(Sources[index]);
+ if (AlGetError2("ERROR %d: 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) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Pause sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+ alSourcePause(Sources[index]);
+ if (AlGetError2("ERROR %d: Pausing sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_stopsound(uint32_t index){
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Stop sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+ alSourceStop(Sources[index]);
+ if (AlGetError2("ERROR %d: Stopping sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
#ifdef __CPLUSPLUS
}
#endif
--- a/openalbridge/openalwrap.h Sun Jul 12 13:57:20 2009 +0000
+++ b/openalbridge/openalwrap.h Sun Jul 12 15:42:54 2009 +0000
@@ -18,27 +18,27 @@
#ifndef _OALB_INTERFACE_H
#define _OALB_INTERFACE_H
-
+#include <stdbool.h>
#ifdef __CPLUSPLUS
extern "C" {
#endif
-
- int openal_init (unsigned int memorysize);
- int openal_close (void);
- int openal_loadfile (const char *filename);
- int openal_toggleloop (unsigned int index);
- int openal_setposition (unsigned int index, float x, float y, float z);
- int openal_setvolume (unsigned int index, unsigned char percentage);
- int openal_setglobalvolume (unsigned char percentage);
- int openal_togglemute (void);
- int openal_fadeout (unsigned int index, unsigned short int quantity);
- int openal_fadein (unsigned int index, unsigned short int quantity);
- int openal_fade (unsigned int index, unsigned short int quantity, unsigned char direction);
- int openal_playsound (unsigned int index);
- int openal_pausesound (unsigned int index);
- int openal_stopsound (unsigned int index);
-
+
+ bool openal_init (unsigned int memorysize);
+ bool openal_close (void);
+ int openal_loadfile (const char *filename);
+ bool openal_toggleloop (unsigned int index);
+ bool openal_setposition (unsigned int index, float x, float y, float z);
+ bool openal_setvolume (unsigned int index, unsigned char percentage);
+ bool openal_setglobalvolume (unsigned char percentage);
+ bool openal_togglemute (void);
+ bool openal_fadeout (unsigned int index, unsigned short int quantity);
+ bool openal_fadein (unsigned int index, unsigned short int quantity);
+ bool openal_fade (unsigned int index, unsigned short int quantity, bool direction);
+ bool openal_playsound (unsigned int index);
+ bool openal_pausesound (unsigned int index);
+ bool openal_stopsound (unsigned int index);
+
#ifdef __CPLUSPLUS
}
#endif
--- a/openalbridge/wrappers.c Sun Jul 12 13:57:20 2009 +0000
+++ b/openalbridge/wrappers.c Sun Jul 12 15:42:54 2009 +0000
@@ -21,144 +21,154 @@
#ifdef __CPLUSPLUS
extern "C" {
#endif
-
- extern ALint *Sources;
-
- void *Malloc (size_t nbytes) {
- void *aptr;
- if ((aptr = malloc(nbytes)) == NULL) {
- fprintf(stderr, "ERROR: not enough memory! malloc() failed\n");
- exit(-1);
- }
- return aptr;
- }
-
-
- void *Realloc (void *aptr, size_t nbytes) {
- aptr = realloc(aptr, nbytes);
-
- if (aptr == NULL) {
- fprintf(stderr, "ERROR: not enough memory! realloc() failed\n");
- free(aptr);
- exit(-1);
- }
- return aptr;
- }
-
-
- FILE *Fopen (const char *fname, char *mode) {
- FILE *fp;
- if ((fp=fopen(fname,mode)) == NULL)
- fprintf (stderr, "ERROR: can't open file %s in mode '%s'\n", fname, mode);
- return fp;
- }
-
-
- ALint AlGetError (const char *str) {
- ALenum error;
-
- error = alGetError();
- if (error != AL_NO_ERROR) {
- fprintf(stderr, str, error);
- return -2;
- } else
- return AL_TRUE;
- }
-
-
+
+ extern ALint *Sources;
+
+ void *Malloc (size_t nbytes) {
+ void *aptr;
+ if ((aptr = malloc(nbytes)) == NULL) {
+ fprintf(stderr, "ERROR: not enough memory! malloc() failed\n");
+ exit(-1);
+ }
+ return aptr;
+ }
+
+
+ void *Realloc (void *aptr, size_t nbytes) {
+ aptr = realloc(aptr, nbytes);
+
+ if (aptr == NULL) {
+ fprintf(stderr, "ERROR: not enough memory! realloc() failed\n");
+ free(aptr);
+ exit(-1);
+ }
+ return aptr;
+ }
+
+
+ FILE *Fopen (const char *fname, char *mode) {
+ FILE *fp;
+ if ((fp=fopen(fname,mode)) == NULL)
+ fprintf (stderr, "ERROR: can't open file %s in mode '%s'\n", fname, mode);
+ return fp;
+ }
+
+
+ ALint AlGetError (const char *str) {
+ ALenum error;
+
+ error = alGetError();
+ if (error != AL_NO_ERROR) {
+ fprintf(stderr, str, error);
+ return -2;
+ } else
+ return AL_TRUE;
+ }
+
+ ALint AlGetError2 (const char *str, int num) {
+ ALenum error;
+
+ error = alGetError();
+ if (error != AL_NO_ERROR) {
+ fprintf(stderr, str, error, num);
+ return -2;
+ } else
+ return AL_TRUE;
+ }
+
#ifndef _WIN32
- void *helper_fadein(void *tmp)
+ void *helper_fadein(void *tmp)
#else
- void *helper_fadein(void *tmp)
-#endif
- {
- ALfloat gain;
- ALfloat target_gain;
- fade_t *fade;
- uint32_t index;
- uint16_t quantity;
-
- fade = tmp;
- index = fade->index;
- quantity = fade->quantity;
- free (fade);
-
-#ifdef DEBUG
- fprintf(stderr, "Fade-out: index %d quantity %d\n", index, quantity);
+ void *helper_fadein(void *tmp)
#endif
-
- /*save the volume desired after the fade*/
- alGetSourcef(Sources[index], AL_GAIN, &target_gain);
- if (target_gain > 1.0f || target_gain <= 0.0f)
- target_gain = 1.0f;
-
- alSourcePlay(Sources[index]);
-
- for (gain = 0.0f ; gain <= target_gain; gain += (float) quantity/10000) {
+ {
+ ALfloat gain;
+ ALfloat target_gain;
+ fade_t *fade;
+ uint32_t index;
+ uint16_t quantity;
+
+ fade = tmp;
+ index = fade->index;
+ quantity = fade->quantity;
+ free (fade);
+
#ifdef DEBUG
- fprintf(stderr, "Fade-in: Set gain to: %f\n", gain);
+ fprintf(stderr, "Fade-out: index %d quantity %d\n", index, quantity);
#endif
- alSourcef(Sources[index], AL_GAIN, gain);
- usleep(10000);
- }
-
- AlGetError("ERROR %d: Setting fade in volume\n");
-
+
+ /*save the volume desired after the fade*/
+ alGetSourcef(Sources[index], AL_GAIN, &target_gain);
+ if (target_gain > 1.0f || target_gain <= 0.0f)
+ target_gain = 1.0f;
+
+ alSourcePlay(Sources[index]);
+
+ for (gain = 0.0f ; gain <= target_gain; gain += (float) quantity/10000) {
+#ifdef DEBUG
+ fprintf(stderr, "Fade-in: Set gain to: %f\n", gain);
+#endif
+ alSourcef(Sources[index], AL_GAIN, gain);
+ usleep(10000);
+ }
+
+ AlGetError("ERROR %d: Setting fade in volume\n");
+
#ifndef _WIN32
- pthread_exit(NULL);
+ pthread_exit(NULL);
#else
- _endthread();
-#endif
- return 0;
- }
-
-
-#ifndef _WIN32
- void *helper_fadeout(void *tmp)
-#else
- void *helper_fadeout(void *tmp)
+ _endthread();
#endif
- {
- ALfloat gain;
- ALfloat old_gain;
- fade_t *fade;
- uint32_t index;
- uint16_t quantity;
-
- fade = tmp;
- index = fade->index;
- quantity = fade->quantity;
- free(fade);
-
-#ifdef DEBUG
- fprintf(stderr, "Fade-out: index %d quantity %d\n", index, quantity);
+ return 0;
+ }
+
+
+#ifndef _WIN32
+ void *helper_fadeout(void *tmp)
+#else
+ void *helper_fadeout(void *tmp)
#endif
-
- alGetSourcef(Sources[index], AL_GAIN, &old_gain);
-
- for (gain = old_gain; gain >= 0.00f; gain -= (float) quantity/10000) {
+ {
+ ALfloat gain;
+ ALfloat old_gain;
+ fade_t *fade;
+ uint32_t index;
+ uint16_t quantity;
+
+ fade = tmp;
+ index = fade->index;
+ quantity = fade->quantity;
+ free(fade);
+
#ifdef DEBUG
- fprintf(stderr, "Fade-out: Set gain to %f\n", gain);
+ fprintf(stderr, "Fade-out: index %d quantity %d\n", index, quantity);
+#endif
+
+ alGetSourcef(Sources[index], AL_GAIN, &old_gain);
+
+ for (gain = old_gain; gain >= 0.00f; gain -= (float) quantity/10000) {
+#ifdef DEBUG
+ fprintf(stderr, "Fade-out: Set gain to %f\n", gain);
#endif
- alSourcef(Sources[index], AL_GAIN, gain);
- usleep(10000);
- }
-
- AlGetError("ERROR %d: Setting fade out volume\n");
-
- /*stop that sound and reset its volume*/
- alSourceStop (Sources[index]);
- alSourcef (Sources[index], AL_GAIN, old_gain);
-
+ alSourcef(Sources[index], AL_GAIN, gain);
+ usleep(10000);
+ }
+
+ AlGetError("ERROR %d: Setting fade out volume\n");
+
+ /*stop that sound and reset its volume*/
+ alSourceStop (Sources[index]);
+ alSourcef (Sources[index], AL_GAIN, old_gain);
+
#ifndef _WIN32
- pthread_exit(NULL);
+ pthread_exit(NULL);
#else
- _endthread();
+ _endthread();
#endif
- return 0;
- }
-
-
+ return 0;
+ }
+
+
#ifdef __CPLUSPLUS
}
#endif
--- a/openalbridge/wrappers.h Sun Jul 12 13:57:20 2009 +0000
+++ b/openalbridge/wrappers.h Sun Jul 12 15:42:54 2009 +0000
@@ -26,12 +26,9 @@
void *Realloc (void *aptr, size_t nbytes);
FILE *Fopen (const char *fname, char *mode);
ALint AlGetError (const char *str);
-#ifndef _WIN32
+ALint AlGetError2 (const char *str, int num);
void *helper_fadein (void *tmp);
void *helper_fadeout (void *tmp);
-#else
-void *helper_fadein (void *tmp);
-void *helper_fadeout (void *tmp);
-#endif
+
#endif /*_OALB_WRAPPERS_H*/