Merge branch 'master' into efx-experiment
[openal-soft.git] / OpenAL32 / Include / alMain.h
bloba5e5184af135d8991e467dc022610eefa2ef14f6
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
6 #include "alu.h"
8 #ifdef _WIN32
9 #include <windows.h>
10 //#define strcasecmp _stricmp
12 #else
14 #include <assert.h>
15 #include <pthread.h>
17 #define IsBadWritePtr(a,b) (0)
19 typedef pthread_mutex_t CRITICAL_SECTION;
20 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
22 int ret;
23 ret = pthread_mutex_lock(cs);
24 assert(ret == 0);
26 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
28 int ret;
29 ret = pthread_mutex_unlock(cs);
30 assert(ret == 0);
32 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
34 pthread_mutexattr_t attrib;
35 int ret;
37 ret = pthread_mutexattr_init(&attrib);
38 assert(ret == 0);
40 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
41 assert(ret == 0);
42 ret = pthread_mutex_init(cs, &attrib);
43 assert(ret == 0);
45 pthread_mutexattr_destroy(&attrib);
48 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
50 int ret;
51 ret = pthread_mutex_destroy(cs);
52 assert(ret == 0);
55 #define min(x,y) (((x)<(y))?(x):(y))
56 #define max(x,y) (((x)>(y))?(x):(y))
57 #endif
59 #include "alListener.h"
61 #ifdef __cplusplus
62 extern "C"
64 #endif
66 extern CRITICAL_SECTION _alMutex;
68 extern char _alDebug[256];
70 #define AL_PRINT(...) do { \
71 int _al_print_i; \
72 char *_al_print_fn = strrchr(__FILE__, '/'); \
73 if(!_al_print_fn) _al_print_fn = __FILE__; \
74 else _al_print_fn += 1; \
75 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
76 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
77 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
78 _alDebug[sizeof(_alDebug)-1] = 0; \
79 fprintf(stderr, "%s", _alDebug); \
80 } while(0)
83 #define AL_FORMAT_MONO_FLOAT32 0x10010
84 #define AL_FORMAT_STEREO_FLOAT32 0x10011
86 #define AL_FORMAT_MONO_IMA4 0x1300
87 #define AL_FORMAT_STEREO_IMA4 0x1301
89 #define AL_FORMAT_51CHN8 0x120A
90 #define AL_FORMAT_51CHN16 0x120B
91 #define AL_FORMAT_51CHN32 0x120C
92 #define AL_FORMAT_61CHN8 0x120D
93 #define AL_FORMAT_61CHN16 0x120E
94 #define AL_FORMAT_61CHN32 0x120F
95 #define AL_FORMAT_71CHN8 0x1210
96 #define AL_FORMAT_71CHN16 0x1211
97 #define AL_FORMAT_71CHN32 0x1212
98 #define AL_FORMAT_QUAD8 0x1204
99 #define AL_FORMAT_QUAD16 0x1205
100 #define AL_FORMAT_QUAD32 0x1206
101 #define AL_FORMAT_REAR8 0x1207
102 #define AL_FORMAT_REAR16 0x1208
103 #define AL_FORMAT_REAR32 0x1209
105 #define SWMIXER_OUTPUT_RATE 44100
107 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
108 #define AIRABSORBGAINHF (0.994f)
110 typedef struct {
111 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
112 void (*ClosePlayback)(ALCdevice*);
114 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
115 void (*CloseCapture)(ALCdevice*);
116 void (*StartCapture)(ALCdevice*);
117 void (*StopCapture)(ALCdevice*);
118 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
119 ALCuint (*AvailableSamples)(ALCdevice*);
120 } BackendFuncs;
122 void alc_alsa_init(BackendFuncs *func_list);
123 void alc_oss_init(BackendFuncs *func_list);
124 void alcDSoundInit(BackendFuncs *func_list);
125 void alcWinMMInit(BackendFuncs *FuncList);
128 struct ALCdevice_struct
130 ALboolean InUse;
131 ALboolean IsCaptureDevice;
133 ALuint Frequency;
134 ALuint UpdateFreq;
135 ALuint FrameSize;
136 ALuint Channels;
137 ALenum Format;
139 ALCchar *szDeviceName;
141 // Maximum number of sources that can be created
142 ALuint MaxNoOfSources;
144 // Context created on this device
145 ALCcontext *Context;
147 BackendFuncs *Funcs;
148 void *ExtraData; // For the backend's use
151 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
152 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
153 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
154 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
155 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
156 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
157 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
158 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
160 struct ALCcontext_struct
162 ALlistener Listener;
164 struct ALsource *Source;
165 ALuint SourceCount;
167 ALenum LastError;
168 ALboolean InUse;
170 ALuint Frequency;
172 ALenum DistanceModel;
174 ALfloat DopplerFactor;
175 ALfloat DopplerVelocity;
176 ALfloat flSpeedOfSound;
178 ALint lNumMonoSources;
179 ALint lNumStereoSources;
181 ALCdevice *Device;
182 ALCchar ExtensionList[1024];
184 ALCcontext *next;
187 ALCchar *AppendDeviceList(char *name);
188 ALCchar *AppendAllDeviceList(char *name);
189 ALCchar *AppendCaptureDeviceList(char *name);
191 ALCvoid SetALCError(ALenum errorCode);
193 ALCvoid SuspendContext(ALCcontext *context);
194 ALCvoid ProcessContext(ALCcontext *context);
196 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
197 ALuint StopThread(ALvoid *thread);
199 typedef struct RingBuffer RingBuffer;
200 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
201 void DestroyRingBuffer(RingBuffer *ring);
202 ALsizei RingBufferSize(RingBuffer *ring);
203 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
204 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
206 void ReadALConfig(void);
207 void FreeALConfig(void);
208 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
209 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
210 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
212 #ifdef __cplusplus
214 #endif
216 #endif