author | koda |
Mon, 12 Oct 2009 21:29:28 +0000 | |
changeset 2437 | 10e4b5fc0d93 |
parent 2421 | a4b039ee2eb0 |
permissions | -rw-r--r-- |
2212 | 1 |
/* |
2 |
* OpenAL Bridge - a simple portable library for OpenAL interface |
|
3 |
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2216
diff
changeset
|
6 |
* it under the terms of the GNU Lesser General Public License as published by |
2212 | 7 |
* the Free Software Foundation; version 2 of the License |
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2216
diff
changeset
|
12 |
* GNU Lesser General Public License for more details. |
2212 | 13 |
* |
2257
7eb31efcfb9b
updates licence and fix a memory leak (which was consuming iphone memory)
koda
parents:
2216
diff
changeset
|
14 |
* You should have received a copy of the GNU Lesser General Public License |
2212 | 15 |
* along with this program; if not, write to the Free Software |
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
2213 | 19 |
#ifndef _OALB_GLOBALS_H |
20 |
#define _OALB_GLOBALS_H |
|
2212 | 21 |
|
22 |
#include <stdio.h> |
|
23 |
#include <stdlib.h> |
|
2215 | 24 |
#include <stdint.h> |
2418 | 25 |
#include <stdarg.h> |
2259 | 26 |
#include <string.h> |
2418 | 27 |
#include <errno.h> |
2212 | 28 |
|
29 |
#ifndef _WIN32 |
|
30 |
#include <pthread.h> |
|
2421 | 31 |
#include <syslog.h> |
2212 | 32 |
#else |
33 |
#include <process.h> |
|
2421 | 34 |
#define syslog(x,y) fprintf(stderr,y) |
35 |
#define LOG_INFO 6 |
|
36 |
#define LOG_ERR 3 |
|
2212 | 37 |
#endif |
38 |
||
2213 | 39 |
#include "al.h" |
2418 | 40 |
#include "errlib.h" |
2213 | 41 |
|
2415 | 42 |
|
2421 | 43 |
/*control debug verbosity*/ |
2418 | 44 |
#ifdef TRACE |
45 |
#ifndef DEBUG |
|
46 |
#define DEBUG |
|
47 |
#endif |
|
48 |
#endif |
|
49 |
||
2415 | 50 |
/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. [Wu Yongwei] **/ |
2212 | 51 |
#ifndef _SLEEP_H |
52 |
#define _SLEEP_H |
|
53 |
#ifdef _WIN32 |
|
54 |
# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) |
|
55 |
# include <stdlib.h> |
|
56 |
# define sleep(t) _sleep((t) * 1000) |
|
57 |
# else |
|
2213 | 58 |
# define WIN32_LEAN_AND_MEAN |
2212 | 59 |
# include <windows.h> |
60 |
# define sleep(t) Sleep((t) * 1000) |
|
61 |
# endif |
|
62 |
# ifndef _NEED_SLEEP_ONLY |
|
63 |
# define msleep(t) Sleep(t) |
|
64 |
# define usleep(t) Sleep((t) / 1000) |
|
65 |
# endif |
|
66 |
#else |
|
67 |
# include <unistd.h> |
|
68 |
# ifndef _NEED_SLEEP_ONLY |
|
69 |
# define msleep(t) usleep((t) * 1000) |
|
70 |
# endif |
|
71 |
#endif |
|
72 |
#endif /* _SLEEP_H */ |
|
73 |
||
2421 | 74 |
|
2420 | 75 |
/* check compiler requirements */ /*FIXME*/ |
2417 | 76 |
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) |
2420 | 77 |
#warning __BIG_ENDIAN__ or __LITTLE_ENDIAN__ not found, going to set __LITTLE_ENDIAN__ as default |
78 |
#define __LITTLE_ENDIAN__ 1 |
|
79 |
//#error Do not know the endianess of this architecture |
|
2419 | 80 |
#endif |
2212 | 81 |
|
2417 | 82 |
/* use byteswap macros from the host system, hopefully optimized ones ;-) |
83 |
* or define our own version, simple, stupid, straight-forward... */ |
|
84 |
#ifdef HAVE_BYTESWAP_H |
|
85 |
#include <byteswap.h> |
|
86 |
#else |
|
87 |
#define bswap_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) |
|
88 |
#define bswap_32(x) ((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | \ |
|
2421 | 89 |
(((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24) ) |
2417 | 90 |
#endif /* HAVE_BYTESWAP_H */ |
2212 | 91 |
|
2417 | 92 |
/* swap numbers accordingly to architecture automatically */ |
93 |
#ifdef __LITTLE_ENDIAN__ |
|
94 |
#define ENDIAN_LITTLE_32(x) x |
|
95 |
#define ENDIAN_BIG_32(x) bswap_32(x) |
|
96 |
#define ENDIAN_LITTLE_16(x) x |
|
97 |
#define ENDIAN_BIG_16(x) bswap_16(x) |
|
98 |
#elif __BIG_ENDIAN__ |
|
99 |
#define ENDIAN_LITTLE_32(x) bswap_32(x) |
|
100 |
#define ENDIAN_BIG_32(x) x |
|
101 |
#define ENDIAN_LITTLE_16(x) bswap_16(x) |
|
102 |
#define ENDIAN_BIG_16(x) x |
|
103 |
#endif |
|
2212 | 104 |
|
105 |
||
106 |
#ifdef __CPLUSPLUS |
|
107 |
extern "C" { |
|
108 |
#endif |
|
2415 | 109 |
|
2419 | 110 |
/*data type for WAV header*/ |
2212 | 111 |
#pragma pack(1) |
2415 | 112 |
typedef struct _WAV_header_t { |
113 |
uint32_t ChunkID; |
|
114 |
uint32_t ChunkSize; |
|
115 |
uint32_t Format; |
|
116 |
uint32_t Subchunk1ID; |
|
117 |
uint32_t Subchunk1Size; |
|
118 |
uint16_t AudioFormat; |
|
119 |
uint16_t NumChannels; |
|
120 |
uint32_t SampleRate; |
|
121 |
uint32_t ByteRate; |
|
122 |
uint16_t BlockAlign; |
|
123 |
uint16_t BitsPerSample; |
|
124 |
uint32_t Subchunk2ID; |
|
125 |
uint32_t Subchunk2Size; |
|
126 |
} WAV_header_t; |
|
2212 | 127 |
#pragma pack() |
2415 | 128 |
|
2419 | 129 |
/*data type for passing data between threads*/ |
2216
82e7da49c26a
-Smaxx' patch: checks for initialized openal + disables sound options if openal init fails
koda
parents:
2215
diff
changeset
|
130 |
#pragma pack(1) |
2415 | 131 |
typedef struct _fade_t { |
132 |
uint32_t index; |
|
133 |
uint16_t quantity; |
|
134 |
} fade_t; |
|
2216
82e7da49c26a
-Smaxx' patch: checks for initialized openal + disables sound options if openal init fails
koda
parents:
2215
diff
changeset
|
135 |
#pragma pack() |
2419 | 136 |
|
2415 | 137 |
|
2419 | 138 |
/*file format defines*/ |
2415 | 139 |
#define OGG_FILE_FORMAT 0x4F676753 |
140 |
#define WAV_FILE_FORMAT 0x52494646 |
|
141 |
#define WAV_HEADER_SUBCHUNK2ID 0x64617461 |
|
2419 | 142 |
|
143 |
||
144 |
/*other defines*/ |
|
2418 | 145 |
#define FADE_IN 0 |
2415 | 146 |
#define FADE_OUT 1 |
2419 | 147 |
|
2418 | 148 |
char *prog; |
2415 | 149 |
|
2212 | 150 |
#ifdef __CPLUSPLUS |
151 |
} |
|
152 |
#endif |
|
153 |
||
2213 | 154 |
#endif /*_OALB_GLOBALS_H*/ |