[Openal-devel] ALC_ENUMERATE_ALL_EXT and pluggable sound devices

Guilherme Balena Versiani guibv at comunip.com.br
Thu Sep 24 12:43:17 PDT 2009


Chris Robinson wrote:
> I'm not too sure if the router code on SVN is still up to date or not. I 
> *think* I read it was, or at least wasn't changed significantly, but that was 
> a while ago. I know the wrap_oal driver code isn't up-to-date.
>   

Well, then I am using the last revision at Creative repository (*r1789*).

> If you're going to modify the router code on SVN, there's some things you need 
> to be very careful of. These things bit me pretty hard when I was implementing 
> it for OpenAL Soft.
>
> First is (obviously) to make sure you don't leak the previous strings (change 
> the malloc calls to realloc, or free the old pointers first). Also be careful 
> that querying the default devices will also trigger rebuilding the list. (...)

I take care of this. But I didn't make any cosmetic changes like you 
mentioned, breaking up *BuildDeviceList* function, as my work is just to 
put it working and not maintain the code... After you validate that this 
code is fine, and if really want that, I send you another patch.

What I done:

    - In the start of *BuildDeviceList* there were a clause verifying 
first if the global variables was initialized. I just cleaned up them 
using free() and set them to NULL: *g_pDeviceList*, 
*g_pCaptureDeviceList*, and *g_pAllDevicesList*, and force their 
initialization every time *BuildDeviceList* is called.
    - I note a *BUG* in Creative driver for Windows when enumerating the 
capture devices: it does not append the final '0' to the device string 
list. Then I call *alcGetString* (for this driver) twice: once to get 
the string pointer and to make it all zeroes, and another to get the 
string list. This is a *very ugly hack*, but it does the work (I tested 
using the latest Creative driver for a SoundBlaster soundcard I have).

It follows attached this simple change to be validated. Please help me 
to check if this have any impact on other implementations.

Regards,

-- Guilherme Balena Versiani.
-------------- next part --------------
Index: OpenAL-Windows/Router/alc.cpp
===================================================================
--- OpenAL-Windows/Router/alc.cpp	(revision 1789)
+++ OpenAL-Windows/Router/alc.cpp	(working copy)
@@ -371,9 +371,27 @@
 	bool bUsedWrapper = false;
 	ALDEVICE *pDevice = NULL;
 
+    /// Always build the list ...
+    if (g_pDeviceList != NULL)
+    {
+        free(g_pDeviceList);
+        g_pDeviceList = NULL;
+    }
+
+    if (g_pCaptureDeviceList != NULL)
+    {
+        free(g_pCaptureDeviceList);
+        g_pCaptureDeviceList = NULL;
+    }
+
+    if (g_pAllDevicesList != NULL)
+    {
+        free(g_pAllDevicesList);
+        g_pAllDevicesList = NULL;
+    }
+
 	// Only build the list once ...
-	if (((g_pDeviceList == NULL) && (waveOutGetNumDevs())) ||
-		((g_pCaptureDeviceList == NULL) && (waveInGetNumDevs())))
+	if ( (waveOutGetNumDevs()) || (waveInGetNumDevs()) )
 	{
 		//
 		// Directory[0] is the directory containing OpenAL32.dll
@@ -531,10 +549,23 @@
 										// Skip native AL component (will contain same Capture List as the wrap_oal component)
 										if (alcIsExtensionPresentFxn(NULL, "ALC_EXT_CAPTURE")) {
 											// this DLL supports capture -- so add complete list of capture devices
+
+                                            // Ugly hack: zero memory first, as Creative driver
+                                            // does not add the final '0' to the listing.
 											specifier = alcGetStringFxn(0, ALC_CAPTURE_DEVICE_SPECIFIER);
 											if ((specifier) && strlen(specifier))
 											{
 												do {
+                                                    int len = strlen((char *)specifier);
+													memset((void *)specifier, 0, len);
+													specifier += len + 1;
+												} while (strlen((char *)specifier) > 0);
+											}
+
+                                            specifier = alcGetStringFxn(0, ALC_CAPTURE_DEVICE_SPECIFIER);
+											if ((specifier) && strlen(specifier))
+											{
+												do {
 													AddDevice(specifier, searchName, &g_pCaptureDeviceList);
 													specifier += strlen((char *)specifier) + 1;
 												} while (strlen((char *)specifier) > 0);


More information about the Openal-devel mailing list