From 4c38ed272d2b9626cf65abb3dcfb6ad393dc0ea0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 8 Feb 2008 20:46:34 -0800 Subject: [PATCH] Enumerate DirectSound devices --- Alc/dsound.c | 48 +++++++++++++++++++++++++++++++++++++++--------- CMakeLists.txt | 8 ++++++++ 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Alc/dsound.c b/Alc/dsound.c index 313284c6..dbe72c77 100644 --- a/Alc/dsound.c +++ b/Alc/dsound.c @@ -51,7 +51,11 @@ typedef struct { } DSoundData; -static ALCchar *DeviceList[16]; +typedef struct { + ALCchar *name; + GUID guid; +} DevMap; +static DevMap DeviceList[16]; static ALuint DSoundProc(ALvoid *ptr) @@ -123,25 +127,28 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam DSBUFFERDESC DSBDescription; DSoundData *pData = NULL; WAVEFORMATEXTENSIBLE OutputType; + LPGUID guid = NULL; DWORD speakers; HRESULT hr; if(deviceName) { int i; - for(i = 0;DeviceList[i];i++) + for(i = 0;DeviceList[i].name;i++) { - if(strcmp(deviceName, DeviceList[i]) == 0) + if(strcmp(deviceName, DeviceList[i].name) == 0) { - device->szDeviceName = DeviceList[i]; + device->szDeviceName = DeviceList[i].name; + if(i > 0) + guid = &DeviceList[i].guid; break; } } - if(!DeviceList[i]) + if(!DeviceList[i].name) return ALC_FALSE; } else - device->szDeviceName = DeviceList[0]; + device->szDeviceName = DeviceList[0].name; memset(&OutputType, 0, sizeof(OutputType)); @@ -160,7 +167,7 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam //DirectSound Init code hr = CoCreateInstance(&CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound, (LPVOID*)&pData->lpDS); if(SUCCEEDED(hr)) - hr = IDirectSound_Initialize(pData->lpDS, NULL); + hr = IDirectSound_Initialize(pData->lpDS, guid); if(SUCCEEDED(hr)) hr = IDirectSound_SetCooperativeLevel(pData->lpDS, GetForegroundWindow(), DSSCL_PRIORITY); @@ -358,10 +365,33 @@ BackendFuncs DSoundFuncs = { DSoundAvailableSamples }; +static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data) +{ + static size_t i = 1; + (void)drvname; + (void)data; + + if(guid) + { + char str[128]; + snprintf(str, sizeof(str), "DirectSound Software on %s", desc); + DeviceList[i].name = AppendAllDeviceList(str); + DeviceList[i].guid = *guid; + i++; + } + else + DeviceList[0].name = AppendDeviceList("DirectSound Software"); + + return TRUE; +} + void alcDSoundInit(BackendFuncs *FuncList) { + HRESULT hr; + *FuncList = DSoundFuncs; - DeviceList[0] = AppendDeviceList("DirectSound Software"); - AppendAllDeviceList(DeviceList[0]); + hr = DirectSoundEnumerate(DSoundEnumDevices, NULL); + if(FAILED(hr)) + AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr); } diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bcb3b44..46c34e3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,6 +266,14 @@ IF(HAVE_WINDOWS_H) IF(HAVE_LIBDXGUID) SET(EXTRA_LIBS dxguid ${EXTRA_LIBS}) ENDIF() + + 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}) + ENDIF() ENDIF() ENDIF() IF(WINMM) -- 2.11.4.GIT