changeset 3788:7006b176ef4f SDL-ryan-multiple-audio-device

More work on the 1.3 CoreAudio code.
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 03 Oct 2006 18:32:34 +0000
parents 8d74a4721ca9
children e2f68b579a01
files src/audio/SDL_audio.c src/audio/macosx/SDL_coreaudio.c
diffstat 2 files changed, 34 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/audio/SDL_audio.c	Tue Oct 03 16:26:42 2006 +0000
+++ b/src/audio/SDL_audio.c	Tue Oct 03 18:32:34 2006 +0000
@@ -854,7 +854,7 @@
     }
 
     /* Free the driver data */
-    current_audio.Deinitialize();
+    current_audio.impl.Deinitialize();
     SDL_memset(&current_audio, '\0', sizeof (current_audio));
     SDL_memset(open_devices, '\0', sizeof (open_devices));
 }
--- a/src/audio/macosx/SDL_coreaudio.c	Tue Oct 03 16:26:42 2006 +0000
+++ b/src/audio/macosx/SDL_coreaudio.c	Tue Oct 03 18:32:34 2006 +0000
@@ -29,6 +29,7 @@
 #include "../SDL_sysaudio.h"
 #include "SDL_coreaudio.h"
 
+#define DEBUG_COREAUDIO 1
 
 typedef struct COREAUDIO_DeviceList
 {
@@ -88,10 +89,12 @@
         return;
 
     for (i = 0; i < max; i++) {
+        CFStringRef cfstr = NULL;
         char *ptr = NULL;
         AudioDeviceID dev = devs[i];
         AudioBufferList *buflist = NULL;
         int usable = 0;
+        CFIndex len = 0;
 
         result = AudioDeviceGetPropertyInfo(dev, 0, iscapture,
                                       kAudioDevicePropertyStreamConfiguration,
@@ -122,32 +125,43 @@
         if (!usable)
             continue;
 
-        /* !!! FIXME: use CFStrings, instead, and convert to UTF-8. */
-        result = AudioDeviceGetPropertyInfo(dev, 0, iscapture,
-                                           kAudioDevicePropertyDeviceName,
-                                           &size, &outWritable);
+        size = sizeof (CFStringRef);
+        result = AudioDeviceGetProperty(dev, 0, iscapture,
+                                        kAudioObjectPropertyName,
+                                        &size, &cfstr);
 
         if (result != kAudioHardwareNoError)
             continue;
 
-        ptr = (char *) SDL_malloc(size + 1);
-        if (ptr == NULL)
-            continue;
+        len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
+                                                kCFStringEncodingUTF8);
 
-        result = AudioDeviceGetProperty(dev, 0, iscapture,
-                                       kAudioDevicePropertyDeviceName,
-                                       &size, ptr);
+        ptr = (char *) SDL_malloc(len + 1);
+        usable = ( (ptr != NULL) &&
+                (CFStringGetCString(cfstr,ptr,len+1,kCFStringEncodingUTF8)) );
+
+        CFRelease(cfstr);
 
-        if (result != kAudioHardwareNoError)
-            continue;
+        if (usable) {
+            len = strlen(ptr);
+            /* Some devices have whitespace at the end...trim it. */
+            while ((len > 0) && (ptr[len-1] == ' ')) {
+                len--;
+            }
+            usable = (len > 0);
+        }
 
-        while ((size > 0) && (ptr[size-1] == ' '))
-            size--; /* I have a USB device with whitespace at the end... */
-
-        if (size == 0) {
+        if (!usable) {
             SDL_free(ptr);
         } else {
-            ptr[size] = '\0';
+            ptr[len] = '\0';
+
+            #if DEBUG_COREAUDIO
+            printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n",
+                    ((iscapture) ? "capture" : "output"),
+                    (int) *devCount, ptr, (int) dev);
+            #endif
+
             (*devices)[*devCount].id = dev;
             (*devices)[*devCount].name = ptr;
             (*devCount)++;
@@ -216,8 +230,8 @@
 static void
 COREAUDIO_Deinitialize(void)
 {
-    free_device_list(0, &outputDevices, &outputDeviceCount);
-    free_device_list(1, &inputDevices, &inputDeviceCount);
+    free_device_list(&outputDevices, &outputDeviceCount);
+    free_device_list(&inputDevices, &inputDeviceCount);
 }