Store extension list with a pointer, not a per-context array
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob66dcaaac9be6911adbd9ecd98475375cc25c18ab
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
7 #include "alu.h"
9 #ifdef _WIN32
11 #ifndef _WIN32_WINNT
12 #define _WIN32_WINNT 0x0500
13 #endif
14 #include <windows.h>
16 #else
18 #include <assert.h>
19 #include <pthread.h>
20 #ifdef HAVE_PTHREAD_NP_H
21 #include <pthread_np.h>
22 #endif
23 #include <sys/time.h>
24 #include <time.h>
25 #include <errno.h>
27 #define IsBadWritePtr(a,b) (0)
29 typedef pthread_mutex_t CRITICAL_SECTION;
30 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
32 int ret;
33 ret = pthread_mutex_lock(cs);
34 assert(ret == 0);
36 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
38 int ret;
39 ret = pthread_mutex_unlock(cs);
40 assert(ret == 0);
42 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
44 pthread_mutexattr_t attrib;
45 int ret;
47 ret = pthread_mutexattr_init(&attrib);
48 assert(ret == 0);
50 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
51 #ifdef HAVE_PTHREAD_NP_H
52 if(ret != 0)
53 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
54 #endif
55 assert(ret == 0);
56 ret = pthread_mutex_init(cs, &attrib);
57 assert(ret == 0);
59 pthread_mutexattr_destroy(&attrib);
62 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
64 int ret;
65 ret = pthread_mutex_destroy(cs);
66 assert(ret == 0);
69 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
70 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
71 * Additionally, Win32 is supposed to measure the time since Windows started,
72 * as opposed to the actual time. */
73 static inline ALuint timeGetTime(void)
75 struct timeval tv;
76 int ret;
78 ret = gettimeofday(&tv, NULL);
79 assert(ret == 0);
81 return tv.tv_usec/1000 + tv.tv_sec*1000;
84 static inline void Sleep(ALuint t)
86 struct timespec tv, rem;
87 tv.tv_nsec = (t*1000000)%1000000000;
88 tv.tv_sec = t/1000;
90 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
91 tv = rem;
93 #define min(x,y) (((x)<(y))?(x):(y))
94 #define max(x,y) (((x)>(y))?(x):(y))
95 #endif
97 #include "AL/al.h"
98 #include "AL/alc.h"
99 #include "AL/alext.h"
100 #include "alListener.h"
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
106 extern char _alDebug[256];
108 #define AL_PRINT(...) do { \
109 int _al_print_i; \
110 const char *_al_print_fn = strrchr(__FILE__, '/'); \
111 if(!_al_print_fn) _al_print_fn = __FILE__; \
112 else _al_print_fn += 1; \
113 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
114 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
115 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
116 _alDebug[sizeof(_alDebug)-1] = 0; \
117 fprintf(stderr, "%s", _alDebug); \
118 } while(0)
121 #define SWMIXER_OUTPUT_RATE 44100
123 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
124 #define AIRABSORBGAINHF (0.994f)
126 typedef struct {
127 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
128 void (*ClosePlayback)(ALCdevice*);
130 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
131 void (*CloseCapture)(ALCdevice*);
132 void (*StartCapture)(ALCdevice*);
133 void (*StopCapture)(ALCdevice*);
134 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
135 ALCuint (*AvailableSamples)(ALCdevice*);
136 } BackendFuncs;
138 void alc_alsa_init(BackendFuncs *func_list);
139 void alc_oss_init(BackendFuncs *func_list);
140 void alcDSoundInit(BackendFuncs *func_list);
141 void alcWinMMInit(BackendFuncs *FuncList);
142 void alc_wave_init(BackendFuncs *func_list);
145 struct ALCdevice_struct
147 ALboolean IsCaptureDevice;
149 ALuint Frequency;
150 ALuint UpdateSize;
151 ALenum Format;
153 ALCchar *szDeviceName;
155 // Maximum number of sources that can be created
156 ALuint MaxNoOfSources;
158 // Context created on this device
159 ALCcontext *Context;
161 BackendFuncs *Funcs;
162 void *ExtraData; // For the backend's use
164 ALCdevice *next;
167 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
168 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
169 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
170 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
171 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
172 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
173 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
174 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
176 struct ALCcontext_struct
178 ALlistener Listener;
180 struct ALsource *Source;
181 ALuint SourceCount;
183 struct ALeffectslot *AuxiliaryEffectSlot;
184 ALuint AuxiliaryEffectSlotCount;
186 ALenum LastError;
187 ALboolean InUse;
189 ALuint Frequency;
191 ALenum DistanceModel;
193 ALfloat DopplerFactor;
194 ALfloat DopplerVelocity;
195 ALfloat flSpeedOfSound;
197 ALint lNumMonoSources;
198 ALint lNumStereoSources;
200 ALCdevice *Device;
201 const ALCchar *ExtensionList;
203 struct bs2b *bs2b;
205 ALCcontext *next;
208 ALCvoid ReleaseALC(ALCvoid);
210 ALCchar *AppendDeviceList(char *name);
211 ALCchar *AppendAllDeviceList(char *name);
212 ALCchar *AppendCaptureDeviceList(char *name);
214 ALCvoid SetALCError(ALenum errorCode);
216 ALCvoid SuspendContext(ALCcontext *context);
217 ALCvoid ProcessContext(ALCcontext *context);
219 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
220 ALuint StopThread(ALvoid *thread);
222 typedef struct RingBuffer RingBuffer;
223 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
224 void DestroyRingBuffer(RingBuffer *ring);
225 ALsizei RingBufferSize(RingBuffer *ring);
226 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
227 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
229 void ReadALConfig(void);
230 void FreeALConfig(void);
231 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
232 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
233 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
235 #ifdef __cplusplus
237 #endif
239 #endif