aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/dsound.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2010-03-09 06:09:29 -0800
committerChris Robinson <[email protected]>2010-03-09 06:09:29 -0800
commit8feb089f5ca9166810cb2655356db2006cd22496 (patch)
treec998636a4749690683d471d366f52b24d5cc729e /Alc/dsound.c
parent2ba3a88ace65803393c7f4bdb1b9e158a644d05e (diff)
Build device lists only when needed
Diffstat (limited to 'Alc/dsound.c')
-rw-r--r--Alc/dsound.c70
1 files changed, 41 insertions, 29 deletions
diff --git a/Alc/dsound.c b/Alc/dsound.c
index 41583525..7894585d 100644
--- a/Alc/dsound.c
+++ b/Alc/dsound.c
@@ -122,6 +122,33 @@ void DSoundUnload(void)
}
+static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data)
+{
+ (void)data;
+ (void)drvname;
+
+ if(guid)
+ {
+ char str[128];
+ void *temp;
+
+ temp = realloc(DeviceList, sizeof(DevMap) * (NumDevices+1));
+ if(temp)
+ {
+ DeviceList = temp;
+
+ snprintf(str, sizeof(str), "DirectSound Software on %s", desc);
+
+ DeviceList[NumDevices].name = strdup(str);
+ DeviceList[NumDevices].guid = *guid;
+ NumDevices++;
+ }
+ }
+
+ return TRUE;
+}
+
+
static ALuint DSoundProc(ALvoid *ptr)
{
ALCdevice *pDevice = (ALCdevice*)ptr;
@@ -208,11 +235,22 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
LPGUID guid = NULL;
HRESULT hr;
+ if(!DSoundLoad())
+ return ALC_FALSE;
+
if(!deviceName)
deviceName = dsDevice;
else if(strcmp(deviceName, dsDevice) != 0)
{
ALuint i;
+
+ if(!DeviceList)
+ {
+ hr = pDirectSoundEnumerateA(DSoundEnumDevices, NULL);
+ if(FAILED(hr))
+ AL_PRINT("Error enumerating DirectSound devices (%#x)!\n", (unsigned int)hr);
+ }
+
for(i = 0;i < NumDevices;i++)
{
if(strcmp(deviceName, DeviceList[i].name) == 0)
@@ -222,14 +260,13 @@ static ALCboolean DSoundOpenPlayback(ALCdevice *device, const ALCchar *deviceNam
}
}
if(i == NumDevices)
+ {
+ DSoundUnload();
return ALC_FALSE;
+ }
}
- if(!DSoundLoad())
- return ALC_FALSE;
-
//Initialise requested device
-
pData = calloc(1, sizeof(DSoundData));
if(!pData)
{
@@ -506,31 +543,6 @@ BackendFuncs DSoundFuncs = {
DSoundAvailableSamples
};
-static BOOL CALLBACK DSoundEnumDevices(LPGUID guid, LPCSTR desc, LPCSTR drvname, LPVOID data)
-{
- (void)data;
- (void)drvname;
-
- if(guid)
- {
- char str[128];
- void *temp;
-
- temp = realloc(DeviceList, sizeof(DevMap) * (NumDevices+1));
- if(temp)
- {
- DeviceList = temp;
-
- snprintf(str, sizeof(str), "DirectSound Software on %s", desc);
-
- DeviceList[NumDevices].name = strdup(str);
- DeviceList[NumDevices].guid = *guid;
- NumDevices++;
- }
- }
-
- return TRUE;
-}
void alcDSoundInit(BackendFuncs *FuncList)
{