Store the effect and filter lists in the device
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob78128c9092fae280ad9e11cedf125732dcab668e
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 ALboolean IsCaptureDevice;
176 ALuint Frequency;
177 ALuint UpdateSize;
178 ALuint BufferSize;
179 ALenum Format;
181 ALCchar *szDeviceName;
183 // Maximum number of sources that can be created
184 ALuint MaxNoOfSources;
185 // Maximum number of slots that can be created
186 ALuint AuxiliaryEffectSlotMax;
188 ALint lNumMonoSources;
189 ALint lNumStereoSources;
190 ALuint NumAuxSends;
192 // Linked List of Buffers for this device
193 struct ALbuffer *Buffers;
194 ALuint BufferCount;
196 // Linked List of Effects for this device
197 struct ALeffect *EffectList;
198 ALuint EffectCount;
200 // Linked List of Filters for this device
201 struct ALfilter *FilterList;
202 ALuint FilterCount;
204 // Context created on this device
205 ALCcontext *Context;
207 BackendFuncs *Funcs;
208 void *ExtraData; // For the backend's use
210 ALCdevice *next;
213 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
214 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
215 #define ALCdevice_StartContext(a,b) ((a)->Funcs->StartContext((a), (b)))
216 #define ALCdevice_StopContext(a,b) ((a)->Funcs->StopContext((a), (b)))
217 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
218 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
219 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
220 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
221 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
222 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
224 struct ALCcontext_struct
226 ALlistener Listener;
228 struct ALsource *Source;
229 ALuint SourceCount;
231 struct ALeffectslot *AuxiliaryEffectSlot;
232 ALuint AuxiliaryEffectSlotCount;
234 ALenum LastError;
235 ALboolean InUse;
237 ALuint Frequency;
239 ALenum DistanceModel;
241 ALfloat DopplerFactor;
242 ALfloat DopplerVelocity;
243 ALfloat flSpeedOfSound;
245 ALfloat PanningLUT[OUTPUTCHANNELS * LUT_NUM];
246 ALint NumChan;
248 ALfloat ChannelMatrix[OUTPUTCHANNELS][OUTPUTCHANNELS];
250 ALCdevice *Device;
251 const ALCchar *ExtensionList;
253 struct bs2b *bs2b;
255 ALCcontext *next;
258 ALCvoid ReleaseALC(ALCvoid);
260 ALCchar *AppendDeviceList(char *name);
261 ALCchar *AppendAllDeviceList(char *name);
262 ALCchar *AppendCaptureDeviceList(char *name);
264 ALCvoid SetALCError(ALenum errorCode);
266 ALCvoid SuspendContext(ALCcontext *context);
267 ALCvoid ProcessContext(ALCcontext *context);
269 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
270 ALuint StopThread(ALvoid *thread);
272 typedef struct RingBuffer RingBuffer;
273 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
274 void DestroyRingBuffer(RingBuffer *ring);
275 ALsizei RingBufferSize(RingBuffer *ring);
276 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
277 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
279 void ReadALConfig(void);
280 void FreeALConfig(void);
281 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
282 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
283 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
285 #ifdef __cplusplus
287 #endif
289 #endif