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 /Alc | |
parent | 9e8801141716e52fd6897eb23cc116e08661814b (diff) |
Dynamically load dsound when possible
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/dsound.c | 38 |
1 files changed, 36 insertions, 2 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); } |