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 |
|
|
20 |
#ifndef COMMON_H
|
|
21 |
#define COMMON_H
|
|
22 |
|
|
23 |
#include <stdio.h>
|
|
24 |
#include <stdlib.h>
|
|
25 |
#include <stdint.h>
|
|
26 |
#include <string.h>
|
|
27 |
#include <stdarg.h>
|
|
28 |
#include <errno.h>
|
|
29 |
#include "al.h"
|
|
30 |
#include "errlib.h"
|
|
31 |
|
|
32 |
#ifndef _WIN32
|
|
33 |
#include <pthread.h>
|
|
34 |
#include <syslog.h>
|
|
35 |
#else
|
|
36 |
#include <process.h>
|
|
37 |
#define syslog(x,y) fprintf(stderr,y)
|
|
38 |
#define LOG_INFO 6
|
|
39 |
#define LOG_ERR 3
|
|
40 |
#endif
|
|
41 |
|
|
42 |
/* magics */
|
|
43 |
#define OGG_FILE_FORMAT 0x4F676753
|
|
44 |
#define WAV_FILE_FORMAT 0x52494646
|
|
45 |
#define WAV_HEADER_SUBCHUNK2ID 0x64617461
|
|
46 |
|
|
47 |
#define MAX_SOUNDS 1024
|
|
48 |
#define MAX_SOURCES 16
|
|
49 |
|
|
50 |
/* check compiler requirements */ /*FIXME*/
|
|
51 |
#if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
|
|
52 |
#warning __BIG_ENDIAN__ or __LITTLE_ENDIAN__ not found, going to set __LITTLE_ENDIAN__ as default
|
|
53 |
#define __LITTLE_ENDIAN__ 1
|
|
54 |
//#error Do not know the endianess of this architecture
|
|
55 |
#endif
|
|
56 |
|
|
57 |
/* use byteswap macros from the host system, hopefully optimized ones ;-)
|
|
58 |
* or define our own version, simple, stupid, straight-forward... */
|
|
59 |
#ifdef HAVE_BYTESWAP_H
|
|
60 |
#include <byteswap.h>
|
|
61 |
#else
|
|
62 |
#define bswap_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
|
|
63 |
#define bswap_32(x) ((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | \
|
|
64 |
(((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24) )
|
|
65 |
#endif /* HAVE_BYTESWAP_H */
|
|
66 |
|
|
67 |
/* swap numbers accordingly to architecture automatically */
|
|
68 |
#ifdef __LITTLE_ENDIAN__
|
|
69 |
#define ENDIAN_LITTLE_32(x) x
|
|
70 |
#define ENDIAN_BIG_32(x) bswap_32(x)
|
|
71 |
#define ENDIAN_LITTLE_16(x) x
|
|
72 |
#define ENDIAN_BIG_16(x) bswap_16(x)
|
|
73 |
#elif __BIG_ENDIAN__
|
|
74 |
#define ENDIAN_LITTLE_32(x) bswap_32(x)
|
|
75 |
#define ENDIAN_BIG_32(x) x
|
|
76 |
#define ENDIAN_LITTLE_16(x) bswap_16(x)
|
|
77 |
#define ENDIAN_BIG_16(x) x
|
|
78 |
#endif
|
|
79 |
|
|
80 |
#pragma pack(1)
|
|
81 |
typedef struct _WAV_header_t {
|
|
82 |
uint32_t ChunkID;
|
|
83 |
uint32_t ChunkSize;
|
|
84 |
uint32_t Format;
|
|
85 |
uint32_t Subchunk1ID;
|
|
86 |
uint32_t Subchunk1Size;
|
|
87 |
uint16_t AudioFormat;
|
|
88 |
uint16_t NumChannels;
|
|
89 |
uint32_t SampleRate;
|
|
90 |
uint32_t ByteRate;
|
|
91 |
uint16_t BlockAlign;
|
|
92 |
uint16_t BitsPerSample;
|
|
93 |
uint32_t Subchunk2ID;
|
|
94 |
uint32_t Subchunk2Size;
|
|
95 |
} WAV_header_t;
|
|
96 |
#pragma pack()
|
|
97 |
|
|
98 |
#pragma pack(1)
|
|
99 |
typedef struct _SSound_t {
|
|
100 |
int source;
|
|
101 |
char Filename[256];
|
|
102 |
ALuint Buffer;
|
|
103 |
} SSound_t;
|
|
104 |
#pragma pack()
|
|
105 |
|
|
106 |
#endif
|
|
107 |
|