14 DriverIface
*DriverList
= NULL
;
15 int DriverListSize
= 0;
16 static int DriverListSizeMax
= 0;
18 static void LoadDriverList(void);
21 BOOL APIENTRY
DllMain(HINSTANCE module
, DWORD reason
, void *reserved
)
27 case DLL_PROCESS_ATTACH
:
31 case DLL_THREAD_ATTACH
:
32 case DLL_THREAD_DETACH
:
35 case DLL_PROCESS_DETACH
:
36 ResetPtrIntMap(&ContextIfaceMap
);
37 ResetPtrIntMap(&DeviceIfaceMap
);
38 for(i
= 0;i
< DriverListSize
;i
++)
40 if(DriverList
[i
].Module
)
41 FreeLibrary(DriverList
[i
].Module
);
46 DriverListSizeMax
= 0;
54 #define CAST_FUNC(x) (__typeof(x))
56 #define CAST_FUNC(x) (void*)
59 static void AddModule(HMODULE module
, const WCHAR
*name
)
64 for(i
= 0;i
< DriverListSize
;i
++)
66 if(DriverList
[i
].Module
== module
|| wcscmp(DriverList
[i
].Name
, name
) == 0)
73 if(DriverListSize
== DriverListSizeMax
)
75 int newmax
= DriverListSizeMax
? DriverListSizeMax
<<1 : 4;
76 void *newlist
= calloc(sizeof(DriverList
[0]), newmax
);
79 memcpy(newlist
, DriverList
, DriverListSize
*sizeof(DriverList
[0]));
82 DriverListSizeMax
= newmax
;
85 #define LOAD_PROC(x) do { \
86 DriverList[DriverListSize].x = CAST_FUNC(DriverList[DriverListSize].x) \
87 GetProcAddress(module, #x); \
88 if(!DriverList[DriverListSize].x) \
90 fprintf(stderr, "Failed to find entry point for %s in %ls\n", \
95 LOAD_PROC(alcCreateContext
);
96 LOAD_PROC(alcMakeContextCurrent
);
97 LOAD_PROC(alcProcessContext
);
98 LOAD_PROC(alcSuspendContext
);
99 LOAD_PROC(alcDestroyContext
);
100 LOAD_PROC(alcGetCurrentContext
);
101 LOAD_PROC(alcGetContextsDevice
);
102 LOAD_PROC(alcOpenDevice
);
103 LOAD_PROC(alcCloseDevice
);
104 LOAD_PROC(alcGetError
);
105 LOAD_PROC(alcIsExtensionPresent
);
106 LOAD_PROC(alcGetProcAddress
);
107 LOAD_PROC(alcGetEnumValue
);
108 LOAD_PROC(alcGetString
);
109 LOAD_PROC(alcGetIntegerv
);
110 LOAD_PROC(alcCaptureOpenDevice
);
111 LOAD_PROC(alcCaptureCloseDevice
);
112 LOAD_PROC(alcCaptureStart
);
113 LOAD_PROC(alcCaptureStop
);
114 LOAD_PROC(alcCaptureSamples
);
117 LOAD_PROC(alDisable
);
118 LOAD_PROC(alIsEnabled
);
119 LOAD_PROC(alGetString
);
120 LOAD_PROC(alGetBooleanv
);
121 LOAD_PROC(alGetIntegerv
);
122 LOAD_PROC(alGetFloatv
);
123 LOAD_PROC(alGetDoublev
);
124 LOAD_PROC(alGetBoolean
);
125 LOAD_PROC(alGetInteger
);
126 LOAD_PROC(alGetFloat
);
127 LOAD_PROC(alGetDouble
);
128 LOAD_PROC(alGetError
);
129 LOAD_PROC(alIsExtensionPresent
);
130 LOAD_PROC(alGetProcAddress
);
131 LOAD_PROC(alGetEnumValue
);
132 LOAD_PROC(alListenerf
);
133 LOAD_PROC(alListener3f
);
134 LOAD_PROC(alListenerfv
);
135 LOAD_PROC(alListeneri
);
136 LOAD_PROC(alListener3i
);
137 LOAD_PROC(alListeneriv
);
138 LOAD_PROC(alGetListenerf
);
139 LOAD_PROC(alGetListener3f
);
140 LOAD_PROC(alGetListenerfv
);
141 LOAD_PROC(alGetListeneri
);
142 LOAD_PROC(alGetListener3i
);
143 LOAD_PROC(alGetListeneriv
);
144 LOAD_PROC(alGenSources
);
145 LOAD_PROC(alDeleteSources
);
146 LOAD_PROC(alIsSource
);
147 LOAD_PROC(alSourcef
);
148 LOAD_PROC(alSource3f
);
149 LOAD_PROC(alSourcefv
);
150 LOAD_PROC(alSourcei
);
151 LOAD_PROC(alSource3i
);
152 LOAD_PROC(alSourceiv
);
153 LOAD_PROC(alGetSourcef
);
154 LOAD_PROC(alGetSource3f
);
155 LOAD_PROC(alGetSourcefv
);
156 LOAD_PROC(alGetSourcei
);
157 LOAD_PROC(alGetSource3i
);
158 LOAD_PROC(alGetSourceiv
);
159 LOAD_PROC(alSourcePlayv
);
160 LOAD_PROC(alSourceStopv
);
161 LOAD_PROC(alSourceRewindv
);
162 LOAD_PROC(alSourcePausev
);
163 LOAD_PROC(alSourcePlay
);
164 LOAD_PROC(alSourceStop
);
165 LOAD_PROC(alSourceRewind
);
166 LOAD_PROC(alSourcePause
);
167 LOAD_PROC(alSourceQueueBuffers
);
168 LOAD_PROC(alSourceUnqueueBuffers
);
169 LOAD_PROC(alGenBuffers
);
170 LOAD_PROC(alDeleteBuffers
);
171 LOAD_PROC(alIsBuffer
);
172 LOAD_PROC(alBufferf
);
173 LOAD_PROC(alBuffer3f
);
174 LOAD_PROC(alBufferfv
);
175 LOAD_PROC(alBufferi
);
176 LOAD_PROC(alBuffer3i
);
177 LOAD_PROC(alBufferiv
);
178 LOAD_PROC(alGetBufferf
);
179 LOAD_PROC(alGetBuffer3f
);
180 LOAD_PROC(alGetBufferfv
);
181 LOAD_PROC(alGetBufferi
);
182 LOAD_PROC(alGetBuffer3i
);
183 LOAD_PROC(alGetBufferiv
);
184 LOAD_PROC(alBufferData
);
185 LOAD_PROC(alDopplerFactor
);
186 LOAD_PROC(alDopplerVelocity
);
187 LOAD_PROC(alSpeedOfSound
);
188 LOAD_PROC(alDistanceModel
);
191 wcsncpy(DriverList
[DriverListSize
].Name
, name
, 32);
192 DriverList
[DriverListSize
++].Module
= module
;
196 static void SearchDrivers(WCHAR
*path
)
198 WCHAR srchPath
[MAX_PATH
+1] = L
"";
199 WIN32_FIND_DATAW fdata
;
202 wcsncpy(srchPath
, path
, MAX_PATH
);
203 wcsncat(srchPath
, L
"\\*oal.dll", MAX_PATH
- lstrlenW(srchPath
));
204 srchHdl
= FindFirstFileW(srchPath
, &fdata
);
205 if(srchHdl
!= INVALID_HANDLE_VALUE
)
210 wcsncpy(srchPath
, path
, MAX_PATH
);
211 wcsncat(srchPath
, L
"\\", MAX_PATH
- lstrlenW(srchPath
));
212 wcsncat(srchPath
, fdata
.cFileName
, MAX_PATH
- lstrlenW(srchPath
));
214 mod
= LoadLibraryW(srchPath
);
215 if(mod
) AddModule(mod
, fdata
.cFileName
);
216 } while(FindNextFileW(srchHdl
, &fdata
));
221 static WCHAR
*strrchrW(WCHAR
*str
, WCHAR ch
)
224 while(str
&& *str
!= '\0')
233 static int GetLoadedModuleDirectory(const WCHAR
*name
, WCHAR
*moddir
, DWORD length
)
235 HMODULE module
= NULL
;
240 module
= GetModuleHandleW(name
);
241 if(!module
) return 0;
244 if(GetModuleFileNameW(module
, moddir
, length
) == 0)
247 sep0
= strrchrW(moddir
, '/');
248 if(sep0
) sep1
= strrchrW(sep0
+1, '\\');
249 else sep1
= strrchrW(moddir
, '\\');
251 if(sep1
) *sep1
= '\0';
252 else if(sep0
) *sep0
= '\0';
258 void LoadDriverList(void)
260 WCHAR path
[MAX_PATH
+1] = L
"";
263 if(GetLoadedModuleDirectory(L
"OpenAL32.dll", path
, MAX_PATH
))
266 GetCurrentDirectoryW(MAX_PATH
, path
);
267 len
= lstrlenW(path
);
268 if(len
> 0 && (path
[len
-1] == '\\' || path
[len
-1] == '/'))
272 if(GetLoadedModuleDirectory(NULL
, path
, MAX_PATH
))
275 GetSystemDirectoryW(path
, MAX_PATH
);
276 len
= lstrlenW(path
);
277 if(len
> 0 && (path
[len
-1] == '\\' || path
[len
-1] == '/'))
283 void InitPtrIntMap(PtrIntMap
*map
)
289 RWLockInit(&map
->lock
);
292 void ResetPtrIntMap(PtrIntMap
*map
)
294 WriteLock(&map
->lock
);
300 WriteUnlock(&map
->lock
);
303 ALenum
InsertPtrIntMapEntry(PtrIntMap
*map
, ALvoid
*key
, ALint value
)
307 WriteLock(&map
->lock
);
310 ALsizei count
= map
->size
;
312 ALsizei step
= count
>>1;
313 ALsizei i
= pos
+step
;
314 if(!(map
->keys
[i
] < key
))
324 if(pos
== map
->size
|| map
->keys
[pos
] != key
)
326 if(map
->size
== map
->capacity
)
328 ALvoid
**keys
= NULL
;
332 newcap
= (map
->capacity
? (map
->capacity
<<1) : 4);
333 if(newcap
> map
->capacity
)
334 keys
= calloc(sizeof(map
->keys
[0])+sizeof(map
->values
[0]), newcap
);
337 WriteUnlock(&map
->lock
);
338 return AL_OUT_OF_MEMORY
;
340 values
= (ALint
*)&keys
[newcap
];
344 memcpy(keys
, map
->keys
, map
->size
*sizeof(map
->keys
[0]));
345 memcpy(values
, map
->values
, map
->size
*sizeof(map
->values
[0]));
349 map
->values
= values
;
350 map
->capacity
= newcap
;
355 memmove(&map
->keys
[pos
+1], &map
->keys
[pos
],
356 (map
->size
-pos
)*sizeof(map
->keys
[0]));
357 memmove(&map
->values
[pos
+1], &map
->values
[pos
],
358 (map
->size
-pos
)*sizeof(map
->values
[0]));
362 map
->keys
[pos
] = key
;
363 map
->values
[pos
] = value
;
364 WriteUnlock(&map
->lock
);
369 ALint
RemovePtrIntMapKey(PtrIntMap
*map
, ALvoid
*key
)
372 WriteLock(&map
->lock
);
376 ALsizei count
= map
->size
;
378 ALsizei step
= count
>>1;
379 ALsizei i
= pos
+step
;
380 if(!(map
->keys
[i
] < key
))
388 if(pos
< map
->size
&& map
->keys
[pos
] == key
)
390 ret
= map
->values
[pos
];
391 if(pos
< map
->size
-1)
393 memmove(&map
->keys
[pos
], &map
->keys
[pos
+1],
394 (map
->size
-1-pos
)*sizeof(map
->keys
[0]));
395 memmove(&map
->values
[pos
], &map
->values
[pos
+1],
396 (map
->size
-1-pos
)*sizeof(map
->values
[0]));
401 WriteUnlock(&map
->lock
);
405 ALint
LookupPtrIntMapKey(PtrIntMap
*map
, ALvoid
*key
)
408 ReadLock(&map
->lock
);
412 ALsizei count
= map
->size
;
414 ALsizei step
= count
>>1;
415 ALsizei i
= pos
+step
;
416 if(!(map
->keys
[i
] < key
))
424 if(pos
< map
->size
&& map
->keys
[pos
] == key
)
425 ret
= map
->values
[pos
];
427 ReadUnlock(&map
->lock
);