comparison ext/openal-soft/OpenAL32/Include/alMain.h @ 89:fa33cda75471

* Reverting back to 2543 as requested by sleek
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 19 Jul 2008 11:38:52 +0000
parents 4a0efb7baf70
children
comparison
equal deleted inserted replaced
88:1c2842ebe393 89:fa33cda75471
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
3
4 #include <string.h>
5 #include <stdio.h>
6
7 #include "alu.h"
8
9 #ifdef _WIN32
10
11 #include <windows.h>
12
13 #else
14
15 #include <assert.h>
16 #include <pthread.h>
17 #include <sys/time.h>
18 #include <time.h>
19 #include <errno.h>
20
21 #define IsBadWritePtr(a,b) (0)
22
23 typedef pthread_mutex_t CRITICAL_SECTION;
24 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
25 {
26 int ret;
27 ret = pthread_mutex_lock(cs);
28 assert(ret == 0);
29 }
30 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
31 {
32 int ret;
33 ret = pthread_mutex_unlock(cs);
34 assert(ret == 0);
35 }
36 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
37 {
38 pthread_mutexattr_t attrib;
39 int ret;
40
41 ret = pthread_mutexattr_init(&attrib);
42 assert(ret == 0);
43
44 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
45 assert(ret == 0);
46 ret = pthread_mutex_init(cs, &attrib);
47 assert(ret == 0);
48
49 pthread_mutexattr_destroy(&attrib);
50 }
51
52 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
53 {
54 int ret;
55 ret = pthread_mutex_destroy(cs);
56 assert(ret == 0);
57 }
58
59 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
60 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
61 * Additionally, Win32 is supposed to measure the time since Windows started,
62 * as opposed to the actual time. */
63 static inline ALuint timeGetTime(void)
64 {
65 struct timeval tv;
66 int ret;
67
68 ret = gettimeofday(&tv, NULL);
69 assert(ret == 0);
70
71 return tv.tv_usec/1000 + tv.tv_sec*1000;
72 }
73
74 static inline void Sleep(ALuint t)
75 {
76 struct timespec tv, rem;
77 tv.tv_nsec = (t*1000000)%1000000000;
78 tv.tv_sec = t/1000;
79
80 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
81 tv = rem;
82 }
83 #define min(x,y) (((x)<(y))?(x):(y))
84 #define max(x,y) (((x)>(y))?(x):(y))
85 #endif
86
87 #include "AL/al.h"
88 #include "AL/alc.h"
89 #include "AL/alext.h"
90 #include "alListener.h"
91
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95
96 extern CRITICAL_SECTION _alMutex;
97
98 extern char _alDebug[256];
99
100 #define AL_PRINT(...) do { \
101 int _al_print_i; \
102 char *_al_print_fn = strrchr(__FILE__, '/'); \
103 if(!_al_print_fn) _al_print_fn = __FILE__; \
104 else _al_print_fn += 1; \
105 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
106 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
107 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
108 _alDebug[sizeof(_alDebug)-1] = 0; \
109 fprintf(stderr, "%s", _alDebug); \
110 } while(0)
111
112
113 #define SWMIXER_OUTPUT_RATE 44100
114
115 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
116 #define AIRABSORBGAINHF (0.994f)
117
118 typedef struct {
119 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
120 void (*ClosePlayback)(ALCdevice*);
121
122 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
123 void (*CloseCapture)(ALCdevice*);
124 void (*StartCapture)(ALCdevice*);
125 void (*StopCapture)(ALCdevice*);
126 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
127 ALCuint (*AvailableSamples)(ALCdevice*);
128 } BackendFuncs;
129
130 void alc_alsa_init(BackendFuncs *func_list);
131 void alc_oss_init(BackendFuncs *func_list);
132 void alcDSoundInit(BackendFuncs *func_list);
133 void alcWinMMInit(BackendFuncs *FuncList);
134 void alc_wave_init(BackendFuncs *func_list);
135
136
137 struct ALCdevice_struct
138 {
139 ALboolean IsCaptureDevice;
140
141 ALuint Frequency;
142 ALuint UpdateSize;
143 ALenum Format;
144
145 ALCchar *szDeviceName;
146
147 // Maximum number of sources that can be created
148 ALuint MaxNoOfSources;
149
150 // Context created on this device
151 ALCcontext *Context;
152
153 BackendFuncs *Funcs;
154 void *ExtraData; // For the backend's use
155
156 ALCdevice *next;
157 };
158
159 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
160 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
161 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
162 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
163 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
164 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
165 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
166 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
167
168 struct ALCcontext_struct
169 {
170 ALlistener Listener;
171
172 struct ALsource *Source;
173 ALuint SourceCount;
174
175 struct ALeffectslot *AuxiliaryEffectSlot;
176 ALuint AuxiliaryEffectSlotCount;
177
178 ALenum LastError;
179 ALboolean InUse;
180
181 ALuint Frequency;
182
183 ALenum DistanceModel;
184
185 ALfloat DopplerFactor;
186 ALfloat DopplerVelocity;
187 ALfloat flSpeedOfSound;
188
189 ALint lNumMonoSources;
190 ALint lNumStereoSources;
191
192 ALCdevice *Device;
193 ALCchar ExtensionList[1024];
194
195 struct bs2b *bs2b;
196
197 ALCcontext *next;
198 };
199
200 ALCvoid ReleaseALC(ALCvoid);
201
202 ALCchar *AppendDeviceList(char *name);
203 ALCchar *AppendAllDeviceList(char *name);
204 ALCchar *AppendCaptureDeviceList(char *name);
205
206 ALCvoid SetALCError(ALenum errorCode);
207
208 ALCvoid SuspendContext(ALCcontext *context);
209 ALCvoid ProcessContext(ALCcontext *context);
210
211 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
212 ALuint StopThread(ALvoid *thread);
213
214 typedef struct RingBuffer RingBuffer;
215 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
216 void DestroyRingBuffer(RingBuffer *ring);
217 ALsizei RingBufferSize(RingBuffer *ring);
218 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
219 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
220
221 void ReadALConfig(void);
222 void FreeALConfig(void);
223 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
224 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
225 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
226
227 #ifdef __cplusplus
228 }
229 #endif
230
231 #endif