--- a/QTfrontend/SDLs.cpp Sun Oct 11 16:23:59 2009 +0000
+++ b/QTfrontend/SDLs.cpp Sun Oct 11 20:14:55 2009 +0000
@@ -22,6 +22,7 @@
#include "hwconsts.h"
bool hardware;
+extern char *programname;
SDLInteraction::SDLInteraction(bool hardware_snd)
{
@@ -79,6 +80,6 @@
void OpenAL_Init()
{
if (!openal_ready())
- openal_init(hardware ? 1 : 0, 5);
+ openal_init(programname, hardware ? 1 : 0, 5);
}
--- a/QTfrontend/SDLs.h Sun Oct 11 16:23:59 2009 +0000
+++ b/QTfrontend/SDLs.h Sun Oct 11 20:14:55 2009 +0000
@@ -21,7 +21,7 @@
#include <QStringList>
-extern "C" bool openal_init (unsigned int usehardware, unsigned int memorysize);
+extern "C" bool openal_init (char *programname, bool usehardware, unsigned int memorysize);
extern "C" bool openal_close (void);
extern "C" bool openal_ready (void);
extern "C" int openal_loadfile (const char *filename);
--- a/QTfrontend/main.cpp Sun Oct 11 16:23:59 2009 +0000
+++ b/QTfrontend/main.cpp Sun Oct 11 20:14:55 2009 +0000
@@ -24,7 +24,7 @@
#include <QRegExp>
#include <QMap>
-
+char *programname;
#include "hwform.h"
#include "hwconsts.h"
@@ -44,8 +44,10 @@
return true;
}
-int main(int argc, char *argv[])
-{
+int main(int argc, char *argv[]) {
+
+ programname = argv[0];
+
QApplication app(argc, argv);
QStringList arguments = app.arguments();
@@ -287,9 +289,8 @@
bindir->cd("bin"); // workaround over NSIS installer
cfgdir->setPath(cfgdir->homePath());
+
#ifdef __APPLE__
-
-
if (checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars"))
{
checkForDir(cfgdir->absolutePath() + "/Library/Application Support/Hedgewars/Demos");
--- a/hedgewars/uSound.pas Sun Oct 11 16:23:59 2009 +0000
+++ b/hedgewars/uSound.pas Sun Oct 11 20:14:55 2009 +0000
@@ -59,7 +59,7 @@
function soundFadeOut(snd: TSound; qt: LongInt; voicepack: PVoicepack): LongInt;
{*remember: LongInt = 32bit; integer = 16bit; byte = 8bit*}
-function openal_init (hardware: LongInt; memsize: LongInt) : boolean; cdecl; external OpenALBridge;
+function openal_init (filename: PChar; hardware: boolean; memsize: LongInt) : boolean; cdecl; external OpenALBridge;
function openal_close : boolean; cdecl; external OpenALBridge;
function openal_loadfile (const filename: PChar) : LongInt; cdecl; external OpenALBridge;
function openal_toggleloop (index: LongInt) : boolean; cdecl; external OpenALBridge;
@@ -107,7 +107,8 @@
{*sound works in ipodtouch only if LAND_WIDTH = 1024; LAND_HEIGHT = 512;
or if ogg are loaded in stream or if sound is loaded by demand*}
WriteToConsole('Init OpenAL sound...');
-if isSoundHardware then isSoundEnabled:= openal_init(1, numSounds) else isSoundEnabled:= openal_init(0, numSounds);
+
+isSoundEnabled:= openal_init(str2pchar(ParamStr(0)), isSoundHardware, numSounds);
if isSoundEnabled then WriteLnToConsole(msgOK)
else WriteLnToConsole(msgFailed);
--- a/openalbridge/CMakeLists.txt Sun Oct 11 16:23:59 2009 +0000
+++ b/openalbridge/CMakeLists.txt Sun Oct 11 20:14:55 2009 +0000
@@ -8,7 +8,7 @@
#list of source files for libraries
set(openal_src
- openalbridge.c loaders.c wrappers.c
+ openalbridge.c loaders.c wrappers.c errlib.c
)
#build a static library for human systems
@@ -18,7 +18,7 @@
if(WIN32)
#workaround for visualstudio (wants headers in the source list)
set(openal_src
- openalbridge.h loaders.h wrappers.h globals.h oggvorbis.h ${openal_src}
+ openalbridge.h loaders.h wrappers.h globals.h oggvorbis.h errlib.h ${openal_src}
)
#deps for the shared library
link_libraries(${VORBISFILE_LIBRARY})
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/errlib.c Sun Oct 11 20:14:55 2009 +0000
@@ -0,0 +1,96 @@
+/*
+
+ module: errlib.c
+
+ purpose: library of error functions
+
+ reference: Stevens, Unix network programming (2ed), p.922
+
+ */
+
+#include "errlib.h"
+
+
+#define MAXLINE 4095
+
+#ifdef __CPLUSPLUS
+extern "C" {
+#endif
+
+ int daemon_proc = 0; /* set to 0 if stdout/stderr available, else set to 1 */
+
+ static void err_doit (int errnoflag, int level, const char *fmt, va_list ap)
+ {
+ int errno_save = errno, n;
+ char buf[MAXLINE+1];
+
+ vsnprintf (buf, MAXLINE, fmt, ap);
+ n = strlen(buf);
+ if (errnoflag)
+ snprintf (buf+n, MAXLINE-n, ": %s", strerror(errno_save));
+ strcat (buf, "\n");
+
+ if (daemon_proc)
+ syslog (level, buf);
+ else {
+ fflush (stdout);
+ fputs (buf, stderr);
+ fflush (stderr);
+ }
+
+ return;
+ }
+
+ void err_ret (const char *fmt, ...)
+ {
+ va_list ap;
+
+ va_start (ap, fmt);
+ err_doit (1, LOG_INFO, fmt, ap);
+ va_end (ap);
+ return;
+ }
+
+ void err_sys (const char *fmt, ...)
+ {
+ va_list ap;
+
+ va_start (ap, fmt);
+ err_doit (1, LOG_ERR, fmt, ap);
+ va_end (ap);
+ exit (1);
+ }
+
+ void err_msg (const char *fmt, ...)
+ {
+ va_list ap;
+
+ va_start (ap, fmt);
+ err_doit (0, LOG_INFO, fmt, ap);
+ va_end (ap);
+ return;
+ }
+
+ void err_quit (const char *fmt, ...)
+ {
+ va_list ap;
+
+ va_start (ap, fmt);
+ err_doit (0, LOG_ERR, fmt, ap);
+ va_end (ap);
+ exit (1);
+ }
+
+ void err_dump (const char *fmt, ...)
+ {
+ va_list ap;
+
+ va_start (ap, fmt);
+ err_doit (1, LOG_ERR, fmt, ap);
+ va_end (ap);
+ abort();
+ }
+
+#ifdef __CPLUSPLUS
+}
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/errlib.h Sun Oct 11 20:14:55 2009 +0000
@@ -0,0 +1,47 @@
+/*
+
+ module: errlib.h
+
+ purpose: definitions of function sin errlib.c
+
+ reference: Stevens, Unix network programming (2ed), p.922
+
+ */
+
+#ifndef _ERRLIB_H
+#define _ERRLIB_H
+
+#include "globals.h"
+
+#ifdef __CPLUSPLUS
+extern "C" {
+#endif
+
+ extern int daemon_proc;
+
+ void err_msg (const char *fmt, ...);
+
+ void err_quit (const char *fmt, ...);
+
+ void err_ret (const char *fmt, ...);
+
+ void err_sys (const char *fmt, ...);
+
+ void err_dump (const char *fmt, ...);
+
+#ifdef __CPLUSPLUS
+}
+#endif
+
+#endif /*_ERRLIB_H*/
+
+/*
+ suggested error string ( PROG ) LEVEL - TEXT : ERRNO
+
+ errno? closeprog? log level
+ err_msg no no LOG_INFO
+ err_quit no exit(1) LOG_ERR
+ err_ret si no LOG_INFO
+ err_sys si exit(1) LOG_ERR
+ err_dump si abort( ) LOG_ERR
+ */
\ No newline at end of file
--- a/openalbridge/globals.h Sun Oct 11 16:23:59 2009 +0000
+++ b/openalbridge/globals.h Sun Oct 11 20:14:55 2009 +0000
@@ -22,7 +22,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
+#include <stdarg.h>
+#include <syslog.h>
#include <string.h>
+#include <errno.h>
#ifndef _WIN32
#include <pthread.h>
@@ -31,8 +34,15 @@
#endif
#include "al.h"
+#include "errlib.h"
+#ifdef TRACE
+#ifndef DEBUG
+#define DEBUG
+#endif
+#endif
+
/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. [Wu Yongwei] **/
#ifndef _SLEEP_H
#define _SLEEP_H
@@ -126,8 +136,10 @@
/*other defines*/
-#define FADE_IN 0
+#define FADE_IN 0
#define FADE_OUT 1
+
+ char *prog;
#ifdef __CPLUSPLUS
}
--- a/openalbridge/loaders.c Sun Oct 11 16:23:59 2009 +0000
+++ b/openalbridge/loaders.c Sun Oct 11 20:14:55 2009 +0000
@@ -18,6 +18,7 @@
#include "loaders.h"
+
#ifdef __CPLUSPLUS
extern "C" {
#endif
@@ -80,7 +81,8 @@
if (t <= 0) {
/*eof*/
- fprintf(stderr, "ERROR 'load_wavpcm()': wrong WAV header\n");
+ errno = EILSEQ;
+ err_ret("(%s) ERROR - wrong WAV header", prog);
return AL_FALSE;
}
} while (1);
@@ -157,7 +159,7 @@
if (result < 0) {
fprintf (stderr, "ERROR 'load_oggvorbis()': ov_fopen failed with %X", result);
ov_clear(&oggStream);
- return -1;
+ return AL_FALSE;
}
/*load OGG header and determine the decoded data size*/
@@ -190,7 +192,8 @@
if (vorbisInfo->channels == 2)
*format = AL_FORMAT_STEREO16;
else {
- fprintf(stderr, "ERROR 'load_oggvorbis()': wrong OGG header - channel value (%d)\n", vorbisInfo->channels);
+ errno = EILSEQ;
+ err_ret("(%s) ERROR - wrong OGG header [channel %d]", prog, vorbisInfo->channels);
ov_clear(&oggStream);
return AL_FALSE;
}
--- a/openalbridge/loaders.h Sun Oct 11 16:23:59 2009 +0000
+++ b/openalbridge/loaders.h Sun Oct 11 20:14:55 2009 +0000
@@ -22,7 +22,6 @@
#include "globals.h"
#include "wrappers.h"
#include "oggvorbis.h"
-#include "endianness.h"
#ifdef __CPLUSPLUS
--- a/openalbridge/openalbridge.c Sun Oct 11 16:23:59 2009 +0000
+++ b/openalbridge/openalbridge.c Sun Oct 11 20:14:55 2009 +0000
@@ -17,10 +17,7 @@
*/
#include "openalbridge.h"
-#include "wrappers.h"
-#include "alc.h"
-#include "loaders.h"
-#include "endianness.h"
+
#ifdef __CPLUSPLUS
extern "C" {
@@ -36,15 +33,16 @@
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;
- }
-
+ /*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);
@@ -68,12 +66,15 @@
return openalReady;
}
- ALboolean openal_init(uint32_t usehardware, uint32_t memorysize) {
+ 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*/
@@ -81,32 +82,29 @@
/*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_init()': OpenAL already initialized\n");
- return AL_FALSE;
- }
+ if (openalReady == AL_TRUE) {
+ errno = EPERM;
+ err_ret("(%s) WARN - OpenAL already initialized", prog);
+ return AL_FALSE;
+ }
- if(usehardware)
- {
- if ((device = alcOpenDevice(NULL)) == NULL) {
- fprintf(stderr, "ERROR 'openal_init()': Failed to open sound device\n");
- return AL_FALSE;
- }
- }
- else
- {
- if ((device = alcOpenDevice("Generic Software")) == NULL) {
- fprintf(stderr, "ERROR 'openal_init()': Failed to open sound device\n");
- return AL_FALSE;
- }
- }
- fprintf(stderr, "Using default device: %s\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
-
- context = alcCreateContext(device, NULL);
- alcMakeContextCurrent(context);
- alcProcessContext(context);
-
- if (AlGetError("ERROR %d in 'openal_init()': Creating a new contex\n") != AL_TRUE)
+ 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*/
@@ -125,7 +123,7 @@
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
- if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE)
+ if (AlGetError("(%s) WARN - Failed to set Listener properties") != AL_TRUE)
return AL_FALSE;
openalReady = AL_TRUE;
@@ -141,7 +139,7 @@
globalsize += increment;
#ifdef DEBUG
- fprintf(stderr, "OpenALBridge: Realloc in process from %d to %d\n", oldsize, globalsize);
+ err_msg("(%s) INFO - Realloc in process from %d to %d\n", prog, oldsize, globalsize);
#endif
Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
@@ -162,10 +160,11 @@
ALenum error;
FILE *fp;
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_loadfile()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ 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)
@@ -173,26 +172,29 @@
/*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 'openal_loadfile()': file %s is too short \n", filename);
- return -2;
+ 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("ERROR %d in 'openal_loadfile()': Allocating memory for buffers\n") != AL_TRUE)
+ if (AlGetError("(%s) ERROR - allocating memory for buffers") != AL_TRUE)
return -3;
/*prepare the source to emit sound*/
alGenSources(1, &Sources[globalindex]);
- if (AlGetError("ERROR %d in 'openal_loadfile()': Allocating memory for sources\n") != AL_TRUE)
+ if (AlGetError("(%s) ERROR - allocating memory for sources") != AL_TRUE)
return -4;
@@ -204,7 +206,8 @@
error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
break;
default:
- fprintf(stderr, "ERROR 'openal_loadfile()': File format (%08X) not supported!\n", ENDIAN_BIG_32(fileformat));
+ errno = EINVAL;
+ err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(fileformat));
return -5;
break;
}
@@ -214,7 +217,7 @@
alBufferData(Buffers[globalindex], format, data, bitsize, freq);
free(data); /*deallocate data to save memory*/
- if (AlGetError("ERROR %d in 'openal_loadfile()': Writing data to buffer\n") != AL_TRUE)
+ if (AlGetError("(%s) ERROR - writing data to buffers") != AL_TRUE)
return -6;
/*set source properties that it will use when it's in playback*/
@@ -225,7 +228,7 @@
alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel );
alSourcei (Sources[globalindex], AL_LOOPING, 0 );
- if (AlGetError("ERROR %d in 'openal_loadfile()': Setting source properties\n") != AL_TRUE)
+ if (AlGetError("(%s) ERROR - setting Source properties") != AL_TRUE)
return -7;
alGetError(); /* clear any AL errors beforehand */
@@ -239,19 +242,21 @@
/*Set or unset looping mode*/
ALint loop;
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_toggleloop()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ if (openalReady == AL_FALSE) {
+ errno = EPERM;
+ err_ret("(%s) WARN - OpenAL not initialized", prog);
+ return AL_FALSE;
+ }
if (index >= globalsize) {
- fprintf(stderr, "ERROR 'openal_toggleloop()': index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
+ 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("ERROR %d in 'openal_toggleloop()': Getting or setting loop property\n") != AL_TRUE)
+ if (AlGetError("(%s) ERROR - getting or setting loop property") != AL_TRUE)
return AL_FALSE;
alGetError(); /* clear any AL errors beforehand */
@@ -261,10 +266,11 @@
ALboolean openal_setvolume (uint32_t index, uint8_t percentage) {
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_setvolume()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ 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) {
@@ -285,10 +291,11 @@
ALboolean openal_setglobalvolume (uint8_t percentage) {
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_setglobalvolume()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ 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)
@@ -307,10 +314,11 @@
/*Mute or unmute sound*/
ALfloat mute;
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_togglemute()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ if (openalReady == AL_FALSE) {
+ errno = EPERM;
+ err_ret("(%s) WARN - OpenAL not initialized", prog);
+ return AL_FALSE;
+ }
alGetListenerf (AL_GAIN, &mute);
if (mute > 0)
@@ -337,10 +345,11 @@
#endif
fade_t *fade;
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_fade()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ 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;
@@ -396,10 +405,11 @@
ALboolean openal_setposition (uint32_t index, float x, float y, float z) {
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_setposition()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ 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);
@@ -415,10 +425,11 @@
ALboolean openal_playsound (uint32_t index){
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_playsound()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ if (openalReady == AL_FALSE) {
+ errno = EPERM;
+ err_ret("(%s) WARN - OpenAL not initialized", prog);
+ return AL_FALSE;
+ }
/*Play sound number index*/
if (index >= globalindex) {
@@ -436,10 +447,11 @@
ALboolean openal_pausesound(uint32_t index){
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_pausesound()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ if (openalReady == AL_FALSE) {
+ errno = EPERM;
+ err_ret("(%s) WARN - OpenAL not initialized", prog);
+ return AL_FALSE;
+ }
/*Pause sound number index*/
if (index >= globalindex) {
@@ -455,10 +467,11 @@
ALboolean openal_stopsound(uint32_t index){
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR 'openal_stopsound()': OpenAL not initialized\n");
- return AL_FALSE;
- }
+ if (openalReady == AL_FALSE) {
+ errno = EPERM;
+ err_ret("(%s) WARN - OpenAL not initialized", prog);
+ return AL_FALSE;
+ }
/*Stop sound number index*/
if (index >= globalindex) {
--- a/openalbridge/openalbridge.h Sun Oct 11 16:23:59 2009 +0000
+++ b/openalbridge/openalbridge.h Sun Oct 11 20:14:55 2009 +0000
@@ -20,12 +20,16 @@
#define _OALB_INTERFACE_H
#include "globals.h"
+#include "wrappers.h"
+#include "alc.h"
+#include "loaders.h"
+
#ifdef __CPLUSPLUS
extern "C" {
#endif
- ALboolean openal_init (unsigned int usehardware, unsigned int memorysize);
+ ALboolean openal_init (char* programname, ALboolean usehardware, unsigned int memorysize);
ALboolean openal_close (void);
ALboolean openal_ready (void);
ALint openal_loadfile (const char *filename);
--- a/openalbridge/wrappers.c Sun Oct 11 16:23:59 2009 +0000
+++ b/openalbridge/wrappers.c Sun Oct 11 20:14:55 2009 +0000
@@ -18,147 +18,147 @@
#include "wrappers.h"
+
#ifdef __CPLUSPLUS
extern "C" {
#endif
-
- extern ALint *Sources;
-
- void *Malloc (size_t nbytes) {
- void *aptr;
-
- if ((aptr = malloc(nbytes)) == NULL) {
- fprintf(stderr, "ERROR 'malloc()': not enough memory\n");
- exit(-1);
- }
- return aptr;
- }
-
-
- void *Realloc (void *aptr, size_t nbytes) {
- aptr = realloc(aptr, nbytes);
+
+ extern ALint *Sources;
- if (aptr == NULL) {
- fprintf(stderr, "ERROR 'realloc()': not enough memory\n");
- free(aptr);
- exit(-1);
+ void *Malloc (size_t nbytes) {
+ void *aptr;
+
+ if ((aptr = malloc(nbytes)) == NULL)
+ err_dump("(%s) FATAL - not enough memory");
+
+ return aptr;
}
- return aptr;
- }
-
-
- FILE *Fopen (const char *fname, char *mode) {
- FILE *fp;
- if ((fp=fopen(fname,mode)) == NULL)
- fprintf (stderr, "ERROR 'fopen()': can't open file %s in mode '%s'\n", fname, mode);
- return fp;
- }
-
- /*TODO make a proper error reporting routine*/
- ALint AlGetError (const char *str) {
- ALenum error;
+
+
+ void *Realloc (void *aptr, size_t nbytes) {
+ aptr = realloc(aptr, nbytes);
+
+ if (aptr == NULL)
+ err_dump("(%s) FATAL - not enough memory");
+
+ return aptr;
+ }
+
- 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;
+ FILE *Fopen (const char *fname, char *mode) {
+ FILE *fp;
+
+ fp = fopen(fname,mode);
+ if (fp == NULL)
+ err_ret("(%s) ERROR - can't open file %s in mode '%s'", prog, fname, mode);
+ return fp;
+ }
- error = alGetError();
- if (error != AL_NO_ERROR) {
- fprintf(stderr, str, error, num);
- return -2;
- } else
- return AL_TRUE;
- }
-
- void *helper_fadein(void *tmp) {
- ALfloat gain;
- ALfloat target_gain;
- fade_t *fade;
- uint32_t index;
- uint16_t quantity;
+ /*TODO make a proper error reporting routine*/
+ ALint AlGetError (const char *str) {
+ ALenum error;
+
+ error = alGetError();
+ if (error != AL_NO_ERROR) {
+ err_msg(str, prog);
+ return error;
+ } else
+ return AL_TRUE;
+ }
- fade = tmp;
- index = fade->index;
- quantity = fade->quantity;
- free (fade);
-
-#ifdef DEBUG
- fprintf(stderr, "Fade-in: index %d quantity %d\n", index, quantity);
-#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) {
-#ifdef DEBUG
- fprintf(stderr, "Fade-in: set gain to: %f\n", gain);
-#endif
- alSourcef(Sources[index], AL_GAIN, gain);
- usleep(10000);
+ 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;
}
- AlGetError("ERROR %d in 'helper_fadein()': Setting fade in volume\n");
-
-#ifndef _WIN32
- pthread_exit(NULL);
-#else
- _endthread();
+ void *helper_fadein(void *tmp) {
+ 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
+ err_msg("(%s) INFO - Fade-in in progress [index %d quantity %d]", prog, index, quantity);
#endif
- return 0;
- }
-
- void *helper_fadeout(void *tmp) {
- 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);
+
+ /*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 TRACE
+ err_msg("(%s) DEBUG - Fade-in set gain to %f", gain);
#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);
+ alSourcef(Sources[index], AL_GAIN, gain);
+ usleep(10000);
+ }
+
+ AlGetError("(%s) WARN - Failed to set fade-in volume level");
+
+#ifndef _WIN32
+ pthread_exit(NULL);
+#else
+ _endthread();
#endif
- alSourcef(Sources[index], AL_GAIN, gain);
- usleep(10000);
+ return 0;
}
- AlGetError("ERROR %d in 'helper_fadeout()': Setting fade out volume\n");
-
- /*stop that sound and reset its volume*/
- alSourceStop (Sources[index]);
- alSourcef (Sources[index], AL_GAIN, old_gain);
-
+ void *helper_fadeout(void *tmp) {
+ 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
+ err_msg("(%s) INFO - Fade-out in progress [index %d quantity %d]", prog, index, quantity);
+#endif
+
+ alGetSourcef(Sources[index], AL_GAIN, &old_gain);
+
+ for (gain = old_gain; gain >= 0.00f; gain -= (float) quantity/10000) {
+#ifdef TRACE
+ err_msg("(%s) DEBUG - Fade-out set gain to %f", gain);
+#endif
+ alSourcef(Sources[index], AL_GAIN, gain);
+ usleep(10000);
+ }
+
+ AlGetError("(%s) WARN - Failed to set fade-out volume level");
+
+ /*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