diff options
author | Chris Robinson <[email protected]> | 2009-03-10 02:46:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2009-03-10 02:46:42 -0700 |
commit | 8ee47d557356bbd358c2197a1a6a535b32c89820 (patch) | |
tree | 64e2edb3abaf415cea5262b453bf382f30c5a458 | |
parent | 9e8801141716e52fd6897eb23cc116e08661814b (diff) |
Dynamically load dsound when possible
-rw-r--r-- | Alc/dsound.c | 38 | ||||
-rw-r--r-- | CMakeLists.txt | 21 |
2 files changed, 47 insertions, 12 deletions
diff --git a/Alc/dsound.c b/Alc/dsound.c index 899a0936..6ce4c66e 100644 --- a/Alc/dsound.c +++ b/Alc/dsound.c @@ -39,6 +39,10 @@ DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); +static void *ds_handle; +static HRESULT (WINAPI *pDirectSoundCreate)(LPCGUID pcGuidDevice, LPDIRECTSOUND *ppDS, LPUNKNOWN pUnkOuter); +static HRESULT (WINAPI *pDirectSoundEnumerateA)(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext); + // Since DSound doesn't report the fragment size, emulate it static int num_frags; @@ -136,6 +140,9 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam DWORD speakers; HRESULT hr; + if(ds_handle == NULL) + return ALC_FALSE; + if(deviceName) { int i; @@ -167,7 +174,7 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam } //DirectSound Init code - hr = DirectSoundCreate(guid, &pData->lpDS, NULL); + hr = pDirectSoundCreate(guid, &pData->lpDS, NULL); if(SUCCEEDED(hr)) hr = IDirectSound_SetCooperativeLevel(pData->lpDS, GetForegroundWindow(), DSSCL_PRIORITY); @@ -411,10 +418,37 @@ void alcDSoundInit(BackendFuncs *FuncList) *FuncList = DSoundFuncs; +#ifdef _WIN32 + ds_handle = LoadLibraryA("dsound.dll"); + if(ds_handle == NULL) + { + AL_PRINT("Failed to load dsound.dll\n"); + return; + } + +#define LOAD_FUNC(f) do { \ + p##f = (void*)GetProcAddress((HMODULE)ds_handle, #f); \ + if(p##f == NULL) \ + { \ + FreeLibrary(ds_handle); \ + ds_handle = NULL; \ + AL_PRINT("Could not load %s from dsound.dll\n", #f); \ + return; \ + } \ +} while(0) +#else + ds_handle = (void*)0xDEADBEEF; +#define LOAD_FUNC(f) p##f = f +#endif + +LOAD_FUNC(DirectSoundCreate); +LOAD_FUNC(DirectSoundEnumerateA); +#undef LOAD_FUNC + num_frags = GetConfigValueInt("dsound", "periods", 4); if(num_frags < 2) num_frags = 2; - hr = DirectSoundEnumerate(DSoundEnumDevices, &iter); + hr = pDirectSoundEnumerateA(DSoundEnumDevices, &iter); if(FAILED(hr)) AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr); } diff --git a/CMakeLists.txt b/CMakeLists.txt index 784713d2..f74dcd20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,16 +289,17 @@ ENDIF() IF(DSOUND) CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H) IF(HAVE_DSOUND_H) - SET(HAVE_DSOUND 1) - SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c) - SET(BACKENDS "${BACKENDS} DirectSound,") - - SET(CMAKE_REQUIRED_LIBRARIES dsound) - CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBDSOUND) - SET(CMAKE_REQUIRED_LIBRARIES "") -# CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND) - IF(HAVE_LIBDSOUND) - SET(EXTRA_LIBS dsound ${EXTRA_LIBS}) + CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND) + IF(HAVE_LIBDSOUND OR WIN32) + SET(HAVE_DSOUND 1) + SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c) + + IF(WIN32) + SET(BACKENDS "${BACKENDS} DirectSound,") + ELSE() + SET(BACKENDS "${BACKENDS} DirectSound \(linked\),") + SET(EXTRA_LIBS dsound ${EXTRA_LIBS}) + ENDIF() ENDIF() ENDIF() ENDIF() |