Remove the SDL backend
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob68b176e4b72b9d3d9234d92f03097a8dc6b29a1b
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
7 #include "alu.h"
9 #ifdef HAVE_FENV_H
10 #include <fenv.h>
11 #endif
13 #ifdef _WIN32
15 #ifndef _WIN32_WINNT
16 #define _WIN32_WINNT 0x0500
17 #endif
18 #include <windows.h>
20 #else
22 #include <assert.h>
23 #include <pthread.h>
24 #ifdef HAVE_PTHREAD_NP_H
25 #include <pthread_np.h>
26 #endif
27 #include <sys/time.h>
28 #include <time.h>
29 #include <errno.h>
31 #define IsBadWritePtr(a,b) (0)
33 typedef pthread_mutex_t CRITICAL_SECTION;
34 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
36 int ret;
37 ret = pthread_mutex_lock(cs);
38 assert(ret == 0);
40 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
42 int ret;
43 ret = pthread_mutex_unlock(cs);
44 assert(ret == 0);
46 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
48 pthread_mutexattr_t attrib;
49 int ret;
51 ret = pthread_mutexattr_init(&attrib);
52 assert(ret == 0);
54 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
55 #ifdef HAVE_PTHREAD_NP_H
56 if(ret != 0)
57 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
58 #endif
59 assert(ret == 0);
60 ret = pthread_mutex_init(cs, &attrib);
61 assert(ret == 0);
63 pthread_mutexattr_destroy(&attrib);
66 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
68 int ret;
69 ret = pthread_mutex_destroy(cs);
70 assert(ret == 0);
73 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
74 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
75 * Additionally, Win32 is supposed to measure the time since Windows started,
76 * as opposed to the actual time. */
77 static inline ALuint timeGetTime(void)
79 struct timeval tv;
80 int ret;
82 ret = gettimeofday(&tv, NULL);
83 assert(ret == 0);
85 return tv.tv_usec/1000 + tv.tv_sec*1000;
88 static inline void Sleep(ALuint t)
90 struct timespec tv, rem;
91 tv.tv_nsec = (t*1000000)%1000000000;
92 tv.tv_sec = t/1000;
94 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
95 tv = rem;
97 #define min(x,y) (((x)<(y))?(x):(y))
98 #define max(x,y) (((x)>(y))?(x):(y))
99 #endif
101 #include "AL/al.h"
102 #include "AL/alc.h"
103 #include "AL/alext.h"
104 #include "alListener.h"
106 #ifdef __cplusplus
107 extern "C" {
108 #endif
110 extern char _alDebug[256];
112 #define AL_PRINT(...) do { \
113 int _al_print_i; \
114 const char *_al_print_fn = strrchr(__FILE__, '/'); \
115 if(!_al_print_fn) _al_print_fn = __FILE__; \
116 else _al_print_fn += 1; \
117 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
118 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
119 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
120 _alDebug[sizeof(_alDebug)-1] = 0; \
121 fprintf(stderr, "%s", _alDebug); \
122 } while(0)
125 #define SWMIXER_OUTPUT_RATE 44100
127 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
128 #define AIRABSORBGAINDBHF (-0.05f)
130 #define LOWPASSFREQCUTOFF (5000)
132 #define QUADRANT_NUM 128
133 #define LUT_NUM (4 * QUADRANT_NUM)
136 typedef struct {
137 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
138 void (*ClosePlayback)(ALCdevice*);
140 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
141 void (*CloseCapture)(ALCdevice*);
142 void (*StartCapture)(ALCdevice*);
143 void (*StopCapture)(ALCdevice*);
144 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
145 ALCuint (*AvailableSamples)(ALCdevice*);
146 } BackendFuncs;
148 void alc_alsa_init(BackendFuncs *func_list);
149 void alc_oss_init(BackendFuncs *func_list);
150 void alc_solaris_init(BackendFuncs *func_list);
151 void alcDSoundInit(BackendFuncs *func_list);
152 void alcWinMMInit(BackendFuncs *FuncList);
153 void alc_pa_init(BackendFuncs *func_list);
154 void alc_wave_init(BackendFuncs *func_list);
157 struct ALCdevice_struct
159 ALboolean IsCaptureDevice;
161 ALuint Frequency;
162 ALuint UpdateSize;
163 ALenum Format;
165 ALCchar *szDeviceName;
167 // Maximum number of sources that can be created
168 ALuint MaxNoOfSources;
170 // Context created on this device
171 ALCcontext *Context;
173 BackendFuncs *Funcs;
174 void *ExtraData; // For the backend's use
176 ALCdevice *next;
179 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
180 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
181 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
182 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
183 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
184 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
185 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
186 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
188 struct ALCcontext_struct
190 ALlistener Listener;
192 struct ALsource *Source;
193 ALuint SourceCount;
195 struct ALeffectslot *AuxiliaryEffectSlot;
196 ALuint AuxiliaryEffectSlotCount;
198 ALenum LastError;
199 ALboolean InUse;
201 ALuint Frequency;
203 ALenum DistanceModel;
205 ALfloat DopplerFactor;
206 ALfloat DopplerVelocity;
207 ALfloat flSpeedOfSound;
209 ALint lNumMonoSources;
210 ALint lNumStereoSources;
212 ALfloat PanningLUT[OUTPUTCHANNELS * LUT_NUM];
213 ALint NumChan;
215 ALfloat ChannelMatrix[OUTPUTCHANNELS][OUTPUTCHANNELS];
217 ALCdevice *Device;
218 const ALCchar *ExtensionList;
220 struct bs2b *bs2b;
222 ALCcontext *next;
225 ALCvoid ReleaseALC(ALCvoid);
227 ALCchar *AppendDeviceList(char *name);
228 ALCchar *AppendAllDeviceList(char *name);
229 ALCchar *AppendCaptureDeviceList(char *name);
231 ALCvoid SetALCError(ALenum errorCode);
233 ALCvoid SuspendContext(ALCcontext *context);
234 ALCvoid ProcessContext(ALCcontext *context);
236 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
237 ALuint StopThread(ALvoid *thread);
239 typedef struct RingBuffer RingBuffer;
240 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
241 void DestroyRingBuffer(RingBuffer *ring);
242 ALsizei RingBufferSize(RingBuffer *ring);
243 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
244 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
246 void ReadALConfig(void);
247 void FreeALConfig(void);
248 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
249 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
250 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
252 #ifdef __cplusplus
254 #endif
256 #endif