--- a/openalbridge/errlib.c Wed Oct 14 22:12:02 2009 +0000
+++ b/openalbridge/errlib.c Wed Oct 14 22:21:25 2009 +0000
@@ -9,88 +9,80 @@
*/
#include "errlib.h"
-#include <stdarg.h>
#define MAXLINE 4095
-#ifdef __CPLUSPLUS
-extern "C" {
-#endif
-
- int daemon_proc = 0; /* set to 0 if stdout/stderr available, else set to 1 */
+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];
- 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);
- fprintf (stderr, buf);
- fflush (stderr);
- }
-
- return;
- }
+ vsnprintf (buf, MAXLINE, fmt, ap);
+ n = strlen(buf);
+ if (errnoflag)
+ snprintf (buf+n, MAXLINE-n, ": %s", strerror(errno_save));
+ strcat (buf, "\n");
- void err_ret (const char *fmt, ...)
- {
- va_list ap;
-
- va_start (ap, fmt);
- err_doit (1, LOG_INFO, fmt, ap);
- va_end (ap);
- return;
+ if (daemon_proc)
+ syslog (level, buf);
+ else {
+ fflush (stdout);
+ fprintf (stderr, buf);
+ fflush (stderr);
}
- 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);
- }
+ return;
+}
+
+void err_ret (const char *fmt, ...)
+{
+ va_list ap;
- void err_msg (const char *fmt, ...)
- {
- va_list ap;
-
- va_start (ap, fmt);
- err_doit (0, LOG_INFO, fmt, ap);
- va_end (ap);
- return;
- }
+ 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;
- 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);
- }
+ va_start (ap, fmt);
+ err_doit (0, LOG_INFO, fmt, ap);
+ va_end (ap);
+ return;
+}
+
+void err_quit (const char *fmt, ...)
+{
+ va_list ap;
- void err_dump (const char *fmt, ...)
- {
- va_list ap;
-
- va_start (ap, fmt);
- err_doit (1, LOG_ERR, fmt, ap);
- va_end (ap);
- abort();
- }
+ 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;
-#ifdef __CPLUSPLUS
+ va_start (ap, fmt);
+ err_doit (1, LOG_ERR, fmt, ap);
+ va_end (ap);
+ abort();
}
-#endif
+
--- a/openalbridge/errlib.h Wed Oct 14 22:12:02 2009 +0000
+++ b/openalbridge/errlib.h Wed Oct 14 22:21:25 2009 +0000
@@ -12,22 +12,14 @@
#define _ERRLIB_H
#include "common.h"
-
-#ifdef __CPLUSPLUS
-extern "C" {
-#endif
- extern int daemon_proc;
+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
+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, ...);
#endif /*_ERRLIB_H*/
--- a/openalbridge/loaders.h Wed Oct 14 22:12:02 2009 +0000
+++ b/openalbridge/loaders.h Wed Oct 14 22:21:25 2009 +0000
@@ -23,17 +23,10 @@
#include "common.h"
#include "wrappers.h"
#include "oggvorbis.h"
+
extern char *prog;
-#ifdef __CPLUSPLUS
-extern "C" {
-#endif
-
- int load_wavpcm (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq);
- int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq);
-
-#ifdef __CPLUSPLUS
-}
-#endif
+int load_wavpcm (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq);
+int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq);
#endif /*_OALB_LOADERS_H*/
--- a/openalbridge/openalbridge.c Wed Oct 14 22:12:02 2009 +0000
+++ b/openalbridge/openalbridge.c Wed Oct 14 22:21:25 2009 +0000
@@ -40,8 +40,13 @@
ALCdevice *device;
ALuint sources[MAX_SOURCES];
-
-
+char SSound_load (SSound_t* pSound, const char* cFilename);
+void SSound_close (SSound_t* pSound);
+void SSound_play (SSound_t* pSound, const char bLoop);
+void SSound_pause (const SSound_t* pSound);
+void SSound_continue (const SSound_t* pSound);
+void SSound_stop (SSound_t* pSound);
+void SSound_volume (const SSound_t* pSound, const float fPercentage);
/**
@@ -57,7 +62,7 @@
* 2 error
*/
-char oalb_init (const char* programname, const char usehardware) {
+const char oalb_init (const char* programname, const char usehardware) {
prog = (char *) programname;
if (oalbReady == AL_TRUE) {
@@ -98,7 +103,6 @@
if (AlGetError("(%s) WARN - Failed to create a new contex") != AL_TRUE)
return AL_FALSE;
-
/*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/
alListenerf (AL_GAIN, 1.0f);
alListenerfv(AL_POSITION, NV);
@@ -120,18 +124,17 @@
/**
- * void oalb_close(void)
+ * void oalb_close (void)
*
* ARGUMENTS
* -
* DESCRIPTION
- *
+ * Stop all sounds, deallocate all memory and close OpenAL
* RETURN
* -
*/
-void oalb_close(void) {
- /*Stop all sounds, deallocate all memory and close OpenAL */
+void oalb_close (void) {
int i;
if (oalbReady == 0) {
@@ -157,7 +160,18 @@
return;
}
-char oalb_ready(void) {
+/**
+ * char oalb_ready (void)
+ *
+ * ARGUMENTS
+ * -
+ * DESCRIPTION
+ *
+ * RETURN
+ * -
+ */
+
+char oalb_ready (void) {
return oalbReady;
}
@@ -172,7 +186,7 @@
* -
*/
-int32_t oalb_loadfile (const char *filename) {
+const int32_t oalb_loadfile (const char *filename) {
int i;
if (oalbReady == 0) {
@@ -198,33 +212,6 @@
}
-/*
- ALboolean openal_toggleloop (uint32_t index){
- /*Set or unset looping mode
- ALint loop;
-
- if (oalbReady == 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;
- }
- */
void oalb_setvolume (const uint32_t iIndex, const char cPercentage) {
if (oalbReady == 0) {
@@ -275,31 +262,33 @@
return;
}
-/*
- ALboolean openal_togglemute () {
- /*Mute or unmute sound
- ALfloat mute;
-
- if (oalbReady == 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;
- }
-
+
+void oalb_togglemute (void) {
+ /*Mute or unmute sound*/
+ ALfloat mute;
+
+ if (oalbReady == AL_FALSE) {
+ errno = EPERM;
+ err_ret("(%s) WARN - OpenAL not initialized", prog);
+ return;
+ }
+
+ 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;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return;
+}
+ /*
ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) {
/*Fade in or out by calling a helper thread
--- a/openalbridge/openalbridge.h Wed Oct 14 22:12:02 2009 +0000
+++ b/openalbridge/openalbridge.h Wed Oct 14 22:21:25 2009 +0000
@@ -29,33 +29,26 @@
extern "C" {
#endif
- char oalb_init (const char* programname, const char usehardware);
- void oalb_close (void);
- char oalb_ready (void);
- int32_t oalb_loadfile (const char* cFilename);
- void oalb_playsound (const uint32_t iIndex, const char bLoop);
- void oalb_pausesound (const uint32_t iIndex);
- void oalb_stopsound (const uint32_t iIndex);
- void oalb_setvolume (const uint32_t iIndex, const char cPercentage);
- void oalb_setglobalvolume (const char cPercentage);
-
+ const char oalb_init (const char* programname, const char usehardware);
+ void oalb_close (void);
+ char oalb_ready (void);
+ const int32_t oalb_loadfile (const char* cFilename);
+ void oalb_playsound (const uint32_t iIndex, const char bLoop);
+ void oalb_pausesound (const uint32_t iIndex);
+ void oalb_stopsound (const uint32_t iIndex);
+ void oalb_setvolume (const uint32_t iIndex, const char cPercentage);
+ void oalb_setglobalvolume (const char cPercentage);
+ void oalb_togglemute (void);
/*
- ALboolean openal_toggleloop (unsigned int index);
ALboolean openal_setposition (unsigned int index, float x, float y, float z);
- ALboolean openal_togglemute (void);
ALboolean openal_fadeout (unsigned int index, unsigned short int quantity);
ALboolean openal_fadein (unsigned int index, unsigned short int quantity);
ALboolean openal_fade (unsigned int index, unsigned short int quantity, ALboolean direction);
ALboolean openal_pausesound (unsigned int index);
*/
- char SSound_load (SSound_t* pSound, const char* cFilename);
- void SSound_close (SSound_t* pSound);
- void SSound_play (SSound_t* pSound, const char bLoop);
- void SSound_pause (const SSound_t* pSound);
- void SSound_continue (const SSound_t* pSound);
- void SSound_stop (SSound_t* pSound);
- void SSound_volume (const SSound_t* pSound, const float fPercentage);
+
+
#ifdef __cplusplus
}
#endif
--- a/openalbridge/wrappers.c Wed Oct 14 22:12:02 2009 +0000
+++ b/openalbridge/wrappers.c Wed Oct 14 22:21:25 2009 +0000
@@ -20,66 +20,62 @@
extern char *prog;
-#ifdef __CPLUSPLUS
-extern "C" {
-#endif
+//extern ALint *Sources;
+
+void *Malloc (size_t nbytes) {
+ void *aptr;
- extern ALint *Sources;
+ if ((aptr = malloc(nbytes)) == NULL)
+ err_dump("(%s) FATAL - not enough memory");
- void *Malloc (size_t nbytes) {
- void *aptr;
-
- if ((aptr = malloc(nbytes)) == NULL)
- err_dump("(%s) FATAL - not enough memory");
-
- return aptr;
- }
-
+ return aptr;
+}
+
+
+void *Realloc (void *aptr, size_t nbytes) {
+ aptr = realloc(aptr, nbytes);
- void *Realloc (void *aptr, size_t nbytes) {
- aptr = realloc(aptr, nbytes);
-
- if (aptr == NULL)
- err_dump("(%s) FATAL - not enough memory");
-
- return aptr;
- }
+ if (aptr == NULL)
+ err_dump("(%s) FATAL - not enough memory");
+ return aptr;
+}
+
+
+FILE *Fopen (const char *fname, char *mode) {
+ FILE *fp;
- 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;
- }
+ fp = fopen(fname,mode);
+ if (fp == NULL)
+ err_ret("(%s) ERROR - can't open file %s in mode '%s'", prog, fname, mode);
+
+ return fp;
+}
+
+/*TODO make a proper error reporting routine*/
+ALint AlGetError (const char *str) {
+ ALenum error;
- /*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;
- }
+ error = alGetError();
+ if (error != AL_NO_ERROR) {
+ err_msg(str, prog);
+ return error;
+ } else
+ return AL_TRUE;
+}
+
+ALint AlGetError2 (const char *str, int num) {
+ ALenum error;
- ALint AlGetError2 (const char *str, int num) {
- ALenum error;
-
- error = alGetError();
- if (error != AL_NO_ERROR) {
- err_msg(str, prog, num);
- return error;
- } else
- return AL_TRUE;
- }
-
- /* void *helper_fadein(void *tmp) {
+ error = alGetError();
+ if (error != AL_NO_ERROR) {
+ err_msg(str, prog, num);
+ return error;
+ } else
+ return AL_TRUE;
+}
+
+/* void *helper_fadein(void *tmp) {
ALfloat gain;
ALfloat target_gain;
fade_t *fade;
@@ -161,6 +157,3 @@
}
*/
-#ifdef __CPLUSPLUS
-}
-#endif