Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
More work on the 1.3 CoreAudio code.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 3, 2006
1 parent a42a3b2 commit 897de3e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/audio/SDL_audio.c
Expand Up @@ -854,7 +854,7 @@ SDL_AudioQuit(void)
}

/* 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));
}
Expand Down
50 changes: 32 additions & 18 deletions src/audio/macosx/SDL_coreaudio.c
Expand Up @@ -29,6 +29,7 @@
#include "../SDL_sysaudio.h"
#include "SDL_coreaudio.h"

#define DEBUG_COREAUDIO 1

typedef struct COREAUDIO_DeviceList
{
Expand Down Expand Up @@ -88,10 +89,12 @@ build_device_list(int iscapture, COREAUDIO_DeviceList **devices, int *devCount)
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,
Expand Down Expand Up @@ -122,32 +125,43 @@ build_device_list(int iscapture, COREAUDIO_DeviceList **devices, int *devCount)
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)) );

if (result != kAudioHardwareNoError)
continue;
CFRelease(cfstr);

while ((size > 0) && (ptr[size-1] == ' '))
size--; /* I have a USB device with whitespace at the end... */
if (usable) {
len = strlen(ptr);
/* Some devices have whitespace at the end...trim it. */
while ((len > 0) && (ptr[len-1] == ' ')) {
len--;
}
usable = (len > 0);
}

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)++;
Expand Down Expand Up @@ -216,8 +230,8 @@ AudioBootStrap COREAUDIO_bootstrap = {
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);
}


Expand Down

0 comments on commit 897de3e

Please sign in to comment.