From 2ba3a88ace65803393c7f4bdb1b9e158a644d05e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 9 Mar 2010 05:44:18 -0800 Subject: Probe physical devices separately from appending them to the device list --- Alc/winmm.c | 66 ++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'Alc/winmm.c') diff --git a/Alc/winmm.c b/Alc/winmm.c index 6dd88191..54ec2f30 100644 --- a/Alc/winmm.c +++ b/Alc/winmm.c @@ -53,6 +53,29 @@ typedef struct { static ALCchar **CaptureDeviceList; static ALuint NumCaptureDevices; +static void ProbeDevices(void) +{ + ALuint i; + + for(i = 0;i < NumCaptureDevices;i++) + free(CaptureDeviceList[i]); + + NumCaptureDevices = waveInGetNumDevs(); + CaptureDeviceList = realloc(CaptureDeviceList, sizeof(ALCchar*) * NumCaptureDevices); + for(i = 0;i < NumCaptureDevices;i++) + { + WAVEINCAPS WaveInCaps; + + CaptureDeviceList[i] = NULL; + if(waveInGetDevCaps(i, &WaveInCaps, sizeof(WAVEINCAPS)) == MMSYSERR_NOERROR) + { + char name[128]; + snprintf(name, sizeof(name), "WaveIn on %s", WaveInCaps.szPname); + CaptureDeviceList[i] = strdup(name); + } + } +} + /* WaveInProc @@ -185,19 +208,31 @@ static ALCboolean WinMMOpenCapture(ALCdevice *pDevice, const ALCchar *deviceName ALuint i; // Find the Device ID matching the deviceName if valid - if (deviceName) + if(deviceName) + { + for(i = 0;i < NumCaptureDevices;i++) + { + if(CaptureDeviceList[i] && + strcmp(deviceName, CaptureDeviceList[i]) == 0) + { + lDeviceID = i; + break; + } + } + } + else { for(i = 0;i < NumCaptureDevices;i++) { - if (!strcmp(deviceName, CaptureDeviceList[i])) + if(CaptureDeviceList[i]) { lDeviceID = i; break; } } - if(i == NumCaptureDevices) - return ALC_FALSE; } + if(i == NumCaptureDevices) + return ALC_FALSE; pData = calloc(1, sizeof(*pData)); if(!pData) @@ -443,28 +478,15 @@ void alcWinMMDeinit() void alcWinMMProbe(int type) { - ALuint lLoop; + ALuint i; if(type != CAPTURE_DEVICE_PROBE) return; - for(lLoop = 0; lLoop < NumCaptureDevices; lLoop++) - free(CaptureDeviceList[lLoop]); - - NumCaptureDevices = waveInGetNumDevs(); - CaptureDeviceList = realloc(CaptureDeviceList, sizeof(ALCchar*) * NumCaptureDevices); - for(lLoop = 0; lLoop < NumCaptureDevices; lLoop++) + ProbeDevices(); + for(i = 0;i < NumCaptureDevices;i++) { - WAVEINCAPS WaveInCaps; - - if(waveInGetDevCaps(lLoop, &WaveInCaps, sizeof(WAVEINCAPS)) == MMSYSERR_NOERROR) - { - char name[128]; - snprintf(name, sizeof(name), "WaveIn on %s", WaveInCaps.szPname); - AppendCaptureDeviceList(name); - CaptureDeviceList[lLoop] = strdup(name); - } - else - CaptureDeviceList[lLoop] = strdup(""); + if(CaptureDeviceList[i]) + AppendCaptureDeviceList(CaptureDeviceList[i]); } } -- cgit v1.2.3