author | nemo |
Fri, 16 Oct 2009 22:46:58 +0000 | |
changeset 2514 | df9d0728c5bb |
parent 2494 | 1e10a47cabea |
permissions | -rw-r--r-- |
2445 | 1 |
/* |
2 |
* OpenAL Bridge - a simple portable library for OpenAL interface |
|
3 |
* Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>, |
|
4 |
* Mario Liebisch <mario.liebisch+hw@googlemail.com> |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU Lesser General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU Lesser General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU Lesser General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 |
*/ |
|
19 |
||
2454
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
20 |
|
2494 | 21 |
#ifndef _COMMON_H |
22 |
#define _COMMON_H |
|
2445 | 23 |
|
24 |
#include <stdio.h> |
|
25 |
#include <stdlib.h> |
|
26 |
#include <stdint.h> |
|
27 |
#include <string.h> |
|
28 |
#include <stdarg.h> |
|
29 |
#include <errno.h> |
|
30 |
#include "al.h" |
|
31 |
#include "errlib.h" |
|
32 |
||
33 |
#ifndef _WIN32 |
|
34 |
#include <pthread.h> |
|
35 |
#include <syslog.h> |
|
36 |
#else |
|
37 |
#include <process.h> |
|
38 |
#define syslog(x,y) fprintf(stderr,y) |
|
39 |
#define LOG_INFO 6 |
|
40 |
#define LOG_ERR 3 |
|
41 |
#endif |
|
42 |
||
2454
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
43 |
|
2445 | 44 |
/* magics */ |
45 |
#define OGG_FILE_FORMAT 0x4F676753 |
|
46 |
#define WAV_FILE_FORMAT 0x52494646 |
|
47 |
#define WAV_HEADER_SUBCHUNK2ID 0x64617461 |
|
48 |
||
2458 | 49 |
/* max allocations */ |
2445 | 50 |
#define MAX_SOUNDS 1024 |
51 |
#define MAX_SOURCES 16 |
|
52 |
||
53 |
/* check compiler requirements */ /*FIXME*/ |
|
54 |
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) |
|
55 |
#warning __BIG_ENDIAN__ or __LITTLE_ENDIAN__ not found, going to set __LITTLE_ENDIAN__ as default |
|
56 |
#define __LITTLE_ENDIAN__ 1 |
|
57 |
//#error Do not know the endianess of this architecture |
|
58 |
#endif |
|
59 |
||
60 |
/* use byteswap macros from the host system, hopefully optimized ones ;-) |
|
61 |
* or define our own version, simple, stupid, straight-forward... */ |
|
62 |
#ifdef HAVE_BYTESWAP_H |
|
63 |
#include <byteswap.h> |
|
64 |
#else |
|
65 |
#define bswap_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) |
|
66 |
#define bswap_32(x) ((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | \ |
|
67 |
(((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24) ) |
|
68 |
#endif /* HAVE_BYTESWAP_H */ |
|
69 |
||
70 |
/* swap numbers accordingly to architecture automatically */ |
|
71 |
#ifdef __LITTLE_ENDIAN__ |
|
72 |
#define ENDIAN_LITTLE_32(x) x |
|
73 |
#define ENDIAN_BIG_32(x) bswap_32(x) |
|
74 |
#define ENDIAN_LITTLE_16(x) x |
|
75 |
#define ENDIAN_BIG_16(x) bswap_16(x) |
|
76 |
#elif __BIG_ENDIAN__ |
|
77 |
#define ENDIAN_LITTLE_32(x) bswap_32(x) |
|
78 |
#define ENDIAN_BIG_32(x) x |
|
79 |
#define ENDIAN_LITTLE_16(x) bswap_16(x) |
|
80 |
#define ENDIAN_BIG_16(x) x |
|
81 |
#endif |
|
82 |
||
2454
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
83 |
/** 1.0 02/03/10 - Defines cross-platform sleep, usleep, etc. [Wu Yongwei] **/ |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
84 |
#ifndef _SLEEP_H |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
85 |
#define _SLEEP_H |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
86 |
#ifdef _WIN32 |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
87 |
# if defined(_NEED_SLEEP_ONLY) && (defined(_MSC_VER) || defined(__MINGW32__)) |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
88 |
# include <stdlib.h> |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
89 |
# define sleep(t) _sleep((t) * 1000) |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
90 |
# else |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
91 |
# define WIN32_LEAN_AND_MEAN |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
92 |
# include <windows.h> |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
93 |
# define sleep(t) Sleep((t) * 1000) |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
94 |
# endif |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
95 |
# ifndef _NEED_SLEEP_ONLY |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
96 |
# define msleep(t) Sleep(t) |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
97 |
# define usleep(t) Sleep((t) / 1000) |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
98 |
# endif |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
99 |
#else |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
100 |
# include <unistd.h> |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
101 |
# ifndef _NEED_SLEEP_ONLY |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
102 |
# define msleep(t) usleep((t) * 1000) |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
103 |
# endif |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
104 |
#endif |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
105 |
#endif /* _SLEEP_H */ |
c8b1fb10003c
fix a potential bug when playing two sounds at the same time (or very near)
koda
parents:
2445
diff
changeset
|
106 |
|
2445 | 107 |
#pragma pack(1) |
108 |
typedef struct _WAV_header_t { |
|
109 |
uint32_t ChunkID; |
|
110 |
uint32_t ChunkSize; |
|
111 |
uint32_t Format; |
|
112 |
uint32_t Subchunk1ID; |
|
113 |
uint32_t Subchunk1Size; |
|
114 |
uint16_t AudioFormat; |
|
115 |
uint16_t NumChannels; |
|
116 |
uint32_t SampleRate; |
|
117 |
uint32_t ByteRate; |
|
118 |
uint16_t BlockAlign; |
|
119 |
uint16_t BitsPerSample; |
|
120 |
uint32_t Subchunk2ID; |
|
121 |
uint32_t Subchunk2Size; |
|
122 |
} WAV_header_t; |
|
123 |
#pragma pack() |
|
124 |
||
125 |
#pragma pack(1) |
|
126 |
typedef struct _SSound_t { |
|
2494 | 127 |
int isLoaded; |
128 |
int sourceIndex; |
|
129 |
char *filename; |
|
2445 | 130 |
ALuint Buffer; |
131 |
} SSound_t; |
|
132 |
#pragma pack() |
|
133 |
||
2494 | 134 |
/*data type for passing data between threads*/ |
135 |
#pragma pack(1) |
|
136 |
typedef struct _fade_t { |
|
137 |
uint32_t index; |
|
138 |
uint16_t quantity; |
|
139 |
} fade_t; |
|
140 |
#pragma pack() |
|
2445 | 141 |
|
2494 | 142 |
#define FADE_IN 0 |
143 |
#define FADE_OUT 1 |
|
144 |
||
145 |
#endif /* _COMMON_H*/ |