other indentation, binding and miscellaneous fixes to openalbridge
authorkoda
Sun, 12 Jul 2009 19:12:08 +0000
changeset 2260 31756e21c436
parent 2259 ca42efdce3ce
child 2261 57e99c908e7c
other indentation, binding and miscellaneous fixes to openalbridge
QTfrontend/SDLs.h
openalbridge/endianness.c
openalbridge/endianness.h
openalbridge/globals.h
openalbridge/loaders.c
openalbridge/loaders.h
openalbridge/oggvorbis.h
openalbridge/openalwrap.c
openalbridge/wrappers.h
--- a/QTfrontend/SDLs.h	Sun Jul 12 15:42:54 2009 +0000
+++ b/QTfrontend/SDLs.h	Sun Jul 12 19:12:08 2009 +0000
@@ -21,20 +21,20 @@
 
 #include <QStringList>
 
-extern "C" int openal_init		(unsigned int memorysize);
-extern "C" int openal_close		(void);
-extern "C" int openal_ready		(void);
-extern "C" int openal_loadfile		(const char *filename);
-extern "C" int openal_toggleloop	(unsigned int index);
-extern "C" int openal_setvolume		(unsigned int index, unsigned char percentage);
-extern "C" int openal_setglobalvolume	(unsigned char percentage);
-extern "C" int openal_togglemute	(void);
-extern "C" int openal_fadeout		(unsigned int index, unsigned short int quantity);
-extern "C" int openal_fadein		(unsigned int index, unsigned short int quantity);
-extern "C" int openal_fade		(unsigned int index, unsigned short int quantity, unsigned char direction);
-extern "C" int openal_playsound 	(unsigned int index);
-extern "C" int openal_stopsound		(unsigned int index);
-extern "C" int openal_pausesound	(unsigned int index);
+extern "C" bool openal_init		(unsigned int memorysize);
+extern "C" bool openal_close		(void);
+extern "C" bool openal_ready		(void);
+extern "C" int  openal_loadfile		(const char *filename);
+extern "C" bool openal_toggleloop	(unsigned int index);
+extern "C" bool openal_setvolume	(unsigned int index, unsigned char percentage);
+extern "C" bool openal_setglobalvolume	(unsigned char percentage);
+extern "C" bool openal_togglemute	(void);
+extern "C" bool openal_fadeout		(unsigned int index, unsigned short int quantity);
+extern "C" bool openal_fadein		(unsigned int index, unsigned short int quantity);
+extern "C" bool openal_fade		(unsigned int index, unsigned short int quantity, bool direction);
+extern "C" bool openal_playsound 	(unsigned int index);
+extern "C" bool openal_stopsound	(unsigned int index);
+extern "C" bool openal_pausesound	(unsigned int index);
 
 class SDLInteraction : public QObject
 {
--- a/openalbridge/endianness.c	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/endianness.c	Sun Jul 12 19:12:08 2009 +0000
@@ -21,12 +21,12 @@
 #ifdef __CPLUSPLUS
 extern "C" {
 #endif 
-	
-	/*from big endian to little endian*/
-	int invert_endianness(uint32_t number){
-		return bswap_32(number);
-	}
-	
+    
+    /*from big endian to little endian*/
+    int invert_endianness(uint32_t number){
+        return bswap_32(number);
+    }
+    
 #ifdef __CPLUSPLUS
 }
 #endif
--- a/openalbridge/endianness.h	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/endianness.h	Sun Jul 12 19:12:08 2009 +0000
@@ -25,11 +25,11 @@
 #ifdef __CPLUSPLUS
 extern "C" {
 #endif 
-		
+    
 #pragma once
-	
-	int invert_endianness(uint32_t number);
-	
+    
+    int invert_endianness(uint32_t number);
+    
 #ifdef __CPLUSPLUS
 }
 #endif
--- a/openalbridge/globals.h	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/globals.h	Sun Jul 12 19:12:08 2009 +0000
@@ -65,48 +65,46 @@
 
 #define bswap_16(x)	((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
 
-#define bswap_32(x)	((((x) & 0xFF000000) >> 24) | \
-(((x) & 0x00FF0000) >> 8)  | \
-(((x) & 0x0000FF00) << 8)  | \
-(((x) & 0x000000FF) << 24) )
+#define bswap_32(x)	((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8)  | \
+                         (((x) & 0x0000FF00) << 8)  | (((x) & 0x000000FF) << 24) )
 
 #endif /* HAVE_BYTESWAP_H */
 
 #ifdef __CPLUSPLUS
 extern "C" {
 #endif 
-	
-	/*data type for WAV header*/
+    
+    /*data type for WAV header*/
 #pragma pack(1)
-	typedef struct _WAV_header_t {
-		uint32_t ChunkID;
-		uint32_t ChunkSize;
-		uint32_t Format;
-		uint32_t Subchunk1ID;
-		uint32_t Subchunk1Size;
-		uint16_t AudioFormat;
-		uint16_t NumChannels;
-		uint32_t SampleRate;
-		uint32_t ByteRate;
-		uint16_t BlockAlign;
-		uint16_t BitsPerSample;
-		uint32_t Subchunk2ID;
-		uint32_t Subchunk2Size;
-	} WAV_header_t;
+    typedef struct _WAV_header_t {
+        uint32_t ChunkID;
+        uint32_t ChunkSize;
+        uint32_t Format;
+        uint32_t Subchunk1ID;
+        uint32_t Subchunk1Size;
+        uint16_t AudioFormat;
+        uint16_t NumChannels;
+        uint32_t SampleRate;
+        uint32_t ByteRate;
+        uint16_t BlockAlign;
+        uint16_t BitsPerSample;
+        uint32_t Subchunk2ID;
+        uint32_t Subchunk2Size;
+    } WAV_header_t;
 #pragma pack()
-	
-	/*data type for passing data between threads*/
+    
+    /*data type for passing data between threads*/
 #pragma pack(1)
-	typedef struct _fade_t {
-		uint32_t index;
-		uint16_t quantity;
-	} fade_t;
+    typedef struct _fade_t {
+        uint32_t index;
+        uint16_t quantity;
+    } fade_t;
 #pragma pack()
-	
-	/*other defines*/
+    
+    /*other defines*/
 #define FADE_IN	 true
 #define FADE_OUT false
-	
+    
 #ifdef __CPLUSPLUS
 }
 #endif
