# HG changeset patch # User koda # Date 1246316605 0 # Node ID 6b5da1a2765ac3eccad25f4b6e3dc30b2a7e015b # Parent 288360b78f30b56bfae98246bad7935a159a6347 -openalbridge headers cleaned -static building of lib for non MSVC compilers diff -r 288360b78f30 -r 6b5da1a2765a QTfrontend/CMakeLists.txt --- a/QTfrontend/CMakeLists.txt Mon Jun 29 20:01:05 2009 +0000 +++ b/QTfrontend/CMakeLists.txt Mon Jun 29 23:03:25 2009 +0000 @@ -172,8 +172,8 @@ openalbridge ) -#since openalbridge is linked statically in human systems we need to explicitly link dependencies -if(UNIX) +#since openalbridge is linked statically with non-m$ compilers we need to explicitly link dependencies +if(NOT MSVC) set(HW_LINK_LIBS ${OPENAL_LIBRARY} ${OGG_LIBRARY} @@ -186,7 +186,7 @@ ${HW_LINK_LIBS} ) endif(NOT APPLE) -endif(UNIX) +endif(NOT MSVC) if(WIN32 AND NOT UNIX) diff -r 288360b78f30 -r 6b5da1a2765a hedgewars/uSound.pas --- a/hedgewars/uSound.pas Mon Jun 29 20:01:05 2009 +0000 +++ b/hedgewars/uSound.pas Mon Jun 29 23:03:25 2009 +0000 @@ -26,13 +26,11 @@ {$linkframework Ogg} {$linkframework Vorbis} {$ELSE} -{$IFDEF UNIX} {$linklib openal} {$linklib ogg} {$linklib vorbis} {$linklib vorbisfile} {$ENDIF} -{$ENDIF} uses uConsts; {$INCLUDE options.inc} diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/CMakeLists.txt --- a/openalbridge/CMakeLists.txt Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/CMakeLists.txt Mon Jun 29 23:03:25 2009 +0000 @@ -19,10 +19,11 @@ #build a static library for human systems set (build_type STATIC) -if(WIN32) +#visualstudio doesn't like static linking, so we're building a shared library just for it +if(MSVC) #workaround for visualstudio (wants headers in the source list) set(openal_src - openalwrap.h loaders.h endianness.h wrappers.h winstdint.h ${openal_src} + openalwrap.h loaders.h endianness.h wrappers.h winstdint.h globals.h ${openal_src} ) #deps for the shared library link_libraries(${OPENAL_LIBRARY}) @@ -31,7 +32,7 @@ link_libraries(${VORBISFILE_LIBRARY}) #build a shared library set (build_type SHARED) -endif(WIN32) +endif(MSVC) #compiles and links actual library add_library (openalbridge ${build_type} ${openal_src}) diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/endianness.c --- a/openalbridge/endianness.c Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/endianness.c Mon Jun 29 23:03:25 2009 +0000 @@ -22,7 +22,7 @@ extern "C" { #endif - //from big endian to little endian + /*from big endian to little endian*/ int invert_endianness(int number){ return bswap_32(number); } diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/endianness.h --- a/openalbridge/endianness.h Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/endianness.h Mon Jun 29 23:03:25 2009 +0000 @@ -16,35 +16,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include -#include +#include "globals.h" -#ifndef _WIN32 -#include -#else -#include "winstdint.h" -#endif #ifdef __CPLUSPLUS extern "C" { #endif - -#ifdef HAVE_BYTESWAP_H - /* use byteswap macros from the host system, hopefully optimized ones ;-) */ -#include -#else - /* define our own version, simple, stupid, straight-forward... */ - -#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) ) - -#endif - - + #pragma once int invert_endianness(int number); diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/globals.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openalbridge/globals.h Mon Jun 29 23:03:25 2009 +0000 @@ -0,0 +1,315 @@ +/* + * OpenAL Bridge - a simple portable library for OpenAL interface + * Copyright (c) 2009 Vittorio Giovara + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef __OLAB_INCLUDES__ +#define __OLAB_INCLUDES__ + +#include +#include +#include "al.h" +#include "alc.h" +#include "loaders.h" +#include "wrappers.h" +#include "endianness.h" +#include "openalwrap.h" + +#ifndef _WIN32 +#include +#include +#else +#define WIN32_LEAN_AND_MEAN +#include +#include "winstdint.h" +#endif + +#ifndef _SLEEP_H +#define _SLEEP_H +/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. * By Wu Yongwei **/ +#ifdef _WIN32 +# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) +# include +# define sleep(t) _sleep((t) * 1000) +# else +# include +# define sleep(t) Sleep((t) * 1000) +# endif +# ifndef _NEED_SLEEP_ONLY +# define msleep(t) Sleep(t) +# define usleep(t) Sleep((t) / 1000) +# endif +#else +# include +# ifndef _NEED_SLEEP_ONLY +# define msleep(t) usleep((t) * 1000) +# endif +#endif +#endif /* _SLEEP_H */ + +#ifdef HAVE_BYTESWAP_H +/* use byteswap macros from the host system, hopefully optimized ones ;-) */ +#include +#else +/* define our own version, simple, stupid, straight-forward... */ + +#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) ) + +#endif /* HAVE_BYTESWAP_H */ + +#ifdef __CPLUSPLUS +extern "C" { +#endif + + /*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; +#pragma pack() + + /*data type for passing data between threads*/ + typedef struct _fade_t { + int index; + unsigned int quantity; + } fade_t; + + /*other defines*/ +#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__*/ diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/loaders.c --- a/openalbridge/loaders.c Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/loaders.c Mon Jun 29 23:03:25 2009 +0000 @@ -22,13 +22,6 @@ extern "C" { #endif - 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); - int load_WavPcm (const char *filename, ALenum *format, uint8_t** data, ALsizei *bitsize, ALsizei *freq) { WAV_header_t WAVHeader; FILE *wavfile; @@ -66,11 +59,11 @@ fprintf(stderr, "BitsPerSample: %d\n", WAVHeader.BitsPerSample); #endif - do { //remove useless header chunks (plenty room for improvements) + 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 found + if (t <= 0) { /*eof*/ fprintf(stderr, "ERROR: wrong WAV header\n"); return AL_FALSE; } @@ -84,7 +77,7 @@ *data = (uint8_t*) malloc (sizeof(uint8_t) * WAVHeader.Subchunk2Size); - //this could be improved + /*this could be improved*/ do { n += fread(&((*data)[n]), sizeof(uint8_t), 1, wavfile); } while (n < WAVHeader.Subchunk2Size); @@ -96,7 +89,7 @@ #endif /*remaining parameters*/ - //Valid formats are AL_FORMAT_MONO8, AL_FORMAT_MONO16, AL_FORMAT_STEREO8, and AL_FORMAT_STEREO16. + /*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; @@ -132,21 +125,21 @@ } int load_OggVorbis (const char *filename, ALenum *format, uint8_t**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 + /*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 + 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 + /*TODO: check returning value of result*/ vorbisInfo = ov_info(&oggStream, -1); pcm_length = ov_pcm_total(&oggStream,-1) << vorbisInfo->channels; @@ -167,10 +160,10 @@ fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]); #endif - //allocates enough room for the decoded data + /*allocates enough room for the decoded data*/ *data = (uint8_t*) malloc (sizeof(uint8_t) * pcm_length); - //there *should* not be ogg at 8 bits + /*there *should* not be ogg at 8 bits*/ if (vorbisInfo->channels == 1) *format = AL_FORMAT_MONO16; else { @@ -183,7 +176,7 @@ } while(size < pcm_length) { - //ov_read decodes the ogg stream and storse the pcm in data + /*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; @@ -197,7 +190,7 @@ } } - //records the last fields + /*records the last fields*/ *bitsize = size; *freq = vorbisInfo->rate; return AL_TRUE; diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/loaders.h --- a/openalbridge/loaders.h Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/loaders.h Mon Jun 29 23:03:25 2009 +0000 @@ -15,18 +15,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include -#include -#include "al.h" -#include "alc.h" -#include "endianness.h" -#include "wrappers.h" -#ifndef _WIN32 -#include -#else -#include "winstdint.h" -#endif +#include "globals.h" + #ifdef __CPLUSPLUS extern "C" { @@ -34,221 +25,6 @@ #pragma once -#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; -#pragma pack() - - /*data types for ogg and vorbis*/ -#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; - - 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); diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/openalwrap.c --- a/openalbridge/openalwrap.c Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/openalwrap.c Mon Jun 29 23:03:25 2009 +0000 @@ -22,15 +22,15 @@ extern "C" { #endif - // Sources are points emitting sound. + /*Sources are points emitting sound*/ ALuint *Sources; - // Buffers hold sound data. + /*Buffers hold sound data*/ ALuint *Buffers; - //index for Sources and Buffers + /*index for Sources and Buffers*/ ALuint globalindex, globalsize; - // Position of the source sound. + /*Position of the source sound*/ ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; - // Velocity of the source sound. + /*Velocity of the source sound*/ ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; int increment; @@ -63,11 +63,11 @@ ALCdevice *device; const ALCchar *default_device; - // Position of the listener. + /*Position of the listener*/ ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; - // Velocity of the listener. + /*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") + /*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 }; default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); @@ -85,13 +85,13 @@ if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE) return AL_FALSE; - //allocate memory space for buffers and sources + /*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 + /*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); @@ -146,23 +146,23 @@ return -2; } - //prepare the buffers to receive data + /*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 sources to emit sound + /*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 + if (fileformat == 0x5367674F) /*check if ogg*/ error = load_OggVorbis (filename, &format, &data, &bitsize, &freq); else { - if (fileformat == 0x46464952) //check if wav + 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)); @@ -170,14 +170,14 @@ } } - //copy pcm data in one buffer + /*copy pcm data in one buffer*/ alBufferData(Buffers[globalindex], format, data, bitsize, freq); - free(data); //deallocate data to save memory + free(data); /*deallocate data to save memory*/ if (AlGetError("ERROR %d: Writing data to buffer\n") != AL_TRUE) return -6; - //source properties that it will use when it's in playback + /*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 ); @@ -190,7 +190,7 @@ alGetError(); /* clear any AL errors beforehand */ - //returns the index of the source you just loaded, increments it and exits + /*returns the index of the source you just loaded, increments it and exits*/ return globalindex++; } diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/openalwrap.h --- a/openalbridge/openalwrap.h Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/openalwrap.h Mon Jun 29 23:03:25 2009 +0000 @@ -16,22 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include -#include -#include "al.h" -#include "alc.h" -#include "loaders.h" -#include "wrappers.h" -#include "endianness.h" - -#ifndef _WIN32 -#include -#include -#else -#define WIN32_LEAN_AND_MEAN -#include -#include "winstdint.h" -#endif +#include "globals.h" #ifdef __CPLUSPLUS @@ -54,8 +39,6 @@ ALint openal_pausesound (int index); ALint openal_stopsound (int index); -#define FADE_IN 11 -#define FADE_OUT 12 #ifdef __CPLUSPLUS } #endif \ No newline at end of file diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/wrappers.c --- a/openalbridge/wrappers.c Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/wrappers.c Mon Jun 29 23:03:25 2009 +0000 @@ -75,7 +75,7 @@ fprintf(stderr, "Fade-out: index %d quantity %d\n", index, quantity); #endif - //save the volume desired after the fade + /*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; @@ -133,7 +133,7 @@ AlGetError("ERROR %d: Setting fade out volume\n"); - //stop that sound and reset its volume + /*stop that sound and reset its volume*/ alSourceStop (Sources[index]); alSourcef (Sources[index], AL_GAIN, old_gain); diff -r 288360b78f30 -r 6b5da1a2765a openalbridge/wrappers.h --- a/openalbridge/wrappers.h Mon Jun 29 20:01:05 2009 +0000 +++ b/openalbridge/wrappers.h Mon Jun 29 23:03:25 2009 +0000 @@ -16,49 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include -#include -#include "al.h" - -#ifndef _WIN32 -#include -#include -#else -#define WIN32_LEAN_AND_MEAN -#include -#include "winstdint.h" -#endif - -#ifndef _SLEEP_H -#define _SLEEP_H -/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. * By Wu Yongwei **/ -#ifdef _WIN32 -# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) -# include -# define sleep(t) _sleep((t) * 1000) -# else -# include -# define sleep(t) Sleep((t) * 1000) -# endif -# ifndef _NEED_SLEEP_ONLY -# define msleep(t) Sleep(t) -# define usleep(t) Sleep((t) / 1000) -# endif -#else -# include -# ifndef _NEED_SLEEP_ONLY -# define msleep(t) usleep((t) * 1000) -# endif -#endif -#endif /* _SLEEP_H */ +#include "globals.h" #pragma once -typedef struct _fade_t { - int index; - unsigned int quantity; -} fade_t; - void *Malloc (size_t nbytes); FILE *Fopen (const char *fname, char *mode); ALint AlGetError (const char *str);