committing some missing files
authorkoda
Wed, 14 Oct 2009 22:25:28 +0000
changeset 2445 5033848d3afa
parent 2444 ace11b7d8eab
child 2446 cbb3af76bcc0
committing some missing files
openalbridge/CMakeLists.txt
openalbridge/common.h
openalbridge/openalbridge.c
openalbridge/openalbridge.h
openalbridge/ssound.c
openalbridge/ssound.h
--- a/openalbridge/CMakeLists.txt	Wed Oct 14 22:21:25 2009 +0000
+++ b/openalbridge/CMakeLists.txt	Wed Oct 14 22:25:28 2009 +0000
@@ -8,7 +8,7 @@
 
 #list of source files for libraries
 set(openal_src
-	openalbridge.c loaders.c wrappers.c errlib.c
+	openalbridge.c loaders.c wrappers.c errlib.c ssound.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 common.h oggvorbis.h errlib.h ${openal_src}
+		openalbridge.h loaders.h wrappers.h common.h oggvorbis.h errlib.h ssound.h ${openal_src}
 	)
 #deps for the shared library
 	link_libraries(${VORBISFILE_LIBRARY})
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/common.h	Wed Oct 14 22:25:28 2009 +0000
@@ -0,0 +1,107 @@
+/*
+ * OpenAL Bridge - a simple portable library for OpenAL interface
+ * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>,
+ *                    Mario Liebisch <mario.liebisch+hw@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 COMMON_H
+#define COMMON_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdarg.h>
+#include <errno.h>
+#include "al.h"
+#include "errlib.h"
+
+#ifndef _WIN32
+#include <pthread.h>
+#include <syslog.h>
+#else
+#include <process.h>
+#define syslog(x,y) fprintf(stderr,y)
+#define LOG_INFO 6
+#define LOG_ERR 3
+#endif
+
+/* magics */
+#define OGG_FILE_FORMAT 0x4F676753
+#define WAV_FILE_FORMAT 0x52494646
+#define WAV_HEADER_SUBCHUNK2ID 0x64617461
+
+#define MAX_SOUNDS 1024
+#define MAX_SOURCES 16
+
+/* check compiler requirements */    /*FIXME*/
+#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
+#warning __BIG_ENDIAN__ or __LITTLE_ENDIAN__ not found, going to set __LITTLE_ENDIAN__ as default
+#define __LITTLE_ENDIAN__ 1
+//#error Do not know the endianess of this architecture
+#endif
+
+/* use byteswap macros from the host system, hopefully optimized ones ;-) 
+ * or define our own version, simple, stupid, straight-forward... */
+#ifdef HAVE_BYTESWAP_H
+#include <byteswap.h>
+#else        
+#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 */
+
+/* swap numbers accordingly to architecture automatically */
+#ifdef __LITTLE_ENDIAN__
+#define ENDIAN_LITTLE_32(x) x
+#define ENDIAN_BIG_32(x)    bswap_32(x)
+#define ENDIAN_LITTLE_16(x) x
+#define ENDIAN_BIG_16(x)    bswap_16(x)
+#elif __BIG_ENDIAN__
+#define ENDIAN_LITTLE_32(x) bswap_32(x)
+#define ENDIAN_BIG_32(x)    x
+#define ENDIAN_LITTLE_16(x) bswap_16(x)
+#define ENDIAN_BIG_16(x)    x    
+#endif
+
+#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()
+
+#pragma pack(1)
+typedef struct _SSound_t {
+        int source;
+        char Filename[256];
+        ALuint Buffer;
+} SSound_t;
+#pragma pack()
+
+#endif
+
--- a/openalbridge/openalbridge.c	Wed Oct 14 22:21:25 2009 +0000
+++ b/openalbridge/openalbridge.c	Wed Oct 14 22:25:28 2009 +0000
@@ -40,13 +40,7 @@
 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);
