Add base support for ALC_EXT_disconnect
[openal-soft.git] / OpenAL32 / Include / alMain.h
blobca9d8006c64bbfce67599830382f6e6d759da552
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
6 #include <stdarg.h>
8 #ifdef HAVE_FENV_H
9 #include <fenv.h>
10 #endif
12 #include "AL/al.h"
13 #include "AL/alc.h"
14 #include "AL/alext.h"
16 #ifdef _WIN32
18 #ifndef _WIN32_WINNT
19 #define _WIN32_WINNT 0x0500
20 #endif
21 #include <windows.h>
23 #else
25 #include <assert.h>
26 #include <pthread.h>
27 #ifdef HAVE_PTHREAD_NP_H
28 #include <pthread_np.h>
29 #endif
30 #include <sys/time.h>
31 #include <time.h>
32 #include <errno.h>
34 #define IsBadWritePtr(a,b) (0)
36 typedef pthread_mutex_t CRITICAL_SECTION;
37 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
39 int ret;
40 ret = pthread_mutex_lock(cs);
41 assert(ret == 0);
43 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
45 int ret;
46 ret = pthread_mutex_unlock(cs);
47 assert(ret == 0);
49 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
51 pthread_mutexattr_t attrib;
52 int ret;
54 ret = pthread_mutexattr_init(&attrib);
55 assert(ret == 0);
57 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
58 #ifdef HAVE_PTHREAD_NP_H
59 if(ret != 0)
60 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
61 #endif
62 assert(ret == 0);
63 ret = pthread_mutex_init(cs, &attrib);
64 assert(ret == 0);
66 pthread_mutexattr_destroy(&attrib);
69 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
71 int ret;
72 ret = pthread_mutex_destroy(cs);
73 assert(ret == 0);
76 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
77 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
78 * Additionally, Win32 is supposed to measure the time since Windows started,
79 * as opposed to the actual time. */
80 static inline ALuint timeGetTime(void)
82 struct timeval tv;
83 int ret;
85 ret = gettimeofday(&tv, NULL);
86 assert(ret == 0);
88 return tv.tv_usec/1000 + tv.tv_sec*1000;
91 static inline void Sleep(ALuint t)
93 struct timespec tv, rem;
94 tv.tv_nsec = (t*1000000)%1000000000;
95 tv.tv_sec = t/1000;
97 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
98 tv = rem;
100 #define min(x,y) (((x)<(y))?(x):(y))
101 #define max(x,y) (((x)>(y))?(x):(y))
102 #endif
104 #include "alListener.h"
105 #include "alu.h"
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
111 static __inline void al_print(const char *fname, unsigned int line, const char *fmt, ...)
113 const char *fn;
114 char str[256];
115 int i;
117 fn = strrchr(fname, '/');
118 if(!fn) fn = strrchr(fname, '\\');;
119 if(!fn) fn = fname;
120 else fn += 1;
122 i = snprintf(str, sizeof(str), "AL lib: %s:%d: ", fn, line);
123 if(i < (int)sizeof(str) && i > 0)
125 va_list ap;
126 va_start(ap, fmt);
127 vsnprintf(str+i, sizeof(str)-i, fmt, ap);
128 va_end(ap);
130 str[sizeof(str)-1] = 0;
132 fprintf(stderr, "%s", str);
134 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
137 #define SWMIXER_OUTPUT_RATE 44100
139 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
140 #define AIRABSORBGAINDBHF (-0.05f)
142 #define LOWPASSFREQCUTOFF (5000)
144 #define QUADRANT_NUM 128
145 #define LUT_NUM (4 * QUADRANT_NUM)
148 typedef struct {
149 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
150 void (*ClosePlayback)(ALCdevice*);
151 ALCboolean (*StartContext)(ALCdevice*, ALCcontext*);
152 void (*StopContext)(ALCdevice*, ALCcontext*);
154 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*);
155 void (*CloseCapture)(ALCdevice*);
156 void (*StartCapture)(ALCdevice*);
157 void (*StopCapture)(ALCdevice*);
158 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
159 ALCuint (*AvailableSamples)(ALCdevice*);
160 } BackendFuncs;
162 void alc_alsa_init(BackendFuncs *func_list);
163 void alc_oss_init(BackendFuncs *func_list);
164 void alc_solaris_init(BackendFuncs *func_list);
165 void alcDSoundInit(BackendFuncs *func_list);
166 void alcWinMMInit(BackendFuncs *FuncList);
167 void alc_pa_init(BackendFuncs *func_list);
168 void alc_wave_init(BackendFuncs *func_list);
169 void alc_pulse_init(BackendFuncs *func_list);
172 struct ALCdevice_struct
174 ALCboolean Connected;
175 ALboolean IsCaptureDevice;
177 ALuint Frequency;
178 ALuint UpdateSize;
179 ALuint BufferSize;
180 ALenum Format;
182 ALCchar *szDeviceName;
184 // Maximum number of sources that can be created
185 ALuint MaxNoOfSources;
186 // Maximum number of slots that can be created
187 ALuint AuxiliaryEffectSlotMax;
189 ALint lNumMonoSources;
190 ALint lNumStereoSources;
191 ALuint NumAuxSends;
193 // Linked List of Buffers for this device
194 struct ALbuffer *Buffers;
195 ALuint BufferCount;
197 // Linked List of Effects for this device
198 struct ALeffect *EffectList;
199 ALuint EffectCount;
201 // Linked List of Filters for this device
202 struct ALfilter *FilterList;
203 ALuint FilterCount;
205 // Linked List of Databuffers for this device
206 struct ALdatabuffer *Databuffers;
207 ALuint DatabufferCount;
209 // Context created on this device
210 ALCcontext *Context;
212 BackendFuncs *Funcs;
213 void *ExtraData; // For the backend's use
215 ALCdevice *next;
218 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
219 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
220 #define ALCdevice_StartContext(a,b) ((a)->Funcs->StartContext((a), (b)))
221 #define ALCdevice_StopContext(a,b) ((a)->Funcs->StopContext((a), (b)))
222 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
223 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
224 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
225 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
226 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
227 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
229 struct ALCcontext_struct
231 ALlistener Listener;
233 struct ALsource *Source;
234 ALuint SourceCount;
236 struct ALeffectslot *AuxiliaryEffectSlot;
237 ALuint AuxiliaryEffectSlotCount;
239 struct ALdatabuffer *SampleSource;
240 struct ALdatabuffer *SampleSink;
242 ALenum LastError;
243 ALboolean InUse;
245 ALuint Frequency;
247 ALenum DistanceModel;
249 ALfloat DopplerFactor;
250 ALfloat DopplerVelocity;
251 ALfloat flSpeedOfSound;
253 ALfloat PanningLUT[OUTPUTCHANNELS * LUT_NUM];
254 ALint NumChan;
256 ALfloat ChannelMatrix[OUTPUTCHANNELS][OUTPUTCHANNELS];
258 ALCdevice *Device;
259 const ALCchar *ExtensionList;
261 struct bs2b *bs2b;
263 ALCcontext *next;
266 ALCvoid ReleaseALC(ALCvoid);
268 ALCchar *AppendDeviceList(char *name);
269 ALCchar *AppendAllDeviceList(char *name);
270 ALCchar *AppendCaptureDeviceList(char *name);
272 ALCvoid SetALCError(ALenum errorCode);
274 ALCvoid SuspendContext(ALCcontext *context);
275 ALCvoid ProcessContext(ALCcontext *context);
277 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
278 ALuint StopThread(ALvoid *thread);
280 ALCcontext *GetContextSuspended(void);
282 typedef struct RingBuffer RingBuffer;
283 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
284 void DestroyRingBuffer(RingBuffer *ring);
285 ALsizei RingBufferSize(RingBuffer *ring);
286 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
287 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
289 void ReadALConfig(void);
290 void FreeALConfig(void);
291 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
292 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
293 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
295 #ifdef __cplusplus
297 #endif
299 #endif