--- a/openalbridge/loaders.c	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/loaders.c	Sun Jul 12 19:12:08 2009 +0000
@@ -132,8 +132,7 @@
         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             section, result, size = 0;
 #ifdef DEBUG
         int i;
         vorbis_comment	*vorbisComment;	/*other less useful data*/
@@ -141,7 +140,6 @@
         
         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;	
@@ -173,6 +171,8 @@
                 *format = AL_FORMAT_STEREO16;
             else {
                 fprintf(stderr, "ERROR: wrong OGG header - channel value (%d)\n", vorbisInfo->channels);
+                ov_clear (&oggStream);
+                fclose(oggFile);
                 return AL_FALSE;
             }
         }
@@ -187,6 +187,8 @@
                     break;
                 else { 
                     fprintf(stderr, "ERROR: end of file from OGG stream\n");
+                    ov_clear (&oggStream);
+                    fclose(oggFile);
                     return AL_FALSE;
                 }
             }
@@ -197,6 +199,7 @@
         *freq    = vorbisInfo->rate;
         
         ov_clear (&oggStream);
+        fclose (oggFile);
         return AL_TRUE;
     }
     
--- a/openalbridge/loaders.h	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/loaders.h	Sun Jul 12 19:12:08 2009 +0000
@@ -28,10 +28,10 @@
 #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);
-	
+    
+    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
--- a/openalbridge/oggvorbis.h	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/oggvorbis.h	Sun Jul 12 19:12:08 2009 +0000
@@ -17,192 +17,151 @@
 #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;
+    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;
+    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;
-	
+    /* 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;
-	
+    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;
+    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;
+    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;
-	
+    /* 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);
+    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;
-	
+    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;
 
 
--- a/openalbridge/openalwrap.c	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/openalwrap.c	Sun Jul 12 19:12:08 2009 +0000
@@ -125,11 +125,13 @@
     
     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);
-#endif
+        int oldsize = globalsize;
         globalsize += increment;
 
+#ifdef DEBUG
+        fprintf(stderr, "OpenAL: Realloc in process from %d to %d\n", oldsize, globalsize);
+#endif
+        
         Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
         Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
         
@@ -338,14 +340,14 @@
 #ifndef _WIN32
             pthread_create(&thread, NULL, helper_fadein, (void*) fade);
 #else
-            Thread = _beginthread(&helper_fadein, 0, (void*) fade);
+        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);
+            Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
 #endif	
             else {
                 fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction);
--- a/openalbridge/wrappers.h	Sun Jul 12 15:42:54 2009 +0000
+++ b/openalbridge/wrappers.h	Sun Jul 12 19:12:08 2009 +0000
@@ -22,13 +22,20 @@
 #include "globals.h"
 
 
-void *Malloc (size_t nbytes);
-void *Realloc (void *aptr, size_t nbytes);
-FILE *Fopen (const char *fname, char *mode);
-ALint AlGetError (const char *str);
-ALint AlGetError2 (const char *str, int num);
-void *helper_fadein (void *tmp);
-void *helper_fadeout (void *tmp); 
-
+#ifdef __CPLUSPLUS
+extern "C" {
+#endif
+    
+    void *Malloc (size_t nbytes);
+    void *Realloc (void *aptr, size_t nbytes);
+    FILE *Fopen (const char *fname, char *mode);
+    ALint AlGetError (const char *str);
+    ALint AlGetError2 (const char *str, int num);
+    void *helper_fadein (void *tmp);
+    void *helper_fadeout (void *tmp); 
+    
+#ifdef __CPLUSPLUS
+}
+#endif
 
 #endif /*_OALB_WRAPPERS_H*/