Store a persistant name string with the device struct
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob26761bb11ceb2aacd9c5b9b56c8ee410bced48ec
1 #ifndef AL_MAIN_H
2 #define AL_MAIN_H
4 #define AL_MAX_CHANNELS 4
5 #define AL_MAX_SOURCES 32
7 #include <string.h>
9 #include "alu.h"
11 #ifdef _WIN32
12 #include <windows.h>
13 //#define strcasecmp _stricmp
15 #else
17 #include <assert.h>
18 #include <pthread.h>
20 #define IsBadWritePtr(a,b) (0)
22 typedef pthread_mutex_t CRITICAL_SECTION;
23 static inline void EnterCriticalSection(CRITICAL_SECTION *cs)
25 int ret;
26 ret = pthread_mutex_lock(cs);
27 assert(ret == 0);
29 static inline void LeaveCriticalSection(CRITICAL_SECTION *cs)
31 int ret;
32 ret = pthread_mutex_unlock(cs);
33 assert(ret == 0);
35 static inline void InitializeCriticalSection(CRITICAL_SECTION *cs)
37 pthread_mutexattr_t attrib;
38 int ret;
40 ret = pthread_mutexattr_init(&attrib);
41 assert(ret == 0);
43 ret = pthread_mutexattr_settype(&attrib, PTHREAD_MUTEX_RECURSIVE);
44 assert(ret == 0);
45 ret = pthread_mutex_init(cs, &attrib);
46 assert(ret == 0);
48 pthread_mutexattr_destroy(&attrib);
51 static inline void DeleteCriticalSection(CRITICAL_SECTION *cs)
53 int ret;
54 ret = pthread_mutex_destroy(cs);
55 assert(ret == 0);
58 #define min(x,y) (((x)<(y))?(x):(y))
59 #define max(x,y) (((x)>(y))?(x):(y))
60 #endif
62 #include "alBuffer.h"
63 #include "alError.h"
64 #include "alExtension.h"
65 #include "alListener.h"
66 #include "alSource.h"
67 #include "alState.h"
68 #include "alThunk.h"
70 #ifdef __cplusplus
71 extern "C"
73 #endif
75 extern CRITICAL_SECTION g_mutex;
77 extern char szDebug[256];
79 #define AL_PRINT(...) do { \
80 int _al_print_i; \
81 char *_al_print_fn = strrchr(__FILE__, '/'); \
82 if(!_al_print_fn) _al_print_fn = __FILE__; \
83 else _al_print_fn += 1; \
84 _al_print_i = snprintf(szDebug, sizeof(szDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
85 snprintf(szDebug+_al_print_i, sizeof(szDebug)-_al_print_i, __VA_ARGS__); \
86 fprintf(stderr, "%s", szDebug); \
87 } while(0)
90 #define AL_FORMAT_MONO_IMA4 0x1300
91 #define AL_FORMAT_STEREO_IMA4 0x1301
92 // These are from AL_EXT_MCFORMATS, which we don't support yet but the mixer
93 // can use 4-channel formats
94 #define AL_FORMAT_QUAD8 0x1204
95 #define AL_FORMAT_QUAD16 0x1205
97 #define SWMIXER_OUTPUT_RATE 44100
98 //#define OUTPUT_BUFFER_SIZE (32768*SWMIXER_OUTPUT_RATE/22050)
100 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
102 typedef struct {
103 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
104 void (*ClosePlayback)(ALCdevice*);
106 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
107 void (*CloseCapture)(ALCdevice*);
108 void (*StartCapture)(ALCdevice*);
109 void (*StopCapture)(ALCdevice*);
110 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
111 ALCuint (*AvailableSamples)(ALCdevice*);
112 } BackendFuncs;
114 void alc_alsa_init(BackendFuncs *func_list);
115 void alc_oss_init(BackendFuncs *func_list);
116 void alcDSoundInit(BackendFuncs *func_list);
117 void alcWinMMInit(BackendFuncs *FuncList);
120 struct ALCdevice_struct
122 ALboolean InUse;
123 ALboolean IsCaptureDevice;
125 ALuint Frequency;
126 ALuint UpdateFreq;
127 ALuint FrameSize;
128 ALuint Channels;
129 ALenum Format;
131 ALCchar *szDeviceName;
133 // Maximum number of sources that can be created
134 ALuint MaxNoOfSources;
136 // Context created on this device
137 ALCcontext *Context;
139 BackendFuncs *Funcs;
140 void *ExtraData; // For the backend's use
143 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
144 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
145 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
146 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
147 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
148 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
149 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
150 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
152 struct ALCcontext_struct
154 ALlistener Listener;
156 ALsource *Source;
157 ALuint SourceCount;
159 ALenum LastError;
160 ALboolean InUse;
162 ALuint Frequency;
164 ALenum DistanceModel;
166 ALfloat DopplerFactor;
167 ALfloat DopplerVelocity;
168 ALfloat flSpeedOfSound;
170 ALint lNumMonoSources;
171 ALint lNumStereoSources;
173 ALCdevice *Device;
174 ALCchar ExtensionList[1024];
176 ALCcontext *next;
179 ALCchar *AppendDeviceList(char *name);
180 ALCchar *AppendAllDeviceList(char *name);
181 ALCchar *AppendCaptureDeviceList(char *name);
183 ALCvoid SetALCError(ALenum errorCode);
185 ALCvoid SuspendContext(ALCcontext *context);
186 ALCvoid ProcessContext(ALCcontext *context);
188 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
189 ALuint StopThread(ALvoid *thread);
191 void ReadALConfig(void);
192 void FreeALConfig(void);
193 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
194 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
195 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
197 #ifdef __cplusplus
199 #endif
201 #endif