-Smaxx's porting of the library to MSVC compilers
-library is now ANSI C
-interface headers reworked
--- a/QTfrontend/SDLs.cpp Mon Jun 29 23:03:25 2009 +0000
+++ b/QTfrontend/SDLs.cpp Tue Jun 30 12:31:32 2009 +0000
@@ -64,10 +64,10 @@
openal_toggleloop(music);
}
openal_setvolume(music, 60);
- openal_fadein(music, 70);
+ openal_fadein(music, 25);
}
void SDLInteraction::StopMusic()
{
- if (music >= 0) openal_fadeout(music, 70);
+ if (music >= 0) openal_fadeout(music, 40);
}
--- a/hedgewars/CMakeLists.txt Mon Jun 29 23:03:25 2009 +0000
+++ b/hedgewars/CMakeLists.txt Tue Jun 30 12:31:32 2009 +0000
@@ -107,6 +107,10 @@
message(FATAL_ERROR "No Pascal compiler found!")
endif (NOT pascal_compiler)
+#special handling of MSVC compiler (no static linking)
+if(MSVC)
+ set(pascal_compiler_flags "-dMSVC" ${pascal_compiler_flags})
+endif(MSVC)
IF(NOT APPLE OR NOT universal_build MATCHES "1")
#here is the standard command for any system
--- a/hedgewars/uSound.pas Mon Jun 29 23:03:25 2009 +0000
+++ b/hedgewars/uSound.pas Tue Jun 30 12:31:32 2009 +0000
@@ -26,11 +26,13 @@
{$linkframework Ogg}
{$linkframework Vorbis}
{$ELSE}
+{$IFNDEF MSVC}
{$linklib openal}
{$linklib ogg}
{$linklib vorbis}
{$linklib vorbisfile}
{$ENDIF}
+{$ENDIF}
uses uConsts;
{$INCLUDE options.inc}
@@ -186,7 +188,7 @@
WriteLnToConsole(msgOK);
openal_setvolume(Mus, 60);
-openal_fadein(Mus, 70);
+openal_fadein(Mus, 20);
openal_toggleloop(Mus);
end;
--- a/openalbridge/CMakeLists.txt Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/CMakeLists.txt Tue Jun 30 12:31:32 2009 +0000
@@ -23,7 +23,7 @@
if(MSVC)
#workaround for visualstudio (wants headers in the source list)
set(openal_src
- openalwrap.h loaders.h endianness.h wrappers.h winstdint.h globals.h ${openal_src}
+ openalwrap.h loaders.h endianness.h wrappers.h winstdint.h globals.h oggvorbis.h ${openal_src}
)
#deps for the shared library
link_libraries(${OPENAL_LIBRARY})
--- a/openalbridge/endianness.h Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/endianness.h Tue Jun 30 12:31:32 2009 +0000
@@ -16,6 +16,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+#ifndef _OALB_ENDIANNESS_H
+#define _OALB_ENDIANNESS_H
+
#include "globals.h"
@@ -29,4 +32,6 @@
#ifdef __CPLUSPLUS
}
-#endif
\ No newline at end of file
+#endif
+
+#endif /*_OALB_ENDIANNESS_H*/
--- a/openalbridge/globals.h Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/globals.h Tue Jun 30 12:31:32 2009 +0000
@@ -16,27 +16,22 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#ifndef __OLAB_INCLUDES__
-#define __OLAB_INCLUDES__
+#ifndef _OALB_GLOBALS_H
+#define _OALB_GLOBALS_H
#include <stdio.h>
#include <stdlib.h>
-#include "al.h"
-#include "alc.h"
-#include "loaders.h"
-#include "wrappers.h"
-#include "endianness.h"
-#include "openalwrap.h"
#ifndef _WIN32
+#include <stdint.h>
#include <pthread.h>
-#include <stdint.h>
#else
-#define WIN32_LEAN_AND_MEAN
#include <process.h>
#include "winstdint.h"
#endif
+#include "al.h"
+
#ifndef _SLEEP_H
#define _SLEEP_H
/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. * By Wu Yongwei **/
@@ -45,6 +40,7 @@
# include <stdlib.h>
# define sleep(t) _sleep((t) * 1000)
# else
+# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# define sleep(t) Sleep((t) * 1000)
# endif
@@ -108,208 +104,8 @@
#define FADE_IN 11
#define FADE_OUT 12
-
- /*data types for ogg and vorbis that are required to be external*/
-#ifndef ogg_int64_t
-#define ogg_int64_t int64_t
-#endif
-
- typedef struct {
- unsigned char *data;
- int storage;
- int fill;
- int returned;
-
- int unsynced;
- int headerbytes;
- int bodybytes;
- } ogg_sync_state;
- typedef struct vorbis_info{
- int version;
- int channels;
- long rate;
-
- /* The below bitrate declarations are *hints*.
- Combinations of the three values carry the following implications:
-
- all three set to the same value:
- implies a fixed rate bitstream
- only nominal set:
- implies a VBR stream that averages the nominal bitrate. No hard
- upper/lower limit
- upper and or lower set:
- implies a VBR bitstream that obeys the bitrate limits. nominal
- may also be set to give a nominal rate.
- none set:
- the coder does not care to speculate.
- */
-
- long bitrate_upper;
- long bitrate_nominal;
- long bitrate_lower;
- long bitrate_window;
-
- void *codec_setup;
- } vorbis_info;
- typedef struct vorbis_comment{
- /* unlimited user comment fields. libvorbis writes 'libvorbis' whatever vendor is set to in encode */
- char **user_comments;
- int *comment_lengths;
- int comments;
- char *vendor;
-
- } vorbis_comment;
- typedef struct {
- unsigned char *body_data; /* bytes from packet bodies */
- long body_storage; /* storage elements allocated */
- long body_fill; /* elements stored; fill mark */
- long body_returned; /* elements of fill returned */
-
-
- int *lacing_vals; /* The values that will go to the segment table */
- ogg_int64_t *granule_vals;
- /* granulepos values for headers. Not compact
- this way, but it is simple coupled to the lacing fifo */
- long lacing_storage;
- long lacing_fill;
- long lacing_packet;
- long lacing_returned;
-
- unsigned char header[282]; /* working space for header encode */
- int header_fill;
-
- int e_o_s; /* set when we have buffered the last packet in the logical bitstream */
- int b_o_s; /* set after we've written the initial page of a logical bitstream */
- long serialno;
- long pageno;
- ogg_int64_t packetno;
- /* sequence number for decode; the framing
- knows where there's a hole in the data,
- but we need coupling so that the codec
- (which is in a seperate abstraction
- layer) also knows about the gap */
- ogg_int64_t granulepos;
-
- } ogg_stream_state;
- typedef struct vorbis_dsp_state{
- int analysisp;
- vorbis_info *vi;
-
- float **pcm;
- float **pcmret;
- int pcm_storage;
- int pcm_current;
- int pcm_returned;
-
- int preextrapolate;
- int eofflag;
-
- long lW;
- long W;
- long nW;
- long centerW;
-
- ogg_int64_t granulepos;
- ogg_int64_t sequence;
-
- ogg_int64_t glue_bits;
- ogg_int64_t time_bits;
- ogg_int64_t floor_bits;
- ogg_int64_t res_bits;
-
- void *backend_state;
- } vorbis_dsp_state;
- typedef struct {
- long endbyte;
- int endbit;
-
- unsigned char *buffer;
- unsigned char *ptr;
- long storage;
- } oggpack_buffer;
- typedef struct vorbis_block{
- /* necessary stream state for linking to the framing abstraction */
- float **pcm; /* this is a pointer into local storage */
- oggpack_buffer opb;
-
- long lW;
- long W;
- long nW;
- int pcmend;
- int mode;
-
- int eofflag;
- ogg_int64_t granulepos;
- ogg_int64_t sequence;
- vorbis_dsp_state *vd; /* For read-only access of configuration */
-
- /* local storage to avoid remallocing; it's up to the mapping to structure it */
- void *localstore;
- long localtop;
- long localalloc;
- long totaluse;
- struct alloc_chain *reap;
-
- /* bitmetrics for the frame */
- long glue_bits;
- long time_bits;
- long floor_bits;
- long res_bits;
-
- void *internal;
-
- } vorbis_block;
- typedef struct {
- size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
- int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
- int (*close_func) (void *datasource);
- long (*tell_func) (void *datasource);
- } ov_callbacks;
- typedef struct OggVorbis_File {
- void *datasource; /* Pointer to a FILE *, etc. */
- int seekable;
- ogg_int64_t offset;
- ogg_int64_t end;
- ogg_sync_state oy;
-
- /* If the FILE handle isn't seekable (eg, a pipe), only the current stream appears */
- int links;
- ogg_int64_t *offsets;
- ogg_int64_t *dataoffsets;
- long *serialnos;
- ogg_int64_t *pcmlengths;
- /* overloaded to maintain binary
- compatability; x2 size, stores both
- beginning and end values */
- vorbis_info *vi;
- vorbis_comment *vc;
-
- /* Decoding working state local storage */
- ogg_int64_t pcm_offset;
- int ready_state;
- long current_serialno;
- int current_link;
-
- double bittrack;
- double samptrack;
-
- ogg_stream_state os; /* take physical pages, weld into a logical stream of packets */
- vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
- vorbis_block vb; /* local working space for packet->PCM decode */
-
- ov_callbacks callbacks;
-
- } OggVorbis_File;
-
- extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
- extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream);
- extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
- extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream);
- extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
- extern vorbis_comment *ov_comment(OggVorbis_File *f, int num);
-
#ifdef __CPLUSPLUS
}
#endif
-#endif /*__OLAB_INCLUDES__*/
+#endif /*_OALB_GLOBALS_H*/
--- a/openalbridge/loaders.c Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/loaders.c Tue Jun 30 12:31:32 2009 +0000
@@ -22,7 +22,7 @@
extern "C" {
#endif
- int load_WavPcm (const char *filename, ALenum *format, uint8_t** data, ALsizei *bitsize, ALsizei *freq) {
+ int load_WavPcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) {
WAV_header_t WAVHeader;
FILE *wavfile;
int t, n = 0;
@@ -75,7 +75,7 @@
fprintf(stderr, "Subchunk2Size: %d\n", WAVHeader.Subchunk2Size);
#endif
- *data = (uint8_t*) malloc (sizeof(uint8_t) * WAVHeader.Subchunk2Size);
+ *data = (char*) malloc (sizeof(char) * WAVHeader.Subchunk2Size);
/*this could be improved*/
do {
@@ -124,7 +124,7 @@
return AL_TRUE;
}
- int load_OggVorbis (const char *filename, ALenum *format, uint8_t**data, ALsizei *bitsize, ALsizei *freq) {
+ 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*/
@@ -161,7 +161,7 @@
#endif
/*allocates enough room for the decoded data*/
- *data = (uint8_t*) malloc (sizeof(uint8_t) * pcm_length);
+ *data = (char*) malloc (sizeof(char) * pcm_length);
/*there *should* not be ogg at 8 bits*/
if (vorbisInfo->channels == 1)
--- a/openalbridge/loaders.h Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/loaders.h Tue Jun 30 12:31:32 2009 +0000
@@ -16,18 +16,24 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+#ifndef _OALB_LOADERS_H
+#define _OALB_LOADERS_H
+
#include "globals.h"
+#include "wrappers.h"
+#include "oggvorbis.h"
+#include "endianness.h"
#ifdef __CPLUSPLUS
extern "C" {
#endif
-
-#pragma once
-
- int load_WavPcm (const char *filename, ALenum *format, uint8_t **data, ALsizei *bitsize, ALsizei *freq);
- int load_OggVorbis (const char *filename, ALenum *format, uint8_t **data, ALsizei *bitsize, ALsizei *freq);
+
+ 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
\ No newline at end of file
+#endif
+
+#endif /*_OALB_LOADERS_H*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/oggvorbis.h Tue Jun 30 12:31:32 2009 +0000
@@ -0,0 +1,216 @@
+/********************************************************************
+ * *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
+ * *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
+ * by the Xiph.Org Foundation http://www.xiph.org/ *
+ * *
+ ********************************************************************/
+
+#ifndef _OGGVORBIS_H
+#define _OGGVORBIS_H
+
+/*data types for ogg and vorbis that are required to be external*/
+#ifndef ogg_int64_t
+#define ogg_int64_t int64_t
+#endif
+
+typedef struct {
+ unsigned char *data;
+ int storage;
+ int fill;
+ int returned;
+
+ int unsynced;
+ int headerbytes;
+ int bodybytes;
+} ogg_sync_state;
+typedef struct vorbis_info{
+ int version;
+ int channels;
+ long rate;
+
+ /* The below bitrate declarations are *hints*.
+ Combinations of the three values carry the following implications:
+
+ all three set to the same value:
+ implies a fixed rate bitstream
+ only nominal set:
+ implies a VBR stream that averages the nominal bitrate. No hard
+ upper/lower limit
+ upper and or lower set:
+ implies a VBR bitstream that obeys the bitrate limits. nominal
+ may also be set to give a nominal rate.
+ none set:
+ the coder does not care to speculate.
+ */
+
+ long bitrate_upper;
+ long bitrate_nominal;
+ long bitrate_lower;
+ long bitrate_window;
+
+ void *codec_setup;
+} vorbis_info;
+typedef struct vorbis_comment{
+ /* unlimited user comment fields. libvorbis writes 'libvorbis' whatever vendor is set to in encode */
+ char **user_comments;
+ int *comment_lengths;
+ int comments;
+ char *vendor;
+
+} vorbis_comment;
+typedef struct {
+ unsigned char *body_data; /* bytes from packet bodies */
+ long body_storage; /* storage elements allocated */
+ long body_fill; /* elements stored; fill mark */
+ long body_returned; /* elements of fill returned */
+
+
+ int *lacing_vals; /* The values that will go to the segment table */
+ ogg_int64_t *granule_vals;
+ /* granulepos values for headers. Not compact
+ this way, but it is simple coupled to the lacing fifo */
+ long lacing_storage;
+ long lacing_fill;
+ long lacing_packet;
+ long lacing_returned;
+
+ unsigned char header[282]; /* working space for header encode */
+ int header_fill;
+
+ int e_o_s; /* set when we have buffered the last packet in the logical bitstream */
+ int b_o_s; /* set after we've written the initial page of a logical bitstream */
+ long serialno;
+ long pageno;
+ ogg_int64_t packetno;
+ /* sequence number for decode; the framing
+ knows where there's a hole in the data,
+ but we need coupling so that the codec
+ (which is in a seperate abstraction
+ layer) also knows about the gap */
+ ogg_int64_t granulepos;
+
+} ogg_stream_state;
+typedef struct vorbis_dsp_state{
+ int analysisp;
+ vorbis_info *vi;
+
+ float **pcm;
+ float **pcmret;
+ int pcm_storage;
+ int pcm_current;
+ int pcm_returned;
+
+ int preextrapolate;
+ int eofflag;
+
+ long lW;
+ long W;
+ long nW;
+ long centerW;
+
+ ogg_int64_t granulepos;
+ ogg_int64_t sequence;
+
+ ogg_int64_t glue_bits;
+ ogg_int64_t time_bits;
+ ogg_int64_t floor_bits;
+ ogg_int64_t res_bits;
+
+ void *backend_state;
+} vorbis_dsp_state;
+typedef struct {
+ long endbyte;
+ int endbit;
+
+ unsigned char *buffer;
+ unsigned char *ptr;
+ long storage;
+} oggpack_buffer;
+typedef struct vorbis_block{
+ /* necessary stream state for linking to the framing abstraction */
+ float **pcm; /* this is a pointer into local storage */
+ oggpack_buffer opb;
+
+ long lW;
+ long W;
+ long nW;
+ int pcmend;
+ int mode;
+
+ int eofflag;
+ ogg_int64_t granulepos;
+ ogg_int64_t sequence;
+ vorbis_dsp_state *vd; /* For read-only access of configuration */
+
+ /* local storage to avoid remallocing; it's up to the mapping to structure it */
+ void *localstore;
+ long localtop;
+ long localalloc;
+ long totaluse;
+ struct alloc_chain *reap;
+
+ /* bitmetrics for the frame */
+ long glue_bits;
+ long time_bits;
+ long floor_bits;
+ long res_bits;
+
+ void *internal;
+
+} vorbis_block;
+typedef struct {
+ size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
+ int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
+ int (*close_func) (void *datasource);
+ long (*tell_func) (void *datasource);
+} ov_callbacks;
+typedef struct OggVorbis_File {
+ void *datasource; /* Pointer to a FILE *, etc. */
+ int seekable;
+ ogg_int64_t offset;
+ ogg_int64_t end;
+ ogg_sync_state oy;
+
+ /* If the FILE handle isn't seekable (eg, a pipe), only the current stream appears */
+ int links;
+ ogg_int64_t *offsets;
+ ogg_int64_t *dataoffsets;
+ long *serialnos;
+ ogg_int64_t *pcmlengths;
+ /* overloaded to maintain binary
+ compatability; x2 size, stores both
+ beginning and end values */
+ vorbis_info *vi;
+ vorbis_comment *vc;
+
+ /* Decoding working state local storage */
+ ogg_int64_t pcm_offset;
+ int ready_state;
+ long current_serialno;
+ int current_link;
+
+ double bittrack;
+ double samptrack;
+
+ ogg_stream_state os; /* take physical pages, weld into a logical stream of packets */
+ vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
+ vorbis_block vb; /* local working space for packet->PCM decode */
+
+ ov_callbacks callbacks;
+
+} OggVorbis_File;
+
+
+extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
+extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream);
+extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
+extern long ov_read(OggVorbis_File *vf,char *buffer,int length,int bigendianp,int word,int sgned,int *bitstream);
+extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
+extern vorbis_comment *ov_comment(OggVorbis_File *f, int num);
+
+#endif /*_OGGVORBIS_H*/
--- a/openalbridge/openalbridge.def Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/openalbridge.def Tue Jun 30 12:31:32 2009 +0000
@@ -9,20 +9,8 @@
openal_togglemute
openal_fadeout
openal_fadein
+ openal_fade
openal_playsound
openal_pausesound
openal_stopsound
-LIBRARY "openalbridge"
-EXPORTS
- openal_init
- openal_close
- openal_loadfile
- openal_toggleloop
- openal_setvolume
- openal_setglobalvolume
- openal_togglemute
- openal_fadeout
- openal_fadein
- openal_playsound
- openal_pausesound
- openal_stopsound
+
--- a/openalbridge/openalwrap.c Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/openalwrap.c Tue Jun 30 12:31:32 2009 +0000
@@ -16,7 +16,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#include "openalwrap.h"
+#include "globals.h"
+#include "wrappers.h"
+#include "alc.h"
+#include "loaders.h"
+#include "endianness.h"
#ifdef __CPLUSPLUS
extern "C" {
@@ -27,16 +31,15 @@
/*Buffers hold sound data*/
ALuint *Buffers;
/*index for Sources and Buffers*/
- ALuint globalindex, globalsize;
+ ALuint globalindex, globalsize, increment;
/*Position of the source sound*/
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };
/*Velocity of the source sound*/
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };
- int increment;
ALint openal_close(void) {
- /* This function stops all the sounds, deallocates all memory and closes OpenAL */
+ /*Stop all sounds, deallocate all memory and close OpenAL */
ALCcontext *context;
ALCdevice *device;
@@ -58,7 +61,7 @@
ALint openal_init(int memorysize) {
- /* This function initializes an OpenAL contex, allocates memory space for data and prepares OpenAL buffers*/
+ /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
ALCcontext *context;
ALCdevice *device;
const ALCchar *default_device;
@@ -104,33 +107,32 @@
return AL_TRUE;
}
+
int helper_realloc (void) {
+ /*expands allocated memory when loading more sound files than expected*/
globalsize += increment;
#ifdef DEBUG
fprintf(stderr, "OpenAL: Realloc in process %d\n", globalsize);
#endif
- Buffers = (ALuint*) reallocf(Buffers, sizeof(ALuint)*globalsize);
- Sources = (ALuint*) reallocf(Sources, sizeof(ALuint)*globalsize);
- if (Buffers == NULL || Sources == NULL) {
- fprintf(stderr, "ERROR: not enough memory! realloc() failed\n");
- exit(-1);
- } else {
- return 0;
- }
+ Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
+ Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
+
+ return 0;
}
int openal_loadfile (const char *filename){
- /* This function opens a file, loads into memory and allocates the Source buffer for playing*/
+ /*Open a file, load into memory and allocate the Source buffer for playing*/
ALenum format;
ALsizei bitsize;
ALsizei freq;
- uint8_t *data;
+ char *data;
uint32_t fileformat;
int error;
FILE *fp;
+ /*when the buffers are all used, we can expand memory to accept new files*/
if (globalindex == globalsize)
helper_realloc();
@@ -224,7 +226,7 @@
if (percentage > 100)
percentage = 100;
- alSourcef (Sources[index], AL_GAIN, (ALfloat) percentage/100.0f);
+ alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f);
if (AlGetError("ERROR %d: Setting volume for last sound\n") != AL_TRUE)
return AL_FALSE;
@@ -238,7 +240,7 @@
/*Set volume for all sounds*/
if (percentage > 100)
percentage = 100;
- alListenerf (AL_GAIN, (ALfloat) percentage/100.0f);
+ alListenerf (AL_GAIN, (float) percentage/100.0f);
if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE)
return AL_FALSE;
@@ -267,7 +269,8 @@
}
- ALint openal_fade(int index, unsigned int quantity, char inout) {
+ ALint openal_fade(int index, unsigned int quantity, char direction) {
+ /*Fade in or out by calling a helper thread*/
#ifndef _WIN32
pthread_t thread;
#else
@@ -285,21 +288,21 @@
return AL_FALSE;
}
- if (inout == FADE_IN)
+ 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 (inout == FADE_OUT)
+ 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", inout);
+ fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction);
free(fade);
return AL_FALSE;
}
@@ -316,11 +319,13 @@
ALint openal_fadeout(int index, unsigned int quantity) {
+ /*wrapper for fadeout*/
return openal_fade(index, quantity, FADE_OUT);
}
ALint openal_fadein(int index, unsigned int quantity) {
+ /*wrapper for fadein*/
return openal_fade(index, quantity, FADE_IN);
}
--- a/openalbridge/openalwrap.h Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/openalwrap.h Tue Jun 30 12:31:32 2009 +0000
@@ -16,29 +16,30 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#include "globals.h"
+#ifndef _OALB_INTERFACE_H
+#define _OALB_INTERFACE_H
#ifdef __CPLUSPLUS
extern "C" {
#endif
-
-#pragma once
-
- ALint openal_init (int memorysize);
- ALint openal_close (void);
- int openal_loadfile (const char *filename);
- ALint openal_toggleloop (int index);
- ALint openal_setvolume (int index, unsigned char percentage);
- ALint openal_setglobalvolume (unsigned char percentage);
- ALint openal_togglemute (void);
- ALint openal_fadeout (int index, unsigned int quantity);
- ALint openal_fadein (int index, unsigned int quantity);
- ALint openal_fade (int index, unsigned int quantity, char direction);
- ALint openal_playsound (int index);
- ALint openal_pausesound (int index);
- ALint openal_stopsound (int index);
+
+ int openal_init (int memorysize);
+ int openal_close (void);
+ int openal_loadfile (const char *filename);
+ int openal_toggleloop (int index);
+ int openal_setvolume (int index, unsigned char percentage);
+ int openal_setglobalvolume (unsigned char percentage);
+ int openal_togglemute (void);
+ int openal_fadeout (int index, unsigned int quantity);
+ int openal_fadein (int index, unsigned int quantity);
+ int openal_fade (int index, unsigned int quantity, char direction);
+ int openal_playsound (int index);
+ int openal_pausesound (int index);
+ int openal_stopsound (int index);
#ifdef __CPLUSPLUS
}
-#endif
\ No newline at end of file
+#endif
+
+#endif /*_OALB_INTERFACE_H*/
--- a/openalbridge/wrappers.c Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/wrappers.c Tue Jun 30 12:31:32 2009 +0000
@@ -24,7 +24,7 @@
extern ALint *Sources;
- void *Malloc (size_t nbytes){
+ void *Malloc (size_t nbytes) {
void *aptr;
if ((aptr = malloc(nbytes)) == NULL) {
fprintf(stderr, "ERROR: not enough memory! malloc() failed\n");
@@ -34,6 +34,23 @@
}
+ void *Realloc (void *aptr, size_t nbytes) {
+#ifndef _WIN32
+ aptr = reallocf(aptr, nbytes);
+#else
+ aptr = realloc(aptr, nbytes);
+#endif
+ if (aptr == NULL) {
+ fprintf(stderr, "ERROR: not enough memory! realloc() failed\n");
+#ifdef _WIN32
+ free(aptr);
+#endif
+ exit(-1);
+ }
+ return aptr;
+ }
+
+
FILE *Fopen (const char *fname, char *mode) {
FILE *fp;
if ((fp=fopen(fname,mode)) == NULL)
@@ -57,7 +74,7 @@
#ifndef _WIN32
void *helper_fadein(void *tmp)
#else
- void WINAPI helper_fadein(void *tmp)
+ void *helper_fadein(void *tmp)
#endif
{
ALfloat gain;
@@ -103,7 +120,7 @@
#ifndef _WIN32
void *helper_fadeout(void *tmp)
#else
- void WINAPI helper_fadeout(void *tmp)
+ void *helper_fadeout(void *tmp)
#endif
{
ALfloat gain;
@@ -144,6 +161,7 @@
#endif
}
+
#ifdef __CPLUSPLUS
}
#endif
\ No newline at end of file
--- a/openalbridge/wrappers.h Mon Jun 29 23:03:25 2009 +0000
+++ b/openalbridge/wrappers.h Tue Jun 30 12:31:32 2009 +0000
@@ -16,17 +16,22 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
+#ifndef _OALB_WRAPPERS_H
+#define _OALB_WRAPPERS_H
+
#include "globals.h"
-#pragma once
void *Malloc (size_t nbytes);
+void *Realloc (void *aptr, size_t nbytes);
FILE *Fopen (const char *fname, char *mode);
ALint AlGetError (const char *str);
#ifndef _WIN32
void *helper_fadein (void *tmp);
void *helper_fadeout (void *tmp);
#else
-void WINAPI helper_fadein (void *tmp);
-void WINAPI helper_fadeout (void *tmp);
-#endif
\ No newline at end of file
+void *helper_fadein (void *tmp);
+void *helper_fadeout (void *tmp);
+#endif
+
+#endif /*_OALB_WRAPPERS_H*/