Allow 5.1 channel output
[openal-soft.git] / OpenAL32 / Include / alMain.h
blob30dd068f8561f3bd84f2462ae9a678a26c9c27eb
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 _alMutex;
77 extern char _alDebug[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(_alDebug, sizeof(_alDebug), "AL lib: %s:%d: ", _al_print_fn, __LINE__); \
85 if(_al_print_i < (int)sizeof(_alDebug) && _al_print_i > 0) \
86 snprintf(_alDebug+_al_print_i, sizeof(_alDebug)-_al_print_i, __VA_ARGS__); \
87 _alDebug[sizeof(_alDebug)-1] = 0; \
88 fprintf(stderr, "%s", _alDebug); \
89 } while(0)
92 #define AL_FORMAT_MONO_IMA4 0x1300
93 #define AL_FORMAT_STEREO_IMA4 0x1301
94 // These are from AL_EXT_MCFORMATS, which we don't support yet but the mixer
95 // can use the extra formats
96 #define AL_FORMAT_QUAD8 0x1204
97 #define AL_FORMAT_QUAD16 0x1205
98 #define AL_FORMAT_51CHN8 0x120A
99 #define AL_FORMAT_51CHN16 0x120B
101 #define SWMIXER_OUTPUT_RATE 44100
102 //#define OUTPUT_BUFFER_SIZE (32768*SWMIXER_OUTPUT_RATE/22050)
104 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
106 typedef struct {
107 ALCboolean (*OpenPlayback)(ALCdevice*, const ALCchar*);
108 void (*ClosePlayback)(ALCdevice*);
110 ALCboolean (*OpenCapture)(ALCdevice*, const ALCchar*, ALCuint, ALCenum, ALCsizei);
111 void (*CloseCapture)(ALCdevice*);
112 void (*StartCapture)(ALCdevice*);
113 void (*StopCapture)(ALCdevice*);
114 void (*CaptureSamples)(ALCdevice*, void*, ALCuint);
115 ALCuint (*AvailableSamples)(ALCdevice*);
116 } BackendFuncs;
118 void alc_alsa_init(BackendFuncs *func_list);
119 void alc_oss_init(BackendFuncs *func_list);
120 void alcDSoundInit(BackendFuncs *func_list);
121 void alcWinMMInit(BackendFuncs *FuncList);
124 struct ALCdevice_struct
126 ALboolean InUse;
127 ALboolean IsCaptureDevice;
129 ALuint Frequency;
130 ALuint UpdateFreq;
131 ALuint FrameSize;
132 ALuint Channels;
133 ALenum Format;
135 ALCchar *szDeviceName;
137 // Maximum number of sources that can be created
138 ALuint MaxNoOfSources;
140 // Context created on this device
141 ALCcontext *Context;
143 BackendFuncs *Funcs;
144 void *ExtraData; // For the backend's use
147 #define ALCdevice_OpenPlayback(a,b) ((a)->Funcs->OpenPlayback((a), (b)))
148 #define ALCdevice_ClosePlayback(a) ((a)->Funcs->ClosePlayback((a)))
149 #define ALCdevice_OpenCapture(a,b,c,d,e) ((a)->Funcs->OpenCapture((a), (b), (c), (d), (e)))
150 #define ALCdevice_CloseCapture(a) ((a)->Funcs->CloseCapture((a)))
151 #define ALCdevice_StartCapture(a) ((a)->Funcs->StartCapture((a)))
152 #define ALCdevice_StopCapture(a) ((a)->Funcs->StopCapture((a)))
153 #define ALCdevice_CaptureSamples(a,b,c) ((a)->Funcs->CaptureSamples((a), (b), (c)))
154 #define ALCdevice_AvailableSamples(a) ((a)->Funcs->AvailableSamples((a)))
156 struct ALCcontext_struct
158 ALlistener Listener;
160 ALsource *Source;
161 ALuint SourceCount;
163 ALenum LastError;
164 ALboolean InUse;
166 ALuint Frequency;
168 ALenum DistanceModel;
170 ALfloat DopplerFactor;
171 ALfloat DopplerVelocity;
172 ALfloat flSpeedOfSound;
174 ALint lNumMonoSources;
175 ALint lNumStereoSources;
177 ALCdevice *Device;
178 ALCchar ExtensionList[1024];
180 ALCcontext *next;
183 ALCchar *AppendDeviceList(char *name);
184 ALCchar *AppendAllDeviceList(char *name);
185 ALCchar *AppendCaptureDeviceList(char *name);
187 ALCvoid SetALCError(ALenum errorCode);
189 ALCvoid SuspendContext(ALCcontext *context);
190 ALCvoid ProcessContext(ALCcontext *context);
192 ALvoid *StartThread(ALuint (*func)(ALvoid*), ALvoid *ptr);
193 ALuint StopThread(ALvoid *thread);
195 typedef struct RingBuffer RingBuffer;
196 RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length);
197 void DestroyRingBuffer(RingBuffer *ring);
198 ALsizei RingBufferSize(RingBuffer *ring);
199 void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len);
200 void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len);
202 void ReadALConfig(void);
203 void FreeALConfig(void);
204 const char *GetConfigValue(const char *blockName, const char *keyName, const char *def);
205 int GetConfigValueInt(const char *blockName, const char *keyName, int def);
206 float GetConfigValueFloat(const char *blockName, const char *keyName, float def);
208 #ifdef __cplusplus
210 #endif
212 #endif