Remove the Frequency field from the context
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob2fa795743b37d4a3979ecd13cdb7e4e2d3cf6c4c
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 typedef DWORD tls_type;
24 #define tls_create(x) (*(x) = TlsAlloc())
25 #define tls_delete(x) TlsFree((x))
26 #define tls_get(x) TlsGetValue((x))
27 #define tls_set(x, a) TlsSetValue((x), (a))
29 #else
31 #include <assert.h>
32 #include <pthread.h>
33 #ifdef HAVE_PTHREAD_NP_H
34 #include <pthread_np.h>
35 #endif
36 #include <sys/time.h>
37 #include <time.h>
38 #include <errno.h>
40 #define IsBadWritePtr(a,b) (0)
42 typedef pthread_key_t tls_type;
43 #define tls_create(x) pthread_key_create((x), NULL)
44 #define tls_delete(x) pthread_key_delete((x))
45 #define tls_get(x) pthread_getspecific((x))
46 #define tls_set(x, a) pthread_setspecific((x), (a))
48 typedef pthread_mutex_t CRITICAL_SECTION;
49 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
51 int ret;
52 ret = pthread_mutex_lock(cs);
53 assert(ret == 0);
55 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
57 int ret;
58 ret = pthread_mutex_unlock(cs);
59 assert(ret == 0);
61 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
63 pthread_mutexattr_t attrib;
64 int ret;
66 ret = pthread_mutexattr_init(&attrib);
67 assert(ret == 0);
69 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
70 #ifdef HAVE_PTHREAD_NP_H
71 if(ret != 0)
72 ret = pthread_mutexattr_setkind_np(&attrib, PTHREAD_MUTEX_RECURSIVE);
73 #endif
74 assert(ret == 0);
75 ret = pthread_mutex_init(cs, &attrib);
76 assert(ret == 0);
78 pthread_mutexattr_destroy(&attrib);
81 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
83 int ret;
84 ret = pthread_mutex_destroy(cs);
85 assert(ret == 0);
88 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
89 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
90 * Additionally, Win32 is supposed to measure the time since Windows started,
91 * as opposed to the actual time. */
92 static inline ALuint timeGetTime(void)
94 struct timeval tv;
95 int ret;
97 ret = gettimeofday(&tv, NULL);
98 assert(ret == 0);
100 return tv.tv_usec/1000 + tv.tv_sec*1000;
103 static inline void Sleep(ALuint t)
105 struct timespec tv, rem;
106 tv.tv_nsec = (t*1000000)%1000000000;
107 tv.tv_sec = t/1000;
109 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
110 tv = rem;
112 #define min(x,y) (((x)<(y))?(x):(y))
113 #define max(x,y) (((x)>(y))?(x):(y))
114 #endif
116 #include "alListener.h"
117 #include "alu.h"
119 #ifdef __cplusplus
120 extern "C" {
121 #endif
123 static __inline void al_print(const char *fname, unsigned int line, const char *fmt, ...)
125 const char *fn;
126 char str[256];
127 int i;
129 fn = strrchr(fname, '/');
130 if(!fn) fn = strrchr(fname, '\\');;
131 if(!fn) fn = fname;
132 else fn += 1;
134 i = snprintf(str, sizeof(str), "AL lib: %s:%d: ", fn, line);
135 if(i < (int)sizeof(str) && i > 0)
137 va_list ap;
138 va_start(ap, fmt);
139 vsnprintf(str+i, sizeof(str)-i, fmt, ap);
140 va_end(ap);
142 str[sizeof(str)-1] = 0;
144 fprintf(stderr, "%s", str);
146 #define AL_PRINT(...) al_print(__FILE__, __LINE__, __VA_ARGS__)
149 #define SWMIXER_OUTPUT_RATE 44100
151 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
152 #define AIRABSORBGAINDBHF (-0.05f)
154 #define LOWPASSFREQCUTOFF (5000)
156 #define QUADRANT_NUM 128
157 #define LUT_NUM (4 * QUADRANT_NUM)
160 typedef struct {
161 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
162 void (*ClosePlayback)(ALCdevice*);
163 ALCboolean (*ResetPlayback)(ALCdevice*);
164 void (*StopPlayback)(ALCdevice*);
166 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*);
167 void (*CloseCapture)(ALCdevice*);
168 void (*StartCapture)(ALCdevice*);
169 void (*StopCapture)(ALCdevice*);
170 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
171 ALCuint (*AvailableSamples)(ALCdevice*);
172 } BackendFuncs;
174 enum {
175 DEVICE_PROBE,
176 ALL_DEVICE_PROBE,
177 CAPTURE_DEVICE_PROBE
180 void alc_alsa_init(BackendFuncs *func_list);
181 void alc_alsa_deinit(void);
182 void alc_alsa_probe(int type);
183 void alc_oss_init(BackendFuncs *func_list);
184 void alc_oss_deinit(void);
185 void alc_oss_probe(int type);
186 void alc_solaris_init(BackendFuncs *func_list);
187 void alc_solaris_deinit(void);
188 void alc_solarise_probe(int type);
189 void alcDSoundInit(BackendFuncs *func_list);
190 void alcDSoundDeinit(void);
191 void alcDSoundProbe(int type);
192 void alcWinMMInit(BackendFuncs *FuncList);
193 void alcWinMMDeinit(void);
194 void alcWinMMProbe(int type);
195 void alc_pa_init(BackendFuncs *func_list);
196 void alc_pa_deinit(void);
197 void alc_pa_probe(int type);
198 void alc_wave_init(BackendFuncs *func_list);
199 void alc_wave_deinit(void);
200 void alc_wave_probe(int type);
201 void alc_pulse_init(BackendFuncs *func_list);
202 void alc_pulse_deinit(void);
203 void alc_pulse_probe(int type);
206 struct ALCdevice_struct
208 ALCboolean Connected;
209 ALboolean IsCaptureDevice;
211 ALuint Frequency;
212 ALuint UpdateSize;
213 ALuint NumUpdates;
214 ALenum Format;
216 ALCchar *szDeviceName;
218 // Maximum number of sources that can be created
219 ALuint MaxNoOfSources;
220 // Maximum number of slots that can be created
221 ALuint AuxiliaryEffectSlotMax;
223 ALint lNumMonoSources;
224 ALint lNumStereoSources;
225 ALuint NumAuxSends;
227 // Linked List of Buffers for this device
228 struct ALbuffer *Buffers;
229 ALuint BufferCount;
231 // Linked List of Effects for this device
232 struct ALeffect *EffectList;
233 ALuint EffectCount;
235 // Linked List of Filters for this device
236 struct ALfilter *FilterList;
237 ALuint FilterCount;
239 // Linked List of Databuffers for this device
240 struct ALdatabuffer *Databuffers;
241 ALuint DatabufferCount;
243 // Stereo-to-binaural filter
244 struct bs2b *Bs2b;
245 ALCint Bs2bLevel;
247 // Dry path buffer mix
248 float DryBuffer[BUFFERSIZE][OUTPUTCHANNELS];
250 // Contexts created on this device
251 ALCcontext **Contexts;
252 ALuint NumContexts;
254 BackendFuncs *Funcs;
255 void *ExtraData; // For the backend's use
257 ALCdevice *next;
260 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
261 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
262 #define ALCdevice_ResetPlayback(a) ((a)->Funcs->ResetPlayback((a)))
263 #define ALCdevice_StopPlayback(a) ((a)->Funcs->StopPlayback((a)))
264 #define ALCdevice_OpenCapture(a,b) ((a)->Funcs->OpenCapture((a), (b)))
265 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
266 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
267 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
268 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
269 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
271 struct ALCcontext_struct
273 ALlistener Listener;
275 struct ALsource *Source;
276 ALuint SourceCount;
278 struct ALeffectslot *AuxiliaryEffectSlot;
279 ALuint AuxiliaryEffectSlotCount;
281 struct ALdatabuffer *SampleSource;
282 struct ALdatabuffer *SampleSink;
284 ALenum LastError;
285 ALboolean InUse;
287 ALenum DistanceModel;
289 ALfloat DopplerFactor;
290 ALfloat DopplerVelocity;
291 ALfloat flSpeedOfSound;
293 ALfloat PanningLUT[OUTPUTCHANNELS * LUT_NUM];
294 ALint NumChan;
296 ALfloat ChannelMatrix[OUTPUTCHANNELS][OUTPUTCHANNELS];
298 ALCdevice *Device;
299 const ALCchar *ExtensionList;
301 ALCcontext *next;
304 ALCvoid ReleaseALC(ALCvoid);
306 void AppendDeviceList(const ALCchar *name);
307 void AppendAllDeviceList(const ALCchar *name);
308 void AppendCaptureDeviceList(const ALCchar *name);
310 ALCvoid alcSetError(ALenum errorCode);
312 ALCvoid SuspendContext(ALCcontext *context);
313 ALCvoid ProcessContext(ALCcontext *context);
315 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
316 ALuint StopThread(ALvoid *thread);
318 ALCcontext *GetContextSuspended(void);
320 typedef struct RingBuffer RingBuffer;
321 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
322 void DestroyRingBuffer(RingBuffer *ring);
323 ALsizei RingBufferSize(RingBuffer *ring);
324 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
325 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
327 void ReadALConfig(void);
328 void FreeALConfig(void);
329 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
330 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
331 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
332 int GetConfigValueBool(const char *blockName, const char *keyName, float def);
334 ALCboolean ALCAPIENTRY alcMakeCurrent(ALCcontext *context);
335 ALCcontext* ALCAPIENTRY alcGetThreadContext(void);
337 #ifdef __cplusplus
339 #endif
341 #endif