+
 
 
 /**
@@ -450,153 +444,3 @@
         
         return;
 }
-
-
-/*SSOUND STUFF HERE*/
-
-char SSound_load (SSound_t* pSound, const char* cFilename) {
-        uint32_t magic;
-        ALenum format;
-        ALsizei bitsize, freq;
-        char *data;
-        FILE* fp;
-        
-        snprintf(pSound->Filename, 256, "%s", cFilename);
-        pSound->source = -1;
-        alGenBuffers(1, &pSound->Buffer);
-        
-        if(alGetError() != AL_NO_ERROR) {
-                fprintf(stderr, "CSound: Couldn't create buffer.\n");
-                return 0;
-        }
-        
-        fp = fopen(pSound->Filename, "rb");
-        
-        if(!fp) {
-                fprintf(stderr, "CSound: Couldn't open file for reading.\n");
-                return 0;
-        }
-        
-        if(fread(&magic, sizeof(uint32_t), 1, fp) < 1)
-        {
-                fclose(fp);
-                fprintf(stderr, "CSound: Couldn't read file header.\n");
-                return 0;
-        }
-        fclose(fp);
-        
-        switch (ENDIAN_BIG_32(magic)) {
-                case OGG_FILE_FORMAT:
-                        load_oggvorbis (pSound->Filename, &format, &data, &bitsize, &freq);
-                        break;
-                case WAV_FILE_FORMAT:
-                        load_wavpcm (pSound->Filename, &format, &data, &bitsize, &freq);
-                        break;
-                default:
-                        errno = EINVAL;
-                        err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(magic));
-                        return 0;
-                        break;
-        }
-        
-        alBufferData(pSound->Buffer, format, data, bitsize, freq);
-        if(alGetError() != AL_NO_ERROR)
-        {
-                fprintf(stderr, "CSound: Couldn't write buffer data.\n");
-                return 0;
-        }
-        free(data);
-        
-        return 1;
-}
-
-void SSound_close(SSound_t* pSound)
-{
-        SSound_stop(pSound);
-        alDeleteBuffers(1, &pSound->Buffer);
-}
-
-void SSound_play(SSound_t* pSound, const char bLoop) {
-        int i;
-        
-        if(pSound->source == -1) // need a new source
-        {
-                int i;
-                for(i = 0; i < MAX_SOURCES; i++)
-                {
-                        ALint state;
-                        alGetSourcei(sources[i], AL_SOURCE_STATE, &state);
-                        if(state != AL_PLAYING && state != AL_PAUSED)
-                        {
-#ifdef DEBUG
-                                printf("using source %d (state 0x%x) for buffer.\n", i, state);
-#endif
-                                alSourceStop(sources[pSound->source]);
-                                alGetError();
-                                break;
-                        }
-                }
-                if(i == MAX_SOURCES) // no available source found; skip
-                {
-#ifdef DEBUG
-                        printf("no source to play buffer %d!\n", i);
-#endif
-                        return;
-                }
-                pSound->source = i;
-        }
-        else // reuse already playing source
-        {
-                alSourceStop(sources[pSound->source]);
-        }
-        alSourcei (sources[pSound->source], AL_BUFFER, pSound->Buffer);
-        alSourcef (sources[pSound->source], AL_PITCH,            1.0f);
-        alSourcef (sources[pSound->source], AL_GAIN,             1.0f);
-        alSourcefv(sources[pSound->source], AL_POSITION, NV          );
-        alSourcefv(sources[pSound->source], AL_VELOCITY, NV          );
-        alSourcei (sources[pSound->source], AL_LOOPING,  bLoop       );
-        alSourcePlay(sources[pSound->source]);
-        
-        if((i = alGetError()) != AL_NO_ERROR)
-        {
-                fprintf(stderr, "CSound: SourcePlay error 0x%4x in source %d\n", i, pSound->source);
-        }
-#ifdef DEBUG
-        fprintf(stderr, "play %s%s [%d]\n", pSound->Filename, bLoop ? " forever" : " once", pSound->source);
-#endif
-}
-
-void SSound_pause(const SSound_t* pSound) {
-        if(pSound->source == -1) // not playing
-                return;
-        alSourcePause(sources[pSound->source]);
-#ifdef DEBUG
-        fprintf(stderr, "pause %s\n", pSound->Filename);
-#endif
-}
-
-void SSound_continue(const SSound_t* pSound) {
-        if(pSound->source == -1) // not playing
-                return;
-        alSourcePlay(sources[pSound->source]);
-#ifdef DEBUG
-        fprintf(stderr, "pause %s\n", pSound->Filename);
-#endif
-}
-
-void SSound_stop(SSound_t* pSound) {
-        if(pSound->source == -1) // not playing
-                return;
-        alSourceStop(sources[pSound->source]);
-        pSound->source = -1;
-#ifdef DEBUG
-        fprintf(stderr, "stop %s\n", pSound->Filename);
-#endif
-}
-
-void SSound_volume(const SSound_t* pSound, const float fPercentage) {
-        if(pSound->source == -1) // not playing
-                return;
-        alSourcef(sources[pSound->source], AL_GAIN, fPercentage);
-}        
-
--- a/openalbridge/openalbridge.h	Wed Oct 14 22:21:25 2009 +0000
+++ b/openalbridge/openalbridge.h	Wed Oct 14 22:25:28 2009 +0000
@@ -22,6 +22,7 @@
 #include "common.h"
 #include "wrappers.h"
 #include "loaders.h"
