Set some common macros in alu.h
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob828777351214d0d6bfd983eef49f5fefd1bed3ac
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
7 #ifdef HAVE_FENV_H
8 #include <fenv.h>
9 #endif
11 #include "AL/al.h"
12 #include "AL/alc.h"
13 #include "AL/alext.h"
15 #ifdef _WIN32
17 #ifndef _WIN32_WINNT
18 #define _WIN32_WINNT 0x0500
19 #endif
20 #include <windows.h>
22 #else
24 #include <assert.h>
25 #include <pthread.h>
26 #ifdef HAVE_PTHREAD_NP_H
27 #include <pthread_np.h>
28 #endif
29 #include <sys/time.h>
30 #include <time.h>
31 #include <errno.h>
33 #define IsBadWritePtr(a,b) (0)
35 typedef pthread_mutex_t CRITICAL_SECTION;
36 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
38 int ret;
39 ret = pthread_mutex_lock(cs);
40 assert(ret == 0);
42 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
44 int ret;
45 ret = pthread_mutex_unlock(cs);
46 assert(ret == 0);
48 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
50 pthread_mutexattr_t attrib;
51 int ret;
53 ret = pthread_mutexattr_init(&attrib);
54 assert(ret == 0);
56 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
57 #ifdef HAVE_PTHREAD_NP_H
58 if(ret != 0)
59 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
60 #endif
61 assert(ret == 0);
62 ret = pthread_mutex_init(cs, &attrib);
63 assert(ret == 0);
65 pthread_mutexattr_destroy(&attrib);
68 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
70 int ret;
71 ret = pthread_mutex_destroy(cs);
72 assert(ret == 0);
75 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
76 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
77 * Additionally, Win32 is supposed to measure the time since Windows started,
78 * as opposed to the actual time. */
79 static inline ALuint timeGetTime(void)
81 struct timeval tv;
82 int ret;
84 ret = gettimeofday(&tv, NULL);
85 assert(ret == 0);
87 return tv.tv_usec/1000 + tv.tv_sec*1000;
90 static inline void Sleep(ALuint t)
92 struct timespec tv, rem;
93 tv.tv_nsec = (t*1000000)%1000000000;
94 tv.tv_sec = t/1000;
96 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
97 tv = rem;
99 #define min(x,y) (((x)<(y))?(x):(y))
100 #define max(x,y) (((x)>(y))?(x):(y))
101 #endif
103 #include "alListener.h"
104 #include "alu.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);
155 void alc_pulse_init(BackendFuncs *func_list);
158 struct ALCdevice_struct
160 ALboolean IsCaptureDevice;
162 ALuint Frequency;
163 ALuint UpdateSize;
164 ALenum Format;
166 ALCchar *szDeviceName;
168 // Maximum number of sources that can be created
169 ALuint MaxNoOfSources;
171 // Context created on this device
172 ALCcontext *Context;
174 BackendFuncs *Funcs;
175 void *ExtraData; // For the backend's use
177 ALCdevice *next;
180 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
181 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
182 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
183 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
184 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
185 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
186 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
187 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
189 struct ALCcontext_struct
191 ALlistener Listener;
193 struct ALsource *Source;
194 ALuint SourceCount;
196 struct ALeffectslot *AuxiliaryEffectSlot;
197 ALuint AuxiliaryEffectSlotCount;
198 // Maximum number of slots that can be created
199 ALuint AuxiliaryEffectSlotMax;
201 ALenum LastError;
202 ALboolean InUse;
204 ALuint Frequency;
206 ALenum DistanceModel;
208 ALfloat DopplerFactor;
209 ALfloat DopplerVelocity;
210 ALfloat flSpeedOfSound;
212 ALint lNumMonoSources;
213 ALint lNumStereoSources;
215 ALuint NumSends;
217 ALfloat PanningLUT[OUTPUTCHANNELS * LUT_NUM];
218 ALint NumChan;
220 ALfloat ChannelMatrix[OUTPUTCHANNELS][OUTPUTCHANNELS];
222 ALCdevice *Device;
223 const ALCchar *ExtensionList;
225 struct bs2b *bs2b;
227 ALCcontext *next;
230 ALCvoid ReleaseALC(ALCvoid);
232 ALCchar *AppendDeviceList(char *name);
233 ALCchar *AppendAllDeviceList(char *name);
234 ALCchar *AppendCaptureDeviceList(char *name);
236 ALCvoid SetALCError(ALenum errorCode);
238 ALCvoid SuspendContext(ALCcontext *context);
239 ALCvoid ProcessContext(ALCcontext *context);
241 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
242 ALuint StopThread(ALvoid *thread);
244 typedef struct RingBuffer RingBuffer;
245 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
246 void DestroyRingBuffer(RingBuffer *ring);
247 ALsizei RingBufferSize(RingBuffer *ring);
248 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
249 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
251 void ReadALConfig(void);
252 void FreeALConfig(void);
253 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
254 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
255 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
257 #ifdef __cplusplus
259 #endif
261 #endif