Rename UpdateFreq device field to UpdateSize
[openal-soft/openal-hmr.git] / OpenAL32 / Include / alMain.h
bloba833be5eff4097cb51f0502b50a365d2ef54984f
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #include <string.h>
5 #include <stdio.h>
7 #include "alu.h"
9 #ifdef _WIN32
11 #include <windows.h>
13 #else
15 #include <assert.h>
16 #include <pthread.h>
17 #include <sys/time.h>
18 #include <time.h>
19 #include <errno.h>
21 #define IsBadWritePtr(a,b) (0)
23 typedef pthread_mutex_t CRITICAL_SECTION;
24 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
26 int ret;
27 ret = pthread_mutex_lock(cs);
28 assert(ret == 0);
30 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
32 int ret;
33 ret = pthread_mutex_unlock(cs);
34 assert(ret == 0);
36 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
38 pthread_mutexattr_t attrib;
39 int ret;
41 ret = pthread_mutexattr_init(&attrib);
42 assert(ret == 0);
44 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
45 assert(ret == 0);
46 ret = pthread_mutex_init(cs, &attrib);
47 assert(ret == 0);
49 pthread_mutexattr_destroy(&attrib);
52 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
54 int ret;
55 ret = pthread_mutex_destroy(cs);
56 assert(ret == 0);
59 /* NOTE: This wrapper isn't quite accurate as it returns an ALuint, as opposed
60 * to the expected DWORD. Both are defined as unsigned 32-bit types, however.
61 * Additionally, Win32 is supposed to measure the time since Windows started,
62 * as opposed to the actual time. */
63 static inline ALuint timeGetTime(void)
65 struct timeval tv;
66 int ret;
68 ret = gettimeofday(&tv, NULL);
69 assert(ret == 0);
71 return tv.tv_usec/1000 + tv.tv_sec*1000;
74 static inline void Sleep(ALuint t)
76 struct timespec tv, rem;
77 tv.tv_nsec = (t*1000000)%1000000000;
78 tv.tv_sec = t/1000;
80 while(nanosleep(&tv, &rem) == -1 && errno == EINTR)
81 tv = rem;
83 #define min(x,y) (((x)<(y))?(x):(y))
84 #define max(x,y) (((x)>(y))?(x):(y))
85 #endif
87 #include "AL/al.h"
88 #include "AL/alc.h"
89 #include "AL/alext.h"
90 #include "alListener.h"
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
96 extern CRITICAL_SECTION _alMutex;
98 extern char _alDebug[256];
100 #define AL_PRINT(...) do { \
101 int _al_print_i; \
102 char *_al_print_fn = strrchr(__FILE__, '/'); \
103 if(!_al_print_fn) _al_print_fn = __FILE__; \
104 else _al_print_fn += 1; \
105 _al_print_i = snprintf(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
106 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
107 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
108 _alDebug[sizeof(_alDebug)-1] = 0; \
109 fprintf(stderr, "%s", _alDebug); \
110 } while(0)
113 #define SWMIXER_OUTPUT_RATE 44100
115 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
116 #define AIRABSORBGAINHF (0.994f)
118 typedef struct {
119 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
120 void (*ClosePlayback)(ALCdevice*);
122 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
123 void (*CloseCapture)(ALCdevice*);
124 void (*StartCapture)(ALCdevice*);
125 void (*StopCapture)(ALCdevice*);
126 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
127 ALCuint (*AvailableSamples)(ALCdevice*);
128 } BackendFuncs;
130 void alc_alsa_init(BackendFuncs *func_list);
131 void alc_oss_init(BackendFuncs *func_list);
132 void alcDSoundInit(BackendFuncs *func_list);
133 void alcWinMMInit(BackendFuncs *FuncList);
134 void alc_wave_init(BackendFuncs *func_list);
137 struct ALCdevice_struct
139 ALboolean IsCaptureDevice;
141 ALuint Frequency;
142 ALuint UpdateSize;
143 ALuint FrameSize;
144 ALenum Format;
146 ALCchar *szDeviceName;
148 // Maximum number of sources that can be created
149 ALuint MaxNoOfSources;
151 // Context created on this device
152 ALCcontext *Context;
154 BackendFuncs *Funcs;
155 void *ExtraData; // For the backend's use
157 ALCdevice *next;
160 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
161 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
162 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
163 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
164 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
165 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
166 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
167 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
169 struct ALCcontext_struct
171 ALlistener Listener;
173 struct ALsource *Source;
174 ALuint SourceCount;
176 struct ALeffectslot *AuxiliaryEffectSlot;
177 ALuint AuxiliaryEffectSlotCount;
179 ALenum LastError;
180 ALboolean InUse;
182 ALuint Frequency;
184 ALenum DistanceModel;
186 ALfloat DopplerFactor;
187 ALfloat DopplerVelocity;
188 ALfloat flSpeedOfSound;
190 ALint lNumMonoSources;
191 ALint lNumStereoSources;
193 ALCdevice *Device;
194 ALCchar ExtensionList[1024];
196 struct bs2b *bs2b;
198 ALCcontext *next;
201 ALCvoid ReleaseALC(ALCvoid);
203 ALCchar *AppendDeviceList(char *name);
204 ALCchar *AppendAllDeviceList(char *name);
205 ALCchar *AppendCaptureDeviceList(char *name);
207 ALCvoid SetALCError(ALenum errorCode);
209 ALCvoid SuspendContext(ALCcontext *context);
210 ALCvoid ProcessContext(ALCcontext *context);
212 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
213 ALuint StopThread(ALvoid *thread);
215 typedef struct RingBuffer RingBuffer;
216 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
217 void DestroyRingBuffer(RingBuffer *ring);
218 ALsizei RingBufferSize(RingBuffer *ring);
219 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
220 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
222 void ReadALConfig(void);
223 void FreeALConfig(void);
224 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
225 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
226 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
228 #ifdef __cplusplus
230 #endif
232 #endif