+#include "ssound.h"
 #include "alc.h"
 
 
@@ -44,11 +45,8 @@
         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);
         */
         
-
-        
 #ifdef __cplusplus
 }
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/ssound.c	Wed Oct 14 22:25:28 2009 +0000
@@ -0,0 +1,174 @@
+/*
+ * OpenAL Bridge - a simple portable library for OpenAL interface
+ * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>,
+ *                    Mario Liebisch <mario.liebisch+hw@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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
+ */
+
+#include "openalbridge.h"
+
+extern ALuint sources[MAX_SOURCES];
+extern const ALfloat NV[3];
+extern const ALfloat LO[6];
+
+char *prog;
+
+/*SSOUND STUFF HERE*/
+
+char SSound_load (SSound_t* pSound, const char* cFilename) {
+        uint32_t magic;
+        ALenum format;
+        ALsizei bitsize, freq;
+        char *data;
+        FILE* fp;
+        
+        snprintf(pSound->Filename, 256, "%s", cFilename);
+        pSound->source = -1;
+        alGenBuffers(1, &pSound->Buffer);
+        
+        if(alGetError() != AL_NO_ERROR) {
+                fprintf(stderr, "CSound: Couldn't create buffer.\n");
+                return 0;
+        }
+        
+        fp = fopen(pSound->Filename, "rb");
+        
+        if(!fp) {
+                fprintf(stderr, "CSound: Couldn't open file for reading.\n");
+                return 0;
+        }
+        
+        if(fread(&magic, sizeof(uint32_t), 1, fp) < 1)
+        {
+                fclose(fp);
+                fprintf(stderr, "CSound: Couldn't read file header.\n");
+                return 0;
+        }
+        fclose(fp);
+        
+        switch (ENDIAN_BIG_32(magic)) {
+                case OGG_FILE_FORMAT:
+                        load_oggvorbis (pSound->Filename, &format, &data, &bitsize, &freq);
+                        break;
+                case WAV_FILE_FORMAT:
+                        load_wavpcm (pSound->Filename, &format, &data, &bitsize, &freq);
+                        break;
+                default:
+                        errno = EINVAL;
+                        err_ret ("(%s) ERROR - File format (%08X) not supported", prog, ENDIAN_BIG_32(magic));
+                        return 0;
+                        break;
+        }
+        
+        alBufferData(pSound->Buffer, format, data, bitsize, freq);
+        if(alGetError() != AL_NO_ERROR)
+        {
+                fprintf(stderr, "CSound: Couldn't write buffer data.\n");
+                return 0;
+        }
+        free(data);
+        
+        return 1;
+}
+
+void SSound_close(SSound_t* pSound)
+{
+        SSound_stop(pSound);
+        alDeleteBuffers(1, &pSound->Buffer);
+}
+
+void SSound_play(SSound_t* pSound, const char bLoop) {
+        int i;
+        
+        if(pSound->source == -1) // need a new source
+        {
+                int i;
+                for(i = 0; i < MAX_SOURCES; i++)
+                {
+                        ALint state;
+                        alGetSourcei(sources[i], AL_SOURCE_STATE, &state);
+                        if(state != AL_PLAYING && state != AL_PAUSED)
+                        {
+#ifdef DEBUG
+                                printf("using source %d (state 0x%x) for buffer.\n", i, state);
+#endif
+                                alSourceStop(sources[pSound->source]);
+                                alGetError();
+                                break;
+                        }
+                }
+                if(i == MAX_SOURCES) // no available source found; skip
+                {
+#ifdef DEBUG
+                        printf("no source to play buffer %d!\n", i);
+#endif
+                        return;
+                }
+                pSound->source = i;
+        }
+        else // reuse already playing source
+        {
+                alSourceStop(sources[pSound->source]);
+        }
+        alSourcei (sources[pSound->source], AL_BUFFER, pSound->Buffer);
+        alSourcef (sources[pSound->source], AL_PITCH,            1.0f);
+        alSourcef (sources[pSound->source], AL_GAIN,             1.0f);
+        alSourcefv(sources[pSound->source], AL_POSITION, NV          );
+        alSourcefv(sources[pSound->source], AL_VELOCITY, NV          );
+        alSourcei (sources[pSound->source], AL_LOOPING,  bLoop       );
+        alSourcePlay(sources[pSound->source]);
+        
+        if((i = alGetError()) != AL_NO_ERROR)
+        {
+                fprintf(stderr, "CSound: SourcePlay error 0x%4x in source %d\n", i, pSound->source);
+        }
+#ifdef DEBUG
+        fprintf(stderr, "play %s%s [%d]\n", pSound->Filename, bLoop ? " forever" : " once", pSound->source);
+#endif
+}
+
+void SSound_pause(const SSound_t* pSound) {
+        if(pSound->source == -1) // not playing
+                return;
+        alSourcePause(sources[pSound->source]);
+#ifdef DEBUG
+        fprintf(stderr, "pause %s\n", pSound->Filename);
+#endif
+}
+
+void SSound_continue(const SSound_t* pSound) {
+        if(pSound->source == -1) // not playing
+                return;
+        alSourcePlay(sources[pSound->source]);
+#ifdef DEBUG
+        fprintf(stderr, "pause %s\n", pSound->Filename);
+#endif
+}
+
+void SSound_stop(SSound_t* pSound) {
+        if(pSound->source == -1) // not playing
+                return;
+        alSourceStop(sources[pSound->source]);
+        pSound->source = -1;
+#ifdef DEBUG
+        fprintf(stderr, "stop %s\n", pSound->Filename);
+#endif
+}
+
+void SSound_volume(const SSound_t* pSound, const float fPercentage) {
+        if(pSound->source == -1) // not playing
+                return;
+        alSourcef(sources[pSound->source], AL_GAIN, fPercentage);
+}    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/ssound.h	Wed Oct 14 22:25:28 2009 +0000
@@ -0,0 +1,33 @@
+/*
+ * OpenAL Bridge - a simple portable library for OpenAL interface
+ * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>,
+ *                    Mario Liebisch <mario.liebisch+hw@googlemail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 _SSOUND_H
+#define _SSOUND_H
+
+#include "common.h"
+
+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);
+
+#endif /*_SSOUND_H*/